From 4a77990cb20e3fdd5885a926585a9e26d186717e Mon Sep 17 00:00:00 2001 From: zoep Date: Sat, 25 Jul 2026 14:39:43 +0300 Subject: [PATCH 01/38] Solm: move decEq to different files; cleanup --- Solm/Syntax/Basic.lean | 325 +++++++ Solm/Syntax/DecEq.lean | 1931 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 2256 insertions(+) create mode 100644 Solm/Syntax/Basic.lean create mode 100644 Solm/Syntax/DecEq.lean diff --git a/Solm/Syntax/Basic.lean b/Solm/Syntax/Basic.lean new file mode 100644 index 00000000..8df0a682 --- /dev/null +++ b/Solm/Syntax/Basic.lean @@ -0,0 +1,325 @@ +import EVM.Types +import ABI.Types + +namespace Solm + +open ABI + +abbrev Ident := String + +/- Basically all values that can be a key for a mapping. + In other words all types that can fit in a word. -/ +inductive KeyValue where + | int : Int -> KeyValue + | bool : Bool -> KeyValue + | address : EVM.Address -> KeyValue + | fixedBytes : Fin 32 -> List UInt8 -> KeyValue + deriving Repr, Inhabited + +inductive EvaledStorageRefStep where + | field : Ident -> EvaledStorageRefStep + | tupleElem : Nat -> EvaledStorageRefStep + | mindex : KeyValue -> EvaledStorageRefStep + | aindex : KeyValue -> EvaledStorageRefStep + /- Marker for "the length of the array reached so far". A distinct ref the layout + resolves to wherever it stores that array's length — the semantics commits to no + particular slot convention (solc puts it at the array's base slot; another layout + may put it elsewhere). Only the array's length query produces this step. -/ + | length : EvaledStorageRefStep + deriving Repr, Inhabited + +structure EvaledStorageRef where + base : Ident + steps : List EvaledStorageRefStep := [] + deriving Repr, Inhabited + +/- The types that can be in storage -/ +inductive StorageType where + | elem : ElemType -> StorageType + | mapping : ElemType -> StorageType -> StorageType -- Check more on Keytype here + | contract : Ident -> StorageType + -- Keeping the fields inside the struct so that recursion over StorageType is well-founded + -- So right now this refers to the AST, not the surface syntax + | struct : Ident -> List (Ident × StorageType) -> StorageType + | tuple : List StorageType -> StorageType + | array : StorageType -> Nat -> StorageType + | dynamicArray : StorageType -> StorageType + -- Conditionally compact layout used by solidity for bytes and strings + | bytes : StorageType + | string : StorageType + deriving Repr, Inhabited + +/- Ethereum environment variables -/ +inductive EnvVar where + | caller + | origin + | callvalue + | this + | timestamp + | chainid + | selfbalance + | gasprice + | number + | coinbase + | gaslimit + | prevrandao + | basefee + | msgSig + | msgData + deriving Repr, Inhabited + +inductive UnaryOp where + | not + | neg + | bitNot + deriving Repr, Inhabited + +inductive BinaryOp where + | add + | sub + | mul + | div + | mod + | eq + | ne + | lt + | le + | gt + | ge + | and + | or + | bitAnd + | bitOr + | bitXor + | shl + | shr + | exp + deriving Repr, Inhabited + +/-- Whether a variable path is rooted in a memory **local** or **storage**. Resolved statically + by the spec author / frontend, exactly as solc resolves the name. -/ +inductive VarOrigin where + | localVar + | storage + deriving Repr, Inhabited + +mutual + +/- Expressions are intentionally lightweight for now. We are aiming for a meaningful + subset of Solidity. -/ +inductive Expr where + | intLit : Int -> Expr + | boolLit : Bool -> Expr + | bytesLit : ByteArray -> Expr + /- `new bytes(len)`: a fresh zero-filled byte string of dynamic length `len` -/ + | newBytes : Expr -> Expr + /- `new T[](len)`: a fresh memory array with `len` default-initialized elements of type `T` -/ + | newArray : StorageType -> Expr -> Expr + /- struct literal `S({field₁: e₁, …})`: builds a `Value.struct` from the named field expressions + (e.g. `Proposal({name: x, voteCount: 0})`). -/ + | structLit : Ident -> List (Ident × Expr) -> Expr + /- array literal `[e₁, …]`: builds a `Value.array` from the element expressions. -/ + | arrayLit : List Expr -> Expr + /- tuple literal: builds a `Value.tuple` from the element expressions. Used to assemble a + multi-value (tuple) return (e.g. a struct getter returning `(a, b)`); its value representation + is `Value.tuple`, distinct from `Value.array`. -/ + | tupleLit : List Expr -> Expr + /- static tuple projection `t.i`: the `i`-th component. -/ + | tupleGet : Expr -> Nat -> Expr + /- `b[start:end]`: byte slice of dynamic bytes `b` over `[start, end)` -/ + | bytesSlice : Expr /- base -/ -> Expr /- start -/ -> Expr /- end -/ -> Expr + | var : Ident -> Expr + | env : EnvVar -> Expr + /- for struct fields -/ + | field : Expr -> Ident -> Expr + | storage : StorageRef -> Expr + | inRange : IntType -> Expr -> Expr + | cast : Expr -> StorageType -> Expr /- TODO do we really need casting?-/ + | addrOf : Expr -> Expr + | unary : UnaryOp -> Expr -> Expr + | binary : BinaryOp -> Expr -> Expr -> Expr + | index : Expr -> Expr -> Expr + | ite : Expr -> Expr -> Expr -> Expr + /- `arr.length`. The origin is explicit, matching assignment: storage paths read the declared + storage array length; local paths read the in-memory value and return its array/byte count. -/ + | arrayLength : VarOrigin -> StorageRef -> Expr + /- `keccak256(b)`: the Keccak-256 hash of the dynamic bytes `b`, as a `bytes32` value. The hash + primitive is the same `ffi.KEC` the EVM's `KECCAK256` opcode uses, so equivalence reduces to + equality of the hashed bytes. -/ + | keccak256 : Expr -> Expr + /- `abi.encodePacked(e₁, …)`: the non-padded ("packed") ABI encoding of the listed values, as a + dynamic `bytes`. Each operand carries its (statically known) `ABIType`, which fixes its packed + width (`uintN`→N/8 bytes, `bool`→1, `address`→20, `bytesN`→N, with no length prefixes). -/ + | abiEncodePacked : List (ABIType × Expr) -> Expr + /- ABI calldata for a configured external call, including the 4-byte selector. The contract's + `Config.externalABI.encode?` determines the selector/types for `name`; this models + `abi.encodeWithSelector(...)` without baking contract-specific selectors into Solm. -/ + | abiEncodeCall : Ident -> List Expr -> Expr + /- `abi.decode(bytes, (T))`: decode a single ABI return value from dynamic bytes. Decode failure is + a model-level revert, matching Solidity's runtime `abi.decode` behavior. -/ + | abiDecode : ABIType -> Expr -> Expr + /- `addr.code.length` (EXTCODESIZE): the size in bytes of the code deployed at address `addr`. + Matches `Ethereum.State.extCodeSize` — a non-existent account or an EOA (no code) has size 0. + Used by ERC721 `safeTransferFrom`'s `to.code.length == 0` contract-detection guard. -/ + | extCodeSize : Expr -> Expr + /- `addr` code prefix (EXTCODECOPY): the first `len` bytes of the code at `addr`, as `bytes`, + zero-padded past the code end (all zero for a non-existent account or an EOA). -/ + | extCodePrefix : Expr /- addr -/ -> Expr /- len -/ -> Expr + /- `blockhash(n)` (BLOCKHASH), `addr.balance` (BALANCE), `addr.codehash` (EXTCODEHASH). -/ + | blockhash : Expr -> Expr + | balanceOf : Expr -> Expr + | extCodeHash : Expr -> Expr + /- Fixed-size `bytesN` literal: the ABI type index (`n : Fin 32` ⇒ width `n+1`) and the bytes in + Solidity order. Models compile-time `bytesN` constants — hex `bytesN` literals, a function's + `.selector` (`bytes4`), and `type(I).interfaceId` (`bytes4`) — all of which solc bakes as PUSH + immediates. Evaluates to `Value.fixedBytes n bs`; `==`/comparisons already act on `fixedBytes`. -/ + | fixedBytesLit : Fin 32 -> List UInt8 -> Expr + +inductive StorageRefStep where + | field : Ident -> StorageRefStep + | mindex : Expr -> StorageRefStep + | aindex : Expr -> StorageRefStep + +structure StorageRef where /- TODO better name, since it can be a reference to locals or storage -/ + base : Ident + steps : List StorageRefStep := [] + +/- Zoe: Shall we use StorageRef at the Expr level too instead of having field? -/ + +end + +instance : Repr ByteArray where + reprPrec b _ := repr b.data + +deriving instance Repr for Expr +deriving instance Inhabited for Expr +deriving instance Repr for StorageRefStep +deriving instance Inhabited for StorageRefStep +deriving instance Repr for StorageRef +deriving instance Inhabited for StorageRef + +namespace StorageRef + +def var (name : Ident) : StorageRef := + { base := name } + +end StorageRef + +inductive AssignRhs where + | expr : Expr -> AssignRhs + -- Do we want non-determinism? + -- | havoc + deriving Repr, Inhabited + +inductive Stmt where + /- local variable -/ + | letDecl : Ident -> Option ABIType -> Expr -> Stmt + /- local storage alias: `T storage x = ref`; stores an evaluated storage pointer in locals -/ + | letStorage : Ident -> StorageRef -> Stmt + /- `uint256 x = gasleft()`: bind `x` to a nondeterministic gas value (Solm tracks no gas). -/ + | letGas : Ident -> Stmt + /- assignment to a local (`.local`) or storage (`.storage`) variable path -/ + | assign : VarOrigin -> StorageRef -> Expr -> Stmt + | require : Expr -> Stmt + | while : Expr -> List Stmt -> Stmt + /- `for (init; cond; post) { body }`, modelled as Yul's `for {init} cond {post} {body}`: + `init` runs once, then each iteration checks `cond`, runs `body`, then `post`. A `continue` + in `body` skips to `post` (re-checking `cond` after); a `break` exits without running `post`. -/ + | for : List Stmt /- init -/ -> Expr /- cond -/ -> List Stmt /- post -/ -> List Stmt /- body -/ -> Stmt + /- conditional: `if cond { thenBranch } else { elseBranch }`; a no-`else` `if` is `elseBranch = []` -/ + | ite : Expr -> List Stmt -> List Stmt -> Stmt + /- constructor call; `salt = none` ⇒ CREATE, `some e` (bytes32) ⇒ CREATE2. -/ + | new : Ident -> Expr /- ETH to send -/ -> List Expr -> Ident /- return value binder -/ -> + (salt : Option Expr := none) -> Stmt + /- internal and external call results are explicitly let-bound -/ + | internalCall : Ident -> List Expr -> Ident /- return value binder -/ -> Stmt + | externalCall : Expr -> Ident -> Expr /- ETH to send -/ -> List Expr -> + Ident /- return value binder -/ -> (perm : Bool := true) -> Stmt + /- low-level raw call, binds a success `bool` to `okVar` and raw returndata to `dataVar`. + `perm = true` models `.call`; `perm = false` models raw `.staticcall`. -/ + | lowLevelCall : Expr /- target -/ -> Expr /- ETH to send -/ -> + Expr /- calldata bytes -/ -> Ident /- success binder -/ -> + Ident /- raw returndata binder -/ -> (perm : Bool := true) -> Stmt + /- low-level raw delegatecall, binds a success `bool` to `okVar` and raw returndata to + `dataVar`. There is no ETH argument: EVM `DELEGATECALL` preserves `msg.value` and transfers + no value. -/ + | delegateCall : Expr /- target -/ -> Expr /- calldata bytes -/ -> + Ident /- success binder -/ -> Ident /- raw returndata binder -/ -> Stmt + /- `try recv.name{value}(args) returns (retVar) { onSuccess } catch { onFail }`. All callee + reverts hand control to `onFail` with the raw revert bytes bound to `errVar`; the spec filters by + selector prefix (e.g. `Error(string)`) and re-reverts uncaught cases via `require false`. + `retVar` is bound only within `onSuccess`. -/ + | checkedCall : Expr /- receiver -/ -> Ident /- name -/ -> Expr /- ETH -/ -> + List Expr /- args -/ -> Ident /- decoded return, scoped to onSuccess -/ -> + List Stmt /- onSuccess -/ -> Ident /- raw revert bytes, scoped to onFail -/ -> + List Stmt /- onFail -/ -> (perm : Bool := true) -> Stmt + /- `return (e₁, …, eₙ)`: return the listed values. `[]` models `return;` / a void return. -/ + | return : List Expr -> Stmt + | break : Stmt + | continue : Stmt + /- `arr.push(v?)`: grow a dynamic storage array by one. `some v` appends scalar `v`; `none` is a + grow-only push (structured elements — the new slots are zero, fields set by later writes). -/ + | push : StorageRef -> Option Expr -> Stmt + /- `arr.pop()`: remove the last element of a dynamic storage array (reverts if empty), + clearing the slot and shrinking its length by one -/ + | pop : StorageRef -> Stmt + /- `delete x`: reset the storage at `x` to its zero value (recursively, per its type) -/ + | delete : StorageRef -> Stmt + deriving Repr, Inhabited + + +abbrev Body := List Stmt + +structure Param where + name : Ident + ty : ABI.ABIType + deriving Repr, Inhabited + +structure StorageDecl where + name : Ident + ty : StorageType + deriving Repr, Inhabited + +structure ConstructorDecl where + params : List Param + body : List Stmt + deriving Repr, Inhabited + +-- Currently this covers storage structs +-- The ABI technically has no structs, +-- Solidity implements call-parameter structs through ABI tuples +structure StructDecl where + name : Ident + fields : List StorageDecl + deriving Repr, Inhabited + +structure FunctionDecl where + name : Ident + params : List Param + /-- ABI return types, in order. `[]` = void; multi-element lists encode flat, as solc does. -/ + returnType : List ABIType := [] + body : List Stmt + deriving Repr, Inhabited + +structure TransitionDecl where + name : Ident + params : List Param + /-- ABI return types, in order. `[]` = void; multi-element lists encode flat, as solc does. -/ + returnType : List ABIType := [] + body : List Stmt + deriving Repr, Inhabited + +structure ContractDecl where + name : Ident + storage : List StorageDecl + ctor : ConstructorDecl + structs : List StructDecl := [] -- Maybe these should not be per-contract. Zoe: if we are inlining them anyway, do we still need this? + functions : List FunctionDecl := [] + transitions : List TransitionDecl := [] + receive : Option TransitionDecl := none + fallback : Option TransitionDecl := none + deriving Repr, Inhabited + +abbrev Program := List ContractDecl + +end Solm diff --git a/Solm/Syntax/DecEq.lean b/Solm/Syntax/DecEq.lean new file mode 100644 index 00000000..683f59d1 --- /dev/null +++ b/Solm/Syntax/DecEq.lean @@ -0,0 +1,1931 @@ +import Solm.Syntax.Basic + +/-! +`DecidableEq` instances for the `Solm` syntax types. + +`Expr`, `StorageType`, and `Stmt` each carry nested `List` payloads (e.g. +`arrayLit : List Expr`), a shape Lean's `deriving DecidableEq` handler cannot +process, so their instances are hand-written structural `decEq`s. Every other +type derives normally. Instances appear in dependency order: each is in scope +before the types that use it. Kept out of `Solm.Syntax.Basic` so that file reads +as plain type definitions. +-/ + +namespace Solm + +open ABI + +deriving instance DecidableEq for KeyValue + +deriving instance DecidableEq for EvaledStorageRefStep + +deriving instance DecidableEq for EvaledStorageRef + +mutual + private def StorageType.decEq : (a b : StorageType) -> Decidable (a = b) + | .elem p, .elem q => + match (inferInstance : Decidable (p = q)) with + | isTrue h => isTrue (by subst q; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .mapping k t, .mapping l u => + match (inferInstance : Decidable (k = l)), StorageType.decEq t u with + | isTrue hk, isTrue ht => isTrue (by subst l; subst u; rfl) + | isFalse hk, _ => isFalse (by intro h'; cases h'; exact hk rfl) + | _, isFalse ht => isFalse (by intro h'; cases h'; exact ht rfl) + | .contract x, .contract y => + match (inferInstance : Decidable (x = y)) with + | isTrue h => isTrue (by subst y; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .struct x fx, .struct y fy => + match (inferInstance : Decidable (x = y)), StorageType.decEqNamedList fx fy with + | isTrue h, isTrue hf => isTrue (by subst y; cases hf; rfl) + | _, isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | isFalse h, _ => isFalse (by intro h'; cases h'; exact h rfl) + | .tuple xs, .tuple ys => + match StorageType.decEqList xs ys with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .array t n, .array u m => + match StorageType.decEq t u, (inferInstance : Decidable (n = m)) with + | isTrue ht, isTrue hn => isTrue (by subst u; subst m; rfl) + | isFalse ht, _ => isFalse (by intro h'; cases h'; exact ht rfl) + | _, isFalse hn => isFalse (by intro h'; cases h'; exact hn rfl) + | .dynamicArray t, .dynamicArray u => + match StorageType.decEq t u with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .bytes, .bytes => isTrue rfl + | .string, .string => isTrue rfl + | .elem _, .mapping _ _ => isFalse (by intro h; cases h) + | .elem _, .contract _ => isFalse (by intro h; cases h) + | .elem _, .struct _ _ => isFalse (by intro h; cases h) + | .elem _, .tuple _ => isFalse (by intro h; cases h) + | .elem _, .array _ _ => isFalse (by intro h; cases h) + | .elem _, .dynamicArray _ => isFalse (by intro h; cases h) + | .elem _, .bytes => isFalse (by intro h; cases h) + | .elem _, .string => isFalse (by intro h; cases h) + | .mapping _ _, .elem _ => isFalse (by intro h; cases h) + | .mapping _ _, .contract _ => isFalse (by intro h; cases h) + | .mapping _ _, .struct _ _ => isFalse (by intro h; cases h) + | .mapping _ _, .tuple _ => isFalse (by intro h; cases h) + | .mapping _ _, .array _ _ => isFalse (by intro h; cases h) + | .mapping _ _, .dynamicArray _ => isFalse (by intro h; cases h) + | .mapping _ _, .bytes => isFalse (by intro h; cases h) + | .mapping _ _, .string => isFalse (by intro h; cases h) + | .contract _, .elem _ => isFalse (by intro h; cases h) + | .contract _, .mapping _ _ => isFalse (by intro h; cases h) + | .contract _, .struct _ _ => isFalse (by intro h; cases h) + | .contract _, .tuple _ => isFalse (by intro h; cases h) + | .contract _, .array _ _ => isFalse (by intro h; cases h) + | .contract _, .dynamicArray _ => isFalse (by intro h; cases h) + | .contract _, .bytes => isFalse (by intro h; cases h) + | .contract _, .string => isFalse (by intro h; cases h) + | .struct _ _, .elem _ => isFalse (by intro h; cases h) + | .struct _ _, .mapping _ _ => isFalse (by intro h; cases h) + | .struct _ _, .contract _ => isFalse (by intro h; cases h) + | .struct _ _, .tuple _ => isFalse (by intro h; cases h) + | .struct _ _, .array _ _ => isFalse (by intro h; cases h) + | .struct _ _, .dynamicArray _ => isFalse (by intro h; cases h) + | .struct _ _, .bytes => isFalse (by intro h; cases h) + | .struct _ _, .string => isFalse (by intro h; cases h) + | .tuple _, .elem _ => isFalse (by intro h; cases h) + | .tuple _, .mapping _ _ => isFalse (by intro h; cases h) + | .tuple _, .contract _ => isFalse (by intro h; cases h) + | .tuple _, .struct _ _ => isFalse (by intro h; cases h) + | .tuple _, .array _ _ => isFalse (by intro h; cases h) + | .tuple _, .dynamicArray _ => isFalse (by intro h; cases h) + | .tuple _, .bytes => isFalse (by intro h; cases h) + | .tuple _, .string => isFalse (by intro h; cases h) + | .array _ _, .elem _ => isFalse (by intro h; cases h) + | .array _ _, .mapping _ _ => isFalse (by intro h; cases h) + | .array _ _, .contract _ => isFalse (by intro h; cases h) + | .array _ _, .struct _ _ => isFalse (by intro h; cases h) + | .array _ _, .tuple _ => isFalse (by intro h; cases h) + | .array _ _, .dynamicArray _ => isFalse (by intro h; cases h) + | .array _ _, .bytes => isFalse (by intro h; cases h) + | .array _ _, .string => isFalse (by intro h; cases h) + | .dynamicArray _, .elem _ => isFalse (by intro h; cases h) + | .dynamicArray _, .mapping _ _ => isFalse (by intro h; cases h) + | .dynamicArray _, .contract _ => isFalse (by intro h; cases h) + | .dynamicArray _, .struct _ _ => isFalse (by intro h; cases h) + | .dynamicArray _, .tuple _ => isFalse (by intro h; cases h) + | .dynamicArray _, .array _ _ => isFalse (by intro h; cases h) + | .dynamicArray _, .bytes => isFalse (by intro h; cases h) + | .dynamicArray _, .string => isFalse (by intro h; cases h) + | .bytes, .elem _ => isFalse (by intro h; cases h) + | .bytes, .mapping _ _ => isFalse (by intro h; cases h) + | .bytes, .contract _ => isFalse (by intro h; cases h) + | .bytes, .struct _ _ => isFalse (by intro h; cases h) + | .bytes, .tuple _ => isFalse (by intro h; cases h) + | .bytes, .array _ _ => isFalse (by intro h; cases h) + | .bytes, .dynamicArray _ => isFalse (by intro h; cases h) + | .bytes, .string => isFalse (by intro h; cases h) + | .string, .elem _ => isFalse (by intro h; cases h) + | .string, .mapping _ _ => isFalse (by intro h; cases h) + | .string, .contract _ => isFalse (by intro h; cases h) + | .string, .struct _ _ => isFalse (by intro h; cases h) + | .string, .tuple _ => isFalse (by intro h; cases h) + | .string, .array _ _ => isFalse (by intro h; cases h) + | .string, .dynamicArray _ => isFalse (by intro h; cases h) + | .string, .bytes => isFalse (by intro h; cases h) + + private def StorageType.decEqList : (as bs : List StorageType) -> Decidable (as = bs) + | [], [] => isTrue rfl + | a :: as, b :: bs => + match StorageType.decEq a b, StorageType.decEqList as bs with + | isTrue ha, isTrue hs => isTrue (by cases ha; cases hs; rfl) + | isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) + | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) + | [], _ :: _ => isFalse (by intro h; cases h) + | _ :: _, [] => isFalse (by intro h; cases h) + + private def StorageType.decEqNamedList : (as bs : List (Ident × StorageType)) -> Decidable (as = bs) + | [], [] => isTrue rfl + | (an, al) :: as, (bn, bl) :: bs => + match String.decEq an bn, StorageType.decEq al bl, StorageType.decEqNamedList as bs with + | isTrue han, isTrue ha, isTrue hs => isTrue (by cases ha; cases hs; cases han; rfl) + | isFalse han, _, _ => isFalse (by intro h; cases h; exact han rfl) + | _, isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) + | _, _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) + | [], _ :: _ => isFalse (by intro h; cases h) + | _ :: _, [] => isFalse (by intro h; cases h) +end + +instance : DecidableEq StorageType := + StorageType.decEq + +deriving instance DecidableEq for EnvVar + +deriving instance DecidableEq for UnaryOp + +deriving instance DecidableEq for BinaryOp + +deriving instance DecidableEq for VarOrigin + +-- The hand-written structural `DecidableEq` is an O(n²) match over `Expr`'s constructors; with the +-- `keccak256`/`abiEncodePacked` additions it exceeds the default heartbeat budget during the equation +-- compiler's `simp` pass, so the limit is raised for this block. +set_option maxHeartbeats 5000000 in +mutual + private def Expr.decEq : (a b : Expr) -> Decidable (a = b) + | .intLit x, .intLit y => + match (inferInstance : Decidable (x = y)) with + | isTrue h => isTrue (by subst y; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .boolLit x, .boolLit y => + match (inferInstance : Decidable (x = y)) with + | isTrue h => isTrue (by subst y; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .bytesLit x, .bytesLit y => + match (inferInstance : Decidable (x = y)) with + | isTrue h => isTrue (by subst y; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .newBytes x, .newBytes y => + match Expr.decEq x y with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .newArray tx x, .newArray ty y => + match (inferInstance : Decidable (tx = ty)), Expr.decEq x y with + | isTrue ht, isTrue hx => isTrue (by cases ht; cases hx; rfl) + | isFalse ht, _ => isFalse (by intro h'; cases h'; exact ht rfl) + | _, isFalse hx => isFalse (by intro h'; cases h'; exact hx rfl) + | .bytesSlice b1 s1 e1, .bytesSlice b2 s2 e2 => + match Expr.decEq b1 b2, Expr.decEq s1 s2, Expr.decEq e1 e2 with + | isTrue hb, isTrue hs, isTrue he => isTrue (by cases hb; cases hs; cases he; rfl) + | isFalse hb, _, _ => isFalse (by intro h'; cases h'; exact hb rfl) + | _, isFalse hs, _ => isFalse (by intro h'; cases h'; exact hs rfl) + | _, _, isFalse he => isFalse (by intro h'; cases h'; exact he rfl) + | .var x, .var y => + match (inferInstance : Decidable (x = y)) with + | isTrue h => isTrue (by subst y; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .env x, .env y => + match (inferInstance : Decidable (x = y)) with + | isTrue h => isTrue (by subst y; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .field x fx, .field y fy => + match Expr.decEq x y, (inferInstance : Decidable (fx = fy)) with + | isTrue hx, isTrue hf => isTrue (by subst y; subst fy; rfl) + | isFalse hx, _ => isFalse (by intro h'; cases h'; exact hx rfl) + | _, isFalse hf => isFalse (by intro h'; cases h'; exact hf rfl) + | .storage x, .storage y => + match StorageRef.decEq x y with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .inRange tx x, .inRange ty y => + match (inferInstance : Decidable (tx = ty)), Expr.decEq x y with + | isTrue ht, isTrue hx => isTrue (by cases ht; cases hx; rfl) + | isFalse ht, _ => isFalse (by intro h'; cases h'; exact ht rfl) + | _, isFalse hx => isFalse (by intro h'; cases h'; exact hx rfl) + | .cast x tx, .cast y ty => + match Expr.decEq x y, (inferInstance : Decidable (tx = ty)) with + | isTrue hx, isTrue ht => isTrue (by cases hx; cases ht; rfl) + | isFalse hx, _ => isFalse (by intro h'; cases h'; exact hx rfl) + | _, isFalse ht => isFalse (by intro h'; cases h'; exact ht rfl) + | .addrOf x, .addrOf y => + match Expr.decEq x y with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .unary ox x, .unary oy y => + match (inferInstance : Decidable (ox = oy)), Expr.decEq x y with + | isTrue ho, isTrue hx => isTrue (by cases ho; cases hx; rfl) + | isFalse ho, _ => isFalse (by intro h'; cases h'; exact ho rfl) + | _, isFalse hx => isFalse (by intro h'; cases h'; exact hx rfl) + | .binary ox lx rx, .binary oy ly ry => + match (inferInstance : Decidable (ox = oy)), Expr.decEq lx ly, Expr.decEq rx ry with + | isTrue ho, isTrue hl, isTrue hr => isTrue (by cases ho; cases hl; cases hr; rfl) + | isFalse ho, _, _ => isFalse (by intro h'; cases h'; exact ho rfl) + | _, isFalse hl, _ => isFalse (by intro h'; cases h'; exact hl rfl) + | _, _, isFalse hr => isFalse (by intro h'; cases h'; exact hr rfl) + | .index bx ix, .index byx iy => + match Expr.decEq bx byx, Expr.decEq ix iy with + | isTrue hb, isTrue hi => isTrue (by cases hb; cases hi; rfl) + | isFalse hb, _ => isFalse (by intro h'; cases h'; exact hb rfl) + | _, isFalse hi => isFalse (by intro h'; cases h'; exact hi rfl) + | .ite cx tx fx, .ite cy ty fy => + match Expr.decEq cx cy, Expr.decEq tx ty, Expr.decEq fx fy with + | isTrue hc, isTrue ht, isTrue hf => isTrue (by cases hc; cases ht; cases hf; rfl) + | isFalse hc, _, _ => isFalse (by intro h'; cases h'; exact hc rfl) + | _, isFalse ht, _ => isFalse (by intro h'; cases h'; exact ht rfl) + | _, _, isFalse hf => isFalse (by intro h'; cases h'; exact hf rfl) + | .arrayLength ox x, .arrayLength oy y => + match (inferInstance : Decidable (ox = oy)), StorageRef.decEq x y with + | isTrue ho, isTrue hx => isTrue (by cases ho; cases hx; rfl) + | isFalse ho, _ => isFalse (by intro h'; cases h'; exact ho rfl) + | _, isFalse hx => isFalse (by intro h'; cases h'; exact hx rfl) + | .newArray _ _, .intLit _ => isFalse (by intro h; cases h) + | .newArray _ _, .boolLit _ => isFalse (by intro h; cases h) + | .newArray _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .newArray _ _, .newBytes _ => isFalse (by intro h; cases h) + | .newArray _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .var _ => isFalse (by intro h; cases h) + | .newArray _ _, .env _ => isFalse (by intro h; cases h) + | .newArray _ _, .field _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .storage _ => isFalse (by intro h; cases h) + | .newArray _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .cast _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .addrOf _ => isFalse (by intro h; cases h) + | .newArray _ _, .unary _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .index _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .intLit _, .newArray _ _ => isFalse (by intro h; cases h) + | .boolLit _, .newArray _ _ => isFalse (by intro h; cases h) + | .bytesLit _, .newArray _ _ => isFalse (by intro h; cases h) + | .newBytes _, .newArray _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .var _, .newArray _ _ => isFalse (by intro h; cases h) + | .env _, .newArray _ _ => isFalse (by intro h; cases h) + | .field _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .storage _, .newArray _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .cast _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .addrOf _, .newArray _ _ => isFalse (by intro h; cases h) + | .unary _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .index _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .intLit _, .boolLit _ => isFalse (by intro h; cases h) + | .intLit _, .var _ => isFalse (by intro h; cases h) + | .intLit _, .env _ => isFalse (by intro h; cases h) + | .intLit _, .field _ _ => isFalse (by intro h; cases h) + | .intLit _, .storage _ => isFalse (by intro h; cases h) + | .intLit _, .inRange _ _ => isFalse (by intro h; cases h) + | .intLit _, .cast _ _ => isFalse (by intro h; cases h) + | .intLit _, .addrOf _ => isFalse (by intro h; cases h) + | .intLit _, .unary _ _ => isFalse (by intro h; cases h) + | .intLit _, .binary _ _ _ => isFalse (by intro h; cases h) + | .intLit _, .index _ _ => isFalse (by intro h; cases h) + | .intLit _, .ite _ _ _ => isFalse (by intro h; cases h) + | .boolLit _, .intLit _ => isFalse (by intro h; cases h) + | .boolLit _, .var _ => isFalse (by intro h; cases h) + | .boolLit _, .env _ => isFalse (by intro h; cases h) + | .boolLit _, .field _ _ => isFalse (by intro h; cases h) + | .boolLit _, .storage _ => isFalse (by intro h; cases h) + | .boolLit _, .inRange _ _ => isFalse (by intro h; cases h) + | .boolLit _, .cast _ _ => isFalse (by intro h; cases h) + | .boolLit _, .addrOf _ => isFalse (by intro h; cases h) + | .boolLit _, .unary _ _ => isFalse (by intro h; cases h) + | .boolLit _, .binary _ _ _ => isFalse (by intro h; cases h) + | .boolLit _, .index _ _ => isFalse (by intro h; cases h) + | .boolLit _, .ite _ _ _ => isFalse (by intro h; cases h) + | .var _, .intLit _ => isFalse (by intro h; cases h) + | .var _, .boolLit _ => isFalse (by intro h; cases h) + | .var _, .env _ => isFalse (by intro h; cases h) + | .var _, .field _ _ => isFalse (by intro h; cases h) + | .var _, .storage _ => isFalse (by intro h; cases h) + | .var _, .inRange _ _ => isFalse (by intro h; cases h) + | .var _, .cast _ _ => isFalse (by intro h; cases h) + | .var _, .addrOf _ => isFalse (by intro h; cases h) + | .var _, .unary _ _ => isFalse (by intro h; cases h) + | .var _, .binary _ _ _ => isFalse (by intro h; cases h) + | .var _, .index _ _ => isFalse (by intro h; cases h) + | .var _, .ite _ _ _ => isFalse (by intro h; cases h) + | .env _, .intLit _ => isFalse (by intro h; cases h) + | .env _, .boolLit _ => isFalse (by intro h; cases h) + | .env _, .var _ => isFalse (by intro h; cases h) + | .env _, .field _ _ => isFalse (by intro h; cases h) + | .env _, .storage _ => isFalse (by intro h; cases h) + | .env _, .inRange _ _ => isFalse (by intro h; cases h) + | .env _, .cast _ _ => isFalse (by intro h; cases h) + | .env _, .addrOf _ => isFalse (by intro h; cases h) + | .env _, .unary _ _ => isFalse (by intro h; cases h) + | .env _, .binary _ _ _ => isFalse (by intro h; cases h) + | .env _, .index _ _ => isFalse (by intro h; cases h) + | .env _, .ite _ _ _ => isFalse (by intro h; cases h) + | .field _ _, .intLit _ => isFalse (by intro h; cases h) + | .field _ _, .boolLit _ => isFalse (by intro h; cases h) + | .field _ _, .var _ => isFalse (by intro h; cases h) + | .field _ _, .env _ => isFalse (by intro h; cases h) + | .field _ _, .storage _ => isFalse (by intro h; cases h) + | .field _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .field _ _, .cast _ _ => isFalse (by intro h; cases h) + | .field _ _, .addrOf _ => isFalse (by intro h; cases h) + | .field _ _, .unary _ _ => isFalse (by intro h; cases h) + | .field _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .field _ _, .index _ _ => isFalse (by intro h; cases h) + | .field _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .storage _, .intLit _ => isFalse (by intro h; cases h) + | .storage _, .boolLit _ => isFalse (by intro h; cases h) + | .storage _, .var _ => isFalse (by intro h; cases h) + | .storage _, .env _ => isFalse (by intro h; cases h) + | .storage _, .field _ _ => isFalse (by intro h; cases h) + | .storage _, .inRange _ _ => isFalse (by intro h; cases h) + | .storage _, .cast _ _ => isFalse (by intro h; cases h) + | .storage _, .addrOf _ => isFalse (by intro h; cases h) + | .storage _, .unary _ _ => isFalse (by intro h; cases h) + | .storage _, .binary _ _ _ => isFalse (by intro h; cases h) + | .storage _, .index _ _ => isFalse (by intro h; cases h) + | .storage _, .ite _ _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .intLit _ => isFalse (by intro h; cases h) + | .inRange _ _, .boolLit _ => isFalse (by intro h; cases h) + | .inRange _ _, .var _ => isFalse (by intro h; cases h) + | .inRange _ _, .env _ => isFalse (by intro h; cases h) + | .inRange _ _, .field _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .storage _ => isFalse (by intro h; cases h) + | .inRange _ _, .cast _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .addrOf _ => isFalse (by intro h; cases h) + | .inRange _ _, .unary _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .index _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .cast _ _, .intLit _ => isFalse (by intro h; cases h) + | .cast _ _, .boolLit _ => isFalse (by intro h; cases h) + | .cast _ _, .var _ => isFalse (by intro h; cases h) + | .cast _ _, .env _ => isFalse (by intro h; cases h) + | .cast _ _, .field _ _ => isFalse (by intro h; cases h) + | .cast _ _, .storage _ => isFalse (by intro h; cases h) + | .cast _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .cast _ _, .addrOf _ => isFalse (by intro h; cases h) + | .cast _ _, .unary _ _ => isFalse (by intro h; cases h) + | .cast _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .cast _ _, .index _ _ => isFalse (by intro h; cases h) + | .cast _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .addrOf _, .intLit _ => isFalse (by intro h; cases h) + | .addrOf _, .boolLit _ => isFalse (by intro h; cases h) + | .addrOf _, .var _ => isFalse (by intro h; cases h) + | .addrOf _, .env _ => isFalse (by intro h; cases h) + | .addrOf _, .field _ _ => isFalse (by intro h; cases h) + | .addrOf _, .storage _ => isFalse (by intro h; cases h) + | .addrOf _, .inRange _ _ => isFalse (by intro h; cases h) + | .addrOf _, .cast _ _ => isFalse (by intro h; cases h) + | .addrOf _, .unary _ _ => isFalse (by intro h; cases h) + | .addrOf _, .binary _ _ _ => isFalse (by intro h; cases h) + | .addrOf _, .index _ _ => isFalse (by intro h; cases h) + | .addrOf _, .ite _ _ _ => isFalse (by intro h; cases h) + | .unary _ _, .intLit _ => isFalse (by intro h; cases h) + | .unary _ _, .boolLit _ => isFalse (by intro h; cases h) + | .unary _ _, .var _ => isFalse (by intro h; cases h) + | .unary _ _, .env _ => isFalse (by intro h; cases h) + | .unary _ _, .field _ _ => isFalse (by intro h; cases h) + | .unary _ _, .storage _ => isFalse (by intro h; cases h) + | .unary _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .unary _ _, .cast _ _ => isFalse (by intro h; cases h) + | .unary _ _, .addrOf _ => isFalse (by intro h; cases h) + | .unary _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .unary _ _, .index _ _ => isFalse (by intro h; cases h) + | .unary _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .intLit _ => isFalse (by intro h; cases h) + | .binary _ _ _, .boolLit _ => isFalse (by intro h; cases h) + | .binary _ _ _, .var _ => isFalse (by intro h; cases h) + | .binary _ _ _, .env _ => isFalse (by intro h; cases h) + | .binary _ _ _, .field _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .storage _ => isFalse (by intro h; cases h) + | .binary _ _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .cast _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .addrOf _ => isFalse (by intro h; cases h) + | .binary _ _ _, .unary _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .index _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .index _ _, .intLit _ => isFalse (by intro h; cases h) + | .index _ _, .boolLit _ => isFalse (by intro h; cases h) + | .index _ _, .var _ => isFalse (by intro h; cases h) + | .index _ _, .env _ => isFalse (by intro h; cases h) + | .index _ _, .field _ _ => isFalse (by intro h; cases h) + | .index _ _, .storage _ => isFalse (by intro h; cases h) + | .index _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .index _ _, .cast _ _ => isFalse (by intro h; cases h) + | .index _ _, .addrOf _ => isFalse (by intro h; cases h) + | .index _ _, .unary _ _ => isFalse (by intro h; cases h) + | .index _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .index _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .intLit _ => isFalse (by intro h; cases h) + | .ite _ _ _, .boolLit _ => isFalse (by intro h; cases h) + | .ite _ _ _, .var _ => isFalse (by intro h; cases h) + | .ite _ _ _, .env _ => isFalse (by intro h; cases h) + | .ite _ _ _, .field _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .storage _ => isFalse (by intro h; cases h) + | .ite _ _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .cast _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .addrOf _ => isFalse (by intro h; cases h) + | .ite _ _ _, .unary _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .index _ _ => isFalse (by intro h; cases h) + | .bytesLit _, .intLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .boolLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .var _ => isFalse (by intro h; cases h) + | .bytesLit _, .env _ => isFalse (by intro h; cases h) + | .bytesLit _, .field _ _ => isFalse (by intro h; cases h) + | .bytesLit _, .storage _ => isFalse (by intro h; cases h) + | .bytesLit _, .inRange _ _ => isFalse (by intro h; cases h) + | .bytesLit _, .cast _ _ => isFalse (by intro h; cases h) + | .bytesLit _, .addrOf _ => isFalse (by intro h; cases h) + | .bytesLit _, .unary _ _ => isFalse (by intro h; cases h) + | .bytesLit _, .binary _ _ _ => isFalse (by intro h; cases h) + | .bytesLit _, .index _ _ => isFalse (by intro h; cases h) + | .bytesLit _, .ite _ _ _ => isFalse (by intro h; cases h) + | .bytesLit _, .newBytes _ => isFalse (by intro h; cases h) + | .intLit _, .bytesLit _ => isFalse (by intro h; cases h) + | .boolLit _, .bytesLit _ => isFalse (by intro h; cases h) + | .var _, .bytesLit _ => isFalse (by intro h; cases h) + | .env _, .bytesLit _ => isFalse (by intro h; cases h) + | .field _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .storage _, .bytesLit _ => isFalse (by intro h; cases h) + | .inRange _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .cast _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .addrOf _, .bytesLit _ => isFalse (by intro h; cases h) + | .unary _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .binary _ _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .index _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .ite _ _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .newBytes _, .intLit _ => isFalse (by intro h; cases h) + | .newBytes _, .boolLit _ => isFalse (by intro h; cases h) + | .newBytes _, .var _ => isFalse (by intro h; cases h) + | .newBytes _, .env _ => isFalse (by intro h; cases h) + | .newBytes _, .field _ _ => isFalse (by intro h; cases h) + | .newBytes _, .storage _ => isFalse (by intro h; cases h) + | .newBytes _, .inRange _ _ => isFalse (by intro h; cases h) + | .newBytes _, .cast _ _ => isFalse (by intro h; cases h) + | .newBytes _, .addrOf _ => isFalse (by intro h; cases h) + | .newBytes _, .unary _ _ => isFalse (by intro h; cases h) + | .newBytes _, .binary _ _ _ => isFalse (by intro h; cases h) + | .newBytes _, .index _ _ => isFalse (by intro h; cases h) + | .newBytes _, .ite _ _ _ => isFalse (by intro h; cases h) + | .newBytes _, .bytesLit _ => isFalse (by intro h; cases h) + | .intLit _, .newBytes _ => isFalse (by intro h; cases h) + | .boolLit _, .newBytes _ => isFalse (by intro h; cases h) + | .var _, .newBytes _ => isFalse (by intro h; cases h) + | .env _, .newBytes _ => isFalse (by intro h; cases h) + | .field _ _, .newBytes _ => isFalse (by intro h; cases h) + | .storage _, .newBytes _ => isFalse (by intro h; cases h) + | .inRange _ _, .newBytes _ => isFalse (by intro h; cases h) + | .cast _ _, .newBytes _ => isFalse (by intro h; cases h) + | .addrOf _, .newBytes _ => isFalse (by intro h; cases h) + | .unary _ _, .newBytes _ => isFalse (by intro h; cases h) + | .binary _ _ _, .newBytes _ => isFalse (by intro h; cases h) + | .index _ _, .newBytes _ => isFalse (by intro h; cases h) + | .ite _ _ _, .newBytes _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .intLit _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .boolLit _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .newBytes _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .var _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .env _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .field _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .storage _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .cast _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .addrOf _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .unary _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .index _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .intLit _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .boolLit _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesLit _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .newBytes _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .var _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .env _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .field _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .storage _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .cast _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .addrOf _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .unary _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .index _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .intLit _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .boolLit _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .newBytes _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .var _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .env _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .field _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .storage _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .cast _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .addrOf _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .unary _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .index _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .intLit _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .boolLit _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .bytesLit _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .newBytes _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .var _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .env _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .field _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .storage _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .cast _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .addrOf _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .unary _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .index _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .structLit nx fx, .structLit ny fy => + match (inferInstance : Decidable (nx = ny)), Expr.decEqNamedList fx fy with + | isTrue hn, isTrue hf => isTrue (by cases hn; cases hf; rfl) + | isFalse hn, _ => isFalse (by intro h; cases h; exact hn rfl) + | _, isFalse hf => isFalse (by intro h; cases h; exact hf rfl) + | .arrayLit xs, .arrayLit ys => + match Expr.decEqList xs ys with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .structLit _ _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .var _ => isFalse (by intro h; cases h) + | .var _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .env _ => isFalse (by intro h; cases h) + | .env _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .arrayLit _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .var _ => isFalse (by intro h; cases h) + | .var _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .env _ => isFalse (by intro h; cases h) + | .env _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .structLit _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .structLit _ _ => isFalse (by intro h; cases h) + | .tupleLit xs, .tupleLit ys => + match Expr.decEqList xs ys with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .tupleLit _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .var _ => isFalse (by intro h; cases h) + | .var _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .env _ => isFalse (by intro h; cases h) + | .env _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .keccak256 x, .keccak256 y => + match Expr.decEq x y with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .keccak256 _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .var _ => isFalse (by intro h; cases h) + | .var _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .env _ => isFalse (by intro h; cases h) + | .env _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .keccak256 _ => isFalse (by intro h; cases h) + | .abiEncodePacked xs, .abiEncodePacked ys => + match Expr.decEqTypedList xs ys with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .abiEncodeCall nx xs, .abiEncodeCall ny ys => + match (inferInstance : Decidable (nx = ny)), Expr.decEqList xs ys with + | isTrue hn, isTrue hs => isTrue (by cases hn; cases hs; rfl) + | isFalse hn, _ => isFalse (by intro h; cases h; exact hn rfl) + | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) + | .abiDecode tx x, .abiDecode ty y => + match (inferInstance : Decidable (tx = ty)), Expr.decEq x y with + | isTrue ht, isTrue hx => isTrue (by cases ht; cases hx; rfl) + | isFalse ht, _ => isFalse (by intro h; cases h; exact ht rfl) + | _, isFalse hx => isFalse (by intro h; cases h; exact hx rfl) + | .abiEncodeCall _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .var _ => isFalse (by intro h; cases h) + | .var _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .env _ => isFalse (by intro h; cases h) + | .env _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .var _ => isFalse (by intro h; cases h) + | .var _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .env _ => isFalse (by intro h; cases h) + | .env _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .var _ => isFalse (by intro h; cases h) + | .var _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .env _ => isFalse (by intro h; cases h) + | .env _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .extCodeSize x, .extCodeSize y => + match Expr.decEq x y with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .fixedBytesLit nx bx, .fixedBytesLit ny byy => + match (inferInstance : Decidable (nx = ny)), (inferInstance : Decidable (bx = byy)) with + | isTrue hn, isTrue hb => isTrue (by cases hn; cases hb; rfl) + | isFalse hn, _ => isFalse (by intro h; cases h; exact hn rfl) + | _, isFalse hb => isFalse (by intro h; cases h; exact hb rfl) + | .extCodeSize _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .var _ => isFalse (by intro h; cases h) + | .var _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .env _ => isFalse (by intro h; cases h) + | .env _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodePrefix ax lx, .extCodePrefix ay ly => + match Expr.decEq ax ay, Expr.decEq lx ly with + | isTrue ha, isTrue hl => isTrue (by cases ha; cases hl; rfl) + | isFalse ha, _ => isFalse (by intro h'; cases h'; exact ha rfl) + | _, isFalse hl => isFalse (by intro h'; cases h'; exact hl rfl) + | .tupleGet ex nx, .tupleGet ey ny => + match Expr.decEq ex ey, (inferInstance : Decidable (nx = ny)) with + | isTrue he, isTrue hn => isTrue (by cases he; cases hn; rfl) + | isFalse he, _ => isFalse (by intro h'; cases h'; exact he rfl) + | _, isFalse hn => isFalse (by intro h'; cases h'; exact hn rfl) + | .blockhash x, .blockhash y => + match Expr.decEq x y with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .balanceOf x, .balanceOf y => + match Expr.decEq x y with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .extCodeHash x, .extCodeHash y => + match Expr.decEq x y with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .tupleGet _ _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .var _ => isFalse (by intro h; cases h) + | .var _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .env _ => isFalse (by intro h; cases h) + | .env _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .blockhash _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .var _ => isFalse (by intro h; cases h) + | .var _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .env _ => isFalse (by intro h; cases h) + | .env _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .blockhash _ => isFalse (by intro h; cases h) + | .balanceOf _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .var _ => isFalse (by intro h; cases h) + | .var _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .env _ => isFalse (by intro h; cases h) + | .env _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .extCodeHash _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .var _ => isFalse (by intro h; cases h) + | .var _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .env _ => isFalse (by intro h; cases h) + | .env _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .tupleGet _ _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .tupleGet _ _ => isFalse (by intro h; cases h) + | .blockhash _, .balanceOf _ => isFalse (by intro h; cases h) + | .balanceOf _, .blockhash _ => isFalse (by intro h; cases h) + | .blockhash _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .blockhash _ => isFalse (by intro h; cases h) + | .balanceOf _, .extCodeHash _ => isFalse (by intro h; cases h) + | .extCodeHash _, .balanceOf _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .var _ => isFalse (by intro h; cases h) + | .var _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .env _ => isFalse (by intro h; cases h) + | .env _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) + | .abiEncodeCall _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .abiDecode _ _ => isFalse (by intro h; cases h) + | .abiDecode _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .extCodeSize _ => isFalse (by intro h; cases h) + | .extCodeSize _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .extCodePrefix _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .intLit _ => isFalse (by intro h; cases h) + | .intLit _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .boolLit _ => isFalse (by intro h; cases h) + | .boolLit _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .bytesLit _ => isFalse (by intro h; cases h) + | .bytesLit _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .newBytes _ => isFalse (by intro h; cases h) + | .newBytes _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .newArray _ _ => isFalse (by intro h; cases h) + | .newArray _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .structLit _ _ => isFalse (by intro h; cases h) + | .structLit _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .arrayLit _ => isFalse (by intro h; cases h) + | .arrayLit _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .tupleLit _ => isFalse (by intro h; cases h) + | .tupleLit _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) + | .bytesSlice _ _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .var _ => isFalse (by intro h; cases h) + | .var _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .env _ => isFalse (by intro h; cases h) + | .env _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .field _ _ => isFalse (by intro h; cases h) + | .field _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .storage _ => isFalse (by intro h; cases h) + | .storage _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .inRange _ _ => isFalse (by intro h; cases h) + | .inRange _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .cast _ _ => isFalse (by intro h; cases h) + | .cast _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .addrOf _ => isFalse (by intro h; cases h) + | .addrOf _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .unary _ _ => isFalse (by intro h; cases h) + | .unary _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .binary _ _ _ => isFalse (by intro h; cases h) + | .binary _ _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .index _ _ => isFalse (by intro h; cases h) + | .index _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .arrayLength _ _ => isFalse (by intro h; cases h) + | .arrayLength _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .keccak256 _ => isFalse (by intro h; cases h) + | .keccak256 _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + | .fixedBytesLit _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) + | .abiEncodePacked _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) + + private def Expr.decEqList : (as bs : List Expr) -> Decidable (as = bs) + | [], [] => isTrue rfl + | a :: as, b :: bs => + match Expr.decEq a b, Expr.decEqList as bs with + | isTrue ha, isTrue hs => isTrue (by cases ha; cases hs; rfl) + | isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) + | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) + | [], _ :: _ => isFalse (by intro h; cases h) + | _ :: _, [] => isFalse (by intro h; cases h) + + private def Expr.decEqNamedList : (as bs : List (Ident × Expr)) -> Decidable (as = bs) + | [], [] => isTrue rfl + | (nx, ex) :: as, (ny, ey) :: bs => + match (inferInstance : Decidable (nx = ny)), Expr.decEq ex ey, Expr.decEqNamedList as bs with + | isTrue hn, isTrue he, isTrue hs => isTrue (by cases hn; cases he; cases hs; rfl) + | isFalse hn, _, _ => isFalse (by intro h; cases h; exact hn rfl) + | _, isFalse he, _ => isFalse (by intro h; cases h; exact he rfl) + | _, _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) + | [], _ :: _ => isFalse (by intro h; cases h) + | _ :: _, [] => isFalse (by intro h; cases h) + + private def Expr.decEqTypedList : (as bs : List (ABIType × Expr)) -> Decidable (as = bs) + | [], [] => isTrue rfl + | (tx, ex) :: as, (ty, ey) :: bs => + match (inferInstance : Decidable (tx = ty)), Expr.decEq ex ey, Expr.decEqTypedList as bs with + | isTrue ht, isTrue he, isTrue hs => isTrue (by cases ht; cases he; cases hs; rfl) + | isFalse ht, _, _ => isFalse (by intro h; cases h; exact ht rfl) + | _, isFalse he, _ => isFalse (by intro h; cases h; exact he rfl) + | _, _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) + | [], _ :: _ => isFalse (by intro h; cases h) + | _ :: _, [] => isFalse (by intro h; cases h) + + private def StorageRefStep.decEq : (a b : StorageRefStep) -> Decidable (a = b) + | .field x, .field y => + match (inferInstance : Decidable (x = y)) with + | isTrue h => isTrue (by subst y; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .mindex x, .mindex y => + match Expr.decEq x y with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .aindex x, .aindex y => + match Expr.decEq x y with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .field _, .mindex _ => isFalse (by intro h; cases h) + | .field _, .aindex _ => isFalse (by intro h; cases h) + | .mindex _, .field _ => isFalse (by intro h; cases h) + | .mindex _, .aindex _ => isFalse (by intro h; cases h) + | .aindex _, .field _ => isFalse (by intro h; cases h) + | .aindex _, .mindex _ => isFalse (by intro h; cases h) + + private def StorageRef.decEq : (a b : StorageRef) -> Decidable (a = b) + | ⟨base, steps⟩, ⟨base', steps'⟩ => + match (inferInstance : Decidable (base = base')), StorageRefStep.decEqList steps steps' with + | isTrue hb, isTrue hs => isTrue (by cases hb; cases hs; rfl) + | isFalse hb, _ => isFalse (by intro h; cases h; exact hb rfl) + | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) + + private def StorageRefStep.decEqList : (as bs : List StorageRefStep) -> Decidable (as = bs) + | [], [] => isTrue rfl + | a :: as, b :: bs => + match StorageRefStep.decEq a b, StorageRefStep.decEqList as bs with + | isTrue ha, isTrue hs => isTrue (by cases ha; cases hs; rfl) + | isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) + | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) + | [], _ :: _ => isFalse (by intro h; cases h) + | _ :: _, [] => isFalse (by intro h; cases h) +end + +instance : DecidableEq Expr := + Expr.decEq + +instance : DecidableEq StorageRefStep := + StorageRefStep.decEq + +instance : DecidableEq StorageRef := + StorageRef.decEq + +deriving instance DecidableEq for AssignRhs + +mutual + private def Stmt.decEq : (a b : Stmt) -> Decidable (a = b) + | .letDecl nx tx ex, .letDecl ny ty ey => + match (inferInstance : Decidable (nx = ny)), (inferInstance : Decidable (tx = ty)), Expr.decEq ex ey with + | isTrue hn, isTrue ht, isTrue he => isTrue (by cases hn; cases ht; cases he; rfl) + | isFalse hn, _, _ => isFalse (by intro h; cases h; exact hn rfl) + | _, isFalse ht, _ => isFalse (by intro h; cases h; exact ht rfl) + | _, _, isFalse he => isFalse (by intro h; cases h; exact he rfl) + | .letStorage nx rx, .letStorage ny ry => + match (inferInstance : Decidable (nx = ny)), StorageRef.decEq rx ry with + | isTrue hn, isTrue hr => isTrue (by cases hn; cases hr; rfl) + | isFalse hn, _ => isFalse (by intro h; cases h; exact hn rfl) + | _, isFalse hr => isFalse (by intro h; cases h; exact hr rfl) + | .letGas nx, .letGas ny => + match (inferInstance : Decidable (nx = ny)) with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .letGas _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .assign _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .require _ => isFalse (by intro h; cases h) + | .require _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .while _ _ => isFalse (by intro h; cases h) + | .while _ _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .return _ => isFalse (by intro h; cases h) + | .return _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .break => isFalse (by intro h; cases h) + | .break, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .continue => isFalse (by intro h; cases h) + | .continue, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .letGas _ => isFalse (by intro h; cases h) + | .letGas _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .letGas _ => isFalse (by intro h; cases h) + | .assign ox sx ex, .assign oy sy ey => + match (inferInstance : Decidable (ox = oy)), StorageRef.decEq sx sy, Expr.decEq ex ey with + | isTrue ho, isTrue hs, isTrue he => isTrue (by cases ho; cases hs; cases he; rfl) + | isFalse ho, _, _ => isFalse (by intro h; cases h; exact ho rfl) + | _, isFalse hs, _ => isFalse (by intro h; cases h; exact hs rfl) + | _, _, isFalse he => isFalse (by intro h; cases h; exact he rfl) + | .require ex, .require ey => + match Expr.decEq ex ey with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .while cx bx, .while cy bodyY => + match Expr.decEq cx cy, Stmt.decEqList bx bodyY with + | isTrue hc, isTrue hb => isTrue (by cases hc; cases hb; rfl) + | isFalse hc, _ => isFalse (by intro h; cases h; exact hc rfl) + | _, isFalse hb => isFalse (by intro h; cases h; exact hb rfl) + | .ite cx tx ex, .ite cy ty ey => + match Expr.decEq cx cy, Stmt.decEqList tx ty, Stmt.decEqList ex ey with + | isTrue hc, isTrue ht, isTrue he => isTrue (by cases hc; cases ht; cases he; rfl) + | isFalse hc, _, _ => isFalse (by intro h; cases h; exact hc rfl) + | _, isFalse ht, _ => isFalse (by intro h; cases h; exact ht rfl) + | _, _, isFalse he => isFalse (by intro h; cases h; exact he rfl) + | .new nx vx ax rx sx, .new ny vy ay ry sy => + match (inferInstance : Decidable (nx = ny)), Expr.decEq vx vy, (inferInstance : Decidable (ax = ay)), (inferInstance : Decidable (rx = ry)), (inferInstance : Decidable (sx = sy)) with + | isTrue hn, isTrue hv, isTrue ha, isTrue hr, isTrue hs => isTrue (by cases hn; cases hv; cases ha; cases hr; cases hs; rfl) + | isFalse hn, _, _, _, _ => isFalse (by intro h; cases h; exact hn rfl) + | _, isFalse hv, _, _, _ => isFalse (by intro h; cases h; exact hv rfl) + | _, _, isFalse ha, _, _ => isFalse (by intro h; cases h; exact ha rfl) + | _, _, _, isFalse hr, _ => isFalse (by intro h; cases h; exact hr rfl) + | _, _, _, _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) + | .internalCall nx ax rx, .internalCall ny ay ry => + match (inferInstance : Decidable (nx = ny)), (inferInstance : Decidable (ax = ay)), (inferInstance : Decidable (rx = ry)) with + | isTrue hn, isTrue ha, isTrue hr => isTrue (by cases hn; cases ha; cases hr; rfl) + | isFalse hn, _, _ => isFalse (by intro h; cases h; exact hn rfl) + | _, isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) + | _, _, isFalse hr => isFalse (by intro h; cases h; exact hr rfl) + | .externalCall tx nx vx ax rx px, .externalCall ty ny vy ay ry py => + match Expr.decEq tx ty, (inferInstance : Decidable (nx = ny)), Expr.decEq vx vy, + (inferInstance : Decidable (ax = ay)), (inferInstance : Decidable (rx = ry)), + (inferInstance : Decidable (px = py)) with + | isTrue ht, isTrue hn, isTrue hv, isTrue ha, isTrue hr, isTrue hp => + isTrue (by cases ht; cases hn; cases hv; cases ha; cases hr; cases hp; rfl) + | isFalse ht, _, _, _, _, _ => isFalse (by intro h; cases h; exact ht rfl) + | _, isFalse hn, _, _, _, _ => isFalse (by intro h; cases h; exact hn rfl) + | _, _, isFalse hv, _, _, _ => isFalse (by intro h; cases h; exact hv rfl) + | _, _, _, isFalse ha, _, _ => isFalse (by intro h; cases h; exact ha rfl) + | _, _, _, _, isFalse hr, _ => isFalse (by intro h; cases h; exact hr rfl) + | _, _, _, _, _, isFalse hp => isFalse (by intro h; cases h; exact hp rfl) + | .lowLevelCall tx vx cx ox dx px, .lowLevelCall ty vy cy oy dy py => + match Expr.decEq tx ty, Expr.decEq vx vy, Expr.decEq cx cy, (inferInstance : Decidable (ox = oy)), (inferInstance : Decidable (dx = dy)), (inferInstance : Decidable (px = py)) with + | isTrue ht, isTrue hv, isTrue hc, isTrue ho, isTrue hd, isTrue hp => isTrue (by cases ht; cases hv; cases hc; cases ho; cases hd; cases hp; rfl) + | isFalse ht, _, _, _, _, _ => isFalse (by intro h; cases h; exact ht rfl) + | _, isFalse hv, _, _, _, _ => isFalse (by intro h; cases h; exact hv rfl) + | _, _, isFalse hc, _, _, _ => isFalse (by intro h; cases h; exact hc rfl) + | _, _, _, isFalse ho, _, _ => isFalse (by intro h; cases h; exact ho rfl) + | _, _, _, _, isFalse hd, _ => isFalse (by intro h; cases h; exact hd rfl) + | _, _, _, _, _, isFalse hp => isFalse (by intro h; cases h; exact hp rfl) + | .delegateCall tx cx ox dx, .delegateCall ty cy oy dy => + match Expr.decEq tx ty, Expr.decEq cx cy, (inferInstance : Decidable (ox = oy)), + (inferInstance : Decidable (dx = dy)) with + | isTrue ht, isTrue hc, isTrue ho, isTrue hd => + isTrue (by cases ht; cases hc; cases ho; cases hd; rfl) + | isFalse ht, _, _, _ => isFalse (by intro h; cases h; exact ht rfl) + | _, isFalse hc, _, _ => isFalse (by intro h; cases h; exact hc rfl) + | _, _, isFalse ho, _ => isFalse (by intro h; cases h; exact ho rfl) + | _, _, _, isFalse hd => isFalse (by intro h; cases h; exact hd rfl) + | .checkedCall rx nx vx ax retx sx ex cx px, + .checkedCall ry ny vy ay rety sy ey cy py => + match Expr.decEq rx ry, (inferInstance : Decidable (nx = ny)), Expr.decEq vx vy, + (inferInstance : Decidable (ax = ay)), (inferInstance : Decidable (retx = rety)), + Stmt.decEqList sx sy, (inferInstance : Decidable (ex = ey)), Stmt.decEqList cx cy, + (inferInstance : Decidable (px = py)) with + | isTrue hr, isTrue hn, isTrue hv, isTrue ha, isTrue hret, isTrue hs, isTrue he, + isTrue hc, isTrue hp => + isTrue (by + cases hr; cases hn; cases hv; cases ha; cases hret; cases hs; cases he + cases hc; cases hp; rfl) + | isFalse hr, _, _, _, _, _, _, _, _ => isFalse (by intro h; cases h; exact hr rfl) + | _, isFalse hn, _, _, _, _, _, _, _ => isFalse (by intro h; cases h; exact hn rfl) + | _, _, isFalse hv, _, _, _, _, _, _ => isFalse (by intro h; cases h; exact hv rfl) + | _, _, _, isFalse ha, _, _, _, _, _ => isFalse (by intro h; cases h; exact ha rfl) + | _, _, _, _, isFalse hret, _, _, _, _ => isFalse (by intro h; cases h; exact hret rfl) + | _, _, _, _, _, isFalse hs, _, _, _ => isFalse (by intro h; cases h; exact hs rfl) + | _, _, _, _, _, _, isFalse he, _, _ => isFalse (by intro h; cases h; exact he rfl) + | _, _, _, _, _, _, _, isFalse hc, _ => isFalse (by intro h; cases h; exact hc rfl) + | _, _, _, _, _, _, _, _, isFalse hp => isFalse (by intro h; cases h; exact hp rfl) + | .return ex, .return ey => + match Expr.decEqList ex ey with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .break, .break => isTrue rfl + | .continue, .continue => isTrue rfl + | .letStorage _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .assign _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .require _ => isFalse (by intro h; cases h) + | .require _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .while _ _ => isFalse (by intro h; cases h) + | .while _ _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .return _ => isFalse (by intro h; cases h) + | .return _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .break => isFalse (by intro h; cases h) + | .break, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .continue => isFalse (by intro h; cases h) + | .continue, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .require _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .while _ _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .return _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .break => isFalse (by intro h; cases h) + | .letDecl _ _ _, .continue => isFalse (by intro h; cases h) + | .assign _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .require _ => isFalse (by intro h; cases h) + | .assign _ _ _, .while _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .return _ => isFalse (by intro h; cases h) + | .assign _ _ _, .break => isFalse (by intro h; cases h) + | .assign _ _ _, .continue => isFalse (by intro h; cases h) + | .require _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .require _, .assign _ _ _ => isFalse (by intro h; cases h) + | .require _, .while _ _ => isFalse (by intro h; cases h) + | .require _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .require _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .require _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .require _, .return _ => isFalse (by intro h; cases h) + | .require _, .break => isFalse (by intro h; cases h) + | .require _, .continue => isFalse (by intro h; cases h) + | .while _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .while _ _, .assign _ _ _ => isFalse (by intro h; cases h) + | .while _ _, .require _ => isFalse (by intro h; cases h) + | .while _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .while _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .while _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .while _ _, .return _ => isFalse (by intro h; cases h) + | .while _ _, .break => isFalse (by intro h; cases h) + | .while _ _, .continue => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .require _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .while _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .return _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .break => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .continue => isFalse (by intro h; cases h) + | .internalCall _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .require _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .while _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .return _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .break => isFalse (by intro h; cases h) + | .internalCall _ _ _, .continue => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .require _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .while _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .return _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .break => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .continue => isFalse (by intro h; cases h) + | .return _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .return _, .assign _ _ _ => isFalse (by intro h; cases h) + | .return _, .require _ => isFalse (by intro h; cases h) + | .return _, .while _ _ => isFalse (by intro h; cases h) + | .return _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .return _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .return _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .return _, .break => isFalse (by intro h; cases h) + | .return _, .continue => isFalse (by intro h; cases h) + | .break, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .break, .assign _ _ _ => isFalse (by intro h; cases h) + | .break, .require _ => isFalse (by intro h; cases h) + | .break, .while _ _ => isFalse (by intro h; cases h) + | .break, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .break, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .break, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .break, .return _ => isFalse (by intro h; cases h) + | .break, .continue => isFalse (by intro h; cases h) + | .continue, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .continue, .assign _ _ _ => isFalse (by intro h; cases h) + | .continue, .require _ => isFalse (by intro h; cases h) + | .continue, .while _ _ => isFalse (by intro h; cases h) + | .continue, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .continue, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .continue, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .continue, .return _ => isFalse (by intro h; cases h) + | .continue, .break => isFalse (by intro h; cases h) + | .letDecl _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .require _, .ite _ _ _ => isFalse (by intro h; cases h) + | .while _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .return _, .ite _ _ _ => isFalse (by intro h; cases h) + | .break, .ite _ _ _ => isFalse (by intro h; cases h) + | .continue, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .require _ => isFalse (by intro h; cases h) + | .ite _ _ _, .while _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .return _ => isFalse (by intro h; cases h) + | .ite _ _ _, .break => isFalse (by intro h; cases h) + | .ite _ _ _, .continue => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .require _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .while _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .return _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .break => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .continue => isFalse (by intro h; cases h) + | .letDecl _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .require _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .while _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .return _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .break, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .continue, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .require _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .while _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .return _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .break => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .continue => isFalse (by intro h; cases h) + | .letDecl _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .require _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .while _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .return _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .break, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .continue, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .push rx vx, .push ry vy => + match StorageRef.decEq rx ry, (inferInstance : Decidable (vx = vy)) with + | isTrue hr, isTrue hv => isTrue (by cases hr; cases hv; rfl) + | isFalse hr, _ => isFalse (by intro h; cases h; exact hr rfl) + | _, isFalse hv => isFalse (by intro h; cases h; exact hv rfl) + | .pop rx, .pop ry => + match StorageRef.decEq rx ry with + | isTrue hr => isTrue (by cases hr; rfl) + | isFalse hr => isFalse (by intro h; cases h; exact hr rfl) + | .delete rx, .delete ry => + match StorageRef.decEq rx ry with + | isTrue hr => isTrue (by cases hr; rfl) + | isFalse hr => isFalse (by intro h; cases h; exact hr rfl) + | .delete _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .assign _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .require _ => isFalse (by intro h; cases h) + | .require _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .while _ _ => isFalse (by intro h; cases h) + | .while _ _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .return _ => isFalse (by intro h; cases h) + | .return _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .break => isFalse (by intro h; cases h) + | .break, .delete _ => isFalse (by intro h; cases h) + | .delete _, .continue => isFalse (by intro h; cases h) + | .continue, .delete _ => isFalse (by intro h; cases h) + | .delete _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .delete _ => isFalse (by intro h; cases h) + | .push _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .assign _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .require _ => isFalse (by intro h; cases h) + | .require _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .while _ _ => isFalse (by intro h; cases h) + | .while _ _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .return _ => isFalse (by intro h; cases h) + | .return _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .break => isFalse (by intro h; cases h) + | .break, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .continue => isFalse (by intro h; cases h) + | .continue, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .push _ _ => isFalse (by intro h; cases h) + | .pop _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .assign _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .require _ => isFalse (by intro h; cases h) + | .require _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .while _ _ => isFalse (by intro h; cases h) + | .while _ _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .return _ => isFalse (by intro h; cases h) + | .return _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .break => isFalse (by intro h; cases h) + | .break, .pop _ => isFalse (by intro h; cases h) + | .pop _, .continue => isFalse (by intro h; cases h) + | .continue, .pop _ => isFalse (by intro h; cases h) + | .for ix cx px bx, .for iy cy py by_ => + match Stmt.decEqList ix iy, Expr.decEq cx cy, Stmt.decEqList px py, Stmt.decEqList bx by_ with + | isTrue hi, isTrue hc, isTrue hp, isTrue hb => isTrue (by cases hi; cases hc; cases hp; cases hb; rfl) + | isFalse hi, _, _, _ => isFalse (by intro h; cases h; exact hi rfl) + | _, isFalse hc, _, _ => isFalse (by intro h; cases h; exact hc rfl) + | _, _, isFalse hp, _ => isFalse (by intro h; cases h; exact hp rfl) + | _, _, _, isFalse hb => isFalse (by intro h; cases h; exact hb rfl) + | .for _ _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .require _ => isFalse (by intro h; cases h) + | .require _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .while _ _ => isFalse (by intro h; cases h) + | .while _ _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .return _ => isFalse (by intro h; cases h) + | .return _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .break => isFalse (by intro h; cases h) + | .break, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .continue => isFalse (by intro h; cases h) + | .continue, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) + | .letDecl _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) + | .letStorage _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) + | .assign _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .require _ => isFalse (by intro h; cases h) + | .require _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .while _ _ => isFalse (by intro h; cases h) + | .while _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) + | .for _ _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) + | .ite _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) + | .new _ _ _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) + | .internalCall _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .externalCall _ _ _ _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) + | .lowLevelCall _ _ _ _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => + isFalse (by intro h; cases h) + | .checkedCall _ _ _ _ _ _ _ _ _, .delegateCall _ _ _ _ => + isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .return _ => isFalse (by intro h; cases h) + | .return _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .break => isFalse (by intro h; cases h) + | .break, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .continue => isFalse (by intro h; cases h) + | .continue, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .push _ _ => isFalse (by intro h; cases h) + | .push _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .pop _ => isFalse (by intro h; cases h) + | .pop _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + | .delegateCall _ _ _ _, .delete _ => isFalse (by intro h; cases h) + | .delete _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) + + private def Stmt.decEqList : (as bs : List Stmt) -> Decidable (as = bs) + | [], [] => isTrue rfl + | a :: as, b :: bs => + match Stmt.decEq a b, Stmt.decEqList as bs with + | isTrue ha, isTrue hs => isTrue (by cases ha; cases hs; rfl) + | isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) + | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) + | [], _ :: _ => isFalse (by intro h; cases h) + | _ :: _, [] => isFalse (by intro h; cases h) +end + +instance : DecidableEq Stmt := + Stmt.decEq + +deriving instance DecidableEq for Param + +deriving instance DecidableEq for StorageDecl + +deriving instance DecidableEq for ConstructorDecl + +deriving instance DecidableEq for StructDecl + +deriving instance DecidableEq for FunctionDecl + +deriving instance DecidableEq for TransitionDecl + +deriving instance DecidableEq for ContractDecl + +end Solm From 90039e4f1d82a24dd5ff3cb45c97e1fc3bd0ee62 Mon Sep 17 00:00:00 2001 From: zoep Date: Sat, 25 Jul 2026 15:16:59 +0300 Subject: [PATCH 02/38] Solm: Syntax nits --- Solm/Syntax.lean | 2212 +--------------------------------------- Solm/Syntax/Basic.lean | 58 +- 2 files changed, 34 insertions(+), 2236 deletions(-) diff --git a/Solm/Syntax.lean b/Solm/Syntax.lean index 4117b647..8d0386be 100644 --- a/Solm/Syntax.lean +++ b/Solm/Syntax.lean @@ -1,2210 +1,2 @@ -import EVM.Types -import ABI.Types - -namespace Solm - -open ABI - -abbrev Ident := String - -/- Basically all values that can be a key for a mapping. - In other words all types that can fit in a word. -/ -inductive KeyValue where - | int : Int -> KeyValue - | bool : Bool -> KeyValue - | address : EVM.Address -> KeyValue - | fixedBytes : Fin 32 -> List UInt8 -> KeyValue - deriving DecidableEq, Repr, Inhabited - -inductive EvaledStorageRefStep where - | field : Ident -> EvaledStorageRefStep - | tupleElem : Nat -> EvaledStorageRefStep - | mindex : KeyValue -> EvaledStorageRefStep - | aindex : KeyValue -> EvaledStorageRefStep - /- Marker for "the length of the array reached so far". A distinct ref the layout - resolves to wherever it stores that array's length — the semantics commits to no - particular slot convention (solc puts it at the array's base slot; another layout - may put it elsewhere). Only the array's length query produces this step. -/ - | length : EvaledStorageRefStep - deriving DecidableEq, Repr, Inhabited - -structure EvaledStorageRef where - base : Ident - steps : List EvaledStorageRefStep := [] - deriving DecidableEq, Repr, Inhabited - -/- Storage slots may either hold Elementary ABI values or nested mappings. -/ --- Note: name changed from StorageRefType, because in Solidity terminology --- a slot is a storage word, not a location for an item in storage --- of which there may be multiple in a given word -inductive StorageType where - | elem : ElemType -> StorageType - | mapping : ElemType -> StorageType -> StorageType -- Check more on Keytype here - | contract : Ident -> StorageType - -- Keeping the fields inside the struct so that recursion over StorageType is well-founded - -- So right now this refers to the AST, not the surface syntax - | struct : Ident -> List (Ident × StorageType) -> StorageType - | tuple : List StorageType -> StorageType - | array : StorageType -> Nat -> StorageType - | dynamicArray : StorageType -> StorageType - -- Conditionally compact layout used by solidity for bytes and strings - | bytes : StorageType - | string : StorageType - deriving Repr, Inhabited - -mutual - private def StorageType.decEq : (a b : StorageType) -> Decidable (a = b) - | .elem p, .elem q => - match (inferInstance : Decidable (p = q)) with - | isTrue h => isTrue (by subst q; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .mapping k t, .mapping l u => - match (inferInstance : Decidable (k = l)), StorageType.decEq t u with - | isTrue hk, isTrue ht => isTrue (by subst l; subst u; rfl) - | isFalse hk, _ => isFalse (by intro h'; cases h'; exact hk rfl) - | _, isFalse ht => isFalse (by intro h'; cases h'; exact ht rfl) - | .contract x, .contract y => - match (inferInstance : Decidable (x = y)) with - | isTrue h => isTrue (by subst y; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .struct x fx, .struct y fy => - match (inferInstance : Decidable (x = y)), StorageType.decEqNamedList fx fy with - | isTrue h, isTrue hf => isTrue (by subst y; cases hf; rfl) - | _, isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | isFalse h, _ => isFalse (by intro h'; cases h'; exact h rfl) - | .tuple xs, .tuple ys => - match StorageType.decEqList xs ys with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .array t n, .array u m => - match StorageType.decEq t u, (inferInstance : Decidable (n = m)) with - | isTrue ht, isTrue hn => isTrue (by subst u; subst m; rfl) - | isFalse ht, _ => isFalse (by intro h'; cases h'; exact ht rfl) - | _, isFalse hn => isFalse (by intro h'; cases h'; exact hn rfl) - | .dynamicArray t, .dynamicArray u => - match StorageType.decEq t u with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .bytes, .bytes => isTrue rfl - | .string, .string => isTrue rfl - | .elem _, .mapping _ _ => isFalse (by intro h; cases h) - | .elem _, .contract _ => isFalse (by intro h; cases h) - | .elem _, .struct _ _ => isFalse (by intro h; cases h) - | .elem _, .tuple _ => isFalse (by intro h; cases h) - | .elem _, .array _ _ => isFalse (by intro h; cases h) - | .elem _, .dynamicArray _ => isFalse (by intro h; cases h) - | .elem _, .bytes => isFalse (by intro h; cases h) - | .elem _, .string => isFalse (by intro h; cases h) - | .mapping _ _, .elem _ => isFalse (by intro h; cases h) - | .mapping _ _, .contract _ => isFalse (by intro h; cases h) - | .mapping _ _, .struct _ _ => isFalse (by intro h; cases h) - | .mapping _ _, .tuple _ => isFalse (by intro h; cases h) - | .mapping _ _, .array _ _ => isFalse (by intro h; cases h) - | .mapping _ _, .dynamicArray _ => isFalse (by intro h; cases h) - | .mapping _ _, .bytes => isFalse (by intro h; cases h) - | .mapping _ _, .string => isFalse (by intro h; cases h) - | .contract _, .elem _ => isFalse (by intro h; cases h) - | .contract _, .mapping _ _ => isFalse (by intro h; cases h) - | .contract _, .struct _ _ => isFalse (by intro h; cases h) - | .contract _, .tuple _ => isFalse (by intro h; cases h) - | .contract _, .array _ _ => isFalse (by intro h; cases h) - | .contract _, .dynamicArray _ => isFalse (by intro h; cases h) - | .contract _, .bytes => isFalse (by intro h; cases h) - | .contract _, .string => isFalse (by intro h; cases h) - | .struct _ _, .elem _ => isFalse (by intro h; cases h) - | .struct _ _, .mapping _ _ => isFalse (by intro h; cases h) - | .struct _ _, .contract _ => isFalse (by intro h; cases h) - | .struct _ _, .tuple _ => isFalse (by intro h; cases h) - | .struct _ _, .array _ _ => isFalse (by intro h; cases h) - | .struct _ _, .dynamicArray _ => isFalse (by intro h; cases h) - | .struct _ _, .bytes => isFalse (by intro h; cases h) - | .struct _ _, .string => isFalse (by intro h; cases h) - | .tuple _, .elem _ => isFalse (by intro h; cases h) - | .tuple _, .mapping _ _ => isFalse (by intro h; cases h) - | .tuple _, .contract _ => isFalse (by intro h; cases h) - | .tuple _, .struct _ _ => isFalse (by intro h; cases h) - | .tuple _, .array _ _ => isFalse (by intro h; cases h) - | .tuple _, .dynamicArray _ => isFalse (by intro h; cases h) - | .tuple _, .bytes => isFalse (by intro h; cases h) - | .tuple _, .string => isFalse (by intro h; cases h) - | .array _ _, .elem _ => isFalse (by intro h; cases h) - | .array _ _, .mapping _ _ => isFalse (by intro h; cases h) - | .array _ _, .contract _ => isFalse (by intro h; cases h) - | .array _ _, .struct _ _ => isFalse (by intro h; cases h) - | .array _ _, .tuple _ => isFalse (by intro h; cases h) - | .array _ _, .dynamicArray _ => isFalse (by intro h; cases h) - | .array _ _, .bytes => isFalse (by intro h; cases h) - | .array _ _, .string => isFalse (by intro h; cases h) - | .dynamicArray _, .elem _ => isFalse (by intro h; cases h) - | .dynamicArray _, .mapping _ _ => isFalse (by intro h; cases h) - | .dynamicArray _, .contract _ => isFalse (by intro h; cases h) - | .dynamicArray _, .struct _ _ => isFalse (by intro h; cases h) - | .dynamicArray _, .tuple _ => isFalse (by intro h; cases h) - | .dynamicArray _, .array _ _ => isFalse (by intro h; cases h) - | .dynamicArray _, .bytes => isFalse (by intro h; cases h) - | .dynamicArray _, .string => isFalse (by intro h; cases h) - | .bytes, .elem _ => isFalse (by intro h; cases h) - | .bytes, .mapping _ _ => isFalse (by intro h; cases h) - | .bytes, .contract _ => isFalse (by intro h; cases h) - | .bytes, .struct _ _ => isFalse (by intro h; cases h) - | .bytes, .tuple _ => isFalse (by intro h; cases h) - | .bytes, .array _ _ => isFalse (by intro h; cases h) - | .bytes, .dynamicArray _ => isFalse (by intro h; cases h) - | .bytes, .string => isFalse (by intro h; cases h) - | .string, .elem _ => isFalse (by intro h; cases h) - | .string, .mapping _ _ => isFalse (by intro h; cases h) - | .string, .contract _ => isFalse (by intro h; cases h) - | .string, .struct _ _ => isFalse (by intro h; cases h) - | .string, .tuple _ => isFalse (by intro h; cases h) - | .string, .array _ _ => isFalse (by intro h; cases h) - | .string, .dynamicArray _ => isFalse (by intro h; cases h) - | .string, .bytes => isFalse (by intro h; cases h) - - private def StorageType.decEqList : (as bs : List StorageType) -> Decidable (as = bs) - | [], [] => isTrue rfl - | a :: as, b :: bs => - match StorageType.decEq a b, StorageType.decEqList as bs with - | isTrue ha, isTrue hs => isTrue (by cases ha; cases hs; rfl) - | isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) - | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) - | [], _ :: _ => isFalse (by intro h; cases h) - | _ :: _, [] => isFalse (by intro h; cases h) - - private def StorageType.decEqNamedList : (as bs : List (Ident × StorageType)) -> Decidable (as = bs) - | [], [] => isTrue rfl - | (an, al) :: as, (bn, bl) :: bs => - match String.decEq an bn, StorageType.decEq al bl, StorageType.decEqNamedList as bs with - | isTrue han, isTrue ha, isTrue hs => isTrue (by cases ha; cases hs; cases han; rfl) - | isFalse han, _, _ => isFalse (by intro h; cases h; exact han rfl) - | _, isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) - | _, _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) - | [], _ :: _ => isFalse (by intro h; cases h) - | _ :: _, [] => isFalse (by intro h; cases h) -end - -instance : DecidableEq StorageType := - StorageType.decEq - -inductive EnvVar where - | caller - | origin - | callvalue - | this - | timestamp - | chainid - | selfbalance - | gasprice - | number - | coinbase - | gaslimit - | prevrandao - | basefee - | msgSig - | msgData - deriving DecidableEq, Repr, Inhabited - -inductive UnaryOp where - | not - | neg - | bitNot - deriving DecidableEq, Repr, Inhabited - -inductive BinaryOp where - | add - | sub - | mul - | div - | mod - | eq - | ne - | lt - | le - | gt - | ge - | and - | or - | bitAnd - | bitOr - | bitXor - | shl - | shr - | exp - deriving DecidableEq, Repr, Inhabited - -/-- Whether a variable path is rooted in a memory **local** or **storage**. Resolved statically - by the spec author / frontend, exactly as solc resolves the name. -/ -inductive VarOrigin where - | localVar - | storage - deriving DecidableEq, Repr, Inhabited - -mutual - -/- Expressions are intentionally lightweight for now. We are aiming for a meaningful - subset of Solidity. -/ -inductive Expr where - | intLit : Int -> Expr - | boolLit : Bool -> Expr - | bytesLit : ByteArray -> Expr - /- `new bytes(len)`: a fresh zero-filled byte string of dynamic length `len` -/ - | newBytes : Expr -> Expr - /- `new T[](len)`: a fresh memory array with `len` default-initialized elements of type `T` -/ - | newArray : StorageType -> Expr -> Expr - /- struct literal `S({field₁: e₁, …})`: builds a `Value.struct` from the named field expressions - (e.g. `Proposal({name: x, voteCount: 0})`). -/ - | structLit : Ident -> List (Ident × Expr) -> Expr - /- array literal `[e₁, …]`: builds a `Value.array` from the element expressions. -/ - | arrayLit : List Expr -> Expr - /- tuple literal: builds a `Value.tuple` from the element expressions. Used to assemble a - multi-value (tuple) return (e.g. a struct getter returning `(a, b)`); its value representation - is `Value.tuple`, distinct from `Value.array`. -/ - | tupleLit : List Expr -> Expr - /- static tuple projection `t.i`: the `i`-th component. -/ - | tupleGet : Expr -> Nat -> Expr - /- `b[start:end]`: byte slice of dynamic bytes `b` over `[start, end)` -/ - | bytesSlice : Expr /- base -/ -> Expr /- start -/ -> Expr /- end -/ -> Expr - | var : Ident -> Expr - | env : EnvVar -> Expr - /- for struct fields -/ - | field : Expr -> Ident -> Expr - | storage : StorageRef -> Expr - | inRange : IntType -> Expr -> Expr - | cast : Expr -> StorageType -> Expr /- TODO do we really need casting?-/ - | addrOf : Expr -> Expr - | unary : UnaryOp -> Expr -> Expr - | binary : BinaryOp -> Expr -> Expr -> Expr - | index : Expr -> Expr -> Expr - | ite : Expr -> Expr -> Expr -> Expr - /- `arr.length`. The origin is explicit, matching assignment: storage paths read the declared - storage array length; local paths read the in-memory value and return its array/byte count. -/ - | arrayLength : VarOrigin -> StorageRef -> Expr - /- `keccak256(b)`: the Keccak-256 hash of the dynamic bytes `b`, as a `bytes32` value. The hash - primitive is the same `ffi.KEC` the EVM's `KECCAK256` opcode uses, so equivalence reduces to - equality of the hashed bytes. -/ - | keccak256 : Expr -> Expr - /- `abi.encodePacked(e₁, …)`: the non-padded ("packed") ABI encoding of the listed values, as a - dynamic `bytes`. Each operand carries its (statically known) `ABIType`, which fixes its packed - width (`uintN`→N/8 bytes, `bool`→1, `address`→20, `bytesN`→N, with no length prefixes). -/ - | abiEncodePacked : List (ABIType × Expr) -> Expr - /- ABI calldata for a configured external call, including the 4-byte selector. The contract's - `Config.externalABI.encode?` determines the selector/types for `name`; this models - `abi.encodeWithSelector(...)` without baking contract-specific selectors into Solm. -/ - | abiEncodeCall : Ident -> List Expr -> Expr - /- `abi.decode(bytes, (T))`: decode a single ABI return value from dynamic bytes. Decode failure is - a model-level revert, matching Solidity's runtime `abi.decode` behavior. -/ - | abiDecode : ABIType -> Expr -> Expr - /- `addr.code.length` (EXTCODESIZE): the size in bytes of the code deployed at address `addr`. - Matches `Ethereum.State.extCodeSize` — a non-existent account or an EOA (no code) has size 0. - Used by ERC721 `safeTransferFrom`'s `to.code.length == 0` contract-detection guard. -/ - | extCodeSize : Expr -> Expr - /- `addr` code prefix (EXTCODECOPY): the first `len` bytes of the code at `addr`, as `bytes`, - zero-padded past the code end (all zero for a non-existent account or an EOA). -/ - | extCodePrefix : Expr /- addr -/ -> Expr /- len -/ -> Expr - /- `blockhash(n)` (BLOCKHASH), `addr.balance` (BALANCE), `addr.codehash` (EXTCODEHASH). -/ - | blockhash : Expr -> Expr - | balanceOf : Expr -> Expr - | extCodeHash : Expr -> Expr - /- Fixed-size `bytesN` literal: the ABI type index (`n : Fin 32` ⇒ width `n+1`) and the bytes in - Solidity order. Models compile-time `bytesN` constants — hex `bytesN` literals, a function's - `.selector` (`bytes4`), and `type(I).interfaceId` (`bytes4`) — all of which solc bakes as PUSH - immediates. Evaluates to `Value.fixedBytes n bs`; `==`/comparisons already act on `fixedBytes`. -/ - | fixedBytesLit : Fin 32 -> List UInt8 -> Expr - -inductive StorageRefStep where - | field : Ident -> StorageRefStep - | mindex : Expr -> StorageRefStep - | aindex : Expr -> StorageRefStep - -structure StorageRef where /- TODO better name, since it can be a reference to locals or storage -/ - base : Ident - steps : List StorageRefStep := [] - -/- Zoe: Shall we use StorageRef at the Expr level too instead of having field? -/ - -end - -instance : Repr ByteArray where - reprPrec b _ := repr b.data - -deriving instance Repr for Expr -deriving instance Inhabited for Expr -deriving instance Repr for StorageRefStep -deriving instance Inhabited for StorageRefStep -deriving instance Repr for StorageRef -deriving instance Inhabited for StorageRef - --- The hand-written structural `DecidableEq` is an O(n²) match over `Expr`'s constructors; with the --- `keccak256`/`abiEncodePacked` additions it exceeds the default heartbeat budget during the equation --- compiler's `simp` pass, so the limit is raised for this block. -set_option maxHeartbeats 5000000 in -mutual - private def Expr.decEq : (a b : Expr) -> Decidable (a = b) - | .intLit x, .intLit y => - match (inferInstance : Decidable (x = y)) with - | isTrue h => isTrue (by subst y; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .boolLit x, .boolLit y => - match (inferInstance : Decidable (x = y)) with - | isTrue h => isTrue (by subst y; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .bytesLit x, .bytesLit y => - match (inferInstance : Decidable (x = y)) with - | isTrue h => isTrue (by subst y; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .newBytes x, .newBytes y => - match Expr.decEq x y with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .newArray tx x, .newArray ty y => - match (inferInstance : Decidable (tx = ty)), Expr.decEq x y with - | isTrue ht, isTrue hx => isTrue (by cases ht; cases hx; rfl) - | isFalse ht, _ => isFalse (by intro h'; cases h'; exact ht rfl) - | _, isFalse hx => isFalse (by intro h'; cases h'; exact hx rfl) - | .bytesSlice b1 s1 e1, .bytesSlice b2 s2 e2 => - match Expr.decEq b1 b2, Expr.decEq s1 s2, Expr.decEq e1 e2 with - | isTrue hb, isTrue hs, isTrue he => isTrue (by cases hb; cases hs; cases he; rfl) - | isFalse hb, _, _ => isFalse (by intro h'; cases h'; exact hb rfl) - | _, isFalse hs, _ => isFalse (by intro h'; cases h'; exact hs rfl) - | _, _, isFalse he => isFalse (by intro h'; cases h'; exact he rfl) - | .var x, .var y => - match (inferInstance : Decidable (x = y)) with - | isTrue h => isTrue (by subst y; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .env x, .env y => - match (inferInstance : Decidable (x = y)) with - | isTrue h => isTrue (by subst y; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .field x fx, .field y fy => - match Expr.decEq x y, (inferInstance : Decidable (fx = fy)) with - | isTrue hx, isTrue hf => isTrue (by subst y; subst fy; rfl) - | isFalse hx, _ => isFalse (by intro h'; cases h'; exact hx rfl) - | _, isFalse hf => isFalse (by intro h'; cases h'; exact hf rfl) - | .storage x, .storage y => - match StorageRef.decEq x y with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .inRange tx x, .inRange ty y => - match (inferInstance : Decidable (tx = ty)), Expr.decEq x y with - | isTrue ht, isTrue hx => isTrue (by cases ht; cases hx; rfl) - | isFalse ht, _ => isFalse (by intro h'; cases h'; exact ht rfl) - | _, isFalse hx => isFalse (by intro h'; cases h'; exact hx rfl) - | .cast x tx, .cast y ty => - match Expr.decEq x y, (inferInstance : Decidable (tx = ty)) with - | isTrue hx, isTrue ht => isTrue (by cases hx; cases ht; rfl) - | isFalse hx, _ => isFalse (by intro h'; cases h'; exact hx rfl) - | _, isFalse ht => isFalse (by intro h'; cases h'; exact ht rfl) - | .addrOf x, .addrOf y => - match Expr.decEq x y with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .unary ox x, .unary oy y => - match (inferInstance : Decidable (ox = oy)), Expr.decEq x y with - | isTrue ho, isTrue hx => isTrue (by cases ho; cases hx; rfl) - | isFalse ho, _ => isFalse (by intro h'; cases h'; exact ho rfl) - | _, isFalse hx => isFalse (by intro h'; cases h'; exact hx rfl) - | .binary ox lx rx, .binary oy ly ry => - match (inferInstance : Decidable (ox = oy)), Expr.decEq lx ly, Expr.decEq rx ry with - | isTrue ho, isTrue hl, isTrue hr => isTrue (by cases ho; cases hl; cases hr; rfl) - | isFalse ho, _, _ => isFalse (by intro h'; cases h'; exact ho rfl) - | _, isFalse hl, _ => isFalse (by intro h'; cases h'; exact hl rfl) - | _, _, isFalse hr => isFalse (by intro h'; cases h'; exact hr rfl) - | .index bx ix, .index byx iy => - match Expr.decEq bx byx, Expr.decEq ix iy with - | isTrue hb, isTrue hi => isTrue (by cases hb; cases hi; rfl) - | isFalse hb, _ => isFalse (by intro h'; cases h'; exact hb rfl) - | _, isFalse hi => isFalse (by intro h'; cases h'; exact hi rfl) - | .ite cx tx fx, .ite cy ty fy => - match Expr.decEq cx cy, Expr.decEq tx ty, Expr.decEq fx fy with - | isTrue hc, isTrue ht, isTrue hf => isTrue (by cases hc; cases ht; cases hf; rfl) - | isFalse hc, _, _ => isFalse (by intro h'; cases h'; exact hc rfl) - | _, isFalse ht, _ => isFalse (by intro h'; cases h'; exact ht rfl) - | _, _, isFalse hf => isFalse (by intro h'; cases h'; exact hf rfl) - | .arrayLength ox x, .arrayLength oy y => - match (inferInstance : Decidable (ox = oy)), StorageRef.decEq x y with - | isTrue ho, isTrue hx => isTrue (by cases ho; cases hx; rfl) - | isFalse ho, _ => isFalse (by intro h'; cases h'; exact ho rfl) - | _, isFalse hx => isFalse (by intro h'; cases h'; exact hx rfl) - | .newArray _ _, .intLit _ => isFalse (by intro h; cases h) - | .newArray _ _, .boolLit _ => isFalse (by intro h; cases h) - | .newArray _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .newArray _ _, .newBytes _ => isFalse (by intro h; cases h) - | .newArray _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .var _ => isFalse (by intro h; cases h) - | .newArray _ _, .env _ => isFalse (by intro h; cases h) - | .newArray _ _, .field _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .storage _ => isFalse (by intro h; cases h) - | .newArray _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .cast _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .addrOf _ => isFalse (by intro h; cases h) - | .newArray _ _, .unary _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .index _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .intLit _, .newArray _ _ => isFalse (by intro h; cases h) - | .boolLit _, .newArray _ _ => isFalse (by intro h; cases h) - | .bytesLit _, .newArray _ _ => isFalse (by intro h; cases h) - | .newBytes _, .newArray _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .var _, .newArray _ _ => isFalse (by intro h; cases h) - | .env _, .newArray _ _ => isFalse (by intro h; cases h) - | .field _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .storage _, .newArray _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .cast _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .addrOf _, .newArray _ _ => isFalse (by intro h; cases h) - | .unary _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .index _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .intLit _, .boolLit _ => isFalse (by intro h; cases h) - | .intLit _, .var _ => isFalse (by intro h; cases h) - | .intLit _, .env _ => isFalse (by intro h; cases h) - | .intLit _, .field _ _ => isFalse (by intro h; cases h) - | .intLit _, .storage _ => isFalse (by intro h; cases h) - | .intLit _, .inRange _ _ => isFalse (by intro h; cases h) - | .intLit _, .cast _ _ => isFalse (by intro h; cases h) - | .intLit _, .addrOf _ => isFalse (by intro h; cases h) - | .intLit _, .unary _ _ => isFalse (by intro h; cases h) - | .intLit _, .binary _ _ _ => isFalse (by intro h; cases h) - | .intLit _, .index _ _ => isFalse (by intro h; cases h) - | .intLit _, .ite _ _ _ => isFalse (by intro h; cases h) - | .boolLit _, .intLit _ => isFalse (by intro h; cases h) - | .boolLit _, .var _ => isFalse (by intro h; cases h) - | .boolLit _, .env _ => isFalse (by intro h; cases h) - | .boolLit _, .field _ _ => isFalse (by intro h; cases h) - | .boolLit _, .storage _ => isFalse (by intro h; cases h) - | .boolLit _, .inRange _ _ => isFalse (by intro h; cases h) - | .boolLit _, .cast _ _ => isFalse (by intro h; cases h) - | .boolLit _, .addrOf _ => isFalse (by intro h; cases h) - | .boolLit _, .unary _ _ => isFalse (by intro h; cases h) - | .boolLit _, .binary _ _ _ => isFalse (by intro h; cases h) - | .boolLit _, .index _ _ => isFalse (by intro h; cases h) - | .boolLit _, .ite _ _ _ => isFalse (by intro h; cases h) - | .var _, .intLit _ => isFalse (by intro h; cases h) - | .var _, .boolLit _ => isFalse (by intro h; cases h) - | .var _, .env _ => isFalse (by intro h; cases h) - | .var _, .field _ _ => isFalse (by intro h; cases h) - | .var _, .storage _ => isFalse (by intro h; cases h) - | .var _, .inRange _ _ => isFalse (by intro h; cases h) - | .var _, .cast _ _ => isFalse (by intro h; cases h) - | .var _, .addrOf _ => isFalse (by intro h; cases h) - | .var _, .unary _ _ => isFalse (by intro h; cases h) - | .var _, .binary _ _ _ => isFalse (by intro h; cases h) - | .var _, .index _ _ => isFalse (by intro h; cases h) - | .var _, .ite _ _ _ => isFalse (by intro h; cases h) - | .env _, .intLit _ => isFalse (by intro h; cases h) - | .env _, .boolLit _ => isFalse (by intro h; cases h) - | .env _, .var _ => isFalse (by intro h; cases h) - | .env _, .field _ _ => isFalse (by intro h; cases h) - | .env _, .storage _ => isFalse (by intro h; cases h) - | .env _, .inRange _ _ => isFalse (by intro h; cases h) - | .env _, .cast _ _ => isFalse (by intro h; cases h) - | .env _, .addrOf _ => isFalse (by intro h; cases h) - | .env _, .unary _ _ => isFalse (by intro h; cases h) - | .env _, .binary _ _ _ => isFalse (by intro h; cases h) - | .env _, .index _ _ => isFalse (by intro h; cases h) - | .env _, .ite _ _ _ => isFalse (by intro h; cases h) - | .field _ _, .intLit _ => isFalse (by intro h; cases h) - | .field _ _, .boolLit _ => isFalse (by intro h; cases h) - | .field _ _, .var _ => isFalse (by intro h; cases h) - | .field _ _, .env _ => isFalse (by intro h; cases h) - | .field _ _, .storage _ => isFalse (by intro h; cases h) - | .field _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .field _ _, .cast _ _ => isFalse (by intro h; cases h) - | .field _ _, .addrOf _ => isFalse (by intro h; cases h) - | .field _ _, .unary _ _ => isFalse (by intro h; cases h) - | .field _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .field _ _, .index _ _ => isFalse (by intro h; cases h) - | .field _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .storage _, .intLit _ => isFalse (by intro h; cases h) - | .storage _, .boolLit _ => isFalse (by intro h; cases h) - | .storage _, .var _ => isFalse (by intro h; cases h) - | .storage _, .env _ => isFalse (by intro h; cases h) - | .storage _, .field _ _ => isFalse (by intro h; cases h) - | .storage _, .inRange _ _ => isFalse (by intro h; cases h) - | .storage _, .cast _ _ => isFalse (by intro h; cases h) - | .storage _, .addrOf _ => isFalse (by intro h; cases h) - | .storage _, .unary _ _ => isFalse (by intro h; cases h) - | .storage _, .binary _ _ _ => isFalse (by intro h; cases h) - | .storage _, .index _ _ => isFalse (by intro h; cases h) - | .storage _, .ite _ _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .intLit _ => isFalse (by intro h; cases h) - | .inRange _ _, .boolLit _ => isFalse (by intro h; cases h) - | .inRange _ _, .var _ => isFalse (by intro h; cases h) - | .inRange _ _, .env _ => isFalse (by intro h; cases h) - | .inRange _ _, .field _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .storage _ => isFalse (by intro h; cases h) - | .inRange _ _, .cast _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .addrOf _ => isFalse (by intro h; cases h) - | .inRange _ _, .unary _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .index _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .cast _ _, .intLit _ => isFalse (by intro h; cases h) - | .cast _ _, .boolLit _ => isFalse (by intro h; cases h) - | .cast _ _, .var _ => isFalse (by intro h; cases h) - | .cast _ _, .env _ => isFalse (by intro h; cases h) - | .cast _ _, .field _ _ => isFalse (by intro h; cases h) - | .cast _ _, .storage _ => isFalse (by intro h; cases h) - | .cast _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .cast _ _, .addrOf _ => isFalse (by intro h; cases h) - | .cast _ _, .unary _ _ => isFalse (by intro h; cases h) - | .cast _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .cast _ _, .index _ _ => isFalse (by intro h; cases h) - | .cast _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .addrOf _, .intLit _ => isFalse (by intro h; cases h) - | .addrOf _, .boolLit _ => isFalse (by intro h; cases h) - | .addrOf _, .var _ => isFalse (by intro h; cases h) - | .addrOf _, .env _ => isFalse (by intro h; cases h) - | .addrOf _, .field _ _ => isFalse (by intro h; cases h) - | .addrOf _, .storage _ => isFalse (by intro h; cases h) - | .addrOf _, .inRange _ _ => isFalse (by intro h; cases h) - | .addrOf _, .cast _ _ => isFalse (by intro h; cases h) - | .addrOf _, .unary _ _ => isFalse (by intro h; cases h) - | .addrOf _, .binary _ _ _ => isFalse (by intro h; cases h) - | .addrOf _, .index _ _ => isFalse (by intro h; cases h) - | .addrOf _, .ite _ _ _ => isFalse (by intro h; cases h) - | .unary _ _, .intLit _ => isFalse (by intro h; cases h) - | .unary _ _, .boolLit _ => isFalse (by intro h; cases h) - | .unary _ _, .var _ => isFalse (by intro h; cases h) - | .unary _ _, .env _ => isFalse (by intro h; cases h) - | .unary _ _, .field _ _ => isFalse (by intro h; cases h) - | .unary _ _, .storage _ => isFalse (by intro h; cases h) - | .unary _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .unary _ _, .cast _ _ => isFalse (by intro h; cases h) - | .unary _ _, .addrOf _ => isFalse (by intro h; cases h) - | .unary _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .unary _ _, .index _ _ => isFalse (by intro h; cases h) - | .unary _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .intLit _ => isFalse (by intro h; cases h) - | .binary _ _ _, .boolLit _ => isFalse (by intro h; cases h) - | .binary _ _ _, .var _ => isFalse (by intro h; cases h) - | .binary _ _ _, .env _ => isFalse (by intro h; cases h) - | .binary _ _ _, .field _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .storage _ => isFalse (by intro h; cases h) - | .binary _ _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .cast _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .addrOf _ => isFalse (by intro h; cases h) - | .binary _ _ _, .unary _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .index _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .index _ _, .intLit _ => isFalse (by intro h; cases h) - | .index _ _, .boolLit _ => isFalse (by intro h; cases h) - | .index _ _, .var _ => isFalse (by intro h; cases h) - | .index _ _, .env _ => isFalse (by intro h; cases h) - | .index _ _, .field _ _ => isFalse (by intro h; cases h) - | .index _ _, .storage _ => isFalse (by intro h; cases h) - | .index _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .index _ _, .cast _ _ => isFalse (by intro h; cases h) - | .index _ _, .addrOf _ => isFalse (by intro h; cases h) - | .index _ _, .unary _ _ => isFalse (by intro h; cases h) - | .index _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .index _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .intLit _ => isFalse (by intro h; cases h) - | .ite _ _ _, .boolLit _ => isFalse (by intro h; cases h) - | .ite _ _ _, .var _ => isFalse (by intro h; cases h) - | .ite _ _ _, .env _ => isFalse (by intro h; cases h) - | .ite _ _ _, .field _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .storage _ => isFalse (by intro h; cases h) - | .ite _ _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .cast _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .addrOf _ => isFalse (by intro h; cases h) - | .ite _ _ _, .unary _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .index _ _ => isFalse (by intro h; cases h) - | .bytesLit _, .intLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .boolLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .var _ => isFalse (by intro h; cases h) - | .bytesLit _, .env _ => isFalse (by intro h; cases h) - | .bytesLit _, .field _ _ => isFalse (by intro h; cases h) - | .bytesLit _, .storage _ => isFalse (by intro h; cases h) - | .bytesLit _, .inRange _ _ => isFalse (by intro h; cases h) - | .bytesLit _, .cast _ _ => isFalse (by intro h; cases h) - | .bytesLit _, .addrOf _ => isFalse (by intro h; cases h) - | .bytesLit _, .unary _ _ => isFalse (by intro h; cases h) - | .bytesLit _, .binary _ _ _ => isFalse (by intro h; cases h) - | .bytesLit _, .index _ _ => isFalse (by intro h; cases h) - | .bytesLit _, .ite _ _ _ => isFalse (by intro h; cases h) - | .bytesLit _, .newBytes _ => isFalse (by intro h; cases h) - | .intLit _, .bytesLit _ => isFalse (by intro h; cases h) - | .boolLit _, .bytesLit _ => isFalse (by intro h; cases h) - | .var _, .bytesLit _ => isFalse (by intro h; cases h) - | .env _, .bytesLit _ => isFalse (by intro h; cases h) - | .field _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .storage _, .bytesLit _ => isFalse (by intro h; cases h) - | .inRange _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .cast _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .addrOf _, .bytesLit _ => isFalse (by intro h; cases h) - | .unary _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .binary _ _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .index _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .ite _ _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .newBytes _, .intLit _ => isFalse (by intro h; cases h) - | .newBytes _, .boolLit _ => isFalse (by intro h; cases h) - | .newBytes _, .var _ => isFalse (by intro h; cases h) - | .newBytes _, .env _ => isFalse (by intro h; cases h) - | .newBytes _, .field _ _ => isFalse (by intro h; cases h) - | .newBytes _, .storage _ => isFalse (by intro h; cases h) - | .newBytes _, .inRange _ _ => isFalse (by intro h; cases h) - | .newBytes _, .cast _ _ => isFalse (by intro h; cases h) - | .newBytes _, .addrOf _ => isFalse (by intro h; cases h) - | .newBytes _, .unary _ _ => isFalse (by intro h; cases h) - | .newBytes _, .binary _ _ _ => isFalse (by intro h; cases h) - | .newBytes _, .index _ _ => isFalse (by intro h; cases h) - | .newBytes _, .ite _ _ _ => isFalse (by intro h; cases h) - | .newBytes _, .bytesLit _ => isFalse (by intro h; cases h) - | .intLit _, .newBytes _ => isFalse (by intro h; cases h) - | .boolLit _, .newBytes _ => isFalse (by intro h; cases h) - | .var _, .newBytes _ => isFalse (by intro h; cases h) - | .env _, .newBytes _ => isFalse (by intro h; cases h) - | .field _ _, .newBytes _ => isFalse (by intro h; cases h) - | .storage _, .newBytes _ => isFalse (by intro h; cases h) - | .inRange _ _, .newBytes _ => isFalse (by intro h; cases h) - | .cast _ _, .newBytes _ => isFalse (by intro h; cases h) - | .addrOf _, .newBytes _ => isFalse (by intro h; cases h) - | .unary _ _, .newBytes _ => isFalse (by intro h; cases h) - | .binary _ _ _, .newBytes _ => isFalse (by intro h; cases h) - | .index _ _, .newBytes _ => isFalse (by intro h; cases h) - | .ite _ _ _, .newBytes _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .intLit _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .boolLit _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .newBytes _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .var _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .env _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .field _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .storage _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .cast _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .addrOf _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .unary _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .index _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .intLit _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .boolLit _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesLit _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .newBytes _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .var _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .env _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .field _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .storage _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .cast _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .addrOf _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .unary _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .index _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .intLit _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .boolLit _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .newBytes _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .var _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .env _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .field _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .storage _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .cast _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .addrOf _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .unary _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .index _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .intLit _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .boolLit _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .bytesLit _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .newBytes _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .var _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .env _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .field _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .storage _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .cast _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .addrOf _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .unary _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .index _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .structLit nx fx, .structLit ny fy => - match (inferInstance : Decidable (nx = ny)), Expr.decEqNamedList fx fy with - | isTrue hn, isTrue hf => isTrue (by cases hn; cases hf; rfl) - | isFalse hn, _ => isFalse (by intro h; cases h; exact hn rfl) - | _, isFalse hf => isFalse (by intro h; cases h; exact hf rfl) - | .arrayLit xs, .arrayLit ys => - match Expr.decEqList xs ys with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .structLit _ _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .var _ => isFalse (by intro h; cases h) - | .var _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .env _ => isFalse (by intro h; cases h) - | .env _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .arrayLit _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .var _ => isFalse (by intro h; cases h) - | .var _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .env _ => isFalse (by intro h; cases h) - | .env _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .structLit _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .structLit _ _ => isFalse (by intro h; cases h) - | .tupleLit xs, .tupleLit ys => - match Expr.decEqList xs ys with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .tupleLit _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .var _ => isFalse (by intro h; cases h) - | .var _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .env _ => isFalse (by intro h; cases h) - | .env _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .keccak256 x, .keccak256 y => - match Expr.decEq x y with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .keccak256 _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .var _ => isFalse (by intro h; cases h) - | .var _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .env _ => isFalse (by intro h; cases h) - | .env _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .keccak256 _ => isFalse (by intro h; cases h) - | .abiEncodePacked xs, .abiEncodePacked ys => - match Expr.decEqTypedList xs ys with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .abiEncodeCall nx xs, .abiEncodeCall ny ys => - match (inferInstance : Decidable (nx = ny)), Expr.decEqList xs ys with - | isTrue hn, isTrue hs => isTrue (by cases hn; cases hs; rfl) - | isFalse hn, _ => isFalse (by intro h; cases h; exact hn rfl) - | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) - | .abiDecode tx x, .abiDecode ty y => - match (inferInstance : Decidable (tx = ty)), Expr.decEq x y with - | isTrue ht, isTrue hx => isTrue (by cases ht; cases hx; rfl) - | isFalse ht, _ => isFalse (by intro h; cases h; exact ht rfl) - | _, isFalse hx => isFalse (by intro h; cases h; exact hx rfl) - | .abiEncodeCall _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .var _ => isFalse (by intro h; cases h) - | .var _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .env _ => isFalse (by intro h; cases h) - | .env _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .var _ => isFalse (by intro h; cases h) - | .var _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .env _ => isFalse (by intro h; cases h) - | .env _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .var _ => isFalse (by intro h; cases h) - | .var _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .env _ => isFalse (by intro h; cases h) - | .env _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .extCodeSize x, .extCodeSize y => - match Expr.decEq x y with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .fixedBytesLit nx bx, .fixedBytesLit ny byy => - match (inferInstance : Decidable (nx = ny)), (inferInstance : Decidable (bx = byy)) with - | isTrue hn, isTrue hb => isTrue (by cases hn; cases hb; rfl) - | isFalse hn, _ => isFalse (by intro h; cases h; exact hn rfl) - | _, isFalse hb => isFalse (by intro h; cases h; exact hb rfl) - | .extCodeSize _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .var _ => isFalse (by intro h; cases h) - | .var _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .env _ => isFalse (by intro h; cases h) - | .env _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodePrefix ax lx, .extCodePrefix ay ly => - match Expr.decEq ax ay, Expr.decEq lx ly with - | isTrue ha, isTrue hl => isTrue (by cases ha; cases hl; rfl) - | isFalse ha, _ => isFalse (by intro h'; cases h'; exact ha rfl) - | _, isFalse hl => isFalse (by intro h'; cases h'; exact hl rfl) - | .tupleGet ex nx, .tupleGet ey ny => - match Expr.decEq ex ey, (inferInstance : Decidable (nx = ny)) with - | isTrue he, isTrue hn => isTrue (by cases he; cases hn; rfl) - | isFalse he, _ => isFalse (by intro h'; cases h'; exact he rfl) - | _, isFalse hn => isFalse (by intro h'; cases h'; exact hn rfl) - | .blockhash x, .blockhash y => - match Expr.decEq x y with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .balanceOf x, .balanceOf y => - match Expr.decEq x y with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .extCodeHash x, .extCodeHash y => - match Expr.decEq x y with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .tupleGet _ _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .var _ => isFalse (by intro h; cases h) - | .var _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .env _ => isFalse (by intro h; cases h) - | .env _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .blockhash _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .var _ => isFalse (by intro h; cases h) - | .var _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .env _ => isFalse (by intro h; cases h) - | .env _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .blockhash _ => isFalse (by intro h; cases h) - | .balanceOf _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .var _ => isFalse (by intro h; cases h) - | .var _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .env _ => isFalse (by intro h; cases h) - | .env _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .extCodeHash _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .var _ => isFalse (by intro h; cases h) - | .var _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .env _ => isFalse (by intro h; cases h) - | .env _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .tupleGet _ _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .tupleGet _ _ => isFalse (by intro h; cases h) - | .blockhash _, .balanceOf _ => isFalse (by intro h; cases h) - | .balanceOf _, .blockhash _ => isFalse (by intro h; cases h) - | .blockhash _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .blockhash _ => isFalse (by intro h; cases h) - | .balanceOf _, .extCodeHash _ => isFalse (by intro h; cases h) - | .extCodeHash _, .balanceOf _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .var _ => isFalse (by intro h; cases h) - | .var _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .env _ => isFalse (by intro h; cases h) - | .env _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .abiEncodeCall _ _ => isFalse (by intro h; cases h) - | .abiEncodeCall _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .abiDecode _ _ => isFalse (by intro h; cases h) - | .abiDecode _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .extCodeSize _ => isFalse (by intro h; cases h) - | .extCodeSize _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .extCodePrefix _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .extCodePrefix _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .intLit _ => isFalse (by intro h; cases h) - | .intLit _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .boolLit _ => isFalse (by intro h; cases h) - | .boolLit _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .bytesLit _ => isFalse (by intro h; cases h) - | .bytesLit _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .newBytes _ => isFalse (by intro h; cases h) - | .newBytes _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .newArray _ _ => isFalse (by intro h; cases h) - | .newArray _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .structLit _ _ => isFalse (by intro h; cases h) - | .structLit _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .arrayLit _ => isFalse (by intro h; cases h) - | .arrayLit _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .tupleLit _ => isFalse (by intro h; cases h) - | .tupleLit _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .bytesSlice _ _ _ => isFalse (by intro h; cases h) - | .bytesSlice _ _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .var _ => isFalse (by intro h; cases h) - | .var _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .env _ => isFalse (by intro h; cases h) - | .env _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .field _ _ => isFalse (by intro h; cases h) - | .field _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .storage _ => isFalse (by intro h; cases h) - | .storage _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .inRange _ _ => isFalse (by intro h; cases h) - | .inRange _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .cast _ _ => isFalse (by intro h; cases h) - | .cast _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .addrOf _ => isFalse (by intro h; cases h) - | .addrOf _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .unary _ _ => isFalse (by intro h; cases h) - | .unary _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .binary _ _ _ => isFalse (by intro h; cases h) - | .binary _ _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .index _ _ => isFalse (by intro h; cases h) - | .index _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .arrayLength _ _ => isFalse (by intro h; cases h) - | .arrayLength _ _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .keccak256 _ => isFalse (by intro h; cases h) - | .keccak256 _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - | .fixedBytesLit _ _, .abiEncodePacked _ => isFalse (by intro h; cases h) - | .abiEncodePacked _, .fixedBytesLit _ _ => isFalse (by intro h; cases h) - - private def Expr.decEqList : (as bs : List Expr) -> Decidable (as = bs) - | [], [] => isTrue rfl - | a :: as, b :: bs => - match Expr.decEq a b, Expr.decEqList as bs with - | isTrue ha, isTrue hs => isTrue (by cases ha; cases hs; rfl) - | isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) - | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) - | [], _ :: _ => isFalse (by intro h; cases h) - | _ :: _, [] => isFalse (by intro h; cases h) - - private def Expr.decEqNamedList : (as bs : List (Ident × Expr)) -> Decidable (as = bs) - | [], [] => isTrue rfl - | (nx, ex) :: as, (ny, ey) :: bs => - match (inferInstance : Decidable (nx = ny)), Expr.decEq ex ey, Expr.decEqNamedList as bs with - | isTrue hn, isTrue he, isTrue hs => isTrue (by cases hn; cases he; cases hs; rfl) - | isFalse hn, _, _ => isFalse (by intro h; cases h; exact hn rfl) - | _, isFalse he, _ => isFalse (by intro h; cases h; exact he rfl) - | _, _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) - | [], _ :: _ => isFalse (by intro h; cases h) - | _ :: _, [] => isFalse (by intro h; cases h) - - private def Expr.decEqTypedList : (as bs : List (ABIType × Expr)) -> Decidable (as = bs) - | [], [] => isTrue rfl - | (tx, ex) :: as, (ty, ey) :: bs => - match (inferInstance : Decidable (tx = ty)), Expr.decEq ex ey, Expr.decEqTypedList as bs with - | isTrue ht, isTrue he, isTrue hs => isTrue (by cases ht; cases he; cases hs; rfl) - | isFalse ht, _, _ => isFalse (by intro h; cases h; exact ht rfl) - | _, isFalse he, _ => isFalse (by intro h; cases h; exact he rfl) - | _, _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) - | [], _ :: _ => isFalse (by intro h; cases h) - | _ :: _, [] => isFalse (by intro h; cases h) - - private def StorageRefStep.decEq : (a b : StorageRefStep) -> Decidable (a = b) - | .field x, .field y => - match (inferInstance : Decidable (x = y)) with - | isTrue h => isTrue (by subst y; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .mindex x, .mindex y => - match Expr.decEq x y with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .aindex x, .aindex y => - match Expr.decEq x y with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .field _, .mindex _ => isFalse (by intro h; cases h) - | .field _, .aindex _ => isFalse (by intro h; cases h) - | .mindex _, .field _ => isFalse (by intro h; cases h) - | .mindex _, .aindex _ => isFalse (by intro h; cases h) - | .aindex _, .field _ => isFalse (by intro h; cases h) - | .aindex _, .mindex _ => isFalse (by intro h; cases h) - - private def StorageRef.decEq : (a b : StorageRef) -> Decidable (a = b) - | ⟨base, steps⟩, ⟨base', steps'⟩ => - match (inferInstance : Decidable (base = base')), StorageRefStep.decEqList steps steps' with - | isTrue hb, isTrue hs => isTrue (by cases hb; cases hs; rfl) - | isFalse hb, _ => isFalse (by intro h; cases h; exact hb rfl) - | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) - - private def StorageRefStep.decEqList : (as bs : List StorageRefStep) -> Decidable (as = bs) - | [], [] => isTrue rfl - | a :: as, b :: bs => - match StorageRefStep.decEq a b, StorageRefStep.decEqList as bs with - | isTrue ha, isTrue hs => isTrue (by cases ha; cases hs; rfl) - | isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) - | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) - | [], _ :: _ => isFalse (by intro h; cases h) - | _ :: _, [] => isFalse (by intro h; cases h) -end - -instance : DecidableEq Expr := - Expr.decEq - -instance : DecidableEq StorageRefStep := - StorageRefStep.decEq - -instance : DecidableEq StorageRef := - StorageRef.decEq - -namespace StorageRef - -def var (name : Ident) : StorageRef := - { base := name } - -end StorageRef - -inductive AssignRhs where - | expr : Expr -> AssignRhs - -- Do we want non-determinism? - -- | havoc - deriving DecidableEq, Repr, Inhabited - -inductive Stmt where - /- local variable -/ - | letDecl : Ident -> Option ABIType -> Expr -> Stmt - /- local storage alias: `T storage x = ref`; stores an evaluated storage pointer in locals -/ - | letStorage : Ident -> StorageRef -> Stmt - /- `uint256 x = gasleft()`: bind `x` to a nondeterministic gas value (Solm tracks no gas). -/ - | letGas : Ident -> Stmt - /- assignment to a local (`.local`) or storage (`.storage`) variable path -/ - | assign : VarOrigin -> StorageRef -> Expr -> Stmt - | require : Expr -> Stmt - | while : Expr -> List Stmt -> Stmt - /- `for (init; cond; post) { body }`, modelled as Yul's `for {init} cond {post} {body}`: - `init` runs once, then each iteration checks `cond`, runs `body`, then `post`. A `continue` - in `body` skips to `post` (re-checking `cond` after); a `break` exits without running `post`. -/ - | for : List Stmt /- init -/ -> Expr /- cond -/ -> List Stmt /- post -/ -> List Stmt /- body -/ -> Stmt - /- conditional: `if cond { thenBranch } else { elseBranch }`; a no-`else` `if` is `elseBranch = []` -/ - | ite : Expr -> List Stmt -> List Stmt -> Stmt - /- constructor call; `salt = none` ⇒ CREATE, `some e` (bytes32) ⇒ CREATE2. -/ - | new : Ident -> Expr /- ETH to send -/ -> List Expr -> Ident /- return value binder -/ -> - (salt : Option Expr := none) -> Stmt - /- internal and external call results are explicitly let-bound -/ - | internalCall : Ident -> List Expr -> Ident /- return value binder -/ -> Stmt - | externalCall : Expr -> Ident -> Expr /- ETH to send -/ -> List Expr -> - Ident /- return value binder -/ -> (perm : Bool := true) -> Stmt - /- low-level raw call, binds a success `bool` to `okVar` and raw returndata to `dataVar`. - `perm = true` models `.call`; `perm = false` models raw `.staticcall`. -/ - | lowLevelCall : Expr /- target -/ -> Expr /- ETH to send -/ -> - Expr /- calldata bytes -/ -> Ident /- success binder -/ -> - Ident /- raw returndata binder -/ -> (perm : Bool := true) -> Stmt - /- low-level raw delegatecall, binds a success `bool` to `okVar` and raw returndata to - `dataVar`. There is no ETH argument: EVM `DELEGATECALL` preserves `msg.value` and transfers - no value. -/ - | delegateCall : Expr /- target -/ -> Expr /- calldata bytes -/ -> - Ident /- success binder -/ -> Ident /- raw returndata binder -/ -> Stmt - /- `try recv.name{value}(args) returns (retVar) { onSuccess } catch { onFail }`. All callee - reverts hand control to `onFail` with the raw revert bytes bound to `errVar`; the spec filters by - selector prefix (e.g. `Error(string)`) and re-reverts uncaught cases via `require false`. - `retVar` is bound only within `onSuccess`. -/ - | checkedCall : Expr /- receiver -/ -> Ident /- name -/ -> Expr /- ETH -/ -> - List Expr /- args -/ -> Ident /- decoded return, scoped to onSuccess -/ -> - List Stmt /- onSuccess -/ -> Ident /- raw revert bytes, scoped to onFail -/ -> - List Stmt /- onFail -/ -> (perm : Bool := true) -> Stmt - /- `return (e₁, …, eₙ)`: return the listed values. `[]` models `return;` / a void return. -/ - | return : List Expr -> Stmt - | break : Stmt - | continue : Stmt - /- `arr.push(v?)`: grow a dynamic storage array by one. `some v` appends scalar `v`; `none` is a - grow-only push (structured elements — the new slots are zero, fields set by later writes). -/ - | push : StorageRef -> Option Expr -> Stmt - /- `arr.pop()`: remove the last element of a dynamic storage array (reverts if empty), - clearing the slot and shrinking its length by one -/ - | pop : StorageRef -> Stmt - /- `delete x`: reset the storage at `x` to its zero value (recursively, per its type) -/ - | delete : StorageRef -> Stmt - deriving Repr, Inhabited - - -mutual - private def Stmt.decEq : (a b : Stmt) -> Decidable (a = b) - | .letDecl nx tx ex, .letDecl ny ty ey => - match (inferInstance : Decidable (nx = ny)), (inferInstance : Decidable (tx = ty)), Expr.decEq ex ey with - | isTrue hn, isTrue ht, isTrue he => isTrue (by cases hn; cases ht; cases he; rfl) - | isFalse hn, _, _ => isFalse (by intro h; cases h; exact hn rfl) - | _, isFalse ht, _ => isFalse (by intro h; cases h; exact ht rfl) - | _, _, isFalse he => isFalse (by intro h; cases h; exact he rfl) - | .letStorage nx rx, .letStorage ny ry => - match (inferInstance : Decidable (nx = ny)), StorageRef.decEq rx ry with - | isTrue hn, isTrue hr => isTrue (by cases hn; cases hr; rfl) - | isFalse hn, _ => isFalse (by intro h; cases h; exact hn rfl) - | _, isFalse hr => isFalse (by intro h; cases h; exact hr rfl) - | .letGas nx, .letGas ny => - match (inferInstance : Decidable (nx = ny)) with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .letGas _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .assign _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .require _ => isFalse (by intro h; cases h) - | .require _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .while _ _ => isFalse (by intro h; cases h) - | .while _ _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .return _ => isFalse (by intro h; cases h) - | .return _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .break => isFalse (by intro h; cases h) - | .break, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .continue => isFalse (by intro h; cases h) - | .continue, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .letGas _ => isFalse (by intro h; cases h) - | .letGas _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .letGas _ => isFalse (by intro h; cases h) - | .assign ox sx ex, .assign oy sy ey => - match (inferInstance : Decidable (ox = oy)), StorageRef.decEq sx sy, Expr.decEq ex ey with - | isTrue ho, isTrue hs, isTrue he => isTrue (by cases ho; cases hs; cases he; rfl) - | isFalse ho, _, _ => isFalse (by intro h; cases h; exact ho rfl) - | _, isFalse hs, _ => isFalse (by intro h; cases h; exact hs rfl) - | _, _, isFalse he => isFalse (by intro h; cases h; exact he rfl) - | .require ex, .require ey => - match Expr.decEq ex ey with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .while cx bx, .while cy bodyY => - match Expr.decEq cx cy, Stmt.decEqList bx bodyY with - | isTrue hc, isTrue hb => isTrue (by cases hc; cases hb; rfl) - | isFalse hc, _ => isFalse (by intro h; cases h; exact hc rfl) - | _, isFalse hb => isFalse (by intro h; cases h; exact hb rfl) - | .ite cx tx ex, .ite cy ty ey => - match Expr.decEq cx cy, Stmt.decEqList tx ty, Stmt.decEqList ex ey with - | isTrue hc, isTrue ht, isTrue he => isTrue (by cases hc; cases ht; cases he; rfl) - | isFalse hc, _, _ => isFalse (by intro h; cases h; exact hc rfl) - | _, isFalse ht, _ => isFalse (by intro h; cases h; exact ht rfl) - | _, _, isFalse he => isFalse (by intro h; cases h; exact he rfl) - | .new nx vx ax rx sx, .new ny vy ay ry sy => - match (inferInstance : Decidable (nx = ny)), Expr.decEq vx vy, (inferInstance : Decidable (ax = ay)), (inferInstance : Decidable (rx = ry)), (inferInstance : Decidable (sx = sy)) with - | isTrue hn, isTrue hv, isTrue ha, isTrue hr, isTrue hs => isTrue (by cases hn; cases hv; cases ha; cases hr; cases hs; rfl) - | isFalse hn, _, _, _, _ => isFalse (by intro h; cases h; exact hn rfl) - | _, isFalse hv, _, _, _ => isFalse (by intro h; cases h; exact hv rfl) - | _, _, isFalse ha, _, _ => isFalse (by intro h; cases h; exact ha rfl) - | _, _, _, isFalse hr, _ => isFalse (by intro h; cases h; exact hr rfl) - | _, _, _, _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) - | .internalCall nx ax rx, .internalCall ny ay ry => - match (inferInstance : Decidable (nx = ny)), (inferInstance : Decidable (ax = ay)), (inferInstance : Decidable (rx = ry)) with - | isTrue hn, isTrue ha, isTrue hr => isTrue (by cases hn; cases ha; cases hr; rfl) - | isFalse hn, _, _ => isFalse (by intro h; cases h; exact hn rfl) - | _, isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) - | _, _, isFalse hr => isFalse (by intro h; cases h; exact hr rfl) - | .externalCall tx nx vx ax rx px, .externalCall ty ny vy ay ry py => - match Expr.decEq tx ty, (inferInstance : Decidable (nx = ny)), Expr.decEq vx vy, - (inferInstance : Decidable (ax = ay)), (inferInstance : Decidable (rx = ry)), - (inferInstance : Decidable (px = py)) with - | isTrue ht, isTrue hn, isTrue hv, isTrue ha, isTrue hr, isTrue hp => - isTrue (by cases ht; cases hn; cases hv; cases ha; cases hr; cases hp; rfl) - | isFalse ht, _, _, _, _, _ => isFalse (by intro h; cases h; exact ht rfl) - | _, isFalse hn, _, _, _, _ => isFalse (by intro h; cases h; exact hn rfl) - | _, _, isFalse hv, _, _, _ => isFalse (by intro h; cases h; exact hv rfl) - | _, _, _, isFalse ha, _, _ => isFalse (by intro h; cases h; exact ha rfl) - | _, _, _, _, isFalse hr, _ => isFalse (by intro h; cases h; exact hr rfl) - | _, _, _, _, _, isFalse hp => isFalse (by intro h; cases h; exact hp rfl) - | .lowLevelCall tx vx cx ox dx px, .lowLevelCall ty vy cy oy dy py => - match Expr.decEq tx ty, Expr.decEq vx vy, Expr.decEq cx cy, (inferInstance : Decidable (ox = oy)), (inferInstance : Decidable (dx = dy)), (inferInstance : Decidable (px = py)) with - | isTrue ht, isTrue hv, isTrue hc, isTrue ho, isTrue hd, isTrue hp => isTrue (by cases ht; cases hv; cases hc; cases ho; cases hd; cases hp; rfl) - | isFalse ht, _, _, _, _, _ => isFalse (by intro h; cases h; exact ht rfl) - | _, isFalse hv, _, _, _, _ => isFalse (by intro h; cases h; exact hv rfl) - | _, _, isFalse hc, _, _, _ => isFalse (by intro h; cases h; exact hc rfl) - | _, _, _, isFalse ho, _, _ => isFalse (by intro h; cases h; exact ho rfl) - | _, _, _, _, isFalse hd, _ => isFalse (by intro h; cases h; exact hd rfl) - | _, _, _, _, _, isFalse hp => isFalse (by intro h; cases h; exact hp rfl) - | .delegateCall tx cx ox dx, .delegateCall ty cy oy dy => - match Expr.decEq tx ty, Expr.decEq cx cy, (inferInstance : Decidable (ox = oy)), - (inferInstance : Decidable (dx = dy)) with - | isTrue ht, isTrue hc, isTrue ho, isTrue hd => - isTrue (by cases ht; cases hc; cases ho; cases hd; rfl) - | isFalse ht, _, _, _ => isFalse (by intro h; cases h; exact ht rfl) - | _, isFalse hc, _, _ => isFalse (by intro h; cases h; exact hc rfl) - | _, _, isFalse ho, _ => isFalse (by intro h; cases h; exact ho rfl) - | _, _, _, isFalse hd => isFalse (by intro h; cases h; exact hd rfl) - | .checkedCall rx nx vx ax retx sx ex cx px, - .checkedCall ry ny vy ay rety sy ey cy py => - match Expr.decEq rx ry, (inferInstance : Decidable (nx = ny)), Expr.decEq vx vy, - (inferInstance : Decidable (ax = ay)), (inferInstance : Decidable (retx = rety)), - Stmt.decEqList sx sy, (inferInstance : Decidable (ex = ey)), Stmt.decEqList cx cy, - (inferInstance : Decidable (px = py)) with - | isTrue hr, isTrue hn, isTrue hv, isTrue ha, isTrue hret, isTrue hs, isTrue he, - isTrue hc, isTrue hp => - isTrue (by - cases hr; cases hn; cases hv; cases ha; cases hret; cases hs; cases he - cases hc; cases hp; rfl) - | isFalse hr, _, _, _, _, _, _, _, _ => isFalse (by intro h; cases h; exact hr rfl) - | _, isFalse hn, _, _, _, _, _, _, _ => isFalse (by intro h; cases h; exact hn rfl) - | _, _, isFalse hv, _, _, _, _, _, _ => isFalse (by intro h; cases h; exact hv rfl) - | _, _, _, isFalse ha, _, _, _, _, _ => isFalse (by intro h; cases h; exact ha rfl) - | _, _, _, _, isFalse hret, _, _, _, _ => isFalse (by intro h; cases h; exact hret rfl) - | _, _, _, _, _, isFalse hs, _, _, _ => isFalse (by intro h; cases h; exact hs rfl) - | _, _, _, _, _, _, isFalse he, _, _ => isFalse (by intro h; cases h; exact he rfl) - | _, _, _, _, _, _, _, isFalse hc, _ => isFalse (by intro h; cases h; exact hc rfl) - | _, _, _, _, _, _, _, _, isFalse hp => isFalse (by intro h; cases h; exact hp rfl) - | .return ex, .return ey => - match Expr.decEqList ex ey with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .break, .break => isTrue rfl - | .continue, .continue => isTrue rfl - | .letStorage _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .assign _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .require _ => isFalse (by intro h; cases h) - | .require _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .while _ _ => isFalse (by intro h; cases h) - | .while _ _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .return _ => isFalse (by intro h; cases h) - | .return _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .break => isFalse (by intro h; cases h) - | .break, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .continue => isFalse (by intro h; cases h) - | .continue, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .require _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .while _ _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .return _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .break => isFalse (by intro h; cases h) - | .letDecl _ _ _, .continue => isFalse (by intro h; cases h) - | .assign _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .require _ => isFalse (by intro h; cases h) - | .assign _ _ _, .while _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .return _ => isFalse (by intro h; cases h) - | .assign _ _ _, .break => isFalse (by intro h; cases h) - | .assign _ _ _, .continue => isFalse (by intro h; cases h) - | .require _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .require _, .assign _ _ _ => isFalse (by intro h; cases h) - | .require _, .while _ _ => isFalse (by intro h; cases h) - | .require _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .require _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .require _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .require _, .return _ => isFalse (by intro h; cases h) - | .require _, .break => isFalse (by intro h; cases h) - | .require _, .continue => isFalse (by intro h; cases h) - | .while _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .while _ _, .assign _ _ _ => isFalse (by intro h; cases h) - | .while _ _, .require _ => isFalse (by intro h; cases h) - | .while _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .while _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .while _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .while _ _, .return _ => isFalse (by intro h; cases h) - | .while _ _, .break => isFalse (by intro h; cases h) - | .while _ _, .continue => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .require _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .while _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .return _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .break => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .continue => isFalse (by intro h; cases h) - | .internalCall _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .require _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .while _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .return _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .break => isFalse (by intro h; cases h) - | .internalCall _ _ _, .continue => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .require _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .while _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .return _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .break => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .continue => isFalse (by intro h; cases h) - | .return _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .return _, .assign _ _ _ => isFalse (by intro h; cases h) - | .return _, .require _ => isFalse (by intro h; cases h) - | .return _, .while _ _ => isFalse (by intro h; cases h) - | .return _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .return _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .return _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .return _, .break => isFalse (by intro h; cases h) - | .return _, .continue => isFalse (by intro h; cases h) - | .break, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .break, .assign _ _ _ => isFalse (by intro h; cases h) - | .break, .require _ => isFalse (by intro h; cases h) - | .break, .while _ _ => isFalse (by intro h; cases h) - | .break, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .break, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .break, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .break, .return _ => isFalse (by intro h; cases h) - | .break, .continue => isFalse (by intro h; cases h) - | .continue, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .continue, .assign _ _ _ => isFalse (by intro h; cases h) - | .continue, .require _ => isFalse (by intro h; cases h) - | .continue, .while _ _ => isFalse (by intro h; cases h) - | .continue, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .continue, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .continue, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .continue, .return _ => isFalse (by intro h; cases h) - | .continue, .break => isFalse (by intro h; cases h) - | .letDecl _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .require _, .ite _ _ _ => isFalse (by intro h; cases h) - | .while _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .return _, .ite _ _ _ => isFalse (by intro h; cases h) - | .break, .ite _ _ _ => isFalse (by intro h; cases h) - | .continue, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .require _ => isFalse (by intro h; cases h) - | .ite _ _ _, .while _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .return _ => isFalse (by intro h; cases h) - | .ite _ _ _, .break => isFalse (by intro h; cases h) - | .ite _ _ _, .continue => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .require _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .while _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .return _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .break => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .continue => isFalse (by intro h; cases h) - | .letDecl _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .require _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .while _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .return _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .break, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .continue, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .require _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .while _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .return _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .break => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .continue => isFalse (by intro h; cases h) - | .letDecl _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .require _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .while _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .return _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .break, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .continue, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .push rx vx, .push ry vy => - match StorageRef.decEq rx ry, (inferInstance : Decidable (vx = vy)) with - | isTrue hr, isTrue hv => isTrue (by cases hr; cases hv; rfl) - | isFalse hr, _ => isFalse (by intro h; cases h; exact hr rfl) - | _, isFalse hv => isFalse (by intro h; cases h; exact hv rfl) - | .pop rx, .pop ry => - match StorageRef.decEq rx ry with - | isTrue hr => isTrue (by cases hr; rfl) - | isFalse hr => isFalse (by intro h; cases h; exact hr rfl) - | .delete rx, .delete ry => - match StorageRef.decEq rx ry with - | isTrue hr => isTrue (by cases hr; rfl) - | isFalse hr => isFalse (by intro h; cases h; exact hr rfl) - | .delete _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .assign _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .require _ => isFalse (by intro h; cases h) - | .require _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .while _ _ => isFalse (by intro h; cases h) - | .while _ _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .return _ => isFalse (by intro h; cases h) - | .return _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .break => isFalse (by intro h; cases h) - | .break, .delete _ => isFalse (by intro h; cases h) - | .delete _, .continue => isFalse (by intro h; cases h) - | .continue, .delete _ => isFalse (by intro h; cases h) - | .delete _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .delete _ => isFalse (by intro h; cases h) - | .push _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .assign _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .require _ => isFalse (by intro h; cases h) - | .require _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .while _ _ => isFalse (by intro h; cases h) - | .while _ _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .return _ => isFalse (by intro h; cases h) - | .return _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .break => isFalse (by intro h; cases h) - | .break, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .continue => isFalse (by intro h; cases h) - | .continue, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .push _ _ => isFalse (by intro h; cases h) - | .pop _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .assign _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .require _ => isFalse (by intro h; cases h) - | .require _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .while _ _ => isFalse (by intro h; cases h) - | .while _ _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .return _ => isFalse (by intro h; cases h) - | .return _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .break => isFalse (by intro h; cases h) - | .break, .pop _ => isFalse (by intro h; cases h) - | .pop _, .continue => isFalse (by intro h; cases h) - | .continue, .pop _ => isFalse (by intro h; cases h) - | .for ix cx px bx, .for iy cy py by_ => - match Stmt.decEqList ix iy, Expr.decEq cx cy, Stmt.decEqList px py, Stmt.decEqList bx by_ with - | isTrue hi, isTrue hc, isTrue hp, isTrue hb => isTrue (by cases hi; cases hc; cases hp; cases hb; rfl) - | isFalse hi, _, _, _ => isFalse (by intro h; cases h; exact hi rfl) - | _, isFalse hc, _, _ => isFalse (by intro h; cases h; exact hc rfl) - | _, _, isFalse hp, _ => isFalse (by intro h; cases h; exact hp rfl) - | _, _, _, isFalse hb => isFalse (by intro h; cases h; exact hb rfl) - | .for _ _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .require _ => isFalse (by intro h; cases h) - | .require _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .while _ _ => isFalse (by intro h; cases h) - | .while _ _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .return _ => isFalse (by intro h; cases h) - | .return _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .break => isFalse (by intro h; cases h) - | .break, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .continue => isFalse (by intro h; cases h) - | .continue, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .letDecl _ _ _ => isFalse (by intro h; cases h) - | .letDecl _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .letStorage _ _ => isFalse (by intro h; cases h) - | .letStorage _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .assign _ _ _ => isFalse (by intro h; cases h) - | .assign _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .require _ => isFalse (by intro h; cases h) - | .require _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .while _ _ => isFalse (by intro h; cases h) - | .while _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .for _ _ _ _ => isFalse (by intro h; cases h) - | .for _ _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .ite _ _ _ => isFalse (by intro h; cases h) - | .ite _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .new _ _ _ _ _ => isFalse (by intro h; cases h) - | .new _ _ _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .internalCall _ _ _ => isFalse (by intro h; cases h) - | .internalCall _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .externalCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .externalCall _ _ _ _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .lowLevelCall _ _ _ _ _ _ => isFalse (by intro h; cases h) - | .lowLevelCall _ _ _ _ _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .checkedCall _ _ _ _ _ _ _ _ _ => - isFalse (by intro h; cases h) - | .checkedCall _ _ _ _ _ _ _ _ _, .delegateCall _ _ _ _ => - isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .return _ => isFalse (by intro h; cases h) - | .return _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .break => isFalse (by intro h; cases h) - | .break, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .continue => isFalse (by intro h; cases h) - | .continue, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .push _ _ => isFalse (by intro h; cases h) - | .push _ _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .pop _ => isFalse (by intro h; cases h) - | .pop _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - | .delegateCall _ _ _ _, .delete _ => isFalse (by intro h; cases h) - | .delete _, .delegateCall _ _ _ _ => isFalse (by intro h; cases h) - - private def Stmt.decEqList : (as bs : List Stmt) -> Decidable (as = bs) - | [], [] => isTrue rfl - | a :: as, b :: bs => - match Stmt.decEq a b, Stmt.decEqList as bs with - | isTrue ha, isTrue hs => isTrue (by cases ha; cases hs; rfl) - | isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) - | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) - | [], _ :: _ => isFalse (by intro h; cases h) - | _ :: _, [] => isFalse (by intro h; cases h) -end - -instance : DecidableEq Stmt := - Stmt.decEq - -abbrev Body := List Stmt - -structure Param where - name : Ident - ty : ABI.ABIType - deriving DecidableEq, Repr, Inhabited - -structure StorageDecl where - name : Ident - ty : StorageType - deriving DecidableEq, Repr, Inhabited - -structure ConstructorDecl where - params : List Param - body : List Stmt - deriving DecidableEq, Repr, Inhabited - --- Currently this covers storage structs --- The ABI technically has no structs, --- Solidity implements call-parameter structs through ABI tuples -structure StructDecl where - name : Ident - fields : List StorageDecl - deriving DecidableEq, Repr, Inhabited - -structure FunctionDecl where - name : Ident - params : List Param - /-- ABI return types, in order. `[]` = void; multi-element lists encode flat, as solc does. -/ - returnType : List ABIType := [] - body : List Stmt - deriving DecidableEq, Repr, Inhabited - -structure TransitionDecl where - name : Ident - params : List Param - /-- ABI return types, in order. `[]` = void; multi-element lists encode flat, as solc does. -/ - returnType : List ABIType := [] - body : List Stmt - deriving DecidableEq, Repr, Inhabited - -structure ContractDecl where - name : Ident - storage : List StorageDecl - ctor : ConstructorDecl - structs : List StructDecl := [] -- Maybe these should not be per-contract. Zoe: if we are inlining them anyway, do we still need this? - functions : List FunctionDecl := [] - transitions : List TransitionDecl := [] - receive : Option TransitionDecl := none - fallback : Option TransitionDecl := none - deriving DecidableEq, Repr, Inhabited - -abbrev Program := List ContractDecl - -end Solm +import Solm.Syntax.Basic +import Solm.Syntax.DecEq diff --git a/Solm/Syntax/Basic.lean b/Solm/Syntax/Basic.lean index 8df0a682..a94576a7 100644 --- a/Solm/Syntax/Basic.lean +++ b/Solm/Syntax/Basic.lean @@ -16,18 +16,17 @@ inductive KeyValue where | fixedBytes : Fin 32 -> List UInt8 -> KeyValue deriving Repr, Inhabited +/- Storage deref step. -/ inductive EvaledStorageRefStep where | field : Ident -> EvaledStorageRefStep | tupleElem : Nat -> EvaledStorageRefStep | mindex : KeyValue -> EvaledStorageRefStep | aindex : KeyValue -> EvaledStorageRefStep - /- Marker for "the length of the array reached so far". A distinct ref the layout - resolves to wherever it stores that array's length — the semantics commits to no - particular slot convention (solc puts it at the array's base slot; another layout - may put it elsewhere). Only the array's length query produces this step. -/ + /- Accessor for the slot that holds the length of an array. -/ | length : EvaledStorageRefStep deriving Repr, Inhabited +/- The evaluated path to a storage reference. -/ structure EvaledStorageRef where base : Ident steps : List EvaledStorageRefStep := [] @@ -96,8 +95,8 @@ inductive BinaryOp where | exp deriving Repr, Inhabited -/-- Whether a variable path is rooted in a memory **local** or **storage**. Resolved statically - by the spec author / frontend, exactly as solc resolves the name. -/ +/-- Whether a variable path is rooted in a memory **local** or **storage**. + Resolved statically, similar to solc. -/ inductive VarOrigin where | localVar | storage @@ -105,8 +104,11 @@ inductive VarOrigin where mutual -/- Expressions are intentionally lightweight for now. We are aiming for a meaningful - subset of Solidity. -/ +/- + - Expressions. + - In Solm, expressions are pure and side-effect free (similar to Clight). + - All stateful operations are statements. + -/ inductive Expr where | intLit : Int -> Expr | boolLit : Bool -> Expr @@ -132,7 +134,9 @@ inductive Expr where | env : EnvVar -> Expr /- for struct fields -/ | field : Expr -> Ident -> Expr + /- Storage reference -/ | storage : StorageRef -> Expr + /- Predicate asserting that an integer expression is within the range of the specified type. -/ | inRange : IntType -> Expr -> Expr | cast : Expr -> StorageType -> Expr /- TODO do we really need casting?-/ | addrOf : Expr -> Expr @@ -144,8 +148,7 @@ inductive Expr where storage array length; local paths read the in-memory value and return its array/byte count. -/ | arrayLength : VarOrigin -> StorageRef -> Expr /- `keccak256(b)`: the Keccak-256 hash of the dynamic bytes `b`, as a `bytes32` value. The hash - primitive is the same `ffi.KEC` the EVM's `KECCAK256` opcode uses, so equivalence reduces to - equality of the hashed bytes. -/ + primitive is the same `ffi.KEC` the EVM's `KECCAK256` opcode uses. -/ | keccak256 : Expr -> Expr /- `abi.encodePacked(e₁, …)`: the non-padded ("packed") ABI encoding of the listed values, as a dynamic `bytes`. Each operand carries its (statically known) `ABIType`, which fixes its packed @@ -180,14 +183,20 @@ inductive StorageRefStep where | mindex : Expr -> StorageRefStep | aindex : Expr -> StorageRefStep -structure StorageRef where /- TODO better name, since it can be a reference to locals or storage -/ +/- A reference to storage. The base variable is either a storage variable or a local variable alias. -/ +structure StorageRef where base : Ident steps : List StorageRefStep := [] -/- Zoe: Shall we use StorageRef at the Expr level too instead of having field? -/ - end +namespace StorageRef + +def var (name : Ident) : StorageRef := + { base := name } + +end StorageRef + instance : Repr ByteArray where reprPrec b _ := repr b.data @@ -198,13 +207,6 @@ deriving instance Inhabited for StorageRefStep deriving instance Repr for StorageRef deriving instance Inhabited for StorageRef -namespace StorageRef - -def var (name : Ident) : StorageRef := - { base := name } - -end StorageRef - inductive AssignRhs where | expr : Expr -> AssignRhs -- Do we want non-determinism? @@ -212,9 +214,9 @@ inductive AssignRhs where deriving Repr, Inhabited inductive Stmt where - /- local variable -/ + /- local variable declaration (values are in-memory copies)-/ | letDecl : Ident -> Option ABIType -> Expr -> Stmt - /- local storage alias: `T storage x = ref`; stores an evaluated storage pointer in locals -/ + /- local storage alias (values are evaluated storage references) -/ | letStorage : Ident -> StorageRef -> Stmt /- `uint256 x = gasleft()`: bind `x` to a nondeterministic gas value (Solm tracks no gas). -/ | letGas : Ident -> Stmt @@ -228,7 +230,7 @@ inductive Stmt where | for : List Stmt /- init -/ -> Expr /- cond -/ -> List Stmt /- post -/ -> List Stmt /- body -/ -> Stmt /- conditional: `if cond { thenBranch } else { elseBranch }`; a no-`else` `if` is `elseBranch = []` -/ | ite : Expr -> List Stmt -> List Stmt -> Stmt - /- constructor call; `salt = none` ⇒ CREATE, `some e` (bytes32) ⇒ CREATE2. -/ + /- constructor call: `salt = none` ⇒ CREATE, `some e` (bytes32) ⇒ CREATE2. -/ | new : Ident -> Expr /- ETH to send -/ -> List Expr -> Ident /- return value binder -/ -> (salt : Option Expr := none) -> Stmt /- internal and external call results are explicitly let-bound -/ @@ -258,7 +260,7 @@ inductive Stmt where | break : Stmt | continue : Stmt /- `arr.push(v?)`: grow a dynamic storage array by one. `some v` appends scalar `v`; `none` is a - grow-only push (structured elements — the new slots are zero, fields set by later writes). -/ + grow-only push (the new slots are zero). -/ | push : StorageRef -> Option Expr -> Stmt /- `arr.pop()`: remove the last element of a dynamic storage array (reverts if empty), clearing the slot and shrinking its length by one -/ @@ -268,6 +270,7 @@ inductive Stmt where deriving Repr, Inhabited +/-- Body of a function, constructor, or transition is a sequence of statements. -/ abbrev Body := List Stmt structure Param where @@ -293,10 +296,12 @@ structure StructDecl where fields : List StorageDecl deriving Repr, Inhabited +/- For now, internal function interface only accept ABI types. + - In the future, we may extend this with non-ABI types as well (e.g., mappings). -/ structure FunctionDecl where name : Ident params : List Param - /-- ABI return types, in order. `[]` = void; multi-element lists encode flat, as solc does. -/ + /-- ABI return types (potentially, multi-element; `[]` = void) -/ returnType : List ABIType := [] body : List Stmt deriving Repr, Inhabited @@ -304,11 +309,12 @@ structure FunctionDecl where structure TransitionDecl where name : Ident params : List Param - /-- ABI return types, in order. `[]` = void; multi-element lists encode flat, as solc does. -/ + /-- ABI return types (potentially, multi-element; `[]` = void) -/ returnType : List ABIType := [] body : List Stmt deriving Repr, Inhabited +/- A top-level contract declaration. -/ structure ContractDecl where name : Ident storage : List StorageDecl From 0884cbe63edaa2353156eaee81f313f6cd72762a Mon Sep 17 00:00:00 2001 From: zoep Date: Sat, 25 Jul 2026 15:17:17 +0300 Subject: [PATCH 03/38] Solm: comments --- Solm/SolidityLayout.lean | 4 ++++ Solm/VyperLayout.lean | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Solm/SolidityLayout.lean b/Solm/SolidityLayout.lean index ac5225aa..9f36ce79 100644 --- a/Solm/SolidityLayout.lean +++ b/Solm/SolidityLayout.lean @@ -13,6 +13,10 @@ open ABI - -/ +/- + - This is an attempt to mechanize the Solidity storage layout generation. + - It is currently work in progress and known to be incomplete and not fully correct. +-/ -- Difference with `StorageLoc` is that size can be larger than a slot, so we can deal with broad intermediate locs structure IntermediateStorageLoc where diff --git a/Solm/VyperLayout.lean b/Solm/VyperLayout.lean index d1444c69..93270b70 100644 --- a/Solm/VyperLayout.lean +++ b/Solm/VyperLayout.lean @@ -7,9 +7,7 @@ open ABI /-! # Vyper storage-layout helpers -Vyper exposes concrete storage layouts through compiler output, so this module intentionally does -not try to mirror the compiler's allocation algorithm. It only packages the representation rules -needed by hand-recorded layouts. +This file only packages the representation rules needed by hand-recorded layouts. -/ def vyperWordLoc (slot : EVM.Word) (ty : ElemType) : StorageLoc := From 0b7f620d7ed2396bfd86e93a574d7d38981957cc Mon Sep 17 00:00:00 2001 From: zoep Date: Sat, 25 Jul 2026 15:20:52 +0300 Subject: [PATCH 04/38] Solm: Value rafactoring --- Solm/Value.lean | 207 +----------------------------------------- Solm/Value/Basic.lean | 25 +++++ Solm/Value/DecEq.lean | 178 ++++++++++++++++++++++++++++++++++++ TODO.md | 19 ++++ 4 files changed, 224 insertions(+), 205 deletions(-) create mode 100644 Solm/Value/Basic.lean create mode 100644 Solm/Value/DecEq.lean diff --git a/Solm/Value.lean b/Solm/Value.lean index 9285688c..5566a4c7 100644 --- a/Solm/Value.lean +++ b/Solm/Value.lean @@ -1,212 +1,9 @@ import Std.Data.HashMap - -import EVM.Types -import ABI.Types -import Solm.Syntax +import Solm.Value.Basic +import Solm.Value.DecEq namespace Solm -/- Runtime values for the first semantics pass. Mappings are finite maps here; - open-world behavior and typed defaults can be refined later. -/ -inductive Value where - | int : Int -> Value - | bool : Bool -> Value - | address : EVM.Address -> Value - | struct : Ident -> List (Ident × Value) -> Value - | array : List Value -> Value /- arrays can be copied to memory, so we need array values -/ - | tuple : List Value -> Value - /- Fixed-size `bytesN`, carrying the ABI type index and the bytes in Solidity order. -/ - | fixedBytes : Fin 32 -> List UInt8 -> Value - /- dynamic `bytes` (arbitrary-length byte string), e.g. low-level `.call` calldata -/ - | bytes : ByteArray -> Value - /- Internal-only local alias for Solidity `storage` variables. Not ABI-encodable or storable. -/ - | storageRef : EvaledStorageRef -> StorageType -> Value - | unit : Value - deriving Inhabited - - -/- Zoe: We need a way to represent references to mappings, arrays, and structs in storage -/ - -mutual - private def Value.decEq : (a b : Value) -> Decidable (a = b) - | .int x, .int y => - match (inferInstance : Decidable (x = y)) with - | isTrue h => isTrue (by subst y; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .bool x, .bool y => - match (inferInstance : Decidable (x = y)) with - | isTrue h => isTrue (by subst y; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .address x, .address y => - match (inferInstance : Decidable (x = y)) with - | isTrue h => isTrue (by subst y; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .struct tag fields, .struct tag' fields' => - match (inferInstance : Decidable (tag = tag')), Value.decEqNamedList fields fields' with - | isTrue htag, isTrue hfields => isTrue (by subst tag'; cases hfields; rfl) - | isFalse htag, _ => isFalse (by intro h'; cases h'; exact htag rfl) - | _, isFalse hfields => isFalse (by intro h'; cases h'; exact hfields rfl) - | .array xs, .array ys => - match Value.decEqList xs ys with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .tuple xs, .tuple ys => - match Value.decEqList xs ys with - | isTrue h => isTrue (by cases h; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .fixedBytes n bs, .fixedBytes m bs' => - match (inferInstance : Decidable (n = m)), (inferInstance : Decidable (bs = bs')) with - | isTrue hn, isTrue hbytes => isTrue (by cases hn; cases hbytes; rfl) - | isFalse hn, _ => isFalse (by intro h; cases h; exact hn rfl) - | _, isFalse hbytes => isFalse (by intro h; cases h; exact hbytes rfl) - | .unit, .unit => isTrue rfl - | .bytes x, .bytes y => - match (inferInstance : Decidable (x = y)) with - | isTrue h => isTrue (by subst y; rfl) - | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) - | .storageRef rx tx, .storageRef ry ty => - match (inferInstance : Decidable (rx = ry)), (inferInstance : Decidable (tx = ty)) with - | isTrue hr, isTrue ht => isTrue (by cases hr; cases ht; rfl) - | isFalse hr, _ => isFalse (by intro h; cases h; exact hr rfl) - | _, isFalse ht => isFalse (by intro h; cases h; exact ht rfl) - | .int _, .bool _ => isFalse (by intro h; cases h) - | .int _, .address _ => isFalse (by intro h; cases h) - | .int _, .struct _ _ => isFalse (by intro h; cases h) - | .int _, .array _ => isFalse (by intro h; cases h) - | .int _, .tuple _ => isFalse (by intro h; cases h) - | .int _, .fixedBytes _ _ => isFalse (by intro h; cases h) - | .int _, .unit => isFalse (by intro h; cases h) - | .bool _, .int _ => isFalse (by intro h; cases h) - | .bool _, .address _ => isFalse (by intro h; cases h) - | .bool _, .struct _ _ => isFalse (by intro h; cases h) - | .bool _, .array _ => isFalse (by intro h; cases h) - | .bool _, .tuple _ => isFalse (by intro h; cases h) - | .bool _, .fixedBytes _ _ => isFalse (by intro h; cases h) - | .bool _, .unit => isFalse (by intro h; cases h) - | .address _, .int _ => isFalse (by intro h; cases h) - | .address _, .bool _ => isFalse (by intro h; cases h) - | .address _, .struct _ _ => isFalse (by intro h; cases h) - | .address _, .array _ => isFalse (by intro h; cases h) - | .address _, .tuple _ => isFalse (by intro h; cases h) - | .address _, .fixedBytes _ _ => isFalse (by intro h; cases h) - | .address _, .unit => isFalse (by intro h; cases h) - | .struct _ _, .int _ => isFalse (by intro h; cases h) - | .struct _ _, .bool _ => isFalse (by intro h; cases h) - | .struct _ _, .address _ => isFalse (by intro h; cases h) - | .struct _ _, .array _ => isFalse (by intro h; cases h) - | .struct _ _, .tuple _ => isFalse (by intro h; cases h) - | .struct _ _, .fixedBytes _ _ => isFalse (by intro h; cases h) - | .struct _ _, .unit => isFalse (by intro h; cases h) - | .array _, .int _ => isFalse (by intro h; cases h) - | .array _, .bool _ => isFalse (by intro h; cases h) - | .array _, .address _ => isFalse (by intro h; cases h) - | .array _, .struct _ _ => isFalse (by intro h; cases h) - | .array _, .tuple _ => isFalse (by intro h; cases h) - | .array _, .fixedBytes _ _ => isFalse (by intro h; cases h) - | .array _, .unit => isFalse (by intro h; cases h) - | .tuple _, .int _ => isFalse (by intro h; cases h) - | .tuple _, .bool _ => isFalse (by intro h; cases h) - | .tuple _, .address _ => isFalse (by intro h; cases h) - | .tuple _, .struct _ _ => isFalse (by intro h; cases h) - | .tuple _, .array _ => isFalse (by intro h; cases h) - | .tuple _, .fixedBytes _ _ => isFalse (by intro h; cases h) - | .tuple _, .unit => isFalse (by intro h; cases h) - | .fixedBytes _ _, .int _ => isFalse (by intro h; cases h) - | .fixedBytes _ _, .bool _ => isFalse (by intro h; cases h) - | .fixedBytes _ _, .address _ => isFalse (by intro h; cases h) - | .fixedBytes _ _, .struct _ _ => isFalse (by intro h; cases h) - | .fixedBytes _ _, .array _ => isFalse (by intro h; cases h) - | .fixedBytes _ _, .tuple _ => isFalse (by intro h; cases h) - | .fixedBytes _ _, .unit => isFalse (by intro h; cases h) - | .unit, .int _ => isFalse (by intro h; cases h) - | .unit, .bool _ => isFalse (by intro h; cases h) - | .unit, .address _ => isFalse (by intro h; cases h) - | .unit, .struct _ _ => isFalse (by intro h; cases h) - | .unit, .array _ => isFalse (by intro h; cases h) - | .unit, .tuple _ => isFalse (by intro h; cases h) - | .unit, .fixedBytes _ _ => isFalse (by intro h; cases h) - | .int _, .bytes _ => isFalse (by intro h; cases h) - | .bool _, .bytes _ => isFalse (by intro h; cases h) - | .address _, .bytes _ => isFalse (by intro h; cases h) - | .struct _ _, .bytes _ => isFalse (by intro h; cases h) - | .array _, .bytes _ => isFalse (by intro h; cases h) - | .tuple _, .bytes _ => isFalse (by intro h; cases h) - | .fixedBytes _ _, .bytes _ => isFalse (by intro h; cases h) - | .unit, .bytes _ => isFalse (by intro h; cases h) - | .bytes _, .int _ => isFalse (by intro h; cases h) - | .bytes _, .bool _ => isFalse (by intro h; cases h) - | .bytes _, .address _ => isFalse (by intro h; cases h) - | .bytes _, .struct _ _ => isFalse (by intro h; cases h) - | .bytes _, .array _ => isFalse (by intro h; cases h) - | .bytes _, .tuple _ => isFalse (by intro h; cases h) - | .bytes _, .fixedBytes _ _ => isFalse (by intro h; cases h) - | .bytes _, .unit => isFalse (by intro h; cases h) - | .storageRef _ _, .int _ => isFalse (by intro h; cases h) - | .int _, .storageRef _ _ => isFalse (by intro h; cases h) - | .storageRef _ _, .bool _ => isFalse (by intro h; cases h) - | .bool _, .storageRef _ _ => isFalse (by intro h; cases h) - | .storageRef _ _, .address _ => isFalse (by intro h; cases h) - | .address _, .storageRef _ _ => isFalse (by intro h; cases h) - | .storageRef _ _, .struct _ _ => isFalse (by intro h; cases h) - | .struct _ _, .storageRef _ _ => isFalse (by intro h; cases h) - | .storageRef _ _, .array _ => isFalse (by intro h; cases h) - | .array _, .storageRef _ _ => isFalse (by intro h; cases h) - | .storageRef _ _, .tuple _ => isFalse (by intro h; cases h) - | .tuple _, .storageRef _ _ => isFalse (by intro h; cases h) - | .storageRef _ _, .fixedBytes _ _ => isFalse (by intro h; cases h) - | .fixedBytes _ _, .storageRef _ _ => isFalse (by intro h; cases h) - | .storageRef _ _, .bytes _ => isFalse (by intro h; cases h) - | .bytes _, .storageRef _ _ => isFalse (by intro h; cases h) - | .storageRef _ _, .unit => isFalse (by intro h; cases h) - | .unit, .storageRef _ _ => isFalse (by intro h; cases h) - - private def Value.decEqList : (as bs : List Value) -> Decidable (as = bs) - | [], [] => isTrue rfl - | a :: as, b :: bs => - match Value.decEq a b, Value.decEqList as bs with - | isTrue ha, isTrue hs => isTrue (by cases ha; cases hs; rfl) - | isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) - | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) - | [], _ :: _ => isFalse (by intro h; cases h) - | _ :: _, [] => isFalse (by intro h; cases h) - - private def Value.decEqNamedList : - (as bs : List (Ident × Value)) -> Decidable (as = bs) - | [], [] => isTrue rfl - | (name, value) :: as, (name', value') :: bs => - match (inferInstance : Decidable (name = name')), - Value.decEq value value', Value.decEqNamedList as bs with - | isTrue hname, isTrue hvalue, isTrue hs => - isTrue (by subst name'; cases hvalue; cases hs; rfl) - | isFalse hname, _, _ => - isFalse (by intro h; cases h; exact hname rfl) - | _, isFalse hvalue, _ => - isFalse (by intro h; cases h; exact hvalue rfl) - | _, _, isFalse hs => - isFalse (by intro h; cases h; exact hs rfl) - | [], _ :: _ => isFalse (by intro h; cases h) - | _ :: _, [] => isFalse (by intro h; cases h) - - private def Value.decEqPairList : - (as bs : List (Value × Value)) -> Decidable (as = bs) - | [], [] => isTrue rfl - | (key, value) :: as, (key', value') :: bs => - match Value.decEq key key', Value.decEq value value', Value.decEqPairList as bs with - | isTrue hkey, isTrue hvalue, isTrue hs => - isTrue (by cases hkey; cases hvalue; cases hs; rfl) - | isFalse hkey, _, _ => - isFalse (by intro h; cases h; exact hkey rfl) - | _, isFalse hvalue, _ => - isFalse (by intro h; cases h; exact hvalue rfl) - | _, _, isFalse hs => - isFalse (by intro h; cases h; exact hs rfl) - | [], _ :: _ => isFalse (by intro h; cases h) - | _ :: _, [] => isFalse (by intro h; cases h) -end - -instance : DecidableEq Value := - Value.decEq - def valueToWord : Value -> Option EVM.Word | .int i => pure $ EVM.wordOfInt i | .unit => .none diff --git a/Solm/Value/Basic.lean b/Solm/Value/Basic.lean new file mode 100644 index 00000000..15a0f356 --- /dev/null +++ b/Solm/Value/Basic.lean @@ -0,0 +1,25 @@ +import EVM.Types +import ABI.Types +import Solm.Syntax + +namespace Solm + +/- Solm in-memory value representation. -/ +inductive Value where + /- Local variables can store unbounded integers -/ + | int : Int -> Value + | bool : Bool -> Value + | address : EVM.Address -> Value + | struct : Ident -> List (Ident × Value) -> Value + | array : List Value -> Value /- arrays can be copied to memory, so we need array values -/ + | tuple : List Value -> Value + /- Fixed-size `bytesN`, carrying the ABI type index and the bytes in Solidity order. -/ + | fixedBytes : Fin 32 -> List UInt8 -> Value + /- dynamic `bytes` (arbitrary-length byte string), e.g. low-level `.call` calldata -/ + | bytes : ByteArray -> Value + /- Storage reference alias -/ + | storageRef : EvaledStorageRef -> StorageType -> Value + | unit : Value + deriving Inhabited + +end Solm diff --git a/Solm/Value/DecEq.lean b/Solm/Value/DecEq.lean new file mode 100644 index 00000000..fd3f18a4 --- /dev/null +++ b/Solm/Value/DecEq.lean @@ -0,0 +1,178 @@ +import Solm.Value.Basic + +/-! +`DecidableEq Value`. + +`Value` carries nested `List` payloads (`struct`, `array`, `tuple`), a shape Lean's +`deriving DecidableEq` handler cannot process, so the instance is a hand-written +structural `decEq`. Kept out of `Solm.Value.Basic` so that file reads as the type +definition alone. +-/ + +namespace Solm + +mutual + private def Value.decEq : (a b : Value) -> Decidable (a = b) + | .int x, .int y => + match (inferInstance : Decidable (x = y)) with + | isTrue h => isTrue (by subst y; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .bool x, .bool y => + match (inferInstance : Decidable (x = y)) with + | isTrue h => isTrue (by subst y; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .address x, .address y => + match (inferInstance : Decidable (x = y)) with + | isTrue h => isTrue (by subst y; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .struct tag fields, .struct tag' fields' => + match (inferInstance : Decidable (tag = tag')), Value.decEqNamedList fields fields' with + | isTrue htag, isTrue hfields => isTrue (by subst tag'; cases hfields; rfl) + | isFalse htag, _ => isFalse (by intro h'; cases h'; exact htag rfl) + | _, isFalse hfields => isFalse (by intro h'; cases h'; exact hfields rfl) + | .array xs, .array ys => + match Value.decEqList xs ys with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .tuple xs, .tuple ys => + match Value.decEqList xs ys with + | isTrue h => isTrue (by cases h; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .fixedBytes n bs, .fixedBytes m bs' => + match (inferInstance : Decidable (n = m)), (inferInstance : Decidable (bs = bs')) with + | isTrue hn, isTrue hbytes => isTrue (by cases hn; cases hbytes; rfl) + | isFalse hn, _ => isFalse (by intro h; cases h; exact hn rfl) + | _, isFalse hbytes => isFalse (by intro h; cases h; exact hbytes rfl) + | .unit, .unit => isTrue rfl + | .bytes x, .bytes y => + match (inferInstance : Decidable (x = y)) with + | isTrue h => isTrue (by subst y; rfl) + | isFalse h => isFalse (by intro h'; cases h'; exact h rfl) + | .storageRef rx tx, .storageRef ry ty => + match (inferInstance : Decidable (rx = ry)), (inferInstance : Decidable (tx = ty)) with + | isTrue hr, isTrue ht => isTrue (by cases hr; cases ht; rfl) + | isFalse hr, _ => isFalse (by intro h; cases h; exact hr rfl) + | _, isFalse ht => isFalse (by intro h; cases h; exact ht rfl) + | .int _, .bool _ => isFalse (by intro h; cases h) + | .int _, .address _ => isFalse (by intro h; cases h) + | .int _, .struct _ _ => isFalse (by intro h; cases h) + | .int _, .array _ => isFalse (by intro h; cases h) + | .int _, .tuple _ => isFalse (by intro h; cases h) + | .int _, .fixedBytes _ _ => isFalse (by intro h; cases h) + | .int _, .unit => isFalse (by intro h; cases h) + | .bool _, .int _ => isFalse (by intro h; cases h) + | .bool _, .address _ => isFalse (by intro h; cases h) + | .bool _, .struct _ _ => isFalse (by intro h; cases h) + | .bool _, .array _ => isFalse (by intro h; cases h) + | .bool _, .tuple _ => isFalse (by intro h; cases h) + | .bool _, .fixedBytes _ _ => isFalse (by intro h; cases h) + | .bool _, .unit => isFalse (by intro h; cases h) + | .address _, .int _ => isFalse (by intro h; cases h) + | .address _, .bool _ => isFalse (by intro h; cases h) + | .address _, .struct _ _ => isFalse (by intro h; cases h) + | .address _, .array _ => isFalse (by intro h; cases h) + | .address _, .tuple _ => isFalse (by intro h; cases h) + | .address _, .fixedBytes _ _ => isFalse (by intro h; cases h) + | .address _, .unit => isFalse (by intro h; cases h) + | .struct _ _, .int _ => isFalse (by intro h; cases h) + | .struct _ _, .bool _ => isFalse (by intro h; cases h) + | .struct _ _, .address _ => isFalse (by intro h; cases h) + | .struct _ _, .array _ => isFalse (by intro h; cases h) + | .struct _ _, .tuple _ => isFalse (by intro h; cases h) + | .struct _ _, .fixedBytes _ _ => isFalse (by intro h; cases h) + | .struct _ _, .unit => isFalse (by intro h; cases h) + | .array _, .int _ => isFalse (by intro h; cases h) + | .array _, .bool _ => isFalse (by intro h; cases h) + | .array _, .address _ => isFalse (by intro h; cases h) + | .array _, .struct _ _ => isFalse (by intro h; cases h) + | .array _, .tuple _ => isFalse (by intro h; cases h) + | .array _, .fixedBytes _ _ => isFalse (by intro h; cases h) + | .array _, .unit => isFalse (by intro h; cases h) + | .tuple _, .int _ => isFalse (by intro h; cases h) + | .tuple _, .bool _ => isFalse (by intro h; cases h) + | .tuple _, .address _ => isFalse (by intro h; cases h) + | .tuple _, .struct _ _ => isFalse (by intro h; cases h) + | .tuple _, .array _ => isFalse (by intro h; cases h) + | .tuple _, .fixedBytes _ _ => isFalse (by intro h; cases h) + | .tuple _, .unit => isFalse (by intro h; cases h) + | .fixedBytes _ _, .int _ => isFalse (by intro h; cases h) + | .fixedBytes _ _, .bool _ => isFalse (by intro h; cases h) + | .fixedBytes _ _, .address _ => isFalse (by intro h; cases h) + | .fixedBytes _ _, .struct _ _ => isFalse (by intro h; cases h) + | .fixedBytes _ _, .array _ => isFalse (by intro h; cases h) + | .fixedBytes _ _, .tuple _ => isFalse (by intro h; cases h) + | .fixedBytes _ _, .unit => isFalse (by intro h; cases h) + | .unit, .int _ => isFalse (by intro h; cases h) + | .unit, .bool _ => isFalse (by intro h; cases h) + | .unit, .address _ => isFalse (by intro h; cases h) + | .unit, .struct _ _ => isFalse (by intro h; cases h) + | .unit, .array _ => isFalse (by intro h; cases h) + | .unit, .tuple _ => isFalse (by intro h; cases h) + | .unit, .fixedBytes _ _ => isFalse (by intro h; cases h) + | .int _, .bytes _ => isFalse (by intro h; cases h) + | .bool _, .bytes _ => isFalse (by intro h; cases h) + | .address _, .bytes _ => isFalse (by intro h; cases h) + | .struct _ _, .bytes _ => isFalse (by intro h; cases h) + | .array _, .bytes _ => isFalse (by intro h; cases h) + | .tuple _, .bytes _ => isFalse (by intro h; cases h) + | .fixedBytes _ _, .bytes _ => isFalse (by intro h; cases h) + | .unit, .bytes _ => isFalse (by intro h; cases h) + | .bytes _, .int _ => isFalse (by intro h; cases h) + | .bytes _, .bool _ => isFalse (by intro h; cases h) + | .bytes _, .address _ => isFalse (by intro h; cases h) + | .bytes _, .struct _ _ => isFalse (by intro h; cases h) + | .bytes _, .array _ => isFalse (by intro h; cases h) + | .bytes _, .tuple _ => isFalse (by intro h; cases h) + | .bytes _, .fixedBytes _ _ => isFalse (by intro h; cases h) + | .bytes _, .unit => isFalse (by intro h; cases h) + | .storageRef _ _, .int _ => isFalse (by intro h; cases h) + | .int _, .storageRef _ _ => isFalse (by intro h; cases h) + | .storageRef _ _, .bool _ => isFalse (by intro h; cases h) + | .bool _, .storageRef _ _ => isFalse (by intro h; cases h) + | .storageRef _ _, .address _ => isFalse (by intro h; cases h) + | .address _, .storageRef _ _ => isFalse (by intro h; cases h) + | .storageRef _ _, .struct _ _ => isFalse (by intro h; cases h) + | .struct _ _, .storageRef _ _ => isFalse (by intro h; cases h) + | .storageRef _ _, .array _ => isFalse (by intro h; cases h) + | .array _, .storageRef _ _ => isFalse (by intro h; cases h) + | .storageRef _ _, .tuple _ => isFalse (by intro h; cases h) + | .tuple _, .storageRef _ _ => isFalse (by intro h; cases h) + | .storageRef _ _, .fixedBytes _ _ => isFalse (by intro h; cases h) + | .fixedBytes _ _, .storageRef _ _ => isFalse (by intro h; cases h) + | .storageRef _ _, .bytes _ => isFalse (by intro h; cases h) + | .bytes _, .storageRef _ _ => isFalse (by intro h; cases h) + | .storageRef _ _, .unit => isFalse (by intro h; cases h) + | .unit, .storageRef _ _ => isFalse (by intro h; cases h) + + private def Value.decEqList : (as bs : List Value) -> Decidable (as = bs) + | [], [] => isTrue rfl + | a :: as, b :: bs => + match Value.decEq a b, Value.decEqList as bs with + | isTrue ha, isTrue hs => isTrue (by cases ha; cases hs; rfl) + | isFalse ha, _ => isFalse (by intro h; cases h; exact ha rfl) + | _, isFalse hs => isFalse (by intro h; cases h; exact hs rfl) + | [], _ :: _ => isFalse (by intro h; cases h) + | _ :: _, [] => isFalse (by intro h; cases h) + + private def Value.decEqNamedList : + (as bs : List (Ident × Value)) -> Decidable (as = bs) + | [], [] => isTrue rfl + | (name, value) :: as, (name', value') :: bs => + match (inferInstance : Decidable (name = name')), + Value.decEq value value', Value.decEqNamedList as bs with + | isTrue hname, isTrue hvalue, isTrue hs => + isTrue (by subst name'; cases hvalue; cases hs; rfl) + | isFalse hname, _, _ => + isFalse (by intro h; cases h; exact hname rfl) + | _, isFalse hvalue, _ => + isFalse (by intro h; cases h; exact hvalue rfl) + | _, _, isFalse hs => + isFalse (by intro h; cases h; exact hs rfl) + | [], _ :: _ => isFalse (by intro h; cases h) + | _ :: _, [] => isFalse (by intro h; cases h) +end + +instance : DecidableEq Value := + Value.decEq + +end Solm diff --git a/TODO.md b/TODO.md index 67e22e42..fdb47892 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,22 @@ +# Release TODOs + +- [X] EquiVM/EVM +- [ ] Solm +- [ ] ABI +- [ ] Reasoning +- [ ] Examples + + [ ] Concrete syntax +- [ ] Benchmarks + + [ ] Concrete syntax +- [ ] Proofs +- [ ] Misc +- [ ] Docs + + [ ] README + + [ ] GUIDE +- [ ] CI/CD + + + # Solm Semantics - [X] Constructor calls + currently we don't have From fd5e8df9648e55bd47bf59314ec08aaa83a6aaf4 Mon Sep 17 00:00:00 2001 From: zoep Date: Sat, 25 Jul 2026 15:41:48 +0300 Subject: [PATCH 05/38] Solm: Move disatch theorem to reasoning --- .../CompoundIII/CometRewards/Trusted.lean | 2 +- Benchmarks/Dss/Cat/Trusted.lean | 2 +- Benchmarks/Dss/Clipper/Trusted.lean | 2 +- Benchmarks/Dss/Cure/Trusted.lean | 2 +- Benchmarks/Dss/Vow/Trusted.lean | 2 +- Benchmarks/ERC721/Bytecode.lean | 2 +- Benchmarks/UniswapV3Pool/Trusted.lean | 2 +- Examples/Ballot/Bytecode.lean | 2 +- Examples/BlindAuction/Bytecode.lean | 2 +- Examples/Caller/Bytecode.lean | 2 +- Examples/CtorTruth/Bytecode.lean | 2 +- Examples/ERC20/Bytecode.lean | 2 +- .../AccessControl/Trusted.lean | 2 +- .../OpenZeppelinBench/ERC6909/Trusted.lean | 2 +- .../Ownable2Step/Trusted.lean | 2 +- .../OpenZeppelinBench/Pausable/Trusted.lean | 2 +- Examples/Pow/Bytecode.lean | 2 +- Examples/Reuse/Bytecode.lean | 2 +- Examples/SimpleAuction/Bytecode.lean | 2 +- Examples/StringStoreLite/Bytecode.lean | 2 +- Examples/Truth/Bytecode.lean | 2 +- Examples/UniswapV2Pair/Bytecode.lean | 2 +- Examples/VyperERC20/Bytecode.lean | 2 +- Reasoning/Dispatch.lean | 2 +- Reasoning/Theory.lean | 20 +++++++++++++++++ Solm/Dispatch.lean | 22 ------------------- Solm/Equiv.lean | 2 +- Solm/Notation.lean | 2 +- 28 files changed, 46 insertions(+), 48 deletions(-) delete mode 100644 Solm/Dispatch.lean diff --git a/Benchmarks/CompoundIII/CometRewards/Trusted.lean b/Benchmarks/CompoundIII/CometRewards/Trusted.lean index 2ea8f0a0..03198c02 100644 --- a/Benchmarks/CompoundIII/CometRewards/Trusted.lean +++ b/Benchmarks/CompoundIII/CometRewards/Trusted.lean @@ -1,5 +1,5 @@ import Benchmarks.CompoundIII.CometRewards.Bytecode -import Solm.Dispatch +import Solm.Semantics open Solm Ethereum Ethereum.EVM diff --git a/Benchmarks/Dss/Cat/Trusted.lean b/Benchmarks/Dss/Cat/Trusted.lean index 9ee2b7e4..9b8d483d 100644 --- a/Benchmarks/Dss/Cat/Trusted.lean +++ b/Benchmarks/Dss/Cat/Trusted.lean @@ -1,5 +1,5 @@ import Benchmarks.Dss.Cat.Bytecode -import Solm.Dispatch +import Solm.Semantics /-! # MakerDAO/Sky DSS Cat trusted bytecode facts diff --git a/Benchmarks/Dss/Clipper/Trusted.lean b/Benchmarks/Dss/Clipper/Trusted.lean index 384d1e49..36acb944 100644 --- a/Benchmarks/Dss/Clipper/Trusted.lean +++ b/Benchmarks/Dss/Clipper/Trusted.lean @@ -1,5 +1,5 @@ import Benchmarks.Dss.Clipper.Common -import Solm.Dispatch +import Solm.Semantics /-! # MakerDAO/Sky DSS Clipper trusted selector facts diff --git a/Benchmarks/Dss/Cure/Trusted.lean b/Benchmarks/Dss/Cure/Trusted.lean index 7588bcd1..a55fc833 100644 --- a/Benchmarks/Dss/Cure/Trusted.lean +++ b/Benchmarks/Dss/Cure/Trusted.lean @@ -1,5 +1,5 @@ import Benchmarks.Dss.Cure.Bytecode -import Solm.Dispatch +import Solm.Semantics import Reasoning.Solc /-! diff --git a/Benchmarks/Dss/Vow/Trusted.lean b/Benchmarks/Dss/Vow/Trusted.lean index eb034837..1436af61 100644 --- a/Benchmarks/Dss/Vow/Trusted.lean +++ b/Benchmarks/Dss/Vow/Trusted.lean @@ -1,5 +1,5 @@ import Benchmarks.Dss.Vow.Bytecode -import Solm.Dispatch +import Solm.Semantics /-! # MakerDAO/Sky DSS Vow trusted bytecode facts diff --git a/Benchmarks/ERC721/Bytecode.lean b/Benchmarks/ERC721/Bytecode.lean index 04973955..7e831100 100644 --- a/Benchmarks/ERC721/Bytecode.lean +++ b/Benchmarks/ERC721/Bytecode.lean @@ -1,5 +1,5 @@ import Benchmarks.ERC721.Spec -import Solm.Dispatch +import Solm.Semantics import Reasoning.JumpDest open Solm Ethereum Ethereum.EVM diff --git a/Benchmarks/UniswapV3Pool/Trusted.lean b/Benchmarks/UniswapV3Pool/Trusted.lean index f1c3a250..fc266bce 100644 --- a/Benchmarks/UniswapV3Pool/Trusted.lean +++ b/Benchmarks/UniswapV3Pool/Trusted.lean @@ -1,5 +1,5 @@ import Benchmarks.UniswapV3Pool.Bytecode -import Solm.Dispatch +import Solm.Semantics /-! # UniswapV3Pool trusted selector facts diff --git a/Examples/Ballot/Bytecode.lean b/Examples/Ballot/Bytecode.lean index cf6d5034..637ec27b 100644 --- a/Examples/Ballot/Bytecode.lean +++ b/Examples/Ballot/Bytecode.lean @@ -1,5 +1,5 @@ import Examples.Ballot.Spec -import Solm.Dispatch +import Solm.Semantics import Reasoning.JumpDest open Solm Ethereum Ethereum.EVM diff --git a/Examples/BlindAuction/Bytecode.lean b/Examples/BlindAuction/Bytecode.lean index e930782a..f69c8274 100644 --- a/Examples/BlindAuction/Bytecode.lean +++ b/Examples/BlindAuction/Bytecode.lean @@ -1,5 +1,5 @@ import Examples.BlindAuction.Spec -import Solm.Dispatch +import Solm.Semantics import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Examples/Caller/Bytecode.lean b/Examples/Caller/Bytecode.lean index 81139d68..664a8299 100644 --- a/Examples/Caller/Bytecode.lean +++ b/Examples/Caller/Bytecode.lean @@ -1,5 +1,5 @@ import Examples.Caller.Spec -import Solm.Dispatch +import Solm.Semantics import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Examples/CtorTruth/Bytecode.lean b/Examples/CtorTruth/Bytecode.lean index 3f4daf63..43b2d7b7 100644 --- a/Examples/CtorTruth/Bytecode.lean +++ b/Examples/CtorTruth/Bytecode.lean @@ -1,5 +1,5 @@ import Examples.CtorTruth.Spec -import Solm.Dispatch +import Solm.Semantics import Ethereum.Semantics import Reasoning.Initcode import Reasoning.JumpDest diff --git a/Examples/ERC20/Bytecode.lean b/Examples/ERC20/Bytecode.lean index ee71bab1..f2fd58d0 100644 --- a/Examples/ERC20/Bytecode.lean +++ b/Examples/ERC20/Bytecode.lean @@ -1,5 +1,5 @@ import Examples.ERC20.Spec -import Solm.Dispatch +import Solm.Semantics import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Examples/OpenZeppelinBench/AccessControl/Trusted.lean b/Examples/OpenZeppelinBench/AccessControl/Trusted.lean index f56108b9..fb031682 100644 --- a/Examples/OpenZeppelinBench/AccessControl/Trusted.lean +++ b/Examples/OpenZeppelinBench/AccessControl/Trusted.lean @@ -1,5 +1,5 @@ import Examples.OpenZeppelinBench.AccessControl.Bytecode -import Solm.Dispatch +import Solm.Semantics open Solm Ethereum Ethereum.EVM diff --git a/Examples/OpenZeppelinBench/ERC6909/Trusted.lean b/Examples/OpenZeppelinBench/ERC6909/Trusted.lean index fb35f51b..a71f7def 100644 --- a/Examples/OpenZeppelinBench/ERC6909/Trusted.lean +++ b/Examples/OpenZeppelinBench/ERC6909/Trusted.lean @@ -1,5 +1,5 @@ import Examples.OpenZeppelinBench.ERC6909.Bytecode -import Solm.Dispatch +import Solm.Semantics /-! # ERC6909 benchmark trusted selector facts diff --git a/Examples/OpenZeppelinBench/Ownable2Step/Trusted.lean b/Examples/OpenZeppelinBench/Ownable2Step/Trusted.lean index bbcf0113..51d34859 100644 --- a/Examples/OpenZeppelinBench/Ownable2Step/Trusted.lean +++ b/Examples/OpenZeppelinBench/Ownable2Step/Trusted.lean @@ -1,5 +1,5 @@ import Examples.OpenZeppelinBench.Ownable2Step.Bytecode -import Solm.Dispatch +import Solm.Semantics open Solm Ethereum Ethereum.EVM diff --git a/Examples/OpenZeppelinBench/Pausable/Trusted.lean b/Examples/OpenZeppelinBench/Pausable/Trusted.lean index 10b3dbce..760c9d69 100644 --- a/Examples/OpenZeppelinBench/Pausable/Trusted.lean +++ b/Examples/OpenZeppelinBench/Pausable/Trusted.lean @@ -1,5 +1,5 @@ import Examples.OpenZeppelinBench.Pausable.Bytecode -import Solm.Dispatch +import Solm.Semantics open Solm Ethereum Ethereum.EVM diff --git a/Examples/Pow/Bytecode.lean b/Examples/Pow/Bytecode.lean index b448352a..f68ef318 100644 --- a/Examples/Pow/Bytecode.lean +++ b/Examples/Pow/Bytecode.lean @@ -1,5 +1,5 @@ import Examples.Pow.Spec -import Solm.Dispatch +import Solm.Semantics import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Examples/Reuse/Bytecode.lean b/Examples/Reuse/Bytecode.lean index 3e88eaa4..91bc0a02 100644 --- a/Examples/Reuse/Bytecode.lean +++ b/Examples/Reuse/Bytecode.lean @@ -1,5 +1,5 @@ import Examples.Reuse.Spec -import Solm.Dispatch +import Solm.Semantics import Reasoning.JumpDest open Solm Ethereum Ethereum.EVM diff --git a/Examples/SimpleAuction/Bytecode.lean b/Examples/SimpleAuction/Bytecode.lean index 5e0d7e12..1d57b454 100644 --- a/Examples/SimpleAuction/Bytecode.lean +++ b/Examples/SimpleAuction/Bytecode.lean @@ -1,5 +1,5 @@ import Examples.SimpleAuction.Spec -import Solm.Dispatch +import Solm.Semantics import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Examples/StringStoreLite/Bytecode.lean b/Examples/StringStoreLite/Bytecode.lean index f70a17ba..ae628cc8 100644 --- a/Examples/StringStoreLite/Bytecode.lean +++ b/Examples/StringStoreLite/Bytecode.lean @@ -1,5 +1,5 @@ import Examples.StringStoreLite.Spec -import Solm.Dispatch +import Solm.Semantics import Ethereum.Semantics import Reasoning.Initcode import Reasoning.JumpDest diff --git a/Examples/Truth/Bytecode.lean b/Examples/Truth/Bytecode.lean index a0d83ae7..a0095a82 100644 --- a/Examples/Truth/Bytecode.lean +++ b/Examples/Truth/Bytecode.lean @@ -1,5 +1,5 @@ import Examples.Truth.Spec -import Solm.Dispatch +import Solm.Semantics import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Examples/UniswapV2Pair/Bytecode.lean b/Examples/UniswapV2Pair/Bytecode.lean index 8d45a0bb..a23ae656 100644 --- a/Examples/UniswapV2Pair/Bytecode.lean +++ b/Examples/UniswapV2Pair/Bytecode.lean @@ -1,5 +1,5 @@ import Examples.UniswapV2Pair.Spec -import Solm.Dispatch +import Solm.Semantics import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Examples/VyperERC20/Bytecode.lean b/Examples/VyperERC20/Bytecode.lean index 265ef302..8173b814 100644 --- a/Examples/VyperERC20/Bytecode.lean +++ b/Examples/VyperERC20/Bytecode.lean @@ -1,5 +1,5 @@ import Examples.VyperERC20.Spec -import Solm.Dispatch +import Solm.Semantics import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Reasoning/Dispatch.lean b/Reasoning/Dispatch.lean index 786bf724..dcceca40 100644 --- a/Reasoning/Dispatch.lean +++ b/Reasoning/Dispatch.lean @@ -1,4 +1,4 @@ -import Solm.Dispatch +import Solm.Semantics import Reasoning.Reach import Reasoning.Storage diff --git a/Reasoning/Theory.lean b/Reasoning/Theory.lean index a55b0948..bff36907 100644 --- a/Reasoning/Theory.lean +++ b/Reasoning/Theory.lean @@ -205,6 +205,26 @@ theorem reEquiv_outOfGas {cfg contract cA gh bl σ_evm σ_solm σ₀ g A I} runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g A I := .outOfGas h +/-- When a contract has no `receive`/`fallback`, a successful `dispatchMsg` is a successful + selector dispatch: the receive and fallback arms of `dispatchMsg` are `none`. Shared by the + `decodingFailed`/`execution` coverage helpers below. -/ +theorem selectorDispatchMsg_eq_some_of_dispatchMsg_eq_some + {contract : ContractDecl} {calldata : ByteArray} {transition : TransitionDecl} + (hreceive : contract.receive = none) + (hfallback : contract.fallback = none) + (h : dispatchMsg contract calldata = some transition) : + selectorDispatchMsg contract calldata = some transition := by + unfold dispatchMsg at h + cases hsel : selectorDispatchMsg contract calldata with + | none => + have hreceiveDispatch : receiveDispatchMsg contract calldata = none := by + simp [receiveDispatchMsg, hreceive] + rw [hsel, hreceiveDispatch, hfallback] at h + simp at h + | some selected => + rw [hsel] at h + simpa using h + /-- Solm fails to dispatch and `Ξ` reverts ⇒ the `noDispatch` case. The Solm-side maps are unconstrained — this path never runs `solmExec`. -/ theorem reEquiv_noDispatch {cfg contract cA gh bl σ_evm σ_solm σ₀ g A I} {g' o} diff --git a/Solm/Dispatch.lean b/Solm/Dispatch.lean deleted file mode 100644 index 052a9329..00000000 --- a/Solm/Dispatch.lean +++ /dev/null @@ -1,22 +0,0 @@ -import Solm.Semantics - -namespace Solm - -open ABI - -theorem selectorDispatchMsg_eq_some_of_dispatchMsg_eq_some - {contract : ContractDecl} {calldata : ByteArray} {transition : TransitionDecl} - (hreceive : contract.receive = none) - (hfallback : contract.fallback = none) - (h : dispatchMsg contract calldata = some transition) : - selectorDispatchMsg contract calldata = some transition := by - unfold dispatchMsg at h - cases hsel : selectorDispatchMsg contract calldata with - | none => - have hreceiveDispatch : receiveDispatchMsg contract calldata = none := by - simp [receiveDispatchMsg, hreceive] - rw [hsel, hreceiveDispatch, hfallback] at h - simp at h - | some selected => - rw [hsel] at h - simpa using h diff --git a/Solm/Equiv.lean b/Solm/Equiv.lean index 19a27487..deae48e4 100644 --- a/Solm/Equiv.lean +++ b/Solm/Equiv.lean @@ -1,6 +1,6 @@ import ABI.Encode import ABI.Decode -import Solm.Dispatch +import Solm.Semantics open Solm open ABI diff --git a/Solm/Notation.lean b/Solm/Notation.lean index 8a606a76..6244cb7c 100644 --- a/Solm/Notation.lean +++ b/Solm/Notation.lean @@ -4,7 +4,7 @@ import Solm.Syntax # Solm — a macro-generated surface syntax A lightweight, Lean-embedded DSL that desugars to the `Solm` AST (`Expr`, `Stmt`, -`StorageRef`, the `*Decl` structures). The goal is to let a spec author write something that +`StorageRef`, and top-level`*Decl` structures). The goal is to let a spec author write something that *reads* like the Solidity it models, instead of hand-constructing constructor trees. Everything here is pure `syntax` + `macro_rules` sugar: each surface form expands to the exact From ee95df40ca8b0a3ea0917bb16d2751fc5884deeb Mon Sep 17 00:00:00 2001 From: zoep Date: Sat, 25 Jul 2026 16:06:07 +0300 Subject: [PATCH 06/38] Solm: nits in Storage.lean --- Solm/Storage.lean | 41 ++++++++++++++--------------------------- Solm/Value.lean | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/Solm/Storage.lean b/Solm/Storage.lean index 9d4fdd11..25795e19 100644 --- a/Solm/Storage.lean +++ b/Solm/Storage.lean @@ -2,7 +2,7 @@ import EVM.Types import EVM.Lemmas import Solm.Value --- TODO: I'd like to get rid of these maybe +-- TODO: get rid of these maybe import Ethereum.Semantics import Ethereum.UInt256 import Ethereum.Wheels @@ -13,10 +13,18 @@ open ABI namespace EVM +/- + - Storage access definitions and helpers. + - + - This file defines **raw storage slot access functions**, + - **packed load/store** of values at a given storage location, + - and a **storage layout** abstraction for higher-level storage access. + -/ + -- The two following functions implement storage access -- However their semantics are not equivalent to actual evm semantics, -- as they do not affect substate. --- This is because the number of storage reads of a slot in the bytecode +-- This is because the number of storage reads of a slot in the bytecode -- may not equal the number of times said slot appears in expressions -- This fact may also make equivalence proofs a bit trickier @@ -28,7 +36,7 @@ def storageStore (self : EVM.State) (a : EVM.Address) (key value : EVM.Word) : E self.lookupAccount a |>.option self λ acc ↦ self.setAccount a (Ethereum.Account.updateStorage acc key value) -end EVM +end EVM @@ -77,7 +85,7 @@ def storageLocLoad (self : EVM.State) (loc : StorageLoc) : Value := apply Or.inl (by apply Nat.le_of_lt_succ; simp) have hresSize : Ethereum.fromBytes' bytes < Ethereum.UInt256.size := by apply lt_of_lt_of_le (b := 2^(8 * bytes.length)) - · exact EVM.fromBytes'_le + · exact EVM.fromBytes'_le · simp [Ethereum.UInt256.size] apply le_trans (b := 2^(8 * 32)) · apply Nat.pow_le_pow_right @@ -125,7 +133,7 @@ def storageLocStore (self : EVM.State) (loc : StorageLoc) (value : Value) : Opti have hprevEndLen : previousEnd.length = 32 - endByte := by simp [previousEnd]; rw [hprevStorageRefSize] rw [hprevStartLen, hprevEndLen] - rw [Nat.min_eq_left] + rw [Nat.min_eq_left] · simp [startByte, endByte]; rw [← Nat.add_assoc, ← Nat.add_sub_assoc] simp @@ -134,7 +142,7 @@ def storageLocStore (self : EVM.State) (loc : StorageLoc) (value : Value) : Opti · rw [hvalueSize]; omega have hresSize : Ethereum.fromBytes' resList < Ethereum.UInt256.size := by apply lt_of_lt_of_le (b := 2^(8 * resList.length)) - · exact EVM.fromBytes'_le + · exact EVM.fromBytes'_le · simp [Ethereum.UInt256.size] apply le_trans (b := 2^(8 * 32)) · apply Nat.pow_le_pow_right @@ -169,27 +177,6 @@ structure StorageLayout where -- e.g. access within array bounds returns `.some v` --- TODO: move -def keyValueToWord : KeyValue -> EVM.Word - | .int i => EVM.wordOfInt i - | .bool b => b.toUInt256 - | .address a => - { val := (@Fin.castLE Ethereum.AccountAddress.size - Ethereum.UInt256.size - (by unfold Ethereum.AccountAddress.size Ethereum.UInt256.size; simp) a : Fin Ethereum.UInt256.size) } - | .fixedBytes n bs => - -- `bytesN` keys are LEFT-aligned in the hashed word: `value * 2^(8·(31-n))` (solc 0.6.12 & - -- 0.8.35 mask the key to its high bytes before `keccak256`). `bytes32` (`n=31`) is `×1`. - if bs.length = n.val + 1 then - EVM.Word.ofNat (Ethereum.fromBytesBigEndian bs * 2 ^ (8 * (31 - n.val))) - else - -- Unreachable on the eval path (`valueToKey?` rejects length-mismatched keys); total fallback. - ⟨0⟩ -#guard keyValueToWord (.fixedBytes ⟨3, by decide⟩ [0xDE, 0xAD, 0xBE, 0xEF]) - = EVM.Word.ofNat (0xDEADBEEF * 2 ^ 224) -#guard keyValueToWord (.fixedBytes ⟨31, by decide⟩ (List.replicate 31 0 ++ [0x2A])) - = EVM.Word.ofNat 0x2A - def intTypeSize (t : IntType) : Fin 33 := match t with | .uint ⟨bw,hbw⟩ => ⟨bw/8, by apply Nat.lt_succ_of_le; apply Nat.div_le_of_le_mul; simp; omega⟩ diff --git a/Solm/Value.lean b/Solm/Value.lean index 5566a4c7..2a2c8d04 100644 --- a/Solm/Value.lean +++ b/Solm/Value.lean @@ -20,6 +20,26 @@ def valueToWord : Value -> Option EVM.Word none | .storageRef _ _ => .none +def keyValueToWord : KeyValue -> EVM.Word + | .int i => EVM.wordOfInt i + | .bool b => b.toUInt256 + | .address a => + { val := (@Fin.castLE Ethereum.AccountAddress.size + Ethereum.UInt256.size + (by unfold Ethereum.AccountAddress.size Ethereum.UInt256.size; simp) a : Fin Ethereum.UInt256.size) } + | .fixedBytes n bs => + -- `bytesN` keys are LEFT-aligned in the hashed word: `value * 2^(8·(31-n))` (solc 0.6.12 & + -- 0.8.35 mask the key to its high bytes before `keccak256`). `bytes32` (`n=31`) is `×1`. + if bs.length = n.val + 1 then + EVM.Word.ofNat (Ethereum.fromBytesBigEndian bs * 2 ^ (8 * (31 - n.val))) + else + -- Unreachable on the eval path (`valueToKey?` rejects length-mismatched keys); total fallback. + ⟨0⟩ +#guard keyValueToWord (.fixedBytes ⟨3, by decide⟩ [0xDE, 0xAD, 0xBE, 0xEF]) + = EVM.Word.ofNat (0xDEADBEEF * 2 ^ 224) +#guard keyValueToWord (.fixedBytes ⟨31, by decide⟩ (List.replicate 31 0 ++ [0x2A])) + = EVM.Word.ofNat 0x2A + def wordToElem (t : ABI.ElemType) (w : EVM.Word) : Value := match t with | .int (.uint _) => .int (w.toNat) From 341828060562bae63c2487cabb0adf095daa042e Mon Sep 17 00:00:00 2001 From: zoep Date: Sat, 25 Jul 2026 17:07:35 +0300 Subject: [PATCH 07/38] Solm: wip cleanup --- Solm/Semantics.lean | 71 ++------------------------------------------- 1 file changed, 2 insertions(+), 69 deletions(-) diff --git a/Solm/Semantics.lean b/Solm/Semantics.lean index afedb1c9..e816249e 100644 --- a/Solm/Semantics.lean +++ b/Solm/Semantics.lean @@ -6,6 +6,8 @@ import ABI.Decode namespace Solm +/- Solm Semantics -/ + open ABI def transitionSignature (transition : TransitionDecl) : Signature := @@ -75,20 +77,6 @@ structure Config where deployment of the contract's constructor -/ selfDeployment : EVM.Bytes → List Value → Option EVM.Bytes -structure ContractInstance where - contract : Ident - contractCode : ContractDecl - storage : Store - balance : Int - -abbrev World := Std.HashMap EVM.Address ContractInstance - -structure CallEnv where - caller : EVM.Address - origin : EVM.Address - callvalue : Int - this : EVM.Address - structure Frame where contract : ContractDecl locals : Store @@ -110,11 +98,6 @@ structure CallableDecl where deriving Repr, Inhabited -def lookupStorageDecl? (decls : List StorageDecl) (name : Ident) : Option StorageDecl := - match decls with - | [] => none - | d :: ds => if d.name = name then some d else lookupStorageDecl? ds name - def envValue (evm : EVM.State) : EnvVar -> Value | .caller => .address evm.executionEnv.source | .origin => .address evm.executionEnv.sender @@ -137,27 +120,6 @@ def envValue (evm : EVM.State) : EnvVar -> Value .fixedBytes ⟨3, by decide⟩ (b ++ List.replicate (4 - b.length) 0) | .msgData => .bytes evm.executionEnv.calldata -def abiValueToWord? (ty : ABIType) (value : Value) : Option EVM.Word := - match ty, value with - | .elem .bool, .bool b => some (b.toUInt256) - | .elem .address, .address a => some (EVM.word a) - | .elem (.int (.uint _)), .int i => - if i < 0 then none else some (EVM.wordOfInt i) - | .elem (.int (.sint _)), .int i => some (EVM.wordOfInt i) - | _, _ => none - -def slotValueToWord? (ty : StorageType) (value : Value) : Option EVM.Word := - match ty with - | .elem primTy => abiValueToWord? (.elem primTy) value - | .contract _ => - match value with - | .address a => some (EVM.word a) - | _ => none - | _ => none - -def slotPushStep (slot : StorageRef) (step : StorageRefStep) : StorageRef := - { slot with steps := slot.steps ++ [step] } - def valueToKey? (v : Value) : Option KeyValue := match v with | .int i => pure $ .int i @@ -182,21 +144,6 @@ def updateAssoc [DecidableEq α] (entries : List (α × β)) (key : α) (value : else (k, v) :: updateAssoc rest key value -def lookupValueAssoc (entries : List (Value × β)) (key : Value) : Option β := - match entries with - | [] => none - | (k, v) :: rest => if k = key then some v else lookupValueAssoc rest key - -def updateValueAssoc (entries : List (Value × β)) (key : Value) (value : β) : - List (Value × β) := - match entries with - | [] => [(key, value)] - | (k, v) :: rest => - if k == key then - (key, value) :: rest - else - (k, v) :: updateValueAssoc rest key value - def updateNth? (xs : List α) (index : Nat) (value : α) : Option (List α) := match xs, index with | [], _ => none @@ -678,20 +625,6 @@ mutual all_goals decreasing_tactic end -lemma stepSize_lt_stepsSize : ∀ (slot : StorageRef) step, - step ∈ slot.steps → - slotStepEvalSize step < slotStepsEvalSize slot.steps := by - intros slot step - induction slot.steps with - | nil => intro hin; cases hin - | cons head tail tail_ih => - intro hin - cases hin - · simp [slotStepsEvalSize]; omega - · rename_i hin - simp [slotStepsEvalSize] - apply lt_trans (b:= slotStepsEvalSize tail) (tail_ih hin); omega - /-- The declared `StorageType` reached by following one evaled step from a value of type `t`. -/ def storageTypeStep? : StorageType -> EvaledStorageRefStep -> Option StorageType | .struct _ fields, .field name => (fields.find? (fun f => f.1 == name)).map (·.2) From 10246b48b5cdf9c92e153edc0bba3903e35a58d5 Mon Sep 17 00:00:00 2001 From: zoep Date: Sat, 25 Jul 2026 18:34:18 +0300 Subject: [PATCH 08/38] Solm: wip semantics cleanup --- Reasoning/ExternalCall.lean | 6 +- Solm/Semantics.lean | 2258 +------------------------------- Solm/Semantics/Calls.lean | 195 +++ Solm/Semantics/Dispatch.lean | 61 + Solm/Semantics/Eval.lean | 525 ++++++++ Solm/Semantics/Exec.lean | 680 ++++++++++ Solm/Semantics/StorageOps.lean | 340 +++++ Solm/Semantics/Types.lean | 31 + Solm/Semantics/ValueOps.lean | 472 +++++++ 9 files changed, 2314 insertions(+), 2254 deletions(-) create mode 100644 Solm/Semantics/Calls.lean create mode 100644 Solm/Semantics/Dispatch.lean create mode 100644 Solm/Semantics/Eval.lean create mode 100644 Solm/Semantics/Exec.lean create mode 100644 Solm/Semantics/StorageOps.lean create mode 100644 Solm/Semantics/Types.lean create mode 100644 Solm/Semantics/ValueOps.lean diff --git a/Reasoning/ExternalCall.lean b/Reasoning/ExternalCall.lean index 2455cbd8..28772e75 100644 --- a/Reasoning/ExternalCall.lean +++ b/Reasoning/ExternalCall.lean @@ -9,7 +9,7 @@ import Ethereum.Theory.StorageExtensionality The Solm↔EVM boundary for a contract's **external call**, the peer of `Reasoning/Dispatch.lean` (which couples the transaction entry / dispatcher). An EVM `CALL` (exposed by `RD.call` as a -`Θ`-link) and the Solm `externalCall` (the `externalCallViaEVM` relation) invoke the *identical* `Θ` +`Θ`-link) and the Solm `externalCall` (the `typedCallViaEVM` relation) invoke the *identical* `Θ` with the same arguments, so the opaque result `(z, σ', o)` coincides on both sides **by construction** — no assumption about the callee's code. @@ -58,7 +58,7 @@ private theorem accountMapEquiv_of_accountMapExtensionalEq {σ τ : AccountMap} /-- **Coincidence (call made).** Given the EVM-side `Θ`-link produced by `RD.call` (with witnesses `A_in`, `callGas`) and the trace couplings — the Solm target `tgt` is the cleaned stack address (`htgt`), and the ABI encoding of `name args` is exactly the calldata the bytecode placed in - memory (`hcd`) — the Solm `externalCallViaEVM` holds for the *same* opaque `(z, σ', o)`. + memory (`hcd`) — the Solm `typedCallViaEVM` holds for the *same* opaque `(z, σ', o)`. Instantiate the Solm existentials with the EVM witnesses; `Θ`'s determinism does the rest. Generic over the config / callee name / arguments (value `0`). -/ theorem callCoincides {cfg : Config} {evm : EVM.State} {name : Ident} {args : List Value} @@ -744,7 +744,7 @@ theorem delegateCallViaEVM_initState_EVMStateEquiv exact ⟨σ'_solm, A'_solm, hcall_solm, hEnv, rfl, hσ'⟩ /-- **Coincidence (call not made).** At the call-depth limit (`evm.depth = 1024`) the EVM `CALL` - returns `0` *without* invoking `Θ`; the Solm `externalCallViaEVM` takes the matching + returns `0` *without* invoking `Θ`; the Solm `typedCallViaEVM` takes the matching `callNotMade` branch — `(false, evm[substate], ∅)` — independent of value/balance. Generic over config / callee name / arguments (value `0`). -/ theorem callNotMade_depthLimit {cfg : Config} {evm : EVM.State} {tgt : EVM.Address} diff --git a/Solm/Semantics.lean b/Solm/Semantics.lean index e816249e..1df4b864 100644 --- a/Solm/Semantics.lean +++ b/Solm/Semantics.lean @@ -1,2252 +1,8 @@ -import Solm.Storage -import Solm.Value -import ABI.Signature -import ABI.Encode -import ABI.Decode - -namespace Solm - /- Solm Semantics -/ - -open ABI - -def transitionSignature (transition : TransitionDecl) : Signature := - ⟨transition.name, transition.params.map Param.ty⟩ - -def transitionSigStr (transition : TransitionDecl) : String := - printSignature $ transitionSignature transition - -def selectorDispatchMsg (contract : ContractDecl) (calldata : ByteArray) - : Option TransitionDecl := - let sigs := contract.transitions.map (λ t ↦ (t, transitionSigStr t)) - let sigHashes := sigs.map (Prod.map id (ffi.KEC ∘ String.toByteArray)) - let selectors := sigHashes.map (Prod.map id (λ b ↦ b.extract 0 4)) - let currentSelector := calldata.extract 0 4 - match selectors.find? (λ (_,s) ↦ s == currentSelector) with - | some (t,_) => t - | none => none - -def receiveDispatchMsg (contract : ContractDecl) (calldata : ByteArray) - : Option TransitionDecl := - if calldata.size = 0 then contract.receive else none - -def dispatchMsg (contract : ContractDecl) (calldata : ByteArray) - : Option TransitionDecl := - match selectorDispatchMsg contract calldata with - | some transition => some transition - | none => - match receiveDispatchMsg contract calldata with - | some transition => some transition - | none => contract.fallback - -inductive ReturnConvention where - | abi : List ABIType → ReturnConvention - | rawBytes : ReturnConvention - deriving DecidableEq, Repr, Inhabited - -def fallbackCallargs (calldata : ByteArray) : List Param → Option Store - | [] => some ∅ - | [param] => - match param.ty with - | .bytes => some ((∅ : Store).insert param.name (.bytes calldata)) - | _ => none - | _ => none - -def fallbackReturnConvention (transition : TransitionDecl) : Option ReturnConvention := - match transition.params, transition.returnType with - | [], [] => some (.abi []) - | [param], [.bytes] => - match param.ty with - | .bytes => some .rawBytes - | _ => none - | _, _ => none - -structure ExternalCallABI where - encode? : Ident -> List Value -> Option EVM.Bytes - decode? : Ident -> EVM.Bytes-> Option (List Value) - -structure Config where - storage : StorageLayout - externalABI : ExternalCallABI - abiDecodeMode : ABI.DecodeMode := ABI.DecodeMode.modern - /- Initialisation code (creation bytecode ++ ABI-encoded constructor args) for a - `new` of the named contract. -/ - creationCode : Ident -> List Value -> Option EVM.Bytes := fun _ _ => none - - /- Scheme for initialisation code (creation bytecode ++ ABI-encoded constructor args) for - deployment of the contract's constructor -/ - selfDeployment : EVM.Bytes → List Value → Option EVM.Bytes - -structure Frame where - contract : ContractDecl - locals : Store - -inductive ExecResult where - /- The returned-value component is `Option (List Value)`: `none` means the body fell through - without executing `return`; `some vs` is an explicit `return` of the listed values (`some []` - is an explicit void return). -/ - | returned : Frame -> EVM.State -> Option (List Value) -> ExecResult - | ok : Frame -> EVM.State -> ExecResult - | break : Frame -> EVM.State -> ExecResult - | continue : Frame -> EVM.State -> ExecResult - | reverted : ExecResult - -structure CallableDecl where - params : List Param - returnType : List ABIType := [] - body : Body - deriving Repr, Inhabited - - -def envValue (evm : EVM.State) : EnvVar -> Value - | .caller => .address evm.executionEnv.source - | .origin => .address evm.executionEnv.sender - | .callvalue => .int (Int.ofNat evm.executionEnv.weiValue.val) - | .this => .address evm.executionEnv.codeOwner - | .timestamp => .int (Int.ofNat (Ethereum.UInt256.ofNat evm.executionEnv.header.timestamp).toNat) - | .chainid => .int (Int.ofNat Ethereum.chainId) - | .selfbalance => - .int (Int.ofNat ((evm.lookupAccount evm.executionEnv.codeOwner).option - (EVM.Word.ofNat 0) (·.balance)).toNat) - | .gasprice => .int (Int.ofNat (EVM.Word.ofNat evm.executionEnv.gasPrice).toNat) - -- Each mirrors the evmlean opcode handler (Semantics.lean:485-531) / StateOps.lean. - | .number => .int (Int.ofNat (EVM.Word.ofNat evm.executionEnv.header.number).toNat) -- NUMBER - | .coinbase => .address evm.executionEnv.header.beneficiary -- COINBASE - | .gaslimit => .int (Int.ofNat (EVM.Word.ofNat evm.executionEnv.header.gasLimit).toNat) -- GASLIMIT - | .prevrandao => .int (Int.ofNat evm.executionEnv.header.prevRandao.toNat) -- PREVRANDAO - | .basefee => .int (Int.ofNat (EVM.Word.ofNat evm.executionEnv.header.baseFeePerGas).toNat) -- BASEFEE - | .msgSig => - let b := evm.executionEnv.calldata.toList.take 4 - .fixedBytes ⟨3, by decide⟩ (b ++ List.replicate (4 - b.length) 0) - | .msgData => .bytes evm.executionEnv.calldata - -def valueToKey? (v : Value) : Option KeyValue := - match v with - | .int i => pure $ .int i - | .bool b => pure $ .bool b - | .address a => pure $ .address a - -- Reject a length-mismatched `bytesN` key loudly (avoid `keyValueToWord`'s silent slot-`0` fallback). - | .fixedBytes n bs => if bs.length = n.val + 1 then pure (.fixedBytes n bs) else .none - | _ => .none - -def lookupAssoc [DecidableEq α] (entries : List (α × β)) (key : α) : Option β := - match entries with - | [] => none - | (k, v) :: rest => if k = key then some v else lookupAssoc rest key - -def updateAssoc [DecidableEq α] (entries : List (α × β)) (key : α) (value : β) : - List (α × β) := - match entries with - | [] => [(key, value)] - | (k, v) :: rest => - if k = key then - (key, value) :: rest - else - (k, v) :: updateAssoc rest key value - -def updateNth? (xs : List α) (index : Nat) (value : α) : Option (List α) := - match xs, index with - | [], _ => none - | _ :: rest, 0 => some (value :: rest) - | x :: rest, i + 1 => do - let rest' <- updateNth? rest i value - pure (x :: rest') - -def lookupNth? (xs : List α) (index : Nat) : Option α := - match xs, index with - | [], _ => none - | x :: _, 0 => some x - | _ :: rest, i + 1 => lookupNth? rest i - -def intToNat? (n : Int) : Option Nat := - if n < 0 then none else some n.toNat - -def lookupField? (v : Value) (name : Ident) : Option Value := - match v with - | .struct _ fields => lookupAssoc fields name - | _ => none - -def updateField? (v : Value) (name : Ident) (value : Value) : Option Value := - match v with - | .struct tag fields => - match lookupAssoc fields name with - | some _ => some (.struct tag (updateAssoc fields name value)) - | none => none - | _ => none - -def lookupIndex? (container key : Value) : Option Value := - match container with - | .array elems => - match key with - | .int i => do - let idx <- intToNat? i - lookupNth? elems idx - | _ => none - | .fixedBytes n bytes => - match key with - | .int i => do - if bytes.length = n.val + 1 then - let idx <- intToNat? i - let b <- lookupNth? bytes idx - pure (.fixedBytes ⟨0, by decide⟩ [b]) - else - none - | _ => none - | .bytes bytes => - match key with - | .int i => do - let idx <- intToNat? i - let b <- lookupNth? bytes.toList idx - pure (.fixedBytes ⟨0, by decide⟩ [b]) - | _ => none - | _ => none - -def updateIndex? (container key value : Value) : Option Value := - match container with - | .array elems => - match key with - | .int i => do - let idx <- intToNat? i - let elems' <- updateNth? elems idx value - pure (.array elems') - | _ => none - | _ => none - -def fixedBytesSize (n : Fin 32) : Nat := - n.val + 1 - -def fixedBytesValid (n : Fin 32) (bytes : List UInt8) : Bool := - bytes.length = fixedBytesSize n - -def fixedBytesToNat? (n : Fin 32) (bytes : List UInt8) : Option Nat := - if fixedBytesValid n bytes then some (Ethereum.fromBytesBigEndian bytes) else none - -def castValue? (v : Value) (ty : StorageType) : Option Value := - match ty, v with - | .elem (.bool), .bool _ => some v - | .elem (.address), .address _ => some v - | .elem (.bytes expected), .fixedBytes actual _ => - if expected = actual then some v else none - -- A negative int fails loudly (silent `n.toNat = 0` would be a wrong value); literal-`0` casts are ≥0. - | .elem (.bytes expected), .int n => - if n < 0 then none - else some (.fixedBytes expected ((EVM.Word.ofNat n.toNat).toBytesBE.drop (32 - (expected.val + 1)))) - -- `address(n)`: an integer cast to `address` (e.g. `address(0)`), truncated to the address width. - | .elem (.address), .int n => if n < 0 then none else some (.address (.ofNat n.toNat)) - | .elem (.int (.uint bits)), .address a => - if a.toNat < EVM.twoPow bits.val then - some (.int (Int.ofNat a.toNat)) - else - none - -- `uintN(bytesN)`: solc allows this cast only at equal width (`8·(n+1) = bits`); the bytes are - -- read big-endian via the same `fixedBytesToNat?` the comparison/`bitAnd` cases use. - | .elem (.int (.uint bits)), .fixedBytes n bs => - if 8 * (n.val + 1) = bits.val then - match fixedBytesToNat? n bs with - | some k => some (.int (Int.ofNat k)) - | none => none - else none - | .elem (.int _), .int _ => some v - | .contract _, .address _ => some v - | .struct expected _, .struct actual _ => - if expected = actual then some v else none - | .array _ _, .array _ => some v - | .dynamicArray _, .array _ => some v - | _, _ => none - --- `uint256(bytes32 0x…01) = 1`; a width mismatch (`uint128(bytes32)`) is rejected. -#guard castValue? (.fixedBytes ⟨31, by decide⟩ (List.replicate 31 0 ++ [1])) - (.elem (.int (.uint ⟨256, by decide⟩))) = some (.int 1) -#guard castValue? (.fixedBytes ⟨31, by decide⟩ (List.replicate 32 0)) - (.elem (.int (.uint ⟨128, by decide⟩))) = none - -/-- Solm evaluation errors. Should never happen in well-formed programs -/ -inductive EvalError where - | unboundVariable - | typeError - | storageError - deriving DecidableEq, Repr, Inhabited - -/-- Result of evaluating an Solm expression: - - a value (`ok`) - - a `revert` - - or an error, which indicates an ill-formed program --/ -inductive EvalResult (α : Type) where - | ok : α -> EvalResult α - | revert : EvalResult α - | error : EvalError -> EvalResult α - deriving Repr, DecidableEq - -namespace EvalResult - -@[inline] def bind : EvalResult α -> (α -> EvalResult β) -> EvalResult β - | .ok a, f => f a - | .revert, _ => .revert - | .error e, _ => .error e - -instance : Monad EvalResult where - pure := .ok - bind := bind - -/-- Lift an `Option`, mapping `none` to the model-level `error e`. -/ -@[inline] def ofOption (e : EvalError) : Option α -> EvalResult α - | some a => .ok a - | none => .error e - -/-- Sequence a list of results, short-circuiting on the first `revert`/`error`. -/ -def seqList : List (EvalResult α) -> EvalResult (List α) - | [] => .ok [] - | x :: xs => do - let a <- x - let as <- seqList xs - .ok (a :: as) - -end EvalResult - -def fixedBytesFromNat (n : Fin 32) (value : Nat) : Value := - .fixedBytes n ((EVM.Word.ofNat value).toBytesBE.drop (32 - fixedBytesSize n)) - -def fixedBytesBytewise? (f : UInt8 -> UInt8 -> UInt8) : - List UInt8 -> List UInt8 -> Option (List UInt8) - | [], [] => some [] - | x :: xs, y :: ys => do - let rest <- fixedBytesBytewise? f xs ys - some (f x y :: rest) - | _, _ => none - -def evalByteIndex? (bytes : List UInt8) (i : Int) : EvalResult Value := - if i < 0 then - .revert - else - let idx := i.toNat - if idx < bytes.length then - EvalResult.ofOption .typeError - (Option.map (fun b => Value.fixedBytes ⟨0, by decide⟩ [b]) (lookupNth? bytes idx)) - else - .revert - -def evalFixedBytesIndex? (n : Fin 32) (bytes : List UInt8) (i : Int) : EvalResult Value := - if fixedBytesValid n bytes then evalByteIndex? bytes i else .error .typeError - -def normalizeRawBoolWord? : Value -> EvalResult Value - | .tuple [.unit, .int n] => - if n = 0 then - .ok (.bool false) - else if n = 1 then - .ok (.bool true) - else - .revert - | v => .ok v - -def evalIndex? (container key : Value) : EvalResult Value := - match container, key with - | .array elems, .int i => - if 0 ≤ i ∧ i < elems.length then - match lookupNth? elems i.toNat with - | some v => normalizeRawBoolWord? v - | none => .error .typeError - else - .revert - | .fixedBytes n bytes, .int i => evalFixedBytesIndex? n bytes i - | .bytes bytes, .int i => evalByteIndex? bytes.toList i - | _, _ => .error .typeError - -def evalUnaryOp? (op : UnaryOp) (v : Value) : Option Value := - match op, v with - | .not, .bool b => some (.bool (!b)) - | .neg, .int i => some (.int (-i)) - | .bitNot, .fixedBytes n bytes => - if fixedBytesValid n bytes then some (.fixedBytes n (bytes.map (fun b => ~~~b))) else none - -- `~x` on an int is the word complement, defined only on `[0, 2^256)`. - | .bitNot, .int x => - if 0 ≤ x ∧ x < (EVM.wordModulus : Int) then some (.int (EVM.wordModulus - 1 - x.toNat)) - else none - | _, _ => none - -#guard evalUnaryOp? .bitNot (.int 0) = some (.int (EVM.wordModulus - 1)) -#guard evalUnaryOp? .bitNot (.int (EVM.wordModulus - 1)) = some (.int 0) -#guard evalUnaryOp? .bitNot (.int (-1)) = none - -def evalBinaryOp? (op : BinaryOp) (v₁ v₂ : Value) : EvalResult Value := - match op, v₁, v₂ with - | .add, .int x, .int y => .ok (.int (x + y)) - | .sub, .int x, .int y => .ok (.int (x - y)) - | .mul, .int x, .int y => .ok (.int (x * y)) - -- division/modulo by zero reverts (Solidity Panic 0x12) - | .div, .int x, .int y => if y = 0 then .revert else .ok (.int (x / y)) - | .mod, .int x, .int y => if y = 0 then .revert else .ok (.int (x % y)) - | .eq, .storageRef _ _, _ => .error .typeError - | .eq, _, .storageRef _ _ => .error .typeError - | .ne, .storageRef _ _, _ => .error .typeError - | .ne, _, .storageRef _ _ => .error .typeError - | .eq, x, y => .ok (.bool (x == y)) - | .ne, x, y => .ok (.bool (!(x == y))) - | .lt, .int x, .int y => .ok (.bool (x < y)) - | .le, .int x, .int y => .ok (.bool (x <= y)) - | .gt, .int x, .int y => .ok (.bool (x > y)) - | .ge, .int x, .int y => .ok (.bool (x >= y)) - -- addresses are zero-extended words on the stack, so word-LT ≡ Nat compare of their values. - | .lt, .address a, .address b => .ok (.bool (a.toNat < b.toNat)) - | .le, .address a, .address b => .ok (.bool (a.toNat <= b.toNat)) - | .gt, .address a, .address b => .ok (.bool (a.toNat > b.toNat)) - | .ge, .address a, .address b => .ok (.bool (a.toNat >= b.toNat)) - -- `x ** y`: exact integer power; exponent must be ≥ 0 (spec wraps `% 2^N` by hand, like add/mul). - | .exp, .int x, .int y => if y < 0 then .error .typeError else .ok (.int (x ^ y.toNat)) - | .lt, .fixedBytes n xs, .fixedBytes m ys => - if n = m then - match fixedBytesToNat? n xs, fixedBytesToNat? m ys with - | some x, some y => .ok (.bool (x < y)) - | _, _ => .error .typeError - else .error .typeError - | .le, .fixedBytes n xs, .fixedBytes m ys => - if n = m then - match fixedBytesToNat? n xs, fixedBytesToNat? m ys with - | some x, some y => .ok (.bool (x <= y)) - | _, _ => .error .typeError - else .error .typeError - | .gt, .fixedBytes n xs, .fixedBytes m ys => - if n = m then - match fixedBytesToNat? n xs, fixedBytesToNat? m ys with - | some x, some y => .ok (.bool (x > y)) - | _, _ => .error .typeError - else .error .typeError - | .ge, .fixedBytes n xs, .fixedBytes m ys => - if n = m then - match fixedBytesToNat? n xs, fixedBytesToNat? m ys with - | some x, some y => .ok (.bool (x >= y)) - | _, _ => .error .typeError - else .error .typeError - | .bitAnd, .fixedBytes n xs, .fixedBytes m ys => - if n = m then - if fixedBytesValid n xs && fixedBytesValid m ys then - match fixedBytesBytewise? (· &&& ·) xs ys with - | some zs => .ok (.fixedBytes n zs) - | none => .error .typeError - else .error .typeError - else .error .typeError - | .bitOr, .fixedBytes n xs, .fixedBytes m ys => - if n = m then - if fixedBytesValid n xs && fixedBytesValid m ys then - match fixedBytesBytewise? (· ||| ·) xs ys with - | some zs => .ok (.fixedBytes n zs) - | none => .error .typeError - else .error .typeError - else .error .typeError - | .bitXor, .fixedBytes n xs, .fixedBytes m ys => - if n = m then - if fixedBytesValid n xs && fixedBytesValid m ys then - match fixedBytesBytewise? (· ^^^ ·) xs ys with - | some zs => .ok (.fixedBytes n zs) - | none => .error .typeError - else .error .typeError - else .error .typeError - | .shl, .fixedBytes n xs, .int s => - if s < 0 then .error .typeError - else - match fixedBytesToNat? n xs with - | some x => - let width := 8 * fixedBytesSize n - if s.toNat >= width then .ok (.fixedBytes n (List.replicate (fixedBytesSize n) 0)) - else .ok (fixedBytesFromNat n (x * 2 ^ s.toNat)) - | none => .error .typeError - | .shr, .fixedBytes n xs, .int s => - if s < 0 then .error .typeError - else - match fixedBytesToNat? n xs with - | some x => - let width := 8 * fixedBytesSize n - if s.toNat >= width then .ok (.fixedBytes n (List.replicate (fixedBytesSize n) 0)) - else .ok (fixedBytesFromNat n (x / 2 ^ s.toNat)) - | none => .error .typeError - -- Integer bitwise/shift: defined only on operands in `[0, 2^256)`; a negative or oversized - -- operand is `.error .typeError`, so specs on signed values must re-encode to a word first. - | .bitAnd, .int x, .int y => - if 0 ≤ x ∧ x < (EVM.wordModulus : Int) ∧ 0 ≤ y ∧ y < (EVM.wordModulus : Int) then - .ok (.int (Nat.land x.toNat y.toNat)) - else .error .typeError - | .bitOr, .int x, .int y => - if 0 ≤ x ∧ x < (EVM.wordModulus : Int) ∧ 0 ≤ y ∧ y < (EVM.wordModulus : Int) then - .ok (.int (Nat.lor x.toNat y.toNat)) - else .error .typeError - | .bitXor, .int x, .int y => - if 0 ≤ x ∧ x < (EVM.wordModulus : Int) ∧ 0 ≤ y ∧ y < (EVM.wordModulus : Int) then - .ok (.int (Nat.xor x.toNat y.toNat)) - else .error .typeError - -- `x << s`: the shift `s` must be a non-negative int; `s ≥ 256` gives `0` (EVM `SHL`). - | .shl, .int x, .int s => - if 0 ≤ x ∧ x < (EVM.wordModulus : Int) ∧ 0 ≤ s then - if (256 : Int) ≤ s then .ok (.int 0) - else .ok (.int ((x.toNat * 2 ^ s.toNat) % EVM.wordModulus)) - else .error .typeError - -- `x >> s`: the shift `s` must be a non-negative int; `s ≥ 256` gives `0` (EVM `SHR`). - | .shr, .int x, .int s => - if 0 ≤ x ∧ x < (EVM.wordModulus : Int) ∧ 0 ≤ s then - if (256 : Int) ≤ s then .ok (.int 0) - else .ok (.int (x.toNat / 2 ^ s.toNat)) - else .error .typeError - | _, _, _ => .error .typeError - --- Bitwise mask = mod; single-bit xor flip; `shl` wraps at the top word; `shr` of the max word; --- and a negative operand is a type error. -#guard evalBinaryOp? .bitAnd (.int 0xABCDEF) (.int 0xFF) = .ok (.int (0xABCDEF % 256)) -#guard evalBinaryOp? .bitXor (.int 5) (.int 2) = .ok (.int 7) -#guard evalBinaryOp? .shl (.int (2 ^ 255)) (.int 1) = .ok (.int 0) -#guard evalBinaryOp? .shr (.int (2 ^ 256 - 1)) (.int 255) = .ok (.int 1) -#guard evalBinaryOp? .bitAnd (.int (-1)) (.int 0) = .error .typeError -#guard evalBinaryOp? .exp (.int 2) (.int 10) = .ok (.int 1024) -#guard evalBinaryOp? .exp (.int 0) (.int 0) = .ok (.int 1) -#guard evalBinaryOp? .exp (.int 2) (.int (-1)) = .error .typeError -#guard evalBinaryOp? .lt (.address (.ofNat 3)) (.address (.ofNat 5)) = .ok (.bool true) -#guard evalBinaryOp? .gt (.address (.ofNat 3)) (.address (.ofNat 5)) = .ok (.bool false) - -def bindParams? (params : List Param) (args : List Value) : Option Store := - match params, args with - | [], [] => some ∅ - | p :: ps, v :: vs => do - let rest <- bindParams? ps vs - pure (rest.insert p.name v) - | _, _ => none - -def FunctionDecl.toCallable (decl : FunctionDecl) : CallableDecl := - { params := decl.params, returnType := decl.returnType, body := decl.body } - -def TransitionDecl.toCallable (decl : TransitionDecl) : CallableDecl := - { params := decl.params, returnType := decl.returnType, body := decl.body } - - -def lookupFunction? (decls : List FunctionDecl) (name : Ident) : Option CallableDecl := - match decls with - | [] => none - | d :: ds => - if d.name = name then some d.toCallable else lookupFunction? ds name - -def lookupTransition? (decls : List TransitionDecl) (name : Ident) : Option CallableDecl := - match decls with - | [] => none - | d :: ds => - if d.name = name then some d.toCallable else lookupTransition? ds name - - -def lookupCallable? (contract : ContractDecl) (name : Ident) : Option CallableDecl := - match lookupFunction? contract.functions name with - | some decl => some decl - | none => lookupTransition? contract.transitions name - - --- Defining a measure for termination of the next mutual block, --- that evaluates expressions and related types -mutual - def exprEvalSize : Expr → Nat - | .intLit _ => 1 - | .boolLit _ => 1 - | .bytesLit _ => 1 - | .newBytes lenExpr => exprEvalSize lenExpr + 1 - | .newArray _ lenExpr => exprEvalSize lenExpr + 1 - | .structLit _ fields => structFieldsEvalSize fields + 1 - | .arrayLit elems => exprListEvalSize elems + 1 - | .tupleLit elems => exprListEvalSize elems + 1 - | .bytesSlice baseE startE endE => - exprEvalSize baseE + exprEvalSize startE + exprEvalSize endE + 1 - | .var _ => 1 - | .env _ => 1 - | .storage slot => slotEvalSize slot + 1 - | .arrayLength _ slot => slotEvalSize slot + 1 - | .field base _ => exprEvalSize base + 1 - | .cast expr _ => exprEvalSize expr + 1 - | .inRange _ expr => exprEvalSize expr + 1 - | .addrOf expr => exprEvalSize expr + 1 - | .unary _ expr => exprEvalSize expr + 1 - | .binary _ lhs rhs => exprEvalSize lhs + exprEvalSize rhs + 1 - | .index base idx => exprEvalSize base + exprEvalSize idx + 1 - | .ite cond thenExpr elseExpr => - exprEvalSize cond + exprEvalSize thenExpr + exprEvalSize elseExpr + 1 - | .keccak256 e => exprEvalSize e + 1 - | .abiEncodePacked args => typedArgsEvalSize args + 1 - | .abiEncodeCall _ args => exprListEvalSize args + 1 - | .abiDecode _ e => exprEvalSize e + 1 - | .extCodeSize e => exprEvalSize e + 1 - | .extCodePrefix addrE lenE => exprEvalSize addrE + exprEvalSize lenE + 1 - | .tupleGet e _ => exprEvalSize e + 1 - | .blockhash e => exprEvalSize e + 1 - | .balanceOf e => exprEvalSize e + 1 - | .extCodeHash e => exprEvalSize e + 1 - | .fixedBytesLit _ _ => 1 - termination_by expr => (sizeOf expr, 0) - decreasing_by - all_goals simp_wf - all_goals first | (cases slot; simp; omega) | decreasing_tactic - - def slotEvalSize (slot : StorageRef) : Nat := - slotStepsEvalSize slot.steps + 1 - termination_by (sizeOf slot.steps, 1) - decreasing_by - all_goals omega - - def slotStepEvalSize : StorageRefStep → Nat - | .field _ => 1 - | .mindex expr => exprEvalSize expr + 1 - | .aindex expr => exprEvalSize expr + 1 - termination_by step => (sizeOf step, 0) - decreasing_by - all_goals simp_wf - all_goals decreasing_tactic - - def slotStepsEvalSize : List StorageRefStep → Nat - | [] => 1 - | step :: rest => slotStepEvalSize step + slotStepsEvalSize rest + 1 - termination_by steps => (sizeOf steps, 0) - decreasing_by - all_goals simp_wf - all_goals decreasing_tactic - - def exprListEvalSize : List Expr → Nat - | [] => 1 - | e :: rest => exprEvalSize e + exprListEvalSize rest + 1 - termination_by es => (sizeOf es, 0) - decreasing_by - all_goals simp_wf - all_goals decreasing_tactic - - def structFieldsEvalSize : List (Ident × Expr) → Nat - | [] => 1 - | (_, e) :: rest => exprEvalSize e + structFieldsEvalSize rest + 1 - termination_by fs => (sizeOf fs, 0) - decreasing_by - all_goals simp_wf - all_goals decreasing_tactic - - def typedArgsEvalSize : List (ABIType × Expr) → Nat - | [] => 1 - | (_, e) :: rest => exprEvalSize e + typedArgsEvalSize rest + 1 - termination_by as => (sizeOf as, 0) - decreasing_by - all_goals simp_wf - all_goals decreasing_tactic -end - -/-- The declared `StorageType` reached by following one evaled step from a value of type `t`. -/ -def storageTypeStep? : StorageType -> EvaledStorageRefStep -> Option StorageType - | .struct _ fields, .field name => (fields.find? (fun f => f.1 == name)).map (·.2) - | .tuple ts, .tupleElem k => ts[k]? - | .mapping _ v, .mindex _ => some v - | .array t' _, .aindex _ => some t' - | .dynamicArray t', .aindex _ => some t' - | .bytes, .aindex _ => some (.elem (.int (.uint ⟨8, by decide⟩))) - | .string, .aindex _ => some (.elem (.int (.uint ⟨8, by decide⟩))) - | _, _ => none - -/-- The declared `StorageType` of whatever the evaled ref `er` points at, walked from the contract's - storage declarations (the type tree carried by the frame, independent of the opaque layout). -/ -def storageTypeAt? (decls : List StorageDecl) (er : EvaledStorageRef) : Option StorageType := do - let baseTy <- (decls.find? (fun d => d.name == er.base)).map (·.ty) - er.steps.foldlM storageTypeStep? baseTy - -def storageNatResultToEval : StorageReadResult Nat -> EvalResult Nat - | .ok n => .ok n - | .revert => .revert - | .error => .error .storageError - -def readStorageBytesLength? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : - EvalResult Nat := - match cfg.storage.readBytesLength er evm with - | some result => storageNatResultToEval result - | none => .error .storageError - -/-- Bounds-check a single array index `i` against the array reached by the evaled prefix `pre`. - Fixed arrays are checked against their declared static bound. Dynamic arrays are checked by - asking the layout for the distinct `.length` ref `layout {base, pre ++ [.length]}` and reading - the stored length. In both cases, an index outside `[0, length)` reverts, matching Solidity's - `Panic(0x32)`. - - This is invoked from `evalStorageRefStep` as each `.aindex` is evaluated, so the check is - interleaved with index evaluation exactly as solc emits it. -/ -@[simp] def arrayIndexInBounds? (cfg : Config) (evm : EVM.State) - (decls : List StorageDecl) (base : Ident) (pre : List EvaledStorageRefStep) (i : KeyValue) : - EvalResult Unit := - match storageTypeAt? decls { base := base, steps := pre }, i with - | some (.array _ n), .int iv => - if 0 ≤ iv ∧ iv < n then .ok () else .revert - | some (.array _ _), _ => .error .typeError - | some (.dynamicArray _), .int iv => - match cfg.storage.layout { base := base, steps := pre ++ [.length] } evm with - | some lenLoc => - match storageLocLoad evm lenLoc with - | .int len => if 0 ≤ iv ∧ iv < len then .ok () else .revert - | _ => .error .storageError - | none => .error .storageError - | some (.dynamicArray _), _ => .error .typeError - | some (.bytes), .int iv - | some (.string), .int iv => - match readStorageBytesLength? cfg evm { base := base, steps := pre } with - | .ok len => if 0 ≤ iv ∧ iv < len then .ok () else .revert - | .revert => .revert - | .error e => .error e - | some (.bytes), _ | some (.string), _ => .error .typeError - | some _, _ => .error .typeError - | none, _ => .error .storageError - -def storagePrepareResultToEval : StorageReadResult EVM.State -> EvalResult EVM.State - | .ok evm => .ok evm - | .revert => .revert - | .error => .error .storageError - -def storageValueResultToEval : StorageReadResult Value -> EvalResult Value - | .ok v => .ok v - | .revert => .revert - | .error => .error .storageError - -/- Recursively zero **every** storage slot occupied by a value of declared type `t` located at - `er` — solc's `delete`. Leaves are cleared through the opaque `layout`; the *structure* (struct - fields, tuple/fixed-array elements, dynamic-array length + all data) is driven by `t`, so a - nested dynamic array is cleared in full (its inner length is read and every inner element - recursively cleared). Mappings are skipped — their keys aren't enumerable, and solc's `delete` - on a mapping is likewise a no-op. -/ -mutual -def clearStorage? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : - StorageType -> EvalResult EVM.State - | .elem _ | .contract _ => - match cfg.storage.layout er evm with - | some loc => EvalResult.ofOption .storageError (storageLocStore evm loc (.int 0)) - | none => .error .storageError - | .mapping _ _ => .ok evm - | .struct _ fields => clearFields? cfg evm er fields - | .tuple ts => clearTupleElems? cfg evm er 0 ts - | .array t' n => clearArrayElems? cfg evm er t' n - | .dynamicArray t' => - match cfg.storage.layout { er with steps := er.steps ++ [.length] } evm with - | some lenLoc => - match storageLocLoad evm lenLoc with - | .int len => - match clearArrayElems? cfg evm er t' len.toNat with - | .ok evm1 => EvalResult.ofOption .storageError (storageLocStore evm1 lenLoc (.int 0)) - | r => r - | _ => .error .storageError - | none => .error .storageError - | .bytes => - match cfg.storage.clearValue? er .bytes evm with - | some result => storagePrepareResultToEval result - | none => .error .storageError - | .string => - match cfg.storage.clearValue? er .string evm with - | some result => storagePrepareResultToEval result - | none => .error .storageError - termination_by t => (sizeOf t, 0) - -def clearFields? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : - List (Ident × StorageType) -> EvalResult EVM.State - | [] => .ok evm - | (name, ft) :: rest => - match clearStorage? cfg evm { er with steps := er.steps ++ [.field name] } ft with - | .ok evm1 => clearFields? cfg evm1 er rest - | r => r - termination_by fields => (sizeOf fields, 0) - -def clearTupleElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (k : Nat) : - List StorageType -> EvalResult EVM.State - | [] => .ok evm - | tt :: rest => - match clearStorage? cfg evm { er with steps := er.steps ++ [.tupleElem k] } tt with - | .ok evm1 => clearTupleElems? cfg evm1 er (k+1) rest - | r => r - termination_by ts => (sizeOf ts, 0) - -def clearArrayElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (t' : StorageType) : - Nat -> EvalResult EVM.State - | 0 => .ok evm - | n+1 => - match clearStorage? cfg evm { er with steps := er.steps ++ [.aindex (.int n)] } t' with - | .ok evm1 => clearArrayElems? cfg evm1 er t' n - | r => r - termination_by c => (sizeOf t', c) -end - -/- Recursively write a structured `Value` into the storage of declared type `t` at `er` — the dual - of `clearStorage?`. Leaves go through the opaque `layout` + `storageLocStore`; structure (struct - fields, tuple/array elements) is driven by `t`, and a `dynamicArray` target also writes its - length. A type/value mismatch (or a mapping/`bytes` target) is an `.error`, never a partial - write. -/ -mutual -def writeStorage? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : - StorageType -> Value -> EvalResult EVM.State - | .elem _, v - | .contract _, v => - match cfg.storage.layout er evm with - | some loc => EvalResult.ofOption .storageError (storageLocStore evm loc v) - | none => .error .storageError - | .struct _ ftypes, .struct _ fvals => writeFields? cfg evm er ftypes fvals - | .tuple ts, .tuple vs => writeTupleElems? cfg evm er 0 ts vs - | .array t' n, .array vs => - if vs.length = n then writeArrayElems? cfg evm er t' 0 vs - else .error .typeError - | .dynamicArray t', .array vs => do - -- clear the existing array first, so old elements beyond the new (possibly shorter) length - -- don't linger — matching solc's array-assignment cleanup, and preserving the - -- zero-beyond-length invariant that grow-only `push` relies on - let evm0 <- clearStorage? cfg evm er (.dynamicArray t') - let evm1 <- writeArrayElems? cfg evm0 er t' 0 vs - let lenLoc <- EvalResult.ofOption .storageError - (cfg.storage.layout { er with steps := er.steps ++ [.length] } evm) - EvalResult.ofOption .storageError (storageLocStore evm1 lenLoc (.int vs.length)) - | .bytes, .bytes bs => - match cfg.storage.writeValue? er .bytes (.bytes bs) evm with - | some result => storagePrepareResultToEval result - | none => .error .storageError - | .string, .bytes bs => - match cfg.storage.writeValue? er .string (.bytes bs) evm with - | some result => storagePrepareResultToEval result - | none => .error .storageError - | _, _ => .error .typeError - termination_by t => (sizeOf t, 0) - -def writeFields? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : - List (Ident × StorageType) -> List (Ident × Value) -> EvalResult EVM.State - | [], [] => .ok evm - | (name, ft) :: trest, (vname, fv) :: vrest => - if name == vname then - match writeStorage? cfg evm { er with steps := er.steps ++ [.field name] } ft fv with - | .ok evm1 => writeFields? cfg evm1 er trest vrest - | r => r - else .error .typeError - | _, _ => .error .typeError - termination_by ftypes => (sizeOf ftypes, 0) - -def writeTupleElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (k : Nat) : - List StorageType -> List Value -> EvalResult EVM.State - | [], [] => .ok evm - | tt :: trest, v :: vrest => - match writeStorage? cfg evm { er with steps := er.steps ++ [.tupleElem k] } tt v with - | .ok evm1 => writeTupleElems? cfg evm1 er (k+1) trest vrest - | r => r - | _, _ => .error .typeError - termination_by ts => (sizeOf ts, 0) - -def writeArrayElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (t' : StorageType) - (k : Nat) : List Value -> EvalResult EVM.State - | [] => .ok evm - | v :: rest => - match writeStorage? cfg evm { er with steps := er.steps ++ [.aindex (.int k)] } t' v with - | .ok evm1 => writeArrayElems? cfg evm1 er t' (k+1) rest - | r => r - termination_by vs => (sizeOf t', sizeOf vs) -end - -/- Recursively read a value of declared type `t` out of storage at `er` into a `Value` — the read - dual of `writeStorage?`/`clearStorage?`. Leaves come from the opaque `layout` + `storageLocLoad`; - structure (struct fields, tuple/fixed-array elements, dynamic-array length + all data) is driven - by `t`, so a nested dynamic array is read in full. A mapping has no enumerable contents, so a - whole-mapping read is an `.error`. -/ -mutual -def readStorage? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : - StorageType -> EvalResult Value - | .elem _ - | .contract _ => - match cfg.storage.layout er evm with - | some loc => .ok (storageLocLoad evm loc) - | none => .error .storageError - | .mapping _ _ => .error .typeError - | .struct name fields => do - let fvals <- readFields? cfg evm er fields - pure (.struct name fvals) - | .tuple ts => do - let vs <- readTupleElems? cfg evm er 0 ts - pure (.tuple vs) - | .array t' n => do - let vs <- readArrayElems? cfg evm er t' 0 n - pure (.array vs) - | .dynamicArray t' => - match cfg.storage.layout { er with steps := er.steps ++ [.length] } evm with - | some lenLoc => - match storageLocLoad evm lenLoc with - | .int len => do - let vs <- readArrayElems? cfg evm er t' 0 len.toNat - pure (.array vs) - | _ => .error .storageError - | none => .error .storageError - | .bytes => - match cfg.storage.readValue? er .bytes evm with - | some result => storageValueResultToEval result - | none => .error .storageError - | .string => - match cfg.storage.readValue? er .string evm with - | some result => storageValueResultToEval result - | none => .error .storageError - termination_by t => (sizeOf t, 0) - -def readFields? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : - List (Ident × StorageType) -> EvalResult (List (Ident × Value)) - | [] => .ok [] - | (name, ft) :: rest => do - let v <- readStorage? cfg evm { er with steps := er.steps ++ [.field name] } ft - let vrest <- readFields? cfg evm er rest - pure ((name, v) :: vrest) - termination_by fields => (sizeOf fields, 0) - -def readTupleElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (k : Nat) : - List StorageType -> EvalResult (List Value) - | [] => .ok [] - | tt :: rest => do - let v <- readStorage? cfg evm { er with steps := er.steps ++ [.tupleElem k] } tt - let vrest <- readTupleElems? cfg evm er (k+1) rest - pure (v :: vrest) - termination_by ts => (sizeOf ts, 0) - -def readArrayElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (t' : StorageType) - (k : Nat) : Nat -> EvalResult (List Value) - | 0 => .ok [] - | c+1 => do - let v <- readStorage? cfg evm { er with steps := er.steps ++ [.aindex (.int k)] } t' - let vrest <- readArrayElems? cfg evm er t' (k+1) c - pure (v :: vrest) - termination_by c => (sizeOf t', c) -end - -def readStorageArrayLength? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) - : StorageType -> EvalResult Value - | .array _ n => pure (.int n) - | .elem (.bytes n) => pure (.int (fixedBytesSize n)) - | .dynamicArray _ => - match cfg.storage.layout { er with steps := er.steps ++ [.length] } evm with - | some lenLoc => - match storageLocLoad evm lenLoc with - | .int n => pure (.int n) - | _ => .error .storageError - | none => .error .storageError - | .bytes | .string => do - let len <- readStorageBytesLength? cfg evm er - pure (.int len) - | _ => .error .typeError - -mutual -def defaultValue? : StorageType -> EvalResult Value - | .elem (.bool) => pure (.bool false) - | .elem (.address) => pure (.address (.ofNat 0)) - | .elem (.bytes n) => pure (.fixedBytes n (List.replicate (n.val + 1) 0)) - | .elem _ => pure (.int 0) - | .contract _ => pure (.address (.ofNat 0)) - | .mapping _ _ => .error .typeError - | .struct name fields => do - let values <- defaultFields? fields - pure (.struct name values) - | .tuple ts => do - let values <- defaultValues? ts - pure (.tuple values) - | .array elemTy n => do - let value <- defaultValue? elemTy - pure (.array (List.replicate n value)) - | .dynamicArray _ => pure (.array []) - | .bytes | .string => pure (.bytes ByteArray.empty) - termination_by t => (sizeOf t, 0) - -def defaultFields? : List (Ident × StorageType) -> EvalResult (List (Ident × Value)) - | [] => pure [] - | (name, ty) :: rest => do - let value <- defaultValue? ty - let values <- defaultFields? rest - pure ((name, value) :: values) - termination_by fields => (sizeOf fields, 0) - -def defaultValues? : List StorageType -> EvalResult (List Value) - | [] => pure [] - | ty :: rest => do - let value <- defaultValue? ty - let values <- defaultValues? rest - pure (value :: values) - termination_by ts => (sizeOf ts, 0) -end - -/-- Packed ("non-padded") ABI encoding of a single value, per Solidity's `abi.encodePacked`: each - value takes its natural byte width with no left/right padding and no length prefix — `uintN`/`intN` - are `N/8` big-endian bytes, `bool` is one byte, `address` is its 20 bytes, `bytesN` is its `N` - bytes, and dynamic `bytes` is its raw contents. Only the cases needed by current specs are - handled; anything else returns `none` rather than risk a silent mis-encoding. -/ --- `abi.encodePacked` of an array: each element is a full 32-byte padded word, no length prefix --- (verified from solc 0.8.35 Yul IR — `add(pos, 0x20)` per element). Elementary elements only --- (`encodeABIWord?` returns `none` for nested/dynamic element types). -def encodePackedArrayElems? (elemTy : ABIType) : List Value → Option (List UInt8) - | [] => some [] - | v :: vs => do - let w <- encodeABIWord? elemTy v - let rest <- encodePackedArrayElems? elemTy vs - some (EVM.Word.toBytesBE w ++ rest) - -def encodePackedValue? (ty : ABIType) (v : Value) : Option (List UInt8) := - match ty, v with - | .elem .bool, .bool b => some [if b then (1 : UInt8) else 0] - | .array elemTy _, .array vs => encodePackedArrayElems? elemTy vs - | .dynamicArray elemTy, .array vs => encodePackedArrayElems? elemTy vs - | .elem .address, .address a => some ((EVM.word a).toBytesBE.drop 12) - | .elem (.int (.uint bits)), .int _ => do - let w <- encodeABIWord? ty v - some (w.toBytesBE.drop (32 - bits.val / 8)) - | .elem (.int (.sint bits)), .int _ => do - let w <- encodeABIWord? ty v - some (w.toBytesBE.drop (32 - bits.val / 8)) - | .elem (.bytes n), .fixedBytes m bytes => - if m = n ∧ bytes.length = fixedBytesSize n then some bytes else none - | .bytes, .bytes ba => some ba.toList - | .string, .bytes ba => some ba.toList - | _, _ => none - -#guard encodePackedValue? (.dynamicArray (.elem (.int (.uint ⟨8, by decide⟩)))) (.array [.int 1, .int 2]) - = some (List.replicate 31 0 ++ [1] ++ List.replicate 31 0 ++ [2]) - --- `b[s:e]`: solc compiles `d[x:y]` to two `GT → REVERT` guards (verified solc 0.6.12 & 0.8.35): --- revert iff `s > e` or `e > b.size`; negative bounds are ill-typed. -def sliceBytes? (ba : ByteArray) (s e : Int) : EvalResult Value := - if s < 0 || e < 0 then .error .typeError - else if s.toNat > e.toNat || e.toNat > ba.size then .revert - else .ok (.bytes (ba.extract s.toNat e.toNat)) - -#guard sliceBytes? (ByteArray.mk #[10, 20, 30, 40, 50]) 1 3 = .ok (.bytes (ByteArray.mk #[20, 30])) -#guard sliceBytes? (ByteArray.mk #[10, 20, 30]) 0 3 = .ok (.bytes (ByteArray.mk #[10, 20, 30])) -#guard sliceBytes? (ByteArray.mk #[10, 20, 30]) 0 4 = .revert -#guard sliceBytes? (ByteArray.mk #[10, 20, 30]) 2 1 = .revert -#guard sliceBytes? (ByteArray.mk #[10, 20, 30]) 2 2 = .ok (.bytes (ByteArray.mk #[])) -#guard sliceBytes? (ByteArray.mk #[10, 20, 30]) (-1) 2 = .error .typeError - -def tupleGetValue? (v : Value) (i : Nat) : EvalResult Value := - match v with - | .tuple vs => match vs[i]? with | some c => .ok c | none => .error .typeError - | _ => .error .typeError - -#guard tupleGetValue? (.tuple [.int 7, .bool true]) 0 = .ok (.int 7) -#guard tupleGetValue? (.tuple [.int 7, .bool true]) 1 = .ok (.bool true) -#guard tupleGetValue? (.tuple [.int 7, .bool true]) 2 = .error .typeError -#guard tupleGetValue? (.int 7) 0 = .error .typeError - --- CREATE2 salt: a `bytes32` value → its 32 salt bytes; anything else is invalid. -def saltBytes? : Value → Option ByteArray - | .fixedBytes n bs => if n.val = 31 ∧ bs.length = 32 then some (ByteArray.mk bs.toArray) else none - | _ => none - -#guard saltBytes? (.fixedBytes ⟨31, by decide⟩ (List.replicate 32 0)) - = some (ByteArray.mk (Array.replicate 32 0)) -#guard saltBytes? (.int 5) = none - -mutual - -def evalStorageRefStep (cfg : Config) (solm : Frame) (evm : EVM.State) - (base : Ident) (pre : List EvaledStorageRefStep) (step : StorageRefStep) : EvalResult EvaledStorageRefStep := - match step with - | .field name => pure (.field name) - | .mindex expr => do - let index <- evalExpr? cfg solm evm expr - let indexKey <- EvalResult.ofOption .typeError (valueToKey? index) - pure (.mindex indexKey) - | .aindex expr => do - let index <- evalExpr? cfg solm evm expr - let indexKey <- EvalResult.ofOption .typeError (valueToKey? index) - -- check this index in bounds against the array reached by `pre`, *before* descending — - -- interleaved with index evaluation exactly as solc emits it - let _ <- arrayIndexInBounds? cfg evm solm.contract.storage base pre indexKey - pure (.aindex indexKey) - termination_by (slotStepEvalSize step, 0) - decreasing_by - all_goals simp [slotStepEvalSize] - all_goals omega - -/-- Evaluate a list of storage-ref steps left to right, threading the evaled prefix so each - `.aindex` can be bounds-checked against the array reached so far (see `evalStorageRefStep`). -/ -@[simp] def evalStorageRefSteps (cfg : Config) (solm : Frame) (evm : EVM.State) - (base : Ident) (pre : List EvaledStorageRefStep) : - List StorageRefStep -> EvalResult (List EvaledStorageRefStep) - | [] => pure [] - | step :: rest => do - let estep <- evalStorageRefStep cfg solm evm base pre step - let erest <- evalStorageRefSteps cfg solm evm base (pre ++ [estep]) rest - pure (estep :: erest) - termination_by steps => (slotStepsEvalSize steps, 0) - decreasing_by - all_goals simp [slotStepsEvalSize] - all_goals omega - -def evalStorageRef (cfg : Config) (solm : Frame) (evm : EVM.State) (slot : StorageRef) : EvalResult EvaledStorageRef := do - let steps <- evalStorageRefSteps cfg solm evm slot.base [] slot.steps - pure { base := slot.base, steps := steps } - termination_by (slotEvalSize slot, 0) - decreasing_by - simp [slotEvalSize] - apply Prod.Lex.left - omega - -/-- Follow unevaluated storage-ref steps from an already-evaluated storage root, threading both the - concrete evaluated path and its declared storage type. This is the workhorse for local - `storage` aliases. -/ -def evalStorageRefFrom? (cfg : Config) (solm : Frame) (evm : EVM.State) - (er : EvaledStorageRef) (ty : StorageType) : - List StorageRefStep -> EvalResult (EvaledStorageRef × StorageType) - | [] => pure (er, ty) - | step :: rest => do - let estep <- evalStorageRefStep cfg solm evm er.base er.steps step - let ty' <- EvalResult.ofOption .typeError (storageTypeStep? ty estep) - evalStorageRefFrom? cfg solm evm { er with steps := er.steps ++ [estep] } ty' rest - termination_by steps => (slotStepsEvalSize steps, 0) - decreasing_by - all_goals simp [slotStepsEvalSize] - all_goals omega - -/-- Resolve a storage lvalue. The base may be a contract storage declaration or a local - `Value.storageRef` alias; in the latter case we append the unevaluated suffix to the stored, - already-evaluated reference. -/ -def resolveStorageRef? (cfg : Config) (solm : Frame) (evm : EVM.State) - (slot : StorageRef) : EvalResult (EvaledStorageRef × StorageType) := - match solm.locals.get? slot.base with - | some (.storageRef er ty) => evalStorageRefFrom? cfg solm evm er ty slot.steps - | _ => - match evalStorageRef cfg solm evm slot with - | .ok er => do - let ty <- EvalResult.ofOption .storageError (storageTypeAt? solm.contract.storage er) - pure (er, ty) - | .revert => .revert - | .error e => .error e - termination_by (slotEvalSize slot, 1) - decreasing_by - all_goals simp [slotEvalSize] - all_goals omega - -def resolveDynamicArrayRef? (cfg : Config) (solm : Frame) (evm : EVM.State) - (ref : StorageRef) : EvalResult (EvaledStorageRef × StorageType) := do - let (er, ty) <- resolveStorageRef? cfg solm evm ref - match ty with - | .dynamicArray elemTy => pure (er, elemTy) - | _ => .error .storageError - -def readLocalPath? (cfg : Config) (solm : Frame) (evm : EVM.State) - (root : Value) : List StorageRefStep -> EvalResult Value - | [] => pure root - | .field name :: rest => do - let child <- EvalResult.ofOption .typeError (lookupField? root name) - readLocalPath? cfg solm evm child rest - | .mindex expr :: rest => do - let idx <- evalExpr? cfg solm evm expr - let child <- EvalResult.ofOption .typeError (lookupIndex? root idx) - readLocalPath? cfg solm evm child rest - | .aindex expr :: rest => do - let idx <- evalExpr? cfg solm evm expr - match root, idx with - | .array elems, .int i => - -- memory array index read: out of bounds reverts (solc's `Panic(0x32)`) - if 0 ≤ i ∧ i < elems.length then - let child <- EvalResult.ofOption .typeError (lookupIndex? root idx) - readLocalPath? cfg solm evm child rest - else .revert - | .fixedBytes n bytes, .int i => - match evalFixedBytesIndex? n bytes i with - | .ok child => readLocalPath? cfg solm evm child rest - | .revert => .revert - | .error e => .error e - | .bytes bytes, .int i => - match evalByteIndex? bytes.toList i with - | .ok child => readLocalPath? cfg solm evm child rest - | .revert => .revert - | .error e => .error e - | _, _ => - let child <- EvalResult.ofOption .typeError (lookupIndex? root idx) - readLocalPath? cfg solm evm child rest - termination_by steps => (slotStepsEvalSize steps, 0) - decreasing_by - all_goals simp [slotStepsEvalSize, slotStepEvalSize] - all_goals omega - -def updateLocalPath? (cfg : Config) (solm : Frame) (evm : EVM.State) - (root : Value) (steps : List StorageRefStep) (value : Value) : EvalResult Value := - match steps with - | [] => pure value - | .field name :: rest => do - let child <- EvalResult.ofOption .typeError (lookupField? root name) - let child' <- updateLocalPath? cfg solm evm child rest value - EvalResult.ofOption .typeError (updateField? root name child') - | .mindex expr :: rest => do - let idx <- evalExpr? cfg solm evm expr - let child <- EvalResult.ofOption .typeError (lookupIndex? root idx) - let child' <- updateLocalPath? cfg solm evm child rest value - EvalResult.ofOption .typeError (updateIndex? root idx child') - | .aindex expr :: rest => do - let idx <- evalExpr? cfg solm evm expr - match root, idx with - | .array elems, .int i => - -- memory array index write: out of bounds reverts (solc's `Panic(0x32)`) - if 0 ≤ i ∧ i < elems.length then - let child <- EvalResult.ofOption .typeError (lookupIndex? root idx) - let child' <- updateLocalPath? cfg solm evm child rest value - EvalResult.ofOption .typeError (updateIndex? root idx child') - else .revert - | _, _ => - let child <- EvalResult.ofOption .typeError (lookupIndex? root idx) - let child' <- updateLocalPath? cfg solm evm child rest value - EvalResult.ofOption .typeError (updateIndex? root idx child') - termination_by (slotStepsEvalSize steps, 0) - decreasing_by - all_goals simp [slotStepsEvalSize, slotStepEvalSize] - all_goals omega - -def assignStorageRef? (cfg : Config) (solm : Frame) (evm : EVM.State) - (origin : VarOrigin) (slot : StorageRef) (value : Value) : EvalResult (Frame × EVM.State) := - match origin with - | .localVar => - -- in-memory local: functionally update the bound `Value` along the path - match solm.locals.get? slot.base with - | some root => do - let root' <- updateLocalPath? cfg solm evm root slot.steps value - pure ({ solm with locals := solm.locals.insert slot.base root' }, evm) - | none => .error .unboundVariable - | .storage => do - let (evaledStorageRef, ty) <- resolveStorageRef? cfg solm evm slot - match value with - | .struct _ _ | .array _ | .bytes _ => do - -- whole-array / whole-struct assignment: write every slot by the declared type - let evm' <- writeStorage? cfg evm evaledStorageRef ty value - pure (solm, evm') - | _ => do - -- scalar leaf: a single whole/partial-slot store - let loc <- EvalResult.ofOption .storageError (cfg.storage.layout evaledStorageRef evm) - let evm' <- EvalResult.ofOption .storageError (storageLocStore evm loc value) - pure (solm, evm') - -def evalExpr? (cfg : Config) (solm : Frame) (evm : EVM.State) : - Expr -> EvalResult Value - | .intLit n => pure (.int n) - | .boolLit b => pure (.bool b) - | .bytesLit b => pure (.bytes b) - | .newBytes lenExpr => do - let lenVal <- evalExpr? cfg solm evm lenExpr - match lenVal with - | .int n => if n < 0 then .error .typeError - else pure (.bytes (ByteArray.mk (Array.replicate n.toNat (0 : UInt8)))) - | _ => .error .typeError - | .newArray elemTy lenExpr => do - let lenVal <- evalExpr? cfg solm evm lenExpr - match lenVal with - | .int n => - if n < 0 then .error .typeError - else do - let defaultValue <- defaultValue? elemTy - pure (.array (List.replicate n.toNat defaultValue)) - | _ => .error .typeError - | .structLit name fields => do - let fvals <- evalStructFields? cfg solm evm fields - pure (.struct name fvals) - | .arrayLit elems => do - let vals <- evalExprList? cfg solm evm elems - pure (.array vals) - | .tupleLit elems => do - let vals <- evalExprList? cfg solm evm elems - pure (.tuple vals) - | .bytesSlice baseE startE endE => do - let baseV <- evalExpr? cfg solm evm baseE - let startV <- evalExpr? cfg solm evm startE - let endV <- evalExpr? cfg solm evm endE - match baseV, startV, endV with - | .bytes ba, .int s, .int e => sliceBytes? ba s e - | _, _, _ => .error .typeError - | .var name => EvalResult.ofOption .unboundVariable (solm.locals.get? name) - | .env var => pure (envValue evm var) - | .storage slot => do - let (evaledStorageRef, ty) <- resolveStorageRef? cfg solm evm slot - readStorage? cfg evm evaledStorageRef ty - | .arrayLength origin slot => do - match origin with - | .storage => do - let (er, ty) <- resolveStorageRef? cfg solm evm slot - readStorageArrayLength? cfg evm er ty - | .localVar => - match solm.locals.get? slot.base with - | some root => do - let v <- readLocalPath? cfg solm evm root slot.steps - match v with - | .array vs => pure (.int vs.length) - | .bytes b => pure (.int (Int.ofNat b.size)) - | .fixedBytes n _ => pure (.int (fixedBytesSize n)) - | _ => .error .typeError - | none => .error .unboundVariable - | .field base name => do - let baseValue <- evalExpr? cfg solm evm base - match baseValue with - | .storageRef er ty => do - let step := EvaledStorageRefStep.field name - let ty' <- EvalResult.ofOption .typeError (storageTypeStep? ty step) - readStorage? cfg evm { er with steps := er.steps ++ [step] } ty' - | _ => EvalResult.ofOption .typeError (lookupField? baseValue name) - | .cast expr ty => do /- TODO do we really need to have casting? -/ - let value <- evalExpr? cfg solm evm expr - EvalResult.ofOption .typeError (castValue? value ty) - | .addrOf expr => do - let value <- evalExpr? cfg solm evm expr - match value with - | .address a => pure (.address a) - | _ => .error .typeError - | .unary op expr => do - let value <- evalExpr? cfg solm evm expr - EvalResult.ofOption .typeError (evalUnaryOp? op value) - | .binary .and lhs rhs => do - match <- evalExpr? cfg solm evm lhs with - | .bool false => pure (.bool false) - | .bool true => - (match <- evalExpr? cfg solm evm rhs with - | .bool b => pure (.bool b) - | _ => .error .typeError) - | _ => .error .typeError - | .binary .or lhs rhs => do - match <- evalExpr? cfg solm evm lhs with - | .bool true => pure (.bool true) - | .bool false => - (match <- evalExpr? cfg solm evm rhs with - | .bool b => pure (.bool b) - | _ => .error .typeError) - | _ => .error .typeError - | .binary op lhs rhs => do - let lhsValue <- evalExpr? cfg solm evm lhs - let rhsValue <- evalExpr? cfg solm evm rhs - evalBinaryOp? op lhsValue rhsValue - | .index base idx => do - let baseValue <- evalExpr? cfg solm evm base - let idxValue <- evalExpr? cfg solm evm idx - evalIndex? baseValue idxValue - | .ite cond thenExpr elseExpr => do - let condValue <- evalExpr? cfg solm evm cond - match condValue with - | .bool true => evalExpr? cfg solm evm thenExpr - | .bool false => evalExpr? cfg solm evm elseExpr - | _ => .error .typeError - | .inRange intType expr => do - let value <- evalExpr? cfg solm evm expr - match value, intType with - | .int i, .uint n => - if i < 0 || i >= 2^(n.val) then .revert else pure value - | .int i, .sint n => - let bound : Int := 2^(n.val - 1) - if i < -bound || i >= bound then .revert else pure value - | _, _ => .error .typeError - | .keccak256 e => do - let value <- evalExpr? cfg solm evm e - match value with - -- Keccak-256 of the dynamic bytes, as a `bytes32` value; same `ffi.KEC` as the EVM opcode. - | .bytes ba => pure (.fixedBytes ⟨31, by decide⟩ (ffi.KEC ba).toList) - | _ => .error .typeError - | .abiEncodePacked args => do - let bytes <- evalPackedArgs? cfg solm evm args - pure (.bytes (ByteArray.mk bytes.toArray)) - | .abiEncodeCall name args => do - let values <- evalExprList? cfg solm evm args - let bytes <- EvalResult.ofOption .typeError (cfg.externalABI.encode? name values) - pure (.bytes bytes) - | .abiDecode ty e => do - let value <- evalExpr? cfg solm evm e - match value with - | .bytes bytes => - match ABI.decodeReturnValueWithMode? cfg.abiDecodeMode ty bytes with - | some decoded => pure decoded - | none => .revert - | _ => .error .typeError - | .extCodeSize e => do - let value <- evalExpr? cfg solm evm e - match value with - -- EXTCODESIZE: the deployed code size at `a`; 0 for a non-existent account or an EOA. - -- Mirrors `Ethereum.State.extCodeSize` (which the EVM's EXTCODESIZE opcode dispatches to). - | .address a => - pure (.int (Int.ofNat - (EVM.Word.ofNat ((evm.lookupAccount a).option 0 (fun acc => acc.code.size))).toNat)) - | _ => .error .typeError - | .extCodePrefix addrE lenE => do - let addrV <- evalExpr? cfg solm evm addrE - let lenV <- evalExpr? cfg solm evm lenE - match addrV, lenV with - | .address a, .int n => - if n < 0 then .error .typeError - else - let code := (evm.lookupAccount a).option .empty (fun acc => acc.code) - let codePrefix := code.extract 0 n.toNat - pure (.bytes (codePrefix ++ - ByteArray.mk (Array.replicate (n.toNat - codePrefix.size) (0 : UInt8)))) - | _, _ => .error .typeError - | .tupleGet e i => do - let v <- evalExpr? cfg solm evm e - tupleGetValue? v i - -- BLOCKHASH: mirrors `Ethereum.State.blockHash` (256-block window; current/future → 0), as bytes32. - | .blockhash e => do - let v <- evalExpr? cfg solm evm e - match v with - | .int n => if n < 0 then .error .typeError - else pure (.fixedBytes ⟨31, by decide⟩ - (EVM.Word.toBytesBE (evm.blockHash (EVM.Word.ofNat n.toNat)))) - | _ => .error .typeError - -- BALANCE: mirrors `Ethereum.State.balance` (absent account → 0). - | .balanceOf e => do - let v <- evalExpr? cfg solm evm e - match v with - | .address a => - pure (.int (Int.ofNat ((evm.lookupAccount a).option (EVM.Word.ofNat 0) (·.balance)).toNat)) - | _ => .error .typeError - -- EXTCODEHASH: mirrors `Ethereum.State.extCodeHash` (dead account → 0), as bytes32. - | .extCodeHash e => do - let v <- evalExpr? cfg solm evm e - match v with - | .address a => - let h : EVM.Word := - if Ethereum.State.dead evm.accountMap a then ⟨0⟩ - else (evm.lookupAccount a).option ⟨0⟩ Ethereum.Account.codeHash - pure (.fixedBytes ⟨31, by decide⟩ (EVM.Word.toBytesBE h)) - | _ => .error .typeError - | .fixedBytesLit n bs => pure (.fixedBytes n bs) - termination_by expr => (exprEvalSize expr, 0) -decreasing_by - all_goals simp [exprEvalSize, slotEvalSize] - all_goals omega - -/-- Evaluate a list of expressions left to right (for `arrayLit` / tuple returns), short-circuiting - on the first `revert`/`error`. -/ -def evalExprList? (cfg : Config) (solm : Frame) (evm : EVM.State) : - List Expr -> EvalResult (List Value) - | [] => pure [] - | e :: rest => do - let v <- evalExpr? cfg solm evm e - let vs <- evalExprList? cfg solm evm rest - pure (v :: vs) -termination_by es => (exprListEvalSize es, 0) -decreasing_by - all_goals simp [exprListEvalSize] - all_goals omega - -/-- Evaluate a struct literal's named field expressions left to right (for `structLit`), - short-circuiting on the first `revert`/`error`. -/ -def evalStructFields? (cfg : Config) (solm : Frame) (evm : EVM.State) : - List (Ident × Expr) -> EvalResult (List (Ident × Value)) - | [] => pure [] - | (name, e) :: rest => do - let v <- evalExpr? cfg solm evm e - let vs <- evalStructFields? cfg solm evm rest - pure ((name, v) :: vs) -termination_by fs => (structFieldsEvalSize fs, 0) -decreasing_by - all_goals simp [structFieldsEvalSize] - all_goals omega - -/-- Evaluate each `abi.encodePacked` operand left to right and concatenate its packed encoding, - short-circuiting on the first `revert`/`error` (or a `.typeError` if a value cannot be packed). -/ -def evalPackedArgs? (cfg : Config) (solm : Frame) (evm : EVM.State) : - List (ABIType × Expr) -> EvalResult (List UInt8) - | [] => pure [] - | (ty, e) :: rest => do - let v <- evalExpr? cfg solm evm e - let head <- EvalResult.ofOption .typeError (encodePackedValue? ty v) - let tail <- evalPackedArgs? cfg solm evm rest - pure (head ++ tail) -termination_by as => (typedArgsEvalSize as, 0) -decreasing_by - all_goals simp [typedArgsEvalSize] - all_goals omega - -end - -def evalExprs? (cfg : Config) (solm : Frame) (evm : EVM.State) - (exprs : List Expr) : EvalResult (List Value) := - match exprs with - | [] => pure [] - | expr :: rest => do - let value <- evalExpr? cfg solm evm expr - let values <- evalExprs? cfg solm evm rest - pure (value :: values) - -def externalValueToWord? : Value -> Option EVM.Word - | .int i => some (EVM.wordOfInt i) - | .bool b => some b.toUInt256 - | .address a => some (EVM.word a) - | .unit => some ⟨0⟩ - | _ => none - -def wordsOfValues? (values : List Value) : Option (List EVM.Word) := - match values with - | [] => some [] - | value :: rest => do - let word <- externalValueToWord? value - let words <- wordsOfValues? rest - some (word :: words) - -def defaultEncodeCall? (_name : Ident) (args : List Value) : Option EVM.Bytes := do - let words <- wordsOfValues? args - some (words.foldl (fun bytes word => bytes ++ (Ethereum.UInt256.toByteArray word)) ByteArray.empty) - -def defaultDecodeReturn? (_name : Ident) (bytes : EVM.Bytes) : Option (List Value) := - -- Default typed external calls expect one `uint256` return word. The ABI decoder models solc's - -- generated signed-size guard, so under-length and huge return data both decode to `none`. - ABI.decodeReturnValues? [.elem (.int (.uint ⟨256, by decide⟩))] bytes - -def defaultExternalCallABI : ExternalCallABI := - { encode? := defaultEncodeCall?, decode? := defaultDecodeReturn? } - -/-- A raw message call to `target` with the given `value` and `calldata`, bridged directly to the - EVM `Θ`. No ABI encoding — calldata is supplied verbatim — and the boolean result is the raw - call success flag. The final optional parameter is the callee permission bit passed to `Θ`; - ordinary `CALL` uses the default `true`, while `STATICCALL` uses `false`. Both the low-level - `.call` and (via `typedCallViaEVM`) typed external calls are built on this. -/ -inductive callViaEVM (evm : EVM.State) (target : EVM.Address) - (value : ℤ) (calldata : EVM.Bytes) : - (Bool × EVM.State × EVM.Bytes) → (perm : Bool := true) → Prop where - | callMade : - valueWord = EVM.wordOfInt value - → (∃ (callGas : Ethereum.UInt256) (A_in : Ethereum.Substate), - -- The external call bridges directly to the EVM `Θ`. Solm tracks neither gas nor the - -- substate, so — exactly as `callGas` is already existential — the *entire* input - -- substate `A_in` is existentially quantified: the call "behaves as `Θ` would for some - -- gas and substate". (The result substate `A'` is discarded; `execResultsEquiv` ignores - -- it.) `g'` is the (discarded) returned gas; named so it is a plain implicit. - (cA', σ', g', A', z, o) - = Ethereum.EVM.Θ - evm.executionEnv.blobVersionedHashes - evm.createdAccounts - evm.genesisBlockHeader - evm.blocks - evm.accountMap - evm.σ₀ - A_in - evm.executionEnv.codeOwner -- sender (msg.sender): `this`, as a CALL does - evm.executionEnv.sender -- original transactor (tx.origin) - target - (Ethereum.toExecute evm.accountMap target) -- this is the code - callGas - (.ofNat evm.executionEnv.gasPrice) - valueWord -- actual value sent - valueWord -- value reported to queries - calldata - (evm.executionEnv.depth + 1) - evm.executionEnv.header - perm -- permission to modify state; - -- true for call/delegatecall/callcode, false for staticcall - ) - - -- let machine := -- We don't track machine state anyway - -- { evm.machineState with - -- gasAvailable := evm.machineState.gasAvailable + g' -- is this correct? - -- returnData := o } - → evm' = { evm with accountMap := σ', substate := A', createdAccounts := cA' } - - → valueWord ≤ (evm.accountMap.find? evm.executionEnv.codeOwner |>.elim ⟨0⟩ (·.balance)) - → evm.executionEnv.depth ≠ 1024 - → callViaEVM evm target value calldata (z, evm', o) perm - - | callNotMade : - A' = ((evm.addAccessedAccount target) |>.substate ) - → evm' = { evm with substate := A' } - → (¬ (EVM.wordOfInt value ≤ (evm.accountMap.find? evm.executionEnv.codeOwner |>.elim ⟨0⟩ (·.balance)) - ∧ evm.executionEnv.depth ≠ 1024)) - → callViaEVM evm target value calldata (false, evm', ByteArray.empty) perm - -/-- A raw `DELEGATECALL` to `target` with verbatim `calldata`, bridged directly to EVM `Θ`. - Delegatecall executes the target's code in the current contract's context: `address(this)` and - storage owner stay `codeOwner`, `msg.sender` and `msg.value` are preserved, no ETH is - transferred, and the current static permission bit is preserved. -/ -inductive delegateCallViaEVM (evm : EVM.State) (target : EVM.Address) - (calldata : EVM.Bytes) : (Bool × EVM.State × EVM.Bytes) → Prop where - | callMade : - (∃ (callGas : Ethereum.UInt256) (A_in : Ethereum.Substate), - (cA', σ', g', A', z, o) - = Ethereum.EVM.Θ - evm.executionEnv.blobVersionedHashes - evm.createdAccounts - evm.genesisBlockHeader - evm.blocks - evm.accountMap - evm.σ₀ - A_in - evm.executionEnv.source - evm.executionEnv.sender - evm.executionEnv.codeOwner - (Ethereum.toExecute evm.accountMap target) - callGas - (.ofNat evm.executionEnv.gasPrice) - (⟨0⟩ : EVM.Word) - evm.executionEnv.weiValue - calldata - (evm.executionEnv.depth + 1) - evm.executionEnv.header - evm.executionEnv.perm) - → evm' = { evm with accountMap := σ', substate := A', createdAccounts := cA' } - → evm.executionEnv.depth ≠ 1024 - → delegateCallViaEVM evm target calldata (z, evm', o) - | callNotMade : - A' = ((evm.addAccessedAccount target) |>.substate) - → evm' = { evm with substate := A' } - → evm.executionEnv.depth = 1024 - → delegateCallViaEVM evm target calldata (false, evm', ByteArray.empty) - -/-- A typed external call: ABI-encode `name`/`args` into calldata, then make a raw `callViaEVM`. - This is the call form `externalCall` uses. The return *decode* (and its failure) stays in the - `ExecStmt` rules over the raw output bytes `o`, so decode-failure handling is unchanged. -/ -def typedCallViaEVM (cfg : Config) (evm : EVM.State) (target : EVM.Address) - (name : Ident) (value : ℤ) (args : List Value) - (result : Bool × EVM.State × EVM.Bytes) (perm : Bool := true) : Prop := - ∃ calldata, cfg.externalABI.encode? name args = some calldata - ∧ callViaEVM evm target value calldata result perm - --- Contract creation (`new`) via the EVM `Λ` (Lambda) function. The result triple is --- `(addr, evm', success)`: the created contract's address, the resulting EVM state, --- and whether creation succeeded. Mirrors `externalCallViaEVM`, but `Λ` runs the --- initialisation code instead of a message call and returns the new address. --- TODO Lefteris check - --- Preconditions under which a `new` (the `CREATE` opcode) actually runs the init code, --- mirroring the guards the opcode checks before calling `Lambda`. -def newCanCreate (evm : EVM.State) (value : ℤ) (initCode : EVM.Bytes) : Prop := - let creator := evm.accountMap.find? evm.executionEnv.codeOwner |>.getD default - EVM.wordOfInt value ≤ creator.balance -- creator can afford the endowment - ∧ evm.executionEnv.depth ≠ 1024 -- call-depth limit not reached - ∧ creator.nonce.toNat < 2 ^ 64 - 1 -- creator nonce below the cap (EIP-2681) - ∧ initCode.size ≤ 49152 -- init code within the limit (EIP-3860) - -inductive newViaEVM (cfg : Config) (evm : EVM.State) - (name : Ident) (value : ℤ) (args : List Value) (salt : Option ByteArray) : - (EVM.Address × EVM.State × Bool) → Prop where - | created : - cfg.creationCode name args = .some initCode - → newCanCreate evm value initCode - → valueWord = EVM.wordOfInt value - → (∃ createGas refunds accessedStorageKeys, - -- As in `externalCallViaEVM`, existentially quantify over substate fields - -- whose value we do not track accurately but which creation can change. - let A_exist := { evm.substate with - refundBalance := refunds - accessedStorageKeys := accessedStorageKeys } - -- Mirror the CREATE opcode: bump the creator's nonce before calling `Lambda`, - -- which derives the new address from `sender.nonce - 1` and so expects the - -- already-incremented nonce. - let creator := evm.accountMap.find? evm.executionEnv.codeOwner |>.getD default - let σStar := evm.accountMap.insert evm.executionEnv.codeOwner - { creator with nonce := creator.nonce + ⟨1⟩ } - (addr, cA', σ', _, A', z, _) - = Ethereum.EVM.Lambda - evm.executionEnv.blobVersionedHashes - evm.createdAccounts - evm.genesisBlockHeader - evm.blocks - σStar - evm.σ₀ - A_exist - evm.executionEnv.codeOwner -- sender (msg.sender): `this`, as CREATE does - evm.executionEnv.sender -- original transactor (tx.origin) - createGas - (.ofNat evm.executionEnv.gasPrice) - valueWord -- endowment - initCode -- initialisation EVM code - (evm.executionEnv.depth + 1) - salt -- `none` ⇒ CREATE; `some s` ⇒ CREATE2 with salt `s` - evm.executionEnv.header - true) -- permission to modify state - → evm' = { evm with accountMap := σ', substate := A', createdAccounts := cA' } - → newViaEVM cfg evm name value args salt (addr, evm', z) - | notCreated : - cfg.creationCode name args = .some initCode - → ¬ newCanCreate evm value initCode - → newViaEVM cfg evm name value args salt (EVM.address 0, evm, false) - - -/-- Collapse a callee's returned list into the single value bound to a call's result identifier. - This `Value.tuple` is internal-call plumbing only — it is never ABI-encoded; the ABI boundary is - transitions, which use the return list directly. -/ -def collapseReturns : List Value → Value - | [] => .unit - | [v] => v - | vs => .tuple vs - -def resumeAfterInternalCall (caller : Frame) (retVar : Ident) (value : Option (List Value)) : - Frame := - let valueToWrite := match value with - | none => .unit - | some vs => collapseReturns vs - { caller with locals := caller.locals.insert retVar valueToWrite } - -/-- `arr.push(v?)`: grow the dynamic array named by `ref` by one. Reads the current length `L` - (the layout's `.length` query), stores length `L+1`, then `some v` writes the value at element - `L` via `writeStorage?`. Writing the length first mirrors solc's generated storage order and - also makes the new index in-bounds for the ordinary storage writer. `none` is a grow-only push - (the new slots are already zero by storage default). `.revert`s only if evaluating the array ref - does. It `.error`s (a stuck, ill-formed program) when the target isn't a dynamic array, the - layout has no `.length`/element slot for it, the length slot doesn't hold an integer, or a - compound value's shape doesn't match the element type — i.e. for a well-formed layout + matching - value, `.revert` is the only non-`.ok` outcome. -/ -def pushArray? (cfg : Config) (solm : Frame) (evm : EVM.State) (ref : StorageRef) - (value : Option Value) : EvalResult EVM.State := do - let (er, ty) <- resolveStorageRef? cfg solm evm ref - match ty with - | .dynamicArray elemTy => do - let lenLoc <- EvalResult.ofOption .storageError - (cfg.storage.layout { er with steps := er.steps ++ [.length] } evm) - match storageLocLoad evm lenLoc with - | .int len => do - let evmLen <- EvalResult.ofOption .storageError (storageLocStore evm lenLoc (.int (len + 1))) - match value with - | some v => - writeStorage? cfg evmLen - { er with steps := er.steps ++ [.aindex (.int len)] } elemTy v - | none => pure evmLen - | _ => .error .storageError - -- `bytes`/`string` push: read-modify-write the whole value through the layout hooks (they handle - -- short↔long transitions). Arg-less appends a zero byte; else a `bytes1` (`fixedBytes ⟨0,_⟩`). - | .bytes | .string => do - match (← readStorage? cfg evm er ty) with - | .bytes ba => - match value with - | none => writeStorage? cfg evm er ty (.bytes (ba.push 0)) - | some (.fixedBytes n bs) => - if n.val = 0 ∧ bs.length = 1 then - writeStorage? cfg evm er ty (.bytes (ba ++ ByteArray.mk bs.toArray)) - else .error .typeError - | some _ => .error .typeError - | _ => .error .storageError - | _ => .error .storageError - -/-- `arr.pop()`: remove the last element of the dynamic array named by `ref`. Reverts when the - array is empty (solc's `Panic(0x31)`). Otherwise recursively clears the whole last element - (per its declared type, via `clearStorage?` — so nested arrays/structs are fully zeroed) and - sets the length to `L-1`. -/ -def popArray? (cfg : Config) (solm : Frame) (evm : EVM.State) (ref : StorageRef) - : EvalResult EVM.State := do - let (er, ty) <- resolveStorageRef? cfg solm evm ref - match ty with - | .dynamicArray elemTy => do - let lenLoc <- EvalResult.ofOption .storageError - (cfg.storage.layout { er with steps := er.steps ++ [.length] } evm) - match storageLocLoad evm lenLoc with - | .int len => - if len ≤ 0 then .revert - else do - let evm1 <- clearStorage? cfg evm - { er with steps := er.steps ++ [.aindex (.int (len - 1))] } elemTy - EvalResult.ofOption .storageError (storageLocStore evm1 lenLoc (.int (len - 1))) - | _ => .error .storageError - -- `bytes`/`string` pop: read-modify-write; empty → revert (solc `Panic(0x31)`). - | .bytes | .string => do - match (← readStorage? cfg evm er ty) with - | .bytes ba => - if ba.size = 0 then .revert - else writeStorage? cfg evm er ty (.bytes (ba.extract 0 (ba.size - 1))) - | _ => .error .storageError - | _ => .error .storageError - -/-- `delete x`: reset the storage at `ref` to its zero value, recursively per its declared type - (`clearStorage?` — a dynamic array becomes empty, a struct/array is fully zeroed). `.revert`s - only if evaluating the ref does; `.error`s on an ill-formed layout/type. -/ -def deleteStorage? (cfg : Config) (solm : Frame) (evm : EVM.State) (ref : StorageRef) - : EvalResult EVM.State := do - let (er, ty) <- resolveStorageRef? cfg solm evm ref - clearStorage? cfg evm er ty - --- Evaluate a `new`'s optional salt: `none` ⇒ CREATE; `some e` must be a `bytes32` ⇒ CREATE2. -def evalSalt? (cfg : Config) (solm : Frame) (evm : EVM.State) : - Option Expr → EvalResult (Option ByteArray) - | none => .ok none - | some e => do - let v <- evalExpr? cfg solm evm e - match saltBytes? v with - | some b => .ok (some b) - | none => .error .typeError - -mutual - -inductive ExecStmt (cfg : Config) : - Frame -> EVM.State -> Stmt -> ExecResult -> Prop where - | letDecl : - evalExpr? cfg solm evm expr = .ok value -> - ExecStmt cfg solm evm (.letDecl name ty expr) - (.ok { solm with locals := solm.locals.insert name value } evm) - | letDeclRevert : - evalExpr? cfg solm evm expr = .revert -> - ExecStmt cfg solm evm (.letDecl name ty expr) .reverted - | letStorage : - resolveStorageRef? cfg solm evm ref = .ok (er, ty) -> - ExecStmt cfg solm evm (.letStorage name ref) - (.ok { solm with locals := solm.locals.insert name (.storageRef er ty) } evm) - | letStorageRevert : - resolveStorageRef? cfg solm evm ref = .revert -> - ExecStmt cfg solm evm (.letStorage name ref) .reverted - -- `gasleft()`: Solm tracks no gas, so any word `w` is a legal result. A proof picks the `w` - -- matching the EVM's actual gas at the corresponding `GAS` opcode. - | letGas (w : EVM.Word) : - ExecStmt cfg solm evm (.letGas name) - (.ok { solm with locals := solm.locals.insert name (.int (Int.ofNat w.toNat)) } evm) - | assign : - evalExpr? cfg solm evm expr = .ok value -> - assignStorageRef? cfg solm evm origin slot value = .ok (solm', evm') -> - ExecStmt cfg solm evm (.assign origin slot expr) (.ok solm' evm') - | assignExprRevert : - evalExpr? cfg solm evm expr = .revert -> - ExecStmt cfg solm evm (.assign origin slot expr) .reverted - | assignStoreRevert : - evalExpr? cfg solm evm expr = .ok value -> - assignStorageRef? cfg solm evm origin slot value = .revert -> - ExecStmt cfg solm evm (.assign origin slot expr) .reverted - | pushVal : - evalExpr? cfg solm evm expr = .ok value -> - pushArray? cfg solm evm ref (some value) = .ok evm' -> - ExecStmt cfg solm evm (.push ref (some expr)) (.ok solm evm') - | pushValExprRevert : - evalExpr? cfg solm evm expr = .revert -> - ExecStmt cfg solm evm (.push ref (some expr)) .reverted - | pushValStoreRevert : - evalExpr? cfg solm evm expr = .ok value -> - pushArray? cfg solm evm ref (some value) = .revert -> - ExecStmt cfg solm evm (.push ref (some expr)) .reverted - | pushGrow : - pushArray? cfg solm evm ref none = .ok evm' -> - ExecStmt cfg solm evm (.push ref none) (.ok solm evm') - | pushGrowRevert : - pushArray? cfg solm evm ref none = .revert -> - ExecStmt cfg solm evm (.push ref none) .reverted - | pop : - popArray? cfg solm evm ref = .ok evm' -> - ExecStmt cfg solm evm (.pop ref) (.ok solm evm') - | popRevert : - popArray? cfg solm evm ref = .revert -> - ExecStmt cfg solm evm (.pop ref) .reverted - | delete : - deleteStorage? cfg solm evm ref = .ok evm' -> - ExecStmt cfg solm evm (.delete ref) (.ok solm evm') - | deleteRevert : - deleteStorage? cfg solm evm ref = .revert -> - ExecStmt cfg solm evm (.delete ref) .reverted - | requireTrue {condExpr} : - evalExpr? cfg solm evm condExpr = .ok (.bool true) -> - ExecStmt cfg solm evm (.require condExpr) (.ok solm evm) - | requireFalse {condExpr} : - evalExpr? cfg solm evm condExpr = .ok (.bool false) -> - ExecStmt cfg solm evm (.require condExpr) .reverted - | requireRevert {condExpr} : - evalExpr? cfg solm evm condExpr = .revert -> - ExecStmt cfg solm evm (.require condExpr) .reverted - | whileFalse {condExpr} : - evalExpr? cfg solm evm condExpr = .ok (.bool false) -> - ExecStmt cfg solm evm (.while condExpr body) (.ok solm evm) - | whileCondRevert {condExpr} : - evalExpr? cfg solm evm condExpr = .revert -> - ExecStmt cfg solm evm (.while condExpr body) .reverted - | whileTrue {condExpr} : - evalExpr? cfg solm evm condExpr = .ok (.bool true) -> - ExecBlock cfg solm evm body (.ok solm' evm') -> - ExecStmt cfg solm' evm' (.while condExpr body) result -> - ExecStmt cfg solm evm (.while condExpr body) result - | whileReturn {condExpr} : - evalExpr? cfg solm evm condExpr = .ok (.bool true) -> - ExecBlock cfg solm evm body (.returned solm' evm' value) -> - ExecStmt cfg solm evm (.while condExpr body) (.returned solm' evm' value) - | whileRevert {condExpr} : - evalExpr? cfg solm evm condExpr = .ok (.bool true) -> - ExecBlock cfg solm evm body .reverted -> - ExecStmt cfg solm evm (.while condExpr body) .reverted - | whileBreak {condExpr} : - evalExpr? cfg solm evm condExpr = .ok (.bool true) -> - ExecBlock cfg solm evm body (.break solm' evm') -> - ExecStmt cfg solm evm (.while condExpr body) (.ok solm' evm') - | whileContinue {condExpr} : - evalExpr? cfg solm evm condExpr = .ok (.bool true) -> - ExecBlock cfg solm evm body (.continue solm' evm') -> - ExecStmt cfg solm' evm' (.while condExpr body) result -> - ExecStmt cfg solm evm (.while condExpr body) result - -- `for (init; cond; post) { body }`: run `init` once, then loop via `ExecForLoop`. - | for : - ExecBlock cfg solm evm init (.ok solm1 evm1) -> - ExecForLoop cfg solm1 evm1 condExpr post body result -> - ExecStmt cfg solm evm (.for init condExpr post body) result - | forInitReturn : - ExecBlock cfg solm evm init (.returned solm1 evm1 value) -> - ExecStmt cfg solm evm (.for init condExpr post body) (.returned solm1 evm1 value) - | forInitRevert : - ExecBlock cfg solm evm init .reverted -> - ExecStmt cfg solm evm (.for init condExpr post body) .reverted - | iteTrue {condExpr} : - evalExpr? cfg solm evm condExpr = .ok (.bool true) -> - ExecBlock cfg solm evm thenB result -> - ExecStmt cfg solm evm (.ite condExpr thenB elseB) result - | iteFalse {condExpr} : - evalExpr? cfg solm evm condExpr = .ok (.bool false) -> - ExecBlock cfg solm evm elseB result -> - ExecStmt cfg solm evm (.ite condExpr thenB elseB) result - | iteCondRevert {condExpr} : - evalExpr? cfg solm evm condExpr = .revert -> - ExecStmt cfg solm evm (.ite condExpr thenB elseB) .reverted - | internalCallReturn : - evalExprs? cfg solm evm args = .ok argVals -> - lookupCallable? solm.contract name = some callee -> - bindParams? callee.params argVals = some locals -> - ExecFuncBody cfg { solm with locals := locals } evm callee.body - (.returned calleeSolm calleeEvm value) -> - ExecStmt cfg solm evm (.internalCall name args retVar) - (.ok (resumeAfterInternalCall solm retVar value) calleeEvm) - | internalCallRevert : - evalExprs? cfg solm evm args = .ok argVals -> - lookupCallable? solm.contract name = some callee -> - bindParams? callee.params argVals = some locals -> - ExecFuncBody cfg { solm with locals := locals } evm callee.body .reverted -> - ExecStmt cfg solm evm (.internalCall name args retVar) .reverted - | internalCallArgsRevert : - evalExprs? cfg solm evm args = .revert -> - ExecStmt cfg solm evm (.internalCall name args retVar) .reverted - | externalCallSuccess : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .ok (.int sendVal) -> - evalExprs? cfg solm evm args = .ok argVals -> - typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals - (true, evm', out) perm -> - cfg.externalABI.decode? name out = some value -> - ExecStmt cfg solm evm (.externalCall receiver name eth args retVar (perm := perm)) - (.ok { solm with locals := solm.locals.insert retVar (collapseReturns value) } evm') - | externalCallFailure : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .ok (.int sendVal) -> - evalExprs? cfg solm evm args = .ok argVals -> - typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals - (false, evm', out) perm -> - ExecStmt cfg solm evm (.externalCall receiver name eth args retVar (perm := perm)) .reverted - | externalCallReturnDecodeRevert : - -- The sub-call *succeeds* (`z = true`) but the returned bytes do not ABI-decode to the - -- expected return value (`decode? = none`). The caller's solc-generated return decoder then - -- reverts (`if slt(returndatasize, 32) { revert }`), so the whole statement reverts. - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .ok (.int sendVal) -> - evalExprs? cfg solm evm args = .ok argVals -> - typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals - (true, evm', out) perm -> - cfg.externalABI.decode? name out = none -> - ExecStmt cfg solm evm (.externalCall receiver name eth args retVar (perm := perm)) .reverted - | externalCallReceiverRevert : - evalExpr? cfg solm evm receiver = .revert -> - ExecStmt cfg solm evm (.externalCall receiver name eth args retVar (perm := perm)) .reverted - | externalCallSendRevert : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .revert -> - ExecStmt cfg solm evm (.externalCall receiver name eth args retVar (perm := perm)) .reverted - | externalCallArgsRevert : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .ok (.int sendVal) -> - evalExprs? cfg solm evm args = .revert -> - ExecStmt cfg solm evm (.externalCall receiver name eth args retVar (perm := perm)) .reverted - | lowLevelCallSuccess : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .ok (.int sendVal) -> - evalExpr? cfg solm evm cdata = .ok (.bytes calldata) -> - callViaEVM evm (EVM.address target) sendVal calldata (true, evm', out) perm -> - ExecStmt cfg solm evm (.lowLevelCall receiver eth cdata okVar dataVar (perm := perm)) - (.ok { solm with locals := (solm.locals.insert okVar (.bool true)).insert dataVar (.bytes out) } evm') - | lowLevelCallFailure : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .ok (.int sendVal) -> - evalExpr? cfg solm evm cdata = .ok (.bytes calldata) -> - callViaEVM evm (EVM.address target) sendVal calldata (false, evm', out) perm -> - ExecStmt cfg solm evm (.lowLevelCall receiver eth cdata okVar dataVar (perm := perm)) - (.ok { solm with locals := (solm.locals.insert okVar (.bool false)).insert dataVar (.bytes out) } evm') - | lowLevelCallReceiverRevert : - evalExpr? cfg solm evm receiver = .revert -> - ExecStmt cfg solm evm (.lowLevelCall receiver eth cdata okVar dataVar (perm := perm)) .reverted - | lowLevelCallSendRevert : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .revert -> - ExecStmt cfg solm evm (.lowLevelCall receiver eth cdata okVar dataVar (perm := perm)) .reverted - | lowLevelCallDataRevert : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .ok (.int sendVal) -> - evalExpr? cfg solm evm cdata = .revert -> - ExecStmt cfg solm evm (.lowLevelCall receiver eth cdata okVar dataVar (perm := perm)) .reverted - | delegateCallSuccess : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm cdata = .ok (.bytes calldata) -> - delegateCallViaEVM evm (EVM.address target) calldata (true, evm', out) -> - ExecStmt cfg solm evm (.delegateCall receiver cdata okVar dataVar) - (.ok - { solm with - locals := (solm.locals.insert okVar (.bool true)).insert dataVar (.bytes out) } - evm') - | delegateCallFailure : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm cdata = .ok (.bytes calldata) -> - delegateCallViaEVM evm (EVM.address target) calldata (false, evm', out) -> - ExecStmt cfg solm evm (.delegateCall receiver cdata okVar dataVar) - (.ok - { solm with - locals := (solm.locals.insert okVar (.bool false)).insert dataVar (.bytes out) } - evm') - | delegateCallReceiverRevert : - evalExpr? cfg solm evm receiver = .revert -> - ExecStmt cfg solm evm (.delegateCall receiver cdata okVar dataVar) .reverted - | delegateCallDataRevert : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm cdata = .revert -> - ExecStmt cfg solm evm (.delegateCall receiver cdata okVar dataVar) .reverted - | checkedCallSuccess : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .ok (.int sendVal) -> - evalExprs? cfg solm evm args = .ok argVals -> - typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals - (true, evm', out) perm -> - cfg.externalABI.decode? name out = some value -> - ExecBlock cfg { solm with locals := solm.locals.insert retVar (collapseReturns value) } evm' onSuccess result -> - ExecStmt cfg solm evm - (.checkedCall receiver name eth args retVar onSuccess errVar onFail (perm := perm)) result - | checkedCallFail : - -- callee reverted: bind the raw returndata to `errVar` and run `onFail`. The per-contract spec - -- decides there (via `ite` on `errVar`) whether to recover or re-revert (`require false`). - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .ok (.int sendVal) -> - evalExprs? cfg solm evm args = .ok argVals -> - typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals - (false, evm', out) perm -> - ExecBlock cfg { solm with locals := solm.locals.insert errVar (.bytes out) } evm' onFail result -> - ExecStmt cfg solm evm - (.checkedCall receiver name eth args retVar onSuccess errVar onFail (perm := perm)) result - | checkedCallReturnDecodeRevert : - -- Call succeeds but returndata doesn't ABI-decode (`decode? = none`, e.g. codeless callee): - -- solc's return decoder reverts *uncaught* (never enters `onFail`). Cf. externalCall twin. - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .ok (.int sendVal) -> - evalExprs? cfg solm evm args = .ok argVals -> - typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals - (true, evm', out) perm -> - cfg.externalABI.decode? name out = none -> - ExecStmt cfg solm evm - (.checkedCall receiver name eth args retVar onSuccess errVar onFail (perm := perm)) .reverted - | checkedCallReceiverRevert : - evalExpr? cfg solm evm receiver = .revert -> - ExecStmt cfg solm evm - (.checkedCall receiver name eth args retVar onSuccess errVar onFail (perm := perm)) .reverted - | checkedCallSendRevert : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .revert -> - ExecStmt cfg solm evm - (.checkedCall receiver name eth args retVar onSuccess errVar onFail (perm := perm)) .reverted - | checkedCallArgsRevert : - evalExpr? cfg solm evm receiver = .ok (.address target) -> - evalExpr? cfg solm evm eth = .ok (.int sendVal) -> - evalExprs? cfg solm evm args = .revert -> - ExecStmt cfg solm evm - (.checkedCall receiver name eth args retVar onSuccess errVar onFail (perm := perm)) .reverted - | newSuccess : - evalExpr? cfg solm evm valExpr = .ok (.int sendVal) -> - evalExprs? cfg solm evm args = .ok argVals -> - evalSalt? cfg solm evm salt = .ok saltBytes -> - newViaEVM cfg evm name sendVal argVals saltBytes (addr, evm', true) -> - ExecStmt cfg solm evm (.new name valExpr args retVar salt) - (.ok { solm with locals := solm.locals.insert retVar (.address addr) } evm') - | newRevert : - -- A failed creation reverts the caller, unlike a low-level external call. - evalExpr? cfg solm evm valExpr = .ok (.int sendVal) -> - evalExprs? cfg solm evm args = .ok argVals -> - evalSalt? cfg solm evm salt = .ok saltBytes -> - newViaEVM cfg evm name sendVal argVals saltBytes (addr, evm', false) -> - ExecStmt cfg solm evm (.new name valExpr args retVar salt) .reverted - | newValueRevert : - evalExpr? cfg solm evm valExpr = .revert -> - ExecStmt cfg solm evm (.new name valExpr args retVar salt) .reverted - | newArgsRevert : - evalExpr? cfg solm evm valExpr = .ok (.int sendVal) -> - evalExprs? cfg solm evm args = .revert -> - ExecStmt cfg solm evm (.new name valExpr args retVar salt) .reverted - | return : - evalExprs? cfg solm evm exprs = .ok values -> - ExecStmt cfg solm evm (.return exprs) (.returned solm evm (some values)) - | returnRevert : - evalExprs? cfg solm evm exprs = .revert -> - ExecStmt cfg solm evm (.return exprs) .reverted - | break : - ExecStmt cfg solm evm .break (.break solm evm) - | continue : - ExecStmt cfg solm evm .continue (.continue solm evm) - -/-- The loop part of a `for (init; cond; post) { body }`, after `init` has run. Each iteration - checks `cond`; on `true` it runs `body` then `post` and loops. A `break` in `body` exits the - loop with `.ok` (skipping `post`); a `continue` runs `post` and loops; `return`/`revert` - propagate. `post` may only fall through (`.ok`) or revert. -/ -inductive ExecForLoop (cfg : Config) : - Frame -> EVM.State -> Expr /- cond -/ -> List Stmt /- post -/ -> List Stmt /- body -/ -> - ExecResult -> Prop where - | falseDone {condExpr} : - evalExpr? cfg solm evm condExpr =.ok (.bool false) -> - ExecForLoop cfg solm evm condExpr post body (.ok solm evm) - | condRevert {condExpr} : - evalExpr? cfg solm evm condExpr =.revert -> - ExecForLoop cfg solm evm condExpr post body .reverted - | bodyReturn {condExpr} : - evalExpr? cfg solm evm condExpr =.ok (.bool true) -> - ExecBlock cfg solm evm body (.returned solm' evm' value) -> - ExecForLoop cfg solm evm condExpr post body (.returned solm' evm' value) - | bodyRevert {condExpr} : - evalExpr? cfg solm evm condExpr =.ok (.bool true) -> - ExecBlock cfg solm evm body .reverted -> - ExecForLoop cfg solm evm condExpr post body .reverted - | bodyBreak {condExpr} : - evalExpr? cfg solm evm condExpr =.ok (.bool true) -> - ExecBlock cfg solm evm body (.break solm' evm') -> - ExecForLoop cfg solm evm condExpr post body (.ok solm' evm') - | iterate {condExpr} : - evalExpr? cfg solm evm condExpr =.ok (.bool true) -> - ExecBlock cfg solm evm body (.ok solm1 evm1) -> - ExecBlock cfg solm1 evm1 post (.ok solm2 evm2) -> - ExecForLoop cfg solm2 evm2 condExpr post body result -> - ExecForLoop cfg solm evm condExpr post body result - | iteratePostRevert {condExpr} : - evalExpr? cfg solm evm condExpr =.ok (.bool true) -> - ExecBlock cfg solm evm body (.ok solm1 evm1) -> - ExecBlock cfg solm1 evm1 post .reverted -> - ExecForLoop cfg solm evm condExpr post body .reverted - | continueIter {condExpr} : - evalExpr? cfg solm evm condExpr =.ok (.bool true) -> - ExecBlock cfg solm evm body (.continue solm1 evm1) -> - ExecBlock cfg solm1 evm1 post (.ok solm2 evm2) -> - ExecForLoop cfg solm2 evm2 condExpr post body result -> - ExecForLoop cfg solm evm condExpr post body result - | continuePostRevert {condExpr} : - evalExpr? cfg solm evm condExpr =.ok (.bool true) -> - ExecBlock cfg solm evm body (.continue solm1 evm1) -> - ExecBlock cfg solm1 evm1 post .reverted -> - ExecForLoop cfg solm evm condExpr post body .reverted - -inductive ExecBlock (cfg : Config) : - Frame -> EVM.State -> List Stmt -> ExecResult -> Prop where - | nil : - ExecBlock cfg solm evm [] (.ok solm evm) - | consNormal : - ExecStmt cfg solm evm stmt (.ok solm' evm') -> - ExecBlock cfg solm' evm' stmts result -> - ExecBlock cfg solm evm (stmt :: stmts) result - | consReturn : - ExecStmt cfg solm evm stmt (.returned solm' evm' value) -> - ExecBlock cfg solm evm (stmt :: stmts) (.returned solm' evm' value) - | consRevert : - ExecStmt cfg solm evm stmt .reverted -> - ExecBlock cfg solm evm (stmt :: stmts) .reverted - | consBreak : - ExecStmt cfg solm evm stmt (.break solm' evm') -> - ExecBlock cfg solm evm (stmt :: stmts) (.break solm' evm') - | consContinue : - ExecStmt cfg solm evm stmt (.continue solm' evm') -> - ExecBlock cfg solm evm (stmt :: stmts) (.continue solm' evm') - -inductive ExecFuncBody (cfg : Config) : - Frame -> EVM.State -> List Stmt -> ExecResult -> Prop where - | execBlockOK : - ExecBlock cfg solm evm body (.ok solm' evm') -> - ExecFuncBody cfg solm evm body (.returned solm' evm' none) - | execBlockRet : - ExecBlock cfg solm evm body (.returned solm' evm' value) -> - ExecFuncBody cfg solm evm body (.returned solm' evm' value) - | execBlockRevert : - ExecBlock cfg solm evm body .reverted -> - ExecFuncBody cfg solm evm body .reverted - -- A `break`/`continue` that occurs outside a loop is malformed. We have to handle it so that ExecFuncBody is never stuck. - | execBlockBreak : - ExecBlock cfg solm evm body (.break solm' evm') -> - ExecFuncBody cfg solm evm body (.returned solm' evm' none) - | execBlockContinue : - ExecBlock cfg solm evm body (.continue solm' evm') -> - ExecFuncBody cfg solm evm body (.returned solm' evm' none) - -end - -def ExecTransitionBody (cfg : Config) (contract : ContractDecl) (evm : EVM.State) - (locals : Store) (body : Body) (result : ExecResult) : Prop := - ExecFuncBody cfg { contract := contract, locals := locals } evm body result - --- Solm transaction dispatch and execution. -inductive solmExec - (conf : Config) - (contract : ContractDecl) /- Spec -/ - (createdAccounts : Batteries.RBSet Ethereum.AccountAddress compare) - (genesisBlockHeader : Ethereum.BlockHeader) - (blocks : Ethereum.ProcessedBlocks) - (σ : Ethereum.AccountMap) - (σ₀ : Ethereum.AccountMap) - (g : Ethereum.UInt256) - (A : Ethereum.Substate) - (I : Ethereum.ExecutionEnv) - (solmRes : ExecResult) -: ReturnConvention -> Prop where - | intro : - /- Solm selector transition dispatch. -/ - selectorDispatchMsg contract I.calldata = .some transition → - transitionSig = transitionSignature transition → - decodeCalldataWithMode conf.abiDecodeMode (transition.params.map Param.name) - transitionSig.paramTypes I.calldata = .some callargs → - evmState = - { (default : EVM.State) with - accountMap := σ - σ₀ := σ₀ - executionEnv := I - substate := A - createdAccounts := createdAccounts - machineState.gasAvailable := .ofUInt256 g - blocks := blocks - genesisBlockHeader := genesisBlockHeader - } → - ExecTransitionBody conf contract evmState callargs transition.body solmRes → - solmExec conf contract createdAccounts genesisBlockHeader blocks σ σ₀ g A I solmRes - (.abi transition.returnType) - | fallback : - /- Solidity fallback dispatch has no selector or ABI argument decoding. -/ - selectorDispatchMsg contract I.calldata = .none → - receiveDispatchMsg contract I.calldata = .none → - contract.fallback = .some transition → - fallbackCallargs I.calldata transition.params = some callargs → - fallbackReturnConvention transition = some returnConvention → - evmState = - { (default : EVM.State) with - accountMap := σ - σ₀ := σ₀ - executionEnv := I - substate := A - createdAccounts := createdAccounts - machineState.gasAvailable := .ofUInt256 g - blocks := blocks - genesisBlockHeader := genesisBlockHeader - } → - ExecTransitionBody conf contract evmState callargs transition.body solmRes → - solmExec conf contract createdAccounts genesisBlockHeader blocks σ σ₀ g A I solmRes - returnConvention - | receive : - /- Solidity receive dispatch has no selector or ABI argument decoding. -/ - receiveDispatchMsg contract I.calldata = .some transition → - transition.params = [] → - transition.returnType = [] → - evmState = - { (default : EVM.State) with - accountMap := σ - σ₀ := σ₀ - executionEnv := I - substate := A - createdAccounts := createdAccounts - machineState.gasAvailable := .ofUInt256 g - blocks := blocks - genesisBlockHeader := genesisBlockHeader - } → - ExecTransitionBody conf contract evmState ∅ transition.body solmRes → - solmExec conf contract createdAccounts genesisBlockHeader blocks σ σ₀ g A I solmRes (.abi []) - --- Solm constructor execution. -inductive solmCtorExec - (conf : Config) - (contract : ContractDecl) /- Spec -/ - (args : List Value) - (createdAccounts : Batteries.RBSet Ethereum.AccountAddress compare) - (genesisBlockHeader : Ethereum.BlockHeader) - (blocks : Ethereum.ProcessedBlocks) - (σ : Ethereum.AccountMap) - (σ₀ : Ethereum.AccountMap) - (g : Ethereum.UInt256) - (A : Ethereum.Substate) - (I : Ethereum.ExecutionEnv) - (solmRes : ExecResult) -: Prop where - | intro : - evmState = - { (default : EVM.State) with - accountMap := σ - σ₀ := σ₀ - executionEnv := I - substate := A - createdAccounts := createdAccounts - machineState.gasAvailable := .ofUInt256 g - blocks := blocks - genesisBlockHeader := genesisBlockHeader - } → - -- This may be redundant when `cfg.selfDeployment` already enforces valid constructor ABI - -- encoding, but it keeps the parameter store from relying on `List.zip` truncation. - args.length = contract.ctor.params.length → - argsStore = Std.HashMap.ofList (List.zip (contract.ctor.params.map Param.name) args) → - ExecTransitionBody conf contract evmState argsStore contract.ctor.body solmRes → - solmCtorExec conf contract args createdAccounts genesisBlockHeader blocks σ σ₀ g A I solmRes +import Solm.Semantics.Types +import Solm.Semantics.Dispatch +import Solm.Semantics.ValueOps +import Solm.Semantics.StorageOps +import Solm.Semantics.Eval +import Solm.Semantics.Calls +import Solm.Semantics.Exec diff --git a/Solm/Semantics/Calls.lean b/Solm/Semantics/Calls.lean new file mode 100644 index 00000000..8a37f285 --- /dev/null +++ b/Solm/Semantics/Calls.lean @@ -0,0 +1,195 @@ +import Solm.Semantics.Types + +/-! EVM bridges for external calls and contract creation (`Θ`/`Λ`). -/ + +namespace Solm + +open ABI + +def externalValueToWord? : Value -> Option EVM.Word + | .int i => some (EVM.wordOfInt i) + | .bool b => some b.toUInt256 + | .address a => some (EVM.word a) + | .unit => some ⟨0⟩ + | _ => none + +def wordsOfValues? (values : List Value) : Option (List EVM.Word) := + match values with + | [] => some [] + | value :: rest => do + let word <- externalValueToWord? value + let words <- wordsOfValues? rest + some (word :: words) + +def defaultEncodeCall? (_name : Ident) (args : List Value) : Option EVM.Bytes := do + let words <- wordsOfValues? args + some (words.foldl (fun bytes word => bytes ++ (Ethereum.UInt256.toByteArray word)) ByteArray.empty) + +def defaultDecodeReturn? (_name : Ident) (bytes : EVM.Bytes) : Option (List Value) := + -- Default typed external calls expect one `uint256` return word. The ABI decoder models solc's + -- generated signed-size guard, so under-length and huge return data both decode to `none`. + ABI.decodeReturnValues? [.elem (.int (.uint ⟨256, by decide⟩))] bytes + +def defaultExternalCallABI : ExternalCallABI := + { encode? := defaultEncodeCall?, decode? := defaultDecodeReturn? } + +/-- A raw message call to `target` with the given `value` and `calldata`, bridged directly to the + EVM `Θ`. No ABI encoding — calldata is supplied verbatim — and the boolean result is the raw + call success flag. The final optional parameter is the callee permission bit passed to `Θ`; + ordinary `CALL` uses the default `true`, while `STATICCALL` uses `false`. Both the low-level + `.call` and (via `typedCallViaEVM`) typed external calls are built on this. -/ +inductive callViaEVM (evm : EVM.State) (target : EVM.Address) + (value : ℤ) (calldata : EVM.Bytes) : + (Bool × EVM.State × EVM.Bytes) → (perm : Bool := true) → Prop where + | callMade : + valueWord = EVM.wordOfInt value + → (∃ (callGas : Ethereum.UInt256) (A_in : Ethereum.Substate), + -- The external call bridges directly to the EVM `Θ`. Solm tracks neither gas nor the + -- substate, so — exactly as `callGas` is already existential — the *entire* input + -- substate `A_in` is existentially quantified: the call "behaves as `Θ` would for some + -- gas and substate". (The result substate `A'` is discarded; `execResultsEquiv` ignores + -- it.) `g'` is the (discarded) returned gas; named so it is a plain implicit. + (cA', σ', g', A', z, o) + = Ethereum.EVM.Θ + evm.executionEnv.blobVersionedHashes + evm.createdAccounts + evm.genesisBlockHeader + evm.blocks + evm.accountMap + evm.σ₀ + A_in + evm.executionEnv.codeOwner -- sender (msg.sender): `this`, as a CALL does + evm.executionEnv.sender -- original transactor (tx.origin) + target + (Ethereum.toExecute evm.accountMap target) -- this is the code + callGas + (.ofNat evm.executionEnv.gasPrice) + valueWord -- actual value sent + valueWord -- value reported to queries + calldata + (evm.executionEnv.depth + 1) + evm.executionEnv.header + perm -- permission to modify state; + -- true for call/delegatecall/callcode, false for staticcall + ) + + → evm' = { evm with accountMap := σ', substate := A', createdAccounts := cA' } + + → valueWord ≤ (evm.accountMap.find? evm.executionEnv.codeOwner |>.elim ⟨0⟩ (·.balance)) + → evm.executionEnv.depth ≠ 1024 + → callViaEVM evm target value calldata (z, evm', o) perm + + | callNotMade : + A' = ((evm.addAccessedAccount target) |>.substate ) + → evm' = { evm with substate := A' } + → (¬ (EVM.wordOfInt value ≤ (evm.accountMap.find? evm.executionEnv.codeOwner |>.elim ⟨0⟩ (·.balance)) + ∧ evm.executionEnv.depth ≠ 1024)) + → callViaEVM evm target value calldata (false, evm', ByteArray.empty) perm + +/-- A raw `DELEGATECALL` to `target` with verbatim `calldata`, bridged directly to EVM `Θ`. + Delegatecall executes the target's code in the current contract's context: `address(this)` and + storage owner stay `codeOwner`, `msg.sender` and `msg.value` are preserved, no ETH is + transferred, and the current static permission bit is preserved. -/ +inductive delegateCallViaEVM (evm : EVM.State) (target : EVM.Address) + (calldata : EVM.Bytes) : (Bool × EVM.State × EVM.Bytes) → Prop where + | callMade : + (∃ (callGas : Ethereum.UInt256) (A_in : Ethereum.Substate), + (cA', σ', g', A', z, o) + = Ethereum.EVM.Θ + evm.executionEnv.blobVersionedHashes + evm.createdAccounts + evm.genesisBlockHeader + evm.blocks + evm.accountMap + evm.σ₀ + A_in + evm.executionEnv.source + evm.executionEnv.sender + evm.executionEnv.codeOwner + (Ethereum.toExecute evm.accountMap target) + callGas + (.ofNat evm.executionEnv.gasPrice) + (⟨0⟩ : EVM.Word) + evm.executionEnv.weiValue + calldata + (evm.executionEnv.depth + 1) + evm.executionEnv.header + evm.executionEnv.perm) + → evm' = { evm with accountMap := σ', substate := A', createdAccounts := cA' } + → evm.executionEnv.depth ≠ 1024 + → delegateCallViaEVM evm target calldata (z, evm', o) + | callNotMade : + A' = ((evm.addAccessedAccount target) |>.substate) + → evm' = { evm with substate := A' } + → evm.executionEnv.depth = 1024 + → delegateCallViaEVM evm target calldata (false, evm', ByteArray.empty) + +/-- A typed external call: ABI-encode `name`/`args` into calldata, then make a raw `callViaEVM`. + This is the call form `externalCall` uses. The return *decode* (and its failure) stays in the + `ExecStmt` rules over the raw output bytes `o`, so decode-failure handling is unchanged. -/ +def typedCallViaEVM (cfg : Config) (evm : EVM.State) (target : EVM.Address) + (name : Ident) (value : ℤ) (args : List Value) + (result : Bool × EVM.State × EVM.Bytes) (perm : Bool := true) : Prop := + ∃ calldata, cfg.externalABI.encode? name args = some calldata + ∧ callViaEVM evm target value calldata result perm + +-- Contract creation (`new`) via the EVM `Λ` (Lambda) function. The result triple is +-- `(addr, evm', success)`: the created contract's address, the resulting EVM state, +-- and whether creation succeeded. Mirrors `callViaEVM`, but `Λ` runs the +-- initialisation code instead of a message call and returns the new address. + +-- Preconditions under which a `new` (the `CREATE` opcode) actually runs the init code, +-- mirroring the guards the opcode checks before calling `Lambda`. +def newCanCreate (evm : EVM.State) (value : ℤ) (initCode : EVM.Bytes) : Prop := + let creator := evm.accountMap.find? evm.executionEnv.codeOwner |>.getD default + EVM.wordOfInt value ≤ creator.balance -- creator can afford the endowment + ∧ evm.executionEnv.depth ≠ 1024 -- call-depth limit not reached + ∧ creator.nonce.toNat < 2 ^ 64 - 1 -- creator nonce below the cap (EIP-2681) + ∧ initCode.size ≤ 49152 -- init code within the limit (EIP-3860) + +inductive newViaEVM (cfg : Config) (evm : EVM.State) + (name : Ident) (value : ℤ) (args : List Value) (salt : Option ByteArray) : + (EVM.Address × EVM.State × Bool) → Prop where + | created : + cfg.creationCode name args = .some initCode + → newCanCreate evm value initCode + → valueWord = EVM.wordOfInt value + → (∃ createGas refunds accessedStorageKeys, + -- As in `callViaEVM`, existentially quantify over substate fields + -- whose value we do not track accurately but which creation can change. + let A_exist := { evm.substate with + refundBalance := refunds + accessedStorageKeys := accessedStorageKeys } + -- Mirror the CREATE opcode: bump the creator's nonce before calling `Lambda`, + -- which derives the new address from `sender.nonce - 1` and so expects the + -- already-incremented nonce. + let creator := evm.accountMap.find? evm.executionEnv.codeOwner |>.getD default + let σStar := evm.accountMap.insert evm.executionEnv.codeOwner + { creator with nonce := creator.nonce + ⟨1⟩ } + (addr, cA', σ', _, A', z, _) + = Ethereum.EVM.Lambda + evm.executionEnv.blobVersionedHashes + evm.createdAccounts + evm.genesisBlockHeader + evm.blocks + σStar + evm.σ₀ + A_exist + evm.executionEnv.codeOwner -- sender (msg.sender): `this`, as CREATE does + evm.executionEnv.sender -- original transactor (tx.origin) + createGas + (.ofNat evm.executionEnv.gasPrice) + valueWord -- endowment + initCode -- initialisation EVM code + (evm.executionEnv.depth + 1) + salt -- `none` ⇒ CREATE; `some s` ⇒ CREATE2 with salt `s` + evm.executionEnv.header + true) -- permission to modify state + → evm' = { evm with accountMap := σ', substate := A', createdAccounts := cA' } + → newViaEVM cfg evm name value args salt (addr, evm', z) + | notCreated : + cfg.creationCode name args = .some initCode + → ¬ newCanCreate evm value initCode + → newViaEVM cfg evm name value args salt (EVM.address 0, evm, false) + +end Solm diff --git a/Solm/Semantics/Dispatch.lean b/Solm/Semantics/Dispatch.lean new file mode 100644 index 00000000..08c16578 --- /dev/null +++ b/Solm/Semantics/Dispatch.lean @@ -0,0 +1,61 @@ +import ABI.Signature +import Solm.Value + +/-! Message dispatch: selector, `receive`, and `fallback` resolution, and return conventions. -/ + +namespace Solm + +open ABI + +def transitionSignature (transition : TransitionDecl) : Signature := + ⟨transition.name, transition.params.map Param.ty⟩ + +def transitionSigStr (transition : TransitionDecl) : String := + printSignature $ transitionSignature transition + +def selectorDispatchMsg (contract : ContractDecl) (calldata : ByteArray) + : Option TransitionDecl := + let sigs := contract.transitions.map (λ t ↦ (t, transitionSigStr t)) + let sigHashes := sigs.map (Prod.map id (ffi.KEC ∘ String.toByteArray)) + let selectors := sigHashes.map (Prod.map id (λ b ↦ b.extract 0 4)) + let currentSelector := calldata.extract 0 4 + match selectors.find? (λ (_,s) ↦ s == currentSelector) with + | some (t,_) => t + | none => none + +def receiveDispatchMsg (contract : ContractDecl) (calldata : ByteArray) + : Option TransitionDecl := + if calldata.size = 0 then contract.receive else none + +def dispatchMsg (contract : ContractDecl) (calldata : ByteArray) + : Option TransitionDecl := + match selectorDispatchMsg contract calldata with + | some transition => some transition + | none => + match receiveDispatchMsg contract calldata with + | some transition => some transition + | none => contract.fallback + +inductive ReturnConvention where + | abi : List ABIType → ReturnConvention + | rawBytes : ReturnConvention + deriving DecidableEq, Repr, Inhabited + +def fallbackCallargs (calldata : ByteArray) : List Param → Option Store + | [] => some ∅ + | [param] => + match param.ty with + | .bytes => some ((∅ : Store).insert param.name (.bytes calldata)) + | _ => none + | _ => none + +def fallbackReturnConvention (transition : TransitionDecl) : Option ReturnConvention := + match transition.params, transition.returnType with + | [], [] => some (.abi []) + | [param], [.bytes] => + match param.ty with + | .bytes => some .rawBytes + | _ => none + | _, _ => none + +end Solm diff --git a/Solm/Semantics/Eval.lean b/Solm/Semantics/Eval.lean new file mode 100644 index 00000000..13154663 --- /dev/null +++ b/Solm/Semantics/Eval.lean @@ -0,0 +1,525 @@ +import ABI.Decode +import Solm.Semantics.StorageOps + +/-! The expression evaluator: termination measures and the `evalExpr?` mutual block. -/ + +namespace Solm + +open ABI + +-- Defining a measure for termination of the next mutual block, +-- that evaluates expressions and related types +mutual + def exprEvalSize : Expr → Nat + | .intLit _ => 1 + | .boolLit _ => 1 + | .bytesLit _ => 1 + | .newBytes lenExpr => exprEvalSize lenExpr + 1 + | .newArray _ lenExpr => exprEvalSize lenExpr + 1 + | .structLit _ fields => structFieldsEvalSize fields + 1 + | .arrayLit elems => exprListEvalSize elems + 1 + | .tupleLit elems => exprListEvalSize elems + 1 + | .bytesSlice baseE startE endE => + exprEvalSize baseE + exprEvalSize startE + exprEvalSize endE + 1 + | .var _ => 1 + | .env _ => 1 + | .storage slot => slotEvalSize slot + 1 + | .arrayLength _ slot => slotEvalSize slot + 1 + | .field base _ => exprEvalSize base + 1 + | .cast expr _ => exprEvalSize expr + 1 + | .inRange _ expr => exprEvalSize expr + 1 + | .addrOf expr => exprEvalSize expr + 1 + | .unary _ expr => exprEvalSize expr + 1 + | .binary _ lhs rhs => exprEvalSize lhs + exprEvalSize rhs + 1 + | .index base idx => exprEvalSize base + exprEvalSize idx + 1 + | .ite cond thenExpr elseExpr => + exprEvalSize cond + exprEvalSize thenExpr + exprEvalSize elseExpr + 1 + | .keccak256 e => exprEvalSize e + 1 + | .abiEncodePacked args => typedArgsEvalSize args + 1 + | .abiEncodeCall _ args => exprListEvalSize args + 1 + | .abiDecode _ e => exprEvalSize e + 1 + | .extCodeSize e => exprEvalSize e + 1 + | .extCodePrefix addrE lenE => exprEvalSize addrE + exprEvalSize lenE + 1 + | .tupleGet e _ => exprEvalSize e + 1 + | .blockhash e => exprEvalSize e + 1 + | .balanceOf e => exprEvalSize e + 1 + | .extCodeHash e => exprEvalSize e + 1 + | .fixedBytesLit _ _ => 1 + termination_by expr => (sizeOf expr, 0) + decreasing_by + all_goals simp_wf + all_goals first | (cases slot; simp; omega) | decreasing_tactic + + def slotEvalSize (slot : StorageRef) : Nat := + slotStepsEvalSize slot.steps + 1 + termination_by (sizeOf slot.steps, 1) + decreasing_by + all_goals omega + + def slotStepEvalSize : StorageRefStep → Nat + | .field _ => 1 + | .mindex expr => exprEvalSize expr + 1 + | .aindex expr => exprEvalSize expr + 1 + termination_by step => (sizeOf step, 0) + decreasing_by + all_goals simp_wf + all_goals decreasing_tactic + + def slotStepsEvalSize : List StorageRefStep → Nat + | [] => 1 + | step :: rest => slotStepEvalSize step + slotStepsEvalSize rest + 1 + termination_by steps => (sizeOf steps, 0) + decreasing_by + all_goals simp_wf + all_goals decreasing_tactic + + def exprListEvalSize : List Expr → Nat + | [] => 1 + | e :: rest => exprEvalSize e + exprListEvalSize rest + 1 + termination_by es => (sizeOf es, 0) + decreasing_by + all_goals simp_wf + all_goals decreasing_tactic + + def structFieldsEvalSize : List (Ident × Expr) → Nat + | [] => 1 + | (_, e) :: rest => exprEvalSize e + structFieldsEvalSize rest + 1 + termination_by fs => (sizeOf fs, 0) + decreasing_by + all_goals simp_wf + all_goals decreasing_tactic + + def typedArgsEvalSize : List (ABIType × Expr) → Nat + | [] => 1 + | (_, e) :: rest => exprEvalSize e + typedArgsEvalSize rest + 1 + termination_by as => (sizeOf as, 0) + decreasing_by + all_goals simp_wf + all_goals decreasing_tactic +end + +mutual + +def evalStorageRefStep (cfg : Config) (solm : Frame) (evm : EVM.State) + (base : Ident) (pre : List EvaledStorageRefStep) (step : StorageRefStep) : EvalResult EvaledStorageRefStep := + match step with + | .field name => pure (.field name) + | .mindex expr => do + let index <- evalExpr? cfg solm evm expr + let indexKey <- EvalResult.ofOption .typeError (valueToKey? index) + pure (.mindex indexKey) + | .aindex expr => do + let index <- evalExpr? cfg solm evm expr + let indexKey <- EvalResult.ofOption .typeError (valueToKey? index) + -- check this index in bounds against the array reached by `pre`, *before* descending — + -- interleaved with index evaluation exactly as solc emits it + let _ <- arrayIndexInBounds? cfg evm solm.contract.storage base pre indexKey + pure (.aindex indexKey) + termination_by (slotStepEvalSize step, 0) + decreasing_by + all_goals simp [slotStepEvalSize] + all_goals omega + +/-- Evaluate a list of storage-ref steps left to right, threading the evaled prefix so each + `.aindex` can be bounds-checked against the array reached so far (see `evalStorageRefStep`). -/ +@[simp] def evalStorageRefSteps (cfg : Config) (solm : Frame) (evm : EVM.State) + (base : Ident) (pre : List EvaledStorageRefStep) : + List StorageRefStep -> EvalResult (List EvaledStorageRefStep) + | [] => pure [] + | step :: rest => do + let estep <- evalStorageRefStep cfg solm evm base pre step + let erest <- evalStorageRefSteps cfg solm evm base (pre ++ [estep]) rest + pure (estep :: erest) + termination_by steps => (slotStepsEvalSize steps, 0) + decreasing_by + all_goals simp [slotStepsEvalSize] + all_goals omega + +def evalStorageRef (cfg : Config) (solm : Frame) (evm : EVM.State) (slot : StorageRef) : EvalResult EvaledStorageRef := do + let steps <- evalStorageRefSteps cfg solm evm slot.base [] slot.steps + pure { base := slot.base, steps := steps } + termination_by (slotEvalSize slot, 0) + decreasing_by + simp [slotEvalSize] + apply Prod.Lex.left + omega + +/-- Follow unevaluated storage-ref steps from an already-evaluated storage root, threading both the + concrete evaluated path and its declared storage type. This is the workhorse for local + `storage` aliases. -/ +def evalStorageRefFrom? (cfg : Config) (solm : Frame) (evm : EVM.State) + (er : EvaledStorageRef) (ty : StorageType) : + List StorageRefStep -> EvalResult (EvaledStorageRef × StorageType) + | [] => pure (er, ty) + | step :: rest => do + let estep <- evalStorageRefStep cfg solm evm er.base er.steps step + let ty' <- EvalResult.ofOption .typeError (storageTypeStep? ty estep) + evalStorageRefFrom? cfg solm evm { er with steps := er.steps ++ [estep] } ty' rest + termination_by steps => (slotStepsEvalSize steps, 0) + decreasing_by + all_goals simp [slotStepsEvalSize] + all_goals omega + +/-- Resolve a storage lvalue. The base may be a contract storage declaration or a local + `Value.storageRef` alias; in the latter case we append the unevaluated suffix to the stored, + already-evaluated reference. -/ +def resolveStorageRef? (cfg : Config) (solm : Frame) (evm : EVM.State) + (slot : StorageRef) : EvalResult (EvaledStorageRef × StorageType) := + match solm.locals.get? slot.base with + | some (.storageRef er ty) => evalStorageRefFrom? cfg solm evm er ty slot.steps + | _ => + match evalStorageRef cfg solm evm slot with + | .ok er => do + let ty <- EvalResult.ofOption .storageError (storageTypeAt? solm.contract.storage er) + pure (er, ty) + | .revert => .revert + | .error e => .error e + termination_by (slotEvalSize slot, 1) + decreasing_by + all_goals simp [slotEvalSize] + all_goals omega + +def resolveDynamicArrayRef? (cfg : Config) (solm : Frame) (evm : EVM.State) + (ref : StorageRef) : EvalResult (EvaledStorageRef × StorageType) := do + let (er, ty) <- resolveStorageRef? cfg solm evm ref + match ty with + | .dynamicArray elemTy => pure (er, elemTy) + | _ => .error .storageError + +def readLocalPath? (cfg : Config) (solm : Frame) (evm : EVM.State) + (root : Value) : List StorageRefStep -> EvalResult Value + | [] => pure root + | .field name :: rest => do + let child <- EvalResult.ofOption .typeError (lookupField? root name) + readLocalPath? cfg solm evm child rest + | .mindex expr :: rest => do + let idx <- evalExpr? cfg solm evm expr + let child <- EvalResult.ofOption .typeError (lookupIndex? root idx) + readLocalPath? cfg solm evm child rest + | .aindex expr :: rest => do + let idx <- evalExpr? cfg solm evm expr + match root, idx with + | .array elems, .int i => + -- memory array index read: out of bounds reverts (solc's `Panic(0x32)`) + if 0 ≤ i ∧ i < elems.length then + let child <- EvalResult.ofOption .typeError (lookupIndex? root idx) + readLocalPath? cfg solm evm child rest + else .revert + | .fixedBytes n bytes, .int i => + match evalFixedBytesIndex? n bytes i with + | .ok child => readLocalPath? cfg solm evm child rest + | .revert => .revert + | .error e => .error e + | .bytes bytes, .int i => + match evalByteIndex? bytes.toList i with + | .ok child => readLocalPath? cfg solm evm child rest + | .revert => .revert + | .error e => .error e + | _, _ => + let child <- EvalResult.ofOption .typeError (lookupIndex? root idx) + readLocalPath? cfg solm evm child rest + termination_by steps => (slotStepsEvalSize steps, 0) + decreasing_by + all_goals simp [slotStepsEvalSize, slotStepEvalSize] + all_goals omega + +def updateLocalPath? (cfg : Config) (solm : Frame) (evm : EVM.State) + (root : Value) (steps : List StorageRefStep) (value : Value) : EvalResult Value := + match steps with + | [] => pure value + | .field name :: rest => do + let child <- EvalResult.ofOption .typeError (lookupField? root name) + let child' <- updateLocalPath? cfg solm evm child rest value + EvalResult.ofOption .typeError (updateField? root name child') + | .mindex expr :: rest => do + let idx <- evalExpr? cfg solm evm expr + let child <- EvalResult.ofOption .typeError (lookupIndex? root idx) + let child' <- updateLocalPath? cfg solm evm child rest value + EvalResult.ofOption .typeError (updateIndex? root idx child') + | .aindex expr :: rest => do + let idx <- evalExpr? cfg solm evm expr + match root, idx with + | .array elems, .int i => + -- memory array index write: out of bounds reverts (solc's `Panic(0x32)`) + if 0 ≤ i ∧ i < elems.length then + let child <- EvalResult.ofOption .typeError (lookupIndex? root idx) + let child' <- updateLocalPath? cfg solm evm child rest value + EvalResult.ofOption .typeError (updateIndex? root idx child') + else .revert + | _, _ => + let child <- EvalResult.ofOption .typeError (lookupIndex? root idx) + let child' <- updateLocalPath? cfg solm evm child rest value + EvalResult.ofOption .typeError (updateIndex? root idx child') + termination_by (slotStepsEvalSize steps, 0) + decreasing_by + all_goals simp [slotStepsEvalSize, slotStepEvalSize] + all_goals omega + +def assignStorageRef? (cfg : Config) (solm : Frame) (evm : EVM.State) + (origin : VarOrigin) (slot : StorageRef) (value : Value) : EvalResult (Frame × EVM.State) := + match origin with + | .localVar => + -- in-memory local: functionally update the bound `Value` along the path + match solm.locals.get? slot.base with + | some root => do + let root' <- updateLocalPath? cfg solm evm root slot.steps value + pure ({ solm with locals := solm.locals.insert slot.base root' }, evm) + | none => .error .unboundVariable + | .storage => do + let (evaledStorageRef, ty) <- resolveStorageRef? cfg solm evm slot + match value with + | .struct _ _ | .array _ | .bytes _ => do + -- whole-array / whole-struct assignment: write every slot by the declared type + let evm' <- writeStorage? cfg evm evaledStorageRef ty value + pure (solm, evm') + | _ => do + -- scalar leaf: a single whole/partial-slot store + let loc <- EvalResult.ofOption .storageError (cfg.storage.layout evaledStorageRef evm) + let evm' <- EvalResult.ofOption .storageError (storageLocStore evm loc value) + pure (solm, evm') + +def evalExpr? (cfg : Config) (solm : Frame) (evm : EVM.State) : + Expr -> EvalResult Value + | .intLit n => pure (.int n) + | .boolLit b => pure (.bool b) + | .bytesLit b => pure (.bytes b) + | .newBytes lenExpr => do + let lenVal <- evalExpr? cfg solm evm lenExpr + match lenVal with + | .int n => if n < 0 then .error .typeError + else pure (.bytes (ByteArray.mk (Array.replicate n.toNat (0 : UInt8)))) + | _ => .error .typeError + | .newArray elemTy lenExpr => do + let lenVal <- evalExpr? cfg solm evm lenExpr + match lenVal with + | .int n => + if n < 0 then .error .typeError + else do + let defaultValue <- defaultValue? elemTy + pure (.array (List.replicate n.toNat defaultValue)) + | _ => .error .typeError + | .structLit name fields => do + let fvals <- evalStructFields? cfg solm evm fields + pure (.struct name fvals) + | .arrayLit elems => do + let vals <- evalExprList? cfg solm evm elems + pure (.array vals) + | .tupleLit elems => do + let vals <- evalExprList? cfg solm evm elems + pure (.tuple vals) + | .bytesSlice baseE startE endE => do + let baseV <- evalExpr? cfg solm evm baseE + let startV <- evalExpr? cfg solm evm startE + let endV <- evalExpr? cfg solm evm endE + match baseV, startV, endV with + | .bytes ba, .int s, .int e => sliceBytes? ba s e + | _, _, _ => .error .typeError + | .var name => EvalResult.ofOption .unboundVariable (solm.locals.get? name) + | .env var => pure (envValue evm var) + | .storage slot => do + let (evaledStorageRef, ty) <- resolveStorageRef? cfg solm evm slot + readStorage? cfg evm evaledStorageRef ty + | .arrayLength origin slot => do + match origin with + | .storage => do + let (er, ty) <- resolveStorageRef? cfg solm evm slot + readStorageArrayLength? cfg evm er ty + | .localVar => + match solm.locals.get? slot.base with + | some root => do + let v <- readLocalPath? cfg solm evm root slot.steps + match v with + | .array vs => pure (.int vs.length) + | .bytes b => pure (.int (Int.ofNat b.size)) + | .fixedBytes n _ => pure (.int (fixedBytesSize n)) + | _ => .error .typeError + | none => .error .unboundVariable + | .field base name => do + let baseValue <- evalExpr? cfg solm evm base + match baseValue with + | .storageRef er ty => do + let step := EvaledStorageRefStep.field name + let ty' <- EvalResult.ofOption .typeError (storageTypeStep? ty step) + readStorage? cfg evm { er with steps := er.steps ++ [step] } ty' + | _ => EvalResult.ofOption .typeError (lookupField? baseValue name) + | .cast expr ty => do /- TODO do we really need to have casting? -/ + let value <- evalExpr? cfg solm evm expr + EvalResult.ofOption .typeError (castValue? value ty) + | .addrOf expr => do + let value <- evalExpr? cfg solm evm expr + match value with + | .address a => pure (.address a) + | _ => .error .typeError + | .unary op expr => do + let value <- evalExpr? cfg solm evm expr + EvalResult.ofOption .typeError (evalUnaryOp? op value) + | .binary .and lhs rhs => do + match <- evalExpr? cfg solm evm lhs with + | .bool false => pure (.bool false) + | .bool true => + (match <- evalExpr? cfg solm evm rhs with + | .bool b => pure (.bool b) + | _ => .error .typeError) + | _ => .error .typeError + | .binary .or lhs rhs => do + match <- evalExpr? cfg solm evm lhs with + | .bool true => pure (.bool true) + | .bool false => + (match <- evalExpr? cfg solm evm rhs with + | .bool b => pure (.bool b) + | _ => .error .typeError) + | _ => .error .typeError + | .binary op lhs rhs => do + let lhsValue <- evalExpr? cfg solm evm lhs + let rhsValue <- evalExpr? cfg solm evm rhs + evalBinaryOp? op lhsValue rhsValue + | .index base idx => do + let baseValue <- evalExpr? cfg solm evm base + let idxValue <- evalExpr? cfg solm evm idx + evalIndex? baseValue idxValue + | .ite cond thenExpr elseExpr => do + let condValue <- evalExpr? cfg solm evm cond + match condValue with + | .bool true => evalExpr? cfg solm evm thenExpr + | .bool false => evalExpr? cfg solm evm elseExpr + | _ => .error .typeError + | .inRange intType expr => do + let value <- evalExpr? cfg solm evm expr + match value, intType with + | .int i, .uint n => + if i < 0 || i >= 2^(n.val) then .revert else pure value + | .int i, .sint n => + let bound : Int := 2^(n.val - 1) + if i < -bound || i >= bound then .revert else pure value + | _, _ => .error .typeError + | .keccak256 e => do + let value <- evalExpr? cfg solm evm e + match value with + -- Keccak-256 of the dynamic bytes, as a `bytes32` value; same `ffi.KEC` as the EVM opcode. + | .bytes ba => pure (.fixedBytes ⟨31, by decide⟩ (ffi.KEC ba).toList) + | _ => .error .typeError + | .abiEncodePacked args => do + let bytes <- evalPackedArgs? cfg solm evm args + pure (.bytes (ByteArray.mk bytes.toArray)) + | .abiEncodeCall name args => do + let values <- evalExprList? cfg solm evm args + let bytes <- EvalResult.ofOption .typeError (cfg.externalABI.encode? name values) + pure (.bytes bytes) + | .abiDecode ty e => do + let value <- evalExpr? cfg solm evm e + match value with + | .bytes bytes => + match ABI.decodeReturnValueWithMode? cfg.abiDecodeMode ty bytes with + | some decoded => pure decoded + | none => .revert + | _ => .error .typeError + | .extCodeSize e => do + let value <- evalExpr? cfg solm evm e + match value with + -- EXTCODESIZE: the deployed code size at `a`; 0 for a non-existent account or an EOA. + -- Mirrors `Ethereum.State.extCodeSize` (which the EVM's EXTCODESIZE opcode dispatches to). + | .address a => + pure (.int (Int.ofNat + (EVM.Word.ofNat ((evm.lookupAccount a).option 0 (fun acc => acc.code.size))).toNat)) + | _ => .error .typeError + | .extCodePrefix addrE lenE => do + let addrV <- evalExpr? cfg solm evm addrE + let lenV <- evalExpr? cfg solm evm lenE + match addrV, lenV with + | .address a, .int n => + if n < 0 then .error .typeError + else + let code := (evm.lookupAccount a).option .empty (fun acc => acc.code) + let codePrefix := code.extract 0 n.toNat + pure (.bytes (codePrefix ++ + ByteArray.mk (Array.replicate (n.toNat - codePrefix.size) (0 : UInt8)))) + | _, _ => .error .typeError + | .tupleGet e i => do + let v <- evalExpr? cfg solm evm e + tupleGetValue? v i + -- BLOCKHASH: mirrors `Ethereum.State.blockHash` (256-block window; current/future → 0), as bytes32. + | .blockhash e => do + let v <- evalExpr? cfg solm evm e + match v with + | .int n => if n < 0 then .error .typeError + else pure (.fixedBytes ⟨31, by decide⟩ + (EVM.Word.toBytesBE (evm.blockHash (EVM.Word.ofNat n.toNat)))) + | _ => .error .typeError + -- BALANCE: mirrors `Ethereum.State.balance` (absent account → 0). + | .balanceOf e => do + let v <- evalExpr? cfg solm evm e + match v with + | .address a => + pure (.int (Int.ofNat ((evm.lookupAccount a).option (EVM.Word.ofNat 0) (·.balance)).toNat)) + | _ => .error .typeError + -- EXTCODEHASH: mirrors `Ethereum.State.extCodeHash` (dead account → 0), as bytes32. + | .extCodeHash e => do + let v <- evalExpr? cfg solm evm e + match v with + | .address a => + let h : EVM.Word := + if Ethereum.State.dead evm.accountMap a then ⟨0⟩ + else (evm.lookupAccount a).option ⟨0⟩ Ethereum.Account.codeHash + pure (.fixedBytes ⟨31, by decide⟩ (EVM.Word.toBytesBE h)) + | _ => .error .typeError + | .fixedBytesLit n bs => pure (.fixedBytes n bs) + termination_by expr => (exprEvalSize expr, 0) +decreasing_by + all_goals simp [exprEvalSize, slotEvalSize] + all_goals omega + +/-- Evaluate a list of expressions left to right (for `arrayLit` / tuple returns), short-circuiting + on the first `revert`/`error`. -/ +def evalExprList? (cfg : Config) (solm : Frame) (evm : EVM.State) : + List Expr -> EvalResult (List Value) + | [] => pure [] + | e :: rest => do + let v <- evalExpr? cfg solm evm e + let vs <- evalExprList? cfg solm evm rest + pure (v :: vs) +termination_by es => (exprListEvalSize es, 0) +decreasing_by + all_goals simp [exprListEvalSize] + all_goals omega + +/-- Evaluate a struct literal's named field expressions left to right (for `structLit`), + short-circuiting on the first `revert`/`error`. -/ +def evalStructFields? (cfg : Config) (solm : Frame) (evm : EVM.State) : + List (Ident × Expr) -> EvalResult (List (Ident × Value)) + | [] => pure [] + | (name, e) :: rest => do + let v <- evalExpr? cfg solm evm e + let vs <- evalStructFields? cfg solm evm rest + pure ((name, v) :: vs) +termination_by fs => (structFieldsEvalSize fs, 0) +decreasing_by + all_goals simp [structFieldsEvalSize] + all_goals omega + +/-- Evaluate each `abi.encodePacked` operand left to right and concatenate its packed encoding, + short-circuiting on the first `revert`/`error` (or a `.typeError` if a value cannot be packed). -/ +def evalPackedArgs? (cfg : Config) (solm : Frame) (evm : EVM.State) : + List (ABIType × Expr) -> EvalResult (List UInt8) + | [] => pure [] + | (ty, e) :: rest => do + let v <- evalExpr? cfg solm evm e + let head <- EvalResult.ofOption .typeError (encodePackedValue? ty v) + let tail <- evalPackedArgs? cfg solm evm rest + pure (head ++ tail) +termination_by as => (typedArgsEvalSize as, 0) +decreasing_by + all_goals simp [typedArgsEvalSize] + all_goals omega + +end + +def evalExprs? (cfg : Config) (solm : Frame) (evm : EVM.State) + (exprs : List Expr) : EvalResult (List Value) := + match exprs with + | [] => pure [] + | expr :: rest => do + let value <- evalExpr? cfg solm evm expr + let values <- evalExprs? cfg solm evm rest + pure (value :: values) + +end Solm diff --git a/Solm/Semantics/Exec.lean b/Solm/Semantics/Exec.lean new file mode 100644 index 00000000..f48d89e5 --- /dev/null +++ b/Solm/Semantics/Exec.lean @@ -0,0 +1,680 @@ +import Solm.Semantics.Dispatch +import Solm.Semantics.Eval +import Solm.Semantics.Calls + +/-! Statement and transaction big-step semantics: `ExecStmt` through `solmExec`. -/ + +namespace Solm + +open ABI + +inductive ExecResult where + /- The returned-value component is `Option (List Value)`: `none` means the body fell through + without executing `return`; `some vs` is an explicit `return` of the listed values (`some []` + is an explicit void return). -/ + | returned : Frame -> EVM.State -> Option (List Value) -> ExecResult + | ok : Frame -> EVM.State -> ExecResult + | break : Frame -> EVM.State -> ExecResult + | continue : Frame -> EVM.State -> ExecResult + | reverted : ExecResult + +structure CallableDecl where + params : List Param + returnType : List ABIType := [] + body : Body + deriving Repr, Inhabited + +def bindParams? (params : List Param) (args : List Value) : Option Store := + match params, args with + | [], [] => some ∅ + | p :: ps, v :: vs => do + let rest <- bindParams? ps vs + pure (rest.insert p.name v) + | _, _ => none + +def FunctionDecl.toCallable (decl : FunctionDecl) : CallableDecl := + { params := decl.params, returnType := decl.returnType, body := decl.body } + +def TransitionDecl.toCallable (decl : TransitionDecl) : CallableDecl := + { params := decl.params, returnType := decl.returnType, body := decl.body } + + +def lookupFunction? (decls : List FunctionDecl) (name : Ident) : Option CallableDecl := + match decls with + | [] => none + | d :: ds => + if d.name = name then some d.toCallable else lookupFunction? ds name + +def lookupTransition? (decls : List TransitionDecl) (name : Ident) : Option CallableDecl := + match decls with + | [] => none + | d :: ds => + if d.name = name then some d.toCallable else lookupTransition? ds name + + +def lookupCallable? (contract : ContractDecl) (name : Ident) : Option CallableDecl := + match lookupFunction? contract.functions name with + | some decl => some decl + | none => lookupTransition? contract.transitions name + +-- CREATE2 salt: a `bytes32` value → its 32 salt bytes; anything else is invalid. +def saltBytes? : Value → Option ByteArray + | .fixedBytes n bs => if n.val = 31 ∧ bs.length = 32 then some (ByteArray.mk bs.toArray) else none + | _ => none + +#guard saltBytes? (.fixedBytes ⟨31, by decide⟩ (List.replicate 32 0)) + = some (ByteArray.mk (Array.replicate 32 0)) +#guard saltBytes? (.int 5) = none + +/-- Collapse a callee's returned list into the single value bound to a call's result identifier. + This `Value.tuple` is internal-call plumbing only — it is never ABI-encoded; the ABI boundary is + transitions, which use the return list directly. -/ +def collapseReturns : List Value → Value + | [] => .unit + | [v] => v + | vs => .tuple vs + +def resumeAfterInternalCall (caller : Frame) (retVar : Ident) (value : Option (List Value)) : + Frame := + let valueToWrite := match value with + | none => .unit + | some vs => collapseReturns vs + { caller with locals := caller.locals.insert retVar valueToWrite } + +/-- `arr.push(v?)`: grow the dynamic array named by `ref` by one. Reads the current length `L` + (the layout's `.length` query), stores length `L+1`, then `some v` writes the value at element + `L` via `writeStorage?`. Writing the length first mirrors solc's generated storage order and + also makes the new index in-bounds for the ordinary storage writer. `none` is a grow-only push + (the new slots are already zero by storage default). `.revert`s only if evaluating the array ref + does. It `.error`s (a stuck, ill-formed program) when the target isn't a dynamic array, the + layout has no `.length`/element slot for it, the length slot doesn't hold an integer, or a + compound value's shape doesn't match the element type — i.e. for a well-formed layout + matching + value, `.revert` is the only non-`.ok` outcome. -/ +def pushArray? (cfg : Config) (solm : Frame) (evm : EVM.State) (ref : StorageRef) + (value : Option Value) : EvalResult EVM.State := do + let (er, ty) <- resolveStorageRef? cfg solm evm ref + match ty with + | .dynamicArray elemTy => do + let lenLoc <- EvalResult.ofOption .storageError + (cfg.storage.layout { er with steps := er.steps ++ [.length] } evm) + match storageLocLoad evm lenLoc with + | .int len => do + let evmLen <- EvalResult.ofOption .storageError (storageLocStore evm lenLoc (.int (len + 1))) + match value with + | some v => + writeStorage? cfg evmLen + { er with steps := er.steps ++ [.aindex (.int len)] } elemTy v + | none => pure evmLen + | _ => .error .storageError + -- `bytes`/`string` push: read-modify-write the whole value through the layout hooks (they handle + -- short↔long transitions). Arg-less appends a zero byte; else a `bytes1` (`fixedBytes ⟨0,_⟩`). + | .bytes | .string => do + match (← readStorage? cfg evm er ty) with + | .bytes ba => + match value with + | none => writeStorage? cfg evm er ty (.bytes (ba.push 0)) + | some (.fixedBytes n bs) => + if n.val = 0 ∧ bs.length = 1 then + writeStorage? cfg evm er ty (.bytes (ba ++ ByteArray.mk bs.toArray)) + else .error .typeError + | some _ => .error .typeError + | _ => .error .storageError + | _ => .error .storageError + +/-- `arr.pop()`: remove the last element of the dynamic array named by `ref`. Reverts when the + array is empty (solc's `Panic(0x31)`). Otherwise recursively clears the whole last element + (per its declared type, via `clearStorage?` — so nested arrays/structs are fully zeroed) and + sets the length to `L-1`. -/ +def popArray? (cfg : Config) (solm : Frame) (evm : EVM.State) (ref : StorageRef) + : EvalResult EVM.State := do + let (er, ty) <- resolveStorageRef? cfg solm evm ref + match ty with + | .dynamicArray elemTy => do + let lenLoc <- EvalResult.ofOption .storageError + (cfg.storage.layout { er with steps := er.steps ++ [.length] } evm) + match storageLocLoad evm lenLoc with + | .int len => + if len ≤ 0 then .revert + else do + let evm1 <- clearStorage? cfg evm + { er with steps := er.steps ++ [.aindex (.int (len - 1))] } elemTy + EvalResult.ofOption .storageError (storageLocStore evm1 lenLoc (.int (len - 1))) + | _ => .error .storageError + -- `bytes`/`string` pop: read-modify-write; empty → revert (solc `Panic(0x31)`). + | .bytes | .string => do + match (← readStorage? cfg evm er ty) with + | .bytes ba => + if ba.size = 0 then .revert + else writeStorage? cfg evm er ty (.bytes (ba.extract 0 (ba.size - 1))) + | _ => .error .storageError + | _ => .error .storageError + +/-- `delete x`: reset the storage at `ref` to its zero value, recursively per its declared type + (`clearStorage?` — a dynamic array becomes empty, a struct/array is fully zeroed). `.revert`s + only if evaluating the ref does; `.error`s on an ill-formed layout/type. -/ +def deleteStorage? (cfg : Config) (solm : Frame) (evm : EVM.State) (ref : StorageRef) + : EvalResult EVM.State := do + let (er, ty) <- resolveStorageRef? cfg solm evm ref + clearStorage? cfg evm er ty + +-- Evaluate a `new`'s optional salt: `none` ⇒ CREATE; `some e` must be a `bytes32` ⇒ CREATE2. +def evalSalt? (cfg : Config) (solm : Frame) (evm : EVM.State) : + Option Expr → EvalResult (Option ByteArray) + | none => .ok none + | some e => do + let v <- evalExpr? cfg solm evm e + match saltBytes? v with + | some b => .ok (some b) + | none => .error .typeError + +mutual + +inductive ExecStmt (cfg : Config) : + Frame -> EVM.State -> Stmt -> ExecResult -> Prop where + | letDecl : + evalExpr? cfg solm evm expr = .ok value -> + ExecStmt cfg solm evm (.letDecl name ty expr) + (.ok { solm with locals := solm.locals.insert name value } evm) + | letDeclRevert : + evalExpr? cfg solm evm expr = .revert -> + ExecStmt cfg solm evm (.letDecl name ty expr) .reverted + | letStorage : + resolveStorageRef? cfg solm evm ref = .ok (er, ty) -> + ExecStmt cfg solm evm (.letStorage name ref) + (.ok { solm with locals := solm.locals.insert name (.storageRef er ty) } evm) + | letStorageRevert : + resolveStorageRef? cfg solm evm ref = .revert -> + ExecStmt cfg solm evm (.letStorage name ref) .reverted + -- `gasleft()`: Solm tracks no gas, so any word `w` is a legal result. A proof picks the `w` + -- matching the EVM's actual gas at the corresponding `GAS` opcode. + | letGas (w : EVM.Word) : + ExecStmt cfg solm evm (.letGas name) + (.ok { solm with locals := solm.locals.insert name (.int (Int.ofNat w.toNat)) } evm) + | assign : + evalExpr? cfg solm evm expr = .ok value -> + assignStorageRef? cfg solm evm origin slot value = .ok (solm', evm') -> + ExecStmt cfg solm evm (.assign origin slot expr) (.ok solm' evm') + | assignExprRevert : + evalExpr? cfg solm evm expr = .revert -> + ExecStmt cfg solm evm (.assign origin slot expr) .reverted + | assignStoreRevert : + evalExpr? cfg solm evm expr = .ok value -> + assignStorageRef? cfg solm evm origin slot value = .revert -> + ExecStmt cfg solm evm (.assign origin slot expr) .reverted + | pushVal : + evalExpr? cfg solm evm expr = .ok value -> + pushArray? cfg solm evm ref (some value) = .ok evm' -> + ExecStmt cfg solm evm (.push ref (some expr)) (.ok solm evm') + | pushValExprRevert : + evalExpr? cfg solm evm expr = .revert -> + ExecStmt cfg solm evm (.push ref (some expr)) .reverted + | pushValStoreRevert : + evalExpr? cfg solm evm expr = .ok value -> + pushArray? cfg solm evm ref (some value) = .revert -> + ExecStmt cfg solm evm (.push ref (some expr)) .reverted + | pushGrow : + pushArray? cfg solm evm ref none = .ok evm' -> + ExecStmt cfg solm evm (.push ref none) (.ok solm evm') + | pushGrowRevert : + pushArray? cfg solm evm ref none = .revert -> + ExecStmt cfg solm evm (.push ref none) .reverted + | pop : + popArray? cfg solm evm ref = .ok evm' -> + ExecStmt cfg solm evm (.pop ref) (.ok solm evm') + | popRevert : + popArray? cfg solm evm ref = .revert -> + ExecStmt cfg solm evm (.pop ref) .reverted + | delete : + deleteStorage? cfg solm evm ref = .ok evm' -> + ExecStmt cfg solm evm (.delete ref) (.ok solm evm') + | deleteRevert : + deleteStorage? cfg solm evm ref = .revert -> + ExecStmt cfg solm evm (.delete ref) .reverted + | requireTrue {condExpr} : + evalExpr? cfg solm evm condExpr = .ok (.bool true) -> + ExecStmt cfg solm evm (.require condExpr) (.ok solm evm) + | requireFalse {condExpr} : + evalExpr? cfg solm evm condExpr = .ok (.bool false) -> + ExecStmt cfg solm evm (.require condExpr) .reverted + | requireRevert {condExpr} : + evalExpr? cfg solm evm condExpr = .revert -> + ExecStmt cfg solm evm (.require condExpr) .reverted + | whileFalse {condExpr} : + evalExpr? cfg solm evm condExpr = .ok (.bool false) -> + ExecStmt cfg solm evm (.while condExpr body) (.ok solm evm) + | whileCondRevert {condExpr} : + evalExpr? cfg solm evm condExpr = .revert -> + ExecStmt cfg solm evm (.while condExpr body) .reverted + | whileTrue {condExpr} : + evalExpr? cfg solm evm condExpr = .ok (.bool true) -> + ExecBlock cfg solm evm body (.ok solm' evm') -> + ExecStmt cfg solm' evm' (.while condExpr body) result -> + ExecStmt cfg solm evm (.while condExpr body) result + | whileReturn {condExpr} : + evalExpr? cfg solm evm condExpr = .ok (.bool true) -> + ExecBlock cfg solm evm body (.returned solm' evm' value) -> + ExecStmt cfg solm evm (.while condExpr body) (.returned solm' evm' value) + | whileRevert {condExpr} : + evalExpr? cfg solm evm condExpr = .ok (.bool true) -> + ExecBlock cfg solm evm body .reverted -> + ExecStmt cfg solm evm (.while condExpr body) .reverted + | whileBreak {condExpr} : + evalExpr? cfg solm evm condExpr = .ok (.bool true) -> + ExecBlock cfg solm evm body (.break solm' evm') -> + ExecStmt cfg solm evm (.while condExpr body) (.ok solm' evm') + | whileContinue {condExpr} : + evalExpr? cfg solm evm condExpr = .ok (.bool true) -> + ExecBlock cfg solm evm body (.continue solm' evm') -> + ExecStmt cfg solm' evm' (.while condExpr body) result -> + ExecStmt cfg solm evm (.while condExpr body) result + -- `for (init; cond; post) { body }`: run `init` once, then loop via `ExecForLoop`. + | for : + ExecBlock cfg solm evm init (.ok solm1 evm1) -> + ExecForLoop cfg solm1 evm1 condExpr post body result -> + ExecStmt cfg solm evm (.for init condExpr post body) result + | forInitReturn : + ExecBlock cfg solm evm init (.returned solm1 evm1 value) -> + ExecStmt cfg solm evm (.for init condExpr post body) (.returned solm1 evm1 value) + | forInitRevert : + ExecBlock cfg solm evm init .reverted -> + ExecStmt cfg solm evm (.for init condExpr post body) .reverted + | iteTrue {condExpr} : + evalExpr? cfg solm evm condExpr = .ok (.bool true) -> + ExecBlock cfg solm evm thenB result -> + ExecStmt cfg solm evm (.ite condExpr thenB elseB) result + | iteFalse {condExpr} : + evalExpr? cfg solm evm condExpr = .ok (.bool false) -> + ExecBlock cfg solm evm elseB result -> + ExecStmt cfg solm evm (.ite condExpr thenB elseB) result + | iteCondRevert {condExpr} : + evalExpr? cfg solm evm condExpr = .revert -> + ExecStmt cfg solm evm (.ite condExpr thenB elseB) .reverted + | internalCallReturn : + evalExprs? cfg solm evm args = .ok argVals -> + lookupCallable? solm.contract name = some callee -> + bindParams? callee.params argVals = some locals -> + ExecFuncBody cfg { solm with locals := locals } evm callee.body + (.returned calleeSolm calleeEvm value) -> + ExecStmt cfg solm evm (.internalCall name args retVar) + (.ok (resumeAfterInternalCall solm retVar value) calleeEvm) + | internalCallRevert : + evalExprs? cfg solm evm args = .ok argVals -> + lookupCallable? solm.contract name = some callee -> + bindParams? callee.params argVals = some locals -> + ExecFuncBody cfg { solm with locals := locals } evm callee.body .reverted -> + ExecStmt cfg solm evm (.internalCall name args retVar) .reverted + | internalCallArgsRevert : + evalExprs? cfg solm evm args = .revert -> + ExecStmt cfg solm evm (.internalCall name args retVar) .reverted + | externalCallSuccess : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .ok (.int sendVal) -> + evalExprs? cfg solm evm args = .ok argVals -> + typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals + (true, evm', out) perm -> + cfg.externalABI.decode? name out = some value -> + ExecStmt cfg solm evm (.externalCall receiver name eth args retVar (perm := perm)) + (.ok { solm with locals := solm.locals.insert retVar (collapseReturns value) } evm') + | externalCallFailure : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .ok (.int sendVal) -> + evalExprs? cfg solm evm args = .ok argVals -> + typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals + (false, evm', out) perm -> + ExecStmt cfg solm evm (.externalCall receiver name eth args retVar (perm := perm)) .reverted + | externalCallReturnDecodeRevert : + -- The sub-call *succeeds* (`z = true`) but the returned bytes do not ABI-decode to the + -- expected return value (`decode? = none`). The caller's solc-generated return decoder then + -- reverts (`if slt(returndatasize, 32) { revert }`), so the whole statement reverts. + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .ok (.int sendVal) -> + evalExprs? cfg solm evm args = .ok argVals -> + typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals + (true, evm', out) perm -> + cfg.externalABI.decode? name out = none -> + ExecStmt cfg solm evm (.externalCall receiver name eth args retVar (perm := perm)) .reverted + | externalCallReceiverRevert : + evalExpr? cfg solm evm receiver = .revert -> + ExecStmt cfg solm evm (.externalCall receiver name eth args retVar (perm := perm)) .reverted + | externalCallSendRevert : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .revert -> + ExecStmt cfg solm evm (.externalCall receiver name eth args retVar (perm := perm)) .reverted + | externalCallArgsRevert : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .ok (.int sendVal) -> + evalExprs? cfg solm evm args = .revert -> + ExecStmt cfg solm evm (.externalCall receiver name eth args retVar (perm := perm)) .reverted + | lowLevelCallSuccess : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .ok (.int sendVal) -> + evalExpr? cfg solm evm cdata = .ok (.bytes calldata) -> + callViaEVM evm (EVM.address target) sendVal calldata (true, evm', out) perm -> + ExecStmt cfg solm evm (.lowLevelCall receiver eth cdata okVar dataVar (perm := perm)) + (.ok { solm with locals := (solm.locals.insert okVar (.bool true)).insert dataVar (.bytes out) } evm') + | lowLevelCallFailure : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .ok (.int sendVal) -> + evalExpr? cfg solm evm cdata = .ok (.bytes calldata) -> + callViaEVM evm (EVM.address target) sendVal calldata (false, evm', out) perm -> + ExecStmt cfg solm evm (.lowLevelCall receiver eth cdata okVar dataVar (perm := perm)) + (.ok { solm with locals := (solm.locals.insert okVar (.bool false)).insert dataVar (.bytes out) } evm') + | lowLevelCallReceiverRevert : + evalExpr? cfg solm evm receiver = .revert -> + ExecStmt cfg solm evm (.lowLevelCall receiver eth cdata okVar dataVar (perm := perm)) .reverted + | lowLevelCallSendRevert : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .revert -> + ExecStmt cfg solm evm (.lowLevelCall receiver eth cdata okVar dataVar (perm := perm)) .reverted + | lowLevelCallDataRevert : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .ok (.int sendVal) -> + evalExpr? cfg solm evm cdata = .revert -> + ExecStmt cfg solm evm (.lowLevelCall receiver eth cdata okVar dataVar (perm := perm)) .reverted + | delegateCallSuccess : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm cdata = .ok (.bytes calldata) -> + delegateCallViaEVM evm (EVM.address target) calldata (true, evm', out) -> + ExecStmt cfg solm evm (.delegateCall receiver cdata okVar dataVar) + (.ok + { solm with + locals := (solm.locals.insert okVar (.bool true)).insert dataVar (.bytes out) } + evm') + | delegateCallFailure : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm cdata = .ok (.bytes calldata) -> + delegateCallViaEVM evm (EVM.address target) calldata (false, evm', out) -> + ExecStmt cfg solm evm (.delegateCall receiver cdata okVar dataVar) + (.ok + { solm with + locals := (solm.locals.insert okVar (.bool false)).insert dataVar (.bytes out) } + evm') + | delegateCallReceiverRevert : + evalExpr? cfg solm evm receiver = .revert -> + ExecStmt cfg solm evm (.delegateCall receiver cdata okVar dataVar) .reverted + | delegateCallDataRevert : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm cdata = .revert -> + ExecStmt cfg solm evm (.delegateCall receiver cdata okVar dataVar) .reverted + | checkedCallSuccess : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .ok (.int sendVal) -> + evalExprs? cfg solm evm args = .ok argVals -> + typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals + (true, evm', out) perm -> + cfg.externalABI.decode? name out = some value -> + ExecBlock cfg { solm with locals := solm.locals.insert retVar (collapseReturns value) } evm' onSuccess result -> + ExecStmt cfg solm evm + (.checkedCall receiver name eth args retVar onSuccess errVar onFail (perm := perm)) result + | checkedCallFail : + -- callee reverted: bind the raw returndata to `errVar` and run `onFail`. The per-contract spec + -- decides there (via `ite` on `errVar`) whether to recover or re-revert (`require false`). + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .ok (.int sendVal) -> + evalExprs? cfg solm evm args = .ok argVals -> + typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals + (false, evm', out) perm -> + ExecBlock cfg { solm with locals := solm.locals.insert errVar (.bytes out) } evm' onFail result -> + ExecStmt cfg solm evm + (.checkedCall receiver name eth args retVar onSuccess errVar onFail (perm := perm)) result + | checkedCallReturnDecodeRevert : + -- Call succeeds but returndata doesn't ABI-decode (`decode? = none`, e.g. codeless callee): + -- solc's return decoder reverts *uncaught* (never enters `onFail`). Cf. externalCall twin. + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .ok (.int sendVal) -> + evalExprs? cfg solm evm args = .ok argVals -> + typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals + (true, evm', out) perm -> + cfg.externalABI.decode? name out = none -> + ExecStmt cfg solm evm + (.checkedCall receiver name eth args retVar onSuccess errVar onFail (perm := perm)) .reverted + | checkedCallReceiverRevert : + evalExpr? cfg solm evm receiver = .revert -> + ExecStmt cfg solm evm + (.checkedCall receiver name eth args retVar onSuccess errVar onFail (perm := perm)) .reverted + | checkedCallSendRevert : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .revert -> + ExecStmt cfg solm evm + (.checkedCall receiver name eth args retVar onSuccess errVar onFail (perm := perm)) .reverted + | checkedCallArgsRevert : + evalExpr? cfg solm evm receiver = .ok (.address target) -> + evalExpr? cfg solm evm eth = .ok (.int sendVal) -> + evalExprs? cfg solm evm args = .revert -> + ExecStmt cfg solm evm + (.checkedCall receiver name eth args retVar onSuccess errVar onFail (perm := perm)) .reverted + | newSuccess : + evalExpr? cfg solm evm valExpr = .ok (.int sendVal) -> + evalExprs? cfg solm evm args = .ok argVals -> + evalSalt? cfg solm evm salt = .ok saltBytes -> + newViaEVM cfg evm name sendVal argVals saltBytes (addr, evm', true) -> + ExecStmt cfg solm evm (.new name valExpr args retVar salt) + (.ok { solm with locals := solm.locals.insert retVar (.address addr) } evm') + | newRevert : + -- A failed creation reverts the caller, unlike a low-level external call. + evalExpr? cfg solm evm valExpr = .ok (.int sendVal) -> + evalExprs? cfg solm evm args = .ok argVals -> + evalSalt? cfg solm evm salt = .ok saltBytes -> + newViaEVM cfg evm name sendVal argVals saltBytes (addr, evm', false) -> + ExecStmt cfg solm evm (.new name valExpr args retVar salt) .reverted + | newValueRevert : + evalExpr? cfg solm evm valExpr = .revert -> + ExecStmt cfg solm evm (.new name valExpr args retVar salt) .reverted + | newArgsRevert : + evalExpr? cfg solm evm valExpr = .ok (.int sendVal) -> + evalExprs? cfg solm evm args = .revert -> + ExecStmt cfg solm evm (.new name valExpr args retVar salt) .reverted + | return : + evalExprs? cfg solm evm exprs = .ok values -> + ExecStmt cfg solm evm (.return exprs) (.returned solm evm (some values)) + | returnRevert : + evalExprs? cfg solm evm exprs = .revert -> + ExecStmt cfg solm evm (.return exprs) .reverted + | break : + ExecStmt cfg solm evm .break (.break solm evm) + | continue : + ExecStmt cfg solm evm .continue (.continue solm evm) + +/-- The loop part of a `for (init; cond; post) { body }`, after `init` has run. Each iteration + checks `cond`; on `true` it runs `body` then `post` and loops. A `break` in `body` exits the + loop with `.ok` (skipping `post`); a `continue` runs `post` and loops; `return`/`revert` + propagate. `post` may only fall through (`.ok`) or revert. -/ +inductive ExecForLoop (cfg : Config) : + Frame -> EVM.State -> Expr /- cond -/ -> List Stmt /- post -/ -> List Stmt /- body -/ -> + ExecResult -> Prop where + | falseDone {condExpr} : + evalExpr? cfg solm evm condExpr =.ok (.bool false) -> + ExecForLoop cfg solm evm condExpr post body (.ok solm evm) + | condRevert {condExpr} : + evalExpr? cfg solm evm condExpr =.revert -> + ExecForLoop cfg solm evm condExpr post body .reverted + | bodyReturn {condExpr} : + evalExpr? cfg solm evm condExpr =.ok (.bool true) -> + ExecBlock cfg solm evm body (.returned solm' evm' value) -> + ExecForLoop cfg solm evm condExpr post body (.returned solm' evm' value) + | bodyRevert {condExpr} : + evalExpr? cfg solm evm condExpr =.ok (.bool true) -> + ExecBlock cfg solm evm body .reverted -> + ExecForLoop cfg solm evm condExpr post body .reverted + | bodyBreak {condExpr} : + evalExpr? cfg solm evm condExpr =.ok (.bool true) -> + ExecBlock cfg solm evm body (.break solm' evm') -> + ExecForLoop cfg solm evm condExpr post body (.ok solm' evm') + | iterate {condExpr} : + evalExpr? cfg solm evm condExpr =.ok (.bool true) -> + ExecBlock cfg solm evm body (.ok solm1 evm1) -> + ExecBlock cfg solm1 evm1 post (.ok solm2 evm2) -> + ExecForLoop cfg solm2 evm2 condExpr post body result -> + ExecForLoop cfg solm evm condExpr post body result + | iteratePostRevert {condExpr} : + evalExpr? cfg solm evm condExpr =.ok (.bool true) -> + ExecBlock cfg solm evm body (.ok solm1 evm1) -> + ExecBlock cfg solm1 evm1 post .reverted -> + ExecForLoop cfg solm evm condExpr post body .reverted + | continueIter {condExpr} : + evalExpr? cfg solm evm condExpr =.ok (.bool true) -> + ExecBlock cfg solm evm body (.continue solm1 evm1) -> + ExecBlock cfg solm1 evm1 post (.ok solm2 evm2) -> + ExecForLoop cfg solm2 evm2 condExpr post body result -> + ExecForLoop cfg solm evm condExpr post body result + | continuePostRevert {condExpr} : + evalExpr? cfg solm evm condExpr =.ok (.bool true) -> + ExecBlock cfg solm evm body (.continue solm1 evm1) -> + ExecBlock cfg solm1 evm1 post .reverted -> + ExecForLoop cfg solm evm condExpr post body .reverted + +inductive ExecBlock (cfg : Config) : + Frame -> EVM.State -> List Stmt -> ExecResult -> Prop where + | nil : + ExecBlock cfg solm evm [] (.ok solm evm) + | consNormal : + ExecStmt cfg solm evm stmt (.ok solm' evm') -> + ExecBlock cfg solm' evm' stmts result -> + ExecBlock cfg solm evm (stmt :: stmts) result + | consReturn : + ExecStmt cfg solm evm stmt (.returned solm' evm' value) -> + ExecBlock cfg solm evm (stmt :: stmts) (.returned solm' evm' value) + | consRevert : + ExecStmt cfg solm evm stmt .reverted -> + ExecBlock cfg solm evm (stmt :: stmts) .reverted + | consBreak : + ExecStmt cfg solm evm stmt (.break solm' evm') -> + ExecBlock cfg solm evm (stmt :: stmts) (.break solm' evm') + | consContinue : + ExecStmt cfg solm evm stmt (.continue solm' evm') -> + ExecBlock cfg solm evm (stmt :: stmts) (.continue solm' evm') + +inductive ExecFuncBody (cfg : Config) : + Frame -> EVM.State -> List Stmt -> ExecResult -> Prop where + | execBlockOK : + ExecBlock cfg solm evm body (.ok solm' evm') -> + ExecFuncBody cfg solm evm body (.returned solm' evm' none) + | execBlockRet : + ExecBlock cfg solm evm body (.returned solm' evm' value) -> + ExecFuncBody cfg solm evm body (.returned solm' evm' value) + | execBlockRevert : + ExecBlock cfg solm evm body .reverted -> + ExecFuncBody cfg solm evm body .reverted + -- A `break`/`continue` that occurs outside a loop is malformed. We have to handle it so that ExecFuncBody is never stuck. + | execBlockBreak : + ExecBlock cfg solm evm body (.break solm' evm') -> + ExecFuncBody cfg solm evm body (.returned solm' evm' none) + | execBlockContinue : + ExecBlock cfg solm evm body (.continue solm' evm') -> + ExecFuncBody cfg solm evm body (.returned solm' evm' none) + +end + +def ExecTransitionBody (cfg : Config) (contract : ContractDecl) (evm : EVM.State) + (locals : Store) (body : Body) (result : ExecResult) : Prop := + ExecFuncBody cfg { contract := contract, locals := locals } evm body result + +-- Solm transaction dispatch and execution. +inductive solmExec + (conf : Config) + (contract : ContractDecl) /- Spec -/ + (createdAccounts : Batteries.RBSet Ethereum.AccountAddress compare) + (genesisBlockHeader : Ethereum.BlockHeader) + (blocks : Ethereum.ProcessedBlocks) + (σ : Ethereum.AccountMap) + (σ₀ : Ethereum.AccountMap) + (g : Ethereum.UInt256) + (A : Ethereum.Substate) + (I : Ethereum.ExecutionEnv) + (solmRes : ExecResult) +: ReturnConvention -> Prop where + | intro : + /- Solm selector transition dispatch. -/ + selectorDispatchMsg contract I.calldata = .some transition → + transitionSig = transitionSignature transition → + decodeCalldataWithMode conf.abiDecodeMode (transition.params.map Param.name) + transitionSig.paramTypes I.calldata = .some callargs → + evmState = + { (default : EVM.State) with + accountMap := σ + σ₀ := σ₀ + executionEnv := I + substate := A + createdAccounts := createdAccounts + machineState.gasAvailable := .ofUInt256 g + blocks := blocks + genesisBlockHeader := genesisBlockHeader + } → + ExecTransitionBody conf contract evmState callargs transition.body solmRes → + solmExec conf contract createdAccounts genesisBlockHeader blocks σ σ₀ g A I solmRes + (.abi transition.returnType) + | fallback : + /- Solidity fallback dispatch has no selector or ABI argument decoding. -/ + selectorDispatchMsg contract I.calldata = .none → + receiveDispatchMsg contract I.calldata = .none → + contract.fallback = .some transition → + fallbackCallargs I.calldata transition.params = some callargs → + fallbackReturnConvention transition = some returnConvention → + evmState = + { (default : EVM.State) with + accountMap := σ + σ₀ := σ₀ + executionEnv := I + substate := A + createdAccounts := createdAccounts + machineState.gasAvailable := .ofUInt256 g + blocks := blocks + genesisBlockHeader := genesisBlockHeader + } → + ExecTransitionBody conf contract evmState callargs transition.body solmRes → + solmExec conf contract createdAccounts genesisBlockHeader blocks σ σ₀ g A I solmRes + returnConvention + | receive : + /- Solidity receive dispatch has no selector or ABI argument decoding. -/ + receiveDispatchMsg contract I.calldata = .some transition → + transition.params = [] → + transition.returnType = [] → + evmState = + { (default : EVM.State) with + accountMap := σ + σ₀ := σ₀ + executionEnv := I + substate := A + createdAccounts := createdAccounts + machineState.gasAvailable := .ofUInt256 g + blocks := blocks + genesisBlockHeader := genesisBlockHeader + } → + ExecTransitionBody conf contract evmState ∅ transition.body solmRes → + solmExec conf contract createdAccounts genesisBlockHeader blocks σ σ₀ g A I solmRes (.abi []) + +-- Solm constructor execution. +inductive solmCtorExec + (conf : Config) + (contract : ContractDecl) /- Spec -/ + (args : List Value) + (createdAccounts : Batteries.RBSet Ethereum.AccountAddress compare) + (genesisBlockHeader : Ethereum.BlockHeader) + (blocks : Ethereum.ProcessedBlocks) + (σ : Ethereum.AccountMap) + (σ₀ : Ethereum.AccountMap) + (g : Ethereum.UInt256) + (A : Ethereum.Substate) + (I : Ethereum.ExecutionEnv) + (solmRes : ExecResult) +: Prop where + | intro : + evmState = + { (default : EVM.State) with + accountMap := σ + σ₀ := σ₀ + executionEnv := I + substate := A + createdAccounts := createdAccounts + machineState.gasAvailable := .ofUInt256 g + blocks := blocks + genesisBlockHeader := genesisBlockHeader + } → + -- This may be redundant when `cfg.selfDeployment` already enforces valid constructor ABI + -- encoding, but it keeps the parameter store from relying on `List.zip` truncation. + args.length = contract.ctor.params.length → + argsStore = Std.HashMap.ofList (List.zip (contract.ctor.params.map Param.name) args) → + ExecTransitionBody conf contract evmState argsStore contract.ctor.body solmRes → + solmCtorExec conf contract args createdAccounts genesisBlockHeader blocks σ σ₀ g A I solmRes + +end Solm diff --git a/Solm/Semantics/StorageOps.lean b/Solm/Semantics/StorageOps.lean new file mode 100644 index 00000000..40bf4766 --- /dev/null +++ b/Solm/Semantics/StorageOps.lean @@ -0,0 +1,340 @@ +import Solm.Semantics.Types +import Solm.Semantics.ValueOps + +/-! Structured storage operations: typed read/write/clear/default over the opaque layout. -/ + +namespace Solm + +open ABI + +/-- The declared `StorageType` reached by following one evaled step from a value of type `t`. -/ +def storageTypeStep? : StorageType -> EvaledStorageRefStep -> Option StorageType + | .struct _ fields, .field name => (fields.find? (fun f => f.1 == name)).map (·.2) + | .tuple ts, .tupleElem k => ts[k]? + | .mapping _ v, .mindex _ => some v + | .array t' _, .aindex _ => some t' + | .dynamicArray t', .aindex _ => some t' + | .bytes, .aindex _ => some (.elem (.int (.uint ⟨8, by decide⟩))) + | .string, .aindex _ => some (.elem (.int (.uint ⟨8, by decide⟩))) + | _, _ => none + +/-- The declared `StorageType` of whatever the evaled ref `er` points at, walked from the contract's + storage declarations (the type tree carried by the frame, independent of the opaque layout). -/ +def storageTypeAt? (decls : List StorageDecl) (er : EvaledStorageRef) : Option StorageType := do + let baseTy <- (decls.find? (fun d => d.name == er.base)).map (·.ty) + er.steps.foldlM storageTypeStep? baseTy + +def storageNatResultToEval : StorageReadResult Nat -> EvalResult Nat + | .ok n => .ok n + | .revert => .revert + | .error => .error .storageError + +def readStorageBytesLength? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : + EvalResult Nat := + match cfg.storage.readBytesLength er evm with + | some result => storageNatResultToEval result + | none => .error .storageError + +/-- Bounds-check a single array index `i` against the array reached by the evaled prefix `pre`. + Fixed arrays are checked against their declared static bound. Dynamic arrays are checked by + asking the layout for the distinct `.length` ref `layout {base, pre ++ [.length]}` and reading + the stored length. In both cases, an index outside `[0, length)` reverts, matching Solidity's + `Panic(0x32)`. + + This is invoked from `evalStorageRefStep` as each `.aindex` is evaluated, so the check is + interleaved with index evaluation exactly as solc emits it. -/ +@[simp] def arrayIndexInBounds? (cfg : Config) (evm : EVM.State) + (decls : List StorageDecl) (base : Ident) (pre : List EvaledStorageRefStep) (i : KeyValue) : + EvalResult Unit := + match storageTypeAt? decls { base := base, steps := pre }, i with + | some (.array _ n), .int iv => + if 0 ≤ iv ∧ iv < n then .ok () else .revert + | some (.array _ _), _ => .error .typeError + | some (.dynamicArray _), .int iv => + match cfg.storage.layout { base := base, steps := pre ++ [.length] } evm with + | some lenLoc => + match storageLocLoad evm lenLoc with + | .int len => if 0 ≤ iv ∧ iv < len then .ok () else .revert + | _ => .error .storageError + | none => .error .storageError + | some (.dynamicArray _), _ => .error .typeError + | some (.bytes), .int iv + | some (.string), .int iv => + match readStorageBytesLength? cfg evm { base := base, steps := pre } with + | .ok len => if 0 ≤ iv ∧ iv < len then .ok () else .revert + | .revert => .revert + | .error e => .error e + | some (.bytes), _ | some (.string), _ => .error .typeError + | some _, _ => .error .typeError + | none, _ => .error .storageError + +def storagePrepareResultToEval : StorageReadResult EVM.State -> EvalResult EVM.State + | .ok evm => .ok evm + | .revert => .revert + | .error => .error .storageError + +def storageValueResultToEval : StorageReadResult Value -> EvalResult Value + | .ok v => .ok v + | .revert => .revert + | .error => .error .storageError + +/- Recursively zero **every** storage slot occupied by a value of declared type `t` located at + `er` — solc's `delete`. Leaves are cleared through the opaque `layout`; the *structure* (struct + fields, tuple/fixed-array elements, dynamic-array length + all data) is driven by `t`, so a + nested dynamic array is cleared in full (its inner length is read and every inner element + recursively cleared). Mappings are skipped — their keys aren't enumerable, and solc's `delete` + on a mapping is likewise a no-op. -/ +mutual +def clearStorage? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : + StorageType -> EvalResult EVM.State + | .elem _ | .contract _ => + match cfg.storage.layout er evm with + | some loc => EvalResult.ofOption .storageError (storageLocStore evm loc (.int 0)) + | none => .error .storageError + | .mapping _ _ => .ok evm + | .struct _ fields => clearFields? cfg evm er fields + | .tuple ts => clearTupleElems? cfg evm er 0 ts + | .array t' n => clearArrayElems? cfg evm er t' n + | .dynamicArray t' => + match cfg.storage.layout { er with steps := er.steps ++ [.length] } evm with + | some lenLoc => + match storageLocLoad evm lenLoc with + | .int len => + match clearArrayElems? cfg evm er t' len.toNat with + | .ok evm1 => EvalResult.ofOption .storageError (storageLocStore evm1 lenLoc (.int 0)) + | r => r + | _ => .error .storageError + | none => .error .storageError + | .bytes => + match cfg.storage.clearValue? er .bytes evm with + | some result => storagePrepareResultToEval result + | none => .error .storageError + | .string => + match cfg.storage.clearValue? er .string evm with + | some result => storagePrepareResultToEval result + | none => .error .storageError + termination_by t => (sizeOf t, 0) + +def clearFields? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : + List (Ident × StorageType) -> EvalResult EVM.State + | [] => .ok evm + | (name, ft) :: rest => + match clearStorage? cfg evm { er with steps := er.steps ++ [.field name] } ft with + | .ok evm1 => clearFields? cfg evm1 er rest + | r => r + termination_by fields => (sizeOf fields, 0) + +def clearTupleElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (k : Nat) : + List StorageType -> EvalResult EVM.State + | [] => .ok evm + | tt :: rest => + match clearStorage? cfg evm { er with steps := er.steps ++ [.tupleElem k] } tt with + | .ok evm1 => clearTupleElems? cfg evm1 er (k+1) rest + | r => r + termination_by ts => (sizeOf ts, 0) + +def clearArrayElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (t' : StorageType) : + Nat -> EvalResult EVM.State + | 0 => .ok evm + | n+1 => + match clearStorage? cfg evm { er with steps := er.steps ++ [.aindex (.int n)] } t' with + | .ok evm1 => clearArrayElems? cfg evm1 er t' n + | r => r + termination_by c => (sizeOf t', c) +end + +/- Recursively write a structured `Value` into the storage of declared type `t` at `er` — the dual + of `clearStorage?`. Leaves go through the opaque `layout` + `storageLocStore`; structure (struct + fields, tuple/array elements) is driven by `t`, and a `dynamicArray` target also writes its + length. A type/value mismatch (or a mapping/`bytes` target) is an `.error`, never a partial + write. -/ +mutual +def writeStorage? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : + StorageType -> Value -> EvalResult EVM.State + | .elem _, v + | .contract _, v => + match cfg.storage.layout er evm with + | some loc => EvalResult.ofOption .storageError (storageLocStore evm loc v) + | none => .error .storageError + | .struct _ ftypes, .struct _ fvals => writeFields? cfg evm er ftypes fvals + | .tuple ts, .tuple vs => writeTupleElems? cfg evm er 0 ts vs + | .array t' n, .array vs => + if vs.length = n then writeArrayElems? cfg evm er t' 0 vs + else .error .typeError + | .dynamicArray t', .array vs => do + -- clear the existing array first, so old elements beyond the new (possibly shorter) length + -- don't linger — matching solc's array-assignment cleanup, and preserving the + -- zero-beyond-length invariant that grow-only `push` relies on + let evm0 <- clearStorage? cfg evm er (.dynamicArray t') + let evm1 <- writeArrayElems? cfg evm0 er t' 0 vs + let lenLoc <- EvalResult.ofOption .storageError + (cfg.storage.layout { er with steps := er.steps ++ [.length] } evm) + EvalResult.ofOption .storageError (storageLocStore evm1 lenLoc (.int vs.length)) + | .bytes, .bytes bs => + match cfg.storage.writeValue? er .bytes (.bytes bs) evm with + | some result => storagePrepareResultToEval result + | none => .error .storageError + | .string, .bytes bs => + match cfg.storage.writeValue? er .string (.bytes bs) evm with + | some result => storagePrepareResultToEval result + | none => .error .storageError + | _, _ => .error .typeError + termination_by t => (sizeOf t, 0) + +def writeFields? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : + List (Ident × StorageType) -> List (Ident × Value) -> EvalResult EVM.State + | [], [] => .ok evm + | (name, ft) :: trest, (vname, fv) :: vrest => + if name == vname then + match writeStorage? cfg evm { er with steps := er.steps ++ [.field name] } ft fv with + | .ok evm1 => writeFields? cfg evm1 er trest vrest + | r => r + else .error .typeError + | _, _ => .error .typeError + termination_by ftypes => (sizeOf ftypes, 0) + +def writeTupleElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (k : Nat) : + List StorageType -> List Value -> EvalResult EVM.State + | [], [] => .ok evm + | tt :: trest, v :: vrest => + match writeStorage? cfg evm { er with steps := er.steps ++ [.tupleElem k] } tt v with + | .ok evm1 => writeTupleElems? cfg evm1 er (k+1) trest vrest + | r => r + | _, _ => .error .typeError + termination_by ts => (sizeOf ts, 0) + +def writeArrayElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (t' : StorageType) + (k : Nat) : List Value -> EvalResult EVM.State + | [] => .ok evm + | v :: rest => + match writeStorage? cfg evm { er with steps := er.steps ++ [.aindex (.int k)] } t' v with + | .ok evm1 => writeArrayElems? cfg evm1 er t' (k+1) rest + | r => r + termination_by vs => (sizeOf t', sizeOf vs) +end + +/- Recursively read a value of declared type `t` out of storage at `er` into a `Value` — the read + dual of `writeStorage?`/`clearStorage?`. Leaves come from the opaque `layout` + `storageLocLoad`; + structure (struct fields, tuple/fixed-array elements, dynamic-array length + all data) is driven + by `t`, so a nested dynamic array is read in full. A mapping has no enumerable contents, so a + whole-mapping read is an `.error`. -/ +mutual +def readStorage? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : + StorageType -> EvalResult Value + | .elem _ + | .contract _ => + match cfg.storage.layout er evm with + | some loc => .ok (storageLocLoad evm loc) + | none => .error .storageError + | .mapping _ _ => .error .typeError + | .struct name fields => do + let fvals <- readFields? cfg evm er fields + pure (.struct name fvals) + | .tuple ts => do + let vs <- readTupleElems? cfg evm er 0 ts + pure (.tuple vs) + | .array t' n => do + let vs <- readArrayElems? cfg evm er t' 0 n + pure (.array vs) + | .dynamicArray t' => + match cfg.storage.layout { er with steps := er.steps ++ [.length] } evm with + | some lenLoc => + match storageLocLoad evm lenLoc with + | .int len => do + let vs <- readArrayElems? cfg evm er t' 0 len.toNat + pure (.array vs) + | _ => .error .storageError + | none => .error .storageError + | .bytes => + match cfg.storage.readValue? er .bytes evm with + | some result => storageValueResultToEval result + | none => .error .storageError + | .string => + match cfg.storage.readValue? er .string evm with + | some result => storageValueResultToEval result + | none => .error .storageError + termination_by t => (sizeOf t, 0) + +def readFields? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : + List (Ident × StorageType) -> EvalResult (List (Ident × Value)) + | [] => .ok [] + | (name, ft) :: rest => do + let v <- readStorage? cfg evm { er with steps := er.steps ++ [.field name] } ft + let vrest <- readFields? cfg evm er rest + pure ((name, v) :: vrest) + termination_by fields => (sizeOf fields, 0) + +def readTupleElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (k : Nat) : + List StorageType -> EvalResult (List Value) + | [] => .ok [] + | tt :: rest => do + let v <- readStorage? cfg evm { er with steps := er.steps ++ [.tupleElem k] } tt + let vrest <- readTupleElems? cfg evm er (k+1) rest + pure (v :: vrest) + termination_by ts => (sizeOf ts, 0) + +def readArrayElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (t' : StorageType) + (k : Nat) : Nat -> EvalResult (List Value) + | 0 => .ok [] + | c+1 => do + let v <- readStorage? cfg evm { er with steps := er.steps ++ [.aindex (.int k)] } t' + let vrest <- readArrayElems? cfg evm er t' (k+1) c + pure (v :: vrest) + termination_by c => (sizeOf t', c) +end + +def readStorageArrayLength? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) + : StorageType -> EvalResult Value + | .array _ n => pure (.int n) + | .elem (.bytes n) => pure (.int (fixedBytesSize n)) + | .dynamicArray _ => + match cfg.storage.layout { er with steps := er.steps ++ [.length] } evm with + | some lenLoc => + match storageLocLoad evm lenLoc with + | .int n => pure (.int n) + | _ => .error .storageError + | none => .error .storageError + | .bytes | .string => do + let len <- readStorageBytesLength? cfg evm er + pure (.int len) + | _ => .error .typeError + +mutual +def defaultValue? : StorageType -> EvalResult Value + | .elem (.bool) => pure (.bool false) + | .elem (.address) => pure (.address (.ofNat 0)) + | .elem (.bytes n) => pure (.fixedBytes n (List.replicate (n.val + 1) 0)) + | .elem _ => pure (.int 0) + | .contract _ => pure (.address (.ofNat 0)) + | .mapping _ _ => .error .typeError + | .struct name fields => do + let values <- defaultFields? fields + pure (.struct name values) + | .tuple ts => do + let values <- defaultValues? ts + pure (.tuple values) + | .array elemTy n => do + let value <- defaultValue? elemTy + pure (.array (List.replicate n value)) + | .dynamicArray _ => pure (.array []) + | .bytes | .string => pure (.bytes ByteArray.empty) + termination_by t => (sizeOf t, 0) + +def defaultFields? : List (Ident × StorageType) -> EvalResult (List (Ident × Value)) + | [] => pure [] + | (name, ty) :: rest => do + let value <- defaultValue? ty + let values <- defaultFields? rest + pure ((name, value) :: values) + termination_by fields => (sizeOf fields, 0) + +def defaultValues? : List StorageType -> EvalResult (List Value) + | [] => pure [] + | ty :: rest => do + let value <- defaultValue? ty + let values <- defaultValues? rest + pure (value :: values) + termination_by ts => (sizeOf ts, 0) +end + +end Solm diff --git a/Solm/Semantics/Types.lean b/Solm/Semantics/Types.lean new file mode 100644 index 00000000..332bc61e --- /dev/null +++ b/Solm/Semantics/Types.lean @@ -0,0 +1,31 @@ +import Solm.Storage +import Solm.Value +import ABI.Decode + +/-! Shared execution context: external-call ABI, configuration, and frames. -/ + +namespace Solm + +open ABI + +structure ExternalCallABI where + encode? : Ident -> List Value -> Option EVM.Bytes + decode? : Ident -> EVM.Bytes-> Option (List Value) + +structure Config where + storage : StorageLayout + externalABI : ExternalCallABI + abiDecodeMode : ABI.DecodeMode := ABI.DecodeMode.modern + /- Initialisation code (creation bytecode ++ ABI-encoded constructor args) for a + `new` of the named contract. -/ + creationCode : Ident -> List Value -> Option EVM.Bytes := fun _ _ => none + + /- Scheme for initialisation code (creation bytecode ++ ABI-encoded constructor args) for + deployment of the contract's constructor -/ + selfDeployment : EVM.Bytes → List Value → Option EVM.Bytes + +structure Frame where + contract : ContractDecl + locals : Store + +end Solm diff --git a/Solm/Semantics/ValueOps.lean b/Solm/Semantics/ValueOps.lean new file mode 100644 index 00000000..9ca4c971 --- /dev/null +++ b/Solm/Semantics/ValueOps.lean @@ -0,0 +1,472 @@ +import ABI.Encode +import Solm.Value + +/-! The evaluation monad (`EvalResult`) and value-level primitive operations. -/ + +namespace Solm + +open ABI + +/-- Solm evaluation errors. Should never happen in well-formed programs -/ +inductive EvalError where + | unboundVariable + | typeError + | storageError + deriving DecidableEq, Repr, Inhabited + +/-- Result of evaluating an Solm expression: + - a value (`ok`) + - a `revert` + - or an error, which indicates an ill-formed program +-/ +inductive EvalResult (α : Type) where + | ok : α -> EvalResult α + | revert : EvalResult α + | error : EvalError -> EvalResult α + deriving Repr, DecidableEq + +namespace EvalResult + +@[inline] def bind : EvalResult α -> (α -> EvalResult β) -> EvalResult β + | .ok a, f => f a + | .revert, _ => .revert + | .error e, _ => .error e + +instance : Monad EvalResult where + pure := .ok + bind := bind + +/-- Lift an `Option`, mapping `none` to the model-level `error e`. -/ +@[inline] def ofOption (e : EvalError) : Option α -> EvalResult α + | some a => .ok a + | none => .error e + +/-- Sequence a list of results, short-circuiting on the first `revert`/`error`. -/ +def seqList : List (EvalResult α) -> EvalResult (List α) + | [] => .ok [] + | x :: xs => do + let a <- x + let as <- seqList xs + .ok (a :: as) + +end EvalResult + +def envValue (evm : EVM.State) : EnvVar -> Value + | .caller => .address evm.executionEnv.source + | .origin => .address evm.executionEnv.sender + | .callvalue => .int (Int.ofNat evm.executionEnv.weiValue.val) + | .this => .address evm.executionEnv.codeOwner + | .timestamp => .int (Int.ofNat (Ethereum.UInt256.ofNat evm.executionEnv.header.timestamp).toNat) + | .chainid => .int (Int.ofNat Ethereum.chainId) + | .selfbalance => + .int (Int.ofNat ((evm.lookupAccount evm.executionEnv.codeOwner).option + (EVM.Word.ofNat 0) (·.balance)).toNat) + | .gasprice => .int (Int.ofNat (EVM.Word.ofNat evm.executionEnv.gasPrice).toNat) + -- Each mirrors the evmlean opcode handler (Semantics.lean:485-531) / StateOps.lean. + | .number => .int (Int.ofNat (EVM.Word.ofNat evm.executionEnv.header.number).toNat) -- NUMBER + | .coinbase => .address evm.executionEnv.header.beneficiary -- COINBASE + | .gaslimit => .int (Int.ofNat (EVM.Word.ofNat evm.executionEnv.header.gasLimit).toNat) -- GASLIMIT + | .prevrandao => .int (Int.ofNat evm.executionEnv.header.prevRandao.toNat) -- PREVRANDAO + | .basefee => .int (Int.ofNat (EVM.Word.ofNat evm.executionEnv.header.baseFeePerGas).toNat) -- BASEFEE + | .msgSig => + let b := evm.executionEnv.calldata.toList.take 4 + .fixedBytes ⟨3, by decide⟩ (b ++ List.replicate (4 - b.length) 0) + | .msgData => .bytes evm.executionEnv.calldata + +def valueToKey? (v : Value) : Option KeyValue := + match v with + | .int i => pure $ .int i + | .bool b => pure $ .bool b + | .address a => pure $ .address a + -- Reject a length-mismatched `bytesN` key loudly (avoid `keyValueToWord`'s silent slot-`0` fallback). + | .fixedBytes n bs => if bs.length = n.val + 1 then pure (.fixedBytes n bs) else .none + | _ => .none + +def lookupAssoc [DecidableEq α] (entries : List (α × β)) (key : α) : Option β := + match entries with + | [] => none + | (k, v) :: rest => if k = key then some v else lookupAssoc rest key + +def updateAssoc [DecidableEq α] (entries : List (α × β)) (key : α) (value : β) : + List (α × β) := + match entries with + | [] => [(key, value)] + | (k, v) :: rest => + if k = key then + (key, value) :: rest + else + (k, v) :: updateAssoc rest key value + +def updateNth? (xs : List α) (index : Nat) (value : α) : Option (List α) := + match xs, index with + | [], _ => none + | _ :: rest, 0 => some (value :: rest) + | x :: rest, i + 1 => do + let rest' <- updateNth? rest i value + pure (x :: rest') + +def lookupNth? (xs : List α) (index : Nat) : Option α := + match xs, index with + | [], _ => none + | x :: _, 0 => some x + | _ :: rest, i + 1 => lookupNth? rest i + +def intToNat? (n : Int) : Option Nat := + if n < 0 then none else some n.toNat + +def lookupField? (v : Value) (name : Ident) : Option Value := + match v with + | .struct _ fields => lookupAssoc fields name + | _ => none + +def updateField? (v : Value) (name : Ident) (value : Value) : Option Value := + match v with + | .struct tag fields => + match lookupAssoc fields name with + | some _ => some (.struct tag (updateAssoc fields name value)) + | none => none + | _ => none + +def lookupIndex? (container key : Value) : Option Value := + match container with + | .array elems => + match key with + | .int i => do + let idx <- intToNat? i + lookupNth? elems idx + | _ => none + | .fixedBytes n bytes => + match key with + | .int i => do + if bytes.length = n.val + 1 then + let idx <- intToNat? i + let b <- lookupNth? bytes idx + pure (.fixedBytes ⟨0, by decide⟩ [b]) + else + none + | _ => none + | .bytes bytes => + match key with + | .int i => do + let idx <- intToNat? i + let b <- lookupNth? bytes.toList idx + pure (.fixedBytes ⟨0, by decide⟩ [b]) + | _ => none + | _ => none + +def updateIndex? (container key value : Value) : Option Value := + match container with + | .array elems => + match key with + | .int i => do + let idx <- intToNat? i + let elems' <- updateNth? elems idx value + pure (.array elems') + | _ => none + | _ => none + +def fixedBytesSize (n : Fin 32) : Nat := + n.val + 1 + +def fixedBytesValid (n : Fin 32) (bytes : List UInt8) : Bool := + bytes.length = fixedBytesSize n + +def fixedBytesToNat? (n : Fin 32) (bytes : List UInt8) : Option Nat := + if fixedBytesValid n bytes then some (Ethereum.fromBytesBigEndian bytes) else none + +def castValue? (v : Value) (ty : StorageType) : Option Value := + match ty, v with + | .elem (.bool), .bool _ => some v + | .elem (.address), .address _ => some v + | .elem (.bytes expected), .fixedBytes actual _ => + if expected = actual then some v else none + -- A negative int fails loudly (silent `n.toNat = 0` would be a wrong value); literal-`0` casts are ≥0. + | .elem (.bytes expected), .int n => + if n < 0 then none + else some (.fixedBytes expected ((EVM.Word.ofNat n.toNat).toBytesBE.drop (32 - (expected.val + 1)))) + -- `address(n)`: an integer cast to `address` (e.g. `address(0)`), truncated to the address width. + | .elem (.address), .int n => if n < 0 then none else some (.address (.ofNat n.toNat)) + | .elem (.int (.uint bits)), .address a => + if a.toNat < EVM.twoPow bits.val then + some (.int (Int.ofNat a.toNat)) + else + none + -- `uintN(bytesN)`: solc allows this cast only at equal width (`8·(n+1) = bits`); the bytes are + -- read big-endian via the same `fixedBytesToNat?` the comparison/`bitAnd` cases use. + | .elem (.int (.uint bits)), .fixedBytes n bs => + if 8 * (n.val + 1) = bits.val then + match fixedBytesToNat? n bs with + | some k => some (.int (Int.ofNat k)) + | none => none + else none + | .elem (.int _), .int _ => some v + | .contract _, .address _ => some v + | .struct expected _, .struct actual _ => + if expected = actual then some v else none + | .array _ _, .array _ => some v + | .dynamicArray _, .array _ => some v + | _, _ => none + +-- `uint256(bytes32 0x…01) = 1`; a width mismatch (`uint128(bytes32)`) is rejected. +#guard castValue? (.fixedBytes ⟨31, by decide⟩ (List.replicate 31 0 ++ [1])) + (.elem (.int (.uint ⟨256, by decide⟩))) = some (.int 1) +#guard castValue? (.fixedBytes ⟨31, by decide⟩ (List.replicate 32 0)) + (.elem (.int (.uint ⟨128, by decide⟩))) = none + +def fixedBytesFromNat (n : Fin 32) (value : Nat) : Value := + .fixedBytes n ((EVM.Word.ofNat value).toBytesBE.drop (32 - fixedBytesSize n)) + +def fixedBytesBytewise? (f : UInt8 -> UInt8 -> UInt8) : + List UInt8 -> List UInt8 -> Option (List UInt8) + | [], [] => some [] + | x :: xs, y :: ys => do + let rest <- fixedBytesBytewise? f xs ys + some (f x y :: rest) + | _, _ => none + +def evalByteIndex? (bytes : List UInt8) (i : Int) : EvalResult Value := + if i < 0 then + .revert + else + let idx := i.toNat + if idx < bytes.length then + EvalResult.ofOption .typeError + (Option.map (fun b => Value.fixedBytes ⟨0, by decide⟩ [b]) (lookupNth? bytes idx)) + else + .revert + +def evalFixedBytesIndex? (n : Fin 32) (bytes : List UInt8) (i : Int) : EvalResult Value := + if fixedBytesValid n bytes then evalByteIndex? bytes i else .error .typeError + +def normalizeRawBoolWord? : Value -> EvalResult Value + | .tuple [.unit, .int n] => + if n = 0 then + .ok (.bool false) + else if n = 1 then + .ok (.bool true) + else + .revert + | v => .ok v + +def evalIndex? (container key : Value) : EvalResult Value := + match container, key with + | .array elems, .int i => + if 0 ≤ i ∧ i < elems.length then + match lookupNth? elems i.toNat with + | some v => normalizeRawBoolWord? v + | none => .error .typeError + else + .revert + | .fixedBytes n bytes, .int i => evalFixedBytesIndex? n bytes i + | .bytes bytes, .int i => evalByteIndex? bytes.toList i + | _, _ => .error .typeError + +def evalUnaryOp? (op : UnaryOp) (v : Value) : Option Value := + match op, v with + | .not, .bool b => some (.bool (!b)) + | .neg, .int i => some (.int (-i)) + | .bitNot, .fixedBytes n bytes => + if fixedBytesValid n bytes then some (.fixedBytes n (bytes.map (fun b => ~~~b))) else none + -- `~x` on an int is the word complement, defined only on `[0, 2^256)`. + | .bitNot, .int x => + if 0 ≤ x ∧ x < (EVM.wordModulus : Int) then some (.int (EVM.wordModulus - 1 - x.toNat)) + else none + | _, _ => none + +#guard evalUnaryOp? .bitNot (.int 0) = some (.int (EVM.wordModulus - 1)) +#guard evalUnaryOp? .bitNot (.int (EVM.wordModulus - 1)) = some (.int 0) +#guard evalUnaryOp? .bitNot (.int (-1)) = none + +def evalBinaryOp? (op : BinaryOp) (v₁ v₂ : Value) : EvalResult Value := + match op, v₁, v₂ with + | .add, .int x, .int y => .ok (.int (x + y)) + | .sub, .int x, .int y => .ok (.int (x - y)) + | .mul, .int x, .int y => .ok (.int (x * y)) + -- division/modulo by zero reverts (Solidity Panic 0x12) + | .div, .int x, .int y => if y = 0 then .revert else .ok (.int (x / y)) + | .mod, .int x, .int y => if y = 0 then .revert else .ok (.int (x % y)) + | .eq, .storageRef _ _, _ => .error .typeError + | .eq, _, .storageRef _ _ => .error .typeError + | .ne, .storageRef _ _, _ => .error .typeError + | .ne, _, .storageRef _ _ => .error .typeError + | .eq, x, y => .ok (.bool (x == y)) + | .ne, x, y => .ok (.bool (!(x == y))) + | .lt, .int x, .int y => .ok (.bool (x < y)) + | .le, .int x, .int y => .ok (.bool (x <= y)) + | .gt, .int x, .int y => .ok (.bool (x > y)) + | .ge, .int x, .int y => .ok (.bool (x >= y)) + -- addresses are zero-extended words on the stack, so word-LT ≡ Nat compare of their values. + | .lt, .address a, .address b => .ok (.bool (a.toNat < b.toNat)) + | .le, .address a, .address b => .ok (.bool (a.toNat <= b.toNat)) + | .gt, .address a, .address b => .ok (.bool (a.toNat > b.toNat)) + | .ge, .address a, .address b => .ok (.bool (a.toNat >= b.toNat)) + -- `x ** y`: exact integer power; exponent must be ≥ 0 (spec wraps `% 2^N` by hand, like add/mul). + | .exp, .int x, .int y => if y < 0 then .error .typeError else .ok (.int (x ^ y.toNat)) + | .lt, .fixedBytes n xs, .fixedBytes m ys => + if n = m then + match fixedBytesToNat? n xs, fixedBytesToNat? m ys with + | some x, some y => .ok (.bool (x < y)) + | _, _ => .error .typeError + else .error .typeError + | .le, .fixedBytes n xs, .fixedBytes m ys => + if n = m then + match fixedBytesToNat? n xs, fixedBytesToNat? m ys with + | some x, some y => .ok (.bool (x <= y)) + | _, _ => .error .typeError + else .error .typeError + | .gt, .fixedBytes n xs, .fixedBytes m ys => + if n = m then + match fixedBytesToNat? n xs, fixedBytesToNat? m ys with + | some x, some y => .ok (.bool (x > y)) + | _, _ => .error .typeError + else .error .typeError + | .ge, .fixedBytes n xs, .fixedBytes m ys => + if n = m then + match fixedBytesToNat? n xs, fixedBytesToNat? m ys with + | some x, some y => .ok (.bool (x >= y)) + | _, _ => .error .typeError + else .error .typeError + | .bitAnd, .fixedBytes n xs, .fixedBytes m ys => + if n = m then + if fixedBytesValid n xs && fixedBytesValid m ys then + match fixedBytesBytewise? (· &&& ·) xs ys with + | some zs => .ok (.fixedBytes n zs) + | none => .error .typeError + else .error .typeError + else .error .typeError + | .bitOr, .fixedBytes n xs, .fixedBytes m ys => + if n = m then + if fixedBytesValid n xs && fixedBytesValid m ys then + match fixedBytesBytewise? (· ||| ·) xs ys with + | some zs => .ok (.fixedBytes n zs) + | none => .error .typeError + else .error .typeError + else .error .typeError + | .bitXor, .fixedBytes n xs, .fixedBytes m ys => + if n = m then + if fixedBytesValid n xs && fixedBytesValid m ys then + match fixedBytesBytewise? (· ^^^ ·) xs ys with + | some zs => .ok (.fixedBytes n zs) + | none => .error .typeError + else .error .typeError + else .error .typeError + | .shl, .fixedBytes n xs, .int s => + if s < 0 then .error .typeError + else + match fixedBytesToNat? n xs with + | some x => + let width := 8 * fixedBytesSize n + if s.toNat >= width then .ok (.fixedBytes n (List.replicate (fixedBytesSize n) 0)) + else .ok (fixedBytesFromNat n (x * 2 ^ s.toNat)) + | none => .error .typeError + | .shr, .fixedBytes n xs, .int s => + if s < 0 then .error .typeError + else + match fixedBytesToNat? n xs with + | some x => + let width := 8 * fixedBytesSize n + if s.toNat >= width then .ok (.fixedBytes n (List.replicate (fixedBytesSize n) 0)) + else .ok (fixedBytesFromNat n (x / 2 ^ s.toNat)) + | none => .error .typeError + -- Integer bitwise/shift: defined only on operands in `[0, 2^256)`; a negative or oversized + -- operand is `.error .typeError`, so specs on signed values must re-encode to a word first. + | .bitAnd, .int x, .int y => + if 0 ≤ x ∧ x < (EVM.wordModulus : Int) ∧ 0 ≤ y ∧ y < (EVM.wordModulus : Int) then + .ok (.int (Nat.land x.toNat y.toNat)) + else .error .typeError + | .bitOr, .int x, .int y => + if 0 ≤ x ∧ x < (EVM.wordModulus : Int) ∧ 0 ≤ y ∧ y < (EVM.wordModulus : Int) then + .ok (.int (Nat.lor x.toNat y.toNat)) + else .error .typeError + | .bitXor, .int x, .int y => + if 0 ≤ x ∧ x < (EVM.wordModulus : Int) ∧ 0 ≤ y ∧ y < (EVM.wordModulus : Int) then + .ok (.int (Nat.xor x.toNat y.toNat)) + else .error .typeError + -- `x << s`: the shift `s` must be a non-negative int; `s ≥ 256` gives `0` (EVM `SHL`). + | .shl, .int x, .int s => + if 0 ≤ x ∧ x < (EVM.wordModulus : Int) ∧ 0 ≤ s then + if (256 : Int) ≤ s then .ok (.int 0) + else .ok (.int ((x.toNat * 2 ^ s.toNat) % EVM.wordModulus)) + else .error .typeError + -- `x >> s`: the shift `s` must be a non-negative int; `s ≥ 256` gives `0` (EVM `SHR`). + | .shr, .int x, .int s => + if 0 ≤ x ∧ x < (EVM.wordModulus : Int) ∧ 0 ≤ s then + if (256 : Int) ≤ s then .ok (.int 0) + else .ok (.int (x.toNat / 2 ^ s.toNat)) + else .error .typeError + | _, _, _ => .error .typeError + +-- Bitwise mask = mod; single-bit xor flip; `shl` wraps at the top word; `shr` of the max word; +-- and a negative operand is a type error. +#guard evalBinaryOp? .bitAnd (.int 0xABCDEF) (.int 0xFF) = .ok (.int (0xABCDEF % 256)) +#guard evalBinaryOp? .bitXor (.int 5) (.int 2) = .ok (.int 7) +#guard evalBinaryOp? .shl (.int (2 ^ 255)) (.int 1) = .ok (.int 0) +#guard evalBinaryOp? .shr (.int (2 ^ 256 - 1)) (.int 255) = .ok (.int 1) +#guard evalBinaryOp? .bitAnd (.int (-1)) (.int 0) = .error .typeError +#guard evalBinaryOp? .exp (.int 2) (.int 10) = .ok (.int 1024) +#guard evalBinaryOp? .exp (.int 0) (.int 0) = .ok (.int 1) +#guard evalBinaryOp? .exp (.int 2) (.int (-1)) = .error .typeError +#guard evalBinaryOp? .lt (.address (.ofNat 3)) (.address (.ofNat 5)) = .ok (.bool true) +#guard evalBinaryOp? .gt (.address (.ofNat 3)) (.address (.ofNat 5)) = .ok (.bool false) + +/-- Packed ("non-padded") ABI encoding of a single value, per Solidity's `abi.encodePacked`: each + value takes its natural byte width with no left/right padding and no length prefix — `uintN`/`intN` + are `N/8` big-endian bytes, `bool` is one byte, `address` is its 20 bytes, `bytesN` is its `N` + bytes, and dynamic `bytes` is its raw contents. Only the cases needed by current specs are + handled; anything else returns `none` rather than risk a silent mis-encoding. -/ +-- `abi.encodePacked` of an array: each element is a full 32-byte padded word, no length prefix +-- (verified from solc 0.8.35 Yul IR — `add(pos, 0x20)` per element). Elementary elements only +-- (`encodeABIWord?` returns `none` for nested/dynamic element types). +def encodePackedArrayElems? (elemTy : ABIType) : List Value → Option (List UInt8) + | [] => some [] + | v :: vs => do + let w <- encodeABIWord? elemTy v + let rest <- encodePackedArrayElems? elemTy vs + some (EVM.Word.toBytesBE w ++ rest) + +def encodePackedValue? (ty : ABIType) (v : Value) : Option (List UInt8) := + match ty, v with + | .elem .bool, .bool b => some [if b then (1 : UInt8) else 0] + | .array elemTy _, .array vs => encodePackedArrayElems? elemTy vs + | .dynamicArray elemTy, .array vs => encodePackedArrayElems? elemTy vs + | .elem .address, .address a => some ((EVM.word a).toBytesBE.drop 12) + | .elem (.int (.uint bits)), .int _ => do + let w <- encodeABIWord? ty v + some (w.toBytesBE.drop (32 - bits.val / 8)) + | .elem (.int (.sint bits)), .int _ => do + let w <- encodeABIWord? ty v + some (w.toBytesBE.drop (32 - bits.val / 8)) + | .elem (.bytes n), .fixedBytes m bytes => + if m = n ∧ bytes.length = fixedBytesSize n then some bytes else none + | .bytes, .bytes ba => some ba.toList + | .string, .bytes ba => some ba.toList + | _, _ => none + +#guard encodePackedValue? (.dynamicArray (.elem (.int (.uint ⟨8, by decide⟩)))) (.array [.int 1, .int 2]) + = some (List.replicate 31 0 ++ [1] ++ List.replicate 31 0 ++ [2]) + +-- `b[s:e]`: solc compiles `d[x:y]` to two `GT → REVERT` guards (verified solc 0.6.12 & 0.8.35): +-- revert iff `s > e` or `e > b.size`; negative bounds are ill-typed. +def sliceBytes? (ba : ByteArray) (s e : Int) : EvalResult Value := + if s < 0 || e < 0 then .error .typeError + else if s.toNat > e.toNat || e.toNat > ba.size then .revert + else .ok (.bytes (ba.extract s.toNat e.toNat)) + +#guard sliceBytes? (ByteArray.mk #[10, 20, 30, 40, 50]) 1 3 = .ok (.bytes (ByteArray.mk #[20, 30])) +#guard sliceBytes? (ByteArray.mk #[10, 20, 30]) 0 3 = .ok (.bytes (ByteArray.mk #[10, 20, 30])) +#guard sliceBytes? (ByteArray.mk #[10, 20, 30]) 0 4 = .revert +#guard sliceBytes? (ByteArray.mk #[10, 20, 30]) 2 1 = .revert +#guard sliceBytes? (ByteArray.mk #[10, 20, 30]) 2 2 = .ok (.bytes (ByteArray.mk #[])) +#guard sliceBytes? (ByteArray.mk #[10, 20, 30]) (-1) 2 = .error .typeError + +def tupleGetValue? (v : Value) (i : Nat) : EvalResult Value := + match v with + | .tuple vs => match vs[i]? with | some c => .ok c | none => .error .typeError + | _ => .error .typeError + +#guard tupleGetValue? (.tuple [.int 7, .bool true]) 0 = .ok (.int 7) +#guard tupleGetValue? (.tuple [.int 7, .bool true]) 1 = .ok (.bool true) +#guard tupleGetValue? (.tuple [.int 7, .bool true]) 2 = .error .typeError +#guard tupleGetValue? (.int 7) 0 = .error .typeError + +end Solm From c712982d3c7f22fe45fad05d08237c2b4bb63362 Mon Sep 17 00:00:00 2001 From: zoep Date: Sat, 25 Jul 2026 18:59:19 +0300 Subject: [PATCH 09/38] Solm: remove marks from equiv name --- Benchmarks/Auction/Correct.lean | 2 +- Benchmarks/CompoundIII/Comet/Correct.lean | 2 +- .../CompoundIII/CometRewards/Correct.lean | 2 +- Benchmarks/Dss/Cat/Correct.lean | 4 +-- Benchmarks/Dss/Dai/Correct.lean | 2 +- Benchmarks/Dss/DaiJoin/Correct.lean | 4 +-- Benchmarks/Dss/Dog/Correct.lean | 2 +- Benchmarks/Dss/End/Correct.lean | 4 +-- .../Dss/ExponentialDecrease/Correct.lean | 4 +-- Benchmarks/Dss/Flapper/Correct.lean | 4 +-- Benchmarks/Dss/Flipper/Correct.lean | 4 +-- Benchmarks/Dss/Flopper/Correct.lean | 4 +-- Benchmarks/Dss/GemJoin/Correct.lean | 4 +-- Benchmarks/Dss/Jug/Correct.lean | 4 +-- Benchmarks/Dss/LinearDecrease/Correct.lean | 4 +-- Benchmarks/Dss/Pot/Correct.lean | 4 +-- Benchmarks/Dss/Spot/Correct.lean | 4 +-- .../StairstepExponentialDecrease/Correct.lean | 4 +-- Benchmarks/Dss/Vat/Correct.lean | 4 +-- Benchmarks/Dss/Vow/Correct.lean | 6 ++-- Benchmarks/EAS/Attester/Correct.lean | 4 +-- Benchmarks/ERC721/Correct.lean | 4 +-- Benchmarks/Klima/Correct.lean | 2 +- .../TimelockController/Correct.lean | 2 +- .../VestingWallet/Correct.lean | 2 +- Benchmarks/Safe/Correct.lean | 2 +- Benchmarks/UniswapV2Router02/Correct.lean | 2 +- Benchmarks/UniswapV3Pool/Correct.lean | 2 +- Benchmarks/WETH9/Correct.lean | 2 +- Examples/Ballot/Correct.lean | 4 +-- Examples/BlindAuction/Correct.lean | 4 +-- Examples/Caller/Correct.lean | 2 +- Examples/CtorStore/Correct.lean | 2 +- Examples/CtorTruth/Correct.lean | 2 +- Examples/ERC20/Correct.lean | 2 +- .../AccessControl/Correct.lean | 2 +- .../OpenZeppelinBench/ERC6909/Correct.lean | 2 +- .../Ownable2Step/Correct.lean | 2 +- .../OpenZeppelinBench/Pausable/Correct.lean | 2 +- Examples/Pow/Correct.lean | 2 +- Examples/Reuse/Correct.lean | 2 +- Examples/SimpleAuction/Correct.lean | 2 +- Examples/StringStoreLite/Correct.lean | 6 ++-- Examples/TinyImmutable/Correct.lean | 2 +- Examples/Truth/Correct.lean | 2 +- Examples/UniswapV2Pair/Correct.lean | 2 +- Examples/VyperERC20/Correct.lean | 2 +- README.md | 2 +- Reasoning/Constructor.lean | 2 +- Reasoning/MISSPEC.md | 2 +- Reasoning/Theory.lean | 2 +- Solm/Equiv.lean | 30 +++++++---------- Solm/Semantics.lean | 3 +- Solm/Semantics/Calls.lean | 13 ++++---- Solm/Semantics/Eval.lean | 4 +-- Solm/Semantics/Exec.lean | 23 ++++++------- Solm/Semantics/StorageOps.lean | 32 +++++++++---------- Solm/Semantics/Types.lean | 8 ++--- Solm/Semantics/ValueOps.lean | 20 ++++++------ TODO.md | 2 +- prompt.md | 2 +- 61 files changed, 139 insertions(+), 144 deletions(-) diff --git a/Benchmarks/Auction/Correct.lean b/Benchmarks/Auction/Correct.lean index e47ed001..da0b2df6 100644 --- a/Benchmarks/Auction/Correct.lean +++ b/Benchmarks/Auction/Correct.lean @@ -13,7 +13,7 @@ runtime targets. open Solm ABI Ethereum Ethereum.EVM theorem auctionCorrect : - runtimeEquivalence!?! auctionConfig auctionBytecode Auction.auctionContract := by + runtimeEquivalence auctionConfig auctionBytecode Auction.auctionContract := by sorry theorem auctionContractCorrect : diff --git a/Benchmarks/CompoundIII/Comet/Correct.lean b/Benchmarks/CompoundIII/Comet/Correct.lean index 8ecd920b..73a1982b 100644 --- a/Benchmarks/CompoundIII/Comet/Correct.lean +++ b/Benchmarks/CompoundIII/Comet/Correct.lean @@ -16,7 +16,7 @@ namespace Benchmarks.CompoundIII.Comet theorem cometCorrect (v : CometImmutables) {code : ByteArray} (hcode : patchRuntime cometBytecode (patches v) = some code) : - runtimeEquivalence!?! (config v) code (contract v) := by + runtimeEquivalence (config v) code (contract v) := by sorry theorem cometContractCorrect (v : CometImmutables) {code : ByteArray} diff --git a/Benchmarks/CompoundIII/CometRewards/Correct.lean b/Benchmarks/CompoundIII/CometRewards/Correct.lean index 6ab13000..79dec9da 100644 --- a/Benchmarks/CompoundIII/CometRewards/Correct.lean +++ b/Benchmarks/CompoundIII/CometRewards/Correct.lean @@ -24,7 +24,7 @@ open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.R namespace Benchmarks.CompoundIII.CometRewards theorem cometRewardsCorrect : - runtimeEquivalence!?! config cometRewardsBytecode contract := by + runtimeEquivalence config cometRewardsBytecode contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ diff --git a/Benchmarks/Dss/Cat/Correct.lean b/Benchmarks/Dss/Cat/Correct.lean index 33be3b26..620af3f5 100644 --- a/Benchmarks/Dss/Cat/Correct.lean +++ b/Benchmarks/Dss/Cat/Correct.lean @@ -115,8 +115,8 @@ theorem catNoSelectorMatches {I : ExecutionEnv} · simpa [catSelBytes, selIs] using hwards theorem catCorrect : - runtimeEquivalence!?! config catBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config catBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hbite : selIs I ⟨#[0x45, 0xcf, 0x22, 0x30]⟩ diff --git a/Benchmarks/Dss/Dai/Correct.lean b/Benchmarks/Dss/Dai/Correct.lean index 9bfa967a..8cc7bbd2 100644 --- a/Benchmarks/Dss/Dai/Correct.lean +++ b/Benchmarks/Dss/Dai/Correct.lean @@ -360,7 +360,7 @@ theorem daiNoDispatch {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (daiDispatch_none_short hshort) theorem daiCorrect : - runtimeEquivalence!?! config daiBytecode contract := by + runtimeEquivalence config daiBytecode contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hsz : 4 ≤ I.calldata.size diff --git a/Benchmarks/Dss/DaiJoin/Correct.lean b/Benchmarks/Dss/DaiJoin/Correct.lean index 778503a2..3bbbad97 100644 --- a/Benchmarks/Dss/DaiJoin/Correct.lean +++ b/Benchmarks/Dss/DaiJoin/Correct.lean @@ -25,8 +25,8 @@ set_option maxRecDepth 2000000 namespace Benchmarks.Dss.DaiJoin theorem daiJoinCorrect : - runtimeEquivalence!?! config daiJoinBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config daiJoinBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hcage : selIs I (daiJoinSelBytes 0) diff --git a/Benchmarks/Dss/Dog/Correct.lean b/Benchmarks/Dss/Dog/Correct.lean index 61d16dec..ebd2f66e 100644 --- a/Benchmarks/Dss/Dog/Correct.lean +++ b/Benchmarks/Dss/Dog/Correct.lean @@ -15,7 +15,7 @@ namespace Benchmarks.Dss.Dog theorem dogCorrect (v : DogImmutables) {code : ByteArray} (hcode : patchRuntime dogBytecode (patches v) = some code) : - runtimeEquivalence!?! (config v) code (contract v) := by + runtimeEquivalence (config v) code (contract v) := by sorry theorem dogContractCorrect (v : DogImmutables) {code : ByteArray} diff --git a/Benchmarks/Dss/End/Correct.lean b/Benchmarks/Dss/End/Correct.lean index b69574ee..9c682c6f 100644 --- a/Benchmarks/Dss/End/Correct.lean +++ b/Benchmarks/Dss/End/Correct.lean @@ -42,8 +42,8 @@ open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.R namespace Benchmarks.Dss.End theorem endCorrect : - runtimeEquivalence!?! config endBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config endBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hwards : selIs I (selectorOf wardsTransition) diff --git a/Benchmarks/Dss/ExponentialDecrease/Correct.lean b/Benchmarks/Dss/ExponentialDecrease/Correct.lean index f4076d9b..fea83c7f 100644 --- a/Benchmarks/Dss/ExponentialDecrease/Correct.lean +++ b/Benchmarks/Dss/ExponentialDecrease/Correct.lean @@ -20,8 +20,8 @@ open Solm ABI Ethereum Ethereum.EVM namespace Benchmarks.Dss.ExponentialDecrease theorem exponentialDecreaseCorrect : - runtimeEquivalence!?! config exponentialDecreaseBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config exponentialDecreaseBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hcut : selIs I (stairstepSelBytes 0) diff --git a/Benchmarks/Dss/Flapper/Correct.lean b/Benchmarks/Dss/Flapper/Correct.lean index 322113e6..32d84b16 100644 --- a/Benchmarks/Dss/Flapper/Correct.lean +++ b/Benchmarks/Dss/Flapper/Correct.lean @@ -34,8 +34,8 @@ open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.R namespace Benchmarks.Dss.Flapper theorem flapperCorrect : - runtimeEquivalence!?! config flapperBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config flapperBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hbeg : selIs I (flapperSelBytes 0) diff --git a/Benchmarks/Dss/Flipper/Correct.lean b/Benchmarks/Dss/Flipper/Correct.lean index 177c3a86..b49c3996 100644 --- a/Benchmarks/Dss/Flipper/Correct.lean +++ b/Benchmarks/Dss/Flipper/Correct.lean @@ -78,8 +78,8 @@ theorem flipperNoSelectorMatches {I : ExecutionEnv} · simpa [selIs, flipperSelBytes] using hyank theorem flipperCorrect : - runtimeEquivalence!?! config flipperBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config flipperBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hbeg : selIs I (flipperSelBytes 0) diff --git a/Benchmarks/Dss/Flopper/Correct.lean b/Benchmarks/Dss/Flopper/Correct.lean index 3617c44b..2d5198ec 100644 --- a/Benchmarks/Dss/Flopper/Correct.lean +++ b/Benchmarks/Dss/Flopper/Correct.lean @@ -34,8 +34,8 @@ open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.R namespace Benchmarks.Dss.Flopper theorem flopperCorrect : - runtimeEquivalence!?! config flopperBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config flopperBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hbeg : selIs I (flopperSelBytes 0) diff --git a/Benchmarks/Dss/GemJoin/Correct.lean b/Benchmarks/Dss/GemJoin/Correct.lean index fe7b7bd6..0648a13b 100644 --- a/Benchmarks/Dss/GemJoin/Correct.lean +++ b/Benchmarks/Dss/GemJoin/Correct.lean @@ -23,8 +23,8 @@ open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.R namespace Benchmarks.Dss.GemJoin theorem gemJoinCorrect : - runtimeEquivalence!?! config gemJoinBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config gemJoinBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hcage : selIs I (gemJoinSelBytes 0) diff --git a/Benchmarks/Dss/Jug/Correct.lean b/Benchmarks/Dss/Jug/Correct.lean index 44f1d1f4..06e9a00e 100644 --- a/Benchmarks/Dss/Jug/Correct.lean +++ b/Benchmarks/Dss/Jug/Correct.lean @@ -95,8 +95,8 @@ theorem jugNoSelectorMatches {I : ExecutionEnv} · simpa [selIs, jugSelBytes] using hwards theorem jugCorrect : - runtimeEquivalence!?! config jugBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config jugBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hbase : selIs I (jugSelBytes 0) diff --git a/Benchmarks/Dss/LinearDecrease/Correct.lean b/Benchmarks/Dss/LinearDecrease/Correct.lean index 2211d7cb..90003892 100644 --- a/Benchmarks/Dss/LinearDecrease/Correct.lean +++ b/Benchmarks/Dss/LinearDecrease/Correct.lean @@ -20,8 +20,8 @@ open Solm ABI Ethereum Ethereum.EVM namespace Benchmarks.Dss.LinearDecrease theorem linearDecreaseCorrect : - runtimeEquivalence!?! config linearDecreaseBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config linearDecreaseBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hdeny : selIs I (stairstepSelBytes 0) diff --git a/Benchmarks/Dss/Pot/Correct.lean b/Benchmarks/Dss/Pot/Correct.lean index 3eaceaa5..308e8c43 100644 --- a/Benchmarks/Dss/Pot/Correct.lean +++ b/Benchmarks/Dss/Pot/Correct.lean @@ -101,8 +101,8 @@ theorem potNoSelectorMatches {I : ExecutionEnv} · simpa [selIs] using h16 theorem potCorrect : - runtimeEquivalence!?! config potBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config potBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases h0 : selIs I (potSelBytes 0) diff --git a/Benchmarks/Dss/Spot/Correct.lean b/Benchmarks/Dss/Spot/Correct.lean index 701ada10..dfed380e 100644 --- a/Benchmarks/Dss/Spot/Correct.lean +++ b/Benchmarks/Dss/Spot/Correct.lean @@ -28,8 +28,8 @@ set_option maxRecDepth 2000000 namespace Benchmarks.Dss.Spot theorem spotCorrect : - runtimeEquivalence!?! config spotBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config spotBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hcage : selIs I (spotSelBytes 0) diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Correct.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Correct.lean index 5e55649a..babb2f19 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Correct.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Correct.lean @@ -23,8 +23,8 @@ set_option maxRecDepth 2000000 namespace Benchmarks.Dss.StairstepExponentialDecrease theorem stairstepExponentialDecreaseCorrect : - runtimeEquivalence!?! config stairstepExponentialDecreaseBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config stairstepExponentialDecreaseBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hcut : selIs I (stairstepSelBytes 0) diff --git a/Benchmarks/Dss/Vat/Correct.lean b/Benchmarks/Dss/Vat/Correct.lean index be9e13a5..82e63b7b 100644 --- a/Benchmarks/Dss/Vat/Correct.lean +++ b/Benchmarks/Dss/Vat/Correct.lean @@ -152,8 +152,8 @@ theorem vatNoSelectorMatches {I : ExecutionEnv} · simpa [selIs] using hwards theorem vatCorrect : - runtimeEquivalence!?! config vatBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config vatBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hLine : selIs I (vatSelBytes 0) diff --git a/Benchmarks/Dss/Vow/Correct.lean b/Benchmarks/Dss/Vow/Correct.lean index bdbc7f5c..7b85c00d 100644 --- a/Benchmarks/Dss/Vow/Correct.lean +++ b/Benchmarks/Dss/Vow/Correct.lean @@ -174,8 +174,8 @@ theorem vowCorrectWith selIs I ⟨#[0xbb, 0xbb, 0x0d, 0x7b]⟩ → accountMapEquiv σ_evm σ_solm → runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I) : - runtimeEquivalence!?! config vowBytecode contract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence config vowBytecode contract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hAsh : selIs I ⟨#[0x2a, 0x1d, 0x2b, 0x3c]⟩ @@ -279,7 +279,7 @@ theorem vowCorrectWith · exact vowNonPayable hcode hwv theorem vowCorrect : - runtimeEquivalence!?! config vowBytecode contract := by + runtimeEquivalence config vowBytecode contract := by exact vowCorrectWith vowCageBody vowFlapBody vowFlopBody theorem vowContractCorrect : diff --git a/Benchmarks/EAS/Attester/Correct.lean b/Benchmarks/EAS/Attester/Correct.lean index e3267fde..9f566971 100644 --- a/Benchmarks/EAS/Attester/Correct.lean +++ b/Benchmarks/EAS/Attester/Correct.lean @@ -20,8 +20,8 @@ namespace Benchmarks.EAS.Attester theorem attesterCorrect (v : AttesterImmutables) {code : ByteArray} (hcode : patchRuntime attesterBytecode (patches v) = some code) : - runtimeEquivalence!?! (config v) code (contract v) := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence (config v) code (contract v) := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hIcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hshort : I.calldata.size < 4 diff --git a/Benchmarks/ERC721/Correct.lean b/Benchmarks/ERC721/Correct.lean index e700fa7d..2079f160 100644 --- a/Benchmarks/ERC721/Correct.lean +++ b/Benchmarks/ERC721/Correct.lean @@ -14,7 +14,7 @@ import Mathlib.Tactic.IntervalCases /-! # ERC721 — top-level correctness **scaffold** -Routing skeleton for `erc721Correct : runtimeEquivalence!?! …`, mirroring +Routing skeleton for `erc721Correct : runtimeEquivalence …`, mirroring `Examples/ERC20/Correct.lean` / `Examples/Ballot/Correct.lean`: `by_cases` on `callvalue = 0`, `size ≥ 4`, then each of the seven selectors, dispatching to that function's body obligation, with the shared revert paths. @@ -162,7 +162,7 @@ theorem erc721NoDispatch {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} /-! ## Top-level theorem — drive the dispatcher, route each body to its correctness -/ /-- The deployed ERC721 runtime bytecode refines the Solm specification, for every initial state. -/ -theorem erc721Correct : runtimeEquivalence!?! erc721Config erc721Bytecode erc721Contract := by +theorem erc721Correct : runtimeEquivalence erc721Config erc721Bytecode erc721Contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ diff --git a/Benchmarks/Klima/Correct.lean b/Benchmarks/Klima/Correct.lean index 99d69ef9..9006b34a 100644 --- a/Benchmarks/Klima/Correct.lean +++ b/Benchmarks/Klima/Correct.lean @@ -15,7 +15,7 @@ open Solm ABI Ethereum Ethereum.EVM namespace Benchmarks.Klima theorem klimaCorrect : - runtimeEquivalence!?! config klimaBytecode contract := by + runtimeEquivalence config klimaBytecode contract := by sorry theorem klimaContractCorrect : diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Correct.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Correct.lean index ab21021b..e714a11f 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Correct.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Correct.lean @@ -46,7 +46,7 @@ set_option maxRecDepth 2000000 namespace OpenZeppelinBench.TimelockController theorem timelockControllerBenchCorrect : - runtimeEquivalence!?! config timelockControllerBenchBytecode contract := by + runtimeEquivalence config timelockControllerBenchBytecode contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hsz : 4 ≤ I.calldata.size · by_cases h0 : selIs I (tlcSelBytes 0) diff --git a/Benchmarks/OpenZeppelinBench/VestingWallet/Correct.lean b/Benchmarks/OpenZeppelinBench/VestingWallet/Correct.lean index e75851f0..e75b2e4b 100644 --- a/Benchmarks/OpenZeppelinBench/VestingWallet/Correct.lean +++ b/Benchmarks/OpenZeppelinBench/VestingWallet/Correct.lean @@ -14,7 +14,7 @@ open Solm ABI Ethereum Ethereum.EVM namespace OpenZeppelinBench.VestingWallet theorem vestingWalletBenchCorrect : - runtimeEquivalence!?! config vestingWalletBenchBytecode contract := by + runtimeEquivalence config vestingWalletBenchBytecode contract := by sorry theorem vestingWalletBenchContractCorrect : diff --git a/Benchmarks/Safe/Correct.lean b/Benchmarks/Safe/Correct.lean index 35afe279..0146e18d 100644 --- a/Benchmarks/Safe/Correct.lean +++ b/Benchmarks/Safe/Correct.lean @@ -14,7 +14,7 @@ open Solm ABI Ethereum Ethereum.EVM namespace Benchmarks.Safe theorem safeCorrect : - runtimeEquivalence!?! config safeBytecode contract := by + runtimeEquivalence config safeBytecode contract := by sorry theorem safeContractCorrect : diff --git a/Benchmarks/UniswapV2Router02/Correct.lean b/Benchmarks/UniswapV2Router02/Correct.lean index 1c732e60..1c0855eb 100644 --- a/Benchmarks/UniswapV2Router02/Correct.lean +++ b/Benchmarks/UniswapV2Router02/Correct.lean @@ -16,7 +16,7 @@ namespace Benchmarks.UniswapV2Router02 theorem uniswapV2Router02Correct (v : RouterImmutables) {code : ByteArray} (hcode : patchRuntime uniswapV2Router02Bytecode (patches v) = some code) : - runtimeEquivalence!?! (config v) code (contract v) := by + runtimeEquivalence (config v) code (contract v) := by sorry theorem uniswapV2Router02ContractCorrect (v : RouterImmutables) {code : ByteArray} diff --git a/Benchmarks/UniswapV3Pool/Correct.lean b/Benchmarks/UniswapV3Pool/Correct.lean index c725eb6f..904a936d 100644 --- a/Benchmarks/UniswapV3Pool/Correct.lean +++ b/Benchmarks/UniswapV3Pool/Correct.lean @@ -17,7 +17,7 @@ namespace Benchmarks.UniswapV3Pool theorem uniswapV3PoolCorrect (v : PoolImmutables) {code : ByteArray} (hcode : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - runtimeEquivalence!?! (config v) code (contract v) := by + runtimeEquivalence (config v) code (contract v) := by constructor intro cA gh bl σ_evm σ_solm σ₀ g A I hIcode hsize hperm haccounts by_cases hwv : I.weiValue = ⟨0⟩ diff --git a/Benchmarks/WETH9/Correct.lean b/Benchmarks/WETH9/Correct.lean index 94786153..85516458 100644 --- a/Benchmarks/WETH9/Correct.lean +++ b/Benchmarks/WETH9/Correct.lean @@ -27,7 +27,7 @@ set_option maxRecDepth 2000000 namespace Benchmarks.WETH9 theorem weth9Correct : - runtimeEquivalence!?! config weth9Bytecode contract := by + runtimeEquivalence config weth9Bytecode contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hsz : 4 ≤ I.calldata.size · by_cases h0 : selIs I (weth9SelBytes 0) diff --git a/Examples/Ballot/Correct.lean b/Examples/Ballot/Correct.lean index 21aec738..3adf8335 100644 --- a/Examples/Ballot/Correct.lean +++ b/Examples/Ballot/Correct.lean @@ -21,7 +21,7 @@ import Mathlib.Tactic.IntervalCases /-! # Ballot — top-level correctness proof -This is the routing proof for `ballotCorrect : runtimeEquivalence!?! …`. It mirrors +This is the routing proof for `ballotCorrect : runtimeEquivalence …`. It mirrors `Examples/ERC20/Correct.lean`: `by_cases` on `callvalue = 0`, `size ≥ 4`, then each of the eight selectors, dispatching to that function's body obligation, with the shared revert paths. @@ -602,7 +602,7 @@ theorem ballotNoDispatch {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} /-! ## Top-level theorem — drive the dispatcher, route each body to its correctness -/ /-- The deployed Ballot runtime bytecode refines the Solm specification, for every initial state. -/ -theorem ballotCorrect : runtimeEquivalence!?! ballotConfig ballotBytecode ballotContract := by +theorem ballotCorrect : runtimeEquivalence ballotConfig ballotBytecode ballotContract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ diff --git a/Examples/BlindAuction/Correct.lean b/Examples/BlindAuction/Correct.lean index f88dd430..08a8315a 100644 --- a/Examples/BlindAuction/Correct.lean +++ b/Examples/BlindAuction/Correct.lean @@ -16,7 +16,7 @@ import Reasoning.Refinement # BlindAuction — top-level correctness proof This file is the Phase 0 dispatcher assembly for -`blindAuctionCorrect : runtimeEquivalence!?! …`. It follows the optimizer-on binary-search +`blindAuctionCorrect : runtimeEquivalence …`. It follows the optimizer-on binary-search dispatcher shape shared with Ballot/SimpleAuction, but with BlindAuction's payable top-level dispatcher: calldata size and selector routing happen before any callvalue check, and non-payable guards are proved inside the individual body files. @@ -31,7 +31,7 @@ namespace BlindAuction /-- The deployed BlindAuction runtime bytecode refines the Solm specification. -/ theorem blindAuctionCorrect : - runtimeEquivalence!?! blindAuctionConfig blindAuctionBytecode blindAuctionContract := by + runtimeEquivalence blindAuctionConfig blindAuctionBytecode blindAuctionContract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hsz : 4 ≤ I.calldata.size diff --git a/Examples/Caller/Correct.lean b/Examples/Caller/Correct.lean index 714baaa5..657434d4 100644 --- a/Examples/Caller/Correct.lean +++ b/Examples/Caller/Correct.lean @@ -1324,7 +1324,7 @@ theorem callerReEquiv_callvalueZero /-- The runtime bytecode refines the Solm specification, for every initial state. -/ theorem callerCorrect : - runtimeEquivalence!?! callerConfig callerBytecode callerContract := by + runtimeEquivalence callerConfig callerBytecode callerContract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hσ => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ diff --git a/Examples/CtorStore/Correct.lean b/Examples/CtorStore/Correct.lean index 41c8c783..02270b71 100644 --- a/Examples/CtorStore/Correct.lean +++ b/Examples/CtorStore/Correct.lean @@ -45,7 +45,7 @@ theorem ctorStoreRuntimeRevert {cA gh bl σ σ₀ A I} {g : Sat256} raw rev 0 (by decide) mem_cost (by evm_ov)] theorem ctorStoreRuntimeCorrect : - runtimeEquivalence!?! ctorStoreConfig ctorStoreRuntimeBytecode CtorStore.contract := by + runtimeEquivalence ctorStoreConfig ctorStoreRuntimeBytecode CtorStore.contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode _hsize _hperm _hσ => ?_⟩ exact (ctorStoreRuntimeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) diff --git a/Examples/CtorTruth/Correct.lean b/Examples/CtorTruth/Correct.lean index ea02d945..7e295db7 100644 --- a/Examples/CtorTruth/Correct.lean +++ b/Examples/CtorTruth/Correct.lean @@ -90,7 +90,7 @@ theorem ctorTruthReEquiv_callvalueZero /-- Runtime bytecode refines the Solm runtime specification. -/ theorem ctorTruthRuntimeCorrect : - runtimeEquivalence!?! ctorTruthConfig ctorTruthRuntimeBytecode CtorTruth.contract := by + runtimeEquivalence ctorTruthConfig ctorTruthRuntimeBytecode CtorTruth.contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize _hperm hσ => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ · exact ctorTruthReEquiv_callvalueZero (g := Sat256.ofUInt256 g) hcode hsize hwv hσ diff --git a/Examples/ERC20/Correct.lean b/Examples/ERC20/Correct.lean index 17e08b0b..26ac7208 100644 --- a/Examples/ERC20/Correct.lean +++ b/Examples/ERC20/Correct.lean @@ -353,7 +353,7 @@ theorem erc20NonPayable {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} `callvalue ≠ 0` / short calldata / no-match revert; otherwise the dispatcher machinery (`erc20ReachBody`) drives the EVM to the matched function's body entry, handed to that function's body obligation. -/ -theorem erc20Correct : runtimeEquivalence!?! erc20Config erc20Bytecode erc20Contract := by +theorem erc20Correct : runtimeEquivalence erc20Config erc20Bytecode erc20Contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ diff --git a/Examples/OpenZeppelinBench/AccessControl/Correct.lean b/Examples/OpenZeppelinBench/AccessControl/Correct.lean index 6ccd6a21..faa73185 100644 --- a/Examples/OpenZeppelinBench/AccessControl/Correct.lean +++ b/Examples/OpenZeppelinBench/AccessControl/Correct.lean @@ -68,7 +68,7 @@ theorem accessControlNoDispatch {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 /-- The deployed AccessControl benchmark runtime bytecode refines the Solm specification. -/ theorem accessControlCorrect : - runtimeEquivalence!?! config accessControlBenchBytecode contract := by + runtimeEquivalence config accessControlBenchBytecode contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hsz : 4 ≤ I.calldata.size diff --git a/Examples/OpenZeppelinBench/ERC6909/Correct.lean b/Examples/OpenZeppelinBench/ERC6909/Correct.lean index 489c3ecc..2b50b949 100644 --- a/Examples/OpenZeppelinBench/ERC6909/Correct.lean +++ b/Examples/OpenZeppelinBench/ERC6909/Correct.lean @@ -223,7 +223,7 @@ theorem erc6909NoDispatch {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} /-- The deployed ERC6909 benchmark runtime bytecode refines the Solm specification. -/ theorem erc6909Correct : - runtimeEquivalence!?! config erc6909BenchBytecode contract := by + runtimeEquivalence config erc6909BenchBytecode contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ diff --git a/Examples/OpenZeppelinBench/Ownable2Step/Correct.lean b/Examples/OpenZeppelinBench/Ownable2Step/Correct.lean index aa19c219..c0c9a182 100644 --- a/Examples/OpenZeppelinBench/Ownable2Step/Correct.lean +++ b/Examples/OpenZeppelinBench/Ownable2Step/Correct.lean @@ -11,7 +11,7 @@ set_option maxRecDepth 2000000 namespace OpenZeppelinBench.Ownable2Step /-- The deployed Ownable2Step benchmark runtime bytecode refines the Solm specification. -/ -theorem ownable2StepCorrect : runtimeEquivalence!?! config ownable2StepBenchBytecode contract := by +theorem ownable2StepCorrect : runtimeEquivalence config ownable2StepBenchBytecode contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hsz : 4 ≤ I.calldata.size diff --git a/Examples/OpenZeppelinBench/Pausable/Correct.lean b/Examples/OpenZeppelinBench/Pausable/Correct.lean index 7b7ddfbf..afa4d8f7 100644 --- a/Examples/OpenZeppelinBench/Pausable/Correct.lean +++ b/Examples/OpenZeppelinBench/Pausable/Correct.lean @@ -18,7 +18,7 @@ hands the body proof to the one-function file for that selector. -/ theorem pausableCorrect : - runtimeEquivalence!?! config pausableBenchBytecode contract := by + runtimeEquivalence config pausableBenchBytecode contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hsz : 4 ≤ I.calldata.size diff --git a/Examples/Pow/Correct.lean b/Examples/Pow/Correct.lean index 5f9fd428..1f890317 100644 --- a/Examples/Pow/Correct.lean +++ b/Examples/Pow/Correct.lean @@ -921,7 +921,7 @@ theorem powXiSuccess {cA gh bl σ σ₀ A I} {g : Sat256} (powX_success hcode hwv hsz36 hsz255 hmatch hn).xiResult hcode /-- **Runtime equivalence of `Pow.sol`'s `pow2` bytecode and its Solm specification.** -/ -theorem powCorrect : runtimeEquivalence!?! powConfig powBytecode Pow.powContract := by +theorem powCorrect : runtimeEquivalence powConfig powBytecode Pow.powContract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize _hperm hσ => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ · exact powReEquiv_callvalueZero (g := Sat256.ofUInt256 g) hcode hwv hsize hσ diff --git a/Examples/Reuse/Correct.lean b/Examples/Reuse/Correct.lean index f2917940..979587d2 100644 --- a/Examples/Reuse/Correct.lean +++ b/Examples/Reuse/Correct.lean @@ -1130,7 +1130,7 @@ theorem cReEquiv_callvalueZero {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact cNoDispatch hcode hsize hperm hwv hnm /-- **Correctness of `C`.** -/ -theorem cCorrect : runtimeEquivalence!?! cConfig cBytecode Reuse.cContract := by +theorem cCorrect : runtimeEquivalence cConfig cBytecode Reuse.cContract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hσ => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ · exact cReEquiv_callvalueZero hcode hsize hperm hwv hσ diff --git a/Examples/SimpleAuction/Correct.lean b/Examples/SimpleAuction/Correct.lean index af5589ca..90d0b727 100644 --- a/Examples/SimpleAuction/Correct.lean +++ b/Examples/SimpleAuction/Correct.lean @@ -48,7 +48,7 @@ theorem simpleAuctionNoDispatch {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 /-- The deployed SimpleAuction runtime bytecode refines the Solm specification. -/ theorem simpleAuctionCorrect : - runtimeEquivalence!?! simpleAuctionConfig simpleAuctionBytecode simpleAuctionContract := by + runtimeEquivalence simpleAuctionConfig simpleAuctionBytecode simpleAuctionContract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hsz : 4 ≤ I.calldata.size diff --git a/Examples/StringStoreLite/Correct.lean b/Examples/StringStoreLite/Correct.lean index 8f3c16a7..9fe2be35 100644 --- a/Examples/StringStoreLite/Correct.lean +++ b/Examples/StringStoreLite/Correct.lean @@ -3,7 +3,7 @@ import Examples.StringStoreLite.SetLong /-! # StringStoreLite — top-level runtime assembly -This file assembles the proved per-branch facts into a `runtimeEquivalence!?!` entry point. +This file assembles the proved per-branch facts into a `runtimeEquivalence` entry point. Dispatch, revert, getter, malformed calldata/header, zero-header empty-string, valid empty old-long, and short non-empty old-short execution branches are proved in imported modules. -/ @@ -277,8 +277,8 @@ theorem stringStoreLiteClearCurrentRuntime set_option maxHeartbeats 1200000 in theorem stringStoreLiteCorrect : - runtimeEquivalence!?! stringStoreLiteConfig stringStoreLiteBytecode stringStoreLiteContract := by - refine runtimeEquivalence!?!.intro ?_ + runtimeEquivalence stringStoreLiteConfig stringStoreLiteBytecode stringStoreLiteContract := by + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hsz : 4 ≤ I.calldata.size diff --git a/Examples/TinyImmutable/Correct.lean b/Examples/TinyImmutable/Correct.lean index 13fa8f20..52a86c0f 100644 --- a/Examples/TinyImmutable/Correct.lean +++ b/Examples/TinyImmutable/Correct.lean @@ -49,7 +49,7 @@ theorem tinyNonPayable {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} theorem tinyImmutableCorrect (v : TinyImmutables) {code : ByteArray} (hcode : patchRuntime tinyImmutableBytecode (patches v) = some code) : - runtimeEquivalence!?! (config v) code (contract v) := by + runtimeEquivalence (config v) code (contract v) := by have hcode' := code_eq_patchedRuntime_of_patch (v := v) hcode subst code refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hIcode hsize _hperm hAccounts => ?_⟩ diff --git a/Examples/Truth/Correct.lean b/Examples/Truth/Correct.lean index 53c89225..0cf2ecb4 100644 --- a/Examples/Truth/Correct.lean +++ b/Examples/Truth/Correct.lean @@ -249,7 +249,7 @@ theorem truthReEquiv_callvalueZero /-- The runtime bytecode refines the Solm specification, for every initial state. -/ theorem truthCorrect : - runtimeEquivalence!?! truthConfig truthBytecode truthContract := by + runtimeEquivalence truthConfig truthBytecode truthContract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize _hperm hσ => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ · exact truthReEquiv_callvalueZero (g := Sat256.ofUInt256 g) hcode hsize hwv hσ diff --git a/Examples/UniswapV2Pair/Correct.lean b/Examples/UniswapV2Pair/Correct.lean index d3574905..872d2eeb 100644 --- a/Examples/UniswapV2Pair/Correct.lean +++ b/Examples/UniswapV2Pair/Correct.lean @@ -44,7 +44,7 @@ open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.R namespace UniswapV2Pair theorem uniswapV2PairCorrect : - runtimeEquivalence!?! config uniswapV2PairBytecode contract := by + runtimeEquivalence config uniswapV2PairBytecode contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ · by_cases hsz : 4 ≤ I.calldata.size diff --git a/Examples/VyperERC20/Correct.lean b/Examples/VyperERC20/Correct.lean index 0036f1cb..aef99613 100644 --- a/Examples/VyperERC20/Correct.lean +++ b/Examples/VyperERC20/Correct.lean @@ -1630,7 +1630,7 @@ The dispatcher routing is explicit here. The proven Vyper function-body obligat `approve`, `totalSupply`, `balanceOf`, `transfer`, and `allowance`; only `transferFrom` success remains isolated above as a bytecode obligation. -/ theorem runtimeCorrect : - runtimeEquivalence!?! config vyperERC20Bytecode contract := by + runtimeEquivalence config vyperERC20Bytecode contract := by refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ by_cases hwv : I.weiValue = ⟨0⟩ · by_cases h0 : ((⟨#[0x09, 0x5e, 0xa7, 0xb3]⟩ : ByteArray) == I.calldata.extract 0 4) = true diff --git a/README.md b/README.md index 3352ad74..f716e82a 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The primary ... for such proofs is to be generated by LLMs and be checked agains A completed proof is a Lean theorem, e.g. ```lean -theorem erc20Correct : runtimeEquivalence!?! erc20Config erc20Bytecode erc20Contract +theorem erc20Correct : runtimeEquivalence erc20Config erc20Bytecode erc20Contract ``` Quantified over every reachable EVM state and every input, it says that either the diff --git a/Reasoning/Constructor.lean b/Reasoning/Constructor.lean index 46238221..fb1d6037 100644 --- a/Reasoning/Constructor.lean +++ b/Reasoning/Constructor.lean @@ -143,7 +143,7 @@ theorem emptyContractCorrect_of_RDret I.code = initcode → RDret initcode g (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) (createdAccounts, σ) runtimeCode) - (hruntime : runtimeEquivalence!?! cfg runtimeCode contract) : + (hruntime : runtimeEquivalence cfg runtimeCode contract) : contractEquivalence cfg initcode runtimeCode contract := contractEquivalence.intro (emptyConstructorCorrect_of_RDret hself hparams hbody hrun) diff --git a/Reasoning/MISSPEC.md b/Reasoning/MISSPEC.md index 599ab591..afec738a 100644 --- a/Reasoning/MISSPEC.md +++ b/Reasoning/MISSPEC.md @@ -129,7 +129,7 @@ selector). Once the base defects are fixed, both become `decide`-provable and ca # `Pow.powCorrect` (the `pow2(uint256 n)` contract) -`powCorrect : runtimeEquivalence!?! powConfig powBytecode Pow.powContract` is **fully proved — +`powCorrect : runtimeEquivalence powConfig powBytecode Pow.powContract` is **fully proved — no `sorry`**. `#print axioms Pow.powCorrect` ⇒ `[propext, Classical.choice, Quot.sound, ByteArray_zeroes_size, byteArray_zeroes_toList, powSelectorBytes, powValidJumps]`. diff --git a/Reasoning/Theory.lean b/Reasoning/Theory.lean index bff36907..a2c91793 100644 --- a/Reasoning/Theory.lean +++ b/Reasoning/Theory.lean @@ -6,7 +6,7 @@ import Ethereum.Theory.OpcodeLemmas # Theory — reusable, compositional lemmas for runtime-equivalence proofs General, **contract-agnostic** infrastructure for proving -`runtimeEquivalence!?! cfg bytecode contract`. +`runtimeEquivalence cfg bytecode contract`. Lemmas here are about `runtimeEquivalenceFor`, `actExec`, `execResultsEquiv`, `returnEquiv`, and the EVM driver `Ethereum.EVM.Ξ` / `X` / `Xstep` — never about a diff --git a/Solm/Equiv.lean b/Solm/Equiv.lean index deae48e4..2d077c2d 100644 --- a/Solm/Equiv.lean +++ b/Solm/Equiv.lean @@ -9,6 +9,7 @@ open ABI with a declared return type falls through without an explicit `return`: the EVM then returns the ABI encoding of this value (e.g. 32 zero bytes for `uint`), not empty output. Only the elementary types the model supports are covered. -/ +/- TODO move -/ def defaultAbiValue : ABIType -> Option Value | .elem .bool => some (.bool false) | .elem .address => some (.address (.ofNat 0)) @@ -16,6 +17,7 @@ def defaultAbiValue : ABIType -> Option Value | .elem (.bytes n) => some (.fixedBytes n (List.replicate (n.val + 1) 0)) | _ => none +/- Equivalence of ABI-returned data -/ inductive returnEquiv (o : ByteArray) (r : Option (List Value)) (t : List ABIType) : Prop where | returned : /- Explicit `return`: the returned values encode flat to the output. `vs = []`, `t = []` @@ -47,6 +49,7 @@ inductive returnEquiv (o : ByteArray) (r : Option (List Value)) (t : List ABITyp @[simp] theorem encodeReturnValue_eq_singleton (t : ABIType) (v : Value) : encodeReturnValue? t v = encodeReturnValues? [t] [v] := rfl +/- Equivalence of return data -/ inductive returnDataEquiv (o : ByteArray) (r : Option (List Value)) : ReturnConvention → Prop where | abi {t} : returnEquiv o r t → @@ -127,9 +130,7 @@ inductive execResultsEquiv (evmRes: Except Ethereum.EVM.ExecutionException (Ethereum.ExecutionResult (Batteries.RBSet Ethereum.AccountAddress compare × Ethereum.AccountMap × Ethereum.UInt256 × Ethereum.Substate))) (solmRes : ExecResult) (returnConvention : ReturnConvention) : Prop where | success : - -- Resulting states are compared up to storage-map representation (`accountMapEquiv`), the - -- sound notion given `SSTORE` zero-canonicalization / `RBMap` non-extensionality. Syntactic - -- equality is a special case, so this single constructor subsumes it. + -- Resulting states are compared up to storage-map representation (`accountMapEquiv`). evmRes = .ok (.success (createdAccounts', σ', g', A') o) → solmRes = .returned _ solmState retVal → createdAccounts' = solmState.createdAccounts → @@ -180,13 +181,6 @@ inductive ctorResultEquiv evmRes = .error .InvalidInstruction → solmRes = .reverted → ctorResultEquiv evmRes solmRes runtimeCode - -- Zoe: commenting out so that it matches execResultsEquiv - -- | error : - -- -- TODO: is this what needs to happen? - -- -- Zoe: Do we model all errors in Solm? AFAICT right now, some may cause the evaluation relation to be uninhabited (undef behavior) - -- evmRes = .error e → - -- solmRes = .reverted → - -- ctorResultEquiv evmRes solmRes runtimeCode inductive runtimeEquivalenceFor (cfg : Config) (contract : ContractDecl) /- Spec -/ @@ -197,7 +191,7 @@ inductive runtimeEquivalenceFor (cfg : Config) (σ_evm : Ethereum.AccountMap) -- Solm-side initial maps (fed to `solmExec`). They need only be `accountMapEquiv` to the -- EVM-side `σ_evm`/`σ₀` (not syntactically equal); the storage-observational semantics make - -- the two executions agree. The coupling is imposed as a precondition at `runtimeEquivalence!?!`. + -- the two executions agree. The coupling is imposed as a precondition at `runtimeEquivalence`. (σ_solm : Ethereum.AccountMap) (σ₀ : Ethereum.AccountMap) (g : Ethereum.UInt256) @@ -235,7 +229,7 @@ def trivialStorageWF : StorageWF := fun _ _ => True /-- Runtime equivalence under a contract-specific storage well-formedness precondition. -This is the same runtime relation as `runtimeEquivalence!?!`, except the caller must additionally +This is the same runtime relation as `runtimeEquivalence`, except the caller must additionally prove `wf σ_evm I` for the EVM-side initial storage and execution environment. The old unconditional relation remains available as before; new contracts that need reachable-state or layout invariants can use this parameterized entry point. -/ @@ -261,7 +255,7 @@ inductive runtimeEquivalenceWithWF (wf : StorageWF) (cfg : Config) (bytecode : B runtimeEquivalenceWithWF wf cfg bytecode contract -- a Solm contract corresponds to what? -inductive runtimeEquivalence!?! (cfg : Config) (bytecode : ByteArray) (contract : ContractDecl) : Prop where +inductive runtimeEquivalence (cfg : Config) (bytecode : ByteArray) (contract : ContractDecl) : Prop where | intro : (∀ (createdAccounts : Batteries.RBSet Ethereum.AccountAddress compare) (genesisBlockHeader : Ethereum.BlockHeader) @@ -284,17 +278,17 @@ inductive runtimeEquivalence!?! (cfg : Config) (bytecode : ByteArray) (contract accountMapEquiv σ_evm σ_solm → runtimeEquivalenceFor cfg contract createdAccounts genesisBlockHeader blocks σ_evm σ_solm σ₀ g A I ) → - runtimeEquivalence!?! cfg bytecode contract + runtimeEquivalence cfg bytecode contract theorem runtimeEquivalenceWithWF_trivial_iff {cfg : Config} {bytecode : ByteArray} {contract : ContractDecl} : runtimeEquivalenceWithWF trivialStorageWF cfg bytecode contract ↔ - runtimeEquivalence!?! cfg bytecode contract := by + runtimeEquivalence cfg bytecode contract := by constructor · intro h cases h with | intro hrun => - refine runtimeEquivalence!?!.intro ?_ + refine runtimeEquivalence.intro ?_ intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts exact hrun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts trivial · intro h @@ -379,7 +373,7 @@ inductive constructorEquivalence (cfg : Config) (initcode : ByteArray) (contract inductive contractEquivalence (cfg : Config) (initcode : EVM.Bytes) (runtimeCode : EVM.Bytes) (contract : ContractDecl) : Prop where | intro : constructorEquivalence cfg initcode contract runtimeCode → - runtimeEquivalence!?! cfg runtimeCode contract → + runtimeEquivalence cfg runtimeCode contract → contractEquivalence cfg initcode runtimeCode contract inductive contractEquivalenceWF (wf : StorageWF) (cfg : Config) (initcode : EVM.Bytes) @@ -479,7 +473,7 @@ inductive contractEquivalenceWith (cfg : Config) (initcode : EVM.Bytes) (runtime (contract : ContractDecl) (runtimeCodeOf : Store → Option ByteArray) : Prop where | intro : constructorEquivalenceWith cfg initcode contract runtimeCodeOf → - runtimeEquivalence!?! cfg runtimeCode contract → + runtimeEquivalence cfg runtimeCode contract → contractEquivalenceWith cfg initcode runtimeCode contract runtimeCodeOf inductive contractEquivalenceWithWF (wf : StorageWF) (cfg : Config) (initcode : EVM.Bytes) diff --git a/Solm/Semantics.lean b/Solm/Semantics.lean index 1df4b864..38b6d06f 100644 --- a/Solm/Semantics.lean +++ b/Solm/Semantics.lean @@ -1,4 +1,3 @@ -/- Solm Semantics -/ import Solm.Semantics.Types import Solm.Semantics.Dispatch import Solm.Semantics.ValueOps @@ -6,3 +5,5 @@ import Solm.Semantics.StorageOps import Solm.Semantics.Eval import Solm.Semantics.Calls import Solm.Semantics.Exec + +/-! The Solm semantics, split by layer. Import this module to get all of it. -/ diff --git a/Solm/Semantics/Calls.lean b/Solm/Semantics/Calls.lean index 8a37f285..6b0b809e 100644 --- a/Solm/Semantics/Calls.lean +++ b/Solm/Semantics/Calls.lean @@ -133,13 +133,8 @@ def typedCallViaEVM (cfg : Config) (evm : EVM.State) (target : EVM.Address) ∃ calldata, cfg.externalABI.encode? name args = some calldata ∧ callViaEVM evm target value calldata result perm --- Contract creation (`new`) via the EVM `Λ` (Lambda) function. The result triple is --- `(addr, evm', success)`: the created contract's address, the resulting EVM state, --- and whether creation succeeded. Mirrors `callViaEVM`, but `Λ` runs the --- initialisation code instead of a message call and returns the new address. - --- Preconditions under which a `new` (the `CREATE` opcode) actually runs the init code, --- mirroring the guards the opcode checks before calling `Lambda`. +/-- Preconditions under which a `new` (the `CREATE` opcode) actually runs the init code, + mirroring the guards the opcode checks before calling `Lambda`. -/ def newCanCreate (evm : EVM.State) (value : ℤ) (initCode : EVM.Bytes) : Prop := let creator := evm.accountMap.find? evm.executionEnv.codeOwner |>.getD default EVM.wordOfInt value ≤ creator.balance -- creator can afford the endowment @@ -147,6 +142,10 @@ def newCanCreate (evm : EVM.State) (value : ℤ) (initCode : EVM.Bytes) : Prop : ∧ creator.nonce.toNat < 2 ^ 64 - 1 -- creator nonce below the cap (EIP-2681) ∧ initCode.size ≤ 49152 -- init code within the limit (EIP-3860) +/-- Contract creation (`new`) via the EVM `Λ` (Lambda) function. The result triple is + `(addr, evm', success)`: the created contract's address, the resulting EVM state, + and whether creation succeeded. Mirrors `callViaEVM`, but `Λ` runs the + initialisation code instead of a message call and returns the new address. -/ inductive newViaEVM (cfg : Config) (evm : EVM.State) (name : Ident) (value : ℤ) (args : List Value) (salt : Option ByteArray) : (EVM.Address × EVM.State × Bool) → Prop where diff --git a/Solm/Semantics/Eval.lean b/Solm/Semantics/Eval.lean index 13154663..26cdbe28 100644 --- a/Solm/Semantics/Eval.lean +++ b/Solm/Semantics/Eval.lean @@ -7,9 +7,9 @@ namespace Solm open ABI --- Defining a measure for termination of the next mutual block, --- that evaluates expressions and related types mutual + /-- Termination measure for the expression-evaluating mutual block below + (`evalExpr?` and related helpers). -/ def exprEvalSize : Expr → Nat | .intLit _ => 1 | .boolLit _ => 1 diff --git a/Solm/Semantics/Exec.lean b/Solm/Semantics/Exec.lean index f48d89e5..d9ab08b4 100644 --- a/Solm/Semantics/Exec.lean +++ b/Solm/Semantics/Exec.lean @@ -9,9 +9,9 @@ namespace Solm open ABI inductive ExecResult where - /- The returned-value component is `Option (List Value)`: `none` means the body fell through - without executing `return`; `some vs` is an explicit `return` of the listed values (`some []` - is an explicit void return). -/ + /-- The returned-value component is `Option (List Value)`: `none` means the body fell through + without executing `return`; `some vs` is an explicit `return` of the listed values (`some []` + is an explicit void return). -/ | returned : Frame -> EVM.State -> Option (List Value) -> ExecResult | ok : Frame -> EVM.State -> ExecResult | break : Frame -> EVM.State -> ExecResult @@ -57,7 +57,7 @@ def lookupCallable? (contract : ContractDecl) (name : Ident) : Option CallableDe | some decl => some decl | none => lookupTransition? contract.transitions name --- CREATE2 salt: a `bytes32` value → its 32 salt bytes; anything else is invalid. +/-- CREATE2 salt: a `bytes32` value → its 32 salt bytes; anything else is invalid. -/ def saltBytes? : Value → Option ByteArray | .fixedBytes n bs => if n.val = 31 ∧ bs.length = 32 then some (ByteArray.mk bs.toArray) else none | _ => none @@ -157,7 +157,7 @@ def deleteStorage? (cfg : Config) (solm : Frame) (evm : EVM.State) (ref : Storag let (er, ty) <- resolveStorageRef? cfg solm evm ref clearStorage? cfg evm er ty --- Evaluate a `new`'s optional salt: `none` ⇒ CREATE; `some e` must be a `bytes32` ⇒ CREATE2. +/-- Evaluate a `new`'s optional salt: `none` ⇒ CREATE; `some e` must be a `bytes32` ⇒ CREATE2. -/ def evalSalt? (cfg : Config) (solm : Frame) (evm : EVM.State) : Option Expr → EvalResult (Option ByteArray) | none => .ok none @@ -185,8 +185,8 @@ inductive ExecStmt (cfg : Config) : | letStorageRevert : resolveStorageRef? cfg solm evm ref = .revert -> ExecStmt cfg solm evm (.letStorage name ref) .reverted - -- `gasleft()`: Solm tracks no gas, so any word `w` is a legal result. A proof picks the `w` - -- matching the EVM's actual gas at the corresponding `GAS` opcode. + /-- `gasleft()`: Solm tracks no gas, so any word `w` is a legal result. A proof picks the `w` + matching the EVM's actual gas at the corresponding `GAS` opcode. -/ | letGas (w : EVM.Word) : ExecStmt cfg solm evm (.letGas name) (.ok { solm with locals := solm.locals.insert name (.int (Int.ofNat w.toNat)) } evm) @@ -267,7 +267,7 @@ inductive ExecStmt (cfg : Config) : ExecBlock cfg solm evm body (.continue solm' evm') -> ExecStmt cfg solm' evm' (.while condExpr body) result -> ExecStmt cfg solm evm (.while condExpr body) result - -- `for (init; cond; post) { body }`: run `init` once, then loop via `ExecForLoop`. + /-- `for (init; cond; post) { body }`: run `init` once, then loop via `ExecForLoop`. -/ | for : ExecBlock cfg solm evm init (.ok solm1 evm1) -> ExecForLoop cfg solm1 evm1 condExpr post body result -> @@ -555,7 +555,8 @@ inductive ExecFuncBody (cfg : Config) : | execBlockRevert : ExecBlock cfg solm evm body .reverted -> ExecFuncBody cfg solm evm body .reverted - -- A `break`/`continue` that occurs outside a loop is malformed. We have to handle it so that ExecFuncBody is never stuck. + /-- A `break`/`continue` that occurs outside a loop is malformed. We have to handle it so that + `ExecFuncBody` is never stuck. -/ | execBlockBreak : ExecBlock cfg solm evm body (.break solm' evm') -> ExecFuncBody cfg solm evm body (.returned solm' evm' none) @@ -569,7 +570,7 @@ def ExecTransitionBody (cfg : Config) (contract : ContractDecl) (evm : EVM.State (locals : Store) (body : Body) (result : ExecResult) : Prop := ExecFuncBody cfg { contract := contract, locals := locals } evm body result --- Solm transaction dispatch and execution. +/-- Solm transaction dispatch and execution. -/ inductive solmExec (conf : Config) (contract : ContractDecl) /- Spec -/ @@ -643,7 +644,7 @@ inductive solmExec ExecTransitionBody conf contract evmState ∅ transition.body solmRes → solmExec conf contract createdAccounts genesisBlockHeader blocks σ σ₀ g A I solmRes (.abi []) --- Solm constructor execution. +/-- Solm constructor execution. -/ inductive solmCtorExec (conf : Config) (contract : ContractDecl) /- Spec -/ diff --git a/Solm/Semantics/StorageOps.lean b/Solm/Semantics/StorageOps.lean index 40bf4766..6001b2af 100644 --- a/Solm/Semantics/StorageOps.lean +++ b/Solm/Semantics/StorageOps.lean @@ -78,13 +78,13 @@ def storageValueResultToEval : StorageReadResult Value -> EvalResult Value | .revert => .revert | .error => .error .storageError -/- Recursively zero **every** storage slot occupied by a value of declared type `t` located at - `er` — solc's `delete`. Leaves are cleared through the opaque `layout`; the *structure* (struct - fields, tuple/fixed-array elements, dynamic-array length + all data) is driven by `t`, so a - nested dynamic array is cleared in full (its inner length is read and every inner element - recursively cleared). Mappings are skipped — their keys aren't enumerable, and solc's `delete` - on a mapping is likewise a no-op. -/ mutual +/-- Recursively zero **every** storage slot occupied by a value of declared type `t` located at + `er` — solc's `delete`. Leaves are cleared through the opaque `layout`; the *structure* (struct + fields, tuple/fixed-array elements, dynamic-array length + all data) is driven by `t`, so a + nested dynamic array is cleared in full (its inner length is read and every inner element + recursively cleared). Mappings are skipped — their keys aren't enumerable, and solc's `delete` + on a mapping is likewise a no-op. -/ def clearStorage? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : StorageType -> EvalResult EVM.State | .elem _ | .contract _ => @@ -143,12 +143,12 @@ def clearArrayElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (t termination_by c => (sizeOf t', c) end -/- Recursively write a structured `Value` into the storage of declared type `t` at `er` — the dual - of `clearStorage?`. Leaves go through the opaque `layout` + `storageLocStore`; structure (struct - fields, tuple/array elements) is driven by `t`, and a `dynamicArray` target also writes its - length. A type/value mismatch (or a mapping/`bytes` target) is an `.error`, never a partial - write. -/ mutual +/-- Recursively write a structured `Value` into the storage of declared type `t` at `er` — the dual + of `clearStorage?`. Leaves go through the opaque `layout` + `storageLocStore`; structure (struct + fields, tuple/array elements) is driven by `t`, and a `dynamicArray` target also writes its + length. A type/value mismatch (or a mapping/`bytes` target) is an `.error`, never a partial + write. -/ def writeStorage? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : StorageType -> Value -> EvalResult EVM.State | .elem _, v @@ -213,12 +213,12 @@ def writeArrayElems? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) (t termination_by vs => (sizeOf t', sizeOf vs) end -/- Recursively read a value of declared type `t` out of storage at `er` into a `Value` — the read - dual of `writeStorage?`/`clearStorage?`. Leaves come from the opaque `layout` + `storageLocLoad`; - structure (struct fields, tuple/fixed-array elements, dynamic-array length + all data) is driven - by `t`, so a nested dynamic array is read in full. A mapping has no enumerable contents, so a - whole-mapping read is an `.error`. -/ mutual +/-- Recursively read a value of declared type `t` out of storage at `er` into a `Value` — the read + dual of `writeStorage?`/`clearStorage?`. Leaves come from the opaque `layout` + `storageLocLoad`; + structure (struct fields, tuple/fixed-array elements, dynamic-array length + all data) is driven + by `t`, so a nested dynamic array is read in full. A mapping has no enumerable contents, so a + whole-mapping read is an `.error`. -/ def readStorage? (cfg : Config) (evm : EVM.State) (er : EvaledStorageRef) : StorageType -> EvalResult Value | .elem _ diff --git a/Solm/Semantics/Types.lean b/Solm/Semantics/Types.lean index 332bc61e..88787b7b 100644 --- a/Solm/Semantics/Types.lean +++ b/Solm/Semantics/Types.lean @@ -16,12 +16,12 @@ structure Config where storage : StorageLayout externalABI : ExternalCallABI abiDecodeMode : ABI.DecodeMode := ABI.DecodeMode.modern - /- Initialisation code (creation bytecode ++ ABI-encoded constructor args) for a - `new` of the named contract. -/ + /-- Initialisation code (creation bytecode ++ ABI-encoded constructor args) for a + `new` of the named contract. -/ creationCode : Ident -> List Value -> Option EVM.Bytes := fun _ _ => none - /- Scheme for initialisation code (creation bytecode ++ ABI-encoded constructor args) for - deployment of the contract's constructor -/ + /-- Scheme for initialisation code (creation bytecode ++ ABI-encoded constructor args) for + deployment of the contract's constructor -/ selfDeployment : EVM.Bytes → List Value → Option EVM.Bytes structure Frame where diff --git a/Solm/Semantics/ValueOps.lean b/Solm/Semantics/ValueOps.lean index 9ca4c971..3577d5a5 100644 --- a/Solm/Semantics/ValueOps.lean +++ b/Solm/Semantics/ValueOps.lean @@ -409,14 +409,9 @@ def evalBinaryOp? (op : BinaryOp) (v₁ v₂ : Value) : EvalResult Value := #guard evalBinaryOp? .lt (.address (.ofNat 3)) (.address (.ofNat 5)) = .ok (.bool true) #guard evalBinaryOp? .gt (.address (.ofNat 3)) (.address (.ofNat 5)) = .ok (.bool false) -/-- Packed ("non-padded") ABI encoding of a single value, per Solidity's `abi.encodePacked`: each - value takes its natural byte width with no left/right padding and no length prefix — `uintN`/`intN` - are `N/8` big-endian bytes, `bool` is one byte, `address` is its 20 bytes, `bytesN` is its `N` - bytes, and dynamic `bytes` is its raw contents. Only the cases needed by current specs are - handled; anything else returns `none` rather than risk a silent mis-encoding. -/ --- `abi.encodePacked` of an array: each element is a full 32-byte padded word, no length prefix --- (verified from solc 0.8.35 Yul IR — `add(pos, 0x20)` per element). Elementary elements only --- (`encodeABIWord?` returns `none` for nested/dynamic element types). +/-- `abi.encodePacked` of an array: each element is a full 32-byte padded word, no length prefix + (verified from solc 0.8.35 Yul IR — `add(pos, 0x20)` per element). Elementary elements only + (`encodeABIWord?` returns `none` for nested/dynamic element types). -/ def encodePackedArrayElems? (elemTy : ABIType) : List Value → Option (List UInt8) | [] => some [] | v :: vs => do @@ -424,6 +419,11 @@ def encodePackedArrayElems? (elemTy : ABIType) : List Value → Option (List UIn let rest <- encodePackedArrayElems? elemTy vs some (EVM.Word.toBytesBE w ++ rest) +/-- Packed ("non-padded") ABI encoding of a single value, per Solidity's `abi.encodePacked`: each + value takes its natural byte width with no left/right padding and no length prefix — `uintN`/`intN` + are `N/8` big-endian bytes, `bool` is one byte, `address` is its 20 bytes, `bytesN` is its `N` + bytes, and dynamic `bytes` is its raw contents. Only the cases needed by current specs are + handled; anything else returns `none` rather than risk a silent mis-encoding. -/ def encodePackedValue? (ty : ABIType) (v : Value) : Option (List UInt8) := match ty, v with | .elem .bool, .bool b => some [if b then (1 : UInt8) else 0] @@ -445,8 +445,8 @@ def encodePackedValue? (ty : ABIType) (v : Value) : Option (List UInt8) := #guard encodePackedValue? (.dynamicArray (.elem (.int (.uint ⟨8, by decide⟩)))) (.array [.int 1, .int 2]) = some (List.replicate 31 0 ++ [1] ++ List.replicate 31 0 ++ [2]) --- `b[s:e]`: solc compiles `d[x:y]` to two `GT → REVERT` guards (verified solc 0.6.12 & 0.8.35): --- revert iff `s > e` or `e > b.size`; negative bounds are ill-typed. +/-- `b[s:e]`: solc compiles `d[x:y]` to two `GT → REVERT` guards (verified solc 0.6.12 & 0.8.35): + revert iff `s > e` or `e > b.size`; negative bounds are ill-typed. -/ def sliceBytes? (ba : ByteArray) (s e : Int) : EvalResult Value := if s < 0 || e < 0 then .error .typeError else if s.toNat > e.toNat || e.toNat > ba.size then .revert diff --git a/TODO.md b/TODO.md index fdb47892..85f06b87 100644 --- a/TODO.md +++ b/TODO.md @@ -110,7 +110,7 @@ Severity check: this is not load-bearing for the hard parts of the benchmarks Parameterized statement (the principled one). Add a trusted patchRuntime : ByteArray → List (Nat × EVM.Word) → ByteArray and the offset table — solc emits exactly this as immutableReferences in its standard-JSON output, so the table is a compiler artifact, not something you reverse-engineer. Then: -Runtime: ∀ vals, runtimeEquivalence!?! cfg (patchRuntime template (offsets vals)) (poolSpec vals) — one proof, universally quantified over instantiations. The proof works exactly like today's, except symbolic PUSH32 operands where the template had zeros. +Runtime: ∀ vals, runtimeEquivalence cfg (patchRuntime template (offsets vals)) (poolSpec vals) — one proof, universally quantified over instantiations. The proof works exactly like today's, except symbolic PUSH32 operands where the template had zeros. Constructor: generalize ctorResultEquiv's o = runtimeCode to o = patchRuntime template (offsets (valsOf env solmState)), where the expected values are derived from the same things the spec constructor computed (the parameters() return, env .this). This is a change to the equivalence-statement layer only — Solm syntax and semantics don't move. diff --git a/prompt.md b/prompt.md index ee55f743..e470d8b3 100644 --- a/prompt.md +++ b/prompt.md @@ -32,7 +32,7 @@ constructorEquivalence and the correctness of the runtime code: ```lean -runtimeEquivalence!?! +runtimeEquivalence ``` Your goal is to complete the proof. The proof must be correct, From 2300cb44191bb0ed7990766ebe3c8b64f1ae3a16 Mon Sep 17 00:00:00 2001 From: zoep Date: Sat, 25 Jul 2026 19:27:56 +0300 Subject: [PATCH 10/38] Solm: cleanup equiv --- Solm/Equiv.lean | 62 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/Solm/Equiv.lean b/Solm/Equiv.lean index 2d077c2d..a7a92bc1 100644 --- a/Solm/Equiv.lean +++ b/Solm/Equiv.lean @@ -2,6 +2,24 @@ import ABI.Encode import ABI.Decode import Solm.Semantics +/-! +The statement of Solm/EVM refinement, layered bottom-up: + +* **Result equivalence** — `returnEquiv`/`returnDataEquiv` couple returned bytes with spec + return values; `execResultsEquiv` / `ctorResultEquiv` couple whole execution outcomes + (final account maps up to `accountMapEquiv`, plus the return data — for constructors, the + returned bytes must be the deployed runtime code). +* **Fixed-input relations** — `runtimeEquivalenceFor` / `constructorEquivalenceFor` couple one + EVM execution (`Ethereum.EVM.Ξ`) with one Solm execution (`solmExec` / `solmCtorExec`) at + fixed transaction inputs. +* **∀-closures** — `runtimeEquivalence` (and the precondition-carrying + `runtimeEquivalenceWithWF`) and `constructorEquivalence` quantify over all inputs. +* **Top level** — `contractEquivalence` = constructor + runtime + +The `*With` family at the bottom of the file generalizes the constructor relations to +immutable-dependent runtime code (`runtimeCodeOf : Store → Option ByteArray`). +-/ + open Solm open ABI @@ -9,7 +27,6 @@ open ABI with a declared return type falls through without an explicit `return`: the EVM then returns the ABI encoding of this value (e.g. 32 zero bytes for `uint`), not empty output. Only the elementary types the model supports are covered. -/ -/- TODO move -/ def defaultAbiValue : ABIType -> Option Value | .elem .bool => some (.bool false) | .elem .address => some (.address (.ofNat 0)) @@ -17,7 +34,7 @@ def defaultAbiValue : ABIType -> Option Value | .elem (.bytes n) => some (.fixedBytes n (List.replicate (n.val + 1) 0)) | _ => none -/- Equivalence of ABI-returned data -/ +/-- Equivalence of ABI-returned data. -/ inductive returnEquiv (o : ByteArray) (r : Option (List Value)) (t : List ABIType) : Prop where | returned : /- Explicit `return`: the returned values encode flat to the output. `vs = []`, `t = []` @@ -49,7 +66,7 @@ inductive returnEquiv (o : ByteArray) (r : Option (List Value)) (t : List ABITyp @[simp] theorem encodeReturnValue_eq_singleton (t : ABIType) (v : Value) : encodeReturnValue? t v = encodeReturnValues? [t] [v] := rfl -/- Equivalence of return data -/ +/-- Equivalence of return data, per the transition's return convention. -/ inductive returnDataEquiv (o : ByteArray) (r : Option (List Value)) : ReturnConvention → Prop where | abi {t} : returnEquiv o r t → @@ -135,7 +152,6 @@ inductive execResultsEquiv solmRes = .returned _ solmState retVal → createdAccounts' = solmState.createdAccounts → accountMapEquiv σ' solmState.accountMap → - -- A' = solmState.substate → /- We ignore the substate -/ returnDataEquiv o retVal returnConvention → execResultsEquiv evmRes solmRes returnConvention | revert : @@ -160,7 +176,6 @@ inductive ctorResultEquiv solmRes = .returned _ solmState .none → createdAccounts' = solmState.createdAccounts → accountMapEquiv σ' solmState.accountMap → - -- A' = solmState.substate → /- We ignore the substate -/ o = runtimeCode → ctorResultEquiv evmRes solmRes runtimeCode -- Twin of `success` for a ctor body ending in a bare `return` (explicit void return `some []`); @@ -182,6 +197,21 @@ inductive ctorResultEquiv solmRes = .reverted → ctorResultEquiv evmRes solmRes runtimeCode +/-- Runtime equivalence of a single message call at fixed transaction inputs: couples the EVM + execution of the bytecode (`Ethereum.EVM.Ξ`) with the Solm execution of the spec (`solmExec`), + both run from the given accounts, gas, substate, and environment `I` (which carries the code + and calldata). The EVM side starts from `σ_evm`, the Solm side from `σ_solm`; the two are + only related up to `accountMapEquiv` — that coupling, and the quantification over all inputs, + are imposed by the entry points `runtimeEquivalence` / `runtimeEquivalenceWithWF`. + + Holds in exactly one of four ways: + * `execution`: Solm dispatches and runs a transition to `solmRes`; the EVM result is + `execResultsEquiv`-related to it under the transition's return convention. + * `noDispatch`: no Solm transition accepts the calldata, and the EVM reverts. + * `decodingFailed`: the selector matches a transition but calldata decoding fails, + and the EVM reverts. + * `outOfGas`: the EVM exhausts its gas; the spec side is unconstrained. (TODO: because + termination is not forced, a non-terminating EVM program is equivalent to any spec.) -/ inductive runtimeEquivalenceFor (cfg : Config) (contract : ContractDecl) /- Spec -/ (createdAccounts : Batteries.RBSet Ethereum.AccountAddress compare) @@ -254,7 +284,6 @@ inductive runtimeEquivalenceWithWF (wf : StorageWF) (cfg : Config) (bytecode : B ) → runtimeEquivalenceWithWF wf cfg bytecode contract --- a Solm contract corresponds to what? inductive runtimeEquivalence (cfg : Config) (bytecode : ByteArray) (contract : ContractDecl) : Prop where | intro : (∀ (createdAccounts : Batteries.RBSet Ethereum.AccountAddress compare) @@ -280,6 +309,7 @@ inductive runtimeEquivalence (cfg : Config) (bytecode : ByteArray) (contract : C ) → runtimeEquivalence cfg bytecode contract +/-- Sanity check: the two definitions agree for the trivial storage well-formedness predicate. -/ theorem runtimeEquivalenceWithWF_trivial_iff {cfg : Config} {bytecode : ByteArray} {contract : ContractDecl} : runtimeEquivalenceWithWF trivialStorageWF cfg bytecode contract ↔ @@ -298,6 +328,24 @@ theorem runtimeEquivalenceWithWF_trivial_iff {cfg : Config} {bytecode : ByteArra intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts _hwf exact hrun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts + +/-- Constructor (deployment) equivalence at fixed transaction inputs: couples the EVM + execution of the init code (`Ethereum.EVM.Ξ`, with `I.code` the deployed initcode and empty + calldata) with the Solm execution of the constructor body (`solmCtorExec`) on the argument + values `args`. Unlike the runtime relation there is no dispatch or calldata-decoding case: + creation calls are compiler-generated and trusted, so the *spec side* fixes `args`, and the + ∀-closure (`constructorEquivalence`) ties them to the deployed initcode via + `cfg.selfDeployment`. The EVM side starts from `σ_evm`, the Solm side from `σ_solm`, + related up to `accountMapEquiv` at the entry point. + + Holds in one of two ways: + * `execution` — the Solm constructor runs to `solmRes`; the EVM result is + `ctorResultEquiv`-related: on success the final states agree up to `accountMapEquiv` + **and the EVM's returned bytes are exactly `runtimeCode`** (the deployed runtime bytecode); + reverts and `INVALID` halts pair with a Solm revert. + * `outOfGas` — the EVM exhausts its gas; the spec side is unconstrained. (same + termination caveat as `runtimeEquivalenceFor`) -/ + inductive constructorEquivalenceFor (cfg : Config) (contract : ContractDecl) /- Spec -/ (args : List Value) @@ -370,6 +418,8 @@ inductive constructorEquivalence (cfg : Config) (initcode : ByteArray) (contract -- We do not have a model of message calls (Θ) for the spec (which would handle balance transfer for example) -- If it were implemented however it would likely exactly mirror the EVM version except for calling solmExec -- instead of EVM.Ξ, so on the equivalence checking level it is uninteresting + +/-- Top-level contract equivalence -/ inductive contractEquivalence (cfg : Config) (initcode : EVM.Bytes) (runtimeCode : EVM.Bytes) (contract : ContractDecl) : Prop where | intro : constructorEquivalence cfg initcode contract runtimeCode → From a916aed7206ddc5030ad93ed7c42cd978d57a6ae Mon Sep 17 00:00:00 2001 From: zoep Date: Mon, 27 Jul 2026 09:57:08 +0300 Subject: [PATCH 11/38] Solm: cleanup equiv --- Solm/Equiv.lean | 5 ++++- Solm/STRUCTURE.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++ TODO.md | 2 +- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 Solm/STRUCTURE.md diff --git a/Solm/Equiv.lean b/Solm/Equiv.lean index a7a92bc1..247b8933 100644 --- a/Solm/Equiv.lean +++ b/Solm/Equiv.lean @@ -20,7 +20,8 @@ The `*With` family at the bottom of the file generalizes the constructor relatio immutable-dependent runtime code (`runtimeCodeOf : Store → Option ByteArray`). -/ -open Solm +namespace Solm + open ABI /-- Default (zero-initialized) value for an ABI return type. Used when a function @@ -533,3 +534,5 @@ inductive contractEquivalenceWithWF (wf : StorageWF) (cfg : Config) (initcode : constructorEquivalenceWith cfg initcode contract runtimeCodeOf → runtimeEquivalenceWithWF wf cfg runtimeCode contract → contractEquivalenceWithWF wf cfg initcode runtimeCode contract runtimeCodeOf + +end Solm diff --git a/Solm/STRUCTURE.md b/Solm/STRUCTURE.md new file mode 100644 index 00000000..205f1bc3 --- /dev/null +++ b/Solm/STRUCTURE.md @@ -0,0 +1,56 @@ +# Solm/ structure + +Sol⁻ is the high-level specification language of EquiVM. Is structure, +mirrors a subset of Solidity. Solidity's structs like inheritance, +modifiers are assumed to be desugared away. + +Currently, Sol⁻ does not currently model events, error payloads, or gas. +``` +Solm/ +├── Syntax.lean umbrella: Syntax/Basic + Syntax/DecEq +├── Syntax/ +│ ├── Basic.lean the AST: StorageType, Expr, StorageRef, Stmt, contract declarations +│ └── DecEq.lean DecidableEq instances (hand-written where `deriving` fails +│ on nested List payloads) +├── Notation.lean surface syntax macros +├── Value.lean umbrella + Value↔word conversions (valueToWord, wordToElem, +│ keyValueToWord) +├── Value/ +│ ├── Basic.lean the runtime Value type +│ └── DecEq.lean DecidableEq Value (hand-written, same reason as Syntax) +├── Storage.lean StorageLoc (slot/offset/size of a primitive), packed load/store +│ within a slot, and the StorageLayout interface a compiler +│ layout implements +├── SolidityLayout.lean solc's storage layout (slots, packing, keccak-derived +│ mapping/array locations, bytes/string representation) +├── VyperLayout.lean Vyper's storage layout +├── Immutables.lean splice immutable values / library addresses into the +│ runtime-code template (patchRuntime) +├── Semantics.lean umbrella for Semantics/ +├── Semantics/ +│ ├── Types.lean shared context: Config, ExternalCallABI, Frame +│ ├── Dispatch.lean selector/receive/fallback dispatch, return conventions +│ ├── ValueOps.lean EvalResult monad; operations on values (operators, casts, +│ │ indexing, packed encoding) +│ ├── StorageOps.lean operations on storage: typed read/write/clear/default +│ │ through the layout +│ ├── Eval.lean the expression evaluator (evalExpr?, functional) +│ ├── Calls.lean external call and contract creation, bridged to the +│ │ EVM's Θ/Λ (relational) +│ └── Exec.lean statement and transaction execution relations +│ (ExecStmt … solmExec, solmCtorExec) +└── Equiv.lean the top-level refinement statement (contractEquivalence) + and supporting definitions. +``` + +Dependency order (each layer imports the previous): + +``` +Syntax → Notation +Syntax → Value → Storage → {SolidityLayout, VyperLayout} + Value → Immutables +Semantics: Types → ValueOps → StorageOps → Eval → Exec (Calls, Dispatch join at Exec) +Equiv: on top of Semantics +``` + +Everything is in `namespace Solm`. diff --git a/TODO.md b/TODO.md index 85f06b87..0d738990 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,7 @@ # Release TODOs - [X] EquiVM/EVM -- [ ] Solm +- [X] Solm - [ ] ABI - [ ] Reasoning - [ ] Examples From 14c343911381d3ad8eb5295ffc06d29cb0e80a94 Mon Sep 17 00:00:00 2001 From: zoep Date: Mon, 27 Jul 2026 11:18:34 +0300 Subject: [PATCH 12/38] ABI: cleanup --- ABI/Decode.lean | 29 ++++++++++++++++------------- ABI/Encode.lean | 2 ++ ABI/Signature.lean | 2 ++ ABI/StaticWords.lean | 5 +++-- ABI/Types.lean | 23 +++++++++++------------ Solm/STRUCTURE.md | 9 +++++++-- TODO.md | 3 +++ 7 files changed, 44 insertions(+), 29 deletions(-) diff --git a/ABI/Decode.lean b/ABI/Decode.lean index d77b9f63..2475960a 100644 --- a/ABI/Decode.lean +++ b/ABI/Decode.lean @@ -2,15 +2,18 @@ import EVM.Types import ABI.Types import Solm.Value +/-! ABI decoding of calldata and return data into Solm values, parameterized by the +compiler-specific `DecodeMode` (modern solc, legacy coder-v1 solc, Vyper). -/ + namespace ABI def solcMaxU64 : Nat := 18446744073709551615 --- Coder-v1 (solc 0.5.16 / 0.7.6) caps dynamic offsets and lengths at `2^32` *inclusive*. Verified --- by disassembly (`P2.h(bytes)`, `--optimize`): both the offset and length guards are --- `PUSH5 0x0100000000; DUP; GT; ISZERO; JUMPI(→ok) else REVERT`, i.e. `GT` computes `value > 2^32` --- and reverts iff true — so `2^32` is the largest accepted value. (Coder v2 / `solcMaxU64` uses --- `2^64 - 1`, and we keep applying that only in `modern`.) +/-- Coder-v1 (solc 0.5.16 / 0.7.6) caps dynamic offsets and lengths at `2^32` *inclusive*. Verified + by disassembly (`P2.h(bytes)`, `--optimize`): both the offset and length guards are + `PUSH5 0x0100000000; DUP; GT; ISZERO; JUMPI(→ok) else REVERT`, i.e. `GT` computes `value > 2^32` + and reverts iff true — so `2^32` is the largest accepted value. (Coder v2 / `solcMaxU64` uses + `2^64 - 1`, and we keep applying that only in `modern`.) -/ def solcMaxLenV1 : Nat := 4294967296 -- 2^32 def solcMaxLen : DecodeMode → Nat @@ -18,13 +21,13 @@ def solcMaxLen : DecodeMode → Nat | DecodeMode.vyper => solcMaxU64 | DecodeMode.legacySolc05 => solcMaxLenV1 --- In `modern` the dynamic cap is exactly `solcMaxU64`, so `modern`-mode decode proofs that unfold the --- guards reduce back to the pre-existing `solcMaxU64 < …` shape (statements unchanged). +/-- In `modern` the dynamic cap is exactly `solcMaxU64`, so `modern`-mode decode proofs that unfold + the guards reduce back to the pre-existing `solcMaxU64 < …` shape (statements unchanged). -/ @[simp] theorem solcMaxLen_modern : solcMaxLen DecodeMode.modern = solcMaxU64 := rfl --- Modern solc nested dynamic-array decoders do not reject an element's relative offset just because --- it is larger than `2^64 - 1`; the generated bytecode relies on signed calldata-bounds checks for --- the target. Legacy coder-v1 keeps the old inclusive `2^32` offset cap. +/-- Modern solc nested dynamic-array decoders do not reject an element's relative offset just because + it is larger than `2^64 - 1`; the generated bytecode relies on signed calldata-bounds checks for + the target. Legacy coder-v1 keeps the old inclusive `2^32` offset cap. -/ def solcRejectsDynamicArrayElementOffset (mode : DecodeMode) (relativeOffset : Nat) : Bool := match mode with | DecodeMode.modern => false @@ -476,9 +479,9 @@ def decodeReturnValuesWithMode? (mode : DecodeMode) (types : List ABIType) (retu decodeABIValues? types bytes 0 0 headSize headSize DecodeMode.legacySolc05 some values --- Decodes a single top-level value. For a callee's multi-value return use `decodeReturnValues?` — --- a `.tuple` type here is one tuple-typed output (ABI-wrapped, with a leading offset word), NOT a --- flat multi-return. +/-- Decodes a single top-level value. For a callee's multi-value return use `decodeReturnValues?` — + a `.tuple` type here is one tuple-typed output (ABI-wrapped, with a leading offset word), NOT a + flat multi-return. -/ def decodeReturnValue? (ty : ABIType) (returndata : ByteArray) : Option Solm.Value := do match decodeReturnValues? [ty] returndata with | some [value] => some value diff --git a/ABI/Encode.lean b/ABI/Encode.lean index 8a2f30aa..1639a73e 100644 --- a/ABI/Encode.lean +++ b/ABI/Encode.lean @@ -2,6 +2,8 @@ import EVM.Types import ABI.Types import Solm.Value +/-! ABI encoding of Solm values -/ + namespace ABI def natBytes (n : Nat) : List UInt8 := diff --git a/ABI/Signature.lean b/ABI/Signature.lean index f67b14c6..f09c988f 100644 --- a/ABI/Signature.lean +++ b/ABI/Signature.lean @@ -1,5 +1,7 @@ import ABI.Types +/-! Function signatures and their canonical string form, as hashed for the 4-byte selector. -/ + namespace ABI structure Signature where diff --git a/ABI/StaticWords.lean b/ABI/StaticWords.lean index 932c8251..a9f00268 100644 --- a/ABI/StaticWords.lean +++ b/ABI/StaticWords.lean @@ -1,6 +1,8 @@ import ABI.Encode import ABI.Decode +/-! Flattening static ABI types into the word-scalar leaves they occupy. -/ + namespace ABI /-- Repeat a list `n` times and concatenate the copies. -/ @@ -41,8 +43,7 @@ end mutual /-- Flatten a static ABI value into `(type, value)` word-scalar leaves, in ABI order. - The function succeeds only when every scalar leaf is accepted by `encodeABIWord?`; this makes it - a convenient domain predicate for word-level encoder theorems. + The function succeeds only when every scalar leaf is accepted by `encodeABIWord?`. -/ def staticWordPairs? : ABIType → Solm.Value → Option (List (ABIType × Solm.Value)) | ty@(.elem _), value => diff --git a/ABI/Types.lean b/ABI/Types.lean index 24f9eda9..9e91adeb 100644 --- a/ABI/Types.lean +++ b/ABI/Types.lean @@ -1,3 +1,4 @@ +/-! The Solidity ABI type grammar, and static size/dynamicity computations over it. -/ namespace ABI @@ -7,20 +8,20 @@ def BitWidth := { m : Nat // 0 < m ∧ m ≤ 256 ∧ m % 8 = 0} def FinPos N := { n : Nat // 0 < n ∧ n ≤ N } deriving DecidableEq, Repr -/- Integer types used by Solidity-style ABI values. -/ +/-- Integer types used by Solidity-style ABI values. -/ inductive IntType where | uint : BitWidth -> IntType | sint : BitWidth -> IntType deriving DecidableEq, Repr -/- Fixed-point decimal number types used by Solidity-style ABI values. -/ +/-- Fixed-point decimal number types used by Solidity-style ABI values. -/ -- Note: Just added to have complete coverage of ABI, will not implement right now inductive FixedType where | ufixed : BitWidth -> FinPos 80 -> FixedType | fixed : BitWidth -> FinPos 81 -> FixedType deriving DecidableEq, Repr -/- Elemnrary first-order types, per the Solidity ABI. -/ +/-- Elementary first-order types, per the Solidity ABI. -/ inductive ElemType where | bool : ElemType | address : ElemType @@ -30,19 +31,19 @@ inductive ElemType where | function : ElemType deriving DecidableEq, Repr, Inhabited -/- ABI decoder mode for compiler-specific wrapper behavior. Modern solc decoders reject - non-canonical value words and use signed size guards. Legacy solc (coder v1) instead *cleans* - value types rather than validating them: normalize `bool` (nonzero → true), mask `address`, and - mask narrow `uintN` — using unsigned static-size checks. . Vyper fixed-argument wrappers keep - canonical address checks but use minimum static-size checks rather than solc's signed - huge-calldata guard. -/ +/-- ABI decoder mode for compiler-specific wrapper behavior. Modern solc decoders reject + non-canonical value words and use signed size guards. Legacy solc (coder v1) instead *cleans* + value types rather than validating them: normalize `bool` (nonzero → true), mask `address`, and + mask narrow `uintN` — using unsigned static-size checks. Vyper fixed-argument wrappers keep + canonical address checks but use minimum static-size checks rather than solc's signed + huge-calldata guard. -/ inductive DecodeMode where | modern : DecodeMode | legacySolc05 : DecodeMode | vyper : DecodeMode deriving DecidableEq, Repr, Inhabited -/- ABI types for parameters, locals, and return values. -/ +/-- ABI types for parameters, locals, and return values. -/ inductive ABIType where | elem : ElemType -> ABIType | array : ABIType -> Nat -> ABIType @@ -132,8 +133,6 @@ mutual | ty :: tys => isDynamicABIType ty || isDynamicABITypeList tys end -def usesLegacyAddressTypes (_types : List ABIType) : Bool := false - mutual def staticABIEncodedSize? : ABIType → Option Nat | .elem _ => some 32 diff --git a/Solm/STRUCTURE.md b/Solm/STRUCTURE.md index 205f1bc3..0bf7d9c5 100644 --- a/Solm/STRUCTURE.md +++ b/Solm/STRUCTURE.md @@ -1,8 +1,13 @@ # Solm/ structure -Sol⁻ is the high-level specification language of EquiVM. Is structure, +Sol⁻ is the high-level specification language of EquiVM. Its structure mirrors a subset of Solidity. Solidity's structs like inheritance, -modifiers are assumed to be desugared away. +modifiers are assumed to be desugared away. + +Note that there are semantics differences between Solidity and Sol⁻, +for example in Sol⁻, in-memory integers have unbounded range. +This facilitates reasoning using unbounded mathematical integers, and only +converts to bounded integers at the storage boundary. Currently, Sol⁻ does not currently model events, error payloads, or gas. ``` diff --git a/TODO.md b/TODO.md index 0d738990..83f35f92 100644 --- a/TODO.md +++ b/TODO.md @@ -10,8 +10,11 @@ + [ ] Concrete syntax - [ ] Proofs - [ ] Misc + + [ ] Proof template - [ ] Docs + [ ] README + * [ ] External call section + * [ ] Top-level theorem section + [ ] GUIDE - [ ] CI/CD From 4581cb22de5ceaa7178386b506eb6796c11ace25 Mon Sep 17 00:00:00 2001 From: zoep Date: Mon, 27 Jul 2026 23:47:01 +0300 Subject: [PATCH 13/38] Add top-level lean files --- ABI.lean | 5 +++++ EVM.lean | 3 +++ EquiVM.lean | 18 ++++++++++++++++++ Proofs/ERC20/Invariant.lean | 18 +++++++++--------- 4 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 ABI.lean create mode 100644 EVM.lean create mode 100644 EquiVM.lean diff --git a/ABI.lean b/ABI.lean new file mode 100644 index 00000000..e6144126 --- /dev/null +++ b/ABI.lean @@ -0,0 +1,5 @@ +import ABI.Types +import ABI.Signature +import ABI.Encode +import ABI.Decode +import ABI.StaticWords diff --git a/EVM.lean b/EVM.lean new file mode 100644 index 00000000..159f6ec2 --- /dev/null +++ b/EVM.lean @@ -0,0 +1,3 @@ +import EVM.Types +import EVM.Semantics +import EVM.Lemmas diff --git a/EquiVM.lean b/EquiVM.lean new file mode 100644 index 00000000..9bf09cb6 --- /dev/null +++ b/EquiVM.lean @@ -0,0 +1,18 @@ +import Solm +import Reasoning.ABI +import Reasoning.Constructor +import Reasoning.Dispatch +import Reasoning.EVMWord +import Reasoning.ExternalCall +import Reasoning.Initcode +import Reasoning.JumpDest +import Reasoning.MemCascade +import Reasoning.Memory +import Reasoning.Reach +import Reasoning.Refinement +import Reasoning.Solc +import Reasoning.SolcDecode +import Reasoning.SolmBody +import Reasoning.Stepping +import Reasoning.Storage +import Reasoning.Theory diff --git a/Proofs/ERC20/Invariant.lean b/Proofs/ERC20/Invariant.lean index 16862f60..3e456f9a 100644 --- a/Proofs/ERC20/Invariant.lean +++ b/Proofs/ERC20/Invariant.lean @@ -420,7 +420,7 @@ theorem transfer_closesLoop (hinj : InjectiveLayout erc20Config) (hfit : transferNewToNat evm I < UInt256.size) (hInv : Inv evm) : ExecTransitionBody erc20Config erc20Contract evm (transferStore I) transferTransition.body (.returned { contract := erc20Contract, locals := transferStoreNewToBalance evm I } - (transferPostState evm I) (some (.bool true))) + (transferPostState evm I) (some [.bool true])) ∧ Inv (transferPostState evm I) := ⟨erc20TransferBodyReturns evm I hwv henough hfit, transfer_preserves_inv evm I hinj hco hne henough hfit hInv⟩ @@ -439,7 +439,7 @@ theorem transferFrom_closesLoop (hinj : InjectiveLayout erc20Config) ExecTransitionBody erc20Config erc20Contract evm (transferFromStore I) transferFromTransition.body (.returned { contract := erc20Contract, locals := transferFromStoreNewToBalance evm I } - (transferFromPostState evm I) (some (.bool true))) + (transferFromPostState evm I) (some [.bool true])) ∧ Inv (transferFromPostState evm I) := ⟨erc20TransferFromBodyReturns evm I hwv hallowance hbalance hbalanceDebit hfit, transferFrom_preserves_inv evm I hinj hco hft hbalance hfit hInv⟩ @@ -448,31 +448,31 @@ theorem approve_closesLoop (hinj : InjectiveLayout erc20Config) (hwv : evm.executionEnv.weiValue = ⟨0⟩) (hInv : Inv evm) : ExecTransitionBody erc20Config erc20Contract evm (approveStore I) approveTransition.body (.returned { contract := erc20Contract, locals := approveStore I } - (approvePostState evm I) (some (.bool true))) + (approvePostState evm I) (some [.bool true])) ∧ Inv (approvePostState evm I) := ⟨erc20ApproveBodyReturns evm I hwv, approve_preserves_inv evm I hinj hInv⟩ theorem totalSupply_closesLoop (hwv : evm.executionEnv.weiValue = ⟨0⟩) (hInv : Inv evm) : ExecTransitionBody erc20Config erc20Contract evm (∅ : Store) totalSupplyTransition.body (.returned { contract := erc20Contract, locals := (∅ : Store) } evm - (some (.int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨2⟩).toNat)))) + (some [.int (Int.ofNat + (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨2⟩).toNat)])) ∧ Inv evm := ⟨erc20TotalSupplyBodyReturns evm (∅ : Store) hwv (by simp), hInv⟩ theorem balanceOf_closesLoop (hwv : evm.executionEnv.weiValue = ⟨0⟩) (hInv : Inv evm) : ExecTransitionBody erc20Config erc20Contract evm (balanceOfStore I) balanceOfTransition.body (.returned { contract := erc20Contract, locals := balanceOfStore I } evm - (some (.int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (balanceOfSlot I)).toNat)))) + (some [.int (Int.ofNat + (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (balanceOfSlot I)).toNat)])) ∧ Inv evm := ⟨erc20BalanceOfBodyReturns evm I hwv, hInv⟩ theorem allowance_closesLoop (hwv : evm.executionEnv.weiValue = ⟨0⟩) (hInv : Inv evm) : ExecTransitionBody erc20Config erc20Contract evm (allowanceStore I) allowanceTransition.body (.returned { contract := erc20Contract, locals := allowanceStore I } evm - (some (.int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (allowanceSlot I)).toNat)))) + (some [.int (Int.ofNat + (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (allowanceSlot I)).toNat)])) ∧ Inv evm := ⟨erc20AllowanceBodyReturns evm I hwv, hInv⟩ From 2bd6b21de15c183b057016f0fd525d75ec41a073 Mon Sep 17 00:00:00 2001 From: zoep Date: Tue, 28 Jul 2026 17:17:13 +0300 Subject: [PATCH 14/38] Reasoning: cleanup --- Reasoning/ABI.lean | 13 +-- Reasoning/Dispatch.lean | 21 ++-- Reasoning/EVMWord.lean | 23 ---- Reasoning/ExternalCall.lean | 6 +- Reasoning/GUIDE.md | 76 ------------- Reasoning/Memory.lean | 15 --- Reasoning/Reach.lean | 84 +++++--------- Reasoning/Refinement.lean | 17 --- Reasoning/Solc.lean | 221 +++++++++++++++--------------------- Reasoning/SolcDecode.lean | 213 ---------------------------------- Reasoning/SolmBody.lean | 14 ++- Reasoning/Stepping.lean | 20 ++-- Reasoning/Storage.lean | 29 +++-- 13 files changed, 177 insertions(+), 575 deletions(-) delete mode 100644 Reasoning/GUIDE.md delete mode 100644 Reasoning/SolcDecode.lean diff --git a/Reasoning/ABI.lean b/Reasoning/ABI.lean index 0a23c9cc..7cf7fb82 100644 --- a/Reasoning/ABI.lean +++ b/Reasoning/ABI.lean @@ -43,9 +43,9 @@ abbrev calldataWord (cd : ByteArray) (off : Nat) : UInt256 := ABI types whose top-level calldata representation is a single scalar word and whose decoder path runs through `decodeABIWord?`. -This intentionally excludes fixed bytes/function for now: they are also one word on the wire, but -their decoder validates padding bytes rather than only the decoded word. Arrays, tuples, strings, -and dynamic bytes are a later structural tier. +This intentionally excludes fixed bytes/function: they are also one word on the wire, but their +decoder validates padding bytes rather than only the decoded word. Arrays, tuples, strings, and +dynamic bytes are structural types with their own decode lemmas below. -/ def isABIScalarWordType : ABIType → Bool | .elem (.bytes _) => false @@ -1260,7 +1260,6 @@ theorem readNat_drop4_zero_eq_calldataWord {cd : ByteArray} rfl theorem readNat_drop4_dynamic_eq_calldataWord {cd : ByteArray} - (_hoffMax : ¬ solcMaxU64 < (calldataWord cd 4).toNat) (hlenWord : 4 + (calldataWord cd 4).toNat + 32 ≤ cd.size) : readNat? (cd.toList.drop 4) (calldataWord cd 4).toNat = some (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat := by @@ -1393,7 +1392,7 @@ theorem decodeCalldata_string_none_length_huge {cd : ByteArray} {x : Solm.Ident} · rw [if_pos htotal] · rw [if_neg htotal] have hreadOff := readNat_drop4_zero_eq_calldataWord (cd := cd) hsz36 - have hreadLen := readNat_drop4_dynamic_eq_calldataWord (cd := cd) hoffMax hlenWord + have hreadLen := readNat_drop4_dynamic_eq_calldataWord (cd := cd) hlenWord simp [decodeCalldata.decodeArgs, decodeABIValues?, decodeABIValue?, isDynamicABIType, abiTupleHeadSize?, solcMaxLen, hreadOff, hoffMax, hreadLen, hlenHuge] @@ -1423,7 +1422,7 @@ theorem decodeCalldata_string_none_payload_short {cd : ByteArray} {x : Solm.Iden · rw [if_pos htotal] · rw [if_neg htotal] have hreadOff := readNat_drop4_zero_eq_calldataWord (cd := cd) hsz36 - have hreadLen := readNat_drop4_dynamic_eq_calldataWord (cd := cd) hoffMax hlenWord + have hreadLen := readNat_drop4_dynamic_eq_calldataWord (cd := cd) hlenWord have hpayloadRead : readBytes? (cd.toList.drop 4) ((calldataWord cd 4).toNat + 32) (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat = none := by @@ -2293,8 +2292,6 @@ theorem decodeCalldata_addr_bool_none_huge {cd : ByteArray} {x y : Solm.Ident} · exact ⟨rfl, by rw [List.length_drop, htlen]; omega⟩ -/-! ## Address-argument calldata decoding (single + two address) -/ - /-! ## Single-address calldata decoding -/ theorem decodeScalarWords_address_ok {bytes : List UInt8} diff --git a/Reasoning/Dispatch.lean b/Reasoning/Dispatch.lean index dcceca40..31e7d418 100644 --- a/Reasoning/Dispatch.lean +++ b/Reasoning/Dispatch.lean @@ -3,17 +3,20 @@ import Reasoning.Reach import Reasoning.Storage /-! -# Dispatch — generic Solm `dispatchMsg` facts for a single-transition contract +# Dispatch — generic Solm `dispatchMsg` facts -For a contract with exactly one transition (`contract.transitions = [transition]`) whose 4-byte -keccak selector is `selBytes`, `dispatchMsg` reduces to a 4-byte calldata-prefix compare. These -four lemmas are contract-agnostic; each example instantiates them with its `transitions = [t]` -proof (`rfl`) and its selector axiom. `RDrev.reEquivNonPayable` (below) packages the whole -`callvalue ≠ 0` Solm-coupling on top of them. +`dispatchMsg` (the trusted Solm dispatcher) maps each transition to its 4-byte keccak selector and +returns the first whose selector matches the calldata prefix. Everything here is contract-agnostic: + +- **Multi-selector dispatch**: `dispatchList`, the pure list-recursive form of `dispatchMsg`, plus + the bridge and list-walking lemmas that handle a contract with any number of functions; +- **Single-transition instances** (`contract.transitions = [transition]`): `dispatchMsg` reduces + to a 4-byte calldata-prefix compare, instantiated per contract with its `transitions = [t]` + proof (`rfl`) and its selector axiom, bundled in `SingleSelectorDispatch`; +- **`Reasoning.Reach` bridges** (`RDret`/`RDrev.reEquiv*`): package the runtime-equivalence + coupling, e.g. `RDrev.reEquivNonPayable` for the whole `callvalue ≠ 0` branch. -/ -/- TODO generalize for an arbitrary number of transitions -/ - open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory namespace Reasoning.Theory @@ -256,7 +259,7 @@ namespace Reasoning.Reach non-payable guard's revert (`h : RDrev …`) and the contract body's revert under non-zero call value (`hbody`), produce the `runtimeEquivalenceFor` case: the OOG alternative folds via `reEquivElim`, and the Solm side is dispatched abstractly into `noDispatch` / `decodingFailed` / - `execution`-with-revert. Both examples' `callvalue ≠ 0` branch is a single call to this. -/ + `execution`-with-revert. Each example's `callvalue ≠ 0` branch is a single call to this. -/ theorem RDrev.reEquivNonPayable {cfg : Config} {contract : ContractDecl} {transition : TransitionDecl} {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} {code : ByteArray} (hcode : I.code = code) diff --git a/Reasoning/EVMWord.lean b/Reasoning/EVMWord.lean index 30605a3f..49f54f86 100644 --- a/Reasoning/EVMWord.lean +++ b/Reasoning/EVMWord.lean @@ -395,10 +395,6 @@ theorem testBit_shiftLeft (m k i : Nat) : · have hnk : ¬ i < k := by omega simp [hi, hnk, Nat.succ_sub_succ_eq_sub] -theorem nat_testBit_shiftLeft (m k i : Nat) : - (m <<< k).testBit i = if i < k then false else m.testBit (i - k) := - testBit_shiftLeft m k i - /-- Bit access after dropping the low `k` bits by division. -/ theorem divPow_testBit (n k i : Nat) (hk : k ≤ i) : (n / 2 ^ k).testBit (i - k) = n.testBit i := by @@ -409,10 +405,6 @@ theorem divPow_testBit (n k i : Nat) (hk : k ≤ i) : congr omega] -theorem nat_div_pow_testBit (n k i : Nat) (hk : k ≤ i) : - (n / 2 ^ k).testBit (i - k) = n.testBit i := - divPow_testBit n k i hk - theorem nat_land_mask_eq_mod (n k : Nat) : Nat.land n (2 ^ k - 1) = n % 2 ^ k := by apply Nat.eq_of_testBit_eq @@ -747,21 +739,6 @@ theorem slt_ofNat_lit_one_low {n m : ℕ} rw [ulit_toNat' n (lt_size_of_lt_sign (lt_trans hlo hm))] exact hlo -/-! ## Small arithmetic tactic - -`evm_arith` is deliberately modest: it handles closed literal goals immediately, and can close many -side conditions after a parametric word lemma has reduced them to natural arithmetic. It is not -intended to replace the named lemmas above. --/ - -macro "evm_arith" : tactic => - `(tactic| - first - | decide - | omega - | norm_num [UInt256.size] - | (simp only [UInt256.size] <;> omega)) - /-! ## Word equality (`UInt256.eq`) and low-bit masking -/ /-- The EVM `EQ` of a word with itself is `1`. -/ diff --git a/Reasoning/ExternalCall.lean b/Reasoning/ExternalCall.lean index 25a90c8e..3f1f2631 100644 --- a/Reasoning/ExternalCall.lean +++ b/Reasoning/ExternalCall.lean @@ -138,7 +138,7 @@ theorem callViaEVM_static_accountCodeStateEq {evm evm' : EVM.State} subst hevm' exact accountCodeStateEq_refl evm.accountMap -theorem typedCallViaEVM_static_accountCode_eq {cfg : Config} {evm evm' : EVM.State} +theorem typedCallViaEVM_static_accountCodeStateEq {cfg : Config} {evm evm' : EVM.State} {target : EVM.Address} {name : Ident} {args : List Value} {z : Bool} {out : ByteArray} (hcall : typedCallViaEVM cfg evm target name 0 args (z, evm', out) false) : @@ -172,8 +172,8 @@ theorem typedCallViaEVM_static_storage_findD_of_accountMapEquiv {cfg : Config} If a typed external call is possible from an EVM state, and a Solm-side state differs only by `accountMapEquiv`-equivalent current/original account maps, then the same success flag and return data are possible on the Solm side, with a post-call account map equivalent to the EVM post-call -map. This is the narrow interface needed by examples; it should be replaced by the direct proof -about `Ethereum.EVM.Θ` once that proof lands. -/ +map. This is the narrow interface needed by examples; the proof routes through the +Θ-extensionality result `accountMap_extensionality_of_Theta_and_Lambda`. -/ theorem typedCallViaEVM_accountMapEquiv {cfg : Config} {evm_evm evm_solm evm'_evm : EVM.State} {tgt : EVM.Address} {name : Ident} {value : ℤ} {args : List Value} {z : Bool} {out : ByteArray} {callPerm : Bool} diff --git a/Reasoning/GUIDE.md b/Reasoning/GUIDE.md deleted file mode 100644 index 153672a9..00000000 --- a/Reasoning/GUIDE.md +++ /dev/null @@ -1,76 +0,0 @@ -# Reasoning/ — library guide (for agents) - -Orientation only. **Per-module detail lives in each file's `/-! # … -/` header — that is the source -of truth.** This file covers the cross-cutting things no single header tells you: where a new lemma -goes, the import layering, and the conventions/gotchas that are easy to get wrong. - -Everything here is under namespace `Reasoning.Theory`, except the `RD`/`evm_run` straight-line -execution combinators, which are `Reasoning.Reach` (`RD.*`). - -## Where does X go? (routing) - -| You're proving / stating … | Module | -|---|---| -| Symbolic EVM runs: `evm_run`, `RD`/`RDret`/`RDrev` combinators, `RD.whileLoop`, factored routine lemmas | **Reach** | -| Per-opcode step wrappers (`*_xstep`) | **Stepping** | -| `UInt256` arithmetic / comparisons / `compare` instances / `EQ` + low-bit mask facts | **EVMWord** | -| EVM memory & `ByteArray` byte facts (`MSTORE`/`MLOAD`/`RETURN` round-trips, `toByteArray`↔`toBytesBE`, selector-byte extraction) | **Memory** | -| ABI calldata **decode** *and* return-value **encode** facts | **ABI** | -| RBMap / EVM storage-map preservation (`storage_findD_*`, `rbmap_find?_erase_ne`) | **Storage** | -| solc boilerplate every compiled contract shares: prologue/callvalue/size guards, dispatch driver, selector load, **address-mask cleanup** (`solcAddrMask`, `solcAddrCanon_eq`, `solcAddrMask_clean`) | **Solc** | -| Generic `dispatchMsg` / selector-routing facts | **Dispatch** | -| `JUMPDEST`-membership (the `jump_dest` tactic) | **JumpDest** | -| `CALL` ↔ Solm `externalCall` opaque coupling | **ExternalCall** | -| Decode facts for creation `initcode ++ args` (per-PC decode proved on the prefix, reused for any appended ABI tail) | **Initcode** | -| Source-level Solm body execution (`ExecStmt`/`ExecBlock`) compositional lemmas | **SolmBody** | -| Proof-side bridges to the equivalence statements (`reEquiv*`, `runtimeEquivalenceFor`) | **Refinement** | -| Core runtime-equivalence theory | **Theory** | - -`SolcDecode` is experimental and **unused** (intentionally not imported) — don't build on it. - -## Import layering (low → high; a module may import anything strictly below it) - -``` -Theory, JumpDest, Initcode (base, no Reasoning deps) - Stepping, EVMWord, SolmBody ⟵ Theory - Memory, Storage ⟵ EVMWord+Stepping ExternalCall ⟵ SolmBody - ABI ⟵ Memory Reach ⟵ Stepping+Memory - Dispatch ⟵ Reach Solc ⟵ Memory+Stepping+Reach - Refinement ⟵ Dispatch (SolcDecode ⟵ Solc, unused) -``` - -(`Initcode` depends only on `Ethereum.Semantics`, like `Theory`/`JumpDest`; its lemmas live under -namespace `Reasoning.Theory`.) - -Place a lemma in the **lowest** module whose imports already give it everything it needs. Don't add -an *upward* import to force a placement — that's the sign it belongs in a lower module (or that you -need a small new one, as `Storage` was split out of `Memory`). - -## Conventions & gotchas (these bite) - -- **Target optimizer-ON solc bytecode.** Optimizer-ON is the target. The newer examples (`Ballot`, - `ERC721`, `Ownable2Step`, `Reuse`, `SimpleAuction`, `BlindAuction`) are optimizer-**ON**; the older - ones (`ERC20`, `Pow`, `Truth`) are optimizer-off — an artifact of how their bytecode was generated, - not a requirement. Don't assume an optimizer-off example's PCs/shapes/lemma constants carry over to - optimized output — disassemble and validate before reusing a concrete lemma. -- **Decode is discharged by `native_decide`, not `decide`.** `evm_run`'s cooked steps auto-supply - `(by native_decide)` for the `decode code pc = …` obligation (≈20× faster on big bytecode); keep - it. `raw` steps still write `(by native_decide)` for decode and `(by decide)` for small side - conditions. `jump_dest` is also `native_decide`. So proofs depend on `ofReduceBool` axioms — that - is expected and pervasive, not a problem. -- **Factoring a routine over a generic stack tail `R`** (or any compound, non-reducing term): needs - `set_option maxHeartbeats 1000000 in`, and the proof split into intermediate `have`s (one per - sub-trace) — a single giant `evm_run` blows the budget at `isDefEq`/`whnf`. -- **`rd.myLemma` dot-notation fails** (the `RD` type whnf's to an `Or`) — call `RD.myLemma rd …`. -- **Before moving an example lemma here, validate it references only library symbols.** Watch for - example-local defs: `addr`, `uint256`, `uint256Int` are defined per-example in each `Spec.lean` - (small abbreviations, deliberately not shared), so a "general-looking" lemma may resolve them only - transitively. Inline the raw type or it won't compile in the library. -- **Migrating a lemma out of an example**: leave a thin re-export shim under the old name - (`theorem erc20Foo … := libFoo …`) so the example's call sites stay unchanged. - -## Building / verifying - -A bare `lake build` does **not** compile `Reasoning.ExternalCall` or `Examples/*/Correct`. After -touching a shared module, build the affected `Examples..Correct` targets explicitly and scan for -`sorry`/`admit`. Editing a low module rebuilds everything above it — expect long rebuilds. diff --git a/Reasoning/Memory.lean b/Reasoning/Memory.lean index c07749a7..b3b3be54 100644 --- a/Reasoning/Memory.lean +++ b/Reasoning/Memory.lean @@ -255,10 +255,6 @@ theorem byteArray_write_len_zero (src base : ByteArray) (srcOff dstOff : ℕ) : unfold ByteArray.write simp -/-- `(A ++ B).size = A.size + B.size` for `ByteArray`. -/ -theorem byteArray_size_append (A B : ByteArray) : (A ++ B).size = A.size + B.size := - ByteArray.size_append - /-- `ffi.ByteArray.zeroes` of a `toNat`-zero size is the empty array. -/ theorem zeroes_zero {n : Nat} (hn : n = 0) : ffi.ByteArray.zeroes n = ByteArray.empty := by apply ByteArray.ext @@ -1572,17 +1568,6 @@ theorem mappingSlot_single (key baseSlot : UInt256) : = uInt256OfByteArray (ffi.KEC (key.toByteArray ++ baseSlot.toByteArray)) := keccakSlot_eq _ -/-- **Nested-mapping slot.** For `mapping[k₁][k₂]` at base `baseSlot`: the inner slot is the - single-mapping slot for `k₁`, and the outer `KECCAK256` over `k₂ ‖ innerSlot` yields the Solm - layout slot — matching `uInt256OfByteArray (KEC (k₂ ‖ KEC(k₁ ‖ baseSlot)))`. -/ -theorem mappingSlot_nested (k₁ k₂ baseSlot : UInt256) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC (k₂.toByteArray - ++ (uInt256OfByteArray (ffi.KEC (k₁.toByteArray ++ baseSlot.toByteArray))).toByteArray))) - = uInt256OfByteArray (ffi.KEC (k₂.toByteArray - ++ (uInt256OfByteArray (ffi.KEC (k₁.toByteArray ++ baseSlot.toByteArray))).toByteArray)) := - keccakSlot_eq _ - /-- **Load coupling.** The word `RD.sload` pushes (storage of `codeOwner` at `slot`, read from the carried `accountMap`) is exactly the Solm-level `storageLoad` of the same account/slot — so a mapping `SLOAD` at the keccak slot reads the same word the Solm spec's `storageLocLoad` decodes. -/ diff --git a/Reasoning/Reach.lean b/Reasoning/Reach.lean index b6a78203..bee73f46 100644 --- a/Reasoning/Reach.lean +++ b/Reasoning/Reach.lean @@ -20,7 +20,7 @@ ordinary function application (`r.jumpdest … |>.swap1 …`), the out-of-gas c threads itself inside the `Prop`, and `RD.conclude` repackages the indices back into the `∃ k' C'` form the segment lemmas state. -Design notes live in `Reasoning/REACH_PLAN.md`. Built on `Reasoning.Theory` +Built on `Reasoning.Theory` (`stepContinue`/`stepOOG`, `toNat_sub_ofNat`) and `Reasoning.Stepping` (the `st_op` successors + `_xstep` lemmas). Straight-line only; control flow stays ordinary Lean and composes by `RD` transitivity at the call site. @@ -1578,7 +1578,7 @@ theorem Theta_returnData_size_lt_2pow138_of_eq rw [← hΘ] at htheta simpa using htheta -/-- **SSTORE** as an `RD → RD` combinator (existential step/gas counters, like `RD.loop`): from a +/-- **SSTORE** as an `RD → RD` combinator (existential step/gas counters): from a cursor at the `SSTORE` pc with `[slot, val, …t]` and carried accounts `(cA, σ)`, write `val` to `slot` of the caller account (`ee.codeOwner`), advancing the carried `accountMap` to `sstoreAccountMap ee.codeOwner σ slot val` (`createdAccounts` and memory untouched). The cost @@ -1651,7 +1651,7 @@ theorem RD.caller {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : Stat /-- **ADDRESS**: push the current contract address (`ee.codeOwner`) onto the stack (cost `Gbase = 2`, pc += 1). -/ -theorem RD.uniswapAddress {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} +theorem RD.address {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc : UInt256} {stk : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} @@ -1662,60 +1662,60 @@ theorem RD.uniswapAddress {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} unfold RD at h ⊢ rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, hee, hworld⟩ · exact Or.inl hoog - · have st := uniswapAddress_xstep hcode hpc hdec hstk hov + · have st := address_xstep hcode hpc hdec hstk hov by_cases gg : g.toNat < C + 2 · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨uniswapStAddress s, + · refine Or.inr ⟨stAddress s, hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, by omega, by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [uniswapStAddress]; exact hcode - · simp only [uniswapStAddress]; rw [hpc] - · simp only [uniswapStAddress]; rw [hstk, hee] - · simp only [uniswapStAddress]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [uniswapStAddress]; exact hmem - · simp only [uniswapStAddress]; exact haw - · simp only [uniswapStAddress]; exact hrdata - · simp only [uniswapStAddress]; exact hacc + · simp only [stAddress]; exact hcode + · simp only [stAddress]; rw [hpc] + · simp only [stAddress]; rw [hstk, hee] + · simp only [stAddress]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] + · simp only [stAddress]; exact hmem + · simp only [stAddress]; exact haw + · simp only [stAddress]; exact hrdata + · simp only [stAddress]; exact hacc · exact hee · exact hworld /-- **EXTCODESIZE**: push the target account code size onto the stack, existentializing the warm/cold `Caccess` gas cost like `RD.sload` does for `Csload`. -/ -theorem RD.uniswapExtcodesize {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} +theorem RD.extcodesize {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} {target : UInt256} {t : List UInt256} (h : RD code ee g s0 pc (target :: t) mem aw rdata (cA, σ) k C) (hdec : decode code pc = some (.EXTCODESIZE, .none)) (hov : t.length + 1 ≤ 1024) : ∃ k' C', RD code ee g s0 (pc + ⟨1⟩) - (uniswapExtCodeSizeWord σ target :: t) mem aw rdata (cA, σ) k' C' := by + (extCodeSizeWord σ target :: t) mem aw rdata (cA, σ) k' C' := by unfold RD at h rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, hee, hworld⟩ · exact ⟨k, C, Or.inl hoog⟩ - · have st := uniswapExtcodesize_xstep hcode hpc hdec hstk hov + · have st := extcodesize_xstep hcode hpc hdec hstk hov have hσ : s.accountMap = σ := congrArg Prod.snd hacc have hcA : s.createdAccounts = cA := congrArg Prod.fst hacc by_cases gg : g.toNat < C + Caccess (AccountAddress.ofUInt256 target) s.substate · exact ⟨k, C, Or.inl (hX.trans (stepOOG hgas st hk hC gg))⟩ · refine ⟨k + 1, C + Caccess (AccountAddress.ofUInt256 target) s.substate, - Or.inr ⟨uniswapStExtcodesize s target t, + Or.inr ⟨stExtcodesize s target t, hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, by have hpos : 1 ≤ Caccess (AccountAddress.ofUInt256 target) s.substate := by unfold Caccess; split <;> decide omega, by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩⟩ - · simp only [uniswapStExtcodesize]; exact hcode - · simp only [uniswapStExtcodesize]; rw [hpc] - · simp only [uniswapStExtcodesize, uniswapExtCodeSizeWord, hσ] - · simp only [uniswapStExtcodesize] + · simp only [stExtcodesize]; exact hcode + · simp only [stExtcodesize]; rw [hpc] + · simp only [stExtcodesize, extCodeSizeWord, hσ] + · simp only [stExtcodesize] rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [uniswapStExtcodesize]; exact hmem - · simp only [uniswapStExtcodesize]; exact haw - · simp only [uniswapStExtcodesize]; exact hrdata - · simp only [uniswapStExtcodesize]; rw [hcA, hσ] - · simp only [uniswapStExtcodesize]; exact hee + · simp only [stExtcodesize]; exact hmem + · simp only [stExtcodesize]; exact haw + · simp only [stExtcodesize]; exact hrdata + · simp only [stExtcodesize]; rw [hcA, hσ] + · simp only [stExtcodesize]; exact hee · exact hworld /-- **SWAP4**: exchange the stack top with the 5th element (cost `Gverylow = 3`, pc += 1). -/ @@ -3722,8 +3722,7 @@ theorem RDret.reEquivElim /-! ## Callable interface — exposing a segment's raw `Ξ` result `xiResult` turns an `RDret`/`RDrev` over `initState` into the `Ξ`-level disjunction (out-of-gas or -the concrete halt). (Originally built for callee-correctness reuse; the external-call proof instead -treats the sub-call result as opaque, so this is currently unused — kept pending cleanup.) -/ +the concrete halt). -/ /-- A success segment's **raw `Ξ` result**: either the run OOGs, or `Ξ` halts with success returning `o`, the accounts projected back to the carried `(cA, σ)`. -/ @@ -3751,35 +3750,6 @@ theorem RDrev.xiResult {cA gh bl σ σ₀ A I} {g : Sat256} {code : ByteArray} · exact Or.inl (Xi_error_of_X_sat (by rw [← hcode] at hoog; exact hoog)) · exact Or.inr ⟨g', o, Xi_revert_of_X_sat (by rw [← hcode] at hX; exact hX)⟩ -/-! ## Spike acceptance: a 2-step fold closes a fixed-pc / fixed-stack conclusion -/ - -/-- JUMPDEST then SWAP1, fully abstract over the bytecode (decode facts supplied as - hypotheses). Confirms `conclude` produces the fixed `pc`/`stack` and the carried - `memory`/`activeWords`/accounts preservation with no leftover goals. -/ -example {code : ByteArray} {g : Sat256} {s0 s : State} {k C : ℕ} - {a b : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = ⟨10⟩) - (hstk : s.machineState.stack = a :: b :: t) - (hd0 : decode code ⟨10⟩ = some (.JUMPDEST, .none)) - (hd1 : decode code (⟨10⟩ + ⟨1⟩) = some (.SWAP1, .none)) - (hov : t.length + 2 ≤ 1024) - (hgas : s.machineState.gasAvailable = g.subNat C) (hk : k ≤ C) (hC : C ≤ g.toNat) - (hX : X (g.toNat + 1) (D_J code 0) s0 = X (g.toNat + 1 - k) (D_J code 0) s) - (hworld : RDWorld s0 s) : - X (g.toNat + 1) (D_J code 0) s0 = .error .OutOfGass - ∨ ∃ (k' C' : ℕ) (s' : State), - X (g.toNat + 1) (D_J code 0) s0 = X (g.toNat + 1 - k') (D_J code 0) s' - ∧ s'.executionEnv.code = code ∧ s'.machineState.pc = ⟨10⟩ + ⟨1⟩ + ⟨1⟩ - ∧ s'.machineState.stack = b :: a :: t - ∧ s'.machineState.gasAvailable = g.subNat C' ∧ k' ≤ C' ∧ C' ≤ g.toNat - ∧ s'.machineState.memory = s.machineState.memory - ∧ s'.machineState.activeWords = s.machineState.activeWords - ∧ s'.machineState.returnData = s.machineState.returnData - ∧ (s'.createdAccounts, s'.accountMap) = (s.createdAccounts, s.accountMap) := - (RD.start hcode hpc hstk hgas hk hC hX hworld - |>.jumpdest hd0 (by simp only [List.length_cons]; omega) - |>.swap1 hd1 (by omega)).conclude - /-! ## `evm_run` — a boilerplate-eliding chain builder Every straight-line combinator above ends in the *same* two trailing proofs: a decode diff --git a/Reasoning/Refinement.lean b/Reasoning/Refinement.lean index ac81e3b7..7cabe30a 100644 --- a/Reasoning/Refinement.lean +++ b/Reasoning/Refinement.lean @@ -51,14 +51,6 @@ end StateRel mention the local store. -/ abbrev StoreRel := Cursor → Store → State → Prop -namespace StoreRel - -/-- Lift a locals-only relation to the frame-shaped relation expected by top-level statement rules. -/ -def toStateRel (R : StoreRel) : StateRel := - fun cur frame evm => R cur frame.locals evm - -end StoreRel - /-- A postcondition over a Solm block result. The postcondition is where each client decides what `.ok`, `.returned`, `.break`, `.continue`, and `.reverted` mean on the EVM side. -/ abbrev StmtPost := ExecResult → Prop @@ -131,15 +123,6 @@ def CoupledState.stepRD {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 (cursorOfRD pc' stack' mem' aw' rdata' world') frame' evm') pc' := CoupledState.ofRD frame' evm' hRD hworld (StateRel.stepFrom_here st.hrel) -/-- Compatibility wrapper for older proof scripts; prefer `CoupledState.reached` at the new state. -/ -def CoupledState.next {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R R' : StateRel} {pc pc' : UInt256} (_st : CoupledState code ee g s0 R pc) - (cur' : Cursor) (k' C' : ℕ) (frame' : Frame) (evm' : State) - (hpc' : cur'.pc = pc') (hRD' : RDc code ee g s0 cur' k' C') - (hworld' : cur'.world = worldOf evm') (hrel' : R' cur' frame' evm') : - CoupledState code ee g s0 R' pc' := - CoupledState.reached cur' k' C' frame' evm' hpc' hRD' hworld' hrel' - /-- Convert the cursor-indexed reachability proof stored in a coupled state into the positional `RD` form expected by `evm_run`, after exposing the cursor fields used by the local relation. -/ theorem CoupledState.toRD {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} diff --git a/Reasoning/Solc.lean b/Reasoning/Solc.lean index 4bd4b993..249c150e 100644 --- a/Reasoning/Solc.lean +++ b/Reasoning/Solc.lean @@ -6,13 +6,20 @@ import Reasoning.Reach /-! # Solc — reusable boilerplate shared by every solc-compiled contract -Solidity's compiler emits the same prologue for every external function: a free-memory-pointer -store, a non-payable guard, a `calldatasize` check, and a **4-byte selector dispatch**. The -selector dispatch is identical across contracts apart from the four selector bytes, so it is proved -here once, generically, and instantiated per contract (`truthEvmSelector`, `powEvmSelector`). - -Everything in this file is contract-agnostic; the only inputs are the four selector bytes and the -matching `UInt256` constant. +Solidity's compiler emits the same code shapes in every contract; this file proves them once, +generically, so per-contract proofs only instantiate them. Contents: + +- the **4-byte selector dispatch** (selector word, big-endian decode, the generic dispatch lemma, + the dispatcher scaffold and one-level binary dispatch); +- ABI decoder length checks for calldata and returndata tuples; +- the recurring memory shapes: free-memory-pointer store, `Error(string)` revert memory, mapping + scratch memory, dynamic bytes/string return and calldata-copy memory; +- the 160-bit **address-cleanup mask** and its canonicality facts; +- getter thunks, mapping getter/store routines, reentrancy-lock prefixes, checked-arithmetic + success tails, boolean-success continuations, event-log suffixes, one-word return wrappers; +- high-level external-call combinators (EXTCODESIZE guard, call-success guard, STATICCALL). + +Everything in this file is contract-agnostic. -/ namespace Reasoning.Theory @@ -896,9 +903,6 @@ noncomputable def solcBytesReturnAllocMem (len : UInt256) : ByteArray := noncomputable def solcBytesReturnLengthMem (len : UInt256) : ByteArray := len.toByteArray.write 0 (solcBytesReturnAllocMem len) 128 32 -def solcBytesReturnPayloadWord (header : UInt256) : UInt256 := - (header / ⟨256⟩) * ⟨256⟩ - noncomputable def solcBytesReturnPayloadMem (len payloadWord : UInt256) : ByteArray := payloadWord.toByteArray.write 0 (solcBytesReturnLengthMem len) 160 32 @@ -1385,7 +1389,7 @@ theorem memExpRevert0 (s : State) {t : List UInt256} show (⟨0⟩ : UInt256).toNat = 0 from rfl, MachineState.M, hof, Nat.sub_self] /-- `REVERT` (or `RETURN`) memory-expansion cost when the **offset is zero** and the length `len` is - arbitrary (e.g. the post-call `RETURNDATACOPY`+`REVERT` failure tail copies/​reverts the whole + arbitrary (e.g. the post-call `RETURNDATACOPY`+`REVERT` failure tail copies/reverts the whole return buffer at offset 0). Unlike `memExpRevert0` the cost is *not* zero, so it is returned symbolically in terms of the carried active-words. -/ theorem memExpRevertZeroOff (s : State) {len : UInt256} {t : List UInt256} @@ -1437,10 +1441,11 @@ theorem solcGuardPrologueRD {cA gh bl σ σ₀ A I} {g : Sat256} {code : ByteArr /-! ## solc address cleanup (the 160-bit mask) -Every solc-compiled function masks `address` values with `0xff…ff` (20 bytes, `PUSH20`) to clean the -high 96 bits. These facts couple that mask to address canonicality (`< 2^160`). -/ +Every solc-compiled function masks `address` values with the 160-bit mask `0xff…ff` (built by the +optimizer as `PUSH1 1; PUSH1 160; SHL; SUB`) to clean the high 96 bits. These facts couple that +mask to address canonicality (`< 2^160`). -/ -/-- The address-cleanup mask literal `0xff…ff` (`PUSH20`), shared by every solc contract. -/ +/-- The address-cleanup mask literal `2^160 - 1`, shared by every solc contract. -/ def solcAddrMask : UInt256 := ⟨1461501637330902918203684832716283019655932542975⟩ /-- The canonical EVM word for `CALLER`/`msg.sender`. -/ @@ -1555,9 +1560,9 @@ theorem fromBytes'_take20_wordLE_solcAddrMask (w : UInt256) : simpa [solcAddrMask] using fromBytes'_take_wordLE_land_mask w 20 (by decide) --- Reading an arbitrary little-endian byte window of an EVM word is the corresponding --- divide-and-mask operation. set_option maxHeartbeats 1000000 in +/-- Reading an arbitrary little-endian byte window of an EVM word is the corresponding + divide-and-mask operation. -/ theorem fromBytes'_drop_take_wordLE_land_div_mask (w : UInt256) (off size : Nat) (hoff : 8 * off < 256) (hsize : 8 * size ≤ 256) : fromBytes' (((EVM.Word.toBytesLEWithSizeProof w).1.drop off).take size) = @@ -1859,9 +1864,9 @@ theorem RD.solcOneAddressExternalLenOk {cA gh bl σ σ₀ A I} {g : Sat256} hd13 hd14 hd17 hdecoded hlt set_option maxHeartbeats 1000000 in -theorem RD.solcOneAddressExternalMaskAndJump {code : ByteArray} {g : Sat256} {s0 : State} - {ee : ExecutionEnv} {k C : ℕ} {decoded ret routine de : UInt256} {R : List UInt256} - {mem rdata : ByteArray} {aw : UInt256} +theorem RD.solcOneAddressExternalMaskAndJumpMasked {code : ByteArray} {g : Sat256} + {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {decoded ret routine de : UInt256} + {R : List UInt256} {mem rdata : ByteArray} {aw : UInt256} {acc : Batteries.RBSet AccountAddress compare × AccountMap} (h : RD code ee g s0 decoded (de :: ⟨4⟩ :: ret :: R) mem aw rdata acc k C) (hd0 : decode code decoded = some (.JUMPDEST, .none)) @@ -1901,18 +1906,11 @@ theorem RD.solcOneAddressExternalMaskAndJump {code : ByteArray} {g : Sat256} {s0 ((decoded + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) + UInt256.ofNat 3) = some (.JUMP, .none)) - (hcanon : (calldataWord ee.calldata 4).toNat < EVM.addressModulus) (hroutine : (D_J code 0).contains routine = true) (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 routine (calldataWord ee.calldata 4 :: ret :: R) + ∃ k' C', RD code ee g s0 routine + (UInt256.land solcAddrMask (calldataWord ee.calldata 4) :: ret :: R) mem aw rdata acc k' C' := by - have hmask : - UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) - (calldataWord ee.calldata 4) = - calldataWord ee.calldata 4 := by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact solcAddrMask_clean_left hcanon have rd1 := h.jumpdest hd0 (by evm_ov) have rd2 := rd1.pop hd1 (by evm_ov) have rd3 := rd2.calldataload hd2 (by evm_ov) @@ -1924,13 +1922,13 @@ theorem RD.solcOneAddressExternalMaskAndJump {code : ByteArray} {g : Sat256} {s0 have rd12 := rd11.and hd11 (by evm_ov) have rd15 := rd12.push2 routine hd12 (by evm_ov) exact ⟨_, _, by - simpa [calldataWord, show (⟨4⟩ : UInt256).toNat = 4 from by decide, hmask] + simpa [calldataWord, show (⟨4⟩ : UInt256).toNat = 4 from by decide, solcAddrMask] using rd15.jump hd15 hroutine (by evm_ov)⟩ set_option maxHeartbeats 1000000 in -theorem RD.solcOneAddressExternalMaskAndJumpMasked {code : ByteArray} {g : Sat256} - {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {decoded ret routine de : UInt256} - {R : List UInt256} {mem rdata : ByteArray} {aw : UInt256} +theorem RD.solcOneAddressExternalMaskAndJump {code : ByteArray} {g : Sat256} {s0 : State} + {ee : ExecutionEnv} {k C : ℕ} {decoded ret routine de : UInt256} {R : List UInt256} + {mem rdata : ByteArray} {aw : UInt256} {acc : Batteries.RBSet AccountAddress compare × AccountMap} (h : RD code ee g s0 decoded (de :: ⟨4⟩ :: ret :: R) mem aw rdata acc k C) (hd0 : decode code decoded = some (.JUMPDEST, .none)) @@ -1970,24 +1968,19 @@ theorem RD.solcOneAddressExternalMaskAndJumpMasked {code : ByteArray} {g : Sat25 ((decoded + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) + UInt256.ofNat 3) = some (.JUMP, .none)) + (hcanon : (calldataWord ee.calldata 4).toNat < EVM.addressModulus) (hroutine : (D_J code 0).contains routine = true) (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 routine - (UInt256.land solcAddrMask (calldataWord ee.calldata 4) :: ret :: R) + ∃ k' C', RD code ee g s0 routine (calldataWord ee.calldata 4 :: ret :: R) mem aw rdata acc k' C' := by - have rd1 := h.jumpdest hd0 (by evm_ov) - have rd2 := rd1.pop hd1 (by evm_ov) - have rd3 := rd2.calldataload hd2 (by evm_ov) - have rd5 := rd3.push1 ⟨1⟩ hd3 (by evm_ov) - have rd7 := rd5.push1 ⟨1⟩ hd5 (by evm_ov) - have rd9 := rd7.push1 ⟨160⟩ hd7 (by evm_ov) - have rd10 := rd9.shl hd9 (by evm_ov) - have rd11 := rd10.sub hd10 (by evm_ov) - have rd12 := rd11.and hd11 (by evm_ov) - have rd15 := rd12.push2 routine hd12 (by evm_ov) - exact ⟨_, _, by - simpa [calldataWord, show (⟨4⟩ : UInt256).toNat = 4 from by decide, solcAddrMask] - using rd15.jump hd15 hroutine (by evm_ov)⟩ + obtain ⟨k', C', h'⟩ := + RD.solcOneAddressExternalMaskAndJumpMasked h hd0 hd1 hd2 hd3 hd5 hd7 hd9 hd10 hd11 + hd12 hd15 hroutine hov + have hmask : + UInt256.land solcAddrMask (calldataWord ee.calldata 4) = + calldataWord ee.calldata 4 := + solcAddrMask_clean_left hcanon + exact ⟨k', C', by simpa [hmask] using h'⟩ set_option maxHeartbeats 1000000 in theorem RD.solcTwoAddressExternalLenOk {cA gh bl σ σ₀ A I} {g : Sat256} @@ -2137,7 +2130,7 @@ theorem RD.solcExternalStaticArgsShortReverts {cA gh bl σ σ₀ A I} {g : Sat25 exact rd21.rev 0 hd21 mem_cost (by evm_ov) set_option maxHeartbeats 1000000 in -theorem RD.solcTwoAddressExternalMaskAndJump {code : ByteArray} {g : Sat256} +theorem RD.solcTwoAddressExternalMaskAndJumpMasked {code : ByteArray} {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {decoded ret routine de : UInt256} {R : List UInt256} {mem rdata : ByteArray} {aw : UInt256} {acc : Batteries.RBSet AccountAddress compare × AccountMap} @@ -2223,33 +2216,12 @@ theorem RD.solcTwoAddressExternalMaskAndJump {code : ByteArray} {g : Sat256} UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) + UInt256.ofNat 3) = some (.JUMP, .none)) - (hcanon0 : (calldataWord ee.calldata 4).toNat < EVM.addressModulus) - (hcanon1 : (calldataWord ee.calldata 36).toNat < EVM.addressModulus) (hroutine : (D_J code 0).contains routine = true) (hov : R.length + 7 ≤ 1024) : ∃ k' C', RD code ee g s0 routine - (calldataWord ee.calldata 36 :: calldataWord ee.calldata 4 :: ret :: R) + (UInt256.land solcAddrMask (calldataWord ee.calldata 36) :: + UInt256.land solcAddrMask (calldataWord ee.calldata 4) :: ret :: R) mem aw rdata acc k' C' := by - have hmask0 : - UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) - (calldataWord ee.calldata 4) = - calldataWord ee.calldata 4 := by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact solcAddrMask_clean_left hcanon0 - have hmask1 : - UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) - (calldataWord ee.calldata 36) = - calldataWord ee.calldata 36 := by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact solcAddrMask_clean_left hcanon1 - have hmask1Right : - UInt256.land (calldataWord ee.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) = - calldataWord ee.calldata 36 := by - rw [u256_land_comm] - exact hmask1 have rd1 := h.jumpdest hd0 (by evm_ov) have rd2 := rd1.pop hd1 (by evm_ov) have rd4 := rd2.push1 ⟨1⟩ hd2 (by evm_ov) @@ -2270,11 +2242,12 @@ theorem RD.solcTwoAddressExternalMaskAndJump {code : ByteArray} {g : Sat256} exact ⟨_, _, by simpa [calldataWord, show (⟨4⟩ : UInt256).toNat = 4 from by decide, show ((⟨32⟩ : UInt256) + ⟨4⟩).toNat = 36 from by decide, - hmask0, hmask1, hmask1Right] + show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = + solcAddrMask from by decide, u256_land_comm] using rd23.jump hd23 hroutine (by evm_ov)⟩ set_option maxHeartbeats 1000000 in -theorem RD.solcTwoAddressExternalMaskAndJumpMasked {code : ByteArray} {g : Sat256} +theorem RD.solcTwoAddressExternalMaskAndJump {code : ByteArray} {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {decoded ret routine de : UInt256} {R : List UInt256} {mem rdata : ByteArray} {aw : UInt256} {acc : Batteries.RBSet AccountAddress compare × AccountMap} @@ -2360,35 +2333,25 @@ theorem RD.solcTwoAddressExternalMaskAndJumpMasked {code : ByteArray} {g : Sat25 UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) + UInt256.ofNat 3) = some (.JUMP, .none)) + (hcanon0 : (calldataWord ee.calldata 4).toNat < EVM.addressModulus) + (hcanon1 : (calldataWord ee.calldata 36).toNat < EVM.addressModulus) (hroutine : (D_J code 0).contains routine = true) (hov : R.length + 7 ≤ 1024) : ∃ k' C', RD code ee g s0 routine - (UInt256.land solcAddrMask (calldataWord ee.calldata 36) :: - UInt256.land solcAddrMask (calldataWord ee.calldata 4) :: ret :: R) + (calldataWord ee.calldata 36 :: calldataWord ee.calldata 4 :: ret :: R) mem aw rdata acc k' C' := by - have rd1 := h.jumpdest hd0 (by evm_ov) - have rd2 := rd1.pop hd1 (by evm_ov) - have rd4 := rd2.push1 ⟨1⟩ hd2 (by evm_ov) - have rd6 := rd4.push1 ⟨1⟩ hd4 (by evm_ov) - have rd8 := rd6.push1 ⟨160⟩ hd6 (by evm_ov) - have rd9 := rd8.shl hd8 (by evm_ov) - have rd10 := rd9.sub hd9 (by evm_ov) - have rd11 := rd10.dup2 hd10 (by evm_ov) - have rd12 := rd11.calldataload hd11 (by evm_ov) - have rd13 := rd12.dup2 hd12 (by evm_ov) - have rd14 := rd13.and hd13 (by evm_ov) - have rd15 := rd14.swap2 hd14 (by evm_ov) - have rd17 := rd15.push1 ⟨32⟩ hd15 (by evm_ov) - have rd18 := rd17.add hd17 (by evm_ov) - have rd19 := rd18.calldataload hd18 (by evm_ov) - have rd20 := rd19.and hd19 (by evm_ov) - have rd23 := rd20.push2 routine hd20 (by evm_ov) - exact ⟨_, _, by - simpa [calldataWord, show (⟨4⟩ : UInt256).toNat = 4 from by decide, - show ((⟨32⟩ : UInt256) + ⟨4⟩).toNat = 36 from by decide, - show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, u256_land_comm] - using rd23.jump hd23 hroutine (by evm_ov)⟩ + obtain ⟨k', C', h'⟩ := + RD.solcTwoAddressExternalMaskAndJumpMasked h hd0 hd1 hd2 hd4 hd6 hd8 hd9 hd10 hd11 + hd12 hd13 hd14 hd15 hd17 hd18 hd19 hd20 hd23 hroutine hov + have hmask0 : + UInt256.land solcAddrMask (calldataWord ee.calldata 4) = + calldataWord ee.calldata 4 := + solcAddrMask_clean_left hcanon0 + have hmask1 : + UInt256.land solcAddrMask (calldataWord ee.calldata 36) = + calldataWord ee.calldata 36 := + solcAddrMask_clean_left hcanon1 + exact ⟨k', C', by simpa [hmask0, hmask1] using h'⟩ set_option maxHeartbeats 1000000 in theorem RD.solcAddressUint256ExternalMaskAndJumpMasked {code : ByteArray} {g : Sat256} @@ -6266,7 +6229,7 @@ theorem RD.revertStub {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : |>.rev 0 hd2 (fun s _ hstks => memExpRevert0 s hstks) (by omega) /-- Legacy solc `revert(0,0)` terminal emitted as `PUSH1 0; DUP1; REVERT`. -/ -theorem RD.uniswapPush1Dup1Revert0 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} +theorem RD.solcPush1Dup1Revert0 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc : UInt256} {stk : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} @@ -6280,8 +6243,8 @@ theorem RD.uniswapPush1Dup1Revert0 {code : ByteArray} {ee : ExecutionEnv} {g : S |>.dup1 hd1 (by omega) |>.rev 0 hd2 (fun s _ hstks => memExpRevert0 s hstks) (by omega) --- Generic solc high-level-call uint256 return decoder after a successful CALL-like opcode. set_option maxHeartbeats 2000000 in +/-- Generic solc high-level-call uint256 return decoder after a successful CALL-like opcode. -/ theorem RD.solcUint256ReturnWordDecodeOk {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc okPc : UInt256} {mem o : ByteArray} {aw : UInt256} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} @@ -6500,19 +6463,19 @@ theorem RD.solcUint256ReturnWordDecodeShortReverts {code : ByteArray} {ee : Exec decide have rdFallthrough := RD.jumpiNT rdPushOk hJumpi hcond (by simp only [List.length_cons]; omega) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough hPush0 hDupZero hRevert + exact RD.solcPush1Dup1Revert0 rdFallthrough hPush0 hDupZero hRevert (by simp only [List.length_cons]; omega) /-! ## Legacy solc high-level-call combinators -/ --- Generic solc high-level-call `EXTCODESIZE` guard for the branch where the target account has --- deployed code. -theorem RD.uniswapExtcodesizeGuardOk {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} +/-- Generic solc high-level-call `EXTCODESIZE` guard for the branch where the target account has + deployed code. -/ +theorem RD.solcExtcodesizeGuardOk {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc okPc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} {target : UInt256} {R : List UInt256} (h : RD code ee g s0 pc (target :: target :: R) mem aw rdata (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) (hExt : decode code pc = some (.EXTCODESIZE, .none)) (hIszero0 : decode code (pc + ⟨1⟩) = some (.ISZERO, .none)) (hDup1 : decode code (pc + ⟨1⟩ + ⟨1⟩) = some (.DUP1, .none)) @@ -6529,7 +6492,7 @@ theorem RD.uniswapExtcodesizeGuardOk {code : ByteArray} {ee : ExecutionEnv} {g : ∃ k' C', RD code ee g s0 (okPc + ⟨1⟩ + ⟨1⟩) (target :: R) mem aw rdata (cA, σ) k' C' := by obtain ⟨_, _, rdExt⟩ := - RD.uniswapExtcodesize h hExt + RD.extcodesize h hExt (by simp only [List.length_cons]; omega) have rdIszero0 := RD.iszero rdExt hIszero0 (by simp only [List.length_cons]; omega) @@ -6541,7 +6504,7 @@ theorem RD.uniswapExtcodesizeGuardOk {code : ByteArray} {ee : ExecutionEnv} {g : (by simp only [List.length_cons]; omega) have hcond : UInt256.isZero (UInt256.isZero - (Reasoning.Theory.uniswapExtCodeSizeWord σ target)) ≠ ⟨0⟩ := by + (Reasoning.Theory.extCodeSizeWord σ target)) ≠ ⟨0⟩ := by rw [Reasoning.Theory.isZero_eq_zero_of_ne hcodeSize] decide have rdJumpi := RD.jumpiT rdPush hJumpi hcond hjd @@ -6552,15 +6515,15 @@ theorem RD.uniswapExtcodesizeGuardOk {code : ByteArray} {ee : ExecutionEnv} {g : (by simp only [List.length_cons]; omega) exact ⟨_, _, rdPop⟩ --- Generic solc high-level-call `EXTCODESIZE` guard plus `GAS`, stopping at the call opcode with --- existential gas. -theorem RD.uniswapExtcodesizeGuardOkGas {code : ByteArray} {ee : ExecutionEnv} +/-- Generic solc high-level-call `EXTCODESIZE` guard plus `GAS`, stopping at the call opcode with + existential gas. -/ +theorem RD.solcExtcodesizeGuardOkGas {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc okPc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} {target : UInt256} {R : List UInt256} (h : RD code ee g s0 pc (target :: target :: R) mem aw rdata (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) (hExt : decode code pc = some (.EXTCODESIZE, .none)) (hIszero0 : decode code (pc + ⟨1⟩) = some (.ISZERO, .none)) (hDup1 : decode code (pc + ⟨1⟩ + ⟨1⟩) = some (.DUP1, .none)) @@ -6578,21 +6541,21 @@ theorem RD.uniswapExtcodesizeGuardOkGas {code : ByteArray} {ee : ExecutionEnv} ∃ gasWord k' C', RD code ee g s0 (okPc + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) (gasWord :: target :: R) mem aw rdata (cA, σ) k' C' := by obtain ⟨_, _, rdReady⟩ := - RD.uniswapExtcodesizeGuardOk h hcodeSize hExt hIszero0 hDup1 hIszero1 hPush hJumpi + RD.solcExtcodesizeGuardOk h hcodeSize hExt hIszero0 hDup1 hIszero1 hPush hJumpi hjd hJumpdest hPop hov obtain ⟨gasWord, rdGas⟩ := RD.gas rdReady hGas (by simp only [List.length_cons]; omega) exact ⟨gasWord, _, _, rdGas⟩ --- Generic solc high-level-call `EXTCODESIZE` guard for the branch where the target account has no --- deployed code. -theorem RD.uniswapExtcodesizeGuardMissing {code : ByteArray} {ee : ExecutionEnv} +/-- Generic solc high-level-call `EXTCODESIZE` guard for the branch where the target account has no + deployed code. -/ +theorem RD.solcExtcodesizeGuardMissing {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc okPc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} {target : UInt256} {R : List UInt256} (h : RD code ee g s0 pc (target :: target :: R) mem aw rdata (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) (hExt : decode code pc = some (.EXTCODESIZE, .none)) (hIszero0 : decode code (pc + ⟨1⟩) = some (.ISZERO, .none)) (hDup1 : decode code (pc + ⟨1⟩ + ⟨1⟩) = some (.DUP1, .none)) @@ -6618,7 +6581,7 @@ theorem RD.uniswapExtcodesizeGuardMissing {code : ByteArray} {ee : ExecutionEnv} (hov : R.length + 4 ≤ 1024) : RDrev code g s0 := by obtain ⟨_, _, rdExt⟩ := - RD.uniswapExtcodesize h hExt + RD.extcodesize h hExt (by simp only [List.length_cons]; omega) have rdIszero0 := RD.iszero rdExt hIszero0 (by simp only [List.length_cons]; omega) @@ -6630,17 +6593,17 @@ theorem RD.uniswapExtcodesizeGuardMissing {code : ByteArray} {ee : ExecutionEnv} (by simp only [List.length_cons]; omega) have hcond : UInt256.isZero (UInt256.isZero - (Reasoning.Theory.uniswapExtCodeSizeWord σ target)) = ⟨0⟩ := by + (Reasoning.Theory.extCodeSizeWord σ target)) = ⟨0⟩ := by rw [hcodeSize] decide have rdFallthrough := RD.jumpiNT rdPush hJumpi hcond (by simp only [List.length_cons]; omega) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough hPush0 hDupZero hRevert + exact RD.solcPush1Dup1Revert0 rdFallthrough hPush0 hDupZero hRevert (by simp only [List.length_cons]; omega) --- Generic solc high-level-call success guard for the branch where a CALL-like status word is --- nonzero. -theorem RD.uniswapCallSuccessGuardOk {code : ByteArray} {ee : ExecutionEnv} +/-- Generic solc high-level-call success guard for the branch where a CALL-like status word is + nonzero. -/ +theorem RD.solcCallSuccessGuardOk {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc okPc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} @@ -6678,9 +6641,9 @@ theorem RD.uniswapCallSuccessGuardOk {code : ByteArray} {ee : ExecutionEnv} (by omega) exact ⟨_, _, rdPop⟩ --- Generic solc high-level-call success guard for the branch where a CALL-like status word is zero --- and the revert-data bubbling tail is executed. -theorem RD.uniswapCallSuccessGuardMissing {code : ByteArray} {ee : ExecutionEnv} +/-- Generic solc high-level-call success guard for the branch where a CALL-like status word is zero + and the revert-data bubbling tail is executed. -/ +theorem RD.solcCallSuccessGuardMissing {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc okPc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} @@ -6772,9 +6735,9 @@ theorem RD.uniswapCallSuccessGuardMissing {code : ByteArray} {ee : ExecutionEnv} simpa [awout, len, haw] using memExpRevertZeroOff s hstk) (by simp only [List.length_cons]; omega) --- Same opaque `Θ` reach proof shape as `RD.call`, specialized to `STATICCALL`. set_option maxHeartbeats 1000000 in -theorem RD.uniswapStaticcall {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} +/-- Same opaque `Θ` reach proof shape as `RD.call`, specialized to `STATICCALL`. -/ +theorem RD.solcStaticcall {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} {gasArg target inOffset inSize outOffset outSize : UInt256} @@ -6943,8 +6906,8 @@ theorem RD.uniswapStaticcall {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} (s.executionEnv.depth + 1) s.executionEnv.header false (Ethereum.EVM.ByteArray.readWithPadding_size_lt_uint256 _ _ _) --- Generic `STATICCALL` depth-limit `RD` combinator. -theorem RD.uniswapStaticcallDepthLimit {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} +/-- Generic `STATICCALL` depth-limit `RD` combinator. -/ +theorem RD.solcStaticcallDepthLimit {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} {gasArg target inOffset inSize outOffset outSize : UInt256} diff --git a/Reasoning/SolcDecode.lean b/Reasoning/SolcDecode.lean deleted file mode 100644 index b306a07f..00000000 --- a/Reasoning/SolcDecode.lean +++ /dev/null @@ -1,213 +0,0 @@ -import Reasoning.Solc - -/-! -# SolcDecode — experimental scalar ABI decoder routine combinators - -This file keeps the bytecode/PC-parametric scalar decoder routines separate from the main -`Reasoning.Solc` library. They are useful as a reference point for future decoder factoring, but -are intentionally not imported by the examples. --/ - -namespace Reasoning.Reach - -open Ethereum Ethereum.EVM Reasoning.Theory - -/-! ## Solc scalar ABI decoder routines - -These lemmas capture small compiler-emitted decoder subroutines independently of a particular -contract. Concrete proofs discharge the `*Wf` bytecode-shape hypotheses with `by decide`, but the -large instruction trace is checked once here. - -These are currently unused, as they did not provide significant simplifications. --/ - -/-- Bytecode shape for solc's `cleanup_t_uint256` identity routine. -/ -@[reducible] def solcCleanupUInt256Wf (code : ByteArray) (pc : UInt256) : Prop := - let p1 := pc + ⟨1⟩ - let p2 := p1 + ⟨1⟩ - let p3 := p2 + ⟨1⟩ - let p4 := p3 + ⟨1⟩ - let p5 := p4 + ⟨1⟩ - let p6 := p5 + ⟨1⟩ - let p7 := p6 + ⟨1⟩ - let p8 := p7 + ⟨1⟩ - decode code pc = some (.JUMPDEST, .none) - ∧ decode code p1 = some (.PUSH0, .none) - ∧ decode code p2 = some (.DUP2, .none) - ∧ decode code p3 = some (.SWAP1, .none) - ∧ decode code p4 = some (.POP, .none) - ∧ decode code p5 = some (.SWAP2, .none) - ∧ decode code p6 = some (.SWAP1, .none) - ∧ decode code p7 = some (.POP, .none) - ∧ decode code p8 = some (.JUMP, .none) - -/-- -solc `cleanup_t_uint256`: from `[v, ret, ...]`, return `v` unchanged to the dynamic return -address. This is the common identity cleanup used by uint256 decoders and encoders. --/ -theorem RD.solcCleanupUInt256 {code : ByteArray} {g : Sat256} {s0 : State} - {ee : ExecutionEnv} {k C : ℕ} {pc v ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - (h : RD code ee g s0 pc (v :: ret :: R) mem aw rdata acc k C) - (hwf : solcCleanupUInt256Wf code pc) - (hret : (D_J code 0).contains ret = true) (hov : R.length + 4 ≤ 1024) : - RD code ee g s0 ret (v :: R) mem aw rdata acc (k + 9) (C + 27) := by - rcases hwf with ⟨hd0, hd1, hd2, hd3, hd4, hd5, hd6, hd7, hd8⟩ - exact h.jumpdest hd0 (by evm_ov) - |>.push0 hd1 (by evm_ov) - |>.dup2 hd2 (by evm_ov) - |>.swap1 hd3 (by evm_ov) - |>.pop hd4 (by evm_ov) - |>.swap2 hd5 (by evm_ov) - |>.swap1 hd6 (by evm_ov) - |>.pop hd7 (by evm_ov) - |>.jump hd8 hret (by evm_ov) - -/-- Bytecode shape for solc's uint256 validator routine, parameterized by its inner cleanup call. -/ -@[reducible] def solcValidateUInt256Wf - (code : ByteArray) (pc cleanupPc afterCleanupPc okPc : UInt256) : Prop := - let p1 := pc + ⟨1⟩ - let p4 := p1 + UInt256.ofNat 3 - let p5 := p4 + ⟨1⟩ - let p8 := p5 + UInt256.ofNat 3 - let a1 := afterCleanupPc + ⟨1⟩ - let a2 := a1 + ⟨1⟩ - let a3 := a2 + ⟨1⟩ - let a6 := a3 + UInt256.ofNat 3 - let ok1 := okPc + ⟨1⟩ - let ok2 := ok1 + ⟨1⟩ - decode code pc = some (.JUMPDEST, .none) - ∧ decode code p1 = some (.Push .PUSH2, some (afterCleanupPc, 2)) - ∧ decode code p4 = some (.DUP2, .none) - ∧ decode code p5 = some (.Push .PUSH2, some (cleanupPc, 2)) - ∧ decode code p8 = some (.JUMP, .none) - ∧ decode code afterCleanupPc = some (.JUMPDEST, .none) - ∧ decode code a1 = some (.DUP2, .none) - ∧ decode code a2 = some (.EQ, .none) - ∧ decode code a3 = some (.Push .PUSH2, some (okPc, 2)) - ∧ decode code a6 = some (.JUMPI, .none) - ∧ decode code okPc = some (.JUMPDEST, .none) - ∧ decode code ok1 = some (.POP, .none) - ∧ decode code ok2 = some (.JUMP, .none) - -/-- -solc uint256 validator: call `cleanup_t_uint256`, compare the cleaned value with the original -value, and return to `ret`. For uint256 the comparison is reflexive, so this is a pass-only -validator. --/ -theorem RD.solcValidateUInt256 {code : ByteArray} {g : Sat256} {s0 : State} - {ee : ExecutionEnv} {k C : ℕ} - {pc cleanupPc afterCleanupPc okPc arg ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - (h : RD code ee g s0 pc (arg :: ret :: R) mem aw rdata acc k C) - (hwf : solcValidateUInt256Wf code pc cleanupPc afterCleanupPc okPc) - (hcleanup : solcCleanupUInt256Wf code cleanupPc) - (hcleanupJd : (D_J code 0).contains cleanupPc = true) - (hafterCleanupJd : (D_J code 0).contains afterCleanupPc = true) - (hokJd : (D_J code 0).contains okPc = true) - (hret : (D_J code 0).contains ret = true) (hov : R.length + 6 ≤ 1024) : - RD code ee g s0 ret R mem aw rdata acc (k + 22) (C + 76) := by - rcases hwf with - ⟨hd0, hd1, hd2, hd3, hd4, hd5, hd6, hd7, hd8, hd9, hd10, hd11, hd12⟩ - have h1 := h.jumpdest hd0 (by evm_ov) - |>.push2 afterCleanupPc hd1 (by evm_ov) - |>.dup2 hd2 (by evm_ov) - |>.push2 cleanupPc hd3 (by evm_ov) - |>.jump hd4 hcleanupJd (by evm_ov) - have h2 := h1.solcCleanupUInt256 hcleanup hafterCleanupJd (by evm_ov) - exact h2.jumpdest hd5 (by evm_ov) - |>.dup2 hd6 (by evm_ov) - |>.eq hd7 (by evm_ov) - |>.push2 okPc hd8 (by evm_ov) - |>.jumpiT hd9 (by rw [u256_eq_refl]; exact one_ne_zero_uint) hokJd (by evm_ov) - |>.jumpdest hd10 (by evm_ov) - |>.pop hd11 (by evm_ov) - |>.jump hd12 hret (by evm_ov) - -/-- Bytecode shape for solc's `abi_decode_uint256` routine, parameterized by its validator call. -/ -@[reducible] def solcDecodeUInt256Wf - (code : ByteArray) (pc validatePc afterValidatePc : UInt256) : Prop := - let p1 := pc + ⟨1⟩ - let p2 := p1 + ⟨1⟩ - let p3 := p2 + ⟨1⟩ - let p4 := p3 + ⟨1⟩ - let p5 := p4 + ⟨1⟩ - let p6 := p5 + ⟨1⟩ - let p9 := p6 + UInt256.ofNat 3 - let p10 := p9 + ⟨1⟩ - let p13 := p10 + UInt256.ofNat 3 - let a1 := afterValidatePc + ⟨1⟩ - let a2 := a1 + ⟨1⟩ - let a3 := a2 + ⟨1⟩ - let a4 := a3 + ⟨1⟩ - let a5 := a4 + ⟨1⟩ - decode code pc = some (.JUMPDEST, .none) - ∧ decode code p1 = some (.PUSH0, .none) - ∧ decode code p2 = some (.DUP2, .none) - ∧ decode code p3 = some (.CALLDATALOAD, .none) - ∧ decode code p4 = some (.SWAP1, .none) - ∧ decode code p5 = some (.POP, .none) - ∧ decode code p6 = some (.Push .PUSH2, some (afterValidatePc, 2)) - ∧ decode code p9 = some (.DUP2, .none) - ∧ decode code p10 = some (.Push .PUSH2, some (validatePc, 2)) - ∧ decode code p13 = some (.JUMP, .none) - ∧ decode code afterValidatePc = some (.JUMPDEST, .none) - ∧ decode code a1 = some (.SWAP3, .none) - ∧ decode code a2 = some (.SWAP2, .none) - ∧ decode code a3 = some (.POP, .none) - ∧ decode code a4 = some (.POP, .none) - ∧ decode code a5 = some (.JUMP, .none) - -/-- Discharge concrete solc bytecode-shape predicates by splitting their opcode facts. -/ -macro "solc_wf" : tactic => - `(tactic| - (dsimp only [solcCleanupUInt256Wf, solcValidateUInt256Wf, solcDecodeUInt256Wf]; - repeat' first | apply And.intro | decide)) - -/-- -solc `abi_decode_uint256`: load one calldata word at `offset`, validate it with the uint256 -validator, and return the decoded word to the dynamic return address. --/ -theorem RD.solcDecodeUInt256 {code : ByteArray} {g : Sat256} {s0 : State} - {ee : ExecutionEnv} {k C : ℕ} - {pc validatePc afterValidatePc cleanupPc afterCleanupPc okPc offset ennd ret : UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - (h : RD code ee g s0 pc (offset :: ennd :: ret :: R) mem aw rdata acc k C) - (hwf : solcDecodeUInt256Wf code pc validatePc afterValidatePc) - (hvalidate : solcValidateUInt256Wf code validatePc cleanupPc afterCleanupPc okPc) - (hcleanup : solcCleanupUInt256Wf code cleanupPc) - (hvalidateJd : (D_J code 0).contains validatePc = true) - (hcleanupJd : (D_J code 0).contains cleanupPc = true) - (hafterCleanupJd : (D_J code 0).contains afterCleanupPc = true) - (hokJd : (D_J code 0).contains okPc = true) - (hafterValidateJd : (D_J code 0).contains afterValidatePc = true) - (hret : (D_J code 0).contains ret = true) (hov : R.length + 10 ≤ 1024) : - RD code ee g s0 ret - (uInt256OfByteArray (ee.calldata.readBytes offset.toNat 32) :: R) - mem aw rdata acc (k + 38) (C + 126) := by - rcases hwf with - ⟨hd0, hd1, hd2, hd3, hd4, hd5, hd6, hd7, hd8, hd9, hd10, hd11, hd12, hd13, hd14, hd15⟩ - have h1 := h.jumpdest hd0 (by evm_ov) - |>.push0 hd1 (by evm_ov) - |>.dup2 hd2 (by evm_ov) - |>.calldataload hd3 (by evm_ov) - |>.swap1 hd4 (by evm_ov) - |>.pop hd5 (by evm_ov) - |>.push2 afterValidatePc hd6 (by evm_ov) - |>.dup2 hd7 (by evm_ov) - |>.push2 validatePc hd8 (by evm_ov) - |>.jump hd9 hvalidateJd (by evm_ov) - have h2 := h1.solcValidateUInt256 (cleanupPc := cleanupPc) - (afterCleanupPc := afterCleanupPc) (okPc := okPc) - hvalidate hcleanup hcleanupJd hafterCleanupJd hokJd hafterValidateJd (by evm_ov) - exact h2.jumpdest hd10 (by evm_ov) - |>.swap3 hd11 (by evm_ov) - |>.swap2 hd12 (by evm_ov) - |>.pop hd13 (by evm_ov) - |>.pop hd14 (by evm_ov) - |>.jump hd15 hret (by evm_ov) - -end Reasoning.Reach diff --git a/Reasoning/SolmBody.lean b/Reasoning/SolmBody.lean index 68ccda04..31be75e3 100644 --- a/Reasoning/SolmBody.lean +++ b/Reasoning/SolmBody.lean @@ -3,11 +3,15 @@ import Reasoning.Theory /-! # SolmBody — compositional lemmas for the Solm contract body -The Solm-side analogue of the EVM trace: facts about `ExecTransitionBody` / `ExecStmt`. The piece -shared across every solc contract is the **non-payable guard** `require(callvalue == 0)` that opens -each transition body — its evaluation (both directions) and the body-revert it produces under -non-zero call value. Statement-level combinators for the success path / loops can be added here as -more contracts need them. +The Solm-side analogue of the EVM trace: facts about `ExecTransitionBody` / `ExecStmt`, all +contract-agnostic: + +- the **non-payable guard** `require(callvalue == 0)` that opens each transition body — its + evaluation (both directions) and the body-revert it produces under non-zero call value; +- internal-call unfolding, and wrappers for external / checked / low-level / delegate calls; +- Hoare-style while/for loop rules; +- the `ABlock` forward block builder; +- `Solm.Store` (locals) lookup and storage-access collapse lemmas. -/ open Solm ABI Ethereum diff --git a/Reasoning/Stepping.lean b/Reasoning/Stepping.lean index aeb0bf6a..98d6b5bb 100644 --- a/Reasoning/Stepping.lean +++ b/Reasoning/Stepping.lean @@ -1445,34 +1445,34 @@ theorem caller_xstep {s : State} {code : ByteArray} {pcv : UInt256} {rest : List /-! ### ADDRESS (cost `Gbase = 2`, pc += 1, pushes current contract address) -/ -def uniswapStAddress (s : State) : State := +def stAddress (s : State) : State := { s with machineState := { s.machineState with pc := s.machineState.pc + ⟨1⟩, stack := UInt256.ofNat s.executionEnv.codeOwner.val :: s.machineState.stack, execLength := s.machineState.execLength + 1, gasAvailable := s.machineState.gasAvailable.subNat 2 } } -theorem uniswapAddress_xstep {s : State} {code : ByteArray} {pcv : UInt256} +theorem address_xstep {s : State} {code : ByteArray} {pcv : UInt256} {rest : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) (hdec : decode code pcv = some (.ADDRESS, .none)) (hstk : s.machineState.stack = rest) (hov : rest.length + 1 ≤ 1024) : Xstep (D_J code 0) s = (if s.machineState.gasAvailable.toNat < 2 then .error .OutOfGass - else .ok (uniswapStAddress s, .none)) := by + else .ok (stAddress s, .none)) := by have hd : decode s.executionEnv.code s.machineState.pc = some (.ADDRESS, .none) := by rw [hcode, hpc]; exact hdec have hov' : ¬ (s.machineState.stack.length - 0 + 1 > 1024) := by rw [hstk]; omega rw [← hcode, step_address s hd, if_neg hov'] - simp only [GasConstants.Gbase, uniswapStAddress] + simp only [GasConstants.Gbase, stAddress] /-! ### EXTCODESIZE (dynamic `Caccess`, pc += 1) -/ -def uniswapExtCodeSizeWord (σ : AccountMap) (target : UInt256) : UInt256 := +def extCodeSizeWord (σ : AccountMap) (target : UInt256) : UInt256 := σ.find? (AccountAddress.ofUInt256 target) |>.option ⟨0⟩ (UInt256.ofNat ∘ ByteArray.size ∘ (·.code)) -def uniswapStExtcodesize (s : State) (target : UInt256) (t : List UInt256) : State := +def stExtcodesize (s : State) (target : UInt256) (t : List UInt256) : State := let addr := AccountAddress.ofUInt256 target { s with substate := @@ -1480,24 +1480,24 @@ def uniswapStExtcodesize (s : State) (target : UInt256) (t : List UInt256) : Sta machineState := { s.machineState with pc := s.machineState.pc + ⟨1⟩, - stack := uniswapExtCodeSizeWord s.accountMap target :: t, + stack := extCodeSizeWord s.accountMap target :: t, execLength := s.machineState.execLength + 1, gasAvailable := s.machineState.gasAvailable.subNat (Caccess addr s.substate) } } -theorem uniswapExtcodesize_xstep {s : State} {code : ByteArray} {pcv target : UInt256} +theorem extcodesize_xstep {s : State} {code : ByteArray} {pcv target : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) (hdec : decode code pcv = some (.EXTCODESIZE, .none)) (hstk : s.machineState.stack = target :: t) (hov : t.length + 1 ≤ 1024) : Xstep (D_J code 0) s = (if s.machineState.gasAvailable.toNat < Caccess (AccountAddress.ofUInt256 target) s.substate - then .error .OutOfGass else .ok (uniswapStExtcodesize s target t, .none)) := by + then .error .OutOfGass else .ok (stExtcodesize s target t, .none)) := by have hd : decode s.executionEnv.code s.machineState.pc = some (.EXTCODESIZE, .none) := by rw [hcode, hpc]; exact hdec rw [← hcode, step_extcodesize s hd, hstk] have hov' : ¬ ((target :: t).length - 1 + 1 > 1024) := by simp only [List.length_cons]; omega - simp only [if_neg hov', uniswapStExtcodesize, uniswapExtCodeSizeWord] + simp only [if_neg hov', stExtcodesize, extCodeSizeWord] /-! ### SWAP4–SWAP6 (cost `Gverylow = 3`, pc += 1) -/ diff --git a/Reasoning/Storage.lean b/Reasoning/Storage.lean index 95726ef3..83469bbf 100644 --- a/Reasoning/Storage.lean +++ b/Reasoning/Storage.lean @@ -7,13 +7,22 @@ import Ethereum.Theory.StaticStorage import Ethereum.Theory.StorageExtensionality /-! -# Storage — ordered-map (`Batteries.RBMap`) facts for EVM storage maps - -Generic lookup/update facts for the red-black-tree maps that back EVM storage (`Storage`) and the -account map (`AccountMap`), independent of any contract or keccak layout: a write at one slot -preserves lookup at a different slot. The `RBNode`/`RBMap` `find?_erase_ne` machinery fills the gap -left by `Batteries` (which ships `find?_insert_of_ne` but no erase analogue). The `UInt256` -`compare` instances these rely on live in `Reasoning.EVMWord`. +# Storage — EVM storage maps, Solidity storage layout, and account-map equivalences + +Contract-agnostic layers, bottom up: + +- **Ordered-map (`Batteries.RBMap`) facts** for the red-black-tree maps that back EVM storage + (`Storage`) and the account map (`AccountMap`): a write at one slot preserves lookup at a + different slot. The `RBNode`/`RBMap` `find?_erase_ne` machinery fills the gap left by + `Batteries` (which ships `find?_insert_of_ne` but no erase analogue). +- **`StorageLoc` load/store facts** for the Solidity value encodings: full-slot uint256/bytes32, + packed unsigned integers, addresses at byte offsets 0/1, packed bools. +- **The Solidity bytes/string storage layout**: writing, reading, deleting, and clearing the + length slot and the keccak-addressed data words. +- **`accountMapEquiv` / `EVMStateEquiv`**: account-map equivalence up to storage representation, + with preservation lemmas for `SLOAD`/`SSTORE` and code-size reads used by the refinement proofs. + +The `UInt256` `compare` instances these rely on live in `Reasoning.EVMWord`. -/ open Ethereum Ethereum.EVM Solm @@ -1375,10 +1384,10 @@ theorem accountMapEquiv_code_size_word {σ τ : AccountMap} simp [hσ, hτ, Option.option] at hστ ⊢ exact congrArg (fun code => EVM.Word.ofNat code.size) hστ.2.2.1 -theorem uniswapExtCodeSizeWord_accountMapEquiv {σ τ : AccountMap} +theorem extCodeSizeWord_accountMapEquiv {σ τ : AccountMap} (hστ : accountMapEquiv σ τ) (target : UInt256) : - uniswapExtCodeSizeWord σ target = uniswapExtCodeSizeWord τ target := by - simpa [uniswapExtCodeSizeWord] using + extCodeSizeWord σ target = extCodeSizeWord τ target := by + simpa [extCodeSizeWord] using accountMapEquiv_code_size_word hστ (AccountAddress.ofUInt256 target) theorem accountStorageStateEq_storage_findD {σ τ : AccountMap} From 50f81f9f0d413fbe4e50a6db576cd339d684ceaf Mon Sep 17 00:00:00 2001 From: zoep Date: Tue, 28 Jul 2026 17:20:31 +0300 Subject: [PATCH 15/38] Solm: source syntax for all contracts --- Benchmarks/Auction/SpecSyntax.lean | 245 +++ Benchmarks/CompoundIII/Comet/SpecSyntax.lean | 413 ++++- .../CompoundIII/CometRewards/Claim.lean | 4 +- .../CompoundIII/CometRewards/Common.lean | 4 +- .../CompoundIII/CometRewards/Constructor.lean | 2 +- .../CometRewards/GetRewardOwed.lean | 34 +- .../CometRewards/SetRewardConfig.lean | 6 +- .../SetRewardConfigWithMultiplier.lean | 6 +- .../CompoundIII/CometRewards/SpecSyntax.lean | 203 ++- Benchmarks/Dss/Cat/BiteBody.lean | 28 +- Benchmarks/Dss/Cat/BiteBodyAw.lean | 16 +- Benchmarks/Dss/Cat/BiteBodyKick.lean | 10 +- Benchmarks/Dss/Cat/BiteBodyMem.lean | 2 +- Benchmarks/Dss/Cat/BiteBodyReach.lean | 8 +- Benchmarks/Dss/Cat/BiteCallDiverge.lean | 22 +- Benchmarks/Dss/Cat/BiteCallFess.lean | 12 +- Benchmarks/Dss/Cat/BiteCallGrab.lean | 16 +- Benchmarks/Dss/Cat/BiteCallKick.lean | 12 +- Benchmarks/Dss/Cat/BiteCallUrns.lean | 22 +- Benchmarks/Dss/Cat/BiteConnect.lean | 10 +- Benchmarks/Dss/Cat/BiteRevertBranch.lean | 240 +-- Benchmarks/Dss/Cat/BiteSuccessBranch.lean | 2 +- Benchmarks/Dss/Cat/BiteTrace.lean | 28 +- Benchmarks/Dss/Cat/BiteWalk.lean | 38 +- Benchmarks/Dss/Cat/Claw.lean | 2 +- Benchmarks/Dss/Cat/Common.lean | 26 +- Benchmarks/Dss/Cat/FileIlkFlip.lean | 48 +- Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean | 24 +- Benchmarks/Dss/Cat/SpecSyntax.lean | 201 ++- Benchmarks/Dss/Clipper/Fallback.lean | 6 +- Benchmarks/Dss/Clipper/SpecSyntax.lean | 437 ++++- Benchmarks/Dss/Cure/Common.lean | 8 +- Benchmarks/Dss/Cure/Constructor.lean | 2 +- Benchmarks/Dss/Cure/Load.lean | 12 +- Benchmarks/Dss/Cure/LoadBase.lean | 12 +- Benchmarks/Dss/Cure/LoadSource.lean | 14 +- Benchmarks/Dss/Cure/LoadTrace.lean | 22 +- Benchmarks/Dss/Cure/SpecSyntax.lean | 168 +- Benchmarks/Dss/Cure/Srcs.lean | 1 - Benchmarks/Dss/Dai/Burn.lean | 4 +- Benchmarks/Dss/Dai/Constructor.lean | 2 +- Benchmarks/Dss/Dai/Correct.lean | 8 +- Benchmarks/Dss/Dai/Mint.lean | 2 +- Benchmarks/Dss/Dai/Permit.lean | 8 +- Benchmarks/Dss/Dai/SpecSyntax.lean | 267 +-- Benchmarks/Dss/Dai/TransferFrom.lean | 4 +- Benchmarks/Dss/DaiJoin/Calls.lean | 44 +- Benchmarks/Dss/DaiJoin/Dispatch.lean | 8 +- Benchmarks/Dss/DaiJoin/Exit.lean | 28 +- Benchmarks/Dss/DaiJoin/ExitRuntime.lean | 52 +- Benchmarks/Dss/DaiJoin/Join.lean | 60 +- Benchmarks/Dss/DaiJoin/JoinTrace.lean | 26 +- Benchmarks/Dss/DaiJoin/Mul.lean | 2 +- Benchmarks/Dss/DaiJoin/SpecSyntax.lean | 79 +- Benchmarks/Dss/Dog/Bark.lean | 176 +- Benchmarks/Dss/Dog/Dispatch.lean | 8 +- Benchmarks/Dss/Dog/FileIlkClip.lean | 48 +- Benchmarks/Dss/Dog/SpecSyntax.lean | 243 ++- Benchmarks/Dss/End/Cage.lean | 148 +- Benchmarks/Dss/End/CageIlk.lean | 204 +-- Benchmarks/Dss/End/Cash.lean | 54 +- Benchmarks/Dss/End/Common.lean | 8 +- Benchmarks/Dss/End/Dispatch.lean | 8 +- Benchmarks/Dss/End/Flow.lean | 46 +- Benchmarks/Dss/End/Free.lean | 72 +- Benchmarks/Dss/End/Pack.lean | 50 +- Benchmarks/Dss/End/PackBody.lean | 18 +- Benchmarks/Dss/End/Skim.lean | 108 +- Benchmarks/Dss/End/Skip.lean | 274 +-- Benchmarks/Dss/End/Snip.lean | 220 +-- Benchmarks/Dss/End/SpecSyntax.lean | 365 +++- Benchmarks/Dss/End/Thaw.lean | 134 +- .../Dss/ExponentialDecrease/Dispatch.lean | 6 +- Benchmarks/Dss/ExponentialDecrease/Price.lean | 4 +- .../Dss/ExponentialDecrease/RpowEVM.lean | 8 +- .../Dss/ExponentialDecrease/SpecSyntax.lean | 93 +- Benchmarks/Dss/Flapper/Cage.lean | 64 +- Benchmarks/Dss/Flapper/Deal.lean | 94 +- Benchmarks/Dss/Flapper/Dispatch.lean | 8 +- Benchmarks/Dss/Flapper/Kick.lean | 36 +- Benchmarks/Dss/Flapper/SpecSyntax.lean | 223 ++- Benchmarks/Dss/Flapper/Tend.lean | 80 +- Benchmarks/Dss/Flapper/Tick.lean | 2 +- Benchmarks/Dss/Flapper/Yank.lean | 60 +- Benchmarks/Dss/Flipper/CheckedMul.lean | 2 +- Benchmarks/Dss/Flipper/Constructor.lean | 2 +- Benchmarks/Dss/Flipper/Deal.lean | 32 +- Benchmarks/Dss/Flipper/DealEVM.lean | 34 +- Benchmarks/Dss/Flipper/DentRefundEVM.lean | 28 +- Benchmarks/Dss/Flipper/DentRefundMain.lean | 20 +- Benchmarks/Dss/Flipper/DentSameCaller.lean | 6 +- Benchmarks/Dss/Flipper/DentTail.lean | 20 +- Benchmarks/Dss/Flipper/Dispatch.lean | 8 +- Benchmarks/Dss/Flipper/ExternalTargets.lean | 54 +- Benchmarks/Dss/Flipper/Kick.lean | 2 +- Benchmarks/Dss/Flipper/KickBody.lean | 6 +- Benchmarks/Dss/Flipper/KickTail.lean | 18 +- Benchmarks/Dss/Flipper/SpecSyntax.lean | 227 ++- Benchmarks/Dss/Flipper/TendRefund.lean | 48 +- Benchmarks/Dss/Flipper/TendSameCaller.lean | 6 +- Benchmarks/Dss/Flipper/TendSourceTail.lean | 2 +- Benchmarks/Dss/Flipper/TendTail.lean | 16 +- Benchmarks/Dss/Flipper/Tick.lean | 2 +- Benchmarks/Dss/Flipper/Yank.lean | 22 +- Benchmarks/Dss/Flipper/YankBody.lean | 26 +- Benchmarks/Dss/Flipper/YankCalls.lean | 24 +- Benchmarks/Dss/Flopper/AuctionCommon.lean | 26 +- Benchmarks/Dss/Flopper/Deal.lean | 14 +- Benchmarks/Dss/Flopper/DealRuntime.lean | 34 +- Benchmarks/Dss/Flopper/Dent/Part1.lean | 6 +- Benchmarks/Dss/Flopper/Dent/Part10.lean | 16 +- Benchmarks/Dss/Flopper/Dent/Part3.lean | 40 +- Benchmarks/Dss/Flopper/Dent/Part4.lean | 16 +- Benchmarks/Dss/Flopper/Dent/Part5.lean | 16 +- Benchmarks/Dss/Flopper/Dent/Part6.lean | 32 +- Benchmarks/Dss/Flopper/Dent/Part7.lean | 46 +- Benchmarks/Dss/Flopper/Dent/Part8.lean | 44 +- Benchmarks/Dss/Flopper/Dent/Part9.lean | 10 +- Benchmarks/Dss/Flopper/Dispatch.lean | 8 +- Benchmarks/Dss/Flopper/Kick/Part2.lean | 2 +- Benchmarks/Dss/Flopper/SpecSyntax.lean | 215 ++- Benchmarks/Dss/Flopper/Tick/Part2.lean | 2 +- Benchmarks/Dss/Flopper/Yank/Part1.lean | 18 +- Benchmarks/Dss/Flopper/Yank/Part2.lean | 28 +- Benchmarks/Dss/GemJoin/Constructor.lean | 18 +- .../Dss/GemJoin/ConstructorTraceCall.lean | 22 +- Benchmarks/Dss/GemJoin/Dispatch.lean | 8 +- Benchmarks/Dss/GemJoin/Exit.lean | 170 +- Benchmarks/Dss/GemJoin/Join.lean | 202 +-- Benchmarks/Dss/GemJoin/SpecSyntax.lean | 89 +- Benchmarks/Dss/Jug/Dispatch.lean | 8 +- Benchmarks/Dss/Jug/Drip.lean | 2 +- Benchmarks/Dss/Jug/DripBase.lean | 26 +- .../Dss/Jug/DripBodyAddReturnsTactic.lean | 4 +- Benchmarks/Dss/Jug/DripBodyAgeOneTactic.lean | 18 +- Benchmarks/Dss/Jug/DripBodyCore.lean | 20 +- Benchmarks/Dss/Jug/DripBodyFeeZeroTactic.lean | 18 +- Benchmarks/Dss/Jug/DripBodyGenericTactic.lean | 10 +- Benchmarks/Dss/Jug/DripBodyNZeroTactic.lean | 24 +- Benchmarks/Dss/Jug/DripEVMFold.lean | 12 +- Benchmarks/Dss/Jug/DripEVMRpow.lean | 10 +- Benchmarks/Dss/Jug/DripEVMVat.lean | 16 +- Benchmarks/Dss/Jug/Rpow.lean | 8 +- Benchmarks/Dss/Jug/SpecSyntax.lean | 250 ++- Benchmarks/Dss/LinearDecrease/Dispatch.lean | 6 +- Benchmarks/Dss/LinearDecrease/Price.lean | 4 +- Benchmarks/Dss/LinearDecrease/SpecSyntax.lean | 80 +- Benchmarks/Dss/Pot/Dispatch.lean | 8 +- Benchmarks/Dss/Pot/Drip.lean | 38 +- Benchmarks/Dss/Pot/DripEVMArith.lean | 4 +- Benchmarks/Dss/Pot/Exit.lean | 18 +- Benchmarks/Dss/Pot/Join.lean | 44 +- Benchmarks/Dss/Pot/Rpow.lean | 8 +- Benchmarks/Dss/Pot/SpecSyntax.lean | 295 ++-- Benchmarks/Dss/Spot/Dispatch.lean | 8 +- Benchmarks/Dss/Spot/Poke.lean | 18 +- Benchmarks/Dss/Spot/PokeCalls.lean | 46 +- Benchmarks/Dss/Spot/PokeTraceBody.lean | 28 +- Benchmarks/Dss/Spot/SpecSyntax.lean | 217 ++- .../Dispatch.lean | 8 +- .../StairstepExponentialDecrease/Price.lean | 4 +- .../StairstepExponentialDecrease/RpowEVM.lean | 8 +- .../SpecSyntax.lean | 104 +- Benchmarks/Dss/Vat/Common.lean | 8 +- Benchmarks/Dss/Vat/Dispatch.lean | 8 +- Benchmarks/Dss/Vat/Slip.lean | 4 +- Benchmarks/Dss/Vat/SpecSyntax.lean | 486 ++++-- Benchmarks/Dss/Vow/Cage.lean | 46 +- Benchmarks/Dss/Vow/CageBody.lean | 50 +- Benchmarks/Dss/Vow/CageBodyRuntime.lean | 104 +- Benchmarks/Dss/Vow/CageBodyRuntimeTail.lean | 26 +- Benchmarks/Dss/Vow/CageHealRuntime.lean | 4 +- Benchmarks/Dss/Vow/CageRuntime.lean | 14 +- Benchmarks/Dss/Vow/CageTailRuntime.lean | 4 +- Benchmarks/Dss/Vow/Common.lean | 8 +- Benchmarks/Dss/Vow/Constructor.lean | 10 +- Benchmarks/Dss/Vow/ConstructorTail.lean | 22 +- Benchmarks/Dss/Vow/FileAddress.lean | 10 +- Benchmarks/Dss/Vow/FileAddressFlapper.lean | 60 +- .../Dss/Vow/FileAddressFlapperBody.lean | 72 +- Benchmarks/Dss/Vow/Flap.lean | 30 +- Benchmarks/Dss/Vow/FlapBody.lean | 8 +- Benchmarks/Dss/Vow/FlapDai.lean | 18 +- Benchmarks/Dss/Vow/FlapDaiBody.lean | 2 +- Benchmarks/Dss/Vow/FlapKick.lean | 14 +- Benchmarks/Dss/Vow/FlapKickBody.lean | 2 +- Benchmarks/Dss/Vow/FlapRuntime.lean | 52 +- Benchmarks/Dss/Vow/FlapSin1.lean | 18 +- Benchmarks/Dss/Vow/FlapSin1Body.lean | 2 +- Benchmarks/Dss/Vow/Flop.lean | 32 +- Benchmarks/Dss/Vow/FlopAsh.lean | 16 +- Benchmarks/Dss/Vow/FlopBody.lean | 66 +- Benchmarks/Dss/Vow/FlopDai.lean | 10 +- Benchmarks/Dss/Vow/FlopKick.lean | 2 +- Benchmarks/Dss/Vow/Heal.lean | 50 +- Benchmarks/Dss/Vow/HealBody.lean | 50 +- Benchmarks/Dss/Vow/HealFinal.lean | 2 +- Benchmarks/Dss/Vow/HealSuccess.lean | 12 +- Benchmarks/Dss/Vow/Kiss.lean | 28 +- Benchmarks/Dss/Vow/KissSuccess.lean | 66 +- Benchmarks/Dss/Vow/SpecSyntax.lean | 355 ++-- Benchmarks/EAS/Attester/DynamicArray.lean | 12 +- Benchmarks/EAS/Attester/MultiRevoke.lean | 6 +- .../EAS/Attester/MultiRevokePostCall.lean | 48 +- Benchmarks/EAS/Attester/Revoke.lean | 54 +- Benchmarks/ERC721/SpecSyntax.lean | 73 + Benchmarks/Klima/SpecSyntax.lean | 350 ++++ .../TimelockController/UpdateDelay.lean | 4 +- Benchmarks/Safe/SpecSyntax.lean | 592 ++++++- Benchmarks/UniswapV2Router02/SpecSyntax.lean | 539 +++++- Benchmarks/UniswapV3Pool/Common.lean | 8 +- Benchmarks/UniswapV3Pool/NoDelegateCall.lean | 8 +- Benchmarks/UniswapV3Pool/Observations.lean | 2 +- .../UniswapV3Pool/ObservationsInt56.lean | 2 +- Benchmarks/UniswapV3Pool/SetFeeProtocol.lean | 12 +- .../SetFeeProtocolFeeProtocolCheck.lean | 2 +- .../SetFeeProtocolOwnerCall.lean | 24 +- .../UniswapV3Pool/SetFeeProtocolSource.lean | 8 +- Benchmarks/UniswapV3Pool/SpecSyntax.lean | 1513 ++++++++++++++++- Benchmarks/UniswapV3Pool/TickBitmap.lean | 2 +- Benchmarks/UniswapV3Pool/TickSpacing.lean | 2 +- Benchmarks/UniswapV3Pool/TicksInt128.lean | 2 +- Benchmarks/WETH9/Allowance.lean | 2 +- Benchmarks/WETH9/Approve.lean | 2 +- Benchmarks/WETH9/BalanceOf.lean | 2 +- Benchmarks/WETH9/Routines.lean | 2 +- Benchmarks/WETH9/SpecSyntax.lean | 227 +-- Benchmarks/WETH9/Transfer.lean | 2 +- Benchmarks/WETH9/TransferFrom.lean | 2 +- Benchmarks/WETH9/TransferFromBody.lean | 4 +- Benchmarks/WETH9/WithdrawBody.lean | 4 +- EquiVM.lean | 1 - Examples/Ballot/SpecSyntax.lean | 114 ++ Examples/BlindAuction/SpecSyntax.lean | 135 ++ Examples/Caller/SpecSyntax.lean | 32 + Examples/CtorStore/SpecSyntax.lean | 25 + Examples/CtorTruth/SpecSyntax.lean | 25 + Examples/ERC20/SpecSugar.lean | 112 +- .../AccessControl/SpecSyntax.lean | 73 + .../OpenZeppelinBench/ERC6909/SpecSyntax.lean | 87 + .../OpenZeppelinBench/ERC6909/Transfer.lean | 1 - .../ERC6909/TransferFrom/Decode.lean | 1 - .../Ownable2Step/SpecSyntax.lean | 55 + .../Pausable/SpecSyntax.lean | 52 + Examples/Pow/SpecSyntax.lean | 33 + Examples/Reuse/SpecSyntax.lean | 36 + Examples/SimpleAuction/SpecSyntax.lean | 79 + Examples/StringStoreLite/Getters.lean | 2 +- Examples/StringStoreLite/SetOldLong.lean | 10 +- Examples/StringStoreLite/SpecSyntax.lean | 44 + Examples/TinyImmutable/SpecSyntax.lean | 44 + Examples/Truth/SpecSyntax.lean | 25 + Examples/UniswapV2Pair/Common.lean | 6 +- Examples/UniswapV2Pair/Dispatch.lean | 8 +- Examples/UniswapV2Pair/Mint.lean | 6 +- Examples/UniswapV2Pair/MintCommon.lean | 54 +- .../UniswapV2Pair/MintFeeRuntimeFactory.lean | 16 +- .../UniswapV2Pair/MintRuntimeBalance.lean | 48 +- Examples/UniswapV2Pair/Permit.lean | 12 +- Examples/UniswapV2Pair/PermitRuntime.lean | 6 +- Examples/UniswapV2Pair/Skim.lean | 68 +- .../SkimDynamicSecondRuntime.lean | 20 +- Examples/UniswapV2Pair/SkimRuntime.lean | 34 +- .../UniswapV2Pair/SkimSafeTransferReturn.lean | 2 +- Examples/UniswapV2Pair/SkimSecondRuntime.lean | 20 +- ...afeTransferDynamicOffsetReturnRuntime.lean | 2 +- Examples/UniswapV2Pair/SpecSyntax.lean | 403 +++++ Examples/UniswapV2Pair/Sync.lean | 16 +- Examples/UniswapV2Pair/SyncBody.lean | 52 +- Examples/UniswapV2Pair/SyncRuntime.lean | 90 +- Examples/VyperERC20/SpecSyntax.lean | 72 + README.md | 47 +- Solm/Notation.lean | 1388 ++++++++++++--- 273 files changed, 13191 insertions(+), 4327 deletions(-) create mode 100644 Benchmarks/Auction/SpecSyntax.lean create mode 100644 Benchmarks/ERC721/SpecSyntax.lean create mode 100644 Benchmarks/Klima/SpecSyntax.lean create mode 100644 Examples/Ballot/SpecSyntax.lean create mode 100644 Examples/BlindAuction/SpecSyntax.lean create mode 100644 Examples/Caller/SpecSyntax.lean create mode 100644 Examples/CtorStore/SpecSyntax.lean create mode 100644 Examples/CtorTruth/SpecSyntax.lean create mode 100644 Examples/OpenZeppelinBench/AccessControl/SpecSyntax.lean create mode 100644 Examples/OpenZeppelinBench/ERC6909/SpecSyntax.lean create mode 100644 Examples/OpenZeppelinBench/Ownable2Step/SpecSyntax.lean create mode 100644 Examples/OpenZeppelinBench/Pausable/SpecSyntax.lean create mode 100644 Examples/Pow/SpecSyntax.lean create mode 100644 Examples/Reuse/SpecSyntax.lean create mode 100644 Examples/SimpleAuction/SpecSyntax.lean create mode 100644 Examples/StringStoreLite/SpecSyntax.lean create mode 100644 Examples/TinyImmutable/SpecSyntax.lean create mode 100644 Examples/Truth/SpecSyntax.lean create mode 100644 Examples/UniswapV2Pair/SpecSyntax.lean create mode 100644 Examples/VyperERC20/SpecSyntax.lean diff --git a/Benchmarks/Auction/SpecSyntax.lean b/Benchmarks/Auction/SpecSyntax.lean new file mode 100644 index 00000000..cd32f5ba --- /dev/null +++ b/Benchmarks/Auction/SpecSyntax.lean @@ -0,0 +1,245 @@ +import Benchmarks.Auction.Spec +import Solm.Notation + +/-! +# NounsAuctionHouse spec in the Solidity-faithful Solm frontend + +The whole Nouns auction-house spec written with `solidity%` and proven definitionally equal to +the AST spec in `Spec.lean`. + +Notes mirroring the AST spec: +* The flattened OpenZeppelin base storage (initializer flags, gaps, `_paused`, `_status`, + `_owner`) is declared inline; the modifiers are the inlined `require`/assign prefixes. +* `_createAuction` carries the project's only `try/catch` (`nouns.mint()`); the `Error(string)` + selector comparison splices the spec's `errorStringSelector` bytes literal. +* `_safeTransferETHWithFallback` is the raw low-level value send plus the WETH deposit/transfer + fallback; `«to»` escapes the Lean keyword. +* Transition order matches `auctionContract.transitions`. +-/ + +open Solm Solm.Notation + +namespace Auction.Syntax + +def contractSyntax : ContractDecl := solidity% contract NounsAuctionHouse { + struct Auction { + uint256 nounId; + uint256 amount; + uint256 startTime; + uint256 endTime; + address bidder; + bool settled; + } + + bool _initialized; + bool _initializing; + uint256[50] __contextGap; + bool _paused; + uint256[49] __pausableGap; + uint256 _status; + uint256[49] __reentrancyGuardGap; + address _owner; + uint256[49] __ownableGap; + address nouns; + address weth; + uint256 timeBuffer; + uint256 reservePrice; + uint8 minBidIncrementPercentage; + uint256 duration; + Auction auction; + + constructor() { } + + function _safeTransferETHWithFallback(address «to», uint256 amount) internal { + (bool success, bytes memory _data) = «to».call{value: amount}(new bytes(0)); + if (!success) { + require(weth.code.length > 0); + var _dep = weth.deposit{value: amount}(); + var _xfer = weth.transfer(«to», amount); + } + } + + function _settleAuction() internal { + var _auction = auction; + require(_auction.startTime != 0); + require(!_auction.settled); + require(block.timestamp >= _auction.endTime); + auction.settled = true; + if (_auction.bidder == address(0)) { + require(nouns.code.length > 0); + var _burn = nouns.burn(_auction.nounId); + } else { + require(nouns.code.length > 0); + var _tf = nouns.transferFrom(address(this), _auction.bidder, _auction.nounId); + } + if (_auction.amount > 0) { + var _pay = _safeTransferETHWithFallback(_owner, _auction.amount); + } + } + + function _createAuction() internal { + try nouns.mint() returns (nounId) { + uint256 startTime = block.timestamp; + uint256 endTime = (startTime + duration) as uint256; + auction.nounId = nounId; + auction.amount = 0; + auction.startTime = startTime; + auction.endTime = endTime; + auction.bidder = address(0); + auction.settled = false; + } catch (err) { + if (err[0 : 4] == ${Expr.bytesLit errorStringSelector}) { + string _errString = abi.decode(err[4 : err.length], (string)); + require(!_paused); + _paused = true; + } else { + require(false); + } + } + } + + function «initialize»(address _nouns, address _weth, uint256 _timeBuffer, + uint256 _reservePrice, uint8 _minBidIncrementPercentage, uint256 _duration) external { + require(_initializing || !_initialized); + bool isTopLevelCall = !_initializing; + if (isTopLevelCall) { + _initializing = true; + _initialized = true; + } + _paused = false; + _status = 1; + _owner = msg.sender; + require(!_paused); + _paused = true; + nouns = _nouns; + weth = _weth; + timeBuffer = _timeBuffer; + reservePrice = _reservePrice; + minBidIncrementPercentage = _minBidIncrementPercentage; + duration = _duration; + if (isTopLevelCall) { + _initializing = false; + } + } + + function createBid(uint256 nounId) external payable { + require(_status != 2); + _status = 2; + var _auction = auction; + require(_auction.nounId == nounId); + require(block.timestamp < _auction.endTime); + require(msg.value >= reservePrice); + require(msg.value >= + ((_auction.amount + ((_auction.amount * minBidIncrementPercentage) as uint256) / 100) as uint256)); + address lastBidder = _auction.bidder; + if (lastBidder != address(0)) { + var _refund = _safeTransferETHWithFallback(lastBidder, _auction.amount); + } + auction.amount = msg.value; + auction.bidder = msg.sender; + bool extended = _auction.endTime - block.timestamp < timeBuffer; + if (extended) { + auction.endTime = (block.timestamp + timeBuffer) as uint256; + } + _status = 1; + } + + function settleCurrentAndCreateNewAuction() external { + require(_status != 2); + _status = 2; + require(!_paused); + var _s = _settleAuction(); + var _c = _createAuction(); + _status = 1; + } + + function settleAuction() external { + require(_paused); + require(_status != 2); + _status = 2; + var _s = _settleAuction(); + _status = 1; + } + + function pause() external { + require(msg.sender == _owner); + require(!_paused); + _paused = true; + } + + function unpause() external { + require(msg.sender == _owner); + require(_paused); + _paused = false; + if (auction.startTime == 0 || auction.settled) { + var _c = _createAuction(); + } + } + + function setTimeBuffer(uint256 _timeBuffer) external { + require(msg.sender == _owner); + timeBuffer = _timeBuffer; + } + + function setReservePrice(uint256 _reservePrice) external { + require(msg.sender == _owner); + reservePrice = _reservePrice; + } + + function setMinBidIncrementPercentage(uint8 _minBidIncrementPercentage) external { + require(msg.sender == _owner); + minBidIncrementPercentage = _minBidIncrementPercentage; + } + + function transferOwnership(address newOwner) external { + require(msg.sender == _owner); + require(newOwner != address(0)); + _owner = newOwner; + } + + function renounceOwnership() external { + require(msg.sender == _owner); + _owner = address(0); + } + + function owner() external returns (address) { + return _owner; + } + + function paused() external returns (bool) { + return _paused; + } + + function nouns() external returns (address) { + return nouns; + } + + function weth() external returns (address) { + return weth; + } + + function timeBuffer() external returns (uint256) { + return timeBuffer; + } + + function reservePrice() external returns (uint256) { + return reservePrice; + } + + function minBidIncrementPercentage() external returns (uint8) { + return minBidIncrementPercentage; + } + + function duration() external returns (uint256) { + return duration; + } + + function auction() external returns (uint256, uint256, uint256, uint256, address, bool) { + return (auction.nounId, auction.amount, auction.startTime, + auction.endTime, auction.bidder, auction.settled); + } +} + +theorem contractSyntax_eq : contractSyntax = Auction.auctionContract := by rfl + +end Auction.Syntax diff --git a/Benchmarks/CompoundIII/Comet/SpecSyntax.lean b/Benchmarks/CompoundIII/Comet/SpecSyntax.lean index 8c28cabe..8be10c08 100644 --- a/Benchmarks/CompoundIII/Comet/SpecSyntax.lean +++ b/Benchmarks/CompoundIII/Comet/SpecSyntax.lean @@ -2,42 +2,405 @@ import Benchmarks.CompoundIII.Comet.Spec import Solm.Notation /-! -# Compound III CometWithExtendedAssetList spec through the Solm syntax-facing module +# Comet spec in the Solidity-faithful Solm frontend -This benchmark is large enough that the current notation frontend does not cover the full surface. -The file still mirrors the established benchmark convention by exposing a syntax-side contract value -and checking it is definitionally equal to the AST spec. +The whole `CometWithExtendedAssetList` benchmark spec, written with `solidity%` and proven +definitionally equal to the AST spec in `Benchmarks/CompoundIII/Comet/Spec.lean`. + +Notes mirroring the AST spec: +* The 25 immutable reads splice the spec's `Immutables` exprs (`${Immutables.governor v}`, …); + Int constants (`maxUint40`, `baseIndexScale`, `factorScale`, `10 ^ 15`) splice via `#`. +* Principal/present-value math and the interest-rate kink formulas are written out in surface + form (`(…) as uint256` for the spec's `u256`/`u104`/`u64`/`u40`/`u8` range wraps). +* `getAssetInfo`/`getAssetInfoByAddress` return the `AssetInfo` struct as the surface ABI + tuple type `((uint8, address, address, uint64, uint64, uint64, uint64, uint128))`; the + results are built with `tuple(…)`. +* The constructor's `config` param is the surface ABI tuple type (with a nested tuple-array + postfix `(…)[]`), mirroring the spec's `ConstructorDecl` param exactly. +* The fallback delegatecalls the extension delegate (an `Expr`-valued immutable receiver, so the + statement is spliced); it carries no callvalue guard in the spec, hence `payable`, and it + declares its `bytes` return type with the surface `returns (bytes)` clause. +* Lean-keyword param names are guillemet-escaped («from», «to»). +* Transition order matches `contract.transitions` (selector order); no internal functions. -/ -open Solm Solm.Notation Benchmarks.CompoundIII.Comet.Immutables +open Solm Solm.Notation +open Benchmarks.CompoundIII.Comet.Immutables (CometImmutables) namespace Benchmarks.CompoundIII.Comet.Syntax -def storageDeclsSyntax : List StorageDecl := Benchmarks.CompoundIII.Comet.storageDecls +def contractSyntax (v : CometImmutables) : ContractDecl := + solidity% contract CometWithExtendedAssetList { + struct LiquidatorPoints { + uint32 numAbsorbs; + uint64 numAbsorbed; + uint128 approxSpend; + uint32 _reserved; + } -def constructorDeclSyntax : ConstructorDecl := Benchmarks.CompoundIII.Comet.constructorDecl + struct TotalsCollateral { + uint128 totalSupplyAsset; + uint128 _reserved; + } -def transitionsSyntax (v : CometImmutables) : List TransitionDecl := - Benchmarks.CompoundIII.Comet.transitions v + struct UserBasic { + int104 principal; + uint64 baseTrackingIndex; + uint64 baseTrackingAccrued; + uint16 assetsIn; + uint8 _reserved; + } -def fallbackTransitionSyntax (v : CometImmutables) : TransitionDecl := - Benchmarks.CompoundIII.Comet.fallbackTransition v + struct UserCollateral { + uint128 balance; + uint128 _reserved; + } -def contractSyntax (v : CometImmutables) : ContractDecl := - { name := "CometWithExtendedAssetList" - storage := storageDeclsSyntax - ctor := constructorDeclSyntax - structs := Benchmarks.CompoundIII.Comet.structs - functions := [] - transitions := transitionsSyntax v - fallback := some (fallbackTransitionSyntax v) } - -theorem storageDeclsSyntax_eq : - storageDeclsSyntax = Benchmarks.CompoundIII.Comet.storageDecls := by - rfl + uint64 baseSupplyIndex; + uint64 baseBorrowIndex; + uint64 trackingSupplyIndex; + uint64 trackingBorrowIndex; + uint104 totalSupplyBase; + uint104 totalBorrowBase; + uint40 lastAccrualTime; + uint8 pauseFlags; + mapping(address => TotalsCollateral) totalsCollateral; + mapping(address => mapping(address => bool)) isAllowed; + mapping(address => uint256) userNonce; + mapping(address => UserBasic) userBasic; + mapping(address => mapping(address => UserCollateral)) userCollateral; + mapping(address => LiquidatorPoints) liquidatorPoints; + + constructor((address, address, address, address, address, + uint64, uint64, uint64, uint64, uint64, uint64, uint64, uint64, uint64, uint64, uint64, + uint64, uint104, uint104, uint104, + (address, address, uint8, uint64, uint64, uint64, uint128)[]) config) { + var imm_governor = config.0; + var imm_pauseGuardian = config.1; + var imm_baseToken = config.2; + var imm_baseTokenPriceFeed = config.3; + var imm_extensionDelegate = config.4; + var imm_storeFrontPriceFactor = config.13; + var imm_trackingIndexScale = config.14; + var imm_baseMinForRewards = config.17; + var imm_baseTrackingSupplySpeed = config.15; + var imm_baseTrackingBorrowSpeed = config.16; + var imm_baseBorrowMin = config.18; + var imm_targetReserves = config.19; + var imm_supplyKink = config.5; + var imm_borrowKink = config.9; + var imm_supplyPerSecondInterestRateSlopeLow = config.6 / 31536000; + var imm_supplyPerSecondInterestRateSlopeHigh = config.7 / 31536000; + var imm_supplyPerSecondInterestRateBase = config.8 / 31536000; + var imm_borrowPerSecondInterestRateSlopeLow = config.10 / 31536000; + var imm_borrowPerSecondInterestRateSlopeHigh = config.11 / 31536000; + var imm_borrowPerSecondInterestRateBase = config.12 / 31536000; + var imm_decimals = imm_baseToken.decimals{view}(); + var imm_baseScale = 10 ** imm_decimals; + var imm_accrualDescaleFactor = imm_baseScale / #(10 ^ 15); + var imm_numAssets = 0; + var imm_assetList = imm_extensionDelegate.createAssetList(); + } + + fallback(bytes calldata) external payable returns (bytes) { + ${[Stmt.delegateCall (Immutables.extensionDelegate v) (.var "calldata") "ok" "returndata"]} + require(${Expr.var "ok"}); + return ${Expr.var "returndata"}; + } + + function absorb(address absorber, address[] accounts) external { } + + function accrueAccount(address account) external { } + + function approveThis(address manager, address asset, uint256 amount) external { } + + function assetList() external returns (address) { + return ${Immutables.assetList v}; + } + + function balanceOf(address account) external returns (uint256) { + int104 principal = userBasic[account].principal; + return principal > 0 ? + (((principal * baseSupplyIndex) as uint256) / #baseIndexScale) as uint256 : 0; + } + + function baseBorrowMin() external returns (uint256) { + return ${Immutables.baseBorrowMin v}; + } + + function baseMinForRewards() external returns (uint256) { + return ${Immutables.baseMinForRewards v}; + } + + function baseScale() external returns (uint256) { + return ${Immutables.baseScale v}; + } + + function baseToken() external returns (address) { + return ${Immutables.baseToken v}; + } + + function baseTokenPriceFeed() external returns (address) { + return ${Immutables.baseTokenPriceFeed v}; + } + + function baseTrackingBorrowSpeed() external returns (uint256) { + return ${Immutables.baseTrackingBorrowSpeed v}; + } + + function baseTrackingSupplySpeed() external returns (uint256) { + return ${Immutables.baseTrackingSupplySpeed v}; + } + + function borrowBalanceOf(address account) external returns (uint256) { + int104 principal = userBasic[account].principal; + return principal < 0 ? + (((((-principal) as uint104) * baseBorrowIndex) as uint256) / #baseIndexScale) as uint256 : + 0; + } + + function borrowKink() external returns (uint256) { + return ${Immutables.borrowKink v}; + } + + function borrowPerSecondInterestRateBase() external returns (uint256) { + return ${Immutables.borrowPerSecondInterestRateBase v}; + } + + function borrowPerSecondInterestRateSlopeHigh() external returns (uint256) { + return ${Immutables.borrowPerSecondInterestRateSlopeHigh v}; + } + + function borrowPerSecondInterestRateSlopeLow() external returns (uint256) { + return ${Immutables.borrowPerSecondInterestRateSlopeLow v}; + } + + function buyCollateral(address asset, uint256 minAmount, uint256 baseAmount, + address recipient) external { } + + function decimals() external returns (uint8) { + return ${Immutables.decimals v}; + } + + function extensionDelegate() external returns (address) { + return ${Immutables.extensionDelegate v}; + } + + function getAssetInfo(uint8 i) external + returns ((uint8, address, address, uint64, uint64, uint64, uint64, uint128)) { + return tuple(0, address(0), address(0), 0, 0, 0, 0, 0); + } + + function getAssetInfoByAddress(address asset) external + returns ((uint8, address, address, uint64, uint64, uint64, uint64, uint128)) { + return tuple(0, address(0), address(0), 0, 0, 0, 0, 0); + } + + function getBorrowRate(uint256 utilization) external returns (uint64) { + return (utilization <= ${Immutables.borrowKink v} ? + (${Immutables.borrowPerSecondInterestRateBase v} + + (((${Immutables.borrowPerSecondInterestRateSlopeLow v} * utilization) as uint256) / + #factorScale)) as uint256 : + (((${Immutables.borrowPerSecondInterestRateBase v} + + (((${Immutables.borrowPerSecondInterestRateSlopeLow v} * + ${Immutables.borrowKink v}) as uint256) / #factorScale)) as uint256) + + (((${Immutables.borrowPerSecondInterestRateSlopeHigh v} * + ((utilization - ${Immutables.borrowKink v}) as uint256)) as uint256) / + #factorScale)) as uint256) as uint64; + } + + function getCollateralReserves(address asset) external returns (uint256) { + return 0; + } + + function getPrice(address priceFeed) external returns (uint256) { + return 0; + } + + function getReserves() external returns (int256) { + return 0; + } + + function getSupplyRate(uint256 utilization) external returns (uint64) { + return (utilization <= ${Immutables.supplyKink v} ? + (${Immutables.supplyPerSecondInterestRateBase v} + + (((${Immutables.supplyPerSecondInterestRateSlopeLow v} * utilization) as uint256) / + #factorScale)) as uint256 : + (((${Immutables.supplyPerSecondInterestRateBase v} + + (((${Immutables.supplyPerSecondInterestRateSlopeLow v} * + ${Immutables.supplyKink v}) as uint256) / #factorScale)) as uint256) + + (((${Immutables.supplyPerSecondInterestRateSlopeHigh v} * + ((utilization - ${Immutables.supplyKink v}) as uint256)) as uint256) / + #factorScale)) as uint256) as uint64; + } + + function getUtilization() external returns (uint256) { + uint256 totalSupply_ = + (((totalSupplyBase * baseSupplyIndex) as uint256) / #baseIndexScale) as uint256; + uint256 totalBorrow_ = + (((totalBorrowBase * baseBorrowIndex) as uint256) / #baseIndexScale) as uint256; + return totalSupply_ == 0 ? 0 : + ((totalBorrow_ * #factorScale) as uint256) / totalSupply_; + } + + function governor() external returns (address) { + return ${Immutables.governor v}; + } + + function hasPermission(address owner, address manager) external returns (bool) { + return owner == manager || isAllowed[owner][manager]; + } + + function initializeStorage() external { + require(lastAccrualTime == 0); + require(block.timestamp <= #maxUint40); + lastAccrualTime = (block.timestamp) as uint40; + baseSupplyIndex = #baseIndexScale; + baseBorrowIndex = #baseIndexScale; + } + + function isAbsorbPaused() external returns (bool) { + return (pauseFlags & (1 << 3)) != 0; + } + + function isAllowed(address arg0, address arg1) external returns (bool) { + return isAllowed[arg0][arg1]; + } + + function isBorrowCollateralized(address account) external returns (bool) { + return false; + } + + function isBuyPaused() external returns (bool) { + return (pauseFlags & (1 << 4)) != 0; + } + + function isLiquidatable(address account) external returns (bool) { + return false; + } + + function isSupplyPaused() external returns (bool) { + return (pauseFlags & (1 << 0)) != 0; + } + + function isTransferPaused() external returns (bool) { + return (pauseFlags & (1 << 1)) != 0; + } + + function isWithdrawPaused() external returns (bool) { + return (pauseFlags & (1 << 2)) != 0; + } + + function liquidatorPoints(address arg0) external returns (uint32, uint64, uint128, uint32) { + return (liquidatorPoints[arg0].numAbsorbs, liquidatorPoints[arg0].numAbsorbed, + liquidatorPoints[arg0].approxSpend, liquidatorPoints[arg0]._reserved); + } + + function numAssets() external returns (uint8) { + return ${Immutables.numAssets v}; + } + + function pause(bool supplyPaused, bool transferPaused, bool withdrawPaused, + bool absorbPaused, bool buyPaused) external { + require(msg.sender == ${Immutables.governor v} || + msg.sender == ${Immutables.pauseGuardian v}); + pauseFlags = (((supplyPaused ? 1 : 0) << 0) | + (((transferPaused ? 1 : 0) << 1) | + (((withdrawPaused ? 1 : 0) << 2) | + (((absorbPaused ? 1 : 0) << 3) | + ((buyPaused ? 1 : 0) << 4))))) as uint8; + } + + function pauseGuardian() external returns (address) { + return ${Immutables.pauseGuardian v}; + } + + function quoteCollateral(address asset, uint256 baseAmount) external returns (uint256) { + return 0; + } + + function storeFrontPriceFactor() external returns (uint256) { + return ${Immutables.storeFrontPriceFactor v}; + } + + function supply(address asset, uint256 amount) external { } + + function supplyFrom(address «from», address dst, address asset, uint256 amount) external { } + + function supplyKink() external returns (uint256) { + return ${Immutables.supplyKink v}; + } + + function supplyPerSecondInterestRateBase() external returns (uint256) { + return ${Immutables.supplyPerSecondInterestRateBase v}; + } + + function supplyPerSecondInterestRateSlopeHigh() external returns (uint256) { + return ${Immutables.supplyPerSecondInterestRateSlopeHigh v}; + } + + function supplyPerSecondInterestRateSlopeLow() external returns (uint256) { + return ${Immutables.supplyPerSecondInterestRateSlopeLow v}; + } + + function supplyTo(address dst, address asset, uint256 amount) external { } + + function targetReserves() external returns (uint256) { + return ${Immutables.targetReserves v}; + } + + function totalBorrow() external returns (uint256) { + return (((totalBorrowBase * baseBorrowIndex) as uint256) / #baseIndexScale) as uint256; + } + + function totalSupply() external returns (uint256) { + return (((totalSupplyBase * baseSupplyIndex) as uint256) / #baseIndexScale) as uint256; + } + + function totalsCollateral(address arg0) external returns (uint128, uint128) { + return (totalsCollateral[arg0].totalSupplyAsset, totalsCollateral[arg0]._reserved); + } + + function trackingIndexScale() external returns (uint256) { + return ${Immutables.trackingIndexScale v}; + } + + function transfer(address dst, uint256 amount) external returns (bool) { + return false; + } + + function transferAsset(address dst, address asset, uint256 amount) external { } + + function transferAssetFrom(address src, address dst, address asset, + uint256 amount) external { } + + function transferFrom(address src, address dst, uint256 amount) external returns (bool) { + return false; + } + + function userBasic(address arg0) external returns (int104, uint64, uint64, uint16, uint8) { + return (userBasic[arg0].principal, userBasic[arg0].baseTrackingIndex, + userBasic[arg0].baseTrackingAccrued, userBasic[arg0].assetsIn, userBasic[arg0]._reserved); + } + + function userCollateral(address arg0, address arg1) external returns (uint128, uint128) { + return (userCollateral[arg0][arg1].balance, userCollateral[arg0][arg1]._reserved); + } + + function userNonce(address arg0) external returns (uint256) { + return userNonce[arg0]; + } + + function withdraw(address asset, uint256 amount) external { } + + function withdrawFrom(address src, address «to», address asset, uint256 amount) external { } + + function withdrawReserves(address «to», uint256 amount) external { } + + function withdrawTo(address «to», address asset, uint256 amount) external { } + } theorem contractSyntax_eq (v : CometImmutables) : - contractSyntax v = Benchmarks.CompoundIII.Comet.contract v := by - rfl + contractSyntax v = Benchmarks.CompoundIII.Comet.contract v := by rfl end Benchmarks.CompoundIII.Comet.Syntax diff --git a/Benchmarks/CompoundIII/CometRewards/Claim.lean b/Benchmarks/CompoundIII/CometRewards/Claim.lean index 03fc0051..11496f0a 100644 --- a/Benchmarks/CompoundIII/CometRewards/Claim.lean +++ b/Benchmarks/CompoundIII/CometRewards/Claim.lean @@ -3143,7 +3143,7 @@ theorem cometRewardsClaimInternalX_noAccrue_call_baseTracking_made native_decide obtain ⟨cA', σ'_evm, z, baseOut, A_in, callGas, k', C', hΘ, rd3724, _houtSize⟩ := - RD.uniswapStaticcall (t := + RD.solcStaticcall (t := claimBaseTrackingPostCallTail I (getRewardOwedClaimedWord σ_evm I)) rd3723Call hdecCall hdepth (by simp [claimBaseTrackingPostCallTail]) @@ -3343,7 +3343,7 @@ theorem cometRewardsClaimInternalX_noAccrue_callDepthLimit (initState cA gh bl σ σ₀ g A I).executionEnv.depth = 1024 := by simpa [initState] using hdepth obtain ⟨k', C', rdPost₀⟩ := - RD.uniswapStaticcallDepthLimit + RD.solcStaticcallDepthLimit (t := claimBaseTrackingPostCallTail I (getRewardOwedClaimedWord σ I)) rd3723Call hdecCall hdepthInit (by simp [claimBaseTrackingPostCallTail]) have rdPost : diff --git a/Benchmarks/CompoundIII/CometRewards/Common.lean b/Benchmarks/CompoundIII/CometRewards/Common.lean index 61461845..364a616c 100644 --- a/Benchmarks/CompoundIII/CometRewards/Common.lean +++ b/Benchmarks/CompoundIII/CometRewards/Common.lean @@ -640,7 +640,7 @@ theorem cometRewardsX_short {cA gh bl σ σ₀ A I} {g : Sat256} (by decide) (by evm_ov), push1 ⟨4⟩, swap2, dup3, calldatasize, lt, iszero, push2 ⟨22⟩, jumpiNT (isZero_eq_zero_of_ne (lt_four_ne_zero_of_lt hsz))] - exact (rd.uniswapPush1Dup1Revert0 (by decide) (by decide) (by decide) (by evm_ov) : + exact (rd.solcPush1Dup1Revert0 (by decide) (by decide) (by decide) (by evm_ov) : RDrev cometRewardsBytecode g s0) theorem cometRewardsX_nomatch {cA gh bl σ σ₀ A I} {g : Sat256} @@ -772,7 +772,7 @@ theorem cometRewardsX_nomatch {cA gh bl σ σ₀ A I} {g : Sat256} push4 ⟨0xcdc0ca09⟩, eq] rw [heq10] at rd have rd := evm_run rd with [push2 ⟨159⟩, jumpiNT (by decide)] - exact (rd.uniswapPush1Dup1Revert0 (by decide) (by decide) (by decide) (by evm_ov) : + exact (rd.solcPush1Dup1Revert0 (by decide) (by decide) (by decide) (by evm_ov) : RDrev cometRewardsBytecode g s0) theorem cometRewardsReachFirstArm {cA gh bl σ σ₀ A I} {g : Sat256} diff --git a/Benchmarks/CompoundIII/CometRewards/Constructor.lean b/Benchmarks/CompoundIII/CometRewards/Constructor.lean index 2dbad7f7..efb2740a 100644 --- a/Benchmarks/CompoundIII/CometRewards/Constructor.lean +++ b/Benchmarks/CompoundIII/CometRewards/Constructor.lean @@ -417,7 +417,7 @@ theorem cometRewardsInitcodeNonpayableRevert push1 ⟨128⟩, callvalue, push2 ⟨116⟩, jumpiT hwv (by comet_rewards_ctor_jd), jumpdest] - exact rd116.uniswapPush1Dup1Revert0 + exact rd116.solcPush1Dup1Revert0 (by comet_rewards_ctor_decode) (by comet_rewards_ctor_decode) (by comet_rewards_ctor_decode) (by simp) diff --git a/Benchmarks/CompoundIII/CometRewards/GetRewardOwed.lean b/Benchmarks/CompoundIII/CometRewards/GetRewardOwed.lean index 4ba66090..4ba4a965 100644 --- a/Benchmarks/CompoundIII/CometRewards/GetRewardOwed.lean +++ b/Benchmarks/CompoundIII/CometRewards/GetRewardOwed.lean @@ -4246,7 +4246,7 @@ theorem evalExpr_getRewardOwed_extCodeSizeGuard_false (evm : EVM.State) (I : ExecutionEnv) (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (UInt256.land (getRewardOwedCometWord I) solcAddrMask) = ⟨0⟩) : evalExpr? config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm (.binary .gt (.extCodeSize (.var "comet")) (.intLit 0)) = .ok (.bool false) := by @@ -4270,7 +4270,7 @@ theorem evalExpr_getRewardOwed_extCodeSizeGuard_false cases hacc : evm.accountMap.find? (AccountAddress.ofUInt256 (UInt256.land (getRewardOwedCometWord I) solcAddrMask)) · decide - · simpa [Reasoning.Theory.uniswapExtCodeSizeWord, Function.comp, Option.option, + · simpa [Reasoning.Theory.extCodeSizeWord, Function.comp, Option.option, EVM.Word.ofNat, hacc] using hzero rw [hword] decide @@ -4280,7 +4280,7 @@ theorem evalExpr_getRewardOwed_extCodeSizeGuard_true (evm : EVM.State) (I : ExecutionEnv) (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) (hnz : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (UInt256.land (getRewardOwedCometWord I) solcAddrMask) ≠ ⟨0⟩) : evalExpr? config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm (.binary .gt (.extCodeSize (.var "comet")) (.intLit 0)) = .ok (.bool true) := by @@ -4303,9 +4303,9 @@ theorem evalExpr_getRewardOwed_extCodeSizeGuard_true have hwordNZ : codeWord ≠ ⟨0⟩ := by cases hacc : evm.accountMap.find? (AccountAddress.ofUInt256 (UInt256.land (getRewardOwedCometWord I) solcAddrMask)) - · simpa [codeWord, Reasoning.Theory.uniswapExtCodeSizeWord, Function.comp, + · simpa [codeWord, Reasoning.Theory.extCodeSizeWord, Function.comp, Option.option, EVM.Word.ofNat, hacc] using hnz - · simpa [codeWord, Reasoning.Theory.uniswapExtCodeSizeWord, Function.comp, + · simpa [codeWord, Reasoning.Theory.extCodeSizeWord, Function.comp, Option.option, EVM.Word.ofNat, hacc] using hnz have hpos : 0 < codeWord.toNat := by by_contra hnot @@ -4867,7 +4867,7 @@ theorem cometRewardsGetRewardOwedX_accrueNoCode {cA gh bl σ σ₀ A I} {g : Sat (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) (hnz : rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) ≠ ⟨0⟩) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (UInt256.land (getRewardOwedCometWord I) solcAddrMask) = ⟨0⟩) (hreach : ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) getRewardOwedPc @@ -4887,7 +4887,7 @@ theorem cometRewardsGetRewardOwedX_accrueNoCode {cA gh bl σ σ₀ A I} {g : Sat push2 ⟨2592⟩, jumpiNT (by decide)] have rd2415 := evm_run rd2414 with [dup5] obtain ⟨_, _, rd2416⟩ := - Reasoning.Reach.RD.uniswapExtcodesize rd2415 (by native_decide) + Reasoning.Reach.RD.extcodesize rd2415 (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) rw [hnoCode] at rd2416 have rd2420 := evm_run rd2416 with [iszero, push2 ⟨797⟩] @@ -4903,7 +4903,7 @@ theorem cometRewardsGetRewardOwedX_call_accrueAccount {cA gh bl σ σ₀ A I} {g (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) (hnz : rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (UInt256.land (getRewardOwedCometWord I) solcAddrMask) ≠ ⟨0⟩) (hreach : ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) getRewardOwedPc @@ -4946,7 +4946,7 @@ theorem cometRewardsGetRewardOwedX_call_accrueAccount {cA gh bl σ σ₀ A I} {g push2 ⟨2592⟩, jumpiNT (by decide)] have rd2415 := evm_run rd2414 with [dup5] obtain ⟨_, _, rd2416⟩ := - Reasoning.Reach.RD.uniswapExtcodesize rd2415 (by native_decide) + Reasoning.Reach.RD.extcodesize rd2415 (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) have rd2417 := evm_run rd2416 with [iszero] rw [isZero_eq_zero_of_ne hcodeSize] at rd2417 @@ -5010,7 +5010,7 @@ theorem cometRewardsGetRewardOwedX_call_accrueAccount_made (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) (hnz : rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ_evm I) ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (UInt256.land (getRewardOwedCometWord I) solcAddrMask) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) @@ -5402,7 +5402,7 @@ theorem cometRewardsGetRewardOwedX_call_baseTrackingAccrued_made native_decide obtain ⟨cA'', σ''_evm, z, baseOut, A_in, callGas, k', C', hΘ, rd3724, _houtSize⟩ := - RD.uniswapStaticcall (t := + RD.solcStaticcall (t := getRewardOwedBaseTrackingPostCallTail (getRewardOwedClaimedWord σ'_evm I)) rd3723Call hdecCall hdepth (by simp [getRewardOwedBaseTrackingPostCallTail]) @@ -6568,7 +6568,7 @@ theorem cometRewardsGetRewardOwedX_callDepthLimit {cA gh bl σ σ₀ A I} {g : U (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) (hnz : rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (UInt256.land (getRewardOwedCometWord I) solcAddrMask) ≠ ⟨0⟩) (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) getRewardOwedPc @@ -7200,7 +7200,7 @@ theorem cometRewardsGetRewardOwedBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g · let evmSolm : EVM.State := initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I by_cases hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (UInt256.land (getRewardOwedCometWord I) solcAddrMask) = ⟨0⟩ · have htokenNZSolm : rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evmSolm I) ≠ ⟨0⟩ := by @@ -7212,9 +7212,9 @@ theorem cometRewardsGetRewardOwedBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g rw [hload, ← hslotWord] exact htokenZero have hnoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (UInt256.land (getRewardOwedCometWord I) solcAddrMask) = ⟨0⟩ := by - rw [← uniswapExtCodeSizeWord_accountMapEquiv hAccounts + rw [← extCodeSizeWord_accountMapEquiv hAccounts (UInt256.land (getRewardOwedCometWord I) solcAddrMask)] exact hnoCode have hguard : @@ -7244,10 +7244,10 @@ theorem cometRewardsGetRewardOwedBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g rw [hload, ← hslotWord] exact htokenZero have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (UInt256.land (getRewardOwedCometWord I) solcAddrMask) ≠ ⟨0⟩ := by intro hz - exact hnoCode ((uniswapExtCodeSizeWord_accountMapEquiv hAccounts + exact hnoCode ((extCodeSizeWord_accountMapEquiv hAccounts (UInt256.land (getRewardOwedCometWord I) solcAddrMask)).trans hz) have hguard : evalExpr? config diff --git a/Benchmarks/CompoundIII/CometRewards/SetRewardConfig.lean b/Benchmarks/CompoundIII/CometRewards/SetRewardConfig.lean index ede290d2..6da4d74a 100644 --- a/Benchmarks/CompoundIII/CometRewards/SetRewardConfig.lean +++ b/Benchmarks/CompoundIII/CometRewards/SetRewardConfig.lean @@ -3140,7 +3140,7 @@ theorem cometRewardsSetRewardConfigX_call_baseAccrualScale_made decode cometRewardsBytecode (⟨1115⟩ : UInt256) = some (.STATICCALL, .none) := by native_decide obtain ⟨cA', σ'_evm, z, out, A_in, callGas, k', C', hΘ, rd1116, _houtSize⟩ := - RD.uniswapStaticcall (t := setRewardConfigWrapperBasePostCallTail I) rd1115Call hdecCall + RD.solcStaticcall (t := setRewardConfigWrapperBasePostCallTail I) rd1115Call hdecCall hdepth (by simp [setRewardConfigWrapperBasePostCallTail]) obtain ⟨g'', A'_evm, hΘeq⟩ := hΘ have houtSmall : out.size < 2 ^ 138 := by @@ -3540,7 +3540,7 @@ theorem cometRewardsSetRewardConfigX_baseAccrualScale_callDepthLimit (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).executionEnv.depth = 1024 := by simpa [initState] using hdepth obtain ⟨k', C', rdPost₀⟩ := - RD.uniswapStaticcallDepthLimit (t := setRewardConfigWrapperBasePostCallTail I) + RD.solcStaticcallDepthLimit (t := setRewardConfigWrapperBasePostCallTail I) rd1115Call hdecCall hdepthInit (by simp [setRewardConfigWrapperBasePostCallTail]) have rdPost : RD cometRewardsBytecode I (Sat256.ofUInt256 g) @@ -4113,7 +4113,7 @@ theorem cometRewardsSetRewardConfigX_call_decimals_made decode cometRewardsBytecode (⟨1153⟩ : UInt256) = some (.STATICCALL, .none) := by native_decide obtain ⟨cA'', σ''_evm, z, out, A_in, callGas, k', C', hΘ, rd1154, _houtSize⟩ := - RD.uniswapStaticcall (t := setRewardConfigWrapperDecimalsPostCallTail baseWord I) + RD.solcStaticcall (t := setRewardConfigWrapperDecimalsPostCallTail baseWord I) rd1153Call hdecCall hdepth (by simp [setRewardConfigWrapperDecimalsPostCallTail]) obtain ⟨g'', A''_evm, hΘeq⟩ := hΘ let evmEBase : EVM.State := diff --git a/Benchmarks/CompoundIII/CometRewards/SetRewardConfigWithMultiplier.lean b/Benchmarks/CompoundIII/CometRewards/SetRewardConfigWithMultiplier.lean index f1ab5561..36724e15 100644 --- a/Benchmarks/CompoundIII/CometRewards/SetRewardConfigWithMultiplier.lean +++ b/Benchmarks/CompoundIII/CometRewards/SetRewardConfigWithMultiplier.lean @@ -5670,7 +5670,7 @@ theorem cometRewardsSetRewardConfigWithMultiplierX_call_baseAccrualScale_made decode cometRewardsBytecode (⟨241⟩ : UInt256) = some (.STATICCALL, .none) := by native_decide obtain ⟨cA', σ'_evm, z, out, A_in, callGas, k', C', hΘ, rd242, _houtSize⟩ := - RD.uniswapStaticcall (t := setRewardConfigBasePostCallTail I) rd241Call hdecCall + RD.solcStaticcall (t := setRewardConfigBasePostCallTail I) rd241Call hdecCall hdepth (by simp [setRewardConfigBasePostCallTail]) obtain ⟨g'', A'_evm, hΘeq⟩ := hΘ have houtSmall : out.size < 2 ^ 138 := by @@ -6433,7 +6433,7 @@ theorem cometRewardsSetRewardConfigWithMultiplierX_call_decimals_made decode cometRewardsBytecode (⟨279⟩ : UInt256) = some (.STATICCALL, .none) := by native_decide obtain ⟨cA'', σ''_evm, z, out, A_in, callGas, k', C', hΘ, rd280, _houtSize⟩ := - RD.uniswapStaticcall (t := setRewardConfigDecimalsPostCallTail baseWord I) + RD.solcStaticcall (t := setRewardConfigDecimalsPostCallTail baseWord I) rd279Call hdecCall hdepth (by simp [setRewardConfigDecimalsPostCallTail]) obtain ⟨g'', A''_evm, hΘeq⟩ := hΘ let evmEBase : EVM.State := @@ -8567,7 +8567,7 @@ theorem cometRewardsSetRewardConfigWithMultiplierX_baseAccrualScale_callDepthLim (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).executionEnv.depth = 1024 := by simpa [initState] using hdepth obtain ⟨k', C', rdPost₀⟩ := - RD.uniswapStaticcallDepthLimit (t := setRewardConfigBasePostCallTail I) + RD.solcStaticcallDepthLimit (t := setRewardConfigBasePostCallTail I) rd241Call hdecCall hdepthInit (by simp [setRewardConfigBasePostCallTail]) have rdPost : RD cometRewardsBytecode I (Sat256.ofUInt256 g) diff --git a/Benchmarks/CompoundIII/CometRewards/SpecSyntax.lean b/Benchmarks/CompoundIII/CometRewards/SpecSyntax.lean index ffeee0f8..49530d6a 100644 --- a/Benchmarks/CompoundIII/CometRewards/SpecSyntax.lean +++ b/Benchmarks/CompoundIII/CometRewards/SpecSyntax.lean @@ -2,38 +2,201 @@ import Benchmarks.CompoundIII.CometRewards.Spec import Solm.Notation /-! -# Compound III CometRewards spec through the Solm syntax-facing module +# CometRewards spec in the Solidity-faithful Solm frontend -This benchmark is large enough that the current notation frontend does not cover the full surface. -The file still mirrors the established benchmark convention by exposing a syntax-side contract value -and checking it is definitionally equal to the AST spec. +The whole CometRewards benchmark spec, written with `solidity%` and proven definitionally equal +to the AST spec in `Benchmarks/CompoundIII/CometRewards/Spec.lean`. + +Notes mirroring the AST spec: +* Every external entry point opens with the spec's calldata-size guard + (`bytes __calldata = msg.data; require(__calldata.length < …)`), after the auto-inserted + callvalue guard. +* Int constants (`maxUint64`, `factorScale`, `calldataSizeLimit`) splice via `#`. +* View externals (`baseTrackingAccrued`, `baseAccrualScale`, `decimals`, `hasPermission`) + are marked `{view}` (perm := false); `accrueAccount`/`transfer` are permanent. +* `getRewardOwed` returns the `RewardOwed` struct as the surface ABI tuple type + `((address, uint256))`; the tuple result is built with `tuple(token, owed)`. +* Transition and internal-function order match `contract.transitions`/`contract.functions`. -/ open Solm Solm.Notation namespace Benchmarks.CompoundIII.CometRewards.Syntax -def storageDeclsSyntax : List StorageDecl := Benchmarks.CompoundIII.CometRewards.storageDecls +def contractSyntax : ContractDecl := solidity% contract CometRewards { + struct RewardConfig { + address token; + uint64 rescaleFactor; + bool shouldUpscale; + uint256 multiplier; + } + + address governor; + mapping(address => RewardConfig) rewardConfig; + mapping(address => mapping(address => uint256)) rewardsClaimed; + + constructor(address governor_) { + governor = governor_; + } + + function safe64(uint256 n) internal returns (uint64) { + require(n <= #maxUint64); + return n as uint64; + } + + function pow10(uint8 n) internal returns (uint256) { + require(n <= 77); + return (10 ** n) as uint256; + } + + function getRewardAccrued(address comet, address account, uint64 rescaleFactor, + bool shouldUpscale, uint256 multiplier) internal returns (uint256) { + var accrued = comet.baseTrackingAccrued{view}(account); + if (shouldUpscale) { + accrued = (accrued * rescaleFactor) as uint256; + } else { + accrued = accrued / rescaleFactor; + } + uint256 scaled = (accrued * multiplier) as uint256; + return scaled / #factorScale; + } + + function doTransferOut(address token, address «to», uint256 amount) internal { + var success = token.transfer(«to», amount); + require(success); + } + + function setRewardConfigWithMultiplierBody(address comet, address token, + uint256 multiplier) internal { + require(msg.sender == governor); + require(rewardConfig[comet].token == address(0)); + var accrualScale = comet.baseAccrualScale{view}(); + var tokenDecimals = token.decimals{view}(); + var tokenScale256 = pow10(tokenDecimals); + var tokenScale = safe64(tokenScale256); + if (accrualScale > tokenScale) { + rewardConfig[comet].token = token; + rewardConfig[comet].rescaleFactor = accrualScale / tokenScale; + rewardConfig[comet].shouldUpscale = false; + rewardConfig[comet].multiplier = multiplier; + } else { + rewardConfig[comet].token = token; + rewardConfig[comet].rescaleFactor = tokenScale / accrualScale; + rewardConfig[comet].shouldUpscale = true; + rewardConfig[comet].multiplier = multiplier; + } + } + + function claimInternal(address comet, address src, address «to», bool shouldAccrue) internal { + address token = rewardConfig[comet].token; + uint64 rescaleFactor = rewardConfig[comet].rescaleFactor; + bool shouldUpscale = rewardConfig[comet].shouldUpscale; + uint256 multiplier = rewardConfig[comet].multiplier; + require(token != address(0)); + if (shouldAccrue) { + require(comet.code.length > 0); + var _accrued = comet.accrueAccount(src); + } + uint256 claimed = rewardsClaimed[comet][src]; + var accrued = getRewardAccrued(comet, src, rescaleFactor, shouldUpscale, multiplier); + if (accrued > claimed) { + uint256 owed = accrued - claimed; + rewardsClaimed[comet][src] = accrued; + var _sent = doTransferOut(token, «to», owed); + } + } + + function claim(address comet, address src, bool shouldAccrue) external { + bytes __calldata = msg.data; + require(__calldata.length < #calldataSizeLimit); + var _claim = claimInternal(comet, src, src, shouldAccrue); + } + + function claimTo(address comet, address src, address «to», bool shouldAccrue) external { + bytes __calldata = msg.data; + require(__calldata.length < #calldataSizeLimit); + var permitted = comet.hasPermission{view}(src, msg.sender); + require(permitted); + var _claim = claimInternal(comet, src, «to», shouldAccrue); + } + + function getRewardOwed(address comet, address account) external + returns ((address, uint256)) { + bytes __calldata = msg.data; + require(__calldata.length < #calldataSizeLimit); + address token = rewardConfig[comet].token; + uint64 rescaleFactor = rewardConfig[comet].rescaleFactor; + bool shouldUpscale = rewardConfig[comet].shouldUpscale; + uint256 multiplier = rewardConfig[comet].multiplier; + require(token != address(0)); + require(comet.code.length > 0); + var _accrued = comet.accrueAccount(account); + uint256 claimed = rewardsClaimed[comet][account]; + var accrued = getRewardAccrued(comet, account, rescaleFactor, shouldUpscale, multiplier); + uint256 owed = accrued > claimed ? accrued - claimed : 0; + return tuple(token, owed); + } + + function governor() external returns (address) { + bytes __calldata = msg.data; + require(__calldata.length < #calldataSizeLimit); + return governor; + } + + function rewardConfig(address arg0) external returns (address, uint64, bool, uint256) { + bytes __calldata = msg.data; + require(__calldata.length < #calldataSizeLimit); + return (rewardConfig[arg0].token, rewardConfig[arg0].rescaleFactor, + rewardConfig[arg0].shouldUpscale, rewardConfig[arg0].multiplier); + } + + function rewardsClaimed(address arg0, address arg1) external returns (uint256) { + bytes __calldata = msg.data; + require(__calldata.length < #calldataSizeLimit); + return rewardsClaimed[arg0][arg1]; + } -def constructorDeclSyntax : ConstructorDecl := Benchmarks.CompoundIII.CometRewards.constructorDecl + function setRewardConfig(address comet, address token) external { + bytes __calldata = msg.data; + require(__calldata.length < #calldataSizeLimit); + var _set = setRewardConfigWithMultiplierBody(comet, token, #factorScale); + } -def transitionsSyntax : List TransitionDecl := Benchmarks.CompoundIII.CometRewards.transitions + function setRewardConfigWithMultiplier(address comet, address token, uint256 multiplier) external { + bytes __calldata = msg.data; + require(__calldata.length < #calldataSizeLimit); + var _set = setRewardConfigWithMultiplierBody(comet, token, multiplier); + } -def functionsSyntax : List FunctionDecl := Benchmarks.CompoundIII.CometRewards.functions + function setRewardsClaimed(address comet, address[] calldata users, + uint256[] calldata claimedAmounts) external { + bytes __calldata = msg.data; + require(__calldata.length < #calldataSizeLimit); + require(msg.sender == governor); + require(users.length == claimedAmounts.length); + uint256 i = 0; + while (i < users.length) { + rewardsClaimed[comet][users[i]] = claimedAmounts[i]; + i = i + 1; + } + } -def contractSyntax : ContractDecl := - { name := "CometRewards" - storage := storageDeclsSyntax - ctor := constructorDeclSyntax - structs := Benchmarks.CompoundIII.CometRewards.structs - functions := functionsSyntax - transitions := transitionsSyntax } + function transferGovernor(address newGovernor) external { + bytes __calldata = msg.data; + require(__calldata.length < #calldataSizeLimit); + require(msg.sender == governor); + governor = newGovernor; + } -theorem storageDeclsSyntax_eq : - storageDeclsSyntax = Benchmarks.CompoundIII.CometRewards.storageDecls := by - rfl + function withdrawToken(address token, address «to», uint256 amount) external { + bytes __calldata = msg.data; + require(__calldata.length < #calldataSizeLimit); + require(msg.sender == governor); + var _sent = doTransferOut(token, «to», amount); + } +} -theorem contractSyntax_eq : contractSyntax = Benchmarks.CompoundIII.CometRewards.contract := by - rfl +theorem contractSyntax_eq : + contractSyntax = Benchmarks.CompoundIII.CometRewards.contract := by rfl end Benchmarks.CompoundIII.CometRewards.Syntax diff --git a/Benchmarks/Dss/Cat/BiteBody.lean b/Benchmarks/Dss/Cat/BiteBody.lean index b23655ae..1edb9771 100644 --- a/Benchmarks/Dss/Cat/BiteBody.lean +++ b/Benchmarks/Dss/Cat/BiteBody.lean @@ -47,7 +47,7 @@ business leaves, `catBiteSuccessBranch`) is green. -/ to the Solm-side `vat` account having empty code (the `hvatCode0 = 0` shape the source reverts want). -/ theorem catBiteVatCodeZero_of_uniswap {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (hAccounts : accountMapEquiv σ_evm σ_solm) - (hvatCode : Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) : + (hvatCode : Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (biteVatAddr (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I))).option 0 @@ -55,13 +55,13 @@ theorem catBiteVatCodeZero_of_uniswap {cA gh bl σ_evm σ_solm σ₀ A I} {g : U have htgt : catBiteVatTargetWord σ_evm I = catBiteVatTargetWord σ_solm I := by simp only [catBiteVatTargetWord, catAddressReturnWord, catSlotWord, solcSlotWord] rw [accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨3⟩ ⟨0⟩] - have hSolm : Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (catBiteVatTargetWord σ_solm I) = ⟨0⟩ := by - rw [← htgt, ← uniswapExtCodeSizeWord_accountMapEquiv hAccounts]; exact hvatCode + have hSolm : Reasoning.Theory.extCodeSizeWord σ_solm (catBiteVatTargetWord σ_solm I) = ⟨0⟩ := by + rw [← htgt, ← extCodeSizeWord_accountMapEquiv hAccounts]; exact hvatCode have haddr : biteVatAddr (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) = AccountAddress.ofUInt256 (catBiteVatTargetWord σ_solm I) := by rw [accountAddress_ofUInt256_eq_ofNat_toNat] simp only [biteVatAddr, initState, catBiteVatTargetWord, catAddressReturnWord, catSlotWord] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hSolm + unfold Reasoning.Theory.extCodeSizeWord at hSolm rw [haddr] simp only [initState, State.lookupAccount] cases hacc : σ_solm.find? (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_solm I)) with @@ -73,7 +73,7 @@ theorem catBiteVatCodeZero_of_uniswap {cA gh bl σ_evm σ_solm σ₀ A I} {g : U `0 < hvatCode0` shape the ilks fail / decode / success bodies want). -/ theorem catBiteVatCodePos_of_uniswap {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (hAccounts : accountMapEquiv σ_evm σ_solm) - (hvatCode : Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) ≠ ⟨0⟩) : + (hvatCode : Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (biteVatAddr (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I))).option 0 @@ -81,13 +81,13 @@ theorem catBiteVatCodePos_of_uniswap {cA gh bl σ_evm σ_solm σ₀ A I} {g : UI have htgt : catBiteVatTargetWord σ_evm I = catBiteVatTargetWord σ_solm I := by simp only [catBiteVatTargetWord, catAddressReturnWord, catSlotWord, solcSlotWord] rw [accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨3⟩ ⟨0⟩] - have hSolm : Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (catBiteVatTargetWord σ_solm I) ≠ ⟨0⟩ := by - rw [← htgt, ← uniswapExtCodeSizeWord_accountMapEquiv hAccounts]; exact hvatCode + have hSolm : Reasoning.Theory.extCodeSizeWord σ_solm (catBiteVatTargetWord σ_solm I) ≠ ⟨0⟩ := by + rw [← htgt, ← extCodeSizeWord_accountMapEquiv hAccounts]; exact hvatCode have haddr : biteVatAddr (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) = AccountAddress.ofUInt256 (catBiteVatTargetWord σ_solm I) := by rw [accountAddress_ofUInt256_eq_ofNat_toNat] simp only [biteVatAddr, initState, catBiteVatTargetWord, catAddressReturnWord, catSlotWord] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hSolm + unfold Reasoning.Theory.extCodeSizeWord at hSolm rw [haddr] simp only [initState, State.lookupAccount] cases hacc : σ_solm.find? (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_solm I)) with @@ -110,7 +110,7 @@ theorem catBiteBodyIlksNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} decodeCalldataWithMode config.abiDecodeMode (biteTransition.params.map Param.name) (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by obtain ⟨k, C, rd1163⟩ := catReachBiteRoutine (g := Sat256.ofUInt256 g) hcode hwv hsz68 hsize hsel @@ -149,7 +149,7 @@ theorem catBiteBodyIlksFailCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 decodeCalldataWithMode config.abiDecodeMode (biteTransition.params.map Param.name) (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) - (hvatCode : Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) ≠ ⟨0⟩) + (hvatCode : Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) ≠ ⟨0⟩) (hIlksFailCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] (false, evmIlk, oi) false) @@ -195,7 +195,7 @@ theorem catBiteReachGrabAw {cA gh bl σ σ₀ A I} {g : UInt256} (hpsz : p.toNat + 256 < UInt256.size) (hthisCanon : (UInt256.ofNat I.codeOwner.val).toNat < EVM.addressModulus) (hdink : dink.toNat ≤ 2 ^ 255) (hdart : dart.toNat ≤ 2 ^ 255) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ' + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ' (UInt256.land (solcSlotWord σ' I ⟨3⟩) biteAddrMaskWord) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) @@ -237,7 +237,7 @@ theorem catBiteReachGrabAw {cA gh bl σ σ₀ A I} {g : UInt256} have hencode := catBiteGrabEncode_eq p (biteIlkWord I) urn (UInt256.ofNat I.codeOwner.val) (solcSlotWord σ' I ⟨4⟩) dink dart hp96 hpmem (by omega) hthisCanon hdink hdart obtain ⟨gasWord, _, _, rd2192⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2177⟩) (okPc := ⟨2189⟩) rd2177 hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨2177⟩) (okPc := ⟨2189⟩) rd2177 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp) @@ -297,7 +297,7 @@ theorem catBiteReachFessAw {cA gh bl σ σ₀ A I} {g : UInt256} (hp96 : 96 ≤ p2.toNat) (hpmem : p2.toNat ≤ mem.size) (hawcov : p2.toNat ≤ aw.toNat * 32) (hawsz : aw.toNat * 32 < UInt256.size) (hpsz : p2.toNat + 96 < UInt256.size) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ' + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ' (UInt256.land biteAddrMaskWord (solcSlotWord σ' I ⟨4⟩)) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) @@ -332,7 +332,7 @@ theorem catBiteReachFessAw {cA gh bl σ σ₀ A I} {g : UInt256} obtain ⟨_, _, rd2284⟩ := catBiteTraceFessBuildAw rd2242 hFree64 hp96 hpmem hawcov hawsz hpsz (by simp) have hencode := catBiteFessEncode_eq p2 dartRate hpmem (by omega) obtain ⟨gasWord, _, _, rd2299⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2284⟩) (okPc := ⟨2296⟩) rd2284 hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨2284⟩) (okPc := ⟨2296⟩) rd2284 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp) diff --git a/Benchmarks/Dss/Cat/BiteBodyAw.lean b/Benchmarks/Dss/Cat/BiteBodyAw.lean index 673f167f..2b95ed09 100644 --- a/Benchmarks/Dss/Cat/BiteBodyAw.lean +++ b/Benchmarks/Dss/Cat/BiteBodyAw.lean @@ -45,14 +45,14 @@ theorem catBiteAwInvGen (aw : UInt256) (off sz : Nat) (h : off + sz ≤ aw.toNat conclusion to the frozen `catBiteReachPostIlks` but additionally supplies `288 ≤ awout·32` — the bound `catBiteReachPostUrns` needs and which the abstract wrapper's existential `awout` cannot provide. The active words after the ilks return-copy (`outOff = 128`, `outSize = 160`) are `M (M 6 128 36) 128 160 -= 9`, so `9·32 = 288`. Derives the call at the low level (`RD.uniswapStaticcall`) to keep `aw` += 9`, so `9·32 = 288`. Derives the call at the low level (`RD.solcStaticcall`) to keep `aw` concrete instead of chaining the aw-forgetting wrapper. -/ theorem catBiteReachPostIlksAw {cA gh bl σ σ₀ A I} {g : UInt256} (hcode : I.code = catBytecode) (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) (hsz36 : 36 ≤ I.calldata.size) (hsel : selIs I ⟨#[0x45, 0xcf, 0x22, 0x30]⟩) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (catBiteVatTargetWord σ I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (catBiteVatTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (o' : ByteArray) (A' : Substate) (awout : UInt256) (k' C' : ℕ), @@ -82,12 +82,12 @@ theorem catBiteReachPostIlksAw {cA gh bl σ σ₀ A I} {g : UInt256} catBiteIlksOutPtr.toNat catBiteIlksInSize.toNat) := by simpa [biteIlkVal] using catBiteIlksEncode_eq (biteIlkWord I) (biteIlkBytes I) solcFreePtrMem_size hbytes - obtain ⟨gasWord, _, _, rd1248⟩ := RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1233⟩) (okPc := ⟨1245⟩) + obtain ⟨gasWord, _, _, rd1248⟩ := RD.solcExtcodesizeGuardOkGas (pc := ⟨1233⟩) (okPc := ⟨1245⟩) rd1233 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp) obtain ⟨cA', σ', z, o', A_in, callGas, k', C', hΘpack, rd1249, hosz⟩ := - RD.uniswapStaticcall rd1248 (by native_decide) hdepth (by simp) + RD.solcStaticcall rd1248 (by native_decide) hdepth (by simp) obtain ⟨g'', A', hΘ⟩ := hΘpack refine ⟨cA', σ', z, o', A', _, k', C', rd1249, ?_, hosz, by native_decide, by native_decide⟩ refine callCoincides (A_in := A_in) (g'' := g'') (callGas := callGas) @@ -121,7 +121,7 @@ theorem catBiteReachPostUrnsAw {cA gh bl σ σ₀ A I} {g : UInt256} (hSpot : mem.readWithPadding 192 32 = UInt256.toByteArray iSpot) (hDust : mem.readWithPadding 256 32 = UInt256.toByteArray iDust) (hurn : UInt256.land biteAddrMaskWord urn = biteUrnWord I) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ' + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ' (UInt256.land (catSlotWord ⟨3⟩ σ' I) biteAddrMaskWord) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) @@ -197,12 +197,12 @@ theorem catBiteReachPostUrnsAw {cA gh bl σ σ₀ A I} {g : UInt256} biteUrnsEncode_eq I (by omega) hsz36 -- urns STATICCALL at the low level, exposing the concrete post-call active-words. obtain ⟨gasWord, _, _, rd1398⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1383⟩) (okPc := ⟨1395⟩) rd1383 hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨1383⟩) (okPc := ⟨1395⟩) rd1383 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) obtain ⟨cA'', σ'', z, o', A_in, callGas, k', C', hΘpack, rd1399, hosz'⟩ := - RD.uniswapStaticcall rd1398 (by native_decide) hdepth + RD.solcStaticcall rd1398 (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) obtain ⟨g'', A', hΘ⟩ := hΘpack have hawEq : UInt256.ofNat (MachineState.M (MachineState.M aw.toNat (⟨128⟩ : UInt256).toNat @@ -610,7 +610,7 @@ theorem catBiteTraceGrabBuildAw {cA gh bl σ σ₀ A I} {g : UInt256} have rd2115 := rd2114.add (by native_decide) (by evm_ov) have rd2116 := RD.mstore _ (catBiteGrabUrnMemP p ilk urn mem) (catBiteAwStepL aw (p + ⟨36⟩).toNat) rd2115 (by native_decide) catBiteMstoreCostML rfl hcol3 (by evm_ov) - have rd2117 := rd2116.uniswapAddress (by native_decide) (by evm_ov) + have rd2117 := rd2116.address (by native_decide) (by evm_ov) have rd2118 := rd2117.push1 ⟨68⟩ (by native_decide) (by evm_ov) have rd2120 := rd2118.dup6 (by native_decide) (by evm_ov) have rd2121 := rd2120.add (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Cat/BiteBodyKick.lean b/Benchmarks/Dss/Cat/BiteBodyKick.lean index 7cdcb556..0afaea9f 100644 --- a/Benchmarks/Dss/Cat/BiteBodyKick.lean +++ b/Benchmarks/Dss/Cat/BiteBodyKick.lean @@ -297,7 +297,7 @@ theorem kickEncodeP_eq (p urn vow tab dink : UInt256) {mem : ByteArray} have hw0 : EVM.word 0 = (⟨0⟩ : UInt256) := by decide simp [hw0, ByteArray.append_assoc] -/-- `2516 → 2532`: the EXTCODESIZE guard (`RD.uniswapExtcodesizeGuardOkGas`) + the `kick` `CALL` +/-- `2516 → 2532`: the EXTCODESIZE guard (`RD.solcExtcodesizeGuardOkGas`) + the `kick` `CALL` (`perm := true`, value `0`, `depth < 1024`, inOff/retOff `p`, argsLen `164`, retLen `32`) + the `Θ`→Solm coupling (`callCoincides`). The kick `CALL` copies its 1-word return `o'` (the auction `id`) into memory at `p`, so the post-call memory is `o'.write 0 mem' p (min 32 o'.size)`. Generic in the @@ -310,7 +310,7 @@ theorem catBiteKickGuardCallP {cA gh bl σ σ₀ A I} {g : UInt256} (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨2516⟩ (target :: target :: ⟨0⟩ :: p :: ⟨164⟩ :: p :: ⟨32⟩ :: R) mem' aw o (cAx, σx) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σx target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σx target ≠ ⟨0⟩) (hencode : config.externalABI.encode? "kick" args = some (mem'.readWithPadding p.toNat 164)) (hdepth : I.depth.val < 1024) (hov : R.length + 9 ≤ 1024) : @@ -329,7 +329,7 @@ theorem catBiteKickGuardCallP {cA gh bl σ σ₀ A I} {g : UInt256} accountMap := σ', substate := A', createdAccounts := cA' }, o') I.perm ∧ o'.size < UInt256.size := by obtain ⟨gasWord, _, _, rd2531⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2516⟩) (okPc := ⟨2528⟩) rd hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨2516⟩) (okPc := ⟨2528⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -921,7 +921,7 @@ theorem catBiteReachKickC {cA gh bl σ σ₀ A I} {g : UInt256} (hawsz : aw.toNat * 32 < UInt256.size) (hpmem : p.toNat + 164 ≤ mem.size) (hpsz : p.toNat + 164 < UInt256.size) (hperm : I.perm = true) (hRateFit : iRate.toNat * dart.toNat < UInt256.size) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σx + (hcodeSize : Reasoning.Theory.extCodeSizeWord σx (UInt256.land biteAddrMaskWord milkFlip) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) @@ -959,7 +959,7 @@ theorem catBiteReachKickC {cA gh bl σ σ₀ A I} {g : UInt256} hp96 hpmem hpsz (seg8_maskBound urn) (seg8_maskBound _) -- 2516 → 2532: inline EXTCODESIZE guard + kick CALL (concrete post-call active-words) obtain ⟨gasWord, _, _, rd2531⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2516⟩) (okPc := ⟨2528⟩) rd2516 hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨2516⟩) (okPc := ⟨2528⟩) rd2516 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) diff --git a/Benchmarks/Dss/Cat/BiteBodyMem.lean b/Benchmarks/Dss/Cat/BiteBodyMem.lean index a56ab518..4bd0b2c1 100644 --- a/Benchmarks/Dss/Cat/BiteBodyMem.lean +++ b/Benchmarks/Dss/Cat/BiteBodyMem.lean @@ -185,7 +185,7 @@ theorem catBiteReach2383to2532 {cA gh bl σ σ₀ A I} {g : UInt256} (hmemsize : 292 ≤ mem.size) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σx (UInt256.land biteAddrMaskWord milkFlip) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σx (UInt256.land biteAddrMaskWord milkFlip) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hov : R.length + 40 ≤ 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (o' : ByteArray) diff --git a/Benchmarks/Dss/Cat/BiteBodyReach.lean b/Benchmarks/Dss/Cat/BiteBodyReach.lean index 6271700a..cd47dab7 100644 --- a/Benchmarks/Dss/Cat/BiteBodyReach.lean +++ b/Benchmarks/Dss/Cat/BiteBodyReach.lean @@ -97,7 +97,7 @@ theorem catBiteReachGrabRegionC {cA gh bl σ σ₀ A I} {g : UInt256} (hpsz : p.toNat + 256 < UInt256.size) (hthisCanon : (UInt256.ofNat I.codeOwner.val).toNat < EVM.addressModulus) (hdink : dink.toNat ≤ 2 ^ 255) (hdart : dart.toNat ≤ 2 ^ 255) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ' + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ' (UInt256.land (solcSlotWord σ' I ⟨3⟩) biteAddrMaskWord) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) @@ -130,7 +130,7 @@ theorem catBiteReachGrabRegionC {cA gh bl σ σ₀ A I} {g : UInt256} have hencode := catBiteGrabEncode_eq p (biteIlkWord I) urn (UInt256.ofNat I.codeOwner.val) (solcSlotWord σ' I ⟨4⟩) dink dart hp96 hpmem (by omega) hthisCanon hdink hdart obtain ⟨gasWord, _, _, rd2192⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2177⟩) (okPc := ⟨2189⟩) rd2177 hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨2177⟩) (okPc := ⟨2189⟩) rd2177 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp) @@ -175,7 +175,7 @@ theorem catBiteReachFessRegionC {cA gh bl σ σ₀ A I} {g : UInt256} (hp96 : 96 ≤ p2.toNat) (hpmem : p2.toNat ≤ mem.size) (hawcov : p2.toNat ≤ aw.toNat * 32) (hawsz : aw.toNat * 32 < UInt256.size) (hpsz : p2.toNat + 96 < UInt256.size) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ' + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ' (UInt256.land biteAddrMaskWord (solcSlotWord σ' I ⟨4⟩)) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) @@ -201,7 +201,7 @@ theorem catBiteReachFessRegionC {cA gh bl σ σ₀ A I} {g : UInt256} catBiteTraceFessBuild rd2242 hFree64 hp96 hpmem hawcov hawsz hpsz (by simp) have hencode := catBiteFessEncode_eq p2 dartRate hpmem (by omega) obtain ⟨gasWord, _, _, rd2299⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2284⟩) (okPc := ⟨2296⟩) rd2284 hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨2284⟩) (okPc := ⟨2296⟩) rd2284 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp) diff --git a/Benchmarks/Dss/Cat/BiteCallDiverge.lean b/Benchmarks/Dss/Cat/BiteCallDiverge.lean index df4d1770..85a6c630 100644 --- a/Benchmarks/Dss/Cat/BiteCallDiverge.lean +++ b/Benchmarks/Dss/Cat/BiteCallDiverge.lean @@ -36,11 +36,11 @@ theorem RD.catBiteIlksNoCode (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1233⟩ (target :: target :: outPtr :: inSize :: outPtr :: outSize :: R) mem aw o (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) (hov : R.length + 8 ≤ 1024) : RDrev catBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := - RD.uniswapExtcodesizeGuardMissing (pc := ⟨1233⟩) (okPc := ⟨1245⟩) rd hcodeSize + RD.solcExtcodesizeGuardMissing (pc := ⟨1233⟩) (okPc := ⟨1245⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -58,7 +58,7 @@ theorem RD.catBiteIlksCallFailed (hov : R.length + 5 ≤ 1024) : RDrev catBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := - RD.uniswapCallSuccessGuardMissing (pc := ⟨1249⟩) (okPc := ⟨1265⟩) rd rfl + RD.solcCallSuccessGuardMissing (pc := ⟨1249⟩) (okPc := ⟨1265⟩) rd rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) hosz hov @@ -88,7 +88,7 @@ theorem RD.catBiteIlksReturnDecodeShortReverts RDrev catBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd1267⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨1249⟩) (okPc := ⟨1265⟩) rd hstatus + RD.solcCallSuccessGuardOk (pc := ⟨1249⟩) (okPc := ⟨1265⟩) rd hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -112,7 +112,7 @@ theorem RD.catBiteIlksReturnDecodeShortReverts rw [hlt]; decide have rdFallthrough := RD.jumpiNT rd1282 (by native_decide) hcond (by simp only [List.length_cons]; omega) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -129,7 +129,7 @@ theorem catBiteUrnsNoCodeLeaf {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (rd : RD catBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1383⟩ (target :: target :: outPtr :: ⟨68⟩ :: outPtr :: ⟨64⟩ :: R) mem aw o (cA, σ_evm) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ_evm target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ_evm target = ⟨0⟩) (hov : R.length + 8 ≤ 1024) (hbody : ExecTransitionBody config contract @@ -204,7 +204,7 @@ theorem catBiteGrabNoCodeLeaf {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (rd : RD catBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨2177⟩ (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: ⟨0⟩ :: R) mem aw rdata (cA, σ_evm) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ_evm target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ_evm target = ⟨0⟩) (hov : R.length + 9 ≤ 1024) (hbody : ExecTransitionBody config contract @@ -226,7 +226,7 @@ theorem catBiteFessNoCodeLeaf {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (rd : RD catBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨2284⟩ (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: outSize :: R) mem aw rdata (cA, σ_evm) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ_evm target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ_evm target = ⟨0⟩) (hov : R.length + 9 ≤ 1024) (hbody : ExecTransitionBody config contract @@ -249,7 +249,7 @@ theorem catBiteKickNoCodeLeaf {cA gh bl σ_evm σ_solm σ₀ A I} {g target : UI (rd : RD catBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨2516⟩ (target :: target :: ⟨0⟩ :: ⟨128⟩ :: ⟨164⟩ :: ⟨128⟩ :: ⟨32⟩ :: R) mem aw rdata (cAx, σx) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σx target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σx target = ⟨0⟩) (hov : R.length + 9 ≤ 1024) (hbody : ExecTransitionBody config contract @@ -272,7 +272,7 @@ theorem catBiteIlksNoCodeLeaf {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (rd : RD catBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1233⟩ (target :: target :: outPtr :: inSize :: outPtr :: outSize :: R) mem aw o (cA, σ_evm) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ_evm target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ_evm target = ⟨0⟩) (hov : R.length + 8 ≤ 1024) (hbody : ExecTransitionBody config contract @@ -621,7 +621,7 @@ theorem RD.catBiteKickReturnDecodeShortReverts have hcond : UInt256.isZero (UInt256.lt (UInt256.ofNat o.size) ⟨32⟩) = ⟨0⟩ := by rw [hlt]; decide have rdFallthrough := RD.jumpiNT rd2565 (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by evm_ov) /-- **kick return-decode-short leaf.** EVM cursor at the `kick` success-guard `@2532` with a diff --git a/Benchmarks/Dss/Cat/BiteCallFess.lean b/Benchmarks/Dss/Cat/BiteCallFess.lean index 5c61fbd7..66dd3395 100644 --- a/Benchmarks/Dss/Cat/BiteCallFess.lean +++ b/Benchmarks/Dss/Cat/BiteCallFess.lean @@ -153,7 +153,7 @@ theorem RD.catBiteFessCall {cA gh bl σ σ₀ A I} {g : Sat256} (rd : RD catBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2284⟩ (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: outSize :: R) mem aw rdata (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hov : R.length + 9 ≤ 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) @@ -173,7 +173,7 @@ theorem RD.catBiteFessCall {cA gh bl σ σ₀ A I} {g : Sat256} o (cA', σ') k' C' ∧ o.size < UInt256.size := by obtain ⟨gasWord, k1, C1, rd2299⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2284⟩) (okPc := ⟨2296⟩) rd hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨2284⟩) (okPc := ⟨2296⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) @@ -191,10 +191,10 @@ theorem RD.catBiteFessNoCode {cA gh bl σ σ₀ A I} {g : Sat256} (rd : RD catBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2284⟩ (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: outSize :: R) mem aw rdata (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) (hov : R.length + 9 ≤ 1024) : RDrev catBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2284⟩) (okPc := ⟨2296⟩) rd hcodeSize + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2284⟩) (okPc := ⟨2296⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -228,7 +228,7 @@ theorem RD.catBiteFessCallFailed {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} (hrdataSize : rdata.size < UInt256.size) (hov : R.length + 5 ≤ 1024) : RDrev catBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2300⟩) (okPc := ⟨2316⟩) rd2300 rfl + exact RD.solcCallSuccessGuardMissing (pc := ⟨2300⟩) (okPc := ⟨2316⟩) rd2300 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -244,7 +244,7 @@ theorem RD.catBiteFessCallSucceeded {cA gh bl σ σ₀ A I} {g : Sat256} (hov : R.length + 3 ≤ 1024) : ∃ k' C', RD catBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2318⟩ R mem aw rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨2300⟩) (okPc := ⟨2316⟩) rd2300 + exact RD.solcCallSuccessGuardOk (pc := ⟨2300⟩) (okPc := ⟨2316⟩) rd2300 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Cat/BiteCallGrab.lean b/Benchmarks/Dss/Cat/BiteCallGrab.lean index 3f201b4d..85bc093a 100644 --- a/Benchmarks/Dss/Cat/BiteCallGrab.lean +++ b/Benchmarks/Dss/Cat/BiteCallGrab.lean @@ -50,10 +50,10 @@ theorem RD.catBiteGrabNoCode (rd2177 : RD catBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2177⟩ (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: ⟨0⟩ :: R) mem aw rdata (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) (hov : R.length + 9 ≤ 1024) : RDrev catBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2177⟩) (okPc := ⟨2189⟩) rd2177 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2177⟩) (okPc := ⟨2189⟩) rd2177 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -72,7 +72,7 @@ theorem RD.catBiteGrabCall (rd2177 : RD catBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2177⟩ (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: ⟨0⟩ :: R) mem aw rdata (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hov : R.length + 9 ≤ 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) @@ -89,7 +89,7 @@ theorem RD.catBiteGrabCall ((if z then ⟨1⟩ else ⟨0⟩) :: R) mem' aw' o (cA', σ') k' C' ∧ o.size < UInt256.size := by obtain ⟨gasWord, k1, C1, rd2192⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2177⟩) (okPc := ⟨2189⟩) rd2177 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2177⟩) (okPc := ⟨2189⟩) rd2177 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -113,13 +113,13 @@ theorem RD.catBiteGrabCallDepthLimit (rd2177 : RD catBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2177⟩ (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: ⟨0⟩ :: R) mem aw rdata (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hov : R.length + 9 ≤ 1024) : ∃ mem' aw' k' C', RD catBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2193⟩ (⟨0⟩ :: R) mem' aw' ByteArray.empty (cA, σ) k' C' := by obtain ⟨gasWord, k1, C1, rd2192⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2177⟩) (okPc := ⟨2189⟩) rd2177 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2177⟩) (okPc := ⟨2189⟩) rd2177 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -145,7 +145,7 @@ theorem RD.catBiteGrabCallFailed (hrdataSize : rdata.size < UInt256.size) (hov : R.length + 5 ≤ 1024) : RDrev catBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2193⟩) (okPc := ⟨2209⟩) rd2193 + exact RD.solcCallSuccessGuardMissing (pc := ⟨2193⟩) (okPc := ⟨2209⟩) rd2193 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -168,7 +168,7 @@ theorem RD.catBiteGrabCallSucceeded ∃ k' C', RD catBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2212⟩ R mem aw rdata acc k' C' := by obtain ⟨k1, C1, rd2211⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨2193⟩) (okPc := ⟨2209⟩) rd2193 + RD.solcCallSuccessGuardOk (pc := ⟨2193⟩) (okPc := ⟨2209⟩) rd2193 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Cat/BiteCallKick.lean b/Benchmarks/Dss/Cat/BiteCallKick.lean index ff0e5f4a..22d251c1 100644 --- a/Benchmarks/Dss/Cat/BiteCallKick.lean +++ b/Benchmarks/Dss/Cat/BiteCallKick.lean @@ -327,11 +327,11 @@ theorem RD.catBiteKickGuardMissing {cA gh bl σ σ₀ A I} {g target : UInt256} (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨2516⟩ (target :: target :: ⟨0⟩ :: ⟨128⟩ :: ⟨164⟩ :: ⟨128⟩ :: ⟨32⟩ :: R) mem aw rdata (cAx, σx) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σx target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σx target = ⟨0⟩) (hov : R.length + 9 ≤ 1024) : RDrev catBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2516⟩) (okPc := ⟨2528⟩) rd hcodeSize + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2516⟩) (okPc := ⟨2528⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -344,14 +344,14 @@ theorem RD.catBiteKickGuardOk {cA gh bl σ σ₀ A I} {g target : UInt256} {mem (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨2516⟩ (target :: target :: ⟨0⟩ :: ⟨128⟩ :: ⟨164⟩ :: ⟨128⟩ :: ⟨32⟩ :: R) mem aw rdata (cAx, σx) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σx target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σx target ≠ ⟨0⟩) (hov : R.length + 9 ≤ 1024) : ∃ gasWord k' C', RD catBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨2531⟩ (gasWord :: target :: ⟨0⟩ :: ⟨128⟩ :: ⟨164⟩ :: ⟨128⟩ :: ⟨32⟩ :: R) mem aw rdata (cAx, σx) k' C' := by obtain ⟨gasWord, k', C', rd'⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2516⟩) (okPc := ⟨2528⟩) rd hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨2516⟩) (okPc := ⟨2528⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -416,7 +416,7 @@ theorem RD.catBiteKickCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} {mem : By (hov : R.length + 5 ≤ 1024) : RDrev catBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2532⟩) (okPc := ⟨2548⟩) rd rfl + exact RD.solcCallSuccessGuardMissing (pc := ⟨2532⟩) (okPc := ⟨2548⟩) rd rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -435,7 +435,7 @@ theorem RD.catBiteKickCallSucceeded {cA gh bl σ σ₀ A I} {g status : UInt256} ∃ k' C', RD catBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨2550⟩ R mem aw rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨2532⟩) (okPc := ⟨2548⟩) rd hstatus + exact RD.solcCallSuccessGuardOk (pc := ⟨2532⟩) (okPc := ⟨2548⟩) rd hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) hov diff --git a/Benchmarks/Dss/Cat/BiteCallUrns.lean b/Benchmarks/Dss/Cat/BiteCallUrns.lean index 6bf4a9e4..b730a7e5 100644 --- a/Benchmarks/Dss/Cat/BiteCallUrns.lean +++ b/Benchmarks/Dss/Cat/BiteCallUrns.lean @@ -231,11 +231,11 @@ theorem RD.catBiteUrnsNoCode (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1383⟩ (target :: target :: outPtr :: ⟨68⟩ :: outPtr :: ⟨64⟩ :: R) mem aw o (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) (hov : R.length + 8 ≤ 1024) : RDrev catBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := - RD.uniswapExtcodesizeGuardMissing (pc := ⟨1383⟩) (okPc := ⟨1395⟩) rd hcodeSize + RD.solcExtcodesizeGuardMissing (pc := ⟨1383⟩) (okPc := ⟨1395⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -251,7 +251,7 @@ theorem RD.catBiteUrnsStaticcall (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1383⟩ (target :: target :: outPtr :: ⟨68⟩ :: outPtr :: ⟨64⟩ :: R) mem aw o (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hencode : config.externalABI.encode? "urns" args = some (mem.readWithPadding outPtr.toNat 68)) @@ -269,12 +269,12 @@ theorem RD.catBiteUrnsStaticcall accountMap := σ', substate := A', createdAccounts := cA' }, o') false ∧ o'.size < UInt256.size := by obtain ⟨gasWord, _, _, rd1398⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1383⟩) (okPc := ⟨1395⟩) rd hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨1383⟩) (okPc := ⟨1395⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) obtain ⟨cA', σ', z, o', A_in, callGas, k', C', hΘpack, rd1399, hosz⟩ := - RD.uniswapStaticcall rd1398 (by native_decide) hdepth (by omega) + RD.solcStaticcall rd1398 (by native_decide) hdepth (by omega) obtain ⟨g'', A', hΘ⟩ := hΘpack refine ⟨cA', σ', z, o', A', _, k', C', rd1399, ?_, hosz⟩ refine callCoincides (A_in := A_in) (g'' := g'') (callGas := callGas) @@ -292,7 +292,7 @@ theorem RD.catBiteUrnsDepthLimit (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1383⟩ (target :: target :: outPtr :: ⟨68⟩ :: outPtr :: ⟨64⟩ :: R) mem aw o (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hov : R.length + 8 ≤ 1024) : ∃ (awout : UInt256) (k' C' : ℕ), RD catBytecode I (Sat256.ofUInt256 g) @@ -302,12 +302,12 @@ theorem RD.catBiteUrnsDepthLimit (min (⟨64⟩ : UInt256) (UInt256.ofNat ByteArray.empty.size)).toNat) awout ByteArray.empty (cA, σ) k' C' := by obtain ⟨gasWord, _, _, rd1398⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1383⟩) (okPc := ⟨1395⟩) rd hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨1383⟩) (okPc := ⟨1395⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) obtain ⟨k', C', rd1399⟩ := - RD.uniswapStaticcallDepthLimit rd1398 (by native_decide) hdepth (by omega) + RD.solcStaticcallDepthLimit rd1398 (by native_decide) hdepth (by omega) exact ⟨_, k', C', rd1399⟩ /-- **call failed** (`status = 0`) — the success guard bubbles the revert. -/ @@ -322,7 +322,7 @@ theorem RD.catBiteUrnsCallFailed (hov : R.length + 5 ≤ 1024) : RDrev catBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := - RD.uniswapCallSuccessGuardMissing (pc := ⟨1399⟩) (okPc := ⟨1415⟩) rd rfl + RD.solcCallSuccessGuardMissing (pc := ⟨1399⟩) (okPc := ⟨1415⟩) rd rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) hosz hov @@ -342,7 +342,7 @@ theorem RD.catBiteUrnsCallSucceeded (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1420⟩ R mem aw o acc k' C' := by obtain ⟨_, _, rd1417⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨1399⟩) (okPc := ⟨1415⟩) rd hstatus + RD.solcCallSuccessGuardOk (pc := ⟨1399⟩) (okPc := ⟨1415⟩) rd hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -390,7 +390,7 @@ theorem RD.catBiteUrnsReturnDecodeShortReverts rw [hlt]; decide have rdFallthrough := RD.jumpiNT rdPushOk (by native_decide) hcond (by simp only [List.length_cons]; omega) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) diff --git a/Benchmarks/Dss/Cat/BiteConnect.lean b/Benchmarks/Dss/Cat/BiteConnect.lean index faabe404..163b37e7 100644 --- a/Benchmarks/Dss/Cat/BiteConnect.lean +++ b/Benchmarks/Dss/Cat/BiteConnect.lean @@ -72,7 +72,7 @@ theorem RD.catBiteCheckedMulRevert {cA gh bl σ σ₀ A I} {g : Sat256} have rd3748 := rd3747.jumpdest (by native_decide) (by evm_ov) have rd3751 := rd3748.push2 ⟨3756⟩ (by native_decide) (by evm_ov) have rd3752 := rd3751.jumpiNT (by native_decide) rfl (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd3752 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd3752 (by native_decide) (by native_decide) (by native_decide) (by evm_ov) /-- Entry (`375`) → routine (`1163`) → ilks `STATICCALL` (Seg 1, at pc `1249`): the first view call. @@ -81,7 +81,7 @@ theorem catBiteReachPostIlks {cA gh bl σ σ₀ A I} {g : UInt256} (hcode : I.code = catBytecode) (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) (hsel : selIs I ⟨#[0x45, 0xcf, 0x22, 0x30]⟩) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (catBiteVatTargetWord σ I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (catBiteVatTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (o' : ByteArray) (A' : Substate) (awout : UInt256) (k' C' : ℕ), @@ -126,7 +126,7 @@ theorem catBiteReachPostUrns {cA gh bl σ σ₀ A I} {g : UInt256} (hSpot : mem.readWithPadding 192 32 = UInt256.toByteArray iSpot) (hDust : mem.readWithPadding 256 32 = UInt256.toByteArray iDust) (hurn : UInt256.land biteAddrMaskWord urn = biteUrnWord I) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ' + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ' (UInt256.land (catSlotWord ⟨3⟩ σ' I) biteAddrMaskWord) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) @@ -459,7 +459,7 @@ theorem catBiteReachFessRegion {cA gh bl σ σ₀ A I} {g : UInt256} (hp96 : 96 ≤ p2.toNat) (hpmem : p2.toNat ≤ mem.size) (hawcov : p2.toNat ≤ aw.toNat * 32) (hawsz : aw.toNat * 32 < UInt256.size) (hpsz : p2.toNat + 96 < UInt256.size) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ' + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ' (UInt256.land biteAddrMaskWord (solcSlotWord σ' I ⟨4⟩)) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) @@ -505,7 +505,7 @@ theorem catBiteReachGrabRegion {cA gh bl σ σ₀ A I} {g : UInt256} (hpsz : p.toNat + 256 < UInt256.size) (hthisCanon : (UInt256.ofNat I.codeOwner.val).toNat < EVM.addressModulus) (hdink : dink.toNat ≤ 2 ^ 255) (hdart : dart.toNat ≤ 2 ^ 255) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ' + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ' (UInt256.land (solcSlotWord σ' I ⟨3⟩) biteAddrMaskWord) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) diff --git a/Benchmarks/Dss/Cat/BiteRevertBranch.lean b/Benchmarks/Dss/Cat/BiteRevertBranch.lean index d2936d97..c7df0f1c 100644 --- a/Benchmarks/Dss/Cat/BiteRevertBranch.lean +++ b/Benchmarks/Dss/Cat/BiteRevertBranch.lean @@ -98,7 +98,7 @@ theorem catBiteMapUrns {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (hAccounts : accountMapEquiv σ_evm σ_solm) (hdepthNe : I.depth ≠ 1024) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -143,11 +143,11 @@ theorem catBiteMapUrns {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rw [show EVM.addressModulus = AccountAddress.size from by decide] exact Nat.mod_eq_of_lt a.isLt have codePos : ∀ (e : EVM.State) (w : UInt256), - uniswapExtCodeSizeWord e.accountMap w ≠ ⟨0⟩ → + extCodeSizeWord e.accountMap w ≠ ⟨0⟩ → 0 < (UInt256.ofNat ((e.lookupAccount (AccountAddress.ofUInt256 w)).option 0 (fun acc => acc.code.size))).toNat := by intro e w hw - unfold uniswapExtCodeSizeWord at hw + unfold extCodeSizeWord at hw simp only [State.lookupAccount] cases hf : e.accountMap.find? (AccountAddress.ofUInt256 w) with | none => rw [hf] at hw; simp [Option.option] at hw @@ -187,7 +187,7 @@ theorem catBiteMapUrns {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} refine codePos eI (catBiteVatTargetWord σs I) ?_ rw [heIam, show catBiteVatTargetWord σs I = (catSlotWord ⟨3⟩ σs I).land biteAddrMaskWord from by simp only [catBiteVatTargetWord, catAddressReturnWord, hmask], - ← hslot3, ← uniswapExtCodeSizeWord_accountMapEquiv hEqIlk.accountMap] + ← hslot3, ← extCodeSizeWord_accountMapEquiv hEqIlk.accountMap] exact hUrnsVatCode exact ⟨σs, As, σus, Aus, hIlksSolm, hUrnsSolm, hEqUrn.accountMap, hvatCodeIlk⟩ @@ -214,11 +214,11 @@ theorem catBiteRevertGrabFail {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (hurn : biteAddrMaskWord.land (biteAddrMaskWord.land (calldataWord I.calldata 36)) = biteUrnWord I) (hilkslen : 160 ≤ o'.size) (hurnslen : 64 ≤ ou.size) (hlive : catSlotWord ⟨2⟩ σu I = ⟨1⟩) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hGrabCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -287,12 +287,12 @@ theorem catBiteRevertGrabFail {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rw [show EVM.addressModulus = AccountAddress.size from by decide] exact Nat.mod_eq_of_lt a.isLt have codePos : ∀ (e : EVM.State) (w : UInt256), - uniswapExtCodeSizeWord e.accountMap w ≠ ⟨0⟩ → + extCodeSizeWord e.accountMap w ≠ ⟨0⟩ → 0 < (UInt256.ofNat ((e.lookupAccount (AccountAddress.ofUInt256 w)).option 0 (fun acc => acc.code.size))).toNat := by intro e w hw - unfold uniswapExtCodeSizeWord at hw + unfold extCodeSizeWord at hw simp only [State.lookupAccount] cases hf : e.accountMap.find? (AccountAddress.ofUInt256 w) with | none => rw [hf] at hw; simp [Option.option] at hw @@ -438,9 +438,9 @@ theorem catBiteRevertGrabFail {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hdinkvBS : biteDinkV I eUrnS iRate art ink = dink := by rw [← biteDinkV_eq_of_equiv hEqU]; exact hdinkvB have hGrabCodeS : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σus + ¬ Reasoning.Theory.extCodeSizeWord σus ((solcSlotWord σus I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩ := by - rw [slotEqUS ⟨3⟩, ← uniswapExtCodeSizeWord_accountMapEquiv hAmEq] + rw [slotEqUS ⟨3⟩, ← extCodeSizeWord_accountMapEquiv hAmEq] exact hGrabCode -- reshape the mapped grab call to the source-revert form. rw [hperm, ← htgtU, ← h1, ← h2, ← h3, ← h4, ← hdinkvBS, ← hdartvBS] @@ -511,13 +511,13 @@ theorem catBiteRevertFessFail {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (hurn : biteAddrMaskWord.land (biteAddrMaskWord.land (calldataWord I.calldata 36)) = biteUrnWord I) (hilkslen : 160 ≤ o'.size) (hurnslen : 64 ≤ ou.size) (hlive : catSlotWord ⟨2⟩ σu I = ⟨1⟩) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hGrabCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) (hFessCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -590,12 +590,12 @@ theorem catBiteRevertFessFail {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hposNe : ∀ w : UInt256, w ≠ ⟨0⟩ → 0 < w.toNat := fun w hw => Nat.pos_of_ne_zero (fun h => hw (uint256_toNat_eq_zero h)) have codePos : ∀ (e : EVM.State) (w : UInt256), - uniswapExtCodeSizeWord e.accountMap w ≠ ⟨0⟩ → + extCodeSizeWord e.accountMap w ≠ ⟨0⟩ → 0 < (UInt256.ofNat ((e.lookupAccount (AccountAddress.ofUInt256 w)).option 0 (fun acc => acc.code.size))).toNat := by intro e w hw - unfold uniswapExtCodeSizeWord at hw + unfold extCodeSizeWord at hw simp only [State.lookupAccount] cases hf : e.accountMap.find? (AccountAddress.ofUInt256 w) with | none => rw [hf] at hw; simp [Option.option] at hw @@ -752,9 +752,9 @@ theorem catBiteRevertFessFail {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rw [← biteDartRateV_eq_of_equiv hEqU] simp only [biteDartRateV, hdartvB]; rfl have hGrabCodeS : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σus + ¬ Reasoning.Theory.extCodeSizeWord σus ((solcSlotWord σus I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩ := by - rw [slotEqUS ⟨3⟩, ← uniswapExtCodeSizeWord_accountMapEquiv hAmEq] + rw [slotEqUS ⟨3⟩, ← extCodeSizeWord_accountMapEquiv hAmEq] exact hGrabCode rw [hperm, ← htgtU, ← h1, ← h2, ← h3, ← h4, ← hdinkvBS, ← hdartvBS] at hGrabSolm @@ -846,15 +846,15 @@ theorem catBiteRevertKickFail {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (hurn : biteAddrMaskWord.land (biteAddrMaskWord.land (calldataWord I.calldata 36)) = biteUrnWord I) (hilkslen : 160 ≤ o'.size) (hurnslen : 64 ≤ ou.size) (hlive : catSlotWord ⟨2⟩ σu I = ⟨1⟩) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hGrabCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) (hFessCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) (hKickCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σf ⟨6⟩ litterNew) + ¬ Reasoning.Theory.extCodeSizeWord (sstoreAccountMap I.codeOwner σf ⟨6⟩ litterNew) (biteAddrMaskWord.land flipW) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) @@ -944,12 +944,12 @@ theorem catBiteRevertKickFail {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hposNe : ∀ w : UInt256, w ≠ ⟨0⟩ → 0 < w.toNat := fun w hw => Nat.pos_of_ne_zero (fun h => hw (uint256_toNat_eq_zero h)) have codePos : ∀ (e : EVM.State) (w : UInt256), - uniswapExtCodeSizeWord e.accountMap w ≠ ⟨0⟩ → + extCodeSizeWord e.accountMap w ≠ ⟨0⟩ → 0 < (UInt256.ofNat ((e.lookupAccount (AccountAddress.ofUInt256 w)).option 0 (fun acc => acc.code.size))).toNat := by intro e w hw - unfold uniswapExtCodeSizeWord at hw + unfold extCodeSizeWord at hw simp only [State.lookupAccount] cases hf : e.accountMap.find? (AccountAddress.ofUInt256 w) with | none => rw [hf] at hw; simp [Option.option] at hw @@ -1120,9 +1120,9 @@ theorem catBiteRevertKickFail {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have htabBS : biteTabV I eUrnS iRate art = tab := by rw [← biteTabV_eq_of_equiv hEqU]; exact htabB have hGrabCodeS : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σus + ¬ Reasoning.Theory.extCodeSizeWord σus ((solcSlotWord σus I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩ := by - rw [slotEqUS ⟨3⟩, ← uniswapExtCodeSizeWord_accountMapEquiv hAmEq] + rw [slotEqUS ⟨3⟩, ← extCodeSizeWord_accountMapEquiv hAmEq] exact hGrabCode rw [hperm, ← htgtU, ← h1, ← h2, ← h3, ← h4, ← hdinkvBS, ← hdartvBS] at hGrabSolm @@ -1233,7 +1233,7 @@ theorem catBiteRevertKickFail {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (fun acc => acc.code.size))).toNat := by rw [hflipAddrS] refine codePos eLitS (biteAddrMaskWord.land flipW) ?_ - rw [heLSam, ← uniswapExtCodeSizeWord_accountMapEquiv + rw [heLSam, ← extCodeSizeWord_accountMapEquiv (accountMapEquiv_sstoreAccountMap I.codeOwner ⟨6⟩ hLitVal hEqFess.accountMap), ← hLitValEq] exact hKickCode @@ -1306,15 +1306,15 @@ theorem catBiteRevertKickDecode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 (hurn : biteAddrMaskWord.land (biteAddrMaskWord.land (calldataWord I.calldata 36)) = biteUrnWord I) (hilkslen : 160 ≤ o'.size) (hurnslen : 64 ≤ ou.size) (hlive : catSlotWord ⟨2⟩ σu I = ⟨1⟩) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hGrabCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) (hFessCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) (hKickCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σf ⟨6⟩ litterNew) + ¬ Reasoning.Theory.extCodeSizeWord (sstoreAccountMap I.codeOwner σf ⟨6⟩ litterNew) (biteAddrMaskWord.land flipW) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) @@ -1412,12 +1412,12 @@ theorem catBiteRevertKickDecode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 have hposNe : ∀ w : UInt256, w ≠ ⟨0⟩ → 0 < w.toNat := fun w hw => Nat.pos_of_ne_zero (fun h => hw (uint256_toNat_eq_zero h)) have codePos : ∀ (e : EVM.State) (w : UInt256), - uniswapExtCodeSizeWord e.accountMap w ≠ ⟨0⟩ → + extCodeSizeWord e.accountMap w ≠ ⟨0⟩ → 0 < (UInt256.ofNat ((e.lookupAccount (AccountAddress.ofUInt256 w)).option 0 (fun acc => acc.code.size))).toNat := by intro e w hw - unfold uniswapExtCodeSizeWord at hw + unfold extCodeSizeWord at hw simp only [State.lookupAccount] cases hf : e.accountMap.find? (AccountAddress.ofUInt256 w) with | none => rw [hf] at hw; simp [Option.option] at hw @@ -1588,9 +1588,9 @@ theorem catBiteRevertKickDecode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 have htabBS : biteTabV I eUrnS iRate art = tab := by rw [← biteTabV_eq_of_equiv hEqU]; exact htabB have hGrabCodeS : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σus + ¬ Reasoning.Theory.extCodeSizeWord σus ((solcSlotWord σus I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩ := by - rw [slotEqUS ⟨3⟩, ← uniswapExtCodeSizeWord_accountMapEquiv hAmEq] + rw [slotEqUS ⟨3⟩, ← extCodeSizeWord_accountMapEquiv hAmEq] exact hGrabCode rw [hperm, ← htgtU, ← h1, ← h2, ← h3, ← h4, ← hdinkvBS, ← hdartvBS] at hGrabSolm @@ -1701,7 +1701,7 @@ theorem catBiteRevertKickDecode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 (fun acc => acc.code.size))).toNat := by rw [hflipAddrS] refine codePos eLitS (biteAddrMaskWord.land flipW) ?_ - rw [heLSam, ← uniswapExtCodeSizeWord_accountMapEquiv + rw [heLSam, ← extCodeSizeWord_accountMapEquiv (accountMapEquiv_sstoreAccountMap I.codeOwner ⟨6⟩ hLitVal hEqFess.accountMap), ← hLitValEq] exact hKickCode @@ -1778,15 +1778,15 @@ theorem catBiteRevertKickDecodeW {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt25 (hurn : biteAddrMaskWord.land (biteAddrMaskWord.land (calldataWord I.calldata 36)) = biteUrnWord I) (hilkslen : 160 ≤ o'.size) (hurnslen : 64 ≤ ou.size) (hlive : catSlotWord ⟨2⟩ σu I = ⟨1⟩) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hGrabCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) (hFessCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) (hKickCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σf ⟨6⟩ litterNew) + ¬ Reasoning.Theory.extCodeSizeWord (sstoreAccountMap I.codeOwner σf ⟨6⟩ litterNew) (biteAddrMaskWord.land flipW) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) @@ -2101,7 +2101,7 @@ theorem catBiteReachGuardRoomSubAw {cA gh bl σ σ₀ A I} {g : UInt256} /-- **checked-`sub` underflow → empty `revert(0,0)`.** solc 0.6.12 compiles the DSMath `sub` underflow guard's false branch as `PUSH1 0; DUP1; REVERT` (empty revert), NOT an error string (unlike `RD.solcCheckedSubStringRevertGrown`). Same success-guard prefix; the tail fires -`RD.uniswapPush1Dup1Revert0`. -/ +`RD.solcPush1Dup1Revert0`. -/ theorem RD.solcCheckedSubEmptyRevert {code : ByteArray} {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {pc okPc : UInt256} {a b ret : UInt256} {R : List UInt256} {mem rdata : ByteArray} {aw : UInt256} @@ -2143,7 +2143,7 @@ theorem RD.solcCheckedSubEmptyRevert {code : ByteArray} {g : Sat256} {s0 : State have rdTail₀ := rdPush.jumpiNT hd11 (by decide) (by simp only [List.length_cons]; omega) have rdTail := by simpa [solcCheckedArithmeticRevertPc] using rdTail₀ - exact RD.uniswapPush1Dup1Revert0 rdTail hd0 hd1 hd2 (by simp only [List.length_cons]; omega) + exact RD.solcPush1Dup1Revert0 rdTail hd0 hd1 hd2 (by simp only [List.length_cons]; omega) /-- **room-underflow (box < litter) empty-revert leaf.** `room = box - litter` underflows; the checked-`sub` reverts `revert(0,0)`. EVM side via `RD.solcCheckedSubEmptyRevert`, Solm side fed as @@ -2188,9 +2188,9 @@ theorem catBiteRevertRoomSub {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -2309,9 +2309,9 @@ theorem catBiteRevertDunkRoomWad {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt25 (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -2461,9 +2461,9 @@ theorem catBiteRevertMilkChopZero {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt2 (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -2622,9 +2622,9 @@ theorem catBiteRevertInkSpot {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -2718,9 +2718,9 @@ theorem catBiteRevertLive {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -2881,9 +2881,9 @@ theorem catBiteRevertUnsafe {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -3007,9 +3007,9 @@ theorem catBiteRevertSpotZero {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -3132,9 +3132,9 @@ theorem catBiteRevertArtRate {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -3267,9 +3267,9 @@ theorem catBiteRevertInkDart {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -3450,13 +3450,13 @@ theorem catBiteRevertTabBase {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (hurn : biteAddrMaskWord.land (biteAddrMaskWord.land (calldataWord I.calldata 36)) = biteUrnWord I) (hilkslen : 160 ≤ o'.size) (hurnslen : 64 ≤ ou.size) (hlive : catSlotWord ⟨2⟩ σu I = ⟨1⟩) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hGrabCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) (hFessCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -3535,12 +3535,12 @@ theorem catBiteRevertTabBase {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hposNe : ∀ w : UInt256, w ≠ ⟨0⟩ → 0 < w.toNat := fun w hw => Nat.pos_of_ne_zero (fun h => hw (uint256_toNat_eq_zero h)) have codePos : ∀ (e : EVM.State) (w : UInt256), - uniswapExtCodeSizeWord e.accountMap w ≠ ⟨0⟩ → + extCodeSizeWord e.accountMap w ≠ ⟨0⟩ → 0 < (UInt256.ofNat ((e.lookupAccount (AccountAddress.ofUInt256 w)).option 0 (fun acc => acc.code.size))).toNat := by intro e w hw - unfold uniswapExtCodeSizeWord at hw + unfold extCodeSizeWord at hw simp only [State.lookupAccount] cases hf : e.accountMap.find? (AccountAddress.ofUInt256 w) with | none => rw [hf] at hw; simp [Option.option] at hw @@ -3697,9 +3697,9 @@ theorem catBiteRevertTabBase {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hdartrateBS : biteDartRateV I eUrnS iRate art = dartRate := by rw [← biteDartRateV_eq_of_equiv hEqU]; exact hdartrateBE have hGrabCodeS : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σus + ¬ Reasoning.Theory.extCodeSizeWord σus ((solcSlotWord σus I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩ := by - rw [slotEqUS ⟨3⟩, ← uniswapExtCodeSizeWord_accountMapEquiv hAmEq] + rw [slotEqUS ⟨3⟩, ← extCodeSizeWord_accountMapEquiv hAmEq] exact hGrabCode rw [hperm, ← htgtU, ← h1, ← h2, ← h3, ← h4, ← hdinkvBS, ← hdartvBS] at hGrabSolm @@ -3870,7 +3870,7 @@ theorem catBiteRevertIlksDecode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hvatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -4010,9 +4010,9 @@ theorem catBiteRevertDartZero {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -4198,9 +4198,9 @@ theorem catBiteRevertDinkZero {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -4395,9 +4395,9 @@ theorem catBiteRevertDartLimit {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -4594,9 +4594,9 @@ theorem catBiteRevertDinkLimit {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -4972,9 +4972,9 @@ theorem catBiteRevertLitterGeBox {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt25 (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -5090,9 +5090,9 @@ theorem catBiteRevertRoomDust {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hsz36 : 36 ≤ I.calldata.size) (hdepth : (I.depth : ℕ) < 1024) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -5202,7 +5202,7 @@ theorem catBiteRevertRoomDust {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} set_option maxHeartbeats 4000000 in /-- **fess no-code branch (extracted).** grab succeeds; the `EXTCODESIZE(vow)` guard before the `vow.fess(...)` CALL is false (empty code), so the EVM reverts at pc `2284` before any call. Maps -ilks+urns+grab to σ_solm, fires the generic `RD.uniswapExtcodesizeGuardMissing` at the abstract +ilks+urns+grab to σ_solm, fires the generic `RD.solcExtcodesizeGuardMissing` at the abstract post-grab account map + `catBiteSourceFessNoCodeRevert`. Dual of `catBiteRevertFessFail`. -/ theorem catBiteRevertFessNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {σ' σu σg : AccountMap} {A' Au Ag : Substate} @@ -5221,13 +5221,13 @@ theorem catBiteRevertFessNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 (hurn : biteAddrMaskWord.land (biteAddrMaskWord.land (calldataWord I.calldata 36)) = biteUrnWord I) (hilkslen : 160 ≤ o'.size) (hurnslen : 64 ≤ ou.size) (hlive : catSlotWord ⟨2⟩ σu I = ⟨1⟩) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hGrabCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) (hFessCode : - Reasoning.Theory.uniswapExtCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -5293,12 +5293,12 @@ theorem catBiteRevertFessNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 have hposNe : ∀ w : UInt256, w ≠ ⟨0⟩ → 0 < w.toNat := fun w hw => Nat.pos_of_ne_zero (fun h => hw (uint256_toNat_eq_zero h)) have codePos : ∀ (e : EVM.State) (w : UInt256), - uniswapExtCodeSizeWord e.accountMap w ≠ ⟨0⟩ → + extCodeSizeWord e.accountMap w ≠ ⟨0⟩ → 0 < (UInt256.ofNat ((e.lookupAccount (AccountAddress.ofUInt256 w)).option 0 (fun acc => acc.code.size))).toNat := by intro e w hw - unfold uniswapExtCodeSizeWord at hw + unfold extCodeSizeWord at hw simp only [State.lookupAccount] cases hf : e.accountMap.find? (AccountAddress.ofUInt256 w) with | none => rw [hf] at hw; simp [Option.option] at hw @@ -5455,9 +5455,9 @@ theorem catBiteRevertFessNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 rw [← biteDartRateV_eq_of_equiv hEqU] simp only [biteDartRateV, hdartvB]; rfl have hGrabCodeS : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σus + ¬ Reasoning.Theory.extCodeSizeWord σus ((solcSlotWord σus I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩ := by - rw [slotEqUS ⟨3⟩, ← uniswapExtCodeSizeWord_accountMapEquiv hAmEq] + rw [slotEqUS ⟨3⟩, ← extCodeSizeWord_accountMapEquiv hAmEq] exact hGrabCode rw [hperm, ← htgtU, ← h1, ← h2, ← h3, ← h4, ← hdinkvBS, ← hdartvBS] at hGrabSolm @@ -5466,12 +5466,12 @@ theorem catBiteRevertFessNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 have hlive' : catSlotWord ⟨2⟩ eUrnS.accountMap eUrnS.executionEnv = ⟨1⟩ := by rw [← biteSlotEqOfEquiv hEqU ⟨2⟩]; exact hlive have codeZero : ∀ (e : EVM.State) (w : UInt256), - uniswapExtCodeSizeWord e.accountMap w = ⟨0⟩ → + extCodeSizeWord e.accountMap w = ⟨0⟩ → (UInt256.ofNat ((e.lookupAccount (AccountAddress.ofUInt256 w)).option 0 (fun acc => acc.code.size))).toNat = 0 := by intro e w hw - unfold uniswapExtCodeSizeWord at hw + unfold extCodeSizeWord at hw simp only [State.lookupAccount] cases hf : e.accountMap.find? (AccountAddress.ofUInt256 w) with | none => native_decide @@ -5524,7 +5524,7 @@ theorem catBiteRevertFessNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 rw [heGEam, u256_land_comm, ← hmask]; exact hFessCode have hrev : RDrev catBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := - RD.uniswapExtcodesizeGuardMissing (pc := ⟨2284⟩) (okPc := ⟨2296⟩) rd2284 hFessCode + RD.solcExtcodesizeGuardMissing (pc := ⟨2284⟩) (okPc := ⟨2296⟩) rd2284 hFessCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) hov2 @@ -5536,7 +5536,7 @@ set_option maxHeartbeats 4000000 in /-- **kick no-code branch (extracted).** grab+fess succeed, litter is stored, but the `EXTCODESIZE(flip)` guard before the `flip.kick(...)` CALL is false (empty code), so the EVM reverts at pc `2516` before any call. Maps the 4-call chain + the litter SSTORE, fires the generic -`RD.uniswapExtcodesizeGuardMissing` at the post-SSTORE account map + `catBiteSourceKickNoCodeRevert`. +`RD.solcExtcodesizeGuardMissing` at the post-SSTORE account map + `catBiteSourceKickNoCodeRevert`. Dual of `catBiteRevertKickFail`. -/ theorem catBiteRevertKickNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {σ' σu σg σf : AccountMap} {A' Au Ag Af : Substate} @@ -5556,15 +5556,15 @@ theorem catBiteRevertKickNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 (hurn : biteAddrMaskWord.land (biteAddrMaskWord.land (calldataWord I.calldata 36)) = biteUrnWord I) (hilkslen : 160 ≤ o'.size) (hurnslen : 64 ≤ ou.size) (hlive : catSlotWord ⟨2⟩ σu I = ⟨1⟩) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hGrabCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) (hFessCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) (hKickCode : - Reasoning.Theory.uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σf ⟨6⟩ litterNew) + Reasoning.Theory.extCodeSizeWord (sstoreAccountMap I.codeOwner σf ⟨6⟩ litterNew) (biteAddrMaskWord.land flipW) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) @@ -5646,12 +5646,12 @@ theorem catBiteRevertKickNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 have hposNe : ∀ w : UInt256, w ≠ ⟨0⟩ → 0 < w.toNat := fun w hw => Nat.pos_of_ne_zero (fun h => hw (uint256_toNat_eq_zero h)) have codePos : ∀ (e : EVM.State) (w : UInt256), - uniswapExtCodeSizeWord e.accountMap w ≠ ⟨0⟩ → + extCodeSizeWord e.accountMap w ≠ ⟨0⟩ → 0 < (UInt256.ofNat ((e.lookupAccount (AccountAddress.ofUInt256 w)).option 0 (fun acc => acc.code.size))).toNat := by intro e w hw - unfold uniswapExtCodeSizeWord at hw + unfold extCodeSizeWord at hw simp only [State.lookupAccount] cases hf : e.accountMap.find? (AccountAddress.ofUInt256 w) with | none => rw [hf] at hw; simp [Option.option] at hw @@ -5822,9 +5822,9 @@ theorem catBiteRevertKickNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 have htabBS : biteTabV I eUrnS iRate art = tab := by rw [← biteTabV_eq_of_equiv hEqU]; exact htabB have hGrabCodeS : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σus + ¬ Reasoning.Theory.extCodeSizeWord σus ((solcSlotWord σus I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩ := by - rw [slotEqUS ⟨3⟩, ← uniswapExtCodeSizeWord_accountMapEquiv hAmEq] + rw [slotEqUS ⟨3⟩, ← extCodeSizeWord_accountMapEquiv hAmEq] exact hGrabCode rw [hperm, ← htgtU, ← h1, ← h2, ← h3, ← h4, ← hdinkvBS, ← hdartvBS] at hGrabSolm @@ -5872,12 +5872,12 @@ theorem catBiteRevertKickNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 have hLitValEq : litterNew = hLitVal := hlitternewE.symm.trans (biteLitterNewV_eq_of_equiv hEqU hEqFess iRate art) have codeZero : ∀ (e : EVM.State) (w : UInt256), - uniswapExtCodeSizeWord e.accountMap w = ⟨0⟩ → + extCodeSizeWord e.accountMap w = ⟨0⟩ → (UInt256.ofNat ((e.lookupAccount (AccountAddress.ofUInt256 w)).option 0 (fun acc => acc.code.size))).toNat = 0 := by intro e w hw - unfold uniswapExtCodeSizeWord at hw + unfold extCodeSizeWord at hw simp only [State.lookupAccount] cases hf : e.accountMap.find? (AccountAddress.ofUInt256 w) with | none => native_decide @@ -5904,7 +5904,7 @@ theorem catBiteRevertKickNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 (fun acc => acc.code.size))).toNat = 0 := by rw [hflipAddrS] refine codeZero eLitS (biteAddrMaskWord.land flipW) ?_ - rw [heLSam, ← uniswapExtCodeSizeWord_accountMapEquiv + rw [heLSam, ← extCodeSizeWord_accountMapEquiv (accountMapEquiv_sstoreAccountMap I.codeOwner ⟨6⟩ hLitVal hEqFess.accountMap), ← hLitValEq] exact hKickCode @@ -5958,7 +5958,7 @@ theorem catBiteRevertKickNoCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 hlitFB, htabB]; exact hLitFit have hrev : RDrev catBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := - RD.uniswapExtcodesizeGuardMissing (pc := ⟨2516⟩) (okPc := ⟨2528⟩) rd2516 hKickCode + RD.solcExtcodesizeGuardMissing (pc := ⟨2516⟩) (okPc := ⟨2528⟩) rd2516 hKickCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) hov3 @@ -5995,7 +5995,7 @@ theorem RD.catBiteCheckedAddRevert {cA gh bl σ σ₀ A I} {g : Sat256} rw [show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rd3810 have rd3813 := rd3810.push2 ⟨3756⟩ (by native_decide) (by evm_ov) have rd3814 := rd3813.jumpiNT (by native_decide) rfl (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd3814 + exact RD.solcPush1Dup1Revert0 rd3814 (by native_decide) (by native_decide) (by native_decide) (by evm_ov) set_option maxHeartbeats 4000000 in @@ -6023,13 +6023,13 @@ theorem catBiteRevertLitterAdd {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (hurn : biteAddrMaskWord.land (biteAddrMaskWord.land (calldataWord I.calldata 36)) = biteUrnWord I) (hilkslen : 160 ≤ o'.size) (hurnslen : 64 ≤ ou.size) (hlive : catSlotWord ⟨2⟩ σu I = ⟨1⟩) - (hvatCode : ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + (hvatCode : ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hGrabCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σu ((solcSlotWord σu I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩) (hFessCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σg (biteAddrMaskWord.land (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -6111,12 +6111,12 @@ theorem catBiteRevertLitterAdd {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hposNe : ∀ w : UInt256, w ≠ ⟨0⟩ → 0 < w.toNat := fun w hw => Nat.pos_of_ne_zero (fun h => hw (uint256_toNat_eq_zero h)) have codePos : ∀ (e : EVM.State) (w : UInt256), - uniswapExtCodeSizeWord e.accountMap w ≠ ⟨0⟩ → + extCodeSizeWord e.accountMap w ≠ ⟨0⟩ → 0 < (UInt256.ofNat ((e.lookupAccount (AccountAddress.ofUInt256 w)).option 0 (fun acc => acc.code.size))).toNat := by intro e w hw - unfold uniswapExtCodeSizeWord at hw + unfold extCodeSizeWord at hw simp only [State.lookupAccount] cases hf : e.accountMap.find? (AccountAddress.ofUInt256 w) with | none => rw [hf] at hw; simp [Option.option] at hw @@ -6287,9 +6287,9 @@ theorem catBiteRevertLitterAdd {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have htabBS : biteTabV I eUrnS iRate art = tab := by rw [← biteTabV_eq_of_equiv hEqU]; exact htabB have hGrabCodeS : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σus + ¬ Reasoning.Theory.extCodeSizeWord σus ((solcSlotWord σus I ⟨3⟩).land biteAddrMaskWord) = ⟨0⟩ := by - rw [slotEqUS ⟨3⟩, ← uniswapExtCodeSizeWord_accountMapEquiv hAmEq] + rw [slotEqUS ⟨3⟩, ← extCodeSizeWord_accountMapEquiv hAmEq] exact hGrabCode rw [hperm, ← htgtU, ← h1, ← h2, ← h3, ← h4, ← hdinkvBS, ← hdartvBS] at hGrabSolm diff --git a/Benchmarks/Dss/Cat/BiteSuccessBranch.lean b/Benchmarks/Dss/Cat/BiteSuccessBranch.lean index 08dcb3b7..d81e9c12 100644 --- a/Benchmarks/Dss/Cat/BiteSuccessBranch.lean +++ b/Benchmarks/Dss/Cat/BiteSuccessBranch.lean @@ -24,7 +24,7 @@ arithmetic bounds, the storage reads) from the σ_evm states to the `accountMapE coupled σ_solm states, then invoking `catBiteSuccessLeaf`. That transfer is the single remaining step (the one remaining gap below): every needed coupling accessor is green (`EVMStateEquiv.{accountMap,executionEnv,createdAccounts,storageLoad_codeOwner}`, -`accountMapEquiv_storage_findD`, `uniswapExtCodeSizeWord_accountMapEquiv`, +`accountMapEquiv_storage_findD`, `extCodeSizeWord_accountMapEquiv`, `typedCallViaEVM_static_storage_findD_of_accountMapEquiv`), and the values coincide because the mapped calls return the identical `out`/`z`, so the decode lemmas give equal `iRate`/`ink`/… on both sides. diff --git a/Benchmarks/Dss/Cat/BiteTrace.lean b/Benchmarks/Dss/Cat/BiteTrace.lean index c2df9774..5e27409b 100644 --- a/Benchmarks/Dss/Cat/BiteTrace.lean +++ b/Benchmarks/Dss/Cat/BiteTrace.lean @@ -283,7 +283,7 @@ theorem RD.catBiteIlksStaticcall (target :: target :: catBiteIlksOutPtr :: catBiteIlksInSize :: catBiteIlksOutPtr :: catBiteIlksOutSize :: t) mem aw o (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hencode : config.externalABI.encode? "ilks" args = some (mem.readWithPadding catBiteIlksOutPtr.toNat catBiteIlksInSize.toNat)) @@ -302,12 +302,12 @@ theorem RD.catBiteIlksStaticcall accountMap := σ', substate := A', createdAccounts := cA' }, o') false ∧ o'.size < UInt256.size := by obtain ⟨gasWord, _, _, rd1248⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1233⟩) (okPc := ⟨1245⟩) rd hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨1233⟩) (okPc := ⟨1245⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) obtain ⟨cA', σ', z, o', A_in, callGas, k', C', hΘpack, rd1249, hosz⟩ := - RD.uniswapStaticcall rd1248 (by native_decide) hdepth (by omega) + RD.solcStaticcall rd1248 (by native_decide) hdepth (by omega) obtain ⟨g'', A', hΘ⟩ := hΘpack refine ⟨cA', σ', z, o', A', _, k', C', rd1249, ?_, hosz⟩ refine callCoincides (A_in := A_in) (g'' := g'') (callGas := callGas) @@ -334,7 +334,7 @@ theorem catBiteTraceSeg1 {cA gh bl σ σ₀ A I} {g : UInt256} (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1163⟩ (urn :: biteIlkWord I :: R) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (catBiteVatTargetWord σ I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (catBiteVatTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hov : R.length + 17 ≤ 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) @@ -389,7 +389,7 @@ theorem catBiteTraceSeg2a {cA gh bl σ σ₀ A I} {g : UInt256} (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1289⟩ (⟨128⟩ :: rest) mem aw o' acc k' C' := by obtain ⟨_, _, rd1267⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨1249⟩) (okPc := ⟨1265⟩) rd hstatus + RD.solcCallSuccessGuardOk (pc := ⟨1249⟩) (okPc := ⟨1265⟩) rd hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -668,7 +668,7 @@ theorem RD.catBiteUrnsStaticcallGen (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1383⟩ (target :: target :: outPtr :: ⟨68⟩ :: outPtr :: ⟨64⟩ :: R) mem aw o (cAx, σx) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σx target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σx target ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hencode : config.externalABI.encode? "urns" args = some (mem.readWithPadding outPtr.toNat 68)) @@ -688,12 +688,12 @@ theorem RD.catBiteUrnsStaticcallGen accountMap := σ', substate := A', createdAccounts := cA' }, o') false ∧ o'.size < UInt256.size := by obtain ⟨gasWord, _, _, rd1398⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1383⟩) (okPc := ⟨1395⟩) rd hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨1383⟩) (okPc := ⟨1395⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) obtain ⟨cA', σ', z, o', A_in, callGas, k', C', hΘpack, rd1399, hosz⟩ := - RD.uniswapStaticcall rd1398 (by native_decide) hdepth (by omega) + RD.solcStaticcall rd1398 (by native_decide) hdepth (by omega) obtain ⟨g'', A', hΘ⟩ := hΘpack refine ⟨cA', σ', z, o', A', _, k', C', rd1399, ?_, hosz⟩ refine callCoincides (A_in := A_in) (g'' := g'') (callGas := callGas) @@ -1827,7 +1827,7 @@ theorem catBiteTraceGrabBuild {cA gh bl σ σ₀ A I} {g : UInt256} have rd2116 := RD.mstore _ (catBiteGrabUrnMemP p ilk urn mem) (catBiteAwStep aw (p + ⟨36⟩).toNat) rd2115 (by native_decide) catBiteMstoreCostM rfl hcol3 (by evm_ov) -- 2117 → 2122 : address(this), MSTORE #4 @ p+68 - have rd2117 := rd2116.uniswapAddress (by native_decide) (by evm_ov) + have rd2117 := rd2116.address (by native_decide) (by evm_ov) have rd2118 := rd2117.push1 ⟨68⟩ (by native_decide) (by evm_ov) have rd2120 := rd2118.dup6 (by native_decide) (by evm_ov) have rd2121 := rd2120.add (by native_decide) (by evm_ov) @@ -2040,7 +2040,7 @@ theorem RD.catBiteGrabCallGen {cA gh bl σ σ₀ A I} {g : UInt256} {args : List (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨2177⟩ (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: ⟨0⟩ :: R) mem aw rdata (cAx, σx) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σx target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σx target ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hencode : config.externalABI.encode? "grab" args = some (mem.readWithPadding inOff.toNat inSize.toNat)) @@ -2058,7 +2058,7 @@ theorem RD.catBiteGrabCallGen {cA gh bl σ σ₀ A I} {g : UInt256} {args : List accountMap := σ', substate := A', createdAccounts := cA' }, o') I.perm ∧ o'.size < UInt256.size := by obtain ⟨gasWord, _, _, rd2192⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2177⟩) (okPc := ⟨2189⟩) rd hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨2177⟩) (okPc := ⟨2189⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -2086,7 +2086,7 @@ theorem RD.catBiteFessCallGen {cA gh bl σ σ₀ A I} {g : UInt256} {args : List (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨2284⟩ (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: outSize :: R) mem aw rdata (cAx, σx) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σx target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σx target ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hencode : config.externalABI.encode? "fess" args = some (mem.readWithPadding inOff.toNat inSize.toNat)) @@ -2104,7 +2104,7 @@ theorem RD.catBiteFessCallGen {cA gh bl σ σ₀ A I} {g : UInt256} {args : List accountMap := σ', substate := A', createdAccounts := cA' }, o') I.perm ∧ o'.size < UInt256.size := by obtain ⟨gasWord, _, _, rd2299⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2284⟩) (okPc := ⟨2296⟩) rd hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨2284⟩) (okPc := ⟨2296⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -2548,7 +2548,7 @@ theorem catBiteTraceSeg8a {cA gh bl σ σ₀ A I} {g : UInt256} (haw292 : 292 ≤ aw.toNat * 32) (hmemsize : 292 ≤ mem.size) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σx (UInt256.land biteAddrMaskWord milkFlip) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σx (UInt256.land biteAddrMaskWord milkFlip) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hov : R.length + 40 ≤ 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) diff --git a/Benchmarks/Dss/Cat/BiteWalk.lean b/Benchmarks/Dss/Cat/BiteWalk.lean index 8b7050ea..03c2b1a9 100644 --- a/Benchmarks/Dss/Cat/BiteWalk.lean +++ b/Benchmarks/Dss/Cat/BiteWalk.lean @@ -92,9 +92,9 @@ theorem catBiteRevertUrnsDecode {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256 (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hdepth : (I.depth : ℕ) < 1024) (hvatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩) (hUrnsVatCode : - ¬ Reasoning.Theory.uniswapExtCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) + ¬ Reasoning.Theory.extCodeSizeWord σ' ((catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord) = ⟨0⟩) (hIlksCall : typedCallViaEVM config (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (AccountAddress.ofUInt256 (catBiteVatTargetWord σ_evm I)) "ilks" 0 [biteIlkVal I] @@ -162,7 +162,7 @@ theorem catBiteBodyImpl {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (transitionSignature biteTransition).paramTypes I.calldata = some (biteLocals I) := biteDecode_ok hsz68 by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_evm (catBiteVatTargetWord σ_evm I) = ⟨0⟩ · exact catBiteBodyIlksNoCode hcode hsize hwv hsel hsz68 hAccounts hdispatch hdecode hvatCode · -- vat has code. Spine walk begins at the ilks STATICCALL. by_cases hdepth : I.depth.val < 1024 @@ -198,7 +198,7 @@ theorem catBiteBodyImpl {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} UInt256.toNat_ofNat_of_lt (by rw [hval]; exact lt_of_lt_of_le (Nat.mod_lt _ (by positivity)) h2), hval] by_cases hUrnsVatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (UInt256.land (catSlotWord ⟨3⟩ σ' I) biteAddrMaskWord) = ⟨0⟩ · -- urns vat has no code: unreachable. The `vat.ilks` STATICCALL (`hIlksCall`, perm -- `false`) cannot change any account's code, so `vat` (read from slot 3, whose value @@ -207,7 +207,7 @@ theorem catBiteBodyImpl {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exfalso apply hvatCode have hcode1 : accountCodeStateEq σ_evm σ' := - typedCallViaEVM_static_accountCode_eq hIlksCall + typedCallViaEVM_static_accountCodeStateEq hIlksCall have hslot3ilks : catSlotWord ⟨3⟩ σ_evm I = catSlotWord ⟨3⟩ σ' I := by simp only [catSlotWord, solcSlotWord] exact accountStorageStateEq_storage_findD @@ -216,7 +216,7 @@ theorem catBiteBodyImpl {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} = (catSlotWord ⟨3⟩ σ' I).land biteAddrMaskWord := by have hmask : solcAddrMask = biteAddrMaskWord := by native_decide simp only [catBiteVatTargetWord, catAddressReturnWord, hslot3ilks, hmask] - rw [haddr, ← uniswapExtCodeSizeWord_eq_of_accountCodeStateEq _ hcode1] + rw [haddr, ← extCodeSizeWord_eq_of_accountCodeStateEq _ hcode1] exact hUrnsVatCode · obtain ⟨cAu, σu, zu, ou, Au, ku, Cu, rd1399, hUrnsCall, hoszu⟩ := catBiteReachPostUrnsAw rd1249 (by decide) hsz36 haw288 @@ -241,11 +241,11 @@ theorem catBiteBodyImpl {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rw [show EVM.addressModulus = AccountAddress.size from by decide] exact Nat.mod_eq_of_lt a.isLt have codePos : ∀ (e : EVM.State) (w : UInt256), - uniswapExtCodeSizeWord e.accountMap w ≠ ⟨0⟩ → + extCodeSizeWord e.accountMap w ≠ ⟨0⟩ → 0 < (UInt256.ofNat ((e.lookupAccount (AccountAddress.ofUInt256 w)).option 0 (fun acc => acc.code.size))).toNat := by intro e w hw - unfold uniswapExtCodeSizeWord at hw + unfold extCodeSizeWord at hw simp only [State.lookupAccount] cases hf : e.accountMap.find? (AccountAddress.ofUInt256 w) with | none => rw [hf] at hw; simp [Option.option] at hw @@ -288,7 +288,7 @@ theorem catBiteBodyImpl {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rw [heIam, show catBiteVatTargetWord σs I = (catSlotWord ⟨3⟩ σs I).land biteAddrMaskWord from by simp only [catBiteVatTargetWord, catAddressReturnWord, hmask], - ← hslot3, ← uniswapExtCodeSizeWord_accountMapEquiv hEqIlk.accountMap] + ← hslot3, ← extCodeSizeWord_accountMapEquiv hEqIlk.accountMap] exact hUrnsVatCode refine catBiteUrnsFailLeaf hcode hdispatch hdecode rd1399 hoszu (by simp only [List.length_cons, List.length_nil]; omega) ?_ @@ -573,7 +573,7 @@ theorem catBiteBodyImpl {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} native_decide] exact le_max_right _ _ by_cases hGrabCode : - Reasoning.Theory.uniswapExtCodeSizeWord σu + Reasoning.Theory.extCodeSizeWord σu (UInt256.land (solcSlotWord σu I ⟨3⟩) biteAddrMaskWord) = ⟨0⟩ · -- grab vat has no code: unreachable. Both the `ilks` -- (`hIlksCall`) and `urns` (`hUrnsCall`) STATICCALLs are perm @@ -584,9 +584,9 @@ theorem catBiteBodyImpl {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exfalso apply hvatCode have hcode1 : accountCodeStateEq σ_evm σ' := - typedCallViaEVM_static_accountCode_eq hIlksCall + typedCallViaEVM_static_accountCodeStateEq hIlksCall have hcode2 : accountCodeStateEq σ' σu := - typedCallViaEVM_static_accountCode_eq hUrnsCall + typedCallViaEVM_static_accountCodeStateEq hUrnsCall have hslot3ilks : catSlotWord ⟨3⟩ σ_evm I = catSlotWord ⟨3⟩ σ' I := by simp only [catSlotWord, solcSlotWord] exact accountStorageStateEq_storage_findD @@ -597,7 +597,7 @@ theorem catBiteBodyImpl {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hmask : solcAddrMask = biteAddrMaskWord := by native_decide simp only [catBiteVatTargetWord, catAddressReturnWord, hslot3ilks, hslot3, hmask] - rw [haddr, ← uniswapExtCodeSizeWord_eq_of_accountCodeStateEq _ + rw [haddr, ← extCodeSizeWord_eq_of_accountCodeStateEq _ (accountCodeStateEq_trans hcode1 hcode2)] exact hGrabCode · obtain ⟨cAg, σg, zg, og, Ag, kg, Cg, rd2193, hGrabCall, hoszg⟩ := @@ -649,7 +649,7 @@ theorem catBiteBodyImpl {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (UInt256.ofNat I.codeOwner.val) (solcSlotWord σu I ⟨4⟩) dink dart hpmemMilk (by native_decide) by_cases hFessCode : - Reasoning.Theory.uniswapExtCodeSizeWord σg + Reasoning.Theory.extCodeSizeWord σg (UInt256.land biteAddrMaskWord (solcSlotWord σg I ⟨4⟩)) = ⟨0⟩ · -- fess vow has no code → divergence leaf obtain ⟨_, _, rd2242f⟩ := @@ -853,7 +853,7 @@ theorem catBiteBodyImpl {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} hdartRateDef.symm htabBaseDef.symm htabDef.symm hlitterNewDef.symm -- STEP C: kick CALL reach (2383 → 2532), all at free ptr `p`. by_cases hKickCode : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (sstoreAccountMap I.codeOwner σf ⟨6⟩ litterNew) (UInt256.land biteAddrMaskWord flipW) = ⟨0⟩ · -- kick flip target has no code → divergence leaf @@ -1104,12 +1104,12 @@ theorem catBiteBodyImpl {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rw [show EVM.addressModulus = AccountAddress.size from by decide] exact Nat.mod_eq_of_lt a.isLt have codePos : ∀ (e : EVM.State) (w : UInt256), - uniswapExtCodeSizeWord e.accountMap w ≠ ⟨0⟩ → + extCodeSizeWord e.accountMap w ≠ ⟨0⟩ → 0 < (UInt256.ofNat ((e.lookupAccount (AccountAddress.ofUInt256 w)).option 0 (fun acc => acc.code.size))).toNat := by intro e w hw - unfold uniswapExtCodeSizeWord at hw + unfold extCodeSizeWord at hw simp only [State.lookupAccount] cases hf : e.accountMap.find? (AccountAddress.ofUInt256 w) with | none => rw [hf] at hw; simp [Option.option] at hw @@ -1366,13 +1366,13 @@ theorem catBiteBodyImpl {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} obtain ⟨k, C, rd1163⟩ := catReachBiteRoutine (g := Sat256.ofUInt256 g) hcode hwv hsz68 hsize hsel obtain ⟨_, _, rd1233⟩ := RD.catBiteIlksToStaticcallGuard (hR := by simp) rd1163 - obtain ⟨gasWord, _, _, rd1248⟩ := RD.uniswapExtcodesizeGuardOkGas + obtain ⟨gasWord, _, _, rd1248⟩ := RD.solcExtcodesizeGuardOkGas (pc := ⟨1233⟩) (okPc := ⟨1245⟩) rd1233 hvatCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp) obtain ⟨_, _, rd1249⟩ := - RD.uniswapStaticcallDepthLimit rd1248 (by native_decide) hdepth1024 (by simp) + RD.solcStaticcallDepthLimit rd1248 (by native_decide) hdepth1024 (by simp) have hbytes : biteIlkBytes I = EVM.Word.toBytesBE (biteIlkWord I) := by simpa [biteIlkBytes, biteIlkWord, biteUrnsIlkBytes, biteUrnsIlkWord] using biteUrnsIlkBytes_eq_toBytesBE (I := I) hsz36 diff --git a/Benchmarks/Dss/Cat/Claw.lean b/Benchmarks/Dss/Cat/Claw.lean index 8244ab59..dffa3bdf 100644 --- a/Benchmarks/Dss/Cat/Claw.lean +++ b/Benchmarks/Dss/Cat/Claw.lean @@ -97,7 +97,7 @@ theorem RD.catClawSubReverts {ee : ExecutionEnv} {g : Sat256} {s0 : State} raw iszero (by native_decide) (by evm_ov), raw push2 ⟨3756⟩ (by native_decide) (by evm_ov)] have rdRev := rdPre.jumpiNT (by native_decide) (by rw [hgt]; decide) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdRev + exact RD.solcPush1Dup1Revert0 rdRev (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) diff --git a/Benchmarks/Dss/Cat/Common.lean b/Benchmarks/Dss/Cat/Common.lean index 40d9aaa6..68ea76e6 100644 --- a/Benchmarks/Dss/Cat/Common.lean +++ b/Benchmarks/Dss/Cat/Common.lean @@ -34,23 +34,23 @@ The EVMLean static-storage/code projections exposed through `Reasoning.ExternalC translate that account-address relation to the Uniswap code-size word helper used by the solc reach rules. -/ -/-- `uniswapExtCodeSizeWord` reads only an account's `.code` (as `ofNat · .code.size`), so it is a +/-- `extCodeSizeWord` reads only an account's `.code` (as `ofNat · .code.size`), so it is a function of `(σ.findD a default).code` — the projection `accountCodeStateEq` preserves. -/ -theorem uniswapExtCodeSizeWord_eq_ofNat_findD (σ : AccountMap) (target : UInt256) : - Reasoning.Theory.uniswapExtCodeSizeWord σ target +theorem extCodeSizeWord_eq_ofNat_findD (σ : AccountMap) (target : UInt256) : + Reasoning.Theory.extCodeSizeWord σ target = UInt256.ofNat (σ.findD (AccountAddress.ofUInt256 target) default).code.size := by - unfold Reasoning.Theory.uniswapExtCodeSizeWord + unfold Reasoning.Theory.extCodeSizeWord cases h : σ.find? (AccountAddress.ofUInt256 target) with | none => simp [Batteries.RBMap.findD, h, Option.option]; rfl | some acc => simp [Batteries.RBMap.findD, h, Option.option] -/-- Code preservation transfers to `uniswapExtCodeSizeWord`: static calls leave every account's +/-- Code preservation transfers to `extCodeSizeWord`: static calls leave every account's `EXTCODESIZE` word unchanged. -/ -theorem uniswapExtCodeSizeWord_eq_of_accountCodeStateEq {σ σ' : AccountMap} (target : UInt256) +theorem extCodeSizeWord_eq_of_accountCodeStateEq {σ σ' : AccountMap} (target : UInt256) (h : accountCodeStateEq σ σ') : - Reasoning.Theory.uniswapExtCodeSizeWord σ' target - = Reasoning.Theory.uniswapExtCodeSizeWord σ target := by - rw [uniswapExtCodeSizeWord_eq_ofNat_findD, uniswapExtCodeSizeWord_eq_ofNat_findD, + Reasoning.Theory.extCodeSizeWord σ' target + = Reasoning.Theory.extCodeSizeWord σ target := by + rw [extCodeSizeWord_eq_ofNat_findD, extCodeSizeWord_eq_ofNat_findD, (h (AccountAddress.ofUInt256 target)).symm] /-! ## Selector helpers -/ @@ -674,7 +674,7 @@ theorem catX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem catX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -697,7 +697,7 @@ theorem catX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h256 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h256 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) /-! ## Dispatch-failure (`dispatchMsg = none`) and non-payable body facts -/ @@ -784,7 +784,7 @@ theorem catJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : UInt25 have h256 := h.push2 catDispatchRevertPc hpush (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h256 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h256 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem catLowLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -800,7 +800,7 @@ theorem catLowLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} |>.selectorArmNotTakenAuto (catLowLowArmsWellFormed 2 (by omega)) (heq0 2 (by omega)) (by simp) |>.selectorArmNotTakenAuto (catLowLowArmsWellFormed 3 (by omega)) (heq0 3 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h256 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h256 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem catLowHighNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} diff --git a/Benchmarks/Dss/Cat/FileIlkFlip.lean b/Benchmarks/Dss/Cat/FileIlkFlip.lean index bb1434b9..d0c99884 100644 --- a/Benchmarks/Dss/Cat/FileIlkFlip.lean +++ b/Benchmarks/Dss/Cat/FileIlkFlip.lean @@ -226,14 +226,14 @@ theorem fifVatGuardFalse {evm : EVM.State} {locals : Store} simp [evalExpr?, EvalResult.bind, bind, biteVatRead hbase, evalBinaryOp?, EVM.Word.ofNat, hcode] theorem fifExtCodeSizeWord_eq (σ : AccountMap) (target : UInt256) : - uniswapExtCodeSizeWord σ target = + extCodeSizeWord σ target = UInt256.ofNat ((σ.find? (AccountAddress.ofUInt256 target)).option 0 (fun acc => acc.code.size)) := by - unfold uniswapExtCodeSizeWord + unfold extCodeSizeWord cases σ.find? (AccountAddress.ofUInt256 target) <;> rfl theorem fifVatCodeZero {cA gh bl σ σ₀ A I} {g : Sat256} - (hzero : uniswapExtCodeSizeWord σ (fifVatM σ I) = ⟨0⟩) : + (hzero : extCodeSizeWord σ (fifVatM σ I) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ g A I).lookupAccount (biteVatAddr (initState cA gh bl σ σ₀ g A I))).option 0 (fun acc => acc.code.size))).toNat = 0 := by rw [show (initState cA gh bl σ σ₀ g A I).lookupAccount @@ -243,7 +243,7 @@ theorem fifVatCodeZero {cA gh bl σ σ₀ A I} {g : Sat256} rw [← fifExtCodeSizeWord_eq, hzero]; rfl theorem fifVatCodePos {cA gh bl σ σ₀ A I} {g : Sat256} - (hne : uniswapExtCodeSizeWord σ (fifVatM σ I) ≠ ⟨0⟩) : + (hne : extCodeSizeWord σ (fifVatM σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ g A I).lookupAccount (biteVatAddr (initState cA gh bl σ σ₀ g A I))).option 0 (fun acc => acc.code.size))).toNat := by rw [show (initState cA gh bl σ σ₀ g A I).lookupAccount @@ -256,7 +256,7 @@ theorem fifVatCodePos {cA gh bl σ σ₀ A I} {g : Sat256} theorem fifVatCodeZeroGen {evm : EVM.State} {target : UInt256} (haddr : biteVatAddr evm = AccountAddress.ofUInt256 target) - (hzero : uniswapExtCodeSizeWord evm.accountMap target = ⟨0⟩) : + (hzero : extCodeSizeWord evm.accountMap target = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (biteVatAddr evm)).option 0 (fun acc => acc.code.size))).toNat = 0 := by rw [haddr, show evm.lookupAccount (AccountAddress.ofUInt256 target) = @@ -265,7 +265,7 @@ theorem fifVatCodeZeroGen {evm : EVM.State} {target : UInt256} theorem fifVatCodePosGen {evm : EVM.State} {target : UInt256} (haddr : biteVatAddr evm = AccountAddress.ofUInt256 target) - (hne : uniswapExtCodeSizeWord evm.accountMap target ≠ ⟨0⟩) : + (hne : extCodeSizeWord evm.accountMap target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (biteVatAddr evm)).option 0 (fun acc => acc.code.size))).toNat := by rw [haddr, show evm.lookupAccount (AccountAddress.ofUInt256 target) = @@ -309,9 +309,9 @@ theorem RD.catFileIlkFlipHopeNoCodeGen {cA gh bl σ σ₀ A I} {g : Sat256} {fli ⟨2746363844⟩ :: fifVat2M σ' I :: flip :: fileIlkFlipWhatWord I :: fileIlkFlipIlkWord I :: ret :: sel :: []) (fifHopeCdMem mem (UInt256.land flip solcAddrMask)) (UInt256.ofNat 6) rdata (cA', σ') k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ' (fifVat2M σ' I) = ⟨0⟩) : + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ' (fifVat2M σ' I) = ⟨0⟩) : RDrev catBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3679⟩) (okPc := ⟨3691⟩) rd hcodeSize + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3679⟩) (okPc := ⟨3691⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp) @@ -324,7 +324,7 @@ theorem RD.catFileIlkFlipHopePostCallGen {cA gh bl σ σ₀ A I} {g : Sat256} {f ret :: sel :: []) (fifHopeCdMem mem (UInt256.land flip solcAddrMask)) (UInt256.ofNat 6) rdata (cA', σ') k C) (hmem : mem.size = 164) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ' (fifVat2M σ' I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ' (fifVat2M σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hperm : I.perm = true) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) @@ -341,7 +341,7 @@ theorem RD.catFileIlkFlipHopePostCallGen {cA gh bl σ σ₀ A I} {g : Sat256} {f accountMap := σ'', substate := A'', createdAccounts := cA'' }, out) true ∧ out.size < UInt256.size := by obtain ⟨gasWord, k1, C1, rd3694⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3679⟩) (okPc := ⟨3691⟩) rd hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨3679⟩) (okPc := ⟨3691⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp) @@ -384,11 +384,11 @@ theorem RD.catFileIlkFlipNopeDepthLimit {cA gh bl σ σ₀ A I} {g : Sat256} {fl ⟨3696042234⟩ :: fifVatM σ I :: flip :: fileIlkFlipWhatWord I :: fileIlkFlipIlkWord I :: ret :: sel :: []) (fifNopeCdMem I (fifNopeArg σ I)) (UInt256.ofNat 6) ByteArray.empty (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (fifVatM σ I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (fifVatM σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : RDrev catBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨gasWord, k1, C1, rd3561⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3546⟩) (okPc := ⟨3558⟩) rd hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨3546⟩) (okPc := ⟨3558⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp) @@ -943,20 +943,20 @@ theorem catFileIlkFlipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hVat3 : solcSlotWord σ_evm I ⟨3⟩ = solcSlotWord σ_solm I ⟨3⟩ := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨3⟩ ⟨0⟩ have hVatM : fifVatM σ_evm I = fifVatM σ_solm I := by unfold fifVatM; rw [hVat3] - have hcodeEq : uniswapExtCodeSizeWord σ_evm (fifVatM σ_evm I) = - uniswapExtCodeSizeWord σ_solm (fifVatM σ_solm I) := - (uniswapExtCodeSizeWord_accountMapEquiv hAccounts (fifVatM σ_evm I)).trans - (congrArg (uniswapExtCodeSizeWord σ_solm) hVatM) - by_cases hcodeNope : uniswapExtCodeSizeWord σ_evm (fifVatM σ_evm I) = ⟨0⟩ + have hcodeEq : extCodeSizeWord σ_evm (fifVatM σ_evm I) = + extCodeSizeWord σ_solm (fifVatM σ_solm I) := + (extCodeSizeWord_accountMapEquiv hAccounts (fifVatM σ_evm I)).trans + (congrArg (extCodeSizeWord σ_solm) hVatM) + by_cases hcodeNope : extCodeSizeWord σ_evm (fifVatM σ_evm I) = ⟨0⟩ · -- vat has no code → both sides revert at the nope guard - have hcodeSolm : uniswapExtCodeSizeWord σ_solm (fifVatM σ_solm I) = ⟨0⟩ := + have hcodeSolm : extCodeSizeWord σ_solm (fifVatM σ_solm I) = ⟨0⟩ := hcodeEq.symm.trans hcodeNope exact (RD.catFileIlkFlipNopeNoCode rd3546 hcodeNope).reEquivExecutionRevert hcode hdispatch hdecode (fileIlkFlipNopeNoCodeSource (σ := σ_solm) hwv hauthSolm hflip (fifVatCodeZero hcodeSolm)) · -- vat has code - have hcodeSolmNe : uniswapExtCodeSizeWord σ_solm (fifVatM σ_solm I) ≠ ⟨0⟩ := + have hcodeSolmNe : extCodeSizeWord σ_solm (fifVatM σ_solm I) ≠ ⟨0⟩ := fun h => hcodeNope (hcodeEq.trans h) have hIlksAgree : solcSlotWord σ_evm I (solcMappingSlot ⟨1⟩ (fileIlkFlipIlkWord I)) = @@ -1067,9 +1067,9 @@ theorem catFileIlkFlipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} solcSlotWord σStore I ⟨3⟩ = solcSlotWord evmStoreSolm.accountMap I ⟨3⟩ := accountMapEquiv_storage_findD hAccountsStore I.codeOwner ⟨3⟩ ⟨0⟩ have hHopeCode : - uniswapExtCodeSizeWord evmStoreSolm.accountMap (fifVat2M σStore I) = - uniswapExtCodeSizeWord σStore (fifVat2M σStore I) := - (uniswapExtCodeSizeWord_accountMapEquiv hAccountsStore (fifVat2M σStore I)).symm + extCodeSizeWord evmStoreSolm.accountMap (fifVat2M σStore I) = + extCodeSizeWord σStore (fifVat2M σStore I) := + (extCodeSizeWord_accountMapEquiv hAccountsStore (fifVat2M σStore I)).symm have hHopeTarget : biteVatAddr evmStoreSolm = AccountAddress.ofUInt256 (fifVat2M σStore I) := by have hinner : @@ -1085,7 +1085,7 @@ theorem catFileIlkFlipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} solcAddrMask).toNat = AccountAddress.ofNat (fifVat2M σStore I).toNat rw [hinner] rw [← hVatAddrBridge, ← hNopeArgCoupling] at hcallNope_solm - by_cases hcodeHope : uniswapExtCodeSizeWord σStore (fifVat2M σStore I) = ⟨0⟩ + by_cases hcodeHope : extCodeSizeWord σStore (fifVat2M σStore I) = ⟨0⟩ · -- vat has no code at the hope call → both sides revert at the hope guard exact (RD.catFileIlkFlipHopeNoCodeGen rd3679 hcodeHope).reEquivExecutionRevert hcode hdispatch hdecode @@ -1095,7 +1095,7 @@ theorem catFileIlkFlipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} · obtain ⟨cA'', σ'', z2, out2, A'', k2, C2, rd3695, hcallHope_evm, hout2sz⟩ := RD.catFileIlkFlipHopePostCallGen rd3679 hStoreMem164 hcodeHope hdepth hperm have hcodeStoreSolmNe : - uniswapExtCodeSizeWord evmStoreSolm.accountMap (fifVat2M σStore I) ≠ ⟨0⟩ := + extCodeSizeWord evmStoreSolm.accountMap (fifVat2M σStore I) ≠ ⟨0⟩ := fun h => hcodeHope (hHopeCode.symm.trans h) -- bridge the EVM hope CALL target/arg to the Solm-source forms have hcanon2 : (fifVat2M σStore I).toNat < EVM.addressModulus := by diff --git a/Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean b/Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean index 21de0a5f..c1678d16 100644 --- a/Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean +++ b/Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean @@ -112,7 +112,7 @@ theorem RD.catFileIlkFlipNopePostCall {cA gh bl σ σ₀ A I} {g : Sat256} {flip ⟨3696042234⟩ :: fifVatM σ I :: flip :: fileIlkFlipWhatWord I :: fileIlkFlipIlkWord I :: ret :: sel :: []) (fifNopeCdMem I (fifNopeArg σ I)) (UInt256.ofNat 6) ByteArray.empty (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (fifVatM σ I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (fifVatM σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hperm : I.perm = true) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) @@ -128,7 +128,7 @@ theorem RD.catFileIlkFlipNopePostCall {cA gh bl σ σ₀ A I} {g : Sat256} {flip accountMap := σ', substate := A', createdAccounts := cA' }, out) true ∧ out.size < UInt256.size := by obtain ⟨gasWord, k1, C1, rd3561⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3546⟩) (okPc := ⟨3558⟩) rd hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨3546⟩) (okPc := ⟨3558⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp) @@ -169,9 +169,9 @@ theorem RD.catFileIlkFlipNopeNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {flip r ⟨3696042234⟩ :: fifVatM σ I :: flip :: fileIlkFlipWhatWord I :: fileIlkFlipIlkWord I :: ret :: sel :: []) (fifNopeCdMem I (fifNopeArg σ I)) (UInt256.ofNat 6) ByteArray.empty (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (fifVatM σ I) = ⟨0⟩) : + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (fifVatM σ I) = ⟨0⟩) : RDrev catBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3546⟩) (okPc := ⟨3558⟩) rd hcodeSize + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3546⟩) (okPc := ⟨3558⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp) @@ -185,7 +185,7 @@ theorem RD.catFileIlkFlipNopeCallFailure {cA gh bl σ σ₀ A I} {g : Sat256} mem aw rdata acc k C) (hrdataSize : rdata.size < UInt256.size) : RDrev catBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3562⟩) (okPc := ⟨3578⟩) rd rfl + exact RD.solcCallSuccessGuardMissing (pc := ⟨3562⟩) (okPc := ⟨3578⟩) rd rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -202,7 +202,7 @@ theorem RD.catFileIlkFlipNopeCallSuccessToStore {cA gh bl σ σ₀ A I} {g : Sat (fifVatM σ I :: flip :: fileIlkFlipWhatWord I :: fileIlkFlipIlkWord I :: ret :: sel :: []) mem aw rdata acc k' C' := by obtain ⟨k1, C1, rd3580⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨3562⟩) (okPc := ⟨3578⟩) rd + RD.solcCallSuccessGuardOk (pc := ⟨3562⟩) (okPc := ⟨3578⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp) @@ -534,7 +534,7 @@ theorem RD.catFileIlkFlipHopePostCall {cA gh bl σ σ₀ A I} {g : Sat256} {flip (fifHopeCdMem mem (UInt256.land flip solcAddrMask)) (UInt256.ofNat 6) ByteArray.empty (cA', σ') k C) (hmem : mem.size = 164) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ' (fifVat2M σ' I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ' (fifVat2M σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hperm : I.perm = true) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) @@ -551,7 +551,7 @@ theorem RD.catFileIlkFlipHopePostCall {cA gh bl σ σ₀ A I} {g : Sat256} {flip accountMap := σ'', substate := A'', createdAccounts := cA'' }, out) true ∧ out.size < UInt256.size := by obtain ⟨gasWord, k1, C1, rd3694⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3679⟩) (okPc := ⟨3691⟩) rd hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨3679⟩) (okPc := ⟨3691⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp) @@ -593,9 +593,9 @@ theorem RD.catFileIlkFlipHopeNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {flip r ret :: sel :: []) (fifHopeCdMem mem (UInt256.land flip solcAddrMask)) (UInt256.ofNat 6) ByteArray.empty (cA', σ') k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ' (fifVat2M σ' I) = ⟨0⟩) : + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ' (fifVat2M σ' I) = ⟨0⟩) : RDrev catBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3679⟩) (okPc := ⟨3691⟩) rd hcodeSize + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3679⟩) (okPc := ⟨3691⟩) rd hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp) @@ -609,7 +609,7 @@ theorem RD.catFileIlkFlipHopeCallFailure {cA gh bl σ σ₀ A I} {g : Sat256} mem aw rdata acc k C) (hrdataSize : rdata.size < UInt256.size) : RDrev catBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3695⟩) (okPc := ⟨3711⟩) rd rfl + exact RD.solcCallSuccessGuardMissing (pc := ⟨3695⟩) (okPc := ⟨3711⟩) rd rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -624,7 +624,7 @@ theorem RD.catFileIlkFlipHopeCallSuccess {cA gh bl σ σ₀ A I} {g : Sat256} mem aw rdata acc k C) : RDret catBytecode g (initState cA gh bl σ σ₀ g A I) acc ByteArray.empty := by obtain ⟨_, _, rd3713⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨3695⟩) (okPc := ⟨3711⟩) rd + RD.solcCallSuccessGuardOk (pc := ⟨3695⟩) (okPc := ⟨3711⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp) diff --git a/Benchmarks/Dss/Cat/SpecSyntax.lean b/Benchmarks/Dss/Cat/SpecSyntax.lean index 68ae508e..91b09274 100644 --- a/Benchmarks/Dss/Cat/SpecSyntax.lean +++ b/Benchmarks/Dss/Cat/SpecSyntax.lean @@ -2,19 +2,208 @@ import Benchmarks.Dss.Cat.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS Cat spec through the Solm notation frontend +# Cat spec in the Solidity-faithful Solm frontend -The main spec lives in `Spec.lean`; this companion keeps the benchmark's notation-side check wired -up as the body surface grows. +The whole `cat.sol` spec written with `solidity%` and proven definitionally equal to the AST +spec in `Spec.lean`. Checked-math helper stmt-lists and the extCodeSize-guarded external calls +are inlined as surface statements; `file` keys are big-endian `bytes32` literals. Transition +order matches `contract.transitions` (selector order). -/ open Solm Solm.Notation namespace Benchmarks.Dss.Cat.Syntax -def contractSyntax : ContractDecl := Benchmarks.Dss.Cat.contract +def contractSyntax : ContractDecl := solidity% contract Cat { + mapping(address => uint256) wards; + mapping(bytes32 => Ilk) ilks; + uint256 live; + address vat; + address vow; + uint256 box; + uint256 litter; -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Cat.contract := by - rfl + struct Ilk { + address flip; + uint256 chop; + uint256 dunk; + } + + constructor(address vat_) { + wards[msg.sender] = 1; + vat = vat_; + live = 1; + } + + function min(uint256 x, uint256 y) internal returns (uint256) { + if (x > y) { + return y; + } else { + return x; + } + } + + function add(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x + y) as uint256; + require(z >= x); + return z; + } + + function sub(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x - y) as uint256; + require(z <= x); + return z; + } + + function mul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + return z; + } + + function bite(bytes32 ilk, address urn) external returns (uint256) { + require(vat.code.length > 0); + var vatIlk = vat.ilks{view}(ilk); + uint256 rate = vatIlk.1; + uint256 spot = vatIlk.2; + uint256 dust = vatIlk.4; + require(vat.code.length > 0); + var vatUrn = vat.urns{view}(ilk, urn); + uint256 ink = vatUrn.0; + uint256 art = vatUrn.1; + require(live == 1); + uint256 inkSpot = (ink * spot) as uint256; + require(spot == 0 || inkSpot / spot == ink); + uint256 artRateUnsafe = (art * rate) as uint256; + require(rate == 0 || artRateUnsafe / rate == art); + require(spot > 0 && inkSpot < artRateUnsafe); + address milkFlip = ilks[ilk].flip; + uint256 milkChop = ilks[ilk].chop; + uint256 milkDunk = ilks[ilk].dunk; + uint256 room = (box - litter) as uint256; + require(room <= box); + require(litter < box && room >= dust); + var dunkRoom = min(milkDunk, room); + uint256 dunkRoomWad = (dunkRoom * #WAD) as uint256; + require(#WAD == 0 || dunkRoomWad / #WAD == dunkRoom); + uint256 dartDenomRate = dunkRoomWad / rate; + uint256 dartCandidate = dartDenomRate / milkChop; + var dart = min(art, dartCandidate); + uint256 inkDart = (ink * dart) as uint256; + require(dart == 0 || inkDart / dart == ink); + uint256 dinkCandidate = inkDart / art; + var dink = min(ink, dinkCandidate); + require(dart > 0 && dink > 0); + require(dart <= #int256Limit && dink <= #int256Limit); + require(vat.code.length > 0); + var _grabRet = vat.grab(ilk, urn, address(this), vow, -int256(dink), -int256(dart)); + uint256 dartRate = (dart * rate) as uint256; + require(rate == 0 || dartRate / rate == dart); + require(vow.code.length > 0); + var _fessRet = vow.fess(dartRate); + uint256 tabBase = (dartRate * milkChop) as uint256; + require(milkChop == 0 || tabBase / milkChop == dartRate); + uint256 tab = tabBase / #WAD; + uint256 litterNew = (litter + tab) as uint256; + require(litterNew >= litter); + litter = litterNew; + require(milkFlip.code.length > 0); + var id = milkFlip.kick(urn, vow, tab, dink, 0); + return id; + } + + function box() external returns (uint256) { + return box; + } + + function cage() external { + require(wards[msg.sender] == 1); + live = 0; + } + + function claw(uint256 rad) external { + require(wards[msg.sender] == 1); + var litterNew = sub(litter, rad); + litter = litterNew; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function file(bytes32 what, address data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x766f770000000000000000000000000000000000000000000000000000000000)) { + vow = data; + } else { + require(false); + } + } + + function file(bytes32 ilk, bytes32 what, address flip) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x666c697000000000000000000000000000000000000000000000000000000000)) { + require(vat.code.length > 0); + var _nopeRet = vat.nope(ilks[ilk].flip); + ilks[ilk].flip = flip; + require(vat.code.length > 0); + var _hopeRet = vat.hope(flip); + } else { + require(false); + } + } + + function file(bytes32 ilk, bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x63686f7000000000000000000000000000000000000000000000000000000000)) { + ilks[ilk].chop = data; + } else if (what == bytes32(0x64756e6b00000000000000000000000000000000000000000000000000000000)) { + ilks[ilk].dunk = data; + } else { + require(false); + } + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x626f780000000000000000000000000000000000000000000000000000000000)) { + box = data; + } else { + require(false); + } + } + + function ilks(bytes32 arg0) external returns (address, uint256, uint256) { + return (ilks[arg0].flip, ilks[arg0].chop, ilks[arg0].dunk); + } + + function litter() external returns (uint256) { + return litter; + } + + function live() external returns (uint256) { + return live; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 1; + } + + function vat() external returns (address) { + return vat; + } + + function vow() external returns (address) { + return vow; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Cat.contract := by rfl end Benchmarks.Dss.Cat.Syntax diff --git a/Benchmarks/Dss/Clipper/Fallback.lean b/Benchmarks/Dss/Clipper/Fallback.lean index da9e1573..88189e3d 100644 --- a/Benchmarks/Dss/Clipper/Fallback.lean +++ b/Benchmarks/Dss/Clipper/Fallback.lean @@ -95,7 +95,7 @@ theorem clipperFallbackRevertAt {code : ByteArray} {ee : ExecutionEnv} {g : Sat2 change decode code (⟨463⟩ : UInt256) = some (.JUMPDEST, .none) clipper_decode) (by omega) - exact RD.uniswapPush1Dup1Revert0 h464 + exact RD.solcPush1Dup1Revert0 h464 (by change decode code ((⟨463⟩ : UInt256) + ⟨1⟩) = some (.Push .PUSH1, some (⟨0⟩, 1)) @@ -165,7 +165,7 @@ theorem clipperX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} (v : ClipperI native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 + exact RD.solcPush1Dup1Revert0 h12 (by change decode code (⟨12⟩ : UInt256) = some (.Push .PUSH1, some (⟨0⟩, 1)) @@ -262,7 +262,7 @@ theorem clipperX_short {cA gh bl σ σ₀ A I} {g : Sat256} (v : ClipperImmutabl rw [clipperDecodeBeforeFirstPatch v hpatch (⟨463⟩ : UInt256) (by native_decide)] native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h464 + exact RD.solcPush1Dup1Revert0 h464 (by rw [show ((⟨463⟩ : UInt256) + ⟨1⟩) = (⟨464⟩ : UInt256) from by native_decide] change decode code (⟨464⟩ : UInt256) = diff --git a/Benchmarks/Dss/Clipper/SpecSyntax.lean b/Benchmarks/Dss/Clipper/SpecSyntax.lean index 82eae538..dde70255 100644 --- a/Benchmarks/Dss/Clipper/SpecSyntax.lean +++ b/Benchmarks/Dss/Clipper/SpecSyntax.lean @@ -2,10 +2,15 @@ import Benchmarks.Dss.Clipper.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS Clipper spec through the Solm notation frontend +# Clipper spec in the Solidity-faithful Solm frontend -The main spec lives in `Spec.lean`; this companion keeps the benchmark's notation-side check wired -up as the body surface grows. +The whole `clip.sol` spec written with `solidity%` and proven definitionally equal to the AST +spec in `Spec.lean`. Checked DSMath helpers keep their inlined spec shapes (`(…) as uint256` +plus the overflow `require`), built-in wrapping arithmetic is the explicit `% #wordModulus` +(resp. `#uint96Modulus`/`#uint64Modulus`/`#uint192Modulus`), `bytes32` file keys are big-endian +ASCII literals, and immutable `vat`/`ilk` reads plus the external calls that target them are +spliced from the spec (`${vatExpr v}`, `${checkedExternalCallStmts …}`). Transition order +matches `contract.transitions` (selector order). -/ open Solm Solm.Notation @@ -13,10 +18,430 @@ open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper.Syntax -def contractSyntax (v : ClipperImmutables) : ContractDecl := Benchmarks.Dss.Clipper.contract v +def contractSyntax (v : ClipperImmutables) : ContractDecl := solidity% contract Clipper { + struct Sale { + uint256 pos; + uint256 tab; + uint256 lot; + address usr; + uint96 tic; + uint256 top; + } + + mapping(address => uint256) wards; + address dog; + address vow; + address spotter; + address «calc»; + uint256 buf; + uint256 tail; + uint256 cusp; + uint64 chip; + uint192 tip; + uint256 chost; + uint256 kicks; + uint256[] active; + mapping(uint256 => Sale) sales; + uint256 locked; + uint256 stopped; + + constructor(address vat_, address spotter_, address dog_, bytes32 ilk_) { + address imm_vat = vat_; + bytes32 imm_ilk = ilk_; + spotter = spotter_; + dog = dog_; + buf = #RAY; + wards[msg.sender] = 1; + } + + function min(uint256 x, uint256 y) internal returns (uint256) { + if (x <= y) { + return x; + } else { + return y; + } + } + + function add(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x + y) as uint256; + require(z >= x); + return z; + } + + function sub(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x - y) as uint256; + require(z <= x); + return z; + } + + function mul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + return z; + } + + function wmul(uint256 x, uint256 y) internal returns (uint256) { + var xy = mul(x, y); + return xy / #WAD; + } + + function rmul(uint256 x, uint256 y) internal returns (uint256) { + var xy = mul(x, y); + return xy / #RAY; + } + + function rdiv(uint256 x, uint256 y) internal returns (uint256) { + var xray = mul(x, #RAY); + return xray / y; + } + + function getFeedPrice() internal returns (uint256) { + require(spotter.code.length > 0); + var spotterIlk = spotter.spotterIlks(${ilkExpr v}); + address pip = spotterIlk.0; + require(pip.code.length > 0); + var peekRet = pip.peek(); + bytes32 val = peekRet.0; + bool has = peekRet.1; + require(has); + uint256 valBln = (uint256(val) * #BLN) as uint256; + require(#BLN == 0 || valBln / #BLN == uint256(val)); + require(spotter.code.length > 0); + var par = spotter.par(); + var feedPrice = rdiv(valBln, par); + return feedPrice; + } + + function status(uint96 tic, uint256 top) internal returns (bool, uint256) { + var ageForPrice = sub(block.timestamp, tic); + require(«calc».code.length > 0); + var price = «calc».price{view}(top, ageForPrice); + var ageForDone = sub(block.timestamp, tic); + bool done = false; + if (ageForDone > tail) { + done = true; + } else { + var ratio = rdiv(price, top); + done = ratio < cusp; + } + return (done, price); + } + + function _remove(uint256 id) internal { + uint256 lastIndex = (active.length - 1) as uint256; + uint256 _move = active[lastIndex]; + if (id != _move) { + uint256 _index = sales[id].pos; + active[_index] = _move; + sales[_move].pos = _index; + } + active.pop(); + delete sales[id]; + } + + function active(uint256 arg0) external returns (uint256) { + return active[arg0]; + } + + function buf() external returns (uint256) { + return buf; + } + + function «calc»() external returns (address) { + return «calc»; + } + + function chip() external returns (uint64) { + return chip; + } + + function chost() external returns (uint256) { + return chost; + } + + function count() external returns (uint256) { + return active.length; + } + + function cusp() external returns (uint256) { + return cusp; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function dog() external returns (address) { + return dog; + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + require(locked == 0); + locked = 1; + if (what == bytes32(0x6275660000000000000000000000000000000000000000000000000000000000)) { + buf = data; + } else if (what == bytes32(0x7461696c00000000000000000000000000000000000000000000000000000000)) { + tail = data; + } else if (what == bytes32(0x6375737000000000000000000000000000000000000000000000000000000000)) { + cusp = data; + } else if (what == bytes32(0x6368697000000000000000000000000000000000000000000000000000000000)) { + chip = data % #uint64Modulus; + } else if (what == bytes32(0x7469700000000000000000000000000000000000000000000000000000000000)) { + tip = data % #uint192Modulus; + } else if (what == bytes32(0x73746f7070656400000000000000000000000000000000000000000000000000)) { + stopped = data; + } else { + require(false); + } + locked = 0; + } + + function file(bytes32 what, address data) external { + require(wards[msg.sender] == 1); + require(locked == 0); + locked = 1; + if (what == bytes32(0x73706f7474657200000000000000000000000000000000000000000000000000)) { + spotter = data; + } else if (what == bytes32(0x646f670000000000000000000000000000000000000000000000000000000000)) { + dog = data; + } else if (what == bytes32(0x766f770000000000000000000000000000000000000000000000000000000000)) { + vow = data; + } else if (what == bytes32(0x63616c6300000000000000000000000000000000000000000000000000000000)) { + «calc» = data; + } else { + require(false); + } + locked = 0; + } + + function getStatus(uint256 id) external returns (bool, uint256, uint256, uint256) { + address usr = sales[id].usr; + uint96 tic = sales[id].tic; + var st = status(tic, sales[id].top); + bool done = st.0; + uint256 price = st.1; + bool needsRedo = usr != address(0) && done; + return (needsRedo, price, sales[id].lot, sales[id].tab); + } + + function ilk() external returns (bytes32) { + return ${ilkExpr v}; + } + + function kick(uint256 tab, uint256 lot, address usr, address kpr) external returns (uint256) { + require(wards[msg.sender] == 1); + require(locked == 0); + locked = 1; + require(stopped < 1); + require(tab > 0); + require(lot > 0); + require(usr != address(0)); + uint256 id = (kicks + 1) % #wordModulus; + kicks = id; + require(id > 0); + active.push(id); + uint256 activePos = (active.length - 1) % #wordModulus; + sales[id].pos = activePos; + sales[id].tab = tab; + sales[id].lot = lot; + sales[id].usr = usr; + sales[id].tic = block.timestamp % #uint96Modulus; + var feedPrice = getFeedPrice(); + var top = rmul(feedPrice, buf); + require(top > 0); + sales[id].top = top; + uint256 _tip = tip; + uint256 _chip = chip; + uint256 coin = 0; + if (_tip > 0 || _chip > 0) { + var chipCoin = wmul(tab, _chip); + uint256 coinNew = (_tip + chipCoin) as uint256; + require(coinNew >= _tip); + coin = coinNew; + ${checkedExternalCallStmts (vatExpr v) "suck" (.intLit 0) + [.storage vowRef, .var "kpr", .var "coin"] "_suckRet"} + } + locked = 0; + return id; + } + + function kicks() external returns (uint256) { + return kicks; + } + + function list() external returns (uint256[]) { + return active; + } + + function redo(uint256 id, address kpr) external { + require(locked == 0); + locked = 1; + require(stopped < 2); + address usr = sales[id].usr; + uint96 tic = sales[id].tic; + uint256 top = sales[id].top; + require(usr != address(0)); + var st = status(tic, top); + require(st.0); + uint256 tab = sales[id].tab; + uint256 lot = sales[id].lot; + sales[id].tic = block.timestamp % #uint96Modulus; + var feedPrice = getFeedPrice(); + var topNew = rmul(feedPrice, buf); + require(topNew > 0); + sales[id].top = topNew; + uint256 _tip = tip; + uint256 _chip = chip; + if (_tip > 0 || _chip > 0) { + uint256 _chost = chost; + if (tab >= _chost) { + uint256 lotFeed = (lot * feedPrice) as uint256; + require(feedPrice == 0 || lotFeed / feedPrice == lot); + if (lotFeed >= _chost) { + var chipCoin = wmul(tab, _chip); + uint256 coin = (_tip + chipCoin) as uint256; + require(coin >= _tip); + ${checkedExternalCallStmts (vatExpr v) "suck" (.intLit 0) + [.storage vowRef, .var "kpr", .var "coin"] "_suckRet"} + } + } + } + locked = 0; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 1; + } + + function sales(uint256 arg0) external returns (uint256, uint256, uint256, address, uint96, uint256) { + return (sales[arg0].pos, sales[arg0].tab, sales[arg0].lot, + sales[arg0].usr, sales[arg0].tic, sales[arg0].top); + } + + function spotter() external returns (address) { + return spotter; + } + + function stopped() external returns (uint256) { + return stopped; + } + + function tail() external returns (uint256) { + return tail; + } + + function take(uint256 id, uint256 amt, uint256 max, address who, bytes memory data) external { + require(locked == 0); + locked = 1; + require(stopped < 3); + address usr = sales[id].usr; + uint96 tic = sales[id].tic; + require(usr != address(0)); + var st = status(tic, sales[id].top); + bool done = st.0; + uint256 price = st.1; + require(!done); + require(max >= price); + uint256 lot = sales[id].lot; + uint256 tab = sales[id].tab; + var slice = min(lot, amt); + uint256 owe0 = (slice * price) as uint256; + require(price == 0 || owe0 / price == slice); + uint256 owe = owe0; + if (owe > tab) { + owe = tab; + slice = owe / price; + } else { + if (owe < tab && slice < lot) { + uint256 _chost = chost; + uint256 remainingTab = (tab - owe) % #wordModulus; + if (remainingTab < _chost) { + require(tab > _chost); + uint256 oweAdjusted = (tab - _chost) % #wordModulus; + owe = oweAdjusted; + slice = owe / price; + } + } + } + uint256 tabNew = (tab - owe) % #wordModulus; + uint256 lotNew = (lot - slice) % #wordModulus; + tab = tabNew; + lot = lotNew; + ${checkedExternalCallStmts (vatExpr v) "flux" (.intLit 0) + [ilkExpr v, thisAddr, .var "who", .var "slice"] "_fluxBuyerRet"} + address dog_ = dog; + if (data.length > 0 && who != ${vatExpr v} && who != dog_) { + require(who.code.length > 0); + var _clipperCallRet = who.clipperCall(msg.sender, owe, slice, data); + } + ${checkedExternalCallStmts (vatExpr v) "move" (.intLit 0) + [sender, .storage vowRef, .var "owe"] "_moveRet"} + if (lot == 0) { + uint256 digsAmt = (tab + owe) % #wordModulus; + require(dog_.code.length > 0); + var _digsRet = dog_.digs(${ilkExpr v}, digsAmt); + } else { + require(dog_.code.length > 0); + var _digsRet = dog_.digs(${ilkExpr v}, owe); + } + if (lot == 0) { + var _removeRet = _remove(id); + } else { + if (tab == 0) { + ${checkedExternalCallStmts (vatExpr v) "flux" (.intLit 0) + [ilkExpr v, thisAddr, .var "usr", .var "lot"] "_fluxUsrRet"} + var _removeRet2 = _remove(id); + } else { + sales[id].tab = tab; + sales[id].lot = lot; + } + } + locked = 0; + } + + function tip() external returns (uint192) { + return tip; + } + + function upchost() external { + ${checkedExternalCallStmts (vatExpr v) "vatIlks" (.intLit 0) [ilkExpr v] "vatIlk"} + uint256 _dust = ${Expr.tupleGet (Expr.var "vatIlk") 4}; + require(dog.code.length > 0); + var chop = dog.chop(${ilkExpr v}); + var chostNew = wmul(_dust, chop); + chost = chostNew; + } + + function vat() external returns (address) { + return ${vatExpr v}; + } + + function vow() external returns (address) { + return vow; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } + + function yank(uint256 id) external { + require(wards[msg.sender] == 1); + require(locked == 0); + locked = 1; + require(sales[id].usr != address(0)); + require(dog.code.length > 0); + var _digsRet = dog.digs(${ilkExpr v}, sales[id].tab); + ${checkedExternalCallStmts (vatExpr v) "flux" (.intLit 0) + [ilkExpr v, thisAddr, sender, .storage (salesF (.var "id") "lot")] "_fluxRet"} + var _removeRet = _remove(id); + locked = 0; + } +} theorem contractSyntax_eq (v : ClipperImmutables) : - contractSyntax v = Benchmarks.Dss.Clipper.contract v := by - rfl + contractSyntax v = Benchmarks.Dss.Clipper.contract v := by rfl end Benchmarks.Dss.Clipper.Syntax diff --git a/Benchmarks/Dss/Cure/Common.lean b/Benchmarks/Dss/Cure/Common.lean index 9e0905d5..f79c5ede 100644 --- a/Benchmarks/Dss/Cure/Common.lean +++ b/Benchmarks/Dss/Cure/Common.lean @@ -354,7 +354,7 @@ theorem solcGuardCallvalueNonzeroRevertLegacy {cA gh bl σ σ₀ A I} {g : Sat25 (h.pushConst ctgt hopC hpushC (by simp only [List.length]; omega) |>.jumpiNT hjumpi (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega)) - |>.uniswapPush1Dup1Revert0 hr0 hr1 hr2 (by simp only [List.length]; omega) + |>.solcPush1Dup1Revert0 hr0 hr1 hr2 (by simp only [List.length]; omega) /-- Legacy solc short-calldata revert for `PUSH1 0; DUP1; REVERT` stubs. -/ theorem solcCalldataShortRevertLegacy {cA gh bl σ σ₀ A I} {g : Sat256} @@ -383,7 +383,7 @@ theorem solcCalldataShortRevertLegacy {cA gh bl σ σ₀ A I} {g : Sat256} |>.pushConst rtgt hopR hd_pR (by simp only [List.length]; omega) |>.jumpiT hd_ji (lt_four_ne_zero_of_lt hsz) hjd (by simp only [List.length]; omega) |>.jumpdest hd_jd (by simp only [List.length]; omega)) - |>.uniswapPush1Dup1Revert0 hr0 hr1 hr2 (by simp only [List.length]; omega) + |>.solcPush1Dup1Revert0 hr0 hr1 hr2 (by simp only [List.length]; omega) /-- `callvalue ≠ 0` makes the global solc non-payable guard revert before dispatch. -/ theorem cureX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} @@ -822,7 +822,7 @@ theorem cureJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : UInt2 have h300 := h.push2 cureDispatchRevertPc hpush (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h300 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h300 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem cureLowLowerNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -844,7 +844,7 @@ theorem cureLowLowerNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : |>.selectorArmNotTakenAuto (cureLowLowerArmsWellFormed 4 (by omega)) (heq0 4 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h300 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h300 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem cureLowUpperNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} diff --git a/Benchmarks/Dss/Cure/Constructor.lean b/Benchmarks/Dss/Cure/Constructor.lean index 928a1ce1..c8fb0b3d 100644 --- a/Benchmarks/Dss/Cure/Constructor.lean +++ b/Benchmarks/Dss/Cure/Constructor.lean @@ -114,7 +114,7 @@ theorem cureCtorNonpayableRDrev (by simp only [List.length_cons, List.length_nil]; omega)) simpa [show ((⟨8⟩ : UInt256) + UInt256.ofNat 3 + ⟨1⟩) = ⟨12⟩ from by native_decide] using - RD.uniswapPush1Dup1Revert0 (code := cureCreationBytecode) (ee := I) (g := g) + RD.solcPush1Dup1Revert0 (code := cureCreationBytecode) (ee := I) (g := g) (s0 := initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) rd12 (by ctor_decode) (by ctor_decode) (by ctor_decode) (by simp only [List.length_cons, List.length_nil]; omega) diff --git a/Benchmarks/Dss/Cure/Load.lean b/Benchmarks/Dss/Cure/Load.lean index bdf44d7c..0e4f6f55 100644 --- a/Benchmarks/Dss/Cure/Load.lean +++ b/Benchmarks/Dss/Cure/Load.lean @@ -130,10 +130,10 @@ theorem cureLoadBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (ee := I) (key := key) (ret := ⟨484⟩) (R := [sel]) hafterLive hcanonKey hposSolc solcFreePtrMem_size (by simp) - by_cases hnoCodeEvm : uniswapExtCodeSizeWord σ_evm key = ⟨0⟩ - · have hnoCodeSolm : uniswapExtCodeSizeWord σ_solm key = ⟨0⟩ := by + by_cases hnoCodeEvm : extCodeSizeWord σ_evm key = ⟨0⟩ + · have hnoCodeSolm : extCodeSizeWord σ_solm key = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv _hAccounts key + Reasoning.Theory.extCodeSizeWord_accountMapEquiv _hAccounts key rw [← hsame] exact hnoCodeEvm let evm0 := initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I @@ -155,12 +155,12 @@ theorem cureLoadBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (ee := I) (key := key) (ret := ⟨484⟩) (R := [sel]) hafterPos hcanonKey hnoCodeEvm hposMem hposRead64 (by simp) exact hrev.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hcodeSizeEvm : uniswapExtCodeSizeWord σ_evm key ≠ ⟨0⟩ := hnoCodeEvm - have hcodeSizeSolm : uniswapExtCodeSizeWord σ_solm key ≠ ⟨0⟩ := by + · have hcodeSizeEvm : extCodeSizeWord σ_evm key ≠ ⟨0⟩ := hnoCodeEvm + have hcodeSizeSolm : extCodeSizeWord σ_solm key ≠ ⟨0⟩ := by intro hzero apply hcodeSizeEvm have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv _hAccounts key + Reasoning.Theory.extCodeSizeWord_accountMapEquiv _hAccounts key rw [hsame] exact hzero have hposMem : diff --git a/Benchmarks/Dss/Cure/LoadBase.lean b/Benchmarks/Dss/Cure/LoadBase.lean index 838ccb8c..6d297907 100644 --- a/Benchmarks/Dss/Cure/LoadBase.lean +++ b/Benchmarks/Dss/Cure/LoadBase.lean @@ -485,7 +485,7 @@ theorem evalExpr_loadPosGtZero_true (evm : EVM.State) (I : ExecutionEnv) theorem evalExpr_loadExtCodeSizeGtZero_false_of_src {cA gh bl σ σ₀ A I} {g : Sat256} {locals : Store} (hsrc : locals.get? "src" = some (.address (loadSrc I))) - (hnoCode : uniswapExtCodeSizeWord σ (loadKey I) = ⟨0⟩) : + (hnoCode : extCodeSizeWord σ (loadKey I) = ⟨0⟩) : evalExpr? config { contract := contract, locals := locals } (initState cA gh bl σ σ₀ g A I) (.binary .gt (.extCodeSize (.var "src")) (.intLit 0)) = .ok (.bool false) := by @@ -508,7 +508,7 @@ theorem evalExpr_loadExtCodeSizeGtZero_false_of_src {cA gh bl σ σ₀ A I} {g : rfl | some acc => have hnoAcc : UInt256.ofNat acc.code.size = ⟨0⟩ := by - simpa [uniswapExtCodeSizeWord, loadKey_address_eq I, hacc] using hnoCode + simpa [extCodeSizeWord, loadKey_address_eq I, hacc] using hnoCode simpa [hacc] using hnoAcc have hext : evalExpr? config { contract := contract, locals := locals } evm0 @@ -528,7 +528,7 @@ theorem evalExpr_loadExtCodeSizeGtZero_false_of_src {cA gh bl σ σ₀ A I} {g : · native_decide theorem evalExpr_loadExtCodeSizeGtZero_false {cA gh bl σ σ₀ A I} {g : Sat256} - (hnoCode : uniswapExtCodeSizeWord σ (loadKey I) = ⟨0⟩) : + (hnoCode : extCodeSizeWord σ (loadKey I) = ⟨0⟩) : evalExpr? config { contract := contract, locals := loadLocals I } (initState cA gh bl σ σ₀ g A I) (.binary .gt (.extCodeSize (.var "src")) (.intLit 0)) = .ok (.bool false) := by @@ -539,7 +539,7 @@ theorem evalExpr_loadExtCodeSizeGtZero_false {cA gh bl σ σ₀ A I} {g : Sat256 theorem evalExpr_loadExtCodeSizeGtZero_true_of_src {cA gh bl σ σ₀ A I} {g : Sat256} {locals : Store} (hsrc : locals.get? "src" = some (.address (loadSrc I))) - (hcode : uniswapExtCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) : + (hcode : extCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) : evalExpr? config { contract := contract, locals := locals } (initState cA gh bl σ σ₀ g A I) (.binary .gt (.extCodeSize (.var "src")) (.intLit 0)) = .ok (.bool true) := by @@ -559,9 +559,9 @@ theorem evalExpr_loadExtCodeSizeGtZero_true_of_src {cA gh bl σ σ₀ A I} {g : ((σ.find? (loadSrc I)).option 0 (fun acc => acc.code.size)) ≠ ⟨0⟩ cases hacc : σ.find? (loadSrc I) with | none => - exact False.elim (hcode (by simp [uniswapExtCodeSizeWord, loadKey_address_eq I, hacc, Option.option])) + exact False.elim (hcode (by simp [extCodeSizeWord, loadKey_address_eq I, hacc, Option.option])) | some acc => - simpa [uniswapExtCodeSizeWord, loadKey_address_eq I, hacc] using hcode + simpa [extCodeSizeWord, loadKey_address_eq I, hacc] using hcode have hcodePos : 0 < (EVM.Word.ofNat ((evm0.lookupAccount (loadSrc I)).option 0 (fun acc => acc.code.size))).toNat := diff --git a/Benchmarks/Dss/Cure/LoadSource.lean b/Benchmarks/Dss/Cure/LoadSource.lean index b540e5e3..2276f5db 100644 --- a/Benchmarks/Dss/Cure/LoadSource.lean +++ b/Benchmarks/Dss/Cure/LoadSource.lean @@ -83,7 +83,7 @@ theorem cureLoadSourceBodyNoCodeRevert {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : cureSlotWord ⟨1⟩ σ I = ⟨0⟩) (hpos : cureSlotWord (loadPosSlotFor I) σ I ≠ ⟨0⟩) - (hnoCode : uniswapExtCodeSizeWord σ (loadKey I) = ⟨0⟩) : + (hnoCode : extCodeSizeWord σ (loadKey I) = ⟨0⟩) : ExecTransitionBody config contract (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (loadLocals I) loadTransition.body .reverted := by @@ -170,7 +170,7 @@ theorem cureLoadSourceBodyCallFailureRevert {cA gh bl σ σ₀ A I} {g : UInt256 (hwv : I.weiValue = ⟨0⟩) (hlive : cureSlotWord ⟨1⟩ σ I = ⟨0⟩) (hpos : cureSlotWord (loadPosSlotFor I) σ I ≠ ⟨0⟩) - (hcode : uniswapExtCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) + (hcode : extCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) @@ -265,7 +265,7 @@ theorem cureLoadSourceBodyReturnDecodeRevert {cA gh bl σ σ₀ A I} {g : UInt25 (hwv : I.weiValue = ⟨0⟩) (hlive : cureSlotWord ⟨1⟩ σ I = ⟨0⟩) (hpos : cureSlotWord (loadPosSlotFor I) σ I ≠ ⟨0⟩) - (hcode : uniswapExtCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) + (hcode : extCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) @@ -363,7 +363,7 @@ theorem cureLoadSourceBodySubRevert {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : cureSlotWord ⟨1⟩ σ I = ⟨0⟩) (hpos : cureSlotWord (loadPosSlotFor I) σ I ≠ ⟨0⟩) - (hcode : uniswapExtCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) + (hcode : extCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) @@ -583,7 +583,7 @@ theorem cureLoadSourceBodyAddRevert {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : cureSlotWord ⟨1⟩ σ I = ⟨0⟩) (hpos : cureSlotWord (loadPosSlotFor I) σ I ≠ ⟨0⟩) - (hcode : uniswapExtCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) + (hcode : extCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) @@ -862,7 +862,7 @@ theorem cureLoadSourceBodyOkLoadedNonzero {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : cureSlotWord ⟨1⟩ σ I = ⟨0⟩) (hpos : cureSlotWord (loadPosSlotFor I) σ I ≠ ⟨0⟩) - (hcode : uniswapExtCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) + (hcode : extCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) @@ -1194,7 +1194,7 @@ theorem cureLoadSourceBodyOkLoadedZero {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : cureSlotWord ⟨1⟩ σ I = ⟨0⟩) (hpos : cureSlotWord (loadPosSlotFor I) σ I ≠ ⟨0⟩) - (hcode : uniswapExtCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) + (hcode : extCodeSizeWord σ (loadKey I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) diff --git a/Benchmarks/Dss/Cure/LoadTrace.lean b/Benchmarks/Dss/Cure/LoadTrace.lean index f9174f67..e5a8ace2 100644 --- a/Benchmarks/Dss/Cure/LoadTrace.lean +++ b/Benchmarks/Dss/Cure/LoadTrace.lean @@ -362,14 +362,14 @@ theorem RD.cureLoadNoCodeRevert {g : Sat256} {s0 : State} (h : RD cureBytecode ee g s0 ⟨1520⟩ (key :: ret :: R) mem (UInt256.ofNat 3) rdata (cA, σ) k C) (hcanonKey : key.toNat < EVM.addressModulus) - (hnoCode : uniswapExtCodeSizeWord σ key = ⟨0⟩) + (hnoCode : extCodeSizeWord σ key = ⟨0⟩) (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hov : R.length + 16 ≤ 1024) : RDrev cureBytecode g s0 := by obtain ⟨Rext, _, _, _hRext, hRextLen, rd1586⟩ := RD.cureLoadToCureExtcodesizeGuard h hcanonKey hmem hread64 hov - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1586⟩) (okPc := ⟨1598⟩) rd1586 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1586⟩) (okPc := ⟨1598⟩) rd1586 hnoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -381,7 +381,7 @@ theorem RD.cureLoadStaticcallSetup {g : Sat256} {s0 : State} (h : RD cureBytecode ee g s0 ⟨1520⟩ (key :: ret :: R) mem (UInt256.ofNat 3) rdata (cA, σ) k C) (hcanonKey : key.toNat < EVM.addressModulus) - (hcodeSize : uniswapExtCodeSizeWord σ key ≠ ⟨0⟩) + (hcodeSize : extCodeSizeWord σ key ≠ ⟨0⟩) (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hov : R.length + 16 ≤ 1024) : @@ -395,7 +395,7 @@ theorem RD.cureLoadStaticcallSetup {g : Sat256} {s0 : State} obtain ⟨Rext, _, _, hRext, hRextLen, rd1586⟩ := RD.cureLoadToCureExtcodesizeGuard h hcanonKey hmem hread64 hov obtain ⟨gasWord, k1601, C1601, rd1601⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1586⟩) (okPc := ⟨1598⟩) rd1586 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1586⟩) (okPc := ⟨1598⟩) rd1586 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -411,7 +411,7 @@ theorem RD.cureLoadStaticcall (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1520⟩ (key :: ret :: R) mem (UInt256.ofNat 3) rdata (cA_call, σCall) k C) (hcanonKey : key.toNat < EVM.addressModulus) - (hcodeSize : uniswapExtCodeSizeWord σCall key ≠ ⟨0⟩) + (hcodeSize : extCodeSizeWord σCall key ≠ ⟨0⟩) (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hdepth : I.depth.val < 1024) @@ -442,7 +442,7 @@ theorem RD.cureLoadStaticcall RD.cureLoadStaticcallSetup h hcanonKey hcodeSize hmem hread64 hov obtain ⟨cA', σ', z, out, A_in, callGas, k1602, C1602, hΘpack, rd1602raw, houtsz⟩ := - RD.uniswapStaticcall rd1601 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall rd1601 (by native_decide) hdepth (by evm_ov) obtain ⟨g'', A', hΘ⟩ := hΘpack let evmIn := { initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I with accountMap := σCall @@ -484,7 +484,7 @@ theorem RD.cureLoadStaticcallDepthLimit (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1520⟩ (key :: ret :: R) mem (UInt256.ofNat 3) rdata (cA, σ) k C) (hcanonKey : key.toNat < EVM.addressModulus) - (hcodeSize : uniswapExtCodeSizeWord σ key ≠ ⟨0⟩) + (hcodeSize : extCodeSizeWord σ key ≠ ⟨0⟩) (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hdepth : I.depth = 1024) @@ -500,7 +500,7 @@ theorem RD.cureLoadStaticcallDepthLimit obtain ⟨_, _, _, rd1601⟩ := RD.cureLoadStaticcallSetup h hcanonKey hcodeSize hmem hread64 hov obtain ⟨k1602, C1602, rd1602raw⟩ := - RD.uniswapStaticcallDepthLimit rd1601 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcallDepthLimit rd1601 (by native_decide) hdepth (by evm_ov) have haw : UInt256.ofNat (MachineState.M (MachineState.M (UInt256.ofNat 5).toNat (⟨128⟩ : UInt256).toNat @@ -516,7 +516,7 @@ theorem RD.cureLoadCallFailure {g : Sat256} {s0 : State} (hosz : o.size < UInt256.size) (hov : rest.length + 5 ≤ 1024) : RDrev cureBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1602⟩) (okPc := ⟨1618⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨1602⟩) (okPc := ⟨1618⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -533,7 +533,7 @@ theorem RD.cureLoadCallSuccessToReturnDecode {g : Sat256} {s0 : State} ∃ k' C', RD cureBytecode ee g s0 ⟨1623⟩ (d3 :: d4 :: d5 :: d6 :: R) mem aw o acc k' C' := by obtain ⟨_, _, rd1620⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨1602⟩) (okPc := ⟨1618⟩) rd + RD.solcCallSuccessGuardOk (pc := ⟨1602⟩) (okPc := ⟨1618⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -583,7 +583,7 @@ theorem RD.cureLoadReturnDecodeShortReverts {g : Sat256} {s0 : State} decide have rdFallthrough := RD.jumpiNT rdPushOk (by native_decide) hcond (by simp only [List.length_cons]; omega) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) diff --git a/Benchmarks/Dss/Cure/SpecSyntax.lean b/Benchmarks/Dss/Cure/SpecSyntax.lean index 2e0aa534..a17b1d25 100644 --- a/Benchmarks/Dss/Cure/SpecSyntax.lean +++ b/Benchmarks/Dss/Cure/SpecSyntax.lean @@ -2,19 +2,173 @@ import Benchmarks.Dss.Cure.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS Cure spec through the Solm notation frontend +# Cure spec in the Solidity-faithful Solm frontend -The main spec lives in `Spec.lean`; this companion keeps the benchmark's notation-side check wired -up as the body surface grows. +The whole `cure.sol` spec written with `solidity%` and proven definitionally equal to the AST +spec in `Spec.lean`. Checked-math helpers (`_add`/`_sub`) and the checked external call in +`load` are inlined; `"wait"` is the big-endian `bytes32` literal; the unchecked `lCount++` is the +explicit `% #wordModulus` wrap. Transition order matches `contract.transitions` (selector order). -/ -open Solm Solm.Notation +open Solm Solm.Notation Benchmarks.Dss.Cure namespace Benchmarks.Dss.Cure.Syntax -def contractSyntax : ContractDecl := Benchmarks.Dss.Cure.contract +def contractSyntax : ContractDecl := solidity% contract Cure { + mapping(address => uint256) wards; + uint256 live; + address[] srcs; + uint256 wait; + uint256 when; + mapping(address => uint256) pos; + mapping(address => uint256) amt; + mapping(address => uint256) loaded; + uint256 lCount; + uint256 say; -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Cure.contract := by - rfl + constructor() { + live = 1; + wards[msg.sender] = 1; + } + + function _add(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x + y) as uint256; + require(z >= x); + return z; + } + + function _sub(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x - y) as uint256; + require(z <= x); + return z; + } + + function amt(address arg0) external returns (uint256) { + return amt[arg0]; + } + + function cage() external { + require(wards[msg.sender] == 1); + require(live == 1); + live = 0; + var when_ = _add(block.timestamp, wait); + when = when_; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + require(live == 1); + wards[usr] = 0; + } + + function drop(address src) external { + require(wards[msg.sender] == 1); + require(live == 1); + uint256 pos_ = pos[src]; + require(pos_ > 0); + uint256 last = srcs.length; + if (pos_ < last) { + uint256 lastIndex = (last - 1) as uint256; + address move = srcs[lastIndex]; + uint256 dstIndex = (pos_ - 1) as uint256; + srcs[dstIndex] = move; + pos[move] = pos_; + } + srcs.pop(); + delete pos[src]; + delete amt[src]; + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + require(live == 1); + if (what == bytes32(0x7761697400000000000000000000000000000000000000000000000000000000)) { + wait = data; + } else { + require(false); + } + } + + function lCount() external returns (uint256) { + return lCount; + } + + function lift(address src) external { + require(wards[msg.sender] == 1); + require(live == 1); + require(pos[src] == 0); + srcs.push(src); + pos[src] = srcs.length; + } + + function list() external returns (address[]) { + return srcs; + } + + function live() external returns (uint256) { + return live; + } + + function load(address src) external { + require(live == 0); + require(pos[src] > 0); + uint256 oldAmt_ = amt[src]; + require(src.code.length > 0); + var newAmt_ = src.cure{view}(); + amt[src] = newAmt_; + var withoutOld = _sub(say, oldAmt_); + var sayNew = _add(withoutOld, newAmt_); + say = sayNew; + if (loaded[src] == 0) { + loaded[src] = 1; + lCount = (lCount + 1) % #wordModulus; + } + } + + function loaded(address arg0) external returns (uint256) { + return loaded[arg0]; + } + + function pos(address arg0) external returns (uint256) { + return pos[arg0]; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + require(live == 1); + wards[usr] = 1; + } + + function say() external returns (uint256) { + return say; + } + + function srcs(uint256 arg0) external returns (address) { + return srcs[arg0]; + } + + function tCount() external returns (uint256) { + return srcs.length; + } + + function tell() external returns (uint256) { + require(live == 0 && (lCount == srcs.length || block.timestamp >= when)); + return say; + } + + function wait() external returns (uint256) { + return wait; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } + + function when() external returns (uint256) { + return when; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Cure.contract := by rfl end Benchmarks.Dss.Cure.Syntax diff --git a/Benchmarks/Dss/Cure/Srcs.lean b/Benchmarks/Dss/Cure/Srcs.lean index aacc5f03..200ad98c 100644 --- a/Benchmarks/Dss/Cure/Srcs.lean +++ b/Benchmarks/Dss/Cure/Srcs.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.Cure.Common import Ethereum.Theory.OpcodeLemmas -import Reasoning.SolcDecode open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement diff --git a/Benchmarks/Dss/Dai/Burn.lean b/Benchmarks/Dss/Dai/Burn.lean index d801cf56..7ca56739 100644 --- a/Benchmarks/Dss/Dai/Burn.lean +++ b/Benchmarks/Dss/Dai/Burn.lean @@ -1686,7 +1686,7 @@ theorem daiBurnX_tailUsrDebitRevertCont {cA σ I} {g : Sat256} {s0 : State} have rdPush := evm_run rd8 with [raw push2 ⟨1399⟩ hd8 (by evm_ov)] have rdTail := rdPush.jumpiNT hd11 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rdTail + exact RD.solcPush1Dup1Revert0 rdTail (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1892,7 +1892,7 @@ theorem daiBurnX_tailSupplyRevertCont {cA σ I} {g : Sat256} {s0 : State} have rdPush := evm_run rd8 with [raw push2 ⟨1399⟩ hd8 (by evm_ov)] have rdTail := rdPush.jumpiNT hd11 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rdTail + exact RD.solcPush1Dup1Revert0 rdTail (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) diff --git a/Benchmarks/Dss/Dai/Constructor.lean b/Benchmarks/Dss/Dai/Constructor.lean index 453c9127..1f55a0f9 100644 --- a/Benchmarks/Dss/Dai/Constructor.lean +++ b/Benchmarks/Dss/Dai/Constructor.lean @@ -1429,7 +1429,7 @@ theorem daiCtorDomainWordsTrace push1 ⟨128⟩, dup2, add, swap4, swap1, swap4, raw mstore 3 (daiCtorDomainChainMem I chainIdWord) (UInt256.ofNat 14) (by dai_ctor_decode) mem_cost rfl (by decide) (by evm_ov), - uniswapAddress, push1 ⟨160⟩, dup1, dup6, add, swap2, swap1, swap2, + address, push1 ⟨160⟩, dup1, dup6, add, swap2, swap1, swap2, raw mstore 3 (daiCtorDomainWordsMem I chainIdWord) (UInt256.ofNat 15) (by dai_ctor_decode) mem_cost rfl (by decide) (by evm_ov)] exact ⟨_, _, rd⟩ diff --git a/Benchmarks/Dss/Dai/Correct.lean b/Benchmarks/Dss/Dai/Correct.lean index 8cc7bbd2..682e046f 100644 --- a/Benchmarks/Dss/Dai/Correct.lean +++ b/Benchmarks/Dss/Dai/Correct.lean @@ -79,7 +79,7 @@ theorem daiX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem daiX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -102,7 +102,7 @@ theorem daiX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h322 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h322 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem daiDispatch_none_short {cd : ByteArray} (hshort : cd.size < 4) : @@ -180,7 +180,7 @@ theorem daiJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} have h322 := h.push2 ⟨322⟩ hpush (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by evm_ov) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h322 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h322 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem daiX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} @@ -313,7 +313,7 @@ theorem daiX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} |>.selectorArmNotTakenAuto (daiVeryLowArmsWellFormed 4 (by omega)) (heqVeryLow 4 (by omega)) (by simp) have h323 := h322.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h323 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h323 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) /-- `callvalue != 0` reverts on both sides for every Dai transition. -/ diff --git a/Benchmarks/Dss/Dai/Mint.lean b/Benchmarks/Dss/Dai/Mint.lean index 7445d522..1b59cd86 100644 --- a/Benchmarks/Dss/Dai/Mint.lean +++ b/Benchmarks/Dss/Dai/Mint.lean @@ -1019,7 +1019,7 @@ theorem daiCheckedAddRevert0 {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} have rdPush := evm_run rd8 with [raw push2 ⟨1399⟩ hd8 (by evm_ov)] have rdTail := rdPush.jumpiNT hd11 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by simp only [List.length_cons]; omega) - exact RD.uniswapPush1Dup1Revert0 rdTail + exact RD.solcPush1Dup1Revert0 rdTail (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) diff --git a/Benchmarks/Dss/Dai/Permit.lean b/Benchmarks/Dss/Dai/Permit.lean index 47dafecf..7f6c2b9d 100644 --- a/Benchmarks/Dss/Dai/Permit.lean +++ b/Benchmarks/Dss/Dai/Permit.lean @@ -4653,7 +4653,7 @@ theorem daiPermitX_nonzeroHolderStaticcallFrom2684 {cA gh bl σ σ₀ A I} {g : raw dup6 (by native_decide) (by evm_ov)] obtain ⟨_gasArg, rd2757⟩ := RD.gas rd2756 (by native_decide) (by evm_ov) obtain ⟨cA', σ', z, o, A_in, callGas, k', C', hΘ, rd2758, hoSize⟩ := - RD.uniswapStaticcall rd2757 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall rd2757 (by native_decide) hdepth (by evm_ov) refine ⟨cA', σ', z, o, A_in, callGas, k', C', ?_, ?_, hoSize⟩ · rcases hΘ with ⟨g'', A', hΘ⟩ refine ⟨g'', A', ?_⟩ @@ -4750,7 +4750,7 @@ theorem daiPermitX_nonzeroHolderEcrecoverFailureAfter2758 mem aw o (cA', σ') k C) (hoSize : o.size < UInt256.size) : RDrev daiBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (okPc := ⟨2774⟩) rd2758 rfl + exact RD.solcCallSuccessGuardMissing (okPc := ⟨2774⟩) rd2758 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -5080,7 +5080,7 @@ theorem daiPermitX_nonzeroHolderEcrecoverSuccessToRecoveredBranchAfter2758 simpa [baseMem] using permitEcrecoverMem5_read64 I domainWord digestWord) (hoSize := hoSize) obtain ⟨_, _, rd2776⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨2774⟩) rd2758 + RD.solcCallSuccessGuardOk (okPc := ⟨2774⟩) rd2758 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -6657,7 +6657,7 @@ theorem daiPermitBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} omega have hdepthEq : I.depth = (1024 : Fin 1025) := Fin.ext hdepthEqVal obtain ⟨_kStatic, _CStatic, rd2758⟩ := - RD.uniswapStaticcallDepthLimit rd2757 (by native_decide) hdepthEq (by simp) + RD.solcStaticcallDepthLimit rd2757 (by native_decide) hdepthEq (by simp) let evmPostSolm := { evmSolm with substate := (evmSolm.addAccessedAccount diff --git a/Benchmarks/Dss/Dai/SpecSyntax.lean b/Benchmarks/Dss/Dai/SpecSyntax.lean index 611f7879..1f121b85 100644 --- a/Benchmarks/Dss/Dai/SpecSyntax.lean +++ b/Benchmarks/Dss/Dai/SpecSyntax.lean @@ -2,106 +2,183 @@ import Benchmarks.Dss.Dai.Spec import Solm.Notation /-! -# MakerDAO DSS Dai spec through the Solm notation frontend - -This file exposes a notation-side presentation for the parts of the Dai scaffold covered by the -current Solm frontend, and checks by `rfl` that it is definitionally equal to the AST spec in -`Benchmarks/Dss/Dai/Spec.lean`. +# Dai spec in the Solidity-faithful Solm frontend + +The whole Dai benchmark spec, written with `solidity%` and proven definitionally equal to the +AST spec in `Benchmarks/Dss/Dai/Spec.lean`. + +Notes: +* The strict-`&&` allowance guards are the spec's short-circuit ternaries, written as `c ? a : false`. +* `abi.encodePacked` operands carry their ABI types as `T(e)` annotations; inner casts nest, e.g. + `uint256(uint256(holder))` is the pair `(uint256, .cast holder uint256St)`. +* `permit`'s ecrecover precompile call targets `address(1)` (a cast), which the surface low-level + call cannot express, so that one statement is spliced; its `ecrecoverSuccess`/`ecrecoverData` + binders are then referenced via `${…}`. The EIP-191 `"\x19\x01"` prefix and `PERMIT_TYPEHASH` + literal reuse the spec's `eip191Prefix`/`permitTypehashExpr` defs. +* Transition order matches `contract.transitions` (selector order). -/ open Solm Solm.Notation namespace Benchmarks.Dss.Dai.Syntax -def storageDeclsSyntax : List StorageDecl := - sState% { - (address => uint256) wards - uint256 totalSupply - (address => uint256) balanceOf - (address => (address => uint256)) allowance - (address => uint256) nonces - } ++ - [ { name := "DOMAIN_SEPARATOR", ty := bytes32St } ] - -def relyTransitionSyntax : TransitionDecl := - { name := "rely" - params := [{ name := "guy", ty := addr }] - returnType := [] - body := sBlock% { - require msg.value == 0 - require @wards[msg.sender] == 1 - @wards[guy] := 1 - } } - -def approveTransitionSyntax : TransitionDecl := - solm_transition approve (usr : address) (wad : uint256) -> bool { - require msg.value == 0 - @allowance[msg.sender][usr] := wad - return true - } - -def transferTransitionSyntax : TransitionDecl := - { name := "transfer" - params := [{ name := "dst", ty := addr }, { name := "wad", ty := uint256 }] - returnType := [boolTy] - body := - sBlock% { - require msg.value == 0 - } ++ - [ .internalCall "transferFrom" [sender, .var "dst", .var "wad"] "_ok" ] ++ - sBlock% { - return _ok - } } - -def transitionsSyntax : List TransitionDecl := - [ allowanceTransition, - approveTransitionSyntax, - balanceOfTransition, - burnTransition, - decimalsTransition, - denyTransition, - domainSeparatorTransition, - mintTransition, - moveTransition, - nameTransition, - noncesTransition, - permitTransition, - permitTypehashTransition, - pullTransition, - pushTransition, - relyTransitionSyntax, - symbolTransition, - totalSupplyTransition, - transferTransitionSyntax, - transferFromTransition, - versionTransition, - wardsTransition ] - -def contractSyntax : ContractDecl := - { name := "Dai" - storage := storageDeclsSyntax - ctor := constructorDecl - functions := [] - transitions := transitionsSyntax } - -theorem storageDeclsSyntax_eq : storageDeclsSyntax = Benchmarks.Dss.Dai.storageDecls := by - rfl - -theorem relyTransitionSyntax_eq : relyTransitionSyntax = Benchmarks.Dss.Dai.relyTransition := by - rfl - -theorem approveTransitionSyntax_eq : - approveTransitionSyntax = Benchmarks.Dss.Dai.approveTransition := by - rfl - -theorem transferTransitionSyntax_eq : - transferTransitionSyntax = Benchmarks.Dss.Dai.transferTransition := by - rfl - -theorem transitionsSyntax_eq : transitionsSyntax = Benchmarks.Dss.Dai.transitions := by - rfl - -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Dai.contract := by - rfl +def contractSyntax : ContractDecl := solidity% contract Dai { + mapping(address => uint256) wards; + uint256 totalSupply; + mapping(address => uint256) balanceOf; + mapping(address => mapping(address => uint256)) allowance; + mapping(address => uint256) nonces; + bytes32 DOMAIN_SEPARATOR; + + constructor(uint256 chainId_) { + wards[msg.sender] = 1; + DOMAIN_SEPARATOR = keccak256(abi.encodePacked( + bytes32(keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")), + bytes32(keccak256("Dai Stablecoin")), + bytes32(keccak256("1")), + uint256(chainId_), + uint256(uint256(this)))); + } + + function allowance(address arg0, address arg1) external returns (uint256) { + return allowance[arg0][arg1]; + } + + function approve(address usr, uint256 wad) external returns (bool) { + allowance[msg.sender][usr] = wad; + return true; + } + + function balanceOf(address arg0) external returns (uint256) { + return balanceOf[arg0]; + } + + function burn(address usr, uint256 wad) external { + require(balanceOf[usr] >= wad); + if (usr != msg.sender ? allowance[usr][msg.sender] != type(uint256).max : false) { + require(allowance[usr][msg.sender] >= wad); + require(((allowance[usr][msg.sender] - wad) as uint256) <= allowance[usr][msg.sender]); + allowance[usr][msg.sender] = (allowance[usr][msg.sender] - wad) as uint256; + } + require(balanceOf[usr] >= wad); + require(((balanceOf[usr] - wad) as uint256) <= balanceOf[usr]); + balanceOf[usr] = (balanceOf[usr] - wad) as uint256; + require(((totalSupply - wad) as uint256) <= totalSupply); + totalSupply = (totalSupply - wad) as uint256; + } + + function decimals() external returns (uint8) { + return 18; + } + + function deny(address guy) external { + require(wards[msg.sender] == 1); + wards[guy] = 0; + } + + function DOMAIN_SEPARATOR() external returns (bytes32) { + return DOMAIN_SEPARATOR; + } + + function mint(address usr, uint256 wad) external { + require(wards[msg.sender] == 1); + require(((balanceOf[usr] + wad) as uint256) >= balanceOf[usr]); + balanceOf[usr] = (balanceOf[usr] + wad) as uint256; + require(((totalSupply + wad) as uint256) >= totalSupply); + totalSupply = (totalSupply + wad) as uint256; + } + + function move(address src, address dst, uint256 wad) external { + var _ok = transferFrom(src, dst, wad); + } + + function name() external returns (string) { + return "Dai Stablecoin"; + } + + function nonces(address arg0) external returns (uint256) { + return nonces[arg0]; + } + + function permit(address holder, address spender, uint256 nonce, uint256 expiry, + bool allowed, uint8 v, bytes32 r, bytes32 s) external { + bytes32 digest = keccak256(abi.encodePacked( + bytes(${eip191Prefix}), + bytes32(DOMAIN_SEPARATOR), + bytes32(keccak256(abi.encodePacked( + bytes32(${permitTypehashExpr}), + uint256(uint256(holder)), + uint256(uint256(spender)), + uint256(nonce), + uint256(expiry), + uint256(allowed ? 1 : 0)))))); + require(holder != address(0)); + ${[Stmt.lowLevelCall ecrecoverPrecompile (.intLit 0) ecrecoverCalldataExpr + "ecrecoverSuccess" "ecrecoverData" false]} + require(${Expr.var "ecrecoverSuccess"}); + address recovered = abi.decode(${Expr.var "ecrecoverData"}, (address)); + require(holder == recovered); + require(expiry == 0 || block.timestamp <= expiry); + require(nonce == nonces[holder]); + nonces[holder] = nonces[holder] + 1; + uint256 wad = allowed ? type(uint256).max : 0; + allowance[holder][spender] = wad; + } + + function PERMIT_TYPEHASH() external returns (bytes32) { + return ${permitTypehashExpr}; + } + + function pull(address usr, uint256 wad) external { + var _ok = transferFrom(usr, msg.sender, wad); + } + + function push(address usr, uint256 wad) external { + var _ok = transferFrom(msg.sender, usr, wad); + } + + function rely(address guy) external { + require(wards[msg.sender] == 1); + wards[guy] = 1; + } + + function symbol() external returns (string) { + return "DAI"; + } + + function totalSupply() external returns (uint256) { + return totalSupply; + } + + function transfer(address dst, uint256 wad) external returns (bool) { + var _ok = transferFrom(msg.sender, dst, wad); + return _ok; + } + + function transferFrom(address src, address dst, uint256 wad) external returns (bool) { + require(balanceOf[src] >= wad); + if (src != msg.sender ? allowance[src][msg.sender] != type(uint256).max : false) { + require(allowance[src][msg.sender] >= wad); + require(((allowance[src][msg.sender] - wad) as uint256) <= allowance[src][msg.sender]); + allowance[src][msg.sender] = (allowance[src][msg.sender] - wad) as uint256; + } + require(balanceOf[src] >= wad); + require(((balanceOf[src] - wad) as uint256) <= balanceOf[src]); + balanceOf[src] = (balanceOf[src] - wad) as uint256; + require(((balanceOf[dst] + wad) as uint256) >= balanceOf[dst]); + balanceOf[dst] = (balanceOf[dst] + wad) as uint256; + return true; + } + + function version() external returns (string) { + return "1"; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Dai.contract := by rfl end Benchmarks.Dss.Dai.Syntax diff --git a/Benchmarks/Dss/Dai/TransferFrom.lean b/Benchmarks/Dss/Dai/TransferFrom.lean index 808bcebb..e1c3ffe1 100644 --- a/Benchmarks/Dss/Dai/TransferFrom.lean +++ b/Benchmarks/Dss/Dai/TransferFrom.lean @@ -4057,7 +4057,7 @@ theorem daiTransferFromX_tailSrcDebitRevertCont {cA σ I} {g : Sat256} {s0 : Sta have rdPush := evm_run rd8 with [raw push2 ⟨1399⟩ hd8 (by evm_ov)] have rdTail := rdPush.jumpiNT hd11 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rdTail + exact RD.solcPush1Dup1Revert0 rdTail (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -4297,7 +4297,7 @@ theorem daiTransferFromX_tailDstOverflowRevertCont {cA σ I} {g : Sat256} {s0 : have rdPush := evm_run rd8 with [raw push2 ⟨1399⟩ hd8 (by evm_ov)] have rdTail := rdPush.jumpiNT hd11 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rdTail + exact RD.solcPush1Dup1Revert0 rdTail (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) diff --git a/Benchmarks/Dss/DaiJoin/Calls.lean b/Benchmarks/Dss/DaiJoin/Calls.lean index 8f496254..010d21db 100644 --- a/Benchmarks/Dss/DaiJoin/Calls.lean +++ b/Benchmarks/Dss/DaiJoin/Calls.lean @@ -50,10 +50,10 @@ theorem daiJoinDaiAddress_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv theorem daiJoinVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (daiJoinVatTargetWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (daiJoinVatTargetWord τ I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (daiJoinVatTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (daiJoinVatTargetWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (daiJoinVatTargetWord σ I) have htarget : daiJoinVatTargetWord σ I = daiJoinVatTargetWord τ I := daiJoinVatTargetWord_accountMapEquiv hAccounts @@ -63,18 +63,18 @@ theorem daiJoinVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execut theorem daiJoinVatCodeSize_ne_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (daiJoinVatTargetWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (daiJoinVatTargetWord τ I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (daiJoinVatTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (daiJoinVatTargetWord τ I) ≠ ⟨0⟩ := by intro hzero exact hne (daiJoinVatCodeSize_zero_accountMapEquiv hAccounts.symm hzero) theorem daiJoinDaiCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (daiJoinDaiTargetWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (daiJoinDaiTargetWord τ I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (daiJoinDaiTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (daiJoinDaiTargetWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (daiJoinDaiTargetWord σ I) have htarget : daiJoinDaiTargetWord σ I = daiJoinDaiTargetWord τ I := daiJoinDaiTargetWord_accountMapEquiv hAccounts @@ -84,8 +84,8 @@ theorem daiJoinDaiCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execut theorem daiJoinDaiCodeSize_ne_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (daiJoinDaiTargetWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (daiJoinDaiTargetWord τ I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (daiJoinDaiTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (daiJoinDaiTargetWord τ I) ≠ ⟨0⟩ := by intro hzero exact hne (daiJoinDaiCodeSize_zero_accountMapEquiv hAccounts.symm hzero) @@ -126,14 +126,14 @@ theorem daiJoinDaiEvmAddress_eq_target_of_accountMapEquiv {σ_evm σ_solm : Acco rw [haddr, daiJoinDaiAddress_eq_target σ_evm I] exact daiJoinEvmAddress_accountAddress _ -theorem daiJoin_uniswapExtCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} +theorem daiJoin_extCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using @@ -145,17 +145,17 @@ theorem daiJoin_uniswapExtCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} theorem daiJoinCode_zero_of_codeSize_zero {evm : EVM.State} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord evm.accountMap target = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [State.lookupAccount] using - daiJoin_uniswapExtCodeSizeWord_zero_lookup_code_zero + daiJoin_extCodeSizeWord_zero_lookup_code_zero (σ := evm.accountMap) haddr hzero theorem daiJoinCode_pos_of_codeSize_ne_zero {evm : EVM.State} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord evm.accountMap target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount addr).option 0 (fun acc => acc.code.size))).toNat := by @@ -169,17 +169,17 @@ theorem daiJoinCode_pos_of_codeSize_ne_zero {evm : EVM.State} {target : UInt256} uint256_toNat_eq_zero hnat have hword : UInt256.ofNat ((evm.lookupAccount addr).option 0 (fun acc => acc.code.size)) = - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap target := by + Reasoning.Theory.extCodeSizeWord evm.accountMap target := by subst addr cases hacc : evm.accountMap.find? (AccountAddress.ofUInt256 target) <;> - simp [State.lookupAccount, Reasoning.Theory.uniswapExtCodeSizeWord, hacc, + simp [State.lookupAccount, Reasoning.Theory.extCodeSizeWord, hacc, Option.option] <;> native_decide exact hne (by rw [← hword, hwordZero]) theorem daiJoinVatCode_zero_of_codeSize_zero {evm : EVM.State} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinVatTargetWord evm.accountMap evm.executionEnv) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (daiJoinVatAddress evm.accountMap evm.executionEnv)).option 0 @@ -189,7 +189,7 @@ theorem daiJoinVatCode_zero_of_codeSize_zero {evm : EVM.State} theorem daiJoinVatCode_pos_of_codeSize_ne_zero {evm : EVM.State} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinVatTargetWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) : 0 < (UInt256.ofNat @@ -200,7 +200,7 @@ theorem daiJoinVatCode_pos_of_codeSize_ne_zero {evm : EVM.State} theorem daiJoinDaiCode_zero_of_codeSize_zero {evm : EVM.State} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinDaiTargetWord evm.accountMap evm.executionEnv) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (daiJoinDaiAddress evm.accountMap evm.executionEnv)).option 0 @@ -210,7 +210,7 @@ theorem daiJoinDaiCode_zero_of_codeSize_zero {evm : EVM.State} theorem daiJoinDaiCode_pos_of_codeSize_ne_zero {evm : EVM.State} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinDaiTargetWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) : 0 < (UInt256.ofNat diff --git a/Benchmarks/Dss/DaiJoin/Dispatch.lean b/Benchmarks/Dss/DaiJoin/Dispatch.lean index ceb2a209..bb8a21c3 100644 --- a/Benchmarks/Dss/DaiJoin/Dispatch.lean +++ b/Benchmarks/Dss/DaiJoin/Dispatch.lean @@ -372,7 +372,7 @@ theorem daiJoinJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : UI have h147 := h.push2 daiJoinDispatchRevertPc hpush (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h147 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h147 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem daiJoinLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -392,7 +392,7 @@ theorem daiJoinLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} |>.selectorArmNotTakenAuto (daiJoinLowArmsWellFormed 3 (by omega)) (heq0 3 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h147 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h147 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem daiJoinHighNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -424,7 +424,7 @@ theorem daiJoinX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem daiJoinX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -447,7 +447,7 @@ theorem daiJoinX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h147 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h147 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem daiJoinX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} diff --git a/Benchmarks/Dss/DaiJoin/Exit.lean b/Benchmarks/Dss/DaiJoin/Exit.lean index 25957a7d..1be3b05f 100644 --- a/Benchmarks/Dss/DaiJoin/Exit.lean +++ b/Benchmarks/Dss/DaiJoin/Exit.lean @@ -693,7 +693,7 @@ theorem daiJoinExitMulSuccess {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} raw and (by native_decide) (by evm_ov), raw push4 joinMoveSelectorPlainWord (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), - uniswapAddress, + address, raw push2 ⟨1377⟩ (by native_decide) (by evm_ov)] have rd1359Norm : ∃ k C, RD daiJoinBytecode I g s0 ⟨1359⟩ [⟨1377⟩, UInt256.ofNat I.codeOwner, solcSourceWord I, joinMoveSelectorPlainWord, @@ -770,7 +770,7 @@ theorem daiJoinExitMulReverts {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} raw and (by native_decide) (by evm_ov), raw push4 joinMoveSelectorPlainWord (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), - uniswapAddress, + address, raw push2 ⟨1377⟩ (by native_decide) (by evm_ov)] have rd1359Norm : ∃ k C, RD daiJoinBytecode I g s0 ⟨1359⟩ [⟨1377⟩, UInt256.ofNat I.codeOwner, solcSourceWord I, joinMoveSelectorPlainWord, @@ -978,10 +978,10 @@ theorem daiJoinExitVatMoveNoCode daiJoinVatTargetWord σ I, exitWadWord I, exitUsrMaskedWord I, ⟨232⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (daiJoinVatTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (daiJoinVatTargetWord σ I) = ⟨0⟩) : RDrev daiJoinBytecode g s0 := by obtain ⟨_, _, rd1451⟩ := daiJoinExitToVatMoveExtcodesizeGuard rd1377 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1451⟩) (okPc := ⟨1463⟩) rd1451 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1451⟩) (okPc := ⟨1463⟩) rd1451 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -994,7 +994,7 @@ theorem daiJoinExitVatMoveCallReady daiJoinVatTargetWord σ I, exitWadWord I, exitUsrMaskedWord I, ⟨232⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (daiJoinVatTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (daiJoinVatTargetWord σ I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD daiJoinBytecode I g s0 ⟨1466⟩ (gasWord :: daiJoinVatTargetWord σ I :: ⟨0⟩ :: ⟨128⟩ :: ⟨100⟩ :: ⟨128⟩ :: ⟨0⟩ :: ⟨228⟩ :: joinMoveSelectorPlainWord :: @@ -1004,7 +1004,7 @@ theorem daiJoinExitVatMoveCallReady ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd1451⟩ := daiJoinExitToVatMoveExtcodesizeGuard rd1377 obtain ⟨gasWord, k', C', rd1466⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1451⟩) (okPc := ⟨1463⟩) rd1451 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1451⟩) (okPc := ⟨1463⟩) rd1451 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1099,7 +1099,7 @@ theorem daiJoinExitVatMoveCallFailed {cA σ σ₀ A I} {g sel : UInt256} (hrdataSize : rdata.size < UInt256.size) : RDrev daiJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1467⟩) (okPc := ⟨1483⟩) rd1467 + exact RD.solcCallSuccessGuardMissing (pc := ⟨1467⟩) (okPc := ⟨1483⟩) rd1467 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1119,7 +1119,7 @@ theorem daiJoinExitVatMoveCallSucceeded {cA σ σ₀ A I} {g sel : UInt256} (⟨228⟩ :: joinMoveSelectorPlainWord :: daiJoinVatTargetWord σ I :: exitWadWord I :: exitUsrMaskedWord I :: ⟨232⟩ :: sel :: []) mem (UInt256.ofNat 8) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨1467⟩) (okPc := ⟨1483⟩) rd1467 + exact RD.solcCallSuccessGuardOk (pc := ⟨1467⟩) (okPc := ⟨1483⟩) rd1467 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1295,11 +1295,11 @@ theorem daiJoinExitDaiMintNoCode (exitMoveCalldataMem I rad solcFreePtrMem) (UInt256.ofNat 8) rdata (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) = ⟨0⟩) : RDrev daiJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd1560⟩ := daiJoinExitVatMoveToDaiMintExtcodesizeGuard rd1485 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1560⟩) (okPc := ⟨1572⟩) rd1560 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1560⟩) (okPc := ⟨1572⟩) rd1560 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1316,7 +1316,7 @@ theorem daiJoinExitDaiMintCallReady (exitMoveCalldataMem I rad solcFreePtrMem) (UInt256.ofNat 8) rdata (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD daiJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1575⟩ (gasWord :: daiJoinDaiTargetWord σ' I :: ⟨0⟩ :: ⟨128⟩ :: ⟨68⟩ :: @@ -1327,7 +1327,7 @@ theorem daiJoinExitDaiMintCallReady (UInt256.ofNat 8) rdata (cA', σ') k' C' := by obtain ⟨_, _, rd1560⟩ := daiJoinExitVatMoveToDaiMintExtcodesizeGuard rd1485 obtain ⟨gasWord, k', C', rd1575⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1560⟩) (okPc := ⟨1572⟩) rd1560 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1560⟩) (okPc := ⟨1572⟩) rd1560 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1392,7 +1392,7 @@ theorem daiJoinExitDaiMintCallFailed (hrdataSize : rdata.size < UInt256.size) : RDrev daiJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1576⟩) (okPc := ⟨1592⟩) rd1576 + exact RD.solcCallSuccessGuardMissing (pc := ⟨1576⟩) (okPc := ⟨1592⟩) rd1576 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1413,7 +1413,7 @@ theorem daiJoinExitDaiMintCallSucceeded (⟨196⟩ :: exitMintSelectorPlainWord :: daiJoinDaiTargetWord σd I :: exitWadWord I :: exitUsrMaskedWord I :: ⟨232⟩ :: sel :: []) mem (UInt256.ofNat 8) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨1576⟩) (okPc := ⟨1592⟩) rd1576 + exact RD.solcCallSuccessGuardOk (pc := ⟨1576⟩) (okPc := ⟨1592⟩) rd1576 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/DaiJoin/ExitRuntime.lean b/Benchmarks/Dss/DaiJoin/ExitRuntime.lean index 2de5711f..98a9f092 100644 --- a/Benchmarks/Dss/DaiJoin/ExitRuntime.lean +++ b/Benchmarks/Dss/DaiJoin/ExitRuntime.lean @@ -83,7 +83,7 @@ theorem daiJoinExitVatNoCodeReverts (evm : EVM.State) (I : ExecutionEnv) (hliveOne : exitLiveWord evm.accountMap evm.executionEnv = ⟨1⟩) (hfit : daiJoinONEWord.toNat * (exitWadWord I).toNat < UInt256.size) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinVatTargetWord evm.accountMap evm.executionEnv) = ⟨0⟩) : ExecTransitionBody config contract evm (exitStore I) exitTransition.body .reverted := by have hlive : @@ -130,7 +130,7 @@ theorem daiJoinExitVatMoveCallFailedReverts (evm evmVat : EVM.State) (hliveOne : exitLiveWord evm.accountMap evm.executionEnv = ⟨1⟩) (hfit : daiJoinONEWord.toNat * (exitWadWord I).toNat < UInt256.size) (hcode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinVatTargetWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -189,7 +189,7 @@ theorem daiJoinExitDaiMintNoCodeAfterVatReverts (evm evmVat : EVM.State) (hliveOne : exitLiveWord evm.accountMap evm.executionEnv = ⟨1⟩) (hfit : daiJoinONEWord.toNat * (exitWadWord I).toNat < UInt256.size) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinVatTargetWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcallMove : typedCallViaEVM config evm @@ -198,7 +198,7 @@ theorem daiJoinExitDaiMintNoCodeAfterVatReverts (evm evmVat : EVM.State) .int (Int.ofNat (daiJoinRadWord (exitWadWord I)).toNat)] (true, evmVat, out) true) (hdaiNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evmVat.accountMap + Reasoning.Theory.extCodeSizeWord evmVat.accountMap (daiJoinDaiTargetWord evmVat.accountMap evmVat.executionEnv) = ⟨0⟩) : ExecTransitionBody config contract evm (exitStore I) exitTransition.body .reverted := by have hlive : @@ -265,7 +265,7 @@ theorem daiJoinExitDaiMintCallFailedAfterVatReverts (evm evmVat evmMint : EVM.St (hliveOne : exitLiveWord evm.accountMap evm.executionEnv = ⟨1⟩) (hfit : daiJoinONEWord.toNat * (exitWadWord I).toNat < UInt256.size) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinVatTargetWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcallMove : typedCallViaEVM config evm @@ -274,7 +274,7 @@ theorem daiJoinExitDaiMintCallFailedAfterVatReverts (evm evmVat evmMint : EVM.St .int (Int.ofNat (daiJoinRadWord (exitWadWord I)).toNat)] (true, evmVat, outMove) true) (hdaiCode : - Reasoning.Theory.uniswapExtCodeSizeWord evmVat.accountMap + Reasoning.Theory.extCodeSizeWord evmVat.accountMap (daiJoinDaiTargetWord evmVat.accountMap evmVat.executionEnv) ≠ ⟨0⟩) (hcallMint : typedCallViaEVM config evmVat @@ -352,7 +352,7 @@ theorem daiJoinExitDaiMintSuccessAfterVatReturns (evm evmVat evmMint : EVM.State (hliveOne : exitLiveWord evm.accountMap evm.executionEnv = ⟨1⟩) (hfit : daiJoinONEWord.toNat * (exitWadWord I).toNat < UInt256.size) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinVatTargetWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcallMove : typedCallViaEVM config evm @@ -361,7 +361,7 @@ theorem daiJoinExitDaiMintSuccessAfterVatReturns (evm evmVat evmMint : EVM.State .int (Int.ofNat (daiJoinRadWord (exitWadWord I)).toNat)] (true, evmVat, outMove) true) (hdaiCode : - Reasoning.Theory.uniswapExtCodeSizeWord evmVat.accountMap + Reasoning.Theory.extCodeSizeWord evmVat.accountMap (daiJoinDaiTargetWord evmVat.accountMap evmVat.executionEnv) ≠ ⟨0⟩) (hcallMint : typedCallViaEVM config evmVat @@ -458,7 +458,7 @@ theorem daiJoinExitVatMoveCallFailedCore (hliveOne : exitLiveWord σ_solm I = ⟨1⟩) (hfit : daiJoinONEWord.toNat * (exitWadWord I).toNat < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd1467 : RD daiJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1467⟩ @@ -484,7 +484,7 @@ theorem daiJoinExitVatMoveCallFailedCore have hrev : RDrev daiJoinBytecode (Sat256.ofUInt256 g) evmE := by simpa [evmE] using daiJoinExitVatMoveCallFailed rd1467 hout have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := daiJoinVatCodeSize_ne_zero_accountMapEquiv hAccounts hcodeSize rcases hΘ with ⟨g'', A', hΘ⟩ have hdepthNe : evmE.executionEnv.depth ≠ 1024 := by @@ -559,9 +559,9 @@ theorem daiJoinExitDaiMintNoCodeCore (hliveOne : exitLiveWord σ_solm I = ⟨1⟩) (hfit : daiJoinONEWord.toNat * (exitWadWord I).toNat < UInt256.size) (hvatCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) (hdaiCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) = ⟨0⟩) (hdepth : I.depth.val < 1024) (rd1485 : RD daiJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1485⟩ @@ -586,7 +586,7 @@ theorem daiJoinExitDaiMintNoCodeCore have hrev : RDrev daiJoinBytecode (Sat256.ofUInt256 g) evmE := by simpa [evmE] using daiJoinExitDaiMintNoCode rd1485 hdaiCodeSize have hvatCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := daiJoinVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCodeSize rcases hΘ with ⟨g'', A', hΘ⟩ have hdepthNe : evmE.executionEnv.depth ≠ 1024 := by @@ -632,7 +632,7 @@ theorem daiJoinExitDaiMintNoCodeCore (by rfl) (by rfl) have hdaiCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm (daiJoinDaiTargetWord σ'_solm I) = ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ'_solm (daiJoinDaiTargetWord σ'_solm I) = ⟨0⟩ := daiJoinDaiCodeSize_zero_accountMapEquiv hAccounts' hdaiCodeSize have hbody : ExecTransitionBody config contract evmS (exitStore I) exitTransition.body .reverted := by @@ -665,9 +665,9 @@ theorem daiJoinExitDaiMintCallFailedCore (hliveOne : exitLiveWord σ_solm I = ⟨1⟩) (hfit : daiJoinONEWord.toNat * (exitWadWord I).toNat < UInt256.size) (hvatCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) (hdaiCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd1576 : RD daiJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1576⟩ @@ -706,7 +706,7 @@ theorem daiJoinExitDaiMintCallFailedCore have hrev : RDrev daiJoinBytecode (Sat256.ofUInt256 g) evmE := by simpa [evmE] using daiJoinExitDaiMintCallFailed rd1576 houtMint have hvatCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := daiJoinVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCodeSize rcases hΘMove with ⟨gMove'', AMove', hΘMove⟩ have hdepthNe : evmE.executionEnv.depth ≠ 1024 := by @@ -752,7 +752,7 @@ theorem daiJoinExitDaiMintCallFailedCore (by rfl) (by rfl) have hdaiCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm (daiJoinDaiTargetWord σ'_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ'_solm (daiJoinDaiTargetWord σ'_solm I) ≠ ⟨0⟩ := daiJoinDaiCodeSize_ne_zero_accountMapEquiv hAccounts' hdaiCodeSize rcases hΘMint with ⟨gMint'', AMint', hΘMint⟩ let evmVatE : EVM.State := @@ -851,9 +851,9 @@ theorem daiJoinExitDaiMintSuccessCore (hliveOne : exitLiveWord σ_solm I = ⟨1⟩) (hfit : daiJoinONEWord.toNat * (exitWadWord I).toNat < UInt256.size) (hvatCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) (hdaiCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd1576 : RD daiJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1576⟩ @@ -918,7 +918,7 @@ theorem daiJoinExitDaiMintSuccessCore (rdata := outMint) (acc := (cA'', σ'')) hperm hmintMemSize hmintRead64 (by simpa using rd1594) have hvatCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := daiJoinVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCodeSize rcases hΘMove with ⟨gMove'', AMove', hΘMove⟩ have hdepthNe : evmE.executionEnv.depth ≠ 1024 := by @@ -964,7 +964,7 @@ theorem daiJoinExitDaiMintSuccessCore (by rfl) (by rfl) have hdaiCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm (daiJoinDaiTargetWord σ'_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ'_solm (daiJoinDaiTargetWord σ'_solm I) ≠ ⟨0⟩ := daiJoinDaiCodeSize_ne_zero_accountMapEquiv hAccounts' hdaiCodeSize rcases hΘMint with ⟨gMint'', AMint', hΘMint⟩ let evmVatE : EVM.State := @@ -1091,13 +1091,13 @@ theorem daiJoinExitBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ_evm) k C) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) = ⟨0⟩ · have hrev : RDrev daiJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := daiJoinExitVatMoveNoCode rd1377 hvatCode have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) = ⟨0⟩ := daiJoinVatCodeSize_zero_accountMapEquiv hAccounts hvatCode have hbody : @@ -1126,7 +1126,7 @@ theorem daiJoinExitBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} · obtain ⟨_, _, rd1485⟩ := daiJoinExitVatMoveCallSucceeded (by simpa using rd1467) by_cases hdaiCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) = ⟨0⟩ · exact daiJoinExitDaiMintNoCodeCore (cA := cA) (cA' := cA') (gh := gh) (bl := bl) @@ -1170,7 +1170,7 @@ theorem daiJoinExitBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} daiJoinExitVatMoveCallFailed rd1467 (by simp [UInt256.size]) let evmS := initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := daiJoinVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hcallSolm : diff --git a/Benchmarks/Dss/DaiJoin/Join.lean b/Benchmarks/Dss/DaiJoin/Join.lean index cbd51935..3f3b312a 100644 --- a/Benchmarks/Dss/DaiJoin/Join.lean +++ b/Benchmarks/Dss/DaiJoin/Join.lean @@ -388,7 +388,7 @@ theorem daiJoinJoinVatNoCodeReverts (evm : EVM.State) (I : ExecutionEnv) (hwv : evm.executionEnv.weiValue = ⟨0⟩) (hfit : daiJoinONEWord.toNat * (joinWadWord I).toNat < UInt256.size) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinVatTargetWord evm.accountMap evm.executionEnv) = ⟨0⟩) : ExecTransitionBody config contract evm (joinStore I) joinTransition.body .reverted := by have hmulStmt := @@ -423,7 +423,7 @@ theorem daiJoinJoinVatMoveCallFailedReverts (evm evmVat : EVM.State) (hwv : evm.executionEnv.weiValue = ⟨0⟩) (hfit : daiJoinONEWord.toNat * (joinWadWord I).toNat < UInt256.size) (hcode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinVatTargetWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -471,7 +471,7 @@ theorem daiJoinJoinDaiBurnNoCodeAfterVatReverts (evm evmVat : EVM.State) (hwv : evm.executionEnv.weiValue = ⟨0⟩) (hfit : daiJoinONEWord.toNat * (joinWadWord I).toNat < UInt256.size) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinVatTargetWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcallMove : typedCallViaEVM config evm @@ -481,7 +481,7 @@ theorem daiJoinJoinDaiBurnNoCodeAfterVatReverts (evm evmVat : EVM.State) .int (Int.ofNat (daiJoinRadWord (joinWadWord I)).toNat)] (true, evmVat, out) true) (hdaiNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evmVat.accountMap + Reasoning.Theory.extCodeSizeWord evmVat.accountMap (daiJoinDaiTargetWord evmVat.accountMap evmVat.executionEnv) = ⟨0⟩) : ExecTransitionBody config contract evm (joinStore I) joinTransition.body .reverted := by have hmulStmt := @@ -545,7 +545,7 @@ theorem daiJoinJoinDaiBurnCallFailedAfterVatReverts (evm evmVat evmBurn : EVM.St (hwv : evm.executionEnv.weiValue = ⟨0⟩) (hfit : daiJoinONEWord.toNat * (joinWadWord I).toNat < UInt256.size) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinVatTargetWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcallMove : typedCallViaEVM config evm @@ -555,7 +555,7 @@ theorem daiJoinJoinDaiBurnCallFailedAfterVatReverts (evm evmVat evmBurn : EVM.St .int (Int.ofNat (daiJoinRadWord (joinWadWord I)).toNat)] (true, evmVat, outMove) true) (hdaiCode : - Reasoning.Theory.uniswapExtCodeSizeWord evmVat.accountMap + Reasoning.Theory.extCodeSizeWord evmVat.accountMap (daiJoinDaiTargetWord evmVat.accountMap evmVat.executionEnv) ≠ ⟨0⟩) (hcallBurn : typedCallViaEVM config evmVat @@ -630,7 +630,7 @@ theorem daiJoinJoinDaiBurnSuccessAfterVatReturns (evm evmVat evmBurn : EVM.State (hwv : evm.executionEnv.weiValue = ⟨0⟩) (hfit : daiJoinONEWord.toNat * (joinWadWord I).toNat < UInt256.size) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (daiJoinVatTargetWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcallMove : typedCallViaEVM config evm @@ -640,7 +640,7 @@ theorem daiJoinJoinDaiBurnSuccessAfterVatReturns (evm evmVat evmBurn : EVM.State .int (Int.ofNat (daiJoinRadWord (joinWadWord I)).toNat)] (true, evmVat, outMove) true) (hdaiCode : - Reasoning.Theory.uniswapExtCodeSizeWord evmVat.accountMap + Reasoning.Theory.extCodeSizeWord evmVat.accountMap (daiJoinDaiTargetWord evmVat.accountMap evmVat.executionEnv) ≠ ⟨0⟩) (hcallBurn : typedCallViaEVM config evmVat @@ -734,7 +734,7 @@ theorem daiJoinJoinVatMoveCallFailedCore (hAccounts : accountMapEquiv σ_evm σ_solm) (hfit : daiJoinONEWord.toNat * (joinWadWord I).toNat < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd580 : RD daiJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨580⟩ @@ -760,7 +760,7 @@ theorem daiJoinJoinVatMoveCallFailedCore have hrev : RDrev daiJoinBytecode (Sat256.ofUInt256 g) evmE := by simpa [evmE] using daiJoinJoinVatMoveCallFailed rd580 hout have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := daiJoinVatCodeSize_ne_zero_accountMapEquiv hAccounts hcodeSize rcases hΘ with ⟨g'', A', hΘ⟩ have hdepthNe : evmE.executionEnv.depth ≠ 1024 := by @@ -832,9 +832,9 @@ theorem daiJoinJoinDaiBurnNoCodeCore (hAccounts : accountMapEquiv σ_evm σ_solm) (hfit : daiJoinONEWord.toNat * (joinWadWord I).toNat < UInt256.size) (hvatCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) (hdaiCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) = ⟨0⟩) (hdepth : I.depth.val < 1024) (rd598 : RD daiJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨598⟩ @@ -859,7 +859,7 @@ theorem daiJoinJoinDaiBurnNoCodeCore have hrev : RDrev daiJoinBytecode (Sat256.ofUInt256 g) evmE := by simpa [evmE] using daiJoinJoinDaiBurnNoCode rd598 hdaiCodeSize have hvatCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := daiJoinVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCodeSize rcases hΘ with ⟨g'', A', hΘ⟩ have hdepthNe : evmE.executionEnv.depth ≠ 1024 := by @@ -905,7 +905,7 @@ theorem daiJoinJoinDaiBurnNoCodeCore (by rfl) (by rfl) have hdaiCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm (daiJoinDaiTargetWord σ'_solm I) = ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ'_solm (daiJoinDaiTargetWord σ'_solm I) = ⟨0⟩ := daiJoinDaiCodeSize_zero_accountMapEquiv hAccounts' hdaiCodeSize have hbody : ExecTransitionBody config contract evmS (joinStore I) joinTransition.body .reverted := by @@ -935,9 +935,9 @@ theorem daiJoinJoinDaiBurnCallFailedCore (hAccounts : accountMapEquiv σ_evm σ_solm) (hfit : daiJoinONEWord.toNat * (joinWadWord I).toNat < UInt256.size) (hvatCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) (hdaiCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd687 : RD daiJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨687⟩ @@ -976,7 +976,7 @@ theorem daiJoinJoinDaiBurnCallFailedCore have hrev : RDrev daiJoinBytecode (Sat256.ofUInt256 g) evmE := by simpa [evmE] using daiJoinJoinDaiBurnCallFailed rd687 houtBurn have hvatCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := daiJoinVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCodeSize rcases hΘMove with ⟨gMove'', AMove', hΘMove⟩ have hdepthNe : evmE.executionEnv.depth ≠ 1024 := by @@ -1022,7 +1022,7 @@ theorem daiJoinJoinDaiBurnCallFailedCore (by rfl) (by rfl) have hdaiCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm (daiJoinDaiTargetWord σ'_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ'_solm (daiJoinDaiTargetWord σ'_solm I) ≠ ⟨0⟩ := daiJoinDaiCodeSize_ne_zero_accountMapEquiv hAccounts' hdaiCodeSize rcases hΘBurn with ⟨gBurn'', ABurn', hΘBurn⟩ let evmVatE : EVM.State := @@ -1118,9 +1118,9 @@ theorem daiJoinJoinDaiBurnSuccessCore (hAccounts : accountMapEquiv σ_evm σ_solm) (hfit : daiJoinONEWord.toNat * (joinWadWord I).toNat < UInt256.size) (hvatCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) ≠ ⟨0⟩) (hdaiCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd687 : RD daiJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨687⟩ @@ -1185,7 +1185,7 @@ theorem daiJoinJoinDaiBurnSuccessCore (rdata := outBurn) (acc := (cA'', σ'')) hperm hburnMemSize hburnRead64 (by simpa using rd705) have hvatCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := daiJoinVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCodeSize rcases hΘMove with ⟨gMove'', AMove', hΘMove⟩ have hdepthNe : evmE.executionEnv.depth ≠ 1024 := by @@ -1231,7 +1231,7 @@ theorem daiJoinJoinDaiBurnSuccessCore (by rfl) (by rfl) have hdaiCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm (daiJoinDaiTargetWord σ'_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ'_solm (daiJoinDaiTargetWord σ'_solm I) ≠ ⟨0⟩ := daiJoinDaiCodeSize_ne_zero_accountMapEquiv hAccounts' hdaiCodeSize rcases hΘBurn with ⟨gBurn'', ABurn', hΘBurn⟩ let evmVatE : EVM.State := @@ -1349,13 +1349,13 @@ theorem daiJoinJoinBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rw [hwad] native_decide by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) = ⟨0⟩ · have hrev : RDrev daiJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := daiJoinJoinVatMoveNoCode rd490 hvatCode have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) = ⟨0⟩ := daiJoinVatCodeSize_zero_accountMapEquiv hAccounts hvatCode have hbody : @@ -1383,7 +1383,7 @@ theorem daiJoinJoinBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} · obtain ⟨_, _, rd598⟩ := daiJoinJoinVatMoveCallSucceeded (by simpa using rd580) by_cases hdaiCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) = ⟨0⟩ · exact daiJoinJoinDaiBurnNoCodeCore (cA := cA) (cA' := cA') (gh := gh) (bl := bl) @@ -1427,7 +1427,7 @@ theorem daiJoinJoinBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} daiJoinJoinVatMoveCallFailed rd580 (by simp [UInt256.size]) let evmS := initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := daiJoinVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hcallSolm : @@ -1477,13 +1477,13 @@ theorem daiJoinJoinBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hfit : daiJoinONEWord.toNat * (joinWadWord I).toNat < UInt256.size := daiJoinMulFit_of_guard hguard by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (daiJoinVatTargetWord σ_evm I) = ⟨0⟩ · have hrev : RDrev daiJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := daiJoinJoinVatMoveNoCode rd490 hvatCode have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) = ⟨0⟩ := daiJoinVatCodeSize_zero_accountMapEquiv hAccounts hvatCode have hbody : @@ -1511,7 +1511,7 @@ theorem daiJoinJoinBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} · obtain ⟨_, _, rd598⟩ := daiJoinJoinVatMoveCallSucceeded (by simpa using rd580) by_cases hdaiCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) = ⟨0⟩ · exact daiJoinJoinDaiBurnNoCodeCore (cA := cA) (cA' := cA') (gh := gh) (bl := bl) @@ -1555,7 +1555,7 @@ theorem daiJoinJoinBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} daiJoinJoinVatMoveCallFailed rd580 (by simp [UInt256.size]) let evmS := initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (daiJoinVatTargetWord σ_solm I) ≠ ⟨0⟩ := daiJoinVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hcallSolm : diff --git a/Benchmarks/Dss/DaiJoin/JoinTrace.lean b/Benchmarks/Dss/DaiJoin/JoinTrace.lean index bf335728..3e120871 100644 --- a/Benchmarks/Dss/DaiJoin/JoinTrace.lean +++ b/Benchmarks/Dss/DaiJoin/JoinTrace.lean @@ -446,7 +446,7 @@ theorem daiJoinJoinToMul {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} simpa [daiJoinVatTargetWord, daiJoinAddressReturnWord, hmaskConst, u256_land_comm] using rd467⟩ obtain ⟨_, _, rd467'⟩ := rd467Norm - have rd468 := RD.uniswapAddress rd467' (by native_decide) (by evm_ov) + have rd468 := RD.address rd467' (by native_decide) (by evm_ov) have rd468Norm : ∃ k C, RD daiJoinBytecode I g s0 ⟨468⟩ [UInt256.ofNat I.codeOwner, joinMoveSelectorPlainWord, daiJoinVatTargetWord σ I, joinWadWord I, joinUsrMaskedWord I, ⟨232⟩, sel] @@ -671,10 +671,10 @@ theorem daiJoinJoinVatMoveNoCode {cA σ I} {g : Sat256} {s0 : State} daiJoinVatTargetWord σ I, joinWadWord I, joinUsrMaskedWord I, ⟨232⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (daiJoinVatTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (daiJoinVatTargetWord σ I) = ⟨0⟩) : RDrev daiJoinBytecode g s0 := by obtain ⟨_, _, rd564⟩ := daiJoinJoinToVatMoveExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨564⟩) (okPc := ⟨576⟩) rd564 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨564⟩) (okPc := ⟨576⟩) rd564 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -687,7 +687,7 @@ theorem daiJoinJoinVatMoveCallReady {cA σ I} {g : Sat256} {s0 : State} daiJoinVatTargetWord σ I, joinWadWord I, joinUsrMaskedWord I, ⟨232⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (daiJoinVatTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (daiJoinVatTargetWord σ I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD daiJoinBytecode I g s0 ⟨579⟩ (gasWord :: daiJoinVatTargetWord σ I :: ⟨0⟩ :: ⟨128⟩ :: ⟨100⟩ :: ⟨128⟩ :: ⟨0⟩ :: ⟨228⟩ :: joinMoveSelectorPlainWord :: @@ -697,7 +697,7 @@ theorem daiJoinJoinVatMoveCallReady {cA σ I} {g : Sat256} {s0 : State} ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd564⟩ := daiJoinJoinToVatMoveExtcodesizeGuard h obtain ⟨gasWord, k', C', rd579⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨564⟩) (okPc := ⟨576⟩) rd564 + RD.solcExtcodesizeGuardOkGas (pc := ⟨564⟩) (okPc := ⟨576⟩) rd564 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -790,7 +790,7 @@ theorem daiJoinJoinVatMoveCallFailed {cA gh bl σ σ₀ A I} {g sel : UInt256} (hrdataSize : rdata.size < UInt256.size) : RDrev daiJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨580⟩) (okPc := ⟨596⟩) rd580 + exact RD.solcCallSuccessGuardMissing (pc := ⟨580⟩) (okPc := ⟨596⟩) rd580 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -810,7 +810,7 @@ theorem daiJoinJoinVatMoveCallSucceeded {cA gh bl σ σ₀ A I} {g sel : UInt256 (⟨228⟩ :: joinMoveSelectorPlainWord :: daiJoinVatTargetWord σ I :: joinWadWord I :: joinUsrMaskedWord I :: ⟨232⟩ :: sel :: []) mem (UInt256.ofNat 8) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨580⟩) (okPc := ⟨596⟩) rd580 + exact RD.solcCallSuccessGuardOk (pc := ⟨580⟩) (okPc := ⟨596⟩) rd580 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -977,11 +977,11 @@ theorem daiJoinJoinDaiBurnNoCode (joinMoveCalldataMem I rad solcFreePtrMem) (UInt256.ofNat 8) rdata (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) = ⟨0⟩) : RDrev daiJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd671⟩ := daiJoinJoinVatMoveToDaiBurnExtcodesizeGuard rd598 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨671⟩) (okPc := ⟨683⟩) rd671 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨671⟩) (okPc := ⟨683⟩) rd671 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -998,7 +998,7 @@ theorem daiJoinJoinDaiBurnCallReady (joinMoveCalldataMem I rad solcFreePtrMem) (UInt256.ofNat 8) rdata (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (daiJoinDaiTargetWord σ' I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD daiJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨686⟩ (gasWord :: daiJoinDaiTargetWord σ' I :: ⟨0⟩ :: ⟨128⟩ :: ⟨68⟩ :: @@ -1009,7 +1009,7 @@ theorem daiJoinJoinDaiBurnCallReady (UInt256.ofNat 8) rdata (cA', σ') k' C' := by obtain ⟨_, _, rd671⟩ := daiJoinJoinVatMoveToDaiBurnExtcodesizeGuard rd598 obtain ⟨gasWord, k', C', rd686⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨671⟩) (okPc := ⟨683⟩) rd671 + RD.solcExtcodesizeGuardOkGas (pc := ⟨671⟩) (okPc := ⟨683⟩) rd671 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1106,7 +1106,7 @@ theorem daiJoinJoinDaiBurnCallFailed (hrdataSize : rdata.size < UInt256.size) : RDrev daiJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨687⟩) (okPc := ⟨703⟩) rd687 + exact RD.solcCallSuccessGuardMissing (pc := ⟨687⟩) (okPc := ⟨703⟩) rd687 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1127,7 +1127,7 @@ theorem daiJoinJoinDaiBurnCallSucceeded (⟨196⟩ :: joinBurnSelectorPlainWord :: daiJoinDaiTargetWord σd I :: joinWadWord I :: joinUsrMaskedWord I :: ⟨232⟩ :: sel :: []) mem (UInt256.ofNat 8) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨687⟩) (okPc := ⟨703⟩) rd687 + exact RD.solcCallSuccessGuardOk (pc := ⟨687⟩) (okPc := ⟨703⟩) rd687 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/DaiJoin/Mul.lean b/Benchmarks/Dss/DaiJoin/Mul.lean index f8fe1668..152a2400 100644 --- a/Benchmarks/Dss/DaiJoin/Mul.lean +++ b/Benchmarks/Dss/DaiJoin/Mul.lean @@ -506,7 +506,7 @@ theorem daiJoinMulRoutine_revert {code : ByteArray} {ee : ExecutionEnv} {g : Sat exact u256_eq_of_ne hguard rw [heq0] at rd1709 have rd1710 := rd1709.jumpiNT hd1709 rfl (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd1710 hd1710 hd1712 hd1713 (by evm_ov) + exact RD.solcPush1Dup1Revert0 rd1710 hd1710 hd1712 hd1713 (by evm_ov) theorem daiJoinMulRoutine_shape : decode daiJoinBytecode ⟨1678⟩ = some (.JUMPDEST, .none) ∧ diff --git a/Benchmarks/Dss/DaiJoin/SpecSyntax.lean b/Benchmarks/Dss/DaiJoin/SpecSyntax.lean index 62f7c682..d0833a70 100644 --- a/Benchmarks/Dss/DaiJoin/SpecSyntax.lean +++ b/Benchmarks/Dss/DaiJoin/SpecSyntax.lean @@ -2,19 +2,86 @@ import Benchmarks.Dss.DaiJoin.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS DaiJoin spec through the Solm notation frontend +# DaiJoin spec in the Solidity-faithful Solm frontend -The main spec lives in `Spec.lean`; this companion keeps the benchmark's notation-side check wired -up as the body surface grows. +The whole DaiJoin benchmark spec, written with `solidity%` and proven definitionally equal to the +AST spec in `Benchmarks/Dss/DaiJoin/Spec.lean`. The `extCodeSize` guards on storage receivers +(`vat`, `dai`) use the `${…}` expression escape (surface `x.code.length` only covers locals). +Transition order matches `contract.transitions` (selector order). -/ open Solm Solm.Notation namespace Benchmarks.Dss.DaiJoin.Syntax -def contractSyntax : ContractDecl := Benchmarks.Dss.DaiJoin.contract +def contractSyntax : ContractDecl := solidity% contract DaiJoin { + mapping(address => uint256) wards; + address vat; + address dai; + uint256 live; -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.DaiJoin.contract := by - rfl + constructor(address vat_, address dai_) { + wards[msg.sender] = 1; + live = 1; + vat = vat_; + dai = dai_; + } + + function mul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + return z; + } + + function cage() external { + require(wards[msg.sender] == 1); + live = 0; + } + + function dai() external returns (address) { + return dai; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function exit(address usr, uint256 wad) external { + require(live == 1); + uint256 rad = mul(#ONE, wad); + require(${Expr.extCodeSize (Expr.storage vatRef)} > 0); + var moveRet = vat.move(msg.sender, this, rad); + require(${Expr.extCodeSize (Expr.storage daiRef)} > 0); + var mintRet = dai.mint(usr, wad); + } + + function join(address usr, uint256 wad) external { + uint256 rad = mul(#ONE, wad); + require(${Expr.extCodeSize (Expr.storage vatRef)} > 0); + var moveRet = vat.move(this, usr, rad); + require(${Expr.extCodeSize (Expr.storage daiRef)} > 0); + var burnRet = dai.burn(msg.sender, wad); + } + + function live() external returns (uint256) { + return live; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 1; + } + + function vat() external returns (address) { + return vat; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.DaiJoin.contract := by rfl end Benchmarks.Dss.DaiJoin.Syntax diff --git a/Benchmarks/Dss/Dog/Bark.lean b/Benchmarks/Dss/Dog/Bark.lean index 31e3a72f..e2f453af 100644 --- a/Benchmarks/Dss/Dog/Bark.lean +++ b/Benchmarks/Dss/Dog/Bark.lean @@ -6431,34 +6431,34 @@ theorem barkVat_eq_vatKey (v : DogImmutables) : theorem barkVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {v : DogImmutables} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (barkVatWord v) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (barkVatWord v) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts (barkVatWord v) + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (barkVatWord v) rw [← hsame] exact hzero theorem barkVatCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {v : DogImmutables} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (barkVatWord v) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (barkVatWord v) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts (barkVatWord v) + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (barkVatWord v) rw [hsame] exact hzero theorem barkVatCode_zero_of_codeSize_zero {v : DogImmutables} {cA gh bl σ σ₀ A I} {g : UInt256} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (AccountAddress.ofNat v.vat.toNat)).option 0 (fun acc => acc.code.size))).toNat = 0 := by rw [barkVat_eq_vatKey v] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 (barkVatWord v)) with | none => simpa [initState, State.lookupAccount, hacc, Option.option] using @@ -6470,12 +6470,12 @@ theorem barkVatCode_zero_of_codeSize_zero {v : DogImmutables} theorem barkVatCode_pos_of_codeSize_ne {v : DogImmutables} {cA gh bl σ σ₀ A I} {g : UInt256} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (AccountAddress.ofNat v.vat.toNat)).option 0 (fun acc => acc.code.size))).toNat := by rw [barkVat_eq_vatKey v] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : σ.find? (AccountAddress.ofUInt256 (barkVatWord v)) with | none => exfalso @@ -6496,12 +6496,12 @@ theorem barkVatCode_pos_of_codeSize_ne {v : DogImmutables} theorem barkVatCode_zero_of_state_codeSize_zero {v : DogImmutables} {evm : EVM.State} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (barkVatWord v) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord evm.accountMap (barkVatWord v) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (AccountAddress.ofNat v.vat.toNat)).option 0 (fun acc => acc.code.size))).toNat = 0 := by rw [barkVat_eq_vatKey v] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : evm.accountMap.find? (AccountAddress.ofUInt256 (barkVatWord v)) with | none => simpa [State.lookupAccount, hacc, Option.option] using @@ -6512,12 +6512,12 @@ theorem barkVatCode_zero_of_state_codeSize_zero {v : DogImmutables} {evm : EVM.S theorem barkVatCode_pos_of_state_codeSize_ne {v : DogImmutables} {evm : EVM.State} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (barkVatWord v) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord evm.accountMap (barkVatWord v) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (AccountAddress.ofNat v.vat.toNat)).option 0 (fun acc => acc.code.size))).toNat := by rw [barkVat_eq_vatKey v] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : evm.accountMap.find? (AccountAddress.ofUInt256 (barkVatWord v)) with | none => exfalso @@ -6538,12 +6538,12 @@ theorem barkVatCode_pos_of_state_codeSize_ne {v : DogImmutables} {evm : EVM.Stat theorem dogCode_zero_of_state_codeSize_zero {evm : EVM.State} {targetWord : UInt256} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap targetWord = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord evm.accountMap targetWord = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (AccountAddress.ofNat targetWord.toNat)).option 0 (fun acc => acc.code.size))).toNat = 0 := by rw [← accountAddress_ofUInt256_eq_ofNat_toNat targetWord] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : evm.accountMap.find? (AccountAddress.ofUInt256 targetWord) with | none => simpa [State.lookupAccount, hacc, Option.option] using @@ -6554,12 +6554,12 @@ theorem dogCode_zero_of_state_codeSize_zero {evm : EVM.State} {targetWord : UInt theorem dogCode_pos_of_state_codeSize_ne {evm : EVM.State} {targetWord : UInt256} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap targetWord ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord evm.accountMap targetWord ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (AccountAddress.ofNat targetWord.toNat)).option 0 (fun acc => acc.code.size))).toNat := by rw [← accountAddress_ofUInt256_eq_ofNat_toNat targetWord] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : evm.accountMap.find? (AccountAddress.ofUInt256 targetWord) with | none => exfalso @@ -6581,22 +6581,22 @@ theorem dogCode_pos_of_state_codeSize_ne {evm : EVM.State} {targetWord : UInt256 theorem dogCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {targetWord : UInt256} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ targetWord = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ targetWord = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ targetWord = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ targetWord = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts targetWord + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts targetWord rw [← hsame] exact hzero theorem dogCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {targetWord : UInt256} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ targetWord ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ targetWord ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ targetWord ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ targetWord ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts targetWord + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts targetWord rw [hsame] exact hzero @@ -13755,7 +13755,7 @@ theorem RD.dogCheckedMulOverflowReverts {v : DogImmutables} {code : ByteArray} rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] native_decide) heqCond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] native_decide) @@ -13872,7 +13872,7 @@ theorem RD.dogCheckedAddOverflowReverts {v : DogImmutables} {code : ByteArray} native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by simp only [List.length_cons]; omega) - exact RD.uniswapPush1Dup1Revert0 rd4637 + exact RD.solcPush1Dup1Revert0 rd4637 (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] native_decide) @@ -14585,14 +14585,14 @@ theorem RD.dogBarkVatUrnsNoCodeRevert {v : DogImmutables} {code : ByteArray} mem (UInt256.ofNat 3) rdata (cA, σ) k C) (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) = ⟨0⟩) (hov : R.length + 24 ≤ 1024) : RDrev code g s0 := by obtain ⟨_, _, rd2941⟩ := RD.dogBarkVatUrnsToCallMload hpatch h hmem hread64 (by omega) obtain ⟨_, _, rd2992⟩ := RD.dogBarkVatUrnsToExtcodesize hpatch rd2941 hmem hread64 hov - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2992⟩) (okPc := ⟨3004⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2992⟩) (okPc := ⟨3004⟩) rd2992 hcodeSize (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] @@ -14634,7 +14634,7 @@ theorem RD.dogBarkVatUrnsToStaticcall {v : DogImmutables} {code : ByteArray} (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) (hov : R.length + 24 ≤ 1024) : ∃ gasWord k' C', RD code I g s0 ⟨3007⟩ (gasWord :: barkVatWord v :: ⟨128⟩ :: ⟨68⟩ :: ⟨128⟩ :: ⟨64⟩ :: @@ -14646,7 +14646,7 @@ theorem RD.dogBarkVatUrnsToStaticcall {v : DogImmutables} {code : ByteArray} obtain ⟨_, _, rd2992⟩ := RD.dogBarkVatUrnsToExtcodesize hpatch rd2941 hmem hread64 hov obtain ⟨gasWord, k', C', rd3007⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2992⟩) (okPc := ⟨3004⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨2992⟩) (okPc := ⟨3004⟩) rd2992 hcodeSize (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] @@ -14690,7 +14690,7 @@ theorem RD.dogBarkVatUrnsPostStaticcall {v : DogImmutables} {code : ByteArray} (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hov : R.length + 24 ≤ 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) @@ -14711,7 +14711,7 @@ theorem RD.dogBarkVatUrnsPostStaticcall {v : DogImmutables} {code : ByteArray} obtain ⟨_, _, _, rd3007⟩ := RD.dogBarkVatUrnsToStaticcall hpatch h hmem hread64 hcodeSize hov obtain ⟨cA', σ', z, out, A_in, callGas, k', C', hΘpack, rd3008raw, hosz⟩ := - RD.uniswapStaticcall rd3007 + RD.solcStaticcall rd3007 (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] native_decide) @@ -14777,7 +14777,7 @@ theorem RD.dogBarkVatUrnsCallFailure {v : DogImmutables} {code : ByteArray} (hrdataSize : rdata.size < UInt256.size) (hov : R.length + 5 ≤ 1024) : RDrev code g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3008⟩) (okPc := ⟨3024⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨3008⟩) (okPc := ⟨3024⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] @@ -14828,7 +14828,7 @@ theorem RD.dogBarkVatUrnsCallSuccessToDecode {v : DogImmutables} {code : ByteArr (hov : R.length + 6 ≤ 1024) : ∃ k' C', RD code I g s0 ⟨3026⟩ (d0 :: d1 :: d2 :: R) mem aw rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨3008⟩) (okPc := ⟨3024⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨3008⟩) (okPc := ⟨3024⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] @@ -14938,7 +14938,7 @@ theorem RD.dogBarkVatUrnsReturnDecodeShortReverts {v : DogImmutables} {code : By native_decide) hcond (by simp only [List.length_cons]; omega) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] native_decide) @@ -16124,7 +16124,7 @@ theorem RD.dogBarkVatIlksToStaticcall {v : DogImmutables} {code : ByteArray} (barkIlksMem σ I mem out) (UInt256.ofNat 12) rdata (cA, σ) k C) (hmem : mem.size = 96) (hlong : 64 ≤ out.size) (hout : out.size < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) (hov : R.length + 40 ≤ 1024) : ∃ gasWord k' C', RD code I g s0 ⟨3244⟩ (gasWord :: barkVatWord v :: ⟨384⟩ :: ⟨36⟩ :: ⟨384⟩ :: ⟨160⟩ :: @@ -16136,7 +16136,7 @@ theorem RD.dogBarkVatIlksToStaticcall {v : DogImmutables} {code : ByteArray} obtain ⟨_, _, rd3229⟩ := RD.dogBarkVatIlksToExtcodesize hpatch rd hmem hlong hout (by omega) obtain ⟨gasWord, k', C', rd3244⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3229⟩) (okPc := ⟨3241⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨3229⟩) (okPc := ⟨3241⟩) rd3229 hcodeSize (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] @@ -16182,7 +16182,7 @@ theorem RD.dogBarkVatIlksPostStaticcall {v : DogImmutables} {code : ByteArray} (hsz100 : 100 ≤ I.calldata.size) (hmem : mem.size = 96) (hlong : 64 ≤ out.size) (hout : out.size < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) (hevmEnv : evm.executionEnv = I) (hevmCreated : evm.createdAccounts = cA) (hevmMap : evm.accountMap = σ) @@ -16210,7 +16210,7 @@ theorem RD.dogBarkVatIlksPostStaticcall {v : DogImmutables} {code : ByteArray} obtain ⟨_, _, _, rd3244⟩ := RD.dogBarkVatIlksToStaticcall hpatch rd hmem hlong hout hcodeSize hov obtain ⟨cA', σ', z, outIlks, A_in, callGas, k', C', hΘpack, rd3245raw, hosz⟩ := - RD.uniswapStaticcall rd3244 + RD.solcStaticcall rd3244 (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] native_decide) @@ -16276,12 +16276,12 @@ theorem RD.dogBarkVatIlksNoCodeRevert {v : DogImmutables} {code : ByteArray} barkKprKey I :: barkUrnKey I :: barkIlkWord I :: ret :: sel :: R) (barkIlksMem σ I mem out) (UInt256.ofNat 12) rdata (cA, σ) k C) (hmem : mem.size = 96) (hlong : 64 ≤ out.size) (hout : out.size < UInt256.size) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) = ⟨0⟩) (hov : R.length + 40 ≤ 1024) : RDrev code g s0 := by obtain ⟨_, _, rd3229⟩ := RD.dogBarkVatIlksToExtcodesize hpatch rd hmem hlong hout (by omega) - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3229⟩) (okPc := ⟨3241⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3229⟩) (okPc := ⟨3241⟩) rd3229 hcodeSize (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] @@ -16321,7 +16321,7 @@ theorem RD.dogBarkVatIlksCallFailure {v : DogImmutables} {code : ByteArray} (hrdataSize : rdata.size < UInt256.size) (hov : R.length + 5 ≤ 1024) : RDrev code g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3245⟩) (okPc := ⟨3261⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨3245⟩) (okPc := ⟨3261⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] @@ -16377,7 +16377,7 @@ theorem RD.dogBarkVatIlksCallSuccessToDecode {v : DogImmutables} {code : ByteArr (d0 :: d1 :: d2 :: d3 :: d4 :: d5 :: d6 :: d7 :: d8 :: d9 :: d10 :: d11 :: d12 :: d13 :: ret :: sel :: R) mem aw out acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨3245⟩) (okPc := ⟨3261⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨3245⟩) (okPc := ⟨3261⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] @@ -16492,7 +16492,7 @@ theorem RD.dogBarkVatIlksReturnDecodeShortReverts {v : DogImmutables} {code : By native_decide) hcond (by simp only [List.length_cons]; omega) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] native_decide) @@ -20679,10 +20679,10 @@ theorem RD.dogBarkVatGrabNoCodeRevert {v : DogImmutables} {code : ByteArray} (hpatch : patchRuntime dogBytecode (patches v) = some code) (rd4023 : RD code I g s0 ⟨4023⟩ (barkVatWord v :: barkVatWord v :: R) mem (UInt256.ofNat 19) rdata (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) = ⟨0⟩) (hov : R.length + 4 ≤ 1024) : RDrev code g s0 := by - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4023⟩) (okPc := ⟨4035⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4023⟩) (okPc := ⟨4035⟩) rd4023 hcodeSize (by rw [dogDecodePatchedEqTemplatePrecise hpatch (by native_decide) (by native_decide) @@ -20730,12 +20730,12 @@ theorem RD.dogBarkVatGrabToCall {v : DogImmutables} {code : ByteArray} (hpatch : patchRuntime dogBytecode (patches v) = some code) (rd4023 : RD code I g s0 ⟨4023⟩ (barkVatWord v :: barkVatWord v :: R) mem (UInt256.ofNat 19) rdata (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) (hov : R.length + 4 ≤ 1024) : ∃ gasWord k' C', RD code I g s0 ⟨4038⟩ (gasWord :: barkVatWord v :: R) mem (UInt256.ofNat 19) rdata (cA, σ) k' C' := by obtain ⟨gasWord, k', C', rd4038⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4023⟩) (okPc := ⟨4035⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨4023⟩) (okPc := ⟨4035⟩) rd4023 hcodeSize (by rw [dogDecodePatchedEqTemplatePrecise hpatch (by native_decide) (by native_decide) @@ -20786,7 +20786,7 @@ theorem RD.dogBarkVatGrabCallFailure {v : DogImmutables} {code : ByteArray} (hrdataSize : rdata.size < UInt256.size) (hov : R.length + 5 ≤ 1024) : RDrev code g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨4039⟩) (okPc := ⟨4055⟩) rd4039 + exact RD.solcCallSuccessGuardMissing (pc := ⟨4039⟩) (okPc := ⟨4055⟩) rd4039 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by rw [dogDecodePatchedEqTemplatePrecise hpatch (by native_decide) (by native_decide) @@ -20846,7 +20846,7 @@ theorem RD.dogBarkVatGrabCallSuccess {v : DogImmutables} {code : ByteArray} (rd4039 : RD code I g s0 ⟨4039⟩ (⟨1⟩ :: R) mem aw rdata acc k C) (hov : R.length + 3 ≤ 1024) : ∃ k' C', RD code I g s0 ⟨4057⟩ R mem aw rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨4039⟩) (okPc := ⟨4055⟩) rd4039 + exact RD.solcCallSuccessGuardOk (pc := ⟨4039⟩) (okPc := ⟨4055⟩) rd4039 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by rw [dogDecodePatchedEqTemplatePrecise hpatch (by native_decide) (by native_decide) @@ -20899,7 +20899,7 @@ theorem RD.dogBarkVatGrabPostCall {v : DogImmutables} {code : ByteArray} (fromByteArrayBigEndian (mem.readWithPadding (⟨256⟩ : UInt256).toNat 32))) = barkIlksClipWord σMem I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) (hevmEnv : evm.executionEnv = I) (hevmCreated : evm.createdAccounts = cA) (hevmMap : evm.accountMap = σ) @@ -21544,10 +21544,10 @@ theorem RD.dogBarkFessNoCodeRevert {v : DogImmutables} {code : ByteArray} (hpatch : patchRuntime dogBytecode (patches v) = some code) (rd4139 : RD code I g s0 ⟨4139⟩ (barkVowWord σ I :: barkVowWord σ I :: R) mem (UInt256.ofNat 19) rdata (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVowWord σ I) = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (barkVowWord σ I) = ⟨0⟩) (hov : R.length + 4 ≤ 1024) : RDrev code g s0 := by - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4139⟩) (okPc := ⟨4151⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4139⟩) (okPc := ⟨4151⟩) rd4139 hcodeSize (by rw [dogDecodePatchedEqTemplatePrecise hpatch (by native_decide) (by native_decide) @@ -21595,12 +21595,12 @@ theorem RD.dogBarkFessToCall {v : DogImmutables} {code : ByteArray} (hpatch : patchRuntime dogBytecode (patches v) = some code) (rd4139 : RD code I g s0 ⟨4139⟩ (barkVowWord σ I :: barkVowWord σ I :: R) mem (UInt256.ofNat 19) rdata (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVowWord σ I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (barkVowWord σ I) ≠ ⟨0⟩) (hov : R.length + 4 ≤ 1024) : ∃ gasWord k' C', RD code I g s0 ⟨4154⟩ (gasWord :: barkVowWord σ I :: R) mem (UInt256.ofNat 19) rdata (cA, σ) k' C' := by obtain ⟨gasWord, k', C', rd4154⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4139⟩) (okPc := ⟨4151⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨4139⟩) (okPc := ⟨4151⟩) rd4139 hcodeSize (by rw [dogDecodePatchedEqTemplatePrecise hpatch (by native_decide) (by native_decide) @@ -21651,7 +21651,7 @@ theorem RD.dogBarkFessCallFailure {v : DogImmutables} {code : ByteArray} (hrdataSize : rdata.size < UInt256.size) (hov : R.length + 5 ≤ 1024) : RDrev code g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨4155⟩) (okPc := ⟨4171⟩) rd4155 + exact RD.solcCallSuccessGuardMissing (pc := ⟨4155⟩) (okPc := ⟨4171⟩) rd4155 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by rw [dogDecodePatchedEqTemplatePrecise hpatch (by native_decide) (by native_decide) @@ -21714,7 +21714,7 @@ theorem RD.dogBarkFessCallSuccess {v : DogImmutables} {code : ByteArray} (hov : R.length + 6 ≤ 1024) : ∃ k' C', RD code I g s0 ⟨4176⟩ R mem aw rdata acc k' C' := by obtain ⟨k4173, C4173, rd4173⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨4155⟩) (okPc := ⟨4171⟩) rd4155 + RD.solcCallSuccessGuardOk (pc := ⟨4155⟩) (okPc := ⟨4171⟩) rd4155 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by rw [dogDecodePatchedEqTemplatePrecise hpatch (by native_decide) (by native_decide) @@ -21779,7 +21779,7 @@ theorem RD.dogBarkFessPostCall {v : DogImmutables} {code : ByteArray} mem (UInt256.ofNat 19) rdata (cA, σ) k C) (hmem : mem.size = 580) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨384⟩) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVowWord σ I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (barkVowWord σ I) ≠ ⟨0⟩) (hevmEnv : evm.executionEnv = I) (hevmCreated : evm.createdAccounts = cA) (hevmMap : evm.accountMap = σ) @@ -23225,10 +23225,10 @@ theorem RD.dogBarkKickNoCodeRevert {v : DogImmutables} {code : ByteArray} (barkIlksClipWord σMem I :: barkIlksClipWord σMem I :: R) mem (UInt256.ofNat 19) rdata (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (barkIlksClipWord σMem I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (barkIlksClipWord σMem I) = ⟨0⟩) (hov : R.length + 4 ≤ 1024) : RDrev code g s0 := by - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4370⟩) (okPc := ⟨4382⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4370⟩) (okPc := ⟨4382⟩) rd4370 hcodeSize (by rw [dogDecodePatchedEqTemplatePrecise hpatch (by native_decide) (by native_decide) @@ -23278,13 +23278,13 @@ theorem RD.dogBarkKickToCall {v : DogImmutables} {code : ByteArray} (barkIlksClipWord σMem I :: barkIlksClipWord σMem I :: R) mem (UInt256.ofNat 19) rdata (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (barkIlksClipWord σMem I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (barkIlksClipWord σMem I) ≠ ⟨0⟩) (hov : R.length + 4 ≤ 1024) : ∃ gasWord k' C', RD code I g s0 ⟨4385⟩ (gasWord :: barkIlksClipWord σMem I :: R) mem (UInt256.ofNat 19) rdata (cA, σ) k' C' := by obtain ⟨gasWord, k', C', rd4385⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4370⟩) (okPc := ⟨4382⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨4370⟩) (okPc := ⟨4382⟩) rd4370 hcodeSize (by rw [dogDecodePatchedEqTemplatePrecise hpatch (by native_decide) (by native_decide) @@ -23345,7 +23345,7 @@ theorem RD.dogBarkKickPostCall {v : DogImmutables} {code : ByteArray} (fromByteArrayBigEndian (mem.readWithPadding (⟨256⟩ : UInt256).toNat 32))) = barkIlksClipWord σMem I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (barkIlksClipWord σMem I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (barkIlksClipWord σMem I) ≠ ⟨0⟩) (hevmEnv : evm.executionEnv = I) (hevmCreated : evm.createdAccounts = cA) (hevmMap : evm.accountMap = σ) @@ -23451,7 +23451,7 @@ theorem RD.dogBarkKickCallFailure {v : DogImmutables} {code : ByteArray} (hrdataSize : rdata.size < UInt256.size) (hov : R.length + 5 ≤ 1024) : RDrev code g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨4386⟩) (okPc := ⟨4402⟩) rd4386 + exact RD.solcCallSuccessGuardMissing (pc := ⟨4386⟩) (okPc := ⟨4402⟩) rd4386 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by rw [dogDecodePatchedEqTemplatePrecise hpatch (by native_decide) (by native_decide) @@ -23514,7 +23514,7 @@ theorem RD.dogBarkKickCallSuccessToDecode {v : DogImmutables} {code : ByteArray} (hov : R.length + 6 ≤ 1024) : ∃ k' C', RD code I g s0 ⟨4404⟩ (d0 :: d1 :: d2 :: R) mem aw rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨4386⟩) (okPc := ⟨4402⟩) rd4386 + exact RD.solcCallSuccessGuardOk (pc := ⟨4386⟩) (okPc := ⟨4402⟩) rd4386 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by rw [dogDecodePatchedEqTemplatePrecise hpatch (by native_decide) (by native_decide) @@ -23644,7 +23644,7 @@ theorem RD.dogBarkKickReturnDecodeShortReverts {v : DogImmutables} {code : ByteA native_decide) hcond (by simp only [List.length_cons]; omega) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by rw [dogDecodePatchedEqTemplatePrecise hpatch (by native_decide) (by native_decide) (by native_decide) (by native_decide)] @@ -24682,14 +24682,14 @@ theorem RD.dogBarkVatUrnsStaticcallDepthLimitRevert {v : DogImmutables} {code : (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (barkVatWord v) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hov : R.length + 24 ≤ 1024) : RDrev code g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, _, rd3007⟩ := RD.dogBarkVatUrnsToStaticcall hpatch h hmem hread64 hcodeSize hov obtain ⟨_, _, rd3008raw⟩ := - RD.uniswapStaticcallDepthLimit rd3007 + RD.solcStaticcallDepthLimit rd3007 (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] native_decide) @@ -24925,13 +24925,13 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} obtain ⟨_, _, h2885⟩ := RD.dogBarkLiveOk hpatch hbodyReach hliveSolc (by simp only [List.length_cons, List.length_nil]; omega) by_cases hvatCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (barkVatWord v) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_evm (barkVatWord v) = ⟨0⟩ · have hrev := RD.dogBarkVatUrnsNoCodeRevert (v := v) (code := code) (ret := ⟨448⟩) (sel := solcSelectorWord I) (R := []) hpatch h2885 solcFreePtrMem_size solcFreePtrMem_read64 hvatCodeSize (by simp) have hvatCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (barkVatWord v) = ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (barkVatWord v) = ⟨0⟩ := barkVatCodeSize_zero_accountMapEquiv hAccounts hvatCodeSize have hvatNoCode : (UInt256.ofNat @@ -24950,10 +24950,10 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} hwv hliveSolm hvatNoCode) exact hrev.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatCodeSizeNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (barkVatWord v) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_evm (barkVatWord v) ≠ ⟨0⟩ := hvatCodeSize have hvatCodeSizeSolmNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (barkVatWord v) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (barkVatWord v) ≠ ⟨0⟩ := barkVatCodeSize_ne_accountMapEquiv hAccounts hvatCodeSizeNe have hvatCode : 0 < (UInt256.ofNat @@ -25026,16 +25026,16 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} have hStateCall : EVMStateEquiv evmPostEvm evmPostSolm := by simpa [evmPostEvm, evmPostSolm] using hStateCallRaw by_cases hvatIlksCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (barkVatWord v) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ' (barkVatWord v) = ⟨0⟩ · have hrev := RD.dogBarkVatIlksNoCodeRevert hpatch rd3139 solcFreePtrMem_size hretLong hosz hvatIlksCodeSize (by simp only [List.length_cons, List.length_nil]; omega) have hvatIlksCodeSizeEvm : - Reasoning.Theory.uniswapExtCodeSizeWord evmPostEvm.accountMap + Reasoning.Theory.extCodeSizeWord evmPostEvm.accountMap (barkVatWord v) = ⟨0⟩ := by simpa [evmPostEvm] using hvatIlksCodeSize have hvatIlksCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmPostSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmPostSolm.accountMap (barkVatWord v) = ⟨0⟩ := barkVatCodeSize_zero_accountMapEquiv hStateCall.accountMap hvatIlksCodeSizeEvm @@ -25105,11 +25105,11 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} have hrev := RD.dogBarkVatIlksCallFailure hpatch rd3245 hoszIlks (by simp only [List.length_cons, List.length_nil]; omega) have hvatIlksCodeSizeEvmNe : - Reasoning.Theory.uniswapExtCodeSizeWord evmPostEvm.accountMap + Reasoning.Theory.extCodeSizeWord evmPostEvm.accountMap (barkVatWord v) ≠ ⟨0⟩ := by simpa [evmPostEvm] using hvatIlksCodeSize have hvatIlksCodeSizeSolmNe : - Reasoning.Theory.uniswapExtCodeSizeWord evmPostSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmPostSolm.accountMap (barkVatWord v) ≠ ⟨0⟩ := barkVatCodeSize_ne_accountMapEquiv hStateCall.accountMap hvatIlksCodeSizeEvmNe @@ -25137,11 +25137,11 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} RD.dogBarkVatIlksCallSuccessToDecode hpatch rd3245 (by simp only [List.length_cons, List.length_nil]; omega) have hvatIlksCodeSizeEvmNe : - Reasoning.Theory.uniswapExtCodeSizeWord evmPostEvm.accountMap + Reasoning.Theory.extCodeSizeWord evmPostEvm.accountMap (barkVatWord v) ≠ ⟨0⟩ := by simpa [evmPostEvm] using hvatIlksCodeSize have hvatIlksCodeSizeSolmNe : - Reasoning.Theory.uniswapExtCodeSizeWord evmPostSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmPostSolm.accountMap (barkVatWord v) ≠ ⟨0⟩ := barkVatCodeSize_ne_accountMapEquiv hStateCall.accountMap hvatIlksCodeSizeEvmNe @@ -26164,7 +26164,7 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} (σ := σ') (I := I) solcFreePtrMem_size hretLong hosz hretIlksLong hoszIlks by_cases hvatGrabCodeZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ'' + Reasoning.Theory.extCodeSizeWord σ'' (barkVatWord v) = ⟨0⟩ · obtain ⟨_, _, rd4023⟩ := RD.dogBarkVatGrabExtcodesizeGuard @@ -26176,7 +26176,7 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} (by simpa [mem0] using hpostMemRead64) hmload256Grab rd3885 (by simp) have hvatGrabZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmIlksPostSolm.accountMap (barkVatWord v) = ⟨0⟩ := barkVatCodeSize_zero_accountMapEquiv @@ -26329,7 +26329,7 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} simpa [evmGrabSolm, hvowWordIlks] using hcallGrabSolmRaw have hvatGrabNonzeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmIlksPostSolm.accountMap (barkVatWord v) ≠ ⟨0⟩ := barkVatCodeSize_ne_accountMapEquiv @@ -26550,7 +26550,7 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} "id" ++ [ .return [.var "id"] ] by_cases hvowCodeZero : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σGrab (barkVowWord σGrab I) = ⟨0⟩ · obtain ⟨_, _, rd4139⟩ := RD.dogBarkFessExtcodesizeGuard @@ -26562,7 +26562,7 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} hpatch hmemGrabSize hmemGrabRead64 rd4071 (by simp) have hvowCodeZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmGrabSolm.accountMap (barkVowWord evmGrabSolm.accountMap evmGrabSolm.executionEnv) = ⟨0⟩ := by @@ -26706,7 +26706,7 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} simpa [evmFessEvm, evmFessSolm] using hAccountsFessRaw have hvowCodeNonzeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmGrabSolm.accountMap (barkVowWord evmGrabSolm.accountMap @@ -27732,7 +27732,7 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} rw [hmilkClipIlkDirtNew] rfl by_cases hclipCodeZero : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σIlkDirt (barkIlksClipWord σ' I) = ⟨0⟩ · obtain ⟨_, _, rd4370⟩ := @@ -27749,7 +27749,7 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} hmload256KickPre rd4267 (by simp) have hclipZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmIlkDirtSolm.accountMap (barkIlksClipWord σ' I) = ⟨0⟩ := dogCodeSize_zero_accountMapEquiv @@ -27814,7 +27814,7 @@ theorem dogBarkBodyCore {v : DogImmutables} {code : ByteArray} exact hrev.reEquivExecutionRevert hcode hdispatch hdecode htailBody · have hclipNonzeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmIlkDirtSolm.accountMap (barkIlksClipWord σ' I) ≠ ⟨0⟩ := dogCodeSize_ne_accountMapEquiv diff --git a/Benchmarks/Dss/Dog/Dispatch.lean b/Benchmarks/Dss/Dog/Dispatch.lean index 4e28a164..ad2d2fcd 100644 --- a/Benchmarks/Dss/Dog/Dispatch.lean +++ b/Benchmarks/Dss/Dog/Dispatch.lean @@ -746,7 +746,7 @@ theorem dogX_callvalue_ne {v : DogImmutables} {code : ByteArray} rw [dogDecodePatchedEqTemplate1405 (pc := ⟨11⟩) hpatch (by native_decide)] native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 + exact RD.solcPush1Dup1Revert0 h12 (by change decode code (⟨12⟩ : UInt256) = some (.Push .PUSH1, some (⟨0⟩, 1)) rw [dogDecodePatchedEqTemplate1405 (pc := ⟨12⟩) hpatch (by native_decide)] @@ -833,7 +833,7 @@ theorem dogX_short {v : DogImmutables} {code : ByteArray} rw [dogDecodePatchedEqTemplate1405 (pc := ⟨267⟩) hpatch (by native_decide)] native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h267 + exact RD.solcPush1Dup1Revert0 h267 (by change decode code (⟨268⟩ : UInt256) = some (.Push .PUSH1, some (⟨0⟩, 1)) rw [dogDecodePatchedEqTemplate1405 (pc := ⟨268⟩) hpatch (by native_decide)] @@ -1064,7 +1064,7 @@ theorem dogJumpToDispatchRevert {v : DogImmutables} {code : ByteArray} rw [dogDecodePatchedEqTemplate1405 (pc := ⟨267⟩) hpatch (by native_decide)] native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h267 + exact RD.solcPush1Dup1Revert0 h267 (by change decode code (⟨268⟩ : UInt256) = some (.Push .PUSH1, some (⟨0⟩, 1)) rw [dogDecodePatchedEqTemplate1405 (pc := ⟨268⟩) hpatch (by native_decide)] @@ -1090,7 +1090,7 @@ theorem dogDispatchRevertAt {v : DogImmutables} {code : ByteArray} rw [dogDecodePatchedEqTemplate1405 (pc := ⟨267⟩) hpatch (by native_decide)] native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h268 + exact RD.solcPush1Dup1Revert0 h268 (by change decode code (⟨268⟩ : UInt256) = some (.Push .PUSH1, some (⟨0⟩, 1)) rw [dogDecodePatchedEqTemplate1405 (pc := ⟨268⟩) hpatch (by native_decide)] diff --git a/Benchmarks/Dss/Dog/FileIlkClip.lean b/Benchmarks/Dss/Dog/FileIlkClip.lean index 47eefb83..6604f5f6 100644 --- a/Benchmarks/Dss/Dog/FileIlkClip.lean +++ b/Benchmarks/Dss/Dog/FileIlkClip.lean @@ -758,10 +758,10 @@ theorem fileIlkClipClip_eq_clipKey (I : ExecutionEnv) : theorem fileIlkClipCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileIlkClipClipKey I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (fileIlkClipClipKey I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (fileIlkClipClipKey I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (fileIlkClipClipKey I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (fileIlkClipClipKey I) rw [← hsame] exact hzero @@ -769,24 +769,24 @@ theorem fileIlkClipCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execu theorem fileIlkClipCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileIlkClipClipKey I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (fileIlkClipClipKey I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (fileIlkClipClipKey I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (fileIlkClipClipKey I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (fileIlkClipClipKey I) rw [hsame] exact hzero theorem fileIlkClipCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt256} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileIlkClipClipKey I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (fileIlkClipClipKey I) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (fileIlkClipClip I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by rw [fileIlkClipClip_eq_clipKey I] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 (fileIlkClipClipKey I)) with | none => simpa [initState, State.lookupAccount, hacc, Option.option] using @@ -797,12 +797,12 @@ theorem fileIlkClipCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt2 theorem fileIlkClipCode_pos_of_codeSize_ne {cA gh bl σ σ₀ A I} {g : UInt256} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileIlkClipClipKey I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (fileIlkClipClipKey I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (fileIlkClipClip I)).option 0 (fun acc => acc.code.size))).toNat := by rw [fileIlkClipClip_eq_clipKey I] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : σ.find? (AccountAddress.ofUInt256 (fileIlkClipClipKey I)) with | none => exfalso @@ -2084,12 +2084,12 @@ theorem RD.dogFileIlkClipNoCodeRevert {v : DogImmutables} {code : ByteArray} (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileIlkClipClipKey ee) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (fileIlkClipClipKey ee) = ⟨0⟩) (hov : R.length + 18 ≤ 1024) : RDrev code g s0 := by obtain ⟨_, _, rd2566⟩ := RD.dogFileIlkClipToExtcodesize hpatch h hmatch hmem hread64 hov - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2566⟩) (okPc := ⟨2578⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2566⟩) (okPc := ⟨2578⟩) rd2566 hcodeSize (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] @@ -2133,7 +2133,7 @@ theorem RD.dogFileIlkClipToStaticcall {v : DogImmutables} {code : ByteArray} (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileIlkClipClipKey ee) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (fileIlkClipClipKey ee) ≠ ⟨0⟩) (hov : R.length + 18 ≤ 1024) : ∃ gasWord k' C', RD code ee g s0 ⟨2581⟩ (gasWord :: fileIlkClipClipKey ee :: ⟨128⟩ :: ⟨4⟩ :: ⟨128⟩ :: ⟨32⟩ :: @@ -2143,7 +2143,7 @@ theorem RD.dogFileIlkClipToStaticcall {v : DogImmutables} {code : ByteArray} obtain ⟨_, _, rd2566⟩ := RD.dogFileIlkClipToExtcodesize hpatch h hmatch hmem hread64 hov obtain ⟨gasWord, k', C', rd2581⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2566⟩) (okPc := ⟨2578⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨2566⟩) (okPc := ⟨2578⟩) rd2566 hcodeSize (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] @@ -2188,7 +2188,7 @@ theorem RD.dogFileIlkClipPostStaticcall {v : DogImmutables} {code : ByteArray} (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileIlkClipClipKey I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (fileIlkClipClipKey I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hov : R.length + 18 ≤ 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) @@ -2208,7 +2208,7 @@ theorem RD.dogFileIlkClipPostStaticcall {v : DogImmutables} {code : ByteArray} obtain ⟨_, _, _, rd2581⟩ := RD.dogFileIlkClipToStaticcall hpatch h hmatch hmem hread64 hcodeSize hov obtain ⟨cA', σ', z, out, A_in, callGas, k', C', hΘpack, rd2582raw, hosz⟩ := - RD.uniswapStaticcall rd2581 + RD.solcStaticcall rd2581 (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] native_decide) @@ -2272,7 +2272,7 @@ theorem RD.dogFileIlkClipCallFailure {v : DogImmutables} {code : ByteArray} (hrdataSize : rdata.size < UInt256.size) (hov : R.length + 5 ≤ 1024) : RDrev code g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2582⟩) (okPc := ⟨2598⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨2582⟩) (okPc := ⟨2598⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] @@ -2324,14 +2324,14 @@ theorem RD.dogFileIlkClipStaticcallDepthLimitRevert {v : DogImmutables} {code : (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileIlkClipClipKey I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (fileIlkClipClipKey I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hov : R.length + 18 ≤ 1024) : RDrev code g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, _, rd2581⟩ := RD.dogFileIlkClipToStaticcall hpatch h hmatch hmem hread64 hcodeSize hov obtain ⟨_, _, rd2582raw⟩ := - RD.uniswapStaticcallDepthLimit rd2581 + RD.solcStaticcallDepthLimit rd2581 (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] native_decide) @@ -2367,7 +2367,7 @@ theorem RD.dogFileIlkClipCallSuccessToDecode {v : DogImmutables} {code : ByteArr ∃ k' C', RD code ee g s0 ⟨2600⟩ (d0 :: d1 :: d2 :: d3 :: d4 :: d5 :: ret :: sel :: R) mem aw out acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨2582⟩) (okPc := ⟨2598⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨2582⟩) (okPc := ⟨2598⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)] @@ -3261,12 +3261,12 @@ theorem dogFileIlkClipBodyCoreOk {v : DogImmutables} {code : ByteArray} fileIlkClipWhatWord I = ABI.bytesToWord fileIlkClipClipBytes := fileIlkClipWhatWord_eq_of_bytes_eq (by omega) hwhatClip by_cases hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (fileIlkClipClipKey I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_evm (fileIlkClipClipKey I) = ⟨0⟩ · have hrev := RD.dogFileIlkClipNoCodeRevert (v := v) (code := code) (ret := ⟨313⟩) (sel := sel) (R := []) hpatch hswitch hwordClip hmemAuth hread64Auth hcodeSize (by simp) have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (fileIlkClipClipKey I) = ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (fileIlkClipClipKey I) = ⟨0⟩ := fileIlkClipCodeSize_zero_accountMapEquiv hAccounts hcodeSize have hclipNoCode : (UInt256.ofNat @@ -3284,11 +3284,11 @@ theorem dogFileIlkClipBodyCoreOk {v : DogImmutables} {code : ByteArray} hwv hauthSolm hwhatClip hclipNoCode) exact hrev.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hcodeSizeNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (fileIlkClipClipKey I) ≠ + Reasoning.Theory.extCodeSizeWord σ_evm (fileIlkClipClipKey I) ≠ ⟨0⟩ := hcodeSize have hcodeSizeSolmNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (fileIlkClipClipKey I) ≠ + Reasoning.Theory.extCodeSizeWord σ_solm (fileIlkClipClipKey I) ≠ ⟨0⟩ := fileIlkClipCodeSize_ne_accountMapEquiv hAccounts hcodeSizeNe have hclipCode : diff --git a/Benchmarks/Dss/Dog/SpecSyntax.lean b/Benchmarks/Dss/Dog/SpecSyntax.lean index f1cf5716..68848afe 100644 --- a/Benchmarks/Dss/Dog/SpecSyntax.lean +++ b/Benchmarks/Dss/Dog/SpecSyntax.lean @@ -2,10 +2,13 @@ import Benchmarks.Dss.Dog.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS Dog spec through the Solm notation frontend +# Dog spec in the Solidity-faithful Solm frontend -The main spec lives in `Spec.lean`; this companion keeps the benchmark's notation-side check wired -up as the body surface grows. +The whole `dog.sol` spec written with `solidity%` and proven definitionally equal to the AST +spec in `Spec.lean`, quantified over the immutable `vat` address. Calls through the immutable +`vat` (`vatExpr v`, a cast literal) cannot head a surface call, so those sites splice the +guarded require/externalCall statement pair and reference the returned tuple binders via `${…}` +escapes. Transition order matches `(contract v).transitions` (selector order). -/ open Solm Solm.Notation @@ -13,10 +16,242 @@ open Benchmarks.Dss.Dog.Immutables namespace Benchmarks.Dss.Dog.Syntax -def contractSyntax (v : DogImmutables) : ContractDecl := Benchmarks.Dss.Dog.contract v +def contractSyntax (v : DogImmutables) : ContractDecl := solidity% contract Dog { + mapping(address => uint256) wards; + mapping(bytes32 => Ilk) ilks; + address vow; + uint256 live; + uint256 Hole; + uint256 Dirt; + struct Ilk { + address clip; + uint256 chop; + uint256 hole; + uint256 dirt; + } + + constructor(address vat_) { + address imm_vat = vat_; + live = 1; + wards[msg.sender] = 1; + } + + function min(uint256 x, uint256 y) internal returns (uint256) { + if (x <= y) { + return x; + } else { + return y; + } + } + + function add(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x + y) as uint256; + require(z >= x); + return z; + } + + function sub(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x - y) as uint256; + require(z <= x); + return z; + } + + function mul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + return z; + } + + function Dirt() external returns (uint256) { + return Dirt; + } + + function Hole() external returns (uint256) { + return Hole; + } + + function bark(bytes32 ilk, address urn, address kpr) external returns (uint256) { + require(live == 1); + ${[Stmt.require (.binary .gt (.extCodeSize (vatExpr v)) (.intLit 0)), + Stmt.externalCall (vatExpr v) "urns" (.intLit 0) + [.var "ilk", .var "urn"] "vatUrn" (perm := false)]} + uint256 ink = ${Expr.var "vatUrn"}.0; + uint256 art = ${Expr.var "vatUrn"}.1; + address milkClip = ilks[ilk].clip; + uint256 milkChop = ilks[ilk].chop; + uint256 milkHole = ilks[ilk].hole; + uint256 milkDirt = ilks[ilk].dirt; + ${[Stmt.require (.binary .gt (.extCodeSize (vatExpr v)) (.intLit 0)), + Stmt.externalCall (vatExpr v) "ilks" (.intLit 0) + [.var "ilk"] "vatIlk" (perm := false)]} + uint256 rate = ${Expr.var "vatIlk"}.1; + uint256 spot = ${Expr.var "vatIlk"}.2; + uint256 dust = ${Expr.var "vatIlk"}.4; + uint256 inkSpot = (ink * spot) as uint256; + require(spot == 0 || inkSpot / spot == ink); + uint256 artRateUnsafe = (art * rate) as uint256; + require(rate == 0 || artRateUnsafe / rate == art); + require(spot > 0 && inkSpot < artRateUnsafe); + require(Hole > Dirt && milkHole > milkDirt); + uint256 globalRoom = (Hole - Dirt) as uint256; + require(globalRoom <= Hole); + uint256 ilkRoom = (milkHole - milkDirt) as uint256; + require(ilkRoom <= milkHole); + var room = min(globalRoom, ilkRoom); + uint256 roomWad = (room * #WAD) as uint256; + require(#WAD == 0 || roomWad / #WAD == room); + uint256 dartByRate = roomWad / rate; + uint256 dartCandidate = dartByRate / milkChop; + var dart = min(art, dartCandidate); + if (art > dart) { + uint256 leftoverArt = (art - dart) as uint256; + require(leftoverArt <= art); + uint256 leftoverDue = (leftoverArt * rate) as uint256; + require(rate == 0 || leftoverDue / rate == leftoverArt); + if (leftoverDue < dust) { + dart = art; + } else { + uint256 partialDue = (dart * rate) as uint256; + require(rate == 0 || partialDue / rate == dart); + require(partialDue >= dust); + } + } + uint256 inkDart = (ink * dart) as uint256; + require(dart == 0 || inkDart / dart == ink); + uint256 dink = inkDart / art; + require(dink > 0); + require(dart <= #int256Limit && dink <= #int256Limit); + ${[Stmt.require (.binary .gt (.extCodeSize (vatExpr v)) (.intLit 0)), + Stmt.externalCall (vatExpr v) "grab" (.intLit 0) + [.var "ilk", .var "urn", .var "milkClip", vowAddr, + .unary .neg (asInt256 (.var "dink")), + .unary .neg (asInt256 (.var "dart"))] "_grabRet"]} + uint256 due = (dart * rate) as uint256; + require(rate == 0 || due / rate == dart); + require(vow.code.length > 0); + var _fessRet = vow.fess(due); + uint256 tabBase = (due * milkChop) as uint256; + require(milkChop == 0 || tabBase / milkChop == due); + uint256 tab = tabBase / #WAD; + uint256 DirtNew = (Dirt + tab) as uint256; + require(DirtNew >= Dirt); + Dirt = DirtNew; + uint256 ilkDirtNew = (milkDirt + tab) as uint256; + require(ilkDirtNew >= milkDirt); + ilks[ilk].dirt = ilkDirtNew; + require(milkClip.code.length > 0); + var id = milkClip.kick(tab, dink, urn, kpr); + return id; + } + + function cage() external { + require(wards[msg.sender] == 1); + live = 0; + } + + function chop(bytes32 ilk) external returns (uint256) { + return ilks[ilk].chop; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function digs(bytes32 ilk, uint256 rad) external { + require(wards[msg.sender] == 1); + var DirtNew = sub(Dirt, rad); + Dirt = DirtNew; + var ilkDirtNew = sub(ilks[ilk].dirt, rad); + ilks[ilk].dirt = ilkDirtNew; + } + + function file(bytes32 ilk, bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x63686f7000000000000000000000000000000000000000000000000000000000)) { + require(data >= #WAD); + ilks[ilk].chop = data; + } else if (what == bytes32(0x686f6c6500000000000000000000000000000000000000000000000000000000)) { + ilks[ilk].hole = data; + } else { + require(false); + } + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x486f6c6500000000000000000000000000000000000000000000000000000000)) { + Hole = data; + } else { + require(false); + } + } + + function file(bytes32 what, address data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x766f770000000000000000000000000000000000000000000000000000000000)) { + vow = data; + } else { + require(false); + } + } + + function file(bytes32 ilk, bytes32 what, address clip) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x636c697000000000000000000000000000000000000000000000000000000000)) { + require(clip.code.length > 0); + var clipIlk = clip.ilk{view}(); + require(ilk == clipIlk); + ilks[ilk].clip = clip; + } else { + require(false); + } + } + + function ilks(bytes32 arg0) external returns (address, uint256, uint256, uint256) { + return (ilks[arg0].clip, ilks[arg0].chop, ilks[arg0].hole, ilks[arg0].dirt); + } + + function live() external returns (uint256) { + return live; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 1; + } + + function vat() external returns (address) { + return ${vatExpr v}; + } + + function vow() external returns (address) { + return vow; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } +} + +/-- Definitional equality with the AST spec. A bare `rfl` diverges here: `bark` mentions the +immutable `vatExpr v` six times, and the elaborator's defeq cache is disabled on terms with free +variables, so the lazy pairwise comparison blows up. `simp only` first rewrites both sides to the +same cons-normal form (no defeq search); the closing `rfl` then only crosses closed leaves. -/ theorem contractSyntax_eq (v : DogImmutables) : contractSyntax v = Benchmarks.Dss.Dog.contract v := by + simp only [contractSyntax, Benchmarks.Dss.Dog.contract, Benchmarks.Dss.Dog.transitions, + Benchmarks.Dss.Dog.barkTransition, Benchmarks.Dss.Dog.barkBodyRest, + Benchmarks.Dss.Dog.vatTransition, Benchmarks.Dss.Dog.nonpayable, + Benchmarks.Dss.Dog.checkedExternalCallStmts, Benchmarks.Dss.Dog.checkedMulUintInto, + Benchmarks.Dss.Dog.checkedSubUintInto, Benchmarks.Dss.Dog.checkedAddUintInto, + Benchmarks.Dss.Dog.liveRef, Benchmarks.Dss.Dog.vowAddr, Benchmarks.Dss.Dog.vowRef, + Benchmarks.Dss.Dog.HoleRef, Benchmarks.Dss.Dog.DirtRef, Benchmarks.Dss.Dog.ilksF, + Benchmarks.Dss.Dog.varRef, Benchmarks.Dss.Dog.uint256, Benchmarks.Dss.Dog.addr, + Benchmarks.Dss.Dog.uint256Int, Benchmarks.Dss.Dog.u256, Benchmarks.Dss.Dog.mul256, + Benchmarks.Dss.Dog.sub256, Benchmarks.Dss.Dog.add256, + List.cons_append, List.nil_append] rfl end Benchmarks.Dss.Dog.Syntax diff --git a/Benchmarks/Dss/End/Cage.lean b/Benchmarks/Dss/End/Cage.lean index 6ce86a15..7cafc3ea 100644 --- a/Benchmarks/Dss/End/Cage.lean +++ b/Benchmarks/Dss/End/Cage.lean @@ -189,12 +189,12 @@ theorem endCageCallTargetWord_accountMapEquiv {σ τ : AccountMap} {I : Executio theorem endCageCallTargetCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (slot : UInt256) (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCageCallTargetWord slot σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endCageCallTargetWord slot τ I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (endCageCallTargetWord slot σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endCageCallTargetWord slot τ I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endCageCallTargetWord slot σ I) have htarget : endCageCallTargetWord slot σ I = endCageCallTargetWord slot τ I := endCageCallTargetWord_accountMapEquiv slot hAccounts @@ -204,10 +204,10 @@ theorem endCageCallTargetCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : E theorem endCageCallTargetCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (slot : UInt256) (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCageCallTargetWord slot σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endCageCallTargetWord slot τ I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (endCageCallTargetWord slot σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endCageCallTargetWord slot τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endCageCallTargetWord slot σ I) have htarget : endCageCallTargetWord slot σ I = endCageCallTargetWord slot τ I := endCageCallTargetWord_accountMapEquiv slot hAccounts @@ -324,7 +324,7 @@ theorem endCageCallNotMadeDepthLimit (evm : EVM.State) (slot : UInt256) theorem endCageCallTargetCode_zero_of_codeSize_zero {σ : AccountMap} {I : ExecutionEnv} (slot : UInt256) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCageCallTargetWord slot σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endCageCallTargetWord slot σ I) = ⟨0⟩) : (UInt256.ofNat ((σ.find? (endCageCallTargetAddr slot σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by @@ -337,7 +337,7 @@ theorem endCageCallTargetCode_zero_of_codeSize_zero {σ : AccountMap} {I : Execu theorem endCageCallTargetCode_pos_of_codeSize_ne {σ : AccountMap} {I : ExecutionEnv} (slot : UInt256) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCageCallTargetWord slot σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endCageCallTargetWord slot σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((σ.find? (endCageCallTargetAddr slot σ I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [State.lookupAccount] using @@ -843,11 +843,11 @@ theorem endCageX_vatNoCode {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} (h : RD endBytecode I g s0 ⟨5604⟩ [⟨0⟩, endCageReturnPc, sel] (endRelyAuthHashMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCageCallTargetWord ⟨1⟩ σ I) = + Reasoning.Theory.extCodeSizeWord σ (endCageCallTargetWord ⟨1⟩ σ I) = ⟨0⟩) : RDrev endBytecode g s0 := by obtain ⟨_, _, rd5655⟩ := endCageX_vatExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨5655⟩) (okPc := ⟨5667⟩) rd5655 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨5655⟩) (okPc := ⟨5667⟩) rd5655 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -858,7 +858,7 @@ theorem endCageX_vatCallReady {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} (h : RD endBytecode I g s0 ⟨5604⟩ [⟨0⟩, endCageReturnPc, sel] (endRelyAuthHashMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCageCallTargetWord ⟨1⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (endCageCallTargetWord ⟨1⟩ σ I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g s0 ⟨5670⟩ (gasWord :: endCageCallTargetWord ⟨1⟩ σ I :: ⟨0⟩ :: endCageCallOutPtr :: @@ -869,7 +869,7 @@ theorem endCageX_vatCallReady {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd5655⟩ := endCageX_vatExtcodesizeGuard h obtain ⟨gasWord, k', C', rd5670⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨5655⟩) (okPc := ⟨5667⟩) rd5655 + RD.solcExtcodesizeGuardOkGas (pc := ⟨5655⟩) (okPc := ⟨5667⟩) rd5655 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -972,7 +972,7 @@ theorem endCageX_vatCallFailed {cA cA' gh bl σ σCall σ' σ₀ A I} {g : UInt2 (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨5671⟩) (okPc := ⟨5687⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨5671⟩) (okPc := ⟨5687⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -992,7 +992,7 @@ theorem endCageX_vatCallSucceeded {cA gh bl σ σCall σ₀ A I} {g : UInt256} (endCageCallEndPtr :: endCageCallSelectorWord :: endCageCallTargetWord ⟨1⟩ σCall I :: endCageReturnPc :: sel :: []) mem (UInt256.ofNat 5) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨5671⟩) (okPc := ⟨5687⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨5671⟩) (okPc := ⟨5687⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1146,12 +1146,12 @@ theorem endCageX_catNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (endCageCallCalldataMem (endRelyAuthHashMem I)) (UInt256.ofNat 5) rdata acc k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (endCageCallTargetWord ⟨2⟩ acc.2 I) = ⟨0⟩) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd5759⟩ := endCageX_catExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨5759⟩) (okPc := ⟨5771⟩) rd5759 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨5759⟩) (okPc := ⟨5771⟩) rd5759 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1166,7 +1166,7 @@ theorem endCageX_catCallReady {cA gh bl σ σ₀ A I} {g : UInt256} (endCageCallCalldataMem (endRelyAuthHashMem I)) (UInt256.ofNat 5) rdata acc k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (endCageCallTargetWord ⟨2⟩ acc.2 I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨5774⟩ @@ -1178,7 +1178,7 @@ theorem endCageX_catCallReady {cA gh bl σ σ₀ A I} {g : UInt256} rdata acc k' C' := by obtain ⟨_, _, rd5759⟩ := endCageX_catExtcodesizeGuard h obtain ⟨gasWord, k', C', rd5774⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨5759⟩) (okPc := ⟨5771⟩) rd5759 + RD.solcExtcodesizeGuardOkGas (pc := ⟨5759⟩) (okPc := ⟨5771⟩) rd5759 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1282,7 +1282,7 @@ theorem endCageX_catCallFailed {cA cA' gh bl σ σCall σ' σ₀ A I} {g : UInt2 (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨5775⟩) (okPc := ⟨5791⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨5775⟩) (okPc := ⟨5791⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1302,7 +1302,7 @@ theorem endCageX_catCallSucceeded {cA gh bl σ σCall σ₀ A I} {g : UInt256} (endCageCallEndPtr :: endCageCallSelectorWord :: endCageCallTargetWord ⟨2⟩ σCall I :: endCageReturnPc :: sel :: []) mem (UInt256.ofNat 5) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨5775⟩) (okPc := ⟨5791⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨5775⟩) (okPc := ⟨5791⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1453,12 +1453,12 @@ theorem endCageX_dogNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (endCageCallCalldataMem (endRelyAuthHashMem I)) (UInt256.ofNat 5) rdata acc k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (endCageCallTargetWord ⟨3⟩ acc.2 I) = ⟨0⟩) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd5863⟩ := endCageX_dogExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨5863⟩) (okPc := ⟨5875⟩) rd5863 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨5863⟩) (okPc := ⟨5875⟩) rd5863 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1473,7 +1473,7 @@ theorem endCageX_dogCallReady {cA gh bl σ σ₀ A I} {g : UInt256} (endCageCallCalldataMem (endRelyAuthHashMem I)) (UInt256.ofNat 5) rdata acc k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (endCageCallTargetWord ⟨3⟩ acc.2 I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨5878⟩ @@ -1485,7 +1485,7 @@ theorem endCageX_dogCallReady {cA gh bl σ σ₀ A I} {g : UInt256} rdata acc k' C' := by obtain ⟨_, _, rd5863⟩ := endCageX_dogExtcodesizeGuard h obtain ⟨gasWord, k', C', rd5878⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨5863⟩) (okPc := ⟨5875⟩) rd5863 + RD.solcExtcodesizeGuardOkGas (pc := ⟨5863⟩) (okPc := ⟨5875⟩) rd5863 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1589,7 +1589,7 @@ theorem endCageX_dogCallFailed {cA cA' gh bl σ σCall σ' σ₀ A I} {g : UInt2 (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨5879⟩) (okPc := ⟨5895⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨5879⟩) (okPc := ⟨5895⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1609,7 +1609,7 @@ theorem endCageX_dogCallSucceeded {cA gh bl σ σCall σ₀ A I} {g : UInt256} (endCageCallEndPtr :: endCageCallSelectorWord :: endCageCallTargetWord ⟨3⟩ σCall I :: endCageReturnPc :: sel :: []) mem (UInt256.ofNat 5) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨5879⟩) (okPc := ⟨5895⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨5879⟩) (okPc := ⟨5895⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1753,12 +1753,12 @@ theorem endCageX_vowNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (endCageCallCalldataMem (endRelyAuthHashMem I)) (UInt256.ofNat 5) rdata acc k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (endCageCallTargetWord ⟨4⟩ acc.2 I) = ⟨0⟩) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd5954⟩ := endCageX_vowExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨5954⟩) (okPc := ⟨5966⟩) rd5954 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨5954⟩) (okPc := ⟨5966⟩) rd5954 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1773,7 +1773,7 @@ theorem endCageX_vowCallReady {cA gh bl σ σ₀ A I} {g : UInt256} (endCageCallCalldataMem (endRelyAuthHashMem I)) (UInt256.ofNat 5) rdata acc k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (endCageCallTargetWord ⟨4⟩ acc.2 I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨5969⟩ @@ -1785,7 +1785,7 @@ theorem endCageX_vowCallReady {cA gh bl σ σ₀ A I} {g : UInt256} rdata acc k' C' := by obtain ⟨_, _, rd5954⟩ := endCageX_vowExtcodesizeGuard h obtain ⟨gasWord, k', C', rd5969⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨5954⟩) (okPc := ⟨5966⟩) rd5954 + RD.solcExtcodesizeGuardOkGas (pc := ⟨5954⟩) (okPc := ⟨5966⟩) rd5954 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1889,7 +1889,7 @@ theorem endCageX_vowCallFailed {cA cA' gh bl σ σCall σ' σ₀ A I} {g : UInt2 (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨5970⟩) (okPc := ⟨5986⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨5970⟩) (okPc := ⟨5986⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1909,7 +1909,7 @@ theorem endCageX_vowCallSucceeded {cA gh bl σ σCall σ₀ A I} {g : UInt256} (endCageCallEndPtr :: endCageCallSelectorWord :: endCageCallTargetWord ⟨4⟩ σCall I :: endCageReturnPc :: sel :: []) mem (UInt256.ofNat 5) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨5970⟩) (okPc := ⟨5986⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨5970⟩) (okPc := ⟨5986⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -2060,12 +2060,12 @@ theorem endCageX_spotNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (endCageCallCalldataMem (endRelyAuthHashMem I)) (UInt256.ofNat 5) rdata acc k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (endCageCallTargetWord ⟨6⟩ acc.2 I) = ⟨0⟩) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd6058⟩ := endCageX_spotExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨6058⟩) (okPc := ⟨6070⟩) rd6058 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨6058⟩) (okPc := ⟨6070⟩) rd6058 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2080,7 +2080,7 @@ theorem endCageX_spotCallReady {cA gh bl σ σ₀ A I} {g : UInt256} (endCageCallCalldataMem (endRelyAuthHashMem I)) (UInt256.ofNat 5) rdata acc k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (endCageCallTargetWord ⟨6⟩ acc.2 I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨6073⟩ @@ -2092,7 +2092,7 @@ theorem endCageX_spotCallReady {cA gh bl σ σ₀ A I} {g : UInt256} rdata acc k' C' := by obtain ⟨_, _, rd6058⟩ := endCageX_spotExtcodesizeGuard h obtain ⟨gasWord, k', C', rd6073⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨6058⟩) (okPc := ⟨6070⟩) rd6058 + RD.solcExtcodesizeGuardOkGas (pc := ⟨6058⟩) (okPc := ⟨6070⟩) rd6058 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -2196,7 +2196,7 @@ theorem endCageX_spotCallFailed {cA cA' gh bl σ σCall σ' σ₀ A I} {g : UInt (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨6074⟩) (okPc := ⟨6090⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨6074⟩) (okPc := ⟨6090⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2216,7 +2216,7 @@ theorem endCageX_spotCallSucceeded {cA gh bl σ σCall σ₀ A I} {g : UInt256} (endCageCallEndPtr :: endCageCallSelectorWord :: endCageCallTargetWord ⟨6⟩ σCall I :: endCageReturnPc :: sel :: []) mem (UInt256.ofNat 5) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨6074⟩) (okPc := ⟨6090⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨6074⟩) (okPc := ⟨6090⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -2367,12 +2367,12 @@ theorem endCageX_potNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (endCageCallCalldataMem (endRelyAuthHashMem I)) (UInt256.ofNat 5) rdata acc k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (endCageCallTargetWord ⟨5⟩ acc.2 I) = ⟨0⟩) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd6162⟩ := endCageX_potExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨6162⟩) (okPc := ⟨6174⟩) rd6162 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨6162⟩) (okPc := ⟨6174⟩) rd6162 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2387,7 +2387,7 @@ theorem endCageX_potCallReady {cA gh bl σ σ₀ A I} {g : UInt256} (endCageCallCalldataMem (endRelyAuthHashMem I)) (UInt256.ofNat 5) rdata acc k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (endCageCallTargetWord ⟨5⟩ acc.2 I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨6177⟩ @@ -2399,7 +2399,7 @@ theorem endCageX_potCallReady {cA gh bl σ σ₀ A I} {g : UInt256} rdata acc k' C' := by obtain ⟨_, _, rd6162⟩ := endCageX_potExtcodesizeGuard h obtain ⟨gasWord, k', C', rd6177⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨6162⟩) (okPc := ⟨6174⟩) rd6162 + RD.solcExtcodesizeGuardOkGas (pc := ⟨6162⟩) (okPc := ⟨6174⟩) rd6162 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -2503,7 +2503,7 @@ theorem endCageX_potCallFailed {cA cA' gh bl σ σCall σ' σ₀ A I} {g : UInt2 (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨6178⟩) (okPc := ⟨6194⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨6178⟩) (okPc := ⟨6194⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2523,7 +2523,7 @@ theorem endCageX_potCallSucceeded {cA gh bl σ σCall σ₀ A I} {g : UInt256} (endCageCallEndPtr :: endCageCallSelectorWord :: endCageCallTargetWord ⟨5⟩ σCall I :: endCageReturnPc :: sel :: []) mem (UInt256.ofNat 5) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨6178⟩) (okPc := ⟨6194⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨6178⟩) (okPc := ⟨6194⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -2674,12 +2674,12 @@ theorem endCageX_cureNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (endCageCallCalldataMem (endRelyAuthHashMem I)) (UInt256.ofNat 5) rdata acc k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (endCageCallTargetWord ⟨7⟩ acc.2 I) = ⟨0⟩) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd6266⟩ := endCageX_cureExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨6266⟩) (okPc := ⟨6278⟩) rd6266 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨6266⟩) (okPc := ⟨6278⟩) rd6266 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2694,7 +2694,7 @@ theorem endCageX_cureCallReady {cA gh bl σ σ₀ A I} {g : UInt256} (endCageCallCalldataMem (endRelyAuthHashMem I)) (UInt256.ofNat 5) rdata acc k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (endCageCallTargetWord ⟨7⟩ acc.2 I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨6281⟩ @@ -2706,7 +2706,7 @@ theorem endCageX_cureCallReady {cA gh bl σ σ₀ A I} {g : UInt256} rdata acc k' C' := by obtain ⟨_, _, rd6266⟩ := endCageX_cureExtcodesizeGuard h obtain ⟨gasWord, k', C', rd6281⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨6266⟩) (okPc := ⟨6278⟩) rd6266 + RD.solcExtcodesizeGuardOkGas (pc := ⟨6266⟩) (okPc := ⟨6278⟩) rd6266 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -2810,7 +2810,7 @@ theorem endCageX_cureCallFailed {cA cA' gh bl σ σCall σ' σ₀ A I} {g : UInt (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨6282⟩) (okPc := ⟨6298⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨6282⟩) (okPc := ⟨6298⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2830,7 +2830,7 @@ theorem endCageX_cureCallSucceeded {cA gh bl σ σCall σ₀ A I} {g : UInt256} (endCageCallEndPtr :: endCageCallSelectorWord :: endCageCallTargetWord ⟨7⟩ σCall I :: endCageReturnPc :: sel :: []) mem (UInt256.ofNat 5) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨6282⟩) (okPc := ⟨6298⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨6282⟩) (okPc := ⟨6298⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -2965,7 +2965,7 @@ theorem endCageCheckedCallNoCode {evm : EVM.State} {locals : Store} (hty : storageTypeAt? contract.storage er = some (.elem .address)) (hloc : config.storage.layout er = fun _ => some (addrLoc slot)) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageCallTargetWord slot evm.accountMap evm.executionEnv) = ⟨0⟩) : ExecBlock config { contract := contract, locals := locals } evm (checkedExternalCallStmts (.storage ref) "cage" (.intLit 0) [] retVar) @@ -2999,7 +2999,7 @@ theorem endCageCheckedCallFailed {evm evm' : EVM.State} {locals : Store} (hty : storageTypeAt? contract.storage er = some (.elem .address)) (hloc : config.storage.layout er = fun _ => some (addrLoc slot)) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageCallTargetWord slot evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -3042,7 +3042,7 @@ theorem endCageCheckedCallSuccess {evm evm' : EVM.State} {locals : Store} (hty : storageTypeAt? contract.storage er = some (.elem .address)) (hloc : config.storage.layout er = fun _ => some (addrLoc slot)) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageCallTargetWord slot evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -3273,10 +3273,10 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact endCageExecBlock_append_revert (tail := tail) h1 h2 simpa [ExecTransitionBody] using ExecFuncBody.execBlockRevert hblock by_cases hVatCodeE : - Reasoning.Theory.uniswapExtCodeSizeWord evmE0.accountMap + Reasoning.Theory.extCodeSizeWord evmE0.accountMap (endCageCallTargetWord ⟨1⟩ evmE0.accountMap evmE0.executionEnv) = ⟨0⟩ · have hVatCodeS : - Reasoning.Theory.uniswapExtCodeSizeWord evmS0.accountMap + Reasoning.Theory.extCodeSizeWord evmS0.accountMap (endCageCallTargetWord ⟨1⟩ evmS0.accountMap evmS0.executionEnv) = ⟨0⟩ := by have hcodeS := endCageCallTargetCodeSize_zero_accountMapEquiv @@ -3312,7 +3312,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} storageStore_executionEnv, endCageStoredAccountMap] using hVatCodeE)) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hVatCodeSNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmS0.accountMap + Reasoning.Theory.extCodeSizeWord evmS0.accountMap (endCageCallTargetWord ⟨1⟩ evmS0.accountMap evmS0.executionEnv) ≠ ⟨0⟩ := by have hcodeS := @@ -3430,11 +3430,11 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} Reasoning.Refinement.execBlock_append (s2 := endCageSourceVatStmts) hSrc0 hVatBlock by_cases hCatCodeE : - Reasoning.Theory.uniswapExtCodeSizeWord evmE1.accountMap + Reasoning.Theory.extCodeSizeWord evmE1.accountMap (endCageCallTargetWord ⟨2⟩ evmE1.accountMap evmE1.executionEnv) = ⟨0⟩ · have hCatCodeS : - Reasoning.Theory.uniswapExtCodeSizeWord evmS1.accountMap + Reasoning.Theory.extCodeSizeWord evmS1.accountMap (endCageCallTargetWord ⟨2⟩ evmS1.accountMap evmS1.executionEnv) = ⟨0⟩ := by have hcodeS := @@ -3471,7 +3471,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simpa [evmE1, evmE0, endCagePostStoresState, initState] using hCatCodeE)) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hCatCodeSNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmS1.accountMap + Reasoning.Theory.extCodeSizeWord evmS1.accountMap (endCageCallTargetWord ⟨2⟩ evmS1.accountMap evmS1.executionEnv) ≠ ⟨0⟩ := by have hcodeS := @@ -3587,11 +3587,11 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} Reasoning.Refinement.execBlock_append (s2 := endCageSourceCatStmts) hSrcVat hCatBlock by_cases hDogCodeE : - Reasoning.Theory.uniswapExtCodeSizeWord evmE2.accountMap + Reasoning.Theory.extCodeSizeWord evmE2.accountMap (endCageCallTargetWord ⟨3⟩ evmE2.accountMap evmE2.executionEnv) = ⟨0⟩ · have hDogCodeS : - Reasoning.Theory.uniswapExtCodeSizeWord evmS2.accountMap + Reasoning.Theory.extCodeSizeWord evmS2.accountMap (endCageCallTargetWord ⟨3⟩ evmS2.accountMap evmS2.executionEnv) = ⟨0⟩ := by have hcodeS := @@ -3630,7 +3630,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simpa [evmE2, evmE1, evmE0, endCagePostStoresState, initState] using hDogCodeE)) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hDogCodeSNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmS2.accountMap + Reasoning.Theory.extCodeSizeWord evmS2.accountMap (endCageCallTargetWord ⟨3⟩ evmS2.accountMap evmS2.executionEnv) ≠ ⟨0⟩ := by have hcodeS := @@ -3748,11 +3748,11 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} Reasoning.Refinement.execBlock_append (s2 := endCageSourceDogStmts) hSrcCat hDogBlock by_cases hVowCodeE : - Reasoning.Theory.uniswapExtCodeSizeWord evmE3.accountMap + Reasoning.Theory.extCodeSizeWord evmE3.accountMap (endCageCallTargetWord ⟨4⟩ evmE3.accountMap evmE3.executionEnv) = ⟨0⟩ · have hVowCodeS : - Reasoning.Theory.uniswapExtCodeSizeWord evmS3.accountMap + Reasoning.Theory.extCodeSizeWord evmS3.accountMap (endCageCallTargetWord ⟨4⟩ evmS3.accountMap evmS3.executionEnv) = ⟨0⟩ := by have hcodeS := @@ -3791,7 +3791,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simpa [evmE3, evmE2, evmE1, evmE0, endCagePostStoresState, initState] using hVowCodeE)) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hVowCodeSNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmS3.accountMap + Reasoning.Theory.extCodeSizeWord evmS3.accountMap (endCageCallTargetWord ⟨4⟩ evmS3.accountMap evmS3.executionEnv) ≠ ⟨0⟩ := by have hcodeS := @@ -3915,11 +3915,11 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} Reasoning.Refinement.execBlock_append (s2 := endCageSourceVowStmts) hSrcDog hVowBlock by_cases hSpotCodeE : - Reasoning.Theory.uniswapExtCodeSizeWord evmE4.accountMap + Reasoning.Theory.extCodeSizeWord evmE4.accountMap (endCageCallTargetWord ⟨6⟩ evmE4.accountMap evmE4.executionEnv) = ⟨0⟩ · have hSpotCodeS : - Reasoning.Theory.uniswapExtCodeSizeWord evmS4.accountMap + Reasoning.Theory.extCodeSizeWord evmS4.accountMap (endCageCallTargetWord ⟨6⟩ evmS4.accountMap evmS4.executionEnv) = ⟨0⟩ := by have hcodeS := @@ -3959,7 +3959,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simpa [evmE4, evmE3, evmE2, evmE1, evmE0, endCagePostStoresState, initState] using hSpotCodeE)) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hSpotCodeSNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmS4.accountMap + Reasoning.Theory.extCodeSizeWord evmS4.accountMap (endCageCallTargetWord ⟨6⟩ evmS4.accountMap evmS4.executionEnv) ≠ ⟨0⟩ := by have hcodeS := @@ -4092,11 +4092,11 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} Reasoning.Refinement.execBlock_append (s2 := endCageSourceSpotStmts) hSrcVow hSpotBlock by_cases hPotCodeE : - Reasoning.Theory.uniswapExtCodeSizeWord evmE5.accountMap + Reasoning.Theory.extCodeSizeWord evmE5.accountMap (endCageCallTargetWord ⟨5⟩ evmE5.accountMap evmE5.executionEnv) = ⟨0⟩ · have hPotCodeS : - Reasoning.Theory.uniswapExtCodeSizeWord evmS5.accountMap + Reasoning.Theory.extCodeSizeWord evmS5.accountMap (endCageCallTargetWord ⟨5⟩ evmS5.accountMap evmS5.executionEnv) = ⟨0⟩ := by have hcodeS := @@ -4137,7 +4137,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simpa [evmE5, evmE4, evmE3, evmE2, evmE1, evmE0, endCagePostStoresState, initState] using hPotCodeE)) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hPotCodeSNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmS5.accountMap + Reasoning.Theory.extCodeSizeWord evmS5.accountMap (endCageCallTargetWord ⟨5⟩ evmS5.accountMap evmS5.executionEnv) ≠ ⟨0⟩ := by have hcodeS := @@ -4282,11 +4282,11 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} Reasoning.Refinement.execBlock_append (s2 := endCageSourcePotStmts) hSrcSpot hPotBlock by_cases hCureCodeE : - Reasoning.Theory.uniswapExtCodeSizeWord evmE6.accountMap + Reasoning.Theory.extCodeSizeWord evmE6.accountMap (endCageCallTargetWord ⟨7⟩ evmE6.accountMap evmE6.executionEnv) = ⟨0⟩ · have hCureCodeS : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmS6.accountMap (endCageCallTargetWord ⟨7⟩ evmS6.accountMap evmS6.executionEnv) = ⟨0⟩ := by @@ -4330,7 +4330,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simpa [evmE6, evmE5, evmE4, evmE3, evmE2, evmE1, evmE0, endCagePostStoresState, initState] using hCureCodeE)) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hCureCodeSNE : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmS6.accountMap (endCageCallTargetWord ⟨7⟩ evmS6.accountMap evmS6.executionEnv) ≠ ⟨0⟩ := by diff --git a/Benchmarks/Dss/End/CageIlk.lean b/Benchmarks/Dss/End/CageIlk.lean index 1af89c99..416689e8 100644 --- a/Benchmarks/Dss/End/CageIlk.lean +++ b/Benchmarks/Dss/End/CageIlk.lean @@ -1487,11 +1487,11 @@ theorem endCageIlkX_vatIlksNoCode {cA gh bl σ σ₀ A I} {g : Sat256} [endCageIlkIlkWord I, endCageIlkReturnPc, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd9065⟩ := endCageIlkX_vatIlksExtcodesizeGuard hsz36 hlive htag h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨9065⟩) (okPc := ⟨9077⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨9065⟩) (okPc := ⟨9077⟩) rd9065 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1506,7 +1506,7 @@ theorem endCageIlkX_vatIlksCallReady {cA gh bl σ σ₀ A I} {g : Sat256} [endCageIlkIlkWord I, endCageIlkReturnPc, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨9080⟩ (gasWord :: endPackVatWord σ I :: ⟨0⟩ :: endFlowVatIlksOutPtr :: endFlowVatIlksInSize :: endFlowVatIlksOutPtr :: endFlowVatIlksOutSize :: @@ -1517,7 +1517,7 @@ theorem endCageIlkX_vatIlksCallReady {cA gh bl σ σ₀ A I} {g : Sat256} obtain ⟨_, _, rd9065⟩ := endCageIlkX_vatIlksExtcodesizeGuard hsz36 hlive htag h obtain ⟨gasWord, k', C', rd9080⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨9065⟩) (okPc := ⟨9077⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨9065⟩) (okPc := ⟨9077⟩) rd9065 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1603,7 +1603,7 @@ theorem endCageIlkX_vatIlksCallFailed {cA cA' gh bl σ σ' σ₀ A I} {g : Sat25 mem (UInt256.ofNat 9) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨9081⟩) (okPc := ⟨9097⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨9081⟩) (okPc := ⟨9097⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1620,7 +1620,7 @@ theorem endCageIlkX_vatIlksCallSucceeded {cA cA' gh bl σ σ' σ₀ A I} {g : Sa (endFlowVatIlksEndPtr :: endFlowVatIlksSelectorWord :: endPackVatWord σ I :: endCageIlkIlkWord I :: endCageIlkReturnPc :: sel :: []) mem (UInt256.ofNat 9) rdata (cA', σ') k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨9081⟩) (okPc := ⟨9097⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨9081⟩) (okPc := ⟨9097⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1699,7 +1699,7 @@ theorem endCageIlkX_vatIlksReturnDecodeShort {cA cA' gh bl σ σ' σ₀ A I} rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rdShort have rdFall := rdShort.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFall + exact RD.solcPush1Dup1Revert0 rdFall (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1886,13 +1886,13 @@ theorem endCageIlkX_spotIlksNoCode {cA cA' gh bl σ σ' σ₀ A I} (endCageIlkVatIlksPostCallMem I vatOut) (UInt256.ofNat 9) vatOut (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (endCageIlkPostArtAccountMap σ' I vatOut) (endCageIlkSpotWord (endCageIlkPostArtAccountMap σ' I vatOut) I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd9201⟩ := endCageIlkX_spotIlksExtcodesizeGuard hsz36 hperm hlo h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨9201⟩) (okPc := ⟨9213⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨9201⟩) (okPc := ⟨9213⟩) rd9201 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1908,7 +1908,7 @@ theorem endCageIlkX_spotIlksCallReady {cA cA' gh bl σ σ' σ₀ A I} (endCageIlkVatIlksPostCallMem I vatOut) (UInt256.ofNat 9) vatOut (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (endCageIlkPostArtAccountMap σ' I vatOut) (endCageIlkSpotWord (endCageIlkPostArtAccountMap σ' I vatOut) I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨9216⟩ @@ -1922,7 +1922,7 @@ theorem endCageIlkX_spotIlksCallReady {cA cA' gh bl σ σ' σ₀ A I} obtain ⟨_, _, rd9201⟩ := endCageIlkX_spotIlksExtcodesizeGuard hsz36 hperm hlo h obtain ⟨gasWord, k', C', rd9216⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨9201⟩) (okPc := ⟨9213⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨9201⟩) (okPc := ⟨9213⟩) rd9201 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1966,7 +1966,7 @@ theorem endCageIlkX_spotIlksPostStaticcall {cA cA' gh bl σ σ' σ₀ A I} spotOut (cA'', σ'') k' C' ∧ spotOut.size < UInt256.size := by obtain ⟨cA'', σ'', z, spotOut, Ain, callGas, k', C', hΘ, rd9217raw, hout⟩ := - RD.uniswapStaticcall h (by native_decide) hdepth + RD.solcStaticcall h (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨cA'', σ'', z, spotOut, Ain, callGas, k', C', ?_, ?_, hout⟩ · simpa [initState] using hΘ @@ -1998,7 +1998,7 @@ theorem endCageIlkX_spotIlksStaticcallDepthLimit {cA cA' gh bl σ σ' σ₀ A I} (endCageIlkSpotIlksCalldataMem I vatOut) (UInt256.ofNat 9) ByteArray.empty (cA', endCageIlkPostArtAccountMap σ' I vatOut) k' C' := by obtain ⟨k', C', rd9217raw⟩ := - RD.uniswapStaticcallDepthLimit h (by native_decide) hdepth + RD.solcStaticcallDepthLimit h (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨k', C', ?_⟩ have hmin : @@ -2023,7 +2023,7 @@ theorem endCageIlkX_spotIlksCallFailed {cA cA' gh bl σ σTarget σ' σ₀ A I} mem (UInt256.ofNat 9) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨9217⟩) (okPc := ⟨9233⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨9217⟩) (okPc := ⟨9233⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2043,7 +2043,7 @@ theorem endCageIlkX_spotIlksCallSucceeded {cA cA' gh bl σ σTarget σ' σ₀ A endCageIlkSpotWord (endCageIlkPostArtAccountMap σTarget I vatOut) I :: ⟨0⟩ :: endCageIlkIlkWord I :: endCageIlkReturnPc :: sel :: []) mem (UInt256.ofNat 9) rdata (cA', σ') k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨9217⟩) (okPc := ⟨9233⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨9217⟩) (okPc := ⟨9233⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -2128,7 +2128,7 @@ theorem endCageIlkX_spotIlksReturnDecodeShort {cA cA' gh bl σ σTarget σ' σ rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rdShort have rdFall := rdShort.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFall + exact RD.solcPush1Dup1Revert0 rdFall (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -2267,10 +2267,10 @@ theorem endCageIlkX_parNoCode {cA cA' gh bl σ σ' σ₀ A I} (endCageIlkSpotIlksPostCallMem I vatOut spotOut) (UInt256.ofNat 9) spotOut (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endCageIlkSpotWord σ' I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endCageIlkSpotWord σ' I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd9321⟩ := endCageIlkX_parExtcodesizeGuard hvat hspot h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨9321⟩) (okPc := ⟨9333⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨9321⟩) (okPc := ⟨9333⟩) rd9321 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2285,7 +2285,7 @@ theorem endCageIlkX_parCallReady {cA cA' gh bl σ σ' σ₀ A I} (endCageIlkSpotIlksPostCallMem I vatOut spotOut) (UInt256.ofNat 9) spotOut (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endCageIlkSpotWord σ' I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endCageIlkSpotWord σ' I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨9336⟩ (gasWord :: endCageIlkSpotWord σ' I :: endFlowVatIlksOutPtr :: endCageIlkNoArgInSize :: endFlowVatIlksOutPtr :: endCageIlkNoArgOutSize :: @@ -2296,7 +2296,7 @@ theorem endCageIlkX_parCallReady {cA cA' gh bl σ σ' σ₀ A I} spotOut (cA', σ') k' C' := by obtain ⟨_, _, rd9321⟩ := endCageIlkX_parExtcodesizeGuard hvat hspot h obtain ⟨gasWord, k', C', rd9336⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨9321⟩) (okPc := ⟨9333⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨9321⟩) (okPc := ⟨9333⟩) rd9321 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -2335,7 +2335,7 @@ theorem endCageIlkX_parPostStaticcall {cA cA' gh bl σ σ' σ₀ A I} parOut (cA'', σ'') k' C' ∧ parOut.size < UInt256.size := by obtain ⟨cA'', σ'', z, parOut, Ain, callGas, k', C', hΘ, rd9337raw, hout⟩ := - RD.uniswapStaticcall h (by native_decide) hdepth + RD.solcStaticcall h (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨cA'', σ'', z, parOut, Ain, callGas, k', C', ?_, ?_, hout⟩ · simpa [initState] using hΘ @@ -2368,7 +2368,7 @@ theorem endCageIlkX_parStaticcallDepthLimit {cA cA' gh bl σ σ' σ₀ A I} (endCageIlkParCalldataMem I vatOut spotOut) (UInt256.ofNat 9) ByteArray.empty (cA', σ') k' C' := by obtain ⟨k', C', rd9337raw⟩ := - RD.uniswapStaticcallDepthLimit h (by native_decide) hdepth + RD.solcStaticcallDepthLimit h (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨k', C', ?_⟩ have hmin : @@ -2393,7 +2393,7 @@ theorem endCageIlkX_parCallFailed {cA cA' gh bl σ σTarget σ' σ₀ A I} mem (UInt256.ofNat 9) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨9337⟩) (okPc := ⟨9353⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨9337⟩) (okPc := ⟨9353⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2413,7 +2413,7 @@ theorem endCageIlkX_parCallSucceeded {cA cA' gh bl σ σTarget σ' σ₀ A I} endCageIlkSpotWord σTarget I :: ⟨9490⟩ :: endCageIlkSpotIlkPipWord spotOut :: endCageIlkIlkWord I :: endCageIlkReturnPc :: sel :: []) mem (UInt256.ofNat 9) rdata (cA', σ') k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨9337⟩) (okPc := ⟨9353⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨9337⟩) (okPc := ⟨9353⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -2633,10 +2633,10 @@ theorem endCageIlkX_readNoCode {cA cA' gh bl σ σ' σ₀ A I} (endCageIlkParPostCallMem I vatOut spotOut parOut) (UInt256.ofNat 9) parOut (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endCageIlkPipCallWord spotOut) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endCageIlkPipCallWord spotOut) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd9429⟩ := endCageIlkX_readExtcodesizeGuard hvat hspot hpar h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨9429⟩) (okPc := ⟨9441⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨9429⟩) (okPc := ⟨9441⟩) rd9429 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2652,7 +2652,7 @@ theorem endCageIlkX_readCallReady {cA cA' gh bl σ σ' σ₀ A I} (endCageIlkParPostCallMem I vatOut spotOut parOut) (UInt256.ofNat 9) parOut (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨9444⟩ (gasWord :: endCageIlkPipCallWord spotOut :: endFlowVatIlksOutPtr :: endCageIlkNoArgInSize :: endFlowVatIlksOutPtr :: endCageIlkNoArgOutSize :: @@ -2664,7 +2664,7 @@ theorem endCageIlkX_readCallReady {cA cA' gh bl σ σ' σ₀ A I} parOut (cA', σ') k' C' := by obtain ⟨_, _, rd9429⟩ := endCageIlkX_readExtcodesizeGuard hvat hspot hpar h obtain ⟨gasWord, k', C', rd9444⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨9429⟩) (okPc := ⟨9441⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨9429⟩) (okPc := ⟨9441⟩) rd9429 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -2705,7 +2705,7 @@ theorem endCageIlkX_readPostStaticcall {cA cA' gh bl σ σ' σ₀ A I} readOut (cA'', σ'') k' C' ∧ readOut.size < UInt256.size := by obtain ⟨cA'', σ'', z, readOut, Ain, callGas, k', C', hΘ, rd9445raw, hout⟩ := - RD.uniswapStaticcall h (by native_decide) hdepth + RD.solcStaticcall h (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨cA'', σ'', z, readOut, Ain, callGas, k', C', ?_, ?_, hout⟩ · simpa [initState] using hΘ @@ -2741,7 +2741,7 @@ theorem endCageIlkX_readStaticcallDepthLimit {cA cA' gh bl σ σ' σ₀ A I} (endCageIlkReadCalldataMem I vatOut spotOut parOut) (UInt256.ofNat 9) ByteArray.empty (cA', σ') k' C' := by obtain ⟨k', C', rd9445raw⟩ := - RD.uniswapStaticcallDepthLimit h (by native_decide) hdepth + RD.solcStaticcallDepthLimit h (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨k', C', ?_⟩ have hmin : @@ -2767,7 +2767,7 @@ theorem endCageIlkX_readCallFailed {cA cA' gh bl σ σ' σ₀ A I} mem (UInt256.ofNat 9) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨9445⟩) (okPc := ⟨9461⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨9445⟩) (okPc := ⟨9461⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2789,7 +2789,7 @@ theorem endCageIlkX_readCallSucceeded {cA cA' gh bl σ σ' σ₀ A I} endCageIlkSpotIlkPipWord spotOut :: endCageIlkIlkWord I :: endCageIlkReturnPc :: sel :: []) mem (UInt256.ofNat 9) rdata (cA', σ') k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨9445⟩) (okPc := ⟨9461⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨9445⟩) (okPc := ⟨9461⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -3603,7 +3603,7 @@ theorem endCageIlk_evalExpr_spot {locals : Store} (evm : EVM.State) endStorageLocLoad_address_offset0 evm ⟨6⟩) theorem endCageIlkAddressWordCode_zero_of_state {evm : EVM.State} (target : UInt256) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord evm.accountMap target = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (AccountAddress.ofNat target.toNat)).option 0 (fun acc => acc.code.size))).toNat = 0 := by @@ -3614,7 +3614,7 @@ theorem endCageIlkAddressWordCode_zero_of_state {evm : EVM.State} (target : UInt (accountAddress_ofUInt256_eq_ofNat_toNat target).symm hzero theorem endCageIlkAddressWordCode_pos_of_state {evm : EVM.State} (target : UInt256) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord evm.accountMap target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (AccountAddress.ofNat target.toNat)).option 0 (fun acc => acc.code.size))).toNat := by @@ -3659,9 +3659,9 @@ theorem endCageIlkSpotWord_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEn theorem endCageIlkSpotCodeSize_zero_EVMStateEquiv {evm₁ evm₂ : EVM.State} (hState : EVMStateEquiv evm₁ evm₂) (hcode : - Reasoning.Theory.uniswapExtCodeSizeWord evm₁.accountMap + Reasoning.Theory.extCodeSizeWord evm₁.accountMap (endCageIlkSpotWord evm₁.accountMap evm₁.executionEnv) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord evm₂.accountMap + Reasoning.Theory.extCodeSizeWord evm₂.accountMap (endCageIlkSpotWord evm₂.accountMap evm₂.executionEnv) = ⟨0⟩ := by have htarget : endCageIlkSpotWord evm₁.accountMap evm₁.executionEnv = @@ -3669,7 +3669,7 @@ theorem endCageIlkSpotCodeSize_zero_EVMStateEquiv {evm₁ evm₂ : EVM.State} rw [← hState.executionEnv] exact endCageIlkSpotWord_accountMapEquiv hState.accountMap have hcodeEq := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hState.accountMap + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hState.accountMap (endCageIlkSpotWord evm₁.accountMap evm₁.executionEnv) rw [← htarget, ← hcodeEq] exact hcode @@ -3677,9 +3677,9 @@ theorem endCageIlkSpotCodeSize_zero_EVMStateEquiv {evm₁ evm₂ : EVM.State} theorem endCageIlkSpotCodeSize_ne_EVMStateEquiv {evm₁ evm₂ : EVM.State} (hState : EVMStateEquiv evm₁ evm₂) (hcode : - Reasoning.Theory.uniswapExtCodeSizeWord evm₁.accountMap + Reasoning.Theory.extCodeSizeWord evm₁.accountMap (endCageIlkSpotWord evm₁.accountMap evm₁.executionEnv) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord evm₂.accountMap + Reasoning.Theory.extCodeSizeWord evm₂.accountMap (endCageIlkSpotWord evm₂.accountMap evm₂.executionEnv) ≠ ⟨0⟩ := by intro hbad have htarget : @@ -3688,7 +3688,7 @@ theorem endCageIlkSpotCodeSize_ne_EVMStateEquiv {evm₁ evm₂ : EVM.State} rw [← hState.executionEnv] exact endCageIlkSpotWord_accountMapEquiv hState.accountMap have hcodeEq := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hState.accountMap + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hState.accountMap (endCageIlkSpotWord evm₁.accountMap evm₁.executionEnv) rw [← htarget, ← hcodeEq] at hbad exact hcode hbad @@ -3696,25 +3696,25 @@ theorem endCageIlkSpotCodeSize_ne_EVMStateEquiv {evm₁ evm₂ : EVM.State} theorem endCageIlkPipCodeSize_zero_accountMapEquiv {σ τ : AccountMap} (hAccounts : accountMapEquiv σ τ) (spotOut : ByteArray) (hcode : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCageIlkPipCallWord spotOut) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endCageIlkPipCallWord spotOut) = ⟨0⟩ := by - rw [← Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord σ (endCageIlkPipCallWord spotOut) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endCageIlkPipCallWord spotOut) = ⟨0⟩ := by + rw [← Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endCageIlkPipCallWord spotOut)] exact hcode theorem endCageIlkPipCodeSize_ne_accountMapEquiv {σ τ : AccountMap} (hAccounts : accountMapEquiv σ τ) (spotOut : ByteArray) (hcode : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩ := by intro hbad - rw [← Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + rw [← Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endCageIlkPipCallWord spotOut)] at hbad exact hcode hbad theorem endCageIlkCheckedVatIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecBlock config { contract := contract, locals := endCageIlkStore I } evm0 (checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] @@ -3750,7 +3750,7 @@ theorem endCageIlkCheckedVatIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} theorem endCageIlkCheckedVatIlksFailure {cA gh bl σ σ₀ A I} {g : UInt256} {evmVat : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -3804,7 +3804,7 @@ theorem endCageIlkCheckedVatIlksFailure {cA gh bl σ σ₀ A I} {g : UInt256} theorem endCageIlkCheckedVatIlksDecodeRevert {cA gh bl σ σ₀ A I} {g : UInt256} {evmVat : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -3860,7 +3860,7 @@ theorem endCageIlkCheckedVatIlksDecodeRevert {cA gh bl σ σ₀ A I} {g : UInt25 theorem endCageIlkCheckedVatIlksSuccess {cA gh bl σ σ₀ A I} {g : UInt256} {evmVat : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -3924,7 +3924,7 @@ theorem endCageIlkCheckedVatIlksSuccess {cA gh bl σ σ₀ A I} {g : UInt256} theorem endCageIlkCheckedSpotIlksNoCode (evm : EVM.State) (I : ExecutionEnv) (vatOut : ByteArray) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageIlkSpotWord evm.accountMap evm.executionEnv) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endCageIlkStoreVatIlk I vatOut } evm (checkedExternalCallStmts (.storage spotRef) "spotIlks" (.intLit 0) [.var "ilk"] @@ -3957,7 +3957,7 @@ theorem endCageIlkCheckedSpotIlksNoCode (evm : EVM.State) (I : ExecutionEnv) theorem endCageIlkCheckedSpotIlksFailure {evm evm' : EVM.State} {I : ExecutionEnv} {vatOut spotOut : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageIlkSpotWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4013,7 +4013,7 @@ theorem endCageIlkCheckedSpotIlksFailure {evm evm' : EVM.State} theorem endCageIlkCheckedSpotIlksDecodeRevert {evm evm' : EVM.State} {I : ExecutionEnv} {vatOut spotOut : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageIlkSpotWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4071,7 +4071,7 @@ theorem endCageIlkCheckedSpotIlksDecodeRevert {evm evm' : EVM.State} theorem endCageIlkCheckedSpotIlksSuccess {evm evm' : EVM.State} {I : ExecutionEnv} {vatOut spotOut : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageIlkSpotWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4146,7 +4146,7 @@ theorem endCageIlk_evalExpr_pip {I : ExecutionEnv} {vatOut spotOut parOut : Byte theorem endCageIlkCheckedParNoCode (evm : EVM.State) (I : ExecutionEnv) (vatOut spotOut : ByteArray) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageIlkSpotWord evm.accountMap evm.executionEnv) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endCageIlkStorePip I vatOut spotOut } evm (checkedExternalCallStmts (.storage spotRef) "par" (.intLit 0) [] "parV" @@ -4181,7 +4181,7 @@ theorem endCageIlkCheckedParNoCode (evm : EVM.State) (I : ExecutionEnv) theorem endCageIlkCheckedParFailure {evm evm' : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageIlkSpotWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4227,7 +4227,7 @@ theorem endCageIlkCheckedParFailure {evm evm' : EVM.State} theorem endCageIlkCheckedParDecodeRevert {evm evm' : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageIlkSpotWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4275,7 +4275,7 @@ theorem endCageIlkCheckedParDecodeRevert {evm evm' : EVM.State} theorem endCageIlkCheckedParSuccess {evm evm' : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageIlkSpotWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4327,7 +4327,7 @@ theorem endCageIlkCheckedParSuccess {evm evm' : EVM.State} theorem endCageIlkCheckedReadNoCode (evm : EVM.State) (I : ExecutionEnv) (vatOut spotOut parOut : ByteArray) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageIlkPipCallWord spotOut) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endCageIlkStorePar I vatOut spotOut parOut } evm (checkedExternalCallStmts (.var "pip") "read" (.intLit 0) [] "pipRead" @@ -4357,7 +4357,7 @@ theorem endCageIlkCheckedReadNoCode (evm : EVM.State) (I : ExecutionEnv) theorem endCageIlkCheckedReadFailure {evm evm' : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut readOut : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4397,7 +4397,7 @@ theorem endCageIlkCheckedReadFailure {evm evm' : EVM.State} theorem endCageIlkCheckedReadDecodeRevert {evm evm' : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut readOut : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4439,7 +4439,7 @@ theorem endCageIlkCheckedReadDecodeRevert {evm evm' : EVM.State} theorem endCageIlkCheckedReadSuccess {evm evm' : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut readOut : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4948,7 +4948,7 @@ theorem endCageIlkBodyReverts_vatIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256 (hlive : endCageIlkLiveWord σ I = ⟨0⟩) (htag : endCageIlkTagWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecTransitionBody config contract evm0 (endCageIlkStore I) cageIlkTransition.body .reverted := by @@ -4967,7 +4967,7 @@ theorem endCageIlkBodyReverts_vatIlksCallFailed {cA gh bl σ σ₀ A I} {g : UIn (hlive : endCageIlkLiveWord σ I = ⟨0⟩) (htag : endCageIlkTagWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -4992,7 +4992,7 @@ theorem endCageIlkBodyReverts_vatIlksDecodeShort {cA gh bl σ σ₀ A I} (hlive : endCageIlkLiveWord σ I = ⟨0⟩) (htag : endCageIlkTagWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -5057,7 +5057,7 @@ theorem endCageIlkTailFromVatReverts_spotTerminated (evmVat : EVM.State) theorem endCageIlkTailFromVatReverts_spotNoCode (evmVat : EVM.State) (I : ExecutionEnv) (vatOut : ByteArray) (hsz36 : 36 ≤ I.calldata.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (endCageIlkPostArtState evmVat I vatOut).accountMap (endCageIlkSpotWord (endCageIlkPostArtState evmVat I vatOut).accountMap (endCageIlkPostArtState evmVat I vatOut).executionEnv) = ⟨0⟩) : @@ -5084,7 +5084,7 @@ theorem endCageIlkTailFromVatReverts_spotFailure {evmVat evmSpot : EVM.State} {I : ExecutionEnv} {vatOut spotOut : ByteArray} (hsz36 : 36 ≤ I.calldata.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (endCageIlkPostArtState evmVat I vatOut).accountMap (endCageIlkSpotWord (endCageIlkPostArtState evmVat I vatOut).accountMap (endCageIlkPostArtState evmVat I vatOut).executionEnv) ≠ ⟨0⟩) @@ -5120,7 +5120,7 @@ theorem endCageIlkTailFromVatReverts_spotDecodeShort {evmVat evmSpot : EVM.State {I : ExecutionEnv} {vatOut spotOut : ByteArray} (hsz36 : 36 ≤ I.calldata.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (endCageIlkPostArtState evmVat I vatOut).accountMap (endCageIlkSpotWord (endCageIlkPostArtState evmVat I vatOut).accountMap (endCageIlkPostArtState evmVat I vatOut).executionEnv) ≠ ⟨0⟩) @@ -5183,7 +5183,7 @@ theorem endCageIlkTailAfterSpotReverts_parTerminated {evmSpot : EVM.State} theorem endCageIlkTailAfterSpotReverts_parNoCode (evmSpot : EVM.State) (I : ExecutionEnv) (vatOut spotOut : ByteArray) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmSpot.accountMap + Reasoning.Theory.extCodeSizeWord evmSpot.accountMap (endCageIlkSpotWord evmSpot.accountMap evmSpot.executionEnv) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endCageIlkStorePip I vatOut spotOut } evmSpot @@ -5200,7 +5200,7 @@ theorem endCageIlkTailAfterSpotReverts_parNoCode (evmSpot : EVM.State) theorem endCageIlkTailAfterSpotReverts_parFailure {evmSpot evmPar : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmSpot.accountMap + Reasoning.Theory.extCodeSizeWord evmSpot.accountMap (endCageIlkSpotWord evmSpot.accountMap evmSpot.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evmSpot @@ -5223,7 +5223,7 @@ theorem endCageIlkTailAfterSpotReverts_parFailure {evmSpot evmPar : EVM.State} theorem endCageIlkTailAfterSpotReverts_parDecodeShort {evmSpot evmPar : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmSpot.accountMap + Reasoning.Theory.extCodeSizeWord evmSpot.accountMap (endCageIlkSpotWord evmSpot.accountMap evmSpot.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evmSpot @@ -5269,7 +5269,7 @@ theorem endCageIlkTailAfterParReverts_readTerminated {evmPar : EVM.State} theorem endCageIlkTailAfterParReverts_readNoCode (evmPar : EVM.State) (I : ExecutionEnv) (vatOut spotOut parOut : ByteArray) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmPar.accountMap + Reasoning.Theory.extCodeSizeWord evmPar.accountMap (endCageIlkPipCallWord spotOut) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endCageIlkStorePar I vatOut spotOut parOut } evmPar @@ -5284,7 +5284,7 @@ theorem endCageIlkTailAfterParReverts_readNoCode (evmPar : EVM.State) theorem endCageIlkTailAfterParReverts_readFailure {evmPar evmRead : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut readOut : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmPar.accountMap + Reasoning.Theory.extCodeSizeWord evmPar.accountMap (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evmPar @@ -5303,7 +5303,7 @@ theorem endCageIlkTailAfterParReverts_readFailure {evmPar evmRead : EVM.State} theorem endCageIlkTailAfterParReverts_readDecodeShort {evmPar evmRead : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut readOut : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmPar.accountMap + Reasoning.Theory.extCodeSizeWord evmPar.accountMap (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evmPar @@ -5324,7 +5324,7 @@ theorem endCageIlkTailAfterParReadOk {evmPar evmRead : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut readOut : ByteArray} {res : ExecResult} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmPar.accountMap + Reasoning.Theory.extCodeSizeWord evmPar.accountMap (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evmPar @@ -5355,7 +5355,7 @@ theorem endCageIlkTailAfterSpotParOk {evmSpot evmPar : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut : ByteArray} {res : ExecResult} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmSpot.accountMap + Reasoning.Theory.extCodeSizeWord evmSpot.accountMap (endCageIlkSpotWord evmSpot.accountMap evmSpot.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evmSpot @@ -5399,7 +5399,7 @@ theorem endCageIlkTailFromVatSpotOk {evmVat evmSpot : EVM.State} {res : ExecResult} (hsz36 : 36 ≤ I.calldata.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (endCageIlkPostArtState evmVat I vatOut).accountMap (endCageIlkSpotWord (endCageIlkPostArtState evmVat I vatOut).accountMap (endCageIlkPostArtState evmVat I vatOut).executionEnv) ≠ ⟨0⟩) @@ -5494,7 +5494,7 @@ theorem endCageIlkPrefixVatIlksSuccess {cA gh bl σ σ₀ A I} {g : UInt256} (hlive : endCageIlkLiveWord σ I = ⟨0⟩) (htag : endCageIlkTagWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -5548,7 +5548,7 @@ theorem endCageIlkBodyReverts_vatIlksOkTailReverted {cA gh bl σ σ₀ A I} (hlive : endCageIlkLiveWord σ I = ⟨0⟩) (htag : endCageIlkTagWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -5610,7 +5610,7 @@ theorem endCageIlkBodyReturns_vatIlksOkTail {cA gh bl σ σ₀ A I} (hlive : endCageIlkLiveWord σ I = ⟨0⟩) (htag : endCageIlkTagWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -5832,10 +5832,10 @@ theorem endCageIlkBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rw [← htagCouple] exact htag by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (endPackVatWord σ_evm I) = + Reasoning.Theory.extCodeSizeWord σ_evm (endPackVatWord σ_evm I) = ⟨0⟩ · have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endPackVatWord σ_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv hAccounts hvatCode have hbody : @@ -5851,10 +5851,10 @@ theorem endCageIlkBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (g := Sat256.ofUInt256 g) hsz36 hlive htag hbodyReach hvatCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (endPackVatWord σ_evm I) ≠ ⟨0⟩ := hvatCode have hvatCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endPackVatWord σ_solm I) ≠ ⟨0⟩ := endPackVatCodeSize_ne_accountMapEquiv hAccounts hvatCodeNE obtain ⟨gasWord, _, _, hcallReady⟩ := @@ -5980,18 +5980,18 @@ theorem endCageIlkBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (val₁ := endFlowVatIlkArtWord vatOut) (val₂ := endFlowVatIlkArtWord vatOut) rfl by_cases hspotCode : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (endCageIlkPostArtAccountMap σ_vat I vatOut) (endCageIlkSpotWord (endCageIlkPostArtAccountMap σ_vat I vatOut) I) = ⟨0⟩ · have hspotCodeState : - Reasoning.Theory.uniswapExtCodeSizeWord evmArtEvm.accountMap + Reasoning.Theory.extCodeSizeWord evmArtEvm.accountMap (endCageIlkSpotWord evmArtEvm.accountMap evmArtEvm.executionEnv) = ⟨0⟩ := by simpa [evmArtEvm, endCageIlkPostArtState, endCageIlkPostArtAccountMap, storageStore_accountMap, storageStore_executionEnv] using hspotCode have hspotCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmArtSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmArtSolm.accountMap (endCageIlkSpotWord evmArtSolm.accountMap evmArtSolm.executionEnv) = ⟨0⟩ := endCageIlkSpotCodeSize_zero_EVMStateEquiv hStateArt hspotCodeState @@ -6029,18 +6029,18 @@ theorem endCageIlkBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (g := Sat256.ofUInt256 g) hsz36 hperm hloVat rd9122 hspotCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hspotCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (endCageIlkPostArtAccountMap σ_vat I vatOut) (endCageIlkSpotWord (endCageIlkPostArtAccountMap σ_vat I vatOut) I) ≠ ⟨0⟩ := hspotCode have hspotCodeStateNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmArtEvm.accountMap + Reasoning.Theory.extCodeSizeWord evmArtEvm.accountMap (endCageIlkSpotWord evmArtEvm.accountMap evmArtEvm.executionEnv) ≠ ⟨0⟩ := by simpa [evmArtEvm, endCageIlkPostArtState, endCageIlkPostArtAccountMap, storageStore_accountMap, storageStore_executionEnv] using hspotCodeNE have hspotCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmArtSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmArtSolm.accountMap (endCageIlkSpotWord evmArtSolm.accountMap evmArtSolm.executionEnv) ≠ ⟨0⟩ := endCageIlkSpotCodeSize_ne_EVMStateEquiv hStateArt hspotCodeStateNE @@ -6249,16 +6249,16 @@ theorem endCageIlkBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} · simpa [evmSpotEvm, evmSpotSolm] using hStateArt.createdAccounts · simpa [evmSpotEvm, evmSpotSolm] using hAccountsSpot by_cases hparCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_spot + Reasoning.Theory.extCodeSizeWord σ_spot (endCageIlkSpotWord σ_spot I) = ⟨0⟩ · have hparCodeState : - Reasoning.Theory.uniswapExtCodeSizeWord evmSpotEvm.accountMap + Reasoning.Theory.extCodeSizeWord evmSpotEvm.accountMap (endCageIlkSpotWord evmSpotEvm.accountMap evmSpotEvm.executionEnv) = ⟨0⟩ := by simpa [evmSpotEvm, evmArtEvm, endCageIlkPostArtState, storageStore_executionEnv] using hparCode have hparCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmSpotSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSpotSolm.accountMap (endCageIlkSpotWord evmSpotSolm.accountMap evmSpotSolm.executionEnv) = ⟨0⟩ := endCageIlkSpotCodeSize_zero_EVMStateEquiv hStateSpot hparCodeState @@ -6303,16 +6303,16 @@ theorem endCageIlkBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endCageIlkX_parNoCode hloVat hspotOutSize rd9258 hparCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hparCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_spot + Reasoning.Theory.extCodeSizeWord σ_spot (endCageIlkSpotWord σ_spot I) ≠ ⟨0⟩ := hparCode have hparCodeStateNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmSpotEvm.accountMap + Reasoning.Theory.extCodeSizeWord evmSpotEvm.accountMap (endCageIlkSpotWord evmSpotEvm.accountMap evmSpotEvm.executionEnv) ≠ ⟨0⟩ := by simpa [evmSpotEvm, evmArtEvm, endCageIlkPostArtState, storageStore_executionEnv] using hparCodeNE have hparCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmSpotSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSpotSolm.accountMap (endCageIlkSpotWord evmSpotSolm.accountMap evmSpotSolm.executionEnv) ≠ ⟨0⟩ := endCageIlkSpotCodeSize_ne_EVMStateEquiv hStateSpot hparCodeStateNE @@ -6693,15 +6693,15 @@ theorem endCageIlkBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simpa [evmVatSolm, evmSolm] using hcallSolm) hloVat htail by_cases hreadCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_par + Reasoning.Theory.extCodeSizeWord σ_par (endCageIlkPipCallWord spotOut) = ⟨0⟩ · have hreadCodeState : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmParEvm.accountMap (endCageIlkPipCallWord spotOut) = ⟨0⟩ := by simpa [evmParEvm] using hreadCode have hreadCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmParSolm.accountMap (endCageIlkPipCallWord spotOut) = ⟨0⟩ := endCageIlkPipCodeSize_zero_accountMapEquiv @@ -6716,15 +6716,15 @@ theorem endCageIlkBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} hparOutSize rd9378 hreadCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hreadCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_par + Reasoning.Theory.extCodeSizeWord σ_par (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩ := hreadCode have hreadCodeStateNE : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmParEvm.accountMap (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩ := by simpa [evmParEvm] using hreadCodeNE have hreadCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmParSolm.accountMap (endCageIlkPipCallWord spotOut) ≠ ⟨0⟩ := endCageIlkPipCodeSize_ne_accountMapEquiv diff --git a/Benchmarks/Dss/End/Cash.lean b/Benchmarks/Dss/End/Cash.lean index 00223e89..ecdebb13 100644 --- a/Benchmarks/Dss/End/Cash.lean +++ b/Benchmarks/Dss/End/Cash.lean @@ -1205,7 +1205,7 @@ theorem endCashX_rmulStackReady {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt raw swap1 (by native_decide) (by evm_ov), raw dup5 (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] - have rd9745 := RD.uniswapAddress rd9744 (by native_decide) (by evm_ov) + have rd9745 := RD.address rd9744 (by native_decide) (by evm_ov) have rd9754 := evm_run rd9745 with [ raw swap1 (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), @@ -1322,7 +1322,7 @@ theorem endCashX_mulHelperOverflow {cA gh bl σ σ₀ A I} {g : Sat256} UInt256.eq (UInt256.div (x * y) y) x = ⟨0⟩ := u256_eq_of_ne hdivNe have rdFallthrough := rd10201.jumpiNT (by native_decide) heqCond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -1624,10 +1624,10 @@ theorem endCashX_fluxNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel amt : UInt endCashIlkWord I, endCashReturnPc, sel] (endCashFixHashMem2 I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCashVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endCashVatWord σ I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd9839⟩ := endCashX_fluxExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨9839⟩) (okPc := ⟨9851⟩) rd9839 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨9839⟩) (okPc := ⟨9851⟩) rd9839 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1641,7 +1641,7 @@ theorem endCashX_fluxCallReady {cA gh bl σ σ₀ A I} {g : Sat256} {sel amt : U endCashIlkWord I, endCashReturnPc, sel] (endCashFixHashMem2 I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨9854⟩ (gasWord :: endCashVatWord σ I :: ⟨0⟩ :: endCashFluxOutPtr :: endCashFluxInSize :: endCashFluxOutPtr :: endCashFluxOutSize :: @@ -1651,7 +1651,7 @@ theorem endCashX_fluxCallReady {cA gh bl σ σ₀ A I} {g : Sat256} {sel amt : U ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd9839⟩ := endCashX_fluxExtcodesizeGuard h obtain ⟨gasWord, k', C', rd9854⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨9839⟩) (okPc := ⟨9851⟩) rd9839 + RD.solcExtcodesizeGuardOkGas (pc := ⟨9839⟩) (okPc := ⟨9851⟩) rd9839 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1742,7 +1742,7 @@ theorem endCashX_fluxCallFailed {cA cA' gh bl σ σ' σ₀ A I} {g sel : UInt256 (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨9855⟩) (okPc := ⟨9871⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨9855⟩) (okPc := ⟨9871⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1762,7 +1762,7 @@ theorem endCashX_fluxCallSucceeded {cA gh bl σ σ₀ A I} {g sel : UInt256} (endCashFluxEndPtr :: endCashFluxSelectorWord :: endCashVatWord σ I :: endCashWadWord I :: endCashIlkWord I :: endCashReturnPc :: sel :: []) mem (UInt256.ofNat 9) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨9855⟩) (okPc := ⟨9871⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨9855⟩) (okPc := ⟨9871⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1898,7 +1898,7 @@ theorem endCashX_outAddOverflow {cA cA' gh bl σ σ' σ₀ A I} {g sel : UInt256 have rd10104pre := evm_run rd10100 with [raw push2 ⟨10108⟩ (by native_decide) (by evm_ov)] have rd10104 := rd10104pre.jumpiNT (by native_decide) (by decide) (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rd10104 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd10104 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -2564,10 +2564,10 @@ theorem endCashVatWord_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} theorem endCashVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCashVatWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endCashVatWord τ I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (endCashVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endCashVatWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endCashVatWord σ I) have htarget : endCashVatWord σ I = endCashVatWord τ I := endCashVatWord_accountMapEquiv hAccounts @@ -2577,12 +2577,12 @@ theorem endCashVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execut theorem endCashVatCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endCashVatWord τ I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endCashVatWord τ I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endCashVatWord σ I) have htarget : endCashVatWord σ I = endCashVatWord τ I := endCashVatWord_accountMapEquiv hAccounts @@ -2596,7 +2596,7 @@ theorem endCashVatAddr_eq_ofUInt256 (σ : AccountMap) (I : ExecutionEnv) : theorem endCashVatCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt256} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCashVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endCashVatWord σ I) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (endCashVatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [initState, State.lookupAccount] using @@ -2606,7 +2606,7 @@ theorem endCashVatCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt25 theorem endCashVatCode_pos_of_codeSize_ne {cA gh bl σ σ₀ A I} {g : UInt256} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (endCashVatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [initState, State.lookupAccount] using @@ -2771,7 +2771,7 @@ theorem endCashBodyReverts_fluxNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hfix : endCashFixWord σ I ≠ ⟨0⟩) (hfit : (endCashWadWord I).toNat * (endCashFixWord σ I).toNat < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCashVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endCashVatWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecTransitionBody config contract evm0 (endCashStore I) cashTransition.body .reverted := by intro evm0 @@ -2858,7 +2858,7 @@ theorem endCashBodyReverts_fluxCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} (hfix : endCashFixWord σ I ≠ ⟨0⟩) (hfit : (endCashWadWord I).toNat * (endCashFixWord σ I).toNat < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endCashVatAddr σ I)) "flux" 0 @@ -3402,7 +3402,7 @@ theorem endCashPrefixFluxSuccess {cA gh bl σ σ₀ A I} {g : UInt256} (hfix : endCashFixWord σ I ≠ ⟨0⟩) (hfit : (endCashWadWord I).toNat * (endCashFixWord σ I).toNat < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endCashVatAddr σ I)) "flux" 0 @@ -3527,7 +3527,7 @@ theorem endCashBodyReverts_outAddOverflow {cA gh bl σ σ₀ A I} {g : UInt256} (hfix : endCashFixWord σ I ≠ ⟨0⟩) (hfit : (endCashWadWord I).toNat * (endCashFixWord σ I).toNat < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endCashVatAddr σ I)) "flux" 0 @@ -3576,7 +3576,7 @@ theorem endCashBodyReverts_outExceedsBag {cA gh bl σ σ₀ A I} {g : UInt256} (hfix : endCashFixWord σ I ≠ ⟨0⟩) (hfit : (endCashWadWord I).toNat * (endCashFixWord σ I).toNat < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endCashVatAddr σ I)) "flux" 0 @@ -3630,7 +3630,7 @@ theorem endCashBodyReturns {cA gh bl σ σ₀ A I} {g : UInt256} (hfix : endCashFixWord σ I ≠ ⟨0⟩) (hfit : (endCashWadWord I).toNat * (endCashFixWord σ I).toNat < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endCashVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endCashVatAddr σ I)) "flux" 0 @@ -3782,10 +3782,10 @@ theorem endCashBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} obtain ⟨_, _, hafterRmul⟩ := endCashX_rmulReturns (g := Sat256.ofUInt256 g) hfit hfix hrmulEntry by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (endCashVatWord σ_evm I) = + Reasoning.Theory.extCodeSizeWord σ_evm (endCashVatWord σ_evm I) = ⟨0⟩ · have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endCashVatWord σ_solm I) = ⟨0⟩ := endCashVatCodeSize_zero_accountMapEquiv hAccounts hvatCode have hbody : @@ -3799,10 +3799,10 @@ theorem endCashBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endCashX_fluxNoCode (g := Sat256.ofUInt256 g) hafterRmul hvatCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (endCashVatWord σ_evm I) ≠ ⟨0⟩ := hvatCode have hvatCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endCashVatWord σ_solm I) ≠ ⟨0⟩ := endCashVatCodeSize_ne_accountMapEquiv hAccounts hvatCodeNE obtain ⟨gasWord, _, _, hcallReady⟩ := diff --git a/Benchmarks/Dss/End/Common.lean b/Benchmarks/Dss/End/Common.lean index c0766c98..5600acaf 100644 --- a/Benchmarks/Dss/End/Common.lean +++ b/Benchmarks/Dss/End/Common.lean @@ -1074,11 +1074,11 @@ theorem endEvalExpr_extCodeGuard_false {evm : EVM.State} {locals : Store} theorem endUniswapExtCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => exfalso @@ -1100,11 +1100,11 @@ theorem endUniswapExtCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} {tar theorem endUniswapExtCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using diff --git a/Benchmarks/Dss/End/Dispatch.lean b/Benchmarks/Dss/End/Dispatch.lean index 076e535d..eafd3cb7 100644 --- a/Benchmarks/Dss/End/Dispatch.lean +++ b/Benchmarks/Dss/End/Dispatch.lean @@ -1297,7 +1297,7 @@ theorem endJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : UInt25 have h496 := h.push2 endDispatchRevertPc hpush (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h496 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h496 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem endGroup65NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -1443,7 +1443,7 @@ theorem endGroup452NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ |>.selectorArmNotTakenAuto (endGroup452ArmsWellFormed 3 (by omega)) (heq0 3 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h496 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h496 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem endBodyReverts_nonPayable (t : TransitionDecl) (ht : t ∈ contract.transitions) @@ -1465,7 +1465,7 @@ theorem endX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem endX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -1488,7 +1488,7 @@ theorem endX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h496 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h496 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem endX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} diff --git a/Benchmarks/Dss/End/Flow.lean b/Benchmarks/Dss/End/Flow.lean index 8211f56d..fe718838 100644 --- a/Benchmarks/Dss/End/Flow.lean +++ b/Benchmarks/Dss/End/Flow.lean @@ -1264,10 +1264,10 @@ theorem endFlowX_vatIlksNoCode {cA gh bl σ σ₀ A I} {g : Sat256} [endFlowIlkWord I, endFlowReturnPc, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd2948⟩ := endFlowX_vatIlksExtcodesizeGuard hsz36 hdebt hfix h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2948⟩) (okPc := ⟨2960⟩) rd2948 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2948⟩) (okPc := ⟨2960⟩) rd2948 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1282,7 +1282,7 @@ theorem endFlowX_vatIlksCallReady {cA gh bl σ σ₀ A I} {g : Sat256} [endFlowIlkWord I, endFlowReturnPc, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2963⟩ (gasWord :: endPackVatWord σ I :: ⟨0⟩ :: endFlowVatIlksOutPtr :: endFlowVatIlksInSize :: endFlowVatIlksOutPtr :: endFlowVatIlksOutSize :: @@ -1292,7 +1292,7 @@ theorem endFlowX_vatIlksCallReady {cA gh bl σ σ₀ A I} {g : Sat256} ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd2948⟩ := endFlowX_vatIlksExtcodesizeGuard hsz36 hdebt hfix h obtain ⟨gasWord, k', C', rd2963⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2948⟩) (okPc := ⟨2960⟩) rd2948 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2948⟩) (okPc := ⟨2960⟩) rd2948 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1378,7 +1378,7 @@ theorem endFlowX_vatIlksCallFailed {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} mem (UInt256.ofNat 9) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2964⟩) (okPc := ⟨2980⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨2964⟩) (okPc := ⟨2980⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1395,7 +1395,7 @@ theorem endFlowX_vatIlksCallSucceeded {cA cA' gh bl σ σ' σ₀ A I} {g : Sat25 (endFlowVatIlksEndPtr :: endFlowVatIlksSelectorWord :: endPackVatWord σ I :: ⟨0⟩ :: endFlowIlkWord I :: endFlowReturnPc :: sel :: []) mem (UInt256.ofNat 9) rdata (cA', σ') k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨2964⟩) (okPc := ⟨2980⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨2964⟩) (okPc := ⟨2980⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1489,7 +1489,7 @@ theorem endFlowX_vatIlksReturnDecodeShort {cA cA' gh bl σ σ' σ₀ A I} {g : S rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rdShort have rdFall := rdShort.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFall + exact RD.solcPush1Dup1Revert0 rdFall (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1698,7 +1698,7 @@ theorem endFlowX_mulHelperOverflow {cA gh bl σ σ₀ A I} {g : Sat256} UInt256.eq (UInt256.div (x * y) y) x = ⟨0⟩ := u256_eq_of_ne hdivNe have rdFallthrough := rd10201.jumpiNT (by native_decide) heqCond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -2556,7 +2556,7 @@ theorem endFlowX_tailReturns {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} theorem endFlowCheckedVatIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecBlock config { contract := contract, locals := endFlowStore I } evm0 (checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] @@ -2592,7 +2592,7 @@ theorem endFlowCheckedVatIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} theorem endFlowCheckedVatIlksFailure {cA gh bl σ σ₀ A I} {g : UInt256} {evmVat : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -2646,7 +2646,7 @@ theorem endFlowCheckedVatIlksFailure {cA gh bl σ σ₀ A I} {g : UInt256} theorem endFlowCheckedVatIlksDecodeRevert {cA gh bl σ σ₀ A I} {g : UInt256} {evmVat : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -2702,7 +2702,7 @@ theorem endFlowCheckedVatIlksDecodeRevert {cA gh bl σ σ₀ A I} {g : UInt256} theorem endFlowCheckedVatIlksSuccess {cA gh bl σ σ₀ A I} {g : UInt256} {evmVat : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -4042,7 +4042,7 @@ theorem endFlowBodyReverts_vatIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hdebt : endFlowDebtWord σ I ≠ ⟨0⟩) (hfix : endFlowFixWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecTransitionBody config contract evm0 (endFlowStore I) flowTransition.body .reverted := by intro evm0 @@ -4061,7 +4061,7 @@ theorem endFlowBodyReverts_vatIlksCallFailed {cA gh bl σ σ₀ A I} {g : UInt25 (hdebt : endFlowDebtWord σ I ≠ ⟨0⟩) (hfix : endFlowFixWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -4086,7 +4086,7 @@ theorem endFlowBodyReverts_vatIlksDecodeShort {cA gh bl σ σ₀ A I} {g : UInt2 (hdebt : endFlowDebtWord σ I ≠ ⟨0⟩) (hfix : endFlowFixWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -4112,7 +4112,7 @@ theorem endFlowPrefixVatIlksSuccess {cA gh bl σ σ₀ A I} {g : UInt256} (hdebt : endFlowDebtWord σ I ≠ ⟨0⟩) (hfix : endFlowFixWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -4169,7 +4169,7 @@ theorem endFlowBodyReverts_vatIlksOkTailReverted {cA gh bl σ σ₀ A I} {g : UI (hdebt : endFlowDebtWord σ I ≠ ⟨0⟩) (hfix : endFlowFixWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -4226,7 +4226,7 @@ theorem endFlowBodyReturns_vatIlksOkTail {cA gh bl σ σ₀ A I} {g : UInt256} (hdebt : endFlowDebtWord σ I ≠ ⟨0⟩) (hfix : endFlowFixWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -4284,7 +4284,7 @@ theorem endFlowBodyReturns {cA gh bl σ σ₀ A I} {g : UInt256} (hdebt : endFlowDebtWord σ I ≠ ⟨0⟩) (hfix : endFlowFixWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -4430,10 +4430,10 @@ theorem endFlowBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rw [← hfixCouple] exact hfix by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (endPackVatWord σ_evm I) = + Reasoning.Theory.extCodeSizeWord σ_evm (endPackVatWord σ_evm I) = ⟨0⟩ · have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endPackVatWord σ_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv hAccounts hvatCode have hbody : @@ -4448,10 +4448,10 @@ theorem endFlowBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (g := Sat256.ofUInt256 g) hsz36 hdebt hfix hbodyReach hvatCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (endPackVatWord σ_evm I) ≠ ⟨0⟩ := hvatCode have hvatCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endPackVatWord σ_solm I) ≠ ⟨0⟩ := endPackVatCodeSize_ne_accountMapEquiv hAccounts hvatCodeNE obtain ⟨gasWord, _, _, hcallReady⟩ := diff --git a/Benchmarks/Dss/End/Free.lean b/Benchmarks/Dss/End/Free.lean index 9a22d462..ef2ebbde 100644 --- a/Benchmarks/Dss/End/Free.lean +++ b/Benchmarks/Dss/End/Free.lean @@ -1319,7 +1319,7 @@ theorem endFreeBodyReverts_urnsNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : endSlotWord ⟨8⟩ σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecTransitionBody config contract evm0 (endFreeStore I) freeTransition.body .reverted := by intro evm0 @@ -1381,7 +1381,7 @@ theorem endFreeBodyReverts_urnsCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : endSlotWord ⟨8⟩ σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) @@ -1455,7 +1455,7 @@ theorem endFreeBodyReverts_urnsDecodeShort {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : endSlotWord ⟨8⟩ σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) @@ -1531,7 +1531,7 @@ theorem endFreePrefixUrnsSuccess {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : endSlotWord ⟨8⟩ σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) @@ -1790,7 +1790,7 @@ theorem endFreeTailReverts_grabNoCode (evm : EVM.State) (I : ExecutionEnv) (hart : endFreeUrnArtWord out = ⟨0⟩) (hink : (endFreeUrnInkWord out).toNat ≤ 2 ^ 255) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endPackVatWord evm.accountMap I) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endFreeStoreVatUrn I out } evm endFreeAfterUrnsStmts .reverted := by @@ -1871,7 +1871,7 @@ theorem endFreeTailReverts_grabCallFailed (evm evmGrab : EVM.State) (I : Executi (hart : endFreeUrnArtWord out = ⟨0⟩) (hink : (endFreeUrnInkWord out).toNat ≤ 2 ^ 255) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endPackVatWord evm.accountMap I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -1982,7 +1982,7 @@ theorem endFreeTailReturns_grabSuccess (evm evmGrab : EVM.State) (I : ExecutionE (hart : endFreeUrnArtWord out = ⟨0⟩) (hink : (endFreeUrnInkWord out).toNat ≤ 2 ^ 255) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endPackVatWord evm.accountMap I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -2094,7 +2094,7 @@ theorem endFreeBodyReverts_artNonzero {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : endSlotWord ⟨8⟩ σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) @@ -2132,7 +2132,7 @@ theorem endFreeBodyReverts_inkOverflow {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : endSlotWord ⟨8⟩ σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) @@ -2171,7 +2171,7 @@ theorem endFreeBodyReverts_grabNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : endSlotWord ⟨8⟩ σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) @@ -2183,7 +2183,7 @@ theorem endFreeBodyReverts_grabNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hart : endFreeUrnArtWord out = ⟨0⟩) (hink : (endFreeUrnInkWord out).toNat ≤ 2 ^ 255) (hgrabCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmUrns.accountMap + Reasoning.Theory.extCodeSizeWord evmUrns.accountMap (endPackVatWord evmUrns.accountMap I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecTransitionBody config contract evm0 (endFreeStore I) freeTransition.body .reverted := by @@ -2215,7 +2215,7 @@ theorem endFreeBodyReverts_grabCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : endSlotWord ⟨8⟩ σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) @@ -2228,7 +2228,7 @@ theorem endFreeBodyReverts_grabCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} (hart : endFreeUrnArtWord out = ⟨0⟩) (hink : (endFreeUrnInkWord out).toNat ≤ 2 ^ 255) (hgrabCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmUrns.accountMap + Reasoning.Theory.extCodeSizeWord evmUrns.accountMap (endPackVatWord evmUrns.accountMap I) ≠ ⟨0⟩) (hgrabCall : typedCallViaEVM config evmUrns @@ -2271,7 +2271,7 @@ theorem endFreeBodyReturns_grabSuccess {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hlive : endSlotWord ⟨8⟩ σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) @@ -2284,7 +2284,7 @@ theorem endFreeBodyReturns_grabSuccess {cA gh bl σ σ₀ A I} {g : UInt256} (hart : endFreeUrnArtWord out = ⟨0⟩) (hink : (endFreeUrnInkWord out).toNat ≤ 2 ^ 255) (hgrabCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmUrns.accountMap + Reasoning.Theory.extCodeSizeWord evmUrns.accountMap (endPackVatWord evmUrns.accountMap I) ≠ ⟨0⟩) (hgrabCall : typedCallViaEVM config evmUrns @@ -2517,10 +2517,10 @@ theorem endFreeX_urnsNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} (h : RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨7760⟩ [endFreeIlkWord I, endFreeReturnPc, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd7831⟩ := endFreeX_urnsExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨7831⟩) (okPc := ⟨7843⟩) rd7831 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨7831⟩) (okPc := ⟨7843⟩) rd7831 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2531,7 +2531,7 @@ theorem endFreeX_urnsCallReady {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt2 (h : RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨7760⟩ [endFreeIlkWord I, endFreeReturnPc, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨7846⟩ (gasWord :: endPackVatWord σ I :: ⟨0⟩ :: endFreeUrnsOutPtr :: endFreeUrnsInSize :: endFreeUrnsOutPtr :: endFreeUrnsOutSize :: @@ -2541,7 +2541,7 @@ theorem endFreeX_urnsCallReady {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt2 ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd7831⟩ := endFreeX_urnsExtcodesizeGuard h obtain ⟨gasWord, k', C', rd7846⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨7831⟩) (okPc := ⟨7843⟩) rd7831 + RD.solcExtcodesizeGuardOkGas (pc := ⟨7831⟩) (okPc := ⟨7843⟩) rd7831 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -2627,7 +2627,7 @@ theorem endFreeX_urnsCallFailed {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} mem (UInt256.ofNat 7) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨7847⟩) (okPc := ⟨7863⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨7847⟩) (okPc := ⟨7863⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2645,7 +2645,7 @@ theorem endFreeX_urnsCallSucceeded {cA gh bl σ σ₀ A I} {g : Sat256} (endFreeUrnsEndPtr :: endFreeUrnsSelectorWord :: endPackVatWord σ I :: ⟨0⟩ :: ⟨0⟩ :: endFreeIlkWord I :: endFreeReturnPc :: sel :: []) mem (UInt256.ofNat 7) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨7847⟩) (okPc := ⟨7863⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨7847⟩) (okPc := ⟨7863⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -2757,7 +2757,7 @@ theorem endFreeX_urnsReturnDecodeShort {cA gh bl σ σ₀ A I} {g : Sat256} rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rdShort have rdFall := rdShort.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFall + exact RD.solcPush1Dup1Revert0 rdFall (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -3107,10 +3107,10 @@ theorem endFreeX_grabNoCode {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} (⟨0⟩ :: endFreeUrnInkWord out :: endFreeIlkWord I :: endFreeReturnPc :: sel :: []) (endFreeUrnsPostCallMem I out) (UInt256.ofNat 7) out (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endPackVatWord σ' I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd8143⟩ := endFreeX_grabExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨8143⟩) (okPc := ⟨8155⟩) rd8143 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨8143⟩) (okPc := ⟨8155⟩) rd8143 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3122,7 +3122,7 @@ theorem endFreeX_grabCallReady {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} (⟨0⟩ :: endFreeUrnInkWord out :: endFreeIlkWord I :: endFreeReturnPc :: sel :: []) (endFreeUrnsPostCallMem I out) (UInt256.ofNat 7) out (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endPackVatWord σ' I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨8158⟩ (gasWord :: endPackVatWord σ' I :: ⟨0⟩ :: endFreeGrabOutPtr :: endFreeGrabInSize :: endFreeGrabOutPtr :: endFreeGrabOutSize :: @@ -3132,7 +3132,7 @@ theorem endFreeX_grabCallReady {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} (endFreeGrabCalldataMem σ' I out) (UInt256.ofNat 11) out (cA', σ') k' C' := by obtain ⟨_, _, rd8143⟩ := endFreeX_grabExtcodesizeGuard h obtain ⟨gasWord, k', C', rd8158⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨8143⟩) (okPc := ⟨8155⟩) rd8143 + RD.solcExtcodesizeGuardOkGas (pc := ⟨8143⟩) (okPc := ⟨8155⟩) rd8143 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -3223,7 +3223,7 @@ theorem endFreeX_grabCallFailed {cA cA' gh bl σ σpre σpost σ₀ A I} {g : Sa mem (UInt256.ofNat 11) rdata (cA', σpost) k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨8159⟩) (okPc := ⟨8175⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨8159⟩) (okPc := ⟨8175⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3240,7 +3240,7 @@ theorem endFreeX_grabCallSucceeded {cA cA' gh bl σ σpre σpost σ₀ A I} {g : (endFreeGrabEndPtr :: endFreeGrabSelectorWord :: endPackVatWord σpre I :: ⟨0⟩ :: endFreeUrnInkWord out :: endFreeIlkWord I :: endFreeReturnPc :: sel :: []) mem (UInt256.ofNat 11) rdata (cA', σpost) k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨8159⟩) (okPc := ⟨8175⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨8159⟩) (okPc := ⟨8175⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -3635,10 +3635,10 @@ theorem endFreeBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rw [Nat.mod_eq_of_lt] exact a.isLt by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (endPackVatWord σ_evm I) = + Reasoning.Theory.extCodeSizeWord σ_evm (endPackVatWord σ_evm I) = ⟨0⟩ · have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endPackVatWord σ_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv hAccounts hvatCode have hbody : @@ -3651,10 +3651,10 @@ theorem endFreeBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endFreeX_urnsNoCode (g := Sat256.ofUInt256 g) hlivePc hvatCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (endPackVatWord σ_evm I) ≠ ⟨0⟩ := hvatCode have hvatCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endPackVatWord σ_solm I) ≠ ⟨0⟩ := endPackVatCodeSize_ne_accountMapEquiv hAccounts hvatCodeNE obtain ⟨gasWord, _, _, hcallReady⟩ := @@ -3810,10 +3810,10 @@ theorem endFreeBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} · have hinkOk : (endFreeUrnInkWord out).toNat ≤ 2 ^ 255 := by omega obtain ⟨_, _, rd8041⟩ := endFreeX_inkInRange hinkOk rd7969 by_cases hgrabCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) = ⟨0⟩ · have hgrabCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmUrnsSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmUrnsSolm.accountMap (endPackVatWord evmUrnsSolm.accountMap I) = ⟨0⟩ := by simpa [evmUrnsEvm, evmUrnsSolm] using endPackVatCodeSize_zero_accountMapEquiv hStateCall.accountMap @@ -3832,10 +3832,10 @@ theorem endFreeBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endFreeX_grabNoCode rd8041 hgrabCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hgrabCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) ≠ ⟨0⟩ := hgrabCode have hgrabCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmUrnsSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmUrnsSolm.accountMap (endPackVatWord evmUrnsSolm.accountMap I) ≠ ⟨0⟩ := by simpa [evmUrnsEvm, evmUrnsSolm] using endPackVatCodeSize_ne_accountMapEquiv hStateCall.accountMap diff --git a/Benchmarks/Dss/End/Pack.lean b/Benchmarks/Dss/End/Pack.lean index ae8cf112..ca982244 100644 --- a/Benchmarks/Dss/End/Pack.lean +++ b/Benchmarks/Dss/End/Pack.lean @@ -742,7 +742,7 @@ theorem endPackX_mulOverflow {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256 (endPackWadWord I) = ⟨0⟩ := by exact u256_eq_of_ne hdivNe have rdFallthrough := rd10201.jumpiNT (by native_decide) heqCond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -964,10 +964,10 @@ theorem endPackX_moveNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel amt : UInt endPackVatWord σ I, endPackWadWord I, endPackReturnPc, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd6536⟩ := endPackX_moveExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨6536⟩) (okPc := ⟨6548⟩) rd6536 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨6536⟩) (okPc := ⟨6548⟩) rd6536 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -980,7 +980,7 @@ theorem endPackX_moveCallReady {cA gh bl σ σ₀ A I} {g : Sat256} {sel amt : U endPackVatWord σ I, endPackWadWord I, endPackReturnPc, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨6551⟩ (gasWord :: endPackVatWord σ I :: ⟨0⟩ :: endPackMoveOutPtr :: endPackMoveInSize :: endPackMoveOutPtr :: ⟨0⟩ :: endPackMoveEndPtr :: @@ -990,7 +990,7 @@ theorem endPackX_moveCallReady {cA gh bl σ σ₀ A I} {g : Sat256} {sel amt : U ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd6536⟩ := endPackX_moveExtcodesizeGuard h obtain ⟨gasWord, k', C', rd6551⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨6536⟩) (okPc := ⟨6548⟩) rd6536 + RD.solcExtcodesizeGuardOkGas (pc := ⟨6536⟩) (okPc := ⟨6548⟩) rd6536 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1080,7 +1080,7 @@ theorem endPackX_moveCallFailed {cA cA' gh bl σ σ' σ₀ A I} {g sel : UInt256 (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨6552⟩) (okPc := ⟨6568⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨6552⟩) (okPc := ⟨6568⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1100,7 +1100,7 @@ theorem endPackX_moveCallSucceeded {cA gh bl σ σ₀ A I} {g sel : UInt256} (endPackMoveEndPtr :: endPackMoveSelectorWord :: endPackVatWord σ I :: endPackWadWord I :: endPackReturnPc :: sel :: []) mem (UInt256.ofNat 8) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨6552⟩) (okPc := ⟨6568⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨6552⟩) (okPc := ⟨6568⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1212,7 +1212,7 @@ theorem endPackX_bagAddOverflow {cA cA' gh bl σ σ' σ₀ A I} {g sel : UInt256 have rd10104pre := evm_run rd10100 with [raw push2 ⟨10108⟩ (by native_decide) (by evm_ov)] have rd10104 := rd10104pre.jumpiNT (by native_decide) (by decide) (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rd10104 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd10104 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1731,12 +1731,12 @@ theorem endPackVatWord_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} theorem endPackVatCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endPackVatWord τ I) ≠ ⟨0⟩ := by + (hne : Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endPackVatWord τ I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endPackVatWord σ I) have htarget : endPackVatWord σ I = endPackVatWord τ I := endPackVatWord_accountMapEquiv hAccounts @@ -1745,10 +1745,10 @@ theorem endPackVatCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : Executio theorem endPackVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endPackVatWord τ I) = ⟨0⟩ := by + (hzero : Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endPackVatWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endPackVatWord σ I) have htarget : endPackVatWord σ I = endPackVatWord τ I := endPackVatWord_accountMapEquiv hAccounts @@ -1761,7 +1761,7 @@ theorem endPackVatAddr_eq_ofUInt256 (σ : AccountMap) (I : ExecutionEnv) : (accountAddress_ofUInt256_eq_ofNat_toNat (endPackVatWord σ I)).symm theorem endPackVatCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt256} - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (endPackVatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by @@ -1771,7 +1771,7 @@ theorem endPackVatCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt25 (endPackVatAddr_eq_ofUInt256 σ I) hzero theorem endPackVatCode_pos_of_codeSize_ne {cA gh bl σ σ₀ A I} {g : UInt256} - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (endPackVatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat := by @@ -1882,7 +1882,7 @@ theorem endPackBodyReverts_moveNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hdebt : endPackDebtWord σ I ≠ ⟨0⟩) (hfit : (endPackWadWord I).toNat * endPackRayWord.toNat < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecTransitionBody config contract evm0 (endPackStore I) packTransition.body .reverted := by intro evm0 @@ -1999,7 +1999,7 @@ theorem endPackBodyReverts_moveCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} (hdebt : endPackDebtWord σ I ≠ ⟨0⟩) (hfit : (endPackWadWord I).toNat * endPackRayWord.toNat < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "move" 0 @@ -2149,7 +2149,7 @@ theorem endPackPrefixMoveSuccess {cA gh bl σ σ₀ A I} {g : UInt256} (hdebt : endPackDebtWord σ I ≠ ⟨0⟩) (hfit : (endPackWadWord I).toNat * endPackRayWord.toNat < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "move" 0 @@ -2300,7 +2300,7 @@ theorem endPackBodyReverts_bagAddOverflow {cA gh bl σ σ₀ A I} {g : UInt256} (hdebt : endPackDebtWord σ I ≠ ⟨0⟩) (hfit : (endPackWadWord I).toNat * endPackRayWord.toNat < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "move" 0 @@ -2347,7 +2347,7 @@ theorem endPackBodyReturns {cA gh bl σ σ₀ A I} {g : UInt256} (hdebt : endPackDebtWord σ I ≠ ⟨0⟩) (hfit : (endPackWadWord I).toNat * endPackRayWord.toNat < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "move" 0 @@ -2573,10 +2573,10 @@ theorem endPackBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} obtain ⟨_, _, hmoveStart⟩ := endPackX_mulReturns (g := Sat256.ofUInt256 g) hfit hmulEntry by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (endPackVatWord σ_evm I) = + Reasoning.Theory.extCodeSizeWord σ_evm (endPackVatWord σ_evm I) = ⟨0⟩ · have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endPackVatWord σ_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv hAccounts hvatCode have hbody : @@ -2589,10 +2589,10 @@ theorem endPackBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endPackX_moveNoCode (g := Sat256.ofUInt256 g) hmoveStart hvatCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (endPackVatWord σ_evm I) ≠ ⟨0⟩ := hvatCode have hvatCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endPackVatWord σ_solm I) ≠ ⟨0⟩ := endPackVatCodeSize_ne_accountMapEquiv hAccounts hvatCodeNE obtain ⟨gasWord, _, _, hcallReady⟩ := diff --git a/Benchmarks/Dss/End/PackBody.lean b/Benchmarks/Dss/End/PackBody.lean index 29b0bc88..f07ada33 100644 --- a/Benchmarks/Dss/End/PackBody.lean +++ b/Benchmarks/Dss/End/PackBody.lean @@ -100,7 +100,7 @@ theorem RD.endPackBagAddOverflow raw iszero (by native_decide) (by evm_ov), raw push2 ⟨10108⟩ (by native_decide) (by evm_ov)] have rd10104 := rd10103pre.jumpiNT (by native_decide) rfl (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd10104 + exact RD.solcPush1Dup1Revert0 rd10104 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -189,7 +189,7 @@ theorem RD.endPackMovePostCall packMoveSelectorWord :: packVatMaskedWord σ I :: packWadWord I :: ⟨562⟩ :: [sel]) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (packVatMaskedWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (packVatMaskedWord σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (out : ByteArray) (A' : Substate) (k' C' : ℕ), @@ -233,7 +233,7 @@ theorem RD.endPackMoveDepthLimitReverts packMoveSelectorWord :: packVatMaskedWord σ I :: packWadWord I :: ⟨562⟩ :: [sel]) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (packVatMaskedWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (packVatMaskedWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : RDrev endBytecode g s0 := by obtain ⟨_, _, _, rd6551⟩ := RD.endPackMoveCall rd hcodeSize @@ -881,7 +881,7 @@ theorem endPackBodyCore : endBodyObligation 30 := by endPackX_mulOk (g := Sat256.ofUInt256 g) hmulOk hmulRD obtain ⟨kAfterMul, CAfterMul, hafterMulRD⟩ := hafterMul by_cases hvatNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (packVatMaskedWord σ_evm I) = ⟨0⟩ · have hrev := RD.endPackMoveNoCode (g := Sat256.ofUInt256 g) hafterMulRD hvatNoCode @@ -896,10 +896,10 @@ theorem endPackBodyCore : endBodyObligation 30 := by simpa [packVatMaskedWord] using congrArg (fun w => UInt256.land solcAddrMask w) hword have hvatNoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (packVatMaskedWord σ_solm I) = ⟨0⟩ := by rw [← hvatWord] - rw [← uniswapExtCodeSizeWord_accountMapEquiv hAccounts + rw [← extCodeSizeWord_accountMapEquiv hAccounts (packVatMaskedWord σ_evm I)] exact hvatNoCode have hbody : @@ -927,12 +927,12 @@ theorem endPackBodyCore : endBodyObligation 30 := by simpa [packVowMaskedWord] using congrArg (fun w => UInt256.land solcAddrMask w) hword have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (packVatMaskedWord σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatNoCode rw [← hvatWord] at hzero - rw [← uniswapExtCodeSizeWord_accountMapEquiv hAccounts + rw [← extCodeSizeWord_accountMapEquiv hAccounts (packVatMaskedWord σ_evm I)] at hzero exact hzero have hvatCodeNatSolm : @@ -942,7 +942,7 @@ theorem endPackBodyCore : endBodyObligation 30 := by (fun acc => acc.code.size))).toNat ≠ 0 := by intro hnat apply hvatCodeSolm - simp [Reasoning.Theory.uniswapExtCodeSizeWord, initState, State.lookupAccount, + simp [Reasoning.Theory.extCodeSizeWord, initState, State.lookupAccount, accountAddress_ofUInt256_eq_ofNat_toNat] at hnat ⊢ cases hfind : σ_solm.find? (AccountAddress.ofNat (packVatMaskedWord σ_solm I).toNat) · native_decide diff --git a/Benchmarks/Dss/End/Skim.lean b/Benchmarks/Dss/End/Skim.lean index 875e05de..af243078 100644 --- a/Benchmarks/Dss/End/Skim.lean +++ b/Benchmarks/Dss/End/Skim.lean @@ -1273,10 +1273,10 @@ theorem endSkimX_vatIlksNoCode {cA gh bl σ σ₀ A I} {g : Sat256} [endSkimUrnKey I, endSkimIlkWord I, endSkimReturnPc, sel] (endSkimVatIlksBaseMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd6860⟩ := endSkimX_vatIlksExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨6860⟩) (okPc := ⟨6872⟩) rd6860 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨6860⟩) (okPc := ⟨6872⟩) rd6860 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1288,7 +1288,7 @@ theorem endSkimX_vatIlksCallReady {cA gh bl σ σ₀ A I} {g : Sat256} [endSkimUrnKey I, endSkimIlkWord I, endSkimReturnPc, sel] (endSkimVatIlksBaseMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨6875⟩ (gasWord :: endPackVatWord σ I :: ⟨0⟩ :: endFlowVatIlksOutPtr :: endFlowVatIlksInSize :: endFlowVatIlksOutPtr :: endFlowVatIlksOutSize :: @@ -1298,7 +1298,7 @@ theorem endSkimX_vatIlksCallReady {cA gh bl σ σ₀ A I} {g : Sat256} ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd6860⟩ := endSkimX_vatIlksExtcodesizeGuard h obtain ⟨gasWord, k', C', rd6875⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨6860⟩) (okPc := ⟨6872⟩) rd6860 + RD.solcExtcodesizeGuardOkGas (pc := ⟨6860⟩) (okPc := ⟨6872⟩) rd6860 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1386,7 +1386,7 @@ theorem endSkimX_vatIlksCallFailed {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} mem (UInt256.ofNat 9) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨6876⟩) (okPc := ⟨6892⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨6876⟩) (okPc := ⟨6892⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1404,7 +1404,7 @@ theorem endSkimX_vatIlksCallSucceeded {cA cA' gh bl σ σ' σ₀ A I} {g : Sat25 (endFlowVatIlksEndPtr :: endFlowVatIlksSelectorWord :: endPackVatWord σ I :: ⟨0⟩ :: endSkimUrnKey I :: endSkimIlkWord I :: endSkimReturnPc :: sel :: []) mem (UInt256.ofNat 9) rdata (cA', σ') k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨6876⟩) (okPc := ⟨6892⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨6876⟩) (okPc := ⟨6892⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1485,7 +1485,7 @@ theorem endSkimX_vatIlksReturnDecodeShort {cA cA' gh bl σ σ' σ₀ A I} {g : S rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rdShort have rdFall := rdShort.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFall + exact RD.solcPush1Dup1Revert0 rdFall (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1645,10 +1645,10 @@ theorem endSkimX_urnsNoCode {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} (endSkimVatIlksPostCallMem I vatOut) (UInt256.ofNat 9) vatOut (cA', σ') k C) (hloVat : 160 ≤ vatOut.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endPackVatWord σ' I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd6996⟩ := endSkimX_urnsExtcodesizeGuard h hloVat - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨6996⟩) (okPc := ⟨7008⟩) rd6996 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨6996⟩) (okPc := ⟨7008⟩) rd6996 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1662,7 +1662,7 @@ theorem endSkimX_urnsCallReady {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} (endSkimVatIlksPostCallMem I vatOut) (UInt256.ofNat 9) vatOut (cA', σ') k C) (hloVat : 160 ≤ vatOut.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endPackVatWord σ' I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨7011⟩ (gasWord :: endPackVatWord σ' I :: ⟨0⟩ :: endFreeUrnsOutPtr :: endFreeUrnsInSize :: endFreeUrnsOutPtr :: endFreeUrnsOutSize :: @@ -1672,7 +1672,7 @@ theorem endSkimX_urnsCallReady {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} (endSkimUrnsCalldataMem I vatOut) (UInt256.ofNat 9) vatOut (cA', σ') k' C' := by obtain ⟨_, _, rd6996⟩ := endSkimX_urnsExtcodesizeGuard h hloVat obtain ⟨gasWord, k', C', rd7011⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨6996⟩) (okPc := ⟨7008⟩) rd6996 + RD.solcExtcodesizeGuardOkGas (pc := ⟨6996⟩) (okPc := ⟨7008⟩) rd6996 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1761,7 +1761,7 @@ theorem endSkimX_urnsCallFailed {cA cA' gh bl σ σcur σ' σ₀ A I} {g : Sat25 mem (UInt256.ofNat 9) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨7012⟩) (okPc := ⟨7028⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨7012⟩) (okPc := ⟨7028⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1780,7 +1780,7 @@ theorem endSkimX_urnsCallSucceeded {cA cA' gh bl σ σcur σ' σ₀ A I} {g : Sa ⟨0⟩ :: ⟨0⟩ :: endFlowVatIlkRateWord vatOut :: endSkimUrnKey I :: endSkimIlkWord I :: endSkimReturnPc :: sel :: []) mem (UInt256.ofNat 9) rdata (cA', σ') k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨7012⟩) (okPc := ⟨7028⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨7012⟩) (okPc := ⟨7028⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1876,7 +1876,7 @@ theorem endSkimX_urnsReturnDecodeShort {cA cA' gh bl σ σcur σ' σ₀ A I} {g rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rdShort have rdFall := rdShort.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFall + exact RD.solcPush1Dup1Revert0 rdFall (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -2321,7 +2321,7 @@ theorem endSkimX_gapAddOverflow {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} have rd10104pre := evm_run rd10100 with [raw push2 ⟨10108⟩ (by native_decide) (by evm_ov)] have rd10104 := rd10104pre.jumpiNT (by native_decide) (by decide) (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rd10104 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd10104 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -3988,7 +3988,7 @@ theorem endSkimX_grabExtcodesizeGuard {cA cA' gh bl σ σCall σLoc σ₀ A I} rw [haddrMask, hurnMaskLeft] rfl) (by decide) (by evm_ov), - raw uniswapAddress (by native_decide) (by evm_ov), + raw address (by native_decide) (by evm_ov), raw push1 ⟨68⟩ (by native_decide) (by evm_ov), raw dup6 (by native_decide) (by evm_ov), raw add (by native_decide) (by evm_ov), @@ -4093,10 +4093,10 @@ theorem endSkimX_grabNoCode {cA cA' gh bl σ σCall σLoc σ₀ A I} (endSkimGapStoreHashMem I vatOut urnOut) (UInt256.ofNat 9) rdata (cA', σCall) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd7357⟩ := endSkimX_grabExtcodesizeGuard hloVat h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨7357⟩) (okPc := ⟨7369⟩) rd7357 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨7357⟩) (okPc := ⟨7369⟩) rd7357 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -4113,7 +4113,7 @@ theorem endSkimX_grabCallReady {cA cA' gh bl σ σCall σLoc σ₀ A I} (endSkimGapStoreHashMem I vatOut urnOut) (UInt256.ofNat 9) rdata (cA', σCall) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨7372⟩ (gasWord :: endPackVatWord σCall I :: ⟨0⟩ :: endFreeGrabOutPtr :: endFreeGrabInSize :: endFreeGrabOutPtr :: endFreeGrabOutSize :: @@ -4126,7 +4126,7 @@ theorem endSkimX_grabCallReady {cA cA' gh bl σ σCall σLoc σ₀ A I} rdata (cA', σCall) k' C' := by obtain ⟨_, _, rd7357⟩ := endSkimX_grabExtcodesizeGuard hloVat h obtain ⟨gasWord, k', C', rd7372⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨7357⟩) (okPc := ⟨7369⟩) rd7357 + RD.solcExtcodesizeGuardOkGas (pc := ⟨7357⟩) (okPc := ⟨7369⟩) rd7357 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -4234,7 +4234,7 @@ theorem endSkimX_grabCallFailed {cA cA' gh bl σ σpre σpost σ₀ A I} mem (UInt256.ofNat 11) rdata (cA', σpost) k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨7373⟩) (okPc := ⟨7389⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨7373⟩) (okPc := ⟨7389⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -4258,7 +4258,7 @@ theorem endSkimX_grabCallSucceeded {cA cA' gh bl σ σpre σpost σ₀ A I} endFlowVatIlkRateWord vatOut :: endSkimUrnKey I :: endSkimIlkWord I :: endSkimReturnPc :: sel :: []) mem (UInt256.ofNat 11) rdata (cA', σpost) k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨7373⟩) (okPc := ⟨7389⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨7373⟩) (okPc := ⟨7389⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -4516,7 +4516,7 @@ theorem evalExpr_endSkim_tag_ne_true (evm : EVM.State) (I : ExecutionEnv) theorem endSkimCheckedVatIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecBlock config { contract := contract, locals := endSkimStore I } evm0 (checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] @@ -4552,7 +4552,7 @@ theorem endSkimCheckedVatIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} theorem endSkimCheckedVatIlksFailure {cA gh bl σ σ₀ A I} {g : UInt256} {evmVat : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -4606,7 +4606,7 @@ theorem endSkimCheckedVatIlksFailure {cA gh bl σ σ₀ A I} {g : UInt256} theorem endSkimCheckedVatIlksDecodeRevert {cA gh bl σ σ₀ A I} {g : UInt256} {evmVat : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -4662,7 +4662,7 @@ theorem endSkimCheckedVatIlksDecodeRevert {cA gh bl σ σ₀ A I} {g : UInt256} theorem endSkimCheckedVatIlksSuccess {cA gh bl σ σ₀ A I} {g : UInt256} {evmVat : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -4795,7 +4795,7 @@ theorem endSkimVatReceiver_afterRate {σ I vatOut evm} theorem endSkimVatCode_zero_afterRate {σ I} {vatOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (endPackVatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by @@ -4806,7 +4806,7 @@ theorem endSkimVatCode_zero_afterRate {σ I} {vatOut : ByteArray} {evm : EVM.Sta theorem endSkimVatCode_pos_afterRate {σ I} {vatOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (endPackVatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [State.lookupAccount, hmap] using @@ -4817,7 +4817,7 @@ theorem endSkimVatCode_pos_afterRate {σ I} {vatOut : ByteArray} {evm : EVM.Stat theorem endSkimCheckedUrnsNoCode {σ I} {vatOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSkimStoreRate I vatOut } evm (checkedExternalCallStmts (.storage vatRef) "urns" (.intLit 0) [.var "ilk", .var "urn"] "vatUrn") .reverted := by @@ -4840,7 +4840,7 @@ theorem endSkimCheckedUrnsFailure {σ I} {vatOut urnOut : ByteArray} {evm evmUrns : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "urns" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I), .address (endSkimUrnAddr I)] @@ -4871,7 +4871,7 @@ theorem endSkimCheckedUrnsDecodeRevert {σ I} {vatOut urnOut : ByteArray} {evm evmUrns : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "urns" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I), .address (endSkimUrnAddr I)] @@ -4904,7 +4904,7 @@ theorem endSkimCheckedUrnsSuccess {σ I} {vatOut urnOut : ByteArray} {evm evmUrns : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "urns" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I), .address (endSkimUrnAddr I)] @@ -5924,7 +5924,7 @@ theorem endSkimGrabTailReverts_noCode {σ I} {vatOut urnOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSkimStoreGapNew σ I vatOut urnOut } evm (checkedExternalCallStmts (.storage vatRef) "grab" (.intLit 0) @@ -5958,7 +5958,7 @@ theorem endSkimGrabTailReverts_callFailed {σ I} {vatOut urnOut grabOut : ByteAr {evm evmGrab : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "grab" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I), @@ -6023,7 +6023,7 @@ theorem endSkimGrabTailReturns_success {σ I} {vatOut urnOut grabOut : ByteArray {evm evmGrab : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "grab" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I), @@ -6105,7 +6105,7 @@ theorem endSkimGrabTailReverts_noCodeFor {σCall σLoc I} {vatOut urnOut : ByteA {evm : EVM.State} (hmap : evm.accountMap = σCall) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSkimStoreGapNew σLoc I vatOut urnOut } evm (checkedExternalCallStmts (.storage vatRef) "grab" (.intLit 0) @@ -6139,7 +6139,7 @@ theorem endSkimGrabTailReverts_callFailedFor {σCall σLoc I} {vatOut urnOut grabOut : ByteArray} {evm evmGrab : EVM.State} (hmap : evm.accountMap = σCall) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σCall I)) "grab" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I), @@ -6204,7 +6204,7 @@ theorem endSkimGrabTailReturns_successFor {σCall σLoc I} {vatOut urnOut grabOut : ByteArray} {evm evmGrab : EVM.State} (hmap : evm.accountMap = σCall) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σCall I)) "grab" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I), @@ -6773,7 +6773,7 @@ theorem endSkimBodyReverts_vatIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (htag : endSkimTagWord σ I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecTransitionBody config contract evm0 (endSkimStore I) skimTransition.body .reverted := by intro evm0 @@ -6791,7 +6791,7 @@ theorem endSkimBodyReverts_vatIlksCallFailed {cA gh bl σ σ₀ A I} {g : UInt25 (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (htag : endSkimTagWord σ I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -6815,7 +6815,7 @@ theorem endSkimBodyReverts_vatIlksDecodeShort {cA gh bl σ σ₀ A I} {g : UInt2 (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (htag : endSkimTagWord σ I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -6840,7 +6840,7 @@ theorem endSkimPrefixRateSuccess {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (htag : endSkimTagWord σ I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 @@ -7069,9 +7069,9 @@ theorem endSkimBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (cA, σ_evm) kTag CTag := by simpa [endSkimVatIlksBaseMem] using htagPcRaw by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (endPackVatWord σ_evm I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_evm (endPackVatWord σ_evm I) = ⟨0⟩ · have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (endPackVatWord σ_solm I) = + Reasoning.Theory.extCodeSizeWord σ_solm (endPackVatWord σ_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv hAccounts hvatCode have hbody : @@ -7084,10 +7084,10 @@ theorem endSkimBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endSkimX_vatIlksNoCode (g := Sat256.ofUInt256 g) htagPc hvatCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (endPackVatWord σ_evm I) ≠ + Reasoning.Theory.extCodeSizeWord σ_evm (endPackVatWord σ_evm I) ≠ ⟨0⟩ := hvatCode have hvatCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (endPackVatWord σ_solm I) ≠ + Reasoning.Theory.extCodeSizeWord σ_solm (endPackVatWord σ_solm I) ≠ ⟨0⟩ := endPackVatCodeSize_ne_accountMapEquiv hAccounts hvatCodeNE obtain ⟨gasWord, _, _, hcallReady⟩ := @@ -7223,10 +7223,10 @@ theorem endSkimBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simpa [evmVatSolm, evmSolm] using hcallSolm) hloVat by_cases hurnsCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat + Reasoning.Theory.extCodeSizeWord σ_vat (endPackVatWord σ_vat I) = ⟨0⟩ · have hurnsCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat_solm + Reasoning.Theory.extCodeSizeWord σ_vat_solm (endPackVatWord σ_vat_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv hAccountsVat hurnsCode have hurnsBlock : @@ -7247,10 +7247,10 @@ theorem endSkimBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endSkimX_urnsNoCode rd6920 hloVat hurnsCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hurnsCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat + Reasoning.Theory.extCodeSizeWord σ_vat (endPackVatWord σ_vat I) ≠ ⟨0⟩ := hurnsCode have hurnsCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat_solm + Reasoning.Theory.extCodeSizeWord σ_vat_solm (endPackVatWord σ_vat_solm I) ≠ ⟨0⟩ := endPackVatCodeSize_ne_accountMapEquiv hAccountsVat hurnsCodeNE obtain ⟨gasWordUrns, _, _, hurnsReady⟩ := @@ -7722,10 +7722,10 @@ theorem endSkimBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} storageStore_executionEnv, evmUrnsSolm, evmVatSolm, evmSolm, initState] by_cases hgrabCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_post + Reasoning.Theory.extCodeSizeWord σ_post (endPackVatWord σ_post I) = ⟨0⟩ · have hgrabCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_post_solm + Reasoning.Theory.extCodeSizeWord σ_post_solm (endPackVatWord σ_post_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv hAccountsPost hgrabCode @@ -7746,10 +7746,10 @@ theorem endSkimBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (σLoc := σ_urns) hloVat rd7253 hgrabCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hgrabCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_post + Reasoning.Theory.extCodeSizeWord σ_post (endPackVatWord σ_post I) ≠ ⟨0⟩ := hgrabCode have hgrabCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_post_solm + Reasoning.Theory.extCodeSizeWord σ_post_solm (endPackVatWord σ_post_solm I) ≠ ⟨0⟩ := endPackVatCodeSize_ne_accountMapEquiv hAccountsPost hgrabCodeNE diff --git a/Benchmarks/Dss/End/Skip.lean b/Benchmarks/Dss/End/Skip.lean index 33bc58b7..e99ff515 100644 --- a/Benchmarks/Dss/End/Skip.lean +++ b/Benchmarks/Dss/End/Skip.lean @@ -3582,10 +3582,10 @@ theorem endSkipX_catIlksNoCode {cA gh bl σ σ₀ A I} {g : Sat256} [endSkipIdWord I, endSkipIlkWord I, endSkipReturnPc, sel] (endSkipCatIlksBaseMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd3379⟩ := endSkipX_catIlksExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3379⟩) (okPc := ⟨3391⟩) rd3379 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3379⟩) (okPc := ⟨3391⟩) rd3379 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3597,7 +3597,7 @@ theorem endSkipX_catIlksCallReady {cA gh bl σ σ₀ A I} {g : Sat256} [endSkipIdWord I, endSkipIlkWord I, endSkipReturnPc, sel] (endSkipCatIlksBaseMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3394⟩ (gasWord :: endSkipCatWord σ I :: ⟨0⟩ :: endFlowVatIlksOutPtr :: endFlowVatIlksInSize :: endFlowVatIlksOutPtr :: endSkipCatIlksOutSize :: @@ -3607,7 +3607,7 @@ theorem endSkipX_catIlksCallReady {cA gh bl σ σ₀ A I} {g : Sat256} ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd3379⟩ := endSkipX_catIlksExtcodesizeGuard h obtain ⟨gasWord, k', C', rd3394⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3379⟩) (okPc := ⟨3391⟩) rd3379 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3379⟩) (okPc := ⟨3391⟩) rd3379 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -3695,7 +3695,7 @@ theorem endSkipX_catIlksCallFailed {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} mem (UInt256.ofNat 7) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3395⟩) (okPc := ⟨3411⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨3395⟩) (okPc := ⟨3411⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3713,7 +3713,7 @@ theorem endSkipX_catIlksCallSucceeded {cA cA' gh bl σ σ' σ₀ A I} {g : Sat25 (⟨0⟩ :: endSkipIdWord I :: endSkipIlkWord I :: endSkipReturnPc :: sel :: []) mem (UInt256.ofNat 7) rdata (cA', σ') k' C' := by obtain ⟨_, _, rd3413⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨3395⟩) (okPc := ⟨3411⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨3395⟩) (okPc := ⟨3411⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -3787,7 +3787,7 @@ theorem endSkipX_catIlksReturnDecodeShort {cA cA' gh bl σ σ' σ₀ A I} rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rdShort have rdFall := rdShort.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFall + exact RD.solcPush1Dup1Revert0 rdFall (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -3930,10 +3930,10 @@ theorem endSkipX_vatIlksNoCode {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} (cA', σ') k C) (hloCat : 96 ≤ catOut.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endPackVatWord σ' I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd3505⟩ := endSkipX_vatIlksExtcodesizeGuard hloCat h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3505⟩) (okPc := ⟨3517⟩) rd3505 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3505⟩) (okPc := ⟨3517⟩) rd3505 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3948,7 +3948,7 @@ theorem endSkipX_vatIlksCallReady {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} (cA', σ') k C) (hloCat : 96 ≤ catOut.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endPackVatWord σ' I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3520⟩ (gasWord :: endPackVatWord σ' I :: ⟨0⟩ :: endFlowVatIlksOutPtr :: endFlowVatIlksInSize :: endFlowVatIlksOutPtr :: endFlowVatIlksOutSize :: @@ -3959,7 +3959,7 @@ theorem endSkipX_vatIlksCallReady {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} catOut (cA', σ') k' C' := by obtain ⟨_, _, rd3505⟩ := endSkipX_vatIlksExtcodesizeGuard hloCat h obtain ⟨gasWord, k', C', rd3520⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3505⟩) (okPc := ⟨3517⟩) rd3505 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3505⟩) (okPc := ⟨3517⟩) rd3505 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -4054,7 +4054,7 @@ theorem endSkipX_vatIlksCallFailed {cA cA' gh bl σ σcur σ' σ₀ A I} mem (UInt256.ofNat 9) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3521⟩) (okPc := ⟨3537⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨3521⟩) (okPc := ⟨3537⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -4075,7 +4075,7 @@ theorem endSkipX_vatIlksCallSucceeded {cA cA' gh bl σ σcur σ' σ₀ A I} ⟨0⟩ :: endSkipCatIlkFlipWord catOut :: endSkipCatIlkFlipWord catOut :: endSkipIdWord I :: endSkipIlkWord I :: endSkipReturnPc :: sel :: []) mem (UInt256.ofNat 9) rdata (cA', σ') k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨3521⟩) (okPc := ⟨3537⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨3521⟩) (okPc := ⟨3537⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -4166,7 +4166,7 @@ theorem endSkipX_vatIlksReturnDecodeShort {cA cA' gh bl σ σcur σ' σ₀ A I} rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rdShort have rdFall := rdShort.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFall + exact RD.solcPush1Dup1Revert0 rdFall (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -4295,11 +4295,11 @@ theorem endSkipX_bidsNoCode {cA cA' gh bl σ σ' σ₀ A I} (cA', σ') k C) (hloCat : 96 ≤ catOut.size) (hloVat : 160 ≤ vatOut.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (endSkipCatIlkFlipTargetWord catOut) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd3637⟩ := endSkipX_bidsExtcodesizeGuard hloCat hloVat h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3637⟩) (okPc := ⟨3649⟩) rd3637 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3637⟩) (okPc := ⟨3649⟩) rd3637 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -4315,7 +4315,7 @@ theorem endSkipX_bidsCallReady {cA cA' gh bl σ σ' σ₀ A I} (cA', σ') k C) (hloCat : 96 ≤ catOut.size) (hloVat : 160 ≤ vatOut.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3652⟩ (gasWord :: endSkipCatIlkFlipTargetWord catOut :: endFlowVatIlksOutPtr :: @@ -4329,7 +4329,7 @@ theorem endSkipX_bidsCallReady {cA cA' gh bl σ σ' σ₀ A I} vatOut (cA', σ') k' C' := by obtain ⟨_, _, rd3637⟩ := endSkipX_bidsExtcodesizeGuard hloCat hloVat h obtain ⟨gasWord, k', C', rd3652⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3637⟩) (okPc := ⟨3649⟩) rd3637 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3637⟩) (okPc := ⟨3649⟩) rd3637 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -4373,7 +4373,7 @@ theorem endSkipX_bidsPostStaticcall {cA cAcur gh bl σ σcur σ₀ A I} bidOut (cA', σ') k' C' ∧ bidOut.size < UInt256.size := by obtain ⟨cA', σ', z, bidOut, Ain, callGas, k', C', hΘ, rd3653raw, hout⟩ := - RD.uniswapStaticcall h (by native_decide) hdepth + RD.solcStaticcall h (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨cA', σ', z, bidOut, Ain, callGas, k', C', ?_, ?_, hout⟩ · simpa [initState] using hΘ @@ -4409,7 +4409,7 @@ theorem endSkipX_bidsStaticcallDepthLimit {cA cAcur gh bl σ σcur σ₀ A I} (endSkipBidsCalldataMem I catOut vatOut) (UInt256.ofNat 12) ByteArray.empty (cAcur, σcur) k' C' := by obtain ⟨k', C', rd3653raw⟩ := - RD.uniswapStaticcallDepthLimit h (by native_decide) hdepth + RD.solcStaticcallDepthLimit h (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨k', C', ?_⟩ have hmin : (min endSkipBidsOutSize (UInt256.ofNat ByteArray.empty.size)).toNat = 0 := by @@ -4435,7 +4435,7 @@ theorem endSkipX_bidsCallFailed {cA cA' gh bl σ σ' σ₀ A I} mem (UInt256.ofNat 12) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3653⟩) (okPc := ⟨3669⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨3653⟩) (okPc := ⟨3669⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -4458,7 +4458,7 @@ theorem endSkipX_bidsCallSucceeded {cA cA' gh bl σ σ' σ₀ A I} endSkipIdWord I :: endSkipIlkWord I :: endSkipReturnPc :: sel :: []) mem (UInt256.ofNat 12) rdata (cA', σ') k' C' := by obtain ⟨_, _, rd3671⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨3653⟩) (okPc := ⟨3669⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨3653⟩) (okPc := ⟨3669⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -4570,7 +4570,7 @@ theorem endSkipX_bidsReturnDecodeShort {cA cA' gh bl σ σ' σ₀ A I} rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rdShort have rdFall := rdShort.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFall + exact RD.solcPush1Dup1Revert0 rdFall (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -4791,10 +4791,10 @@ theorem endSkipX_suck1NoCode {cA cA' gh bl σ σ' σ₀ A I} (endSkipBidsPostCallMem I catOut vatOut bidOut) (UInt256.ofNat 12) bidOut (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endPackVatWord σ' I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd3805⟩ := endSkipX_suck1ExtcodesizeGuard hloCat hloVat hloBid h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3805⟩) (okPc := ⟨3817⟩) rd3805 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3805⟩) (okPc := ⟨3817⟩) rd3805 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -4813,7 +4813,7 @@ theorem endSkipX_suck1CallReady {cA cA' gh bl σ σ' σ₀ A I} (endSkipBidsPostCallMem I catOut vatOut bidOut) (UInt256.ofNat 12) bidOut (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endPackVatWord σ' I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3820⟩ (gasWord :: endPackVatWord σ' I :: ⟨0⟩ :: endSkipSuckOutPtr :: endSkipSuckInSize :: endSkipSuckOutPtr :: @@ -4826,7 +4826,7 @@ theorem endSkipX_suck1CallReady {cA cA' gh bl σ σ' σ₀ A I} bidOut (cA', σ') k' C' := by obtain ⟨_, _, rd3805⟩ := endSkipX_suck1ExtcodesizeGuard hloCat hloVat hloBid h obtain ⟨gasWord, k', C', rd3820⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3805⟩) (okPc := ⟨3817⟩) rd3805 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3805⟩) (okPc := ⟨3817⟩) rd3805 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -4933,7 +4933,7 @@ theorem endSkipX_suck1CallFailed {cA cA' gh bl σ σpre σpost σ₀ A I} mem (UInt256.ofNat 12) rdata (cA', σpost) k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3821⟩) (okPc := ⟨3837⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨3821⟩) (okPc := ⟨3837⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -4957,7 +4957,7 @@ theorem endSkipX_suck1CallSucceeded {cA cA' gh bl σ σpre σpost σ₀ A I} endSkipIdWord I :: endSkipIlkWord I :: endSkipReturnPc :: sel :: []) mem (UInt256.ofNat 12) rdata (cA', σpost) k' C' := by obtain ⟨_, _, rd3839⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨3821⟩) (okPc := ⟨3837⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨3821⟩) (okPc := ⟨3837⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -5098,7 +5098,7 @@ theorem endSkipX_suck2ExtcodesizeGuard {cA cA' gh bl σ σmem σpost σ₀ A I} unfold Reasoning.Theory.writeWord rfl) (by decide) (by evm_ov)] - have rd3880 := RD.uniswapAddress rd3879 (by native_decide) (by evm_ov) + have rd3880 := RD.address rd3879 (by native_decide) (by evm_ov) have rd3924raw := evm_run rd3880 with [ raw push1 ⟨36⟩ (by native_decide) (by evm_ov), raw dup5 (by native_decide) (by evm_ov), @@ -5197,10 +5197,10 @@ theorem endSkipX_suck2NoCode {cA cA' gh bl σ σmem σpost σ₀ A I} (endSkipSuck1PostCallMem σmem I catOut vatOut bidOut rdata) (UInt256.ofNat 12) rdata (cA', σpost) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σpost (endPackVatWord σpost I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σpost (endPackVatWord σpost I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd3924⟩ := endSkipX_suck2ExtcodesizeGuard hloCat hloVat hloBid h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3924⟩) (okPc := ⟨3936⟩) rd3924 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3924⟩) (okPc := ⟨3936⟩) rd3924 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -5219,7 +5219,7 @@ theorem endSkipX_suck2CallReady {cA cA' gh bl σ σmem σpost σ₀ A I} (endSkipSuck1PostCallMem σmem I catOut vatOut bidOut rdata) (UInt256.ofNat 12) rdata (cA', σpost) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σpost (endPackVatWord σpost I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σpost (endPackVatWord σpost I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3939⟩ (gasWord :: endPackVatWord σpost I :: ⟨0⟩ :: endSkipSuckOutPtr :: endSkipSuckInSize :: endSkipSuckOutPtr :: @@ -5232,7 +5232,7 @@ theorem endSkipX_suck2CallReady {cA cA' gh bl σ σmem σpost σ₀ A I} (UInt256.ofNat 12) rdata (cA', σpost) k' C' := by obtain ⟨_, _, rd3924⟩ := endSkipX_suck2ExtcodesizeGuard hloCat hloVat hloBid h obtain ⟨gasWord, k', C', rd3939⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3924⟩) (okPc := ⟨3936⟩) rd3924 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3924⟩) (okPc := ⟨3936⟩) rd3924 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -5341,7 +5341,7 @@ theorem endSkipX_suck2CallFailed {cA cA' gh bl σ σpre σpost σ₀ A I} mem (UInt256.ofNat 12) rdata (cA', σpost) k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3940⟩) (okPc := ⟨3956⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨3940⟩) (okPc := ⟨3956⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -5365,7 +5365,7 @@ theorem endSkipX_suck2CallSucceeded {cA cA' gh bl σ σpre σpost σ₀ A I} endSkipIdWord I :: endSkipIlkWord I :: endSkipReturnPc :: sel :: []) mem (UInt256.ofNat 12) rdata (cA', σpost) k' C' := by obtain ⟨_, _, rd3958⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨3940⟩) (okPc := ⟨3956⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨3940⟩) (okPc := ⟨3956⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -5543,10 +5543,10 @@ theorem endSkipX_hopeNoCode {cA cA' gh bl σ σmem σcall σpost σ₀ A I} (endSkipSuck2PostCallMemFor σmem σcall I catOut vatOut bidOut rdata) (UInt256.ofNat 12) rdata (cA', σpost) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σpost (endPackVatWord σpost I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σpost (endPackVatWord σpost I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd4026⟩ := endSkipX_hopeExtcodesizeGuard hloCat hloVat hloBid h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4026⟩) (okPc := ⟨4038⟩) rd4026 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4026⟩) (okPc := ⟨4038⟩) rd4026 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -5565,7 +5565,7 @@ theorem endSkipX_hopeCallReady {cA cA' gh bl σ σmem σcall σpost σ₀ A I} (endSkipSuck2PostCallMemFor σmem σcall I catOut vatOut bidOut rdata) (UInt256.ofNat 12) rdata (cA', σpost) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σpost (endPackVatWord σpost I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σpost (endPackVatWord σpost I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4041⟩ (gasWord :: endPackVatWord σpost I :: ⟨0⟩ :: endSkipHopeOutPtr :: endSkipHopeInSize :: endSkipHopeOutPtr :: @@ -5578,7 +5578,7 @@ theorem endSkipX_hopeCallReady {cA cA' gh bl σ σmem σcall σpost σ₀ A I} (UInt256.ofNat 12) rdata (cA', σpost) k' C' := by obtain ⟨_, _, rd4026⟩ := endSkipX_hopeExtcodesizeGuard hloCat hloVat hloBid h obtain ⟨gasWord, k', C', rd4041⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4026⟩) (okPc := ⟨4038⟩) rd4026 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4026⟩) (okPc := ⟨4038⟩) rd4026 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -5687,7 +5687,7 @@ theorem endSkipX_hopeCallFailed {cA cA' gh bl σ σpre σpost σ₀ A I} mem (UInt256.ofNat 12) rdata (cA', σpost) k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨4042⟩) (okPc := ⟨4058⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨4042⟩) (okPc := ⟨4058⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -5710,7 +5710,7 @@ theorem endSkipX_hopeCallSucceeded {cA cA' gh bl σ σpre σpost σ₀ A I} endSkipIdWord I :: endSkipIlkWord I :: endSkipReturnPc :: sel :: []) mem (UInt256.ofNat 12) rdata (cA', σpost) k' C' := by obtain ⟨_, _, rd4060⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨4042⟩) (okPc := ⟨4058⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨4042⟩) (okPc := ⟨4058⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -5854,11 +5854,11 @@ theorem endSkipX_yankNoCode {cA cA' gh bl σ σmem σcall σpost σ₀ A I} (endSkipHopePostCallMemFor σmem σcall I catOut vatOut bidOut rdata) (UInt256.ofNat 12) rdata (cA', σpost) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σpost + Reasoning.Theory.extCodeSizeWord σpost (endSkipCatIlkFlipTargetWord catOut) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd4120⟩ := endSkipX_yankExtcodesizeGuard hloCat hloVat hloBid h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4120⟩) (okPc := ⟨4132⟩) rd4120 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4120⟩) (okPc := ⟨4132⟩) rd4120 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -5876,7 +5876,7 @@ theorem endSkipX_yankCallReady {cA cA' gh bl σ σmem σcall σpost σ₀ A I} (endSkipHopePostCallMemFor σmem σcall I catOut vatOut bidOut rdata) (UInt256.ofNat 12) rdata (cA', σpost) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σpost + Reasoning.Theory.extCodeSizeWord σpost (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4135⟩ (gasWord :: endSkipCatIlkFlipTargetWord catOut :: ⟨0⟩ :: @@ -5891,7 +5891,7 @@ theorem endSkipX_yankCallReady {cA cA' gh bl σ σmem σcall σpost σ₀ A I} (UInt256.ofNat 12) rdata (cA', σpost) k' C' := by obtain ⟨_, _, rd4120⟩ := endSkipX_yankExtcodesizeGuard hloCat hloVat hloBid h obtain ⟨gasWord, k', C', rd4135⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4120⟩) (okPc := ⟨4132⟩) rd4120 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4120⟩) (okPc := ⟨4132⟩) rd4120 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -6004,7 +6004,7 @@ theorem endSkipX_yankCallFailed {cA cA' gh bl σ σpost σ₀ A I} mem (UInt256.ofNat 12) rdata (cA', σpost) k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨4136⟩) (okPc := ⟨4152⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨4136⟩) (okPc := ⟨4152⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -6028,7 +6028,7 @@ theorem endSkipX_yankCallSucceeded {cA cA' gh bl σ σpost σ₀ A I} endSkipIdWord I :: endSkipIlkWord I :: endSkipReturnPc :: sel :: []) mem (UInt256.ofNat 12) rdata (cA', σpost) k' C' := by obtain ⟨_, _, rd4154⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨4136⟩) (okPc := ⟨4152⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨4136⟩) (okPc := ⟨4152⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -6271,7 +6271,7 @@ theorem endSkipX_artAddOverflow {cA cA' gh bl σ σmem σcall σpost σ₀ A I} have rd10104pre := evm_run rd10100 with [raw push2 ⟨10108⟩ (by native_decide) (by evm_ov)] have rd10104 := rd10104pre.jumpiNT (by native_decide) (by decide) (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rd10104 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd10104 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -6683,7 +6683,7 @@ theorem endSkipX_grabExtcodesizeGuard {cA cA' gh bl σ σCall σmem σcall σ₀ rw [haddrMask, husrMaskLeft] rfl) (by decide) (by evm_ov), - raw uniswapAddress (by native_decide) (by evm_ov), + raw address (by native_decide) (by evm_ov), raw push1 ⟨68⟩ (by native_decide) (by evm_ov), raw dup6 (by native_decide) (by evm_ov), raw add (by native_decide) (by evm_ov), @@ -6786,10 +6786,10 @@ theorem endSkipX_grabNoCode {cA cA' gh bl σ σCall σmem σcall σ₀ A I} (endSkipArtStoreHashMemFor σmem σcall I catOut vatOut bidOut) (UInt256.ofNat 12) rdata (cA', σCall) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd4397⟩ := endSkipX_grabExtcodesizeGuard hloCat hloVat hloBid h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4397⟩) (okPc := ⟨4409⟩) rd4397 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4397⟩) (okPc := ⟨4409⟩) rd4397 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -6808,7 +6808,7 @@ theorem endSkipX_grabCallReady {cA cA' gh bl σ σCall σmem σcall σ₀ A I} (endSkipArtStoreHashMemFor σmem σcall I catOut vatOut bidOut) (UInt256.ofNat 12) rdata (cA', σCall) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4412⟩ (gasWord :: endPackVatWord σCall I :: ⟨0⟩ :: endFreeGrabOutPtr :: endFreeGrabInSize :: endFreeGrabOutPtr :: endFreeGrabOutSize :: @@ -6822,7 +6822,7 @@ theorem endSkipX_grabCallReady {cA cA' gh bl σ σCall σmem σcall σ₀ A I} (UInt256.ofNat 12) rdata (cA', σCall) k' C' := by obtain ⟨_, _, rd4397⟩ := endSkipX_grabExtcodesizeGuard hloCat hloVat hloBid h obtain ⟨gasWord, k', C', rd4412⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4397⟩) (okPc := ⟨4409⟩) rd4397 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4397⟩) (okPc := ⟨4409⟩) rd4397 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -6937,7 +6937,7 @@ theorem endSkipX_grabCallFailed {cA cA' gh bl σ σpre σpost σ₀ A I} mem (UInt256.ofNat 12) rdata (cA', σpost) k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨4413⟩) (okPc := ⟨4429⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨4413⟩) (okPc := ⟨4429⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -6963,7 +6963,7 @@ theorem endSkipX_grabCallSucceeded {cA cA' gh bl σ σpre σpost σ₀ A I} endSkipCatIlkFlipWord catOut :: endSkipIdWord I :: endSkipIlkWord I :: endSkipReturnPc :: sel :: []) mem (UInt256.ofNat 12) rdata (cA', σpost) k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨4413⟩) (okPc := ⟨4429⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨4413⟩) (okPc := ⟨4429⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -7278,12 +7278,12 @@ theorem endSkipCatAddr_eq_ofUInt256 (σ : AccountMap) (I : ExecutionEnv) : theorem endSkipCatCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endSkipCatWord τ I) ≠ ⟨0⟩ := by + (hne : Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endSkipCatWord τ I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endSkipCatWord σ I) have htarget : endSkipCatWord σ I = endSkipCatWord τ I := endSkipCatWord_accountMapEquiv hAccounts @@ -7292,10 +7292,10 @@ theorem endSkipCatCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : Executio theorem endSkipCatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endSkipCatWord τ I) = ⟨0⟩ := by + (hzero : Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endSkipCatWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endSkipCatWord σ I) have htarget : endSkipCatWord σ I = endSkipCatWord τ I := endSkipCatWord_accountMapEquiv hAccounts @@ -7303,7 +7303,7 @@ theorem endSkipCatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execut exact hzero theorem endSkipCatCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt256} - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (endSkipCatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by @@ -7313,7 +7313,7 @@ theorem endSkipCatCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt25 (endSkipCatAddr_eq_ofUInt256 σ I) hzero theorem endSkipCatCode_pos_of_codeSize_ne {cA gh bl σ σ₀ A I} {g : UInt256} - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (endSkipCatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat := by @@ -7349,7 +7349,7 @@ theorem evalExpr_endSkip_cat {locals : Store} (evm : EVM.State) theorem endSkipCheckedCatIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecBlock config { contract := contract, locals := endSkipStore I } evm0 (checkedExternalCallStmts (.storage catRef) "catIlks" (.intLit 0) [.var "ilk"] @@ -7385,7 +7385,7 @@ theorem endSkipCheckedCatIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} theorem endSkipCheckedCatIlksFailure {cA gh bl σ σ₀ A I} {g : UInt256} {evmCat : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endSkipCatAddr σ I)) "catIlks" 0 @@ -7432,7 +7432,7 @@ theorem endSkipCheckedCatIlksFailure {cA gh bl σ σ₀ A I} {g : UInt256} theorem endSkipCheckedCatIlksDecodeRevert {cA gh bl σ σ₀ A I} {g : UInt256} {evmCat : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endSkipCatAddr σ I)) "catIlks" 0 @@ -7481,7 +7481,7 @@ theorem endSkipCheckedCatIlksDecodeRevert {cA gh bl σ σ₀ A I} {g : UInt256} theorem endSkipCheckedCatIlksSuccess {cA gh bl σ σ₀ A I} {g : UInt256} {evmCat : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endSkipCatAddr σ I)) "catIlks" 0 @@ -7664,7 +7664,7 @@ theorem endSkipBodyReverts_catIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (htag : endSkipTagWord σ I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecTransitionBody config contract evm0 (endSkipStore I) skipTransition.body .reverted := by intro evm0 @@ -7682,7 +7682,7 @@ theorem endSkipBodyReverts_catIlksCallFailed {cA gh bl σ σ₀ A I} {g : UInt25 (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (htag : endSkipTagWord σ I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endSkipCatAddr σ I)) "catIlks" 0 @@ -7706,7 +7706,7 @@ theorem endSkipBodyReverts_catIlksDecodeShort {cA gh bl σ σ₀ A I} {g : UInt2 (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (htag : endSkipTagWord σ I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endSkipCatAddr σ I)) "catIlks" 0 @@ -7731,7 +7731,7 @@ theorem endSkipPrefixFlipSuccess {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (htag : endSkipTagWord σ I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSkipCatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endSkipCatAddr σ I)) "catIlks" 0 @@ -7797,7 +7797,7 @@ theorem endSkipVatReceiver_afterFlip {σ I catOut evm} theorem endSkipVatCode_zero_afterFlip {σ I} {catOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (endPackVatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by @@ -7808,7 +7808,7 @@ theorem endSkipVatCode_zero_afterFlip {σ I} {catOut : ByteArray} {evm : EVM.Sta theorem endSkipVatCode_pos_afterFlip {σ I} {catOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (endPackVatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [State.lookupAccount, hmap] using @@ -7835,7 +7835,7 @@ theorem evalExprs_endSkip_vatIlksArgs_afterFlip (evm : EVM.State) theorem endSkipCheckedVatIlksNoCode {σ I} {catOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSkipStoreFlip I catOut } evm (checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] "vatIlk") .reverted := by @@ -7858,7 +7858,7 @@ theorem endSkipCheckedVatIlksFailure {σ I} {catOut vatOut : ByteArray} {evm evmVat : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I)] @@ -7888,7 +7888,7 @@ theorem endSkipCheckedVatIlksDecodeRevert {σ I} {catOut vatOut : ByteArray} {evm evmVat : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I)] @@ -7920,7 +7920,7 @@ theorem endSkipCheckedVatIlksSuccess {σ I} {catOut vatOut : ByteArray} {evm evmVat : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I)] @@ -8114,7 +8114,7 @@ theorem endSkipBidsCode_zero_afterRate {σ : AccountMap} {catOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) = + Reasoning.Theory.extCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (endSkipCatIlkFlipAddr catOut)).option 0 @@ -8129,7 +8129,7 @@ theorem endSkipBidsCode_pos_afterRate {σ : AccountMap} {catOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ + Reasoning.Theory.extCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (endSkipCatIlkFlipAddr catOut)).option 0 @@ -8143,23 +8143,23 @@ theorem endSkipBidsCode_pos_afterRate {σ : AccountMap} {catOut : ByteArray} theorem endSkipBidsCodeSize_zero_accountMapEquiv {σ τ : AccountMap} (hAccounts : accountMapEquiv σ τ) (catOut : ByteArray) (hcode : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) = + Reasoning.Theory.extCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endSkipCatIlkFlipTargetWord catOut) = + Reasoning.Theory.extCodeSizeWord τ (endSkipCatIlkFlipTargetWord catOut) = ⟨0⟩ := by - rw [← Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + rw [← Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endSkipCatIlkFlipTargetWord catOut)] exact hcode theorem endSkipBidsCodeSize_ne_accountMapEquiv {σ τ : AccountMap} (hAccounts : accountMapEquiv σ τ) (catOut : ByteArray) (hcode : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ + Reasoning.Theory.extCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endSkipCatIlkFlipTargetWord catOut) ≠ + Reasoning.Theory.extCodeSizeWord τ (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩ := by intro hbad - rw [← Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + rw [← Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endSkipCatIlkFlipTargetWord catOut)] at hbad exact hcode hbad @@ -8185,7 +8185,7 @@ theorem evalExprs_endSkip_bidsArgs_afterRate (evm : EVM.State) theorem endSkipCheckedBidsNoCode {σ I} {catOut vatOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) = + Reasoning.Theory.extCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSkipStoreRate I catOut vatOut } evm (checkedExternalCallStmts (.var "flip") "bids" (.intLit 0) [.var "id"] @@ -8209,7 +8209,7 @@ theorem endSkipCheckedBidsFailure {σ I} {catOut vatOut bidOut : ByteArray} {evm evmBids : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ + Reasoning.Theory.extCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endSkipCatIlkFlipAddr catOut)) @@ -8241,7 +8241,7 @@ theorem endSkipCheckedBidsDecodeRevert {σ I} {catOut vatOut bidOut : ByteArray} {evm evmBids : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ + Reasoning.Theory.extCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endSkipCatIlkFlipAddr catOut)) @@ -8275,7 +8275,7 @@ theorem endSkipCheckedBidsSuccess {σ I} {catOut vatOut bidOut : ByteArray} {evm evmBids : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ + Reasoning.Theory.extCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endSkipCatIlkFlipAddr catOut)) @@ -8613,7 +8613,7 @@ theorem endSkipCheckedSuck1NoCode {σ I} {catOut vatOut bidOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSkipStoreTab I catOut vatOut bidOut } evm (checkedExternalCallStmts (.storage vatRef) "suck" (.intLit 0) @@ -8639,7 +8639,7 @@ theorem endSkipCheckedSuck1Failure {σ I} {catOut vatOut bidOut suckOut : ByteAr {evm evmSuck : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "suck" 0 [.address (endPackVowAddr σ I), .address (endPackVowAddr σ I), @@ -8676,7 +8676,7 @@ theorem endSkipCheckedSuck1Success {σ I} {catOut vatOut bidOut suckOut : ByteAr {evm evmSuck : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "suck" 0 [.address (endPackVowAddr σ I), .address (endPackVowAddr σ I), @@ -8774,7 +8774,7 @@ theorem endSkipCheckedSuck2NoCode {σ I} {catOut vatOut bidOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSkipStoreSuck1 I catOut vatOut bidOut } evm (checkedExternalCallStmts (.storage vatRef) "suck" (.intLit 0) @@ -8801,7 +8801,7 @@ theorem endSkipCheckedSuck2Failure {σ I} {catOut vatOut bidOut suckOut : ByteAr {evm evmSuck : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "suck" 0 [.address (endPackVowAddr σ I), .address I.codeOwner, @@ -8839,7 +8839,7 @@ theorem endSkipCheckedSuck2Success {σ I} {catOut vatOut bidOut suckOut : ByteAr {evm evmSuck : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "suck" 0 [.address (endPackVowAddr σ I), .address I.codeOwner, @@ -8922,7 +8922,7 @@ theorem endSkipCheckedHopeNoCode {σ I} {catOut vatOut bidOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSkipStoreSuck2 I catOut vatOut bidOut } evm (checkedExternalCallStmts (.storage vatRef) "hope" (.intLit 0) @@ -8949,7 +8949,7 @@ theorem endSkipCheckedHopeFailure {σ I} {catOut vatOut bidOut hopeOut : ByteArr {evm evmHope : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "hope" 0 [.address (endSkipCatIlkFlipAddr catOut)] (false, evmHope, hopeOut) true) : @@ -8982,7 +8982,7 @@ theorem endSkipCheckedHopeSuccess {σ I} {catOut vatOut bidOut hopeOut : ByteArr {evm evmHope : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "hope" 0 [.address (endSkipCatIlkFlipAddr catOut)] (true, evmHope, hopeOut) true) : @@ -9070,7 +9070,7 @@ theorem endSkipCheckedYankNoCode {σ I} {catOut vatOut bidOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) = + Reasoning.Theory.extCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSkipStoreHope I catOut vatOut bidOut } evm @@ -9097,7 +9097,7 @@ theorem endSkipCheckedYankFailure {σ I} {catOut vatOut bidOut yankOut : ByteArr {evm evmYank : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ + Reasoning.Theory.extCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endSkipCatIlkFlipAddr catOut)) @@ -9131,7 +9131,7 @@ theorem endSkipCheckedYankSuccess {σ I} {catOut vatOut bidOut yankOut : ByteArr {evm evmYank : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ + Reasoning.Theory.extCodeSizeWord σ (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endSkipCatIlkFlipAddr catOut)) @@ -9666,7 +9666,7 @@ theorem endSkipGrabTailReverts_noCodeFor {σCall σLoc I} {catOut vatOut bidOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σCall) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSkipStoreArtNew σLoc I catOut vatOut bidOut } evm @@ -9699,7 +9699,7 @@ theorem endSkipGrabTailReverts_callFailedFor {σCall σLoc I} {catOut vatOut bidOut grabOut : ByteArray} {evm evmGrab : EVM.State} (hmap : evm.accountMap = σCall) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σCall I)) "grab" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I), @@ -9761,7 +9761,7 @@ theorem endSkipGrabTailReturns_successFor {σCall σLoc I} {catOut vatOut bidOut grabOut : ByteArray} {evm evmGrab : EVM.State} (hmap : evm.accountMap = σCall) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σCall I)) "grab" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I), @@ -10494,10 +10494,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rw [Nat.mod_eq_of_lt] exact a.isLt by_cases hcatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (endSkipCatWord σ_evm I) = + Reasoning.Theory.extCodeSizeWord σ_evm (endSkipCatWord σ_evm I) = ⟨0⟩ · have hcatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endSkipCatWord σ_solm I) = ⟨0⟩ := endSkipCatCodeSize_zero_accountMapEquiv hAccounts hcatCode have hbody : @@ -10510,10 +10510,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endSkipX_catIlksNoCode (g := Sat256.ofUInt256 g) htagPc hcatCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hcatCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (endSkipCatWord σ_evm I) ≠ + Reasoning.Theory.extCodeSizeWord σ_evm (endSkipCatWord σ_evm I) ≠ ⟨0⟩ := hcatCode have hcatCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endSkipCatWord σ_solm I) ≠ ⟨0⟩ := endSkipCatCodeSize_ne_accountMapEquiv hAccounts hcatCodeNE obtain ⟨catGasWord, _, _, hcatReady⟩ := @@ -10650,10 +10650,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simpa [evmCatSolm, evmSolm] using hcallCatSolm) hloCat by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_cat + Reasoning.Theory.extCodeSizeWord σ_cat (endPackVatWord σ_cat I) = ⟨0⟩ · have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_cat_solm + Reasoning.Theory.extCodeSizeWord σ_cat_solm (endPackVatWord σ_cat_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv hAccountsCat hvatCode have hvatBlock : @@ -10674,10 +10674,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endSkipX_vatIlksNoCode rd3436 hloCat hvatCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_cat + Reasoning.Theory.extCodeSizeWord σ_cat (endPackVatWord σ_cat I) ≠ ⟨0⟩ := hvatCode have hvatCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_cat_solm + Reasoning.Theory.extCodeSizeWord σ_cat_solm (endPackVatWord σ_cat_solm I) ≠ ⟨0⟩ := endPackVatCodeSize_ne_accountMapEquiv hAccountsCat hvatCodeNE obtain ⟨gasWordVat, _, _, hvatReady⟩ := @@ -10835,10 +10835,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} evmVatSolm) := by exact endSkipPrefixRateSuccess hprefix hvatBlock by_cases hbidsCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat + Reasoning.Theory.extCodeSizeWord σ_vat (endSkipCatIlkFlipTargetWord catOut) = ⟨0⟩ · have hbidsCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat_solm + Reasoning.Theory.extCodeSizeWord σ_vat_solm (endSkipCatIlkFlipTargetWord catOut) = ⟨0⟩ := endSkipBidsCodeSize_zero_accountMapEquiv hAccountsVat catOut hbidsCode @@ -10863,10 +10863,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endSkipX_bidsNoCode rd3565 hloCat hloVat hbidsCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hbidsCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat + Reasoning.Theory.extCodeSizeWord σ_vat (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩ := hbidsCode have hbidsCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat_solm + Reasoning.Theory.extCodeSizeWord σ_vat_solm (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩ := endSkipBidsCodeSize_ne_accountMapEquiv hAccountsVat catOut hbidsCodeNE @@ -11033,10 +11033,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} evmBidsSolm.executionEnv.codeOwner = I.codeOwner := by rfl by_cases hsuck1Code : - Reasoning.Theory.uniswapExtCodeSizeWord σ_bids + Reasoning.Theory.extCodeSizeWord σ_bids (endPackVatWord σ_bids I) = ⟨0⟩ · have hsuck1CodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_bids_solm + Reasoning.Theory.extCodeSizeWord σ_bids_solm (endPackVatWord σ_bids_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv hAccountsBids hsuck1Code @@ -11058,10 +11058,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rd3712 hsuck1Code) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hsuck1CodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_bids + Reasoning.Theory.extCodeSizeWord σ_bids (endPackVatWord σ_bids I) ≠ ⟨0⟩ := hsuck1Code have hsuck1CodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_bids_solm + Reasoning.Theory.extCodeSizeWord σ_bids_solm (endPackVatWord σ_bids_solm I) ≠ ⟨0⟩ := endPackVatCodeSize_ne_accountMapEquiv hAccountsBids hsuck1CodeNE @@ -11211,10 +11211,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} obtain ⟨_, _, rd3840⟩ := endSkipX_suck1CallSucceeded rd3821Succ by_cases hsuck2Code : - Reasoning.Theory.uniswapExtCodeSizeWord σ_suck1 + Reasoning.Theory.extCodeSizeWord σ_suck1 (endPackVatWord σ_suck1 I) = ⟨0⟩ · have hsuck2CodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_suck1_solm + Reasoning.Theory.extCodeSizeWord σ_suck1_solm (endPackVatWord σ_suck1_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv hAccountsSuck1 hsuck2Code @@ -11237,10 +11237,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} hloCat hloVat hloBid rd3840 hsuck2Code) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hsuck2CodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_suck1 + Reasoning.Theory.extCodeSizeWord σ_suck1 (endPackVatWord σ_suck1 I) ≠ ⟨0⟩ := hsuck2Code have hsuck2CodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_suck1_solm + Reasoning.Theory.extCodeSizeWord σ_suck1_solm (endPackVatWord σ_suck1_solm I) ≠ ⟨0⟩ := endPackVatCodeSize_ne_accountMapEquiv hAccountsSuck1 hsuck2CodeNE @@ -11407,10 +11407,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} obtain ⟨_, _, rd3959⟩ := endSkipX_suck2CallSucceeded rd3940Succ by_cases hhopeCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_suck2 + Reasoning.Theory.extCodeSizeWord σ_suck2 (endPackVatWord σ_suck2 I) = ⟨0⟩ · have hhopeCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σ_suck2_solm (endPackVatWord σ_suck2_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv @@ -11439,10 +11439,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hhopeCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_suck2 + Reasoning.Theory.extCodeSizeWord σ_suck2 (endPackVatWord σ_suck2 I) ≠ ⟨0⟩ := hhopeCode have hhopeCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σ_suck2_solm (endPackVatWord σ_suck2_solm I) ≠ ⟨0⟩ := endPackVatCodeSize_ne_accountMapEquiv @@ -11596,10 +11596,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} obtain ⟨_, _, rd4063⟩ := endSkipX_hopeCallSucceeded rd4042Succ by_cases hyankCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_hope + Reasoning.Theory.extCodeSizeWord σ_hope (endSkipCatIlkFlipTargetWord catOut) = ⟨0⟩ · have hyankCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σ_hope_solm (endSkipCatIlkFlipTargetWord catOut) = ⟨0⟩ := endSkipBidsCodeSize_zero_accountMapEquiv @@ -11628,11 +11628,11 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hyankCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_hope + Reasoning.Theory.extCodeSizeWord σ_hope (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩ := hyankCode have hyankCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σ_hope_solm (endSkipCatIlkFlipTargetWord catOut) ≠ ⟨0⟩ := endSkipBidsCodeSize_ne_accountMapEquiv @@ -11938,10 +11938,10 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} evmSuck1Solm, evmBidsSolm, evmVatSolm, evmCatSolm, evmSolm, initState] by_cases hgrabCode : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σ_post (endPackVatWord σ_post I) = ⟨0⟩ · have hgrabCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σ_post_solm (endPackVatWord σ_post_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv @@ -11971,11 +11971,11 @@ theorem endSkipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hgrabCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σ_post (endPackVatWord σ_post I) ≠ ⟨0⟩ := hgrabCode have hgrabCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σ_post_solm (endPackVatWord σ_post_solm I) ≠ ⟨0⟩ := diff --git a/Benchmarks/Dss/End/Snip.lean b/Benchmarks/Dss/End/Snip.lean index 45749c41..333da08f 100644 --- a/Benchmarks/Dss/End/Snip.lean +++ b/Benchmarks/Dss/End/Snip.lean @@ -2813,10 +2813,10 @@ theorem endSnipX_dogIlksNoCode {cA gh bl σ σ₀ A I} {g : Sat256} [endSnipIdWord I, endSnipIlkWord I, endSnipReturnPc, sel] (endSnipDogIlksBaseMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd1804⟩ := endSnipX_dogIlksExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1804⟩) (okPc := ⟨1816⟩) rd1804 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1804⟩) (okPc := ⟨1816⟩) rd1804 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2828,7 +2828,7 @@ theorem endSnipX_dogIlksCallReady {cA gh bl σ σ₀ A I} {g : Sat256} [endSnipIdWord I, endSnipIlkWord I, endSnipReturnPc, sel] (endSnipDogIlksBaseMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1819⟩ (gasWord :: endSnipDogWord σ I :: ⟨0⟩ :: endFlowVatIlksOutPtr :: endFlowVatIlksInSize :: endFlowVatIlksOutPtr :: endSnipDogIlksOutSize :: @@ -2838,7 +2838,7 @@ theorem endSnipX_dogIlksCallReady {cA gh bl σ σ₀ A I} {g : Sat256} ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd1804⟩ := endSnipX_dogIlksExtcodesizeGuard h obtain ⟨gasWord, k', C', rd1819⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1804⟩) (okPc := ⟨1816⟩) rd1804 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1804⟩) (okPc := ⟨1816⟩) rd1804 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -2926,7 +2926,7 @@ theorem endSnipX_dogIlksCallFailed {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} mem (UInt256.ofNat 8) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1820⟩) (okPc := ⟨1836⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨1820⟩) (okPc := ⟨1836⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2944,7 +2944,7 @@ theorem endSnipX_dogIlksCallSucceeded {cA cA' gh bl σ σ' σ₀ A I} {g : Sat25 (⟨0⟩ :: endSnipIdWord I :: endSnipIlkWord I :: endSnipReturnPc :: sel :: []) mem (UInt256.ofNat 8) rdata (cA', σ') k' C' := by obtain ⟨_, _, rd1838⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨1820⟩) (okPc := ⟨1836⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨1820⟩) (okPc := ⟨1836⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -3018,7 +3018,7 @@ theorem endSnipX_dogIlksReturnDecodeShort {cA cA' gh bl σ σ' σ₀ A I} {g : S rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rdShort have rdFall := rdShort.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFall + exact RD.solcPush1Dup1Revert0 rdFall (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -3160,10 +3160,10 @@ theorem endSnipX_vatIlksNoCode {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} (endSnipDogIlksPostCallMem I dogOut) (UInt256.ofNat 8) dogOut (cA', σ') k C) (hloDog : 128 ≤ dogOut.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endPackVatWord σ' I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd1930⟩ := endSnipX_vatIlksExtcodesizeGuard hloDog h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1930⟩) (okPc := ⟨1942⟩) rd1930 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1930⟩) (okPc := ⟨1942⟩) rd1930 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3177,7 +3177,7 @@ theorem endSnipX_vatIlksCallReady {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} (endSnipDogIlksPostCallMem I dogOut) (UInt256.ofNat 8) dogOut (cA', σ') k C) (hloDog : 128 ≤ dogOut.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endPackVatWord σ' I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1945⟩ (gasWord :: endPackVatWord σ' I :: ⟨0⟩ :: endFlowVatIlksOutPtr :: endFlowVatIlksInSize :: endFlowVatIlksOutPtr :: endFlowVatIlksOutSize :: @@ -3188,7 +3188,7 @@ theorem endSnipX_vatIlksCallReady {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} dogOut (cA', σ') k' C' := by obtain ⟨_, _, rd1930⟩ := endSnipX_vatIlksExtcodesizeGuard hloDog h obtain ⟨gasWord, k', C', rd1945⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1930⟩) (okPc := ⟨1942⟩) rd1930 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1930⟩) (okPc := ⟨1942⟩) rd1930 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -3282,7 +3282,7 @@ theorem endSnipX_vatIlksCallFailed {cA cA' gh bl σ σcur σ' σ₀ A I} mem (UInt256.ofNat 9) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1946⟩) (okPc := ⟨1962⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨1946⟩) (okPc := ⟨1962⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3302,7 +3302,7 @@ theorem endSnipX_vatIlksCallSucceeded {cA cA' gh bl σ σcur σ' σ₀ A I} ⟨0⟩ :: endSnipDogIlkClipWord dogOut :: endSnipDogIlkClipWord dogOut :: endSnipIdWord I :: endSnipIlkWord I :: endSnipReturnPc :: sel :: []) mem (UInt256.ofNat 9) rdata (cA', σ') k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨1946⟩) (okPc := ⟨1962⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨1946⟩) (okPc := ⟨1962⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -3393,7 +3393,7 @@ theorem endSnipX_vatIlksReturnDecodeShort {cA cA' gh bl σ σcur σ' σ₀ A I} rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rdShort have rdFall := rdShort.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFall + exact RD.solcPush1Dup1Revert0 rdFall (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -3527,10 +3527,10 @@ theorem endSnipX_salesNoCode {cA cA' gh bl σ σ' σ₀ A I} (cA', σ') k C) (hloDog : 128 ≤ dogOut.size) (hloVat : 160 ≤ vatOut.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endSnipSalesClipWord dogOut) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endSnipSalesClipWord dogOut) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd2058⟩ := endSnipX_salesExtcodesizeGuard hloDog hloVat h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2058⟩) (okPc := ⟨2070⟩) rd2058 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2058⟩) (okPc := ⟨2070⟩) rd2058 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3546,7 +3546,7 @@ theorem endSnipX_salesCallReady {cA cA' gh bl σ σ' σ₀ A I} (cA', σ') k C) (hloDog : 128 ≤ dogOut.size) (hloVat : 160 ≤ vatOut.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2073⟩ (gasWord :: endSnipSalesClipWord dogOut :: endFlowVatIlksOutPtr :: endFlowVatIlksInSize :: endFlowVatIlksOutPtr :: endSnipSalesOutSize :: @@ -3559,7 +3559,7 @@ theorem endSnipX_salesCallReady {cA cA' gh bl σ σ' σ₀ A I} (cA', σ') k' C' := by obtain ⟨_, _, rd2058⟩ := endSnipX_salesExtcodesizeGuard hloDog hloVat h obtain ⟨gasWord, k', C', rd2073⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2058⟩) (okPc := ⟨2070⟩) rd2058 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2058⟩) (okPc := ⟨2070⟩) rd2058 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -3602,7 +3602,7 @@ theorem endSnipX_salesPostStaticcall {cA cAcur gh bl σ σcur σ₀ A I} saleOut (cA', σ') k' C' ∧ saleOut.size < UInt256.size := by obtain ⟨cA', σ', z, saleOut, Ain, callGas, k', C', hΘ, rd2074raw, hout⟩ := - RD.uniswapStaticcall h (by native_decide) hdepth + RD.solcStaticcall h (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨cA', σ', z, saleOut, Ain, callGas, k', C', ?_, ?_, hout⟩ · simpa [initState] using hΘ @@ -3638,7 +3638,7 @@ theorem endSnipX_salesStaticcallDepthLimit {cA cAcur gh bl σ σcur σ₀ A I} (endSnipSalesCalldataMem I dogOut vatOut) (UInt256.ofNat 10) ByteArray.empty (cAcur, σcur) k' C' := by obtain ⟨k', C', rd2074raw⟩ := - RD.uniswapStaticcallDepthLimit h (by native_decide) hdepth + RD.solcStaticcallDepthLimit h (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨k', C', ?_⟩ have hmin : (min endSnipSalesOutSize (UInt256.ofNat ByteArray.empty.size)).toNat = 0 := by @@ -3664,7 +3664,7 @@ theorem endSnipX_salesCallFailed {cA cA' gh bl σ σ' σ₀ A I} mem (UInt256.ofNat 10) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2074⟩) (okPc := ⟨2090⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨2074⟩) (okPc := ⟨2090⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3687,7 +3687,7 @@ theorem endSnipX_salesCallSucceeded {cA cA' gh bl σ σ' σ₀ A I} endSnipIdWord I :: endSnipIlkWord I :: endSnipReturnPc :: sel :: []) mem (UInt256.ofNat 10) rdata (cA', σ') k' C' := by obtain ⟨_, _, rd2092⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨2074⟩) (okPc := ⟨2090⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨2074⟩) (okPc := ⟨2090⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -3795,7 +3795,7 @@ theorem endSnipX_salesReturnDecodeShort {cA cA' gh bl σ σ' σ₀ A I} rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rdShort have rdFall := rdShort.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFall + exact RD.solcPush1Dup1Revert0 rdFall (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -4241,10 +4241,10 @@ theorem endSnipX_suckNoCode {cA cA' gh bl σ σ' σ₀ A I} (endSnipSalesPostCallMem I dogOut vatOut saleOut) (UInt256.ofNat 10) saleOut (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endPackVatWord σ' I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd2220⟩ := endSnipX_suckExtcodesizeGuard hloDog hloVat hloSale h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2220⟩) (okPc := ⟨2232⟩) rd2220 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2220⟩) (okPc := ⟨2232⟩) rd2220 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -4263,7 +4263,7 @@ theorem endSnipX_suckCallReady {cA cA' gh bl σ σ' σ₀ A I} (endSnipSalesPostCallMem I dogOut vatOut saleOut) (UInt256.ofNat 10) saleOut (cA', σ') k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endPackVatWord σ' I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (endPackVatWord σ' I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2235⟩ (gasWord :: endPackVatWord σ' I :: ⟨0⟩ :: endSnipSuckOutPtr :: endSnipSuckInSize :: endSnipSuckOutPtr :: endSnipSuckOutSize :: @@ -4276,7 +4276,7 @@ theorem endSnipX_suckCallReady {cA cA' gh bl σ σ' σ₀ A I} saleOut (cA', σ') k' C' := by obtain ⟨_, _, rd2220⟩ := endSnipX_suckExtcodesizeGuard hloDog hloVat hloSale h obtain ⟨gasWord, k', C', rd2235⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2220⟩) (okPc := ⟨2232⟩) rd2220 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2220⟩) (okPc := ⟨2232⟩) rd2220 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -4383,7 +4383,7 @@ theorem endSnipX_suckCallFailed {cA cA' gh bl σ σpre σpost σ₀ A I} mem (UInt256.ofNat 10) rdata (cA', σpost) k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2236⟩) (okPc := ⟨2252⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨2236⟩) (okPc := ⟨2252⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -4406,7 +4406,7 @@ theorem endSnipX_suckCallSucceeded {cA cA' gh bl σ σpre σpost σ₀ A I} endSnipIdWord I :: endSnipIlkWord I :: endSnipReturnPc :: sel :: []) mem (UInt256.ofNat 10) rdata (cA', σpost) k' C' := by obtain ⟨_, _, rd2254⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨2236⟩) (okPc := ⟨2252⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨2236⟩) (okPc := ⟨2252⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -4560,10 +4560,10 @@ theorem endSnipX_yankNoCode {cA cA' gh bl σ σmem σpost σ₀ A I} (endSnipSuckCalldataMem σmem I dogOut vatOut saleOut) (UInt256.ofNat 10) rdata (cA', σpost) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σpost (endSnipSalesClipWord dogOut) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σpost (endSnipSalesClipWord dogOut) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd2314⟩ := endSnipX_yankExtcodesizeGuard hloDog hloVat hloSale h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2314⟩) (okPc := ⟨2326⟩) rd2314 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2314⟩) (okPc := ⟨2326⟩) rd2314 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -4581,7 +4581,7 @@ theorem endSnipX_yankCallReady {cA cA' gh bl σ σmem σpost σ₀ A I} (endSnipSuckCalldataMem σmem I dogOut vatOut saleOut) (UInt256.ofNat 10) rdata (cA', σpost) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σpost (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σpost (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2329⟩ (gasWord :: endSnipSalesClipWord dogOut :: ⟨0⟩ :: endSnipYankOutPtr :: endSnipYankInSize :: endSnipYankOutPtr :: endSnipYankOutSize :: @@ -4594,7 +4594,7 @@ theorem endSnipX_yankCallReady {cA cA' gh bl σ σmem σpost σ₀ A I} rdata (cA', σpost) k' C' := by obtain ⟨_, _, rd2314⟩ := endSnipX_yankExtcodesizeGuard hloDog hloVat hloSale h obtain ⟨gasWord, k', C', rd2329⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2314⟩) (okPc := ⟨2326⟩) rd2314 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2314⟩) (okPc := ⟨2326⟩) rd2314 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -4701,7 +4701,7 @@ theorem endSnipX_yankCallFailed {cA cA' gh bl σ σpost σ₀ A I} mem (UInt256.ofNat 10) rdata (cA', σpost) k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2330⟩) (okPc := ⟨2346⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨2330⟩) (okPc := ⟨2346⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -4724,7 +4724,7 @@ theorem endSnipX_yankCallSucceeded {cA cA' gh bl σ σpost σ₀ A I} endSnipIdWord I :: endSnipIlkWord I :: endSnipReturnPc :: sel :: []) mem (UInt256.ofNat 10) rdata (cA', σpost) k' C' := by obtain ⟨_, _, rd2348⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨2330⟩) (okPc := ⟨2346⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨2330⟩) (okPc := ⟨2346⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -4966,7 +4966,7 @@ theorem endSnipX_artAddOverflow {cA cA' gh bl σ σmem σpost σ₀ A I} have rd10104pre := evm_run rd10100 with [raw push2 ⟨10108⟩ (by native_decide) (by evm_ov)] have rd10104 := rd10104pre.jumpiNT (by native_decide) (by decide) (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rd10104 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd10104 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -5375,7 +5375,7 @@ theorem endSnipX_grabExtcodesizeGuard {cA cA' gh bl σ σCall σLoc σ₀ A I} rw [haddrMask, husrMaskLeft] rfl) (by decide) (by evm_ov), - raw uniswapAddress (by native_decide) (by evm_ov), + raw address (by native_decide) (by evm_ov), raw push1 ⟨68⟩ (by native_decide) (by evm_ov), raw dup6 (by native_decide) (by evm_ov), raw add (by native_decide) (by evm_ov), @@ -5481,10 +5481,10 @@ theorem endSnipX_grabNoCode {cA cA' gh bl σ σCall σLoc σ₀ A I} (endSnipArtStoreHashMem σLoc I dogOut vatOut saleOut) (UInt256.ofNat 10) rdata (cA', σCall) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) = ⟨0⟩) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd2591⟩ := endSnipX_grabExtcodesizeGuard hloDog hloVat hloSale h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2591⟩) (okPc := ⟨2603⟩) rd2591 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2591⟩) (okPc := ⟨2603⟩) rd2591 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -5503,7 +5503,7 @@ theorem endSnipX_grabCallReady {cA cA' gh bl σ σCall σLoc σ₀ A I} (endSnipArtStoreHashMem σLoc I dogOut vatOut saleOut) (UInt256.ofNat 10) rdata (cA', σCall) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2606⟩ (gasWord :: endPackVatWord σCall I :: ⟨0⟩ :: endFreeGrabOutPtr :: endFreeGrabInSize :: endFreeGrabOutPtr :: endFreeGrabOutSize :: @@ -5517,7 +5517,7 @@ theorem endSnipX_grabCallReady {cA cA' gh bl σ σCall σLoc σ₀ A I} (UInt256.ofNat 11) rdata (cA', σCall) k' C' := by obtain ⟨_, _, rd2591⟩ := endSnipX_grabExtcodesizeGuard hloDog hloVat hloSale h obtain ⟨gasWord, k', C', rd2606⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2591⟩) (okPc := ⟨2603⟩) rd2591 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2591⟩) (okPc := ⟨2603⟩) rd2591 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -5631,7 +5631,7 @@ theorem endSnipX_grabCallFailed {cA cA' gh bl σ σpre σpost σ₀ A I} mem (UInt256.ofNat 11) rdata (cA', σpost) k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2607⟩) (okPc := ⟨2623⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨2607⟩) (okPc := ⟨2623⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -5657,7 +5657,7 @@ theorem endSnipX_grabCallSucceeded {cA cA' gh bl σ σpre σpost σ₀ A I} endSnipDogIlkClipWord dogOut :: endSnipIdWord I :: endSnipIlkWord I :: endSnipReturnPc :: sel :: []) mem (UInt256.ofNat 11) rdata (cA', σpost) k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨2607⟩) (okPc := ⟨2623⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨2607⟩) (okPc := ⟨2623⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -5971,12 +5971,12 @@ theorem endPackVowWord_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} theorem endSnipDogCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endSnipDogWord τ I) ≠ ⟨0⟩ := by + (hne : Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endSnipDogWord τ I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endSnipDogWord σ I) have htarget : endSnipDogWord σ I = endSnipDogWord τ I := endSnipDogWord_accountMapEquiv hAccounts @@ -5985,10 +5985,10 @@ theorem endSnipDogCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : Executio theorem endSnipDogCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endSnipDogWord τ I) = ⟨0⟩ := by + (hzero : Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endSnipDogWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endSnipDogWord σ I) have htarget : endSnipDogWord σ I = endSnipDogWord τ I := endSnipDogWord_accountMapEquiv hAccounts @@ -5996,7 +5996,7 @@ theorem endSnipDogCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execut exact hzero theorem endSnipDogCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt256} - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (endSnipDogAddr σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by @@ -6006,7 +6006,7 @@ theorem endSnipDogCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt25 (endSnipDogAddr_eq_ofUInt256 σ I) hzero theorem endSnipDogCode_pos_of_codeSize_ne {cA gh bl σ σ₀ A I} {g : UInt256} - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (endSnipDogAddr σ I)).option 0 (fun acc => acc.code.size))).toNat := by @@ -6042,7 +6042,7 @@ theorem evalExpr_endSnip_dog {locals : Store} (evm : EVM.State) theorem endSnipCheckedDogIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecBlock config { contract := contract, locals := endSnipStore I } evm0 (checkedExternalCallStmts (.storage dogRef) "dogIlks" (.intLit 0) [.var "ilk"] @@ -6078,7 +6078,7 @@ theorem endSnipCheckedDogIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} theorem endSnipCheckedDogIlksFailure {cA gh bl σ σ₀ A I} {g : UInt256} {evmDog : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endSnipDogAddr σ I)) "dogIlks" 0 @@ -6125,7 +6125,7 @@ theorem endSnipCheckedDogIlksFailure {cA gh bl σ σ₀ A I} {g : UInt256} theorem endSnipCheckedDogIlksDecodeRevert {cA gh bl σ σ₀ A I} {g : UInt256} {evmDog : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endSnipDogAddr σ I)) "dogIlks" 0 @@ -6174,7 +6174,7 @@ theorem endSnipCheckedDogIlksDecodeRevert {cA gh bl σ σ₀ A I} {g : UInt256} theorem endSnipCheckedDogIlksSuccess {cA gh bl σ σ₀ A I} {g : UInt256} {evmDog : EVM.State} {out : ByteArray} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endSnipDogAddr σ I)) "dogIlks" 0 @@ -6350,7 +6350,7 @@ theorem endSnipBodyReverts_dogIlksNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (htag : endSnipTagWord σ I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecTransitionBody config contract evm0 (endSnipStore I) snipTransition.body .reverted := by intro evm0 @@ -6368,7 +6368,7 @@ theorem endSnipBodyReverts_dogIlksCallFailed {cA gh bl σ σ₀ A I} {g : UInt25 (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (htag : endSnipTagWord σ I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endSnipDogAddr σ I)) "dogIlks" 0 @@ -6392,7 +6392,7 @@ theorem endSnipBodyReverts_dogIlksDecodeShort {cA gh bl σ σ₀ A I} {g : UInt2 (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (htag : endSnipTagWord σ I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endSnipDogAddr σ I)) "dogIlks" 0 @@ -6417,7 +6417,7 @@ theorem endSnipPrefixClipSuccess {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) (htag : endSnipTagWord σ I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSnipDogWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endSnipDogAddr σ I)) "dogIlks" 0 @@ -6483,7 +6483,7 @@ theorem endSnipVatReceiver_afterClip {σ I dogOut evm} theorem endSnipVatCode_zero_afterClip {σ I} {dogOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (endPackVatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by @@ -6494,7 +6494,7 @@ theorem endSnipVatCode_zero_afterClip {σ I} {dogOut : ByteArray} {evm : EVM.Sta theorem endSnipVatCode_pos_afterClip {σ I} {dogOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (endPackVatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [State.lookupAccount, hmap] using @@ -6521,7 +6521,7 @@ theorem evalExprs_endSnip_vatIlksArgs_afterClip (evm : EVM.State) theorem endSnipCheckedVatIlksNoCode {σ I} {dogOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSnipStoreClip I dogOut } evm (checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] "vatIlk") .reverted := by @@ -6544,7 +6544,7 @@ theorem endSnipCheckedVatIlksFailure {σ I} {dogOut vatOut : ByteArray} {evm evmVat : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I)] @@ -6574,7 +6574,7 @@ theorem endSnipCheckedVatIlksDecodeRevert {σ I} {dogOut vatOut : ByteArray} {evm evmVat : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I)] @@ -6606,7 +6606,7 @@ theorem endSnipCheckedVatIlksSuccess {σ I} {dogOut vatOut : ByteArray} {evm evmVat : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "vatIlks" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I)] @@ -6782,7 +6782,7 @@ theorem endSnipSalesReceiver_afterRate {I dogOut vatOut evm} : theorem endSnipSalesCode_zero_afterRate {σ : AccountMap} {dogOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipSalesClipWord dogOut) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endSnipSalesClipWord dogOut) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (endSnipDogIlkClipAddr dogOut)).option 0 (fun acc => acc.code.size))).toNat = 0 := by @@ -6795,7 +6795,7 @@ theorem endSnipSalesCode_zero_afterRate {σ : AccountMap} {dogOut : ByteArray} { theorem endSnipSalesCode_pos_afterRate {σ : AccountMap} {dogOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (endSnipDogIlkClipAddr dogOut)).option 0 (fun acc => acc.code.size))).toNat := by @@ -6808,19 +6808,19 @@ theorem endSnipSalesCode_pos_afterRate {σ : AccountMap} {dogOut : ByteArray} {e theorem endSnipSalesCodeSize_zero_accountMapEquiv {σ τ : AccountMap} (hAccounts : accountMapEquiv σ τ) (dogOut : ByteArray) (hcode : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipSalesClipWord dogOut) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endSnipSalesClipWord dogOut) = ⟨0⟩ := by - rw [← Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord σ (endSnipSalesClipWord dogOut) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endSnipSalesClipWord dogOut) = ⟨0⟩ := by + rw [← Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endSnipSalesClipWord dogOut)] exact hcode theorem endSnipSalesCodeSize_ne_accountMapEquiv {σ τ : AccountMap} (hAccounts : accountMapEquiv σ τ) (dogOut : ByteArray) (hcode : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩ := by intro hbad - rw [← Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + rw [← Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endSnipSalesClipWord dogOut)] at hbad exact hcode hbad @@ -6846,7 +6846,7 @@ theorem evalExprs_endSnip_salesArgs_afterRate (evm : EVM.State) theorem endSnipCheckedSalesNoCode {σ I} {dogOut vatOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipSalesClipWord dogOut) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endSnipSalesClipWord dogOut) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSnipStoreRate I dogOut vatOut } evm (checkedExternalCallStmts (.var "clip") "sales" (.intLit 0) [.var "id"] "clipSale" (perm := false)) .reverted := by @@ -6869,7 +6869,7 @@ theorem endSnipCheckedSalesFailure {σ I} {dogOut vatOut saleOut : ByteArray} {evm evmSales : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endSnipDogIlkClipAddr dogOut)) "sales" 0 [.int (Int.ofNat (endSnipIdWord I).toNat)] @@ -6900,7 +6900,7 @@ theorem endSnipCheckedSalesDecodeRevert {σ I} {dogOut vatOut saleOut : ByteArra {evm evmSales : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endSnipDogIlkClipAddr dogOut)) "sales" 0 [.int (Int.ofNat (endSnipIdWord I).toNat)] @@ -6933,7 +6933,7 @@ theorem endSnipCheckedSalesSuccess {σ I} {dogOut vatOut saleOut : ByteArray} {evm evmSales : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endSnipDogIlkClipAddr dogOut)) "sales" 0 [.int (Int.ofNat (endSnipIdWord I).toNat)] @@ -7208,7 +7208,7 @@ theorem endSnipCheckedSuckNoCode {σ I} {dogOut vatOut saleOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSnipStoreUsr I dogOut vatOut saleOut } evm (checkedExternalCallStmts (.storage vatRef) "suck" (.intLit 0) @@ -7234,7 +7234,7 @@ theorem endSnipCheckedSuckFailure {σ I} {dogOut vatOut saleOut suckOut : ByteAr {evm evmSuck : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "suck" 0 [.address (endPackVowAddr σ I), .address (endPackVowAddr σ I), @@ -7271,7 +7271,7 @@ theorem endSnipCheckedSuckSuccess {σ I} {dogOut vatOut saleOut suckOut : ByteAr {evm evmSuck : EVM.State} (hmap : evm.accountMap = σ) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endPackVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σ I)) "suck" 0 [.address (endPackVowAddr σ I), .address (endPackVowAddr σ I), @@ -7354,7 +7354,7 @@ theorem endSnipCheckedYankNoCode {σ I} {dogOut vatOut saleOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipSalesClipWord dogOut) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endSnipSalesClipWord dogOut) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSnipStoreSuck I dogOut vatOut saleOut } evm (checkedExternalCallStmts (.var "clip") "yank" (.intLit 0) [.var "id"] "_yank") @@ -7378,7 +7378,7 @@ theorem endSnipCheckedYankFailure {σ I} {dogOut vatOut saleOut yankOut : ByteAr {evm evmYank : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endSnipDogIlkClipAddr dogOut)) "yank" 0 [.int (Int.ofNat (endSnipIdWord I).toNat)] @@ -7409,7 +7409,7 @@ theorem endSnipCheckedYankSuccess {σ I} {dogOut vatOut saleOut yankOut : ByteAr {evm evmYank : EVM.State} (hmap : evm.accountMap = σ) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endSnipSalesClipWord dogOut) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endSnipDogIlkClipAddr dogOut)) "yank" 0 [.int (Int.ofNat (endSnipIdWord I).toNat)] @@ -7971,7 +7971,7 @@ theorem endSnipGrabTailReverts_noCodeFor {σCall σLoc I} {dogOut vatOut saleOut : ByteArray} {evm : EVM.State} (hmap : evm.accountMap = σCall) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endSnipStoreArtNew σLoc I dogOut vatOut saleOut } evm @@ -8004,7 +8004,7 @@ theorem endSnipGrabTailReverts_callFailedFor {σCall σLoc I} {dogOut vatOut saleOut grabOut : ByteArray} {evm evmGrab : EVM.State} (hmap : evm.accountMap = σCall) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σCall I)) "grab" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I), @@ -8066,7 +8066,7 @@ theorem endSnipGrabTailReturns_successFor {σCall σLoc I} {dogOut vatOut saleOut grabOut : ByteArray} {evm evmGrab : EVM.State} (hmap : evm.accountMap = σCall) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σCall (endPackVatWord σCall I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (endPackVatAddr σCall I)) "grab" 0 [.fixedBytes bytes32Width (endBytes32ArgBytes I), @@ -8877,10 +8877,10 @@ theorem endSnipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rw [Nat.mod_eq_of_lt] exact a.isLt by_cases hdogCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (endSnipDogWord σ_evm I) = + Reasoning.Theory.extCodeSizeWord σ_evm (endSnipDogWord σ_evm I) = ⟨0⟩ · have hdogCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endSnipDogWord σ_solm I) = ⟨0⟩ := endSnipDogCodeSize_zero_accountMapEquiv hAccounts hdogCode have hbody : @@ -8893,10 +8893,10 @@ theorem endSnipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endSnipX_dogIlksNoCode (g := Sat256.ofUInt256 g) htagPc hdogCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hdogCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (endSnipDogWord σ_evm I) ≠ + Reasoning.Theory.extCodeSizeWord σ_evm (endSnipDogWord σ_evm I) ≠ ⟨0⟩ := hdogCode have hdogCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endSnipDogWord σ_solm I) ≠ ⟨0⟩ := endSnipDogCodeSize_ne_accountMapEquiv hAccounts hdogCodeNE obtain ⟨dogGasWord, _, _, hcallReady⟩ := @@ -9033,10 +9033,10 @@ theorem endSnipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simpa [evmDogSolm, evmSolm] using hcallSolm) hloDog by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dog + Reasoning.Theory.extCodeSizeWord σ_dog (endPackVatWord σ_dog I) = ⟨0⟩ · have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dog_solm + Reasoning.Theory.extCodeSizeWord σ_dog_solm (endPackVatWord σ_dog_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv hAccountsDog hvatCode have hvatBlock : @@ -9057,10 +9057,10 @@ theorem endSnipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endSnipX_vatIlksNoCode rd1861 hloDog hvatCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dog + Reasoning.Theory.extCodeSizeWord σ_dog (endPackVatWord σ_dog I) ≠ ⟨0⟩ := hvatCode have hvatCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dog_solm + Reasoning.Theory.extCodeSizeWord σ_dog_solm (endPackVatWord σ_dog_solm I) ≠ ⟨0⟩ := endPackVatCodeSize_ne_accountMapEquiv hAccountsDog hvatCodeNE obtain ⟨gasWordVat, _, _, hvatReady⟩ := @@ -9218,10 +9218,10 @@ theorem endSnipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} evmVatSolm) := by exact endSnipPrefixRateSuccess hprefix hvatBlock by_cases hsalesCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat + Reasoning.Theory.extCodeSizeWord σ_vat (endSnipSalesClipWord dogOut) = ⟨0⟩ · have hsalesCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat_solm + Reasoning.Theory.extCodeSizeWord σ_vat_solm (endSnipSalesClipWord dogOut) = ⟨0⟩ := endSnipSalesCodeSize_zero_accountMapEquiv hAccountsVat dogOut hsalesCode @@ -9246,10 +9246,10 @@ theorem endSnipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endSnipX_salesNoCode rd1990 hloDog hloVat hsalesCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hsalesCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat + Reasoning.Theory.extCodeSizeWord σ_vat (endSnipSalesClipWord dogOut) ≠ ⟨0⟩ := hsalesCode have hsalesCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat_solm + Reasoning.Theory.extCodeSizeWord σ_vat_solm (endSnipSalesClipWord dogOut) ≠ ⟨0⟩ := endSnipSalesCodeSize_ne_accountMapEquiv hAccountsVat dogOut hsalesCodeNE @@ -9415,10 +9415,10 @@ theorem endSnipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} evmSalesSolm.executionEnv.codeOwner = I.codeOwner := by rfl by_cases hsuckCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sales + Reasoning.Theory.extCodeSizeWord σ_sales (endPackVatWord σ_sales I) = ⟨0⟩ · have hsuckCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sales_solm + Reasoning.Theory.extCodeSizeWord σ_sales_solm (endPackVatWord σ_sales_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv hAccountsSales hsuckCode @@ -9440,10 +9440,10 @@ theorem endSnipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rd2131 hsuckCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hsuckCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sales + Reasoning.Theory.extCodeSizeWord σ_sales (endPackVatWord σ_sales I) ≠ ⟨0⟩ := hsuckCode have hsuckCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sales_solm + Reasoning.Theory.extCodeSizeWord σ_sales_solm (endPackVatWord σ_sales_solm I) ≠ ⟨0⟩ := endPackVatCodeSize_ne_accountMapEquiv hAccountsSales hsuckCodeNE @@ -9592,10 +9592,10 @@ theorem endSnipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} obtain ⟨_, _, rd2257⟩ := endSnipX_suckCallSucceeded rd2236Succ by_cases hyankCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_suck + Reasoning.Theory.extCodeSizeWord σ_suck (endSnipSalesClipWord dogOut) = ⟨0⟩ · have hyankCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_suck_solm + Reasoning.Theory.extCodeSizeWord σ_suck_solm (endSnipSalesClipWord dogOut) = ⟨0⟩ := endSnipSalesCodeSize_zero_accountMapEquiv hAccountsSuck dogOut hyankCode @@ -9617,10 +9617,10 @@ theorem endSnipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} hyankCode) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hyankCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_suck + Reasoning.Theory.extCodeSizeWord σ_suck (endSnipSalesClipWord dogOut) ≠ ⟨0⟩ := hyankCode have hyankCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_suck_solm + Reasoning.Theory.extCodeSizeWord σ_suck_solm (endSnipSalesClipWord dogOut) ≠ ⟨0⟩ := endSnipSalesCodeSize_ne_accountMapEquiv hAccountsSuck dogOut hyankCodeNE @@ -9905,10 +9905,10 @@ theorem endSnipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} evmSuckSolm, evmSalesSolm, evmVatSolm, evmDogSolm, evmSolm, initState] by_cases hgrabCode : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σ_post (endPackVatWord σ_post I) = ⟨0⟩ · have hgrabCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σ_post_solm (endPackVatWord σ_post_solm I) = ⟨0⟩ := endPackVatCodeSize_zero_accountMapEquiv @@ -9936,11 +9936,11 @@ theorem endSnipBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hgrabCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σ_post (endPackVatWord σ_post I) ≠ ⟨0⟩ := hgrabCode have hgrabCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord σ_post_solm (endPackVatWord σ_post_solm I) ≠ ⟨0⟩ := diff --git a/Benchmarks/Dss/End/SpecSyntax.lean b/Benchmarks/Dss/End/SpecSyntax.lean index 256a1860..bfa4842a 100644 --- a/Benchmarks/Dss/End/SpecSyntax.lean +++ b/Benchmarks/Dss/End/SpecSyntax.lean @@ -2,19 +2,370 @@ import Benchmarks.Dss.End.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS End spec through the Solm notation frontend +# End spec in the Solidity-faithful Solm frontend -The main spec lives in `Spec.lean`; this companion keeps the benchmark's notation-side check wired -up as the body surface grows. +The whole `end.sol` spec written with `solidity%` and proven definitionally equal to the AST +spec in `Spec.lean`. Checked external calls are the `require(x.code.length > 0)` + +call pairs; `{view}` marks the spec's `(perm := false)` calls; the `int256(x) >= 0` guards are +the spec's `< 2^255` / `<= 2^255` comparisons against `#int256Limit`; `file` keys are big-endian +`bytes32` ASCII literals. Transition order matches `contract.transitions` (selector order). -/ -open Solm Solm.Notation +open Solm Solm.Notation Benchmarks.Dss.End namespace Benchmarks.Dss.End.Syntax -def contractSyntax : ContractDecl := Benchmarks.Dss.End.contract +def contractSyntax : ContractDecl := solidity% contract End { + mapping(address => uint256) wards; + address vat; + address cat; + address dog; + address vow; + address pot; + address spot; + address cure; + uint256 live; + uint256 when; + uint256 wait; + uint256 debt; + mapping(bytes32 => uint256) tag; + mapping(bytes32 => uint256) gap; + mapping(bytes32 => uint256) Art; + mapping(bytes32 => uint256) fix; + mapping(address => uint256) bag; + mapping(bytes32 => mapping(address => uint256)) out; -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.End.contract := by - rfl + constructor() { + wards[msg.sender] = 1; + live = 1; + } + + function add(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x + y) as uint256; + require(z >= x); + return z; + } + + function sub(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x - y) as uint256; + require(z <= x); + return z; + } + + function mul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + return z; + } + + function min(uint256 x, uint256 y) internal returns (uint256) { + if (x <= y) { + return x; + } else { + return y; + } + } + + function rmul(uint256 x, uint256 y) internal returns (uint256) { + var m = mul(x, y); + return m / #RAY; + } + + function wdiv(uint256 x, uint256 y) internal returns (uint256) { + var m = mul(x, #WAD); + return m / y; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } + + function vat() external returns (address) { + return vat; + } + + function cat() external returns (address) { + return cat; + } + + function dog() external returns (address) { + return dog; + } + + function vow() external returns (address) { + return vow; + } + + function pot() external returns (address) { + return pot; + } + + function spot() external returns (address) { + return spot; + } + + function cure() external returns (address) { + return cure; + } + + function live() external returns (uint256) { + return live; + } + + function when() external returns (uint256) { + return when; + } + + function wait() external returns (uint256) { + return wait; + } + + function debt() external returns (uint256) { + return debt; + } + + function tag(bytes32 arg0) external returns (uint256) { + return tag[arg0]; + } + + function gap(bytes32 arg0) external returns (uint256) { + return gap[arg0]; + } + + function Art(bytes32 arg0) external returns (uint256) { + return Art[arg0]; + } + + function fix(bytes32 arg0) external returns (uint256) { + return fix[arg0]; + } + + function bag(address arg0) external returns (uint256) { + return bag[arg0]; + } + + function out(bytes32 arg0, address arg1) external returns (uint256) { + return out[arg0][arg1]; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 1; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function file(bytes32 what, address data) external { + require(wards[msg.sender] == 1); + require(live == 1); + if (what == bytes32(0x7661740000000000000000000000000000000000000000000000000000000000)) { + vat = data; + } else if (what == bytes32(0x6361740000000000000000000000000000000000000000000000000000000000)) { + cat = data; + } else if (what == bytes32(0x646f670000000000000000000000000000000000000000000000000000000000)) { + dog = data; + } else if (what == bytes32(0x766f770000000000000000000000000000000000000000000000000000000000)) { + vow = data; + } else if (what == bytes32(0x706f740000000000000000000000000000000000000000000000000000000000)) { + pot = data; + } else if (what == bytes32(0x73706f7400000000000000000000000000000000000000000000000000000000)) { + spot = data; + } else if (what == bytes32(0x6375726500000000000000000000000000000000000000000000000000000000)) { + cure = data; + } else { + require(false); + } + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + require(live == 1); + if (what == bytes32(0x7761697400000000000000000000000000000000000000000000000000000000)) { + wait = data; + } else { + require(false); + } + } + + function cage() external { + require(wards[msg.sender] == 1); + require(live == 1); + live = 0; + when = block.timestamp; + require(vat.code.length > 0); + var _vatCage = vat.cage(); + require(cat.code.length > 0); + var _catCage = cat.cage(); + require(dog.code.length > 0); + var _dogCage = dog.cage(); + require(vow.code.length > 0); + var _vowCage = vow.cage(); + require(spot.code.length > 0); + var _spotCage = spot.cage(); + require(pot.code.length > 0); + var _potCage = pot.cage(); + require(cure.code.length > 0); + var _cureCage = cure.cage(); + } + + function cage(bytes32 ilk) external { + require(live == 0); + require(tag[ilk] == 0); + require(vat.code.length > 0); + var vatIlk = vat.vatIlks(ilk); + Art[ilk] = vatIlk.0; + require(spot.code.length > 0); + var spotIlk = spot.spotIlks{view}(ilk); + address pip = spotIlk.0; + require(spot.code.length > 0); + var parV = spot.par{view}(); + require(pip.code.length > 0); + var pipRead = pip.read{view}(); + var tagV = wdiv(parV, uint256(pipRead)); + tag[ilk] = tagV; + } + + function snip(bytes32 ilk, uint256 id) external { + require(tag[ilk] != 0); + require(dog.code.length > 0); + var dogIlk = dog.dogIlks(ilk); + address clip = dogIlk.0; + require(vat.code.length > 0); + var vatIlk = vat.vatIlks(ilk); + uint256 rate = vatIlk.1; + require(clip.code.length > 0); + var clipSale = clip.sales{view}(id); + uint256 tab = clipSale.1; + uint256 lot = clipSale.2; + address usr = clipSale.3; + require(vat.code.length > 0); + var _suck = vat.suck(vow, vow, tab); + require(clip.code.length > 0); + var _yank = clip.yank(id); + uint256 art = tab / rate; + var ArtNew = add(Art[ilk], art); + Art[ilk] = ArtNew; + require(lot < #int256Limit && art < #int256Limit); + require(vat.code.length > 0); + var _grab = vat.grab(ilk, usr, address(this), vow, int256(lot), int256(art)); + } + + function skip(bytes32 ilk, uint256 id) external { + require(tag[ilk] != 0); + require(cat.code.length > 0); + var catIlk = cat.catIlks(ilk); + address flip = catIlk.0; + require(vat.code.length > 0); + var vatIlk = vat.vatIlks(ilk); + uint256 rate = vatIlk.1; + require(flip.code.length > 0); + var flipBid = flip.bids{view}(id); + uint256 bid = flipBid.0; + uint256 lot = flipBid.1; + address usr = flipBid.5; + uint256 tab = flipBid.7; + require(vat.code.length > 0); + var _suck1 = vat.suck(vow, vow, tab); + require(vat.code.length > 0); + var _suck2 = vat.suck(vow, address(this), bid); + require(vat.code.length > 0); + var _hope = vat.hope(flip); + require(flip.code.length > 0); + var _yank = flip.yank(id); + uint256 art = tab / rate; + var ArtNew = add(Art[ilk], art); + Art[ilk] = ArtNew; + require(lot < #int256Limit && art < #int256Limit); + require(vat.code.length > 0); + var _grab = vat.grab(ilk, usr, address(this), vow, int256(lot), int256(art)); + } + + function skim(bytes32 ilk, address urn) external { + require(tag[ilk] != 0); + require(vat.code.length > 0); + var vatIlk = vat.vatIlks(ilk); + uint256 rate = vatIlk.1; + require(vat.code.length > 0); + var vatUrn = vat.urns(ilk, urn); + uint256 ink = vatUrn.0; + uint256 art = vatUrn.1; + var owe0 = rmul(art, rate); + var owe = rmul(owe0, tag[ilk]); + var wad = min(ink, owe); + var diff = sub(owe, wad); + var gapNew = add(gap[ilk], diff); + gap[ilk] = gapNew; + require(wad <= #int256Limit && art <= #int256Limit); + require(vat.code.length > 0); + var _grab = vat.grab(ilk, urn, address(this), vow, -int256(wad), -int256(art)); + } + + function free(bytes32 ilk) external { + require(live == 0); + require(vat.code.length > 0); + var vatUrn = vat.urns(ilk, msg.sender); + uint256 ink = vatUrn.0; + uint256 art = vatUrn.1; + require(art == 0); + require(ink <= #int256Limit); + require(vat.code.length > 0); + var _grab = vat.grab(ilk, msg.sender, msg.sender, vow, -int256(ink), 0); + } + + function thaw() external { + require(live == 0); + require(debt == 0); + require(vat.code.length > 0); + var vatDai = vat.dai{view}(vow); + require(vatDai == 0); + var deadline = add(when, wait); + require(block.timestamp >= deadline); + require(vat.code.length > 0); + var vatDebt = vat.debt(); + require(cure.code.length > 0); + var cureTell = cure.tell{view}(); + var debtNew = sub(vatDebt, cureTell); + debt = debtNew; + } + + function flow(bytes32 ilk) external { + require(debt != 0); + require(fix[ilk] == 0); + require(vat.code.length > 0); + var vatIlk = vat.vatIlks(ilk); + uint256 rate = vatIlk.1; + var wad0 = rmul(Art[ilk], rate); + var wad = rmul(wad0, tag[ilk]); + var num0 = sub(wad, gap[ilk]); + var num = mul(num0, #RAY); + uint256 den = debt / #RAY; + uint256 fixV = num / den; + fix[ilk] = fixV; + } + + function pack(uint256 wad) external { + require(debt != 0); + var amt = mul(wad, #RAY); + require(vat.code.length > 0); + var _move = vat.move(msg.sender, vow, amt); + var bagNew = add(bag[msg.sender], wad); + bag[msg.sender] = bagNew; + } + + function cash(bytes32 ilk, uint256 wad) external { + require(fix[ilk] != 0); + var amt = rmul(wad, fix[ilk]); + require(vat.code.length > 0); + var _flux = vat.flux(ilk, address(this), msg.sender, amt); + var outNew = add(out[ilk][msg.sender], wad); + out[ilk][msg.sender] = outNew; + require(outNew <= bag[msg.sender]); + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.End.contract := by rfl end Benchmarks.Dss.End.Syntax diff --git a/Benchmarks/Dss/End/Thaw.lean b/Benchmarks/Dss/End/Thaw.lean index a8da83a3..4f0d8f0b 100644 --- a/Benchmarks/Dss/End/Thaw.lean +++ b/Benchmarks/Dss/End/Thaw.lean @@ -730,10 +730,10 @@ theorem endThawVatWord_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} theorem endThawVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawVatWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endThawVatWord τ I) = ⟨0⟩ := by + (hzero : Reasoning.Theory.extCodeSizeWord σ (endThawVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endThawVatWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endThawVatWord σ I) have htarget : endThawVatWord σ I = endThawVatWord τ I := endThawVatWord_accountMapEquiv hAccounts @@ -742,12 +742,12 @@ theorem endThawVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execut theorem endThawVatCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endThawVatWord τ I) ≠ ⟨0⟩ := by + (hne : Reasoning.Theory.extCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endThawVatWord τ I) ≠ ⟨0⟩ := by intro hbad apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endThawVatWord σ I) have htarget : endThawVatWord σ I = endThawVatWord τ I := endThawVatWord_accountMapEquiv hAccounts @@ -760,7 +760,7 @@ theorem endThawVatAddr_eq_ofUInt256 (σ : AccountMap) (I : ExecutionEnv) : (accountAddress_ofUInt256_eq_ofNat_toNat (endThawVatWord σ I)).symm theorem endThawVatCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt256} - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawVatWord σ I) = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ (endThawVatWord σ I) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (endThawVatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by @@ -770,7 +770,7 @@ theorem endThawVatCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt25 (endThawVatAddr_eq_ofUInt256 σ I) hzero theorem endThawVatCode_pos_of_codeSize_ne {cA gh bl σ σ₀ A I} {g : UInt256} - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (endThawVatAddr σ I)).option 0 (fun acc => acc.code.size))).toNat := by @@ -787,10 +787,10 @@ theorem endThawCureWord_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} theorem endThawCureCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawCureWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endThawCureWord τ I) = ⟨0⟩ := by + (hzero : Reasoning.Theory.extCodeSizeWord σ (endThawCureWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endThawCureWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endThawCureWord σ I) have htarget : endThawCureWord σ I = endThawCureWord τ I := endThawCureWord_accountMapEquiv hAccounts @@ -799,12 +799,12 @@ theorem endThawCureCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execu theorem endThawCureCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawCureWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (endThawCureWord τ I) ≠ ⟨0⟩ := by + (hne : Reasoning.Theory.extCodeSizeWord σ (endThawCureWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (endThawCureWord τ I) ≠ ⟨0⟩ := by intro hbad apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (endThawCureWord σ I) have htarget : endThawCureWord σ I = endThawCureWord τ I := endThawCureWord_accountMapEquiv hAccounts @@ -1149,7 +1149,7 @@ theorem endThawX_daiCallReady {cA gh bl σ σ₀ A I} {g : Sat256} (hlive : endThawLiveWord σ I = ⟨0⟩) (hdebt : endThawDebtWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) (h : RD endBytecode I g (initState cA gh bl σ σ₀ g A I) endThawBodyPc [endThawReturnPc, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : @@ -1162,7 +1162,7 @@ theorem endThawX_daiCallReady {cA gh bl σ σ₀ A I} {g : Sat256} ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd4737⟩ := endThawX_daiExtcodesizeGuard hlive hdebt h obtain ⟨gasWord, k', C', rd4752⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4737⟩) (okPc := ⟨4749⟩) rd4737 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4737⟩) (okPc := ⟨4749⟩) rd4737 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1199,7 +1199,7 @@ theorem endThawX_daiPostStaticcall {cA gh bl σ σ₀ A I} {g : UInt256} (endThawDaiPostCallMem σ I out) (UInt256.ofNat 6) out (cA', σ') k' C' ∧ out.size < UInt256.size := by obtain ⟨cA', σ', z, out, Ain, callGas, k', C', hΘ, rd4753raw, hout⟩ := - RD.uniswapStaticcall h (by native_decide) hdepth + RD.solcStaticcall h (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨cA', σ', z, out, Ain, callGas, k', C', ?_, ?_, hout⟩ · simpa [initState] using hΘ @@ -1230,7 +1230,7 @@ theorem endThawX_daiStaticcallDepthLimit {cA gh bl σ σ₀ A I} {g : UInt256} (endThawDaiCalldataMem σ I solcFreePtrMem) (UInt256.ofNat 6) ByteArray.empty (cA, σ) k' C' := by obtain ⟨k', C', rd4753raw⟩ := - RD.uniswapStaticcallDepthLimit h (by native_decide) hdepth + RD.solcStaticcallDepthLimit h (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨k', C', ?_⟩ have hmin : (min endThawDaiOutSize (UInt256.ofNat ByteArray.empty.size)).toNat = 0 := by @@ -1255,7 +1255,7 @@ theorem endThawX_daiCallFailed {cA cA' gh bl σ σ' σ₀ A I} {g sel : UInt256} (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨4753⟩) (okPc := ⟨4769⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨4753⟩) (okPc := ⟨4769⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1275,7 +1275,7 @@ theorem endThawX_daiCallSucceeded {cA gh bl σ σ₀ A I} {g sel : UInt256} (endThawDaiEndPtr :: endThawDaiSelectorWord :: endThawVatWord σ I :: endThawReturnPc :: sel :: []) mem (UInt256.ofNat 6) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨4753⟩) (okPc := ⟨4769⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨4753⟩) (okPc := ⟨4769⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1353,7 +1353,7 @@ theorem endThawX_daiReturnDecodeShort {cA cA' gh bl σ σ' σ₀ A I} {g : Sat25 rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rdShort have rdFall := rdShort.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFall + exact RD.solcPush1Dup1Revert0 rdFall (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1451,7 +1451,7 @@ theorem endThawX_deadlineAddOverflow {cA cA' gh bl σ σ' σ₀ A I} have rd10104pre := evm_run rd10100 with [raw push2 ⟨10108⟩ (by native_decide) (by evm_ov)] have rd10104 := rd10104pre.jumpiNT (by native_decide) (by decide) (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rd10104 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd10104 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1668,7 +1668,7 @@ theorem endThawX_debtCallReady {cA cA' gh bl σ σ' σ₀ A I} (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endThawVatWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (endThawVatWord σ' I) ≠ ⟨0⟩) (h : RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4956⟩ [endThawReturnPc, sel] mem (UInt256.ofNat 6) out (cA', σ') k C) : ∃ gasWord k' C', RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨5031⟩ @@ -1777,7 +1777,7 @@ theorem endThawX_debtCallReady {cA cA' gh bl σ σ' σ₀ A I} convert rd5016norm using 1⟩ rcases rd5016 with ⟨_, _, rd5016ok⟩ obtain ⟨gasWord, k', C', rd5031⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨5016⟩) (okPc := ⟨5028⟩) rd5016ok + RD.solcExtcodesizeGuardOkGas (pc := ⟨5016⟩) (okPc := ⟨5028⟩) rd5016ok hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1790,7 +1790,7 @@ theorem endThawX_debtNoCode {cA cA' gh bl σ σ' σ₀ A I} (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endThawVatWord σ' I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (endThawVatWord σ' I) = ⟨0⟩) (h : RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4956⟩ [endThawReturnPc, sel] mem (UInt256.ofNat 6) out (cA', σ') k C) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by @@ -1886,7 +1886,7 @@ theorem endThawX_debtNoCode {cA cA' gh bl σ σ' σ₀ A I} rw [hvatMask] at rd5016norm convert rd5016norm using 1⟩ rcases rd5016 with ⟨_, _, rd5016zero⟩ - exact RD.uniswapExtcodesizeGuardMissing (okPc := ⟨5028⟩) rd5016zero + exact RD.solcExtcodesizeGuardMissing (okPc := ⟨5028⟩) rd5016zero hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1943,7 +1943,7 @@ theorem endThawX_debtCallFailed {cA cA' gh bl σ σTarget σ' σ₀ A I} {g : Sa mem (UInt256.ofNat 6) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨5032⟩) (okPc := ⟨5048⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨5032⟩) (okPc := ⟨5048⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1960,7 +1960,7 @@ theorem endThawX_debtCallSucceeded {cA cA' gh bl σ σTarget σ' σ₀ A I} {g : (endThawNoArgEndPtr :: endThawDebtSelectorWord :: endThawVatWord σTarget I :: ⟨5190⟩ :: endThawReturnPc :: sel :: []) mem (UInt256.ofNat 6) rdata (cA', σ') k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨5032⟩) (okPc := ⟨5048⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨5032⟩) (okPc := ⟨5048⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -2023,7 +2023,7 @@ theorem endThawX_tellCallReady {cA cA' gh bl σ σ' σ₀ A I} (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hdebtOut : debtOut.size < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endThawCureWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (endThawCureWord σ' I) ≠ ⟨0⟩) (h : RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨5073⟩ (endThawReturnWord debtOut :: ⟨5190⟩ :: endThawReturnPc :: sel :: []) (endThawNoArgPostCallMem endThawDebtSelectorWord mem debtOut) (UInt256.ofNat 6) @@ -2151,7 +2151,7 @@ theorem endThawX_tellCallReady {cA cA' gh bl σ σ' σ₀ A I} convert rd5129norm using 1⟩ rcases rd5129 with ⟨_, _, rd5129ok⟩ obtain ⟨gasWord, k', C', rd5144⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨5129⟩) (okPc := ⟨5141⟩) rd5129ok + RD.solcExtcodesizeGuardOkGas (pc := ⟨5129⟩) (okPc := ⟨5141⟩) rd5129ok hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -2165,7 +2165,7 @@ theorem endThawX_tellNoCode {cA cA' gh bl σ σ' σ₀ A I} (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hdebtOut : debtOut.size < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (endThawCureWord σ' I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (endThawCureWord σ' I) = ⟨0⟩) (h : RD endBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨5073⟩ (endThawReturnWord debtOut :: ⟨5190⟩ :: endThawReturnPc :: sel :: []) (endThawNoArgPostCallMem endThawDebtSelectorWord mem debtOut) (UInt256.ofNat 6) @@ -2279,7 +2279,7 @@ theorem endThawX_tellNoCode {cA cA' gh bl σ σ' σ₀ A I} rw [hcureMask] at rd5129norm convert rd5129norm using 1⟩ rcases rd5129 with ⟨_, _, rd5129zero⟩ - exact RD.uniswapExtcodesizeGuardMissing (okPc := ⟨5141⟩) rd5129zero + exact RD.solcExtcodesizeGuardMissing (okPc := ⟨5141⟩) rd5129zero hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2315,7 +2315,7 @@ theorem endThawX_tellPostStaticcall {cA cA' gh bl σ σ' σ₀ A I} {g : Sat256} (UInt256.ofNat 6) tellOut (cA'', σ'') k' C' ∧ tellOut.size < UInt256.size := by obtain ⟨cA'', σ'', z, tellOut, Ain, callGas, k', C', hΘ, rd5145raw, hout⟩ := - RD.uniswapStaticcall h (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall h (by native_decide) hdepth (by evm_ov) refine ⟨cA'', σ'', z, tellOut, Ain, callGas, k', C', ?_, ?_, hout⟩ · simpa [initState] using hΘ · have hmin := endThawNoArgWriteLen_eq (out := tellOut) hout @@ -2337,7 +2337,7 @@ theorem endThawX_tellCallFailed {cA cA' gh bl σ σTarget σ' σ₀ A I} {g : Sa mem (UInt256.ofNat 6) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev endBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨5145⟩) (okPc := ⟨5161⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨5145⟩) (okPc := ⟨5161⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2354,7 +2354,7 @@ theorem endThawX_tellCallSucceeded {cA cA' gh bl σ σTarget σ' σ₀ A I} {g : (endThawNoArgEndPtr :: endThawTellSelectorWord :: endThawCureWord σTarget I :: debtWord :: ⟨5190⟩ :: endThawReturnPc :: sel :: []) mem (UInt256.ofNat 6) rdata (cA', σ') k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨5145⟩) (okPc := ⟨5161⟩) h + exact RD.solcCallSuccessGuardOk (pc := ⟨5145⟩) (okPc := ⟨5161⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -2526,7 +2526,7 @@ theorem endThawX_daiNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} (hlive : endThawLiveWord σ I = ⟨0⟩) (hdebt : endThawDebtWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawVatWord σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endThawVatWord σ I) = ⟨0⟩) (h : RD endBytecode I g (initState cA gh bl σ σ₀ g A I) endThawBodyPc [endThawReturnPc, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : @@ -2688,7 +2688,7 @@ theorem endThawX_daiNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} hvatMask, hvowMask, u256_land_comm] using rd4737pre) have hcodeSizeGuard := hcodeSize rw [← hvatMask] at hcodeSizeGuard - exact RD.uniswapExtcodesizeGuardMissing (okPc := ⟨4749⟩) rd4737 + exact RD.solcExtcodesizeGuardMissing (okPc := ⟨4749⟩) rd4737 hcodeSizeGuard (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3002,7 +3002,7 @@ theorem endThawBodyReverts_daiNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hlive : endThawLiveWord σ I = ⟨0⟩) (hdebt : endThawDebtWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawVatWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (endThawVatWord σ I) = ⟨0⟩) : let evm0 := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I ExecTransitionBody config contract evm0 (∅ : Store) thawTransition.body .reverted := by intro evm0 @@ -3131,7 +3131,7 @@ theorem endThawBodyReverts_daiCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} (hlive : endThawLiveWord σ I = ⟨0⟩) (hdebt : endThawDebtWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endThawVatAddr σ I)) "dai" 0 @@ -3378,7 +3378,7 @@ theorem endThawBodyReverts_daiDecodeShort {cA gh bl σ σ₀ A I} {g : UInt256} (hlive : endThawLiveWord σ I = ⟨0⟩) (hdebt : endThawDebtWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endThawVatAddr σ I)) "dai" 0 @@ -3553,7 +3553,7 @@ theorem endThawBodyReverts_daiNonzero {cA gh bl σ σ₀ A I} {g : UInt256} (hlive : endThawLiveWord σ I = ⟨0⟩) (hdebt : endThawDebtWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endThawVatAddr σ I)) "dai" 0 @@ -3659,7 +3659,7 @@ theorem endThawBodyReverts_deadlineAddOverflow {cA gh bl σ σ₀ A I} {g : UInt (hlive : endThawLiveWord σ I = ⟨0⟩) (hdebt : endThawDebtWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endThawVatAddr σ I)) "dai" 0 @@ -3810,7 +3810,7 @@ theorem endThawBodyReverts_waitNotFinished {cA gh bl σ σ₀ A I} {g : UInt256} (hlive : endThawLiveWord σ I = ⟨0⟩) (hdebt : endThawDebtWord σ I = ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (endThawVatWord σ I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (endThawVatAddr σ I)) "dai" 0 @@ -4083,7 +4083,7 @@ theorem endThawTailReadyPrefix (evmDai : EVM.State) (out : ByteArray) theorem endThawVatCode_zero_of_state {evm : EVM.State} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endThawVatWord evm.accountMap evm.executionEnv) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (endThawVatAddr evm.accountMap evm.executionEnv)).option 0 @@ -4096,7 +4096,7 @@ theorem endThawVatCode_zero_of_state {evm : EVM.State} theorem endThawVatCode_pos_of_state {evm : EVM.State} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endThawVatWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (endThawVatAddr evm.accountMap evm.executionEnv)).option 0 @@ -4109,7 +4109,7 @@ theorem endThawVatCode_pos_of_state {evm : EVM.State} theorem endThawCureCode_zero_of_state {evm : EVM.State} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endThawCureWord evm.accountMap evm.executionEnv) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (endThawCureAddr evm.accountMap evm.executionEnv)).option 0 @@ -4122,7 +4122,7 @@ theorem endThawCureCode_zero_of_state {evm : EVM.State} theorem endThawCureCode_pos_of_state {evm : EVM.State} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endThawCureWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (endThawCureAddr evm.accountMap evm.executionEnv)).option 0 @@ -4161,7 +4161,7 @@ theorem endThawAssignDebt {locals : Store} (evm : EVM.State) (debtNew : UInt256) theorem endThawCheckedDebtNoCode (evm : EVM.State) (out : ByteArray) (deadline : UInt256) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endThawVatWord evm.accountMap evm.executionEnv) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endThawStoreDeadlineWord out deadline } evm (checkedExternalCallStmts (.storage vatRef) "debt" (.intLit 0) [] "vatDebt") @@ -4189,7 +4189,7 @@ theorem endThawCheckedDebtNoCode (evm : EVM.State) (out : ByteArray) theorem endThawCheckedDebtFailure {evm evm' : EVM.State} {out debtOut : ByteArray} {deadline : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endThawVatWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4227,7 +4227,7 @@ theorem endThawCheckedDebtFailure {evm evm' : EVM.State} {out debtOut : ByteArra theorem endThawCheckedDebtDecodeRevert {evm evm' : EVM.State} {out debtOut : ByteArray} {deadline : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endThawVatWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4266,7 +4266,7 @@ theorem endThawCheckedDebtDecodeRevert {evm evm' : EVM.State} {out debtOut : Byt theorem endThawCheckedDebtSuccess {evm evm' : EVM.State} {out debtOut : ByteArray} {deadline : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endThawVatWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4308,7 +4308,7 @@ theorem endThawCheckedDebtSuccess {evm evm' : EVM.State} {out debtOut : ByteArra theorem endThawCheckedTellNoCode (evm : EVM.State) (out debtOut : ByteArray) (deadline : UInt256) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endThawCureWord evm.accountMap evm.executionEnv) = ⟨0⟩) : ExecBlock config { contract := contract, locals := endThawStoreVatDebt out debtOut deadline } evm (checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" @@ -4336,7 +4336,7 @@ theorem endThawCheckedTellNoCode (evm : EVM.State) (out debtOut : ByteArray) theorem endThawCheckedTellFailure {evm evm' : EVM.State} {out debtOut tellOut : ByteArray} {deadline : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endThawCureWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4374,7 +4374,7 @@ theorem endThawCheckedTellFailure {evm evm' : EVM.State} theorem endThawCheckedTellDecodeRevert {evm evm' : EVM.State} {out debtOut tellOut : ByteArray} {deadline : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endThawCureWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -4413,7 +4413,7 @@ theorem endThawCheckedTellDecodeRevert {evm evm' : EVM.State} theorem endThawCheckedTellSuccess {evm evm' : EVM.State} {out debtOut tellOut : ByteArray} {deadline : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (endThawCureWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -5098,10 +5098,10 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rw [← hdebtCouple] exact hdebt by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (endThawVatWord σ_evm I) = + Reasoning.Theory.extCodeSizeWord σ_evm (endThawVatWord σ_evm I) = ⟨0⟩ · have hvatCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endThawVatWord σ_solm I) = ⟨0⟩ := endThawVatCodeSize_zero_accountMapEquiv hAccounts hvatCode have hbody : @@ -5114,10 +5114,10 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (endThawX_daiNoCode (g := Sat256.ofUInt256 g) hlive hdebt hvatCode hbodyReach) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (endThawVatWord σ_evm I) ≠ ⟨0⟩ := hvatCode have hvatCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (endThawVatWord σ_solm I) ≠ ⟨0⟩ := endThawVatCodeSize_ne_accountMapEquiv hAccounts hvatCodeNE obtain ⟨gasWord, _, _, hdaiReady⟩ := @@ -5373,12 +5373,12 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} simpa [checkedExternalCallStmts, endThawStoreVatDai, collapseReturns] using hblock by_cases hvatCodeDebt : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (endThawVatWord σ' I) = ⟨0⟩ · have hrev := endThawX_debtNoCode hmemDai hreadDai hvatCodeDebt rd4956 have hvatCodeDebtSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmDaiSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmDaiSolm.accountMap (endThawVatWord evmDaiSolm.accountMap evmDaiSolm.executionEnv) = ⟨0⟩ := by have htmp := @@ -5428,10 +5428,10 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simpa [evmSolm, evmDaiSolm] using hdaiBlock) htail exact hrev.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatCodeDebtNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (endThawVatWord σ' I) ≠ ⟨0⟩ := hvatCodeDebt have hvatCodeDebtSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmDaiSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmDaiSolm.accountMap (endThawVatWord evmDaiSolm.accountMap evmDaiSolm.executionEnv) ≠ ⟨0⟩ := by have htmp := @@ -5603,13 +5603,13 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} hvatCodeDebtSolmNE (by simpa using hcallDebtSolm) hloDebt by_cases hcureCode : - Reasoning.Theory.uniswapExtCodeSizeWord σDebt + Reasoning.Theory.extCodeSizeWord σDebt (endThawCureWord σDebt I) = ⟨0⟩ · have hrev := endThawX_tellNoCode hmemDai hreadDai hdebtOutSize hcureCode rd5073 have hcureCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmDebtSolm.accountMap (endThawCureWord evmDebtSolm.accountMap evmDebtSolm.executionEnv) = ⟨0⟩ := by @@ -5684,10 +5684,10 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simpa [evmSolm, evmDaiSolm] using hdaiBlock) htail exact hrev.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hcureCodeNE : - Reasoning.Theory.uniswapExtCodeSizeWord σDebt + Reasoning.Theory.extCodeSizeWord σDebt (endThawCureWord σDebt I) ≠ ⟨0⟩ := hcureCode have hcureCodeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord evmDebtSolm.accountMap (endThawCureWord evmDebtSolm.accountMap evmDebtSolm.executionEnv) ≠ ⟨0⟩ := by diff --git a/Benchmarks/Dss/ExponentialDecrease/Dispatch.lean b/Benchmarks/Dss/ExponentialDecrease/Dispatch.lean index 8373726e..1371b294 100644 --- a/Benchmarks/Dss/ExponentialDecrease/Dispatch.lean +++ b/Benchmarks/Dss/ExponentialDecrease/Dispatch.lean @@ -265,7 +265,7 @@ theorem stairstepNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} |>.selectorArmNotTakenAuto (stairstepArmsWellFormed 5 (by omega)) (heq0 5 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h98 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h98 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem stairstepX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} @@ -277,7 +277,7 @@ theorem stairstepX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem stairstepX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -300,7 +300,7 @@ theorem stairstepX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h98 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h98 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem stairstepX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} diff --git a/Benchmarks/Dss/ExponentialDecrease/Price.lean b/Benchmarks/Dss/ExponentialDecrease/Price.lean index 1dc3f568..e080461e 100644 --- a/Benchmarks/Dss/ExponentialDecrease/Price.lean +++ b/Benchmarks/Dss/ExponentialDecrease/Price.lean @@ -423,7 +423,7 @@ theorem stairstepPriceRmulRayOverflowReverts {cA σ I} {g : Sat256} {s0 : State} raw jumpdest (by native_decide) (by evm_ov), raw push2 ⟨1210⟩ (by native_decide) (by evm_ov), raw jumpiNT (by native_decide) rfl (by evm_ov)] - exact RD.uniswapPush1Dup1Revert0 rd1261pre + exact RD.solcPush1Dup1Revert0 rd1261pre (by native_decide) (by native_decide) (by native_decide) (by evm_ov) set_option maxHeartbeats 1000000 in @@ -565,7 +565,7 @@ theorem stairstepPriceRmulOverflowReverts {cA σ I} {g : Sat256} {s0 : State} raw jumpdest (by native_decide) (by evm_ov), raw push2 ⟨1210⟩ (by native_decide) (by evm_ov), raw jumpiNT (by native_decide) rfl (by evm_ov)] - exact RD.uniswapPush1Dup1Revert0 rd1261pre + exact RD.solcPush1Dup1Revert0 rd1261pre (by native_decide) (by native_decide) (by native_decide) (by evm_ov) set_option maxHeartbeats 1000000 in diff --git a/Benchmarks/Dss/ExponentialDecrease/RpowEVM.lean b/Benchmarks/Dss/ExponentialDecrease/RpowEVM.lean index 5774481c..2e9ac8d3 100644 --- a/Benchmarks/Dss/ExponentialDecrease/RpowEVM.lean +++ b/Benchmarks/Dss/ExponentialDecrease/RpowEVM.lean @@ -281,7 +281,7 @@ theorem RD.stairstepRpowLoopRevertXX have hcond : UInt256.isZero (UInt256.shiftRight x (⟨128⟩ : UInt256)) = ⟨0⟩ := isZero_eq_zero_of_ne (rpowShiftRight128_ne_zero_of_square_overflow x hover) have rdFallthrough := rd1110pre.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -328,7 +328,7 @@ theorem RD.stairstepRpowLoopRevertXXRound rw [hlt] native_decide have rdFallthrough := rd1126pre.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -479,7 +479,7 @@ theorem RD.stairstepRpowLoopRevertZX raw iszero (by native_decide) (by evm_ov), raw push2 ⟨1114⟩ (by native_decide) (by evm_ov)] have rdFallthrough := rd1164pre.jumpiNT (by native_decide) hmulGuardFail (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -571,7 +571,7 @@ theorem RD.stairstepRpowLoopRevertZXRound rw [hlt] native_decide have rdFallthrough := rd1180pre.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) diff --git a/Benchmarks/Dss/ExponentialDecrease/SpecSyntax.lean b/Benchmarks/Dss/ExponentialDecrease/SpecSyntax.lean index ecf7eef8..40634efd 100644 --- a/Benchmarks/Dss/ExponentialDecrease/SpecSyntax.lean +++ b/Benchmarks/Dss/ExponentialDecrease/SpecSyntax.lean @@ -2,19 +2,98 @@ import Benchmarks.Dss.ExponentialDecrease.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS ExponentialDecrease spec through the Solm notation frontend +# ExponentialDecrease spec in the Solidity-faithful Solm frontend -The main spec lives in `Spec.lean`; this companion keeps the benchmark's notation-side check wired -up as the body surface grows. +The whole `abaci.sol` `ExponentialDecrease` spec (including the `rpow` while-loop) written with +`solidity%` and proven definitionally equal to the AST spec in `Spec.lean`. Checked-math helpers +are inlined as surface statements; `"cut"` is the big-endian `bytes32` literal; `#RAY` is the +spec's `RAY` constant. Transition order matches `contract.transitions` (selector order). -/ -open Solm Solm.Notation +open Solm Solm.Notation Benchmarks.Dss.ExponentialDecrease namespace Benchmarks.Dss.ExponentialDecrease.Syntax -def contractSyntax : ContractDecl := Benchmarks.Dss.ExponentialDecrease.contract +def contractSyntax : ContractDecl := solidity% contract ExponentialDecrease { + mapping(address => uint256) wards; + uint256 cut; -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.ExponentialDecrease.contract := by - rfl + constructor() { + wards[msg.sender] = 1; + } + + function rmul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + z = z / #RAY; + return z; + } + + function rpow(uint256 x, uint256 n, uint256 b) internal returns (uint256) { + if (n == 0) { + return b; + } else { + if (x == 0) { + return 0; + } else { + uint256 z = n % 2 == 0 ? b : x; + uint256 half = b / 2; + n = n / 2; + while (n != 0) { + uint256 xx = (x * x) as uint256; + require(x == 0 || xx / x == x); + uint256 xxRound = (xx + half) as uint256; + require(xxRound >= xx); + x = xxRound / b; + if (n % 2 != 0) { + uint256 zx = (z * x) as uint256; + require(x == 0 || zx / x == z); + uint256 zxRound = (zx + half) as uint256; + require(zxRound >= zx); + z = zxRound / b; + } + n = n / 2; + } + return z; + } + } + } + + function cut() external returns (uint256) { + return cut; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x6375740000000000000000000000000000000000000000000000000000000000)) { + cut = data; + require(data <= #RAY); + } else { + require(false); + } + } + + function price(uint256 top, uint256 dur) external returns (uint256) { + var pow = rpow(cut, dur, #RAY); + var out = rmul(top, pow); + return out; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 1; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.ExponentialDecrease.contract := by rfl end Benchmarks.Dss.ExponentialDecrease.Syntax diff --git a/Benchmarks/Dss/Flapper/Cage.lean b/Benchmarks/Dss/Flapper/Cage.lean index 6f5ebc20..f29e00ab 100644 --- a/Benchmarks/Dss/Flapper/Cage.lean +++ b/Benchmarks/Dss/Flapper/Cage.lean @@ -447,7 +447,7 @@ theorem flapperCageX_toMoveExtcodesizeGuard raw dup2 (by native_decide) (by evm_ov), raw mstore 6 (Benchmarks.Dss.Flopper.dentMoveSelectorMem mem0) (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - raw uniswapAddress (by native_decide) (by evm_ov), + raw address (by native_decide) (by evm_ov), raw push1 ⟨4⟩ (by native_decide) (by evm_ov), raw dup3 (by native_decide) (by evm_ov), raw add (by native_decide) (by evm_ov), @@ -541,7 +541,7 @@ theorem flapperCageX_toMoveExtcodesizeGuard theorem flapperCageX_moveNoCode {cA gh bl σStart σ σ₀ A I} {g : Sat256} {sel : UInt256} {k C : ℕ} - (hnoCode : Reasoning.Theory.uniswapExtCodeSizeWord σ (cageVatWord σ I) = ⟨0⟩) + (hnoCode : Reasoning.Theory.extCodeSizeWord σ (cageVatWord σ I) = ⟨0⟩) (rd3207 : RD flapperBytecode I g (initState cA gh bl σStart σ₀ g A I) ⟨3207⟩ [⟨0⟩, cageRadWord I, ⟨360⟩, sel] @@ -549,7 +549,7 @@ theorem flapperCageX_moveNoCode (cA, σ) k C) : RDrev flapperBytecode g (initState cA gh bl σStart σ₀ g A I) := by obtain ⟨_, _, rd3277⟩ := flapperCageX_toMoveExtcodesizeGuard rd3207 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3277⟩) (okPc := ⟨3289⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3277⟩) (okPc := ⟨3289⟩) rd3277 hnoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -559,7 +559,7 @@ theorem flapperCageX_moveCall {cA gh bl σStart σ σ₀ A I} {g : Sat256} {sel : UInt256} {k C : ℕ} (hperm : I.perm = true) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (cageVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (cageVatWord σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd3207 : RD flapperBytecode I g (initState cA gh bl σStart σ₀ g A I) ⟨3207⟩ @@ -603,7 +603,7 @@ theorem flapperCageX_moveCall simpa [guy, cageSenderWord, solcSourceWord] using solcSource_ofNat I obtain ⟨_, _, rd3277⟩ := flapperCageX_toMoveExtcodesizeGuard rd3207 obtain ⟨gasWord, _, _, rd3292⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3277⟩) (okPc := ⟨3289⟩) rd3277 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3277⟩) (okPc := ⟨3289⟩) rd3277 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -645,7 +645,7 @@ theorem flapperCageX_moveCall theorem flapperCageX_moveCallDepthLimit {cA gh bl σStart σ σ₀ A I} {g : Sat256} {sel : UInt256} {k C : ℕ} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (cageVatWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (cageVatWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (rd3207 : RD flapperBytecode I g (initState cA gh bl σStart σ₀ g A I) ⟨3207⟩ @@ -663,7 +663,7 @@ theorem flapperCageX_moveCallDepthLimit intro src guy rad vat obtain ⟨_, _, rd3277⟩ := flapperCageX_toMoveExtcodesizeGuard rd3207 obtain ⟨gasWord, _, _, rd3292⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3277⟩) (okPc := ⟨3289⟩) rd3277 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3277⟩) (okPc := ⟨3289⟩) rd3277 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -694,7 +694,7 @@ theorem flapperCageX_moveCallFailure mem aw out (cA', σ') k C) (houtSize : out.size < UInt256.size) : RDrev flapperBytecode g (initState cA gh bl σStart σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3293⟩) (okPc := ⟨3309⟩) rd3293 + exact RD.solcCallSuccessGuardMissing (pc := ⟨3293⟩) (okPc := ⟨3309⟩) rd3293 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -712,7 +712,7 @@ theorem flapperCageX_moveCallSuccess RDret flapperBytecode g (initState cA gh bl σStart σ₀ g A I) (cA', σ') ByteArray.empty := by obtain ⟨k3311, C3311, rd3311raw⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨3293⟩) (okPc := ⟨3309⟩) rd3293 + RD.solcCallSuccessGuardOk (pc := ⟨3293⟩) (okPc := ⟨3309⟩) rd3293 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -745,12 +745,12 @@ theorem cageAddressReturnWord_accountMapEquiv {σ τ : AccountMap} {I : Executio theorem cageCodeSize_ne_accountMapEquiv_addressSlot {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (slot : UInt256) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flapperAddressReturnWord slot σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flapperAddressReturnWord slot τ I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (flapperAddressReturnWord slot σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (flapperAddressReturnWord slot τ I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (flapperAddressReturnWord slot σ I) have htarget : flapperAddressReturnWord slot σ I = flapperAddressReturnWord slot τ I := @@ -761,10 +761,10 @@ theorem cageCodeSize_ne_accountMapEquiv_addressSlot {σ τ : AccountMap} theorem cageCodeSize_zero_accountMapEquiv_addressSlot {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (slot : UInt256) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flapperAddressReturnWord slot σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flapperAddressReturnWord slot τ I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (flapperAddressReturnWord slot σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (flapperAddressReturnWord slot τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (flapperAddressReturnWord slot σ I) have htarget : flapperAddressReturnWord slot σ I = flapperAddressReturnWord slot τ I := @@ -890,7 +890,7 @@ theorem flapperCageBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) (hauth : Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (relyAuthStorageSlot I) = ⟨1⟩) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostState evm).accountMap + Reasoning.Theory.extCodeSizeWord (cageLivePostState evm).accountMap (flapperAddressReturnWord ⟨2⟩ (cageLivePostState evm).accountMap (cageLivePostState evm).executionEnv) = ⟨0⟩) : ExecTransitionBody config contract evm (cageLocals I) cageTransition.body .reverted := by @@ -950,7 +950,7 @@ theorem flapperCageBodyReverts_moveCallFailure (hauth : Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (relyAuthStorageSlot I) = ⟨1⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostState evm).accountMap + Reasoning.Theory.extCodeSizeWord (cageLivePostState evm).accountMap (flapperAddressReturnWord ⟨2⟩ (cageLivePostState evm).accountMap (cageLivePostState evm).executionEnv) ≠ ⟨0⟩) (hcall : @@ -1020,7 +1020,7 @@ theorem flapperCageBodyReturns_moveCallSuccess (hauth : Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (relyAuthStorageSlot I) = ⟨1⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostState evm).accountMap + Reasoning.Theory.extCodeSizeWord (cageLivePostState evm).accountMap (flapperAddressReturnWord ⟨2⟩ (cageLivePostState evm).accountMap (cageLivePostState evm).executionEnv) ≠ ⟨0⟩) (hcall : @@ -1129,7 +1129,7 @@ theorem flapperCageBodyCoreMoveNoCode (hsz36 : 36 ≤ I.calldata.size) (hauth : relyAuthWord σ_evm I = ⟨1⟩) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostAccountMap I σ_evm) + Reasoning.Theory.extCodeSizeWord (cageLivePostAccountMap I σ_evm) (cageVatWord (cageLivePostAccountMap I σ_evm) I) = ⟨0⟩) (hdispatch : dispatchMsg contract I.calldata = some cageTransition) (hdecode : @@ -1150,12 +1150,12 @@ theorem flapperCageBodyCoreMoveNoCode accountMapEquiv (cageLivePostAccountMap I σ_evm) (cageLivePostAccountMap I σ_solm) := accountMapEquiv_sstoreAccountMap I.codeOwner ⟨7⟩ ⟨0⟩ hAccounts have hnoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostAccountMap I σ_solm) + Reasoning.Theory.extCodeSizeWord (cageLivePostAccountMap I σ_solm) (flapperAddressReturnWord ⟨2⟩ (cageLivePostAccountMap I σ_solm) I) = ⟨0⟩ := by simpa [cageVatWord] using cageCodeSize_zero_accountMapEquiv_addressSlot hAccountsLive ⟨2⟩ hnoCode have hnoCodePost : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostState evmSolm).accountMap + Reasoning.Theory.extCodeSizeWord (cageLivePostState evmSolm).accountMap (flapperAddressReturnWord ⟨2⟩ (cageLivePostState evmSolm).accountMap (cageLivePostState evmSolm).executionEnv) = ⟨0⟩ := by simpa [evmSolm, cageLivePostState, cageLivePostAccountMap, initState, @@ -1188,7 +1188,7 @@ theorem flapperCageBodyCoreMoveCallDepthLimit (hsz36 : 36 ≤ I.calldata.size) (hauth : relyAuthWord σ_evm I = ⟨1⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostAccountMap I σ_evm) + Reasoning.Theory.extCodeSizeWord (cageLivePostAccountMap I σ_evm) (cageVatWord (cageLivePostAccountMap I σ_evm) I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hdispatch : dispatchMsg contract I.calldata = some cageTransition) @@ -1252,11 +1252,11 @@ theorem flapperCageBodyCoreMoveCallDepthLimit accountMapEquiv (cageLivePostAccountMap I σ_evm) (cageLivePostAccountMap I σ_solm) := accountMapEquiv_sstoreAccountMap I.codeOwner ⟨7⟩ ⟨0⟩ hAccounts have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmLiveSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmLiveSolm.accountMap (flapperAddressReturnWord ⟨2⟩ evmLiveSolm.accountMap evmLiveSolm.executionEnv) ≠ ⟨0⟩ := by have hcodeSizeSolmMap : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostAccountMap I σ_solm) + Reasoning.Theory.extCodeSizeWord (cageLivePostAccountMap I σ_solm) (flapperAddressReturnWord ⟨2⟩ (cageLivePostAccountMap I σ_solm) I) ≠ ⟨0⟩ := by simpa [cageVatWord] using cageCodeSize_ne_accountMapEquiv_addressSlot hAccountsLive ⟨2⟩ hcodeSize @@ -1293,7 +1293,7 @@ theorem flapperCageBodyCoreMoveCallFailure (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) (hauth : relyAuthWord σ_evm I = ⟨1⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostAccountMap I σ_evm) + Reasoning.Theory.extCodeSizeWord (cageLivePostAccountMap I σ_evm) (cageVatWord (cageLivePostAccountMap I σ_evm) I) ≠ ⟨0⟩) (rd3293 : RD flapperBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨3293⟩ @@ -1373,11 +1373,11 @@ theorem flapperCageBodyCoreMoveCallFailure rw [← hword] exact hauth have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmLiveSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmLiveSolm.accountMap (flapperAddressReturnWord ⟨2⟩ evmLiveSolm.accountMap evmLiveSolm.executionEnv) ≠ ⟨0⟩ := by have hcodeSizeSolmMap : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostAccountMap I σ_solm) + Reasoning.Theory.extCodeSizeWord (cageLivePostAccountMap I σ_solm) (flapperAddressReturnWord ⟨2⟩ (cageLivePostAccountMap I σ_solm) I) ≠ ⟨0⟩ := by simpa [cageVatWord] using cageCodeSize_ne_accountMapEquiv_addressSlot hAccountsLiveMap ⟨2⟩ hcodeSize @@ -1405,7 +1405,7 @@ theorem flapperCageBodyCoreMoveCallSuccess (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) (hauth : relyAuthWord σ_evm I = ⟨1⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostAccountMap I σ_evm) + Reasoning.Theory.extCodeSizeWord (cageLivePostAccountMap I σ_evm) (cageVatWord (cageLivePostAccountMap I σ_evm) I) ≠ ⟨0⟩) (rd3293 : RD flapperBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨3293⟩ @@ -1484,11 +1484,11 @@ theorem flapperCageBodyCoreMoveCallSuccess rw [← hword] exact hauth have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmLiveSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmLiveSolm.accountMap (flapperAddressReturnWord ⟨2⟩ evmLiveSolm.accountMap evmLiveSolm.executionEnv) ≠ ⟨0⟩ := by have hcodeSizeSolmMap : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostAccountMap I σ_solm) + Reasoning.Theory.extCodeSizeWord (cageLivePostAccountMap I σ_solm) (flapperAddressReturnWord ⟨2⟩ (cageLivePostAccountMap I σ_solm) I) ≠ ⟨0⟩ := by simpa [cageVatWord] using cageCodeSize_ne_accountMapEquiv_addressSlot hAccountsLiveMap ⟨2⟩ hcodeSize @@ -1549,12 +1549,12 @@ theorem flapperCageBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} · have hdecode := flapperDecode_cage_ok (I := I) hsz36 by_cases hauth : relyAuthWord σ_evm I = ⟨1⟩ · by_cases hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostAccountMap I σ_evm) + Reasoning.Theory.extCodeSizeWord (cageLivePostAccountMap I σ_evm) (cageVatWord (cageLivePostAccountMap I σ_evm) I) = ⟨0⟩ · exact flapperCageBodyCoreMoveNoCode hcode hsize hperm hwv hsz36 hauth hnoCode hdispatch hdecode hreach hAccounts · have hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (cageLivePostAccountMap I σ_evm) + Reasoning.Theory.extCodeSizeWord (cageLivePostAccountMap I σ_evm) (cageVatWord (cageLivePostAccountMap I σ_evm) I) ≠ ⟨0⟩ := hnoCode by_cases hdepthEq : I.depth = 1024 · exact flapperCageBodyCoreMoveCallDepthLimit hcode hsize hperm hwv hsz36 diff --git a/Benchmarks/Dss/Flapper/Deal.lean b/Benchmarks/Dss/Flapper/Deal.lean index 77d5d466..791e1e16 100644 --- a/Benchmarks/Dss/Flapper/Deal.lean +++ b/Benchmarks/Dss/Flapper/Deal.lean @@ -1412,7 +1412,7 @@ theorem flapperDealBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) (dealTicWord evm I).toNat < (dealTimestampWord evm).toNat ∨ (dealEndWord evm I).toNat < (dealTimestampWord evm).toNat) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dealVatWord evm) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord evm.accountMap (dealVatWord evm) = ⟨0⟩) : ExecTransitionBody config contract evm (dealLocals I) dealTransition.body .reverted := by have hvat := evalExpr_deal_vat_storage_of_locals evm (dealLotLocals evm I) @@ -1478,7 +1478,7 @@ theorem flapperDealBodyReverts_moveCallFailure (dealTicWord evm I).toNat < (dealTimestampWord evm).toNat ∨ (dealEndWord evm I).toNat < (dealTimestampWord evm).toNat) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dealVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dealVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dealVatWord evm).toNat)) @@ -1553,7 +1553,7 @@ theorem flapperDealBodyReverts_burnNoCode (dealTicWord evm I).toNat < (dealTimestampWord evm).toNat ∨ (dealEndWord evm I).toNat < (dealTimestampWord evm).toNat) (hmoveCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dealVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dealVatWord evm) ≠ ⟨0⟩) (hmoveCall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dealVatWord evm).toNat)) @@ -1563,7 +1563,7 @@ theorem flapperDealBodyReverts_burnNoCode .int (Int.ofNat (dealLotWord evm I).toNat)] (true, evmMove, outMove) true) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dealGemWord evmMove) = ⟨0⟩) : ExecTransitionBody config contract evm (dealLocals I) dealTransition.body .reverted := by have hvat := @@ -1658,7 +1658,7 @@ theorem flapperDealBodyReverts_burnCallFailure (dealTicWord evm I).toNat < (dealTimestampWord evm).toNat ∨ (dealEndWord evm I).toNat < (dealTimestampWord evm).toNat) (hmoveCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dealVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dealVatWord evm) ≠ ⟨0⟩) (hmoveCall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dealVatWord evm).toNat)) @@ -1668,7 +1668,7 @@ theorem flapperDealBodyReverts_burnCallFailure .int (Int.ofNat (dealLotWord evm I).toNat)] (true, evmMove, outMove) true) (hburnCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dealGemWord evmMove) ≠ ⟨0⟩) (hburnCall : typedCallViaEVM config evmMove @@ -1765,7 +1765,7 @@ theorem flapperDealBodyBurnSuccessPrefix (evm evmMove evmBurn : EVM.State) (I : ExecutionEnv) (outMove outBurn : ByteArray) (hmoveCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dealVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dealVatWord evm) ≠ ⟨0⟩) (hmoveCall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dealVatWord evm).toNat)) @@ -1775,7 +1775,7 @@ theorem flapperDealBodyBurnSuccessPrefix .int (Int.ofNat (dealLotWord evm I).toNat)] (true, evmMove, outMove) true) (hburnCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dealGemWord evmMove) ≠ ⟨0⟩) (hburnCall : typedCallViaEVM config evmMove @@ -1856,7 +1856,7 @@ theorem flapperDealBodyReverts_fillSubUnderflow (dealTicWord evm I).toNat < (dealTimestampWord evm).toNat ∨ (dealEndWord evm I).toNat < (dealTimestampWord evm).toNat) (hmoveCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dealVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dealVatWord evm) ≠ ⟨0⟩) (hmoveCall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dealVatWord evm).toNat)) @@ -1866,7 +1866,7 @@ theorem flapperDealBodyReverts_fillSubUnderflow .int (Int.ofNat (dealLotWord evm I).toNat)] (true, evmMove, outMove) true) (hburnCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dealGemWord evmMove) ≠ ⟨0⟩) (hburnCall : typedCallViaEVM config evmMove @@ -1949,7 +1949,7 @@ theorem flapperDealBodyReturns_success (dealTicWord evm I).toNat < (dealTimestampWord evm).toNat ∨ (dealEndWord evm I).toNat < (dealTimestampWord evm).toNat) (hmoveCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dealVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dealVatWord evm) ≠ ⟨0⟩) (hmoveCall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dealVatWord evm).toNat)) @@ -1959,7 +1959,7 @@ theorem flapperDealBodyReturns_success .int (Int.ofNat (dealLotWord evm I).toNat)] (true, evmMove, outMove) true) (hburnCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dealGemWord evmMove) ≠ ⟨0⟩) (hburnCall : typedCallViaEVM config evmMove @@ -2996,7 +2996,7 @@ theorem flapperDealX_toMoveExtcodesizeGuard raw dup2 (by native_decide) (by evm_ov), raw mstore 6 (yankMoveSelectorMem memMap) (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - raw uniswapAddress (by native_decide) (by evm_ov), + raw address (by native_decide) (by evm_ov), raw push1 ⟨4⟩ (by native_decide) (by evm_ov), raw dup3 (by native_decide) (by evm_ov), raw add (by native_decide) (by evm_ov), @@ -3094,7 +3094,7 @@ theorem flapperDealX_moveNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt (flapperUint48Offset26Word (auctionPackedSlot (dealIdWord I)) σ I).toNat < (UInt256.ofNat I.header.timestamp).toNat) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flapperAddressReturnWord ⟨2⟩ σ I) = + Reasoning.Theory.extCodeSizeWord σ (flapperAddressReturnWord ⟨2⟩ σ I) = ⟨0⟩) (rd3408 : ∃ k C, RD flapperBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3408⟩ @@ -3105,7 +3105,7 @@ theorem flapperDealX_moveNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt flapperDealX_readyToMove (g := g) htic hfinished rd3408 obtain ⟨_, _, rd3699⟩ := flapperDealX_toMoveExtcodesizeGuard hmemStart hread64Start rd3601 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3699⟩) (okPc := ⟨3711⟩) rd3699 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3699⟩) (okPc := ⟨3711⟩) rd3699 hnoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3115,7 +3115,7 @@ theorem flapperDealX_moveCall {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} (hperm : I.perm = true) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flapperAddressReturnWord ⟨2⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (flapperAddressReturnWord ⟨2⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (htic : flapperUint48Offset20Word (auctionPackedSlot (dealIdWord I)) σ I ≠ ⟨0⟩) @@ -3179,7 +3179,7 @@ theorem flapperDealX_moveCall obtain ⟨_, _, rd3699⟩ := flapperDealX_toMoveExtcodesizeGuard hmemStart hread64Start rd3601 obtain ⟨gasWord, _, _, rd3714⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3699⟩) (okPc := ⟨3711⟩) rd3699 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3699⟩) (okPc := ⟨3711⟩) rd3699 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -3221,7 +3221,7 @@ theorem flapperDealX_moveCall theorem flapperDealX_moveCallDepthLimit {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flapperAddressReturnWord ⟨2⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (flapperAddressReturnWord ⟨2⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (htic : flapperUint48Offset20Word (auctionPackedSlot (dealIdWord I)) σ I ≠ ⟨0⟩) @@ -3250,7 +3250,7 @@ theorem flapperDealX_moveCallDepthLimit obtain ⟨_, _, rd3699⟩ := flapperDealX_toMoveExtcodesizeGuard hmemStart hread64Start rd3601 obtain ⟨gasWord, _, _, rd3714⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3699⟩) (okPc := ⟨3711⟩) rd3699 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3699⟩) (okPc := ⟨3711⟩) rd3699 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -3282,7 +3282,7 @@ theorem flapperDealX_moveCallFailure mem (UInt256.ofNat 8) out (cA', σ') k C) (houtSize : out.size < UInt256.size) : RDrev flapperBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3715⟩) (okPc := ⟨3731⟩) rd3715 + exact RD.solcCallSuccessGuardMissing (pc := ⟨3715⟩) (okPc := ⟨3731⟩) rd3715 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3356,7 +3356,7 @@ theorem flapperDealX_toBurnExtcodesizeGuard ⟨128⟩ := mloadFreePtrValue (by rw [hcallMem]; decide) (by decide) hcallRead64 obtain ⟨k3733, C3733, rd3733raw⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨3715⟩) (okPc := ⟨3731⟩) rd3715 + RD.solcCallSuccessGuardOk (pc := ⟨3715⟩) (okPc := ⟨3731⟩) rd3715 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -3452,7 +3452,7 @@ theorem flapperDealX_toBurnExtcodesizeGuard rw [show (⟨128⟩ : UInt256).toNat = 128 from by native_decide] simp [dealBurnSelectorMem, hselShift]) (by native_decide) (by evm_ov), - raw uniswapAddress (by native_decide) (by evm_ov), + raw address (by native_decide) (by evm_ov), raw push1 ⟨4⟩ (by native_decide) (by evm_ov), raw dup3 (by native_decide) (by evm_ov), raw add (by native_decide) (by evm_ov), @@ -3532,7 +3532,7 @@ theorem flapperDealX_burnNoCode {cA cA' gh bl σ σ₀ σ' A I} {g : Sat256} {sel : UInt256} {mem out : ByteArray} {k C : ℕ} (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (flapperAddressReturnWord ⟨3⟩ σ' I) = + Reasoning.Theory.extCodeSizeWord σ' (flapperAddressReturnWord ⟨3⟩ σ' I) = ⟨0⟩) (hmem : mem.size = 228) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) @@ -3545,7 +3545,7 @@ theorem flapperDealX_burnNoCode RDrev flapperBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd3816⟩ := flapperDealX_toBurnExtcodesizeGuard hmem hread64 rd3715 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3816⟩) (okPc := ⟨3828⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3816⟩) (okPc := ⟨3828⟩) rd3816 hnoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3556,7 +3556,7 @@ theorem flapperDealX_burnCall {mem out : ByteArray} {k C : ℕ} (hperm : I.perm = true) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (flapperAddressReturnWord ⟨3⟩ σ' I) ≠ + Reasoning.Theory.extCodeSizeWord σ' (flapperAddressReturnWord ⟨3⟩ σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hmem : mem.size = 228) @@ -3622,7 +3622,7 @@ theorem flapperDealX_burnCall obtain ⟨_, _, rd3816⟩ := flapperDealX_toBurnExtcodesizeGuard hmem hread64 rd3715 obtain ⟨gasWord, _, _, rd3831⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3816⟩) (okPc := ⟨3828⟩) rd3816 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3816⟩) (okPc := ⟨3828⟩) rd3816 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -3672,7 +3672,7 @@ theorem flapperDealX_burnCallFailure mem (UInt256.ofNat 8) out (cA', σ') k C) (houtSize : out.size < UInt256.size) : RDrev flapperBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3832⟩) (okPc := ⟨3848⟩) rd3832 + exact RD.solcCallSuccessGuardMissing (pc := ⟨3832⟩) (okPc := ⟨3848⟩) rd3832 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3834,7 +3834,7 @@ theorem flapperDealX_burnCallSuccessFill ByteArray.empty := by intro id lot σDel fill obtain ⟨k3850, C3850, rd3850raw⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨3832⟩) (okPc := ⟨3848⟩) rd3832 + RD.solcCallSuccessGuardOk (pc := ⟨3832⟩) (okPc := ⟨3848⟩) rd3832 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -3900,7 +3900,7 @@ theorem flapperDealX_fillSubUnderflow let σDel := auctionRuntimeDeleteAccountMap I.codeOwner id σBurn let fill := flapperSlotWord ⟨9⟩ σDel I obtain ⟨k3850, C3850, rd3850raw⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨3832⟩) (okPc := ⟨3848⟩) rd3832 + RD.solcCallSuccessGuardOk (pc := ⟨3832⟩) (okPc := ⟨3848⟩) rd3832 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -3938,7 +3938,7 @@ theorem flapperDealX_fillSubUnderflow have rd4974 := rd4971pre.push2 ⟨4930⟩ (by native_decide) (by evm_ov) have rd4975 := rd4974.jumpiNT (by native_decide) rfl (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rd4975 + exact RD.solcPush1Dup1Revert0 rd4975 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -4094,7 +4094,7 @@ theorem flapperDealBodyCoreMoveNoCode (flapperUint48Offset26Word (auctionPackedSlot (dealIdWord I)) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨2⟩ σ_evm I) = ⟨0⟩) (hdispatch : dispatchMsg contract I.calldata = some dealTransition) (hdecode : @@ -4130,7 +4130,7 @@ theorem flapperDealBodyCoreMoveNoCode right simpa [evmSolm, initState, dealEndWord, dealTimestampWord, hendEq] using h have hnoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flapperAddressReturnWord ⟨2⟩ σ_solm I) = ⟨0⟩ := flapperCodeSize_zero_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hnoCode have hbody : @@ -4163,7 +4163,7 @@ theorem flapperDealBodyCoreMoveCallFailure (flapperUint48Offset26Word (auctionPackedSlot (dealIdWord I)) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (rd3715 : RD flapperBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨3715⟩ @@ -4248,7 +4248,7 @@ theorem flapperDealBodyCoreMoveCallFailure right simpa [evmSolm, initState, dealEndWord, dealTimestampWord, hendEq] using h have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flapperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flapperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hbody : @@ -4277,7 +4277,7 @@ theorem flapperDealBodyCoreMoveCallDepthLimit (flapperUint48Offset26Word (auctionPackedSlot (dealIdWord I)) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hdispatch : dispatchMsg contract I.calldata = some dealTransition) @@ -4354,7 +4354,7 @@ theorem flapperDealBodyCoreMoveCallDepthLimit right simpa [evmSolm, initState, dealEndWord, dealTimestampWord, hendEq] using h have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flapperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flapperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hbody : @@ -4391,7 +4391,7 @@ theorem flapperDealBodyCoreBurnNoCode (flapperUint48Offset26Word (auctionPackedSlot (dealIdWord I)) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat) (hmoveCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (rd3715 : RD flapperBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨3715⟩ @@ -4416,7 +4416,7 @@ theorem flapperDealBodyCoreBurnNoCode accountMap := σMove, substate := AMove, createdAccounts := cA' }, outMove) true) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σMove + Reasoning.Theory.extCodeSizeWord σMove (flapperAddressReturnWord ⟨3⟩ σMove I) = ⟨0⟩) (hmem : mem.size = 228) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) @@ -4479,11 +4479,11 @@ theorem flapperDealBodyCoreBurnNoCode right simpa [evmSolm, initState, dealEndWord, dealTimestampWord, hendEq] using h have hmoveCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flapperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flapperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hmoveCodeSize have hnoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σMoveSolm + Reasoning.Theory.extCodeSizeWord σMoveSolm (flapperAddressReturnWord ⟨3⟩ σMoveSolm I) = ⟨0⟩ := flapperCodeSize_zero_accountMapEquiv_addressSlot hpostMoveAccounts ⟨3⟩ hnoCode have hbody : @@ -4515,7 +4515,7 @@ theorem flapperDealBodyCoreMoveCallSuccess (flapperUint48Offset26Word (auctionPackedSlot (dealIdWord I)) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat) (hmoveCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd3715 : RD flapperBytecode I (Sat256.ofUInt256 g) @@ -4601,17 +4601,17 @@ theorem flapperDealBodyCoreMoveCallSuccess right simpa [evmSolm, initState, dealEndWord, dealTimestampWord, hendEq] using h have hmoveCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flapperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flapperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hmoveCodeSize by_cases hburnNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σMove + Reasoning.Theory.extCodeSizeWord σMove (flapperAddressReturnWord ⟨3⟩ σMove I) = ⟨0⟩ · exact flapperDealBodyCoreBurnNoCode hcode _hsize hwv _hsz36 hlive htic hfinished hmoveCodeSize rd3715 hmoveCall hburnNoCode hmemMove hread64Move hdispatch hdecode hAccounts · have hburnCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σMove + Reasoning.Theory.extCodeSizeWord σMove (flapperAddressReturnWord ⟨3⟩ σMove I) ≠ ⟨0⟩ := hburnNoCode obtain ⟨cABurn, σBurn, z, outBurn, ABurn, memBurn, k3832, C3832, rd3832, hmemBurn, hread64Burn, hburnCall, houtBurnSize⟩ := @@ -4657,7 +4657,7 @@ theorem flapperDealBodyCoreMoveCallSuccess simpa [evmMoveEvmForBurn, evmMoveSolm, evmBurnSolm, hgemEq, hbidEq] using hburnCallSolmRaw have hburnCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σMoveSolm + Reasoning.Theory.extCodeSizeWord σMoveSolm (flapperAddressReturnWord ⟨3⟩ σMoveSolm I) ≠ ⟨0⟩ := flapperCodeSize_ne_accountMapEquiv_addressSlot hpostMoveAccounts ⟨3⟩ hburnCodeSize by_cases hz : z = true @@ -4871,12 +4871,12 @@ theorem flapperDealBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (UInt256.ofNat I.header.timestamp).toNat) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by by_cases hmoveNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨2⟩ σ_evm I) = ⟨0⟩ · exact flapperDealBodyCoreMoveNoCode hcode hsize hwv hsz36 hlive htic hfinished hmoveNoCode hdispatch hdecode hreach hAccounts · have hmoveCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩ := hmoveNoCode by_cases hdepthEq : I.depth = 1024 diff --git a/Benchmarks/Dss/Flapper/Dispatch.lean b/Benchmarks/Dss/Flapper/Dispatch.lean index 5d2d30d0..9418efda 100644 --- a/Benchmarks/Dss/Flapper/Dispatch.lean +++ b/Benchmarks/Dss/Flapper/Dispatch.lean @@ -603,7 +603,7 @@ theorem flapperX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) /-- Calldata shorter than a selector reverts at the shared dispatcher revert block. -/ @@ -628,7 +628,7 @@ theorem flapperX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h300 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h300 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) /-- A fallthrough `PUSH2 300; JUMP` reaches the shared revert block. -/ @@ -643,7 +643,7 @@ theorem flapperJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : UI (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h300 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h300 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem flapperLowLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -666,7 +666,7 @@ theorem flapperLowLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : |>.selectorArmNotTakenAuto (flapperLowLowArmsWellFormed 4 (by omega)) (heq0 4 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h300 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h300 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem flapperLowHighNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} diff --git a/Benchmarks/Dss/Flapper/Kick.lean b/Benchmarks/Dss/Flapper/Kick.lean index f76637f4..708f333c 100644 --- a/Benchmarks/Dss/Flapper/Kick.lean +++ b/Benchmarks/Dss/Flapper/Kick.lean @@ -1486,7 +1486,7 @@ theorem flapperKickBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) (hendFit : (kickNow48Word evm).toNat + (kickTauWord (kickAfterGuyState evm I)).toNat < 2 ^ 48) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord (kickAfterEndState evm I).accountMap + Reasoning.Theory.extCodeSizeWord (kickAfterEndState evm I).accountMap (kickVatWord (kickAfterEndState evm I).accountMap (kickAfterEndState evm I).executionEnv) = ⟨0⟩) : ExecTransitionBody config contract evm (kickLocals I) kickTransition.body .reverted := by @@ -1590,7 +1590,7 @@ theorem flapperKickBodyReverts_moveCallFailure (hendFit : (kickNow48Word evm).toNat + (kickTauWord (kickAfterGuyState evm I)).toNat < 2 ^ 48) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (kickAfterEndState evm I).accountMap + Reasoning.Theory.extCodeSizeWord (kickAfterEndState evm I).accountMap (kickVatWord (kickAfterEndState evm I).accountMap (kickAfterEndState evm I).executionEnv) ≠ ⟨0⟩) (hcall : @@ -1704,7 +1704,7 @@ theorem flapperKickBodyReturns_moveCallSuccess (hendFit : (kickNow48Word evm).toNat + (kickTauWord (kickAfterGuyState evm I)).toNat < 2 ^ 48) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (kickAfterEndState evm I).accountMap + Reasoning.Theory.extCodeSizeWord (kickAfterEndState evm I).accountMap (kickVatWord (kickAfterEndState evm I).accountMap (kickAfterEndState evm I).executionEnv) ≠ ⟨0⟩) (hcall : @@ -2356,7 +2356,7 @@ theorem flapperKickX_fillAddOverflow {cA σ I} {g : Sat256} {s0 : State} {k C : rw [show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rd4987 have rd4990 := rd4987.push2 ⟨4930⟩ (by native_decide) (by evm_ov) have rd4991 := rd4990.jumpiNT (by native_decide) rfl (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd4991 + exact RD.solcPush1Dup1Revert0 rd4991 (by native_decide) (by native_decide) (by native_decide) (by simp) @@ -2821,7 +2821,7 @@ theorem flapperKickX_endAddOverflow {cA σ I} {g : Sat256} {s0 : State} rw [hltTrue] native_decide have rd4959 := rd4958.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd4959 + exact RD.solcPush1Dup1Revert0 rd4959 (by native_decide) (by native_decide) (by native_decide) (by simp) @@ -3066,7 +3066,7 @@ theorem flapperKickX_toMoveExtcodesizeGuard {cA σ I} {g : Sat256} {s0 : State} simp [Benchmarks.Dss.Flopper.dentMoveSrcMem, src, kickSenderWord, show ((⟨128⟩ : UInt256) + ⟨4⟩).toNat = 132 from by native_decide]) (by native_decide) (by evm_ov), - raw uniswapAddress (by native_decide) (by evm_ov), + raw address (by native_decide) (by evm_ov), raw push1 ⟨36⟩ (by native_decide) (by evm_ov), raw dup3 (by native_decide) (by evm_ov), raw add (by native_decide) (by evm_ov), @@ -3201,7 +3201,7 @@ theorem RD.flapperKickReturnWordFromMem8 {cA σ I} {g : Sat256} {s0 : State} theorem flapperKickX_moveNoCode {cA gh bl σStart σ σ₀ A I} {g : Sat256} {sel : UInt256} {k C : ℕ} (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord (kickRuntimeBeforeMoveMap I.codeOwner σ I) + Reasoning.Theory.extCodeSizeWord (kickRuntimeBeforeMoveMap I.codeOwner σ I) (kickVatWord (kickRuntimeBeforeMoveMap I.codeOwner σ I) I) = ⟨0⟩) (rd4379 : RD flapperBytecode I g (initState cA gh bl σStart σ₀ g A I) ⟨4379⟩ [flapperSlotWord ⟨2⟩ (kickRuntimeBeforeMoveMap I.codeOwner σ I) I, @@ -3212,7 +3212,7 @@ theorem flapperKickX_moveNoCode (cA, kickRuntimeBeforeMoveMap I.codeOwner σ I) k C) : RDrev flapperBytecode g (initState cA gh bl σStart σ₀ g A I) := by obtain ⟨_, _, rd4446⟩ := flapperKickX_toMoveExtcodesizeGuard rd4379 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4446⟩) (okPc := ⟨4458⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4446⟩) (okPc := ⟨4458⟩) rd4446 hnoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3222,7 +3222,7 @@ theorem flapperKickX_moveCall {cA gh bl σStart σ σ₀ A I} {g : Sat256} {sel : UInt256} {k C : ℕ} (hperm : I.perm = true) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (kickRuntimeBeforeMoveMap I.codeOwner σ I) + Reasoning.Theory.extCodeSizeWord (kickRuntimeBeforeMoveMap I.codeOwner σ I) (kickVatWord (kickRuntimeBeforeMoveMap I.codeOwner σ I) I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd4379 : RD flapperBytecode I g (initState cA gh bl σStart σ₀ g A I) ⟨4379⟩ @@ -3283,7 +3283,7 @@ theorem flapperKickX_moveCall simpa [guy, kickThisWord] using accountAddress_roundtrip I.codeOwner obtain ⟨_, _, rd4446⟩ := flapperKickX_toMoveExtcodesizeGuard rd4379 obtain ⟨gasWord, _, _, rd4461⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4446⟩) (okPc := ⟨4458⟩) rd4446 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4446⟩) (okPc := ⟨4458⟩) rd4446 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -3325,7 +3325,7 @@ theorem flapperKickX_moveCall theorem flapperKickX_moveCallDepthLimit {cA gh bl σStart σ σ₀ A I} {g : Sat256} {sel : UInt256} {k C : ℕ} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (kickRuntimeBeforeMoveMap I.codeOwner σ I) + Reasoning.Theory.extCodeSizeWord (kickRuntimeBeforeMoveMap I.codeOwner σ I) (kickVatWord (kickRuntimeBeforeMoveMap I.codeOwner σ I) I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (rd4379 : RD flapperBytecode I g (initState cA gh bl σStart σ₀ g A I) ⟨4379⟩ @@ -3351,7 +3351,7 @@ theorem flapperKickX_moveCallDepthLimit intro id memStore memEndStore σBeforeMove src guy rad vat obtain ⟨_, _, rd4446⟩ := flapperKickX_toMoveExtcodesizeGuard rd4379 obtain ⟨gasWord, _, _, rd4461⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4446⟩) (okPc := ⟨4458⟩) rd4446 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4446⟩) (okPc := ⟨4458⟩) rd4446 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -3383,7 +3383,7 @@ theorem flapperKickX_moveCallFailure mem aw out (cA', σ') k C) (houtSize : out.size < UInt256.size) : RDrev flapperBytecode g (initState cA gh bl σStart σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨4462⟩) (okPc := ⟨4478⟩) rd4462 + exact RD.solcCallSuccessGuardMissing (pc := ⟨4462⟩) (okPc := ⟨4478⟩) rd4462 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3498,7 +3498,7 @@ theorem flapperKickX_moveCallSuccess UInt256.toByteArray id := toByteArray_write32_read_back memEvent id 128 (by rw [hmemEventSize]; omega) obtain ⟨k4480, C4480, rd4480raw⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨4462⟩) (okPc := ⟨4478⟩) rd4462 + RD.solcCallSuccessGuardOk (pc := ⟨4462⟩) (okPc := ⟨4478⟩) rd4462 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -3937,12 +3937,12 @@ theorem flapperKickBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (cA := cA) (gh := gh) (bl := bl) (σ₀ := σ₀) (A := A) (I := I) (g := g) hAccounts hendFit by_cases hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (kickRuntimeBeforeMoveMap I.codeOwner σ_evm I) (kickVatWord (kickRuntimeBeforeMoveMap I.codeOwner σ_evm I) I) = ⟨0⟩ · have hnoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (kickAfterEndState evmSolm I).accountMap (kickVatWord (kickAfterEndState evmSolm I).accountMap (kickAfterEndState evmSolm I).executionEnv) = ⟨0⟩ := by @@ -3960,12 +3960,12 @@ theorem flapperKickBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (flapperKickX_moveNoCode (g := Sat256.ofUInt256 g) hnoCode rd4379) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (kickRuntimeBeforeMoveMap I.codeOwner σ_evm I) (kickVatWord (kickRuntimeBeforeMoveMap I.codeOwner σ_evm I) I) ≠ ⟨0⟩ := hnoCode have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (kickAfterEndState evmSolm I).accountMap (kickVatWord (kickAfterEndState evmSolm I).accountMap (kickAfterEndState evmSolm I).executionEnv) ≠ ⟨0⟩ := by diff --git a/Benchmarks/Dss/Flapper/SpecSyntax.lean b/Benchmarks/Dss/Flapper/SpecSyntax.lean index 26f7aba9..a436f7d8 100644 --- a/Benchmarks/Dss/Flapper/SpecSyntax.lean +++ b/Benchmarks/Dss/Flapper/SpecSyntax.lean @@ -2,19 +2,228 @@ import Benchmarks.Dss.Flapper.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS Flapper spec through the Solm notation frontend +# Flapper spec in the Solidity-faithful Solm frontend -The main spec lives in `Spec.lean`; this companion keeps the benchmark's notation-side check wired -up as the body surface grows. +The whole `flap.sol` spec written with `solidity%` and proven definitionally equal to the AST spec +in `Spec.lean`. Checked-math helpers are inlined (uint48 adds are the explicit +`% #uint48Modulus` wraps); the struct field `end` is guillemet-escaped; `extCodeSize` guards on +the storage `vat`/`gem` receivers use the `${…}` escape. Transition order matches +`contract.transitions` (selector order). -/ -open Solm Solm.Notation +open Solm Solm.Notation Benchmarks.Dss.Flapper namespace Benchmarks.Dss.Flapper.Syntax -def contractSyntax : ContractDecl := Benchmarks.Dss.Flapper.contract +def contractSyntax : ContractDecl := solidity% contract Flapper { + struct Bid { + uint256 bid; + uint256 lot; + address guy; + uint48 tic; + uint48 «end»; + } -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Flapper.contract := by - rfl + mapping(address => uint256) wards; + mapping(uint256 => Bid) bids; + address vat; + address gem; + uint256 beg; + uint48 ttl; + uint48 tau; + uint256 kicks; + uint256 live; + uint256 lid; + uint256 fill; + + constructor(address vat_, address gem_) { + beg = #defaultBeg; + ttl = #defaultTtl; + tau = #defaultTau; + kicks = 0; + wards[msg.sender] = 1; + vat = vat_; + gem = gem_; + live = 1; + } + + function add(uint48 x, uint48 y) internal returns (uint48) { + uint48 z = (x + y) % #uint48Modulus; + require(z >= x); + return z; + } + + function add256(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x + y) as uint256; + require(z >= x); + return z; + } + + function sub(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x - y) as uint256; + require(z <= x); + return z; + } + + function mul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + return z; + } + + function beg() external returns (uint256) { + return beg; + } + + function bids(uint256 arg0) external returns (uint256, uint256, address, uint48, uint48) { + return (bids[arg0].bid, bids[arg0].lot, bids[arg0].guy, bids[arg0].tic, bids[arg0].«end»); + } + + function cage(uint256 rad) external { + require(wards[msg.sender] == 1); + live = 0; + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _moveRet = vat.move(address(this), msg.sender, rad); + } + + function deal(uint256 id) external { + require(live == 1); + require(bids[id].tic != 0 && (bids[id].tic < block.timestamp || bids[id].«end» < block.timestamp)); + uint256 lot = bids[id].lot; + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _moveRet = vat.move(address(this), bids[id].guy, lot); + require(${Expr.extCodeSize (.storage gemRef)} > 0); + var _burnRet = gem.burn(address(this), bids[id].bid); + delete bids[id]; + var fillNew = sub(fill, lot); + fill = fillNew; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x6265670000000000000000000000000000000000000000000000000000000000)) { + beg = data; + } else if (what == bytes32(0x74746c0000000000000000000000000000000000000000000000000000000000)) { + ttl = data % #uint48Modulus; + } else if (what == bytes32(0x7461750000000000000000000000000000000000000000000000000000000000)) { + tau = data % #uint48Modulus; + } else if (what == bytes32(0x6c69640000000000000000000000000000000000000000000000000000000000)) { + lid = data; + } else { + require(false); + } + } + + function fill() external returns (uint256) { + return fill; + } + + function gem() external returns (address) { + return gem; + } + + function kick(uint256 lot, uint256 bid) external returns (uint256) { + require(wards[msg.sender] == 1); + require(live == 1); + require(kicks < #maxUint256); + uint256 fillNew = (fill + lot) as uint256; + require(fillNew >= fill); + fill = fillNew; + require(fill <= lid); + uint256 id = (kicks + 1) as uint256; + require(id >= kicks); + kicks = id; + bids[id].bid = bid; + bids[id].lot = lot; + bids[id].guy = msg.sender; + uint48 end_ = (block.timestamp % #uint48Modulus + tau) % #uint48Modulus; + require(end_ >= block.timestamp % #uint48Modulus); + bids[id].«end» = end_; + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _moveRet = vat.move(msg.sender, address(this), lot); + return id; + } + + function kicks() external returns (uint256) { + return kicks; + } + + function lid() external returns (uint256) { + return lid; + } + + function live() external returns (uint256) { + return live; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 1; + } + + function tau() external returns (uint48) { + return tau; + } + + function tend(uint256 id, uint256 lot, uint256 bid) external { + require(live == 1); + require(bids[id].guy != address(0)); + require(bids[id].tic > block.timestamp || bids[id].tic == 0); + require(bids[id].«end» > block.timestamp); + require(lot == bids[id].lot); + require(bid > bids[id].bid); + uint256 bidOne = (bid * #ONE) as uint256; + require(#ONE == 0 || bidOne / #ONE == bid); + uint256 begBid = (beg * bids[id].bid) as uint256; + require(bids[id].bid == 0 || begBid / bids[id].bid == beg); + require(bidOne >= begBid); + if (msg.sender != bids[id].guy) { + require(${Expr.extCodeSize (.storage gemRef)} > 0); + var _refundRet = gem.move(msg.sender, bids[id].guy, bids[id].bid); + bids[id].guy = msg.sender; + } + require(${Expr.extCodeSize (.storage gemRef)} > 0); + var _payRet = gem.move(msg.sender, address(this), (bid - bids[id].bid) % #wordModulus); + bids[id].bid = bid; + uint48 tic_ = (block.timestamp % #uint48Modulus + ttl) % #uint48Modulus; + require(tic_ >= block.timestamp % #uint48Modulus); + bids[id].tic = tic_; + } + + function tick(uint256 id) external { + require(bids[id].«end» < block.timestamp); + require(bids[id].tic == 0); + uint48 end_ = (block.timestamp % #uint48Modulus + tau) % #uint48Modulus; + require(end_ >= block.timestamp % #uint48Modulus); + bids[id].«end» = end_; + } + + function ttl() external returns (uint48) { + return ttl; + } + + function vat() external returns (address) { + return vat; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } + + function yank(uint256 id) external { + require(live == 0); + require(bids[id].guy != address(0)); + require(${Expr.extCodeSize (.storage gemRef)} > 0); + var _moveRet = gem.move(address(this), bids[id].guy, bids[id].bid); + delete bids[id]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Flapper.contract := by rfl end Benchmarks.Dss.Flapper.Syntax diff --git a/Benchmarks/Dss/Flapper/Tend.lean b/Benchmarks/Dss/Flapper/Tend.lean index a3bc982a..7c2b78ea 100644 --- a/Benchmarks/Dss/Flapper/Tend.lean +++ b/Benchmarks/Dss/Flapper/Tend.lean @@ -2018,7 +2018,7 @@ theorem flapperTendPaySuccessTail (hgem : baseLocals.get? "gem" = none) (httl : baseLocals.get? "ttl" = none) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (tendGemWord evm).toNat)) "move" 0 @@ -2147,7 +2147,7 @@ theorem flapperTendBodyReturns_success_callerEq (hsuff : (tendBegBidWord evm I).toNat ≤ (tendBidOneWord I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val = tendGuyWord evm I) (hpayCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) (hpayCall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (tendGemWord evm).toNat)) "move" 0 @@ -2236,7 +2236,7 @@ theorem flapperTendRefundSuccessPrefix (evm evmRefund : EVM.State) (I : ExecutionEnv) (outRefund : ByteArray) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ tendGuyWord evm I) (hrefundCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) (hrefundCall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (tendGemWord evm).toNat)) "move" 0 @@ -2326,7 +2326,7 @@ theorem flapperTendBodyReturns_success_callerNe (hsuff : (tendBegBidWord evm I).toNat ≤ (tendBidOneWord I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ tendGuyWord evm I) (hrefundCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) (hrefundCall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (tendGemWord evm).toNat)) "move" 0 @@ -2335,7 +2335,7 @@ theorem flapperTendBodyReturns_success_callerNe .int (Int.ofNat (tendBidStoredWord evm I).toNat)] (true, evmRefund, outRefund) true) (hpayCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (tendAfterGuyStore evmRefund I).accountMap + Reasoning.Theory.extCodeSizeWord (tendAfterGuyStore evmRefund I).accountMap (tendGemWord (tendAfterGuyStore evmRefund I)) ≠ ⟨0⟩) (hpayCall : typedCallViaEVM config (tendAfterGuyStore evmRefund I) @@ -2431,7 +2431,7 @@ theorem flapperTendRefundNoCodeTail (evm : EVM.State) (I : ExecutionEnv) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ tendGuyWord evm I) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (tendGemWord evm) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord evm.accountMap (tendGemWord evm) = ⟨0⟩) : ExecBlock config { contract := contract, locals := tendBegBidLocals evm I } evm ([.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) (checkedExternalCallStmts (.storage gemRef) "move" (.intLit 0) @@ -2498,7 +2498,7 @@ theorem flapperTendRefundCallFailureTail (evm evmRefund : EVM.State) (I : ExecutionEnv) (outRefund : ByteArray) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ tendGuyWord evm I) (hrefundCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) (hrefundCall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (tendGemWord evm).toNat)) "move" 0 @@ -2574,7 +2574,7 @@ theorem flapperTendPayNoCodeTail (evm : EVM.State) (I : ExecutionEnv) (baseLocals : Store) (hgem : baseLocals.get? "gem" = none) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (tendGemWord evm) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord evm.accountMap (tendGemWord evm) = ⟨0⟩) : ExecBlock config { contract := contract, locals := baseLocals } evm ((checkedExternalCallStmts (.storage gemRef) "move" (.intLit 0) [sender, thisAddr, @@ -2629,7 +2629,7 @@ theorem flapperTendPayCallFailureTail (hbids : baseLocals.get? "bids" = none) (hgem : baseLocals.get? "gem" = none) (hpayCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) (hpayCall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (tendGemWord evm).toNat)) "move" 0 @@ -2693,7 +2693,7 @@ theorem flapperTendPayAddOverflowTail (hgem : baseLocals.get? "gem" = none) (httl : baseLocals.get? "ttl" = none) (hpayCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (tendGemWord evm) ≠ ⟨0⟩) (hpayCall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (tendGemWord evm).toNat)) "move" 0 @@ -4370,7 +4370,7 @@ theorem RD.flapperCheckedMulOverflowReverts have heqCond : UInt256.eq (UInt256.div (x * y) y) x = ⟨0⟩ := u256_eq_of_ne hdivNe have rd4926 := rd4925.jumpiNT (by native_decide) heqCond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd4926 + exact RD.solcPush1Dup1Revert0 rd4926 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -5008,7 +5008,7 @@ theorem flapperTendX_refundNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} {memCaller : ByteArray} {k C : ℕ} (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flapperAddressReturnWord ⟨3⟩ σ I) = + Reasoning.Theory.extCodeSizeWord σ (flapperAddressReturnWord ⟨3⟩ σ I) = ⟨0⟩) (hmemCaller : memCaller.size = 96) (hread64Caller : memCaller.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) @@ -5018,7 +5018,7 @@ theorem flapperTendX_refundNoCode RDrev flapperBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd2528⟩ := flapperTendX_toRefundExtcodesizeGuard hmemCaller hread64Caller rd2433 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2528⟩) (okPc := ⟨2540⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2528⟩) (okPc := ⟨2540⟩) rd2528 hnoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -5030,7 +5030,7 @@ theorem flapperTendX_refundCall {k C : ℕ} (hperm : I.perm = true) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flapperAddressReturnWord ⟨3⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (flapperAddressReturnWord ⟨3⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hmemCaller : memCaller.size = 96) @@ -5070,7 +5070,7 @@ theorem flapperTendX_refundCall obtain ⟨_, _, rd2528⟩ := flapperTendX_toRefundExtcodesizeGuard hmemCaller hread64Caller rd2433 obtain ⟨gasWord, _, _, rd2543⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2528⟩) (okPc := ⟨2540⟩) rd2528 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2528⟩) (okPc := ⟨2540⟩) rd2528 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -5112,7 +5112,7 @@ theorem flapperTendX_refundCallDepthLimit {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} {memCaller : ByteArray} {k C : ℕ} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flapperAddressReturnWord ⟨3⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (flapperAddressReturnWord ⟨3⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hmemCaller : memCaller.size = 96) @@ -5135,7 +5135,7 @@ theorem flapperTendX_refundCallDepthLimit obtain ⟨_, _, rd2528⟩ := flapperTendX_toRefundExtcodesizeGuard hmemCaller hread64Caller rd2433 obtain ⟨gasWord, _, _, rd2543⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2528⟩) (okPc := ⟨2540⟩) rd2528 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2528⟩) (okPc := ⟨2540⟩) rd2528 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -5165,7 +5165,7 @@ theorem flapperTendX_refundCallFailure mem (UInt256.ofNat 8) out (cAcur, τ) k C) (houtSize : out.size < UInt256.size) : RDrev flapperBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2544⟩) (okPc := ⟨2560⟩) rd2544 + exact RD.solcCallSuccessGuardMissing (pc := ⟨2544⟩) (okPc := ⟨2560⟩) rd2544 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -5194,7 +5194,7 @@ theorem flapperTendX_refundCallSuccessToPayStart let oldPacked := solcSlotWord τ I packedSlot let src := UInt256.ofNat I.source.val obtain ⟨k2562, C2562, rd2562raw⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨2544⟩) (okPc := ⟨2560⟩) rd2544 + RD.solcCallSuccessGuardOk (pc := ⟨2544⟩) (okPc := ⟨2560⟩) rd2544 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -5460,7 +5460,7 @@ theorem flapperTendX_addOverflowFromCheckedAddAw8 rw [hltTrue] native_decide have rd4959 := rd4958.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd4959 + exact RD.solcPush1Dup1Revert0 rd4959 (by native_decide) (by native_decide) (by native_decide) (by simp) @@ -6057,7 +6057,7 @@ theorem flapperTendX_toPayExtcodesizeGuardAw8Mem228 simp [yankMoveSrcMem, src, show ((⟨128⟩ : UInt256) + ⟨4⟩).toNat = 132 from by native_decide]) (by native_decide) (by evm_ov), - raw uniswapAddress (by native_decide) (by evm_ov), + raw address (by native_decide) (by evm_ov), raw push1 ⟨36⟩ (by native_decide) (by evm_ov), raw dup3 (by native_decide) (by evm_ov), raw add (by native_decide) (by evm_ov), @@ -6149,7 +6149,7 @@ theorem flapperTendX_payNoCodeAw8Mem228 {cA cAcur gh bl σ τ σ₀ A I} {g : Sat256} {sel : UInt256} {memCaller retData : ByteArray} {k C : ℕ} (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flapperAddressReturnWord ⟨3⟩ τ I) = + Reasoning.Theory.extCodeSizeWord τ (flapperAddressReturnWord ⟨3⟩ τ I) = ⟨0⟩) (hmemCaller : memCaller.size = 228) (hread64Caller : memCaller.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) @@ -6159,7 +6159,7 @@ theorem flapperTendX_payNoCodeAw8Mem228 RDrev flapperBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd2687⟩ := flapperTendX_toPayExtcodesizeGuardAw8Mem228 hmemCaller hread64Caller rd2598 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2687⟩) (okPc := ⟨2699⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2687⟩) (okPc := ⟨2699⟩) rd2687 hnoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -6171,7 +6171,7 @@ theorem flapperTendX_payCallAw8Mem228 {memCaller retData : ByteArray} {k C : ℕ} (hperm : I.perm = true) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flapperAddressReturnWord ⟨3⟩ τ I) ≠ + Reasoning.Theory.extCodeSizeWord τ (flapperAddressReturnWord ⟨3⟩ τ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hmemCaller : memCaller.size = 228) @@ -6224,7 +6224,7 @@ theorem flapperTendX_payCallAw8Mem228 obtain ⟨_, _, rd2687⟩ := flapperTendX_toPayExtcodesizeGuardAw8Mem228 hmemCaller hread64Caller rd2598 obtain ⟨gasWord, _, _, rd2702⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2687⟩) (okPc := ⟨2699⟩) rd2687 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2687⟩) (okPc := ⟨2699⟩) rd2687 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -6401,7 +6401,7 @@ theorem flapperTendX_toPayExtcodesizeGuard simp [yankMoveSrcMem, src, show ((⟨128⟩ : UInt256) + ⟨4⟩).toNat = 132 from by native_decide]) (by native_decide) (by evm_ov), - raw uniswapAddress (by native_decide) (by evm_ov), + raw address (by native_decide) (by evm_ov), raw push1 ⟨36⟩ (by native_decide) (by evm_ov), raw dup3 (by native_decide) (by evm_ov), raw add (by native_decide) (by evm_ov), @@ -6493,7 +6493,7 @@ theorem flapperTendX_payNoCode {cA cAcur gh bl σ τ σ₀ A I} {g : Sat256} {sel : UInt256} {memCaller retData : ByteArray} {k C : ℕ} (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flapperAddressReturnWord ⟨3⟩ τ I) = + Reasoning.Theory.extCodeSizeWord τ (flapperAddressReturnWord ⟨3⟩ τ I) = ⟨0⟩) (hmemCaller : memCaller.size = 96) (hread64Caller : memCaller.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) @@ -6503,7 +6503,7 @@ theorem flapperTendX_payNoCode RDrev flapperBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd2687⟩ := flapperTendX_toPayExtcodesizeGuard hmemCaller hread64Caller rd2598 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2687⟩) (okPc := ⟨2699⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2687⟩) (okPc := ⟨2699⟩) rd2687 hnoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -6515,7 +6515,7 @@ theorem flapperTendX_payCall {memCaller retData : ByteArray} {k C : ℕ} (hperm : I.perm = true) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flapperAddressReturnWord ⟨3⟩ τ I) ≠ + Reasoning.Theory.extCodeSizeWord τ (flapperAddressReturnWord ⟨3⟩ τ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hmemCaller : memCaller.size = 96) @@ -6564,7 +6564,7 @@ theorem flapperTendX_payCall obtain ⟨_, _, rd2687⟩ := flapperTendX_toPayExtcodesizeGuard hmemCaller hread64Caller rd2598 obtain ⟨gasWord, _, _, rd2702⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2687⟩) (okPc := ⟨2699⟩) rd2687 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2687⟩) (okPc := ⟨2699⟩) rd2687 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -6606,7 +6606,7 @@ theorem flapperTendX_payCallDepthLimit {cA cAcur gh bl σ τ σ₀ A I} {g : Sat256} {sel : UInt256} {memCaller retData : ByteArray} {k C : ℕ} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flapperAddressReturnWord ⟨3⟩ τ I) ≠ + Reasoning.Theory.extCodeSizeWord τ (flapperAddressReturnWord ⟨3⟩ τ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hmemCaller : memCaller.size = 96) @@ -6630,7 +6630,7 @@ theorem flapperTendX_payCallDepthLimit obtain ⟨_, _, rd2687⟩ := flapperTendX_toPayExtcodesizeGuard hmemCaller hread64Caller rd2598 obtain ⟨gasWord, _, _, rd2702⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2687⟩) (okPc := ⟨2699⟩) rd2687 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2687⟩) (okPc := ⟨2699⟩) rd2687 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -6660,7 +6660,7 @@ theorem flapperTendX_payCallFailure mem (UInt256.ofNat 8) out (cAcur, τ) k C) (houtSize : out.size < UInt256.size) : RDrev flapperBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2703⟩) (okPc := ⟨2719⟩) rd2703 + exact RD.solcCallSuccessGuardMissing (pc := ⟨2703⟩) (okPc := ⟨2719⟩) rd2703 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -6680,7 +6680,7 @@ theorem flapperTendX_payCallSuccessToTail gem :: tendBidWord I :: tendLotWord I :: tendIdWord I :: ⟨360⟩ :: sel :: []) mem (UInt256.ofNat 8) out (cAcur, τ) k' C' := by obtain ⟨k2721, C2721, rd2721raw⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨2703⟩) (okPc := ⟨2719⟩) rd2703 hstatus + RD.solcCallSuccessGuardOk (pc := ⟨2703⟩) (okPc := ⟨2719⟩) rd2703 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -7851,7 +7851,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard evalExpr_tend_sender_ne_guy_false_begBidLocals evmSolm I hcallerSolm exact ExecBlock.consNormal (ExecStmt.iteFalse hcallerCond ExecBlock.nil) ExecBlock.nil by_cases hpayNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨3⟩ σ_evm I) = ⟨0⟩ · have hpayNoCodeSolm := flapperCodeSize_zero_accountMapEquiv_addressSlot hAccounts ⟨3⟩ hpayNoCode @@ -7890,7 +7890,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard (by simpa [evmEvm, id] using rd2598)) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hpayCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨3⟩ σ_evm I) ≠ ⟨0⟩ := hpayNoCode have hpayCodeSizeSolm := flapperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨3⟩ hpayCodeSize @@ -8167,7 +8167,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard (σ := σ_evm) (sel := sel) (by simpa [packedSlot, id] using hcallerNe) (by simpa [evmEvm] using rd2429) by_cases hrefundNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨3⟩ σ_evm I) = ⟨0⟩ · have hrefundNoCodeSolm := flapperCodeSize_zero_accountMapEquiv_addressSlot hAccounts ⟨3⟩ hrefundNoCode @@ -8184,7 +8184,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard (by simpa [evmEvm, id] using rd2433)) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hrefundCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨3⟩ σ_evm I) ≠ ⟨0⟩ := hrefundNoCode have hrefundCodeSizeSolm := flapperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨3⟩ hrefundCodeSize @@ -8345,7 +8345,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard (by simpa [evmSolm, tendGemWord, initState] using hrefundCodeSizeSolm) hrefundCallTrue by_cases hpayNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σGuy + Reasoning.Theory.extCodeSizeWord σGuy (flapperAddressReturnWord ⟨3⟩ σGuy I) = ⟨0⟩ · have hpayNoCodeSolm := flapperCodeSize_zero_accountMapEquiv_addressSlot hpostGuyAccounts ⟨3⟩ @@ -8386,7 +8386,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard packedSlot] using rd2598Guy)) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hpayCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σGuy + Reasoning.Theory.extCodeSizeWord σGuy (flapperAddressReturnWord ⟨3⟩ σGuy I) ≠ ⟨0⟩ := hpayNoCode have hpayCodeSizeSolm := flapperCodeSize_ne_accountMapEquiv_addressSlot hpostGuyAccounts ⟨3⟩ diff --git a/Benchmarks/Dss/Flapper/Tick.lean b/Benchmarks/Dss/Flapper/Tick.lean index 9e8f88e4..7d141466 100644 --- a/Benchmarks/Dss/Flapper/Tick.lean +++ b/Benchmarks/Dss/Flapper/Tick.lean @@ -1352,7 +1352,7 @@ theorem flapperTickX_addOverflow rw [hltTrue] native_decide have rd4959 := rd4958.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd4959 + exact RD.solcPush1Dup1Revert0 rd4959 (by native_decide) (by native_decide) (by native_decide) (by simp) diff --git a/Benchmarks/Dss/Flapper/Yank.lean b/Benchmarks/Dss/Flapper/Yank.lean index f9956a1b..4c16f1a1 100644 --- a/Benchmarks/Dss/Flapper/Yank.lean +++ b/Benchmarks/Dss/Flapper/Yank.lean @@ -151,12 +151,12 @@ theorem flapperAddressOfSlot_accountMapEquiv {σ τ : AccountMap} {I : Execution theorem flapperCodeSize_ne_accountMapEquiv_addressSlot {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (slot : UInt256) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flapperAddressReturnWord slot σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flapperAddressReturnWord slot τ I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (flapperAddressReturnWord slot σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (flapperAddressReturnWord slot τ I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (flapperAddressReturnWord slot σ I) have htarget : flapperAddressReturnWord slot σ I = flapperAddressReturnWord slot τ I := @@ -167,10 +167,10 @@ theorem flapperCodeSize_ne_accountMapEquiv_addressSlot {σ τ : AccountMap} theorem flapperCodeSize_zero_accountMapEquiv_addressSlot {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (slot : UInt256) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flapperAddressReturnWord slot σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flapperAddressReturnWord slot τ I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (flapperAddressReturnWord slot σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (flapperAddressReturnWord slot τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (flapperAddressReturnWord slot σ I) have htarget : flapperAddressReturnWord slot σ I = flapperAddressReturnWord slot τ I := @@ -1097,11 +1097,11 @@ theorem evalExpr_yank_extCodeGuard_false {evm : EVM.State} {locals : Store} theorem flapperExtCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => exfalso @@ -1123,11 +1123,11 @@ theorem flapperExtCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} theorem flapperExtCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using @@ -1176,7 +1176,7 @@ theorem flapperYankBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) (hguy : flapperAddressReturnWord (auctionPackedSlot (yankIdWord I)) evm.accountMap evm.executionEnv ≠ ⟨0⟩) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (flapperAddressReturnWord ⟨3⟩ evm.accountMap evm.executionEnv) = ⟨0⟩) : ExecTransitionBody config contract evm (yankLocals I) yankTransition.body .reverted := by have hvat := evalExpr_yank_gem_storage evm I @@ -1216,7 +1216,7 @@ theorem flapperYankBodyReverts_moveCallFailure (hguy : flapperAddressReturnWord (auctionPackedSlot (yankIdWord I)) evm.accountMap evm.executionEnv ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (flapperAddressReturnWord ⟨3⟩ evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -1284,7 +1284,7 @@ theorem flapperYankBodyReturns_moveCallSuccess (hguy : flapperAddressReturnWord (auctionPackedSlot (yankIdWord I)) evm.accountMap evm.executionEnv ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (flapperAddressReturnWord ⟨3⟩ evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -1928,7 +1928,7 @@ theorem flapperYankX_toMoveExtcodesizeGuard raw dup2 (by native_decide) (by evm_ov), raw mstore 6 (yankMoveSelectorMem memMap) (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - raw uniswapAddress (by native_decide) (by evm_ov), + raw address (by native_decide) (by evm_ov), raw push1 ⟨4⟩ (by native_decide) (by evm_ov), raw dup3 (by native_decide) (by evm_ov), raw add (by native_decide) (by evm_ov), @@ -2045,14 +2045,14 @@ theorem flapperYankX_toMoveExtcodesizeGuard theorem flapperYankX_moveNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} {k C : ℕ} (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flapperAddressReturnWord ⟨3⟩ σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flapperAddressReturnWord ⟨3⟩ σ I) = ⟨0⟩) (rd1050 : RD flapperBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1062⟩ [yankIdWord I, ⟨360⟩, sel] (twoWordHashMem (yankIdWord I) ⟨1⟩ solcFreePtrMem) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : RDrev flapperBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd1148⟩ := flapperYankX_toMoveExtcodesizeGuard rd1050 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1158⟩) (okPc := ⟨1170⟩) rd1148 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1158⟩) (okPc := ⟨1170⟩) rd1148 hnoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2061,7 +2061,7 @@ theorem flapperYankX_moveCall {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} {k C : ℕ} (hperm : I.perm = true) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flapperAddressReturnWord ⟨3⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (flapperAddressReturnWord ⟨3⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd1050 : RD flapperBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1062⟩ @@ -2114,7 +2114,7 @@ theorem flapperYankX_moveCall simpa [src, yankThisWord] using accountAddress_roundtrip I.codeOwner obtain ⟨_, _, rd1148⟩ := flapperYankX_toMoveExtcodesizeGuard rd1050 obtain ⟨gasWord, _, _, rd1163⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1158⟩) (okPc := ⟨1170⟩) rd1148 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1158⟩) (okPc := ⟨1170⟩) rd1148 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -2155,7 +2155,7 @@ theorem flapperYankX_moveCall theorem flapperYankX_moveCallDepthLimit {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} {k C : ℕ} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flapperAddressReturnWord ⟨3⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (flapperAddressReturnWord ⟨3⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (rd1050 : RD flapperBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1062⟩ @@ -2177,7 +2177,7 @@ theorem flapperYankX_moveCallDepthLimit intro id memHash memMap gem src guy bid obtain ⟨_, _, rd1148⟩ := flapperYankX_toMoveExtcodesizeGuard rd1050 obtain ⟨gasWord, _, _, rd1163⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1158⟩) (okPc := ⟨1170⟩) rd1148 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1158⟩) (okPc := ⟨1170⟩) rd1148 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -2208,7 +2208,7 @@ theorem flapperYankX_moveCallFailure mem aw out (cA', σ') k C) (houtSize : out.size < UInt256.size) : RDrev flapperBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1174⟩) (okPc := ⟨1190⟩) rd1164 + exact RD.solcCallSuccessGuardMissing (pc := ⟨1174⟩) (okPc := ⟨1190⟩) rd1164 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2325,7 +2325,7 @@ theorem flapperYankBodyCoreMoveNoCode (hlive : flapperSlotWord ⟨7⟩ σ_evm I = ⟨0⟩) (hguy : flapperAddressReturnWord (auctionPackedSlot (yankIdWord I)) σ_evm I ≠ ⟨0⟩) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨3⟩ σ_evm I) = ⟨0⟩) (hdispatch : dispatchMsg contract I.calldata = some yankTransition) (hdecode : @@ -2350,7 +2350,7 @@ theorem flapperYankBodyCoreMoveNoCode (auctionPackedSlot (yankIdWord I)) rw [hword, hzero]) have hnoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flapperAddressReturnWord ⟨3⟩ σ_solm I) = ⟨0⟩ := flapperCodeSize_zero_accountMapEquiv_addressSlot hAccounts ⟨3⟩ hnoCode have hbody : @@ -2378,7 +2378,7 @@ theorem flapperYankBodyCoreMoveCallFailure (hlive : flapperSlotWord ⟨7⟩ σ_evm I = ⟨0⟩) (hguy : flapperAddressReturnWord (auctionPackedSlot (yankIdWord I)) σ_evm I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨3⟩ σ_evm I) ≠ ⟨0⟩) (rd1164 : RD flapperBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1174⟩ @@ -2451,7 +2451,7 @@ theorem flapperYankBodyCoreMoveCallFailure intro hzero exact hguy (by rw [hguyEq, hzero]) have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flapperAddressReturnWord ⟨3⟩ σ_solm I) ≠ ⟨0⟩ := flapperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨3⟩ hcodeSize have hbody : @@ -2476,7 +2476,7 @@ theorem flapperYankBodyCoreMoveCallDepthLimit (hlive : flapperSlotWord ⟨7⟩ σ_evm I = ⟨0⟩) (hguy : flapperAddressReturnWord (auctionPackedSlot (yankIdWord I)) σ_evm I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨3⟩ σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hdispatch : dispatchMsg contract I.calldata = some yankTransition) @@ -2545,7 +2545,7 @@ theorem flapperYankBodyCoreMoveCallDepthLimit (auctionPackedSlot (yankIdWord I)) rw [hword, hzero]) have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flapperAddressReturnWord ⟨3⟩ σ_solm I) ≠ ⟨0⟩ := flapperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨3⟩ hcodeSize have hbody : @@ -2577,7 +2577,7 @@ theorem flapperYankBodyCoreMoveCallSuccess (hlive : flapperSlotWord ⟨7⟩ σ_evm I = ⟨0⟩) (hguy : flapperAddressReturnWord (auctionPackedSlot (yankIdWord I)) σ_evm I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨3⟩ σ_evm I) ≠ ⟨0⟩) (rd1164 : RD flapperBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1174⟩ @@ -2649,7 +2649,7 @@ theorem flapperYankBodyCoreMoveCallSuccess intro hzero exact hguy (by rw [hguyEq, hzero]) have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flapperAddressReturnWord ⟨3⟩ σ_solm I) ≠ ⟨0⟩ := flapperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨3⟩ hcodeSize have hbody : @@ -2734,7 +2734,7 @@ theorem flapperYankBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} · exact flapperYankBodyCoreGuyNotSet hcode hsize hwv hsz36 hlive hguy hdispatch hdecode hreach hAccounts · by_cases hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flapperAddressReturnWord ⟨3⟩ σ_evm I) = ⟨0⟩ · exact flapperYankBodyCoreMoveNoCode hcode hsize hwv hsz36 hlive hguy hcodeSize hdispatch hdecode hreach hAccounts diff --git a/Benchmarks/Dss/Flipper/CheckedMul.lean b/Benchmarks/Dss/Flipper/CheckedMul.lean index 00957c10..4021c96d 100644 --- a/Benchmarks/Dss/Flipper/CheckedMul.lean +++ b/Benchmarks/Dss/Flipper/CheckedMul.lean @@ -412,7 +412,7 @@ theorem flipperCheckedMulRevert {cA σ I} {g : Sat256} {s0 : State} raw push2 ⟨6299⟩ (by native_decide) (by evm_ov), raw jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov)] - exact RD.uniswapPush1Dup1Revert0 rd6337 + exact RD.solcPush1Dup1Revert0 rd6337 (by native_decide) (by native_decide) (by native_decide) (by evm_ov) end Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/Constructor.lean b/Benchmarks/Dss/Flipper/Constructor.lean index e2d25e40..04cf7780 100644 --- a/Benchmarks/Dss/Flipper/Constructor.lean +++ b/Benchmarks/Dss/Flipper/Constructor.lean @@ -1040,7 +1040,7 @@ theorem flipperCtorNonpayableRDrev have rd73 := rd72.jumpiNT (by flipper_ctor_decode) (isZero_eq_zero_of_ne hwv) (by simp only [List.length_cons, List.length_nil]; omega) simpa [code] using - RD.uniswapPush1Dup1Revert0 (code := code) (ee := I) (g := g) + RD.solcPush1Dup1Revert0 (code := code) (ee := I) (g := g) (s0 := initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) rd73 (by flipper_ctor_decode) (by flipper_ctor_decode) (by flipper_ctor_decode) (by simp only [List.length_cons, List.length_nil]; omega) diff --git a/Benchmarks/Dss/Flipper/Deal.lean b/Benchmarks/Dss/Flipper/Deal.lean index c81d3611..4b2011fd 100644 --- a/Benchmarks/Dss/Flipper/Deal.lean +++ b/Benchmarks/Dss/Flipper/Deal.lean @@ -173,7 +173,7 @@ theorem flipperDealBodyCoreCatNoCodeEndExpired {cA gh bl σ_evm σ_solm σ₀ A (hendLtEvm : (bidEndWord (dealId I) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat) (hcatZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (flipperCatTargetWord σ_evm I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ_evm (flipperCatTargetWord σ_evm I) = ⟨0⟩) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by have hsz4 : 4 ≤ I.calldata.size := calldata_size_ge_of_selIs I (flipperSelBytes 3) rfl hsel @@ -215,7 +215,7 @@ theorem flipperDealBodyCoreCatNoCodeEndExpired {cA gh bl σ_evm σ_solm σ₀ A (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hticNeSolm hticGeSolm hendLtSolm have hcatZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (flipperCatTargetWord σ_solm I) = ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (flipperCatTargetWord σ_solm I) = ⟨0⟩ := flipperCatCodeSize_zero_accountMapEquiv hAccounts hcatZero have hcatNoCode := flipperCatCode_zero_of_codeSize_zero (cA := cA) (gh := gh) (bl := bl) @@ -241,7 +241,7 @@ theorem flipperDealBodyCoreCatNoCodeTicExpired {cA gh bl σ_evm σ_solm σ₀ A (hticLtEvm : (bidTicWord (dealId I) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat) (hcatZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (flipperCatTargetWord σ_evm I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ_evm (flipperCatTargetWord σ_evm I) = ⟨0⟩) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by have hsz4 : 4 ≤ I.calldata.size := calldata_size_ge_of_selIs I (flipperSelBytes 3) rfl hsel @@ -278,7 +278,7 @@ theorem flipperDealBodyCoreCatNoCodeTicExpired {cA gh bl σ_evm σ_solm σ₀ A (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hticNeSolm hticLtSolm have hcatZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (flipperCatTargetWord σ_solm I) = ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (flipperCatTargetWord σ_solm I) = ⟨0⟩ := flipperCatCodeSize_zero_accountMapEquiv hAccounts hcatZero have hcatNoCode := flipperCatCode_zero_of_codeSize_zero (cA := cA) (gh := gh) (bl := bl) @@ -310,7 +310,7 @@ theorem flipperDealBodyCoreCatCallDepthLimit {cA gh bl σ_evm σ_solm σ₀ A I} (bidEndWord (dealId I) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat)) (hcatNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (flipperCatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (flipperCatTargetWord σ_evm I) ≠ ⟨0⟩) (hdepthEq : I.depth = 1024) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by have hsz4 : 4 ≤ I.calldata.size := @@ -369,7 +369,7 @@ theorem flipperDealBodyCoreCatCallDepthLimit {cA gh bl σ_evm σ_solm σ₀ A I} (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hticNeSolm hticGeSolm hendLtSolm have hcatNeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (flipperCatTargetWord σ_solm I) ≠ + Reasoning.Theory.extCodeSizeWord σ_solm (flipperCatTargetWord σ_solm I) ≠ ⟨0⟩ := flipperCatCodeSize_ne_zero_accountMapEquiv hAccounts hcatNe have hcatCode := flipperCatCode_pos_of_codeSize_ne_zero (cA := cA) (gh := gh) (bl := bl) @@ -418,7 +418,7 @@ theorem flipperDealBodyCoreCatPostCall {cA gh bl σ_evm σ_solm σ₀ A I} (bidEndWord (dealId I) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat)) (hcatNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (flipperCatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (flipperCatTargetWord σ_evm I) ≠ ⟨0⟩) (hdepthNe : I.depth ≠ 1024) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by have hsz4 : 4 ≤ I.calldata.size := @@ -477,7 +477,7 @@ theorem flipperDealBodyCoreCatPostCall {cA gh bl σ_evm σ_solm σ₀ A I} (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hticNeSolm hticGeSolm hendLtSolm have hcatNeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (flipperCatTargetWord σ_solm I) ≠ + Reasoning.Theory.extCodeSizeWord σ_solm (flipperCatTargetWord σ_solm I) ≠ ⟨0⟩ := flipperCatCodeSize_ne_zero_accountMapEquiv hAccounts hcatNe have hcatCode := flipperCatCode_pos_of_codeSize_ne_zero (cA := cA) (gh := gh) (bl := bl) @@ -575,9 +575,9 @@ theorem flipperDealBodyCoreCatPostCall {cA gh bl σ_evm σ_solm σ₀ A I} simpa [evmCatEvm, evmCatSolm] using hCatStateEquiv'.accountMap obtain ⟨_, _, rd5673⟩ := flipperDealX_catCallSuccessToVatStart rd5654True by_cases hvatZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ_cat (flipperVatTargetWord σ_cat I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_cat (flipperVatTargetWord σ_cat I) = ⟨0⟩ · have hvatZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_cat_solm + Reasoning.Theory.extCodeSizeWord σ_cat_solm (flipperVatTargetWord σ_cat_solm I) = ⟨0⟩ := flipperVatCodeSize_zero_accountMapEquiv hAccountsCat hvatZero have hvatNoCode : @@ -586,7 +586,7 @@ theorem flipperDealBodyCoreCatPostCall {cA gh bl σ_evm σ_solm σ₀ A I} (flipperVatAddress evmCatSolm.accountMap evmCatSolm.executionEnv)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [evmCatSolm, evm0Solm, initState, State.lookupAccount] using - flipper_uniswapExtCodeSizeWord_zero_lookup_code_zero + flipper_extCodeSizeWord_zero_lookup_code_zero (σ := σ_cat_solm) (target := flipperVatTargetWord σ_cat_solm I) (addr := flipperVatAddress σ_cat_solm I) (flipperVatAddress_eq_target σ_cat_solm I) hvatZeroSolm @@ -601,7 +601,7 @@ theorem flipperDealBodyCoreCatPostCall {cA gh bl σ_evm σ_solm σ₀ A I} exact (flipperDealX_vatNoCode hvatZero rd5673) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatNeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_cat_solm + Reasoning.Theory.extCodeSizeWord σ_cat_solm (flipperVatTargetWord σ_cat_solm I) ≠ ⟨0⟩ := flipperVatCodeSize_ne_zero_accountMapEquiv hAccountsCat hvatZero have hvatCodeSolm : @@ -611,7 +611,7 @@ theorem flipperDealBodyCoreCatPostCall {cA gh bl σ_evm σ_solm σ₀ A I} (flipperVatAddress evmCatSolm.accountMap evmCatSolm.executionEnv)).option 0 (fun acc => acc.code.size))).toNat := by simpa [evmCatSolm, evm0Solm, initState, State.lookupAccount] using - flipper_uniswapExtCodeSizeWord_pos_lookup_code_pos + flipper_extCodeSizeWord_pos_lookup_code_pos (σ := σ_cat_solm) (target := flipperVatTargetWord σ_cat_solm I) (addr := flipperVatAddress σ_cat_solm I) (flipperVatAddress_eq_target σ_cat_solm I) hvatNeSolm @@ -790,7 +790,7 @@ theorem flipperDealBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (bidTicWord (dealId I) σ_evm I).toNat ∧ (bidEndWord (dealId I) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat) → - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flipperCatTargetWord σ_evm I) ≠ ⟨0⟩ → runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by intro hfinishedEvm hcatNe @@ -805,7 +805,7 @@ theorem flipperDealBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (bidTicWord (dealId I) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat · by_cases hcatZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flipperCatTargetWord σ_evm I) = ⟨0⟩ · exact flipperDealBodyCoreCatNoCodeTicExpired hcode hsize hwv hsel hAccounts hsz36 hticEvm hticLtEvm hcatZero @@ -818,7 +818,7 @@ theorem flipperDealBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (bidEndWord (dealId I) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat · by_cases hcatZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flipperCatTargetWord σ_evm I) = ⟨0⟩ · exact flipperDealBodyCoreCatNoCodeEndExpired hcode hsize hwv hsel hAccounts hsz36 hticEvm hticGeEvm hendLtEvm hcatZero diff --git a/Benchmarks/Dss/Flipper/DealEVM.lean b/Benchmarks/Dss/Flipper/DealEVM.lean index 0600c044..421c376c 100644 --- a/Benchmarks/Dss/Flipper/DealEVM.lean +++ b/Benchmarks/Dss/Flipper/DealEVM.lean @@ -1276,12 +1276,12 @@ theorem flipperDealX_toCatExtcodesizeGuard {cA σ I} {g : Sat256} {s0 : State} theorem flipperDealX_catNoCode {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} {ret sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperCatTargetWord σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperCatTargetWord σ I) = ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨5558⟩ [dealId I, ret, sel] (dealHashMem2 I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : RDrev flipperBytecode g s0 := by obtain ⟨_, _, rd5638⟩ := flipperDealX_toCatExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨5638⟩) (okPc := ⟨5650⟩) rd5638 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨5638⟩) (okPc := ⟨5650⟩) rd5638 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1290,7 +1290,7 @@ theorem flipperDealX_catNoCode {cA σ I} {g : Sat256} {s0 : State} theorem flipperDealX_toCatCall {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} {ret sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨5558⟩ [dealId I, ret, sel] (dealHashMem2 I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : ∃ gasWord k' C', RD flipperBytecode I g s0 ⟨5653⟩ @@ -1300,7 +1300,7 @@ theorem flipperDealX_toCatCall {cA σ I} {g : Sat256} {s0 : State} (dealCatCallMem σ I) (UInt256.ofNat 6) ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd5638⟩ := flipperDealX_toCatExtcodesizeGuard h obtain ⟨gasWord, k5653, C5653, rd5653⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨5638⟩) (okPc := ⟨5650⟩) rd5638 + RD.solcExtcodesizeGuardOkGas (pc := ⟨5638⟩) (okPc := ⟨5650⟩) rd5638 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1310,7 +1310,7 @@ theorem flipperDealX_toCatCall {cA σ I} {g : Sat256} {s0 : State} theorem flipperDealX_catPostCall {cA gh bl σ σ₀ A I} {g : UInt256} {k C : ℕ} {ret sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) (h : RD flipperBytecode I (Sat256.ofUInt256 g) @@ -1375,7 +1375,7 @@ theorem flipperDealX_catCallFailure {I} {g : Sat256} {s0 : State} mem aw out acc k C) (houtsz : out.size < UInt256.size) : RDrev flipperBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨5654⟩) (okPc := ⟨5670⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨5654⟩) (okPc := ⟨5670⟩) h (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1385,7 +1385,7 @@ theorem flipperDealX_catCallFailure {I} {g : Sat256} {s0 : State} theorem flipperDealX_catCallDepthLimit {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} {ret sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (h : RD flipperBytecode I g s0 ⟨5558⟩ [dealId I, ret, sel] (dealHashMem2 I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : @@ -1425,7 +1425,7 @@ theorem flipperDealX_catCallSuccessToVatStart {I} {g : Sat256} {s0 : State} (selector :: target :: id :: ret :: sel :: []) mem aw out acc k' C' := by obtain ⟨k5672, C5672, rd5672⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨5654⟩) (okPc := ⟨5670⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨5654⟩) (okPc := ⟨5670⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1555,7 +1555,7 @@ theorem flipperDealX_toVatExtcodesizeGuard {cA σmem σ I} {g : Sat256} {s0 : St raw swap5 (by native_decide) (by evm_ov), raw mstore 0 (dealVatFluxIlkMem σmem σ I) (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov)] - have rd5727 := RD.uniswapAddress rd5726 (by native_decide) (by evm_ov) + have rd5727 := RD.address rd5726 (by native_decide) (by evm_ov) have rd5782 := evm_run rd5727 with [ raw push1 ⟨36⟩ (by native_decide) (by evm_ov), raw dup6 (by native_decide) (by evm_ov), @@ -1619,13 +1619,13 @@ theorem flipperDealX_toVatExtcodesizeGuard {cA σmem σ I} {g : Sat256} {s0 : St theorem flipperDealX_vatNoCode {cA σmem σ I} {g : Sat256} {s0 : State} {k C : ℕ} {out : ByteArray} {ret sel selector target : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨5673⟩ (selector :: target :: dealId I :: ret :: sel :: []) (dealCatCallMem σmem I) (UInt256.ofNat 6) out (cA, σ) k C) : RDrev flipperBytecode g s0 := by obtain ⟨_, _, rd5782⟩ := flipperDealX_toVatExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨5782⟩) (okPc := ⟨1611⟩) rd5782 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨5782⟩) (okPc := ⟨1611⟩) rd5782 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1634,7 +1634,7 @@ theorem flipperDealX_vatNoCode {cA σmem σ I} {g : Sat256} {s0 : State} theorem flipperDealX_toVatCall {cA σmem σ I} {g : Sat256} {s0 : State} {k C : ℕ} {out : ByteArray} {ret sel selector target : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨5673⟩ (selector :: target :: dealId I :: ret :: sel :: []) (dealCatCallMem σmem I) (UInt256.ofNat 6) out (cA, σ) k C) : @@ -1645,7 +1645,7 @@ theorem flipperDealX_toVatCall {cA σmem σ I} {g : Sat256} {s0 : State} (dealVatFluxCallMem σmem σ I) (UInt256.ofNat 9) out (cA, σ) k' C' := by obtain ⟨_, _, rd5782⟩ := flipperDealX_toVatExtcodesizeGuard h obtain ⟨gasWord, k1614, C1614, rd1614⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨5782⟩) (okPc := ⟨1611⟩) rd5782 + RD.solcExtcodesizeGuardOkGas (pc := ⟨5782⟩) (okPc := ⟨1611⟩) rd5782 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1657,7 +1657,7 @@ theorem flipperDealX_vatPostCall {cA : Batteries.RBSet AccountAddress compare} {σmem σ : AccountMap} {Acur : Substate} {k C : ℕ} {out0 : ByteArray} {ret sel selector target : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) (h : RD flipperBytecode I (Sat256.ofUInt256 g) @@ -1731,7 +1731,7 @@ theorem flipperDealX_vatCallFailure {I} {g : Sat256} {s0 : State} mem aw out acc k C) (houtsz : out.size < UInt256.size) : RDrev flipperBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1615⟩) (okPc := ⟨1631⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨1615⟩) (okPc := ⟨1631⟩) h (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1741,7 +1741,7 @@ theorem flipperDealX_vatCallFailure {I} {g : Sat256} {s0 : State} theorem flipperDealX_vatCallDepthLimit {cA σmem σ I} {g : Sat256} {s0 : State} {k C : ℕ} {out : ByteArray} {ret sel selector target : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (h : RD flipperBytecode I g s0 ⟨5673⟩ (selector :: target :: dealId I :: ret :: sel :: []) @@ -1783,7 +1783,7 @@ theorem flipperDealX_vatCallSuccessToDeleteStart {I} {g : Sat256} {s0 : State} (⟨260⟩ :: selector :: target :: id :: ret :: sel :: []) mem aw out acc k' C' := by obtain ⟨k1633, C1633, rd1633⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨1615⟩) (okPc := ⟨1631⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨1615⟩) (okPc := ⟨1631⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Flipper/DentRefundEVM.lean b/Benchmarks/Dss/Flipper/DentRefundEVM.lean index d2212f75..79df7ec8 100644 --- a/Benchmarks/Dss/Flipper/DentRefundEVM.lean +++ b/Benchmarks/Dss/Flipper/DentRefundEVM.lean @@ -274,13 +274,13 @@ theorem flipperDentX_refundNoCode {cA σ I} {g : Sat256} {s0 : State} (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcaller : solcSourceWord I ≠ bidGuyWord (dentId I) σ I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨4733⟩ [dentBid I, dentLot I, dentId I, ret, sel] mem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : RDrev flipperBytecode g s0 := by obtain ⟨_, _, rd4857⟩ := flipperDentX_toRefundExtcodesizeGuard hmemSize hmemRead64 hcaller h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4857⟩) (okPc := ⟨4869⟩) rd4857 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4857⟩) (okPc := ⟨4869⟩) rd4857 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -292,7 +292,7 @@ theorem flipperDentX_toRefundCall {cA σ I} {g : Sat256} {s0 : State} (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcaller : solcSourceWord I ≠ bidGuyWord (dentId I) σ I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨4733⟩ [dentBid I, dentLot I, dentId I, ret, sel] mem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : ∃ gasWord k' C', RD flipperBytecode I g s0 ⟨4872⟩ @@ -304,7 +304,7 @@ theorem flipperDentX_toRefundCall {cA σ I} {g : Sat256} {s0 : State} obtain ⟨_, _, rd4857⟩ := flipperDentX_toRefundExtcodesizeGuard hmemSize hmemRead64 hcaller h obtain ⟨gasWord, k4872, C4872, rd4872⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4857⟩) (okPc := ⟨4869⟩) rd4857 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4857⟩) (okPc := ⟨4869⟩) rd4857 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -317,7 +317,7 @@ theorem flipperDentX_refundDepthLimit {cA σ I} {g : Sat256} {s0 : State} (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcaller : solcSourceWord I ≠ bidGuyWord (dentId I) σ I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = (1024 : Fin 1025)) (h : RD flipperBytecode I g s0 ⟨4733⟩ [dentBid I, dentLot I, dentId I, ret, sel] mem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : @@ -357,7 +357,7 @@ theorem flipperDentX_refundPostCall (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcaller : solcSourceWord I ≠ bidGuyWord (dentId I) σ I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) (h : RD flipperBytecode I (Sat256.ofUInt256 g) @@ -438,7 +438,7 @@ theorem flipperDentX_refundCallFailure {I} {g : Sat256} {s0 : State} mem aw out acc k C) (houtsz : out.size < UInt256.size) : RDrev flipperBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨4873⟩) (okPc := ⟨4889⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨4873⟩) (okPc := ⟨4889⟩) h (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -454,7 +454,7 @@ theorem flipperDentX_refundCallSuccessToStoreStart {I} {g : Sat256} {s0 : State} ∃ k' C', RD flipperBytecode I g s0 ⟨4893⟩ (target :: bid :: lot :: id :: ret :: sel :: []) mem aw out acc k' C' := by obtain ⟨_, _, rd4889⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨4873⟩) (okPc := ⟨4889⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨4873⟩) (okPc := ⟨4889⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -937,7 +937,7 @@ theorem flipperDentX_toFluxExtcodesizeGuardAw8 {cA σ I} {g : Sat256} {s0 : Stat raw swap5 (by native_decide) (by evm_ov), raw mstore 0 memIlk (UInt256.ofNat 8) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov)] - have rd4981 := RD.uniswapAddress rd4980 (by native_decide) (by evm_ov) + have rd4981 := RD.address rd4980 (by native_decide) (by evm_ov) have rd4986 := evm_run rd4981 with [ raw push1 ⟨36⟩ (by native_decide) (by evm_ov), raw dup6 (by native_decide) (by evm_ov), @@ -1006,14 +1006,14 @@ theorem flipperDentX_fluxNoCodeAw8 {cA σ I} {g : Sat256} {s0 : State} (hmemSize : mem.size = 228) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨4927⟩ [dentBid I, dentLot I, dentId I, ret, sel] mem (UInt256.ofNat 8) out (cA, σ) k C) : RDrev flipperBytecode g s0 := by obtain ⟨_, _, rd5037⟩ := flipperDentX_toFluxExtcodesizeGuardAw8 hmemSize hmemRead64 h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨5037⟩) (okPc := ⟨5049⟩) rd5037 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨5037⟩) (okPc := ⟨5049⟩) rd5037 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1024,7 +1024,7 @@ theorem flipperDentX_toFluxCallAw8 {cA σ I} {g : Sat256} {s0 : State} (hmemSize : mem.size = 228) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨4927⟩ [dentBid I, dentLot I, dentId I, ret, sel] mem (UInt256.ofNat 8) out (cA, σ) k C) : @@ -1037,7 +1037,7 @@ theorem flipperDentX_toFluxCallAw8 {cA σ I} {g : Sat256} {s0 : State} obtain ⟨_, _, rd5037⟩ := flipperDentX_toFluxExtcodesizeGuardAw8 hmemSize hmemRead64 h obtain ⟨gasWord, k5052, C5052, rd5052⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨5037⟩) (okPc := ⟨5049⟩) rd5037 + RD.solcExtcodesizeGuardOkGas (pc := ⟨5037⟩) (okPc := ⟨5049⟩) rd5037 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1051,7 +1051,7 @@ theorem flipperDentX_fluxPostCallAw8 (hmemSize : mem.size = 228) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) (h : RD flipperBytecode I (Sat256.ofUInt256 g) diff --git a/Benchmarks/Dss/Flipper/DentRefundMain.lean b/Benchmarks/Dss/Flipper/DentRefundMain.lean index 5d9cf740..3300357f 100644 --- a/Benchmarks/Dss/Flipper/DentRefundMain.lean +++ b/Benchmarks/Dss/Flipper/DentRefundMain.lean @@ -71,10 +71,10 @@ theorem flipperDentBodyFrom4733Refund dsimp [memHash] exact twoWordHashMem_read64 (dentId I) ⟨1⟩ hmemSize hmemRead64 by_cases hrefundZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flipperVatTargetWord σ_evm I) = ⟨0⟩ · have hrefundZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flipperVatTargetWord σ_solm I) = ⟨0⟩ := flipperVatCodeSize_zero_accountMapEquiv hAccounts hrefundZero have hvatNoCode := @@ -92,7 +92,7 @@ theorem flipperDentBodyFrom4733Refund exact (flipperDentX_refundNoCode hmemSize hmemRead64 hcallerEvm hrefundZero h) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hrefundNeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flipperVatTargetWord σ_solm I) ≠ ⟨0⟩ := flipperVatCodeSize_ne_zero_accountMapEquiv hAccounts hrefundZero have hrefundCodeSolm := @@ -315,14 +315,14 @@ theorem flipperDentBodyFrom4733Refund (true, evmRefundSolm, outRefund) true := by simpa using hcallRefundSolm by_cases hfluxZero : - Reasoning.Theory.uniswapExtCodeSizeWord (dentAfterRefundMap σ_ref I) + Reasoning.Theory.extCodeSizeWord (dentAfterRefundMap σ_ref I) (flipperVatTargetWord (dentAfterRefundMap σ_ref I) I) = ⟨0⟩ · have hfluxZeroEvm : - Reasoning.Theory.uniswapExtCodeSizeWord evmGuyEvm.accountMap + Reasoning.Theory.extCodeSizeWord evmGuyEvm.accountMap (flipperVatTargetWord evmGuyEvm.accountMap I) = ⟨0⟩ := by simpa [hmapGuyEvm] using hfluxZero have hfluxZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmGuySolm.accountMap + Reasoning.Theory.extCodeSizeWord evmGuySolm.accountMap (flipperVatTargetWord evmGuySolm.accountMap I) = ⟨0⟩ := flipperVatCodeSize_zero_accountMapEquiv hGuyStateEquiv.accountMap hfluxZeroEvm have hfluxNoCodeSolm : @@ -333,7 +333,7 @@ theorem flipperDentBodyFrom4733Refund 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [evmGuySolm, evmRefundSolm, evm0Solm, initState, storageStore_executionEnv, State.lookupAccount] using - flipper_uniswapExtCodeSizeWord_zero_lookup_code_zero + flipper_extCodeSizeWord_zero_lookup_code_zero (σ := evmGuySolm.accountMap) (target := flipperVatTargetWord evmGuySolm.accountMap I) (addr := flipperVatAddress evmGuySolm.accountMap I) @@ -352,11 +352,11 @@ theorem flipperDentBodyFrom4733Refund exact (flipperDentX_fluxNoCodeAw8 hmemFluxSize hmemFluxRead64 hfluxZero rd4927) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hfluxNeEvm : - Reasoning.Theory.uniswapExtCodeSizeWord evmGuyEvm.accountMap + Reasoning.Theory.extCodeSizeWord evmGuyEvm.accountMap (flipperVatTargetWord evmGuyEvm.accountMap I) ≠ ⟨0⟩ := by simpa [hmapGuyEvm] using hfluxZero have hfluxNeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmGuySolm.accountMap + Reasoning.Theory.extCodeSizeWord evmGuySolm.accountMap (flipperVatTargetWord evmGuySolm.accountMap I) ≠ ⟨0⟩ := flipperVatCodeSize_ne_zero_accountMapEquiv hGuyStateEquiv.accountMap hfluxNeEvm have hfluxCodeSolm : @@ -368,7 +368,7 @@ theorem flipperDentBodyFrom4733Refund 0 (fun acc => acc.code.size))).toNat := by simpa [evmGuySolm, evmRefundSolm, evm0Solm, initState, storageStore_executionEnv, State.lookupAccount] using - flipper_uniswapExtCodeSizeWord_pos_lookup_code_pos + flipper_extCodeSizeWord_pos_lookup_code_pos (σ := evmGuySolm.accountMap) (target := flipperVatTargetWord evmGuySolm.accountMap I) (addr := flipperVatAddress evmGuySolm.accountMap I) diff --git a/Benchmarks/Dss/Flipper/DentSameCaller.lean b/Benchmarks/Dss/Flipper/DentSameCaller.lean index 5da66eae..f7594e65 100644 --- a/Benchmarks/Dss/Flipper/DentSameCaller.lean +++ b/Benchmarks/Dss/Flipper/DentSameCaller.lean @@ -74,9 +74,9 @@ theorem flipperDentBodyFrom4733SameCaller dsimp [memFlux] exact twoWordHashMem_read64 (dentId I) ⟨1⟩ hmemSize hmemRead64 by_cases hfluxZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (flipperVatTargetWord σ_evm I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_evm (flipperVatTargetWord σ_evm I) = ⟨0⟩ · have hfluxZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flipperVatTargetWord σ_solm I) = ⟨0⟩ := flipperVatCodeSize_zero_accountMapEquiv hAccounts hfluxZero have hvatNoCode := @@ -94,7 +94,7 @@ theorem flipperDentBodyFrom4733SameCaller exact (flipperDentX_fluxNoCode hmemFluxSize hmemFluxRead64 hfluxZero rd4927) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hfluxNeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flipperVatTargetWord σ_solm I) ≠ ⟨0⟩ := flipperVatCodeSize_ne_zero_accountMapEquiv hAccounts hfluxZero have hvatCodeSolm := diff --git a/Benchmarks/Dss/Flipper/DentTail.lean b/Benchmarks/Dss/Flipper/DentTail.lean index 8f628928..12ee90b0 100644 --- a/Benchmarks/Dss/Flipper/DentTail.lean +++ b/Benchmarks/Dss/Flipper/DentTail.lean @@ -1446,7 +1446,7 @@ theorem flipperDentX_toFluxExtcodesizeGuard {cA σ I} {g : Sat256} {s0 : State} raw swap5 (by native_decide) (by evm_ov), raw mstore 3 memIlk (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov)] - have rd4981 := RD.uniswapAddress rd4980 (by native_decide) (by evm_ov) + have rd4981 := RD.address rd4980 (by native_decide) (by evm_ov) have rd4986 := evm_run rd4981 with [ raw push1 ⟨36⟩ (by native_decide) (by evm_ov), raw dup6 (by native_decide) (by evm_ov), @@ -1521,13 +1521,13 @@ theorem flipperDentX_fluxNoCode {cA σ I} {g : Sat256} {s0 : State} (hmemSize : mem.size = 96) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨4927⟩ [dentBid I, dentLot I, dentId I, ret, sel] mem (UInt256.ofNat 3) out (cA, σ) k C) : RDrev flipperBytecode g s0 := by obtain ⟨_, _, rd5037⟩ := flipperDentX_toFluxExtcodesizeGuard hmemSize hmemRead64 h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨5037⟩) (okPc := ⟨5049⟩) rd5037 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨5037⟩) (okPc := ⟨5049⟩) rd5037 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1538,7 +1538,7 @@ theorem flipperDentX_toFluxCall {cA σ I} {g : Sat256} {s0 : State} (hmemSize : mem.size = 96) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨4927⟩ [dentBid I, dentLot I, dentId I, ret, sel] mem (UInt256.ofNat 3) out (cA, σ) k C) : @@ -1550,7 +1550,7 @@ theorem flipperDentX_toFluxCall {cA σ I} {g : Sat256} {s0 : State} (dentVatFluxCallMem mem σ I) (UInt256.ofNat 9) out (cA, σ) k' C' := by obtain ⟨_, _, rd5037⟩ := flipperDentX_toFluxExtcodesizeGuard hmemSize hmemRead64 h obtain ⟨gasWord, k5052, C5052, rd5052⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨5037⟩) (okPc := ⟨5049⟩) rd5037 + RD.solcExtcodesizeGuardOkGas (pc := ⟨5037⟩) (okPc := ⟨5049⟩) rd5037 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1564,7 +1564,7 @@ theorem flipperDentX_fluxPostCall (hmemSize : mem.size = 96) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) (h : RD flipperBytecode I (Sat256.ofUInt256 g) @@ -1641,7 +1641,7 @@ theorem flipperDentX_fluxCallFailure {I} {g : Sat256} {s0 : State} mem aw out acc k C) (houtsz : out.size < UInt256.size) : RDrev flipperBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨5053⟩) (okPc := ⟨5069⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨5053⟩) (okPc := ⟨5069⟩) h (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1653,7 +1653,7 @@ theorem flipperDentX_fluxCallDepthLimit {cA σ I} {g : Sat256} {s0 : State} (hmemSize : mem.size = 96) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (h : RD flipperBytecode I g s0 ⟨4927⟩ [dentBid I, dentLot I, dentId I, ret, sel] @@ -1696,7 +1696,7 @@ theorem flipperDentX_fluxCallSuccessToStoreStart {I} {g : Sat256} {s0 : State} ∃ k' C', RD flipperBytecode I g s0 ⟨5073⟩ (target :: bid :: lot :: id :: ret :: sel :: []) mem aw out acc k' C' := by obtain ⟨k5071, C5071, rd5071⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨5053⟩) (okPc := ⟨5069⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨5053⟩) (okPc := ⟨5069⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1857,7 +1857,7 @@ theorem flipperDentX_add48Overflow {cA σ I} {g : Sat256} {s0 : State} rw [show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rd6290 have rd6295 := rd6290.push2 ⟨6299⟩ (by native_decide) (by evm_ov) |>.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd6295 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd6295 (by native_decide) (by native_decide) (by native_decide) (by evm_ov) theorem flipperDentX_storeTicReturn {cA σ I} {g : Sat256} {s0 : State} diff --git a/Benchmarks/Dss/Flipper/Dispatch.lean b/Benchmarks/Dss/Flipper/Dispatch.lean index cc904d63..07b86194 100644 --- a/Benchmarks/Dss/Flipper/Dispatch.lean +++ b/Benchmarks/Dss/Flipper/Dispatch.lean @@ -232,7 +232,7 @@ theorem flipperX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) /-- `callvalue ≠ 0` makes the global non-payable guard revert before dispatch. -/ @@ -744,7 +744,7 @@ theorem flipperJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : UI (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h289 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h289 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem flipperLowHighNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -829,7 +829,7 @@ theorem flipperHighLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : |>.selectorArmNotTakenAuto (flipperHighLowArmsWellFormed 3 (by omega)) (heq0 3 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h289 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h289 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem flipperX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -852,7 +852,7 @@ theorem flipperX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h289 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h289 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem flipperX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} diff --git a/Benchmarks/Dss/Flipper/ExternalTargets.lean b/Benchmarks/Dss/Flipper/ExternalTargets.lean index fd55dbfb..005d0849 100644 --- a/Benchmarks/Dss/Flipper/ExternalTargets.lean +++ b/Benchmarks/Dss/Flipper/ExternalTargets.lean @@ -49,10 +49,10 @@ theorem flipperCatAddress_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv theorem flipperVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flipperVatTargetWord τ I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (flipperVatTargetWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (flipperVatTargetWord σ I) have htarget : flipperVatTargetWord σ I = flipperVatTargetWord τ I := flipperVatTargetWord_accountMapEquiv hAccounts @@ -62,10 +62,10 @@ theorem flipperVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execut theorem flipperCatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperCatTargetWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flipperCatTargetWord τ I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (flipperCatTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (flipperCatTargetWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (flipperCatTargetWord σ I) have htarget : flipperCatTargetWord σ I = flipperCatTargetWord τ I := flipperCatTargetWord_accountMapEquiv hAccounts @@ -75,16 +75,16 @@ theorem flipperCatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execut theorem flipperVatCodeSize_ne_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flipperVatTargetWord τ I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (flipperVatTargetWord τ I) ≠ ⟨0⟩ := by intro hzero exact hne (flipperVatCodeSize_zero_accountMapEquiv hAccounts.symm hzero) theorem flipperCatCodeSize_ne_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flipperCatTargetWord τ I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (flipperCatTargetWord τ I) ≠ ⟨0⟩ := by intro hzero exact hne (flipperCatCodeSize_zero_accountMapEquiv hAccounts.symm hzero) @@ -133,14 +133,14 @@ theorem flipperCatEvmAddress_eq_target_of_accountMapEquiv {σ_evm σ_solm : Acco rw [haddr] exact flipperEvmAddress_accountAddress _ -theorem flipper_uniswapExtCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} +theorem flipper_extCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using @@ -149,10 +149,10 @@ theorem flipper_uniswapExtCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} { have hword := congrArg UInt256.toNat hzero simpa [hacc] using hword -theorem flipper_uniswapExtCodeSizeWord_pos_lookup_code_pos {σ : AccountMap} {target : UInt256} +theorem flipper_extCodeSizeWord_pos_lookup_code_pos {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by @@ -166,38 +166,38 @@ theorem flipper_uniswapExtCodeSizeWord_pos_lookup_code_pos {σ : AccountMap} {ta uint256_toNat_eq_zero hnat have hword : UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size)) = - Reasoning.Theory.uniswapExtCodeSizeWord σ target := by + Reasoning.Theory.extCodeSizeWord σ target := by subst addr cases hacc : σ.find? (AccountAddress.ofUInt256 target) <;> - simp [Reasoning.Theory.uniswapExtCodeSizeWord, hacc, Option.option] <;> + simp [Reasoning.Theory.extCodeSizeWord, hacc, Option.option] <;> native_decide exact hne (by rw [← hword, hwordZero]) theorem flipperVatCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt256} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (flipperVatAddress σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [initState, State.lookupAccount] using - flipper_uniswapExtCodeSizeWord_zero_lookup_code_zero + flipper_extCodeSizeWord_zero_lookup_code_zero (σ := σ) (target := flipperVatTargetWord σ I) (addr := flipperVatAddress σ I) (flipperVatAddress_eq_target σ I) hzero theorem flipperCatCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt256} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperCatTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (flipperCatTargetWord σ I) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (flipperCatAddress σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [initState, State.lookupAccount] using - flipper_uniswapExtCodeSizeWord_zero_lookup_code_zero + flipper_extCodeSizeWord_zero_lookup_code_zero (σ := σ) (target := flipperCatTargetWord σ I) (addr := flipperCatAddress σ I) (flipperCatAddress_eq_target σ I) hzero theorem flipperVatCode_pos_of_codeSize_ne_zero {cA gh bl σ σ₀ A I} {g : UInt256} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount @@ -217,16 +217,16 @@ theorem flipperVatCode_pos_of_codeSize_ne_zero {cA gh bl σ σ₀ A I} {g : UInt UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (flipperVatAddress σ I)).option 0 (fun acc => acc.code.size)) = - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) := by + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) := by cases hacc : σ.find? (AccountAddress.ofUInt256 (flipperVatTargetWord σ I)) <;> - simp [initState, State.lookupAccount, Reasoning.Theory.uniswapExtCodeSizeWord, + simp [initState, State.lookupAccount, Reasoning.Theory.extCodeSizeWord, flipperVatAddress_eq_target σ I, hacc, Option.option] <;> native_decide exact hne (by rw [← hword, hwordZero]) theorem flipperCatCode_pos_of_codeSize_ne_zero {cA gh bl σ σ₀ A I} {g : UInt256} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount @@ -246,9 +246,9 @@ theorem flipperCatCode_pos_of_codeSize_ne_zero {cA gh bl σ σ₀ A I} {g : UInt UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (flipperCatAddress σ I)).option 0 (fun acc => acc.code.size)) = - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperCatTargetWord σ I) := by + Reasoning.Theory.extCodeSizeWord σ (flipperCatTargetWord σ I) := by cases hacc : σ.find? (AccountAddress.ofUInt256 (flipperCatTargetWord σ I)) <;> - simp [initState, State.lookupAccount, Reasoning.Theory.uniswapExtCodeSizeWord, + simp [initState, State.lookupAccount, Reasoning.Theory.extCodeSizeWord, flipperCatAddress_eq_target σ I, hacc, Option.option] <;> native_decide exact hne (by rw [← hword, hwordZero]) diff --git a/Benchmarks/Dss/Flipper/Kick.lean b/Benchmarks/Dss/Flipper/Kick.lean index c06a6491..5e688306 100644 --- a/Benchmarks/Dss/Flipper/Kick.lean +++ b/Benchmarks/Dss/Flipper/Kick.lean @@ -1444,7 +1444,7 @@ theorem flipperKickX_add48Overflow {cA σ σtau I} {g : Sat256} {s0 : State} rw [show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rd6290 have rd6295 := rd6290.push2 ⟨6299⟩ (by native_decide) (by evm_ov) |>.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd6295 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd6295 (by native_decide) (by native_decide) (by native_decide) (by evm_ov) theorem flipperKickX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} diff --git a/Benchmarks/Dss/Flipper/KickBody.lean b/Benchmarks/Dss/Flipper/KickBody.lean index 3481100b..21b8cc11 100644 --- a/Benchmarks/Dss/Flipper/KickBody.lean +++ b/Benchmarks/Dss/Flipper/KickBody.lean @@ -1549,10 +1549,10 @@ theorem flipperKickBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} accountMapEquiv_sstoreAccountMap I.codeOwner (bidSlotOfWord (kickIdWord σ_evm I) ⟨5⟩) (kickTab I) hAccountsGal by_cases hvatZero : - Reasoning.Theory.uniswapExtCodeSizeWord (kickAfterTabMap σ_evm I) + Reasoning.Theory.extCodeSizeWord (kickAfterTabMap σ_evm I) (flipperVatTargetWord (kickAfterTabMap σ_evm I) I) = ⟨0⟩ · have hvatZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord (kickAfterTabMap σ_solm I) + Reasoning.Theory.extCodeSizeWord (kickAfterTabMap σ_solm I) (flipperVatTargetWord (kickAfterTabMap σ_solm I) I) = ⟨0⟩ := flipperVatCodeSize_zero_accountMapEquiv hAccountsTab hvatZero have hvatNoCode : @@ -1574,7 +1574,7 @@ theorem flipperKickBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (test_flipperKickX_vatNoCode hvatZero rd2354) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatNeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord (kickAfterTabMap σ_solm I) + Reasoning.Theory.extCodeSizeWord (kickAfterTabMap σ_solm I) (flipperVatTargetWord (kickAfterTabMap σ_solm I) I) ≠ ⟨0⟩ := flipperVatCodeSize_ne_zero_accountMapEquiv hAccountsTab hvatZero have hvatCodeSolm : diff --git a/Benchmarks/Dss/Flipper/KickTail.lean b/Benchmarks/Dss/Flipper/KickTail.lean index 5684e721..61b2f031 100644 --- a/Benchmarks/Dss/Flipper/KickTail.lean +++ b/Benchmarks/Dss/Flipper/KickTail.lean @@ -471,7 +471,7 @@ theorem test_flipperKickX_toVatCallMem {cA σ I} {g : Sat256} {s0 : State} unfold kickVatFluxSenderMem rfl) (by decide) (by evm_ov)] - have rd2381 := RD.uniswapAddress rd2380 (by native_decide) (by evm_ov) + have rd2381 := RD.address rd2380 (by native_decide) (by evm_ov) have rd2386 := evm_run rd2381 with [ raw push1 ⟨68⟩ (by native_decide) (by evm_ov), raw dup4 (by native_decide) (by evm_ov), @@ -658,7 +658,7 @@ theorem test_flipperKickX_toVatExtcodesizeGuard {cA σ I} {g : Sat256} {s0 : Sta theorem test_flipperKickX_vatNoCode {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} {out : ByteArray} {sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (kickAfterTabMap σ I) + Reasoning.Theory.extCodeSizeWord (kickAfterTabMap σ I) (flipperVatTargetWord (kickAfterTabMap σ I) I) = ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨2354⟩ [solcAddrMask, ⟨3⟩, ⟨4⟩, ⟨64⟩, ⟨0⟩, ⟨2⟩, kickIdWord σ I, kickBid I, @@ -666,7 +666,7 @@ theorem test_flipperKickX_vatNoCode {cA σ I} {g : Sat256} {s0 : State} (kickFieldHashMem σ I) (UInt256.ofNat 3) out (cA, kickAfterTabMap σ I) k C) : RDrev flipperBytecode g s0 := by obtain ⟨_, _, rd2422⟩ := test_flipperKickX_toVatExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2422⟩) (okPc := ⟨2434⟩) rd2422 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2422⟩) (okPc := ⟨2434⟩) rd2422 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -675,7 +675,7 @@ theorem test_flipperKickX_vatNoCode {cA σ I} {g : Sat256} {s0 : State} theorem test_flipperKickX_toVatCall {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} {out : ByteArray} {sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (kickAfterTabMap σ I) + Reasoning.Theory.extCodeSizeWord (kickAfterTabMap σ I) (flipperVatTargetWord (kickAfterTabMap σ I) I) ≠ ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨2354⟩ [solcAddrMask, ⟨3⟩, ⟨4⟩, ⟨64⟩, ⟨0⟩, ⟨2⟩, kickIdWord σ I, kickBid I, @@ -690,7 +690,7 @@ theorem test_flipperKickX_toVatCall {cA σ I} {g : Sat256} {s0 : State} (cA, kickAfterTabMap σ I) k' C' := by obtain ⟨_, _, rd2422⟩ := test_flipperKickX_toVatExtcodesizeGuard h obtain ⟨gasWord, k2437, C2437, rd2437⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2422⟩) (okPc := ⟨2434⟩) rd2422 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2422⟩) (okPc := ⟨2434⟩) rd2422 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -702,7 +702,7 @@ theorem test_flipperKickX_vatPostCall {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {Acur : Substate} {k C : ℕ} {out0 : ByteArray} {sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (kickAfterTabMap σ I) + Reasoning.Theory.extCodeSizeWord (kickAfterTabMap σ I) (flipperVatTargetWord (kickAfterTabMap σ I) I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) @@ -782,7 +782,7 @@ theorem test_flipperKickX_vatCallFailure {I} {g : Sat256} {s0 : State} mem aw out acc k C) (houtsz : out.size < UInt256.size) : RDrev flipperBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2438⟩) (okPc := ⟨2454⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨2438⟩) (okPc := ⟨2454⟩) h (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -792,7 +792,7 @@ theorem test_flipperKickX_vatCallFailure {I} {g : Sat256} {s0 : State} theorem test_flipperKickX_vatCallDepthLimit {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} {out : ByteArray} {sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord (kickAfterTabMap σ I) + Reasoning.Theory.extCodeSizeWord (kickAfterTabMap σ I) (flipperVatTargetWord (kickAfterTabMap σ I) I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (h : RD flipperBytecode I g s0 ⟨2354⟩ @@ -841,7 +841,7 @@ theorem test_flipperKickX_vatCallSuccessToLogStart {I} {g : Sat256} {s0 : State} (selector :: target :: id :: bid :: lot :: tab :: gal :: usr :: ret :: sel :: []) mem aw out acc k' C' := by obtain ⟨k2456, C2456, rd2456⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨2438⟩) (okPc := ⟨2454⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨2438⟩) (okPc := ⟨2454⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Flipper/SpecSyntax.lean b/Benchmarks/Dss/Flipper/SpecSyntax.lean index be34893e..d5068a6e 100644 --- a/Benchmarks/Dss/Flipper/SpecSyntax.lean +++ b/Benchmarks/Dss/Flipper/SpecSyntax.lean @@ -2,19 +2,232 @@ import Benchmarks.Dss.Flipper.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS Flipper spec through the Solm notation frontend +# Flipper spec in the Solidity-faithful Solm frontend -The main spec lives in `Spec.lean`; this companion keeps the benchmark's notation-side check wired -up as the body surface grows. +The whole `flip.sol` spec written with `solidity%` and proven definitionally equal to the AST +spec in `Spec.lean`. Checked-math helper statement lists are inlined; the `Bid.end` field is +the guillemet-escaped `«end»`; `extCodeSize` guards on storage receivers use `${…}` escapes. +Transition order matches `contract.transitions` (selector order). -/ -open Solm Solm.Notation +open Solm Solm.Notation Benchmarks.Dss.Flipper namespace Benchmarks.Dss.Flipper.Syntax -def contractSyntax : ContractDecl := Benchmarks.Dss.Flipper.contract +def contractSyntax : ContractDecl := solidity% contract Flipper { + struct Bid { + uint256 bid; + uint256 lot; + address guy; + uint48 tic; + uint48 «end»; + address usr; + address gal; + uint256 tab; + } -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Flipper.contract := by - rfl + mapping(address => uint256) wards; + mapping(uint256 => Bid) bids; + address vat; + bytes32 ilk; + uint256 beg; + uint48 ttl; + uint48 tau; + uint256 kicks; + address cat; + + constructor(address vat_, address cat_, bytes32 ilk_) { + beg = #defaultBeg; + ttl = #defaultTtl; + tau = #defaultTau; + kicks = 0; + vat = vat_; + cat = cat_; + ilk = ilk_; + wards[msg.sender] = 1; + } + + function add(uint48 x, uint48 y) internal returns (uint48) { + uint48 z = (x + y) % #uint48Modulus; + require(z >= x); + return z; + } + + function mul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + return z; + } + + function beg() external returns (uint256) { + return beg; + } + + function bids(uint256 arg0) external returns (uint256, uint256, address, uint48, uint48, address, address, uint256) { + return (bids[arg0].bid, bids[arg0].lot, bids[arg0].guy, bids[arg0].tic, + bids[arg0].«end», bids[arg0].usr, bids[arg0].gal, bids[arg0].tab); + } + + function cat() external returns (address) { + return cat; + } + + function deal(uint256 id) external { + require(bids[id].tic != 0 && (bids[id].tic < block.timestamp || bids[id].«end» < block.timestamp)); + require(${Expr.extCodeSize (.storage catRef)} > 0); + var _clawRet = cat.claw(bids[id].tab); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _fluxRet = vat.flux(ilk, this, bids[id].guy, bids[id].lot); + delete bids[id]; + } + + function dent(uint256 id, uint256 lot, uint256 bid) external { + require(bids[id].guy != address(0)); + require(bids[id].tic > block.timestamp || bids[id].tic == 0); + require(bids[id].«end» > block.timestamp); + require(bid == bids[id].bid); + require(bid == bids[id].tab); + require(lot < bids[id].lot); + uint256 lotOne = (bids[id].lot * #ONE) as uint256; + require(#ONE == 0 || lotOne / #ONE == bids[id].lot); + uint256 begLot = (beg * lot) as uint256; + require(lot == 0 || begLot / lot == beg); + require(begLot <= lotOne); + if (msg.sender != bids[id].guy) { + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _refundRet = vat.move(msg.sender, bids[id].guy, bid); + bids[id].guy = msg.sender; + } + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _fluxRet = vat.flux(ilk, this, bids[id].usr, (bids[id].lot - lot) % #wordModulus); + bids[id].lot = lot; + uint48 tic_ = (block.timestamp % #uint48Modulus + ttl) % #uint48Modulus; + require(tic_ >= block.timestamp % #uint48Modulus); + bids[id].tic = tic_; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function file(bytes32 what, address data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x6361740000000000000000000000000000000000000000000000000000000000)) { + cat = data; + } else { + require(false); + } + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x6265670000000000000000000000000000000000000000000000000000000000)) { + beg = data; + } else if (what == bytes32(0x74746c0000000000000000000000000000000000000000000000000000000000)) { + ttl = data % #uint48Modulus; + } else if (what == bytes32(0x7461750000000000000000000000000000000000000000000000000000000000)) { + tau = data % #uint48Modulus; + } else { + require(false); + } + } + + function ilk() external returns (bytes32) { + return ilk; + } + + function kick(address usr, address gal, uint256 tab, uint256 lot, uint256 bid) external returns (uint256) { + require(wards[msg.sender] == 1); + require(kicks < #maxUint256); + uint256 id = (kicks + 1) % #wordModulus; + kicks = id; + bids[id].bid = bid; + bids[id].lot = lot; + bids[id].guy = msg.sender; + uint48 end_ = (block.timestamp % #uint48Modulus + tau) % #uint48Modulus; + require(end_ >= block.timestamp % #uint48Modulus); + bids[id].«end» = end_; + bids[id].usr = usr; + bids[id].gal = gal; + bids[id].tab = tab; + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _fluxRet = vat.flux(ilk, msg.sender, this, lot); + return id; + } + + function kicks() external returns (uint256) { + return kicks; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 1; + } + + function tau() external returns (uint48) { + return tau; + } + + function tend(uint256 id, uint256 lot, uint256 bid) external { + require(bids[id].guy != address(0)); + require(bids[id].tic > block.timestamp || bids[id].tic == 0); + require(bids[id].«end» > block.timestamp); + require(lot == bids[id].lot); + require(bid <= bids[id].tab); + require(bid > bids[id].bid); + uint256 bidOne = (bid * #ONE) as uint256; + require(#ONE == 0 || bidOne / #ONE == bid); + uint256 begBid = (beg * bids[id].bid) as uint256; + require(bids[id].bid == 0 || begBid / bids[id].bid == beg); + require(bidOne >= begBid || bid == bids[id].tab); + if (msg.sender != bids[id].guy) { + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _refundRet = vat.move(msg.sender, bids[id].guy, bids[id].bid); + bids[id].guy = msg.sender; + } + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _payRet = vat.move(msg.sender, bids[id].gal, (bid - bids[id].bid) % #wordModulus); + bids[id].bid = bid; + uint48 tic_ = (block.timestamp % #uint48Modulus + ttl) % #uint48Modulus; + require(tic_ >= block.timestamp % #uint48Modulus); + bids[id].tic = tic_; + } + + function tick(uint256 id) external { + require(bids[id].«end» < block.timestamp); + require(bids[id].tic == 0); + uint48 end_ = (block.timestamp % #uint48Modulus + tau) % #uint48Modulus; + require(end_ >= block.timestamp % #uint48Modulus); + bids[id].«end» = end_; + } + + function ttl() external returns (uint48) { + return ttl; + } + + function vat() external returns (address) { + return vat; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } + + function yank(uint256 id) external { + require(wards[msg.sender] == 1); + require(bids[id].guy != address(0)); + require(bids[id].bid < bids[id].tab); + require(${Expr.extCodeSize (.storage catRef)} > 0); + var _clawRet = cat.claw(bids[id].tab); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _fluxRet = vat.flux(ilk, this, msg.sender, bids[id].lot); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _moveRet = vat.move(msg.sender, bids[id].guy, bids[id].bid); + delete bids[id]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Flipper.contract := by rfl end Benchmarks.Dss.Flipper.Syntax diff --git a/Benchmarks/Dss/Flipper/TendRefund.lean b/Benchmarks/Dss/Flipper/TendRefund.lean index 4a6a1036..532516bb 100644 --- a/Benchmarks/Dss/Flipper/TendRefund.lean +++ b/Benchmarks/Dss/Flipper/TendRefund.lean @@ -1774,13 +1774,13 @@ theorem flipperTendX_refundNoCode {cA σ I} {g : Sat256} {s0 : State} (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcaller : solcSourceWord I ≠ bidGuyWord (tendId I) σ I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨3486⟩ [tendBid I, tendLot I, tendId I, ret, sel] mem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : RDrev flipperBytecode g s0 := by obtain ⟨_, _, rd3616⟩ := flipperTendX_toRefundExtcodesizeGuard hmemSize hmemRead64 hcaller h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3616⟩) (okPc := ⟨3628⟩) rd3616 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3616⟩) (okPc := ⟨3628⟩) rd3616 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1792,7 +1792,7 @@ theorem flipperTendX_toRefundCall {cA σ I} {g : Sat256} {s0 : State} (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcaller : solcSourceWord I ≠ bidGuyWord (tendId I) σ I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨3486⟩ [tendBid I, tendLot I, tendId I, ret, sel] mem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : ∃ gasWord k' C', RD flipperBytecode I g s0 ⟨3631⟩ @@ -1804,7 +1804,7 @@ theorem flipperTendX_toRefundCall {cA σ I} {g : Sat256} {s0 : State} obtain ⟨_, _, rd3616⟩ := flipperTendX_toRefundExtcodesizeGuard hmemSize hmemRead64 hcaller h obtain ⟨gasWord, k3631, C3631, rd3631⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3616⟩) (okPc := ⟨3628⟩) rd3616 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3616⟩) (okPc := ⟨3628⟩) rd3616 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1817,7 +1817,7 @@ theorem flipperTendX_refundDepthLimit {cA σ I} {g : Sat256} {s0 : State} (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcaller : solcSourceWord I ≠ bidGuyWord (tendId I) σ I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = (1024 : Fin 1025)) (h : RD flipperBytecode I g s0 ⟨3486⟩ [tendBid I, tendLot I, tendId I, ret, sel] mem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : @@ -1857,7 +1857,7 @@ theorem flipperTendX_refundPostCall (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcaller : solcSourceWord I ≠ bidGuyWord (tendId I) σ I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) (h : RD flipperBytecode I (Sat256.ofUInt256 g) @@ -1938,7 +1938,7 @@ theorem flipperTendX_refundCallFailure {I} {g : Sat256} {s0 : State} mem aw out acc k C) (houtsz : out.size < UInt256.size) : RDrev flipperBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3632⟩) (okPc := ⟨3648⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨3632⟩) (okPc := ⟨3648⟩) h (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1954,7 +1954,7 @@ theorem flipperTendX_refundCallSuccessToStoreStart {I} {g : Sat256} {s0 : State} ∃ k' C', RD flipperBytecode I g s0 ⟨3652⟩ (target :: bid :: lot :: id :: ret :: sel :: []) mem aw out acc k' C' := by obtain ⟨_, _, rd3649⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨3632⟩) (okPc := ⟨3648⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨3632⟩) (okPc := ⟨3648⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -2442,13 +2442,13 @@ theorem flipperTendX_payNoCodeAw8 {cA σ I} {g : Sat256} {s0 : State} (hmemSize : mem.size = 228) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨3686⟩ [tendBid I, tendLot I, tendId I, ret, sel] mem (UInt256.ofNat 8) rdata (cA, σ) k C) : RDrev flipperBytecode g s0 := by obtain ⟨_, _, rd3784⟩ := flipperTendX_toPayExtcodesizeGuardAw8 hmemSize hmemRead64 h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3784⟩) (okPc := ⟨3796⟩) rd3784 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3784⟩) (okPc := ⟨3796⟩) rd3784 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2459,7 +2459,7 @@ theorem flipperTendX_toPayCallAw8 {cA σ I} {g : Sat256} {s0 : State} (hmemSize : mem.size = 228) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨3686⟩ [tendBid I, tendLot I, tendId I, ret, sel] mem (UInt256.ofNat 8) rdata (cA, σ) k C) : ∃ gasWord k' C', RD flipperBytecode I g s0 ⟨3799⟩ @@ -2471,7 +2471,7 @@ theorem flipperTendX_toPayCallAw8 {cA σ I} {g : Sat256} {s0 : State} obtain ⟨_, _, rd3784⟩ := flipperTendX_toPayExtcodesizeGuardAw8 hmemSize hmemRead64 h obtain ⟨gasWord, k3799, C3799, rd3799⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3784⟩) (okPc := ⟨3796⟩) rd3784 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3784⟩) (okPc := ⟨3796⟩) rd3784 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -2483,7 +2483,7 @@ theorem flipperTendX_payDepthLimitAw8 {cA σ I} {g : Sat256} {s0 : State} (hmemSize : mem.size = 228) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = (1024 : Fin 1025)) (h : RD flipperBytecode I g s0 ⟨3686⟩ [tendBid I, tendLot I, tendId I, ret, sel] mem (UInt256.ofNat 8) rdata (cA, σ) k C) : @@ -2520,7 +2520,7 @@ theorem flipperTendX_payPostCallAw8 (hmemSize : mem.size = 228) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) (h : RD flipperBytecode I (Sat256.ofUInt256 g) @@ -2654,10 +2654,10 @@ theorem flipperTendBodyFrom3486Refund dsimp [memHash] exact twoWordHashMem_read64 (tendId I) ⟨1⟩ hmemSize hmemRead64 by_cases hrefundZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flipperVatTargetWord σ_evm I) = ⟨0⟩ · have hrefundZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flipperVatTargetWord σ_solm I) = ⟨0⟩ := flipperVatCodeSize_zero_accountMapEquiv hAccounts hrefundZero have hvatNoCode := @@ -2675,7 +2675,7 @@ theorem flipperTendBodyFrom3486Refund exact (flipperTendX_refundNoCode hmemSize hmemRead64 hcallerEvm hrefundZero h) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hrefundNeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flipperVatTargetWord σ_solm I) ≠ ⟨0⟩ := flipperVatCodeSize_ne_zero_accountMapEquiv hAccounts hrefundZero have hrefundCodeSolm := @@ -2909,14 +2909,14 @@ theorem flipperTendBodyFrom3486Refund (true, evmRefundSolm, outRefund) true := by simpa using hcallRefundSolm by_cases hpayZero : - Reasoning.Theory.uniswapExtCodeSizeWord (tendAfterRefundMap σ_ref I) + Reasoning.Theory.extCodeSizeWord (tendAfterRefundMap σ_ref I) (flipperVatTargetWord (tendAfterRefundMap σ_ref I) I) = ⟨0⟩ · have hpayZeroEvm : - Reasoning.Theory.uniswapExtCodeSizeWord evmGuyEvm.accountMap + Reasoning.Theory.extCodeSizeWord evmGuyEvm.accountMap (flipperVatTargetWord evmGuyEvm.accountMap I) = ⟨0⟩ := by simpa [hmapGuyEvm] using hpayZero have hpayZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmGuySolm.accountMap + Reasoning.Theory.extCodeSizeWord evmGuySolm.accountMap (flipperVatTargetWord evmGuySolm.accountMap I) = ⟨0⟩ := flipperVatCodeSize_zero_accountMapEquiv hGuyStateEquiv.accountMap hpayZeroEvm have hpayNoCodeSolm : @@ -2927,7 +2927,7 @@ theorem flipperTendBodyFrom3486Refund 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [evmGuySolm, evmRefundSolm, evm0Solm, initState, storageStore_executionEnv, State.lookupAccount] using - flipper_uniswapExtCodeSizeWord_zero_lookup_code_zero + flipper_extCodeSizeWord_zero_lookup_code_zero (σ := evmGuySolm.accountMap) (target := flipperVatTargetWord evmGuySolm.accountMap I) (addr := flipperVatAddress evmGuySolm.accountMap I) @@ -2946,11 +2946,11 @@ theorem flipperTendBodyFrom3486Refund exact (flipperTendX_payNoCodeAw8 hmemPaySize hmemPayRead64 hpayZero rd3686) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hpayNeEvm : - Reasoning.Theory.uniswapExtCodeSizeWord evmGuyEvm.accountMap + Reasoning.Theory.extCodeSizeWord evmGuyEvm.accountMap (flipperVatTargetWord evmGuyEvm.accountMap I) ≠ ⟨0⟩ := by simpa [hmapGuyEvm] using hpayZero have hpayNeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmGuySolm.accountMap + Reasoning.Theory.extCodeSizeWord evmGuySolm.accountMap (flipperVatTargetWord evmGuySolm.accountMap I) ≠ ⟨0⟩ := flipperVatCodeSize_ne_zero_accountMapEquiv hGuyStateEquiv.accountMap hpayNeEvm have hpayCodeSolm : @@ -2962,7 +2962,7 @@ theorem flipperTendBodyFrom3486Refund 0 (fun acc => acc.code.size))).toNat := by simpa [evmGuySolm, evmRefundSolm, evm0Solm, initState, storageStore_executionEnv, State.lookupAccount] using - flipper_uniswapExtCodeSizeWord_pos_lookup_code_pos + flipper_extCodeSizeWord_pos_lookup_code_pos (σ := evmGuySolm.accountMap) (target := flipperVatTargetWord evmGuySolm.accountMap I) (addr := flipperVatAddress evmGuySolm.accountMap I) diff --git a/Benchmarks/Dss/Flipper/TendSameCaller.lean b/Benchmarks/Dss/Flipper/TendSameCaller.lean index 1dffbce3..7b19b648 100644 --- a/Benchmarks/Dss/Flipper/TendSameCaller.lean +++ b/Benchmarks/Dss/Flipper/TendSameCaller.lean @@ -78,9 +78,9 @@ theorem flipperTendBodyFrom3486SameCaller dsimp [memPay] exact twoWordHashMem_read64 (tendId I) ⟨1⟩ hmemSize hmemRead64 by_cases hpayZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (flipperVatTargetWord σ_evm I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_evm (flipperVatTargetWord σ_evm I) = ⟨0⟩ · have hpayZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flipperVatTargetWord σ_solm I) = ⟨0⟩ := flipperVatCodeSize_zero_accountMapEquiv hAccounts hpayZero have hvatNoCode := @@ -98,7 +98,7 @@ theorem flipperTendBodyFrom3486SameCaller exact (flipperTendX_payNoCode hmemPaySize hmemPayRead64 hpayZero rd3686) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hpayNeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flipperVatTargetWord σ_solm I) ≠ ⟨0⟩ := flipperVatCodeSize_ne_zero_accountMapEquiv hAccounts hpayZero have hvatCodeSolm := diff --git a/Benchmarks/Dss/Flipper/TendSourceTail.lean b/Benchmarks/Dss/Flipper/TendSourceTail.lean index d389c069..f78ecc64 100644 --- a/Benchmarks/Dss/Flipper/TendSourceTail.lean +++ b/Benchmarks/Dss/Flipper/TendSourceTail.lean @@ -22,7 +22,7 @@ theorem flipperTendX_payDepthLimit {cA σ I} {g : Sat256} {s0 : State} (hmemSize : mem.size = 96) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = (1024 : Fin 1025)) (h : RD flipperBytecode I g s0 ⟨3686⟩ [tendBid I, tendLot I, tendId I, ret, sel] mem (UInt256.ofNat 3) rdata (cA, σ) k C) : diff --git a/Benchmarks/Dss/Flipper/TendTail.lean b/Benchmarks/Dss/Flipper/TendTail.lean index 5fc6fc85..24578f8e 100644 --- a/Benchmarks/Dss/Flipper/TendTail.lean +++ b/Benchmarks/Dss/Flipper/TendTail.lean @@ -1317,13 +1317,13 @@ theorem flipperTendX_payNoCode {cA σ I} {g : Sat256} {s0 : State} (hmemSize : mem.size = 96) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨3686⟩ [tendBid I, tendLot I, tendId I, ret, sel] mem (UInt256.ofNat 3) rdata (cA, σ) k C) : RDrev flipperBytecode g s0 := by obtain ⟨_, _, rd3784⟩ := flipperTendX_toPayExtcodesizeGuard hmemSize hmemRead64 h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3784⟩) (okPc := ⟨3796⟩) rd3784 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3784⟩) (okPc := ⟨3796⟩) rd3784 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1334,7 +1334,7 @@ theorem flipperTendX_toPayCall {cA σ I} {g : Sat256} {s0 : State} (hmemSize : mem.size = 96) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨3686⟩ [tendBid I, tendLot I, tendId I, ret, sel] mem (UInt256.ofNat 3) rdata (cA, σ) k C) : ∃ gasWord k' C', RD flipperBytecode I g s0 ⟨3799⟩ @@ -1346,7 +1346,7 @@ theorem flipperTendX_toPayCall {cA σ I} {g : Sat256} {s0 : State} obtain ⟨_, _, rd3784⟩ := flipperTendX_toPayExtcodesizeGuard hmemSize hmemRead64 h obtain ⟨gasWord, k3799, C3799, rd3799⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3784⟩) (okPc := ⟨3796⟩) rd3784 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3784⟩) (okPc := ⟨3796⟩) rd3784 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1361,7 +1361,7 @@ theorem flipperTendX_payPostCall (hmemSize : mem.size = 96) (hmemRead64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) (h : RD flipperBytecode I (Sat256.ofUInt256 g) @@ -1435,7 +1435,7 @@ theorem flipperTendX_payCallFailure {I} {g : Sat256} {s0 : State} mem aw out acc k C) (houtsz : out.size < UInt256.size) : RDrev flipperBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3800⟩) (okPc := ⟨3816⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨3800⟩) (okPc := ⟨3816⟩) h (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1451,7 +1451,7 @@ theorem flipperTendX_payCallSuccessToStoreStart {I} {g : Sat256} {s0 : State} ∃ k' C', RD flipperBytecode I g s0 ⟨3820⟩ (target :: bid :: lot :: id :: ret :: sel :: []) mem aw out acc k' C' := by obtain ⟨_, _, rd3817⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨3800⟩) (okPc := ⟨3816⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨3800⟩) (okPc := ⟨3816⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1629,7 +1629,7 @@ theorem flipperTendX_add48Overflow {cA σ I} {g : Sat256} {s0 : State} rw [show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rd6290 have rd6295 := rd6290.push2 ⟨6299⟩ (by native_decide) (by evm_ov) |>.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd6295 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd6295 (by native_decide) (by native_decide) (by native_decide) (by evm_ov) theorem flipperTendX_storeTicReturn {cA σ I} {g : Sat256} {s0 : State} diff --git a/Benchmarks/Dss/Flipper/Tick.lean b/Benchmarks/Dss/Flipper/Tick.lean index 5d01e7f6..63bb12e1 100644 --- a/Benchmarks/Dss/Flipper/Tick.lean +++ b/Benchmarks/Dss/Flipper/Tick.lean @@ -1101,7 +1101,7 @@ theorem flipperTickX_add48Overflow {cA σ I} {g : Sat256} {s0 : State} rw [show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rd6290 have rd6295 := rd6290.push2 ⟨6299⟩ (by native_decide) (by evm_ov) |>.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd6295 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd6295 (by native_decide) (by native_decide) (by native_decide) (by evm_ov) theorem flipperTickX_storeEnd {cA σ I} {g : Sat256} {s0 : State} diff --git a/Benchmarks/Dss/Flipper/Yank.lean b/Benchmarks/Dss/Flipper/Yank.lean index 1d9d27e0..5e4821ad 100644 --- a/Benchmarks/Dss/Flipper/Yank.lean +++ b/Benchmarks/Dss/Flipper/Yank.lean @@ -1365,12 +1365,12 @@ theorem flipperYankX_toCatExtcodesizeGuard {cA σ I} {g : Sat256} {s0 : State} theorem flipperYankX_catNoCode {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} {ret sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperCatTargetWord σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperCatTargetWord σ I) = ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨1250⟩ [yankId I, ret, sel] (yankHashMem1 I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : RDrev flipperBytecode g s0 := by obtain ⟨_, _, rd1330⟩ := flipperYankX_toCatExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1330⟩) (okPc := ⟨1342⟩) rd1330 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1330⟩) (okPc := ⟨1342⟩) rd1330 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1379,7 +1379,7 @@ theorem flipperYankX_catNoCode {cA σ I} {g : Sat256} {s0 : State} theorem flipperYankX_toCatCall {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} {ret sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨1250⟩ [yankId I, ret, sel] (yankHashMem1 I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : ∃ gasWord k' C', RD flipperBytecode I g s0 ⟨1345⟩ @@ -1389,7 +1389,7 @@ theorem flipperYankX_toCatCall {cA σ I} {g : Sat256} {s0 : State} (yankCatCallMem σ I) (UInt256.ofNat 6) ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd1330⟩ := flipperYankX_toCatExtcodesizeGuard h obtain ⟨gasWord, k1345, C1345, rd1345⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1330⟩) (okPc := ⟨1342⟩) rd1330 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1330⟩) (okPc := ⟨1342⟩) rd1330 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1399,7 +1399,7 @@ theorem flipperYankX_toCatCall {cA σ I} {g : Sat256} {s0 : State} theorem flipperYankX_catPostCall {cA gh bl σ σ₀ A I} {g : UInt256} {k C : ℕ} {ret sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) (h : RD flipperBytecode I (Sat256.ofUInt256 g) @@ -1464,7 +1464,7 @@ theorem flipperYankX_catCallFailure {I} {g : Sat256} {s0 : State} mem aw out acc k C) (houtsz : out.size < UInt256.size) : RDrev flipperBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1346⟩) (okPc := ⟨1362⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨1346⟩) (okPc := ⟨1362⟩) h (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1474,7 +1474,7 @@ theorem flipperYankX_catCallFailure {I} {g : Sat256} {s0 : State} theorem flipperYankX_catCallDepthLimit {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} {ret sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperCatTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (h : RD flipperBytecode I g s0 ⟨1250⟩ [yankId I, ret, sel] (yankHashMem1 I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : @@ -1514,7 +1514,7 @@ theorem flipperYankX_catCallSuccessToVatStart {I} {g : Sat256} {s0 : State} (selector :: target :: id :: ret :: sel :: []) mem aw out acc k' C' := by obtain ⟨k1364, C1364, rd1364⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨1346⟩) (okPc := ⟨1362⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨1346⟩) (okPc := ⟨1362⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1621,7 +1621,7 @@ theorem flipperYankX_toVatExtcodesizeGuard {cA σmem σ I} {g : Sat256} {s0 : St raw swap5 (by native_decide) (by evm_ov), raw mstore 0 (yankVatFluxIlkMem σmem σ I) (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov)] - have rd1413 := RD.uniswapAddress rd1412 (by native_decide) (by evm_ov) + have rd1413 := RD.address rd1412 (by native_decide) (by evm_ov) have rd1466 := evm_run rd1413 with [ raw push1 ⟨36⟩ (by native_decide) (by evm_ov), raw dup6 (by native_decide) (by evm_ov), @@ -1676,13 +1676,13 @@ theorem flipperYankX_toVatExtcodesizeGuard {cA σmem σ I} {g : Sat256} {s0 : St theorem flipperYankX_vatNoCode {cA σmem σ I} {g : Sat256} {s0 : State} {k C : ℕ} {out : ByteArray} {ret sel selector target : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨1365⟩ (selector :: target :: yankId I :: ret :: sel :: []) (yankCatCallMem σmem I) (UInt256.ofNat 6) out (cA, σ) k C) : RDrev flipperBytecode g s0 := by obtain ⟨_, _, rd1466⟩ := flipperYankX_toVatExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1466⟩) (okPc := ⟨1478⟩) rd1466 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1466⟩) (okPc := ⟨1478⟩) rd1466 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Flipper/YankBody.lean b/Benchmarks/Dss/Flipper/YankBody.lean index 2dff957c..59472248 100644 --- a/Benchmarks/Dss/Flipper/YankBody.lean +++ b/Benchmarks/Dss/Flipper/YankBody.lean @@ -68,10 +68,10 @@ theorem flipperYankBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (bidTabWord (yankId I) σ_evm I).toNat · obtain ⟨_, _, hafterBidLt⟩ := flipperYankX_bidLt (I := I) hbidLtEvm hafterGuy by_cases hcatZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flipperCatTargetWord σ_evm I) = ⟨0⟩ · have hcatZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flipperCatTargetWord σ_solm I) = ⟨0⟩ := flipperCatCodeSize_zero_accountMapEquiv hAccounts hcatZero have hnoCode : @@ -102,7 +102,7 @@ theorem flipperYankBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (flipperYankX_catNoCode (I := I) hcatZero hafterBidLt) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hcatNeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flipperCatTargetWord σ_solm I) ≠ ⟨0⟩ := flipperCatCodeSize_ne_zero_accountMapEquiv hAccounts hcatZero have hcatCode := flipperCatCode_pos_of_codeSize_ne_zero @@ -244,10 +244,10 @@ theorem flipperYankBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hAccountsCat : accountMapEquiv σ_cat σ_cat_solm := by simpa [evmCatEvm, evmCatSolm] using hCatStateEquiv'.accountMap by_cases hvatZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ_cat + Reasoning.Theory.extCodeSizeWord σ_cat (flipperVatTargetWord σ_cat I) = ⟨0⟩ · have hvatZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_cat_solm + Reasoning.Theory.extCodeSizeWord σ_cat_solm (flipperVatTargetWord σ_cat_solm I) = ⟨0⟩ := flipperVatCodeSize_zero_accountMapEquiv hAccountsCat hvatZero have hvatNoCode : @@ -257,7 +257,7 @@ theorem flipperYankBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} evmCatSolm.executionEnv)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [evmCatSolm, evm0Solm, initState, State.lookupAccount] using - flipper_uniswapExtCodeSizeWord_zero_lookup_code_zero + flipper_extCodeSizeWord_zero_lookup_code_zero (σ := σ_cat_solm) (target := flipperVatTargetWord σ_cat_solm I) (addr := flipperVatAddress σ_cat_solm I) (flipperVatAddress_eq_target σ_cat_solm I) hvatZeroSolm @@ -273,7 +273,7 @@ theorem flipperYankBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (flipperYankX_vatNoCode hvatZero rd1365) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hvatNeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_cat_solm + Reasoning.Theory.extCodeSizeWord σ_cat_solm (flipperVatTargetWord σ_cat_solm I) ≠ ⟨0⟩ := flipperVatCodeSize_ne_zero_accountMapEquiv hAccountsCat hvatZero have hvatCodeSolm : @@ -284,7 +284,7 @@ theorem flipperYankBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} evmCatSolm.executionEnv)).option 0 (fun acc => acc.code.size))).toNat := by simpa [evmCatSolm, evm0Solm, initState, State.lookupAccount] using - flipper_uniswapExtCodeSizeWord_pos_lookup_code_pos + flipper_extCodeSizeWord_pos_lookup_code_pos (σ := σ_cat_solm) (target := flipperVatTargetWord σ_cat_solm I) (addr := flipperVatAddress σ_cat_solm I) (flipperVatAddress_eq_target σ_cat_solm I) hvatNeSolm @@ -414,10 +414,10 @@ theorem flipperYankBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hAccountsVat : accountMapEquiv σ_vat σ_vat_solm := by simpa [evmVatEvm, evmVatSolm] using hVatStateEquiv'.accountMap by_cases hmoveZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat + Reasoning.Theory.extCodeSizeWord σ_vat (flipperVatTargetWord σ_vat I) = ⟨0⟩ · have hmoveZeroSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat_solm + Reasoning.Theory.extCodeSizeWord σ_vat_solm (flipperVatTargetWord σ_vat_solm I) = ⟨0⟩ := flipperVatCodeSize_zero_accountMapEquiv hAccountsVat hmoveZero have hmoveNoCode : @@ -428,7 +428,7 @@ theorem flipperYankBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [evmVatSolm, evmCatSolm, evm0Solm, initState, State.lookupAccount] using - flipper_uniswapExtCodeSizeWord_zero_lookup_code_zero + flipper_extCodeSizeWord_zero_lookup_code_zero (σ := σ_vat_solm) (target := flipperVatTargetWord σ_vat_solm I) (addr := flipperVatAddress σ_vat_solm I) @@ -447,7 +447,7 @@ theorem flipperYankBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} exact (flipperYankX_moveNoCode hmoveZero rd1501) |>.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hmoveNeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_vat_solm + Reasoning.Theory.extCodeSizeWord σ_vat_solm (flipperVatTargetWord σ_vat_solm I) ≠ ⟨0⟩ := flipperVatCodeSize_ne_zero_accountMapEquiv hAccountsVat hmoveZero have hmoveCodeSolm : @@ -459,7 +459,7 @@ theorem flipperYankBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} 0 (fun acc => acc.code.size))).toNat := by simpa [evmVatSolm, evmCatSolm, evm0Solm, initState, State.lookupAccount] using - flipper_uniswapExtCodeSizeWord_pos_lookup_code_pos + flipper_extCodeSizeWord_pos_lookup_code_pos (σ := σ_vat_solm) (target := flipperVatTargetWord σ_vat_solm I) (addr := flipperVatAddress σ_vat_solm I) diff --git a/Benchmarks/Dss/Flipper/YankCalls.lean b/Benchmarks/Dss/Flipper/YankCalls.lean index 62debcd4..070d3ffb 100644 --- a/Benchmarks/Dss/Flipper/YankCalls.lean +++ b/Benchmarks/Dss/Flipper/YankCalls.lean @@ -569,7 +569,7 @@ theorem yankLocalsAfterCalls_get_bids (I : ExecutionEnv) : theorem flipperYankX_toVatCall {cA σmem σ I} {g : Sat256} {s0 : State} {k C : ℕ} {out : ByteArray} {ret sel selector target : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨1365⟩ (selector :: target :: yankId I :: ret :: sel :: []) (yankCatCallMem σmem I) (UInt256.ofNat 6) out (cA, σ) k C) : @@ -580,7 +580,7 @@ theorem flipperYankX_toVatCall {cA σmem σ I} {g : Sat256} {s0 : State} (yankVatFluxCallMem σmem σ I) (UInt256.ofNat 9) out (cA, σ) k' C' := by obtain ⟨_, _, rd1466⟩ := flipperYankX_toVatExtcodesizeGuard h obtain ⟨gasWord, k1481, C1481, rd1481⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1466⟩) (okPc := ⟨1478⟩) rd1466 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1466⟩) (okPc := ⟨1478⟩) rd1466 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -592,7 +592,7 @@ theorem flipperYankX_vatPostCall {cA : Batteries.RBSet AccountAddress compare} {σmem σ : AccountMap} {Acur : Substate} {k C : ℕ} {out0 : ByteArray} {ret sel selector target : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) (h : RD flipperBytecode I (Sat256.ofUInt256 g) @@ -1267,7 +1267,7 @@ theorem flipperYankX_vatCallFailure {I} {g : Sat256} {s0 : State} mem aw out acc k C) (houtsz : out.size < UInt256.size) : RDrev flipperBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1482⟩) (okPc := ⟨1498⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨1482⟩) (okPc := ⟨1498⟩) h (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1283,7 +1283,7 @@ theorem flipperYankX_vatCallSuccessToMoveStart {I} {g : Sat256} {s0 : State} ∃ k' C', RD flipperBytecode I g s0 ⟨1501⟩ (selector :: target :: id :: ret :: sel :: []) mem aw out acc k' C' := by obtain ⟨k1500, C1500, rd1500⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨1482⟩) (okPc := ⟨1498⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨1482⟩) (okPc := ⟨1498⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1473,13 +1473,13 @@ theorem flipperYankX_toMoveExtcodesizeGuard {cA σmem σflux σ I} {g : Sat256} theorem flipperYankX_moveNoCode {cA σmem σflux σ I} {g : Sat256} {s0 : State} {k C : ℕ} {out : ByteArray} {ret sel selector target : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) = ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨1501⟩ (selector :: target :: yankId I :: ret :: sel :: []) (yankVatFluxCallMem σmem σflux I) (UInt256.ofNat 9) out (cA, σ) k C) : RDrev flipperBytecode g s0 := by obtain ⟨_, _, rd1599⟩ := flipperYankX_toMoveExtcodesizeGuard h - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1599⟩) (okPc := ⟨1611⟩) rd1599 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1599⟩) (okPc := ⟨1611⟩) rd1599 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1488,7 +1488,7 @@ theorem flipperYankX_moveNoCode {cA σmem σflux σ I} {g : Sat256} {s0 : State} theorem flipperYankX_toMoveCall {cA σmem σflux σ I} {g : Sat256} {s0 : State} {k C : ℕ} {out : ByteArray} {ret sel selector target : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (h : RD flipperBytecode I g s0 ⟨1501⟩ (selector :: target :: yankId I :: ret :: sel :: []) (yankVatFluxCallMem σmem σflux I) (UInt256.ofNat 9) out (cA, σ) k C) : @@ -1499,7 +1499,7 @@ theorem flipperYankX_toMoveCall {cA σmem σflux σ I} {g : Sat256} {s0 : State} (yankVatMoveCallMem σmem σflux σ I) (UInt256.ofNat 9) out (cA, σ) k' C' := by obtain ⟨_, _, rd1599⟩ := flipperYankX_toMoveExtcodesizeGuard h obtain ⟨gasWord, k1614, C1614, rd1614⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1599⟩) (okPc := ⟨1611⟩) rd1599 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1599⟩) (okPc := ⟨1611⟩) rd1599 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1512,7 +1512,7 @@ theorem flipperYankX_movePostCall {σmem σflux σ : AccountMap} {Acur : Substate} {k C : ℕ} {out0 : ByteArray} {ret sel selector target : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flipperVatTargetWord σ I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) (h : RD flipperBytecode I (Sat256.ofUInt256 g) @@ -1586,7 +1586,7 @@ theorem flipperYankX_moveCallFailure {I} {g : Sat256} {s0 : State} mem aw out acc k C) (houtsz : out.size < UInt256.size) : RDrev flipperBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1615⟩) (okPc := ⟨1631⟩) h + exact RD.solcCallSuccessGuardMissing (pc := ⟨1615⟩) (okPc := ⟨1631⟩) h (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1602,7 +1602,7 @@ theorem flipperYankX_moveCallSuccessToDeleteStart {I} {g : Sat256} {s0 : State} ∃ k' C', RD flipperBytecode I g s0 ⟨1635⟩ (target :: id :: ret :: sel :: []) mem aw out acc k' C' := by obtain ⟨_, _, rd1633⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨1615⟩) (okPc := ⟨1631⟩) h + RD.solcCallSuccessGuardOk (pc := ⟨1615⟩) (okPc := ⟨1631⟩) h (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Flopper/AuctionCommon.lean b/Benchmarks/Dss/Flopper/AuctionCommon.lean index a62baaf3..5050031b 100644 --- a/Benchmarks/Dss/Flopper/AuctionCommon.lean +++ b/Benchmarks/Dss/Flopper/AuctionCommon.lean @@ -991,33 +991,33 @@ theorem flopperAddressOfSlot_accountMapEquiv {σ τ : AccountMap} {I : Execution theorem flopperCodeSize_ne_accountMapEquiv {σ τ : AccountMap} (hAccounts : accountMapEquiv σ τ) {target : UInt256} - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ target ≠ ⟨0⟩ := by + (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ target ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts target + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts target rw [hsame] exact hzero theorem flopperCodeSize_zero_accountMapEquiv {σ τ : AccountMap} (hAccounts : accountMapEquiv σ τ) {target : UInt256} - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ target = ⟨0⟩ := by + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ target = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts target + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts target rw [← hsame] exact hzero theorem flopperCodeSize_ne_accountMapEquiv_addressSlot {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (slot : UInt256) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flopperAddressReturnWord slot σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flopperAddressReturnWord slot τ I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (flopperAddressReturnWord slot σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (flopperAddressReturnWord slot τ I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (flopperAddressReturnWord slot σ I) have htarget : flopperAddressReturnWord slot σ I = flopperAddressReturnWord slot τ I := @@ -1028,10 +1028,10 @@ theorem flopperCodeSize_ne_accountMapEquiv_addressSlot {σ τ : AccountMap} theorem flopperCodeSize_zero_accountMapEquiv_addressSlot {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (slot : UInt256) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flopperAddressReturnWord slot σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (flopperAddressReturnWord slot τ I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (flopperAddressReturnWord slot σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (flopperAddressReturnWord slot τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (flopperAddressReturnWord slot σ I) have htarget : flopperAddressReturnWord slot σ I = flopperAddressReturnWord slot τ I := @@ -1390,7 +1390,7 @@ theorem RD.flopperCheckedMulOverflowReverts have heqCond : UInt256.eq (UInt256.div (x * y) y) x = ⟨0⟩ := u256_eq_of_ne hdivNe have rd4706 := rd4705.jumpiNT (by native_decide) heqCond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd4706 + exact RD.solcPush1Dup1Revert0 rd4706 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) diff --git a/Benchmarks/Dss/Flopper/Deal.lean b/Benchmarks/Dss/Flopper/Deal.lean index ab2169c5..755f9b84 100644 --- a/Benchmarks/Dss/Flopper/Deal.lean +++ b/Benchmarks/Dss/Flopper/Deal.lean @@ -602,11 +602,11 @@ theorem evalExpr_deal_extCodeGuard_false {evm : EVM.State} {locals : Store} theorem dealExtCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => exfalso @@ -628,11 +628,11 @@ theorem dealExtCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} theorem dealExtCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using @@ -703,7 +703,7 @@ theorem flopperDealBodyReverts_mintNoCode (evm : EVM.State) (I : ExecutionEnv) (dealTicWord evm I).toNat < (dealTimestampWord evm).toNat ∨ (dealEndWord evm I).toNat < (dealTimestampWord evm).toNat) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dealGemWord evm) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord evm.accountMap (dealGemWord evm) = ⟨0⟩) : ExecTransitionBody config contract evm (dealLocals I) dealTransition.body .reverted := by have hgem := evalExpr_deal_gem_storage evm I have hnoCodeLookup : @@ -741,7 +741,7 @@ theorem flopperDealBodyReverts_mintCallFailure (dealTicWord evm I).toNat < (dealTimestampWord evm).toNat ∨ (dealEndWord evm I).toNat < (dealTimestampWord evm).toNat) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dealGemWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dealGemWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dealGemWord evm).toNat)) @@ -801,7 +801,7 @@ theorem flopperDealBodyReturns_mintCallSuccess (dealTicWord evm I).toNat < (dealTimestampWord evm).toNat ∨ (dealEndWord evm I).toNat < (dealTimestampWord evm).toNat) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dealGemWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dealGemWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dealGemWord evm).toNat)) diff --git a/Benchmarks/Dss/Flopper/DealRuntime.lean b/Benchmarks/Dss/Flopper/DealRuntime.lean index b4a21baa..e8041228 100644 --- a/Benchmarks/Dss/Flopper/DealRuntime.lean +++ b/Benchmarks/Dss/Flopper/DealRuntime.lean @@ -397,7 +397,7 @@ theorem flopperDealX_mintNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt (flopperUint48Offset26Word (auctionPackedSlot (dealIdWord I)) σ I).toNat < (UInt256.ofNat I.header.timestamp).toNat) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flopperAddressReturnWord ⟨3⟩ σ I) = + Reasoning.Theory.extCodeSizeWord σ (flopperAddressReturnWord ⟨3⟩ σ I) = ⟨0⟩) (rd3966 : ∃ k C, RD flopperBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3966⟩ @@ -408,7 +408,7 @@ theorem flopperDealX_mintNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt flopperDealX_readyToMint (g := g) htic hfinished rd3966 obtain ⟨_, _, rd4253⟩ := flopperDealX_toMintExtcodesizeGuard hmemStart hread64Start rd4159 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4253⟩) (okPc := ⟨1160⟩) rd4253 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4253⟩) (okPc := ⟨1160⟩) rd4253 hnoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -418,7 +418,7 @@ theorem flopperDealX_mintCall {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} (hperm : I.perm = true) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flopperAddressReturnWord ⟨3⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (flopperAddressReturnWord ⟨3⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (htic : flopperUint48Offset20Word (auctionPackedSlot (dealIdWord I)) σ I ≠ ⟨0⟩) @@ -459,7 +459,7 @@ theorem flopperDealX_mintCall obtain ⟨_, _, rd4253⟩ := flopperDealX_toMintExtcodesizeGuard hmemStart hread64Start rd4159 obtain ⟨gasWord, _, _, rd1163⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4253⟩) (okPc := ⟨1160⟩) rd4253 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4253⟩) (okPc := ⟨1160⟩) rd4253 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -500,7 +500,7 @@ theorem flopperDealX_mintCall theorem flopperDealX_mintCallDepthLimit {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flopperAddressReturnWord ⟨3⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (flopperAddressReturnWord ⟨3⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (htic : flopperUint48Offset20Word (auctionPackedSlot (dealIdWord I)) σ I ≠ ⟨0⟩) @@ -528,7 +528,7 @@ theorem flopperDealX_mintCallDepthLimit obtain ⟨_, _, rd4253⟩ := flopperDealX_toMintExtcodesizeGuard hmemStart hread64Start rd4159 obtain ⟨gasWord, _, _, rd1163⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4253⟩) (okPc := ⟨1160⟩) rd4253 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4253⟩) (okPc := ⟨1160⟩) rd4253 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -559,7 +559,7 @@ theorem flopperDealX_mintCallFailure mem (UInt256.ofNat 7) out (cA', σ') k C) (houtSize : out.size < UInt256.size) : RDrev flopperBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1164⟩) (okPc := ⟨1180⟩) rd1164 + exact RD.solcCallSuccessGuardMissing (pc := ⟨1164⟩) (okPc := ⟨1180⟩) rd1164 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -733,7 +733,7 @@ theorem flopperDealBodyCoreMintNoCode (flopperUint48Offset26Word (auctionPackedSlot (dealIdWord I)) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨3⟩ σ_evm I) = ⟨0⟩) (hdispatch : dispatchMsg contract I.calldata = some dealTransition) (hdecode : @@ -769,7 +769,7 @@ theorem flopperDealBodyCoreMintNoCode right simpa [evmSolm, initState, dealEndWord, dealTimestampWord, hendEq] using h have hnoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨3⟩ σ_solm I) = ⟨0⟩ := flopperCodeSize_zero_accountMapEquiv_addressSlot hAccounts ⟨3⟩ hnoCode have hbody : @@ -802,7 +802,7 @@ theorem flopperDealBodyCoreMintCallFailure (flopperUint48Offset26Word (auctionPackedSlot (dealIdWord I)) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨3⟩ σ_evm I) ≠ ⟨0⟩) (rd1164 : RD flopperBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1164⟩ @@ -882,7 +882,7 @@ theorem flopperDealBodyCoreMintCallFailure right simpa [evmSolm, initState, dealEndWord, dealTimestampWord, hendEq] using h have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨3⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨3⟩ hcodeSize have hbody : @@ -911,7 +911,7 @@ theorem flopperDealBodyCoreMintCallDepthLimit (flopperUint48Offset26Word (auctionPackedSlot (dealIdWord I)) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨3⟩ σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hdispatch : dispatchMsg contract I.calldata = some dealTransition) @@ -976,7 +976,7 @@ theorem flopperDealBodyCoreMintCallDepthLimit right simpa [evmSolm, initState, dealEndWord, dealTimestampWord, hendEq] using h have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨3⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨3⟩ hcodeSize have hbody : @@ -1013,7 +1013,7 @@ theorem flopperDealBodyCoreMintCallSuccess (flopperUint48Offset26Word (auctionPackedSlot (dealIdWord I)) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨3⟩ σ_evm I) ≠ ⟨0⟩) (rd1164 : RD flopperBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1164⟩ @@ -1092,7 +1092,7 @@ theorem flopperDealBodyCoreMintCallSuccess right simpa [evmSolm, initState, dealEndWord, dealTimestampWord, hendEq] using h have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨3⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨3⟩ hcodeSize have hbody : @@ -1187,7 +1187,7 @@ theorem flopperDealBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (flopperUint48Offset26Word (auctionPackedSlot (dealIdWord I)) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat := Or.inl hticLt by_cases hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨3⟩ σ_evm I) = ⟨0⟩ · exact flopperDealBodyCoreMintNoCode hcode hsize hwv hsz36 hlive htic hfinished hcodeSize hdispatch hdecode hreach hAccounts @@ -1275,7 +1275,7 @@ theorem flopperDealBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (flopperUint48Offset26Word (auctionPackedSlot (dealIdWord I)) σ_evm I).toNat < (UInt256.ofNat I.header.timestamp).toNat := Or.inr hendLt by_cases hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨3⟩ σ_evm I) = ⟨0⟩ · exact flopperDealBodyCoreMintNoCode hcode hsize hwv hsz36 hlive htic hfinished hcodeSize hdispatch hdecode hreach hAccounts diff --git a/Benchmarks/Dss/Flopper/Dent/Part1.lean b/Benchmarks/Dss/Flopper/Dent/Part1.lean index 3564249d..306d1270 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part1.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part1.lean @@ -1476,7 +1476,7 @@ theorem dentAshDecode_none_short {out : ByteArray} (hshort : out.size < 32) : theorem flopperDentBodyAfterAshSuccessKissNoCode (localsEvm evmAsh : EVM.State) (I : ExecutionEnv) (outAsh : ByteArray) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) = + Reasoning.Theory.extCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) = ⟨0⟩) : ExecBlock config { contract := contract, locals := dentAshLocals localsEvm I outAsh } evmAsh ([ .internalCall "min" [.var "bid", .var "Ash"] "kissAmt" ] ++ @@ -1529,7 +1529,7 @@ theorem flopperDentBodyAfterAshSuccessKissCallFailure (localsEvm evmAsh evmKiss : EVM.State) (I : ExecutionEnv) (outAsh outKiss : ByteArray) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) ≠ + Reasoning.Theory.extCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evmAsh @@ -1588,7 +1588,7 @@ theorem flopperDentBodyAfterAshSuccessKissCallSuccess (localsEvm evmAsh evmKiss : EVM.State) (I : ExecutionEnv) (outAsh outKiss : ByteArray) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) ≠ + Reasoning.Theory.extCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evmAsh diff --git a/Benchmarks/Dss/Flopper/Dent/Part10.lean b/Benchmarks/Dss/Flopper/Dent/Part10.lean index 88936df7..cce21393 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part10.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part10.lean @@ -101,7 +101,7 @@ theorem flopperDentBody (auctionPackedSlot (dentIdWord I)) σ_evm I := by simpa [packedSlot, id] using hcallerEq by_cases hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) = ⟨0⟩ · exact flopperDentBodyCoreMoveNoCode hcode hperm hwv hlive hguy hticOk (by simpa [packedSlot, id] using hendGt) @@ -110,7 +110,7 @@ theorem flopperDentBody hcallerNe hnoCode hdispatch hdecode rd2405 hmemLotOne hreadLotOne hAccounts · have hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩ := hnoCode by_cases hdepthEq : I.depth = 1024 · exact flopperDentBodyCoreMoveCallDepthLimit hcode hwv @@ -202,7 +202,7 @@ theorem flopperDentBody by_cases hticMoveZero : flopperUint48Offset20Word packedSlot σ' I = ⟨0⟩ · by_cases hashNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (flopperAddressReturnWord packedSlot σ' I) = ⟨0⟩ · exact flopperDentBodyCoreAshNoCodeMoveCallerNeTicZero hcode hwv hlive hguy hticOk @@ -216,7 +216,7 @@ theorem flopperDentBody rd2545True hmoveMem96 hmoveRead64 hcallMoveTrue hdispatch hdecode hAccounts · have hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ' I) ≠ ⟨0⟩ := by @@ -299,7 +299,7 @@ theorem flopperDentBody · have hmemAsh128 := hmemAsh128Of houtAsh32 have hreadAsh128 := hreadAsh128Of houtAsh32 by_cases hkissNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σAsh + Reasoning.Theory.extCodeSizeWord σAsh (flopperAddressReturnWord packedSlot σAsh I) = ⟨0⟩ · exact @@ -318,7 +318,7 @@ theorem flopperDentBody hmemAsh128 hreadAsh128 hdispatch hdecode hAccounts · have hkissCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σAsh + Reasoning.Theory.extCodeSizeWord σAsh (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σAsh I) ≠ ⟨0⟩ := by @@ -725,7 +725,7 @@ theorem flopperDentBody (auctionPackedSlot (dentIdWord I)) σ_evm I := by simpa [packedSlot, id] using hcallerEq by_cases hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) = ⟨0⟩ · exact flopperDentBodyCoreMoveNoCode hcode hperm hwv hlive hguy hticOk (by simpa [packedSlot, id] using hendGt) @@ -734,7 +734,7 @@ theorem flopperDentBody hcallerNe hnoCode hdispatch hdecode rd2405 hmemLotOne hreadLotOne hAccounts · have hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩ := hnoCode by_cases hdepthEq : I.depth = 1024 diff --git a/Benchmarks/Dss/Flopper/Dent/Part3.lean b/Benchmarks/Dss/Flopper/Dent/Part3.lean index af7def2b..3f3fc6b8 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part3.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part3.lean @@ -73,7 +73,7 @@ theorem flopperDentBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) (hsuff : (dentBegLotWord evm I).toNat ≤ (dentLotOneWord evm I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) = ⟨0⟩) : ExecTransitionBody config contract evm (dentLocals I) dentTransition.body .reverted := by have hticGuard : evalExpr? config { contract := contract, locals := dentLocals I } evm @@ -210,7 +210,7 @@ theorem flopperDentBodyReverts_moveCallFailure (hsuff : (dentBegLotWord evm I).toNat ≤ (dentLotOneWord evm I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dentVatWord evm).toNat)) "move" 0 @@ -355,7 +355,7 @@ theorem flopperDentBodyReverts_ashNoCode_moveCallerNe_ticZero (hsuff : (dentBegLotWord evm I).toNat ≤ (dentLotOneWord evm I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dentVatWord evm).toNat)) "move" 0 @@ -365,7 +365,7 @@ theorem flopperDentBodyReverts_ashNoCode_moveCallerNe_ticZero (true, evmMove, out) true) (hticMove : dentTicWord evmMove I = ⟨0⟩) (hashNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) = + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) = ⟨0⟩) : ExecTransitionBody config contract evm (dentLocals I) dentTransition.body .reverted := by have hticGuard : @@ -575,7 +575,7 @@ theorem flopperDentBodyReverts_ashCallFailure_moveCallerNe_ticZero (hsuff : (dentBegLotWord evm I).toNat ≤ (dentLotOneWord evm I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dentVatWord evm).toNat)) "move" 0 @@ -585,7 +585,7 @@ theorem flopperDentBodyReverts_ashCallFailure_moveCallerNe_ticZero (true, evmMove, outMove) true) (hticMove : dentTicWord evmMove I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ ⟨0⟩) (hashCall : typedCallViaEVM config evmMove @@ -800,7 +800,7 @@ theorem flopperDentBodyReverts_ashDecodeShort_moveCallerNe_ticZero (hsuff : (dentBegLotWord evm I).toNat ≤ (dentLotOneWord evm I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dentVatWord evm).toNat)) "move" 0 @@ -810,7 +810,7 @@ theorem flopperDentBodyReverts_ashDecodeShort_moveCallerNe_ticZero (true, evmMove, outMove) true) (hticMove : dentTicWord evmMove I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ ⟨0⟩) (hashCall : typedCallViaEVM config evmMove @@ -1027,7 +1027,7 @@ theorem flopperDentBodyReverts_afterAshRevert_moveCallerNe_ticZero (hsuff : (dentBegLotWord evm I).toNat ≤ (dentLotOneWord evm I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dentVatWord evm).toNat)) "move" 0 @@ -1037,7 +1037,7 @@ theorem flopperDentBodyReverts_afterAshRevert_moveCallerNe_ticZero (true, evmMove, outMove) true) (hticMove : dentTicWord evmMove I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ ⟨0⟩) (hashCall : typedCallViaEVM config evmMove @@ -1253,7 +1253,7 @@ theorem flopperDentBodyReverts_kissNoCode_moveCallerNe_ticZero (hsuff : (dentBegLotWord evm I).toNat ≤ (dentLotOneWord evm I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dentVatWord evm).toNat)) "move" 0 @@ -1263,7 +1263,7 @@ theorem flopperDentBodyReverts_kissNoCode_moveCallerNe_ticZero (true, evmMove, outMove) true) (hticMove : dentTicWord evmMove I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ ⟨0⟩) (hashCall : typedCallViaEVM config evmMove @@ -1271,7 +1271,7 @@ theorem flopperDentBodyReverts_kissNoCode_moveCallerNe_ticZero (true, evmAsh, outAsh) true) (houtAsh32 : 32 ≤ outAsh.size) (hkissNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) = + Reasoning.Theory.extCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) = ⟨0⟩) : ExecTransitionBody config contract evm (dentLocals I) dentTransition.body .reverted := flopperDentBodyReverts_afterAshRevert_moveCallerNe_ticZero @@ -1297,7 +1297,7 @@ theorem flopperDentBodyReverts_kissCallFailure_moveCallerNe_ticZero (hsuff : (dentBegLotWord evm I).toNat ≤ (dentLotOneWord evm I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dentVatWord evm).toNat)) "move" 0 @@ -1307,7 +1307,7 @@ theorem flopperDentBodyReverts_kissCallFailure_moveCallerNe_ticZero (true, evmMove, outMove) true) (hticMove : dentTicWord evmMove I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ ⟨0⟩) (hashCall : typedCallViaEVM config evmMove @@ -1315,7 +1315,7 @@ theorem flopperDentBodyReverts_kissCallFailure_moveCallerNe_ticZero (true, evmAsh, outAsh) true) (houtAsh32 : 32 ≤ outAsh.size) (hkissCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) ≠ + Reasoning.Theory.extCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) ≠ ⟨0⟩) (hkissCall : typedCallViaEVM config evmAsh @@ -1335,7 +1335,7 @@ theorem flopperDentBodyMoveSuccessTicNonzeroToLot (evm evmMove : EVM.State) (I : ExecutionEnv) (out : ByteArray) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dentVatWord evm).toNat)) "move" 0 @@ -1475,7 +1475,7 @@ theorem flopperDentBodyMoveAshKissSuccessTicZeroToLot (outMove outAsh outKiss : ByteArray) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dentVatWord evm).toNat)) "move" 0 @@ -1485,7 +1485,7 @@ theorem flopperDentBodyMoveAshKissSuccessTicZeroToLot (true, evmMove, outMove) true) (hticMove : dentTicWord evmMove I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ ⟨0⟩) (hashCall : typedCallViaEVM config evmMove @@ -1493,7 +1493,7 @@ theorem flopperDentBodyMoveAshKissSuccessTicZeroToLot (true, evmAsh, outAsh) true) (houtAsh32 : 32 ≤ outAsh.size) (hkissCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) ≠ + Reasoning.Theory.extCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) ≠ ⟨0⟩) (hkissCall : typedCallViaEVM config evmAsh diff --git a/Benchmarks/Dss/Flopper/Dent/Part4.lean b/Benchmarks/Dss/Flopper/Dent/Part4.lean index 94413be4..ab7429b3 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part4.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part4.lean @@ -26,7 +26,7 @@ theorem flopperDentBodyReverts_addOverflow_moveCallerNe_ticZero_kissSuccess (hsuff : (dentBegLotWord evm I).toNat ≤ (dentLotOneWord evm I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dentVatWord evm).toNat)) "move" 0 @@ -36,7 +36,7 @@ theorem flopperDentBodyReverts_addOverflow_moveCallerNe_ticZero_kissSuccess (true, evmMove, outMove) true) (hticMove : dentTicWord evmMove I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ ⟨0⟩) (hashCall : typedCallViaEVM config evmMove @@ -44,7 +44,7 @@ theorem flopperDentBodyReverts_addOverflow_moveCallerNe_ticZero_kissSuccess (true, evmAsh, outAsh) true) (houtAsh32 : 32 ≤ outAsh.size) (hkissCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) ≠ + Reasoning.Theory.extCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) ≠ ⟨0⟩) (hkissCall : typedCallViaEVM config evmAsh @@ -155,7 +155,7 @@ theorem flopperDentBodyReturns_success_moveCallerNe_ticZero_kissSuccess (hsuff : (dentBegLotWord evm I).toNat ≤ (dentLotOneWord evm I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dentVatWord evm).toNat)) "move" 0 @@ -165,7 +165,7 @@ theorem flopperDentBodyReturns_success_moveCallerNe_ticZero_kissSuccess (true, evmMove, outMove) true) (hticMove : dentTicWord evmMove I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ + Reasoning.Theory.extCodeSizeWord evmMove.accountMap (dentGuyWord evmMove I) ≠ ⟨0⟩) (hashCall : typedCallViaEVM config evmMove @@ -173,7 +173,7 @@ theorem flopperDentBodyReturns_success_moveCallerNe_ticZero_kissSuccess (true, evmAsh, outAsh) true) (houtAsh32 : 32 ≤ outAsh.size) (hkissCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) ≠ + Reasoning.Theory.extCodeSizeWord evmAsh.accountMap (dentGuyWord evmAsh I) ≠ ⟨0⟩) (hkissCall : typedCallViaEVM config evmAsh @@ -291,7 +291,7 @@ theorem flopperDentBodyReverts_addOverflow_moveCallerNe_ticNonzero (hsuff : (dentBegLotWord evm I).toNat ≤ (dentLotOneWord evm I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dentVatWord evm).toNat)) "move" 0 @@ -399,7 +399,7 @@ theorem flopperDentBodyReturns_success_moveCallerNe_ticNonzero (hsuff : (dentBegLotWord evm I).toNat ≤ (dentLotOneWord evm I).toNat) (hcaller : UInt256.ofNat evm.executionEnv.source.val ≠ dentGuyWord evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord evm.accountMap (dentVatWord evm) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm (EVM.address (AccountAddress.ofNat (dentVatWord evm).toNat)) "move" 0 diff --git a/Benchmarks/Dss/Flopper/Dent/Part5.lean b/Benchmarks/Dss/Flopper/Dent/Part5.lean index 081f77d5..fd0d68d8 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part5.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part5.lean @@ -1198,7 +1198,7 @@ theorem flopperDentX_moveNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt (hmemCaller : memCaller.size = 96) (hread64Caller : memCaller.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flopperAddressReturnWord ⟨2⟩ σ I) = + Reasoning.Theory.extCodeSizeWord σ (flopperAddressReturnWord ⟨2⟩ σ I) = ⟨0⟩) (rd2439 : RD flopperBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2439⟩ [dentBidWord I, dentLotWord I, dentIdWord I, ⟨334⟩, sel] @@ -1206,7 +1206,7 @@ theorem flopperDentX_moveNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt RDrev flopperBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd2529⟩ := flopperDentX_toMoveExtcodesizeGuard hmemCaller hread64Caller rd2439 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2529⟩) (okPc := ⟨2541⟩) rd2529 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2529⟩) (okPc := ⟨2541⟩) rd2529 hnoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1217,7 +1217,7 @@ theorem flopperDentX_moveCall {k C : ℕ} (hperm : I.perm = true) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flopperAddressReturnWord ⟨2⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (flopperAddressReturnWord ⟨2⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hmemCaller : memCaller.size = 96) @@ -1256,7 +1256,7 @@ theorem flopperDentX_moveCall obtain ⟨_, _, rd2529⟩ := flopperDentX_toMoveExtcodesizeGuard hmemCaller hread64Caller rd2439 obtain ⟨gasWord, _, _, rd2544⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2529⟩) (okPc := ⟨2541⟩) rd2529 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2529⟩) (okPc := ⟨2541⟩) rd2529 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1297,7 +1297,7 @@ theorem flopperDentX_moveCallDepthLimit {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} {memCaller : ByteArray} {k C : ℕ} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flopperAddressReturnWord ⟨2⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (flopperAddressReturnWord ⟨2⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hmemCaller : memCaller.size = 96) @@ -1319,7 +1319,7 @@ theorem flopperDentX_moveCallDepthLimit obtain ⟨_, _, rd2529⟩ := flopperDentX_toMoveExtcodesizeGuard hmemCaller hread64Caller rd2439 obtain ⟨gasWord, _, _, rd2544⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2529⟩) (okPc := ⟨2541⟩) rd2529 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2529⟩) (okPc := ⟨2541⟩) rd2529 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1351,7 +1351,7 @@ theorem flopperDentX_moveCallFailure mem aw out (cA', σ') k C) (houtSize : out.size < UInt256.size) : RDrev flopperBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2545⟩) (okPc := ⟨2561⟩) rd2545 + exact RD.solcCallSuccessGuardMissing (pc := ⟨2545⟩) (okPc := ⟨2561⟩) rd2545 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1387,7 +1387,7 @@ theorem flopperDentX_moveSuccessTicNonzeroToTail let src := UInt256.ofNat I.source.val let σGuy := dentRuntimeAfterGuyMap I.codeOwner σ' I obtain ⟨_, _, rd2563⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨2545⟩) (okPc := ⟨2561⟩) rd2545 + RD.solcCallSuccessGuardOk (pc := ⟨2545⟩) (okPc := ⟨2561⟩) rd2545 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Flopper/Dent/Part6.lean b/Benchmarks/Dss/Flopper/Dent/Part6.lean index b5ff8208..e9de3509 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part6.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part6.lean @@ -87,7 +87,7 @@ theorem flopperDentX_moveSuccessTicZeroToAshExtcodesizeGuard (lt_of_lt_of_le (by decide : 64 < 160) hmemAshSelector160) (by decide) hread64AshSelector obtain ⟨_, _, rd2563⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨2545⟩) (okPc := ⟨2561⟩) rd2545 + RD.solcCallSuccessGuardOk (pc := ⟨2545⟩) (okPc := ⟨2561⟩) rd2545 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -329,7 +329,7 @@ theorem flopperDentX_moveSuccessTicZeroAshNoCode (hticZero : flopperUint48Offset20Word (auctionPackedSlot (dentIdWord I)) σ' I = ⟨0⟩) (hashNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ' I) = ⟨0⟩) (rd2545 : RD flopperBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2545⟩ (⟨1⟩ :: dentMoveEndPtr :: dentMoveSelectorWord :: @@ -340,7 +340,7 @@ theorem flopperDentX_moveSuccessTicZeroAshNoCode obtain ⟨_, _, _, rd2674, _hashCalldata, _hmem128, _hread64⟩ := flopperDentX_moveSuccessTicZeroToAshExtcodesizeGuard (g := g) hmem hread64 hticZero rd2545 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2674⟩) (okPc := ⟨2686⟩) rd2674 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2674⟩) (okPc := ⟨2686⟩) rd2674 hashNoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -356,7 +356,7 @@ theorem flopperDentX_ashCallFailure mem aw out (cA', σ') k C) (houtSize : out.size < UInt256.size) : RDrev flopperBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2690⟩) (okPc := ⟨2706⟩) rd2690 + exact RD.solcCallSuccessGuardMissing (pc := ⟨2690⟩) (okPc := ⟨2706⟩) rd2690 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -373,7 +373,7 @@ theorem flopperDentX_moveSuccessTicZeroAshCall (hticZero : flopperUint48Offset20Word (auctionPackedSlot (dentIdWord I)) σ' I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd2545 : RD flopperBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2545⟩ @@ -422,7 +422,7 @@ theorem flopperDentX_moveSuccessTicZeroAshCall flopperDentX_moveSuccessTicZeroToAshExtcodesizeGuard (g := g) hmem hread64 hticZero rd2545 obtain ⟨gasWord, _, _, rd2689⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2674⟩) (okPc := ⟨2686⟩) rd2674 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2674⟩) (okPc := ⟨2686⟩) rd2674 hashCodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -520,7 +520,7 @@ theorem flopperDentX_ashCallSuccessDecodeShort mem (UInt256.ofNat 8) out acc k C) : RDrev flopperBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd2708⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨2690⟩) (okPc := ⟨2706⟩) rd2690 + RD.solcCallSuccessGuardOk (pc := ⟨2690⟩) (okPc := ⟨2706⟩) rd2690 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -559,7 +559,7 @@ theorem flopperDentX_ashCallSuccessDecodeOk ⟨334⟩ :: sel :: []) mem (UInt256.ofNat 8) out acc k' C' := by obtain ⟨_, _, rd2708⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨2690⟩) (okPc := ⟨2706⟩) rd2690 + RD.solcCallSuccessGuardOk (pc := ⟨2690⟩) (okPc := ⟨2706⟩) rd2690 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -871,7 +871,7 @@ theorem flopperDentX_kissNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel target : UInt256} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {mem out : ByteArray} {k C : ℕ} - (hnoCode : Reasoning.Theory.uniswapExtCodeSizeWord acc.2 target = ⟨0⟩) + (hnoCode : Reasoning.Theory.extCodeSizeWord acc.2 target = ⟨0⟩) (rd2817 : RD flopperBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2817⟩ (target :: target :: ⟨0⟩ :: dentKissOutPtr :: dentKissInSize :: dentKissOutPtr :: dentKissOutSize :: dentKissEndPtr :: dentKissSelectorWord :: target :: @@ -879,7 +879,7 @@ theorem flopperDentX_kissNoCode sel :: []) mem (UInt256.ofNat 8) out acc k C) : RDrev flopperBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2817⟩) (okPc := ⟨2829⟩) rd2817 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2817⟩) (okPc := ⟨2829⟩) rd2817 hnoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -891,7 +891,7 @@ theorem flopperDentX_kissCall {acc : Batteries.RBSet AccountAddress compare × AccountMap} {mem outAsh : ByteArray} {k C : ℕ} (hperm : I.perm = true) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord acc.2 target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord acc.2 target ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hencode : config.externalABI.encode? "kiss" @@ -921,7 +921,7 @@ theorem flopperDentX_kissCall outKiss) true ∧ outKiss.size < UInt256.size := by obtain ⟨gasWord, _, _, rd2832⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2817⟩) (okPc := ⟨2829⟩) rd2817 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2817⟩) (okPc := ⟨2829⟩) rd2817 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -979,7 +979,7 @@ theorem flopperDentX_kissCallFailure mem aw outKiss acc k C) (houtSize : outKiss.size < UInt256.size) : RDrev flopperBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2833⟩) (okPc := ⟨2849⟩) rd2833 + exact RD.solcCallSuccessGuardMissing (pc := ⟨2833⟩) (okPc := ⟨2849⟩) rd2833 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1122,7 +1122,7 @@ theorem flopperDentX_kissCallSuccessToTail memGuy (UInt256.ofNat 8) outKiss (cAKiss, dentRuntimeAfterGuyMap I.codeOwner σKiss I) k' C' := by obtain ⟨_, _, rd2851⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨2833⟩) (okPc := ⟨2849⟩) rd2833 + RD.solcCallSuccessGuardOk (pc := ⟨2833⟩) (okPc := ⟨2849⟩) rd2833 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1290,7 +1290,7 @@ theorem flopperDentX_addOverflowFromCheckedAdd rw [hltTrue] native_decide have rd4763 := rd4759.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd4763 + exact RD.solcPush1Dup1Revert0 rd4763 (by native_decide) (by native_decide) (by native_decide) (by simp) @@ -1675,7 +1675,7 @@ theorem flopperDentX_addOverflowFromCheckedAddAw8 rw [hltTrue] native_decide have rd4763 := rd4759.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd4763 + exact RD.solcPush1Dup1Revert0 rd4763 (by native_decide) (by native_decide) (by native_decide) (by simp) diff --git a/Benchmarks/Dss/Flopper/Dent/Part7.lean b/Benchmarks/Dss/Flopper/Dent/Part7.lean index cfa48114..47624975 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part7.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part7.lean @@ -448,7 +448,7 @@ theorem flopperDentBodyCoreMoveNoCode UInt256.ofNat I.source.val ≠ flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ_evm I) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) = ⟨0⟩) (hdispatch : dispatchMsg contract I.calldata = some dentTransition) (hdecode : @@ -521,7 +521,7 @@ theorem flopperDentBodyCoreMoveNoCode rw [hword] simpa [evmSolm, dentGuyWord, initState, packedSlot] using heq have hnoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) = ⟨0⟩ := flopperCodeSize_zero_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hnoCode have hbody : @@ -575,7 +575,7 @@ theorem flopperDentBodyCoreMoveCallFailure UInt256.ofNat I.source.val ≠ flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ_evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (rd2545 : RD flopperBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨2545⟩ @@ -687,7 +687,7 @@ theorem flopperDentBodyCoreMoveCallFailure rw [hguyEq] simpa [evmSolm, dentGuyWord, initState, packedSlot] using heq have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hbody : @@ -731,7 +731,7 @@ theorem flopperDentBodyCoreMoveCallDepthLimit UInt256.ofNat I.source.val ≠ flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ_evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hdispatch : dispatchMsg contract I.calldata = some dentTransition) @@ -826,12 +826,12 @@ theorem flopperDentBodyCoreAshNoCodeMoveCallerNeTicZero UInt256.ofNat I.source.val ≠ flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ_evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hticMove : flopperUint48Offset20Word (auctionPackedSlot (dentIdWord I)) σ' I = ⟨0⟩) (hashNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ' I) = ⟨0⟩) (rd2545 : RD flopperBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨2545⟩ @@ -947,7 +947,7 @@ theorem flopperDentBodyCoreAshNoCodeMoveCallerNeTicZero rw [hguyEq] simpa [evmSolm, dentGuyWord, initState, packedSlot] using heq have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hticMoveSolm : dentTicWord evmCallSolm I = ⟨0⟩ := by @@ -955,7 +955,7 @@ theorem flopperDentBodyCoreAshNoCodeMoveCallerNeTicZero hpostAccountsCall packedSlot simpa [evmCallSolm, dentTicWord, packedSlot, hcallEnv, hword] using hticMove have hashNoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmCallSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmCallSolm.accountMap (dentGuyWord evmCallSolm I) = ⟨0⟩ := by have hzero := flopperCodeSize_zero_accountMapEquiv_addressSlot @@ -1006,12 +1006,12 @@ theorem flopperDentBodyCoreAshCallFailureMoveCallerNeTicZero UInt256.ofNat I.source.val ≠ flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ_evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hticMove : flopperUint48Offset20Word (auctionPackedSlot (dentIdWord I)) σ' I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd2690 : RD flopperBytecode I (Sat256.ofUInt256 g) @@ -1179,7 +1179,7 @@ theorem flopperDentBodyCoreAshCallFailureMoveCallerNeTicZero rw [hguyEq] simpa [evmSolm, dentGuyWord, initState, packedSlot] using heq have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hticMoveSolm : dentTicWord evmCallSolm I = ⟨0⟩ := by @@ -1187,7 +1187,7 @@ theorem flopperDentBodyCoreAshCallFailureMoveCallerNeTicZero hpostAccountsCall packedSlot simpa [evmCallSolm, dentTicWord, packedSlot, hcallEnv, hword] using hticMove have hashCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmCallSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmCallSolm.accountMap (dentGuyWord evmCallSolm I) ≠ ⟨0⟩ := by have hne := flopperCodeSize_ne_accountMapEquiv_addressSlot @@ -1236,12 +1236,12 @@ theorem flopperDentBodyCoreAshDecodeShortMoveCallerNeTicZero UInt256.ofNat I.source.val ≠ flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ_evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hticMove : flopperUint48Offset20Word (auctionPackedSlot (dentIdWord I)) σ' I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd2690 : RD flopperBytecode I (Sat256.ofUInt256 g) @@ -1412,7 +1412,7 @@ theorem flopperDentBodyCoreAshDecodeShortMoveCallerNeTicZero rw [hguyEq] simpa [evmSolm, dentGuyWord, initState, packedSlot] using heq have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hticMoveSolm : dentTicWord evmCallSolm I = ⟨0⟩ := by @@ -1420,7 +1420,7 @@ theorem flopperDentBodyCoreAshDecodeShortMoveCallerNeTicZero hpostAccountsCall packedSlot simpa [evmCallSolm, dentTicWord, packedSlot, hcallEnv, hword] using hticMove have hashCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmCallSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmCallSolm.accountMap (dentGuyWord evmCallSolm I) ≠ ⟨0⟩ := by have hne := flopperCodeSize_ne_accountMapEquiv_addressSlot @@ -1469,15 +1469,15 @@ theorem flopperDentBodyCoreKissNoCodeMoveCallerNeTicZero UInt256.ofNat I.source.val ≠ flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ_evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hticMove : flopperUint48Offset20Word (auctionPackedSlot (dentIdWord I)) σ' I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ' I) ≠ ⟨0⟩) (hkissNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σAsh + Reasoning.Theory.extCodeSizeWord σAsh (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σAsh I) = ⟨0⟩) (hdepth : I.depth.val < 1024) (rd2690 : RD flopperBytecode I (Sat256.ofUInt256 g) @@ -1650,7 +1650,7 @@ theorem flopperDentBodyCoreKissNoCodeMoveCallerNeTicZero rw [hguyEq] simpa [evmSolm, dentGuyWord, initState, packedSlot] using heq have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hticMoveSolm : dentTicWord evmCallSolm I = ⟨0⟩ := by @@ -1658,14 +1658,14 @@ theorem flopperDentBodyCoreKissNoCodeMoveCallerNeTicZero hpostAccountsCall packedSlot simpa [evmCallSolm, dentTicWord, packedSlot, hcallEnv, hword] using hticMove have hashCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmCallSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmCallSolm.accountMap (dentGuyWord evmCallSolm I) ≠ ⟨0⟩ := by have hne := flopperCodeSize_ne_accountMapEquiv_addressSlot hpostAccountsCall packedSlot hashCodeSize simpa [evmCallSolm, dentGuyWord, packedSlot, hcallEnv] using hne have hkissNoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmAshSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmAshSolm.accountMap (dentGuyWord evmAshSolm I) = ⟨0⟩ := by have hzero := flopperCodeSize_zero_accountMapEquiv_addressSlot diff --git a/Benchmarks/Dss/Flopper/Dent/Part8.lean b/Benchmarks/Dss/Flopper/Dent/Part8.lean index 3951ddad..2ee8a0c7 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part8.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part8.lean @@ -39,15 +39,15 @@ theorem flopperDentBodyCoreKissCallFailureMoveCallerNeTicZero UInt256.ofNat I.source.val ≠ flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ_evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hticMove : flopperUint48Offset20Word (auctionPackedSlot (dentIdWord I)) σ' I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ' I) ≠ ⟨0⟩) (hkissCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σAsh + Reasoning.Theory.extCodeSizeWord σAsh (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σAsh I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd2833 : RD flopperBytecode I (Sat256.ofUInt256 g) @@ -276,7 +276,7 @@ theorem flopperDentBodyCoreKissCallFailureMoveCallerNeTicZero rw [hguyEq] simpa [evmSolm, dentGuyWord, initState, packedSlot] using heq have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hticMoveSolm : dentTicWord evmCallSolm I = ⟨0⟩ := by @@ -284,14 +284,14 @@ theorem flopperDentBodyCoreKissCallFailureMoveCallerNeTicZero hpostAccountsCall packedSlot simpa [evmCallSolm, dentTicWord, packedSlot, hcallEnv, hword] using hticMove have hashCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmCallSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmCallSolm.accountMap (dentGuyWord evmCallSolm I) ≠ ⟨0⟩ := by have hne := flopperCodeSize_ne_accountMapEquiv_addressSlot hpostAccountsCall packedSlot hashCodeSize simpa [evmCallSolm, dentGuyWord, packedSlot, hcallEnv] using hne have hkissCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmAshSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmAshSolm.accountMap (dentGuyWord evmAshSolm I) ≠ ⟨0⟩ := by have hne := flopperCodeSize_ne_accountMapEquiv_addressSlot @@ -343,15 +343,15 @@ theorem flopperDentBodyCoreAddOverflowMoveCallerNeTicZeroKissSuccess UInt256.ofNat I.source.val ≠ flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ_evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hticMove : flopperUint48Offset20Word (auctionPackedSlot (dentIdWord I)) σ' I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ' I) ≠ ⟨0⟩) (hkissCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σAsh + Reasoning.Theory.extCodeSizeWord σAsh (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σAsh I) ≠ ⟨0⟩) (haddOverflow : 2 ^ 48 ≤ @@ -593,7 +593,7 @@ theorem flopperDentBodyCoreAddOverflowMoveCallerNeTicZeroKissSuccess rw [hguyEq] simpa [evmSolm, dentGuyWord, initState, packedSlot] using heq have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hticMoveSolm : dentTicWord evmCallSolm I = ⟨0⟩ := by @@ -601,14 +601,14 @@ theorem flopperDentBodyCoreAddOverflowMoveCallerNeTicZeroKissSuccess hpostAccountsCall packedSlot simpa [evmCallSolm, dentTicWord, packedSlot, hcallEnv, hword] using hticMove have hashCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmCallSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmCallSolm.accountMap (dentGuyWord evmCallSolm I) ≠ ⟨0⟩ := by have hne := flopperCodeSize_ne_accountMapEquiv_addressSlot hpostAccountsCall packedSlot hashCodeSize simpa [evmCallSolm, dentGuyWord, packedSlot, hcallEnv] using hne have hkissCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmAshSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmAshSolm.accountMap (dentGuyWord evmAshSolm I) ≠ ⟨0⟩ := by have hne := flopperCodeSize_ne_accountMapEquiv_addressSlot @@ -670,15 +670,15 @@ theorem flopperDentBodyCoreSuccessMoveCallerNeTicZeroKissSuccess UInt256.ofNat I.source.val ≠ flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ_evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hticMove : flopperUint48Offset20Word (auctionPackedSlot (dentIdWord I)) σ' I = ⟨0⟩) (hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ' I) ≠ ⟨0⟩) (hkissCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σAsh + Reasoning.Theory.extCodeSizeWord σAsh (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σAsh I) ≠ ⟨0⟩) (haddFit : (UInt256.land (UInt256.ofNat I.header.timestamp) flopperUint48Mask).toNat + @@ -920,7 +920,7 @@ theorem flopperDentBodyCoreSuccessMoveCallerNeTicZeroKissSuccess rw [hguyEq] simpa [evmSolm, dentGuyWord, initState, packedSlot] using heq have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hticMoveSolm : dentTicWord evmCallSolm I = ⟨0⟩ := by @@ -928,14 +928,14 @@ theorem flopperDentBodyCoreSuccessMoveCallerNeTicZeroKissSuccess hpostAccountsCall packedSlot simpa [evmCallSolm, dentTicWord, packedSlot, hcallEnv, hword] using hticMove have hashCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmCallSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmCallSolm.accountMap (dentGuyWord evmCallSolm I) ≠ ⟨0⟩ := by have hne := flopperCodeSize_ne_accountMapEquiv_addressSlot hpostAccountsCall packedSlot hashCodeSize simpa [evmCallSolm, dentGuyWord, packedSlot, hcallEnv] using hne have hkissCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmAshSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmAshSolm.accountMap (dentGuyWord evmAshSolm I) ≠ ⟨0⟩ := by have hne := flopperCodeSize_ne_accountMapEquiv_addressSlot @@ -1011,7 +1011,7 @@ theorem flopperDentBodyCoreAddOverflowMoveCallerNeTicNonzero UInt256.ofNat I.source.val ≠ flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ_evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hticMove : flopperUint48Offset20Word (auctionPackedSlot (dentIdWord I)) σ' I ≠ ⟨0⟩) @@ -1135,7 +1135,7 @@ theorem flopperDentBodyCoreAddOverflowMoveCallerNeTicNonzero rw [hguyEq] simpa [evmSolm, dentGuyWord, initState, packedSlot] using heq have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hticMoveSolm : dentTicWord evmCallSolm I ≠ ⟨0⟩ := by @@ -1199,7 +1199,7 @@ theorem flopperDentBodyCoreSuccessMoveCallerNeTicNonzero UInt256.ofNat I.source.val ≠ flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ_evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hticMove : flopperUint48Offset20Word (auctionPackedSlot (dentIdWord I)) σ' I ≠ ⟨0⟩) @@ -1324,7 +1324,7 @@ theorem flopperDentBodyCoreSuccessMoveCallerNeTicNonzero rw [hguyEq] simpa [evmSolm, dentGuyWord, initState, packedSlot] using heq have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hticMoveSolm : dentTicWord evmCallSolm I ≠ ⟨0⟩ := by diff --git a/Benchmarks/Dss/Flopper/Dent/Part9.lean b/Benchmarks/Dss/Flopper/Dent/Part9.lean index 32121945..6f9fa1e2 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part9.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part9.lean @@ -685,7 +685,7 @@ theorem flopperDentBodyCoreMoveSuccessTicZero UInt256.ofNat I.source.val ≠ flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ_evm I) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hticMove : flopperUint48Offset20Word (auctionPackedSlot (dentIdWord I)) σ' I = ⟨0⟩) @@ -719,13 +719,13 @@ theorem flopperDentBodyCoreMoveSuccessTicZero (hAccounts : accountMapEquiv σ_evm σ_solm) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by by_cases hashNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ' I) = ⟨0⟩ · exact flopperDentBodyCoreAshNoCodeMoveCallerNeTicZero hcode hwv hlive hguy hticOk hendGt hbid hlotLt hbegFit hlotOneFit hsuff hcaller hcodeSize hticMove hashNoCode rd2545 hmem hread64 hcall hdispatch hdecode hAccounts · have hashCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σ' I) ≠ ⟨0⟩ := hashNoCode obtain ⟨memAshSelector, cAAsh, σAsh, zAsh, outAsh, AinAsh, AAsh, k2690, C2690, @@ -783,7 +783,7 @@ theorem flopperDentBodyCoreMoveSuccessTicZero · have hmemAsh128 := hmemAsh128Of houtAsh32 have hreadAsh128 := hreadAsh128Of houtAsh32 by_cases hkissNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σAsh + Reasoning.Theory.extCodeSizeWord σAsh (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σAsh I) = ⟨0⟩ · exact flopperDentBodyCoreKissNoCodeMoveCallerNeTicZero hcode hwv hlive hguy @@ -792,7 +792,7 @@ theorem flopperDentBodyCoreMoveSuccessTicZero houtAshSize hmemAsh64 hreadAsh64 hmemAsh128 hreadAsh128 hdispatch hdecode hAccounts · have hkissCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σAsh + Reasoning.Theory.extCodeSizeWord σAsh (flopperAddressReturnWord (auctionPackedSlot (dentIdWord I)) σAsh I) ≠ ⟨0⟩ := hkissNoCode obtain ⟨_, _, rd2731⟩ := diff --git a/Benchmarks/Dss/Flopper/Dispatch.lean b/Benchmarks/Dss/Flopper/Dispatch.lean index 4a94f1f4..f9198aa8 100644 --- a/Benchmarks/Dss/Flopper/Dispatch.lean +++ b/Benchmarks/Dss/Flopper/Dispatch.lean @@ -603,7 +603,7 @@ theorem flopperX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) /-- Calldata shorter than a selector reverts at the shared dispatcher revert block. -/ @@ -628,7 +628,7 @@ theorem flopperX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h300 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h300 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) /-- A fallthrough `PUSH2 300; JUMP` reaches the shared revert block. -/ @@ -643,7 +643,7 @@ theorem flopperJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : UI (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h300 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h300 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem flopperLowLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -666,7 +666,7 @@ theorem flopperLowLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : |>.selectorArmNotTakenAuto (flopperLowLowArmsWellFormed 4 (by omega)) (heq0 4 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h300 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h300 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem flopperLowHighNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} diff --git a/Benchmarks/Dss/Flopper/Kick/Part2.lean b/Benchmarks/Dss/Flopper/Kick/Part2.lean index cf660109..aa10a00d 100644 --- a/Benchmarks/Dss/Flopper/Kick/Part2.lean +++ b/Benchmarks/Dss/Flopper/Kick/Part2.lean @@ -159,7 +159,7 @@ theorem flopperKickX_addOverflow {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} rw [hltTrue] native_decide have rd4763 := rd4759.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd4763 + exact RD.solcPush1Dup1Revert0 rd4763 (by native_decide) (by native_decide) (by native_decide) (by simp) diff --git a/Benchmarks/Dss/Flopper/SpecSyntax.lean b/Benchmarks/Dss/Flopper/SpecSyntax.lean index 068ff8cc..c68f9557 100644 --- a/Benchmarks/Dss/Flopper/SpecSyntax.lean +++ b/Benchmarks/Dss/Flopper/SpecSyntax.lean @@ -2,19 +2,220 @@ import Benchmarks.Dss.Flopper.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS Flopper spec through the Solm notation frontend +# Flopper spec in the Solidity-faithful Solm frontend -The main spec lives in `Spec.lean`; this companion keeps the benchmark's notation-side check wired -up as the body surface grows. +The whole `flop.sol` spec written with `solidity%` and proven definitionally equal to the AST +spec in `Spec.lean`. Checked-math helper statement lists are inlined; the `Bid.end` field is +the guillemet-escaped `«end»`; `extCodeSize` guards on storage receivers use `${…}` escapes. +The `Ash`/`kiss` external calls in `dent` have a storage *path* receiver (`bids[id].guy`), +which the surface call form cannot express, so those two checked calls are `${…}` statement +splices of the spec's own `checkedExternalCallStmts`. Transition order matches +`contract.transitions` (selector order). -/ -open Solm Solm.Notation +open Solm Solm.Notation Benchmarks.Dss.Flopper namespace Benchmarks.Dss.Flopper.Syntax -def contractSyntax : ContractDecl := Benchmarks.Dss.Flopper.contract +def contractSyntax : ContractDecl := solidity% contract Flopper { + struct Bid { + uint256 bid; + uint256 lot; + address guy; + uint48 tic; + uint48 «end»; + } -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Flopper.contract := by - rfl + mapping(address => uint256) wards; + mapping(uint256 => Bid) bids; + address vat; + address gem; + uint256 beg; + uint256 pad; + uint48 ttl; + uint48 tau; + uint256 kicks; + uint256 live; + address vow; + + constructor(address vat_, address gem_) { + beg = #defaultBeg; + pad = #defaultPad; + ttl = #defaultTtl; + tau = #defaultTau; + kicks = 0; + wards[msg.sender] = 1; + vat = vat_; + gem = gem_; + live = 1; + } + + function add(uint48 x, uint48 y) internal returns (uint48) { + uint48 z = (x + y) % #uint48Modulus; + require(z >= x); + return z; + } + + function mul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + return z; + } + + function min(uint256 x, uint256 y) internal returns (uint256) { + if (x > y) { + return y; + } else { + return x; + } + } + + function beg() external returns (uint256) { + return beg; + } + + function bids(uint256 arg0) external returns (uint256, uint256, address, uint48, uint48) { + return (bids[arg0].bid, bids[arg0].lot, bids[arg0].guy, bids[arg0].tic, bids[arg0].«end»); + } + + function cage() external { + require(wards[msg.sender] == 1); + live = 0; + vow = msg.sender; + } + + function deal(uint256 id) external { + require(live == 1); + require(bids[id].tic != 0 && (bids[id].tic < block.timestamp || bids[id].«end» < block.timestamp)); + require(${Expr.extCodeSize (.storage gemRef)} > 0); + var _mintRet = gem.mint(bids[id].guy, bids[id].lot); + delete bids[id]; + } + + function dent(uint256 id, uint256 lot, uint256 bid) external { + require(live == 1); + require(bids[id].guy != address(0)); + require(bids[id].tic > block.timestamp || bids[id].tic == 0); + require(bids[id].«end» > block.timestamp); + require(bid == bids[id].bid); + require(lot < bids[id].lot); + uint256 begLot = (beg * lot) as uint256; + require(lot == 0 || begLot / lot == beg); + uint256 lotOne = (bids[id].lot * #ONE) as uint256; + require(#ONE == 0 || lotOne / #ONE == bids[id].lot); + require(begLot <= lotOne); + if (msg.sender != bids[id].guy) { + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _moveRet = vat.move(msg.sender, bids[id].guy, bid); + if (bids[id].tic == 0) { + ${checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "Ash" (.intLit 0) [] "Ash"} + var kissAmt = min(bid, ${Expr.var "Ash"}); + ${checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "kiss" (.intLit 0) [.var "kissAmt"] "_kissRet"} + } + bids[id].guy = msg.sender; + } + bids[id].lot = lot; + uint48 tic_ = (block.timestamp % #uint48Modulus + ttl) % #uint48Modulus; + require(tic_ >= block.timestamp % #uint48Modulus); + bids[id].tic = tic_; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x6265670000000000000000000000000000000000000000000000000000000000)) { + beg = data; + } else if (what == bytes32(0x7061640000000000000000000000000000000000000000000000000000000000)) { + pad = data; + } else if (what == bytes32(0x74746c0000000000000000000000000000000000000000000000000000000000)) { + ttl = data % #uint48Modulus; + } else if (what == bytes32(0x7461750000000000000000000000000000000000000000000000000000000000)) { + tau = data % #uint48Modulus; + } else { + require(false); + } + } + + function gem() external returns (address) { + return gem; + } + + function kick(address gal, uint256 lot, uint256 bid) external returns (uint256) { + require(wards[msg.sender] == 1); + require(live == 1); + require(kicks < #maxUint256); + uint256 id = kicks + 1; + kicks = id; + bids[id].bid = bid; + bids[id].lot = lot; + bids[id].guy = gal; + uint48 end_ = (block.timestamp % #uint48Modulus + tau) % #uint48Modulus; + require(end_ >= block.timestamp % #uint48Modulus); + bids[id].«end» = end_; + return id; + } + + function kicks() external returns (uint256) { + return kicks; + } + + function live() external returns (uint256) { + return live; + } + + function pad() external returns (uint256) { + return pad; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 1; + } + + function tau() external returns (uint48) { + return tau; + } + + function tick(uint256 id) external { + require(bids[id].«end» < block.timestamp); + require(bids[id].tic == 0); + uint256 lotBase = (pad * bids[id].lot) as uint256; + require(bids[id].lot == 0 || lotBase / bids[id].lot == pad); + bids[id].lot = lotBase / #ONE; + uint48 end_ = (block.timestamp % #uint48Modulus + tau) % #uint48Modulus; + require(end_ >= block.timestamp % #uint48Modulus); + bids[id].«end» = end_; + } + + function ttl() external returns (uint48) { + return ttl; + } + + function vat() external returns (address) { + return vat; + } + + function vow() external returns (address) { + return vow; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } + + function yank(uint256 id) external { + require(live == 0); + require(bids[id].guy != address(0)); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _suckRet = vat.suck(vow, bids[id].guy, bids[id].bid); + delete bids[id]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Flopper.contract := by rfl end Benchmarks.Dss.Flopper.Syntax diff --git a/Benchmarks/Dss/Flopper/Tick/Part2.lean b/Benchmarks/Dss/Flopper/Tick/Part2.lean index 65290516..5286cf9a 100644 --- a/Benchmarks/Dss/Flopper/Tick/Part2.lean +++ b/Benchmarks/Dss/Flopper/Tick/Part2.lean @@ -560,7 +560,7 @@ theorem flopperTickX_addOverflow rw [hltTrue] native_decide have rd4763 := rd4759.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd4763 + exact RD.solcPush1Dup1Revert0 rd4763 (by native_decide) (by native_decide) (by native_decide) (by simp) diff --git a/Benchmarks/Dss/Flopper/Yank/Part1.lean b/Benchmarks/Dss/Flopper/Yank/Part1.lean index 97369c45..0082378b 100644 --- a/Benchmarks/Dss/Flopper/Yank/Part1.lean +++ b/Benchmarks/Dss/Flopper/Yank/Part1.lean @@ -819,11 +819,11 @@ theorem evalExpr_yank_extCodeGuard_false {evm : EVM.State} {locals : Store} theorem flopperExtCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => exfalso @@ -845,11 +845,11 @@ theorem flopperExtCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} theorem flopperExtCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using @@ -898,7 +898,7 @@ theorem flopperYankBodyReverts_suckNoCode (evm : EVM.State) (I : ExecutionEnv) (hguy : flopperAddressReturnWord (auctionPackedSlot (yankIdWord I)) evm.accountMap evm.executionEnv ≠ ⟨0⟩) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (flopperAddressReturnWord ⟨2⟩ evm.accountMap evm.executionEnv) = ⟨0⟩) : ExecTransitionBody config contract evm (yankLocals I) yankTransition.body .reverted := by have hvat := evalExpr_yank_vat_storage evm I @@ -938,7 +938,7 @@ theorem flopperYankBodyReverts_suckCallFailure (hguy : flopperAddressReturnWord (auctionPackedSlot (yankIdWord I)) evm.accountMap evm.executionEnv ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (flopperAddressReturnWord ⟨2⟩ evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -1007,7 +1007,7 @@ theorem flopperYankBodyReturns_suckCallSuccess (hguy : flopperAddressReturnWord (auctionPackedSlot (yankIdWord I)) evm.accountMap evm.executionEnv ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (flopperAddressReturnWord ⟨2⟩ evm.accountMap evm.executionEnv) ≠ ⟨0⟩) (hcall : typedCallViaEVM config evm @@ -1710,14 +1710,14 @@ theorem flopperYankX_toSuckExtcodesizeGuard theorem flopperYankX_suckNoCode {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} {k C : ℕ} (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flopperAddressReturnWord ⟨2⟩ σ I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (flopperAddressReturnWord ⟨2⟩ σ I) = ⟨0⟩) (rd1050 : RD flopperBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1050⟩ [yankIdWord I, ⟨334⟩, sel] (twoWordHashMem (yankIdWord I) ⟨1⟩ solcFreePtrMem) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : RDrev flopperBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd1148⟩ := flopperYankX_toSuckExtcodesizeGuard rd1050 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1148⟩) (okPc := ⟨1160⟩) rd1148 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1148⟩) (okPc := ⟨1160⟩) rd1148 hnoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Flopper/Yank/Part2.lean b/Benchmarks/Dss/Flopper/Yank/Part2.lean index 0f065666..d7aa0f89 100644 --- a/Benchmarks/Dss/Flopper/Yank/Part2.lean +++ b/Benchmarks/Dss/Flopper/Yank/Part2.lean @@ -9,7 +9,7 @@ theorem flopperYankX_suckCall {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} {k C : ℕ} (hperm : I.perm = true) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flopperAddressReturnWord ⟨2⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (flopperAddressReturnWord ⟨2⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd1050 : RD flopperBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1050⟩ @@ -56,7 +56,7 @@ theorem flopperYankX_suckCall solcAddrMask_result_canonical (flopperSlotWord (auctionPackedSlot id) σ I) obtain ⟨_, _, rd1148⟩ := flopperYankX_toSuckExtcodesizeGuard rd1050 obtain ⟨gasWord, _, _, rd1163⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1148⟩) (okPc := ⟨1160⟩) rd1148 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1148⟩) (okPc := ⟨1160⟩) rd1148 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -96,7 +96,7 @@ theorem flopperYankX_suckCall theorem flopperYankX_suckCallDepthLimit {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} {k C : ℕ} (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (flopperAddressReturnWord ⟨2⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (flopperAddressReturnWord ⟨2⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (rd1050 : RD flopperBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1050⟩ @@ -118,7 +118,7 @@ theorem flopperYankX_suckCallDepthLimit intro id memHash memMap vat vow guy bid obtain ⟨_, _, rd1148⟩ := flopperYankX_toSuckExtcodesizeGuard rd1050 obtain ⟨gasWord, _, _, rd1163⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1148⟩) (okPc := ⟨1160⟩) rd1148 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1148⟩) (okPc := ⟨1160⟩) rd1148 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -149,7 +149,7 @@ theorem flopperYankX_suckCallFailure mem aw out (cA', σ') k C) (houtSize : out.size < UInt256.size) : RDrev flopperBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1164⟩) (okPc := ⟨1180⟩) rd1164 + exact RD.solcCallSuccessGuardMissing (pc := ⟨1164⟩) (okPc := ⟨1180⟩) rd1164 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -266,7 +266,7 @@ theorem flopperYankBodyCoreSuckNoCode (hlive : flopperSlotWord ⟨8⟩ σ_evm I = ⟨0⟩) (hguy : flopperAddressReturnWord (auctionPackedSlot (yankIdWord I)) σ_evm I ≠ ⟨0⟩) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) = ⟨0⟩) (hdispatch : dispatchMsg contract I.calldata = some yankTransition) (hdecode : @@ -291,7 +291,7 @@ theorem flopperYankBodyCoreSuckNoCode (auctionPackedSlot (yankIdWord I)) rw [hword, hzero]) have hnoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) = ⟨0⟩ := flopperCodeSize_zero_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hnoCode have hbody : @@ -319,7 +319,7 @@ theorem flopperYankBodyCoreSuckCallFailure (hlive : flopperSlotWord ⟨8⟩ σ_evm I = ⟨0⟩) (hguy : flopperAddressReturnWord (auctionPackedSlot (yankIdWord I)) σ_evm I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (rd1164 : RD flopperBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1164⟩ @@ -398,7 +398,7 @@ theorem flopperYankBodyCoreSuckCallFailure intro hzero exact hguy (by rw [hguyEq, hzero]) have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hbody : @@ -423,7 +423,7 @@ theorem flopperYankBodyCoreSuckCallDepthLimit (hlive : flopperSlotWord ⟨8⟩ σ_evm I = ⟨0⟩) (hguy : flopperAddressReturnWord (auctionPackedSlot (yankIdWord I)) σ_evm I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hdispatch : dispatchMsg contract I.calldata = some yankTransition) @@ -486,7 +486,7 @@ theorem flopperYankBodyCoreSuckCallDepthLimit (auctionPackedSlot (yankIdWord I)) rw [hword, hzero]) have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hbody : @@ -518,7 +518,7 @@ theorem flopperYankBodyCoreSuckCallSuccess (hlive : flopperSlotWord ⟨8⟩ σ_evm I = ⟨0⟩) (hguy : flopperAddressReturnWord (auctionPackedSlot (yankIdWord I)) σ_evm I ≠ ⟨0⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) ≠ ⟨0⟩) (rd1164 : RD flopperBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1164⟩ @@ -596,7 +596,7 @@ theorem flopperYankBodyCoreSuckCallSuccess intro hzero exact hguy (by rw [hguyEq, hzero]) have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (flopperAddressReturnWord ⟨2⟩ σ_solm I) ≠ ⟨0⟩ := flopperCodeSize_ne_accountMapEquiv_addressSlot hAccounts ⟨2⟩ hcodeSize have hbody : @@ -681,7 +681,7 @@ theorem flopperYankBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} · exact flopperYankBodyCoreGuyNotSet hcode hsize hwv hsz36 hlive hguy hdispatch hdecode hreach hAccounts · by_cases hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (flopperAddressReturnWord ⟨2⟩ σ_evm I) = ⟨0⟩ · exact flopperYankBodyCoreSuckNoCode hcode hsize hwv hsz36 hlive hguy hcodeSize hdispatch hdecode hreach hAccounts diff --git a/Benchmarks/Dss/GemJoin/Constructor.lean b/Benchmarks/Dss/GemJoin/Constructor.lean index dae9496e..b0f0dcce 100644 --- a/Benchmarks/Dss/GemJoin/Constructor.lean +++ b/Benchmarks/Dss/GemJoin/Constructor.lean @@ -14,11 +14,11 @@ set_option maxRecDepth 2000000 private theorem ctorExtCodeSize_ne_zero_lookup_code_pos {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => exfalso @@ -40,11 +40,11 @@ private theorem ctorExtCodeSize_ne_zero_lookup_code_pos {σ : AccountMap} {targe private theorem ctorExtCodeSize_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using @@ -257,12 +257,12 @@ theorem gemJoinConstructorCorrect : have htargetAddr : gem = AccountAddress.ofUInt256 gemTarget := by simpa [gemTarget, gemStored, gemJoinCtorGemTargetOfStored] using (gemJoinCtorGemTargetAddress_eq σIlk I gem).symm - by_cases hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σGem gemTarget = ⟨0⟩ + by_cases hcodeSize : Reasoning.Theory.extCodeSizeWord σGem gemTarget = ⟨0⟩ · have hrev := gemJoinCtorDecimalsNoCodeReverts vat ilk gem gemTarget hcodeSize rd184 rcases hrev.xiResult hcodeCtor with hOOG | ⟨g', out, hRev⟩ · exact constructorEquivalenceFor.outOfGas (by simpa [Sat256.ofUInt256] using hOOG) - · have hcodeSizeSolm : uniswapExtCodeSizeWord evm5s.accountMap gemTarget = ⟨0⟩ := by - have hEq := uniswapExtCodeSizeWord_accountMapEquiv hAccounts5 gemTarget + · have hcodeSizeSolm : extCodeSizeWord evm5s.accountMap gemTarget = ⟨0⟩ := by + have hEq := extCodeSizeWord_accountMapEquiv hAccounts5 gemTarget exact hEq ▸ hcodeSize have hgemNoCode : (UInt256.ofNat ((evm5s.lookupAccount gem).option 0 (fun acc => acc.code.size))).toNat = @@ -280,9 +280,9 @@ theorem gemJoinConstructorCorrect : evm2s, evm3s, evm4s, evm5s] using hgemNoCode)) ?_ exact ctorResultEquiv.revert rfl rfl - · have hcodeSizeSolmNe : uniswapExtCodeSizeWord evm5s.accountMap gemTarget ≠ ⟨0⟩ := by + · have hcodeSizeSolmNe : extCodeSizeWord evm5s.accountMap gemTarget ≠ ⟨0⟩ := by intro hzero - have hEq := uniswapExtCodeSizeWord_accountMapEquiv hAccounts5 gemTarget + have hEq := extCodeSizeWord_accountMapEquiv hAccounts5 gemTarget exact hcodeSize (hEq.trans hzero) have hgemCode : 0 < (UInt256.ofNat ((evm5s.lookupAccount gem).option 0 diff --git a/Benchmarks/Dss/GemJoin/ConstructorTraceCall.lean b/Benchmarks/Dss/GemJoin/ConstructorTraceCall.lean index c99b408a..b4cf7684 100644 --- a/Benchmarks/Dss/GemJoin/ConstructorTraceCall.lean +++ b/Benchmarks/Dss/GemJoin/ConstructorTraceCall.lean @@ -89,7 +89,7 @@ theorem gemJoinCtorDecimalsStaticcallReach (vat : AccountAddress) (ilk : UInt256) (gem : AccountAddress) {k C : ℕ} (gemTarget : UInt256) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σAcc gemTarget ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σAcc gemTarget ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd184 : RD (gemJoinCtorCode vat ilk gem) I g0 @@ -125,14 +125,14 @@ theorem gemJoinCtorDecimalsStaticcallReach out (createdAccounts', σ') k' C' ∧ out.size < UInt256.size := by obtain ⟨gasWord, kGas, CGas, rd199⟩ := - RD.uniswapExtcodesizeGuardOkGas + RD.solcExtcodesizeGuardOkGas (pc := ⟨184⟩) (okPc := ⟨196⟩) rd184 hcodeSize (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_jd) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by evm_ov) obtain ⟨createdAccounts', σ', z, out, Ain, callGas, k', C', hTheta, rd200, houtSize⟩ := - RD.uniswapStaticcall rd199 (by gem_ctor_decode) hdepth (by evm_ov) + RD.solcStaticcall rd199 (by gem_ctor_decode) hdepth (by evm_ov) exact ⟨createdAccounts', σ', z, out, Ain, callGas, k', C', hTheta, by simpa [show (⟨199⟩ : UInt256) + ⟨1⟩ = ⟨200⟩ from by native_decide] using rd200, houtSize⟩ @@ -144,7 +144,7 @@ theorem gemJoinCtorDecimalsStaticcallDepthLimitReach (vat : AccountAddress) (ilk : UInt256) (gem : AccountAddress) {k C : ℕ} (gemTarget : UInt256) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σAcc gemTarget ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σAcc gemTarget ≠ ⟨0⟩) (hdepth : I.depth = 1024) (rd184 : RD (gemJoinCtorCode vat ilk gem) I g0 @@ -167,14 +167,14 @@ theorem gemJoinCtorDecimalsStaticcallDepthLimitReach (⟨224⟩ : UInt256).toNat (⟨32⟩ : UInt256).toNat)) ByteArray.empty (createdAccounts, σAcc) k' C' := by obtain ⟨gasWord, kGas, CGas, rd199⟩ := - RD.uniswapExtcodesizeGuardOkGas + RD.solcExtcodesizeGuardOkGas (pc := ⟨184⟩) (okPc := ⟨196⟩) rd184 hcodeSize (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_jd) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by evm_ov) obtain ⟨k', C', rd200⟩ := - RD.uniswapStaticcallDepthLimit rd199 (by gem_ctor_decode) hdepth (by evm_ov) + RD.solcStaticcallDepthLimit rd199 (by gem_ctor_decode) hdepth (by evm_ov) exact ⟨k', C', by simpa [show (⟨199⟩ : UInt256) + ⟨1⟩ = ⟨200⟩ from by native_decide] using rd200⟩ @@ -186,7 +186,7 @@ theorem gemJoinCtorDecimalsNoCodeReverts (vat : AccountAddress) (ilk : UInt256) (gem : AccountAddress) {k C : ℕ} (gemTarget : UInt256) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σAcc gemTarget = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σAcc gemTarget = ⟨0⟩) (rd184 : RD (gemJoinCtorCode vat ilk gem) I g0 (initState createdAccounts genesisBlockHeader blocks σ σ₀ g0 A I) ⟨184⟩ @@ -197,7 +197,7 @@ theorem gemJoinCtorDecimalsNoCodeReverts (createdAccounts, σAcc) k C) : RDrev (gemJoinCtorCode vat ilk gem) g0 (initState createdAccounts genesisBlockHeader blocks σ σ₀ g0 A I) := by - exact RD.uniswapExtcodesizeGuardMissing + exact RD.solcExtcodesizeGuardMissing (pc := ⟨184⟩) (okPc := ⟨196⟩) rd184 hcodeSize (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) @@ -291,7 +291,7 @@ theorem gemJoinCtorDecimalsStatusOkReach [⟨228⟩, ⟨826074471⟩, gemTarget, EVM.word gem.val, ilk, EVM.word vat.val] mem aw out acc k' C' := by subst z - exact RD.uniswapCallSuccessGuardOk + exact RD.solcCallSuccessGuardOk (pc := ⟨200⟩) (okPc := ⟨216⟩) rd200 (by decide) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) @@ -312,7 +312,7 @@ theorem gemJoinCtorDecimalsStatusFailReverts mem aw out acc k C) : RDrev (gemJoinCtorCode vat ilk gem) g0 s0 := by subst z - exact RD.uniswapCallSuccessGuardMissing + exact RD.solcCallSuccessGuardMissing (pc := ⟨200⟩) (okPc := ⟨216⟩) rd200 rfl (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) @@ -459,7 +459,7 @@ theorem gemJoinCtorDecimalsReturnDecodeShortReverts decide have rdFallthrough := RD.jumpiNT rdPushOk (by gem_ctor_decode) hcond (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by gem_ctor_decode) (by gem_ctor_decode) (by gem_ctor_decode) (by simp only [List.length_cons, List.length_nil]; omega) diff --git a/Benchmarks/Dss/GemJoin/Dispatch.lean b/Benchmarks/Dss/GemJoin/Dispatch.lean index 2221ffb1..429aa76e 100644 --- a/Benchmarks/Dss/GemJoin/Dispatch.lean +++ b/Benchmarks/Dss/GemJoin/Dispatch.lean @@ -413,7 +413,7 @@ theorem gemJoinJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : UI (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h169 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h169 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem gemJoinLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -435,7 +435,7 @@ theorem gemJoinLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} |>.selectorArmNotTakenAuto (gemJoinLowArmsWellFormed 4 (by omega)) (heq0 4 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h169 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h169 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem gemJoinHighNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -469,7 +469,7 @@ theorem gemJoinX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem gemJoinX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -492,7 +492,7 @@ theorem gemJoinX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h169 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h169 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem gemJoinX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} diff --git a/Benchmarks/Dss/GemJoin/Exit.lean b/Benchmarks/Dss/GemJoin/Exit.lean index 5200002e..27848ee5 100644 --- a/Benchmarks/Dss/GemJoin/Exit.lean +++ b/Benchmarks/Dss/GemJoin/Exit.lean @@ -643,7 +643,7 @@ theorem RD.gemJoinExitToSlipCallReady solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hwadOk : (joinWadWord I).toNat ≤ intLimit) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (gemJoinAddressReturnWord ⟨1⟩ σ I) ≠ ⟨0⟩) : ∃ gasWord k C, RD gemJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1716⟩ @@ -656,7 +656,7 @@ theorem RD.gemJoinExitToSlipCallReady obtain ⟨_, _, rd1620⟩ := hreach obtain ⟨_, _, rd1701⟩ := RD.gemJoinExitToSlipExtcodesizeGuard hwadOk rd1620 obtain ⟨gasWord, k, C, rd1716⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1701⟩) (okPc := ⟨1713⟩) rd1701 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1701⟩) (okPc := ⟨1713⟩) rd1701 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -671,13 +671,13 @@ theorem RD.gemJoinExitSlipNoCode solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hwadOk : (joinWadWord I).toNat ≤ intLimit) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (gemJoinAddressReturnWord ⟨1⟩ σ I) = ⟨0⟩) : RDrev gemJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd1620⟩ := hreach obtain ⟨_, _, rd1701⟩ := RD.gemJoinExitToSlipExtcodesizeGuard hwadOk rd1620 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1701⟩) (okPc := ⟨1713⟩) rd1701 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1701⟩) (okPc := ⟨1713⟩) rd1701 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -691,7 +691,7 @@ theorem RD.gemJoinExitSlipPostCall solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hwadOk : (joinWadWord I).toNat ≤ intLimit) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (gemJoinAddressReturnWord ⟨1⟩ σ I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) : @@ -774,7 +774,7 @@ theorem RD.gemJoinExitSlipCallFailure (houtSize : out.size < UInt256.size) : RDrev gemJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1717⟩) (okPc := ⟨1733⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨1717⟩) (okPc := ⟨1733⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -789,7 +789,7 @@ theorem RD.gemJoinExitSlipCallDepthLimit solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hwadOk : (joinWadWord I).toNat ≤ intLimit) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (gemJoinAddressReturnWord ⟨1⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : ∃ k C, RD gemJoinBytecode I (Sat256.ofUInt256 g) @@ -841,7 +841,7 @@ theorem RD.gemJoinExitSlipCallSuccessToTransferSetup joinWadWord I :: joinUsrMaskedWord I :: ⟨254⟩ :: sel :: []) mem aw out acc k' C' := by obtain ⟨_, _, rd1735⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨1717⟩) (okPc := ⟨1733⟩) rd + RD.solcCallSuccessGuardOk (pc := ⟨1717⟩) (okPc := ⟨1733⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1218,7 +1218,7 @@ theorem RD.gemJoinExitToTransferCallReady (exitSlipCalldataMem I σ solcFreePtrMem) (UInt256.ofNat 8) outSlip (cAcur, σcur) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σcur + Reasoning.Theory.extCodeSizeWord σcur (gemJoinAddressReturnWord ⟨3⟩ σcur I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD gemJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1826⟩ @@ -1231,7 +1231,7 @@ theorem RD.gemJoinExitToTransferCallReady (UInt256.ofNat 8) outSlip (cAcur, σcur) k' C' := by obtain ⟨_, _, rd1811⟩ := RD.gemJoinExitToTransferExtcodesizeGuard rd obtain ⟨gasWord, k, C, rd1826⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1811⟩) (okPc := ⟨1823⟩) rd1811 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1811⟩) (okPc := ⟨1823⟩) rd1811 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1249,12 +1249,12 @@ theorem RD.gemJoinExitTransferNoCode (exitSlipCalldataMem I σ solcFreePtrMem) (UInt256.ofNat 8) outSlip (cAcur, σcur) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σcur + Reasoning.Theory.extCodeSizeWord σcur (gemJoinAddressReturnWord ⟨3⟩ σcur I) = ⟨0⟩) : RDrev gemJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd1811⟩ := RD.gemJoinExitToTransferExtcodesizeGuard rd - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1811⟩) (okPc := ⟨1823⟩) rd1811 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1811⟩) (okPc := ⟨1823⟩) rd1811 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1272,7 +1272,7 @@ theorem RD.gemJoinExitTransferPostCall (exitSlipCalldataMem I σ solcFreePtrMem) (UInt256.ofNat 8) outSlip (cAcur, σcur) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σcur + Reasoning.Theory.extCodeSizeWord σcur (gemJoinAddressReturnWord ⟨3⟩ σcur I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) : @@ -1354,7 +1354,7 @@ theorem RD.gemJoinExitTransferCallFailure (houtSize : outTransfer.size < UInt256.size) : RDrev gemJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1827⟩) (okPc := ⟨1843⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨1827⟩) (okPc := ⟨1843⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1372,7 +1372,7 @@ theorem RD.gemJoinExitTransferCallDepthLimit (exitSlipCalldataMem I σ solcFreePtrMem) (UInt256.ofNat 8) outSlip (cAcur, σcur) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σcur + Reasoning.Theory.extCodeSizeWord σcur (gemJoinAddressReturnWord ⟨3⟩ σcur I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : ∃ k' C', RD gemJoinBytecode I (Sat256.ofUInt256 g) @@ -1424,7 +1424,7 @@ theorem RD.gemJoinExitTransferCallSuccessToDecode (exitTransferEndPtr :: exitTransferSelectorWord :: gemTarget :: joinWadWord I :: joinUsrMaskedWord I :: ⟨254⟩ :: sel :: []) mem aw outTransfer acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨1827⟩) (okPc := ⟨1843⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨1827⟩) (okPc := ⟨1843⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -2322,7 +2322,7 @@ theorem gemJoinExitBodyCoreVatNoCode (hsz68 : 68 ≤ I.calldata.size) (hwadOk : (joinWadWord I).toNat ≤ intLimit) (hvatNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩) (hdispatch : dispatchMsg contract I.calldata = some exitTransition) (hdecode : @@ -2347,13 +2347,13 @@ theorem gemJoinExitBodyCoreVatNoCode accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨1⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hword] have hnoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hsolmAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by rw [← hsame] exact hvatNoCode @@ -2370,7 +2370,7 @@ theorem gemJoinExitBodyCoreVatNoCode ((evmSolm.lookupAccount (joinVatAddressOf evmSolm)).option 0 (fun acc => acc.code.size))).toNat = 0 := by rw [hvatAddr] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hnoCodeSolm + unfold Reasoning.Theory.extCodeSizeWord at hnoCodeSolm cases hacc : σ_solm.find? (AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) with | none => @@ -2393,7 +2393,7 @@ theorem gemJoinExitBodyCoreSlipCallDepthLimit (hsz68 : 68 ≤ I.calldata.size) (hwadOk : (joinWadWord I).toNat ≤ intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hdispatch : dispatchMsg contract I.calldata = some exitTransition) @@ -2421,15 +2421,15 @@ theorem gemJoinExitBodyCoreSlipCallDepthLimit accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨1⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hword] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -2447,7 +2447,7 @@ theorem gemJoinExitBodyCoreSlipCallDepthLimit (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -2490,7 +2490,7 @@ theorem gemJoinExitBodyCoreSlipCallFailure (hsz68 : 68 ≤ I.calldata.size) (hwadOk : (joinWadWord I).toNat ≤ intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hdispatch : dispatchMsg contract I.calldata = some exitTransition) (hdecode : @@ -2542,15 +2542,15 @@ theorem gemJoinExitBodyCoreSlipCallFailure accountAddress_ofUInt256_eq_ofNat_toNat, AccountAddress.ofNat] rw [hvatAddrEvm, hvatAddrSolm', hVatSlot] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -2568,7 +2568,7 @@ theorem gemJoinExitBodyCoreSlipCallFailure (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -2631,10 +2631,10 @@ theorem gemJoinExitBodyCoreGemNoCode (hsz68 : 68 ≤ I.calldata.size) (hwadOk : (joinWadWord I).toNat ≤ intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hgemNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = ⟨0⟩) (hdispatch : dispatchMsg contract I.calldata = some exitTransition) (hdecode : @@ -2688,15 +2688,15 @@ theorem gemJoinExitBodyCoreGemNoCode accountAddress_ofUInt256_eq_ofNat_toNat, AccountAddress.ofNat] rw [hvatAddrEvm, hvatAddrSolm', hVatSlot] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -2714,7 +2714,7 @@ theorem gemJoinExitBodyCoreGemNoCode (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -2765,13 +2765,13 @@ theorem gemJoinExitBodyCoreGemNoCode accountMapEquiv_storage_findD hStateSlip.accountMap I.codeOwner ⟨3⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hword] have hgemNoCodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hStateSlip.accountMap + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hStateSlip.accountMap (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = ⟨0⟩ := by rw [← hsame] exact hgemNoCode @@ -2789,7 +2789,7 @@ theorem gemJoinExitBodyCoreGemNoCode ((evmSolmSlip.lookupAccount (joinGemAddressOf evmSolmSlip)).option 0 (fun acc => acc.code.size))).toNat = 0 := by rw [hgemAddrSolm] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hgemNoCodeSolmWord + unfold Reasoning.Theory.extCodeSizeWord at hgemNoCodeSolmWord cases hacc : σ_slip_solm.find? (AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I)) with @@ -2816,10 +2816,10 @@ theorem gemJoinExitBodyCoreTransferCallFailure (hsz68 : 68 ≤ I.calldata.size) (hwadOk : (joinWadWord I).toNat ≤ intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hgemCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hdispatch : dispatchMsg contract I.calldata = some exitTransition) @@ -2895,15 +2895,15 @@ theorem gemJoinExitBodyCoreTransferCallFailure accountAddress_ofUInt256_eq_ofNat_toNat, AccountAddress.ofNat] rw [hvatAddrEvm, hvatAddrSolm', hVatSlot] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -2921,7 +2921,7 @@ theorem gemJoinExitBodyCoreTransferCallFailure (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -2972,15 +2972,15 @@ theorem gemJoinExitBodyCoreTransferCallFailure accountMapEquiv_storage_findD hStateSlip.accountMap I.codeOwner ⟨3⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hword] have hgemCodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) ≠ ⟨0⟩ := by intro hzero apply hgemCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hStateSlip.accountMap + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hStateSlip.accountMap (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = ⟨0⟩ := by simpa [hGemSlot] using hzero rw [hsame] @@ -2999,7 +2999,7 @@ theorem gemJoinExitBodyCoreTransferCallFailure (fun acc => acc.code.size))).toNat := by rw [hgemAddrSolm] simpa [evmSolmSlip, evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_slip_solm) (target := gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I)) rfl hgemCodeSolmWord @@ -3066,10 +3066,10 @@ theorem gemJoinExitBodyCoreTransferDecodeShort (hsz68 : 68 ≤ I.calldata.size) (hwadOk : (joinWadWord I).toNat ≤ intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hgemCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hshort : outTransfer.size < 32) @@ -3193,15 +3193,15 @@ theorem gemJoinExitBodyCoreTransferDecodeShort accountAddress_ofUInt256_eq_ofNat_toNat, AccountAddress.ofNat] rw [hvatAddrEvm, hvatAddrSolm', hVatSlot] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -3219,7 +3219,7 @@ theorem gemJoinExitBodyCoreTransferDecodeShort (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -3270,15 +3270,15 @@ theorem gemJoinExitBodyCoreTransferDecodeShort accountMapEquiv_storage_findD hStateSlip.accountMap I.codeOwner ⟨3⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hword] have hgemCodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) ≠ ⟨0⟩ := by intro hzero apply hgemCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hStateSlip.accountMap + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hStateSlip.accountMap (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = ⟨0⟩ := by simpa [hGemSlot] using hzero rw [hsame] @@ -3297,7 +3297,7 @@ theorem gemJoinExitBodyCoreTransferDecodeShort (fun acc => acc.code.size))).toNat := by rw [hgemAddrSolm] simpa [evmSolmSlip, evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_slip_solm) (target := gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I)) rfl hgemCodeSolmWord @@ -3367,10 +3367,10 @@ theorem gemJoinExitBodyCoreTransferReturnTrueSmall (hsz68 : 68 ≤ I.calldata.size) (hwadOk : (joinWadWord I).toNat ≤ intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hgemCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hret : retWord ≠ ⟨0⟩) @@ -3444,15 +3444,15 @@ theorem gemJoinExitBodyCoreTransferReturnTrueSmall accountAddress_ofUInt256_eq_ofNat_toNat, AccountAddress.ofNat] rw [hvatAddrEvm, hvatAddrSolm', hVatSlot] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -3470,7 +3470,7 @@ theorem gemJoinExitBodyCoreTransferReturnTrueSmall (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -3519,15 +3519,15 @@ theorem gemJoinExitBodyCoreTransferReturnTrueSmall accountMapEquiv_storage_findD hStateSlip.accountMap I.codeOwner ⟨3⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hwordSlot] have hgemCodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) ≠ ⟨0⟩ := by intro hzero apply hgemCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hStateSlip.accountMap + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hStateSlip.accountMap (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = ⟨0⟩ := by simpa [hGemSlot] using hzero rw [hsame] @@ -3546,7 +3546,7 @@ theorem gemJoinExitBodyCoreTransferReturnTrueSmall (fun acc => acc.code.size))).toNat := by rw [hgemAddrSolm] simpa [evmSolmSlip, evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_slip_solm) (target := gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I)) rfl hgemCodeSolmWord @@ -3629,10 +3629,10 @@ theorem gemJoinExitBodyCoreTransferReturnFalseSmall (hsz68 : 68 ≤ I.calldata.size) (hwadOk : (joinWadWord I).toNat ≤ intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hgemCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hret : retWord = ⟨0⟩) @@ -3706,15 +3706,15 @@ theorem gemJoinExitBodyCoreTransferReturnFalseSmall accountAddress_ofUInt256_eq_ofNat_toNat, AccountAddress.ofNat] rw [hvatAddrEvm, hvatAddrSolm', hVatSlot] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -3732,7 +3732,7 @@ theorem gemJoinExitBodyCoreTransferReturnFalseSmall (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -3781,15 +3781,15 @@ theorem gemJoinExitBodyCoreTransferReturnFalseSmall accountMapEquiv_storage_findD hStateSlip.accountMap I.codeOwner ⟨3⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hwordSlot] have hgemCodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) ≠ ⟨0⟩ := by intro hzero apply hgemCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hStateSlip.accountMap + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hStateSlip.accountMap (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = ⟨0⟩ := by simpa [hGemSlot] using hzero rw [hsame] @@ -3808,7 +3808,7 @@ theorem gemJoinExitBodyCoreTransferReturnFalseSmall (fun acc => acc.code.size))).toNat := by rw [hgemAddrSolm] simpa [evmSolmSlip, evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_slip_solm) (target := gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I)) rfl hgemCodeSolmWord @@ -3891,12 +3891,12 @@ theorem gemJoinExitBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (gemJoinDecode_exit_ok hsz68) hreach · have hwadOk : (joinWadWord I).toNat ≤ intLimit := by omega by_cases hvatNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ · exact gemJoinExitBodyCoreVatNoCode hcode hsize hwv hsz68 hwadOk hvatNoCode hdispatch (gemJoinDecode_exit_ok hsz68) hreach hAccounts · have hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩ := hvatNoCode by_cases hdepthLt : I.depth.val < 1024 · obtain ⟨_, _, rd1544⟩ := @@ -3912,13 +3912,13 @@ theorem gemJoinExitBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simpa using hcallSlipEvmRaw) houtSlipSize hAccounts · obtain ⟨_, _, rd1736⟩ := RD.gemJoinExitSlipCallSuccessToTransferSetup rd1717 by_cases hgemNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = (⟨0⟩ : UInt256) · exact gemJoinExitBodyCoreGemNoCode hcode hsize hwv hsz68 hwadOk hvatCode hgemNoCode hdispatch (gemJoinDecode_exit_ok hsz68) rd1736 (by simpa using hcallSlipEvmRaw) hAccounts · have hgemCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) ≠ (⟨0⟩ : UInt256) := hgemNoCode obtain ⟨cA_transfer, σ_transfer, zTransfer, outTransfer, A_transfer, diff --git a/Benchmarks/Dss/GemJoin/Join.lean b/Benchmarks/Dss/GemJoin/Join.lean index a09bdcdf..7dedbbfe 100644 --- a/Benchmarks/Dss/GemJoin/Join.lean +++ b/Benchmarks/Dss/GemJoin/Join.lean @@ -1701,7 +1701,7 @@ theorem RD.gemJoinToSlipCallReady [joinWadWord I, joinUsrMaskedWord I, ⟨254⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (gemJoinAddressReturnWord ⟨1⟩ σ I) ≠ ⟨0⟩) : ∃ gasWord k C, RD gemJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨732⟩ @@ -1714,7 +1714,7 @@ theorem RD.gemJoinToSlipCallReady obtain ⟨_, _, rd634⟩ := hreach obtain ⟨_, _, rd717⟩ := RD.gemJoinToSlipExtcodesizeGuard rd634 obtain ⟨gasWord, k, C, rd732⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨717⟩) (okPc := ⟨729⟩) rd717 + RD.solcExtcodesizeGuardOkGas (pc := ⟨717⟩) (okPc := ⟨729⟩) rd717 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1728,13 +1728,13 @@ theorem RD.gemJoinSlipNoCode [joinWadWord I, joinUsrMaskedWord I, ⟨254⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (gemJoinAddressReturnWord ⟨1⟩ σ I) = ⟨0⟩) : RDrev gemJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd634⟩ := hreach obtain ⟨_, _, rd717⟩ := RD.gemJoinToSlipExtcodesizeGuard rd634 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨717⟩) (okPc := ⟨729⟩) rd717 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨717⟩) (okPc := ⟨729⟩) rd717 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1747,7 +1747,7 @@ theorem RD.gemJoinSlipPostCall [joinWadWord I, joinUsrMaskedWord I, ⟨254⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (gemJoinAddressReturnWord ⟨1⟩ σ I) ≠ ⟨0⟩) (hwadLow : (joinWadWord I).toNat < intLimit) (hperm : I.perm = true) @@ -1830,7 +1830,7 @@ theorem RD.gemJoinSlipCallFailure (houtSize : out.size < UInt256.size) : RDrev gemJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨733⟩) (okPc := ⟨749⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨733⟩) (okPc := ⟨749⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1844,7 +1844,7 @@ theorem RD.gemJoinSlipCallDepthLimit [joinWadWord I, joinUsrMaskedWord I, ⟨254⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (gemJoinAddressReturnWord ⟨1⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : ∃ k C, RD gemJoinBytecode I (Sat256.ofUInt256 g) @@ -1896,7 +1896,7 @@ theorem RD.gemJoinSlipCallSuccessToTransferSetup joinWadWord I :: joinUsrMaskedWord I :: ⟨254⟩ :: sel :: []) mem aw out acc k' C' := by obtain ⟨_, _, rd751⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨733⟩) (okPc := ⟨749⟩) rd + RD.solcCallSuccessGuardOk (pc := ⟨733⟩) (okPc := ⟨749⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -2022,7 +2022,7 @@ theorem RD.gemJoinToTransferFromExtcodesizeGuard add, raw mstore 0 (joinTransferFromSrcMem I (joinSlipCalldataMem I σ solcFreePtrMem)) (UInt256.ofNat 8) (by native_decide) mem_cost hSrcMemEq (by decide) (by evm_ov), - uniswapAddress, + address, push1 ⟨36⟩, dup3, add, @@ -2110,7 +2110,7 @@ theorem RD.gemJoinToTransferFromCallReady (joinSlipCalldataMem I σ solcFreePtrMem) (UInt256.ofNat 8) outSlip (cAcur, σcur) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σcur + Reasoning.Theory.extCodeSizeWord σcur (gemJoinAddressReturnWord ⟨3⟩ σcur I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD gemJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨846⟩ @@ -2123,7 +2123,7 @@ theorem RD.gemJoinToTransferFromCallReady (UInt256.ofNat 8) outSlip (cAcur, σcur) k' C' := by obtain ⟨_, _, rd831⟩ := RD.gemJoinToTransferFromExtcodesizeGuard rd obtain ⟨gasWord, k, C, rd846⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨831⟩) (okPc := ⟨843⟩) rd831 + RD.solcExtcodesizeGuardOkGas (pc := ⟨831⟩) (okPc := ⟨843⟩) rd831 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -2141,12 +2141,12 @@ theorem RD.gemJoinTransferFromNoCode (joinSlipCalldataMem I σ solcFreePtrMem) (UInt256.ofNat 8) outSlip (cAcur, σcur) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σcur + Reasoning.Theory.extCodeSizeWord σcur (gemJoinAddressReturnWord ⟨3⟩ σcur I) = ⟨0⟩) : RDrev gemJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd831⟩ := RD.gemJoinToTransferFromExtcodesizeGuard rd - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨831⟩) (okPc := ⟨843⟩) rd831 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨831⟩) (okPc := ⟨843⟩) rd831 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2164,7 +2164,7 @@ theorem RD.gemJoinTransferFromPostCall (joinSlipCalldataMem I σ solcFreePtrMem) (UInt256.ofNat 8) outSlip (cAcur, σcur) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σcur + Reasoning.Theory.extCodeSizeWord σcur (gemJoinAddressReturnWord ⟨3⟩ σcur I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) : @@ -2246,7 +2246,7 @@ theorem RD.gemJoinTransferFromCallFailure (houtSize : outTransfer.size < UInt256.size) : RDrev gemJoinBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨847⟩) (okPc := ⟨863⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨847⟩) (okPc := ⟨863⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -2264,7 +2264,7 @@ theorem RD.gemJoinTransferFromCallDepthLimit (joinSlipCalldataMem I σ solcFreePtrMem) (UInt256.ofNat 8) outSlip (cAcur, σcur) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σcur + Reasoning.Theory.extCodeSizeWord σcur (gemJoinAddressReturnWord ⟨3⟩ σcur I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : ∃ k' C', RD gemJoinBytecode I (Sat256.ofUInt256 g) @@ -2317,7 +2317,7 @@ theorem RD.gemJoinTransferFromCallSuccessToDecode gemTarget :: joinWadWord I :: joinUsrMaskedWord I :: ⟨254⟩ :: sel :: []) mem aw outTransfer acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨847⟩) (okPc := ⟨863⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨847⟩) (okPc := ⟨863⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -2920,7 +2920,7 @@ theorem gemJoinX_join_vatNoCode {cA gh bl σ σ₀ A I} {g sel : UInt256} (hlive : gemJoinSlotWord ⟨5⟩ σ I = ⟨1⟩) (hwadLow : (joinWadWord I).toNat < intLimit) (hvatNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (gemJoinAddressReturnWord ⟨1⟩ σ I) = ⟨0⟩) (hreach : ∃ k C, RD gemJoinBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨210⟩ [sel] @@ -2937,7 +2937,7 @@ theorem gemJoinX_join_slipCallDepthLimit {cA gh bl σ σ₀ A I} {g sel : UInt25 (hlive : gemJoinSlotWord ⟨5⟩ σ I = ⟨1⟩) (hwadLow : (joinWadWord I).toNat < intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (gemJoinAddressReturnWord ⟨1⟩ σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hreach : ∃ k C, RD gemJoinBytecode I (Sat256.ofUInt256 g) @@ -2998,14 +2998,14 @@ theorem gemJoinJoinBodyRevertsOverflow (evm : EVM.State) (I : ExecutionEnv) refine ExecBlock.consNormal (ExecStmt.requireTrue (evalExpr_join_live_true evm I hlive)) ?_ exact ExecBlock.consRevert (ExecStmt.requireFalse (evalExpr_join_wad_lt_false evm I hwadHigh)) -theorem gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos +theorem gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => exfalso @@ -3093,7 +3093,7 @@ theorem gemJoinJoinBodyCoreVatNoCode (hlive : gemJoinSlotWord ⟨5⟩ σ_evm I = ⟨1⟩) (hwadLow : (joinWadWord I).toNat < intLimit) (hvatNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩) (hdispatch : dispatchMsg contract I.calldata = some joinTransition) (hdecode : @@ -3118,13 +3118,13 @@ theorem gemJoinJoinBodyCoreVatNoCode accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨1⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hword] have hnoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hsolmAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by rw [← hsame] exact hvatNoCode @@ -3141,7 +3141,7 @@ theorem gemJoinJoinBodyCoreVatNoCode ((evmSolm.lookupAccount (joinVatAddressOf evmSolm)).option 0 (fun acc => acc.code.size))).toNat = 0 := by rw [hvatAddr] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hnoCodeSolm + unfold Reasoning.Theory.extCodeSizeWord at hnoCodeSolm cases hacc : σ_solm.find? (AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) with | none => @@ -3167,7 +3167,7 @@ theorem gemJoinJoinBodyCoreSlipCallDepthLimit (hlive : gemJoinSlotWord ⟨5⟩ σ_evm I = ⟨1⟩) (hwadLow : (joinWadWord I).toNat < intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hdispatch : dispatchMsg contract I.calldata = some joinTransition) @@ -3193,15 +3193,15 @@ theorem gemJoinJoinBodyCoreSlipCallDepthLimit accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨1⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hword] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -3219,7 +3219,7 @@ theorem gemJoinJoinBodyCoreSlipCallDepthLimit (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -3263,7 +3263,7 @@ theorem gemJoinJoinBodyCoreSlipCallFailure (hlive : gemJoinSlotWord ⟨5⟩ σ_evm I = ⟨1⟩) (hwadLow : (joinWadWord I).toNat < intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hdispatch : dispatchMsg contract I.calldata = some joinTransition) @@ -3322,15 +3322,15 @@ theorem gemJoinJoinBodyCoreSlipCallFailure accountAddress_ofUInt256_eq_ofNat_toNat, AccountAddress.ofNat] rw [hvatAddrEvm, hvatAddrSolm', hVatSlot] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -3348,7 +3348,7 @@ theorem gemJoinJoinBodyCoreSlipCallFailure (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -3412,10 +3412,10 @@ theorem gemJoinJoinBodyCoreGemNoCode (hlive : gemJoinSlotWord ⟨5⟩ σ_evm I = ⟨1⟩) (hwadLow : (joinWadWord I).toNat < intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hgemNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = ⟨0⟩) (hdispatch : dispatchMsg contract I.calldata = some joinTransition) (hdecode : @@ -3475,15 +3475,15 @@ theorem gemJoinJoinBodyCoreGemNoCode accountAddress_ofUInt256_eq_ofNat_toNat, AccountAddress.ofNat] rw [hvatAddrEvm, hvatAddrSolm', hVatSlot] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -3501,7 +3501,7 @@ theorem gemJoinJoinBodyCoreGemNoCode (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -3550,13 +3550,13 @@ theorem gemJoinJoinBodyCoreGemNoCode accountMapEquiv_storage_findD hStateSlip.accountMap I.codeOwner ⟨3⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hword] have hgemNoCodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hStateSlip.accountMap + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hStateSlip.accountMap (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = ⟨0⟩ := by rw [← hsame] exact hgemNoCode @@ -3574,7 +3574,7 @@ theorem gemJoinJoinBodyCoreGemNoCode ((evmSolmSlip.lookupAccount (joinGemAddressOf evmSolmSlip)).option 0 (fun acc => acc.code.size))).toNat = 0 := by rw [hgemAddrSolm] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hgemNoCodeSolmWord + unfold Reasoning.Theory.extCodeSizeWord at hgemNoCodeSolmWord cases hacc : σ_slip_solm.find? (AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I)) with @@ -3602,10 +3602,10 @@ theorem gemJoinJoinBodyCoreTransferCallFailure (hlive : gemJoinSlotWord ⟨5⟩ σ_evm I = ⟨1⟩) (hwadLow : (joinWadWord I).toNat < intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hgemCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hdispatch : dispatchMsg contract I.calldata = some joinTransition) @@ -3687,15 +3687,15 @@ theorem gemJoinJoinBodyCoreTransferCallFailure accountAddress_ofUInt256_eq_ofNat_toNat, AccountAddress.ofNat] rw [hvatAddrEvm, hvatAddrSolm', hVatSlot] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -3713,7 +3713,7 @@ theorem gemJoinJoinBodyCoreTransferCallFailure (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -3762,15 +3762,15 @@ theorem gemJoinJoinBodyCoreTransferCallFailure accountMapEquiv_storage_findD hStateSlip.accountMap I.codeOwner ⟨3⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hword] have hgemCodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) ≠ ⟨0⟩ := by intro hzero apply hgemCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hStateSlip.accountMap + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hStateSlip.accountMap (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = ⟨0⟩ := by simpa [hGemSlot] using hzero rw [hsame] @@ -3789,7 +3789,7 @@ theorem gemJoinJoinBodyCoreTransferCallFailure (fun acc => acc.code.size))).toNat := by rw [hgemAddrSolm] simpa [evmSolmSlip, evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_slip_solm) (target := gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I)) rfl hgemCodeSolmWord @@ -3859,10 +3859,10 @@ theorem gemJoinJoinBodyCoreTransferDecodeShort (hlive : gemJoinSlotWord ⟨5⟩ σ_evm I = ⟨1⟩) (hwadLow : (joinWadWord I).toNat < intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hgemCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hshort : outTransfer.size < 32) @@ -3989,15 +3989,15 @@ theorem gemJoinJoinBodyCoreTransferDecodeShort accountAddress_ofUInt256_eq_ofNat_toNat, AccountAddress.ofNat] rw [hvatAddrEvm, hvatAddrSolm', hVatSlot] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -4015,7 +4015,7 @@ theorem gemJoinJoinBodyCoreTransferDecodeShort (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -4064,15 +4064,15 @@ theorem gemJoinJoinBodyCoreTransferDecodeShort accountMapEquiv_storage_findD hStateSlip.accountMap I.codeOwner ⟨3⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hword] have hgemCodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) ≠ ⟨0⟩ := by intro hzero apply hgemCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hStateSlip.accountMap + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hStateSlip.accountMap (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = ⟨0⟩ := by simpa [hGemSlot] using hzero rw [hsame] @@ -4091,7 +4091,7 @@ theorem gemJoinJoinBodyCoreTransferDecodeShort (fun acc => acc.code.size))).toNat := by rw [hgemAddrSolm] simpa [evmSolmSlip, evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_slip_solm) (target := gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I)) rfl hgemCodeSolmWord @@ -4164,10 +4164,10 @@ theorem gemJoinJoinBodyCoreTransferReturnTrueSmall (hlive : gemJoinSlotWord ⟨5⟩ σ_evm I = ⟨1⟩) (hwadLow : (joinWadWord I).toNat < intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hgemCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hret : retWord ≠ ⟨0⟩) @@ -4247,15 +4247,15 @@ theorem gemJoinJoinBodyCoreTransferReturnTrueSmall accountAddress_ofUInt256_eq_ofNat_toNat, AccountAddress.ofNat] rw [hvatAddrEvm, hvatAddrSolm', hVatSlot] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -4273,7 +4273,7 @@ theorem gemJoinJoinBodyCoreTransferReturnTrueSmall (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -4322,15 +4322,15 @@ theorem gemJoinJoinBodyCoreTransferReturnTrueSmall accountMapEquiv_storage_findD hStateSlip.accountMap I.codeOwner ⟨3⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hwordSlot] have hgemCodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) ≠ ⟨0⟩ := by intro hzero apply hgemCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hStateSlip.accountMap + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hStateSlip.accountMap (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = ⟨0⟩ := by simpa [hGemSlot] using hzero rw [hsame] @@ -4349,7 +4349,7 @@ theorem gemJoinJoinBodyCoreTransferReturnTrueSmall (fun acc => acc.code.size))).toNat := by rw [hgemAddrSolm] simpa [evmSolmSlip, evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_slip_solm) (target := gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I)) rfl hgemCodeSolmWord @@ -4434,10 +4434,10 @@ theorem gemJoinJoinBodyCoreTransferReturnFalseSmall (hlive : gemJoinSlotWord ⟨5⟩ σ_evm I = ⟨1⟩) (hwadLow : (joinWadWord I).toNat < intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hgemCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hret : retWord = ⟨0⟩) @@ -4517,15 +4517,15 @@ theorem gemJoinJoinBodyCoreTransferReturnFalseSmall accountAddress_ofUInt256_eq_ofNat_toNat, AccountAddress.ofNat] rw [hvatAddrEvm, hvatAddrSolm', hVatSlot] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -4543,7 +4543,7 @@ theorem gemJoinJoinBodyCoreTransferReturnFalseSmall (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -4592,15 +4592,15 @@ theorem gemJoinJoinBodyCoreTransferReturnFalseSmall accountMapEquiv_storage_findD hStateSlip.accountMap I.codeOwner ⟨3⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hwordSlot] have hgemCodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) ≠ ⟨0⟩ := by intro hzero apply hgemCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hStateSlip.accountMap + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hStateSlip.accountMap (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = ⟨0⟩ := by simpa [hGemSlot] using hzero rw [hsame] @@ -4619,7 +4619,7 @@ theorem gemJoinJoinBodyCoreTransferReturnFalseSmall (fun acc => acc.code.size))).toNat := by rw [hgemAddrSolm] simpa [evmSolmSlip, evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_slip_solm) (target := gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I)) rfl hgemCodeSolmWord @@ -4693,10 +4693,10 @@ theorem gemJoinJoinBodyCoreTransferReturnFalseHuge (hlive : gemJoinSlotWord ⟨5⟩ σ_evm I = ⟨1⟩) (hwadLow : (joinWadWord I).toNat < intLimit) (hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩) (hgemCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hret : retWord = ⟨0⟩) @@ -4776,15 +4776,15 @@ theorem gemJoinJoinBodyCoreTransferReturnFalseHuge accountAddress_ofUInt256_eq_ofNat_toNat, AccountAddress.ofNat] rw [hvatAddrEvm, hvatAddrSolm', hVatSlot] have hcodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hvatCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ := by simpa [hVatSlot] using hzero rw [hsame] @@ -4802,7 +4802,7 @@ theorem gemJoinJoinBodyCoreTransferReturnFalseHuge (fun acc => acc.code.size))).toNat := by rw [hvatAddrSolm] simpa [evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := gemJoinAddressReturnWord ⟨1⟩ σ_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨1⟩ σ_solm I)) rfl hcodeSolmWord @@ -4851,15 +4851,15 @@ theorem gemJoinJoinBodyCoreTransferReturnFalseHuge accountMapEquiv_storage_findD hStateSlip.accountMap I.codeOwner ⟨3⟩ ⟨0⟩ simp [gemJoinAddressReturnWord, hwordSlot] have hgemCodeSolmWord : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) ≠ ⟨0⟩ := by intro hzero apply hgemCode have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hStateSlip.accountMap + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hStateSlip.accountMap (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip_solm + Reasoning.Theory.extCodeSizeWord σ_slip_solm (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = ⟨0⟩ := by simpa [hGemSlot] using hzero rw [hsame] @@ -4878,7 +4878,7 @@ theorem gemJoinJoinBodyCoreTransferReturnFalseHuge (fun acc => acc.code.size))).toNat := by rw [hgemAddrSolm] simpa [evmSolmSlip, evmSolm, initState, State.lookupAccount] using - gemJoin_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + gemJoin_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_slip_solm) (target := gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I) (addr := AccountAddress.ofUInt256 (gemJoinAddressReturnWord ⟨3⟩ σ_slip_solm I)) rfl hgemCodeSolmWord @@ -4974,12 +4974,12 @@ theorem gemJoinJoinBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (gemJoinDecode_join_ok hsz68) hreach hAccounts · have hwadLow : (joinWadWord I).toNat < intLimit := by omega by_cases hvatNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) = ⟨0⟩ · exact gemJoinJoinBodyCoreVatNoCode hcode hsize hwv hsz68 hlive hwadLow hvatNoCode hdispatch (gemJoinDecode_join_ok hsz68) hreach hAccounts · have hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (gemJoinAddressReturnWord ⟨1⟩ σ_evm I) ≠ ⟨0⟩ := hvatNoCode by_cases hdepthLt : I.depth.val < 1024 · obtain ⟨_, _, rd487⟩ := @@ -4995,13 +4995,13 @@ theorem gemJoinJoinBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rd733 (by simpa using hcallSlipEvmRaw) houtSlipSize hAccounts · obtain ⟨_, _, rd752⟩ := RD.gemJoinSlipCallSuccessToTransferSetup rd733 by_cases hgemNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) = (⟨0⟩ : UInt256) · exact gemJoinJoinBodyCoreGemNoCode hcode hsize hwv hsz68 hlive hwadLow hvatCode hgemNoCode hdispatch (gemJoinDecode_join_ok hsz68) rd752 (by simpa using hcallSlipEvmRaw) hAccounts · have hgemCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_slip + Reasoning.Theory.extCodeSizeWord σ_slip (gemJoinAddressReturnWord ⟨3⟩ σ_slip I) ≠ (⟨0⟩ : UInt256) := hgemNoCode obtain ⟨cA_transfer, σ_transfer, zTransfer, outTransfer, A_transfer, k847, C847, rd847, hcallTransferEvmRaw, houtTransferSize⟩ := diff --git a/Benchmarks/Dss/GemJoin/SpecSyntax.lean b/Benchmarks/Dss/GemJoin/SpecSyntax.lean index 0c8f8f2f..3b9e3bb7 100644 --- a/Benchmarks/Dss/GemJoin/SpecSyntax.lean +++ b/Benchmarks/Dss/GemJoin/SpecSyntax.lean @@ -2,19 +2,96 @@ import Benchmarks.Dss.GemJoin.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS GemJoin spec through the Solm notation frontend +# GemJoin spec in the Solidity-faithful Solm frontend -The main spec lives in `Spec.lean`; this companion keeps the benchmark's notation-side check wired -up as the body surface grows. +The whole GemJoin benchmark spec, written with `solidity%` and proven definitionally equal to the +AST spec in `Benchmarks/Dss/GemJoin/Spec.lean`. The `extCodeSize` guards on storage receivers +(`vat`, `gem`) use the `${…}` expression escape; the constructor's `decimals()` STATICCALL is the +`{view}` call on the local `gem_`. Transition order matches `contract.transitions`. -/ open Solm Solm.Notation namespace Benchmarks.Dss.GemJoin.Syntax -def contractSyntax : ContractDecl := Benchmarks.Dss.GemJoin.contract +def contractSyntax : ContractDecl := solidity% contract GemJoin { + mapping(address => uint256) wards; + address vat; + bytes32 ilk; + address gem; + uint256 dec; + uint256 live; -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.GemJoin.contract := by - rfl + constructor(address vat_, bytes32 ilk_, address gem_) { + wards[msg.sender] = 1; + live = 1; + vat = vat_; + ilk = ilk_; + gem = gem_; + require(gem_.code.length > 0); + var decimalsRet = gem_.decimals{view}(); + dec = decimalsRet; + } + + function cage() external { + require(wards[msg.sender] == 1); + live = 0; + } + + function dec() external returns (uint256) { + return dec; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function exit(address usr, uint256 wad) external { + require(wad <= #intLimit); + require(${Expr.extCodeSize (Expr.storage vatRef)} > 0); + var slipRet = vat.slip(ilk, msg.sender, -int256(wad)); + require(${Expr.extCodeSize (Expr.storage gemRef)} > 0); + var transferOk = gem.transfer(usr, wad); + require(transferOk); + } + + function gem() external returns (address) { + return gem; + } + + function ilk() external returns (bytes32) { + return ilk; + } + + function join(address usr, uint256 wad) external { + require(live == 1); + require(wad < #intLimit); + require(${Expr.extCodeSize (Expr.storage vatRef)} > 0); + var slipRet = vat.slip(ilk, usr, int256(wad)); + require(${Expr.extCodeSize (Expr.storage gemRef)} > 0); + var transferFromOk = gem.transferFrom(msg.sender, this, wad); + require(transferFromOk); + } + + function live() external returns (uint256) { + return live; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 1; + } + + function vat() external returns (address) { + return vat; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.GemJoin.contract := by rfl end Benchmarks.Dss.GemJoin.Syntax diff --git a/Benchmarks/Dss/Jug/Dispatch.lean b/Benchmarks/Dss/Jug/Dispatch.lean index 63c5095d..2b678bce 100644 --- a/Benchmarks/Dss/Jug/Dispatch.lean +++ b/Benchmarks/Dss/Jug/Dispatch.lean @@ -393,7 +393,7 @@ theorem jugJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : UInt25 have h180 := h.push2 jugDispatchRevertPc hpush (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h180 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h180 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem jugLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -417,7 +417,7 @@ theorem jugLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} |>.selectorArmNotTakenAuto (jugLowArmsWellFormed 5 (by omega)) (heq0 5 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h180 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h180 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem jugHighNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -451,7 +451,7 @@ theorem jugX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem jugX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -474,7 +474,7 @@ theorem jugX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h180 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h180 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem jugX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} diff --git a/Benchmarks/Dss/Jug/Drip.lean b/Benchmarks/Dss/Jug/Drip.lean index 20af4de1..3425e3fe 100644 --- a/Benchmarks/Dss/Jug/Drip.lean +++ b/Benchmarks/Dss/Jug/Drip.lean @@ -32,7 +32,7 @@ theorem jugDripBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (UInt256.ofNat I.header.timestamp).toNat := by omega by_cases hvatCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (dripVatTargetWord σ_evm I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_evm (dripVatTargetWord σ_evm I) = ⟨0⟩ · exact jugDripBodyCoreVatIlksNoCode hcode hsize hwv hsz36 hle hdispatch (jugDecode_drip_ok hsz36) hreach hAccounts hvatCode · by_cases hdepth : I.depth.val < 1024 diff --git a/Benchmarks/Dss/Jug/DripBase.lean b/Benchmarks/Dss/Jug/DripBase.lean index d309bca4..cd9c7649 100644 --- a/Benchmarks/Dss/Jug/DripBase.lean +++ b/Benchmarks/Dss/Jug/DripBase.lean @@ -967,10 +967,10 @@ theorem dripVatAddress_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} theorem dripVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (dripVatTargetWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (dripVatTargetWord τ I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (dripVatTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (dripVatTargetWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (dripVatTargetWord σ I) have htarget : dripVatTargetWord σ I = dripVatTargetWord τ I := dripVatTargetWord_accountMapEquiv hAccounts @@ -980,8 +980,8 @@ theorem dripVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execution theorem dripVatCodeSize_ne_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (dripVatTargetWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (dripVatTargetWord τ I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (dripVatTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (dripVatTargetWord τ I) ≠ ⟨0⟩ := by intro hzero exact hne (dripVatCodeSize_zero_accountMapEquiv hAccounts.symm hzero) @@ -1013,14 +1013,14 @@ theorem dripVatEvmAddress_eq_target_of_accountMapEquiv {σ_evm σ_solm : Account rw [dripVatAddress_eq_evm_target_of_accountMapEquiv hAccounts] exact evmAddress_accountAddress _ -theorem drip_uniswapExtCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} +theorem drip_extCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using @@ -1031,18 +1031,18 @@ theorem drip_uniswapExtCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {tar theorem dripVatCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt256} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (dripVatTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (dripVatTargetWord σ I) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (dripVatAddress σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [initState, State.lookupAccount] using - drip_uniswapExtCodeSizeWord_zero_lookup_code_zero + drip_extCodeSizeWord_zero_lookup_code_zero (σ := σ) (target := dripVatTargetWord σ I) (addr := dripVatAddress σ I) (dripVatAddress_eq_target σ I) hzero theorem dripVatCode_pos_of_codeSize_ne_zero {cA gh bl σ σ₀ A I} {g : UInt256} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (dripVatTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (dripVatTargetWord σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount @@ -1062,9 +1062,9 @@ theorem dripVatCode_pos_of_codeSize_ne_zero {cA gh bl σ σ₀ A I} {g : UInt256 UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (dripVatAddress σ I)).option 0 (fun acc => acc.code.size)) = - Reasoning.Theory.uniswapExtCodeSizeWord σ (dripVatTargetWord σ I) := by + Reasoning.Theory.extCodeSizeWord σ (dripVatTargetWord σ I) := by cases hacc : σ.find? (AccountAddress.ofUInt256 (dripVatTargetWord σ I)) <;> - simp [initState, State.lookupAccount, Reasoning.Theory.uniswapExtCodeSizeWord, + simp [initState, State.lookupAccount, Reasoning.Theory.extCodeSizeWord, dripVatAddress_eq_target σ I, hacc, Option.option] <;> native_decide exact hne (by rw [← hword, hwordZero]) diff --git a/Benchmarks/Dss/Jug/DripBodyAddReturnsTactic.lean b/Benchmarks/Dss/Jug/DripBodyAddReturnsTactic.lean index 08e0e981..b4fd3b2d 100644 --- a/Benchmarks/Dss/Jug/DripBodyAddReturnsTactic.lean +++ b/Benchmarks/Dss/Jug/DripBodyAddReturnsTactic.lean @@ -92,7 +92,7 @@ have _foldNZeroCallReady : age = ⟨0⟩ → jugRay.toNat * (dripVatIlksPrevWord out).toNat < UInt256.size → ((dripVatIlksPrevWord out).toNat : Int) ≤ maxInt256 → - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (dripVatTargetWord σ' I) ≠ ⟨0⟩ → ∃ gasWord k' C', RD jugBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1650⟩ @@ -146,7 +146,7 @@ have _foldNZeroNoCode : age = ⟨0⟩ → jugRay.toNat * (dripVatIlksPrevWord out).toNat < UInt256.size → ((dripVatIlksPrevWord out).toNat : Int) ≤ maxInt256 → - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (dripVatTargetWord σ' I) = ⟨0⟩ → RDrev jugBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by diff --git a/Benchmarks/Dss/Jug/DripBodyAgeOneTactic.lean b/Benchmarks/Dss/Jug/DripBodyAgeOneTactic.lean index b43f52e7..d6fa1230 100644 --- a/Benchmarks/Dss/Jug/DripBodyAgeOneTactic.lean +++ b/Benchmarks/Dss/Jug/DripBodyAgeOneTactic.lean @@ -30,7 +30,7 @@ by_cases hageOne : age = ⟨1⟩ rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -202,7 +202,7 @@ by_cases hageOne : age = ⟨1⟩ rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -386,7 +386,7 @@ by_cases hageOne : age = ⟨1⟩ by_contra hbad exact hprevMaxNot hbad by_cases hfoldNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (dripVatTargetWord σ' I) = ⟨0⟩ · let locals := dripLocals I let evmE := @@ -404,7 +404,7 @@ by_cases hageOne : age = ⟨1⟩ rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -532,7 +532,7 @@ by_cases hageOne : age = ⟨1⟩ jugRay).toNat : Int) ≤ maxInt256 := by simpa [rate, fee, hbaseWord, hdutyWord] using hrateMax have hfoldCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (dripVatTargetWord σ'_solm I) = ⟨0⟩ := dripVatCodeSize_zero_accountMapEquiv hAccounts' hfoldNoCode @@ -540,7 +540,7 @@ by_cases hageOne : age = ⟨1⟩ (UInt256.ofNat ((σ'_solm.find? (dripVatAddress σ'_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := - drip_uniswapExtCodeSizeWord_zero_lookup_code_zero + drip_extCodeSizeWord_zero_lookup_code_zero (σ := σ'_solm) (target := dripVatTargetWord σ'_solm I) (addr := dripVatAddress σ'_solm I) @@ -740,7 +740,7 @@ by_cases hageOne : age = ⟨1⟩ rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -924,7 +924,7 @@ by_cases hageOne : age = ⟨1⟩ jugRay = rate simpa [rate, fee, hbaseWord, hdutyWord] have hfoldCodeSolmNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (dripVatTargetWord σ'_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts' hfoldNoCode @@ -1201,7 +1201,7 @@ by_cases hageOne : age = ⟨1⟩ rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : diff --git a/Benchmarks/Dss/Jug/DripBodyCore.lean b/Benchmarks/Dss/Jug/DripBodyCore.lean index 2efe2a7a..c8b5d763 100644 --- a/Benchmarks/Dss/Jug/DripBodyCore.lean +++ b/Benchmarks/Dss/Jug/DripBodyCore.lean @@ -83,7 +83,7 @@ theorem jugDripBodyCoreVatIlksNoCode solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ_evm) k C) (hAccounts : accountMapEquiv σ_evm σ_solm) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (dripVatTargetWord σ_evm I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ_evm (dripVatTargetWord σ_evm I) = ⟨0⟩) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by let locals := dripLocals I let evm0 := initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I @@ -96,7 +96,7 @@ theorem jugDripBodyCoreVatIlksNoCode rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) = ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) = ⟨0⟩ := dripVatCodeSize_zero_accountMapEquiv hAccounts hcodeSize have hvatNoCodeSolm : (UInt256.ofNat @@ -131,7 +131,7 @@ theorem jugDripBodyCoreVatIlksCallFailed (transitionSignature dripTransition).paramTypes I.calldata = some (dripLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (dripVatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (dripVatTargetWord σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd1400 : RD jugBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1400⟩ @@ -164,7 +164,7 @@ theorem jugDripBodyCoreVatIlksCallFailed rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hcodeSize have hvatCodeSolm : 0 < @@ -246,7 +246,7 @@ theorem jugDripBodyCoreVatIlksCallDepthLimit (transitionSignature dripTransition).paramTypes I.calldata = some (dripLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (dripVatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (dripVatTargetWord σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (rd1400 : RD jugBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1400⟩ @@ -267,7 +267,7 @@ theorem jugDripBodyCoreVatIlksCallDepthLimit rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hcodeSize have hvatCodeSolm : 0 < @@ -318,7 +318,7 @@ theorem jugDripBodyCoreVatIlksReturnDecodeShort (transitionSignature dripTransition).paramTypes I.calldata = some (dripLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (dripVatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (dripVatTargetWord σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd1400 : RD jugBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1400⟩ @@ -352,7 +352,7 @@ theorem jugDripBodyCoreVatIlksReturnDecodeShort rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hcodeSize have hvatCodeSolm : 0 < @@ -437,7 +437,7 @@ theorem jugDripBodyCoreVatIlksAddOverflow (transitionSignature dripTransition).paramTypes I.calldata = some (dripLocals I)) (hAccounts : accountMapEquiv σ_evm σ_solm) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (dripVatTargetWord σ_evm I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ_evm (dripVatTargetWord σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (rd2131 : RD jugBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨2131⟩ @@ -476,7 +476,7 @@ theorem jugDripBodyCoreVatIlksAddOverflow rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hcodeSize have hvatCodeSolm : 0 < diff --git a/Benchmarks/Dss/Jug/DripBodyFeeZeroTactic.lean b/Benchmarks/Dss/Jug/DripBodyFeeZeroTactic.lean index b1145d6f..94e8b668 100644 --- a/Benchmarks/Dss/Jug/DripBodyFeeZeroTactic.lean +++ b/Benchmarks/Dss/Jug/DripBodyFeeZeroTactic.lean @@ -27,7 +27,7 @@ by_cases hprevMaxNot : rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -188,7 +188,7 @@ by_cases hprevMaxNot : by_contra hbad exact hprevMaxNot hbad by_cases hfoldNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (dripVatTargetWord σ' I) = ⟨0⟩ · let locals := dripLocals I let evmE := @@ -205,7 +205,7 @@ by_cases hprevMaxNot : rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -304,14 +304,14 @@ by_cases hprevMaxNot : intro hbad exact hageNZ (by simpa [age, hrhoPostWord] using hbad) have hfoldCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (dripVatTargetWord σ'_solm I) = ⟨0⟩ := dripVatCodeSize_zero_accountMapEquiv hAccounts' hfoldNoCode have hfoldNoCodeSolmRaw : (UInt256.ofNat ((σ'_solm.find? (dripVatAddress σ'_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := - drip_uniswapExtCodeSizeWord_zero_lookup_code_zero + drip_extCodeSizeWord_zero_lookup_code_zero (σ := σ'_solm) (target := dripVatTargetWord σ'_solm I) (addr := dripVatAddress σ'_solm I) (dripVatAddress_eq_target σ'_solm I) hfoldCodeSolm @@ -501,7 +501,7 @@ by_cases hprevMaxNot : rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -693,7 +693,7 @@ by_cases hprevMaxNot : intro hbad exact hageNZ (by simpa [age, hrhoPostWord] using hbad) have hfoldCodeSolmNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (dripVatTargetWord σ'_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts' hfoldNoCode @@ -768,7 +768,7 @@ by_cases hprevMaxNot : rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -960,7 +960,7 @@ by_cases hprevMaxNot : intro hbad exact hageNZ (by simpa [age, hrhoPostWord] using hbad) have hfoldCodeSolmNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (dripVatTargetWord σ'_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts' hfoldNoCode diff --git a/Benchmarks/Dss/Jug/DripBodyGenericTactic.lean b/Benchmarks/Dss/Jug/DripBodyGenericTactic.lean index 1fa646fd..b5d2ec02 100644 --- a/Benchmarks/Dss/Jug/DripBodyGenericTactic.lean +++ b/Benchmarks/Dss/Jug/DripBodyGenericTactic.lean @@ -27,7 +27,7 @@ have hleSolm : rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -192,10 +192,10 @@ cases hrpowCoupled with · by_cases hprevMax : ((dripVatIlksPrevWord out).toNat : Int) ≤ maxInt256 · by_cases hfoldNoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (dripVatTargetWord σ' I) = ⟨0⟩ · have hfoldCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (dripVatTargetWord σ'_solm I) = ⟨0⟩ := dripVatCodeSize_zero_accountMapEquiv hAccounts' hfoldNoCode @@ -203,7 +203,7 @@ cases hrpowCoupled with (UInt256.ofNat ((σ'_solm.find? (dripVatAddress σ'_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := - drip_uniswapExtCodeSizeWord_zero_lookup_code_zero + drip_extCodeSizeWord_zero_lookup_code_zero (σ := σ'_solm) (target := dripVatTargetWord σ'_solm I) (addr := dripVatAddress σ'_solm I) @@ -373,7 +373,7 @@ cases hrpowCoupled with (UInt256.sub rate (dripVatIlksPrevWord out)) hfoldBaseSize hsz36 hrateMax hprevMax rfl have hfoldCodeSolmNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (dripVatTargetWord σ'_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts' hfoldNoCode diff --git a/Benchmarks/Dss/Jug/DripBodyNZeroTactic.lean b/Benchmarks/Dss/Jug/DripBodyNZeroTactic.lean index 812e7e5b..508685a9 100644 --- a/Benchmarks/Dss/Jug/DripBodyNZeroTactic.lean +++ b/Benchmarks/Dss/Jug/DripBodyNZeroTactic.lean @@ -31,7 +31,7 @@ by_cases hRmulOverflowNZero : rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -145,7 +145,7 @@ by_cases hRmulOverflowNZero : age = ⟨0⟩ ∧ jugRay.toNat * (dripVatIlksPrevWord out).toNat < UInt256.size ∧ ((dripVatIlksPrevWord out).toNat : Int) ≤ maxInt256 ∧ - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (dripVatTargetWord σ' I) = ⟨0⟩ · rcases hFoldNoCodeNZero with ⟨hage0, hfitRmul, hprevMax, hfoldCode⟩ @@ -162,7 +162,7 @@ by_cases hRmulOverflowNZero : rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -252,14 +252,14 @@ by_cases hRmulOverflowNZero : rw [← hrhoPostWord] exact hage0Evm have hfoldCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (dripVatTargetWord σ'_solm I) = ⟨0⟩ := dripVatCodeSize_zero_accountMapEquiv hAccounts' hfoldCode have hfoldNoCodeSolmRaw : (UInt256.ofNat ((σ'_solm.find? (dripVatAddress σ'_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := - drip_uniswapExtCodeSizeWord_zero_lookup_code_zero + drip_extCodeSizeWord_zero_lookup_code_zero (σ := σ'_solm) (target := dripVatTargetWord σ'_solm I) (addr := dripVatAddress σ'_solm I) (dripVatAddress_eq_target σ'_solm I) hfoldCodeSolm @@ -304,7 +304,7 @@ by_cases hRmulOverflowNZero : rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -417,7 +417,7 @@ by_cases hRmulOverflowNZero : age = ⟨0⟩ ∧ jugRay.toNat * (dripVatIlksPrevWord out).toNat < UInt256.size ∧ ((dripVatIlksPrevWord out).toNat : Int) ≤ maxInt256 ∧ - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (dripVatTargetWord σ' I) ≠ ⟨0⟩ · rcases hFoldCallReadyNZero with ⟨hage0, hfitRmul, hprevMax, hfoldCode⟩ @@ -467,7 +467,7 @@ by_cases hRmulOverflowNZero : rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -643,7 +643,7 @@ by_cases hRmulOverflowNZero : rw [← hrhoPostWord] exact hage0Evm have hfoldCodeSolmNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (dripVatTargetWord σ'_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts' hfoldCode have hfoldCodeSolm : @@ -706,7 +706,7 @@ by_cases hRmulOverflowNZero : rw [← hrhoWord] exact hle have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts hvatCode have hvatCodeSolm : @@ -882,7 +882,7 @@ by_cases hRmulOverflowNZero : rw [← hrhoPostWord] exact hage0Evm have hfoldCodeSolmNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (dripVatTargetWord σ'_solm I) ≠ ⟨0⟩ := dripVatCodeSize_ne_zero_accountMapEquiv hAccounts' hfoldCode have hfoldCodeSolm : @@ -955,7 +955,7 @@ by_cases hRmulOverflowNZero : · by_cases hprevMax : ((dripVatIlksPrevWord out).toNat : Int) ≤ maxInt256 · by_cases hfoldCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (dripVatTargetWord σ' I) = ⟨0⟩ · exact hFoldNoCodeNZero ⟨hage0, hfit, hprevMax, hfoldCode⟩ diff --git a/Benchmarks/Dss/Jug/DripEVMFold.lean b/Benchmarks/Dss/Jug/DripEVMFold.lean index da6cca89..b972625e 100644 --- a/Benchmarks/Dss/Jug/DripEVMFold.lean +++ b/Benchmarks/Dss/Jug/DripEVMFold.lean @@ -178,7 +178,7 @@ theorem RD.jugDripVatFoldCallReady (hmem : mem.size = 192) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (dripVatTargetWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (dripVatTargetWord σ' I) ≠ ⟨0⟩) (rd1570 : RD jugBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1570⟩ (delta :: dripVowTargetWord σ' I :: fileDutyIlkWord I :: dripVatFoldSelectorWord :: @@ -193,7 +193,7 @@ theorem RD.jugDripVatFoldCallReady (dripVatFoldCalldataMem σ' I delta mem) (UInt256.ofNat 8) out (cA', σ') k' C' := by obtain ⟨_, _, rd1635⟩ := RD.jugDripVatFoldCallGuard hmem hread64 rd1570 obtain ⟨gasWord, k', C', rd1650⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1635⟩) (okPc := ⟨1647⟩) rd1635 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1635⟩) (okPc := ⟨1647⟩) rd1635 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -206,7 +206,7 @@ theorem RD.jugDripVatFoldNoCode (hmem : mem.size = 192) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (dripVatTargetWord σ' I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (dripVatTargetWord σ' I) = ⟨0⟩) (rd1570 : RD jugBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1570⟩ (delta :: dripVowTargetWord σ' I :: fileDutyIlkWord I :: dripVatFoldSelectorWord :: @@ -215,7 +215,7 @@ theorem RD.jugDripVatFoldNoCode RDrev jugBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd1635⟩ := RD.jugDripVatFoldCallGuard hmem hread64 rd1570 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1635⟩) (okPc := ⟨1647⟩) rd1635 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1635⟩) (okPc := ⟨1647⟩) rd1635 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -282,7 +282,7 @@ theorem RD.jugDripVatFoldCallFailed (hrdataSize : rdata.size < UInt256.size) : RDrev jugBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1651⟩) (okPc := ⟨1667⟩) rd1651 + exact RD.solcCallSuccessGuardMissing (pc := ⟨1651⟩) (okPc := ⟨1667⟩) rd1651 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -302,7 +302,7 @@ theorem RD.jugDripVatFoldCallSucceeded (dripVatFoldEndPtr :: dripVatFoldSelectorWord :: targetWord :: prev :: rate :: fileDutyIlkWord I :: ⟨357⟩ :: sel :: []) mem (UInt256.ofNat 8) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨1651⟩) (okPc := ⟨1667⟩) rd1651 + exact RD.solcCallSuccessGuardOk (pc := ⟨1651⟩) (okPc := ⟨1667⟩) rd1651 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Jug/DripEVMRpow.lean b/Benchmarks/Dss/Jug/DripEVMRpow.lean index c47e5e47..f18747df 100644 --- a/Benchmarks/Dss/Jug/DripEVMRpow.lean +++ b/Benchmarks/Dss/Jug/DripEVMRpow.lean @@ -600,7 +600,7 @@ theorem RD.jugDripRmulOverflowReverts UInt256.eq (UInt256.div (prev * pow) prev) pow = ⟨0⟩ := by exact u256_eq_of_ne hdivNe have rdFallthrough := rd2368.jumpiNT (by native_decide) heqCond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -657,7 +657,7 @@ theorem RD.jugDripRmulRayOverflowReverts UInt256.eq (UInt256.div (prev * jugRay) prev) jugRay = ⟨0⟩ := by exact u256_eq_of_ne hdivNe have rdFallthrough := rd2368.jumpiNT (by native_decide) heqCond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -828,7 +828,7 @@ theorem RD.jugDiffSameRevertXBound rw [hslt] decide have rd2423 := rd2422.jumpiNT (by native_decide) hcond2 (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd2423 + exact RD.solcPush1Dup1Revert0 rd2423 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -875,7 +875,7 @@ theorem RD.jugDiffRevertXBound rw [hslt] decide have rd2423 := rd2422.jumpiNT (by native_decide) hcond2 (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd2423 + exact RD.solcPush1Dup1Revert0 rd2423 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -935,7 +935,7 @@ theorem RD.jugDiffRevertYBound rw [hprevSlt] decide have rd2423 := rd2422.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd2423 + exact RD.solcPush1Dup1Revert0 rd2423 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) diff --git a/Benchmarks/Dss/Jug/DripEVMVat.lean b/Benchmarks/Dss/Jug/DripEVMVat.lean index 37f62436..aaa7528d 100644 --- a/Benchmarks/Dss/Jug/DripEVMVat.lean +++ b/Benchmarks/Dss/Jug/DripEVMVat.lean @@ -131,11 +131,11 @@ theorem RD.jugDripVatIlksNoCode [⟨0⟩, fileDutyIlkWord I, ⟨357⟩, sel] (dripIlkHashMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (dripVatTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (dripVatTargetWord σ I) = ⟨0⟩) : RDrev jugBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd1384⟩ := RD.jugDripToVatIlksExtcodesizeGuard rd1323 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1384⟩) (okPc := ⟨1396⟩) rd1384 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1384⟩) (okPc := ⟨1396⟩) rd1384 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -148,7 +148,7 @@ theorem RD.jugDripVatIlksCallReady [⟨0⟩, fileDutyIlkWord I, ⟨357⟩, sel] (dripIlkHashMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (dripVatTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (dripVatTargetWord σ I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD jugBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1399⟩ (gasWord :: dripVatTargetWord σ I :: ⟨0⟩ :: dripVatIlksOutPtr :: @@ -159,7 +159,7 @@ theorem RD.jugDripVatIlksCallReady ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd1384⟩ := RD.jugDripToVatIlksExtcodesizeGuard rd1323 obtain ⟨gasWord, k', C', rd1399⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1384⟩) (okPc := ⟨1396⟩) rd1384 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1384⟩) (okPc := ⟨1396⟩) rd1384 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -251,7 +251,7 @@ theorem RD.jugDripVatIlksCallFailed (hrdataSize : rdata.size < UInt256.size) : RDrev jugBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1400⟩) (okPc := ⟨1416⟩) rd1400 + exact RD.solcCallSuccessGuardMissing (pc := ⟨1400⟩) (okPc := ⟨1416⟩) rd1400 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -271,7 +271,7 @@ theorem RD.jugDripVatIlksCallSucceeded (dripVatIlksEndPtr :: dripVatIlksSelectorWord :: dripVatTargetWord σ I :: ⟨0⟩ :: ⟨0⟩ :: fileDutyIlkWord I :: ⟨357⟩ :: sel :: []) mem (UInt256.ofNat 6) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨1400⟩) (okPc := ⟨1416⟩) rd1400 + exact RD.solcCallSuccessGuardOk (pc := ⟨1400⟩) (okPc := ⟨1416⟩) rd1400 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -325,7 +325,7 @@ theorem RD.jugDripVatIlksReturnDecodeShortReverts decide have rdFallthrough := RD.jumpiNT rdPushOk (by native_decide) hcond (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -528,7 +528,7 @@ theorem RD.jugDripAddOverflowReverts have rdFallthrough := rdPushOk.jumpiNT (by native_decide) (by rw [hlt]; decide) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) diff --git a/Benchmarks/Dss/Jug/Rpow.lean b/Benchmarks/Dss/Jug/Rpow.lean index 948e711c..7b5e878c 100644 --- a/Benchmarks/Dss/Jug/Rpow.lean +++ b/Benchmarks/Dss/Jug/Rpow.lean @@ -838,7 +838,7 @@ theorem RD.jugDripRpowLoopRevertXX have heqCond : UInt256.eq (UInt256.div (x * x) x) x = ⟨0⟩ := u256_eq_of_ne hdivNe have rdFallthrough := rd2214.jumpiNT (by native_decide) heqCond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -899,7 +899,7 @@ theorem RD.jugDripRpowLoopRevertXXRound rw [hlt] native_decide have rdFallthrough := rd2230.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1065,7 +1065,7 @@ theorem RD.jugDripRpowLoopRevertZX raw iszero (by native_decide) (by evm_ov), raw push2 ⟨2273⟩ (by native_decide) (by evm_ov)] have rdFallthrough := rd2268.jumpiNT (by native_decide) hmulGuardFail (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -1157,7 +1157,7 @@ theorem RD.jugDripRpowLoopRevertZXRound rw [hlt] native_decide have rdFallthrough := rd2284.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) diff --git a/Benchmarks/Dss/Jug/SpecSyntax.lean b/Benchmarks/Dss/Jug/SpecSyntax.lean index 84582805..8902141f 100644 --- a/Benchmarks/Dss/Jug/SpecSyntax.lean +++ b/Benchmarks/Dss/Jug/SpecSyntax.lean @@ -2,105 +2,167 @@ import Benchmarks.Dss.Jug.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS Jug spec through the Solm notation frontend +# Jug spec in the Solidity-faithful Solm frontend -This file exposes a notation-side presentation for representative parts of the Jug scaffold covered -by the current Solm frontend, and checks by `rfl` that they are definitionally equal to the AST spec -in `Benchmarks.Dss.Jug.Spec`. +The whole `jug.sol` spec written with `solidity%` and proven definitionally equal to the AST spec +in `Spec.lean`. Checked-math helpers are inlined; the assembly `_rpow` loop is the structural +while-loop; `drip`'s wrapping age subtraction is the explicit ternary; `extCodeSize` guards on +the storage `vat` receiver use the `${…}` escape (the surface `x.code.length` builtin only +resolves locals). Transition order matches `contract.transitions` (selector order). -/ -open Solm Solm.Notation +open Solm Solm.Notation Benchmarks.Dss.Jug namespace Benchmarks.Dss.Jug.Syntax -def storageDeclsSyntax : List StorageDecl := - sState% { - (address => uint256) wards - } ++ - [ { name := "ilks", ty := .mapping (.bytes bytes32Width) IlkStructTy }, - { name := "vat", ty := addrSt }, - { name := "vow", ty := addrSt }, - { name := "base", ty := uint256St } ] - -def relyTransitionSyntax : TransitionDecl := - { name := "rely" - params := [{ name := "usr", ty := addr }] - returnType := [] - body := sBlock% { - require msg.value == 0 - require @wards[msg.sender] == 1 - @wards[usr] := 1 - } } - -def denyTransitionSyntax : TransitionDecl := - { name := "deny" - params := [{ name := "usr", ty := addr }] - returnType := [] - body := sBlock% { - require msg.value == 0 - require @wards[msg.sender] == 1 - @wards[usr] := 0 - } } - -def baseTransitionSyntax : TransitionDecl := - { name := "base" - params := [] - returnType := [uint256] - body := sBlock% { - require msg.value == 0 - return @base - } } - -def vowTransitionSyntax : TransitionDecl := - { name := "vow" - params := [] - returnType := [addr] - body := sBlock% { - require msg.value == 0 - return @vow - } } - -def transitionsSyntax : List TransitionDecl := - [ baseTransitionSyntax, - denyTransitionSyntax, - dripTransition, - fileBaseTransition, - fileDutyTransition, - fileVowTransition, - ilksTransition, - initTransition, - relyTransitionSyntax, - vatTransition, - vowTransitionSyntax, - wardsTransition ] - -def contractSyntax : ContractDecl := - { name := "Jug" - storage := storageDeclsSyntax - ctor := constructorDecl - structs := structs - functions := functions - transitions := transitionsSyntax } - -theorem storageDeclsSyntax_eq : storageDeclsSyntax = Benchmarks.Dss.Jug.storageDecls := by - rfl - -theorem relyTransitionSyntax_eq : relyTransitionSyntax = Benchmarks.Dss.Jug.relyTransition := by - rfl - -theorem denyTransitionSyntax_eq : denyTransitionSyntax = Benchmarks.Dss.Jug.denyTransition := by - rfl - -theorem baseTransitionSyntax_eq : baseTransitionSyntax = Benchmarks.Dss.Jug.baseTransition := by - rfl - -theorem vowTransitionSyntax_eq : vowTransitionSyntax = Benchmarks.Dss.Jug.vowTransition := by - rfl - -theorem transitionsSyntax_eq : transitionsSyntax = Benchmarks.Dss.Jug.transitions := by - rfl - -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Jug.contract := by - rfl +def contractSyntax : ContractDecl := solidity% contract Jug { + struct Ilk { + uint256 duty; + uint256 rho; + } + + mapping(address => uint256) wards; + mapping(bytes32 => Ilk) ilks; + address vat; + address vow; + uint256 base; + + constructor(address vat_) { + wards[msg.sender] = 1; + vat = vat_; + } + + function _add(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x + y) as uint256; + require(z >= x); + return z; + } + + function _diff(uint256 x, uint256 y) internal returns (int256) { + int256 z = (x - y) as int256; + require(x <= #maxInt256); + require(y <= #maxInt256); + return z; + } + + function _rmul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + z = z / #one; + return z; + } + + function _rpow(uint256 x, uint256 n, uint256 b) internal returns (uint256) { + if (x == 0) { + if (n == 0) { + return b; + } else { + return 0; + } + } else { + uint256 z = n % 2 == 0 ? b : x; + uint256 half = b / 2; + n = n / 2; + while (n != 0) { + uint256 xx = (x * x) as uint256; + require(x == 0 || xx / x == x); + uint256 xxRound = (xx + half) as uint256; + require(xxRound >= xx); + x = xxRound / b; + if (n % 2 != 0) { + uint256 zx = (z * x) as uint256; + require(x == 0 || zx / x == z); + uint256 zxRound = (zx + half) as uint256; + require(zxRound >= zx); + z = zxRound / b; + } + n = n / 2; + } + return z; + } + } + + function base() external returns (uint256) { + return base; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function drip(bytes32 ilk) external returns (uint256) { + require(block.timestamp >= ilks[ilk].rho); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var vatIlk = vat.ilks(ilk); + uint256 prev = ${Expr.tupleGet (.var "vatIlk") 1}; + var fee = _add(base, ilks[ilk].duty); + var pow = _rpow(fee, ilks[ilk].rho <= block.timestamp ? (block.timestamp - ilks[ilk].rho) as uint256 : (#(Int.ofNat Ethereum.UInt256.size) + block.timestamp - ilks[ilk].rho) as uint256, #one); + var rate = _rmul(pow, prev); + var delta = _diff(rate, prev); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _foldRet = vat.fold(ilk, vow, delta); + ilks[ilk].rho = block.timestamp; + return rate; + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x6261736500000000000000000000000000000000000000000000000000000000)) { + base = data; + } else { + require(false); + } + } + + function file(bytes32 ilk, bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + require(block.timestamp == ilks[ilk].rho); + if (what == bytes32(0x6475747900000000000000000000000000000000000000000000000000000000)) { + ilks[ilk].duty = data; + } else { + require(false); + } + } + + function file(bytes32 what, address data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x766f770000000000000000000000000000000000000000000000000000000000)) { + vow = data; + } else { + require(false); + } + } + + function ilks(bytes32 arg0) external returns (uint256, uint256) { + return (ilks[arg0].duty, ilks[arg0].rho); + } + + function init(bytes32 ilk) external { + require(wards[msg.sender] == 1); + require(ilks[ilk].duty == 0); + ilks[ilk].duty = #one; + ilks[ilk].rho = block.timestamp; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 1; + } + + function vat() external returns (address) { + return vat; + } + + function vow() external returns (address) { + return vow; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Jug.contract := by rfl end Benchmarks.Dss.Jug.Syntax diff --git a/Benchmarks/Dss/LinearDecrease/Dispatch.lean b/Benchmarks/Dss/LinearDecrease/Dispatch.lean index 6ac72713..be2a6a41 100644 --- a/Benchmarks/Dss/LinearDecrease/Dispatch.lean +++ b/Benchmarks/Dss/LinearDecrease/Dispatch.lean @@ -265,7 +265,7 @@ theorem stairstepNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} |>.selectorArmNotTakenAuto (stairstepArmsWellFormed 5 (by omega)) (heq0 5 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h98 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h98 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem stairstepX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} @@ -277,7 +277,7 @@ theorem stairstepX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem stairstepX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -300,7 +300,7 @@ theorem stairstepX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h98 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h98 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem stairstepX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} diff --git a/Benchmarks/Dss/LinearDecrease/Price.lean b/Benchmarks/Dss/LinearDecrease/Price.lean index eeefe838..5ab48f58 100644 --- a/Benchmarks/Dss/LinearDecrease/Price.lean +++ b/Benchmarks/Dss/LinearDecrease/Price.lean @@ -1564,7 +1564,7 @@ theorem stairstepPriceMulRayOverflowReverts {cA σ I} {g : Sat256} {s0 : State} raw jumpdest (by native_decide) (by evm_ov), raw push2 ⟨620⟩ (by native_decide) (by evm_ov), raw jumpiNT (by native_decide) rfl (by evm_ov)] - exact RD.uniswapPush1Dup1Revert0 rd1019pre + exact RD.solcPush1Dup1Revert0 rd1019pre (by native_decide) (by native_decide) (by native_decide) (by evm_ov) set_option maxHeartbeats 1000000 in @@ -1730,7 +1730,7 @@ theorem stairstepPriceRmulOverflowReverts {cA σ I} {g : Sat256} {s0 : State} raw jumpdest (by native_decide) (by evm_ov), raw push2 ⟨1056⟩ (by native_decide) (by evm_ov), raw jumpiNT (by native_decide) rfl (by evm_ov)] - exact RD.uniswapPush1Dup1Revert0 rd1052pre + exact RD.solcPush1Dup1Revert0 rd1052pre (by native_decide) (by native_decide) (by native_decide) (by evm_ov) theorem stairstepPriceFinishReturn {cA σ I} {g : Sat256} {s0 : State} diff --git a/Benchmarks/Dss/LinearDecrease/SpecSyntax.lean b/Benchmarks/Dss/LinearDecrease/SpecSyntax.lean index a3e0e6c9..96c35ea2 100644 --- a/Benchmarks/Dss/LinearDecrease/SpecSyntax.lean +++ b/Benchmarks/Dss/LinearDecrease/SpecSyntax.lean @@ -2,19 +2,85 @@ import Benchmarks.Dss.LinearDecrease.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS LinearDecrease spec through the Solm notation frontend +# LinearDecrease spec in the Solidity-faithful Solm frontend -The main spec lives in `Spec.lean`; this companion keeps the benchmark's notation-side check wired -up as the body surface grows. +The whole `abaci.sol` `LinearDecrease` spec written with `solidity%` and proven definitionally +equal to the AST spec in `Spec.lean`. Checked-math helpers are inlined as surface statements; +`"tau"` is the big-endian `bytes32` literal; `#RAY` is the spec's `RAY` constant. +Transition order matches `contract.transitions` (selector order). -/ -open Solm Solm.Notation +open Solm Solm.Notation Benchmarks.Dss.LinearDecrease namespace Benchmarks.Dss.LinearDecrease.Syntax -def contractSyntax : ContractDecl := Benchmarks.Dss.LinearDecrease.contract +def contractSyntax : ContractDecl := solidity% contract LinearDecrease { + mapping(address => uint256) wards; + uint256 tau; -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.LinearDecrease.contract := by - rfl + constructor() { + wards[msg.sender] = 1; + } + + function add(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x + y) as uint256; + require(z >= x); + return z; + } + + function mul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + return z; + } + + function rmul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + z = z / #RAY; + return z; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x7461750000000000000000000000000000000000000000000000000000000000)) { + tau = data; + } else { + require(false); + } + } + + function price(uint256 top, uint256 dur) external returns (uint256) { + if (dur >= tau) { + return 0; + } else { + uint256 left = (tau - dur) as uint256; + var scaled = mul(left, #RAY); + uint256 ratio = scaled / tau; + var out = rmul(top, ratio); + return out; + } + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 1; + } + + function tau() external returns (uint256) { + return tau; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.LinearDecrease.contract := by rfl end Benchmarks.Dss.LinearDecrease.Syntax diff --git a/Benchmarks/Dss/Pot/Dispatch.lean b/Benchmarks/Dss/Pot/Dispatch.lean index 7a3b677a..8bcd58a8 100644 --- a/Benchmarks/Dss/Pot/Dispatch.lean +++ b/Benchmarks/Dss/Pot/Dispatch.lean @@ -603,7 +603,7 @@ theorem potJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : UInt25 have h267 := h.push2 potDispatchRevertPc hpush (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h267 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h267 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem potG223NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -619,7 +619,7 @@ theorem potG223NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} |>.selectorArmNotTakenAuto (potG223ArmsWellFormed 2 (by omega)) (heq0 2 (by omega)) (by simp) |>.selectorArmNotTakenAuto (potG223ArmsWellFormed 3 (by omega)) (heq0 3 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h267 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h267 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem potG174NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -675,7 +675,7 @@ theorem potX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) /-- `calldatasize < 4`: the selector guard reverts. -/ @@ -699,7 +699,7 @@ theorem potX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h267 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h267 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) /-- No selector matches: the dispatcher routes to some group, scans all arms, and reverts. -/ diff --git a/Benchmarks/Dss/Pot/Drip.lean b/Benchmarks/Dss/Pot/Drip.lean index 157ab820..05725b0f 100644 --- a/Benchmarks/Dss/Pot/Drip.lean +++ b/Benchmarks/Dss/Pot/Drip.lean @@ -52,7 +52,7 @@ theorem potDripX_mulReady {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel raw swap2 (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] - have rd1994 := rd1993.uniswapAddress (by native_decide) (by evm_ov) + have rd1994 := rd1993.address (by native_decide) (by evm_ov) have rd2001 := evm_run rd1994 with [ raw swap1 (by native_decide) (by evm_ov), raw push2 ⟨2005⟩ (by native_decide) (by evm_ov), @@ -177,7 +177,7 @@ theorem potDripX_callGuard {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {se and the post-`CALL` cursor. -/ theorem potDripX_postCall {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel chi_ tmp : UInt256} (hdepth : I.depth.val < 1024) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ'' (dripVatTargetWord σ'' I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ'' (dripVatTargetWord σ'' I) ≠ ⟨0⟩) (h : RD potBytecode I g s0 ⟨2079⟩ (dripVatTargetWord σ'' I :: dripVatTargetWord σ'' I :: ⟨0⟩ :: ⟨128⟩ :: ⟨100⟩ :: ⟨128⟩ :: ⟨0⟩ :: ⟨228⟩ :: potSuckSelectorWord :: dripVatTargetWord σ'' I :: chi_ :: tmp :: @@ -203,7 +203,7 @@ theorem potDripX_postCall {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel (UInt256.ofNat 8) o (cA', σ') k' C' ∧ o.size < UInt256.size := by obtain ⟨gasWord, k1, C1, rd2094⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2079⟩) (okPc := ⟨2091⟩) h hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨2079⟩) (okPc := ⟨2091⟩) h hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -231,7 +231,7 @@ theorem potDripX_successTail {I} {g : Sat256} {s0 : State} {k C : ℕ} (⟨1⟩ :: w1 :: w2 :: w3 :: chi_ :: tmp :: ⟨341⟩ :: [sel]) mem (UInt256.ofNat 8) o acc k C) : RDret potBytecode g s0 acc (UInt256.toByteArray tmp) := by - obtain ⟨k1, C1, rd2113⟩ := RD.uniswapCallSuccessGuardOk (pc := ⟨2095⟩) (okPc := ⟨2111⟩) h + obtain ⟨k1, C1, rd2113⟩ := RD.solcCallSuccessGuardOk (pc := ⟨2095⟩) (okPc := ⟨2111⟩) h (by decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -282,7 +282,7 @@ theorem potDripX_failTail {I} {g : Sat256} {s0 : State} {k C : ℕ} (⟨0⟩ :: w1 :: w2 :: w3 :: chi_ :: tmp :: ⟨341⟩ :: [sel]) mem aw o acc k C) : RDrev potBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2095⟩) (okPc := ⟨2111⟩) h rfl + exact RD.solcCallSuccessGuardMissing (pc := ⟨2095⟩) (okPc := ⟨2111⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) hosz @@ -290,7 +290,7 @@ theorem potDripX_failTail {I} {g : Sat256} {s0 : State} {k C : ℕ} /-- `@2079`: `extcodesize(vat) = 0` ⇒ the checked external call reverts. -/ theorem potDripX_ecsZero {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel chi_ tmp : UInt256} - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ'' (dripVatTargetWord σ'' I) = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ'' (dripVatTargetWord σ'' I) = ⟨0⟩) (h : RD potBytecode I g s0 ⟨2079⟩ (dripVatTargetWord σ'' I :: dripVatTargetWord σ'' I :: ⟨0⟩ :: ⟨128⟩ :: ⟨100⟩ :: ⟨128⟩ :: ⟨0⟩ :: ⟨228⟩ :: potSuckSelectorWord :: dripVatTargetWord σ'' I :: chi_ :: tmp :: @@ -298,14 +298,14 @@ theorem potDripX_ecsZero {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel (potSuckCalldataMem σ'' I (dripPieWord σ'' I * chi_) solcFreePtrMem) (UInt256.ofNat 8) ByteArray.empty (cA, σ'') k C) : RDrev potBytecode g s0 := by - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2079⟩) (okPc := ⟨2091⟩) h hcodeSize + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2079⟩) (okPc := ⟨2091⟩) h hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) /-- `@2079`: `depth = 1024` ⇒ the CALL cannot proceed (checked external call reverts). -/ theorem potDripX_depthLimit {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel chi_ tmp : UInt256} - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ'' (dripVatTargetWord σ'' I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ'' (dripVatTargetWord σ'' I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (h : RD potBytecode I g s0 ⟨2079⟩ (dripVatTargetWord σ'' I :: dripVatTargetWord σ'' I :: ⟨0⟩ :: ⟨128⟩ :: ⟨100⟩ :: ⟨128⟩ :: @@ -315,7 +315,7 @@ theorem potDripX_depthLimit {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {s (UInt256.ofNat 8) ByteArray.empty (cA, σ'') k C) : RDrev potBytecode g s0 := by obtain ⟨gasWord, k1, C1, rd2094⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2079⟩) (okPc := ⟨2091⟩) h hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨2079⟩) (okPc := ⟨2091⟩) h hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -363,7 +363,7 @@ theorem potDripX_mulReverts {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {s raw swap2 (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] - have rd1994 := rd1993.uniswapAddress (by native_decide) (by evm_ov) + have rd1994 := rd1993.address (by native_decide) (by evm_ov) have rd2001 := evm_run rd1994 with [ raw swap1 (by native_decide) (by evm_ov), raw push2 ⟨2005⟩ (by native_decide) (by evm_ov), @@ -879,7 +879,7 @@ theorem potDripSolm_vatLookup {cA gh bl σ σ₀ A I} {g v4 v7 : UInt256} : /-- Bridge the EVM `extcodesize(vat) ≠ 0` fact to Solm-side `vat` code positivity on `dripEvmRho`. -/ theorem potDripSolm_vatCodePos {cA gh bl σ_evm σ_solm σ₀ A I} {g v4 v7 : UInt256} (hAccounts : accountMapEquiv σ_evm σ_solm) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord + (hcodeSize : Reasoning.Theory.extCodeSizeWord (sstoreAccountMap I.codeOwner (sstoreAccountMap I.codeOwner σ_evm ⟨4⟩ v4) ⟨7⟩ v7) (dripVatTargetWord (sstoreAccountMap I.codeOwner (sstoreAccountMap I.codeOwner σ_evm ⟨4⟩ v4) ⟨7⟩ v7) I) ≠ @@ -899,14 +899,14 @@ theorem potDripSolm_vatCodePos {cA gh bl σ_evm σ_solm σ₀ A I} {g v4 v7 : UI have haccEquiv : accountMapEquiv (sstoreAccountMap I.codeOwner (sstoreAccountMap I.codeOwner σ_evm ⟨4⟩ v4) ⟨7⟩ v7) σ''s := accountMapEquiv_sstoreAccountMap_two I.codeOwner I.codeOwner ⟨4⟩ v4 ⟨7⟩ v7 hAccounts - have hne : Reasoning.Theory.uniswapExtCodeSizeWord σ''s (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := by - rw [← htarget, ← Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv haccEquiv] + have hne : Reasoning.Theory.extCodeSizeWord σ''s (dripVatTargetWord σ_solm I) ≠ ⟨0⟩ := by + rw [← htarget, ← Reasoning.Theory.extCodeSizeWord_accountMapEquiv haccEquiv] exact hcodeSize rw [potDripSolm_vatLookup, ← hσs] have haddr : dripVatAddress σ_solm I = AccountAddress.ofUInt256 (dripVatTargetWord σ_solm I) := by rw [dripVatAddress]; exact (accountAddress_ofUInt256_eq_ofNat_toNat _).symm rw [haddr] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hf : σ''s.find? (AccountAddress.ofUInt256 (dripVatTargetWord σ_solm I)) with | none => simp only [hf, Option.option] at hne; exact absurd rfl hne | some acc => @@ -916,7 +916,7 @@ theorem potDripSolm_vatCodePos {cA gh bl σ_evm σ_solm σ₀ A I} {g v4 v7 : UI /-- Bridge the EVM `extcodesize(vat) = 0` fact to Solm-side `vat` empty code on `dripEvmRho`. -/ theorem potDripSolm_vatCodeZero {cA gh bl σ_evm σ_solm σ₀ A I} {g v4 v7 : UInt256} (hAccounts : accountMapEquiv σ_evm σ_solm) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord + (hcodeSize : Reasoning.Theory.extCodeSizeWord (sstoreAccountMap I.codeOwner (sstoreAccountMap I.codeOwner σ_evm ⟨4⟩ v4) ⟨7⟩ v7) (dripVatTargetWord (sstoreAccountMap I.codeOwner (sstoreAccountMap I.codeOwner σ_evm ⟨4⟩ v4) ⟨7⟩ v7) I) = @@ -936,14 +936,14 @@ theorem potDripSolm_vatCodeZero {cA gh bl σ_evm σ_solm σ₀ A I} {g v4 v7 : U have haccEquiv : accountMapEquiv (sstoreAccountMap I.codeOwner (sstoreAccountMap I.codeOwner σ_evm ⟨4⟩ v4) ⟨7⟩ v7) σ''s := accountMapEquiv_sstoreAccountMap_two I.codeOwner I.codeOwner ⟨4⟩ v4 ⟨7⟩ v7 hAccounts - have hz : Reasoning.Theory.uniswapExtCodeSizeWord σ''s (dripVatTargetWord σ_solm I) = ⟨0⟩ := by - rw [← htarget, ← Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv haccEquiv] + have hz : Reasoning.Theory.extCodeSizeWord σ''s (dripVatTargetWord σ_solm I) = ⟨0⟩ := by + rw [← htarget, ← Reasoning.Theory.extCodeSizeWord_accountMapEquiv haccEquiv] exact hcodeSize rw [potDripSolm_vatLookup, ← hσs] have haddr : dripVatAddress σ_solm I = AccountAddress.ofUInt256 (dripVatTargetWord σ_solm I) := by rw [dripVatAddress]; exact (accountAddress_ofUInt256_eq_ofNat_toNat _).symm rw [haddr] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hz + unfold Reasoning.Theory.extCodeSizeWord at hz cases hf : σ''s.find? (AccountAddress.ofUInt256 (dripVatTargetWord σ_solm I)) with | none => simp only [Option.option]; native_decide | some acc => @@ -1380,7 +1380,7 @@ theorem potDripBodyAfterRpow {cA gh bl σ_evm σ_solm σ₀ A I} {g pow : UInt25 rd1960 obtain ⟨_, _, rd2079⟩ := potDripX_callGuard rd2005 by_cases hecs : - Reasoning.Theory.uniswapExtCodeSizeWord σ2 (dripVatTargetWord σ2 I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ2 (dripVatTargetWord σ2 I) = ⟨0⟩ · exact RDrev.reEquivExecutionRevert hcode (potDripX_ecsZero hecs rd2079) hdispatch hdecode (potDripSolmBody_ecsZero hwv hleSolm hrpow hfitRmul hleSub hfitMul (potDripSolm_vatCodeZero (v4 := dripTmpVal σ_solm I pow) diff --git a/Benchmarks/Dss/Pot/DripEVMArith.lean b/Benchmarks/Dss/Pot/DripEVMArith.lean index a1d551f4..b2eca478 100644 --- a/Benchmarks/Dss/Pot/DripEVMArith.lean +++ b/Benchmarks/Dss/Pot/DripEVMArith.lean @@ -180,7 +180,7 @@ theorem RD.potMulRevertsDrip {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} raw jumpdest (by native_decide) (by evm_ov), raw push2 ⟨2294⟩ (by native_decide) (by evm_ov)] have rd2332 := rd2331.jumpiNT (by native_decide) hne (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd2332 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd2332 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) /-! ## `_rmul @2542` (calls `_mul @2300`, divides by `ONE`) -/ @@ -329,7 +329,7 @@ theorem potDripX_subReverts {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} {sel rw [show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rd2344 have rd2347 := rd2344.push2 ⟨2294⟩ (by native_decide) (by evm_ov) have rd2348 := rd2347.jumpiNT (by native_decide) rfl (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd2348 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd2348 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) /-! ## Storage writes `chi := tmp`, `rho := now` (`@1950 → @1960`) -/ diff --git a/Benchmarks/Dss/Pot/Exit.lean b/Benchmarks/Dss/Pot/Exit.lean index cd3aa048..0efc5dce 100644 --- a/Benchmarks/Dss/Pot/Exit.lean +++ b/Benchmarks/Dss/Pot/Exit.lean @@ -67,7 +67,7 @@ theorem RD.potSubReverts {ee : ExecutionEnv} {g : Sat256} {s0 : State} raw iszero (by native_decide) (by evm_ov), raw push2 ⟨2294⟩ (by native_decide) (by evm_ov)] have rdRev := rdPre.jumpiNT (by native_decide) (by rw [hgt]; decide) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdRev + exact RD.solcPush1Dup1Revert0 rdRev (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -158,7 +158,7 @@ theorem potExitX_shortReverts {cA σ I} {g : Sat256} {s0 : State} {sel : UInt256 raw iszero (by native_decide) (by evm_ov), raw push2 ⟨530⟩ (by native_decide) (by evm_ov)] have rdRev := rdPre.jumpiNT (by native_decide) (by rw [hlt]; decide) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdRev + exact RD.solcPush1Dup1Revert0 rdRev (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -282,7 +282,7 @@ theorem potExitX_mulReady {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel raw swap1 (by native_decide) (by evm_ov), raw push4 potMoveSelectorWord (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] - have rd1685 := rdPre.uniswapAddress (by native_decide) (by evm_ov) + have rd1685 := rdPre.address (by native_decide) (by evm_ov) have rdPre2 := evm_run rd1685 with [ raw swap1 (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), @@ -419,7 +419,7 @@ theorem potExitX_callGuard {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {se theorem potExitX_postCall {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel : UInt256} {mem : ByteArray} (hmemSize : mem.size = 96) (hdepth : I.depth.val < 1024) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ'' (joinVatMasked σ'' I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ'' (joinVatMasked σ'' I) ≠ ⟨0⟩) (h : RD potBytecode I g s0 ⟨927⟩ (joinVatMasked σ'' I :: joinVatMasked σ'' I :: ⟨0⟩ :: ⟨128⟩ :: ⟨100⟩ :: ⟨128⟩ :: ⟨0⟩ :: ⟨228⟩ :: potMoveSelectorWord :: joinVatMasked σ'' I :: joinWadWord I :: ⟨301⟩ :: sel :: []) @@ -444,7 +444,7 @@ theorem potExitX_postCall {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel mem' aw' o (cA', σ') k' C' ∧ o.size < UInt256.size := by obtain ⟨gasWord, k1, C1, rd942⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨927⟩) (okPc := ⟨939⟩) h hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨927⟩) (okPc := ⟨939⟩) h hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -457,7 +457,7 @@ set_option maxHeartbeats 1000000 in theorem potExitX_depthLimitReverts {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel : UInt256} {mem : ByteArray} (hdepth : I.depth = 1024) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ'' (joinVatMasked σ'' I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ'' (joinVatMasked σ'' I) ≠ ⟨0⟩) (h : RD potBytecode I g s0 ⟨927⟩ (joinVatMasked σ'' I :: joinVatMasked σ'' I :: ⟨0⟩ :: ⟨128⟩ :: ⟨100⟩ :: ⟨128⟩ :: ⟨0⟩ :: ⟨228⟩ :: potMoveSelectorWord :: joinVatMasked σ'' I :: joinWadWord I :: ⟨301⟩ :: sel :: []) @@ -466,7 +466,7 @@ theorem potExitX_depthLimitReverts {cA σ'' I} {g : Sat256} {s0 : State} {k C : (UInt256.ofNat 8) ByteArray.empty (cA, σ'') k C) : RDrev potBytecode g s0 := by obtain ⟨gasWord, k1, C1, rd942⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨927⟩) (okPc := ⟨939⟩) h hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨927⟩) (okPc := ⟨939⟩) h hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -553,7 +553,7 @@ theorem potExitX_mulOverflowReverts {cA σ'' I} {g : Sat256} {s0 : State} {k C : raw swap1 (by native_decide) (by evm_ov), raw push4 potMoveSelectorWord (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] - have rd1685 := rdPre.uniswapAddress (by native_decide) (by evm_ov) + have rd1685 := rdPre.address (by native_decide) (by evm_ov) have rdPre2 := evm_run rd1685 with [ raw swap1 (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), @@ -1163,7 +1163,7 @@ theorem potExitBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} twoWordHashMem_read64 (joinCallerWord I) ⟨1⟩ (joinPieHashMem_size I) (joinPieHashMem_read64 I) obtain ⟨_, _, rd927⟩ := potExitX_callGuard hmemSz hmemR64 rd853 - by_cases hEcs : uniswapExtCodeSizeWord (exitSigma'' σ_evm I) + by_cases hEcs : extCodeSizeWord (exitSigma'' σ_evm I) (joinVatMasked (exitSigma'' σ_evm I) I) = ⟨0⟩ · refine (potJoinX_ecsZero hEcs rd927).reEquivExecutionRevert hcode hdispatch (potDecode_exit_ok hsz36) diff --git a/Benchmarks/Dss/Pot/Join.lean b/Benchmarks/Dss/Pot/Join.lean index b92effa4..2db32f30 100644 --- a/Benchmarks/Dss/Pot/Join.lean +++ b/Benchmarks/Dss/Pot/Join.lean @@ -335,7 +335,7 @@ theorem RD.potAddReverts {ee : ExecutionEnv} {g : Sat256} {s0 : State} raw iszero (by native_decide) (by evm_ov), raw push2 ⟨2294⟩ (by native_decide) (by evm_ov)] have rdRev := rdPre.jumpiNT (by native_decide) (by rw [hlt]; decide) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdRev + exact RD.solcPush1Dup1Revert0 rdRev (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -478,7 +478,7 @@ theorem RD.potMulReverts {ee : ExecutionEnv} {g : Sat256} {s0 : State} raw jumpdest (by native_decide) (by evm_ov), raw push2 ⟨2294⟩ (by native_decide) (by evm_ov)] have rdRev := rdPre3.jumpiNT (by native_decide) (by rw [hEqZero]) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdRev + exact RD.solcPush1Dup1Revert0 rdRev (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -568,7 +568,7 @@ theorem potJoinX_shortReverts {cA σ I} {g : Sat256} {s0 : State} {sel : UInt256 raw iszero (by native_decide) (by evm_ov), raw push2 ⟨294⟩ (by native_decide) (by evm_ov)] have rdRev := rdPre.jumpiNT (by native_decide) (by rw [hlt]; decide) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdRev + exact RD.solcPush1Dup1Revert0 rdRev (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -744,7 +744,7 @@ theorem potJoinX_mulReady {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel raw swap1 (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] - have rd843 := rdPre.uniswapAddress (by native_decide) (by evm_ov) + have rd843 := rdPre.address (by native_decide) (by evm_ov) have rdPre2 := evm_run rd843 with [ raw swap1 (by native_decide) (by evm_ov), raw push2 ⟨853⟩ (by native_decide) (by evm_ov), @@ -941,7 +941,7 @@ theorem potDecode_join_none_short {I : ExecutionEnv} theorem potJoinX_postCall {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel : UInt256} {mem : ByteArray} (hmemSize : mem.size = 96) (hdepth : I.depth.val < 1024) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ'' (joinVatMasked σ'' I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ'' (joinVatMasked σ'' I) ≠ ⟨0⟩) (h : RD potBytecode I g s0 ⟨927⟩ (joinVatMasked σ'' I :: joinVatMasked σ'' I :: ⟨0⟩ :: ⟨128⟩ :: ⟨100⟩ :: ⟨128⟩ :: ⟨0⟩ :: ⟨228⟩ :: potMoveSelectorWord :: joinVatMasked σ'' I :: joinWadWord I :: ⟨301⟩ :: sel :: []) @@ -966,7 +966,7 @@ theorem potJoinX_postCall {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel mem' aw' o (cA', σ') k' C' ∧ o.size < UInt256.size := by obtain ⟨gasWord, k1, C1, rd942⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨927⟩) (okPc := ⟨939⟩) h hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨927⟩) (okPc := ⟨939⟩) h hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -983,7 +983,7 @@ theorem potJoinX_successTail {cA' σ' I} {g : Sat256} {s0 : State} {k C : ℕ} { mem aw o (cA', σ') k C) : RDret potBytecode g s0 (cA', σ') ByteArray.empty := by obtain ⟨k1, C1, rd961⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨943⟩) (okPc := ⟨959⟩) h (by decide) + RD.solcCallSuccessGuardOk (pc := ⟨943⟩) (okPc := ⟨959⟩) h (by decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1005,7 +1005,7 @@ theorem potJoinX_failTail {cA' σ' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel joinWadWord I :: ⟨301⟩ :: sel :: []) mem aw o (cA', σ') k C) : RDrev potBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨943⟩) (okPc := ⟨959⟩) h rfl + exact RD.solcCallSuccessGuardMissing (pc := ⟨943⟩) (okPc := ⟨959⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) hosz @@ -1020,7 +1020,7 @@ theorem potJoinX_successTailGen {cA' σ' I} {g : Sat256} {s0 : State} {k C : ℕ mem aw o (cA', σ') k C) : RDret potBytecode g s0 (cA', σ') ByteArray.empty := by obtain ⟨k1, C1, rd961⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨943⟩) (okPc := ⟨959⟩) h (by decide) + RD.solcCallSuccessGuardOk (pc := ⟨943⟩) (okPc := ⟨959⟩) h (by decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1041,7 +1041,7 @@ theorem potJoinX_failTailGen {cA' σ' I} {g : Sat256} {s0 : State} {k C : ℕ} { (⟨0⟩ :: ⟨228⟩ :: potMoveSelectorWord :: vw :: joinWadWord I :: ⟨301⟩ :: sel :: []) mem aw o (cA', σ') k C) : RDrev potBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨943⟩) (okPc := ⟨959⟩) h rfl + exact RD.solcCallSuccessGuardMissing (pc := ⟨943⟩) (okPc := ⟨959⟩) h rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) hosz @@ -1050,13 +1050,13 @@ theorem potJoinX_failTailGen {cA' σ' I} {g : Sat256} {s0 : State} {k C : ℕ} { /-- Logic 927: `extcodesize(vat) = 0` ⇒ the checked external call reverts. -/ theorem potJoinX_ecsZero {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel : UInt256} {mem : ByteArray} - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ'' (joinVatMasked σ'' I) = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ'' (joinVatMasked σ'' I) = ⟨0⟩) (h : RD potBytecode I g s0 ⟨927⟩ (joinVatMasked σ'' I :: joinVatMasked σ'' I :: ⟨0⟩ :: ⟨128⟩ :: ⟨100⟩ :: ⟨128⟩ :: ⟨0⟩ :: ⟨228⟩ :: potMoveSelectorWord :: joinVatMasked σ'' I :: joinWadWord I :: ⟨301⟩ :: sel :: []) mem (UInt256.ofNat 8) ByteArray.empty (cA, σ'') k C) : RDrev potBytecode g s0 := by - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨927⟩) (okPc := ⟨939⟩) h hcodeSize + exact RD.solcExtcodesizeGuardMissing (pc := ⟨927⟩) (okPc := ⟨939⟩) h hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1141,7 +1141,7 @@ theorem potJoinX_mulOverflowReverts {cA σ'' I} {g : Sat256} {s0 : State} {k C : raw swap1 (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] - have rd843 := rdPre.uniswapAddress (by native_decide) (by evm_ov) + have rd843 := rdPre.address (by native_decide) (by evm_ov) have rdPre2 := evm_run rd843 with [ raw swap1 (by native_decide) (by evm_ov), raw push2 ⟨853⟩ (by native_decide) (by evm_ov), @@ -1344,7 +1344,7 @@ set_option maxHeartbeats 1000000 in theorem potJoinX_depthLimitReverts {cA σ'' I} {g : Sat256} {s0 : State} {k C : ℕ} {sel : UInt256} {mem : ByteArray} (hdepth : I.depth = 1024) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ'' (joinVatMasked σ'' I) ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ'' (joinVatMasked σ'' I) ≠ ⟨0⟩) (h : RD potBytecode I g s0 ⟨927⟩ (joinVatMasked σ'' I :: joinVatMasked σ'' I :: ⟨0⟩ :: ⟨128⟩ :: ⟨100⟩ :: ⟨128⟩ :: ⟨0⟩ :: ⟨228⟩ :: potMoveSelectorWord :: joinVatMasked σ'' I :: joinWadWord I :: ⟨301⟩ :: sel :: []) @@ -1353,7 +1353,7 @@ theorem potJoinX_depthLimitReverts {cA σ'' I} {g : Sat256} {s0 : State} {k C : (UInt256.ofNat 8) ByteArray.empty (cA, σ'') k C) : RDrev potBytecode g s0 := by obtain ⟨gasWord, k1, C1, rd942⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨927⟩) (okPc := ⟨939⟩) h hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨927⟩) (okPc := ⟨939⟩) h hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1813,16 +1813,16 @@ theorem addrOfUInt256_eq_ofNat (w : UInt256) : theorem joinExtCodeAgree (σ'' : AccountMap) (evm2 : EVM.State) (I : ExecutionEnv) (hAcc : accountMapEquiv σ'' evm2.accountMap) (hvat : joinVatRaw σ'' I = Solm.EVM.storageLoad evm2 I.codeOwner ⟨5⟩) : - uniswapExtCodeSizeWord σ'' (joinVatMasked σ'' I) + extCodeSizeWord σ'' (joinVatMasked σ'' I) = UInt256.ofNat ((evm2.lookupAccount (AccountAddress.ofNat (UInt256.land (Solm.EVM.storageLoad evm2 I.codeOwner ⟨5⟩) solcAddrMask).toNat)).option 0 (fun acc => acc.code.size)) := by - rw [uniswapExtCodeSizeWord_accountMapEquiv hAcc] + rw [extCodeSizeWord_accountMapEquiv hAcc] have htgt : AccountAddress.ofUInt256 (joinVatMasked σ'' I) = AccountAddress.ofNat (UInt256.land (Solm.EVM.storageLoad evm2 I.codeOwner ⟨5⟩) solcAddrMask).toNat := by rw [joinVatMasked, hvat, addrOfUInt256_eq_ofNat] - rw [uniswapExtCodeSizeWord, htgt] + rw [extCodeSizeWord, htgt] simp only [State.lookupAccount] cases evm2.accountMap.find? (AccountAddress.ofNat (UInt256.land (Solm.EVM.storageLoad evm2 I.codeOwner ⟨5⟩) solcAddrMask).toNat) <;> rfl @@ -1831,12 +1831,12 @@ theorem joinExtCodeAgree (σ'' : AccountMap) (evm2 : EVM.State) (I : ExecutionEn theorem joinExtCodeNe (σ'' : AccountMap) (evm2 : EVM.State) (I : ExecutionEnv) (hAcc : accountMapEquiv σ'' evm2.accountMap) (hvat : joinVatRaw σ'' I = Solm.EVM.storageLoad evm2 I.codeOwner ⟨5⟩) - (hne : uniswapExtCodeSizeWord σ'' (joinVatMasked σ'' I) ≠ ⟨0⟩) : + (hne : extCodeSizeWord σ'' (joinVatMasked σ'' I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm2.lookupAccount (AccountAddress.ofNat (UInt256.land (Solm.EVM.storageLoad evm2 I.codeOwner ⟨5⟩) solcAddrMask).toNat)).option 0 (fun acc => acc.code.size))).toNat := by rw [← joinExtCodeAgree σ'' evm2 I hAcc hvat] - rcases Nat.eq_zero_or_pos (uniswapExtCodeSizeWord σ'' (joinVatMasked σ'' I)).toNat with h | h + rcases Nat.eq_zero_or_pos (extCodeSizeWord σ'' (joinVatMasked σ'' I)).toNat with h | h · exact absurd (u256_inj (by rw [h]; rfl)) hne · exact h @@ -1844,7 +1844,7 @@ theorem joinExtCodeNe (σ'' : AccountMap) (evm2 : EVM.State) (I : ExecutionEnv) theorem joinExtCodeEq (σ'' : AccountMap) (evm2 : EVM.State) (I : ExecutionEnv) (hAcc : accountMapEquiv σ'' evm2.accountMap) (hvat : joinVatRaw σ'' I = Solm.EVM.storageLoad evm2 I.codeOwner ⟨5⟩) - (heq : uniswapExtCodeSizeWord σ'' (joinVatMasked σ'' I) = ⟨0⟩) : + (heq : extCodeSizeWord σ'' (joinVatMasked σ'' I) = ⟨0⟩) : (UInt256.ofNat ((evm2.lookupAccount (AccountAddress.ofNat (UInt256.land (Solm.EVM.storageLoad evm2 I.codeOwner ⟨5⟩) solcAddrMask).toNat)).option 0 (fun acc => acc.code.size))).toNat = 0 := by @@ -2082,7 +2082,7 @@ theorem potJoinBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} twoWordHashMem_read64 (joinCallerWord I) ⟨1⟩ (joinPieHashMem_size I) (joinPieHashMem_read64 I) obtain ⟨_, _, rd927⟩ := potJoinX_callGuard hmemSz hmemR64 rd853 - by_cases hEcs : uniswapExtCodeSizeWord (joinSigma'' σ_evm I) + by_cases hEcs : extCodeSizeWord (joinSigma'' σ_evm I) (joinVatMasked (joinSigma'' σ_evm I) I) = ⟨0⟩ · -- extcodesize(vat) = 0 ⇒ both revert at the `extcodesize` guard refine (potJoinX_ecsZero hEcs rd927).reEquivExecutionRevert hcode hdispatch diff --git a/Benchmarks/Dss/Pot/Rpow.lean b/Benchmarks/Dss/Pot/Rpow.lean index 6831bfaf..2e718ce6 100644 --- a/Benchmarks/Dss/Pot/Rpow.lean +++ b/Benchmarks/Dss/Pot/Rpow.lean @@ -838,7 +838,7 @@ theorem RD.potDripRpowLoopRevertXX have heqCond : UInt256.eq (UInt256.div (x * x) x) x = ⟨0⟩ := u256_eq_of_ne hdivNe have rdFallthrough := rd2413.jumpiNT (by native_decide) heqCond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -899,7 +899,7 @@ theorem RD.potDripRpowLoopRevertXXRound rw [hlt] native_decide have rdFallthrough := rd2429.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1065,7 +1065,7 @@ theorem RD.potDripRpowLoopRevertZX raw iszero (by native_decide) (by evm_ov), raw push2 ⟨2472⟩ (by native_decide) (by evm_ov)] have rdFallthrough := rd2467.jumpiNT (by native_decide) hmulGuardFail (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -1157,7 +1157,7 @@ theorem RD.potDripRpowLoopRevertZXRound rw [hlt] native_decide have rdFallthrough := rd2483.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) diff --git a/Benchmarks/Dss/Pot/SpecSyntax.lean b/Benchmarks/Dss/Pot/SpecSyntax.lean index 8fd4201e..76c47fab 100644 --- a/Benchmarks/Dss/Pot/SpecSyntax.lean +++ b/Benchmarks/Dss/Pot/SpecSyntax.lean @@ -2,113 +2,204 @@ import Benchmarks.Dss.Pot.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS Pot spec through the Solm notation frontend +# Pot spec in the Solidity-faithful Solm frontend -This file exposes a notation-side presentation for representative parts of the Pot scaffold covered -by the current Solm frontend, and checks by `rfl` that they are definitionally equal to the AST spec -in `Benchmarks.Dss.Pot.Spec`. +The whole `pot.sol` spec written with `solidity%` and proven definitionally equal to the AST spec +in `Spec.lean`. Checked-math helpers are inlined (`_rmul` keeps its `_mul` internal call, as in +the AST); the assembly `_rpow` loop is the structural while-loop; `extCodeSize` guards on the +storage `vat` receiver use the `${…}` escape. Transition order matches `contract.transitions` +(selector order). -/ -open Solm Solm.Notation +open Solm Solm.Notation Benchmarks.Dss.Pot namespace Benchmarks.Dss.Pot.Syntax -def storageDeclsSyntax : List StorageDecl := - sState% { - (address => uint256) wards - (address => uint256) pie - } ++ - [ { name := "Pie", ty := uint256St }, - { name := "dsr", ty := uint256St }, - { name := "chi", ty := uint256St }, - { name := "vat", ty := addrSt }, - { name := "vow", ty := addrSt }, - { name := "rho", ty := uint256St }, - { name := "live", ty := uint256St } ] - -def relyTransitionSyntax : TransitionDecl := - { name := "rely" - params := [{ name := "guy", ty := addr }] - returnType := [] - body := sBlock% { - require msg.value == 0 - require @wards[msg.sender] == 1 - @wards[guy] := 1 - } } - -def denyTransitionSyntax : TransitionDecl := - { name := "deny" - params := [{ name := "guy", ty := addr }] - returnType := [] - body := sBlock% { - require msg.value == 0 - require @wards[msg.sender] == 1 - @wards[guy] := 0 - } } - -def dsrTransitionSyntax : TransitionDecl := - { name := "dsr" - params := [] - returnType := [uint256] - body := sBlock% { - require msg.value == 0 - return @dsr - } } - -def vowTransitionSyntax : TransitionDecl := - { name := "vow" - params := [] - returnType := [addr] - body := sBlock% { - require msg.value == 0 - return @vow - } } - -def transitionsSyntax : List TransitionDecl := - [ PieTransition, - cageTransition, - chiTransition, - denyTransitionSyntax, - dripTransition, - dsrTransitionSyntax, - exitTransition, - fileDsrTransition, - fileVowTransition, - joinTransition, - liveTransition, - pieTransition, - relyTransitionSyntax, - rhoTransition, - vatTransition, - vowTransitionSyntax, - wardsTransition ] - -def contractSyntax : ContractDecl := - { name := "Pot" - storage := storageDeclsSyntax - ctor := constructorDecl - functions := functions - transitions := transitionsSyntax } - -theorem storageDeclsSyntax_eq : storageDeclsSyntax = Benchmarks.Dss.Pot.storageDecls := by - rfl - -theorem relyTransitionSyntax_eq : relyTransitionSyntax = Benchmarks.Dss.Pot.relyTransition := by - rfl - -theorem denyTransitionSyntax_eq : denyTransitionSyntax = Benchmarks.Dss.Pot.denyTransition := by - rfl - -theorem dsrTransitionSyntax_eq : dsrTransitionSyntax = Benchmarks.Dss.Pot.dsrTransition := by - rfl - -theorem vowTransitionSyntax_eq : vowTransitionSyntax = Benchmarks.Dss.Pot.vowTransition := by - rfl - -theorem transitionsSyntax_eq : transitionsSyntax = Benchmarks.Dss.Pot.transitions := by - rfl - -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Pot.contract := by - rfl +def contractSyntax : ContractDecl := solidity% contract Pot { + mapping(address => uint256) wards; + mapping(address => uint256) pie; + uint256 Pie; + uint256 dsr; + uint256 chi; + address vat; + address vow; + uint256 rho; + uint256 live; + + constructor(address vat_) { + wards[msg.sender] = 1; + vat = vat_; + dsr = #one; + chi = #one; + rho = block.timestamp; + live = 1; + } + + function _add(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x + y) as uint256; + require(z >= x); + return z; + } + + function _sub(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x - y) as uint256; + require(z <= x); + return z; + } + + function _mul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + return z; + } + + function _rmul(uint256 x, uint256 y) internal returns (uint256) { + var z = _mul(x, y); + z = z / #one; + return z; + } + + function _rpow(uint256 x, uint256 n, uint256 base) internal returns (uint256) { + if (x == 0) { + if (n == 0) { + return base; + } else { + return 0; + } + } else { + uint256 z = n % 2 == 0 ? base : x; + uint256 half = base / 2; + n = n / 2; + while (n != 0) { + uint256 xx = (x * x) as uint256; + require(x == 0 || xx / x == x); + uint256 xxRound = (xx + half) as uint256; + require(xxRound >= xx); + x = xxRound / base; + if (n % 2 != 0) { + uint256 zx = (z * x) as uint256; + require(x == 0 || zx / x == z); + uint256 zxRound = (zx + half) as uint256; + require(zxRound >= zx); + z = zxRound / base; + } + n = n / 2; + } + return z; + } + } + + function Pie() external returns (uint256) { + return Pie; + } + + function cage() external { + require(wards[msg.sender] == 1); + live = 0; + dsr = #one; + } + + function chi() external returns (uint256) { + return chi; + } + + function deny(address guy) external { + require(wards[msg.sender] == 1); + wards[guy] = 0; + } + + function drip() external returns (uint256) { + require(block.timestamp >= rho); + var pow = _rpow(dsr, (block.timestamp - rho) as uint256, #one); + var tmp = _rmul(pow, chi); + var chi_ = _sub(tmp, chi); + chi = tmp; + rho = block.timestamp; + var rad = _mul(Pie, chi_); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _suckRet = vat.suck(vow, address(this), rad); + return tmp; + } + + function dsr() external returns (uint256) { + return dsr; + } + + function exit(uint256 wad) external { + uint256 pieNew = (pie[msg.sender] - wad) as uint256; + require(pieNew <= pie[msg.sender]); + pie[msg.sender] = pieNew; + uint256 PieNew = (Pie - wad) as uint256; + require(PieNew <= Pie); + Pie = PieNew; + var rad = _mul(chi, wad); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _moveRet = vat.move(address(this), msg.sender, rad); + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + require(live == 1); + require(block.timestamp == rho); + if (what == bytes32(0x6473720000000000000000000000000000000000000000000000000000000000)) { + dsr = data; + } else { + require(false); + } + } + + function file(bytes32 what, address addr) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x766f770000000000000000000000000000000000000000000000000000000000)) { + vow = addr; + } else { + require(false); + } + } + + function join(uint256 wad) external { + require(block.timestamp == rho); + uint256 pieNew = (pie[msg.sender] + wad) as uint256; + require(pieNew >= pie[msg.sender]); + pie[msg.sender] = pieNew; + uint256 PieNew = (Pie + wad) as uint256; + require(PieNew >= Pie); + Pie = PieNew; + var rad = _mul(chi, wad); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _moveRet = vat.move(msg.sender, address(this), rad); + } + + function live() external returns (uint256) { + return live; + } + + function pie(address arg0) external returns (uint256) { + return pie[arg0]; + } + + function rely(address guy) external { + require(wards[msg.sender] == 1); + wards[guy] = 1; + } + + function rho() external returns (uint256) { + return rho; + } + + function vat() external returns (address) { + return vat; + } + + function vow() external returns (address) { + return vow; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Pot.contract := by rfl end Benchmarks.Dss.Pot.Syntax diff --git a/Benchmarks/Dss/Spot/Dispatch.lean b/Benchmarks/Dss/Spot/Dispatch.lean index 122874f3..b85a65f4 100644 --- a/Benchmarks/Dss/Spot/Dispatch.lean +++ b/Benchmarks/Dss/Spot/Dispatch.lean @@ -393,7 +393,7 @@ theorem spotJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : UInt2 have h180 := h.push2 spotDispatchRevertPc hpush (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h180 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h180 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem spotLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -417,7 +417,7 @@ theorem spotLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} |>.selectorArmNotTakenAuto (spotLowArmsWellFormed 5 (by omega)) (heq0 5 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h180 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h180 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem spotHighNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -451,7 +451,7 @@ theorem spotX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem spotX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -474,7 +474,7 @@ theorem spotX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h180 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h180 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem spotX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} diff --git a/Benchmarks/Dss/Spot/Poke.lean b/Benchmarks/Dss/Spot/Poke.lean index 09c4f67d..755ce73e 100644 --- a/Benchmarks/Dss/Spot/Poke.lean +++ b/Benchmarks/Dss/Spot/Poke.lean @@ -25,9 +25,9 @@ theorem spotPokeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} obtain ⟨_, _, rd598⟩ := spotPokeX_decoded (g := Sat256.ofUInt256 g) hsz36 hsize hreach by_cases hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (pokePipTargetWord σ_evm I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_evm (pokePipTargetWord σ_evm I) = ⟨0⟩ · have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (pokePipTargetWord σ_solm I) = ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (pokePipTargetWord σ_solm I) = ⟨0⟩ := pokePipCodeSize_zero_accountMapEquiv hsz36 hAccounts hcodeSize have hpipNoCodeSolm : (UInt256.ofNat @@ -48,7 +48,7 @@ theorem spotPokeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} · obtain ⟨gasWord, _, _, rd679⟩ := RD.spotPokePeekCallReady hsz36 rd598 hcodeSize have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (pokePipTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (pokePipTargetWord σ_solm I) ≠ ⟨0⟩ := pokePipCodeSize_ne_zero_accountMapEquiv hsz36 hAccounts hcodeSize have hpipCodeSolm : 0 < @@ -198,9 +198,9 @@ theorem spotPokeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} substate := A'_solm createdAccounts := cA' } by_cases hvatCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (pokeVatTargetWord σ' I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ' (pokeVatTargetWord σ' I) = ⟨0⟩ · have hvatCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (pokeVatTargetWord σ'_solm I) = ⟨0⟩ := pokeVatCodeSize_zero_accountMapEquiv hAccounts' hvatCodeSize have hvatNoCodeSolm : @@ -295,7 +295,7 @@ theorem spotPokeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (typedCallViaEVM_zero_substate_irrel (evm := evmPipS) (A0 := A') hfileCallSolmAligned hfileDepth) have hvatCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (pokeVatTargetWord σ'_solm I) ≠ ⟨0⟩ := pokeVatCodeSize_ne_zero_accountMapEquiv hAccounts' hvatCodeSize have hvatCodeSolm : @@ -559,10 +559,10 @@ theorem spotPokeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} hvalScaled (by simpa [val] using hfitVal) hfitPar hparNeS hspot1S hfitMat hmatNeS hspot2S by_cases hvatCodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' + Reasoning.Theory.extCodeSizeWord σ' (pokeVatTargetWord σ' I) = ⟨0⟩ · have hvatCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (pokeVatTargetWord σ'_solm I) = ⟨0⟩ := pokeVatCodeSize_zero_accountMapEquiv hAccounts' hvatCodeSize have hvatNoCodeSolm : @@ -683,7 +683,7 @@ theorem spotPokeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (evm := evmPipS) (A0 := A') hfileCallSolmAligned hfileDepth) have hvatCodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_solm + Reasoning.Theory.extCodeSizeWord σ'_solm (pokeVatTargetWord σ'_solm I) ≠ ⟨0⟩ := pokeVatCodeSize_ne_zero_accountMapEquiv hAccounts' hvatCodeSize have hvatCodeSolm : diff --git a/Benchmarks/Dss/Spot/PokeCalls.lean b/Benchmarks/Dss/Spot/PokeCalls.lean index 06066981..e4791c48 100644 --- a/Benchmarks/Dss/Spot/PokeCalls.lean +++ b/Benchmarks/Dss/Spot/PokeCalls.lean @@ -146,10 +146,10 @@ theorem pokePipAddress_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} theorem pokePipCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (pokePipTargetWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (pokePipTargetWord τ I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (pokePipTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (pokePipTargetWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (pokePipTargetWord σ I) have htarget : pokePipTargetWord σ I = pokePipTargetWord τ I := pokePipTargetWord_accountMapEquiv hsz36 hAccounts @@ -159,8 +159,8 @@ theorem pokePipCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execution theorem pokePipCodeSize_ne_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (pokePipTargetWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (pokePipTargetWord τ I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (pokePipTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (pokePipTargetWord τ I) ≠ ⟨0⟩ := by intro hzero exact hne (pokePipCodeSize_zero_accountMapEquiv hsz36 hAccounts.symm hzero) @@ -201,10 +201,10 @@ theorem pokeVatAddress_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} theorem pokeVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (pokeVatTargetWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (pokeVatTargetWord τ I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (pokeVatTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (pokeVatTargetWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (pokeVatTargetWord σ I) have htarget : pokeVatTargetWord σ I = pokeVatTargetWord τ I := pokeVatTargetWord_accountMapEquiv hAccounts @@ -214,8 +214,8 @@ theorem pokeVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execution theorem pokeVatCodeSize_ne_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (pokeVatTargetWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (pokeVatTargetWord τ I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (pokeVatTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (pokeVatTargetWord τ I) ≠ ⟨0⟩ := by intro hzero exact hne (pokeVatCodeSize_zero_accountMapEquiv hAccounts.symm hzero) @@ -232,14 +232,14 @@ theorem pokeVatEvmAddress_eq_target_of_accountMapEquiv {σ_evm σ_solm : Account rw [haddr, pokeVatAddress_eq_target σ_evm I] exact spotEvmAddress_accountAddress _ -theorem poke_uniswapExtCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} +theorem poke_extCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using @@ -250,18 +250,18 @@ theorem poke_uniswapExtCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {tar theorem pokePipCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt256} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (pokePipTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (pokePipTargetWord σ I) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (pokePipAddress σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [initState, State.lookupAccount] using - poke_uniswapExtCodeSizeWord_zero_lookup_code_zero + poke_extCodeSizeWord_zero_lookup_code_zero (σ := σ) (target := pokePipTargetWord σ I) (addr := pokePipAddress σ I) (pokePipAddress_eq_target σ I) hzero theorem pokePipCode_pos_of_codeSize_ne_zero {cA gh bl σ σ₀ A I} {g : UInt256} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (pokePipTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (pokePipTargetWord σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount @@ -281,29 +281,29 @@ theorem pokePipCode_pos_of_codeSize_ne_zero {cA gh bl σ σ₀ A I} {g : UInt256 UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (pokePipAddress σ I)).option 0 (fun acc => acc.code.size)) = - Reasoning.Theory.uniswapExtCodeSizeWord σ (pokePipTargetWord σ I) := by + Reasoning.Theory.extCodeSizeWord σ (pokePipTargetWord σ I) := by cases hacc : σ.find? (AccountAddress.ofUInt256 (pokePipTargetWord σ I)) <;> - simp [initState, State.lookupAccount, Reasoning.Theory.uniswapExtCodeSizeWord, + simp [initState, State.lookupAccount, Reasoning.Theory.extCodeSizeWord, pokePipAddress_eq_target σ I, hacc, Option.option] <;> native_decide exact hne (by rw [← hword, hwordZero]) theorem pokeVatCode_zero_of_codeSize_zero {evm : EVM.State} (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (pokeVatTargetWord evm.accountMap evm.executionEnv) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (pokeVatAddress evm.accountMap evm.executionEnv)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [State.lookupAccount] using - poke_uniswapExtCodeSizeWord_zero_lookup_code_zero + poke_extCodeSizeWord_zero_lookup_code_zero (σ := evm.accountMap) (target := pokeVatTargetWord evm.accountMap evm.executionEnv) (addr := pokeVatAddress evm.accountMap evm.executionEnv) (pokeVatAddress_eq_target evm.accountMap evm.executionEnv) hzero theorem pokeVatCode_pos_of_codeSize_ne_zero {evm : EVM.State} (hne : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (pokeVatTargetWord evm.accountMap evm.executionEnv) ≠ ⟨0⟩) : 0 < (UInt256.ofNat @@ -324,13 +324,13 @@ theorem pokeVatCode_pos_of_codeSize_ne_zero {evm : EVM.State} UInt256.ofNat ((evm.lookupAccount (pokeVatAddress evm.accountMap evm.executionEnv)).option 0 (fun acc => acc.code.size)) = - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (pokeVatTargetWord evm.accountMap evm.executionEnv) := by cases hacc : evm.accountMap.find? (AccountAddress.ofUInt256 (pokeVatTargetWord evm.accountMap evm.executionEnv)) <;> - simp [State.lookupAccount, Reasoning.Theory.uniswapExtCodeSizeWord, + simp [State.lookupAccount, Reasoning.Theory.extCodeSizeWord, pokeVatAddress_eq_target evm.accountMap evm.executionEnv, hacc, Option.option] <;> native_decide exact hne (by rw [← hword, hwordZero]) diff --git a/Benchmarks/Dss/Spot/PokeTraceBody.lean b/Benchmarks/Dss/Spot/PokeTraceBody.lean index 355fc252..0e7256e9 100644 --- a/Benchmarks/Dss/Spot/PokeTraceBody.lean +++ b/Benchmarks/Dss/Spot/PokeTraceBody.lean @@ -150,10 +150,10 @@ theorem RD.spotPokePeekNoCode [pokeIlkWord I, ⟨214⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (pokePipTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (pokePipTargetWord σ I) = ⟨0⟩) : RDrev spotBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd664⟩ := RD.spotPokeToPeekExtcodesizeGuard hsz36 rd598 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨664⟩) (okPc := ⟨676⟩) rd664 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨664⟩) (okPc := ⟨676⟩) rd664 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -167,7 +167,7 @@ theorem RD.spotPokePeekCallReady [pokeIlkWord I, ⟨214⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (pokePipTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (pokePipTargetWord σ I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD spotBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨679⟩ (gasWord :: pokePipTargetWord σ I :: ⟨0⟩ :: pokePeekOutPtr :: @@ -177,7 +177,7 @@ theorem RD.spotPokePeekCallReady (pokePeekCalldataMem I) (UInt256.ofNat 5) ByteArray.empty (cA, σ) k' C' := by obtain ⟨_, _, rd664⟩ := RD.spotPokeToPeekExtcodesizeGuard hsz36 rd598 obtain ⟨gasWord, k', C', rd679⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨664⟩) (okPc := ⟨676⟩) rd664 + RD.solcExtcodesizeGuardOkGas (pc := ⟨664⟩) (okPc := ⟨676⟩) rd664 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -269,7 +269,7 @@ theorem RD.spotPokePeekCallFailed mem (UInt256.ofNat 6) rdata (cA', σ') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev spotBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨680⟩) (okPc := ⟨696⟩) rd680 + exact RD.solcCallSuccessGuardMissing (pc := ⟨680⟩) (okPc := ⟨696⟩) rd680 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -290,7 +290,7 @@ theorem RD.spotPokePeekCallSucceeded (pokePeekEndPtr :: pokePeekSelectorPlainWord :: pokePipTargetWord σ I :: ⟨0⟩ :: ⟨0⟩ :: pokeIlkWord I :: ⟨214⟩ :: sel :: []) mem (UInt256.ofNat 6) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨680⟩) (okPc := ⟨696⟩) rd680 + exact RD.solcCallSuccessGuardOk (pc := ⟨680⟩) (okPc := ⟨696⟩) rd680 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -343,7 +343,7 @@ theorem RD.spotPokePeekReturnDecodeShortReverts decide have rdFallthrough := RD.jumpiNT rdPushOk (by native_decide) hcond (by simp only [List.length_cons, List.length_nil]; omega) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -593,7 +593,7 @@ theorem RD.spotCheckedMulOverflowReverts have heqCond : UInt256.eq (UInt256.div (x * y) y) x = ⟨0⟩ := u256_eq_of_ne hdivNe have rdFallthrough := rd2082.jumpiNT (by native_decide) heqCond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -979,7 +979,7 @@ theorem RD.spotPokeVatFileCallReady (hmem : mem.size = 192) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (pokeVatTargetWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (pokeVatTargetWord σ' I) ≠ ⟨0⟩) (rd798 : RD spotBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨798⟩ (spot :: scratch :: has :: val :: pokeIlkWord I :: ⟨214⟩ :: sel :: []) @@ -993,7 +993,7 @@ theorem RD.spotPokeVatFileCallReady (pokeVatFileCalldataMem I spot mem) (UInt256.ofNat 8) out (cA', σ') k' C' := by obtain ⟨_, _, rd886⟩ := RD.spotPokeVatFileCallGuard hmem hread64 rd798 obtain ⟨gasWord, k', C', rd901⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨886⟩) (okPc := ⟨898⟩) rd886 + RD.solcExtcodesizeGuardOkGas (pc := ⟨886⟩) (okPc := ⟨898⟩) rd886 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1006,14 +1006,14 @@ theorem RD.spotPokeVatFileNoCode (hmem : mem.size = 192) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (pokeVatTargetWord σ' I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (pokeVatTargetWord σ' I) = ⟨0⟩) (rd798 : RD spotBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨798⟩ (spot :: scratch :: has :: val :: pokeIlkWord I :: ⟨214⟩ :: sel :: []) mem (UInt256.ofNat 6) out (cA', σ') k C) : RDrev spotBytecode g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd886⟩ := RD.spotPokeVatFileCallGuard hmem hread64 rd798 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨886⟩) (okPc := ⟨898⟩) rd886 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨886⟩) (okPc := ⟨898⟩) rd886 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1079,7 +1079,7 @@ theorem RD.spotPokeVatFileCallFailed mem (UInt256.ofNat 8) rdata (cA'', σ'') k C) (hrdataSize : rdata.size < UInt256.size) : RDrev spotBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨902⟩) (okPc := ⟨918⟩) rd902 + exact RD.solcCallSuccessGuardMissing (pc := ⟨902⟩) (okPc := ⟨918⟩) rd902 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1100,7 +1100,7 @@ theorem RD.spotPokeVatFileCallSucceeded (pokeVatFileEndPtr :: pokeVatFileSelectorPlainWord :: pokeVatTargetWord σ' I :: spot :: has :: val :: pokeIlkWord I :: ⟨214⟩ :: sel :: []) mem (UInt256.ofNat 8) rdata acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨902⟩) (okPc := ⟨918⟩) rd902 + exact RD.solcCallSuccessGuardOk (pc := ⟨902⟩) (okPc := ⟨918⟩) rd902 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Spot/SpecSyntax.lean b/Benchmarks/Dss/Spot/SpecSyntax.lean index 700553ed..4aaf2b19 100644 --- a/Benchmarks/Dss/Spot/SpecSyntax.lean +++ b/Benchmarks/Dss/Spot/SpecSyntax.lean @@ -2,105 +2,136 @@ import Benchmarks.Dss.Spot.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS Spotter spec through the Solm notation frontend +# Spotter spec in the Solidity-faithful Solm frontend -This file exposes a notation-side presentation for representative parts of the Spotter scaffold -covered by the current Solm frontend, and checks by `rfl` that they are definitionally equal to the -AST spec in `Benchmarks.Dss.Spot.Spec`. +The whole Spotter benchmark spec, written with `solidity%` and proven definitionally equal to the +AST spec in `Benchmarks/Dss/Spot/Spec.lean`. + +Escapes: the `"pip"`/`"par"`/`"mat"`/`"spot"` `bytes32` parameter literals are the spec's +`fixedBytesLit` defs; `poke`'s oracle call has an indexed-path receiver (`ilks[ilk].pip`), which +the surface method-call syntax cannot express, so that require+call pair is spliced with the +spec's own `checkedExternalCallStmts` (its `peekRet` binder is then referenced via `${…}`). +Transition order matches `contract.transitions`. -/ open Solm Solm.Notation namespace Benchmarks.Dss.Spot.Syntax -def storageDeclsSyntax : List StorageDecl := - sState% { - (address => uint256) wards - } ++ - [ { name := "ilks", ty := .mapping (.bytes bytes32Width) IlkStructTy }, - { name := "vat", ty := addrSt }, - { name := "par", ty := uint256St }, - { name := "live", ty := uint256St } ] - -def relyTransitionSyntax : TransitionDecl := - { name := "rely" - params := [{ name := "guy", ty := addr }] - returnType := [] - body := sBlock% { - require msg.value == 0 - require @wards[msg.sender] == 1 - @wards[guy] := 1 - } } - -def denyTransitionSyntax : TransitionDecl := - { name := "deny" - params := [{ name := "guy", ty := addr }] - returnType := [] - body := sBlock% { - require msg.value == 0 - require @wards[msg.sender] == 1 - @wards[guy] := 0 - } } - -def parTransitionSyntax : TransitionDecl := - { name := "par" - params := [] - returnType := [uint256] - body := sBlock% { - require msg.value == 0 - return @par - } } - -def liveTransitionSyntax : TransitionDecl := - { name := "live" - params := [] - returnType := [uint256] - body := sBlock% { - require msg.value == 0 - return @live - } } - -def transitionsSyntax : List TransitionDecl := - [ cageTransition, - denyTransitionSyntax, - fileMatTransition, - fileParTransition, - filePipTransition, - ilksTransition, - liveTransitionSyntax, - parTransitionSyntax, - pokeTransition, - relyTransitionSyntax, - vatTransition, - wardsTransition ] - -def contractSyntax : ContractDecl := - { name := "Spotter" - storage := storageDeclsSyntax - ctor := constructorDecl - structs := structs - functions := functions - transitions := transitionsSyntax } - -theorem storageDeclsSyntax_eq : storageDeclsSyntax = Benchmarks.Dss.Spot.storageDecls := by - rfl - -theorem relyTransitionSyntax_eq : relyTransitionSyntax = Benchmarks.Dss.Spot.relyTransition := by - rfl - -theorem denyTransitionSyntax_eq : denyTransitionSyntax = Benchmarks.Dss.Spot.denyTransition := by - rfl - -theorem parTransitionSyntax_eq : parTransitionSyntax = Benchmarks.Dss.Spot.parTransition := by - rfl - -theorem liveTransitionSyntax_eq : liveTransitionSyntax = Benchmarks.Dss.Spot.liveTransition := by - rfl - -theorem transitionsSyntax_eq : transitionsSyntax = Benchmarks.Dss.Spot.transitions := by - rfl - -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Spot.contract := by - rfl +def contractSyntax : ContractDecl := solidity% contract Spotter { + struct Ilk { + address pip; + uint256 mat; + } + + mapping(address => uint256) wards; + mapping(bytes32 => Ilk) ilks; + address vat; + uint256 par; + uint256 live; + + constructor(address vat_) { + wards[msg.sender] = 1; + vat = vat_; + par = #one; + live = 1; + } + + function mul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + return z; + } + + function rdiv(uint256 x, uint256 y) internal returns (uint256) { + var z = mul(x, #one); + z = z / y; + return z; + } + + function cage() external { + require(wards[msg.sender] == 1); + live = 0; + } + + function deny(address guy) external { + require(wards[msg.sender] == 1); + wards[guy] = 0; + } + + function file(bytes32 ilk, bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + require(live == 1); + if (what == ${matParamLit}) { + ilks[ilk].mat = data; + } else { + require(false); + } + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + require(live == 1); + if (what == ${parParamLit}) { + par = data; + } else { + require(false); + } + } + + function file(bytes32 ilk, bytes32 what, address pip_) external { + require(wards[msg.sender] == 1); + require(live == 1); + if (what == ${pipParamLit}) { + ilks[ilk].pip = pip_; + } else { + require(false); + } + } + + function ilks(bytes32 arg0) external returns (address, uint256) { + return (ilks[arg0].pip, ilks[arg0].mat); + } + + function live() external returns (uint256) { + return live; + } + + function par() external returns (uint256) { + return par; + } + + function poke(bytes32 ilk) external { + ${checkedExternalCallStmts (.storage (ilksF (.var "ilk") "pip")) "peek" (.intLit 0) [] + "peekRet"} + bytes32 val = ${Expr.tupleGet (Expr.var "peekRet") 0}; + bool has = ${Expr.tupleGet (Expr.var "peekRet") 1}; + uint256 spot = 0; + if (has) { + uint256 valScaled = (uint256(val) * #billion) as uint256; + require(#billion == 0 || valScaled / #billion == uint256(val)); + var spot1 = rdiv(valScaled, par); + var spot2 = rdiv(spot1, ilks[ilk].mat); + spot = spot2; + } + require(${Expr.extCodeSize (Expr.storage vatRef)} > 0); + var _fileRet = vat.file(ilk, ${spotParamLit}, spot); + } + + function rely(address guy) external { + require(wards[msg.sender] == 1); + wards[guy] = 1; + } + + function vat() external returns (address) { + return vat; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Spot.contract := by rfl end Benchmarks.Dss.Spot.Syntax diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Dispatch.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Dispatch.lean index a1bb41df..193ceedf 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Dispatch.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Dispatch.lean @@ -379,7 +379,7 @@ theorem stairstepJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h125 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h125 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem stairstepLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -400,7 +400,7 @@ theorem stairstepLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : |>.selectorArmNotTakenAuto (stairstepLowArmsWellFormed 2 (by omega)) (heq0 2 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h125 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h125 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem stairstepHighNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -433,7 +433,7 @@ theorem stairstepX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem stairstepX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -456,7 +456,7 @@ theorem stairstepX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h125 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h125 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem stairstepX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Price.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Price.lean index 0e34411f..3926115f 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Price.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Price.lean @@ -482,7 +482,7 @@ theorem stairstepPriceRmulRayOverflowReverts {cA σ I} {g : Sat256} {s0 : State} raw jumpdest (by native_decide) (by evm_ov), raw push2 ⟨1265⟩ (by native_decide) (by evm_ov), raw jumpiNT (by native_decide) rfl (by evm_ov)] - exact RD.uniswapPush1Dup1Revert0 rd1261pre + exact RD.solcPush1Dup1Revert0 rd1261pre (by native_decide) (by native_decide) (by native_decide) (by evm_ov) set_option maxHeartbeats 1000000 in @@ -624,7 +624,7 @@ theorem stairstepPriceRmulOverflowReverts {cA σ I} {g : Sat256} {s0 : State} raw jumpdest (by native_decide) (by evm_ov), raw push2 ⟨1265⟩ (by native_decide) (by evm_ov), raw jumpiNT (by native_decide) rfl (by evm_ov)] - exact RD.uniswapPush1Dup1Revert0 rd1261pre + exact RD.solcPush1Dup1Revert0 rd1261pre (by native_decide) (by native_decide) (by native_decide) (by evm_ov) set_option maxHeartbeats 1000000 in diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/RpowEVM.lean b/Benchmarks/Dss/StairstepExponentialDecrease/RpowEVM.lean index 4c85d2d8..3dedbde7 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/RpowEVM.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/RpowEVM.lean @@ -281,7 +281,7 @@ theorem RD.stairstepRpowLoopRevertXX have hcond : UInt256.isZero (UInt256.shiftRight x (⟨128⟩ : UInt256)) = ⟨0⟩ := isZero_eq_zero_of_ne (rpowShiftRight128_ne_zero_of_square_overflow x hover) have rdFallthrough := rd1110pre.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -328,7 +328,7 @@ theorem RD.stairstepRpowLoopRevertXXRound rw [hlt] native_decide have rdFallthrough := rd1126pre.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -479,7 +479,7 @@ theorem RD.stairstepRpowLoopRevertZX raw iszero (by native_decide) (by evm_ov), raw push2 ⟨1169⟩ (by native_decide) (by evm_ov)] have rdFallthrough := rd1164pre.jumpiNT (by native_decide) hmulGuardFail (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -571,7 +571,7 @@ theorem RD.stairstepRpowLoopRevertZXRound rw [hlt] native_decide have rdFallthrough := rd1180pre.jumpiNT (by native_decide) hcond (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/SpecSyntax.lean b/Benchmarks/Dss/StairstepExponentialDecrease/SpecSyntax.lean index 7feec402..8ae06b9a 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/SpecSyntax.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/SpecSyntax.lean @@ -2,19 +2,109 @@ import Benchmarks.Dss.StairstepExponentialDecrease.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS StairstepExponentialDecrease spec through the Solm notation frontend +# StairstepExponentialDecrease spec in the Solidity-faithful Solm frontend -The main spec lives in `Spec.lean`; this companion keeps the benchmark's notation-side check wired -up as the body surface grows. +The whole `abaci.sol` `StairstepExponentialDecrease` spec (including the `rpow` while-loop and +the two-way `file`) written with `solidity%` and proven definitionally equal to the AST spec in +`Spec.lean`. Checked-math helpers are inlined; `"cut"`/`"step"` are big-endian `bytes32` +literals; `#RAY` is the spec's `RAY` constant. Transition order matches `contract.transitions`. -/ -open Solm Solm.Notation +open Solm Solm.Notation Benchmarks.Dss.StairstepExponentialDecrease namespace Benchmarks.Dss.StairstepExponentialDecrease.Syntax -def contractSyntax : ContractDecl := Benchmarks.Dss.StairstepExponentialDecrease.contract +def contractSyntax : ContractDecl := solidity% contract StairstepExponentialDecrease { + mapping(address => uint256) wards; + uint256 step; + uint256 cut; -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.StairstepExponentialDecrease.contract := by - rfl + constructor() { + wards[msg.sender] = 1; + } + + function rmul(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x * y) as uint256; + require(y == 0 || z / y == x); + z = z / #RAY; + return z; + } + + function rpow(uint256 x, uint256 n, uint256 b) internal returns (uint256) { + if (n == 0) { + return b; + } else { + if (x == 0) { + return 0; + } else { + uint256 z = n % 2 == 0 ? b : x; + uint256 half = b / 2; + n = n / 2; + while (n != 0) { + uint256 xx = (x * x) as uint256; + require(x == 0 || xx / x == x); + uint256 xxRound = (xx + half) as uint256; + require(xxRound >= xx); + x = xxRound / b; + if (n % 2 != 0) { + uint256 zx = (z * x) as uint256; + require(x == 0 || zx / x == z); + uint256 zxRound = (zx + half) as uint256; + require(zxRound >= zx); + z = zxRound / b; + } + n = n / 2; + } + return z; + } + } + } + + function cut() external returns (uint256) { + return cut; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x6375740000000000000000000000000000000000000000000000000000000000)) { + cut = data; + require(data <= #RAY); + } else { + if (what == bytes32(0x7374657000000000000000000000000000000000000000000000000000000000)) { + step = data; + } else { + require(false); + } + } + } + + function price(uint256 top, uint256 dur) external returns (uint256) { + uint256 n = dur / step; + var pow = rpow(cut, n, #RAY); + var out = rmul(top, pow); + return out; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 1; + } + + function step() external returns (uint256) { + return step; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } +} + +theorem contractSyntax_eq : + contractSyntax = Benchmarks.Dss.StairstepExponentialDecrease.contract := by rfl end Benchmarks.Dss.StairstepExponentialDecrease.Syntax diff --git a/Benchmarks/Dss/Vat/Common.lean b/Benchmarks/Dss/Vat/Common.lean index cffcf138..19a80e15 100644 --- a/Benchmarks/Dss/Vat/Common.lean +++ b/Benchmarks/Dss/Vat/Common.lean @@ -1080,7 +1080,7 @@ theorem RD.vatSignedMulRevert {g : Sat256} {s0 : State} rw [hcond] at rd6718pre simpa [prod] using rd6718pre.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd6719 + exact RD.solcPush1Dup1Revert0 rd6719 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) · have rd6723 := by @@ -1120,7 +1120,7 @@ theorem RD.vatSignedMulRevert {g : Sat256} {s0 : State} exact hmulFail (Or.inr (by simpa [prod] using heqNe)) have rd6748 := by simpa [prod] using rd6747.jumpiNT (by native_decide) heq0 (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd6748 + exact RD.solcPush1Dup1Revert0 rd6748 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -1272,7 +1272,7 @@ theorem RD.vatSignedSubRevert {g : Sat256} {s0 : State} have rd6818 := rd6815.push2 ⟨6823⟩ (by native_decide) (by evm_ov) have rd6819 := rd6818.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd6819 + exact RD.solcPush1Dup1Revert0 rd6819 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) · have hrd6814 : @@ -1333,7 +1333,7 @@ theorem RD.vatSignedSubRevert {g : Sat256} {s0 : State} rw [hltIsZero] at rd6842 have rd6843 := rd6842.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd6843 + exact RD.solcPush1Dup1Revert0 rd6843 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) diff --git a/Benchmarks/Dss/Vat/Dispatch.lean b/Benchmarks/Dss/Vat/Dispatch.lean index 89b4a3d8..f6dadbda 100644 --- a/Benchmarks/Dss/Vat/Dispatch.lean +++ b/Benchmarks/Dss/Vat/Dispatch.lean @@ -469,7 +469,7 @@ theorem vatJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : UInt25 have h452 := h.push2 vatDispatchRevertPc hpush (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h452 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h452 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem vatArms65NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -607,7 +607,7 @@ theorem vatArms419NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} |>.selectorArmNotTakenAuto (vatArms419WellFormed 2 (by omega)) (heq0 2 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h452 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h452 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem vatReachRootSplit {cA gh bl σ σ₀ A I} {g : Sat256} @@ -1520,7 +1520,7 @@ theorem vatX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem vatX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -1543,7 +1543,7 @@ theorem vatX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h452 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h452 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) end Benchmarks.Dss.Vat diff --git a/Benchmarks/Dss/Vat/Slip.lean b/Benchmarks/Dss/Vat/Slip.lean index bb82195e..24d87ac0 100644 --- a/Benchmarks/Dss/Vat/Slip.lean +++ b/Benchmarks/Dss/Vat/Slip.lean @@ -1131,7 +1131,7 @@ theorem RD.vatSignedAddRevertSecond {g : Sat256} {s0 : State} have rd6701 := rd6698.push2 ⟨6615⟩ (by native_decide) (by evm_ov) have rd6702 := rd6701.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd6702 + exact RD.solcPush1Dup1Revert0 rd6702 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -1240,7 +1240,7 @@ theorem RD.vatSignedAddRevert {g : Sat256} {s0 : State} have rd6676 := rd6673.push2 ⟨6681⟩ (by native_decide) (by evm_ov) have rd6677 := rd6676.jumpiNT (by native_decide) (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd6677 + exact RD.solcPush1Dup1Revert0 rd6677 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) · by_cases hyneg0 : UInt256.slt y ⟨0⟩ = ⟨0⟩ diff --git a/Benchmarks/Dss/Vat/SpecSyntax.lean b/Benchmarks/Dss/Vat/SpecSyntax.lean index 2f2ffac4..0c145e53 100644 --- a/Benchmarks/Dss/Vat/SpecSyntax.lean +++ b/Benchmarks/Dss/Vat/SpecSyntax.lean @@ -2,154 +2,354 @@ import Benchmarks.Dss.Vat.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS Vat spec through the Solm notation frontend +# Vat spec in the Solidity-faithful Solm frontend -This file exposes a notation-side presentation for representative parts of the Vat scaffold covered -by the current Solm frontend, and checks by `rfl` that they are definitionally equal to the AST spec -in `Benchmarks.Dss.Vat.Spec`. +The whole `vat.sol` spec written with `solidity%` and proven definitionally equal to the AST +spec in `Spec.lean`. Maker's checked-arithmetic helper statement lists are inlined: unsigned +add/sub/mul are the `as uint256` range checks, the signed variants wrap with +`% #(Int.ofNat EVM.wordModulus)` and check the sign conditions, and signed mul is the +`as int256` range check plus the `#maxInt256` bound. `wish` is the inline +`x == msg.sender || can[x][msg.sender] == 1`. `file` keys are big-endian `bytes32` ASCII +literals. Transition order matches `contract.transitions` (selector order). -/ -open Solm Solm.Notation +open Solm Solm.Notation Benchmarks.Dss.Vat namespace Benchmarks.Dss.Vat.Syntax -def storageDeclsSyntax : List StorageDecl := - sState% { - (address => uint256) wards - (address => (address => uint256)) can - } ++ - [ { name := "ilks", ty := .mapping (.bytes bytes32Width) IlkStructTy }, - { name := "urns", ty := .mapping (.bytes bytes32Width) (.mapping .address UrnStructTy) }, - { name := "gem", ty := .mapping (.bytes bytes32Width) (.mapping .address uint256St) }, - { name := "dai", ty := .mapping .address uint256St }, - { name := "sin", ty := .mapping .address uint256St }, - { name := "debt", ty := uint256St }, - { name := "vice", ty := uint256St }, - { name := "Line", ty := uint256St }, - { name := "live", ty := uint256St } ] - -def hopeTransitionSyntax : TransitionDecl := - { name := "hope" - params := [{ name := "usr", ty := addr }] - returnType := [] - body := sBlock% { - require msg.value == 0 - @can[msg.sender][usr] := 1 - } } - -def nopeTransitionSyntax : TransitionDecl := - { name := "nope" - params := [{ name := "usr", ty := addr }] - returnType := [] - body := sBlock% { - require msg.value == 0 - @can[msg.sender][usr] := 0 - } } - -def relyTransitionSyntax : TransitionDecl := - { name := "rely" - params := [{ name := "usr", ty := addr }] - returnType := [] - body := sBlock% { - require msg.value == 0 - require @wards[msg.sender] == 1 - require @live == 1 - @wards[usr] := 1 - } } - -def denyTransitionSyntax : TransitionDecl := - { name := "deny" - params := [{ name := "usr", ty := addr }] - returnType := [] - body := sBlock% { - require msg.value == 0 - require @wards[msg.sender] == 1 - require @live == 1 - @wards[usr] := 0 - } } - -def cageTransitionSyntax : TransitionDecl := - { name := "cage" - params := [] - returnType := [] - body := sBlock% { - require msg.value == 0 - require @wards[msg.sender] == 1 - @live := 0 - } } - -def liveTransitionSyntax : TransitionDecl := - { name := "live" - params := [] - returnType := [uint256] - body := sBlock% { - require msg.value == 0 - return @live - } } - -def transitionsSyntax : List TransitionDecl := - [ LineTransition, - cageTransitionSyntax, - canTransition, - daiTransition, - debtTransition, - denyTransitionSyntax, - fileIlkTransition, - fileLineTransition, - fluxTransition, - foldTransition, - forkTransition, - frobTransition, - gemTransition, - grabTransition, - healTransition, - hopeTransitionSyntax, - ilksTransition, - initTransition, - liveTransitionSyntax, - moveTransition, - nopeTransitionSyntax, - relyTransitionSyntax, - sinTransition, - slipTransition, - suckTransition, - urnsTransition, - viceTransition, - wardsTransition ] - -def contractSyntax : ContractDecl := - { name := "Vat" - storage := storageDeclsSyntax - ctor := constructorDecl - structs := structs - functions := [] - transitions := transitionsSyntax } - -theorem storageDeclsSyntax_eq : storageDeclsSyntax = Benchmarks.Dss.Vat.storageDecls := by - rfl - -theorem hopeTransitionSyntax_eq : hopeTransitionSyntax = Benchmarks.Dss.Vat.hopeTransition := by - rfl - -theorem nopeTransitionSyntax_eq : nopeTransitionSyntax = Benchmarks.Dss.Vat.nopeTransition := by - rfl - -theorem relyTransitionSyntax_eq : relyTransitionSyntax = Benchmarks.Dss.Vat.relyTransition := by - rfl - -theorem denyTransitionSyntax_eq : denyTransitionSyntax = Benchmarks.Dss.Vat.denyTransition := by - rfl - -theorem cageTransitionSyntax_eq : cageTransitionSyntax = Benchmarks.Dss.Vat.cageTransition := by - rfl - -theorem liveTransitionSyntax_eq : liveTransitionSyntax = Benchmarks.Dss.Vat.liveTransition := by - rfl - -theorem transitionsSyntax_eq : transitionsSyntax = Benchmarks.Dss.Vat.transitions := by - rfl - -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Vat.contract := by - rfl +def contractSyntax : ContractDecl := solidity% contract Vat { + struct Ilk { + uint256 Art; + uint256 rate; + uint256 spot; + uint256 line; + uint256 dust; + } + + struct Urn { + uint256 ink; + uint256 art; + } + + mapping(address => uint256) wards; + mapping(address => mapping(address => uint256)) can; + mapping(bytes32 => Ilk) ilks; + mapping(bytes32 => mapping(address => Urn)) urns; + mapping(bytes32 => mapping(address => uint256)) gem; + mapping(address => uint256) dai; + mapping(address => uint256) sin; + uint256 debt; + uint256 vice; + uint256 Line; + uint256 live; + + constructor() { + wards[msg.sender] = 1; + live = 1; + } + + function Line() external returns (uint256) { + return Line; + } + + function cage() external { + require(wards[msg.sender] == 1); + live = 0; + } + + function can(address arg0, address arg1) external returns (uint256) { + return can[arg0][arg1]; + } + + function dai(address arg0) external returns (uint256) { + return dai[arg0]; + } + + function debt() external returns (uint256) { + return debt; + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + require(live == 1); + wards[usr] = 0; + } + + function file(bytes32 ilk, bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + require(live == 1); + if (what == bytes32(0x73706f7400000000000000000000000000000000000000000000000000000000)) { + ilks[ilk].spot = data; + } else if (what == bytes32(0x6c696e6500000000000000000000000000000000000000000000000000000000)) { + ilks[ilk].line = data; + } else if (what == bytes32(0x6475737400000000000000000000000000000000000000000000000000000000)) { + ilks[ilk].dust = data; + } else { + require(false); + } + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + require(live == 1); + if (what == bytes32(0x4c696e6500000000000000000000000000000000000000000000000000000000)) { + Line = data; + } else { + require(false); + } + } + + function flux(bytes32 ilk, address src, address dst, uint256 wad) external { + require(src == msg.sender || can[src][msg.sender] == 1); + uint256 srcGemNew = (gem[ilk][src] - wad) as uint256; + require(srcGemNew <= gem[ilk][src]); + gem[ilk][src] = srcGemNew; + uint256 dstGemNew = (gem[ilk][dst] + wad) as uint256; + require(dstGemNew >= gem[ilk][dst]); + gem[ilk][dst] = dstGemNew; + } + + function fold(bytes32 i, address u, int256 rate) external { + require(wards[msg.sender] == 1); + require(live == 1); + uint256 rateNew = (ilks[i].rate + rate) % #(Int.ofNat EVM.wordModulus); + require(rate >= 0 || rateNew <= ilks[i].rate); + require(rate <= 0 || rateNew >= ilks[i].rate); + ilks[i].rate = rateNew; + int256 rad = (ilks[i].Art * rate) as int256; + require(ilks[i].Art <= #maxInt256); + require(rate == 0 || rad / rate == ilks[i].Art); + uint256 daiNew = (dai[u] + rad) % #(Int.ofNat EVM.wordModulus); + require(rad >= 0 || daiNew <= dai[u]); + require(rad <= 0 || daiNew >= dai[u]); + dai[u] = daiNew; + uint256 debtNew = (debt + rad) % #(Int.ofNat EVM.wordModulus); + require(rad >= 0 || debtNew <= debt); + require(rad <= 0 || debtNew >= debt); + debt = debtNew; + } + + function fork(bytes32 ilk, address src, address dst, int256 dink, int256 dart) external { + uint256 srcInkNew = (urns[ilk][src].ink - dink) % #(Int.ofNat EVM.wordModulus); + require(dink <= 0 || srcInkNew <= urns[ilk][src].ink); + require(dink >= 0 || srcInkNew >= urns[ilk][src].ink); + urns[ilk][src].ink = srcInkNew; + uint256 srcArtNew = (urns[ilk][src].art - dart) % #(Int.ofNat EVM.wordModulus); + require(dart <= 0 || srcArtNew <= urns[ilk][src].art); + require(dart >= 0 || srcArtNew >= urns[ilk][src].art); + urns[ilk][src].art = srcArtNew; + uint256 dstInkNew = (urns[ilk][dst].ink + dink) % #(Int.ofNat EVM.wordModulus); + require(dink >= 0 || dstInkNew <= urns[ilk][dst].ink); + require(dink <= 0 || dstInkNew >= urns[ilk][dst].ink); + urns[ilk][dst].ink = dstInkNew; + uint256 dstArtNew = (urns[ilk][dst].art + dart) % #(Int.ofNat EVM.wordModulus); + require(dart >= 0 || dstArtNew <= urns[ilk][dst].art); + require(dart <= 0 || dstArtNew >= urns[ilk][dst].art); + urns[ilk][dst].art = dstArtNew; + uint256 srcArtFinal = urns[ilk][src].art; + uint256 dstArtFinal = urns[ilk][dst].art; + uint256 srcInkFinal = urns[ilk][src].ink; + uint256 dstInkFinal = urns[ilk][dst].ink; + uint256 utab = (srcArtFinal * ilks[ilk].rate) as uint256; + require(ilks[ilk].rate == 0 || utab / ilks[ilk].rate == srcArtFinal); + uint256 vtab = (dstArtFinal * ilks[ilk].rate) as uint256; + require(ilks[ilk].rate == 0 || vtab / ilks[ilk].rate == dstArtFinal); + uint256 srcInkSpot = (srcInkFinal * ilks[ilk].spot) as uint256; + require(ilks[ilk].spot == 0 || srcInkSpot / ilks[ilk].spot == srcInkFinal); + uint256 dstInkSpot = (dstInkFinal * ilks[ilk].spot) as uint256; + require(ilks[ilk].spot == 0 || dstInkSpot / ilks[ilk].spot == dstInkFinal); + require((src == msg.sender || can[src][msg.sender] == 1) && + (dst == msg.sender || can[dst][msg.sender] == 1)); + require(utab <= srcInkSpot); + require(vtab <= dstInkSpot); + require(utab >= ilks[ilk].dust || srcArtFinal == 0); + require(vtab >= ilks[ilk].dust || dstArtFinal == 0); + } + + function frob(bytes32 i, address u, address v, address w, int256 dink, int256 dart) external { + require(live == 1); + uint256 urnInk = urns[i][u].ink; + uint256 urnArt = urns[i][u].art; + uint256 ilkArt = ilks[i].Art; + uint256 ilkRate = ilks[i].rate; + uint256 ilkSpot = ilks[i].spot; + uint256 ilkLine = ilks[i].line; + uint256 ilkDust = ilks[i].dust; + require(ilkRate != 0); + uint256 urnInkNew = (urnInk + dink) % #(Int.ofNat EVM.wordModulus); + require(dink >= 0 || urnInkNew <= urnInk); + require(dink <= 0 || urnInkNew >= urnInk); + uint256 urnArtNew = (urnArt + dart) % #(Int.ofNat EVM.wordModulus); + require(dart >= 0 || urnArtNew <= urnArt); + require(dart <= 0 || urnArtNew >= urnArt); + uint256 ilkArtNew = (ilkArt + dart) % #(Int.ofNat EVM.wordModulus); + require(dart >= 0 || ilkArtNew <= ilkArt); + require(dart <= 0 || ilkArtNew >= ilkArt); + int256 dtab = (ilkRate * dart) as int256; + require(ilkRate <= #maxInt256); + require(dart == 0 || dtab / dart == ilkRate); + uint256 tab = (ilkRate * urnArtNew) as uint256; + require(urnArtNew == 0 || tab / urnArtNew == ilkRate); + uint256 debtNew = (debt + dtab) % #(Int.ofNat EVM.wordModulus); + require(dtab >= 0 || debtNew <= debt); + require(dtab <= 0 || debtNew >= debt); + debt = debtNew; + uint256 ceilingDebt = (ilkArtNew * ilkRate) as uint256; + require(ilkRate == 0 || ceilingDebt / ilkRate == ilkArtNew); + uint256 inkSpot = (urnInkNew * ilkSpot) as uint256; + require(ilkSpot == 0 || inkSpot / ilkSpot == urnInkNew); + require(dart <= 0 || (ceilingDebt <= ilkLine && debtNew <= Line)); + require((dart <= 0 && dink >= 0) || tab <= inkSpot); + require((dart <= 0 && dink >= 0) || (u == msg.sender || can[u][msg.sender] == 1)); + require(dink <= 0 || (v == msg.sender || can[v][msg.sender] == 1)); + require(dart >= 0 || (w == msg.sender || can[w][msg.sender] == 1)); + require(urnArtNew == 0 || tab >= ilkDust); + uint256 gemNew = (gem[i][v] - dink) % #(Int.ofNat EVM.wordModulus); + require(dink <= 0 || gemNew <= gem[i][v]); + require(dink >= 0 || gemNew >= gem[i][v]); + gem[i][v] = gemNew; + uint256 daiNew = (dai[w] + dtab) % #(Int.ofNat EVM.wordModulus); + require(dtab >= 0 || daiNew <= dai[w]); + require(dtab <= 0 || daiNew >= dai[w]); + dai[w] = daiNew; + urns[i][u].ink = urnInkNew; + urns[i][u].art = urnArtNew; + ilks[i].Art = ilkArtNew; + ilks[i].rate = ilkRate; + ilks[i].spot = ilkSpot; + ilks[i].line = ilkLine; + ilks[i].dust = ilkDust; + } + + function gem(bytes32 arg0, address arg1) external returns (uint256) { + return gem[arg0][arg1]; + } + + function grab(bytes32 i, address u, address v, address w, int256 dink, int256 dart) external { + require(wards[msg.sender] == 1); + uint256 urnInkNew = (urns[i][u].ink + dink) % #(Int.ofNat EVM.wordModulus); + require(dink >= 0 || urnInkNew <= urns[i][u].ink); + require(dink <= 0 || urnInkNew >= urns[i][u].ink); + urns[i][u].ink = urnInkNew; + uint256 urnArtNew = (urns[i][u].art + dart) % #(Int.ofNat EVM.wordModulus); + require(dart >= 0 || urnArtNew <= urns[i][u].art); + require(dart <= 0 || urnArtNew >= urns[i][u].art); + urns[i][u].art = urnArtNew; + uint256 ilkArtNew = (ilks[i].Art + dart) % #(Int.ofNat EVM.wordModulus); + require(dart >= 0 || ilkArtNew <= ilks[i].Art); + require(dart <= 0 || ilkArtNew >= ilks[i].Art); + ilks[i].Art = ilkArtNew; + int256 dtab = (ilks[i].rate * dart) as int256; + require(ilks[i].rate <= #maxInt256); + require(dart == 0 || dtab / dart == ilks[i].rate); + uint256 gemNew = (gem[i][v] - dink) % #(Int.ofNat EVM.wordModulus); + require(dink <= 0 || gemNew <= gem[i][v]); + require(dink >= 0 || gemNew >= gem[i][v]); + gem[i][v] = gemNew; + uint256 sinNew = (sin[w] - dtab) % #(Int.ofNat EVM.wordModulus); + require(dtab <= 0 || sinNew <= sin[w]); + require(dtab >= 0 || sinNew >= sin[w]); + sin[w] = sinNew; + uint256 viceNew = (vice - dtab) % #(Int.ofNat EVM.wordModulus); + require(dtab <= 0 || viceNew <= vice); + require(dtab >= 0 || viceNew >= vice); + vice = viceNew; + } + + function heal(uint256 rad) external { + uint256 sinNew = (sin[msg.sender] - rad) as uint256; + require(sinNew <= sin[msg.sender]); + sin[msg.sender] = sinNew; + uint256 daiNew = (dai[msg.sender] - rad) as uint256; + require(daiNew <= dai[msg.sender]); + dai[msg.sender] = daiNew; + uint256 viceNew = (vice - rad) as uint256; + require(viceNew <= vice); + vice = viceNew; + uint256 debtNew = (debt - rad) as uint256; + require(debtNew <= debt); + debt = debtNew; + } + + function hope(address usr) external { + can[msg.sender][usr] = 1; + } + + function ilks(bytes32 arg0) external returns (uint256, uint256, uint256, uint256, uint256) { + return (ilks[arg0].Art, ilks[arg0].rate, ilks[arg0].spot, ilks[arg0].line, ilks[arg0].dust); + } + + function init(bytes32 ilk) external { + require(wards[msg.sender] == 1); + require(ilks[ilk].rate == 0); + ilks[ilk].rate = #ray; + } + + function live() external returns (uint256) { + return live; + } + + function move(address src, address dst, uint256 rad) external { + require(src == msg.sender || can[src][msg.sender] == 1); + uint256 srcDaiNew = (dai[src] - rad) as uint256; + require(srcDaiNew <= dai[src]); + dai[src] = srcDaiNew; + uint256 dstDaiNew = (dai[dst] + rad) as uint256; + require(dstDaiNew >= dai[dst]); + dai[dst] = dstDaiNew; + } + + function nope(address usr) external { + can[msg.sender][usr] = 0; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + require(live == 1); + wards[usr] = 1; + } + + function sin(address arg0) external returns (uint256) { + return sin[arg0]; + } + + function slip(bytes32 ilk, address usr, int256 wad) external { + require(wards[msg.sender] == 1); + uint256 gemNew = (gem[ilk][usr] + wad) % #(Int.ofNat EVM.wordModulus); + require(wad >= 0 || gemNew <= gem[ilk][usr]); + require(wad <= 0 || gemNew >= gem[ilk][usr]); + gem[ilk][usr] = gemNew; + } + + function suck(address u, address v, uint256 rad) external { + require(wards[msg.sender] == 1); + uint256 sinNew = (sin[u] + rad) as uint256; + require(sinNew >= sin[u]); + sin[u] = sinNew; + uint256 daiNew = (dai[v] + rad) as uint256; + require(daiNew >= dai[v]); + dai[v] = daiNew; + uint256 viceNew = (vice + rad) as uint256; + require(viceNew >= vice); + vice = viceNew; + uint256 debtNew = (debt + rad) as uint256; + require(debtNew >= debt); + debt = debtNew; + } + + function urns(bytes32 arg0, address arg1) external returns (uint256, uint256) { + return (urns[arg0][arg1].ink, urns[arg0][arg1].art); + } + + function vice() external returns (uint256) { + return vice; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Vat.contract := by rfl end Benchmarks.Dss.Vat.Syntax diff --git a/Benchmarks/Dss/Vow/Cage.lean b/Benchmarks/Dss/Vow/Cage.lean index 461277e6..7e76e19c 100644 --- a/Benchmarks/Dss/Vow/Cage.lean +++ b/Benchmarks/Dss/Vow/Cage.lean @@ -797,13 +797,13 @@ theorem RD.vowCageFirstDaiNoCode {g : Sat256} {s0 : State} {ee : ExecutionEnv} (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (UInt256.land solcAddrMask (solcSlotWord σ ee ⟨1⟩)) = ⟨0⟩) (hov : R.length + 14 ≤ 1024) : RDrev vowBytecode g s0 := by obtain ⟨_, _, rd2738⟩ := RD.vowCageFirstDaiExtcodesizeGuard rd hmem hread64 (by omega) - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2738⟩) (okPc := ⟨2750⟩) rd2738 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2738⟩) (okPc := ⟨2750⟩) rd2738 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -818,7 +818,7 @@ theorem RD.vowCageFirstDaiStaticcallSetup {g : Sat256} {s0 : State} (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ + Reasoning.Theory.extCodeSizeWord σ (UInt256.land solcAddrMask (solcSlotWord σ ee ⟨1⟩)) ≠ ⟨0⟩) (hov : R.length + 14 ≤ 1024) : ∃ gasWord k' C', RD vowBytecode ee g s0 ⟨2753⟩ @@ -831,7 +831,7 @@ theorem RD.vowCageFirstDaiStaticcallSetup {g : Sat256} {s0 : State} obtain ⟨_, _, rd2738⟩ := RD.vowCageFirstDaiExtcodesizeGuard rd hmem hread64 (by omega) obtain ⟨gasWord, k2753, C2753, rd2753⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2738⟩) (okPc := ⟨2750⟩) rd2738 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2738⟩) (okPc := ⟨2750⟩) rd2738 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -848,7 +848,7 @@ theorem RD.vowCageFirstDaiStaticcall (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (kissDaiTargetWord σCall I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σCall (kissDaiTargetWord σCall I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hov : R.length + 14 ≤ 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) @@ -874,14 +874,14 @@ theorem RD.vowCageFirstDaiStaticcall outDai) false ∧ outDai.size < UInt256.size := by have hcodeSize' : - Reasoning.Theory.uniswapExtCodeSizeWord σCall + Reasoning.Theory.extCodeSizeWord σCall (UInt256.land solcAddrMask (solcSlotWord σCall I ⟨1⟩)) ≠ ⟨0⟩ := by simpa [kissDaiTargetWord, vowSlotWord, solcSlotWord, u256_land_comm] using hcodeSize obtain ⟨gasWord, _, _, rd2753⟩ := RD.vowCageFirstDaiStaticcallSetup rd hmem hread64 hcodeSize' hov obtain ⟨cA', σ', z, outDai, A_in, callGas, k2754, C2754, hΘpack, rd2754raw, houtsz⟩ := - RD.uniswapStaticcall rd2753 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall rd2753 (by native_decide) hdepth (by evm_ov) obtain ⟨g'', A', hΘ⟩ := hΘpack let evmDaiIn := { initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I with accountMap := σCall } @@ -924,7 +924,7 @@ theorem RD.vowCageFirstDaiCallFailure {g : Sat256} {s0 : State} {ee : ExecutionE (hosz : o.size < UInt256.size) (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2754⟩) (okPc := ⟨2770⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨2754⟩) (okPc := ⟨2770⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -939,7 +939,7 @@ theorem RD.vowCageFirstDaiCallSuccessToDecode {g : Sat256} {s0 : State} (hov : R.length + 6 ≤ 1024) : ∃ k' C', RD vowBytecode ee g s0 ⟨2772⟩ (d0 :: d1 :: d2 :: R) mem aw o acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨2754⟩) (okPc := ⟨2770⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨2754⟩) (okPc := ⟨2770⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1107,12 +1107,12 @@ theorem RD.vowCageFlapperCageNoCode {g : Sat256} {s0 : State} (rad :: flapCageSelectorWord :: target :: R) mem (UInt256.ofNat 6) rdata acc k C) (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord acc.2 target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord acc.2 target = ⟨0⟩) (hov : R.length + 12 ≤ 1024) : RDrev vowBytecode g s0 := by obtain ⟨_, _, rd2844⟩ := RD.vowCageFlapperCageExtcodesizeGuard rd hmem hread64 hov - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2844⟩) (okPc := ⟨2856⟩) rd2844 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2844⟩) (okPc := ⟨2856⟩) rd2844 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1125,7 +1125,7 @@ theorem RD.vowCageFlapperCageCallSetup {g : Sat256} {s0 : State} (rad :: flapCageSelectorWord :: target :: R) mem (UInt256.ofNat 6) rdata acc k C) (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord acc.2 target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord acc.2 target ≠ ⟨0⟩) (hov : R.length + 12 ≤ 1024) : ∃ gasWord k' C', RD vowBytecode ee g s0 ⟨2859⟩ (gasWord :: target :: flapCageOutSize :: flapCageOutPtr :: flapCageInSize :: @@ -1135,7 +1135,7 @@ theorem RD.vowCageFlapperCageCallSetup {g : Sat256} {s0 : State} obtain ⟨_, _, rd2844⟩ := RD.vowCageFlapperCageExtcodesizeGuard rd hmem hread64 hov obtain ⟨gasWord, k', C', rd2859⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2844⟩) (okPc := ⟨2856⟩) rd2844 + RD.solcExtcodesizeGuardOkGas (pc := ⟨2844⟩) (okPc := ⟨2856⟩) rd2844 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1152,7 +1152,7 @@ theorem RD.vowCageFlapperCageCall mem (UInt256.ofNat 6) rdata (cA_call, σCall) k C) (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σCall target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σCall target ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hperm : I.perm = true) (htgt : EVM.address (AccountAddress.ofNat target.toNat) = @@ -1225,7 +1225,7 @@ theorem RD.vowCageFlapperCageCallFailure {g : Sat256} {s0 : State} (hosz : o.size < UInt256.size) (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2860⟩) (okPc := ⟨2876⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨2860⟩) (okPc := ⟨2876⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1239,7 +1239,7 @@ theorem RD.vowCageFlapperCageCallSuccessCleanup {g : Sat256} {s0 : State} (⟨1⟩ :: d0 :: d1 :: d2 :: R) mem aw o acc k C) (hov : R.length + 6 ≤ 1024) : ∃ k' C', RD vowBytecode ee g s0 ⟨2881⟩ R mem aw o acc k' C' := by - obtain ⟨_, _, rd2878⟩ := RD.uniswapCallSuccessGuardOk + obtain ⟨_, _, rd2878⟩ := RD.solcCallSuccessGuardOk (pc := ⟨2860⟩) (okPc := ⟨2876⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1377,14 +1377,14 @@ theorem RD.vowCageFlopperCageNoCode {g : Sat256} {s0 : State} (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (vowAddressReturnWord ⟨3⟩ acc.2 ee) = ⟨0⟩) (hov : R.length + 15 ≤ 1024) : RDrev vowBytecode g s0 := by let target := vowAddressReturnWord ⟨3⟩ acc.2 ee obtain ⟨_, _, rd2948⟩ := RD.vowCageFlopperCageExtcodesizeGuard rd hmem hread64 hov - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨2948⟩) (okPc := ⟨2960⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨2948⟩) (okPc := ⟨2960⟩) (by simpa [target] using rd2948) (by simpa [target] using hcodeSize) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1399,7 +1399,7 @@ theorem RD.vowCageFlopperCageCallSetup {g : Sat256} {s0 : State} (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (vowAddressReturnWord ⟨3⟩ acc.2 ee) ≠ ⟨0⟩) (hov : R.length + 15 ≤ 1024) : let target := vowAddressReturnWord ⟨3⟩ acc.2 ee @@ -1412,7 +1412,7 @@ theorem RD.vowCageFlopperCageCallSetup {g : Sat256} {s0 : State} obtain ⟨_, _, rd2948⟩ := RD.vowCageFlopperCageExtcodesizeGuard rd hmem hread64 hov obtain ⟨gasWord, k', C', rd2963⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2948⟩) (okPc := ⟨2960⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨2948⟩) (okPc := ⟨2960⟩) (by simpa [target] using rd2948) (by simpa [target] using hcodeSize) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1430,7 +1430,7 @@ theorem RD.vowCageFlopperCageCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall + Reasoning.Theory.extCodeSizeWord σCall (vowAddressReturnWord ⟨3⟩ σCall I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hperm : I.perm = true) @@ -1504,7 +1504,7 @@ theorem RD.vowCageFlopperCageCallFailure {g : Sat256} {s0 : State} (hosz : o.size < UInt256.size) (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨2964⟩) (okPc := ⟨2980⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨2964⟩) (okPc := ⟨2980⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1518,7 +1518,7 @@ theorem RD.vowCageFlopperCageCallSuccessCleanup {g : Sat256} {s0 : State} (⟨1⟩ :: d0 :: d1 :: d2 :: R) mem aw o acc k C) (hov : R.length + 6 ≤ 1024) : ∃ k' C', RD vowBytecode ee g s0 ⟨2983⟩ (d1 :: d2 :: R) mem aw o acc k' C' := by - obtain ⟨_, _, rd2982⟩ := RD.uniswapCallSuccessGuardOk + obtain ⟨_, _, rd2982⟩ := RD.solcCallSuccessGuardOk (pc := ⟨2964⟩) (okPc := ⟨2980⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Vow/CageBody.lean b/Benchmarks/Dss/Vow/CageBody.lean index 83a8f612..f979f49a 100644 --- a/Benchmarks/Dss/Vow/CageBody.lean +++ b/Benchmarks/Dss/Vow/CageBody.lean @@ -873,7 +873,7 @@ theorem RD.vowCageSecondDaiExtcodesizeGuard {g : Sat256} {s0 : State} dup2, raw mstore 0 (vatDaiSelectorMem mem) (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov), - uniswapAddress, + address, push1 ⟨4⟩, dup3, add, @@ -949,12 +949,12 @@ theorem RD.vowCageSecondDaiNoCode {g : Sat256} {s0 : State} (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 ee) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 ee) = ⟨0⟩) (hov : R.length + 16 ≤ 1024) : RDrev vowBytecode g s0 := by obtain ⟨_, _, rd3058⟩ := RD.vowCageSecondDaiExtcodesizeGuard rd hmem hread64 hov - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3058⟩) (okPc := ⟨3070⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3058⟩) (okPc := ⟨3070⟩) rd3058 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -968,7 +968,7 @@ theorem RD.vowCageSecondDaiStaticcallSetup {g : Sat256} {s0 : State} (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 ee) ≠ ⟨0⟩) (hov : R.length + 16 ≤ 1024) : ∃ gasWord k' C', RD vowBytecode ee g s0 ⟨3073⟩ @@ -979,7 +979,7 @@ theorem RD.vowCageSecondDaiStaticcallSetup {g : Sat256} {s0 : State} obtain ⟨_, _, rd3058⟩ := RD.vowCageSecondDaiExtcodesizeGuard rd hmem hread64 hov obtain ⟨gasWord, k3073, C3073, rd3073⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3058⟩) (okPc := ⟨3070⟩) rd3058 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3058⟩) (okPc := ⟨3070⟩) rd3058 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -996,7 +996,7 @@ theorem RD.vowCageSecondDaiStaticcall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (kissDaiTargetWord σCall I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σCall (kissDaiTargetWord σCall I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hov : R.length + 16 ≤ 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) @@ -1025,7 +1025,7 @@ theorem RD.vowCageSecondDaiStaticcall rd hmem hread64 hcodeSize hov obtain ⟨cA', σ', z, outDai, A_in, callGas, k3074, C3074, hΘpack, rd3074raw, houtsz⟩ := - RD.uniswapStaticcall rd3073 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall rd3073 (by native_decide) hdepth (by evm_ov) obtain ⟨g'', A', hΘ⟩ := hΘpack let evmDaiIn := { initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I with accountMap := σCall @@ -1054,7 +1054,7 @@ theorem RD.vowCageSecondDaiCallFailure {g : Sat256} {s0 : State} (hosz : o.size < UInt256.size) (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3074⟩) (okPc := ⟨3090⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨3074⟩) (okPc := ⟨3090⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1069,7 +1069,7 @@ theorem RD.vowCageSecondDaiCallSuccessToDecode {g : Sat256} {s0 : State} (hov : R.length + 6 ≤ 1024) : ∃ k' C', RD vowBytecode ee g s0 ⟨3092⟩ (d0 :: d1 :: d2 :: R) mem aw o acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨3074⟩) (okPc := ⟨3090⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨3074⟩) (okPc := ⟨3090⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1183,7 +1183,7 @@ theorem RD.vowCageVatSinExtcodesizeGuard {g : Sat256} {s0 : State} dup2, raw mstore 0 (healSinSelectorMem mem) (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov), - uniswapAddress, + address, push1 ⟨4⟩, dup3, add, @@ -1249,11 +1249,11 @@ theorem RD.vowCageVatSinNoCode {g : Sat256} {s0 : State} (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 ee) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 ee) = ⟨0⟩) (hov : R.length + 18 ≤ 1024) : RDrev vowBytecode g s0 := by obtain ⟨_, _, rd3177⟩ := RD.vowCageVatSinExtcodesizeGuard rd hmem hread64 hov - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3177⟩) (okPc := ⟨3189⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3177⟩) (okPc := ⟨3189⟩) rd3177 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1268,7 +1268,7 @@ theorem RD.vowCageVatSinStaticcallSetup {g : Sat256} {s0 : State} (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 ee) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 ee) ≠ ⟨0⟩) (hov : R.length + 18 ≤ 1024) : ∃ gasWord k' C', RD vowBytecode ee g s0 ⟨3192⟩ (gasWord :: kissDaiTargetWord acc.2 ee :: healSinOutPtr :: healSinInSize :: @@ -1278,7 +1278,7 @@ theorem RD.vowCageVatSinStaticcallSetup {g : Sat256} {s0 : State} (healSinCalldataMem ee mem) (UInt256.ofNat 6) rdata acc k' C' := by obtain ⟨_, _, rd3177⟩ := RD.vowCageVatSinExtcodesizeGuard rd hmem hread64 hov obtain ⟨gasWord, k3192, C3192, rd3192⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3177⟩) (okPc := ⟨3189⟩) rd3177 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3177⟩) (okPc := ⟨3189⟩) rd3177 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1297,7 +1297,7 @@ theorem RD.vowCageVatSinStaticcall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (kissDaiTargetWord σCall I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σCall (kissDaiTargetWord σCall I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hov : R.length + 18 ≤ 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) @@ -1327,7 +1327,7 @@ theorem RD.vowCageVatSinStaticcall (vatDai := vatDai) (R := R) rd hmem hread64 hcodeSize hov obtain ⟨cA', σ', z, outSin, A_in, callGas, k3193, C3193, hΘpack, rd3193raw, houtsz⟩ := - RD.uniswapStaticcall rd3192 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall rd3192 (by native_decide) hdepth (by evm_ov) obtain ⟨g'', A', hΘ⟩ := hΘpack let evmSinIn := { initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I with accountMap := σCall @@ -1358,7 +1358,7 @@ theorem RD.vowCageVatSinCallFailure {g : Sat256} {s0 : State} (hosz : o.size < UInt256.size) (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3193⟩) (okPc := ⟨3209⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨3193⟩) (okPc := ⟨3209⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1373,7 +1373,7 @@ theorem RD.vowCageVatSinCallSuccessToDecode {g : Sat256} {s0 : State} (hov : R.length + 6 ≤ 1024) : ∃ k' C', RD vowBytecode ee g s0 ⟨3211⟩ (d0 :: d1 :: d2 :: R) mem aw o acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨3193⟩) (okPc := ⟨3209⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨3193⟩) (okPc := ⟨3209⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1608,11 +1608,11 @@ theorem RD.vowCageHealNoCode {g : Sat256} {s0 : State} (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 ee) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 ee) = ⟨0⟩) (hov : R.length + 15 ≤ 1024) : RDrev vowBytecode g s0 := by obtain ⟨_, _, rd3280⟩ := RD.vowCageHealExtcodesizeGuard rd hmem hread64 hov - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3280⟩) (okPc := ⟨3292⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3280⟩) (okPc := ⟨3292⟩) rd3280 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1628,7 +1628,7 @@ theorem RD.vowCageHealCallSetup {g : Sat256} {s0 : State} (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 ee) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 ee) ≠ ⟨0⟩) (hov : R.length + 15 ≤ 1024) : ∃ gasWord k' C', RD vowBytecode ee g s0 ⟨3295⟩ (gasWord :: kissDaiTargetWord acc.2 ee :: kissHealOutSize :: @@ -1637,7 +1637,7 @@ theorem RD.vowCageHealCallSetup {g : Sat256} {s0 : State} (cageHealCalldataMem healRad mem) (UInt256.ofNat 6) rdata acc k' C' := by obtain ⟨_, _, rd3280⟩ := RD.vowCageHealExtcodesizeGuard rd hmem hread64 hov obtain ⟨gasWord, k3295, C3295, rd3295⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3280⟩) (okPc := ⟨3292⟩) rd3280 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3280⟩) (okPc := ⟨3292⟩) rd3280 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1656,7 +1656,7 @@ theorem RD.vowCageHealPostCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (kissDaiTargetWord σCall I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σCall (kissDaiTargetWord σCall I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hperm : I.perm = true) (hov : R.length + 15 ≤ 1024) : @@ -1735,7 +1735,7 @@ theorem RD.vowCageHealCallFailure {g : Sat256} {s0 : State} (hosz : o.size < UInt256.size) (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3296⟩) (okPc := ⟨3312⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨3296⟩) (okPc := ⟨3312⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1750,7 +1750,7 @@ theorem RD.vowCageHealCallSuccessCleanup {g : Sat256} {s0 : State} (hret : (D_J vowBytecode 0).contains ret = true) (hov : R.length + 7 ≤ 1024) : ∃ k' C', RD vowBytecode ee g s0 ret R mem aw o acc k' C' := by - obtain ⟨_, _, rd3314⟩ := RD.uniswapCallSuccessGuardOk + obtain ⟨_, _, rd3314⟩ := RD.solcCallSuccessGuardOk (pc := ⟨3296⟩) (okPc := ⟨3312⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Vow/CageBodyRuntime.lean b/Benchmarks/Dss/Vow/CageBodyRuntime.lean index 16d1b372..67d05624 100644 --- a/Benchmarks/Dss/Vow/CageBodyRuntime.lean +++ b/Benchmarks/Dss/Vow/CageBodyRuntime.lean @@ -24,14 +24,14 @@ theorem cageFlapperTargetWord_accountMapEquiv {σ τ : AccountMap} {I : Executio theorem cageFlapperCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (vowAddressReturnWord ⟨2⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (vowAddressReturnWord ⟨2⟩ σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (vowAddressReturnWord ⟨2⟩ τ I) ≠ + Reasoning.Theory.extCodeSizeWord τ (vowAddressReturnWord ⟨2⟩ τ I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (vowAddressReturnWord ⟨2⟩ σ I) have htarget : vowAddressReturnWord ⟨2⟩ σ I = vowAddressReturnWord ⟨2⟩ τ I := cageFlapperTargetWord_accountMapEquiv hAccounts @@ -41,12 +41,12 @@ theorem cageFlapperCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : Executi theorem cageFlapperCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (vowAddressReturnWord ⟨2⟩ σ I) = + Reasoning.Theory.extCodeSizeWord σ (vowAddressReturnWord ⟨2⟩ σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (vowAddressReturnWord ⟨2⟩ τ I) = + Reasoning.Theory.extCodeSizeWord τ (vowAddressReturnWord ⟨2⟩ τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (vowAddressReturnWord ⟨2⟩ σ I) have htarget : vowAddressReturnWord ⟨2⟩ σ I = vowAddressReturnWord ⟨2⟩ τ I := cageFlapperTargetWord_accountMapEquiv hAccounts @@ -63,14 +63,14 @@ theorem cageFlopperTargetWord_accountMapEquiv {σ τ : AccountMap} {I : Executio theorem cageFlopperCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (vowAddressReturnWord ⟨3⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (vowAddressReturnWord ⟨3⟩ σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (vowAddressReturnWord ⟨3⟩ τ I) ≠ + Reasoning.Theory.extCodeSizeWord τ (vowAddressReturnWord ⟨3⟩ τ I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (vowAddressReturnWord ⟨3⟩ σ I) have htarget : vowAddressReturnWord ⟨3⟩ σ I = vowAddressReturnWord ⟨3⟩ τ I := cageFlopperTargetWord_accountMapEquiv hAccounts @@ -80,12 +80,12 @@ theorem cageFlopperCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : Executi theorem cageFlopperCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (vowAddressReturnWord ⟨3⟩ σ I) = + Reasoning.Theory.extCodeSizeWord σ (vowAddressReturnWord ⟨3⟩ σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (vowAddressReturnWord ⟨3⟩ τ I) = + Reasoning.Theory.extCodeSizeWord τ (vowAddressReturnWord ⟨3⟩ τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (vowAddressReturnWord ⟨3⟩ σ I) have htarget : vowAddressReturnWord ⟨3⟩ σ I = vowAddressReturnWord ⟨3⟩ τ I := cageFlopperTargetWord_accountMapEquiv hAccounts @@ -107,12 +107,12 @@ theorem cageVatAddress_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} theorem cageVatCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (kissDaiTargetWord τ I) ≠ ⟨0⟩ := by + (hne : Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (kissDaiTargetWord τ I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (kissDaiTargetWord σ I) have htarget : kissDaiTargetWord σ I = kissDaiTargetWord τ I := cageVatTargetWord_accountMapEquiv hAccounts @@ -121,10 +121,10 @@ theorem cageVatCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEn theorem cageVatCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (kissDaiTargetWord τ I) = ⟨0⟩ := by + (hzero : Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (kissDaiTargetWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (kissDaiTargetWord σ I) have htarget : kissDaiTargetWord σ I = kissDaiTargetWord τ I := cageVatTargetWord_accountMapEquiv hAccounts @@ -152,13 +152,13 @@ theorem cageFlopperAddressOf_eq_vowAddressReturnWord (evm : EVM.State) (I : Exec theorem cageFlopperCode_pos_of_codeSize_ne (evm : EVM.State) (I : ExecutionEnv) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (vowAddressReturnWord ⟨3⟩ evm.accountMap I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (flopFlopperAddressOf evm)).option 0 (fun acc => acc.code.size))).toNat := by simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := evm.accountMap) (target := vowAddressReturnWord ⟨3⟩ evm.accountMap I) (addr := flopFlopperAddressOf evm) (cageFlopperAddressOf_eq_vowAddressReturnWord evm I howner) hne @@ -166,13 +166,13 @@ theorem cageFlopperCode_pos_of_codeSize_ne (evm : EVM.State) (I : ExecutionEnv) theorem cageFlopperCode_zero_of_codeSize_zero (evm : EVM.State) (I : ExecutionEnv) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (vowAddressReturnWord ⟨3⟩ evm.accountMap I) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (flopFlopperAddressOf evm)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := evm.accountMap) (target := vowAddressReturnWord ⟨3⟩ evm.accountMap I) (addr := flopFlopperAddressOf evm) (cageFlopperAddressOf_eq_vowAddressReturnWord evm I howner) hzero @@ -189,7 +189,7 @@ theorem cageVatAddressOf_eq_kissVatAddress (evm : EVM.State) (I : ExecutionEnv) theorem cageVatCode_pos_of_codeSize_ne (evm : EVM.State) (I : ExecutionEnv) (howner : evm.executionEnv.codeOwner = I.codeOwner) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + (hne : Reasoning.Theory.extCodeSizeWord evm.accountMap (kissDaiTargetWord evm.accountMap I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (cageVatAddressOf evm)).option 0 @@ -199,13 +199,13 @@ theorem cageVatCode_pos_of_codeSize_ne (evm : EVM.State) (I : ExecutionEnv) (cageVatAddressOf_eq_kissVatAddress evm I howner).trans (kissVatAddress_eq_daiTarget_account evm.accountMap I) simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := evm.accountMap) (target := kissDaiTargetWord evm.accountMap I) (addr := cageVatAddressOf evm) haddr hne theorem cageVatCode_zero_of_codeSize_zero (evm : EVM.State) (I : ExecutionEnv) (howner : evm.executionEnv.codeOwner = I.codeOwner) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + (hzero : Reasoning.Theory.extCodeSizeWord evm.accountMap (kissDaiTargetWord evm.accountMap I) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (cageVatAddressOf evm)).option 0 @@ -215,7 +215,7 @@ theorem cageVatCode_zero_of_codeSize_zero (evm : EVM.State) (I : ExecutionEnv) (cageVatAddressOf_eq_kissVatAddress evm I howner).trans (kissVatAddress_eq_daiTarget_account evm.accountMap I) simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := evm.accountMap) (target := kissDaiTargetWord evm.accountMap I) (addr := cageVatAddressOf evm) haddr hzero @@ -229,7 +229,7 @@ theorem RD.vowCageFirstDaiCallDepthLimit (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σCall (kissDaiTargetWord σCall I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σCall (kissDaiTargetWord σCall I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hov : R.length + 14 ≤ 1024) : ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) @@ -239,13 +239,13 @@ theorem RD.vowCageFirstDaiCallDepthLimit (vatDaiCalldataMemFor (vowAddressReturnWord ⟨2⟩ σCall I) mem) (UInt256.ofNat 6) ByteArray.empty (cA, σCall) k' C' := by have hcodeSizeRaw : - Reasoning.Theory.uniswapExtCodeSizeWord σCall + Reasoning.Theory.extCodeSizeWord σCall (UInt256.land solcAddrMask (solcSlotWord σCall I ⟨1⟩)) ≠ ⟨0⟩ := by simpa [kissDaiTargetWord, vowSlotWord, solcSlotWord, u256_land_comm] using hcodeSize obtain ⟨_, _, _, rd2753⟩ := RD.vowCageFirstDaiStaticcallSetup rd hmem hread64 hcodeSizeRaw hov obtain ⟨k2754, C2754, rd2754raw⟩ := - RD.uniswapStaticcallDepthLimit rd2753 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcallDepthLimit rd2753 (by native_decide) hdepth (by evm_ov) have haw : UInt256.ofNat (MachineState.M (MachineState.M (UInt256.ofNat 6).toNat (⟨128⟩ : UInt256).toNat (⟨36⟩ : UInt256).toNat) @@ -279,7 +279,7 @@ theorem vowCageFirstDaiCallDepthLimitBody (hauthEvm : vowSlotWord (vowCallerWardsSlot I) σ_evm I = ⟨1⟩) (hliveEvm : vowSlotWord ⟨12⟩ σ_evm I = ⟨1⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (vowCageClearedAccountMap I.codeOwner σ_evm) (kissDaiTargetWord (vowCageClearedAccountMap I.codeOwner σ_evm) I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : @@ -328,12 +328,12 @@ theorem vowCageFirstDaiCallDepthLimitBody have hslot := accountMapEquiv_storage_findD hClearedAccounts I.codeOwner ⟨1⟩ ⟨0⟩ simp [kissDaiTargetWord, vowSlotWord, hslot] have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σClearedSolm + Reasoning.Theory.extCodeSizeWord σClearedSolm (kissDaiTargetWord σClearedSolm I) ≠ ⟨0⟩ := by intro hzero apply hcodeSize have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hClearedAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hClearedAccounts (kissDaiTargetWord σClearedEvm I) rw [hsame, hTargetCleared] exact hzero @@ -363,7 +363,7 @@ theorem vowCageFirstDaiCallDepthLimitBody ((evmAsh.lookupAccount (cageVatAddressOf evmAsh)).option 0 (fun acc => acc.code.size))).toNat := by have hpos := - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := σClearedSolm) (target := kissDaiTargetWord σClearedSolm I) (addr := cageVatAddressOf evmAsh) haddr hcodeSizeSolm simpa [evmAsh, evmSin, evmLive, evm0, initState, State.lookupAccount, @@ -464,13 +464,13 @@ theorem vowCageBodyToFlapperCage (transitionSignature cageTransition).paramTypes I.calldata = some ∅ := vowDecode_cage hsz by_cases hcodeSizeFirst : - Reasoning.Theory.uniswapExtCodeSizeWord σClearedEvm + Reasoning.Theory.extCodeSizeWord σClearedEvm (kissDaiTargetWord σClearedEvm I) = ⟨0⟩ · exact vowCageFirstDaiNoCodeBodyCore hcode hsize hperm hwv hsel hAccounts hauthEvm hliveEvm (by simpa [σClearedEvm] using hcodeSizeFirst) have hcodeSizeFirstNE : - Reasoning.Theory.uniswapExtCodeSizeWord σClearedEvm + Reasoning.Theory.extCodeSizeWord σClearedEvm (kissDaiTargetWord σClearedEvm I) ≠ ⟨0⟩ := hcodeSizeFirst @@ -517,12 +517,12 @@ theorem vowCageBodyToFlapperCage accountMapEquiv_storage_findD hClearedAccounts I.codeOwner ⟨2⟩ ⟨0⟩ simp [vowAddressReturnWord, vowSlotWord, hslot] have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σClearedSolm + Reasoning.Theory.extCodeSizeWord σClearedSolm (kissDaiTargetWord σClearedSolm I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeFirstNE have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hClearedAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hClearedAccounts (kissDaiTargetWord σClearedEvm I) rw [hsame, hTargetCleared] exact hzero @@ -561,7 +561,7 @@ theorem vowCageBodyToFlapperCage ((evmAsh.lookupAccount (cageVatAddressOf evmAsh)).option 0 (fun acc => acc.code.size))).toNat := by have hpos := - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := σClearedSolm) (target := kissDaiTargetWord σClearedSolm I) (addr := cageVatAddressOf evmAsh) haddr hcodeSizeSolm simpa [evmAsh, evmSin, evmLive, evm0, initState, State.lookupAccount, @@ -844,14 +844,14 @@ theorem vowCageBodyToFlopperCage _ = vowAddressReturnWord ⟨2⟩ σClearedEvm I := (cageFlapperTargetWord_accountMapEquiv hClearedAccounts).symm by_cases hcodeSizeFlapper : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dai + Reasoning.Theory.extCodeSizeWord σ_dai (vowAddressReturnWord ⟨2⟩ σClearedEvm I) = ⟨0⟩ · have hcodeSizeFlapperDai : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dai + Reasoning.Theory.extCodeSizeWord σ_dai (vowAddressReturnWord ⟨2⟩ σ_dai I) = ⟨0⟩ := by simpa [hflapperTarget] using hcodeSizeFlapper have hcodeSizeFlapperSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmDai.accountMap + Reasoning.Theory.extCodeSizeWord evmDai.accountMap (vowAddressReturnWord ⟨2⟩ evmDai.accountMap I) = ⟨0⟩ := cageFlapperCodeSize_zero_accountMapEquiv hAccountsDai hcodeSizeFlapperDai have hownerDai : evmDai.executionEnv.codeOwner = I.codeOwner := by @@ -868,17 +868,17 @@ theorem vowCageBodyToFlopperCage (by simpa [hflapperTarget] using rd2795) hmemDai hread64Dai hcodeSizeFlapper (by simp) hvatCode hcallDai hdecDai hflapperNoCode have hcodeSizeFlapperNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dai + Reasoning.Theory.extCodeSizeWord σ_dai (vowAddressReturnWord ⟨2⟩ σClearedEvm I) ≠ ⟨0⟩ := hcodeSizeFlapper have hcodeSizeFlapperDaiNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dai + Reasoning.Theory.extCodeSizeWord σ_dai (vowAddressReturnWord ⟨2⟩ σ_dai I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeFlapperNE simpa [hflapperTarget] using hzero have hcodeSizeFlapperSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmDai.accountMap + Reasoning.Theory.extCodeSizeWord evmDai.accountMap (vowAddressReturnWord ⟨2⟩ evmDai.accountMap I) ≠ ⟨0⟩ := cageFlapperCodeSize_ne_accountMapEquiv hAccountsDai hcodeSizeFlapperDaiNE have hownerDai : evmDai.executionEnv.codeOwner = I.codeOwner := by @@ -1084,10 +1084,10 @@ theorem vowCageBodyToSecondDai hAccountsFlap => ?_) hcode hsize hperm hwv hsel hAccounts by_cases hcodeSizeFlopper : - Reasoning.Theory.uniswapExtCodeSizeWord σ_flap + Reasoning.Theory.extCodeSizeWord σ_flap (vowAddressReturnWord ⟨3⟩ σ_flap I) = ⟨0⟩ · have hcodeSizeFlopperSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmFlap.accountMap + Reasoning.Theory.extCodeSizeWord evmFlap.accountMap (vowAddressReturnWord ⟨3⟩ evmFlap.accountMap I) = ⟨0⟩ := cageFlopperCodeSize_zero_accountMapEquiv hAccountsFlap hcodeSizeFlopper have hownerFlap : evmFlap.executionEnv.codeOwner = I.codeOwner := by @@ -1104,11 +1104,11 @@ theorem vowCageBodyToSecondDai (by simpa using rd2881) hmemFlap hread64Flap hcodeSizeFlopper (by simp) hvatCode hcallDai hdecDai hflapperCode hcallFlap hflopperNoCode have hcodeSizeFlopperNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_flap + Reasoning.Theory.extCodeSizeWord σ_flap (vowAddressReturnWord ⟨3⟩ σ_flap I) ≠ ⟨0⟩ := hcodeSizeFlopper have hcodeSizeFlopperSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmFlap.accountMap + Reasoning.Theory.extCodeSizeWord evmFlap.accountMap (vowAddressReturnWord ⟨3⟩ evmFlap.accountMap I) ≠ ⟨0⟩ := cageFlopperCodeSize_ne_accountMapEquiv hAccountsFlap hcodeSizeFlopperNE have hownerFlap : evmFlap.executionEnv.codeOwner = I.codeOwner := by @@ -1316,10 +1316,10 @@ theorem vowCageBodyToVatSin hAccountsFlop => ?_) hcode hsize hperm hwv hsel hAccounts by_cases hcodeSizeVat : - Reasoning.Theory.uniswapExtCodeSizeWord σ_flop (kissDaiTargetWord σ_flop I) = + Reasoning.Theory.extCodeSizeWord σ_flop (kissDaiTargetWord σ_flop I) = ⟨0⟩ · have hcodeSizeVatSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmFlop.accountMap + Reasoning.Theory.extCodeSizeWord evmFlop.accountMap (kissDaiTargetWord evmFlop.accountMap I) = ⟨0⟩ := cageVatCodeSize_zero_accountMapEquiv hAccountsFlop hcodeSizeVat have hownerFlop : evmFlop.executionEnv.codeOwner = I.codeOwner := by @@ -1338,11 +1338,11 @@ theorem vowCageBodyToVatSin hvatCode hcallDai hdecDai hflapperCode hcallFlap hflopperCode hcallFlop hvatNoCode have hcodeSizeVatNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_flop (kissDaiTargetWord σ_flop I) ≠ + Reasoning.Theory.extCodeSizeWord σ_flop (kissDaiTargetWord σ_flop I) ≠ ⟨0⟩ := hcodeSizeVat have hcodeSizeVatSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmFlop.accountMap + Reasoning.Theory.extCodeSizeWord evmFlop.accountMap (kissDaiTargetWord evmFlop.accountMap I) ≠ ⟨0⟩ := cageVatCodeSize_ne_accountMapEquiv hAccountsFlop hcodeSizeVatNE have hownerFlop : evmFlop.executionEnv.codeOwner = I.codeOwner := by diff --git a/Benchmarks/Dss/Vow/CageBodyRuntimeTail.lean b/Benchmarks/Dss/Vow/CageBodyRuntimeTail.lean index 37245054..03cd0d9c 100644 --- a/Benchmarks/Dss/Vow/CageBodyRuntimeTail.lean +++ b/Benchmarks/Dss/Vow/CageBodyRuntimeTail.lean @@ -28,7 +28,7 @@ theorem vowCageVatSinNoCodeAt3115BodyCore (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) (hov : R.length + 18 ≤ 1024) (hvatCode : @@ -184,10 +184,10 @@ theorem vowCageBodyToMinHeal hgenesisDai2 henvDai2 hAccountsDai2 => ?_) hcode hsize hperm hwv hsel hAccounts by_cases hcodeSizeVatSin : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dai2 (kissDaiTargetWord σ_dai2 I) = + Reasoning.Theory.extCodeSizeWord σ_dai2 (kissDaiTargetWord σ_dai2 I) = ⟨0⟩ · have hcodeSizeVatSinSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmDai2.accountMap + Reasoning.Theory.extCodeSizeWord evmDai2.accountMap (kissDaiTargetWord evmDai2.accountMap I) = ⟨0⟩ := cageVatCodeSize_zero_accountMapEquiv hAccountsDai2 hcodeSizeVatSin have hownerDai2 : evmDai2.executionEnv.codeOwner = I.codeOwner := by @@ -206,11 +206,11 @@ theorem vowCageBodyToMinHeal hvatCode hcallDai hdecDai hflapperCode hcallFlap hflopperCode hcallFlop hvatCode2 hcallDai2 hdecDai2 hvatNoCode have hcodeSizeVatSinNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dai2 (kissDaiTargetWord σ_dai2 I) ≠ + Reasoning.Theory.extCodeSizeWord σ_dai2 (kissDaiTargetWord σ_dai2 I) ≠ ⟨0⟩ := hcodeSizeVatSin have hcodeSizeVatSinSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmDai2.accountMap + Reasoning.Theory.extCodeSizeWord evmDai2.accountMap (kissDaiTargetWord evmDai2.accountMap I) ≠ ⟨0⟩ := cageVatCodeSize_ne_accountMapEquiv hAccountsDai2 hcodeSizeVatSinNE have hownerDai2 : evmDai2.executionEnv.codeOwner = I.codeOwner := by @@ -437,10 +437,10 @@ theorem vowCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} simp [henvSin] by_cases hle : vatDai.toNat ≤ vatSin.toNat · by_cases hcodeSizeHeal : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) = + Reasoning.Theory.extCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) = ⟨0⟩ · have hcodeSizeHealSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmSin.accountMap + Reasoning.Theory.extCodeSizeWord evmSin.accountMap (kissDaiTargetWord evmSin.accountMap I) = ⟨0⟩ := cageVatCodeSize_zero_accountMapEquiv hAccountsSin hcodeSizeHeal have hvatNoCode : @@ -458,11 +458,11 @@ theorem vowCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} hcallFlap hflopperCode hcallFlop hvatCode2 hcallDai2 hdecDai2 hvatCodeSin hcallSin hdecSin hle hvatNoCode have hcodeSizeHealNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) ≠ + Reasoning.Theory.extCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) ≠ ⟨0⟩ := hcodeSizeHeal have hcodeSizeHealSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmSin.accountMap + Reasoning.Theory.extCodeSizeWord evmSin.accountMap (kissDaiTargetWord evmSin.accountMap I) ≠ ⟨0⟩ := cageVatCodeSize_ne_accountMapEquiv hAccountsSin hcodeSizeHealNE have hvatCodeHeal : @@ -570,10 +570,10 @@ theorem vowCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} · have hlt : vatSin.toNat < vatDai.toNat := by omega by_cases hcodeSizeHeal : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) = + Reasoning.Theory.extCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) = ⟨0⟩ · have hcodeSizeHealSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmSin.accountMap + Reasoning.Theory.extCodeSizeWord evmSin.accountMap (kissDaiTargetWord evmSin.accountMap I) = ⟨0⟩ := cageVatCodeSize_zero_accountMapEquiv hAccountsSin hcodeSizeHeal have hvatNoCode : @@ -591,11 +591,11 @@ theorem vowCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} hcallFlap hflopperCode hcallFlop hvatCode2 hcallDai2 hdecDai2 hvatCodeSin hcallSin hdecSin hlt hvatNoCode have hcodeSizeHealNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) ≠ + Reasoning.Theory.extCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) ≠ ⟨0⟩ := hcodeSizeHeal have hcodeSizeHealSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmSin.accountMap + Reasoning.Theory.extCodeSizeWord evmSin.accountMap (kissDaiTargetWord evmSin.accountMap I) ≠ ⟨0⟩ := cageVatCodeSize_ne_accountMapEquiv hAccountsSin hcodeSizeHealNE have hvatCodeHeal : diff --git a/Benchmarks/Dss/Vow/CageHealRuntime.lean b/Benchmarks/Dss/Vow/CageHealRuntime.lean index b7f30844..0c3f12c0 100644 --- a/Benchmarks/Dss/Vow/CageHealRuntime.lean +++ b/Benchmarks/Dss/Vow/CageHealRuntime.lean @@ -898,7 +898,7 @@ theorem vowCageMinHealLeftNoCodeBodyCore (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) (hov : R.length + 15 ≤ 1024) (hvatCode : @@ -999,7 +999,7 @@ theorem vowCageMinHealRightNoCodeBodyCore (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) (hov : R.length + 15 ≤ 1024) (hvatCode : diff --git a/Benchmarks/Dss/Vow/CageRuntime.lean b/Benchmarks/Dss/Vow/CageRuntime.lean index 11a1e42e..28dba7f5 100644 --- a/Benchmarks/Dss/Vow/CageRuntime.lean +++ b/Benchmarks/Dss/Vow/CageRuntime.lean @@ -1083,7 +1083,7 @@ theorem vowCageFirstDaiNoCodeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : U (hauthEvm : vowSlotWord (vowCallerWardsSlot I) σ_evm I = ⟨1⟩) (hliveEvm : vowSlotWord ⟨12⟩ σ_evm I = ⟨1⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (vowCageClearedAccountMap I.codeOwner σ_evm) (kissDaiTargetWord (vowCageClearedAccountMap I.codeOwner σ_evm) I) = ⟨0⟩) : @@ -1113,7 +1113,7 @@ theorem vowCageFirstDaiNoCodeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : U obtain ⟨_, _, rdLoads⟩ := RD.vowCageFirstDaiLoadTargets (R := [vowSelWord I]) rdClear (by simp) have hcodeSizeRaw : - Reasoning.Theory.uniswapExtCodeSizeWord σClearedEvm + Reasoning.Theory.extCodeSizeWord σClearedEvm (UInt256.land solcAddrMask (solcSlotWord σClearedEvm I ⟨1⟩)) = ⟨0⟩ := by simpa [σClearedEvm, kissDaiTargetWord, vowSlotWord, solcSlotWord, u256_land_comm] using hcodeSize @@ -1136,10 +1136,10 @@ theorem vowCageFirstDaiNoCodeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : U have hslot := accountMapEquiv_storage_findD hClearedAccounts I.codeOwner ⟨1⟩ ⟨0⟩ simp [kissDaiTargetWord, vowSlotWord, hslot] have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σClearedSolm + Reasoning.Theory.extCodeSizeWord σClearedSolm (kissDaiTargetWord σClearedSolm I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hClearedAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hClearedAccounts (kissDaiTargetWord σClearedEvm I) rw [← hTargetCleared, ← hsame] simpa [σClearedEvm] using hcodeSize @@ -1168,7 +1168,7 @@ theorem vowCageFirstDaiNoCodeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : U ((evmAsh.lookupAccount (cageVatAddressOf evmAsh)).option 0 (fun acc => acc.code.size))).toNat = 0 := by have hzero := - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := σClearedSolm) (target := kissDaiTargetWord σClearedSolm I) (addr := cageVatAddressOf evmAsh) haddr hcodeSizeSolm simpa [evmAsh, evmSin, evmLive, evm0, initState, State.lookupAccount, @@ -1316,7 +1316,7 @@ theorem vowCageFlapperCageNoCodeBodyCore mem (UInt256.ofNat 6) rdata acc k C) (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord acc.2 target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord acc.2 target = ⟨0⟩) (hov : R.length + 13 ≤ 1024) (hvatCode : let evm0 := initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I @@ -1425,7 +1425,7 @@ theorem vowCageFlopperCageNoCodeBodyCore (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (vowAddressReturnWord ⟨3⟩ acc.2 I) = ⟨0⟩) (hov : R.length + 15 ≤ 1024) (hvatCode : diff --git a/Benchmarks/Dss/Vow/CageTailRuntime.lean b/Benchmarks/Dss/Vow/CageTailRuntime.lean index 699f1144..ab996b49 100644 --- a/Benchmarks/Dss/Vow/CageTailRuntime.lean +++ b/Benchmarks/Dss/Vow/CageTailRuntime.lean @@ -800,7 +800,7 @@ theorem vowCageSecondDaiNoCodeBodyCore (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) (hov : R.length + 16 ≤ 1024) (hvatCode : @@ -1059,7 +1059,7 @@ theorem vowCageVatSinNoCodeBodyCore (ho32 : 32 ≤ outDai2.size) (hosz : outDai2.size < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) (hov : R.length + 18 ≤ 1024) (hvatCode : diff --git a/Benchmarks/Dss/Vow/Common.lean b/Benchmarks/Dss/Vow/Common.lean index 4dbe92ad..abcc3802 100644 --- a/Benchmarks/Dss/Vow/Common.lean +++ b/Benchmarks/Dss/Vow/Common.lean @@ -671,7 +671,7 @@ theorem vowJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {pc : UInt25 have h344 := h.push2 vowDispatchRevertPc hpush (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by simp only [List.length_singleton]; omega) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h344 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h344 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem vowLowLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -695,7 +695,7 @@ theorem vowLowLowNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} |>.selectorArmNotTakenAuto (vowLowLowArmsWellFormed 5 (by omega)) (heq0 5 (by omega)) (by simp) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h344 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h344 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem vowLowHighNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} @@ -1155,7 +1155,7 @@ theorem vowX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem vowX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -1178,7 +1178,7 @@ theorem vowX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h344 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h344 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) end Benchmarks.Dss.Vow diff --git a/Benchmarks/Dss/Vow/Constructor.lean b/Benchmarks/Dss/Vow/Constructor.lean index 1072e8a5..97b7de51 100644 --- a/Benchmarks/Dss/Vow/Constructor.lean +++ b/Benchmarks/Dss/Vow/Constructor.lean @@ -197,7 +197,7 @@ theorem vowCtorNonpayableRDrev (by simp only [List.length_cons, List.length_nil]; omega)) simpa [code, show ((⟨8⟩ : UInt256) + UInt256.ofNat 3 + ⟨1⟩) = ⟨12⟩ from by native_decide] using - RD.uniswapPush1Dup1Revert0 (code := code) (ee := I) (g := g) + RD.solcPush1Dup1Revert0 (code := code) (ee := I) (g := g) (s0 := initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) rd12 (by ctor_decode) (by ctor_decode) (by ctor_decode) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1233,11 +1233,11 @@ theorem vowCtorHopeNoCode (vowCtorWardsHashMem I vat flapper flopper)) (UInt256.ofNat 9) ByteArray.empty (createdAccounts, σFinal) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σFinal (UInt256.land solcAddrMask vatStored) = + Reasoning.Theory.extCodeSizeWord σFinal (UInt256.land solcAddrMask vatStored) = ⟨0⟩) : RDrev (vowCreationBytecode ++ vowCtorArgsTail vat flapper flopper) g (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) := by - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨201⟩) (okPc := ⟨213⟩) rd201 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨201⟩) (okPc := ⟨213⟩) rd201 hcodeSize (by ctor_decode) (by ctor_decode) (by ctor_decode) (by ctor_decode) (by ctor_decode) (by ctor_decode) (by ctor_decode) (by ctor_decode) @@ -1260,7 +1260,7 @@ theorem vowCtorHopeCallReady (vowCtorWardsHashMem I vat flapper flopper)) (UInt256.ofNat 9) ByteArray.empty (createdAccounts, σFinal) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σFinal (UInt256.land solcAddrMask vatStored) ≠ + Reasoning.Theory.extCodeSizeWord σFinal (UInt256.land solcAddrMask vatStored) ≠ ⟨0⟩) : ∃ gasWord k' C', RD (vowCreationBytecode ++ vowCtorArgsTail vat flapper flopper) I g (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) ⟨216⟩ @@ -1273,7 +1273,7 @@ theorem vowCtorHopeCallReady (vowCtorWardsHashMem I vat flapper flopper)) (UInt256.ofNat 9) ByteArray.empty (createdAccounts, σFinal) k' C' := by obtain ⟨gasWord, k', C', rd216⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨201⟩) (okPc := ⟨213⟩) rd201 + RD.solcExtcodesizeGuardOkGas (pc := ⟨201⟩) (okPc := ⟨213⟩) rd201 hcodeSize (by ctor_decode) (by ctor_decode) (by ctor_decode) (by ctor_decode) (by ctor_decode) (by ctor_decode) (by ctor_jump_dest) (by ctor_decode) diff --git a/Benchmarks/Dss/Vow/ConstructorTail.lean b/Benchmarks/Dss/Vow/ConstructorTail.lean index c77e6c8c..00e0f5f2 100644 --- a/Benchmarks/Dss/Vow/ConstructorTail.lean +++ b/Benchmarks/Dss/Vow/ConstructorTail.lean @@ -41,7 +41,7 @@ theorem vowCtorHopeCallFailure (hov : rest.length + 5 ≤ 1024) : RDrev (vowCreationBytecode ++ vowCtorArgsTail vat flapper flopper) g (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨217⟩) (okPc := ⟨233⟩) rd217 + exact RD.solcCallSuccessGuardMissing (pc := ⟨217⟩) (okPc := ⟨233⟩) rd217 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by ctor_tail_decode) (by ctor_tail_decode) (by ctor_tail_decode) (by ctor_tail_decode) (by ctor_tail_decode) (by ctor_tail_decode) (by ctor_tail_decode) (by ctor_tail_decode) @@ -67,7 +67,7 @@ theorem vowCtorHopeCallSuccessToReturnStart [] mem aw out (createdAccounts', sstoreAccountMap I.codeOwner σFinal ⟨12⟩ ⟨1⟩) k' C' := by obtain ⟨_, _, rd235⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨217⟩) (okPc := ⟨233⟩) rd217 + RD.solcCallSuccessGuardOk (pc := ⟨217⟩) (okPc := ⟨233⟩) rd217 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by ctor_tail_decode) (by ctor_tail_decode) (by ctor_tail_decode) (by ctor_tail_decode) (by ctor_tail_decode) (by ctor_tail_jump_dest) (by ctor_tail_decode) (by ctor_tail_decode) @@ -264,11 +264,11 @@ private theorem storageStore_genesisBlockHeader_tail (evm : EVM.State) private theorem ctorExtCodeSize_ne_zero_lookup_code_pos {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => exfalso @@ -290,11 +290,11 @@ private theorem ctorExtCodeSize_ne_zero_lookup_code_pos {σ : AccountMap} {targe private theorem ctorExtCodeSize_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using @@ -534,14 +534,14 @@ theorem vowConstructorCorrect : (genesisBlockHeader := genesisBlockHeader) (blocks := blocks) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := g) vat flapper flopper hAccounts - by_cases hcodeSize : uniswapExtCodeSizeWord σFlopper targetWord = ⟨0⟩ + by_cases hcodeSize : extCodeSizeWord σFlopper targetWord = ⟨0⟩ · have hrev := vowCtorHopeNoCode vat flapper flopper vatStored (by simpa [σFlopper, targetWord] using rd201) (by simpa [targetWord] using hcodeSize) rcases hrev.xiResult hcodeTail with hOOG | ⟨g', out, hRev⟩ · exact constructorEquivalenceFor.outOfGas (by simpa [Sat256.ofUInt256] using hOOG) - · have hcodeSizeSolm : uniswapExtCodeSizeWord evm4s.accountMap targetWord = ⟨0⟩ := by - have hEq := uniswapExtCodeSizeWord_accountMapEquiv hAccounts4 targetWord + · have hcodeSizeSolm : extCodeSizeWord evm4s.accountMap targetWord = ⟨0⟩ := by + have hEq := extCodeSizeWord_accountMapEquiv hAccounts4 targetWord exact hEq ▸ hcodeSize have haddr : vat = AccountAddress.ofUInt256 targetWord := by rw [htargetWord, accountAddress_of_word_val_tail] @@ -558,9 +558,9 @@ theorem vowConstructorCorrect : vat flapper flopper hwv (by simpa [evm0s, evm1s, evm2s, evm3s, evm4s] using hvatNoCode)) ?_ exact ctorResultEquiv.revert rfl rfl - · have hcodeSizeSolmNe : uniswapExtCodeSizeWord evm4s.accountMap targetWord ≠ ⟨0⟩ := by + · have hcodeSizeSolmNe : extCodeSizeWord evm4s.accountMap targetWord ≠ ⟨0⟩ := by intro hzero - have hEq := uniswapExtCodeSizeWord_accountMapEquiv hAccounts4 targetWord + have hEq := extCodeSizeWord_accountMapEquiv hAccounts4 targetWord exact hcodeSize (hEq.trans hzero) have haddr : vat = AccountAddress.ofUInt256 targetWord := by rw [htargetWord, accountAddress_of_word_val_tail] diff --git a/Benchmarks/Dss/Vow/FileAddress.lean b/Benchmarks/Dss/Vow/FileAddress.lean index 93107ae6..23370b52 100644 --- a/Benchmarks/Dss/Vow/FileAddress.lean +++ b/Benchmarks/Dss/Vow/FileAddress.lean @@ -1130,7 +1130,7 @@ theorem RD.vowFileAddressFlapperToNopeCall (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileAddressVatTargetWord σ ee) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (fileAddressVatTargetWord σ ee) ≠ ⟨0⟩) : ∃ gasWord k' C', RD vowBytecode ee g s0 ⟨4299⟩ (gasWord :: fileAddressVatTargetWord σ ee :: fileAddressCallOutSize :: fileAddressCallOutPtr :: fileAddressCallInSize :: fileAddressCallOutPtr :: @@ -1141,7 +1141,7 @@ theorem RD.vowFileAddressFlapperToNopeCall obtain ⟨_, _, rd4284⟩ := RD.vowFileAddressFlapperToNopeExtcodesizeGuard h hmatch hmem hread64 obtain ⟨gasWord, k', C', rd4299⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4284⟩) (okPc := ⟨4296⟩) rd4284 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4284⟩) (okPc := ⟨4296⟩) rd4284 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1158,7 +1158,7 @@ theorem RD.vowFileAddressNopePostCall (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileAddressVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (fileAddressVatTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hperm : I.perm = true) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) @@ -1235,7 +1235,7 @@ theorem RD.vowFileAddressNopeCallFailure (hrdataSize : rdata.size < UInt256.size) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨4300⟩) (okPc := ⟨4316⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨4300⟩) (okPc := ⟨4316⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1257,7 +1257,7 @@ theorem RD.vowFileAddressNopeSuccessStoreFlapper mem (UInt256.ofNat 6) rdata (cA, sstoreAccountMap ee.codeOwner σ ⟨2⟩ (setAddressOffset0Word (solcSlotWord σ ee ⟨2⟩) data)) k' C' := by - obtain ⟨k4318, C4318, rd4318⟩ := RD.uniswapCallSuccessGuardOk + obtain ⟨k4318, C4318, rd4318⟩ := RD.solcCallSuccessGuardOk (pc := ⟨4300⟩) (okPc := ⟨4316⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Vow/FileAddressFlapper.lean b/Benchmarks/Dss/Vow/FileAddressFlapper.lean index edc5a3c0..263752e2 100644 --- a/Benchmarks/Dss/Vow/FileAddressFlapper.lean +++ b/Benchmarks/Dss/Vow/FileAddressFlapper.lean @@ -194,14 +194,14 @@ theorem fileAddressFlapperAddressOf_initState_eq vowSlotWord, solcSlotWord, accountAddress_ofUInt256_eq_ofNat_toNat] -theorem fileAddress_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos +theorem fileAddress_extCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => exfalso @@ -220,14 +220,14 @@ theorem fileAddress_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos · simp [UInt256.toNat, hword] at hzeroNat simpa [hacc] using Nat.pos_of_ne_zero htoNatNe -theorem fileAddress_uniswapExtCodeSizeWord_zero_lookup_code_zero +theorem fileAddress_extCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using @@ -676,7 +676,7 @@ theorem RD.vowFileAddressNopeCallDepthLimit (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileAddressVatTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (fileAddressVatTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨4300⟩ @@ -723,11 +723,11 @@ theorem RD.vowFileAddressNopeNoCode (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileAddressVatTargetWord σ ee) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (fileAddressVatTargetWord σ ee) = ⟨0⟩) : RDrev vowBytecode g s0 := by obtain ⟨_, _, rd4284⟩ := RD.vowFileAddressFlapperToNopeExtcodesizeGuard rd hmatch hmem hread64 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4284⟩) (okPc := ⟨4296⟩) rd4284 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4284⟩) (okPc := ⟨4296⟩) rd4284 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -747,7 +747,7 @@ theorem RD.vowFileAddressNopeSuccessStoreFlapperWithTarget target :: data :: what :: ret :: sel :: []) mem (UInt256.ofNat 6) rdata (cA, fileAddressSetFlapperAccountMap σ ee data) k' C' := by - obtain ⟨k4318, C4318, rd4318⟩ := RD.uniswapCallSuccessGuardOk + obtain ⟨k4318, C4318, rd4318⟩ := RD.solcCallSuccessGuardOk (pc := ⟨4300⟩) (okPc := ⟨4316⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1054,7 +1054,7 @@ theorem RD.vowFileAddressFlapperToHopeCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileAddressVatTargetWord σ ee) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (fileAddressVatTargetWord σ ee) ≠ ⟨0⟩) : ∃ gasWord k' C', RD vowBytecode ee g s0 ⟨4422⟩ (gasWord :: fileAddressVatTargetWord σ ee :: fileAddressCallOutSize :: fileAddressCallOutPtr :: fileAddressCallInSize :: fileAddressCallOutPtr :: @@ -1065,7 +1065,7 @@ theorem RD.vowFileAddressFlapperToHopeCall obtain ⟨_, _, rd4407⟩ := RD.vowFileAddressFlapperToHopeExtcodesizeGuard rd hmem hread64 obtain ⟨gasWord, k', C', rd4422⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4407⟩) (okPc := ⟨4419⟩) rd4407 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4407⟩) (okPc := ⟨4419⟩) rd4407 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1083,7 +1083,7 @@ theorem RD.vowFileAddressFlapperToHopeCallWithTarget (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileAddressVatTargetWord σ ee) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (fileAddressVatTargetWord σ ee) ≠ ⟨0⟩) : ∃ gasWord k' C', RD vowBytecode ee g s0 ⟨4422⟩ (gasWord :: fileAddressVatTargetWord σ ee :: fileAddressCallOutSize :: fileAddressCallOutPtr :: fileAddressCallInSize :: fileAddressCallOutPtr :: @@ -1094,7 +1094,7 @@ theorem RD.vowFileAddressFlapperToHopeCallWithTarget obtain ⟨_, _, rd4407⟩ := RD.vowFileAddressFlapperToHopeExtcodesizeGuardWithTarget rd hmem hread64 obtain ⟨gasWord, k', C', rd4422⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4407⟩) (okPc := ⟨4419⟩) rd4407 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4407⟩) (okPc := ⟨4419⟩) rd4407 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1112,11 +1112,11 @@ theorem RD.vowFileAddressHopeNoCode (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileAddressVatTargetWord σ ee) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (fileAddressVatTargetWord σ ee) = ⟨0⟩) : RDrev vowBytecode g s0 := by obtain ⟨_, _, rd4407⟩ := RD.vowFileAddressFlapperToHopeExtcodesizeGuard rd hmem hread64 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4407⟩) (okPc := ⟨4419⟩) rd4407 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4407⟩) (okPc := ⟨4419⟩) rd4407 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1133,11 +1133,11 @@ theorem RD.vowFileAddressHopeNoCodeWithTarget (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (fileAddressVatTargetWord σ ee) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (fileAddressVatTargetWord σ ee) = ⟨0⟩) : RDrev vowBytecode g s0 := by obtain ⟨_, _, rd4407⟩ := RD.vowFileAddressFlapperToHopeExtcodesizeGuardWithTarget rd hmem hread64 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4407⟩) (okPc := ⟨4419⟩) rd4407 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4407⟩) (okPc := ⟨4419⟩) rd4407 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1155,7 +1155,7 @@ theorem RD.vowFileAddressHopePostCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (fileAddressVatTargetWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (fileAddressVatTargetWord σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hperm : I.perm = true) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) @@ -1222,7 +1222,7 @@ theorem RD.vowFileAddressHopePostCallWithTarget (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (fileAddressVatTargetWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (fileAddressVatTargetWord σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hperm : I.perm = true) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) @@ -1289,7 +1289,7 @@ theorem RD.vowFileAddressHopeCallDepthLimitWithTarget (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (fileAddressVatTargetWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (fileAddressVatTargetWord σ' I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨4423⟩ @@ -1337,7 +1337,7 @@ theorem RD.vowFileAddressNopeSuccessToHopePostCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSizeHope : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (fileAddressSetFlapperAccountMap σNope I data) (fileAddressVatTargetWord (fileAddressSetFlapperAccountMap σNope I data) I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : @@ -1378,7 +1378,7 @@ theorem RD.vowFileAddressHopeCallFailure (hrdataSize : rdata.size < UInt256.size) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨4423⟩) (okPc := ⟨4439⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨4423⟩) (okPc := ⟨4439⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1398,7 +1398,7 @@ theorem RD.vowFileAddressHopeCallSuccessToReturn ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ret [sel] mem aw rdata acc k' C' := by - obtain ⟨_, _, rd4441⟩ := RD.uniswapCallSuccessGuardOk + obtain ⟨_, _, rd4441⟩ := RD.solcCallSuccessGuardOk (pc := ⟨4423⟩) (okPc := ⟨4439⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1445,7 +1445,7 @@ theorem vowFileAddressFlapperNopeNoCodeBodyCore (hauthEvm : vowSlotWord (vowCallerWardsSlot I) σ_evm I = ⟨1⟩) (hwhat : fileAddressWhat I = fileAddressFlapperBytes) (hcodeSizeNope : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (fileAddressVatTargetWord σ_evm I) = ⟨0⟩) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by let locals := fileAddressLocals I @@ -1464,13 +1464,13 @@ theorem vowFileAddressFlapperNopeNoCodeBodyCore fileAddressVatTargetWord σ_evm I = fileAddressVatTargetWord σ_solm I := by simp [fileAddressVatTargetWord, vowAddressReturnWord, hVatWord] have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (fileAddressVatTargetWord σ_solm I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (fileAddressVatTargetWord σ_evm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (fileAddressVatTargetWord σ_evm I) = ⟨0⟩ := by rw [← hsame] exact hcodeSizeNope @@ -1485,7 +1485,7 @@ theorem vowFileAddressFlapperNopeNoCodeBodyCore AccountAddress.ofUInt256 (fileAddressVatTargetWord σ_solm I) := by simpa [evm0] using fileAddressVatAddressOf_initState_eq cA gh bl σ_solm σ₀ A I g have hlookup := - fileAddress_uniswapExtCodeSizeWord_zero_lookup_code_zero + fileAddress_extCodeSizeWord_zero_lookup_code_zero (σ := σ_solm) (target := fileAddressVatTargetWord σ_solm I) (addr := fileAddressVatAddressOf evm0) haddr hcodeSizeSolm simpa [evm0, initState, State.lookupAccount] using hlookup @@ -1575,7 +1575,7 @@ theorem vowFileAddressFlapperHopeNoCodeBodyCore (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSizeHope : - Reasoning.Theory.uniswapExtCodeSizeWord σSet (fileAddressVatTargetWord σSet I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σSet (fileAddressVatTargetWord σSet I) = ⟨0⟩) (hcallNope : typedCallViaEVM config (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) (EVM.address (fileAddressVatAddressOf diff --git a/Benchmarks/Dss/Vow/FileAddressFlapperBody.lean b/Benchmarks/Dss/Vow/FileAddressFlapperBody.lean index 217e10e1..34d83980 100644 --- a/Benchmarks/Dss/Vow/FileAddressFlapperBody.lean +++ b/Benchmarks/Dss/Vow/FileAddressFlapperBody.lean @@ -169,7 +169,7 @@ theorem vowFileAddressFlapperNopeCallDepthLimitBodyCore (hauthEvm : vowSlotWord (vowCallerWardsSlot I) σ_evm I = ⟨1⟩) (hwhat : fileAddressWhat I = fileAddressFlapperBytes) (hcodeSizeNope : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (fileAddressVatTargetWord σ_evm I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by @@ -186,12 +186,12 @@ theorem vowFileAddressFlapperNopeCallDepthLimitBodyCore fileAddressVatTargetWord σ_evm I = fileAddressVatTargetWord σ_solm I := fileAddressVatTargetWord_accountMapEquiv hAccounts I have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (fileAddressVatTargetWord σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeNope have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (fileAddressVatTargetWord σ_evm I) rw [hsame, hVatTargetOrig] exact hzero @@ -207,7 +207,7 @@ theorem vowFileAddressFlapperNopeCallDepthLimitBodyCore AccountAddress.ofUInt256 (fileAddressVatTargetWord σ_solm I) := by simpa [evm0Solm] using fileAddressVatAddressOf_initState_eq cA gh bl σ_solm σ₀ A I g simpa [evm0Solm, initState, State.lookupAccount] using - fileAddress_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + fileAddress_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := fileAddressVatTargetWord σ_solm I) (addr := fileAddressVatAddressOf evm0Solm) haddr hcodeSizeSolm obtain ⟨_, _, hswitch⟩ := RD.vowFileAddressToSwitch hreach hsz68 hsize hauthSolc @@ -271,10 +271,10 @@ theorem vowFileAddressFlapperHopeNoCodeAfterNopeSuccessBodyCore (hauthEvm : vowSlotWord (vowCallerWardsSlot I) σ_evm I = ⟨1⟩) (hwhat : fileAddressWhat I = fileAddressFlapperBytes) (hcodeSizeNope : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (fileAddressVatTargetWord σ_evm I) ≠ ⟨0⟩) (hcodeSizeHope : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) (fileAddressVatTargetWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) I) = ⟨0⟩) : @@ -289,12 +289,12 @@ theorem vowFileAddressFlapperHopeNoCodeAfterNopeSuccessBodyCore fileAddressVatTargetWord σ_evm I = fileAddressVatTargetWord σ_solm I := fileAddressVatTargetWord_accountMapEquiv hAccounts I have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (fileAddressVatTargetWord σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeNope have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (fileAddressVatTargetWord σ_evm I) rw [hsame, hVatTargetOrig] exact hzero @@ -310,7 +310,7 @@ theorem vowFileAddressFlapperHopeNoCodeAfterNopeSuccessBodyCore AccountAddress.ofUInt256 (fileAddressVatTargetWord σ_solm I) := by simpa [evm0Solm] using fileAddressVatAddressOf_initState_eq cA gh bl σ_solm σ₀ A I g simpa [evm0Solm, initState, State.lookupAccount] using - fileAddress_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + fileAddress_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := fileAddressVatTargetWord σ_solm I) (addr := fileAddressVatAddressOf evm0Solm) haddr hcodeSizeSolm obtain ⟨σNopeSolm, ANopeSolm, hcallNopeSolm, hStateNope⟩ := @@ -345,14 +345,14 @@ theorem vowFileAddressFlapperHopeNoCodeAfterNopeSuccessBodyCore fileAddressVatTargetWord evmSetSolm.accountMap I := fileAddressVatTargetWord_accountMapEquiv hAccountsSet I have hcodeSizeHopeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmSetSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSetSolm.accountMap (fileAddressVatTargetWord evmSetSolm.accountMap I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccountsSet + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccountsSet (fileAddressVatTargetWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord evmSetSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSetSolm.accountMap (fileAddressVatTargetWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) I) = ⟨0⟩ := by rw [← hsame] @@ -368,7 +368,7 @@ theorem vowFileAddressFlapperHopeNoCodeAfterNopeSuccessBodyCore AccountAddress.ofUInt256 (fileAddressVatTargetWord evmSetSolm.accountMap I) := fileAddressVatAddressOf_eq_target_of_env evmSetSolm I hEnvSet simpa [evmSetSolm, State.lookupAccount] using - fileAddress_uniswapExtCodeSizeWord_zero_lookup_code_zero + fileAddress_extCodeSizeWord_zero_lookup_code_zero (σ := evmSetSolm.accountMap) (target := fileAddressVatTargetWord evmSetSolm.accountMap I) (addr := fileAddressVatAddressOf evmSetSolm) haddr hcodeSizeHopeSolm @@ -428,10 +428,10 @@ theorem vowFileAddressFlapperHopeCallFailureAfterNopeSuccessBodyCore (hauthEvm : vowSlotWord (vowCallerWardsSlot I) σ_evm I = ⟨1⟩) (hwhat : fileAddressWhat I = fileAddressFlapperBytes) (hcodeSizeNope : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (fileAddressVatTargetWord σ_evm I) ≠ ⟨0⟩) (hcodeSizeHope : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) (fileAddressVatTargetWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) I) ≠ ⟨0⟩) @@ -447,12 +447,12 @@ theorem vowFileAddressFlapperHopeCallFailureAfterNopeSuccessBodyCore fileAddressVatTargetWord σ_evm I = fileAddressVatTargetWord σ_solm I := fileAddressVatTargetWord_accountMapEquiv hAccounts I have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (fileAddressVatTargetWord σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeNope have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (fileAddressVatTargetWord σ_evm I) rw [hsame, hVatTargetOrig] exact hzero @@ -468,7 +468,7 @@ theorem vowFileAddressFlapperHopeCallFailureAfterNopeSuccessBodyCore AccountAddress.ofUInt256 (fileAddressVatTargetWord σ_solm I) := by simpa [evm0Solm] using fileAddressVatAddressOf_initState_eq cA gh bl σ_solm σ₀ A I g simpa [evm0Solm, initState, State.lookupAccount] using - fileAddress_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + fileAddress_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := fileAddressVatTargetWord σ_solm I) (addr := fileAddressVatAddressOf evm0Solm) haddr hcodeSizeSolm obtain ⟨σNopeSolm, ANopeSolm, hcallNopeSolm, hStateNope⟩ := @@ -503,12 +503,12 @@ theorem vowFileAddressFlapperHopeCallFailureAfterNopeSuccessBodyCore fileAddressVatTargetWord evmSetSolm.accountMap I := fileAddressVatTargetWord_accountMapEquiv hAccountsSet I have hcodeSizeHopeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmSetSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSetSolm.accountMap (fileAddressVatTargetWord evmSetSolm.accountMap I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeHope have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccountsSet + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccountsSet (fileAddressVatTargetWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) I) rw [hsame, hTargetSet] @@ -523,7 +523,7 @@ theorem vowFileAddressFlapperHopeCallFailureAfterNopeSuccessBodyCore (fileAddressVatAddressOf (fileAddressSetFlapperEVM evmNopeSolm I))).option 0 (fun acc => acc.code.size))).toNat := by simpa [evmSetSolm, State.lookupAccount] using - fileAddress_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + fileAddress_extCodeSizeWord_ne_zero_lookup_code_pos (σ := evmSetSolm.accountMap) (target := fileAddressVatTargetWord evmSetSolm.accountMap I) (addr := fileAddressVatAddressOf evmSetSolm) haddrHope hcodeSizeHopeSolm @@ -624,10 +624,10 @@ theorem vowFileAddressFlapperHopeSuccessAfterNopeSuccessBodyCore (hauthEvm : vowSlotWord (vowCallerWardsSlot I) σ_evm I = ⟨1⟩) (hwhat : fileAddressWhat I = fileAddressFlapperBytes) (hcodeSizeNope : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (fileAddressVatTargetWord σ_evm I) ≠ ⟨0⟩) (hcodeSizeHope : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) (fileAddressVatTargetWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) I) ≠ ⟨0⟩) @@ -643,12 +643,12 @@ theorem vowFileAddressFlapperHopeSuccessAfterNopeSuccessBodyCore fileAddressVatTargetWord σ_evm I = fileAddressVatTargetWord σ_solm I := fileAddressVatTargetWord_accountMapEquiv hAccounts I have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (fileAddressVatTargetWord σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeNope have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (fileAddressVatTargetWord σ_evm I) rw [hsame, hVatTargetOrig] exact hzero @@ -664,7 +664,7 @@ theorem vowFileAddressFlapperHopeSuccessAfterNopeSuccessBodyCore AccountAddress.ofUInt256 (fileAddressVatTargetWord σ_solm I) := by simpa [evm0Solm] using fileAddressVatAddressOf_initState_eq cA gh bl σ_solm σ₀ A I g simpa [evm0Solm, initState, State.lookupAccount] using - fileAddress_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + fileAddress_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := fileAddressVatTargetWord σ_solm I) (addr := fileAddressVatAddressOf evm0Solm) haddr hcodeSizeSolm obtain ⟨σNopeSolm, ANopeSolm, hcallNopeSolm, hStateNope⟩ := @@ -699,12 +699,12 @@ theorem vowFileAddressFlapperHopeSuccessAfterNopeSuccessBodyCore fileAddressVatTargetWord evmSetSolm.accountMap I := fileAddressVatTargetWord_accountMapEquiv hAccountsSet I have hcodeSizeHopeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmSetSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSetSolm.accountMap (fileAddressVatTargetWord evmSetSolm.accountMap I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeHope have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccountsSet + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccountsSet (fileAddressVatTargetWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) I) rw [hsame, hTargetSet] @@ -719,7 +719,7 @@ theorem vowFileAddressFlapperHopeSuccessAfterNopeSuccessBodyCore (fileAddressVatAddressOf (fileAddressSetFlapperEVM evmNopeSolm I))).option 0 (fun acc => acc.code.size))).toNat := by simpa [evmSetSolm, State.lookupAccount] using - fileAddress_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + fileAddress_extCodeSizeWord_ne_zero_lookup_code_pos (σ := evmSetSolm.accountMap) (target := fileAddressVatTargetWord evmSetSolm.accountMap I) (addr := fileAddressVatAddressOf evmSetSolm) haddrHope hcodeSizeHopeSolm @@ -822,21 +822,21 @@ theorem vowFileAddressFlapperAuthorizedBodyCore twoWordHashMem_read64 (solcSourceWord I) ⟨0⟩ solcFreePtrMem_size solcFreePtrMem_read64 by_cases hcodeSizeNopeZero : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (fileAddressVatTargetWord σ_evm I) = ⟨0⟩ · exact vowFileAddressFlapperNopeNoCodeBodyCore (sel := sel) hcode hwv hperm hsz68 hsize hdispatch hdecode hreach hAccounts hauthEvm hwhat hcodeSizeNopeZero have hcodeSizeNope : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (fileAddressVatTargetWord σ_evm I) ≠ ⟨0⟩ := hcodeSizeNopeZero have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (fileAddressVatTargetWord σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeNope have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (fileAddressVatTargetWord σ_evm I) rw [hsame, hVatTargetOrig] exact hzero @@ -852,7 +852,7 @@ theorem vowFileAddressFlapperAuthorizedBodyCore AccountAddress.ofUInt256 (fileAddressVatTargetWord σ_solm I) := by simpa [evm0Solm] using fileAddressVatAddressOf_initState_eq cA gh bl σ_solm σ₀ A I g simpa [evm0Solm, initState, State.lookupAccount] using - fileAddress_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + fileAddress_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := fileAddressVatTargetWord σ_solm I) (addr := fileAddressVatAddressOf evm0Solm) haddr hcodeSizeSolm by_cases hdepthLt : I.depth.val < 1024 @@ -925,7 +925,7 @@ theorem vowFileAddressFlapperAuthorizedBodyCore UInt256.toByteArray ⟨128⟩ := fileAddressNopeCalldataMem_read64 _ hmemAuth hread64 by_cases hcodeSizeHopeZero : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) (fileAddressVatTargetWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) I) = ⟨0⟩ @@ -933,7 +933,7 @@ theorem vowFileAddressFlapperAuthorizedBodyCore hcode hwv hperm hdispatch hdecode rd4300True hmemNope hreadNope hcallNopeTrue hAccounts hauthEvm hwhat hcodeSizeNope hcodeSizeHopeZero have hcodeSizeHope : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) (fileAddressVatTargetWord (fileAddressSetFlapperAccountMap σNope I (fileAddressDataKey I)) I) ≠ ⟨0⟩ := diff --git a/Benchmarks/Dss/Vow/Flap.lean b/Benchmarks/Dss/Vow/Flap.lean index cf3a6866..52fffa83 100644 --- a/Benchmarks/Dss/Vow/Flap.lean +++ b/Benchmarks/Dss/Vow/Flap.lean @@ -129,7 +129,7 @@ theorem RD.vowFlapToSin0ExtcodesizeGuard dup2, raw mstore 6 (healSinSelectorMem solcFreePtrMem) (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov), - uniswapAddress, + address, push1 ⟨4⟩, dup3, add, @@ -183,11 +183,11 @@ theorem RD.vowFlapVatSin0NoCode (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨349⟩ [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd921⟩ := RD.vowFlapToSin0ExtcodesizeGuard hreach - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨921⟩) (okPc := ⟨933⟩) rd921 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨921⟩) (okPc := ⟨933⟩) rd921 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -199,7 +199,7 @@ theorem RD.vowFlapToSin0Staticcall (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨349⟩ [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : ∃ gasWord k C, RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨936⟩ (gasWord :: kissDaiTargetWord σ I :: healSinOutPtr :: @@ -208,7 +208,7 @@ theorem RD.vowFlapToSin0Staticcall (healSinCalldataMem I solcFreePtrMem) (UInt256.ofNat 6) ByteArray.empty (cA, σ) k C := by obtain ⟨_, _, rd921⟩ := RD.vowFlapToSin0ExtcodesizeGuard hreach obtain ⟨gasWord, k, C, rd936⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨921⟩) (okPc := ⟨933⟩) rd921 + RD.solcExtcodesizeGuardOkGas (pc := ⟨921⟩) (okPc := ⟨933⟩) rd921 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -221,7 +221,7 @@ theorem RD.vowFlapSin0PostCall (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨349⟩ [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (o : ByteArray) (A' : Substate) (k C : ℕ), @@ -240,7 +240,7 @@ theorem RD.vowFlapSin0PostCall obtain ⟨gasWord, _, _, rd936⟩ := RD.vowFlapToSin0Staticcall hreach hcodeSize obtain ⟨cA', σ', z, o, A_in, callGas, k937, C937, hΘpack, rd937raw, hosz⟩ := - RD.uniswapStaticcall rd936 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall rd936 (by native_decide) hdepth (by evm_ov) obtain ⟨g'', A', hΘ⟩ := hΘpack refine ⟨cA', σ', z, o, A', k937, C937, ?_, ?_, hosz⟩ · have haw : @@ -275,7 +275,7 @@ theorem RD.vowFlapSin0CallDepthLimit (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨349⟩ [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨937⟩ @@ -285,7 +285,7 @@ theorem RD.vowFlapSin0CallDepthLimit (cA, σ) k' C' := by obtain ⟨_, _, _, rd936⟩ := RD.vowFlapToSin0Staticcall hreach hcodeSize obtain ⟨k937, C937, rd937raw⟩ := - RD.uniswapStaticcallDepthLimit rd936 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcallDepthLimit rd936 (by native_decide) hdepth (by evm_ov) have haw : UInt256.ofNat (MachineState.M (MachineState.M (UInt256.ofNat 6).toNat healSinOutPtr.toNat healSinInSize.toNat) @@ -318,7 +318,7 @@ theorem RD.vowFlapSin0CallFailure (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨937⟩) (okPc := ⟨953⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨937⟩) (okPc := ⟨953⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -336,7 +336,7 @@ theorem RD.vowFlapSin0CallSuccessToDecode ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨955⟩ (d0 :: d1 :: d2 :: R) mem aw o acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨937⟩) (okPc := ⟨953⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨937⟩) (okPc := ⟨953⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -533,7 +533,7 @@ theorem vowFlapVatSin0NoCodeBodyCore solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ_evm) k C) (hAccounts : accountMapEquiv σ_evm σ_solm) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by have hrev := RD.vowFlapVatSin0NoCode hreach hcodeSize have hVat : vowSlotWord ⟨1⟩ σ_evm I = vowSlotWord ⟨1⟩ σ_solm I := @@ -541,9 +541,9 @@ theorem vowFlapVatSin0NoCodeBodyCore have hTarget : kissDaiTargetWord σ_evm I = kissDaiTargetWord σ_solm I := by simp [kissDaiTargetWord, hVat] have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (kissDaiTargetWord σ_evm I) rw [← hTarget, ← hsame] exact hcodeSize @@ -556,7 +556,7 @@ theorem vowFlapVatSin0NoCodeBodyCore (((initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [initState, State.lookupAccount] using - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := σ_solm) (target := kissDaiTargetWord σ_solm I) (addr := kissVatAddress σ_solm I) haddr hcodeSizeSolm have hbody := vowFlapSourceVatSin0NoCode (cA := cA) (gh := gh) (bl := bl) diff --git a/Benchmarks/Dss/Vow/FlapBody.lean b/Benchmarks/Dss/Vow/FlapBody.lean index 07049532..368a136f 100644 --- a/Benchmarks/Dss/Vow/FlapBody.lean +++ b/Benchmarks/Dss/Vow/FlapBody.lean @@ -218,13 +218,13 @@ theorem flapFlapperAddressOf_eq_vowAddressReturnWord (evm : EVM.State) theorem flapFlapperCode_pos_of_codeSize_ne (evm : EVM.State) (I : ExecutionEnv) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (vowAddressReturnWord ⟨2⟩ evm.accountMap I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (flapFlapperAddressOf evm)).option 0 (fun acc => acc.code.size))).toNat := by simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := evm.accountMap) (target := vowAddressReturnWord ⟨2⟩ evm.accountMap I) (addr := flapFlapperAddressOf evm) (flapFlapperAddressOf_eq_vowAddressReturnWord evm I howner) hne @@ -232,13 +232,13 @@ theorem flapFlapperCode_pos_of_codeSize_ne (evm : EVM.State) (I : ExecutionEnv) theorem flapFlapperCode_zero_of_codeSize_zero (evm : EVM.State) (I : ExecutionEnv) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (vowAddressReturnWord ⟨2⟩ evm.accountMap I) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (flapFlapperAddressOf evm)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := evm.accountMap) (target := vowAddressReturnWord ⟨2⟩ evm.accountMap I) (addr := flapFlapperAddressOf evm) (flapFlapperAddressOf_eq_vowAddressReturnWord evm I howner) hzero diff --git a/Benchmarks/Dss/Vow/FlapDai.lean b/Benchmarks/Dss/Vow/FlapDai.lean index 4037e765..d6e6cc0f 100644 --- a/Benchmarks/Dss/Vow/FlapDai.lean +++ b/Benchmarks/Dss/Vow/FlapDai.lean @@ -66,7 +66,7 @@ theorem RD.vowFlapToDai0ExtcodesizeGuard dup2, raw mstore 0 (vatDaiSelectorMem mem) (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov), - uniswapAddress, + address, push1 ⟨4⟩, dup3, add, @@ -119,11 +119,11 @@ theorem RD.vowFlapDai0NoCode (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd1056⟩ := RD.vowFlapToDai0ExtcodesizeGuard rd hmem hread64 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1056⟩) (okPc := ⟨1068⟩) rd1056 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1056⟩) (okPc := ⟨1068⟩) rd1056 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -140,7 +140,7 @@ theorem RD.vowFlapToDai0Staticcall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1071⟩ (gasWord :: kissDaiTargetWord acc.2 I :: ⟨128⟩ :: ⟨36⟩ :: @@ -149,7 +149,7 @@ theorem RD.vowFlapToDai0Staticcall (vatDaiCalldataMem I mem) (UInt256.ofNat 6) o acc k' C' := by obtain ⟨_, _, rd1056⟩ := RD.vowFlapToDai0ExtcodesizeGuard rd hmem hread64 obtain ⟨gasWord, k1071, C1071, rd1071⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1056⟩) (okPc := ⟨1068⟩) rd1056 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1056⟩) (okPc := ⟨1068⟩) rd1056 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -167,7 +167,7 @@ theorem RD.vowFlapDai0PostCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (outDai : ByteArray) (A' : Substate) (k' C' : ℕ), @@ -194,7 +194,7 @@ theorem RD.vowFlapDai0PostCall RD.vowFlapToDai0Staticcall rd hmem hread64 hcodeSize obtain ⟨cA', σ', z, outDai, A_in, callGas, k1072, C1072, hΘpack, rd1072raw, hosz⟩ := - RD.uniswapStaticcall rd1071 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall rd1071 (by native_decide) hdepth (by evm_ov) obtain ⟨g'', A', hΘ⟩ := hΘpack let evmDaiIn := { initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I with accountMap := acc.2 @@ -227,7 +227,7 @@ theorem RD.vowFlapDai0CallFailure (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1072⟩) (okPc := ⟨1088⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨1072⟩) (okPc := ⟨1088⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -245,7 +245,7 @@ theorem RD.vowFlapDai0CallSuccessToDecode ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1090⟩ (d0 :: d1 :: d2 :: R) mem aw o acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨1072⟩) (okPc := ⟨1088⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨1072⟩) (okPc := ⟨1088⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Vow/FlapDaiBody.lean b/Benchmarks/Dss/Vow/FlapDaiBody.lean index f8d11af1..7686a7e0 100644 --- a/Benchmarks/Dss/Vow/FlapDaiBody.lean +++ b/Benchmarks/Dss/Vow/FlapDaiBody.lean @@ -425,7 +425,7 @@ theorem vowFlapDai0NoCodeBodyCore (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) (hvatCode : 0 < (UInt256.ofNat (((initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).lookupAccount diff --git a/Benchmarks/Dss/Vow/FlapKick.lean b/Benchmarks/Dss/Vow/FlapKick.lean index f07d84eb..ddf8dabe 100644 --- a/Benchmarks/Dss/Vow/FlapKick.lean +++ b/Benchmarks/Dss/Vow/FlapKick.lean @@ -317,14 +317,14 @@ theorem RD.vowFlapKickNoCode (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (vowAddressReturnWord ⟨2⟩ acc.2 I) = ⟨0⟩) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by let target := vowAddressReturnWord ⟨2⟩ acc.2 I let bump := vowSlotWord ⟨10⟩ acc.2 I obtain ⟨_, _, rd1482⟩ := RD.vowFlapToKickExtcodesizeGuard rd hmem hread64 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1482⟩) (okPc := ⟨1494⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1482⟩) (okPc := ⟨1494⟩) (by simpa [target, bump] using rd1482) (by simpa [target] using hcodeSize) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -342,7 +342,7 @@ theorem RD.vowFlapKickCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (vowAddressReturnWord ⟨2⟩ acc.2 I) ≠ ⟨0⟩) : let target := vowAddressReturnWord ⟨2⟩ acc.2 I let bump := vowSlotWord ⟨10⟩ acc.2 I @@ -356,7 +356,7 @@ theorem RD.vowFlapKickCall intro target bump obtain ⟨_, _, rd1482⟩ := RD.vowFlapToKickExtcodesizeGuard rd hmem hread64 obtain ⟨gasWord, k', C', rd1497⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1482⟩) (okPc := ⟨1494⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨1482⟩) (okPc := ⟨1494⟩) (by simpa [target, bump] using rd1482) (by simpa [target] using hcodeSize) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -375,7 +375,7 @@ theorem RD.vowFlapKickPostCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (vowAddressReturnWord ⟨2⟩ acc.2 I) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) : @@ -468,7 +468,7 @@ theorem RD.vowFlapKickCallFailure (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1498⟩) (okPc := ⟨1514⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨1498⟩) (okPc := ⟨1514⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -486,7 +486,7 @@ theorem RD.vowFlapKickCallSuccessToDecode ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1516⟩ (d0 :: d1 :: d2 :: R) mem aw o acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨1498⟩) (okPc := ⟨1514⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨1498⟩) (okPc := ⟨1514⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Vow/FlapKickBody.lean b/Benchmarks/Dss/Vow/FlapKickBody.lean index 2c58d13f..78dfbb47 100644 --- a/Benchmarks/Dss/Vow/FlapKickBody.lean +++ b/Benchmarks/Dss/Vow/FlapKickBody.lean @@ -225,7 +225,7 @@ theorem vowFlapKickNoCodeBodyCore (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hflapperNoCodeEvm : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 + Reasoning.Theory.extCodeSizeWord acc.2 (vowAddressReturnWord ⟨2⟩ acc.2 I) = ⟨0⟩) (hvatCode0 : 0 < (UInt256.ofNat diff --git a/Benchmarks/Dss/Vow/FlapRuntime.lean b/Benchmarks/Dss/Vow/FlapRuntime.lean index 61abdea8..dbac8cc6 100644 --- a/Benchmarks/Dss/Vow/FlapRuntime.lean +++ b/Benchmarks/Dss/Vow/FlapRuntime.lean @@ -17,14 +17,14 @@ theorem flapFlapperTargetWord_accountMapEquiv {σ τ : AccountMap} {I : Executio theorem flapFlapperCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (vowAddressReturnWord ⟨2⟩ σ I) ≠ + Reasoning.Theory.extCodeSizeWord σ (vowAddressReturnWord ⟨2⟩ σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (vowAddressReturnWord ⟨2⟩ τ I) ≠ + Reasoning.Theory.extCodeSizeWord τ (vowAddressReturnWord ⟨2⟩ τ I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (vowAddressReturnWord ⟨2⟩ σ I) have htarget : vowAddressReturnWord ⟨2⟩ σ I = vowAddressReturnWord ⟨2⟩ τ I := flapFlapperTargetWord_accountMapEquiv hAccounts @@ -34,12 +34,12 @@ theorem flapFlapperCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : Executi theorem flapFlapperCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (vowAddressReturnWord ⟨2⟩ σ I) = + Reasoning.Theory.extCodeSizeWord σ (vowAddressReturnWord ⟨2⟩ σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (vowAddressReturnWord ⟨2⟩ τ I) = + Reasoning.Theory.extCodeSizeWord τ (vowAddressReturnWord ⟨2⟩ τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (vowAddressReturnWord ⟨2⟩ σ I) have htarget : vowAddressReturnWord ⟨2⟩ σ I = vowAddressReturnWord ⟨2⟩ τ I := flapFlapperTargetWord_accountMapEquiv hAccounts @@ -57,7 +57,7 @@ theorem vowFlapSin0CallDepthLimitBody (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨349⟩ [vowSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ_evm) k C) (hcodeSizeSinNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) ≠ + Reasoning.Theory.extCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) ≠ ⟨0⟩) (hvatCodeSolm : 0 < (UInt256.ofNat @@ -354,14 +354,14 @@ theorem vowFlapBodyPrefix (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hwv hsz4 hsize hsel by_cases hcodeSizeSin : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩ · exact vowFlapVatSin0NoCodeBodyCore hcode hwv hdispatch hdecode hreach hAccounts hcodeSizeSin have hcodeSizeSinNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) ≠ ⟨0⟩ := hcodeSizeSin have hcodeSizeSinSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) ≠ + Reasoning.Theory.extCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) ≠ ⟨0⟩ := kissDaiCodeSize_ne_accountMapEquiv hAccounts hcodeSizeSinNE have hvatCodeSolm : @@ -683,10 +683,10 @@ theorem vowFlapBodyToSin1 apply Fin.ext simp [kissVatAddress, vowAddressReturnWord, hslotVatSin] by_cases hcodeSizeDai : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) = + Reasoning.Theory.extCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) = ⟨0⟩ · have hcodeSizeDaiSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmSinSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSinSolm.accountMap (kissDaiTargetWord evmSinSolm.accountMap I) = ⟨0⟩ := kissDaiCodeSize_zero_accountMapEquiv hAccountsSin hcodeSizeDai have hvatNoCodeDai : @@ -694,7 +694,7 @@ theorem vowFlapBodyToSin1 ((evmSinSolm.lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := evmSinSolm.accountMap) (target := kissDaiTargetWord evmSinSolm.accountMap I) (addr := kissVatAddress σ_solm I) haddrDai hcodeSizeDaiSolm @@ -703,11 +703,11 @@ theorem vowFlapBodyToSin1 hcodeSizeDai hvatCodeSolm hcallSinSolm hdecSin hBumpLoad hsurplus0 hfit0 hHumpLoad hsurplusNeed hfitNeed hvatLoadSin hvatNoCodeDai have hcodeSizeDaiNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) ≠ + Reasoning.Theory.extCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) ≠ ⟨0⟩ := hcodeSizeDai have hcodeSizeDaiSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmSinSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSinSolm.accountMap (kissDaiTargetWord evmSinSolm.accountMap I) ≠ ⟨0⟩ := kissDaiCodeSize_ne_accountMapEquiv hAccountsSin hcodeSizeDaiNE have hvatCodeDai : @@ -715,7 +715,7 @@ theorem vowFlapBodyToSin1 ((evmSinSolm.lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := evmSinSolm.accountMap) (target := kissDaiTargetWord evmSinSolm.accountMap I) (addr := kissVatAddress σ_solm I) haddrDai hcodeSizeDaiSolmNE @@ -989,10 +989,10 @@ theorem vowFlapBodyToSub rw [hDaiAcc, hSlotDaiStatic ⟨1⟩] simp [kissVatAddress, vowAddressReturnWord, hslot] by_cases hcodeSizeSin1 : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dai (kissDaiTargetWord σ_dai I) = + Reasoning.Theory.extCodeSizeWord σ_dai (kissDaiTargetWord σ_dai I) = ⟨0⟩ · have hcodeSizeSin1Solm : - Reasoning.Theory.uniswapExtCodeSizeWord evmDaiSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmDaiSolm.accountMap (kissDaiTargetWord evmDaiSolm.accountMap I) = ⟨0⟩ := kissDaiCodeSize_zero_accountMapEquiv hAccountsDai hcodeSizeSin1 have hvatNoCodeSin1 : @@ -1000,7 +1000,7 @@ theorem vowFlapBodyToSub ((evmDaiSolm.lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := evmDaiSolm.accountMap) (target := kissDaiTargetWord evmDaiSolm.accountMap I) (addr := kissVatAddress σ_solm I) haddrSin1 hcodeSizeSin1Solm @@ -1011,11 +1011,11 @@ theorem vowFlapBodyToSub hsurplusNeed hfitNeed hvatLoadSin hvatCodeDai hcallDaiSolm hdecDai henough hvatLoadDai hvatNoCodeSin1 have hcodeSizeSin1NE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dai (kissDaiTargetWord σ_dai I) ≠ + Reasoning.Theory.extCodeSizeWord σ_dai (kissDaiTargetWord σ_dai I) ≠ ⟨0⟩ := hcodeSizeSin1 have hcodeSizeSin1SolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmDaiSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmDaiSolm.accountMap (kissDaiTargetWord evmDaiSolm.accountMap I) ≠ ⟨0⟩ := kissDaiCodeSize_ne_accountMapEquiv hAccountsDai hcodeSizeSin1NE have hvatCodeSin1 : @@ -1023,7 +1023,7 @@ theorem vowFlapBodyToSub ((evmDaiSolm.lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := evmDaiSolm.accountMap) (target := kissDaiTargetWord evmDaiSolm.accountMap I) (addr := kissVatAddress σ_solm I) haddrSin1 hcodeSizeSin1SolmNE @@ -1371,10 +1371,10 @@ theorem vowFlapBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hownerSin1 : evmSin1.executionEnv.codeOwner = I.codeOwner := by simp [henvSin1] by_cases hcodeSizeKick : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sin1 (vowAddressReturnWord ⟨2⟩ σ_sin1 I) = + Reasoning.Theory.extCodeSizeWord σ_sin1 (vowAddressReturnWord ⟨2⟩ σ_sin1 I) = ⟨0⟩ · have hcodeSizeKickSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmSin1.accountMap + Reasoning.Theory.extCodeSizeWord evmSin1.accountMap (vowAddressReturnWord ⟨2⟩ evmSin1.accountMap I) = ⟨0⟩ := flapFlapperCodeSize_zero_accountMapEquiv hAccountsSin1 hcodeSizeKick have hflapperNoCode : @@ -1390,11 +1390,11 @@ theorem vowFlapBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} henough hvatLoadDai hvatCodeSin1 hcallSin1 hdecSin1 hSinLoad hfree hfreeOk hAshLoad hdebt hdebtOk hdebtZero hflapperNoCode have hcodeSizeKickNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sin1 (vowAddressReturnWord ⟨2⟩ σ_sin1 I) ≠ + Reasoning.Theory.extCodeSizeWord σ_sin1 (vowAddressReturnWord ⟨2⟩ σ_sin1 I) ≠ ⟨0⟩ := hcodeSizeKick have hcodeSizeKickSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmSin1.accountMap + Reasoning.Theory.extCodeSizeWord evmSin1.accountMap (vowAddressReturnWord ⟨2⟩ evmSin1.accountMap I) ≠ ⟨0⟩ := flapFlapperCodeSize_ne_accountMapEquiv hAccountsSin1 hcodeSizeKickNE have hflapperCode : diff --git a/Benchmarks/Dss/Vow/FlapSin1.lean b/Benchmarks/Dss/Vow/FlapSin1.lean index 27c70d55..eeba1e71 100644 --- a/Benchmarks/Dss/Vow/FlapSin1.lean +++ b/Benchmarks/Dss/Vow/FlapSin1.lean @@ -64,7 +64,7 @@ theorem RD.vowFlapToSin1ExtcodesizeGuard dup2, raw mstore 0 (healSinSelectorMem mem) (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov), - uniswapAddress, + address, push1 ⟨4⟩, dup3, add, @@ -120,11 +120,11 @@ theorem RD.vowFlapSin1NoCode (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd1261⟩ := RD.vowFlapToSin1ExtcodesizeGuard rd hmem hread64 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1261⟩) (okPc := ⟨1273⟩) rd1261 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1261⟩) (okPc := ⟨1273⟩) rd1261 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -140,7 +140,7 @@ theorem RD.vowFlapToSin1Staticcall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1276⟩ (gasWord :: kissDaiTargetWord acc.2 I :: healSinOutPtr :: healSinInSize :: @@ -149,7 +149,7 @@ theorem RD.vowFlapToSin1Staticcall (healSinCalldataMem I mem) (UInt256.ofNat 6) o acc k' C' := by obtain ⟨_, _, rd1261⟩ := RD.vowFlapToSin1ExtcodesizeGuard rd hmem hread64 obtain ⟨gasWord, k1276, C1276, rd1276⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1261⟩) (okPc := ⟨1273⟩) rd1261 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1261⟩) (okPc := ⟨1273⟩) rd1261 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -166,7 +166,7 @@ theorem RD.vowFlapSin1PostCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (out : ByteArray) (A' : Substate) (k' C' : ℕ), @@ -187,7 +187,7 @@ theorem RD.vowFlapSin1PostCall obtain ⟨gasWord, _, _, rd1276⟩ := RD.vowFlapToSin1Staticcall rd hmem hread64 hcodeSize obtain ⟨cA', σ', z, out, A_in, callGas, k1277, C1277, hΘpack, rd1277raw, houtsz⟩ := - RD.uniswapStaticcall rd1276 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall rd1276 (by native_decide) hdepth (by evm_ov) obtain ⟨g'', A', hΘ⟩ := hΘpack refine ⟨cA', σ', z, out, A', k1277, C1277, ?_, ?_, houtsz⟩ · have haw : @@ -229,7 +229,7 @@ theorem RD.vowFlapSin1CallFailure (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1277⟩) (okPc := ⟨1293⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨1277⟩) (okPc := ⟨1293⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -247,7 +247,7 @@ theorem RD.vowFlapSin1CallSuccessToDecode ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1295⟩ (d0 :: d1 :: d2 :: R) mem aw o acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨1277⟩) (okPc := ⟨1293⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨1277⟩) (okPc := ⟨1293⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Vow/FlapSin1Body.lean b/Benchmarks/Dss/Vow/FlapSin1Body.lean index e99c9615..033edf13 100644 --- a/Benchmarks/Dss/Vow/FlapSin1Body.lean +++ b/Benchmarks/Dss/Vow/FlapSin1Body.lean @@ -219,7 +219,7 @@ theorem vowFlapSin1NoCodeBodyCore (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) (hvatCode0 : 0 < (UInt256.ofNat (((initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).lookupAccount diff --git a/Benchmarks/Dss/Vow/Flop.lean b/Benchmarks/Dss/Vow/Flop.lean index a9748901..58e9e33f 100644 --- a/Benchmarks/Dss/Vow/Flop.lean +++ b/Benchmarks/Dss/Vow/Flop.lean @@ -188,7 +188,7 @@ theorem RD.vowFlopToSin0ExtcodesizeGuard dup2, raw mstore 6 (healSinSelectorMem solcFreePtrMem) (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov), - uniswapAddress, + address, push1 ⟨4⟩, dup3, add, @@ -242,11 +242,11 @@ theorem RD.vowFlopVatSin0NoCode (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨646⟩ [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd3663⟩ := RD.vowFlopToSin0ExtcodesizeGuard hreach - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3663⟩) (okPc := ⟨1273⟩) rd3663 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3663⟩) (okPc := ⟨1273⟩) rd3663 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -258,7 +258,7 @@ theorem RD.vowFlopToSin0Staticcall (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨646⟩ [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : ∃ gasWord k C, RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1276⟩ (gasWord :: kissDaiTargetWord σ I :: healSinOutPtr :: @@ -267,7 +267,7 @@ theorem RD.vowFlopToSin0Staticcall (healSinCalldataMem I solcFreePtrMem) (UInt256.ofNat 6) ByteArray.empty (cA, σ) k C := by obtain ⟨_, _, rd3663⟩ := RD.vowFlopToSin0ExtcodesizeGuard hreach obtain ⟨gasWord, k, C, rd1276⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3663⟩) (okPc := ⟨1273⟩) rd3663 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3663⟩) (okPc := ⟨1273⟩) rd3663 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -280,7 +280,7 @@ theorem RD.vowFlopSin0PostCall (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨646⟩ [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (o : ByteArray) (A' : Substate) (k C : ℕ), @@ -299,7 +299,7 @@ theorem RD.vowFlopSin0PostCall obtain ⟨gasWord, _, _, rd1276⟩ := RD.vowFlopToSin0Staticcall hreach hcodeSize obtain ⟨cA', σ', z, o, A_in, callGas, k1277, C1277, hΘpack, rd1277raw, hosz⟩ := - RD.uniswapStaticcall rd1276 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall rd1276 (by native_decide) hdepth (by evm_ov) obtain ⟨g'', A', hΘ⟩ := hΘpack refine ⟨cA', σ', z, o, A', k1277, C1277, ?_, ?_, hosz⟩ · have haw : @@ -779,7 +779,7 @@ theorem RD.vowFlopToDai1ExtcodesizeGuard dup2, raw mstore 0 (vatDaiSelectorMem mem) (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov), - uniswapAddress, + address, push1 ⟨4⟩, dup3, add, @@ -833,12 +833,12 @@ theorem RD.vowFlopDai1NoCode (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd3816⟩ := RD.vowFlopToDai1ExtcodesizeGuard rd henough hmem hread64 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨3816⟩) (okPc := ⟨3828⟩) rd3816 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨3816⟩) (okPc := ⟨3828⟩) rd3816 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -856,7 +856,7 @@ theorem RD.vowFlopToDai1Staticcall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨3831⟩ (gasWord :: kissDaiTargetWord acc.2 I :: ⟨128⟩ :: ⟨36⟩ :: @@ -866,7 +866,7 @@ theorem RD.vowFlopToDai1Staticcall obtain ⟨_, _, rd3816⟩ := RD.vowFlopToDai1ExtcodesizeGuard rd henough hmem hread64 obtain ⟨gasWord, k3831, C3831, rd3831⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨3816⟩) (okPc := ⟨3828⟩) rd3816 + RD.solcExtcodesizeGuardOkGas (pc := ⟨3816⟩) (okPc := ⟨3828⟩) rd3816 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -1312,7 +1312,7 @@ theorem vowFlopVatSin0NoCodeBodyCore solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ_evm) k C) (hAccounts : accountMapEquiv σ_evm σ_solm) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by have hrev := RD.vowFlopVatSin0NoCode hreach hcodeSize have hVat : vowSlotWord ⟨1⟩ σ_evm I = vowSlotWord ⟨1⟩ σ_solm I := @@ -1320,9 +1320,9 @@ theorem vowFlopVatSin0NoCodeBodyCore have hTarget : kissDaiTargetWord σ_evm I = kissDaiTargetWord σ_solm I := by simp [kissDaiTargetWord, hVat] have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (kissDaiTargetWord σ_evm I) rw [← hTarget, ← hsame] exact hcodeSize @@ -1335,7 +1335,7 @@ theorem vowFlopVatSin0NoCodeBodyCore (((initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [initState, State.lookupAccount] using - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := σ_solm) (target := kissDaiTargetWord σ_solm I) (addr := kissVatAddress σ_solm I) haddr hcodeSizeSolm have hbody := vowFlopSourceVatSin0NoCode (cA := cA) (gh := gh) (bl := bl) diff --git a/Benchmarks/Dss/Vow/FlopAsh.lean b/Benchmarks/Dss/Vow/FlopAsh.lean index 98c9707b..c0942e3f 100644 --- a/Benchmarks/Dss/Vow/FlopAsh.lean +++ b/Benchmarks/Dss/Vow/FlopAsh.lean @@ -1121,7 +1121,7 @@ theorem RD.vowFlopToKickExtcodesizeGuard dup2, raw mstore 0 (flopKickSelectorMem mem) (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov), - uniswapAddress, + address, push1 ⟨4⟩, dup3, add, @@ -1220,7 +1220,7 @@ theorem RD.vowFlopKickNoCode (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : let σAsh := sstoreAccountMap I.codeOwner acc.2 ⟨6⟩ AshNew - Reasoning.Theory.uniswapExtCodeSizeWord σAsh + Reasoning.Theory.extCodeSizeWord σAsh (vowAddressReturnWord ⟨3⟩ σAsh I) = ⟨0⟩) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by @@ -1230,7 +1230,7 @@ theorem RD.vowFlopKickNoCode let sump := vowSlotWord ⟨9⟩ σAsh I obtain ⟨_, _, rd4048⟩ := RD.vowFlopToKickExtcodesizeGuard rd hperm hmem hread64 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4048⟩) (okPc := ⟨1494⟩) + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4048⟩) (okPc := ⟨1494⟩) (by simpa [σAsh, target, dump, sump] using rd4048) (by simpa [σAsh, target] using hcodeSize) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1250,7 +1250,7 @@ theorem RD.vowFlopKickCall (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : let σAsh := sstoreAccountMap I.codeOwner acc.2 ⟨6⟩ AshNew - Reasoning.Theory.uniswapExtCodeSizeWord σAsh + Reasoning.Theory.extCodeSizeWord σAsh (vowAddressReturnWord ⟨3⟩ σAsh I) ≠ ⟨0⟩) : let σAsh := sstoreAccountMap I.codeOwner acc.2 ⟨6⟩ AshNew let target := vowAddressReturnWord ⟨3⟩ σAsh I @@ -1267,7 +1267,7 @@ theorem RD.vowFlopKickCall obtain ⟨_, _, rd4048⟩ := RD.vowFlopToKickExtcodesizeGuard rd hperm hmem hread64 obtain ⟨gasWord, k', C', rd1497⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4048⟩) (okPc := ⟨1494⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨4048⟩) (okPc := ⟨1494⟩) (by simpa [σAsh, target, dump, sump] using rd4048) (by simpa [σAsh, target] using hcodeSize) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1288,7 +1288,7 @@ theorem RD.vowFlopKickPostCall (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : let σAsh := sstoreAccountMap I.codeOwner acc.2 ⟨6⟩ AshNew - Reasoning.Theory.uniswapExtCodeSizeWord σAsh + Reasoning.Theory.extCodeSizeWord σAsh (vowAddressReturnWord ⟨3⟩ σAsh I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : let σAsh := sstoreAccountMap I.codeOwner acc.2 ⟨6⟩ AshNew @@ -1385,7 +1385,7 @@ theorem RD.vowFlopKickCallFailure (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1498⟩) (okPc := ⟨1514⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨1498⟩) (okPc := ⟨1514⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1403,7 +1403,7 @@ theorem RD.vowFlopKickCallSuccessToDecode ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1516⟩ (d0 :: d1 :: d2 :: R) mem aw o acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨1498⟩) (okPc := ⟨1514⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨1498⟩) (okPc := ⟨1514⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) diff --git a/Benchmarks/Dss/Vow/FlopBody.lean b/Benchmarks/Dss/Vow/FlopBody.lean index b443739e..e9c084cf 100644 --- a/Benchmarks/Dss/Vow/FlopBody.lean +++ b/Benchmarks/Dss/Vow/FlopBody.lean @@ -27,12 +27,12 @@ theorem kissVatAddress_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} theorem kissDaiCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (kissDaiTargetWord τ I) ≠ ⟨0⟩ := by + (hne : Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (kissDaiTargetWord τ I) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (kissDaiTargetWord σ I) have htarget : kissDaiTargetWord σ I = kissDaiTargetWord τ I := kissDaiTargetWord_accountMapEquiv hAccounts @@ -41,10 +41,10 @@ theorem kissDaiCodeSize_ne_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEn theorem kissDaiCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : ExecutionEnv} (hAccounts : accountMapEquiv σ τ) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (kissDaiTargetWord τ I) = ⟨0⟩ := by + (hzero : Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (kissDaiTargetWord τ I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (kissDaiTargetWord σ I) have htarget : kissDaiTargetWord σ I = kissDaiTargetWord τ I := kissDaiTargetWord_accountMapEquiv hAccounts @@ -52,22 +52,22 @@ theorem kissDaiCodeSize_zero_accountMapEquiv {σ τ : AccountMap} {I : Execution exact hzero theorem kissVatCode_pos_of_codeSize_ne {cA gh bl σ σ₀ A I} {g : UInt256} - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (kissVatAddress σ I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [initState, State.lookupAccount] using - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ) (target := kissDaiTargetWord σ I) (addr := kissVatAddress σ I) (kissVatAddress_eq_daiTarget_account σ I) hne theorem kissVatCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : UInt256} - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (kissVatAddress σ I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [initState, State.lookupAccount] using - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := σ) (target := kissDaiTargetWord σ I) (addr := kissVatAddress σ I) (kissVatAddress_eq_daiTarget_account σ I) hzero @@ -89,13 +89,13 @@ theorem flopFlopperAddressOf_eq_vowAddressReturnWord (evm : EVM.State) (I : Exec theorem flopFlopperCode_pos_of_codeSize_ne (evm : EVM.State) (I : ExecutionEnv) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (vowAddressReturnWord ⟨3⟩ evm.accountMap I) ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((evm.lookupAccount (flopFlopperAddressOf evm)).option 0 (fun acc => acc.code.size))).toNat := by simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := evm.accountMap) (target := vowAddressReturnWord ⟨3⟩ evm.accountMap I) (addr := flopFlopperAddressOf evm) (flopFlopperAddressOf_eq_vowAddressReturnWord evm I howner) hne @@ -103,13 +103,13 @@ theorem flopFlopperCode_pos_of_codeSize_ne (evm : EVM.State) (I : ExecutionEnv) theorem flopFlopperCode_zero_of_codeSize_zero (evm : EVM.State) (I : ExecutionEnv) (howner : evm.executionEnv.codeOwner = I.codeOwner) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (vowAddressReturnWord ⟨3⟩ evm.accountMap I) = ⟨0⟩) : (UInt256.ofNat ((evm.lookupAccount (flopFlopperAddressOf evm)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := evm.accountMap) (target := vowAddressReturnWord ⟨3⟩ evm.accountMap I) (addr := flopFlopperAddressOf evm) (flopFlopperAddressOf_eq_vowAddressReturnWord evm I howner) hzero @@ -120,7 +120,7 @@ theorem RD.vowFlopSin0CallDepthLimit (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨646⟩ [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1277⟩ @@ -130,7 +130,7 @@ theorem RD.vowFlopSin0CallDepthLimit (cA, σ) k' C' := by obtain ⟨_, _, _, rd1276⟩ := RD.vowFlopToSin0Staticcall hreach hcodeSize obtain ⟨k1277, C1277, rd1277raw⟩ := - RD.uniswapStaticcallDepthLimit rd1276 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcallDepthLimit rd1276 (by native_decide) hdepth (by evm_ov) have haw : UInt256.ofNat (MachineState.M (MachineState.M (UInt256.ofNat 6).toNat healSinOutPtr.toNat healSinInSize.toNat) @@ -174,14 +174,14 @@ theorem vowFlopBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hwv hsz4 hsize hsel by_cases hcodeSizeSin : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩ · exact vowFlopVatSin0NoCodeBodyCore hcode hwv hdispatch hdecode hreach hAccounts hcodeSizeSin have hcodeSizeSinNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) ≠ ⟨0⟩ := hcodeSizeSin have hcodeSizeSinSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) ≠ ⟨0⟩ := kissDaiCodeSize_ne_accountMapEquiv hAccounts hcodeSizeSinNE have hvatCodeSolm : 0 < (UInt256.ofNat @@ -405,10 +405,10 @@ theorem vowFlopBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (vowSlotWord ⟨9⟩ (cA_sin, σ_sin).2 I).toNat ≤ flopDebt.toNat := by simpa [SumpVal] using henough by_cases hcodeSizeDai : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) = + Reasoning.Theory.extCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) = ⟨0⟩ · have hcodeSizeDaiSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmSinSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSinSolm.accountMap (kissDaiTargetWord evmSinSolm.accountMap I) = ⟨0⟩ := kissDaiCodeSize_zero_accountMapEquiv hAccountsSin hcodeSizeDai have hvatNoCodeDai : @@ -416,7 +416,7 @@ theorem vowFlopBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} ((evmSinSolm.lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := evmSinSolm.accountMap) (target := kissDaiTargetWord evmSinSolm.accountMap I) (addr := kissVatAddress σ_solm I) haddrDai hcodeSizeDaiSolm @@ -428,11 +428,11 @@ theorem vowFlopBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by simp [flopDebt, freeSin, AshVal]) hdebtOk hSumpLoad (by simp [SumpVal]) hvatLoadSin hvatNoCodeDai have hcodeSizeDaiNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) ≠ + Reasoning.Theory.extCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) ≠ ⟨0⟩ := hcodeSizeDai have hcodeSizeDaiSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmSinSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSinSolm.accountMap (kissDaiTargetWord evmSinSolm.accountMap I) ≠ ⟨0⟩ := kissDaiCodeSize_ne_accountMapEquiv hAccountsSin hcodeSizeDaiNE have hvatCodeDai : @@ -440,7 +440,7 @@ theorem vowFlopBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} ((evmSinSolm.lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [State.lookupAccount] using - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := evmSinSolm.accountMap) (target := kissDaiTargetWord evmSinSolm.accountMap I) (addr := kissVatAddress σ_solm I) haddrDai hcodeSizeDaiSolmNE @@ -614,16 +614,16 @@ theorem vowFlopBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hslot := vowSlotWord_accountMapEquiv (I := I) hAccountsAsh ⟨3⟩ simp [vowAddressReturnWord, hslot] by_cases hcodeSizeKick : - Reasoning.Theory.uniswapExtCodeSizeWord σAshEvm + Reasoning.Theory.extCodeSizeWord σAshEvm (vowAddressReturnWord ⟨3⟩ σAshEvm I) = ⟨0⟩ · have hcodeSizeKickSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmAshSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmAshSolm.accountMap (vowAddressReturnWord ⟨3⟩ evmAshSolm.accountMap I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccountsAsh + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccountsAsh (vowAddressReturnWord ⟨3⟩ σAshEvm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord evmAshSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmAshSolm.accountMap (vowAddressReturnWord ⟨3⟩ σAshEvm I) = ⟨0⟩ := by rw [← hsame] exact hcodeSizeKick @@ -647,7 +647,7 @@ theorem vowFlopBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} rfl hfit (by simpa [evmAshSolm] using hflopperNoCode) (by simpa [σAshEvm, AshNew] using hcodeSizeKick) have hcodeSizeKickNE : - Reasoning.Theory.uniswapExtCodeSizeWord σAshEvm + Reasoning.Theory.extCodeSizeWord σAshEvm (vowAddressReturnWord ⟨3⟩ σAshEvm I) ≠ ⟨0⟩ := hcodeSizeKick let memDai := @@ -676,15 +676,15 @@ theorem vowFlopBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} memDai (UInt256.ofNat 6) outDai (cA_dai, σ_dai) k3959 C3959 := by simpa [memDai, AshNew, AshValDai, SumpValDai] using rd3959Raw have hcodeSizeKickSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmAshSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmAshSolm.accountMap (vowAddressReturnWord ⟨3⟩ evmAshSolm.accountMap I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeKickNE have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccountsAsh + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccountsAsh (vowAddressReturnWord ⟨3⟩ σAshEvm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord evmAshSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmAshSolm.accountMap (vowAddressReturnWord ⟨3⟩ σAshEvm I) = ⟨0⟩ := by simpa [hTargetAshEq] using hzero rw [hsame] diff --git a/Benchmarks/Dss/Vow/FlopDai.lean b/Benchmarks/Dss/Vow/FlopDai.lean index def360b4..aba1c4e7 100644 --- a/Benchmarks/Dss/Vow/FlopDai.lean +++ b/Benchmarks/Dss/Vow/FlopDai.lean @@ -823,7 +823,7 @@ theorem RD.vowFlopDai1PostCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (outDai : ByteArray) (A' : Substate) (k' C' : ℕ), @@ -849,7 +849,7 @@ theorem RD.vowFlopDai1PostCall obtain ⟨gasWord, _, _, rd3831⟩ := RD.vowFlopToDai1Staticcall rd henough hmem hread64 hcodeSize obtain ⟨cA', σ', z, outDai, A_in, callGas, k3832, C3832, hΘpack, rd3832raw, hosz⟩ := - RD.uniswapStaticcall rd3831 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall rd3831 (by native_decide) hdepth (by evm_ov) obtain ⟨g'', A', hΘ⟩ := hΘpack let evmDaiIn := { initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I with accountMap := acc.2 @@ -882,7 +882,7 @@ theorem RD.vowFlopDai1CallFailure (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨3832⟩) (okPc := ⟨3848⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨3832⟩) (okPc := ⟨3848⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -900,7 +900,7 @@ theorem RD.vowFlopDai1CallSuccessToDecode ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨3850⟩ (d0 :: d1 :: d2 :: R) mem aw o acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨3832⟩) (okPc := ⟨3848⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨3832⟩) (okPc := ⟨3848⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1175,7 +1175,7 @@ theorem vowFlopDai1NoCodeBodyCore (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) (hvatCode : 0 < (UInt256.ofNat (((initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).lookupAccount diff --git a/Benchmarks/Dss/Vow/FlopKick.lean b/Benchmarks/Dss/Vow/FlopKick.lean index 89648b5b..168c7e7f 100644 --- a/Benchmarks/Dss/Vow/FlopKick.lean +++ b/Benchmarks/Dss/Vow/FlopKick.lean @@ -1423,7 +1423,7 @@ theorem vowFlopKickNoCodeBodyCore 0 (fun acc => acc.code.size))).toNat = 0) (hflopperNoCodeEvm : let σAsh := sstoreAccountMap I.codeOwner acc.2 ⟨6⟩ AshNew - Reasoning.Theory.uniswapExtCodeSizeWord σAsh + Reasoning.Theory.extCodeSizeWord σAsh (vowAddressReturnWord ⟨3⟩ σAsh I) = ⟨0⟩) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by let memDai := outDai.write 0 (vatDaiCalldataMem I mem) 128 32 diff --git a/Benchmarks/Dss/Vow/Heal.lean b/Benchmarks/Dss/Vow/Heal.lean index da443437..40724a6c 100644 --- a/Benchmarks/Dss/Vow/Heal.lean +++ b/Benchmarks/Dss/Vow/Heal.lean @@ -317,7 +317,7 @@ theorem RD.vowHealToDaiExtcodesizeGuard dup2, raw mstore 6 kissDaiSelectorMem (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov), - uniswapAddress, + address, push1 ⟨4⟩, dup3, add, @@ -368,12 +368,12 @@ theorem RD.vowHealDaiNoCode (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by let target := kissDaiTargetWord σ I obtain ⟨_, _, rd4703⟩ := RD.vowHealToDaiExtcodesizeGuard hreach hsz36 hsize - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4703⟩) (okPc := ⟨4715⟩) rd4703 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4703⟩) (okPc := ⟨4715⟩) rd4703 (by simpa [target] using hcodeSize) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -387,7 +387,7 @@ theorem RD.vowHealToDaiStaticcall (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : ∃ gasWord k C, RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨4718⟩ (gasWord :: kissDaiTargetWord σ I :: kissDaiOutPtr I :: kissDaiInSize I :: @@ -397,7 +397,7 @@ theorem RD.vowHealToDaiStaticcall let target := kissDaiTargetWord σ I obtain ⟨_, _, rd4703⟩ := RD.vowHealToDaiExtcodesizeGuard hreach hsz36 hsize obtain ⟨gasWord, k, C, rd4718⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4703⟩) (okPc := ⟨4715⟩) rd4703 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4703⟩) (okPc := ⟨4715⟩) rd4703 (by simpa [target] using hcodeSize) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -412,7 +412,7 @@ theorem RD.vowHealDaiPostCall (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (o : ByteArray) (A' : Substate) (k C : ℕ), @@ -431,7 +431,7 @@ theorem RD.vowHealDaiPostCall obtain ⟨gasWord, _, _, rd4718⟩ := RD.vowHealToDaiStaticcall hreach hsz36 hsize hcodeSize obtain ⟨cA', σ', z, o, A_in, callGas, k4719, C4719, hΘpack, rd4719raw, hosz⟩ := - RD.uniswapStaticcall rd4718 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall rd4718 (by native_decide) hdepth (by evm_ov) obtain ⟨g'', A', hΘ⟩ := hΘpack refine ⟨cA', σ', z, o, A', k4719, C4719, ?_, ?_, hosz⟩ · have haw : @@ -469,7 +469,7 @@ theorem RD.vowHealDaiCallDepthLimit (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨4719⟩ @@ -479,7 +479,7 @@ theorem RD.vowHealDaiCallDepthLimit obtain ⟨_, _, _, rd4718⟩ := RD.vowHealToDaiStaticcall hreach hsz36 hsize hcodeSize obtain ⟨k4719, C4719, rd4719raw⟩ := - RD.uniswapStaticcallDepthLimit rd4718 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcallDepthLimit rd4718 (by native_decide) hdepth (by evm_ov) have haw : UInt256.ofNat (MachineState.M (MachineState.M (UInt256.ofNat 6).toNat (kissDaiOutPtr I).toNat (kissDaiInSize I).toNat) @@ -510,7 +510,7 @@ theorem RD.vowHealDaiCallFailure (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨4719⟩) (okPc := ⟨4735⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨4719⟩) (okPc := ⟨4735⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -528,7 +528,7 @@ theorem RD.vowHealDaiCallSuccessToDecode ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨4737⟩ (d0 :: d1 :: d2 :: R) mem aw o acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨4719⟩) (okPc := ⟨4735⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨4719⟩) (okPc := ⟨4735⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -761,7 +761,7 @@ theorem RD.vowHealToSinExtcodesizeGuard dup2, raw mstore 0 (healSinSelectorMem mem) (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov), - uniswapAddress, + address, push1 ⟨4⟩, dup3, add, @@ -817,11 +817,11 @@ theorem RD.vowHealSinNoCode (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (kissDaiTargetWord σ' I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (kissDaiTargetWord σ' I) = ⟨0⟩) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd4909⟩ := RD.vowHealToSinExtcodesizeGuard rd hmem hread64 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨4909⟩) (okPc := ⟨1273⟩) rd4909 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨4909⟩) (okPc := ⟨1273⟩) rd4909 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -837,7 +837,7 @@ theorem RD.vowHealToSinStaticcall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (kissDaiTargetWord σ' I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (kissDaiTargetWord σ' I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1276⟩ (gasWord :: kissDaiTargetWord σ' I :: healSinOutPtr :: healSinInSize :: @@ -846,7 +846,7 @@ theorem RD.vowHealToSinStaticcall (healSinCalldataMem I mem) (UInt256.ofNat 6) o (cA', σ') k' C' := by obtain ⟨_, _, rd4909⟩ := RD.vowHealToSinExtcodesizeGuard rd hmem hread64 obtain ⟨gasWord, k1276, C1276, rd1276⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨4909⟩) (okPc := ⟨1273⟩) rd4909 + RD.solcExtcodesizeGuardOkGas (pc := ⟨4909⟩) (okPc := ⟨1273⟩) rd4909 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -863,7 +863,7 @@ theorem RD.vowHealSinPostCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (kissDaiTargetWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (kissDaiTargetWord σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) (out : ByteArray) (A'' : Substate) (k' C' : ℕ), @@ -884,7 +884,7 @@ theorem RD.vowHealSinPostCall obtain ⟨gasWord, _, _, rd1276⟩ := RD.vowHealToSinStaticcall rd hmem hread64 hcodeSize obtain ⟨cA'', σ'', z, out, A_in, callGas, k1277, C1277, hΘpack, rd1277raw, houtsz⟩ := - RD.uniswapStaticcall rd1276 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall rd1276 (by native_decide) hdepth (by evm_ov) obtain ⟨g'', A'', hΘ⟩ := hΘpack refine ⟨cA'', σ'', z, out, A'', k1277, C1277, ?_, ?_, houtsz⟩ · have haw : @@ -926,7 +926,7 @@ theorem RD.vowHealSinCallFailure (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1277⟩) (okPc := ⟨1293⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨1277⟩) (okPc := ⟨1293⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1322,7 +1322,7 @@ theorem vowHealDaiNoCodeBodyCore solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ_evm) k C) (hAccounts : accountMapEquiv σ_evm σ_solm) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by have hVat : vowSlotWord ⟨1⟩ σ_evm I = vowSlotWord ⟨1⟩ σ_solm I := @@ -1330,12 +1330,12 @@ theorem vowHealDaiNoCodeBodyCore have hTarget : kissDaiTargetWord σ_evm I = kissDaiTargetWord σ_solm I := by simp [kissDaiTargetWord, hVat] have hnoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (kissDaiTargetWord σ_evm I) have hsolmTargetEvm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (kissDaiTargetWord σ_evm I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ_solm (kissDaiTargetWord σ_evm I) = ⟨0⟩ := by rw [← hsame] exact hnoCode simpa [hTarget] using hsolmTargetEvm @@ -1349,7 +1349,7 @@ theorem vowHealDaiNoCodeBodyCore (((initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by rw [hvatAddr] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hnoCodeSolm + unfold Reasoning.Theory.extCodeSizeWord at hnoCodeSolm cases hacc : σ_solm.find? (AccountAddress.ofUInt256 (kissDaiTargetWord σ_solm I)) with | none => @@ -1615,7 +1615,7 @@ theorem vowHealSinNoCodeBodyCore (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSizeEvm : - Reasoning.Theory.uniswapExtCodeSizeWord σ'_evm (kissDaiTargetWord σ'_evm I) = + Reasoning.Theory.extCodeSizeWord σ'_evm (kissDaiTargetWord σ'_evm I) = ⟨0⟩) (hvatCode : 0 < (UInt256.ofNat diff --git a/Benchmarks/Dss/Vow/HealBody.lean b/Benchmarks/Dss/Vow/HealBody.lean index ba588df8..fbc83822 100644 --- a/Benchmarks/Dss/Vow/HealBody.lean +++ b/Benchmarks/Dss/Vow/HealBody.lean @@ -32,11 +32,11 @@ theorem vowHealBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hwv hsz4 hsize hsel by_cases hcodeSizeDai : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩ · exact vowHealDaiNoCodeBodyCore hcode hwv hsz36 hsize hdispatch hdecode hreach hAccounts hcodeSizeDai have hcodeSizeDaiNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) ≠ ⟨0⟩ := hcodeSizeDai have hVatOrig : vowSlotWord ⟨1⟩ σ_evm I = vowSlotWord ⟨1⟩ σ_solm I := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨1⟩ ⟨0⟩ @@ -46,11 +46,11 @@ theorem vowHealBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} apply Fin.ext simp [kissVatAddress, vowAddressReturnWord, hVatOrig] have hcodeSizeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeDaiNE have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (kissDaiTargetWord σ_evm I) rw [hsame, hTargetOrig] exact hzero @@ -59,7 +59,7 @@ theorem vowHealBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (((initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [initState, State.lookupAccount] using - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := kissDaiTargetWord σ_solm I) (addr := kissVatAddress σ_solm I) (kissVatAddress_eq_daiTarget_account σ_solm I) hcodeSizeSolmNE @@ -200,15 +200,15 @@ theorem vowHealBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} kissDaiTargetWord evmDaiSolm.accountMap I = kissDaiTargetWord σ_solm I := by simp [kissDaiTargetWord, hVatDaiSolmOrig] by_cases hcodeSizeSin : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dai (kissDaiTargetWord σ_dai I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_dai (kissDaiTargetWord σ_dai I) = ⟨0⟩ · have hcodeSizeSinSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmDaiSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmDaiSolm.accountMap (kissDaiTargetWord evmDaiSolm.accountMap I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccountsDai + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccountsDai (kissDaiTargetWord σ_dai I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord evmDaiSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmDaiSolm.accountMap (kissDaiTargetWord σ_dai I) = ⟨0⟩ := by rw [← hsame] exact hcodeSizeSin @@ -223,7 +223,7 @@ theorem vowHealBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} ((evmDaiSolm.lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [evmDaiSolm, State.lookupAccount] using - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := evmDaiSolm.accountMap) (target := kissDaiTargetWord evmDaiSolm.accountMap I) (addr := kissVatAddress σ_solm I) haddrSin hcodeSizeSinSolm @@ -232,18 +232,18 @@ theorem vowHealBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} hcode hwv hdispatch hdecode rd4838 hmemDai hread64Dai hcodeSizeSin hvatCodeSolm hcallDaiSolm hdecDai hvatDaiEnough hvatLoadDai hvatNoCodeSin have hcodeSizeSinNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_dai (kissDaiTargetWord σ_dai I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_dai (kissDaiTargetWord σ_dai I) ≠ ⟨0⟩ := hcodeSizeSin have hcodeSizeSinSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmDaiSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmDaiSolm.accountMap (kissDaiTargetWord evmDaiSolm.accountMap I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeSinNE have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccountsDai + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccountsDai (kissDaiTargetWord σ_dai I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord evmDaiSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmDaiSolm.accountMap (kissDaiTargetWord σ_dai I) = ⟨0⟩ := by simpa [hTargetDaiEq] using hzero rw [hsame] @@ -258,7 +258,7 @@ theorem vowHealBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} ((evmDaiSolm.lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [evmDaiSolm, State.lookupAccount] using - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := evmDaiSolm.accountMap) (target := kissDaiTargetWord evmDaiSolm.accountMap I) (addr := kissVatAddress σ_solm I) haddrSin hcodeSizeSinSolmNE @@ -482,16 +482,16 @@ theorem vowHealBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} apply Fin.ext simp [kissVatAddress, vowAddressReturnWord, hSlotSinOrig] by_cases hcodeSizeHeal : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sin + Reasoning.Theory.extCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) = ⟨0⟩ · have hcodeSizeHealSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmSinSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSinSolm.accountMap (kissDaiTargetWord evmSinSolm.accountMap I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccountsSin + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccountsSin (kissDaiTargetWord σ_sin I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord evmSinSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSinSolm.accountMap (kissDaiTargetWord σ_sin I) = ⟨0⟩ := by rw [← hsame] exact hcodeSizeHeal @@ -506,7 +506,7 @@ theorem vowHealBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} ((evmSinSolm.lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [evmSinSolm, State.lookupAccount] using - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := evmSinSolm.accountMap) (target := kissDaiTargetWord evmSinSolm.accountMap I) (addr := kissVatAddress σ_solm I) haddrHeal hcodeSizeHealSolm @@ -517,19 +517,19 @@ theorem vowHealBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} hvatCodeSinSolm hcallSinTrue hdecSin hSinLoad hfree hfreeOk hAshLoad hdebt hdebtOk hdebtEnough hvatLoadSin hvatNoCodeHeal have hcodeSizeHealNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_sin + Reasoning.Theory.extCodeSizeWord σ_sin (kissDaiTargetWord σ_sin I) ≠ ⟨0⟩ := hcodeSizeHeal have hcodeSizeHealSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmSinSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSinSolm.accountMap (kissDaiTargetWord evmSinSolm.accountMap I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeHealNE have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccountsSin + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccountsSin (kissDaiTargetWord σ_sin I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord evmSinSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmSinSolm.accountMap (kissDaiTargetWord σ_sin I) = ⟨0⟩ := by simpa [hTargetSinEq] using hzero rw [hsame] @@ -544,7 +544,7 @@ theorem vowHealBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} ((evmSinSolm.lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [evmSinSolm, State.lookupAccount] using - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := evmSinSolm.accountMap) (target := kissDaiTargetWord evmSinSolm.accountMap I) (addr := kissVatAddress σ_solm I) haddrHeal hcodeSizeHealSolmNE diff --git a/Benchmarks/Dss/Vow/HealFinal.lean b/Benchmarks/Dss/Vow/HealFinal.lean index 7f717dd5..598ca0c2 100644 --- a/Benchmarks/Dss/Vow/HealFinal.lean +++ b/Benchmarks/Dss/Vow/HealFinal.lean @@ -269,7 +269,7 @@ theorem vowHealHealNoCodeBodyCore (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSizeEvm : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) (hvatCode : 0 < (UInt256.ofNat diff --git a/Benchmarks/Dss/Vow/HealSuccess.lean b/Benchmarks/Dss/Vow/HealSuccess.lean index 299962b8..c00953dc 100644 --- a/Benchmarks/Dss/Vow/HealSuccess.lean +++ b/Benchmarks/Dss/Vow/HealSuccess.lean @@ -150,7 +150,7 @@ theorem RD.vowHealSinCallSuccessToDecode ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1295⟩ (d0 :: d1 :: d2 :: R) mem aw o acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨1277⟩) (okPc := ⟨1293⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨1277⟩) (okPc := ⟨1293⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -617,11 +617,11 @@ theorem RD.vowHealHealNoCode (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) = ⟨0⟩) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd5062⟩ := RD.vowHealToHealExtcodesizeGuard rd hmem hread64 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨5062⟩) (okPc := ⟨1915⟩) rd5062 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨5062⟩) (okPc := ⟨1915⟩) rd5062 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -637,7 +637,7 @@ theorem RD.vowHealToHealCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1918⟩ (gasWord :: kissDaiTargetWord acc.2 I :: kissHealOutSize :: kissHealOutPtr :: @@ -646,7 +646,7 @@ theorem RD.vowHealToHealCall (kissHealCalldataMem I mem) (UInt256.ofNat 6) o acc k' C' := by obtain ⟨_, _, rd5062⟩ := RD.vowHealToHealExtcodesizeGuard rd hmem hread64 obtain ⟨gasWord, k1918, C1918, rd1918⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨5062⟩) (okPc := ⟨1915⟩) rd5062 + RD.solcExtcodesizeGuardOkGas (pc := ⟨5062⟩) (okPc := ⟨1915⟩) rd5062 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -663,7 +663,7 @@ theorem RD.vowHealHealPostCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord acc.2 (kissDaiTargetWord acc.2 I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hperm : I.perm = true) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) diff --git a/Benchmarks/Dss/Vow/Kiss.lean b/Benchmarks/Dss/Vow/Kiss.lean index 017da0de..557b7d42 100644 --- a/Benchmarks/Dss/Vow/Kiss.lean +++ b/Benchmarks/Dss/Vow/Kiss.lean @@ -618,7 +618,7 @@ theorem RD.vowKissToDaiExtcodesizeGuard dup2, raw mstore 6 kissDaiSelectorMem (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov), - uniswapAddress, + address, push1 ⟨4⟩, dup3, add, @@ -670,7 +670,7 @@ theorem RD.vowKissToDaiStaticcall (hsize : I.calldata.size < UInt256.size) (hashEnough : (kissRad I).toNat ≤ (vowSlotWord ⟨6⟩ σ I).toNat) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) : ∃ gasWord k C, RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1703⟩ (gasWord :: kissDaiTargetWord σ I :: kissDaiOutPtr I :: kissDaiInSize I :: @@ -681,7 +681,7 @@ theorem RD.vowKissToDaiStaticcall obtain ⟨_, _, rd1688⟩ := RD.vowKissToDaiExtcodesizeGuard hreach hsz36 hsize hashEnough obtain ⟨gasWord, k, C, rd1703⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1688⟩) (okPc := ⟨1700⟩) rd1688 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1688⟩) (okPc := ⟨1700⟩) rd1688 (by simpa [target] using hcodeSize) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -697,13 +697,13 @@ theorem RD.vowKissDaiNoCode (hsize : I.calldata.size < UInt256.size) (hashEnough : (kissRad I).toNat ≤ (vowSlotWord ⟨6⟩ σ I).toNat) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) = ⟨0⟩) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by let target := kissDaiTargetWord σ I obtain ⟨_, _, rd1688⟩ := RD.vowKissToDaiExtcodesizeGuard hreach hsz36 hsize hashEnough - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1688⟩) (okPc := ⟨1700⟩) rd1688 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1688⟩) (okPc := ⟨1700⟩) rd1688 (by simpa [target] using hcodeSize) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -718,7 +718,7 @@ theorem RD.vowKissDaiPostCall (hsize : I.calldata.size < UInt256.size) (hashEnough : (kissRad I).toNat ≤ (vowSlotWord ⟨6⟩ σ I).toNat) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (o : ByteArray) (A' : Substate) (k C : ℕ), @@ -737,7 +737,7 @@ theorem RD.vowKissDaiPostCall obtain ⟨gasWord, _, _, rd1703⟩ := RD.vowKissToDaiStaticcall hreach hsz36 hsize hashEnough hcodeSize obtain ⟨cA', σ', z, o, A_in, callGas, k1704, C1704, hΘpack, rd1704raw, hosz⟩ := - RD.uniswapStaticcall rd1703 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcall rd1703 (by native_decide) hdepth (by evm_ov) obtain ⟨g'', A', hΘ⟩ := hΘpack refine ⟨cA', σ', z, o, A', k1704, C1704, ?_, ?_, hosz⟩ · have haw : @@ -778,7 +778,7 @@ theorem RD.vowKissDaiCallFailure (hov : rest.length + 5 ≤ 1024) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1704⟩) (okPc := ⟨1720⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨1704⟩) (okPc := ⟨1720⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -796,7 +796,7 @@ theorem RD.vowKissDaiCallSuccessToDecode ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1722⟩ (d0 :: d1 :: d2 :: R) mem aw o acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (pc := ⟨1704⟩) (okPc := ⟨1720⟩) rd + exact RD.solcCallSuccessGuardOk (pc := ⟨1704⟩) (okPc := ⟨1720⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -1564,7 +1564,7 @@ theorem vowKissNoVatCodeBodyCore (hAccounts : accountMapEquiv σ_evm σ_solm) (hashEnough : (kissRad I).toNat ≤ (vowSlotWord ⟨6⟩ σ_evm I).toNat) (hnoCode : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by have hAsh : vowSlotWord ⟨6⟩ σ_evm I = vowSlotWord ⟨6⟩ σ_solm I := @@ -1577,12 +1577,12 @@ theorem vowKissNoVatCodeBodyCore have hTarget : kissDaiTargetWord σ_evm I = kissDaiTargetWord σ_solm I := by simp [kissDaiTargetWord, hVat] have hnoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (kissDaiTargetWord σ_evm I) have hsolmTargetEvm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (kissDaiTargetWord σ_evm I) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ_solm (kissDaiTargetWord σ_evm I) = ⟨0⟩ := by rw [← hsame] exact hnoCode simpa [hTarget] using hsolmTargetEvm @@ -1596,7 +1596,7 @@ theorem vowKissNoVatCodeBodyCore (((initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by rw [hvatAddr] - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hnoCodeSolm + unfold Reasoning.Theory.extCodeSizeWord at hnoCodeSolm cases hacc : σ_solm.find? (AccountAddress.ofUInt256 (kissDaiTargetWord σ_solm I)) with | none => diff --git a/Benchmarks/Dss/Vow/KissSuccess.lean b/Benchmarks/Dss/Vow/KissSuccess.lean index d5c532d9..d6d1f290 100644 --- a/Benchmarks/Dss/Vow/KissSuccess.lean +++ b/Benchmarks/Dss/Vow/KissSuccess.lean @@ -308,11 +308,11 @@ theorem RD.vowKissHealNoCode (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (kissDaiTargetWord σ' I) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (kissDaiTargetWord σ' I) = ⟨0⟩) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd1903⟩ := RD.vowKissToHealExtcodesizeGuard rd hmem hread64 - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨1903⟩) (okPc := ⟨1915⟩) rd1903 + exact RD.solcExtcodesizeGuardMissing (pc := ⟨1903⟩) (okPc := ⟨1915⟩) rd1903 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -328,7 +328,7 @@ theorem RD.vowKissToHealCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (kissDaiTargetWord σ' I) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ' (kissDaiTargetWord σ' I) ≠ ⟨0⟩) : ∃ gasWord k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1918⟩ (gasWord :: kissDaiTargetWord σ' I :: kissHealOutSize :: kissHealOutPtr :: @@ -337,7 +337,7 @@ theorem RD.vowKissToHealCall (kissHealCalldataMem I mem) (UInt256.ofNat 6) o (cA', σ') k' C' := by obtain ⟨_, _, rd1903⟩ := RD.vowKissToHealExtcodesizeGuard rd hmem hread64 obtain ⟨gasWord, k1918, C1918, rd1918⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨1903⟩) (okPc := ⟨1915⟩) rd1903 + RD.solcExtcodesizeGuardOkGas (pc := ⟨1903⟩) (okPc := ⟨1915⟩) rd1903 hcodeSize (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) @@ -354,7 +354,7 @@ theorem RD.vowKissHealPostCall (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (kissDaiTargetWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (kissDaiTargetWord σ' I) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hperm : I.perm = true) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z : Bool) @@ -418,7 +418,7 @@ theorem RD.vowKissHealCallFailure (hrdataSize : rdata.size < UInt256.size) : RDrev vowBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapCallSuccessGuardMissing (pc := ⟨1919⟩) (okPc := ⟨1935⟩) rd + exact RD.solcCallSuccessGuardMissing (pc := ⟨1919⟩) (okPc := ⟨1935⟩) rd (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -437,7 +437,7 @@ theorem RD.vowKissHealCallSuccessToReturn ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨412⟩ [sel] mem aw rdata acc k' C' := by - obtain ⟨_, _, rd1937⟩ := RD.uniswapCallSuccessGuardOk + obtain ⟨_, _, rd1937⟩ := RD.solcCallSuccessGuardOk (pc := ⟨1919⟩) (okPc := ⟨1935⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -473,7 +473,7 @@ theorem RD.vowKissHealCallDepthLimit (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ' (kissDaiTargetWord σ' I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ' (kissDaiTargetWord σ' I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1919⟩ @@ -514,7 +514,7 @@ theorem RD.vowKissDaiCallDepthLimit (hsize : I.calldata.size < UInt256.size) (hashEnough : (kissRad I).toNat ≤ (vowSlotWord ⟨6⟩ σ I).toNat) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (kissDaiTargetWord σ I) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : ∃ k' C', RD vowBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1704⟩ @@ -524,7 +524,7 @@ theorem RD.vowKissDaiCallDepthLimit obtain ⟨_, _, _, rd1703⟩ := RD.vowKissToDaiStaticcall hreach hsz36 hsize hashEnough hcodeSize obtain ⟨k1704, C1704, rd1704raw⟩ := - RD.uniswapStaticcallDepthLimit rd1703 (by native_decide) hdepth (by evm_ov) + RD.solcStaticcallDepthLimit rd1703 (by native_decide) hdepth (by evm_ov) have haw : UInt256.ofNat (MachineState.M (MachineState.M (UInt256.ofNat 6).toNat (kissDaiOutPtr I).toNat (kissDaiInSize I).toNat) @@ -576,14 +576,14 @@ theorem typedCallViaEVM_zero_setSubstate {cfg : Config} {evm evm' : EVM.State} -- LIBRARY CANDIDATE: converts the word-level extcodesize guard used by traces into the -- source-level positive code-size fact used by `evalExpr_extCodeSize`. -theorem uniswapExtCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} {target : UInt256} +theorem extCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => exfalso @@ -602,15 +602,15 @@ theorem uniswapExtCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} {target · simp [UInt256.toNat, hword] at hzeroNat simpa [hacc] using Nat.pos_of_ne_zero htoNatNe --- LIBRARY CANDIDATE: zero counterpart of `uniswapExtCodeSizeWord_ne_zero_lookup_code_pos`. -theorem uniswapExtCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} +-- LIBRARY CANDIDATE: zero counterpart of `extCodeSizeWord_ne_zero_lookup_code_pos`. +theorem extCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using @@ -1007,7 +1007,7 @@ theorem vowKissHealNoCodeBodyCore (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (hcodeSizeEvm : - Reasoning.Theory.uniswapExtCodeSizeWord σAsh_evm (kissDaiTargetWord σAsh_evm I) = + Reasoning.Theory.extCodeSizeWord σAsh_evm (kissDaiTargetWord σAsh_evm I) = ⟨0⟩) (hashEnough : (kissRad I).toNat ≤ (vowSlotWord ⟨6⟩ σ_solm I).toNat) (hvatCode : @@ -1186,11 +1186,11 @@ theorem vowKissBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hashEnoughEvm : (kissRad I).toNat ≤ (vowSlotWord ⟨6⟩ σ_evm I).toNat := by omega by_cases hcodeSizeDai : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) = ⟨0⟩ · exact vowKissNoVatCodeBodyCore hcode hwv hsz36 hsize hdispatch hdecode hreach hAccounts hashEnoughEvm hcodeSizeDai have hcodeSizeDaiNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) ≠ ⟨0⟩ := + Reasoning.Theory.extCodeSizeWord σ_evm (kissDaiTargetWord σ_evm I) ≠ ⟨0⟩ := hcodeSizeDai have hAshOrig : vowSlotWord ⟨6⟩ σ_evm I = vowSlotWord ⟨6⟩ σ_solm I := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨6⟩ ⟨0⟩ @@ -1204,11 +1204,11 @@ theorem vowKissBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hashEnoughSolm : (kissRad I).toNat ≤ (vowSlotWord ⟨6⟩ σ_solm I).toNat := by simpa [← hAshOrig] using hashEnoughEvm have hcodeSizeSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ_solm (kissDaiTargetWord σ_solm I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeDaiNE have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (kissDaiTargetWord σ_evm I) rw [hsame, hTargetOrig] exact hzero @@ -1217,7 +1217,7 @@ theorem vowKissBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (((initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [initState, State.lookupAccount] using - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ_solm) (target := kissDaiTargetWord σ_solm I) (addr := kissVatAddress σ_solm I) (kissVatAddress_eq_daiTarget_account σ_solm I) hcodeSizeSolmNE @@ -1403,16 +1403,16 @@ theorem vowKissBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (by decide : (⟨1⟩ : UInt256) ≠ ⟨6⟩)).trans hslotDai simp [kissVatAddress, vowAddressReturnWord, hslotAsh] by_cases hcodeSizeHeal : - Reasoning.Theory.uniswapExtCodeSizeWord σAshEvm + Reasoning.Theory.extCodeSizeWord σAshEvm (kissDaiTargetWord σAshEvm I) = ⟨0⟩ · have hcodeSizeHealSolm : - Reasoning.Theory.uniswapExtCodeSizeWord evmAshSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmAshSolm.accountMap (kissDaiTargetWord evmAshSolm.accountMap I) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccountsAsh + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccountsAsh (kissDaiTargetWord σAshEvm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord evmAshSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmAshSolm.accountMap (kissDaiTargetWord σAshEvm I) = ⟨0⟩ := by rw [← hsame] exact hcodeSizeHeal @@ -1428,7 +1428,7 @@ theorem vowKissBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} ⟨6⟩ AshNew).lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [evmAshSolm, State.lookupAccount] using - uniswapExtCodeSizeWord_zero_lookup_code_zero + extCodeSizeWord_zero_lookup_code_zero (σ := evmAshSolm.accountMap) (target := kissDaiTargetWord evmAshSolm.accountMap I) (addr := kissVatAddress σ_solm I) haddrHeal hcodeSizeHealSolm @@ -1437,19 +1437,19 @@ theorem vowKissBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} hcodeSizeHeal hashEnoughSolm hvatCodeSolm hcallDaiSolm hdecDai hvatDaiEnough hAshLoadDai hvatLoadDai hAshNew hvatNoCodeHeal have hcodeSizeHealNE : - Reasoning.Theory.uniswapExtCodeSizeWord σAshEvm + Reasoning.Theory.extCodeSizeWord σAshEvm (kissDaiTargetWord σAshEvm I) ≠ ⟨0⟩ := hcodeSizeHeal have hcodeSizeHealSolmNE : - Reasoning.Theory.uniswapExtCodeSizeWord evmAshSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmAshSolm.accountMap (kissDaiTargetWord evmAshSolm.accountMap I) ≠ ⟨0⟩ := by intro hzero apply hcodeSizeHealNE have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccountsAsh + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccountsAsh (kissDaiTargetWord σAshEvm I) have hzeroAtEvmTarget : - Reasoning.Theory.uniswapExtCodeSizeWord evmAshSolm.accountMap + Reasoning.Theory.extCodeSizeWord evmAshSolm.accountMap (kissDaiTargetWord σAshEvm I) = ⟨0⟩ := by simpa [hTargetAshEq] using hzero rw [hsame] @@ -1465,7 +1465,7 @@ theorem vowKissBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} ⟨6⟩ AshNew).lookupAccount (kissVatAddress σ_solm I)).option 0 (fun acc => acc.code.size))).toNat := by simpa [evmAshSolm, State.lookupAccount] using - uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + extCodeSizeWord_ne_zero_lookup_code_pos (σ := evmAshSolm.accountMap) (target := kissDaiTargetWord evmAshSolm.accountMap I) (addr := kissVatAddress σ_solm I) haddrHeal hcodeSizeHealSolmNE diff --git a/Benchmarks/Dss/Vow/SpecSyntax.lean b/Benchmarks/Dss/Vow/SpecSyntax.lean index 37446e8a..59c80e76 100644 --- a/Benchmarks/Dss/Vow/SpecSyntax.lean +++ b/Benchmarks/Dss/Vow/SpecSyntax.lean @@ -2,123 +2,254 @@ import Benchmarks.Dss.Vow.Spec import Solm.Notation /-! -# MakerDAO/Sky DSS Vow spec through the Solm notation frontend +# Vow spec in the Solidity-faithful Solm frontend -This file exposes a notation-side presentation for representative parts of the Vow scaffold covered -by the current Solm frontend, and checks by `rfl` that they are definitionally equal to the AST spec -in `Benchmarks.Dss.Vow.Spec`. +The whole `vow.sol` spec written with `solidity%` and proven definitionally equal to the AST +spec in `Spec.lean`. Checked-math helpers live as the internal `add`/`sub`/`min` functions and +their inlined uses; `{view}` marks the permission-free `vat.dai`/`vat.sin` reads; `extCodeSize` +guards on storage receivers use `${…}` escapes. Transition order matches `contract.transitions` +(selector order). -/ -open Solm Solm.Notation +open Solm Solm.Notation Benchmarks.Dss.Vow namespace Benchmarks.Dss.Vow.Syntax -def storageDeclsSyntax : List StorageDecl := - sState% { - (address => uint256) wards - } ++ - [ { name := "vat", ty := addrSt }, - { name := "flapper", ty := addrSt }, - { name := "flopper", ty := addrSt }, - { name := "sin", ty := .mapping (.int uint256Int) uint256St }, - { name := "Sin", ty := uint256St }, - { name := "Ash", ty := uint256St }, - { name := "wait", ty := uint256St }, - { name := "dump", ty := uint256St }, - { name := "sump", ty := uint256St }, - { name := "bump", ty := uint256St }, - { name := "hump", ty := uint256St }, - { name := "live", ty := uint256St } ] - -def denyTransitionSyntax : TransitionDecl := - { name := "deny" - params := [{ name := "usr", ty := addr }] - returnType := [] - body := sBlock% { - require msg.value == 0 - require @wards[msg.sender] == 1 - @wards[usr] := 0 - } } - -def vatTransitionSyntax : TransitionDecl := - { name := "vat" - params := [] - returnType := [addr] - body := sBlock% { - require msg.value == 0 - return @vat - } } - -def waitTransitionSyntax : TransitionDecl := - { name := "wait" - params := [] - returnType := [uint256] - body := sBlock% { - require msg.value == 0 - return @wait - } } - -def liveTransitionSyntax : TransitionDecl := - { name := "live" - params := [] - returnType := [uint256] - body := sBlock% { - require msg.value == 0 - return @live - } } - -def transitionsSyntax : List TransitionDecl := - [ AshTransition, - SinTransition, - bumpTransition, - cageTransition, - denyTransitionSyntax, - dumpTransition, - fessTransition, - fileUintTransition, - fileAddressTransition, - flapTransition, - flapperTransition, - flogTransition, - flopTransition, - flopperTransition, - healTransition, - humpTransition, - kissTransition, - liveTransitionSyntax, - relyTransition, - sinTransition, - sumpTransition, - vatTransitionSyntax, - waitTransitionSyntax, - wardsTransition ] - -def contractSyntax : ContractDecl := - { name := "Vow" - storage := storageDeclsSyntax - ctor := constructorDecl - functions := functions - transitions := transitionsSyntax } - -theorem storageDeclsSyntax_eq : storageDeclsSyntax = Benchmarks.Dss.Vow.storageDecls := by - rfl - -theorem denyTransitionSyntax_eq : denyTransitionSyntax = Benchmarks.Dss.Vow.denyTransition := by - rfl - -theorem vatTransitionSyntax_eq : vatTransitionSyntax = Benchmarks.Dss.Vow.vatTransition := by - rfl - -theorem waitTransitionSyntax_eq : waitTransitionSyntax = Benchmarks.Dss.Vow.waitTransition := by - rfl - -theorem liveTransitionSyntax_eq : liveTransitionSyntax = Benchmarks.Dss.Vow.liveTransition := by - rfl - -theorem transitionsSyntax_eq : transitionsSyntax = Benchmarks.Dss.Vow.transitions := by - rfl - -theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Vow.contract := by - rfl +def contractSyntax : ContractDecl := solidity% contract Vow { + mapping(address => uint256) wards; + address vat; + address flapper; + address flopper; + mapping(uint256 => uint256) sin; + uint256 Sin; + uint256 Ash; + uint256 wait; + uint256 dump; + uint256 sump; + uint256 bump; + uint256 hump; + uint256 live; + + constructor(address vat_, address flapper_, address flopper_) { + wards[msg.sender] = 1; + vat = vat_; + flapper = flapper_; + flopper = flopper_; + require(vat_.code.length > 0); + var _hopeRet = vat_.hope(flapper_); + live = 1; + } + + function add(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x + y) as uint256; + require(z >= x); + return z; + } + + function sub(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x - y) as uint256; + require(z <= x); + return z; + } + + function min(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = x <= y ? x : y; + return z; + } + + function Ash() external returns (uint256) { + return Ash; + } + + function Sin() external returns (uint256) { + return Sin; + } + + function bump() external returns (uint256) { + return bump; + } + + function cage() external { + require(wards[msg.sender] == 1); + require(live == 1); + live = 0; + Sin = 0; + Ash = 0; + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var flapperDai = vat.dai{view}(flapper); + require(${Expr.extCodeSize (.storage flapperRef)} > 0); + var _flapCageRet = flapper.cage(flapperDai); + require(${Expr.extCodeSize (.storage flopperRef)} > 0); + var _flopCageRet = flopper.cage(); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var vatDai = vat.dai{view}(this); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var vatSin = vat.sin{view}(this); + var healRad = min(vatDai, vatSin); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _healRet = vat.heal(healRad); + } + + function deny(address usr) external { + require(wards[msg.sender] == 1); + wards[usr] = 0; + } + + function dump() external returns (uint256) { + return dump; + } + + function fess(uint256 tab) external { + require(wards[msg.sender] == 1); + uint256 sinNew = (sin[block.timestamp] + tab) as uint256; + require(sinNew >= sin[block.timestamp]); + sin[block.timestamp] = sinNew; + uint256 SinNew = (Sin + tab) as uint256; + require(SinNew >= Sin); + Sin = SinNew; + } + + function file(bytes32 what, uint256 data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x7761697400000000000000000000000000000000000000000000000000000000)) { + wait = data; + } else if (what == bytes32(0x62756d7000000000000000000000000000000000000000000000000000000000)) { + bump = data; + } else if (what == bytes32(0x73756d7000000000000000000000000000000000000000000000000000000000)) { + sump = data; + } else if (what == bytes32(0x64756d7000000000000000000000000000000000000000000000000000000000)) { + dump = data; + } else if (what == bytes32(0x68756d7000000000000000000000000000000000000000000000000000000000)) { + hump = data; + } else { + require(false); + } + } + + function file(bytes32 what, address data) external { + require(wards[msg.sender] == 1); + if (what == bytes32(0x666c617070657200000000000000000000000000000000000000000000000000)) { + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _nopeRet = vat.nope(flapper); + flapper = data; + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _hopeRet = vat.hope(data); + } else if (what == bytes32(0x666c6f7070657200000000000000000000000000000000000000000000000000)) { + flopper = data; + } else { + require(false); + } + } + + function flap() external returns (uint256) { + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var vatSin0 = vat.sin{view}(this); + var surplus0 = add(vatSin0, bump); + var surplusNeed = add(surplus0, hump); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var vatDai = vat.dai{view}(this); + require(vatDai >= surplusNeed); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var vatSin1 = vat.sin{view}(this); + var freeSin = sub(vatSin1, Sin); + var debt = sub(freeSin, Ash); + require(debt == 0); + require(${Expr.extCodeSize (.storage flapperRef)} > 0); + var id = flapper.kick(bump, 0); + return id; + } + + function flapper() external returns (address) { + return flapper; + } + + function flog(uint256 era) external { + var doneAt = add(era, wait); + require(doneAt <= block.timestamp); + var SinNew = sub(Sin, sin[era]); + Sin = SinNew; + sin[era] = 0; + } + + function flop() external returns (uint256) { + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var vatSin = vat.sin{view}(this); + var freeSin = sub(vatSin, Sin); + var flopDebt = sub(freeSin, Ash); + require(sump <= flopDebt); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var vatDai = vat.dai{view}(this); + require(vatDai == 0); + var AshNew = add(Ash, sump); + Ash = AshNew; + require(${Expr.extCodeSize (.storage flopperRef)} > 0); + var id = flopper.kick(this, dump, sump); + return id; + } + + function flopper() external returns (address) { + return flopper; + } + + function heal(uint256 rad) external { + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var vatDai = vat.dai{view}(this); + require(rad <= vatDai); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var vatSin = vat.sin{view}(this); + var freeSin = sub(vatSin, Sin); + var healDebt = sub(freeSin, Ash); + require(rad <= healDebt); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _healRet = vat.heal(rad); + } + + function hump() external returns (uint256) { + return hump; + } + + function kiss(uint256 rad) external { + require(rad <= Ash); + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var vatDai = vat.dai{view}(this); + require(rad <= vatDai); + var AshNew = sub(Ash, rad); + Ash = AshNew; + require(${Expr.extCodeSize (.storage vatRef)} > 0); + var _healRet = vat.heal(rad); + } + + function live() external returns (uint256) { + return live; + } + + function rely(address usr) external { + require(wards[msg.sender] == 1); + require(live == 1); + wards[usr] = 1; + } + + function sin(uint256 arg0) external returns (uint256) { + return sin[arg0]; + } + + function sump() external returns (uint256) { + return sump; + } + + function vat() external returns (address) { + return vat; + } + + function wait() external returns (uint256) { + return wait; + } + + function wards(address arg0) external returns (uint256) { + return wards[arg0]; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Dss.Vow.contract := by rfl end Benchmarks.Dss.Vow.Syntax diff --git a/Benchmarks/EAS/Attester/DynamicArray.lean b/Benchmarks/EAS/Attester/DynamicArray.lean index f705d8b0..1e6bc0f3 100644 --- a/Benchmarks/EAS/Attester/DynamicArray.lean +++ b/Benchmarks/EAS/Attester/DynamicArray.lean @@ -313,7 +313,7 @@ theorem attesterDecodeCalldata_twoDynamicArrays_none_firstLengthHuge {cd : ByteA · rw [if_neg hargsHuge] have hreadOff := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) have hreadLen := readNat_drop4_dynamic_eq_calldataWord - (cd := cd) hoffMax hlenWord + (cd := cd) hlenWord simp [decodeCalldata.decodeArgs, decodeABIValues?, decodeABIValue?, isDynamicABIType, abiTupleHeadSize?, bind, Option.bind, solcMaxLen, hreadOff, hoffMax, hreadLen, hlenHuge] @@ -350,7 +350,7 @@ theorem attesterDecodeCalldata_twoDynamicArrays_none_firstBytes32PayloadShort {c rw [if_neg (by simp [solcTotalSizeDynamicGuard])] have hreadOff := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) have hreadLen := readNat_drop4_dynamic_eq_calldataWord - (cd := cd) hoffMax hlenWord + (cd := cd) hlenWord have hstaticNone : decodeABIArrayStaticElems? bytes32 (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat 32 @@ -655,7 +655,7 @@ theorem attesterDecodeCalldata_twoDynamicArrays_none_secondOffsetHuge {cd : Byte rw [if_neg (by simp [solcTotalSizeDynamicGuard])] have hread0 := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) have hreadLen0 := readNat_drop4_dynamic_eq_calldataWord - (cd := cd) hoff0Max hlenWord + (cd := cd) hlenWord have hread1 := readNat_drop4_32_eq_calldataWord (cd := cd) hsz68 have hstaticSize : staticABIEncodedSize? bytes32 = some 32 := by native_decide @@ -716,7 +716,7 @@ theorem attesterDecodeCalldata_twoDynamicArrays_none_secondLengthShort {cd : Byt rw [if_neg (by simp [solcTotalSizeDynamicGuard])] have hread0 := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) have hreadLen0 := readNat_drop4_dynamic_eq_calldataWord - (cd := cd) hoff0Max hlen0Word + (cd := cd) hlen0Word have hread1 := readNat_drop4_32_eq_calldataWord (cd := cd) hsz68 have hreadLen1 : readNat? (cd.toList.drop 4) (calldataWord cd 36).toNat = none := @@ -783,7 +783,7 @@ theorem attesterDecodeCalldata_twoDynamicArrays_none_secondLengthHuge {cd : Byte rw [if_neg (by simp [solcTotalSizeDynamicGuard])] have hread0 := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) have hreadLen0 := readNat_drop4_dynamic_eq_calldataWord - (cd := cd) hoff0Max hlen0Word + (cd := cd) hlen0Word have hread1 := readNat_drop4_32_eq_calldataWord (cd := cd) hsz68 have hreadLen1 := readNat_drop4_at_eq_calldataWord (cd := cd) (off := (calldataWord cd 36).toNat) hlen1Word @@ -853,7 +853,7 @@ theorem attesterDecodeCalldata_twoDynamicArrays_none_secondPayloadShort {cd : By rw [if_neg (by simp [solcTotalSizeDynamicGuard])] have hread0 := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) have hreadLen0 := readNat_drop4_dynamic_eq_calldataWord - (cd := cd) hoff0Max hlen0Word + (cd := cd) hlen0Word have hread1 := readNat_drop4_32_eq_calldataWord (cd := cd) hsz68 have hreadLen1 := readNat_drop4_at_eq_calldataWord (cd := cd) (off := (calldataWord cd 36).toNat) hlen1Word diff --git a/Benchmarks/EAS/Attester/MultiRevoke.lean b/Benchmarks/EAS/Attester/MultiRevoke.lean index 156a22a9..a8a19d12 100644 --- a/Benchmarks/EAS/Attester/MultiRevoke.lean +++ b/Benchmarks/EAS/Attester/MultiRevoke.lean @@ -1225,14 +1225,14 @@ theorem attesterMultiRevoke_postEncoder_fromDone (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) (g := gS) v rd775 by_cases hcodeSizeEvm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm + Reasoning.Theory.extCodeSizeWord σ_evm (attesterMultiRevokeTargetWord v) = ⟨0⟩ · have hrdrev := attesterX_multiRevokeNoCodeAtExtcodesize (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) (g := gS) v rd787 hcodeSizeEvm (by simp) have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (attesterMultiRevokeTargetWord v) = ⟨0⟩ := attesterMultiRevokeCodeSize_zero_accountMapEquiv v hAccounts hcodeSizeEvm have hcodeSolmRaw := @@ -1265,7 +1265,7 @@ theorem attesterMultiRevoke_postEncoder_fromDone hrequestsDone hguard exact hrdrev.reEquivExecutionRevert hIcode hd hdec hbody · have hcodeSizeSolmNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm + Reasoning.Theory.extCodeSizeWord σ_solm (attesterMultiRevokeTargetWord v) ≠ ⟨0⟩ := attesterMultiRevokeCodeSize_ne_accountMapEquiv v hAccounts hcodeSizeEvm have hcodeSolmRaw := diff --git a/Benchmarks/EAS/Attester/MultiRevokePostCall.lean b/Benchmarks/EAS/Attester/MultiRevokePostCall.lean index 899a2f96..7783d10d 100644 --- a/Benchmarks/EAS/Attester/MultiRevokePostCall.lean +++ b/Benchmarks/EAS/Attester/MultiRevokePostCall.lean @@ -215,14 +215,14 @@ theorem attesterX_multiRevokeEncoderReturnToExtcodesize raw dup8 (by attester_decode_at v, ⟨785⟩, 0x87, .DUP8) (by evm_ov), raw dup1 (by attester_decode_at v, ⟨786⟩, 0x80, .DUP1) (by evm_ov)]⟩ -private theorem attesterMultiRevoke_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos +private theorem attesterMultiRevoke_extCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => exfalso @@ -241,14 +241,14 @@ private theorem attesterMultiRevoke_uniswapExtCodeSizeWord_ne_zero_lookup_code_p · simp [UInt256.toNat, hword] at hzeroNat simpa [hacc] using Nat.pos_of_ne_zero htoNatNe -private theorem attesterMultiRevoke_uniswapExtCodeSizeWord_zero_lookup_code_zero +private theorem attesterMultiRevoke_extCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using @@ -285,14 +285,14 @@ theorem attesterMultiRevokeCodeSize_ne_accountMapEquiv (v : AttesterImmutables) {σ τ : AccountMap} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (attesterMultiRevokeTargetWord v) ≠ + Reasoning.Theory.extCodeSizeWord σ (attesterMultiRevokeTargetWord v) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (attesterMultiRevokeTargetWord v) ≠ + Reasoning.Theory.extCodeSizeWord τ (attesterMultiRevokeTargetWord v) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (attesterMultiRevokeTargetWord v) rw [hsame] exact hzero @@ -301,12 +301,12 @@ theorem attesterMultiRevokeCodeSize_zero_accountMapEquiv (v : AttesterImmutables {σ τ : AccountMap} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (attesterMultiRevokeTargetWord v) = + Reasoning.Theory.extCodeSizeWord σ (attesterMultiRevokeTargetWord v) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (attesterMultiRevokeTargetWord v) = + Reasoning.Theory.extCodeSizeWord τ (attesterMultiRevokeTargetWord v) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (attesterMultiRevokeTargetWord v) rw [← hsame] exact hzero @@ -315,13 +315,13 @@ theorem attesterMultiRevokeEasCode_pos_of_codeSize_ne {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (attesterMultiRevokeTargetWord v) ≠ + Reasoning.Theory.extCodeSizeWord σ (attesterMultiRevokeTargetWord v) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ g A I).lookupAccount (EVM.address v.eas)).option 0 (fun acc => acc.code.size))).toNat := by simpa [initState, State.lookupAccount] using - attesterMultiRevoke_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + attesterMultiRevoke_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ) (target := attesterMultiRevokeTargetWord v) (addr := EVM.address v.eas) (attesterMultiRevokeTarget_eq v) hne @@ -329,13 +329,13 @@ theorem attesterMultiRevokeEasCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (attesterMultiRevokeTargetWord v) = + Reasoning.Theory.extCodeSizeWord σ (attesterMultiRevokeTargetWord v) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ g A I).lookupAccount (EVM.address v.eas)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [initState, State.lookupAccount] using - attesterMultiRevoke_uniswapExtCodeSizeWord_zero_lookup_code_zero + attesterMultiRevoke_extCodeSizeWord_zero_lookup_code_zero (σ := σ) (target := attesterMultiRevokeTargetWord v) (addr := EVM.address v.eas) (attesterMultiRevokeTarget_eq v) hzero @@ -347,7 +347,7 @@ theorem attesterX_multiRevokeCallAtExtcodesize {cA gh bl σ σ₀ A I} {g : Sat2 (⟨787⟩ : UInt256) (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: outSize :: rest) mem aw ByteArray.empty (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) (htgt : EVM.address v.eas = AccountAddress.ofUInt256 target) (hcd : (config v).externalABI.encode? "multiRevoke" args = some (mem.readWithPadding inOff.toNat inSize.toNat)) @@ -367,7 +367,7 @@ theorem attesterX_multiRevokeCallAtExtcodesize {cA gh bl σ σ₀ A I} {g : Sat2 accountMap := σ', substate := A', createdAccounts := cA' }, o) true ∧ o.size < UInt256.size := by obtain ⟨_, _, _, rd801⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨787⟩) (okPc := ⟨798⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨787⟩) (okPc := ⟨798⟩) rd hcodeSize (by attester_decode_at v, ⟨787⟩, 0x3b, .EXTCODESIZE) (by attester_decode_at v, ⟨788⟩, 0x15, .ISZERO) @@ -401,15 +401,15 @@ theorem attesterX_multiRevokeNoCodeAtExtcodesize {cA gh bl σ σ₀ A I} {g : Sa (⟨787⟩ : UInt256) (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: outSize :: rest) mem aw ByteArray.empty (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) (hov : rest.length + 9 ≤ 1024) : RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨k788, C788, rd788raw⟩ := RD.uniswapExtcodesize rd + obtain ⟨k788, C788, rd788raw⟩ := RD.extcodesize rd (by attester_decode_at v, ⟨787⟩, 0x3b, .EXTCODESIZE) (by simp only [List.length_cons]; omega) have rd788 : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨788⟩ : UInt256) - (Reasoning.Theory.uniswapExtCodeSizeWord σ target :: target :: ⟨0⟩ :: + (Reasoning.Theory.extCodeSizeWord σ target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: outSize :: rest) mem aw ByteArray.empty (cA, σ) k788 C788 := by simpa using rd788raw @@ -495,12 +495,12 @@ theorem attesterX_multiRevokeCallDepthLimitAtExtcodesize (⟨787⟩ : UInt256) (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: outSize :: rest) mem aw ByteArray.empty (cA, σ) k C) - (hcodeSize : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) + (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) (hdepth : I.depth = 1024) (hov : rest.length + 9 ≤ 1024) : RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, _, rd801⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨787⟩) (okPc := ⟨798⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨787⟩) (okPc := ⟨798⟩) rd hcodeSize (by attester_decode_at v, ⟨787⟩, 0x3b, .EXTCODESIZE) (by attester_decode_at v, ⟨788⟩, 0x15, .ISZERO) @@ -539,7 +539,7 @@ theorem attesterX_multiRevokeSuccessStop {cA gh bl σ σ₀ A I} {g : Sat256} mem aw o acc k C) : RDret (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) acc ByteArray.empty := by obtain ⟨_, _, rd818⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨802⟩) (okPc := ⟨816⟩) rd + RD.solcCallSuccessGuardOk (pc := ⟨802⟩) (okPc := ⟨816⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by attester_decode_at v, ⟨802⟩, 0x15, .ISZERO) (by attester_decode_at v, ⟨803⟩, 0x80, .DUP1) diff --git a/Benchmarks/EAS/Attester/Revoke.lean b/Benchmarks/EAS/Attester/Revoke.lean index 65265fac..7f1f6cde 100644 --- a/Benchmarks/EAS/Attester/Revoke.lean +++ b/Benchmarks/EAS/Attester/Revoke.lean @@ -1138,14 +1138,14 @@ theorem attesterX_revokeToExtcodesize {cA gh bl σ σ₀ A I} {g : Sat256} show UInt256.sub (⟨356⟩ : UInt256) ⟨256⟩ = (⟨100⟩ : UInt256) by decide] using rd2001⟩ -private theorem attester_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos +private theorem attester_extCodeSizeWord_ne_zero_lookup_code_pos {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.uniswapExtCodeSizeWord σ target ≠ ⟨0⟩) : + (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : 0 < (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hne + unfold Reasoning.Theory.extCodeSizeWord at hne cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => exfalso @@ -1164,14 +1164,14 @@ private theorem attester_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos · simp [UInt256.toNat, hword] at hzeroNat simpa [hacc] using Nat.pos_of_ne_zero htoNatNe -private theorem attester_uniswapExtCodeSizeWord_zero_lookup_code_zero +private theorem attester_extCodeSizeWord_zero_lookup_code_zero {σ : AccountMap} {target : UInt256} {addr : AccountAddress} (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.uniswapExtCodeSizeWord σ target = ⟨0⟩) : + (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : (UInt256.ofNat ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by subst addr - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hzero + unfold Reasoning.Theory.extCodeSizeWord at hzero cases hacc : σ.find? (AccountAddress.ofUInt256 target) with | none => simpa [hacc, Option.option] using @@ -1208,12 +1208,12 @@ theorem attesterRevokeCodeSize_ne_accountMapEquiv (v : AttesterImmutables) {σ τ : AccountMap} (hAccounts : accountMapEquiv σ τ) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (attesterRevokeTargetWord v) ≠ ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (attesterRevokeTargetWord v) ≠ ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (attesterRevokeTargetWord v) ≠ ⟨0⟩ := by intro hzero apply hne have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (attesterRevokeTargetWord v) rw [hsame] exact hzero @@ -1222,10 +1222,10 @@ theorem attesterRevokeCodeSize_zero_accountMapEquiv (v : AttesterImmutables) {σ τ : AccountMap} (hAccounts : accountMapEquiv σ τ) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (attesterRevokeTargetWord v) = ⟨0⟩) : - Reasoning.Theory.uniswapExtCodeSizeWord τ (attesterRevokeTargetWord v) = ⟨0⟩ := by + Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord τ (attesterRevokeTargetWord v) = ⟨0⟩ := by have hsame := - Reasoning.Theory.uniswapExtCodeSizeWord_accountMapEquiv hAccounts + Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts (attesterRevokeTargetWord v) rw [← hsame] exact hzero @@ -1234,12 +1234,12 @@ theorem attesterRevokeEasCode_pos_of_codeSize_ne {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) (hne : - Reasoning.Theory.uniswapExtCodeSizeWord σ (attesterRevokeTargetWord v) ≠ ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) ≠ ⟨0⟩) : 0 < (UInt256.ofNat (((initState cA gh bl σ σ₀ g A I).lookupAccount (EVM.address v.eas)).option 0 (fun acc => acc.code.size))).toNat := by simpa [initState, State.lookupAccount] using - attester_uniswapExtCodeSizeWord_ne_zero_lookup_code_pos + attester_extCodeSizeWord_ne_zero_lookup_code_pos (σ := σ) (target := attesterRevokeTargetWord v) (addr := EVM.address v.eas) (attesterRevokeTarget_eq v) hne @@ -1247,12 +1247,12 @@ theorem attesterRevokeEasCode_zero_of_codeSize_zero {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) (hzero : - Reasoning.Theory.uniswapExtCodeSizeWord σ (attesterRevokeTargetWord v) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) = ⟨0⟩) : (UInt256.ofNat (((initState cA gh bl σ σ₀ g A I).lookupAccount (EVM.address v.eas)).option 0 (fun acc => acc.code.size))).toNat = 0 := by simpa [initState, State.lookupAccount] using - attester_uniswapExtCodeSizeWord_zero_lookup_code_zero + attester_extCodeSizeWord_zero_lookup_code_zero (σ := σ) (target := attesterRevokeTargetWord v) (addr := EVM.address v.eas) (attesterRevokeTarget_eq v) hzero @@ -1266,7 +1266,7 @@ theorem attesterX_revokeNoCode {cA gh bl σ σ₀ A I} {g : Sat256} (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = false) (hrevoke : (attesterRevokeSelBytes == I.calldata.extract 0 4) = true) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (attesterRevokeTargetWord v) = ⟨0⟩) : + Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) = ⟨0⟩) : RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd2001⟩ := attesterX_revokeToExtcodesize (cA := cA) (gh := gh) (bl := bl) @@ -1274,11 +1274,11 @@ theorem attesterX_revokeNoCode {cA gh bl σ σ₀ A I} {g : Sat256} (attesterX_revokeWrapper (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) v hcode hwv hsz4 hsize hmultiRevoke hmultiAttest hattest hrevoke) - obtain ⟨k2002, C2002, rd2002raw⟩ := RD.uniswapExtcodesize rd2001 + obtain ⟨k2002, C2002, rd2002raw⟩ := RD.extcodesize rd2001 (by attester_decode_at v, ⟨2001⟩, 0x3b, .EXTCODESIZE) (by simp) have rd2002 : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨2002⟩ : UInt256) - [Reasoning.Theory.uniswapExtCodeSizeWord σ (attesterRevokeTargetWord v), + [Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v), attesterRevokeTargetWord v, ⟨0⟩, ⟨256⟩, ⟨100⟩, ⟨256⟩, ⟨0⟩, ⟨356⟩, ⟨0x46926267⟩, attesterRevokeTargetWord v, attesterRevokeUidWord I, attesterRevokeSchemaWord I, ⟨97⟩, solcSelectorWord I] @@ -1307,7 +1307,7 @@ theorem attesterX_revokePostCall {cA gh bl σ σ₀ A I} {g : Sat256} [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (attesterRevokeTargetWord v) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) ≠ ⟨0⟩) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (o : ByteArray) (A' : Substate) (k' C' : ℕ), @@ -1327,7 +1327,7 @@ theorem attesterX_revokePostCall {cA gh bl σ σ₀ A I} {g : Sat256} obtain ⟨_, _, rd2001⟩ := attesterX_revokeToExtcodesize (v := v) hsz68 hsize hsmall hreach obtain ⟨_, _, _, rd2015⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2001⟩) (okPc := ⟨2012⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨2001⟩) (okPc := ⟨2012⟩) rd2001 hcodeSize (by attester_decode_at v, ⟨2001⟩, 0x3b, .EXTCODESIZE) (by attester_decode_at v, ⟨2002⟩, 0x15, .ISZERO) @@ -1442,7 +1442,7 @@ theorem attesterX_revokeSuccessStop {cA gh bl σ σ₀ A I} {g : Sat256} mem ⟨12⟩ o acc k C) : RDret (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) acc ByteArray.empty := by obtain ⟨_, _, rd2032⟩ := - RD.uniswapCallSuccessGuardOk (pc := ⟨2016⟩) (okPc := ⟨2030⟩) rd + RD.solcCallSuccessGuardOk (pc := ⟨2016⟩) (okPc := ⟨2030⟩) rd (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) (by attester_decode_at v, ⟨2016⟩, 0x15, .ISZERO) (by attester_decode_at v, ⟨2017⟩, 0x80, .DUP1) @@ -1475,7 +1475,7 @@ theorem attesterX_revokeCallDepthLimit {cA gh bl σ σ₀ A I} {g : Sat256} (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = false) (hrevoke : (attesterRevokeSelBytes == I.calldata.extract 0 4) = true) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (attesterRevokeTargetWord v) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) ≠ ⟨0⟩) (hdepth : I.depth = 1024) : RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by obtain ⟨_, _, rd2001⟩ := @@ -1485,7 +1485,7 @@ theorem attesterX_revokeCallDepthLimit {cA gh bl σ σ₀ A I} {g : Sat256} (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) v hcode hwv hsz4 hsize hmultiRevoke hmultiAttest hattest hrevoke) obtain ⟨_, _, _, rd2015⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨2001⟩) (okPc := ⟨2012⟩) + RD.solcExtcodesizeGuardOkGas (pc := ⟨2001⟩) (okPc := ⟨2012⟩) rd2001 hcodeSize (by attester_decode_at v, ⟨2001⟩, 0x3b, .EXTCODESIZE) (by attester_decode_at v, ⟨2002⟩, 0x15, .ISZERO) @@ -1554,13 +1554,13 @@ theorem attesterRevokeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (σ₀ := σ₀) (A := A) (I := I) (g := gS) v hIcode hwv hsz4 hsize hmultiRevoke hmultiAttest hattest hrevoke by_cases hcodeSizeEvm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_evm (attesterRevokeTargetWord v) = ⟨0⟩ + Reasoning.Theory.extCodeSizeWord σ_evm (attesterRevokeTargetWord v) = ⟨0⟩ · have hrdrev := attesterX_revokeNoCode (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) (g := gS) v hIcode hwv hsz4 hsize hsz68 hsmall hmultiRevoke hmultiAttest hattest hrevoke hcodeSizeEvm have hcodeSizeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (attesterRevokeTargetWord v) = + Reasoning.Theory.extCodeSizeWord σ_solm (attesterRevokeTargetWord v) = ⟨0⟩ := attesterRevokeCodeSize_zero_accountMapEquiv v hAccounts hcodeSizeEvm have hcodeSolmRaw := @@ -1589,7 +1589,7 @@ theorem attesterRevokeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} attesterRevokeBodyNoCode v evmSolm (attesterRevokeStore I) hwvSolm hguard exact hrdrev.reEquivExecutionRevert hIcode hd hdec hbody · have hcodeSizeSolmNe : - Reasoning.Theory.uniswapExtCodeSizeWord σ_solm (attesterRevokeTargetWord v) ≠ + Reasoning.Theory.extCodeSizeWord σ_solm (attesterRevokeTargetWord v) ≠ ⟨0⟩ := attesterRevokeCodeSize_ne_accountMapEquiv v hAccounts hcodeSizeEvm have hcodeSolmRaw := diff --git a/Benchmarks/ERC721/SpecSyntax.lean b/Benchmarks/ERC721/SpecSyntax.lean new file mode 100644 index 00000000..00e5b2d4 --- /dev/null +++ b/Benchmarks/ERC721/SpecSyntax.lean @@ -0,0 +1,73 @@ +import Benchmarks.ERC721.Spec +import Solm.Notation + +/-! +# ERC721 spec in the Solidity-faithful Solm frontend + +The whole ERC721 benchmark spec, written with `solidity%` and proven definitionally equal to the +AST spec in `Benchmarks/ERC721/Spec.lean`. + +Notes mirroring the AST spec: +* The spec constructor is `{ params := [], body := [] }` — no callvalue guard — so it is written + `payable` (which suppresses the auto guard) with an empty body. +* The `unchecked` balance decrement/increment in `transferFrom` is the explicit `% 2^256` wrap. +* `from`/`to` are Lean keywords, written `«from»`/`«to»`. +* Transition order matches `erc721Contract.transitions` (selector order). +-/ + +open Solm Solm.Notation + +namespace ERC721.Syntax + +def contractSyntax : ContractDecl := solidity% contract ERC721 { + mapping(uint256 => address) _ownerOf; + mapping(address => uint256) _balanceOf; + mapping(uint256 => address) getApproved; + mapping(address => mapping(address => bool)) isApprovedForAll; + + constructor() payable { } + + function approve(address spender, uint256 id) external { + address owner = _ownerOf[id]; + require(msg.sender == owner || isApprovedForAll[owner][msg.sender]); + getApproved[id] = spender; + } + + function balanceOf(address owner) external returns (uint256) { + require(owner != address(0)); + return _balanceOf[owner]; + } + + function getApproved(uint256 id) external returns (address) { + return getApproved[id]; + } + + function isApprovedForAll(address owner, address operator) external returns (bool) { + return isApprovedForAll[owner][operator]; + } + + function ownerOf(uint256 id) external returns (address) { + address owner = _ownerOf[id]; + require(owner != address(0)); + return owner; + } + + function setApprovalForAll(address operator, bool approved) external { + isApprovedForAll[msg.sender][operator] = approved; + } + + function transferFrom(address «from», address «to», uint256 id) external { + require(«from» == _ownerOf[id]); + require(«to» != address(0)); + require((msg.sender == «from» || isApprovedForAll[«from»][msg.sender]) + || msg.sender == getApproved[id]); + _balanceOf[«from»] = (_balanceOf[«from»] - 1) % #(Int.ofNat EVM.wordModulus); + _balanceOf[«to»] = (_balanceOf[«to»] + 1) % #(Int.ofNat EVM.wordModulus); + _ownerOf[id] = «to»; + delete getApproved[id]; + } +} + +theorem contractSyntax_eq : contractSyntax = ERC721.erc721Contract := by rfl + +end ERC721.Syntax diff --git a/Benchmarks/Klima/SpecSyntax.lean b/Benchmarks/Klima/SpecSyntax.lean new file mode 100644 index 00000000..03e5cc6b --- /dev/null +++ b/Benchmarks/Klima/SpecSyntax.lean @@ -0,0 +1,350 @@ +import Benchmarks.Klima.Spec +import Solm.Notation + +/-! +# KlimaToken spec in the Solidity-faithful Solm frontend + +The whole KlimaToken benchmark spec, written with `solidity%` and proven definitionally equal to +the AST spec in `Benchmarks/Klima/Spec.lean`. + +Notes mirroring the AST spec: +* SafeMath checked add/sub are the explicit `require` + `(… ) as uint256` range-cast forms. +* The `_beforeTokenTransfer` TWAP hook is inlined at every mint/burn/transfer site: the doubled + `dexIndexes[bytes32(uint256(x))] != 0` test (`_beforeTokenTransfer` then `_uodateTWAPOracle`), + the `EXTCODESIZE` guard, and the `twapOracle.updateTWAP` external call. +* EnumerableSet keys are `bytes32(uint256(addr))` casts, exactly as the library stores them. +* `permit`'s ecrecover precompile call targets `address(1)` (a cast), which the surface low-level + call cannot express, so that one statement is spliced; its `ecrecoverSuccess`/`ecrecoverData` + binders are then referenced via `${…}`. `PERMIT_TYPEHASH` and the EIP-191 prefix reuse the + spec's `permitTypehashExpr`/`eip191Prefix` defs. +* Transition order matches `contract.transitions` (selector order). +-/ + +open Solm Solm.Notation + +namespace Benchmarks.Klima.Syntax + +def contractSyntax : ContractDecl := solidity% contract KlimaToken { + mapping(address => uint256) balances; + mapping(address => mapping(address => uint256)) allowances; + uint256 totalSupply; + string name; + string symbol; + uint8 decimals; + mapping(address => uint256) nonces; + bytes32 DOMAIN_SEPARATOR; + address owner; + address vault; + bytes32[] dexValues; + mapping(bytes32 => uint256) dexIndexes; + address twapOracle; + uint256 twapEpochPeriod; + + constructor() { + name = "Klima DAO"; + symbol = "KLIMA"; + decimals = 9; + DOMAIN_SEPARATOR = keccak256(abi.encodePacked( + bytes32(keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")), + bytes32(keccak256("Klima DAO")), + bytes32(keccak256("1")), + uint256(block.chainid), + uint256(uint256(this)))); + owner = msg.sender; + } + + function addTWAPSource(address newSource) external { + require(owner == msg.sender); + require(dexIndexes[bytes32(uint256(newSource))] == 0); + dexValues.push(bytes32(uint256(newSource))); + dexIndexes[bytes32(uint256(newSource))] = dexValues.length; + } + + function allowance(address owner, address spender) external returns (uint256) { + return allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) external returns (bool) { + require(msg.sender != address(0)); + require(spender != address(0)); + allowances[msg.sender][spender] = amount; + return true; + } + + function balanceOf(address account) external returns (uint256) { + return balances[account]; + } + + function burn(uint256 amount) external { + require(msg.sender != address(0)); + if (dexIndexes[bytes32(uint256(msg.sender))] != 0) { + if (dexIndexes[bytes32(uint256(msg.sender))] != 0) { + require(twapOracle.code.length > 0); + var _twapRet = twapOracle.updateTWAP(msg.sender, twapEpochPeriod); + } + } else { + if (dexIndexes[bytes32(uint256(address(0)))] != 0) { + if (dexIndexes[bytes32(uint256(address(0)))] != 0) { + require(twapOracle.code.length > 0); + var _twapRet = twapOracle.updateTWAP(address(0), twapEpochPeriod); + } + } + } + require(amount <= balances[msg.sender]); + balances[msg.sender] = (balances[msg.sender] - amount) as uint256; + require(amount <= totalSupply); + totalSupply = (totalSupply - amount) as uint256; + } + + function burnFrom(address account, uint256 amount) external { + require(amount <= allowances[account][msg.sender]); + require(account != address(0)); + require(msg.sender != address(0)); + allowances[account][msg.sender] = (allowances[account][msg.sender] - amount) as uint256; + require(account != address(0)); + if (dexIndexes[bytes32(uint256(account))] != 0) { + if (dexIndexes[bytes32(uint256(account))] != 0) { + require(twapOracle.code.length > 0); + var _twapRet = twapOracle.updateTWAP(account, twapEpochPeriod); + } + } else { + if (dexIndexes[bytes32(uint256(address(0)))] != 0) { + if (dexIndexes[bytes32(uint256(address(0)))] != 0) { + require(twapOracle.code.length > 0); + var _twapRet = twapOracle.updateTWAP(address(0), twapEpochPeriod); + } + } + } + require(amount <= balances[account]); + balances[account] = (balances[account] - amount) as uint256; + require(amount <= totalSupply); + totalSupply = (totalSupply - amount) as uint256; + } + + function _burnFrom(address account, uint256 amount) external { + require(amount <= allowances[account][msg.sender]); + require(account != address(0)); + require(msg.sender != address(0)); + allowances[account][msg.sender] = (allowances[account][msg.sender] - amount) as uint256; + require(account != address(0)); + if (dexIndexes[bytes32(uint256(account))] != 0) { + if (dexIndexes[bytes32(uint256(account))] != 0) { + require(twapOracle.code.length > 0); + var _twapRet = twapOracle.updateTWAP(account, twapEpochPeriod); + } + } else { + if (dexIndexes[bytes32(uint256(address(0)))] != 0) { + if (dexIndexes[bytes32(uint256(address(0)))] != 0) { + require(twapOracle.code.length > 0); + var _twapRet = twapOracle.updateTWAP(address(0), twapEpochPeriod); + } + } + } + require(amount <= balances[account]); + balances[account] = (balances[account] - amount) as uint256; + require(amount <= totalSupply); + totalSupply = (totalSupply - amount) as uint256; + } + + function changeTWAPEpochPeriod(uint256 newTWAPEpochPeriod) external { + require(owner == msg.sender); + require(newTWAPEpochPeriod > 0); + twapEpochPeriod = newTWAPEpochPeriod; + } + + function changeTWAPOracle(address newTWAPOracle) external { + require(owner == msg.sender); + twapOracle = newTWAPOracle; + } + + function decimals() external returns (uint8) { + return decimals; + } + + function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool) { + require(subtractedValue <= allowances[msg.sender][spender]); + require(msg.sender != address(0)); + require(spender != address(0)); + allowances[msg.sender][spender] = (allowances[msg.sender][spender] - subtractedValue) as uint256; + return true; + } + + function DOMAIN_SEPARATOR() external returns (bytes32) { + return DOMAIN_SEPARATOR; + } + + function increaseAllowance(address spender, uint256 addedValue) external returns (bool) { + require(((allowances[msg.sender][spender] + addedValue) as uint256) >= allowances[msg.sender][spender]); + require(msg.sender != address(0)); + require(spender != address(0)); + allowances[msg.sender][spender] = (allowances[msg.sender][spender] + addedValue) as uint256; + return true; + } + + function mint(address account, uint256 amount) external { + require(vault == msg.sender); + require(account != address(0)); + if (dexIndexes[bytes32(uint256(address(this)))] != 0) { + if (dexIndexes[bytes32(uint256(address(this)))] != 0) { + require(twapOracle.code.length > 0); + var _twapRet = twapOracle.updateTWAP(address(this), twapEpochPeriod); + } + } else { + if (dexIndexes[bytes32(uint256(account))] != 0) { + if (dexIndexes[bytes32(uint256(account))] != 0) { + require(twapOracle.code.length > 0); + var _twapRet = twapOracle.updateTWAP(account, twapEpochPeriod); + } + } + } + require(((totalSupply + amount) as uint256) >= totalSupply); + totalSupply = (totalSupply + amount) as uint256; + require(((balances[account] + amount) as uint256) >= balances[account]); + balances[account] = (balances[account] + amount) as uint256; + } + + function name() external returns (string) { + return name; + } + + function nonces(address owner) external returns (uint256) { + return nonces[owner]; + } + + function owner() external returns (address) { + return owner; + } + + function permit(address owner, address spender, uint256 amount, uint256 deadline, + uint8 v, bytes32 r, bytes32 s) external { + require(block.timestamp <= deadline); + bytes32 hashStruct = keccak256(abi.encodePacked( + bytes32(${permitTypehashExpr}), + uint256(uint256(owner)), + uint256(uint256(spender)), + uint256(amount), + uint256(nonces[owner]), + uint256(deadline))); + bytes32 digest = keccak256(abi.encodePacked( + bytes(${eip191Prefix}), + bytes32(DOMAIN_SEPARATOR), + bytes32(hashStruct))); + ${[Stmt.lowLevelCall ecrecoverPrecompile (.intLit 0) ecrecoverCalldataExpr + "ecrecoverSuccess" "ecrecoverData" false]} + require(${Expr.var "ecrecoverSuccess"}); + address signer = abi.decode(${Expr.var "ecrecoverData"}, (address)); + require(signer != address(0) && signer == owner); + nonces[owner] = (nonces[owner] + 1) as uint256; + require(owner != address(0)); + require(spender != address(0)); + allowances[owner][spender] = amount; + } + + function PERMIT_TYPEHASH() external returns (bytes32) { + return ${permitTypehashExpr}; + } + + function removeTWAPSource(address rm) external { + require(owner == msg.sender); + uint256 valueIndex = dexIndexes[bytes32(uint256(rm))]; + require(valueIndex != 0); + uint256 toDeleteIndex = (valueIndex - 1) as uint256; + uint256 lastIndex = (dexValues.length - 1) as uint256; + bytes32 lastvalue = dexValues[lastIndex]; + dexValues[toDeleteIndex] = lastvalue; + dexIndexes[lastvalue] = (toDeleteIndex + 1) as uint256; + dexValues.pop(); + delete dexIndexes[bytes32(uint256(rm))]; + } + + function renounceOwnership() external { + require(owner == msg.sender); + owner = address(0); + } + + function setVault(address vault_) external returns (bool) { + require(owner == msg.sender); + vault = vault_; + return true; + } + + function symbol() external returns (string) { + return symbol; + } + + function totalSupply() external returns (uint256) { + return totalSupply; + } + + function transfer(address recipient, uint256 amount) external returns (bool) { + require(msg.sender != address(0)); + require(recipient != address(0)); + if (dexIndexes[bytes32(uint256(msg.sender))] != 0) { + if (dexIndexes[bytes32(uint256(msg.sender))] != 0) { + require(twapOracle.code.length > 0); + var _twapRet = twapOracle.updateTWAP(msg.sender, twapEpochPeriod); + } + } else { + if (dexIndexes[bytes32(uint256(recipient))] != 0) { + if (dexIndexes[bytes32(uint256(recipient))] != 0) { + require(twapOracle.code.length > 0); + var _twapRet = twapOracle.updateTWAP(recipient, twapEpochPeriod); + } + } + } + require(amount <= balances[msg.sender]); + balances[msg.sender] = (balances[msg.sender] - amount) as uint256; + require(((balances[recipient] + amount) as uint256) >= balances[recipient]); + balances[recipient] = (balances[recipient] + amount) as uint256; + return true; + } + + function transferFrom(address sender_, address recipient, uint256 amount) external returns (bool) { + require(sender_ != address(0)); + require(recipient != address(0)); + if (dexIndexes[bytes32(uint256(sender_))] != 0) { + if (dexIndexes[bytes32(uint256(sender_))] != 0) { + require(twapOracle.code.length > 0); + var _twapRet = twapOracle.updateTWAP(sender_, twapEpochPeriod); + } + } else { + if (dexIndexes[bytes32(uint256(recipient))] != 0) { + if (dexIndexes[bytes32(uint256(recipient))] != 0) { + require(twapOracle.code.length > 0); + var _twapRet = twapOracle.updateTWAP(recipient, twapEpochPeriod); + } + } + } + require(amount <= balances[sender_]); + balances[sender_] = (balances[sender_] - amount) as uint256; + require(((balances[recipient] + amount) as uint256) >= balances[recipient]); + balances[recipient] = (balances[recipient] + amount) as uint256; + require(amount <= allowances[sender_][msg.sender]); + require(sender_ != address(0)); + require(msg.sender != address(0)); + allowances[sender_][msg.sender] = (allowances[sender_][msg.sender] - amount) as uint256; + return true; + } + + function transferOwnership(address newOwner) external { + require(owner == msg.sender); + require(newOwner != address(0)); + owner = newOwner; + } + + function twapEpochPeriod() external returns (uint256) { + return twapEpochPeriod; + } + + function twapOracle() external returns (address) { + return twapOracle; + } + + function vault() external returns (address) { + return vault; + } +} + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Klima.contract := by rfl + +end Benchmarks.Klima.Syntax diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/UpdateDelay.lean b/Benchmarks/OpenZeppelinBench/TimelockController/UpdateDelay.lean index fdcdf64c..268d634b 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/UpdateDelay.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/UpdateDelay.lean @@ -227,7 +227,7 @@ theorem tlcUpdateDelayX_ok {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} have h2167 := evm_run h with [ jumpdest, raw caller (by native_decide) (by evm_ov), - raw uniswapAddress (by native_decide) (by evm_ov), + raw address (by native_decide) (by evm_ov), dup2, eq, push2 ⟨2166⟩, jumpiT (by rw [hself, uInt256_eq_self]; decide) (by jump_dest), jumpdest, push1 ⟨2⟩ ] @@ -276,7 +276,7 @@ theorem tlcUpdateDelayRevCaller {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} have h2165pre := evm_run h with [ jumpdest, raw caller (by native_decide) (by evm_ov), - raw uniswapAddress (by native_decide) (by evm_ov), + raw address (by native_decide) (by evm_ov), dup2, eq, push2 ⟨2166⟩, jumpiNT (by exact heq0), push1 ⟨64⟩, diff --git a/Benchmarks/Safe/SpecSyntax.lean b/Benchmarks/Safe/SpecSyntax.lean index 82b842fc..edea5e9b 100644 --- a/Benchmarks/Safe/SpecSyntax.lean +++ b/Benchmarks/Safe/SpecSyntax.lean @@ -2,42 +2,586 @@ import Benchmarks.Safe.Spec import Solm.Notation /-! -# Safe spec through the Solm syntax-facing module +# Safe spec in the Solidity-faithful Solm frontend -This benchmark is large enough that the current notation frontend does not cover the full surface. -The file still mirrors the established benchmark convention by exposing a syntax-side contract value -and checking it is definitionally equal to the AST spec. +The whole Safe benchmark spec, written with `solidity%` and proven definitionally equal to the +AST spec in `Benchmarks/Safe/Spec.lean`. + +Notes mirroring the AST spec: +* EIP-712 typehashes, the EIP-1271 magic value, and the guard interface ids are the surface + `bytesN(0x…)` fixed-bytes literals; `abi.encodePacked` operands carry their ABI types as `T(e)` + annotations (`uint256(uint256(x))` when the spec casts inside the pair). +* The ecrecover and P-256 precompile calls target cast addresses (`address(1)`, `address(256)`), + which the surface low-level call cannot express, so those two statements are spliced; their + binders are then referenced via `${…}`. The `"\x19Ethereum Signed Message:\n32"` prefix reuses + the spec's `ethSignPrefix` (non-UTF-8 bytes), and the EIP-7702 code-prefix probe's + `0xef0100` literal is spliced inside the surface `extCodePrefix(…) == …` comparison. +* Function and transition order match `contract.functions` / `contract.transitions` exactly. +* The fallback declares its `bytes` return type with the surface `returns (bytes)` clause. -/ open Solm Solm.Notation namespace Benchmarks.Safe.Syntax -def storageDeclsSyntax : List StorageDecl := Benchmarks.Safe.storageDecls +def contractSyntax : ContractDecl := + solidity% contract Safe { + address singleton; + mapping(address => address) modules; + mapping(address => address) owners; + uint256 ownerCount; + uint256 threshold; + uint256 nonce; + bytes32 _deprecatedDomainSeparator; + mapping(bytes32 => uint256) signedMessages; + mapping(address => mapping(bytes32 => uint256)) approvedHashes; + address _fallbackHandler; + address _guard; + address _moduleGuard; + mapping(uint256 => uint256) _rawStorage; + + constructor() { + threshold = 1; + } -def constructorDeclSyntax : ConstructorDecl := Benchmarks.Safe.constructorDecl + receive() external payable { } -def transitionsSyntax : List TransitionDecl := Benchmarks.Safe.transitions + fallback(bytes calldata) external returns (bytes) { + address handler = _fallbackHandler; + if (handler == address(0)) { + return ""; + } else { + (bool handlerSuccess, bytes memory handlerReturn) = + handler.call(abi.encodePacked(bytes(calldata), address(msg.sender))); + require(handlerSuccess); + return handlerReturn; + } + } -def functionsSyntax : List FunctionDecl := Benchmarks.Safe.internalFunctions + function _add(uint256 x, uint256 y) internal returns (uint256) { + return ((x + y) as uint256); + } -def receiveSyntax : TransitionDecl := Benchmarks.Safe.receiveTransition + function _sub(uint256 x, uint256 y) internal returns (uint256) { + return ((x - y) as uint256); + } -def fallbackSyntax : TransitionDecl := Benchmarks.Safe.fallbackTransition + function _mul(uint256 x, uint256 y) internal returns (uint256) { + return ((x * y) as uint256); + } -def contractSyntax : ContractDecl := - { name := "Safe" - storage := storageDeclsSyntax - ctor := constructorDeclSyntax - functions := functionsSyntax - transitions := transitionsSyntax - receive := some receiveSyntax - fallback := some fallbackSyntax } - -theorem storageDeclsSyntax_eq : storageDeclsSyntax = Benchmarks.Safe.storageDecls := by - rfl - -theorem contractSyntax_eq : contractSyntax = Benchmarks.Safe.contract := by - rfl + function execute(address «to», uint256 value, bytes data, uint8 operation, uint256 txGas) + internal returns (bool) { + if (operation == 1) { + (bool success, bytes memory returnData) = «to».delegatecall(data); + } else { + (bool success, bytes memory returnData) = «to».call{value: value}(data); + } + return success; + } + + function transferToken(address token, address receiver, uint256 amount) + internal returns (bool) { + (bool tokenSuccess, bytes memory tokenData) = + token.call(abi.encodeWithSelector(transfer, receiver, amount)); + return tokenData.length == 0 ? tokenSuccess : + tokenData.length == 32 ? tokenSuccess && abi.decode(tokenData, (uint256)) != 0 : false; + } + + function handlePayment(uint256 gasUsed, uint256 baseGas, uint256 gasPrice, address gasToken, + address refundReceiver) internal returns (uint256) { + address receiver = refundReceiver == address(0) ? tx.origin : refundReceiver; + var gasTotal = _add(gasUsed, baseGas); + if (gasToken == address(0)) { + var payment = _mul(gasTotal, gasPrice < tx.gasprice ? gasPrice : tx.gasprice); + (bool refundSuccess, bytes memory refundData) = receiver.call{value: payment}(""); + require(refundSuccess); + } else { + var payment = _mul(gasTotal, gasPrice); + var transferred = transferToken(gasToken, receiver, payment); + require(transferred); + } + return payment; + } + + function requireCanAddOwner(address owner) internal { + require(owner != address(0) && owner != address(1) && + (owner != address(this) || + extCodePrefix(address(this), 3) == ${Expr.bytesLit ⟨#[0xef, 0x01, 0x00]⟩})); + require(owners[owner] == address(0)); + } + + function requireCanRemoveOwner(address prevOwner, address owner) internal { + require(owner != address(0) && owner != address(1) && + (owner != address(this) || + extCodePrefix(address(this), 3) == ${Expr.bytesLit ⟨#[0xef, 0x01, 0x00]⟩})); + require(owners[prevOwner] == owner); + } + + function changeThresholdBody(uint256 _threshold) internal { + require(_threshold <= ownerCount); + require(_threshold != 0); + threshold = _threshold; + } + + function setupOwners(address[] _owners, uint256 _threshold) internal { + require(threshold == 0); + require(_threshold <= _owners.length); + require(_threshold != 0); + address currentOwner = address(1); + uint256 ownersLength = _owners.length; + uint256 i = 0; + while (i < ownersLength) { + address owner = _owners[i]; + require(owner != currentOwner); + var _ok = requireCanAddOwner(owner); + owners[currentOwner] = owner; + currentOwner = owner; + i = ((i + 1) as uint256); + } + owners[currentOwner] = address(1); + ownerCount = ownersLength; + threshold = _threshold; + } + + function internalSetFallbackHandler(address handler) internal { + require(handler != address(this)); + _fallbackHandler = handler; + } + + function setupModules(address «to», bytes data) internal { + require(modules[address(1)] == address(0)); + modules[address(1)] = address(1); + if («to» != address(0)) { + require(«to».code.length > 0); + var setupSuccess = execute(«to», 0, data, 1, type(uint256).max); + require(setupSuccess); + } + } + + function preModuleExecution(address «to», uint256 value, bytes data, uint8 operation) + internal returns (address, bytes32) { + address guard = _moduleGuard; + bytes32 guardHash = bytes32(0); + require(msg.sender != address(1) && modules[msg.sender] != address(0)); + if (guard != address(0)) { + var guardHashCall = guard.checkModuleTransaction(«to», value, data, operation, msg.sender); + guardHash = guardHashCall; + } + return (guard, guardHash); + } + + function postModuleExecution(address guard, bytes32 guardHash, bool success) internal { + if (guard != address(0)) { + require(guard.code.length > 0); + var _after = guard.checkAfterModuleExecution(guardHash, success); + } + } + + function validateContractSignature(address owner, bytes32 dataHash, bytes signature) + internal returns (bool) { + (bool sigSuccess, bytes memory sigResult) = + owner.staticcall(abi.encodeWithSelector(isValidSignature, dataHash, signature)); + return sigSuccess && sigResult.length == 32 && + abi.decode(sigResult, (bytes32)) == + bytes32(0x1626ba7e00000000000000000000000000000000000000000000000000000000); + } + + function checkContractSignature(address owner, bytes32 dataHash, bytes signatures, + uint256 offset) internal { + var signatureDataStart = _add(offset, 32); + require(signatureDataStart <= signatures.length); + uint256 contractSignatureLen = abi.decode(signatures[offset : offset + 32], (uint256)); + var signatureDataEnd = _add(signatureDataStart, contractSignatureLen); + require(signatureDataEnd <= signatures.length); + bytes memory contractSignature = signatures[signatureDataStart : signatureDataEnd]; + var valid = validateContractSignature(owner, dataHash, contractSignature); + require(valid); + } + + function p256Verify(bytes32 h, bytes32 r, bytes32 s, uint256 qx, uint256 qy) + internal returns (bool) { + ${[Stmt.lowLevelCall p256Precompile (.intLit 0) + (.abiEncodePacked + [ (Benchmarks.Safe.bytes32, .var "h"), (Benchmarks.Safe.bytes32, .var "r"), + (Benchmarks.Safe.bytes32, .var "s"), + (Benchmarks.Safe.uint256, .var "qx"), (Benchmarks.Safe.uint256, .var "qy") ]) + "p256Success" "p256Result" false]} + return ${Expr.var "p256Success"} && ${localLength "p256Result"} == 32 && + abi.decode(${Expr.var "p256Result"}, (uint256)) == 1; + } + + function ecrecoverAddress(bytes32 digest, uint8 v, bytes32 r, bytes32 s) + internal returns (address) { + ${[Stmt.lowLevelCall ecrecoverPrecompile (.intLit 0) ecrecoverCalldataExpr + "ecrecoverSuccess" "ecrecoverData" false]} + require(${Expr.var "ecrecoverSuccess"}); + return ${localLength "ecrecoverData"} == 0 ? address(0) : + abi.decode(${Expr.var "ecrecoverData"}, (address)); + } + + function checkNSignaturesImpl(address executor, bytes32 dataHash, bytes signatures, + uint256 requiredSignatures) internal { + var requiredBytes = _mul(requiredSignatures, 65); + require(signatures.length >= requiredBytes); + address lastOwner = address(0); + address currentOwner = address(0); + uint256 i = 0; + while (i < requiredSignatures) { + uint256 signatureOffset = 65 * i; + bytes32 r = abi.decode(signatures[signatureOffset : signatureOffset + 32], (bytes32)); + bytes32 s = + abi.decode(signatures[signatureOffset + 32 : signatureOffset + 32 + 32], (bytes32)); + uint8 v = uint8(signatures[signatureOffset + 64]); + if (v == 0) { + currentOwner = address(uint256(r)); + uint256 contractOffset = uint256(s); + require(contractOffset >= requiredBytes); + var _contractSigOk = + checkContractSignature(currentOwner, dataHash, signatures, contractOffset); + } else if (v == 1) { + currentOwner = address(uint256(r)); + require(executor == currentOwner || approvedHashes[currentOwner][dataHash] != 0); + } else if (v == 2) { + currentOwner = address(uint256(r)); + uint256 p256Offset = uint256(s); + require(p256Offset >= requiredBytes); + var p256End = _add(p256Offset, 128); + require(p256End <= signatures.length); + bytes32 p256r = abi.decode(signatures[p256Offset : p256Offset + 32], (bytes32)); + bytes32 p256s = + abi.decode(signatures[p256Offset + 32 : p256Offset + 32 + 32], (bytes32)); + uint256 qx = abi.decode(signatures[p256Offset + 64 : p256Offset + 64 + 32], (uint256)); + uint256 qy = abi.decode(signatures[p256Offset + 96 : p256Offset + 96 + 32], (uint256)); + address signerAddress = + address(uint256(keccak256(abi.encodePacked(uint256(qx), uint256(qy))))); + var p256Ok = p256Verify(dataHash, p256r, p256s, qx, qy); + require(currentOwner == signerAddress && p256Ok); + } else if (v > 30) { + bytes32 ethSignedHash = + keccak256(abi.encodePacked(bytes(${ethSignPrefix}), bytes32(dataHash))); + var recoveredOwner = ecrecoverAddress(ethSignedHash, (v - 4) as uint8, r, s); + currentOwner = recoveredOwner; + } else { + var recoveredOwner = ecrecoverAddress(dataHash, v, r, s); + currentOwner = recoveredOwner; + } + require(currentOwner > lastOwner && owners[currentOwner] != address(0) && + currentOwner != address(1)); + lastOwner = currentOwner; + i = ((i + 1) as uint256); + } + } + + function checkSignaturesImpl(address executor, bytes32 dataHash, bytes signatures) internal { + uint256 _threshold = threshold; + require(_threshold != 0); + var _checked = checkNSignaturesImpl(executor, dataHash, signatures, _threshold); + } + + function VERSION() external returns (string) { + return "1.5.0"; + } + + function addOwnerWithThreshold(address owner, uint256 _threshold) external { + require(msg.sender == address(this)); + var _ok = requireCanAddOwner(owner); + owners[owner] = owners[address(1)]; + owners[address(1)] = owner; + ownerCount = ((ownerCount + 1) as uint256); + if (threshold != _threshold) { + var _thresholdChanged = changeThresholdBody(_threshold); + } + } + + function approveHash(bytes32 hashToApprove) external { + require(owners[msg.sender] != address(0)); + approvedHashes[msg.sender][hashToApprove] = 1; + } + + function approvedHashes(address arg0, bytes32 arg1) external returns (uint256) { + return approvedHashes[arg0][arg1]; + } + + function changeThreshold(uint256 _threshold) external { + require(msg.sender == address(this)); + var _ok = changeThresholdBody(_threshold); + } + + function checkNSignatures(bytes32 dataHash, bytes data, bytes signatures, + uint256 requiredSignatures) external { + var _checked = checkNSignaturesImpl(msg.sender, dataHash, signatures, requiredSignatures); + } + + function checkNSignatures(address executor, bytes32 dataHash, bytes signatures, + uint256 requiredSignatures) external { + var _checked = checkNSignaturesImpl(executor, dataHash, signatures, requiredSignatures); + } + + function checkSignatures(bytes32 dataHash, bytes data, bytes signatures) external { + var _checked = checkSignaturesImpl(msg.sender, dataHash, signatures); + } + + function checkSignatures(address executor, bytes32 dataHash, bytes signatures) external { + var _checked = checkSignaturesImpl(executor, dataHash, signatures); + } + + function disableModule(address prevModule, address «module») external { + require(msg.sender == address(this)); + require(«module» != address(0) && «module» != address(1)); + require(modules[prevModule] == «module»); + modules[prevModule] = modules[«module»]; + modules[«module»] = address(0); + } + + function domainSeparator() external returns (bytes32) { + return keccak256(abi.encodePacked( + bytes32(bytes32(0x47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218)), + uint256(block.chainid), + uint256(uint256(this)))); + } + + function enableModule(address «module») external { + require(msg.sender == address(this)); + require(«module» != address(0) && «module» != address(1)); + require(modules[«module»] == address(0)); + modules[«module»] = modules[address(1)]; + modules[address(1)] = «module»; + } + + function execTransaction(address «to», uint256 value, bytes data, uint8 operation, + uint256 safeTxGas, uint256 baseGas, uint256 gasPrice, address gasToken, + address refundReceiver, bytes signatures) external payable returns (bool) { + require(operation <= 1); + uint256 nonceBefore = nonce; + bytes32 txHash = keccak256(abi.encodePacked( + bytes2(bytes2(0x1901)), + bytes32(keccak256(abi.encodePacked( + bytes32(bytes32(0x47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218)), + uint256(block.chainid), + uint256(uint256(this))))), + bytes32(keccak256(abi.encodePacked( + bytes32(bytes32(0xbb8310d486368db6bd6f849402fdd73ad53d316b5a4b2644ad6efe0f941286d8)), + uint256(uint256(«to»)), + uint256(value), + bytes32(keccak256(data)), + uint256(operation), + uint256(safeTxGas), + uint256(baseGas), + uint256(gasPrice), + uint256(uint256(gasToken)), + uint256(uint256(refundReceiver)), + uint256(nonceBefore)))))); + nonce = ((nonceBefore + 1) as uint256); + var _sigOk = checkSignaturesImpl(msg.sender, txHash, signatures); + address guard = _guard; + if (guard != address(0)) { + require(guard.code.length > 0); + var _guardChecked = guard.checkTransaction(«to», value, data, operation, safeTxGas, + baseGas, gasPrice, gasToken, refundReceiver, signatures, msg.sender); + } + uint256 gasForCheck = gasleft(); + require(gasForCheck >= + ((((safeTxGas << 6) / 63 > ((safeTxGas + 2500) as uint256) ? + (safeTxGas << 6) / 63 : ((safeTxGas + 2500) as uint256)) + 500) as uint256)); + uint256 gasBefore = gasleft(); + uint256 txGasLeft = gasleft(); + var success = execute(«to», value, data, operation, + gasPrice == 0 ? ((txGasLeft - 2500) as uint256) : safeTxGas); + uint256 gasAfter = gasleft(); + var gasUsed = _sub(gasBefore, gasAfter); + require(success || safeTxGas != 0 || gasPrice != 0); + uint256 payment = 0; + if (gasPrice > 0) { + var paymentCall = handlePayment(gasUsed, baseGas, gasPrice, gasToken, refundReceiver); + payment = paymentCall; + } + if (guard != address(0)) { + require(guard.code.length > 0); + var _guardAfter = guard.checkAfterExecution(txHash, success); + } + return success; + } + + function execTransactionFromModule(address «to», uint256 value, bytes data, uint8 operation) + external returns (bool) { + require(operation <= 1); + var pre = preModuleExecution(«to», value, data, operation); + var success = execute(«to», value, data, operation, type(uint256).max); + var _post = postModuleExecution(pre.0, pre.1, success); + return success; + } + + function execTransactionFromModuleReturnData(address «to», uint256 value, bytes data, + uint8 operation) external returns (bool, bytes) { + require(operation <= 1); + var pre = preModuleExecution(«to», value, data, operation); + if (operation == 1) { + (bool success, bytes memory returnData) = «to».delegatecall(data); + } else { + (bool success, bytes memory returnData) = «to».call{value: value}(data); + } + var _post = postModuleExecution(pre.0, pre.1, success); + return (success, returnData); + } + + function getModulesPaginated(address start, uint256 pageSize) + external returns (address[], address) { + require(start == address(1) || (modules[start] != address(0) && start != address(1))); + require(pageSize != 0); + uint256 moduleCount = 0; + address next = modules[start]; + address last = address(0); + while ((next != address(0) && next != address(1)) && moduleCount < pageSize) { + last = next; + next = modules[next]; + moduleCount = ((moduleCount + 1) as uint256); + } + if (next != address(1)) { + require(moduleCount > 0); + next = last; + } + address[] memory array = new address[](moduleCount); + uint256 fill = 0; + address current = modules[start]; + while (fill < moduleCount) { + array[fill] = current; + current = modules[current]; + fill = ((fill + 1) as uint256); + } + return (array, next); + } + + function getOwners() external returns (address[]) { + address[] memory array = new address[](ownerCount); + uint256 index = 0; + address currentOwner = owners[address(1)]; + while (currentOwner != address(1)) { + array[index] = currentOwner; + currentOwner = owners[currentOwner]; + index = ((index + 1) as uint256); + } + return array; + } + + function getStorageAt(uint256 offset, uint256 length) external returns (bytes) { + bytes memory result = ""; + uint256 index = 0; + while (index < length) { + result = abi.encodePacked(bytes(result), uint256(_rawStorage[offset + index])); + index = ((index + 1) as uint256); + } + return result; + } + + function getThreshold() external returns (uint256) { + return threshold; + } + + function getTransactionHash(address «to», uint256 value, bytes data, uint8 operation, + uint256 safeTxGas, uint256 baseGas, uint256 gasPrice, address gasToken, + address refundReceiver, uint256 _nonce) external returns (bytes32) { + require(operation <= 1); + return keccak256(abi.encodePacked( + bytes2(bytes2(0x1901)), + bytes32(keccak256(abi.encodePacked( + bytes32(bytes32(0x47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218)), + uint256(block.chainid), + uint256(uint256(this))))), + bytes32(keccak256(abi.encodePacked( + bytes32(bytes32(0xbb8310d486368db6bd6f849402fdd73ad53d316b5a4b2644ad6efe0f941286d8)), + uint256(uint256(«to»)), + uint256(value), + bytes32(keccak256(data)), + uint256(operation), + uint256(safeTxGas), + uint256(baseGas), + uint256(gasPrice), + uint256(uint256(gasToken)), + uint256(uint256(refundReceiver)), + uint256(_nonce)))))); + } + + function isModuleEnabled(address «module») external returns (bool) { + return modules[«module»] != address(0) && «module» != address(1); + } + + function isOwner(address owner) external returns (bool) { + return owners[owner] != address(0) && owner != address(1); + } + + function nonce() external returns (uint256) { + return nonce; + } + + function removeOwner(address prevOwner, address owner, uint256 _threshold) external { + require(msg.sender == address(this)); + ownerCount = ((ownerCount - 1) as uint256); + require(ownerCount >= _threshold); + var _ok = requireCanRemoveOwner(prevOwner, owner); + owners[prevOwner] = owners[owner]; + owners[owner] = address(0); + if (threshold != _threshold) { + var _thresholdChanged = changeThresholdBody(_threshold); + } + } + + function setFallbackHandler(address handler) external { + require(msg.sender == address(this)); + var _ok = internalSetFallbackHandler(handler); + } + + function setGuard(address guard) external { + require(msg.sender == address(this)); + if (guard != address(0)) { + var supported = guard.supportsInterface{view}(bytes4(0xe6d7a83a)); + require(supported); + } + _guard = guard; + } + + function setModuleGuard(address moduleGuard) external { + require(msg.sender == address(this)); + if (moduleGuard != address(0)) { + var supported = moduleGuard.supportsInterface{view}(bytes4(0x58401ed8)); + require(supported); + } + _moduleGuard = moduleGuard; + } + + function setup(address[] _owners, uint256 _threshold, address «to», bytes data, + address fallbackHandler, address paymentToken, uint256 payment, + address paymentReceiver) external { + var _ownersSetup = setupOwners(_owners, _threshold); + if (fallbackHandler != address(0)) { + var _fallbackSet = internalSetFallbackHandler(fallbackHandler); + } + var _modulesSetup = setupModules(«to», data); + if (payment > 0) { + var _paymentDone = handlePayment(payment, 0, 1, paymentToken, paymentReceiver); + } + } + + function signedMessages(bytes32 arg0) external returns (uint256) { + return signedMessages[arg0]; + } + + function simulateAndRevert(address targetContract, bytes calldataPayload) external { + (bool simulateSuccess, bytes memory simulateReturn) = + targetContract.delegatecall(calldataPayload); + require(false); + } + + function swapOwner(address prevOwner, address oldOwner, address newOwner) external { + require(msg.sender == address(this)); + var _canAdd = requireCanAddOwner(newOwner); + var _canRemove = requireCanRemoveOwner(prevOwner, oldOwner); + owners[newOwner] = owners[oldOwner]; + owners[prevOwner] = newOwner; + owners[oldOwner] = address(0); + } + } + +theorem contractSyntax_eq : contractSyntax = Benchmarks.Safe.contract := by rfl end Benchmarks.Safe.Syntax diff --git a/Benchmarks/UniswapV2Router02/SpecSyntax.lean b/Benchmarks/UniswapV2Router02/SpecSyntax.lean index c43d60a1..a375c37c 100644 --- a/Benchmarks/UniswapV2Router02/SpecSyntax.lean +++ b/Benchmarks/UniswapV2Router02/SpecSyntax.lean @@ -2,43 +2,534 @@ import Benchmarks.UniswapV2Router02.Spec import Solm.Notation /-! -# UniswapV2Router02 spec through the Solm syntax-facing module +# UniswapV2Router02 spec in the Solidity-faithful Solm frontend -This benchmark is large enough that the current notation frontend does not cover the full surface. -The file still mirrors the established benchmark convention by exposing a syntax-side contract value -and checking it is definitionally equal to the AST spec. +The whole Router02 benchmark spec, written with `solidity%` and proven definitionally equal to +the AST spec in `Spec.lean`. The contract is parameterized by its two immutables +(`factory`, `WETH`); immutable reads are `${factory v}` / `${WETH v}` escapes, and external +calls whose receiver is an immutable (or a `path[…]` element) are `${[Stmt.externalCall …]}` +splices, with splice-bound binders read back via `${Expr.var …}`. `abi.encodePacked` +fixed-bytes pairs use the `T(T(e))` double annotation; the create2 init-code hash is the spec's +own `initCodeHashLit`. Transition order matches `contract.transitions` (selector order). -/ -open Solm Solm.Notation Benchmarks.UniswapV2Router02.Immutables +open Solm Solm.Notation +open Benchmarks.UniswapV2Router02.Immutables namespace Benchmarks.UniswapV2Router02.Syntax -def storageDeclsSyntax : List StorageDecl := Benchmarks.UniswapV2Router02.storageDecls +def contractSyntax (v : RouterImmutables) : ContractDecl := solidity% contract UniswapV2Router02 { + constructor(address _factory, address _WETH) { + address imm_factory = _factory; + address imm_WETH = _WETH; + } -def constructorDeclSyntax : ConstructorDecl := Benchmarks.UniswapV2Router02.constructorDecl + receive() external payable { + require(msg.sender == ${WETH v}); + return; + } -def functionsSyntax : List FunctionDecl := Benchmarks.UniswapV2Router02.functions + function safeAdd(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x + y) as uint256; + require(z >= x); + return z; + } -def transitionsSyntax (v : RouterImmutables) : List TransitionDecl := - Benchmarks.UniswapV2Router02.transitions v + function safeSub(uint256 x, uint256 y) internal returns (uint256) { + uint256 z = (x - y) as uint256; + require(z <= x); + return z; + } -def receiveTransitionSyntax (v : RouterImmutables) : TransitionDecl := - Benchmarks.UniswapV2Router02.receiveTransition v + function safeMul(uint256 x, uint256 y) internal returns (uint256) { + if (y == 0) { + uint256 z = 0; + } else { + uint256 z = (x * y) as uint256; + require(z / y == x); + } + return z; + } -def contractSyntax (v : RouterImmutables) : ContractDecl := - { name := "UniswapV2Router02" - storage := storageDeclsSyntax - ctor := constructorDeclSyntax - functions := functionsSyntax - transitions := transitionsSyntax v - receive := some (receiveTransitionSyntax v) } + function sortTokens(address tokenA, address tokenB) internal returns (address, address) { + require(tokenA != tokenB); + address token0 = tokenA < tokenB ? tokenA : tokenB; + address token1 = tokenA < tokenB ? tokenB : tokenA; + require(token0 != address(0)); + return (token0, token1); + } -theorem storageDeclsSyntax_eq : - storageDeclsSyntax = Benchmarks.UniswapV2Router02.storageDecls := by - rfl + function pairFor(address factory_, address tokenA, address tokenB) internal returns (address) { + var tokens = sortTokens(tokenA, tokenB); + bytes32 salt = keccak256(abi.encodePacked(address(tokens.0), address(tokens.1))); + bytes32 raw = keccak256(abi.encodePacked( + bytes1(bytes1(0xff)), + address(factory_), + bytes32(salt), + bytes32(${initCodeHashLit}))); + return address(uint256(raw)); + } + + function quoteBody(uint256 amountA, uint256 reserveA, uint256 reserveB) internal returns (uint256) { + require(amountA > 0); + require(reserveA > 0 && reserveB > 0); + var num = safeMul(amountA, reserveB); + return num / reserveA; + } + + function getAmountOutBody(uint256 amountIn, uint256 reserveIn, uint256 reserveOut) internal returns (uint256) { + require(amountIn > 0); + require(reserveIn > 0 && reserveOut > 0); + var amountInWithFee = safeMul(amountIn, 997); + var numerator = safeMul(amountInWithFee, reserveOut); + var reserveTimes = safeMul(reserveIn, 1000); + var denominator = safeAdd(reserveTimes, amountInWithFee); + return numerator / denominator; + } + + function getAmountInBody(uint256 amountOut, uint256 reserveIn, uint256 reserveOut) internal returns (uint256) { + require(amountOut > 0); + require(reserveIn > 0 && reserveOut > 0); + var a = safeMul(reserveIn, amountOut); + var numerator = safeMul(a, 1000); + var reserveMinus = safeSub(reserveOut, amountOut); + var denominator = safeMul(reserveMinus, 997); + var amountIn = safeAdd(numerator / denominator, 1); + return amountIn; + } + + function getReservesBody(address factory_, address tokenA, address tokenB) internal returns (uint256, uint256) { + var tokens = sortTokens(tokenA, tokenB); + var pair = pairFor(factory_, tokenA, tokenB); + var reserves = pair.getReserves{view}(); + uint256 reserve0 = reserves.0; + uint256 reserve1 = reserves.1; + if (tokenA == tokens.0) { + return (reserve0, reserve1); + } else { + return (reserve1, reserve0); + } + } + + function getAmountsOutBody(address factory_, uint256 amountIn, address[] path) internal returns (uint256[]) { + require(path.length >= 2); + uint256[] amounts = new uint256[](path.length); + amounts[0] = amountIn; + for (uint256 i = 0; i < path.length - 1; i = i + 1) { + var reserves = getReservesBody(factory_, path[i], path[i + 1]); + var amountOut = getAmountOutBody(amounts[i], reserves.0, reserves.1); + amounts[i + 1] = amountOut; + } + return amounts; + } + + function getAmountsInBody(address factory_, uint256 amountOut, address[] path) internal returns (uint256[]) { + require(path.length >= 2); + uint256[] amounts = new uint256[](path.length); + amounts[path.length - 1] = amountOut; + for (uint256 i = path.length - 1; i > 0; i = i - 1) { + var reserves = getReservesBody(factory_, path[i - 1], path[i]); + var amountIn = getAmountInBody(amounts[i], reserves.0, reserves.1); + amounts[i - 1] = amountIn; + } + return amounts; + } + + function safeTransfer(address token, address «to», uint256 value) internal { + bytes data = abi.encodeWithSelector(transfer, «to», value); + (bool success, bytes memory returndata) = token.call(data); + require(success); + if (returndata.length != 0) { + bool returndata_ok = abi.decode(returndata, (bool)); + require(returndata_ok); + } + return; + } + + function safeTransferFrom(address token, address «from», address «to», uint256 value) internal { + bytes data = abi.encodeWithSelector(transferFrom, «from», «to», value); + (bool success, bytes memory returndata) = token.call(data); + require(success); + if (returndata.length != 0) { + bool returndata_ok = abi.decode(returndata, (bool)); + require(returndata_ok); + } + return; + } + + function safeTransferETH(address «to», uint256 value) internal { + (bool success, bytes memory _data) = «to».call{value: value}(new bytes(0)); + require(success); + return; + } + + function addLiquidityBody(address factory_, address tokenA, address tokenB, + uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, + uint256 amountBMin) internal returns (uint256, uint256) { + var pair0 = factory_.getPair{view}(tokenA, tokenB); + if (pair0 == address(0)) { + var _created = factory_.createPair(tokenA, tokenB); + } + var reserves = getReservesBody(factory_, tokenA, tokenB); + if (reserves.0 == 0 && reserves.1 == 0) { + return (amountADesired, amountBDesired); + } else { + var amountBOptimal = quoteBody(amountADesired, reserves.0, reserves.1); + if (amountBOptimal <= amountBDesired) { + require(amountBOptimal >= amountBMin); + return (amountADesired, amountBOptimal); + } else { + var amountAOptimal = quoteBody(amountBDesired, reserves.1, reserves.0); + require(amountAOptimal <= amountADesired); + require(amountAOptimal >= amountAMin); + return (amountAOptimal, amountBDesired); + } + } + } + + function removeLiquidityBody(address factory_, address tokenA, address tokenB, + uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address «to», + uint256 deadline) internal returns (uint256, uint256) { + require(deadline >= block.timestamp); + var pair = pairFor(factory_, tokenA, tokenB); + var _transferOk = pair.transferFrom(msg.sender, pair, liquidity); + var burned = pair.burn(«to»); + var tokens = sortTokens(tokenA, tokenB); + uint256 amountA = tokenA == tokens.0 ? burned.0 : burned.1; + uint256 amountB = tokenA == tokens.0 ? burned.1 : burned.0; + require(amountA >= amountAMin); + require(amountB >= amountBMin); + return (amountA, amountB); + } + + function removeLiquidityETHBody(address factory_, address weth_, address token, + uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address «to», + uint256 deadline) internal returns (uint256, uint256) { + require(deadline >= block.timestamp); + var amounts = removeLiquidityBody(factory_, token, weth_, liquidity, + amountTokenMin, amountETHMin, address(this), deadline); + var _t = safeTransfer(token, «to», amounts.0); + var _w = weth_.withdraw(amounts.1); + var _eth = safeTransferETH(«to», amounts.1); + return (amounts.0, amounts.1); + } + + function removeLiquidityETHSupportingFeeBody(address factory_, address weth_, address token, + uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address «to», + uint256 deadline) internal returns (uint256) { + require(deadline >= block.timestamp); + var amounts = removeLiquidityBody(factory_, token, weth_, liquidity, + amountTokenMin, amountETHMin, address(this), deadline); + var tokenBalance = token.balanceOf{view}(address(this)); + var _t = safeTransfer(token, «to», tokenBalance); + var _w = weth_.withdraw(amounts.1); + var _eth = safeTransferETH(«to», amounts.1); + return amounts.1; + } + + function swapBody(address factory_, uint256[] amounts, address[] path, address _to) internal { + for (uint256 i = 0; i < path.length - 1; i = i + 1) { + address input = path[i]; + address output = path[i + 1]; + var tokens = sortTokens(input, output); + uint256 amountOut = amounts[i + 1]; + uint256 amount0Out = input == tokens.0 ? 0 : amountOut; + uint256 amount1Out = input == tokens.0 ? amountOut : 0; + address nextTo = _to; + if (i < path.length - 2) { + var nextPair = pairFor(factory_, output, path[i + 2]); + nextTo = nextPair; + } + var pair = pairFor(factory_, input, output); + var _swap = pair.swap(amount0Out, amount1Out, nextTo, new bytes(0)); + } + return; + } + + function swapSupportingFeeBody(address factory_, address[] path, address _to) internal { + for (uint256 i = 0; i < path.length - 1; i = i + 1) { + address input = path[i]; + address output = path[i + 1]; + var tokens = sortTokens(input, output); + var pair = pairFor(factory_, input, output); + var reserves = pair.getReserves{view}(); + uint256 reserveInput = input == tokens.0 ? reserves.0 : reserves.1; + uint256 reserveOutput = input == tokens.0 ? reserves.1 : reserves.0; + var balanceIn = input.balanceOf{view}(pair); + var amountInput = safeSub(balanceIn, reserveInput); + var amountOutput = getAmountOutBody(amountInput, reserveInput, reserveOutput); + uint256 amount0Out = input == tokens.0 ? 0 : amountOutput; + uint256 amount1Out = input == tokens.0 ? amountOutput : 0; + address nextTo = _to; + if (i < path.length - 2) { + var nextPair = pairFor(factory_, output, path[i + 2]); + nextTo = nextPair; + } + var _swap = pair.swap(amount0Out, amount1Out, nextTo, new bytes(0)); + } + return; + } + + function factory() external returns (address) { + return ${factory v}; + } + + function WETH() external returns (address) { + return ${WETH v}; + } + + function addLiquidity(address tokenA, address tokenB, uint256 amountADesired, + uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address «to», + uint256 deadline) external returns (uint256, uint256, uint256) { + require(deadline >= block.timestamp); + var amounts = addLiquidityBody(${factory v}, tokenA, tokenB, amountADesired, + amountBDesired, amountAMin, amountBMin); + var pair = pairFor(${factory v}, tokenA, tokenB); + var _a = safeTransferFrom(tokenA, msg.sender, pair, amounts.0); + var _b = safeTransferFrom(tokenB, msg.sender, pair, amounts.1); + var liquidity = pair.mint(«to»); + return (amounts.0, amounts.1, liquidity); + } + + function addLiquidityETH(address token, uint256 amountTokenDesired, uint256 amountTokenMin, + uint256 amountETHMin, address «to», uint256 deadline) external payable + returns (uint256, uint256, uint256) { + require(deadline >= block.timestamp); + var amounts = addLiquidityBody(${factory v}, token, ${WETH v}, amountTokenDesired, + msg.value, amountTokenMin, amountETHMin); + var pair = pairFor(${factory v}, token, ${WETH v}); + var _t = safeTransferFrom(token, msg.sender, pair, amounts.0); + ${[Stmt.externalCall (WETH v) "deposit" (tuple1 (.var "amounts")) [] "_d", + Stmt.externalCall (WETH v) "transfer" (.intLit 0) + [.var "pair", tuple1 (.var "amounts")] "wethTransferOk", + Stmt.require (.var "wethTransferOk")]} + var liquidity = pair.mint(«to»); + if (msg.value > amounts.1) { + var _refund = safeTransferETH(msg.sender, (msg.value - amounts.1) as uint256); + } + return (amounts.0, amounts.1, liquidity); + } + + function removeLiquidity(address tokenA, address tokenB, uint256 liquidity, + uint256 amountAMin, uint256 amountBMin, address «to», uint256 deadline) + external returns (uint256, uint256) { + var amounts = removeLiquidityBody(${factory v}, tokenA, tokenB, liquidity, + amountAMin, amountBMin, «to», deadline); + return (amounts.0, amounts.1); + } + + function removeLiquidityETH(address token, uint256 liquidity, uint256 amountTokenMin, + uint256 amountETHMin, address «to», uint256 deadline) external returns (uint256, uint256) { + var amounts = removeLiquidityETHBody(${factory v}, ${WETH v}, token, liquidity, + amountTokenMin, amountETHMin, «to», deadline); + return (amounts.0, amounts.1); + } + + function removeLiquidityWithPermit(address tokenA, address tokenB, uint256 liquidity, + uint256 amountAMin, uint256 amountBMin, address «to», uint256 deadline, bool approveMax, + uint8 v, bytes32 r, bytes32 s) external returns (uint256, uint256) { + var pair = pairFor(${factory v}, tokenA, tokenB); + var _permit = pair.permit(msg.sender, address(this), + approveMax ? type(uint256).max : liquidity, deadline, v, r, s); + var amounts = removeLiquidityBody(${factory v}, tokenA, tokenB, liquidity, + amountAMin, amountBMin, «to», deadline); + return (amounts.0, amounts.1); + } + + function removeLiquidityETHWithPermit(address token, uint256 liquidity, + uint256 amountTokenMin, uint256 amountETHMin, address «to», uint256 deadline, + bool approveMax, uint8 v, bytes32 r, bytes32 s) external returns (uint256, uint256) { + var pair = pairFor(${factory v}, token, ${WETH v}); + var _permit = pair.permit(msg.sender, address(this), + approveMax ? type(uint256).max : liquidity, deadline, v, r, s); + var amounts = removeLiquidityETHBody(${factory v}, ${WETH v}, token, liquidity, + amountTokenMin, amountETHMin, «to», deadline); + return (amounts.0, amounts.1); + } + + function removeLiquidityETHSupportingFeeOnTransferTokens(address token, uint256 liquidity, + uint256 amountTokenMin, uint256 amountETHMin, address «to», uint256 deadline) + external returns (uint256) { + var amountETH = removeLiquidityETHSupportingFeeBody(${factory v}, ${WETH v}, token, + liquidity, amountTokenMin, amountETHMin, «to», deadline); + return amountETH; + } + + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(address token, + uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address «to», + uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s) + external returns (uint256) { + var pair = pairFor(${factory v}, token, ${WETH v}); + var _permit = pair.permit(msg.sender, address(this), + approveMax ? type(uint256).max : liquidity, deadline, v, r, s); + var amountETH = removeLiquidityETHSupportingFeeBody(${factory v}, ${WETH v}, token, + liquidity, amountTokenMin, amountETHMin, «to», deadline); + return amountETH; + } + + function swapExactTokensForTokens(uint256 amountIn, uint256 amountOutMin, address[] path, + address «to», uint256 deadline) external returns (uint256[]) { + require(deadline >= block.timestamp); + var amounts = getAmountsOutBody(${factory v}, amountIn, path); + require(amounts[amounts.length - 1] >= amountOutMin); + var firstPair = pairFor(${factory v}, path[0], path[1]); + var _t = safeTransferFrom(path[0], msg.sender, firstPair, amounts[0]); + var _swap = swapBody(${factory v}, amounts, path, «to»); + return amounts; + } + + function swapTokensForExactTokens(uint256 amountOut, uint256 amountInMax, address[] path, + address «to», uint256 deadline) external returns (uint256[]) { + require(deadline >= block.timestamp); + var amounts = getAmountsInBody(${factory v}, amountOut, path); + require(amounts[0] <= amountInMax); + var firstPair = pairFor(${factory v}, path[0], path[1]); + var _t = safeTransferFrom(path[0], msg.sender, firstPair, amounts[0]); + var _swap = swapBody(${factory v}, amounts, path, «to»); + return amounts; + } + + function swapExactETHForTokens(uint256 amountOutMin, address[] path, address «to», + uint256 deadline) external payable returns (uint256[]) { + require(deadline >= block.timestamp); + require(path[0] == ${WETH v}); + var amounts = getAmountsOutBody(${factory v}, msg.value, path); + require(amounts[amounts.length - 1] >= amountOutMin); + ${[Stmt.externalCall (WETH v) "deposit" (arrGet "amounts" (.intLit 0)) [] "_d"]} + var firstPair = pairFor(${factory v}, path[0], path[1]); + ${[Stmt.externalCall (WETH v) "transfer" (.intLit 0) + [.var "firstPair", arrGet "amounts" (.intLit 0)] "wethTransferOk", + Stmt.require (.var "wethTransferOk")]} + var _swap = swapBody(${factory v}, amounts, path, «to»); + return amounts; + } + + function swapTokensForExactETH(uint256 amountOut, uint256 amountInMax, address[] path, + address «to», uint256 deadline) external returns (uint256[]) { + require(deadline >= block.timestamp); + require(path[path.length - 1] == ${WETH v}); + var amounts = getAmountsInBody(${factory v}, amountOut, path); + require(amounts[0] <= amountInMax); + var firstPair = pairFor(${factory v}, path[0], path[1]); + var _t = safeTransferFrom(path[0], msg.sender, firstPair, amounts[0]); + var _swap = swapBody(${factory v}, amounts, path, address(this)); + ${[Stmt.externalCall (WETH v) "withdraw" (.intLit 0) + [arrGet "amounts" (lastIndex "amounts")] "_w"]} + var _eth = safeTransferETH(«to», amounts[amounts.length - 1]); + return amounts; + } + + function swapExactTokensForETH(uint256 amountIn, uint256 amountOutMin, address[] path, + address «to», uint256 deadline) external returns (uint256[]) { + require(deadline >= block.timestamp); + require(path[path.length - 1] == ${WETH v}); + var amounts = getAmountsOutBody(${factory v}, amountIn, path); + require(amounts[amounts.length - 1] >= amountOutMin); + var firstPair = pairFor(${factory v}, path[0], path[1]); + var _t = safeTransferFrom(path[0], msg.sender, firstPair, amounts[0]); + var _swap = swapBody(${factory v}, amounts, path, address(this)); + ${[Stmt.externalCall (WETH v) "withdraw" (.intLit 0) + [arrGet "amounts" (lastIndex "amounts")] "_w"]} + var _eth = safeTransferETH(«to», amounts[amounts.length - 1]); + return amounts; + } + + function swapETHForExactTokens(uint256 amountOut, address[] path, address «to», + uint256 deadline) external payable returns (uint256[]) { + require(deadline >= block.timestamp); + require(path[0] == ${WETH v}); + var amounts = getAmountsInBody(${factory v}, amountOut, path); + require(amounts[0] <= msg.value); + ${[Stmt.externalCall (WETH v) "deposit" (arrGet "amounts" (.intLit 0)) [] "_d"]} + var firstPair = pairFor(${factory v}, path[0], path[1]); + ${[Stmt.externalCall (WETH v) "transfer" (.intLit 0) + [.var "firstPair", arrGet "amounts" (.intLit 0)] "wethTransferOk", + Stmt.require (.var "wethTransferOk")]} + var _swap = swapBody(${factory v}, amounts, path, «to»); + if (msg.value > amounts[0]) { + var _refund = safeTransferETH(msg.sender, (msg.value - amounts[0]) as uint256); + } + return amounts; + } + + function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint256 amountIn, + uint256 amountOutMin, address[] path, address «to», uint256 deadline) external { + require(deadline >= block.timestamp); + var firstPair = pairFor(${factory v}, path[0], path[1]); + var _t = safeTransferFrom(path[0], msg.sender, firstPair, amountIn); + ${[Stmt.externalCall (arrGet "path" (lastIndex "path")) "balanceOf" (.intLit 0) + [.var "to"] "balanceBefore" false]} + var _swap = swapSupportingFeeBody(${factory v}, path, «to»); + ${[Stmt.externalCall (arrGet "path" (lastIndex "path")) "balanceOf" (.intLit 0) + [.var "to"] "balanceAfter" false]} + var delta = safeSub(${Expr.var "balanceAfter"}, ${Expr.var "balanceBefore"}); + require(delta >= amountOutMin); + return; + } + + function swapExactETHForTokensSupportingFeeOnTransferTokens(uint256 amountOutMin, + address[] path, address «to», uint256 deadline) external payable { + require(deadline >= block.timestamp); + require(path[0] == ${WETH v}); + uint256 amountIn = msg.value; + ${[Stmt.externalCall (WETH v) "deposit" (.var "amountIn") [] "_d"]} + var firstPair = pairFor(${factory v}, path[0], path[1]); + ${[Stmt.externalCall (WETH v) "transfer" (.intLit 0) + [.var "firstPair", .var "amountIn"] "wethTransferOk", + Stmt.require (.var "wethTransferOk"), + Stmt.externalCall (arrGet "path" (lastIndex "path")) "balanceOf" (.intLit 0) + [.var "to"] "balanceBefore" false]} + var _swap = swapSupportingFeeBody(${factory v}, path, «to»); + ${[Stmt.externalCall (arrGet "path" (lastIndex "path")) "balanceOf" (.intLit 0) + [.var "to"] "balanceAfter" false]} + var delta = safeSub(${Expr.var "balanceAfter"}, ${Expr.var "balanceBefore"}); + require(delta >= amountOutMin); + return; + } + + function swapExactTokensForETHSupportingFeeOnTransferTokens(uint256 amountIn, + uint256 amountOutMin, address[] path, address «to», uint256 deadline) external { + require(deadline >= block.timestamp); + require(path[path.length - 1] == ${WETH v}); + var firstPair = pairFor(${factory v}, path[0], path[1]); + var _t = safeTransferFrom(path[0], msg.sender, firstPair, amountIn); + var _swap = swapSupportingFeeBody(${factory v}, path, address(this)); + ${[Stmt.externalCall (WETH v) "balanceOf" (.intLit 0) [thisAddr] "amountOut" false]} + require(${Expr.var "amountOut"} >= amountOutMin); + ${[Stmt.externalCall (WETH v) "withdraw" (.intLit 0) [.var "amountOut"] "_w"]} + var _eth = safeTransferETH(«to», ${Expr.var "amountOut"}); + return; + } + + function quote(uint256 amountA, uint256 reserveA, uint256 reserveB) external returns (uint256) { + var amountB = quoteBody(amountA, reserveA, reserveB); + return amountB; + } + + function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut) + external returns (uint256) { + var amountOut = getAmountOutBody(amountIn, reserveIn, reserveOut); + return amountOut; + } + + function getAmountIn(uint256 amountOut, uint256 reserveIn, uint256 reserveOut) + external returns (uint256) { + var amountIn = getAmountInBody(amountOut, reserveIn, reserveOut); + return amountIn; + } + + function getAmountsOut(uint256 amountIn, address[] path) external returns (uint256[]) { + var amounts = getAmountsOutBody(${factory v}, amountIn, path); + return amounts; + } + + function getAmountsIn(uint256 amountOut, address[] path) external returns (uint256[]) { + var amounts = getAmountsInBody(${factory v}, amountOut, path); + return amounts; + } +} theorem contractSyntax_eq (v : RouterImmutables) : - contractSyntax v = Benchmarks.UniswapV2Router02.contract v := by - rfl + contractSyntax v = Benchmarks.UniswapV2Router02.contract v := by rfl end Benchmarks.UniswapV2Router02.Syntax diff --git a/Benchmarks/UniswapV3Pool/Common.lean b/Benchmarks/UniswapV3Pool/Common.lean index e58bc617..bd5f197d 100644 --- a/Benchmarks/UniswapV3Pool/Common.lean +++ b/Benchmarks/UniswapV3Pool/Common.lean @@ -1240,7 +1240,7 @@ theorem uniswapV3PoolFallbackRevertFrom {code : ByteArray} {ee : ExecutionEnv} (hr2 : decode code ⟨434⟩ = some (.REVERT, .none)) (hovPush : stk.length + 1 ≤ 1024) (hovRev : stk.length + 2 ≤ 1024) : RDrev code g s0 := by - exact RD.uniswapPush1Dup1Revert0 + exact RD.solcPush1Dup1Revert0 (h.pushConst ⟨430⟩ (width := 2) (op := .PUSH2) (by native_decide) hpush hovPush |>.jump hjump hjd (by omega) |>.jumpdest hjdDecode (by omega)) @@ -1457,7 +1457,7 @@ theorem uniswapV3PoolFallbackJumpdestFrom {v : PoolImmutables} {code : ByteArray (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) (h : RD code I g s0 ⟨430⟩ [solcSelectorWord I] mem aw rdata acc k C) : RDrev code g s0 := by - exact RD.uniswapPush1Dup1Revert0 + exact RD.solcPush1Dup1Revert0 (h.jumpdest (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) (by simp)) @@ -1891,7 +1891,7 @@ theorem uniswapV3PoolX_callvalue_ne {v : PoolImmutables} {code : ByteArray} (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - exact RD.uniswapPush1Dup1Revert0 + exact RD.solcPush1Dup1Revert0 (h0.pushConst (solcGuardTgt uniswapV3PoolBytecode) (width := solcGuardTgtWidth uniswapV3PoolBytecode) (op := solcGuardTgtOp uniswapV3PoolBytecode) @@ -1931,7 +1931,7 @@ theorem uniswapV3PoolX_short {v : PoolImmutables} {code : ByteArray} (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - exact RD.uniswapPush1Dup1Revert0 + exact RD.solcPush1Dup1Revert0 (h1.push1 ⟨4⟩ (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) (by simp only [List.length]; omega) diff --git a/Benchmarks/UniswapV3Pool/NoDelegateCall.lean b/Benchmarks/UniswapV3Pool/NoDelegateCall.lean index c7e20bf0..77fa89cb 100644 --- a/Benchmarks/UniswapV3Pool/NoDelegateCall.lean +++ b/Benchmarks/UniswapV3Pool/NoDelegateCall.lean @@ -381,7 +381,7 @@ theorem uniswapV3PoolNoDelegateCallReturnOk have rd11249 := by simpa using h.jumpdest hd11248 (by evm_ov) have rd11250 := by - simpa using rd11249.uniswapAddress hd11249 (by simp only [List.length_cons]; omega) + simpa using rd11249.address hd11249 (by simp only [List.length_cons]; omega) have rd11252 := by simpa using rd11250.push1 ⟨1⟩ hd11250 (by simp only [List.length_cons]; omega) have rd11254 := by @@ -488,7 +488,7 @@ theorem uniswapV3PoolNoDelegateCallOk have rd11249 := by simpa using rd11248.jumpdest hd11248 (by evm_ov) have rd11250 := by - simpa using rd11249.uniswapAddress hd11249 (by simp only [List.length_cons]; omega) + simpa using rd11249.address hd11249 (by simp only [List.length_cons]; omega) have rd11252 := by simpa using rd11250.push1 ⟨1⟩ hd11250 (by simp only [List.length_cons]; omega) have rd11254 := by @@ -598,7 +598,7 @@ theorem uniswapV3PoolNoDelegateCallReturnRevert have rd11249 := by simpa using rd11248.jumpdest hd11248 (by evm_ov) have rd11250 := by - simpa using rd11249.uniswapAddress hd11249 (by simp only [List.length_cons]; omega) + simpa using rd11249.address hd11249 (by simp only [List.length_cons]; omega) have rd11252 := by simpa using rd11250.push1 ⟨1⟩ hd11250 (by simp only [List.length_cons]; omega) have rd11254 := by @@ -624,7 +624,7 @@ theorem uniswapV3PoolNoDelegateCallReturnRevert have rd11296 := by simpa using rd11293.push2 ⟨11301⟩ hd11293 (by simp only [List.length_cons]; omega) have rd11297 := rd11296.jumpiNT hd11296 hguard (by simp only [List.length_cons]; omega) - exact RD.uniswapPush1Dup1Revert0 rd11297 hd11297 hd11299 hd11300 + exact RD.solcPush1Dup1Revert0 rd11297 hd11297 hd11299 hd11300 (by simp only [List.length_cons]; omega) theorem uniswapV3PoolNoDelegateCallRevert diff --git a/Benchmarks/UniswapV3Pool/Observations.lean b/Benchmarks/UniswapV3Pool/Observations.lean index 81b88b8b..4e454580 100644 --- a/Benchmarks/UniswapV3Pool/Observations.lean +++ b/Benchmarks/UniswapV3Pool/Observations.lean @@ -885,7 +885,7 @@ theorem uniswapV3PoolObservationsRoutineOob {v : PoolImmutables} {code : ByteArr have rd5347 := rd5346.jumpiNT hd5346 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd5347 hd5347 hd5349 hd5350 (by evm_ov) + exact RD.solcPush1Dup1Revert0 rd5347 hd5347 hd5349 hd5350 (by evm_ov) theorem uniswapV3PoolObservationsEvmOob {v : PoolImmutables} {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} diff --git a/Benchmarks/UniswapV3Pool/ObservationsInt56.lean b/Benchmarks/UniswapV3Pool/ObservationsInt56.lean index 541f85a4..5d9cb38a 100644 --- a/Benchmarks/UniswapV3Pool/ObservationsInt56.lean +++ b/Benchmarks/UniswapV3Pool/ObservationsInt56.lean @@ -99,7 +99,7 @@ private theorem nat_lor_high_mask_55 (n : Nat) (hn : n < 2 ^ 256) : rw [Nat.testBit_or, Nat.testBit_or] rw [show (2 ^ (256 - 55) - 1) * 2 ^ 55 = (2 ^ (256 - 55) - 1) <<< 55 by rw [Nat.shiftLeft_eq]] - rw [nat_testBit_shiftLeft] + rw [testBit_shiftLeft] by_cases hi55 : i < 55 · rw [if_pos hi55] conv_rhs => rw [Nat.testBit_mod_two_pow] diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocol.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocol.lean index 097e5e11..06212f91 100644 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocol.lean +++ b/Benchmarks/UniswapV3Pool/SetFeeProtocol.lean @@ -1414,16 +1414,16 @@ theorem uniswapV3PoolSetFeeProtocolBodyCore {v : PoolImmutables} hpatch hrdOwnerSetup (by simp only [List.length_cons, List.length_nil]; omega) by_cases hfactoryCode : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ (setFeeProtocolLockedSlotWord σ_evm I)) (setFeeProtocolFactoryWord v) ≠ ⟨0⟩ · have hfactoryCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (setFeeProtocolLockedSlotWord σ_solm I)) (setFeeProtocolFactoryWord v) ≠ ⟨0⟩ := by - rw [← uniswapExtCodeSizeWord_accountMapEquiv hAccountsAfterLock + rw [← extCodeSizeWord_accountMapEquiv hAccountsAfterLock (setFeeProtocolFactoryWord v)] exact hfactoryCode let evmLockSolm := @@ -1797,7 +1797,7 @@ theorem uniswapV3PoolSetFeeProtocolBodyCore {v : PoolImmutables} hownerRevert exact hrdOwnerDepth.reEquivExecutionRevert hcode hdispatch hdecode hbody · have hfactoryNoCodeEvm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ (setFeeProtocolLockedSlotWord σ_evm I)) (setFeeProtocolFactoryWord v) = ⟨0⟩ := by @@ -1815,11 +1815,11 @@ theorem uniswapV3PoolSetFeeProtocolBodyCore {v : PoolImmutables} hpatch hrdOwnerGuard hfactoryNoCodeEvm (by simp only [List.length_cons, List.length_nil]; omega) have hfactoryNoCodeSolm : - Reasoning.Theory.uniswapExtCodeSizeWord + Reasoning.Theory.extCodeSizeWord (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (setFeeProtocolLockedSlotWord σ_solm I)) (setFeeProtocolFactoryWord v) = ⟨0⟩ := by - rw [← uniswapExtCodeSizeWord_accountMapEquiv hAccountsAfterLock + rw [← extCodeSizeWord_accountMapEquiv hAccountsAfterLock (setFeeProtocolFactoryWord v)] exact hfactoryNoCodeEvm let evmLockSolm := diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocolFeeProtocolCheck.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocolFeeProtocolCheck.lean index 24d50595..954a886c 100644 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocolFeeProtocolCheck.lean +++ b/Benchmarks/UniswapV3Pool/SetFeeProtocolFeeProtocolCheck.lean @@ -388,7 +388,7 @@ theorem uniswapV3PoolSetFeeProtocolFeeProtocolFalseAt8526Reverts {v : PoolImmuta raw jumpdest hd8526 (by evm_ov), raw push2 ⟨8535⟩ hd8527 (by evm_ov)] have rd8531 := rd8530.jumpiNT hd8530 (by decide) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd8531 hd8531 + exact RD.solcPush1Dup1Revert0 rd8531 hd8531 (by simpa [show (⟨8531⟩ : UInt256) + UInt256.ofNat 2 = ⟨8533⟩ by native_decide] using hd8533) (by simpa [ diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocolOwnerCall.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocolOwnerCall.lean index 62c32bbe..61f96532 100644 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocolOwnerCall.lean +++ b/Benchmarks/UniswapV3Pool/SetFeeProtocolOwnerCall.lean @@ -721,7 +721,7 @@ theorem uniswapV3PoolSetFeeProtocolOwnerExtcodesizeMissingReverts {v : PoolImmut ⟨128⟩ :: ⟨32⟩ :: ⟨132⟩ :: ⟨2376452955⟩ :: setFeeProtocolFactoryWord v :: R) setFeeProtocolOwnerCallMem (UInt256.ofNat 5) rdata (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (setFeeProtocolFactoryWord v) = ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (setFeeProtocolFactoryWord v) = ⟨0⟩) (hov : R.length + 11 ≤ 1024) : RDrev code g s0 := by have hd8373 : decode code ⟨8373⟩ = some (.EXTCODESIZE, .none) := by @@ -778,7 +778,7 @@ theorem uniswapV3PoolSetFeeProtocolOwnerExtcodesizeMissingReverts {v : PoolImmut (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) (by native_decide) (by native_decide)) (by native_decide) (by native_decide) (by native_decide) - exact RD.uniswapExtcodesizeGuardMissing (pc := ⟨8373⟩) (okPc := ⟨8385⟩) h + exact RD.solcExtcodesizeGuardMissing (pc := ⟨8373⟩) (okPc := ⟨8385⟩) h hcodeSize hd8373 (by simpa using hd8374) (by simpa using hd8375) (by simpa using hd8376) (by simpa using hd8377) (by simpa using hd8380) (by simpa using hd8381) (by simpa using hd8383) (by simpa using hd8384) @@ -795,7 +795,7 @@ theorem uniswapV3PoolSetFeeProtocolOwnerStaticcallMade {v : PoolImmutables} ⟨128⟩ :: ⟨32⟩ :: ⟨132⟩ :: ⟨2376452955⟩ :: setFeeProtocolFactoryWord v :: R) setFeeProtocolOwnerCallMem (UInt256.ofNat 5) rdata (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (setFeeProtocolFactoryWord v) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (setFeeProtocolFactoryWord v) ≠ ⟨0⟩) (hdepth : ee.depth.val < 1024) (hov : R.length + 11 ≤ 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) @@ -875,14 +875,14 @@ theorem uniswapV3PoolSetFeeProtocolOwnerStaticcallMade {v : PoolImmutables} (by native_decide) (by native_decide)) (by native_decide) (by native_decide) (by native_decide) obtain ⟨gasWord, kGas, CGas, rd8388⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨8373⟩) (okPc := ⟨8385⟩) h hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨8373⟩) (okPc := ⟨8385⟩) h hcodeSize hd8373 (by simpa using hd8374) (by simpa using hd8375) (by simpa using hd8376) (by simpa using hd8377) (by simpa using hd8380) (uniswapV3PoolJumpDestPatched8385 hpatch) (by simpa using hd8385) (by simpa using hd8386) (by simpa using hd8387) (by simp only [List.length_cons]; omega) obtain ⟨cA', σ', z, o, A_in, callGas, k', C', hΘ, rd8389, hoSize⟩ := - RD.uniswapStaticcall rd8388 (by simpa using hd8388) hdepth + RD.solcStaticcall rd8388 (by simpa using hd8388) hdepth (by simp only [List.length_cons]; omega) exact ⟨cA', σ', z, o, A_in, callGas, k', C', hΘ, @@ -904,7 +904,7 @@ theorem uniswapV3PoolSetFeeProtocolOwnerTypedStaticcallMade {v : PoolImmutables} ⟨128⟩ :: ⟨32⟩ :: ⟨132⟩ :: ⟨2376452955⟩ :: setFeeProtocolFactoryWord v :: R) setFeeProtocolOwnerCallMem (UInt256.ofNat 5) rdata (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (setFeeProtocolFactoryWord v) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (setFeeProtocolFactoryWord v) ≠ ⟨0⟩) (hdepth : I.depth.val < 1024) (hov : R.length + 11 ≤ 1024) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) @@ -1051,7 +1051,7 @@ theorem uniswapV3PoolSetFeeProtocolOwnerStaticcallStatusGuard {v : PoolImmutable have hstatus : (if z then (⟨1⟩ : UInt256) else ⟨0⟩) ≠ ⟨0⟩ := by rw [hz] decide - exact RD.uniswapCallSuccessGuardOk (pc := ⟨8389⟩) (okPc := ⟨8405⟩) h hstatus + exact RD.solcCallSuccessGuardOk (pc := ⟨8389⟩) (okPc := ⟨8405⟩) h hstatus hd8389 (by simpa using hd8390) (by simpa using hd8391) (by simpa using hd8392) (by simpa using hd8395) (uniswapV3PoolJumpDestPatched8405 hpatch) (by simpa using hd8405) (by simpa using hd8406) @@ -1060,7 +1060,7 @@ theorem uniswapV3PoolSetFeeProtocolOwnerStaticcallStatusGuard {v : PoolImmutable have hstatus : (if z then (⟨1⟩ : UInt256) else ⟨0⟩) = ⟨0⟩ := by rw [hz] rfl - refine RD.uniswapCallSuccessGuardMissing (pc := ⟨8389⟩) (okPc := ⟨8405⟩) h hstatus + refine RD.solcCallSuccessGuardMissing (pc := ⟨8389⟩) (okPc := ⟨8405⟩) h hstatus hd8389 (by simpa using hd8390) (by simpa using hd8391) (by simpa using hd8392) (by simpa using hd8395) (by simpa using hd8396) (by simpa using hd8397) (by simpa using hd8399) (by simpa using hd8400) (by simpa using hd8401) @@ -1600,7 +1600,7 @@ theorem uniswapV3PoolSetFeeProtocolOwnerCallerGuardReverts {v : PoolImmutables} raw push2 ⟨8449⟩ hd8441 (by evm_ov)] rw [hmask, heq] at rd8444 have rd8445 := rd8444.jumpiNT hd8444 (by decide) (by evm_ov) - exact RD.uniswapPush1Dup1Revert0 rd8445 hd8445 + exact RD.solcPush1Dup1Revert0 rd8445 hd8445 (by simpa [show (⟨8445⟩ : UInt256) + UInt256.ofNat 2 = ⟨8447⟩ by native_decide] using hd8447) (by simpa [ @@ -1619,7 +1619,7 @@ theorem uniswapV3PoolSetFeeProtocolOwnerStaticcallDepthLimitReverts {v : PoolImm ⟨128⟩ :: ⟨32⟩ :: ⟨132⟩ :: ⟨2376452955⟩ :: setFeeProtocolFactoryWord v :: R) setFeeProtocolOwnerCallMem (UInt256.ofNat 5) rdata (cA, σ) k C) (hcodeSize : - Reasoning.Theory.uniswapExtCodeSizeWord σ (setFeeProtocolFactoryWord v) ≠ ⟨0⟩) + Reasoning.Theory.extCodeSizeWord σ (setFeeProtocolFactoryWord v) ≠ ⟨0⟩) (hdepth : ee.depth = 1024) (hov : R.length + 11 ≤ 1024) : RDrev code g s0 := by @@ -1684,14 +1684,14 @@ theorem uniswapV3PoolSetFeeProtocolOwnerStaticcallDepthLimitReverts {v : PoolImm (by native_decide) (by native_decide)) (by native_decide) (by native_decide) (by native_decide) obtain ⟨_, _, _, rd8388⟩ := - RD.uniswapExtcodesizeGuardOkGas (pc := ⟨8373⟩) (okPc := ⟨8385⟩) h hcodeSize + RD.solcExtcodesizeGuardOkGas (pc := ⟨8373⟩) (okPc := ⟨8385⟩) h hcodeSize hd8373 (by simpa using hd8374) (by simpa using hd8375) (by simpa using hd8376) (by simpa using hd8377) (by simpa using hd8380) (uniswapV3PoolJumpDestPatched8385 hpatch) (by simpa using hd8385) (by simpa using hd8386) (by simpa using hd8387) (by simp only [List.length_cons]; omega) obtain ⟨kDepth, CDepth, rd8389⟩ := - RD.uniswapStaticcallDepthLimit rd8388 (by simpa using hd8388) hdepth + RD.solcStaticcallDepthLimit rd8388 (by simpa using hd8388) hdepth (by simp only [List.length_cons]; omega) have rd8389' : RD code ee g s0 ⟨8389⟩ ((if false then (⟨1⟩ : UInt256) else ⟨0⟩) :: ⟨132⟩ :: ⟨2376452955⟩ :: diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocolSource.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocolSource.lean index dd6dd488..a65036f2 100644 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocolSource.lean +++ b/Benchmarks/UniswapV3Pool/SetFeeProtocolSource.lean @@ -74,11 +74,11 @@ theorem evalExpr_setFeeProtocol_addrLit {v : PoolImmutables} (evm : EVM.State) theorem evalExpr_setFeeProtocol_factoryExtCodeSizeGuard_true {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) (hcode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (setFeeProtocolFactoryWord v) ≠ ⟨0⟩) : evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } evm (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)) = .ok (.bool true) := by - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hcode + unfold Reasoning.Theory.extCodeSizeWord at hcode have haddr : AccountAddress.ofUInt256 (setFeeProtocolFactoryWord v) = AccountAddress.ofNat ↑v.factory := by simpa using setFeeProtocolFactoryAddress_eq v @@ -108,11 +108,11 @@ theorem evalExpr_setFeeProtocol_factoryExtCodeSizeGuard_true {v : PoolImmutables theorem evalExpr_setFeeProtocol_factoryExtCodeSizeGuard_false {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) (hcode : - Reasoning.Theory.uniswapExtCodeSizeWord evm.accountMap + Reasoning.Theory.extCodeSizeWord evm.accountMap (setFeeProtocolFactoryWord v) = ⟨0⟩) : evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } evm (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)) = .ok (.bool false) := by - unfold Reasoning.Theory.uniswapExtCodeSizeWord at hcode + unfold Reasoning.Theory.extCodeSizeWord at hcode have haddr : AccountAddress.ofUInt256 (setFeeProtocolFactoryWord v) = AccountAddress.ofNat ↑v.factory := by simpa using setFeeProtocolFactoryAddress_eq v diff --git a/Benchmarks/UniswapV3Pool/SpecSyntax.lean b/Benchmarks/UniswapV3Pool/SpecSyntax.lean index 380fa288..111ee984 100644 --- a/Benchmarks/UniswapV3Pool/SpecSyntax.lean +++ b/Benchmarks/UniswapV3Pool/SpecSyntax.lean @@ -2,40 +2,1511 @@ import Benchmarks.UniswapV3Pool.Spec import Solm.Notation /-! -# UniswapV3Pool spec through the Solm syntax-facing module +# UniswapV3Pool spec in the Solidity-faithful Solm frontend -This benchmark is large enough that the current notation frontend does not cover the full surface. -The file still mirrors the established benchmark convention by exposing a syntax-side contract value -and checking it is definitionally equal to the AST spec. +The whole UniswapV3Pool benchmark spec written with `solidity%` and proven definitionally equal +to the AST spec in `Spec.lean`. + +Escapes used, mirroring the AST spec exactly: +* Storage-alias *reads* are var-style in the spec (`.field (.var x) f`), so every alias field + read goes through `${vf "x" "f"}`; alias *writes* are storage-style (`{base := alias, …}`) and + stay in surface syntax (`info.liquidityGross = …;`). +* Immutables: `${addrLit v.…}` for addresses, `#(v.fee)` / `#(v.tickSpacing)` / + `#(v.maxLiquidityPerTick)` for the integer ones. +* List-`Stmt` spec helpers whose receivers are immutable `Expr`s are spliced: + `${safeTransfer …}`, `${balanceOfInto …}`, `${onlyFactoryOwner v}`, `${checkedWordAddLe …}`; + their binders are read back via `${Expr.var "…"}` where needed (`flash` `paid0`/`paid1`). +* `${int56Wrap …}` splices for the signed-wrap shape (with `sdivTowardZeroE` inside for + `observeSingle`); unsigned wraps are the surface `… % #(2 ^ N)`. +* External callbacks on `msg.sender` use the option form (`{view}` for the constructor's + `parameters` view call, `{value: 0}` for the mint/swap/flash callbacks — the same + `.intLit 0` eth as the spec's default). +* `#(-887272)` for `minTick` (surface `-` would be `.unary .neg`, the spec uses an `intLit`). -/ open Solm Solm.Notation Benchmarks.UniswapV3Pool.Immutables namespace Benchmarks.UniswapV3Pool.Syntax -def storageDeclsSyntax : List StorageDecl := Benchmarks.UniswapV3Pool.storageDecls +/-- Var-style read of a storage-alias field: the spec reads aliases as `.field (.var x) f`, + not as storage references. -/ +def vf (x f : Ident) : Expr := .field (.var x) f + +def contractSyntax (v : PoolImmutables) : ContractDecl := solidity% contract UniswapV3Pool { + struct Slot0 { + uint160 sqrtPriceX96; + int24 tick; + uint16 observationIndex; + uint16 observationCardinality; + uint16 observationCardinalityNext; + uint8 feeProtocol; + bool unlocked; + } + + struct ProtocolFees { + uint128 token0; + uint128 token1; + } + + struct Tick.Info { + uint128 liquidityGross; + int128 liquidityNet; + uint256 feeGrowthOutside0X128; + uint256 feeGrowthOutside1X128; + int56 tickCumulativeOutside; + uint160 secondsPerLiquidityOutsideX128; + uint32 secondsOutside; + bool initialized; + } + + struct Position.Info { + uint128 liquidity; + uint256 feeGrowthInside0LastX128; + uint256 feeGrowthInside1LastX128; + uint128 tokensOwed0; + uint128 tokensOwed1; + } + + struct Oracle.Observation { + uint32 blockTimestamp; + int56 tickCumulative; + uint160 secondsPerLiquidityCumulativeX128; + bool initialized; + } + + Slot0 slot0; + uint256 feeGrowthGlobal0X128; + uint256 feeGrowthGlobal1X128; + ProtocolFees protocolFees; + uint128 liquidity; + mapping(int24 => Tick.Info) ticks; + mapping(int16 => uint256) tickBitmap; + mapping(bytes32 => Position.Info) positions; + Oracle.Observation[65535] observations; + mapping(uint256 => Oracle.Observation) observationsRaw; + + constructor() { + var r = msg.sender.parameters{view}(); + var imm_factory = r.0; + var imm_token0 = r.1; + var imm_token1 = r.2; + var imm_fee = r.3; + var imm_tickSpacing = r.4; + var imm_original = this; + var imm_maxLiquidityPerTick = #(2 ^ 128 - 1) / (2 * (887272 / imm_tickSpacing) + 1); + } + + function getSqrtRatioAtTick(int24 tick) internal returns (uint160) { + uint256 absTick = tick < 0 ? 0 - tick : tick; + require(absTick <= 887272); + uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : #(2 ^ 128); + if (absTick & 0x2 != 0) { + ratio = ratio * 0xfff97272373d413259a46990580e213a >> 128; + } + if (absTick & 0x4 != 0) { + ratio = ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc >> 128; + } + if (absTick & 0x8 != 0) { + ratio = ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0 >> 128; + } + if (absTick & 0x10 != 0) { + ratio = ratio * 0xffcb9843d60f6159c9db58835c926644 >> 128; + } + if (absTick & 0x20 != 0) { + ratio = ratio * 0xff973b41fa98c081472e6896dfb254c0 >> 128; + } + if (absTick & 0x40 != 0) { + ratio = ratio * 0xff2ea16466c96a3843ec78b326b52861 >> 128; + } + if (absTick & 0x80 != 0) { + ratio = ratio * 0xfe5dee046a99a2a811c461f1969c3053 >> 128; + } + if (absTick & 0x100 != 0) { + ratio = ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4 >> 128; + } + if (absTick & 0x200 != 0) { + ratio = ratio * 0xf987a7253ac413176f2b074cf7815e54 >> 128; + } + if (absTick & 0x400 != 0) { + ratio = ratio * 0xf3392b0822b70005940c7a398e4b70f3 >> 128; + } + if (absTick & 0x800 != 0) { + ratio = ratio * 0xe7159475a2c29b7443b29c7fa6e889d9 >> 128; + } + if (absTick & 0x1000 != 0) { + ratio = ratio * 0xd097f3bdfd2022b8845ad8f792aa5825 >> 128; + } + if (absTick & 0x2000 != 0) { + ratio = ratio * 0xa9f746462d870fdf8a65dc1f90e061e5 >> 128; + } + if (absTick & 0x4000 != 0) { + ratio = ratio * 0x70d869a156d2a1b890bb3df62baf32f7 >> 128; + } + if (absTick & 0x8000 != 0) { + ratio = ratio * 0x31be135f97d08fd981231505542fcfa6 >> 128; + } + if (absTick & 0x10000 != 0) { + ratio = ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9 >> 128; + } + if (absTick & 0x20000 != 0) { + ratio = ratio * 0x5d6af8dedb81196699c329225ee604 >> 128; + } + if (absTick & 0x40000 != 0) { + ratio = ratio * 0x2216e584f5fa1ea926041bedfe98 >> 128; + } + if (absTick & 0x80000 != 0) { + ratio = ratio * 0x48a170391f7dc42444e8fa2 >> 128; + } + if (tick > 0) { + ratio = type(uint256).max / ratio; + } + return (ratio >> 32) + (ratio % #(2 ^ 32) == 0 ? 0 : 1); + } + + function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal returns (int24) { + require(sqrtPriceX96 >= 4295128739 && + sqrtPriceX96 < 1461446703485210103287273052203988822378723970342); + uint256 ratio = sqrtPriceX96 << 32; + uint256 r = ratio; + uint256 msb = 0; + uint256 f = r > 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ? #(2 ^ 7) : 0; + msb = msb + f; + r = r >> f; + uint256 f = r > 0xFFFFFFFFFFFFFFFF ? #(2 ^ 6) : 0; + msb = msb + f; + r = r >> f; + uint256 f = r > 0xFFFFFFFF ? #(2 ^ 5) : 0; + msb = msb + f; + r = r >> f; + uint256 f = r > 0xFFFF ? #(2 ^ 4) : 0; + msb = msb + f; + r = r >> f; + uint256 f = r > 0xFF ? #(2 ^ 3) : 0; + msb = msb + f; + r = r >> f; + uint256 f = r > 0xF ? #(2 ^ 2) : 0; + msb = msb + f; + r = r >> f; + uint256 f = r > 0x3 ? #(2 ^ 1) : 0; + msb = msb + f; + r = r >> f; + uint256 f = r > 0x1 ? 1 : 0; + msb = msb + f; + if (msb >= 128) { + r = ratio >> (msb - 127); + } else { + r = ratio << (127 - msb); + } + int256 log_2 = (msb - 128) * #(2 ^ 64); + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 63); + r = r >> f; + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 62); + r = r >> f; + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 61); + r = r >> f; + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 60); + r = r >> f; + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 59); + r = r >> f; + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 58); + r = r >> f; + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 57); + r = r >> f; + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 56); + r = r >> f; + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 55); + r = r >> f; + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 54); + r = r >> f; + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 53); + r = r >> f; + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 52); + r = r >> f; + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 51); + r = r >> f; + r = r * r >> 127; + uint256 f = r >> 128; + log_2 = log_2 + f * #(2 ^ 50); + int256 log_sqrt10001 = log_2 * 255738958999603826347141; + int24 tickLow = (log_sqrt10001 - 3402992956809132418596140100660247210) / #(2 ^ 128); + int24 tickHi = (log_sqrt10001 + 291339464771989622907027621153398088495) / #(2 ^ 128); + var sqrtRatioAtTickHi = getSqrtRatioAtTick(tickHi); + return tickLow == tickHi ? tickLow : (sqrtRatioAtTickHi <= sqrtPriceX96 ? tickHi : tickLow); + } + + function oracleLte(uint32 time, uint32 a, uint32 b) internal returns (bool) { + if (a <= time && b <= time) { + return a <= b; + } + uint256 aAdjusted = a > time ? a : a + #(2 ^ 32); + uint256 bAdjusted = b > time ? b : b + #(2 ^ 32); + return aAdjusted <= bAdjusted; + } + + function oracleTransform(uint32 lastBlockTimestamp, int56 lastTickCumulative, + uint160 lastSecondsPerLiquidityCumulativeX128, uint32 blockTimestamp, int24 tick, + uint128 liquidity) internal returns (uint32, int56, uint160, bool) { + uint32 delta = (blockTimestamp - lastBlockTimestamp) % #(2 ^ 32); + uint128 liquidityDenominator = liquidity > 0 ? liquidity : 1; + int56 tickCumulative = + ${int56Wrap (addE (.var "lastTickCumulative") (mulE (.var "tick") (.var "delta")))}; + uint160 secondsPerLiquidityCumulativeX128 = + (lastSecondsPerLiquidityCumulativeX128 + (delta << 128) / liquidityDenominator) + % #(2 ^ 160); + return blockTimestamp, tickCumulative, secondsPerLiquidityCumulativeX128, true; + } + + function getSurroundingObservations(uint32 time, uint32 target, int24 tick, uint16 index, + uint128 liquidity, uint16 cardinality) + internal returns (uint32, int56, uint160, bool, uint32, int56, uint160, bool) { + Oracle.Observation storage beforeOrAt = observations[index]; + uint32 atOrAfterBlockTimestamp = 0; + int56 atOrAfterTickCumulative = 0; + uint160 atOrAfterSecondsPerLiquidityCumulativeX128 = 0; + bool atOrAfterInitialized = false; + var targetAtOrAfterNewest = oracleLte(time, ${vf "beforeOrAt" "blockTimestamp"}, target); + if (targetAtOrAfterNewest) { + if (${vf "beforeOrAt" "blockTimestamp"} == target) { + return ${vf "beforeOrAt" "blockTimestamp"}, ${vf "beforeOrAt" "tickCumulative"}, + ${vf "beforeOrAt" "secondsPerLiquidityCumulativeX128"}, + ${vf "beforeOrAt" "initialized"}, + atOrAfterBlockTimestamp, atOrAfterTickCumulative, + atOrAfterSecondsPerLiquidityCumulativeX128, atOrAfterInitialized; + } + var transformed = oracleTransform(${vf "beforeOrAt" "blockTimestamp"}, + ${vf "beforeOrAt" "tickCumulative"}, + ${vf "beforeOrAt" "secondsPerLiquidityCumulativeX128"}, target, tick, liquidity); + return ${vf "beforeOrAt" "blockTimestamp"}, ${vf "beforeOrAt" "tickCumulative"}, + ${vf "beforeOrAt" "secondsPerLiquidityCumulativeX128"}, + ${vf "beforeOrAt" "initialized"}, + transformed.0, transformed.1, transformed.2, transformed.3; + } + uint256 oldestIndex = (index + 1) % cardinality; + Oracle.Observation storage oldest = observations[oldestIndex]; + if (!${vf "oldest" "initialized"}) { + Oracle.Observation storage oldest = observations[0]; + } + var targetAtOrAfterOldest = oracleLte(time, ${vf "oldest" "blockTimestamp"}, target); + require(targetAtOrAfterOldest); + uint256 l = oldestIndex; + uint256 r = l + (cardinality - 1); + while (true) { + uint256 i = (l + r) / 2; + Oracle.Observation storage beforeOrAt = observations[i % cardinality]; + if (!${vf "beforeOrAt" "initialized"}) { + l = i + 1; + continue; + } + Oracle.Observation storage atOrAfter = observations[(i + 1) % cardinality]; + var targetAtOrAfter = oracleLte(time, ${vf "beforeOrAt" "blockTimestamp"}, target); + var targetAtOrBeforeAfter = oracleLte(time, target, ${vf "atOrAfter" "blockTimestamp"}); + if (targetAtOrAfter && targetAtOrBeforeAfter) { + return ${vf "beforeOrAt" "blockTimestamp"}, ${vf "beforeOrAt" "tickCumulative"}, + ${vf "beforeOrAt" "secondsPerLiquidityCumulativeX128"}, + ${vf "beforeOrAt" "initialized"}, + ${vf "atOrAfter" "blockTimestamp"}, ${vf "atOrAfter" "tickCumulative"}, + ${vf "atOrAfter" "secondsPerLiquidityCumulativeX128"}, + ${vf "atOrAfter" "initialized"}; + } + if (!targetAtOrAfter) { + r = i - 1; + } else { + l = i + 1; + } + } + return ${vf "oldest" "blockTimestamp"}, ${vf "oldest" "tickCumulative"}, + ${vf "oldest" "secondsPerLiquidityCumulativeX128"}, ${vf "oldest" "initialized"}, + atOrAfterBlockTimestamp, atOrAfterTickCumulative, + atOrAfterSecondsPerLiquidityCumulativeX128, atOrAfterInitialized; + } + + function observeSingle(uint32 time, uint32 secondsAgo, int24 tick, uint16 index, + uint128 liquidity, uint16 cardinality) internal returns (int56, uint160) { + if (secondsAgo == 0) { + require(index < 65535); + if (observationsRaw[index].blockTimestamp != time) { + var lastTransformed = oracleTransform(observationsRaw[index].blockTimestamp, + observationsRaw[index].tickCumulative, + observationsRaw[index].secondsPerLiquidityCumulativeX128, time, tick, liquidity); + return lastTransformed.1, lastTransformed.2; + } else { + return observationsRaw[index].tickCumulative, + observationsRaw[index].secondsPerLiquidityCumulativeX128; + } + } + uint32 target = (time - secondsAgo) % #(2 ^ 32); + var surrounding = getSurroundingObservations(time, target, tick, index, liquidity, + cardinality); + if (target == surrounding.0) { + return surrounding.1, surrounding.2; + } + if (target == surrounding.4) { + return surrounding.5, surrounding.6; + } + uint32 observationTimeDelta = (surrounding.4 - surrounding.0) % #(2 ^ 32); + uint32 targetDelta = (target - surrounding.0) % #(2 ^ 32); + return + ${int56Wrap (addE (tuple1 (.var "surrounding")) + (mulE + (sdivTowardZeroE (subE (tuple5 (.var "surrounding")) (tuple1 (.var "surrounding"))) + (.var "observationTimeDelta")) + (.var "targetDelta")))}, + (surrounding.2 + (surrounding.6 - surrounding.2) * targetDelta / observationTimeDelta) + % #(2 ^ 160); + } + + function observeBody(uint32 time, uint32[] secondsAgos, int24 tick, uint16 index, + uint128 liquidity, uint16 cardinality) internal returns (int56[], uint160[]) { + require(cardinality > 0); + int56[] tickCumulatives = new int56[](secondsAgos.length); + uint160[] secondsPerLiquidityCumulativeX128s = new uint160[](secondsAgos.length); + uint256 i = 0; + while (i < secondsAgos.length) { + var observed = observeSingle(time, secondsAgos[i], tick, index, liquidity, cardinality); + tickCumulatives[i] = observed.0; + secondsPerLiquidityCumulativeX128s[i] = observed.1; + i = i + 1; + } + return tickCumulatives, secondsPerLiquidityCumulativeX128s; + } + + function liquidityAddDelta(uint128 x, int128 y) internal returns (uint128) { + if (y < 0) { + uint128 z = (x - (0 - y)) % #(2 ^ 128); + require(z < x); + return z; + } else { + uint128 z = (x + y) % #(2 ^ 128); + require(z >= x); + return z; + } + } + + function oracleWrite(uint16 index, uint32 blockTimestamp, int24 tick, uint128 liquidity, + uint16 cardinality, uint16 cardinalityNext) internal returns (uint16, uint16) { + Oracle.Observation storage last = observations[index]; + if (${vf "last" "blockTimestamp"} == blockTimestamp) { + return index, cardinality; + } + uint16 cardinalityUpdated = + cardinalityNext > cardinality && index == cardinality - 1 ? cardinalityNext : cardinality; + uint16 indexUpdated = (index + 1) % cardinalityUpdated; + var transformed = oracleTransform(${vf "last" "blockTimestamp"}, + ${vf "last" "tickCumulative"}, ${vf "last" "secondsPerLiquidityCumulativeX128"}, + blockTimestamp, tick, liquidity); + observations[indexUpdated].blockTimestamp = transformed.0; + observations[indexUpdated].tickCumulative = transformed.1; + observations[indexUpdated].secondsPerLiquidityCumulativeX128 = transformed.2; + observations[indexUpdated].initialized = transformed.3; + return indexUpdated, cardinalityUpdated; + } + + function tickGetFeeGrowthInside(int24 tickLower, int24 tickUpper, int24 tickCurrent, + uint256 feeGrowthGlobal0X128, uint256 feeGrowthGlobal1X128) + internal returns (uint256, uint256) { + Tick.Info storage lower = ticks[tickLower]; + Tick.Info storage upper = ticks[tickUpper]; + uint256 feeGrowthBelow0X128 = tickCurrent >= tickLower ? + ${vf "lower" "feeGrowthOutside0X128"} : + (feeGrowthGlobal0X128 - ${vf "lower" "feeGrowthOutside0X128"}) % #(2 ^ 256); + uint256 feeGrowthBelow1X128 = tickCurrent >= tickLower ? + ${vf "lower" "feeGrowthOutside1X128"} : + (feeGrowthGlobal1X128 - ${vf "lower" "feeGrowthOutside1X128"}) % #(2 ^ 256); + uint256 feeGrowthAbove0X128 = tickCurrent < tickUpper ? + ${vf "upper" "feeGrowthOutside0X128"} : + (feeGrowthGlobal0X128 - ${vf "upper" "feeGrowthOutside0X128"}) % #(2 ^ 256); + uint256 feeGrowthAbove1X128 = tickCurrent < tickUpper ? + ${vf "upper" "feeGrowthOutside1X128"} : + (feeGrowthGlobal1X128 - ${vf "upper" "feeGrowthOutside1X128"}) % #(2 ^ 256); + return ((feeGrowthGlobal0X128 - feeGrowthBelow0X128) % #(2 ^ 256) - feeGrowthAbove0X128) + % #(2 ^ 256), + ((feeGrowthGlobal1X128 - feeGrowthBelow1X128) % #(2 ^ 256) - feeGrowthAbove1X128) + % #(2 ^ 256); + } + + function tickUpdate(int24 tick, int24 tickCurrent, int128 liquidityDelta, + uint256 feeGrowthGlobal0X128, uint256 feeGrowthGlobal1X128, + uint160 secondsPerLiquidityCumulativeX128, int56 tickCumulative, uint32 time, + bool upper, uint128 maxLiquidity) internal returns (bool) { + Tick.Info storage info = ticks[tick]; + uint128 liquidityGrossBefore = ${vf "info" "liquidityGross"}; + var liquidityGrossAfter = liquidityAddDelta(liquidityGrossBefore, liquidityDelta); + require(liquidityGrossAfter <= maxLiquidity); + bool flipped = (liquidityGrossAfter == 0) != (liquidityGrossBefore == 0); + if (liquidityGrossBefore == 0) { + if (tick <= tickCurrent) { + info.feeGrowthOutside0X128 = feeGrowthGlobal0X128; + info.feeGrowthOutside1X128 = feeGrowthGlobal1X128; + info.secondsPerLiquidityOutsideX128 = secondsPerLiquidityCumulativeX128; + info.tickCumulativeOutside = tickCumulative; + info.secondsOutside = time; + } + info.initialized = true; + } + info.liquidityGross = liquidityGrossAfter; + info.liquidityNet = (upper ? + ${vf "info" "liquidityNet"} - liquidityDelta : + ${vf "info" "liquidityNet"} + liquidityDelta) as int128; + return flipped; + } + + function tickClear(int24 tick) internal { + delete ticks[tick]; + } + + function tickBitmapFlip(int24 tick, int24 tickSpacing) internal { + require(tick % tickSpacing == 0); + int24 compressed = tick / tickSpacing; + int16 wordPos = compressed / 256; + uint8 bitPos = compressed % 256; + uint256 mask = 1 << bitPos; + tickBitmap[wordPos] = tickBitmap[wordPos] ^ mask; + } + + function positionUpdate(bytes32 positionKey, int128 liquidityDelta, + uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) internal { + Position.Info storage position = positions[positionKey]; + if (liquidityDelta == 0) { + require(${vf "position" "liquidity"} > 0); + uint128 liquidityNext = ${vf "position" "liquidity"}; + } else { + var liquidityNext = liquidityAddDelta(${vf "position" "liquidity"}, liquidityDelta); + } + uint128 tokensOwed0 = + ((feeGrowthInside0X128 - ${vf "position" "feeGrowthInside0LastX128"}) % #(2 ^ 256) + * ${vf "position" "liquidity"} / #(2 ^ 128)) % #(2 ^ 128); + uint128 tokensOwed1 = + ((feeGrowthInside1X128 - ${vf "position" "feeGrowthInside1LastX128"}) % #(2 ^ 256) + * ${vf "position" "liquidity"} / #(2 ^ 128)) % #(2 ^ 128); + if (liquidityDelta != 0) { + position.liquidity = liquidityNext; + } + position.feeGrowthInside0LastX128 = feeGrowthInside0X128; + position.feeGrowthInside1LastX128 = feeGrowthInside1X128; + if (tokensOwed0 > 0 || tokensOwed1 > 0) { + position.tokensOwed0 = ${vf "position" "tokensOwed0"} + tokensOwed0; + position.tokensOwed1 = ${vf "position" "tokensOwed1"} + tokensOwed1; + } + } + + function getAmount0DeltaUnsigned(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, + uint128 liquidity, bool roundUp) internal returns (uint256) { + uint160 sqrtRatioA = sqrtRatioAX96; + uint160 sqrtRatioB = sqrtRatioBX96; + if (sqrtRatioA > sqrtRatioB) { + sqrtRatioA = sqrtRatioBX96; + sqrtRatioB = sqrtRatioAX96; + } + uint256 numerator1 = liquidity << 96; + uint256 numerator2 = sqrtRatioB - sqrtRatioA; + require(sqrtRatioA > 0); + if (roundUp) { + require(sqrtRatioB > 0); + uint256 product = numerator1 * numerator2 / sqrtRatioB; + require(product <= type(uint256).max); + if (numerator1 * numerator2 % sqrtRatioB > 0) { + require(product < type(uint256).max); + product = product + 1; + } + require(sqrtRatioA > 0); + uint256 amount0 = product / sqrtRatioA; + if (product % sqrtRatioA > 0) { + require(amount0 < type(uint256).max); + amount0 = amount0 + 1; + } + return amount0; + } else { + require(sqrtRatioB > 0); + uint256 product = numerator1 * numerator2 / sqrtRatioB; + require(product <= type(uint256).max); + return product / sqrtRatioA; + } + } + + function getAmount1DeltaUnsigned(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, + uint128 liquidity, bool roundUp) internal returns (uint256) { + uint160 sqrtRatioA = sqrtRatioAX96; + uint160 sqrtRatioB = sqrtRatioBX96; + if (sqrtRatioA > sqrtRatioB) { + sqrtRatioA = sqrtRatioBX96; + sqrtRatioB = sqrtRatioAX96; + } + if (roundUp) { + require(#(2 ^ 96) > 0); + uint256 amount1 = liquidity * (sqrtRatioB - sqrtRatioA) / #(2 ^ 96); + require(amount1 <= type(uint256).max); + if (liquidity * (sqrtRatioB - sqrtRatioA) % #(2 ^ 96) > 0) { + require(amount1 < type(uint256).max); + amount1 = amount1 + 1; + } + return amount1; + } else { + require(#(2 ^ 96) > 0); + uint256 amount1 = liquidity * (sqrtRatioB - sqrtRatioA) / #(2 ^ 96); + require(amount1 <= type(uint256).max); + return amount1; + } + } + + function getAmount0DeltaSigned(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, + int128 liquidity) internal returns (int256) { + if (liquidity < 0) { + var amount0Unsigned = getAmount0DeltaUnsigned(sqrtRatioAX96, sqrtRatioBX96, + (0 - liquidity) % #(2 ^ 128), false); + return 0 - amount0Unsigned; + } else { + var amount0Unsigned = getAmount0DeltaUnsigned(sqrtRatioAX96, sqrtRatioBX96, + liquidity % #(2 ^ 128), true); + return amount0Unsigned; + } + } + + function getAmount1DeltaSigned(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, + int128 liquidity) internal returns (int256) { + if (liquidity < 0) { + var amount1Unsigned = getAmount1DeltaUnsigned(sqrtRatioAX96, sqrtRatioBX96, + (0 - liquidity) % #(2 ^ 128), false); + return 0 - amount1Unsigned; + } else { + var amount1Unsigned = getAmount1DeltaUnsigned(sqrtRatioAX96, sqrtRatioBX96, + liquidity % #(2 ^ 128), true); + return amount1Unsigned; + } + } + + function modifyPosition(address owner, int24 tickLower, int24 tickUpper, + int128 liquidityDelta) internal returns (bytes32, int256, int256) { + require(this == ${addrLit v.original}); + require(tickLower < tickUpper); + require(tickLower >= #(-887272)); + require(tickUpper <= 887272); + uint160 _slot0sqrtPriceX96 = slot0.sqrtPriceX96; + int24 _slot0tick = slot0.tick; + uint16 _slot0observationIndex = slot0.observationIndex; + uint16 _slot0observationCardinality = slot0.observationCardinality; + uint16 _slot0observationCardinalityNext = slot0.observationCardinalityNext; + bytes32 _positionKey = + keccak256(abi.encodePacked(address(owner), int24(tickLower), int24(tickUpper))); + uint256 _feeGrowthGlobal0X128 = feeGrowthGlobal0X128; + uint256 _feeGrowthGlobal1X128 = feeGrowthGlobal1X128; + bool flippedLower = false; + bool flippedUpper = false; + if (liquidityDelta != 0) { + uint32 time = block.timestamp % #(2 ^ 32); + var observedForUpdate = observeSingle(time, 0, slot0.tick, slot0.observationIndex, + liquidity, slot0.observationCardinality); + var flippedLowerCall = tickUpdate(tickLower, _slot0tick, liquidityDelta, + _feeGrowthGlobal0X128, _feeGrowthGlobal1X128, observedForUpdate.1, + observedForUpdate.0, time, false, #(v.maxLiquidityPerTick)); + flippedLower = flippedLowerCall; + var flippedUpperCall = tickUpdate(tickUpper, _slot0tick, liquidityDelta, + _feeGrowthGlobal0X128, _feeGrowthGlobal1X128, observedForUpdate.1, + observedForUpdate.0, time, true, #(v.maxLiquidityPerTick)); + flippedUpper = flippedUpperCall; + if (flippedLower) { + var _flipLower = tickBitmapFlip(tickLower, #(v.tickSpacing)); + } + if (flippedUpper) { + var _flipUpper = tickBitmapFlip(tickUpper, #(v.tickSpacing)); + } + } + var feeGrowthInside = tickGetFeeGrowthInside(tickLower, tickUpper, _slot0tick, + _feeGrowthGlobal0X128, _feeGrowthGlobal1X128); + var _positionUpdated = positionUpdate(_positionKey, liquidityDelta, feeGrowthInside.0, + feeGrowthInside.1); + if (liquidityDelta < 0) { + if (flippedLower) { + var _clearLower = tickClear(tickLower); + } + if (flippedUpper) { + var _clearUpper = tickClear(tickUpper); + } + } + int256 amount0 = 0; + int256 amount1 = 0; + if (liquidityDelta != 0) { + if (_slot0tick < tickLower) { + var sqrtRatioLowerBelow = getSqrtRatioAtTick(tickLower); + var sqrtRatioUpperBelow = getSqrtRatioAtTick(tickUpper); + var amount0Below = getAmount0DeltaSigned(sqrtRatioLowerBelow, sqrtRatioUpperBelow, + liquidityDelta); + amount0 = amount0Below; + } else { + if (_slot0tick < tickUpper) { + uint128 liquidityBefore = liquidity; + var oracleUpdated = oracleWrite(_slot0observationIndex, block.timestamp % #(2 ^ 32), + _slot0tick, liquidityBefore, _slot0observationCardinality, + _slot0observationCardinalityNext); + slot0.observationIndex = oracleUpdated.0; + slot0.observationCardinality = oracleUpdated.1; + var sqrtRatioUpperInside = getSqrtRatioAtTick(tickUpper); + var amount0Inside = getAmount0DeltaSigned(_slot0sqrtPriceX96, sqrtRatioUpperInside, + liquidityDelta); + amount0 = amount0Inside; + var sqrtRatioLowerInside = getSqrtRatioAtTick(tickLower); + var amount1Inside = getAmount1DeltaSigned(sqrtRatioLowerInside, _slot0sqrtPriceX96, + liquidityDelta); + amount1 = amount1Inside; + var liquidityAfter = liquidityAddDelta(liquidityBefore, liquidityDelta); + liquidity = liquidityAfter; + } else { + var sqrtRatioLowerAbove = getSqrtRatioAtTick(tickLower); + var sqrtRatioUpperAbove = getSqrtRatioAtTick(tickUpper); + var amount1Above = getAmount1DeltaSigned(sqrtRatioLowerAbove, sqrtRatioUpperAbove, + liquidityDelta); + amount1 = amount1Above; + } + } + } + return _positionKey, amount0, amount1; + } + + function mostSignificantBit(uint256 x) internal returns (uint8) { + require(x > 0); + uint8 r = 0; + if (x >= #(2 ^ 128)) { + x = x >> 128; + r = r + 128; + } + if (x >= #(2 ^ 64)) { + x = x >> 64; + r = r + 64; + } + if (x >= #(2 ^ 32)) { + x = x >> 32; + r = r + 32; + } + if (x >= #(2 ^ 16)) { + x = x >> 16; + r = r + 16; + } + if (x >= #(2 ^ 8)) { + x = x >> 8; + r = r + 8; + } + if (x >= #(2 ^ 4)) { + x = x >> 4; + r = r + 4; + } + if (x >= #(2 ^ 2)) { + x = x >> 2; + r = r + 2; + } + if (x >= 2) { + r = r + 1; + } + return r; + } + + function leastSignificantBit(uint256 x) internal returns (uint8) { + require(x > 0); + uint8 r = 255; + if (x & #(2 ^ 128 - 1) > 0) { + r = r - 128; + } else { + x = x >> 128; + } + if (x & #(2 ^ 64 - 1) > 0) { + r = r - 64; + } else { + x = x >> 64; + } + if (x & #(2 ^ 32 - 1) > 0) { + r = r - 32; + } else { + x = x >> 32; + } + if (x & #(2 ^ 16 - 1) > 0) { + r = r - 16; + } else { + x = x >> 16; + } + if (x & #(2 ^ 8 - 1) > 0) { + r = r - 8; + } else { + x = x >> 8; + } + if (x & 0xf > 0) { + r = r - 4; + } else { + x = x >> 4; + } + if (x & 0x3 > 0) { + r = r - 2; + } else { + x = x >> 2; + } + if (x & 0x1 > 0) { + r = r - 1; + } + return r; + } + + function tickBitmapNextInitializedTickWithinOneWord(int24 tick, int24 tickSpacing, bool lte) + internal returns (int24, bool) { + int24 compressed = tick / tickSpacing; + if (lte) { + int16 wordPos = compressed / 256; + uint8 bitPos = compressed % 256; + uint256 oneAtBit = 1 << bitPos; + uint256 mask = (oneAtBit - 1) + oneAtBit; + uint256 masked = tickBitmap[wordPos] & mask; + bool initialized = masked != 0; + if (initialized) { + var msb = mostSignificantBit(masked); + return ((compressed - (bitPos - msb)) * tickSpacing) as int24, initialized; + } else { + return ((compressed - bitPos) * tickSpacing) as int24, initialized; + } + } else { + int24 compressedPlusOne = compressed + 1; + int16 wordPos = compressedPlusOne / 256; + uint8 bitPos = compressedPlusOne % 256; + uint256 mask = ~((1 << bitPos) - 1); + uint256 masked = tickBitmap[wordPos] & mask; + bool initialized = masked != 0; + if (initialized) { + var lsb = leastSignificantBit(masked); + return ((compressedPlusOne + (lsb - bitPos)) * tickSpacing) as int24, initialized; + } else { + return ((compressedPlusOne + (255 - bitPos)) * tickSpacing) as int24, initialized; + } + } + } + + function tickCross(int24 tick, uint256 feeGrowthGlobal0X128, uint256 feeGrowthGlobal1X128, + uint160 secondsPerLiquidityCumulativeX128, int56 tickCumulative, uint32 time) + internal returns (int128) { + Tick.Info storage info = ticks[tick]; + info.feeGrowthOutside0X128 = + (feeGrowthGlobal0X128 - ${vf "info" "feeGrowthOutside0X128"}) % #(2 ^ 256); + info.feeGrowthOutside1X128 = + (feeGrowthGlobal1X128 - ${vf "info" "feeGrowthOutside1X128"}) % #(2 ^ 256); + info.secondsPerLiquidityOutsideX128 = + (secondsPerLiquidityCumulativeX128 - ${vf "info" "secondsPerLiquidityOutsideX128"}) + % #(2 ^ 160); + info.tickCumulativeOutside = + ${int56Wrap (subE (.var "tickCumulative") (vf "info" "tickCumulativeOutside"))}; + info.secondsOutside = (time - ${vf "info" "secondsOutside"}) % #(2 ^ 32); + return ${vf "info" "liquidityNet"}; + } + + function getNextSqrtPriceFromAmount0RoundingUp(uint160 sqrtPX96, uint128 liquidity, + uint256 amount, bool add) internal returns (uint160) { + if (amount == 0) { + return sqrtPX96; + } + uint256 numerator1 = liquidity << 96; + if (add) { + uint256 product = amount * sqrtPX96 % #(2 ^ 256); + if (product / amount == sqrtPX96) { + uint256 denominator = (numerator1 + product) % #(2 ^ 256); + if (denominator >= numerator1) { + require(denominator > 0); + uint256 price = numerator1 * sqrtPX96 / denominator; + require(price <= type(uint256).max); + if (numerator1 * sqrtPX96 % denominator > 0) { + require(price < type(uint256).max); + price = price + 1; + } + return price % #(2 ^ 160); + } + } + uint256 denominator2Base = numerator1 / sqrtPX96; + uint256 denominator2 = (denominator2Base + amount) % #(2 ^ 256); + require(denominator2 >= denominator2Base); + require(denominator2 > 0); + uint256 price = numerator1 / denominator2; + if (numerator1 % denominator2 > 0) { + require(price < type(uint256).max); + price = price + 1; + } + return price % #(2 ^ 160); + } else { + uint256 product = amount * sqrtPX96 % #(2 ^ 256); + require(product / amount == sqrtPX96 && numerator1 > product); + uint256 denominator = numerator1 - product; + require(denominator > 0); + uint256 price = numerator1 * sqrtPX96 / denominator; + require(price <= type(uint256).max); + if (numerator1 * sqrtPX96 % denominator > 0) { + require(price < type(uint256).max); + price = price + 1; + } + return (price) as uint160; + } + } + + function getNextSqrtPriceFromAmount1RoundingDown(uint160 sqrtPX96, uint128 liquidity, + uint256 amount, bool add) internal returns (uint160) { + if (add) { + if (amount <= type(uint160).max) { + uint256 quotient = (amount << 96) / liquidity; + } else { + require(liquidity > 0); + uint256 quotient = amount * #(2 ^ 96) / liquidity; + require(quotient <= type(uint256).max); + } + uint256 next = (sqrtPX96 + quotient) % #(2 ^ 256); + require(next >= sqrtPX96); + return (next) as uint160; + } else { + if (amount <= type(uint160).max) { + require(liquidity > 0); + uint256 quotient = (amount << 96) / liquidity; + if ((amount << 96) % liquidity > 0) { + require(quotient < type(uint256).max); + quotient = quotient + 1; + } + } else { + require(liquidity > 0); + uint256 quotient = amount * #(2 ^ 96) / liquidity; + require(quotient <= type(uint256).max); + if (amount * #(2 ^ 96) % liquidity > 0) { + require(quotient < type(uint256).max); + quotient = quotient + 1; + } + } + require(sqrtPX96 > quotient); + return sqrtPX96 - quotient; + } + } + + function getNextSqrtPriceFromInput(uint160 sqrtPX96, uint128 liquidity, uint256 amountIn, + bool zeroForOne) internal returns (uint160) { + require(sqrtPX96 > 0); + require(liquidity > 0); + if (zeroForOne) { + var sqrtQX96 = getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountIn, + true); + return sqrtQX96; + } else { + var sqrtQX96 = getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountIn, + true); + return sqrtQX96; + } + } + + function getNextSqrtPriceFromOutput(uint160 sqrtPX96, uint128 liquidity, uint256 amountOut, + bool zeroForOne) internal returns (uint160) { + require(sqrtPX96 > 0); + require(liquidity > 0); + if (zeroForOne) { + var sqrtQX96 = getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountOut, + false); + return sqrtQX96; + } else { + var sqrtQX96 = getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountOut, + false); + return sqrtQX96; + } + } + + function computeSwapStep(uint160 sqrtRatioCurrentX96, uint160 sqrtRatioTargetX96, + uint128 liquidity, int256 amountRemaining, uint24 feePips) + internal returns (uint160, uint256, uint256, uint256) { + bool zeroForOne = sqrtRatioCurrentX96 >= sqrtRatioTargetX96; + bool exactIn = amountRemaining >= 0; + uint160 sqrtRatioNextX96 = 0; + uint256 amountIn = 0; + uint256 amountOut = 0; + uint256 feeAmount = 0; + if (exactIn) { + require(1000000 > 0); + uint256 amountRemainingLessFee = + amountRemaining % #(2 ^ 256) * (1000000 - feePips) / 1000000; + require(amountRemainingLessFee <= type(uint256).max); + if (zeroForOne) { + var amountInToTarget = getAmount0DeltaUnsigned(sqrtRatioTargetX96, + sqrtRatioCurrentX96, liquidity, true); + } else { + var amountInToTarget = getAmount1DeltaUnsigned(sqrtRatioCurrentX96, + sqrtRatioTargetX96, liquidity, true); + } + amountIn = amountInToTarget; + if (amountRemainingLessFee >= amountIn) { + sqrtRatioNextX96 = sqrtRatioTargetX96; + } else { + var nextSqrtInput = getNextSqrtPriceFromInput(sqrtRatioCurrentX96, liquidity, + amountRemainingLessFee, zeroForOne); + sqrtRatioNextX96 = nextSqrtInput; + } + } else { + if (zeroForOne) { + var amountOutToTarget = getAmount1DeltaUnsigned(sqrtRatioTargetX96, + sqrtRatioCurrentX96, liquidity, false); + } else { + var amountOutToTarget = getAmount0DeltaUnsigned(sqrtRatioCurrentX96, + sqrtRatioTargetX96, liquidity, false); + } + amountOut = amountOutToTarget; + if ((0 - amountRemaining) % #(2 ^ 256) >= amountOut) { + sqrtRatioNextX96 = sqrtRatioTargetX96; + } else { + var nextSqrtOutput = getNextSqrtPriceFromOutput(sqrtRatioCurrentX96, liquidity, + (0 - amountRemaining) % #(2 ^ 256), zeroForOne); + sqrtRatioNextX96 = nextSqrtOutput; + } + } + bool max = sqrtRatioTargetX96 == sqrtRatioNextX96; + if (zeroForOne) { + if (!(max && exactIn)) { + var amountInRecomputed = getAmount0DeltaUnsigned(sqrtRatioNextX96, + sqrtRatioCurrentX96, liquidity, true); + amountIn = amountInRecomputed; + } + if (!(max && !exactIn)) { + var amountOutRecomputed = getAmount1DeltaUnsigned(sqrtRatioNextX96, + sqrtRatioCurrentX96, liquidity, false); + amountOut = amountOutRecomputed; + } + } else { + if (!(max && exactIn)) { + var amountInRecomputed = getAmount1DeltaUnsigned(sqrtRatioCurrentX96, + sqrtRatioNextX96, liquidity, true); + amountIn = amountInRecomputed; + } + if (!(max && !exactIn)) { + var amountOutRecomputed = getAmount0DeltaUnsigned(sqrtRatioCurrentX96, + sqrtRatioNextX96, liquidity, false); + amountOut = amountOutRecomputed; + } + } + if (!exactIn && amountOut > (0 - amountRemaining) % #(2 ^ 256)) { + amountOut = (0 - amountRemaining) % #(2 ^ 256); + } + if (exactIn && sqrtRatioNextX96 != sqrtRatioTargetX96) { + feeAmount = amountRemaining % #(2 ^ 256) - amountIn; + } else { + require(1000000 - feePips > 0); + uint256 feeAmountComputed = amountIn * feePips / (1000000 - feePips); + require(feeAmountComputed <= type(uint256).max); + if (amountIn * feePips % (1000000 - feePips) > 0) { + require(feeAmountComputed < type(uint256).max); + feeAmountComputed = feeAmountComputed + 1; + } + feeAmount = feeAmountComputed; + } + return sqrtRatioNextX96, amountIn, amountOut, feeAmount; + } + + function burn(int24 tickLower, int24 tickUpper, uint128 amount) + external returns (uint256, uint256) { + require(slot0.unlocked); + slot0.unlocked = false; + int128 liquidityDelta = 0 - ((amount) as int128); + var modified = modifyPosition(msg.sender, tickLower, tickUpper, liquidityDelta); + Position.Info storage position = positions[modified.0]; + uint256 amount0 = (0 - modified.1) % #(2 ^ 256); + uint256 amount1 = (0 - modified.2) % #(2 ^ 256); + if (amount0 > 0 || amount1 > 0) { + position.tokensOwed0 = ${vf "position" "tokensOwed0"} + amount0 % #(2 ^ 128); + position.tokensOwed1 = ${vf "position" "tokensOwed1"} + amount1 % #(2 ^ 128); + } + slot0.unlocked = true; + return amount0, amount1; + } + + function collect(address recipient, int24 tickLower, int24 tickUpper, + uint128 amount0Requested, uint128 amount1Requested) + external returns (uint128, uint128) { + require(slot0.unlocked); + slot0.unlocked = false; + bytes32 positionKey = + keccak256(abi.encodePacked(address(msg.sender), int24(tickLower), int24(tickUpper))); + uint128 amount0 = amount0Requested > positions[positionKey].tokensOwed0 ? + positions[positionKey].tokensOwed0 : amount0Requested; + uint128 amount1 = amount1Requested > positions[positionKey].tokensOwed1 ? + positions[positionKey].tokensOwed1 : amount1Requested; + if (amount0 > 0) { + positions[positionKey].tokensOwed0 = positions[positionKey].tokensOwed0 - amount0; + ${safeTransfer (addrLit v.token0) (.var "recipient") (.var "amount0") "collect0"} + } + if (amount1 > 0) { + positions[positionKey].tokensOwed1 = positions[positionKey].tokensOwed1 - amount1; + ${safeTransfer (addrLit v.token1) (.var "recipient") (.var "amount1") "collect1"} + } + slot0.unlocked = true; + return amount0, amount1; + } + + function collectProtocol(address recipient, uint128 amount0Requested, + uint128 amount1Requested) external returns (uint128, uint128) { + require(slot0.unlocked); + slot0.unlocked = false; + ${onlyFactoryOwner v} + uint128 amount0 = amount0Requested > protocolFees.token0 ? + protocolFees.token0 : amount0Requested; + uint128 amount1 = amount1Requested > protocolFees.token1 ? + protocolFees.token1 : amount1Requested; + if (amount0 > 0) { + if (amount0 == protocolFees.token0) { + amount0 = amount0 - 1; + } + protocolFees.token0 = protocolFees.token0 - amount0; + ${safeTransfer (addrLit v.token0) (.var "recipient") (.var "amount0") "collectProtocol0"} + } + if (amount1 > 0) { + if (amount1 == protocolFees.token1) { + amount1 = amount1 - 1; + } + protocolFees.token1 = protocolFees.token1 - amount1; + ${safeTransfer (addrLit v.token1) (.var "recipient") (.var "amount1") "collectProtocol1"} + } + slot0.unlocked = true; + return amount0, amount1; + } + + function factory() external returns (address) { + return ${addrLit v.factory}; + } + + function fee() external returns (uint24) { + return #(v.fee); + } + + function feeGrowthGlobal0X128() external returns (uint256) { + return feeGrowthGlobal0X128; + } + + function feeGrowthGlobal1X128() external returns (uint256) { + return feeGrowthGlobal1X128; + } + + function flash(address recipient, uint256 amount0, uint256 amount1, bytes data) external { + require(slot0.unlocked); + slot0.unlocked = false; + require(this == ${addrLit v.original}); + uint128 _liquidity = liquidity; + require(_liquidity > 0); + require(1000000 > 0); + uint256 fee0 = amount0 * #(v.fee) / 1000000; + require(fee0 <= type(uint256).max); + if (amount0 * #(v.fee) % 1000000 > 0) { + require(fee0 < type(uint256).max); + fee0 = fee0 + 1; + } + require(1000000 > 0); + uint256 fee1 = amount1 * #(v.fee) / 1000000; + require(fee1 <= type(uint256).max); + if (amount1 * #(v.fee) % 1000000 > 0) { + require(fee1 < type(uint256).max); + fee1 = fee1 + 1; + } + ${balanceOfInto (addrLit v.token0) "balance0Before" "flashBalance0Before"} + ${balanceOfInto (addrLit v.token1) "balance1Before" "flashBalance1Before"} + if (amount0 > 0) { + ${safeTransfer (addrLit v.token0) (.var "recipient") (.var "amount0") "flashTransfer0"} + } + if (amount1 > 0) { + ${safeTransfer (addrLit v.token1) (.var "recipient") (.var "amount1") "flashTransfer1"} + } + var _flashCallback = msg.sender.uniswapV3FlashCallback{value: 0}(fee0, fee1, data); + ${balanceOfInto (addrLit v.token0) "balance0After" "flashBalance0After"} + ${balanceOfInto (addrLit v.token1) "balance1After" "flashBalance1After"} + ${checkedWordAddLe (.var "balance0Before") (.var "fee0") (.var "balance0After")} + ${checkedWordAddLe (.var "balance1Before") (.var "fee1") (.var "balance1After")} + uint256 paid0 = ${Expr.var "balance0After"} - ${Expr.var "balance0Before"}; + uint256 paid1 = ${Expr.var "balance1After"} - ${Expr.var "balance1Before"}; + if (paid0 > 0) { + uint8 feeProtocol0 = slot0.feeProtocol % 16; + uint256 fees0 = feeProtocol0 == 0 ? 0 : paid0 / feeProtocol0; + if (fees0 % #(2 ^ 128) > 0) { + protocolFees.token0 = protocolFees.token0 + fees0 % #(2 ^ 128); + } + require(_liquidity > 0); + uint256 feeGrowth0Delta = (paid0 - fees0) * #(2 ^ 128) / _liquidity; + require(feeGrowth0Delta <= type(uint256).max); + feeGrowthGlobal0X128 = feeGrowthGlobal0X128 + feeGrowth0Delta; + } + if (paid1 > 0) { + uint8 feeProtocol1 = 0 << 0; + feeProtocol1 = slot0.feeProtocol >> 4; + uint256 fees1 = feeProtocol1 == 0 ? 0 : paid1 / feeProtocol1; + if (fees1 % #(2 ^ 128) > 0) { + protocolFees.token1 = protocolFees.token1 + fees1 % #(2 ^ 128); + } + require(_liquidity > 0); + uint256 feeGrowth1Delta = (paid1 - fees1) * #(2 ^ 128) / _liquidity; + require(feeGrowth1Delta <= type(uint256).max); + feeGrowthGlobal1X128 = feeGrowthGlobal1X128 + feeGrowth1Delta; + } + slot0.unlocked = true; + } + + function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external { + require(slot0.unlocked); + slot0.unlocked = false; + require(this == ${addrLit v.original}); + uint16 observationCardinalityNextOld = slot0.observationCardinalityNext; + uint16 observationCardinalityNextNew = observationCardinalityNext; + require(observationCardinalityNextOld > 0); + if (observationCardinalityNextNew <= observationCardinalityNextOld) { + observationCardinalityNextNew = observationCardinalityNextOld; + } else { + uint16 i = observationCardinalityNextOld; + while (i < observationCardinalityNextNew) { + observationsRaw[i].blockTimestamp = 1; + i = i + 1; + } + } + slot0.observationCardinalityNext = observationCardinalityNextNew; + slot0.unlocked = true; + } + + function «initialize»(uint160 sqrtPriceX96) external { + require(slot0.sqrtPriceX96 == 0); + var tick = getTickAtSqrtRatio(sqrtPriceX96); + uint32 time = block.timestamp % #(2 ^ 32); + observations[0].blockTimestamp = time; + observations[0].tickCumulative = 0; + observations[0].secondsPerLiquidityCumulativeX128 = 0; + observations[0].initialized = true; + slot0.sqrtPriceX96 = sqrtPriceX96; + slot0.tick = tick; + slot0.observationIndex = 0; + slot0.observationCardinality = 1; + slot0.observationCardinalityNext = 1; + slot0.feeProtocol = 0; + slot0.unlocked = true; + } + + function liquidity() external returns (uint128) { + return liquidity; + } + + function maxLiquidityPerTick() external returns (uint128) { + return #(v.maxLiquidityPerTick); + } + + function mint(address recipient, int24 tickLower, int24 tickUpper, uint128 amount, + bytes data) external returns (uint256, uint256) { + require(slot0.unlocked); + slot0.unlocked = false; + require(amount > 0); + int128 liquidityDelta = (amount) as int128; + var modified = modifyPosition(recipient, tickLower, tickUpper, liquidityDelta); + uint256 amount0 = modified.1 % #(2 ^ 256); + uint256 amount1 = modified.2 % #(2 ^ 256); + if (amount0 > 0) { + ${balanceOfInto (addrLit v.token0) "balance0Before" "mintBalance0Before"} + } + if (amount1 > 0) { + ${balanceOfInto (addrLit v.token1) "balance1Before" "mintBalance1Before"} + } + var _mintCallback = msg.sender.uniswapV3MintCallback{value: 0}(amount0, amount1, data); + if (amount0 > 0) { + ${balanceOfInto (addrLit v.token0) "balance0After" "mintBalance0After" ++ + checkedWordAddLe (.var "balance0Before") (.var "amount0") (.var "balance0After")} + } + if (amount1 > 0) { + ${balanceOfInto (addrLit v.token1) "balance1After" "mintBalance1After" ++ + checkedWordAddLe (.var "balance1Before") (.var "amount1") (.var "balance1After")} + } + slot0.unlocked = true; + return amount0, amount1; + } + + function observations(uint256 arg0) external returns (uint32, int56, uint160, bool) { + require(arg0 < 65535); + return observationsRaw[arg0].blockTimestamp, observationsRaw[arg0].tickCumulative, + observationsRaw[arg0].secondsPerLiquidityCumulativeX128, + observationsRaw[arg0].initialized; + } + + function observe(uint32[] secondsAgos) external returns (int56[], uint160[]) { + require(this == ${addrLit v.original}); + var observed = observeBody(block.timestamp % #(2 ^ 32), secondsAgos, slot0.tick, + slot0.observationIndex, liquidity, slot0.observationCardinality); + return observed.0, observed.1; + } + + function positions(bytes32 arg0) + external returns (uint128, uint256, uint256, uint128, uint128) { + return positions[arg0].liquidity, positions[arg0].feeGrowthInside0LastX128, + positions[arg0].feeGrowthInside1LastX128, positions[arg0].tokensOwed0, + positions[arg0].tokensOwed1; + } + + function protocolFees() external returns (uint128, uint128) { + return protocolFees.token0, protocolFees.token1; + } + + function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external { + require(slot0.unlocked); + slot0.unlocked = false; + ${onlyFactoryOwner v} + require((feeProtocol0 == 0 || (feeProtocol0 >= 4 && feeProtocol0 <= 10)) && + (feeProtocol1 == 0 || (feeProtocol1 >= 4 && feeProtocol1 <= 10))); + uint8 feeProtocolOld = slot0.feeProtocol; + slot0.feeProtocol = feeProtocol0 + (feeProtocol1 << 4); + slot0.unlocked = true; + } + + function slot0() external returns (uint160, int24, uint16, uint16, uint16, uint8, bool) { + return slot0.sqrtPriceX96, slot0.tick, slot0.observationIndex, + slot0.observationCardinality, slot0.observationCardinalityNext, slot0.feeProtocol, + slot0.unlocked; + } + + function snapshotCumulativesInside(int24 tickLower, int24 tickUpper) + external returns (int56, uint160, uint32) { + require(this == ${addrLit v.original}); + require(tickLower < tickUpper); + require(tickLower >= #(-887272)); + require(tickUpper <= 887272); + Tick.Info storage lower = ticks[tickLower]; + Tick.Info storage upper = ticks[tickUpper]; + require(${vf "lower" "initialized"}); + require(${vf "upper" "initialized"}); + if (slot0.tick < tickLower) { + return ${int56Wrap (subE (vf "lower" "tickCumulativeOutside") + (vf "upper" "tickCumulativeOutside"))}, + (${vf "lower" "secondsPerLiquidityOutsideX128"} - + ${vf "upper" "secondsPerLiquidityOutsideX128"}) % #(2 ^ 160), + (${vf "lower" "secondsOutside"} - ${vf "upper" "secondsOutside"}) % #(2 ^ 32); + } + if (slot0.tick < tickUpper) { + uint32 time = block.timestamp % #(2 ^ 32); + var currentObservation = observeSingle(time, 0, slot0.tick, slot0.observationIndex, + liquidity, slot0.observationCardinality); + return ${int56Wrap (subE (subE (tuple0 (.var "currentObservation")) + (vf "lower" "tickCumulativeOutside")) + (vf "upper" "tickCumulativeOutside"))}, + (currentObservation.1 - ${vf "lower" "secondsPerLiquidityOutsideX128"} - + ${vf "upper" "secondsPerLiquidityOutsideX128"}) % #(2 ^ 160), + (time - ${vf "lower" "secondsOutside"} - ${vf "upper" "secondsOutside"}) % #(2 ^ 32); + } else { + return ${int56Wrap (subE (vf "upper" "tickCumulativeOutside") + (vf "lower" "tickCumulativeOutside"))}, + (${vf "upper" "secondsPerLiquidityOutsideX128"} - + ${vf "lower" "secondsPerLiquidityOutsideX128"}) % #(2 ^ 160), + (${vf "upper" "secondsOutside"} - ${vf "lower" "secondsOutside"}) % #(2 ^ 32); + } + } + + function swap(address recipient, bool zeroForOne, int256 amountSpecified, + uint160 sqrtPriceLimitX96, bytes data) external returns (int256, int256) { + require(this == ${addrLit v.original}); + require(amountSpecified != 0); + uint160 slot0StartSqrtPriceX96 = slot0.sqrtPriceX96; + int24 slot0StartTick = slot0.tick; + uint16 slot0StartObservationIndex = slot0.observationIndex; + uint16 slot0StartObservationCardinality = slot0.observationCardinality; + uint16 slot0StartObservationCardinalityNext = slot0.observationCardinalityNext; + uint8 slot0StartFeeProtocol = slot0.feeProtocol; + bool slot0StartUnlocked = slot0.unlocked; + require(slot0StartUnlocked); + require(zeroForOne ? + sqrtPriceLimitX96 < slot0StartSqrtPriceX96 && sqrtPriceLimitX96 > 4295128739 : + sqrtPriceLimitX96 > slot0StartSqrtPriceX96 && + sqrtPriceLimitX96 < 1461446703485210103287273052203988822378723970342); + slot0.unlocked = false; + uint128 cacheLiquidityStart = liquidity; + uint32 cacheBlockTimestamp = block.timestamp % #(2 ^ 32); + uint8 cacheFeeProtocol = zeroForOne ? + slot0StartFeeProtocol % 16 : slot0StartFeeProtocol >> 4; + uint160 cacheSecondsPerLiquidityCumulativeX128 = 0; + int56 cacheTickCumulative = 0; + bool cacheComputedLatestObservation = false; + bool exactInput = amountSpecified > 0; + int256 stateAmountSpecifiedRemaining = amountSpecified; + int256 stateAmountCalculated = 0; + uint160 stateSqrtPriceX96 = slot0StartSqrtPriceX96; + int24 stateTick = slot0StartTick; + uint256 stateFeeGrowthGlobalX128 = zeroForOne ? + feeGrowthGlobal0X128 : feeGrowthGlobal1X128; + uint128 stateProtocolFee = 0; + uint128 stateLiquidity = cacheLiquidityStart; + while (stateAmountSpecifiedRemaining != 0 && stateSqrtPriceX96 != sqrtPriceLimitX96) { + uint160 stepSqrtPriceStartX96 = stateSqrtPriceX96; + var nextTick = tickBitmapNextInitializedTickWithinOneWord(stateTick, #(v.tickSpacing), + zeroForOne); + int24 stepTickNext = nextTick.0; + bool stepInitialized = nextTick.1; + if (stepTickNext < #(-887272)) { + stepTickNext = #(-887272); + } else { + if (stepTickNext > 887272) { + stepTickNext = 887272; + } + } + var stepSqrtPriceNextX96 = getSqrtRatioAtTick(stepTickNext); + uint160 stepTargetSqrtPriceX96 = + (zeroForOne ? stepSqrtPriceNextX96 < sqrtPriceLimitX96 : + stepSqrtPriceNextX96 > sqrtPriceLimitX96) ? + sqrtPriceLimitX96 : stepSqrtPriceNextX96; + var stepResult = computeSwapStep(stateSqrtPriceX96, stepTargetSqrtPriceX96, + stateLiquidity, stateAmountSpecifiedRemaining, #(v.fee)); + stateSqrtPriceX96 = stepResult.0; + uint256 stepAmountIn = stepResult.1; + uint256 stepAmountOut = stepResult.2; + uint256 stepFeeAmount = stepResult.3; + if (exactInput) { + stateAmountSpecifiedRemaining = + (stateAmountSpecifiedRemaining - ((stepAmountIn + stepFeeAmount) as int256)) + as int256; + stateAmountCalculated = + (stateAmountCalculated - ((stepAmountOut) as int256)) as int256; + } else { + stateAmountSpecifiedRemaining = + (stateAmountSpecifiedRemaining + ((stepAmountOut) as int256)) as int256; + stateAmountCalculated = + (stateAmountCalculated + ((stepAmountIn + stepFeeAmount) as int256)) as int256; + } + if (cacheFeeProtocol > 0) { + uint256 protocolDelta = stepFeeAmount / cacheFeeProtocol; + stepFeeAmount = stepFeeAmount - protocolDelta; + stateProtocolFee = (stateProtocolFee + protocolDelta % #(2 ^ 128)) % #(2 ^ 128); + } + if (stateLiquidity > 0) { + require(stateLiquidity > 0); + uint256 feeGrowthGlobalDelta = stepFeeAmount * #(2 ^ 128) / stateLiquidity; + require(feeGrowthGlobalDelta <= type(uint256).max); + stateFeeGrowthGlobalX128 = + (stateFeeGrowthGlobalX128 + feeGrowthGlobalDelta) % #(2 ^ 256); + } + if (stateSqrtPriceX96 == stepSqrtPriceNextX96) { + if (stepInitialized) { + if (!cacheComputedLatestObservation) { + var latestObservation = observeSingle(cacheBlockTimestamp, 0, slot0StartTick, + slot0StartObservationIndex, cacheLiquidityStart, + slot0StartObservationCardinality); + cacheTickCumulative = latestObservation.0; + cacheSecondsPerLiquidityCumulativeX128 = latestObservation.1; + cacheComputedLatestObservation = true; + } + var liquidityNetCross = tickCross(stepTickNext, + zeroForOne ? stateFeeGrowthGlobalX128 : feeGrowthGlobal0X128, + zeroForOne ? feeGrowthGlobal1X128 : stateFeeGrowthGlobalX128, + cacheSecondsPerLiquidityCumulativeX128, cacheTickCumulative, + cacheBlockTimestamp); + int128 liquidityNet = liquidityNetCross; + if (zeroForOne) { + liquidityNet = (0 - liquidityNet) as int128; + } + var stateLiquidityAfterCross = liquidityAddDelta(stateLiquidity, liquidityNet); + stateLiquidity = stateLiquidityAfterCross; + } + stateTick = zeroForOne ? stepTickNext - 1 : stepTickNext; + } else { + if (stateSqrtPriceX96 != stepSqrtPriceStartX96) { + var stateTickUpdated = getTickAtSqrtRatio(stateSqrtPriceX96); + stateTick = stateTickUpdated; + } + } + } + if (stateTick != slot0StartTick) { + var oracleUpdatedAfterSwap = oracleWrite(slot0StartObservationIndex, + cacheBlockTimestamp, slot0StartTick, cacheLiquidityStart, + slot0StartObservationCardinality, slot0StartObservationCardinalityNext); + slot0.sqrtPriceX96 = stateSqrtPriceX96; + slot0.tick = stateTick; + slot0.observationIndex = oracleUpdatedAfterSwap.0; + slot0.observationCardinality = oracleUpdatedAfterSwap.1; + } else { + slot0.sqrtPriceX96 = stateSqrtPriceX96; + } + if (cacheLiquidityStart != stateLiquidity) { + liquidity = stateLiquidity; + } + if (zeroForOne) { + feeGrowthGlobal0X128 = stateFeeGrowthGlobalX128; + if (stateProtocolFee > 0) { + protocolFees.token0 = protocolFees.token0 + stateProtocolFee; + } + } else { + feeGrowthGlobal1X128 = stateFeeGrowthGlobalX128; + if (stateProtocolFee > 0) { + protocolFees.token1 = protocolFees.token1 + stateProtocolFee; + } + } + int256 amount0 = 0; + int256 amount1 = 0; + if (zeroForOne == exactInput) { + amount0 = (amountSpecified - stateAmountSpecifiedRemaining) as int256; + amount1 = stateAmountCalculated; + } else { + amount0 = stateAmountCalculated; + amount1 = (amountSpecified - stateAmountSpecifiedRemaining) as int256; + } + if (zeroForOne) { + if (amount1 < 0) { + ${safeTransfer (addrLit v.token1) (.var "recipient") + (uint256Wrap (subE (.intLit 0) (.var "amount1"))) "swapTransfer1"} + } + ${balanceOfInto (addrLit v.token0) "balance0Before" "swapBalance0Before"} + var _swapCallback = msg.sender.uniswapV3SwapCallback{value: 0}(amount0, amount1, data); + ${balanceOfInto (addrLit v.token0) "balance0After" "swapBalance0After"} + ${checkedWordAddLe (.var "balance0Before") (uint256Wrap (.var "amount0")) + (.var "balance0After")} + } else { + if (amount0 < 0) { + ${safeTransfer (addrLit v.token0) (.var "recipient") + (uint256Wrap (subE (.intLit 0) (.var "amount0"))) "swapTransfer0"} + } + ${balanceOfInto (addrLit v.token1) "balance1Before" "swapBalance1Before"} + var _swapCallback = msg.sender.uniswapV3SwapCallback{value: 0}(amount0, amount1, data); + ${balanceOfInto (addrLit v.token1) "balance1After" "swapBalance1After"} + ${checkedWordAddLe (.var "balance1Before") (uint256Wrap (.var "amount1")) + (.var "balance1After")} + } + slot0.unlocked = true; + return amount0, amount1; + } -def constructorDeclSyntax : ConstructorDecl := Benchmarks.UniswapV3Pool.constructorDecl + function tickBitmap(int16 arg0) external returns (uint256) { + return tickBitmap[arg0]; + } -def transitionsSyntax (v : PoolImmutables) : List TransitionDecl := - Benchmarks.UniswapV3Pool.transitions v + function tickSpacing() external returns (int24) { + return #(v.tickSpacing); + } -def functionsSyntax (v : PoolImmutables) : List FunctionDecl := - Benchmarks.UniswapV3Pool.functions v + function ticks(int24 arg0) + external returns (uint128, int128, uint256, uint256, int56, uint160, uint32, bool) { + return ticks[arg0].liquidityGross, ticks[arg0].liquidityNet, + ticks[arg0].feeGrowthOutside0X128, ticks[arg0].feeGrowthOutside1X128, + ticks[arg0].tickCumulativeOutside, ticks[arg0].secondsPerLiquidityOutsideX128, + ticks[arg0].secondsOutside, ticks[arg0].initialized; + } -def contractSyntax (v : PoolImmutables) : ContractDecl := - { name := "UniswapV3Pool" - storage := storageDeclsSyntax - ctor := constructorDeclSyntax - structs := Benchmarks.UniswapV3Pool.structs - functions := functionsSyntax v - transitions := transitionsSyntax v } + function token0() external returns (address) { + return ${addrLit v.token0}; + } -theorem storageDeclsSyntax_eq : storageDeclsSyntax = Benchmarks.UniswapV3Pool.storageDecls := by - rfl + function token1() external returns (address) { + return ${addrLit v.token1}; + } +} theorem contractSyntax_eq (v : PoolImmutables) : - contractSyntax v = Benchmarks.UniswapV3Pool.contract v := by - rfl + contractSyntax v = contract v := by rfl end Benchmarks.UniswapV3Pool.Syntax diff --git a/Benchmarks/UniswapV3Pool/TickBitmap.lean b/Benchmarks/UniswapV3Pool/TickBitmap.lean index ba3d271b..43fc0040 100644 --- a/Benchmarks/UniswapV3Pool/TickBitmap.lean +++ b/Benchmarks/UniswapV3Pool/TickBitmap.lean @@ -112,7 +112,7 @@ private theorem nat_lor_high_mask_15 (n : Nat) (hn : n < 2 ^ 256) : rw [Nat.testBit_or, Nat.testBit_or] rw [show (2 ^ (256 - 15) - 1) * 2 ^ 15 = (2 ^ (256 - 15) - 1) <<< 15 by rw [Nat.shiftLeft_eq]] - rw [nat_testBit_shiftLeft] + rw [testBit_shiftLeft] by_cases hi15 : i < 15 · rw [if_pos hi15] conv_rhs => rw [Nat.testBit_mod_two_pow] diff --git a/Benchmarks/UniswapV3Pool/TickSpacing.lean b/Benchmarks/UniswapV3Pool/TickSpacing.lean index b348e037..ec3ca0bc 100644 --- a/Benchmarks/UniswapV3Pool/TickSpacing.lean +++ b/Benchmarks/UniswapV3Pool/TickSpacing.lean @@ -92,7 +92,7 @@ private theorem nat_lor_high_mask_23 (n : Nat) (hn : n < 2 ^ 256) : rw [Nat.testBit_or, Nat.testBit_or] rw [show (2 ^ (256 - 23) - 1) * 2 ^ 23 = (2 ^ (256 - 23) - 1) <<< 23 by rw [Nat.shiftLeft_eq]] - rw [nat_testBit_shiftLeft] + rw [testBit_shiftLeft] by_cases hi23 : i < 23 · rw [if_pos hi23] conv_rhs => rw [Nat.testBit_mod_two_pow] diff --git a/Benchmarks/UniswapV3Pool/TicksInt128.lean b/Benchmarks/UniswapV3Pool/TicksInt128.lean index d9b6440e..7d1972a5 100644 --- a/Benchmarks/UniswapV3Pool/TicksInt128.lean +++ b/Benchmarks/UniswapV3Pool/TicksInt128.lean @@ -99,7 +99,7 @@ private theorem nat_lor_high_mask_127 (n : Nat) (hn : n < 2 ^ 256) : rw [Nat.testBit_or, Nat.testBit_or] rw [show (2 ^ (256 - 127) - 1) * 2 ^ 127 = (2 ^ (256 - 127) - 1) <<< 127 by rw [Nat.shiftLeft_eq]] - rw [nat_testBit_shiftLeft] + rw [testBit_shiftLeft] by_cases hi55 : i < 127 · rw [if_pos hi55] conv_rhs => rw [Nat.testBit_mod_two_pow] diff --git a/Benchmarks/WETH9/Allowance.lean b/Benchmarks/WETH9/Allowance.lean index bd1c80b8..f01475cc 100644 --- a/Benchmarks/WETH9/Allowance.lean +++ b/Benchmarks/WETH9/Allowance.lean @@ -242,7 +242,7 @@ theorem weth9AllowanceBodyCoreOk {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt25 |>.iszero (by native_decide) (by simp) |>.push2 ⟨736⟩ (by native_decide) (by simp) |>.jumpiNT (by native_decide) (by rw [hltShort]; decide) (by simp) - |>.uniswapPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) + |>.solcPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) exact weth9ReEquivDecodeFailed hcode hrev hdisp (weth9Decode_allowance_none_short hsz4 hsz) /-- `allowance(address,address)` body refines its Solm transition (both callvalue branches). -/ diff --git a/Benchmarks/WETH9/Approve.lean b/Benchmarks/WETH9/Approve.lean index 98d65044..5d96e5ce 100644 --- a/Benchmarks/WETH9/Approve.lean +++ b/Benchmarks/WETH9/Approve.lean @@ -502,7 +502,7 @@ theorem weth9ApproveBodyCoreDecodeFailed_short {cA gh bl σ_evm σ_solm σ₀ A |>.iszero (by native_decide) (by simp) |>.push2 ⟨339⟩ (by native_decide) (by simp) |>.jumpiNT (by native_decide) (by rw [hltShort]; decide) (by simp) - |>.uniswapPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) + |>.solcPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) exact weth9ReEquivDecodeFailed hcode hrev (weth9SelectorDispatchApprove hsel) (weth9Decode_approve_none_short hsz4 hshort) diff --git a/Benchmarks/WETH9/BalanceOf.lean b/Benchmarks/WETH9/BalanceOf.lean index 7fd3379e..e655cbc3 100644 --- a/Benchmarks/WETH9/BalanceOf.lean +++ b/Benchmarks/WETH9/BalanceOf.lean @@ -216,7 +216,7 @@ theorem weth9BalanceOfBodyCoreOk {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt25 |>.iszero (by native_decide) (by simp) |>.push2 ⟨607⟩ (by native_decide) (by simp) |>.jumpiNT (by native_decide) (by rw [hltShort]; decide) (by simp) - |>.uniswapPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) + |>.solcPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) exact weth9ReEquivDecodeFailed hcode hrev hdisp (weth9Decode_balanceOf_none_short hsz4 hsz) /-- `balanceOf(address)` body refines its Solm transition (handling both callvalue branches). -/ diff --git a/Benchmarks/WETH9/Routines.lean b/Benchmarks/WETH9/Routines.lean index 1bb95c92..550c57bb 100644 --- a/Benchmarks/WETH9/Routines.lean +++ b/Benchmarks/WETH9/Routines.lean @@ -74,7 +74,7 @@ theorem weth9GuardPeelRev {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s |>.iszero hd3 (by simp) |>.pushConst gt (op := .PUSH2) (width := 2) (by simp) hd4 (by simp) |>.jumpiNT hd7 hcond (by simp) - |>.uniswapPush1Dup1Revert0 hd8 hd10 hd11 (by simp) + |>.solcPush1Dup1Revert0 hd8 hd10 hd11 (by simp) /-- Combined nested-mapping getter (chains the library inner-hash / outer-hash / load-and-jump). LIBRARY CANDIDATE: `Reasoning.Solc` — the nested analogue of `RD.solcSingleMappingGetter`. -/ diff --git a/Benchmarks/WETH9/SpecSyntax.lean b/Benchmarks/WETH9/SpecSyntax.lean index a28f6d13..4bed449c 100644 --- a/Benchmarks/WETH9/SpecSyntax.lean +++ b/Benchmarks/WETH9/SpecSyntax.lean @@ -2,175 +2,98 @@ import Benchmarks.WETH9.Spec import Solm.Notation /-! -# WETH9 spec through the Solm notation frontend - -This file presents the same WETH9 benchmark spec using `Solm.Notation` where the current frontend -covers the construct. The few constructs outside the frontend today (`lowLevelCall`, `internalCall`, -`if`, `selfbalance`, and byte-string literals) are written as AST nodes locally. - -The final `by rfl` theorem checks that this surface presentation desugars to exactly the AST spec in -`Benchmarks/WETH9/Spec.lean`. +# WETH9 spec in the Solidity-faithful Solm frontend + +The whole WETH9 benchmark spec, written with `solidity%` and proven definitionally equal to the +AST spec in `Benchmarks/WETH9/Spec.lean`. + +Notes mirroring the AST spec: +* WETH9.sol has no explicit constructor; solc emits a non-payable implicit one that only runs the + field initializers — written here as a non-payable `constructor()` with the assignments. +* The payable Solidity fallback is the deposit body. +* `transfer` forwards through the public `transferFrom` (an internal dispatch, hence the + explicitly bound `var _ok = transferFrom(…)`). +* Transition order matches `contract.transitions` exactly. -/ open Solm Solm.Notation namespace Benchmarks.WETH9.Syntax -def storageDeclsSyntax : List StorageDecl := - [ { name := "name", ty := .string }, - { name := "symbol", ty := .string } ] ++ - sState% { - uint8 decimals - (address => uint256) balanceOf - (address => (address => uint256)) allowance +def contractSyntax : ContractDecl := solidity% contract WETH9 { + string name; + string symbol; + uint8 decimals; + mapping(address => uint256) balanceOf; + mapping(address => mapping(address => uint256)) allowance; + + constructor() { + name = "Wrapped Ether"; + symbol = "WETH"; + decimals = 18; + } + + function name() external returns (string) { + return name; + } + + function approve(address guy, uint256 wad) external returns (bool) { + allowance[msg.sender][guy] = wad; + return true; + } + + function totalSupply() external returns (uint256) { + return address(this).balance; + } + + function transferFrom(address src, address dst, uint256 wad) external returns (bool) { + require(balanceOf[src] >= wad); + if (src != msg.sender && allowance[src][msg.sender] != type(uint256).max) { + require(allowance[src][msg.sender] >= wad); + allowance[src][msg.sender] = allowance[src][msg.sender] - wad; + } + balanceOf[src] = balanceOf[src] - wad; + balanceOf[dst] = balanceOf[dst] + wad; + return true; + } + + function withdraw(uint256 wad) external { + require(balanceOf[msg.sender] >= wad); + balanceOf[msg.sender] = balanceOf[msg.sender] - wad; + (bool success, bytes memory _data) = msg.sender.call{value: wad}(new bytes(0)); + require(success); + } + + function decimals() external returns (uint8) { + return decimals; + } + + function balanceOf(address owner) external returns (uint256) { + return balanceOf[owner]; } -def constructorDeclSyntax : ConstructorDecl := - { params := [] - body := - sBlock% { - require msg.value == 0 - } ++ - [ .assign .storage nameRef (.bytesLit (String.toByteArray "Wrapped Ether")), - .assign .storage symbolRef (.bytesLit (String.toByteArray "WETH")), - .assign .storage decimalsRef (.intLit 18) ] } - -def nameTransitionSyntax : TransitionDecl := - { name := "name" - params := [] - returnType := [stringTy] - body := sBlock% { - require msg.value == 0 - } ++ [ .return [.storage nameRef] ] } - -def symbolTransitionSyntax : TransitionDecl := - { name := "symbol" - params := [] - returnType := [stringTy] - body := sBlock% { - require msg.value == 0 - } ++ [ .return [.storage symbolRef] ] } - -def decimalsTransitionSyntax : TransitionDecl := - solm_transition decimals -> uint8 { - require msg.value == 0 - return @decimals + function symbol() external returns (string) { + return symbol; } -def balanceOfTransitionSyntax : TransitionDecl := - solm_transition balanceOf (owner : address) -> uint256 { - require msg.value == 0 - return @balanceOf[owner] + function transfer(address dst, uint256 wad) external returns (bool) { + var _ok = transferFrom(msg.sender, dst, wad); + return _ok; } -def allowanceTransitionSyntax : TransitionDecl := - solm_transition allowance (owner : address) (guy : address) -> uint256 { - require msg.value == 0 - return @allowance[owner][guy] + function deposit() external payable { + balanceOf[msg.sender] = balanceOf[msg.sender] + msg.value; } -def depositTransitionSyntax : TransitionDecl := - solm_transition deposit { - @balanceOf[msg.sender] := @balanceOf[msg.sender] + msg.value + function allowance(address owner, address guy) external returns (uint256) { + return allowance[owner][guy]; } -def fallbackTransitionSyntax : TransitionDecl := - { name := "fallback" - params := [] - returnType := [] - body := depositTransitionSyntax.body } - -def withdrawTransitionSyntax : TransitionDecl := - { name := "withdraw" - params := [{ name := "wad", ty := uint256 }] - returnType := [] - body := - sBlock% { - require msg.value == 0 - require @balanceOf[msg.sender] >= wad - @balanceOf[msg.sender] := @balanceOf[msg.sender] - wad - } ++ - [ .lowLevelCall sender (.var "wad") emptyBytes "success" "_data" ] ++ - sBlock% { - require success - } } - -def totalSupplyTransitionSyntax : TransitionDecl := - { name := "totalSupply" - params := [] - returnType := [uint256] - body := sBlock% { - require msg.value == 0 - } ++ [ .return [.env .selfbalance] ] } - -def approveTransitionSyntax : TransitionDecl := - solm_transition approve (guy : address) (wad : uint256) -> bool { - require msg.value == 0 - @allowance[msg.sender][guy] := wad - return true + fallback() external payable { + balanceOf[msg.sender] = balanceOf[msg.sender] + msg.value; } +} -def transferTransitionSyntax : TransitionDecl := - { name := "transfer" - params := [{ name := "dst", ty := addr }, { name := "wad", ty := uint256 }] - returnType := [boolTy] - body := sBlock% { - require msg.value == 0 - } ++ - [ .internalCall "transferFrom" [sender, .var "dst", .var "wad"] "_ok" ] ++ - sBlock% { - return _ok - } } - -def transferFromTransitionSyntax : TransitionDecl := - { name := "transferFrom" - params := - [ { name := "src", ty := addr }, { name := "dst", ty := addr }, - { name := "wad", ty := uint256 } ] - returnType := [boolTy] - body := - sBlock% { - require msg.value == 0 - require @balanceOf[src] >= wad - } ++ - [ .ite - (.binary .and - (.binary .ne (.var "src") sender) - (.binary .ne (.storage (allowanceRef (.var "src") sender)) (.intLit maxUint256))) - (sBlock% { - require @allowance[src][msg.sender] >= wad - @allowance[src][msg.sender] := @allowance[src][msg.sender] - wad - }) - [] ] ++ - sBlock% { - @balanceOf[src] := @balanceOf[src] - wad - @balanceOf[dst] := @balanceOf[dst] + wad - return true - } } - -def contractSyntax : ContractDecl := - { name := "WETH9" - storage := storageDeclsSyntax - ctor := constructorDeclSyntax - functions := [] - transitions := - [ nameTransitionSyntax, - approveTransitionSyntax, - totalSupplyTransitionSyntax, - transferFromTransitionSyntax, - withdrawTransitionSyntax, - decimalsTransitionSyntax, - balanceOfTransitionSyntax, - symbolTransitionSyntax, - transferTransitionSyntax, - depositTransitionSyntax, - allowanceTransitionSyntax ] - fallback := some fallbackTransitionSyntax } - -theorem storageDeclsSyntax_eq : storageDeclsSyntax = Benchmarks.WETH9.storageDecls := by - rfl - -theorem contractSyntax_eq : contractSyntax = Benchmarks.WETH9.contract := by - rfl +theorem contractSyntax_eq : contractSyntax = Benchmarks.WETH9.contract := by rfl end Benchmarks.WETH9.Syntax diff --git a/Benchmarks/WETH9/Transfer.lean b/Benchmarks/WETH9/Transfer.lean index c998c01f..eb8356a6 100644 --- a/Benchmarks/WETH9/Transfer.lean +++ b/Benchmarks/WETH9/Transfer.lean @@ -551,7 +551,7 @@ theorem weth9TransferDecodeFailRev {cA gh bl σ σ₀ A I} {g : Sat256} |>.iszero (by native_decide) (by simp) |>.push2 ⟨679⟩ (by native_decide) (by simp) |>.jumpiNT (by native_decide) (by rw [hltShort]; decide) (by simp) - |>.uniswapPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) + |>.solcPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) /-- `transfer(address,uint256)` body refines its Solm transition. -/ theorem weth9TransferBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} diff --git a/Benchmarks/WETH9/TransferFrom.lean b/Benchmarks/WETH9/TransferFrom.lean index e9a2a420..be27520f 100644 --- a/Benchmarks/WETH9/TransferFrom.lean +++ b/Benchmarks/WETH9/TransferFrom.lean @@ -242,7 +242,7 @@ theorem weth9TFDecodeFailRev {cA gh bl σ σ₀ A I} {g : Sat256} |>.iszero (by native_decide) (by simp) |>.pushConst (⟨455⟩ : UInt256) (op := .PUSH2) (width := 2) (by decide) (by native_decide) (by simp) |>.jumpiNT (by native_decide) (by rw [hltShort]; decide) (by simp) - |>.uniswapPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) + |>.solcPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) theorem weth9TransferFromBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (hcode : I.code = weth9Bytecode) (hsize : I.calldata.size < UInt256.size) diff --git a/Benchmarks/WETH9/TransferFromBody.lean b/Benchmarks/WETH9/TransferFromBody.lean index 1cb860fa..8df9a18b 100644 --- a/Benchmarks/WETH9/TransferFromBody.lean +++ b/Benchmarks/WETH9/TransferFromBody.lean @@ -125,7 +125,7 @@ theorem weth9TFReqBalanceRev {ee g s0 rdata cA σ k C} {src dst wad ret : UInt25 |>.pushConst (⟨1124⟩ : UInt256) (op := .PUSH2) (width := 2) (by decide) (by native_decide) (by simp only [List.length_cons]; omega) |>.jumpiNT (by native_decide) (by rw [ugt_one hlt]; decide) (by simp only [List.length_cons]; omega) - |>.uniswapPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) + |>.solcPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) /-- Branch, case `src == msg.sender` (pc 1124 → 1282): the `EQ msg.sender` short-circuits the @@ -513,7 +513,7 @@ theorem weth9TFBranchSpendRev {ee g s0 rdata cA σ k C} {src dst wad ret : UInt2 |>.pushConst (⟨1239⟩ : UInt256) (op := .PUSH2) (width := 2) (by decide) (by native_decide) (by simp only [List.length_cons]; omega) |>.jumpiNT (by native_decide) (by rw [ugt_one hlt]; decide) (by simp only [List.length_cons]; omega) - |>.uniswapPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) + |>.solcPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) /-- `balanceOf[src]` after the debit `-= wad` (wrapping). -/ diff --git a/Benchmarks/WETH9/WithdrawBody.lean b/Benchmarks/WETH9/WithdrawBody.lean index d3cbded6..15e6f841 100644 --- a/Benchmarks/WETH9/WithdrawBody.lean +++ b/Benchmarks/WETH9/WithdrawBody.lean @@ -308,7 +308,7 @@ theorem weth9WithdrawDecodeRev {cA gh bl σ σ₀ A I} {g : Sat256} |>.iszero (by native_decide) (by simp) |>.push2 ⟨522⟩ (by native_decide) (by simp) |>.jumpiNT (by native_decide) (by rw [hltShort]; decide) (by simp) - |>.uniswapPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) + |>.solcPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) /-- `callvalue = 0`, `size ≥ 36`: reach the body entry (pc 1395) with `[wad, 164, sel]`. -/ theorem weth9WithdrawReachBody {cA gh bl σ σ₀ A I} {g : Sat256} @@ -400,7 +400,7 @@ theorem weth9WithdrawRequireRev {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} ugt_one (by omega) exact h1415.push2 ⟨1423⟩ (by native_decide) (by simp) |>.jumpiNT (by native_decide) (by rw [hgt]; decide) (by simp) - |>.uniswapPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) + |>.solcPush1Dup1Revert0 (by native_decide) (by native_decide) (by native_decide) (by simp) /-- `bal ≥ wad`: pass the require, re-keccak, `balanceOf[caller] -= wad` (`SSTORE`), reaching the `CALL` setup (pc 1447) with the mapping-hash memory and the decremented balance. -/ diff --git a/EquiVM.lean b/EquiVM.lean index 9bf09cb6..3d0bc594 100644 --- a/EquiVM.lean +++ b/EquiVM.lean @@ -11,7 +11,6 @@ import Reasoning.Memory import Reasoning.Reach import Reasoning.Refinement import Reasoning.Solc -import Reasoning.SolcDecode import Reasoning.SolmBody import Reasoning.Stepping import Reasoning.Storage diff --git a/Examples/Ballot/SpecSyntax.lean b/Examples/Ballot/SpecSyntax.lean new file mode 100644 index 00000000..5f0ef3d4 --- /dev/null +++ b/Examples/Ballot/SpecSyntax.lean @@ -0,0 +1,114 @@ +import Examples.Ballot.Spec +import Solm.Notation + +/-! +# Ballot spec in the Solidity-faithful Solm frontend + +The whole Ballot spec (structs, storage aliases, delegation-chain `while`, both `for` loops, and +the auto-generated public getters), written with `solidity%` and proven definitionally equal to +the AST spec in `Examples/Ballot/Spec.lean`. + +`to` is a Lean keyword, so the `delegate(address to)` parameter is written `«to»`. +Transition order matches `ballotContract.transitions` (selector order). +-/ + +open Solm Solm.Notation + +namespace Ballot.Syntax + +def contractSyntax : ContractDecl := solidity% contract Ballot { + struct Voter { + uint256 weight; + bool voted; + address delegate; + uint256 vote; + } + + struct Proposal { + bytes32 name; + uint256 voteCount; + } + + address chairperson; + mapping(address => Voter) voters; + Proposal[] proposals; + + constructor(bytes32[] memory proposalNames) { + chairperson = msg.sender; + voters[chairperson].weight = 1; + for (uint256 i = 0; i < proposalNames.length; i++) { + proposals.push(Proposal({name: proposalNames[i], voteCount: 0})); + } + } + + function vote(uint256 proposal) external { + Voter storage sender = voters[msg.sender]; + require(sender.weight != 0); + require(!sender.voted); + sender.voted = true; + sender.vote = proposal; + proposals[proposal].voteCount = + (proposals[proposal].voteCount + sender.weight) as uint256; + } + + function proposals(uint256 i) external returns (bytes32, uint256) { + return (proposals[i].name, proposals[i].voteCount); + } + + function chairperson() external returns (address) { + return chairperson; + } + + function delegate(address «to») external { + Voter storage sender = voters[msg.sender]; + require(sender.weight != 0); + require(!sender.voted); + require(«to» != msg.sender); + while (voters[«to»].delegate != address(0)) { + «to» = voters[«to»].delegate; + require(«to» != msg.sender); + } + Voter storage delegate_ = voters[«to»]; + require(delegate_.weight >= 1); + sender.voted = true; + sender.delegate = «to»; + if (delegate_.voted) { + proposals[delegate_.vote].voteCount = + (proposals[delegate_.vote].voteCount + sender.weight) as uint256; + } else { + delegate_.weight = (delegate_.weight + sender.weight) as uint256; + } + } + + function winningProposal() external returns (uint256) { + uint256 winningProposal_ = 0; + uint256 winningVoteCount = 0; + for (uint256 p = 0; p < proposals.length; p++) { + if (proposals[p].voteCount > winningVoteCount) { + winningVoteCount = proposals[p].voteCount; + winningProposal_ = p; + } + } + return winningProposal_; + } + + function giveRightToVote(address voter) external { + require(msg.sender == chairperson); + require(!voters[voter].voted); + require(voters[voter].weight == 0); + voters[voter].weight = 1; + } + + function voters(address a) external returns (uint256, bool, address, uint256) { + return (voters[a].weight, voters[a].voted, voters[a].delegate, voters[a].vote); + } + + function winnerName() external returns (bytes32) { + var w = winningProposal(); + return proposals[w].name; + } +} + +theorem contractSyntax_eq : contractSyntax = Ballot.ballotContract := by rfl + +end Ballot.Syntax diff --git a/Examples/BlindAuction/SpecSyntax.lean b/Examples/BlindAuction/SpecSyntax.lean new file mode 100644 index 00000000..d89714d5 --- /dev/null +++ b/Examples/BlindAuction/SpecSyntax.lean @@ -0,0 +1,135 @@ +import Examples.BlindAuction.Spec +import Solm.Notation + +/-! +# BlindAuction spec in the Solidity-faithful Solm frontend + +Covers the mapping-to-struct-array `push`, the storage alias inside `reveal`'s loop, the +`keccak256(abi.encodePacked(…))` guard (packed operands carry their ABI types as `T(e)` +annotations), the internal `placeBid` helper, and the two-key `bids(address,uint256)` getter. + +One escape: the AST spec models `bidToCheck.blindedBid = bytes32(0)` as a *cast* +(`.cast (.intLit 0) bytes32St`), while surface `bytes32(0)` is the fixed-bytes literal — so that +single right-hand side is written with `${…}`. +-/ + +open Solm Solm.Notation + +namespace BlindAuction.Syntax + +def contractSyntax : ContractDecl := solidity% contract BlindAuction { + struct Bid { + bytes32 blindedBid; + uint256 deposit; + } + + address beneficiary; + uint256 biddingEnd; + uint256 revealEnd; + bool ended; + mapping(address => Bid[]) bids; + address highestBidder; + uint256 highestBid; + mapping(address => uint256) pendingReturns; + + constructor(uint256 biddingTime, uint256 revealTime, address beneficiaryAddress) { + beneficiary = beneficiaryAddress; + biddingEnd = (block.timestamp + biddingTime) as uint256; + revealEnd = (biddingEnd + revealTime) as uint256; + } + + function placeBid(address bidder, uint256 value) internal returns (bool) { + if (value <= highestBid) { + return false; + } + if (highestBidder != address(0)) { + pendingReturns[highestBidder] = (pendingReturns[highestBidder] + highestBid) as uint256; + } + highestBid = value; + highestBidder = bidder; + return true; + } + + function bid(bytes32 blindedBid) external payable { + require(block.timestamp < biddingEnd); + bids[msg.sender].push(Bid({blindedBid: blindedBid, deposit: msg.value})); + } + + function reveal(uint256[] calldata values, bool[] calldata fakes, bytes32[] calldata secrets) external { + require(block.timestamp > biddingEnd); + require(block.timestamp < revealEnd); + uint256 length = bids[msg.sender].length; + require(values.length == length); + require(fakes.length == length); + require(secrets.length == length); + uint256 refund = 0; + for (uint256 i = 0; i < length; i++) { + Bid storage bidToCheck = bids[msg.sender][i]; + uint256 value = values[i]; + bool fake = fakes[i]; + bytes32 secret = secrets[i]; + if (bidToCheck.blindedBid != keccak256(abi.encodePacked(uint256(value), bool(fake), bytes32(secret)))) { + continue; + } + refund = (refund + bidToCheck.deposit) as uint256; + if (!fake && bidToCheck.deposit >= value) { + var ok = placeBid(msg.sender, value); + if (ok) { + refund = (refund - value) as uint256; + } + } + bidToCheck.blindedBid = ${Expr.cast (.intLit 0) BlindAuction.bytes32St}; + } + (bool success, bytes memory _data) = msg.sender.call{value: refund}(new bytes(0)); + require(success); + } + + function withdraw() external { + uint256 amount = pendingReturns[msg.sender]; + if (amount > 0) { + pendingReturns[msg.sender] = 0; + (bool success, bytes memory _data) = msg.sender.call{value: amount}(new bytes(0)); + require(success); + } + } + + function auctionEnd() external { + require(block.timestamp > revealEnd); + require(!ended); + ended = true; + (bool success, bytes memory _data) = beneficiary.call{value: highestBid}(new bytes(0)); + require(success); + } + + function beneficiary() external returns (address) { + return beneficiary; + } + + function biddingEnd() external returns (uint256) { + return biddingEnd; + } + + function revealEnd() external returns (uint256) { + return revealEnd; + } + + function ended() external returns (bool) { + return ended; + } + + function highestBidder() external returns (address) { + return highestBidder; + } + + function highestBid() external returns (uint256) { + return highestBid; + } + + function bids(address a, uint256 i) external returns (bytes32, uint256) { + return (bids[a][i].blindedBid, bids[a][i].deposit); + } +} + +theorem contractSyntax_eq : contractSyntax = BlindAuction.blindAuctionContract := by rfl + +end BlindAuction.Syntax diff --git a/Examples/Caller/SpecSyntax.lean b/Examples/Caller/SpecSyntax.lean new file mode 100644 index 00000000..93cc5c89 --- /dev/null +++ b/Examples/Caller/SpecSyntax.lean @@ -0,0 +1,32 @@ +import Examples.Caller.Spec +import Solm.Notation + +/-! +# Caller spec in the Solidity-faithful Solm frontend + +The `Caller` contract from `Examples/Caller/Spec.lean` written with `solidity%` and proven +definitionally equal to the AST spec. + +* The spec's constructor body is empty (no non-payable guard), so the surface constructor is + marked `payable` to suppress the auto-inserted guard. +* `t.pow2(n)` is the external call, bound to `tmp` as in the AST. +-/ + +open Solm Solm.Notation + +namespace Caller.Syntax + +def contractSyntax : ContractDecl := solidity% contract Caller { + uint256 stored; + + constructor() payable { } + + function run(address t, uint256 n) external { + var tmp = t.pow2(n); + stored = tmp; + } +} + +theorem contractSyntax_eq : contractSyntax = Caller.callerContract := by rfl + +end Caller.Syntax diff --git a/Examples/CtorStore/SpecSyntax.lean b/Examples/CtorStore/SpecSyntax.lean new file mode 100644 index 00000000..70f84b9c --- /dev/null +++ b/Examples/CtorStore/SpecSyntax.lean @@ -0,0 +1,25 @@ +import Examples.CtorStore.Spec +import Solm.Notation + +/-! +# CtorStore spec in the Solidity-faithful Solm frontend + +The payable constructor stores its `uint256` argument into the private `stored` field; there are +no runtime transitions. +-/ + +open Solm Solm.Notation + +namespace CtorStore.Syntax + +def contractSyntax : ContractDecl := solidity% contract CtorStore { + uint256 stored; + + constructor(uint256 x) payable { + stored = x; + } +} + +theorem contractSyntax_eq : contractSyntax = CtorStore.contract := by rfl + +end CtorStore.Syntax diff --git a/Examples/CtorTruth/SpecSyntax.lean b/Examples/CtorTruth/SpecSyntax.lean new file mode 100644 index 00000000..6854499f --- /dev/null +++ b/Examples/CtorTruth/SpecSyntax.lean @@ -0,0 +1,25 @@ +import Examples.CtorTruth.Spec +import Solm.Notation + +/-! +# CtorTruth spec in the Solidity-faithful Solm frontend + +The spec's constructor is payable with an empty body (no callvalue guard); `truth()` is +non-payable, so its guard is implicit. +-/ + +open Solm Solm.Notation + +namespace CtorTruth.Syntax + +def contractSyntax : ContractDecl := solidity% contract CtorTruth { + constructor() payable { } + + function truth() external returns (bool) { + return true; + } +} + +theorem contractSyntax_eq : contractSyntax = CtorTruth.contract := by rfl + +end CtorTruth.Syntax diff --git a/Examples/ERC20/SpecSugar.lean b/Examples/ERC20/SpecSugar.lean index 2e77c69a..2362c8cb 100644 --- a/Examples/ERC20/SpecSugar.lean +++ b/Examples/ERC20/SpecSugar.lean @@ -2,86 +2,72 @@ import Examples.ERC20.Spec import Solm.Notation /-! -# ERC20 — the same spec, written with the macro-generated Solm frontend +# ERC20 — the same spec, written in the Solidity-faithful Solm frontend This regenerates the entire `ERC20.erc20Contract` (storage, constructor, all six transitions) -using the surface syntax from `Solm.Notation`, then proves the result is **definitionally equal** -to the hand-written AST in `Examples/ERC20/Spec.lean`. - -The `by rfl` at the end is the whole point: the frontend is pure sugar, adding no semantic layer — -every surface form desugars to exactly the constructors the spec author would otherwise type by hand. - -Note `«from»`: `from` is a Lean keyword, so the parameter named `from` is written with guillemet -escaping; `«from».getId.toString = "from"`, so the generated `Expr.var "from"` matches. +using `solidity%` from `Solm.Notation`, then proves the result is **definitionally equal** to the +hand-written AST in `Examples/ERC20/Spec.lean`. + +Notes: +* The non-payable `require(msg.value == 0)` guards are implicit, as in Solidity. +* `from`/`to` are Lean keywords, so those parameter names are guillemet-escaped («from», «to»); + `.getId.toString` still yields `"from"`/`"to"`, so the generated AST strings match. +* Transition order matches `erc20Contract.transitions` exactly (needed for `rfl`). -/ open Solm Solm.Notation namespace ERC20Sugar -def erc20ContractGen : ContractDecl := { - name := "ERC20" +def erc20ContractGen : ContractDecl := solidity% contract ERC20 { + mapping(address => uint256) balanceOf; + mapping(address => mapping(address => uint256)) allowance; + uint256 totalSupply; - storage := sState% { - (address => uint256) balanceOf - (address => (address => uint256)) allowance - uint256 totalSupply + constructor(uint256 initialSupply) { + balanceOf[msg.sender] = initialSupply; + totalSupply = initialSupply; } - ctor := solm_constructor (initialSupply : uint256) { - require msg.value == 0 - @balanceOf[msg.sender] := initialSupply - @totalSupply := initialSupply + function approve(address spender, uint256 value) external returns (bool) { + allowance[msg.sender][spender] = value; + return true; } - -- Order matches `erc20Contract.transitions` exactly (needed for `rfl`). - transitions := [ - solm_transition approve (spender : address) (value : uint256) -> bool { - require msg.value == 0 - @allowance[msg.sender][spender] := value - return true - }, - - solm_transition totalSupply -> uint256 { - require msg.value == 0 - return @totalSupply - }, + function totalSupply() external returns (uint256) { + return totalSupply; + } - solm_transition transferFrom («from» : address) («to» : address) (value : uint256) -> bool { - require msg.value == 0 - let currentAllowance : uint256 := @allowance[«from»][msg.sender] - require currentAllowance >= value - let fromBalance : uint256 := @balanceOf[«from»] - require fromBalance >= value - @allowance[«from»][msg.sender] := currentAllowance - value - @balanceOf[«from»] := (@balanceOf[«from»] - value) as uint256 - let toBalance : uint256 := @balanceOf[«to»] - let newToBalance : uint256 := (toBalance + value) as uint256 - @balanceOf[«to»] := newToBalance - return true - }, + function transferFrom(address «from», address «to», uint256 value) external returns (bool) { + uint256 currentAllowance = allowance[«from»][msg.sender]; + require(currentAllowance >= value); + uint256 fromBalance = balanceOf[«from»]; + require(fromBalance >= value); + allowance[«from»][msg.sender] = currentAllowance - value; + balanceOf[«from»] = (balanceOf[«from»] - value) as uint256; + uint256 toBalance = balanceOf[«to»]; + uint256 newToBalance = (toBalance + value) as uint256; + balanceOf[«to»] = newToBalance; + return true; + } - solm_transition balanceOf (owner : address) -> uint256 { - require msg.value == 0 - return @balanceOf[owner] - }, + function balanceOf(address owner) external returns (uint256) { + return balanceOf[owner]; + } - solm_transition transfer («to» : address) (value : uint256) -> bool { - require msg.value == 0 - let fromBalance : uint256 := @balanceOf[msg.sender] - require fromBalance >= value - @balanceOf[msg.sender] := fromBalance - value - let toBalance : uint256 := @balanceOf[«to»] - let newToBalance : uint256 := (toBalance + value) as uint256 - @balanceOf[«to»] := newToBalance - return true - }, + function transfer(address «to», uint256 value) external returns (bool) { + uint256 fromBalance = balanceOf[msg.sender]; + require(fromBalance >= value); + balanceOf[msg.sender] = fromBalance - value; + uint256 toBalance = balanceOf[«to»]; + uint256 newToBalance = (toBalance + value) as uint256; + balanceOf[«to»] = newToBalance; + return true; + } - solm_transition allowance (owner : address) (spender : address) -> uint256 { - require msg.value == 0 - return @allowance[owner][spender] - } - ] + function allowance(address owner, address spender) external returns (uint256) { + return allowance[owner][spender]; + } } /-- The macro-generated contract is *definitionally* the hand-written one. -/ diff --git a/Examples/OpenZeppelinBench/AccessControl/SpecSyntax.lean b/Examples/OpenZeppelinBench/AccessControl/SpecSyntax.lean new file mode 100644 index 00000000..b70c9567 --- /dev/null +++ b/Examples/OpenZeppelinBench/AccessControl/SpecSyntax.lean @@ -0,0 +1,73 @@ +import Examples.OpenZeppelinBench.AccessControl.Spec +import Solm.Notation + +/-! +# AccessControl spec in the Solidity-faithful Solm frontend + +The OpenZeppelin `AccessControlBench` spec written with `solidity%` and proven definitionally +equal to the AST spec in `Examples/OpenZeppelinBench/AccessControl/Spec.lean`. + +The AST constructor has no callvalue guard, so the surface constructor is marked `payable`. +`bytes32(0)` is the `DEFAULT_ADMIN_ROLE` fixed-bytes literal (defeq to `List.replicate 32 0`). +Transition order matches `contract.transitions` (selector order). +-/ + +open Solm Solm.Notation + +namespace OpenZeppelinBench.AccessControl.Syntax + +def contractSyntax : ContractDecl := solidity% contract AccessControlBench { + struct RoleData { + mapping(address => bool) hasRole; + bytes32 adminRole; + } + + mapping(bytes32 => RoleData) _roles; + + constructor() payable { + _roles[bytes32(0)].hasRole[msg.sender] = true; + } + + function DEFAULT_ADMIN_ROLE() external returns (bytes32) { + return bytes32(0); + } + + function getRoleAdmin(bytes32 role) external returns (bytes32) { + return _roles[role].adminRole; + } + + function grantRole(bytes32 role, address account) external { + bytes32 adminRole = _roles[role].adminRole; + require(_roles[adminRole].hasRole[msg.sender]); + if (!_roles[role].hasRole[account]) { + _roles[role].hasRole[account] = true; + } + } + + function hasRole(bytes32 role, address account) external returns (bool) { + return _roles[role].hasRole[account]; + } + + function renounceRole(bytes32 role, address callerConfirmation) external { + require(callerConfirmation == msg.sender); + if (_roles[role].hasRole[callerConfirmation]) { + _roles[role].hasRole[callerConfirmation] = false; + } + } + + function revokeRole(bytes32 role, address account) external { + bytes32 adminRole = _roles[role].adminRole; + require(_roles[adminRole].hasRole[msg.sender]); + if (_roles[role].hasRole[account]) { + _roles[role].hasRole[account] = false; + } + } + + function supportsInterface(bytes4 interfaceId) external returns (bool) { + return interfaceId == bytes4(0x7965db0b) || interfaceId == bytes4(0x01ffc9a7); + } +} + +theorem contractSyntax_eq : contractSyntax = OpenZeppelinBench.AccessControl.contract := by rfl + +end OpenZeppelinBench.AccessControl.Syntax diff --git a/Examples/OpenZeppelinBench/ERC6909/SpecSyntax.lean b/Examples/OpenZeppelinBench/ERC6909/SpecSyntax.lean new file mode 100644 index 00000000..cc948b31 --- /dev/null +++ b/Examples/OpenZeppelinBench/ERC6909/SpecSyntax.lean @@ -0,0 +1,87 @@ +import Examples.OpenZeppelinBench.ERC6909.Spec +import Solm.Notation + +/-! +# ERC6909 spec in the Solidity-faithful Solm frontend + +The OpenZeppelin `ERC6909Bench` spec written with `solidity%` and proven definitionally equal to +the AST spec in `Examples/OpenZeppelinBench/ERC6909/Spec.lean`. + +The AST constructor has an empty body (no callvalue guard), so the surface constructor is an +empty `payable` one. Transition order matches `contract.transitions` (selector order). +-/ + +open Solm Solm.Notation + +namespace OpenZeppelinBench.ERC6909.Syntax + +def contractSyntax : ContractDecl := solidity% contract ERC6909Bench { + mapping(address => mapping(uint256 => uint256)) _balances; + mapping(address => mapping(address => bool)) _operatorApprovals; + mapping(address => mapping(address => mapping(uint256 => uint256))) _allowances; + + constructor() payable { } + + function allowance(address owner, address spender, uint256 id) external returns (uint256) { + return _allowances[owner][spender][id]; + } + + function approve(address spender, uint256 id, uint256 amount) external returns (bool) { + require(msg.sender != address(0)); + require(spender != address(0)); + _allowances[msg.sender][spender][id] = amount; + return true; + } + + function balanceOf(address owner, uint256 id) external returns (uint256) { + return _balances[owner][id]; + } + + function isOperator(address owner, address spender) external returns (bool) { + return _operatorApprovals[owner][spender]; + } + + function setOperator(address spender, bool approved) external returns (bool) { + require(msg.sender != address(0)); + require(spender != address(0)); + _operatorApprovals[msg.sender][spender] = approved; + return true; + } + + function supportsInterface(bytes4 interfaceId) external returns (bool) { + return interfaceId == bytes4(0x0f632fb3) || interfaceId == bytes4(0x01ffc9a7); + } + + function transfer(address receiver, uint256 id, uint256 amount) external returns (bool) { + require(msg.sender != address(0)); + require(receiver != address(0)); + uint256 fromBalance = _balances[msg.sender][id]; + require(fromBalance >= amount); + _balances[msg.sender][id] = fromBalance - amount; + uint256 toBalance = _balances[receiver][id]; + _balances[receiver][id] = (toBalance + amount) as uint256; + return true; + } + + function transferFrom(address sender, address receiver, uint256 id, uint256 amount) external returns (bool) { + if (sender != msg.sender && !_operatorApprovals[sender][msg.sender]) { + uint256 currentAllowance = _allowances[sender][msg.sender][id]; + if (currentAllowance < type(uint256).max) { + require(currentAllowance >= amount); + _allowances[sender][msg.sender][id] = currentAllowance - amount; + } + } + require(sender != address(0)); + require(receiver != address(0)); + uint256 fromBalance = _balances[sender][id]; + require(fromBalance >= amount); + _balances[sender][id] = fromBalance - amount; + uint256 toBalance = _balances[receiver][id]; + _balances[receiver][id] = (toBalance + amount) as uint256; + return true; + } +} + +theorem contractSyntax_eq : contractSyntax = OpenZeppelinBench.ERC6909.contract := by rfl + +end OpenZeppelinBench.ERC6909.Syntax diff --git a/Examples/OpenZeppelinBench/ERC6909/Transfer.lean b/Examples/OpenZeppelinBench/ERC6909/Transfer.lean index f908c0ff..17a667d7 100644 --- a/Examples/OpenZeppelinBench/ERC6909/Transfer.lean +++ b/Examples/OpenZeppelinBench/ERC6909/Transfer.lean @@ -3,7 +3,6 @@ import Examples.OpenZeppelinBench.ERC6909.Approve import Examples.OpenZeppelinBench.ERC6909.Storage import Reasoning.Refinement import Reasoning.SolmBody -import Reasoning.SolcDecode open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement diff --git a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Decode.lean b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Decode.lean index 5ad009ac..960d5554 100644 --- a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Decode.lean +++ b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Decode.lean @@ -6,7 +6,6 @@ import Examples.OpenZeppelinBench.ERC6909.Transfer import Examples.OpenZeppelinBench.Pausable.Storage import Reasoning.Refinement import Reasoning.SolmBody -import Reasoning.SolcDecode open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement diff --git a/Examples/OpenZeppelinBench/Ownable2Step/SpecSyntax.lean b/Examples/OpenZeppelinBench/Ownable2Step/SpecSyntax.lean new file mode 100644 index 00000000..00206ae0 --- /dev/null +++ b/Examples/OpenZeppelinBench/Ownable2Step/SpecSyntax.lean @@ -0,0 +1,55 @@ +import Examples.OpenZeppelinBench.Ownable2Step.Spec +import Solm.Notation + +/-! +# Ownable2Step spec in the Solidity-faithful Solm frontend + +The `Ownable2StepBench` spec written with `solidity%`, proven definitionally equal to the AST spec +in `Examples/OpenZeppelinBench/Ownable2Step/Spec.lean`. + +The AST constructor has no callvalue guard, so the surface constructor is marked `payable`. +Transition order matches `contract.transitions` (selector order). +-/ + +open Solm Solm.Notation + +namespace OpenZeppelinBench.Ownable2Step.Syntax + +def contractSyntax : ContractDecl := solidity% contract Ownable2StepBench { + address _owner; + address _pendingOwner; + + constructor(address initialOwner) payable { + require(initialOwner != address(0)); + _owner = initialOwner; + } + + function acceptOwnership() external { + require(_pendingOwner == msg.sender); + _pendingOwner = address(0); + _owner = msg.sender; + } + + function owner() external returns (address) { + return _owner; + } + + function pendingOwner() external returns (address) { + return _pendingOwner; + } + + function renounceOwnership() external { + require(_owner == msg.sender); + _pendingOwner = address(0); + _owner = address(0); + } + + function transferOwnership(address newOwner) external { + require(_owner == msg.sender); + _pendingOwner = newOwner; + } +} + +theorem contractSyntax_eq : contractSyntax = OpenZeppelinBench.Ownable2Step.contract := by rfl + +end OpenZeppelinBench.Ownable2Step.Syntax diff --git a/Examples/OpenZeppelinBench/Pausable/SpecSyntax.lean b/Examples/OpenZeppelinBench/Pausable/SpecSyntax.lean new file mode 100644 index 00000000..fbc5da3a --- /dev/null +++ b/Examples/OpenZeppelinBench/Pausable/SpecSyntax.lean @@ -0,0 +1,52 @@ +import Examples.OpenZeppelinBench.Pausable.Spec +import Solm.Notation + +/-! +# Pausable spec in the Solidity-faithful Solm frontend + +The `PausableBench` spec written with `solidity%`, proven definitionally equal to the AST spec in +`Examples/OpenZeppelinBench/Pausable/Spec.lean`. + +The AST constructor has no callvalue guard, so the surface constructor is marked `payable`. +Transition order matches `contract.transitions` (selector order). +-/ + +open Solm Solm.Notation + +namespace OpenZeppelinBench.Pausable.Syntax + +def contractSyntax : ContractDecl := solidity% contract PausableBench { + bool _paused; + + constructor() payable { + _paused = false; + } + + function guardedWhenNotPaused() external returns (bool) { + require(!_paused); + return true; + } + + function guardedWhenPaused() external returns (bool) { + require(_paused); + return true; + } + + function pause() external { + require(!_paused); + _paused = true; + } + + function paused() external returns (bool) { + return _paused; + } + + function unpause() external { + require(_paused); + _paused = false; + } +} + +theorem contractSyntax_eq : contractSyntax = OpenZeppelinBench.Pausable.contract := by rfl + +end OpenZeppelinBench.Pausable.Syntax diff --git a/Examples/Pow/SpecSyntax.lean b/Examples/Pow/SpecSyntax.lean new file mode 100644 index 00000000..047ff16c --- /dev/null +++ b/Examples/Pow/SpecSyntax.lean @@ -0,0 +1,33 @@ +import Examples.Pow.Spec +import Solm.Notation + +/-! +# Pow spec in the Solidity-faithful Solm frontend + +The spec's constructor has an empty body (no callvalue guard), so it is written `payable`. +`pow2` is non-payable; the loop's local updates are `letDecl` re-binds, written as re-declarations +so the annotations (`some uint256`) match. +-/ + +open Solm Solm.Notation + +namespace Pow.Syntax + +def contractSyntax : ContractDecl := solidity% contract Pow { + constructor() payable { } + + function pow2(uint256 n) external returns (uint256) { + require(n < 256); + uint256 r = 1; + uint256 i = 0; + while (i < n) { + uint256 r = r * 2; + uint256 i = i + 1; + } + return r; + } +} + +theorem contractSyntax_eq : contractSyntax = Pow.powContract := by rfl + +end Pow.Syntax diff --git a/Examples/Reuse/SpecSyntax.lean b/Examples/Reuse/SpecSyntax.lean new file mode 100644 index 00000000..c858a51d --- /dev/null +++ b/Examples/Reuse/SpecSyntax.lean @@ -0,0 +1,36 @@ +import Examples.Reuse.Spec +import Solm.Notation + +/-! +# Reuse spec in the Solidity-faithful Solm frontend + +The `C` contract from `Examples/Reuse/Spec.lean` written with `solidity%` and proven +definitionally equal to the AST spec. + +* The spec's constructor body is empty (no non-payable guard), so the surface constructor is + marked `payable` to suppress the auto-inserted guard. +* `g` calls the public `f` internally, written as the bound internal call `var r = f(v);`. +-/ + +open Solm Solm.Notation + +namespace Reuse.Syntax + +def contractSyntax : ContractDecl := solidity% contract C { + uint256 s; + + constructor() payable { } + + function f(uint256 v) external returns (uint256) { + return (v * 2 + 1) as uint256; + } + + function g(uint256 v) external { + var r = f(v); + s = r; + } +} + +theorem contractSyntax_eq : contractSyntax = Reuse.cContract := by rfl + +end Reuse.Syntax diff --git a/Examples/SimpleAuction/SpecSyntax.lean b/Examples/SimpleAuction/SpecSyntax.lean new file mode 100644 index 00000000..ca05e639 --- /dev/null +++ b/Examples/SimpleAuction/SpecSyntax.lean @@ -0,0 +1,79 @@ +import Examples.SimpleAuction.Spec +import Solm.Notation + +/-! +# SimpleAuction spec in the Solidity-faithful Solm frontend + +The `if (cond) revert E();` sites of the source are `require(!cond)` here, as in the AST spec +(custom-error payloads are dropped). `bid` is payable; every other entry point gets the implicit +non-payable guard. +-/ + +open Solm Solm.Notation + +namespace SimpleAuction.Syntax + +def contractSyntax : ContractDecl := solidity% contract SimpleAuction { + address beneficiary; + uint256 auctionEndTime; + address highestBidder; + uint256 highestBid; + mapping(address => uint256) pendingReturns; + bool ended; + + constructor(uint256 biddingTime, address beneficiaryAddress) { + beneficiary = beneficiaryAddress; + auctionEndTime = (block.timestamp + biddingTime) as uint256; + } + + function bid() external payable { + require(block.timestamp <= auctionEndTime); + require(msg.value > highestBid); + if (highestBid != 0) { + pendingReturns[highestBidder] = (pendingReturns[highestBidder] + highestBid) as uint256; + } + highestBidder = msg.sender; + highestBid = msg.value; + } + + function withdraw() external returns (bool) { + uint256 amount = pendingReturns[msg.sender]; + if (amount > 0) { + pendingReturns[msg.sender] = 0; + (bool success, bytes memory _data) = msg.sender.call{value: amount}(new bytes(0)); + if (!success) { + pendingReturns[msg.sender] = amount; + return false; + } + } + return true; + } + + function auctionEnd() external { + require(block.timestamp >= auctionEndTime); + require(!ended); + ended = true; + (bool success, bytes memory _data) = beneficiary.call{value: highestBid}(new bytes(0)); + require(success); + } + + function beneficiary() external returns (address) { + return beneficiary; + } + + function auctionEndTime() external returns (uint256) { + return auctionEndTime; + } + + function highestBidder() external returns (address) { + return highestBidder; + } + + function highestBid() external returns (uint256) { + return highestBid; + } +} + +theorem contractSyntax_eq : contractSyntax = SimpleAuction.simpleAuctionContract := by rfl + +end SimpleAuction.Syntax diff --git a/Examples/StringStoreLite/Getters.lean b/Examples/StringStoreLite/Getters.lean index 117ff153..0df311c6 100644 --- a/Examples/StringStoreLite/Getters.lean +++ b/Examples/StringStoreLite/Getters.lean @@ -419,7 +419,7 @@ theorem decodeCalldata_string_some {cd : ByteArray} {x : Solm.Ident} rw [htlen] at hhuge omega)] have hreadOff := readNat_drop4_zero_eq_calldataWord (cd := cd) hsz36 - have hreadLen := readNat_drop4_dynamic_eq_calldataWord (cd := cd) hoffMax hlenWord + have hreadLen := readNat_drop4_dynamic_eq_calldataWord (cd := cd) hlenWord have hpayloadRead := readBytes_drop4_string_payload (cd := cd) hpayload have hnotHeadShort : ¬ cd.toList.length - 4 < 32 := by rw [htlen] diff --git a/Examples/StringStoreLite/SetOldLong.lean b/Examples/StringStoreLite/SetOldLong.lean index dde975f3..a0f116ac 100644 --- a/Examples/StringStoreLite/SetOldLong.lean +++ b/Examples/StringStoreLite/SetOldLong.lean @@ -2705,14 +2705,14 @@ theorem nat_land_high_mask5_eq_div_mul {n : Nat} (hn : n < 2 ^ 256) : rw [Nat.testBit_and] rw [show (n / 32) * 32 = (n / 2 ^ 5) <<< 5 by rw [h32, Nat.shiftLeft_eq]] - rw [nat_testBit_shiftLeft] + rw [testBit_shiftLeft] by_cases hi5 : i < 5 · have hmask : (2 ^ 256 - 2 ^ 5).testBit i = false := by rw [show (2 : Nat) ^ 256 - 2 ^ 5 = (2 ^ (256 - 5) - 1) <<< 5 by rw [Nat.shiftLeft_eq] rw [Nat.sub_mul] simp] - rw [nat_testBit_shiftLeft] + rw [testBit_shiftLeft] simp [hi5] rw [hmask] simp [hi5] @@ -2724,14 +2724,14 @@ theorem nat_land_high_mask5_eq_div_mul {n : Nat} (hn : n < 2 ^ 256) : rw [Nat.shiftLeft_eq] rw [Nat.sub_mul] simp] - rw [nat_testBit_shiftLeft] + rw [testBit_shiftLeft] simp [hi5] change (2 ^ (256 - 5) - 1).testBit (i - 5) = true rw [Nat.testBit_two_pow_sub_one] simp [show i - 5 < 256 - 5 by omega] rw [hmask] simp [hi5] - simpa [h32] using (nat_div_pow_testBit n 5 i h5i).symm + simpa [h32] using (divPow_testBit n 5 i h5i).symm · have hmask : (2 ^ 256 - 2 ^ 5).testBit i = false := by exact Nat.testBit_lt_two_pow (lt_of_lt_of_le (by @@ -2741,7 +2741,7 @@ theorem nat_land_high_mask5_eq_div_mul {n : Nat} (hn : n < 2 ^ 256) : exact Nat.testBit_lt_two_pow (lt_of_lt_of_le hn (Nat.pow_le_pow_right (by norm_num) (Nat.le_of_not_gt hi256))) have hdivbit : (n / 2 ^ 5).testBit (i - 5) = false := by - rw [nat_div_pow_testBit n 5 i h5i, hnbit] + rw [divPow_testBit n 5 i h5i, hnbit] rw [hmask, hdivbit] simp [hi5] diff --git a/Examples/StringStoreLite/SpecSyntax.lean b/Examples/StringStoreLite/SpecSyntax.lean new file mode 100644 index 00000000..63a73fe5 --- /dev/null +++ b/Examples/StringStoreLite/SpecSyntax.lean @@ -0,0 +1,44 @@ +import Examples.StringStoreLite.Spec +import Solm.Notation + +/-! +# StringStoreLite spec in the Solidity-faithful Solm frontend + +The `StringStoreLite` contract from `Examples/StringStoreLite/Spec.lean` written with +`solidity%` and proven definitionally equal to the AST spec. + +* The spec's constructor body is empty (no non-payable guard), so the surface constructor is + marked `payable` to suppress the auto-inserted guard. +* `string memory copy = …;` gives the typed `letDecl` (`some ABIType.string`) of the AST; + `copy.length` / `current.length` give the local/storage `arrayLength` reads. +-/ + +open Solm Solm.Notation + +namespace StringStoreLite.Syntax + +def contractSyntax : ContractDecl := solidity% contract StringStoreLite { + string current; + + constructor() payable { } + + function set(string memory value) external returns (uint256) { + string memory copy = value; + current = copy; + return copy.length; + } + + function clearCurrent() external returns (uint256) { + string memory copy = current; + delete current; + return copy.length; + } + + function currentLength() external returns (uint256) { + return current.length; + } +} + +theorem contractSyntax_eq : contractSyntax = StringStoreLite.stringStoreLiteContract := by rfl + +end StringStoreLite.Syntax diff --git a/Examples/TinyImmutable/SpecSyntax.lean b/Examples/TinyImmutable/SpecSyntax.lean new file mode 100644 index 00000000..2b0a5aa2 --- /dev/null +++ b/Examples/TinyImmutable/SpecSyntax.lean @@ -0,0 +1,44 @@ +import Examples.TinyImmutable.Spec +import Solm.Notation + +/-! +# TinyImmutable spec in the Solidity-faithful Solm frontend + +The spec is parameterized by the immutable valuation `v : TinyImmutables`, so `contractSyntax` is +too, and the immutable reads use the `${…}` expression escape. The `unchecked` product in `quote` +is the explicit `% 2^256` wrap, as in the AST spec. +-/ + +open Solm Solm.Notation +open TinyImmutable.Immutables + +namespace TinyImmutable.Syntax + +def contractSyntax (v : TinyImmutables) : ContractDecl := solidity% contract TinyImmutable { + constructor(address _owner, uint256 _scale, bool useScale) { + address imm_owner = _owner; + if (useScale) { + uint256 imm_scale = _scale; + } else { + uint256 imm_scale = 0; + } + } + + function owner() external returns (address) { + return ${owner v}; + } + + function quote(uint256 amount) external returns (uint256) { + require(msg.sender == ${owner v}); + return (amount * ${scale v}) % #(Int.ofNat EVM.wordModulus); + } + + function scale() external returns (uint256) { + return ${scale v}; + } +} + +theorem contractSyntax_eq (v : TinyImmutables) : + contractSyntax v = TinyImmutable.contract v := by rfl + +end TinyImmutable.Syntax diff --git a/Examples/Truth/SpecSyntax.lean b/Examples/Truth/SpecSyntax.lean new file mode 100644 index 00000000..28b2c117 --- /dev/null +++ b/Examples/Truth/SpecSyntax.lean @@ -0,0 +1,25 @@ +import Examples.Truth.Spec +import Solm.Notation + +/-! +# Truth spec in the Solidity-faithful Solm frontend + +The spec's constructor has an empty body (no callvalue guard), so it is written `payable`; +`truth()` is non-payable, so its guard is implicit. +-/ + +open Solm Solm.Notation + +namespace Truth.Syntax + +def contractSyntax : ContractDecl := solidity% contract Truth { + constructor() payable { } + + function truth() external returns (bool) { + return true; + } +} + +theorem contractSyntax_eq : contractSyntax = truthContract := by rfl + +end Truth.Syntax diff --git a/Examples/UniswapV2Pair/Common.lean b/Examples/UniswapV2Pair/Common.lean index 73aafca8..9aa14169 100644 --- a/Examples/UniswapV2Pair/Common.lean +++ b/Examples/UniswapV2Pair/Common.lean @@ -419,7 +419,7 @@ theorem natLandClearMiddle112_224 (n : Nat) (hn : n < 2 ^ 256) : rw [Nat.shiftLeft_eq]] rw [show n / 2 ^ 224 * 2 ^ 224 = (n / 2 ^ 224) <<< 224 by rw [Nat.shiftLeft_eq]] - rw [nat_testBit_shiftLeft, nat_testBit_shiftLeft] + rw [testBit_shiftLeft, testBit_shiftLeft] by_cases hi112 : i < 112 · have hi224 : i < 224 := by omega simp [hi112, hi224] @@ -430,7 +430,7 @@ theorem natLandClearMiddle112_224 (n : Nat) (hn : n < 2 ^ 256) : by_cases hi256 : i < 256 · have hsub32 : i - 224 < 32 := by omega rw [show decide (i - 224 < 32) = true by simp [hsub32]] - rw [nat_div_pow_testBit n 224 i h224le] + rw [divPow_testBit n 224 i h224le] simp [hi112, hi224] · have hsub32 : ¬ (i - 224 < 32) := by omega rw [show decide (i - 224 < 32) = false by simp [hsub32]] @@ -438,7 +438,7 @@ theorem natLandClearMiddle112_224 (n : Nat) (hn : n < 2 ^ 256) : have hpow : n < 2 ^ i := lt_of_lt_of_le hn (Nat.pow_le_pow_right (by norm_num) (by omega)) exact Nat.testBit_lt_two_pow hpow - rw [nat_div_pow_testBit n 224 i h224le, hnfalse] + rw [divPow_testBit n 224 i h224le, hnfalse] simp [hi112, hi224] theorem uint112Offset14MiddleClear_toNat (old : UInt256) : diff --git a/Examples/UniswapV2Pair/Dispatch.lean b/Examples/UniswapV2Pair/Dispatch.lean index 3223560a..173df79e 100644 --- a/Examples/UniswapV2Pair/Dispatch.lean +++ b/Examples/UniswapV2Pair/Dispatch.lean @@ -608,7 +608,7 @@ theorem uniswapX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} have h12 := h0.push2 ⟨16⟩ (by native_decide) (by simp only [List.length]; omega) |>.jumpiNT (by native_decide) (isZero_eq_zero_of_ne hwv) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h12 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h12 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) theorem uniswapX_short {cA gh bl σ σ₀ A I} {g : Sat256} @@ -630,7 +630,7 @@ theorem uniswapX_short {cA gh bl σ σ₀ A I} {g : Sat256} |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hsz) (by jump_dest) (by simp only [List.length]; omega) |>.jumpdest (by native_decide) (by simp only [List.length]; omega) - exact RD.uniswapPush1Dup1Revert0 h425 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h425 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length]; omega) /-- Reach the low-half split from the root split. -/ @@ -932,7 +932,7 @@ theorem uniswapJumpToNoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} have h425 := h.push2 ⟨425⟩ hpush (by simp only [List.length_singleton]; omega) |>.jump hjump (by jump_dest) (by evm_ov) |>.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h425 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h425 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem uniswapX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} @@ -1132,7 +1132,7 @@ theorem uniswapX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} |>.selectorArmNotTakenAuto (uniswapLowestArmsWellFormed 5 (by omega)) (heqLowest 5 (by omega)) (by simp) have h426 := h425.jumpdest (by native_decide) (by simp only [List.length_singleton]; omega) - exact RD.uniswapPush1Dup1Revert0 h426 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 h426 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_singleton]; omega) theorem uniswapNonPayable {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} diff --git a/Examples/UniswapV2Pair/Mint.lean b/Examples/UniswapV2Pair/Mint.lean index ba42d272..4cdcfe95 100644 --- a/Examples/UniswapV2Pair/Mint.lean +++ b/Examples/UniswapV2Pair/Mint.lean @@ -49,7 +49,7 @@ theorem uniswapMintBody have hword := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨12⟩ ⟨0⟩ simpa [evmS, initState] using hword.symm.trans hunlocked by_cases htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) = ⟨0⟩ @@ -135,7 +135,7 @@ theorem uniswapMintBody obtain ⟨_, _, rd3573⟩ := uniswapMintRuntimeSecondBalanceOfExtcodesizeFromFirst rd3505 ho32 hoSize by_cases htoken1NoCode : - uniswapExtCodeSizeWord σ' + extCodeSizeWord σ' (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ' I)) = ⟨0⟩ · have hbody : ExecTransitionBody config contract evmS (mintStore I) mintTransition.body @@ -295,7 +295,7 @@ theorem uniswapMintBody uniswapMintFeeRuntimeFactoryExtcodesize rd7696 ho32 hoSize ho132 ho1Size have henv1I : evm1S.executionEnv = I := henv1.trans henv0I by_cases hfactoryNoCode : - uniswapExtCodeSizeWord σ'' (mintFeeFactoryWord σ'' I) = ⟨0⟩ + extCodeSizeWord σ'' (mintFeeFactoryWord σ'' I) = ⟨0⟩ · have hfeeGuard : evalExpr? config (mintFeeCallFrame diff --git a/Examples/UniswapV2Pair/MintCommon.lean b/Examples/UniswapV2Pair/MintCommon.lean index f0bf7342..dd0cd879 100644 --- a/Examples/UniswapV2Pair/MintCommon.lean +++ b/Examples/UniswapV2Pair/MintCommon.lean @@ -444,7 +444,7 @@ theorem mintFeeFactoryGuardFalse_of_noCode {σ : AccountMap} {evm : EVM.State} {I : ExecutionEnv} {reserve0 reserve1 : UInt256} (hPost : accountMapEquiv σ evm.accountMap) (henv : evm.executionEnv = I) - (hfactoryNoCode : uniswapExtCodeSizeWord σ (mintFeeFactoryWord σ I) = ⟨0⟩) : + (hfactoryNoCode : extCodeSizeWord σ (mintFeeFactoryWord σ I) = ⟨0⟩) : evalExpr? config (mintFeeCallFrame reserve0 reserve1) evm (.binary .gt (.extCodeSize (.storage factoryRef)) (.intLit 0)) = .ok (.bool false) := by @@ -454,10 +454,10 @@ theorem mintFeeFactoryGuardFalse_of_noCode {σ : AccountMap} have hword := accountMapEquiv_storage_findD hPost I.codeOwner ⟨5⟩ ⟨0⟩ simpa [factoryWordS, factoryWordE, uniswapSlotWord, henv] using hword have hcodeEvm : - uniswapExtCodeSizeWord evm.accountMap (UInt256.land solcAddrMask factoryWordE) = + extCodeSizeWord evm.accountMap (UInt256.land solcAddrMask factoryWordE) = ⟨0⟩ := by have hsame := - uniswapExtCodeSizeWord_accountMapEquiv hPost (UInt256.land solcAddrMask factoryWordS) + extCodeSizeWord_accountMapEquiv hPost (UInt256.land solcAddrMask factoryWordS) rw [← hslot] rw [← hsame] simpa [factoryWordS, mintFeeFactoryWord] using hfactoryNoCode @@ -470,11 +470,11 @@ theorem mintFeeFactoryGuardFalse_of_noCode {σ : AccountMap} (fun acc => EVM.Word.ofNat acc.code.size) = ⟨0⟩ := by have hcodeEvmRight : - uniswapExtCodeSizeWord evm.accountMap (UInt256.land factoryWordE solcAddrMask) = + extCodeSizeWord evm.accountMap (UInt256.land factoryWordE solcAddrMask) = ⟨0⟩ := by simpa [u256_land_comm] using hcodeEvm simpa [State.lookupAccount, Solm.EVM.storageLoad, Account.lookupStorage, - uniswapAddressAtSlot, uniswapExtCodeSizeWord, uniswapSlotWord, factoryWordE, + uniswapAddressAtSlot, extCodeSizeWord, uniswapSlotWord, factoryWordE, accountAddress_ofUInt256_eq_ofNat_toNat] using hcodeEvmRight have hcodeSourceWord : EVM.Word.ofNat @@ -496,7 +496,7 @@ theorem mintFeeFactoryGuardTrue_of_code {σ : AccountMap} {evm : EVM.State} {I : ExecutionEnv} {reserve0 reserve1 : UInt256} (hPost : accountMapEquiv σ evm.accountMap) (henv : evm.executionEnv = I) - (hfactoryCode : uniswapExtCodeSizeWord σ (mintFeeFactoryWord σ I) ≠ ⟨0⟩) : + (hfactoryCode : extCodeSizeWord σ (mintFeeFactoryWord σ I) ≠ ⟨0⟩) : evalExpr? config (mintFeeCallFrame reserve0 reserve1) evm (.binary .gt (.extCodeSize (.storage factoryRef)) (.intLit 0)) = .ok (.bool true) := by @@ -506,12 +506,12 @@ theorem mintFeeFactoryGuardTrue_of_code {σ : AccountMap} have hword := accountMapEquiv_storage_findD hPost I.codeOwner ⟨5⟩ ⟨0⟩ simpa [factoryWordS, factoryWordE, uniswapSlotWord, henv] using hword have hcodeEvm : - uniswapExtCodeSizeWord evm.accountMap (UInt256.land solcAddrMask factoryWordE) ≠ + extCodeSizeWord evm.accountMap (UInt256.land solcAddrMask factoryWordE) ≠ ⟨0⟩ := by have hsame := - uniswapExtCodeSizeWord_accountMapEquiv hPost (UInt256.land solcAddrMask factoryWordS) + extCodeSizeWord_accountMapEquiv hPost (UInt256.land solcAddrMask factoryWordS) have hcodeS : - uniswapExtCodeSizeWord σ (UInt256.land solcAddrMask factoryWordS) ≠ ⟨0⟩ := by + extCodeSizeWord σ (UInt256.land solcAddrMask factoryWordS) ≠ ⟨0⟩ := by simpa [factoryWordS, mintFeeFactoryWord] using hfactoryCode intro hzero apply hcodeS @@ -527,13 +527,13 @@ theorem mintFeeFactoryGuardTrue_of_code {σ : AccountMap} (fun acc => EVM.Word.ofNat acc.code.size) ≠ ⟨0⟩ := by have hcodeEvmRight : - uniswapExtCodeSizeWord evm.accountMap (UInt256.land factoryWordE solcAddrMask) ≠ + extCodeSizeWord evm.accountMap (UInt256.land factoryWordE solcAddrMask) ≠ ⟨0⟩ := by simpa [u256_land_comm] using hcodeEvm intro hzero apply hcodeEvmRight simpa [State.lookupAccount, Solm.EVM.storageLoad, Account.lookupStorage, - uniswapAddressAtSlot, uniswapExtCodeSizeWord, uniswapSlotWord, factoryWordE, + uniswapAddressAtSlot, extCodeSizeWord, uniswapSlotWord, factoryWordE, accountAddress_ofUInt256_eq_ofNat_toNat] using hzero have hcodeSourceWord : EVM.Word.ofNat @@ -833,7 +833,7 @@ theorem mintToken0GuardFalse_initState_of_noCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} (hAccounts : accountMapEquiv σ_evm σ_solm) (htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) = ⟨0⟩) : @@ -863,7 +863,7 @@ theorem mintToken0GuardTrue_initState_of_code {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} (hAccounts : accountMapEquiv σ_evm σ_solm) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -885,10 +885,10 @@ theorem mintToken0GuardTrue_initState_of_code simpa [σLockE, σLockS, token0WordE, token0WordS] using accountMapEquiv_storage_findD hLockAccounts I.codeOwner ⟨6⟩ ⟨0⟩ have hcodeSolm : - uniswapExtCodeSizeWord σLockS (UInt256.land solcAddrMask token0WordS) ≠ ⟨0⟩ := by + extCodeSizeWord σLockS (UInt256.land solcAddrMask token0WordS) ≠ ⟨0⟩ := by intro hzero have hsame := - uniswapExtCodeSizeWord_accountMapEquiv hLockAccounts + extCodeSizeWord_accountMapEquiv hLockAccounts (UInt256.land solcAddrMask token0WordE) rw [← hslot] at hzero rw [← hsame] at hzero @@ -908,13 +908,13 @@ theorem mintToken0GuardTrue_initState_of_code (fun acc => EVM.Word.ofNat acc.code.size) ≠ ⟨0⟩ := by have hcodeSolmRight : - uniswapExtCodeSizeWord σLockS (UInt256.land token0WordS solcAddrMask) ≠ ⟨0⟩ := by + extCodeSizeWord σLockS (UInt256.land token0WordS solcAddrMask) ≠ ⟨0⟩ := by simpa [u256_land_comm] using hcodeSolm intro hzero apply hcodeSolmRight simpa [evmL, evmS, uniswapLockEnteredState, uniswapUnlockedState, initState, storageStore_accountMap, storageStore_executionEnv, State.lookupAccount, Solm.EVM.storageLoad, - Account.lookupStorage, uniswapAddressAtSlot, uniswapExtCodeSizeWord, uniswapSlotWord, σLockS, + Account.lookupStorage, uniswapAddressAtSlot, extCodeSizeWord, uniswapSlotWord, σLockS, token0WordS, accountAddress_ofUInt256_eq_ofNat_toNat] using hzero have hcodeSourceWord : EVM.Word.ofNat @@ -947,7 +947,7 @@ theorem mintToken1GuardFalse_of_noCode {σ : AccountMap} (hPost : accountMapEquiv σ evm0.accountMap) (henv : evm0.executionEnv = I) (htoken1NoCode : - uniswapExtCodeSizeWord σ (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ I)) = + extCodeSizeWord σ (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ I)) = ⟨0⟩) : evalExpr? config { contract := contract, locals := (mintReserveStore reserveEvm I).insert "balance0" balance0 } @@ -959,10 +959,10 @@ theorem mintToken1GuardFalse_of_noCode {σ : AccountMap} have hword := accountMapEquiv_storage_findD hPost I.codeOwner ⟨7⟩ ⟨0⟩ simpa [token1WordS, token1WordE, uniswapSlotWord, henv] using hword have hcodeEvm : - uniswapExtCodeSizeWord evm0.accountMap (UInt256.land solcAddrMask token1WordE) = + extCodeSizeWord evm0.accountMap (UInt256.land solcAddrMask token1WordE) = ⟨0⟩ := by have hsame := - uniswapExtCodeSizeWord_accountMapEquiv hPost (UInt256.land solcAddrMask token1WordS) + extCodeSizeWord_accountMapEquiv hPost (UInt256.land solcAddrMask token1WordS) rw [← hslot] rw [← hsame] simpa [token1WordS] using htoken1NoCode @@ -982,11 +982,11 @@ theorem mintToken1GuardFalse_of_noCode {σ : AccountMap} (fun acc => EVM.Word.ofNat acc.code.size) = ⟨0⟩ := by have hcodeEvmRight : - uniswapExtCodeSizeWord evm0.accountMap (UInt256.land token1WordE solcAddrMask) = + extCodeSizeWord evm0.accountMap (UInt256.land token1WordE solcAddrMask) = ⟨0⟩ := by simpa [u256_land_comm] using hcodeEvm simpa [State.lookupAccount, Solm.EVM.storageLoad, Account.lookupStorage, - uniswapAddressAtSlot, uniswapExtCodeSizeWord, uniswapSlotWord, token1WordE, + uniswapAddressAtSlot, extCodeSizeWord, uniswapSlotWord, token1WordE, accountAddress_ofUInt256_eq_ofNat_toNat] using hcodeEvmRight have hcodeSourceWord : EVM.Word.ofNat @@ -1010,7 +1010,7 @@ theorem mintToken1GuardTrue_of_code {σ : AccountMap} (hPost : accountMapEquiv σ evm0.accountMap) (henv : evm0.executionEnv = I) (htoken1Code : - uniswapExtCodeSizeWord σ (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ I)) ≠ + extCodeSizeWord σ (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ I)) ≠ ⟨0⟩) : evalExpr? config { contract := contract, locals := (mintReserveStore reserveEvm I).insert "balance0" balance0 } @@ -1022,11 +1022,11 @@ theorem mintToken1GuardTrue_of_code {σ : AccountMap} have hword := accountMapEquiv_storage_findD hPost I.codeOwner ⟨7⟩ ⟨0⟩ simpa [token1WordS, token1WordE, uniswapSlotWord, henv] using hword have hcodeEvm : - uniswapExtCodeSizeWord evm0.accountMap (UInt256.land solcAddrMask token1WordE) ≠ + extCodeSizeWord evm0.accountMap (UInt256.land solcAddrMask token1WordE) ≠ ⟨0⟩ := by intro hzero have hsame := - uniswapExtCodeSizeWord_accountMapEquiv hPost (UInt256.land solcAddrMask token1WordS) + extCodeSizeWord_accountMapEquiv hPost (UInt256.land solcAddrMask token1WordS) rw [← hslot] at hzero rw [← hsame] at hzero exact htoken1Code (by simpa [token1WordS] using hzero) @@ -1046,13 +1046,13 @@ theorem mintToken1GuardTrue_of_code {σ : AccountMap} (fun acc => EVM.Word.ofNat acc.code.size) ≠ ⟨0⟩ := by have hcodeEvmRight : - uniswapExtCodeSizeWord evm0.accountMap (UInt256.land token1WordE solcAddrMask) ≠ + extCodeSizeWord evm0.accountMap (UInt256.land token1WordE solcAddrMask) ≠ ⟨0⟩ := by simpa [u256_land_comm] using hcodeEvm intro hzero apply hcodeEvmRight simpa [State.lookupAccount, Solm.EVM.storageLoad, Account.lookupStorage, - uniswapAddressAtSlot, uniswapExtCodeSizeWord, uniswapSlotWord, token1WordE, + uniswapAddressAtSlot, extCodeSizeWord, uniswapSlotWord, token1WordE, accountAddress_ofUInt256_eq_ofNat_toNat] using hzero have hcodeSourceWord : EVM.Word.ofNat diff --git a/Examples/UniswapV2Pair/MintFeeRuntimeFactory.lean b/Examples/UniswapV2Pair/MintFeeRuntimeFactory.lean index cbfbb875..57ae1f74 100644 --- a/Examples/UniswapV2Pair/MintFeeRuntimeFactory.lean +++ b/Examples/UniswapV2Pair/MintFeeRuntimeFactory.lean @@ -115,10 +115,10 @@ theorem uniswapMintFeeRuntimeFactoryMissingCodeReverts ⟨0⟩, toWord, ⟨861⟩, sel] (feeToSelectorMem (balanceOfThisRebuiltStaticcallMem (UInt256.ofNat I.codeOwner.val) o o1)) feeToStaticcallActiveWords o1 (cA'', σ'') k C) - (hfactoryNoCode : uniswapExtCodeSizeWord σ'' (mintFeeFactoryWord σ'' I) = ⟨0⟩) : + (hfactoryNoCode : extCodeSizeWord σ'' (mintFeeFactoryWord σ'' I) = ⟨0⟩) : RDrev uniswapV2PairBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapExtcodesizeGuardMissing (okPc := ⟨7777⟩) rd7765 hfactoryNoCode + exact RD.solcExtcodesizeGuardMissing (okPc := ⟨7777⟩) rd7765 hfactoryNoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -145,7 +145,7 @@ theorem uniswapMintFeeRuntimeFactoryStaticcallMade (feeToSelectorMem (balanceOfThisRebuiltStaticcallMem (UInt256.ofNat I.codeOwner.val) o o1)) feeToStaticcallActiveWords o1 (cA'', σ'') k C) (hdepth : I.depth.val < 1024) - (hfactoryCode : uniswapExtCodeSizeWord σ'' (mintFeeFactoryWord σ'' I) ≠ ⟨0⟩) : + (hfactoryCode : extCodeSizeWord σ'' (mintFeeFactoryWord σ'' I) ≠ ⟨0⟩) : ∃ (cAFee : Batteries.RBSet AccountAddress compare) (σFee : AccountMap) (zFee : Bool) (outFee : ByteArray) (A_inFee : Substate) (callGasFee : UInt256) (k' C' : ℕ), @@ -178,14 +178,14 @@ theorem uniswapMintFeeRuntimeFactoryStaticcallMade let baseMem := balanceOfThisRebuiltStaticcallMem (UInt256.ofNat I.codeOwner.val) o o1 let factory := mintFeeFactoryWord σ'' I obtain ⟨_, _, _, rd7780⟩ := - RD.uniswapExtcodesizeGuardOkGas (okPc := ⟨7777⟩) rd7765 hfactoryCode + RD.solcExtcodesizeGuardOkGas (okPc := ⟨7777⟩) rd7765 hfactoryCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) obtain ⟨cAFee, σFee, zFee, outFee, A_inFee, callGasFee, k', C', hΘ, rd7781, houtFeeSize⟩ := - RD.uniswapStaticcall rd7780 (by native_decide) hdepth + RD.solcStaticcall rd7780 (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) exact ⟨cAFee, σFee, zFee, outFee, A_inFee, callGasFee, k', C', by simpa [baseMem, factory, initState] using hΘ, @@ -243,7 +243,7 @@ theorem uniswapMintFeeRuntimeFactoryResultBranchesFromCall · intro hz have hstatus : (if zFee then (⟨1⟩ : UInt256) else ⟨0⟩) = ⟨0⟩ := by simp [hz] - exact RD.uniswapCallSuccessGuardMissing (okPc := ⟨7797⟩) rd7781 hstatus + exact RD.solcCallSuccessGuardMissing (okPc := ⟨7797⟩) rd7781 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -254,7 +254,7 @@ theorem uniswapMintFeeRuntimeFactoryResultBranchesFromCall rw [hz] decide obtain ⟨_, _, rd7799⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨7797⟩) rd7781 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨7797⟩) rd7781 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -279,7 +279,7 @@ theorem uniswapMintFeeRuntimeFactoryResultBranchesFromCall rw [hz] decide obtain ⟨_, _, rd7799⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨7797⟩) rd7781 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨7797⟩) rd7781 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) diff --git a/Examples/UniswapV2Pair/MintRuntimeBalance.lean b/Examples/UniswapV2Pair/MintRuntimeBalance.lean index f2b3d6fc..6e287586 100644 --- a/Examples/UniswapV2Pair/MintRuntimeBalance.lean +++ b/Examples/UniswapV2Pair/MintRuntimeBalance.lean @@ -81,7 +81,7 @@ theorem uniswapMintRuntimeFirstBalanceOfExtcodesize have rd3395 := rd3394.mstore 6 balanceOfThisSelectorMem (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov) have rd3400 := evm_run rd3395 with [ - uniswapAddress, push1 ⟨4⟩, dup3, add] + address, push1 ⟨4⟩, dup3, add] have rd3401 := rd3400.mstore 3 (balanceOfThisCalldataMem (UInt256.ofNat I.codeOwner.val)) (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov) @@ -117,7 +117,7 @@ theorem uniswapMintRuntimeFirstBalanceOfStaticcallReady solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) k C) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -140,7 +140,7 @@ theorem uniswapMintRuntimeFirstBalanceOfStaticcallReady obtain ⟨_, _, rd3448⟩ := uniswapMintRuntimeFirstBalanceOfExtcodesize (g := g) hlockEntered obtain ⟨_, _, rd3462⟩ := - RD.uniswapExtcodesizeGuardOk (okPc := ⟨3460⟩) rd3448 + RD.solcExtcodesizeGuardOk (okPc := ⟨3460⟩) rd3448 (by simpa [σLock, token0Word, token0Clean] using htoken0Code) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) @@ -159,7 +159,7 @@ theorem uniswapMintRuntimeFirstBalanceOfStaticcallEntry solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) k C) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -183,7 +183,7 @@ theorem uniswapMintRuntimeFirstBalanceOfStaticcallEntry obtain ⟨_, _, rd3448⟩ := uniswapMintRuntimeFirstBalanceOfExtcodesize (g := g) hlockEntered obtain ⟨gasWord, _, _, rd3463⟩ := - RD.uniswapExtcodesizeGuardOkGas (okPc := ⟨3460⟩) rd3448 + RD.solcExtcodesizeGuardOkGas (okPc := ⟨3460⟩) rd3448 (by simpa [σLock, token0Word, token0Clean] using htoken0Code) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) @@ -203,7 +203,7 @@ theorem uniswapMintRuntimeFirstBalanceOfStaticcallMade solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) k C) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -242,7 +242,7 @@ theorem uniswapMintRuntimeFirstBalanceOfStaticcallMade uniswapMintRuntimeFirstBalanceOfStaticcallEntry (g := g) hlockEntered htoken0Code obtain ⟨cA', σ', z, o, A_in, callGas, k', C', hΘ, rd3464, hoSize⟩ := - RD.uniswapStaticcall rd3463 (by native_decide) hdepth + RD.solcStaticcall rd3463 (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) exact ⟨cA', σ', z, o, A_in, callGas, k', C', by simpa [σLock, token0Word, token0Clean, initState] using hΘ, @@ -262,7 +262,7 @@ theorem uniswapMintRuntimeFirstBalanceOfResultBranches solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) k C) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -309,7 +309,7 @@ theorem uniswapMintRuntimeFirstBalanceOfResultBranches · intro hz have hstatus : (if z then (⟨1⟩ : UInt256) else ⟨0⟩) = ⟨0⟩ := by simp [hz] - exact RD.uniswapCallSuccessGuardMissing (okPc := ⟨3480⟩) rd3464 hstatus + exact RD.solcCallSuccessGuardMissing (okPc := ⟨3480⟩) rd3464 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -320,7 +320,7 @@ theorem uniswapMintRuntimeFirstBalanceOfResultBranches rw [hz] decide obtain ⟨_, _, rd3482⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨3480⟩) rd3464 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨3480⟩) rd3464 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -337,7 +337,7 @@ theorem uniswapMintRuntimeFirstBalanceOfResultBranches rw [hz] decide obtain ⟨_, _, rd3482⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨3480⟩) rd3464 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨3480⟩) rd3464 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -363,7 +363,7 @@ theorem uniswapMintRuntimeFirstBalanceOfMissingCodeReverts solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) k C) (htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) = ⟨0⟩) : @@ -374,7 +374,7 @@ theorem uniswapMintRuntimeFirstBalanceOfMissingCodeReverts let token0Clean := UInt256.land solcAddrMask token0Word obtain ⟨_, _, rd3448⟩ := uniswapMintRuntimeFirstBalanceOfExtcodesize (g := g) hlockEntered - exact RD.uniswapExtcodesizeGuardMissing (okPc := ⟨3460⟩) rd3448 + exact RD.solcExtcodesizeGuardMissing (okPc := ⟨3460⟩) rd3448 (by simpa [σLock, token0Word, token0Clean] using htoken0NoCode) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -400,9 +400,9 @@ theorem uniswapMintRuntimeFirstBalanceOfStaticcallDepthReverts RDrev uniswapV2PairBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd3464⟩ := - RD.uniswapStaticcallDepthLimit rd3463 (by native_decide) hdepth hovStatic + RD.solcStaticcallDepthLimit rd3463 (by native_decide) hdepth hovStatic have rdRev := - RD.uniswapCallSuccessGuardMissing (okPc := ⟨3480⟩) rd3464 rfl + RD.solcCallSuccessGuardMissing (okPc := ⟨3480⟩) rd3464 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -464,7 +464,7 @@ theorem uniswapMintRuntimeSecondBalanceOfExtcodesizeFromFirst balanceOfThisStaticcallActiveWords (by native_decide) mem_cost (by rfl) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) - have rd3527 := evm_run rd3522 with [uniswapAddress, push1 ⟨4⟩, dup3, add] + have rd3527 := evm_run rd3522 with [address, push1 ⟨4⟩, dup3, add] have rd3528 := rd3527.mstore 0 (balanceOfThisRebuiltCalldataMem (UInt256.ofNat I.codeOwner.val) o) balanceOfThisStaticcallActiveWords @@ -514,7 +514,7 @@ theorem uniswapMintRuntimeSecondBalanceOfResultBranchesFromExtcodesize (hdepth : I.depth.val < 1024) (ho32 : 32 ≤ o.size) (hoSize : o.size < UInt256.size) (htoken1Code : - uniswapExtCodeSizeWord σ' + extCodeSizeWord σ' (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ' I)) ≠ ⟨0⟩) : ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z1 : Bool) (o1 : ByteArray) (A_in1 : Substate) (callGas1 : UInt256), @@ -549,20 +549,20 @@ theorem uniswapMintRuntimeSecondBalanceOfResultBranchesFromExtcodesize balanceOfThisStaticcallActiveWords o1 (cA'', σ'') k' C') ∧ o1.size < UInt256.size := by obtain ⟨gasWord, _, _, rd3588⟩ := - RD.uniswapExtcodesizeGuardOkGas (okPc := ⟨3585⟩) rd3573 htoken1Code + RD.solcExtcodesizeGuardOkGas (okPc := ⟨3585⟩) rd3573 htoken1Code (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) obtain ⟨cA'', σ'', z1, o1, A_in1, callGas1, k', C', hΘ1, rd3589, ho1Size⟩ := - RD.uniswapStaticcall rd3588 (by native_decide) hdepth + RD.solcStaticcall rd3588 (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨cA'', σ'', z1, o1, A_in1, callGas1, ?_, ?_, ?_, ?_, ho1Size⟩ · simpa [balanceOfThisRebuiltStaticcallMem, initState] using hΘ1 · intro hz1 have hstatus : (if z1 then (⟨1⟩ : UInt256) else ⟨0⟩) = ⟨0⟩ := by simp [hz1] - exact RD.uniswapCallSuccessGuardMissing (okPc := ⟨3605⟩) rd3589 hstatus + exact RD.solcCallSuccessGuardMissing (okPc := ⟨3605⟩) rd3589 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -573,7 +573,7 @@ theorem uniswapMintRuntimeSecondBalanceOfResultBranchesFromExtcodesize rw [hz1] decide obtain ⟨_, _, rd3607⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨3605⟩) rd3589 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨3605⟩) rd3589 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -590,7 +590,7 @@ theorem uniswapMintRuntimeSecondBalanceOfResultBranchesFromExtcodesize rw [hz1] decide obtain ⟨_, _, rd3607⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨3605⟩) rd3589 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨3605⟩) rd3589 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -625,11 +625,11 @@ theorem uniswapMintRuntimeSecondBalanceOfMissingCodeFromExtcodesize (balanceOfThisRebuiltCalldataMem (UInt256.ofNat I.codeOwner.val) o) balanceOfThisStaticcallActiveWords o (cA', σ') k C) (htoken1NoCode : - uniswapExtCodeSizeWord σ' + extCodeSizeWord σ' (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ' I)) = ⟨0⟩) : RDrev uniswapV2PairBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - exact RD.uniswapExtcodesizeGuardMissing (okPc := ⟨3585⟩) rd3573 htoken1NoCode + exact RD.solcExtcodesizeGuardMissing (okPc := ⟨3585⟩) rd3573 htoken1NoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) diff --git a/Examples/UniswapV2Pair/Permit.lean b/Examples/UniswapV2Pair/Permit.lean index c66c0b5e..b2a9741f 100644 --- a/Examples/UniswapV2Pair/Permit.lean +++ b/Examples/UniswapV2Pair/Permit.lean @@ -3202,7 +3202,7 @@ theorem uniswapPermitX_ecrecoverStatusAndReturnDecoded · intro hz have hstatus : (if z then (⟨1⟩ : UInt256) else ⟨0⟩) = ⟨0⟩ := by simp [hz] - exact RD.uniswapCallSuccessGuardMissing (okPc := ⟨5830⟩) rd5814 hstatus + exact RD.solcCallSuccessGuardMissing (okPc := ⟨5830⟩) rd5814 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3213,7 +3213,7 @@ theorem uniswapPermitX_ecrecoverStatusAndReturnDecoded rw [hz] decide obtain ⟨_, _, rd5832⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨5830⟩) rd5814 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨5830⟩) rd5814 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -3314,7 +3314,7 @@ theorem uniswapPermitX_ecrecoverStatusAndReturnDecodedAll have hstatus : (if z then (⟨1⟩ : UInt256) else ⟨0⟩) ≠ ⟨0⟩ := by rw [hz] decide - exact RD.uniswapCallSuccessGuardOk (okPc := ⟨5830⟩) rd5814 hstatus + exact RD.solcCallSuccessGuardOk (okPc := ⟨5830⟩) rd5814 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -3322,7 +3322,7 @@ theorem uniswapPermitX_ecrecoverStatusAndReturnDecodedAll · intro hz have hstatus : (if z then (⟨1⟩ : UInt256) else ⟨0⟩) = ⟨0⟩ := by simp [hz] - exact RD.uniswapCallSuccessGuardMissing (okPc := ⟨5830⟩) rd5814 hstatus + exact RD.solcCallSuccessGuardMissing (okPc := ⟨5830⟩) rd5814 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -3406,7 +3406,7 @@ theorem uniswapPermitX_ecrecoverStatusAndReturnDecodedAllAt have hstatus : (if z then (⟨1⟩ : UInt256) else ⟨0⟩) ≠ ⟨0⟩ := by rw [hz] decide - exact RD.uniswapCallSuccessGuardOk (okPc := ⟨5830⟩) rd5814 hstatus + exact RD.solcCallSuccessGuardOk (okPc := ⟨5830⟩) rd5814 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -3414,7 +3414,7 @@ theorem uniswapPermitX_ecrecoverStatusAndReturnDecodedAllAt · intro hz have hstatus : (if z then (⟨1⟩ : UInt256) else ⟨0⟩) = ⟨0⟩ := by simp [hz] - exact RD.uniswapCallSuccessGuardMissing (okPc := ⟨5830⟩) rd5814 hstatus + exact RD.solcCallSuccessGuardMissing (okPc := ⟨5830⟩) rd5814 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) diff --git a/Examples/UniswapV2Pair/PermitRuntime.lean b/Examples/UniswapV2Pair/PermitRuntime.lean index d3aa2ad9..1277c660 100644 --- a/Examples/UniswapV2Pair/PermitRuntime.lean +++ b/Examples/UniswapV2Pair/PermitRuntime.lean @@ -1624,7 +1624,7 @@ theorem RD.uniswapPermitEcrecoverStaticcallMade {g : Sat256} {s0 : State} have rd5813 := rd5813₀ rw [hInSize, hOutOffset, hTail] at rd5813 obtain ⟨cA', σ', z, o, A_in, callGas, k', C', htheta, rd5814, houtSize⟩ := - RD.uniswapStaticcall rd5813 (by native_decide) hdepth + RD.solcStaticcall rd5813 (by native_decide) hdepth (by simp only [List.length_cons]; omega) have haw : UInt256.ofNat (MachineState.M @@ -1703,7 +1703,7 @@ theorem RD.uniswapPermitEcrecoverStaticcallDepthReverts {g : Sat256} {s0 : State have rd5813 := rd5813₀ rw [hInSize, hOutOffset, hTail] at rd5813 obtain ⟨k', C', rd5814₀⟩ := - RD.uniswapStaticcallDepthLimit rd5813 (by native_decide) hdepth + RD.solcStaticcallDepthLimit rd5813 (by native_decide) hdepth (by simp only [List.length_cons]; omega) have haw : UInt256.ofNat (MachineState.M @@ -1720,7 +1720,7 @@ theorem RD.uniswapPermitEcrecoverStaticcallDepthReverts {g : Sat256} {s0 : State (permitRuntimeEcrecoverStaticcallMem baseMem digest v r s ByteArray.empty) (UInt256.ofNat 20) ByteArray.empty (cA, σ) k' C' := by simpa [permitRuntimeEcrecoverStaticcallMem] using rd5814 - exact RD.uniswapCallSuccessGuardMissing (okPc := ⟨5830⟩) rd5814' rfl + exact RD.solcCallSuccessGuardMissing (okPc := ⟨5830⟩) rd5814' rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) diff --git a/Examples/UniswapV2Pair/Skim.lean b/Examples/UniswapV2Pair/Skim.lean index eb1001f1..24b4ecb6 100644 --- a/Examples/UniswapV2Pair/Skim.lean +++ b/Examples/UniswapV2Pair/Skim.lean @@ -604,14 +604,14 @@ theorem skimToken1GuardAfterFirstTransfer_false {σ : AccountMap} (htarget : AccountAddress.ofUInt256 (UInt256.land token1 solcAddrMask) = uniswapAddressAtSlot (uniswapLockEnteredState evm) ⟨7⟩) - (hnoCode : uniswapExtCodeSizeWord σ (UInt256.land token1 solcAddrMask) = ⟨0⟩) : + (hnoCode : extCodeSizeWord σ (UInt256.land token1 solcAddrMask) = ⟨0⟩) : evalExpr? config { contract := contract, locals := skimFirstSafeTransferStore evm evm0 I balance0 } evm1 (.binary .gt (.extCodeSize (.var "_token1")) (.intLit 0)) = .ok (.bool false) := by let target := UInt256.land token1 solcAddrMask let addr := uniswapAddressAtSlot (uniswapLockEnteredState evm) ⟨7⟩ - have hsame := uniswapExtCodeSizeWord_accountMapEquiv hPost target - have hnoEvm : uniswapExtCodeSizeWord evm1.accountMap target = ⟨0⟩ := by + have hsame := extCodeSizeWord_accountMapEquiv hPost target + have hnoEvm : extCodeSizeWord evm1.accountMap target = ⟨0⟩ := by rw [← hsame] exact hnoCode have hcodeWord : @@ -623,7 +623,7 @@ theorem skimToken1GuardAfterFirstTransfer_false {σ : AccountMap} rfl | some acc => have hnoAcc : UInt256.ofNat acc.code.size = ⟨0⟩ := by - simpa [target, addr, htarget, uniswapExtCodeSizeWord, hacc] using hnoEvm + simpa [target, addr, htarget, extCodeSizeWord, hacc] using hnoEvm simpa [hacc] using hnoAcc have hvar : evalExpr? config @@ -643,14 +643,14 @@ theorem skimToken1GuardAfterFirstTransfer_true {σ : AccountMap} (htarget : AccountAddress.ofUInt256 (UInt256.land token1 solcAddrMask) = uniswapAddressAtSlot (uniswapLockEnteredState evm) ⟨7⟩) - (hcode : uniswapExtCodeSizeWord σ (UInt256.land token1 solcAddrMask) ≠ ⟨0⟩) : + (hcode : extCodeSizeWord σ (UInt256.land token1 solcAddrMask) ≠ ⟨0⟩) : evalExpr? config { contract := contract, locals := skimFirstSafeTransferStore evm evm0 I balance0 } evm1 (.binary .gt (.extCodeSize (.var "_token1")) (.intLit 0)) = .ok (.bool true) := by let target := UInt256.land token1 solcAddrMask let addr := uniswapAddressAtSlot (uniswapLockEnteredState evm) ⟨7⟩ - have hsame := uniswapExtCodeSizeWord_accountMapEquiv hPost target - have hcodeEvm : uniswapExtCodeSizeWord evm1.accountMap target ≠ ⟨0⟩ := by + have hsame := extCodeSizeWord_accountMapEquiv hPost target + have hcodeEvm : extCodeSizeWord evm1.accountMap target ≠ ⟨0⟩ := by intro hzero apply hcode rw [hsame] @@ -663,14 +663,14 @@ theorem skimToken1GuardAfterFirstTransfer_true {σ : AccountMap} apply hcodeEvm cases hacc : evm1.accountMap.find? addr with | none => - unfold uniswapExtCodeSizeWord + unfold extCodeSizeWord rw [show AccountAddress.ofUInt256 target = addr by simpa [target, addr] using htarget, hacc] rfl | some acc => have hzeroAcc : UInt256.ofNat acc.code.size = ⟨0⟩ := by simpa [hacc] using hzero - simpa [target, addr, htarget, uniswapExtCodeSizeWord, hacc] using hzeroAcc + simpa [target, addr, htarget, extCodeSizeWord, hacc] using hzeroAcc have hpositive : 0 < (EVM.Word.ofNat ((evm1.lookupAccount addr).option 0 (fun acc => acc.code.size))).toNat := @@ -696,7 +696,7 @@ theorem skimToken0GuardFalse_initState_of_noCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} (hAccounts : accountMapEquiv σ_evm σ_solm) (htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) = ⟨0⟩) : @@ -711,12 +711,12 @@ theorem skimToken0GuardFalse_initState_of_noCode simpa [σLockE, σLockS, token0WordE, token0WordS] using accountMapEquiv_storage_findD hLockAccounts I.codeOwner ⟨6⟩ ⟨0⟩ have hnoSolm : - uniswapExtCodeSizeWord σLockS (UInt256.land solcAddrMask token0WordS) = ⟨0⟩ := by + extCodeSizeWord σLockS (UInt256.land solcAddrMask token0WordS) = ⟨0⟩ := by have hsame := - uniswapExtCodeSizeWord_accountMapEquiv hLockAccounts + extCodeSizeWord_accountMapEquiv hLockAccounts (UInt256.land solcAddrMask token0WordE) have hnoE : - uniswapExtCodeSizeWord σLockE (UInt256.land solcAddrMask token0WordE) = ⟨0⟩ := by + extCodeSizeWord σLockE (UInt256.land solcAddrMask token0WordE) = ⟨0⟩ := by simpa [σLockE, token0WordE] using htoken0NoCode rw [← hslot] rw [← hsame] @@ -737,11 +737,11 @@ theorem skimToken0GuardFalse_initState_of_noCode (fun acc => EVM.Word.ofNat acc.code.size) = ⟨0⟩ := by have hnoSolmRight : - uniswapExtCodeSizeWord σLockS (UInt256.land token0WordS solcAddrMask) = ⟨0⟩ := by + extCodeSizeWord σLockS (UInt256.land token0WordS solcAddrMask) = ⟨0⟩ := by simpa [u256_land_comm] using hnoSolm simpa [evmL, evmS, uniswapLockEnteredState, uniswapUnlockedState, initState, storageStore_accountMap, storageStore_executionEnv, State.lookupAccount, Solm.EVM.storageLoad, - Account.lookupStorage, uniswapAddressAtSlot, uniswapExtCodeSizeWord, uniswapSlotWord, σLockS, + Account.lookupStorage, uniswapAddressAtSlot, extCodeSizeWord, uniswapSlotWord, σLockS, token0WordS, accountAddress_ofUInt256_eq_ofNat_toNat] using hnoSolmRight have hnoSourceWord : EVM.Word.ofNat @@ -763,7 +763,7 @@ theorem skimToken0GuardTrue_initState_of_code {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} (hAccounts : accountMapEquiv σ_evm σ_solm) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -778,12 +778,12 @@ theorem skimToken0GuardTrue_initState_of_code simpa [σLockE, σLockS, token0WordE, token0WordS] using accountMapEquiv_storage_findD hLockAccounts I.codeOwner ⟨6⟩ ⟨0⟩ have hcodeSolm : - uniswapExtCodeSizeWord σLockS (UInt256.land solcAddrMask token0WordS) ≠ ⟨0⟩ := by + extCodeSizeWord σLockS (UInt256.land solcAddrMask token0WordS) ≠ ⟨0⟩ := by have hsame := - uniswapExtCodeSizeWord_accountMapEquiv hLockAccounts + extCodeSizeWord_accountMapEquiv hLockAccounts (UInt256.land solcAddrMask token0WordE) have hcodeE : - uniswapExtCodeSizeWord σLockE (UInt256.land solcAddrMask token0WordE) ≠ ⟨0⟩ := by + extCodeSizeWord σLockE (UInt256.land solcAddrMask token0WordE) ≠ ⟨0⟩ := by simpa [σLockE, token0WordE] using htoken0Code intro hzero apply hcodeE @@ -805,11 +805,11 @@ theorem skimToken0GuardTrue_initState_of_code (fun acc => EVM.Word.ofNat acc.code.size) ≠ ⟨0⟩ := by have hcodeSolmRight : - uniswapExtCodeSizeWord σLockS (UInt256.land token0WordS solcAddrMask) ≠ ⟨0⟩ := by + extCodeSizeWord σLockS (UInt256.land token0WordS solcAddrMask) ≠ ⟨0⟩ := by simpa [u256_land_comm] using hcodeSolm simpa [evmL, evmS, uniswapLockEnteredState, uniswapUnlockedState, initState, storageStore_accountMap, storageStore_executionEnv, State.lookupAccount, Solm.EVM.storageLoad, - Account.lookupStorage, uniswapAddressAtSlot, uniswapExtCodeSizeWord, uniswapSlotWord, σLockS, + Account.lookupStorage, uniswapAddressAtSlot, extCodeSizeWord, uniswapSlotWord, σLockS, token0WordS, accountAddress_ofUInt256_eq_ofNat_toNat] using hcodeSolmRight have hcodeSourceWord : EVM.Word.ofNat @@ -904,7 +904,7 @@ theorem uniswapSkimBodyCoreRevert_firstNoCode (σ_evm.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) = ⟨0⟩) @@ -942,7 +942,7 @@ theorem uniswapSkimBodyCoreRevert_firstCallDepth (σ_evm.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) @@ -1030,7 +1030,7 @@ theorem uniswapSkimBodyRevert_firstNoCode (σ_evm.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) = ⟨0⟩) @@ -1080,7 +1080,7 @@ theorem uniswapSkimBody (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩ := by exact not_not.mp hlocked by_cases htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) = @@ -1666,7 +1666,7 @@ theorem uniswapSkimBody have hPostTransferAccounts1 : accountMapEquiv σ1 evm1S.accountMap := by simpa [evm1S] using hPostTransferAccounts0 by_cases htoken1NoCode : - uniswapExtCodeSizeWord σ1 + extCodeSizeWord σ1 (UInt256.land token1CleanE solcAddrMask) = ⟨0⟩ · have hguard1 := skimToken1GuardAfterFirstTransfer_false @@ -1688,7 +1688,7 @@ theorem uniswapSkimBody exact rdRev.reEquivExecutionRevert hcode hdispatch (uniswapDecode_skim_ok hsz36 hcanonTo) hbody · have htoken1Code : - uniswapExtCodeSizeWord σ1 + extCodeSizeWord σ1 (UInt256.land token1CleanE solcAddrMask) ≠ ⟨0⟩ := htoken1NoCode have hguard1 := @@ -2412,7 +2412,7 @@ theorem uniswapSkimBody exact Ethereum.EVM.ByteArray.readWithPadding_size_le_maxReturnDataSizeByGas _ _ _) by_cases htoken1NoCode : - uniswapExtCodeSizeWord σ1 + extCodeSizeWord σ1 (UInt256.land token1CleanE solcAddrMask) = ⟨0⟩ · have hguard1 := skimToken1GuardAfterFirstTransfer_false @@ -2435,7 +2435,7 @@ theorem uniswapSkimBody exact rdRev.reEquivExecutionRevert hcode hdispatch (uniswapDecode_skim_ok hsz36 hcanonTo) hbody · have htoken1Code : - uniswapExtCodeSizeWord σ1 + extCodeSizeWord σ1 (UInt256.land token1CleanE solcAddrMask) ≠ ⟨0⟩ := htoken1NoCode have hguard1 := @@ -3130,7 +3130,7 @@ theorem uniswapSkimBody (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩ := by exact not_not.mp hlocked by_cases htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) = @@ -3609,7 +3609,7 @@ theorem uniswapSkimBody have hPostTransferAccounts1 : accountMapEquiv σ1 evm1S.accountMap := by simpa [evm1S] using hPostTransferAccounts0 by_cases htoken1NoCode : - uniswapExtCodeSizeWord σ1 + extCodeSizeWord σ1 (UInt256.land token1CleanE solcAddrMask) = ⟨0⟩ · have hguard1 := skimToken1GuardAfterFirstTransfer_false @@ -3631,7 +3631,7 @@ theorem uniswapSkimBody exact rdRev.reEquivExecutionRevert hcode hdispatch (uniswapDecode_skim_ok_noncanon hsz36 hcanonTo) hbody · have htoken1Code : - uniswapExtCodeSizeWord σ1 + extCodeSizeWord σ1 (UInt256.land token1CleanE solcAddrMask) ≠ ⟨0⟩ := htoken1NoCode have hguard1 := @@ -4355,7 +4355,7 @@ theorem uniswapSkimBody exact Ethereum.EVM.ByteArray.readWithPadding_size_le_maxReturnDataSizeByGas _ _ _) by_cases htoken1NoCode : - uniswapExtCodeSizeWord σ1 + extCodeSizeWord σ1 (UInt256.land token1CleanE solcAddrMask) = ⟨0⟩ · have hguard1 := skimToken1GuardAfterFirstTransfer_false @@ -4378,7 +4378,7 @@ theorem uniswapSkimBody exact rdRev.reEquivExecutionRevert hcode hdispatch (uniswapDecode_skim_ok_noncanon hsz36 hcanonTo) hbody · have htoken1Code : - uniswapExtCodeSizeWord σ1 + extCodeSizeWord σ1 (UInt256.land token1CleanE solcAddrMask) ≠ ⟨0⟩ := htoken1NoCode have hguard1 := diff --git a/Examples/UniswapV2Pair/SkimDynamicSecondRuntime.lean b/Examples/UniswapV2Pair/SkimDynamicSecondRuntime.lean index 776deb93..6490a351 100644 --- a/Examples/UniswapV2Pair/SkimDynamicSecondRuntime.lean +++ b/Examples/UniswapV2Pair/SkimDynamicSecondRuntime.lean @@ -920,7 +920,7 @@ theorem RD.uniswapSkimSecondBalanceOfStaticcallMade_dynamic {g : Sat256} {s0 : S (ho32 : 32 ≤ o.size) (hoSize : o.size < UInt256.size) (hout1Ne : out1.size ≠ 0) (hout1Size : out1.size < 2 ^ 255) (hdepth : ee.depth.val < 1024) - (htoken1Code : uniswapExtCodeSizeWord σ (UInt256.land token1 solcAddrMask) ≠ ⟨0⟩) : + (htoken1Code : extCodeSizeWord σ (UInt256.land token1 solcAddrMask) ≠ ⟨0⟩) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (out2 : ByteArray) (A_in : Substate) (callGas : UInt256) (k' C' : ℕ), (∃ (g'' : UInt256) (A' : Substate), @@ -992,7 +992,7 @@ theorem RD.uniswapSkimSecondBalanceOfStaticcallMade_dynamic {g : Sat256} {s0 : S (by unfold skimSecondBalanceDynamicSelectorMem fp; rfl) (by simp [awSel, aw0, fp, skimSecondBalanceDynamicSelectorWords]) (by simp only [List.length_cons, List.length_nil]; omega) - have rd5353 := evm_run rd5348 with [uniswapAddress, push1 ⟨4⟩, dup3, add] + have rd5353 := evm_run rd5348 with [address, push1 ⟨4⟩, dup3, add] let awCalldata := skimSecondBalanceDynamicCalldataWords out1 have rd5354 := RD.mstore (Cₘ awCalldata - Cₘ awSel) @@ -1046,13 +1046,13 @@ theorem RD.uniswapSkimSecondBalanceOfStaticcallMade_dynamic {g : Sat256} {s0 : S rw [show UInt256.sub fp fp = ⟨0⟩ from u256_sub_self fp, show (⟨0⟩ : UInt256) + ⟨36⟩ = ⟨36⟩ from by decide] at rd5421 obtain ⟨gasWord, _, _, rd5272⟩ := - RD.uniswapExtcodesizeGuardOkGas (okPc := ⟨5269⟩) rd5421 htoken1Code + RD.solcExtcodesizeGuardOkGas (okPc := ⟨5269⟩) rd5421 htoken1Code (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) obtain ⟨cA', σ', z, out2, A_in, callGas, k', C', hΘ, rd5273, hout2Size⟩ := - RD.uniswapStaticcall rd5272 (by native_decide) hdepth + RD.solcStaticcall rd5272 (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨cA', σ', z, out2, A_in, callGas, k', C', ?_, ?_, hout2Size⟩ · simpa [token1Clean, skimSecondBalanceDynamicStaticcallMem, fp] using hΘ @@ -1069,7 +1069,7 @@ theorem RD.uniswapSkimSecondBalanceCallFailureReverts_dynamic {g : Sat256} {s0 : (hstatus : status = ⟨0⟩) (houtSize : out.size < UInt256.size) (hov : R.length + 5 ≤ 1024) : RDrev UniswapV2Pair.uniswapV2PairBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (okPc := ⟨5289⟩) h hstatus + exact RD.solcCallSuccessGuardMissing (okPc := ⟨5289⟩) h hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1084,7 +1084,7 @@ theorem RD.uniswapSkimSecondBalanceCallSuccessToDecode_dynamic {g : Sat256} {s0 (hstatus : status ≠ ⟨0⟩) (hov : R.length + 3 ≤ 1024) : ∃ k' C', RD UniswapV2Pair.uniswapV2PairBytecode ee g s0 ⟨5291⟩ R mem aw out acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (okPc := ⟨5289⟩) h hstatus + exact RD.solcCallSuccessGuardOk (okPc := ⟨5289⟩) h hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) hov @@ -1147,7 +1147,7 @@ theorem RD.uniswapSkimSecondBalanceReturnWordDecodeShortReverts_dynamic decide have rdFallthrough := RD.jumpiNT rdPushOk (by native_decide) hcond (by simp only [List.length_cons]; omega) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough (by native_decide) + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -1250,7 +1250,7 @@ theorem RD.uniswapSkimSecondBalanceOfNoCodeReverts_dynamic {g : Sat256} {s0 : St (skimSafeTransferReturnDataActiveWords out1) out1 (cA, σ) k C) (ho32 : 32 ≤ o.size) (hoSize : o.size < UInt256.size) (hout1Ne : out1.size ≠ 0) (hout1Size : out1.size < 2 ^ 255) - (htoken1NoCode : uniswapExtCodeSizeWord σ (UInt256.land token1 solcAddrMask) = ⟨0⟩) : + (htoken1NoCode : extCodeSizeWord σ (UInt256.land token1 solcAddrMask) = ⟨0⟩) : RDrev UniswapV2Pair.uniswapV2PairBytecode g s0 := by let packedWord := uniswapSlotWord ⟨8⟩ σ ee let token1Clean := UInt256.land token1 solcAddrMask @@ -1295,7 +1295,7 @@ theorem RD.uniswapSkimSecondBalanceOfNoCodeReverts_dynamic {g : Sat256} {s0 : St (by unfold skimSecondBalanceDynamicSelectorMem fp; rfl) (by simp [awSel, aw0, fp, skimSecondBalanceDynamicSelectorWords]) (by simp only [List.length_cons, List.length_nil]; omega) - have rd5353 := evm_run rd5348 with [uniswapAddress, push1 ⟨4⟩, dup3, add] + have rd5353 := evm_run rd5348 with [address, push1 ⟨4⟩, dup3, add] let awCalldata := skimSecondBalanceDynamicCalldataWords out1 have rd5354 := RD.mstore (Cₘ awCalldata - Cₘ awSel) @@ -1347,7 +1347,7 @@ theorem RD.uniswapSkimSecondBalanceOfNoCodeReverts_dynamic {g : Sat256} {s0 : St have rd5421 := rd5421₀ rw [show UInt256.sub fp fp = ⟨0⟩ from u256_sub_self fp, show (⟨0⟩ : UInt256) + ⟨36⟩ = ⟨36⟩ from by decide] at rd5421 - exact RD.uniswapExtcodesizeGuardMissing (okPc := ⟨5269⟩) rd5421 htoken1NoCode + exact RD.solcExtcodesizeGuardMissing (okPc := ⟨5269⟩) rd5421 htoken1NoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) diff --git a/Examples/UniswapV2Pair/SkimRuntime.lean b/Examples/UniswapV2Pair/SkimRuntime.lean index c3b46b79..1933b932 100644 --- a/Examples/UniswapV2Pair/SkimRuntime.lean +++ b/Examples/UniswapV2Pair/SkimRuntime.lean @@ -418,7 +418,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfExtcodesize have rd5184 := rd5183.mstore 6 balanceOfThisSelectorMem (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov) have rd5189 := evm_run rd5184 with [ - uniswapAddress, push1 ⟨4⟩, dup3, add] + address, push1 ⟨4⟩, dup3, add] have rd5190 := rd5189.mstore 3 (balanceOfThisCalldataMem (UInt256.ofNat I.codeOwner.val)) (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov) @@ -478,7 +478,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfStaticcallReady (balanceOfThisCalldataMem (UInt256.ofNat I.codeOwner.val)) (UInt256.ofNat 6) ByteArray.empty (cA, sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) k C) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -514,7 +514,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfStaticcallReady UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨112⟩) ⟨1⟩) packedWord obtain ⟨_, _, rd5271⟩ := - RD.uniswapExtcodesizeGuardOk (okPc := ⟨5269⟩) rd5257 + RD.solcExtcodesizeGuardOk (okPc := ⟨5269⟩) rd5257 (by simpa [σLock, token0Word, token0Clean] using htoken0Code) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) @@ -554,7 +554,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfStaticcallEntry (balanceOfThisCalldataMem (UInt256.ofNat I.codeOwner.val)) (UInt256.ofNat 6) ByteArray.empty (cA, sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) k C) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -591,7 +591,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfStaticcallEntry UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨112⟩) ⟨1⟩) packedWord obtain ⟨gasWord, _, _, rd5272⟩ := - RD.uniswapExtcodesizeGuardOkGas (okPc := ⟨5269⟩) rd5257 + RD.solcExtcodesizeGuardOkGas (okPc := ⟨5269⟩) rd5257 (by simpa [σLock, token0Word, token0Clean] using htoken0Code) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) @@ -677,7 +677,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfStaticcallMade UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨112⟩) ⟨1⟩) packedWord obtain ⟨cA', σ', z, o, A_in, callGas, k', C', hΘ, rd5273, hoSize⟩ := - RD.uniswapStaticcall rd5272 (by native_decide) hdepth + RD.solcStaticcall rd5272 (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) exact ⟨cA', σ', z, o, A_in, callGas, k', C', by simpa [σLock, token0Word, token0Clean, initState] using hΘ, @@ -753,7 +753,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfStaticcallFailureGuard have hstatus : (if z then (⟨1⟩ : UInt256) else ⟨0⟩) = ⟨0⟩ := by simp [hz] have rdRev := - RD.uniswapCallSuccessGuardMissing (okPc := ⟨5289⟩) rd5273 hstatus + RD.solcCallSuccessGuardMissing (okPc := ⟨5289⟩) rd5273 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -765,7 +765,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfStaticcallFailureGuard rw [hz] decide obtain ⟨_, _, rd5291⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨5289⟩) rd5273 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨5289⟩) rd5273 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -784,7 +784,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfStaticcallFailureGuard rw [hz] decide obtain ⟨_, _, rd5291⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨5289⟩) rd5273 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨5289⟩) rd5273 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -1029,10 +1029,10 @@ theorem uniswapSkimRuntimeFirstBalanceOfStaticcallDepthReverts RDrev uniswapV2PairBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd5273⟩ := - RD.uniswapStaticcallDepthLimit rd5272 (by native_decide) hdepth + RD.solcStaticcallDepthLimit rd5272 (by native_decide) hdepth hovStatic have rdRev := - RD.uniswapCallSuccessGuardMissing (okPc := ⟨5289⟩) rd5273 rfl + RD.solcCallSuccessGuardMissing (okPc := ⟨5289⟩) rd5273 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1055,7 +1055,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfStaticcallSuccessGuard (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -1153,7 +1153,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfStaticcallSuccessGuard rw [hz] decide obtain ⟨k', C', rd5291⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨5289⟩) rd5273 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨5289⟩) rd5273 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1175,7 +1175,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfReturnWordDecoded (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -1278,7 +1278,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfReturnWordDecodeShortReverts (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -1344,7 +1344,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfMissingCodeReverts (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I) :: R) mem aw rdata (cA, sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) k C) (htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) = ⟨0⟩) @@ -1355,7 +1355,7 @@ theorem uniswapSkimRuntimeFirstBalanceOfMissingCodeReverts let token0Word := uniswapSlotWord ⟨6⟩ σLock I let token0Clean := UInt256.land solcAddrMask token0Word have rdRev := - RD.uniswapExtcodesizeGuardMissing (okPc := ⟨5269⟩) rd5257 + RD.solcExtcodesizeGuardMissing (okPc := ⟨5269⟩) rd5257 (by simpa [σLock, token0Word, token0Clean] using htoken0NoCode) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) diff --git a/Examples/UniswapV2Pair/SkimSafeTransferReturn.lean b/Examples/UniswapV2Pair/SkimSafeTransferReturn.lean index 60334a28..5b07e815 100644 --- a/Examples/UniswapV2Pair/SkimSafeTransferReturn.lean +++ b/Examples/UniswapV2Pair/SkimSafeTransferReturn.lean @@ -270,7 +270,7 @@ theorem RD.uniswapSafeTransferReturnNonemptyShortReverts {g : Sat256} {s0 : Stat have rd6684 := rd6684₀ rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rd6684 have rd6685 := evm_run rd6684 with [jumpiNT (by native_decide)] - exact RD.uniswapPush1Dup1Revert0 rd6685 (by native_decide) (by native_decide) + exact RD.solcPush1Dup1Revert0 rd6685 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) set_option maxHeartbeats 1000000 in diff --git a/Examples/UniswapV2Pair/SkimSecondRuntime.lean b/Examples/UniswapV2Pair/SkimSecondRuntime.lean index ad4bafd0..05cf0a2a 100644 --- a/Examples/UniswapV2Pair/SkimSecondRuntime.lean +++ b/Examples/UniswapV2Pair/SkimSecondRuntime.lean @@ -430,7 +430,7 @@ theorem RD.uniswapSkimSecondBalanceReturnWordDecodeShortReverts {g : Sat256} {s0 decide have rdFallthrough := RD.jumpiNT rdPushOk (by native_decide) hcond (by simp only [List.length_cons]; omega) - exact RD.uniswapPush1Dup1Revert0 rdFallthrough (by native_decide) + exact RD.solcPush1Dup1Revert0 rdFallthrough (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -443,7 +443,7 @@ theorem RD.uniswapSkimSecondBalanceCallFailureReverts {g : Sat256} {s0 : State} (hstatus : status = ⟨0⟩) (houtSize : out.size < UInt256.size) (hov : R.length + 5 ≤ 1024) : RDrev UniswapV2Pair.uniswapV2PairBytecode g s0 := by - exact RD.uniswapCallSuccessGuardMissing (okPc := ⟨5289⟩) h hstatus + exact RD.solcCallSuccessGuardMissing (okPc := ⟨5289⟩) h hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -458,7 +458,7 @@ theorem RD.uniswapSkimSecondBalanceCallSuccessToDecode {g : Sat256} {s0 : State} (hstatus : status ≠ ⟨0⟩) (hov : R.length + 3 ≤ 1024) : ∃ k' C', RD UniswapV2Pair.uniswapV2PairBytecode ee g s0 ⟨5291⟩ R mem (UInt256.ofNat 13) out acc k' C' := by - exact RD.uniswapCallSuccessGuardOk (okPc := ⟨5289⟩) h hstatus + exact RD.solcCallSuccessGuardOk (okPc := ⟨5289⟩) h hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) hov @@ -598,7 +598,7 @@ theorem RD.uniswapSkimSecondBalanceOfStaticcallMade {g : Sat256} {s0 : State} (UInt256.ofNat 13) out0 (cA, σ) k C) (ho32 : 32 ≤ o.size) (hoSize : o.size < UInt256.size) (hdepth : ee.depth.val < 1024) - (htoken1Code : uniswapExtCodeSizeWord σ (UInt256.land token1 solcAddrMask) ≠ ⟨0⟩) : + (htoken1Code : extCodeSizeWord σ (UInt256.land token1 solcAddrMask) ≠ ⟨0⟩) : ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) (out : ByteArray) (A_in : Substate) (callGas : UInt256) (k' C' : ℕ), (∃ (g'' : UInt256) (A' : Substate), @@ -642,7 +642,7 @@ theorem RD.uniswapSkimSecondBalanceOfStaticcallMade {g : Sat256} {s0 : State} (skimSecondBalanceSelectorMem (UInt256.ofNat ee.codeOwner.val) o toWord value) (UInt256.ofNat 13) (by native_decide) mem_cost (by rfl) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) - have rd5353 := evm_run rd5348 with [uniswapAddress, push1 ⟨4⟩, dup3, add] + have rd5353 := evm_run rd5348 with [address, push1 ⟨4⟩, dup3, add] have rd5354 := rd5353.mstore 0 (skimSecondBalanceCalldataMem (UInt256.ofNat ee.codeOwner.val) o toWord value) (UInt256.ofNat 13) (by native_decide) mem_cost @@ -679,13 +679,13 @@ theorem RD.uniswapSkimSecondBalanceOfStaticcallMade {g : Sat256} {s0 : State} show UInt256.sub (⟨292⟩ : UInt256) ⟨292⟩ = ⟨0⟩ from by decide, show (⟨0⟩ : UInt256) + ⟨36⟩ = ⟨36⟩ from by decide] at rd5421 obtain ⟨gasWord, _, _, rd5272⟩ := - RD.uniswapExtcodesizeGuardOkGas (okPc := ⟨5269⟩) rd5421 htoken1Code + RD.solcExtcodesizeGuardOkGas (okPc := ⟨5269⟩) rd5421 htoken1Code (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) obtain ⟨cA', σ', z, out, A_in, callGas, k', C', hΘ, rd5273, houtSize⟩ := - RD.uniswapStaticcall rd5272 (by native_decide) hdepth + RD.solcStaticcall rd5272 (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) refine ⟨cA', σ', z, out, A_in, callGas, k', C', ?_, ?_, houtSize⟩ · simpa [token1Clean, skimSecondBalanceStaticcallMem] using hΘ @@ -706,7 +706,7 @@ theorem RD.uniswapSkimSecondBalanceOfNoCodeReverts {g : Sat256} {s0 : State} (skimSafeTransferCallMem2 (UInt256.ofNat ee.codeOwner.val) o toWord value) (UInt256.ofNat 13) out0 (cA, σ) k C) (ho32 : 32 ≤ o.size) (hoSize : o.size < UInt256.size) - (htoken1NoCode : uniswapExtCodeSizeWord σ (UInt256.land token1 solcAddrMask) = ⟨0⟩) : + (htoken1NoCode : extCodeSizeWord σ (UInt256.land token1 solcAddrMask) = ⟨0⟩) : RDrev UniswapV2Pair.uniswapV2PairBytecode g s0 := by let packedWord := uniswapSlotWord ⟨8⟩ σ ee let token1Clean := UInt256.land token1 solcAddrMask @@ -729,7 +729,7 @@ theorem RD.uniswapSkimSecondBalanceOfNoCodeReverts {g : Sat256} {s0 : State} (skimSecondBalanceSelectorMem (UInt256.ofNat ee.codeOwner.val) o toWord value) (UInt256.ofNat 13) (by native_decide) mem_cost (by rfl) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) - have rd5353 := evm_run rd5348 with [uniswapAddress, push1 ⟨4⟩, dup3, add] + have rd5353 := evm_run rd5348 with [address, push1 ⟨4⟩, dup3, add] have rd5354 := rd5353.mstore 0 (skimSecondBalanceCalldataMem (UInt256.ofNat ee.codeOwner.val) o toWord value) (UInt256.ofNat 13) (by native_decide) mem_cost @@ -765,7 +765,7 @@ theorem RD.uniswapSkimSecondBalanceOfNoCodeReverts {g : Sat256} {s0 : State} rw [show (⟨292⟩ : UInt256) + ⟨36⟩ = ⟨328⟩ from by decide, show UInt256.sub (⟨292⟩ : UInt256) ⟨292⟩ = ⟨0⟩ from by decide, show (⟨0⟩ : UInt256) + ⟨36⟩ = ⟨36⟩ from by decide] at rd5421 - exact RD.uniswapExtcodesizeGuardMissing (okPc := ⟨5269⟩) rd5421 htoken1NoCode + exact RD.solcExtcodesizeGuardMissing (okPc := ⟨5269⟩) rd5421 htoken1NoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) diff --git a/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetReturnRuntime.lean b/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetReturnRuntime.lean index 053cefb9..530678e3 100644 --- a/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetReturnRuntime.lean +++ b/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetReturnRuntime.lean @@ -1364,7 +1364,7 @@ theorem RD.uniswapSkimSecondSafeTransferNonemptyShortReverts_dynamic_offset have rd6684 := rd6684₀ rw [hlt, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ from by decide] at rd6684 have rd6685 := evm_run rd6684 with [jumpiNT (by native_decide)] - exact RD.uniswapPush1Dup1Revert0 rd6685 (by native_decide) + exact RD.solcPush1Dup1Revert0 rd6685 (by native_decide) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) diff --git a/Examples/UniswapV2Pair/SpecSyntax.lean b/Examples/UniswapV2Pair/SpecSyntax.lean new file mode 100644 index 00000000..a01c41f3 --- /dev/null +++ b/Examples/UniswapV2Pair/SpecSyntax.lean @@ -0,0 +1,403 @@ +import Examples.UniswapV2Pair.Spec +import Solm.Notation + +/-! +# UniswapV2Pair spec in the Solidity-faithful Solm frontend + +The whole Pair benchmark spec (LP-token surface, permit, and the mutating AMM entry points), +written with `solidity%` and proven definitionally equal to the AST spec in +`Examples/UniswapV2Pair/Spec.lean`. + +Escapes, where the surface cannot express the AST: +* `extCodeSize` guards on *storage* receivers (`factory`, `token0`, `token1`): the surface + `x.code.length` builtin only resolves locals, so those guards use `${Expr.extCodeSize …}`. +* `permit`'s `ecrecover` is an external call whose receiver is the precompile address + `.cast (.intLit 1) addrSt` — not an identifier — so that statement is a `${[…]}` splice, and + the spliced binder `recoveredAddress` is referenced via `${Expr.var …}` afterwards. +* `mint` binds `liquidity` inside both `if` branches; the frontend's scope does not carry + branch-local binders past the `if`, so later uses are `${Expr.var "liquidity"}`. +* Spec `Int` constants (`q112`, `twoPow32`, `twoPow256`) are embedded with `#`. + +`from`/`to` are Lean keywords, hence «from»/«to». Transition order matches +`UniswapV2Pair.contract.transitions` (selector order). +-/ + +open Solm Solm.Notation + +namespace UniswapV2Pair.Syntax + +def contractSyntax : ContractDecl := solidity% contract UniswapV2Pair { + uint256 totalSupply; + mapping(address => uint256) balanceOf; + mapping(address => mapping(address => uint256)) allowance; + bytes32 DOMAIN_SEPARATOR; + mapping(address => uint256) nonces; + address factory; + address token0; + address token1; + uint112 reserve0; + uint112 reserve1; + uint32 blockTimestampLast; + uint256 price0CumulativeLast; + uint256 price1CumulativeLast; + uint256 kLast; + uint256 unlocked; + + constructor() payable { + DOMAIN_SEPARATOR = keccak256(abi.encodePacked( + bytes32(keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")), + bytes32(keccak256("Uniswap V2")), + bytes32(keccak256("1")), + uint256(block.chainid), + uint256(uint256(this)))); + unlocked = 1; + factory = msg.sender; + } + + function _approve(address owner, address spender, uint256 value) internal { + allowance[owner][spender] = value; + } + + function _transfer(address «from», address «to», uint256 value) internal { + uint256 fromBalance = balanceOf[«from»]; + require(fromBalance >= value); + balanceOf[«from»] = fromBalance - value; + uint256 toBalance = balanceOf[«to»]; + balanceOf[«to»] = (toBalance + value) as uint256; + } + + function _mint(address «to», uint256 value) internal { + totalSupply = (totalSupply + value) as uint256; + balanceOf[«to»] = (balanceOf[«to»] + value) as uint256; + } + + function _burn(address «from», uint256 value) internal { + uint256 fromBalance = balanceOf[«from»]; + require(fromBalance >= value); + balanceOf[«from»] = fromBalance - value; + uint256 _totalSupply = totalSupply; + require(_totalSupply >= value); + totalSupply = _totalSupply - value; + } + + function _safeTransfer(address token, address «to», uint256 value) internal { + (bool _success, bytes memory _data) = token.call(abi.encodeWithSelector(transfer, «to», value)); + require(_success ? (_data.length == 0 ? true : abi.decode(_data, (bool))) : false); + } + + function _update(uint256 balance0, uint256 balance1, uint112 _reserve0, uint112 _reserve1) internal { + require(balance0 <= type(uint112).max && balance1 <= type(uint112).max); + uint32 blockTimestamp = (block.timestamp % #twoPow32) as uint32; + uint32 timeElapsed = ((blockTimestamp - blockTimestampLast + #twoPow32) % #twoPow32) as uint32; + if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) { + price0CumulativeLast = + (price0CumulativeLast + _reserve1 * #q112 / _reserve0 * timeElapsed) % #twoPow256; + price1CumulativeLast = + (price1CumulativeLast + _reserve0 * #q112 / _reserve1 * timeElapsed) % #twoPow256; + } + reserve0 = balance0 as uint112; + reserve1 = balance1 as uint112; + blockTimestampLast = blockTimestamp; + } + + function sqrt(uint256 y) internal returns (uint256) { + if (y > 3) { + uint256 z = y; + uint256 x = y / 2 + 1; + while (x < z) { + z = x; + x = (y / x + x) / 2; + } + return z; + } else if (y != 0) { + return 1; + } else { + return 0; + } + } + + function min(uint256 x, uint256 y) internal returns (uint256) { + return x < y ? x : y; + } + + function _mintFee(uint112 _reserve0, uint112 _reserve1) internal returns (bool) { + require(${Expr.extCodeSize (.storage factoryRef)} > 0); + var feeTo = factory.feeTo{view}(); + bool feeOn = feeTo != address(0); + uint256 _kLast = kLast; + if (feeOn) { + if (_kLast != 0) { + var rootK = sqrt((_reserve0 * _reserve1) as uint256); + var rootKLast = sqrt(_kLast); + if (rootK > rootKLast) { + uint256 numerator = (totalSupply * ((rootK - rootKLast) as uint256)) as uint256; + uint256 denominator = (((rootK * 5) as uint256) + rootKLast) as uint256; + uint256 liquidity = numerator / denominator; + if (liquidity > 0) { + var _feeMint = _mint(feeTo, liquidity); + } + } + } + } else { + if (_kLast != 0) { + kLast = 0; + } + } + return feeOn; + } + + function swap(uint256 amount0Out, uint256 amount1Out, address «to», bytes calldata data) external { + require(unlocked == 1); + unlocked = 0; + require(amount0Out > 0 || amount1Out > 0); + uint112 _reserve0 = reserve0; + uint112 _reserve1 = reserve1; + require(amount0Out < _reserve0 && amount1Out < _reserve1); + address _token0 = token0; + address _token1 = token1; + require(«to» != _token0 && «to» != _token1); + if (amount0Out > 0) { + var ok0 = _safeTransfer(_token0, «to», amount0Out); + } + if (amount1Out > 0) { + var ok1 = _safeTransfer(_token1, «to», amount1Out); + } + if (data.length > 0) { + require(«to».code.length > 0); + var _callback = «to».uniswapV2Call(msg.sender, amount0Out, amount1Out, data); + } + require(_token0.code.length > 0); + var balance0 = _token0.balanceOf{view}(this); + require(_token1.code.length > 0); + var balance1 = _token1.balanceOf{view}(this); + uint256 amount0In = balance0 > _reserve0 - amount0Out + ? ((balance0 - (_reserve0 - amount0Out)) as uint256) : 0; + uint256 amount1In = balance1 > _reserve1 - amount1Out + ? ((balance1 - (_reserve1 - amount1Out)) as uint256) : 0; + require(amount0In > 0 || amount1In > 0); + uint256 balance0Adjusted = (((balance0 * 1000) as uint256) - ((amount0In * 3) as uint256)) as uint256; + uint256 balance1Adjusted = (((balance1 * 1000) as uint256) - ((amount1In * 3) as uint256)) as uint256; + require(((balance0Adjusted * balance1Adjusted) as uint256) >= + ((((_reserve0 * _reserve1) as uint256) * 1000000) as uint256)); + var _updateResult = _update(balance0, balance1, reserve0, reserve1); + unlocked = 1; + } + + function name() external returns (string) { + return "Uniswap V2"; + } + + function getReserves() external returns (uint112, uint112, uint32) { + return (reserve0, reserve1, blockTimestampLast); + } + + function approve(address spender, uint256 value) external returns (bool) { + allowance[msg.sender][spender] = value; + return true; + } + + function token0() external returns (address) { + return token0; + } + + function totalSupply() external returns (uint256) { + return totalSupply; + } + + function transferFrom(address «from», address «to», uint256 value) external returns (bool) { + uint256 currentAllowance = allowance[«from»][msg.sender]; + if (currentAllowance != type(uint256).max) { + require(currentAllowance >= value); + allowance[«from»][msg.sender] = currentAllowance - value; + } + uint256 fromBalance = balanceOf[«from»]; + require(fromBalance >= value); + balanceOf[«from»] = fromBalance - value; + uint256 toBalance = balanceOf[«to»]; + balanceOf[«to»] = (toBalance + value) as uint256; + return true; + } + + function PERMIT_TYPEHASH() external returns (bytes32) { + return bytes32(0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9); + } + + function decimals() external returns (uint8) { + return 18; + } + + function DOMAIN_SEPARATOR() external returns (bytes32) { + return DOMAIN_SEPARATOR; + } + + function «initialize»(address _token0, address _token1) external { + require(msg.sender == factory); + token0 = _token0; + token1 = _token1; + } + + function price0CumulativeLast() external returns (uint256) { + return price0CumulativeLast; + } + + function price1CumulativeLast() external returns (uint256) { + return price1CumulativeLast; + } + + function mint(address «to») external returns (uint256) { + require(unlocked == 1); + unlocked = 0; + uint112 _reserve0 = reserve0; + uint112 _reserve1 = reserve1; + require(${Expr.extCodeSize (.storage token0Ref)} > 0); + var balance0 = token0.balanceOf{view}(this); + require(${Expr.extCodeSize (.storage token1Ref)} > 0); + var balance1 = token1.balanceOf{view}(this); + uint256 amount0 = (balance0 - _reserve0) as uint256; + uint256 amount1 = (balance1 - _reserve1) as uint256; + var feeOn = _mintFee(_reserve0, _reserve1); + uint256 _totalSupply = totalSupply; + if (_totalSupply == 0) { + var rootLiquidity = sqrt((amount0 * amount1) as uint256); + uint256 liquidity = (rootLiquidity - 1000) as uint256; + var _minimumMint = _mint(address(0), 1000); + } else { + uint256 liquidity0 = ((amount0 * _totalSupply) as uint256) / _reserve0; + uint256 liquidity1 = ((amount1 * _totalSupply) as uint256) / _reserve1; + var liquidity = min(liquidity0, liquidity1); + } + require(${Expr.var "liquidity"} > 0); + var _mintResult = _mint(«to», ${Expr.var "liquidity"}); + var _updateResult = _update(balance0, balance1, _reserve0, _reserve1); + if (feeOn) { + kLast = (reserve0 * reserve1) as uint256; + } + unlocked = 1; + return ${Expr.var "liquidity"}; + } + + function balanceOf(address owner) external returns (uint256) { + return balanceOf[owner]; + } + + function kLast() external returns (uint256) { + return kLast; + } + + function nonces(address owner) external returns (uint256) { + return nonces[owner]; + } + + function burn(address «to») external returns (uint256, uint256) { + require(unlocked == 1); + unlocked = 0; + uint112 _reserve0 = reserve0; + uint112 _reserve1 = reserve1; + address _token0 = token0; + address _token1 = token1; + require(_token0.code.length > 0); + var balance0 = _token0.balanceOf{view}(this); + require(_token1.code.length > 0); + var balance1 = _token1.balanceOf{view}(this); + uint256 liquidity = balanceOf[this]; + var feeOn = _mintFee(_reserve0, _reserve1); + uint256 _totalSupply = totalSupply; + uint256 amount0 = ((liquidity * balance0) as uint256) / _totalSupply; + uint256 amount1 = ((liquidity * balance1) as uint256) / _totalSupply; + require(amount0 > 0 && amount1 > 0); + var _burnResult = _burn(this, liquidity); + var ok0 = _safeTransfer(_token0, «to», amount0); + var ok1 = _safeTransfer(_token1, «to», amount1); + require(_token0.code.length > 0); + var newBalance0 = _token0.balanceOf{view}(this); + require(_token1.code.length > 0); + var newBalance1 = _token1.balanceOf{view}(this); + var _updateResult = _update(newBalance0, newBalance1, reserve0, reserve1); + if (feeOn) { + kLast = (reserve0 * reserve1) as uint256; + } + unlocked = 1; + return (amount0, amount1); + } + + function symbol() external returns (string) { + return "UNI-V2"; + } + + function transfer(address «to», uint256 value) external returns (bool) { + uint256 fromBalance = balanceOf[msg.sender]; + require(fromBalance >= value); + balanceOf[msg.sender] = fromBalance - value; + uint256 toBalance = balanceOf[«to»]; + balanceOf[«to»] = (toBalance + value) as uint256; + return true; + } + + function MINIMUM_LIQUIDITY() external returns (uint256) { + return 1000; + } + + function skim(address «to») external { + require(unlocked == 1); + unlocked = 0; + address _token0 = token0; + address _token1 = token1; + require(_token0.code.length > 0); + var balance0 = _token0.balanceOf{view}(this); + uint256 excess0 = (balance0 - reserve0) as uint256; + var ok0 = _safeTransfer(_token0, «to», excess0); + require(_token1.code.length > 0); + var balance1 = _token1.balanceOf{view}(this); + uint256 excess1 = (balance1 - reserve1) as uint256; + var ok1 = _safeTransfer(_token1, «to», excess1); + unlocked = 1; + } + + function factory() external returns (address) { + return factory; + } + + function token1() external returns (address) { + return token1; + } + + function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external { + require(deadline >= block.timestamp); + uint256 nonce = nonces[owner]; + nonces[owner] = (nonce + 1) as uint256; + bytes32 structHash = keccak256(abi.encodePacked( + bytes32(bytes32(0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9)), + uint256(uint256(owner)), + uint256(uint256(spender)), + uint256(value), + uint256(nonce), + uint256(deadline))); + bytes32 digest = keccak256(abi.encodePacked( + bytes2(bytes2(0x1901)), + bytes32(DOMAIN_SEPARATOR), + bytes32(structHash))); + ${[Stmt.externalCall (Expr.cast (.intLit 1) addrSt) "ecrecover" (.intLit 0) + [.var "digest", .var "v", .var "r", .var "s"] "recoveredAddress" (perm := false)]} + require(${Expr.var "recoveredAddress"} != address(0) && ${Expr.var "recoveredAddress"} == owner); + var _approveResult = _approve(owner, spender, value); + } + + function allowance(address owner, address spender) external returns (uint256) { + return allowance[owner][spender]; + } + + function sync() external { + require(unlocked == 1); + unlocked = 0; + require(${Expr.extCodeSize (.storage token0Ref)} > 0); + var balance0 = token0.balanceOf{view}(this); + require(${Expr.extCodeSize (.storage token1Ref)} > 0); + var balance1 = token1.balanceOf{view}(this); + var _updateResult = _update(balance0, balance1, reserve0, reserve1); + unlocked = 1; + } +} + +theorem contractSyntax_eq : contractSyntax = UniswapV2Pair.contract := by rfl + +end UniswapV2Pair.Syntax diff --git a/Examples/UniswapV2Pair/Sync.lean b/Examples/UniswapV2Pair/Sync.lean index b10f02de..921cdfc8 100644 --- a/Examples/UniswapV2Pair/Sync.lean +++ b/Examples/UniswapV2Pair/Sync.lean @@ -1666,7 +1666,7 @@ theorem syncToken0GuardFalse_initState_of_noCode {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} (hAccounts : accountMapEquiv σ_evm σ_solm) (htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) = ⟨0⟩) : @@ -1681,12 +1681,12 @@ theorem syncToken0GuardFalse_initState_of_noCode simpa [σLockE, σLockS, token0WordE, token0WordS] using accountMapEquiv_storage_findD hLockAccounts I.codeOwner ⟨6⟩ ⟨0⟩ have hnoSolm : - uniswapExtCodeSizeWord σLockS (UInt256.land solcAddrMask token0WordS) = ⟨0⟩ := by + extCodeSizeWord σLockS (UInt256.land solcAddrMask token0WordS) = ⟨0⟩ := by have hsame := - uniswapExtCodeSizeWord_accountMapEquiv hLockAccounts + extCodeSizeWord_accountMapEquiv hLockAccounts (UInt256.land solcAddrMask token0WordE) have hnoE : - uniswapExtCodeSizeWord σLockE (UInt256.land solcAddrMask token0WordE) = ⟨0⟩ := by + extCodeSizeWord σLockE (UInt256.land solcAddrMask token0WordE) = ⟨0⟩ := by simpa [σLockE, token0WordE] using htoken0NoCode rw [← hslot] rw [← hsame] @@ -1707,11 +1707,11 @@ theorem syncToken0GuardFalse_initState_of_noCode (fun acc => EVM.Word.ofNat acc.code.size) = ⟨0⟩ := by have hnoSolmRight : - uniswapExtCodeSizeWord σLockS (UInt256.land token0WordS solcAddrMask) = ⟨0⟩ := by + extCodeSizeWord σLockS (UInt256.land token0WordS solcAddrMask) = ⟨0⟩ := by simpa [u256_land_comm] using hnoSolm simpa [evmL, evmS, uniswapLockEnteredState, uniswapUnlockedState, initState, storageStore_accountMap, storageStore_executionEnv, State.lookupAccount, Solm.EVM.storageLoad, - Account.lookupStorage, uniswapAddressAtSlot, uniswapExtCodeSizeWord, uniswapSlotWord, σLockS, + Account.lookupStorage, uniswapAddressAtSlot, extCodeSizeWord, uniswapSlotWord, σLockS, token0WordS, accountAddress_ofUInt256_eq_ofNat_toNat] using hnoSolmRight have hnoSourceWord : EVM.Word.ofNat @@ -2374,7 +2374,7 @@ theorem uniswapSyncBodyCoreRevert_firstNoCode (σ_evm.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) = ⟨0⟩) @@ -2427,7 +2427,7 @@ theorem uniswapSyncBodyRevert_firstNoCode (σ_evm.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) = ⟨0⟩) diff --git a/Examples/UniswapV2Pair/SyncBody.lean b/Examples/UniswapV2Pair/SyncBody.lean index 13687857..845cd7fc 100644 --- a/Examples/UniswapV2Pair/SyncBody.lean +++ b/Examples/UniswapV2Pair/SyncBody.lean @@ -336,7 +336,7 @@ theorem syncToken0GuardTrue_initState_of_code {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} (hAccounts : accountMapEquiv σ_evm σ_solm) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -351,10 +351,10 @@ theorem syncToken0GuardTrue_initState_of_code simpa [σLockE, σLockS, token0WordE, token0WordS] using accountMapEquiv_storage_findD hLockAccounts I.codeOwner ⟨6⟩ ⟨0⟩ have hcodeSolm : - uniswapExtCodeSizeWord σLockS (UInt256.land solcAddrMask token0WordS) ≠ ⟨0⟩ := by + extCodeSizeWord σLockS (UInt256.land solcAddrMask token0WordS) ≠ ⟨0⟩ := by intro hzero have hsame := - uniswapExtCodeSizeWord_accountMapEquiv hLockAccounts + extCodeSizeWord_accountMapEquiv hLockAccounts (UInt256.land solcAddrMask token0WordE) rw [← hslot] at hzero rw [← hsame] at hzero @@ -374,13 +374,13 @@ theorem syncToken0GuardTrue_initState_of_code (fun acc => EVM.Word.ofNat acc.code.size) ≠ ⟨0⟩ := by have hcodeSolmRight : - uniswapExtCodeSizeWord σLockS (UInt256.land token0WordS solcAddrMask) ≠ ⟨0⟩ := by + extCodeSizeWord σLockS (UInt256.land token0WordS solcAddrMask) ≠ ⟨0⟩ := by simpa [u256_land_comm] using hcodeSolm intro hzero apply hcodeSolmRight simpa [evmL, evmS, uniswapLockEnteredState, uniswapUnlockedState, initState, storageStore_accountMap, storageStore_executionEnv, State.lookupAccount, Solm.EVM.storageLoad, - Account.lookupStorage, uniswapAddressAtSlot, uniswapExtCodeSizeWord, uniswapSlotWord, σLockS, + Account.lookupStorage, uniswapAddressAtSlot, extCodeSizeWord, uniswapSlotWord, σLockS, token0WordS, accountAddress_ofUInt256_eq_ofNat_toNat] using hzero have hcodeSourceWord : EVM.Word.ofNat @@ -427,9 +427,9 @@ theorem uniswapSyncRuntimeFirstBalanceOfStaticcallDepthReverts RDrev uniswapV2PairBytecode (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by obtain ⟨_, _, rd6176⟩ := - RD.uniswapStaticcallDepthLimit rd6175 (by native_decide) hdepth hovStatic + RD.solcStaticcallDepthLimit rd6175 (by native_decide) hdepth hovStatic have rdRev := - RD.uniswapCallSuccessGuardMissing (okPc := ⟨6192⟩) rd6176 rfl + RD.solcCallSuccessGuardMissing (okPc := ⟨6192⟩) rd6176 rfl (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -445,7 +445,7 @@ theorem uniswapSyncBodyCoreRevert_firstCallDepth (σ_evm.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) @@ -499,7 +499,7 @@ theorem uniswapSyncBodyRevert_firstCallDepth (σ_evm.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) @@ -526,7 +526,7 @@ theorem syncToken1GuardFalse_of_noCode {σ : AccountMap} (hPost : accountMapEquiv σ evm0.accountMap) (henv : evm0.executionEnv = I) (htoken1NoCode : - uniswapExtCodeSizeWord σ (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ I)) = + extCodeSizeWord σ (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ I)) = ⟨0⟩) : evalExpr? config { contract := contract, locals := (∅ : Store).insert "balance0" balance0 } evm0 (.binary .gt (.extCodeSize (.storage token1Ref)) (.intLit 0)) = @@ -537,10 +537,10 @@ theorem syncToken1GuardFalse_of_noCode {σ : AccountMap} have hword := accountMapEquiv_storage_findD hPost I.codeOwner ⟨7⟩ ⟨0⟩ simpa [token1WordS, token1WordE, uniswapSlotWord, henv] using hword have hcodeEvm : - uniswapExtCodeSizeWord evm0.accountMap (UInt256.land solcAddrMask token1WordE) = + extCodeSizeWord evm0.accountMap (UInt256.land solcAddrMask token1WordE) = ⟨0⟩ := by have hsame := - uniswapExtCodeSizeWord_accountMapEquiv hPost (UInt256.land solcAddrMask token1WordS) + extCodeSizeWord_accountMapEquiv hPost (UInt256.land solcAddrMask token1WordS) rw [← hslot] rw [← hsame] simpa [token1WordS] using htoken1NoCode @@ -557,11 +557,11 @@ theorem syncToken1GuardFalse_of_noCode {σ : AccountMap} (fun acc => EVM.Word.ofNat acc.code.size) = ⟨0⟩ := by have hcodeEvmRight : - uniswapExtCodeSizeWord evm0.accountMap (UInt256.land token1WordE solcAddrMask) = + extCodeSizeWord evm0.accountMap (UInt256.land token1WordE solcAddrMask) = ⟨0⟩ := by simpa [u256_land_comm] using hcodeEvm simpa [State.lookupAccount, Solm.EVM.storageLoad, Account.lookupStorage, - uniswapAddressAtSlot, uniswapExtCodeSizeWord, uniswapSlotWord, token1WordE, + uniswapAddressAtSlot, extCodeSizeWord, uniswapSlotWord, token1WordE, accountAddress_ofUInt256_eq_ofNat_toNat] using hcodeEvmRight have hcodeSourceWord : EVM.Word.ofNat @@ -584,7 +584,7 @@ theorem syncToken1GuardTrue_of_code {σ : AccountMap} (hPost : accountMapEquiv σ evm0.accountMap) (henv : evm0.executionEnv = I) (htoken1Code : - uniswapExtCodeSizeWord σ (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ I)) ≠ + extCodeSizeWord σ (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ I)) ≠ ⟨0⟩) : syncToken1GuardTrue evm0 balance0 := by let token1WordS := uniswapSlotWord ⟨7⟩ σ I @@ -593,11 +593,11 @@ theorem syncToken1GuardTrue_of_code {σ : AccountMap} have hword := accountMapEquiv_storage_findD hPost I.codeOwner ⟨7⟩ ⟨0⟩ simpa [token1WordS, token1WordE, uniswapSlotWord, henv] using hword have hcodeEvm : - uniswapExtCodeSizeWord evm0.accountMap (UInt256.land solcAddrMask token1WordE) ≠ + extCodeSizeWord evm0.accountMap (UInt256.land solcAddrMask token1WordE) ≠ ⟨0⟩ := by intro hzero have hsame := - uniswapExtCodeSizeWord_accountMapEquiv hPost (UInt256.land solcAddrMask token1WordS) + extCodeSizeWord_accountMapEquiv hPost (UInt256.land solcAddrMask token1WordS) rw [← hslot] at hzero rw [← hsame] at hzero exact htoken1Code (by simpa [token1WordS] using hzero) @@ -614,13 +614,13 @@ theorem syncToken1GuardTrue_of_code {σ : AccountMap} (fun acc => EVM.Word.ofNat acc.code.size) ≠ ⟨0⟩ := by have hcodeEvmRight : - uniswapExtCodeSizeWord evm0.accountMap (UInt256.land token1WordE solcAddrMask) ≠ + extCodeSizeWord evm0.accountMap (UInt256.land token1WordE solcAddrMask) ≠ ⟨0⟩ := by simpa [u256_land_comm] using hcodeEvm intro hzero apply hcodeEvmRight simpa [State.lookupAccount, Solm.EVM.storageLoad, Account.lookupStorage, - uniswapAddressAtSlot, uniswapExtCodeSizeWord, uniswapSlotWord, token1WordE, + uniswapAddressAtSlot, extCodeSizeWord, uniswapSlotWord, token1WordE, accountAddress_ofUInt256_eq_ofNat_toNat] using hzero have hcodeSourceWord : EVM.Word.ofNat @@ -736,7 +736,7 @@ theorem uniswapSyncBody ⟨1⟩ := by exact not_not.mp hlocked by_cases htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ_evm ⟨12⟩ ⟨0⟩) I)) = ⟨0⟩ @@ -756,7 +756,7 @@ theorem uniswapSyncBody intro hz have hstatus : (if z then (⟨1⟩ : UInt256) else ⟨0⟩) = ⟨0⟩ := by simp [hz] - exact RD.uniswapCallSuccessGuardMissing (okPc := ⟨6192⟩) rd6176 hstatus + exact RD.solcCallSuccessGuardMissing (okPc := ⟨6192⟩) rd6176 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -771,7 +771,7 @@ theorem uniswapSyncBody rw [hz] decide obtain ⟨_, _, rd6194⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨6192⟩) rd6176 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨6192⟩) rd6176 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -850,10 +850,10 @@ theorem uniswapSyncBody simpa [balance0] using uniswapBalanceOfDecode_ok (returndata := o) ho32 obtain ⟨_, _, rd6279⟩ := hsecondExt hzTrue ho32 by_cases htoken1NoCode : - uniswapExtCodeSizeWord σ' + extCodeSizeWord σ' (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ' I)) = ⟨0⟩ · have rdRev := - RD.uniswapExtcodesizeGuardMissing (okPc := ⟨6291⟩) rd6279 htoken1NoCode + RD.solcExtcodesizeGuardMissing (okPc := ⟨6291⟩) rd6279 htoken1NoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -876,7 +876,7 @@ theorem uniswapSyncBody syncToken1GuardTrue evm0S (uniswapUint256Value balance0) := syncToken1GuardTrue_of_code hPostAccounts0 henv0I htoken1NoCode obtain ⟨_, _, _, rd6294⟩ := - RD.uniswapExtcodesizeGuardOkGas (okPc := ⟨6291⟩) rd6279 htoken1NoCode + RD.solcExtcodesizeGuardOkGas (okPc := ⟨6291⟩) rd6279 htoken1NoCode (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) @@ -884,7 +884,7 @@ theorem uniswapSyncBody (by simp only [List.length_cons, List.length_nil]; omega) obtain ⟨cA'', σ'', z1, o1, A_in1, callGas1, _, _, hΘ1, rd6295, ho1Size⟩ := - RD.uniswapStaticcall rd6294 (by native_decide) hdepth + RD.solcStaticcall rd6294 (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) obtain ⟨evm1S, hcall1All, hPostAccounts1, hcreated1, hσ01, hgenesis1, hblocks1, henv1⟩ := diff --git a/Examples/UniswapV2Pair/SyncRuntime.lean b/Examples/UniswapV2Pair/SyncRuntime.lean index fb5aa867..a3d00896 100644 --- a/Examples/UniswapV2Pair/SyncRuntime.lean +++ b/Examples/UniswapV2Pair/SyncRuntime.lean @@ -105,7 +105,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfExtcodesize have rd6114 := rd6113.mstore 6 balanceOfThisSelectorMem (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov) have rd6119 := evm_run rd6114 with [ - uniswapAddress, push1 ⟨4⟩, dup3, add] + address, push1 ⟨4⟩, dup3, add] have rd6120 := rd6119.mstore 3 (balanceOfThisCalldataMem (UInt256.ofNat I.codeOwner.val)) (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by decide) (by evm_ov) @@ -141,7 +141,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfStaticcallReady (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -162,7 +162,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfStaticcallReady uniswapSyncRuntimeFirstBalanceOfExtcodesize (g := g) hcode hsize hwv hsel hperm hunlocked obtain ⟨_, _, rd6174⟩ := - RD.uniswapExtcodesizeGuardOk (okPc := ⟨6172⟩) rd6160 + RD.solcExtcodesizeGuardOk (okPc := ⟨6172⟩) rd6160 (by simpa [σLock, token0Word, token0Clean] using htoken0Code) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) @@ -182,7 +182,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfStaticcallEntry (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -204,7 +204,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfStaticcallEntry uniswapSyncRuntimeFirstBalanceOfExtcodesize (g := g) hcode hsize hwv hsel hperm hunlocked obtain ⟨gasWord, _, _, rd6175⟩ := - RD.uniswapExtcodesizeGuardOkGas (okPc := ⟨6172⟩) rd6160 + RD.solcExtcodesizeGuardOkGas (okPc := ⟨6172⟩) rd6160 (by simpa [σLock, token0Word, token0Clean] using htoken0Code) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) @@ -225,7 +225,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfStaticcallMade (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -261,7 +261,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfStaticcallMade uniswapSyncRuntimeFirstBalanceOfStaticcallEntry (g := g) hcode hsize hwv hsel hperm hunlocked htoken0Code obtain ⟨cA', σ', z, o, A_in, callGas, k', C', hΘ, rd6176, hoSize⟩ := - RD.uniswapStaticcall rd6175 (by native_decide) hdepth + RD.solcStaticcall rd6175 (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) exact ⟨cA', σ', z, o, A_in, callGas, k', C', by simpa [σLock, token0Word, token0Clean, initState] using hΘ, @@ -333,7 +333,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfStaticcallFailureGuard · intro hz have hstatus : (if z then (⟨1⟩ : UInt256) else ⟨0⟩) = ⟨0⟩ := by simp [hz] - exact RD.uniswapCallSuccessGuardMissing (okPc := ⟨6192⟩) rd6176 hstatus + exact RD.solcCallSuccessGuardMissing (okPc := ⟨6192⟩) rd6176 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -344,7 +344,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfStaticcallFailureGuard rw [hz] decide obtain ⟨_, _, rd6194⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨6192⟩) rd6176 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨6192⟩) rd6176 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -361,7 +361,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfStaticcallFailureGuard rw [hz] decide obtain ⟨_, _, rd6194⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨6192⟩) rd6176 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨6192⟩) rd6176 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -389,7 +389,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfStaticcallSuccessGuard (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -439,7 +439,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfStaticcallSuccessGuard rw [hz] decide obtain ⟨k', C', rd6194⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨6192⟩) rd6176 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨6192⟩) rd6176 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -457,7 +457,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfReturnWordDecoded (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -526,7 +526,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfToken1Sloaded (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -589,7 +589,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfSelectorReady (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -660,7 +660,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfCalldataRebuilt (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -709,7 +709,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfCalldataRebuilt balanceOfThisStaticcallActiveWords (by native_decide) mem_cost (by rfl) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) - have rd6239 := evm_run rd6234 with [uniswapAddress, push1 ⟨4⟩, dup3, add] + have rd6239 := evm_run rd6234 with [address, push1 ⟨4⟩, dup3, add] have rd6240 := rd6239.mstore 0 (balanceOfThisRebuiltCalldataMem (UInt256.ofNat I.codeOwner.val) o) balanceOfThisStaticcallActiveWords @@ -730,7 +730,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfToken1Cleaned (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -805,7 +805,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfExtcodesize (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -873,7 +873,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfStaticcallEntry (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -902,7 +902,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfStaticcallEntry (balanceOfThisStaticcallMem (UInt256.ofNat I.codeOwner.val) o) balanceOfThisStaticcallActiveWords o (cA', σ') k C ∧ (z = true → 32 ≤ o.size → - uniswapExtCodeSizeWord σ' + extCodeSizeWord σ' (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ' I)) ≠ ⟨0⟩ → ∃ gasWord k' C', RD uniswapV2PairBytecode I (Sat256.ofUInt256 g) (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨6294⟩ @@ -921,7 +921,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfStaticcallEntry intro hz ho32 htoken1Code obtain ⟨_, _, rd6279⟩ := hguard hz ho32 obtain ⟨gasWord, _, _, rd6294⟩ := - RD.uniswapExtcodesizeGuardOkGas (okPc := ⟨6291⟩) rd6279 htoken1Code + RD.solcExtcodesizeGuardOkGas (okPc := ⟨6291⟩) rd6279 htoken1Code (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by native_decide) @@ -941,7 +941,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfStaticcallMade (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -970,7 +970,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfStaticcallMade (balanceOfThisStaticcallMem (UInt256.ofNat I.codeOwner.val) o) balanceOfThisStaticcallActiveWords o (cA', σ') k C ∧ (z = true → 32 ≤ o.size → - uniswapExtCodeSizeWord σ' + extCodeSizeWord σ' (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ' I)) ≠ ⟨0⟩ → ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z1 : Bool) (o1 : ByteArray) (A_in1 : Substate) (callGas1 : UInt256) @@ -1005,7 +1005,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfStaticcallMade intro hz ho32 htoken1Code obtain ⟨_, _, _, rd6294⟩ := hentry hz ho32 htoken1Code obtain ⟨cA'', σ'', z1, o1, A_in1, callGas1, k', C', hΘ1, rd6295, ho1Size⟩ := - RD.uniswapStaticcall rd6294 (by native_decide) hdepth + RD.solcStaticcall rd6294 (by native_decide) hdepth (by simp only [List.length_cons, List.length_nil]; omega) exact ⟨cA'', σ'', z1, o1, A_in1, callGas1, k', C', by simpa [balanceOfThisRebuiltStaticcallMem, initState] using hΘ1, @@ -1043,7 +1043,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfStaticcallFailureGuard · intro hz1 have hstatus : (if z1 then (⟨1⟩ : UInt256) else ⟨0⟩) = ⟨0⟩ := by simp [hz1] - exact RD.uniswapCallSuccessGuardMissing (okPc := ⟨6311⟩) rd6295 hstatus + exact RD.solcCallSuccessGuardMissing (okPc := ⟨6311⟩) rd6295 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) @@ -1054,7 +1054,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfStaticcallFailureGuard rw [hz1] decide obtain ⟨_, _, rd6313⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨6311⟩) rd6295 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨6311⟩) rd6295 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -1071,7 +1071,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfStaticcallFailureGuard rw [hz1] decide obtain ⟨_, _, rd6313⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨6311⟩) rd6295 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨6311⟩) rd6295 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons]; omega) @@ -1098,7 +1098,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfStaticcallSuccessGuard (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -1127,7 +1127,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfStaticcallSuccessGuard (balanceOfThisStaticcallMem (UInt256.ofNat I.codeOwner.val) o) balanceOfThisStaticcallActiveWords o (cA', σ') k C ∧ (z = true → 32 ≤ o.size → - uniswapExtCodeSizeWord σ' + extCodeSizeWord σ' (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ' I)) ≠ ⟨0⟩ → ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z1 : Bool) (o1 : ByteArray) (A_in1 : Substate) (callGas1 : UInt256) @@ -1177,7 +1177,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfStaticcallSuccessGuard rw [hz1] decide obtain ⟨k'', C'', rd6313⟩ := - RD.uniswapCallSuccessGuardOk (okPc := ⟨6311⟩) rd6295 hstatus + RD.solcCallSuccessGuardOk (okPc := ⟨6311⟩) rd6295 hstatus (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) (by simp only [List.length_cons, List.length_nil]; omega) @@ -1196,7 +1196,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfReturnWordDecoded (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -1225,7 +1225,7 @@ theorem uniswapSyncRuntimeSecondBalanceOfReturnWordDecoded (balanceOfThisStaticcallMem (UInt256.ofNat I.codeOwner.val) o) balanceOfThisStaticcallActiveWords o (cA', σ') k C ∧ (z = true → 32 ≤ o.size → - uniswapExtCodeSizeWord σ' + extCodeSizeWord σ' (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ' I)) ≠ ⟨0⟩ → ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z1 : Bool) (o1 : ByteArray) (A_in1 : Substate) (callGas1 : UInt256) @@ -1319,7 +1319,7 @@ theorem uniswapSyncRuntimeReserveSlotUnpacked (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -1348,7 +1348,7 @@ theorem uniswapSyncRuntimeReserveSlotUnpacked (balanceOfThisStaticcallMem (UInt256.ofNat I.codeOwner.val) o) balanceOfThisStaticcallActiveWords o (cA', σ') k C ∧ (z = true → 32 ≤ o.size → - uniswapExtCodeSizeWord σ' + extCodeSizeWord σ' (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ' I)) ≠ ⟨0⟩ → ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z1 : Bool) (o1 : ByteArray) (A_in1 : Substate) (callGas1 : UInt256) @@ -1414,7 +1414,7 @@ theorem uniswapSyncRuntimeUpdateOverflowGuardOk (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -1443,7 +1443,7 @@ theorem uniswapSyncRuntimeUpdateOverflowGuardOk (balanceOfThisStaticcallMem (UInt256.ofNat I.codeOwner.val) o) balanceOfThisStaticcallActiveWords o (cA', σ') k C ∧ (z = true → 32 ≤ o.size → - uniswapExtCodeSizeWord σ' + extCodeSizeWord σ' (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ' I)) ≠ ⟨0⟩ → ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z1 : Bool) (o1 : ByteArray) (A_in1 : Substate) (callGas1 : UInt256) @@ -1513,7 +1513,7 @@ theorem uniswapSyncRuntimeUpdateElapsedZeroSkipsCumulatives (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -1542,7 +1542,7 @@ theorem uniswapSyncRuntimeUpdateElapsedZeroSkipsCumulatives (balanceOfThisStaticcallMem (UInt256.ofNat I.codeOwner.val) o) balanceOfThisStaticcallActiveWords o (cA', σ') k C ∧ (z = true → 32 ≤ o.size → - uniswapExtCodeSizeWord σ' + extCodeSizeWord σ' (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ' I)) ≠ ⟨0⟩ → ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z1 : Bool) (o1 : ByteArray) (A_in1 : Substate) (callGas1 : UInt256) @@ -1623,7 +1623,7 @@ theorem uniswapSyncRuntimeUpdateElapsedZeroStoresPackedReserves (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -1652,7 +1652,7 @@ theorem uniswapSyncRuntimeUpdateElapsedZeroStoresPackedReserves (balanceOfThisStaticcallMem (UInt256.ofNat I.codeOwner.val) o) balanceOfThisStaticcallActiveWords o (cA', σ') k C ∧ (z = true → 32 ≤ o.size → - uniswapExtCodeSizeWord σ' + extCodeSizeWord σ' (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ' I)) ≠ ⟨0⟩ → ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z1 : Bool) (o1 : ByteArray) (A_in1 : Substate) (callGas1 : UInt256) @@ -1785,7 +1785,7 @@ theorem uniswapSyncRuntimeUpdateElapsedZeroReturns (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0Code : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) ≠ ⟨0⟩) : @@ -1814,7 +1814,7 @@ theorem uniswapSyncRuntimeUpdateElapsedZeroReturns (balanceOfThisStaticcallMem (UInt256.ofNat I.codeOwner.val) o) balanceOfThisStaticcallActiveWords o (cA', σ') k C ∧ (z = true → 32 ≤ o.size → - uniswapExtCodeSizeWord σ' + extCodeSizeWord σ' (UInt256.land solcAddrMask (uniswapSlotWord ⟨7⟩ σ' I)) ≠ ⟨0⟩ → ∃ (cA'' : Batteries.RBSet AccountAddress compare) (σ'' : AccountMap) (z1 : Bool) (o1 : ByteArray) (A_in1 : Substate) (callGas1 : UInt256) @@ -1942,7 +1942,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfMissingCodeReverts (σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨12⟩ ⟨0⟩)) = ⟨1⟩) (htoken0NoCode : - uniswapExtCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) + extCodeSizeWord (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) (UInt256.land solcAddrMask (uniswapSlotWord ⟨6⟩ (sstoreAccountMap I.codeOwner σ ⟨12⟩ ⟨0⟩) I)) = ⟨0⟩) : @@ -1955,7 +1955,7 @@ theorem uniswapSyncRuntimeFirstBalanceOfMissingCodeReverts uniswapSyncRuntimeFirstBalanceOfExtcodesize (g := g) hcode hsize hwv hsel hperm hunlocked have rdRev := - RD.uniswapExtcodesizeGuardMissing (okPc := ⟨6172⟩) rd6160 + RD.solcExtcodesizeGuardMissing (okPc := ⟨6172⟩) rd6160 (by simpa [σLock, token0Word, token0Clean] using htoken0NoCode) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) diff --git a/Examples/VyperERC20/SpecSyntax.lean b/Examples/VyperERC20/SpecSyntax.lean new file mode 100644 index 00000000..6fd44af9 --- /dev/null +++ b/Examples/VyperERC20/SpecSyntax.lean @@ -0,0 +1,72 @@ +import Examples.VyperERC20.Spec +import Solm.Notation + +/-! +# Vyper ERC20 spec in the Solidity-faithful Solm frontend + +The Vyper ERC20 behavior spec is the language-agnostic ERC20 Solm AST +(`VyperERC20.erc20Contract` is `ERC20.erc20Contract`; only the storage layout is +Vyper-specific). Written here with `solidity%` and proven definitionally equal. + +`from`/`to` are Lean keywords, so those parameter names are guillemet-escaped. +Transition order matches `erc20Contract.transitions` exactly. +-/ + +open Solm Solm.Notation + +namespace VyperERC20.Syntax + +def contractSyntax : ContractDecl := solidity% contract ERC20 { + mapping(address => uint256) balanceOf; + mapping(address => mapping(address => uint256)) allowance; + uint256 totalSupply; + + constructor(uint256 initialSupply) { + balanceOf[msg.sender] = initialSupply; + totalSupply = initialSupply; + } + + function approve(address spender, uint256 value) external returns (bool) { + allowance[msg.sender][spender] = value; + return true; + } + + function totalSupply() external returns (uint256) { + return totalSupply; + } + + function transferFrom(address «from», address «to», uint256 value) external returns (bool) { + uint256 currentAllowance = allowance[«from»][msg.sender]; + require(currentAllowance >= value); + uint256 fromBalance = balanceOf[«from»]; + require(fromBalance >= value); + allowance[«from»][msg.sender] = currentAllowance - value; + balanceOf[«from»] = (balanceOf[«from»] - value) as uint256; + uint256 toBalance = balanceOf[«to»]; + uint256 newToBalance = (toBalance + value) as uint256; + balanceOf[«to»] = newToBalance; + return true; + } + + function balanceOf(address owner) external returns (uint256) { + return balanceOf[owner]; + } + + function transfer(address «to», uint256 value) external returns (bool) { + uint256 fromBalance = balanceOf[msg.sender]; + require(fromBalance >= value); + balanceOf[msg.sender] = fromBalance - value; + uint256 toBalance = balanceOf[«to»]; + uint256 newToBalance = (toBalance + value) as uint256; + balanceOf[«to»] = newToBalance; + return true; + } + + function allowance(address owner, address spender) external returns (uint256) { + return allowance[owner][spender]; + } +} + +theorem contractSyntax_eq : contractSyntax = VyperERC20.erc20Contract := by rfl + +end VyperERC20.Syntax diff --git a/README.md b/README.md index f716e82a..9cf792b6 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,49 @@ -# EquiVM: Foundational refinement proofs for deployed EVM bytecode +# EquiVM: Foundational refinement proofs for EVM bytecode -EquiVM is a framework for proving that a piece of EVM bytecode *refines* a high-level program, written in a specification language called Sol⁻ (pronounced Sol minor). +EquiVM is a framework that allows proving that a piece of EVM bytecode *refines* +a high-level program, written in a specification language called Sol⁻ +(pronounced Sol minor). -Sol⁻ is a small imperative language, inspired by Solidity, which is however not implemented. It serves as a high-level, source-language agnostic human-readable view of the bytecode, and can be certified equivalent to it. Sol⁻ is parametric in the contract's storage layout, so one can describe bytecode generated by different compilers (or no compiler at all). +The goal of the project is to prove that EVM +bytecode refines a high-level, formal, user-readable specification of a smart +contract. After verification, the Sol⁻ specification can serve in further +verification of the contract's behavior or in human audits. -EquiVM provides a framework for stating and proving that the bytecode implements the Sol⁻ specification. This includes semantics for the EVM, semantics rules for Sol⁻, the formal specification of the ABI, and the refinement relation between Sol⁻ and EVM. Furthermore, EquiVM provides a library of compositional lemmas and tactics to help with the proofs. +Refinement proofs are intended to be generated by autonomous LLM agents. We are +currently evaluating the capabilities of LLMs to provide such refinement proofs +autonomously and their cost (section Case Studies). The framework has been +designed with this goal in mind. -Once refinement is established, one can prove properties of the Sol⁻ specification and transfer them to the bytecode, without needing to reason about the EVM directly or trust the compiler that produced it. -The primary ... for such proofs is to be generated by LLMs and be checked against the Lean kernel. The section Case Studies below lists the contracts that have been verified so far, and the status of their proofs. + +## Sol⁻ +Sol⁻ is a small imperative language, inspired by Solidity and designed to be +syntactically close to it. However, Sol⁻ is just a semantic specification +language and is not implemented by any compiler. It serves as a formal +high-level, source-language agnostic human-readable view of the bytecode, and +can be certified equivalent to it. Sol⁻ is parametric in the contract's storage +layout, so one can describe bytecode generated by different compilers (or no +compiler at all). + +EquiVM provides the tools for stating and proving that the bytecode implements +the Sol⁻ specification. This includes semantics for the EVM, semantics rules for +Sol⁻, the formal specification of the ABI, and the refinement relation between +Sol⁻ and EVM. Furthermore, EquiVM provides a library of compositional lemmas and +tactics to help with the proofs. + +## Refinement + +The top-level theorem of EquiVM is a *refinement* theorem, which states that the +bytecode faithfully implements the semantics of the Sol⁻ specification. The +refinement relation is defined in [`Solm/Equiv.lean`](Solm/Equiv.lean). + +Once refinement is established, one can reason about the bytecode at the Sol⁻ +level. This aleviates the need to both reason about low-level EVM bytecode and +to trust the compiler that produced it. + +The primary ... for such proofs is to be generated by LLMs and be checked +against the Lean kernel. The section Case Studies below lists the contracts that +have been verified so far, and the status of their proofs. +Once refinement is established, one can reason about the bytecode at the Sol⁻ level. +This alleviates the need to both reason about low-level EVM bytecode and +to trust the compiler that produced it. ## Architecture -- **EVM semantics** +- **EVM semantics** ([`EVM/`](EVM/)) We build on top of the [EVMLean](https://github.com/lefterislazar/EVMLean) semantics, a formal model of the EVM in Lean. The semantics is a port of Nethermind's [EVMYulLean](https://github.com/NethermindEth/EVMYulLean) to a newer version of Lean with a few other adjustments. The EVM semantics is executable and it passes the official EVM conformance test suite. - **Sol⁻** ([`Solm/`](Solm/)) @@ -77,27 +47,17 @@ can describe bytecode that different compilers lay out differently. --> A library of compositional lemmas and tactics to help with the proofs. Among other things, it includes forward symbolic-execution combinators, dispatcher/ABI/storage lemmas, and external-call bridges. -## Repository layout - -- [`EVM/`](EVM/): TODO this just links to the repo?. - -- [`ABI/`](ABI/): ABI encoding and decoding, function signatures, and selectors. - -- [`Solm/`](Solm/): the Sol⁻ language (syntax, semantics, surface notation, and - storage layouts) and the refinement relation itself in [`Equiv.lean`](Solm/Equiv.lean). +- **Examples** ([`Examples/`](Examples/)) + Contracts (small or large ones) that were proved correct using LLMs in parallel to the development of the reasoning library. The proofs drove the design of the library and its lemmas and tactics. The file [`Examples/README.md`](Examples/README.md) is the per-contract status index. -- [`Reasoning/`](Reasoning/): the compositional proof library that discharges - refinement. +- **Benchmarks** ([`Benchmarks/`](Benchmarks/)) + Larger case studies of real contracts that were proved correct by LLMs. The file [`Benchmarks/README.md`](Benchmarks/README.md) is the per-contract status index. +- **Miscellaneous** ([`Misc/`](Misc/)) + Miscellaneous files, including a template for new contracts and a prompt for LLMs. -- [`Examples/`](Examples/): small contracts exercising specific features (see - [Case studies](#case-studies)). - -- [`Benchmarks/`](Benchmarks/): real deployed contracts; - [`Benchmarks/README.md`](Benchmarks/README.md) is the per-contract status index. - -- [`Proofs/`](Proofs/): proof-of-concept properties proved for Sol⁻ specifications - +- **Proofs** ([`Proofs/`](Proofs/)) + Proof-of-concept high-level proof on Sol⁻ specifications. ## Building @@ -110,33 +70,29 @@ lake build # core library lake build Examples Benchmarks # the proof developments ``` -## Case studies +## Proving a contract correct + +To prove a new contract correct, create a new directory following the template +in `Misc/ContractTemplate/`. The prompt in `Misc/Prompt.md` is the recommended +way to instruct the LLM to produce a refinement proof. -Each contract directory holds the source, the checked-in creation/runtime -bytecode, the Sol⁻ specification, and the proof. +The Sol⁻ specification is typically pretty close to the Solidity source, but it +is not a translation of it. -[`Examples/`](Examples/) are small contracts, each targeting a feature that makes -bytecode proofs hard — loops, nested and packed storage, dynamic calldata, typed -and raw external calls, checked and wrapping arithmetic, reentrancy locks, inline -assembly, the `ecrecover` precompile, and Vyper output. Their proofs drove the -design of the `Reasoning/` library. +LLMs can also be used to automate the Sol⁻ specification generation, or audit +semantic faithfulness before attempting a proof. -[`Benchmarks/`](Benchmarks/) are real contracts verified against their on-chain -bytecode across several `solc` generations and optimizer settings: most of the -MakerDAO stablecoin system (`Dss`), WETH9, the Nouns auction house, and targets -from OpenZeppelin, Compound III, EAS, Safe, Uniswap, and ERC721. -[`Benchmarks/README.md`](Benchmarks/README.md) is the per-contract status index. ## Trusted computing base An EquiVM certificate is a Lean theorem, so what must be trusted is small: the -Lean kernel and standard library axioms; that the EVM model faithfully formalizes -the EVM (backed by the official EVM test suite); that the refinement relation -captures the intended equivalence (it deliberately does not compare gas, substate, -events, or revert payloads); a handful of per-contract Keccak selector facts, -since Keccak is an opaque foreign constant; and Lean's compiled evaluator via -`native_decide`. The proof-producing agent, tactics, and macros are not trusted — -the kernel re-checks every proof term. +Lean kernel and standard library axioms; that the EVM model faithfully +formalizes the EVM (backed by the official EVM test suite); that the refinement +relation captures the intended equivalence (it deliberately does not compare +gas, substate, events, or revert payloads); a handful of per-contract Keccak +selector facts, since Keccak is an opaque foreign constant; and Lean's compiled +evaluator via `native_decide`. The proof-producing agent, tactics, and macros +are not trusted — the kernel re-checks every proof term. ## Paper diff --git a/Reasoning/EVMWord.lean b/Reasoning/EVMWord.lean index 49f54f86..62148eb1 100644 --- a/Reasoning/EVMWord.lean +++ b/Reasoning/EVMWord.lean @@ -8,9 +8,9 @@ import Mathlib.Data.Nat.Digits.Lemmas The EVM executes arithmetic and comparisons on 256-bit stack words, even when the Solidity source type is narrower. This file collects generic `UInt256` facts used by bytecode traces: no-wrap -`toNat` lemmas, unsigned comparisons, and signed `SLT` facts parameterized by the comparison -literal. Memory byte-level facts stay in `Reasoning.Memory`; solc conventions stay in -`Reasoning.Solc`. +`toNat` lemmas, arithmetic/bitwise normalization, unsigned comparisons, signed `SLT` facts +parameterized by the comparison literal, `compare`-order instances, and the bitwise word-rounding +behind solc's memory allocation. Memory byte-level facts stay in `Reasoning.Memory`. -/ open Ethereum Ethereum.EVM @@ -218,9 +218,7 @@ theorem usub_uadd_lit_cancel_mod {base n : ℕ} haddn, ulit_toNat' base hbase, ulit_toNat' n hn] omega -/-! ## Unsigned comparisons and small arithmetic helpers -/ - -/-! ### Arithmetic and bitwise normalization -/ +/-! ## Arithmetic and bitwise normalization -/ theorem nat_land_comm (a b : ℕ) : Nat.land a b = Nat.land b a := by apply Nat.eq_of_testBit_eq @@ -495,6 +493,8 @@ theorem u256_land_high_mask_eq_self (w : UInt256) {k : Nat} (hk : k ≤ 256) rw [hdiv] exact Nat.mod_eq_of_lt w.val.isLt +/-! ## Unsigned comparisons -/ + /-- `LT` returns `1` when the strict order holds. -/ theorem ult_one {a b : UInt256} (h : a.toNat < b.toNat) : UInt256.lt a b = ⟨1⟩ := by show UInt256.fromBool (decide (a < b)) = ⟨1⟩ diff --git a/Reasoning/ExternalCall.lean b/Reasoning/ExternalCall.lean index 3f1f2631..f857f98f 100644 --- a/Reasoning/ExternalCall.lean +++ b/Reasoning/ExternalCall.lean @@ -167,6 +167,94 @@ theorem typedCallViaEVM_static_storage_findD_of_accountMapEquiv {cfg : Config} rw [henv, ← hstaticSlot] exact hpreSlot.symm +/-- Shared Θ-transport core of call/delegatecall transport: an EVM-side `Θ` witness moves +across `accountMapEquiv` to a Solm-side `Θ` witness with the same created accounts, success +flag, and output, and an equivalent post-call account map. Generic in the caller/origin/ +recipient addresses, values, and permission bit — exactly where `CALL` and `DELEGATECALL` +differ. -/ +private theorem Theta_transport_accountMapEquiv + {evm_evm evm_solm : EVM.State} {tgt : EVM.Address} + {s o r : AccountAddress} {v v' callGas : UInt256} {w z : Bool} + {calldata out : ByteArray} {A_in : Substate} + {cA' : Batteries.RBSet AccountAddress compare} {σ' : AccountMap} + {g' : UInt256} {A' : Substate} + (hAccounts : accountMapEquiv evm_evm.accountMap evm_solm.accountMap) + (hOriginalAccounts : evm_evm.σ₀ = evm_solm.σ₀) + (hCreated : evm_solm.createdAccounts = evm_evm.createdAccounts) + (hGenesis : evm_solm.genesisBlockHeader = evm_evm.genesisBlockHeader) + (hBlocks : evm_solm.blocks = evm_evm.blocks) + (hTheta : (cA', σ', g', A', z, out) = + Ethereum.EVM.Θ evm_evm.executionEnv.blobVersionedHashes evm_evm.createdAccounts + evm_evm.genesisBlockHeader evm_evm.blocks evm_evm.accountMap evm_evm.σ₀ A_in + s o r (toExecute evm_evm.accountMap tgt) callGas + (UInt256.ofNat evm_evm.executionEnv.gasPrice) v v' calldata + (evm_evm.executionEnv.depth + 1) evm_evm.executionEnv.header w) : + ∃ (σ'_solm : AccountMap) (g'' : UInt256) (A'_solm : Substate), + (cA', σ'_solm, g'', A'_solm, z, out) = + Ethereum.EVM.Θ evm_evm.executionEnv.blobVersionedHashes evm_solm.createdAccounts + evm_solm.genesisBlockHeader evm_solm.blocks evm_solm.accountMap evm_solm.σ₀ A_in + s o r (toExecute evm_solm.accountMap tgt) callGas + (UInt256.ofNat evm_evm.executionEnv.gasPrice) v v' calldata + (evm_evm.executionEnv.depth + 1) evm_evm.executionEnv.header w ∧ + accountMapEquiv σ' σ'_solm := by + have h_ext_eq : accountMapExtensionalEq evm_evm.accountMap evm_solm.accountMap := + accountMapExtensionalEq_of_accountMapEquiv hAccounts + generalize htheta_solm : + Ethereum.EVM.Θ evm_evm.executionEnv.blobVersionedHashes evm_solm.createdAccounts + evm_solm.genesisBlockHeader evm_solm.blocks evm_solm.accountMap evm_solm.σ₀ A_in + s o r (toExecute evm_solm.accountMap tgt) callGas + (UInt256.ofNat evm_evm.executionEnv.gasPrice) v v' calldata + (evm_evm.executionEnv.depth + 1) evm_evm.executionEnv.header w = thetaRes + have hcode_equiv : + toExecute evm_evm.accountMap tgt = toExecute evm_solm.accountMap tgt := + accountMapExtensionalEq_toExecute h_ext_eq tgt + have htheta_solm' : + Ethereum.EVM.Θ evm_evm.executionEnv.blobVersionedHashes evm_evm.createdAccounts + evm_evm.genesisBlockHeader evm_evm.blocks evm_solm.accountMap evm_evm.σ₀ A_in + s o r (toExecute evm_evm.accountMap tgt) callGas + (UInt256.ofNat evm_evm.executionEnv.gasPrice) v v' calldata + (evm_evm.executionEnv.depth + 1) evm_evm.executionEnv.header w = + (thetaRes.1, thetaRes.2.1, thetaRes.2.2.1, thetaRes.2.2.2.1, + thetaRes.2.2.2.2.1, thetaRes.2.2.2.2.2) := by + rw [← htheta_solm] + rw [hCreated, ← hOriginalAccounts, hGenesis, hBlocks, hcode_equiv] + let a1 : AccountAddress := ⟨0, by simp [AccountAddress.size]⟩ + have hTheta_rel := + (accountMap_extensionality_of_Theta_and_Lambda + (blobVersionedHashes := evm_evm.executionEnv.blobVersionedHashes) + (createdAccounts := evm_evm.createdAccounts) + (genesisBlockHeader := evm_evm.genesisBlockHeader) + (blocks := evm_evm.blocks) + (σ₁ := evm_evm.accountMap) + (σ₂ := evm_solm.accountMap) + (σ₀ := evm_evm.σ₀) + (A := A_in) + (s := s) + (o := o) + (r := r) + (g := callGas) + (p := UInt256.ofNat evm_evm.executionEnv.gasPrice) + (v := v) + (v' := v') + (d := calldata) + (i := ByteArray.empty) + (ζ := none) + (H := evm_evm.executionEnv.header) + (w := w) + a1 a1 + (toExecute evm_evm.accountMap tgt) + cA' thetaRes.1 + σ' thetaRes.2.1 + g' thetaRes.2.2.1 + A' thetaRes.2.2.2.1 + z thetaRes.2.2.2.2.1 + out thetaRes.2.2.2.2.2 + (evm_evm.executionEnv.depth + 1) + h_ext_eq).1 hTheta.symm htheta_solm' + refine ⟨thetaRes.2.1, thetaRes.2.2.1, thetaRes.2.2.2.1, ?_, ?_⟩ + · rw [hTheta_rel.1, hTheta_rel.2.2.2.1, hTheta_rel.2.2.2.2.1] + · exact accountMapEquiv_of_accountMapExtensionalEq hTheta_rel.2.2.2.2.2 + /-- `Θ` respects observationally equivalent account maps. If a typed external call is possible from an EVM state, and a Solm-side state differs only by @@ -201,66 +289,13 @@ theorem typedCallViaEVM_accountMapEquiv {cfg : Config} {evm_evm evm_solm evm'_ev | callMade hvalue hTheta hevm' hvalue' hdepth => obtain ⟨callGas, A_in, hTheta⟩ := hTheta rename_i valueWord cA' σ' g' A' - generalize htheta_solm : - Ethereum.EVM.Θ evm_solm.executionEnv.blobVersionedHashes evm_solm.createdAccounts - evm_solm.genesisBlockHeader evm_solm.blocks evm_solm.accountMap evm_solm.σ₀ A_in - evm_solm.executionEnv.codeOwner evm_solm.executionEnv.sender tgt - (toExecute evm_solm.accountMap tgt) callGas - (UInt256.ofNat evm_solm.executionEnv.gasPrice) valueWord valueWord calldata - (evm_solm.executionEnv.depth + 1) evm_solm.executionEnv.header - callPerm = thetaRes - have hcode_equiv : - toExecute evm_evm.accountMap tgt = toExecute evm_solm.accountMap tgt := - accountMapExtensionalEq_toExecute h_ext_eq tgt - have htheta_solm' : - Ethereum.EVM.Θ evm_evm.executionEnv.blobVersionedHashes evm_evm.createdAccounts - evm_evm.genesisBlockHeader evm_evm.blocks evm_solm.accountMap evm_evm.σ₀ A_in - evm_evm.executionEnv.codeOwner evm_evm.executionEnv.sender tgt - (toExecute evm_evm.accountMap tgt) callGas - (UInt256.ofNat evm_evm.executionEnv.gasPrice) valueWord valueWord calldata - (evm_evm.executionEnv.depth + 1) evm_evm.executionEnv.header - callPerm = - (thetaRes.1, thetaRes.2.1, thetaRes.2.2.1, thetaRes.2.2.2.1, - thetaRes.2.2.2.2.1, thetaRes.2.2.2.2.2) := by - rw [← htheta_solm] - rw [hCreated, ← hOriginalAccounts, hGenesis, hBlocks, hEnv, hcode_equiv] - let a1 : AccountAddress := ⟨0, by simp [AccountAddress.size]⟩ - have hTheta_rel := - (accountMap_extensionality_of_Theta_and_Lambda - (blobVersionedHashes := evm_evm.executionEnv.blobVersionedHashes) - (createdAccounts := evm_evm.createdAccounts) - (genesisBlockHeader := evm_evm.genesisBlockHeader) - (blocks := evm_evm.blocks) - (σ₁ := evm_evm.accountMap) - (σ₂ := evm_solm.accountMap) - (σ₀ := evm_evm.σ₀) - (A := A_in) - (s := evm_evm.executionEnv.codeOwner) - (o := evm_evm.executionEnv.sender) - (r := tgt) - (g := callGas) - (p := UInt256.ofNat evm_evm.executionEnv.gasPrice) - (v := valueWord) - (v' := valueWord) - (d := calldata) - (i := ByteArray.empty) - (ζ := none) - (H := evm_evm.executionEnv.header) - (w := callPerm) - a1 a1 - (toExecute evm_evm.accountMap tgt) - cA' thetaRes.1 - σ' thetaRes.2.1 - g' thetaRes.2.2.1 - A' thetaRes.2.2.2.1 - z thetaRes.2.2.2.2.1 - out thetaRes.2.2.2.2.2 - (evm_evm.executionEnv.depth + 1) - h_ext_eq).1 hTheta.symm htheta_solm' - have hCreated' : evm'_evm.createdAccounts = thetaRes.1 := by - simp [hevm', hTheta_rel.1] + obtain ⟨σ'_solm, g''_solm, A'_solm, hTheta_s', hσ'⟩ := + Theta_transport_accountMapEquiv (tgt := tgt) hAccounts hOriginalAccounts hCreated + hGenesis hBlocks hTheta + have hCreated' : evm'_evm.createdAccounts = cA' := by simp [hevm'] + -- restate the transported Θ witness in the Solm-side environment have hTheta_s : - (evm'_evm.createdAccounts, thetaRes.2.1, thetaRes.2.2.1, thetaRes.2.2.2.1, z, out) = + (evm'_evm.createdAccounts, σ'_solm, g''_solm, A'_solm, z, out) = Ethereum.EVM.Θ evm_solm.executionEnv.blobVersionedHashes evm_solm.createdAccounts evm_solm.genesisBlockHeader evm_solm.blocks evm_solm.accountMap evm_solm.σ₀ A_in evm_solm.executionEnv.codeOwner evm_solm.executionEnv.sender tgt @@ -268,11 +303,10 @@ theorem typedCallViaEVM_accountMapEquiv {cfg : Config} {evm_evm evm_solm evm'_ev (UInt256.ofNat evm_solm.executionEnv.gasPrice) valueWord valueWord calldata (evm_solm.executionEnv.depth + 1) evm_solm.executionEnv.header callPerm := by - rw [hTheta_rel.2.2.2.1, hTheta_rel.2.2.2.2.1] - rw [hCreated'] - exact htheta_solm.symm - use thetaRes.2.1 - use thetaRes.2.2.2.1 + rw [hEnv, hCreated'] + exact hTheta_s' + use σ'_solm + use A'_solm constructor · refine ⟨calldata, hdecode, ?_⟩ exact callViaEVM.callMade (perm := callPerm) hvalue @@ -282,8 +316,7 @@ theorem typedCallViaEVM_accountMapEquiv {cfg : Config} {evm_evm evm_solm evm'_ev exact hvalue') (by rw [hEnv] exact hdepth) - · have hσext : accountMapExtensionalEq σ' thetaRes.2.1 := hTheta_rel.2.2.2.2.2 - simpa [hevm'] using accountMapEquiv_of_accountMapExtensionalEq hσext + · simpa [hevm'] using hσ' | callNotMade hsubstate hevm' hvalue => let A' := (State.addAccessedAccount evm_solm tgt).substate use evm_solm.accountMap @@ -355,7 +388,6 @@ theorem typedCallViaEVM_callMade_accountMapEquiv {cfg : Config} (evm_solm := evm_solm) hcallE hAccounts hOriginalAccounts hCreated hGenesis hBlocks hSubstate hEnv - /-- `initState`-specialized form of `typedCallViaEVM_accountMapEquiv`. This is the shape runtime-equivalence examples usually need: the EVM and Solm runs start from @@ -488,7 +520,7 @@ theorem callViaEVM_accountMapEquiv {storage : StorageLayout} callViaEVM_accountMapEquiv_perm (storage := storage) hcall hAccounts hOriginalAccounts hCreated hGenesis hBlocks hSubstate hEnv -/-- `initState`-specialized raw low-level call transport. -/ +/-- `initState`-specialized raw low-level call transport, generic over the `callPerm` flag. -/ theorem callViaEVM_initState_accountMapEquiv_perm {storage : StorageLayout} {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} {evm'_evm : EVM.State} {tgt : EVM.Address} {value : ℤ} {calldata : ByteArray} @@ -515,7 +547,7 @@ theorem callViaEVM_initState_accountMapEquiv_perm {storage : StorageLayout} (by simp [initState]) (by simp [initState]) -/-- `initState`-specialized raw low-level call transport. -/ +/-- `initState`-specialized raw low-level call transport at the default call permission. -/ theorem callViaEVM_initState_accountMapEquiv {storage : StorageLayout} {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} {evm'_evm : EVM.State} {tgt : EVM.Address} {value : ℤ} {calldata : ByteArray} @@ -534,7 +566,8 @@ theorem callViaEVM_initState_accountMapEquiv {storage : StorageLayout} accountMapEquiv evm'_evm.accountMap σ'_solm := callViaEVM_initState_accountMapEquiv_perm (storage := storage) hcall hAccounts -/-- `EVMStateEquiv`-returning form of raw low-level call transport. -/ +/-- `EVMStateEquiv`-returning form of raw low-level call transport, generic over the `callPerm` + flag. -/ theorem callViaEVM_initState_EVMStateEquiv_perm {storage : StorageLayout} {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} {evm'_evm : EVM.State} {tgt : EVM.Address} {value : ℤ} {calldata : ByteArray} @@ -560,7 +593,8 @@ theorem callViaEVM_initState_EVMStateEquiv_perm {storage : StorageLayout} callViaEVM_initState_accountMapEquiv_perm (storage := storage) hcall hAccounts exact ⟨σ'_solm, A'_solm, hcall_solm, hEnv, rfl, hσ'⟩ -/-- `EVMStateEquiv`-returning form of raw low-level call transport. -/ +/-- `EVMStateEquiv`-returning form of raw low-level call transport at the default call + permission. -/ theorem callViaEVM_initState_EVMStateEquiv {storage : StorageLayout} {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} {evm'_evm : EVM.State} {tgt : EVM.Address} {value : ℤ} {calldata : ByteArray} @@ -617,72 +651,17 @@ theorem delegateCallViaEVM_accountMapEquiv createdAccounts := evm'_evm.createdAccounts }, out) ∧ accountMapEquiv evm'_evm.accountMap σ'_solm := by - have h_ext_eq : accountMapExtensionalEq evm_evm.accountMap evm_solm.accountMap := - accountMapExtensionalEq_of_accountMapEquiv hAccounts cases hcall with | callMade hTheta hevm' hdepth => obtain ⟨callGas, A_in, hTheta⟩ := hTheta rename_i cA' σ' g' A' - generalize htheta_solm : - Ethereum.EVM.Θ evm_solm.executionEnv.blobVersionedHashes evm_solm.createdAccounts - evm_solm.genesisBlockHeader evm_solm.blocks evm_solm.accountMap evm_solm.σ₀ A_in - evm_solm.executionEnv.source evm_solm.executionEnv.sender - evm_solm.executionEnv.codeOwner (toExecute evm_solm.accountMap tgt) callGas - (UInt256.ofNat evm_solm.executionEnv.gasPrice) (⟨0⟩ : UInt256) - evm_solm.executionEnv.weiValue calldata (evm_solm.executionEnv.depth + 1) - evm_solm.executionEnv.header evm_solm.executionEnv.perm = thetaRes - have hcode_equiv : - toExecute evm_evm.accountMap tgt = toExecute evm_solm.accountMap tgt := - accountMapExtensionalEq_toExecute h_ext_eq tgt - have htheta_solm' : - Ethereum.EVM.Θ evm_evm.executionEnv.blobVersionedHashes evm_evm.createdAccounts - evm_evm.genesisBlockHeader evm_evm.blocks evm_solm.accountMap evm_evm.σ₀ A_in - evm_evm.executionEnv.source evm_evm.executionEnv.sender - evm_evm.executionEnv.codeOwner (toExecute evm_evm.accountMap tgt) callGas - (UInt256.ofNat evm_evm.executionEnv.gasPrice) (⟨0⟩ : UInt256) - evm_evm.executionEnv.weiValue calldata (evm_evm.executionEnv.depth + 1) - evm_evm.executionEnv.header evm_evm.executionEnv.perm = - (thetaRes.1, thetaRes.2.1, thetaRes.2.2.1, thetaRes.2.2.2.1, - thetaRes.2.2.2.2.1, thetaRes.2.2.2.2.2) := by - rw [← htheta_solm] - rw [hCreated, ← hOriginalAccounts, hGenesis, hBlocks, hEnv, hcode_equiv] - let a1 : AccountAddress := ⟨0, by simp [AccountAddress.size]⟩ - have hTheta_rel := - (accountMap_extensionality_of_Theta_and_Lambda - (blobVersionedHashes := evm_evm.executionEnv.blobVersionedHashes) - (createdAccounts := evm_evm.createdAccounts) - (genesisBlockHeader := evm_evm.genesisBlockHeader) - (blocks := evm_evm.blocks) - (σ₁ := evm_evm.accountMap) - (σ₂ := evm_solm.accountMap) - (σ₀ := evm_evm.σ₀) - (A := A_in) - (s := evm_evm.executionEnv.source) - (o := evm_evm.executionEnv.sender) - (r := evm_evm.executionEnv.codeOwner) - (g := callGas) - (p := UInt256.ofNat evm_evm.executionEnv.gasPrice) - (v := (⟨0⟩ : UInt256)) - (v' := evm_evm.executionEnv.weiValue) - (d := calldata) - (i := ByteArray.empty) - (ζ := none) - (H := evm_evm.executionEnv.header) - (w := evm_evm.executionEnv.perm) - a1 a1 - (toExecute evm_evm.accountMap tgt) - cA' thetaRes.1 - σ' thetaRes.2.1 - g' thetaRes.2.2.1 - A' thetaRes.2.2.2.1 - z thetaRes.2.2.2.2.1 - out thetaRes.2.2.2.2.2 - (evm_evm.executionEnv.depth + 1) - h_ext_eq).1 hTheta.symm htheta_solm' - have hCreated' : evm'_evm.createdAccounts = thetaRes.1 := by - simp [hevm', hTheta_rel.1] + obtain ⟨σ'_solm, g''_solm, A'_solm, hTheta_s', hσ'⟩ := + Theta_transport_accountMapEquiv (tgt := tgt) hAccounts hOriginalAccounts hCreated + hGenesis hBlocks hTheta + have hCreated' : evm'_evm.createdAccounts = cA' := by simp [hevm'] + -- restate the transported Θ witness in the Solm-side environment have hTheta_s : - (evm'_evm.createdAccounts, thetaRes.2.1, thetaRes.2.2.1, thetaRes.2.2.2.1, z, out) = + (evm'_evm.createdAccounts, σ'_solm, g''_solm, A'_solm, z, out) = Ethereum.EVM.Θ evm_solm.executionEnv.blobVersionedHashes evm_solm.createdAccounts evm_solm.genesisBlockHeader evm_solm.blocks evm_solm.accountMap evm_solm.σ₀ A_in evm_solm.executionEnv.source evm_solm.executionEnv.sender @@ -690,16 +669,14 @@ theorem delegateCallViaEVM_accountMapEquiv (UInt256.ofNat evm_solm.executionEnv.gasPrice) (⟨0⟩ : UInt256) evm_solm.executionEnv.weiValue calldata (evm_solm.executionEnv.depth + 1) evm_solm.executionEnv.header evm_solm.executionEnv.perm := by - rw [hTheta_rel.2.2.2.1, hTheta_rel.2.2.2.2.1] - rw [hCreated'] - exact htheta_solm.symm - use thetaRes.2.1 - use thetaRes.2.2.2.1 + rw [hEnv, hCreated'] + exact hTheta_s' + use σ'_solm + use A'_solm constructor · exact delegateCallViaEVM.callMade ⟨callGas, A_in, hTheta_s⟩ rfl (by rw [hEnv]; exact hdepth) - · have hσext : accountMapExtensionalEq σ' thetaRes.2.1 := hTheta_rel.2.2.2.2.2 - simpa [hevm'] using accountMapEquiv_of_accountMapExtensionalEq hσext + · simpa [hevm'] using hσ' | callNotMade hsubstate hevm' hdepth => let A' := (State.addAccessedAccount evm_solm tgt).substate use evm_solm.accountMap diff --git a/Reasoning/Memory.lean b/Reasoning/Memory.lean index b3b3be54..08c88d66 100644 --- a/Reasoning/Memory.lean +++ b/Reasoning/Memory.lean @@ -60,8 +60,8 @@ theorem fromBytes'_append_zeros (l : List UInt8) (k : ℕ) : | nil => simpa using fromBytes'_replicate_zero k | cons b bs ih => simp only [List.cons_append, fromBytes']; rw [ih] -/-- The little-endian round-trip `fromBytes' (toBytes' x) = x` (re-proved; evmlean's is - `private`). -/ +/-- The little-endian round-trip `fromBytes' (toBytes' x) = x` (evmlean's version is `private`, + so it is proved here). -/ theorem fromBytes'_toBytes' (x : ℕ) : fromBytes' (toBytes' x) = x := by match x with | .zero => simp [toBytes', fromBytes'] @@ -282,8 +282,7 @@ theorem empty_readWithPadding_word_zero : rfl /-- **MSTORE write.** Storing a 32-byte word `v` at offset `off ≥ mem.size` appends it past a - zero gap: `mem ++ zeroes (off - mem.size) ++ v.toByteArray`. (Generic, contract-agnostic; - `off - mem.size < USize.size` rules out the address wrap.) -/ + zero gap: `mem ++ zeroes (off - mem.size) ++ v.toByteArray`. (Generic, contract-agnostic.) -/ theorem toByteArray_write_eq (v : UInt256) (mem : ByteArray) (off : ℕ) (hoff : mem.size ≤ off) (_hb : off - mem.size < USize.size) : (UInt256.toByteArray v).write 0 mem off 32 @@ -409,7 +408,7 @@ theorem empty_append (A : ByteArray) : ByteArray.empty ++ A = A := by theorem lt_usize (n : ℕ) (h : n < 2 ^ 32) : n < USize.size := by rcases System.Platform.numBits_eq with he | he <;> rw [USize.size, he] <;> omega -/-- The size of a small `zeroes` block (no `USize` wrap). -/ +/-- The size of a `zeroes` block. -/ theorem zeroes_ofNat_size (n : ℕ) (_h : n < 2 ^ 32) : (ffi.ByteArray.zeroes n).size = n := by rw [ByteArray_zeroes_size] @@ -1049,7 +1048,7 @@ theorem toByteArray_write_read_window_of_gap rw [show off + start - off = start by omega, show off + start + len - off = start + len by omega] -/-! ## 4a. Two-word scratch memory for mapping-slot hashes -/ +/-! ## 4. Two-word scratch memory for mapping-slot hashes -/ noncomputable def wordAt0Mem (word : UInt256) (mem : ByteArray) : ByteArray := (UInt256.toByteArray word).write 0 mem 0 32 @@ -1296,7 +1295,7 @@ theorem readBytes32_len (cd : ByteArray) : /-- **EVM selector extraction.** `(uInt256OfByteArray (readBytes cd 0 32)) >>> 224` — the EVM's `CALLDATALOAD; PUSH 0xe0; SHR` — equals the big-endian number of `cd`'s first four bytes - (for `4 ≤ cd.size`). Fully proved; nothing opaque. -/ + (for `4 ≤ cd.size`). -/ theorem selector_toNat (cd : ByteArray) (h : 4 ≤ cd.size) : (UInt256.shiftRight (uInt256OfByteArray (ByteArray.readBytes cd 0 32)) ⟨224⟩).toNat = fromBytesBigEndian (cd.data.toList.take 4) := by @@ -1321,7 +1320,7 @@ theorem selector_toNat (cd : ByteArray) (h : 4 ≤ cd.size) : rw [readBytes32_toList, List.take_append_of_le_length (by rw [List.length_take]; omega), List.take_take, show min 4 32 = 4 from rfl] -/-! ## Generic `MLOAD` word-value helper -/ +/-! ## 7. Generic `MLOAD` word-value helper -/ /-- Simplify the value pushed by `MLOAD` when the offset is in bounds and below the active-word limit, leaving the byte read uninterpreted. -/ @@ -1344,7 +1343,7 @@ theorem mloadWordValue_of_readWithPadding {mem : ByteArray} {aw off v : UInt256} rw [if_neg (not_or.mpr ⟨by omega, haw⟩), hread, fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] -/-! ## ABI calldata decode coupling (shared by every contract with arguments) -/ +/-! ## 8. ABI calldata decode coupling (shared by every contract with arguments) -/ /-- `uInt256OfByteArray` is the big-endian decode then `ofNat`. -/ theorem uInt256OfByteArray_eq (arr : ByteArray) : @@ -1542,7 +1541,7 @@ theorem decode_word_at_eq_any (cd : ByteArray) (off : ℕ) (hsz : off + 32 ≤ c rw [byteArray_toList_eq (cd.readBytes off 32), readBytes_at_toList_any _ _ hsz] simp [byteArray_toList_eq] -/-! ## Mapping storage-slot and load coupling +/-! ## 9. Mapping storage-slot and load coupling Solidity stores `mapping[key]` at base slot `s` in `keccak256(key ‖ s)` (each a 32-byte big-endian word); the Solm layout (`Solm.SolidityLayout`) computes exactly diff --git a/Reasoning/Reach.lean b/Reasoning/Reach.lean index bee73f46..f688ad2d 100644 --- a/Reasoning/Reach.lean +++ b/Reasoning/Reach.lean @@ -63,7 +63,7 @@ def RD (code : ByteArray) (ee : ExecutionEnv) (g : Sat256) (s0 : State) /-- The EVM **reach-cursor**: the six fields `RD` pins on the underlying `State` at a program point — the transient machine state `pc`/`stack`/`mem`/`aw`/`rdata`, plus the persistent `world` (`createdAccounts × accountMap`, where contract storage lives). `RDc` below is `RD` indexed by a - `Cursor` instead of six loose arguments; eventually `RD` itself should take one. -/ + `Cursor` instead of six loose arguments. -/ structure Cursor where pc : UInt256 stack : List UInt256 @@ -102,7 +102,7 @@ theorem RD.startWith {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 s : {acc : Batteries.RBSet AccountAddress compare × AccountMap} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pc) (hstk : s.machineState.stack = stk) - (hgas : s.machineState.gasAvailable = g.subNat C) (hk : k ≤ C) (hC : C ≤ g.toNat) + (hgas : s.machineState.gasAvailable = g.subNat C) (hk : k ≤ C) (hC : C ≤ g.toNat) (hX : X (g.toNat + 1) (D_J code 0) s0 = X (g.toNat + 1 - k) (D_J code 0) s) (hmem : s.machineState.memory = mem) (haw : s.machineState.activeWords = aw) @@ -145,7 +145,7 @@ theorem RD.conclude {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : St X (g.toNat + 1) (D_J code 0) s0 = X (g.toNat + 1 - k') (D_J code 0) s' ∧ s'.executionEnv.code = code ∧ s'.machineState.pc = pc ∧ s'.machineState.stack = stk - ∧ s'.machineState.gasAvailable = g.subNat C' ∧ k' ≤ C' ∧ C' ≤ g.toNat + ∧ s'.machineState.gasAvailable = g.subNat C' ∧ k' ≤ C' ∧ C' ≤ g.toNat ∧ s'.machineState.memory = mem ∧ s'.machineState.activeWords = aw ∧ s'.machineState.returnData = rdata @@ -231,6 +231,37 @@ theorem RD.stepBinop {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : S · exact hee · exact hworld +/-- The cost-5 analogue of `RD.stepBinop` (`stBinop5` successor), shared by `MOD`/`MUL`/`DIV`. -/ +theorem RD.stepBinop5 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} + {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} + {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} + {a b res : UInt256} {t : List UInt256} + (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) + (hstep : ∀ s : State, s.executionEnv.code = code → s.machineState.pc = pc → + s.machineState.stack = a :: b :: t → + Xstep (D_J code 0) s = + if s.machineState.gasAvailable.toNat < 5 then .error .OutOfGass + else .ok (stBinop5 s res t, .none)) : + RD code ee g s0 (pc + ⟨1⟩) (res :: t) mem aw rdata acc (k + 1) (C + 5) := by + unfold RD at h ⊢ + rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, hee, hworld⟩ + · exact Or.inl hoog + · have st := hstep s hcode hpc hstk + by_cases gg : g.toNat < C + 5 + · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) + · refine Or.inr ⟨stBinop5 s res t, + hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, by omega, by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ + · simp only [stBinop5]; exact hcode + · simp only [stBinop5]; rw [hpc] + · rfl + · simp only [stBinop5]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] + · simp only [stBinop5]; exact hmem + · simp only [stBinop5]; exact haw + · simp only [stBinop5]; exact hrdata + · simp only [stBinop5]; exact hacc + · exact hee + · exact hworld + theorem RD.jumpdest {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc : UInt256} {stk : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} @@ -960,7 +991,7 @@ theorem RD.and {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} RD code ee g s0 (pc + ⟨1⟩) (UInt256.land a b :: t) mem aw rdata acc (k + 1) (C + 3) := h.stepBinop (fun _ hc hp hs => and_xstep hc hp hdec hs hov) -theorem RD.lor {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} +theorem RD.or {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} {a b : UInt256} {t : List UInt256} @@ -1002,79 +1033,26 @@ theorem RD.mod {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {a b : UInt256} {t : List UInt256} (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) (hdec : decode code pc = some (.MOD, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.mod a b :: t) mem aw rdata acc (k + 1) (C + 5) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, hee, hworld⟩ - · exact Or.inl hoog - · have st := mod_xstep hcode hpc hdec hstk hov - by_cases gg : g.toNat < C + 5 - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨stMul s (UInt256.mod a b) t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, by omega, by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [stMul]; exact hcode - · simp only [stMul]; rw [hpc] - · rfl - · simp only [stMul]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [stMul]; exact hmem - · simp only [stMul]; exact haw - · simp only [stMul]; exact hrdata - · simp only [stMul]; exact hacc - · exact hee - · exact hworld + RD code ee g s0 (pc + ⟨1⟩) (UInt256.mod a b :: t) mem aw rdata acc (k + 1) (C + 5) := + h.stepBinop5 (fun _ hc hp hs => mod_xstep hc hp hdec hs hov) -/-- `MUL` is cost 5 (`stMul`), so it does not share the `stBinop` helper. -/ theorem RD.mul {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} {a b : UInt256} {t : List UInt256} (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) (hdec : decode code pc = some (.MUL, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.mul a b :: t) mem aw rdata acc (k + 1) (C + 5) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, hee, hworld⟩ - · exact Or.inl hoog - · have st := mul_xstep hcode hpc hdec hstk hov - by_cases gg : g.toNat < C + 5 - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨stMul s (UInt256.mul a b) t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, by omega, by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [stMul]; exact hcode - · simp only [stMul]; rw [hpc] - · rfl - · simp only [stMul]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [stMul]; exact hmem - · simp only [stMul]; exact haw - · simp only [stMul]; exact hrdata - · simp only [stMul]; exact hacc - · exact hee - · exact hworld + RD code ee g s0 (pc + ⟨1⟩) (UInt256.mul a b :: t) mem aw rdata acc (k + 1) (C + 5) := + h.stepBinop5 (fun _ hc hp hs => mul_xstep hc hp hdec hs hov) -/-- `DIV` is cost 5 (`stMul`), so it does not share the `stBinop` helper. -/ theorem RD.div {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} {a b : UInt256} {t : List UInt256} (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) (hdec : decode code pc = some (.DIV, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.div a b :: t) mem aw rdata acc (k + 1) (C + 5) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, hee, hworld⟩ - · exact Or.inl hoog - · have st := div_xstep hcode hpc hdec hstk hov - by_cases gg : g.toNat < C + 5 - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨stMul s (UInt256.div a b) t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, by omega, by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [stMul]; exact hcode - · simp only [stMul]; rw [hpc] - · rfl - · simp only [stMul]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [stMul]; exact hmem - · simp only [stMul]; exact haw - · simp only [stMul]; exact hrdata - · simp only [stMul]; exact hacc - · exact hee - · exact hworld + RD code ee g s0 (pc + ⟨1⟩) (UInt256.div a b :: t) mem aw rdata acc (k + 1) (C + 5) := + h.stepBinop5 (fun _ hc hp hs => div_xstep hc hp hdec hs hov) theorem RD.exp {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} @@ -1518,10 +1496,8 @@ theorem RD.jumpiNT {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : Sta /-- A message call cannot create gas: the gas `Θ` returns (the callee's leftover) never exceeds the -gas it was forwarded. The old CALL proof needed this to bound a `gasAvailable - cost + refund` -successor. The current opcode semantics instead charges `cost - refund`, so the `RD` gas invariant -does not fundamentally depend on this bound anymore; the proof below still uses it as a convenient -local fact while establishing that the CALL step advances the symbolic counters. -/ +gas it was forwarded. Used by the CALL combinators as a local fact while establishing that the +call step advances the symbolic counters. -/ theorem Theta_returnedGas_le (blob : List ByteArray) (cA : Batteries.RBSet AccountAddress compare) (gh : BlockHeader) (blocks : ProcessedBlocks) (σ σ₀ : AccountMap) (A : Substate) @@ -2072,7 +2048,8 @@ The `selectorArm*` lemmas take `selNat`/`tgt`/`op`/`width` explicitly because `b infer them inside a decode metavariable. These wrappers **extract** them from the bytecode (`pushAt` reads a `PUSH`'s op/value/width), so a caller supplies only the running cursor and `by decide` for each decode fact — no per-arm `(selNat := …) (tgt := …) (op := …) (width := …)`. The -target push width stays generic (`PUSH1` for `Truth`, `PUSH2` for the rest), read from the bytecode. -/ +target push width stays generic (`PUSH1` or `PUSH2`, whichever the contract uses), read from the +bytecode. -/ /-- The `(op, value, width)` of a `PUSH` decoded at `pc` (junk fallback for a non-push). -/ def pushAt (code : ByteArray) (pc : UInt256) : Operation.POp × UInt256 × ℕ := @@ -2821,6 +2798,64 @@ theorem RD.callValueMadeEmptyInOut {code : ByteArray} {ee : ExecutionEnv} {g : S rw [hmin, byteArray_write_len_zero] at rd exact ⟨cA', σ', z, o, A_in, callGas, k', C', hΘ', rd, hoSize⟩ +/-- Shared tail of the `CALL` *no-call-made* branches (insufficient balance / depth limit). + Once the peeled step lands in the concrete else-state `s'` (fields given as equations), + charge `mc + (gc - (UInt256.ofNat G).toNat)` gas and repackage the `RD` witness. -/ +private theorem RD.callNoCallMade {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} + {s0 : State} {pc : UInt256} {mem : ByteArray} {aw : UInt256} + {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} + {inOffset inSize outOffset outSize : UInt256} {t : List UInt256} + {s s' : State} {mc gc G : ℕ} + (hXP : X (g.toNat + 1) (D_J code 0) s0 = X (g.toNat - k) (D_J code 0) s') + (hgas : s.machineState.gasAvailable = g.subNat C) + (hk : k ≤ C) (hC : C ≤ g.toNat) + (hPle : mc + gc ≤ s.machineState.gasAvailable.toNat) + (hGltgc : G < gc) + (hcode' : s'.executionEnv.code = code) + (hpc' : s'.machineState.pc = pc + ⟨1⟩) + (hstk' : s'.machineState.stack = ⟨0⟩ :: t) + (hgv' : s'.machineState.gasAvailable + = (s.machineState.gasAvailable.subNat mc).subNat (gc - (UInt256.ofNat G).toNat)) + (hmem' : s'.machineState.memory = ByteArray.empty.write 0 mem outOffset.toNat + (min outSize (UInt256.ofNat ByteArray.empty.size)).toNat) + (haw' : s'.machineState.activeWords + = UInt256.ofNat (MachineState.M (MachineState.M aw.toNat inOffset.toNat inSize.toNat) + outOffset.toNat outSize.toNat)) + (hrdata' : s'.machineState.returnData = ByteArray.empty) + (hacc' : (s'.createdAccounts, s'.accountMap) = (cA, σ)) + (hee' : s'.executionEnv = ee) + (hworld' : RDWorld s0 s') : + ∃ k' C', RD code ee g s0 (pc + ⟨1⟩) (⟨0⟩ :: t) + (ByteArray.empty.write 0 mem outOffset.toNat + (min outSize (UInt256.ofNat ByteArray.empty.size)).toNat) + (UInt256.ofNat (MachineState.M (MachineState.M aw.toNat inOffset.toNat inSize.toNat) + outOffset.toNat outSize.toNat)) + ByteArray.empty (cA, σ) k' C' := by + have hcgle : (UInt256.ofNat G).toNat ≤ G := by + show G % UInt256.size ≤ G + exact Nat.mod_le _ _ + have hgasN : s.machineState.gasAvailable.toNat = g.toNat - C := by + rw [hgas, Sat256.subNat_toNat] + set callCharge := mc + (gc - (UInt256.ofNat G).toNat) with hcallCharge + have hcallChargeLeGas : callCharge ≤ s.machineState.gasAvailable.toNat := by + rw [hcallCharge] + have hdeltaLe : gc - (UInt256.ofNat G).toNat ≤ gc := Nat.sub_le _ _ + omega + have hCcallCharge : C + callCharge ≤ g.toNat := by + rw [hgasN] at hcallChargeLeGas + omega + have hgvGas : s'.machineState.gasAvailable = g.subNat (C + callCharge) := by + rw [hgv', hgas, hcallCharge] + rw [Sat256.subNat_sub_add_of_sub_sub, Sat256.subNat_sub_add_of_sub_sub] + rw [show g.toNat - k = g.toNat + 1 - (k + 1) from by omega] at hXP + refine ⟨k + 1, C + callCharge, ?_⟩ + unfold RD + refine Or.inr ⟨s', hXP, hcode', hpc', hstk', hgvGas, ?_, hCcallCharge, hmem', haw', + hrdata', hacc', hee', hworld'⟩ + show k + 1 ≤ C + callCharge + rw [hcallCharge] + omega + set_option maxHeartbeats 1000000 in /-- **`CALL` insufficient-balance branch**, with an arbitrary transferred `value`. The EVM does not invoke `Θ`: it returns status `0`, leaves the account map carried by `RD` @@ -2910,10 +2945,6 @@ theorem RD.callValueInsufficientBalance {code : ByteArray} {ee : ExecutionEnv} { split at hXP · exact ⟨k, C, by unfold RD; exact Or.inl hXP⟩ · rename_i hP - have hPle : mc + gc ≤ s.machineState.gasAvailable.toNat := Nat.le_of_not_lt hP - have hcgle : (UInt256.ofNat G).toNat ≤ G := by - show G % UInt256.size ≤ G - exact Nat.mod_le _ _ have hGltgc : G < gc := by rw [hG, hgc] exact Ccallgas_lt_Ccall (AccountAddress.ofUInt256 target) @@ -2924,38 +2955,8 @@ theorem RD.callValueInsufficientBalance {code : ByteArray} {ee : ExecutionEnv} { activeWords := s.machineState.activeWords, memory := s.machineState.memory, returnData := s.machineState.returnData, H_return := s.machineState.H_return } s.substate - have hgasN : s.machineState.gasAvailable.toNat = g.toNat - C := by - rw [hgas, Sat256.subNat_toNat] - set callCharge := mc + (gc - (UInt256.ofNat G).toNat) with hcallCharge - have hcallChargeLeGas : callCharge ≤ s.machineState.gasAvailable.toNat := by - rw [hcallCharge] - have hdeltaLe : gc - (UInt256.ofNat G).toNat ≤ gc := Nat.sub_le _ _ - omega - have hCcallCharge : C + callCharge ≤ g.toNat := by - rw [hgasN] at hcallChargeLeGas - omega - have hgvGas : gv = g.subNat (C + callCharge) := by - rw [hgv, hgas, hcallCharge] - rw [Sat256.subNat_sub_add_of_sub_sub, Sat256.subNat_sub_add_of_sub_sub] - rw [show g.toNat - k = g.toNat + 1 - (k + 1) from by omega] at hXP - refine ⟨k + 1, C + callCharge, ?_⟩ - unfold RD - refine Or.inr ⟨_, hXP, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · exact hcode - · rw [hpc] - · rfl - · show gv = g.subNat (C + callCharge) - exact hgvGas - · show k + 1 ≤ C + callCharge - rw [hcallCharge] - omega - · exact hCcallCharge - · simp [hmem] - · rw [haw] - · rfl - · simp [hcA, hσ] - · exact hee - · exact hworld + exact RD.callNoCallMade hXP hgas hk hC (Nat.le_of_not_lt hP) hGltgc hcode + (by rw [hpc]) rfl hgv (by simp [hmem]) (by rw [haw]) rfl (by simp [hcA, hσ]) hee hworld set_option maxHeartbeats 1000000 in /-- **`CALL` at the call-depth limit**, with an arbitrary transferred `value`. @@ -3019,10 +3020,6 @@ theorem RD.callValueDepthLimit {code : ByteArray} {ee : ExecutionEnv} {g : Sat25 split at hXP · exact ⟨k, C, by unfold RD; exact Or.inl hXP⟩ · rename_i hP - have hPle : mc + gc ≤ s.machineState.gasAvailable.toNat := Nat.le_of_not_lt hP - have hcgle : (UInt256.ofNat G).toNat ≤ G := by - show G % UInt256.size ≤ G - exact Nat.mod_le _ _ have hGltgc : G < gc := by rw [hG, hgc] exact Ccallgas_lt_Ccall (AccountAddress.ofUInt256 target) @@ -3033,38 +3030,8 @@ theorem RD.callValueDepthLimit {code : ByteArray} {ee : ExecutionEnv} {g : Sat25 activeWords := s.machineState.activeWords, memory := s.machineState.memory, returnData := s.machineState.returnData, H_return := s.machineState.H_return } s.substate - have hgasN : s.machineState.gasAvailable.toNat = g.toNat - C := by - rw [hgas, Sat256.subNat_toNat] - set callCharge := mc + (gc - (UInt256.ofNat G).toNat) with hcallCharge - have hcallChargeLeGas : callCharge ≤ s.machineState.gasAvailable.toNat := by - rw [hcallCharge] - have hdeltaLe : gc - (UInt256.ofNat G).toNat ≤ gc := Nat.sub_le _ _ - omega - have hCcallCharge : C + callCharge ≤ g.toNat := by - rw [hgasN] at hcallChargeLeGas - omega - have hgvGas : gv = g.subNat (C + callCharge) := by - rw [hgv, hgas, hcallCharge] - rw [Sat256.subNat_sub_add_of_sub_sub, Sat256.subNat_sub_add_of_sub_sub] - rw [show g.toNat - k = g.toNat + 1 - (k + 1) from by omega] at hXP - refine ⟨k + 1, C + callCharge, ?_⟩ - unfold RD - refine Or.inr ⟨_, hXP, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · exact hcode - · rw [hpc] - · rfl - · show gv = g.subNat (C + callCharge) - exact hgvGas - · show k + 1 ≤ C + callCharge - rw [hcallCharge] - omega - · exact hCcallCharge - · rw [hmem] - · rw [haw] - · rfl - · rw [hcA, hσ] - · exact hee - · exact hworld + exact RD.callNoCallMade hXP hgas hk hC (Nat.le_of_not_lt hP) hGltgc hcode + (by rw [hpc]) rfl hgv (by rw [hmem]) (by rw [haw]) rfl (by rw [hcA, hσ]) hee hworld /-- **`CALL` at the call-depth limit** (`ee.depth = 1024`, value `0`). The EVM never invokes `Θ`: it takes the *no-call-made* branch, returning `0` (`z = false`) with accounts, memory and @@ -3120,67 +3087,24 @@ theorem RD.callDepthLimit {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s gasAvailable := s.machineState.gasAvailable.subNat mc, activeWords := s.machineState.activeWords, memory := s.machineState.memory, returnData := s.machineState.returnData, H_return := s.machineState.H_return } s.substate with hG - set ce := Cextra (AccountAddress.ofUInt256 target) (AccountAddress.ofUInt256 target) { val := 0 } - s.accountMap s.substate with hce set gv := (s.machineState.gasAvailable.subNat mc).subNat (gc - (UInt256.ofNat G).toNat) with hgv have hcA : s.createdAccounts = cA := congrArg Prod.fst hacc have hσ : s.accountMap = σ := congrArg Prod.snd hacc split at hXP · exact ⟨k, C, by unfold RD; exact Or.inl hXP⟩ · rename_i hP - have haN : s.machineState.gasAvailable.toNat < UInt256.size := s.machineState.gasAvailable.isLt - have hPle : mc + gc ≤ s.machineState.gasAvailable.toNat := Nat.le_of_not_lt hP - have hmcle : mc ≤ s.machineState.gasAvailable.toNat := by omega - have hcgle : (UInt256.ofNat G).toNat ≤ G := by - show G % UInt256.size ≤ G; exact Nat.mod_le _ _ - have hgcG : gc = G + ce := by rw [hgc, hG, hce]; rfl - have hce1 : 1 ≤ ce := by - rw [hce] - have hcacc : 1 ≤ Caccess (AccountAddress.ofUInt256 target) s.substate := by - unfold Caccess; split <;> decide - unfold Cextra; omega - have hgcle' : gc ≤ (s.machineState.gasAvailable.subNat mc).toNat := by - rw [toNat_sub_ofNat hmcle]; omega - have hgvN : gv = (s.machineState.gasAvailable.subNat mc).subNat (gc - (UInt256.ofNat G).toNat) := by - rw [hgv] - have hgasN : s.machineState.gasAvailable.toNat = g.toNat - C := by - rw [hgas, Sat256.subNat_toNat] - set callCharge := mc + (gc - (UInt256.ofNat G).toNat) with hcallCharge - have hrefundCostPos : 1 ≤ gc - (UInt256.ofNat G).toNat := by omega - have hcallChargePos : 1 ≤ callCharge := by - rw [hcallCharge] - omega - have hcallChargeLeGas : callCharge ≤ s.machineState.gasAvailable.toNat := by - rw [hcallCharge] - have hdeltaLe : gc - (UInt256.ofNat G).toNat ≤ gc := Nat.sub_le _ _ - omega - have hCcallCharge : C + callCharge ≤ g.toNat := by - rw [hgasN] at hcallChargeLeGas - omega - have hgvGas : gv = g.subNat (C + callCharge) := by - rw [hgv, hgas, hcallCharge] - rw [Sat256.subNat_sub_add_of_sub_sub, Sat256.subNat_sub_add_of_sub_sub] - have hgkey : gv.toNat + k + 1 ≤ g.toNat := by - rw [hgvGas, Sat256.subNat_toNat] - omega - rw [show g.toNat - k = g.toNat + 1 - (k + 1) from by omega] at hXP - refine ⟨k + 1, C + callCharge, ?_⟩ - unfold RD - refine Or.inr ⟨_, hXP, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · exact hcode - · rw [hpc] - · rfl - · show gv = g.subNat (C + callCharge) - exact hgvGas - · show k + 1 ≤ C + callCharge - omega - · exact hCcallCharge - · rw [hmem] - · rw [haw] - · rfl - · rw [hcA, hσ] - · exact hee - · exact hworld + have hGltgc : G < gc := by + rw [hG, hgc] + exact Ccallgas_lt_Ccall (AccountAddress.ofUInt256 target) + (AccountAddress.ofUInt256 target) { val := 0 } gasArg s.accountMap + { pc := s.machineState.pc, stack := s.machineState.stack, + execLength := s.machineState.execLength + 1, + gasAvailable := s.machineState.gasAvailable.subNat mc, + activeWords := s.machineState.activeWords, memory := s.machineState.memory, + returnData := s.machineState.returnData, H_return := s.machineState.H_return } + s.substate + exact RD.callNoCallMade hXP hgas hk hC (Nat.le_of_not_lt hP) hGltgc hcode + (by rw [hpc]) rfl hgv (by rw [hmem]) (by rw [haw]) rfl (by rw [hcA, hσ]) hee hworld /-- `RD.callValueInsufficientBalance` specialized to empty input and no return-data copy. -/ theorem RD.callValueInsufficientBalanceEmptyInOut {code : ByteArray} {ee : ExecutionEnv} @@ -3494,7 +3418,7 @@ theorem RD.execForLoopOrRevertCarryFull {cfg : Config} {contract : ContractDecl} whereas a halt step carries `.some (_, o)` — so we peel the erroring `Xstep` directly. -/ private theorem RD.terminalOOG {code : ByteArray} {g : Sat256} {s0 s : State} {k C cost : ℕ} {res : Except ExecutionException (State × Option (HaltCause × ByteArray))} - (hgas : s.machineState.gasAvailable = g.subNat C) + (hgas : s.machineState.gasAvailable = g.subNat C) (hstep : Xstep (D_J code 0) s = if s.machineState.gasAvailable.toNat < cost then .error .OutOfGass else res) (hk : k ≤ C) (hC : C ≤ g.toNat) (hOOG : g.toNat < C + cost) @@ -3809,7 +3733,7 @@ macro_rules -- The first auto-supplied proof is the `decode code pc = …` obligation; discharge it -- with `native_decide` rather than `decide`. `decode` kernel-reduces by scanning the -- bytecode `ByteArray` literal (O(pc) per step), so `decide` costs ~300–450ms per - -- opcode on the large ERC20 bytecode; `native_decide` compiles the check and runs it in + -- opcode on large bytecode; `native_decide` compiles the check and runs it in -- ~15ms. This adds no new trust category: every `jump (by jump_dest)` already trusts the -- compiler via `native_decide`, so the proofs depend on it pervasively already. match op.getId with diff --git a/Reasoning/Refinement.lean b/Reasoning/Refinement.lean index 7cabe30a..1563429a 100644 --- a/Reasoning/Refinement.lean +++ b/Reasoning/Refinement.lean @@ -561,7 +561,8 @@ theorem CoupledState.refines.returnTransition {code : ByteArray} {ee : Execution refine CoupledState.refines.consReturn st ?_ exact ⟨frame', evm', rv, hstmt, o, hret, hequiv⟩ -/-- Compatibility name for the external-transition interpretation of `equivStmts`. -/ +/-- The external-transition interpretation of `equivStmts`: run `stmts` against the + transition-level postcondition `transitionPost`. -/ def equivTransitionStmts (code : ByteArray) (ee : ExecutionEnv) (g : Sat256) (s0 : State) (cfg : Config) (returnType : List ABIType) (pc : UInt256) (R : StateRel) (stmts : List Stmt) (Q : StateRel) : Prop := diff --git a/Reasoning/Solc.lean b/Reasoning/Solc.lean index 249c150e..62f78de6 100644 --- a/Reasoning/Solc.lean +++ b/Reasoning/Solc.lean @@ -471,41 +471,57 @@ theorem solcErrorStringMem1_size {mem : ByteArray} (hmem : mem.size = 96) : toByteArray_size] omega -theorem solcErrorStringMem2_size (len : UInt256) {mem : ByteArray} - (hmem : mem.size = 96) : +/-- Everything above `Mem1` only depends on `(solcErrorStringMem1 mem).size = 164`, so the + `Mem2`/`Mem3` facts are proved once here and instantiated by both the 96- and 164-byte base + cases. -/ +theorem solcErrorStringMem2_size_of_mem1 (len : UInt256) {mem : ByteArray} + (h1 : (solcErrorStringMem1 mem).size = 164) : (solcErrorStringMem2 len mem).size = 196 := by unfold solcErrorStringMem2 - rw [write32_eq _ _ _ (by rw [toByteArray_size]) - (by simp [solcErrorStringMem1_size hmem]), + rw [write32_eq _ _ _ (by rw [toByteArray_size]) (by rw [h1]), ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, solcErrorStringMem1_size hmem, - toByteArray_size] + ByteArray.size_extract, ByteArray.size_extract, h1, toByteArray_size] omega -theorem solcErrorStringMem3_size (len word : UInt256) {mem : ByteArray} - (hmem : mem.size = 96) : +theorem solcErrorStringMem3_size_of_mem1 (len word : UInt256) {mem : ByteArray} + (h1 : (solcErrorStringMem1 mem).size = 164) : (solcErrorStringMem3 len word mem).size = 228 := by unfold solcErrorStringMem3 rw [write32_eq _ _ _ (by rw [toByteArray_size]) - (by simp [solcErrorStringMem2_size len hmem]), + (by rw [solcErrorStringMem2_size_of_mem1 len h1]), ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, solcErrorStringMem2_size len hmem, + ByteArray.size_extract, ByteArray.size_extract, solcErrorStringMem2_size_of_mem1 len h1, toByteArray_size] omega -theorem solcErrorStringMem3_read64 (len word : UInt256) {mem : ByteArray} - (hmem : mem.size = 96) - (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : +theorem solcErrorStringMem3_read64_of_mem1 (len word : UInt256) {mem : ByteArray} + (h1 : (solcErrorStringMem1 mem).size = 164) + (h1read : (solcErrorStringMem1 mem).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : (solcErrorStringMem3 len word mem).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by unfold solcErrorStringMem3 rw [toByteArray_write_read_below_of_gap word _ 196 64 - (by rw [solcErrorStringMem2_size len hmem]; omega) (by omega) - (by rw [solcErrorStringMem2_size len hmem]; exact lt_usize _ (by norm_num))] + (by rw [solcErrorStringMem2_size_of_mem1 len h1]; omega) (by omega) + (by rw [solcErrorStringMem2_size_of_mem1 len h1]; exact lt_usize _ (by norm_num))] unfold solcErrorStringMem2 rw [toByteArray_write_read_below_of_gap len _ 164 64 - (by rw [solcErrorStringMem1_size hmem]; omega) (by omega) - (by rw [solcErrorStringMem1_size hmem]; exact lt_usize _ (by norm_num))] + (by rw [h1]; omega) (by omega) + (by rw [h1]; exact lt_usize _ (by norm_num))] + exact h1read + +theorem solcErrorStringMem2_size (len : UInt256) {mem : ByteArray} + (hmem : mem.size = 96) : + (solcErrorStringMem2 len mem).size = 196 := + solcErrorStringMem2_size_of_mem1 len (solcErrorStringMem1_size hmem) + +theorem solcErrorStringMem3_size (len word : UInt256) {mem : ByteArray} + (hmem : mem.size = 96) : + (solcErrorStringMem3 len word mem).size = 228 := + solcErrorStringMem3_size_of_mem1 len word (solcErrorStringMem1_size hmem) + +theorem solcErrorStringMem1_read64 {mem : ByteArray} (hmem : mem.size = 96) + (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : + (solcErrorStringMem1 mem).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by unfold solcErrorStringMem1 rw [toByteArray_write_read_below_of_gap (⟨32⟩ : UInt256) _ 132 64 (by rw [solcErrorStringMem0_size hmem]; omega) (by omega) @@ -515,6 +531,14 @@ theorem solcErrorStringMem3_read64 (len word : UInt256) {mem : ByteArray} (by omega) (by omega) (by rw [hmem]; exact lt_usize _ (by norm_num))] exact hread64 +theorem solcErrorStringMem3_read64 (len word : UInt256) {mem : ByteArray} + (hmem : mem.size = 96) + (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : + (solcErrorStringMem3 len word mem).readWithPadding 64 32 = + UInt256.toByteArray ⟨128⟩ := + solcErrorStringMem3_read64_of_mem1 len word (solcErrorStringMem1_size hmem) + (solcErrorStringMem1_read64 hmem hread64) + theorem solcErrorStringMem3_mload64 (len word : UInt256) {mem : ByteArray} (hmem : mem.size = 96) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : @@ -544,35 +568,17 @@ theorem solcErrorStringMem1_size_of_size164 {mem : ByteArray} (hmem : mem.size = theorem solcErrorStringMem2_size_of_size164 (len : UInt256) {mem : ByteArray} (hmem : mem.size = 164) : - (solcErrorStringMem2 len mem).size = 196 := by - unfold solcErrorStringMem2 - rw [write32_eq _ _ _ (by rw [toByteArray_size]) - (by rw [solcErrorStringMem1_size_of_size164 hmem])] - simp [ByteArray.size_append, ByteArray.size_extract, solcErrorStringMem1_size_of_size164 hmem, - toByteArray_size] + (solcErrorStringMem2 len mem).size = 196 := + solcErrorStringMem2_size_of_mem1 len (solcErrorStringMem1_size_of_size164 hmem) theorem solcErrorStringMem3_size_of_size164 (len word : UInt256) {mem : ByteArray} (hmem : mem.size = 164) : - (solcErrorStringMem3 len word mem).size = 228 := by - unfold solcErrorStringMem3 - rw [write32_eq _ _ _ (by rw [toByteArray_size]) - (by rw [solcErrorStringMem2_size_of_size164 len hmem])] - simp [ByteArray.size_append, ByteArray.size_extract, solcErrorStringMem2_size_of_size164 len hmem, - toByteArray_size] + (solcErrorStringMem3 len word mem).size = 228 := + solcErrorStringMem3_size_of_mem1 len word (solcErrorStringMem1_size_of_size164 hmem) -theorem solcErrorStringMem3_read64_of_size164 (len word : UInt256) {mem : ByteArray} - (hmem : mem.size = 164) +theorem solcErrorStringMem1_read64_of_size164 {mem : ByteArray} (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : - (solcErrorStringMem3 len word mem).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - unfold solcErrorStringMem3 - rw [toByteArray_write_read_below_of_gap word _ 196 64 - (by rw [solcErrorStringMem2_size_of_size164 len hmem]; omega) (by omega) - (by rw [solcErrorStringMem2_size_of_size164 len hmem]; exact lt_usize _ (by norm_num))] - unfold solcErrorStringMem2 - rw [toByteArray_write_read_below_of_gap len _ 164 64 - (by rw [solcErrorStringMem1_size_of_size164 hmem]; omega) (by omega) - (by rw [solcErrorStringMem1_size_of_size164 hmem]; exact lt_usize _ (by norm_num))] + (solcErrorStringMem1 mem).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by unfold solcErrorStringMem1 rw [toByteArray_write_read_below_of_gap (⟨32⟩ : UInt256) _ 132 64 (by rw [solcErrorStringMem0_size_of_size164 hmem]; omega) (by omega) @@ -582,6 +588,14 @@ theorem solcErrorStringMem3_read64_of_size164 (len word : UInt256) {mem : ByteAr (by rw [hmem]; omega) (by omega) (by rw [hmem]; exact lt_usize _ (by norm_num))] exact hread64 +theorem solcErrorStringMem3_read64_of_size164 (len word : UInt256) {mem : ByteArray} + (hmem : mem.size = 164) + (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : + (solcErrorStringMem3 len word mem).readWithPadding 64 32 = + UInt256.toByteArray ⟨128⟩ := + solcErrorStringMem3_read64_of_mem1 len word (solcErrorStringMem1_size_of_size164 hmem) + (solcErrorStringMem1_read64_of_size164 hmem hread64) + theorem solcErrorStringMem3_mload64_of_size164 (len word : UInt256) {mem : ByteArray} (hmem : mem.size = 164) (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : @@ -3041,7 +3055,7 @@ theorem RD.solcConstGetter {code : ByteArray} {g : Sat256} {s0 : State} have rdRet := rdDup.jump hdJump hret (by simp only [List.length_cons]; omega) exact ⟨_, _, rdRet⟩ -/-! ## Solc mapping getter routines -/ +/-! ## Solc mapping getter and store routines -/ abbrev solcSlotWord (σ : AccountMap) (I : ExecutionEnv) (slot : UInt256) : UInt256 := σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD slot ⟨0⟩) @@ -4595,7 +4609,7 @@ theorem RD.solcSingleMappingGetter {code : ByteArray} {g : Sat256} {s0 : State} have rd17 := rd16.dup2 hd16 (by evm_ov) exact ⟨_, _, rd17.jump hd17 hret (by evm_ov)⟩ -set_option maxHeartbeats 3000000 in +set_option maxHeartbeats 2000000 in theorem RD.solcNestedMappingInnerHash {code : ByteArray} {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {pc baseSlot owner spender ret : UInt256} {R : List UInt256} {rdata : ByteArray} diff --git a/Reasoning/SolmBody.lean b/Reasoning/SolmBody.lean index 31be75e3..ee24250e 100644 --- a/Reasoning/SolmBody.lean +++ b/Reasoning/SolmBody.lean @@ -45,12 +45,15 @@ theorem bodyReverts_nonPayable {cfg : Config} {contract : ContractDecl} {evm : E (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: rest) .reverted := ExecFuncBody.execBlockRevert (ExecBlock.consRevert (ExecStmt.requireFalse (evalCallvalueEq_false h))) +/-- Block-level form of the non-payable revert: the guard fails under non-zero call value. -/ theorem blockReverts_nonPayable {cfg : Config} {solm : Frame} {evm : EVM.State} {rest : List Stmt} (h : evm.executionEnv.weiValue ≠ ⟨0⟩) : ExecBlock cfg solm evm (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: rest) .reverted := ExecBlock.consRevert (ExecStmt.requireFalse (evalCallvalueEq_false h)) +/-- The common `require(callvalue == 0); require(guard); storage := rhs` block, all three + statements succeeding. -/ theorem nonpayableRequireAssignStorageBlock {cfg : Config} {solm : Frame} {evm evm' : EVM.State} {guard rhs : Expr} {ref : StorageRef} {value : Value} (hwv : evm.executionEnv.weiValue = ⟨0⟩) @@ -66,6 +69,7 @@ theorem nonpayableRequireAssignStorageBlock {cfg : Config} {solm : Frame} refine ExecBlock.consNormal (ExecStmt.requireTrue hguard) ?_ exact ExecBlock.consNormal (ExecStmt.assign hrhs hassign) ExecBlock.nil +/-- The non-payable guard passes but the second `require(guard)` fails: the block reverts. -/ theorem nonpayableSecondRequireReverts {cfg : Config} {solm : Frame} {evm : EVM.State} {guard : Expr} {rest : List Stmt} (hwv : evm.executionEnv.weiValue = ⟨0⟩) @@ -76,6 +80,7 @@ theorem nonpayableSecondRequireReverts {cfg : Config} {solm : Frame} refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) ?_ exact ExecBlock.consRevert (ExecStmt.requireFalse hguard) +/-- A singleton `storage := rhs` block, evaluating and assigning in one step. -/ theorem assignStorageBlock {cfg : Config} {solm : Frame} {evm evm' : EVM.State} {rhs : Expr} {ref : StorageRef} {value : Value} (hrhs : evalExpr? cfg solm evm rhs = .ok value) diff --git a/Reasoning/Stepping.lean b/Reasoning/Stepping.lean index 98d6b5bb..7c11cd9b 100644 --- a/Reasoning/Stepping.lean +++ b/Reasoning/Stepping.lean @@ -99,7 +99,7 @@ def stPush2 (s : State) (arg : UInt256) : State := pc := s.machineState.pc + UInt256.ofNat 3, stack := arg :: s.machineState.stack, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 3 } } + gasAvailable := s.machineState.gasAvailable.subNat 3 } } theorem push2_xstep {s : State} {code : ByteArray} {pcv argv : UInt256} {rest : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -121,14 +121,29 @@ def stPush0 (s : State) : State := pc := s.machineState.pc + ⟨1⟩, stack := ⟨0⟩ :: s.machineState.stack, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 2 } } + gasAvailable := s.machineState.gasAvailable.subNat 2 } } + +theorem push0_xstep {s : State} {code : ByteArray} {pcv : UInt256} {rest : List UInt256} + (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) + (hdec : decode code pcv = some (.PUSH0, .none)) + (hstk : s.machineState.stack = rest) (hov : rest.length + 1 ≤ 1024) : + Xstep (D_J code 0) s + = (if s.machineState.gasAvailable.toNat < 2 then .error .OutOfGass + else .ok (stPush0 s, .none)) := by + have hd : decode s.executionEnv.code s.machineState.pc = some (.PUSH0, .none) := by + rw [hcode, hpc]; exact hdec + have hov' : ¬ (s.machineState.stack.length - 0 + 1 > 1024) := by rw [hstk]; omega + rw [← hcode, step_push0 s hd, if_neg hov'] + simp only [GasConstants.Gbase, stPush0] + +/-! ### GAS (cost 2, pc += 1, pushes remaining gas) -/ def stGas (s : State) : State := { s with machineState := { s.machineState with pc := s.machineState.pc + ⟨1⟩, - stack := (s.machineState.gasAvailable.subNat 2).toUInt256 :: s.machineState.stack, + stack := (s.machineState.gasAvailable.subNat 2).toUInt256 :: s.machineState.stack, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 2 } } + gasAvailable := s.machineState.gasAvailable.subNat 2 } } theorem gas_xstep {s : State} {code : ByteArray} {pcv : UInt256} {rest : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -143,19 +158,6 @@ theorem gas_xstep {s : State} {code : ByteArray} {pcv : UInt256} {rest : List UI rw [← hcode, step_gas s hd, if_neg hov'] simp only [GasConstants.Gbase, stGas] -theorem push0_xstep {s : State} {code : ByteArray} {pcv : UInt256} {rest : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.PUSH0, .none)) - (hstk : s.machineState.stack = rest) (hov : rest.length + 1 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 2 then .error .OutOfGass - else .ok (stPush0 s, .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.PUSH0, .none) := by - rw [hcode, hpc]; exact hdec - have hov' : ¬ (s.machineState.stack.length - 0 + 1 > 1024) := by rw [hstk]; omega - rw [← hcode, step_push0 s hd, if_neg hov'] - simp only [GasConstants.Gbase, stPush0] - /-! ### CALLVALUE (cost 2, pc += 1, pushes weiValue) -/ def stCallvalue (s : State) : State := @@ -163,7 +165,7 @@ def stCallvalue (s : State) : State := pc := s.machineState.pc + ⟨1⟩, stack := s.executionEnv.weiValue :: s.machineState.stack, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 2 } } + gasAvailable := s.machineState.gasAvailable.subNat 2 } } theorem callvalue_xstep {s : State} {code : ByteArray} {pcv : UInt256} {rest : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -229,7 +231,7 @@ def stDup1 (s : State) (a : UInt256) (t : List UInt256) : State := pc := s.machineState.pc + ⟨1⟩, stack := a :: a :: t, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 3 } } + gasAvailable := s.machineState.gasAvailable.subNat 3 } } theorem dup1_xstep {s : State} {code : ByteArray} {pcv a : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -251,7 +253,7 @@ def stIsZero (s : State) (a : UInt256) (t : List UInt256) : State := pc := s.machineState.pc + ⟨1⟩, stack := UInt256.isZero a :: t, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 3 } } + gasAvailable := s.machineState.gasAvailable.subNat 3 } } theorem iszero_xstep {s : State} {code : ByteArray} {pcv a : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -276,7 +278,7 @@ def stMStore (s : State) (a b : UInt256) (t : List UInt256) : State := activeWords := UInt256.ofNat (MachineState.M s.machineState.activeWords.toNat a.toNat 32), execLength := s.machineState.execLength + 1, gasAvailable := - (s.machineState.gasAvailable.subNat (memoryExpansionCost s .MSTORE)).subNat 3 } } + (s.machineState.gasAvailable.subNat (memoryExpansionCost s .MSTORE)).subNat 3 } } theorem mstore_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -301,7 +303,7 @@ def stJumpiNT (s : State) (t : List UInt256) : State := pc := s.machineState.pc + ⟨1⟩, stack := t, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 10 } } + gasAvailable := s.machineState.gasAvailable.subNat 10 } } theorem jumpi_nt_xstep {s : State} {code : ByteArray} {pcv a : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -331,7 +333,7 @@ def stRevert (s : State) (a b : UInt256) (t : List UInt256) : State := UInt256.ofNat (MachineState.M (UInt256.ofNat m).toNat a.toNat b.toNat), execLength := s.machineState.execLength + 1, gasAvailable := - (s.machineState.gasAvailable.subNat (memoryExpansionCost s .REVERT)).subNat 0 } } + (s.machineState.gasAvailable.subNat (memoryExpansionCost s .REVERT)).subNat 0 } } theorem revert_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -360,7 +362,7 @@ def stReturn (s : State) (a b : UInt256) (t : List UInt256) : State := UInt256.ofNat (MachineState.M s.machineState.activeWords.toNat a.toNat b.toNat), execLength := s.machineState.execLength + 1, gasAvailable := - (s.machineState.gasAvailable.subNat (memoryExpansionCost s .RETURN)).subNat 0 } } + (s.machineState.gasAvailable.subNat (memoryExpansionCost s .RETURN)).subNat 0 } } theorem return_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -391,7 +393,7 @@ def stMLoad (s : State) (a : UInt256) (t : List UInt256) : State := UInt256.ofNat (MachineState.M s.machineState.activeWords.toNat a.toNat 32), execLength := s.machineState.execLength + 1, gasAvailable := - (s.machineState.gasAvailable.subNat (memoryExpansionCost s .MLOAD)).subNat 3 } } + (s.machineState.gasAvailable.subNat (memoryExpansionCost s .MLOAD)).subNat 3 } } theorem mload_xstep {s : State} {code : ByteArray} {pcv a : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -415,7 +417,7 @@ def stBinop (s : State) (res : UInt256) (t : List UInt256) : State := { s with machineState := { s.machineState with pc := s.machineState.pc + ⟨1⟩, stack := res :: t, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 3 } } + gasAvailable := s.machineState.gasAvailable.subNat 3 } } theorem eq_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -551,11 +553,25 @@ theorem xor_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List U have hov' : ¬ ((a :: b :: t).length - 2 + 1 > 1024) := by simp only [List.length_cons]; omega simp only [if_neg hov', GasConstants.Gverylow, stBinop] -def stMul (s : State) (res : UInt256) (t : List UInt256) : State := +theorem shl_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List UInt256} + (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) + (hdec : decode code pcv = some (.SHL, .none)) + (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : + Xstep (D_J code 0) s + = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass + else .ok (stBinop s (UInt256.shiftLeft b a) t, .none)) := by + have hd : decode s.executionEnv.code s.machineState.pc = some (.SHL, .none) := by rw [hcode, hpc]; exact hdec + rw [← hcode, step_shl s hd, hstk] + have hov' : ¬ ((a :: b :: t).length - 2 + 1 > 1024) := by simp only [List.length_cons]; omega + simp only [if_neg hov', GasConstants.Gverylow, stBinop] + +/-! ### MOD / MUL / DIV (cost 5 = `Glow`, `a :: b :: t ↦ res :: t`, pc += 1) -/ + +def stBinop5 (s : State) (res : UInt256) (t : List UInt256) : State := { s with machineState := { s.machineState with pc := s.machineState.pc + ⟨1⟩, stack := res :: t, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 5 } } + gasAvailable := s.machineState.gasAvailable.subNat 5 } } theorem mod_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -563,26 +579,12 @@ theorem mod_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List U (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : Xstep (D_J code 0) s = (if s.machineState.gasAvailable.toNat < 5 then .error .OutOfGass - else .ok (stMul s (UInt256.mod a b) t, .none)) := by + else .ok (stBinop5 s (UInt256.mod a b) t, .none)) := by have hd : decode s.executionEnv.code s.machineState.pc = some (.MOD, .none) := by rw [hcode, hpc]; exact hdec rw [← hcode, step_mod s hd, hstk] have hov' : ¬ ((a :: b :: t).length - 2 + 1 > 1024) := by simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Glow, stMul] - -theorem shl_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.SHL, .none)) - (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok (stBinop s (UInt256.shiftLeft b a) t, .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.SHL, .none) := by rw [hcode, hpc]; exact hdec - rw [← hcode, step_shl s hd, hstk] - have hov' : ¬ ((a :: b :: t).length - 2 + 1 > 1024) := by simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Gverylow, stBinop] - -/-! ### MUL (cost 5 = `Glow`, `a :: b :: t ↦ mul a b :: t`, pc += 1) -/ + simp only [if_neg hov', GasConstants.Glow, stBinop5] theorem mul_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -590,11 +592,11 @@ theorem mul_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List U (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : Xstep (D_J code 0) s = (if s.machineState.gasAvailable.toNat < 5 then .error .OutOfGass - else .ok (stMul s (UInt256.mul a b) t, .none)) := by + else .ok (stBinop5 s (UInt256.mul a b) t, .none)) := by have hd : decode s.executionEnv.code s.machineState.pc = some (.MUL, .none) := by rw [hcode, hpc]; exact hdec rw [← hcode, step_mul s hd, hstk] have hov' : ¬ ((a :: b :: t).length - 2 + 1 > 1024) := by simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Glow, stMul] + simp only [if_neg hov', GasConstants.Glow, stBinop5] theorem div_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -602,11 +604,11 @@ theorem div_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List U (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : Xstep (D_J code 0) s = (if s.machineState.gasAvailable.toNat < 5 then .error .OutOfGass - else .ok (stMul s (UInt256.div a b) t, .none)) := by + else .ok (stBinop5 s (UInt256.div a b) t, .none)) := by have hd : decode s.executionEnv.code s.machineState.pc = some (.DIV, .none) := by rw [hcode, hpc]; exact hdec rw [← hcode, step_div s hd, hstk] have hov' : ¬ ((a :: b :: t).length - 2 + 1 > 1024) := by simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Glow, stMul] + simp only [if_neg hov', GasConstants.Glow, stBinop5] /-! ### EXP (dynamic cost, `a :: b :: t ↦ exp a b :: t`, pc += 1) -/ @@ -648,7 +650,7 @@ def stPop (s : State) (t : List UInt256) : State := { s with machineState := { s.machineState with pc := s.machineState.pc + ⟨1⟩, stack := t, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 2 } } + gasAvailable := s.machineState.gasAvailable.subNat 2 } } theorem pop_xstep {s : State} {code : ByteArray} {pcv a : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -669,7 +671,7 @@ def stCalldatasize (s : State) : State := pc := s.machineState.pc + ⟨1⟩, stack := UInt256.ofNat s.executionEnv.calldata.size :: s.machineState.stack, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 2 } } + gasAvailable := s.machineState.gasAvailable.subNat 2 } } theorem calldatasize_xstep {s : State} {code : ByteArray} {pcv : UInt256} {rest : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -690,7 +692,7 @@ def stCalldataload (s : State) (a : UInt256) (t : List UInt256) : State := pc := s.machineState.pc + ⟨1⟩, stack := (uInt256OfByteArray <| s.executionEnv.calldata.readBytes a.toNat 32) :: t, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 3 } } + gasAvailable := s.machineState.gasAvailable.subNat 3 } } theorem calldataload_xstep {s : State} {code : ByteArray} {pcv a : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -711,14 +713,28 @@ def stPush4 (s : State) (arg : UInt256) : State := pc := s.machineState.pc + UInt256.ofNat 5, stack := arg :: s.machineState.stack, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 3 } } + gasAvailable := s.machineState.gasAvailable.subNat 3 } } + +theorem push4_xstep {s : State} {code : ByteArray} {pcv argv : UInt256} {rest : List UInt256} + (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) + (hdec : decode code pcv = some (.Push .PUSH4, some (argv, 4))) + (hstk : s.machineState.stack = rest) (hov : rest.length + 1 ≤ 1024) : + Xstep (D_J code 0) s + = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass + else .ok (stPush4 s argv, .none)) := by + have hd : decode s.executionEnv.code s.machineState.pc = some (.Push .PUSH4, some (argv, 4)) := by rw [hcode, hpc]; exact hdec + have hov' : ¬ (s.machineState.stack.length - 0 + 1 > 1024) := by rw [hstk]; omega + rw [← hcode, step_push4 s argv hd, if_neg hov'] + simp only [GasConstants.Gverylow, stPush4] + +/-! ### PUSH20 (cost 3, pc += 21) -/ def stPush20 (s : State) (arg : UInt256) : State := { s with machineState := { s.machineState with pc := s.machineState.pc + UInt256.ofNat 21, stack := arg :: s.machineState.stack, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 3 } } + gasAvailable := s.machineState.gasAvailable.subNat 3 } } theorem push20_xstep {s : State} {code : ByteArray} {pcv argv : UInt256} {rest : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -732,25 +748,13 @@ theorem push20_xstep {s : State} {code : ByteArray} {pcv argv : UInt256} {rest : rw [← hcode, step_push s .PUSH20 argv 20 (by decide) hd, if_neg hov'] simp only [GasConstants.Gverylow, stPush20] -theorem push4_xstep {s : State} {code : ByteArray} {pcv argv : UInt256} {rest : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.Push .PUSH4, some (argv, 4))) - (hstk : s.machineState.stack = rest) (hov : rest.length + 1 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok (stPush4 s argv, .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.Push .PUSH4, some (argv, 4)) := by rw [hcode, hpc]; exact hdec - have hov' : ¬ (s.machineState.stack.length - 0 + 1 > 1024) := by rw [hstk]; omega - rw [← hcode, step_push4 s argv hd, if_neg hov'] - simp only [GasConstants.Gverylow, stPush4] - /-! ### JUMPDEST (cost 1, pc += 1) -/ def stJumpdest (s : State) : State := { s with machineState := { s.machineState with pc := s.machineState.pc + ⟨1⟩, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 1 } } + gasAvailable := s.machineState.gasAvailable.subNat 1 } } theorem jumpdest_xstep {s : State} {code : ByteArray} {pcv : UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -770,7 +774,7 @@ def stJump (s : State) (a : UInt256) (t : List UInt256) : State := { s with machineState := { s.machineState with pc := a, stack := t, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 8 } } + gasAvailable := s.machineState.gasAvailable.subNat 8 } } theorem jump_xstep {s : State} {code : ByteArray} {pcv a : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -1040,7 +1044,7 @@ def stJumpiT (s : State) (a : UInt256) (t : List UInt256) : State := { s with machineState := { s.machineState with pc := a, stack := t, execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 10 } } + gasAvailable := s.machineState.gasAvailable.subNat 10 } } theorem jumpi_t_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List UInt256} (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) @@ -1107,7 +1111,7 @@ def stSStore (s : State) (slot val : UInt256) (t : List UInt256) : State := accountMap := accountMap substate := substate machineState.stack := t - machineState.gasAvailable := s.machineState.gasAvailable.subNat (Csstore s) + machineState.gasAvailable := s.machineState.gasAvailable.subNat (Csstore s) machineState.pc := s.machineState.pc + ⟨1⟩ machineState.execLength := s.machineState.execLength + 1 } diff --git a/Reasoning/Theory.lean b/Reasoning/Theory.lean index a2c91793..7b60ea8d 100644 --- a/Reasoning/Theory.lean +++ b/Reasoning/Theory.lean @@ -160,7 +160,7 @@ theorem stepContinue {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g : S but now the next instruction's `cost` exceeds the remaining gas (`g.toNat < C + cost`), so the iterator returns `OutOfGass`. -/ theorem stepOOG {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g : Sat256} - (hgas : s.machineState.gasAvailable = g.subNat C) + (hgas : s.machineState.gasAvailable = g.subNat C) (hstep : Xstep vj s = if s.machineState.gasAvailable.toNat < cost then .error .OutOfGass else .ok (s', .none)) @@ -174,7 +174,7 @@ theorem stepOOG {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g : Sat256 /-- **Halt** (`RETURN`/`STOP`/`SELFDESTRUCT` ⇒ success, or `REVERT`) when the current instruction's gas suffices: the iterator returns the halt result directly. -/ theorem stepHaltSuccess {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g : Sat256} {o} - (hgas : s.machineState.gasAvailable = g.subNat C) + (hgas : s.machineState.gasAvailable = g.subNat C) (hstep : Xstep vj s = if s.machineState.gasAvailable.toNat < cost then .error .OutOfGass else .ok (s', .some (.success, o))) @@ -185,8 +185,10 @@ theorem stepHaltSuccess {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g have hgg : ¬ (s.machineState.gasAvailable.toNat < cost) := by rw [hgas]; simp [Sat256.subNat, Sat256.toNat] at *; omega exact Xstep_X_X_halt_success _ s s' vj o (by rw [hstep]; simp [hgg]) +/-- **Halt with revert** when the current instruction's gas suffices: the iterator returns the + revert result directly. -/ theorem stepHaltRevert {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g : Sat256} {o} - (hgas : s.machineState.gasAvailable = g.subNat C) + (hgas : s.machineState.gasAvailable = g.subNat C) (hstep : Xstep vj s = if s.machineState.gasAvailable.toNat < cost then .error .OutOfGass else .ok (s', .some (.revert, o))) diff --git a/prompt.md b/prompt.md deleted file mode 100644 index e470d8b3..00000000 --- a/prompt.md +++ /dev/null @@ -1,550 +0,0 @@ -# Agent prompt — proving EVM↔Solm correctness for a contract - -You are proving that a concrete EVM bytecode artifact refines its Solm -specification. You goal is to complete the proof of the top-level theorem -in `Correct.lean` with no `sorry` and no added axioms, except for the -accepted trusted base below. - -```lean - -You are given a working directory, which is named after the contract -(`/`) and includes: - -- The EVM bytecode (file `Bytecode.lean`). - -- The source it was compiled from (e.g., `.sol`), plus the exact - compiler and options used to produce it. The bytecode can be of - arbitrary provenance — do not assume a specific compiler or - version. Always check. - -- The Solm specification of the contract, including its storage - layout. (file `Spec.lean`) - -- A correctness file stating the top-level theorem with a `sorry` - placeholder. (file `Correct.lean`) - -The top-level theorem bundles the correctness of the constructor: - -```lean -constructorEquivalence -``` - -and the correctness of the runtime code: - -```lean -runtimeEquivalence -``` - -Your goal is to complete the proof. The proof must be correct, -modular, fast enough to work on, and axiom-clean except for the -accepted trusted base below. - -Be forthcoming with blocking issues. Never bypass a problem to move on -to the next proof, and never circumvent it. If you suspect something -is unprovable, investigate thoroughly, report it immediately to the -user, and do not continue until it is resolved. - -You should only work in the `/` directory. Do not make changes -outside of it. - -## 1. Overall Workflow - -### Phase 0: Evaluate the spec and bytecode - -Do a thorough read of the Solm spec and the bytecode. Check that the -Solm spec matches the bytecode's storage reads/writes, arithmetic, and -control flow. If you find a mismatch, report it immediately. After -this pass, you should be confident that the Solm spec is a faithful -model of the bytecode, and that it is possible to prove the -refinement. - -Things to watch for: - -- The Solm spec, in general, must model storage reads/writes in the - order the bytecode performs them. This is not a hard rule, for all - data types. But for mapping, array, string and byte types this is - important as otherwise you will have to introduce a slot noncollision - axiom to prove the refinement, which is not allowed. - - If you find that you need such an axiom, evaluate whether the Solm can - be written - differently to exactly model the bytecode's storage reads/writes. - If it can, rewrite the Solm spec to do so. - - Only add such axiom if the compiler has done an optimization that cannot - be reflected in the Solm spec and the proof cannot be completed without it. - -- The Solm spec must use helper functions where possible and not - inline the same logic in multiple places. This is important for - modularity and reusability of proofs. - -- The storage layout in the Solm spec must match the storage layout in - the bytecode. If there is a mismatch, report it immediately. - -### Phase 1: Scaffold the proof - -Create the top-level scaffold of the proof in `Correct.lean`. This -includes the dispatch skeleton, the per-function `…BodyCore` lemmas, -and the revert paths. The top-level theorem should type-check and -route correctly before the leaves are done. Reuse the available -machinery drivers for dispatching (e.g., `solcDispatchReachBody`). - -1. Add the dispatch handler to the main theorem first. Wire the full - dispatcher (`by_cases` on `callvalue`/`size`/each selector, routing - each selector to its per-function `…BodyCore`, plus the shared - revert paths). This skeleton should type-check and route correctly - before the leaves are done. Add the necessary ABI selector axiom - as needed. - -2. For each ABI function ``, route to a `…BodyCore` whose proof is - a `sorry`. That `…BodyCore` should be defined in that function's - own file `.lean`. - -3. Create a `…BodyCore` lemma for the constructor in - `Constructor.lean` file. - -4. The skeleton of the proof should now route every function and the - constructor correctly through the main top-level dispatch. - -*Hard rule*: You should set up the dispatch skeleton and the per ABI -function theorems (initially with `sorry`) in their own files before -proving any of the functions. - -It is likely that some of the `Examples/` proof templates will be useful -for this phase. You can use them as a reference for the ABI dispatch skeleton. - -### Phase 2: Prove each function - -Finish each function's `…BodyCore` lemma in its own `.lean` -file. If the proof gets difficult, do not try to bypass the problem -and move to another function. Investigate thoroughly and report -immediately any blocking issues you may find. - -You should tackle proofs in order of dependency: if function `f` calls -function `g`, prove `g` first, then `f`. This is true for both -internal and external calls. - -The proof of each function follows, roughly, four phases: - - -1. ABI decode. Prove decode succeeds for valid calldata and fails on - each malformed branch (short / huge / non-canonical address - lemmas). Use the `decodeCalldata_*` library lemmas - (`decodeCalldata_address_ok`, `decodeCalldata_uint256_ok`, - `…_none_short`, `…_none_huge`, `…_none_noncanon`). One `simpa … - using ` per branch (see `BalanceOf.lean`). - -2. Add trusted selector facts for the public selectors in `Trusted.lean`. - -3. Solm source body. Prove the `ExecTransitionBody` result (return - value / storage update / revert) using `Reasoning.SolmBody` - (`ExecStmt`/`ExecBlock` combinators, `evalExpr_*`, `requireStep`, - `returns`). For mutating functions, split success and revert - branches early. - -4. EVM reachability. Thread the bytecode trace from the body entry PC - to `RDret` (success) or `RDrev` (revert) using `evm_run … with [ … - ]` cooked-step chains and factored `RD.*` routine lemmas. Never - write one giant `evm_run`; split into named `have`s, one per - phase/routine. - -5. Connect. `reEquivExecution` / `reEquivDecodingFailed` / - `reEquivNoDispatch` / `reEquivElim` glue the source result, the - decode fact, and the EVM `RDret`/`RDrev` into - `runtimeEquivalenceFor`. - ---- - -### Phase 3: Prove the constructor - -In a similar manner, prove correct the constructor body. - ---- - -### Phase 4: Finish the proof - -After you have proved all the functions and the constructor, verify -that the top-level theorem complies with no added axioms and no -`sorry`/`admit`. Report the axiom footprint. - ---- - -## 2. Accepted axioms - -The only acceptable trusted facts are: - -- The selector / jump-dest facts in `Bytecode.lean` (the selector - bytes of each function). - -- Axioms that already exist in `Reasoning/`, including the - external-call axioms described in §6. - -Do not introduce new axioms about EVM semantics, Solm semantics, or -mapping-slot noncollision. If you think you need one, stop, report the -situation, and ask for guidance. - ---- - -## 3. File layout - -You should work exclusively in a directory `/` for the contract -you are proving. The file structure is the following: - -The proof of a contract `` goes in a directory `/`: - -| File | Role | -|---|---| -| `.sol` | the Solidity source + the exact compiler invocation used. | -| `Spec.lean` | the Solm `ContractDecl`, storage layout, `Config`. | -| `Bytecode.lean` | runtime bytecode + selector/jump-dest trusted facts. | -| `Common.lean` | contract-wide ABI / memory / selector / return / other helpers shared by ≥2 functions. | -| `Storage.lean` | contract-wide storage load/store + RBMap preservation + bool-return facts (only if it has storage). | -| `.lean` | one file per interface (public/external) function — its decode, source body, EVM trace, and `…BodyCore` refinement. | -| `Constructor.lean` | the equivalence proof of the contract's constructor. | -| `Correct.lean` | thin top-level: dispatcher driver + per-function routing + revert paths + constructor packaging + the final `theorem Correct`. | - - -- At least one file per external ABI function. Never put two ABI - functions' proofs in one file, never fold a function's body proof - into `Correct.lean` or `Common.lean`, and never let `Correct.lean` - carry body-specific complexity. - -- Shared machinery used by several functions goes in - `Common.lean`/`Storage.lean`/`Routines.lean`, not in any one - function's file. Internal/private functions are not ABI - entries. Their proofs can go into common files or their own - standalone files. - -- You can add further helper files in `/` for common lemmas and - helpers. - -- **Hard rule:** do not let files grow past 2000 lines. If this - happens you should split them into smaller files by concern. - This is important for build speed. - You can exceptionally create files larger that 2000 lines - ONLY IF ABSOLUTELY NECESSARY AND UNAVOIDABLE. - ---- - -## 4. Reasoning library and reuse - -`Reasoning/` is a library of abstractions, lemmas, and tactics for -proving EVM bytecode correct against its Solm spec. Useful reads: - -- `Reasoning/GUIDE.md` — the library map: where every kind of fact - lives, import layering, and the gotchas (native_decide for decode, - `RD.foo rd` not `rd.foo`, heartbeat budgets, etc.). - -- Each `Reasoning/*.lean` file's `/-! # … -/` header — per-module - detail. - -How to use the library: - -- Respect and extend the library's abstractions. Almost every line should apply a library lemma. - A reusable, contract-independent fact the library lacks is a missing library lemma. Add it - (proved) to the current working directory's `Common.lean` (or another local common file), - tagged `-- LIBRARY CANDIDATE: ` - (or `-- GENERALIZES Reasoning.. …` for a near-variant). - -- Never edit `Reasoning/` yourself - -- Do not reinvent. The library already discharges the solc prologue, - non-payable guard, calldata-size guard, selector load, - `RD.dispatchTo` selector routing, ABI decode/encode, memory/storage - round-trips, and the `RD`/`RDret`/`RDrev` stepping - discipline. Almost every line you write should be applying a library - lemma, not proving EVM semantics from scratch. Before writing any - arithmetic / calldata / memory / dispatch proof by hand, search for - an existing lemma. - -- Never duplicate lemmas and proof work. Always search `Reasoning/` - for existing lemmas before proving a new one. If you find yourself - proving the same fact in two places, refactor it into a single lemma - in a common file. - -- You should strive to build generic, modular, and reusable - infrastructure in your proofs and follow the library abstractions. - This will make your proofs more maintainable and easier to - understand. - -- After you are done with your proof, someone will evaluate it for - generality and reusability. If your lemmas are deemed general - enough, they will promote your lemmas to the `Reasoning/` library. - If they find that your lemmas are too specific, they will ask you to - refactor them into more generic lemmas that can be reused in other - proofs. - -- Lemma hygiene: - - 1. Make lemmas useful and general. The new lemmas that you add - should be as generic as possible, avoiding hard-coded PCs, - widths, types, and stack tails when possible. - - 2. Do not prove anticipated lemmas, unless you are 100% sure they - will be used in the final proof. - - 3. Before introducing a lemma, search `Reasoning/` and the existing - examples for one that already exists — do not re-prove it. - - 4. Never duplicate a lemma. If you find yourself writing the same - lemma in two places, refactor it into a single lemma in a common - file. If you find yourself proving similar lemmas in two places, - consider generalizing the lemma to make it reusable. - - 5. Add lemmas in the working directory (shared ones in common - files), then flag the contract-independent ones for promotion to - `Reasoning/` (below). Do not add lemmas directly to `Reasoning/`. - -- The library is not yet exercised by every Solidity construct. As you - prove new patterns you will find segments that are - contract-independent and reusable and can be promoted to the - library. When you do: - - 1. Make sure the theorem is not already proved in `Reasoning/`. Search first. - - 2. If your lemma is a near-miss of an existing one (same shape, - different PC/width/type/stack tail), that is a generalization - opportunity: write your version in the common file and mark it `-- - GENERALIZES Reasoning.. — lift by parameterizing - over `, so the library lemma can later be widened to - subsume both instead of accreting near-duplicates. - - 3. If it's genuinely new but contract-independent, mark it a fresh - `LIBRARY CANDIDATE`. The goal: every reusable fact ends up in - one place, tagged with where it belongs in `Reasoning/`, so - lifting it later is a mechanical move, not a hunt across function - files. - - 4. Collect all candidates in common files per example so the lift is - mechanical, not a scavenger hunt. - - 5. A lemma is library-ready only if it references no example-local - defs. Watch for per-example abbreviations (`addr`, `uint256`, - `uint256Int` are redefined in each `Spec.lean`); inline the raw - type or it won't compile in the library. - - ---- - -## 5. Examples - -The `Examples/` directory contains a set of template proofs. You can -use them as a reference for your own proof. - -Look at the examples to find known patterns and proof templates for -your proof. - -Note that not all examples are derived with the same compiler, -version, and optimization settings. Always check the source and -bytecode for your contract. - -The examples may lag behind recent Solm changes (they are migrated in -batches). If an example does not compile, use it as a *reading* -reference for trace/dispatch/proof patterns only — do not build it and -do not copy its conventions blindly. In particular, examples written -before the multi-value-return change show the old return conventions -(`returnType := some T` / `.return e`); the current convention is -lists (`returnType := [T]` / `.return [e]`, multi-value -`.return [a, b]`). - -- For an example of binary search dispatch, see `Examples/Ballot`. -- For an example of linear dispatch, see `Examples/ERC20`. - - -*Hard rule:* do not import code directly from `Examples/` into your proof. -If you find yourself needed the same lemma, prove it in your own working -directory and flag it for promotion to the library if it is general enough. - ---- - -## 6. Function Calls and loops - -Function calls should be proven modularly. In particular: - -- External calls (calls to other contracts): - - All external calls are proved correct by showing the bytecode and - the source semantics make to the same opaque Ethereum.EVM.Θ - invocation. Runtime RD lemmas produce the Θ witness; calldata/target - lemmas prove the bytecode memory slice matches the source ABI call; - then callCoincides or direct callViaEVM.callMade turns that into the - source-side call relation, with account-map transport handled by - typedCallViaEVM_accountMapEquiv or callViaEVM_accountMapEquiv. - - For static external calls, you may also use the proved fact that the - accounts storage is preserved by the call. - -- Internal calls: - - For internal calls, never inline the caller proof manually. Prove - the callee body once as an ExecFuncBody, then use - internalCallFunctionReturn or internalCallFunctionRevert to - discharge the caller’s .internalCall statement by supplying argument - evaluation, function lookup, parameter binding, and the callee body - proof. - - This is also true when a public function is also called internally - by another function of the contract. The callee body is proved once, - and the caller uses the callee’s lemma to discharge its internal - call. - - Reference: `Examples/Reuse`; larger patterns occur in Ballot and - BlindAuction. - - If a function `f` is called internally by another function `g`, - prove `f` before tackling the proof of `g`. - - -- Loops: - - The `Examples/BlindAuction` example has a big complicated loop in the - `Reveal` function and shows how to prove loops by induction: state - the invariant over the loop counter, prove a single reusable - body-step lemma, and close the loop by induction on the remaining - iterations, on both the Solm side and the bytecode trace. ---- - -## 7. Build discipline, tactics, proof engineering, efficiency - -- Every file should compile and should be validated by the build - system. - -- Builds are slow. Only recompile when necessary. Do not make - pointless recompilation attempts. - -- Quick elaboration is important. Prefer `simp only` over `simp`, and - `native_decide` over `decide`. Avoid tactics that blow up build - time. - -- Don't rebuild the world to check a leaf lemma. - -- If your proof is taking too long to compile, you should evaluate - your tactics and see if you can optimize them. You may also - consider splitting the proof into smaller lemmas to improve - compilation time. - -- Develop new lemmas in a small scratch file, not by editing the large - file in place. Heavy files take minutes to rebuild and every edit - re-elaborates the whole file. Create a throwaway - `/Scratch.lean` in your working directory that imports the real file (so its - defs/lemmas are in scope, compiled once and cached) and develop the - new lemma there with fast cycles. Once it compiles clean, move it - into its proper file and delete the scratch. - -- Decode obligations use `native_decide`, not `decide` (~20× faster on - big bytecode). `evm_run` cooked steps auto-supply it; raw steps - write `(by native_decide)` for decode, `(by decide)` for small side - conditions, `(by jump_dest)` for jump-dest membership, `(by evm_ov)` - for stack-overflow bounds. Keep these — the resulting `ofReduceBool` - axiom dependency is expected and fine. - -- Raise `maxHeartbeats` only on the file/lemma that needs it, with - `set_option … in` on that one theorem, not globally. - ---- - -## 8. Routine-lemma discipline - -Every repeated bytecode segment becomes one `RD`-combinator lemma, -proved once, applied many times: - -- A straight-line bytecode segment `pc_in → pc_out` over a stack tail - `R` becomes a theorem of the form `RD code … pc_in (args ++ R) … → ∃ - k' C', RD code … pc_out (results ++ R) …` (or `→ RDret` / `→ RDrev` - for terminal segments). See `RD.routine9c`, `RD.routinebb`, - `RD.routinecf`, `RD.erc20DecodeAddrMask`, - `RD.erc20MappingHashSuffix`, `RD.erc20RoutineEncodeUint256`. - -- These chain directly: `rd |>.routineA … |>.routineB …` (call as - `RD.foo rd …`, not `rd.foo` — the `RD` type whnf's to an - `Or`). Factor over a generic tail `R` so the lemma is reused at - every call site regardless of what else is on the stack. - -- Before writing a trace, scan the bytecode for segments solc shares - (decoders, the address mask/cleanup, the mapping-hash `keccak` - suffix, the uint256 ABI encoder, identity `cleanup_t_*` - routines). solc emits these once; prove them once. If you find - yourself writing the same `evm_run [...]` block in two functions, - stop and extract a lemma. - -- Generalize hard-coded constants (PCs, widths, types, stack tails) - into lemma parameters wherever possible, so the lemma is reusable - across functions. If a lemma is truly contract-independent, flag it - for promotion to `Reasoning/`. - -- Split traces into `have`s, one per sub-trace / routine. A single - giant `evm_run` over a compound tail blows the heartbeat/`whnf` - budget. Factoring a routine over a generic tail `R` needs - `set_option maxHeartbeats 1000000 in` and intermediate `have`s — see - the note in `Reasoning/GUIDE.md` and `RD.erc20DecodeAddrMask`. - -Disassemble — never guess PCs, opcodes, or jump-dests. The biggest -failure mode in these proofs is guessing contract-specific constants: -the exact `evm_run … with [push2 ⟨71⟩, dup1, …]` opcode sequence for a -basic block, the entry/exit PCs, the jump-dest set, the selector -bytes, the stack shapes. These are a pure function of the bytecode — -one wrong token fails late and opaquely and wastes a whole cycle. Read -them off the actual bytecode: disassemble `Bytecode.lean` (a short -script, `evmasm`/`solc --asm`, or by decoding the byte array) to get -each block's exact cooked-step list, its PCs, and the jump-dest array -before writing the trace. Treat the trace as "fill in the -side-conditions of a known opcode list," not "invent the opcode list." -When a step fails, re-check it against the disassembly first. - ---- - -## 9. Hard rules - -- Do not make changes outside of your working directory. - -- Do not build examples and benchmarks that are not your own. - **This is extremely important**. Builds are extremely expensive and time-consuming. - Only build your own working directory. - -- If you find misspecifications, mismatches, or unprovable - obligations, stop and report them immediately. Do not continue until - they are resolved. - -- Edit `Spec.lean` only if you are certain it is wrong, and report the - change immediately. Do not change the given bytecode or Solidity - source. - -- Never edit `Bytecode.lean`. If you suspect it is wrong, report it - immediately. - -- No `sorry` in the finished proof. - -- Do not introduce new `axiom`, unless explicitly told to do so. If - you think you need one, stop, report the situation, and ask for - guidance. - ---- - -## 10. Finish checklist - -Run, and report results verbatim: - -``` -lake build .Correct -rg -n '\b(sorry|admit)\b' -printf '%s\n' 'import .Correct' '#print axioms .Correct' | lake env lean --stdin -``` - -where `` is your working directory, `` its Lean module -path, and `` the contract's namespace — e.g. for -`Examples/ERC20/`: `Examples.ERC20`; for `Benchmarks/Dss/Dai/`: -`Benchmarks.Dss.Dai`. - -The build must succeed with no `sorry`. - -The axiom footprint should contain only -`propext`/`Classical.choice`/`Quot.sound`, the expected `ofReduceBool` -(from `native_decide`), the pre-existing library axiom -`ByteArray_zeroes_size`, your contract's selector/jump-dest facts, and -— for any contract with an external call — the tolerated external-call -axiom `Reasoning.Reach.Theta_returnData_size_lt_2pow138` (a known -trusted base being removed separately; do not block on it). -(`typedCallViaEVM_accountMapEquiv` is a proved theorem in -`Reasoning/ExternalCall.lean`, not an axiom — it does not appear in the -footprint.) Flag only anything beyond this set — a new axiom your work -introduced. From 6d4bd595db9b9e539be149b1eed8b34ac11f1cbb Mon Sep 17 00:00:00 2001 From: zoep Date: Tue, 28 Jul 2026 20:07:59 +0300 Subject: [PATCH 18/38] Reasoning: cleanup --- .../CompoundIII/CometRewards/Claim.lean | 2 +- .../CompoundIII/CometRewards/ClaimTo.lean | 2 +- .../CompoundIII/CometRewards/Common.lean | 3 +- .../CompoundIII/CometRewards/Constructor.lean | 2 +- .../CompoundIII/CometRewards/Correct.lean | 2 +- .../CometRewards/GetRewardOwed.lean | 2 +- .../CompoundIII/CometRewards/Governor.lean | 2 +- .../CometRewards/RewardConfig.lean | 2 +- .../CometRewards/RewardsClaimed.lean | 2 +- .../CompoundIII/CometRewards/Scratch.lean | 2 +- .../CometRewards/SetRewardConfig.lean | 2 +- .../SetRewardConfigWithMultiplier.lean | 2 +- .../CometRewards/SetRewardsClaimed.lean | 2 +- .../CometRewards/TransferGovernor.lean | 2 +- .../CometRewards/WithdrawToken.lean | 2 +- Benchmarks/Dss/Cat/Arithmetic.lean | 2 +- Benchmarks/Dss/Cat/Bite.lean | 2 +- Benchmarks/Dss/Cat/BiteBody.lean | 2 +- Benchmarks/Dss/Cat/BiteBodyAw.lean | 2 +- Benchmarks/Dss/Cat/BiteBodyKick.lean | 2 +- Benchmarks/Dss/Cat/BiteBodyMem.lean | 2 +- Benchmarks/Dss/Cat/BiteBodyReach.lean | 2 +- Benchmarks/Dss/Cat/BiteCallDiverge.lean | 2 +- Benchmarks/Dss/Cat/BiteCallFess.lean | 2 +- Benchmarks/Dss/Cat/BiteCallGrab.lean | 2 +- Benchmarks/Dss/Cat/BiteCallIlks.lean | 2 +- Benchmarks/Dss/Cat/BiteCallKick.lean | 2 +- Benchmarks/Dss/Cat/BiteCallUrns.lean | 2 +- Benchmarks/Dss/Cat/BiteConnect.lean | 2 +- Benchmarks/Dss/Cat/BiteConnectDecode.lean | 2 +- Benchmarks/Dss/Cat/BiteConnectGrab.lean | 2 +- Benchmarks/Dss/Cat/BiteConnectMem.lean | 2 +- Benchmarks/Dss/Cat/BiteEVM.lean | 2 +- Benchmarks/Dss/Cat/BiteGuardReach.lean | 2 +- Benchmarks/Dss/Cat/BiteRevertBranch.lean | 2 +- Benchmarks/Dss/Cat/BiteRevertLeaves.lean | 2 +- Benchmarks/Dss/Cat/BiteRevertPrim.lean | 2 +- Benchmarks/Dss/Cat/BiteSource.lean | 2 +- Benchmarks/Dss/Cat/BiteSuccessBranch.lean | 2 +- Benchmarks/Dss/Cat/BiteTrace.lean | 2 +- Benchmarks/Dss/Cat/BiteWalk.lean | 2 +- Benchmarks/Dss/Cat/Box.lean | 2 +- Benchmarks/Dss/Cat/Cage.lean | 2 +- Benchmarks/Dss/Cat/Claw.lean | 2 +- Benchmarks/Dss/Cat/Common.lean | 3 +- Benchmarks/Dss/Cat/Correct.lean | 3 +- Benchmarks/Dss/Cat/Deny.lean | 2 +- Benchmarks/Dss/Cat/FileAddress.lean | 2 +- Benchmarks/Dss/Cat/FileIlkFlip.lean | 2 +- Benchmarks/Dss/Cat/FileIlkFlipCalls.lean | 2 +- Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean | 2 +- Benchmarks/Dss/Cat/FileIlkUint.lean | 2 +- Benchmarks/Dss/Cat/FileUint.lean | 2 +- Benchmarks/Dss/Cat/Ilks.lean | 2 +- Benchmarks/Dss/Cat/Litter.lean | 2 +- Benchmarks/Dss/Cat/Live.lean | 2 +- Benchmarks/Dss/Cat/Rely.lean | 2 +- Benchmarks/Dss/Cat/Storage.lean | 2 +- Benchmarks/Dss/Cat/Vat.lean | 2 +- Benchmarks/Dss/Cat/Vow.lean | 2 +- Benchmarks/Dss/Cat/Wards.lean | 2 +- Benchmarks/Dss/Clipper/Active.lean | 2 +- Benchmarks/Dss/Clipper/Buf.lean | 2 +- Benchmarks/Dss/Clipper/Calc.lean | 2 +- Benchmarks/Dss/Clipper/Chip.lean | 2 +- Benchmarks/Dss/Clipper/Chost.lean | 2 +- Benchmarks/Dss/Clipper/Common.lean | 3 +- Benchmarks/Dss/Clipper/Correct.lean | 2 +- Benchmarks/Dss/Clipper/Count.lean | 2 +- Benchmarks/Dss/Clipper/Cusp.lean | 2 +- Benchmarks/Dss/Clipper/Deny.lean | 2 +- Benchmarks/Dss/Clipper/Dispatch.lean | 2 +- Benchmarks/Dss/Clipper/Dog.lean | 2 +- Benchmarks/Dss/Clipper/Fallback.lean | 2 +- Benchmarks/Dss/Clipper/FileAddress.lean | 2 +- Benchmarks/Dss/Clipper/FileUint.lean | 2 +- Benchmarks/Dss/Clipper/GetStatus.lean | 2 +- Benchmarks/Dss/Clipper/Ilk.lean | 2 +- Benchmarks/Dss/Clipper/Kick.lean | 2 +- Benchmarks/Dss/Clipper/Kicks.lean | 2 +- Benchmarks/Dss/Clipper/List.lean | 2 +- Benchmarks/Dss/Clipper/Redo.lean | 2 +- Benchmarks/Dss/Clipper/Rely.lean | 2 +- Benchmarks/Dss/Clipper/Sales.lean | 2 +- Benchmarks/Dss/Clipper/Spotter.lean | 2 +- Benchmarks/Dss/Clipper/Stopped.lean | 2 +- Benchmarks/Dss/Clipper/Tail.lean | 2 +- Benchmarks/Dss/Clipper/Take.lean | 2 +- Benchmarks/Dss/Clipper/Tip.lean | 2 +- Benchmarks/Dss/Clipper/UintEntry.lean | 2 +- Benchmarks/Dss/Clipper/Upchost.lean | 2 +- Benchmarks/Dss/Clipper/Vat.lean | 2 +- Benchmarks/Dss/Clipper/Vow.lean | 2 +- Benchmarks/Dss/Clipper/Wards.lean | 2 +- Benchmarks/Dss/Clipper/Yank.lean | 2 +- Benchmarks/Dss/Cure/Amt.lean | 2 +- Benchmarks/Dss/Cure/Cage.lean | 2 +- Benchmarks/Dss/Cure/Common.lean | 3 +- Benchmarks/Dss/Cure/Correct.lean | 2 +- Benchmarks/Dss/Cure/Deny.lean | 2 +- Benchmarks/Dss/Cure/Drop.lean | 2 +- Benchmarks/Dss/Cure/DropSource.lean | 2 +- Benchmarks/Dss/Cure/File.lean | 2 +- Benchmarks/Dss/Cure/LCount.lean | 2 +- Benchmarks/Dss/Cure/Lift.lean | 2 +- Benchmarks/Dss/Cure/List.lean | 2 +- Benchmarks/Dss/Cure/ListBase.lean | 2 +- Benchmarks/Dss/Cure/ListLoop.lean | 2 +- Benchmarks/Dss/Cure/Live.lean | 2 +- Benchmarks/Dss/Cure/Load.lean | 2 +- Benchmarks/Dss/Cure/LoadBase.lean | 2 +- Benchmarks/Dss/Cure/LoadSource.lean | 16 +- Benchmarks/Dss/Cure/LoadTrace.lean | 2 +- Benchmarks/Dss/Cure/Loaded.lean | 2 +- Benchmarks/Dss/Cure/Pos.lean | 2 +- Benchmarks/Dss/Cure/Rely.lean | 2 +- Benchmarks/Dss/Cure/Say.lean | 2 +- Benchmarks/Dss/Cure/Srcs.lean | 2 +- Benchmarks/Dss/Cure/TCount.lean | 2 +- Benchmarks/Dss/Cure/Tell.lean | 2 +- Benchmarks/Dss/Cure/Wait.lean | 2 +- Benchmarks/Dss/Cure/Wards.lean | 2 +- Benchmarks/Dss/Cure/When.lean | 2 +- Benchmarks/Dss/Dai/Allowance.lean | 2 +- Benchmarks/Dss/Dai/Approve.lean | 2 +- Benchmarks/Dss/Dai/BalanceOf.lean | 2 +- Benchmarks/Dss/Dai/Burn.lean | 2 +- Benchmarks/Dss/Dai/Common.lean | 3 +- Benchmarks/Dss/Dai/Constructor.lean | 2 +- Benchmarks/Dss/Dai/Correct.lean | 2 +- Benchmarks/Dss/Dai/Decimals.lean | 2 +- Benchmarks/Dss/Dai/Deny.lean | 2 +- Benchmarks/Dss/Dai/Dispatch.lean | 2 +- Benchmarks/Dss/Dai/DomainSeparator.lean | 2 +- Benchmarks/Dss/Dai/Mint.lean | 2 +- Benchmarks/Dss/Dai/Move.lean | 2 +- Benchmarks/Dss/Dai/Name.lean | 2 +- Benchmarks/Dss/Dai/Nonces.lean | 2 +- Benchmarks/Dss/Dai/Permit.lean | 2 +- Benchmarks/Dss/Dai/PermitTypehash.lean | 2 +- Benchmarks/Dss/Dai/Pull.lean | 2 +- Benchmarks/Dss/Dai/Push.lean | 2 +- Benchmarks/Dss/Dai/Rely.lean | 2 +- Benchmarks/Dss/Dai/StringReturn.lean | 2 +- Benchmarks/Dss/Dai/Symbol.lean | 2 +- Benchmarks/Dss/Dai/TotalSupply.lean | 2 +- Benchmarks/Dss/Dai/Transfer.lean | 2 +- Benchmarks/Dss/Dai/TransferFrom.lean | 2 +- Benchmarks/Dss/Dai/Version.lean | 2 +- Benchmarks/Dss/Dai/Wards.lean | 2 +- Benchmarks/Dss/DaiJoin/Cage.lean | 2 +- Benchmarks/Dss/DaiJoin/Calls.lean | 2 +- Benchmarks/Dss/DaiJoin/Common.lean | 3 +- Benchmarks/Dss/DaiJoin/Correct.lean | 2 +- Benchmarks/Dss/DaiJoin/Dai.lean | 2 +- Benchmarks/Dss/DaiJoin/Deny.lean | 2 +- Benchmarks/Dss/DaiJoin/Dispatch.lean | 2 +- Benchmarks/Dss/DaiJoin/Exit.lean | 2 +- Benchmarks/Dss/DaiJoin/ExitRuntime.lean | 2 +- Benchmarks/Dss/DaiJoin/Join.lean | 2 +- Benchmarks/Dss/DaiJoin/JoinTrace.lean | 2 +- Benchmarks/Dss/DaiJoin/Live.lean | 2 +- Benchmarks/Dss/DaiJoin/Mul.lean | 2 +- Benchmarks/Dss/DaiJoin/Rely.lean | 2 +- Benchmarks/Dss/DaiJoin/Vat.lean | 2 +- Benchmarks/Dss/DaiJoin/Wards.lean | 2 +- Benchmarks/Dss/Dog/Bark.lean | 2 +- Benchmarks/Dss/Dog/Cage.lean | 2 +- Benchmarks/Dss/Dog/Chop.lean | 2 +- Benchmarks/Dss/Dog/Common.lean | 3 +- Benchmarks/Dss/Dog/Correct.lean | 2 +- Benchmarks/Dss/Dog/Deny.lean | 2 +- Benchmarks/Dss/Dog/Digs.lean | 2 +- Benchmarks/Dss/Dog/Dirt.lean | 2 +- Benchmarks/Dss/Dog/Dispatch.lean | 2 +- Benchmarks/Dss/Dog/FileAddress.lean | 2 +- Benchmarks/Dss/Dog/FileIlkClip.lean | 2 +- Benchmarks/Dss/Dog/FileIlkUint.lean | 2 +- Benchmarks/Dss/Dog/FileUint.lean | 2 +- Benchmarks/Dss/Dog/Hole.lean | 2 +- Benchmarks/Dss/Dog/Ilks.lean | 2 +- Benchmarks/Dss/Dog/Live.lean | 2 +- Benchmarks/Dss/Dog/Rely.lean | 2 +- Benchmarks/Dss/Dog/Vat.lean | 2 +- Benchmarks/Dss/Dog/Vow.lean | 2 +- Benchmarks/Dss/Dog/Wards.lean | 2 +- Benchmarks/Dss/End/Art.lean | 2 +- Benchmarks/Dss/End/Bag.lean | 2 +- Benchmarks/Dss/End/Cage.lean | 20 +- Benchmarks/Dss/End/CageIlk.lean | 22 +- Benchmarks/Dss/End/Cash.lean | 16 +- Benchmarks/Dss/End/Cat.lean | 2 +- Benchmarks/Dss/End/Common.lean | 3 +- Benchmarks/Dss/End/Constructor.lean | 2 +- Benchmarks/Dss/End/Correct.lean | 2 +- Benchmarks/Dss/End/Cure.lean | 2 +- Benchmarks/Dss/End/Debt.lean | 2 +- Benchmarks/Dss/End/Deny.lean | 2 +- Benchmarks/Dss/End/Dispatch.lean | 2 +- Benchmarks/Dss/End/Dog.lean | 2 +- Benchmarks/Dss/End/FileAddress.lean | 2 +- Benchmarks/Dss/End/FileAddressTail.lean | 2 +- Benchmarks/Dss/End/FileUint.lean | 2 +- Benchmarks/Dss/End/Fix.lean | 2 +- Benchmarks/Dss/End/Flow.lean | 10 +- Benchmarks/Dss/End/Free.lean | 18 +- Benchmarks/Dss/End/Gap.lean | 2 +- Benchmarks/Dss/End/Live.lean | 2 +- Benchmarks/Dss/End/Out.lean | 2 +- Benchmarks/Dss/End/Pack.lean | 10 +- Benchmarks/Dss/End/PackBody.lean | 2 +- Benchmarks/Dss/End/Pot.lean | 2 +- Benchmarks/Dss/End/Rely.lean | 2 +- Benchmarks/Dss/End/Skim.lean | 26 +- Benchmarks/Dss/End/Skip.lean | 94 +- Benchmarks/Dss/End/Snip.lean | 64 +- Benchmarks/Dss/End/Spot.lean | 2 +- Benchmarks/Dss/End/Tag.lean | 2 +- Benchmarks/Dss/End/Thaw.lean | 40 +- Benchmarks/Dss/End/Vat.lean | 2 +- Benchmarks/Dss/End/Vow.lean | 2 +- Benchmarks/Dss/End/Wait.lean | 2 +- Benchmarks/Dss/End/Wards.lean | 2 +- Benchmarks/Dss/End/When.lean | 2 +- .../Dss/ExponentialDecrease/Common.lean | 3 +- .../Dss/ExponentialDecrease/Constructor.lean | 2 +- Benchmarks/Dss/ExponentialDecrease/Cut.lean | 2 +- Benchmarks/Dss/ExponentialDecrease/Deny.lean | 2 +- .../Dss/ExponentialDecrease/Dispatch.lean | 2 +- Benchmarks/Dss/ExponentialDecrease/File.lean | 2 +- Benchmarks/Dss/ExponentialDecrease/Price.lean | 2 +- .../Dss/ExponentialDecrease/PriceSource.lean | 2 +- Benchmarks/Dss/ExponentialDecrease/Rely.lean | 2 +- .../RpowArithmeticExpr.lean | 2 +- .../RpowArithmeticLocals.lean | 2 +- .../RpowArithmeticLoop.lean | 2 +- .../Dss/ExponentialDecrease/RpowEVM.lean | 2 +- .../Dss/ExponentialDecrease/RpowSource.lean | 2 +- Benchmarks/Dss/ExponentialDecrease/Wards.lean | 2 +- Benchmarks/Dss/Flapper/Beg.lean | 2 +- Benchmarks/Dss/Flapper/Bids.lean | 2 +- Benchmarks/Dss/Flapper/Cage.lean | 2 +- Benchmarks/Dss/Flapper/Common.lean | 3 +- Benchmarks/Dss/Flapper/Correct.lean | 2 +- Benchmarks/Dss/Flapper/Deal.lean | 24 +- Benchmarks/Dss/Flapper/Deny.lean | 2 +- Benchmarks/Dss/Flapper/Dispatch.lean | 2 +- Benchmarks/Dss/Flapper/File.lean | 2 +- Benchmarks/Dss/Flapper/Fill.lean | 2 +- Benchmarks/Dss/Flapper/Gem.lean | 2 +- Benchmarks/Dss/Flapper/Kick.lean | 8 +- Benchmarks/Dss/Flapper/Kicks.lean | 2 +- Benchmarks/Dss/Flapper/Lid.lean | 2 +- Benchmarks/Dss/Flapper/Live.lean | 2 +- Benchmarks/Dss/Flapper/Rely.lean | 2 +- Benchmarks/Dss/Flapper/Tau.lean | 2 +- Benchmarks/Dss/Flapper/Tend.lean | 48 +- Benchmarks/Dss/Flapper/Tick.lean | 2 +- Benchmarks/Dss/Flapper/Ttl.lean | 2 +- Benchmarks/Dss/Flapper/Vat.lean | 2 +- Benchmarks/Dss/Flapper/Wards.lean | 2 +- Benchmarks/Dss/Flapper/Yank.lean | 6 +- Benchmarks/Dss/Flipper/Beg.lean | 2 +- Benchmarks/Dss/Flipper/BidAccess.lean | 2 +- Benchmarks/Dss/Flipper/BidDelete.lean | 2 +- Benchmarks/Dss/Flipper/BidStorage.lean | 2 +- Benchmarks/Dss/Flipper/Bids.lean | 2 +- Benchmarks/Dss/Flipper/Cat.lean | 2 +- Benchmarks/Dss/Flipper/CheckedMul.lean | 2 +- Benchmarks/Dss/Flipper/Common.lean | 3 +- Benchmarks/Dss/Flipper/CommonRoutines.lean | 2 +- Benchmarks/Dss/Flipper/Correct.lean | 2 +- Benchmarks/Dss/Flipper/Deal.lean | 2 +- Benchmarks/Dss/Flipper/DealEVM.lean | 2 +- Benchmarks/Dss/Flipper/DealSource.lean | 2 +- Benchmarks/Dss/Flipper/DealTicEVM.lean | 2 +- Benchmarks/Dss/Flipper/Dent.lean | 2 +- Benchmarks/Dss/Flipper/DentBody.lean | 2 +- Benchmarks/Dss/Flipper/DentBodyBranch.lean | 2 +- Benchmarks/Dss/Flipper/DentDecreaseGuard.lean | 2 +- Benchmarks/Dss/Flipper/DentLotGuard.lean | 2 +- Benchmarks/Dss/Flipper/DentRefund.lean | 2 +- Benchmarks/Dss/Flipper/DentRefundEVM.lean | 2 +- Benchmarks/Dss/Flipper/DentRefundMain.lean | 2 +- Benchmarks/Dss/Flipper/DentSameCaller.lean | 2 +- Benchmarks/Dss/Flipper/DentTail.lean | 2 +- Benchmarks/Dss/Flipper/Deny.lean | 2 +- Benchmarks/Dss/Flipper/Dispatch.lean | 2 +- Benchmarks/Dss/Flipper/ErrorStringFull.lean | 2 +- .../Dss/Flipper/ExternalCallTransport.lean | 2 +- Benchmarks/Dss/Flipper/ExternalTargets.lean | 2 +- Benchmarks/Dss/Flipper/FileAddress.lean | 2 +- Benchmarks/Dss/Flipper/FileUint.lean | 2 +- Benchmarks/Dss/Flipper/Ilk.lean | 2 +- Benchmarks/Dss/Flipper/Kick.lean | 2 +- Benchmarks/Dss/Flipper/KickBody.lean | 2 +- Benchmarks/Dss/Flipper/KickTail.lean | 2 +- Benchmarks/Dss/Flipper/Kicks.lean | 2 +- Benchmarks/Dss/Flipper/Rely.lean | 2 +- Benchmarks/Dss/Flipper/Tau.lean | 2 +- Benchmarks/Dss/Flipper/Tend.lean | 2 +- Benchmarks/Dss/Flipper/TendBidGuard.lean | 2 +- Benchmarks/Dss/Flipper/TendBody.lean | 2 +- Benchmarks/Dss/Flipper/TendIncreaseGuard.lean | 2 +- Benchmarks/Dss/Flipper/TendRefund.lean | 2 +- Benchmarks/Dss/Flipper/TendSameCaller.lean | 2 +- Benchmarks/Dss/Flipper/TendSourceTail.lean | 2 +- Benchmarks/Dss/Flipper/TendTail.lean | 2 +- Benchmarks/Dss/Flipper/Tick.lean | 2 +- Benchmarks/Dss/Flipper/Ttl.lean | 2 +- Benchmarks/Dss/Flipper/Vat.lean | 2 +- Benchmarks/Dss/Flipper/Wards.lean | 2 +- Benchmarks/Dss/Flipper/Yank.lean | 2 +- Benchmarks/Dss/Flipper/YankBody.lean | 2 +- Benchmarks/Dss/Flipper/YankCalls.lean | 2 +- Benchmarks/Dss/Flopper/AuctionCommon.lean | 2 +- Benchmarks/Dss/Flopper/Beg.lean | 2 +- Benchmarks/Dss/Flopper/Bids.lean | 2 +- Benchmarks/Dss/Flopper/Cage.lean | 2 +- Benchmarks/Dss/Flopper/Common.lean | 3 +- Benchmarks/Dss/Flopper/Correct.lean | 2 +- Benchmarks/Dss/Flopper/Deal.lean | 6 +- Benchmarks/Dss/Flopper/DealRuntime.lean | 2 +- Benchmarks/Dss/Flopper/Dent/Part1.lean | 8 +- Benchmarks/Dss/Flopper/Dent/Part10.lean | 2 +- Benchmarks/Dss/Flopper/Dent/Part2.lean | 2 +- Benchmarks/Dss/Flopper/Dent/Part3.lean | 50 +- Benchmarks/Dss/Flopper/Dent/Part4.lean | 20 +- Benchmarks/Dss/Flopper/Dent/Part5.lean | 2 +- Benchmarks/Dss/Flopper/Dent/Part6.lean | 2 +- Benchmarks/Dss/Flopper/Dent/Part7.lean | 2 +- Benchmarks/Dss/Flopper/Dent/Part8.lean | 2 +- Benchmarks/Dss/Flopper/Dent/Part9.lean | 2 +- Benchmarks/Dss/Flopper/Deny.lean | 2 +- Benchmarks/Dss/Flopper/Dispatch.lean | 2 +- Benchmarks/Dss/Flopper/File/Part1.lean | 2 +- Benchmarks/Dss/Flopper/File/Part2.lean | 2 +- Benchmarks/Dss/Flopper/Gem.lean | 2 +- Benchmarks/Dss/Flopper/Kick/Part1.lean | 2 +- Benchmarks/Dss/Flopper/Kick/Part2.lean | 2 +- Benchmarks/Dss/Flopper/Kicks.lean | 2 +- Benchmarks/Dss/Flopper/Live.lean | 2 +- Benchmarks/Dss/Flopper/Pad.lean | 2 +- Benchmarks/Dss/Flopper/Rely.lean | 2 +- Benchmarks/Dss/Flopper/Tau.lean | 2 +- Benchmarks/Dss/Flopper/Tick/Part1.lean | 8 +- Benchmarks/Dss/Flopper/Tick/Part2.lean | 2 +- Benchmarks/Dss/Flopper/Ttl.lean | 2 +- Benchmarks/Dss/Flopper/Vat.lean | 2 +- Benchmarks/Dss/Flopper/Vow.lean | 2 +- Benchmarks/Dss/Flopper/Wards.lean | 2 +- Benchmarks/Dss/Flopper/Yank/Part1.lean | 6 +- Benchmarks/Dss/Flopper/Yank/Part2.lean | 2 +- Benchmarks/Dss/GemJoin/Cage.lean | 2 +- Benchmarks/Dss/GemJoin/Common.lean | 3 +- Benchmarks/Dss/GemJoin/Correct.lean | 2 +- Benchmarks/Dss/GemJoin/Dec.lean | 2 +- Benchmarks/Dss/GemJoin/Deny.lean | 2 +- Benchmarks/Dss/GemJoin/Dispatch.lean | 2 +- Benchmarks/Dss/GemJoin/Exit.lean | 2 +- Benchmarks/Dss/GemJoin/Gem.lean | 2 +- Benchmarks/Dss/GemJoin/Ilk.lean | 2 +- Benchmarks/Dss/GemJoin/Join.lean | 2 +- Benchmarks/Dss/GemJoin/Live.lean | 2 +- Benchmarks/Dss/GemJoin/Rely.lean | 2 +- Benchmarks/Dss/GemJoin/Vat.lean | 2 +- Benchmarks/Dss/GemJoin/Wards.lean | 2 +- Benchmarks/Dss/Jug/ArithmeticAddDiff.lean | 2 +- Benchmarks/Dss/Jug/ArithmeticExpr.lean | 2 +- Benchmarks/Dss/Jug/ArithmeticLocals.lean | 2 +- Benchmarks/Dss/Jug/ArithmeticRmulRpow.lean | 2 +- Benchmarks/Dss/Jug/ArithmeticRpowLoop.lean | 2 +- Benchmarks/Dss/Jug/Base.lean | 2 +- Benchmarks/Dss/Jug/Common.lean | 3 +- Benchmarks/Dss/Jug/Correct.lean | 2 +- Benchmarks/Dss/Jug/Deny.lean | 2 +- Benchmarks/Dss/Jug/Dispatch.lean | 2 +- Benchmarks/Dss/Jug/Drip.lean | 2 +- Benchmarks/Dss/Jug/DripBase.lean | 2 +- .../Dss/Jug/DripBodyAddReturnsTactic.lean | 2 +- Benchmarks/Dss/Jug/DripBodyAgeOneTactic.lean | 2 +- Benchmarks/Dss/Jug/DripBodyCore.lean | 2 +- Benchmarks/Dss/Jug/DripBodyFeeZeroTactic.lean | 2 +- Benchmarks/Dss/Jug/DripBodyGenericTactic.lean | 2 +- Benchmarks/Dss/Jug/DripBodyNZeroTactic.lean | 2 +- Benchmarks/Dss/Jug/DripEVMFold.lean | 2 +- Benchmarks/Dss/Jug/DripEVMRpow.lean | 2 +- Benchmarks/Dss/Jug/DripEVMVat.lean | 2 +- Benchmarks/Dss/Jug/DripSourceFold.lean | 2 +- Benchmarks/Dss/Jug/DripSourceGenericFold.lean | 2 +- Benchmarks/Dss/Jug/DripSourceGenericRpow.lean | 2 +- Benchmarks/Dss/Jug/DripSourceNOne.lean | 2 +- Benchmarks/Dss/Jug/DripSourceRho.lean | 2 +- Benchmarks/Dss/Jug/DripSourceXZero.lean | 2 +- Benchmarks/Dss/Jug/FileBase.lean | 2 +- Benchmarks/Dss/Jug/FileDuty.lean | 2 +- Benchmarks/Dss/Jug/FileVow.lean | 2 +- Benchmarks/Dss/Jug/Ilks.lean | 2 +- Benchmarks/Dss/Jug/Init.lean | 2 +- Benchmarks/Dss/Jug/Rely.lean | 2 +- Benchmarks/Dss/Jug/Rpow.lean | 2 +- Benchmarks/Dss/Jug/RpowGeneric.lean | 2 +- Benchmarks/Dss/Jug/Vat.lean | 2 +- Benchmarks/Dss/Jug/Vow.lean | 2 +- Benchmarks/Dss/Jug/Wards.lean | 2 +- Benchmarks/Dss/LinearDecrease/Common.lean | 3 +- .../Dss/LinearDecrease/Constructor.lean | 2 +- Benchmarks/Dss/LinearDecrease/Deny.lean | 2 +- Benchmarks/Dss/LinearDecrease/Dispatch.lean | 2 +- Benchmarks/Dss/LinearDecrease/File.lean | 2 +- Benchmarks/Dss/LinearDecrease/Price.lean | 2 +- Benchmarks/Dss/LinearDecrease/Rely.lean | 2 +- Benchmarks/Dss/LinearDecrease/Tau.lean | 2 +- Benchmarks/Dss/LinearDecrease/Wards.lean | 2 +- Benchmarks/Dss/Pot/Arith.lean | 2 +- Benchmarks/Dss/Pot/ArithExpr.lean | 2 +- Benchmarks/Dss/Pot/Cage.lean | 2 +- Benchmarks/Dss/Pot/Chi.lean | 2 +- Benchmarks/Dss/Pot/Common.lean | 3 +- Benchmarks/Dss/Pot/Correct.lean | 2 +- Benchmarks/Dss/Pot/Deny.lean | 2 +- Benchmarks/Dss/Pot/Dispatch.lean | 2 +- Benchmarks/Dss/Pot/Drip.lean | 2 +- Benchmarks/Dss/Pot/DripCommon.lean | 2 +- Benchmarks/Dss/Pot/DripEVMArith.lean | 2 +- Benchmarks/Dss/Pot/DripEVMSuck.lean | 2 +- Benchmarks/Dss/Pot/DripSource.lean | 2 +- Benchmarks/Dss/Pot/DripSuckBase.lean | 2 +- Benchmarks/Dss/Pot/Dsr.lean | 2 +- Benchmarks/Dss/Pot/Exit.lean | 2 +- Benchmarks/Dss/Pot/FileDsr.lean | 2 +- Benchmarks/Dss/Pot/FileVow.lean | 2 +- Benchmarks/Dss/Pot/Join.lean | 2 +- Benchmarks/Dss/Pot/Live.lean | 2 +- Benchmarks/Dss/Pot/Pie.lean | 2 +- Benchmarks/Dss/Pot/PieTotal.lean | 2 +- Benchmarks/Dss/Pot/Rely.lean | 2 +- Benchmarks/Dss/Pot/Rho.lean | 2 +- Benchmarks/Dss/Pot/Rpow.lean | 2 +- Benchmarks/Dss/Pot/RpowGeneric.lean | 2 +- Benchmarks/Dss/Pot/RpowLoop.lean | 2 +- Benchmarks/Dss/Pot/Vat.lean | 2 +- Benchmarks/Dss/Pot/Vow.lean | 2 +- Benchmarks/Dss/Pot/Wards.lean | 2 +- Benchmarks/Dss/Spot/Cage.lean | 2 +- Benchmarks/Dss/Spot/Common.lean | 3 +- Benchmarks/Dss/Spot/Correct.lean | 2 +- Benchmarks/Dss/Spot/Deny.lean | 2 +- Benchmarks/Dss/Spot/Dispatch.lean | 2 +- Benchmarks/Dss/Spot/FileMat.lean | 2 +- Benchmarks/Dss/Spot/FilePar.lean | 2 +- Benchmarks/Dss/Spot/FilePip.lean | 2 +- Benchmarks/Dss/Spot/Ilks.lean | 2 +- Benchmarks/Dss/Spot/Live.lean | 2 +- Benchmarks/Dss/Spot/Par.lean | 2 +- Benchmarks/Dss/Spot/Poke.lean | 2 +- Benchmarks/Dss/Spot/PokeArithmetic.lean | 2 +- Benchmarks/Dss/Spot/PokeBase.lean | 2 +- Benchmarks/Dss/Spot/PokeCalls.lean | 2 +- Benchmarks/Dss/Spot/PokeDecode.lean | 2 +- Benchmarks/Dss/Spot/PokeSource.lean | 2 +- Benchmarks/Dss/Spot/PokeTrace.lean | 2 +- Benchmarks/Dss/Spot/PokeTraceBody.lean | 2 +- Benchmarks/Dss/Spot/Rely.lean | 2 +- Benchmarks/Dss/Spot/Vat.lean | 2 +- Benchmarks/Dss/Spot/Wards.lean | 2 +- .../StairstepExponentialDecrease/Common.lean | 3 +- .../Constructor.lean | 2 +- .../StairstepExponentialDecrease/Correct.lean | 2 +- .../Dss/StairstepExponentialDecrease/Cut.lean | 2 +- .../StairstepExponentialDecrease/Deny.lean | 2 +- .../Dispatch.lean | 2 +- .../StairstepExponentialDecrease/File.lean | 2 +- .../StairstepExponentialDecrease/Price.lean | 2 +- .../PriceSource.lean | 2 +- .../StairstepExponentialDecrease/Rely.lean | 2 +- .../RpowArithmeticExpr.lean | 2 +- .../RpowArithmeticLocals.lean | 2 +- .../RpowArithmeticLoop.lean | 2 +- .../StairstepExponentialDecrease/RpowEVM.lean | 2 +- .../RpowSource.lean | 2 +- .../StairstepExponentialDecrease/Step.lean | 2 +- .../StairstepExponentialDecrease/Wards.lean | 2 +- Benchmarks/Dss/Vat/Cage.lean | 2 +- Benchmarks/Dss/Vat/Can.lean | 2 +- Benchmarks/Dss/Vat/Common.lean | 3 +- Benchmarks/Dss/Vat/Correct.lean | 3 +- Benchmarks/Dss/Vat/Dai.lean | 2 +- Benchmarks/Dss/Vat/Debt.lean | 2 +- Benchmarks/Dss/Vat/Deny.lean | 2 +- Benchmarks/Dss/Vat/Dispatch.lean | 2 +- Benchmarks/Dss/Vat/FileIlk.lean | 2 +- Benchmarks/Dss/Vat/FileLine.lean | 2 +- Benchmarks/Dss/Vat/Flux.lean | 2 +- Benchmarks/Dss/Vat/Fold.lean | 2 +- Benchmarks/Dss/Vat/FoldCommon.lean | 22 +- Benchmarks/Dss/Vat/FoldTail.lean | 24 +- Benchmarks/Dss/Vat/Fork.lean | 182 +- Benchmarks/Dss/Vat/Frob.lean | 2 +- Benchmarks/Dss/Vat/FrobBase.lean | 56 +- Benchmarks/Dss/Vat/FrobLive.lean | 40 +- Benchmarks/Dss/Vat/FrobLiveBase.lean | 2 +- Benchmarks/Dss/Vat/FrobLiveSuccess.lean | 40 +- Benchmarks/Dss/Vat/Gem.lean | 2 +- Benchmarks/Dss/Vat/Grab.lean | 80 +- Benchmarks/Dss/Vat/Heal.lean | 2 +- Benchmarks/Dss/Vat/HealBase.lean | 2 +- Benchmarks/Dss/Vat/Hope.lean | 2 +- Benchmarks/Dss/Vat/Ilks.lean | 2 +- Benchmarks/Dss/Vat/Init.lean | 2 +- Benchmarks/Dss/Vat/Line.lean | 2 +- Benchmarks/Dss/Vat/Live.lean | 2 +- Benchmarks/Dss/Vat/Move.lean | 2 +- Benchmarks/Dss/Vat/Nope.lean | 2 +- Benchmarks/Dss/Vat/Rely.lean | 2 +- Benchmarks/Dss/Vat/Signed.lean | 2 +- Benchmarks/Dss/Vat/Sin.lean | 2 +- Benchmarks/Dss/Vat/Slip.lean | 2 +- Benchmarks/Dss/Vat/Suck.lean | 106 +- Benchmarks/Dss/Vat/Urns.lean | 2 +- Benchmarks/Dss/Vat/Vice.lean | 2 +- Benchmarks/Dss/Vat/Wards.lean | 2 +- Benchmarks/Dss/Vow/Arithmetic.lean | 2 +- Benchmarks/Dss/Vow/Ash.lean | 2 +- Benchmarks/Dss/Vow/Bump.lean | 2 +- Benchmarks/Dss/Vow/Cage.lean | 2 +- Benchmarks/Dss/Vow/CageBody.lean | 2 +- Benchmarks/Dss/Vow/CageBodyRuntime.lean | 2 +- Benchmarks/Dss/Vow/CageBodyRuntimeTail.lean | 2 +- Benchmarks/Dss/Vow/CageHealRuntime.lean | 22 +- Benchmarks/Dss/Vow/CageRuntime.lean | 58 +- Benchmarks/Dss/Vow/CageTailRuntime.lean | 46 +- Benchmarks/Dss/Vow/Common.lean | 3 +- Benchmarks/Dss/Vow/Constructor.lean | 6 +- Benchmarks/Dss/Vow/Correct.lean | 3 +- Benchmarks/Dss/Vow/Deny.lean | 2 +- Benchmarks/Dss/Vow/Dump.lean | 2 +- Benchmarks/Dss/Vow/Fess.lean | 2 +- Benchmarks/Dss/Vow/FileAddress.lean | 2 +- Benchmarks/Dss/Vow/FileAddressFlapper.lean | 2 +- .../Dss/Vow/FileAddressFlapperBody.lean | 2 +- Benchmarks/Dss/Vow/FileUint.lean | 2 +- Benchmarks/Dss/Vow/Flap.lean | 2 +- Benchmarks/Dss/Vow/FlapAdd.lean | 2 +- Benchmarks/Dss/Vow/FlapBody.lean | 8 +- Benchmarks/Dss/Vow/FlapDai.lean | 2 +- Benchmarks/Dss/Vow/FlapDaiBody.lean | 8 +- Benchmarks/Dss/Vow/FlapKick.lean | 2 +- Benchmarks/Dss/Vow/FlapKickBody.lean | 10 +- Benchmarks/Dss/Vow/FlapRuntime.lean | 2 +- Benchmarks/Dss/Vow/FlapSin1.lean | 2 +- Benchmarks/Dss/Vow/FlapSin1Body.lean | 8 +- Benchmarks/Dss/Vow/FlapSubBody.lean | 8 +- Benchmarks/Dss/Vow/Flapper.lean | 2 +- Benchmarks/Dss/Vow/Flog.lean | 2 +- Benchmarks/Dss/Vow/Flop.lean | 2 +- Benchmarks/Dss/Vow/FlopAsh.lean | 2 +- Benchmarks/Dss/Vow/FlopBody.lean | 2 +- Benchmarks/Dss/Vow/FlopDai.lean | 2 +- Benchmarks/Dss/Vow/FlopKick.lean | 2 +- Benchmarks/Dss/Vow/Flopper.lean | 2 +- Benchmarks/Dss/Vow/Heal.lean | 2 +- Benchmarks/Dss/Vow/HealBody.lean | 2 +- Benchmarks/Dss/Vow/HealFinal.lean | 2 +- Benchmarks/Dss/Vow/HealSuccess.lean | 2 +- Benchmarks/Dss/Vow/Hump.lean | 2 +- Benchmarks/Dss/Vow/Kiss.lean | 2 +- Benchmarks/Dss/Vow/KissSuccess.lean | 2 +- Benchmarks/Dss/Vow/Live.lean | 2 +- Benchmarks/Dss/Vow/Rely.lean | 2 +- Benchmarks/Dss/Vow/Sin.lean | 2 +- Benchmarks/Dss/Vow/SinMapping.lean | 2 +- Benchmarks/Dss/Vow/Sump.lean | 2 +- Benchmarks/Dss/Vow/Vat.lean | 2 +- Benchmarks/Dss/Vow/VatDaiCall.lean | 2 +- Benchmarks/Dss/Vow/VatSinCall.lean | 2 +- Benchmarks/Dss/Vow/Wait.lean | 2 +- Benchmarks/Dss/Vow/Wards.lean | 2 +- Benchmarks/ERC721/Correct.lean | 3 +- .../TimelockController/AbiDecode.lean | 2 +- .../TimelockController/AbiEncode.lean | 2 +- .../TimelockController/Body.lean | 2 +- .../TimelockController/Cancel.lean | 2 +- .../TimelockController/CancellerRole.lean | 2 +- .../TimelockController/Common.lean | 3 +- .../TimelockController/ConstructorDefs.lean | 2 +- .../TimelockController/ConstructorEvm.lean | 2 +- .../TimelockController/ConstructorSolm.lean | 2 +- .../TimelockController/Correct.lean | 2 +- .../TimelockController/DefaultAdminRole.lean | 2 +- .../TimelockController/Dispatch.lean | 2 +- .../TimelockController/EvmExec.lean | 2 +- .../TimelockController/EvmReach.lean | 2 +- .../TimelockController/EvmReverts.lean | 2 +- .../TimelockController/Execute.lean | 2 +- .../TimelockController/ExecuteBatch.lean | 2 +- .../TimelockController/ExecutorRole.lean | 2 +- .../TimelockController/Fallback.lean | 2 +- .../TimelockController/GetMinDelay.lean | 2 +- .../TimelockController/GetOperationState.lean | 2 +- .../TimelockController/GetRoleAdmin.lean | 2 +- .../TimelockController/GetTimestamp.lean | 2 +- .../TimelockController/GrantRole.lean | 2 +- .../TimelockController/HasRole.lean | 2 +- .../TimelockController/HashOperation.lean | 2 +- .../HashOperationBatch.lean | 2 +- .../TimelockController/IsOperation.lean | 2 +- .../TimelockController/IsOperationDone.lean | 2 +- .../IsOperationPending.lean | 2 +- .../TimelockController/IsOperationReady.lean | 2 +- .../OnERC1155BatchReceived.lean | 2 +- .../TimelockController/OnERC1155Received.lean | 2 +- .../TimelockController/OnERC721Received.lean | 2 +- .../TimelockController/ProposerRole.lean | 2 +- .../TimelockController/Receivers.lean | 2 +- .../TimelockController/RenounceRole.lean | 2 +- .../TimelockController/Return.lean | 2 +- .../TimelockController/RevokeRole.lean | 2 +- .../TimelockController/Routines.lean | 2 +- .../TimelockController/Schedule.lean | 2 +- .../TimelockController/ScheduleBatch.lean | 2 +- .../TimelockController/ScratchGrant.lean | 2 +- .../TimelockController/SolmDispatch.lean | 2 +- .../TimelockController/Storage.lean | 2 +- .../TimelockController/SupportsInterface.lean | 2 +- .../TimelockController/UpdateDelay.lean | 2 +- Benchmarks/UniswapV3Pool/Burn.lean | 2 +- .../UniswapV3Pool/BurnAfterCheckTicks.lean | 2 +- .../UniswapV3Pool/BurnAfterFeeGlobals.lean | 2 +- .../BurnAfterFeeGrowthInside.lean | 2 +- Benchmarks/UniswapV3Pool/BurnBody.lean | 2 +- Benchmarks/UniswapV3Pool/BurnCheckTicks.lean | 2 +- .../UniswapV3Pool/BurnFullMathSlow.lean | 2 +- .../BurnLowerLiquidityAddDeltaRevert.lean | 2 +- Benchmarks/UniswapV3Pool/BurnNoDelegate.lean | 2 +- .../UniswapV3Pool/BurnNonzeroDeltaStart.lean | 2 +- .../UniswapV3Pool/BurnObserveSingle.lean | 2 +- .../UniswapV3Pool/BurnPositionUpdate.lean | 2 +- .../BurnPositionUpdateMemory.lean | 2 +- .../BurnPositionUpdatePostReturn.lean | 2 +- .../BurnPositionUpdateRevert.lean | 2 +- .../BurnPositionUpdateSlowPostReturn.lean | 2 +- .../BurnPositionUpdateSource.lean | 2 +- .../BurnPositionUpdateSourceSuccess.lean | 2 +- .../BurnPositionUpdateTokensOwedBridge.lean | 2 +- .../BurnPositionUpdateTokensOwedPacking.lean | 2 +- .../BurnPositionUpdateTokensOwedStore.lean | 2 +- .../UniswapV3Pool/BurnPostPositionUpdate.lean | 2 +- .../UniswapV3Pool/BurnSourceSuccess.lean | 2 +- .../BurnTickGetFeeGrowthInsideSource.lean | 2 +- .../UniswapV3Pool/BurnTickUpdateSource.lean | 2 +- .../UniswapV3Pool/BurnTickUpdateStart.lean | 2 +- .../UniswapV3Pool/BurnTickUpdateTrace.lean | 2 +- .../UniswapV3Pool/BurnZeroDeltaFinish.lean | 2 +- .../BurnZeroDeltaMulDivStart.lean | 2 +- .../BurnZeroDeltaSlowToken0.lean | 2 +- Benchmarks/UniswapV3Pool/Common.lean | 3 +- Benchmarks/UniswapV3Pool/Factory.lean | 2 +- Benchmarks/UniswapV3Pool/Fee.lean | 2 +- .../UniswapV3Pool/FeeGrowthGlobal0X128.lean | 2 +- .../UniswapV3Pool/FeeGrowthGlobal1X128.lean | 2 +- .../UniswapV3Pool/ImmutableGetters.lean | 2 +- .../IncreaseObservationCardinalityNext.lean | 2 +- ...ncreaseObservationCardinalityNextBase.lean | 2 +- ...ncreaseObservationCardinalityNextGrow.lean | 2 +- ...aseObservationCardinalityNextGrowLoop.lean | 2 +- ...aseObservationCardinalityNextGrowTail.lean | 2 +- Benchmarks/UniswapV3Pool/Initialize.lean | 2 +- Benchmarks/UniswapV3Pool/InitializeBase.lean | 2 +- .../UniswapV3Pool/InitializeGetTick.lean | 2 +- .../UniswapV3Pool/InitializeGetTickLog.lean | 2 +- .../InitializeGetTickLog2Bridge.lean | 2 +- .../InitializeGetTickLogCombine.lean | 2 +- .../InitializeGetTickReturn.lean | 2 +- .../InitializeGetTickSqrtRatio.lean | 2 +- .../InitializeGetTickSqrtRatioBits.lean | 2 +- .../InitializeGetTickSqrtRatioBitsHigh.lean | 2 +- .../InitializeGetTickSqrtRatioFull.lean | 2 +- .../InitializeGetTickSqrtRatioNonzero.lean | 2 +- .../InitializeGetTickSqrtRatioReturn.lean | 2 +- ...nitializeGetTickSqrtRatioSourceBridge.lean | 2 +- .../InitializeGetTickWordBridge.lean | 2 +- .../InitializeSourceGetSqrtRatio.lean | 2 +- .../InitializeSourceGetSqrtRatioHighBits.lean | 2 +- .../InitializeSourceGetSqrtRatioLowBits.lean | 2 +- .../InitializeSourceGetTickLog.lean | 2 +- .../InitializeSourceGetTickLogRemaining.lean | 2 +- .../InitializeSourceGetTickLogStep60.lean | 2 +- .../InitializeSourceGetTickLogStep61.lean | 2 +- .../InitializeSourceGetTickLogStep62.lean | 2 +- .../InitializeSourceGetTickMsb.lean | 2 +- .../InitializeSourceGetTickPostLog.lean | 2 +- .../InitializeSourceStorageEquiv.lean | 2 +- .../InitializeSourceSuccess.lean | 2 +- .../UniswapV3Pool/InitializeSuccess.lean | 2 +- Benchmarks/UniswapV3Pool/Liquidity.lean | 2 +- Benchmarks/UniswapV3Pool/Locking.lean | 2 +- .../UniswapV3Pool/MaxLiquidityPerTick.lean | 2 +- Benchmarks/UniswapV3Pool/NoDelegateCall.lean | 2 +- Benchmarks/UniswapV3Pool/Observations.lean | 2 +- .../UniswapV3Pool/ObservationsInt56.lean | 2 +- Benchmarks/UniswapV3Pool/Positions.lean | 2 +- Benchmarks/UniswapV3Pool/ProtocolFees.lean | 2 +- Benchmarks/UniswapV3Pool/SetFeeProtocol.lean | 2 +- .../SetFeeProtocolFeeProtocolCheck.lean | 2 +- .../SetFeeProtocolOwnerCall.lean | 2 +- .../UniswapV3Pool/SetFeeProtocolSource.lean | 2 +- .../UniswapV3Pool/SetFeeProtocolSuccess.lean | 2 +- Benchmarks/UniswapV3Pool/Slot0.lean | 2 +- Benchmarks/UniswapV3Pool/TickBitmap.lean | 2 +- Benchmarks/UniswapV3Pool/TickSpacing.lean | 2 +- Benchmarks/UniswapV3Pool/Ticks.lean | 2 +- Benchmarks/UniswapV3Pool/TicksInt128.lean | 2 +- .../UniswapV3Pool/TicksReturnMemory.lean | 2 +- Benchmarks/UniswapV3Pool/Token0.lean | 2 +- Benchmarks/UniswapV3Pool/Token1.lean | 2 +- Benchmarks/UniswapV3Pool/Uint128.lean | 2 +- Benchmarks/WETH9/Allowance.lean | 2 +- Benchmarks/WETH9/Approve.lean | 2 +- Benchmarks/WETH9/BalanceOf.lean | 2 +- Benchmarks/WETH9/Common.lean | 3 +- Benchmarks/WETH9/Correct.lean | 2 +- Benchmarks/WETH9/Decimals.lean | 2 +- Benchmarks/WETH9/Deposit.lean | 2 +- Benchmarks/WETH9/Dispatch.lean | 2 +- Benchmarks/WETH9/Name.lean | 2 +- Benchmarks/WETH9/Routines.lean | 2 +- Benchmarks/WETH9/Storage.lean | 2 +- Benchmarks/WETH9/StringEncode.lean | 2 +- Benchmarks/WETH9/StringReturn.lean | 2 +- Benchmarks/WETH9/StringReturnLong.lean | 2 +- Benchmarks/WETH9/StringReturnLong2.lean | 2 +- Benchmarks/WETH9/StringReturnSymbol.lean | 2 +- Benchmarks/WETH9/StringReturnSymbol2.lean | 2 +- Benchmarks/WETH9/Symbol.lean | 2 +- Benchmarks/WETH9/TotalSupply.lean | 2 +- Benchmarks/WETH9/Transfer.lean | 2 +- Benchmarks/WETH9/TransferFrom.lean | 2 +- Benchmarks/WETH9/TransferFromBody.lean | 2 +- Benchmarks/WETH9/TransferFromDefs.lean | 2 +- Benchmarks/WETH9/TransferFromSolm.lean | 2 +- Benchmarks/WETH9/Withdraw.lean | 2 +- Benchmarks/WETH9/WithdrawBody.lean | 2 +- EquiVM.lean | 1 - Examples/Ballot/Chairperson.lean | 3 +- Examples/Ballot/Correct.lean | 3 +- Examples/Ballot/Delegate.lean | 3 +- Examples/Ballot/DelegateChain.lean | 2 +- Examples/Ballot/DelegateComplete.lean | 2 +- Examples/Ballot/DelegateLoop.lean | 2 +- Examples/Ballot/DelegateOOG.lean | 2 +- Examples/Ballot/DelegateTail.lean | 2 +- Examples/Ballot/DelegateTailGeneral.lean | 2 +- Examples/Ballot/GiveRightToVote.lean | 3 +- Examples/Ballot/Proposals.lean | 3 +- Examples/Ballot/Vote.lean | 3 +- Examples/Ballot/Voters.lean | 3 +- Examples/Ballot/WinnerName.lean | 3 +- Examples/Ballot/WinningProposal.lean | 3 +- Examples/BlindAuction/AuctionEnd.lean | 3 +- Examples/BlindAuction/Beneficiary.lean | 3 +- Examples/BlindAuction/Bid.lean | 3 +- Examples/BlindAuction/BiddingEnd.lean | 3 +- Examples/BlindAuction/Bids.lean | 3 +- Examples/BlindAuction/Correct.lean | 3 +- Examples/BlindAuction/Ended.lean | 3 +- Examples/BlindAuction/HighestBid.lean | 3 +- Examples/BlindAuction/HighestBidder.lean | 3 +- Examples/BlindAuction/Reveal.lean | 2 +- Examples/BlindAuction/Reveal/Assemble.lean | 2 +- Examples/BlindAuction/Reveal/Body.lean | 2 +- Examples/BlindAuction/Reveal/BodyCases.lean | 2 +- Examples/BlindAuction/Reveal/Cases.lean | 2 +- Examples/BlindAuction/Reveal/Common.lean | 2 +- Examples/BlindAuction/Reveal/Decode.lean | 3 +- Examples/BlindAuction/Reveal/Decoded.lean | 2 +- .../BlindAuction/Reveal/DecodedEmpty.lean | 2 +- .../BlindAuction/Reveal/DecodedLengthOk.lean | 2 +- .../BlindAuction/Reveal/DecodedNonempty.lean | 2 +- .../Reveal/DecodedNonemptyLoop.lean | 2 +- .../Reveal/DecodedNonemptyRun.lean | 2 +- Examples/BlindAuction/Reveal/FakeFalse.lean | 2 +- Examples/BlindAuction/Reveal/Loop.lean | 2 +- Examples/BlindAuction/Reveal/Nonempty.lean | 2 +- Examples/BlindAuction/Reveal/PlaceBid.lean | 2 +- Examples/BlindAuction/Reveal/PostLoop.lean | 2 +- .../BlindAuction/Reveal/PostLoopBranches.lean | 2 +- Examples/BlindAuction/RevealEnd.lean | 3 +- Examples/BlindAuction/Withdraw.lean | 3 +- Examples/CallerCoupled/BodySuccess.lean | 1461 ----------------- Examples/ERC20/Allowance.lean | 3 +- Examples/ERC20/Approve.lean | 3 +- Examples/ERC20/BalanceOf.lean | 3 +- Examples/ERC20/Correct.lean | 3 +- .../ERC20/{SpecSugar.lean => SpecSyntax.lean} | 8 +- Examples/ERC20/TotalSupply.lean | 3 +- Examples/ERC20/Transfer.lean | 3 +- Examples/ERC20/TransferFrom.lean | 2 +- .../AccessControl/Correct.lean | 3 +- .../AccessControl/DefaultAdminRole.lean | 3 +- .../AccessControl/GetRoleAdmin.lean | 3 +- .../AccessControl/GrantRole.lean | 3 +- .../AccessControl/HasRole.lean | 3 +- .../AccessControl/RenounceRole.lean | 3 +- .../AccessControl/RevokeRole.lean | 3 +- .../AccessControl/SupportsInterface.lean | 3 +- .../OpenZeppelinBench/ERC6909/Allowance.lean | 3 +- .../OpenZeppelinBench/ERC6909/Approve.lean | 3 +- .../OpenZeppelinBench/ERC6909/BalanceOf.lean | 3 +- .../OpenZeppelinBench/ERC6909/Correct.lean | 3 +- .../OpenZeppelinBench/ERC6909/IsOperator.lean | 3 +- .../ERC6909/SetOperator.lean | 3 +- .../ERC6909/SupportsInterface.lean | 3 +- .../OpenZeppelinBench/ERC6909/Transfer.lean | 3 +- .../ERC6909/TransferFrom.lean | 2 +- .../ERC6909/TransferFrom/Cases.lean | 2 +- .../ERC6909/TransferFrom/Common.lean | 2 +- .../ERC6909/TransferFrom/Decode.lean | 3 +- .../TransferFrom/Traces/Allowance.lean | 2 +- .../TransferFrom/Traces/DebitTail.lean | 2 +- .../ERC6909/TransferFrom/Traces/Memory.lean | 2 +- .../ERC6909/TransferFrom/Traces/Operator.lean | 2 +- .../TransferFrom/Traces/SkipCaller.lean | 2 +- .../Ownable2Step/AcceptOwnership.lean | 3 +- .../Ownable2Step/Common.lean | 3 +- .../Ownable2Step/Correct.lean | 2 +- .../OpenZeppelinBench/Ownable2Step/Owner.lean | 3 +- .../Ownable2Step/PendingOwner.lean | 3 +- .../Ownable2Step/RenounceOwnership.lean | 3 +- .../Ownable2Step/TransferOwnership.lean | 3 +- .../OpenZeppelinBench/Pausable/Common.lean | 3 +- .../OpenZeppelinBench/Pausable/Correct.lean | 2 +- .../Pausable/GuardedWhenNotPaused.lean | 2 +- .../Pausable/GuardedWhenPaused.lean | 2 +- .../OpenZeppelinBench/Pausable/Pause.lean | 2 +- .../OpenZeppelinBench/Pausable/Paused.lean | 2 +- .../OpenZeppelinBench/Pausable/Unpause.lean | 2 +- Examples/PowCoupled/BodySuccess.lean | 248 --- Examples/SimpleAuction/AuctionEnd.lean | 3 +- Examples/SimpleAuction/AuctionEndTime.lean | 3 +- Examples/SimpleAuction/Beneficiary.lean | 3 +- Examples/SimpleAuction/Bid.lean | 3 +- Examples/SimpleAuction/Correct.lean | 3 +- Examples/SimpleAuction/HighestBid.lean | 3 +- Examples/SimpleAuction/HighestBidder.lean | 3 +- Examples/SimpleAuction/Withdraw.lean | 3 +- Examples/UniswapV2Pair/Allowance.lean | 3 +- Examples/UniswapV2Pair/Approve.lean | 3 +- Examples/UniswapV2Pair/BalanceCallSource.lean | 2 +- Examples/UniswapV2Pair/BalanceOf.lean | 3 +- Examples/UniswapV2Pair/Burn.lean | 3 +- Examples/UniswapV2Pair/Common.lean | 17 +- Examples/UniswapV2Pair/Correct.lean | 2 +- Examples/UniswapV2Pair/Decimals.lean | 3 +- Examples/UniswapV2Pair/Dispatch.lean | 2 +- Examples/UniswapV2Pair/DomainSeparator.lean | 3 +- Examples/UniswapV2Pair/Factory.lean | 3 +- Examples/UniswapV2Pair/GetReserves.lean | 3 +- Examples/UniswapV2Pair/Initialize.lean | 3 +- Examples/UniswapV2Pair/KLast.lean | 3 +- Examples/UniswapV2Pair/MinimumLiquidity.lean | 3 +- Examples/UniswapV2Pair/Mint.lean | 2 +- Examples/UniswapV2Pair/MintBodyPrelude.lean | 2 +- Examples/UniswapV2Pair/MintCommon.lean | 3 +- .../MintFeeOnKLastNonzeroFactoryCases.lean | 2 +- ...tFeeOnKLastNonzeroInitialFactoryCases.lean | 2 +- ...FeeOnKLastNonzeroInitialOverflowCases.lean | 2 +- .../MintFeeOnKLastNonzeroRevertCases.lean | 6 +- Examples/UniswapV2Pair/MintFeeRoutines.lean | 16 +- .../UniswapV2Pair/MintFeeRoutinesCore.lean | 7 +- .../UniswapV2Pair/MintFeeRuntimeFactory.lean | 2 +- .../UniswapV2Pair/MintFeeRuntimeSqrt.lean | 2 +- Examples/UniswapV2Pair/MintFeeSqrtSmall.lean | 2 +- Examples/UniswapV2Pair/MintInitialCases.lean | 2 +- .../MintInitialFactoryCases.lean | 2 +- .../MintInitialFactoryOverflowCases.lean | 2 +- .../MintInitialFactoryReturnCases.lean | 2 +- .../MintInitialFactoryRootCases.lean | 2 +- ...nitialFactorySecondMintBalanceReverts.lean | 2 +- .../MintInitialFactorySecondMintReverts.lean | 2 +- .../MintInitialFactoryZeroCases.lean | 2 +- .../MintInitialMinimumMintReverts.lean | 2 +- .../MintInitialProductOverflow.lean | 2 +- .../MintInitialSecondMintReverts.lean | 2 +- .../UniswapV2Pair/MintInitialSqrtBridge.lean | 2 +- .../UniswapV2Pair/MintInitialZeroCases.lean | 2 +- .../MintInternalMintReverts.lean | 2 +- .../MintInternalMintRuntime.lean | 2 +- .../UniswapV2Pair/MintLiquidityZeroCases.lean | 2 +- .../MintLiquidityZeroFactoryCases.lean | 2 +- .../MintLiquidityZeroRuntime.lean | 2 +- .../UniswapV2Pair/MintProportionalFinish.lean | 2 +- .../MintProportionalProductOverflow.lean | 2 +- ...intProportionalSecondMintFactoryCases.lean | 2 +- ...lSecondMintFactoryKLastNonzeroReverts.lean | 2 +- ...tProportionalSecondMintFactoryReverts.lean | 2 +- .../MintProportionalSecondMintReverts.lean | 2 +- .../UniswapV2Pair/MintRuntimeAfterFee.lean | 2 +- .../UniswapV2Pair/MintRuntimeBalance.lean | 2 +- .../UniswapV2Pair/MintRuntimeFinalize.lean | 2 +- Examples/UniswapV2Pair/MintSourceCases.lean | 2 +- .../UniswapV2Pair/MintSourcePrefixes.lean | 2 +- Examples/UniswapV2Pair/MintSourceReturns.lean | 2 +- Examples/UniswapV2Pair/MutatorDispatch.lean | 2 +- Examples/UniswapV2Pair/Name.lean | 3 +- Examples/UniswapV2Pair/Nonces.lean | 3 +- Examples/UniswapV2Pair/Permit.lean | 3 +- Examples/UniswapV2Pair/PermitDecode.lean | 2 +- Examples/UniswapV2Pair/PermitRuntime.lean | 3 +- Examples/UniswapV2Pair/PermitTypehash.lean | 3 +- .../UniswapV2Pair/Price0CumulativeLast.lean | 3 +- .../UniswapV2Pair/Price1CumulativeLast.lean | 3 +- Examples/UniswapV2Pair/SafeTransfer.lean | 2 +- .../UniswapV2Pair/SafeTransferRuntime.lean | 2 +- Examples/UniswapV2Pair/Skim.lean | 2 +- Examples/UniswapV2Pair/SkimCommon.lean | 3 +- Examples/UniswapV2Pair/SkimRuntime.lean | 2 +- .../SkimSafeTransferCalldata.lean | 2 +- .../SkimSafeTransferDynamicRuntime.lean | 2 +- .../UniswapV2Pair/SkimSafeTransferReturn.lean | 2 +- .../SkimSafeTransferRuntime.lean | 2 +- ...ondSafeTransferDynamicCalldataRuntime.lean | 2 +- ...afeTransferDynamicOffsetReturnRuntime.lean | 2 +- ...econdSafeTransferDynamicOffsetRuntime.lean | 2 +- .../SkimSecondSafeTransferDynamicRuntime.lean | 2 +- .../SkimSecondSafeTransferRuntime.lean | 2 +- Examples/UniswapV2Pair/SkimSource.lean | 2 +- Examples/UniswapV2Pair/StringReturn.lean | 2 +- Examples/UniswapV2Pair/Swap.lean | 3 +- Examples/UniswapV2Pair/Symbol.lean | 3 +- Examples/UniswapV2Pair/Sync.lean | 3 +- Examples/UniswapV2Pair/SyncBody.lean | 2 +- Examples/UniswapV2Pair/SyncCumulative.lean | 2 +- Examples/UniswapV2Pair/SyncRuntime.lean | 2 +- Examples/UniswapV2Pair/Token0.lean | 3 +- Examples/UniswapV2Pair/Token1.lean | 3 +- Examples/UniswapV2Pair/TotalSupply.lean | 3 +- Examples/UniswapV2Pair/Transfer.lean | 3 +- Examples/UniswapV2Pair/TransferFrom.lean | 3 +- .../UniswapV2Pair/TransferFromDecode.lean | 2 +- .../UniswapV2Pair/TransferFromFinite.lean | 2 +- .../UniswapV2Pair/TransferFromMasked.lean | 2 +- .../TransferFromMaskedFinite.lean | 2 +- .../UniswapV2Pair/TransferFromReverts.lean | 2 +- .../UniswapV2Pair/TransferFromSuccess.lean | 2 +- Examples/VyperERC20/Allowance.lean | 2 +- Examples/VyperERC20/Approve.lean | 2 +- Examples/VyperERC20/BalanceOf.lean | 3 +- Examples/VyperERC20/TotalSupply.lean | 3 +- Examples/VyperERC20/Transfer.lean | 3 +- .../TransferFromAllowancePhase.lean | 2 +- .../TransferFromAllowanceStoreFinish.lean | 2 +- .../TransferFromAllowanceStoreGuard.lean | 2 +- ...nsferFromAllowanceStoreInnerHashStore.lean | 2 +- ...ansferFromAllowanceStoreInnerKeyReady.lean | 2 +- ...ansferFromAllowanceStoreInnerKeyStore.lean | 2 +- .../TransferFromAllowanceStoreInnerLoad.lean | 2 +- ...TransferFromAllowanceStoreOuterFinish.lean | 2 +- ...nsferFromAllowanceStoreOuterHashStore.lean | 2 +- ...ansferFromAllowanceStoreOuterKeyReady.lean | 2 +- ...ansferFromAllowanceStoreOuterKeyStore.lean | 2 +- .../TransferFromAllowanceStoreOuterPhase.lean | 2 +- ...TransferFromAllowanceStoreOuterPrefix.lean | 2 +- .../TransferFromAllowanceStorePrep.lean | 2 +- .../TransferFromBalanceLoadPhase.lean | 2 +- Examples/VyperERC20/TransferFromBase.lean | 2 +- Examples/VyperERC20/TransferFromRuntime.lean | 2 +- ...nsferFromStoresAfterFromLoadHashStore.lean | 2 +- ...ansferFromStoresAfterFromLoadKeyReady.lean | 2 +- ...ansferFromStoresAfterFromLoadKeyStore.lean | 2 +- .../TransferFromStoresAfterFromLoadSetup.lean | 2 +- .../TransferFromStoresAfterFromLoadSlot.lean | 2 +- .../TransferFromStoresAfterFromStore.lean | 2 +- .../TransferFromStoresBeforeFromStore.lean | 2 +- ...TransferFromStoresBeforeFromStoreCore.lean | 2 +- .../VyperERC20/TransferFromStoresFrom.lean | 2 +- .../VyperERC20/TransferFromStoresLog.lean | 2 +- Examples/VyperERC20/TransferFromStoresTo.lean | 2 +- LICENSE | 2 +- Reasoning/ABI.lean | 76 - Reasoning/ExternalCall.lean | 176 -- Reasoning/Memory.lean | 27 - Reasoning/Reach.lean | 5 + Reasoning/Refinement.lean | 1181 ------------- Reasoning/SolmBody.lean | 125 +- Reasoning/Storage.lean | 41 - Reasoning/Theory.lean | 45 - 987 files changed, 1616 insertions(+), 5051 deletions(-) delete mode 100644 Examples/CallerCoupled/BodySuccess.lean rename Examples/ERC20/{SpecSugar.lean => SpecSyntax.lean} (93%) delete mode 100644 Examples/PowCoupled/BodySuccess.lean delete mode 100644 Reasoning/Refinement.lean diff --git a/Benchmarks/CompoundIII/CometRewards/Claim.lean b/Benchmarks/CompoundIII/CometRewards/Claim.lean index 11496f0a..1e635e0a 100644 --- a/Benchmarks/CompoundIII/CometRewards/Claim.lean +++ b/Benchmarks/CompoundIII/CometRewards/Claim.lean @@ -2,7 +2,7 @@ import Benchmarks.CompoundIII.CometRewards.Common import Benchmarks.CompoundIII.CometRewards.GetRewardOwed import Benchmarks.CompoundIII.CometRewards.WithdrawToken -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/CompoundIII/CometRewards/ClaimTo.lean b/Benchmarks/CompoundIII/CometRewards/ClaimTo.lean index 1eeb9e3f..d7ce375f 100644 --- a/Benchmarks/CompoundIII/CometRewards/ClaimTo.lean +++ b/Benchmarks/CompoundIII/CometRewards/ClaimTo.lean @@ -1,6 +1,6 @@ import Benchmarks.CompoundIII.CometRewards.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/Common.lean b/Benchmarks/CompoundIII/CometRewards/Common.lean index 364a616c..d33c0d96 100644 --- a/Benchmarks/CompoundIII/CometRewards/Common.lean +++ b/Benchmarks/CompoundIII/CometRewards/Common.lean @@ -4,7 +4,6 @@ import Reasoning.ABI import Reasoning.Dispatch import Reasoning.Memory import Reasoning.Reach -import Reasoning.Refinement import Reasoning.Solc import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -17,7 +16,7 @@ the via-IR dispatcher. The prefix is not the standard `solcDispatchReachBody` p `cometRewardsReach...` lemmas are local proof obligations rather than uses of the generic driver. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/CompoundIII/CometRewards/Constructor.lean b/Benchmarks/CompoundIII/CometRewards/Constructor.lean index efb2740a..a0f6015e 100644 --- a/Benchmarks/CompoundIII/CometRewards/Constructor.lean +++ b/Benchmarks/CompoundIII/CometRewards/Constructor.lean @@ -2,7 +2,7 @@ import Benchmarks.CompoundIII.CometRewards.Common import Reasoning.Initcode import Solm.Equiv -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/CompoundIII/CometRewards/Correct.lean b/Benchmarks/CompoundIII/CometRewards/Correct.lean index 79dec9da..4f415163 100644 --- a/Benchmarks/CompoundIII/CometRewards/Correct.lean +++ b/Benchmarks/CompoundIII/CometRewards/Correct.lean @@ -19,7 +19,7 @@ This file assembles the CometRewards runtime dispatcher. Function-body correctn live in their own files; shared via-IR dispatcher reach obligations live in `Common.lean`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/GetRewardOwed.lean b/Benchmarks/CompoundIII/CometRewards/GetRewardOwed.lean index 4ba4a965..bf0c238c 100644 --- a/Benchmarks/CompoundIII/CometRewards/GetRewardOwed.lean +++ b/Benchmarks/CompoundIII/CometRewards/GetRewardOwed.lean @@ -3,7 +3,7 @@ import Benchmarks.CompoundIII.CometRewards.RewardsClaimed import Benchmarks.CompoundIII.CometRewards.SetRewardConfigWithMultiplier import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/CompoundIII/CometRewards/Governor.lean b/Benchmarks/CompoundIII/CometRewards/Governor.lean index b28489dd..893e248a 100644 --- a/Benchmarks/CompoundIII/CometRewards/Governor.lean +++ b/Benchmarks/CompoundIII/CometRewards/Governor.lean @@ -1,6 +1,6 @@ import Benchmarks.CompoundIII.CometRewards.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/CompoundIII/CometRewards/RewardConfig.lean b/Benchmarks/CompoundIII/CometRewards/RewardConfig.lean index 6d8c9d96..077274a3 100644 --- a/Benchmarks/CompoundIII/CometRewards/RewardConfig.lean +++ b/Benchmarks/CompoundIII/CometRewards/RewardConfig.lean @@ -1,7 +1,7 @@ import Benchmarks.CompoundIII.CometRewards.Common import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 10000000 diff --git a/Benchmarks/CompoundIII/CometRewards/RewardsClaimed.lean b/Benchmarks/CompoundIII/CometRewards/RewardsClaimed.lean index 4aff54cb..bd55a1b5 100644 --- a/Benchmarks/CompoundIII/CometRewards/RewardsClaimed.lean +++ b/Benchmarks/CompoundIII/CometRewards/RewardsClaimed.lean @@ -1,6 +1,6 @@ import Benchmarks.CompoundIII.CometRewards.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/CompoundIII/CometRewards/Scratch.lean b/Benchmarks/CompoundIII/CometRewards/Scratch.lean index 502fec81..8b2b377c 100644 --- a/Benchmarks/CompoundIII/CometRewards/Scratch.lean +++ b/Benchmarks/CompoundIII/CometRewards/Scratch.lean @@ -1,6 +1,6 @@ import Benchmarks.CompoundIII.CometRewards.Claim -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/CompoundIII/CometRewards/SetRewardConfig.lean b/Benchmarks/CompoundIII/CometRewards/SetRewardConfig.lean index 6da4d74a..c1198457 100644 --- a/Benchmarks/CompoundIII/CometRewards/SetRewardConfig.lean +++ b/Benchmarks/CompoundIII/CometRewards/SetRewardConfig.lean @@ -3,7 +3,7 @@ import Benchmarks.CompoundIII.CometRewards.SetRewardConfigWithMultiplier import Benchmarks.CompoundIII.CometRewards.TransferGovernor import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/CompoundIII/CometRewards/SetRewardConfigWithMultiplier.lean b/Benchmarks/CompoundIII/CometRewards/SetRewardConfigWithMultiplier.lean index 36724e15..f0c206bf 100644 --- a/Benchmarks/CompoundIII/CometRewards/SetRewardConfigWithMultiplier.lean +++ b/Benchmarks/CompoundIII/CometRewards/SetRewardConfigWithMultiplier.lean @@ -3,7 +3,7 @@ import Benchmarks.CompoundIII.CometRewards.TransferGovernor import Reasoning.ExternalCall import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/CompoundIII/CometRewards/SetRewardsClaimed.lean b/Benchmarks/CompoundIII/CometRewards/SetRewardsClaimed.lean index a5314139..807694cb 100644 --- a/Benchmarks/CompoundIII/CometRewards/SetRewardsClaimed.lean +++ b/Benchmarks/CompoundIII/CometRewards/SetRewardsClaimed.lean @@ -1,6 +1,6 @@ import Benchmarks.CompoundIII.CometRewards.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/TransferGovernor.lean b/Benchmarks/CompoundIII/CometRewards/TransferGovernor.lean index 4e25bb44..b789d87f 100644 --- a/Benchmarks/CompoundIII/CometRewards/TransferGovernor.lean +++ b/Benchmarks/CompoundIII/CometRewards/TransferGovernor.lean @@ -1,7 +1,7 @@ import Benchmarks.CompoundIII.CometRewards.Common import Benchmarks.CompoundIII.CometRewards.Governor -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/CompoundIII/CometRewards/WithdrawToken.lean b/Benchmarks/CompoundIII/CometRewards/WithdrawToken.lean index 87311580..e905e8a8 100644 --- a/Benchmarks/CompoundIII/CometRewards/WithdrawToken.lean +++ b/Benchmarks/CompoundIII/CometRewards/WithdrawToken.lean @@ -3,7 +3,7 @@ import Benchmarks.CompoundIII.CometRewards.Governor import Benchmarks.CompoundIII.CometRewards.TransferGovernor import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/Arithmetic.lean b/Benchmarks/Dss/Cat/Arithmetic.lean index 320a42fe..6731c650 100644 --- a/Benchmarks/Dss/Cat/Arithmetic.lean +++ b/Benchmarks/Dss/Cat/Arithmetic.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/Bite.lean b/Benchmarks/Dss/Cat/Bite.lean index 3085093e..d4f829be 100644 --- a/Benchmarks/Dss/Cat/Bite.lean +++ b/Benchmarks/Dss/Cat/Bite.lean @@ -3,7 +3,7 @@ import Benchmarks.Dss.Cat.BiteEVM import Benchmarks.Dss.Cat.BiteWalk import Solm.Equiv -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/BiteBody.lean b/Benchmarks/Dss/Cat/BiteBody.lean index 1edb9771..37323445 100644 --- a/Benchmarks/Dss/Cat/BiteBody.lean +++ b/Benchmarks/Dss/Cat/BiteBody.lean @@ -11,7 +11,7 @@ import Benchmarks.Dss.Cat.BiteEVM import Benchmarks.Dss.Cat.FileAddress import Benchmarks.Dss.Cat.BiteBodyAw -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteBodyAw.lean b/Benchmarks/Dss/Cat/BiteBodyAw.lean index 2b95ed09..f34cef27 100644 --- a/Benchmarks/Dss/Cat/BiteBodyAw.lean +++ b/Benchmarks/Dss/Cat/BiteBodyAw.lean @@ -10,7 +10,7 @@ import Benchmarks.Dss.Cat.BiteGuardReach import Benchmarks.Dss.Cat.BiteEVM import Benchmarks.Dss.Cat.FileAddress -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Benchmarks/Dss/Cat/BiteBodyKick.lean b/Benchmarks/Dss/Cat/BiteBodyKick.lean index 0afaea9f..d3502e0c 100644 --- a/Benchmarks/Dss/Cat/BiteBodyKick.lean +++ b/Benchmarks/Dss/Cat/BiteBodyKick.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.BiteBodyReach -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Benchmarks/Dss/Cat/BiteBodyMem.lean b/Benchmarks/Dss/Cat/BiteBodyMem.lean index 4bd0b2c1..c9857c4f 100644 --- a/Benchmarks/Dss/Cat/BiteBodyMem.lean +++ b/Benchmarks/Dss/Cat/BiteBodyMem.lean @@ -5,7 +5,7 @@ import Benchmarks.Dss.Cat.BiteCallKick import Benchmarks.Dss.Cat.BiteConnectMem import Benchmarks.Dss.Cat.BiteConnectDecode -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteBodyReach.lean b/Benchmarks/Dss/Cat/BiteBodyReach.lean index cd47dab7..10f35538 100644 --- a/Benchmarks/Dss/Cat/BiteBodyReach.lean +++ b/Benchmarks/Dss/Cat/BiteBodyReach.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.BiteConnect import Benchmarks.Dss.Cat.BiteBodyMem -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteCallDiverge.lean b/Benchmarks/Dss/Cat/BiteCallDiverge.lean index 85a6c630..e434d393 100644 --- a/Benchmarks/Dss/Cat/BiteCallDiverge.lean +++ b/Benchmarks/Dss/Cat/BiteCallDiverge.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.BiteRevertLeaves -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteCallFess.lean b/Benchmarks/Dss/Cat/BiteCallFess.lean index 66dd3395..c5209f83 100644 --- a/Benchmarks/Dss/Cat/BiteCallFess.lean +++ b/Benchmarks/Dss/Cat/BiteCallFess.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteCallGrab.lean b/Benchmarks/Dss/Cat/BiteCallGrab.lean index 85bc093a..7ec2e0d5 100644 --- a/Benchmarks/Dss/Cat/BiteCallGrab.lean +++ b/Benchmarks/Dss/Cat/BiteCallGrab.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/BiteCallIlks.lean b/Benchmarks/Dss/Cat/BiteCallIlks.lean index dc16b67a..c7449c0e 100644 --- a/Benchmarks/Dss/Cat/BiteCallIlks.lean +++ b/Benchmarks/Dss/Cat/BiteCallIlks.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/BiteCallKick.lean b/Benchmarks/Dss/Cat/BiteCallKick.lean index 22d251c1..32d7631b 100644 --- a/Benchmarks/Dss/Cat/BiteCallKick.lean +++ b/Benchmarks/Dss/Cat/BiteCallKick.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/BiteCallUrns.lean b/Benchmarks/Dss/Cat/BiteCallUrns.lean index b730a7e5..86cd73e9 100644 --- a/Benchmarks/Dss/Cat/BiteCallUrns.lean +++ b/Benchmarks/Dss/Cat/BiteCallUrns.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.Common import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/BiteConnect.lean b/Benchmarks/Dss/Cat/BiteConnect.lean index 163b37e7..29022c92 100644 --- a/Benchmarks/Dss/Cat/BiteConnect.lean +++ b/Benchmarks/Dss/Cat/BiteConnect.lean @@ -3,7 +3,7 @@ import Benchmarks.Dss.Cat.BiteCallGrab import Benchmarks.Dss.Cat.BiteCallFess import Benchmarks.Dss.Cat.BiteConnectGrab -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteConnectDecode.lean b/Benchmarks/Dss/Cat/BiteConnectDecode.lean index fa5ace00..5e5074a0 100644 --- a/Benchmarks/Dss/Cat/BiteConnectDecode.lean +++ b/Benchmarks/Dss/Cat/BiteConnectDecode.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.BiteTrace -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteConnectGrab.lean b/Benchmarks/Dss/Cat/BiteConnectGrab.lean index 1be35f92..3d25acf5 100644 --- a/Benchmarks/Dss/Cat/BiteConnectGrab.lean +++ b/Benchmarks/Dss/Cat/BiteConnectGrab.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.BiteTrace import Benchmarks.Dss.Cat.BiteCallGrab -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteConnectMem.lean b/Benchmarks/Dss/Cat/BiteConnectMem.lean index f2550706..338b1a35 100644 --- a/Benchmarks/Dss/Cat/BiteConnectMem.lean +++ b/Benchmarks/Dss/Cat/BiteConnectMem.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.BiteTrace -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteEVM.lean b/Benchmarks/Dss/Cat/BiteEVM.lean index 7899fc1b..e5914ab7 100644 --- a/Benchmarks/Dss/Cat/BiteEVM.lean +++ b/Benchmarks/Dss/Cat/BiteEVM.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.Common import Solm.Equiv -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/BiteGuardReach.lean b/Benchmarks/Dss/Cat/BiteGuardReach.lean index c2a21ab0..f0d453e2 100644 --- a/Benchmarks/Dss/Cat/BiteGuardReach.lean +++ b/Benchmarks/Dss/Cat/BiteGuardReach.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.BiteConnect -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteRevertBranch.lean b/Benchmarks/Dss/Cat/BiteRevertBranch.lean index c7df0f1c..2c6a23fd 100644 --- a/Benchmarks/Dss/Cat/BiteRevertBranch.lean +++ b/Benchmarks/Dss/Cat/BiteRevertBranch.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.BiteBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteRevertLeaves.lean b/Benchmarks/Dss/Cat/BiteRevertLeaves.lean index cadbe2e3..bb31e941 100644 --- a/Benchmarks/Dss/Cat/BiteRevertLeaves.lean +++ b/Benchmarks/Dss/Cat/BiteRevertLeaves.lean @@ -3,7 +3,7 @@ import Benchmarks.Dss.Cat.BiteRevertPrim import Benchmarks.Dss.Cat.BiteSource import Benchmarks.Dss.Cat.BiteTrace -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteRevertPrim.lean b/Benchmarks/Dss/Cat/BiteRevertPrim.lean index 87bc8201..dfcd6178 100644 --- a/Benchmarks/Dss/Cat/BiteRevertPrim.lean +++ b/Benchmarks/Dss/Cat/BiteRevertPrim.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.BiteTrace -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteSource.lean b/Benchmarks/Dss/Cat/BiteSource.lean index b2229c83..199b4a8f 100644 --- a/Benchmarks/Dss/Cat/BiteSource.lean +++ b/Benchmarks/Dss/Cat/BiteSource.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Cat.Arithmetic import Benchmarks.Dss.Cat.Common import Benchmarks.Dss.Cat.BiteEVM -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Benchmarks/Dss/Cat/BiteSuccessBranch.lean b/Benchmarks/Dss/Cat/BiteSuccessBranch.lean index d81e9c12..e0656ec1 100644 --- a/Benchmarks/Dss/Cat/BiteSuccessBranch.lean +++ b/Benchmarks/Dss/Cat/BiteSuccessBranch.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.BiteConnect -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteTrace.lean b/Benchmarks/Dss/Cat/BiteTrace.lean index 5e27409b..5a890bb4 100644 --- a/Benchmarks/Dss/Cat/BiteTrace.lean +++ b/Benchmarks/Dss/Cat/BiteTrace.lean @@ -5,7 +5,7 @@ import Benchmarks.Dss.Cat.BiteSource import Reasoning.ExternalCall import Benchmarks.Dss.Cat.BiteCallKick -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/BiteWalk.lean b/Benchmarks/Dss/Cat/BiteWalk.lean index 03c2b1a9..95654533 100644 --- a/Benchmarks/Dss/Cat/BiteWalk.lean +++ b/Benchmarks/Dss/Cat/BiteWalk.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.BiteBody import Benchmarks.Dss.Cat.BiteRevertBranch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Cat/Box.lean b/Benchmarks/Dss/Cat/Box.lean index 6b4a511b..7a6ee68a 100644 --- a/Benchmarks/Dss/Cat/Box.lean +++ b/Benchmarks/Dss/Cat/Box.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.Common import Solm.Equiv -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/Cage.lean b/Benchmarks/Dss/Cat/Cage.lean index da7d8c59..d7acdda2 100644 --- a/Benchmarks/Dss/Cat/Cage.lean +++ b/Benchmarks/Dss/Cat/Cage.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cat/Claw.lean b/Benchmarks/Dss/Cat/Claw.lean index dffa3bdf..5e90e926 100644 --- a/Benchmarks/Dss/Cat/Claw.lean +++ b/Benchmarks/Dss/Cat/Claw.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.Storage import Benchmarks.Dss.Cat.Arithmetic -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cat/Common.lean b/Benchmarks/Dss/Cat/Common.lean index 68ea76e6..0e088bf5 100644 --- a/Benchmarks/Dss/Cat/Common.lean +++ b/Benchmarks/Dss/Cat/Common.lean @@ -3,7 +3,6 @@ import Reasoning.ABI import Reasoning.Dispatch import Reasoning.ExternalCall import Reasoning.Memory -import Reasoning.Refinement import Reasoning.Reach import Reasoning.Solc import Reasoning.Storage @@ -21,7 +20,7 @@ to the other DSS contracts: a root split (pc 32), a high split (pc 43) and a low under which sit four arm groups of four selectors each. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/Correct.lean b/Benchmarks/Dss/Cat/Correct.lean index 620af3f5..d20aa585 100644 --- a/Benchmarks/Dss/Cat/Correct.lean +++ b/Benchmarks/Dss/Cat/Correct.lean @@ -15,7 +15,6 @@ import Benchmarks.Dss.Cat.Rely import Benchmarks.Dss.Cat.Vat import Benchmarks.Dss.Cat.Vow import Benchmarks.Dss.Cat.Wards -import Reasoning.Refinement import Solm.Equiv /-! @@ -26,7 +25,7 @@ refinement lemma, and handles the shared revert paths (non-payable guard, short selector). The whole-contract wrapper combines the constructor and runtime targets. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/Deny.lean b/Benchmarks/Dss/Cat/Deny.lean index 5c966620..c4327301 100644 --- a/Benchmarks/Dss/Cat/Deny.lean +++ b/Benchmarks/Dss/Cat/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cat/FileAddress.lean b/Benchmarks/Dss/Cat/FileAddress.lean index 168f2a2f..f904c540 100644 --- a/Benchmarks/Dss/Cat/FileAddress.lean +++ b/Benchmarks/Dss/Cat/FileAddress.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cat/FileIlkFlip.lean b/Benchmarks/Dss/Cat/FileIlkFlip.lean index d0c99884..0e8ec3a9 100644 --- a/Benchmarks/Dss/Cat/FileIlkFlip.lean +++ b/Benchmarks/Dss/Cat/FileIlkFlip.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Cat.FileIlkFlipCalls2 import Benchmarks.Dss.Cat.BiteSource import Solm.Equiv -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 400000 diff --git a/Benchmarks/Dss/Cat/FileIlkFlipCalls.lean b/Benchmarks/Dss/Cat/FileIlkFlipCalls.lean index 307a4a23..b8dfcfbb 100644 --- a/Benchmarks/Dss/Cat/FileIlkFlipCalls.lean +++ b/Benchmarks/Dss/Cat/FileIlkFlipCalls.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.Storage import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean b/Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean index c1678d16..422d9db1 100644 --- a/Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean +++ b/Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.FileIlkFlipCalls import Benchmarks.Dss.Cat.FileAddress -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cat/FileIlkUint.lean b/Benchmarks/Dss/Cat/FileIlkUint.lean index 34fb6411..780195b9 100644 --- a/Benchmarks/Dss/Cat/FileIlkUint.lean +++ b/Benchmarks/Dss/Cat/FileIlkUint.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cat/FileUint.lean b/Benchmarks/Dss/Cat/FileUint.lean index b2c898fc..832527ba 100644 --- a/Benchmarks/Dss/Cat/FileUint.lean +++ b/Benchmarks/Dss/Cat/FileUint.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cat/Ilks.lean b/Benchmarks/Dss/Cat/Ilks.lean index a4c10a37..b75fdfd7 100644 --- a/Benchmarks/Dss/Cat/Ilks.lean +++ b/Benchmarks/Dss/Cat/Ilks.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.Common import Solm.Equiv -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/Litter.lean b/Benchmarks/Dss/Cat/Litter.lean index 3bf0c425..febcf147 100644 --- a/Benchmarks/Dss/Cat/Litter.lean +++ b/Benchmarks/Dss/Cat/Litter.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.Common import Solm.Equiv -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/Live.lean b/Benchmarks/Dss/Cat/Live.lean index 543c2906..e3f264f9 100644 --- a/Benchmarks/Dss/Cat/Live.lean +++ b/Benchmarks/Dss/Cat/Live.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.Common import Solm.Equiv -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/Rely.lean b/Benchmarks/Dss/Cat/Rely.lean index 2d02c123..7e68a186 100644 --- a/Benchmarks/Dss/Cat/Rely.lean +++ b/Benchmarks/Dss/Cat/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cat.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cat/Storage.lean b/Benchmarks/Dss/Cat/Storage.lean index 816b346d..363f6b20 100644 --- a/Benchmarks/Dss/Cat/Storage.lean +++ b/Benchmarks/Dss/Cat/Storage.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.Common import Solm.Equiv -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cat/Vat.lean b/Benchmarks/Dss/Cat/Vat.lean index b430d68e..1f0acf14 100644 --- a/Benchmarks/Dss/Cat/Vat.lean +++ b/Benchmarks/Dss/Cat/Vat.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.Common import Solm.Equiv -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/Vow.lean b/Benchmarks/Dss/Cat/Vow.lean index f8c70cdb..db51a071 100644 --- a/Benchmarks/Dss/Cat/Vow.lean +++ b/Benchmarks/Dss/Cat/Vow.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.Common import Solm.Equiv -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cat/Wards.lean b/Benchmarks/Dss/Cat/Wards.lean index 9c0148de..4307f735 100644 --- a/Benchmarks/Dss/Cat/Wards.lean +++ b/Benchmarks/Dss/Cat/Wards.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cat.Common import Solm.Equiv -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Clipper/Active.lean b/Benchmarks/Dss/Clipper/Active.lean index b8a7d9b3..f943eff2 100644 --- a/Benchmarks/Dss/Clipper/Active.lean +++ b/Benchmarks/Dss/Clipper/Active.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Clipper.UintEntry import Ethereum.Theory.OpcodeLemmas -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Buf.lean b/Benchmarks/Dss/Clipper/Buf.lean index 14deceea..e3c14a12 100644 --- a/Benchmarks/Dss/Clipper/Buf.lean +++ b/Benchmarks/Dss/Clipper/Buf.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Calc.lean b/Benchmarks/Dss/Clipper/Calc.lean index 813e8e53..bce42d34 100644 --- a/Benchmarks/Dss/Clipper/Calc.lean +++ b/Benchmarks/Dss/Clipper/Calc.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Chip.lean b/Benchmarks/Dss/Clipper/Chip.lean index d2e9471d..4a222b40 100644 --- a/Benchmarks/Dss/Clipper/Chip.lean +++ b/Benchmarks/Dss/Clipper/Chip.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Chost.lean b/Benchmarks/Dss/Clipper/Chost.lean index f71177e2..44c74c60 100644 --- a/Benchmarks/Dss/Clipper/Chost.lean +++ b/Benchmarks/Dss/Clipper/Chost.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Common.lean b/Benchmarks/Dss/Clipper/Common.lean index f4f9602e..c724380c 100644 --- a/Benchmarks/Dss/Clipper/Common.lean +++ b/Benchmarks/Dss/Clipper/Common.lean @@ -4,7 +4,6 @@ import Reasoning.Dispatch import Reasoning.Initcode import Reasoning.Memory import Reasoning.Reach -import Reasoning.Refinement import Reasoning.Solc import Reasoning.SolmBody import Reasoning.Storage @@ -16,7 +15,7 @@ import Mathlib.Tactic.IntervalCases Contract-wide selector notation and constants for the optimized Clipper runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Clipper/Correct.lean b/Benchmarks/Dss/Clipper/Correct.lean index 11faedeb..7f1117e9 100644 --- a/Benchmarks/Dss/Clipper/Correct.lean +++ b/Benchmarks/Dss/Clipper/Correct.lean @@ -39,7 +39,7 @@ are present. The runtime-equivalence proof is intentionally left as the benchmar also exposes the whole-contract wrapper that combines the constructor and runtime targets. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Clipper/Count.lean b/Benchmarks/Dss/Clipper/Count.lean index 1a2814c1..162ace20 100644 --- a/Benchmarks/Dss/Clipper/Count.lean +++ b/Benchmarks/Dss/Clipper/Count.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Cusp.lean b/Benchmarks/Dss/Clipper/Cusp.lean index 39e14454..bc392c14 100644 --- a/Benchmarks/Dss/Clipper/Cusp.lean +++ b/Benchmarks/Dss/Clipper/Cusp.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Deny.lean b/Benchmarks/Dss/Clipper/Deny.lean index 2779a5f8..d13bd758 100644 --- a/Benchmarks/Dss/Clipper/Deny.lean +++ b/Benchmarks/Dss/Clipper/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Clipper/Dispatch.lean b/Benchmarks/Dss/Clipper/Dispatch.lean index 939fd982..467d5dd8 100644 --- a/Benchmarks/Dss/Clipper/Dispatch.lean +++ b/Benchmarks/Dss/Clipper/Dispatch.lean @@ -6,7 +6,7 @@ import Benchmarks.Dss.Clipper.Trusted Shared selector-disjointness facts used by the top-level runtime dispatcher scaffold. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Clipper/Dog.lean b/Benchmarks/Dss/Clipper/Dog.lean index 6200fab3..1b2ad6cd 100644 --- a/Benchmarks/Dss/Clipper/Dog.lean +++ b/Benchmarks/Dss/Clipper/Dog.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Fallback.lean b/Benchmarks/Dss/Clipper/Fallback.lean index 88189e3d..e654fe06 100644 --- a/Benchmarks/Dss/Clipper/Fallback.lean +++ b/Benchmarks/Dss/Clipper/Fallback.lean @@ -4,7 +4,7 @@ import Benchmarks.Dss.Clipper.Dispatch # MakerDAO/Sky DSS Clipper fallback and global-revert scaffolds -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/FileAddress.lean b/Benchmarks/Dss/Clipper/FileAddress.lean index 0173bc6e..70f76aa5 100644 --- a/Benchmarks/Dss/Clipper/FileAddress.lean +++ b/Benchmarks/Dss/Clipper/FileAddress.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/FileUint.lean b/Benchmarks/Dss/Clipper/FileUint.lean index fcb292d1..91c4e768 100644 --- a/Benchmarks/Dss/Clipper/FileUint.lean +++ b/Benchmarks/Dss/Clipper/FileUint.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/GetStatus.lean b/Benchmarks/Dss/Clipper/GetStatus.lean index c895455d..382f8270 100644 --- a/Benchmarks/Dss/Clipper/GetStatus.lean +++ b/Benchmarks/Dss/Clipper/GetStatus.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Ilk.lean b/Benchmarks/Dss/Clipper/Ilk.lean index 20813bd6..70898788 100644 --- a/Benchmarks/Dss/Clipper/Ilk.lean +++ b/Benchmarks/Dss/Clipper/Ilk.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Kick.lean b/Benchmarks/Dss/Clipper/Kick.lean index 130e7b68..9baf6037 100644 --- a/Benchmarks/Dss/Clipper/Kick.lean +++ b/Benchmarks/Dss/Clipper/Kick.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Kicks.lean b/Benchmarks/Dss/Clipper/Kicks.lean index e501be17..b5abeade 100644 --- a/Benchmarks/Dss/Clipper/Kicks.lean +++ b/Benchmarks/Dss/Clipper/Kicks.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/List.lean b/Benchmarks/Dss/Clipper/List.lean index 3cd96398..f043a743 100644 --- a/Benchmarks/Dss/Clipper/List.lean +++ b/Benchmarks/Dss/Clipper/List.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Clipper.Common import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Redo.lean b/Benchmarks/Dss/Clipper/Redo.lean index 421af8ba..82f2bf3c 100644 --- a/Benchmarks/Dss/Clipper/Redo.lean +++ b/Benchmarks/Dss/Clipper/Redo.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Rely.lean b/Benchmarks/Dss/Clipper/Rely.lean index 4da98b1d..6a61ae35 100644 --- a/Benchmarks/Dss/Clipper/Rely.lean +++ b/Benchmarks/Dss/Clipper/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Clipper/Sales.lean b/Benchmarks/Dss/Clipper/Sales.lean index de995fec..afa14ffc 100644 --- a/Benchmarks/Dss/Clipper/Sales.lean +++ b/Benchmarks/Dss/Clipper/Sales.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Clipper.UintEntry import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Spotter.lean b/Benchmarks/Dss/Clipper/Spotter.lean index 980526dc..a8e74a13 100644 --- a/Benchmarks/Dss/Clipper/Spotter.lean +++ b/Benchmarks/Dss/Clipper/Spotter.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Stopped.lean b/Benchmarks/Dss/Clipper/Stopped.lean index 97662a22..f89f6332 100644 --- a/Benchmarks/Dss/Clipper/Stopped.lean +++ b/Benchmarks/Dss/Clipper/Stopped.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Tail.lean b/Benchmarks/Dss/Clipper/Tail.lean index bd844b92..bcee49eb 100644 --- a/Benchmarks/Dss/Clipper/Tail.lean +++ b/Benchmarks/Dss/Clipper/Tail.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Take.lean b/Benchmarks/Dss/Clipper/Take.lean index 5e582b7b..be156df2 100644 --- a/Benchmarks/Dss/Clipper/Take.lean +++ b/Benchmarks/Dss/Clipper/Take.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Tip.lean b/Benchmarks/Dss/Clipper/Tip.lean index a2b2a0af..ab426f3c 100644 --- a/Benchmarks/Dss/Clipper/Tip.lean +++ b/Benchmarks/Dss/Clipper/Tip.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/UintEntry.lean b/Benchmarks/Dss/Clipper/UintEntry.lean index 836afc1f..bfe9ec5d 100644 --- a/Benchmarks/Dss/Clipper/UintEntry.lean +++ b/Benchmarks/Dss/Clipper/UintEntry.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Upchost.lean b/Benchmarks/Dss/Clipper/Upchost.lean index 473dfcb1..85547d53 100644 --- a/Benchmarks/Dss/Clipper/Upchost.lean +++ b/Benchmarks/Dss/Clipper/Upchost.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Vat.lean b/Benchmarks/Dss/Clipper/Vat.lean index bd85177f..8387bd1c 100644 --- a/Benchmarks/Dss/Clipper/Vat.lean +++ b/Benchmarks/Dss/Clipper/Vat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Vow.lean b/Benchmarks/Dss/Clipper/Vow.lean index 14e0a9f7..c055a020 100644 --- a/Benchmarks/Dss/Clipper/Vow.lean +++ b/Benchmarks/Dss/Clipper/Vow.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Wards.lean b/Benchmarks/Dss/Clipper/Wards.lean index 37b11246..29d43af7 100644 --- a/Benchmarks/Dss/Clipper/Wards.lean +++ b/Benchmarks/Dss/Clipper/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Fallback -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Clipper/Yank.lean b/Benchmarks/Dss/Clipper/Yank.lean index 94a78c34..cbab7b58 100644 --- a/Benchmarks/Dss/Clipper/Yank.lean +++ b/Benchmarks/Dss/Clipper/Yank.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Clipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Clipper.Immutables namespace Benchmarks.Dss.Clipper diff --git a/Benchmarks/Dss/Cure/Amt.lean b/Benchmarks/Dss/Cure/Amt.lean index 53da7678..482cf680 100644 --- a/Benchmarks/Dss/Cure/Amt.lean +++ b/Benchmarks/Dss/Cure/Amt.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/Cage.lean b/Benchmarks/Dss/Cure/Cage.lean index 30761de7..6c5918f4 100644 --- a/Benchmarks/Dss/Cure/Cage.lean +++ b/Benchmarks/Dss/Cure/Cage.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cure/Common.lean b/Benchmarks/Dss/Cure/Common.lean index f79c5ede..f2b85d65 100644 --- a/Benchmarks/Dss/Cure/Common.lean +++ b/Benchmarks/Dss/Cure/Common.lean @@ -7,7 +7,6 @@ import Reasoning.Solc import Reasoning.Memory import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -18,7 +17,7 @@ Contract-wide selector notation and top-level revert/no-dispatch placeholders fo Cure runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cure/Correct.lean b/Benchmarks/Dss/Cure/Correct.lean index 014613c9..6efbe0a5 100644 --- a/Benchmarks/Dss/Cure/Correct.lean +++ b/Benchmarks/Dss/Cure/Correct.lean @@ -28,7 +28,7 @@ The runtime proof now follows the phase-1 shape: this file is a thin selector ro function has a separate `...BodyCore` proof obligation in its own file. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cure/Deny.lean b/Benchmarks/Dss/Cure/Deny.lean index 8451cd07..291a8386 100644 --- a/Benchmarks/Dss/Cure/Deny.lean +++ b/Benchmarks/Dss/Cure/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cure/Drop.lean b/Benchmarks/Dss/Cure/Drop.lean index 9cd75844..b3f7951a 100644 --- a/Benchmarks/Dss/Cure/Drop.lean +++ b/Benchmarks/Dss/Cure/Drop.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cure.DropSource import Benchmarks.Dss.Cure.Srcs -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/DropSource.lean b/Benchmarks/Dss/Cure/DropSource.lean index 4600a647..3dd08b7f 100644 --- a/Benchmarks/Dss/Cure/DropSource.lean +++ b/Benchmarks/Dss/Cure/DropSource.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cure.Rely import Benchmarks.Dss.Cure.Trusted -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/File.lean b/Benchmarks/Dss/Cure/File.lean index ba488571..43a41f30 100644 --- a/Benchmarks/Dss/Cure/File.lean +++ b/Benchmarks/Dss/Cure/File.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cure/LCount.lean b/Benchmarks/Dss/Cure/LCount.lean index d93b2a9c..5373a832 100644 --- a/Benchmarks/Dss/Cure/LCount.lean +++ b/Benchmarks/Dss/Cure/LCount.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/Lift.lean b/Benchmarks/Dss/Cure/Lift.lean index 46e5d86f..f987ce21 100644 --- a/Benchmarks/Dss/Cure/Lift.lean +++ b/Benchmarks/Dss/Cure/Lift.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cure/List.lean b/Benchmarks/Dss/Cure/List.lean index a927e7cc..65194c77 100644 --- a/Benchmarks/Dss/Cure/List.lean +++ b/Benchmarks/Dss/Cure/List.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.ListLoop -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/ListBase.lean b/Benchmarks/Dss/Cure/ListBase.lean index bec68a13..95226126 100644 --- a/Benchmarks/Dss/Cure/ListBase.lean +++ b/Benchmarks/Dss/Cure/ListBase.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/ListLoop.lean b/Benchmarks/Dss/Cure/ListLoop.lean index bfedf270..0da949a9 100644 --- a/Benchmarks/Dss/Cure/ListLoop.lean +++ b/Benchmarks/Dss/Cure/ListLoop.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.ListBase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/Live.lean b/Benchmarks/Dss/Cure/Live.lean index 4ae78d41..aeabd14d 100644 --- a/Benchmarks/Dss/Cure/Live.lean +++ b/Benchmarks/Dss/Cure/Live.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/Load.lean b/Benchmarks/Dss/Cure/Load.lean index 0e4f6f55..7ffefc7a 100644 --- a/Benchmarks/Dss/Cure/Load.lean +++ b/Benchmarks/Dss/Cure/Load.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.LoadTrace -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cure/LoadBase.lean b/Benchmarks/Dss/Cure/LoadBase.lean index 6d297907..5f635e7a 100644 --- a/Benchmarks/Dss/Cure/LoadBase.lean +++ b/Benchmarks/Dss/Cure/LoadBase.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Cure.Common import Benchmarks.Dss.Cure.Cage import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/LoadSource.lean b/Benchmarks/Dss/Cure/LoadSource.lean index 2276f5db..c3d1bbe4 100644 --- a/Benchmarks/Dss/Cure/LoadSource.lean +++ b/Benchmarks/Dss/Cure/LoadSource.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.LoadBase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -137,7 +137,7 @@ theorem cureLoadSourceBodyNoCodeRevert {cA gh bl σ σ₀ A I} {g : UInt256} .assign .storage lCountRef (incUnchecked (.storage lCountRef)) ] [] ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term hcall (by intro f e h; cases h) + exact.execBlock_append_term hcall (by intro f e h; cases h) have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -232,7 +232,7 @@ theorem cureLoadSourceBodyCallFailureRevert {cA gh bl σ σ₀ A I} {g : UInt256 .assign .storage lCountRef (incUnchecked (.storage lCountRef)) ] [] ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term hcallBlock (by intro f e h; cases h) + exact.execBlock_append_term hcallBlock (by intro f e h; cases h) have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -330,7 +330,7 @@ theorem cureLoadSourceBodyReturnDecodeRevert {cA gh bl σ σ₀ A I} {g : UInt25 .assign .storage lCountRef (incUnchecked (.storage lCountRef)) ] [] ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term hcallBlock (by intro f e h; cases h) + exact.execBlock_append_term hcallBlock (by intro f e h; cases h) have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -550,7 +550,7 @@ theorem cureLoadSourceBodySubRevert {cA gh bl σ σ₀ A I} {g : UInt256} .reverted := by refine ExecBlock.consNormal (ExecStmt.assign hnewVar hassignAmt) ?_ exact ExecBlock.consRevert hsubStmt - exact Reasoning.Refinement.execBlock_append hcallBlock hrest + exact.execBlock_append hcallBlock hrest have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -829,7 +829,7 @@ theorem cureLoadSourceBodyAddRevert {cA gh bl σ σ₀ A I} {g : UInt256} refine ExecBlock.consNormal (ExecStmt.assign hnewVar hassignAmt) ?_ refine ExecBlock.consNormal hsubStmt ?_ exact ExecBlock.consRevert haddStmt - exact Reasoning.Refinement.execBlock_append hcallBlock hrest + exact.execBlock_append hcallBlock hrest have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -1161,7 +1161,7 @@ theorem cureLoadSourceBodyOkLoadedNonzero {cA gh bl σ σ₀ A I} {g : UInt256} refine ExecBlock.consNormal haddStmt ?_ refine ExecBlock.consNormal (ExecStmt.assign hsayNewVar hassignSay) ?_ exact ExecBlock.consNormal (ExecStmt.iteFalse hcond ExecBlock.nil) ExecBlock.nil - exact Reasoning.Refinement.execBlock_append hcallBlock hrest + exact.execBlock_append hcallBlock hrest have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -1511,7 +1511,7 @@ theorem cureLoadSourceBodyOkLoadedZero {cA gh bl σ σ₀ A I} {g : UInt256} refine ExecBlock.consNormal haddStmt ?_ refine ExecBlock.consNormal (ExecStmt.assign hsayNewVar hassignSay) ?_ exact ExecBlock.consNormal htail ExecBlock.nil - exact Reasoning.Refinement.execBlock_append hcallBlock hrest + exact.execBlock_append hcallBlock hrest have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: diff --git a/Benchmarks/Dss/Cure/LoadTrace.lean b/Benchmarks/Dss/Cure/LoadTrace.lean index e5a8ace2..404443c0 100644 --- a/Benchmarks/Dss/Cure/LoadTrace.lean +++ b/Benchmarks/Dss/Cure/LoadTrace.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.LoadSource -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Cure/Loaded.lean b/Benchmarks/Dss/Cure/Loaded.lean index 7a5f82c9..78415aaa 100644 --- a/Benchmarks/Dss/Cure/Loaded.lean +++ b/Benchmarks/Dss/Cure/Loaded.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/Pos.lean b/Benchmarks/Dss/Cure/Pos.lean index 6e24d623..816e79a1 100644 --- a/Benchmarks/Dss/Cure/Pos.lean +++ b/Benchmarks/Dss/Cure/Pos.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/Rely.lean b/Benchmarks/Dss/Cure/Rely.lean index c43ab964..3e809513 100644 --- a/Benchmarks/Dss/Cure/Rely.lean +++ b/Benchmarks/Dss/Cure/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Cure/Say.lean b/Benchmarks/Dss/Cure/Say.lean index b690fa88..a14af416 100644 --- a/Benchmarks/Dss/Cure/Say.lean +++ b/Benchmarks/Dss/Cure/Say.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/Srcs.lean b/Benchmarks/Dss/Cure/Srcs.lean index 200ad98c..3f23263e 100644 --- a/Benchmarks/Dss/Cure/Srcs.lean +++ b/Benchmarks/Dss/Cure/Srcs.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Cure.Common import Ethereum.Theory.OpcodeLemmas -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/TCount.lean b/Benchmarks/Dss/Cure/TCount.lean index 33f110ed..4c68acf7 100644 --- a/Benchmarks/Dss/Cure/TCount.lean +++ b/Benchmarks/Dss/Cure/TCount.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/Tell.lean b/Benchmarks/Dss/Cure/Tell.lean index 3ba8d5e6..5b27a538 100644 --- a/Benchmarks/Dss/Cure/Tell.lean +++ b/Benchmarks/Dss/Cure/Tell.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/Wait.lean b/Benchmarks/Dss/Cure/Wait.lean index b0e3aa5e..a73de1b4 100644 --- a/Benchmarks/Dss/Cure/Wait.lean +++ b/Benchmarks/Dss/Cure/Wait.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/Wards.lean b/Benchmarks/Dss/Cure/Wards.lean index 62ac9927..2ff04bfa 100644 --- a/Benchmarks/Dss/Cure/Wards.lean +++ b/Benchmarks/Dss/Cure/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Cure/When.lean b/Benchmarks/Dss/Cure/When.lean index 8b320d50..5e3c9896 100644 --- a/Benchmarks/Dss/Cure/When.lean +++ b/Benchmarks/Dss/Cure/When.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Cure.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Cure diff --git a/Benchmarks/Dss/Dai/Allowance.lean b/Benchmarks/Dss/Dai/Allowance.lean index 2f55e2c3..5a801460 100644 --- a/Benchmarks/Dss/Dai/Allowance.lean +++ b/Benchmarks/Dss/Dai/Allowance.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Dispatch import Benchmarks.Dss.Dai.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Dai diff --git a/Benchmarks/Dss/Dai/Approve.lean b/Benchmarks/Dss/Dai/Approve.lean index d47d289c..d2cf0c97 100644 --- a/Benchmarks/Dss/Dai/Approve.lean +++ b/Benchmarks/Dss/Dai/Approve.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Dispatch import Benchmarks.Dss.Dai.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/BalanceOf.lean b/Benchmarks/Dss/Dai/BalanceOf.lean index 0e5b19e0..185fc534 100644 --- a/Benchmarks/Dss/Dai/BalanceOf.lean +++ b/Benchmarks/Dss/Dai/BalanceOf.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Dispatch import Benchmarks.Dss.Dai.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Dai diff --git a/Benchmarks/Dss/Dai/Burn.lean b/Benchmarks/Dss/Dai/Burn.lean index 7ca56739..840d2cb9 100644 --- a/Benchmarks/Dss/Dai/Burn.lean +++ b/Benchmarks/Dss/Dai/Burn.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dai.TransferFrom -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/Common.lean b/Benchmarks/Dss/Dai/Common.lean index eefddac9..ca4629ef 100644 --- a/Benchmarks/Dss/Dai/Common.lean +++ b/Benchmarks/Dss/Dai/Common.lean @@ -5,7 +5,6 @@ import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -17,7 +16,7 @@ from the canonical ABI signatures and cross-checked against the runtime dispatch `Bytecode.lean`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/Constructor.lean b/Benchmarks/Dss/Dai/Constructor.lean index 1f55a0f9..c2d5df2d 100644 --- a/Benchmarks/Dss/Dai/Constructor.lean +++ b/Benchmarks/Dss/Dai/Constructor.lean @@ -15,7 +15,7 @@ The optimized creation bytecode, deployed runtime bytecode, and Solm constructor present. The constructor-equivalence proof is intentionally left as the benchmark target. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Dai diff --git a/Benchmarks/Dss/Dai/Correct.lean b/Benchmarks/Dss/Dai/Correct.lean index 682e046f..b9ce7ca9 100644 --- a/Benchmarks/Dss/Dai/Correct.lean +++ b/Benchmarks/Dss/Dai/Correct.lean @@ -30,7 +30,7 @@ selector-size guard, and one branch per ABI selector. Each matched branch deleg function's `…BodyCore` lemma in its own file. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/Decimals.lean b/Benchmarks/Dss/Dai/Decimals.lean index 25ab2e17..0890a3f4 100644 --- a/Benchmarks/Dss/Dai/Decimals.lean +++ b/Benchmarks/Dss/Dai/Decimals.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Dispatch import Benchmarks.Dss.Dai.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Dai diff --git a/Benchmarks/Dss/Dai/Deny.lean b/Benchmarks/Dss/Dai/Deny.lean index 1e817740..2f499a2d 100644 --- a/Benchmarks/Dss/Dai/Deny.lean +++ b/Benchmarks/Dss/Dai/Deny.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Dispatch import Benchmarks.Dss.Dai.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/Dispatch.lean b/Benchmarks/Dss/Dai/Dispatch.lean index fe262ced..7a188102 100644 --- a/Benchmarks/Dss/Dai/Dispatch.lean +++ b/Benchmarks/Dss/Dai/Dispatch.lean @@ -7,7 +7,7 @@ The optimized Dai runtime uses a three-split selector tree. These facts stop at entry points and are intended to feed the per-function body proofs. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/DomainSeparator.lean b/Benchmarks/Dss/Dai/DomainSeparator.lean index 2186f982..edeb1a32 100644 --- a/Benchmarks/Dss/Dai/DomainSeparator.lean +++ b/Benchmarks/Dss/Dai/DomainSeparator.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Dispatch import Benchmarks.Dss.Dai.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Dai diff --git a/Benchmarks/Dss/Dai/Mint.lean b/Benchmarks/Dss/Dai/Mint.lean index 1b59cd86..5f391ff8 100644 --- a/Benchmarks/Dss/Dai/Mint.lean +++ b/Benchmarks/Dss/Dai/Mint.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Rely import Benchmarks.Dss.Dai.TransferFrom -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/Move.lean b/Benchmarks/Dss/Dai/Move.lean index 0c898655..f47e41e5 100644 --- a/Benchmarks/Dss/Dai/Move.lean +++ b/Benchmarks/Dss/Dai/Move.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dai.TransferFrom -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/Name.lean b/Benchmarks/Dss/Dai/Name.lean index c44a3dac..54fe3b95 100644 --- a/Benchmarks/Dss/Dai/Name.lean +++ b/Benchmarks/Dss/Dai/Name.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dai.StringReturn -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/Nonces.lean b/Benchmarks/Dss/Dai/Nonces.lean index b8b79a41..a75b1ddb 100644 --- a/Benchmarks/Dss/Dai/Nonces.lean +++ b/Benchmarks/Dss/Dai/Nonces.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Dispatch import Benchmarks.Dss.Dai.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Dai diff --git a/Benchmarks/Dss/Dai/Permit.lean b/Benchmarks/Dss/Dai/Permit.lean index 7f6c2b9d..d67cee41 100644 --- a/Benchmarks/Dss/Dai/Permit.lean +++ b/Benchmarks/Dss/Dai/Permit.lean @@ -5,7 +5,7 @@ import Ethereum.Theory.OpcodeLemmas import Reasoning.ExternalCall import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Benchmarks/Dss/Dai/PermitTypehash.lean b/Benchmarks/Dss/Dai/PermitTypehash.lean index a6906a01..b610a41a 100644 --- a/Benchmarks/Dss/Dai/PermitTypehash.lean +++ b/Benchmarks/Dss/Dai/PermitTypehash.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Dispatch import Benchmarks.Dss.Dai.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Dai diff --git a/Benchmarks/Dss/Dai/Pull.lean b/Benchmarks/Dss/Dai/Pull.lean index 95f0ba8e..e75f1967 100644 --- a/Benchmarks/Dss/Dai/Pull.lean +++ b/Benchmarks/Dss/Dai/Pull.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dai.TransferFrom -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/Push.lean b/Benchmarks/Dss/Dai/Push.lean index 85686f70..7e78a109 100644 --- a/Benchmarks/Dss/Dai/Push.lean +++ b/Benchmarks/Dss/Dai/Push.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dai.TransferFrom -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/Rely.lean b/Benchmarks/Dss/Dai/Rely.lean index fee8d4cc..762999d2 100644 --- a/Benchmarks/Dss/Dai/Rely.lean +++ b/Benchmarks/Dss/Dai/Rely.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Dispatch import Benchmarks.Dss.Dai.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/StringReturn.lean b/Benchmarks/Dss/Dai/StringReturn.lean index 769ec93c..793a7c29 100644 --- a/Benchmarks/Dss/Dai/StringReturn.lean +++ b/Benchmarks/Dss/Dai/StringReturn.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Dispatch import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/Symbol.lean b/Benchmarks/Dss/Dai/Symbol.lean index 84ab5a1e..409933aa 100644 --- a/Benchmarks/Dss/Dai/Symbol.lean +++ b/Benchmarks/Dss/Dai/Symbol.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dai.StringReturn -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/TotalSupply.lean b/Benchmarks/Dss/Dai/TotalSupply.lean index 617889d0..b06478dd 100644 --- a/Benchmarks/Dss/Dai/TotalSupply.lean +++ b/Benchmarks/Dss/Dai/TotalSupply.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Dispatch import Benchmarks.Dss.Dai.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Dai diff --git a/Benchmarks/Dss/Dai/Transfer.lean b/Benchmarks/Dss/Dai/Transfer.lean index 776a4450..b16b4716 100644 --- a/Benchmarks/Dss/Dai/Transfer.lean +++ b/Benchmarks/Dss/Dai/Transfer.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dai.TransferFrom -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/TransferFrom.lean b/Benchmarks/Dss/Dai/TransferFrom.lean index e1c3ffe1..a4298ded 100644 --- a/Benchmarks/Dss/Dai/TransferFrom.lean +++ b/Benchmarks/Dss/Dai/TransferFrom.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Dispatch import Benchmarks.Dss.Dai.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Dai diff --git a/Benchmarks/Dss/Dai/Version.lean b/Benchmarks/Dss/Dai/Version.lean index 7956abfb..d819d62f 100644 --- a/Benchmarks/Dss/Dai/Version.lean +++ b/Benchmarks/Dss/Dai/Version.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dai.StringReturn -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dai/Wards.lean b/Benchmarks/Dss/Dai/Wards.lean index cfcc0252..7ef6a081 100644 --- a/Benchmarks/Dss/Dai/Wards.lean +++ b/Benchmarks/Dss/Dai/Wards.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dai.Dispatch import Benchmarks.Dss.Dai.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Dai diff --git a/Benchmarks/Dss/DaiJoin/Cage.lean b/Benchmarks/Dss/DaiJoin/Cage.lean index 9cdfa5c6..ea88cdfe 100644 --- a/Benchmarks/Dss/DaiJoin/Cage.lean +++ b/Benchmarks/Dss/DaiJoin/Cage.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.DaiJoin.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/DaiJoin/Calls.lean b/Benchmarks/Dss/DaiJoin/Calls.lean index 010d21db..fbba8b0d 100644 --- a/Benchmarks/Dss/DaiJoin/Calls.lean +++ b/Benchmarks/Dss/DaiJoin/Calls.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.DaiJoin.Dispatch import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/DaiJoin/Common.lean b/Benchmarks/Dss/DaiJoin/Common.lean index a823fcf6..4f40817f 100644 --- a/Benchmarks/Dss/DaiJoin/Common.lean +++ b/Benchmarks/Dss/DaiJoin/Common.lean @@ -7,7 +7,6 @@ import Reasoning.Solc import Reasoning.Memory import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -17,7 +16,7 @@ import Mathlib.Tactic.IntervalCases Contract-wide selector notation and constants for the optimized DaiJoin runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/DaiJoin/Correct.lean b/Benchmarks/Dss/DaiJoin/Correct.lean index 3bbbad97..785b2854 100644 --- a/Benchmarks/Dss/DaiJoin/Correct.lean +++ b/Benchmarks/Dss/DaiJoin/Correct.lean @@ -18,7 +18,7 @@ are present. The runtime-equivalence proof is intentionally left as the benchmar also exposes the whole-contract wrapper that combines the constructor and runtime targets. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/DaiJoin/Dai.lean b/Benchmarks/Dss/DaiJoin/Dai.lean index 9baf4d2a..b182c4c4 100644 --- a/Benchmarks/Dss/DaiJoin/Dai.lean +++ b/Benchmarks/Dss/DaiJoin/Dai.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.DaiJoin.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.DaiJoin diff --git a/Benchmarks/Dss/DaiJoin/Deny.lean b/Benchmarks/Dss/DaiJoin/Deny.lean index a2cca524..8ee4afd5 100644 --- a/Benchmarks/Dss/DaiJoin/Deny.lean +++ b/Benchmarks/Dss/DaiJoin/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.DaiJoin.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/DaiJoin/Dispatch.lean b/Benchmarks/Dss/DaiJoin/Dispatch.lean index bb8a21c3..72e03f5c 100644 --- a/Benchmarks/Dss/DaiJoin/Dispatch.lean +++ b/Benchmarks/Dss/DaiJoin/Dispatch.lean @@ -6,7 +6,7 @@ import Benchmarks.Dss.DaiJoin.Trusted Solm dispatch routing facts and shared dispatcher-level proof obligations. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/DaiJoin/Exit.lean b/Benchmarks/Dss/DaiJoin/Exit.lean index 1be3b05f..1979574b 100644 --- a/Benchmarks/Dss/DaiJoin/Exit.lean +++ b/Benchmarks/Dss/DaiJoin/Exit.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.DaiJoin.Join -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/DaiJoin/ExitRuntime.lean b/Benchmarks/Dss/DaiJoin/ExitRuntime.lean index 98a9f092..d45b8d76 100644 --- a/Benchmarks/Dss/DaiJoin/ExitRuntime.lean +++ b/Benchmarks/Dss/DaiJoin/ExitRuntime.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.DaiJoin.Exit -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/DaiJoin/Join.lean b/Benchmarks/Dss/DaiJoin/Join.lean index 3f3b312a..bfdf1e78 100644 --- a/Benchmarks/Dss/DaiJoin/Join.lean +++ b/Benchmarks/Dss/DaiJoin/Join.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.DaiJoin.JoinTrace -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/DaiJoin/JoinTrace.lean b/Benchmarks/Dss/DaiJoin/JoinTrace.lean index 3e120871..06221279 100644 --- a/Benchmarks/Dss/DaiJoin/JoinTrace.lean +++ b/Benchmarks/Dss/DaiJoin/JoinTrace.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.DaiJoin.Mul -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/DaiJoin/Live.lean b/Benchmarks/Dss/DaiJoin/Live.lean index 5da9a0d7..1d60c114 100644 --- a/Benchmarks/Dss/DaiJoin/Live.lean +++ b/Benchmarks/Dss/DaiJoin/Live.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.DaiJoin.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.DaiJoin diff --git a/Benchmarks/Dss/DaiJoin/Mul.lean b/Benchmarks/Dss/DaiJoin/Mul.lean index 152a2400..0106e996 100644 --- a/Benchmarks/Dss/DaiJoin/Mul.lean +++ b/Benchmarks/Dss/DaiJoin/Mul.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.DaiJoin.Calls -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/DaiJoin/Rely.lean b/Benchmarks/Dss/DaiJoin/Rely.lean index c283e90f..7a7767ea 100644 --- a/Benchmarks/Dss/DaiJoin/Rely.lean +++ b/Benchmarks/Dss/DaiJoin/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.DaiJoin.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/DaiJoin/Vat.lean b/Benchmarks/Dss/DaiJoin/Vat.lean index 4fb340a1..8113c1b1 100644 --- a/Benchmarks/Dss/DaiJoin/Vat.lean +++ b/Benchmarks/Dss/DaiJoin/Vat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.DaiJoin.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.DaiJoin diff --git a/Benchmarks/Dss/DaiJoin/Wards.lean b/Benchmarks/Dss/DaiJoin/Wards.lean index 78237b22..a67c27a4 100644 --- a/Benchmarks/Dss/DaiJoin/Wards.lean +++ b/Benchmarks/Dss/DaiJoin/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.DaiJoin.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.DaiJoin diff --git a/Benchmarks/Dss/Dog/Bark.lean b/Benchmarks/Dss/Dog/Bark.lean index e2f453af..bfaa12ca 100644 --- a/Benchmarks/Dss/Dog/Bark.lean +++ b/Benchmarks/Dss/Dog/Bark.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Dog.Dispatch import Reasoning.MemCascade import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dog/Cage.lean b/Benchmarks/Dss/Dog/Cage.lean index 078a5f17..4770d64c 100644 --- a/Benchmarks/Dss/Dog/Cage.lean +++ b/Benchmarks/Dss/Dog/Cage.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dog.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables namespace Benchmarks.Dss.Dog diff --git a/Benchmarks/Dss/Dog/Chop.lean b/Benchmarks/Dss/Dog/Chop.lean index 7c090d3d..698d26d8 100644 --- a/Benchmarks/Dss/Dog/Chop.lean +++ b/Benchmarks/Dss/Dog/Chop.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dog.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables namespace Benchmarks.Dss.Dog diff --git a/Benchmarks/Dss/Dog/Common.lean b/Benchmarks/Dss/Dog/Common.lean index e0e3e725..6cae16e0 100644 --- a/Benchmarks/Dss/Dog/Common.lean +++ b/Benchmarks/Dss/Dog/Common.lean @@ -8,7 +8,6 @@ import Reasoning.Memory import Reasoning.Storage import Reasoning.Dispatch import Reasoning.Initcode -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -18,7 +17,7 @@ import Mathlib.Tactic.IntervalCases Contract-wide selector notation and constants for the optimized Dog runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dog/Correct.lean b/Benchmarks/Dss/Dog/Correct.lean index b983cbec..630d3fc1 100644 --- a/Benchmarks/Dss/Dog/Correct.lean +++ b/Benchmarks/Dss/Dog/Correct.lean @@ -26,7 +26,7 @@ are present. The runtime-equivalence proof is intentionally left as the benchmar also exposes the whole-contract wrapper that combines the constructor and runtime targets. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dog/Deny.lean b/Benchmarks/Dss/Dog/Deny.lean index c8fcfd1f..479b3f6b 100644 --- a/Benchmarks/Dss/Dog/Deny.lean +++ b/Benchmarks/Dss/Dog/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dog.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Dog/Digs.lean b/Benchmarks/Dss/Dog/Digs.lean index 80104842..30ad9355 100644 --- a/Benchmarks/Dss/Dog/Digs.lean +++ b/Benchmarks/Dss/Dog/Digs.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dog.Dispatch import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Dog/Dirt.lean b/Benchmarks/Dss/Dog/Dirt.lean index e8e209a4..4b174c94 100644 --- a/Benchmarks/Dss/Dog/Dirt.lean +++ b/Benchmarks/Dss/Dog/Dirt.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dog.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables namespace Benchmarks.Dss.Dog diff --git a/Benchmarks/Dss/Dog/Dispatch.lean b/Benchmarks/Dss/Dog/Dispatch.lean index ad2d2fcd..900bb92b 100644 --- a/Benchmarks/Dss/Dog/Dispatch.lean +++ b/Benchmarks/Dss/Dog/Dispatch.lean @@ -6,7 +6,7 @@ import Benchmarks.Dss.Dog.Trusted Solm dispatch routing facts and the shared runtime revert paths. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Dog/FileAddress.lean b/Benchmarks/Dss/Dog/FileAddress.lean index 2187b988..4cec20d6 100644 --- a/Benchmarks/Dss/Dog/FileAddress.lean +++ b/Benchmarks/Dss/Dog/FileAddress.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dog.Dispatch import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Dog/FileIlkClip.lean b/Benchmarks/Dss/Dog/FileIlkClip.lean index 6604f5f6..b65c263f 100644 --- a/Benchmarks/Dss/Dog/FileIlkClip.lean +++ b/Benchmarks/Dss/Dog/FileIlkClip.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dog.FileIlkUint import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Dog/FileIlkUint.lean b/Benchmarks/Dss/Dog/FileIlkUint.lean index fac2e252..decc76ab 100644 --- a/Benchmarks/Dss/Dog/FileIlkUint.lean +++ b/Benchmarks/Dss/Dog/FileIlkUint.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dog.Dispatch import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Dog/FileUint.lean b/Benchmarks/Dss/Dog/FileUint.lean index bf6d9ded..277d9a38 100644 --- a/Benchmarks/Dss/Dog/FileUint.lean +++ b/Benchmarks/Dss/Dog/FileUint.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dog.Dispatch import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Dog/Hole.lean b/Benchmarks/Dss/Dog/Hole.lean index 65f062b2..ede93cb8 100644 --- a/Benchmarks/Dss/Dog/Hole.lean +++ b/Benchmarks/Dss/Dog/Hole.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dog.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables namespace Benchmarks.Dss.Dog diff --git a/Benchmarks/Dss/Dog/Ilks.lean b/Benchmarks/Dss/Dog/Ilks.lean index af8d055f..a5ced509 100644 --- a/Benchmarks/Dss/Dog/Ilks.lean +++ b/Benchmarks/Dss/Dog/Ilks.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Dog.Dispatch import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Dog/Live.lean b/Benchmarks/Dss/Dog/Live.lean index 46853af3..d2272259 100644 --- a/Benchmarks/Dss/Dog/Live.lean +++ b/Benchmarks/Dss/Dog/Live.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dog.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables namespace Benchmarks.Dss.Dog diff --git a/Benchmarks/Dss/Dog/Rely.lean b/Benchmarks/Dss/Dog/Rely.lean index ea6f9c5f..d585ac34 100644 --- a/Benchmarks/Dss/Dog/Rely.lean +++ b/Benchmarks/Dss/Dog/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dog.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Dog/Vat.lean b/Benchmarks/Dss/Dog/Vat.lean index 2567ddb2..0b2c9a28 100644 --- a/Benchmarks/Dss/Dog/Vat.lean +++ b/Benchmarks/Dss/Dog/Vat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dog.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables namespace Benchmarks.Dss.Dog diff --git a/Benchmarks/Dss/Dog/Vow.lean b/Benchmarks/Dss/Dog/Vow.lean index b5bbc15a..fb1e1113 100644 --- a/Benchmarks/Dss/Dog/Vow.lean +++ b/Benchmarks/Dss/Dog/Vow.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dog.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables namespace Benchmarks.Dss.Dog diff --git a/Benchmarks/Dss/Dog/Wards.lean b/Benchmarks/Dss/Dog/Wards.lean index 06da4de5..ef66692e 100644 --- a/Benchmarks/Dss/Dog/Wards.lean +++ b/Benchmarks/Dss/Dog/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Dog.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.Dss.Dog.Immutables namespace Benchmarks.Dss.Dog diff --git a/Benchmarks/Dss/End/Art.lean b/Benchmarks/Dss/End/Art.lean index 15164dc1..f52f34a4 100644 --- a/Benchmarks/Dss/End/Art.lean +++ b/Benchmarks/Dss/End/Art.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Bag.lean b/Benchmarks/Dss/End/Bag.lean index 9a3f586a..9ada64cd 100644 --- a/Benchmarks/Dss/End/Bag.lean +++ b/Benchmarks/Dss/End/Bag.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Cage.lean b/Benchmarks/Dss/End/Cage.lean index 7cafc3ea..713dc3a4 100644 --- a/Benchmarks/Dss/End/Cage.lean +++ b/Benchmarks/Dss/End/Cage.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.End.Common import Benchmarks.Dss.End.FileUint -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 @@ -3125,10 +3125,10 @@ theorem endCageExecBlock_append_revert {f f1 : Frame} {e e1 : EVM.State} ExecBlock config f e (s1 ++ s2 ++ tail) .reverted := by have h2tail : ExecBlock config f1 e1 (s2 ++ tail) .reverted := - Reasoning.Refinement.execBlock_append_term + .execBlock_append_term (s2 := tail) h2 (by intro f' e' h; cases h) simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append (s2 := s2 ++ tail) h1 h2tail + .execBlock_append (s2 := s2 ++ tail) h1 h2tail theorem endCageSourceAuthReverts {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) @@ -3427,7 +3427,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (endCageSourceStorePrefixStmts ++ endCageSourceVatStmts) (.ok { contract := contract, locals := lVat } evmS1) := by simpa [l0, List.append_assoc] using - Reasoning.Refinement.execBlock_append (s2 := endCageSourceVatStmts) + .execBlock_append (s2 := endCageSourceVatStmts) hSrc0 hVatBlock by_cases hCatCodeE : Reasoning.Theory.extCodeSizeWord evmE1.accountMap @@ -3584,7 +3584,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} endCageSourceCatStmts) (.ok { contract := contract, locals := lCat } evmS2) := by simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append (s2 := endCageSourceCatStmts) + .execBlock_append (s2 := endCageSourceCatStmts) hSrcVat hCatBlock by_cases hDogCodeE : Reasoning.Theory.extCodeSizeWord evmE2.accountMap @@ -3745,7 +3745,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} endCageSourceCatStmts ++ endCageSourceDogStmts) (.ok { contract := contract, locals := lDog } evmS3) := by simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append + .execBlock_append (s2 := endCageSourceDogStmts) hSrcCat hDogBlock by_cases hVowCodeE : Reasoning.Theory.extCodeSizeWord evmE3.accountMap @@ -3912,7 +3912,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} endCageSourceVowStmts) (.ok { contract := contract, locals := lVow } evmS4) := by simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append + .execBlock_append (s2 := endCageSourceVowStmts) hSrcDog hVowBlock by_cases hSpotCodeE : Reasoning.Theory.extCodeSizeWord evmE4.accountMap @@ -4089,7 +4089,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (.ok { contract := contract, locals := lSpot } evmS5) := by simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append + .execBlock_append (s2 := endCageSourceSpotStmts) hSrcVow hSpotBlock by_cases hPotCodeE : Reasoning.Theory.extCodeSizeWord evmE5.accountMap @@ -4279,7 +4279,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (.ok { contract := contract, locals := lPot } evmS6) := by simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append + .execBlock_append (s2 := endCageSourcePotStmts) hSrcSpot hPotBlock by_cases hCureCodeE : Reasoning.Theory.extCodeSizeWord evmE6.accountMap @@ -4489,7 +4489,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (.ok { contract := contract, locals := lCure } evmS7) := by simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append + .execBlock_append (s2 := endCageSourceCureStmts) hSrcPot hCureBlock have hbody : diff --git a/Benchmarks/Dss/End/CageIlk.lean b/Benchmarks/Dss/End/CageIlk.lean index 416689e8..9afd7090 100644 --- a/Benchmarks/Dss/End/CageIlk.lean +++ b/Benchmarks/Dss/End/CageIlk.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.End.Dispatch import Benchmarks.Dss.End.Cage import Benchmarks.Dss.End.Flow -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 @@ -4925,7 +4925,7 @@ theorem endCageIlkBodyReverts_vatIlksTerminated {cA gh bl σ σ₀ A I} {g : UIn · exact evalCallvalueEq_true (by simp only [evm0, initState]; exact hwv) refine ExecBlock.consNormal (ExecStmt.requireTrue hguardLive) ?_ refine ExecBlock.consNormal (ExecStmt.requireTrue hguardTag) ?_ - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s1 := checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] "vatIlk") (s2 := @@ -5041,7 +5041,7 @@ theorem endCageIlkTailFromVatReverts_spotTerminated (evmVat : EVM.State) "spotIlk" (perm := false)) .reverted := by simpa [evmArt] using hspot refine ExecBlock.consNormal (endCageIlkStmtArt evmVat I vatOut hsz36) ?_ - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s1 := checkedExternalCallStmts (.storage spotRef) "spotIlks" (.intLit 0) [.var "ilk"] "spotIlk" (perm := false)) (s2 := @@ -5170,7 +5170,7 @@ theorem endCageIlkTailAfterSpotReverts_parTerminated {evmSpot : EVM.State} [ .internalCall "wdiv" [.var "parV", .cast (.var "pipRead") uint256St] "tagV", .assign .storage (tagRef (.var "ilk")) (.var "tagV") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s1 := checkedExternalCallStmts (.storage spotRef) "par" (.intLit 0) [] "parV" (perm := false)) (s2 := @@ -5258,7 +5258,7 @@ theorem endCageIlkTailAfterParReverts_readTerminated {evmPar : EVM.State} [ .internalCall "wdiv" [.var "parV", .cast (.var "pipRead") uint256St] "tagV", .assign .storage (tagRef (.var "ilk")) (.var "tagV") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s1 := checkedExternalCallStmts (.var "pip") "read" (.intLit 0) [] "pipRead" (perm := false)) (s2 := @@ -5349,7 +5349,7 @@ theorem endCageIlkTailAfterParReadOk {evmPar evmRead : EVM.State} (evm := evmPar) (evm' := evmRead) (I := I) (vatOut := vatOut) (spotOut := spotOut) (parOut := parOut) (readOut := readOut) hcodeSize hcall hlo - exact Reasoning.Refinement.execBlock_append hread htail + exact.execBlock_append hread htail theorem endCageIlkTailAfterSpotParOk {evmSpot evmPar : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut : ByteArray} @@ -5385,7 +5385,7 @@ theorem endCageIlkTailAfterSpotParOk {evmSpot evmPar : EVM.State} endCageIlkCheckedParSuccess (evm := evmSpot) (evm' := evmPar) (I := I) (vatOut := vatOut) (spotOut := spotOut) (parOut := parOut) hcodeSize hcall hlo - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := checkedExternalCallStmts (.var "pip") "read" (.intLit 0) [] "pipRead" (perm := false) ++ @@ -5461,7 +5461,7 @@ theorem endCageIlkTailFromVatSpotOk {evmVat evmSpot : EVM.State} "spotIlk" (perm := false) ++ [ .letDecl "pip" (some addr) (.tupleGet (.var "spotIlk") 0) ]) (.ok { contract := contract, locals := endCageIlkStorePip I vatOut spotOut } evmSpot) := by - exact Reasoning.Refinement.execBlock_append hspot hpip + exact.execBlock_append hspot hpip have hrest : ExecBlock config { contract := contract, locals := endCageIlkStoreVatIlk I vatOut } evmArt @@ -5475,7 +5475,7 @@ theorem endCageIlkTailFromVatSpotOk {evmVat evmSpot : EVM.State} [ .internalCall "wdiv" [.var "parV", .cast (.var "pipRead") uint256St] "tagV", .assign .storage (tagRef (.var "ilk")) (.var "tagV") ]) res := by - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := checkedExternalCallStmts (.storage spotRef) "par" (.intLit 0) [] "parV" (perm := false) ++ @@ -5588,7 +5588,7 @@ theorem endCageIlkBodyReverts_vatIlksOkTailReverted {cA gh bl σ σ₀ A I} have hblock : ExecBlock config { contract := contract, locals := endCageIlkStore I } evm0 cageIlkTransition.body .reverted := by - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := [ .assign .storage (ArtRef (.var "ilk")) (.tupleGet (.var "vatIlk") 0) ] ++ checkedExternalCallStmts (.storage spotRef) "spotIlks" (.intLit 0) [.var "ilk"] @@ -5650,7 +5650,7 @@ theorem endCageIlkBodyReturns_vatIlksOkTail {cA gh bl σ σ₀ A I} have hblock : ExecBlock config { contract := contract, locals := endCageIlkStore I } evm0 cageIlkTransition.body (.ok fPost evmPost) := by - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := [ .assign .storage (ArtRef (.var "ilk")) (.tupleGet (.var "vatIlk") 0) ] ++ checkedExternalCallStmts (.storage spotRef) "spotIlks" (.intLit 0) [.var "ilk"] diff --git a/Benchmarks/Dss/End/Cash.lean b/Benchmarks/Dss/End/Cash.lean index ecdebb13..910d7065 100644 --- a/Benchmarks/Dss/End/Cash.lean +++ b/Benchmarks/Dss/End/Cash.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.End.Dispatch import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 @@ -2834,7 +2834,7 @@ theorem endCashBodyReverts_fluxNoCode {cA gh bl σ σ₀ A I} {g : UInt256} .require (.binary .le (.var "outNew") (.storage (bagRef sender))) ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .internalCall "add" [.storage (outRef (.var "ilk") sender), .var "wad"] "outNew", .assign .storage (outRef (.var "ilk") sender) (.var "outNew"), @@ -2962,7 +2962,7 @@ theorem endCashBodyReverts_fluxCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} .require (.binary .le (.var "outNew") (.storage (bagRef sender))) ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .internalCall "add" [.storage (outRef (.var "ilk") sender), .var "wad"] "outNew", .assign .storage (outRef (.var "ilk") sender) (.var "outNew"), @@ -3325,7 +3325,7 @@ theorem endCashTailReverts_outExceedsBag (evm : EVM.State) (I : ExecutionEnv) (.binary .le (.var "outNew") (.storage (bagRef sender))) ] .reverted := ExecBlock.consRevert (ExecStmt.requireFalse hreq) - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := [ .require (.binary .le (.var "outNew") (.storage (bagRef sender))) ]) hprefix htail @@ -3390,7 +3390,7 @@ theorem endCashTailReturns (evm : EVM.State) (I : ExecutionEnv) (.binary .le (.var "outNew") (.storage (bagRef sender))) ] (.ok { contract := contract, locals := endCashStoreOutNew σ I outNew } evmPost) := ExecBlock.consNormal (ExecStmt.requireTrue hreq) ExecBlock.nil - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := [ .require (.binary .le (.var "outNew") (.storage (bagRef sender))) ]) hprefix htail @@ -3560,7 +3560,7 @@ theorem endCashBodyReverts_outAddOverflow {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endCashStore I } evm0 cashTransition.body .reverted := by - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := [ .internalCall "add" [.storage (outRef (.var "ilk") sender), .var "wad"] "outNew", .assign .storage (outRef (.var "ilk") sender) (.var "outNew"), @@ -3614,7 +3614,7 @@ theorem endCashBodyReverts_outExceedsBag {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endCashStore I } evm0 cashTransition.body .reverted := by - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := [ .internalCall "add" [.storage (outRef (.var "ilk") sender), .var "wad"] "outNew", .assign .storage (outRef (.var "ilk") sender) (.var "outNew"), @@ -3674,7 +3674,7 @@ theorem endCashBodyReturns {cA gh bl σ σ₀ A I} {g : UInt256} cashTransition.body (.ok { contract := contract, locals := endCashStoreOutNew σ I outNew } (endCashPostState evmFlux I outNew)) := by - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := [ .internalCall "add" [.storage (outRef (.var "ilk") sender), .var "wad"] "outNew", .assign .storage (outRef (.var "ilk") sender) (.var "outNew"), diff --git a/Benchmarks/Dss/End/Cat.lean b/Benchmarks/Dss/End/Cat.lean index 536d9235..cc233672 100644 --- a/Benchmarks/Dss/End/Cat.lean +++ b/Benchmarks/Dss/End/Cat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Common.lean b/Benchmarks/Dss/End/Common.lean index 5600acaf..4cfe0b5d 100644 --- a/Benchmarks/Dss/End/Common.lean +++ b/Benchmarks/Dss/End/Common.lean @@ -7,7 +7,6 @@ import Reasoning.Solc import Reasoning.Memory import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Reasoning.ExternalCall import Mathlib.Tactic.IntervalCases @@ -18,7 +17,7 @@ import Mathlib.Tactic.IntervalCases Contract-wide helpers for the optimized runtime and creation bytecode. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/End/Constructor.lean b/Benchmarks/Dss/End/Constructor.lean index 337c1408..e0507be2 100644 --- a/Benchmarks/Dss/End/Constructor.lean +++ b/Benchmarks/Dss/End/Constructor.lean @@ -6,7 +6,7 @@ import Solm.Equiv # MakerDAO/Sky DSS End constructor correctness -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.End diff --git a/Benchmarks/Dss/End/Correct.lean b/Benchmarks/Dss/End/Correct.lean index 9c682c6f..9fe71954 100644 --- a/Benchmarks/Dss/End/Correct.lean +++ b/Benchmarks/Dss/End/Correct.lean @@ -37,7 +37,7 @@ import Solm.Equiv # MakerDAO/Sky DSS End benchmark correctness -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.End diff --git a/Benchmarks/Dss/End/Cure.lean b/Benchmarks/Dss/End/Cure.lean index 088371b2..0a9ccf09 100644 --- a/Benchmarks/Dss/End/Cure.lean +++ b/Benchmarks/Dss/End/Cure.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Debt.lean b/Benchmarks/Dss/End/Debt.lean index 6918b9a9..e844631f 100644 --- a/Benchmarks/Dss/End/Debt.lean +++ b/Benchmarks/Dss/End/Debt.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Deny.lean b/Benchmarks/Dss/End/Deny.lean index a605dd4d..3483ec5a 100644 --- a/Benchmarks/Dss/End/Deny.lean +++ b/Benchmarks/Dss/End/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Dispatch.lean b/Benchmarks/Dss/End/Dispatch.lean index eafd3cb7..d88e9d10 100644 --- a/Benchmarks/Dss/End/Dispatch.lean +++ b/Benchmarks/Dss/End/Dispatch.lean @@ -4,7 +4,7 @@ import Benchmarks.Dss.End.Trusted # MakerDAO/Sky DSS End dispatcher proof boundary -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Dog.lean b/Benchmarks/Dss/End/Dog.lean index 0ce3f4f5..015e7395 100644 --- a/Benchmarks/Dss/End/Dog.lean +++ b/Benchmarks/Dss/End/Dog.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/FileAddress.lean b/Benchmarks/Dss/End/FileAddress.lean index 563b2724..c9b84542 100644 --- a/Benchmarks/Dss/End/FileAddress.lean +++ b/Benchmarks/Dss/End/FileAddress.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.FileUint -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/FileAddressTail.lean b/Benchmarks/Dss/End/FileAddressTail.lean index b4064f7b..20e29407 100644 --- a/Benchmarks/Dss/End/FileAddressTail.lean +++ b/Benchmarks/Dss/End/FileAddressTail.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.FileAddress -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.End diff --git a/Benchmarks/Dss/End/FileUint.lean b/Benchmarks/Dss/End/FileUint.lean index 1e2a52b4..cc5f94f5 100644 --- a/Benchmarks/Dss/End/FileUint.lean +++ b/Benchmarks/Dss/End/FileUint.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Fix.lean b/Benchmarks/Dss/End/Fix.lean index b318fb7c..ab406808 100644 --- a/Benchmarks/Dss/End/Fix.lean +++ b/Benchmarks/Dss/End/Fix.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Flow.lean b/Benchmarks/Dss/End/Flow.lean index fe718838..a83fba6c 100644 --- a/Benchmarks/Dss/End/Flow.lean +++ b/Benchmarks/Dss/End/Flow.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.End.Pack import Benchmarks.Dss.End.Cash import Benchmarks.Dss.End.Thaw -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 @@ -4015,7 +4015,7 @@ theorem endFlowBodyReverts_vatIlksBlock {cA gh bl σ σ₀ A I} {g : UInt256} .letDecl "fixV" (some uint256) (.binary .div (.var "num") (.var "den")), .assign .storage (fixRef (.var "ilk")) (.var "fixV") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1), .internalCall "rmul" [.storage (ArtRef (.var "ilk")), .var "rate"] "wad0", @@ -4206,7 +4206,7 @@ theorem endFlowBodyReverts_vatIlksOkTailReverted {cA gh bl σ σ₀ A I} {g : UI have hblock : ExecBlock config { contract := contract, locals := endFlowStore I } evm0 flowTransition.body .reverted := by - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1), .internalCall "rmul" [.storage (ArtRef (.var "ilk")), .var "rate"] "wad0", @@ -4264,7 +4264,7 @@ theorem endFlowBodyReturns_vatIlksOkTail {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endFlowStore I } evm0 flowTransition.body (.ok fPost evmPost) := by - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1), .internalCall "rmul" [.storage (ArtRef (.var "ilk")), .var "rate"] "wad0", @@ -4336,7 +4336,7 @@ theorem endFlowBodyReturns {cA gh bl σ σ₀ A I} {g : UInt256} flowTransition.body (.ok { contract := contract, locals := endFlowStoreFixV σ I out } (endFlowPostState evmVat I (endFlowFixVWord σ I out))) := by - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1), .internalCall "rmul" [.storage (ArtRef (.var "ilk")), .var "rate"] "wad0", diff --git a/Benchmarks/Dss/End/Free.lean b/Benchmarks/Dss/End/Free.lean index ef2ebbde..88a77cb3 100644 --- a/Benchmarks/Dss/End/Free.lean +++ b/Benchmarks/Dss/End/Free.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.End.Pack import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 @@ -1364,7 +1364,7 @@ theorem endFreeBodyReverts_urnsNoCode {cA gh bl σ σ₀ A I} {g : UInt256} have hurnsWithTail : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 (endFreeUrnsCallStmts ++ endFreeAfterUrnsStmts) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := endFreeAfterUrnsStmts) hurnsBlock (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 @@ -1438,7 +1438,7 @@ theorem endFreeBodyReverts_urnsCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} have hurnsWithTail : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 (endFreeUrnsCallStmts ++ endFreeAfterUrnsStmts) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := endFreeAfterUrnsStmts) hurnsBlock (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 @@ -1514,7 +1514,7 @@ theorem endFreeBodyReverts_urnsDecodeShort {cA gh bl σ σ₀ A I} {g : UInt256} have hurnsWithTail : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 (endFreeUrnsCallStmts ++ endFreeAfterUrnsStmts) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := endFreeAfterUrnsStmts) hurnsBlock (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 @@ -2121,7 +2121,7 @@ theorem endFreeBodyReverts_artNonzero {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 freeTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append + have hseq :=.execBlock_append (s2 := endFreeAfterUrnsStmts) hprefix htail simpa [freeTransition, nonpayable, endFreeUrnsCallStmts, endFreeAfterUrnsStmts, checkedExternalCallStmts, List.cons_append, List.nil_append, List.append_assoc] using hseq @@ -2160,7 +2160,7 @@ theorem endFreeBodyReverts_inkOverflow {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 freeTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append + have hseq :=.execBlock_append (s2 := endFreeAfterUrnsStmts) hprefix htail simpa [freeTransition, nonpayable, endFreeUrnsCallStmts, endFreeAfterUrnsStmts, checkedExternalCallStmts, List.cons_append, List.nil_append, List.append_assoc] using hseq @@ -2204,7 +2204,7 @@ theorem endFreeBodyReverts_grabNoCode {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 freeTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append + have hseq :=.execBlock_append (s2 := endFreeAfterUrnsStmts) hprefix htail simpa [freeTransition, nonpayable, endFreeUrnsCallStmts, endFreeAfterUrnsStmts, checkedExternalCallStmts, List.cons_append, List.nil_append, List.append_assoc] using hseq @@ -2260,7 +2260,7 @@ theorem endFreeBodyReverts_grabCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 freeTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append + have hseq :=.execBlock_append (s2 := endFreeAfterUrnsStmts) hprefix htail simpa [freeTransition, nonpayable, endFreeUrnsCallStmts, endFreeAfterUrnsStmts, checkedExternalCallStmts, List.cons_append, List.nil_append, List.append_assoc] using hseq @@ -2318,7 +2318,7 @@ theorem endFreeBodyReturns_grabSuccess {cA gh bl σ σ₀ A I} {g : UInt256} ExecBlock config { contract := contract, locals := endFreeStore I } evm0 freeTransition.body (.ok { contract := contract, locals := endFreeStoreGrab I out } evmGrab) := by - have hseq := Reasoning.Refinement.execBlock_append + have hseq :=.execBlock_append (s2 := endFreeAfterUrnsStmts) hprefix htail simpa [freeTransition, nonpayable, endFreeUrnsCallStmts, endFreeAfterUrnsStmts, checkedExternalCallStmts, List.cons_append, List.nil_append, List.append_assoc] using hseq diff --git a/Benchmarks/Dss/End/Gap.lean b/Benchmarks/Dss/End/Gap.lean index bc91b928..eb821d31 100644 --- a/Benchmarks/Dss/End/Gap.lean +++ b/Benchmarks/Dss/End/Gap.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Live.lean b/Benchmarks/Dss/End/Live.lean index 9cbfcdbe..c5ff0641 100644 --- a/Benchmarks/Dss/End/Live.lean +++ b/Benchmarks/Dss/End/Live.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Out.lean b/Benchmarks/Dss/End/Out.lean index 463e9314..b7829951 100644 --- a/Benchmarks/Dss/End/Out.lean +++ b/Benchmarks/Dss/End/Out.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Pack.lean b/Benchmarks/Dss/End/Pack.lean index ca982244..3ce0133d 100644 --- a/Benchmarks/Dss/End/Pack.lean +++ b/Benchmarks/Dss/End/Pack.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.End.Dispatch import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 @@ -1977,7 +1977,7 @@ theorem endPackBodyReverts_moveNoCode {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "add" [.storage (bagRef sender), .var "wad"] "bagNew", .assign .storage (bagRef sender) (.var "bagNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .internalCall "add" [.storage (bagRef sender), .var "wad"] "bagNew", .assign .storage (bagRef sender) (.var "bagNew") ]) @@ -2127,7 +2127,7 @@ theorem endPackBodyReverts_moveCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "add" [.storage (bagRef sender), .var "wad"] "bagNew", .assign .storage (bagRef sender) (.var "bagNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .internalCall "add" [.storage (bagRef sender), .var "wad"] "bagNew", .assign .storage (bagRef sender) (.var "bagNew") ]) @@ -2333,7 +2333,7 @@ theorem endPackBodyReverts_bagAddOverflow {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endPackStore I } evm0 packTransition.body .reverted := by - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := [ .internalCall "add" [.storage (bagRef sender), .var "wad"] "bagNew", .assign .storage (bagRef sender) (.var "bagNew") ]) @@ -2394,7 +2394,7 @@ theorem endPackBodyReturns {cA gh bl σ σ₀ A I} {g : UInt256} packTransition.body (.ok { contract := contract, locals := endPackStoreBagNew I bagNew } (endPackPostState evmMove I bagNew)) := by - have happ := Reasoning.Refinement.execBlock_append + have happ :=.execBlock_append (s2 := [ .internalCall "add" [.storage (bagRef sender), .var "wad"] "bagNew", .assign .storage (bagRef sender) (.var "bagNew") ]) diff --git a/Benchmarks/Dss/End/PackBody.lean b/Benchmarks/Dss/End/PackBody.lean index f07ada33..db88c57a 100644 --- a/Benchmarks/Dss/End/PackBody.lean +++ b/Benchmarks/Dss/End/PackBody.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.End.Pack import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.End diff --git a/Benchmarks/Dss/End/Pot.lean b/Benchmarks/Dss/End/Pot.lean index d03251d3..728eac74 100644 --- a/Benchmarks/Dss/End/Pot.lean +++ b/Benchmarks/Dss/End/Pot.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Rely.lean b/Benchmarks/Dss/End/Rely.lean index 5329d5cc..a4ae4e7e 100644 --- a/Benchmarks/Dss/End/Rely.lean +++ b/Benchmarks/Dss/End/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Skim.lean b/Benchmarks/Dss/End/Skim.lean index af243078..b2459b32 100644 --- a/Benchmarks/Dss/End/Skim.lean +++ b/Benchmarks/Dss/End/Skim.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.End.Flow import Benchmarks.Dss.End.Free -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 @@ -6538,11 +6538,11 @@ theorem endSkimBodyReverts_afterArtTailReverted {I} {vatOut urnOut : ByteArray} (.binary .le (.var "wad") (.intLit int256Limit)) (.binary .le (.var "art") (.intLit int256Limit))) ] ++ grabTail) .reverted := by - exact Reasoning.Refinement.execBlock_append_term htail (by intro f' e' h; cases h) + exact.execBlock_append_term htail (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSkimStore I } evm0 skimTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append hprefixArt htailWithGrab + have hseq :=.execBlock_append hprefixArt htailWithGrab simpa [skimTransition, grabTail, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -6606,11 +6606,11 @@ theorem endSkimBodyReverts_afterArtTailGrabReverted {I σLoc} (.binary .le (.var "wad") (.intLit int256Limit)) (.binary .le (.var "art") (.intLit int256Limit))) ] ++ grabTail) .reverted := by - exact Reasoning.Refinement.execBlock_append htail hgrab + exact.execBlock_append htail hgrab have hblock : ExecBlock config { contract := contract, locals := endSkimStore I } evm0 skimTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append hprefixArt htailWithGrab + have hseq :=.execBlock_append hprefixArt htailWithGrab simpa [skimTransition, grabTail, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -6677,13 +6677,13 @@ theorem endSkimBodyReturns_afterArtTailGrabSuccess {I σLoc} (.binary .le (.var "art") (.intLit int256Limit))) ] ++ grabTail) (.ok { contract := contract, locals := endSkimStoreGrab σLoc I vatOut urnOut } evmGrab) := by - exact Reasoning.Refinement.execBlock_append htail hgrab + exact.execBlock_append htail hgrab have hblock : ExecBlock config { contract := contract, locals := endSkimStore I } evm0 skimTransition.body (.ok { contract := contract, locals := endSkimStoreGrab σLoc I vatOut urnOut } evmGrab) := by - have hseq := Reasoning.Refinement.execBlock_append hprefixArt htailWithGrab + have hseq :=.execBlock_append hprefixArt htailWithGrab simpa [skimTransition, grabTail, List.append_assoc] using hseq exact ExecFuncBody.execBlockOK hblock @@ -6737,7 +6737,7 @@ theorem endSkimBodyReverts_vatIlksBlock {cA gh bl σ σ₀ A I} {g : UInt256} .unary .neg (asInt256 (.var "wad")), .unary .neg (asInt256 (.var "art"))] "_grab") .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1) ] ++ checkedExternalCallStmts (.storage vatRef) "urns" (.intLit 0) @@ -6887,7 +6887,7 @@ theorem endSkimPrefixRateSuccess {cA gh bl σ σ₀ A I} {g : UInt256} "vatIlk" ++ [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1) ]) (.ok { contract := contract, locals := endSkimStoreRate I out } evmVat) := by - exact Reasoning.Refinement.execBlock_append hvat hrate + exact.execBlock_append hvat hrate simp only [nonpayable, List.cons_append, List.nil_append] refine ExecBlock.consNormal (ExecStmt.requireTrue ?_) ?_ · exact evalCallvalueEq_true (by simp [evm0, initState]; exact hwv) @@ -6930,12 +6930,12 @@ theorem endSkimBodyReverts_afterRateUrnsBlock {I} {vatOut : ByteArray} ExecBlock config { contract := contract, locals := endSkimStoreRate I vatOut } evmRate (checkedExternalCallStmts (.storage vatRef) "urns" (.intLit 0) [.var "ilk", .var "urn"] "vatUrn" ++ afterUrns) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := afterUrns) hurns (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSkimStore I } evm0 skimTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append hprefix hurnsWithTail + have hseq :=.execBlock_append hprefix hurnsWithTail simpa [skimTransition, afterUrns, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -7429,9 +7429,9 @@ theorem endSkimBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} locals := endSkimStoreArt I vatOut urnOut } evmUrnsSolm) := by have hurnsInkArt := - Reasoning.Refinement.execBlock_append hurnsBlock hinkArt + .execBlock_append hurnsBlock hinkArt simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append hprefix hurnsInkArt + .execBlock_append hprefix hurnsInkArt have hTagCoupleUrns : endSkimTagWord σ_urns I = endSkimTagWord σ_urns_solm I := by simpa [endSkimTagWord, endSlotWord] using diff --git a/Benchmarks/Dss/End/Skip.lean b/Benchmarks/Dss/End/Skip.lean index e99ff515..162470e6 100644 --- a/Benchmarks/Dss/End/Skip.lean +++ b/Benchmarks/Dss/End/Skip.lean @@ -3,7 +3,7 @@ import Benchmarks.Dss.End.Flow import Benchmarks.Dss.End.Free import Benchmarks.Dss.End.Snip -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 @@ -7620,7 +7620,7 @@ theorem endSkipBodyReverts_catIlksBlock {cA gh bl σ σ₀ A I} {g : UInt256} [.var "ilk", .var "usr", thisAddr, vowAddr, asInt256 (.var "lot"), asInt256 (.var "art")] "_grab") .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .letDecl "flip" (some addr) (.tupleGet (.var "catIlk") 0) ] ++ checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] @@ -7778,7 +7778,7 @@ theorem endSkipPrefixFlipSuccess {cA gh bl σ σ₀ A I} {g : UInt256} "catIlk" ++ [ .letDecl "flip" (some addr) (.tupleGet (.var "catIlk") 0) ]) (.ok { contract := contract, locals := endSkipStoreFlip I out } evmCat) := by - exact Reasoning.Refinement.execBlock_append hcat hflip + exact.execBlock_append hcat hflip simp only [nonpayable, List.cons_append, List.nil_append] refine ExecBlock.consNormal (ExecStmt.requireTrue ?_) ?_ · exact evalCallvalueEq_true (by simp [evm0, initState]; exact hwv) @@ -8031,8 +8031,8 @@ theorem endSkipPrefixRateSuccess {I} {catOut vatOut : ByteArray} [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1) ]) (.ok { contract := contract, locals := endSkipStoreRate I catOut vatOut } evmVat) := by - exact Reasoning.Refinement.execBlock_append hvat hrate - have hseq := Reasoning.Refinement.execBlock_append hprefix hvatRate + exact.execBlock_append hvat hrate + have hseq :=.execBlock_append hprefix hvatRate simpa [List.append_assoc] using hseq theorem endSkipBodyReverts_afterFlipVatIlksBlock {I} {catOut : ByteArray} @@ -8078,12 +8078,12 @@ theorem endSkipBodyReverts_afterFlipVatIlksBlock {I} {catOut : ByteArray} ExecBlock config { contract := contract, locals := endSkipStoreFlip I catOut } evmCat (checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] "vatIlk" ++ afterVat) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := afterVat) hvat (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSkipStore I } evm0 skipTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append hprefix hvatWithTail + have hseq :=.execBlock_append hprefix hvatWithTail simpa [skipTransition, afterVat, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -8512,8 +8512,8 @@ theorem endSkipPrefixTabSuccess {I} {catOut vatOut bidOut : ByteArray} .letDecl "tab" (some uint256) (.tupleGet (.var "flipBid") 7) ]) (.ok { contract := contract, locals := endSkipStoreTab I catOut vatOut bidOut } evmBids) := by - exact Reasoning.Refinement.execBlock_append hbids hlets - have hseq := Reasoning.Refinement.execBlock_append hprefix hbidsLets + exact.execBlock_append hbids hlets + have hseq :=.execBlock_append hprefix hbidsLets simpa [List.append_assoc] using hseq theorem endSkipBodyReverts_afterRateBidsBlock {I} {catOut vatOut : ByteArray} @@ -8561,12 +8561,12 @@ theorem endSkipBodyReverts_afterRateBidsBlock {I} {catOut vatOut : ByteArray} evmVat (checkedExternalCallStmts (.var "flip") "bids" (.intLit 0) [.var "id"] "flipBid" (perm := false) ++ afterBids) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := afterBids) hbids (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSkipStore I } evm0 skipTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append hprefix hbidsWithTail + have hseq :=.execBlock_append hprefix hbidsWithTail simpa [skipTransition, afterBids, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -9911,11 +9911,11 @@ theorem endSkipTailAfterTabReturns {I σLoc} (endSkipPostArtState evmYank I (endSkipArtNewWord σLoc I vatOut bidOut)) I σLoc catOut vatOut bidOut hlot hart)) ExecBlock.nil - have htail2 := Reasoning.Refinement.execBlock_append hsuck1 hsuck2 - have htail3 := Reasoning.Refinement.execBlock_append htail2 hhope - have htail4 := Reasoning.Refinement.execBlock_append htail3 hyank + have htail2 :=.execBlock_append hsuck1 hsuck2 + have htail3 :=.execBlock_append htail2 hhope + have htail4 :=.execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using - Reasoning.Refinement.execBlock_append htail4 hartBlock + .execBlock_append htail4 hartBlock theorem endSkipTailReverts_suck1 {I} {catOut vatOut bidOut : ByteArray} {evmTab : EVM.State} @@ -9925,7 +9925,7 @@ theorem endSkipTailReverts_suck1 {I} {catOut vatOut bidOut : ByteArray} ExecBlock config { contract := contract, locals := endSkipStoreTab I catOut vatOut bidOut } evmTab endSkipTailNoGrabStmts .reverted := by simpa [endSkipTailNoGrabStmts, List.append_assoc] using - Reasoning.Refinement.execBlock_append_term hsuck1 (by intro f' e' h; cases h) + .execBlock_append_term hsuck1 (by intro f' e' h; cases h) theorem endSkipTailReverts_suck2 {I} {catOut vatOut bidOut : ByteArray} {evmTab evmSuck1 : EVM.State} @@ -9947,11 +9947,11 @@ theorem endSkipTailReverts_suck2 {I} {catOut vatOut bidOut : ByteArray} (endSkipSuck2Stmts ++ endSkipHopeStmts ++ endSkipYankStmts ++ endSkipArtStmts) .reverted := by simpa [List.append_assoc] using - (Reasoning.Refinement.execBlock_append_term + (Reasoning.Theory.execBlock_append_term (s2 := endSkipHopeStmts ++ endSkipYankStmts ++ endSkipArtStmts) hsuck2 (by intro f' e' h; cases h)) simpa [endSkipTailNoGrabStmts, List.append_assoc] using - Reasoning.Refinement.execBlock_append hsuck1 hsuck2Tail + .execBlock_append hsuck1 hsuck2Tail theorem endSkipTailReverts_hope {I} {catOut vatOut bidOut : ByteArray} {evmTab evmSuck1 evmSuck2 : EVM.State} @@ -9978,12 +9978,12 @@ theorem endSkipTailReverts_hope {I} {catOut vatOut bidOut : ByteArray} evmSuck2 (endSkipHopeStmts ++ endSkipYankStmts ++ endSkipArtStmts) .reverted := by simpa [List.append_assoc] using - (Reasoning.Refinement.execBlock_append_term + (Reasoning.Theory.execBlock_append_term (s2 := endSkipYankStmts ++ endSkipArtStmts) hhope (by intro f' e' h; cases h)) - have htail2 := Reasoning.Refinement.execBlock_append hsuck1 hsuck2 + have htail2 :=.execBlock_append hsuck1 hsuck2 simpa [endSkipTailNoGrabStmts, List.append_assoc] using - Reasoning.Refinement.execBlock_append htail2 hhopeTail + .execBlock_append htail2 hhopeTail theorem endSkipTailReverts_yank {I} {catOut vatOut bidOut : ByteArray} {evmTab evmSuck1 evmSuck2 evmHope : EVM.State} @@ -10014,11 +10014,11 @@ theorem endSkipTailReverts_yank {I} {catOut vatOut bidOut : ByteArray} ExecBlock config { contract := contract, locals := endSkipStoreHope I catOut vatOut bidOut } evmHope (endSkipYankStmts ++ endSkipArtStmts) .reverted := by - exact Reasoning.Refinement.execBlock_append_term hyank (by intro f' e' h; cases h) - have htail2 := Reasoning.Refinement.execBlock_append hsuck1 hsuck2 - have htail3 := Reasoning.Refinement.execBlock_append htail2 hhope + exact.execBlock_append_term hyank (by intro f' e' h; cases h) + have htail2 :=.execBlock_append hsuck1 hsuck2 + have htail3 :=.execBlock_append htail2 hhope simpa [endSkipTailNoGrabStmts, List.append_assoc] using - Reasoning.Refinement.execBlock_append htail3 hyankTail + .execBlock_append htail3 hyankTail theorem endSkipTailReverts_artDivZero {I} {catOut vatOut bidOut : ByteArray} {evmTab evmSuck1 evmSuck2 evmHope evmYank : EVM.State} @@ -10052,11 +10052,11 @@ theorem endSkipTailReverts_artDivZero {I} {catOut vatOut bidOut : ByteArray} ExecBlock config { contract := contract, locals := endSkipStoreYank I catOut vatOut bidOut } evmYank endSkipArtStmts .reverted := ExecBlock.consRevert (endSkipStmtArtReverts evmYank I catOut vatOut bidOut hrate) - have htail2 := Reasoning.Refinement.execBlock_append hsuck1 hsuck2 - have htail3 := Reasoning.Refinement.execBlock_append htail2 hhope - have htail4 := Reasoning.Refinement.execBlock_append htail3 hyank + have htail2 :=.execBlock_append hsuck1 hsuck2 + have htail3 :=.execBlock_append htail2 hhope + have htail4 :=.execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using - Reasoning.Refinement.execBlock_append htail4 hartRevert + .execBlock_append htail4 hartRevert theorem endSkipTailReverts_artAddOverflow {I σLoc} {catOut vatOut bidOut : ByteArray} @@ -10100,11 +10100,11 @@ theorem endSkipTailReverts_artAddOverflow {I σLoc} refine ExecBlock.consNormal (endSkipStmtArt evmYank I catOut vatOut bidOut hrate) ?_ exact ExecBlock.consRevert (endSkipStmtArtNewAddReverts evmYank I σLoc catOut vatOut bidOut hsz68 hArtLoad hover) - have htail2 := Reasoning.Refinement.execBlock_append hsuck1 hsuck2 - have htail3 := Reasoning.Refinement.execBlock_append htail2 hhope - have htail4 := Reasoning.Refinement.execBlock_append htail3 hyank + have htail2 :=.execBlock_append hsuck1 hsuck2 + have htail3 :=.execBlock_append htail2 hhope + have htail4 :=.execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using - Reasoning.Refinement.execBlock_append htail4 hartBlock + .execBlock_append htail4 hartBlock theorem endSkipTailReverts_intGuardLot {I σLoc} {catOut vatOut bidOut : ByteArray} @@ -10156,11 +10156,11 @@ theorem endSkipTailReverts_intGuardLot {I σLoc} (endSkipEvalExpr_intGuard_false_lot (endSkipPostArtState evmYank I (endSkipArtNewWord σLoc I vatOut bidOut)) I σLoc catOut vatOut bidOut hlot)) - have htail2 := Reasoning.Refinement.execBlock_append hsuck1 hsuck2 - have htail3 := Reasoning.Refinement.execBlock_append htail2 hhope - have htail4 := Reasoning.Refinement.execBlock_append htail3 hyank + have htail2 :=.execBlock_append hsuck1 hsuck2 + have htail3 :=.execBlock_append htail2 hhope + have htail4 :=.execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using - Reasoning.Refinement.execBlock_append htail4 hartBlock + .execBlock_append htail4 hartBlock theorem endSkipTailReverts_intGuardArt {I σLoc} {catOut vatOut bidOut : ByteArray} @@ -10213,11 +10213,11 @@ theorem endSkipTailReverts_intGuardArt {I σLoc} (endSkipEvalExpr_intGuard_false_art (endSkipPostArtState evmYank I (endSkipArtNewWord σLoc I vatOut bidOut)) I σLoc catOut vatOut bidOut hlot hart)) - have htail2 := Reasoning.Refinement.execBlock_append hsuck1 hsuck2 - have htail3 := Reasoning.Refinement.execBlock_append htail2 hhope - have htail4 := Reasoning.Refinement.execBlock_append htail3 hyank + have htail2 :=.execBlock_append hsuck1 hsuck2 + have htail3 :=.execBlock_append htail2 hhope + have htail4 :=.execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using - Reasoning.Refinement.execBlock_append htail4 hartBlock + .execBlock_append htail4 hartBlock theorem endSkipBodyReverts_afterTabTailReverted {I} {catOut vatOut bidOut : ByteArray} {evm0 evmTab : EVM.State} @@ -10246,11 +10246,11 @@ theorem endSkipBodyReverts_afterTabTailReverted {I} {catOut vatOut bidOut : Byte have htailWithGrab : ExecBlock config { contract := contract, locals := endSkipStoreTab I catOut vatOut bidOut } evmTab (endSkipTailNoGrabStmts ++ endSkipGrabStmts) .reverted := by - exact Reasoning.Refinement.execBlock_append_term htail (by intro f' e' h; cases h) + exact.execBlock_append_term htail (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSkipStore I } evm0 skipTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append hprefixTab htailWithGrab + have hseq :=.execBlock_append hprefixTab htailWithGrab simpa [skipTransition, endSkipTailNoGrabStmts, endSkipGrabStmts, endSkipSuck1Stmts, endSkipSuck2Stmts, endSkipHopeStmts, endSkipYankStmts, endSkipArtStmts, List.append_assoc] using hseq @@ -10289,11 +10289,11 @@ theorem endSkipBodyReverts_afterTabTailGrabReverted {I σLoc} have htailWithGrab : ExecBlock config { contract := contract, locals := endSkipStoreTab I catOut vatOut bidOut } evmTab (endSkipTailNoGrabStmts ++ endSkipGrabStmts) .reverted := by - exact Reasoning.Refinement.execBlock_append htail hgrab + exact.execBlock_append htail hgrab have hblock : ExecBlock config { contract := contract, locals := endSkipStore I } evm0 skipTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append hprefixTab htailWithGrab + have hseq :=.execBlock_append hprefixTab htailWithGrab simpa [skipTransition, endSkipTailNoGrabStmts, endSkipGrabStmts, endSkipSuck1Stmts, endSkipSuck2Stmts, endSkipHopeStmts, endSkipYankStmts, endSkipArtStmts, List.append_assoc] using hseq @@ -10339,13 +10339,13 @@ theorem endSkipBodyReturns_afterTabTailGrabSuccess {I σLoc} evmTab (endSkipTailNoGrabStmts ++ endSkipGrabStmts) (.ok { contract := contract, locals := endSkipStoreGrab σLoc I catOut vatOut bidOut } evmGrab) := by - exact Reasoning.Refinement.execBlock_append htail hgrab + exact.execBlock_append htail hgrab have hblock : ExecBlock config { contract := contract, locals := endSkipStore I } evm0 skipTransition.body (.ok { contract := contract, locals := endSkipStoreGrab σLoc I catOut vatOut bidOut } evmGrab) := by - have hseq := Reasoning.Refinement.execBlock_append hprefixTab htailWithGrab + have hseq :=.execBlock_append hprefixTab htailWithGrab simpa [skipTransition, endSkipTailNoGrabStmts, endSkipGrabStmts, endSkipSuck1Stmts, endSkipSuck2Stmts, endSkipHopeStmts, endSkipYankStmts, endSkipArtStmts, List.append_assoc] using hseq diff --git a/Benchmarks/Dss/End/Snip.lean b/Benchmarks/Dss/End/Snip.lean index 333da08f..6584f471 100644 --- a/Benchmarks/Dss/End/Snip.lean +++ b/Benchmarks/Dss/End/Snip.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.End.Dispatch import Benchmarks.Dss.End.Flow import Benchmarks.Dss.End.Free -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 @@ -6311,7 +6311,7 @@ theorem endSnipBodyReverts_dogIlksBlock {cA gh bl σ σ₀ A I} {g : UInt256} [.var "ilk", .var "usr", thisAddr, vowAddr, asInt256 (.var "lot"), asInt256 (.var "art")] "_grab") .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .letDecl "clip" (some addr) (.tupleGet (.var "dogIlk") 0) ] ++ checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] @@ -6464,7 +6464,7 @@ theorem endSnipPrefixClipSuccess {cA gh bl σ σ₀ A I} {g : UInt256} "dogIlk" ++ [ .letDecl "clip" (some addr) (.tupleGet (.var "dogIlk") 0) ]) (.ok { contract := contract, locals := endSnipStoreClip I out } evmDog) := by - exact Reasoning.Refinement.execBlock_append hdog hclip + exact.execBlock_append hdog hclip simp only [nonpayable, List.cons_append, List.nil_append] refine ExecBlock.consNormal (ExecStmt.requireTrue ?_) ?_ · exact evalCallvalueEq_true (by simp [evm0, initState]; exact hwv) @@ -6715,8 +6715,8 @@ theorem endSnipPrefixRateSuccess {I} {dogOut vatOut : ByteArray} "vatIlk" ++ [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1) ]) (.ok { contract := contract, locals := endSnipStoreRate I dogOut vatOut } evmVat) := by - exact Reasoning.Refinement.execBlock_append hvat hrate - have hseq := Reasoning.Refinement.execBlock_append hprefix hvatRate + exact.execBlock_append hvat hrate + have hseq :=.execBlock_append hprefix hvatRate simpa [List.append_assoc] using hseq theorem endSnipBodyReverts_afterClipVatIlksBlock {I} {dogOut : ByteArray} @@ -6758,12 +6758,12 @@ theorem endSnipBodyReverts_afterClipVatIlksBlock {I} {dogOut : ByteArray} ExecBlock config { contract := contract, locals := endSnipStoreClip I dogOut } evmDog (checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] "vatIlk" ++ afterVat) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := afterVat) hvat (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSnipStore I } evm0 snipTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append hprefix hvatWithTail + have hseq :=.execBlock_append hprefix hvatWithTail simpa [snipTransition, afterVat, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -7146,8 +7146,8 @@ theorem endSnipPrefixUsrSuccess {I} {dogOut vatOut saleOut : ByteArray} .letDecl "usr" (some addr) (.tupleGet (.var "clipSale") 3) ] (.ok { contract := contract, locals := endSnipStoreUsr I dogOut vatOut saleOut } evmSales) := by - exact Reasoning.Refinement.execBlock_append htab - (Reasoning.Refinement.execBlock_append hlot husr) + exact.execBlock_append htab + (Reasoning.Theory.execBlock_append hlot husr) have hsalesTail : ExecBlock config { contract := contract, locals := endSnipStoreRate I dogOut vatOut } evmVat @@ -7158,8 +7158,8 @@ theorem endSnipPrefixUsrSuccess {I} {dogOut vatOut saleOut : ByteArray} .letDecl "usr" (some addr) (.tupleGet (.var "clipSale") 3) ]) (.ok { contract := contract, locals := endSnipStoreUsr I dogOut vatOut saleOut } evmSales) := by - exact Reasoning.Refinement.execBlock_append hsales htail - have hseq := Reasoning.Refinement.execBlock_append hprefix hsalesTail + exact.execBlock_append hsales htail + have hseq :=.execBlock_append hprefix hsalesTail simpa [List.append_assoc] using hseq theorem endSnipVatReceiver_afterUsr {σ I dogOut vatOut saleOut evm} @@ -8191,8 +8191,8 @@ theorem endSnipTailAfterUsrReturns {I σLoc} I σLoc dogOut vatOut saleOut hlot hart)) ExecBlock.nil simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append hsuck - (Reasoning.Refinement.execBlock_append hyank hartBlock) + .execBlock_append hsuck + (Reasoning.Theory.execBlock_append hyank hartBlock) theorem endSnipTailReverts_suck {I} {dogOut vatOut saleOut : ByteArray} {evmUsr : EVM.State} @@ -8216,7 +8216,7 @@ theorem endSnipTailReverts_suck {I} {dogOut vatOut saleOut : ByteArray} (.binary .lt (.var "art") (.intLit int256Limit))) ]) .reverted := by simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append_term hsuck (by intro f' e' h; cases h) + .execBlock_append_term hsuck (by intro f' e' h; cases h) theorem endSnipTailReverts_yank {I} {dogOut vatOut saleOut : ByteArray} {evmUsr evmSuck : EVM.State} @@ -8257,9 +8257,9 @@ theorem endSnipTailReverts_yank {I} {dogOut vatOut saleOut : ByteArray} (.binary .lt (.var "lot") (.intLit int256Limit)) (.binary .lt (.var "art") (.intLit int256Limit))) ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term hyank (by intro f' e' h; cases h) + exact.execBlock_append_term hyank (by intro f' e' h; cases h) simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append hsuck hyankTail + .execBlock_append hsuck hyankTail theorem endSnipTailReverts_artDivZero {I} {dogOut vatOut saleOut : ByteArray} {evmUsr evmSuck evmYank : EVM.State} @@ -8303,8 +8303,8 @@ theorem endSnipTailReverts_artDivZero {I} {dogOut vatOut saleOut : ByteArray} .reverted := ExecBlock.consRevert (endSnipStmtArtReverts evmYank I dogOut vatOut saleOut hrate) simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append hsuck - (Reasoning.Refinement.execBlock_append hyank hartRevert) + .execBlock_append hsuck + (Reasoning.Theory.execBlock_append hyank hartRevert) theorem endSnipTailReverts_artAddOverflow {I σLoc} {dogOut vatOut saleOut : ByteArray} {evmUsr evmSuck evmYank : EVM.State} @@ -8357,8 +8357,8 @@ theorem endSnipTailReverts_artAddOverflow {I σLoc} exact ExecBlock.consRevert (endSnipStmtArtNewAddReverts evmYank I σLoc dogOut vatOut saleOut hsz68 hArtLoad hover) simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append hsuck - (Reasoning.Refinement.execBlock_append hyank hartBlock) + .execBlock_append hsuck + (Reasoning.Theory.execBlock_append hyank hartBlock) theorem endSnipTailReverts_intGuardLot {I σLoc} {dogOut vatOut saleOut : ByteArray} {evmUsr evmSuck evmYank : EVM.State} @@ -8419,8 +8419,8 @@ theorem endSnipTailReverts_intGuardLot {I σLoc} (endSnipPostArtState evmYank I (endSnipArtNewWord σLoc I vatOut saleOut)) I σLoc dogOut vatOut saleOut hlot)) simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append hsuck - (Reasoning.Refinement.execBlock_append hyank hartBlock) + .execBlock_append hsuck + (Reasoning.Theory.execBlock_append hyank hartBlock) theorem endSnipTailReverts_intGuardArt {I σLoc} {dogOut vatOut saleOut : ByteArray} {evmUsr evmSuck evmYank : EVM.State} @@ -8482,8 +8482,8 @@ theorem endSnipTailReverts_intGuardArt {I σLoc} (endSnipPostArtState evmYank I (endSnipArtNewWord σLoc I vatOut saleOut)) I σLoc dogOut vatOut saleOut hlot hart)) simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append hsuck - (Reasoning.Refinement.execBlock_append hyank hartBlock) + .execBlock_append hsuck + (Reasoning.Theory.execBlock_append hyank hartBlock) theorem endSnipBodyReverts_afterUsrTailReverted {I} {dogOut vatOut saleOut : ByteArray} {evm0 evmUsr : EVM.State} @@ -8537,11 +8537,11 @@ theorem endSnipBodyReverts_afterUsrTailReverted {I} {dogOut vatOut saleOut : Byt (.binary .lt (.var "lot") (.intLit int256Limit)) (.binary .lt (.var "art") (.intLit int256Limit))) ] ++ grabTail) .reverted := by - exact Reasoning.Refinement.execBlock_append_term htail (by intro f' e' h; cases h) + exact.execBlock_append_term htail (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSnipStore I } evm0 snipTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append hprefixUsr htailWithGrab + have hseq :=.execBlock_append hprefixUsr htailWithGrab simpa [snipTransition, grabTail, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -8606,11 +8606,11 @@ theorem endSnipBodyReverts_afterUsrTailGrabReverted {I σLoc} (.binary .lt (.var "lot") (.intLit int256Limit)) (.binary .lt (.var "art") (.intLit int256Limit))) ] ++ grabTail) .reverted := by - exact Reasoning.Refinement.execBlock_append htail hgrab + exact.execBlock_append htail hgrab have hblock : ExecBlock config { contract := contract, locals := endSnipStore I } evm0 snipTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append hprefixUsr htailWithGrab + have hseq :=.execBlock_append hprefixUsr htailWithGrab simpa [snipTransition, grabTail, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -8679,13 +8679,13 @@ theorem endSnipBodyReturns_afterUsrTailGrabSuccess {I σLoc} (.binary .lt (.var "art") (.intLit int256Limit))) ] ++ grabTail) (.ok { contract := contract, locals := endSnipStoreGrab σLoc I dogOut vatOut saleOut } evmGrab) := by - exact Reasoning.Refinement.execBlock_append htail hgrab + exact.execBlock_append htail hgrab have hblock : ExecBlock config { contract := contract, locals := endSnipStore I } evm0 snipTransition.body (.ok { contract := contract, locals := endSnipStoreGrab σLoc I dogOut vatOut saleOut } evmGrab) := by - have hseq := Reasoning.Refinement.execBlock_append hprefixUsr htailWithGrab + have hseq :=.execBlock_append hprefixUsr htailWithGrab simpa [snipTransition, grabTail, List.append_assoc] using hseq exact ExecFuncBody.execBlockOK hblock @@ -8730,12 +8730,12 @@ theorem endSnipBodyReverts_afterRateSalesBlock {I} {dogOut vatOut : ByteArray} evmVat (checkedExternalCallStmts (.var "clip") "sales" (.intLit 0) [.var "id"] "clipSale" (perm := false) ++ afterSales) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := afterSales) hsales (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSnipStore I } evm0 snipTransition.body .reverted := by - have hseq := Reasoning.Refinement.execBlock_append hprefix hsalesWithTail + have hseq :=.execBlock_append hprefix hsalesWithTail simpa [snipTransition, afterSales, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock diff --git a/Benchmarks/Dss/End/Spot.lean b/Benchmarks/Dss/End/Spot.lean index 78b6231e..654d2187 100644 --- a/Benchmarks/Dss/End/Spot.lean +++ b/Benchmarks/Dss/End/Spot.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Tag.lean b/Benchmarks/Dss/End/Tag.lean index d6017752..1b0a12fb 100644 --- a/Benchmarks/Dss/End/Tag.lean +++ b/Benchmarks/Dss/End/Tag.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Thaw.lean b/Benchmarks/Dss/End/Thaw.lean index 4f0d8f0b..e862c402 100644 --- a/Benchmarks/Dss/End/Thaw.lean +++ b/Benchmarks/Dss/End/Thaw.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 @@ -3103,7 +3103,7 @@ theorem endThawBodyReverts_daiNoCode {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .require (.binary .eq (.var "vatDai") (.intLit 0)), .internalCall "add" [.storage whenRef, .storage waitRef] "deadline", @@ -3247,7 +3247,7 @@ theorem endThawBodyReverts_daiCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .require (.binary .eq (.var "vatDai") (.intLit 0)), .internalCall "add" [.storage whenRef, .storage waitRef] "deadline", @@ -3350,7 +3350,7 @@ theorem endThawBodyReverts_daiBlockReverted {cA gh bl σ σ₀ A I} {g : UInt256 [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .require (.binary .eq (.var "vatDai") (.intLit 0)), .internalCall "add" [.storage whenRef, .storage waitRef] "deadline", @@ -3525,7 +3525,7 @@ theorem endThawBodyReverts_daiOkTailReverted {cA gh bl σ σ₀ A I} {g : UInt25 [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append + exact.execBlock_append (s2 := [ .require (.binary .eq (.var "vatDai") (.intLit 0)), .internalCall "add" [.storage whenRef, .storage waitRef] "deadline", @@ -3636,7 +3636,7 @@ theorem endThawBodyReverts_daiNonzero {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .internalCall "add" [.storage whenRef, .storage waitRef] "deadline", .require (.binary .ge nowT (.var "deadline")) ] ++ @@ -3788,7 +3788,7 @@ theorem endThawBodyReverts_deadlineAddOverflow {cA gh bl σ σ₀ A I} {g : UInt [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .require (.binary .ge nowT (.var "deadline")) ] ++ checkedExternalCallStmts (.storage vatRef) "debt" (.intLit 0) [] "vatDebt" ++ @@ -3967,7 +3967,7 @@ theorem endThawBodyReverts_waitNotFinished {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := checkedExternalCallStmts (.storage vatRef) "debt" (.intLit 0) [] "vatDebt" ++ checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" @@ -4695,7 +4695,7 @@ theorem endThawBodyReturns_daiOkTail {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) (.ok fPost evmPost) := by - exact Reasoning.Refinement.execBlock_append + exact.execBlock_append (s2 := [ .require (.binary .eq (.var "vatDai") (.intLit 0)), .internalCall "add" [.storage whenRef, .storage waitRef] "deadline", @@ -4901,14 +4901,14 @@ theorem endThawReadyTailRevertsAtDebt (evmDai : EVM.State) (out : ByteArray) [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" (perm := false) ++ [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) hdebt (by intro f' e' h; cases h) - exact Reasoning.Refinement.execBlock_append + exact.execBlock_append (s2 := checkedExternalCallStmts (.storage vatRef) "debt" (.intLit 0) [] "vatDebt" ++ checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" @@ -4964,14 +4964,14 @@ theorem endThawReadyTailRevertsAfterDebt (evmDai evmDebt : EVM.State) [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append + exact.execBlock_append (s2 := checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" (perm := false) ++ [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) hdebt htellTail - exact Reasoning.Refinement.execBlock_append + exact.execBlock_append (s2 := checkedExternalCallStmts (.storage vatRef) "debt" (.intLit 0) [] "vatDebt" ++ checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" @@ -5031,7 +5031,7 @@ theorem endThawReadyTailReturnsAfterDebt (evmDai evmDebt evmTell : EVM.State) .assign .storage debtRef (.var "debtNew") ]) (.ok { contract := contract, locals := postLocals } (endThawPostState evmTell debtNew)) := by - exact Reasoning.Refinement.execBlock_append + exact.execBlock_append (s2 := [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) @@ -5046,14 +5046,14 @@ theorem endThawReadyTailReturnsAfterDebt (evmDai evmDebt evmTell : EVM.State) .assign .storage debtRef (.var "debtNew") ]) (.ok { contract := contract, locals := postLocals } (endThawPostState evmTell debtNew)) := by - exact Reasoning.Refinement.execBlock_append + exact.execBlock_append (s2 := checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" (perm := false) ++ [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) hdebt hafterTell - exact Reasoning.Refinement.execBlock_append + exact.execBlock_append (s2 := checkedExternalCallStmts (.storage vatRef) "debt" (.intLit 0) [] "vatDebt" ++ checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" @@ -5642,7 +5642,7 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", @@ -5781,7 +5781,7 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", @@ -5863,7 +5863,7 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact Reasoning.Refinement.execBlock_append_term + exact.execBlock_append_term (s2 := [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", @@ -6071,7 +6071,7 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} .assign .storage debtRef (.var "debtNew") ]) .reverted := by exact - Reasoning.Refinement.execBlock_append + .execBlock_append (s2 := [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", diff --git a/Benchmarks/Dss/End/Vat.lean b/Benchmarks/Dss/End/Vat.lean index 3aacaa0f..ea244f56 100644 --- a/Benchmarks/Dss/End/Vat.lean +++ b/Benchmarks/Dss/End/Vat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Vow.lean b/Benchmarks/Dss/End/Vow.lean index 2bb6ddc2..01e65420 100644 --- a/Benchmarks/Dss/End/Vow.lean +++ b/Benchmarks/Dss/End/Vow.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Wait.lean b/Benchmarks/Dss/End/Wait.lean index 431e3376..0260dd5f 100644 --- a/Benchmarks/Dss/End/Wait.lean +++ b/Benchmarks/Dss/End/Wait.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/Wards.lean b/Benchmarks/Dss/End/Wards.lean index 43ed4ded..8e45d3f2 100644 --- a/Benchmarks/Dss/End/Wards.lean +++ b/Benchmarks/Dss/End/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/End/When.lean b/Benchmarks/Dss/End/When.lean index a8da12f0..75b78805 100644 --- a/Benchmarks/Dss/End/When.lean +++ b/Benchmarks/Dss/End/When.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.End.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/ExponentialDecrease/Common.lean b/Benchmarks/Dss/ExponentialDecrease/Common.lean index 80b1f334..80b9928a 100644 --- a/Benchmarks/Dss/ExponentialDecrease/Common.lean +++ b/Benchmarks/Dss/ExponentialDecrease/Common.lean @@ -7,7 +7,6 @@ import Reasoning.Solc import Reasoning.Memory import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -17,7 +16,7 @@ import Mathlib.Tactic.IntervalCases Contract-wide selector notation and constants for the optimized runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/ExponentialDecrease/Constructor.lean b/Benchmarks/Dss/ExponentialDecrease/Constructor.lean index 9992a7ed..714c3893 100644 --- a/Benchmarks/Dss/ExponentialDecrease/Constructor.lean +++ b/Benchmarks/Dss/ExponentialDecrease/Constructor.lean @@ -7,7 +7,7 @@ import Solm.Equiv # MakerDAO/Sky DSS ExponentialDecrease constructor correctness -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.ExponentialDecrease diff --git a/Benchmarks/Dss/ExponentialDecrease/Cut.lean b/Benchmarks/Dss/ExponentialDecrease/Cut.lean index bff7164a..3359e567 100644 --- a/Benchmarks/Dss/ExponentialDecrease/Cut.lean +++ b/Benchmarks/Dss/ExponentialDecrease/Cut.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.ExponentialDecrease.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.ExponentialDecrease diff --git a/Benchmarks/Dss/ExponentialDecrease/Deny.lean b/Benchmarks/Dss/ExponentialDecrease/Deny.lean index 8ee4cbd0..d4bb073a 100644 --- a/Benchmarks/Dss/ExponentialDecrease/Deny.lean +++ b/Benchmarks/Dss/ExponentialDecrease/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.ExponentialDecrease.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/ExponentialDecrease/Dispatch.lean b/Benchmarks/Dss/ExponentialDecrease/Dispatch.lean index 1371b294..86f595fa 100644 --- a/Benchmarks/Dss/ExponentialDecrease/Dispatch.lean +++ b/Benchmarks/Dss/ExponentialDecrease/Dispatch.lean @@ -6,7 +6,7 @@ import Benchmarks.Dss.ExponentialDecrease.Trusted Solm dispatch routing facts and shared dispatcher-level proof obligations. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/ExponentialDecrease/File.lean b/Benchmarks/Dss/ExponentialDecrease/File.lean index 63e2c437..407441cd 100644 --- a/Benchmarks/Dss/ExponentialDecrease/File.lean +++ b/Benchmarks/Dss/ExponentialDecrease/File.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.ExponentialDecrease.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/ExponentialDecrease/Price.lean b/Benchmarks/Dss/ExponentialDecrease/Price.lean index e080461e..56d2cc60 100644 --- a/Benchmarks/Dss/ExponentialDecrease/Price.lean +++ b/Benchmarks/Dss/ExponentialDecrease/Price.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.ExponentialDecrease.PriceSource -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/ExponentialDecrease/PriceSource.lean b/Benchmarks/Dss/ExponentialDecrease/PriceSource.lean index 00192705..4c1b741f 100644 --- a/Benchmarks/Dss/ExponentialDecrease/PriceSource.lean +++ b/Benchmarks/Dss/ExponentialDecrease/PriceSource.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.ExponentialDecrease.RpowEVM -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/ExponentialDecrease/Rely.lean b/Benchmarks/Dss/ExponentialDecrease/Rely.lean index 95a34d5a..b5c5b23a 100644 --- a/Benchmarks/Dss/ExponentialDecrease/Rely.lean +++ b/Benchmarks/Dss/ExponentialDecrease/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.ExponentialDecrease.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/ExponentialDecrease/RpowArithmeticExpr.lean b/Benchmarks/Dss/ExponentialDecrease/RpowArithmeticExpr.lean index 5d4a86dc..7278756c 100644 --- a/Benchmarks/Dss/ExponentialDecrease/RpowArithmeticExpr.lean +++ b/Benchmarks/Dss/ExponentialDecrease/RpowArithmeticExpr.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.ExponentialDecrease.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/ExponentialDecrease/RpowArithmeticLocals.lean b/Benchmarks/Dss/ExponentialDecrease/RpowArithmeticLocals.lean index 992f9c3e..7297b31c 100644 --- a/Benchmarks/Dss/ExponentialDecrease/RpowArithmeticLocals.lean +++ b/Benchmarks/Dss/ExponentialDecrease/RpowArithmeticLocals.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.ExponentialDecrease.RpowArithmeticExpr -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/ExponentialDecrease/RpowArithmeticLoop.lean b/Benchmarks/Dss/ExponentialDecrease/RpowArithmeticLoop.lean index bf94bddb..5359baf1 100644 --- a/Benchmarks/Dss/ExponentialDecrease/RpowArithmeticLoop.lean +++ b/Benchmarks/Dss/ExponentialDecrease/RpowArithmeticLoop.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.ExponentialDecrease.RpowArithmeticLocals -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/ExponentialDecrease/RpowEVM.lean b/Benchmarks/Dss/ExponentialDecrease/RpowEVM.lean index 2e9ac8d3..27547977 100644 --- a/Benchmarks/Dss/ExponentialDecrease/RpowEVM.lean +++ b/Benchmarks/Dss/ExponentialDecrease/RpowEVM.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.ExponentialDecrease.RpowSource -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/ExponentialDecrease/RpowSource.lean b/Benchmarks/Dss/ExponentialDecrease/RpowSource.lean index 2e09f646..c9ce8193 100644 --- a/Benchmarks/Dss/ExponentialDecrease/RpowSource.lean +++ b/Benchmarks/Dss/ExponentialDecrease/RpowSource.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.ExponentialDecrease.RpowArithmeticLoop -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.ExponentialDecrease diff --git a/Benchmarks/Dss/ExponentialDecrease/Wards.lean b/Benchmarks/Dss/ExponentialDecrease/Wards.lean index 9d8160dd..ff1f2c97 100644 --- a/Benchmarks/Dss/ExponentialDecrease/Wards.lean +++ b/Benchmarks/Dss/ExponentialDecrease/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.ExponentialDecrease.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.ExponentialDecrease diff --git a/Benchmarks/Dss/Flapper/Beg.lean b/Benchmarks/Dss/Flapper/Beg.lean index c7033f13..b2175f2f 100644 --- a/Benchmarks/Dss/Flapper/Beg.lean +++ b/Benchmarks/Dss/Flapper/Beg.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flapper diff --git a/Benchmarks/Dss/Flapper/Bids.lean b/Benchmarks/Dss/Flapper/Bids.lean index 085270f9..7ba5ed73 100644 --- a/Benchmarks/Dss/Flapper/Bids.lean +++ b/Benchmarks/Dss/Flapper/Bids.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flapper.Dispatch import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flapper/Cage.lean b/Benchmarks/Dss/Flapper/Cage.lean index f29e00ab..56aa51a8 100644 --- a/Benchmarks/Dss/Flapper/Cage.lean +++ b/Benchmarks/Dss/Flapper/Cage.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flapper.Deny import Benchmarks.Dss.Flopper.Dent.Part1 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flapper/Common.lean b/Benchmarks/Dss/Flapper/Common.lean index 4ab7767a..ebe8ee3e 100644 --- a/Benchmarks/Dss/Flapper/Common.lean +++ b/Benchmarks/Dss/Flapper/Common.lean @@ -6,7 +6,6 @@ import Reasoning.Reach import Reasoning.Solc import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -16,7 +15,7 @@ import Mathlib.Tactic.IntervalCases Contract-wide selector notation and constants for the optimized Flapper runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flapper/Correct.lean b/Benchmarks/Dss/Flapper/Correct.lean index 32d84b16..1f29f65e 100644 --- a/Benchmarks/Dss/Flapper/Correct.lean +++ b/Benchmarks/Dss/Flapper/Correct.lean @@ -29,7 +29,7 @@ are present. The runtime-equivalence proof is intentionally left as the benchmar also exposes the whole-contract wrapper that combines the constructor and runtime targets. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flapper diff --git a/Benchmarks/Dss/Flapper/Deal.lean b/Benchmarks/Dss/Flapper/Deal.lean index 791e1e16..78c9b45b 100644 --- a/Benchmarks/Dss/Flapper/Deal.lean +++ b/Benchmarks/Dss/Flapper/Deal.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Yank -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -1445,7 +1445,7 @@ theorem flapperDealBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) checkedExternalCallStmts (.storage gemRef) "burn" (.intLit 0) [thisAddr, .storage (bidsF (.var "id") "bid")] "_burnRet") .reverted := - Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h) + .execBlock_append_term hchecked (by intro f e h; cases h) have htail : ExecBlock config { contract := contract, locals := dealLotLocals evm I } evm ((checkedExternalCallStmts (.storage vatRef) "move" (.intLit 0) @@ -1456,7 +1456,7 @@ theorem flapperDealBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) .internalCall "sub" [.storage fillRef, .var "lot"] "fillNew", .assign .storage fillRef (.var "fillNew")]) .reverted := - Reasoning.Refinement.execBlock_append_term hmoveTail (by intro f e h; cases h) + .execBlock_append_term hmoveTail (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -1520,7 +1520,7 @@ theorem flapperDealBodyReverts_moveCallFailure checkedExternalCallStmts (.storage gemRef) "burn" (.intLit 0) [thisAddr, .storage (bidsF (.var "id") "bid")] "_burnRet") .reverted := - Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h) + .execBlock_append_term hchecked (by intro f e h; cases h) have htail : ExecBlock config { contract := contract, locals := dealLotLocals evm I } evm ((checkedExternalCallStmts (.storage vatRef) "move" (.intLit 0) @@ -1531,7 +1531,7 @@ theorem flapperDealBodyReverts_moveCallFailure .internalCall "sub" [.storage fillRef, .var "lot"] "fillNew", .assign .storage fillRef (.var "fillNew")]) .reverted := - Reasoning.Refinement.execBlock_append_term hmoveTail (by intro f e h; cases h) + .execBlock_append_term hmoveTail (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -1624,7 +1624,7 @@ theorem flapperDealBodyReverts_burnNoCode checkedExternalCallStmts (.storage gemRef) "burn" (.intLit 0) [thisAddr, .storage (bidsF (.var "id") "bid")] "_burnRet") .reverted := - Reasoning.Refinement.execBlock_append hmoveChecked hburnChecked + .execBlock_append hmoveChecked hburnChecked have htail : ExecBlock config { contract := contract, locals := dealLotLocals evm I } evm ((checkedExternalCallStmts (.storage vatRef) "move" (.intLit 0) @@ -1635,7 +1635,7 @@ theorem flapperDealBodyReverts_burnNoCode .internalCall "sub" [.storage fillRef, .var "lot"] "fillNew", .assign .storage fillRef (.var "fillNew")]) .reverted := - Reasoning.Refinement.execBlock_append_term hmoveTail (by intro f e h; cases h) + .execBlock_append_term hmoveTail (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -1737,7 +1737,7 @@ theorem flapperDealBodyReverts_burnCallFailure checkedExternalCallStmts (.storage gemRef) "burn" (.intLit 0) [thisAddr, .storage (bidsF (.var "id") "bid")] "_burnRet") .reverted := - Reasoning.Refinement.execBlock_append hmoveChecked hburnChecked + .execBlock_append hmoveChecked hburnChecked have htail : ExecBlock config { contract := contract, locals := dealLotLocals evm I } evm ((checkedExternalCallStmts (.storage vatRef) "move" (.intLit 0) @@ -1748,7 +1748,7 @@ theorem flapperDealBodyReverts_burnCallFailure .internalCall "sub" [.storage fillRef, .var "lot"] "fillNew", .assign .storage fillRef (.var "fillNew")]) .reverted := - Reasoning.Refinement.execBlock_append_term hmoveTail (by intro f e h; cases h) + .execBlock_append_term hmoveTail (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -1844,7 +1844,7 @@ theorem flapperDealBodyBurnSuccessPrefix simpa [checkedExternalCallStmts, dealBurnLocals] using checkedExternalCallSuccess hburnGuard hgem hburnArgs hburnCall (dealBurnDecode_ok outBurn) - exact Reasoning.Refinement.execBlock_append hmoveChecked hburnChecked + exact.execBlock_append hmoveChecked hburnChecked theorem flapperDealBodyReverts_fillSubUnderflow (evm evmMove evmBurn : EVM.State) (I : ExecutionEnv) @@ -1926,7 +1926,7 @@ theorem flapperDealBodyReverts_fillSubUnderflow .assign .storage fillRef (.var "fillNew")]) .reverted := by simpa [List.append_assoc] using - (Reasoning.Refinement.execBlock_append hprefix hdeleteSub) + (Reasoning.Theory.execBlock_append hprefix hdeleteSub) refine ExecFuncBody.execBlockRevert ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append, List.append_assoc] using @@ -2047,7 +2047,7 @@ theorem flapperDealBodyReturns_success (.ok { contract := contract, locals := dealFillNewLocals evm evmDelete I } evmFinal) := by simpa [List.append_assoc] using - (Reasoning.Refinement.execBlock_append hprefix hdeleteSubAssign) + (Reasoning.Theory.execBlock_append hprefix hdeleteSubAssign) refine ExecFuncBody.execBlockOK ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append, List.append_assoc, evmDelete, evmFinal, diff] using diff --git a/Benchmarks/Dss/Flapper/Deny.lean b/Benchmarks/Dss/Flapper/Deny.lean index 71d7eb28..8adce1f9 100644 --- a/Benchmarks/Dss/Flapper/Deny.lean +++ b/Benchmarks/Dss/Flapper/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flapper/Dispatch.lean b/Benchmarks/Dss/Flapper/Dispatch.lean index 9418efda..1cfdfbbb 100644 --- a/Benchmarks/Dss/Flapper/Dispatch.lean +++ b/Benchmarks/Dss/Flapper/Dispatch.lean @@ -6,7 +6,7 @@ import Benchmarks.Dss.Flapper.Trusted Solm dispatch routing facts and the shared dispatcher revert entry points. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flapper/File.lean b/Benchmarks/Dss/Flapper/File.lean index 67d42ee7..066189b0 100644 --- a/Benchmarks/Dss/Flapper/File.lean +++ b/Benchmarks/Dss/Flapper/File.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Deny -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flapper/Fill.lean b/Benchmarks/Dss/Flapper/Fill.lean index 69dd4e38..b3c76f5a 100644 --- a/Benchmarks/Dss/Flapper/Fill.lean +++ b/Benchmarks/Dss/Flapper/Fill.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flapper diff --git a/Benchmarks/Dss/Flapper/Gem.lean b/Benchmarks/Dss/Flapper/Gem.lean index 54b9ea0f..8c7c914c 100644 --- a/Benchmarks/Dss/Flapper/Gem.lean +++ b/Benchmarks/Dss/Flapper/Gem.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flapper diff --git a/Benchmarks/Dss/Flapper/Kick.lean b/Benchmarks/Dss/Flapper/Kick.lean index 708f333c..cc0d1411 100644 --- a/Benchmarks/Dss/Flapper/Kick.lean +++ b/Benchmarks/Dss/Flapper/Kick.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flapper.Tick import Benchmarks.Dss.Flopper.Kick.Part1 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 @@ -1528,7 +1528,7 @@ theorem flapperKickBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) [sender, thisAddr, .var "lot"] "_moveRet" ++ [.return [.var "id"]]) .reverted := - Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h) + .execBlock_append_term hchecked (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [kickTransition, nonpayable, auth, checkedAddUintInto, checkedAdd48Into, checkedExternalCallStmts, List.cons_append, List.nil_append, evmMove] using @@ -1642,7 +1642,7 @@ theorem flapperKickBodyReverts_moveCallFailure [sender, thisAddr, .var "lot"] "_moveRet" ++ [.return [.var "id"]]) .reverted := - Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h) + .execBlock_append_term hchecked (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [kickTransition, nonpayable, auth, checkedAddUintInto, checkedAdd48Into, checkedExternalCallStmts, List.cons_append, List.nil_append, evmMove] using @@ -1773,7 +1773,7 @@ theorem flapperKickBodyReturns_moveCallSuccess [.return [.var "id"]]) (.returned { contract := contract, locals := kickMoveLocals evm I } evm' (some [.int (Int.ofNat (kickIdWord evm).toNat)])) := - Reasoning.Refinement.execBlock_append hchecked hreturn + .execBlock_append hchecked hreturn refine ExecFuncBody.execBlockRet ?_ simpa [kickTransition, nonpayable, auth, checkedAddUintInto, checkedAdd48Into, checkedExternalCallStmts, List.cons_append, List.nil_append, evmMove] using diff --git a/Benchmarks/Dss/Flapper/Kicks.lean b/Benchmarks/Dss/Flapper/Kicks.lean index 18113d99..d52a9ed6 100644 --- a/Benchmarks/Dss/Flapper/Kicks.lean +++ b/Benchmarks/Dss/Flapper/Kicks.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flapper diff --git a/Benchmarks/Dss/Flapper/Lid.lean b/Benchmarks/Dss/Flapper/Lid.lean index 0ae8b3a9..ea55af18 100644 --- a/Benchmarks/Dss/Flapper/Lid.lean +++ b/Benchmarks/Dss/Flapper/Lid.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flapper diff --git a/Benchmarks/Dss/Flapper/Live.lean b/Benchmarks/Dss/Flapper/Live.lean index 668dc6fb..c7c926da 100644 --- a/Benchmarks/Dss/Flapper/Live.lean +++ b/Benchmarks/Dss/Flapper/Live.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flapper diff --git a/Benchmarks/Dss/Flapper/Rely.lean b/Benchmarks/Dss/Flapper/Rely.lean index 70e57eed..fb3bb7d3 100644 --- a/Benchmarks/Dss/Flapper/Rely.lean +++ b/Benchmarks/Dss/Flapper/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flapper/Tau.lean b/Benchmarks/Dss/Flapper/Tau.lean index d98b0a4f..e3f7c256 100644 --- a/Benchmarks/Dss/Flapper/Tau.lean +++ b/Benchmarks/Dss/Flapper/Tau.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flapper diff --git a/Benchmarks/Dss/Flapper/Tend.lean b/Benchmarks/Dss/Flapper/Tend.lean index 7c2b78ea..0ecc6f4b 100644 --- a/Benchmarks/Dss/Flapper/Tend.lean +++ b/Benchmarks/Dss/Flapper/Tend.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Kick -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -2099,7 +2099,7 @@ theorem flapperTendPaySuccessTail [.assign .storage (bidsF (.var "id") "bid") (.var "bid")]) (.ok { contract := contract, locals := tendPayRetLocals baseLocals } (tendAfterBidStore evmPay I)) := - Reasoning.Refinement.execBlock_append hpayChecked hbidAssign + .execBlock_append hpayChecked hbidAssign have hticExpr : evalExpr? config { contract := contract, locals := tendTicLocals baseLocals evmPay I } (tendAfterBidStore evmPay I) (.var "tic_") = @@ -2128,7 +2128,7 @@ theorem flapperTendPaySuccessTail (tendTicLocals_get_id evmPay I hid) (tendTicLocals_get_bids evmPay I hbids) haddFit)) ExecBlock.nil) - exact Reasoning.Refinement.execBlock_append hpayBidTail htick + exact.execBlock_append hpayBidTail htick set_option maxHeartbeats 1000000 in theorem flapperTendBodyReturns_success_callerEq @@ -2203,7 +2203,7 @@ theorem flapperTendBodyReturns_success_callerEq [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) (.ok { contract := contract, locals := tendTicLocals (tendBegBidLocals evm I) evmPay I } (tendPostState evmPay I)) := - Reasoning.Refinement.execBlock_append hskipRefund hpayTail + .execBlock_append hskipRefund hpayTail refine ExecFuncBody.execBlockOK ?_ simpa [tendTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append, List.append_assoc] using @@ -2305,7 +2305,7 @@ theorem flapperTendRefundSuccessPrefix [.assign .storage (bidsF (.var "id") "guy") sender]) (.ok { contract := contract, locals := tendRefundRetLocals evm I } (tendAfterGuyStore evmRefund I)) := - Reasoning.Refinement.execBlock_append hrefundChecked hassign + .execBlock_append hrefundChecked hassign exact ExecBlock.consNormal (ExecStmt.iteTrue hcallerCond hbranch) ExecBlock.nil set_option maxHeartbeats 1000000 in @@ -2399,7 +2399,7 @@ theorem flapperTendBodyReturns_success_callerNe [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) (.ok { contract := contract, locals := tendTicLocals (tendRefundRetLocals evm I) evmPay I } (tendPostState evmPay I)) := by - simpa [evmGuy] using Reasoning.Refinement.execBlock_append hrefundPrefix hpayTail + simpa [evmGuy] using.execBlock_append hrefundPrefix hpayTail refine ExecFuncBody.execBlockOK ?_ simpa [tendTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append, List.append_assoc] using @@ -2481,7 +2481,7 @@ theorem flapperTendRefundNoCodeTail .storage (bidsF (.var "id") "bid")] "_refundRet" ++ [.assign .storage (bidsF (.var "id") "guy") sender]) .reverted := - Reasoning.Refinement.execBlock_append_term hrefundChecked (by intro f e h; cases h) + .execBlock_append_term hrefundChecked (by intro f e h; cases h) have hite : ExecBlock config { contract := contract, locals := tendBegBidLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -2492,7 +2492,7 @@ theorem flapperTendRefundNoCodeTail []] .reverted := ExecBlock.consRevert (ExecStmt.iteTrue hcallerCond hthen) - exact Reasoning.Refinement.execBlock_append_term hite (by intro f e h; cases h) + exact.execBlock_append_term hite (by intro f e h; cases h) theorem flapperTendRefundCallFailureTail (evm evmRefund : EVM.State) (I : ExecutionEnv) (outRefund : ByteArray) @@ -2557,7 +2557,7 @@ theorem flapperTendRefundCallFailureTail .storage (bidsF (.var "id") "bid")] "_refundRet" ++ [.assign .storage (bidsF (.var "id") "guy") sender]) .reverted := - Reasoning.Refinement.execBlock_append_term hrefundChecked (by intro f e h; cases h) + .execBlock_append_term hrefundChecked (by intro f e h; cases h) have hite : ExecBlock config { contract := contract, locals := tendBegBidLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -2568,7 +2568,7 @@ theorem flapperTendRefundCallFailureTail []] .reverted := ExecBlock.consRevert (ExecStmt.iteTrue hcallerCond hthen) - exact Reasoning.Refinement.execBlock_append_term hite (by intro f e h; cases h) + exact.execBlock_append_term hite (by intro f e h; cases h) theorem flapperTendPayNoCodeTail (evm : EVM.State) (I : ExecutionEnv) (baseLocals : Store) @@ -2616,8 +2616,8 @@ theorem flapperTendPayNoCodeTail "_payRet" ++ [.assign .storage (bidsF (.var "id") "bid") (.var "bid")]) .reverted := - Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h) - exact Reasoning.Refinement.execBlock_append_term hpayBidTail + .execBlock_append_term hchecked (by intro f e h; cases h) + exact.execBlock_append_term hpayBidTail (by intro f e h; cases h) set_option maxHeartbeats 1000000 in @@ -2679,8 +2679,8 @@ theorem flapperTendPayCallFailureTail "_payRet" ++ [.assign .storage (bidsF (.var "id") "bid") (.var "bid")]) .reverted := - Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h) - exact Reasoning.Refinement.execBlock_append_term hpayBidTail + .execBlock_append_term hchecked (by intro f e h; cases h) + exact.execBlock_append_term hpayBidTail (by intro f e h; cases h) set_option maxHeartbeats 1000000 in @@ -2774,7 +2774,7 @@ theorem flapperTendPayAddOverflowTail [.assign .storage (bidsF (.var "id") "bid") (.var "bid")]) (.ok { contract := contract, locals := tendPayRetLocals baseLocals } (tendAfterBidStore evmPay I)) := - Reasoning.Refinement.execBlock_append hpayChecked hbidAssign + .execBlock_append hpayChecked hbidAssign have htickChecked : ExecBlock config { contract := contract, locals := tendPayRetLocals baseLocals } (tendAfterBidStore evmPay I) @@ -2794,8 +2794,8 @@ theorem flapperTendPayAddOverflowTail (checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]) .reverted := - Reasoning.Refinement.execBlock_append_term htickChecked (by intro f e h; cases h) - exact Reasoning.Refinement.execBlock_append hpayBidTail htickTail + .execBlock_append_term htickChecked (by intro f e h; cases h) + exact.execBlock_append hpayBidTail htickTail set_option maxHeartbeats 1000000 in theorem flapperTendBodyReverts_afterIncrease @@ -7878,7 +7878,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append hskipRefund hpayTail + .execBlock_append hskipRefund hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by @@ -7954,7 +7954,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append hskipRefund hpayTail + .execBlock_append hskipRefund hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by @@ -8086,7 +8086,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append hskipRefund hpayTail + .execBlock_append hskipRefund hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by @@ -8142,7 +8142,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append hskipRefund hpayTail + .execBlock_append hskipRefund hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by @@ -8373,7 +8373,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [evmGuySolm] using - Reasoning.Refinement.execBlock_append hprefix hpayTail + .execBlock_append hprefix hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by @@ -8562,7 +8562,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [evmGuySolm] using - Reasoning.Refinement.execBlock_append hprefix hpayTail + .execBlock_append hprefix hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by @@ -8613,7 +8613,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [evmGuySolm] using - Reasoning.Refinement.execBlock_append hprefix hpayTail + .execBlock_append hprefix hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by diff --git a/Benchmarks/Dss/Flapper/Tick.lean b/Benchmarks/Dss/Flapper/Tick.lean index 7d141466..46974b7d 100644 --- a/Benchmarks/Dss/Flapper/Tick.lean +++ b/Benchmarks/Dss/Flapper/Tick.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flapper.Yank import Benchmarks.Dss.Flopper.Tick.Part1 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flapper/Ttl.lean b/Benchmarks/Dss/Flapper/Ttl.lean index 44c3a4ed..b0dff180 100644 --- a/Benchmarks/Dss/Flapper/Ttl.lean +++ b/Benchmarks/Dss/Flapper/Ttl.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flapper diff --git a/Benchmarks/Dss/Flapper/Vat.lean b/Benchmarks/Dss/Flapper/Vat.lean index 79a13397..fbfc52c2 100644 --- a/Benchmarks/Dss/Flapper/Vat.lean +++ b/Benchmarks/Dss/Flapper/Vat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flapper diff --git a/Benchmarks/Dss/Flapper/Wards.lean b/Benchmarks/Dss/Flapper/Wards.lean index a178e4d3..38eb8e33 100644 --- a/Benchmarks/Dss/Flapper/Wards.lean +++ b/Benchmarks/Dss/Flapper/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flapper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flapper diff --git a/Benchmarks/Dss/Flapper/Yank.lean b/Benchmarks/Dss/Flapper/Yank.lean index 4c16f1a1..887c968d 100644 --- a/Benchmarks/Dss/Flapper/Yank.lean +++ b/Benchmarks/Dss/Flapper/Yank.lean @@ -3,7 +3,7 @@ import Benchmarks.Dss.Flapper.Cage import Benchmarks.Dss.Flopper.AuctionCommon import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -1266,7 +1266,7 @@ theorem flapperYankBodyReverts_moveCallFailure .storage (bidsF (.var "id") "bid")] "_moveRet" ++ [.delete (bidRef (.var "id"))]) .reverted := - Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h) + .execBlock_append_term hchecked (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [yankTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -1347,7 +1347,7 @@ theorem flapperYankBodyReturns_moveCallSuccess [.delete (bidRef (.var "id"))]) (.ok { contract := contract, locals := yankMoveLocals I } (yankDeletePostState evm' I)) := - Reasoning.Refinement.execBlock_append hchecked hdelete + .execBlock_append hchecked hdelete refine ExecFuncBody.execBlockOK ?_ simpa [yankTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using diff --git a/Benchmarks/Dss/Flipper/Beg.lean b/Benchmarks/Dss/Flipper/Beg.lean index 43029ac7..5d13f82a 100644 --- a/Benchmarks/Dss/Flipper/Beg.lean +++ b/Benchmarks/Dss/Flipper/Beg.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/BidAccess.lean b/Benchmarks/Dss/Flipper/BidAccess.lean index 39f461f2..f7c460d7 100644 --- a/Benchmarks/Dss/Flipper/BidAccess.lean +++ b/Benchmarks/Dss/Flipper/BidAccess.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.BidStorage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/BidDelete.lean b/Benchmarks/Dss/Flipper/BidDelete.lean index 3a18b37a..00ae2f01 100644 --- a/Benchmarks/Dss/Flipper/BidDelete.lean +++ b/Benchmarks/Dss/Flipper/BidDelete.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.BidAccess -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/BidStorage.lean b/Benchmarks/Dss/Flipper/BidStorage.lean index 1fe65d4d..ffe98e00 100644 --- a/Benchmarks/Dss/Flipper/BidStorage.lean +++ b/Benchmarks/Dss/Flipper/BidStorage.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/Bids.lean b/Benchmarks/Dss/Flipper/Bids.lean index 60a060ee..af9914af 100644 --- a/Benchmarks/Dss/Flipper/Bids.lean +++ b/Benchmarks/Dss/Flipper/Bids.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flipper.Dispatch import Benchmarks.Dss.Flipper.BidStorage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 800000 diff --git a/Benchmarks/Dss/Flipper/Cat.lean b/Benchmarks/Dss/Flipper/Cat.lean index df40e294..17e521ec 100644 --- a/Benchmarks/Dss/Flipper/Cat.lean +++ b/Benchmarks/Dss/Flipper/Cat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/CheckedMul.lean b/Benchmarks/Dss/Flipper/CheckedMul.lean index 4021c96d..79885409 100644 --- a/Benchmarks/Dss/Flipper/CheckedMul.lean +++ b/Benchmarks/Dss/Flipper/CheckedMul.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/Common.lean b/Benchmarks/Dss/Flipper/Common.lean index 2cb3f12f..1bcf1974 100644 --- a/Benchmarks/Dss/Flipper/Common.lean +++ b/Benchmarks/Dss/Flipper/Common.lean @@ -7,7 +7,6 @@ import Reasoning.Solc import Reasoning.Memory import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases import Solm.Equiv @@ -18,7 +17,7 @@ import Solm.Equiv Contract-wide selector notation and constants for the optimized Flipper runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flipper/CommonRoutines.lean b/Benchmarks/Dss/Flipper/CommonRoutines.lean index f2a971e1..ded1feab 100644 --- a/Benchmarks/Dss/Flipper/CommonRoutines.lean +++ b/Benchmarks/Dss/Flipper/CommonRoutines.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/Correct.lean b/Benchmarks/Dss/Flipper/Correct.lean index b49c3996..df7e8a77 100644 --- a/Benchmarks/Dss/Flipper/Correct.lean +++ b/Benchmarks/Dss/Flipper/Correct.lean @@ -28,7 +28,7 @@ are present. The runtime-equivalence proof is intentionally left as the benchmar also exposes the whole-contract wrapper that combines the constructor and runtime targets. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flipper/Deal.lean b/Benchmarks/Dss/Flipper/Deal.lean index 4b2011fd..bb6ecaa3 100644 --- a/Benchmarks/Dss/Flipper/Deal.lean +++ b/Benchmarks/Dss/Flipper/Deal.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Flipper.ExternalCallTransport import Benchmarks.Dss.Flipper.DealTicEVM import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/DealEVM.lean b/Benchmarks/Dss/Flipper/DealEVM.lean index 421c376c..ea35e621 100644 --- a/Benchmarks/Dss/Flipper/DealEVM.lean +++ b/Benchmarks/Dss/Flipper/DealEVM.lean @@ -3,7 +3,7 @@ import Reasoning.ExternalCall import Reasoning.MemCascade import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/DealSource.lean b/Benchmarks/Dss/Flipper/DealSource.lean index 21d813b2..a4ba5ad2 100644 --- a/Benchmarks/Dss/Flipper/DealSource.lean +++ b/Benchmarks/Dss/Flipper/DealSource.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flipper.BidDelete import Benchmarks.Dss.Flipper.ExternalTargets -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/DealTicEVM.lean b/Benchmarks/Dss/Flipper/DealTicEVM.lean index 4d81c708..041d6f09 100644 --- a/Benchmarks/Dss/Flipper/DealTicEVM.lean +++ b/Benchmarks/Dss/Flipper/DealTicEVM.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.DealEVM -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/Dent.lean b/Benchmarks/Dss/Flipper/Dent.lean index e7c28b21..25992866 100644 --- a/Benchmarks/Dss/Flipper/Dent.lean +++ b/Benchmarks/Dss/Flipper/Dent.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Flipper.Dispatch import Benchmarks.Dss.Flipper.BidAccess import Benchmarks.Dss.Flipper.ErrorStringFull -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/DentBody.lean b/Benchmarks/Dss/Flipper/DentBody.lean index b45c1e7e..1adce423 100644 --- a/Benchmarks/Dss/Flipper/DentBody.lean +++ b/Benchmarks/Dss/Flipper/DentBody.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.DentBodyBranch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/DentBodyBranch.lean b/Benchmarks/Dss/Flipper/DentBodyBranch.lean index 70fc6424..d940ded1 100644 --- a/Benchmarks/Dss/Flipper/DentBodyBranch.lean +++ b/Benchmarks/Dss/Flipper/DentBodyBranch.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.DentRefundMain -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/DentDecreaseGuard.lean b/Benchmarks/Dss/Flipper/DentDecreaseGuard.lean index 627a56fb..6d25c2d2 100644 --- a/Benchmarks/Dss/Flipper/DentDecreaseGuard.lean +++ b/Benchmarks/Dss/Flipper/DentDecreaseGuard.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flipper.DentLotGuard import Benchmarks.Dss.Flipper.CheckedMul -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/DentLotGuard.lean b/Benchmarks/Dss/Flipper/DentLotGuard.lean index c669a9b0..2cbf6269 100644 --- a/Benchmarks/Dss/Flipper/DentLotGuard.lean +++ b/Benchmarks/Dss/Flipper/DentLotGuard.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Dent -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/DentRefund.lean b/Benchmarks/Dss/Flipper/DentRefund.lean index 9bd260f6..7d080de1 100644 --- a/Benchmarks/Dss/Flipper/DentRefund.lean +++ b/Benchmarks/Dss/Flipper/DentRefund.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.DentSameCaller -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/DentRefundEVM.lean b/Benchmarks/Dss/Flipper/DentRefundEVM.lean index 79df7ec8..ef320bf5 100644 --- a/Benchmarks/Dss/Flipper/DentRefundEVM.lean +++ b/Benchmarks/Dss/Flipper/DentRefundEVM.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.DentRefund -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/DentRefundMain.lean b/Benchmarks/Dss/Flipper/DentRefundMain.lean index 3300357f..4db52817 100644 --- a/Benchmarks/Dss/Flipper/DentRefundMain.lean +++ b/Benchmarks/Dss/Flipper/DentRefundMain.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.DentRefundEVM -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/DentSameCaller.lean b/Benchmarks/Dss/Flipper/DentSameCaller.lean index f7594e65..ae494a25 100644 --- a/Benchmarks/Dss/Flipper/DentSameCaller.lean +++ b/Benchmarks/Dss/Flipper/DentSameCaller.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flipper.DentTail import Benchmarks.Dss.Flipper.ExternalCallTransport -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/DentTail.lean b/Benchmarks/Dss/Flipper/DentTail.lean index 12ee90b0..388d5ffc 100644 --- a/Benchmarks/Dss/Flipper/DentTail.lean +++ b/Benchmarks/Dss/Flipper/DentTail.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Flipper.DentDecreaseGuard import Benchmarks.Dss.Flipper.BidAccess import Benchmarks.Dss.Flipper.TendRefund -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/Deny.lean b/Benchmarks/Dss/Flipper/Deny.lean index b0ed8632..272074b3 100644 --- a/Benchmarks/Dss/Flipper/Deny.lean +++ b/Benchmarks/Dss/Flipper/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/Dispatch.lean b/Benchmarks/Dss/Flipper/Dispatch.lean index 07b86194..8cef2fb8 100644 --- a/Benchmarks/Dss/Flipper/Dispatch.lean +++ b/Benchmarks/Dss/Flipper/Dispatch.lean @@ -7,7 +7,7 @@ import Benchmarks.Dss.Flipper.CommonRoutines Shared runtime-dispatch obligations for the optimized Flipper bytecode. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flipper/ErrorStringFull.lean b/Benchmarks/Dss/Flipper/ErrorStringFull.lean index c3c3381f..cf4dcc19 100644 --- a/Benchmarks/Dss/Flipper/ErrorStringFull.lean +++ b/Benchmarks/Dss/Flipper/ErrorStringFull.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/ExternalCallTransport.lean b/Benchmarks/Dss/Flipper/ExternalCallTransport.lean index 45c72efd..0e71c0eb 100644 --- a/Benchmarks/Dss/Flipper/ExternalCallTransport.lean +++ b/Benchmarks/Dss/Flipper/ExternalCallTransport.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flipper.Common import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/ExternalTargets.lean b/Benchmarks/Dss/Flipper/ExternalTargets.lean index 005d0849..c68804c6 100644 --- a/Benchmarks/Dss/Flipper/ExternalTargets.lean +++ b/Benchmarks/Dss/Flipper/ExternalTargets.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flipper/FileAddress.lean b/Benchmarks/Dss/Flipper/FileAddress.lean index ee6e760f..a0f3054b 100644 --- a/Benchmarks/Dss/Flipper/FileAddress.lean +++ b/Benchmarks/Dss/Flipper/FileAddress.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/FileUint.lean b/Benchmarks/Dss/Flipper/FileUint.lean index b629c0e0..b0c558ca 100644 --- a/Benchmarks/Dss/Flipper/FileUint.lean +++ b/Benchmarks/Dss/Flipper/FileUint.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/Ilk.lean b/Benchmarks/Dss/Flipper/Ilk.lean index 84d30724..56a6aa91 100644 --- a/Benchmarks/Dss/Flipper/Ilk.lean +++ b/Benchmarks/Dss/Flipper/Ilk.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/Kick.lean b/Benchmarks/Dss/Flipper/Kick.lean index 5e688306..494b8b18 100644 --- a/Benchmarks/Dss/Flipper/Kick.lean +++ b/Benchmarks/Dss/Flipper/Kick.lean @@ -4,7 +4,7 @@ import Benchmarks.Dss.Flipper.BidAccess import Benchmarks.Dss.Flipper.Dispatch import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/KickBody.lean b/Benchmarks/Dss/Flipper/KickBody.lean index 21b8cc11..3b302eb2 100644 --- a/Benchmarks/Dss/Flipper/KickBody.lean +++ b/Benchmarks/Dss/Flipper/KickBody.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.KickTail -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/KickTail.lean b/Benchmarks/Dss/Flipper/KickTail.lean index 61b2f031..24b62533 100644 --- a/Benchmarks/Dss/Flipper/KickTail.lean +++ b/Benchmarks/Dss/Flipper/KickTail.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Kick -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/Kicks.lean b/Benchmarks/Dss/Flipper/Kicks.lean index 67ec431c..718ab381 100644 --- a/Benchmarks/Dss/Flipper/Kicks.lean +++ b/Benchmarks/Dss/Flipper/Kicks.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/Rely.lean b/Benchmarks/Dss/Flipper/Rely.lean index cd0a2b39..4dcb7911 100644 --- a/Benchmarks/Dss/Flipper/Rely.lean +++ b/Benchmarks/Dss/Flipper/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/Tau.lean b/Benchmarks/Dss/Flipper/Tau.lean index 00c3d4d2..ad455eff 100644 --- a/Benchmarks/Dss/Flipper/Tau.lean +++ b/Benchmarks/Dss/Flipper/Tau.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/Tend.lean b/Benchmarks/Dss/Flipper/Tend.lean index 566e539d..abab3c56 100644 --- a/Benchmarks/Dss/Flipper/Tend.lean +++ b/Benchmarks/Dss/Flipper/Tend.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Flipper.Dispatch import Benchmarks.Dss.Flipper.BidAccess import Benchmarks.Dss.Flipper.ErrorStringFull -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/TendBidGuard.lean b/Benchmarks/Dss/Flipper/TendBidGuard.lean index ef6a61d7..6e622234 100644 --- a/Benchmarks/Dss/Flipper/TendBidGuard.lean +++ b/Benchmarks/Dss/Flipper/TendBidGuard.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Tend -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/TendBody.lean b/Benchmarks/Dss/Flipper/TendBody.lean index e9be949d..9489b7c9 100644 --- a/Benchmarks/Dss/Flipper/TendBody.lean +++ b/Benchmarks/Dss/Flipper/TendBody.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.TendRefund -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/TendIncreaseGuard.lean b/Benchmarks/Dss/Flipper/TendIncreaseGuard.lean index aa87b297..7dbdcc6b 100644 --- a/Benchmarks/Dss/Flipper/TendIncreaseGuard.lean +++ b/Benchmarks/Dss/Flipper/TendIncreaseGuard.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flipper.TendBidGuard import Benchmarks.Dss.Flipper.CheckedMul -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/TendRefund.lean b/Benchmarks/Dss/Flipper/TendRefund.lean index 532516bb..148d00bc 100644 --- a/Benchmarks/Dss/Flipper/TendRefund.lean +++ b/Benchmarks/Dss/Flipper/TendRefund.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.TendSameCaller -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/TendSameCaller.lean b/Benchmarks/Dss/Flipper/TendSameCaller.lean index 7b19b648..e3d89b23 100644 --- a/Benchmarks/Dss/Flipper/TendSameCaller.lean +++ b/Benchmarks/Dss/Flipper/TendSameCaller.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flipper.TendSourceTail import Benchmarks.Dss.Flipper.ExternalCallTransport -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/TendSourceTail.lean b/Benchmarks/Dss/Flipper/TendSourceTail.lean index f78ecc64..ab3895af 100644 --- a/Benchmarks/Dss/Flipper/TendSourceTail.lean +++ b/Benchmarks/Dss/Flipper/TendSourceTail.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.TendTail -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/TendTail.lean b/Benchmarks/Dss/Flipper/TendTail.lean index 24578f8e..d4496410 100644 --- a/Benchmarks/Dss/Flipper/TendTail.lean +++ b/Benchmarks/Dss/Flipper/TendTail.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Flipper.TendIncreaseGuard import Benchmarks.Dss.Flipper.BidAccess import Benchmarks.Dss.Flipper.YankCalls -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/Tick.lean b/Benchmarks/Dss/Flipper/Tick.lean index 63bb12e1..fbcf9081 100644 --- a/Benchmarks/Dss/Flipper/Tick.lean +++ b/Benchmarks/Dss/Flipper/Tick.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flipper.Dispatch import Benchmarks.Dss.Flipper.BidStorage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/Ttl.lean b/Benchmarks/Dss/Flipper/Ttl.lean index 625560ba..7068a28c 100644 --- a/Benchmarks/Dss/Flipper/Ttl.lean +++ b/Benchmarks/Dss/Flipper/Ttl.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/Vat.lean b/Benchmarks/Dss/Flipper/Vat.lean index 0cabe52a..85751f7d 100644 --- a/Benchmarks/Dss/Flipper/Vat.lean +++ b/Benchmarks/Dss/Flipper/Vat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/Wards.lean b/Benchmarks/Dss/Flipper/Wards.lean index a744885f..e5738a41 100644 --- a/Benchmarks/Dss/Flipper/Wards.lean +++ b/Benchmarks/Dss/Flipper/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flipper diff --git a/Benchmarks/Dss/Flipper/Yank.lean b/Benchmarks/Dss/Flipper/Yank.lean index 5e4821ad..738ad8fc 100644 --- a/Benchmarks/Dss/Flipper/Yank.lean +++ b/Benchmarks/Dss/Flipper/Yank.lean @@ -5,7 +5,7 @@ import Benchmarks.Dss.Flipper.ExternalCallTransport import Reasoning.ExternalCall import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/YankBody.lean b/Benchmarks/Dss/Flipper/YankBody.lean index 59472248..a5e8a523 100644 --- a/Benchmarks/Dss/Flipper/YankBody.lean +++ b/Benchmarks/Dss/Flipper/YankBody.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flipper.YankCalls -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flipper/YankCalls.lean b/Benchmarks/Dss/Flipper/YankCalls.lean index 070d3ffb..4d24cd80 100644 --- a/Benchmarks/Dss/Flipper/YankCalls.lean +++ b/Benchmarks/Dss/Flipper/YankCalls.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flipper.Yank import Benchmarks.Dss.Flipper.BidDelete -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Flopper/AuctionCommon.lean b/Benchmarks/Dss/Flopper/AuctionCommon.lean index 5050031b..aeb320eb 100644 --- a/Benchmarks/Dss/Flopper/AuctionCommon.lean +++ b/Benchmarks/Dss/Flopper/AuctionCommon.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flopper.Bids import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flopper/Beg.lean b/Benchmarks/Dss/Flopper/Beg.lean index 98eaeef2..30b9f167 100644 --- a/Benchmarks/Dss/Flopper/Beg.lean +++ b/Benchmarks/Dss/Flopper/Beg.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flopper diff --git a/Benchmarks/Dss/Flopper/Bids.lean b/Benchmarks/Dss/Flopper/Bids.lean index c23abaf3..c3f68412 100644 --- a/Benchmarks/Dss/Flopper/Bids.lean +++ b/Benchmarks/Dss/Flopper/Bids.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flopper.Dispatch import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flopper/Cage.lean b/Benchmarks/Dss/Flopper/Cage.lean index b3eb7f02..144e85f2 100644 --- a/Benchmarks/Dss/Flopper/Cage.lean +++ b/Benchmarks/Dss/Flopper/Cage.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Deny -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flopper/Common.lean b/Benchmarks/Dss/Flopper/Common.lean index 80df46bd..bafdc417 100644 --- a/Benchmarks/Dss/Flopper/Common.lean +++ b/Benchmarks/Dss/Flopper/Common.lean @@ -6,7 +6,6 @@ import Reasoning.Reach import Reasoning.Solc import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -16,7 +15,7 @@ import Mathlib.Tactic.IntervalCases Contract-wide selector notation and constants for the optimized Flopper runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flopper/Correct.lean b/Benchmarks/Dss/Flopper/Correct.lean index 2d5198ec..8b85199d 100644 --- a/Benchmarks/Dss/Flopper/Correct.lean +++ b/Benchmarks/Dss/Flopper/Correct.lean @@ -29,7 +29,7 @@ are present. The runtime-equivalence proof is intentionally left as the benchmar also exposes the whole-contract wrapper that combines the constructor and runtime targets. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flopper diff --git a/Benchmarks/Dss/Flopper/Deal.lean b/Benchmarks/Dss/Flopper/Deal.lean index 755f9b84..6ebde3d8 100644 --- a/Benchmarks/Dss/Flopper/Deal.lean +++ b/Benchmarks/Dss/Flopper/Deal.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.AuctionCommon -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -781,7 +781,7 @@ theorem flopperDealBodyReverts_mintCallFailure "_mintRet" ++ [.delete (bidRef (.var "id"))]) .reverted := - Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h) + .execBlock_append_term hchecked (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -854,7 +854,7 @@ theorem flopperDealBodyReturns_mintCallSuccess [.delete (bidRef (.var "id"))]) (.ok { contract := contract, locals := dealMintLocals I } (auctionDeletePostState (dealIdWord I) evm')) := - Reasoning.Refinement.execBlock_append hchecked hdelete + .execBlock_append hchecked hdelete refine ExecFuncBody.execBlockOK ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using diff --git a/Benchmarks/Dss/Flopper/DealRuntime.lean b/Benchmarks/Dss/Flopper/DealRuntime.lean index e8041228..a37aa80f 100644 --- a/Benchmarks/Dss/Flopper/DealRuntime.lean +++ b/Benchmarks/Dss/Flopper/DealRuntime.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Deal -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flopper/Dent/Part1.lean b/Benchmarks/Dss/Flopper/Dent/Part1.lean index 306d1270..7a75ab8b 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part1.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part1.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Flopper.AuctionCommon import Benchmarks.Dss.Flopper.Tick import Benchmarks.Dss.Flopper.Yank -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unusedSimpArgs false @@ -1523,7 +1523,7 @@ theorem flopperDentBodyAfterAshSuccessKissNoCode simpa [checkedExternalCallStmts] using checkedExternalCallNoCode hguard simpa [List.cons_append, List.nil_append] using - Reasoning.Refinement.execBlock_append hmin hkiss + .execBlock_append hmin hkiss theorem flopperDentBodyAfterAshSuccessKissCallFailure (localsEvm evmAsh evmKiss : EVM.State) (I : ExecutionEnv) @@ -1582,7 +1582,7 @@ theorem flopperDentBodyAfterAshSuccessKissCallFailure simpa [checkedExternalCallStmts] using checkedExternalCallFailure hguard htarget hargs hcall simpa [List.cons_append, List.nil_append] using - Reasoning.Refinement.execBlock_append hmin hkiss + .execBlock_append hmin hkiss theorem flopperDentBodyAfterAshSuccessKissCallSuccess (localsEvm evmAsh evmKiss : EVM.State) (I : ExecutionEnv) @@ -1642,7 +1642,7 @@ theorem flopperDentBodyAfterAshSuccessKissCallSuccess simpa [checkedExternalCallStmts, dentKissRetLocals] using checkedExternalCallSuccess hguard htarget hargs hcall (dentKissDecode_ok outKiss) simpa [List.cons_append, List.nil_append] using - Reasoning.Refinement.execBlock_append hmin hkiss + .execBlock_append hmin hkiss theorem evalExpr_dent_live_one_true (evm : EVM.State) (I : ExecutionEnv) (hlive : dentLiveWord evm = ⟨1⟩) : diff --git a/Benchmarks/Dss/Flopper/Dent/Part10.lean b/Benchmarks/Dss/Flopper/Dent/Part10.lean index cce21393..df230f0f 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part10.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part10.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dent.Part9 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unusedSimpArgs false diff --git a/Benchmarks/Dss/Flopper/Dent/Part2.lean b/Benchmarks/Dss/Flopper/Dent/Part2.lean index 1c515796..16481328 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part2.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part2.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dent.Part1 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unusedSimpArgs false diff --git a/Benchmarks/Dss/Flopper/Dent/Part3.lean b/Benchmarks/Dss/Flopper/Dent/Part3.lean index 3f3fc6b8..178cc9a0 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part3.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part3.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dent.Part2 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unusedSimpArgs false @@ -127,7 +127,7 @@ theorem flopperDentBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) [], .assign .storage (bidsF (.var "id") "guy") sender ]) .reverted := - Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h) + .execBlock_append_term hchecked (by intro f e h; cases h) have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -165,7 +165,7 @@ theorem flopperDentBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - Reasoning.Refinement.execBlock_append_term hite (by intro f e h; cases h) + .execBlock_append_term hite (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -272,7 +272,7 @@ theorem flopperDentBodyReverts_moveCallFailure [], .assign .storage (bidsF (.var "id") "guy") sender ]) .reverted := - Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h) + .execBlock_append_term hchecked (by intro f e h; cases h) have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -310,7 +310,7 @@ theorem flopperDentBodyReverts_moveCallFailure checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - Reasoning.Refinement.execBlock_append_term hite (by intro f e h; cases h) + .execBlock_append_term hite (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -455,7 +455,7 @@ theorem flopperDentBodyReverts_ashNoCode_moveCallerNe_ticZero (.intLit 0) [] "Ash" ++ [ .internalCall "min" [.var "bid", .var "Ash"] "kissAmt" ]) .reverted := - Reasoning.Refinement.execBlock_append_term hashChecked (by intro f e h; cases h) + .execBlock_append_term hashChecked (by intro f e h; cases h) have hashBranch : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove (checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "Ash" @@ -464,7 +464,7 @@ theorem flopperDentBodyReverts_ashNoCode_moveCallerNe_ticZero checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "kiss" (.intLit 0) [.var "kissAmt"] "_kissRet") .reverted := - Reasoning.Refinement.execBlock_append_term hashMin (by intro f e h; cases h) + .execBlock_append_term hashMin (by intro f e h; cases h) have hafterMove : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove [.ite (.binary .eq (.storage (bidsF (.var "id") "tic")) (.intLit 0)) @@ -491,7 +491,7 @@ theorem flopperDentBodyReverts_ashNoCode_moveCallerNe_ticZero [], .assign .storage (bidsF (.var "id") "guy") sender ]) .reverted := - Reasoning.Refinement.execBlock_append hchecked hafterMove + .execBlock_append hchecked hafterMove have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -529,7 +529,7 @@ theorem flopperDentBodyReverts_ashNoCode_moveCallerNe_ticZero checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - Reasoning.Refinement.execBlock_append_term hite (by intro f e h; cases h) + .execBlock_append_term hite (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -680,7 +680,7 @@ theorem flopperDentBodyReverts_ashCallFailure_moveCallerNe_ticZero (.intLit 0) [] "Ash" ++ [ .internalCall "min" [.var "bid", .var "Ash"] "kissAmt" ]) .reverted := - Reasoning.Refinement.execBlock_append_term hashChecked (by intro f e h; cases h) + .execBlock_append_term hashChecked (by intro f e h; cases h) have hashBranch : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove (checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "Ash" @@ -689,7 +689,7 @@ theorem flopperDentBodyReverts_ashCallFailure_moveCallerNe_ticZero checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "kiss" (.intLit 0) [.var "kissAmt"] "_kissRet") .reverted := - Reasoning.Refinement.execBlock_append_term hashMin (by intro f e h; cases h) + .execBlock_append_term hashMin (by intro f e h; cases h) have hafterMove : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove [.ite (.binary .eq (.storage (bidsF (.var "id") "tic")) (.intLit 0)) @@ -716,7 +716,7 @@ theorem flopperDentBodyReverts_ashCallFailure_moveCallerNe_ticZero [], .assign .storage (bidsF (.var "id") "guy") sender ]) .reverted := - Reasoning.Refinement.execBlock_append hchecked hafterMove + .execBlock_append hchecked hafterMove have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -754,7 +754,7 @@ theorem flopperDentBodyReverts_ashCallFailure_moveCallerNe_ticZero checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - Reasoning.Refinement.execBlock_append_term hite (by intro f e h; cases h) + .execBlock_append_term hite (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -907,7 +907,7 @@ theorem flopperDentBodyReverts_ashDecodeShort_moveCallerNe_ticZero (.intLit 0) [] "Ash" ++ [ .internalCall "min" [.var "bid", .var "Ash"] "kissAmt" ]) .reverted := - Reasoning.Refinement.execBlock_append_term hashChecked (by intro f e h; cases h) + .execBlock_append_term hashChecked (by intro f e h; cases h) have hashBranch : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove (checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "Ash" @@ -916,7 +916,7 @@ theorem flopperDentBodyReverts_ashDecodeShort_moveCallerNe_ticZero checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "kiss" (.intLit 0) [.var "kissAmt"] "_kissRet") .reverted := - Reasoning.Refinement.execBlock_append_term hashMin (by intro f e h; cases h) + .execBlock_append_term hashMin (by intro f e h; cases h) have hafterMove : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove [.ite (.binary .eq (.storage (bidsF (.var "id") "tic")) (.intLit 0)) @@ -943,7 +943,7 @@ theorem flopperDentBodyReverts_ashDecodeShort_moveCallerNe_ticZero [], .assign .storage (bidsF (.var "id") "guy") sender ]) .reverted := - Reasoning.Refinement.execBlock_append hchecked hafterMove + .execBlock_append hchecked hafterMove have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -981,7 +981,7 @@ theorem flopperDentBodyReverts_ashDecodeShort_moveCallerNe_ticZero checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - Reasoning.Refinement.execBlock_append_term hite (by intro f e h; cases h) + .execBlock_append_term hite (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -1143,7 +1143,7 @@ theorem flopperDentBodyReverts_afterAshRevert_moveCallerNe_ticZero (.intLit 0) [.var "kissAmt"] "_kissRet") .reverted := by simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append hashChecked hafterAsh + .execBlock_append hashChecked hafterAsh have hafterMove : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove [.ite (.binary .eq (.storage (bidsF (.var "id") "tic")) (.intLit 0)) @@ -1170,7 +1170,7 @@ theorem flopperDentBodyReverts_afterAshRevert_moveCallerNe_ticZero [], .assign .storage (bidsF (.var "id") "guy") sender ]) .reverted := - Reasoning.Refinement.execBlock_append hchecked hafterMove + .execBlock_append hchecked hafterMove have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -1208,7 +1208,7 @@ theorem flopperDentBodyReverts_afterAshRevert_moveCallerNe_ticZero checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - Reasoning.Refinement.execBlock_append_term hite (by intro f e h; cases h) + .execBlock_append_term hite (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -1436,7 +1436,7 @@ theorem flopperDentBodyMoveSuccessTicNonzeroToLot [], .assign .storage (bidsF (.var "id") "guy") sender ]) (.ok { contract := contract, locals := dentMoveLocals evm I } evmGuy) := - Reasoning.Refinement.execBlock_append hchecked hguyAssign + .execBlock_append hchecked hguyAssign have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -1466,7 +1466,7 @@ theorem flopperDentBodyMoveSuccessTicNonzeroToLot (dentMoveLocals_get_id evm I) (dentMoveLocals_get_bids evm I))) ExecBlock.nil have htail := - Reasoning.Refinement.execBlock_append hite hlotAssign + .execBlock_append hite hlotAssign simpa [evmGuy, evmLot] using htail set_option maxHeartbeats 1000000 in @@ -1605,7 +1605,7 @@ theorem flopperDentBodyMoveAshKissSuccessTicZeroToLot (.intLit 0) [.var "kissAmt"] "_kissRet") (.ok { contract := contract, locals := dentKissRetLocals evm I outAsh } evmKiss) := by simpa [List.append_assoc] using - Reasoning.Refinement.execBlock_append hashChecked hafterAsh + .execBlock_append hashChecked hafterAsh have hinnerGuy : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove [.ite (.binary .eq (.storage (bidsF (.var "id") "tic")) (.intLit 0)) @@ -1640,7 +1640,7 @@ theorem flopperDentBodyMoveAshKissSuccessTicZeroToLot [], .assign .storage (bidsF (.var "id") "guy") sender ]) (.ok { contract := contract, locals := dentKissRetLocals evm I outAsh } evmGuy) := - Reasoning.Refinement.execBlock_append hchecked hinnerGuy + .execBlock_append hchecked hinnerGuy have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -1672,7 +1672,7 @@ theorem flopperDentBodyMoveAshKissSuccessTicZeroToLot (dentKissRetLocals_get_bids evm I outAsh))) ExecBlock.nil have htail := - Reasoning.Refinement.execBlock_append hite hlotAssign + .execBlock_append hite hlotAssign simpa [evmGuy, evmLot] using htail end Benchmarks.Dss.Flopper diff --git a/Benchmarks/Dss/Flopper/Dent/Part4.lean b/Benchmarks/Dss/Flopper/Dent/Part4.lean index ab7429b3..272ed359 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part4.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part4.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dent.Part3 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unusedSimpArgs false @@ -88,7 +88,7 @@ theorem flopperDentBodyReverts_addOverflow_moveCallerNe_ticZero_kissSuccess evmLot (checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]) .reverted := - Reasoning.Refinement.execBlock_append_term htickChecked (by intro f e h; cases h) + .execBlock_append_term htickChecked (by intro f e h; cases h) have htail : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm ([.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -109,7 +109,7 @@ theorem flopperDentBodyReverts_addOverflow_moveCallerNe_ticZero_kissSuccess [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := by simpa [List.cons_append, List.nil_append, evmGuy, evmLot] using - Reasoning.Refinement.execBlock_append htailIteLot htickTail + .execBlock_append htailIteLot htickTail refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -246,7 +246,7 @@ theorem flopperDentBodyReturns_success_moveCallerNe_ticZero_kissSuccess (.ok { contract := contract, locals := dentKissRetTicLocals evm evmGuy I outAsh } (dentPostState evmGuy I)) := by simpa [List.cons_append, List.nil_append, evmGuy, evmLot] using - Reasoning.Refinement.execBlock_append htailIteLot htickLet + .execBlock_append htailIteLot htickLet refine ExecFuncBody.execBlockOK ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append, evmGuy] using @@ -333,7 +333,7 @@ theorem flopperDentBodyReverts_addOverflow_moveCallerNe_ticNonzero ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmLot (checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]) .reverted := - Reasoning.Refinement.execBlock_append_term htickChecked (by intro f e h; cases h) + .execBlock_append_term htickChecked (by intro f e h; cases h) have htail : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm ([.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -354,7 +354,7 @@ theorem flopperDentBodyReverts_addOverflow_moveCallerNe_ticNonzero [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := by simpa [List.cons_append, List.nil_append, evmGuy, evmLot] using - Reasoning.Refinement.execBlock_append htailIteLot htickTail + .execBlock_append htailIteLot htickTail refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -468,7 +468,7 @@ theorem flopperDentBodyReturns_success_moveCallerNe_ticNonzero (.ok { contract := contract, locals := dentMoveTicLocals evm evmGuy I } (dentPostState evmGuy I)) := by simpa [List.cons_append, List.nil_append, evmGuy, evmLot] using - Reasoning.Refinement.execBlock_append htailIteLot htickLet + .execBlock_append htailIteLot htickLet refine ExecFuncBody.execBlockOK ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append, evmGuy] using @@ -561,7 +561,7 @@ theorem flopperDentBodyReverts_addOverflow_callerEq (evm : EVM.State) (I : Execu ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evmLot (checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]) .reverted := - Reasoning.Refinement.execBlock_append_term htickChecked (by intro f e h; cases h) + .execBlock_append_term htickChecked (by intro f e h; cases h) have htail : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm ([.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -581,7 +581,7 @@ theorem flopperDentBodyReverts_addOverflow_callerEq (evm : EVM.State) (I : Execu (checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - Reasoning.Refinement.execBlock_append htailIteLot htickTail + .execBlock_append htailIteLot htickTail refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -696,7 +696,7 @@ theorem flopperDentBodyReturns_success_callerEq (evm : EVM.State) (I : Execution (checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) (.ok { contract := contract, locals := dentTicLocals evm I } (dentPostState evm I)) := - Reasoning.Refinement.execBlock_append htailIteLot htickLet + .execBlock_append htailIteLot htickLet refine ExecFuncBody.execBlockOK ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using diff --git a/Benchmarks/Dss/Flopper/Dent/Part5.lean b/Benchmarks/Dss/Flopper/Dent/Part5.lean index fd0d68d8..db195f42 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part5.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part5.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dent.Part4 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unusedSimpArgs false diff --git a/Benchmarks/Dss/Flopper/Dent/Part6.lean b/Benchmarks/Dss/Flopper/Dent/Part6.lean index e9de3509..aa66c1fe 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part6.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part6.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dent.Part5 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unusedSimpArgs false diff --git a/Benchmarks/Dss/Flopper/Dent/Part7.lean b/Benchmarks/Dss/Flopper/Dent/Part7.lean index 47624975..7934742a 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part7.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part7.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dent.Part6 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unusedSimpArgs false diff --git a/Benchmarks/Dss/Flopper/Dent/Part8.lean b/Benchmarks/Dss/Flopper/Dent/Part8.lean index 2ee8a0c7..f650d2ed 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part8.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part8.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dent.Part7 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unusedSimpArgs false diff --git a/Benchmarks/Dss/Flopper/Dent/Part9.lean b/Benchmarks/Dss/Flopper/Dent/Part9.lean index 6f9fa1e2..e23349e8 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part9.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part9.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dent.Part8 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unusedSimpArgs false diff --git a/Benchmarks/Dss/Flopper/Deny.lean b/Benchmarks/Dss/Flopper/Deny.lean index 9a43430d..9a83c625 100644 --- a/Benchmarks/Dss/Flopper/Deny.lean +++ b/Benchmarks/Dss/Flopper/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flopper/Dispatch.lean b/Benchmarks/Dss/Flopper/Dispatch.lean index f9198aa8..ffd3e3dc 100644 --- a/Benchmarks/Dss/Flopper/Dispatch.lean +++ b/Benchmarks/Dss/Flopper/Dispatch.lean @@ -6,7 +6,7 @@ import Benchmarks.Dss.Flopper.Trusted Solm dispatch routing facts and the shared non-payable source result. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flopper/File/Part1.lean b/Benchmarks/Dss/Flopper/File/Part1.lean index bc343150..548da2f1 100644 --- a/Benchmarks/Dss/Flopper/File/Part1.lean +++ b/Benchmarks/Dss/Flopper/File/Part1.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Cage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flopper/File/Part2.lean b/Benchmarks/Dss/Flopper/File/Part2.lean index 6a7d16be..a925a7fd 100644 --- a/Benchmarks/Dss/Flopper/File/Part2.lean +++ b/Benchmarks/Dss/Flopper/File/Part2.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.File.Part1 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flopper/Gem.lean b/Benchmarks/Dss/Flopper/Gem.lean index 572c7c4a..0aa2fb35 100644 --- a/Benchmarks/Dss/Flopper/Gem.lean +++ b/Benchmarks/Dss/Flopper/Gem.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flopper diff --git a/Benchmarks/Dss/Flopper/Kick/Part1.lean b/Benchmarks/Dss/Flopper/Kick/Part1.lean index c6d2ffc2..20ce78e0 100644 --- a/Benchmarks/Dss/Flopper/Kick/Part1.lean +++ b/Benchmarks/Dss/Flopper/Kick/Part1.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flopper.Rely import Benchmarks.Dss.Flopper.Tick -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flopper/Kick/Part2.lean b/Benchmarks/Dss/Flopper/Kick/Part2.lean index aa10a00d..b6fe3a10 100644 --- a/Benchmarks/Dss/Flopper/Kick/Part2.lean +++ b/Benchmarks/Dss/Flopper/Kick/Part2.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Kick.Part1 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flopper/Kicks.lean b/Benchmarks/Dss/Flopper/Kicks.lean index df0f0f78..529a5a1e 100644 --- a/Benchmarks/Dss/Flopper/Kicks.lean +++ b/Benchmarks/Dss/Flopper/Kicks.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flopper diff --git a/Benchmarks/Dss/Flopper/Live.lean b/Benchmarks/Dss/Flopper/Live.lean index 1061369f..26e2b1c3 100644 --- a/Benchmarks/Dss/Flopper/Live.lean +++ b/Benchmarks/Dss/Flopper/Live.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flopper diff --git a/Benchmarks/Dss/Flopper/Pad.lean b/Benchmarks/Dss/Flopper/Pad.lean index 44523854..468f798c 100644 --- a/Benchmarks/Dss/Flopper/Pad.lean +++ b/Benchmarks/Dss/Flopper/Pad.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flopper diff --git a/Benchmarks/Dss/Flopper/Rely.lean b/Benchmarks/Dss/Flopper/Rely.lean index f9ad5290..27a92112 100644 --- a/Benchmarks/Dss/Flopper/Rely.lean +++ b/Benchmarks/Dss/Flopper/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flopper/Tau.lean b/Benchmarks/Dss/Flopper/Tau.lean index b23a05db..70481ee4 100644 --- a/Benchmarks/Dss/Flopper/Tau.lean +++ b/Benchmarks/Dss/Flopper/Tau.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flopper diff --git a/Benchmarks/Dss/Flopper/Tick/Part1.lean b/Benchmarks/Dss/Flopper/Tick/Part1.lean index 7b1bd65e..cf4ff076 100644 --- a/Benchmarks/Dss/Flopper/Tick/Part1.lean +++ b/Benchmarks/Dss/Flopper/Tick/Part1.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.AuctionCommon -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -1077,7 +1077,7 @@ theorem flopperTickBodyReverts_addOverflow (evm : EVM.State) (I : ExecutionEnv) ExecBlock config { contract := contract, locals := tickLotBaseLocals evm I } evmLot (checkedAdd48Into "end_" now48 (.storage tauRef) ++ [.assign .storage (bidsF (.var "id") "end") (.var "end_")]) .reverted := - Reasoning.Refinement.execBlock_append_term hendChecked (by intro f e h; cases h) + .execBlock_append_term hendChecked (by intro f e h; cases h) have htail : ExecBlock config { contract := contract, locals := tickLotBaseLocals evm I } evm ([.assign .storage (bidsF (.var "id") "lot") @@ -1085,7 +1085,7 @@ theorem flopperTickBodyReverts_addOverflow (evm : EVM.State) (I : ExecutionEnv) (checkedAdd48Into "end_" now48 (.storage tauRef) ++ [.assign .storage (bidsF (.var "id") "end") (.var "end_")])) .reverted := - Reasoning.Refinement.execBlock_append hlotAssign hendTail + .execBlock_append hlotAssign hendTail refine ExecFuncBody.execBlockRevert ?_ simpa [tickTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -1142,7 +1142,7 @@ theorem flopperTickBodyReturns_success (evm : EVM.State) (I : ExecutionEnv) (checkedAdd48Into "end_" now48 (.storage tauRef) ++ [.assign .storage (bidsF (.var "id") "end") (.var "end_")])) (.ok { contract := contract, locals := tickEndLocals evm I } (tickPostState evm I)) := - Reasoning.Refinement.execBlock_append hlotAssign hendLet + .execBlock_append hlotAssign hendLet refine ExecFuncBody.execBlockOK ?_ simpa [tickTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using diff --git a/Benchmarks/Dss/Flopper/Tick/Part2.lean b/Benchmarks/Dss/Flopper/Tick/Part2.lean index 5286cf9a..54a7ffc1 100644 --- a/Benchmarks/Dss/Flopper/Tick/Part2.lean +++ b/Benchmarks/Dss/Flopper/Tick/Part2.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Tick.Part1 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Flopper/Ttl.lean b/Benchmarks/Dss/Flopper/Ttl.lean index ff5e0eac..29d17c2b 100644 --- a/Benchmarks/Dss/Flopper/Ttl.lean +++ b/Benchmarks/Dss/Flopper/Ttl.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flopper diff --git a/Benchmarks/Dss/Flopper/Vat.lean b/Benchmarks/Dss/Flopper/Vat.lean index b85f59e3..b78e8abd 100644 --- a/Benchmarks/Dss/Flopper/Vat.lean +++ b/Benchmarks/Dss/Flopper/Vat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flopper diff --git a/Benchmarks/Dss/Flopper/Vow.lean b/Benchmarks/Dss/Flopper/Vow.lean index 3e388cf2..1c9a4c28 100644 --- a/Benchmarks/Dss/Flopper/Vow.lean +++ b/Benchmarks/Dss/Flopper/Vow.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flopper diff --git a/Benchmarks/Dss/Flopper/Wards.lean b/Benchmarks/Dss/Flopper/Wards.lean index 567dbec9..1a2561e9 100644 --- a/Benchmarks/Dss/Flopper/Wards.lean +++ b/Benchmarks/Dss/Flopper/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Flopper diff --git a/Benchmarks/Dss/Flopper/Yank/Part1.lean b/Benchmarks/Dss/Flopper/Yank/Part1.lean index 0082378b..dc77acbe 100644 --- a/Benchmarks/Dss/Flopper/Yank/Part1.lean +++ b/Benchmarks/Dss/Flopper/Yank/Part1.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Flopper.AuctionCommon import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -989,7 +989,7 @@ theorem flopperYankBodyReverts_suckCallFailure .storage (bidsF (.var "id") "bid")] "_suckRet" ++ [.delete (bidRef (.var "id"))]) .reverted := - Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h) + .execBlock_append_term hchecked (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [yankTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -1071,7 +1071,7 @@ theorem flopperYankBodyReturns_suckCallSuccess [.delete (bidRef (.var "id"))]) (.ok { contract := contract, locals := yankSuckLocals I } (yankDeletePostState evm' I)) := - Reasoning.Refinement.execBlock_append hchecked hdelete + .execBlock_append hchecked hdelete refine ExecFuncBody.execBlockOK ?_ simpa [yankTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using diff --git a/Benchmarks/Dss/Flopper/Yank/Part2.lean b/Benchmarks/Dss/Flopper/Yank/Part2.lean index d7aa0f89..03e8afe7 100644 --- a/Benchmarks/Dss/Flopper/Yank/Part2.lean +++ b/Benchmarks/Dss/Flopper/Yank/Part2.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Flopper.Yank.Part1 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/GemJoin/Cage.lean b/Benchmarks/Dss/GemJoin/Cage.lean index f2b9cbcf..3cc6ef4f 100644 --- a/Benchmarks/Dss/GemJoin/Cage.lean +++ b/Benchmarks/Dss/GemJoin/Cage.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.GemJoin.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.GemJoin diff --git a/Benchmarks/Dss/GemJoin/Common.lean b/Benchmarks/Dss/GemJoin/Common.lean index fa83690d..e13a7157 100644 --- a/Benchmarks/Dss/GemJoin/Common.lean +++ b/Benchmarks/Dss/GemJoin/Common.lean @@ -6,7 +6,6 @@ import Reasoning.Reach import Reasoning.Solc import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -16,7 +15,7 @@ import Mathlib.Tactic.IntervalCases Contract-wide selector notation and constants for the optimized runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/GemJoin/Correct.lean b/Benchmarks/Dss/GemJoin/Correct.lean index 0648a13b..6d3770c3 100644 --- a/Benchmarks/Dss/GemJoin/Correct.lean +++ b/Benchmarks/Dss/GemJoin/Correct.lean @@ -18,7 +18,7 @@ This file exposes the runtime-equivalence proof and the whole-contract wrapper t the constructor and runtime targets. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.GemJoin diff --git a/Benchmarks/Dss/GemJoin/Dec.lean b/Benchmarks/Dss/GemJoin/Dec.lean index 14eec29c..b9fa90dc 100644 --- a/Benchmarks/Dss/GemJoin/Dec.lean +++ b/Benchmarks/Dss/GemJoin/Dec.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.GemJoin.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.GemJoin diff --git a/Benchmarks/Dss/GemJoin/Deny.lean b/Benchmarks/Dss/GemJoin/Deny.lean index 9f248876..e6b6019a 100644 --- a/Benchmarks/Dss/GemJoin/Deny.lean +++ b/Benchmarks/Dss/GemJoin/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.GemJoin.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/GemJoin/Dispatch.lean b/Benchmarks/Dss/GemJoin/Dispatch.lean index 429aa76e..fd445f92 100644 --- a/Benchmarks/Dss/GemJoin/Dispatch.lean +++ b/Benchmarks/Dss/GemJoin/Dispatch.lean @@ -8,7 +8,7 @@ correctness theorem. The no-dispatch and non-payable runtime paths are proof lea scaffold phase and will be discharged before the benchmark is complete. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/GemJoin/Exit.lean b/Benchmarks/Dss/GemJoin/Exit.lean index 27848ee5..c33ede69 100644 --- a/Benchmarks/Dss/GemJoin/Exit.lean +++ b/Benchmarks/Dss/GemJoin/Exit.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.GemJoin.Join -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/GemJoin/Gem.lean b/Benchmarks/Dss/GemJoin/Gem.lean index be04d804..b6e39b20 100644 --- a/Benchmarks/Dss/GemJoin/Gem.lean +++ b/Benchmarks/Dss/GemJoin/Gem.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.GemJoin.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.GemJoin diff --git a/Benchmarks/Dss/GemJoin/Ilk.lean b/Benchmarks/Dss/GemJoin/Ilk.lean index 3041939a..08c458ae 100644 --- a/Benchmarks/Dss/GemJoin/Ilk.lean +++ b/Benchmarks/Dss/GemJoin/Ilk.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.GemJoin.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.GemJoin diff --git a/Benchmarks/Dss/GemJoin/Join.lean b/Benchmarks/Dss/GemJoin/Join.lean index 7dedbbfe..a61fde1f 100644 --- a/Benchmarks/Dss/GemJoin/Join.lean +++ b/Benchmarks/Dss/GemJoin/Join.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.GemJoin.Deny import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/GemJoin/Live.lean b/Benchmarks/Dss/GemJoin/Live.lean index 69dfc5bb..532eb8c3 100644 --- a/Benchmarks/Dss/GemJoin/Live.lean +++ b/Benchmarks/Dss/GemJoin/Live.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.GemJoin.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.GemJoin diff --git a/Benchmarks/Dss/GemJoin/Rely.lean b/Benchmarks/Dss/GemJoin/Rely.lean index 1fdf5a8f..038fa8d6 100644 --- a/Benchmarks/Dss/GemJoin/Rely.lean +++ b/Benchmarks/Dss/GemJoin/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.GemJoin.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/GemJoin/Vat.lean b/Benchmarks/Dss/GemJoin/Vat.lean index 928a1bd4..39e28a3c 100644 --- a/Benchmarks/Dss/GemJoin/Vat.lean +++ b/Benchmarks/Dss/GemJoin/Vat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.GemJoin.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.GemJoin diff --git a/Benchmarks/Dss/GemJoin/Wards.lean b/Benchmarks/Dss/GemJoin/Wards.lean index 601a10fa..cd697839 100644 --- a/Benchmarks/Dss/GemJoin/Wards.lean +++ b/Benchmarks/Dss/GemJoin/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.GemJoin.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.GemJoin diff --git a/Benchmarks/Dss/Jug/ArithmeticAddDiff.lean b/Benchmarks/Dss/Jug/ArithmeticAddDiff.lean index 7dc7f204..c834de52 100644 --- a/Benchmarks/Dss/Jug/ArithmeticAddDiff.lean +++ b/Benchmarks/Dss/Jug/ArithmeticAddDiff.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.ArithmeticLocals -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Jug/ArithmeticExpr.lean b/Benchmarks/Dss/Jug/ArithmeticExpr.lean index f19167f5..5ea08518 100644 --- a/Benchmarks/Dss/Jug/ArithmeticExpr.lean +++ b/Benchmarks/Dss/Jug/ArithmeticExpr.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Jug/ArithmeticLocals.lean b/Benchmarks/Dss/Jug/ArithmeticLocals.lean index 587abd9b..20b02370 100644 --- a/Benchmarks/Dss/Jug/ArithmeticLocals.lean +++ b/Benchmarks/Dss/Jug/ArithmeticLocals.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.ArithmeticExpr -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Jug/ArithmeticRmulRpow.lean b/Benchmarks/Dss/Jug/ArithmeticRmulRpow.lean index bb37d26c..053673fb 100644 --- a/Benchmarks/Dss/Jug/ArithmeticRmulRpow.lean +++ b/Benchmarks/Dss/Jug/ArithmeticRmulRpow.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Jug.ArithmeticAddDiff import Benchmarks.Dss.Jug.ArithmeticRpowLoop -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Jug/ArithmeticRpowLoop.lean b/Benchmarks/Dss/Jug/ArithmeticRpowLoop.lean index d6b8c0a3..377adfd6 100644 --- a/Benchmarks/Dss/Jug/ArithmeticRpowLoop.lean +++ b/Benchmarks/Dss/Jug/ArithmeticRpowLoop.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.ArithmeticLocals -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Jug/Base.lean b/Benchmarks/Dss/Jug/Base.lean index fb558f09..e2706a9f 100644 --- a/Benchmarks/Dss/Jug/Base.lean +++ b/Benchmarks/Dss/Jug/Base.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/Common.lean b/Benchmarks/Dss/Jug/Common.lean index 9cb27bab..715a3894 100644 --- a/Benchmarks/Dss/Jug/Common.lean +++ b/Benchmarks/Dss/Jug/Common.lean @@ -7,7 +7,6 @@ import Reasoning.Solc import Reasoning.Memory import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -17,7 +16,7 @@ import Mathlib.Tactic.IntervalCases Contract-wide selector notation and constants for the optimized Jug runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Jug/Correct.lean b/Benchmarks/Dss/Jug/Correct.lean index 06e9a00e..2b7f38e4 100644 --- a/Benchmarks/Dss/Jug/Correct.lean +++ b/Benchmarks/Dss/Jug/Correct.lean @@ -21,7 +21,7 @@ are present. The runtime-equivalence proof is intentionally left as the benchmar also exposes the whole-contract wrapper that combines the constructor and runtime targets. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Jug/Deny.lean b/Benchmarks/Dss/Jug/Deny.lean index 077f7162..4790cd5a 100644 --- a/Benchmarks/Dss/Jug/Deny.lean +++ b/Benchmarks/Dss/Jug/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Jug/Dispatch.lean b/Benchmarks/Dss/Jug/Dispatch.lean index 2b678bce..9aec5db1 100644 --- a/Benchmarks/Dss/Jug/Dispatch.lean +++ b/Benchmarks/Dss/Jug/Dispatch.lean @@ -6,7 +6,7 @@ import Benchmarks.Dss.Jug.Trusted Solm dispatch routing facts and the shared non-payable body result. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Jug/Drip.lean b/Benchmarks/Dss/Jug/Drip.lean index 3425e3fe..5dae3ad6 100644 --- a/Benchmarks/Dss/Jug/Drip.lean +++ b/Benchmarks/Dss/Jug/Drip.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.DripBodyAddReturnsTactic -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripBase.lean b/Benchmarks/Dss/Jug/DripBase.lean index cd9c7649..97b5e522 100644 --- a/Benchmarks/Dss/Jug/DripBase.lean +++ b/Benchmarks/Dss/Jug/DripBase.lean @@ -3,7 +3,7 @@ import Benchmarks.Dss.Jug.FileDuty import Reasoning.ExternalCall import Reasoning.Initcode -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripBodyAddReturnsTactic.lean b/Benchmarks/Dss/Jug/DripBodyAddReturnsTactic.lean index b4fd3b2d..e95f9769 100644 --- a/Benchmarks/Dss/Jug/DripBodyAddReturnsTactic.lean +++ b/Benchmarks/Dss/Jug/DripBodyAddReturnsTactic.lean @@ -3,7 +3,7 @@ import Mathlib.Util.ParseCommand import Lean.Elab.Tactic open Lean Elab Tactic -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripBodyAgeOneTactic.lean b/Benchmarks/Dss/Jug/DripBodyAgeOneTactic.lean index d6fa1230..fac50eb7 100644 --- a/Benchmarks/Dss/Jug/DripBodyAgeOneTactic.lean +++ b/Benchmarks/Dss/Jug/DripBodyAgeOneTactic.lean @@ -3,7 +3,7 @@ import Mathlib.Util.ParseCommand import Lean.Elab.Tactic open Lean Elab Tactic -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripBodyCore.lean b/Benchmarks/Dss/Jug/DripBodyCore.lean index c8b5d763..4cdb2e67 100644 --- a/Benchmarks/Dss/Jug/DripBodyCore.lean +++ b/Benchmarks/Dss/Jug/DripBodyCore.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.DripEVM -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripBodyFeeZeroTactic.lean b/Benchmarks/Dss/Jug/DripBodyFeeZeroTactic.lean index 94e8b668..0cbb35b2 100644 --- a/Benchmarks/Dss/Jug/DripBodyFeeZeroTactic.lean +++ b/Benchmarks/Dss/Jug/DripBodyFeeZeroTactic.lean @@ -3,7 +3,7 @@ import Mathlib.Util.ParseCommand import Lean.Elab.Tactic open Lean Elab Tactic -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripBodyGenericTactic.lean b/Benchmarks/Dss/Jug/DripBodyGenericTactic.lean index b5d2ec02..5cf6af68 100644 --- a/Benchmarks/Dss/Jug/DripBodyGenericTactic.lean +++ b/Benchmarks/Dss/Jug/DripBodyGenericTactic.lean @@ -6,7 +6,7 @@ import Mathlib.Util.ParseCommand import Lean.Elab.Tactic open Lean Elab Tactic -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripBodyNZeroTactic.lean b/Benchmarks/Dss/Jug/DripBodyNZeroTactic.lean index 508685a9..0afa2202 100644 --- a/Benchmarks/Dss/Jug/DripBodyNZeroTactic.lean +++ b/Benchmarks/Dss/Jug/DripBodyNZeroTactic.lean @@ -4,7 +4,7 @@ import Mathlib.Util.ParseCommand import Lean.Elab.Tactic open Lean Elab Tactic -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripEVMFold.lean b/Benchmarks/Dss/Jug/DripEVMFold.lean index b972625e..a6e48647 100644 --- a/Benchmarks/Dss/Jug/DripEVMFold.lean +++ b/Benchmarks/Dss/Jug/DripEVMFold.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.DripEVMRpow -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripEVMRpow.lean b/Benchmarks/Dss/Jug/DripEVMRpow.lean index f18747df..73ee3b8e 100644 --- a/Benchmarks/Dss/Jug/DripEVMRpow.lean +++ b/Benchmarks/Dss/Jug/DripEVMRpow.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.DripEVMVat -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripEVMVat.lean b/Benchmarks/Dss/Jug/DripEVMVat.lean index aaa7528d..41de6c87 100644 --- a/Benchmarks/Dss/Jug/DripEVMVat.lean +++ b/Benchmarks/Dss/Jug/DripEVMVat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.DripSourceFold -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripSourceFold.lean b/Benchmarks/Dss/Jug/DripSourceFold.lean index fe51d925..e7b49a21 100644 --- a/Benchmarks/Dss/Jug/DripSourceFold.lean +++ b/Benchmarks/Dss/Jug/DripSourceFold.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.DripSourceXZero -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripSourceGenericFold.lean b/Benchmarks/Dss/Jug/DripSourceGenericFold.lean index 4e397265..c757f33c 100644 --- a/Benchmarks/Dss/Jug/DripSourceGenericFold.lean +++ b/Benchmarks/Dss/Jug/DripSourceGenericFold.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.DripSourceGenericRpow -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripSourceGenericRpow.lean b/Benchmarks/Dss/Jug/DripSourceGenericRpow.lean index 7317f0e6..b649cb76 100644 --- a/Benchmarks/Dss/Jug/DripSourceGenericRpow.lean +++ b/Benchmarks/Dss/Jug/DripSourceGenericRpow.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.DripSourceRho -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripSourceNOne.lean b/Benchmarks/Dss/Jug/DripSourceNOne.lean index b343114c..e78e3c2d 100644 --- a/Benchmarks/Dss/Jug/DripSourceNOne.lean +++ b/Benchmarks/Dss/Jug/DripSourceNOne.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.DripSourceRho -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripSourceRho.lean b/Benchmarks/Dss/Jug/DripSourceRho.lean index de39d691..76104536 100644 --- a/Benchmarks/Dss/Jug/DripSourceRho.lean +++ b/Benchmarks/Dss/Jug/DripSourceRho.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.DripBase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/DripSourceXZero.lean b/Benchmarks/Dss/Jug/DripSourceXZero.lean index 9095ad94..9f4ef5a2 100644 --- a/Benchmarks/Dss/Jug/DripSourceXZero.lean +++ b/Benchmarks/Dss/Jug/DripSourceXZero.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.DripSourceNOne -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/FileBase.lean b/Benchmarks/Dss/Jug/FileBase.lean index a483c39b..27a94707 100644 --- a/Benchmarks/Dss/Jug/FileBase.lean +++ b/Benchmarks/Dss/Jug/FileBase.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Jug/FileDuty.lean b/Benchmarks/Dss/Jug/FileDuty.lean index 559c2e41..72d9be5f 100644 --- a/Benchmarks/Dss/Jug/FileDuty.lean +++ b/Benchmarks/Dss/Jug/FileDuty.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Jug.FileBase import Benchmarks.Dss.Jug.Ilks -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Jug/FileVow.lean b/Benchmarks/Dss/Jug/FileVow.lean index b0604f70..c014486c 100644 --- a/Benchmarks/Dss/Jug/FileVow.lean +++ b/Benchmarks/Dss/Jug/FileVow.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.FileBase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Jug/Ilks.lean b/Benchmarks/Dss/Jug/Ilks.lean index 59f5912b..726b458c 100644 --- a/Benchmarks/Dss/Jug/Ilks.lean +++ b/Benchmarks/Dss/Jug/Ilks.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/Init.lean b/Benchmarks/Dss/Jug/Init.lean index c379c28a..685eb412 100644 --- a/Benchmarks/Dss/Jug/Init.lean +++ b/Benchmarks/Dss/Jug/Init.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.FileDuty -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Jug/Rely.lean b/Benchmarks/Dss/Jug/Rely.lean index d1da8508..4f5a0b26 100644 --- a/Benchmarks/Dss/Jug/Rely.lean +++ b/Benchmarks/Dss/Jug/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Jug/Rpow.lean b/Benchmarks/Dss/Jug/Rpow.lean index 7b5e878c..418802aa 100644 --- a/Benchmarks/Dss/Jug/Rpow.lean +++ b/Benchmarks/Dss/Jug/Rpow.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.Arithmetic -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/RpowGeneric.lean b/Benchmarks/Dss/Jug/RpowGeneric.lean index 36e39232..567ca8a9 100644 --- a/Benchmarks/Dss/Jug/RpowGeneric.lean +++ b/Benchmarks/Dss/Jug/RpowGeneric.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.Rpow -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/Vat.lean b/Benchmarks/Dss/Jug/Vat.lean index 66d706af..8a22288f 100644 --- a/Benchmarks/Dss/Jug/Vat.lean +++ b/Benchmarks/Dss/Jug/Vat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/Vow.lean b/Benchmarks/Dss/Jug/Vow.lean index e91215be..c72b9fc3 100644 --- a/Benchmarks/Dss/Jug/Vow.lean +++ b/Benchmarks/Dss/Jug/Vow.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/Jug/Wards.lean b/Benchmarks/Dss/Jug/Wards.lean index 6f053056..ee9da131 100644 --- a/Benchmarks/Dss/Jug/Wards.lean +++ b/Benchmarks/Dss/Jug/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Jug.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Jug diff --git a/Benchmarks/Dss/LinearDecrease/Common.lean b/Benchmarks/Dss/LinearDecrease/Common.lean index d2060a86..91844d2e 100644 --- a/Benchmarks/Dss/LinearDecrease/Common.lean +++ b/Benchmarks/Dss/LinearDecrease/Common.lean @@ -7,7 +7,6 @@ import Reasoning.Solc import Reasoning.Memory import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -17,7 +16,7 @@ import Mathlib.Tactic.IntervalCases Contract-wide selector notation and constants for the optimized runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/LinearDecrease/Constructor.lean b/Benchmarks/Dss/LinearDecrease/Constructor.lean index 5274d287..3dfe834d 100644 --- a/Benchmarks/Dss/LinearDecrease/Constructor.lean +++ b/Benchmarks/Dss/LinearDecrease/Constructor.lean @@ -7,7 +7,7 @@ import Solm.Equiv # MakerDAO/Sky DSS LinearDecrease constructor correctness -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.LinearDecrease diff --git a/Benchmarks/Dss/LinearDecrease/Deny.lean b/Benchmarks/Dss/LinearDecrease/Deny.lean index bffa0e75..99e2b198 100644 --- a/Benchmarks/Dss/LinearDecrease/Deny.lean +++ b/Benchmarks/Dss/LinearDecrease/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.LinearDecrease.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/LinearDecrease/Dispatch.lean b/Benchmarks/Dss/LinearDecrease/Dispatch.lean index be2a6a41..77c6bda8 100644 --- a/Benchmarks/Dss/LinearDecrease/Dispatch.lean +++ b/Benchmarks/Dss/LinearDecrease/Dispatch.lean @@ -6,7 +6,7 @@ import Benchmarks.Dss.LinearDecrease.Trusted Solm dispatch routing facts and shared dispatcher-level proof obligations. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/LinearDecrease/File.lean b/Benchmarks/Dss/LinearDecrease/File.lean index fca570f9..e4d095f7 100644 --- a/Benchmarks/Dss/LinearDecrease/File.lean +++ b/Benchmarks/Dss/LinearDecrease/File.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.LinearDecrease.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/LinearDecrease/Price.lean b/Benchmarks/Dss/LinearDecrease/Price.lean index 5ab48f58..742294ea 100644 --- a/Benchmarks/Dss/LinearDecrease/Price.lean +++ b/Benchmarks/Dss/LinearDecrease/Price.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.LinearDecrease.Tau -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/LinearDecrease/Rely.lean b/Benchmarks/Dss/LinearDecrease/Rely.lean index 933212c1..a1a89362 100644 --- a/Benchmarks/Dss/LinearDecrease/Rely.lean +++ b/Benchmarks/Dss/LinearDecrease/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.LinearDecrease.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/LinearDecrease/Tau.lean b/Benchmarks/Dss/LinearDecrease/Tau.lean index c14a84b9..4c2bb1e9 100644 --- a/Benchmarks/Dss/LinearDecrease/Tau.lean +++ b/Benchmarks/Dss/LinearDecrease/Tau.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.LinearDecrease.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.LinearDecrease diff --git a/Benchmarks/Dss/LinearDecrease/Wards.lean b/Benchmarks/Dss/LinearDecrease/Wards.lean index 15f42200..5fc8f572 100644 --- a/Benchmarks/Dss/LinearDecrease/Wards.lean +++ b/Benchmarks/Dss/LinearDecrease/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.LinearDecrease.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.LinearDecrease diff --git a/Benchmarks/Dss/Pot/Arith.lean b/Benchmarks/Dss/Pot/Arith.lean index a0cf382a..75267b09 100644 --- a/Benchmarks/Dss/Pot/Arith.lean +++ b/Benchmarks/Dss/Pot/Arith.lean @@ -10,7 +10,7 @@ composes a genuine `.internalCall "_mul"` (discharged with `internalCallFunction followed by division by `ONE = 10^27`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/ArithExpr.lean b/Benchmarks/Dss/Pot/ArithExpr.lean index 75062a04..fe8aa443 100644 --- a/Benchmarks/Dss/Pot/ArithExpr.lean +++ b/Benchmarks/Dss/Pot/ArithExpr.lean @@ -10,7 +10,7 @@ contract-independent (it only exercises `evalExpr?`/`Store` on the binary-locals touches Pot's storage layout or external ABI), so all are flagged `LIBRARY CANDIDATE`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/Cage.lean b/Benchmarks/Dss/Pot/Cage.lean index 34524d49..20b584f2 100644 --- a/Benchmarks/Dss/Pot/Cage.lean +++ b/Benchmarks/Dss/Pot/Cage.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Pot.Rely import Benchmarks.Dss.Pot.Arith -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/Chi.lean b/Benchmarks/Dss/Pot/Chi.lean index e256c61c..08a450dc 100644 --- a/Benchmarks/Dss/Pot/Chi.lean +++ b/Benchmarks/Dss/Pot/Chi.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Pot diff --git a/Benchmarks/Dss/Pot/Common.lean b/Benchmarks/Dss/Pot/Common.lean index 16b29a13..acd02e14 100644 --- a/Benchmarks/Dss/Pot/Common.lean +++ b/Benchmarks/Dss/Pot/Common.lean @@ -7,7 +7,6 @@ import Reasoning.Solc import Reasoning.Memory import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -18,7 +17,7 @@ Contract-wide selector notation and constants for the optimized Pot runtime. Ada fully-proved sibling `Benchmarks/Dss/Jug` (same compiler, shared math helpers/auth/external calls). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/Correct.lean b/Benchmarks/Dss/Pot/Correct.lean index 308e8c43..ff801eb9 100644 --- a/Benchmarks/Dss/Pot/Correct.lean +++ b/Benchmarks/Dss/Pot/Correct.lean @@ -26,7 +26,7 @@ adds the shared revert paths (non-payable guard, no-dispatch), and packages the the runtime target into the whole-contract equivalence. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/Deny.lean b/Benchmarks/Dss/Pot/Deny.lean index 0915dc6a..082e370e 100644 --- a/Benchmarks/Dss/Pot/Deny.lean +++ b/Benchmarks/Dss/Pot/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/Dispatch.lean b/Benchmarks/Dss/Pot/Dispatch.lean index 8bcd58a8..210c7f74 100644 --- a/Benchmarks/Dss/Pot/Dispatch.lean +++ b/Benchmarks/Dss/Pot/Dispatch.lean @@ -18,7 +18,7 @@ Linear-scan groups (arm order = bytecode order): * `54` : deny, drip, wards, chi, file(bytes32,address) (`sel ≥ 0x9c52a7f1`) -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/Drip.lean b/Benchmarks/Dss/Pot/Drip.lean index 05725b0f..47c7f6de 100644 --- a/Benchmarks/Dss/Pot/Drip.lean +++ b/Benchmarks/Dss/Pot/Drip.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Pot.DripSuckBase import Benchmarks.Dss.Pot.DripSource -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/DripCommon.lean b/Benchmarks/Dss/Pot/DripCommon.lean index 10848039..ed91c6c8 100644 --- a/Benchmarks/Dss/Pot/DripCommon.lean +++ b/Benchmarks/Dss/Pot/DripCommon.lean @@ -14,7 +14,7 @@ the EVM and Solm sides, and the storage-word abbreviations used throughout the ` chi=tmp ; rho=now ; rad=_mul(Pie,chi_) ; vat.suck(vow,this,rad) ; return tmp`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/DripEVMArith.lean b/Benchmarks/Dss/Pot/DripEVMArith.lean index b2eca478..73b40d7f 100644 --- a/Benchmarks/Dss/Pot/DripEVMArith.lean +++ b/Benchmarks/Dss/Pot/DripEVMArith.lean @@ -4,7 +4,7 @@ import Benchmarks.Dss.Pot.DripCommon # Pot `drip()` — EVM-side internal-arithmetic traces (`@1894`–`@2005`) -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/DripEVMSuck.lean b/Benchmarks/Dss/Pot/DripEVMSuck.lean index d2a09780..aa8f1011 100644 --- a/Benchmarks/Dss/Pot/DripEVMSuck.lean +++ b/Benchmarks/Dss/Pot/DripEVMSuck.lean @@ -7,7 +7,7 @@ Mirrors Jug's `Benchmarks/Dss/Jug/DripEVMFold.lean`. Entry `@1960` after the `ch stores, exit either at the string/empty revert (`RDrev`) or the `return tmp` epilogue (`RDret`). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/DripSource.lean b/Benchmarks/Dss/Pot/DripSource.lean index 15f8e55b..11f51dc4 100644 --- a/Benchmarks/Dss/Pot/DripSource.lean +++ b/Benchmarks/Dss/Pot/DripSource.lean @@ -15,7 +15,7 @@ mutate the EVM state, so the later `Pie`/`vat`/`vow` reads are threaded through state and reduced back to the original words with the storage-store/load preservation lemmas. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/DripSuckBase.lean b/Benchmarks/Dss/Pot/DripSuckBase.lean index ea633018..7f9ab1e8 100644 --- a/Benchmarks/Dss/Pot/DripSuckBase.lean +++ b/Benchmarks/Dss/Pot/DripSuckBase.lean @@ -8,7 +8,7 @@ The `suck` call encodes selector `0xf24e23eb` + `[address vow, address this, uin (100-byte calldata) built at the free pointer `0x80` on top of the initial `solcFreePtrMem`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/Dsr.lean b/Benchmarks/Dss/Pot/Dsr.lean index 951ddba0..65370ecb 100644 --- a/Benchmarks/Dss/Pot/Dsr.lean +++ b/Benchmarks/Dss/Pot/Dsr.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Pot diff --git a/Benchmarks/Dss/Pot/Exit.lean b/Benchmarks/Dss/Pot/Exit.lean index 0efc5dce..a216b790 100644 --- a/Benchmarks/Dss/Pot/Exit.lean +++ b/Benchmarks/Dss/Pot/Exit.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Pot.Dispatch import Benchmarks.Dss.Pot.Join import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/FileDsr.lean b/Benchmarks/Dss/Pot/FileDsr.lean index 8a83d323..2fa39d36 100644 --- a/Benchmarks/Dss/Pot/FileDsr.lean +++ b/Benchmarks/Dss/Pot/FileDsr.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Pot/FileVow.lean b/Benchmarks/Dss/Pot/FileVow.lean index be84f36e..07abcc58 100644 --- a/Benchmarks/Dss/Pot/FileVow.lean +++ b/Benchmarks/Dss/Pot/FileVow.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.FileDsr -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Pot/Join.lean b/Benchmarks/Dss/Pot/Join.lean index 2db32f30..b7095297 100644 --- a/Benchmarks/Dss/Pot/Join.lean +++ b/Benchmarks/Dss/Pot/Join.lean @@ -3,7 +3,7 @@ import Benchmarks.Dss.Pot.Arith import Reasoning.ExternalCall import Reasoning.Initcode -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/Live.lean b/Benchmarks/Dss/Pot/Live.lean index 80e57f07..af533782 100644 --- a/Benchmarks/Dss/Pot/Live.lean +++ b/Benchmarks/Dss/Pot/Live.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Pot diff --git a/Benchmarks/Dss/Pot/Pie.lean b/Benchmarks/Dss/Pot/Pie.lean index a08e522b..4e22ea3c 100644 --- a/Benchmarks/Dss/Pot/Pie.lean +++ b/Benchmarks/Dss/Pot/Pie.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Pot diff --git a/Benchmarks/Dss/Pot/PieTotal.lean b/Benchmarks/Dss/Pot/PieTotal.lean index 1eb9093a..635d25ba 100644 --- a/Benchmarks/Dss/Pot/PieTotal.lean +++ b/Benchmarks/Dss/Pot/PieTotal.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Pot diff --git a/Benchmarks/Dss/Pot/Rely.lean b/Benchmarks/Dss/Pot/Rely.lean index 9027421f..3c6cf81f 100644 --- a/Benchmarks/Dss/Pot/Rely.lean +++ b/Benchmarks/Dss/Pot/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/Rho.lean b/Benchmarks/Dss/Pot/Rho.lean index 770b8830..51dc7b40 100644 --- a/Benchmarks/Dss/Pot/Rho.lean +++ b/Benchmarks/Dss/Pot/Rho.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Pot diff --git a/Benchmarks/Dss/Pot/Rpow.lean b/Benchmarks/Dss/Pot/Rpow.lean index 2e718ce6..a6cce595 100644 --- a/Benchmarks/Dss/Pot/Rpow.lean +++ b/Benchmarks/Dss/Pot/Rpow.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.RpowLoop -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Pot diff --git a/Benchmarks/Dss/Pot/RpowGeneric.lean b/Benchmarks/Dss/Pot/RpowGeneric.lean index 18b9e7a3..c6e258c5 100644 --- a/Benchmarks/Dss/Pot/RpowGeneric.lean +++ b/Benchmarks/Dss/Pot/RpowGeneric.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.Rpow -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Pot diff --git a/Benchmarks/Dss/Pot/RpowLoop.lean b/Benchmarks/Dss/Pot/RpowLoop.lean index ac3fcfe5..e77a5c5f 100644 --- a/Benchmarks/Dss/Pot/RpowLoop.lean +++ b/Benchmarks/Dss/Pot/RpowLoop.lean @@ -10,7 +10,7 @@ Every declaration here is contract-independent (`LIBRARY CANDIDATE`): it exercis `evalExpr?`/`Store` on the ternary/rpow locals frame. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Pot/Vat.lean b/Benchmarks/Dss/Pot/Vat.lean index 78893959..b87f82d1 100644 --- a/Benchmarks/Dss/Pot/Vat.lean +++ b/Benchmarks/Dss/Pot/Vat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Pot diff --git a/Benchmarks/Dss/Pot/Vow.lean b/Benchmarks/Dss/Pot/Vow.lean index 08d0c623..20f400dd 100644 --- a/Benchmarks/Dss/Pot/Vow.lean +++ b/Benchmarks/Dss/Pot/Vow.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Pot diff --git a/Benchmarks/Dss/Pot/Wards.lean b/Benchmarks/Dss/Pot/Wards.lean index 572b136e..21dd3a1c 100644 --- a/Benchmarks/Dss/Pot/Wards.lean +++ b/Benchmarks/Dss/Pot/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Pot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Pot diff --git a/Benchmarks/Dss/Spot/Cage.lean b/Benchmarks/Dss/Spot/Cage.lean index 5b59628a..5a50178b 100644 --- a/Benchmarks/Dss/Spot/Cage.lean +++ b/Benchmarks/Dss/Spot/Cage.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Spot/Common.lean b/Benchmarks/Dss/Spot/Common.lean index edacda7f..fdde94f6 100644 --- a/Benchmarks/Dss/Spot/Common.lean +++ b/Benchmarks/Dss/Spot/Common.lean @@ -7,7 +7,6 @@ import Reasoning.Solc import Reasoning.Memory import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -17,7 +16,7 @@ import Mathlib.Tactic.IntervalCases Contract-wide selector notation and constants for the optimized Spotter runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Spot/Correct.lean b/Benchmarks/Dss/Spot/Correct.lean index dfed380e..f12523e8 100644 --- a/Benchmarks/Dss/Spot/Correct.lean +++ b/Benchmarks/Dss/Spot/Correct.lean @@ -21,7 +21,7 @@ are present. The runtime-equivalence proof is intentionally left as the benchmar also exposes the whole-contract wrapper that combines the constructor and runtime targets. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Spot/Deny.lean b/Benchmarks/Dss/Spot/Deny.lean index 7c3fd04a..b2c83b1c 100644 --- a/Benchmarks/Dss/Spot/Deny.lean +++ b/Benchmarks/Dss/Spot/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Spot/Dispatch.lean b/Benchmarks/Dss/Spot/Dispatch.lean index b85a65f4..b79fa306 100644 --- a/Benchmarks/Dss/Spot/Dispatch.lean +++ b/Benchmarks/Dss/Spot/Dispatch.lean @@ -6,7 +6,7 @@ import Benchmarks.Dss.Spot.Trusted Solm dispatch routing facts and the shared non-payable/no-selector runtime paths. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Spot/FileMat.lean b/Benchmarks/Dss/Spot/FileMat.lean index a4569348..0c6654d6 100644 --- a/Benchmarks/Dss/Spot/FileMat.lean +++ b/Benchmarks/Dss/Spot/FileMat.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Spot.FilePar import Benchmarks.Dss.Spot.Ilks import Benchmarks.Dss.Jug.FileDuty -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Spot/FilePar.lean b/Benchmarks/Dss/Spot/FilePar.lean index a5970820..03371b21 100644 --- a/Benchmarks/Dss/Spot/FilePar.lean +++ b/Benchmarks/Dss/Spot/FilePar.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Spot.Rely import Benchmarks.Dss.Jug.FileBase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Spot/FilePip.lean b/Benchmarks/Dss/Spot/FilePip.lean index 2f938a29..ea7f8bed 100644 --- a/Benchmarks/Dss/Spot/FilePip.lean +++ b/Benchmarks/Dss/Spot/FilePip.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.FileMat -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Spot/Ilks.lean b/Benchmarks/Dss/Spot/Ilks.lean index dc2568a1..7f03acdf 100644 --- a/Benchmarks/Dss/Spot/Ilks.lean +++ b/Benchmarks/Dss/Spot/Ilks.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Spot.Dispatch import Benchmarks.Dss.Jug.Ilks -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Spot/Live.lean b/Benchmarks/Dss/Spot/Live.lean index a4e3b372..c7181a20 100644 --- a/Benchmarks/Dss/Spot/Live.lean +++ b/Benchmarks/Dss/Spot/Live.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Spot diff --git a/Benchmarks/Dss/Spot/Par.lean b/Benchmarks/Dss/Spot/Par.lean index 6ce4e765..b792ed13 100644 --- a/Benchmarks/Dss/Spot/Par.lean +++ b/Benchmarks/Dss/Spot/Par.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Spot diff --git a/Benchmarks/Dss/Spot/Poke.lean b/Benchmarks/Dss/Spot/Poke.lean index 755ce73e..9ff72c0b 100644 --- a/Benchmarks/Dss/Spot/Poke.lean +++ b/Benchmarks/Dss/Spot/Poke.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.PokeTraceBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Spot diff --git a/Benchmarks/Dss/Spot/PokeArithmetic.lean b/Benchmarks/Dss/Spot/PokeArithmetic.lean index d3abf2c6..7e61a5bf 100644 --- a/Benchmarks/Dss/Spot/PokeArithmetic.lean +++ b/Benchmarks/Dss/Spot/PokeArithmetic.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.PokeDecode -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Spot diff --git a/Benchmarks/Dss/Spot/PokeBase.lean b/Benchmarks/Dss/Spot/PokeBase.lean index 159e20d6..0249e11c 100644 --- a/Benchmarks/Dss/Spot/PokeBase.lean +++ b/Benchmarks/Dss/Spot/PokeBase.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Spot.Ilks import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Spot diff --git a/Benchmarks/Dss/Spot/PokeCalls.lean b/Benchmarks/Dss/Spot/PokeCalls.lean index e4791c48..427c1163 100644 --- a/Benchmarks/Dss/Spot/PokeCalls.lean +++ b/Benchmarks/Dss/Spot/PokeCalls.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.PokeArithmetic -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Spot diff --git a/Benchmarks/Dss/Spot/PokeDecode.lean b/Benchmarks/Dss/Spot/PokeDecode.lean index 111f0824..1e31343c 100644 --- a/Benchmarks/Dss/Spot/PokeDecode.lean +++ b/Benchmarks/Dss/Spot/PokeDecode.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.PokeBase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Spot diff --git a/Benchmarks/Dss/Spot/PokeSource.lean b/Benchmarks/Dss/Spot/PokeSource.lean index 676f0a53..dd9e3aee 100644 --- a/Benchmarks/Dss/Spot/PokeSource.lean +++ b/Benchmarks/Dss/Spot/PokeSource.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.PokeCalls -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Spot diff --git a/Benchmarks/Dss/Spot/PokeTrace.lean b/Benchmarks/Dss/Spot/PokeTrace.lean index 75e383a7..95318ad6 100644 --- a/Benchmarks/Dss/Spot/PokeTrace.lean +++ b/Benchmarks/Dss/Spot/PokeTrace.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.PokeSource -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Spot diff --git a/Benchmarks/Dss/Spot/PokeTraceBody.lean b/Benchmarks/Dss/Spot/PokeTraceBody.lean index 0e7256e9..332407f6 100644 --- a/Benchmarks/Dss/Spot/PokeTraceBody.lean +++ b/Benchmarks/Dss/Spot/PokeTraceBody.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.PokeTrace -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Spot diff --git a/Benchmarks/Dss/Spot/Rely.lean b/Benchmarks/Dss/Spot/Rely.lean index 1a9e186b..292529ea 100644 --- a/Benchmarks/Dss/Spot/Rely.lean +++ b/Benchmarks/Dss/Spot/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Spot/Vat.lean b/Benchmarks/Dss/Spot/Vat.lean index 6ef99ee8..dc6a30ad 100644 --- a/Benchmarks/Dss/Spot/Vat.lean +++ b/Benchmarks/Dss/Spot/Vat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Spot diff --git a/Benchmarks/Dss/Spot/Wards.lean b/Benchmarks/Dss/Spot/Wards.lean index 9188b31d..d14d1f26 100644 --- a/Benchmarks/Dss/Spot/Wards.lean +++ b/Benchmarks/Dss/Spot/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Spot.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Spot diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Common.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Common.lean index 0af84130..c3f13290 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Common.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Common.lean @@ -7,7 +7,6 @@ import Reasoning.Solc import Reasoning.Memory import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -17,7 +16,7 @@ import Mathlib.Tactic.IntervalCases Contract-wide selector notation and constants for the optimized runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Constructor.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Constructor.lean index e41ccbe0..83acaf82 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Constructor.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Constructor.lean @@ -7,7 +7,7 @@ import Solm.Equiv # MakerDAO/Sky DSS StairstepExponentialDecrease constructor correctness -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.StairstepExponentialDecrease diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Correct.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Correct.lean index babb2f19..219f88ab 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Correct.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Correct.lean @@ -16,7 +16,7 @@ are present. The runtime-equivalence proof is intentionally left as the benchmar also exposes the whole-contract wrapper that combines the constructor and runtime targets. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Cut.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Cut.lean index 99bdd0c6..6b9b23f4 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Cut.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Cut.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.StairstepExponentialDecrease.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.StairstepExponentialDecrease diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Deny.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Deny.lean index c03d65cb..18b6f3e0 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Deny.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.StairstepExponentialDecrease.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Dispatch.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Dispatch.lean index 193ceedf..32f58b0b 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Dispatch.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Dispatch.lean @@ -6,7 +6,7 @@ import Benchmarks.Dss.StairstepExponentialDecrease.Trusted Solm dispatch routing facts and shared dispatcher-level proof obligations. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/File.lean b/Benchmarks/Dss/StairstepExponentialDecrease/File.lean index 0bb8fe12..a8058de6 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/File.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/File.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.StairstepExponentialDecrease.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Price.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Price.lean index 3926115f..52f92ee4 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Price.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Price.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.StairstepExponentialDecrease.PriceSource -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/PriceSource.lean b/Benchmarks/Dss/StairstepExponentialDecrease/PriceSource.lean index 2ca99e35..85181f79 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/PriceSource.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/PriceSource.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.StairstepExponentialDecrease.RpowEVM -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Rely.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Rely.lean index 9896a1aa..87b39a05 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Rely.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.StairstepExponentialDecrease.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/RpowArithmeticExpr.lean b/Benchmarks/Dss/StairstepExponentialDecrease/RpowArithmeticExpr.lean index 462f0dca..76126ec2 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/RpowArithmeticExpr.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/RpowArithmeticExpr.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.StairstepExponentialDecrease.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/RpowArithmeticLocals.lean b/Benchmarks/Dss/StairstepExponentialDecrease/RpowArithmeticLocals.lean index d8a3234a..33bc063f 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/RpowArithmeticLocals.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/RpowArithmeticLocals.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.StairstepExponentialDecrease.RpowArithmeticExpr -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/RpowArithmeticLoop.lean b/Benchmarks/Dss/StairstepExponentialDecrease/RpowArithmeticLoop.lean index 464c0766..f5425c0c 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/RpowArithmeticLoop.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/RpowArithmeticLoop.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.StairstepExponentialDecrease.RpowArithmeticLocals -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/RpowEVM.lean b/Benchmarks/Dss/StairstepExponentialDecrease/RpowEVM.lean index 3dedbde7..c7fe9ecf 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/RpowEVM.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/RpowEVM.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.StairstepExponentialDecrease.RpowSource -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/RpowSource.lean b/Benchmarks/Dss/StairstepExponentialDecrease/RpowSource.lean index de7ba016..82f8f420 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/RpowSource.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/RpowSource.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.StairstepExponentialDecrease.RpowArithmeticLoop -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.StairstepExponentialDecrease diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Step.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Step.lean index 7941e980..f2594422 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Step.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Step.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.StairstepExponentialDecrease.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.StairstepExponentialDecrease diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Wards.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Wards.lean index 0f4c502b..9a7aa38e 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Wards.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.StairstepExponentialDecrease.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.StairstepExponentialDecrease diff --git a/Benchmarks/Dss/Vat/Cage.lean b/Benchmarks/Dss/Vat/Cage.lean index 5d4e9248..bf7f12b0 100644 --- a/Benchmarks/Dss/Vat/Cage.lean +++ b/Benchmarks/Dss/Vat/Cage.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 50000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vat/Can.lean b/Benchmarks/Dss/Vat/Can.lean index ba53b171..4176bb8a 100644 --- a/Benchmarks/Dss/Vat/Can.lean +++ b/Benchmarks/Dss/Vat/Can.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/Common.lean b/Benchmarks/Dss/Vat/Common.lean index d2a0fece..69f26dbd 100644 --- a/Benchmarks/Dss/Vat/Common.lean +++ b/Benchmarks/Dss/Vat/Common.lean @@ -2,7 +2,6 @@ import Benchmarks.Dss.Vat.Bytecode import Reasoning.ABI import Reasoning.Dispatch import Reasoning.Memory -import Reasoning.Refinement import Reasoning.SolmBody import Reasoning.Solc import Reasoning.Stepping @@ -16,7 +15,7 @@ import Mathlib.Tactic.IntervalCases Contract-wide selector notation and proof-shape abbreviations for the optimized Vat runtime. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Vat diff --git a/Benchmarks/Dss/Vat/Correct.lean b/Benchmarks/Dss/Vat/Correct.lean index 82e63b7b..ea3cbb29 100644 --- a/Benchmarks/Dss/Vat/Correct.lean +++ b/Benchmarks/Dss/Vat/Correct.lean @@ -27,7 +27,6 @@ import Benchmarks.Dss.Vat.Suck import Benchmarks.Dss.Vat.Urns import Benchmarks.Dss.Vat.Vice import Benchmarks.Dss.Vat.Wards -import Reasoning.Refinement import Solm.Equiv /-! @@ -38,7 +37,7 @@ are present. The runtime-equivalence proof is intentionally left as the benchmar also exposes the whole-contract wrapper that combines the constructor and runtime targets. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/Dai.lean b/Benchmarks/Dss/Vat/Dai.lean index 09eda17c..ab6f1856 100644 --- a/Benchmarks/Dss/Vat/Dai.lean +++ b/Benchmarks/Dss/Vat/Dai.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/Debt.lean b/Benchmarks/Dss/Vat/Debt.lean index fe3f6c7d..422924ad 100644 --- a/Benchmarks/Dss/Vat/Debt.lean +++ b/Benchmarks/Dss/Vat/Debt.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Vat diff --git a/Benchmarks/Dss/Vat/Deny.lean b/Benchmarks/Dss/Vat/Deny.lean index 8153ffb1..ce36f10c 100644 --- a/Benchmarks/Dss/Vat/Deny.lean +++ b/Benchmarks/Dss/Vat/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 50000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vat/Dispatch.lean b/Benchmarks/Dss/Vat/Dispatch.lean index f6dadbda..5a81e457 100644 --- a/Benchmarks/Dss/Vat/Dispatch.lean +++ b/Benchmarks/Dss/Vat/Dispatch.lean @@ -7,7 +7,7 @@ This file is the local home for Solm dispatch routing facts and shared dispatche infrastructure. The first scaffold pass keeps the hard EVM reachability leaves as body stubs. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/FileIlk.lean b/Benchmarks/Dss/Vat/FileIlk.lean index e0366f41..4c6ab78a 100644 --- a/Benchmarks/Dss/Vat/FileIlk.lean +++ b/Benchmarks/Dss/Vat/FileIlk.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Vat.FileLine import Benchmarks.Dss.Vat.Ilks -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 50000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Vat/FileLine.lean b/Benchmarks/Dss/Vat/FileLine.lean index 97febdcf..92743ee6 100644 --- a/Benchmarks/Dss/Vat/FileLine.lean +++ b/Benchmarks/Dss/Vat/FileLine.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 50000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/Dss/Vat/Flux.lean b/Benchmarks/Dss/Vat/Flux.lean index 722d0628..9cce3f3b 100644 --- a/Benchmarks/Dss/Vat/Flux.lean +++ b/Benchmarks/Dss/Vat/Flux.lean @@ -4,7 +4,7 @@ import Benchmarks.Dss.Vat.Hope namespace Benchmarks.Dss.Vat -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/Fold.lean b/Benchmarks/Dss/Vat/Fold.lean index ec3313e7..7197bb45 100644 --- a/Benchmarks/Dss/Vat/Fold.lean +++ b/Benchmarks/Dss/Vat/Fold.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Vat.FoldTail namespace Benchmarks.Dss.Vat -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/FoldCommon.lean b/Benchmarks/Dss/Vat/FoldCommon.lean index 94ca27ba..27d4c6a2 100644 --- a/Benchmarks/Dss/Vat/FoldCommon.lean +++ b/Benchmarks/Dss/Vat/FoldCommon.lean @@ -3,7 +3,7 @@ import Benchmarks.Dss.Vat.Signed namespace Benchmarks.Dss.Vat -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach /-! ## Shared definitions for `fold(bytes32,address,int256)` -/ @@ -1354,10 +1354,10 @@ theorem vatFoldSourceRevertAfterDaiBlock (evm evmRate : EVM.State) (I : Executio · exact evalCallvalueEq_true hwv refine ExecBlock.consNormal (ExecStmt.requireTrue hauth) ?_ exact ExecBlock.consNormal (ExecStmt.requireTrue hlive) ExecBlock.nil - have h01 := Reasoning.Refinement.execBlock_append hprefix hrateOk - have h02 := Reasoning.Refinement.execBlock_append h01 hradOk - have h03 := Reasoning.Refinement.execBlock_append h02 hdaiRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hrateOk + have h02 :=.execBlock_append h01 hradOk + have h03 :=.execBlock_append h02 hdaiRevert + have hblock :=.execBlock_append_term (s2 := [ .assign .storage (daiRef (.var "u")) (.var "daiNew") ] ++ checkedAddSignedInto "debtNew" (.storage debtRef) (.var "rad") ++ @@ -1411,12 +1411,12 @@ theorem vatFoldSourceRevertAfterDebtBlock · exact evalCallvalueEq_true hwv refine ExecBlock.consNormal (ExecStmt.requireTrue hauth) ?_ exact ExecBlock.consNormal (ExecStmt.requireTrue hlive) ExecBlock.nil - have h01 := Reasoning.Refinement.execBlock_append hprefix hrateOk - have h02 := Reasoning.Refinement.execBlock_append h01 hradOk - have h03 := Reasoning.Refinement.execBlock_append h02 hdaiOk - have h04 := Reasoning.Refinement.execBlock_append h03 hdaiAssign - have h05 := Reasoning.Refinement.execBlock_append h04 hdebtRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hrateOk + have h02 :=.execBlock_append h01 hradOk + have h03 :=.execBlock_append h02 hdaiOk + have h04 :=.execBlock_append h03 hdaiAssign + have h05 :=.execBlock_append h04 hdebtRevert + have hblock :=.execBlock_append_term (s2 := [ .assign .storage debtRef (.var "debtNew") ]) h05 (by intro f e h; cases h) simpa [ExecTransitionBody, foldTransition, nonpayable, auth, requireLive, diff --git a/Benchmarks/Dss/Vat/FoldTail.lean b/Benchmarks/Dss/Vat/FoldTail.lean index c48b1686..c54c805d 100644 --- a/Benchmarks/Dss/Vat/FoldTail.lean +++ b/Benchmarks/Dss/Vat/FoldTail.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Vat.FoldCommon namespace Benchmarks.Dss.Vat -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -285,8 +285,8 @@ theorem vatFoldSourceRevertAfterRateBlock (evm : EVM.State) (I : ExecutionEnv) · exact evalCallvalueEq_true hwv refine ExecBlock.consNormal (ExecStmt.requireTrue hauth) ?_ exact ExecBlock.consNormal (ExecStmt.requireTrue hlive) ExecBlock.nil - have h01 := Reasoning.Refinement.execBlock_append hprefix hrateRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hrateRevert + have hblock :=.execBlock_append_term (s2 := [ .assign .storage (ilksF (.var "i") "rate") (.var "rateNew") ] ++ checkedMulSignedInto "rad" (.storage (ilksF (.var "i") "Art")) (.var "rate") ++ @@ -330,9 +330,9 @@ theorem vatFoldSourceRevertAfterRadBlock (evm evmRate : EVM.State) (I : Executio · exact evalCallvalueEq_true hwv refine ExecBlock.consNormal (ExecStmt.requireTrue hauth) ?_ exact ExecBlock.consNormal (ExecStmt.requireTrue hlive) ExecBlock.nil - have h01 := Reasoning.Refinement.execBlock_append hprefix hrateOk - have h02 := Reasoning.Refinement.execBlock_append h01 hradRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hrateOk + have h02 :=.execBlock_append h01 hradRevert + have hblock :=.execBlock_append_term (s2 := checkedAddSignedInto "daiNew" (.storage (daiRef (.var "u"))) (.var "rad") ++ [ .assign .storage (daiRef (.var "u")) (.var "daiNew") ] ++ @@ -757,12 +757,12 @@ theorem vatFoldSourceSuccess (evm : EVM.State) (I : ExecutionEnv) (by simpa [evmDai, evmRate, storageStore_executionEnv] using hDebtGuardPos) have hdebtAssign := vatFoldAssignDebtOk evmDai I (rateNew := rateNew) (rad := rad) (daiNew := daiNew) (debtNew := debtNew) - have h01 := Reasoning.Refinement.execBlock_append hprefix hrateBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hradBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hdaiBlock - have h04 := Reasoning.Refinement.execBlock_append h03 hdaiAssign - have h05 := Reasoning.Refinement.execBlock_append h04 hdebtBlock - have hblock := Reasoning.Refinement.execBlock_append h05 hdebtAssign + have h01 :=.execBlock_append hprefix hrateBlock + have h02 :=.execBlock_append h01 hradBlock + have h03 :=.execBlock_append h02 hdaiBlock + have h04 :=.execBlock_append h03 hdaiAssign + have h05 :=.execBlock_append h04 hdebtBlock + have hblock :=.execBlock_append h05 hdebtAssign simpa [ExecTransitionBody, foldTransition, nonpayable, auth, requireLive, List.append_assoc, evmRate, evmDai, foldPostState, storageStore_executionEnv] using ExecFuncBody.execBlockOK hblock diff --git a/Benchmarks/Dss/Vat/Fork.lean b/Benchmarks/Dss/Vat/Fork.lean index 992eaa9d..b3a60341 100644 --- a/Benchmarks/Dss/Vat/Fork.lean +++ b/Benchmarks/Dss/Vat/Fork.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Vat.Signed namespace Benchmarks.Dss.Vat -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -2750,7 +2750,7 @@ theorem execForkSrcInkUpdateRevertGuardNeg {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hdinkAfter) (by simpa [locals'] using hstorageAfter) (forkDinkSubGuardNegFailCond hfail) - exact Reasoning.Refinement.execBlock_append_term hsub (by intro f e h; cases h) + exact.execBlock_append_term hsub (by intro f e h; cases h) theorem execForkSrcInkUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (srcInkOld srcInkNew : UInt256) @@ -2834,7 +2834,7 @@ theorem execForkSrcInkUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hstorageAfter) (by simpa [locals'] using hguardNegEval) (forkDinkSubGuardPosFailCond hfail) - exact Reasoning.Refinement.execBlock_append_term hsub (by intro f e h; cases h) + exact.execBlock_append_term hsub (by intro f e h; cases h) theorem execForkSrcArtUpdateOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (srcArtOld srcArtNew : UInt256) @@ -3023,7 +3023,7 @@ theorem execForkSrcArtUpdateRevertGuardNeg {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hdartAfter) (by simpa [locals'] using hstorageAfter) (forkDartSubGuardNegFailCond hfail) - exact Reasoning.Refinement.execBlock_append_term hsub (by intro f e h; cases h) + exact.execBlock_append_term hsub (by intro f e h; cases h) theorem execForkSrcArtUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (srcArtOld srcArtNew : UInt256) @@ -3107,7 +3107,7 @@ theorem execForkSrcArtUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hstorageAfter) (by simpa [locals'] using hguardNegEval) (forkDartSubGuardPosFailCond hfail) - exact Reasoning.Refinement.execBlock_append_term hsub (by intro f e h; cases h) + exact.execBlock_append_term hsub (by intro f e h; cases h) theorem execForkDstInkUpdateOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (dstInkOld dstInkNew : UInt256) @@ -3293,7 +3293,7 @@ theorem execForkDstInkUpdateRevertGuardNeg {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hdinkAfter) (by simpa [locals'] using hstorageAfter) (forkDinkAddGuardNegFailCond hfail) - exact Reasoning.Refinement.execBlock_append_term hadd (by intro f e h; cases h) + exact.execBlock_append_term hadd (by intro f e h; cases h) theorem execForkDstInkUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (dstInkOld dstInkNew : UInt256) @@ -3375,7 +3375,7 @@ theorem execForkDstInkUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hstorageAfter) (by simpa [locals'] using hguardNegEval) (forkDinkAddGuardPosFailCond hfail) - exact Reasoning.Refinement.execBlock_append_term hadd (by intro f e h; cases h) + exact.execBlock_append_term hadd (by intro f e h; cases h) theorem execForkDstArtUpdateOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (dstArtOld dstArtNew : UInt256) @@ -3561,7 +3561,7 @@ theorem execForkDstArtUpdateRevertGuardNeg {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hdartAfter) (by simpa [locals'] using hstorageAfter) (forkDartAddGuardNegFailCond hfail) - exact Reasoning.Refinement.execBlock_append_term hadd (by intro f e h; cases h) + exact.execBlock_append_term hadd (by intro f e h; cases h) theorem execForkDstArtUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (dstArtOld dstArtNew : UInt256) @@ -3643,7 +3643,7 @@ theorem execForkDstArtUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hstorageAfter) (by simpa [locals'] using hguardNegEval) (forkDartAddGuardPosFailCond hfail) - exact Reasoning.Refinement.execBlock_append_term hadd (by intro f e h; cases h) + exact.execBlock_append_term hadd (by intro f e h; cases h) theorem execForkFinalLoadsOk {evm : EVM.State} {I : ExecutionEnv} (srcInkNew srcArtNew dstInkNew dstArtNew @@ -7516,16 +7516,16 @@ theorem execForkSourceOk {evm0 : EVM.State} {I : ExecutionEnv} (.binary .eq (.var "dstArtFinal") (.intLit 0))) ] (.ok { contract := contract, locals := finalLocals } evm4) := execForkFinalRequiresOk hwish hutabLe hvtabLe hsrcDust hdstDust - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hsrcArtBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hdstInkBlock - have h04 := Reasoning.Refinement.execBlock_append h03 hdstArtBlock - have h05 := Reasoning.Refinement.execBlock_append h04 hfinalLoadsBlock - have h06 := Reasoning.Refinement.execBlock_append h05 hutabBlock - have h06 := Reasoning.Refinement.execBlock_append h06 hvtabBlock - have h07 := Reasoning.Refinement.execBlock_append h06 hsrcInkSpotBlock - have hblock := Reasoning.Refinement.execBlock_append h07 hdstInkSpotBlock - have hblock := Reasoning.Refinement.execBlock_append hblock hfinalBlock + have h01 :=.execBlock_append hprefix hsrcInkBlock + have h02 :=.execBlock_append h01 hsrcArtBlock + have h03 :=.execBlock_append h02 hdstInkBlock + have h04 :=.execBlock_append h03 hdstArtBlock + have h05 :=.execBlock_append h04 hfinalLoadsBlock + have h06 :=.execBlock_append h05 hutabBlock + have h06 :=.execBlock_append h06 hvtabBlock + have h07 :=.execBlock_append h06 hsrcInkSpotBlock + have hblock :=.execBlock_append h07 hdstInkSpotBlock + have hblock :=.execBlock_append hblock hfinalBlock simpa [ExecTransitionBody, forkTransition, nonpayable, checkedSubSignedInto, checkedAddSignedInto, checkedMulUintInto, List.append_assoc, storageStore_executionEnv] using ExecFuncBody.execBlockOK hblock @@ -7559,8 +7559,8 @@ theorem execForkSourceRevertSrcInkGuardNeg {evm0 : EVM.State} {I : ExecutionEnv} execForkSrcInkUpdateRevertGuardNeg (evm := evm0) (I := I) (locals := forkStore I) srcInkOld srcInkNew hsz164 (forkStore_get_ilk I) (forkStore_get_src I) (forkStore_get_dink I) (forkStore_urns I) hloadSrcInk hsrcInkNew hfail - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsrcInkRevert + have hblock :=.execBlock_append_term (s2 := checkedSubSignedInto "srcArtNew" (.storage (urnsF (.var "ilk") (.var "src") "art")) (.var "dart") ++ @@ -7638,8 +7638,8 @@ theorem execForkSourceRevertSrcInkGuardPos {evm0 : EVM.State} {I : ExecutionEnv} execForkSrcInkUpdateRevertGuardPos (evm := evm0) (I := I) (locals := forkStore I) srcInkOld srcInkNew hsz164 (forkStore_get_ilk I) (forkStore_get_src I) (forkStore_get_dink I) (forkStore_urns I) hloadSrcInk hsrcInkNew hguardNeg hfail - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsrcInkRevert + have hblock :=.execBlock_append_term (s2 := checkedSubSignedInto "srcArtNew" (.storage (urnsF (.var "ilk") (.var "src") "art")) (.var "dart") ++ @@ -7742,9 +7742,9 @@ theorem execForkSourceRevertSrcArtGuardNeg {evm0 : EVM.State} {I : ExecutionEnv} (forkStoreSrcInkNew_get_dart I srcInkNew) (forkStoreSrcInkNew_get_urns I srcInkNew) (by simpa [evm1] using hloadSrcArt) hsrcArtNew hfail - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hsrcArtRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsrcInkBlock + have h02 :=.execBlock_append h01 hsrcArtRevert + have hblock :=.execBlock_append_term (s2 := checkedAddSignedInto "dstInkNew" (.storage (urnsF (.var "ilk") (.var "dst") "ink")) (.var "dink") ++ @@ -7846,9 +7846,9 @@ theorem execForkSourceRevertSrcArtGuardPos {evm0 : EVM.State} {I : ExecutionEnv} (forkStoreSrcInkNew_get_dart I srcInkNew) (forkStoreSrcInkNew_get_urns I srcInkNew) (by simpa [evm1] using hloadSrcArt) hsrcArtNew hguardNeg hfail - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hsrcArtRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsrcInkBlock + have h02 :=.execBlock_append h01 hsrcArtRevert + have hblock :=.execBlock_append_term (s2 := checkedAddSignedInto "dstInkNew" (.storage (urnsF (.var "ilk") (.var "dst") "ink")) (.var "dink") ++ @@ -7961,10 +7961,10 @@ theorem execForkSourceRevertDstInkGuardNeg {evm0 : EVM.State} {I : ExecutionEnv} (forkStoreSrcArtNew_get_urns I srcInkNew srcArtNew) (by simpa [evm1, evm2, storageStore_executionEnv] using hloadDstInk) hdstInkNew hfail - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hsrcArtBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hdstInkRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsrcInkBlock + have h02 :=.execBlock_append h01 hsrcArtBlock + have h03 :=.execBlock_append h02 hdstInkRevert + have hblock :=.execBlock_append_term (s2 := checkedAddSignedInto "dstArtNew" (.storage (urnsF (.var "ilk") (.var "dst") "art")) (.var "dart") ++ @@ -8076,10 +8076,10 @@ theorem execForkSourceRevertDstInkGuardPos {evm0 : EVM.State} {I : ExecutionEnv} (forkStoreSrcArtNew_get_urns I srcInkNew srcArtNew) (by simpa [evm1, evm2, storageStore_executionEnv] using hloadDstInk) hdstInkNew hguardNeg hfail - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hsrcArtBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hdstInkRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsrcInkBlock + have h02 :=.execBlock_append h01 hsrcArtBlock + have h03 :=.execBlock_append h02 hdstInkRevert + have hblock :=.execBlock_append_term (s2 := checkedAddSignedInto "dstArtNew" (.storage (urnsF (.var "ilk") (.var "dst") "art")) (.var "dart") ++ @@ -8213,11 +8213,11 @@ theorem execForkSourceRevertDstArtGuardNeg {evm0 : EVM.State} {I : ExecutionEnv} (forkStoreDstInkNew_get_urns I srcInkNew srcArtNew dstInkNew) (by simpa [evm1, evm2, evm3, storageStore_executionEnv] using hloadDstArt) hdstArtNew hfail - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hsrcArtBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hdstInkBlock - have h04 := Reasoning.Refinement.execBlock_append h03 hdstArtRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsrcInkBlock + have h02 :=.execBlock_append h01 hsrcArtBlock + have h03 :=.execBlock_append h02 hdstInkBlock + have h04 :=.execBlock_append h03 hdstArtRevert + have hblock :=.execBlock_append_term (s2 := [ .letDecl "srcArtFinal" (some uint256) (.storage (urnsF (.var "ilk") (.var "src") "art")), @@ -8350,11 +8350,11 @@ theorem execForkSourceRevertDstArtGuardPos {evm0 : EVM.State} {I : ExecutionEnv} (forkStoreDstInkNew_get_urns I srcInkNew srcArtNew dstInkNew) (by simpa [evm1, evm2, evm3, storageStore_executionEnv] using hloadDstArt) hdstArtNew hguardNeg hfail - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hsrcArtBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hdstInkBlock - have h04 := Reasoning.Refinement.execBlock_append h03 hdstArtRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsrcInkBlock + have h02 :=.execBlock_append h01 hsrcArtBlock + have h03 :=.execBlock_append h02 hdstInkBlock + have h04 :=.execBlock_append h03 hdstArtRevert + have hblock :=.execBlock_append_term (s2 := [ .letDecl "srcArtFinal" (some uint256) (.storage (urnsF (.var "ilk") (.var "src") "art")), @@ -8590,13 +8590,13 @@ theorem execForkSourceRevertUtabMul {evm0 : EVM.State} {I : ExecutionEnv} execForkMulUintIntoRevertOfOverflow (evm := evm4) (locals := localsFinal) "utab" (.var "srcArtFinal") (.storage (ilksF (.var "ilk") "rate")) srcArtFinal rate hsrcArtEval hrateEval hover - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hsrcArtBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hdstInkBlock - have h04 := Reasoning.Refinement.execBlock_append h03 hdstArtBlock - have h05 := Reasoning.Refinement.execBlock_append h04 hfinalLoadsBlock - have h06 := Reasoning.Refinement.execBlock_append h05 hutabRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsrcInkBlock + have h02 :=.execBlock_append h01 hsrcArtBlock + have h03 :=.execBlock_append h02 hdstInkBlock + have h04 :=.execBlock_append h03 hdstArtBlock + have h05 :=.execBlock_append h04 hfinalLoadsBlock + have h06 :=.execBlock_append h05 hutabRevert + have hblock :=.execBlock_append_term (s2 := checkedMulUintInto "vtab" (.var "dstArtFinal") (.storage (ilksF (.var "ilk") "rate")) ++ @@ -8829,14 +8829,14 @@ theorem execForkSourceRevertVtabMul {evm0 : EVM.State} {I : ExecutionEnv} execForkMulUintIntoRevertOfOverflow (evm := evm4) (locals := localsUtab) "vtab" (.var "dstArtFinal") (.storage (ilksF (.var "ilk") "rate")) dstArtFinal rate hdstArtEval hrateEval hover - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hsrcArtBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hdstInkBlock - have h04 := Reasoning.Refinement.execBlock_append h03 hdstArtBlock - have h05 := Reasoning.Refinement.execBlock_append h04 hfinalLoadsBlock - have h06 := Reasoning.Refinement.execBlock_append h05 hutabBlock - have h07 := Reasoning.Refinement.execBlock_append h06 hvtabRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsrcInkBlock + have h02 :=.execBlock_append h01 hsrcArtBlock + have h03 :=.execBlock_append h02 hdstInkBlock + have h04 :=.execBlock_append h03 hdstArtBlock + have h05 :=.execBlock_append h04 hfinalLoadsBlock + have h06 :=.execBlock_append h05 hutabBlock + have h07 :=.execBlock_append h06 hvtabRevert + have hblock :=.execBlock_append_term (s2 := checkedMulUintInto "srcInkSpot" (.var "srcInkFinal") (.storage (ilksF (.var "ilk") "spot")) ++ @@ -9089,15 +9089,15 @@ theorem execForkSourceRevertSrcInkSpotMul {evm0 : EVM.State} {I : ExecutionEnv} execForkMulUintIntoRevertOfOverflow (evm := evm4) (locals := localsVtab) "srcInkSpot" (.var "srcInkFinal") (.storage (ilksF (.var "ilk") "spot")) srcInkFinal spot hsrcInkEval hspotEval hover - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hsrcArtBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hdstInkBlock - have h04 := Reasoning.Refinement.execBlock_append h03 hdstArtBlock - have h05 := Reasoning.Refinement.execBlock_append h04 hfinalLoadsBlock - have h06 := Reasoning.Refinement.execBlock_append h05 hutabBlock - have h07 := Reasoning.Refinement.execBlock_append h06 hvtabBlock - have h08 := Reasoning.Refinement.execBlock_append h07 hsrcInkSpotRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsrcInkBlock + have h02 :=.execBlock_append h01 hsrcArtBlock + have h03 :=.execBlock_append h02 hdstInkBlock + have h04 :=.execBlock_append h03 hdstArtBlock + have h05 :=.execBlock_append h04 hfinalLoadsBlock + have h06 :=.execBlock_append h05 hutabBlock + have h07 :=.execBlock_append h06 hvtabBlock + have h08 :=.execBlock_append h07 hsrcInkSpotRevert + have hblock :=.execBlock_append_term (s2 := checkedMulUintInto "dstInkSpot" (.var "dstInkFinal") (.storage (ilksF (.var "ilk") "spot")) ++ @@ -9358,16 +9358,16 @@ theorem execForkSourceRevertDstInkSpotMul {evm0 : EVM.State} {I : ExecutionEnv} execForkMulUintIntoRevertOfOverflow (evm := evm4) (locals := localsSrcInkSpot) "dstInkSpot" (.var "dstInkFinal") (.storage (ilksF (.var "ilk") "spot")) dstInkFinal spot hdstInkEval hspotEval hover - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hsrcArtBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hdstInkBlock - have h04 := Reasoning.Refinement.execBlock_append h03 hdstArtBlock - have h05 := Reasoning.Refinement.execBlock_append h04 hfinalLoadsBlock - have h06 := Reasoning.Refinement.execBlock_append h05 hutabBlock - have h07 := Reasoning.Refinement.execBlock_append h06 hvtabBlock - have h08 := Reasoning.Refinement.execBlock_append h07 hsrcInkSpotBlock - have h09 := Reasoning.Refinement.execBlock_append h08 hdstInkSpotRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsrcInkBlock + have h02 :=.execBlock_append h01 hsrcArtBlock + have h03 :=.execBlock_append h02 hdstInkBlock + have h04 :=.execBlock_append h03 hdstArtBlock + have h05 :=.execBlock_append h04 hfinalLoadsBlock + have h06 :=.execBlock_append h05 hutabBlock + have h07 :=.execBlock_append h06 hvtabBlock + have h08 :=.execBlock_append h07 hsrcInkSpotBlock + have h09 :=.execBlock_append h08 hdstInkSpotRevert + have hblock :=.execBlock_append_term (s2 := [ .require (bothExpr (wishExpr (.var "src") sender) (wishExpr (.var "dst") sender)), .require (.binary .le (.var "utab") (.var "srcInkSpot")), @@ -9616,16 +9616,16 @@ theorem execForkSourceRevertFinal {evm0 : EVM.State} {I : ExecutionEnv} srcInkNew srcArtNew dstInkNew dstArtNew srcArtFinal dstArtFinal srcInkFinal dstInkFinal spot utab vtab srcInkSpot dstInkSpot hsz164 hloadSpotFinal hdstInkSpotProd hdstInkSpotFit hdstInkSpotGuard - have h01 := Reasoning.Refinement.execBlock_append hprefix hsrcInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hsrcArtBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hdstInkBlock - have h04 := Reasoning.Refinement.execBlock_append h03 hdstArtBlock - have h05 := Reasoning.Refinement.execBlock_append h04 hfinalLoadsBlock - have h06 := Reasoning.Refinement.execBlock_append h05 hutabBlock - have h06 := Reasoning.Refinement.execBlock_append h06 hvtabBlock - have h07 := Reasoning.Refinement.execBlock_append h06 hsrcInkSpotBlock - have hblock := Reasoning.Refinement.execBlock_append h07 hdstInkSpotBlock - have hblock := Reasoning.Refinement.execBlock_append hblock hfinalBlock + have h01 :=.execBlock_append hprefix hsrcInkBlock + have h02 :=.execBlock_append h01 hsrcArtBlock + have h03 :=.execBlock_append h02 hdstInkBlock + have h04 :=.execBlock_append h03 hdstArtBlock + have h05 :=.execBlock_append h04 hfinalLoadsBlock + have h06 :=.execBlock_append h05 hutabBlock + have h06 :=.execBlock_append h06 hvtabBlock + have h07 :=.execBlock_append h06 hsrcInkSpotBlock + have hblock :=.execBlock_append h07 hdstInkSpotBlock + have hblock :=.execBlock_append hblock hfinalBlock simpa [ExecTransitionBody, forkTransition, nonpayable, checkedSubSignedInto, checkedAddSignedInto, checkedMulUintInto, List.append_assoc, storageStore_executionEnv] using ExecFuncBody.execBlockRevert hblock diff --git a/Benchmarks/Dss/Vat/Frob.lean b/Benchmarks/Dss/Vat/Frob.lean index 20660d1e..fdc584ed 100644 --- a/Benchmarks/Dss/Vat/Frob.lean +++ b/Benchmarks/Dss/Vat/Frob.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.FrobLive -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Vat diff --git a/Benchmarks/Dss/Vat/FrobBase.lean b/Benchmarks/Dss/Vat/FrobBase.lean index 98b5befc..24b7980d 100644 --- a/Benchmarks/Dss/Vat/FrobBase.lean +++ b/Benchmarks/Dss/Vat/FrobBase.lean @@ -89,7 +89,7 @@ end Reasoning.Reach namespace Benchmarks.Dss.Vat -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach /-! ## `frob(bytes32,address,address,address,int256,int256)` -/ @@ -11913,11 +11913,11 @@ theorem execFrobLoadedPrefixThreeAdds {evm : EVM.State} {I : ExecutionEnv} ilkDust) (by simp [ilkArtNew]) (by simpa [ilkArtNew] using hIlkNeg) (by simpa [ilkArtNew] using hIlkPos) - have h01 := Reasoning.Refinement.execBlock_append hprefix + have h01 :=.execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) - have h02 := Reasoning.Refinement.execBlock_append h01 + have h02 :=.execBlock_append h01 (by simpa [localsLoaded, localsInk] using hArtBlock) - have h03 := Reasoning.Refinement.execBlock_append h02 + have h03 :=.execBlock_append h02 (by simpa [localsLoaded, localsInk, localsArt] using hIlkBlock) simpa [localsLoaded, localsInk, localsArt, List.append_assoc] using h03 @@ -12483,7 +12483,7 @@ theorem execFrobCeilingInkSpotCheckedOk {evm : EVM.State} {locals : Store} exact execForkMulUintIntoOk "inkSpot" (.var "urnInkNew") (.var "ilkSpot") urnInkNew ilkSpot inkSpot hurnInkNewEval hilkSpotEval hinkSpot hinkFit hinkGuardEval - have h := Reasoning.Refinement.execBlock_append hceilingBlock hinkBlock + have h :=.execBlock_append hceilingBlock hinkBlock simpa [localsCeiling, List.append_assoc] using h theorem execFrobCeilingSafetyOk {evm : EVM.State} {locals : Store} @@ -12579,7 +12579,7 @@ theorem execFrobCeilingSafetyOk {evm : EVM.State} {locals : Store} · simpa [localsFinal] using hceilingReq · exact ExecBlock.consNormal (ExecStmt.requireTrue (by simpa [localsFinal] using hsafeReq)) ExecBlock.nil - have h := Reasoning.Refinement.execBlock_append hmul hreqs + have h :=.execBlock_append hmul hreqs simpa [localsFinal, List.append_assoc] using h theorem execFrobCeilingRequireRevert {evm : EVM.State} {locals : Store} @@ -12643,7 +12643,7 @@ theorem execFrobCeilingRequireRevert {evm : EVM.State} {locals : Store} .reverted := by exact ExecBlock.consRevert (ExecStmt.requireFalse (by simpa [localsFinal] using hceilingReq)) - have h := Reasoning.Refinement.execBlock_append hmul hreq + have h :=.execBlock_append hmul hreq simpa [localsFinal, List.append_assoc] using h theorem execFrobSafetyRequireRevert {evm : EVM.State} {locals : Store} @@ -12734,7 +12734,7 @@ theorem execFrobSafetyRequireRevert {evm : EVM.State} {locals : Store} · simpa [localsFinal] using hceilingReq · exact ExecBlock.consRevert (ExecStmt.requireFalse (by simpa [localsFinal] using hsafeReq)) - have h := Reasoning.Refinement.execBlock_append hmul hreqs + have h :=.execBlock_append hmul hreqs simpa [localsFinal, List.append_assoc] using h theorem execFrobAuthorizationDustOk {evm : EVM.State} {locals : Store} @@ -13610,7 +13610,7 @@ theorem execFrobGemUpdateOk {evm : EVM.State} {I : ExecutionEnv} [ .assign .storage (gemRef (.var "i") (.var "v")) (.var "gemNew") ] (.ok { contract := contract, locals := localsGem } evmGem) := by exact ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - have h := Reasoning.Refinement.execBlock_append hsub hassignBlock + have h :=.execBlock_append hsub hassignBlock simpa [localsGem, evmGem, List.append_assoc] using h theorem execFrobDaiAddCheckedOk {evm : EVM.State} {I : ExecutionEnv} @@ -13852,7 +13852,7 @@ theorem execFrobDaiUpdateOk {evm : EVM.State} {I : ExecutionEnv} [ .assign .storage (daiRef (.var "w")) (.var "daiNew") ] (.ok { contract := contract, locals := localsDai } evmDai) := by exact ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - have h := Reasoning.Refinement.execBlock_append hadd hassignBlock + have h :=.execBlock_append hadd hassignBlock simpa [localsDai, evmDai, List.append_assoc] using h theorem execFrobFinalStoreTailGemRevertFromBlock {evm : EVM.State} @@ -13876,7 +13876,7 @@ theorem execFrobFinalStoreTailGemRevertFromBlock {evm : EVM.State} .assign .storage (ilksF (.var "i") "line") (.var "ilkLine"), .assign .storage (ilksF (.var "i") "dust") (.var "ilkDust") ]) .reverted := by - have h := Reasoning.Refinement.execBlock_append_term + have h :=.execBlock_append_term (s2 := [ .assign .storage (gemRef (.var "i") (.var "v")) (.var "gemNew") ] ++ checkedAddSignedInto "daiNew" (.storage (daiRef (.var "w"))) (.var "dtab") ++ @@ -13917,8 +13917,8 @@ theorem execFrobFinalStoreTailDaiRevertFromBlock {evm evmGem : EVM.State} .assign .storage (ilksF (.var "i") "line") (.var "ilkLine"), .assign .storage (ilksF (.var "i") "dust") (.var "ilkDust") ]) .reverted := by - have h01 := Reasoning.Refinement.execBlock_append hGem hDai - have h := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hGem hDai + have h :=.execBlock_append_term (s2 := [ .assign .storage (daiRef (.var "w")) (.var "daiNew"), .assign .storage (urnsF (.var "i") (.var "u") "ink") (.var "urnInkNew"), @@ -14171,8 +14171,8 @@ theorem execFrobFinalStoreTailOk {evm : EVM.State} {I : ExecutionEnv} (evalVarAfterDai (evm' := evmLine) hilkDust (by native_decide) (by native_decide)) hassignDust) ExecBlock.nil - have h01 := Reasoning.Refinement.execBlock_append hgemBlock hdaiBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hstores + have h01 :=.execBlock_append hgemBlock hdaiBlock + have h02 :=.execBlock_append h01 hstores simpa [localsGem, localsDai, evmGem, evmDai, evmInk, evmArt, evmIlk, evmRate, evmSpot, evmLine, evmDust, List.append_assoc] using h02 @@ -14270,7 +14270,7 @@ theorem execFrobDebtAddStoreOk {evm : EVM.State} {locals : Store} [ .assign .storage debtRef (.var "debtNew") ] (.ok { contract := contract, locals := localsDebt } evmDebt) := by exact ExecBlock.consNormal (ExecStmt.assign hdebtNewEval hdebtAssign) ExecBlock.nil - have h := Reasoning.Refinement.execBlock_append hAdd hAssign + have h :=.execBlock_append hAdd hAssign simpa [localsDebt, evmDebt, List.append_assoc] using h theorem execFrobDebtAddCheckedRevertGuardNeg {evm : EVM.State} {locals : Store} @@ -14406,7 +14406,7 @@ theorem execFrobLoadedPrefixUrnInkRevertGuardNeg {evm : EVM.State} {I : Executio frobStoreIlkDust_get_dink I urnInk urnArt ilkArt ilkRate ilkSpot ilkLine ilkDust) (by simp [urnInkNew]) (by simpa [urnInkNew] using hcond) - have h := Reasoning.Refinement.execBlock_append hprefix + have h :=.execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) simpa [localsLoaded, List.append_assoc] using h @@ -14444,7 +14444,7 @@ theorem execFrobLoadedPrefixUrnInkRevertGuardPos {evm : EVM.State} {I : Executio ilkDust) (by simp [urnInkNew]) (by simpa [urnInkNew] using hguardNeg) (by simpa [urnInkNew] using hcond) - have h := Reasoning.Refinement.execBlock_append hprefix + have h :=.execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) simpa [localsLoaded, List.append_assoc] using h @@ -14513,9 +14513,9 @@ theorem execFrobLoadedPrefixUrnArtRevertGuardNeg {evm : EVM.State} {I : Executio frobStoreIlkDust_get_dart I urnInk urnArt ilkArt ilkRate ilkSpot ilkLine ilkDust) (by simp [urnArtNew]) (by simpa [urnArtNew] using hcond) - have h01 := Reasoning.Refinement.execBlock_append hprefix + have h01 :=.execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) - have h02 := Reasoning.Refinement.execBlock_append h01 + have h02 :=.execBlock_append h01 (by simpa [localsLoaded, localsInk] using hArtBlock) simpa [localsLoaded, localsInk, List.append_assoc] using h02 @@ -14586,9 +14586,9 @@ theorem execFrobLoadedPrefixUrnArtRevertGuardPos {evm : EVM.State} {I : Executio ilkDust) (by simp [urnArtNew]) (by simpa [urnArtNew] using hArtNeg) (by simpa [urnArtNew] using hcond) - have h01 := Reasoning.Refinement.execBlock_append hprefix + have h01 :=.execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) - have h02 := Reasoning.Refinement.execBlock_append h01 + have h02 :=.execBlock_append h01 (by simpa [localsLoaded, localsInk] using hArtBlock) simpa [localsLoaded, localsInk, List.append_assoc] using h02 @@ -14690,11 +14690,11 @@ theorem execFrobLoadedPrefixIlkArtRevertGuardNeg {evm : EVM.State} {I : Executio frobStoreIlkDust_get_dart I urnInk urnArt ilkArt ilkRate ilkSpot ilkLine ilkDust) (by simp [ilkArtNew]) (by simpa [ilkArtNew] using hcond) - have h01 := Reasoning.Refinement.execBlock_append hprefix + have h01 :=.execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) - have h02 := Reasoning.Refinement.execBlock_append h01 + have h02 :=.execBlock_append h01 (by simpa [localsLoaded, localsInk] using hArtBlock) - have h03 := Reasoning.Refinement.execBlock_append h02 + have h03 :=.execBlock_append h02 (by simpa [localsLoaded, localsInk, localsArt] using hIlkBlock) simpa [localsLoaded, localsInk, localsArt, List.append_assoc] using h03 @@ -14798,11 +14798,11 @@ theorem execFrobLoadedPrefixIlkArtRevertGuardPos {evm : EVM.State} {I : Executio ilkDust) (by simp [ilkArtNew]) (by simpa [ilkArtNew] using hIlkNeg) (by simpa [ilkArtNew] using hcond) - have h01 := Reasoning.Refinement.execBlock_append hprefix + have h01 :=.execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) - have h02 := Reasoning.Refinement.execBlock_append h01 + have h02 :=.execBlock_append h01 (by simpa [localsLoaded, localsInk] using hArtBlock) - have h03 := Reasoning.Refinement.execBlock_append h02 + have h03 :=.execBlock_append h02 (by simpa [localsLoaded, localsInk, localsArt] using hIlkBlock) simpa [localsLoaded, localsInk, localsArt, List.append_assoc] using h03 diff --git a/Benchmarks/Dss/Vat/FrobLive.lean b/Benchmarks/Dss/Vat/FrobLive.lean index 89797af1..2dcc02dc 100644 --- a/Benchmarks/Dss/Vat/FrobLive.lean +++ b/Benchmarks/Dss/Vat/FrobLive.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.FrobLiveSuccess -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Vat @@ -252,7 +252,7 @@ theorem hsourceRevertFromPrefix {evm : EVM.State} {I : ExecutionEnv} ExecBlock config { contract := contract, locals := frobStore I } evm frobTransition.body .reverted := by rw [hbody] - exact Reasoning.Refinement.execBlock_append_term (s2 := tail) hsrcPrefixRevert + exact.execBlock_append_term (s2 := tail) hsrcPrefixRevert (by intro f e h; cases h) exact ExecFuncBody.execBlockRevert hblock @@ -1085,7 +1085,7 @@ theorem hsourceRevertFromFinalStoreTail {evm evmDebt : EVM.State} {I : Execution .reverted) : ExecTransitionBody config contract evm (frobStore I) frobTransition.body .reverted := by - have hblock := Reasoning.Refinement.execBlock_append hsourceDust htail + have hblock :=.execBlock_append hsourceDust htail exact ExecFuncBody.execBlockRevert (by simpa [ExecTransitionBody, frobTransition, List.append_assoc] using hblock) @@ -1475,7 +1475,7 @@ theorem execFrobLoadedPrefixDtabMulRevertRange {evm : EVM.State} .reverted := execFrobDtabMulCheckedRevertRange (evm := evm) (I := I) localsIlk ilkRate dtab hrateGet hdartGet hdtab hbad - have hfull := Reasoning.Refinement.execBlock_append + have hfull :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk] using hthree) hdtabBlock simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, @@ -1565,7 +1565,7 @@ theorem execFrobLoadedPrefixDtabMulRevertMaxSlt {evm : EVM.State} execFrobDtabMulCheckedRevertMaxSlt (evm := evm) (I := I) localsIlk ilkRate dtab hrateGet hdartGet hdtab hdtabLo hdtabHi hRateMaxFail - have hfull := Reasoning.Refinement.execBlock_append + have hfull :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk] using hthree) hdtabBlock simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, @@ -1668,7 +1668,7 @@ theorem execFrobLoadedPrefixTabMulRevertOverflow {evm : EVM.State} execFrobDtabMulCheckedOk (evm := evm) (I := I) localsIlk ilkRate dtab hrateGetIlk hdartGet hdtab hdtabLo hdtabHi hdtabGuards.1 hdtabGuards.2 - have hsourceDtab := Reasoning.Refinement.execBlock_append + have hsourceDtab :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk] using hthree) hdtabBlock have hrateGetDtab : @@ -1695,7 +1695,7 @@ theorem execFrobLoadedPrefixTabMulRevertOverflow {evm : EVM.State} (evm := evm) (locals := localsIlk.insert "dtab" (.int dtab)) ilkRate urnArtNew hrateGetDtab hurnArtNewGet (by simpa [urnArtNew] using htabOverflow) - have hfull := Reasoning.Refinement.execBlock_append + have hfull :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, List.append_assoc] using hsourceDtab) htabBlock @@ -1805,7 +1805,7 @@ theorem execFrobLoadedPrefixThroughTabOk {evm : EVM.State} execFrobDtabMulCheckedOk (evm := evm) (I := I) localsIlk ilkRate dtab hrateGetIlk hdartGet hdtab hdtabLo hdtabHi hdtabGuards.1 hdtabGuards.2 - have hsourceDtab := Reasoning.Refinement.execBlock_append + have hsourceDtab :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk] using hthree) hdtabBlock have hTabMulS : @@ -1839,7 +1839,7 @@ theorem execFrobLoadedPrefixThroughTabOk {evm : EVM.State} exact execFrobTabMulCheckedOk (evm := evm) (locals := localsDtab) ilkRate urnArtNew tab hrateGetDtab hurnArtNewGet (by rfl) htabFitGuard.1 htabFitGuard.2 - have hfull := Reasoning.Refinement.execBlock_append + have hfull :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, List.append_assoc] using hsourceDtab) htabBlock @@ -1962,7 +1962,7 @@ theorem execFrobLoadedPrefixThroughDebtOk {evm : EVM.State} debtOld debtNew dtabWord dtab hbaseDebt hdtabGet hdebtLoad hdtabMod hnew (signedAddGuardNegCond_of_word hdtabLo hdtabHi hdtabMod hDebtNeg) (signedAddGuardPosCond_of_word hdtabLo hdtabHi hdtabMod hDebtPos) - have hfull := Reasoning.Refinement.execBlock_append + have hfull :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, List.append_assoc] using hsourceTab) hdebtBlock @@ -2072,7 +2072,7 @@ theorem execFrobLoadedPrefixDebtAddRevertGuardNeg {evm : EVM.State} debtOld debtNew dtabWord dtab hbaseDebt hdtabGet hdebtLoad hdtabMod hnew (signedAddGuardNegFalseCond_of_word hdtabLo hdtabHi hdtabMod hDebtNegFail) - have hfull := Reasoning.Refinement.execBlock_append + have hfull :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, List.append_assoc] using hsourceTab) hdebtBlock @@ -2185,7 +2185,7 @@ theorem execFrobLoadedPrefixDebtAddRevertGuardPos {evm : EVM.State} (signedAddGuardNegCond_of_word hdtabLo hdtabHi hdtabMod hDebtNeg) (signedAddGuardPosFalseCond_of_word hdtabLo hdtabHi hdtabMod hDebtPosFail) - have hfull := Reasoning.Refinement.execBlock_append + have hfull :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, List.append_assoc] using hsourceTab) hdebtBlock @@ -2580,7 +2580,7 @@ theorem execFrobLoadedPrefixThroughSafetyOk {evm : EVM.State} (by rfl) hCeilingFitGuard.1 hCeilingFitGuard.2 (by rfl) hInkFitGuard.1 hInkFitGuard.2 hceilingReqEval hsafetyReqEval - have hfull := Reasoning.Refinement.execBlock_append + have hfull :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, localsDebt, evmDebt, List.append_assoc] using hsourceDebt) @@ -2707,7 +2707,7 @@ theorem execFrobLoadedPrefixCeilingMulRevertOverflow {evm : EVM.State} (evm := evmDebt) (locals := localsDebt) ilkArtNew ilkRate hlocalsDebtIlkArtNew hlocalsDebtRate (by simpa [ilkArtNew] using hover) - have hfull := Reasoning.Refinement.execBlock_append + have hfull :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, localsDebt, evmDebt, List.append_assoc] using hsourceDebt) @@ -2900,8 +2900,8 @@ theorem execFrobLoadedPrefixInkSpotMulRevertOverflow {evm : EVM.State} rw [store_get_ne _ _ (by decide)] exact hlocalsDebtSpot) (by simpa [urnInkNew] using hover) - have hmulRevert := Reasoning.Refinement.execBlock_append hceilBlock hinkBlock - have hfull := Reasoning.Refinement.execBlock_append + have hmulRevert :=.execBlock_append hceilBlock hinkBlock + have hfull :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, localsDebt, evmDebt, List.append_assoc] using hsourceDebt) @@ -3208,7 +3208,7 @@ theorem execFrobLoadedPrefixCeilingRequireRevert {evm : EVM.State} (by rfl) hCeilingFitGuard.1 hCeilingFitGuard.2 (by rfl) hInkFitGuard.1 hInkFitGuard.2 hceilingReqEval - have hfull := Reasoning.Refinement.execBlock_append + have hfull :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, localsDebt, evmDebt, List.append_assoc] using hsourceDebt) @@ -3592,7 +3592,7 @@ theorem execFrobLoadedPrefixSafetyRequireRevert {evm : EVM.State} (by rfl) hCeilingFitGuard.1 hCeilingFitGuard.2 (by rfl) hInkFitGuard.1 hInkFitGuard.2 hceilingReqEval hsafetyReqEval - have hfull := Reasoning.Refinement.execBlock_append + have hfull :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, localsDebt, evmDebt, List.append_assoc] using hsourceDebt) @@ -5098,7 +5098,7 @@ theorem vatFrobBodyCoreLiveFinalArithmeticOverflowReverts (eitherExpr (.binary .eq (.var "urnArtNew") (.intLit 0)) (.binary .ge (.var "tab") (.var "ilkDust"))) ]) (.ok { contract := contract, locals := localsSafe } evmDebt) := by - have hprefix := Reasoning.Refinement.execBlock_append hsourceSafety hauthDust + have hprefix :=.execBlock_append hsourceSafety hauthDust simpa [List.append_assoc] using hprefix obtain ⟨_, _, hDustDone⟩ := RD.vatFrobAuthorizationDustChecksSuccess @@ -6789,7 +6789,7 @@ theorem vatFrobBodyCoreLiveWishAuthDustReverts .reverted := by intro hauthRevert exact hsourceRevertFromAuthorizationDust (by - have hprefix := Reasoning.Refinement.execBlock_append hsourceSafety hauthRevert + have hprefix :=.execBlock_append hsourceSafety hauthRevert simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, debtOld, dtabWord, debtNew, localsDebt, evmDebt, ceilingDebt, inkSpot, localsSafe, List.append_assoc] using hprefix) diff --git a/Benchmarks/Dss/Vat/FrobLiveBase.lean b/Benchmarks/Dss/Vat/FrobLiveBase.lean index 56190327..3ce0d23f 100644 --- a/Benchmarks/Dss/Vat/FrobLiveBase.lean +++ b/Benchmarks/Dss/Vat/FrobLiveBase.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.FrobBase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Vat diff --git a/Benchmarks/Dss/Vat/FrobLiveSuccess.lean b/Benchmarks/Dss/Vat/FrobLiveSuccess.lean index 8efa1b06..6591a25e 100644 --- a/Benchmarks/Dss/Vat/FrobLiveSuccess.lean +++ b/Benchmarks/Dss/Vat/FrobLiveSuccess.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.FrobLiveBase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Vat @@ -232,7 +232,7 @@ theorem execFrobGemDaiUpdatesOk {evm : EVM.State} {I : ExecutionEnv} execFrobDaiUpdateOk (evm := evmGem) (I := I) localsGem daiOld daiNew dtabWord dtab hwGem hdtabGem hbaseDaiGem (by simpa [evmGem] using hloadDai) hdtabMod hdaiNew hDaiNeg hDaiPos - have h := Reasoning.Refinement.execBlock_append hgemBlock hdaiBlock + have h :=.execBlock_append hgemBlock hdaiBlock simpa [localsGem, localsDai, evmGem, evmDai, List.append_assoc] using h set_option maxHeartbeats 0 in @@ -964,7 +964,7 @@ theorem execFrobFinalStoreTailFromConstructedLocalsSplit {evmDebt : EVM.State} urnInkNew urnArtNew ilkArtNew ilkRate ilkSpot ilkLine ilkDust hsz196 hTailBaseI hTailBaseU hTailUrns hTailIlks hTailUrnInkNew hTailUrnArtNew hTailIlkArtNew hTailIlkRate hTailIlkSpot hTailIlkLine hTailIlkDust - have h := Reasoning.Refinement.execBlock_append hgemDai hstores + have h :=.execBlock_append hgemDai hstores simpa [localsGem, localsDai, evmGem, evmDai, evmInk, evmArt, evmIlk, evmRate, evmSpot, evmLine, evmDust, List.append_assoc] using h -/ @@ -1303,7 +1303,7 @@ theorem vatFrobSourceBodySuccessFromDustBlock (frobDinkSubGuardPosCond hGemNegS) (signedAddGuardNegCond_of_word hdtabRange.1 hdtabRange.2 hdtabMod hDaiNegS) (signedAddGuardPosCond_of_word hdtabRange.1 hdtabRange.2 hdtabMod hDaiPosS) - have hfull := Reasoning.Refinement.execBlock_append + have hfull :=.execBlock_append (s2 := checkedSubSignedInto "gemNew" (.storage (gemRef (.var "i") (.var "v"))) (.var "dink") ++ @@ -2175,7 +2175,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards using hguardMax) (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk] using hguardMul) - have h04 := Reasoning.Refinement.execBlock_append + have h04 :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk] using hsourceAdds) hdtabBlock @@ -2449,7 +2449,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards exact execFrobTabMulCheckedOk (evm := evm0) (locals := localsDtab) ilkRate urnArtNew tab hrateGet hurnArtNewGet (by rfl) htabFitGuard.1 htabFitGuard.2 - have h05 := Reasoning.Refinement.execBlock_append + have h05 :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab] using hsourceDtab) htabBlock @@ -2742,7 +2742,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards hDebtNegS) (signedAddGuardPosCond_of_word hdtabRange.1 hdtabRange.2 hdtabMod hDebtPosS) - have h06 := Reasoning.Refinement.execBlock_append + have h06 :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab] using hsourceTab) hdebtBlock @@ -3237,7 +3237,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards (by rw [store_get_self]) (frobSafetySourceCond_of_evm (I := I) hSafetyOkS)) - have h07 := Reasoning.Refinement.execBlock_append + have h07 :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsDebt, debtOld, dtabWord, debtNew, evmDebt] using hsourceDebt) @@ -3818,7 +3818,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards (frobAuthVSourceCond_of_evm (I := I) hV') (frobAuthWSourceCond_of_evm (I := I) hW') (frobDustSourceCond_of_evm hDustS) - have h08 := Reasoning.Refinement.execBlock_append + have h08 :=.execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsDebt, debtOld, dtabWord, debtNew, evmDebt, ceilingDebt, inkSpot, localsSafe] using hsourceSafe) @@ -4173,7 +4173,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock := Reasoning.Refinement.execBlock_append_term + have hblock :=.execBlock_append_term (s2 := checkedAddSignedInto "urnArtNew" (.var "urnArt") (.var "dart") ++ checkedAddSignedInto "ilkArtNew" (.var "ilkArt") (.var "dart") ++ @@ -4245,7 +4245,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock := Reasoning.Refinement.execBlock_append_term + have hblock :=.execBlock_append_term (s2 := checkedAddSignedInto "ilkArtNew" (.var "ilkArt") (.var "dart") ++ checkedMulSignedInto "dtab" (.var "ilkRate") (.var "dart") ++ @@ -4317,7 +4317,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock := Reasoning.Refinement.execBlock_append_term + have hblock :=.execBlock_append_term (s2 := checkedMulSignedInto "dtab" (.var "ilkRate") (.var "dart") ++ checkedMulUintInto "tab" (.var "ilkRate") (.var "urnArtNew") ++ @@ -4389,7 +4389,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock := Reasoning.Refinement.execBlock_append_term + have hblock :=.execBlock_append_term (s2 := checkedMulUintInto "tab" (.var "ilkRate") (.var "urnArtNew") ++ checkedAddSignedInto "debtNew" (.storage debtRef) (.var "dtab") ++ @@ -4461,7 +4461,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock := Reasoning.Refinement.execBlock_append_term + have hblock :=.execBlock_append_term (s2 := checkedAddSignedInto "debtNew" (.storage debtRef) (.var "dtab") ++ [ .assign .storage debtRef (.var "debtNew") ] ++ @@ -4533,7 +4533,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock := Reasoning.Refinement.execBlock_append_term + have hblock :=.execBlock_append_term (s2 := [ .assign .storage debtRef (.var "debtNew") ] ++ checkedMulUintInto "ceilingDebt" (.var "ilkArtNew") (.var "ilkRate") ++ @@ -4606,7 +4606,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock := Reasoning.Refinement.execBlock_append_term + have hblock :=.execBlock_append_term (s2 := checkedMulUintInto "inkSpot" (.var "urnInkNew") (.var "ilkSpot") ++ [ .require @@ -4678,7 +4678,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock := Reasoning.Refinement.execBlock_append_term + have hblock :=.execBlock_append_term (s2 := [ .require (eitherExpr @@ -4755,7 +4755,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock := Reasoning.Refinement.execBlock_append_term + have hblock :=.execBlock_append_term (s2 := [ .require (eitherExpr @@ -4832,7 +4832,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock := Reasoning.Refinement.execBlock_append_term + have hblock :=.execBlock_append_term (s2 := [ .require (eitherExpr @@ -4918,7 +4918,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock := Reasoning.Refinement.execBlock_append_term + have hblock :=.execBlock_append_term (s2 := checkedSubSignedInto "gemNew" (.storage (gemRef (.var "i") (.var "v"))) (.var "dink") ++ diff --git a/Benchmarks/Dss/Vat/Gem.lean b/Benchmarks/Dss/Vat/Gem.lean index 46194a5e..306263a6 100644 --- a/Benchmarks/Dss/Vat/Gem.lean +++ b/Benchmarks/Dss/Vat/Gem.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/Grab.lean b/Benchmarks/Dss/Vat/Grab.lean index a6194bf1..db330c0b 100644 --- a/Benchmarks/Dss/Vat/Grab.lean +++ b/Benchmarks/Dss/Vat/Grab.lean @@ -4,7 +4,7 @@ import Benchmarks.Dss.Vat.FoldCommon namespace Benchmarks.Dss.Vat -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach /-! ## `grab(bytes32,address,address,address,int256,int256)` -/ @@ -4624,7 +4624,7 @@ theorem execGrabUrnArtUpdateOk {evm : EVM.State} {I : ExecutionEnv} [ .assign .storage (urnsF (.var "i") (.var "u") "art") (.var "urnArtNew") ] (.ok { contract := contract, locals := locals' } evm') := ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - exact Reasoning.Refinement.execBlock_append hchecked hassignBlock + exact.execBlock_append hchecked hassignBlock theorem execGrabIlkArtUpdateOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (ilkArtOld ilkArtNew : UInt256) @@ -4677,7 +4677,7 @@ theorem execGrabIlkArtUpdateOk {evm : EVM.State} {I : ExecutionEnv} [ .assign .storage (ilksF (.var "i") "Art") (.var "ilkArtNew") ] (.ok { contract := contract, locals := locals' } evm') := ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - exact Reasoning.Refinement.execBlock_append hchecked hassignBlock + exact.execBlock_append hchecked hassignBlock theorem execGrabGemUpdateOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (gemOld gemNew : UInt256) @@ -4735,7 +4735,7 @@ theorem execGrabGemUpdateOk {evm : EVM.State} {I : ExecutionEnv} [ .assign .storage (gemRef (.var "i") (.var "v")) (.var "gemNew") ] (.ok { contract := contract, locals := locals' } evm') := ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - exact Reasoning.Refinement.execBlock_append hchecked hassignBlock + exact.execBlock_append hchecked hassignBlock theorem execGrabSinUpdateOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (sinOld sinNew dtabWord : UInt256) (dtab : Int) @@ -4786,7 +4786,7 @@ theorem execGrabSinUpdateOk {evm : EVM.State} {I : ExecutionEnv} [ .assign .storage (sinRef (.var "w")) (.var "sinNew") ] (.ok { contract := contract, locals := locals' } evm') := ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - exact Reasoning.Refinement.execBlock_append hchecked hassignBlock + exact.execBlock_append hchecked hassignBlock theorem execGrabViceUpdateOk {evm : EVM.State} (locals : Store) (viceOld viceNew dtabWord : UInt256) (dtab : Int) @@ -4829,7 +4829,7 @@ theorem execGrabViceUpdateOk {evm : EVM.State} [ .assign .storage viceRef (.var "viceNew") ] (.ok { contract := contract, locals := locals' } evm') := ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - exact Reasoning.Refinement.execBlock_append hchecked hassignBlock + exact.execBlock_append hchecked hassignBlock theorem execGrabFinalAssignmentsOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) @@ -5432,13 +5432,13 @@ theorem execGrabSourceOk {cA gh bl σ σ₀ A I} {g : UInt256} viceOld viceNew dtabWord dtab hVice_dtab hVice_vice (by simpa [evm0, evm1, evm2, evm3, evm4, evm5] using hloadVice) hdtabMod hviceNew hviceNeg hvicePos - have h01 := Reasoning.Refinement.execBlock_append hprefix hInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hArtBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hIlkBlock - have h04 := Reasoning.Refinement.execBlock_append h03 hDtabBlock - have h05 := Reasoning.Refinement.execBlock_append h04 hGemBlock - have h06 := Reasoning.Refinement.execBlock_append h05 hSinBlock - have hblock := Reasoning.Refinement.execBlock_append h06 hViceBlock + have h01 :=.execBlock_append hprefix hInkBlock + have h02 :=.execBlock_append h01 hArtBlock + have h03 :=.execBlock_append h02 hIlkBlock + have h04 :=.execBlock_append h03 hDtabBlock + have h05 :=.execBlock_append h04 hGemBlock + have h06 :=.execBlock_append h05 hSinBlock + have hblock :=.execBlock_append h06 hViceBlock simpa [ExecTransitionBody] using ExecFuncBody.execBlockOK hblock theorem vatGrabSourceBodySuccessFromFinalValues @@ -5724,8 +5724,8 @@ theorem vatGrabSourceBodyUrnInkRevertGuardNeg (grabSourceLoad_urnInk (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hsz196)) (by simp [grabUrnInkNew, vatSlotWord]) hguardNeg - have h01 := Reasoning.Refinement.execBlock_append hprefix hInkRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hInkRevert + have hblock :=.execBlock_append_term (s2 := [ .assign .storage (urnsF (.var "i") (.var "u") "ink") (.var "urnInkNew") ] ++ checkedAddSignedInto "urnArtNew" (.storage (urnsF (.var "i") (.var "u") "art")) @@ -5788,8 +5788,8 @@ theorem vatGrabSourceBodyUrnInkRevertGuardPos (grabSourceLoad_urnInk (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hsz196)) (by simp [grabUrnInkNew, vatSlotWord]) hguardNeg hguardPos - have h01 := Reasoning.Refinement.execBlock_append hprefix hInkRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hInkRevert + have hblock :=.execBlock_append_term (s2 := [ .assign .storage (urnsF (.var "i") (.var "u") "ink") (.var "urnInkNew") ] ++ checkedAddSignedInto "urnArtNew" (.storage (urnsF (.var "i") (.var "u") "art")) @@ -5870,14 +5870,14 @@ theorem vatGrabSourceBodyUrnArtRevertFromBlock (by simp [urnInkNew, grabUrnInkNew, vatSlotWord]) (by simpa [urnInkNew, vatSlotWord] using hinkNeg) (by simpa [urnInkNew, vatSlotWord] using hinkPos) - have h01 := Reasoning.Refinement.execBlock_append hprefix hInkBlock + have h01 :=.execBlock_append hprefix hInkBlock have hArt : ExecBlock config { contract := contract, locals := localsInk } evm1 (checkedAddSignedInto "urnArtNew" (.storage (urnsF (.var "i") (.var "u") "art")) (.var "dart")) .reverted := by simpa [evm0, evm1, localsInk, urnInkNew] using hArtRevert - have h02 := Reasoning.Refinement.execBlock_append h01 hArt - have hblock := Reasoning.Refinement.execBlock_append_term + have h02 :=.execBlock_append h01 hArt + have hblock :=.execBlock_append_term (s2 := [ .assign .storage (urnsF (.var "i") (.var "u") "art") (.var "urnArtNew") ] ++ checkedAddSignedInto "ilkArtNew" (.storage (ilksF (.var "i") "Art")) @@ -6115,15 +6115,15 @@ theorem vatGrabSourceBodyIlkArtRevertFromBlock (by simp [urnArtNew, grabUrnArtNew]) (by simpa [urnArtNew] using hartNeg) (by simpa [urnArtNew] using hartPos) - have h01 := Reasoning.Refinement.execBlock_append hprefix hInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hArtBlock + have h01 :=.execBlock_append hprefix hInkBlock + have h02 :=.execBlock_append h01 hArtBlock have hIlk : ExecBlock config { contract := contract, locals := localsArt } evm2 (checkedAddSignedInto "ilkArtNew" (.storage (ilksF (.var "i") "Art")) (.var "dart")) .reverted := by simpa [evm0, evm1, evm2, localsArt, urnInkNew, urnArtNew] using hIlkRevert - have h03 := Reasoning.Refinement.execBlock_append h02 hIlk - have hblock := Reasoning.Refinement.execBlock_append_term + have h03 :=.execBlock_append h02 hIlk + have hblock :=.execBlock_append_term (s2 := [ .assign .storage (ilksF (.var "i") "Art") (.var "ilkArtNew") ] ++ checkedMulSignedInto "dtab" (.storage (ilksF (.var "i") "rate")) (.var "dart") ++ @@ -6432,16 +6432,16 @@ theorem vatGrabSourceBodyDtabRevertFromBlock (by simp [ilkArtNew, grabIlkArtNew]) (by simpa [ilkArtNew] using hilkNeg) (by simpa [ilkArtNew] using hilkPos) - have h01 := Reasoning.Refinement.execBlock_append hprefix hInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hArtBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hIlkBlock + have h01 :=.execBlock_append hprefix hInkBlock + have h02 :=.execBlock_append h01 hArtBlock + have h03 :=.execBlock_append h02 hIlkBlock have hDtab : ExecBlock config { contract := contract, locals := localsIlk } evm3 (checkedMulSignedInto "dtab" (.storage (ilksF (.var "i") "rate")) (.var "dart")) .reverted := by simpa [evm0, evm1, evm2, evm3, localsIlk, urnInkNew, urnArtNew, ilkArtNew] using hDtabRevert - have h04 := Reasoning.Refinement.execBlock_append h03 hDtab - have hblock := Reasoning.Refinement.execBlock_append_term + have h04 :=.execBlock_append h03 hDtab + have hblock :=.execBlock_append_term (s2 := checkedSubSignedInto "gemNew" (.storage (gemRef (.var "i") (.var "v"))) (.var "dink") ++ @@ -6656,11 +6656,11 @@ theorem vatGrabSourceBodyPostDtabRevertFromBlock .reverted := by simpa [evm0, evm1, evm2, evm3, localsDtab, urnInkNew, urnArtNew, ilkArtNew] using hTailRevert - have h01 := Reasoning.Refinement.execBlock_append hprefix hInkBlock - have h02 := Reasoning.Refinement.execBlock_append h01 hArtBlock - have h03 := Reasoning.Refinement.execBlock_append h02 hIlkBlock - have h04 := Reasoning.Refinement.execBlock_append h03 hDtab - have h05 := Reasoning.Refinement.execBlock_append h04 hTail + have h01 :=.execBlock_append hprefix hInkBlock + have h02 :=.execBlock_append h01 hArtBlock + have h03 :=.execBlock_append h02 hIlkBlock + have h04 :=.execBlock_append h03 hDtab + have h05 :=.execBlock_append h04 hTail simpa [ExecTransitionBody, grabTransition, nonpayable, auth, evm0, evm1, evm2, evm3, localsInk, localsArt, localsIlk, localsDtab, urnInkNew, urnArtNew, ilkArtNew, List.append_assoc] using ExecFuncBody.execBlockRevert h05 @@ -6681,7 +6681,7 @@ theorem execGrabTailGemRevertFromBlock {evm : EVM.State} checkedSubSignedInto "viceNew" (.storage viceRef) (.var "dtab") ++ [ .assign .storage viceRef (.var "viceNew") ]) .reverted := by - have h := Reasoning.Refinement.execBlock_append_term + have h :=.execBlock_append_term (s2 := [ .assign .storage (gemRef (.var "i") (.var "v")) (.var "gemNew") ] ++ checkedSubSignedInto "sinNew" (.storage (sinRef (.var "w"))) (.var "dtab") ++ @@ -6712,8 +6712,8 @@ theorem execGrabTailSinRevertFromBlock {evm evm4 : EVM.State} checkedSubSignedInto "viceNew" (.storage viceRef) (.var "dtab") ++ [ .assign .storage viceRef (.var "viceNew") ]) .reverted := by - have h01 := Reasoning.Refinement.execBlock_append hGem hSin - have h := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hGem hSin + have h :=.execBlock_append_term (s2 := [ .assign .storage (sinRef (.var "w")) (.var "sinNew") ] ++ checkedSubSignedInto "viceNew" (.storage viceRef) (.var "dtab") ++ @@ -6747,9 +6747,9 @@ theorem execGrabTailViceRevertFromBlock {evm evm4 evm5 : EVM.State} checkedSubSignedInto "viceNew" (.storage viceRef) (.var "dtab") ++ [ .assign .storage viceRef (.var "viceNew") ]) .reverted := by - have h01 := Reasoning.Refinement.execBlock_append hGem hSin - have h02 := Reasoning.Refinement.execBlock_append h01 hVice - have h := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hGem hSin + have h02 :=.execBlock_append h01 hVice + have h :=.execBlock_append_term (s2 := [ .assign .storage viceRef (.var "viceNew") ]) h02 (by intro f e h; cases h) simpa [List.append_assoc] using h diff --git a/Benchmarks/Dss/Vat/Heal.lean b/Benchmarks/Dss/Vat/Heal.lean index 75da9e6f..c36a87f5 100644 --- a/Benchmarks/Dss/Vat/Heal.lean +++ b/Benchmarks/Dss/Vat/Heal.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.HealBase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vat/HealBase.lean b/Benchmarks/Dss/Vat/HealBase.lean index f0606a90..33ca7f50 100644 --- a/Benchmarks/Dss/Vat/HealBase.lean +++ b/Benchmarks/Dss/Vat/HealBase.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vat/Hope.lean b/Benchmarks/Dss/Vat/Hope.lean index 4de7d205..2fd0075e 100644 --- a/Benchmarks/Dss/Vat/Hope.lean +++ b/Benchmarks/Dss/Vat/Hope.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/Ilks.lean b/Benchmarks/Dss/Vat/Ilks.lean index 4a08da6c..76b916b4 100644 --- a/Benchmarks/Dss/Vat/Ilks.lean +++ b/Benchmarks/Dss/Vat/Ilks.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Vat.Init import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/Init.lean b/Benchmarks/Dss/Vat/Init.lean index 634069ef..7544076d 100644 --- a/Benchmarks/Dss/Vat/Init.lean +++ b/Benchmarks/Dss/Vat/Init.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Rely -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 50000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vat/Line.lean b/Benchmarks/Dss/Vat/Line.lean index 034b4c73..f09d88d9 100644 --- a/Benchmarks/Dss/Vat/Line.lean +++ b/Benchmarks/Dss/Vat/Line.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Vat diff --git a/Benchmarks/Dss/Vat/Live.lean b/Benchmarks/Dss/Vat/Live.lean index 32a27aa7..9cacf42d 100644 --- a/Benchmarks/Dss/Vat/Live.lean +++ b/Benchmarks/Dss/Vat/Live.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Vat diff --git a/Benchmarks/Dss/Vat/Move.lean b/Benchmarks/Dss/Vat/Move.lean index 43cf0cb3..fe068174 100644 --- a/Benchmarks/Dss/Vat/Move.lean +++ b/Benchmarks/Dss/Vat/Move.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Vat.Flux namespace Benchmarks.Dss.Vat -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/Nope.lean b/Benchmarks/Dss/Vat/Nope.lean index d5e1779e..f01ef3fd 100644 --- a/Benchmarks/Dss/Vat/Nope.lean +++ b/Benchmarks/Dss/Vat/Nope.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Hope -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/Rely.lean b/Benchmarks/Dss/Vat/Rely.lean index ea3f24ec..e5db60e2 100644 --- a/Benchmarks/Dss/Vat/Rely.lean +++ b/Benchmarks/Dss/Vat/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Nope -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 50000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vat/Signed.lean b/Benchmarks/Dss/Vat/Signed.lean index 240407e6..75393c3c 100644 --- a/Benchmarks/Dss/Vat/Signed.lean +++ b/Benchmarks/Dss/Vat/Signed.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Vat.Slip namespace Benchmarks.Dss.Vat -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach theorem uintWordLeMaxInt256_of_slt_zero {w : UInt256} (hmax : UInt256.slt w ⟨0⟩ = ⟨0⟩) : diff --git a/Benchmarks/Dss/Vat/Sin.lean b/Benchmarks/Dss/Vat/Sin.lean index 059872db..aab30097 100644 --- a/Benchmarks/Dss/Vat/Sin.lean +++ b/Benchmarks/Dss/Vat/Sin.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/Slip.lean b/Benchmarks/Dss/Vat/Slip.lean index 24d87ac0..822a9d2c 100644 --- a/Benchmarks/Dss/Vat/Slip.lean +++ b/Benchmarks/Dss/Vat/Slip.lean @@ -3,7 +3,7 @@ import Benchmarks.Dss.Vat.Rely namespace Benchmarks.Dss.Vat -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/Suck.lean b/Benchmarks/Dss/Vat/Suck.lean index 6cf007ea..5999525c 100644 --- a/Benchmarks/Dss/Vat/Suck.lean +++ b/Benchmarks/Dss/Vat/Suck.lean @@ -4,7 +4,7 @@ import Benchmarks.Dss.Vat.Rely namespace Benchmarks.Dss.Vat -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 @@ -981,14 +981,14 @@ theorem vatSuckSourceSuccess (evm : EVM.State) (I : ExecutionEnv) have hdebtAssign := vatSuckAssignDebtOk evmVice I (sinNew := sinNew) (daiNew := daiNew) (viceNew := viceNew) (debtNew := debtNew) - have h01 := Reasoning.Refinement.execBlock_append hprefix hsinAdd - have h02 := Reasoning.Refinement.execBlock_append h01 hsinAssign - have h03 := Reasoning.Refinement.execBlock_append h02 hdaiAdd - have h04 := Reasoning.Refinement.execBlock_append h03 hdaiAssign - have h05 := Reasoning.Refinement.execBlock_append h04 hviceAdd - have h06 := Reasoning.Refinement.execBlock_append h05 hviceAssign - have h07 := Reasoning.Refinement.execBlock_append h06 hdebtAdd - have hblock := Reasoning.Refinement.execBlock_append h07 hdebtAssign + have h01 :=.execBlock_append hprefix hsinAdd + have h02 :=.execBlock_append h01 hsinAssign + have h03 :=.execBlock_append h02 hdaiAdd + have h04 :=.execBlock_append h03 hdaiAssign + have h05 :=.execBlock_append h04 hviceAdd + have h06 :=.execBlock_append h05 hviceAssign + have h07 :=.execBlock_append h06 hdebtAdd + have hblock :=.execBlock_append h07 hdebtAssign simpa [ExecTransitionBody, suckTransition, nonpayable, auth, checkedAddUintInto, List.append_assoc, suckPostState, evmSin, evmDai, evmVice, storageStore_executionEnv] using ExecFuncBody.execBlockOK hblock @@ -1027,10 +1027,10 @@ theorem vatSuckSourceRevertDaiOverflow (evm : EVM.State) (I : ExecutionEnv) have hdaiRevert := vatSuckDaiAddBlockRevert evmSin I (sinNew := sinNew) (daiVal := daiVal) hdaiLoad hdaiOverflow - have h01 := Reasoning.Refinement.execBlock_append hprefix hsinAdd - have h02 := Reasoning.Refinement.execBlock_append h01 hsinAssign - have h03 := Reasoning.Refinement.execBlock_append h02 hdaiRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsinAdd + have h02 :=.execBlock_append h01 hsinAssign + have h03 :=.execBlock_append h02 hdaiRevert + have hblock :=.execBlock_append_term (s2 := [ .assign .storage (daiRef (.var "v")) (.var "daiNew") ] ++ checkedAddUintInto "viceNew" (.storage viceRef) (.var "rad") ++ @@ -1100,10 +1100,10 @@ theorem vatSuckSourceRevertDaiOverflowVat have hdaiRevert := vatSuckDaiAddBlockRevert evmSin I (sinNew := sinNew) (daiVal := daiVal) hdaiLoad hdaiOverflowLoad - have h01 := Reasoning.Refinement.execBlock_append hprefix hsinAdd - have h02 := Reasoning.Refinement.execBlock_append h01 hsinAssign - have h03 := Reasoning.Refinement.execBlock_append h02 hdaiRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsinAdd + have h02 :=.execBlock_append h01 hsinAssign + have h03 :=.execBlock_append h02 hdaiRevert + have hblock :=.execBlock_append_term (s2 := [ .assign .storage (daiRef (.var "v")) (.var "daiNew") ] ++ checkedAddUintInto "viceNew" (.storage viceRef) (.var "rad") ++ @@ -1158,12 +1158,12 @@ theorem vatSuckSourceRevertViceOverflow (evm : EVM.State) (I : ExecutionEnv) have hviceRevert := vatSuckViceAddBlockRevert evmDai I (sinNew := sinNew) (daiNew := daiNew) (viceVal := viceVal) hviceLoad hviceOverflow - have h01 := Reasoning.Refinement.execBlock_append hprefix hsinAdd - have h02 := Reasoning.Refinement.execBlock_append h01 hsinAssign - have h03 := Reasoning.Refinement.execBlock_append h02 hdaiAdd - have h04 := Reasoning.Refinement.execBlock_append h03 hdaiAssign - have h05 := Reasoning.Refinement.execBlock_append h04 hviceRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsinAdd + have h02 :=.execBlock_append h01 hsinAssign + have h03 :=.execBlock_append h02 hdaiAdd + have h04 :=.execBlock_append h03 hdaiAssign + have h05 :=.execBlock_append h04 hviceRevert + have hblock :=.execBlock_append_term (s2 := [ .assign .storage viceRef (.var "viceNew") ] ++ checkedAddUintInto "debtNew" (.storage debtRef) (.var "rad") ++ @@ -1261,12 +1261,12 @@ theorem vatSuckSourceRevertViceOverflowVat sinNew).executionEnv.codeOwner (suckDaiSlot I) daiNew) I (sinNew := sinNew) (daiNew := daiNew) (viceVal := vatSlotWord suckViceSlot σDaiSolm I) hviceLoad hviceOverflow - have h01 := Reasoning.Refinement.execBlock_append hprefix hsinAdd - have h02 := Reasoning.Refinement.execBlock_append h01 hsinAssign - have h03 := Reasoning.Refinement.execBlock_append h02 hdaiAdd - have h04 := Reasoning.Refinement.execBlock_append h03 hdaiAssign - have h05 := Reasoning.Refinement.execBlock_append h04 hviceRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsinAdd + have h02 :=.execBlock_append h01 hsinAssign + have h03 :=.execBlock_append h02 hdaiAdd + have h04 :=.execBlock_append h03 hdaiAssign + have h05 :=.execBlock_append h04 hviceRevert + have hblock :=.execBlock_append_term (s2 := [ .assign .storage viceRef (.var "viceNew") ] ++ checkedAddUintInto "debtNew" (.storage debtRef) (.var "rad") ++ @@ -1332,14 +1332,14 @@ theorem vatSuckSourceRevertDebtOverflow (evm : EVM.State) (I : ExecutionEnv) have hdebtRevert := vatSuckDebtAddBlockRevert evmVice I (sinNew := sinNew) (daiNew := daiNew) (viceNew := viceNew) (debtVal := debtVal) hdebtLoad hdebtOverflow - have h01 := Reasoning.Refinement.execBlock_append hprefix hsinAdd - have h02 := Reasoning.Refinement.execBlock_append h01 hsinAssign - have h03 := Reasoning.Refinement.execBlock_append h02 hdaiAdd - have h04 := Reasoning.Refinement.execBlock_append h03 hdaiAssign - have h05 := Reasoning.Refinement.execBlock_append h04 hviceAdd - have h06 := Reasoning.Refinement.execBlock_append h05 hviceAssign - have h07 := Reasoning.Refinement.execBlock_append h06 hdebtRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsinAdd + have h02 :=.execBlock_append h01 hsinAssign + have h03 :=.execBlock_append h02 hdaiAdd + have h04 :=.execBlock_append h03 hdaiAssign + have h05 :=.execBlock_append h04 hviceAdd + have h06 :=.execBlock_append h05 hviceAssign + have h07 :=.execBlock_append h06 hdebtRevert + have hblock :=.execBlock_append_term (s2 := [ .assign .storage debtRef (.var "debtNew") ]) h07 (by intro f' e' h; cases h) simpa [ExecTransitionBody, suckTransition, nonpayable, auth, checkedAddUintInto, @@ -1439,14 +1439,14 @@ theorem vatSuckSourceRevertDebtOverflowVat vatSuckDebtAddBlockRevert evmVice I (sinNew := sinNew) (daiNew := daiNew) (viceNew := viceNew) (debtVal := vatSlotWord suckDebtSlot σViceSolm I) hdebtLoad hdebtOverflow - have h01 := Reasoning.Refinement.execBlock_append hprefix hsinAdd - have h02 := Reasoning.Refinement.execBlock_append h01 hsinAssign - have h03 := Reasoning.Refinement.execBlock_append h02 hdaiAdd - have h04 := Reasoning.Refinement.execBlock_append h03 hdaiAssign - have h05 := Reasoning.Refinement.execBlock_append h04 hviceAdd - have h06 := Reasoning.Refinement.execBlock_append h05 hviceAssign - have h07 := Reasoning.Refinement.execBlock_append h06 hdebtRevert - have hblock := Reasoning.Refinement.execBlock_append_term + have h01 :=.execBlock_append hprefix hsinAdd + have h02 :=.execBlock_append h01 hsinAssign + have h03 :=.execBlock_append h02 hdaiAdd + have h04 :=.execBlock_append h03 hdaiAssign + have h05 :=.execBlock_append h04 hviceAdd + have h06 :=.execBlock_append h05 hviceAssign + have h07 :=.execBlock_append h06 hdebtRevert + have hblock :=.execBlock_append_term (s2 := [ .assign .storage debtRef (.var "debtNew") ]) h07 (by intro f' e' h; cases h) simpa [ExecTransitionBody, suckTransition, nonpayable, auth, checkedAddUintInto, @@ -1555,14 +1555,14 @@ theorem vatSuckSourceSuccessVat have hdebtAssign := vatSuckAssignDebtOk evmVice I (sinNew := sinNew) (daiNew := daiNew) (viceNew := viceNew) (debtNew := debtNew) - have h01 := Reasoning.Refinement.execBlock_append hprefix hsinAdd - have h02 := Reasoning.Refinement.execBlock_append h01 hsinAssign - have h03 := Reasoning.Refinement.execBlock_append h02 hdaiAdd - have h04 := Reasoning.Refinement.execBlock_append h03 hdaiAssign - have h05 := Reasoning.Refinement.execBlock_append h04 hviceAdd - have h06 := Reasoning.Refinement.execBlock_append h05 hviceAssign - have h07 := Reasoning.Refinement.execBlock_append h06 hdebtAdd - have hblock := Reasoning.Refinement.execBlock_append h07 hdebtAssign + have h01 :=.execBlock_append hprefix hsinAdd + have h02 :=.execBlock_append h01 hsinAssign + have h03 :=.execBlock_append h02 hdaiAdd + have h04 :=.execBlock_append h03 hdaiAssign + have h05 :=.execBlock_append h04 hviceAdd + have h06 :=.execBlock_append h05 hviceAssign + have h07 :=.execBlock_append h06 hdebtAdd + have hblock :=.execBlock_append h07 hdebtAssign simpa [ExecTransitionBody, suckTransition, nonpayable, auth, checkedAddUintInto, List.append_assoc, suckPostState, evmSin, evmDai, evmVice, evmDebt, storageStore_executionEnv] using ExecFuncBody.execBlockOK hblock diff --git a/Benchmarks/Dss/Vat/Urns.lean b/Benchmarks/Dss/Vat/Urns.lean index 34692997..151a211d 100644 --- a/Benchmarks/Dss/Vat/Urns.lean +++ b/Benchmarks/Dss/Vat/Urns.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Gem -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vat/Vice.lean b/Benchmarks/Dss/Vat/Vice.lean index 2b24f1a8..fd433daf 100644 --- a/Benchmarks/Dss/Vat/Vice.lean +++ b/Benchmarks/Dss/Vat/Vice.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Vat diff --git a/Benchmarks/Dss/Vat/Wards.lean b/Benchmarks/Dss/Vat/Wards.lean index 44c2cdf8..4a147edf 100644 --- a/Benchmarks/Dss/Vat/Wards.lean +++ b/Benchmarks/Dss/Vat/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vat.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Arithmetic.lean b/Benchmarks/Dss/Vow/Arithmetic.lean index fa05eedf..367a1317 100644 --- a/Benchmarks/Dss/Vow/Arithmetic.lean +++ b/Benchmarks/Dss/Vow/Arithmetic.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Ash.lean b/Benchmarks/Dss/Vow/Ash.lean index 857dc9ed..6069ae71 100644 --- a/Benchmarks/Dss/Vow/Ash.lean +++ b/Benchmarks/Dss/Vow/Ash.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Bump.lean b/Benchmarks/Dss/Vow/Bump.lean index 626a0794..de406833 100644 --- a/Benchmarks/Dss/Vow/Bump.lean +++ b/Benchmarks/Dss/Vow/Bump.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Cage.lean b/Benchmarks/Dss/Vow/Cage.lean index 7e76e19c..a66e909a 100644 --- a/Benchmarks/Dss/Vow/Cage.lean +++ b/Benchmarks/Dss/Vow/Cage.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Vow.Rely import Benchmarks.Dss.Vow.VatDaiCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/CageBody.lean b/Benchmarks/Dss/Vow/CageBody.lean index f979f49a..dad262e2 100644 --- a/Benchmarks/Dss/Vow/CageBody.lean +++ b/Benchmarks/Dss/Vow/CageBody.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Vow.Arithmetic import Benchmarks.Dss.Vow.Cage import Benchmarks.Dss.Vow.FlopAsh -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/CageBodyRuntime.lean b/Benchmarks/Dss/Vow/CageBodyRuntime.lean index 67d05624..f9ea64d7 100644 --- a/Benchmarks/Dss/Vow/CageBodyRuntime.lean +++ b/Benchmarks/Dss/Vow/CageBodyRuntime.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.CageHealRuntime -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/CageBodyRuntimeTail.lean b/Benchmarks/Dss/Vow/CageBodyRuntimeTail.lean index 03cd0d9c..d7d7d41e 100644 --- a/Benchmarks/Dss/Vow/CageBodyRuntimeTail.lean +++ b/Benchmarks/Dss/Vow/CageBodyRuntimeTail.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.CageBodyRuntime -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/CageHealRuntime.lean b/Benchmarks/Dss/Vow/CageHealRuntime.lean index 0c3f12c0..2cb29c45 100644 --- a/Benchmarks/Dss/Vow/CageHealRuntime.lean +++ b/Benchmarks/Dss/Vow/CageHealRuntime.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.CageTailRuntime -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -118,11 +118,11 @@ theorem cageSourceVatSinSuccessTailRevertFromBlock exact cageVatDaiSuccess (evm := evmFlop) (evmDai := evmDai2) (outDai := outDai2) (flapperDai := flapperDai) (vatDai := vatDai) hvatCode2 hcallDai2 hdecDai2 - have hprefix := Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append hclear hfirst) hflopper) hsecond) hsin) + have hprefix :=.execBlock_append + (Reasoning.Theory.execBlock_append + (Reasoning.Theory.execBlock_append + (Reasoning.Theory.execBlock_append + (Reasoning.Theory.execBlock_append hclear hfirst) hflopper) hsecond) hsin) htail have hblock : ExecBlock config { contract := contract, locals := locals } evm0 @@ -258,11 +258,11 @@ theorem cageSourceVatSinSuccessTailOkFromBlock exact cageVatDaiSuccess (evm := evmFlop) (evmDai := evmDai2) (outDai := outDai2) (flapperDai := flapperDai) (vatDai := vatDai) hvatCode2 hcallDai2 hdecDai2 - have hprefix := Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append hclear hfirst) hflopper) hsecond) hsin) + have hprefix :=.execBlock_append + (Reasoning.Theory.execBlock_append + (Reasoning.Theory.execBlock_append + (Reasoning.Theory.execBlock_append + (Reasoning.Theory.execBlock_append hclear hfirst) hflopper) hsecond) hsin) htail have hblock : ExecBlock config { contract := contract, locals := locals } evm0 diff --git a/Benchmarks/Dss/Vow/CageRuntime.lean b/Benchmarks/Dss/Vow/CageRuntime.lean index 28dba7f5..23542b5b 100644 --- a/Benchmarks/Dss/Vow/CageRuntime.lean +++ b/Benchmarks/Dss/Vow/CageRuntime.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Vow.CageBody import Benchmarks.Dss.Vow.FlapBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -328,7 +328,7 @@ theorem cageFirstDaiFlapperNoCode ExecBlock config { contract := contract, locals := ∅ } evm (cageFirstVatDaiStmts ++ cageFlapperCageStmts) .reverted := by have hfirst := cageFirstVatDaiNoCode (evm := evm) hvatNoCode - exact Reasoning.Refinement.execBlock_append_term (s2 := cageFlapperCageStmts) hfirst + exact.execBlock_append_term (s2 := cageFlapperCageStmts) hfirst (by intro f e h; cases h) theorem cageFirstDaiFlapperCallFailure @@ -345,7 +345,7 @@ theorem cageFirstDaiFlapperCallFailure (cageFirstVatDaiStmts ++ cageFlapperCageStmts) .reverted := by have hfirst := cageFirstVatDaiCallFailure (evm := evm) (evmDai := evmDai) (outDai := outDai) hvatCode hcallDai - exact Reasoning.Refinement.execBlock_append_term (s2 := cageFlapperCageStmts) hfirst + exact.execBlock_append_term (s2 := cageFlapperCageStmts) hfirst (by intro f e h; cases h) theorem cageFirstDaiFlapperReturnDecodeFailure @@ -363,7 +363,7 @@ theorem cageFirstDaiFlapperReturnDecodeFailure (cageFirstVatDaiStmts ++ cageFlapperCageStmts) .reverted := by have hfirst := cageFirstVatDaiReturnDecodeFailure (evm := evm) (evmDai := evmDai) (outDai := outDai) hvatCode hcallDai hdecDai - exact Reasoning.Refinement.execBlock_append_term (s2 := cageFlapperCageStmts) hfirst + exact.execBlock_append_term (s2 := cageFlapperCageStmts) hfirst (by intro f e h; cases h) theorem cageFirstDaiFlapperCageNoCode @@ -389,7 +389,7 @@ theorem cageFirstDaiFlapperCageNoCode (outDai := outDai) (flapperDai := flapperDai) hvatCode hcallDai hdecDai have hflapper := cageFlapperCageNoCode (evm := evmDai) (flapperDai := flapperDai) hflapperNoCode - exact Reasoning.Refinement.execBlock_append hfirst hflapper + exact.execBlock_append hfirst hflapper theorem cageFirstDaiFlapperCageCallFailure {evm evmDai evmFlap : EVM.State} {outDai outFlap : ByteArray} @@ -419,7 +419,7 @@ theorem cageFirstDaiFlapperCageCallFailure (outDai := outDai) (flapperDai := flapperDai) hvatCode hcallDai hdecDai have hflapper := cageFlapperCageCallFailure (evm := evmDai) (evmFlap := evmFlap) (outFlap := outFlap) (flapperDai := flapperDai) hflapperCode hcallFlap - exact Reasoning.Refinement.execBlock_append hfirst hflapper + exact.execBlock_append hfirst hflapper theorem cageFirstDaiFlapperCageSuccess {evm evmDai evmFlap : EVM.State} {outDai outFlap : ByteArray} @@ -451,7 +451,7 @@ theorem cageFirstDaiFlapperCageSuccess (outDai := outDai) (flapperDai := flapperDai) hvatCode hcallDai hdecDai have hflapper := cageFlapperCageSuccess (evm := evmDai) (evmFlap := evmFlap) (outFlap := outFlap) (flapperDai := flapperDai) hflapperCode hcallFlap - exact Reasoning.Refinement.execBlock_append hfirst hflapper + exact.execBlock_append hfirst hflapper theorem cageSourceFirstDaiNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) @@ -490,7 +490,7 @@ theorem cageSourceFirstDaiNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (cageFirstVatDaiStmts ++ cageFlapperCageStmts) .reverted := by exact cageFirstDaiFlapperNoCode (evm := evmAsh) (by simpa [evm0, evmLive, evmSin, evmAsh] using hvatNoCode) - have hprefix := Reasoning.Refinement.execBlock_append hclear hfirst + have hprefix :=.execBlock_append hclear hfirst have hblock : ExecBlock config { contract := contract, locals := locals } evm0 ((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -501,7 +501,7 @@ theorem cageSourceFirstDaiNoCode {cA gh bl σ σ₀ A I} {g : UInt256} .assign .storage AshRef (.intLit 0) ] ++ cageFirstVatDaiStmts ++ cageFlapperCageStmts) ++ cageAfterFlapperStmts) .reverted := - Reasoning.Refinement.execBlock_append_term (s2 := cageAfterFlapperStmts) + .execBlock_append_term (s2 := cageAfterFlapperStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) have hbody := ExecFuncBody.execBlockRevert hblock @@ -558,7 +558,7 @@ theorem cageSourceFirstDaiCallFailure (outDai := outDai) (by simpa [evm0, evmLive, evmSin, evmAsh] using hvatCode) (by simpa [evm0, evmLive, evmSin, evmAsh] using hcallDai) - have hprefix := Reasoning.Refinement.execBlock_append hclear hfirst + have hprefix :=.execBlock_append hclear hfirst have hblock : ExecBlock config { contract := contract, locals := locals } evm0 ((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -569,7 +569,7 @@ theorem cageSourceFirstDaiCallFailure .assign .storage AshRef (.intLit 0) ] ++ cageFirstVatDaiStmts ++ cageFlapperCageStmts) ++ cageAfterFlapperStmts) .reverted := - Reasoning.Refinement.execBlock_append_term (s2 := cageAfterFlapperStmts) + .execBlock_append_term (s2 := cageAfterFlapperStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) have hbody := ExecFuncBody.execBlockRevert hblock @@ -628,7 +628,7 @@ theorem cageSourceFirstDaiReturnDecodeFailure (by simpa [evm0, evmLive, evmSin, evmAsh] using hvatCode) (by simpa [evm0, evmLive, evmSin, evmAsh] using hcallDai) hdecDai - have hprefix := Reasoning.Refinement.execBlock_append hclear hfirst + have hprefix :=.execBlock_append hclear hfirst have hblock : ExecBlock config { contract := contract, locals := locals } evm0 ((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -639,7 +639,7 @@ theorem cageSourceFirstDaiReturnDecodeFailure .assign .storage AshRef (.intLit 0) ] ++ cageFirstVatDaiStmts ++ cageFlapperCageStmts) ++ cageAfterFlapperStmts) .reverted := - Reasoning.Refinement.execBlock_append_term (s2 := cageAfterFlapperStmts) + .execBlock_append_term (s2 := cageAfterFlapperStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) have hbody := ExecFuncBody.execBlockRevert hblock @@ -705,7 +705,7 @@ theorem cageSourceFlapperCageNoCode (by simpa [evm0, evmLive, evmSin, evmAsh] using hvatCode) (by simpa [evm0, evmLive, evmSin, evmAsh] using hcallDai) hdecDai hflapperNoCode - have hprefix := Reasoning.Refinement.execBlock_append hclear hfirst + have hprefix :=.execBlock_append hclear hfirst have hblock : ExecBlock config { contract := contract, locals := locals } evm0 ((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -716,7 +716,7 @@ theorem cageSourceFlapperCageNoCode .assign .storage AshRef (.intLit 0) ] ++ cageFirstVatDaiStmts ++ cageFlapperCageStmts) ++ cageAfterFlapperStmts) .reverted := - Reasoning.Refinement.execBlock_append_term (s2 := cageAfterFlapperStmts) + .execBlock_append_term (s2 := cageAfterFlapperStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) have hbody := ExecFuncBody.execBlockRevert hblock @@ -787,7 +787,7 @@ theorem cageSourceFlapperCageCallFailure (by simpa [evm0, evmLive, evmSin, evmAsh] using hvatCode) (by simpa [evm0, evmLive, evmSin, evmAsh] using hcallDai) hdecDai hflapperCode hcallFlap - have hprefix := Reasoning.Refinement.execBlock_append hclear hfirst + have hprefix :=.execBlock_append hclear hfirst have hblock : ExecBlock config { contract := contract, locals := locals } evm0 ((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -798,7 +798,7 @@ theorem cageSourceFlapperCageCallFailure .assign .storage AshRef (.intLit 0) ] ++ cageFirstVatDaiStmts ++ cageFlapperCageStmts) ++ cageAfterFlapperStmts) .reverted := - Reasoning.Refinement.execBlock_append_term (s2 := cageAfterFlapperStmts) + .execBlock_append_term (s2 := cageAfterFlapperStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) have hbody := ExecFuncBody.execBlockRevert hblock @@ -881,8 +881,8 @@ theorem cageSourceFlopperCageNoCode evmFlap cageFlopperCageStmts .reverted := cageFlopperCageNoCode (evm := evmFlap) (flapperDai := flapperDai) hflopperNoCode - have hprefix := Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append hclear hfirst) hflopper + have hprefix :=.execBlock_append + (Reasoning.Theory.execBlock_append hclear hfirst) hflopper have hblock : ExecBlock config { contract := contract, locals := locals } evm0 (((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -895,7 +895,7 @@ theorem cageSourceFlopperCageNoCode cageFlopperCageStmts) ++ cageVatDaiStmts ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) .reverted := - Reasoning.Refinement.execBlock_append_term + .execBlock_append_term (s2 := cageVatDaiStmts ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) @@ -982,8 +982,8 @@ theorem cageSourceFlopperCageCallFailure evmFlap cageFlopperCageStmts .reverted := cageFlopperCageCallFailure (evm := evmFlap) (evmFlop := evmFlop) (outFlop := outFlop) (flapperDai := flapperDai) hflopperCode hcallFlop - have hprefix := Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append hclear hfirst) hflopper + have hprefix :=.execBlock_append + (Reasoning.Theory.execBlock_append hclear hfirst) hflopper have hblock : ExecBlock config { contract := contract, locals := locals } evm0 (((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -996,7 +996,7 @@ theorem cageSourceFlopperCageCallFailure cageFlopperCageStmts) ++ cageVatDaiStmts ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) .reverted := - Reasoning.Refinement.execBlock_append_term + .execBlock_append_term (s2 := cageVatDaiStmts ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) @@ -1550,7 +1550,7 @@ theorem cageMinHealLeftNoCode (vatSin := vatSin) (evm := evm) hle have hheal := cageVatHealNoCode (flapperDai := flapperDai) (vatDai := vatDai) (vatSin := vatSin) (healRad := vatDai) (evm := evm) hvatNoCode - exact Reasoning.Refinement.execBlock_append hmin hheal + exact.execBlock_append hmin hheal theorem cageMinHealRightNoCode {evm : EVM.State} {flapperDai vatDai vatSin : UInt256} @@ -1567,7 +1567,7 @@ theorem cageMinHealRightNoCode (vatSin := vatSin) (evm := evm) hlt have hheal := cageVatHealNoCode (flapperDai := flapperDai) (vatDai := vatDai) (vatSin := vatSin) (healRad := vatSin) (evm := evm) hvatNoCode - exact Reasoning.Refinement.execBlock_append hmin hheal + exact.execBlock_append hmin hheal theorem cageMinHealLeftCallFailure {evm evmHeal : EVM.State} {outHeal : ByteArray} @@ -1589,7 +1589,7 @@ theorem cageMinHealLeftCallFailure have hheal := cageVatHealCallFailure (flapperDai := flapperDai) (vatDai := vatDai) (vatSin := vatSin) (healRad := vatDai) (evm := evm) (evmHeal := evmHeal) (outHeal := outHeal) hvatCode hcallHeal - exact Reasoning.Refinement.execBlock_append hmin hheal + exact.execBlock_append hmin hheal theorem cageMinHealRightCallFailure {evm evmHeal : EVM.State} {outHeal : ByteArray} @@ -1611,7 +1611,7 @@ theorem cageMinHealRightCallFailure have hheal := cageVatHealCallFailure (flapperDai := flapperDai) (vatDai := vatDai) (vatSin := vatSin) (healRad := vatSin) (evm := evm) (evmHeal := evmHeal) (outHeal := outHeal) hvatCode hcallHeal - exact Reasoning.Refinement.execBlock_append hmin hheal + exact.execBlock_append hmin hheal theorem cageMinHealLeftSuccess {evm evmHeal : EVM.State} {outHeal : ByteArray} @@ -1635,7 +1635,7 @@ theorem cageMinHealLeftSuccess have hheal := cageVatHealSuccess (flapperDai := flapperDai) (vatDai := vatDai) (vatSin := vatSin) (healRad := vatDai) (evm := evm) (evmHeal := evmHeal) (outHeal := outHeal) hvatCode hcallHeal - exact Reasoning.Refinement.execBlock_append hmin hheal + exact.execBlock_append hmin hheal theorem cageMinHealRightSuccess {evm evmHeal : EVM.State} {outHeal : ByteArray} @@ -1659,6 +1659,6 @@ theorem cageMinHealRightSuccess have hheal := cageVatHealSuccess (flapperDai := flapperDai) (vatDai := vatDai) (vatSin := vatSin) (healRad := vatSin) (evm := evm) (evmHeal := evmHeal) (outHeal := outHeal) hvatCode hcallHeal - exact Reasoning.Refinement.execBlock_append hmin hheal + exact.execBlock_append hmin hheal end Benchmarks.Dss.Vow diff --git a/Benchmarks/Dss/Vow/CageTailRuntime.lean b/Benchmarks/Dss/Vow/CageTailRuntime.lean index ab996b49..d53ffbc7 100644 --- a/Benchmarks/Dss/Vow/CageTailRuntime.lean +++ b/Benchmarks/Dss/Vow/CageTailRuntime.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.CageRuntime -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -96,9 +96,9 @@ theorem cageSourceSecondDaiNoCode { contract := contract, locals := cageLocalsAfterFlopCage flapperDai } evmFlop cageVatDaiStmts .reverted := cageVatDaiNoCode (evm := evmFlop) (flapperDai := flapperDai) hvatNoCode - have hprefix := Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append hclear hfirst) hflopper) hsecond + have hprefix :=.execBlock_append + (Reasoning.Theory.execBlock_append + (Reasoning.Theory.execBlock_append hclear hfirst) hflopper) hsecond have hblock : ExecBlock config { contract := contract, locals := locals } evm0 ((((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -111,7 +111,7 @@ theorem cageSourceSecondDaiNoCode cageFlopperCageStmts) ++ cageVatDaiStmts) ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) .reverted := - Reasoning.Refinement.execBlock_append_term + .execBlock_append_term (s2 := cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) @@ -215,9 +215,9 @@ theorem cageSourceSecondDaiCallFailure evmFlop cageVatDaiStmts .reverted := cageVatDaiCallFailure (evm := evmFlop) (evmDai := evmDai2) (outDai := outDai2) (flapperDai := flapperDai) hvatCode2 hcallDai2 - have hprefix := Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append hclear hfirst) hflopper) hsecond + have hprefix :=.execBlock_append + (Reasoning.Theory.execBlock_append + (Reasoning.Theory.execBlock_append hclear hfirst) hflopper) hsecond have hblock : ExecBlock config { contract := contract, locals := locals } evm0 ((((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -230,7 +230,7 @@ theorem cageSourceSecondDaiCallFailure cageFlopperCageStmts) ++ cageVatDaiStmts) ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) .reverted := - Reasoning.Refinement.execBlock_append_term + .execBlock_append_term (s2 := cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) @@ -335,9 +335,9 @@ theorem cageSourceSecondDaiReturnDecodeFailure evmFlop cageVatDaiStmts .reverted := cageVatDaiReturnDecodeFailure (evm := evmFlop) (evmDai := evmDai2) (outDai := outDai2) (flapperDai := flapperDai) hvatCode2 hcallDai2 hdecDai2 - have hprefix := Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append hclear hfirst) hflopper) hsecond + have hprefix :=.execBlock_append + (Reasoning.Theory.execBlock_append + (Reasoning.Theory.execBlock_append hclear hfirst) hflopper) hsecond have hblock : ExecBlock config { contract := contract, locals := locals } evm0 ((((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -350,7 +350,7 @@ theorem cageSourceSecondDaiReturnDecodeFailure cageFlopperCageStmts) ++ cageVatDaiStmts) ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) .reverted := - Reasoning.Refinement.execBlock_append_term + .execBlock_append_term (s2 := cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) @@ -470,10 +470,10 @@ theorem cageSourceVatSinNoCode evmDai2 cageVatSinStmts .reverted := cageVatSinNoCode (evm := evmDai2) (flapperDai := flapperDai) (vatDai := vatDai) hvatNoCode - have hprefix := Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append hclear hfirst) hflopper) hsecond) hsin + have hprefix :=.execBlock_append + (Reasoning.Theory.execBlock_append + (Reasoning.Theory.execBlock_append + (Reasoning.Theory.execBlock_append hclear hfirst) hflopper) hsecond) hsin have hblock : ExecBlock config { contract := contract, locals := locals } evm0 (((((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -486,7 +486,7 @@ theorem cageSourceVatSinNoCode cageFlopperCageStmts) ++ cageVatDaiStmts) ++ cageVatSinStmts) ++ cageMinStmts ++ cageVatHealStmts) .reverted := - Reasoning.Refinement.execBlock_append_term + .execBlock_append_term (s2 := cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) @@ -600,10 +600,10 @@ theorem cageSourceVatSinRevertFromBlock exact cageVatDaiSuccess (evm := evmFlop) (evmDai := evmDai2) (outDai := outDai2) (flapperDai := flapperDai) (vatDai := vatDai) hvatCode2 hcallDai2 hdecDai2 - have hprefix := Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append - (Reasoning.Refinement.execBlock_append hclear hfirst) hflopper) hsecond) hsin + have hprefix :=.execBlock_append + (Reasoning.Theory.execBlock_append + (Reasoning.Theory.execBlock_append + (Reasoning.Theory.execBlock_append hclear hfirst) hflopper) hsecond) hsin have hblock : ExecBlock config { contract := contract, locals := locals } evm0 (((((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -616,7 +616,7 @@ theorem cageSourceVatSinRevertFromBlock cageFlopperCageStmts) ++ cageVatDaiStmts) ++ cageVatSinStmts) ++ cageMinStmts ++ cageVatHealStmts) .reverted := - Reasoning.Refinement.execBlock_append_term + .execBlock_append_term (s2 := cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) diff --git a/Benchmarks/Dss/Vow/Common.lean b/Benchmarks/Dss/Vow/Common.lean index abcc3802..6443e8d7 100644 --- a/Benchmarks/Dss/Vow/Common.lean +++ b/Benchmarks/Dss/Vow/Common.lean @@ -2,7 +2,6 @@ import Benchmarks.Dss.Vow.Trusted import Reasoning.ABI import Reasoning.Dispatch import Reasoning.Memory -import Reasoning.Refinement import Reasoning.Reach import Reasoning.Solc import Reasoning.Storage @@ -16,7 +15,7 @@ This file contains contract-wide selector, dispatch-failure, and global revert f top-level runtime proof and the per-function body proofs. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Constructor.lean b/Benchmarks/Dss/Vow/Constructor.lean index 97b7de51..e3b64254 100644 --- a/Benchmarks/Dss/Vow/Constructor.lean +++ b/Benchmarks/Dss/Vow/Constructor.lean @@ -1708,7 +1708,7 @@ theorem vowCtorSolmExecReverts_noCode exact ExecBlock.consRevert (ExecStmt.requireFalse hguard) simpa [ExecTransitionBody, contract, constructorDecl, nonpayable, checkedExternalCallStmts, locals, evm0, evm1, evm2, evm3, evm4, List.cons_append, List.nil_append] using - Reasoning.Refinement.execBlock_append hprefix htail + .execBlock_append hprefix htail theorem vowCtorSolmExecReverts_callFailure {createdAccounts : Batteries.RBSet AccountAddress compare} @@ -1782,7 +1782,7 @@ theorem vowCtorSolmExecReverts_callFailure (by simpa [evm0, evm1, evm2, evm3, evm4] using hcall)) simpa [ExecTransitionBody, contract, constructorDecl, nonpayable, checkedExternalCallStmts, locals, evm0, evm1, evm2, evm3, evm4, List.cons_append, List.nil_append] using - Reasoning.Refinement.execBlock_append hprefix htail + .execBlock_append hprefix htail theorem vowCtorSolmExecSuccess {createdAccounts : Batteries.RBSet AccountAddress compare} @@ -1879,7 +1879,7 @@ theorem vowCtorSolmExecSuccess (.ok { contract := contract, locals := localsHope } evm5) := by simpa [constructorDecl, nonpayable, checkedExternalCallStmts, locals, evm0, evm1, evm2, evm3, evm4, evm5, List.cons_append, List.nil_append] using - Reasoning.Refinement.execBlock_append hprefix htail + .execBlock_append hprefix htail simpa [ExecTransitionBody, contract, constructorDecl, locals, localsHope, evm0, evm5] using ExecFuncBody.execBlockOK hblock diff --git a/Benchmarks/Dss/Vow/Correct.lean b/Benchmarks/Dss/Vow/Correct.lean index 7b85c00d..9cbb758b 100644 --- a/Benchmarks/Dss/Vow/Correct.lean +++ b/Benchmarks/Dss/Vow/Correct.lean @@ -30,7 +30,6 @@ import Benchmarks.Dss.Vow.Sump import Benchmarks.Dss.Vow.Vat import Benchmarks.Dss.Vow.Wait import Benchmarks.Dss.Vow.Wards -import Reasoning.Refinement import Solm.Equiv /-! @@ -41,7 +40,7 @@ are present. The runtime-equivalence proof is intentionally left as the benchmar also exposes the whole-contract wrapper that combines the constructor and runtime targets. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Deny.lean b/Benchmarks/Dss/Vow/Deny.lean index 51c54a3a..63c81e65 100644 --- a/Benchmarks/Dss/Vow/Deny.lean +++ b/Benchmarks/Dss/Vow/Deny.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/Dump.lean b/Benchmarks/Dss/Vow/Dump.lean index 05f292f4..5f5aa2e3 100644 --- a/Benchmarks/Dss/Vow/Dump.lean +++ b/Benchmarks/Dss/Vow/Dump.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Fess.lean b/Benchmarks/Dss/Vow/Fess.lean index 5363efcf..7f198cf6 100644 --- a/Benchmarks/Dss/Vow/Fess.lean +++ b/Benchmarks/Dss/Vow/Fess.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Deny -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/FileAddress.lean b/Benchmarks/Dss/Vow/FileAddress.lean index 23370b52..f8f2a9c6 100644 --- a/Benchmarks/Dss/Vow/FileAddress.lean +++ b/Benchmarks/Dss/Vow/FileAddress.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Vow.FileUint import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/FileAddressFlapper.lean b/Benchmarks/Dss/Vow/FileAddressFlapper.lean index 263752e2..fa2b9676 100644 --- a/Benchmarks/Dss/Vow/FileAddressFlapper.lean +++ b/Benchmarks/Dss/Vow/FileAddressFlapper.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.FileAddress -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/FileAddressFlapperBody.lean b/Benchmarks/Dss/Vow/FileAddressFlapperBody.lean index 34d83980..5d13a1bb 100644 --- a/Benchmarks/Dss/Vow/FileAddressFlapperBody.lean +++ b/Benchmarks/Dss/Vow/FileAddressFlapperBody.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.FileAddressFlapper -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/FileUint.lean b/Benchmarks/Dss/Vow/FileUint.lean index 8bcfe1bf..9c2ed9e2 100644 --- a/Benchmarks/Dss/Vow/FileUint.lean +++ b/Benchmarks/Dss/Vow/FileUint.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Deny -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/Flap.lean b/Benchmarks/Dss/Vow/Flap.lean index 52fffa83..f989185d 100644 --- a/Benchmarks/Dss/Vow/Flap.lean +++ b/Benchmarks/Dss/Vow/Flap.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Vow.HealSuccess import Benchmarks.Dss.Vow.VatSinCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/FlapAdd.lean b/Benchmarks/Dss/Vow/FlapAdd.lean index 1535818b..5315ca66 100644 --- a/Benchmarks/Dss/Vow/FlapAdd.lean +++ b/Benchmarks/Dss/Vow/FlapAdd.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Flap -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/FlapBody.lean b/Benchmarks/Dss/Vow/FlapBody.lean index 368a136f..49212041 100644 --- a/Benchmarks/Dss/Vow/FlapBody.lean +++ b/Benchmarks/Dss/Vow/FlapBody.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.FlapKick -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -730,7 +730,7 @@ theorem flapSourceInsufficientSurplus have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hprefix htail + have hcat :=.execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -1212,7 +1212,7 @@ theorem flapPostDaiToKickSuccess (vatDai := vatDai) (vatSin1 := vatSin1) (freeSin := freeSin) (debt := debt) (BumpVal := BumpVal) (id := id) hBumpLoad hflapperCode hcallKick hdecKick - have htail := Reasoning.Refinement.execBlock_append hpost hkick + have htail :=.execBlock_append hpost hkick simpa [flapTailStmts] using htail theorem flapSourceBlockSuccess @@ -1328,7 +1328,7 @@ theorem flapSourceBlockSuccess ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body (.returned { contract := contract, locals := locals8 } evmKick (some [.int (Int.ofNat id.toNat)])) := by - have hcat := Reasoning.Refinement.execBlock_append hprefix htail + have hcat :=.execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat diff --git a/Benchmarks/Dss/Vow/FlapDai.lean b/Benchmarks/Dss/Vow/FlapDai.lean index d6e6cc0f..2784db61 100644 --- a/Benchmarks/Dss/Vow/FlapDai.lean +++ b/Benchmarks/Dss/Vow/FlapDai.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Vow.FlapAdd import Benchmarks.Dss.Vow.VatDaiCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/FlapDaiBody.lean b/Benchmarks/Dss/Vow/FlapDaiBody.lean index 7686a7e0..551954f0 100644 --- a/Benchmarks/Dss/Vow/FlapDaiBody.lean +++ b/Benchmarks/Dss/Vow/FlapDaiBody.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.FlapBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -225,7 +225,7 @@ theorem flapSourceDai0NoCode have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hbefore htail + have hcat :=.execBlock_append hbefore htail simpa [flapTransition, flapBeforeDaiStmts, flapDai0AndTailStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -313,7 +313,7 @@ theorem flapSourceDai0CallFailure have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hbefore htail + have hcat :=.execBlock_append hbefore htail simpa [flapTransition, flapBeforeDaiStmts, flapDai0AndTailStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -402,7 +402,7 @@ theorem flapSourceDai0DecodeRevert have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hbefore htail + have hcat :=.execBlock_append hbefore htail simpa [flapTransition, flapBeforeDaiStmts, flapDai0AndTailStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat diff --git a/Benchmarks/Dss/Vow/FlapKick.lean b/Benchmarks/Dss/Vow/FlapKick.lean index ddf8dabe..f22cdb2b 100644 --- a/Benchmarks/Dss/Vow/FlapKick.lean +++ b/Benchmarks/Dss/Vow/FlapKick.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.FlapSin1 -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/FlapKickBody.lean b/Benchmarks/Dss/Vow/FlapKickBody.lean index 78dfbb47..ac5d9e26 100644 --- a/Benchmarks/Dss/Vow/FlapKickBody.lean +++ b/Benchmarks/Dss/Vow/FlapKickBody.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.FlapSubBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -331,12 +331,12 @@ theorem vowFlapKickNoCodeBodyCore have htail : ExecBlock config { contract := contract, locals := locals4 } evmDai flapTailStmts .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hpost hkick + have hcat :=.execBlock_append hpost hkick simpa [flapTailStmts] using hcat have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hprefix htail + have hcat :=.execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -450,12 +450,12 @@ theorem flapSourceKickRevert have htail : ExecBlock config { contract := contract, locals := locals4 } evmDai flapTailStmts .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hpost hkick' + have hcat :=.execBlock_append hpost hkick' simpa [flapTailStmts] using hcat have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hprefix htail + have hcat :=.execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat diff --git a/Benchmarks/Dss/Vow/FlapRuntime.lean b/Benchmarks/Dss/Vow/FlapRuntime.lean index dbac8cc6..ab4b0b4a 100644 --- a/Benchmarks/Dss/Vow/FlapRuntime.lean +++ b/Benchmarks/Dss/Vow/FlapRuntime.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Vow.FlapKickBody import Benchmarks.Dss.Vow.FlopBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/FlapSin1.lean b/Benchmarks/Dss/Vow/FlapSin1.lean index eeba1e71..24a55293 100644 --- a/Benchmarks/Dss/Vow/FlapSin1.lean +++ b/Benchmarks/Dss/Vow/FlapSin1.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.FlapDai -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/FlapSin1Body.lean b/Benchmarks/Dss/Vow/FlapSin1Body.lean index 033edf13..2b6cd446 100644 --- a/Benchmarks/Dss/Vow/FlapSin1Body.lean +++ b/Benchmarks/Dss/Vow/FlapSin1Body.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.FlapDaiBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -287,7 +287,7 @@ theorem vowFlapSin1NoCodeBodyCore have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hprefix htail + have hcat :=.execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -385,7 +385,7 @@ theorem vowFlapSin1CallFailureBodyCore have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hprefix htail + have hcat :=.execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -515,7 +515,7 @@ theorem vowFlapSin1DecodeShortBodyCore have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hprefix htail + have hcat :=.execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat diff --git a/Benchmarks/Dss/Vow/FlapSubBody.lean b/Benchmarks/Dss/Vow/FlapSubBody.lean index 96f6dc7d..0c838024 100644 --- a/Benchmarks/Dss/Vow/FlapSubBody.lean +++ b/Benchmarks/Dss/Vow/FlapSubBody.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.FlapSin1Body -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -224,7 +224,7 @@ theorem vowFlapFreeSinUnderflowBodyCore have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hprefix htail + have hcat :=.execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -508,7 +508,7 @@ theorem vowFlapDebtUnderflowBodyCore have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hprefix htail + have hcat :=.execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -825,7 +825,7 @@ theorem vowFlapDebtNotZeroBodyCore have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat := Reasoning.Refinement.execBlock_append hprefix htail + have hcat :=.execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat diff --git a/Benchmarks/Dss/Vow/Flapper.lean b/Benchmarks/Dss/Vow/Flapper.lean index 77d69d6a..649427b3 100644 --- a/Benchmarks/Dss/Vow/Flapper.lean +++ b/Benchmarks/Dss/Vow/Flapper.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Flog.lean b/Benchmarks/Dss/Vow/Flog.lean index bea04185..6b7f0847 100644 --- a/Benchmarks/Dss/Vow/Flog.lean +++ b/Benchmarks/Dss/Vow/Flog.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Arithmetic -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/Flop.lean b/Benchmarks/Dss/Vow/Flop.lean index 58e9e33f..2e96875e 100644 --- a/Benchmarks/Dss/Vow/Flop.lean +++ b/Benchmarks/Dss/Vow/Flop.lean @@ -2,7 +2,7 @@ import Benchmarks.Dss.Vow.HealSuccess import Benchmarks.Dss.Vow.VatDaiCall import Benchmarks.Dss.Vow.VatSinCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/FlopAsh.lean b/Benchmarks/Dss/Vow/FlopAsh.lean index c0942e3f..d8656e8c 100644 --- a/Benchmarks/Dss/Vow/FlopAsh.lean +++ b/Benchmarks/Dss/Vow/FlopAsh.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.FlopDai -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/FlopBody.lean b/Benchmarks/Dss/Vow/FlopBody.lean index e9c084cf..013eedc1 100644 --- a/Benchmarks/Dss/Vow/FlopBody.lean +++ b/Benchmarks/Dss/Vow/FlopBody.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.FlopKick -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/FlopDai.lean b/Benchmarks/Dss/Vow/FlopDai.lean index aba1c4e7..9d950b3c 100644 --- a/Benchmarks/Dss/Vow/FlopDai.lean +++ b/Benchmarks/Dss/Vow/FlopDai.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Flop -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/FlopKick.lean b/Benchmarks/Dss/Vow/FlopKick.lean index 168c7e7f..94e525b1 100644 --- a/Benchmarks/Dss/Vow/FlopKick.lean +++ b/Benchmarks/Dss/Vow/FlopKick.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.FlopAsh -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Flopper.lean b/Benchmarks/Dss/Vow/Flopper.lean index a970f878..161e5ebb 100644 --- a/Benchmarks/Dss/Vow/Flopper.lean +++ b/Benchmarks/Dss/Vow/Flopper.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Heal.lean b/Benchmarks/Dss/Vow/Heal.lean index 40724a6c..ebca67d5 100644 --- a/Benchmarks/Dss/Vow/Heal.lean +++ b/Benchmarks/Dss/Vow/Heal.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Kiss -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/HealBody.lean b/Benchmarks/Dss/Vow/HealBody.lean index fbc83822..96cd4d2b 100644 --- a/Benchmarks/Dss/Vow/HealBody.lean +++ b/Benchmarks/Dss/Vow/HealBody.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.HealFinal -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/HealFinal.lean b/Benchmarks/Dss/Vow/HealFinal.lean index 598ca0c2..21aebaac 100644 --- a/Benchmarks/Dss/Vow/HealFinal.lean +++ b/Benchmarks/Dss/Vow/HealFinal.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.HealSuccess -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/HealSuccess.lean b/Benchmarks/Dss/Vow/HealSuccess.lean index c00953dc..d9f5b91b 100644 --- a/Benchmarks/Dss/Vow/HealSuccess.lean +++ b/Benchmarks/Dss/Vow/HealSuccess.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Vow.Heal import Benchmarks.Dss.Vow.KissSuccess -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/Hump.lean b/Benchmarks/Dss/Vow/Hump.lean index 7b898342..832186b4 100644 --- a/Benchmarks/Dss/Vow/Hump.lean +++ b/Benchmarks/Dss/Vow/Hump.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Kiss.lean b/Benchmarks/Dss/Vow/Kiss.lean index 557b7d42..fb951ec4 100644 --- a/Benchmarks/Dss/Vow/Kiss.lean +++ b/Benchmarks/Dss/Vow/Kiss.lean @@ -1,7 +1,7 @@ import Benchmarks.Dss.Vow.Arithmetic import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/KissSuccess.lean b/Benchmarks/Dss/Vow/KissSuccess.lean index d6d1f290..b194d850 100644 --- a/Benchmarks/Dss/Vow/KissSuccess.lean +++ b/Benchmarks/Dss/Vow/KissSuccess.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Kiss -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/Live.lean b/Benchmarks/Dss/Vow/Live.lean index 141835df..909fa011 100644 --- a/Benchmarks/Dss/Vow/Live.lean +++ b/Benchmarks/Dss/Vow/Live.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Rely.lean b/Benchmarks/Dss/Vow/Rely.lean index d733674a..b3a65e39 100644 --- a/Benchmarks/Dss/Vow/Rely.lean +++ b/Benchmarks/Dss/Vow/Rely.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Deny -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 0 diff --git a/Benchmarks/Dss/Vow/Sin.lean b/Benchmarks/Dss/Vow/Sin.lean index eb11db53..3f827617 100644 --- a/Benchmarks/Dss/Vow/Sin.lean +++ b/Benchmarks/Dss/Vow/Sin.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/SinMapping.lean b/Benchmarks/Dss/Vow/SinMapping.lean index 20ebd1d1..24b9f10d 100644 --- a/Benchmarks/Dss/Vow/SinMapping.lean +++ b/Benchmarks/Dss/Vow/SinMapping.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Sump.lean b/Benchmarks/Dss/Vow/Sump.lean index e59a3455..485abea1 100644 --- a/Benchmarks/Dss/Vow/Sump.lean +++ b/Benchmarks/Dss/Vow/Sump.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Vat.lean b/Benchmarks/Dss/Vow/Vat.lean index 88540b66..71deca03 100644 --- a/Benchmarks/Dss/Vow/Vat.lean +++ b/Benchmarks/Dss/Vow/Vat.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/VatDaiCall.lean b/Benchmarks/Dss/Vow/VatDaiCall.lean index 6f69a353..da91e719 100644 --- a/Benchmarks/Dss/Vow/VatDaiCall.lean +++ b/Benchmarks/Dss/Vow/VatDaiCall.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Kiss -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Vow diff --git a/Benchmarks/Dss/Vow/VatSinCall.lean b/Benchmarks/Dss/Vow/VatSinCall.lean index 1edd23d4..76bdfbad 100644 --- a/Benchmarks/Dss/Vow/VatSinCall.lean +++ b/Benchmarks/Dss/Vow/VatSinCall.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Heal -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace Benchmarks.Dss.Vow diff --git a/Benchmarks/Dss/Vow/Wait.lean b/Benchmarks/Dss/Vow/Wait.lean index ffd5f219..0ddefcd9 100644 --- a/Benchmarks/Dss/Vow/Wait.lean +++ b/Benchmarks/Dss/Vow/Wait.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/Dss/Vow/Wards.lean b/Benchmarks/Dss/Vow/Wards.lean index 2f7314af..f9166af6 100644 --- a/Benchmarks/Dss/Vow/Wards.lean +++ b/Benchmarks/Dss/Vow/Wards.lean @@ -1,6 +1,6 @@ import Benchmarks.Dss.Vow.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/ERC721/Correct.lean b/Benchmarks/ERC721/Correct.lean index 2079f160..c3d3de2f 100644 --- a/Benchmarks/ERC721/Correct.lean +++ b/Benchmarks/ERC721/Correct.lean @@ -7,7 +7,6 @@ import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -45,7 +44,7 @@ Dispatch structure (read off the bytecode): | `0xe985e9c5` | `isApprovedForAll(address,address)` | `356` (0x164) | high | -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/AbiDecode.lean b/Benchmarks/OpenZeppelinBench/TimelockController/AbiDecode.lean index 7b0ef3fa..7f8f96db 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/AbiDecode.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/AbiDecode.lean @@ -13,7 +13,7 @@ Reusable `tlcAbiDec…` lemmas: the finite `decodeABIValues?` unfold for a head- single dynamic `bytes` member, with the offset/maxEnd bookkeeping done explicitly. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1600000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/AbiEncode.lean b/Benchmarks/OpenZeppelinBench/TimelockController/AbiEncode.lean index f11821ae..1cc14747 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/AbiEncode.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/AbiEncode.lean @@ -11,7 +11,7 @@ LIBRARY CANDIDATEs: the `tlcAbiEnc…` lemmas below generalize to any solc tuple dynamic `bytes` member and a `0xa0` head offset. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Body.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Body.lean index df94178e..b473e972 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Body.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Body.lean @@ -15,7 +15,7 @@ through `config.externalABI.encode? = timelockExternalABI.encode? and that encode is exactly `tlcAbiEncHashOperation` (green, in `AbiEncode.lean`). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1600000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Cancel.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Cancel.lean index bae96f0b..d2bd2f79 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Cancel.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Cancel.lean @@ -23,7 +23,7 @@ The delete `.delete (timestampRef id)` clears the `uint256` slot to `0` (`clearS `.elem` leaf), coupling to the EVM `SSTORE 0` via `accountMapEquiv_sstoreAccountMap`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/CancellerRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/CancellerRole.lean index 3ae42232..b113943d 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/CancellerRole.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/CancellerRole.lean @@ -11,7 +11,7 @@ G147 arm 2, body pc 1151). It returns `keccak256("CANCELLER_ROLE")`. Copied fr `PROPOSER_ROLE` template. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Common.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Common.lean index db6bd1e6..f599eb87 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Common.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Common.lean @@ -7,7 +7,6 @@ import Reasoning.Solc import Reasoning.Memory import Reasoning.Storage import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -20,7 +19,7 @@ binary search over 28 selectors, so the selector machinery mirrors the fully-pro (same compiler family, `RD.selectorSplit*Auto` + `RD.dispatchTo`). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorDefs.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorDefs.lean index 541f3d75..ddb96b88 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorDefs.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorDefs.lean @@ -17,7 +17,7 @@ The `tlcCtorGrantMap` operator captures that single step uniformly on `AccountMa Solm sides reach a tower of these, so reconciliation just threads `accountMapEquiv` through it. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorEvm.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorEvm.lean index a2a4d825..05e6d821 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorEvm.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorEvm.lean @@ -8,7 +8,7 @@ the five conditional `_grantRole` writes and `_minDelay = 86400` — i.e. the ac `tlcCtorFinalMap I σ`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorSolm.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorSolm.lean index adb50890..b2400963 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorSolm.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorSolm.lean @@ -8,7 +8,7 @@ guarded admin grant, and `_minDelay = 86400`) runs to a returned state whose acc `tlcCtorFinalMap I σ` and whose created accounts are unchanged. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Correct.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Correct.lean index e714a11f..45248570 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Correct.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Correct.lean @@ -39,7 +39,7 @@ calldata < 4 routes to the payable `receive` (empty calldata) or reverts (1–3 shared callvalue guard — each non-payable function guards its own callvalue. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/DefaultAdminRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/DefaultAdminRole.lean index 5dec3652..40441b08 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/DefaultAdminRole.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/DefaultAdminRole.lean @@ -11,7 +11,7 @@ group G147 arm 1, body pc 1132). It returns `bytes32(0)`, which the optimized r `PUSH0` (not `PUSH32`). Copied from the `PROPOSER_ROLE` template. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Dispatch.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Dispatch.lean index 85e4c0d9..271a7530 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Dispatch.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Dispatch.lean @@ -32,7 +32,7 @@ Leaf arm groups (arm order = bytecode order): * G397 @398 : schedule@445, supportsInterface@478, EXECUTOR_ROLE@530 -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/EvmExec.lean b/Benchmarks/OpenZeppelinBench/TimelockController/EvmExec.lean index e6f85a31..dd4bfb09 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/EvmExec.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/EvmExec.lean @@ -11,7 +11,7 @@ import Benchmarks.OpenZeppelinBench.TimelockController.Return `= keccak256(tlcHashOpCanonBytes I)`, the same preimage as the Solm side. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/EvmReach.lean b/Benchmarks/OpenZeppelinBench/TimelockController/EvmReach.lean index 0e2955ac..20f56b89 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/EvmReach.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/EvmReach.lean @@ -8,7 +8,7 @@ Reach the `hashOperation` body (pc 988, G194 arm 0) and set up the external 5-ar (pc 4600). Shared by the execute-path (`EvmExec`) and revert-path (`EvmReverts`) proofs. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/EvmReverts.lean b/Benchmarks/OpenZeppelinBench/TimelockController/EvmReverts.lean index 0bde41a5..16566e80 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/EvmReverts.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/EvmReverts.lean @@ -11,7 +11,7 @@ bytes-offset > 2^64 / bytes length-or-payload OOB) and the Solm `decodeCalldata` (the `tlcDecodeHashOperation_none_*` lemmas), routed through `tlcReEquivDecodeFailed`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Execute.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Execute.lean index 7179e596..a9f6d2df 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Execute.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Execute.lean @@ -2,7 +2,7 @@ import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch import Benchmarks.OpenZeppelinBench.TimelockController.Routines -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ExecuteBatch.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ExecuteBatch.lean index c6edea19..75a3610d 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ExecuteBatch.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/ExecuteBatch.lean @@ -2,7 +2,7 @@ import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch import Benchmarks.OpenZeppelinBench.TimelockController.Routines -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ExecutorRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ExecutorRole.lean index b0d93849..9e33380e 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ExecutorRole.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/ExecutorRole.lean @@ -11,7 +11,7 @@ G397 arm 2, body pc 530). It returns `keccak256("EXECUTOR_ROLE")`. Copied from template. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Fallback.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Fallback.lean index 7fbfe616..8736a314 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Fallback.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Fallback.lean @@ -13,7 +13,7 @@ import Benchmarks.OpenZeppelinBench.TimelockController.Routines `dispatchMsg = none` → `noDispatch`). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/GetMinDelay.lean b/Benchmarks/OpenZeppelinBench/TimelockController/GetMinDelay.lean index 09f5be66..966a2e27 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/GetMinDelay.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/GetMinDelay.lean @@ -8,7 +8,7 @@ import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch Selector index 6, dispatch group G51 arm 3, body pc 1443. Template for fixed-slot word getters. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/GetOperationState.lean b/Benchmarks/OpenZeppelinBench/TimelockController/GetOperationState.lean index 355b52dc..08233c00 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/GetOperationState.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/GetOperationState.lean @@ -18,7 +18,7 @@ leaf traversal @2232 reuse `GetTimestamp`/`Storage`/`IsOperation` infrastructure dirtied scratch memory (`twoWordHashMem …`) via `Storage.tlcRetMem*`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/GetRoleAdmin.lean b/Benchmarks/OpenZeppelinBench/TimelockController/GetRoleAdmin.lean index 5c6fa4f2..b2b27d86 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/GetRoleAdmin.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/GetRoleAdmin.lean @@ -14,7 +14,7 @@ word. Template for arg-taking struct-field `bytes32` mapping getters (cf. `GetT base-slot-`1` `uint256` analogue). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/GetTimestamp.lean b/Benchmarks/OpenZeppelinBench/TimelockController/GetTimestamp.lean index 73165add..78b8be94 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/GetTimestamp.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/GetTimestamp.lean @@ -11,7 +11,7 @@ The runtime peels its own non-payable guard, runs the modern word-argument decod it, and returns the 32-byte word. Template for arg-taking `uint256` mapping getters. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/GrantRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/GrantRole.lean index 39505ab6..3d90960e 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/GrantRole.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/GrantRole.lean @@ -19,7 +19,7 @@ The admin read, onlyRole nested-slot load, error-scratch, decoded store, and `le evaluations are identical to `revokeRole` and are imported from `RevokeRole.lean`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/HasRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/HasRole.lean index b00cc325..81d0814d 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/HasRole.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/HasRole.lean @@ -15,7 +15,7 @@ it, masks the low byte, and returns the `iszero(iszero(word & 0xff))`-normalized Template for nested-mapping `bool` getters (grantRole/revokeRole read the same slot). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/HashOperation.lean b/Benchmarks/OpenZeppelinBench/TimelockController/HashOperation.lean index d00a8c1f..b01a9f38 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/HashOperation.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/HashOperation.lean @@ -6,7 +6,7 @@ import Benchmarks.OpenZeppelinBench.TimelockController.EvmReach import Benchmarks.OpenZeppelinBench.TimelockController.EvmExec import Benchmarks.OpenZeppelinBench.TimelockController.EvmReverts -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/HashOperationBatch.lean b/Benchmarks/OpenZeppelinBench/TimelockController/HashOperationBatch.lean index c6f4668a..bb243f5a 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/HashOperationBatch.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/HashOperationBatch.lean @@ -2,7 +2,7 @@ import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch import Benchmarks.OpenZeppelinBench.TimelockController.Routines -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperation.lean b/Benchmarks/OpenZeppelinBench/TimelockController/IsOperation.lean index 01277702..31dd76c8 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperation.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/IsOperation.lean @@ -20,7 +20,7 @@ infrastructure; the bool return encoder @509 mirrors `SupportsInterface`, genera scratch memory (`twoWordHashMem …`) via `Storage.tlcRetMem*`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationDone.lean b/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationDone.lean index 4b2c1f74..234ea23e 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationDone.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationDone.lean @@ -18,7 +18,7 @@ mapping keccak) and the memory-generic bool-return encoder @509 (`tlcIsOperation imported unchanged. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationPending.lean b/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationPending.lean index aebfb3d0..fe25431e 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationPending.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationPending.lean @@ -19,7 +19,7 @@ The front half (guard peel, decoder, mapping keccak), the four helper leaves, an bool-return encoder @509 (`tlcIsOperationReturnBool`) are imported unchanged. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationReady.lean b/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationReady.lean index 3573618f..88531257 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationReady.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationReady.lean @@ -19,7 +19,7 @@ JUMPDEST @1882, so the post-helper `EQ` tests `state == 2`; (c) the Solm side is mapping keccak), the four helper leaves, and the bool-return encoder @509 are imported unchanged. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155BatchReceived.lean b/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155BatchReceived.lean index bbc3b509..2624eefb 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155BatchReceived.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155BatchReceived.lean @@ -2,7 +2,7 @@ import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch import Benchmarks.OpenZeppelinBench.TimelockController.Routines -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155Received.lean b/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155Received.lean index 1081b68b..329248f4 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155Received.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155Received.lean @@ -2,7 +2,7 @@ import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch import Benchmarks.OpenZeppelinBench.TimelockController.Routines -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/OnERC721Received.lean b/Benchmarks/OpenZeppelinBench/TimelockController/OnERC721Received.lean index 753424d4..2cc651ab 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/OnERC721Received.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/OnERC721Received.lean @@ -2,7 +2,7 @@ import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch import Benchmarks.OpenZeppelinBench.TimelockController.Routines -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ProposerRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ProposerRole.lean index df2b8792..3917c2af 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ProposerRole.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/ProposerRole.lean @@ -9,7 +9,7 @@ G194 arm 2, body pc 1050). It returns `keccak256("PROPOSER_ROLE")`. Template f role-constant getters. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Receivers.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Receivers.lean index 5dadf6ae..12507cf7 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Receivers.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Receivers.lean @@ -24,7 +24,7 @@ already-active memory, so both have zero memory-expansion cost. `tlcRecvReturnB over an abstract `(mem, P, aw)`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/RenounceRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/RenounceRole.lean index 938f1c59..7839a213 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/RenounceRole.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/RenounceRole.lean @@ -21,7 +21,7 @@ EVM `SSTORE` of `land word (lnot 0xff)` via `storageLocStore_bool_false_offset0` a no-op matching the EVM jump-around at `@4089`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Return.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Return.lean index b117d1f9..1e30a8ab 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Return.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Return.lean @@ -10,7 +10,7 @@ getter. (The library's single-block `RD.solcReturnWordFromMem` does not match t LIBRARY CANDIDATE: `Reasoning.Solc` — split-encoder analogue of `RD.solcReturnWordFromMem`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/RevokeRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/RevokeRole.lean index 3797f873..7cdeaaa2 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/RevokeRole.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/RevokeRole.lean @@ -20,7 +20,7 @@ The admin read dirties the keccak scratch, so the two `@2762` nested-slot loads memory-generic form of `HasRole.tlcHasRoleSlotLoad` used for both. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Routines.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Routines.lean index 6c414274..f8aab9df 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Routines.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Routines.lean @@ -16,7 +16,7 @@ The guard-peel lemmas are the per-function analogues of the library's `solcGuard Adapted from the fully-proved sibling `Benchmarks/WETH9/Routines.lean` (same payable-dispatch shape). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Schedule.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Schedule.lean index f6be9dd9..0d88cbd9 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Schedule.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Schedule.lean @@ -2,7 +2,7 @@ import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch import Benchmarks.OpenZeppelinBench.TimelockController.Routines -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ScheduleBatch.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ScheduleBatch.lean index 91e9a604..8fe5e5c4 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ScheduleBatch.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/ScheduleBatch.lean @@ -2,7 +2,7 @@ import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch import Benchmarks.OpenZeppelinBench.TimelockController.Routines -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ScratchGrant.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ScratchGrant.lean index ccfb37c0..7af99bee 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ScratchGrant.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/ScratchGrant.lean @@ -1,5 +1,5 @@ import Benchmarks.OpenZeppelinBench.TimelockController.ConstructorEvm -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 namespace OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/SolmDispatch.lean b/Benchmarks/OpenZeppelinBench/TimelockController/SolmDispatch.lean index 8f8ef33b..b4c4cc46 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/SolmDispatch.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/SolmDispatch.lean @@ -9,7 +9,7 @@ consumed by the per-function refinement bridges in `Routines.lean` (TimelockCont `selectorDispatchMsg` directly). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Storage.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Storage.lean index 00ee6c84..4e3ca540 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Storage.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Storage.lean @@ -17,7 +17,7 @@ LIBRARY CANDIDATEs: `Reasoning.Solc` — `tlcMappingGetSlot1` generalizes the ba `tlcReturnWordFromMem` is the memory-generic form of the split return encoder. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/SupportsInterface.lean b/Benchmarks/OpenZeppelinBench/TimelockController/SupportsInterface.lean index 96b104fa..4b55d95b 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/SupportsInterface.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/SupportsInterface.lean @@ -17,7 +17,7 @@ The `bytes4` word/mask coupling lemmas below are adapted from the proven codegen; only the constant set and the extra `IERC1155Receiver` arm differ). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/UpdateDelay.lean b/Benchmarks/OpenZeppelinBench/TimelockController/UpdateDelay.lean index 268d634b..4cf8079f 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/UpdateDelay.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/UpdateDelay.lean @@ -17,7 +17,7 @@ carrying a single `sstoreAccountMap`, coupled to the Solm `.assign .storage` bod `accountMapEquiv_sstoreAccountMap`; the void return is `returnEquiv.fallthrough`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/UniswapV3Pool/Burn.lean b/Benchmarks/UniswapV3Pool/Burn.lean index 4fe62555..716cd4b8 100644 --- a/Benchmarks/UniswapV3Pool/Burn.lean +++ b/Benchmarks/UniswapV3Pool/Burn.lean @@ -5,7 +5,7 @@ import Benchmarks.UniswapV3Pool.TicksInt128 import Benchmarks.UniswapV3Pool.Uint128 open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnAfterCheckTicks.lean b/Benchmarks/UniswapV3Pool/BurnAfterCheckTicks.lean index 51983865..bee44251 100644 --- a/Benchmarks/UniswapV3Pool/BurnAfterCheckTicks.lean +++ b/Benchmarks/UniswapV3Pool/BurnAfterCheckTicks.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.BurnCheckTicks import Benchmarks.UniswapV3Pool.InitializeGetTickLogCombine open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnAfterFeeGlobals.lean b/Benchmarks/UniswapV3Pool/BurnAfterFeeGlobals.lean index 5515c8c7..8681b975 100644 --- a/Benchmarks/UniswapV3Pool/BurnAfterFeeGlobals.lean +++ b/Benchmarks/UniswapV3Pool/BurnAfterFeeGlobals.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnAfterCheckTicks open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnAfterFeeGrowthInside.lean b/Benchmarks/UniswapV3Pool/BurnAfterFeeGrowthInside.lean index dae64b86..2ae5177d 100644 --- a/Benchmarks/UniswapV3Pool/BurnAfterFeeGrowthInside.lean +++ b/Benchmarks/UniswapV3Pool/BurnAfterFeeGrowthInside.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnAfterFeeGlobals open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnBody.lean b/Benchmarks/UniswapV3Pool/BurnBody.lean index 8706b341..517fbecb 100644 --- a/Benchmarks/UniswapV3Pool/BurnBody.lean +++ b/Benchmarks/UniswapV3Pool/BurnBody.lean @@ -5,7 +5,7 @@ import Benchmarks.UniswapV3Pool.BurnZeroDeltaSlowToken0 import Benchmarks.UniswapV3Pool.BurnLowerLiquidityAddDeltaRevert open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnCheckTicks.lean b/Benchmarks/UniswapV3Pool/BurnCheckTicks.lean index 1e8eb306..1e81e5be 100644 --- a/Benchmarks/UniswapV3Pool/BurnCheckTicks.lean +++ b/Benchmarks/UniswapV3Pool/BurnCheckTicks.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnNoDelegate open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnFullMathSlow.lean b/Benchmarks/UniswapV3Pool/BurnFullMathSlow.lean index 644fcbfa..1b7176bb 100644 --- a/Benchmarks/UniswapV3Pool/BurnFullMathSlow.lean +++ b/Benchmarks/UniswapV3Pool/BurnFullMathSlow.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdate open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Reasoning.Theory diff --git a/Benchmarks/UniswapV3Pool/BurnLowerLiquidityAddDeltaRevert.lean b/Benchmarks/UniswapV3Pool/BurnLowerLiquidityAddDeltaRevert.lean index d90dcb19..ec47916b 100644 --- a/Benchmarks/UniswapV3Pool/BurnLowerLiquidityAddDeltaRevert.lean +++ b/Benchmarks/UniswapV3Pool/BurnLowerLiquidityAddDeltaRevert.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnTickUpdateTrace open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnNoDelegate.lean b/Benchmarks/UniswapV3Pool/BurnNoDelegate.lean index 9e72992f..e449a969 100644 --- a/Benchmarks/UniswapV3Pool/BurnNoDelegate.lean +++ b/Benchmarks/UniswapV3Pool/BurnNoDelegate.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Burn open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnNonzeroDeltaStart.lean b/Benchmarks/UniswapV3Pool/BurnNonzeroDeltaStart.lean index 5ae640d9..bec6c848 100644 --- a/Benchmarks/UniswapV3Pool/BurnNonzeroDeltaStart.lean +++ b/Benchmarks/UniswapV3Pool/BurnNonzeroDeltaStart.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdate open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnObserveSingle.lean b/Benchmarks/UniswapV3Pool/BurnObserveSingle.lean index c58f7d71..6a791691 100644 --- a/Benchmarks/UniswapV3Pool/BurnObserveSingle.lean +++ b/Benchmarks/UniswapV3Pool/BurnObserveSingle.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.Observations import Benchmarks.UniswapV3Pool.BurnNonzeroDeltaStart open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdate.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdate.lean index a9baff3d..a8c2fb85 100644 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdate.lean +++ b/Benchmarks/UniswapV3Pool/BurnPositionUpdate.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnAfterFeeGrowthInside open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Reasoning.Theory diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateMemory.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateMemory.lean index d2e727fa..8fdafcbf 100644 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateMemory.lean +++ b/Benchmarks/UniswapV3Pool/BurnPositionUpdateMemory.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdate open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdatePostReturn.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdatePostReturn.lean index 2f1ede40..d72a410f 100644 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdatePostReturn.lean +++ b/Benchmarks/UniswapV3Pool/BurnPositionUpdatePostReturn.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdateMemory import Benchmarks.UniswapV3Pool.BurnFullMathSlow open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateRevert.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateRevert.lean index e85a1373..8f814889 100644 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateRevert.lean +++ b/Benchmarks/UniswapV3Pool/BurnPositionUpdateRevert.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdate open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateSlowPostReturn.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateSlowPostReturn.lean index 2048d46b..88c4a81a 100644 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateSlowPostReturn.lean +++ b/Benchmarks/UniswapV3Pool/BurnPositionUpdateSlowPostReturn.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdatePostReturn open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateSource.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateSource.lean index 6f1c3b8e..3219e08e 100644 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateSource.lean +++ b/Benchmarks/UniswapV3Pool/BurnPositionUpdateSource.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdateRevert open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateSourceSuccess.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateSourceSuccess.lean index 38f9222d..6c7b17f1 100644 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateSourceSuccess.lean +++ b/Benchmarks/UniswapV3Pool/BurnPositionUpdateSourceSuccess.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdateSource open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedBridge.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedBridge.lean index 094c58e9..15a5a471 100644 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedBridge.lean +++ b/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedBridge.lean @@ -3,7 +3,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdateTokensOwedStore import Benchmarks.UniswapV3Pool.BurnPositionUpdateSlowPostReturn open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedPacking.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedPacking.lean index 1e568a03..9aba845a 100644 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedPacking.lean +++ b/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedPacking.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdateSourceSuccess import Benchmarks.UniswapV3Pool.BurnPositionUpdatePostReturn open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedStore.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedStore.lean index d2812297..786d7fc2 100644 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedStore.lean +++ b/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedStore.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdatePostReturn open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPostPositionUpdate.lean b/Benchmarks/UniswapV3Pool/BurnPostPositionUpdate.lean index 1bdca010..7bcfcfae 100644 --- a/Benchmarks/UniswapV3Pool/BurnPostPositionUpdate.lean +++ b/Benchmarks/UniswapV3Pool/BurnPostPositionUpdate.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdateTokensOwedBridge open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnSourceSuccess.lean b/Benchmarks/UniswapV3Pool/BurnSourceSuccess.lean index 53229b69..c0a1885e 100644 --- a/Benchmarks/UniswapV3Pool/BurnSourceSuccess.lean +++ b/Benchmarks/UniswapV3Pool/BurnSourceSuccess.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.BurnTickGetFeeGrowthInsideSource import Benchmarks.UniswapV3Pool.BurnPostPositionUpdate open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnTickGetFeeGrowthInsideSource.lean b/Benchmarks/UniswapV3Pool/BurnTickGetFeeGrowthInsideSource.lean index f7feb4db..afe71879 100644 --- a/Benchmarks/UniswapV3Pool/BurnTickGetFeeGrowthInsideSource.lean +++ b/Benchmarks/UniswapV3Pool/BurnTickGetFeeGrowthInsideSource.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdateSourceSuccess open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnTickUpdateSource.lean b/Benchmarks/UniswapV3Pool/BurnTickUpdateSource.lean index ac148fe2..2b382775 100644 --- a/Benchmarks/UniswapV3Pool/BurnTickUpdateSource.lean +++ b/Benchmarks/UniswapV3Pool/BurnTickUpdateSource.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.BurnTickUpdateStart import Benchmarks.UniswapV3Pool.BurnLiquidityAddDelta open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnTickUpdateStart.lean b/Benchmarks/UniswapV3Pool/BurnTickUpdateStart.lean index 152f70e0..84d9fc71 100644 --- a/Benchmarks/UniswapV3Pool/BurnTickUpdateStart.lean +++ b/Benchmarks/UniswapV3Pool/BurnTickUpdateStart.lean @@ -4,7 +4,7 @@ import Benchmarks.UniswapV3Pool.InitializeGetTickLog import Benchmarks.UniswapV3Pool.SetFeeProtocolOwnerCall open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnTickUpdateTrace.lean b/Benchmarks/UniswapV3Pool/BurnTickUpdateTrace.lean index e30a470d..a048ab7b 100644 --- a/Benchmarks/UniswapV3Pool/BurnTickUpdateTrace.lean +++ b/Benchmarks/UniswapV3Pool/BurnTickUpdateTrace.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnTickUpdateSource open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnZeroDeltaFinish.lean b/Benchmarks/UniswapV3Pool/BurnZeroDeltaFinish.lean index c15cf87e..52eff89a 100644 --- a/Benchmarks/UniswapV3Pool/BurnZeroDeltaFinish.lean +++ b/Benchmarks/UniswapV3Pool/BurnZeroDeltaFinish.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.BurnSourceSuccess import Benchmarks.UniswapV3Pool.BurnPositionUpdateTokensOwedBridge open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnZeroDeltaMulDivStart.lean b/Benchmarks/UniswapV3Pool/BurnZeroDeltaMulDivStart.lean index fcb4531d..4d8e0b2f 100644 --- a/Benchmarks/UniswapV3Pool/BurnZeroDeltaMulDivStart.lean +++ b/Benchmarks/UniswapV3Pool/BurnZeroDeltaMulDivStart.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.BurnPositionUpdateTokensOwedBridge open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnZeroDeltaSlowToken0.lean b/Benchmarks/UniswapV3Pool/BurnZeroDeltaSlowToken0.lean index e218c030..f8120ed7 100644 --- a/Benchmarks/UniswapV3Pool/BurnZeroDeltaSlowToken0.lean +++ b/Benchmarks/UniswapV3Pool/BurnZeroDeltaSlowToken0.lean @@ -3,7 +3,7 @@ import Benchmarks.UniswapV3Pool.BurnZeroDeltaFinish import Benchmarks.UniswapV3Pool.BurnPositionUpdateSlowPostReturn open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Common.lean b/Benchmarks/UniswapV3Pool/Common.lean index bd5f197d..bfe7bb8f 100644 --- a/Benchmarks/UniswapV3Pool/Common.lean +++ b/Benchmarks/UniswapV3Pool/Common.lean @@ -5,7 +5,6 @@ import Reasoning.Initcode import Reasoning.JumpDest import Reasoning.Memory import Reasoning.Reach -import Reasoning.Refinement import Reasoning.Solc import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -17,7 +16,7 @@ Contract-wide selector, dispatch, and revert facts used by the top-level runtime per-function body proofs. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach open Benchmarks.UniswapV3Pool.Immutables set_option maxRecDepth 2000000 diff --git a/Benchmarks/UniswapV3Pool/Factory.lean b/Benchmarks/UniswapV3Pool/Factory.lean index 09067d00..ff7a6ac9 100644 --- a/Benchmarks/UniswapV3Pool/Factory.lean +++ b/Benchmarks/UniswapV3Pool/Factory.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.ImmutableGetters open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Fee.lean b/Benchmarks/UniswapV3Pool/Fee.lean index 71fdaa2e..e3cddd0e 100644 --- a/Benchmarks/UniswapV3Pool/Fee.lean +++ b/Benchmarks/UniswapV3Pool/Fee.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Common open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/FeeGrowthGlobal0X128.lean b/Benchmarks/UniswapV3Pool/FeeGrowthGlobal0X128.lean index d966d23b..04abb0e7 100644 --- a/Benchmarks/UniswapV3Pool/FeeGrowthGlobal0X128.lean +++ b/Benchmarks/UniswapV3Pool/FeeGrowthGlobal0X128.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Common open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/FeeGrowthGlobal1X128.lean b/Benchmarks/UniswapV3Pool/FeeGrowthGlobal1X128.lean index 8c2d7691..02c1b511 100644 --- a/Benchmarks/UniswapV3Pool/FeeGrowthGlobal1X128.lean +++ b/Benchmarks/UniswapV3Pool/FeeGrowthGlobal1X128.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Common open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/ImmutableGetters.lean b/Benchmarks/UniswapV3Pool/ImmutableGetters.lean index 8491dc36..62e0ec22 100644 --- a/Benchmarks/UniswapV3Pool/ImmutableGetters.lean +++ b/Benchmarks/UniswapV3Pool/ImmutableGetters.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Common open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNext.lean b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNext.lean index b9fdda49..ec499bc5 100644 --- a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNext.lean +++ b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNext.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.IncreaseObservationCardinalityNextGrowLoop open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextBase.lean b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextBase.lean index 39157ba2..622eaa61 100644 --- a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextBase.lean +++ b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextBase.lean @@ -3,7 +3,7 @@ import Benchmarks.UniswapV3Pool.Locking import Benchmarks.UniswapV3Pool.NoDelegateCall open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrow.lean b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrow.lean index 2b28f1d4..51fa3f29 100644 --- a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrow.lean +++ b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrow.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.IncreaseObservationCardinalityNextBase open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowLoop.lean b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowLoop.lean index de95c172..99ec1564 100644 --- a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowLoop.lean +++ b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowLoop.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.IncreaseObservationCardinalityNextGrowTail open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowTail.lean b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowTail.lean index 2b399333..7f56f1d2 100644 --- a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowTail.lean +++ b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowTail.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.IncreaseObservationCardinalityNextGrow open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Initialize.lean b/Benchmarks/UniswapV3Pool/Initialize.lean index 38ebaf0e..21ae24a3 100644 --- a/Benchmarks/UniswapV3Pool/Initialize.lean +++ b/Benchmarks/UniswapV3Pool/Initialize.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatioSourceBridge import Benchmarks.UniswapV3Pool.InitializeSourceStorageEquiv open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeBase.lean b/Benchmarks/UniswapV3Pool/InitializeBase.lean index 8a8a6953..a50232dd 100644 --- a/Benchmarks/UniswapV3Pool/InitializeBase.lean +++ b/Benchmarks/UniswapV3Pool/InitializeBase.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.SetFeeProtocolOwnerCall import Benchmarks.UniswapV3Pool.Slot0 open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTick.lean b/Benchmarks/UniswapV3Pool/InitializeGetTick.lean index 837318e6..8a6278c2 100644 --- a/Benchmarks/UniswapV3Pool/InitializeGetTick.lean +++ b/Benchmarks/UniswapV3Pool/InitializeGetTick.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeBase open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickLog.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickLog.lean index 7dd65414..19ffed63 100644 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickLog.lean +++ b/Benchmarks/UniswapV3Pool/InitializeGetTickLog.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeGetTick open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickLog2Bridge.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickLog2Bridge.lean index 0f689159..39a42b5c 100644 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickLog2Bridge.lean +++ b/Benchmarks/UniswapV3Pool/InitializeGetTickLog2Bridge.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeGetTickWordBridge open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickLogCombine.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickLogCombine.lean index 85bc0e22..5b84451c 100644 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickLogCombine.lean +++ b/Benchmarks/UniswapV3Pool/InitializeGetTickLogCombine.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeGetTickLog open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickReturn.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickReturn.lean index e16a99b4..aa7ff2fd 100644 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickReturn.lean +++ b/Benchmarks/UniswapV3Pool/InitializeGetTickReturn.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeGetTickLogCombine open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatio.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatio.lean index 803a7cd8..0fc07ac2 100644 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatio.lean +++ b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatio.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeGetTickReturn open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBits.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBits.lean index f1fa2271..3b3f7df2 100644 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBits.lean +++ b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBits.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatio open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBitsHigh.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBitsHigh.lean index 1c402386..5d2e401f 100644 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBitsHigh.lean +++ b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBitsHigh.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatioBits open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioFull.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioFull.lean index ed278dd2..267912d4 100644 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioFull.lean +++ b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioFull.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatioReturn open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioNonzero.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioNonzero.lean index 3c593c69..c41ab61a 100644 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioNonzero.lean +++ b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioNonzero.lean @@ -4,7 +4,7 @@ import Benchmarks.UniswapV3Pool.InitializeSourceStorageEquiv import Benchmarks.UniswapV3Pool.TickSpacing open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioReturn.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioReturn.lean index 7817be7c..8a3b3bd2 100644 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioReturn.lean +++ b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioReturn.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatioBitsHigh open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioSourceBridge.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioSourceBridge.lean index 4937ba69..0b4c20ea 100644 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioSourceBridge.lean +++ b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioSourceBridge.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatioNonzero open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickWordBridge.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickWordBridge.lean index 36ff6d2b..123aee2e 100644 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickWordBridge.lean +++ b/Benchmarks/UniswapV3Pool/InitializeGetTickWordBridge.lean @@ -3,7 +3,7 @@ import Benchmarks.UniswapV3Pool.InitializeSourceGetTickPostLog import Benchmarks.UniswapV3Pool.TickSpacing open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatio.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatio.lean index fdbf8994..c5bc172d 100644 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatio.lean +++ b/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatio.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeSourceGetTickPostLog open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioHighBits.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioHighBits.lean index e65c7939..62531f05 100644 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioHighBits.lean +++ b/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioHighBits.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeSourceGetSqrtRatioLowBits open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioLowBits.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioLowBits.lean index a9a09583..f4d4e3fb 100644 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioLowBits.lean +++ b/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioLowBits.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeSourceGetSqrtRatio open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLog.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLog.lean index 813bfe6f..0f3ae40c 100644 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLog.lean +++ b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLog.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeSourceGetTickMsb open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogRemaining.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogRemaining.lean index 825b1b5d..c01a3f1b 100644 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogRemaining.lean +++ b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogRemaining.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeSourceGetTickLogStep60 open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep60.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep60.lean index 815cb50d..d516e953 100644 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep60.lean +++ b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep60.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeSourceGetTickLogStep61 open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep61.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep61.lean index b4beabfd..05833482 100644 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep61.lean +++ b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep61.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeSourceGetTickLogStep62 open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep62.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep62.lean index 5c613277..8505b044 100644 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep62.lean +++ b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep62.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeSourceGetTickLog open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickMsb.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickMsb.lean index 622836f0..348598c6 100644 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickMsb.lean +++ b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickMsb.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeSourceSuccess open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickPostLog.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickPostLog.lean index 1f57408f..de6c41ed 100644 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickPostLog.lean +++ b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickPostLog.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeSourceGetTickLogRemaining open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceStorageEquiv.lean b/Benchmarks/UniswapV3Pool/InitializeSourceStorageEquiv.lean index f25244fb..ad7e9226 100644 --- a/Benchmarks/UniswapV3Pool/InitializeSourceStorageEquiv.lean +++ b/Benchmarks/UniswapV3Pool/InitializeSourceStorageEquiv.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeSourceSuccess open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceSuccess.lean b/Benchmarks/UniswapV3Pool/InitializeSourceSuccess.lean index b617e4c5..8bee49bc 100644 --- a/Benchmarks/UniswapV3Pool/InitializeSourceSuccess.lean +++ b/Benchmarks/UniswapV3Pool/InitializeSourceSuccess.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeSuccess open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSuccess.lean b/Benchmarks/UniswapV3Pool/InitializeSuccess.lean index dace54ff..a61814cb 100644 --- a/Benchmarks/UniswapV3Pool/InitializeSuccess.lean +++ b/Benchmarks/UniswapV3Pool/InitializeSuccess.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatioFull open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Liquidity.lean b/Benchmarks/UniswapV3Pool/Liquidity.lean index f70f9f1d..afd7ad14 100644 --- a/Benchmarks/UniswapV3Pool/Liquidity.lean +++ b/Benchmarks/UniswapV3Pool/Liquidity.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Uint128 open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Locking.lean b/Benchmarks/UniswapV3Pool/Locking.lean index 237affac..57ed4b76 100644 --- a/Benchmarks/UniswapV3Pool/Locking.lean +++ b/Benchmarks/UniswapV3Pool/Locking.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Slot0 open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/MaxLiquidityPerTick.lean b/Benchmarks/UniswapV3Pool/MaxLiquidityPerTick.lean index f82e8455..dc291704 100644 --- a/Benchmarks/UniswapV3Pool/MaxLiquidityPerTick.lean +++ b/Benchmarks/UniswapV3Pool/MaxLiquidityPerTick.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Liquidity open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/NoDelegateCall.lean b/Benchmarks/UniswapV3Pool/NoDelegateCall.lean index 77fa89cb..0c35f960 100644 --- a/Benchmarks/UniswapV3Pool/NoDelegateCall.lean +++ b/Benchmarks/UniswapV3Pool/NoDelegateCall.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Common open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Observations.lean b/Benchmarks/UniswapV3Pool/Observations.lean index 4e454580..70d538fc 100644 --- a/Benchmarks/UniswapV3Pool/Observations.lean +++ b/Benchmarks/UniswapV3Pool/Observations.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.ObservationsInt56 import Reasoning.MemCascade open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/ObservationsInt56.lean b/Benchmarks/UniswapV3Pool/ObservationsInt56.lean index 5d9cb38a..54266207 100644 --- a/Benchmarks/UniswapV3Pool/ObservationsInt56.lean +++ b/Benchmarks/UniswapV3Pool/ObservationsInt56.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Slot0 open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Positions.lean b/Benchmarks/UniswapV3Pool/Positions.lean index b01817ae..4a6277e4 100644 --- a/Benchmarks/UniswapV3Pool/Positions.lean +++ b/Benchmarks/UniswapV3Pool/Positions.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.Uint128 import Reasoning.MemCascade open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/ProtocolFees.lean b/Benchmarks/UniswapV3Pool/ProtocolFees.lean index cac24323..f884d765 100644 --- a/Benchmarks/UniswapV3Pool/ProtocolFees.lean +++ b/Benchmarks/UniswapV3Pool/ProtocolFees.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Uint128 open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocol.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocol.lean index 06212f91..dfd1402b 100644 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocol.lean +++ b/Benchmarks/UniswapV3Pool/SetFeeProtocol.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.SetFeeProtocolSuccess open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocolFeeProtocolCheck.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocolFeeProtocolCheck.lean index 954a886c..3200d138 100644 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocolFeeProtocolCheck.lean +++ b/Benchmarks/UniswapV3Pool/SetFeeProtocolFeeProtocolCheck.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.SetFeeProtocolSource open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocolOwnerCall.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocolOwnerCall.lean index 61f96532..c9c867c6 100644 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocolOwnerCall.lean +++ b/Benchmarks/UniswapV3Pool/SetFeeProtocolOwnerCall.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.ImmutableGetters import Reasoning.ExternalCall open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocolSource.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocolSource.lean index a65036f2..3425b63d 100644 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocolSource.lean +++ b/Benchmarks/UniswapV3Pool/SetFeeProtocolSource.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.Slot0 import Benchmarks.UniswapV3Pool.SetFeeProtocolOwnerCall open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocolSuccess.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocolSuccess.lean index 2cbf3a77..94aa0ffd 100644 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocolSuccess.lean +++ b/Benchmarks/UniswapV3Pool/SetFeeProtocolSuccess.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.SetFeeProtocolFeeProtocolCheck open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Slot0.lean b/Benchmarks/UniswapV3Pool/Slot0.lean index fcac958a..d24f64bc 100644 --- a/Benchmarks/UniswapV3Pool/Slot0.lean +++ b/Benchmarks/UniswapV3Pool/Slot0.lean @@ -3,7 +3,7 @@ import Benchmarks.UniswapV3Pool.TickSpacing import Reasoning.MemCascade open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/TickBitmap.lean b/Benchmarks/UniswapV3Pool/TickBitmap.lean index 43fc0040..c912770d 100644 --- a/Benchmarks/UniswapV3Pool/TickBitmap.lean +++ b/Benchmarks/UniswapV3Pool/TickBitmap.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Common open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/TickSpacing.lean b/Benchmarks/UniswapV3Pool/TickSpacing.lean index ec3ca0bc..9edd1a49 100644 --- a/Benchmarks/UniswapV3Pool/TickSpacing.lean +++ b/Benchmarks/UniswapV3Pool/TickSpacing.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Common open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Ticks.lean b/Benchmarks/UniswapV3Pool/Ticks.lean index 430e945a..a54a7111 100644 --- a/Benchmarks/UniswapV3Pool/Ticks.lean +++ b/Benchmarks/UniswapV3Pool/Ticks.lean @@ -5,7 +5,7 @@ import Benchmarks.UniswapV3Pool.TicksReturnMemory import Reasoning.MemCascade open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/TicksInt128.lean b/Benchmarks/UniswapV3Pool/TicksInt128.lean index 7d1972a5..59ffadc4 100644 --- a/Benchmarks/UniswapV3Pool/TicksInt128.lean +++ b/Benchmarks/UniswapV3Pool/TicksInt128.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Uint128 open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/TicksReturnMemory.lean b/Benchmarks/UniswapV3Pool/TicksReturnMemory.lean index ebabbb94..66ad3158 100644 --- a/Benchmarks/UniswapV3Pool/TicksReturnMemory.lean +++ b/Benchmarks/UniswapV3Pool/TicksReturnMemory.lean @@ -2,7 +2,7 @@ import Benchmarks.UniswapV3Pool.Uint128 import Reasoning.MemCascade open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Token0.lean b/Benchmarks/UniswapV3Pool/Token0.lean index 0ae78cd5..f58a0791 100644 --- a/Benchmarks/UniswapV3Pool/Token0.lean +++ b/Benchmarks/UniswapV3Pool/Token0.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Common open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Token1.lean b/Benchmarks/UniswapV3Pool/Token1.lean index 683939fe..66a8b012 100644 --- a/Benchmarks/UniswapV3Pool/Token1.lean +++ b/Benchmarks/UniswapV3Pool/Token1.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Common open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Uint128.lean b/Benchmarks/UniswapV3Pool/Uint128.lean index 2e6eea64..e9b97750 100644 --- a/Benchmarks/UniswapV3Pool/Uint128.lean +++ b/Benchmarks/UniswapV3Pool/Uint128.lean @@ -1,7 +1,7 @@ import Benchmarks.UniswapV3Pool.Common open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Reasoning.Theory Reasoning.Reach namespace Benchmarks.UniswapV3Pool diff --git a/Benchmarks/WETH9/Allowance.lean b/Benchmarks/WETH9/Allowance.lean index f01475cc..06ef64aa 100644 --- a/Benchmarks/WETH9/Allowance.lean +++ b/Benchmarks/WETH9/Allowance.lean @@ -8,7 +8,7 @@ decodes two address arguments, hashes the nested slot (`keccak(guy ‖ keccak(ow and ABI-encodes the `uint256`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/WETH9/Approve.lean b/Benchmarks/WETH9/Approve.lean index 5d96e5ce..b78c2fde 100644 --- a/Benchmarks/WETH9/Approve.lean +++ b/Benchmarks/WETH9/Approve.lean @@ -9,7 +9,7 @@ import Benchmarks.WETH9.Routines DappHub/Dai `approve` (caller-keyed outer hash, masked-argument inner hash) over slot 4. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/WETH9/BalanceOf.lean b/Benchmarks/WETH9/BalanceOf.lean index e655cbc3..673eb62b 100644 --- a/Benchmarks/WETH9/BalanceOf.lean +++ b/Benchmarks/WETH9/BalanceOf.lean @@ -7,7 +7,7 @@ import Benchmarks.WETH9.Routines decodes one address argument, hashes the mapping slot, loads it, and ABI-encodes the `uint256`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/WETH9/Common.lean b/Benchmarks/WETH9/Common.lean index 44fd2ce2..0ca7ac32 100644 --- a/Benchmarks/WETH9/Common.lean +++ b/Benchmarks/WETH9/Common.lean @@ -5,7 +5,6 @@ import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -17,7 +16,7 @@ computed from the canonical ABI signatures and cross-checked against the runtime in `Bytecode.lean` (see the disassembled binary-search dispatcher). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/WETH9/Correct.lean b/Benchmarks/WETH9/Correct.lean index 85516458..9ad4fbba 100644 --- a/Benchmarks/WETH9/Correct.lean +++ b/Benchmarks/WETH9/Correct.lean @@ -20,7 +20,7 @@ non-matching selector (and calldata < 4) fall through to the payable fallback (` There is no shared callvalue guard — each non-payable function guards its own callvalue. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/WETH9/Decimals.lean b/Benchmarks/WETH9/Decimals.lean index 0cc4087b..19940849 100644 --- a/Benchmarks/WETH9/Decimals.lean +++ b/Benchmarks/WETH9/Decimals.lean @@ -6,7 +6,7 @@ import Benchmarks.WETH9.Routines `decimals` is a public non-payable uint8 getter reading storage slot 2 (masked with `0xff`). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/WETH9/Deposit.lean b/Benchmarks/WETH9/Deposit.lean index 6c1309f5..4a4ca9dd 100644 --- a/Benchmarks/WETH9/Deposit.lean +++ b/Benchmarks/WETH9/Deposit.lean @@ -12,7 +12,7 @@ converging on the runtime body at pc 760: * calldata < 4 (`weth9ShortFallbackBodyCore`, via fallback dispatch; the prologue short-circuits). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/WETH9/Dispatch.lean b/Benchmarks/WETH9/Dispatch.lean index 39bc231e..1a647d9e 100644 --- a/Benchmarks/WETH9/Dispatch.lean +++ b/Benchmarks/WETH9/Dispatch.lean @@ -12,7 +12,7 @@ so each non-payable function guards its own callvalue at its entry. This file threads `initState` to each function's body-entry pc with the selector word on the stack. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unnecessarySeqFocus false diff --git a/Benchmarks/WETH9/Name.lean b/Benchmarks/WETH9/Name.lean index fc2ac26d..7a824d81 100644 --- a/Benchmarks/WETH9/Name.lean +++ b/Benchmarks/WETH9/Name.lean @@ -7,7 +7,7 @@ return encoder is proved in `StringReturn.lean`/`StringReturnLong2.lean` (empty/ module connects those `RDret`s to the Solm `.return [.storage nameRef]` body via `returnEquiv`. Shared header/word/slot-parametric encode machinery lives in `StringEncode.lean`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Benchmarks/WETH9/Routines.lean b/Benchmarks/WETH9/Routines.lean index 550c57bb..ae69d63e 100644 --- a/Benchmarks/WETH9/Routines.lean +++ b/Benchmarks/WETH9/Routines.lean @@ -10,7 +10,7 @@ JUMPDEST gt; POP` — the peel lemmas below are the per-function analogues of th `solcGuardCallvalueZero` / `solcGuardCallvalueNonzeroRevert`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/WETH9/Storage.lean b/Benchmarks/WETH9/Storage.lean index f91e4405..c3e1f233 100644 --- a/Benchmarks/WETH9/Storage.lean +++ b/Benchmarks/WETH9/Storage.lean @@ -8,7 +8,7 @@ uint256 store that WETH9's `deposit`/`withdraw`/`transferFrom` perform. The two are general library candidates (`Reasoning.Storage`). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Benchmarks/WETH9/StringEncode.lean b/Benchmarks/WETH9/StringEncode.lean index 79394e81..7a37d2c3 100644 --- a/Benchmarks/WETH9/StringEncode.lean +++ b/Benchmarks/WETH9/StringEncode.lean @@ -7,7 +7,7 @@ Header/word/slot-parametric machinery connecting the Solm total-decode string va EVM encoder's `weth9{Empty,Short}StringAbi` / the long tail-mask. `Name.lean`/`Symbol.lean` specialise these to slot 0 / slot 1. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Benchmarks/WETH9/StringReturn.lean b/Benchmarks/WETH9/StringReturn.lean index 76d6ffc2..d9570ea2 100644 --- a/Benchmarks/WETH9/StringReturn.lean +++ b/Benchmarks/WETH9/StringReturn.lean @@ -17,7 +17,7 @@ The final `runtimeEquivalenceFor` connect (dispatch/decode/body) is wired separa `Name.lean`/`Symbol.lean`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Benchmarks/WETH9/StringReturnLong.lean b/Benchmarks/WETH9/StringReturnLong.lean index 630036fc..b45e6e3a 100644 --- a/Benchmarks/WETH9/StringReturnLong.lean +++ b/Benchmarks/WETH9/StringReturnLong.lean @@ -13,7 +13,7 @@ This file currently establishes the LONG-path setup up to the copy-loop entry (t `currentLengthGeneratedLoopState`/`_Step`/`_Final` fuel-recursion template. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Benchmarks/WETH9/StringReturnLong2.lean b/Benchmarks/WETH9/StringReturnLong2.lean index 51c3fb7f..eaa0ed58 100644 --- a/Benchmarks/WETH9/StringReturnLong2.lean +++ b/Benchmarks/WETH9/StringReturnLong2.lean @@ -17,7 +17,7 @@ data words, and reuses the Loop-1 fuel-recursion template + symbolic cost witnes `StringReturnLong.lean`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Benchmarks/WETH9/StringReturnSymbol.lean b/Benchmarks/WETH9/StringReturnSymbol.lean index 1c249ec8..7304f3c9 100644 --- a/Benchmarks/WETH9/StringReturnSymbol.lean +++ b/Benchmarks/WETH9/StringReturnSymbol.lean @@ -22,7 +22,7 @@ the reversed operands with `u256_land_comm` right after the `AND`, after which e definition (`weth9StringMask`/`Len`/`WC`/`NewFp`, `weth9RoutineMem`, …) matches `name`'s. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Benchmarks/WETH9/StringReturnSymbol2.lean b/Benchmarks/WETH9/StringReturnSymbol2.lean index d0d2ecd7..a0d976c1 100644 --- a/Benchmarks/WETH9/StringReturnSymbol2.lean +++ b/Benchmarks/WETH9/StringReturnSymbol2.lean @@ -17,7 +17,7 @@ marker on its stack (the slot value was popped at the Loop-1 exit), so this is a re-parameterization by the slot-1 header. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Benchmarks/WETH9/Symbol.lean b/Benchmarks/WETH9/Symbol.lean index 92d00062..be881ac6 100644 --- a/Benchmarks/WETH9/Symbol.lean +++ b/Benchmarks/WETH9/Symbol.lean @@ -9,7 +9,7 @@ stored at slot 1. The EVM return encoder is proved in `StringReturnSymbol.lean` `.return [.storage symbolRef]` body via `returnEquiv`, a direct mirror of `Name.lean` for slot 1. Shared header/word/slot-parametric encode machinery lives in `StringEncode.lean`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Benchmarks/WETH9/TotalSupply.lean b/Benchmarks/WETH9/TotalSupply.lean index 9f20fae6..233cb560 100644 --- a/Benchmarks/WETH9/TotalSupply.lean +++ b/Benchmarks/WETH9/TotalSupply.lean @@ -8,7 +8,7 @@ import Benchmarks.WETH9.Opcodes the contract's ether balance). No arguments, non-payable. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/WETH9/Transfer.lean b/Benchmarks/WETH9/Transfer.lean index eb8356a6..67cda8df 100644 --- a/Benchmarks/WETH9/Transfer.lean +++ b/Benchmarks/WETH9/Transfer.lean @@ -14,7 +14,7 @@ are reused directly; only the internal-call wrapper (`1661 → 1087`), the inter are proved here. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/WETH9/TransferFrom.lean b/Benchmarks/WETH9/TransferFrom.lean index be27520f..2325e8b1 100644 --- a/Benchmarks/WETH9/TransferFrom.lean +++ b/Benchmarks/WETH9/TransferFrom.lean @@ -2,7 +2,7 @@ import Benchmarks.WETH9.TransferFromSolm /-! # WETH9 `transferFrom(address,address,uint256)` refinement -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/WETH9/TransferFromBody.lean b/Benchmarks/WETH9/TransferFromBody.lean index 8df9a18b..71ab5ed3 100644 --- a/Benchmarks/WETH9/TransferFromBody.lean +++ b/Benchmarks/WETH9/TransferFromBody.lean @@ -11,7 +11,7 @@ the return address `ret`, and the stack tail `S`, in the three branch cases (`sr reverts (`balanceOf[src] < wad`; inner `allowance < wad`). -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/WETH9/TransferFromDefs.lean b/Benchmarks/WETH9/TransferFromDefs.lean index d497d43f..731dc46c 100644 --- a/Benchmarks/WETH9/TransferFromDefs.lean +++ b/Benchmarks/WETH9/TransferFromDefs.lean @@ -8,7 +8,7 @@ source⟺EVM storage-slot reconciliations for `balanceOf[src]`, `balanceOf[dst]` `allowance[src][msg.sender]`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/WETH9/TransferFromSolm.lean b/Benchmarks/WETH9/TransferFromSolm.lean index ff8e04c6..9a313c07 100644 --- a/Benchmarks/WETH9/TransferFromSolm.lean +++ b/Benchmarks/WETH9/TransferFromSolm.lean @@ -9,7 +9,7 @@ and the two require reverts. Each success lemma exposes the post-state accountM `wtfPostMap` tower the EVM produces, so the refinement bridge is a pure `accountMapEquiv` argument. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/WETH9/Withdraw.lean b/Benchmarks/WETH9/Withdraw.lean index 759e7275..33ac6fdb 100644 --- a/Benchmarks/WETH9/Withdraw.lean +++ b/Benchmarks/WETH9/Withdraw.lean @@ -2,7 +2,7 @@ import Benchmarks.WETH9.WithdrawBody /-! # WETH9 `withdraw(uint256)` refinement -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Benchmarks/WETH9/WithdrawBody.lean b/Benchmarks/WETH9/WithdrawBody.lean index 15e6f841..1871c266 100644 --- a/Benchmarks/WETH9/WithdrawBody.lean +++ b/Benchmarks/WETH9/WithdrawBody.lean @@ -10,7 +10,7 @@ with `require(success)`). This file carries the EVM trace and the Solm body-exe top-level refinement `weth9WithdrawBodyCore` lives in `Withdraw.lean`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/EquiVM.lean b/EquiVM.lean index 3d0bc594..c0229a15 100644 --- a/EquiVM.lean +++ b/EquiVM.lean @@ -9,7 +9,6 @@ import Reasoning.JumpDest import Reasoning.MemCascade import Reasoning.Memory import Reasoning.Reach -import Reasoning.Refinement import Reasoning.Solc import Reasoning.SolmBody import Reasoning.Stepping diff --git a/Examples/Ballot/Chairperson.lean b/Examples/Ballot/Chairperson.lean index 261b7ac9..de8faa75 100644 --- a/Examples/Ballot/Chairperson.lean +++ b/Examples/Ballot/Chairperson.lean @@ -1,9 +1,8 @@ import Examples.Ballot.Common -import Reasoning.Refinement import Reasoning.SolmBody import Reasoning.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/Ballot/Correct.lean b/Examples/Ballot/Correct.lean index 3adf8335..88273ff1 100644 --- a/Examples/Ballot/Correct.lean +++ b/Examples/Ballot/Correct.lean @@ -14,7 +14,6 @@ import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases @@ -49,7 +48,7 @@ Body entry PCs (dispatch targets), read off the bytecode disassembly: | `0xe2ba53f0` | `winnerName()` | `417` (`0x1a1`) | -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/Ballot/Delegate.lean b/Examples/Ballot/Delegate.lean index 62c9f01c..0b368cca 100644 --- a/Examples/Ballot/Delegate.lean +++ b/Examples/Ballot/Delegate.lean @@ -1,11 +1,10 @@ import Examples.Ballot.Common import Examples.Ballot.Vote import Reasoning.Memory -import Reasoning.Refinement import Reasoning.SolmBody import Reasoning.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Examples/Ballot/DelegateChain.lean b/Examples/Ballot/DelegateChain.lean index dd65ed2b..ad52797b 100644 --- a/Examples/Ballot/DelegateChain.lean +++ b/Examples/Ballot/DelegateChain.lean @@ -1,6 +1,6 @@ import Examples.Ballot.DelegateTail -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Examples/Ballot/DelegateComplete.lean b/Examples/Ballot/DelegateComplete.lean index 6feba7b5..3ff0420a 100644 --- a/Examples/Ballot/DelegateComplete.lean +++ b/Examples/Ballot/DelegateComplete.lean @@ -1,7 +1,7 @@ import Examples.Ballot.DelegateTailGeneral import Examples.Ballot.DelegateOOG -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Examples/Ballot/DelegateLoop.lean b/Examples/Ballot/DelegateLoop.lean index c5527d6b..b4b833b0 100644 --- a/Examples/Ballot/DelegateLoop.lean +++ b/Examples/Ballot/DelegateLoop.lean @@ -1,6 +1,6 @@ import Examples.Ballot.Delegate -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Examples/Ballot/DelegateOOG.lean b/Examples/Ballot/DelegateOOG.lean index 0f22b3e3..82259f76 100644 --- a/Examples/Ballot/DelegateOOG.lean +++ b/Examples/Ballot/DelegateOOG.lean @@ -1,6 +1,6 @@ import Examples.Ballot.DelegateChain -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Examples/Ballot/DelegateTail.lean b/Examples/Ballot/DelegateTail.lean index 64ed5d86..e269935f 100644 --- a/Examples/Ballot/DelegateTail.lean +++ b/Examples/Ballot/DelegateTail.lean @@ -1,6 +1,6 @@ import Examples.Ballot.DelegateLoop -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Examples/Ballot/DelegateTailGeneral.lean b/Examples/Ballot/DelegateTailGeneral.lean index 2b9d3a92..99136370 100644 --- a/Examples/Ballot/DelegateTailGeneral.lean +++ b/Examples/Ballot/DelegateTailGeneral.lean @@ -1,6 +1,6 @@ import Examples.Ballot.DelegateChain -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Examples/Ballot/GiveRightToVote.lean b/Examples/Ballot/GiveRightToVote.lean index 8ac93726..8aa79573 100644 --- a/Examples/Ballot/GiveRightToVote.lean +++ b/Examples/Ballot/GiveRightToVote.lean @@ -1,10 +1,9 @@ import Examples.Ballot.Common import Reasoning.Memory -import Reasoning.Refinement import Reasoning.SolmBody import Reasoning.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Examples/Ballot/Proposals.lean b/Examples/Ballot/Proposals.lean index 45a2b1e1..dcad4218 100644 --- a/Examples/Ballot/Proposals.lean +++ b/Examples/Ballot/Proposals.lean @@ -1,8 +1,7 @@ import Examples.Ballot.Common -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/Ballot/Vote.lean b/Examples/Ballot/Vote.lean index b94a86e6..be95d99a 100644 --- a/Examples/Ballot/Vote.lean +++ b/Examples/Ballot/Vote.lean @@ -1,10 +1,9 @@ import Examples.Ballot.Common import Examples.Ballot.Proposals -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Data.Nat.Bitwise -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Examples/Ballot/Voters.lean b/Examples/Ballot/Voters.lean index ec117923..7d6763f2 100644 --- a/Examples/Ballot/Voters.lean +++ b/Examples/Ballot/Voters.lean @@ -1,8 +1,7 @@ import Examples.Ballot.Common -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/Ballot/WinnerName.lean b/Examples/Ballot/WinnerName.lean index 59251766..cab9ba74 100644 --- a/Examples/Ballot/WinnerName.lean +++ b/Examples/Ballot/WinnerName.lean @@ -1,8 +1,7 @@ import Examples.Ballot.WinningProposal -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/Ballot/WinningProposal.lean b/Examples/Ballot/WinningProposal.lean index 757dc653..050f379d 100644 --- a/Examples/Ballot/WinningProposal.lean +++ b/Examples/Ballot/WinningProposal.lean @@ -1,8 +1,7 @@ import Examples.Ballot.Common -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/BlindAuction/AuctionEnd.lean b/Examples/BlindAuction/AuctionEnd.lean index 4df711df..26b5a26f 100644 --- a/Examples/BlindAuction/AuctionEnd.lean +++ b/Examples/BlindAuction/AuctionEnd.lean @@ -1,11 +1,10 @@ import Examples.BlindAuction.Beneficiary import Examples.BlindAuction.Ended import Examples.BlindAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/BlindAuction/Beneficiary.lean b/Examples/BlindAuction/Beneficiary.lean index a2689f9e..ba2e0263 100644 --- a/Examples/BlindAuction/Beneficiary.lean +++ b/Examples/BlindAuction/Beneficiary.lean @@ -1,11 +1,10 @@ import Examples.BlindAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Data.Nat.Bitwise import Mathlib.Data.Nat.Digits.Defs import Mathlib.Data.Nat.Digits.Lemmas -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/BlindAuction/Bid.lean b/Examples/BlindAuction/Bid.lean index 6fc89476..1d7167ca 100644 --- a/Examples/BlindAuction/Bid.lean +++ b/Examples/BlindAuction/Bid.lean @@ -2,10 +2,9 @@ import Examples.BlindAuction.Storage import Examples.BlindAuction.Bids import Examples.BlindAuction.BiddingEnd import Reasoning.ABI -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/BlindAuction/BiddingEnd.lean b/Examples/BlindAuction/BiddingEnd.lean index e672439b..1eb8bb49 100644 --- a/Examples/BlindAuction/BiddingEnd.lean +++ b/Examples/BlindAuction/BiddingEnd.lean @@ -1,8 +1,7 @@ import Examples.BlindAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/BlindAuction/Bids.lean b/Examples/BlindAuction/Bids.lean index d3a1715e..4dd57007 100644 --- a/Examples/BlindAuction/Bids.lean +++ b/Examples/BlindAuction/Bids.lean @@ -1,8 +1,7 @@ import Examples.BlindAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/BlindAuction/Correct.lean b/Examples/BlindAuction/Correct.lean index 08a8315a..dbf9f67a 100644 --- a/Examples/BlindAuction/Correct.lean +++ b/Examples/BlindAuction/Correct.lean @@ -10,7 +10,6 @@ import Examples.BlindAuction.RevealEnd import Examples.BlindAuction.HighestBidder import Examples.BlindAuction.HighestBid import Reasoning.Initcode -import Reasoning.Refinement /-! # BlindAuction — top-level correctness proof @@ -22,7 +21,7 @@ dispatcher: calldata size and selector routing happen before any callvalue check guards are proved inside the individual body files. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/BlindAuction/Ended.lean b/Examples/BlindAuction/Ended.lean index f6ff6c5f..41c8c8fc 100644 --- a/Examples/BlindAuction/Ended.lean +++ b/Examples/BlindAuction/Ended.lean @@ -1,11 +1,10 @@ import Examples.BlindAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Data.Nat.Bitwise import Mathlib.Data.Nat.Digits.Defs import Mathlib.Data.Nat.Digits.Lemmas -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/BlindAuction/HighestBid.lean b/Examples/BlindAuction/HighestBid.lean index c4151aaf..84f2c14b 100644 --- a/Examples/BlindAuction/HighestBid.lean +++ b/Examples/BlindAuction/HighestBid.lean @@ -1,8 +1,7 @@ import Examples.BlindAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/BlindAuction/HighestBidder.lean b/Examples/BlindAuction/HighestBidder.lean index 2c039399..82b5433f 100644 --- a/Examples/BlindAuction/HighestBidder.lean +++ b/Examples/BlindAuction/HighestBidder.lean @@ -1,11 +1,10 @@ import Examples.BlindAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody import Mathlib.Data.Nat.Bitwise import Mathlib.Data.Nat.Digits.Defs import Mathlib.Data.Nat.Digits.Lemmas -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/BlindAuction/Reveal.lean b/Examples/BlindAuction/Reveal.lean index cd7944c6..30aad7d8 100644 --- a/Examples/BlindAuction/Reveal.lean +++ b/Examples/BlindAuction/Reveal.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.Decoded -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 10000000 diff --git a/Examples/BlindAuction/Reveal/Assemble.lean b/Examples/BlindAuction/Reveal/Assemble.lean index 9898808b..7a51bfe4 100644 --- a/Examples/BlindAuction/Reveal/Assemble.lean +++ b/Examples/BlindAuction/Reveal/Assemble.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.Cases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 800000 diff --git a/Examples/BlindAuction/Reveal/Body.lean b/Examples/BlindAuction/Reveal/Body.lean index aded7d35..e8c34c5a 100644 --- a/Examples/BlindAuction/Reveal/Body.lean +++ b/Examples/BlindAuction/Reveal/Body.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.BodyCases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 10000000 diff --git a/Examples/BlindAuction/Reveal/BodyCases.lean b/Examples/BlindAuction/Reveal/BodyCases.lean index 40ab2f9c..2f6a53d1 100644 --- a/Examples/BlindAuction/Reveal/BodyCases.lean +++ b/Examples/BlindAuction/Reveal/BodyCases.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.FakeFalse -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 10000000 diff --git a/Examples/BlindAuction/Reveal/Cases.lean b/Examples/BlindAuction/Reveal/Cases.lean index 1cd7ab5c..938335c1 100644 --- a/Examples/BlindAuction/Reveal/Cases.lean +++ b/Examples/BlindAuction/Reveal/Cases.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.Nonempty -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/BlindAuction/Reveal/Common.lean b/Examples/BlindAuction/Reveal/Common.lean index dab1b78f..06380fdf 100644 --- a/Examples/BlindAuction/Reveal/Common.lean +++ b/Examples/BlindAuction/Reveal/Common.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.Decode -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 800000 diff --git a/Examples/BlindAuction/Reveal/Decode.lean b/Examples/BlindAuction/Reveal/Decode.lean index b11abb09..c366a274 100644 --- a/Examples/BlindAuction/Reveal/Decode.lean +++ b/Examples/BlindAuction/Reveal/Decode.lean @@ -5,10 +5,9 @@ import Examples.BlindAuction.HighestBidder import Examples.BlindAuction.RevealEnd import Examples.SimpleAuction.Withdraw import Reasoning.ExternalCall -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 800000 diff --git a/Examples/BlindAuction/Reveal/Decoded.lean b/Examples/BlindAuction/Reveal/Decoded.lean index 741c28a0..acfe9b5f 100644 --- a/Examples/BlindAuction/Reveal/Decoded.lean +++ b/Examples/BlindAuction/Reveal/Decoded.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.DecodedLengthOk -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 10000000 diff --git a/Examples/BlindAuction/Reveal/DecodedEmpty.lean b/Examples/BlindAuction/Reveal/DecodedEmpty.lean index 9ba21fb0..2905d767 100644 --- a/Examples/BlindAuction/Reveal/DecodedEmpty.lean +++ b/Examples/BlindAuction/Reveal/DecodedEmpty.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.PostLoop -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 10000000 diff --git a/Examples/BlindAuction/Reveal/DecodedLengthOk.lean b/Examples/BlindAuction/Reveal/DecodedLengthOk.lean index 30e5c14c..c840308c 100644 --- a/Examples/BlindAuction/Reveal/DecodedLengthOk.lean +++ b/Examples/BlindAuction/Reveal/DecodedLengthOk.lean @@ -1,7 +1,7 @@ import Examples.BlindAuction.Reveal.DecodedEmpty import Examples.BlindAuction.Reveal.DecodedNonempty -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 10000000 diff --git a/Examples/BlindAuction/Reveal/DecodedNonempty.lean b/Examples/BlindAuction/Reveal/DecodedNonempty.lean index c0fae5b1..0b9d4bf9 100644 --- a/Examples/BlindAuction/Reveal/DecodedNonempty.lean +++ b/Examples/BlindAuction/Reveal/DecodedNonempty.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.DecodedNonemptyRun -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 10000000 diff --git a/Examples/BlindAuction/Reveal/DecodedNonemptyLoop.lean b/Examples/BlindAuction/Reveal/DecodedNonemptyLoop.lean index 87cf48f4..0f7a2c25 100644 --- a/Examples/BlindAuction/Reveal/DecodedNonemptyLoop.lean +++ b/Examples/BlindAuction/Reveal/DecodedNonemptyLoop.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.PostLoop -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 10000000 diff --git a/Examples/BlindAuction/Reveal/DecodedNonemptyRun.lean b/Examples/BlindAuction/Reveal/DecodedNonemptyRun.lean index 693bc2b7..13dbd9b0 100644 --- a/Examples/BlindAuction/Reveal/DecodedNonemptyRun.lean +++ b/Examples/BlindAuction/Reveal/DecodedNonemptyRun.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.DecodedNonemptyLoop -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 10000000 diff --git a/Examples/BlindAuction/Reveal/FakeFalse.lean b/Examples/BlindAuction/Reveal/FakeFalse.lean index 8ce68b5c..ed5ac24d 100644 --- a/Examples/BlindAuction/Reveal/FakeFalse.lean +++ b/Examples/BlindAuction/Reveal/FakeFalse.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.Assemble -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 10000000 diff --git a/Examples/BlindAuction/Reveal/Loop.lean b/Examples/BlindAuction/Reveal/Loop.lean index b374bcbe..c0f30123 100644 --- a/Examples/BlindAuction/Reveal/Loop.lean +++ b/Examples/BlindAuction/Reveal/Loop.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.PlaceBid -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 800000 diff --git a/Examples/BlindAuction/Reveal/Nonempty.lean b/Examples/BlindAuction/Reveal/Nonempty.lean index 83c15d8a..330a5947 100644 --- a/Examples/BlindAuction/Reveal/Nonempty.lean +++ b/Examples/BlindAuction/Reveal/Nonempty.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.Loop -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 800000 diff --git a/Examples/BlindAuction/Reveal/PlaceBid.lean b/Examples/BlindAuction/Reveal/PlaceBid.lean index 16f61c66..fd0a99d2 100644 --- a/Examples/BlindAuction/Reveal/PlaceBid.lean +++ b/Examples/BlindAuction/Reveal/PlaceBid.lean @@ -1,6 +1,6 @@ import Examples.BlindAuction.Reveal.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 800000 diff --git a/Examples/BlindAuction/Reveal/PostLoop.lean b/Examples/BlindAuction/Reveal/PostLoop.lean index b7e2f6cd..f81aaf86 100644 --- a/Examples/BlindAuction/Reveal/PostLoop.lean +++ b/Examples/BlindAuction/Reveal/PostLoop.lean @@ -1,7 +1,7 @@ import Examples.BlindAuction.Reveal.PostLoopBranches import Lean.Elab.Tactic.AsAuxLemma -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 10000000 diff --git a/Examples/BlindAuction/Reveal/PostLoopBranches.lean b/Examples/BlindAuction/Reveal/PostLoopBranches.lean index cd3ce181..eddd8f30 100644 --- a/Examples/BlindAuction/Reveal/PostLoopBranches.lean +++ b/Examples/BlindAuction/Reveal/PostLoopBranches.lean @@ -1,7 +1,7 @@ import Examples.BlindAuction.Reveal.Body import Lean.Elab.Tactic.AsAuxLemma -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 10000000 diff --git a/Examples/BlindAuction/RevealEnd.lean b/Examples/BlindAuction/RevealEnd.lean index ec4df3da..8031b3ba 100644 --- a/Examples/BlindAuction/RevealEnd.lean +++ b/Examples/BlindAuction/RevealEnd.lean @@ -1,8 +1,7 @@ import Examples.BlindAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/BlindAuction/Withdraw.lean b/Examples/BlindAuction/Withdraw.lean index f555eaca..dedc457b 100644 --- a/Examples/BlindAuction/Withdraw.lean +++ b/Examples/BlindAuction/Withdraw.lean @@ -1,10 +1,9 @@ import Examples.BlindAuction.Storage import Examples.SimpleAuction.Withdraw import Reasoning.ExternalCall -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/CallerCoupled/BodySuccess.lean b/Examples/CallerCoupled/BodySuccess.lean deleted file mode 100644 index d5d84a77..00000000 --- a/Examples/CallerCoupled/BodySuccess.lean +++ /dev/null @@ -1,1461 +0,0 @@ -import Examples.Caller.Bytecode -import Reasoning.ABI -import Reasoning.EVMWord -import Reasoning.Dispatch -import Reasoning.SolmBody -import Reasoning.Stepping -import Reasoning.Memory -import Reasoning.Solc -import Reasoning.Reach -import Reasoning.ExternalCall -import Reasoning.Refinement - -/-! -# Caller coupled-state experiment - -This mirrors the Pow coupled proof for the body suffix of `Caller.run`: start after calldata decode -at pc 66 with the Solm non-payable guard already accounted for, then couple the opaque external -call and the storage assignment. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement - -namespace CallerCoupled - -noncomputable section - -set_option maxRecDepth 10000 - -private theorem decodeReturnValues_uint256_ok {returndata : ByteArray} - (hlo : 32 ≤ returndata.size) (hhi : returndata.size < (2 : Nat) ^ 255) : - ABI.decodeReturnValues? [abiUInt256] returndata = - some [(.int (Int.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))))] := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have htake0 : (returndata.toList.take 32).length = 32 := by - rw [List.length_take, hlen] - omega - have hword := bytesToWord_take32_eq_extract0_32 (returndata := returndata) - rw [decodeReturnValues_scalarWords_eq (types := [abiUInt256]) (returndata := returndata) - (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - rw [decodeScalarWords_uint256_ok (bytes := returndata.toList) htake0] - simp [hword, UInt256.toNat_ofNat_of_lt (fromByteArrayBigEndian_extract0_32_lt hlo)] - -private theorem decodeReturnValues_uint256_none_short {returndata : ByteArray} - (hshort : returndata.size < 32) : - ABI.decodeReturnValues? [abiUInt256] returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - rw [decodeReturnValues_scalarWords_eq (types := [abiUInt256]) (returndata := returndata) - (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - rw [decodeScalarWords_uint256_none_short (bytes := returndata.toList) (by rw [hlen]; omega)] - -private theorem decodeReturnValues_uint256_none_huge {returndata : ByteArray} - (hhuge : (2 : Nat) ^ 255 ≤ returndata.size) : - ABI.decodeReturnValues? [abiUInt256] returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - rw [decodeReturnValues_scalarWords_eq (types := [abiUInt256]) (returndata := returndata) - (by decide)] - rw [if_pos (by exact ⟨by simp, by rw [hlen]; exact hhuge⟩)] - -/-- All `callerBytecode` jump targets validated by one tactic. -/ -macro "caller_jd" : term => `(by jump_dest) - -private abbrev callerContract := Caller.callerContract -private abbrev runTransition := Caller.runTransition -private abbrev addr := Caller.addr -private abbrev uint256 := Caller.uint256 -private abbrev callerExternalABI := Caller.callerExternalABI -private abbrev pow2Selector := Caller.pow2Selector - -theorem callerDispatch_eq (cd : ByteArray) : - dispatchMsg callerContract cd - = if ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == cd.extract 0 4) - then some runTransition else none := - dispatch_eq rfl rfl callerSelectorBytes cd - -theorem callerDispatch_none_short {cd : ByteArray} (h : cd.size < 4) : - dispatchMsg callerContract cd = none := - dispatch_none_short rfl rfl callerSelectorBytes rfl h - -theorem callerDispatch_none_nomatch {cd : ByteArray} - (h : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == cd.extract 0 4) = false) : - dispatchMsg callerContract cd = none := - dispatch_none_nomatch rfl rfl callerSelectorBytes h - -theorem callerBodyReverts (evm : EVM.State) (locals : Store) - (h : evm.executionEnv.weiValue ≠ ⟨0⟩) : - ExecTransitionBody callerConfig callerContract evm locals runTransition.body .reverted := - bodyReverts_nonPayable h - -theorem callerBodyExtFail (evm : EVM.State) (locals : Solm.Store) {tval : EVM.Address} {nval : ℤ} - {evm' : EVM.State} {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (ht : locals.get? "t" = some (.address tval)) - (hn : locals.get? "n" = some (.int nval)) - (hcall : typedCallViaEVM callerConfig evm (EVM.address tval) "pow2" 0 [.int nval] - (false, evm', out)) : - ExecTransitionBody callerConfig callerContract evm locals runTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert - (ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) - (ExecBlock.consRevert (ExecStmt.externalCallFailure ?_ ?_ ?_ hcall))) - · show evalExpr? callerConfig _ evm (.var "t") = .ok (.address tval) - simp only [evalExpr?, EvalResult.ofOption, ht] - · show evalExpr? callerConfig _ evm (.intLit 0) = .ok (.int 0) - simp only [evalExpr?]; rfl - · show evalExprs? callerConfig _ evm [.var "n"] = .ok [.int nval] - simp only [evalExprs?, evalExpr?, EvalResult.ofOption, hn, EvalResult.bind, bind, pure] - -theorem callerContains15 : (D_J callerBytecode 0).contains ⟨15⟩ = true := by - jump_dest -theorem callerContains41 : (D_J callerBytecode 0).contains ⟨41⟩ = true := by - jump_dest -theorem callerContains45 : (D_J callerBytecode 0).contains ⟨45⟩ = true := by - jump_dest -theorem callerContains348 : (D_J callerBytecode 0).contains ⟨348⟩ = true := by - jump_dest -theorem callerContains491 : (D_J callerBytecode 0).contains ⟨491⟩ = true := by - jump_dest -theorem callerContains203 : (D_J callerBytecode 0).contains ⟨203⟩ = true := by - jump_dest -theorem callerContains71 : (D_J callerBytecode 0).contains ⟨71⟩ = true := by - jump_dest -theorem callerContains194 : (D_J callerBytecode 0).contains ⟨194⟩ = true := by - jump_dest -theorem callerContains297 : (D_J callerBytecode 0).contains ⟨297⟩ = true := by - jump_dest -theorem callerContains306 : (D_J callerBytecode 0).contains ⟨306⟩ = true := by - jump_dest -theorem callerContains315 : (D_J callerBytecode 0).contains ⟨315⟩ = true := by - jump_dest -theorem callerContains325 : (D_J callerBytecode 0).contains ⟨325⟩ = true := by - jump_dest -theorem callerContains450 : (D_J callerBytecode 0).contains ⟨450⟩ = true := by - jump_dest -theorem callerContains464 : (D_J callerBytecode 0).contains ⟨464⟩ = true := by - jump_dest -theorem callerContains504 : (D_J callerBytecode 0).contains ⟨504⟩ = true := by - jump_dest -theorem callerContains158 : (D_J callerBytecode 0).contains ⟨158⟩ = true := by - jump_dest -theorem callerContains470 : (D_J callerBytecode 0).contains ⟨470⟩ = true := by - jump_dest - -/-- Address-mask literal (`PUSH20 0xff…ff`). -/ -def addrMask : UInt256 := ⟨1461501637330902918203684832716283019655932542975⟩ - -/-- The decoded calldata address word at offset 4. -/ -abbrev callerArg0 (I : ExecutionEnv) : UInt256 := - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ + ⟨0⟩ : UInt256).toNat 32) - -/-- The decoded calldata uint256 word at offset 36. -/ -abbrev callerArg1 (I : ExecutionEnv) : UInt256 := - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ + ⟨32⟩ : UInt256).toNat 32) - -theorem ueq_self (a : UInt256) : UInt256.eq a a = ⟨1⟩ := by - have h : UInt256.eq a a = UInt256.ofNat 1 := by simp [UInt256.eq, UInt256.fromBool] - rw [h]; rfl - -noncomputable def callerSelMem : ByteArray := - (UInt256.shiftLeft (UInt256.land ⟨4294967295⟩ ⟨1143701499⟩) ⟨224⟩).toByteArray.write 0 - solcFreePtrMem 128 32 - -noncomputable def callerCalldataMem (I : ExecutionEnv) : ByteArray := - (callerArg1 I).toByteArray.write 0 callerSelMem 132 32 - -noncomputable def callerOutPtr (I : ExecutionEnv) : UInt256 := - if (⟨64⟩ : UInt256).toNat ≥ (callerCalldataMem I).size ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 6 * ⟨32⟩ - then ⟨0⟩ - else UInt256.ofNat (fromByteArrayBigEndian ((callerCalldataMem I).readWithPadding (⟨64⟩ : UInt256).toNat 32)) - -theorem callerSelMem_size : callerSelMem.size = 160 := solcReturnMem_size _ - -theorem callerSelMem_read64 : callerSelMem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := - solcReturnMem_read64 _ - -theorem callerCalldataMem_size (I : ExecutionEnv) : (callerCalldataMem I).size = 164 := by - unfold callerCalldataMem - rw [write32_eq _ _ _ (by rw [toByteArray_size]) (by rw [callerSelMem_size]; omega), - ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, ByteArray.size_extract, - ByteArray.size_extract, callerSelMem_size, toByteArray_size] - omega - -theorem callerCalldataMem_read64 (I : ExecutionEnv) : - (callerCalldataMem I).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by - unfold callerCalldataMem - rw [write32_read_below _ _ 132 64 (by rw [toByteArray_size]) (by rw [callerSelMem_size]; omega) - (by omega), callerSelMem_read64] - -theorem callerOutPtr_eq (I : ExecutionEnv) : callerOutPtr I = ⟨128⟩ := by - unfold callerOutPtr - exact mloadFreePtrValue (by rw [callerCalldataMem_size]; decide) (by decide) - (callerCalldataMem_read64 I) - -theorem callerSelMem_selector : callerSelMem.extract 128 132 = Caller.pow2Selector := by - rw [show callerSelMem - = solcReturnMem (UInt256.shiftLeft (UInt256.land ⟨4294967295⟩ ⟨1143701499⟩) ⟨224⟩) from rfl, - solcReturnMem_eq, - extract_append_right_window _ _ _ _ (by rw [solcFreePtrMem_pad_size]), - solcFreePtrMem_pad_size, show (128:ℕ) - 128 = 0 from rfl, show (132:ℕ) - 128 = 4 from rfl, - toByteArray_eq_toBytesBE] - native_decide - -theorem callerCalldataMem_read128_36 (I : ExecutionEnv) : - (callerCalldataMem I).readWithPadding 128 36 = Caller.pow2Selector ++ (callerArg1 I).toByteArray := by - rw [readWithPadding_eq_extract' _ 128 36 (by norm_num) (by norm_num) - (by rw [callerCalldataMem_size]), callerCalldataMem, - write32_eq _ callerSelMem 132 (by rw [toByteArray_size]) (by rw [callerSelMem_size]; omega)] - have hAsz : (callerSelMem.extract 0 132).size = 132 := by - rw [ByteArray.size_extract, callerSelMem_size]; omega - have hBsz : ((callerArg1 I).toByteArray.extract 0 32).size = 32 := by - rw [ByteArray.size_extract, toByteArray_size]; omega - have hPsz : (callerSelMem.extract 0 132 ++ (callerArg1 I).toByteArray.extract 0 32).size = 164 := by - rw [ByteArray.size_append, hAsz, hBsz] - have hBfull : (callerArg1 I).toByteArray.extract 0 32 = (callerArg1 I).toByteArray := by - have h := @ByteArray.extract_zero_size (callerArg1 I).toByteArray - rwa [toByteArray_size] at h - rw [extract_append_left _ _ _ _ (by rw [hPsz]), - extract_append_span _ _ 128 164 (by rw [hAsz]; omega) (by rw [hAsz]; omega), hAsz, - extract_prefix _ 132 128 132 (by omega), callerSelMem_selector, - extract_extract_BA, show (0:ℕ) + 0 = 0 from rfl, - show min (0 + (164 - 132)) 32 = 32 from by omega, hBfull] - -theorem wordOfInt_ofNat_toNat (a : UInt256) : EVM.wordOfInt (Int.ofNat a.toNat) = a := by - rw [EVM.wordOfInt, if_neg (by simp)] - apply u256_inj - rw [show (Int.ofNat a.toNat).toNat = a.toNat from rfl] - show a.toNat % EVM.twoPow 256 = a.toNat - exact Nat.mod_eq_of_lt (lt_of_lt_of_le a.val.isLt (by decide)) - -theorem callerEncode_eq (I : ExecutionEnv) : - Caller.callerExternalABI.encode? "pow2" [.int (Int.ofNat (callerArg1 I).toNat)] - = some ((callerCalldataMem I).readWithPadding 128 36) := by - rw [callerCalldataMem_read128_36] - show some (Caller.pow2Selector ++ UInt256.toByteArray (EVM.wordOfInt (Int.ofNat (callerArg1 I).toNat))) - = some (Caller.pow2Selector ++ (callerArg1 I).toByteArray) - rw [wordOfInt_ofNat_toNat] - -theorem natLandComm (a b : ℕ) : Nat.land a b = Nat.land b a := by - apply Nat.eq_of_testBit_eq; intro i - show (a &&& b).testBit i = (b &&& a).testBit i - rw [Nat.testBit_and, Nat.testBit_and, Bool.and_comm] - -theorem uland_comm (a b : UInt256) : UInt256.land a b = UInt256.land b a := by - apply u256_inj - show (Fin.land a.val b.val).val = (Fin.land b.val a.val).val - simp only [Fin.land]; rw [natLandComm] - -theorem callerLand_target {I : ExecutionEnv} - (hclean : UInt256.eq (callerArg0 I) (UInt256.land (callerArg0 I) addrMask) = ⟨1⟩) : - UInt256.land addrMask (callerArg0 I) = callerArg0 I := by - have heq : callerArg0 I = UInt256.land (callerArg0 I) addrMask := by - by_contra hne - simp only [UInt256.eq, UInt256.fromBool, Bool.toUInt256, hne, decide_false, Bool.false_eq_true, - ↓reduceIte] at hclean - exact absurd hclean (by decide) - rw [uland_comm, ← heq] - -theorem callerTarget_eq {I : ExecutionEnv} - (hclean : UInt256.eq (callerArg0 I) (UInt256.land (callerArg0 I) addrMask) = ⟨1⟩) : - EVM.address (AccountAddress.ofNat (callerArg0 I).toNat) - = AccountAddress.ofUInt256 (UInt256.land addrMask (callerArg0 I)) := by - rw [callerLand_target hclean] - apply Fin.ext - show (callerArg0 I).toNat % EVM.addressModulus % AccountAddress.size - = (callerArg0 I).val % AccountAddress.size % AccountAddress.size - rw [show EVM.addressModulus = AccountAddress.size from by decide] - rfl - -theorem wordOfInt_ofNat_eq (k : ℕ) : EVM.wordOfInt (Int.ofNat k) = UInt256.ofNat k := by - rw [EVM.wordOfInt, if_neg (by simp)]; apply u256_inj - show (Int.ofNat k).toNat % EVM.twoPow 256 = (UInt256.ofNat k).toNat - rw [show (Int.ofNat k).toNat = k from rfl, show (UInt256.ofNat k).toNat = k % UInt256.size from rfl, - show EVM.twoPow 256 = UInt256.size from by decide] - -theorem fromBytesLE_roundtrip (w : UInt256) : - fromBytes' (EVM.Word.toBytesLEWithSizeProof w).1 = w.toNat := by - show fromBytes' (toBytes' w.val ++ List.replicate (32 - (toBytes' w.val).length) 0) = w.toNat - rw [fromBytes'_append_zeros, fromBytes'_toBytes']; rfl - -theorem callerLocStore (evm' : EVM.State) (k : ℕ) : - storageLocStore evm' - { slot := ⟨0⟩, offset := 0, size := 32, hbound := by decide, - bitOffset := .none, - type := .int (.uint ⟨256, by decide⟩) } (.int (Int.ofNat k)) - = some (EVM.storageStore evm' evm'.executionEnv.codeOwner ⟨0⟩ (UInt256.ofNat k)) := by - unfold storageLocStore - simp only [valueToWord, wordOfInt_ofNat_eq, bind, Option.bind, pure, storageLocWriteWord] - have hslen := (EVM.Word.toBytesLEWithSizeProof (EVM.storageLoad evm' evm'.executionEnv.codeOwner ⟨0⟩)).2 - have hvlen := (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat k)).2 - congr 2; apply u256_inj - show fromBytes' (List.take (0:Fin 32).val _ ++ List.take (32:Fin 33).val _ - ++ List.drop ((0:Fin 32).val + (32:Fin 33).val) _) = (UInt256.ofNat k).toNat - rw [show (0:Fin 32).val = 0 from rfl, show (32:Fin 33).val = 32 from rfl, - List.take_zero, List.nil_append, List.drop_eq_nil_of_le (by omega), List.append_nil, - List.take_of_length_le (by omega), fromBytesLE_roundtrip] - -theorem callerAssign (evm' : EVM.State) (L : Solm.Store) (k : ℕ) (hbase : L.get? "stored" = none) : - assignStorageRef? callerConfig { contract := Caller.callerContract, locals := L } evm' .storage - { base := "stored", steps := [] } (.int (Int.ofNat k)) - = .ok ({ contract := Caller.callerContract, locals := L }, - EVM.storageStore evm' evm'.executionEnv.codeOwner ⟨0⟩ (UInt256.ofNat k)) := by - have her : evalStorageRef callerConfig { contract := Caller.callerContract, locals := L } evm' - { base := "stored", steps := [] } = .ok { base := "stored", steps := [] } := by - simp [evalStorageRef, bind, EvalResult.bind, pure] - have hty : storageTypeAt? Caller.callerContract.storage { base := "stored", steps := [] } = - some (.elem (.int (.uint ⟨256, by decide⟩))) := by - simp [storageTypeAt?, Caller.callerContract] - have hloc : callerConfig.storage.layout { base := "stored", steps := [] } = - fun _ => some { slot := ⟨0⟩, offset := 0, size := 32, hbound := (by decide), - bitOffset := .none, type := .int (.uint ⟨256, (by decide)⟩) } := rfl - exact assignStorageRef_storage_scalar hbase her hty hloc (callerLocStore evm' k) - -theorem storageStore_accountMap (evm' : EVM.State) (a : AccountAddress) (s v : UInt256) : - (EVM.storageStore evm' a s v).accountMap = sstoreAccountMap a evm'.accountMap s v := by - simp only [EVM.storageStore, sstoreAccountMap, State.lookupAccount] - cases evm'.accountMap.find? a with - | none => rfl - | some acc => simp only [Option.option, State.setAccount, Account.updateStorage] - -theorem storageStore_createdAccounts (evm' : EVM.State) (a : AccountAddress) (s v : UInt256) : - (EVM.storageStore evm' a s v).createdAccounts = evm'.createdAccounts := by - simp only [EVM.storageStore, State.lookupAccount] - cases evm'.accountMap.find? a with - | none => rfl - | some acc => simp only [Option.option, State.setAccount] - -theorem ofNat_toNat_lt_size (n : ℕ) (h : n < UInt256.size) : (UInt256.ofNat n).toNat = n := - ulit_toNat' n h - -theorem ofNat_toNat_lt (n : ℕ) (h : n < 2^255) : (UInt256.ofNat n).toNat = n := - ofNat_toNat_lt_size n (by simpa [UInt256.size] using (by omega : n < 2^256)) - -theorem callerL_succ (n : ℕ) (h1 : 32 ≤ n) (h2 : n < UInt256.size) : - (min (⟨32⟩:UInt256) (UInt256.ofNat n)).toNat = 32 := by - show (if (⟨32⟩:UInt256) ≤ UInt256.ofNat n then (⟨32⟩:UInt256) else UInt256.ofNat n).toNat = 32 - rw [if_pos (show (⟨32⟩:UInt256) ≤ UInt256.ofNat n from ?_)] - · rfl - · show (32:ℕ) ≤ (UInt256.ofNat n).val.val - rw [show (UInt256.ofNat n).val.val = (UInt256.ofNat n).toNat from rfl, - ofNat_toNat_lt_size n h2] - omega - -theorem callerL_rev (n : ℕ) (h : n < 32) : - (min (⟨32⟩:UInt256) (UInt256.ofNat n)).toNat = n := by - show (if (⟨32⟩:UInt256) ≤ UInt256.ofNat n then (⟨32⟩:UInt256) else UInt256.ofNat n).toNat = n - rw [if_neg (show ¬ (⟨32⟩:UInt256) ≤ UInt256.ofNat n from ?_), ofNat_toNat_lt n (by omega)] - · show ¬ (32:ℕ) ≤ (UInt256.ofNat n).val.val - rw [show (UInt256.ofNat n).val.val = (UInt256.ofNat n).toNat from rfl, ofNat_toNat_lt n (by omega)]; omega - -theorem write_len_zero (src base : ByteArray) (sa da : ℕ) : src.write sa base da 0 = base := by - rw [ByteArray.write]; rfl - -theorem callerWrite_size (I : ExecutionEnv) (o : ByteArray) (L : ℕ) (hL : L ≤ 32) (hLo : L ≤ o.size) : - (o.write 0 (callerCalldataMem I) 128 L).size = 164 := by - rcases Nat.eq_zero_or_pos L with h | h - · subst h; rw [write_len_zero]; exact callerCalldataMem_size I - · rw [write_eq_gen o (callerCalldataMem I) 128 L (by omega) hLo (by rw [callerCalldataMem_size]; omega), - ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, ByteArray.size_extract, - ByteArray.size_extract, callerCalldataMem_size]; omega - -theorem callerWrite_read64 (I : ExecutionEnv) (o : ByteArray) (L : ℕ) (hL : L ≤ 32) (hLo : L ≤ o.size) : - (o.write 0 (callerCalldataMem I) 128 L).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by - rcases Nat.eq_zero_or_pos L with h | h - · subst h; rw [write_len_zero]; exact callerCalldataMem_read64 I - · rw [write_read_below_gen o (callerCalldataMem I) 128 L 64 (by omega) hLo - (by rw [callerCalldataMem_size]; omega) (by omega), callerCalldataMem_read64] - -theorem callerEvmSelector {cd : ByteArray} (hsz : 4 ≤ cd.size) : - UInt256.eq ⟨941609360⟩ - (UInt256.shiftRight (uInt256OfByteArray (cd.readBytes 0 32)) ⟨224⟩) - = if ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == cd.extract 0 4) then ⟨1⟩ else ⟨0⟩ := - evmSelectorDecode hsz 0x38 0x1f 0xd1 0x90 ⟨941609360⟩ (by decide) - -theorem callerX_callvalue_ne - {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue ≠ ⟨0⟩) : - RDrev callerBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact evm_run (solcGuardPrologueRD hcode (by decide) (by decide) (by decide) (by decide) - (by decide) (by decide)) with [ - push2 ⟨15⟩, - jumpiNT (isZero_eq_zero_of_ne hwv), - raw revertStub (by decide) (by decide) (by decide) (by evm_ov) ] - -theorem callerX_cvz_prefix - {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) : - RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨24⟩ - [⟨41⟩, UInt256.lt (UInt256.ofNat I.calldata.size) ⟨4⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) 14 53 := by - exact evm_run (solcGuardPrologueRD hcode (by decide) (by decide) (by decide) (by decide) - (by decide) (by decide)) with [ - push2 ⟨15⟩, - jumpiT (by rw [hwv]; decide) callerContains15, - jumpdest, pop, push1 ⟨4⟩, calldatasize, lt, push2 ⟨41⟩ ] - -abbrev callerSelWord (I : ExecutionEnv) : UInt256 := - UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes 0 32)) ⟨224⟩ - -abbrev callerFirstArmPc : UInt256 := ⟨30⟩ - -theorem callerArmWellFormed : armWellFormed callerBytecode callerFirstArmPc := - ⟨by decide, by decide, by decide, by decide, by decide, by decide⟩ - -theorem callerArmSelNat : armSelNat callerBytecode callerFirstArmPc = ⟨941609360⟩ := by decide - -theorem callerMatch_eq (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) : - UInt256.eq (armSelNat callerBytecode callerFirstArmPc) (callerSelWord I) - = if ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) then ⟨1⟩ else ⟨0⟩ := by - rw [callerArmSelNat]; exact callerEvmSelector hsz - -theorem callerReachBody {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hmatch : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) = true) : - ∃ k C, RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨45⟩ - [callerSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact solcDispatchReachBody - (firstArmPc := callerFirstArmPc) (bodyPC := ⟨45⟩) (i := 0) - hcode hwv hsz hsize (by solc_dispatch_prefix) (by jump_dest) - (fun j hj => by rw [Nat.le_zero.mp hj]; exact callerArmWellFormed) - (fun j hj => absurd hj (by omega)) - (by show UInt256.eq (armSelNat callerBytecode callerFirstArmPc) (callerSelWord I) ≠ ⟨0⟩ - rw [callerMatch_eq I hsz, if_pos hmatch]; decide) - (by jump_dest) (by decide) - -theorem callerX_cvz_short - {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) (hsz : I.calldata.size < 4) : - RDrev callerBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact evm_run (callerX_cvz_prefix hcode hwv) with [ - jumpiT (lt_four_ne_zero_of_lt hsz) callerContains41, - jumpdest, raw revertStub (by decide) (by decide) (by decide) (by evm_ov) ] - -theorem callerX_cvz_revertB - {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < Ethereum.UInt256.size) - (hmatch : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) = false) : - RDrev callerBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact evm_run (callerX_cvz_prefix hcode hwv) with [ - jumpiNT (lt_four_eq_zero_of_ge hsz hsize), - push0, calldataload, push1 ⟨224⟩, shr, dup1, push4 ⟨941609360⟩, eq, push2 ⟨45⟩, - jumpiNT (by rw [show ((⟨0⟩ : UInt256).toNat) = 0 from by decide, callerEvmSelector hsz]; - simp [hmatch]), - jumpdest, raw revertStub (by decide) (by decide) (by decide) (by evm_ov) ] - -theorem callerX_toDecoder {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hmatch : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) = true) : - ∃ k C, RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨348⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨66⟩, ⟨71⟩, - UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes 0 32)) ⟨224⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨k0, C0, rd0⟩ := callerReachBody (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (g := g) hcode hwv hsz hsize hmatch - have rd := evm_run rd0 with [ - jumpdest, push2 ⟨71⟩, push1 ⟨4⟩, dup1, calldatasize, sub, dup2, add, swap1, push2 ⟨66⟩, - swap2, swap1, push2 ⟨348⟩, - jump callerContains348 ] - rw [uadd_word_usub_ofNat_word (c := (⟨4⟩ : UInt256)) - (by rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide]; exact hsz) hsize] at rd - exact ⟨_, _, rd⟩ - -theorem callerX_dec277 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsz68 : 68 ≤ I.calldata.size) (hszhi : I.calldata.size < 2 ^ 255 + 4) - (hmatch : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) = true) : - ∃ k C, RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨277⟩ - [⟨4⟩ + ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨383⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, ⟨66⟩, ⟨71⟩, - UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes 0 32)) ⟨224⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = ⟨0⟩ := - solcDecodeLenCheckOk_4_64 hsz68 hszhi hsize - obtain ⟨k0, C0, rd0⟩ := callerX_toDecoder (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (g := g) hcode hwv hsz hsize hmatch - exact ⟨_, _, evm_run rd0 with [ - jumpdest, push0, push0, push1 ⟨64⟩, dup4, dup6, sub, slt, iszero, push2 ⟨370⟩, - jumpiT (by rw [hslt]; decide) caller_jd, - jumpdest, push0, push2 ⟨383⟩, dup6, dup3, dup7, add, push2 ⟨277⟩, - jump caller_jd ]⟩ - -theorem callerX_dec264 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsz68 : 68 ≤ I.calldata.size) (hszhi : I.calldata.size < 2 ^ 255 + 4) - (hmatch : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) = true) : - ∃ k C, RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨264⟩ - [UInt256.land (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ + ⟨0⟩ : UInt256).toNat 32)) addrMask, - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ + ⟨0⟩ : UInt256).toNat 32), - ⟨291⟩, uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ + ⟨0⟩ : UInt256).toNat 32), - ⟨4⟩ + ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨383⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, ⟨66⟩, ⟨71⟩, - UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes 0 32)) ⟨224⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨k, C, rd⟩ := callerX_dec277 hcode hwv hsz hsize hsz68 hszhi hmatch - exact ⟨_, _, evm_run rd with [ - jumpdest, push0, dup2, calldataload, swap1, pop, push2 ⟨291⟩, dup2, push2 ⟨255⟩, jump caller_jd, - jumpdest, push2 ⟨264⟩, dup2, push2 ⟨238⟩, jump caller_jd, - jumpdest, push0, push2 ⟨248⟩, dup3, push2 ⟨207⟩, jump caller_jd, - jumpdest, push0, push20 addrMask, dup3, and, swap1, pop, swap2, swap1, pop, jump caller_jd, - jumpdest, swap1, pop, swap2, swap1, pop, jump caller_jd ]⟩ - -theorem callerX_dec291 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsz68 : 68 ≤ I.calldata.size) (hszhi : I.calldata.size < 2 ^ 255 + 4) - (hmatch : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) = true) - (hclean : UInt256.eq (callerArg0 I) (UInt256.land (callerArg0 I) addrMask) = ⟨1⟩) : - ∃ k C, RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨291⟩ - [callerArg0 I, ⟨4⟩ + ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨383⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, ⟨66⟩, ⟨71⟩, - UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes 0 32)) ⟨224⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨k, C, rd⟩ := callerX_dec264 hcode hwv hsz hsize hsz68 hszhi hmatch - exact ⟨_, _, evm_run rd with [ - jumpdest, dup2, eq, push2 ⟨274⟩, jumpiT (by rw [hclean]; decide) caller_jd, - jumpdest, pop, jump caller_jd ]⟩ - -theorem callerDecode_n {I : ExecutionEnv} (hsz68 : 68 ≤ I.calldata.size) - (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanon : (callerArg0 I).toNat < EVM.addressModulus) : - decodeCalldata (runTransition.params.map Param.name) - (transitionSignature runTransition).paramTypes I.calldata - = some (((∅ : Solm.Store).insert "t" - (.address (Ethereum.AccountAddress.ofNat (callerArg0 I).toNat))).insert "n" - (.int (Int.ofNat (callerArg1 I).toNat))) := by - show decodeCalldata ["t", "n"] [addr, uint256] I.calldata = _ - simpa [addr, uint256, Pow.uint256, abiUInt256, calldataWord, callerArg0, callerArg1] - using decodeCalldata_addr_uint256_ok - (cd := I.calldata) (x := "t") (y := "n") hsz68 hbig hcanon - -theorem callerDecode_none_short {I : ExecutionEnv} (hsz4 : 4 ≤ I.calldata.size) - (hshort : I.calldata.size < 68) : - decodeCalldata (runTransition.params.map Param.name) - (transitionSignature runTransition).paramTypes I.calldata = none := by - show decodeCalldata ["t", "n"] [addr, uint256] I.calldata = none - simpa [addr, uint256, Pow.uint256, abiUInt256] - using decodeCalldata_addr_uint256_none_short - (cd := I.calldata) (x := "t") (y := "n") hsz4 hshort - -theorem callerDecode_none_noncanon {I : ExecutionEnv} (hsz68 : 68 ≤ I.calldata.size) - (hbig : I.calldata.size < 2 ^ 255 + 4) - (hnc : ¬ (callerArg0 I).toNat < EVM.addressModulus) : - decodeCalldata (runTransition.params.map Param.name) - (transitionSignature runTransition).paramTypes I.calldata = none := by - show decodeCalldata ["t", "n"] [addr, uint256] I.calldata = none - simpa [addr, uint256, Pow.uint256, abiUInt256, calldataWord, callerArg0] - using decodeCalldata_addr_uint256_none_noncanon - (cd := I.calldata) (x := "t") (y := "n") hsz68 hbig hnc - -theorem callerDecode_none_huge {I : ExecutionEnv} (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldata (runTransition.params.map Param.name) - (transitionSignature runTransition).paramTypes I.calldata = none := by - show decodeCalldata ["t", "n"] [addr, uint256] I.calldata = none - simpa [addr, uint256, Pow.uint256, abiUInt256] - using decodeCalldata_addr_uint256_none_huge - (cd := I.calldata) (x := "t") (y := "n") hbig - -theorem callerX_decoded {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsz68 : 68 ≤ I.calldata.size) (hszhi : I.calldata.size < 2 ^ 255 + 4) - (hmatch : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) = true) - (hclean : UInt256.eq (callerArg0 I) (UInt256.land (callerArg0 I) addrMask) = ⟨1⟩) : - ∃ k C, RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨66⟩ - [callerArg1 I, callerArg0 I, ⟨71⟩, - UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes 0 32)) ⟨224⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨k, C, rd⟩ := callerX_dec291 hcode hwv hsz hsize hsz68 hszhi hmatch hclean - exact ⟨_, _, evm_run rd with [ - jumpdest, swap3, swap2, pop, pop, jump caller_jd, - jumpdest, swap3, pop, pop, push1 ⟨32⟩, push2 ⟨400⟩, dup6, dup3, dup7, add, push2 ⟨328⟩, jump caller_jd, - jumpdest, push0, dup2, calldataload, swap1, pop, push2 ⟨342⟩, dup2, push2 ⟨306⟩, jump caller_jd, - jumpdest, push2 ⟨315⟩, dup2, push2 ⟨297⟩, jump caller_jd, - jumpdest, push0, dup2, swap1, pop, swap2, swap1, pop, jump caller_jd, - jumpdest, dup2, eq, push2 ⟨325⟩, jumpiT (by rw [ueq_self]; decide) caller_jd, - jumpdest, pop, jump caller_jd, - jumpdest, swap3, swap2, pop, pop, jump caller_jd, - jumpdest, swap2, pop, pop, swap3, pop, swap3, swap1, pop, jump caller_jd ]⟩ - -theorem callerArg0_canonical {I : ExecutionEnv} - (hclean : UInt256.eq (callerArg0 I) (UInt256.land (callerArg0 I) addrMask) = ⟨1⟩) : - (callerArg0 I).toNat < EVM.addressModulus := by - have heq : callerArg0 I = UInt256.land (callerArg0 I) addrMask := by - by_contra hne - simp only [UInt256.eq, UInt256.fromBool, Bool.toUInt256, hne, decide_false, Bool.false_eq_true, - ↓reduceIte] at hclean - exact absurd hclean (by decide) - have hlandle : ∀ a b : ℕ, Nat.land a b ≤ b := by - intro a b - refine Nat.le_of_testBit fun i hi => ?_ - change (a &&& b).testBit i = true at hi - rw [Nat.testBit_and] at hi - simp only [Bool.and_eq_true] at hi - exact hi.2 - have hland : (callerArg0 I).toNat - = Nat.land (callerArg0 I).toNat addrMask.toNat % EVM.twoPow 256 := by - conv_lhs => rw [heq] - rfl - have hmod : Nat.land (callerArg0 I).toNat addrMask.toNat % EVM.twoPow 256 - = Nat.land (callerArg0 I).toNat addrMask.toNat := - Nat.mod_eq_of_lt (lt_of_le_of_lt (hlandle _ _) (by decide)) - have hmask : addrMask.toNat < EVM.addressModulus := by decide - rw [hland, hmod]; exact lt_of_le_of_lt (hlandle _ _) hmask - -theorem land_mask160 (n : ℕ) (h : n < 2^160) : Nat.land n (2^160 - 1) = n := by - apply Nat.eq_of_testBit_eq; intro i - show (n &&& (2^160-1)).testBit i = n.testBit i - rw [Nat.testBit_and, Nat.testBit_two_pow_sub_one] - by_cases hi : i < 160 - · rw [decide_eq_true hi, Bool.and_true] - · rw [decide_eq_false hi, Bool.and_false] - have : n < 2^i := lt_of_lt_of_le h (Nat.pow_le_pow_right (by norm_num) (by omega)) - exact (Nat.testBit_lt_two_pow this).symm - -theorem callerCanon_eq {I : ExecutionEnv} (hcanon : (callerArg0 I).toNat < EVM.addressModulus) : - UInt256.eq (callerArg0 I) (UInt256.land (callerArg0 I) addrMask) = ⟨1⟩ := by - have hland : UInt256.land (callerArg0 I) addrMask = callerArg0 I := by - apply u256_inj - show Nat.land (callerArg0 I).toNat addrMask.toNat % EVM.twoPow 256 = (callerArg0 I).toNat - rw [show addrMask.toNat = 2 ^ 160 - 1 from by decide, - land_mask160 _ (by rw [show EVM.addressModulus = 2^160 from by decide] at hcanon; exact hcanon)] - exact Nat.mod_eq_of_lt (by - change (callerArg0 I).val.val < UInt256.size - exact (callerArg0 I).val.isLt) - rw [hland]; exact ueq_self (callerArg0 I) - -theorem callerX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hshort : I.calldata.size < 68) - (hmatch : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) = true) : - RDrev callerBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = ⟨1⟩ := - solcDecodeLenCheckShort_4_64 hsz hshort hsize - obtain ⟨k0, C0, rd0⟩ := callerX_toDecoder (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (g := g) hcode hwv hsz hsize hmatch - exact evm_run rd0 with [ - jumpdest, push0, push0, push1 ⟨64⟩, dup4, dup6, sub, slt, iszero, push2 ⟨370⟩, - jumpiNT (by rw [hslt]; decide), - push2 ⟨369⟩, push2 ⟨203⟩, jump callerContains203, - jumpdest, raw revertStub (by decide) (by decide) (by decide) (by evm_ov) ] - -theorem callerX_hugearg {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hmatch : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) = true) : - RDrev callerBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = ⟨1⟩ := - solcDecodeLenCheckHuge_4_64 hbig hsize - obtain ⟨k0, C0, rd0⟩ := callerX_toDecoder (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (g := g) hcode hwv hsz hsize hmatch - exact evm_run rd0 with [ - jumpdest, push0, push0, push1 ⟨64⟩, dup4, dup6, sub, slt, iszero, push2 ⟨370⟩, - jumpiNT (by rw [hslt]; decide), - push2 ⟨369⟩, push2 ⟨203⟩, jump callerContains203, - jumpdest, raw revertStub (by decide) (by decide) (by decide) (by evm_ov) ] - -theorem ueq_zero_of_ne {a b : UInt256} (h : ¬ UInt256.eq a b = ⟨1⟩) : UInt256.eq a b = ⟨0⟩ := by - by_cases hab : a = b - · subst hab; exact absurd (ueq_self a) h - · show UInt256.fromBool (decide (a = b)) = ⟨0⟩ - rw [decide_eq_false hab]; rfl - -theorem callerX_noncanon {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsz68 : 68 ≤ I.calldata.size) (hszhi : I.calldata.size < 2 ^ 255 + 4) - (hmatch : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) = true) - (hnc : UInt256.eq (callerArg0 I) (UInt256.land (callerArg0 I) addrMask) = ⟨0⟩) : - RDrev callerBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨k, C, rd⟩ := callerX_dec264 hcode hwv hsz hsize hsz68 hszhi hmatch - exact (evm_run rd with [ - jumpdest, dup2, eq, push2 ⟨274⟩, jumpiNT (by rw [hnc]), - raw revertStub (by decide) (by decide) (by decide) (by evm_ov) ] : - RDrev callerBytecode g (initState cA gh bl σ σ₀ g A I)) - -theorem store_get_empty (k : Ident) : (∅ : Solm.Store).get? k = none := by simp - -abbrev callerDecStore (I : ExecutionEnv) : Solm.Store := - ((∅:Solm.Store).insert "t" (.address (AccountAddress.ofNat (callerArg0 I).toNat))).insert "n" - (.int (Int.ofNat (callerArg1 I).toNat)) - -theorem callerStore_t (I : ExecutionEnv) : - (callerDecStore I).get? "t" = some (.address (AccountAddress.ofNat (callerArg0 I).toNat)) := by - rw [callerDecStore, store_get_ne _ _ (by decide), store_get_self] - -theorem callerStore_n (I : ExecutionEnv) : - (callerDecStore I).get? "n" = some (.int (Int.ofNat (callerArg1 I).toNat)) := by - rw [callerDecStore, store_get_self] - -theorem callerStore_stored_none (I : ExecutionEnv) : - (callerDecStore I).get? "stored" = none := by - rw [callerDecStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), store_get_empty] - -theorem callerStore_stored (I : ExecutionEnv) (v : Value) : - ((callerDecStore I).insert "tmp" v).get? "stored" = none := by - rw [store_get_ne _ _ (by decide), callerDecStore, store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_empty] - -private abbrev u3 : UInt256 := UInt256.ofNat 3 -private abbrev u6 : UInt256 := UInt256.ofNat 6 -private abbrev u66 : UInt256 := ⟨66⟩ -private abbrev u143 : UInt256 := ⟨142⟩ + ⟨1⟩ -private abbrev u144 : UInt256 := ⟨142⟩ + ⟨1⟩ + ⟨1⟩ - -private abbrev decodedStack (I : ExecutionEnv) (sel : UInt256) : List UInt256 := - [callerArg1 I, callerArg0 I, ⟨71⟩, sel] - -private abbrev postCallStack (I : ExecutionEnv) (sel : UInt256) (z : Bool) : List UInt256 := - (if z then ⟨1⟩ else ⟨0⟩) :: - ⟨164⟩ :: ⟨1143701499⟩ :: UInt256.land addrMask (callerArg0 I) :: - callerArg1 I :: callerArg0 I :: ⟨71⟩ :: sel :: [] - -private def cursorAt (pc : UInt256) (stack : List UInt256) (mem : ByteArray) (aw : UInt256) - (rdata : ByteArray) (world : Batteries.RBSet AccountAddress compare × AccountMap) : Cursor := - { pc := pc, stack := stack, mem := mem, aw := aw, rdata := rdata, world := world } - -def CallerEntryRel {cA : Batteries.RBSet AccountAddress compare} {gh : BlockHeader} {bl : ProcessedBlocks} - {σ σ₀ : AccountMap} {A : Substate} (I : ExecutionEnv) (g : Sat256) - (sel : UInt256) : StateRel := - fun cur frame evm => - evm = initState cA gh bl σ σ₀ g A I ∧ - cur.stack = decodedStack I sel ∧ - cur.mem = solcFreePtrMem ∧ cur.aw = u3 ∧ cur.rdata = ByteArray.empty ∧ - frame.contract = Caller.callerContract ∧ - frame.locals.get? "t" = - some (.address (AccountAddress.ofNat (callerArg0 I).toNat)) ∧ - frame.locals.get? "n" = some (.int (Int.ofNat (callerArg1 I).toNat)) ∧ - frame.locals.get? "stored" = none - -def CallerPostCallRel {cA : Batteries.RBSet AccountAddress compare} {gh : BlockHeader} {bl : ProcessedBlocks} - {σ σ₀ : AccountMap} {A : Substate} (I : ExecutionEnv) (g : Sat256) - (sel : UInt256) (z : Bool) (o : ByteArray) : StateRel := - fun cur frame evm => - ∃ cA' σ' A', - evm = { initState cA gh bl σ σ₀ g A I with - accountMap := σ', substate := A', createdAccounts := cA' } ∧ - cur.stack = postCallStack I sel z ∧ - cur.mem = (o.write 0 (callerCalldataMem I) 128 - (min (⟨32⟩ : UInt256) (UInt256.ofNat o.size)).toNat) ∧ - cur.aw = u6 ∧ cur.rdata = o ∧ cur.world = worldOf evm ∧ - typedCallViaEVM callerConfig (initState cA gh bl σ σ₀ g A I) - (EVM.address (AccountAddress.ofNat (callerArg0 I).toNat)) "pow2" 0 - [.int (Int.ofNat (callerArg1 I).toNat)] (z, evm, o) ∧ - frame.contract = Caller.callerContract ∧ - frame.locals.get? "t" = - some (.address (AccountAddress.ofNat (callerArg0 I).toNat)) ∧ - frame.locals.get? "n" = some (.int (Int.ofNat (callerArg1 I).toNat)) - -def CallerAssignRel {cA : Batteries.RBSet AccountAddress compare} {gh : BlockHeader} - {bl : ProcessedBlocks} {σ σ₀ : AccountMap} {A : Substate} - (I : ExecutionEnv) (g : Sat256) (sel : UInt256) (o : ByteArray) : StateRel := - fun cur frame evm => - ∃ cA' σ' A' kw, - 32 ≤ o.size ∧ o.size < 2 ^ 255 ∧ - kw = fromByteArrayBigEndian (o.extract 0 32) ∧ - evm = { initState cA gh bl σ σ₀ g A I with - accountMap := σ', substate := A', createdAccounts := cA' } ∧ - cur.stack = postCallStack I sel true ∧ - cur.mem = (o.write 0 (callerCalldataMem I) 128 32) ∧ - cur.aw = u6 ∧ cur.rdata = o ∧ cur.world = worldOf evm ∧ - frame.contract = Caller.callerContract ∧ - frame.locals.get? "tmp" = some (.int (Int.ofNat kw)) ∧ - frame.locals.get? "stored" = none - -def CallerBodyPost (code : ByteArray) (g : Sat256) (s0 : State) : StmtPost - | .ok _ evm' => - ∃ o, RDret code g s0 (worldOf evm') o ∧ returnEquiv o none [] - | .reverted => - RDrev code g s0 - | .returned _ _ _ | .break _ _ | .continue _ _ => - False - -/-- Body code from decoded arguments at pc 66 to the `GAS` opcode immediately before `CALL`. -/ -theorem callerX_toCall142_from66 {I : ExecutionEnv} {g : Sat256} {s0 : State} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} {sel : UInt256} - (rd : RD callerBytecode I g s0 u66 (decodedStack I sel) solcFreePtrMem u3 ByteArray.empty acc k C) : - ∃ k' C', RD callerBytecode I g s0 ⟨142⟩ - [UInt256.land addrMask (callerArg0 I), ⟨0⟩, callerOutPtr I, - UInt256.sub ⟨164⟩ (callerOutPtr I), callerOutPtr I, ⟨32⟩, ⟨164⟩, - ⟨1143701499⟩, UInt256.land addrMask (callerArg0 I), - callerArg1 I, callerArg0 I, ⟨71⟩, sel] - (callerCalldataMem I) u6 ByteArray.empty acc k' C' := by - refine ⟨_, _, evm_run rd with [ - jumpdest, push2 ⟨73⟩, jump caller_jd, - jumpdest, dup2, push20 addrMask, and, push4 ⟨1143701499⟩, dup3, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ u3 (by decide) - mem_cost - solcFreePtrMem_mload64 - (by decide) (by evm_ov), - dup3, push4 ⟨4294967295⟩, and, push1 ⟨224⟩, shl, dup2, - raw mstore 6 callerSelMem (UInt256.ofNat 5) (by decide) - mem_cost - (by rfl) (by decide) (by evm_ov), - push1 ⟨4⟩, add, push2 ⟨130⟩, swap2, swap1, push2 ⟨425⟩, jump caller_jd, - jumpdest, push0, push1 ⟨32⟩, dup3, add, swap1, pop, push2 ⟨444⟩, push0, dup4, add, dup5, - push2 ⟨410⟩, jump caller_jd, - jumpdest, push2 ⟨419⟩, dup2, push2 ⟨297⟩, jump caller_jd, - jumpdest, push0, dup2, swap1, pop, swap2, swap1, pop, jump caller_jd, - jumpdest, dup3, - raw mstore 3 (callerCalldataMem I) u6 (by decide) - mem_cost - (by rfl) (by decide) (by evm_ov), - pop, pop, jump caller_jd, - jumpdest, swap3, swap2, pop, pop, jump caller_jd, - jumpdest, push1 ⟨32⟩, push1 ⟨64⟩, - raw mload 0 (callerOutPtr I) u6 (by decide) - mem_cost - (by rfl) (by decide) (by evm_ov), - dup1, dup4, sub, dup2, push0, dup8 ]⟩ - -/-- Extract the concrete initial world from a coupled decoded-entry state. -/ -theorem callerEntryWorld {cA : Batteries.RBSet AccountAddress compare} {gh : BlockHeader} - {bl : ProcessedBlocks} {σ σ₀ : AccountMap} {A : Substate} - {I : ExecutionEnv} {g : Sat256} {sel : UInt256} - (st : CoupledState callerBytecode I g (initState cA gh bl σ σ₀ g A I) - (CallerEntryRel (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - I g sel) u66) : - st.cur.world = (cA, σ) := by - rcases st.hrel with ⟨hevm, _⟩ - rw [st.hworld, hevm] - rfl - -/- The opaque `CALL` package from the decoded body entry. - - This is the compositional boundary for Caller: all setup before the `CALL`, the `CALL` itself, - the `RD.call` active-word/memory normalization, the `typedCallViaEVM` coincidence, and the - return-data size bound are hidden behind one lemma. Post-call proof chunks can consume the - returned cursor without redoing the call bridge. -/ -set_option maxHeartbeats 4000000 in -theorem callerX_postCall_from66 {cA : Batteries.RBSet AccountAddress compare} - {gh : BlockHeader} {bl : ProcessedBlocks} {σ σ₀ : AccountMap} {A : Substate} - {I : ExecutionEnv} {g : Sat256} {sel : UInt256} {k C : ℕ} - (hperm : I.perm = true) (hdepth : I.depth.val < 1024) - (hclean : UInt256.eq (callerArg0 I) - (UInt256.land (callerArg0 I) addrMask) = ⟨1⟩) - (rd66 : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) u66 - (decodedStack I sel) solcFreePtrMem u3 ByteArray.empty (cA, σ) k C) : - ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) - (o : ByteArray) (A' : Substate) (k' C' : ℕ), - RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) u144 - (postCallStack I sel z) - (o.write 0 (callerCalldataMem I) 128 - (min (⟨32⟩ : UInt256) (UInt256.ofNat o.size)).toNat) - u6 o (cA', σ') k' C' - ∧ typedCallViaEVM callerConfig (initState cA gh bl σ σ₀ g A I) - (EVM.address (AccountAddress.ofNat (callerArg0 I).toNat)) "pow2" 0 - [.int (Int.ofNat (callerArg1 I).toNat)] - (z, { initState cA gh bl σ σ₀ g A I with - accountMap := σ', substate := A', createdAccounts := cA' }, o) - ∧ o.size < UInt256.size := by - obtain ⟨k142, C142, rd142⟩ := callerX_toCall142_from66 rd66 - obtain ⟨gv, rd143⟩ := rd142.gas (by decide) (by evm_ov) - obtain ⟨cA', σ', z, o, A_in, callGas, k144, C144, hΘpack, rd144raw, hosz⟩ := - rd143.call (by decide) hdepth (by evm_ov) - obtain ⟨g'', A', hΘ⟩ := hΘpack - refine ⟨cA', σ', z, o, A', k144, C144, ?_, ?_, ?_⟩ - · have haw : UInt256.ofNat (MachineState.M (MachineState.M (UInt256.ofNat 6).toNat - (callerOutPtr I).toNat (UInt256.sub ⟨164⟩ (callerOutPtr I)).toNat) - (callerOutPtr I).toNat (⟨32⟩ : UInt256).toNat) = u6 := by - rw [callerOutPtr_eq] - decide - have hoff : (callerOutPtr I).toNat = 128 := by - rw [callerOutPtr_eq] - decide - have rd144aw : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) u144 - (postCallStack I sel z) - (o.write 0 (callerCalldataMem I) (callerOutPtr I).toNat - (min (⟨32⟩ : UInt256) (UInt256.ofNat o.size)).toNat) - u6 o (cA', σ') k144 C144 := - haw ▸ rd144raw - rw [hoff] at rd144aw - exact rd144aw - · refine callCoincides (A_in := A_in) (g'' := g'') (callGas := callGas) (callPerm := true) - (targetWord := UInt256.land addrMask (callerArg0 I)) - (mem := callerCalldataMem I) (inOff := callerOutPtr I) - (inSize := UInt256.sub ⟨164⟩ (callerOutPtr I)) - (fun h => absurd hdepth (by rw [show I.depth = (1024 : Fin 1025) from h]; decide)) - (callerTarget_eq hclean) ?_ ?_ - rw [show (callerOutPtr I).toNat = 128 from by rw [callerOutPtr_eq]; decide, - show (UInt256.sub ⟨164⟩ (callerOutPtr I)).toNat = 36 from by - rw [callerOutPtr_eq]; decide] - exact callerEncode_eq I - simpa [initState, hperm] using hΘ - · exact hosz - -theorem callerX_postRevert {cA gh bl σ σ₀ A I} {g : Sat256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {k C : ℕ} {rest : List UInt256} - (rd : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) (⟨142⟩ + ⟨1⟩ + ⟨1⟩) - (⟨0⟩ :: rest) mem aw rdata acc k C) - (hov : rest.length + 4 ≤ 1024) : - RDrev callerBytecode g (initState cA gh bl σ σ₀ g A I) := by - have rd151 : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) - (⟨142⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩) - (UInt256.isZero ⟨0⟩ :: rest) mem aw rdata acc _ _ := - evm_run rd with [iszero, dup1, iszero, push2 ⟨158⟩, jumpiNT (by decide)] - obtain ⟨mem2, aw2, k2, C2, rd155⟩ := - RD.returndatacopyFull rd151 (by decide) (by decide) (by decide) (by decide) - (by simp only [List.length_cons]; omega) - have rd156 := RD.returndatasize rd155 (by decide) (by simp only [List.length_cons]; omega) - have rd157 := RD.push0 rd156 (by decide) (by simp only [List.length_cons]; omega) - exact RD.rev _ rd157 (by decide) - (fun s haws hstks => by rw [memExpRevertZeroOff s hstks, haws]) - (by simp only [List.length_cons]; omega) - -theorem callerX_succ_to165 {cA gh bl σ σ₀ A I} {g : Sat256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {k C : ℕ} - {d0 d1 d2 : UInt256} {tl : List UInt256} - (rd : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) (⟨142⟩ + ⟨1⟩ + ⟨1⟩) - (⟨1⟩ :: d0 :: d1 :: d2 :: tl) mem aw rdata acc k C) - (hov : tl.length + 7 ≤ 1024) : - ∃ k' C', RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨165⟩ - (⟨64⟩ :: tl) mem aw rdata acc k' C' := by - refine ⟨_, _, evm_run rd with [iszero, dup1, iszero, push2 ⟨158⟩, - jumpiT (by decide) callerContains158, jumpdest, pop, pop, pop, pop, push1 ⟨64⟩]⟩ - -noncomputable def callerMem2 (o mem : ByteArray) : ByteArray := - (UInt256.add ⟨128⟩ (UInt256.land (UInt256.add (UInt256.ofNat o.size) ⟨31⟩) - (UInt256.lnot ⟨31⟩))).toByteArray.write 0 mem 64 32 - -theorem callerX_succ_to470 {cA gh bl σ σ₀ A I} {g : Sat256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem : ByteArray} {o : ByteArray} {k C : ℕ} {arg1 arg0 sel : UInt256} - (rd : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨165⟩ - [⟨64⟩, arg1, arg0, ⟨71⟩, sel] mem ⟨6⟩ o acc k C) - (hfp : (if (⟨64⟩ : UInt256).toNat ≥ mem.size ∨ (⟨64⟩ : UInt256) ≥ ⟨6⟩ * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat (fromByteArrayBigEndian (mem.readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩) : - ∃ k' C', RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨470⟩ - [⟨128⟩, UInt256.add ⟨128⟩ (UInt256.ofNat o.size), ⟨194⟩, arg1, arg0, ⟨71⟩, sel] - (callerMem2 o mem) ⟨6⟩ o acc k' C' := by - refine ⟨_, _, evm_run rd with [ - raw mload 0 ⟨128⟩ ⟨6⟩ (by decide) - mem_cost - hfp (by decide) (by evm_ov), - returndatasize, - push1 ⟨31⟩, not, push1 ⟨31⟩, dup3, add, and, dup3, add, dup1, push1 ⟨64⟩, - raw mstore 0 ((UInt256.add ⟨128⟩ (UInt256.land (UInt256.add (UInt256.ofNat o.size) ⟨31⟩) - (UInt256.lnot ⟨31⟩))).toByteArray.write 0 mem 64 32) ⟨6⟩ (by decide) - mem_cost - (by rfl) (by decide) (by evm_ov), - pop, dup2, add, swap1, push2 ⟨194⟩, swap2, swap1, push2 ⟨470⟩, jump callerContains470 ]⟩ - -theorem callerX_succ_to491 {cA gh bl σ σ₀ A I} {g : Sat256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem2 : ByteArray} {o : ByteArray} {k C : ℕ} {arg1 arg0 sel : UInt256} - (rd : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨470⟩ - [⟨128⟩, UInt256.add ⟨128⟩ (UInt256.ofNat o.size), ⟨194⟩, arg1, arg0, ⟨71⟩, sel] - mem2 ⟨6⟩ o acc k C) - (ho32 : 32 ≤ o.size) (ho : o.size < 2 ^ 255) : - ∃ k' C', RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨491⟩ - [⟨0⟩, ⟨128⟩, UInt256.add ⟨128⟩ (UInt256.ofNat o.size), ⟨194⟩, arg1, arg0, ⟨71⟩, sel] - mem2 ⟨6⟩ o acc k' C' := by - refine ⟨_, _, evm_run rd with [ - jumpdest, push0, push1 ⟨32⟩, dup3, dup5, sub, slt, iszero, push2 ⟨491⟩, - jumpiT (by rw [solcDecodeEndLenCheckOk_128_32 ho32 ho]; decide) callerContains491 ]⟩ - -theorem callerX_succ_revert {cA gh bl σ σ₀ A I} {g : Sat256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem2 : ByteArray} {o : ByteArray} {k C : ℕ} {arg1 arg0 sel : UInt256} - (rd : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨470⟩ - [⟨128⟩, UInt256.add ⟨128⟩ (UInt256.ofNat o.size), ⟨194⟩, arg1, arg0, ⟨71⟩, sel] - mem2 ⟨6⟩ o acc k C) - (ho : o.size < 32) : - RDrev callerBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact evm_run rd with [ - jumpdest, push0, push1 ⟨32⟩, dup3, dup5, sub, slt, iszero, push2 ⟨491⟩, - jumpiNT (by rw [solcDecodeEndLenCheckShort_128_32 ho]; decide), - push2 ⟨490⟩, push2 ⟨203⟩, jump callerContains203, - jumpdest, raw revertStub (by decide) (by decide) (by decide) (by evm_ov) ] - -theorem callerX_succ_revert_huge {cA gh bl σ σ₀ A I} {g : Sat256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem2 : ByteArray} {o : ByteArray} {k C : ℕ} {arg1 arg0 sel : UInt256} - (rd : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨470⟩ - [⟨128⟩, UInt256.add ⟨128⟩ (UInt256.ofNat o.size), ⟨194⟩, arg1, arg0, ⟨71⟩, sel] - mem2 ⟨6⟩ o acc k C) - (hhi : 2 ^ 255 ≤ o.size) (hlo : o.size < UInt256.size) : - RDrev callerBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact evm_run rd with [ - jumpdest, push0, push1 ⟨32⟩, dup3, dup5, sub, slt, iszero, push2 ⟨491⟩, - jumpiNT (by rw [solcDecodeEndLenCheckHuge_128_32 hhi hlo]; decide), - push2 ⟨490⟩, push2 ⟨203⟩, jump callerContains203, - jumpdest, raw revertStub (by decide) (by decide) (by decide) (by evm_ov) ] - -theorem callerX_succ_tail {cA gh bl σ σ₀ A I} {g : Sat256} - {cAx : Batteries.RBSet AccountAddress compare} {σx : AccountMap} - {mem2 : ByteArray} {o : ByteArray} {k C : ℕ} {arg1 arg0 sel : UInt256} - (rd : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨491⟩ - [⟨0⟩, ⟨128⟩, UInt256.add ⟨128⟩ (UInt256.ofNat o.size), ⟨194⟩, arg1, arg0, ⟨71⟩, sel] - mem2 ⟨6⟩ o (cAx, σx) k C) - (hperm : I.perm = true) - (hword : mem2.readWithPadding 128 32 = o.extract 0 32) - (hsize2 : 128 < mem2.size) : - RDret callerBytecode g (initState cA gh bl σ σ₀ g A I) - (cAx, sstoreAccountMap I.codeOwner σx ⟨0⟩ - (UInt256.ofNat (fromByteArrayBigEndian (o.extract 0 32)))) - ByteArray.empty := by - have rd198 := evm_run rd with [ - jumpdest, push0, push2 ⟨504⟩, dup5, dup3, dup6, add, push2 ⟨450⟩, jump callerContains450, - jumpdest, push0, dup2, - raw mload 0 (UInt256.ofNat (fromByteArrayBigEndian (o.extract 0 32))) ⟨6⟩ (by decide) - mem_cost - (by - have h128 : ((⟨128⟩ : UInt256) + ⟨0⟩).toNat = 128 := by decide - split_ifs with h - · exfalso; rcases h with h | h - · rw [h128] at h; omega - · exact absurd h (by decide) - · rw [h128, hword]) - (by decide) (by evm_ov), - swap1, pop, push2 ⟨464⟩, dup2, push2 ⟨306⟩, jump callerContains306, - jumpdest, push2 ⟨315⟩, dup2, push2 ⟨297⟩, jump callerContains297, - jumpdest, push0, dup2, swap1, pop, swap2, swap1, pop, jump callerContains315, - jumpdest, dup2, eq, push2 ⟨325⟩, jumpiT (by rw [ueq_self]; decide) callerContains325, - jumpdest, pop, jump callerContains464, - jumpdest, swap3, swap2, pop, pop, jump callerContains504, - jumpdest, swap2, pop, pop, swap3, swap2, pop, pop, jump callerContains194, - jumpdest, push0, dup2, swap1 ] - obtain ⟨k', C', rd199⟩ := rd198.sstore hperm (by decide) (by evm_ov) - exact RD.stop (evm_run rd199 with [pop, pop, pop, jump callerContains71, jumpdest]) - (by decide) (by evm_ov) - -theorem callerX_successChain {cA gh bl σ σ₀ A I} {g : Sat256} - {cAx : Batteries.RBSet AccountAddress compare} {σx : AccountMap} - {mem : ByteArray} {o : ByteArray} {k C : ℕ} {arg1 arg0 sel d0 d1 d2 : UInt256} - (rd144 : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) (⟨142⟩ + ⟨1⟩ + ⟨1⟩) - (⟨1⟩ :: d0 :: d1 :: d2 :: arg1 :: arg0 :: ⟨71⟩ :: sel :: []) mem ⟨6⟩ o (cAx, σx) k C) - (hperm : I.perm = true) (ho32 : 32 ≤ o.size) (ho : o.size < 2 ^ 255) - (hfp : (if (⟨64⟩ : UInt256).toNat ≥ mem.size ∨ (⟨64⟩ : UInt256) ≥ ⟨6⟩ * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat (fromByteArrayBigEndian (mem.readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩) - (hword : mem.readWithPadding 128 32 = o.extract 0 32) (hmsz : 160 ≤ mem.size) : - RDret callerBytecode g (initState cA gh bl σ σ₀ g A I) - (cAx, sstoreAccountMap I.codeOwner σx ⟨0⟩ - (UInt256.ofNat (fromByteArrayBigEndian (o.extract 0 32)))) - ByteArray.empty := by - obtain ⟨k1, C1, rd165⟩ := callerX_succ_to165 rd144 (by simp) - obtain ⟨k2, C2, rd470⟩ := callerX_succ_to470 rd165 hfp - obtain ⟨k3, C3, rd491⟩ := callerX_succ_to491 rd470 ho32 ho - have hword2 : (callerMem2 o mem).readWithPadding 128 32 = o.extract 0 32 := by - rw [callerMem2, write32_read_above _ _ 64 128 (by rw [toByteArray_size]) (by omega) - (by omega) (by omega), hword] - have hmsz2 : 128 < (callerMem2 o mem).size := by - rw [callerMem2, write32_eq _ _ _ (by rw [toByteArray_size]) (by omega), - ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, ByteArray.size_extract, - ByteArray.size_extract, toByteArray_size] - omega - exact callerX_succ_tail rd491 hperm hword2 hmsz2 - -def CallerExternalPost {cA : Batteries.RBSet AccountAddress compare} {gh : BlockHeader} - {bl : ProcessedBlocks} {σ σ₀ : AccountMap} {A : Substate} - (I : ExecutionEnv) (g : Sat256) (s0 : State) (sel : UInt256) : StmtPost - | .ok frame' evm' => - ∃ o cur' k' C', - cur'.pc = u144 ∧ RDc callerBytecode I g s0 cur' k' C' ∧ - cur'.world = worldOf evm' ∧ CallerAssignRel (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) I g sel o cur' frame' evm' - | .reverted => - RDrev callerBytecode g s0 - | .returned _ _ _ | .break _ _ | .continue _ _ => - False - -set_option maxHeartbeats 3000000 in -/-- Coupled proof chunk for the opaque external call in `Caller.run`. - - The pre-call bytecode prefix and `RD.call` bridge are factored through - `callerX_postCall_from66`. On call failure or ABI-decode failure the statement reverts and the - matching EVM path is discharged immediately; on decode success the postcondition exposes the - reached post-call cursor with `tmp` bound, ready for the storage-assignment chunk. -/ -theorem callerCoupled_externalCall {cA : Batteries.RBSet AccountAddress compare} - {gh : BlockHeader} {bl : ProcessedBlocks} {σ σ₀ : AccountMap} {A : Substate} - {I : ExecutionEnv} {g : Sat256} {sel : UInt256} - (hperm : I.perm = true) (hdepth : I.depth.val < 1024) - (hclean : UInt256.eq (callerArg0 I) - (UInt256.land (callerArg0 I) addrMask) = ⟨1⟩) : - ∀ st : CoupledState callerBytecode I g (initState cA gh bl σ σ₀ g A I) - (CallerEntryRel (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - I g sel) u66, - CoupledState.refines st callerConfig - [.externalCall (.var "t") "pow2" (.intLit 0) [.var "n"] "tmp"] - (CallerExternalPost (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) I g (initState cA gh bl σ σ₀ g A I) sel) := by - intro st - rcases st.hrel with ⟨hevm, hstack, hmem, haw, hrdata, hcontract, ht, hn, hstored⟩ - have hworld0 : st.cur.world = (cA, σ) := callerEntryWorld st - have rd66cur := st.toRD hstack hmem haw hrdata - have rd66 : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) u66 - (decodedStack I sel) solcFreePtrMem u3 ByteArray.empty (cA, σ) st.k st.C := by - rw [hworld0] at rd66cur - exact rd66cur - obtain ⟨cA', σ', z, o, A', k144, C144, rd144, hcoin, ho255⟩ := - callerX_postCall_from66 (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) (sel := sel) hperm hdepth hclean rd66 - have hrec : evalExpr? callerConfig st.frame st.evm (.var "t") - = .ok (.address (AccountAddress.ofNat (callerArg0 I).toNat)) := by - simp only [evalExpr?, EvalResult.ofOption, ht] - have heth : evalExpr? callerConfig st.frame st.evm (.intLit 0) = .ok (.int 0) := by - simp only [evalExpr?] - rfl - have hargs : evalExprs? callerConfig st.frame st.evm [.var "n"] - = .ok [.int (Int.ofNat (callerArg1 I).toNat)] := by - simp only [evalExprs?, evalExpr?, EvalResult.ofOption, hn, EvalResult.bind, bind, pure] - cases z - · refine CoupledState.refines.externalCallFailure st ?_ ?_ - · refine ⟨AccountAddress.ofNat (callerArg0 I).toNat, 0, - [.int (Int.ofNat (callerArg1 I).toNat)], - { initState cA gh bl σ σ₀ g A I with - accountMap := σ', substate := A', createdAccounts := cA' }, - o, hrec, heth, hargs, ?_⟩ - rw [hevm] - exact hcoin - · exact callerX_postRevert rd144 (by simp) - · by_cases ho32 : 32 ≤ o.size - · by_cases hoSmall : o.size < 2 ^ 255 - · set kw := fromByteArrayBigEndian (o.extract 0 32) with hkw - have hdec : callerConfig.externalABI.decode? "pow2" o = - some [(.int (Int.ofNat kw))] := by - show defaultDecodeReturn? "pow2" o = _ - simpa [defaultDecodeReturn?, ← hkw, Int.ofNat_eq_natCast] using - decodeReturnValues_uint256_ok (returndata := o) ho32 hoSmall - have hmem32 : o.write 0 (callerCalldataMem I) 128 - (min (⟨32⟩ : UInt256) (UInt256.ofNat o.size)).toNat = - o.write 0 (callerCalldataMem I) 128 32 := by - rw [callerL_succ o.size ho32 ho255] - rw [hmem32] at rd144 - set evmP : State := { initState cA gh bl σ σ₀ g A I with - accountMap := σ', substate := A', createdAccounts := cA' } with hevmP - set frameP : Frame := { st.frame with - locals := st.frame.locals.insert "tmp" (.int (Int.ofNat kw)) } with hframeP - have hcallSt : typedCallViaEVM callerConfig st.evm - (EVM.address (AccountAddress.ofNat (callerArg0 I).toNat)) "pow2" 0 - [.int (Int.ofNat (callerArg1 I).toNat)] (true, evmP, o) := by - rw [hevm, hevmP] - exact hcoin - have hstmt : ExecStmt callerConfig st.frame st.evm - (.externalCall (.var "t") "pow2" (.intLit 0) [.var "n"] "tmp") - (.ok frameP evmP) := by - rw [hframeP] - exact ExecStmt.externalCallSuccess hrec heth hargs hcallSt hdec - let cur144 : Cursor := cursorAt u144 (postCallStack I sel true) - (o.write 0 (callerCalldataMem I) 128 32) u6 o (cA', σ') - have hrdc : RDc callerBytecode I g (initState cA gh bl σ σ₀ g A I) cur144 k144 C144 := by - change RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) cur144.pc - cur144.stack cur144.mem cur144.aw cur144.rdata cur144.world k144 C144 - exact rd144 - have hwcur : cur144.world = worldOf evmP := by - rw [hevmP] - rfl - have hrel : CallerAssignRel (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) I g sel o cur144 frameP evmP := by - refine ⟨cA', σ', A', kw, ho32, hoSmall, hkw, ?_, rfl, rfl, rfl, rfl, ?_, ?_, ?_, ?_⟩ - · rw [hevmP] - · rw [hevmP] - rfl - · rw [hframeP] - exact hcontract - · rw [hframeP, store_get_self] - · rw [hframeP, store_get_ne _ _ (by decide), hstored] - exact ⟨.ok frameP evmP, ExecBlock.consNormal hstmt ExecBlock.nil, - o, cur144, k144, C144, rfl, hrdc, hwcur, hrel⟩ - · rw [not_lt] at hoSmall - have hdecn : callerConfig.externalABI.decode? "pow2" o = none := by - show defaultDecodeReturn? "pow2" o = none - simpa [defaultDecodeReturn?] using - decodeReturnValues_uint256_none_huge (returndata := o) hoSmall - have hmem32 : o.write 0 (callerCalldataMem I) 128 - (min (⟨32⟩ : UInt256) (UInt256.ofNat o.size)).toNat = - o.write 0 (callerCalldataMem I) 128 32 := by - rw [callerL_succ o.size ho32 ho255] - rw [hmem32] at rd144 - have hfp : (if (⟨64⟩ : UInt256).toNat ≥ - (o.write 0 (callerCalldataMem I) 128 32).size - ∨ (⟨64⟩ : UInt256) ≥ ⟨6⟩ * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat (fromByteArrayBigEndian - ((o.write 0 (callerCalldataMem I) 128 32).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨128⟩ := by - exact mloadFreePtrValue - (by rw [callerWrite_size I o 32 (by omega) ho32]; decide) - (by decide) (callerWrite_read64 I o 32 (by omega) ho32) - obtain ⟨k165, C165, rd165⟩ := callerX_succ_to165 rd144 (by simp) - obtain ⟨k470, C470, rd470⟩ := callerX_succ_to470 rd165 hfp - refine CoupledState.refines.externalCallDecodeRevert st ?_ ?_ - · refine ⟨AccountAddress.ofNat (callerArg0 I).toNat, 0, - [.int (Int.ofNat (callerArg1 I).toNat)], - { initState cA gh bl σ σ₀ g A I with - accountMap := σ', substate := A', createdAccounts := cA' }, - o, hrec, heth, hargs, ?_, hdecn⟩ - rw [hevm] - exact hcoin - · exact callerX_succ_revert_huge rd470 hoSmall ho255 - · rw [not_le] at ho32 - have hdecn : callerConfig.externalABI.decode? "pow2" o = none := by - show defaultDecodeReturn? "pow2" o = none - simpa [defaultDecodeReturn?] using - decodeReturnValues_uint256_none_short (returndata := o) ho32 - rw [callerL_rev o.size ho32] at rd144 - have hfp : (if (⟨64⟩ : UInt256).toNat ≥ - (o.write 0 (callerCalldataMem I) 128 o.size).size - ∨ (⟨64⟩ : UInt256) ≥ ⟨6⟩ * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat (fromByteArrayBigEndian - ((o.write 0 (callerCalldataMem I) 128 o.size).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨128⟩ := by - exact mloadFreePtrValue - (by rw [callerWrite_size I o o.size (by omega) (by omega)]; decide) - (by decide) (callerWrite_read64 I o o.size (by omega) (by omega)) - obtain ⟨k165, C165, rd165⟩ := callerX_succ_to165 rd144 (by simp) - obtain ⟨k470, C470, rd470⟩ := callerX_succ_to470 rd165 hfp - refine CoupledState.refines.externalCallDecodeRevert st ?_ ?_ - · refine ⟨AccountAddress.ofNat (callerArg0 I).toNat, 0, - [.int (Int.ofNat (callerArg1 I).toNat)], - { initState cA gh bl σ σ₀ g A I with - accountMap := σ', substate := A', createdAccounts := cA' }, - o, hrec, heth, hargs, ?_, hdecn⟩ - rw [hevm] - exact hcoin - · exact callerX_succ_revert rd470 ho32 - -set_option maxHeartbeats 3000000 in -/-- Coupled proof chunk for the post-call storage assignment and the remaining bytecode tail. -/ -theorem callerCoupled_assignReturn {cA : Batteries.RBSet AccountAddress compare} - {gh : BlockHeader} {bl : ProcessedBlocks} {σ σ₀ : AccountMap} {A : Substate} - {I : ExecutionEnv} {g : Sat256} {sel : UInt256} {o : ByteArray} - (hperm : I.perm = true) : - ∀ st : CoupledState callerBytecode I g (initState cA gh bl σ σ₀ g A I) - (CallerAssignRel (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - I g sel o) u144, - CoupledState.refines st callerConfig - [.assign .storage { base := "stored", steps := [] } (.var "tmp")] - (CallerBodyPost callerBytecode g (initState cA gh bl σ σ₀ g A I)) := by - intro st - rcases st.hrel with - ⟨cA', σ', A', kw, ho32, ho255, hkw, hevm, hstack, hmem, haw, hrdata, hwrel, - hcontract, htmp, hstored⟩ - have hacc : st.cur.world = (cA', σ') := by - rw [st.hworld, hevm] - rfl - have rd144cur := st.toRD hstack hmem haw hrdata - have rd144 : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) u144 - (postCallStack I sel true) (o.write 0 (callerCalldataMem I) 128 32) u6 o - (cA', σ') st.k st.C := by - rw [hacc] at rd144cur - exact rd144cur - have hmsz : 160 ≤ (o.write 0 (callerCalldataMem I) 128 32).size := by - have := callerWrite_size I o 32 (by omega) ho32 - omega - have hfp : (if (⟨64⟩ : UInt256).toNat ≥ - (o.write 0 (callerCalldataMem I) 128 32).size - ∨ (⟨64⟩ : UInt256) ≥ ⟨6⟩ * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat (fromByteArrayBigEndian - ((o.write 0 (callerCalldataMem I) 128 32).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨128⟩ := by - exact mloadFreePtrValue - (by rw [callerWrite_size I o 32 (by omega) ho32]; decide) - (by decide) (callerWrite_read64 I o 32 (by omega) ho32) - have hword : (o.write 0 (callerCalldataMem I) 128 32).readWithPadding 128 32 = - o.extract 0 32 := - write32_read_back o (callerCalldataMem I) 128 ho32 - (by rw [callerCalldataMem_size]; omega) - have hret := callerX_successChain rd144 hperm ho32 ho255 hfp hword hmsz - have hevalTmp : evalExpr? callerConfig st.frame st.evm (.var "tmp") - = .ok (.int (Int.ofNat kw)) := by - simp only [evalExpr?, EvalResult.ofOption, htmp] - set frameS : Frame := { contract := Caller.callerContract, locals := st.frame.locals } with hframeS - set evmS : State := EVM.storageStore st.evm st.evm.executionEnv.codeOwner ⟨0⟩ - (UInt256.ofNat kw) with hevmS - have hassign : assignStorageRef? callerConfig st.frame st.evm .storage { base := "stored", steps := [] } - (.int (Int.ofNat kw)) = .ok (frameS, evmS) := by - have hframe : st.frame = { contract := Caller.callerContract, locals := st.frame.locals } := by - cases hframe' : st.frame with - | mk contract locals => - rw [hframe'] at hcontract - simp only at hcontract - rw [hcontract] - rw [hframe, hframeS, hevmS] - exact callerAssign st.evm st.frame.locals kw hstored - have hstmt : ExecStmt callerConfig st.frame st.evm - (.assign .storage { base := "stored", steps := [] } (.var "tmp")) (.ok frameS evmS) := - ExecStmt.assign hevalTmp hassign - have hworldRet : - (cA', sstoreAccountMap I.codeOwner σ' ⟨0⟩ - (UInt256.ofNat (fromByteArrayBigEndian (o.extract 0 32)))) = worldOf evmS := by - rw [hevmS, worldOf, storageStore_createdAccounts, storageStore_accountMap, hevm, hkw] - rfl - have hretWorld : RDret callerBytecode g (initState cA gh bl σ σ₀ g A I) (worldOf evmS) - ByteArray.empty := by - rw [← hworldRet] - exact hret - exact ⟨.ok frameS evmS, ExecBlock.consNormal hstmt ExecBlock.nil, - ByteArray.empty, hretWorld, returnEquiv.fallthrough rfl rfl (by native_decide)⟩ - -set_option maxHeartbeats 4000000 in -/-- Coupled body-suffix proof from the decoded `Caller.run` body entry at pc 66. -/ -theorem callerCoupled_bodySuffix {cA : Batteries.RBSet AccountAddress compare} - {gh : BlockHeader} {bl : ProcessedBlocks} {σ σ₀ : AccountMap} {A : Substate} - {I : ExecutionEnv} {g : Sat256} {sel : UInt256} - (hperm : I.perm = true) (hdepth : I.depth.val < 1024) - (hclean : UInt256.eq (callerArg0 I) - (UInt256.land (callerArg0 I) addrMask) = ⟨1⟩) : - ∀ st : CoupledState callerBytecode I g (initState cA gh bl σ σ₀ g A I) - (CallerEntryRel (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - I g sel) u66, - CoupledState.refines st callerConfig - [.externalCall (.var "t") "pow2" (.intLit 0) [.var "n"] "tmp", - .assign .storage { base := "stored", steps := [] } (.var "tmp")] - (CallerBodyPost callerBytecode g (initState cA gh bl σ σ₀ g A I)) := by - intro st - obtain ⟨result, hcallBlock, hpost⟩ := - callerCoupled_externalCall (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) (sel := sel) hperm hdepth hclean st - cases hcallBlock with - | consNormal hcall hnil => - cases hnil - obtain ⟨o, cur', k', C', hpc', hRD', hw', hrel'⟩ := hpost - obtain ⟨resultTail, htail, hpostTail⟩ := - callerCoupled_assignReturn (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) (sel := sel) (o := o) hperm - (CoupledState.mk cur' k' C' _ _ hpc' hRD' hw' hrel') - exact ⟨resultTail, ExecBlock.consNormal hcall htail, hpostTail⟩ - | consRevert hcall => - exact ⟨.reverted, ExecBlock.consRevert hcall, hpost⟩ - | consReturn hcall => exact hpost.elim - | consBreak hcall => exact hpost.elim - | consContinue hcall => exact hpost.elim - -set_option maxHeartbeats 4000000 in -theorem callerExec_coupled_canonical {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsize : I.calldata.size < UInt256.size) (hperm : I.perm = true) (hdepth : I.depth.val < 1024) - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hmatch : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) = true) - (hclean : UInt256.eq (callerArg0 I) (UInt256.land (callerArg0 I) addrMask) = ⟨1⟩) : - runtimeEquivalenceFor callerConfig callerContract cA gh bl σ σ σ₀ g.toUInt256 A I := by - have hcanon := callerArg0_canonical hclean - have hd : dispatchMsg callerContract I.calldata = some runTransition := by - rw [callerDispatch_eq, if_pos hmatch] - have hdec := callerDecode_n hsz68 hbig hcanon - obtain ⟨k66, C66, rd66⟩ := - callerX_decoded (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (g := g) hcode hwv (by omega) hsize hsz68 hbig hmatch hclean - set sel := UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes 0 32)) ⟨224⟩ with hsel - let cur66 : Cursor := - cursorAt u66 (decodedStack I sel) solcFreePtrMem u3 ByteArray.empty (cA, σ) - let frame0 : Frame := { contract := callerContract, locals := callerDecStore I } - let evm0 : State := initState cA gh bl σ σ₀ g A I - have hRDc : RDc callerBytecode I g (initState cA gh bl σ σ₀ g A I) cur66 k66 C66 := by - change RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) cur66.pc - cur66.stack cur66.mem cur66.aw cur66.rdata cur66.world k66 C66 - exact rd66 - have hw : cur66.world = worldOf evm0 := by - rfl - have hrel : CallerEntryRel (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) I g sel cur66 frame0 evm0 := by - refine ⟨rfl, ?_, rfl, rfl, rfl, rfl, ?_, ?_, ?_⟩ - · rw [hsel] - rfl - · exact callerStore_t I - · exact callerStore_n I - · exact callerStore_stored_none I - obtain ⟨result, hsuffix, hpost⟩ := - callerCoupled_bodySuffix (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) (sel := sel) hperm hdepth hclean - (CoupledState.mk cur66 k66 C66 frame0 evm0 rfl hRDc hw hrel) - cases result with - | ok frame' evm' => - obtain ⟨o, hret, henc⟩ := hpost - have hbody : ExecTransitionBody callerConfig callerContract - (initState cA gh bl σ σ₀ g A I) (callerDecStore I) runTransition.body - (.returned frame' evm' none) := by - exact ExecFuncBody.execBlockOK - (ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) hsuffix) - exact RDret.reEquivExecutionGenAccountMapEquiv hcode hret hd hdec hbody - rfl (accountMapEquiv.refl _) henc - | reverted => - have hbody : ExecTransitionBody callerConfig callerContract - (initState cA gh bl σ σ₀ g A I) (callerDecStore I) runTransition.body .reverted := by - exact ExecFuncBody.execBlockRevert - (ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) hsuffix) - exact RDrev.reEquivExecutionRevert hcode hpost hd hdec hbody - | returned frame' evm' rv => exact hpost.elim - | «break» frame' evm' => exact hpost.elim - | «continue» frame' evm' => exact hpost.elim - -theorem callerX_callDepthLimit {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsz68 : 68 ≤ I.calldata.size) (hszhi : I.calldata.size < 2 ^ 255 + 4) - (hmatch : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) = true) - (hclean : UInt256.eq (callerArg0 I) (UInt256.land (callerArg0 I) addrMask) = ⟨1⟩) - (hdepth : I.depth = 1024) : - RDrev callerBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨k66, C66, rd66raw⟩ := - callerX_decoded (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (g := g) hcode hwv hsz hsize hsz68 hszhi hmatch hclean - set sel := UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes 0 32)) ⟨224⟩ with hsel - have rd66 : RD callerBytecode I g (initState cA gh bl σ σ₀ g A I) u66 - (decodedStack I sel) solcFreePtrMem u3 ByteArray.empty (cA, σ) k66 C66 := by - rw [hsel] - exact rd66raw - obtain ⟨k142, C142, rd142⟩ := callerX_toCall142_from66 rd66 - obtain ⟨gv, rd143⟩ := rd142.gas (by decide) (by evm_ov) - obtain ⟨k', C', rd144⟩ := rd143.callDepthLimit (by decide) hdepth (by evm_ov) - exact callerX_postRevert rd144 (by simp) - -set_option maxHeartbeats 5000000 in -theorem callerReEquiv_callvalueZero - {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = callerBytecode) (hsize : I.calldata.size < Ethereum.UInt256.size) - (hwv : I.weiValue = ⟨0⟩) (hperm : I.perm = true) : - runtimeEquivalenceFor callerConfig callerContract cA gh bl σ σ σ₀ g.toUInt256 A I := by - by_cases hsz : I.calldata.size < 4 - · exact (callerX_cvz_short hcode hwv hsz).reEquivNoDispatch hcode (callerDispatch_none_short hsz) - · rw [not_lt] at hsz - by_cases hmatch : ((⟨#[0x38, 0x1f, 0xd1, 0x90]⟩ : ByteArray) == I.calldata.extract 0 4) = true - · have hd : dispatchMsg callerContract I.calldata = some runTransition := by - rw [callerDispatch_eq, if_pos hmatch] - by_cases hsz68 : 68 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · by_cases hcanon : (callerArg0 I).toNat < EVM.addressModulus - · by_cases hdepth : I.depth.val < 1024 - · exact callerExec_coupled_canonical hcode hwv hsize hperm hdepth hsz68 hbig hmatch - (callerCanon_eq hcanon) - · rw [not_lt] at hdepth - have hdepth1024 : I.depth = 1024 := Fin.ext (by have := I.depth.isLt; omega) - refine (callerX_callDepthLimit hcode hwv (by omega) hsize hsz68 hbig hmatch - (callerCanon_eq hcanon) hdepth1024).reEquivExecutionRevert hcode hd - (callerDecode_n hsz68 hbig hcanon) ?_ - exact callerBodyExtFail _ (callerDecStore I) (by exact hwv) (callerStore_t I) - (callerStore_n I) (callNotMade_depthLimit (callerEncode_eq I) hdepth1024) - · exact (callerX_noncanon hcode hwv (by omega) hsize hsz68 hbig hmatch - (ueq_zero_of_ne (fun he => hcanon (callerArg0_canonical he)))).reEquivDecodingFailed - hcode hd (callerDecode_none_noncanon hsz68 hbig hcanon) - · rw [not_lt] at hbig - exact (callerX_hugearg hcode hwv (by omega) hsize hbig hmatch).reEquivDecodingFailed - hcode hd (callerDecode_none_huge hbig) - · rw [not_le] at hsz68 - exact (callerX_shortarg hcode hwv hsz hsize hsz68 hmatch).reEquivDecodingFailed - hcode hd (callerDecode_none_short hsz hsz68) - · rw [Bool.not_eq_true] at hmatch - exact (callerX_cvz_revertB hcode hwv hsz hsize hmatch).reEquivNoDispatch hcode - (callerDispatch_none_nomatch hmatch) - -end - -end CallerCoupled diff --git a/Examples/ERC20/Allowance.lean b/Examples/ERC20/Allowance.lean index 9cc39f67..a2e2ec93 100644 --- a/Examples/ERC20/Allowance.lean +++ b/Examples/ERC20/Allowance.lean @@ -1,8 +1,7 @@ import Examples.ERC20.Common -import Reasoning.Refinement import Reasoning.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/ERC20/Approve.lean b/Examples/ERC20/Approve.lean index 233500ac..00337c17 100644 --- a/Examples/ERC20/Approve.lean +++ b/Examples/ERC20/Approve.lean @@ -1,8 +1,7 @@ import Examples.ERC20.Allowance import Examples.ERC20.Storage -import Reasoning.Refinement -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/ERC20/BalanceOf.lean b/Examples/ERC20/BalanceOf.lean index 5aade083..2c95d195 100644 --- a/Examples/ERC20/BalanceOf.lean +++ b/Examples/ERC20/BalanceOf.lean @@ -1,8 +1,7 @@ import Examples.ERC20.Common -import Reasoning.Refinement import Reasoning.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/ERC20/Correct.lean b/Examples/ERC20/Correct.lean index 26ac7208..b82603fb 100644 --- a/Examples/ERC20/Correct.lean +++ b/Examples/ERC20/Correct.lean @@ -12,7 +12,6 @@ import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody import Reasoning.Initcode import Reasoning.Memory @@ -28,7 +27,7 @@ machinery driver (one `RD.dispatchTo`); the per-function body proofs and the sel / revert facts are named obligations discharged in ERC20-local helper files. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/ERC20/SpecSugar.lean b/Examples/ERC20/SpecSyntax.lean similarity index 93% rename from Examples/ERC20/SpecSugar.lean rename to Examples/ERC20/SpecSyntax.lean index 2362c8cb..61772d41 100644 --- a/Examples/ERC20/SpecSugar.lean +++ b/Examples/ERC20/SpecSyntax.lean @@ -17,9 +17,9 @@ Notes: open Solm Solm.Notation -namespace ERC20Sugar +namespace ERC20.Syntax -def erc20ContractGen : ContractDecl := solidity% contract ERC20 { +def contractSyntax : ContractDecl := solidity% contract ERC20 { mapping(address => uint256) balanceOf; mapping(address => mapping(address => uint256)) allowance; uint256 totalSupply; @@ -71,6 +71,6 @@ def erc20ContractGen : ContractDecl := solidity% contract ERC20 { } /-- The macro-generated contract is *definitionally* the hand-written one. -/ -theorem erc20ContractGen_eq : erc20ContractGen = ERC20.erc20Contract := by rfl +theorem contractSyntax_eq : contractSyntax = ERC20.erc20Contract := by rfl -end ERC20Sugar +end ERC20.Syntax diff --git a/Examples/ERC20/TotalSupply.lean b/Examples/ERC20/TotalSupply.lean index 8eae93ba..be6a1631 100644 --- a/Examples/ERC20/TotalSupply.lean +++ b/Examples/ERC20/TotalSupply.lean @@ -1,8 +1,7 @@ import Examples.ERC20.Common -import Reasoning.Refinement import Reasoning.Storage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/ERC20/Transfer.lean b/Examples/ERC20/Transfer.lean index a61b267a..2b024eda 100644 --- a/Examples/ERC20/Transfer.lean +++ b/Examples/ERC20/Transfer.lean @@ -1,8 +1,7 @@ import Examples.ERC20.BalanceOf import Examples.ERC20.Approve -import Reasoning.Refinement -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Examples/ERC20/TransferFrom.lean b/Examples/ERC20/TransferFrom.lean index a7c6a74f..80e5a1eb 100644 --- a/Examples/ERC20/TransferFrom.lean +++ b/Examples/ERC20/TransferFrom.lean @@ -1,6 +1,6 @@ import Examples.ERC20.Transfer -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/OpenZeppelinBench/AccessControl/Correct.lean b/Examples/OpenZeppelinBench/AccessControl/Correct.lean index faa73185..1ae67e36 100644 --- a/Examples/OpenZeppelinBench/AccessControl/Correct.lean +++ b/Examples/OpenZeppelinBench/AccessControl/Correct.lean @@ -5,9 +5,8 @@ import Examples.OpenZeppelinBench.AccessControl.HasRole import Examples.OpenZeppelinBench.AccessControl.RenounceRole import Examples.OpenZeppelinBench.AccessControl.RevokeRole import Examples.OpenZeppelinBench.AccessControl.SupportsInterface -import Reasoning.Refinement -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/AccessControl/DefaultAdminRole.lean b/Examples/OpenZeppelinBench/AccessControl/DefaultAdminRole.lean index b6fdcc2c..c1470f51 100644 --- a/Examples/OpenZeppelinBench/AccessControl/DefaultAdminRole.lean +++ b/Examples/OpenZeppelinBench/AccessControl/DefaultAdminRole.lean @@ -1,8 +1,7 @@ import Examples.OpenZeppelinBench.AccessControl.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/AccessControl/GetRoleAdmin.lean b/Examples/OpenZeppelinBench/AccessControl/GetRoleAdmin.lean index dc2e4da9..06d44370 100644 --- a/Examples/OpenZeppelinBench/AccessControl/GetRoleAdmin.lean +++ b/Examples/OpenZeppelinBench/AccessControl/GetRoleAdmin.lean @@ -1,9 +1,8 @@ import Examples.OpenZeppelinBench.AccessControl.Storage import Reasoning.ABI -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/AccessControl/GrantRole.lean b/Examples/OpenZeppelinBench/AccessControl/GrantRole.lean index 88519407..db80107a 100644 --- a/Examples/OpenZeppelinBench/AccessControl/GrantRole.lean +++ b/Examples/OpenZeppelinBench/AccessControl/GrantRole.lean @@ -1,9 +1,8 @@ import Examples.OpenZeppelinBench.AccessControl.Storage import Examples.OpenZeppelinBench.AccessControl.RevokeRole -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/OpenZeppelinBench/AccessControl/HasRole.lean b/Examples/OpenZeppelinBench/AccessControl/HasRole.lean index 6eabbb31..e4584b82 100644 --- a/Examples/OpenZeppelinBench/AccessControl/HasRole.lean +++ b/Examples/OpenZeppelinBench/AccessControl/HasRole.lean @@ -1,8 +1,7 @@ import Examples.OpenZeppelinBench.AccessControl.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/OpenZeppelinBench/AccessControl/RenounceRole.lean b/Examples/OpenZeppelinBench/AccessControl/RenounceRole.lean index 9db060d0..74647afe 100644 --- a/Examples/OpenZeppelinBench/AccessControl/RenounceRole.lean +++ b/Examples/OpenZeppelinBench/AccessControl/RenounceRole.lean @@ -1,8 +1,7 @@ import Examples.OpenZeppelinBench.AccessControl.RevokeRole -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/OpenZeppelinBench/AccessControl/RevokeRole.lean b/Examples/OpenZeppelinBench/AccessControl/RevokeRole.lean index a639190d..cb5f9a5b 100644 --- a/Examples/OpenZeppelinBench/AccessControl/RevokeRole.lean +++ b/Examples/OpenZeppelinBench/AccessControl/RevokeRole.lean @@ -1,8 +1,7 @@ import Examples.OpenZeppelinBench.AccessControl.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/OpenZeppelinBench/AccessControl/SupportsInterface.lean b/Examples/OpenZeppelinBench/AccessControl/SupportsInterface.lean index f10cfdbb..c21b2309 100644 --- a/Examples/OpenZeppelinBench/AccessControl/SupportsInterface.lean +++ b/Examples/OpenZeppelinBench/AccessControl/SupportsInterface.lean @@ -1,8 +1,7 @@ import Examples.OpenZeppelinBench.AccessControl.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/Allowance.lean b/Examples/OpenZeppelinBench/ERC6909/Allowance.lean index d95687d2..782c8079 100644 --- a/Examples/OpenZeppelinBench/ERC6909/Allowance.lean +++ b/Examples/OpenZeppelinBench/ERC6909/Allowance.lean @@ -1,8 +1,7 @@ import Examples.OpenZeppelinBench.ERC6909.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/Approve.lean b/Examples/OpenZeppelinBench/ERC6909/Approve.lean index 400b32f2..b9e32452 100644 --- a/Examples/OpenZeppelinBench/ERC6909/Approve.lean +++ b/Examples/OpenZeppelinBench/ERC6909/Approve.lean @@ -1,8 +1,7 @@ import Examples.OpenZeppelinBench.ERC6909.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/BalanceOf.lean b/Examples/OpenZeppelinBench/ERC6909/BalanceOf.lean index 500ebd8b..2c2cbcea 100644 --- a/Examples/OpenZeppelinBench/ERC6909/BalanceOf.lean +++ b/Examples/OpenZeppelinBench/ERC6909/BalanceOf.lean @@ -1,8 +1,7 @@ import Examples.OpenZeppelinBench.ERC6909.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/Correct.lean b/Examples/OpenZeppelinBench/ERC6909/Correct.lean index 2b50b949..5cde1afc 100644 --- a/Examples/OpenZeppelinBench/ERC6909/Correct.lean +++ b/Examples/OpenZeppelinBench/ERC6909/Correct.lean @@ -7,10 +7,9 @@ import Examples.OpenZeppelinBench.ERC6909.Storage import Examples.OpenZeppelinBench.ERC6909.SupportsInterface import Examples.OpenZeppelinBench.ERC6909.Transfer import Examples.OpenZeppelinBench.ERC6909.TransferFrom -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/IsOperator.lean b/Examples/OpenZeppelinBench/ERC6909/IsOperator.lean index c452fcdd..d814eef0 100644 --- a/Examples/OpenZeppelinBench/ERC6909/IsOperator.lean +++ b/Examples/OpenZeppelinBench/ERC6909/IsOperator.lean @@ -1,9 +1,8 @@ import Examples.OpenZeppelinBench.ERC6909.Storage import Examples.OpenZeppelinBench.Pausable.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/SetOperator.lean b/Examples/OpenZeppelinBench/ERC6909/SetOperator.lean index 3a592067..6c62b48e 100644 --- a/Examples/OpenZeppelinBench/ERC6909/SetOperator.lean +++ b/Examples/OpenZeppelinBench/ERC6909/SetOperator.lean @@ -1,10 +1,9 @@ import Examples.OpenZeppelinBench.ERC6909.Storage import Examples.OpenZeppelinBench.ERC6909.Approve import Examples.OpenZeppelinBench.Pausable.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/SupportsInterface.lean b/Examples/OpenZeppelinBench/ERC6909/SupportsInterface.lean index 5857d0db..cb83515a 100644 --- a/Examples/OpenZeppelinBench/ERC6909/SupportsInterface.lean +++ b/Examples/OpenZeppelinBench/ERC6909/SupportsInterface.lean @@ -1,9 +1,8 @@ import Examples.OpenZeppelinBench.ERC6909.Storage import Examples.OpenZeppelinBench.AccessControl.SupportsInterface -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/Transfer.lean b/Examples/OpenZeppelinBench/ERC6909/Transfer.lean index 17a667d7..b2500127 100644 --- a/Examples/OpenZeppelinBench/ERC6909/Transfer.lean +++ b/Examples/OpenZeppelinBench/ERC6909/Transfer.lean @@ -1,10 +1,9 @@ import Examples.OpenZeppelinBench.ERC6909.BalanceOf import Examples.OpenZeppelinBench.ERC6909.Approve import Examples.OpenZeppelinBench.ERC6909.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/TransferFrom.lean b/Examples/OpenZeppelinBench/ERC6909/TransferFrom.lean index 8fd979d3..9f120c9d 100644 --- a/Examples/OpenZeppelinBench/ERC6909/TransferFrom.lean +++ b/Examples/OpenZeppelinBench/ERC6909/TransferFrom.lean @@ -1,7 +1,7 @@ import Examples.OpenZeppelinBench.ERC6909.TransferFrom.Cases import Examples.OpenZeppelinBench.ERC6909.TransferFrom.Traces -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Cases.lean b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Cases.lean index 85fcd9c0..4fe364f2 100644 --- a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Cases.lean +++ b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Cases.lean @@ -1,6 +1,6 @@ import Examples.OpenZeppelinBench.ERC6909.TransferFrom.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Common.lean b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Common.lean index 500e046b..f94ef347 100644 --- a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Common.lean +++ b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Common.lean @@ -1,6 +1,6 @@ import Examples.OpenZeppelinBench.ERC6909.TransferFrom.Decode -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Decode.lean b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Decode.lean index 960d5554..f406f6a9 100644 --- a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Decode.lean +++ b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Decode.lean @@ -4,10 +4,9 @@ import Examples.OpenZeppelinBench.ERC6909.IsOperator import Examples.OpenZeppelinBench.ERC6909.Storage import Examples.OpenZeppelinBench.ERC6909.Transfer import Examples.OpenZeppelinBench.Pausable.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/Allowance.lean b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/Allowance.lean index 3a5baa85..575ee06d 100644 --- a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/Allowance.lean +++ b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/Allowance.lean @@ -1,6 +1,6 @@ import Examples.OpenZeppelinBench.ERC6909.TransferFrom.Traces.SkipCaller -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/DebitTail.lean b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/DebitTail.lean index c36e92b1..599408be 100644 --- a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/DebitTail.lean +++ b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/DebitTail.lean @@ -1,6 +1,6 @@ import Examples.OpenZeppelinBench.ERC6909.TransferFrom.Traces.Allowance -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/Memory.lean b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/Memory.lean index 940e00f5..021ddd8c 100644 --- a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/Memory.lean +++ b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/Memory.lean @@ -1,6 +1,6 @@ import Examples.OpenZeppelinBench.ERC6909.TransferFrom.Decode -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/Operator.lean b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/Operator.lean index 777d3fea..eaca608f 100644 --- a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/Operator.lean +++ b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/Operator.lean @@ -1,6 +1,6 @@ import Examples.OpenZeppelinBench.ERC6909.TransferFrom.Traces.DebitTail -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/SkipCaller.lean b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/SkipCaller.lean index 5fbb48e1..bf801b17 100644 --- a/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/SkipCaller.lean +++ b/Examples/OpenZeppelinBench/ERC6909/TransferFrom/Traces/SkipCaller.lean @@ -1,6 +1,6 @@ import Examples.OpenZeppelinBench.ERC6909.TransferFrom.Traces.Memory -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Examples/OpenZeppelinBench/Ownable2Step/AcceptOwnership.lean b/Examples/OpenZeppelinBench/Ownable2Step/AcceptOwnership.lean index 8f02dff5..a48b25b5 100644 --- a/Examples/OpenZeppelinBench/Ownable2Step/AcceptOwnership.lean +++ b/Examples/OpenZeppelinBench/Ownable2Step/AcceptOwnership.lean @@ -1,8 +1,7 @@ import Examples.OpenZeppelinBench.Ownable2Step.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/Ownable2Step/Common.lean b/Examples/OpenZeppelinBench/Ownable2Step/Common.lean index 5f543060..bbcde918 100644 --- a/Examples/OpenZeppelinBench/Ownable2Step/Common.lean +++ b/Examples/OpenZeppelinBench/Ownable2Step/Common.lean @@ -2,12 +2,11 @@ import Examples.OpenZeppelinBench.Ownable2Step.Trusted import Reasoning.ABI import Reasoning.Dispatch import Reasoning.Memory -import Reasoning.Refinement import Reasoning.Solc import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/Ownable2Step/Correct.lean b/Examples/OpenZeppelinBench/Ownable2Step/Correct.lean index c0c9a182..6697902f 100644 --- a/Examples/OpenZeppelinBench/Ownable2Step/Correct.lean +++ b/Examples/OpenZeppelinBench/Ownable2Step/Correct.lean @@ -4,7 +4,7 @@ import Examples.OpenZeppelinBench.Ownable2Step.PendingOwner import Examples.OpenZeppelinBench.Ownable2Step.RenounceOwnership import Examples.OpenZeppelinBench.Ownable2Step.TransferOwnership -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/Ownable2Step/Owner.lean b/Examples/OpenZeppelinBench/Ownable2Step/Owner.lean index 09d11ed4..d19257d0 100644 --- a/Examples/OpenZeppelinBench/Ownable2Step/Owner.lean +++ b/Examples/OpenZeppelinBench/Ownable2Step/Owner.lean @@ -1,8 +1,7 @@ import Examples.OpenZeppelinBench.Ownable2Step.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/Ownable2Step/PendingOwner.lean b/Examples/OpenZeppelinBench/Ownable2Step/PendingOwner.lean index ffeabe77..4f881a13 100644 --- a/Examples/OpenZeppelinBench/Ownable2Step/PendingOwner.lean +++ b/Examples/OpenZeppelinBench/Ownable2Step/PendingOwner.lean @@ -1,8 +1,7 @@ import Examples.OpenZeppelinBench.Ownable2Step.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/Ownable2Step/RenounceOwnership.lean b/Examples/OpenZeppelinBench/Ownable2Step/RenounceOwnership.lean index 4d6d62bd..b4b6b6ea 100644 --- a/Examples/OpenZeppelinBench/Ownable2Step/RenounceOwnership.lean +++ b/Examples/OpenZeppelinBench/Ownable2Step/RenounceOwnership.lean @@ -1,8 +1,7 @@ import Examples.OpenZeppelinBench.Ownable2Step.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/Ownable2Step/TransferOwnership.lean b/Examples/OpenZeppelinBench/Ownable2Step/TransferOwnership.lean index 8bb904d0..7298151f 100644 --- a/Examples/OpenZeppelinBench/Ownable2Step/TransferOwnership.lean +++ b/Examples/OpenZeppelinBench/Ownable2Step/TransferOwnership.lean @@ -1,8 +1,7 @@ import Examples.OpenZeppelinBench.Ownable2Step.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/Pausable/Common.lean b/Examples/OpenZeppelinBench/Pausable/Common.lean index 6dec4594..8561b266 100644 --- a/Examples/OpenZeppelinBench/Pausable/Common.lean +++ b/Examples/OpenZeppelinBench/Pausable/Common.lean @@ -2,12 +2,11 @@ import Examples.OpenZeppelinBench.Pausable.Trusted import Examples.OpenZeppelinBench.Pausable.Storage import Reasoning.ABI import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.Solc import Reasoning.SolmBody import Mathlib.Tactic.IntervalCases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/Pausable/Correct.lean b/Examples/OpenZeppelinBench/Pausable/Correct.lean index afa4d8f7..9c16ff00 100644 --- a/Examples/OpenZeppelinBench/Pausable/Correct.lean +++ b/Examples/OpenZeppelinBench/Pausable/Correct.lean @@ -4,7 +4,7 @@ import Examples.OpenZeppelinBench.Pausable.Pause import Examples.OpenZeppelinBench.Pausable.GuardedWhenNotPaused import Examples.OpenZeppelinBench.Pausable.GuardedWhenPaused -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/Pausable/GuardedWhenNotPaused.lean b/Examples/OpenZeppelinBench/Pausable/GuardedWhenNotPaused.lean index cee4b1f6..c3114d50 100644 --- a/Examples/OpenZeppelinBench/Pausable/GuardedWhenNotPaused.lean +++ b/Examples/OpenZeppelinBench/Pausable/GuardedWhenNotPaused.lean @@ -1,6 +1,6 @@ import Examples.OpenZeppelinBench.Pausable.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/Pausable/GuardedWhenPaused.lean b/Examples/OpenZeppelinBench/Pausable/GuardedWhenPaused.lean index 8a9e36a4..e437d9b9 100644 --- a/Examples/OpenZeppelinBench/Pausable/GuardedWhenPaused.lean +++ b/Examples/OpenZeppelinBench/Pausable/GuardedWhenPaused.lean @@ -1,6 +1,6 @@ import Examples.OpenZeppelinBench.Pausable.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/Pausable/Pause.lean b/Examples/OpenZeppelinBench/Pausable/Pause.lean index a5361592..690c711f 100644 --- a/Examples/OpenZeppelinBench/Pausable/Pause.lean +++ b/Examples/OpenZeppelinBench/Pausable/Pause.lean @@ -1,6 +1,6 @@ import Examples.OpenZeppelinBench.Pausable.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/Pausable/Paused.lean b/Examples/OpenZeppelinBench/Pausable/Paused.lean index 05428e04..76284b84 100644 --- a/Examples/OpenZeppelinBench/Pausable/Paused.lean +++ b/Examples/OpenZeppelinBench/Pausable/Paused.lean @@ -1,6 +1,6 @@ import Examples.OpenZeppelinBench.Pausable.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/OpenZeppelinBench/Pausable/Unpause.lean b/Examples/OpenZeppelinBench/Pausable/Unpause.lean index 27bab16d..1ffeca22 100644 --- a/Examples/OpenZeppelinBench/Pausable/Unpause.lean +++ b/Examples/OpenZeppelinBench/Pausable/Unpause.lean @@ -1,6 +1,6 @@ import Examples.OpenZeppelinBench.Pausable.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/PowCoupled/BodySuccess.lean b/Examples/PowCoupled/BodySuccess.lean deleted file mode 100644 index c78b0892..00000000 --- a/Examples/PowCoupled/BodySuccess.lean +++ /dev/null @@ -1,248 +0,0 @@ -import Examples.Pow.Correct -import Reasoning.Refinement - -/-! -# Pow coupled-state experiment - -This file tries the new concrete coupled-state refinement style on the successful suffix of -`pow2`: start at the loop head, prove the Solm loop and bytecode loop progress together, then -finish through the bytecode return encoder. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement - -namespace PowCoupled - -noncomputable section - -set_option maxRecDepth 10000 - -private abbrev u0 : UInt256 := ⟨0⟩ -private abbrev u1 : UInt256 := ⟨1⟩ -private abbrev u2 : UInt256 := ⟨2⟩ -private abbrev u3 : UInt256 := UInt256.ofNat 3 -private abbrev u71 : UInt256 := ⟨71⟩ -private abbrev u117 : UInt256 := ⟨117⟩ -private abbrev u126 : UInt256 := ⟨126⟩ -private abbrev u132 : UInt256 := ⟨132⟩ -private abbrev u142 : UInt256 := ⟨142⟩ - -private abbrev loopStack (N i : ℕ) (sel : UInt256) : List UInt256 := - [UInt256.ofNat i, UInt256.ofNat (2 ^ i), u0, UInt256.ofNat N, u71, sel] - -private abbrev afterRStack (N i : ℕ) (sel : UInt256) : List UInt256 := - [UInt256.ofNat i, UInt256.ofNat (2 ^ (i + 1)), u0, UInt256.ofNat N, u71, sel] - -private abbrev exitStack (N : ℕ) (sel : UInt256) : List UInt256 := - [UInt256.ofNat N, UInt256.ofNat (2 ^ N), u0, UInt256.ofNat N, u71, sel] - -private def cursorAt (pc : UInt256) (stack : List UInt256) - (world : Batteries.RBSet AccountAddress compare × AccountMap) : Cursor := - { pc := pc, stack := stack, mem := solcFreePtrMem, aw := u3, rdata := ByteArray.empty, - world := world } - -def PowLoopRel (N : ℕ) (sel : UInt256) (v : ℕ) : StateRel := - fun cur frame _evm => - ∃ i : ℕ, - N - i = v ∧ i ≤ N ∧ - cur.stack = loopStack N i sel ∧ - cur.mem = solcFreePtrMem ∧ cur.aw = u3 ∧ cur.rdata = ByteArray.empty ∧ - frame.locals.get? "i" = some (.int (Int.ofNat i)) ∧ - frame.locals.get? "r" = some (.int (Int.ofNat (2 ^ i))) ∧ - frame.locals.get? "n" = some (.int (Int.ofNat N)) - -def PowBodyRel (N : ℕ) (sel : UInt256) (v : ℕ) : StateRel := - fun cur frame _evm => - ∃ i : ℕ, - N - i = v + 1 ∧ i < N ∧ - cur.stack = loopStack N i sel ∧ - cur.mem = solcFreePtrMem ∧ cur.aw = u3 ∧ cur.rdata = ByteArray.empty ∧ - frame.locals.get? "i" = some (.int (Int.ofNat i)) ∧ - frame.locals.get? "r" = some (.int (Int.ofNat (2 ^ i))) ∧ - frame.locals.get? "n" = some (.int (Int.ofNat N)) - -def PowAfterRRel (N : ℕ) (sel : UInt256) (v : ℕ) : StateRel := - fun cur frame _evm => - ∃ i : ℕ, - N - i = v + 1 ∧ i < N ∧ - cur.stack = afterRStack N i sel ∧ - cur.mem = solcFreePtrMem ∧ cur.aw = u3 ∧ cur.rdata = ByteArray.empty ∧ - frame.locals.get? "i" = some (.int (Int.ofNat i)) ∧ - frame.locals.get? "r" = some (.int (Int.ofNat (2 ^ (i + 1)))) ∧ - frame.locals.get? "n" = some (.int (Int.ofNat N)) - -def PowExitRel (N : ℕ) (sel : UInt256) : StateRel := - fun cur frame _evm => - cur.stack = exitStack N sel ∧ - cur.mem = solcFreePtrMem ∧ cur.aw = u3 ∧ cur.rdata = ByteArray.empty ∧ - frame.locals.get? "r" = some (.int (Int.ofNat (2 ^ N))) ∧ - frame.locals.get? "n" = some (.int (Int.ofNat N)) - -private theorem ofNat_add_one {i : ℕ} (hi : i + 1 < UInt256.size) : - (UInt256.ofNat i + u1).toNat = i + 1 := by - have hi0 : i < UInt256.size := by omega - have hto : (UInt256.ofNat i).toNat = i := ulit_toNat' i hi0 - simpa [u1, hto] using add1_toNat (i := UInt256.ofNat i) (by rw [hto]; exact hi) - -private theorem mul2_ofNat_pow {i : ℕ} (hi : i + 1 < 256) : - UInt256.mul (UInt256.ofNat (2 ^ i)) u2 = UInt256.ofNat (2 ^ (i + 1)) := by - apply u256_inj - have hsize : 2 * (UInt256.ofNat (2 ^ i)).toNat < UInt256.size := by - rw [show (UInt256.ofNat (2 ^ i)).toNat = 2 ^ i from ofNat_pow_toNat (by omega)] - rw [show 2 * 2 ^ i = 2 ^ (i + 1) from by rw [pow_succ]; ring] - exact pow_lt_size hi - rw [mul2_toNat hsize] - rw [show (UInt256.ofNat (2 ^ i)).toNat = 2 ^ i from ofNat_pow_toNat (by omega)] - rw [show (UInt256.ofNat (2 ^ (i + 1))).toNat = 2 ^ (i + 1) from ofNat_pow_toNat hi] - rw [pow_succ] - ring - -private theorem add1_ofNat {i : ℕ} (hi : i + 1 < UInt256.size) : - UInt256.ofNat i + u1 = UInt256.ofNat (i + 1) := by - apply u256_inj - rw [ofNat_add_one hi] - exact (ulit_toNat' (i + 1) hi).symm - -set_option maxHeartbeats 2000000 in -theorem powCoupled_loopSuffix_success {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {N : ℕ} {sel : UInt256} (hN : N < 256) : - ∀ st : CoupledState powBytecode ee g s0 (PowLoopRel N sel N) u117, - CoupledState.refines st powConfig - [.while Pow.powLoopCond Pow.powLoopBody, .return [(.var "r")]] - (transitionPost powBytecode ee g s0 [Pow.uint256] (fun _ _ _ => False)) := by - intro st - refine CoupledState.refines.whileLoopIndexedBody - (code := powBytecode) (ee := ee) (g := g) (s0 := s0) (cfg := powConfig) - (loopPc := u117) (bodyPc := u126) (exitPc := u142) - (Rloop := PowLoopRel N sel) (Rbody := PowBodyRel N sel) (Rexit := PowExitRel N sel) - (Post := transitionPost powBytecode ee g s0 [Pow.uint256] (fun _ _ _ => False)) - (cond := Pow.powLoopCond) (body := Pow.powLoopBody) (rest := [.return [(.var "r")]]) - ?hfalse ?htrue ?hbody ?hrest N st - · intro st0 - rcases st0.hrel with ⟨i, hvar, hile, hstack, hmem, haw, hrdata, hi, hr, hn⟩ - have hieq : i = N := by omega - subst i - have hcond : evalExpr? powConfig st0.frame st0.evm Pow.powLoopCond = .ok (.bool false) := by - rw [Pow.powLoopCond, Pow.evalLt hi hn, - decide_eq_false (by simp only [Int.ofNat_eq_natCast, Nat.cast_lt]; omega)] - have hlt : UInt256.lt (UInt256.ofNat N) (UInt256.ofNat N) = u0 := by - exact ult_zero (by omega) - have hRD0 : RD powBytecode ee g s0 u117 (loopStack N N sel) solcFreePtrMem u3 - ByteArray.empty st0.cur.world st0.k st0.C := - st0.toRD hstack hmem haw hrdata - have rdExit := evm_run hRD0 with [ - jumpdest, dup4, dup2, lt, iszero, push2 ⟨142⟩, - jumpiT (by rw [hlt]; decide) (by jump_dest) ] - exact ⟨cursorAt u142 (exitStack N sel) st0.cur.world, _, _, hcond, rfl, rdExit, - st0.hworld, ⟨rfl, rfl, rfl, rfl, by simpa [exitStack] using hr, hn⟩⟩ - · intro v stLoop - rcases stLoop.hrel with ⟨i, hvar, hile, hstack, hmem, haw, hrdata, hi, hr, hn⟩ - have hltNat : i < N := by omega - have hcond : evalExpr? powConfig stLoop.frame stLoop.evm Pow.powLoopCond = .ok (.bool true) := by - rw [Pow.powLoopCond, Pow.evalLt hi hn, - decide_eq_true (by simp only [Int.ofNat_eq_natCast, Nat.cast_lt]; omega)] - have hlt : UInt256.lt (UInt256.ofNat i) (UInt256.ofNat N) = u1 := by - exact ult_one (by - rw [ulit_toNat' i (by exact lt_size_of_lt256 (by omega)), - ulit_toNat' N (lt_size_of_lt256 hN)] - exact hltNat) - have hRD0 : RD powBytecode ee g s0 u117 (loopStack N i sel) solcFreePtrMem u3 - ByteArray.empty stLoop.cur.world stLoop.k stLoop.C := - stLoop.toRD hstack hmem haw hrdata - have rdBody := evm_run hRD0 with [ - jumpdest, dup4, dup2, lt, iszero, push2 ⟨142⟩, - jumpiNT (by rw [hlt]; decide) ] - exact ⟨cursorAt u126 (loopStack N i sel) stLoop.cur.world, _, _, hcond, rfl, rdBody, - stLoop.hworld, ⟨i, hvar, hltNat, rfl, rfl, rfl, rfl, hi, hr, hn⟩⟩ - · intro v stBody - rcases stBody.hrel with ⟨i, hvar, hlt, hstack, hmem, haw, hrdata, hi, hr, hn⟩ - have hpowInt : (Int.ofNat (2 ^ i) * 2 : Int) = Int.ofNat (2 ^ (i + 1)) := by - simp only [Int.ofNat_eq_natCast] - push_cast [pow_succ] - ring - set frameR : Frame := - { stBody.frame with - locals := stBody.frame.locals.insert "r" (.int (Int.ofNat (2 ^ (i + 1)))) } - with hframeR - have hstmtR : ExecStmt powConfig stBody.frame stBody.evm - (.letDecl "r" (some Pow.uint256) (.binary .mul (.var "r") (.intLit 2))) - (.ok frameR stBody.evm) := by - rw [hframeR, ← hpowInt] - exact ExecStmt.letDecl (by rw [Pow.evalMul2 hr]) - have hRD0 : RD powBytecode ee g s0 u126 (loopStack N i sel) solcFreePtrMem u3 - ByteArray.empty stBody.cur.world stBody.k stBody.C := - stBody.toRD hstack hmem haw hrdata - have hmul : UInt256.mul (UInt256.ofNat (2 ^ i)) u2 = UInt256.ofNat (2 ^ (i + 1)) := - mul2_ofNat_pow (by omega) - have rdR := evm_run hRD0 with [ - push1 ⟨2⟩, dup3, mul, swap2, pop ] - rw [hmul] at rdR - have hrelR : PowAfterRRel N sel v (cursorAt u132 (afterRStack N i sel) stBody.cur.world) - frameR stBody.evm := by - refine ⟨i, hvar, hlt, rfl, rfl, rfl, rfl, ?_, ?_, ?_⟩ - · rw [hframeR, store_get_ne _ _ (by decide), hi] - · rw [hframeR, store_get_self] - · rw [hframeR, store_get_ne _ _ (by decide), hn] - let stR : CoupledState powBytecode ee g s0 (PowAfterRRel N sel v) u132 := - CoupledState.reached (cursorAt u132 (afterRStack N i sel) stBody.cur.world) - _ _ frameR stBody.evm rfl rdR stBody.hworld hrelR - refine CoupledState.refines.consNormalAt - (s := .letDecl "r" (some Pow.uint256) (.binary .mul (.var "r") (.intLit 2))) - (rest := [.letDecl "i" (some Pow.uint256) (.binary .add (.var "i") (.intLit 1))]) - stBody stR hstmtR ?_ - rcases stR.hrel with ⟨i, hvar, hlt, hstack, hmem, haw, hrdata, hi, hr, hn⟩ - have hInt : (Int.ofNat i + 1 : Int) = Int.ofNat (i + 1) := by - simp only [Int.ofNat_eq_natCast] - push_cast - ring - set frameI : Frame := - { stR.frame with locals := stR.frame.locals.insert "i" (.int (Int.ofNat (i + 1))) } - with hframeI - have hstmtI : ExecStmt powConfig stR.frame stR.evm - (.letDecl "i" (some Pow.uint256) (.binary .add (.var "i") (.intLit 1))) - (.ok frameI stR.evm) := by - rw [hframeI, ← hInt] - exact ExecStmt.letDecl (by rw [Pow.evalAdd1 hi]) - have hRD0 : RD powBytecode ee g s0 u132 (afterRStack N i sel) solcFreePtrMem u3 - ByteArray.empty stR.cur.world stR.k stR.C := - stR.toRD hstack hmem haw hrdata - have hadd : UInt256.ofNat i + u1 = UInt256.ofNat (i + 1) := - add1_ofNat (lt_size_of_lt256 (by omega)) - have rdLoop := evm_run hRD0 with [ - push1 ⟨1⟩, dup2, add, swap1, pop, push2 ⟨117⟩, - jump (by jump_dest) ] - rw [hadd] at rdLoop - have hrelLoop : PowLoopRel N sel v - (cursorAt u117 (loopStack N (i + 1) sel) stR.cur.world) frameI stR.evm := by - refine ⟨i + 1, by omega, by omega, rfl, rfl, rfl, rfl, ?_, ?_, ?_⟩ - · rw [hframeI, store_get_self] - · rw [hframeI, store_get_ne _ _ (by decide), hr] - · rw [hframeI, store_get_ne _ _ (by decide), hn] - let stLoop : CoupledState powBytecode ee g s0 (PowLoopRel N sel v) u117 := - CoupledState.reached (cursorAt u117 (loopStack N (i + 1) sel) stR.cur.world) - _ _ frameI stR.evm rfl rdLoop stR.hworld hrelLoop - refine CoupledState.refines.consNormalAt - (s := .letDecl "i" (some Pow.uint256) (.binary .add (.var "i") (.intLit 1))) - (rest := []) stR stLoop hstmtI ?_ - exact ⟨.ok stLoop.frame stLoop.evm, ExecBlock.nil, - stLoop.cur, stLoop.k, stLoop.C, stLoop.hpc, stLoop.hRD, stLoop.hworld, stLoop.hrel⟩ - · intro stExit - rcases stExit.hrel with ⟨hstack, hmem, haw, hrdata, hr, _hn⟩ - have hstmt : ExecStmt powConfig stExit.frame stExit.evm (.return [(.var "r")]) - (.returned stExit.frame stExit.evm (some [(.int (Int.ofNat (2 ^ N)))])) := - ExecStmt.return (evalExprs?_singleton (by rw [Pow.evalVar hr])) - have hRD0 : RD powBytecode ee g s0 u142 (exitStack N sel) solcFreePtrMem u3 - ByteArray.empty stExit.cur.world stExit.k stExit.C := - stExit.toRD hstack hmem haw hrdata - have rdRet : RDret powBytecode g s0 stExit.cur.world - (UInt256.toByteArray (UInt256.ofNat (2 ^ N))) := - hRD0.routineexit (by jump_dest) - (by simp only [List.length_cons, List.length_nil]; omega) - |>.routineencode (by simp only [List.length_cons, List.length_nil]; omega) - rw [stExit.hworld] at rdRet - exact CoupledState.refines.returnTransition stExit hstmt rdRet - (returnEquiv_of_encode (Pow.powReturnEncoding hN)) - -end - -end PowCoupled diff --git a/Examples/SimpleAuction/AuctionEnd.lean b/Examples/SimpleAuction/AuctionEnd.lean index a2d45400..70849fe3 100644 --- a/Examples/SimpleAuction/AuctionEnd.lean +++ b/Examples/SimpleAuction/AuctionEnd.lean @@ -1,9 +1,8 @@ import Examples.SimpleAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/SimpleAuction/AuctionEndTime.lean b/Examples/SimpleAuction/AuctionEndTime.lean index 393294bc..c584c0f4 100644 --- a/Examples/SimpleAuction/AuctionEndTime.lean +++ b/Examples/SimpleAuction/AuctionEndTime.lean @@ -1,8 +1,7 @@ import Examples.SimpleAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/SimpleAuction/Beneficiary.lean b/Examples/SimpleAuction/Beneficiary.lean index 3fda9a9f..ea447536 100644 --- a/Examples/SimpleAuction/Beneficiary.lean +++ b/Examples/SimpleAuction/Beneficiary.lean @@ -1,8 +1,7 @@ import Examples.SimpleAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/SimpleAuction/Bid.lean b/Examples/SimpleAuction/Bid.lean index 9d129ac2..3a1e30ff 100644 --- a/Examples/SimpleAuction/Bid.lean +++ b/Examples/SimpleAuction/Bid.lean @@ -1,8 +1,7 @@ import Examples.SimpleAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/SimpleAuction/Correct.lean b/Examples/SimpleAuction/Correct.lean index 90d0b727..1a87accd 100644 --- a/Examples/SimpleAuction/Correct.lean +++ b/Examples/SimpleAuction/Correct.lean @@ -5,12 +5,11 @@ import Examples.SimpleAuction.Beneficiary import Examples.SimpleAuction.AuctionEndTime import Examples.SimpleAuction.HighestBidder import Examples.SimpleAuction.HighestBid -import Reasoning.Refinement import Reasoning.Initcode import Reasoning.Memory import Reasoning.Solc -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/SimpleAuction/HighestBid.lean b/Examples/SimpleAuction/HighestBid.lean index 232a3407..ee93cb4a 100644 --- a/Examples/SimpleAuction/HighestBid.lean +++ b/Examples/SimpleAuction/HighestBid.lean @@ -1,8 +1,7 @@ import Examples.SimpleAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/SimpleAuction/HighestBidder.lean b/Examples/SimpleAuction/HighestBidder.lean index 6687efe5..ab807f54 100644 --- a/Examples/SimpleAuction/HighestBidder.lean +++ b/Examples/SimpleAuction/HighestBidder.lean @@ -1,8 +1,7 @@ import Examples.SimpleAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/SimpleAuction/Withdraw.lean b/Examples/SimpleAuction/Withdraw.lean index 7da2df3d..6b22499b 100644 --- a/Examples/SimpleAuction/Withdraw.lean +++ b/Examples/SimpleAuction/Withdraw.lean @@ -1,9 +1,8 @@ import Examples.SimpleAuction.Storage -import Reasoning.Refinement import Reasoning.SolmBody import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Allowance.lean b/Examples/UniswapV2Pair/Allowance.lean index 6ebe7142..96cb2b4e 100644 --- a/Examples/UniswapV2Pair/Allowance.lean +++ b/Examples/UniswapV2Pair/Allowance.lean @@ -1,9 +1,8 @@ import Examples.UniswapV2Pair.ExternalWrappers import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Approve.lean b/Examples/UniswapV2Pair/Approve.lean index a29b236f..9ac79e92 100644 --- a/Examples/UniswapV2Pair/Approve.lean +++ b/Examples/UniswapV2Pair/Approve.lean @@ -1,9 +1,8 @@ import Examples.UniswapV2Pair.ExternalWrappers import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/BalanceCallSource.lean b/Examples/UniswapV2Pair/BalanceCallSource.lean index 0fdd212d..ff7f869b 100644 --- a/Examples/UniswapV2Pair/BalanceCallSource.lean +++ b/Examples/UniswapV2Pair/BalanceCallSource.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.Sync import Reasoning.ExternalCall -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/BalanceOf.lean b/Examples/UniswapV2Pair/BalanceOf.lean index 5c37531c..4ac47082 100644 --- a/Examples/UniswapV2Pair/BalanceOf.lean +++ b/Examples/UniswapV2Pair/BalanceOf.lean @@ -1,9 +1,8 @@ import Examples.UniswapV2Pair.ExternalWrappers import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Burn.lean b/Examples/UniswapV2Pair/Burn.lean index 4ce730a1..e4e50d0d 100644 --- a/Examples/UniswapV2Pair/Burn.lean +++ b/Examples/UniswapV2Pair/Burn.lean @@ -1,9 +1,8 @@ import Examples.UniswapV2Pair.ExternalWrappers import Examples.UniswapV2Pair.BurnRoutines import Examples.UniswapV2Pair.MutatorDispatch -import Reasoning.Refinement -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Common.lean b/Examples/UniswapV2Pair/Common.lean index 9aa14169..76373cf9 100644 --- a/Examples/UniswapV2Pair/Common.lean +++ b/Examples/UniswapV2Pair/Common.lean @@ -1,7 +1,6 @@ import Examples.UniswapV2Pair.Bytecode import Reasoning.ABI import Reasoning.Dispatch -import Reasoning.Refinement import Reasoning.Solc import Reasoning.SolmBody import Reasoning.Storage @@ -1102,7 +1101,7 @@ theorem uniswapCheckedTokenBalanceOfThisCallsPrefix (by simp [evalStorageRef, evalStorageRefSteps, token1Ref, EvalResult.bind, pure, bind]) (by decide) (by rfl) hcall1 hdec1 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using Reasoning.Refinement.execBlock_append htoken0 htoken1 + using.execBlock_append htoken0 htoken1 theorem uniswapCheckedTokenBalanceOfThisFirstCallNoCode (evm : EVM.State) (locals : Store) @@ -1117,7 +1116,7 @@ theorem uniswapCheckedTokenBalanceOfThisFirstCallNoCode exact uniswapCheckedExternalBalanceOfThisNoCode (evm := evm) (locals := locals) (ref := token0Ref) (retVar := "balance0") hguard0 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using Reasoning.Refinement.execBlock_append_term + using.execBlock_append_term (s2 := token1BalanceOfThisStmts "balance1") hfirst (by intro f e h; cases h) theorem uniswapCheckedTokenBalanceOfThisFirstCallFailure @@ -1141,7 +1140,7 @@ theorem uniswapCheckedTokenBalanceOfThisFirstCallFailure (by simp [evalStorageRef, evalStorageRefSteps, token0Ref, EvalResult.bind, pure, bind]) (by decide) (by rfl) hcall0 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using Reasoning.Refinement.execBlock_append_term + using.execBlock_append_term (s2 := token1BalanceOfThisStmts "balance1") hfirst (by intro f e h; cases h) theorem uniswapCheckedTokenBalanceOfThisFirstCallDecodeRevert @@ -1166,7 +1165,7 @@ theorem uniswapCheckedTokenBalanceOfThisFirstCallDecodeRevert (by simp [evalStorageRef, evalStorageRefSteps, token0Ref, EvalResult.bind, pure, bind]) (by decide) (by rfl) hcall0 hdec0 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using Reasoning.Refinement.execBlock_append_term + using.execBlock_append_term (s2 := token1BalanceOfThisStmts "balance1") hfirst (by intro f e h; cases h) theorem uniswapCheckedTokenBalanceOfThisSecondCallNoCode @@ -1201,7 +1200,7 @@ theorem uniswapCheckedTokenBalanceOfThisSecondCallNoCode (evm := evm0) (locals := locals.insert "balance0" balance0) (ref := token1Ref) (retVar := "balance1") hguard1 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using Reasoning.Refinement.execBlock_append htoken0 htoken1 + using.execBlock_append htoken0 htoken1 theorem uniswapCheckedTokenBalanceOfThisSecondCallFailure (evm evm0 evm1 : EVM.State) (locals : Store) @@ -1244,7 +1243,7 @@ theorem uniswapCheckedTokenBalanceOfThisSecondCallFailure (by simp [evalStorageRef, evalStorageRefSteps, token1Ref, EvalResult.bind, pure, bind]) (by decide) (by rfl) hcall1 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using Reasoning.Refinement.execBlock_append htoken0 htoken1 + using.execBlock_append htoken0 htoken1 theorem uniswapCheckedTokenBalanceOfThisSecondCallDecodeRevert (evm evm0 evm1 : EVM.State) (locals : Store) @@ -1288,7 +1287,7 @@ theorem uniswapCheckedTokenBalanceOfThisSecondCallDecodeRevert (by simp [evalStorageRef, evalStorageRefSteps, token1Ref, EvalResult.bind, pure, bind]) (by decide) (by rfl) hcall1 hdec1 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using Reasoning.Refinement.execBlock_append htoken0 htoken1 + using.execBlock_append htoken0 htoken1 theorem uniswapAddressGetterBodyReturns (evm : EVM.State) (locals : Store) {ref : StorageRef} {er : EvaledStorageRef} {slot : UInt256} @@ -1904,8 +1903,6 @@ end Reasoning.Reach namespace UniswapV2Pair -open Reasoning.Refinement - theorem uniswapAddressGetterBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {sel : UInt256} {transition : TransitionDecl} {entry routine slot : UInt256} diff --git a/Examples/UniswapV2Pair/Correct.lean b/Examples/UniswapV2Pair/Correct.lean index 872d2eeb..c450b984 100644 --- a/Examples/UniswapV2Pair/Correct.lean +++ b/Examples/UniswapV2Pair/Correct.lean @@ -39,7 +39,7 @@ The source, ABI, optimized runtime bytecode, and Solm specification are present. proof is intentionally left as the benchmark target. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace UniswapV2Pair diff --git a/Examples/UniswapV2Pair/Decimals.lean b/Examples/UniswapV2Pair/Decimals.lean index e6b3a73f..6f964c98 100644 --- a/Examples/UniswapV2Pair/Decimals.lean +++ b/Examples/UniswapV2Pair/Decimals.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Dispatch.lean b/Examples/UniswapV2Pair/Dispatch.lean index 173df79e..4b0c97f7 100644 --- a/Examples/UniswapV2Pair/Dispatch.lean +++ b/Examples/UniswapV2Pair/Dispatch.lean @@ -8,7 +8,7 @@ Small, bytecode-local dispatcher facts for the optimized binary selector tree. function body entries and are meant to feed the per-function `...BodyCore` lemmas from `Correct.lean`. -/ -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/DomainSeparator.lean b/Examples/UniswapV2Pair/DomainSeparator.lean index be47f027..4c71aeb6 100644 --- a/Examples/UniswapV2Pair/DomainSeparator.lean +++ b/Examples/UniswapV2Pair/DomainSeparator.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Factory.lean b/Examples/UniswapV2Pair/Factory.lean index 02178761..ac744194 100644 --- a/Examples/UniswapV2Pair/Factory.lean +++ b/Examples/UniswapV2Pair/Factory.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/GetReserves.lean b/Examples/UniswapV2Pair/GetReserves.lean index 657018cd..75afceac 100644 --- a/Examples/UniswapV2Pair/GetReserves.lean +++ b/Examples/UniswapV2Pair/GetReserves.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Initialize.lean b/Examples/UniswapV2Pair/Initialize.lean index 2d97659a..2ae84b83 100644 --- a/Examples/UniswapV2Pair/Initialize.lean +++ b/Examples/UniswapV2Pair/Initialize.lean @@ -1,10 +1,9 @@ import Examples.UniswapV2Pair.ExternalWrappers import Examples.UniswapV2Pair.Dispatch import Examples.UniswapV2Pair.TransferRoutines -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/KLast.lean b/Examples/UniswapV2Pair/KLast.lean index b037f064..12c0aa36 100644 --- a/Examples/UniswapV2Pair/KLast.lean +++ b/Examples/UniswapV2Pair/KLast.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MinimumLiquidity.lean b/Examples/UniswapV2Pair/MinimumLiquidity.lean index 1d6508f6..37b26b84 100644 --- a/Examples/UniswapV2Pair/MinimumLiquidity.lean +++ b/Examples/UniswapV2Pair/MinimumLiquidity.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Mint.lean b/Examples/UniswapV2Pair/Mint.lean index 4cdcfe95..7ba067d7 100644 --- a/Examples/UniswapV2Pair/Mint.lean +++ b/Examples/UniswapV2Pair/Mint.lean @@ -9,7 +9,7 @@ import Examples.UniswapV2Pair.MintFeeOnKLastNonzeroInitialFactoryCases import Examples.UniswapV2Pair.MintFeeOnKLastNonzeroRevertCases import Examples.UniswapV2Pair.MintProportionalProductOverflow import Examples.UniswapV2Pair.MintProportionalSecondMintFactoryCases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 namespace UniswapV2Pair set_option maxHeartbeats 3000000 in diff --git a/Examples/UniswapV2Pair/MintBodyPrelude.lean b/Examples/UniswapV2Pair/MintBodyPrelude.lean index 6605d3b2..616bc546 100644 --- a/Examples/UniswapV2Pair/MintBodyPrelude.lean +++ b/Examples/UniswapV2Pair/MintBodyPrelude.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintProportionalFinish -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintCommon.lean b/Examples/UniswapV2Pair/MintCommon.lean index dd0cd879..867f01a3 100644 --- a/Examples/UniswapV2Pair/MintCommon.lean +++ b/Examples/UniswapV2Pair/MintCommon.lean @@ -10,9 +10,8 @@ import Examples.UniswapV2Pair.Sync import Examples.UniswapV2Pair.SyncRuntime import Examples.UniswapV2Pair.UpdateRoutines import Reasoning.ExternalCall -import Reasoning.Refinement -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroFactoryCases.lean b/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroFactoryCases.lean index 42711212..f6927758 100644 --- a/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroFactoryCases.lean +++ b/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroFactoryCases.lean @@ -2,7 +2,7 @@ import Examples.UniswapV2Pair.MintProportionalFinish import Examples.UniswapV2Pair.MintFeeSqrtLoopBridge import Examples.UniswapV2Pair.MintRuntimeFitBridge -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroInitialFactoryCases.lean b/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroInitialFactoryCases.lean index 3a94104b..d7b83b78 100644 --- a/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroInitialFactoryCases.lean +++ b/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroInitialFactoryCases.lean @@ -3,7 +3,7 @@ import Examples.UniswapV2Pair.MintInitialFactoryReturnCases import Examples.UniswapV2Pair.MintInitialZeroCases import Examples.UniswapV2Pair.MintInitialProductOverflow -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroInitialOverflowCases.lean b/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroInitialOverflowCases.lean index 6e20ea67..295826a3 100644 --- a/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroInitialOverflowCases.lean +++ b/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroInitialOverflowCases.lean @@ -3,7 +3,7 @@ import Examples.UniswapV2Pair.MintInitialFactoryOverflowCases import Examples.UniswapV2Pair.MintInitialFactorySecondMintReverts import Examples.UniswapV2Pair.MintInitialFactorySecondMintBalanceReverts -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroRevertCases.lean b/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroRevertCases.lean index 755477b1..98a92b2f 100644 --- a/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroRevertCases.lean +++ b/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroRevertCases.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.MintFeeOnKLastNonzeroInitialOverflowCases import Examples.UniswapV2Pair.MintInternalMintReverts -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 @@ -340,7 +340,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_fromRootBlockRevert refine ExecFuncBody.execBlockRevert ?_ simpa [mintFeeFunction, mintFeeRootComparisonStmt, mintFeePositiveRootBranchStmts, List.append_assoc] using - Reasoning.Refinement.execBlock_append hchecked htail + .execBlock_append hchecked htail theorem uniswapMintFeeCallFromMint_feeOn_kLastNonzero_fromRootBlockRevert (reserveEvm callEvm evmFee : EVM.State) (I : ExecutionEnv) @@ -452,7 +452,7 @@ theorem uniswapMintAfterMintFeeReverts_of_call simpa [evmL, List.append_assoc] using execBlock_append hprefix hfeeBlock simpa [mintTransition, mintLiquidityBranchStmt, mintInitialLiquidityBranchStmts, mintProportionalLiquidityBranchStmts, mintAfterLiquidityTailStmts, List.append_assoc] using - (Reasoning.Refinement.execBlock_append_term + (Reasoning.Theory.execBlock_append_term (s2 := [ .letDecl "_totalSupply" (some uint256) (.storage totalSupplyRef), mintLiquidityBranchStmt ] ++ mintAfterLiquidityTailStmts) diff --git a/Examples/UniswapV2Pair/MintFeeRoutines.lean b/Examples/UniswapV2Pair/MintFeeRoutines.lean index 2648a7a8..7af7ae61 100644 --- a/Examples/UniswapV2Pair/MintFeeRoutines.lean +++ b/Examples/UniswapV2Pair/MintFeeRoutines.lean @@ -419,7 +419,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_fromRootBlock (ExecBlock.consReturn (ExecStmt.return (evalExprs?_singleton hreturn))) refine ExecFuncBody.execBlockRet ?_ simpa [mintFeeFunction, List.append_assoc] using - Reasoning.Refinement.execBlock_append hchecked htail + .execBlock_append hchecked htail theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_positiveNoLiquidity (evm evmFee : EVM.State) (reserve0 reserve1 : UInt256) {out : ByteArray} @@ -481,7 +481,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_positiveNoLiquidity (mintFeeKLastWord evmFee) rootK rootKLast) evmFee) := by simpa [mintFeeRootComparisonStmt, mintFeePositiveRootBranchStmts, List.append_assoc] - using Reasoning.Refinement.execBlock_append hprefix + using.execBlock_append hprefix (uniswapMintFeeAfterRoots_positiveNoLiquidity evmFee reserve0 reserve1 feeTo (mintFeeKLastWord evmFee) rootK rootKLast hroot hrootKNonneg hrootKSize hrootKLastNonneg hnumFit hrootFiveFit hdenFit hdenom hliq) @@ -561,7 +561,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_positiveWithLiquidity rootK rootKLast) (mintFunctionPostState evmFee feeTo (mintFeeLiquidityWord evmFee rootK rootKLast))) := by simpa [mintFeeRootComparisonStmt, mintFeePositiveRootBranchStmts, List.append_assoc] - using Reasoning.Refinement.execBlock_append hprefix + using.execBlock_append hprefix (uniswapMintFeeAfterRoots_positiveWithLiquidity evmFee reserve0 reserve1 feeTo (mintFeeKLastWord evmFee) rootK rootKLast hroot hrootKNonneg hrootKSize hrootKLastNonneg hnumFit hrootFiveFit hdenFit hdenom hliq hliqFit hfitSupply @@ -632,7 +632,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_noMint (mintFeeKLastWord evmFee) rootK rootKLast) evmFee) := by simpa [mintFeeRootComparisonStmt, mintFeePositiveRootBranchStmts, List.append_assoc] - using Reasoning.Refinement.execBlock_append hprefix + using.execBlock_append hprefix (uniswapMintFeeAfterRoots_noMint evmFee reserve0 reserve1 feeTo (mintFeeKLastWord evmFee) rootK rootKLast hroot) have htail : @@ -749,7 +749,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_noMint (mintFeeKLastWord evmFee) rootK rootKLast)))) refine ExecFuncBody.execBlockRet ?_ simpa [mintFeeFunction, List.append_assoc] using - Reasoning.Refinement.execBlock_append hchecked htail + .execBlock_append hchecked htail theorem mintFeeAssignKLastZero (evm : EVM.State) (reserve0 reserve1 : UInt256) (feeTo : AccountAddress) @@ -880,7 +880,7 @@ theorem uniswapMintFeeFunctionBody_feeOff_kLastZero (mintFeeKLastWord evmFee))))) refine ExecFuncBody.execBlockRet ?_ simpa [mintFeeFunction, List.append_assoc] using - Reasoning.Refinement.execBlock_append hchecked htail + .execBlock_append hchecked htail theorem uniswapMintFeeFunctionBody_feeOn_kLastZero (evm evmFee : EVM.State) (reserve0 reserve1 : UInt256) {out : ByteArray} @@ -1010,7 +1010,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastZero (mintFeeKLastWord evmFee))))) refine ExecFuncBody.execBlockRet ?_ simpa [mintFeeFunction, List.append_assoc] using - Reasoning.Refinement.execBlock_append hchecked htail + .execBlock_append hchecked htail theorem uniswapMintFeeFunctionBody_feeOff_kLastNonzero (evm evmFee : EVM.State) (reserve0 reserve1 : UInt256) {out : ByteArray} @@ -1137,7 +1137,7 @@ theorem uniswapMintFeeFunctionBody_feeOff_kLastNonzero feeTo false (mintFeeKLastWord evmFee))))) refine ExecFuncBody.execBlockRet ?_ simpa [mintFeeFunction, List.append_assoc] using - Reasoning.Refinement.execBlock_append hchecked htail + .execBlock_append hchecked htail end UniswapV2Pair diff --git a/Examples/UniswapV2Pair/MintFeeRoutinesCore.lean b/Examples/UniswapV2Pair/MintFeeRoutinesCore.lean index eb033e6d..651dcaab 100644 --- a/Examples/UniswapV2Pair/MintFeeRoutinesCore.lean +++ b/Examples/UniswapV2Pair/MintFeeRoutinesCore.lean @@ -1,6 +1,5 @@ import Examples.UniswapV2Pair.MathRoutines import Examples.UniswapV2Pair.MintRoutines -import Reasoning.Refinement import Reasoning.SolmBody open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach @@ -228,7 +227,7 @@ theorem uniswapMintFeeFunctionBody_reverts_noCode have hchecked := uniswapMintFeeCheckedCallNoCode evm reserve0 reserve1 hguard exact ExecFuncBody.execBlockRevert (by simpa [mintFeeFunction, List.append_assoc] using - (Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h))) + (Reasoning.Theory.execBlock_append_term hchecked (by intro f e h; cases h))) theorem uniswapMintFeeFunctionBody_reverts_callFailure (evm evmFee : EVM.State) (reserve0 reserve1 : UInt256) {out : ByteArray} @@ -243,7 +242,7 @@ theorem uniswapMintFeeFunctionBody_reverts_callFailure uniswapMintFeeCheckedCallFailure evm evmFee reserve0 reserve1 hguard hcall exact ExecFuncBody.execBlockRevert (by simpa [mintFeeFunction, List.append_assoc] using - (Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h))) + (Reasoning.Theory.execBlock_append_term hchecked (by intro f e h; cases h))) theorem uniswapMintFeeFunctionBody_reverts_decode (evm evmFee : EVM.State) (reserve0 reserve1 : UInt256) {out : ByteArray} @@ -259,7 +258,7 @@ theorem uniswapMintFeeFunctionBody_reverts_decode uniswapMintFeeCheckedCallDecodeRevert evm evmFee reserve0 reserve1 hguard hcall hdec exact ExecFuncBody.execBlockRevert (by simpa [mintFeeFunction, List.append_assoc] using - (Reasoning.Refinement.execBlock_append_term hchecked (by intro f e h; cases h))) + (Reasoning.Theory.execBlock_append_term hchecked (by intro f e h; cases h))) theorem uniswapMintFeeCheckedCallSuccess (evm evmFee : EVM.State) (reserve0 reserve1 : UInt256) {out : ByteArray} diff --git a/Examples/UniswapV2Pair/MintFeeRuntimeFactory.lean b/Examples/UniswapV2Pair/MintFeeRuntimeFactory.lean index 57ae1f74..5f7d569b 100644 --- a/Examples/UniswapV2Pair/MintFeeRuntimeFactory.lean +++ b/Examples/UniswapV2Pair/MintFeeRuntimeFactory.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintRuntimeBalance -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintFeeRuntimeSqrt.lean b/Examples/UniswapV2Pair/MintFeeRuntimeSqrt.lean index 98bc82e4..b87bc2ef 100644 --- a/Examples/UniswapV2Pair/MintFeeRuntimeSqrt.lean +++ b/Examples/UniswapV2Pair/MintFeeRuntimeSqrt.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintFeeRuntimeFactory -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintFeeSqrtSmall.lean b/Examples/UniswapV2Pair/MintFeeSqrtSmall.lean index c303e9d7..77d446ea 100644 --- a/Examples/UniswapV2Pair/MintFeeSqrtSmall.lean +++ b/Examples/UniswapV2Pair/MintFeeSqrtSmall.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintFeeRuntimeSqrt -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInitialCases.lean b/Examples/UniswapV2Pair/MintInitialCases.lean index 63cbb465..a26ee620 100644 --- a/Examples/UniswapV2Pair/MintInitialCases.lean +++ b/Examples/UniswapV2Pair/MintInitialCases.lean @@ -3,7 +3,7 @@ import Examples.UniswapV2Pair.MintSourcePrefixes import Examples.UniswapV2Pair.MintRuntimeFinalize import Examples.UniswapV2Pair.SyncCumulative -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInitialFactoryCases.lean b/Examples/UniswapV2Pair/MintInitialFactoryCases.lean index e6f44902..187b6beb 100644 --- a/Examples/UniswapV2Pair/MintInitialFactoryCases.lean +++ b/Examples/UniswapV2Pair/MintInitialFactoryCases.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintInitialCases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInitialFactoryOverflowCases.lean b/Examples/UniswapV2Pair/MintInitialFactoryOverflowCases.lean index 512ba724..e065173f 100644 --- a/Examples/UniswapV2Pair/MintInitialFactoryOverflowCases.lean +++ b/Examples/UniswapV2Pair/MintInitialFactoryOverflowCases.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.MintInitialMinimumMintReverts import Examples.UniswapV2Pair.MintRuntimeFitBridge -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInitialFactoryReturnCases.lean b/Examples/UniswapV2Pair/MintInitialFactoryReturnCases.lean index e43e4bff..e563f2ab 100644 --- a/Examples/UniswapV2Pair/MintInitialFactoryReturnCases.lean +++ b/Examples/UniswapV2Pair/MintInitialFactoryReturnCases.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintInitialCases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInitialFactoryRootCases.lean b/Examples/UniswapV2Pair/MintInitialFactoryRootCases.lean index 3070fc0a..d5c01181 100644 --- a/Examples/UniswapV2Pair/MintInitialFactoryRootCases.lean +++ b/Examples/UniswapV2Pair/MintInitialFactoryRootCases.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintInitialCases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInitialFactorySecondMintBalanceReverts.lean b/Examples/UniswapV2Pair/MintInitialFactorySecondMintBalanceReverts.lean index 556f8ad4..b5ee7b71 100644 --- a/Examples/UniswapV2Pair/MintInitialFactorySecondMintBalanceReverts.lean +++ b/Examples/UniswapV2Pair/MintInitialFactorySecondMintBalanceReverts.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintInitialFactorySecondMintReverts -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInitialFactorySecondMintReverts.lean b/Examples/UniswapV2Pair/MintInitialFactorySecondMintReverts.lean index 75710d9f..eab8b781 100644 --- a/Examples/UniswapV2Pair/MintInitialFactorySecondMintReverts.lean +++ b/Examples/UniswapV2Pair/MintInitialFactorySecondMintReverts.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintInitialSecondMintReverts -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInitialFactoryZeroCases.lean b/Examples/UniswapV2Pair/MintInitialFactoryZeroCases.lean index 773fb6e4..45414cf1 100644 --- a/Examples/UniswapV2Pair/MintInitialFactoryZeroCases.lean +++ b/Examples/UniswapV2Pair/MintInitialFactoryZeroCases.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintInitialZeroCases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInitialMinimumMintReverts.lean b/Examples/UniswapV2Pair/MintInitialMinimumMintReverts.lean index 3324165f..ac8dc400 100644 --- a/Examples/UniswapV2Pair/MintInitialMinimumMintReverts.lean +++ b/Examples/UniswapV2Pair/MintInitialMinimumMintReverts.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.MintInitialCases import Examples.UniswapV2Pair.MintInternalMintReverts -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInitialProductOverflow.lean b/Examples/UniswapV2Pair/MintInitialProductOverflow.lean index a9989b03..a1ddd546 100644 --- a/Examples/UniswapV2Pair/MintInitialProductOverflow.lean +++ b/Examples/UniswapV2Pair/MintInitialProductOverflow.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintInitialFactoryOverflowCases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInitialSecondMintReverts.lean b/Examples/UniswapV2Pair/MintInitialSecondMintReverts.lean index fd0c5c6b..6c96ef49 100644 --- a/Examples/UniswapV2Pair/MintInitialSecondMintReverts.lean +++ b/Examples/UniswapV2Pair/MintInitialSecondMintReverts.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintInitialMinimumMintReverts -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInitialSqrtBridge.lean b/Examples/UniswapV2Pair/MintInitialSqrtBridge.lean index 998ea290..0f467eaa 100644 --- a/Examples/UniswapV2Pair/MintInitialSqrtBridge.lean +++ b/Examples/UniswapV2Pair/MintInitialSqrtBridge.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.MintFeeSqrtLoopBridge import Examples.UniswapV2Pair.MintRuntimeAfterFee -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInitialZeroCases.lean b/Examples/UniswapV2Pair/MintInitialZeroCases.lean index a6eb251f..1c514dc1 100644 --- a/Examples/UniswapV2Pair/MintInitialZeroCases.lean +++ b/Examples/UniswapV2Pair/MintInitialZeroCases.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.MintInitialCases import Examples.UniswapV2Pair.MintLiquidityZeroRuntime -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInternalMintReverts.lean b/Examples/UniswapV2Pair/MintInternalMintReverts.lean index cba04488..e7a47839 100644 --- a/Examples/UniswapV2Pair/MintInternalMintReverts.lean +++ b/Examples/UniswapV2Pair/MintInternalMintReverts.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintInternalMintRuntime -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintInternalMintRuntime.lean b/Examples/UniswapV2Pair/MintInternalMintRuntime.lean index a1b6e04b..dd3f2a7f 100644 --- a/Examples/UniswapV2Pair/MintInternalMintRuntime.lean +++ b/Examples/UniswapV2Pair/MintInternalMintRuntime.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintFeeRuntimeSqrt -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintLiquidityZeroCases.lean b/Examples/UniswapV2Pair/MintLiquidityZeroCases.lean index a87584ea..c1650358 100644 --- a/Examples/UniswapV2Pair/MintLiquidityZeroCases.lean +++ b/Examples/UniswapV2Pair/MintLiquidityZeroCases.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.MintLiquidityZeroRuntime import Examples.UniswapV2Pair.MintSourceCases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintLiquidityZeroFactoryCases.lean b/Examples/UniswapV2Pair/MintLiquidityZeroFactoryCases.lean index a33d1823..7dafe902 100644 --- a/Examples/UniswapV2Pair/MintLiquidityZeroFactoryCases.lean +++ b/Examples/UniswapV2Pair/MintLiquidityZeroFactoryCases.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintLiquidityZeroCases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintLiquidityZeroRuntime.lean b/Examples/UniswapV2Pair/MintLiquidityZeroRuntime.lean index ff76c203..22cc89f0 100644 --- a/Examples/UniswapV2Pair/MintLiquidityZeroRuntime.lean +++ b/Examples/UniswapV2Pair/MintLiquidityZeroRuntime.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintRuntimeAfterFee -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintProportionalFinish.lean b/Examples/UniswapV2Pair/MintProportionalFinish.lean index ca5d39ad..57dc2b84 100644 --- a/Examples/UniswapV2Pair/MintProportionalFinish.lean +++ b/Examples/UniswapV2Pair/MintProportionalFinish.lean @@ -3,7 +3,7 @@ import Examples.UniswapV2Pair.MintInternalMintRuntime import Examples.UniswapV2Pair.MintFeeSqrtSmall import Examples.UniswapV2Pair.SyncCumulative -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintProportionalProductOverflow.lean b/Examples/UniswapV2Pair/MintProportionalProductOverflow.lean index 6ad0fd9e..5bc7ad3b 100644 --- a/Examples/UniswapV2Pair/MintProportionalProductOverflow.lean +++ b/Examples/UniswapV2Pair/MintProportionalProductOverflow.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.MintInitialProductOverflow import Examples.UniswapV2Pair.MintLiquidityZeroCases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintProportionalSecondMintFactoryCases.lean b/Examples/UniswapV2Pair/MintProportionalSecondMintFactoryCases.lean index a8a6b07a..86c926be 100644 --- a/Examples/UniswapV2Pair/MintProportionalSecondMintFactoryCases.lean +++ b/Examples/UniswapV2Pair/MintProportionalSecondMintFactoryCases.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintProportionalSecondMintFactoryKLastNonzeroReverts -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintProportionalSecondMintFactoryKLastNonzeroReverts.lean b/Examples/UniswapV2Pair/MintProportionalSecondMintFactoryKLastNonzeroReverts.lean index 75ae9298..34657072 100644 --- a/Examples/UniswapV2Pair/MintProportionalSecondMintFactoryKLastNonzeroReverts.lean +++ b/Examples/UniswapV2Pair/MintProportionalSecondMintFactoryKLastNonzeroReverts.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintProportionalSecondMintFactoryReverts -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintProportionalSecondMintFactoryReverts.lean b/Examples/UniswapV2Pair/MintProportionalSecondMintFactoryReverts.lean index 1e75dabc..8af8ee5c 100644 --- a/Examples/UniswapV2Pair/MintProportionalSecondMintFactoryReverts.lean +++ b/Examples/UniswapV2Pair/MintProportionalSecondMintFactoryReverts.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintProportionalSecondMintReverts -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintProportionalSecondMintReverts.lean b/Examples/UniswapV2Pair/MintProportionalSecondMintReverts.lean index 756a7073..a6ef1e05 100644 --- a/Examples/UniswapV2Pair/MintProportionalSecondMintReverts.lean +++ b/Examples/UniswapV2Pair/MintProportionalSecondMintReverts.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.MintInitialSecondMintReverts import Examples.UniswapV2Pair.MintProportionalFinish -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintRuntimeAfterFee.lean b/Examples/UniswapV2Pair/MintRuntimeAfterFee.lean index 96e7ffdd..71355d92 100644 --- a/Examples/UniswapV2Pair/MintRuntimeAfterFee.lean +++ b/Examples/UniswapV2Pair/MintRuntimeAfterFee.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintInternalMintRuntime -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintRuntimeBalance.lean b/Examples/UniswapV2Pair/MintRuntimeBalance.lean index 6e287586..6a625d43 100644 --- a/Examples/UniswapV2Pair/MintRuntimeBalance.lean +++ b/Examples/UniswapV2Pair/MintRuntimeBalance.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintSourceCases -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintRuntimeFinalize.lean b/Examples/UniswapV2Pair/MintRuntimeFinalize.lean index f71421b3..11cc8895 100644 --- a/Examples/UniswapV2Pair/MintRuntimeFinalize.lean +++ b/Examples/UniswapV2Pair/MintRuntimeFinalize.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.MintRuntimeAfterFee import Examples.UniswapV2Pair.SyncCumulative -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintSourceCases.lean b/Examples/UniswapV2Pair/MintSourceCases.lean index 42dcf5b0..c82278ea 100644 --- a/Examples/UniswapV2Pair/MintSourceCases.lean +++ b/Examples/UniswapV2Pair/MintSourceCases.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintSourcePrefixes -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintSourcePrefixes.lean b/Examples/UniswapV2Pair/MintSourcePrefixes.lean index 99b6f2ae..f4f20724 100644 --- a/Examples/UniswapV2Pair/MintSourcePrefixes.lean +++ b/Examples/UniswapV2Pair/MintSourcePrefixes.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MintSourceReturns -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MintSourceReturns.lean b/Examples/UniswapV2Pair/MintSourceReturns.lean index 1663674a..2528e983 100644 --- a/Examples/UniswapV2Pair/MintSourceReturns.lean +++ b/Examples/UniswapV2Pair/MintSourceReturns.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.MintCommon import Examples.UniswapV2Pair.SyncBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/MutatorDispatch.lean b/Examples/UniswapV2Pair/MutatorDispatch.lean index de03fcfd..e99ab6e6 100644 --- a/Examples/UniswapV2Pair/MutatorDispatch.lean +++ b/Examples/UniswapV2Pair/MutatorDispatch.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.Dispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Name.lean b/Examples/UniswapV2Pair/Name.lean index 4da36cf1..33c858f5 100644 --- a/Examples/UniswapV2Pair/Name.lean +++ b/Examples/UniswapV2Pair/Name.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.StringReturn -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Nonces.lean b/Examples/UniswapV2Pair/Nonces.lean index be32522a..d90b55bb 100644 --- a/Examples/UniswapV2Pair/Nonces.lean +++ b/Examples/UniswapV2Pair/Nonces.lean @@ -1,9 +1,8 @@ import Examples.UniswapV2Pair.ExternalWrappers import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Permit.lean b/Examples/UniswapV2Pair/Permit.lean index b2a9741f..f19cee14 100644 --- a/Examples/UniswapV2Pair/Permit.lean +++ b/Examples/UniswapV2Pair/Permit.lean @@ -2,9 +2,8 @@ import Examples.UniswapV2Pair.MutatorDispatch import Examples.UniswapV2Pair.PermitDecode import Examples.UniswapV2Pair.PermitRuntime import Reasoning.ExternalCall -import Reasoning.Refinement -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/UniswapV2Pair/PermitDecode.lean b/Examples/UniswapV2Pair/PermitDecode.lean index 41f26f3d..d9562941 100644 --- a/Examples/UniswapV2Pair/PermitDecode.lean +++ b/Examples/UniswapV2Pair/PermitDecode.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.MutatorDispatch -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace UniswapV2Pair diff --git a/Examples/UniswapV2Pair/PermitRuntime.lean b/Examples/UniswapV2Pair/PermitRuntime.lean index 1277c660..b4174206 100644 --- a/Examples/UniswapV2Pair/PermitRuntime.lean +++ b/Examples/UniswapV2Pair/PermitRuntime.lean @@ -1,9 +1,8 @@ import Examples.UniswapV2Pair.MutatorDispatch import Examples.UniswapV2Pair.Routines import Reasoning.MemCascade -import Reasoning.Refinement -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/UniswapV2Pair/PermitTypehash.lean b/Examples/UniswapV2Pair/PermitTypehash.lean index 58bfc11e..bb67a876 100644 --- a/Examples/UniswapV2Pair/PermitTypehash.lean +++ b/Examples/UniswapV2Pair/PermitTypehash.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Price0CumulativeLast.lean b/Examples/UniswapV2Pair/Price0CumulativeLast.lean index 8e1b2a7a..9a9f2bdb 100644 --- a/Examples/UniswapV2Pair/Price0CumulativeLast.lean +++ b/Examples/UniswapV2Pair/Price0CumulativeLast.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Price1CumulativeLast.lean b/Examples/UniswapV2Pair/Price1CumulativeLast.lean index 587e318c..948b5bef 100644 --- a/Examples/UniswapV2Pair/Price1CumulativeLast.lean +++ b/Examples/UniswapV2Pair/Price1CumulativeLast.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SafeTransfer.lean b/Examples/UniswapV2Pair/SafeTransfer.lean index 35696c55..b9de3583 100644 --- a/Examples/UniswapV2Pair/SafeTransfer.lean +++ b/Examples/UniswapV2Pair/SafeTransfer.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.Common -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SafeTransferRuntime.lean b/Examples/UniswapV2Pair/SafeTransferRuntime.lean index 6d8aa8b7..f5147431 100644 --- a/Examples/UniswapV2Pair/SafeTransferRuntime.lean +++ b/Examples/UniswapV2Pair/SafeTransferRuntime.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.SkimSafeTransferReturn -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Skim.lean b/Examples/UniswapV2Pair/Skim.lean index 24b4ecb6..d765d8ad 100644 --- a/Examples/UniswapV2Pair/Skim.lean +++ b/Examples/UniswapV2Pair/Skim.lean @@ -9,7 +9,7 @@ import Examples.UniswapV2Pair.SkimSource import Reasoning.ExternalCall import Ethereum.Theory.StaticStorage -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SkimCommon.lean b/Examples/UniswapV2Pair/SkimCommon.lean index e9be9ef1..c61345bb 100644 --- a/Examples/UniswapV2Pair/SkimCommon.lean +++ b/Examples/UniswapV2Pair/SkimCommon.lean @@ -3,10 +3,9 @@ import Examples.UniswapV2Pair.SafeTransfer import Examples.UniswapV2Pair.ExternalWrappers import Examples.UniswapV2Pair.ExternalCalls import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SkimRuntime.lean b/Examples/UniswapV2Pair/SkimRuntime.lean index 1933b932..16ba2011 100644 --- a/Examples/UniswapV2Pair/SkimRuntime.lean +++ b/Examples/UniswapV2Pair/SkimRuntime.lean @@ -4,7 +4,7 @@ import Examples.UniswapV2Pair.ExternalCalls import Examples.UniswapV2Pair.TransferRoutines import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SkimSafeTransferCalldata.lean b/Examples/UniswapV2Pair/SkimSafeTransferCalldata.lean index f7518699..95b19c29 100644 --- a/Examples/UniswapV2Pair/SkimSafeTransferCalldata.lean +++ b/Examples/UniswapV2Pair/SkimSafeTransferCalldata.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.SkimCommon import Reasoning.MemCascade -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 namespace UniswapV2Pair diff --git a/Examples/UniswapV2Pair/SkimSafeTransferDynamicRuntime.lean b/Examples/UniswapV2Pair/SkimSafeTransferDynamicRuntime.lean index f4fad386..c6258a66 100644 --- a/Examples/UniswapV2Pair/SkimSafeTransferDynamicRuntime.lean +++ b/Examples/UniswapV2Pair/SkimSafeTransferDynamicRuntime.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.SkimSafeTransferReturn -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SkimSafeTransferReturn.lean b/Examples/UniswapV2Pair/SkimSafeTransferReturn.lean index 5b07e815..431cccbc 100644 --- a/Examples/UniswapV2Pair/SkimSafeTransferReturn.lean +++ b/Examples/UniswapV2Pair/SkimSafeTransferReturn.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.SkimSafeTransferRuntime -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SkimSafeTransferRuntime.lean b/Examples/UniswapV2Pair/SkimSafeTransferRuntime.lean index cbf7e818..6dd9b37e 100644 --- a/Examples/UniswapV2Pair/SkimSafeTransferRuntime.lean +++ b/Examples/UniswapV2Pair/SkimSafeTransferRuntime.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.SkimRuntime import Examples.UniswapV2Pair.StringReturn -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicCalldataRuntime.lean b/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicCalldataRuntime.lean index c9fd1e3f..7a583335 100644 --- a/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicCalldataRuntime.lean +++ b/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicCalldataRuntime.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.SkimSecondSafeTransferDynamicOffsetReturnRuntime -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach namespace UniswapV2Pair diff --git a/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetReturnRuntime.lean b/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetReturnRuntime.lean index 530678e3..4d3874ce 100644 --- a/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetReturnRuntime.lean +++ b/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetReturnRuntime.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.SkimSecondSafeTransferDynamicOffsetRuntime -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetRuntime.lean b/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetRuntime.lean index 15c4ba62..395a5bcf 100644 --- a/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetRuntime.lean +++ b/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetRuntime.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.SkimDynamicSecondRuntime import Examples.UniswapV2Pair.SkimSecondSafeTransferDynamicRuntime -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicRuntime.lean b/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicRuntime.lean index 655902d1..f6f7f048 100644 --- a/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicRuntime.lean +++ b/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicRuntime.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.SkimSecondSafeTransferRuntime import Examples.UniswapV2Pair.SkimSafeTransferReturn -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SkimSecondSafeTransferRuntime.lean b/Examples/UniswapV2Pair/SkimSecondSafeTransferRuntime.lean index 21a1bd73..98bd2f32 100644 --- a/Examples/UniswapV2Pair/SkimSecondSafeTransferRuntime.lean +++ b/Examples/UniswapV2Pair/SkimSecondSafeTransferRuntime.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.SkimSecondRuntime -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SkimSource.lean b/Examples/UniswapV2Pair/SkimSource.lean index e4a5a868..98047567 100644 --- a/Examples/UniswapV2Pair/SkimSource.lean +++ b/Examples/UniswapV2Pair/SkimSource.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.SkimCommon -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/StringReturn.lean b/Examples/UniswapV2Pair/StringReturn.lean index 4cbe78f7..a69a9498 100644 --- a/Examples/UniswapV2Pair/StringReturn.lean +++ b/Examples/UniswapV2Pair/StringReturn.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.Dispatch import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Swap.lean b/Examples/UniswapV2Pair/Swap.lean index d50614db..d80e9a48 100644 --- a/Examples/UniswapV2Pair/Swap.lean +++ b/Examples/UniswapV2Pair/Swap.lean @@ -1,7 +1,6 @@ import Examples.UniswapV2Pair.MutatorDispatch -import Reasoning.Refinement -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 2000000 diff --git a/Examples/UniswapV2Pair/Symbol.lean b/Examples/UniswapV2Pair/Symbol.lean index d4d896a5..ba657351 100644 --- a/Examples/UniswapV2Pair/Symbol.lean +++ b/Examples/UniswapV2Pair/Symbol.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.StringReturn -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Sync.lean b/Examples/UniswapV2Pair/Sync.lean index 921cdfc8..8a39a62d 100644 --- a/Examples/UniswapV2Pair/Sync.lean +++ b/Examples/UniswapV2Pair/Sync.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.SyncRuntime -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SyncBody.lean b/Examples/UniswapV2Pair/SyncBody.lean index 845cd7fc..cfbd4aed 100644 --- a/Examples/UniswapV2Pair/SyncBody.lean +++ b/Examples/UniswapV2Pair/SyncBody.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.SyncCumulative import Examples.UniswapV2Pair.BalanceCallSource -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SyncCumulative.lean b/Examples/UniswapV2Pair/SyncCumulative.lean index 2bd42df2..ab652dc1 100644 --- a/Examples/UniswapV2Pair/SyncCumulative.lean +++ b/Examples/UniswapV2Pair/SyncCumulative.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.Sync -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/SyncRuntime.lean b/Examples/UniswapV2Pair/SyncRuntime.lean index a3d00896..6f514250 100644 --- a/Examples/UniswapV2Pair/SyncRuntime.lean +++ b/Examples/UniswapV2Pair/SyncRuntime.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.ExternalCalls import Examples.UniswapV2Pair.UpdateRoutines -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Token0.lean b/Examples/UniswapV2Pair/Token0.lean index d31a3003..8a8c42bd 100644 --- a/Examples/UniswapV2Pair/Token0.lean +++ b/Examples/UniswapV2Pair/Token0.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Token1.lean b/Examples/UniswapV2Pair/Token1.lean index 2989c64b..0ae29353 100644 --- a/Examples/UniswapV2Pair/Token1.lean +++ b/Examples/UniswapV2Pair/Token1.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/TotalSupply.lean b/Examples/UniswapV2Pair/TotalSupply.lean index 3ddb6259..e350da1b 100644 --- a/Examples/UniswapV2Pair/TotalSupply.lean +++ b/Examples/UniswapV2Pair/TotalSupply.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/Transfer.lean b/Examples/UniswapV2Pair/Transfer.lean index 7d9fabd3..a83e4df8 100644 --- a/Examples/UniswapV2Pair/Transfer.lean +++ b/Examples/UniswapV2Pair/Transfer.lean @@ -1,10 +1,9 @@ import Examples.UniswapV2Pair.ExternalWrappers import Examples.UniswapV2Pair.TransferRoutines import Examples.UniswapV2Pair.Dispatch -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 1000000 diff --git a/Examples/UniswapV2Pair/TransferFrom.lean b/Examples/UniswapV2Pair/TransferFrom.lean index e318781e..7fa074ff 100644 --- a/Examples/UniswapV2Pair/TransferFrom.lean +++ b/Examples/UniswapV2Pair/TransferFrom.lean @@ -1,8 +1,7 @@ import Examples.UniswapV2Pair.TransferRoutines -import Reasoning.Refinement import Reasoning.SolmBody -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/TransferFromDecode.lean b/Examples/UniswapV2Pair/TransferFromDecode.lean index d6050e9d..056dcc68 100644 --- a/Examples/UniswapV2Pair/TransferFromDecode.lean +++ b/Examples/UniswapV2Pair/TransferFromDecode.lean @@ -5,7 +5,7 @@ import Examples.UniswapV2Pair.TransferFromMaskedFinite import Examples.UniswapV2Pair.TransferFromSuccess import Examples.UniswapV2Pair.TransferFromReverts -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/TransferFromFinite.lean b/Examples/UniswapV2Pair/TransferFromFinite.lean index 06487581..bacb30f8 100644 --- a/Examples/UniswapV2Pair/TransferFromFinite.lean +++ b/Examples/UniswapV2Pair/TransferFromFinite.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.Dispatch import Examples.UniswapV2Pair.TransferFrom -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/TransferFromMasked.lean b/Examples/UniswapV2Pair/TransferFromMasked.lean index 459e9743..50825064 100644 --- a/Examples/UniswapV2Pair/TransferFromMasked.lean +++ b/Examples/UniswapV2Pair/TransferFromMasked.lean @@ -2,7 +2,7 @@ import Examples.UniswapV2Pair.ExternalWrappers import Examples.UniswapV2Pair.Dispatch import Examples.UniswapV2Pair.TransferFrom -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/TransferFromMaskedFinite.lean b/Examples/UniswapV2Pair/TransferFromMaskedFinite.lean index 02915f87..8346c7d1 100644 --- a/Examples/UniswapV2Pair/TransferFromMaskedFinite.lean +++ b/Examples/UniswapV2Pair/TransferFromMaskedFinite.lean @@ -1,6 +1,6 @@ import Examples.UniswapV2Pair.TransferFromMasked -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/TransferFromReverts.lean b/Examples/UniswapV2Pair/TransferFromReverts.lean index ce1dbfb5..ef2b01bb 100644 --- a/Examples/UniswapV2Pair/TransferFromReverts.lean +++ b/Examples/UniswapV2Pair/TransferFromReverts.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.Dispatch import Examples.UniswapV2Pair.TransferFrom -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/UniswapV2Pair/TransferFromSuccess.lean b/Examples/UniswapV2Pair/TransferFromSuccess.lean index 747703f0..0ac81d27 100644 --- a/Examples/UniswapV2Pair/TransferFromSuccess.lean +++ b/Examples/UniswapV2Pair/TransferFromSuccess.lean @@ -1,7 +1,7 @@ import Examples.UniswapV2Pair.Dispatch import Examples.UniswapV2Pair.TransferFromFinite -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/VyperERC20/Allowance.lean b/Examples/VyperERC20/Allowance.lean index 211d6d47..bed1ccb4 100644 --- a/Examples/VyperERC20/Allowance.lean +++ b/Examples/VyperERC20/Allowance.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.BalanceOf -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unusedSimpArgs false diff --git a/Examples/VyperERC20/Approve.lean b/Examples/VyperERC20/Approve.lean index ed424496..f80ec855 100644 --- a/Examples/VyperERC20/Approve.lean +++ b/Examples/VyperERC20/Approve.lean @@ -1,7 +1,7 @@ import Examples.VyperERC20.Allowance import Examples.ERC20.Approve -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unusedSimpArgs false diff --git a/Examples/VyperERC20/BalanceOf.lean b/Examples/VyperERC20/BalanceOf.lean index 44dd3394..d6efa726 100644 --- a/Examples/VyperERC20/BalanceOf.lean +++ b/Examples/VyperERC20/BalanceOf.lean @@ -1,9 +1,8 @@ import Examples.VyperERC20.TotalSupply import Examples.VyperERC20.Storage import Examples.ERC20.Common -import Reasoning.Refinement -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option linter.unusedSimpArgs false diff --git a/Examples/VyperERC20/TotalSupply.lean b/Examples/VyperERC20/TotalSupply.lean index 88329a8b..299f5477 100644 --- a/Examples/VyperERC20/TotalSupply.lean +++ b/Examples/VyperERC20/TotalSupply.lean @@ -1,9 +1,8 @@ import Examples.VyperERC20.Bytecode import Examples.VyperERC20.Storage import Examples.ERC20.Common -import Reasoning.Refinement -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 diff --git a/Examples/VyperERC20/Transfer.lean b/Examples/VyperERC20/Transfer.lean index 68004e46..4fbb4f92 100644 --- a/Examples/VyperERC20/Transfer.lean +++ b/Examples/VyperERC20/Transfer.lean @@ -1,8 +1,7 @@ import Examples.VyperERC20.Approve import Reasoning.Initcode -import Reasoning.Refinement -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 4000000 diff --git a/Examples/VyperERC20/TransferFromAllowancePhase.lean b/Examples/VyperERC20/TransferFromAllowancePhase.lean index 9f49fcb9..d3e54404 100644 --- a/Examples/VyperERC20/TransferFromAllowancePhase.lean +++ b/Examples/VyperERC20/TransferFromAllowancePhase.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromBase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromAllowanceStoreFinish.lean b/Examples/VyperERC20/TransferFromAllowanceStoreFinish.lean index 44240fd0..77a40dc7 100644 --- a/Examples/VyperERC20/TransferFromAllowanceStoreFinish.lean +++ b/Examples/VyperERC20/TransferFromAllowanceStoreFinish.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromAllowanceStoreOuterPhase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromAllowanceStoreGuard.lean b/Examples/VyperERC20/TransferFromAllowanceStoreGuard.lean index 652ca38a..23a17c10 100644 --- a/Examples/VyperERC20/TransferFromAllowanceStoreGuard.lean +++ b/Examples/VyperERC20/TransferFromAllowanceStoreGuard.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromBalanceLoadPhase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromAllowanceStoreInnerHashStore.lean b/Examples/VyperERC20/TransferFromAllowanceStoreInnerHashStore.lean index 83207eb4..4b664e3d 100644 --- a/Examples/VyperERC20/TransferFromAllowanceStoreInnerHashStore.lean +++ b/Examples/VyperERC20/TransferFromAllowanceStoreInnerHashStore.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromAllowanceStoreInnerKeyStore -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromAllowanceStoreInnerKeyReady.lean b/Examples/VyperERC20/TransferFromAllowanceStoreInnerKeyReady.lean index 36766ddb..6a4f98b6 100644 --- a/Examples/VyperERC20/TransferFromAllowanceStoreInnerKeyReady.lean +++ b/Examples/VyperERC20/TransferFromAllowanceStoreInnerKeyReady.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromAllowanceStoreInnerLoad -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromAllowanceStoreInnerKeyStore.lean b/Examples/VyperERC20/TransferFromAllowanceStoreInnerKeyStore.lean index a145441e..baf82df7 100644 --- a/Examples/VyperERC20/TransferFromAllowanceStoreInnerKeyStore.lean +++ b/Examples/VyperERC20/TransferFromAllowanceStoreInnerKeyStore.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromAllowanceStoreInnerKeyReady -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromAllowanceStoreInnerLoad.lean b/Examples/VyperERC20/TransferFromAllowanceStoreInnerLoad.lean index 0c856fee..6f75e875 100644 --- a/Examples/VyperERC20/TransferFromAllowanceStoreInnerLoad.lean +++ b/Examples/VyperERC20/TransferFromAllowanceStoreInnerLoad.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromAllowanceStoreGuard -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromAllowanceStoreOuterFinish.lean b/Examples/VyperERC20/TransferFromAllowanceStoreOuterFinish.lean index 0030c3c7..3eaf4eb9 100644 --- a/Examples/VyperERC20/TransferFromAllowanceStoreOuterFinish.lean +++ b/Examples/VyperERC20/TransferFromAllowanceStoreOuterFinish.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromAllowanceStoreOuterHashStore -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromAllowanceStoreOuterHashStore.lean b/Examples/VyperERC20/TransferFromAllowanceStoreOuterHashStore.lean index 078aaedf..e3b6b031 100644 --- a/Examples/VyperERC20/TransferFromAllowanceStoreOuterHashStore.lean +++ b/Examples/VyperERC20/TransferFromAllowanceStoreOuterHashStore.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromAllowanceStoreOuterKeyStore -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromAllowanceStoreOuterKeyReady.lean b/Examples/VyperERC20/TransferFromAllowanceStoreOuterKeyReady.lean index 4022f62f..e9e48a5a 100644 --- a/Examples/VyperERC20/TransferFromAllowanceStoreOuterKeyReady.lean +++ b/Examples/VyperERC20/TransferFromAllowanceStoreOuterKeyReady.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromAllowanceStorePrep -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromAllowanceStoreOuterKeyStore.lean b/Examples/VyperERC20/TransferFromAllowanceStoreOuterKeyStore.lean index 00179cff..1a94f009 100644 --- a/Examples/VyperERC20/TransferFromAllowanceStoreOuterKeyStore.lean +++ b/Examples/VyperERC20/TransferFromAllowanceStoreOuterKeyStore.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromAllowanceStoreOuterKeyReady -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromAllowanceStoreOuterPhase.lean b/Examples/VyperERC20/TransferFromAllowanceStoreOuterPhase.lean index 63f84927..8bb7a39d 100644 --- a/Examples/VyperERC20/TransferFromAllowanceStoreOuterPhase.lean +++ b/Examples/VyperERC20/TransferFromAllowanceStoreOuterPhase.lean @@ -1,7 +1,7 @@ import Examples.VyperERC20.TransferFromAllowanceStoreOuterPrefix import Examples.VyperERC20.TransferFromAllowanceStoreOuterFinish -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromAllowanceStoreOuterPrefix.lean b/Examples/VyperERC20/TransferFromAllowanceStoreOuterPrefix.lean index 056d06af..b1d2dcd3 100644 --- a/Examples/VyperERC20/TransferFromAllowanceStoreOuterPrefix.lean +++ b/Examples/VyperERC20/TransferFromAllowanceStoreOuterPrefix.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromAllowanceStoreOuterHashStore -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromAllowanceStorePrep.lean b/Examples/VyperERC20/TransferFromAllowanceStorePrep.lean index 3d2bd370..1fd4ab3d 100644 --- a/Examples/VyperERC20/TransferFromAllowanceStorePrep.lean +++ b/Examples/VyperERC20/TransferFromAllowanceStorePrep.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromAllowanceStoreInnerHashStore -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromBalanceLoadPhase.lean b/Examples/VyperERC20/TransferFromBalanceLoadPhase.lean index ddd70a0e..5d847001 100644 --- a/Examples/VyperERC20/TransferFromBalanceLoadPhase.lean +++ b/Examples/VyperERC20/TransferFromBalanceLoadPhase.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromAllowancePhase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromBase.lean b/Examples/VyperERC20/TransferFromBase.lean index ee11f03e..47b6383e 100644 --- a/Examples/VyperERC20/TransferFromBase.lean +++ b/Examples/VyperERC20/TransferFromBase.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.Transfer -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromRuntime.lean b/Examples/VyperERC20/TransferFromRuntime.lean index 97e2bf10..80a26af0 100644 --- a/Examples/VyperERC20/TransferFromRuntime.lean +++ b/Examples/VyperERC20/TransferFromRuntime.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFrom -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromStoresAfterFromLoadHashStore.lean b/Examples/VyperERC20/TransferFromStoresAfterFromLoadHashStore.lean index e83b88fe..c1cfae6e 100644 --- a/Examples/VyperERC20/TransferFromStoresAfterFromLoadHashStore.lean +++ b/Examples/VyperERC20/TransferFromStoresAfterFromLoadHashStore.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromStoresAfterFromLoadKeyStore -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromStoresAfterFromLoadKeyReady.lean b/Examples/VyperERC20/TransferFromStoresAfterFromLoadKeyReady.lean index 95296593..e35dac59 100644 --- a/Examples/VyperERC20/TransferFromStoresAfterFromLoadKeyReady.lean +++ b/Examples/VyperERC20/TransferFromStoresAfterFromLoadKeyReady.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromStoresAfterFromLoadSetup -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromStoresAfterFromLoadKeyStore.lean b/Examples/VyperERC20/TransferFromStoresAfterFromLoadKeyStore.lean index 9ebb613a..1a1197e9 100644 --- a/Examples/VyperERC20/TransferFromStoresAfterFromLoadKeyStore.lean +++ b/Examples/VyperERC20/TransferFromStoresAfterFromLoadKeyStore.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromStoresAfterFromLoadKeyReady -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromStoresAfterFromLoadSetup.lean b/Examples/VyperERC20/TransferFromStoresAfterFromLoadSetup.lean index c0a0bc70..5a534e50 100644 --- a/Examples/VyperERC20/TransferFromStoresAfterFromLoadSetup.lean +++ b/Examples/VyperERC20/TransferFromStoresAfterFromLoadSetup.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromAllowance -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromStoresAfterFromLoadSlot.lean b/Examples/VyperERC20/TransferFromStoresAfterFromLoadSlot.lean index b013a4b1..d1d5481d 100644 --- a/Examples/VyperERC20/TransferFromStoresAfterFromLoadSlot.lean +++ b/Examples/VyperERC20/TransferFromStoresAfterFromLoadSlot.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromStoresAfterFromLoadHashStore -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromStoresAfterFromStore.lean b/Examples/VyperERC20/TransferFromStoresAfterFromStore.lean index 75a9f3fd..942bb433 100644 --- a/Examples/VyperERC20/TransferFromStoresAfterFromStore.lean +++ b/Examples/VyperERC20/TransferFromStoresAfterFromStore.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromStoresBeforeFromStore -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromStoresBeforeFromStore.lean b/Examples/VyperERC20/TransferFromStoresBeforeFromStore.lean index d3817407..06ca7948 100644 --- a/Examples/VyperERC20/TransferFromStoresBeforeFromStore.lean +++ b/Examples/VyperERC20/TransferFromStoresBeforeFromStore.lean @@ -1,7 +1,7 @@ import Examples.VyperERC20.TransferFromStoresAfterFromLoadSlot import Examples.VyperERC20.TransferFromStoresBeforeFromStoreCore -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromStoresBeforeFromStoreCore.lean b/Examples/VyperERC20/TransferFromStoresBeforeFromStoreCore.lean index b979d0a2..e3f16479 100644 --- a/Examples/VyperERC20/TransferFromStoresBeforeFromStoreCore.lean +++ b/Examples/VyperERC20/TransferFromStoresBeforeFromStoreCore.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromBase -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromStoresFrom.lean b/Examples/VyperERC20/TransferFromStoresFrom.lean index 8a7a2230..849634bd 100644 --- a/Examples/VyperERC20/TransferFromStoresFrom.lean +++ b/Examples/VyperERC20/TransferFromStoresFrom.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromStoresBeforeFromStore -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromStoresLog.lean b/Examples/VyperERC20/TransferFromStoresLog.lean index e2ad8103..3ff7bf12 100644 --- a/Examples/VyperERC20/TransferFromStoresLog.lean +++ b/Examples/VyperERC20/TransferFromStoresLog.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromStoresTo -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/Examples/VyperERC20/TransferFromStoresTo.lean b/Examples/VyperERC20/TransferFromStoresTo.lean index 20fcdfb2..ce9ea081 100644 --- a/Examples/VyperERC20/TransferFromStoresTo.lean +++ b/Examples/VyperERC20/TransferFromStoresTo.lean @@ -1,6 +1,6 @@ import Examples.VyperERC20.TransferFromStoresAfterFromStore -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach Reasoning.Refinement +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach set_option maxRecDepth 2000000 set_option maxHeartbeats 20000000 diff --git a/LICENSE b/LICENSE index b52090af..b109d23a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2026 Argot Collective +Copyright (c) 2026 Argot Collective, Zoe Paraskevopoulou, Lefteris Lazaropoulos Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Reasoning/ABI.lean b/Reasoning/ABI.lean index 7cf7fb82..68f2060c 100644 --- a/Reasoning/ABI.lean +++ b/Reasoning/ABI.lean @@ -1669,12 +1669,6 @@ theorem decodeABIValue_bytes32_ok {bytes : List UInt8} {start : Nat} rw [if_pos hlen] simp [zeroPadding?, readBytes?] -theorem decodeABIValue_bytes32_none_short {bytes : List UInt8} {start : Nat} - (hshort : ¬ ((bytes.drop start).take 32).length = 32) : - decodeABIValue? abiBytes32 bytes start = none := by - simp only [abiBytes32, abiBytes32Width, decodeABIValue?, readBytes?, bind, Option.bind] - rw [if_neg hshort] - theorem decodeABIValues_bytes32_address_ok {bytes : List UInt8} (hlen0 : (bytes.take 32).length = 32) (hlen32 : ((bytes.drop 32).take 32).length = 32) @@ -1876,32 +1870,6 @@ theorem decodeScalarWords_addr_uint256_none_short {bytes : List UInt8} (by simpa using hcanon)] simp only [Option.bind, bind] -theorem decodeABIValues_addr_uint256_ok {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) - (hlen32 : ((bytes.drop 32).take 32).length = 32) - (hcanon : (ABI.bytesToWord (bytes.take 32)).toNat < EVM.addressModulus) : - decodeABIValues? [.elem .address, abiUInt256] bytes 0 0 64 64 = - some ([.address (Ethereum.AccountAddress.ofNat (ABI.bytesToWord (bytes.take 32)).toNat), - .int (Int.ofNat (ABI.bytesToWord ((bytes.drop 32).take 32)).toNat)], 64) := by - rw [decodeABIValues_scalarWords_eq (types := [.elem .address, abiUInt256]) - (bytes := bytes) (cursor := 0) (total := 64) (by decide) (by norm_num)] - rw [decodeScalarWords_addr_uint256_ok hlen0 hlen32 hcanon] - -theorem decodeABIValues_addr_uint256_none_noncanon {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) - (hnc : ¬ (ABI.bytesToWord (bytes.take 32)).toNat < EVM.addressModulus) : - decodeABIValues? [.elem .address, abiUInt256] bytes 0 0 64 64 = none := by - rw [decodeABIValues_scalarWords_eq (types := [.elem .address, abiUInt256]) - (bytes := bytes) (cursor := 0) (total := 64) (by decide) (by norm_num)] - rw [decodeScalarWords_addr_uint256_none_noncanon hlen0 hnc] - -theorem decodeABIValues_addr_uint256_none_short {bytes : List UInt8} - (hshort : bytes.length < 64) : - decodeABIValues? [.elem .address, abiUInt256] bytes 0 0 64 64 = none := by - rw [decodeABIValues_scalarWords_eq (types := [.elem .address, abiUInt256]) - (bytes := bytes) (cursor := 0) (total := 64) (by decide) (by norm_num)] - rw [decodeScalarWords_addr_uint256_none_short hshort] - theorem decodeCalldata_addr_uint256_ok {cd : ByteArray} {x y : Solm.Ident} (hsz68 : 68 ≤ cd.size) (hbig : cd.size < 2 ^ 255 + 4) (hcanon : (calldataWord cd 4).toNat < EVM.addressModulus) : @@ -4343,50 +4311,6 @@ theorem decodeABIValue_dynamicArray_bytes32_lookup_shape {bytes : List UInt8} /-! ## Return decoding -/ -theorem decodeReturnValue_uint256_ok {returndata : ByteArray} - (hlo : 32 ≤ returndata.size) (hhi : returndata.size < (2 : Nat) ^ 255) : - ABI.decodeReturnValue? abiUInt256 returndata = - some (.int (Int.ofNat (fromByteArrayBigEndian (returndata.extract 0 32)))) := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have htake0 : (returndata.toList.take 32).length = 32 := by - rw [List.length_take, hlen] - omega - have hword := bytesToWord_take32_eq_extract0_32 (returndata := returndata) - unfold ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [abiUInt256]) (returndata := returndata) - (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - rw [decodeScalarWords_uint256_ok (bytes := returndata.toList) htake0] - simp [hword, UInt256.toNat_ofNat_of_lt (fromByteArrayBigEndian_extract0_32_lt hlo)] - -theorem decodeReturnValue_uint256_none_short {returndata : ByteArray} - (hshort : returndata.size < 32) : - ABI.decodeReturnValue? abiUInt256 returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - unfold ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [abiUInt256]) (returndata := returndata) - (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - rw [decodeScalarWords_uint256_none_short (bytes := returndata.toList) (by rw [hlen]; omega)] - -theorem decodeReturnValue_uint256_none_huge {returndata : ByteArray} - (hhuge : (2 : Nat) ^ 255 ≤ returndata.size) : - ABI.decodeReturnValue? abiUInt256 returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - unfold ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [abiUInt256]) (returndata := returndata) - (by decide)] - rw [if_pos (by exact ⟨by simp, by rw [hlen]; exact hhuge⟩)] - /-! ## Return-value (`RETURN`) ABI encoding -/ /-- **Scalar RETURN-encoding core.** Given a scalar value `v` whose ABI encoding is the 32 diff --git a/Reasoning/ExternalCall.lean b/Reasoning/ExternalCall.lean index f857f98f..be0fc5ba 100644 --- a/Reasoning/ExternalCall.lean +++ b/Reasoning/ExternalCall.lean @@ -566,182 +566,6 @@ theorem callViaEVM_initState_accountMapEquiv {storage : StorageLayout} accountMapEquiv evm'_evm.accountMap σ'_solm := callViaEVM_initState_accountMapEquiv_perm (storage := storage) hcall hAccounts -/-- `EVMStateEquiv`-returning form of raw low-level call transport, generic over the `callPerm` - flag. -/ -theorem callViaEVM_initState_EVMStateEquiv_perm {storage : StorageLayout} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} - {evm'_evm : EVM.State} {tgt : EVM.Address} {value : ℤ} {calldata : ByteArray} - {z : Bool} {out : ByteArray} {callPerm : Bool} - (hcall : callViaEVM (initState cA gh bl σ_evm σ₀ g A I) tgt value calldata - (z, evm'_evm, out) callPerm) - (hEnv : evm'_evm.executionEnv = (initState cA gh bl σ_solm σ₀ g A I).executionEnv) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - ∃ (σ'_solm : AccountMap) (A'_solm : Substate), - callViaEVM (initState cA gh bl σ_solm σ₀ g A I) tgt value calldata - (z, - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := evm'_evm.createdAccounts }, - out) callPerm ∧ - EVMStateEquiv evm'_evm - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := evm'_evm.createdAccounts } := by - obtain ⟨σ'_solm, A'_solm, hcall_solm, hσ'⟩ := - callViaEVM_initState_accountMapEquiv_perm (storage := storage) hcall hAccounts - exact ⟨σ'_solm, A'_solm, hcall_solm, hEnv, rfl, hσ'⟩ - -/-- `EVMStateEquiv`-returning form of raw low-level call transport at the default call - permission. -/ -theorem callViaEVM_initState_EVMStateEquiv {storage : StorageLayout} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} - {evm'_evm : EVM.State} {tgt : EVM.Address} {value : ℤ} {calldata : ByteArray} - {z : Bool} {out : ByteArray} - (hcall : callViaEVM (initState cA gh bl σ_evm σ₀ g A I) tgt value calldata - (z, evm'_evm, out)) - (hEnv : evm'_evm.executionEnv = (initState cA gh bl σ_solm σ₀ g A I).executionEnv) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - ∃ (σ'_solm : AccountMap) (A'_solm : Substate), - callViaEVM (initState cA gh bl σ_solm σ₀ g A I) tgt value calldata - (z, - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := evm'_evm.createdAccounts }, - out) ∧ - EVMStateEquiv evm'_evm - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := evm'_evm.createdAccounts } := - callViaEVM_initState_EVMStateEquiv_perm (storage := storage) hcall hEnv hAccounts - -theorem delegateCallViaEVM_executionEnv_eq {evm evm' : EVM.State} - {target : EVM.Address} {calldata : ByteArray} {z : Bool} {out : ByteArray} - (hcall : delegateCallViaEVM evm target calldata (z, evm', out)) : - evm'.executionEnv = evm.executionEnv := by - cases hcall with - | callMade _hTheta hevm' _hdepth => - subst hevm' - rfl - | callNotMade _hsubstate hevm' _hdepth => - subst hevm' - rfl - -/-- Raw delegatecall transport across observationally equivalent account maps. -/ -theorem delegateCallViaEVM_accountMapEquiv - {evm_evm evm_solm evm'_evm : EVM.State} - {tgt : EVM.Address} {calldata : ByteArray} {z : Bool} {out : ByteArray} - (hcall : delegateCallViaEVM evm_evm tgt calldata (z, evm'_evm, out)) - (hAccounts : accountMapEquiv evm_evm.accountMap evm_solm.accountMap) - (hOriginalAccounts : evm_evm.σ₀ = evm_solm.σ₀) - (hCreated : evm_solm.createdAccounts = evm_evm.createdAccounts) - (hGenesis : evm_solm.genesisBlockHeader = evm_evm.genesisBlockHeader) - (hBlocks : evm_solm.blocks = evm_evm.blocks) - (_hSubstate : evm_solm.substate = evm_evm.substate) - (hEnv : evm_solm.executionEnv = evm_evm.executionEnv) : - ∃ (σ'_solm : AccountMap) (A'_solm : Substate), - delegateCallViaEVM evm_solm tgt calldata - (z, - { evm_solm with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := evm'_evm.createdAccounts }, - out) ∧ - accountMapEquiv evm'_evm.accountMap σ'_solm := by - cases hcall with - | callMade hTheta hevm' hdepth => - obtain ⟨callGas, A_in, hTheta⟩ := hTheta - rename_i cA' σ' g' A' - obtain ⟨σ'_solm, g''_solm, A'_solm, hTheta_s', hσ'⟩ := - Theta_transport_accountMapEquiv (tgt := tgt) hAccounts hOriginalAccounts hCreated - hGenesis hBlocks hTheta - have hCreated' : evm'_evm.createdAccounts = cA' := by simp [hevm'] - -- restate the transported Θ witness in the Solm-side environment - have hTheta_s : - (evm'_evm.createdAccounts, σ'_solm, g''_solm, A'_solm, z, out) = - Ethereum.EVM.Θ evm_solm.executionEnv.blobVersionedHashes evm_solm.createdAccounts - evm_solm.genesisBlockHeader evm_solm.blocks evm_solm.accountMap evm_solm.σ₀ A_in - evm_solm.executionEnv.source evm_solm.executionEnv.sender - evm_solm.executionEnv.codeOwner (toExecute evm_solm.accountMap tgt) callGas - (UInt256.ofNat evm_solm.executionEnv.gasPrice) (⟨0⟩ : UInt256) - evm_solm.executionEnv.weiValue calldata (evm_solm.executionEnv.depth + 1) - evm_solm.executionEnv.header evm_solm.executionEnv.perm := by - rw [hEnv, hCreated'] - exact hTheta_s' - use σ'_solm - use A'_solm - constructor - · exact delegateCallViaEVM.callMade - ⟨callGas, A_in, hTheta_s⟩ rfl (by rw [hEnv]; exact hdepth) - · simpa [hevm'] using hσ' - | callNotMade hsubstate hevm' hdepth => - let A' := (State.addAccessedAccount evm_solm tgt).substate - use evm_solm.accountMap - use A' - constructor - · apply delegateCallViaEVM.callNotMade - · rfl - · simp [A', hCreated, hevm'] - · rw [hEnv] - exact hdepth - · simpa [hevm'] using hAccounts - -/-- `initState`-specialized raw delegatecall transport. -/ -theorem delegateCallViaEVM_initState_accountMapEquiv - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} - {evm'_evm : EVM.State} {tgt : EVM.Address} {calldata : ByteArray} - {z : Bool} {out : ByteArray} - (hcall : delegateCallViaEVM (initState cA gh bl σ_evm σ₀ g A I) tgt calldata - (z, evm'_evm, out)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - ∃ (σ'_solm : AccountMap) (A'_solm : Substate), - delegateCallViaEVM (initState cA gh bl σ_solm σ₀ g A I) tgt calldata - (z, - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := evm'_evm.createdAccounts }, - out) ∧ - accountMapEquiv evm'_evm.accountMap σ'_solm := - delegateCallViaEVM_accountMapEquiv - (evm_solm := initState cA gh bl σ_solm σ₀ g A I) hcall - (by simpa [initState] using hAccounts) - (by simp [initState]) - (by simp [initState]) - (by simp [initState]) - (by simp [initState]) - (by simp [initState]) - (by simp [initState]) - -/-- `EVMStateEquiv`-returning form of raw delegatecall transport. -/ -theorem delegateCallViaEVM_initState_EVMStateEquiv - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} - {evm'_evm : EVM.State} {tgt : EVM.Address} {calldata : ByteArray} - {z : Bool} {out : ByteArray} - (hcall : delegateCallViaEVM (initState cA gh bl σ_evm σ₀ g A I) tgt calldata - (z, evm'_evm, out)) - (hEnv : evm'_evm.executionEnv = (initState cA gh bl σ_solm σ₀ g A I).executionEnv) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - ∃ (σ'_solm : AccountMap) (A'_solm : Substate), - delegateCallViaEVM (initState cA gh bl σ_solm σ₀ g A I) tgt calldata - (z, - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := evm'_evm.createdAccounts }, - out) ∧ - EVMStateEquiv evm'_evm - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := evm'_evm.createdAccounts } := by - obtain ⟨σ'_solm, A'_solm, hcall_solm, hσ'⟩ := - delegateCallViaEVM_initState_accountMapEquiv hcall hAccounts - exact ⟨σ'_solm, A'_solm, hcall_solm, hEnv, rfl, hσ'⟩ - /-- **Coincidence (call not made).** At the call-depth limit (`evm.depth = 1024`) the EVM `CALL` returns `0` *without* invoking `Θ`; the Solm `typedCallViaEVM` takes the matching `callNotMade` branch — `(false, evm[substate], ∅)` — independent of value/balance. Generic over diff --git a/Reasoning/Memory.lean b/Reasoning/Memory.lean index 08c88d66..e0a88f6d 100644 --- a/Reasoning/Memory.lean +++ b/Reasoning/Memory.lean @@ -70,12 +70,6 @@ theorem fromBytes'_toBytes' (x : ℕ) : fromBytes' (toBytes' x) = x := by simp [UInt8.size] exact Nat.mod_add_div _ _ -/-- Big-endian round-trip: decoding the big-endian bytes of `x` gives back `x`. -/ -theorem fromBytesBigEndian_toBytesBigEndian (x : ℕ) : - fromBytesBigEndian (toBytesBigEndian x) = x := by - simp only [fromBytesBigEndian, toBytesBigEndian, Function.comp, List.reverse_reverse] - exact fromBytes'_toBytes' x - /-- Nonnegative integers are embedded as their natural-value EVM word. -/ theorem wordOfInt_nonneg (i : Int) (h0 : 0 ≤ i) : EVM.wordOfInt i = EVM.word i.toNat := by @@ -137,10 +131,6 @@ theorem fromBytes'_drop_wordLE (w : UInt256) (n : Nat) : rw [fromBytes'_eq_ofDigits (bs.drop n), List.map_drop] rw [← hdrop, hfull] -theorem fromBytes'_drop1_wordLE (w : UInt256) : - fromBytes' ((EVM.Word.toBytesLEWithSizeProof w).1.drop 1) = w.toNat / 256 := by - simpa using fromBytes'_drop_wordLE w 1 - theorem fromBytes'_take_wordLE_land_mask (w : UInt256) (n : Nat) (hbits : 8 * n ≤ 256) : fromBytes' ((EVM.Word.toBytesLEWithSizeProof w).1.take n) = (UInt256.land w (UInt256.ofNat (2 ^ (8 * n) - 1))).toNat := by @@ -1403,14 +1393,6 @@ theorem fromBytes'_inj_of_length {xs ys : List UInt8} congr exact ih hlen htail -theorem toBytesLEWithSizeProof_fromBytes'_pad32 (bs : List UInt8) - (hlen : bs.length = 32) {hfit : fromBytes' bs < UInt256.size} : - (EVM.Word.toBytesLEWithSizeProof ({ val := ⟨fromBytes' bs, hfit⟩ } : UInt256)).1 = bs := by - apply fromBytes'_inj_of_length - · rw [(EVM.Word.toBytesLEWithSizeProof ({ val := ⟨fromBytes' bs, hfit⟩ } : UInt256)).2, hlen] - · rw [fromBytes'_toBytesLEWithSizeProof] - rfl - theorem fromBytesBigEndian_inj_of_length {xs ys : List UInt8} (hlen : xs.length = ys.length) (h : fromBytesBigEndian xs = fromBytesBigEndian ys) : xs = ys := by @@ -1567,14 +1549,5 @@ theorem mappingSlot_single (key baseSlot : UInt256) : = uInt256OfByteArray (ffi.KEC (key.toByteArray ++ baseSlot.toByteArray)) := keccakSlot_eq _ -/-- **Load coupling.** The word `RD.sload` pushes (storage of `codeOwner` at `slot`, read from the - carried `accountMap`) is exactly the Solm-level `storageLoad` of the same account/slot — so a - mapping `SLOAD` at the keccak slot reads the same word the Solm spec's `storageLocLoad` decodes. -/ -theorem sloadVal_eq_storageLoad (self : EVM.State) (slot : UInt256) : - (self.accountMap.find? self.executionEnv.codeOwner |>.option ⟨0⟩ - (fun acc => acc.storage.findD slot ⟨0⟩)) - = Solm.EVM.storageLoad self self.executionEnv.codeOwner slot := - rfl - end Reasoning.Theory diff --git a/Reasoning/Reach.lean b/Reasoning/Reach.lean index f688ad2d..3667b66c 100644 --- a/Reasoning/Reach.lean +++ b/Reasoning/Reach.lean @@ -60,6 +60,11 @@ def RD (code : ByteArray) (ee : ExecutionEnv) (g : Sat256) (s0 : State) ∧ s.executionEnv = ee ∧ RDWorld s0 s +/-- The persistent **world** carried by an EVM state: its created accounts and storage map. This is + the only part of the state the two executions are required to agree on (between external calls). -/ +def worldOf (s : State) : Batteries.RBSet AccountAddress compare × AccountMap := + (s.createdAccounts, s.accountMap) + /-- The EVM **reach-cursor**: the six fields `RD` pins on the underlying `State` at a program point — the transient machine state `pc`/`stack`/`mem`/`aw`/`rdata`, plus the persistent `world` (`createdAccounts × accountMap`, where contract storage lives). `RDc` below is `RD` indexed by a diff --git a/Reasoning/Refinement.lean b/Reasoning/Refinement.lean deleted file mode 100644 index 1563429a..00000000 --- a/Reasoning/Refinement.lean +++ /dev/null @@ -1,1181 +0,0 @@ -import Reasoning.Dispatch - -/-! -# Refinement — proof-side bridges: straight-line EVM runs ⟹ the equivalence statements - -Only `runtimeEquivalenceFor` lives in `Solm.Equiv`. The *relational* per-block and per-function -judgments — generic `equivStmts` (statement-list logic parameterized by an `ExecResult` -postcondition), `equivTransitionStmts` (the externally-dispatched body interpretation), and -`equivTransition` (one function's EVM body ≈ its Solm body) — mention the EVM `RD`/`RDret`/`RDrev` -discipline, so they live here, together with the bridges up the ladder: - -* segment rules (`nil`/`consNormal`/`consReturn`/`consRevert`/`consBreak`/`consContinue`/ - `consequence`) — discharge a straight-line statement segment by symbolic execution on both sides - (`RD` + `ExecStmt`), leaving the result meaning to the chosen postcondition. -* `equivStmts.toTransition` — externally-dispatched body logic ⟹ `equivTransition`. -* `equivTransition.toRuntime` — `equivTransition` + dispatch/decoding ⟹ `runtimeEquivalenceFor`. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -namespace Reasoning.Refinement - -/-- The persistent **world** carried by an EVM state: its created accounts and storage map. This is - the only part of the state the two executions are required to agree on (between external calls). -/ -def worldOf (s : State) : Batteries.RBSet AccountAddress compare × AccountMap := - (s.createdAccounts, s.accountMap) - -/-- A relation coupling an EVM reach-`Cursor` to the Solm execution state (frame + threaded EVM - state). It carries the *non-`pc`, non-world* part of the coupling — e.g. which stack/memory - slots hold which locals — and is only constrained where it matters (call arguments, return - value). The structural rules are agnostic to what a `StateRel` actually says. -/ -abbrev StateRel := Cursor → Frame → State → Prop - -namespace StateRel - -/-- Mechanically transform a relation across one concrete proof step. The new relation pins the - new cursor/frame/EVM state exactly and retains the old relation fact at the old state. -/ -def stepFrom (R : StateRel) (cur0 : Cursor) (frame0 : Frame) (evm0 : State) - (cur1 : Cursor) (frame1 : Frame) (evm1 : State) : StateRel := - fun cur frame evm => cur = cur1 ∧ frame = frame1 ∧ evm = evm1 ∧ R cur0 frame0 evm0 - -theorem stepFrom_here {R : StateRel} {cur0 cur1 : Cursor} {frame0 frame1 : Frame} - {evm0 evm1 : State} (hrel : R cur0 frame0 evm0) : - StateRel.stepFrom R cur0 frame0 evm0 cur1 frame1 evm1 cur1 frame1 evm1 := by - exact ⟨rfl, rfl, rfl, hrel⟩ - -end StateRel - -/-- A locals-only variant of `StateRel`. This is useful for internal/callable bodies: their entry - and exit frames may differ in the surrounding contract context, but most coupling facts only - mention the local store. -/ -abbrev StoreRel := Cursor → Store → State → Prop - -/-- A postcondition over a Solm block result. The postcondition is where each client decides what - `.ok`, `.returned`, `.break`, `.continue`, and `.reverted` mean on the EVM side. -/ -abbrev StmtPost := ExecResult → Prop - -/-- A concrete coupled proof state. - - This is the proof-mode counterpart of `RD`: it keeps the original EVM initial state `s0`, the - current reachable EVM cursor with its `RDc` evidence, and the current Solm frame/threaded EVM - state with the active coupling relation. Unlike `equivStmts`, this does not quantify over all - possible entries; it represents the single state currently being symbolically advanced. -/ -structure CoupledState (code : ByteArray) (ee : ExecutionEnv) (g : Sat256) (s0 : State) - (R : StateRel) (pc : UInt256) where - cur : Cursor - k : ℕ - C : ℕ - frame : Frame - evm : State - hpc : cur.pc = pc - hRD : RDc code ee g s0 cur k C - hworld : cur.world = worldOf evm - hrel : R cur frame evm - -/-- Cursor packaging for positional `RD` facts. -/ -def cursorOfRD (pc : UInt256) (stack : List UInt256) (mem : ByteArray) - (aw : UInt256) (rdata : ByteArray) - (world : Batteries.RBSet AccountAddress compare × AccountMap) : Cursor := - { pc := pc, stack := stack, mem := mem, aw := aw, rdata := rdata, world := world } - -/-- Package a reached cursor and coupled Solm state as a concrete proof state. -/ -def CoupledState.reached {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : StateRel} {pc : UInt256} - (cur : Cursor) (k C : ℕ) (frame : Frame) (evm : State) - (hpc : cur.pc = pc) (hRD : RDc code ee g s0 cur k C) - (hworld : cur.world = worldOf evm) (hrel : R cur frame evm) : - CoupledState code ee g s0 R pc := - { cur := cur, k := k, C := C, frame := frame, evm := evm, - hpc := hpc, hRD := hRD, hworld := hworld, hrel := hrel } - -/-- Package a positional `RD` fact directly as a concrete coupled proof state. This hides the - routine `RD → RDc` conversion at handoff points where bytecode helpers still expose positional - reachability. -/ -def CoupledState.ofRD {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : StateRel} {pc : UInt256} - {stack : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {world : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (frame : Frame) (evm : State) - (hRD : RD code ee g s0 pc stack mem aw rdata world k C) - (hworld : world = worldOf evm) - (hrel : R (cursorOfRD pc stack mem aw rdata world) frame evm) : - CoupledState code ee g s0 R pc := by - let cur := cursorOfRD pc stack mem aw rdata world - have hRDc : RDc code ee g s0 cur k C := by - change RD code ee g s0 cur.pc cur.stack cur.mem cur.aw cur.rdata cur.world k C - simpa [cur, cursorOfRD] using hRD - have hworld' : cur.world = worldOf evm := by - simpa [cur, cursorOfRD] using hworld - exact CoupledState.reached cur k C frame evm rfl hRDc hworld' hrel - -/-- Advance a coupled state using a positional `RD` fact and a mechanical relation transform. -/ -def CoupledState.stepRD {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : StateRel} {pc pc' : UInt256} - {stack' : List UInt256} {mem' : ByteArray} {aw' : UInt256} {rdata' : ByteArray} - {world' : Batteries.RBSet AccountAddress compare × AccountMap} {k' C' : ℕ} - (st : CoupledState code ee g s0 R pc) - (frame' : Frame) (evm' : State) - (hRD : RD code ee g s0 pc' stack' mem' aw' rdata' world' k' C') - (hworld : world' = worldOf evm') : - CoupledState code ee g s0 - (StateRel.stepFrom R st.cur st.frame st.evm - (cursorOfRD pc' stack' mem' aw' rdata' world') frame' evm') pc' := - CoupledState.ofRD frame' evm' hRD hworld (StateRel.stepFrom_here st.hrel) - -/-- Convert the cursor-indexed reachability proof stored in a coupled state into the positional - `RD` form expected by `evm_run`, after exposing the cursor fields used by the local relation. -/ -theorem CoupledState.toRD {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : StateRel} {pc : UInt256} (st : CoupledState code ee g s0 R pc) - {stack : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - (hstack : st.cur.stack = stack) (hmem : st.cur.mem = mem) - (haw : st.cur.aw = aw) (hrdata : st.cur.rdata = rdata) : - RD code ee g s0 pc stack mem aw rdata st.cur.world st.k st.C := by - have hRD := st.hRD - unfold RDc at hRD - rw [st.hpc, hstack, hmem, haw, hrdata] at hRD - exact hRD - -/-- Concrete statement-list equivalence from one coupled proof state. -/ -def CoupledState.refines {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : StateRel} {pc : UInt256} - (st : CoupledState code ee g s0 R pc) (cfg : Config) - (stmts : List Stmt) (Post : StmtPost) : Prop := - ∃ result, ExecBlock cfg st.frame st.evm stmts result ∧ Post result - -/-- **Generic statement-list equivalence** `{R} stmts ~ bytecode@pc {Post}`. - - From an entry cursor the run has reached (`cur.pc = pc`, `RDc`), with the world coupled - (`cur.world = worldOf evm`) and the rest coupled by `R`, the Solm block *runs* to some - `ExecResult`, and the caller-supplied `Post` explains the matching EVM-side fact for that result. - - This deliberately does not assign a fixed meaning to `.returned`, `.break`, or `.continue`. - Externally-dispatched transition bodies, internal callables, and loop bodies instantiate `Post` - differently. -/ -def equivStmts (code : ByteArray) (ee : ExecutionEnv) (g : Sat256) (s0 : State) - (cfg : Config) (pc : UInt256) (R : StateRel) (stmts : List Stmt) - (Post : StmtPost) : Prop := - ∀ cur k C frame evm, - cur.pc = pc → - RDc code ee g s0 cur k C → - cur.world = worldOf evm → - R cur frame evm → - ∃ result, ExecBlock cfg frame evm stmts result ∧ Post result - -/-- A quantified `equivStmts` theorem can be used at any concrete coupled proof state. -/ -theorem equivStmts.toAt {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc : UInt256} {R : StateRel} {stmts : List Stmt} {Post : StmtPost} - (h : equivStmts code ee g s0 cfg pc R stmts Post) - (st : CoupledState code ee g s0 R pc) : - CoupledState.refines st cfg stmts Post := - h st.cur st.k st.C st.frame st.evm st.hpc st.hRD st.hworld st.hrel - -/-- Build a quantified `equivStmts` theorem from a proof that works for every concrete coupled - proof state. -/ -theorem equivStmts.ofAt {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc : UInt256} {R : StateRel} {stmts : List Stmt} {Post : StmtPost} - (h : ∀ st : CoupledState code ee g s0 R pc, CoupledState.refines st cfg stmts Post) : - equivStmts code ee g s0 cfg pc R stmts Post := by - intro cur k C frame evm hpc hRD hw hR - exact h (CoupledState.mk cur k C frame evm hpc hRD hw hR) - -/-- A normal fall-through postcondition: the block must finish with `.ok` at a reached cursor. -/ -def normalPost (code : ByteArray) (ee : ExecutionEnv) (g : Sat256) (s0 : State) - (Q : StateRel) : StmtPost - | .ok frame' evm' => - ∃ cur' k' C', RDc code ee g s0 cur' k' C' ∧ cur'.world = worldOf evm' - ∧ Q cur' frame' evm' - | .returned _ _ _ | .reverted | .break _ _ | .continue _ _ => - False - -/-- Concrete **nil** rule. -/ -theorem CoupledState.refines.nil {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc : UInt256} {R : StateRel} - (st : CoupledState code ee g s0 R pc) : - CoupledState.refines st cfg [] (normalPost code ee g s0 R) := by - exact ⟨.ok st.frame st.evm, ExecBlock.nil, st.cur, st.k, st.C, st.hRD, st.hworld, st.hrel⟩ - -/-- Concrete postcondition weakening. -/ -theorem CoupledState.refines.consequencePost {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {pc : UInt256} {R : StateRel} {stmts : List Stmt} - {Post Post' : StmtPost} {st : CoupledState code ee g s0 R pc} - (himp : ∀ result, Post result → Post' result) - (h : CoupledState.refines st cfg stmts Post) : - CoupledState.refines st cfg stmts Post' := by - obtain ⟨result, hblock, hpost⟩ := h - exact ⟨result, hblock, himp result hpost⟩ - -/-- Concrete **consNormal** rule. The head statement advances the concrete coupled state to a new - concrete coupled state for the tail. -/ -theorem CoupledState.refines.consNormal {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {pc pc' : UInt256} {R R' : StateRel} - {Post : StmtPost} {s : Stmt} {rest : List Stmt} - (st : CoupledState code ee g s0 R pc) - (hhead : - ∃ frame' evm' cur' k' C', - cur'.pc = pc' ∧ - ExecStmt cfg st.frame st.evm s (.ok frame' evm') ∧ - RDc code ee g s0 cur' k' C' ∧ - cur'.world = worldOf evm' ∧ - R' cur' frame' evm') - (hrest : ∀ cur' k' C' frame' evm', - ∀ (hpc' : cur'.pc = pc') (hRD' : RDc code ee g s0 cur' k' C') - (hworld' : cur'.world = worldOf evm') (hrel' : R' cur' frame' evm'), - CoupledState.refines (CoupledState.mk cur' k' C' frame' evm' hpc' hRD' hworld' hrel') - cfg rest Post) : - CoupledState.refines st cfg (s :: rest) Post := by - obtain ⟨frame', evm', cur', k', C', hpc', hstmt, hRD', hw', hR'⟩ := hhead - obtain ⟨result, hblock, hpost⟩ := hrest cur' k' C' frame' evm' hpc' hRD' hw' hR' - exact ⟨result, ExecBlock.consNormal hstmt hblock, hpost⟩ - -/-- Concrete **consNormal** rule when the advanced coupled state has already been packaged. -/ -theorem CoupledState.refines.consNormalAt {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {pc pc' : UInt256} {R R' : StateRel} - {Post : StmtPost} {s : Stmt} {rest : List Stmt} - (st : CoupledState code ee g s0 R pc) - (st' : CoupledState code ee g s0 R' pc') - (hstmt : ExecStmt cfg st.frame st.evm s (.ok st'.frame st'.evm)) - (hrest : CoupledState.refines st' cfg rest Post) : - CoupledState.refines st cfg (s :: rest) Post := by - obtain ⟨result, hblock, hpost⟩ := hrest - exact ⟨result, ExecBlock.consNormal hstmt hblock, hpost⟩ - -/-- Progress a source-only `require` known to evaluate to true. The EVM cursor/relation are - unchanged; this is useful when the corresponding bytecode check has already happened before the - current coupled point. -/ -theorem CoupledState.refines.requireTrue {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {pc : UInt256} {R : StateRel} - {Post : StmtPost} {cond : Expr} {rest : List Stmt} - (st : CoupledState code ee g s0 R pc) - (heval : evalExpr? cfg st.frame st.evm cond = .ok (.bool true)) - (hrest : CoupledState.refines st cfg rest Post) : - CoupledState.refines st cfg (.require cond :: rest) Post := - CoupledState.refines.consNormalAt st st (ExecStmt.requireTrue heval) hrest - -/-- Progress a `letDecl` while advancing to a caller-supplied coupled state. The bytecode-side - progress is intentionally abstracted into `st'`: callers prove whatever cursor/RD/relation facts - their compiled pattern establishes, while this rule handles the generic source-frame update. -/ -theorem CoupledState.refines.letDeclAt {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {pc pc' : UInt256} {R R' : StateRel} - {Post : StmtPost} {name : Ident} {ty : Option ABIType} {expr : Expr} {rest : List Stmt} - (st : CoupledState code ee g s0 R pc) - (st' : CoupledState code ee g s0 R' pc') - {value : Value} - (heval : evalExpr? cfg st.frame st.evm expr = .ok value) - (hframe : st'.frame = { st.frame with locals := st.frame.locals.insert name value }) - (hevm : st'.evm = st.evm) - (hrest : CoupledState.refines st' cfg rest Post) : - CoupledState.refines st cfg (.letDecl name ty expr :: rest) Post := by - refine CoupledState.refines.consNormalAt st st' ?_ hrest - rw [hframe, hevm] - exact ExecStmt.letDecl heval - -/-- Progress an `assign` while advancing to a caller-supplied coupled state. As with - `letDeclAt`, the EVM reachability and relation update live in `st'`; this rule packages the - generic Solm assignment semantics. -/ -theorem CoupledState.refines.assignAt {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {pc pc' : UInt256} {R R' : StateRel} - {Post : StmtPost} {origin : VarOrigin} {slot : StorageRef} {expr : Expr} {rest : List Stmt} - (st : CoupledState code ee g s0 R pc) - (st' : CoupledState code ee g s0 R' pc') - {value : Value} - (heval : evalExpr? cfg st.frame st.evm expr = .ok value) - (hassign : assignStorageRef? cfg st.frame st.evm origin slot value = .ok (st'.frame, st'.evm)) - (hrest : CoupledState.refines st' cfg rest Post) : - CoupledState.refines st cfg (.assign origin slot expr :: rest) Post := by - refine CoupledState.refines.consNormalAt st st' ?_ hrest - exact ExecStmt.assign heval hassign - -/-- Concrete **consReturn** rule. The caller-supplied postcondition decides what a Solm `return` - means for this proof context. -/ -theorem CoupledState.refines.consReturn {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {pc : UInt256} {R : StateRel} - {Post : StmtPost} {s : Stmt} {rest : List Stmt} - (st : CoupledState code ee g s0 R pc) - (hhead : - ∃ frame' evm' rv, - ExecStmt cfg st.frame st.evm s (.returned frame' evm' rv) ∧ - Post (.returned frame' evm' rv)) : - CoupledState.refines st cfg (s :: rest) Post := by - obtain ⟨frame', evm', rv, hstmt, hpost⟩ := hhead - exact ⟨.returned frame' evm' rv, ExecBlock.consReturn hstmt, hpost⟩ - -/-- Concrete **consRevert** rule. The tail is never reached. -/ -theorem CoupledState.refines.consRevert {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {pc : UInt256} {R : StateRel} - {Post : StmtPost} {s : Stmt} {rest : List Stmt} - (st : CoupledState code ee g s0 R pc) - (hhead : ExecStmt cfg st.frame st.evm s .reverted ∧ Post .reverted) : - CoupledState.refines st cfg (s :: rest) Post := by - obtain ⟨hstmt, hpost⟩ := hhead - exact ⟨.reverted, ExecBlock.consRevert hstmt, hpost⟩ - -/-- Concrete **consBreak** rule. The tail is never reached. -/ -theorem CoupledState.refines.consBreak {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {pc : UInt256} {R : StateRel} - {Post : StmtPost} {s : Stmt} {rest : List Stmt} - (st : CoupledState code ee g s0 R pc) - (hhead : - ∃ frame' evm', - ExecStmt cfg st.frame st.evm s (.break frame' evm') ∧ - Post (.break frame' evm')) : - CoupledState.refines st cfg (s :: rest) Post := by - obtain ⟨frame', evm', hstmt, hpost⟩ := hhead - exact ⟨.break frame' evm', ExecBlock.consBreak hstmt, hpost⟩ - -/-- Concrete **consContinue** rule. The tail is never reached. -/ -theorem CoupledState.refines.consContinue {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {pc : UInt256} {R : StateRel} - {Post : StmtPost} {s : Stmt} {rest : List Stmt} - (st : CoupledState code ee g s0 R pc) - (hhead : - ∃ frame' evm', - ExecStmt cfg st.frame st.evm s (.continue frame' evm') ∧ - Post (.continue frame' evm')) : - CoupledState.refines st cfg (s :: rest) Post := by - obtain ⟨frame', evm', hstmt, hpost⟩ := hhead - exact ⟨.continue frame' evm', ExecBlock.consContinue hstmt, hpost⟩ - -/-- Postcondition for one loop-body iteration. Normal fall-through and `continue` return to the - loop head with the decreased invariant; `break` exits the loop; `return`/`revert` are terminal - for the surrounding block. -/ -def loopBodyPost (code : ByteArray) (ee : ExecutionEnv) (g : Sat256) (s0 : State) - (loopPc exitPc : UInt256) (Rloop : ℕ → StateRel) (Rexit : StateRel) - (v : ℕ) (Post : StmtPost) : StmtPost - | .ok frame' evm' => - ∃ cur' k' C', cur'.pc = loopPc ∧ RDc code ee g s0 cur' k' C' - ∧ cur'.world = worldOf evm' ∧ Rloop v cur' frame' evm' - | .continue frame' evm' => - ∃ cur' k' C', cur'.pc = loopPc ∧ RDc code ee g s0 cur' k' C' - ∧ cur'.world = worldOf evm' ∧ Rloop v cur' frame' evm' - | .break frame' evm' => - ∃ cur' k' C', cur'.pc = exitPc ∧ RDc code ee g s0 cur' k' C' - ∧ cur'.world = worldOf evm' ∧ Rexit cur' frame' evm' - | .returned frame' evm' rv => - Post (.returned frame' evm' rv) - | .reverted => - Post .reverted - -/-- Prefix a recursive `while :: rest` block with an iteration whose body fell through normally. -/ -theorem execBlock_prependWhileTrue {cfg : Config} {cond : Expr} {body rest : List Stmt} - {frame evm frame' evm'} {result : ExecResult} - (hcond : evalExpr? cfg frame evm cond = .ok (.bool true)) - (hbody : ExecBlock cfg frame evm body (.ok frame' evm')) - (hrec : ExecBlock cfg frame' evm' (.while cond body :: rest) result) : - ExecBlock cfg frame evm (.while cond body :: rest) result := by - cases hrec with - | consNormal hwhile hrest => - exact ExecBlock.consNormal (ExecStmt.whileTrue hcond hbody hwhile) hrest - | consReturn hwhile => - exact ExecBlock.consReturn (ExecStmt.whileTrue hcond hbody hwhile) - | consRevert hwhile => - exact ExecBlock.consRevert (ExecStmt.whileTrue hcond hbody hwhile) - | consBreak hwhile => - exact ExecBlock.consBreak (ExecStmt.whileTrue hcond hbody hwhile) - | consContinue hwhile => - exact ExecBlock.consContinue (ExecStmt.whileTrue hcond hbody hwhile) - -/-- Prefix a recursive `while :: rest` block with an iteration whose body hit `continue`. -/ -theorem execBlock_prependWhileContinue {cfg : Config} {cond : Expr} {body rest : List Stmt} - {frame evm frame' evm'} {result : ExecResult} - (hcond : evalExpr? cfg frame evm cond = .ok (.bool true)) - (hbody : ExecBlock cfg frame evm body (.continue frame' evm')) - (hrec : ExecBlock cfg frame' evm' (.while cond body :: rest) result) : - ExecBlock cfg frame evm (.while cond body :: rest) result := by - cases hrec with - | consNormal hwhile hrest => - exact ExecBlock.consNormal (ExecStmt.whileContinue hcond hbody hwhile) hrest - | consReturn hwhile => - exact ExecBlock.consReturn (ExecStmt.whileContinue hcond hbody hwhile) - | consRevert hwhile => - exact ExecBlock.consRevert (ExecStmt.whileContinue hcond hbody hwhile) - | consBreak hwhile => - exact ExecBlock.consBreak (ExecStmt.whileContinue hcond hbody hwhile) - | consContinue hwhile => - exact ExecBlock.consContinue (ExecStmt.whileContinue hcond hbody hwhile) - -/-- Concrete **while-loop** rule with a natural variant. - - `Rloop v` is the coupled invariant at the loop head with `v` iterations remaining. At `0`, the - condition is false and the EVM reaches the loop exit. At `v+1`, the condition is true and the - EVM reaches the body entry; the body proof must either return to `Rloop v`, exit by `break`, or - satisfy the surrounding terminal postcondition. -/ -theorem CoupledState.refines.whileLoop {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {loopPc bodyPc exitPc : UInt256} - {Rbody Rexit : StateRel} {Rloop : ℕ → StateRel} {Post : StmtPost} - {cond : Expr} {body rest : List Stmt} - (hfalse : ∀ st : CoupledState code ee g s0 (Rloop 0) loopPc, - ∃ curExit kExit CExit, - evalExpr? cfg st.frame st.evm cond = .ok (.bool false) ∧ - curExit.pc = exitPc ∧ - RDc code ee g s0 curExit kExit CExit ∧ - curExit.world = worldOf st.evm ∧ - Rexit curExit st.frame st.evm) - (htrue : ∀ v (st : CoupledState code ee g s0 (Rloop (v + 1)) loopPc), - ∃ curBody kBody CBody, - evalExpr? cfg st.frame st.evm cond = .ok (.bool true) ∧ - curBody.pc = bodyPc ∧ - RDc code ee g s0 curBody kBody CBody ∧ - curBody.world = worldOf st.evm ∧ - Rbody curBody st.frame st.evm) - (hbody : ∀ v (stBody : CoupledState code ee g s0 Rbody bodyPc), - CoupledState.refines stBody cfg body - (loopBodyPost code ee g s0 loopPc exitPc Rloop Rexit v Post)) - (hrest : ∀ stExit : CoupledState code ee g s0 Rexit exitPc, - CoupledState.refines stExit cfg rest Post) : - ∀ v (st : CoupledState code ee g s0 (Rloop v) loopPc), - CoupledState.refines st cfg (.while cond body :: rest) Post := by - intro v - induction v with - | zero => - intro st - obtain ⟨curExit, kExit, CExit, hcond, hpcExit, hRDExit, hwExit, hRExit⟩ := hfalse st - obtain ⟨result, hrestBlock, hpost⟩ := - hrest (CoupledState.mk curExit kExit CExit st.frame st.evm hpcExit hRDExit hwExit hRExit) - exact ⟨result, ExecBlock.consNormal (ExecStmt.whileFalse hcond) hrestBlock, hpost⟩ - | succ v ih => - intro st - obtain ⟨curBody, kBody, CBody, hcond, hpcBody, hRDBody, hwBody, hRBody⟩ := htrue v st - obtain ⟨bodyResult, hbodyBlock, hbodyPost⟩ := - hbody v (CoupledState.mk curBody kBody CBody st.frame st.evm hpcBody hRDBody hwBody hRBody) - cases bodyResult with - | ok frame' evm' => - obtain ⟨curLoop, kLoop, CLoop, hpcLoop, hRDLoop, hwLoop, hRLoop⟩ := hbodyPost - obtain ⟨result, hrecBlock, hpost⟩ := - ih (CoupledState.mk curLoop kLoop CLoop frame' evm' hpcLoop hRDLoop hwLoop hRLoop) - exact ⟨result, - execBlock_prependWhileTrue hcond hbodyBlock hrecBlock, - hpost⟩ - | returned frame' evm' rv => - exact ⟨.returned frame' evm' rv, ExecBlock.consReturn (ExecStmt.whileReturn hcond hbodyBlock), - hbodyPost⟩ - | reverted => - exact ⟨.reverted, ExecBlock.consRevert (ExecStmt.whileRevert hcond hbodyBlock), hbodyPost⟩ - | «break» frame' evm' => - obtain ⟨curExit, kExit, CExit, hpcExit, hRDExit, hwExit, hRExit⟩ := hbodyPost - obtain ⟨result, hrestBlock, hpost⟩ := - hrest (CoupledState.mk curExit kExit CExit frame' evm' hpcExit hRDExit hwExit hRExit) - exact ⟨result, ExecBlock.consNormal (ExecStmt.whileBreak hcond hbodyBlock) hrestBlock, hpost⟩ - | «continue» frame' evm' => - obtain ⟨curLoop, kLoop, CLoop, hpcLoop, hRDLoop, hwLoop, hRLoop⟩ := hbodyPost - obtain ⟨result, hrecBlock, hpost⟩ := - ih (CoupledState.mk curLoop kLoop CLoop frame' evm' hpcLoop hRDLoop hwLoop hRLoop) - exact ⟨result, - execBlock_prependWhileContinue hcond hbodyBlock hrecBlock, - hpost⟩ - -/-- Concrete **while-loop** rule with a natural variant and variant-indexed body-entry relation. - - This is the scoped-body version of `CoupledState.refines.whileLoop`: when the guard is true at - variant `v + 1`, the body-entry relation is `Rbody v`, so the body proof retains the exact - target variant it must re-establish. -/ -theorem CoupledState.refines.whileLoopIndexedBody {code : ByteArray} {ee : ExecutionEnv} - {g : Sat256} {s0 : State} {cfg : Config} {loopPc bodyPc exitPc : UInt256} - {Rexit : StateRel} {Rloop Rbody : ℕ → StateRel} {Post : StmtPost} - {cond : Expr} {body rest : List Stmt} - (hfalse : ∀ st : CoupledState code ee g s0 (Rloop 0) loopPc, - ∃ curExit kExit CExit, - evalExpr? cfg st.frame st.evm cond = .ok (.bool false) ∧ - curExit.pc = exitPc ∧ - RDc code ee g s0 curExit kExit CExit ∧ - curExit.world = worldOf st.evm ∧ - Rexit curExit st.frame st.evm) - (htrue : ∀ v (st : CoupledState code ee g s0 (Rloop (v + 1)) loopPc), - ∃ curBody kBody CBody, - evalExpr? cfg st.frame st.evm cond = .ok (.bool true) ∧ - curBody.pc = bodyPc ∧ - RDc code ee g s0 curBody kBody CBody ∧ - curBody.world = worldOf st.evm ∧ - Rbody v curBody st.frame st.evm) - (hbody : ∀ v (stBody : CoupledState code ee g s0 (Rbody v) bodyPc), - CoupledState.refines stBody cfg body - (loopBodyPost code ee g s0 loopPc exitPc Rloop Rexit v Post)) - (hrest : ∀ stExit : CoupledState code ee g s0 Rexit exitPc, - CoupledState.refines stExit cfg rest Post) : - ∀ v (st : CoupledState code ee g s0 (Rloop v) loopPc), - CoupledState.refines st cfg (.while cond body :: rest) Post := by - intro v - induction v with - | zero => - intro st - obtain ⟨curExit, kExit, CExit, hcond, hpcExit, hRDExit, hwExit, hRExit⟩ := hfalse st - obtain ⟨result, hrestBlock, hpost⟩ := - hrest (CoupledState.mk curExit kExit CExit st.frame st.evm hpcExit hRDExit hwExit hRExit) - exact ⟨result, ExecBlock.consNormal (ExecStmt.whileFalse hcond) hrestBlock, hpost⟩ - | succ v ih => - intro st - obtain ⟨curBody, kBody, CBody, hcond, hpcBody, hRDBody, hwBody, hRBody⟩ := htrue v st - obtain ⟨bodyResult, hbodyBlock, hbodyPost⟩ := - hbody v (CoupledState.mk curBody kBody CBody st.frame st.evm hpcBody hRDBody hwBody hRBody) - cases bodyResult with - | ok frame' evm' => - obtain ⟨curLoop, kLoop, CLoop, hpcLoop, hRDLoop, hwLoop, hRLoop⟩ := hbodyPost - obtain ⟨result, hrecBlock, hpost⟩ := - ih (CoupledState.mk curLoop kLoop CLoop frame' evm' hpcLoop hRDLoop hwLoop hRLoop) - exact ⟨result, - execBlock_prependWhileTrue hcond hbodyBlock hrecBlock, - hpost⟩ - | returned frame' evm' rv => - exact ⟨.returned frame' evm' rv, ExecBlock.consReturn (ExecStmt.whileReturn hcond hbodyBlock), - hbodyPost⟩ - | reverted => - exact ⟨.reverted, ExecBlock.consRevert (ExecStmt.whileRevert hcond hbodyBlock), hbodyPost⟩ - | «break» frame' evm' => - obtain ⟨curExit, kExit, CExit, hpcExit, hRDExit, hwExit, hRExit⟩ := hbodyPost - obtain ⟨result, hrestBlock, hpost⟩ := - hrest (CoupledState.mk curExit kExit CExit frame' evm' hpcExit hRDExit hwExit hRExit) - exact ⟨result, ExecBlock.consNormal (ExecStmt.whileBreak hcond hbodyBlock) hrestBlock, hpost⟩ - | «continue» frame' evm' => - obtain ⟨curLoop, kLoop, CLoop, hpcLoop, hRDLoop, hwLoop, hRLoop⟩ := hbodyPost - obtain ⟨result, hrecBlock, hpost⟩ := - ih (CoupledState.mk curLoop kLoop CLoop frame' evm' hpcLoop hRDLoop hwLoop hRLoop) - exact ⟨result, - execBlock_prependWhileContinue hcond hbodyBlock hrecBlock, - hpost⟩ - -/-- Postcondition used by externally-dispatched transition bodies. Here a Solm `return` really is - an EVM `RETURN`; fall-through is left as a cursor for the ABI-encoding epilogue. -/ -def transitionPost (code : ByteArray) (ee : ExecutionEnv) (g : Sat256) (s0 : State) - (returnType : List ABIType) (Q : StateRel) : StmtPost - | .ok frame' evm' => - ∃ cur' k' C', RDc code ee g s0 cur' k' C' ∧ cur'.world = worldOf evm' - ∧ Q cur' frame' evm' - | .returned _ evm' rv => - ∃ o, RDret code g s0 (worldOf evm') o ∧ returnEquiv o rv returnType - | .reverted => - RDrev code g s0 - | .break _ _ | .continue _ _ => - False - -/-- Close an external-transition proof when the next statement is a Solm `return` and the bytecode - side has reached an EVM `RETURN` with ABI-equivalent bytes. -/ -theorem CoupledState.refines.returnTransition {code : ByteArray} {ee : ExecutionEnv} - {g : Sat256} {s0 : State} {cfg : Config} {pc : UInt256} {R Q : StateRel} - {returnType : List ABIType} {exprs : List Expr} {rest : List Stmt} - (st : CoupledState code ee g s0 R pc) - {frame' : Frame} {evm' : State} {rv : Option (List Value)} {o : ByteArray} - (hstmt : ExecStmt cfg st.frame st.evm (.return exprs) (.returned frame' evm' rv)) - (hret : RDret code g s0 (worldOf evm') o) - (hequiv : returnEquiv o rv returnType) : - CoupledState.refines st cfg (.return exprs :: rest) (transitionPost code ee g s0 returnType Q) := by - refine CoupledState.refines.consReturn st ?_ - exact ⟨frame', evm', rv, hstmt, o, hret, hequiv⟩ - -/-- The external-transition interpretation of `equivStmts`: run `stmts` against the - transition-level postcondition `transitionPost`. -/ -def equivTransitionStmts (code : ByteArray) (ee : ExecutionEnv) (g : Sat256) (s0 : State) - (cfg : Config) (returnType : List ABIType) - (pc : UInt256) (R : StateRel) (stmts : List Stmt) (Q : StateRel) : Prop := - equivStmts code ee g s0 cfg pc R stmts (transitionPost code ee g s0 returnType Q) - -/-! ### Structural rules — symbolic execution on both sides, statement by statement -/ - -/-- **nil** — the empty block keeps the cursor and the relation unchanged. -/ -theorem equivStmts.nil {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc : UInt256} (R : StateRel) : - equivStmts code ee g s0 cfg pc R [] (normalPost code ee g s0 R) := by - intro cur k C frame evm _hpc hRD hw hR - exact ⟨.ok frame evm, ExecBlock.nil, cur, k, C, hRD, hw, hR⟩ - -/-- **nil**, fully generic form. -/ -theorem equivStmts.nilPost {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc : UInt256} {R : StateRel} {Post : StmtPost} - (hpost : ∀ cur k C frame evm, cur.pc = pc → RDc code ee g s0 cur k C → - cur.world = worldOf evm → R cur frame evm → Post (.ok frame evm)) : - equivStmts code ee g s0 cfg pc R [] Post := by - intro cur k C frame evm hpc hRD hw hR - exact ⟨.ok frame evm, ExecBlock.nil, hpost cur k C frame evm hpc hRD hw hR⟩ - -/-- **consNormal** — peel a fall-through head statement. `hhead` runs the head in Solm - (`ExecStmt … .ok`) and walks its bytecode (`RDc … cur'`, exit pc `pc'`), re-establishing the - coupling `R'`; `hrest` is the advanced judgment for the tail. This is "run some bytecode with - `RD`, run a Solm statement, move to an advanced `equivStmts`." -/ -theorem equivStmts.consNormal {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc pc' : UInt256} {R R' : StateRel} {Post : StmtPost} - {s : Stmt} {rest : List Stmt} - (hhead : ∀ cur k C frame evm, cur.pc = pc → RDc code ee g s0 cur k C → cur.world = worldOf evm → - R cur frame evm → - ∃ frame' evm' cur' k' C', - cur'.pc = pc' ∧ - ExecStmt cfg frame evm s (.ok frame' evm') ∧ - RDc code ee g s0 cur' k' C' ∧ - cur'.world = worldOf evm' ∧ - R' cur' frame' evm') - (hrest : equivStmts code ee g s0 cfg pc' R' rest Post) : - equivStmts code ee g s0 cfg pc R (s :: rest) Post := by - intro cur k C frame evm hpc hRD hw hR - obtain ⟨frame', evm', cur', k', C', hpc', hstmt, hRD', hw', hR'⟩ := hhead cur k C frame evm hpc hRD hw hR - obtain ⟨result, hblock, hmatch⟩ := hrest cur' k' C' frame' evm' hpc' hRD' hw' hR' - exact ⟨result, ExecBlock.consNormal hstmt hblock, hmatch⟩ - -/-- **consReturn** — the head statement `return`s. The caller-supplied postcondition decides - whether that is an EVM `RETURN` (external transition) or a reached continuation (internal - callable). The tail is never reached. -/ -theorem equivStmts.consReturn {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc : UInt256} {R : StateRel} {Post : StmtPost} - {s : Stmt} {rest : List Stmt} - (hhead : ∀ cur k C frame evm, cur.pc = pc → RDc code ee g s0 cur k C → cur.world = worldOf evm → - R cur frame evm → - ∃ frame' evm' rv, - ExecStmt cfg frame evm s (.returned frame' evm' rv) ∧ - Post (.returned frame' evm' rv)) : - equivStmts code ee g s0 cfg pc R (s :: rest) Post := by - intro cur k C frame evm hpc hRD hw hR - obtain ⟨frame', evm', rv, hstmt, hpost⟩ := hhead cur k C frame evm hpc hRD hw hR - exact ⟨.returned frame' evm' rv, ExecBlock.consReturn hstmt, hpost⟩ - -/-- **consRevert** — the head statement `revert`s. The tail is never reached. -/ -theorem equivStmts.consRevert {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc : UInt256} {R : StateRel} {Post : StmtPost} - {s : Stmt} {rest : List Stmt} - (hhead : ∀ cur k C frame evm, cur.pc = pc → RDc code ee g s0 cur k C → cur.world = worldOf evm → - R cur frame evm → - ExecStmt cfg frame evm s .reverted ∧ Post .reverted) : - equivStmts code ee g s0 cfg pc R (s :: rest) Post := by - intro cur k C frame evm hpc hRD hw hR - obtain ⟨hstmt, hpost⟩ := hhead cur k C frame evm hpc hRD hw hR - exact ⟨.reverted, ExecBlock.consRevert hstmt, hpost⟩ - -/-- **consBreak** — the head statement `break`s. The tail is never reached. -/ -theorem equivStmts.consBreak {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc : UInt256} {R : StateRel} {Post : StmtPost} - {s : Stmt} {rest : List Stmt} - (hhead : ∀ cur k C frame evm, cur.pc = pc → RDc code ee g s0 cur k C → cur.world = worldOf evm → - R cur frame evm → - ∃ frame' evm', ExecStmt cfg frame evm s (.break frame' evm') ∧ - Post (.break frame' evm')) : - equivStmts code ee g s0 cfg pc R (s :: rest) Post := by - intro cur k C frame evm hpc hRD hw hR - obtain ⟨frame', evm', hstmt, hpost⟩ := hhead cur k C frame evm hpc hRD hw hR - exact ⟨.break frame' evm', ExecBlock.consBreak hstmt, hpost⟩ - -/-- **consContinue** — the head statement `continue`s. The tail is never reached. -/ -theorem equivStmts.consContinue {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc : UInt256} {R : StateRel} {Post : StmtPost} - {s : Stmt} {rest : List Stmt} - (hhead : ∀ cur k C frame evm, cur.pc = pc → RDc code ee g s0 cur k C → cur.world = worldOf evm → - R cur frame evm → - ∃ frame' evm', ExecStmt cfg frame evm s (.continue frame' evm') ∧ - Post (.continue frame' evm')) : - equivStmts code ee g s0 cfg pc R (s :: rest) Post := by - intro cur k C frame evm hpc hRD hw hR - obtain ⟨frame', evm', hstmt, hpost⟩ := hhead cur k C frame evm hpc hRD hw hR - exact ⟨.continue frame' evm', ExecBlock.consContinue hstmt, hpost⟩ - -/-- **external call (success / continue)** — peel a *successful* external call. The bytecode's - `CALL` (`RD.call`) and Solm's `externalCall` (`typedCallViaEVM`) invoke the **same** `Θ`, so - the opaque result `(z, evm', out)` coincides on both sides by construction; `hcall` packages that - bridged fact (obtained from `RD.call`) together with the post-`CALL` cursor. On `z = true` with a - decoding return, `retVar` binds the decoded `value` and execution continues at `pc'`. - - A call that **reverts** — `z = false`, or a return that does not decode — is *not* a new rule: - it is `consRevert` with `ExecStmt.externalCallFailure` / `externalCallReturnDecodeRevert`. Which - branch fires is dictated by the (opaque, but deterministic) `Θ` result, exactly as the contract's - post-`CALL` bytecode (`ISZERO …` / the return-size check) branches on it. -/ -theorem CoupledState.refines.externalCall {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {pc pc' : UInt256} {R R' : StateRel} {Post : StmtPost} - {receiver eth : Expr} {name : Ident} {args : List Expr} {retVar : Ident} - {rest : List Stmt} {perm : Bool} - (st : CoupledState code ee g s0 R pc) - (hcall : - ∃ (target : EVM.Address) (sendVal : ℤ) (argVals : List Value) (evm' : State) - (out : ByteArray) (value : List Value) (cur' : Cursor) (k' C' : ℕ), - evalExpr? cfg st.frame st.evm receiver = .ok (.address target) ∧ - evalExpr? cfg st.frame st.evm eth = .ok (.int sendVal) ∧ - evalExprs? cfg st.frame st.evm args = .ok argVals ∧ - typedCallViaEVM cfg st.evm (EVM.address target) name sendVal argVals - (true, evm', out) perm ∧ - cfg.externalABI.decode? name out = some value ∧ - cur'.pc = pc' ∧ - RDc code ee g s0 cur' k' C' ∧ - cur'.world = worldOf evm' ∧ - R' cur' { st.frame with locals := st.frame.locals.insert retVar (collapseReturns value) } evm') - (hrest : ∀ cur' k' C' frame' evm', - ∀ (hpc' : cur'.pc = pc') (hRD' : RDc code ee g s0 cur' k' C') - (hworld' : cur'.world = worldOf evm') (hrel' : R' cur' frame' evm'), - CoupledState.refines (CoupledState.mk cur' k' C' frame' evm' hpc' hRD' hworld' hrel') - cfg rest Post) : - CoupledState.refines st cfg - (.externalCall receiver name eth args retVar (perm := perm) :: rest) Post := by - obtain ⟨target, sendVal, argVals, evm', out, value, cur', k', C', - hrec, heth, hargs, hcallEVM, hdec, hpc', hRD', hw', hR'⟩ := hcall - obtain ⟨result, hblock, hpost⟩ := - hrest cur' k' C' { st.frame with locals := st.frame.locals.insert retVar (collapseReturns value) } evm' - hpc' hRD' hw' hR' - exact ⟨result, - ExecBlock.consNormal (ExecStmt.externalCallSuccess hrec heth hargs hcallEVM hdec) hblock, - hpost⟩ - -/-- Concrete external-call rule for the `z = false` branch. The statement reverts immediately, so - the tail is unreachable and the caller-supplied postcondition must already accept `.reverted`. -/ -theorem CoupledState.refines.externalCallFailure {code : ByteArray} {ee : ExecutionEnv} - {g : Sat256} {s0 : State} {cfg : Config} {pc : UInt256} {R : StateRel} - {Post : StmtPost} {receiver eth : Expr} {name : Ident} {args : List Expr} - {retVar : Ident} {rest : List Stmt} {perm : Bool} - (st : CoupledState code ee g s0 R pc) - (hcall : - ∃ (target : EVM.Address) (sendVal : ℤ) (argVals : List Value) (evm' : State) - (out : ByteArray), - evalExpr? cfg st.frame st.evm receiver = .ok (.address target) ∧ - evalExpr? cfg st.frame st.evm eth = .ok (.int sendVal) ∧ - evalExprs? cfg st.frame st.evm args = .ok argVals ∧ - typedCallViaEVM cfg st.evm (EVM.address target) name sendVal argVals - (false, evm', out) perm) - (hpost : Post .reverted) : - CoupledState.refines st cfg - (.externalCall receiver name eth args retVar (perm := perm) :: rest) Post := by - obtain ⟨target, sendVal, argVals, evm', out, hrec, heth, hargs, hcallEVM⟩ := hcall - exact ⟨.reverted, - ExecBlock.consRevert (ExecStmt.externalCallFailure hrec heth hargs hcallEVM), - hpost⟩ - -/-- Concrete external-call rule for the successful-call / ABI-decode-failure branch. The statement - reverts immediately, so the tail is unreachable. -/ -theorem CoupledState.refines.externalCallDecodeRevert {code : ByteArray} {ee : ExecutionEnv} - {g : Sat256} {s0 : State} {cfg : Config} {pc : UInt256} {R : StateRel} - {Post : StmtPost} {receiver eth : Expr} {name : Ident} {args : List Expr} - {retVar : Ident} {rest : List Stmt} {perm : Bool} - (st : CoupledState code ee g s0 R pc) - (hcall : - ∃ (target : EVM.Address) (sendVal : ℤ) (argVals : List Value) (evm' : State) - (out : ByteArray), - evalExpr? cfg st.frame st.evm receiver = .ok (.address target) ∧ - evalExpr? cfg st.frame st.evm eth = .ok (.int sendVal) ∧ - evalExprs? cfg st.frame st.evm args = .ok argVals ∧ - typedCallViaEVM cfg st.evm (EVM.address target) name sendVal argVals - (true, evm', out) perm ∧ - cfg.externalABI.decode? name out = none) - (hpost : Post .reverted) : - CoupledState.refines st cfg - (.externalCall receiver name eth args retVar (perm := perm) :: rest) Post := by - obtain ⟨target, sendVal, argVals, evm', out, hrec, heth, hargs, hcallEVM, hdec⟩ := hcall - exact ⟨.reverted, - ExecBlock.consRevert (ExecStmt.externalCallReturnDecodeRevert hrec heth hargs hcallEVM hdec), - hpost⟩ - -theorem equivStmts.externalCall {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc pc' : UInt256} {R R' : StateRel} {Post : StmtPost} - {receiver eth : Expr} {name : Ident} {args : List Expr} {retVar : Ident} {rest : List Stmt} - {perm : Bool} - (hcall : ∀ cur k C frame evm, cur.pc = pc → RDc code ee g s0 cur k C → cur.world = worldOf evm → - R cur frame evm → - ∃ (target : EVM.Address) (sendVal : ℤ) (argVals : List Value) (evm' : State) - (out : ByteArray) (value : List Value) (cur' : Cursor) (k' C' : ℕ), - evalExpr? cfg frame evm receiver = .ok (.address target) ∧ - evalExpr? cfg frame evm eth = .ok (.int sendVal) ∧ - evalExprs? cfg frame evm args = .ok argVals ∧ - typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals - (true, evm', out) perm ∧ - cfg.externalABI.decode? name out = some value ∧ - cur'.pc = pc' ∧ - RDc code ee g s0 cur' k' C' ∧ - cur'.world = worldOf evm' ∧ - R' cur' { frame with locals := frame.locals.insert retVar (collapseReturns value) } evm') - (hrest : equivStmts code ee g s0 cfg pc' R' rest Post) : - equivStmts code ee g s0 cfg pc R - (.externalCall receiver name eth args retVar (perm := perm) :: rest) Post := by - intro cur k C frame evm hpc hRD hw hR - obtain ⟨target, sendVal, argVals, evm', out, value, cur', k', C', - hrec, heth, hargs, hcallEVM, hdec, hpc', hRD', hw', hR'⟩ := hcall cur k C frame evm hpc hRD hw hR - obtain ⟨result, hblock, hmatch⟩ := - hrest cur' k' C' { frame with locals := frame.locals.insert retVar (collapseReturns value) } evm' hpc' hRD' hw' hR' - exact ⟨result, - ExecBlock.consNormal (ExecStmt.externalCallSuccess hrec heth hargs hcallEVM hdec) hblock, hmatch⟩ - -/-- **consequence (strengthen the precondition).** -/ -theorem equivStmts.consequencePre {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc : UInt256} {R R' : StateRel} {Post : StmtPost} {stmts} - (himp : ∀ cur frame evm, R' cur frame evm → R cur frame evm) - (h : equivStmts code ee g s0 cfg pc R stmts Post) : - equivStmts code ee g s0 cfg pc R' stmts Post := by - intro cur k C frame evm hpc hRD hw hR' - exact h cur k C frame evm hpc hRD hw (himp cur frame evm hR') - -/-- **consequence (weaken the postcondition).** -/ -theorem equivStmts.consequencePost {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc : UInt256} {R : StateRel} {Post Post' : StmtPost} {stmts} - (himp : ∀ result, Post result → Post' result) - (h : equivStmts code ee g s0 cfg pc R stmts Post) : - equivStmts code ee g s0 cfg pc R stmts Post' := by - intro cur k C frame evm hpc hRD hw hR - obtain ⟨result, hblock, hmatch⟩ := h cur k C frame evm hpc hRD hw hR - exact ⟨result, hblock, himp result hmatch⟩ - -/-! ### Sequencing (chunk composition) -/ - -/-- Append helper: if `s1` falls through to `(f1, e1)`, running `s2` from there is running `s1 ++ s2`. -/ -theorem execBlock_append {cfg : Config} {s2 : List Stmt} : - ∀ {s1 : List Stmt} {f e f1 e1 r}, ExecBlock cfg f e s1 (.ok f1 e1) → ExecBlock cfg f1 e1 s2 r → - ExecBlock cfg f e (s1 ++ s2) r := by - intro s1 - induction s1 with - | nil => intro f e f1 e1 r h1 h2; cases h1; exact h2 - | cons stmt rest ih => - intro f e f1 e1 r h1 h2 - cases h1 with - | consNormal hstmt hrest => exact ExecBlock.consNormal hstmt (ih hrest h2) - -/-- Append helper: if `s1` *terminates* (any non-`.ok` result), `s1 ++ s2` terminates the same way — - `s2` never runs. -/ -theorem execBlock_append_term {cfg : Config} {s2 : List Stmt} : - ∀ {s1 : List Stmt} {f e r}, ExecBlock cfg f e s1 r → (∀ f' e', r ≠ .ok f' e') → - ExecBlock cfg f e (s1 ++ s2) r := by - intro s1 - induction s1 with - | nil => intro f e r h1 hterm; cases h1; exact absurd rfl (hterm _ _) - | cons stmt rest ih => - intro f e r h1 hterm - cases h1 with - | consNormal hstmt hrest => exact ExecBlock.consNormal hstmt (ih hrest hterm) - | consReturn hstmt => exact ExecBlock.consReturn hstmt - | consRevert hstmt => exact ExecBlock.consRevert hstmt - | consBreak hstmt => exact ExecBlock.consBreak hstmt - | consContinue hstmt => exact ExecBlock.consContinue hstmt - -/-- Postcondition for the left side of a sequence. A fall-through result must reach the seam - relation `S` at `pcmid`; any non-fall-through result is already checked by the final `Post`. -/ -def seqPost (code : ByteArray) (ee : ExecutionEnv) (g : Sat256) (s0 : State) - (pcmid : UInt256) (S : StateRel) (Post : StmtPost) : StmtPost - | .ok frame' evm' => - ∃ cur' k' C', cur'.pc = pcmid ∧ RDc code ee g s0 cur' k' C' - ∧ cur'.world = worldOf evm' ∧ S cur' frame' evm' - | .returned frame' evm' rv => - Post (.returned frame' evm' rv) - | .reverted => - Post .reverted - | .break frame' evm' => - Post (.break frame' evm') - | .continue frame' evm' => - Post (.continue frame' evm') - -/-- Concrete **seq (chunk composition)** for coupled proof states. The first chunk is proved from - the current state using `seqPost`; on fall-through, the midpoint facts are repackaged as the - coupled state consumed by the second chunk. -/ -theorem CoupledState.refines.seq {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {pc pcmid : UInt256} {R S : StateRel} {Post : StmtPost} - {s1 s2 : List Stmt} - (st : CoupledState code ee g s0 R pc) - (h1 : CoupledState.refines st cfg s1 (seqPost code ee g s0 pcmid S Post)) - (h2 : ∀ st' : CoupledState code ee g s0 S pcmid, - CoupledState.refines st' cfg s2 Post) : - CoupledState.refines st cfg (s1 ++ s2) Post := by - obtain ⟨result1, hblock1, hmatch1⟩ := h1 - cases result1 with - | ok frame1 evm1 => - obtain ⟨cur1, k1, C1, hpc1, hRD1, hw1, hS⟩ := hmatch1 - let st1 : CoupledState code ee g s0 S pcmid := - { cur := cur1, k := k1, C := C1, frame := frame1, evm := evm1, - hpc := hpc1, hRD := hRD1, hworld := hw1, hrel := hS } - obtain ⟨result2, hblock2, hmatch2⟩ := h2 st1 - exact ⟨result2, execBlock_append hblock1 hblock2, hmatch2⟩ - | returned frame1 evm1 rv => - exact ⟨_, execBlock_append_term hblock1 (by intro f' e' h; simp at h), hmatch1⟩ - | reverted => - exact ⟨_, execBlock_append_term hblock1 (by intro f' e' h; simp at h), hmatch1⟩ - | «break» frame1 evm1 => - exact ⟨_, execBlock_append_term hblock1 (by intro f' e' h; simp at h), hmatch1⟩ - | «continue» frame1 evm1 => - exact ⟨_, execBlock_append_term hblock1 (by intro f' e' h; simp at h), hmatch1⟩ - -/-- **seq (chunk composition).** Glue two chunks at a chosen boundary `pcmid`. If `s1` falls - through, its `seqPost` supplies the `RDc` cursor and relation for `s2`; if `s1` returns, - reverts, breaks, or continues, that result is already the whole appended block's result. - - Composition needs no transitivity — the EVM facts (`RDc`/terminal facts embedded in `Post`) are - absolute from `s0`, so they carry through verbatim. -/ -theorem equivStmts.seq {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {pc pcmid : UInt256} {R S : StateRel} {Post : StmtPost} - {s1 s2 : List Stmt} - (h1 : equivStmts code ee g s0 cfg pc R s1 (seqPost code ee g s0 pcmid S Post)) - (h2 : equivStmts code ee g s0 cfg pcmid S s2 Post) : - equivStmts code ee g s0 cfg pc R (s1 ++ s2) Post := by - intro cur k C frame evm hpc hRD hw hR - obtain ⟨result1, hblock1, hmatch1⟩ := h1 cur k C frame evm hpc hRD hw hR - cases result1 with - | ok f1 e1 => - obtain ⟨cur1, k1, C1, hpc1, hRD1, hw1, hS⟩ := hmatch1 - obtain ⟨result2, hblock2, hmatch2⟩ := - h2 cur1 k1 C1 f1 e1 hpc1 hRD1 hw1 hS - exact ⟨result2, execBlock_append hblock1 hblock2, hmatch2⟩ - | returned f1 e1 rv => - exact ⟨_, execBlock_append_term hblock1 (by intro f' e' h; simp at h), hmatch1⟩ - | reverted => - exact ⟨_, execBlock_append_term hblock1 (by intro f' e' h; simp at h), hmatch1⟩ - | «break» f1 e1 => - exact ⟨_, execBlock_append_term hblock1 (by intro f' e' h; simp at h), hmatch1⟩ - | «continue» f1 e1 => - exact ⟨_, execBlock_append_term hblock1 (by intro f' e' h; simp at h), hmatch1⟩ - -/-! ### Up to the function and the contract -/ - -/-- Per-function equivalence: from possibly representation-different initial maps, the EVM body and - the Solm body `t.body` (run with `callargs`) reach a matching terminal result — both return - ABI-coupled values with equivalent final worlds, or both revert. -/ -inductive equivTransition (cfg : Config) (contract : ContractDecl) (t : TransitionDecl) - (cA : Batteries.RBSet AccountAddress compare) (gh : BlockHeader) (bl : ProcessedBlocks) - (σ_evm σ_solm σ₀ : AccountMap) (A : Substate) (I : ExecutionEnv) - (g : Sat256) - (code : ByteArray) (callargs : Store) : Prop where - | returns {o : ByteArray} {cs : Frame} {retVal} {evm'' : State} - {world : Batteries.RBSet AccountAddress compare × AccountMap} : - RDret code g (initState cA gh bl σ_evm σ₀ g A I) world o → - ExecTransitionBody cfg contract (initState cA gh bl σ_solm σ₀ g A I) callargs t.body - (.returned cs evm'' retVal) → - world.1 = evm''.createdAccounts → - accountMapEquiv world.2 evm''.accountMap → - returnEquiv o retVal t.returnType → - equivTransition cfg contract t cA gh bl σ_evm σ_solm σ₀ A I g code - callargs - | reverts : - RDrev code g (initState cA gh bl σ_evm σ₀ g A I) → - ExecTransitionBody cfg contract (initState cA gh bl σ_solm σ₀ g A I) - callargs t.body .reverted → - equivTransition cfg contract t cA gh bl σ_evm σ_solm σ₀ A I g code - callargs - -/-- `equivTransition` + the selector dispatches to `t` + its args decode ⟹ `runtimeEquivalenceFor`. -/ -theorem equivTransition.toRuntime {cfg : Config} {contract : ContractDecl} {t : TransitionDecl} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} {code : ByteArray} - {callargs : Store} - (hcode : I.code = code) - (hd : dispatchMsg contract I.calldata = some t) - (hdec : decodeCalldataWithMode cfg.abiDecodeMode (t.params.map Param.name) - (transitionSignature t).paramTypes I.calldata = some callargs) - (h : equivTransition cfg contract t cA gh bl σ_evm σ_solm σ₀ A I g code - callargs) - (hfallback : contract.fallback = none := by rfl) - (hreceive : contract.receive = none := by rfl) : - runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ - g.toUInt256 A I := by - cases h with - | returns hret hbody hCreated hAccounts henc => - exact hret.reEquivExecutionGenAccountMapEquiv hcode hd hdec hbody hCreated hAccounts henc - hfallback hreceive - | reverts hrev hbody => exact hrev.reEquivExecutionRevert hcode hd hdec hbody hfallback hreceive - -/-- **Bridge** — the body-level `equivStmts` ⟹ `equivTransition`. The dispatcher reached the body - entry (`hRD` at `pcEntry`) under the entry coupling (`hR`, `hworld`); `h` runs the body and reads - off the matching EVM behaviour. `.returned`/`.reverted` close directly; the `.ok` fall-through - (body runs off the end → `ExecFuncBody.execBlockOK` gives an implicit `return none`) hands the - post-body cursor to `hfall`, the epilogue's trailing `RETURN`. - - This bridge is for externally-dispatched transition bodies. Internal callable bodies use - `equivCallable` below, where Solm `.returned` means "return to caller" rather than EVM `RETURN`. -/ -theorem equivStmts.toTransition {cfg : Config} {contract : ContractDecl} {t : TransitionDecl} - {cA gh bl σ σ₀ A I} {g : Sat256} {code : ByteArray} {callargs : Store} {R Q : StateRel} - {pcEntry : UInt256} {entry : Cursor} {kE CE : ℕ} - (hpc : entry.pc = pcEntry) - (hRD : RDc code I g (initState cA gh bl σ σ₀ g A I) entry kE CE) - (hworld : entry.world = worldOf (initState cA gh bl σ σ₀ g A I)) - (hR : R entry { contract := contract, locals := callargs } (initState cA gh bl σ σ₀ g A I)) - (h : equivTransitionStmts code I g (initState cA gh bl σ σ₀ g A I) - cfg t.returnType pcEntry R t.body Q) - (hfall : ∀ cur' k' C' frame' evm', - RDc code I g (initState cA gh bl σ σ₀ g A I) cur' k' C' → cur'.world = worldOf evm' → - Q cur' frame' evm' → - ∃ o, RDret code g (initState cA gh bl σ σ₀ g A I) (worldOf evm') o - ∧ returnEquiv o none t.returnType) : - equivTransition cfg contract t cA gh bl σ σ σ₀ A I g code callargs := by - obtain ⟨result, hbody, hmatch⟩ := - h entry kE CE { contract := contract, locals := callargs } (initState cA gh bl σ σ₀ g A I) - hpc hRD hworld hR - cases result with - | ok frame' evm' => - obtain ⟨cur', k', C', hRD', hw', hQ⟩ := hmatch - obtain ⟨o, hRDret, henc⟩ := hfall cur' k' C' frame' evm' hRD' hw' hQ - exact .returns hRDret (ExecFuncBody.execBlockOK hbody) rfl - (accountMapEquiv.refl evm'.accountMap) henc - | returned cs evm' rv => - obtain ⟨o, hRDret, henc⟩ := hmatch - exact .returns hRDret (ExecFuncBody.execBlockRet hbody) rfl - (accountMapEquiv.refl evm'.accountMap) henc - | reverted => exact .reverts hmatch (ExecFuncBody.execBlockRevert hbody) - | «break» _ _ => exact hmatch.elim - | «continue» _ _ => exact hmatch.elim - -/-! ### Callable/internal bodies -/ - -/-- Postcondition used by internal/local callables. A Solm return reaches a caller continuation - instead of halting the EVM; ordinary fall-through is treated as `return none`, matching - `ExecFuncBody.execBlockOK`. -/ -def callablePost (code : ByteArray) (ee : ExecutionEnv) (g : Sat256) (s0 : State) - (entry : Cursor) (returnTo : UInt256 → Prop) - (Return : Cursor → Option (List Value) → StoreRel) : StmtPost - | .ok frame' evm' => - ∃ cur' k' C', RDc code ee g s0 cur' k' C' ∧ cur'.world = worldOf evm' - ∧ Return entry none cur' frame'.locals evm' - ∧ returnTo cur'.pc - | .returned frame' evm' rv => - ∃ cur' k' C', RDc code ee g s0 cur' k' C' ∧ cur'.world = worldOf evm' - ∧ Return entry rv cur' frame'.locals evm' - ∧ returnTo cur'.pc - | .reverted => - RDrev code g s0 - | .break _ _ | .continue _ _ => - False - -/-- **Callable-body equivalence** for internal/local functions. - - Unlike `equivStmts`, a Solm `.returned rv` here is not an EVM halt. It means the callable has - returned to its caller, so the bytecode must reach a continuation cursor still inside the same - contract execution. The return postcondition is parameterized by the entry cursor and returned - value, allowing it to express calling conventions such as "jump to the return address from the - entry stack" and "place the return value in this stack slot". - - The precondition `R` is frame-shaped, so callers may either constrain `frame.contract` or leave - the callable generic over contracts. The return postcondition is locals-only (`StoreRel`) so the - caller-resume relation can focus on the returned store. -/ -def equivCallable (code : ByteArray) (ee : ExecutionEnv) (g : Sat256) (s0 : State) - (cfg : Config) (pc : UInt256) (R : StateRel) (callable : CallableDecl) - (ReturnTo : Cursor → UInt256 → Prop) - (Return : Cursor → Option (List Value) → StoreRel) : Prop := - ∀ entry k C args (frame : Frame) evm, - (hpc : entry.pc = pc) → - (hRD : RDc code ee g s0 entry k C) → - (hworld : entry.world = worldOf evm) → - bindParams? callable.params args = .some (frame.locals) → - (hR : R entry frame evm) → - CoupledState.refines (CoupledState.mk entry k C frame evm hpc hRD hworld hR) - cfg callable.body (callablePost code ee g s0 entry (ReturnTo entry) Return) - -/-- Concrete proof-state version of `equivStmts.internalCall`. - - This is the intended proof-mode rule: it consumes one coupled state `st`, so the setup and - continuation obligations are scoped to the actual call currently being peeled. -/ -theorem CoupledState.refines.internalCall {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cfg : Config} {funcPc : UInt256} {R Rcall R' : StateRel} - {Post : StmtPost} {callable : CallableDecl} {name : Ident} {args : List Expr} - {retVar : Ident} {rest : List Stmt} {ReturnTo : Cursor → UInt256 → Prop} - {Return : Cursor → Option (List Value) → StoreRel} - (st : CoupledState code ee g s0 R funcPc) - (hequiv : equivCallable code ee g s0 cfg funcPc Rcall callable ReturnTo Return) - (hsetup : - ∃ argVals locals, - evalExprs? cfg st.frame st.evm args = .ok argVals ∧ - lookupCallable? st.frame.contract name = some callable ∧ - bindParams? callable.params argVals = some locals ∧ - Rcall st.cur { st.frame with locals := locals } st.evm ∧ - (∀ rv curRet localsRet evmRet, - Return st.cur rv curRet localsRet evmRet → - ReturnTo st.cur curRet.pc → - R' curRet (resumeAfterInternalCall st.frame retVar rv) evmRet)) - (hrest : ∀ rv curRet kRet CRet localsRet evmRet, - ∀ (hRDRet : RDc code ee g s0 curRet kRet CRet) - (hworldRet : curRet.world = worldOf evmRet) - (_hReturn : Return st.cur rv curRet localsRet evmRet) - (_hReturnTo : ReturnTo st.cur curRet.pc) - (hRRet : R' curRet (resumeAfterInternalCall st.frame retVar rv) evmRet), - CoupledState.refines - (CoupledState.mk curRet kRet CRet (resumeAfterInternalCall st.frame retVar rv) evmRet - rfl hRDRet hworldRet hRRet) - cfg rest Post) - (hrevert : RDrev code g s0 → Post .reverted) : - CoupledState.refines st cfg (.internalCall name args retVar :: rest) Post := by - obtain ⟨argVals, locals, hargs, hlookup, hbind, hRcall, hresume⟩ := hsetup - obtain ⟨calleeResult, hcalleeBlock, hcalleePost⟩ := - hequiv st.cur st.k st.C argVals { st.frame with locals := locals } st.evm - st.hpc st.hRD st.hworld hbind hRcall - cases calleeResult with - | ok calleeFrame calleeEvm => - obtain ⟨curRet, kRet, CRet, hRDRet, hwRet, hReturn, hReturnTo⟩ := hcalleePost - have hstmt : ExecStmt cfg st.frame st.evm (.internalCall name args retVar) - (.ok (resumeAfterInternalCall st.frame retVar none) calleeEvm) := - ExecStmt.internalCallReturn hargs hlookup hbind (ExecFuncBody.execBlockOK hcalleeBlock) - obtain ⟨result, hrestBlock, hpost⟩ := - hrest none curRet kRet CRet calleeFrame.locals calleeEvm hRDRet hwRet hReturn hReturnTo - (hresume none curRet calleeFrame.locals calleeEvm hReturn hReturnTo) - exact ⟨result, ExecBlock.consNormal hstmt hrestBlock, hpost⟩ - | returned calleeFrame calleeEvm rv => - obtain ⟨curRet, kRet, CRet, hRDRet, hwRet, hReturn, hReturnTo⟩ := hcalleePost - have hstmt : ExecStmt cfg st.frame st.evm (.internalCall name args retVar) - (.ok (resumeAfterInternalCall st.frame retVar rv) calleeEvm) := - ExecStmt.internalCallReturn hargs hlookup hbind (ExecFuncBody.execBlockRet hcalleeBlock) - obtain ⟨result, hrestBlock, hpost⟩ := - hrest rv curRet kRet CRet calleeFrame.locals calleeEvm hRDRet hwRet hReturn hReturnTo - (hresume rv curRet calleeFrame.locals calleeEvm hReturn hReturnTo) - exact ⟨result, ExecBlock.consNormal hstmt hrestBlock, hpost⟩ - | reverted => - have hstmt : ExecStmt cfg st.frame st.evm (.internalCall name args retVar) .reverted := - ExecStmt.internalCallRevert hargs hlookup hbind (ExecFuncBody.execBlockRevert hcalleeBlock) - exact ⟨.reverted, ExecBlock.consRevert hstmt, hrevert hcalleePost⟩ - | «break» _ _ => - exact hcalleePost.elim - | «continue» _ _ => - exact hcalleePost.elim - -/-- **internal call (success / revert)** — peel an internal Solm call when the EVM cursor is already - at the callee body entry `funcPc`. - - `hsetup` is the caller-to-callee Solm bridge: it evaluates the caller arguments, checks the - callable lookup, binds callee locals, establishes the callable precondition `Rcall`, and explains - how a callable return relation resumes the caller frame. No extra EVM setup cursor is produced - here; if bytecode must jump from a call-site to `funcPc`, prove that as a preceding segment. - - `hrest` is indexed by the return PC relation supplied by the callable proof, but only for entries - satisfying this rule's own call-site precondition. That keeps the continuation obligation local - to the call being peeled instead of requiring it for every possible callable entry. -/ -theorem equivStmts.internalCall {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cfg : Config} {funcPc : UInt256} {R Rcall R' : StateRel} {Post : StmtPost} - {callable : CallableDecl} {name : Ident} {args : List Expr} {retVar : Ident} - {rest : List Stmt} {ReturnTo : Cursor → UInt256 → Prop} - {Return : Cursor → Option (List Value) → StoreRel} - (hequiv : equivCallable code ee g s0 cfg funcPc Rcall callable ReturnTo Return) - (hsetup : ∀ cur k C frame evm, - cur.pc = funcPc → - RDc code ee g s0 cur k C → - cur.world = worldOf evm → - R cur frame evm → - ∃ argVals locals, - evalExprs? cfg frame evm args = .ok argVals ∧ - lookupCallable? frame.contract name = some callable ∧ - bindParams? callable.params argVals = some locals ∧ - Rcall cur { frame with locals := locals } evm ∧ - (∀ rv curRet localsRet evmRet, - Return cur rv curRet localsRet evmRet → - ReturnTo cur curRet.pc → - R' curRet (resumeAfterInternalCall frame retVar rv) evmRet)) - (hrest : ∀ entry k C frame evm retPc, - entry.pc = funcPc → - RDc code ee g s0 entry k C → - entry.world = worldOf evm → - R entry frame evm → - ReturnTo entry retPc → - equivStmts code ee g s0 cfg retPc R' rest Post) - (hrevert : RDrev code g s0 → Post .reverted) : - equivStmts code ee g s0 cfg funcPc R (.internalCall name args retVar :: rest) Post := by - intro cur k C frame evm hpc hRD hw hR - obtain ⟨argVals, locals, hargs, hlookup, hbind, hRcall, hresume⟩ := - hsetup cur k C frame evm hpc hRD hw hR - obtain ⟨calleeResult, hcalleeBlock, hcalleePost⟩ := - hequiv cur k C argVals { frame with locals := locals } evm hpc hRD hw hbind hRcall - cases calleeResult with - | ok calleeFrame calleeEvm => - obtain ⟨curRet, kRet, CRet, hRDRet, hwRet, hReturn, hReturnTo⟩ := hcalleePost - have hstmt : ExecStmt cfg frame evm (.internalCall name args retVar) - (.ok (resumeAfterInternalCall frame retVar none) calleeEvm) := - ExecStmt.internalCallReturn hargs hlookup hbind (ExecFuncBody.execBlockOK hcalleeBlock) - obtain ⟨result, hrestBlock, hpost⟩ := - hrest cur k C frame evm curRet.pc hpc hRD hw hR hReturnTo curRet kRet CRet - (resumeAfterInternalCall frame retVar none) calleeEvm rfl hRDRet hwRet - (hresume none curRet calleeFrame.locals calleeEvm hReturn hReturnTo) - exact ⟨result, ExecBlock.consNormal hstmt hrestBlock, hpost⟩ - | returned calleeFrame calleeEvm rv => - obtain ⟨curRet, kRet, CRet, hRDRet, hwRet, hReturn, hReturnTo⟩ := hcalleePost - have hstmt : ExecStmt cfg frame evm (.internalCall name args retVar) - (.ok (resumeAfterInternalCall frame retVar rv) calleeEvm) := - ExecStmt.internalCallReturn hargs hlookup hbind (ExecFuncBody.execBlockRet hcalleeBlock) - obtain ⟨result, hrestBlock, hpost⟩ := - hrest cur k C frame evm curRet.pc hpc hRD hw hR hReturnTo curRet kRet CRet - (resumeAfterInternalCall frame retVar rv) calleeEvm rfl hRDRet hwRet - (hresume rv curRet calleeFrame.locals calleeEvm hReturn hReturnTo) - exact ⟨result, ExecBlock.consNormal hstmt hrestBlock, hpost⟩ - | reverted => - have hstmt : ExecStmt cfg frame evm (.internalCall name args retVar) .reverted := - ExecStmt.internalCallRevert hargs hlookup hbind (ExecFuncBody.execBlockRevert hcalleeBlock) - exact ⟨.reverted, ExecBlock.consRevert hstmt, hrevert hcalleePost⟩ - | «break» _ _ => - exact hcalleePost.elim - | «continue» _ _ => - exact hcalleePost.elim - -end Reasoning.Refinement diff --git a/Reasoning/SolmBody.lean b/Reasoning/SolmBody.lean index ee24250e..c53984fb 100644 --- a/Reasoning/SolmBody.lean +++ b/Reasoning/SolmBody.lean @@ -368,25 +368,6 @@ theorem checkedExternalCallNoCode {cfg : Config} {C : ContractDecl} {evm : EVM.S .reverted := by exact ExecBlock.consRevert (ExecStmt.requireFalse hguard) -/-- A one-statement typed external call through an address-valued local reverts when the raw call -returns `success = false`. -/ -theorem externalCallVarFailure {cfg : Config} {C : ContractDecl} - {evm evm' : EVM.State} {locals : Store} - {receiver retVar name : Ident} {target : AccountAddress} {sendVal : Int} - {args : List Expr} {argVals : List Value} {out : ByteArray} {perm : Bool} - (hreceiver : locals.get? receiver = some (.address target)) - (hargs : evalExprs? cfg { contract := C, locals := locals } evm args = .ok argVals) - (hcall : - typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals - (false, evm', out) perm) : - ExecBlock cfg { contract := C, locals := locals } evm - [ .externalCall (.var receiver) name (.intLit sendVal) args retVar (perm := perm) ] - .reverted := by - exact externalCallFailure - (receiver := .var receiver) - (by rw [evalExpr?, hreceiver]; rfl) - hargs hcall - /-- A one-statement typed external call through an address-valued local succeeds and stores the decoded return value. -/ theorem externalCallVarSuccess {cfg : Config} {C : ContractDecl} @@ -407,26 +388,6 @@ theorem externalCallVarSuccess {cfg : Config} {C : ContractDecl} (by rw [evalExpr?, hreceiver]; rfl) hargs hcall hdec -/-- If a typed external call succeeds but its return bytes fail ABI decoding, the source statement -reverts. -/ -theorem externalCallVarDecodeRevert {cfg : Config} {C : ContractDecl} - {evm evm' : EVM.State} {locals : Store} - {receiver retVar name : Ident} {target : AccountAddress} {sendVal : Int} - {args : List Expr} {argVals : List Value} {out : ByteArray} {perm : Bool} - (hreceiver : locals.get? receiver = some (.address target)) - (hargs : evalExprs? cfg { contract := C, locals := locals } evm args = .ok argVals) - (hcall : - typedCallViaEVM cfg evm (EVM.address target) name sendVal argVals - (true, evm', out) perm) - (hdec : cfg.externalABI.decode? name out = none) : - ExecBlock cfg { contract := C, locals := locals } evm - [ .externalCall (.var receiver) name (.intLit sendVal) args retVar (perm := perm) ] - .reverted := by - exact externalCallDecodeRevert - (receiver := .var receiver) - (by rw [evalExpr?, hreceiver]; rfl) - hargs hcall hdec - /-- A guarded typed external call through an address-valued local reverts when the raw call returns `success = false`. -/ theorem checkedExternalCallVarFailure {cfg : Config} {C : ContractDecl} @@ -571,61 +532,6 @@ theorem lowLevelCallFailureThenRequireFalse {cfg : Config} {C : ContractDecl} · exact ExecStmt.lowLevelCallFailure hreceiver heth hdata hcall · exact ExecBlock.consRevert (ExecStmt.requireFalse hrequire) -/-- A delegatecall followed by `require cond` succeeds when the call returns `success = true` and -the post-call condition evaluates to `true` in the frame containing `(okVar, dataVar)`. -/ -theorem delegateCallSuccessThenRequireTrue {cfg : Config} {C : ContractDecl} - {evm evm' : EVM.State} {locals : Store} - {receiver cdata requireCond : Expr} {okVar dataVar : Ident} - {target : AccountAddress} {calldata out : ByteArray} - (hreceiver : evalExpr? cfg { contract := C, locals := locals } evm receiver = - .ok (.address target)) - (hdata : evalExpr? cfg { contract := C, locals := locals } evm cdata = - .ok (.bytes calldata)) - (hcall : delegateCallViaEVM evm (EVM.address target) calldata (true, evm', out)) - (hrequire : - evalExpr? cfg - { contract := C, locals := (locals.insert okVar (.bool true)).insert dataVar (.bytes out) } - evm' requireCond = .ok (.bool true)) : - ExecBlock cfg { contract := C, locals := locals } evm - [ .delegateCall receiver cdata okVar dataVar, - .require requireCond ] - (.ok - { contract := C, - locals := (locals.insert okVar (.bool true)).insert dataVar (.bytes out) } evm') := by - refine ExecBlock.consNormal - (solm' := - { contract := C, - locals := (locals.insert okVar (.bool true)).insert dataVar (.bytes out) }) - (evm' := evm') ?_ ?_ - · exact ExecStmt.delegateCallSuccess hreceiver hdata hcall - · exact ExecBlock.consNormal (ExecStmt.requireTrue hrequire) ExecBlock.nil - -/-- A delegatecall followed by `require cond` reverts when the call returns `success = false` and -the post-call condition evaluates to `false` in the frame containing `(okVar, dataVar)`. -/ -theorem delegateCallFailureThenRequireFalse {cfg : Config} {C : ContractDecl} - {evm evm' : EVM.State} {locals : Store} - {receiver cdata requireCond : Expr} {okVar dataVar : Ident} - {target : AccountAddress} {calldata out : ByteArray} - (hreceiver : evalExpr? cfg { contract := C, locals := locals } evm receiver = - .ok (.address target)) - (hdata : evalExpr? cfg { contract := C, locals := locals } evm cdata = - .ok (.bytes calldata)) - (hcall : delegateCallViaEVM evm (EVM.address target) calldata (false, evm', out)) - (hrequire : - evalExpr? cfg - { contract := C, locals := (locals.insert okVar (.bool false)).insert dataVar (.bytes out) } - evm' requireCond = .ok (.bool false)) : - ExecBlock cfg { contract := C, locals := locals } evm - [ .delegateCall receiver cdata okVar dataVar, - .require requireCond ] - .reverted := by - refine ExecBlock.consNormal - (solm' := - { contract := C, locals := (locals.insert okVar (.bool false)).insert dataVar (.bytes out) }) - (evm' := evm') ?_ ?_ - · exact ExecStmt.delegateCallFailure hreceiver hdata hcall - · exact ExecBlock.consRevert (ExecStmt.requireFalse hrequire) - /-- **Hoare while-rule for the Solm semantics** — the loop analog of the EVM `RD.loop`. A variant-indexed invariant `P : ℕ → Store → Prop` (`P v L` = "invariant holds with `v` @@ -723,6 +629,37 @@ theorem execFor_var_state_continue {cfg : Config} {C : ContractDecl} · exact ⟨L', evm', ExecForLoop.iterate (htrue v L evm hP) hbody hpost hloop, hP'⟩ · exact ⟨L', evm', ExecForLoop.continueIter (htrue v L evm hP) hbody hpost hloop, hP'⟩ +/-! ## Block sequencing -/ + +/-- Append helper: if `s1` falls through to `(f1, e1)`, running `s2` from there is running `s1 ++ s2`. -/ +theorem execBlock_append {cfg : Config} {s2 : List Stmt} : + ∀ {s1 : List Stmt} {f e f1 e1 r}, ExecBlock cfg f e s1 (.ok f1 e1) → ExecBlock cfg f1 e1 s2 r → + ExecBlock cfg f e (s1 ++ s2) r := by + intro s1 + induction s1 with + | nil => intro f e f1 e1 r h1 h2; cases h1; exact h2 + | cons stmt rest ih => + intro f e f1 e1 r h1 h2 + cases h1 with + | consNormal hstmt hrest => exact ExecBlock.consNormal hstmt (ih hrest h2) + +/-- Append helper: if `s1` *terminates* (any non-`.ok` result), `s1 ++ s2` terminates the same way — + `s2` never runs. -/ +theorem execBlock_append_term {cfg : Config} {s2 : List Stmt} : + ∀ {s1 : List Stmt} {f e r}, ExecBlock cfg f e s1 r → (∀ f' e', r ≠ .ok f' e') → + ExecBlock cfg f e (s1 ++ s2) r := by + intro s1 + induction s1 with + | nil => intro f e r h1 hterm; cases h1; exact absurd rfl (hterm _ _) + | cons stmt rest ih => + intro f e r h1 hterm + cases h1 with + | consNormal hstmt hrest => exact ExecBlock.consNormal hstmt (ih hrest hterm) + | consReturn hstmt => exact ExecBlock.consReturn hstmt + | consRevert hstmt => exact ExecBlock.consRevert hstmt + | consBreak hstmt => exact ExecBlock.consBreak hstmt + | consContinue hstmt => exact ExecBlock.consContinue hstmt + /-! ## Forward block builder `ExecBlock` is built tail-first (`consNormal` needs the rest), so a straight-line body reads diff --git a/Reasoning/Storage.lean b/Reasoning/Storage.lean index 83469bbf..47b14ab9 100644 --- a/Reasoning/Storage.lean +++ b/Reasoning/Storage.lean @@ -237,27 +237,6 @@ theorem storageLocStore_int_some (evm : EVM.State) (loc : StorageLoc) (n : Int) /-! ## Solidity bytes/string storage layout -/ -theorem uInt256_shiftRight_zero_left (s : UInt256) : - UInt256.shiftRight (⟨0⟩ : UInt256) s = ⟨0⟩ := by - cases s with - | mk val => - unfold UInt256.shiftRight - simp - intro _ - apply Fin.ext - rw [Fin.shiftRight_val] - simp [Nat.zero_shiftRight] - -theorem fromBytes'_zero_take1_wordLE : - fromBytes' ((EVM.Word.toBytesLEWithSizeProof (⟨0⟩ : UInt256)).1.take 1) = 0 := by - native_decide - -theorem storageLocLoad_bytesLikeLengthLoc_zero {evm : EVM.State} {base : UInt256} - (hload : Solm.EVM.storageLoad evm evm.executionEnv.codeOwner base = ⟨0⟩) : - storageLocLoad evm (bytesLikeLengthLoc base evm) = .int 0 := by - unfold bytesLikeLengthLoc checkBytesPacked storageLocLoad wordToElem - simp [hload, fromBytes'_zero_take1_wordLE, uInt256_shiftRight_zero_left] - theorem solidityDecodeBytesLengthHeader_zero : solidityDecodeBytesLengthHeader ⟨0⟩ = .ok 0 := by have hflag : UInt256.land (⟨0⟩ : UInt256) ⟨1⟩ = ⟨0⟩ := by native_decide @@ -493,9 +472,6 @@ theorem storageLocStore_address_offset0 (evm : EVM.State) /-! ## Solidity address storage at byte offset 1 -/ -def addressOffset1Loc (slot : UInt256) : StorageLoc := - { slot := slot, offset := 1, size := 20, hbound := by decide, type := .address } - theorem storageLocLoad_address_offset1 (evm : EVM.State) (slot : UInt256) {hbound : (1 : Fin 32).val + (20 : Fin 33).val - 1 < 32} : storageLocLoad evm @@ -1287,13 +1263,6 @@ theorem storage_find?_update_insert_self (storage : Storage) · simp only [hzero, if_false] rw [storage_find?_insert_insert_self] -/-- Account lookup after two same-address writes is the same as after the final write. -/ -theorem accountMap_find?_insert_insert_self (σ : AccountMap) - (write read : AccountAddress) (acc1 acc2 : Account) : - ((σ.insert write acc1).insert write acc2).find? read = - (σ.insert write acc2).find? read := - rbmap_find?_insert_insert_self σ write read acc1 acc2 - /-- Inserting one account preserves lookup at a different address. -/ theorem accountMap_find?_insert_ne (σ : AccountMap) (read write : AccountAddress) (acc : Account) (hne : read ≠ write) : @@ -2357,16 +2326,6 @@ theorem storageStore_codeOwner {evm₁ evm₂ : EVM.State} (h : EVMStateEquiv ev end EVMStateEquiv -theorem storageLoad_storageStore_accountMapEquiv {evm1 evm2 : EVM.State} - (hAccounts : accountMapEquiv evm1.accountMap evm2.accountMap) - (addr : AccountAddress) (writeSlot val1 val2 readSlot : UInt256) - (hval : val1 = val2) : - Solm.EVM.storageLoad (Solm.EVM.storageStore evm1 addr writeSlot val1) addr readSlot = - Solm.EVM.storageLoad (Solm.EVM.storageStore evm2 addr writeSlot val2) addr readSlot := by - subst val2 - exact storageLoad_accountMapEquiv - (storageStore_accountMapEquiv hAccounts addr writeSlot val1) addr readSlot - theorem accountMapEquiv_sstoreAccountMap_two {σ τ : AccountMap} (a1 a2 : AccountAddress) (slot1 val1 slot2 val2 : UInt256) (hστ : accountMapEquiv σ τ) : diff --git a/Reasoning/Theory.lean b/Reasoning/Theory.lean index 7b60ea8d..d65af36f 100644 --- a/Reasoning/Theory.lean +++ b/Reasoning/Theory.lean @@ -118,13 +118,6 @@ theorem X_peel {vj : Array UInt256} {s s' : State} {P : Prop} [Decidable P] {f : · simp only [hg, if_false] at h ⊢ exact Xstep_X_X_continue f s s' vj (X f vj s') h rfl -/-- Continue step: when one `Xstep` does not halt, `X (f+1)` drops to `X f` on the - successor. (The non-branching specialisation of `X_peel`.) -/ -theorem X_continue {vj : Array UInt256} {s s' : State} {f : ℕ} - (h : Xstep vj s = .ok (s', .none)) : - X (f + 1) vj s = X f vj s' := - Xstep_X_X_continue f s s' vj (X f vj s') h rfl - /-- Collapse the two-stage gas guard of a memory opcode (charge `c1` for memory expansion, then `c2` for the base cost) into a single guard `gas < c1 + c2`. -/ theorem collapse_two_stage {α : Type _} {gas : Sat256} {c1 c2 : ℕ} {X Y : α} : @@ -282,44 +275,6 @@ theorem reEquiv_receiveExecution runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g A I := .execution rfl (.receive hreceive hparams hreturn rfl hbody) hequiv -/-- The fallback transition executes without selector ABI decoding and `Ξ`'s result matches. -/ -theorem reEquiv_fallbackExecution - {cfg contract cA gh bl σ_evm σ_solm σ₀ A I} {t actRes returnConvention} - {g : UInt256} - (hd : selectorDispatchMsg contract I.calldata = none) - (hreceive : receiveDispatchMsg contract I.calldata = none) - (hfallback : contract.fallback = some t) - (hargs : fallbackCallargs I.calldata t.params = some callargs) - (hreturn : fallbackReturnConvention t = some returnConvention) - (hbody : ExecTransitionBody cfg contract - (initState cA gh bl σ_solm σ₀ (.ofUInt256 g) A I) callargs t.body actRes) - (hequiv : execResultsEquiv (Ξ cA gh bl σ_evm σ₀ g A I) actRes returnConvention) : - runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g A I := - .execution rfl (.fallback hd hreceive hfallback hargs hreturn rfl hbody) hequiv - /-! ## 4. Fuel monotonicity -/ -/-- **More fuel never changes a terminating run.** Once `X` reaches a genuine terminal - result (`.ok _`, or an error other than `.OutOfFuel`) with fuel `n`, any larger fuel - `m` yields the same result. This lets a universally-quantified fuel `g.toNat + 1` be - replaced by a concrete bound once the trace is known to terminate. -/ -theorem X_mono {vj : Array UInt256} {s : State} : - ∀ {n : ℕ} {r}, X n vj s = r → r ≠ .error .OutOfFuel → - ∀ {m : ℕ}, n ≤ m → X m vj s = r := by - intro n - induction n generalizing s with - | zero => intro r hr hne _ _; rw [X] at hr; exact absurd hr.symm hne - | succ n ih => - intro r hr hne m hm - obtain ⟨m, rfl⟩ : ∃ k, m = k + 1 := ⟨m - 1, by omega⟩ - rw [X] at hr ⊢ - cases hstep : Xstep vj s with - | error e => simp only [hstep, bind, Except.bind] at hr ⊢; exact hr - | ok p => - obtain ⟨s', ctrl⟩ := p - simp only [hstep, bind, Except.bind] at hr ⊢ - cases ctrl with - | none => exact ih hr hne (by omega) - | some bo => obtain ⟨b, o⟩ := bo; cases b <;> simpa using hr - end Reasoning.Theory From bb57efdf26f4d56ef224037653d6410e3dfcb8d2 Mon Sep 17 00:00:00 2001 From: zoep Date: Tue, 28 Jul 2026 22:00:45 +0300 Subject: [PATCH 19/38] Benchmarks: add forgoten source syntax file --- Benchmarks/EAS/Attester/SpecSyntax.lean | 88 +++++++++++++++++++++++++ README.md | 7 ++ 2 files changed, 95 insertions(+) create mode 100644 Benchmarks/EAS/Attester/SpecSyntax.lean diff --git a/Benchmarks/EAS/Attester/SpecSyntax.lean b/Benchmarks/EAS/Attester/SpecSyntax.lean new file mode 100644 index 00000000..0fef9ea5 --- /dev/null +++ b/Benchmarks/EAS/Attester/SpecSyntax.lean @@ -0,0 +1,88 @@ +import Benchmarks.EAS.Attester.Spec +import Solm.Notation + +/-! +# EAS Attester spec in the Solidity-faithful Solm frontend + +The whole Attester spec written with `solidity%`, parameterized by the immutable valuation +`v : AttesterImmutables`, and proven definitionally equal to the AST spec. + +Escapes: the EAS calls (`${easCall …}`/`${checkedEASCallStmts …}` splices — the receiver is the +immutable `easExpr v`, not an identifier) with their binders read back via `${Expr.var …}`, and +`${zeroBytes32}` (the AST models it as a cast, while surface `bytes32(0)` is the fixed-bytes +literal). The EAS request payloads are surface ABI tuples (`tuple(…)` literals with +`(bytes32, (address, uint64, bool, bytes32, bytes, uint256)[])[]`-typed locals). +-/ + +open Solm Solm.Notation +open Benchmarks.EAS.Attester Benchmarks.EAS.Attester.Immutables + +namespace Benchmarks.EAS.Attester.Syntax + +def contractSyntax (v : AttesterImmutables) : ContractDecl := solidity% contract Attester { + constructor(address eas) { + require(eas != address(0)); + address imm_eas = eas; + } + + function attest(bytes32 schema, uint256 input) external returns (bytes32) { + ${[easCall v "attest" [attestationRequest (.var "schema") (.var "input")] "uid"]} + return ${Expr.var "uid"}; + } + + function multiAttest(bytes32[] schemas, uint256[][] schemaInputs) external returns (bytes32[]) { + uint256 schemaLength = schemas.length; + require(schemaLength != 0 && schemaLength == schemaInputs.length); + (bytes32, (address, uint64, bool, bytes32, bytes, uint256)[])[] multiRequests = + new (bytes32, (address, uint64, bool, bytes32, bytes, uint256)[])[](schemaLength); + uint256 i = 0; + while (i < schemaLength) { + uint256[] inputs = schemaInputs[i]; + uint256 inputLength = inputs.length; + require(inputLength != 0); + (address, uint64, bool, bytes32, bytes, uint256)[] data = + new (address, uint64, bool, bytes32, bytes, uint256)[](inputLength); + uint256 j = 0; + while (j < inputLength) { + data[j] = tuple(address(0), 0, true, ${zeroBytes32}, + abi.encodeWithSelector(__abi_encode_uint256, inputs[j])[4 : 36], 0); + j = (j + 1) as uint256; + } + multiRequests[i] = tuple(schemas[i], data); + i = (i + 1) as uint256; + } + ${[easCall v "multiAttest" [.var "multiRequests"] "uids"]} + return ${Expr.var "uids"}; + } + + function multiRevoke(bytes32[] schemas, bytes32[][] schemaUids) external { + uint256 schemaLength = schemas.length; + require(schemaLength != 0 && schemaLength == schemaUids.length); + (bytes32, (bytes32, uint256)[])[] multiRequests = + new (bytes32, (bytes32, uint256)[])[](schemaLength); + uint256 i = 0; + while (i < schemaLength) { + bytes32[] uids = schemaUids[i]; + uint256 uidLength = uids.length; + require(uidLength != 0); + (bytes32, uint256)[] data = new (bytes32, uint256)[](uidLength); + uint256 j = 0; + while (j < uidLength) { + data[j] = tuple(uids[j], 0); + j = (j + 1) as uint256; + } + multiRequests[i] = tuple(schemas[i], data); + i = (i + 1) as uint256; + } + ${checkedEASCallStmts v "multiRevoke" [.var "multiRequests"] "_multiRevoke"} + } + + function revoke(bytes32 schema, bytes32 uid) external { + ${checkedEASCallStmts v "revoke" [revocationRequest (.var "schema") (.var "uid")] "_revoke"} + } +} + +theorem contractSyntax_eq (v : AttesterImmutables) : + contractSyntax v = Benchmarks.EAS.Attester.contract v := by rfl + +end Benchmarks.EAS.Attester.Syntax diff --git a/README.md b/README.md index 95e39a19..2ccb69c7 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,13 @@ selector facts, since Keccak is an opaque foreign constant; and Lean's compiled evaluator via `native_decide`. The proof-producing agent, tactics, and macros are not trusted — the kernel re-checks every proof term. +## Note on AI use + +The development of EquiVM is assisted by LLMs. Semantics and related definitions +were designed and reviewed by humans. Proofs of equivalence between the Sol⁻ +specifications and the EVM bytecode, related boilerplate, and the Sol⁻ +specifications themselves were produced by LLMs. + ## Paper You can find a detailed description of the theory and evaluation in the paper [*Foundational Refinement Proofs for Deployed Bytecode, at The Price of Tokens*](TODO). From b8dd4815b10911f80c38f1af4cb0ef55329240b3 Mon Sep 17 00:00:00 2001 From: zoep Date: Tue, 28 Jul 2026 22:01:20 +0300 Subject: [PATCH 20/38] Misc: supporting proof files --- Misc/Template/Bytecode.lean | 43 +++ Misc/Template/Common.lean | 42 +++ Misc/Template/Constructor.lean | 35 +++ Misc/Template/Correct.lean | 47 +++ Misc/Template/Dispatch.lean | 35 +++ Misc/Template/Function.lean | 41 +++ Misc/Template/README.md | 80 +++++ Misc/Template/Spec.lean | 63 ++++ Misc/Template/SpecSyntax.lean | 52 ++++ Misc/Template/Trusted.lean | 27 ++ Misc/prompt.md | 550 +++++++++++++++++++++++++++++++++ 11 files changed, 1015 insertions(+) create mode 100644 Misc/Template/Bytecode.lean create mode 100644 Misc/Template/Common.lean create mode 100644 Misc/Template/Constructor.lean create mode 100644 Misc/Template/Correct.lean create mode 100644 Misc/Template/Dispatch.lean create mode 100644 Misc/Template/Function.lean create mode 100644 Misc/Template/README.md create mode 100644 Misc/Template/Spec.lean create mode 100644 Misc/Template/SpecSyntax.lean create mode 100644 Misc/Template/Trusted.lean create mode 100644 Misc/prompt.md diff --git a/Misc/Template/Bytecode.lean b/Misc/Template/Bytecode.lean new file mode 100644 index 00000000..2d0aaa12 --- /dev/null +++ b/Misc/Template/Bytecode.lean @@ -0,0 +1,43 @@ +import Benchmarks.Xxx.Spec +import Ethereum.Semantics +import Reasoning.JumpDest + +/-! +# Xxx bytecode (TEMPLATE) + +Record the EXACT build command and compiler version, e.g.: + +```bash +/tmp/solc-0.8.20 --optimize --optimize-runs 200 --metadata-hash none \ + --bin --bin-runtime --abi --storage-layout --ast-compact-json \ + -o /tmp/equivm-xxx-build --overwrite Benchmarks/Xxx/contracts/Xxx.sol +``` + +Runtime bytecode: N bytes; creation bytecode: M bytes. Large arrays are split into chunks to +keep elaboration predictable. `runtime.hex`/`creation.hex` hold the same bytes hex-encoded. +-/ + +open Solm Ethereum Ethereum.EVM + +namespace Benchmarks.Xxx + +set_option maxRecDepth 50000000 +set_option maxHeartbeats 0 + +private def xxxRuntimeChunk0 : ByteArray := + ⟨#[0x60, 0x80, 0x60, 0x40]⟩ -- TODO: paste chunks (≤ ~1000 bytes each) + +def xxxBytecode : ByteArray := + xxxRuntimeChunk0 -- TODO: ++ chunk1 ++ … + +private def xxxCreationChunk0 : ByteArray := + ⟨#[0x60, 0x80, 0x60, 0x40]⟩ -- TODO + +def xxxCreationBytecode : ByteArray := + xxxCreationChunk0 -- TODO + +-- Jump-destination facts. `native_decide` is the accepted mechanism here (deliberate; a scoped +-- `first | decide | native_decide` fallback was tried and rejected). +theorem xxxJumpDests : jump_dest xxxBytecode ⟨0x10⟩ := by native_decide -- TODO: per dest + +end Benchmarks.Xxx diff --git a/Misc/Template/Common.lean b/Misc/Template/Common.lean new file mode 100644 index 00000000..93bbd31c --- /dev/null +++ b/Misc/Template/Common.lean @@ -0,0 +1,42 @@ +import Benchmarks.Xxx.Bytecode +import Reasoning.ABI +import Reasoning.Theory +import Reasoning.Stepping +import Reasoning.Reach +import Reasoning.Solc +import Reasoning.Memory +import Reasoning.Storage +import Reasoning.Dispatch +import Reasoning.SolmBody +import Mathlib.Tactic.IntervalCases + +/-! +# Xxx shared proof foundation (TEMPLATE) + +Contract-wide selector notation and constants for the optimized runtime. +-/ + +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach + +set_option maxRecDepth 2000000 + +namespace Benchmarks.Xxx + +/-- The 4-byte selector word computed by `CALLDATALOAD(0); SHR 224`. -/ +abbrev xxxSelWord (I : ExecutionEnv) : UInt256 := + UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes 0 32)) ⟨224⟩ + +/-- The 4-byte selector of `I`'s calldata equals `sel`. -/ +abbrev selIs (I : ExecutionEnv) (sel : ByteArray) : Prop := + (sel == I.calldata.extract 0 4) = true + +/-- Function selectors in `contract.transitions` order (index comments per signature). -/ +def xxxSelBytes : ℕ → ByteArray + | 0 => ⟨#[0x55, 0x24, 0x11, 0x0f]⟩ -- setValue(uint256) TODO real bytes + | _ => ⟨#[0x3f, 0xa4, 0xf2, 0x45]⟩ -- value() TODO real bytes + +-- TODO: dispatcher pc constants (root split, group splits, first-arm pcs) read off the +-- disassembly, e.g.: +-- def xxxRootSplitPc : UInt256 := ⟨0x4b⟩ + +end Benchmarks.Xxx diff --git a/Misc/Template/Constructor.lean b/Misc/Template/Constructor.lean new file mode 100644 index 00000000..81e74cc6 --- /dev/null +++ b/Misc/Template/Constructor.lean @@ -0,0 +1,35 @@ +import Benchmarks.Xxx.Common + +/-! +# Xxx constructor correctness (TEMPLATE) + +Creation-code equivalence: the constructor's EVM trace (arg decode, stores, runtime-code +return) against the Solm constructor body. For non-trivial constructors split the trace into +`ConstructorTrace*` files (args / stores / return) and the Solm side into `ConstructorSource`, +then assemble here through the account-map-equivalence chain — see +`Benchmarks/Dss/Pot/Constructor.lean` and `Examples/Ballot`'s creation proof. + +Shape of the capstone piece: + +``` +theorem xxxConstructorCorrect : + constructorEquivalence config xxxCreationBytecode contract xxxBytecode := by + refine constructorEquivalence.intro ?_ + intro createdAccounts genesisBlockHeader blocks σ_evm σ_solm σ₀ g A I args deployedInitcode + hdeploy hcode hcalldata hperm hAccounts + -- 1. shape of the deployment payload (initcode ++ ABI-encoded args) + -- 2. by_cases on weiValue: nonzero ⇒ the callvalue guard reverts on both sides + -- 3. success: run the creation trace, build the stored account map store-by-store, + -- and match the Solm constructor evaluation + sorry +``` +-/ + +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach + +namespace Benchmarks.Xxx + +-- TODO: xxxCtorDeployment_shape, xxxInitcodeSuccess, per-store account maps, +-- theorem xxxConstructorCorrect (see docstring). + +end Benchmarks.Xxx diff --git a/Misc/Template/Correct.lean b/Misc/Template/Correct.lean new file mode 100644 index 00000000..71c7c417 --- /dev/null +++ b/Misc/Template/Correct.lean @@ -0,0 +1,47 @@ +import Benchmarks.Xxx.Constructor +import Benchmarks.Xxx.Function -- one import per transition's proof file +import Solm.Equiv + +/-! +# Xxx correctness capstone (TEMPLATE) + +Thin top-level: the dispatcher driver routes each selector to its per-function `…Body` lemma, +adds the shared revert paths (non-payable guard, no-dispatch), and packages the constructor with +the runtime target into the whole-contract equivalence. Mirrors +`Benchmarks/Dss/Pot/Correct.lean` — copy that file's `NonPayable`/`NoDispatch`/ +`NoSelectorMatches` scaffolding and rename. + +After it compiles, verify axiom hygiene on the capstone: only the `Trusted.lean` selector +axioms and the standard Lean axioms may appear. +-/ + +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach + +set_option maxRecDepth 2000000 + +namespace Benchmarks.Xxx + +-- theorem xxxNonPayable … (hwv : I.weiValue ≠ ⟨0⟩) : +-- runtimeEquivalenceFor config contract … := … (Pot: potNonPayable) + +-- theorem xxxNoDispatch … (hnm : ∀ i, i < nArms → (xxxSelBytes i == …) = false) : +-- runtimeEquivalenceFor config contract … := … (Pot: potNoDispatch) + +-- theorem xxxNoSelectorMatches … : ∀ i, i < nArms → … := by interval_cases i <;> simpa [selIs] … + +-- theorem xxxCorrect : runtimeEquivalence config xxxBytecode contract := by +-- refine runtimeEquivalence.intro ?_ +-- intro cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts +-- by_cases hwv : I.weiValue = ⟨0⟩ +-- · by_cases h0 : selIs I (xxxSelBytes 0) +-- · exact xxxSetValueBody hcode hsize hperm hwv h0 hAccounts +-- · by_cases h1 : selIs I (xxxSelBytes 1) +-- · exact xxxValueBody hcode hsize hperm hwv h1 hAccounts +-- · exact xxxNoDispatch hcode hsize hperm hwv (xxxNoSelectorMatches h0 h1) hAccounts +-- · exact xxxNonPayable hcode hwv + +-- theorem xxxContractCorrect : +-- contractEquivalence config xxxCreationBytecode xxxBytecode contract := +-- contractEquivalence.intro xxxConstructorCorrect xxxCorrect + +end Benchmarks.Xxx diff --git a/Misc/Template/Dispatch.lean b/Misc/Template/Dispatch.lean new file mode 100644 index 00000000..84713ac3 --- /dev/null +++ b/Misc/Template/Dispatch.lean @@ -0,0 +1,35 @@ +import Benchmarks.Xxx.Trusted + +/-! +# Xxx dispatcher walk (TEMPLATE) + +Reach lemmas from the runtime entry to each selector arm, mirroring the compiled dispatcher's +binary-search/comparison tree. This file is bytecode-driven: read the tree shape off the +disassembly (root `GT` split, per-group `EQ` chains), define per-group "reach arm j" lemmas, and +close each with symbolic stepping. + +See `Benchmarks/Dss/Pot/Dispatch.lean` (`potReachG54Body` etc.) and +`Benchmarks/Dss/Jug/Dispatch.lean` for the full pattern, including: + +- `xxxSelWord_eq_of_beq` — from `selIs I (xxxSelBytes k)` to the concrete selector word; +- `armSelNat`/`nthArmPc` bookkeeping over the arm list; +- `native_decide` for the concrete word comparisons; +- `xxxDispatch_none_nomatch` / `xxxDispatch_none_short` — Solm-side `dispatchMsg … = none` + facts used by the no-dispatch branch of `Correct.lean`. +-/ + +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach + +namespace Benchmarks.Xxx + +-- TODO: reach lemmas per dispatcher group, e.g. +-- theorem xxxReachArm (j : ℕ) (hj : j < nArms) (pc : UInt256) (hcode : I.code = xxxBytecode) +-- (hwv : I.weiValue = ⟨0⟩) (hsz : 4 ≤ I.calldata.size) … : ∃ k C, RD xxxBytecode I g … := … + +-- TODO: theorem xxxDispatch_none_short (h : I.calldata.size < 4) : +-- dispatchMsg contract I.calldata = none := … +-- TODO: theorem xxxDispatch_none_nomatch +-- (hnm : ∀ i, i < nArms → (xxxSelBytes i == I.calldata.extract 0 4) = false) : +-- dispatchMsg contract I.calldata = none := … + +end Benchmarks.Xxx diff --git a/Misc/Template/Function.lean b/Misc/Template/Function.lean new file mode 100644 index 00000000..31ad8a52 --- /dev/null +++ b/Misc/Template/Function.lean @@ -0,0 +1,41 @@ +import Benchmarks.Xxx.Dispatch + +/-! +# Xxx `setValue(uint256)` (TEMPLATE — one file per transition, named after it) + +Per-function pipeline: calldata-decode facts, the reach lemma into this selector's arm, the EVM +trace through the body, the Solm-side body evaluation, and the `…Body` theorem consumed by +`Correct.lean`. Big functions split the middle parts across `Trace*`/`Source*`/ +`EVM*` files (see `Benchmarks/Dss/Pot/Drip*` or `Benchmarks/Dss/Cat/Bite*`). + +Name every helper with the function prefix (`xxxSetValueKey`, not `key`): generic names collide +at the `Correct.lean` import join when several functions are proved in parallel sessions. +-/ + +open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach + +namespace Benchmarks.Xxx + +/-! ## Calldata decoding -/ + +-- theorem xxxDecode_setValue_ok {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) : +-- decodeCalldataWithMode config.abiDecodeMode (setValueTransition.params.map Param.name) +-- (transitionSignature setValueTransition).paramTypes I.calldata = +-- some ((∅ : Store).insert "data" (.int … (calldataWord I.calldata 4) …)) := … + +-- theorem xxxDecode_setValue_none_short {I : ExecutionEnv} +-- (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 36) : … = none := … + +/-! ## Runtime trace + body theorem -/ + +-- theorem xxxReachSetValueBody … : +-- ∃ k C, RD xxxBytecode I g (initState …) ⟨armPc⟩ [xxxSelWord I] solcFreePtrMem … := … + +-- The theorem `Correct.lean` consumes (fixed signature shape): +-- theorem xxxSetValueBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} +-- (hcode : I.code = xxxBytecode) (hsize : I.calldata.size < UInt256.size) +-- (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) +-- (hsel : selIs I (xxxSelBytes 0)) (hAccounts : accountMapEquiv σ_evm σ_solm) : +-- runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := … + +end Benchmarks.Xxx diff --git a/Misc/Template/README.md b/Misc/Template/README.md new file mode 100644 index 00000000..1fb2cf3b --- /dev/null +++ b/Misc/Template/README.md @@ -0,0 +1,80 @@ +# Refinement proof template + +Skeletons for adding a new contract and proving the deployed runtime bytecode +equivalent to its Solm spec. `Misc/` is not a lake target: these files do not +build; they are reference scaffolds for the layout and shapes described below. + +The division of labor is deliberate: **the user provides the compiled artifacts +and the surface specification (`SpecSyntax.lean`) — the boilerplate and the +proof are the job of the LLM agent**, driven by the prompt in `Misc/prompt.md`. + +Proven end-to-end exemplars: `Benchmarks/Dss/Pot` (this template's source), +`Benchmarks/Dss/Jug`, `Benchmarks/Dss/Cat`, `Benchmarks/WETH9`, `Examples/Ballot`. + +## Directory layout + +Every contract directory follows this structure (`Examples//` or +`Benchmarks/[/]/`): + +| file | role | author | +|---|---|---| +| `contracts/` or `.sol` | pinned source (vendored imports under `contracts/`) | user | +| `sources.sha256` | `shasum -a 256` of the pinned sources | user | +| `creation.hex`, `runtime.hex` | compiler output, hex-encoded | user | +| `.abi.json`, `.storage.json`, `.sol.ast.json` | solc artifacts used for audits | user | +| `SpecSyntax.lean` | **the specification**: the contract in `solidity%` surface syntax | user | +| `Immutables.lean` | contracts with immutables only: the valuation structure + read exprs | user | +| `Spec.lean` | derived assembly: `def contract := Syntax.contractSyntax`, named transition handles, storage layout, `Config` | agent | +| `Bytecode.lean` | runtime/creation bytes as chunked `ByteArray`s + jump-dest facts, transcribed from the `.hex` files | agent | +| `Common.lean` | selector table, `selIs`/`selWord`, shared proof helpers | agent | +| `Storage.lean` | contract-wide storage load/store facts (contracts with storage) | agent | +| `Trusted.lean` | the accepted trusted base: per-function selector-bytes axioms | agent | +| `Dispatch.lean` | dispatcher walk: reach lemmas from entry to each selector arm | agent | +| `.lean` (×N) | per-function proof: decode lemmas, EVM trace, source body, `…Body` refinement | agent | +| `Constructor.lean` (+ `ConstructorTrace*`) | creation-code equivalence | agent | +| `Correct.lean` | thin capstone: dispatch routing, revert paths, `Correct` / `ContractCorrect` | agent | + +The existing contracts predate this flow and carry both a hand-written AST in +`Spec.lean` and the surface syntax in `SpecSyntax.lean`, related by a proved +`contractSyntax_eq … := by rfl`. There is no reason for a new contract to +provide both: exactly one of the two files carries the spec, and for new work +that is `SpecSyntax.lean` — `Spec.lean` only references it. + +## Workflow + +1. **Compile & pin** (user). Build with the contract's original compiler + settings, save `creation.hex`/`runtime.hex`/ABI/storage/AST JSON, write + `sources.sha256`, and record the exact command and compiler version (it ends + up in `Bytecode.lean`'s header). Bytecode provenance is arbitrary — the + proof targets whatever was actually deployed, optimizer included. +2. **Specification** (user). Author the contract in `solidity%` surface syntax + (see `Solm/Notation.lean` header for the language). For the most part it + mirrors the Solidity source, when one is available. Events, error payloads, + and exact gas tracking are not modeled currently. Contracts with immutables + also get an `Immutables.lean` valuation. +3. **Everything else** (agent). Hand the directory to the agent with + `Misc/prompt.md`. It audits the spec against the bytecode, assembles the + derived `Spec.lean` (contract reference, per-transition handles, storage + layout, external-call ABI, `Config`), transcribes `Bytecode.lean`, + scaffolds `Correct.lean`'s dispatch skeleton, proves each function body and + the constructor in their own files, and closes the top-level theorems — + `sorry`-free and axiom-clean up to the accepted trusted base (selector and + jump-dest facts, plus the tolerated `Reasoning/` axioms). +4. **Acceptance** (user). `lake build .Correct` succeeds, no + `sorry`/`admit` in the directory, and `#print axioms` on the capstone shows + only the accepted set (see the finish checklist in `Misc/prompt.md`). + +## Conventions + +- Namespaces `Examples.` / `Benchmarks.[.]`; the surface file + uses `.Syntax` with `contractSyntax`. +- Transitions in selector (dispatch) order everywhere: surface file, derived + handles, selector table. +- Solidity names that are Lean keywords are guillemet-escaped in the surface + syntax: «from», «to», «end», … +- The non-payable guard is implicit in the surface syntax; `payable` marks the + entry points whose compiled body has no callvalue check. +- Parameterized contracts thread the immutable valuation `v` through + `contractSyntax`, `contract`, and the theorems. If a large parameterized + `rfl` ever times out, `simp only [, List.cons_append, + List.nil_append]; rfl` closes it (cf. `Benchmarks/Dss/Dog/SpecSyntax.lean`). diff --git a/Misc/Template/Spec.lean b/Misc/Template/Spec.lean new file mode 100644 index 00000000..a3c76ff7 --- /dev/null +++ b/Misc/Template/Spec.lean @@ -0,0 +1,63 @@ +import Benchmarks.Xxx.SpecSyntax +import Solm.Semantics +import Solm.SolidityLayout + +/-! +# Xxx spec assembly (TEMPLATE) — derived, not authored + +Single-source flow: the contract is DEFINED by `SpecSyntax.lean`; this file only references it +and assembles what the surface syntax cannot carry — named handles for the proof files, the +storage layout, the external-call ABI, and the `Config`. Nothing here restates the contract. + +(Audited two-file flow instead: this file holds the hand-written AST — see +`Benchmarks/Dss/Pot/Spec.lean` — and `SpecSyntax.lean` proves `rfl`-equality against it.) +-/ + +open Solm ABI + +namespace Benchmarks.Xxx + +/-! ## The contract AST in Sol⁻ -/ + +def contract : ContractDecl := Syntax.contractSyntax + +/-- Named handles in `contract.transitions` (selector) order — what the per-function proof + files unfold. All defeq projections; keep the index comments honest. -/ +abbrev constructorDecl : ConstructorDecl := contract.ctor +abbrev setValueTransition : TransitionDecl := contract.transitions[0]! -- setValue(uint256) +abbrev valueTransition : TransitionDecl := contract.transitions[1]! -- value() + +/-! ## Types shared with the proof files -/ + +def uint256Int : IntType := .uint ⟨256, by decide⟩ + +/-! ## Storage layout — the part that stays hand-written + +Derivable only when the contract uses Solidity's standard layout; packing, nested +mapping→array→struct shapes, and compact strings need the per-contract cases below +(cf. `Examples/Ballot/Spec.lean`, `Benchmarks/WETH9/Spec.lean`). -/ + +def mapSlot (key baseSlot : Ethereum.UInt256) : Ethereum.UInt256 := + Ethereum.uInt256OfByteArray (ffi.KEC (key.toByteArray ++ baseSlot.toByteArray)) + +def wordLoc (slot : Ethereum.UInt256) : StorageLoc := + { slot := slot, offset := 0, size := 32, hbound := by decide, type := .int uint256Int } + +-- TODO: match the deployed bytecode's slot assignment. +def storageLayoutRaw : EvaledStorageRef -> EVM.State -> Option StorageLoc + | { base := "wards", steps := [.mindex a] }, _ => some (wordLoc (mapSlot (keyValueToWord a) ⟨0⟩)) + | { base := "value", steps := [] }, _ => some (wordLoc ⟨1⟩) + | _, _ => none + +def storageLayout : StorageLayout := solidityStorageLayout storageLayoutRaw + +/-! ## Config -/ + +-- TODO for contracts with external calls: a real `ExternalCallABI` with the callee selectors +-- (cf. `Benchmarks/EAS/Attester/Spec.lean`); `abiDecodeMode` per compiler version. +def config : Config := + { storage := storageLayout + externalABI := defaultExternalCallABI + selfDeployment := genSolidityConstructorDeployment contract.ctor.params } + +end Benchmarks.Xxx diff --git a/Misc/Template/SpecSyntax.lean b/Misc/Template/SpecSyntax.lean new file mode 100644 index 00000000..1fc39e10 --- /dev/null +++ b/Misc/Template/SpecSyntax.lean @@ -0,0 +1,52 @@ +import Solm.Notation + +/-! +# Xxx surface spec (TEMPLATE) + +The contract in `solidity%` surface syntax (surface language: +`Solm/Notation.lean` header). `Spec.lean` references `contractSyntax` and +derives everything else (named handles, layout, `Config`); the proof files never +look at this file directly. + +Conventions: transitions in selector (dispatch) order; the non-payable guard is +implicit (mark `payable` only where the compiled body has no callvalue check); +bind call results explicitly; guillemet-escape Lean-keyword identifiers («from», +«to», «end»); escapes `${e}`/`${stmts}`/`#c` only for immutable reads, +Expr-valued call receivers, and Lean constants. + +Parameterized contracts (immutables): author `Immutables.lean` first, then `def +contractSyntax (v : XxxImmutables) : ContractDecl := solidity% contract Xxx { … +}`. + +Alternative: hand-write the AST in `Spec.lean` instead, make this file `import +Benchmarks.Xxx.Spec`, and end it with `theorem contractSyntax_eq : +contractSyntax = Benchmarks.Xxx.contract := by rfl`. Either way exactly *one* of +the two files carries the spec content. The existing contracts provide both the +surface syntax in`SpecSyntax.lean`and the AST in `Spec.lean` (with a proof of +correspondence), but there is no reason for the user to provide both. + +-/ + +open Solm Solm.Notation + +namespace Benchmarks.Xxx.Syntax + +def contractSyntax : ContractDecl := solidity% contract Xxx { + mapping(address => uint256) wards; + uint256 value; + + constructor() { + wards[msg.sender] = 1; + } + + function setValue(uint256 data) external { + require(wards[msg.sender] == 1); + value = data; + } + + function value() external returns (uint256) { + return value; + } +} + +end Benchmarks.Xxx.Syntax diff --git a/Misc/Template/Trusted.lean b/Misc/Template/Trusted.lean new file mode 100644 index 00000000..5e58b5b4 --- /dev/null +++ b/Misc/Template/Trusted.lean @@ -0,0 +1,27 @@ +import Benchmarks.Xxx.Common + +/-! +# Xxx trusted selector facts (TEMPLATE) + +Lean does not reduce the FFI-backed Keccak used by `selectorOf`, so the selector bytes of each +function are stated as axioms. This file is the ENTIRE accepted trusted base of the proof — +keep it to exactly one axiom per transition, and cross-check the bytes against the ABI JSON. +The capstone's axiom check (`lean_verify` / `#print axioms`) must show only these plus the +standard Lean axioms. +-/ + +open Solm ABI Ethereum Ethereum.EVM + +namespace Benchmarks.Xxx + +/-- `keccak("setValue(uint256)")[0:4] = 0x…`. -/ +axiom setValueSelectorBytes : + (ffi.KEC (String.toByteArray (transitionSigStr setValueTransition))).extract 0 4 = + xxxSelBytes 0 + +/-- `keccak("value()")[0:4] = 0x…`. -/ +axiom valueSelectorBytes : + (ffi.KEC (String.toByteArray (transitionSigStr valueTransition))).extract 0 4 = + xxxSelBytes 1 + +end Benchmarks.Xxx diff --git a/Misc/prompt.md b/Misc/prompt.md new file mode 100644 index 00000000..e470d8b3 --- /dev/null +++ b/Misc/prompt.md @@ -0,0 +1,550 @@ +# Agent prompt — proving EVM↔Solm correctness for a contract + +You are proving that a concrete EVM bytecode artifact refines its Solm +specification. You goal is to complete the proof of the top-level theorem +in `Correct.lean` with no `sorry` and no added axioms, except for the +accepted trusted base below. + +```lean + +You are given a working directory, which is named after the contract +(`/`) and includes: + +- The EVM bytecode (file `Bytecode.lean`). + +- The source it was compiled from (e.g., `.sol`), plus the exact + compiler and options used to produce it. The bytecode can be of + arbitrary provenance — do not assume a specific compiler or + version. Always check. + +- The Solm specification of the contract, including its storage + layout. (file `Spec.lean`) + +- A correctness file stating the top-level theorem with a `sorry` + placeholder. (file `Correct.lean`) + +The top-level theorem bundles the correctness of the constructor: + +```lean +constructorEquivalence +``` + +and the correctness of the runtime code: + +```lean +runtimeEquivalence +``` + +Your goal is to complete the proof. The proof must be correct, +modular, fast enough to work on, and axiom-clean except for the +accepted trusted base below. + +Be forthcoming with blocking issues. Never bypass a problem to move on +to the next proof, and never circumvent it. If you suspect something +is unprovable, investigate thoroughly, report it immediately to the +user, and do not continue until it is resolved. + +You should only work in the `/` directory. Do not make changes +outside of it. + +## 1. Overall Workflow + +### Phase 0: Evaluate the spec and bytecode + +Do a thorough read of the Solm spec and the bytecode. Check that the +Solm spec matches the bytecode's storage reads/writes, arithmetic, and +control flow. If you find a mismatch, report it immediately. After +this pass, you should be confident that the Solm spec is a faithful +model of the bytecode, and that it is possible to prove the +refinement. + +Things to watch for: + +- The Solm spec, in general, must model storage reads/writes in the + order the bytecode performs them. This is not a hard rule, for all + data types. But for mapping, array, string and byte types this is + important as otherwise you will have to introduce a slot noncollision + axiom to prove the refinement, which is not allowed. + + If you find that you need such an axiom, evaluate whether the Solm can + be written + differently to exactly model the bytecode's storage reads/writes. + If it can, rewrite the Solm spec to do so. + + Only add such axiom if the compiler has done an optimization that cannot + be reflected in the Solm spec and the proof cannot be completed without it. + +- The Solm spec must use helper functions where possible and not + inline the same logic in multiple places. This is important for + modularity and reusability of proofs. + +- The storage layout in the Solm spec must match the storage layout in + the bytecode. If there is a mismatch, report it immediately. + +### Phase 1: Scaffold the proof + +Create the top-level scaffold of the proof in `Correct.lean`. This +includes the dispatch skeleton, the per-function `…BodyCore` lemmas, +and the revert paths. The top-level theorem should type-check and +route correctly before the leaves are done. Reuse the available +machinery drivers for dispatching (e.g., `solcDispatchReachBody`). + +1. Add the dispatch handler to the main theorem first. Wire the full + dispatcher (`by_cases` on `callvalue`/`size`/each selector, routing + each selector to its per-function `…BodyCore`, plus the shared + revert paths). This skeleton should type-check and route correctly + before the leaves are done. Add the necessary ABI selector axiom + as needed. + +2. For each ABI function ``, route to a `…BodyCore` whose proof is + a `sorry`. That `…BodyCore` should be defined in that function's + own file `.lean`. + +3. Create a `…BodyCore` lemma for the constructor in + `Constructor.lean` file. + +4. The skeleton of the proof should now route every function and the + constructor correctly through the main top-level dispatch. + +*Hard rule*: You should set up the dispatch skeleton and the per ABI +function theorems (initially with `sorry`) in their own files before +proving any of the functions. + +It is likely that some of the `Examples/` proof templates will be useful +for this phase. You can use them as a reference for the ABI dispatch skeleton. + +### Phase 2: Prove each function + +Finish each function's `…BodyCore` lemma in its own `.lean` +file. If the proof gets difficult, do not try to bypass the problem +and move to another function. Investigate thoroughly and report +immediately any blocking issues you may find. + +You should tackle proofs in order of dependency: if function `f` calls +function `g`, prove `g` first, then `f`. This is true for both +internal and external calls. + +The proof of each function follows, roughly, four phases: + + +1. ABI decode. Prove decode succeeds for valid calldata and fails on + each malformed branch (short / huge / non-canonical address + lemmas). Use the `decodeCalldata_*` library lemmas + (`decodeCalldata_address_ok`, `decodeCalldata_uint256_ok`, + `…_none_short`, `…_none_huge`, `…_none_noncanon`). One `simpa … + using ` per branch (see `BalanceOf.lean`). + +2. Add trusted selector facts for the public selectors in `Trusted.lean`. + +3. Solm source body. Prove the `ExecTransitionBody` result (return + value / storage update / revert) using `Reasoning.SolmBody` + (`ExecStmt`/`ExecBlock` combinators, `evalExpr_*`, `requireStep`, + `returns`). For mutating functions, split success and revert + branches early. + +4. EVM reachability. Thread the bytecode trace from the body entry PC + to `RDret` (success) or `RDrev` (revert) using `evm_run … with [ … + ]` cooked-step chains and factored `RD.*` routine lemmas. Never + write one giant `evm_run`; split into named `have`s, one per + phase/routine. + +5. Connect. `reEquivExecution` / `reEquivDecodingFailed` / + `reEquivNoDispatch` / `reEquivElim` glue the source result, the + decode fact, and the EVM `RDret`/`RDrev` into + `runtimeEquivalenceFor`. + +--- + +### Phase 3: Prove the constructor + +In a similar manner, prove correct the constructor body. + +--- + +### Phase 4: Finish the proof + +After you have proved all the functions and the constructor, verify +that the top-level theorem complies with no added axioms and no +`sorry`/`admit`. Report the axiom footprint. + +--- + +## 2. Accepted axioms + +The only acceptable trusted facts are: + +- The selector / jump-dest facts in `Bytecode.lean` (the selector + bytes of each function). + +- Axioms that already exist in `Reasoning/`, including the + external-call axioms described in §6. + +Do not introduce new axioms about EVM semantics, Solm semantics, or +mapping-slot noncollision. If you think you need one, stop, report the +situation, and ask for guidance. + +--- + +## 3. File layout + +You should work exclusively in a directory `/` for the contract +you are proving. The file structure is the following: + +The proof of a contract `` goes in a directory `/`: + +| File | Role | +|---|---| +| `.sol` | the Solidity source + the exact compiler invocation used. | +| `Spec.lean` | the Solm `ContractDecl`, storage layout, `Config`. | +| `Bytecode.lean` | runtime bytecode + selector/jump-dest trusted facts. | +| `Common.lean` | contract-wide ABI / memory / selector / return / other helpers shared by ≥2 functions. | +| `Storage.lean` | contract-wide storage load/store + RBMap preservation + bool-return facts (only if it has storage). | +| `.lean` | one file per interface (public/external) function — its decode, source body, EVM trace, and `…BodyCore` refinement. | +| `Constructor.lean` | the equivalence proof of the contract's constructor. | +| `Correct.lean` | thin top-level: dispatcher driver + per-function routing + revert paths + constructor packaging + the final `theorem Correct`. | + + +- At least one file per external ABI function. Never put two ABI + functions' proofs in one file, never fold a function's body proof + into `Correct.lean` or `Common.lean`, and never let `Correct.lean` + carry body-specific complexity. + +- Shared machinery used by several functions goes in + `Common.lean`/`Storage.lean`/`Routines.lean`, not in any one + function's file. Internal/private functions are not ABI + entries. Their proofs can go into common files or their own + standalone files. + +- You can add further helper files in `/` for common lemmas and + helpers. + +- **Hard rule:** do not let files grow past 2000 lines. If this + happens you should split them into smaller files by concern. + This is important for build speed. + You can exceptionally create files larger that 2000 lines + ONLY IF ABSOLUTELY NECESSARY AND UNAVOIDABLE. + +--- + +## 4. Reasoning library and reuse + +`Reasoning/` is a library of abstractions, lemmas, and tactics for +proving EVM bytecode correct against its Solm spec. Useful reads: + +- `Reasoning/GUIDE.md` — the library map: where every kind of fact + lives, import layering, and the gotchas (native_decide for decode, + `RD.foo rd` not `rd.foo`, heartbeat budgets, etc.). + +- Each `Reasoning/*.lean` file's `/-! # … -/` header — per-module + detail. + +How to use the library: + +- Respect and extend the library's abstractions. Almost every line should apply a library lemma. + A reusable, contract-independent fact the library lacks is a missing library lemma. Add it + (proved) to the current working directory's `Common.lean` (or another local common file), + tagged `-- LIBRARY CANDIDATE: ` + (or `-- GENERALIZES Reasoning.. …` for a near-variant). + +- Never edit `Reasoning/` yourself + +- Do not reinvent. The library already discharges the solc prologue, + non-payable guard, calldata-size guard, selector load, + `RD.dispatchTo` selector routing, ABI decode/encode, memory/storage + round-trips, and the `RD`/`RDret`/`RDrev` stepping + discipline. Almost every line you write should be applying a library + lemma, not proving EVM semantics from scratch. Before writing any + arithmetic / calldata / memory / dispatch proof by hand, search for + an existing lemma. + +- Never duplicate lemmas and proof work. Always search `Reasoning/` + for existing lemmas before proving a new one. If you find yourself + proving the same fact in two places, refactor it into a single lemma + in a common file. + +- You should strive to build generic, modular, and reusable + infrastructure in your proofs and follow the library abstractions. + This will make your proofs more maintainable and easier to + understand. + +- After you are done with your proof, someone will evaluate it for + generality and reusability. If your lemmas are deemed general + enough, they will promote your lemmas to the `Reasoning/` library. + If they find that your lemmas are too specific, they will ask you to + refactor them into more generic lemmas that can be reused in other + proofs. + +- Lemma hygiene: + + 1. Make lemmas useful and general. The new lemmas that you add + should be as generic as possible, avoiding hard-coded PCs, + widths, types, and stack tails when possible. + + 2. Do not prove anticipated lemmas, unless you are 100% sure they + will be used in the final proof. + + 3. Before introducing a lemma, search `Reasoning/` and the existing + examples for one that already exists — do not re-prove it. + + 4. Never duplicate a lemma. If you find yourself writing the same + lemma in two places, refactor it into a single lemma in a common + file. If you find yourself proving similar lemmas in two places, + consider generalizing the lemma to make it reusable. + + 5. Add lemmas in the working directory (shared ones in common + files), then flag the contract-independent ones for promotion to + `Reasoning/` (below). Do not add lemmas directly to `Reasoning/`. + +- The library is not yet exercised by every Solidity construct. As you + prove new patterns you will find segments that are + contract-independent and reusable and can be promoted to the + library. When you do: + + 1. Make sure the theorem is not already proved in `Reasoning/`. Search first. + + 2. If your lemma is a near-miss of an existing one (same shape, + different PC/width/type/stack tail), that is a generalization + opportunity: write your version in the common file and mark it `-- + GENERALIZES Reasoning.. — lift by parameterizing + over `, so the library lemma can later be widened to + subsume both instead of accreting near-duplicates. + + 3. If it's genuinely new but contract-independent, mark it a fresh + `LIBRARY CANDIDATE`. The goal: every reusable fact ends up in + one place, tagged with where it belongs in `Reasoning/`, so + lifting it later is a mechanical move, not a hunt across function + files. + + 4. Collect all candidates in common files per example so the lift is + mechanical, not a scavenger hunt. + + 5. A lemma is library-ready only if it references no example-local + defs. Watch for per-example abbreviations (`addr`, `uint256`, + `uint256Int` are redefined in each `Spec.lean`); inline the raw + type or it won't compile in the library. + + +--- + +## 5. Examples + +The `Examples/` directory contains a set of template proofs. You can +use them as a reference for your own proof. + +Look at the examples to find known patterns and proof templates for +your proof. + +Note that not all examples are derived with the same compiler, +version, and optimization settings. Always check the source and +bytecode for your contract. + +The examples may lag behind recent Solm changes (they are migrated in +batches). If an example does not compile, use it as a *reading* +reference for trace/dispatch/proof patterns only — do not build it and +do not copy its conventions blindly. In particular, examples written +before the multi-value-return change show the old return conventions +(`returnType := some T` / `.return e`); the current convention is +lists (`returnType := [T]` / `.return [e]`, multi-value +`.return [a, b]`). + +- For an example of binary search dispatch, see `Examples/Ballot`. +- For an example of linear dispatch, see `Examples/ERC20`. + + +*Hard rule:* do not import code directly from `Examples/` into your proof. +If you find yourself needed the same lemma, prove it in your own working +directory and flag it for promotion to the library if it is general enough. + +--- + +## 6. Function Calls and loops + +Function calls should be proven modularly. In particular: + +- External calls (calls to other contracts): + + All external calls are proved correct by showing the bytecode and + the source semantics make to the same opaque Ethereum.EVM.Θ + invocation. Runtime RD lemmas produce the Θ witness; calldata/target + lemmas prove the bytecode memory slice matches the source ABI call; + then callCoincides or direct callViaEVM.callMade turns that into the + source-side call relation, with account-map transport handled by + typedCallViaEVM_accountMapEquiv or callViaEVM_accountMapEquiv. + + For static external calls, you may also use the proved fact that the + accounts storage is preserved by the call. + +- Internal calls: + + For internal calls, never inline the caller proof manually. Prove + the callee body once as an ExecFuncBody, then use + internalCallFunctionReturn or internalCallFunctionRevert to + discharge the caller’s .internalCall statement by supplying argument + evaluation, function lookup, parameter binding, and the callee body + proof. + + This is also true when a public function is also called internally + by another function of the contract. The callee body is proved once, + and the caller uses the callee’s lemma to discharge its internal + call. + + Reference: `Examples/Reuse`; larger patterns occur in Ballot and + BlindAuction. + + If a function `f` is called internally by another function `g`, + prove `f` before tackling the proof of `g`. + + +- Loops: + + The `Examples/BlindAuction` example has a big complicated loop in the + `Reveal` function and shows how to prove loops by induction: state + the invariant over the loop counter, prove a single reusable + body-step lemma, and close the loop by induction on the remaining + iterations, on both the Solm side and the bytecode trace. +--- + +## 7. Build discipline, tactics, proof engineering, efficiency + +- Every file should compile and should be validated by the build + system. + +- Builds are slow. Only recompile when necessary. Do not make + pointless recompilation attempts. + +- Quick elaboration is important. Prefer `simp only` over `simp`, and + `native_decide` over `decide`. Avoid tactics that blow up build + time. + +- Don't rebuild the world to check a leaf lemma. + +- If your proof is taking too long to compile, you should evaluate + your tactics and see if you can optimize them. You may also + consider splitting the proof into smaller lemmas to improve + compilation time. + +- Develop new lemmas in a small scratch file, not by editing the large + file in place. Heavy files take minutes to rebuild and every edit + re-elaborates the whole file. Create a throwaway + `/Scratch.lean` in your working directory that imports the real file (so its + defs/lemmas are in scope, compiled once and cached) and develop the + new lemma there with fast cycles. Once it compiles clean, move it + into its proper file and delete the scratch. + +- Decode obligations use `native_decide`, not `decide` (~20× faster on + big bytecode). `evm_run` cooked steps auto-supply it; raw steps + write `(by native_decide)` for decode, `(by decide)` for small side + conditions, `(by jump_dest)` for jump-dest membership, `(by evm_ov)` + for stack-overflow bounds. Keep these — the resulting `ofReduceBool` + axiom dependency is expected and fine. + +- Raise `maxHeartbeats` only on the file/lemma that needs it, with + `set_option … in` on that one theorem, not globally. + +--- + +## 8. Routine-lemma discipline + +Every repeated bytecode segment becomes one `RD`-combinator lemma, +proved once, applied many times: + +- A straight-line bytecode segment `pc_in → pc_out` over a stack tail + `R` becomes a theorem of the form `RD code … pc_in (args ++ R) … → ∃ + k' C', RD code … pc_out (results ++ R) …` (or `→ RDret` / `→ RDrev` + for terminal segments). See `RD.routine9c`, `RD.routinebb`, + `RD.routinecf`, `RD.erc20DecodeAddrMask`, + `RD.erc20MappingHashSuffix`, `RD.erc20RoutineEncodeUint256`. + +- These chain directly: `rd |>.routineA … |>.routineB …` (call as + `RD.foo rd …`, not `rd.foo` — the `RD` type whnf's to an + `Or`). Factor over a generic tail `R` so the lemma is reused at + every call site regardless of what else is on the stack. + +- Before writing a trace, scan the bytecode for segments solc shares + (decoders, the address mask/cleanup, the mapping-hash `keccak` + suffix, the uint256 ABI encoder, identity `cleanup_t_*` + routines). solc emits these once; prove them once. If you find + yourself writing the same `evm_run [...]` block in two functions, + stop and extract a lemma. + +- Generalize hard-coded constants (PCs, widths, types, stack tails) + into lemma parameters wherever possible, so the lemma is reusable + across functions. If a lemma is truly contract-independent, flag it + for promotion to `Reasoning/`. + +- Split traces into `have`s, one per sub-trace / routine. A single + giant `evm_run` over a compound tail blows the heartbeat/`whnf` + budget. Factoring a routine over a generic tail `R` needs + `set_option maxHeartbeats 1000000 in` and intermediate `have`s — see + the note in `Reasoning/GUIDE.md` and `RD.erc20DecodeAddrMask`. + +Disassemble — never guess PCs, opcodes, or jump-dests. The biggest +failure mode in these proofs is guessing contract-specific constants: +the exact `evm_run … with [push2 ⟨71⟩, dup1, …]` opcode sequence for a +basic block, the entry/exit PCs, the jump-dest set, the selector +bytes, the stack shapes. These are a pure function of the bytecode — +one wrong token fails late and opaquely and wastes a whole cycle. Read +them off the actual bytecode: disassemble `Bytecode.lean` (a short +script, `evmasm`/`solc --asm`, or by decoding the byte array) to get +each block's exact cooked-step list, its PCs, and the jump-dest array +before writing the trace. Treat the trace as "fill in the +side-conditions of a known opcode list," not "invent the opcode list." +When a step fails, re-check it against the disassembly first. + +--- + +## 9. Hard rules + +- Do not make changes outside of your working directory. + +- Do not build examples and benchmarks that are not your own. + **This is extremely important**. Builds are extremely expensive and time-consuming. + Only build your own working directory. + +- If you find misspecifications, mismatches, or unprovable + obligations, stop and report them immediately. Do not continue until + they are resolved. + +- Edit `Spec.lean` only if you are certain it is wrong, and report the + change immediately. Do not change the given bytecode or Solidity + source. + +- Never edit `Bytecode.lean`. If you suspect it is wrong, report it + immediately. + +- No `sorry` in the finished proof. + +- Do not introduce new `axiom`, unless explicitly told to do so. If + you think you need one, stop, report the situation, and ask for + guidance. + +--- + +## 10. Finish checklist + +Run, and report results verbatim: + +``` +lake build .Correct +rg -n '\b(sorry|admit)\b' +printf '%s\n' 'import .Correct' '#print axioms .Correct' | lake env lean --stdin +``` + +where `` is your working directory, `` its Lean module +path, and `` the contract's namespace — e.g. for +`Examples/ERC20/`: `Examples.ERC20`; for `Benchmarks/Dss/Dai/`: +`Benchmarks.Dss.Dai`. + +The build must succeed with no `sorry`. + +The axiom footprint should contain only +`propext`/`Classical.choice`/`Quot.sound`, the expected `ofReduceBool` +(from `native_decide`), the pre-existing library axiom +`ByteArray_zeroes_size`, your contract's selector/jump-dest facts, and +— for any contract with an external call — the tolerated external-call +axiom `Reasoning.Reach.Theta_returnData_size_lt_2pow138` (a known +trusted base being removed separately; do not block on it). +(`typedCallViaEVM_accountMapEquiv` is a proved theorem in +`Reasoning/ExternalCall.lean`, not an axiom — it does not appear in the +footprint.) Flag only anything beyond this set — a new axiom your work +introduced. From 05be81921f3c908e4a5ff8ea04d622809327ff7d Mon Sep 17 00:00:00 2001 From: zoep Date: Tue, 28 Jul 2026 23:07:15 +0300 Subject: [PATCH 21/38] Reasoning: cleanup --- Benchmarks/Dss/Cure/Common.lean | 1 - Benchmarks/Dss/Dai/Common.lean | 1 - Benchmarks/Dss/DaiJoin/Common.lean | 1 - Benchmarks/Dss/Dog/Common.lean | 1 - Benchmarks/Dss/End/Common.lean | 1 - .../Dss/ExponentialDecrease/Common.lean | 1 - Benchmarks/Dss/Flapper/Common.lean | 1 - Benchmarks/Dss/Flipper/Common.lean | 1 - Benchmarks/Dss/Flopper/Common.lean | 1 - Benchmarks/Dss/GemJoin/Common.lean | 1 - Benchmarks/Dss/Jug/Common.lean | 1 - Benchmarks/Dss/LinearDecrease/Common.lean | 1 - Benchmarks/Dss/Pot/Common.lean | 1 - Benchmarks/Dss/Spot/Common.lean | 1 - .../StairstepExponentialDecrease/Common.lean | 1 - Benchmarks/Dss/Vat/Common.lean | 1 - Benchmarks/ERC721/Correct.lean | 1 - .../TimelockController/Common.lean | 1 - Benchmarks/WETH9/Common.lean | 1 - EquiVM.lean | 1 - Examples/Ballot/Constructor.lean | 2 +- Examples/Ballot/Correct.lean | 1 - Examples/Caller/Correct.lean | 1 - Examples/CtorStore/Correct.lean | 1 - Examples/CtorTruth/Correct.lean | 1 - Examples/ERC20/Correct.lean | 1 - Examples/Pow/Correct.lean | 1 - Examples/StringStoreLite/Getters.lean | 1 - Examples/Truth/Correct.lean | 1 - Examples/VyperERC20/Correct.lean | 2 +- Misc/Template/Common.lean | 1 - Misc/Template/README.md | 23 +- README.md | 82 +++-- Reasoning/Dispatch.lean | 2 +- Reasoning/EVMWord.lean | 8 +- Reasoning/Initcode.lean | 1 + Reasoning/Reach.lean | 98 ++++++ Reasoning/SolmBody.lean | 3 +- Reasoning/Stepping.lean | 174 ++++++++++- Reasoning/Theory.lean | 280 ------------------ 40 files changed, 348 insertions(+), 356 deletions(-) delete mode 100644 Reasoning/Theory.lean diff --git a/Benchmarks/Dss/Cure/Common.lean b/Benchmarks/Dss/Cure/Common.lean index f2b85d65..6bf4fc50 100644 --- a/Benchmarks/Dss/Cure/Common.lean +++ b/Benchmarks/Dss/Cure/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.Cure.Trusted import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/Dai/Common.lean b/Benchmarks/Dss/Dai/Common.lean index ca4629ef..4989b031 100644 --- a/Benchmarks/Dss/Dai/Common.lean +++ b/Benchmarks/Dss/Dai/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.Dai.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/DaiJoin/Common.lean b/Benchmarks/Dss/DaiJoin/Common.lean index 4f40817f..c82bd91a 100644 --- a/Benchmarks/Dss/DaiJoin/Common.lean +++ b/Benchmarks/Dss/DaiJoin/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.DaiJoin.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/Dog/Common.lean b/Benchmarks/Dss/Dog/Common.lean index 6cae16e0..3b15f498 100644 --- a/Benchmarks/Dss/Dog/Common.lean +++ b/Benchmarks/Dss/Dog/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.Dog.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/End/Common.lean b/Benchmarks/Dss/End/Common.lean index 4cfe0b5d..39e03344 100644 --- a/Benchmarks/Dss/End/Common.lean +++ b/Benchmarks/Dss/End/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.End.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/ExponentialDecrease/Common.lean b/Benchmarks/Dss/ExponentialDecrease/Common.lean index 80b9928a..345167e9 100644 --- a/Benchmarks/Dss/ExponentialDecrease/Common.lean +++ b/Benchmarks/Dss/ExponentialDecrease/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.ExponentialDecrease.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/Flapper/Common.lean b/Benchmarks/Dss/Flapper/Common.lean index ebe8ee3e..f893107c 100644 --- a/Benchmarks/Dss/Flapper/Common.lean +++ b/Benchmarks/Dss/Flapper/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.Flapper.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/Flipper/Common.lean b/Benchmarks/Dss/Flipper/Common.lean index 1bcf1974..7f2fbeeb 100644 --- a/Benchmarks/Dss/Flipper/Common.lean +++ b/Benchmarks/Dss/Flipper/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.Flipper.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/Flopper/Common.lean b/Benchmarks/Dss/Flopper/Common.lean index bafdc417..0fd3ac02 100644 --- a/Benchmarks/Dss/Flopper/Common.lean +++ b/Benchmarks/Dss/Flopper/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.Flopper.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/GemJoin/Common.lean b/Benchmarks/Dss/GemJoin/Common.lean index e13a7157..a19e6348 100644 --- a/Benchmarks/Dss/GemJoin/Common.lean +++ b/Benchmarks/Dss/GemJoin/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.GemJoin.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/Jug/Common.lean b/Benchmarks/Dss/Jug/Common.lean index 715a3894..6e45827a 100644 --- a/Benchmarks/Dss/Jug/Common.lean +++ b/Benchmarks/Dss/Jug/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.Jug.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/LinearDecrease/Common.lean b/Benchmarks/Dss/LinearDecrease/Common.lean index 91844d2e..11acc7a8 100644 --- a/Benchmarks/Dss/LinearDecrease/Common.lean +++ b/Benchmarks/Dss/LinearDecrease/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.LinearDecrease.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/Pot/Common.lean b/Benchmarks/Dss/Pot/Common.lean index acd02e14..5d40ebbc 100644 --- a/Benchmarks/Dss/Pot/Common.lean +++ b/Benchmarks/Dss/Pot/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.Pot.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/Spot/Common.lean b/Benchmarks/Dss/Spot/Common.lean index fdde94f6..b15d369b 100644 --- a/Benchmarks/Dss/Spot/Common.lean +++ b/Benchmarks/Dss/Spot/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.Spot.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/StairstepExponentialDecrease/Common.lean b/Benchmarks/Dss/StairstepExponentialDecrease/Common.lean index c3f13290..ae119c26 100644 --- a/Benchmarks/Dss/StairstepExponentialDecrease/Common.lean +++ b/Benchmarks/Dss/StairstepExponentialDecrease/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Dss.StairstepExponentialDecrease.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/Dss/Vat/Common.lean b/Benchmarks/Dss/Vat/Common.lean index 69f26dbd..0cadba22 100644 --- a/Benchmarks/Dss/Vat/Common.lean +++ b/Benchmarks/Dss/Vat/Common.lean @@ -6,7 +6,6 @@ import Reasoning.SolmBody import Reasoning.Solc import Reasoning.Stepping import Reasoning.Storage -import Reasoning.Theory import Mathlib.Tactic.IntervalCases /-! diff --git a/Benchmarks/ERC721/Correct.lean b/Benchmarks/ERC721/Correct.lean index c3d3de2f..1e410d92 100644 --- a/Benchmarks/ERC721/Correct.lean +++ b/Benchmarks/ERC721/Correct.lean @@ -2,7 +2,6 @@ import Benchmarks.ERC721.Bytecode import Benchmarks.ERC721.Constructor import Benchmarks.ERC721.Spec import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Common.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Common.lean index f599eb87..b21edac9 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Common.lean +++ b/Benchmarks/OpenZeppelinBench/TimelockController/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.OpenZeppelinBench.TimelockController.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Benchmarks/WETH9/Common.lean b/Benchmarks/WETH9/Common.lean index 0ca7ac32..f45fe9b9 100644 --- a/Benchmarks/WETH9/Common.lean +++ b/Benchmarks/WETH9/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.WETH9.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/EquiVM.lean b/EquiVM.lean index c0229a15..630f13df 100644 --- a/EquiVM.lean +++ b/EquiVM.lean @@ -13,4 +13,3 @@ import Reasoning.Solc import Reasoning.SolmBody import Reasoning.Stepping import Reasoning.Storage -import Reasoning.Theory diff --git a/Examples/Ballot/Constructor.lean b/Examples/Ballot/Constructor.lean index 277b3c76..95a937df 100644 --- a/Examples/Ballot/Constructor.lean +++ b/Examples/Ballot/Constructor.lean @@ -7,7 +7,7 @@ import Reasoning.Reach import Reasoning.Memory import Reasoning.Solc import Reasoning.SolmBody -import Reasoning.Theory +import Reasoning.Dispatch import Reasoning.JumpDest /-! diff --git a/Examples/Ballot/Correct.lean b/Examples/Ballot/Correct.lean index 88273ff1..49478ede 100644 --- a/Examples/Ballot/Correct.lean +++ b/Examples/Ballot/Correct.lean @@ -9,7 +9,6 @@ import Examples.Ballot.WinningProposal import Examples.Ballot.WinnerName import Examples.Ballot.DelegateComplete import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Examples/Caller/Correct.lean b/Examples/Caller/Correct.lean index 657434d4..b2cccfdb 100644 --- a/Examples/Caller/Correct.lean +++ b/Examples/Caller/Correct.lean @@ -2,7 +2,6 @@ import Examples.Caller.Bytecode import Examples.Caller.Spec import Reasoning.ABI import Reasoning.EVMWord -import Reasoning.Theory import Reasoning.Dispatch import Reasoning.SolmBody import Reasoning.Stepping diff --git a/Examples/CtorStore/Correct.lean b/Examples/CtorStore/Correct.lean index 02270b71..04e8bbde 100644 --- a/Examples/CtorStore/Correct.lean +++ b/Examples/CtorStore/Correct.lean @@ -1,7 +1,6 @@ import Examples.CtorStore.Bytecode import Reasoning.Memory import Reasoning.Solc -import Reasoning.Theory import Reasoning.Dispatch import Reasoning.SolmBody import Reasoning.Reach diff --git a/Examples/CtorTruth/Correct.lean b/Examples/CtorTruth/Correct.lean index 7e295db7..f5a53adc 100644 --- a/Examples/CtorTruth/Correct.lean +++ b/Examples/CtorTruth/Correct.lean @@ -2,7 +2,6 @@ import Examples.CtorTruth.Bytecode import Examples.Truth.Correct import Reasoning.Memory import Reasoning.Solc -import Reasoning.Theory import Reasoning.Dispatch import Reasoning.SolmBody import Reasoning.Reach diff --git a/Examples/ERC20/Correct.lean b/Examples/ERC20/Correct.lean index b82603fb..fcf4b444 100644 --- a/Examples/ERC20/Correct.lean +++ b/Examples/ERC20/Correct.lean @@ -7,7 +7,6 @@ import Examples.ERC20.Approve import Examples.ERC20.Transfer import Examples.ERC20.TransferFrom import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Examples/Pow/Correct.lean b/Examples/Pow/Correct.lean index 1f890317..a292ddb0 100644 --- a/Examples/Pow/Correct.lean +++ b/Examples/Pow/Correct.lean @@ -2,7 +2,6 @@ import Examples.Pow.Bytecode import Examples.Pow.Spec import Reasoning.ABI import Reasoning.EVMWord -import Reasoning.Theory import Reasoning.Dispatch import Reasoning.SolmBody import Reasoning.Stepping diff --git a/Examples/StringStoreLite/Getters.lean b/Examples/StringStoreLite/Getters.lean index 0df311c6..1e8778df 100644 --- a/Examples/StringStoreLite/Getters.lean +++ b/Examples/StringStoreLite/Getters.lean @@ -7,7 +7,6 @@ import Reasoning.Reach import Reasoning.SolmBody import Reasoning.Solc import Reasoning.Storage -import Reasoning.Theory import Mathlib.Tactic.IntervalCases /-! diff --git a/Examples/Truth/Correct.lean b/Examples/Truth/Correct.lean index 0cf2ecb4..83b1c6b0 100644 --- a/Examples/Truth/Correct.lean +++ b/Examples/Truth/Correct.lean @@ -2,7 +2,6 @@ import Examples.Truth.Bytecode import Examples.Truth.Spec import Examples.CtorTruth.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Dispatch import Reasoning.SolmBody import Reasoning.Stepping diff --git a/Examples/VyperERC20/Correct.lean b/Examples/VyperERC20/Correct.lean index aef99613..47617e46 100644 --- a/Examples/VyperERC20/Correct.lean +++ b/Examples/VyperERC20/Correct.lean @@ -8,7 +8,7 @@ import Examples.VyperERC20.Transfer import Examples.VyperERC20.TransferFromRuntime import Solm.Equiv import Reasoning.ABI -import Reasoning.Theory +import Reasoning.Dispatch import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Misc/Template/Common.lean b/Misc/Template/Common.lean index 93bbd31c..5c718610 100644 --- a/Misc/Template/Common.lean +++ b/Misc/Template/Common.lean @@ -1,6 +1,5 @@ import Benchmarks.Xxx.Bytecode import Reasoning.ABI -import Reasoning.Theory import Reasoning.Stepping import Reasoning.Reach import Reasoning.Solc diff --git a/Misc/Template/README.md b/Misc/Template/README.md index 1fb2cf3b..50a1e972 100644 --- a/Misc/Template/README.md +++ b/Misc/Template/README.md @@ -8,7 +8,7 @@ The division of labor is deliberate: **the user provides the compiled artifacts and the surface specification (`SpecSyntax.lean`) — the boilerplate and the proof are the job of the LLM agent**, driven by the prompt in `Misc/prompt.md`. -Proven end-to-end exemplars: `Benchmarks/Dss/Pot` (this template's source), +Proven end-to-end examples: `Benchmarks/Dss/Pot` (this template's source), `Benchmarks/Dss/Jug`, `Benchmarks/Dss/Cat`, `Benchmarks/WETH9`, `Examples/Ballot`. ## Directory layout @@ -60,21 +60,6 @@ that is `SpecSyntax.lean` — `Spec.lean` only references it. the constructor in their own files, and closes the top-level theorems — `sorry`-free and axiom-clean up to the accepted trusted base (selector and jump-dest facts, plus the tolerated `Reasoning/` axioms). -4. **Acceptance** (user). `lake build .Correct` succeeds, no - `sorry`/`admit` in the directory, and `#print axioms` on the capstone shows - only the accepted set (see the finish checklist in `Misc/prompt.md`). - -## Conventions - -- Namespaces `Examples.` / `Benchmarks.[.]`; the surface file - uses `.Syntax` with `contractSyntax`. -- Transitions in selector (dispatch) order everywhere: surface file, derived - handles, selector table. -- Solidity names that are Lean keywords are guillemet-escaped in the surface - syntax: «from», «to», «end», … -- The non-payable guard is implicit in the surface syntax; `payable` marks the - entry points whose compiled body has no callvalue check. -- Parameterized contracts thread the immutable valuation `v` through - `contractSyntax`, `contract`, and the theorems. If a large parameterized - `rfl` ever times out, `simp only [, List.cons_append, - List.nil_append]; rfl` closes it (cf. `Benchmarks/Dss/Dog/SpecSyntax.lean`). +4. **Acceptance**. `lake build .Correct` succeeds, no `sorry`/`admit` in + the directory, and `#print axioms` on the capstone shows only the accepted + set (see the finish checklist in `Misc/prompt.md`). diff --git a/README.md b/README.md index 2ccb69c7..171cc8d5 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,14 @@ EquiVM is a framework that allows proving that a piece of EVM bytecode *refines* a high-level program, written in a specification language called Sol⁻ -(pronounced Sol minor). This specification provides a human-readable, formal source-language agnostic view of the bytecode and it can serve in further verification of the contract's behavior -or in human audits. +(pronounced Sol minor). This specification provides a human-readable, formal, +source-language agnostic view of the bytecode. It can serve in further +verification of the contract's behavior or in human audits. -Refinement proofs are intended to be generated by autonomous LLM agents. We are currently evaluating the capabilities of LLMs to provide such refinement proofs -autonomously and their cost (section `Examples/` and `Benchmarks/` directories). The framework has been -designed with this goal in mind. +Refinement proofs are intended to be generated by autonomous LLM agents. We are +currently evaluating the capabilities of LLMs to provide such refinement proofs +autonomously and their cost (see the `Examples/` and `Benchmarks/` directories). +The framework has been designed with this goal in mind. ## Sol⁻ Sol⁻ is a small imperative language, inspired by Solidity and designed to be @@ -18,8 +20,28 @@ can be certified equivalent to it. Sol⁻ is parametric in the contract's storag layout, so one can describe bytecode generated by different compilers (or no compiler at all). +Sol⁻ specifications are written in Lean with a Solidity-like surface syntax +(`solidity%`, defined in [`Solm/Notation.lean`](Solm/Notation.lean)); every +contract under `Examples/` and `Benchmarks/` carries one in its +`SpecSyntax.lean`. From the ERC20 example: + +```lean +function transfer(address «to», uint256 value) external returns (bool) { + uint256 fromBalance = balanceOf[msg.sender]; + require(fromBalance >= value); + balanceOf[msg.sender] = fromBalance - value; + uint256 toBalance = balanceOf[«to»]; + uint256 newToBalance = (toBalance + value) as uint256; + balanceOf[«to»] = newToBalance; + return true; +} +``` + +(«to» escapes a Lean keyword; `as uint256` is the checked-arithmetic range +assertion.) + EquiVM provides the tools for stating and proving that the bytecode implements -the Sol⁻ specification. This includes semantics for the EVM, semantics rules for +the Sol⁻ specification. This includes semantics for the EVM, semantic rules for Sol⁻, the formal specification of the ABI, and the refinement relation between Sol⁻ and EVM. Furthermore, EquiVM provides a library of compositional lemmas and tactics to help with the proofs. @@ -30,7 +52,18 @@ The top-level *refinement* states that the bytecode faithfully implements the se Once refinement is established, one can reason about the bytecode at the Sol⁻ level. This alleviates the need to both reason about low-level EVM bytecode and -to trust the compiler that produced it. +to trust the compiler that produced it. + +For a contract ``, the certificate is the capstone theorem of its +`Correct.lean`: + +```lean +theorem ContractCorrect : + contractEquivalence config creationBytecode runtimeBytecode contract +``` + +which bundles the constructor equivalence (creation code) with the runtime +equivalence (deployed code). ## Architecture @@ -54,10 +87,12 @@ to trust the compiler that produced it. Larger case studies of real contracts that were proved correct by LLMs. The file [`Benchmarks/README.md`](Benchmarks/README.md) is the per-contract status index. - **Miscellaneous** ([`Misc/`](Misc/)) - Miscellaneous files, including a template for new contracts and a prompt for LLMs. + Miscellaneous files, including the contract template ([`Misc/Template/`](Misc/Template/)) + and the agent prompt ([`Misc/prompt.md`](Misc/prompt.md)). - **Proofs** ([`Proofs/`](Proofs/)) - Proof-of-concept high-level proof on Sol⁻ specifications. + Proof-of-concept high-level proofs on Sol⁻ specifications, e.g. the inductive + ERC20 invariant that the total supply equals the sum of all balances. ## Building @@ -67,20 +102,21 @@ Install the toolchain pinned in [`lean-toolchain`](lean-toolchain) (easiest via ```sh lake exe cache get # prebuilt Mathlib cache lake build # core library -lake build Examples Benchmarks # the proof developments +lake build Examples Benchmarks # the proof developments (large: expect a long build) ``` ## Proving a contract correct To prove a new contract correct, create a new directory following the template -in `Misc/ContractTemplate/`. The prompt in `Misc/Prompt.md` is the recommended -way to instruct the LLM to produce a refinement proof. +in [`Misc/Template/`](Misc/Template/): the user provides the compiled artifacts +and the Sol⁻ specification (`SpecSyntax.lean`); the boilerplate and the proof +are the job of the LLM agent, instructed with the prompt in +[`Misc/prompt.md`](Misc/prompt.md). The Sol⁻ specification is typically pretty close to the Solidity source, but it -is not a translation of it. - -LLMs can also be used to automate the Sol⁻ specification generation, or audit -semantic faithfulness before attempting a proof. +is not a translation of it. LLMs can also be used to draft the Sol⁻ +specification, or to audit its semantic faithfulness against the bytecode +before attempting a proof. ## Trusted computing base @@ -90,9 +126,17 @@ Lean kernel and standard library axioms; that the EVM model faithfully formalizes the EVM (backed by the official EVM test suite); that the refinement relation captures the intended equivalence (it deliberately does not compare gas, substate, events, or revert payloads); a handful of per-contract Keccak -selector facts, since Keccak is an opaque foreign constant; and Lean's compiled -evaluator via `native_decide`. The proof-producing agent, tactics, and macros -are not trusted — the kernel re-checks every proof term. +selector facts, since Keccak is an opaque foreign constant; a short list of +library axioms enumerated in [`Misc/prompt.md`](Misc/prompt.md) (notably a +`ByteArray` size fact and, for contracts with external calls, a returndata-size +bound); and Lean's compiled evaluator via `native_decide`. The Sol⁻ +specification and its declared storage layout are part of the theorem +statement: auditing the claim means reading them. The proof-producing agent, +tactics, and macros are not trusted — the kernel re-checks every proof term. + +To check a certificate: `lake build .Correct`, then +`#print axioms .ContractCorrect` and compare the footprint +against the accepted set above. ## Note on AI use diff --git a/Reasoning/Dispatch.lean b/Reasoning/Dispatch.lean index 31e7d418..0b94ec5d 100644 --- a/Reasoning/Dispatch.lean +++ b/Reasoning/Dispatch.lean @@ -1,4 +1,4 @@ -import Solm.Semantics +import Solm.Equiv import Reasoning.Reach import Reasoning.Storage diff --git a/Reasoning/EVMWord.lean b/Reasoning/EVMWord.lean index 62148eb1..cf536da8 100644 --- a/Reasoning/EVMWord.lean +++ b/Reasoning/EVMWord.lean @@ -1,4 +1,4 @@ -import Reasoning.Theory +import Ethereum.Semantics import Mathlib.Data.Nat.Bitwise import Mathlib.Data.Nat.Digits.Defs import Mathlib.Data.Nat.Digits.Lemmas @@ -19,6 +19,12 @@ namespace Reasoning.Theory /-! ## Word reconstruction and no-wrap arithmetic -/ +/-- A `UInt256` with `toNat = 0` is `⟨0⟩`. (Used to discharge `callvalue = 0` tests.) -/ +theorem uint256_toNat_eq_zero {a : UInt256} (h : a.toNat = 0) : a = ⟨0⟩ := by + obtain ⟨⟨v, hlt⟩⟩ := a + simp only [UInt256.toNat] at h + subst h; rfl + /-- `AccountAddress.ofUInt256` is the same address as taking the word's natural value. -/ theorem accountAddress_ofUInt256_eq_ofNat_toNat (w : UInt256) : AccountAddress.ofUInt256 w = AccountAddress.ofNat w.toNat := by diff --git a/Reasoning/Initcode.lean b/Reasoning/Initcode.lean index 002f42d6..9191decb 100644 --- a/Reasoning/Initcode.lean +++ b/Reasoning/Initcode.lean @@ -1,4 +1,5 @@ import Ethereum.Semantics +import EVM.Types import Reasoning.EVMWord /-! diff --git a/Reasoning/Reach.lean b/Reasoning/Reach.lean index 3667b66c..146546d0 100644 --- a/Reasoning/Reach.lean +++ b/Reasoning/Reach.lean @@ -26,6 +26,11 @@ Built on `Reasoning.Theory` ordinary Lean and composes by `RD` transitivity at the call site. -/ + +/- + +TODO: remove redundant arguments from `RD` and pack remaining as `cursor`. +-/ open Solm ABI Ethereum Ethereum.EVM namespace Reasoning.Reach @@ -3574,6 +3579,99 @@ theorem RD.rev {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} · exact Or.inl (RD.terminalOOG hgas st hk hC gg hX) · exact Or.inr ⟨_, _, hX.trans (stepHaltRevert hgas st hk (by omega))⟩ +end Reasoning.Reach + +namespace Reasoning.Theory + +/-! ## Coverage helpers — build a `runtimeEquivalenceFor` case from a `Ξ` outcome -/ + +/-- `Ξ` runs out of gas ⇒ the `outOfGas` case. -/ +theorem reEquiv_outOfGas {cfg contract cA gh bl σ_evm σ_solm σ₀ g A I} + (h : Ξ cA gh bl σ_evm σ₀ g A I = .error .OutOfGass) : + runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g A I := + .outOfGas h + +/-- When a contract has no `receive`/`fallback`, a successful `dispatchMsg` is a successful + selector dispatch: the receive and fallback arms of `dispatchMsg` are `none`. Shared by the + `decodingFailed`/`execution` coverage helpers below. -/ +theorem selectorDispatchMsg_eq_some_of_dispatchMsg_eq_some + {contract : ContractDecl} {calldata : ByteArray} {transition : TransitionDecl} + (hreceive : contract.receive = none) + (hfallback : contract.fallback = none) + (h : dispatchMsg contract calldata = some transition) : + selectorDispatchMsg contract calldata = some transition := by + unfold dispatchMsg at h + cases hsel : selectorDispatchMsg contract calldata with + | none => + have hreceiveDispatch : receiveDispatchMsg contract calldata = none := by + simp [receiveDispatchMsg, hreceive] + rw [hsel, hreceiveDispatch, hfallback] at h + simp at h + | some selected => + rw [hsel] at h + simpa using h + +/-- Solm fails to dispatch and `Ξ` reverts ⇒ the `noDispatch` case. The Solm-side maps are + unconstrained — this path never runs `solmExec`. -/ +theorem reEquiv_noDispatch {cfg contract cA gh bl σ_evm σ_solm σ₀ g A I} {g' o} + (hd : dispatchMsg contract I.calldata = none) + (h : Ξ cA gh bl σ_evm σ₀ g A I = .ok (.revert g' o)) : + runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g A I := + .noDispatch hd h + +/-- Solm dispatches but decoding fails and `Ξ` reverts ⇒ `decodingFailed`. Solm-side maps + unconstrained. -/ +theorem reEquiv_decodingFailed + {cfg contract cA gh bl σ_evm σ_solm σ₀ g A I} {t g' o} + (hd : dispatchMsg contract I.calldata = some t) + (hdec : decodeCalldataWithMode cfg.abiDecodeMode (t.params.map Param.name) + (transitionSignature t).paramTypes I.calldata = none) + (h : Ξ cA gh bl σ_evm σ₀ g A I = .ok (.revert g' o)) + (hfallback : contract.fallback = none := by rfl) + (hreceive : contract.receive = none := by rfl) : + runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g A I := + .decodingFailed (selectorDispatchMsg_eq_some_of_dispatchMsg_eq_some hreceive hfallback hd) + rfl hdec h + +/-- The Solm transition executes (to `actRes`) and `Ξ`'s result matches ⇒ the `execution` case. + The EVM runs from `σ_evm`, the Solm body from `σ_solm` (genuinely distinct maps); `hequiv` + carries the up-to-`accountMapEquiv` coupling of their results. -/ +theorem reEquiv_execution + {cfg contract cA gh bl σ_evm σ_solm σ₀ A I} {t callargs actRes} + {g : UInt256} + (hd : dispatchMsg contract I.calldata = some t) + (hdec : decodeCalldataWithMode cfg.abiDecodeMode (t.params.map Param.name) + (transitionSignature t).paramTypes I.calldata = some callargs) + (hbody : ExecTransitionBody cfg contract + (initState cA gh bl σ_solm σ₀ (.ofUInt256 g) A I) callargs t.body actRes) + (hequiv : execResultsEquiv (Ξ cA gh bl σ_evm σ₀ g A I) actRes (.abi t.returnType)) + (hfallback : contract.fallback = none := by rfl) + (hreceive : contract.receive = none := by rfl) : + runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g A I := + .execution rfl + (.intro (selectorDispatchMsg_eq_some_of_dispatchMsg_eq_some hreceive hfallback hd) + rfl hdec rfl hbody) + hequiv + +/-- The receive transition executes without selector ABI decoding and `Ξ`'s result matches. -/ +theorem reEquiv_receiveExecution + {cfg contract cA gh bl σ_evm σ_solm σ₀ A I} {t actRes} + {g : UInt256} + (hreceive : receiveDispatchMsg contract I.calldata = some t) + (hparams : t.params = []) + (hreturn : t.returnType = []) + (hbody : ExecTransitionBody cfg contract + (initState cA gh bl σ_solm σ₀ (.ofUInt256 g) A I) ∅ t.body actRes) + (hequiv : execResultsEquiv (Ξ cA gh bl σ_evm σ₀ g A I) actRes (.abi [])) : + runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g A I := + .execution rfl (.receive hreceive hparams hreturn rfl hbody) hequiv + +end Reasoning.Theory + +namespace Reasoning.Reach + +open Reasoning.Theory + /-! ## From RD terminals to Solm runtime-equivalence `RDret`/`RDrev` record that the *whole* run `X (g+1) … (initState …)` halts. These diff --git a/Reasoning/SolmBody.lean b/Reasoning/SolmBody.lean index c53984fb..b06a41bd 100644 --- a/Reasoning/SolmBody.lean +++ b/Reasoning/SolmBody.lean @@ -1,4 +1,5 @@ -import Reasoning.Theory +import Solm.Equiv +import Reasoning.EVMWord /-! # SolmBody — compositional lemmas for the Solm contract body diff --git a/Reasoning/Stepping.lean b/Reasoning/Stepping.lean index 7c11cd9b..099d3014 100644 --- a/Reasoning/Stepping.lean +++ b/Reasoning/Stepping.lean @@ -1,14 +1,22 @@ -import Reasoning.Theory +import Solm.Equiv +import Ethereum.Theory.ProgressLemmas +import Ethereum.Theory.OpcodeLemmas /-! -# Stepping — reusable per-opcode `Xstep` wrappers +# Stepping — the symbolic-execution base layer -For each opcode used by a trace we give: +Two pieces: + +**Trace drivers.** `initState` (the fresh EVM state `Ξ` builds), the `Ξ`-to-iterator bridge +(`Xi_*_of_X`), and single-step peeling (`X_peel`, `stepContinue`, `stepOOG`, `stepHalt*`) — +together they let a concrete bytecode trace be run for a universally quantified gas. + +**Per-opcode `Xstep` wrappers.** For each opcode used by a trace we give: * a **successor-state** `def st` matching the `Ethereum.Theory.OpcodeLemmas` `step_*` output (so the successor is *named* and its fields project cleanly), and * an `_xstep` lemma putting `Xstep` into the single-guard shape `if gas < cost then OutOfGass else .ok (st …, ctrl)` - that `Reasoning.Theory.stepContinue`/`stepOOG`/`stepHalt*` consume. + that `stepContinue`/`stepOOG`/`stepHalt*` consume. These are **contract-agnostic** (parameterised by the code `ByteArray`); only the `decode` facts fed to them are contract-specific. @@ -18,6 +26,164 @@ open Solm ABI Ethereum Ethereum.EVM namespace Reasoning.Theory +/-! ## The initial EVM state -/ + +/-- The fresh EVM state `Ξ` constructs from the transaction inputs. Defined to be + **definitionally** the `freshEvmState` inside `Ethereum.EVM.Ξ` and the `evmState` + inside `actExec`, so both can be rewritten to mention this single name. -/ +def initState + (createdAccounts : Batteries.RBSet AccountAddress compare) + (genesisBlockHeader : BlockHeader) (blocks : ProcessedBlocks) + (σ σ₀ : AccountMap) (g : Sat256) (A : Substate) (I : ExecutionEnv) : State := + { (default : State) with + accountMap := σ + σ₀ := σ₀ + executionEnv := I + substate := A + createdAccounts := createdAccounts + machineState.gasAvailable := g + blocks := blocks + genesisBlockHeader := genesisBlockHeader } + +/-! ## From `Ξ` to the fuelled iterator `X` -/ + +/-- If the fuelled iterator errors, so does `Ξ`. -/ +theorem Xi_error_of_X + {createdAccounts genesisBlockHeader blocks σ σ₀ A I} {e} {g : UInt256} + (h : X (g.toNat + 1) (D_J I.code 0) + (initState createdAccounts genesisBlockHeader blocks σ σ₀ (.ofUInt256 g) A I) = .error e) : + Ξ createdAccounts genesisBlockHeader blocks σ σ₀ g A I = .error e := by + unfold Ξ + simp only [initState, Sat256.ofUInt256] at h + simp [bind, Except.bind, Sat256.ofUInt256, h] + +/-- If the fuelled iterator reverts, so does `Ξ` (same gas/output). -/ +theorem Xi_revert_of_X + {createdAccounts genesisBlockHeader blocks σ σ₀ A I} {g' o} {g : UInt256} + (h : X (g.toNat + 1) (D_J I.code 0) + (initState createdAccounts genesisBlockHeader blocks σ σ₀ (.ofUInt256 g) A I) + = .ok (.revert g' o)) : + Ξ createdAccounts genesisBlockHeader blocks σ σ₀ g A I = .ok (.revert g' o) := by + unfold Ξ + simp only [initState, Sat256.ofUInt256] at h + simp [bind, Except.bind, Sat256.ofUInt256, h] + +/-- If the fuelled iterator succeeds (halts), so does `Ξ`, projecting the relevant + fields of the final machine state. -/ +theorem Xi_success_of_X + {createdAccounts genesisBlockHeader blocks σ σ₀ A I} {s' o} {g : UInt256} + (h : X (g.toNat + 1) (D_J I.code 0) + (initState createdAccounts genesisBlockHeader blocks σ σ₀ (.ofUInt256 g) A I) + = .ok (.success s' o)) : + Ξ createdAccounts genesisBlockHeader blocks σ σ₀ g A I + = .ok (.success (s'.createdAccounts, s'.accountMap, s'.machineState.gasAvailable.toUInt256, + s'.substate) o) := by + unfold Ξ + simp only [initState] at h + simp [bind, Except.bind, h] + +/-- Charging a (small, non-wrapping) gas cost decrements `toNat` by that cost. The + side condition `c ≤ g.toNat` rules out the modular wrap. -/ +theorem toNat_sub_ofNat {g : Sat256} {c : ℕ} (hc : c ≤ g.toNat) : + (g.subNat c).toNat = g.toNat - c := by + have hsize : c < UInt256.size := lt_of_le_of_lt hc g.isLt + have hofnat : (UInt256.ofNat c).val.val = c := by + simp [UInt256.ofNat, Id.run, Fin.ofNat, Nat.mod_eq_of_lt hsize] + have hle : (UInt256.ofNat c).val ≤ g.val := by + rw [hofnat]; exact hc + show (g.subNat c).val = g.toNat - c + rw [← Sat256.toNat, Sat256.subNat_toNat] + +/-! ## Peeling one `Xstep` off `X` -/ + +/-- **The stepping workhorse.** Given that one `Xstep` evaluates to the standard + per-instruction shape `if gas < cost then OutOfGass else .ok (next, .none)` (exactly + what the `step_*` opcode lemmas produce, once stack-shape/overflow side conditions + are discharged), peel it off the iterator: `X (f+1)` becomes the same gas guard + wrapped around `X f` on the successor state. Holds for *any* fuel `f`. -/ +theorem X_peel {vj : Array UInt256} {s s' : State} {P : Prop} [Decidable P] {f : ℕ} + (h : Xstep vj s = if P then .error .OutOfGass else .ok (s', .none)) : + X (f + 1) vj s = if P then .error .OutOfGass else X f vj s' := by + by_cases hg : P + · simp only [hg, if_true] at h ⊢ + exact Xstep_X_X_except f s vj _ h + · simp only [hg, if_false] at h ⊢ + exact Xstep_X_X_continue f s s' vj (X f vj s') h rfl + +/-- Collapse the two-stage gas guard of a memory opcode (charge `c1` for memory + expansion, then `c2` for the base cost) into a single guard `gas < c1 + c2`. -/ +theorem collapse_two_stage {α : Type _} {gas : Sat256} {c1 c2 : ℕ} {X Y : α} : + (if gas.toNat < c1 then Y + else if (gas.subNat c1).toNat < c2 then Y else X) + = if gas.toNat < c1 + c2 then Y else X := by + by_cases h1 : gas.toNat < c1 + · rw [if_pos h1, if_pos (by omega)] + · rw [if_neg h1] + by_cases h2 : (gas.subNat c1).toNat < c2 + · rw [if_pos h2, if_pos (by simp [Sat256.toNat, Sat256.subNat] at *; omega)] + · rw [if_neg h2, if_neg (by simp [Sat256.toNat, Sat256.subNat] at *; omega)] + +/-! ## Trace drivers — peel a step tracking step-count `k` and cumulative cost `C` -/ + +/-- **Continue a trace** when the current instruction's gas suffices. Invariants: + `s` is reached after `k` steps, has gas `g - C` (cumulative cost `C`), and the next + instruction costs `cost` with `C + cost ≤ g.toNat` (enough gas). The iterator advances + one step, decrementing fuel `g.toNat + 1 - k` and growing the cumulative cost. -/ +theorem stepContinue {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g : Sat256} + (hgas : s.machineState.gasAvailable = g.subNat C) + (hstep : Xstep vj s + = if s.machineState.gasAvailable.toNat < cost then .error .OutOfGass + else .ok (s', .none)) + (hk : k ≤ C) (hC : C + cost ≤ g.toNat) : + X (g.toNat + 1 - k) vj s = X (g.toNat + 1 - (k + 1)) vj s' := by + have hfuel : g.toNat + 1 - k = (g.toNat + 1 - (k + 1)) + 1 := by omega + rw [hfuel, X_peel hstep, hgas] + have hgg : ¬ (g.toNat - C < cost) := by omega + simp [hgg] + +/-- **Run out of gas** at the current instruction. Same invariants as `stepContinue`, + but now the next instruction's `cost` exceeds the remaining gas + (`g.toNat < C + cost`), so the iterator returns `OutOfGass`. -/ +theorem stepOOG {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g : Sat256} + (hgas : s.machineState.gasAvailable = g.subNat C) + (hstep : Xstep vj s + = if s.machineState.gasAvailable.toNat < cost then .error .OutOfGass + else .ok (s', .none)) + (hk : k ≤ C) (hC : C ≤ g.toNat) (hOOG : g.toNat < C + cost) : + X (g.toNat + 1 - k) vj s = .error .OutOfGass := by + have hfuel : g.toNat + 1 - k = (g.toNat + 1 - (k + 1)) + 1 := by omega + rw [hfuel, X_peel hstep, hgas] + have hgg : g.toNat - C < cost := by omega + simp [hgg] + +/-- **Halt** (`RETURN`/`STOP`/`SELFDESTRUCT` ⇒ success, or `REVERT`) when the current + instruction's gas suffices: the iterator returns the halt result directly. -/ +theorem stepHaltSuccess {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g : Sat256} {o} + (hgas : s.machineState.gasAvailable = g.subNat C) + (hstep : Xstep vj s + = if s.machineState.gasAvailable.toNat < cost then .error .OutOfGass + else .ok (s', .some (.success, o))) + (hk : k ≤ C) (hC : C + cost ≤ g.toNat) : + X (g.toNat + 1 - k) vj s = .ok (.success s' o) := by + have hfuel : g.toNat + 1 - k = (g.toNat + 1 - (k + 1)) + 1 := by omega + rw [hfuel] + have hgg : ¬ (s.machineState.gasAvailable.toNat < cost) := by rw [hgas]; simp [Sat256.subNat, Sat256.toNat] at *; omega + exact Xstep_X_X_halt_success _ s s' vj o (by rw [hstep]; simp [hgg]) + +/-- **Halt with revert** when the current instruction's gas suffices: the iterator returns the + revert result directly. -/ +theorem stepHaltRevert {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g : Sat256} {o} + (hgas : s.machineState.gasAvailable = g.subNat C) + (hstep : Xstep vj s + = if s.machineState.gasAvailable.toNat < cost then .error .OutOfGass + else .ok (s', .some (.revert, o))) + (hk : k ≤ C) (hC : C + cost ≤ g.toNat) : + X (g.toNat + 1 - k) vj s = .ok (.revert s'.machineState.gasAvailable.toUInt256 o) := by + have hfuel : g.toNat + 1 - k = (g.toNat + 1 - (k + 1)) + 1 := by omega + rw [hfuel] + have hgg : ¬ (s.machineState.gasAvailable.toNat < cost) := by rw [hgas]; simp [Sat256.subNat, Sat256.toNat] at *; omega + exact Xstep_X_X_halt_revert _ s s' vj o (by rw [hstep]; simp [hgg]) + /-- The derived `BEq UInt256` is lawful (it reduces to `Fin` equality). -/ instance : LawfulBEq UInt256 where eq_of_beq {a b} h := by diff --git a/Reasoning/Theory.lean b/Reasoning/Theory.lean deleted file mode 100644 index d65af36f..00000000 --- a/Reasoning/Theory.lean +++ /dev/null @@ -1,280 +0,0 @@ -import Solm.Equiv -import Ethereum.Theory.ProgressLemmas -import Ethereum.Theory.OpcodeLemmas - -/-! -# Theory — reusable, compositional lemmas for runtime-equivalence proofs - -General, **contract-agnostic** infrastructure for proving -`runtimeEquivalence cfg bytecode contract`. - -Lemmas here are about `runtimeEquivalenceFor`, `actExec`, `execResultsEquiv`, -`returnEquiv`, and the EVM driver `Ethereum.EVM.Ξ` / `X` / `Xstep` — never about a -specific contract. Each example's `Correct.lean` assembles them with its contract-specific facts. - -The backbone is a *symbolic-execution* discipline: -* `initState` — the fresh EVM state `Ξ` builds, shared with `actExec`'s `evmState`. -* `Xi_*_of_X` — reduce a fact about `Ξ` to a fact about the fuelled iterator `X`. -* `X_peel` — peel one `Xstep` off `X`, threading the per-instruction gas guard. - -Together with the `Ethereum.Theory.OpcodeLemmas` `step_*` lemmas (which evaluate one -`Xstep` to an explicit `if gas < cost then OutOfGass else .ok (next, .none)`), these let -a concrete bytecode trace be run for a *universally quantified* gas `g`. --/ - -open Solm ABI Ethereum Ethereum.EVM - -namespace Reasoning.Theory - -/-! ## 1. The initial EVM state -/ - -/-- The fresh EVM state `Ξ` constructs from the transaction inputs. Defined to be - **definitionally** the `freshEvmState` inside `Ethereum.EVM.Ξ` and the `evmState` - inside `actExec`, so both can be rewritten to mention this single name. -/ -def initState - (createdAccounts : Batteries.RBSet AccountAddress compare) - (genesisBlockHeader : BlockHeader) (blocks : ProcessedBlocks) - (σ σ₀ : AccountMap) (g : Sat256) (A : Substate) (I : ExecutionEnv) : State := - { (default : State) with - accountMap := σ - σ₀ := σ₀ - executionEnv := I - substate := A - createdAccounts := createdAccounts - machineState.gasAvailable := g - blocks := blocks - genesisBlockHeader := genesisBlockHeader } - -/-! ## 2. From `Ξ` to the fuelled iterator `X` -/ - -/-- If the fuelled iterator errors, so does `Ξ`. -/ -theorem Xi_error_of_X - {createdAccounts genesisBlockHeader blocks σ σ₀ A I} {e} {g : UInt256} - (h : X (g.toNat + 1) (D_J I.code 0) - (initState createdAccounts genesisBlockHeader blocks σ σ₀ (.ofUInt256 g) A I) = .error e) : - Ξ createdAccounts genesisBlockHeader blocks σ σ₀ g A I = .error e := by - unfold Ξ - simp only [initState, Sat256.ofUInt256] at h - simp [bind, Except.bind, Sat256.ofUInt256, h] - -/-- If the fuelled iterator reverts, so does `Ξ` (same gas/output). -/ -theorem Xi_revert_of_X - {createdAccounts genesisBlockHeader blocks σ σ₀ A I} {g' o} {g : UInt256} - (h : X (g.toNat + 1) (D_J I.code 0) - (initState createdAccounts genesisBlockHeader blocks σ σ₀ (.ofUInt256 g) A I) - = .ok (.revert g' o)) : - Ξ createdAccounts genesisBlockHeader blocks σ σ₀ g A I = .ok (.revert g' o) := by - unfold Ξ - simp only [initState, Sat256.ofUInt256] at h - simp [bind, Except.bind, Sat256.ofUInt256, h] - -/-- If the fuelled iterator succeeds (halts), so does `Ξ`, projecting the relevant - fields of the final machine state. -/ -theorem Xi_success_of_X - {createdAccounts genesisBlockHeader blocks σ σ₀ A I} {s' o} {g : UInt256} - (h : X (g.toNat + 1) (D_J I.code 0) - (initState createdAccounts genesisBlockHeader blocks σ σ₀ (.ofUInt256 g) A I) - = .ok (.success s' o)) : - Ξ createdAccounts genesisBlockHeader blocks σ σ₀ g A I - = .ok (.success (s'.createdAccounts, s'.accountMap, s'.machineState.gasAvailable.toUInt256, - s'.substate) o) := by - unfold Ξ - simp only [initState] at h - simp [bind, Except.bind, h] - -/-! ## 2½. `UInt256` gas arithmetic -/ - -/-- Charging a (small, non-wrapping) gas cost decrements `toNat` by that cost. The - side condition `c ≤ g.toNat` rules out the modular wrap. -/ -theorem toNat_sub_ofNat {g : Sat256} {c : ℕ} (hc : c ≤ g.toNat) : - (g.subNat c).toNat = g.toNat - c := by - have hsize : c < UInt256.size := lt_of_le_of_lt hc g.isLt - have hofnat : (UInt256.ofNat c).val.val = c := by - simp [UInt256.ofNat, Id.run, Fin.ofNat, Nat.mod_eq_of_lt hsize] - have hle : (UInt256.ofNat c).val ≤ g.val := by - rw [hofnat]; exact hc - show (g.subNat c).val = g.toNat - c - rw [← Sat256.toNat, Sat256.subNat_toNat] - -/-- A `UInt256` with `toNat = 0` is `⟨0⟩`. (Used to discharge `callvalue = 0` tests.) -/ -theorem uint256_toNat_eq_zero {a : UInt256} (h : a.toNat = 0) : a = ⟨0⟩ := by - obtain ⟨⟨v, hlt⟩⟩ := a - simp only [UInt256.toNat] at h - subst h; rfl - -/-! ## 3. Peeling one `Xstep` off `X` -/ - -/-- **The stepping workhorse.** Given that one `Xstep` evaluates to the standard - per-instruction shape `if gas < cost then OutOfGass else .ok (next, .none)` (exactly - what the `step_*` opcode lemmas produce, once stack-shape/overflow side conditions - are discharged), peel it off the iterator: `X (f+1)` becomes the same gas guard - wrapped around `X f` on the successor state. Holds for *any* fuel `f`. -/ -theorem X_peel {vj : Array UInt256} {s s' : State} {P : Prop} [Decidable P] {f : ℕ} - (h : Xstep vj s = if P then .error .OutOfGass else .ok (s', .none)) : - X (f + 1) vj s = if P then .error .OutOfGass else X f vj s' := by - by_cases hg : P - · simp only [hg, if_true] at h ⊢ - exact Xstep_X_X_except f s vj _ h - · simp only [hg, if_false] at h ⊢ - exact Xstep_X_X_continue f s s' vj (X f vj s') h rfl - -/-- Collapse the two-stage gas guard of a memory opcode (charge `c1` for memory - expansion, then `c2` for the base cost) into a single guard `gas < c1 + c2`. -/ -theorem collapse_two_stage {α : Type _} {gas : Sat256} {c1 c2 : ℕ} {X Y : α} : - (if gas.toNat < c1 then Y - else if (gas.subNat c1).toNat < c2 then Y else X) - = if gas.toNat < c1 + c2 then Y else X := by - by_cases h1 : gas.toNat < c1 - · rw [if_pos h1, if_pos (by omega)] - · rw [if_neg h1] - by_cases h2 : (gas.subNat c1).toNat < c2 - · rw [if_pos h2, if_pos (by simp [Sat256.toNat, Sat256.subNat] at *; omega)] - · rw [if_neg h2, if_neg (by simp [Sat256.toNat, Sat256.subNat] at *; omega)] - -/-! ## 3½. Trace drivers — peel a step tracking step-count `k` and cumulative cost `C` -/ - -/-- **Continue a trace** when the current instruction's gas suffices. Invariants: - `s` is reached after `k` steps, has gas `g - C` (cumulative cost `C`), and the next - instruction costs `cost` with `C + cost ≤ g.toNat` (enough gas). The iterator advances - one step, decrementing fuel `g.toNat + 1 - k` and growing the cumulative cost. -/ -theorem stepContinue {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g : Sat256} - (hgas : s.machineState.gasAvailable = g.subNat C) - (hstep : Xstep vj s - = if s.machineState.gasAvailable.toNat < cost then .error .OutOfGass - else .ok (s', .none)) - (hk : k ≤ C) (hC : C + cost ≤ g.toNat) : - X (g.toNat + 1 - k) vj s = X (g.toNat + 1 - (k + 1)) vj s' := by - have hfuel : g.toNat + 1 - k = (g.toNat + 1 - (k + 1)) + 1 := by omega - rw [hfuel, X_peel hstep, hgas] - have hgg : ¬ (g.toNat - C < cost) := by omega - simp [hgg] - -/-- **Run out of gas** at the current instruction. Same invariants as `stepContinue`, - but now the next instruction's `cost` exceeds the remaining gas - (`g.toNat < C + cost`), so the iterator returns `OutOfGass`. -/ -theorem stepOOG {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g : Sat256} - (hgas : s.machineState.gasAvailable = g.subNat C) - (hstep : Xstep vj s - = if s.machineState.gasAvailable.toNat < cost then .error .OutOfGass - else .ok (s', .none)) - (hk : k ≤ C) (hC : C ≤ g.toNat) (hOOG : g.toNat < C + cost) : - X (g.toNat + 1 - k) vj s = .error .OutOfGass := by - have hfuel : g.toNat + 1 - k = (g.toNat + 1 - (k + 1)) + 1 := by omega - rw [hfuel, X_peel hstep, hgas] - have hgg : g.toNat - C < cost := by omega - simp [hgg] - -/-- **Halt** (`RETURN`/`STOP`/`SELFDESTRUCT` ⇒ success, or `REVERT`) when the current - instruction's gas suffices: the iterator returns the halt result directly. -/ -theorem stepHaltSuccess {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g : Sat256} {o} - (hgas : s.machineState.gasAvailable = g.subNat C) - (hstep : Xstep vj s - = if s.machineState.gasAvailable.toNat < cost then .error .OutOfGass - else .ok (s', .some (.success, o))) - (hk : k ≤ C) (hC : C + cost ≤ g.toNat) : - X (g.toNat + 1 - k) vj s = .ok (.success s' o) := by - have hfuel : g.toNat + 1 - k = (g.toNat + 1 - (k + 1)) + 1 := by omega - rw [hfuel] - have hgg : ¬ (s.machineState.gasAvailable.toNat < cost) := by rw [hgas]; simp [Sat256.subNat, Sat256.toNat] at *; omega - exact Xstep_X_X_halt_success _ s s' vj o (by rw [hstep]; simp [hgg]) - -/-- **Halt with revert** when the current instruction's gas suffices: the iterator returns the - revert result directly. -/ -theorem stepHaltRevert {vj : Array UInt256} {s s' : State} {k C cost : ℕ} {g : Sat256} {o} - (hgas : s.machineState.gasAvailable = g.subNat C) - (hstep : Xstep vj s - = if s.machineState.gasAvailable.toNat < cost then .error .OutOfGass - else .ok (s', .some (.revert, o))) - (hk : k ≤ C) (hC : C + cost ≤ g.toNat) : - X (g.toNat + 1 - k) vj s = .ok (.revert s'.machineState.gasAvailable.toUInt256 o) := by - have hfuel : g.toNat + 1 - k = (g.toNat + 1 - (k + 1)) + 1 := by omega - rw [hfuel] - have hgg : ¬ (s.machineState.gasAvailable.toNat < cost) := by rw [hgas]; simp [Sat256.subNat, Sat256.toNat] at *; omega - exact Xstep_X_X_halt_revert _ s s' vj o (by rw [hstep]; simp [hgg]) - -/-! ## 3¾. Coverage helpers — build a `runtimeEquivalenceFor` case from a `Ξ` outcome -/ - -/-- `Ξ` runs out of gas ⇒ the `outOfGas` case. -/ -theorem reEquiv_outOfGas {cfg contract cA gh bl σ_evm σ_solm σ₀ g A I} - (h : Ξ cA gh bl σ_evm σ₀ g A I = .error .OutOfGass) : - runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g A I := - .outOfGas h - -/-- When a contract has no `receive`/`fallback`, a successful `dispatchMsg` is a successful - selector dispatch: the receive and fallback arms of `dispatchMsg` are `none`. Shared by the - `decodingFailed`/`execution` coverage helpers below. -/ -theorem selectorDispatchMsg_eq_some_of_dispatchMsg_eq_some - {contract : ContractDecl} {calldata : ByteArray} {transition : TransitionDecl} - (hreceive : contract.receive = none) - (hfallback : contract.fallback = none) - (h : dispatchMsg contract calldata = some transition) : - selectorDispatchMsg contract calldata = some transition := by - unfold dispatchMsg at h - cases hsel : selectorDispatchMsg contract calldata with - | none => - have hreceiveDispatch : receiveDispatchMsg contract calldata = none := by - simp [receiveDispatchMsg, hreceive] - rw [hsel, hreceiveDispatch, hfallback] at h - simp at h - | some selected => - rw [hsel] at h - simpa using h - -/-- Solm fails to dispatch and `Ξ` reverts ⇒ the `noDispatch` case. The Solm-side maps are - unconstrained — this path never runs `solmExec`. -/ -theorem reEquiv_noDispatch {cfg contract cA gh bl σ_evm σ_solm σ₀ g A I} {g' o} - (hd : dispatchMsg contract I.calldata = none) - (h : Ξ cA gh bl σ_evm σ₀ g A I = .ok (.revert g' o)) : - runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g A I := - .noDispatch hd h - -/-- Solm dispatches but decoding fails and `Ξ` reverts ⇒ `decodingFailed`. Solm-side maps - unconstrained. -/ -theorem reEquiv_decodingFailed - {cfg contract cA gh bl σ_evm σ_solm σ₀ g A I} {t g' o} - (hd : dispatchMsg contract I.calldata = some t) - (hdec : decodeCalldataWithMode cfg.abiDecodeMode (t.params.map Param.name) - (transitionSignature t).paramTypes I.calldata = none) - (h : Ξ cA gh bl σ_evm σ₀ g A I = .ok (.revert g' o)) - (hfallback : contract.fallback = none := by rfl) - (hreceive : contract.receive = none := by rfl) : - runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g A I := - .decodingFailed (selectorDispatchMsg_eq_some_of_dispatchMsg_eq_some hreceive hfallback hd) - rfl hdec h - -/-- The Solm transition executes (to `actRes`) and `Ξ`'s result matches ⇒ the `execution` case. - The EVM runs from `σ_evm`, the Solm body from `σ_solm` (genuinely distinct maps); `hequiv` - carries the up-to-`accountMapEquiv` coupling of their results. -/ -theorem reEquiv_execution - {cfg contract cA gh bl σ_evm σ_solm σ₀ A I} {t callargs actRes} - {g : UInt256} - (hd : dispatchMsg contract I.calldata = some t) - (hdec : decodeCalldataWithMode cfg.abiDecodeMode (t.params.map Param.name) - (transitionSignature t).paramTypes I.calldata = some callargs) - (hbody : ExecTransitionBody cfg contract - (initState cA gh bl σ_solm σ₀ (.ofUInt256 g) A I) callargs t.body actRes) - (hequiv : execResultsEquiv (Ξ cA gh bl σ_evm σ₀ g A I) actRes (.abi t.returnType)) - (hfallback : contract.fallback = none := by rfl) - (hreceive : contract.receive = none := by rfl) : - runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g A I := - .execution rfl - (.intro (selectorDispatchMsg_eq_some_of_dispatchMsg_eq_some hreceive hfallback hd) - rfl hdec rfl hbody) - hequiv - -/-- The receive transition executes without selector ABI decoding and `Ξ`'s result matches. -/ -theorem reEquiv_receiveExecution - {cfg contract cA gh bl σ_evm σ_solm σ₀ A I} {t actRes} - {g : UInt256} - (hreceive : receiveDispatchMsg contract I.calldata = some t) - (hparams : t.params = []) - (hreturn : t.returnType = []) - (hbody : ExecTransitionBody cfg contract - (initState cA gh bl σ_solm σ₀ (.ofUInt256 g) A I) ∅ t.body actRes) - (hequiv : execResultsEquiv (Ξ cA gh bl σ_evm σ₀ g A I) actRes (.abi [])) : - runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g A I := - .execution rfl (.receive hreceive hparams hreturn rfl hbody) hequiv - -/-! ## 4. Fuel monotonicity -/ - -end Reasoning.Theory From fac0fdbbff660788ff097dff7fc78a069292afe7 Mon Sep 17 00:00:00 2001 From: zoep Date: Tue, 28 Jul 2026 23:09:48 +0300 Subject: [PATCH 22/38] Reasoning: add structure file --- Reasoning/STRUCTURE.md | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Reasoning/STRUCTURE.md diff --git a/Reasoning/STRUCTURE.md b/Reasoning/STRUCTURE.md new file mode 100644 index 00000000..042505f9 --- /dev/null +++ b/Reasoning/STRUCTURE.md @@ -0,0 +1,74 @@ +# Reasoning/ — structure + +Shared, contract-agnostic infrastructure for proving that compiled EVM bytecode refines its Solm +specification. Every per-contract proof in `Examples/` and `Benchmarks/` is assembled from these +files plus contract-specific facts (bytecode literals, selectors, storage layout). + +Everything is in namespace `Reasoning.Theory`, except the EVM trace layer (`RD`, `evm_run`, and the +`RD.*` lemma halves of `Solc.lean` and `Dispatch.lean`), which is in `Reasoning.Reach`. +`JumpDest.lean` has no namespace (it defines a tactic and an attribute). + +One axiom in the whole library: `keccak_size` in `Memory.lean` (a keccak digest is 32 bytes — +trusted spec of the FFI hash; asserts nothing about collision resistance). + +## Files + +| File | Contents | +|---|---| +| `Stepping.lean` | Base layer. Trace drivers — `initState` (the fresh EVM state), the `Ξ`-to-iterator bridge (`Xi_*_of_X`), single-step peeling (`X_peel`, `stepContinue`, `stepOOG`, `stepHalt*`) — plus one lemma per opcode (`_xstep`) evaluating a single `Xstep` to an explicit gas-guarded successor state (`st` definitions). | +| `EVMWord.lean` | `UInt256` arithmetic: no-wrap `toNat` lemmas, bitwise normalization, unsigned comparisons, signed `SLT`, `compare` order instances, the word-rounding used by solc memory allocation. | +| `SolmBody.lean` | The Solm side: `ExecTransitionBody`/`ExecStmt`/`ExecBlock` lemmas. Non-payable guard, call wrappers (external/checked/low-level/delegate), loop rules, block sequencing (`execBlock_append`), locals lookup, storage-access collapse. | +| `Memory.lean` | Byte-level memory: little-endian word arithmetic, `MSTORE`/`MLOAD` read-write facts, scratch memory for mapping hashes, selector extraction, calldata decode coupling, mapping-slot keccak facts. Home of the `keccak_size` axiom. | +| `Reach.lean` | The EVM trace layer. `RD` (reached-or-out-of-gas invariant), one forward step lemma per opcode (`RD.`), `CALL`/`STATICCALL` with the callee treated as an opaque `Θ` result, terminal forms `RDret`/`RDrev` with the `reEquiv_*` case builders for `runtimeEquivalenceFor` and the `reEquivElim` eliminators, `Cursor`/`RDc`, and the `evm_run` macro that chains steps with auto-discharged decode/overflow side conditions. | +| `ABI.lean` | Calldata decoding and return-value encoding: per-shape decode lemmas (address/uint256/bool/bytes32/string/dynamic-array combinations), decode-mode variants, failure cases (short, huge, non-canonical), return encodings. | +| `MemCascade.lean` | Collapsing chains of memory writes into a canonical form. | +| `JumpDest.lean` | The `@[valid_jumps]` attribute and `jump_dest` tactic discharging jump-target validity (via `native_decide`, deliberately). | +| `Initcode.lean` | Constructor-time facts: decode of the initcode prefix, jump-table survival, constructor-argument arithmetic. | +| `Solc.lean` | Compiler-emitted code shapes, proved once: selector dispatch, ABI length checks, free-memory-pointer and revert memory, the 160-bit address mask, getter/store routines, reentrancy locks, checked arithmetic, event logs, high-level call combinators. | +| `Storage.lean` | Storage maps: red-black-map lookup/update facts, `StorageLoc` load/store for the Solidity value encodings, the bytes/string storage layout, `accountMapEquiv`/`EVMStateEquiv` with `SLOAD`/`SSTORE` preservation. | +| `Dispatch.lean` | Solm dispatcher facts: `dispatchMsg` as a list walk (`dispatchList`), single-transition instances, `SingleSelectorDispatch`, and the `RDret`/`RDrev.reEquiv*` bridges that connect a finished trace to the equivalence statement. | +| `ExternalCall.lean` | The `CALL` ↔ Solm `externalCall` boundary: both sides invoke the same `Θ`, so results coincide (`callCoincides`); transport of call results across equivalent account maps. | +| `Constructor.lean` | Skeletons for constructor (creation-code) equivalence proofs. | + +## Dependencies + +External: `Ethereum.*` (evmlean — EVM semantics and opcode lemmas), `Solm` (the spec language and +its semantics), `ABI.Decode`, Mathlib (EVMWord and Memory only). + +Within `Reasoning/`, imports flow upward: + +``` +Stepping EVMWord ── SolmBody + │ │ + ├── Memory ── MemCascade + │ │ + │ ├── ABI + │ └── Reach + │ │ + └───────── Solc + │ + Storage + ├── Dispatch (also Reach) + └── ExternalCall (also SolmBody) + +Constructor ← Reach, SolmBody Initcode ← EVMWord JumpDest ← (Ethereum only) +``` + +## Where to look + +- Run one opcode of a concrete trace → `Stepping` (`_xstep`), chained via `Reach` (`evm_run`). +- Word arithmetic side condition → `EVMWord`. +- Memory read/write or keccak slot → `Memory` (chains of writes: `MemCascade`). +- Decode calldata / encode a return value → `ABI` (solc-specific length checks: `Solc`). +- A code shape the compiler always emits → `Solc`. +- Storage read/write, packed values, bytes/string layout, account-map equivalence → `Storage`. +- Selector dispatch, connecting a trace to `runtimeEquivalence` → `Dispatch`. +- An external call inside a function body → `ExternalCall` (EVM side: `RD.call` in `Reach`; + Solm side: `SolmBody`). +- Constructor proofs → `Constructor`, `Initcode`. +- Jump-target validity → `JumpDest`. + +## Build + +`lake build Reasoning` builds all fourteen files. A bare `lake build` builds only `Solm` +(the default target) — use explicit targets. From 11e7a6b01dede70fc228f9481c7e5f67d3e10dd2 Mon Sep 17 00:00:00 2001 From: zoep Date: Tue, 28 Jul 2026 23:24:23 +0300 Subject: [PATCH 23/38] Worklows: ci --- .github/workflows/ci.yml | 84 ++++++++++++++++++++++++++++++++++++++++ README.md | 11 +++++- TODO.md | 18 +++++---- 3 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..c42f603c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,84 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 330 + steps: + - uses: actions/checkout@v4 + + # Installs the toolchain from lean-toolchain, fetches the mathlib + # olean cache, caches .lake in the GitHub cache, and builds the + # library targets. + - name: Build libraries + uses: leanprover/lean-action@v1 + with: + build-args: EquiVM EVM ABI Solm Reasoning Proofs + use-github-cache: true + + # Mirrors the imports of Examples.lean. Remove lines to prune. + - name: Build examples + run: | + lake build \ + Examples.Pow.Correct \ + Examples.Truth.Correct \ + Examples.Caller.Correct \ + Examples.ERC20.Correct \ + Examples.CtorTruth.Correct \ + Examples.CtorStore.Correct \ + Examples.TinyImmutable.Correct \ + Examples.Ballot.Correct \ + Examples.SimpleAuction.Correct \ + Examples.StringStoreLite.Correct \ + Examples.BlindAuction.Correct \ + Examples.OpenZeppelinBench.Ownable2Step.Correct \ + Examples.OpenZeppelinBench.AccessControl.Correct \ + Examples.OpenZeppelinBench.Pausable.Correct \ + Examples.OpenZeppelinBench.ERC6909.Correct \ + Examples.UniswapV2Pair.Correct + + # Mirrors the imports of Benchmarks.lean. Remove lines to prune. + - name: Build benchmarks + run: | + lake build \ + Benchmarks.WETH9.Correct \ + Benchmarks.Safe.Correct \ + Benchmarks.UniswapV3Pool.Correct \ + Benchmarks.UniswapV2Router02.Correct \ + Benchmarks.Dss.Dai.Correct \ + Benchmarks.Dss.Jug.Correct \ + Benchmarks.Dss.Vat.Correct \ + Benchmarks.Dss.Pot.Correct \ + Benchmarks.Dss.Spot.Correct \ + Benchmarks.Dss.Vow.Correct \ + Benchmarks.Dss.LinearDecrease.Correct \ + Benchmarks.Dss.StairstepExponentialDecrease.Correct \ + Benchmarks.Dss.ExponentialDecrease.Correct \ + Benchmarks.Dss.Cat.Correct \ + Benchmarks.Dss.Clipper.Correct \ + Benchmarks.Dss.Cure.Correct \ + Benchmarks.Dss.Dog.Correct \ + Benchmarks.Dss.End.Correct \ + Benchmarks.Dss.Flapper.Correct \ + Benchmarks.Dss.Flipper.Correct \ + Benchmarks.Dss.Flopper.Correct \ + Benchmarks.Dss.GemJoin.Correct \ + Benchmarks.Dss.DaiJoin.Correct \ + Benchmarks.CompoundIII.CometRewards.Correct \ + Benchmarks.CompoundIII.Comet.Correct \ + Benchmarks.EAS.Attester.Correct \ + Benchmarks.ERC721.Correct \ + Benchmarks.Auction.Correct \ + Benchmarks.OpenZeppelinBench.VestingWallet.Correct \ + Benchmarks.OpenZeppelinBench.TimelockController.Correct \ + Benchmarks.Klima.Correct diff --git a/README.md b/README.md index 171cc8d5..667a3fb3 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,9 @@ verification of the contract's behavior or in human audits. Refinement proofs are intended to be generated by autonomous LLM agents. We are currently evaluating the capabilities of LLMs to provide such refinement proofs autonomously and their cost (see the `Examples/` and `Benchmarks/` directories). -The framework has been designed with this goal in mind. +The framework has been designed with this goal in mind. We have used the framework +to prove refinement for several real-world contracts, including MakerDAO's Dss, WETH9, and several Opal contracts. The framework is designed to be extensible and can be used to prove refinement for other EVM bytecode as well. + ## Sol⁻ Sol⁻ is a small imperative language, inspired by Solidity and designed to be @@ -65,6 +67,13 @@ theorem ContractCorrect : which bundles the constructor equivalence (creation code) with the runtime equivalence (deployed code). +## Interoperability + +One of the technical innovations of Sol⁻ is that it gives a formal semantics +to a contract interacting with arbitrary EVM bytecode. We achieve this by +using an approach inspired by multi-language semantics: the external call +boundary is defined in terms of the EVM semantics. + ## Architecture - **EVM semantics** ([`EVM/`](EVM/)) diff --git a/TODO.md b/TODO.md index 83f35f92..64083d58 100644 --- a/TODO.md +++ b/TODO.md @@ -2,15 +2,17 @@ - [X] EquiVM/EVM - [X] Solm -- [ ] ABI -- [ ] Reasoning +- [X] ABI +- [X] Reasoning - [ ] Examples - + [ ] Concrete syntax + + [X] Concrete syntax + + [X]Verify structure - [ ] Benchmarks - + [ ] Concrete syntax -- [ ] Proofs -- [ ] Misc - + [ ] Proof template + + [X] Concrete syntax + + [X] Verify structure +- [X] Proofs +- [X] Misc + + [X] Proof template - [ ] Docs + [ ] README * [ ] External call section @@ -19,7 +21,7 @@ - [ ] CI/CD - + # Solm Semantics - [X] Constructor calls + currently we don't have From c4c2825baaaba72b18860bc4b8b3ec25c90bece6 Mon Sep 17 00:00:00 2001 From: zoep Date: Tue, 28 Jul 2026 23:28:53 +0300 Subject: [PATCH 24/38] Benchmarks: add forgoten file --- Benchmarks/WETH9/sources.sha256 | 1 + README.md | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 Benchmarks/WETH9/sources.sha256 diff --git a/Benchmarks/WETH9/sources.sha256 b/Benchmarks/WETH9/sources.sha256 new file mode 100644 index 00000000..32d81b7f --- /dev/null +++ b/Benchmarks/WETH9/sources.sha256 @@ -0,0 +1 @@ +097d1a4258c78e1062798419ecb9c4e60b7327de5213be4bedfa4c1fdd04aa95 Benchmarks/WETH9/WETH9.sol diff --git a/README.md b/README.md index 667a3fb3..37960493 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,11 @@ verification of the contract's behavior or in human audits. Refinement proofs are intended to be generated by autonomous LLM agents. We are currently evaluating the capabilities of LLMs to provide such refinement proofs autonomously and their cost (see the `Examples/` and `Benchmarks/` directories). -The framework has been designed with this goal in mind. We have used the framework -to prove refinement for several real-world contracts, including MakerDAO's Dss, WETH9, and several Opal contracts. The framework is designed to be extensible and can be used to prove refinement for other EVM bytecode as well. +The framework has been designed with this goal in mind. We have used the +framework to prove refinement for several real-world contracts, including +MakerDAO's Dss, WETH9, and several OpenZeppelin contracts. Our case studies +exercise various versions and options of the `solc` compiler, including the +optimizer, and we have proof-of-concept proofs for the Vyper compiler as well. ## Sol⁻ From be69296a083c029942d6227e1a249e1b6456a4e0 Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 00:12:43 +0300 Subject: [PATCH 25/38] Benchmarks: cleanup and README --- .github/workflows/ci.yml | 21 +- Benchmarks.lean | 11 - .../CompoundIII/CometRewards/Claim.lean | 6566 ------------ .../CompoundIII/CometRewards/ClaimTo.lean | 20 - .../CompoundIII/CometRewards/Common.lean | 1617 --- .../CompoundIII/CometRewards/Constructor.lean | 753 -- .../CompoundIII/CometRewards/Correct.lean | 89 - .../CometRewards/GetRewardOwed.lean | 7855 -------------- .../CompoundIII/CometRewards/Governor.lean | 238 - .../CometRewards/RewardConfig.lean | 1042 -- .../CometRewards/RewardsClaimed.lean | 698 -- .../CompoundIII/CometRewards/Scratch.lean | 192 - .../CometRewards/SetRewardConfig.lean | 7109 ------------- .../SetRewardConfigWithMultiplier.lean | 9345 ----------------- .../CometRewards/SetRewardsClaimed.lean | 21 - .../CometRewards/TransferGovernor.lean | 725 -- .../CometRewards/WithdrawToken.lean | 2431 ----- Benchmarks/EAS/Attester/Attest.lean | 3883 ------- Benchmarks/EAS/Attester/Common.lean | 1851 ---- Benchmarks/EAS/Attester/Constructor.lean | 936 -- Benchmarks/EAS/Attester/Correct.lean | 65 - Benchmarks/EAS/Attester/DynamicArray.lean | 2800 ----- Benchmarks/EAS/Attester/InnerArray.lean | 485 - Benchmarks/EAS/Attester/InnerArrayCopy.lean | 1927 ---- Benchmarks/EAS/Attester/InnerArrayEVM.lean | 1845 ---- Benchmarks/EAS/Attester/InnerArrayInit.lean | 1439 --- Benchmarks/EAS/Attester/MultiAttest.lean | 1376 --- Benchmarks/EAS/Attester/MultiRevoke.lean | 3088 ------ .../EAS/Attester/MultiRevokeContinuation.lean | 4745 --------- Benchmarks/EAS/Attester/MultiRevokeEVM.lean | 1593 --- .../EAS/Attester/MultiRevokeEncoderABI.lean | 1140 -- .../EAS/Attester/MultiRevokeEncoderExact.lean | 262 - .../Attester/MultiRevokeEncoderLayout.lean | 1565 --- .../EAS/Attester/MultiRevokeLoopRun.lean | 598 -- .../EAS/Attester/MultiRevokeMemory.lean | 2365 ----- .../EAS/Attester/MultiRevokePostCall.lean | 569 - .../EAS/Attester/MultiRevokePostLoop.lean | 1695 --- .../EAS/Attester/MultiRevokeProgress.lean | 2166 ---- Benchmarks/EAS/Attester/MultiSource.lean | 1411 --- Benchmarks/EAS/Attester/NestedArray.lean | 1046 -- Benchmarks/EAS/Attester/OuterArrayInit.lean | 1992 ---- Benchmarks/EAS/Attester/Revoke.lean | 1698 --- .../TimelockController/AbiDecode.lean | 424 - .../TimelockController/AbiEncode.lean | 66 - .../TimelockController/Body.lean | 140 - .../TimelockController/Cancel.lean | 998 -- .../TimelockController/CancellerRole.lean | 102 - .../TimelockController/Constructor.lean | 52 - .../TimelockController/ConstructorDefs.lean | 142 - .../TimelockController/ConstructorEvm.lean | 167 - .../TimelockController/ConstructorSolm.lean | 405 - .../TimelockController/Correct.lean | 146 - .../TimelockController/DefaultAdminRole.lean | 103 - .../TimelockController/Dispatch.lean | 527 - .../TimelockController/EvmExec.lean | 194 - .../TimelockController/EvmReach.lean | 49 - .../TimelockController/EvmReverts.lean | 335 - .../TimelockController/Execute.lean | 19 - .../TimelockController/ExecuteBatch.lean | 19 - .../TimelockController/ExecutorRole.lean | 102 - .../TimelockController/Fallback.lean | 472 - .../TimelockController/GetMinDelay.lean | 99 - .../TimelockController/GetOperationState.lean | 445 - .../TimelockController/GetRoleAdmin.lean | 299 - .../TimelockController/GetTimestamp.lean | 241 - .../TimelockController/GrantRole.lean | 703 -- .../TimelockController/HasRole.lean | 501 - .../TimelockController/HashOperation.lean | 57 - .../HashOperationBatch.lean | 19 - .../TimelockController/IsOperation.lean | 415 - .../TimelockController/IsOperationDone.lean | 383 - .../IsOperationPending.lean | 452 - .../TimelockController/IsOperationReady.lean | 430 - .../OnERC1155BatchReceived.lean | 19 - .../TimelockController/OnERC1155Received.lean | 19 - .../TimelockController/OnERC721Received.lean | 19 - .../TimelockController/ProposerRole.lean | 100 - .../TimelockController/Receivers.lean | 226 - .../TimelockController/RenounceRole.lean | 785 -- .../TimelockController/Return.lean | 55 - .../TimelockController/RevokeRole.lean | 1033 -- .../TimelockController/Routines.lean | 218 - .../TimelockController/Schedule.lean | 19 - .../TimelockController/ScheduleBatch.lean | 19 - .../TimelockController/ScratchGrant.lean | 79 - .../TimelockController/SolmDispatch.lean | 196 - .../TimelockController/Storage.lean | 158 - .../TimelockController/SupportsInterface.lean | 713 -- .../TimelockController/UpdateDelay.lean | 378 - Benchmarks/README.md | 349 +- Benchmarks/Scaffolds.lean | 11 + .../{ => Scaffolds}/Auction/Bytecode.lean | 2 +- .../{ => Scaffolds}/Auction/Constructor.lean | 2 +- .../{ => Scaffolds}/Auction/Correct.lean | 2 +- .../Auction/NounsAuctionHouse.abi.json | 0 .../Auction/NounsAuctionHouse.sol | 0 .../Auction/NounsAuctionHouse.storage.json | 0 Benchmarks/{ => Scaffolds}/Auction/Spec.lean | 0 .../{ => Scaffolds}/Auction/SpecSyntax.lean | 2 +- .../{ => Scaffolds}/Auction/creation.hex | 0 .../Auction/interfaces/INounsAuctionHouse.sol | 0 .../interfaces/INounsDescriptorMinimal.sol | 0 .../Auction/interfaces/INounsSeeder.sol | 0 .../Auction/interfaces/INounsToken.sol | 0 .../Auction/interfaces/IWETH.sol | 0 .../{ => Scaffolds}/Auction/runtime.hex | 0 .../{ => Scaffolds}/Auction/sources.sha256 | 0 .../contracts/access/OwnableUpgradeable.sol | 0 .../contracts/proxy/utils/Initializable.sol | 0 .../security/PausableUpgradeable.sol | 0 .../security/ReentrancyGuardUpgradeable.sol | 0 .../contracts/utils/ContextUpgradeable.sol | 0 .../contracts/token/ERC20/IERC20.sol | 0 .../contracts/token/ERC721/IERC721.sol | 0 .../contracts/utils/introspection/IERC165.sol | 0 .../Comet/Bytecode.lean | 2 +- .../Comet/CometWithExtendedAssetList.abi.json | 0 .../CometWithExtendedAssetList.sol.ast.json | 0 .../CometWithExtendedAssetList.storage.json | 0 .../Comet/Constructor.lean | 2 +- .../Comet/Correct.lean | 2 +- .../Comet/Immutables.lean | 0 .../Comet/README.md | 0 .../Comet/Spec.lean | 2 +- .../Comet/SpecSyntax.lean | 2 +- .../Comet/creation.hex | 0 .../Comet/runtime.hex | 0 .../CometRewards/Bytecode.lean | 2 +- .../CometRewards/CometRewards.abi.json | 0 .../CometRewards/CometRewards.sol.ast.json | 0 .../CometRewards/CometRewards.storage.json | 0 .../Scaffolds/CometRewards/Constructor.lean | 19 + .../Scaffolds/CometRewards/Correct.lean | 23 + .../CometRewards/README.md | 0 .../CometRewards/Spec.lean | 0 .../CometRewards/SpecSyntax.lean | 2 +- .../CometRewards/Trusted.lean | 2 +- .../CometRewards/creation.hex | 0 .../CometRewards/runtime.hex | 0 .../{ => Scaffolds}/CompoundIII/README.md | 0 .../contracts/CometConfiguration.sol | 0 .../CompoundIII/contracts/CometCore.sol | 0 .../contracts/CometExtInterface.sol | 0 .../CompoundIII/contracts/CometInterface.sol | 0 .../contracts/CometMainInterface.sol | 0 .../CompoundIII/contracts/CometMath.sol | 0 .../CompoundIII/contracts/CometRewards.sol | 0 .../CompoundIII/contracts/CometStorage.sol | 0 .../contracts/CometWithExtendedAssetList.sol | 0 .../contracts/interfaces/ERC20.sol | 0 .../contracts/interfaces/IAssetList.sol | 0 .../interfaces/IAssetListFactory.sol | 0 .../interfaces/IAssetListFactoryHolder.sol | 0 .../interfaces/IERC20NonStandard.sol | 0 .../contracts/interfaces/IPriceFeed.sol | 0 .../CompoundIII/sources.sha256 | 0 .../EAS/Attester/Attester.abi.json | 0 .../EAS/Attester/Attester.sol.ast.json | 0 .../EAS/Attester/Attester.storage.json | 0 .../EAS/Attester/Bytecode.lean | 2 +- .../Scaffolds/EAS/Attester/Constructor.lean | 20 + .../Scaffolds/EAS/Attester/Correct.lean | 26 + .../EAS/Attester/Immutables.lean | 0 .../{ => Scaffolds}/EAS/Attester/README.md | 0 .../{ => Scaffolds}/EAS/Attester/Spec.lean | 2 +- .../EAS/Attester/SpecSyntax.lean | 2 +- .../{ => Scaffolds}/EAS/Attester/Trusted.lean | 2 +- .../eas-contracts/contracts/Common.sol | 0 .../eas-contracts/contracts/IEAS.sol | 0 .../contracts/ISchemaRegistry.sol | 0 .../eas-contracts/contracts/ISemver.sol | 0 .../contracts/resolver/ISchemaResolver.sol | 0 .../EAS/Attester/contracts/Attester.sol | 0 .../{ => Scaffolds}/EAS/Attester/creation.hex | 0 .../{ => Scaffolds}/EAS/Attester/runtime.hex | 0 .../EAS/Attester/sources.sha256 | 0 .../{ => Scaffolds}/ERC721/Bytecode.lean | 2 +- .../{ => Scaffolds}/ERC721/Constructor.lean | 2 +- .../{ => Scaffolds}/ERC721/Correct.lean | 6 +- .../{ => Scaffolds}/ERC721/ERC721.abi.json | 0 Benchmarks/{ => Scaffolds}/ERC721/ERC721.sol | 0 .../ERC721/ERC721.storage.json | 0 Benchmarks/{ => Scaffolds}/ERC721/Spec.lean | 0 .../{ => Scaffolds}/ERC721/SpecSyntax.lean | 2 +- .../{ => Scaffolds}/ERC721/creation.hex | 0 Benchmarks/{ => Scaffolds}/ERC721/runtime.hex | 0 .../{ => Scaffolds}/ERC721/sources.sha256 | 0 .../{ => Scaffolds}/Klima/Bytecode.lean | 2 +- .../{ => Scaffolds}/Klima/Constructor.lean | 2 +- Benchmarks/{ => Scaffolds}/Klima/Correct.lean | 2 +- .../{ => Scaffolds}/Klima/KlimaToken.abi.json | 0 .../Klima/KlimaToken.storage.json | 0 Benchmarks/{ => Scaffolds}/Klima/README.md | 0 Benchmarks/{ => Scaffolds}/Klima/Spec.lean | 2 +- .../{ => Scaffolds}/Klima/SpecSyntax.lean | 2 +- .../{ => Scaffolds}/Klima/StringLayout.lean | 0 .../Klima/contracts/KlimaToken.sol | 0 Benchmarks/{ => Scaffolds}/Klima/creation.hex | 0 Benchmarks/{ => Scaffolds}/Klima/runtime.hex | 0 .../{ => Scaffolds}/Klima/sources.sha256 | 0 .../contracts/access/AccessControl.sol | 0 .../contracts/access/IAccessControl.sol | 0 .../contracts/access/Ownable.sol | 0 .../contracts/finance/VestingWallet.sol | 0 .../governance/TimelockController.sol | 0 .../contracts/interfaces/IERC1363.sol | 0 .../contracts/interfaces/IERC165.sol | 0 .../contracts/interfaces/IERC20.sol | 0 .../contracts/interfaces/IERC20Metadata.sol | 0 .../token/ERC1155/IERC1155Receiver.sol | 0 .../token/ERC1155/utils/ERC1155Holder.sol | 0 .../contracts/token/ERC20/IERC20.sol | 0 .../token/ERC20/extensions/IERC20Metadata.sol | 0 .../contracts/token/ERC20/utils/SafeERC20.sol | 0 .../token/ERC721/IERC721Receiver.sol | 0 .../token/ERC721/utils/ERC721Holder.sol | 0 .../contracts/utils/Address.sol | 0 .../contracts/utils/Context.sol | 0 .../contracts/utils/Errors.sol | 0 .../contracts/utils/LowLevelCall.sol | 0 .../contracts/utils/introspection/ERC165.sol | 0 .../contracts/utils/introspection/IERC165.sol | 0 Benchmarks/{ => Scaffolds}/Safe/Bytecode.lean | 2 +- .../{ => Scaffolds}/Safe/Constructor.lean | 2 +- Benchmarks/{ => Scaffolds}/Safe/Correct.lean | 2 +- Benchmarks/{ => Scaffolds}/Safe/README.md | 0 Benchmarks/{ => Scaffolds}/Safe/Safe.abi.json | 0 Benchmarks/{ => Scaffolds}/Safe/Spec.lean | 0 .../{ => Scaffolds}/Safe/SpecSyntax.lean | 2 +- .../{ => Scaffolds}/Safe/contracts/Safe.sol | 0 .../{ => Scaffolds}/Safe/contracts/SafeL2.sol | 0 .../accessors/SimulateTxAccessor.sol | 0 .../Safe/contracts/base/Executor.sol | 0 .../Safe/contracts/base/FallbackManager.sol | 0 .../Safe/contracts/base/GuardManager.sol | 0 .../Safe/contracts/base/ModuleManager.sol | 0 .../Safe/contracts/base/OwnerManager.sol | 0 .../Safe/contracts/common/EIP7702.sol | 0 .../Safe/contracts/common/EIP7951.sol | 0 .../Safe/contracts/common/ErrorMessage.sol | 0 .../common/NativeCurrencyPaymentFallback.sol | 0 .../common/SecuredSignatureValidator.sol | 0 .../contracts/common/SecuredTokenTransfer.sol | 0 .../Safe/contracts/common/SelfAuthorized.sol | 0 .../contracts/common/SignatureDecoder.sol | 0 .../Safe/contracts/common/Singleton.sol | 0 .../contracts/common/StorageAccessible.sol | 0 .../Safe/contracts/examples/README.md | 0 .../contracts/examples/guards/BaseGuard.sol | 0 .../examples/guards/DebugTransactionGuard.sol | 0 .../guards/DelegateCallTransactionGuard.sol | 0 .../examples/guards/OnlyOwnersGuard.sol | 0 .../guards/ReentrancyTransactionGuard.sol | 0 .../libraries/Migrate_1_3_0_to_1_2_0.sol | 0 .../Safe/contracts/external/SafeMath.sol | 0 .../handler/CompatibilityFallbackHandler.sol | 0 .../handler/ExtensibleFallbackHandler.sol | 0 .../Safe/contracts/handler/HandlerContext.sol | 0 .../handler/TokenCallbackHandler.sol | 0 .../handler/extensible/ERC165Handler.sol | 0 .../handler/extensible/ExtensibleBase.sol | 0 .../handler/extensible/FallbackHandler.sol | 0 .../handler/extensible/MarshalLib.sol | 0 .../extensible/SignatureVerifierMuxer.sol | 0 .../handler/extensible/TokenCallbacks.sol | 0 .../interfaces/ERC1155TokenReceiver.sol | 0 .../interfaces/ERC721TokenReceiver.sol | 0 .../interfaces/ERC777TokensRecipient.sol | 0 .../Safe/contracts/interfaces/Enum.sol | 0 .../Safe/contracts/interfaces/IERC165.sol | 0 .../contracts/interfaces/IFallbackManager.sol | 0 .../contracts/interfaces/IGuardManager.sol | 0 .../contracts/interfaces/IModuleManager.sol | 0 .../INativeCurrencyPaymentFallback.sol | 0 .../contracts/interfaces/IOwnerManager.sol | 0 .../Safe/contracts/interfaces/ISafe.sol | 0 .../interfaces/ISignatureValidator.sol | 0 .../interfaces/IStorageAccessible.sol | 0 .../interfaces/ViewStorageAccessible.sol | 0 .../Safe/contracts/libraries/CreateCall.sol | 0 .../Safe/contracts/libraries/MultiSend.sol | 0 .../contracts/libraries/MultiSendCallOnly.sol | 0 .../contracts/libraries/SafeMigration.sol | 0 .../Safe/contracts/libraries/SafeStorage.sol | 0 .../contracts/libraries/SafeToL2Setup.sol | 0 .../contracts/libraries/SignMessageLib.sol | 0 .../Safe/contracts/proxies/SafeProxy.sol | 0 .../contracts/proxies/SafeProxyFactory.sol | 0 .../Safe/contracts/test/DelegateCaller.sol | 0 .../Safe/contracts/test/ERC1155Token.sol | 0 .../Safe/contracts/test/ERC20Token.sol | 0 .../Safe/contracts/test/ERC721Token.sol | 0 .../test/Test4337ModuleAndHandler.sol | 0 .../Safe/contracts/test/TestHandler.sol | 0 .../Safe/contracts/test/TestImports.sol | 0 .../Safe/contracts/test/TestMarshalLib.sol | 0 .../test/TestNativeTokenReceiver.sol | 0 .../test/TestSafeSignatureVerifier.sol | 0 Benchmarks/{ => Scaffolds}/Safe/creation.hex | 0 Benchmarks/{ => Scaffolds}/Safe/runtime.hex | 0 .../{ => Scaffolds}/Safe/sources.sha256 | 0 .../TimelockController/Bytecode.lean | 2 +- .../TimelockController/Common.lean | 2 +- .../TimelockController/Constructor.lean | 21 + .../Scaffolds/TimelockController/Correct.lean | 24 + .../TimelockController/README.md | 0 .../TimelockController/Spec.lean | 0 .../TimelockController/SpecSyntax.lean | 2 +- .../TimelockControllerBench.abi.json | 0 .../TimelockControllerBench.sol | 0 .../TimelockControllerBench.storage.json | 0 .../TimelockController/Trusted.lean | 2 +- .../TimelockController/creation.hex | 0 .../TimelockController/runtime.hex | 0 .../TimelockController/sources.sha256 | 0 .../contracts/libraries/TransferHelper.sol | 0 .../interfaces/IUniswapV2Factory.sol | 0 .../contracts/interfaces/IUniswapV2Pair.sol | 0 .../UniswapV2Router02/Bytecode.lean | 2 +- .../UniswapV2Router02/Constructor.lean | 2 +- .../UniswapV2Router02/Correct.lean | 2 +- .../UniswapV2Router02/Immutables.lean | 0 .../UniswapV2Router02/README.md | 0 .../UniswapV2Router02/Spec.lean | 2 +- .../UniswapV2Router02/SpecSyntax.lean | 2 +- .../UniswapV2Router02.abi.json | 0 .../UniswapV2Router02.sol.ast.json | 0 .../contracts/UniswapV2Router02.sol | 0 .../contracts/interfaces/IERC20.sol | 0 .../interfaces/IUniswapV2Router01.sol | 0 .../interfaces/IUniswapV2Router02.sol | 0 .../contracts/interfaces/IWETH.sol | 0 .../contracts/libraries/SafeMath.sol | 0 .../contracts/libraries/UniswapV2Library.sol | 0 .../UniswapV2Router02/creation.hex | 0 .../UniswapV2Router02/runtime.hex | 0 .../UniswapV2Router02/sources.sha256 | 0 .../UniswapV3Pool/Bytecode.lean | 2 +- .../UniswapV3Pool/Constructor.lean | 2 +- .../Scaffolds/UniswapV3Pool/Correct.lean | 26 + .../UniswapV3Pool/Immutables.lean | 0 .../{ => Scaffolds}/UniswapV3Pool/README.md | 0 .../{ => Scaffolds}/UniswapV3Pool/Spec.lean | 2 +- .../UniswapV3Pool/SpecSyntax.lean | 2 +- .../UniswapV3Pool/Trusted.lean | 2 +- .../UniswapV3Pool/UniswapV3Pool.abi.json | 0 .../contracts/NoDelegateCall.sol | 0 .../contracts/UniswapV3Factory.sol | 0 .../UniswapV3Pool/contracts/UniswapV3Pool.sol | 0 .../contracts/UniswapV3PoolDeployer.sol | 0 .../contracts/interfaces/IERC20Minimal.sol | 0 .../interfaces/IUniswapV3Factory.sol | 0 .../contracts/interfaces/IUniswapV3Pool.sol | 0 .../interfaces/IUniswapV3PoolDeployer.sol | 0 .../contracts/interfaces/LICENSE | 0 .../callback/IUniswapV3FlashCallback.sol | 0 .../callback/IUniswapV3MintCallback.sol | 0 .../callback/IUniswapV3SwapCallback.sol | 0 .../interfaces/pool/IUniswapV3PoolActions.sol | 0 .../pool/IUniswapV3PoolDerivedState.sol | 0 .../interfaces/pool/IUniswapV3PoolEvents.sol | 0 .../pool/IUniswapV3PoolImmutables.sol | 0 .../pool/IUniswapV3PoolOwnerActions.sol | 0 .../interfaces/pool/IUniswapV3PoolState.sol | 0 .../contracts/libraries/BitMath.sol | 0 .../contracts/libraries/FixedPoint128.sol | 0 .../contracts/libraries/FixedPoint96.sol | 0 .../contracts/libraries/FullMath.sol | 0 .../UniswapV3Pool/contracts/libraries/LICENSE | 0 .../contracts/libraries/LICENSE_MIT | 0 .../contracts/libraries/LiquidityMath.sol | 0 .../contracts/libraries/LowGasSafeMath.sol | 0 .../contracts/libraries/Oracle.sol | 0 .../contracts/libraries/Position.sol | 0 .../contracts/libraries/SafeCast.sol | 0 .../contracts/libraries/SqrtPriceMath.sol | 0 .../contracts/libraries/SwapMath.sol | 0 .../contracts/libraries/Tick.sol | 0 .../contracts/libraries/TickBitmap.sol | 0 .../contracts/libraries/TickMath.sol | 0 .../contracts/libraries/TransferHelper.sol | 0 .../contracts/libraries/UnsafeMath.sol | 0 .../contracts/test/BitMathEchidnaTest.sol | 0 .../contracts/test/BitMathTest.sol | 0 .../contracts/test/FullMathEchidnaTest.sol | 0 .../contracts/test/FullMathTest.sol | 0 .../contracts/test/LiquidityMathTest.sol | 0 .../test/LowGasSafeMathEchidnaTest.sol | 0 .../contracts/test/MockTimeUniswapV3Pool.sol | 0 .../test/MockTimeUniswapV3PoolDeployer.sol | 0 .../contracts/test/NoDelegateCallTest.sol | 0 .../contracts/test/OracleEchidnaTest.sol | 0 .../contracts/test/OracleTest.sol | 0 .../test/SqrtPriceMathEchidnaTest.sol | 0 .../contracts/test/SqrtPriceMathTest.sol | 0 .../contracts/test/SwapMathEchidnaTest.sol | 0 .../contracts/test/SwapMathTest.sol | 0 .../contracts/test/TestERC20.sol | 0 .../contracts/test/TestUniswapV3Callee.sol | 0 .../test/TestUniswapV3ReentrantCallee.sol | 0 .../contracts/test/TestUniswapV3Router.sol | 0 .../contracts/test/TestUniswapV3SwapPay.sol | 0 .../contracts/test/TickBitmapEchidnaTest.sol | 0 .../contracts/test/TickBitmapTest.sol | 0 .../contracts/test/TickEchidnaTest.sol | 0 .../contracts/test/TickMathEchidnaTest.sol | 0 .../contracts/test/TickMathTest.sol | 0 .../test/TickOverflowSafetyEchidnaTest.sol | 0 .../UniswapV3Pool/contracts/test/TickTest.sol | 0 .../contracts/test/UniswapV3PoolSwapTest.sol | 0 .../contracts/test/UnsafeMathEchidnaTest.sol | 0 .../UniswapV3Pool/creation.hex | 0 .../{ => Scaffolds}/UniswapV3Pool/runtime.hex | 0 .../UniswapV3Pool/sources.sha256 | 0 .../VestingWallet/Bytecode.lean | 2 +- .../VestingWallet/Constructor.lean | 2 +- .../VestingWallet/Correct.lean | 2 +- .../VestingWallet/Spec.lean | 0 .../VestingWallet/SpecSyntax.lean | 2 +- .../VestingWallet/VestingWalletBench.abi.json | 0 .../VestingWallet/VestingWalletBench.sol | 0 .../VestingWalletBench.storage.json | 0 .../VestingWallet/creation.hex | 0 .../VestingWallet/runtime.hex | 0 .../VestingWallet/sources.sha256 | 0 Benchmarks/UniswapV3Pool/Burn.lean | 1970 ---- .../UniswapV3Pool/BurnAfterCheckTicks.lean | 1993 ---- .../UniswapV3Pool/BurnAfterFeeGlobals.lean | 1946 ---- .../BurnAfterFeeGrowthInside.lean | 295 - Benchmarks/UniswapV3Pool/BurnBody.lean | 2000 ---- Benchmarks/UniswapV3Pool/BurnCheckTicks.lean | 1940 ---- .../UniswapV3Pool/BurnFullMathSlow.lean | 955 -- .../UniswapV3Pool/BurnLiquidityAddDelta.lean | 213 - .../BurnLowerLiquidityAddDeltaRevert.lean | 456 - Benchmarks/UniswapV3Pool/BurnNoDelegate.lean | 217 - .../UniswapV3Pool/BurnNonzeroDeltaStart.lean | 1555 --- .../UniswapV3Pool/BurnObserveSingle.lean | 1434 --- .../UniswapV3Pool/BurnPositionUpdate.lean | 1875 ---- .../BurnPositionUpdateMemory.lean | 174 - .../BurnPositionUpdatePostReturn.lean | 1900 ---- .../BurnPositionUpdateRevert.lean | 226 - .../BurnPositionUpdateSlowPostReturn.lean | 555 - .../BurnPositionUpdateSource.lean | 1831 ---- .../BurnPositionUpdateSourceSuccess.lean | 1907 ---- .../BurnPositionUpdateTokensOwedBridge.lean | 1207 --- .../BurnPositionUpdateTokensOwedPacking.lean | 551 - .../BurnPositionUpdateTokensOwedStore.lean | 786 -- .../UniswapV3Pool/BurnPostPositionUpdate.lean | 1147 -- .../UniswapV3Pool/BurnSourceSuccess.lean | 1214 --- .../BurnTickGetFeeGrowthInsideSource.lean | 1097 -- .../UniswapV3Pool/BurnTickUpdateSource.lean | 1150 -- .../UniswapV3Pool/BurnTickUpdateStart.lean | 581 - .../UniswapV3Pool/BurnTickUpdateTrace.lean | 1753 ---- .../UniswapV3Pool/BurnZeroDeltaFinish.lean | 621 -- .../BurnZeroDeltaMulDivStart.lean | 247 - .../BurnZeroDeltaSlowToken0.lean | 311 - Benchmarks/UniswapV3Pool/Collect.lean | 18 - Benchmarks/UniswapV3Pool/CollectProtocol.lean | 18 - Benchmarks/UniswapV3Pool/Common.lean | 1998 ---- Benchmarks/UniswapV3Pool/Correct.lean | 177 - Benchmarks/UniswapV3Pool/Factory.lean | 177 - Benchmarks/UniswapV3Pool/Fee.lean | 483 - .../UniswapV3Pool/FeeGrowthGlobal0X128.lean | 218 - .../UniswapV3Pool/FeeGrowthGlobal1X128.lean | 225 - Benchmarks/UniswapV3Pool/Flash.lean | 18 - Benchmarks/UniswapV3Pool/Functions.lean | 26 - .../UniswapV3Pool/ImmutableGetters.lean | 244 - .../IncreaseObservationCardinalityNext.lean | 1995 ---- ...ncreaseObservationCardinalityNextBase.lean | 1298 --- ...ncreaseObservationCardinalityNextGrow.lean | 1697 --- ...aseObservationCardinalityNextGrowLoop.lean | 1615 --- ...aseObservationCardinalityNextGrowTail.lean | 251 - Benchmarks/UniswapV3Pool/Initialize.lean | 494 - Benchmarks/UniswapV3Pool/InitializeBase.lean | 1755 ---- .../UniswapV3Pool/InitializeGetTick.lean | 1430 --- .../UniswapV3Pool/InitializeGetTickLog.lean | 1309 --- .../InitializeGetTickLog2Bridge.lean | 131 - .../InitializeGetTickLogCombine.lean | 1754 ---- .../InitializeGetTickReturn.lean | 295 - .../InitializeGetTickSqrtRatio.lean | 1068 -- .../InitializeGetTickSqrtRatioBits.lean | 1799 ---- .../InitializeGetTickSqrtRatioBitsHigh.lean | 1815 ---- .../InitializeGetTickSqrtRatioFull.lean | 721 -- .../InitializeGetTickSqrtRatioNonzero.lean | 1767 ---- .../InitializeGetTickSqrtRatioReturn.lean | 1100 -- ...nitializeGetTickSqrtRatioSourceBridge.lean | 986 -- .../InitializeGetTickWordBridge.lean | 1839 ---- .../InitializeSourceGetSqrtRatio.lean | 838 -- .../InitializeSourceGetSqrtRatioHighBits.lean | 1493 --- .../InitializeSourceGetSqrtRatioLowBits.lean | 911 -- .../InitializeSourceGetTickLog.lean | 599 -- .../InitializeSourceGetTickLogRemaining.lean | 649 -- .../InitializeSourceGetTickLogStep60.lean | 94 - .../InitializeSourceGetTickLogStep61.lean | 362 - .../InitializeSourceGetTickLogStep62.lean | 382 - .../InitializeSourceGetTickMsb.lean | 1473 --- .../InitializeSourceGetTickPostLog.lean | 1120 -- .../InitializeSourceStorageEquiv.lean | 1939 ---- .../InitializeSourceSuccess.lean | 1892 ---- .../UniswapV3Pool/InitializeSuccess.lean | 1548 --- Benchmarks/UniswapV3Pool/Liquidity.lean | 474 - Benchmarks/UniswapV3Pool/Locking.lean | 290 - .../UniswapV3Pool/MaxLiquidityPerTick.lean | 393 - Benchmarks/UniswapV3Pool/Mint.lean | 18 - Benchmarks/UniswapV3Pool/NoDelegateCall.lean | 780 -- Benchmarks/UniswapV3Pool/Observations.lean | 1740 --- .../UniswapV3Pool/ObservationsInt56.lean | 379 - Benchmarks/UniswapV3Pool/Observe.lean | 18 - Benchmarks/UniswapV3Pool/Positions.lean | 1915 ---- Benchmarks/UniswapV3Pool/ProtocolFees.lean | 724 -- Benchmarks/UniswapV3Pool/SetFeeProtocol.lean | 1873 ---- .../SetFeeProtocolFeeProtocolCheck.lean | 1667 --- .../SetFeeProtocolOwnerCall.lean | 1714 --- .../UniswapV3Pool/SetFeeProtocolSource.lean | 820 -- .../UniswapV3Pool/SetFeeProtocolSuccess.lean | 1672 --- Benchmarks/UniswapV3Pool/Slot0.lean | 1904 ---- .../SnapshotCumulativesInside.lean | 18 - Benchmarks/UniswapV3Pool/Swap.lean | 18 - Benchmarks/UniswapV3Pool/TickBitmap.lean | 988 -- Benchmarks/UniswapV3Pool/TickSpacing.lean | 1400 --- Benchmarks/UniswapV3Pool/Ticks.lean | 1970 ---- Benchmarks/UniswapV3Pool/TicksInt128.lean | 424 - .../UniswapV3Pool/TicksReturnMemory.lean | 433 - Benchmarks/UniswapV3Pool/Token0.lean | 279 - Benchmarks/UniswapV3Pool/Token1.lean | 281 - Benchmarks/UniswapV3Pool/Uint128.lean | 86 - Examples.lean | 2 + Examples/README.md | 45 + 528 files changed, 354 insertions(+), 192531 deletions(-) delete mode 100644 Benchmarks/CompoundIII/CometRewards/Claim.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/ClaimTo.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/Common.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/Constructor.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/Correct.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/GetRewardOwed.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/Governor.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/RewardConfig.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/RewardsClaimed.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/Scratch.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/SetRewardConfig.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/SetRewardConfigWithMultiplier.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/SetRewardsClaimed.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/TransferGovernor.lean delete mode 100644 Benchmarks/CompoundIII/CometRewards/WithdrawToken.lean delete mode 100644 Benchmarks/EAS/Attester/Attest.lean delete mode 100644 Benchmarks/EAS/Attester/Common.lean delete mode 100644 Benchmarks/EAS/Attester/Constructor.lean delete mode 100644 Benchmarks/EAS/Attester/Correct.lean delete mode 100644 Benchmarks/EAS/Attester/DynamicArray.lean delete mode 100644 Benchmarks/EAS/Attester/InnerArray.lean delete mode 100644 Benchmarks/EAS/Attester/InnerArrayCopy.lean delete mode 100644 Benchmarks/EAS/Attester/InnerArrayEVM.lean delete mode 100644 Benchmarks/EAS/Attester/InnerArrayInit.lean delete mode 100644 Benchmarks/EAS/Attester/MultiAttest.lean delete mode 100644 Benchmarks/EAS/Attester/MultiRevoke.lean delete mode 100644 Benchmarks/EAS/Attester/MultiRevokeContinuation.lean delete mode 100644 Benchmarks/EAS/Attester/MultiRevokeEVM.lean delete mode 100644 Benchmarks/EAS/Attester/MultiRevokeEncoderABI.lean delete mode 100644 Benchmarks/EAS/Attester/MultiRevokeEncoderExact.lean delete mode 100644 Benchmarks/EAS/Attester/MultiRevokeEncoderLayout.lean delete mode 100644 Benchmarks/EAS/Attester/MultiRevokeLoopRun.lean delete mode 100644 Benchmarks/EAS/Attester/MultiRevokeMemory.lean delete mode 100644 Benchmarks/EAS/Attester/MultiRevokePostCall.lean delete mode 100644 Benchmarks/EAS/Attester/MultiRevokePostLoop.lean delete mode 100644 Benchmarks/EAS/Attester/MultiRevokeProgress.lean delete mode 100644 Benchmarks/EAS/Attester/MultiSource.lean delete mode 100644 Benchmarks/EAS/Attester/NestedArray.lean delete mode 100644 Benchmarks/EAS/Attester/OuterArrayInit.lean delete mode 100644 Benchmarks/EAS/Attester/Revoke.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/AbiDecode.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/AbiEncode.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/Body.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/Cancel.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/CancellerRole.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/Constructor.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/ConstructorDefs.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/ConstructorEvm.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/ConstructorSolm.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/Correct.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/DefaultAdminRole.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/Dispatch.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/EvmExec.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/EvmReach.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/EvmReverts.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/Execute.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/ExecuteBatch.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/ExecutorRole.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/Fallback.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/GetMinDelay.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/GetOperationState.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/GetRoleAdmin.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/GetTimestamp.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/GrantRole.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/HasRole.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/HashOperation.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/HashOperationBatch.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/IsOperation.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/IsOperationDone.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/IsOperationPending.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/IsOperationReady.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155BatchReceived.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155Received.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/OnERC721Received.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/ProposerRole.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/Receivers.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/RenounceRole.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/Return.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/RevokeRole.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/Routines.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/Schedule.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/ScheduleBatch.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/ScratchGrant.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/SolmDispatch.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/Storage.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/SupportsInterface.lean delete mode 100644 Benchmarks/OpenZeppelinBench/TimelockController/UpdateDelay.lean create mode 100644 Benchmarks/Scaffolds.lean rename Benchmarks/{ => Scaffolds}/Auction/Bytecode.lean (99%) rename Benchmarks/{ => Scaffolds}/Auction/Constructor.lean (91%) rename Benchmarks/{ => Scaffolds}/Auction/Correct.lean (93%) rename Benchmarks/{ => Scaffolds}/Auction/NounsAuctionHouse.abi.json (100%) rename Benchmarks/{ => Scaffolds}/Auction/NounsAuctionHouse.sol (100%) rename Benchmarks/{ => Scaffolds}/Auction/NounsAuctionHouse.storage.json (100%) rename Benchmarks/{ => Scaffolds}/Auction/Spec.lean (100%) rename Benchmarks/{ => Scaffolds}/Auction/SpecSyntax.lean (99%) rename Benchmarks/{ => Scaffolds}/Auction/creation.hex (100%) rename Benchmarks/{ => Scaffolds}/Auction/interfaces/INounsAuctionHouse.sol (100%) rename Benchmarks/{ => Scaffolds}/Auction/interfaces/INounsDescriptorMinimal.sol (100%) rename Benchmarks/{ => Scaffolds}/Auction/interfaces/INounsSeeder.sol (100%) rename Benchmarks/{ => Scaffolds}/Auction/interfaces/INounsToken.sol (100%) rename Benchmarks/{ => Scaffolds}/Auction/interfaces/IWETH.sol (100%) rename Benchmarks/{ => Scaffolds}/Auction/runtime.hex (100%) rename Benchmarks/{ => Scaffolds}/Auction/sources.sha256 (100%) rename Benchmarks/{ => Scaffolds}/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol (100%) rename Benchmarks/{ => Scaffolds}/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol (100%) rename Benchmarks/{ => Scaffolds}/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/security/PausableUpgradeable.sol (100%) rename Benchmarks/{ => Scaffolds}/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/security/ReentrancyGuardUpgradeable.sol (100%) rename Benchmarks/{ => Scaffolds}/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol (100%) rename Benchmarks/{ => Scaffolds}/Auction/vendor/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol (100%) rename Benchmarks/{ => Scaffolds}/Auction/vendor/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol (100%) rename Benchmarks/{ => Scaffolds}/Auction/vendor/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol (100%) rename Benchmarks/{CompoundIII => Scaffolds}/Comet/Bytecode.lean (99%) rename Benchmarks/{CompoundIII => Scaffolds}/Comet/CometWithExtendedAssetList.abi.json (100%) rename Benchmarks/{CompoundIII => Scaffolds}/Comet/CometWithExtendedAssetList.sol.ast.json (100%) rename Benchmarks/{CompoundIII => Scaffolds}/Comet/CometWithExtendedAssetList.storage.json (100%) rename Benchmarks/{CompoundIII => Scaffolds}/Comet/Constructor.lean (93%) rename Benchmarks/{CompoundIII => Scaffolds}/Comet/Correct.lean (96%) rename Benchmarks/{CompoundIII => Scaffolds}/Comet/Immutables.lean (100%) rename Benchmarks/{CompoundIII => Scaffolds}/Comet/README.md (100%) rename Benchmarks/{CompoundIII => Scaffolds}/Comet/Spec.lean (99%) rename Benchmarks/{CompoundIII => Scaffolds}/Comet/SpecSyntax.lean (99%) rename Benchmarks/{CompoundIII => Scaffolds}/Comet/creation.hex (100%) rename Benchmarks/{CompoundIII => Scaffolds}/Comet/runtime.hex (100%) rename Benchmarks/{CompoundIII => Scaffolds}/CometRewards/Bytecode.lean (99%) rename Benchmarks/{CompoundIII => Scaffolds}/CometRewards/CometRewards.abi.json (100%) rename Benchmarks/{CompoundIII => Scaffolds}/CometRewards/CometRewards.sol.ast.json (100%) rename Benchmarks/{CompoundIII => Scaffolds}/CometRewards/CometRewards.storage.json (100%) create mode 100644 Benchmarks/Scaffolds/CometRewards/Constructor.lean create mode 100644 Benchmarks/Scaffolds/CometRewards/Correct.lean rename Benchmarks/{CompoundIII => Scaffolds}/CometRewards/README.md (100%) rename Benchmarks/{CompoundIII => Scaffolds}/CometRewards/Spec.lean (100%) rename Benchmarks/{CompoundIII => Scaffolds}/CometRewards/SpecSyntax.lean (99%) rename Benchmarks/{CompoundIII => Scaffolds}/CometRewards/Trusted.lean (98%) rename Benchmarks/{CompoundIII => Scaffolds}/CometRewards/creation.hex (100%) rename Benchmarks/{CompoundIII => Scaffolds}/CometRewards/runtime.hex (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/README.md (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/CometConfiguration.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/CometCore.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/CometExtInterface.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/CometInterface.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/CometMainInterface.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/CometMath.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/CometRewards.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/CometStorage.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/CometWithExtendedAssetList.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/interfaces/ERC20.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/interfaces/IAssetList.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/interfaces/IAssetListFactory.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/interfaces/IAssetListFactoryHolder.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/interfaces/IERC20NonStandard.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/contracts/interfaces/IPriceFeed.sol (100%) rename Benchmarks/{ => Scaffolds}/CompoundIII/sources.sha256 (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/Attester.abi.json (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/Attester.sol.ast.json (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/Attester.storage.json (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/Bytecode.lean (99%) create mode 100644 Benchmarks/Scaffolds/EAS/Attester/Constructor.lean create mode 100644 Benchmarks/Scaffolds/EAS/Attester/Correct.lean rename Benchmarks/{ => Scaffolds}/EAS/Attester/Immutables.lean (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/README.md (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/Spec.lean (99%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/SpecSyntax.lean (98%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/Trusted.lean (96%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/Common.sol (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/IEAS.sol (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/ISchemaRegistry.sol (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/ISemver.sol (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/resolver/ISchemaResolver.sol (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/contracts/Attester.sol (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/creation.hex (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/runtime.hex (100%) rename Benchmarks/{ => Scaffolds}/EAS/Attester/sources.sha256 (100%) rename Benchmarks/{ => Scaffolds}/ERC721/Bytecode.lean (99%) rename Benchmarks/{ => Scaffolds}/ERC721/Constructor.lean (91%) rename Benchmarks/{ => Scaffolds}/ERC721/Correct.lean (98%) rename Benchmarks/{ => Scaffolds}/ERC721/ERC721.abi.json (100%) rename Benchmarks/{ => Scaffolds}/ERC721/ERC721.sol (100%) rename Benchmarks/{ => Scaffolds}/ERC721/ERC721.storage.json (100%) rename Benchmarks/{ => Scaffolds}/ERC721/Spec.lean (100%) rename Benchmarks/{ => Scaffolds}/ERC721/SpecSyntax.lean (98%) rename Benchmarks/{ => Scaffolds}/ERC721/creation.hex (100%) rename Benchmarks/{ => Scaffolds}/ERC721/runtime.hex (100%) rename Benchmarks/{ => Scaffolds}/ERC721/sources.sha256 (100%) rename Benchmarks/{ => Scaffolds}/Klima/Bytecode.lean (99%) rename Benchmarks/{ => Scaffolds}/Klima/Constructor.lean (93%) rename Benchmarks/{ => Scaffolds}/Klima/Correct.lean (94%) rename Benchmarks/{ => Scaffolds}/Klima/KlimaToken.abi.json (100%) rename Benchmarks/{ => Scaffolds}/Klima/KlimaToken.storage.json (100%) rename Benchmarks/{ => Scaffolds}/Klima/README.md (100%) rename Benchmarks/{ => Scaffolds}/Klima/Spec.lean (99%) rename Benchmarks/{ => Scaffolds}/Klima/SpecSyntax.lean (99%) rename Benchmarks/{ => Scaffolds}/Klima/StringLayout.lean (100%) rename Benchmarks/{ => Scaffolds}/Klima/contracts/KlimaToken.sol (100%) rename Benchmarks/{ => Scaffolds}/Klima/creation.hex (100%) rename Benchmarks/{ => Scaffolds}/Klima/runtime.hex (100%) rename Benchmarks/{ => Scaffolds}/Klima/sources.sha256 (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/AccessControl.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/IAccessControl.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/Ownable.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/finance/VestingWallet.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/governance/TimelockController.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC1363.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC165.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC20.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC20Metadata.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC1155/IERC1155Receiver.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC1155/utils/ERC1155Holder.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC721/utils/ERC721Holder.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Address.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Context.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Errors.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/LowLevelCall.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol (100%) rename Benchmarks/{ => Scaffolds}/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/Bytecode.lean (99%) rename Benchmarks/{ => Scaffolds}/Safe/Constructor.lean (91%) rename Benchmarks/{ => Scaffolds}/Safe/Correct.lean (93%) rename Benchmarks/{ => Scaffolds}/Safe/README.md (100%) rename Benchmarks/{ => Scaffolds}/Safe/Safe.abi.json (100%) rename Benchmarks/{ => Scaffolds}/Safe/Spec.lean (100%) rename Benchmarks/{ => Scaffolds}/Safe/SpecSyntax.lean (99%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/Safe.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/SafeL2.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/accessors/SimulateTxAccessor.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/base/Executor.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/base/FallbackManager.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/base/GuardManager.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/base/ModuleManager.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/base/OwnerManager.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/common/EIP7702.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/common/EIP7951.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/common/ErrorMessage.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/common/NativeCurrencyPaymentFallback.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/common/SecuredSignatureValidator.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/common/SecuredTokenTransfer.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/common/SelfAuthorized.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/common/SignatureDecoder.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/common/Singleton.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/common/StorageAccessible.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/examples/README.md (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/examples/guards/BaseGuard.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/examples/guards/DebugTransactionGuard.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/examples/guards/DelegateCallTransactionGuard.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/examples/guards/OnlyOwnersGuard.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/examples/guards/ReentrancyTransactionGuard.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/examples/libraries/Migrate_1_3_0_to_1_2_0.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/external/SafeMath.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/handler/CompatibilityFallbackHandler.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/handler/ExtensibleFallbackHandler.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/handler/HandlerContext.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/handler/TokenCallbackHandler.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/handler/extensible/ERC165Handler.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/handler/extensible/ExtensibleBase.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/handler/extensible/FallbackHandler.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/handler/extensible/MarshalLib.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/handler/extensible/SignatureVerifierMuxer.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/handler/extensible/TokenCallbacks.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/ERC1155TokenReceiver.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/ERC721TokenReceiver.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/ERC777TokensRecipient.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/Enum.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/IERC165.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/IFallbackManager.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/IGuardManager.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/IModuleManager.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/INativeCurrencyPaymentFallback.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/IOwnerManager.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/ISafe.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/ISignatureValidator.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/IStorageAccessible.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/interfaces/ViewStorageAccessible.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/libraries/CreateCall.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/libraries/MultiSend.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/libraries/MultiSendCallOnly.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/libraries/SafeMigration.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/libraries/SafeStorage.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/libraries/SafeToL2Setup.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/libraries/SignMessageLib.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/proxies/SafeProxy.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/proxies/SafeProxyFactory.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/test/DelegateCaller.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/test/ERC1155Token.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/test/ERC20Token.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/test/ERC721Token.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/test/Test4337ModuleAndHandler.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/test/TestHandler.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/test/TestImports.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/test/TestMarshalLib.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/test/TestNativeTokenReceiver.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/contracts/test/TestSafeSignatureVerifier.sol (100%) rename Benchmarks/{ => Scaffolds}/Safe/creation.hex (100%) rename Benchmarks/{ => Scaffolds}/Safe/runtime.hex (100%) rename Benchmarks/{ => Scaffolds}/Safe/sources.sha256 (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/TimelockController/Bytecode.lean (99%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/TimelockController/Common.lean (98%) create mode 100644 Benchmarks/Scaffolds/TimelockController/Constructor.lean create mode 100644 Benchmarks/Scaffolds/TimelockController/Correct.lean rename Benchmarks/{OpenZeppelinBench => Scaffolds}/TimelockController/README.md (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/TimelockController/Spec.lean (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/TimelockController/SpecSyntax.lean (99%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/TimelockController/TimelockControllerBench.abi.json (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/TimelockController/TimelockControllerBench.sol (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/TimelockController/TimelockControllerBench.storage.json (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/TimelockController/Trusted.lean (99%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/TimelockController/creation.hex (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/TimelockController/runtime.hex (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/TimelockController/sources.sha256 (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/@uniswap/lib/contracts/libraries/TransferHelper.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/Bytecode.lean (99%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/Constructor.lean (93%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/Correct.lean (95%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/Immutables.lean (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/README.md (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/Spec.lean (99%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/SpecSyntax.lean (99%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/UniswapV2Router02.abi.json (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/UniswapV2Router02.sol.ast.json (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/contracts/UniswapV2Router02.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/contracts/interfaces/IERC20.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/contracts/interfaces/IUniswapV2Router01.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/contracts/interfaces/IUniswapV2Router02.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/contracts/interfaces/IWETH.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/contracts/libraries/SafeMath.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/contracts/libraries/UniswapV2Library.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/creation.hex (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/runtime.hex (100%) rename Benchmarks/{ => Scaffolds}/UniswapV2Router02/sources.sha256 (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/Bytecode.lean (99%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/Constructor.lean (93%) create mode 100644 Benchmarks/Scaffolds/UniswapV3Pool/Correct.lean rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/Immutables.lean (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/README.md (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/Spec.lean (99%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/SpecSyntax.lean (99%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/Trusted.lean (98%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/UniswapV3Pool.abi.json (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/NoDelegateCall.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/UniswapV3Factory.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/UniswapV3Pool.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/UniswapV3PoolDeployer.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/IERC20Minimal.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/IUniswapV3Factory.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/IUniswapV3Pool.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/IUniswapV3PoolDeployer.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/LICENSE (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3FlashCallback.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3MintCallback.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3SwapCallback.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolActions.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolDerivedState.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolEvents.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolState.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/BitMath.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/FixedPoint128.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/FixedPoint96.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/FullMath.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/LICENSE (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/LICENSE_MIT (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/LiquidityMath.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/LowGasSafeMath.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/Oracle.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/Position.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/SafeCast.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/SqrtPriceMath.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/SwapMath.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/Tick.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/TickBitmap.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/TickMath.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/TransferHelper.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/libraries/UnsafeMath.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/BitMathEchidnaTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/BitMathTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/FullMathEchidnaTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/FullMathTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/LiquidityMathTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/LowGasSafeMathEchidnaTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/MockTimeUniswapV3Pool.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/MockTimeUniswapV3PoolDeployer.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/NoDelegateCallTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/OracleEchidnaTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/OracleTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/SqrtPriceMathEchidnaTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/SqrtPriceMathTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/SwapMathEchidnaTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/SwapMathTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/TestERC20.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/TestUniswapV3Callee.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/TestUniswapV3ReentrantCallee.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/TestUniswapV3Router.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/TestUniswapV3SwapPay.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/TickBitmapEchidnaTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/TickBitmapTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/TickEchidnaTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/TickMathEchidnaTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/TickMathTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/TickOverflowSafetyEchidnaTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/TickTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/UniswapV3PoolSwapTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/contracts/test/UnsafeMathEchidnaTest.sol (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/creation.hex (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/runtime.hex (100%) rename Benchmarks/{ => Scaffolds}/UniswapV3Pool/sources.sha256 (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/VestingWallet/Bytecode.lean (99%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/VestingWallet/Constructor.lean (90%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/VestingWallet/Correct.lean (92%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/VestingWallet/Spec.lean (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/VestingWallet/SpecSyntax.lean (98%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/VestingWallet/VestingWalletBench.abi.json (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/VestingWallet/VestingWalletBench.sol (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/VestingWallet/VestingWalletBench.storage.json (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/VestingWallet/creation.hex (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/VestingWallet/runtime.hex (100%) rename Benchmarks/{OpenZeppelinBench => Scaffolds}/VestingWallet/sources.sha256 (100%) delete mode 100644 Benchmarks/UniswapV3Pool/Burn.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnAfterCheckTicks.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnAfterFeeGlobals.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnAfterFeeGrowthInside.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnBody.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnCheckTicks.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnFullMathSlow.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnLiquidityAddDelta.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnLowerLiquidityAddDeltaRevert.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnNoDelegate.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnNonzeroDeltaStart.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnObserveSingle.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnPositionUpdate.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnPositionUpdateMemory.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnPositionUpdatePostReturn.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnPositionUpdateRevert.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnPositionUpdateSlowPostReturn.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnPositionUpdateSource.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnPositionUpdateSourceSuccess.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedBridge.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedPacking.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedStore.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnPostPositionUpdate.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnSourceSuccess.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnTickGetFeeGrowthInsideSource.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnTickUpdateSource.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnTickUpdateStart.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnTickUpdateTrace.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnZeroDeltaFinish.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnZeroDeltaMulDivStart.lean delete mode 100644 Benchmarks/UniswapV3Pool/BurnZeroDeltaSlowToken0.lean delete mode 100644 Benchmarks/UniswapV3Pool/Collect.lean delete mode 100644 Benchmarks/UniswapV3Pool/CollectProtocol.lean delete mode 100644 Benchmarks/UniswapV3Pool/Common.lean delete mode 100644 Benchmarks/UniswapV3Pool/Correct.lean delete mode 100644 Benchmarks/UniswapV3Pool/Factory.lean delete mode 100644 Benchmarks/UniswapV3Pool/Fee.lean delete mode 100644 Benchmarks/UniswapV3Pool/FeeGrowthGlobal0X128.lean delete mode 100644 Benchmarks/UniswapV3Pool/FeeGrowthGlobal1X128.lean delete mode 100644 Benchmarks/UniswapV3Pool/Flash.lean delete mode 100644 Benchmarks/UniswapV3Pool/Functions.lean delete mode 100644 Benchmarks/UniswapV3Pool/ImmutableGetters.lean delete mode 100644 Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNext.lean delete mode 100644 Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextBase.lean delete mode 100644 Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrow.lean delete mode 100644 Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowLoop.lean delete mode 100644 Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowTail.lean delete mode 100644 Benchmarks/UniswapV3Pool/Initialize.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeBase.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeGetTick.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeGetTickLog.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeGetTickLog2Bridge.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeGetTickLogCombine.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeGetTickReturn.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatio.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBits.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBitsHigh.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioFull.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioNonzero.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioReturn.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioSourceBridge.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeGetTickWordBridge.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatio.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioHighBits.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioLowBits.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeSourceGetTickLog.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogRemaining.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep60.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep61.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep62.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeSourceGetTickMsb.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeSourceGetTickPostLog.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeSourceStorageEquiv.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeSourceSuccess.lean delete mode 100644 Benchmarks/UniswapV3Pool/InitializeSuccess.lean delete mode 100644 Benchmarks/UniswapV3Pool/Liquidity.lean delete mode 100644 Benchmarks/UniswapV3Pool/Locking.lean delete mode 100644 Benchmarks/UniswapV3Pool/MaxLiquidityPerTick.lean delete mode 100644 Benchmarks/UniswapV3Pool/Mint.lean delete mode 100644 Benchmarks/UniswapV3Pool/NoDelegateCall.lean delete mode 100644 Benchmarks/UniswapV3Pool/Observations.lean delete mode 100644 Benchmarks/UniswapV3Pool/ObservationsInt56.lean delete mode 100644 Benchmarks/UniswapV3Pool/Observe.lean delete mode 100644 Benchmarks/UniswapV3Pool/Positions.lean delete mode 100644 Benchmarks/UniswapV3Pool/ProtocolFees.lean delete mode 100644 Benchmarks/UniswapV3Pool/SetFeeProtocol.lean delete mode 100644 Benchmarks/UniswapV3Pool/SetFeeProtocolFeeProtocolCheck.lean delete mode 100644 Benchmarks/UniswapV3Pool/SetFeeProtocolOwnerCall.lean delete mode 100644 Benchmarks/UniswapV3Pool/SetFeeProtocolSource.lean delete mode 100644 Benchmarks/UniswapV3Pool/SetFeeProtocolSuccess.lean delete mode 100644 Benchmarks/UniswapV3Pool/Slot0.lean delete mode 100644 Benchmarks/UniswapV3Pool/SnapshotCumulativesInside.lean delete mode 100644 Benchmarks/UniswapV3Pool/Swap.lean delete mode 100644 Benchmarks/UniswapV3Pool/TickBitmap.lean delete mode 100644 Benchmarks/UniswapV3Pool/TickSpacing.lean delete mode 100644 Benchmarks/UniswapV3Pool/Ticks.lean delete mode 100644 Benchmarks/UniswapV3Pool/TicksInt128.lean delete mode 100644 Benchmarks/UniswapV3Pool/TicksReturnMemory.lean delete mode 100644 Benchmarks/UniswapV3Pool/Token0.lean delete mode 100644 Benchmarks/UniswapV3Pool/Token1.lean delete mode 100644 Benchmarks/UniswapV3Pool/Uint128.lean create mode 100644 Examples/README.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c42f603c..662b385d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,16 +45,15 @@ jobs: Examples.OpenZeppelinBench.AccessControl.Correct \ Examples.OpenZeppelinBench.Pausable.Correct \ Examples.OpenZeppelinBench.ERC6909.Correct \ - Examples.UniswapV2Pair.Correct + Examples.UniswapV2Pair.Correct \ + Examples.Reuse.Correct \ + Examples.VyperERC20.Correct # Mirrors the imports of Benchmarks.lean. Remove lines to prune. - name: Build benchmarks run: | lake build \ Benchmarks.WETH9.Correct \ - Benchmarks.Safe.Correct \ - Benchmarks.UniswapV3Pool.Correct \ - Benchmarks.UniswapV2Router02.Correct \ Benchmarks.Dss.Dai.Correct \ Benchmarks.Dss.Jug.Correct \ Benchmarks.Dss.Vat.Correct \ @@ -73,12 +72,8 @@ jobs: Benchmarks.Dss.Flipper.Correct \ Benchmarks.Dss.Flopper.Correct \ Benchmarks.Dss.GemJoin.Correct \ - Benchmarks.Dss.DaiJoin.Correct \ - Benchmarks.CompoundIII.CometRewards.Correct \ - Benchmarks.CompoundIII.Comet.Correct \ - Benchmarks.EAS.Attester.Correct \ - Benchmarks.ERC721.Correct \ - Benchmarks.Auction.Correct \ - Benchmarks.OpenZeppelinBench.VestingWallet.Correct \ - Benchmarks.OpenZeppelinBench.TimelockController.Correct \ - Benchmarks.Klima.Correct + Benchmarks.Dss.DaiJoin.Correct + + # Scaffolded benchmarks: specs + bytecode compile, proofs are sorry stubs. + - name: Build benchmark scaffolds + run: lake build Benchmarks.Scaffolds diff --git a/Benchmarks.lean b/Benchmarks.lean index 2bc98cba..d2e64bfd 100644 --- a/Benchmarks.lean +++ b/Benchmarks.lean @@ -1,7 +1,4 @@ import Benchmarks.WETH9.Correct -import Benchmarks.Safe.Correct -import Benchmarks.UniswapV3Pool.Correct -import Benchmarks.UniswapV2Router02.Correct import Benchmarks.Dss.Dai.Correct import Benchmarks.Dss.Jug.Correct import Benchmarks.Dss.Vat.Correct @@ -21,11 +18,3 @@ import Benchmarks.Dss.Flipper.Correct import Benchmarks.Dss.Flopper.Correct import Benchmarks.Dss.GemJoin.Correct import Benchmarks.Dss.DaiJoin.Correct -import Benchmarks.CompoundIII.CometRewards.Correct -import Benchmarks.CompoundIII.Comet.Correct -import Benchmarks.EAS.Attester.Correct -import Benchmarks.ERC721.Correct -import Benchmarks.Auction.Correct -import Benchmarks.OpenZeppelinBench.VestingWallet.Correct -import Benchmarks.OpenZeppelinBench.TimelockController.Correct -import Benchmarks.Klima.Correct diff --git a/Benchmarks/CompoundIII/CometRewards/Claim.lean b/Benchmarks/CompoundIII/CometRewards/Claim.lean deleted file mode 100644 index 1e635e0a..00000000 --- a/Benchmarks/CompoundIII/CometRewards/Claim.lean +++ /dev/null @@ -1,6566 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.Common -import Benchmarks.CompoundIII.CometRewards.GetRewardOwed -import Benchmarks.CompoundIII.CometRewards.WithdrawToken - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace Benchmarks.CompoundIII.CometRewards - -end Benchmarks.CompoundIII.CometRewards - -theorem Reasoning.Reach.swap9_xstep {s : State} {code : ByteArray} - {pcv a b c d e f gg hh ii jj : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.SWAP9, .none)) - (hstk : s.machineState.stack = a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: t) - (hov : t.length + 10 ≤ 1024) : - Xstep (D_J code 0) s = - (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok (stSwap s (jj :: b :: c :: d :: e :: f :: gg :: hh :: ii :: a :: t), - .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.SWAP9, .none) := by - rw [hcode, hpc] - exact hdec - rw [← hcode, step_swap9 s hd, hstk] - have hov' : - ¬ ((a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: t).length - 10 - + 10 > 1024) := by - simp only [List.length_cons] - omega - simp only [if_neg hov', GasConstants.Gverylow, stSwap] - -theorem Reasoning.Reach.RD.swap9 - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d e f gg hh ii jj : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: t) - mem aw rdata acc k C) - (hdec : decode code pc = some (.SWAP9, .none)) (hov : t.length + 10 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (jj :: b :: c :: d :: e :: f :: gg :: hh :: ii :: a :: t) - mem aw rdata acc (k + 1) (C + 3) := - h.stepSwap (fun _ hc hp hs => Reasoning.Reach.swap9_xstep hc hp hdec hs hov) - -namespace Benchmarks.CompoundIII.CometRewards - -/-! ## `claim(address,address,bool)` ABI setup -/ - -abbrev claimCometWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -abbrev claimSrcWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 36 - -abbrev claimShouldAccrueWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 68 - -abbrev claimCometValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (claimCometWord I).toNat) - -abbrev claimSrcValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (claimSrcWord I).toNat) - -abbrev claimShouldAccrueValue (I : ExecutionEnv) : Value := - wordToElem .bool (claimShouldAccrueWord I) - -abbrev claimStore (I : ExecutionEnv) : Store := - (((∅ : Store).insert "comet" (claimCometValue I)).insert "src" - (claimSrcValue I)).insert "shouldAccrue" (claimShouldAccrueValue I) - -abbrev claimFrame (evm : EVM.State) (I : ExecutionEnv) : Frame := - { contract := contract, - locals := (claimStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) } - -abbrev claimArgs (I : ExecutionEnv) : List Value := - [claimCometValue I, claimSrcValue I, claimShouldAccrueValue I] - -abbrev claimInternalArgs (I : ExecutionEnv) : List Value := - [claimCometValue I, claimSrcValue I, claimSrcValue I, claimShouldAccrueValue I] - -abbrev claimInternalStore (I : ExecutionEnv) : Store := - ((((∅ : Store).insert "shouldAccrue" (claimShouldAccrueValue I)).insert "to" - (claimSrcValue I)).insert "src" (claimSrcValue I)).insert "comet" (claimCometValue I) - -abbrev claimInternalAfterTokenLocals (evm : EVM.State) (I : ExecutionEnv) : Store := - (claimInternalStore I).insert "token" - (getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I)) - -abbrev claimInternalAfterRescaleLocals (evm : EVM.State) (I : ExecutionEnv) : Store := - (claimInternalAfterTokenLocals evm I).insert "rescaleFactor" - (getRewardOwedRescaleValueFromSlot0 (getRewardOwedSlot0Load evm I)) - -abbrev claimInternalAfterShouldLocals (evm : EVM.State) (I : ExecutionEnv) : Store := - (claimInternalAfterRescaleLocals evm I).insert "shouldUpscale" - (getRewardOwedShouldUpscaleValueFromSlot0 (getRewardOwedSlot0Load evm I)) - -abbrev claimInternalConfigLocals (evm : EVM.State) (I : ExecutionEnv) : Store := - (claimInternalAfterShouldLocals evm I).insert "multiplier" - (getRewardOwedMultiplierValue (getRewardOwedMultiplierLoad evm I)) - -abbrev claimInternalAfterClaimedLocals - (evm evmClaimed : EVM.State) (I : ExecutionEnv) : Store := - (claimInternalConfigLocals evm I).insert "claimed" - (.int (Int.ofNat (getRewardOwedClaimedLoad evmClaimed I).toNat)) - -abbrev claimInternalAfterInternalLocals - (evm evmClaimed : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : Store := - (claimInternalAfterClaimedLocals evm evmClaimed I).insert "accrued" - (.int (Int.ofNat accruedNat)) - -abbrev claimInternalOwedNat (evmClaimed : EVM.State) (I : ExecutionEnv) - (accruedNat : ℕ) : ℕ := - accruedNat - (getRewardOwedClaimedLoad evmClaimed I).toNat - -abbrev claimInternalAfterOwedLocals - (evm evmClaimed : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : Store := - (claimInternalAfterInternalLocals evm evmClaimed I accruedNat).insert "owed" - (.int (Int.ofNat (claimInternalOwedNat evmClaimed I accruedNat))) - -abbrev claimTransferTarget (slot0 : UInt256) : AccountAddress := - AccountAddress.ofNat (rewardConfigTokenFromSlot0 slot0).toNat - -abbrev claimTransferArgs (I : ExecutionEnv) (amount : UInt256) : List Value := - [claimSrcValue I, .int (Int.ofNat amount.toNat)] - -abbrev claimDoTransferOutStore - (I : ExecutionEnv) (slot0 amount : UInt256) : Store := - (((∅ : Store).insert "amount" (.int (Int.ofNat amount.toNat))).insert "to" - (claimSrcValue I)).insert "token" (getRewardOwedTokenValueFromSlot0 slot0) - -abbrev claimTransferCallStore (I : ExecutionEnv) (slot0 amount : UInt256) - (success : Bool) : Store := - (claimDoTransferOutStore I slot0 amount).insert "success" (.bool success) - -theorem claimStore_comet (I : ExecutionEnv) : - (claimStore I).get? "comet" = some (claimCometValue I) := by - rw [claimStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), store_get_self] - -theorem claimStore_src (I : ExecutionEnv) : - (claimStore I).get? "src" = some (claimSrcValue I) := by - rw [claimStore, store_get_ne _ _ (by decide), store_get_self] - -theorem claimStore_shouldAccrue (I : ExecutionEnv) : - (claimStore I).get? "shouldAccrue" = some (claimShouldAccrueValue I) := by - rw [claimStore, store_get_self] - -theorem claimFrame_comet (evm : EVM.State) (I : ExecutionEnv) : - (claimFrame evm I).locals.get? "comet" = some (claimCometValue I) := by - rw [claimFrame] - rw [store_get_ne _ _ (by decide), claimStore_comet] - -theorem claimFrame_src (evm : EVM.State) (I : ExecutionEnv) : - (claimFrame evm I).locals.get? "src" = some (claimSrcValue I) := by - rw [claimFrame] - rw [store_get_ne _ _ (by decide), claimStore_src] - -theorem claimFrame_shouldAccrue (evm : EVM.State) (I : ExecutionEnv) : - (claimFrame evm I).locals.get? "shouldAccrue" = some (claimShouldAccrueValue I) := by - rw [claimFrame] - rw [store_get_ne _ _ (by decide), claimStore_shouldAccrue] - -theorem evalExpr_claim_comet_of {locals : Store} (evm : EVM.State) (I : ExecutionEnv) - (hcomet : locals.get? "comet" = some (claimCometValue I)) : - evalExpr? config { contract := contract, locals := locals } evm (.var "comet") = - .ok (claimCometValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hcomet] - -theorem evalExpr_claim_src_of {locals : Store} (evm : EVM.State) (I : ExecutionEnv) - (hsrc : locals.get? "src" = some (claimSrcValue I)) : - evalExpr? config { contract := contract, locals := locals } evm (.var "src") = - .ok (claimSrcValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hsrc] - -theorem evalExpr_claim_shouldAccrue_of {locals : Store} (evm : EVM.State) - (I : ExecutionEnv) - (hshould : locals.get? "shouldAccrue" = some (claimShouldAccrueValue I)) : - evalExpr? config { contract := contract, locals := locals } evm (.var "shouldAccrue") = - .ok (claimShouldAccrueValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hshould] - -theorem evalExprs_claim_internalArgs_frame (evm : EVM.State) (I : ExecutionEnv) : - evalExprs? config (claimFrame evm I) evm - [.var "comet", .var "src", .var "src", .var "shouldAccrue"] = - .ok (claimInternalArgs I) := by - simp only [claimInternalArgs, evalExprs?, evalExpr_claim_comet_of evm I - (claimFrame_comet evm I), evalExpr_claim_src_of evm I (claimFrame_src evm I), - evalExpr_claim_shouldAccrue_of evm I (claimFrame_shouldAccrue evm I), - EvalResult.bind, bind] - rfl - -theorem bindParams_claimInternal (I : ExecutionEnv) : - bindParams? claimInternalFunction.params (claimInternalArgs I) = - some (claimInternalStore I) := by - simp [claimInternalFunction, claimInternalArgs, claimCometValue, claimSrcValue, - claimShouldAccrueValue, claimInternalStore, bindParams?] - -theorem lookupCallable_claimInternal : - lookupCallable? contract "claimInternal" = some claimInternalFunction.toCallable := by - rfl - -theorem claimInternalStore_comet (I : ExecutionEnv) : - (claimInternalStore I).get? "comet" = some (claimCometValue I) := by - rw [claimInternalStore, store_get_self] - -theorem claimInternalStore_src (I : ExecutionEnv) : - (claimInternalStore I).get? "src" = some (claimSrcValue I) := by - rw [claimInternalStore, store_get_ne _ _ (by decide), store_get_self] - -theorem claimInternalStore_shouldAccrue (I : ExecutionEnv) : - (claimInternalStore I).get? "shouldAccrue" = some (claimShouldAccrueValue I) := by - rw [claimInternalStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_self] - -theorem claimInternalStore_no_rewardConfig (I : ExecutionEnv) : - (claimInternalStore I).get? "rewardConfig" = none := by - rw [claimInternalStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - simp - -theorem claimInternalAfterTokenLocals_comet (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalAfterTokenLocals evm I).get? "comet" = some (claimCometValue I) := by - rw [claimInternalAfterTokenLocals, store_get_ne _ _ (by decide), - claimInternalStore_comet] - -theorem claimInternalAfterTokenLocals_no_rewardConfig - (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalAfterTokenLocals evm I).get? "rewardConfig" = none := by - rw [claimInternalAfterTokenLocals, store_get_ne _ _ (by decide), - claimInternalStore_no_rewardConfig] - -theorem claimInternalAfterRescaleLocals_comet (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalAfterRescaleLocals evm I).get? "comet" = some (claimCometValue I) := by - rw [claimInternalAfterRescaleLocals, store_get_ne _ _ (by decide), - claimInternalAfterTokenLocals_comet] - -theorem claimInternalAfterRescaleLocals_no_rewardConfig - (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalAfterRescaleLocals evm I).get? "rewardConfig" = none := by - rw [claimInternalAfterRescaleLocals, store_get_ne _ _ (by decide), - claimInternalAfterTokenLocals_no_rewardConfig] - -theorem claimInternalAfterShouldLocals_comet (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalAfterShouldLocals evm I).get? "comet" = some (claimCometValue I) := by - rw [claimInternalAfterShouldLocals, store_get_ne _ _ (by decide), - claimInternalAfterRescaleLocals_comet] - -theorem claimInternalAfterShouldLocals_no_rewardConfig - (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalAfterShouldLocals evm I).get? "rewardConfig" = none := by - rw [claimInternalAfterShouldLocals, store_get_ne _ _ (by decide), - claimInternalAfterRescaleLocals_no_rewardConfig] - -theorem claimInternalConfigLocals_token (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalConfigLocals evm I).get? "token" = - some (getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [claimInternalConfigLocals, store_get_ne _ _ (by decide), - claimInternalAfterShouldLocals, store_get_ne _ _ (by decide), - claimInternalAfterRescaleLocals, store_get_ne _ _ (by decide), - claimInternalAfterTokenLocals, store_get_self] - -theorem claimInternalConfigLocals_comet (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalConfigLocals evm I).get? "comet" = some (claimCometValue I) := by - rw [claimInternalConfigLocals, store_get_ne _ _ (by decide), - claimInternalAfterShouldLocals_comet] - -theorem claimInternalConfigLocals_src (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalConfigLocals evm I).get? "src" = some (claimSrcValue I) := by - rw [claimInternalConfigLocals, claimInternalAfterShouldLocals, - claimInternalAfterRescaleLocals, claimInternalAfterTokenLocals] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - exact claimInternalStore_src I - -theorem claimInternalConfigLocals_rescaleFactor (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalConfigLocals evm I).get? "rescaleFactor" = - some (getRewardOwedRescaleValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [claimInternalConfigLocals, claimInternalAfterShouldLocals, - claimInternalAfterRescaleLocals] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), store_get_self] - -theorem claimInternalConfigLocals_shouldUpscale (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalConfigLocals evm I).get? "shouldUpscale" = - some (getRewardOwedShouldUpscaleValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [claimInternalConfigLocals, claimInternalAfterShouldLocals] - rw [store_get_ne _ _ (by decide), store_get_self] - -theorem claimInternalConfigLocals_multiplier (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalConfigLocals evm I).get? "multiplier" = - some (getRewardOwedMultiplierValue (getRewardOwedMultiplierLoad evm I)) := by - rw [claimInternalConfigLocals, store_get_self] - -theorem claimInternalConfigLocals_shouldAccrue (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalConfigLocals evm I).get? "shouldAccrue" = - some (claimShouldAccrueValue I) := by - rw [claimInternalConfigLocals, claimInternalAfterShouldLocals, - claimInternalAfterRescaleLocals, claimInternalAfterTokenLocals] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - exact claimInternalStore_shouldAccrue I - -theorem claimInternalConfigLocals_no_rewardsClaimed (evm : EVM.State) (I : ExecutionEnv) : - (claimInternalConfigLocals evm I).get? "rewardsClaimed" = none := by - rw [claimInternalConfigLocals, claimInternalAfterShouldLocals, - claimInternalAfterRescaleLocals, claimInternalAfterTokenLocals] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - rw [claimInternalStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - simp - -theorem claimInternalAfterClaimedLocals_comet - (evm evmClaimed : EVM.State) (I : ExecutionEnv) : - (claimInternalAfterClaimedLocals evm evmClaimed I).get? "comet" = - some (claimCometValue I) := by - rw [claimInternalAfterClaimedLocals, store_get_ne _ _ (by decide), - claimInternalConfigLocals_comet] - -theorem claimInternalAfterClaimedLocals_src - (evm evmClaimed : EVM.State) (I : ExecutionEnv) : - (claimInternalAfterClaimedLocals evm evmClaimed I).get? "src" = - some (claimSrcValue I) := by - rw [claimInternalAfterClaimedLocals, store_get_ne _ _ (by decide), - claimInternalConfigLocals_src] - -theorem claimInternalAfterClaimedLocals_rescaleFactor - (evm evmClaimed : EVM.State) (I : ExecutionEnv) : - (claimInternalAfterClaimedLocals evm evmClaimed I).get? "rescaleFactor" = - some (getRewardOwedRescaleValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [claimInternalAfterClaimedLocals, store_get_ne _ _ (by decide), - claimInternalConfigLocals_rescaleFactor] - -theorem claimInternalAfterClaimedLocals_shouldUpscale - (evm evmClaimed : EVM.State) (I : ExecutionEnv) : - (claimInternalAfterClaimedLocals evm evmClaimed I).get? "shouldUpscale" = - some (getRewardOwedShouldUpscaleValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [claimInternalAfterClaimedLocals, store_get_ne _ _ (by decide), - claimInternalConfigLocals_shouldUpscale] - -theorem claimInternalAfterClaimedLocals_multiplier - (evm evmClaimed : EVM.State) (I : ExecutionEnv) : - (claimInternalAfterClaimedLocals evm evmClaimed I).get? "multiplier" = - some (getRewardOwedMultiplierValue (getRewardOwedMultiplierLoad evm I)) := by - rw [claimInternalAfterClaimedLocals, store_get_ne _ _ (by decide), - claimInternalConfigLocals_multiplier] - -theorem claimInternalAfterInternalLocals_accrued - (evm evmClaimed : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (claimInternalAfterInternalLocals evm evmClaimed I accruedNat).get? "accrued" = - some (.int (Int.ofNat accruedNat)) := by - rw [claimInternalAfterInternalLocals, store_get_self] - -theorem claimInternalAfterInternalLocals_claimed - (evm evmClaimed : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (claimInternalAfterInternalLocals evm evmClaimed I accruedNat).get? "claimed" = - some (.int (Int.ofNat (getRewardOwedClaimedLoad evmClaimed I).toNat)) := by - rw [claimInternalAfterInternalLocals, store_get_ne _ _ (by decide)] - rw [claimInternalAfterClaimedLocals, store_get_self] - -theorem claimInternalAfterInternalLocals_comet - (evm evmClaimed : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (claimInternalAfterInternalLocals evm evmClaimed I accruedNat).get? "comet" = - some (claimCometValue I) := by - rw [claimInternalAfterInternalLocals, store_get_ne _ _ (by decide), - claimInternalAfterClaimedLocals_comet] - -theorem claimInternalAfterInternalLocals_src - (evm evmClaimed : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (claimInternalAfterInternalLocals evm evmClaimed I accruedNat).get? "src" = - some (claimSrcValue I) := by - rw [claimInternalAfterInternalLocals, store_get_ne _ _ (by decide), - claimInternalAfterClaimedLocals_src] - -theorem claimInternalAfterInternalLocals_token - (evm evmClaimed : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (claimInternalAfterInternalLocals evm evmClaimed I accruedNat).get? "token" = - some (getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [claimInternalAfterInternalLocals, store_get_ne _ _ (by decide)] - rw [claimInternalAfterClaimedLocals, store_get_ne _ _ (by decide), - claimInternalConfigLocals_token] - -theorem claimInternalAfterInternalLocals_no_rewardsClaimed - (evm evmClaimed : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (claimInternalAfterInternalLocals evm evmClaimed I accruedNat).get? "rewardsClaimed" = - none := by - rw [claimInternalAfterInternalLocals, store_get_ne _ _ (by decide)] - rw [claimInternalAfterClaimedLocals, store_get_ne _ _ (by decide), - claimInternalConfigLocals_no_rewardsClaimed] - -theorem claimInternalAfterOwedLocals_token - (evm evmClaimed : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (claimInternalAfterOwedLocals evm evmClaimed I accruedNat).get? "token" = - some (getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [claimInternalAfterOwedLocals, store_get_ne _ _ (by decide), - claimInternalAfterInternalLocals_token] - -theorem claimInternalAfterOwedLocals_to - (evm evmClaimed : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (claimInternalAfterOwedLocals evm evmClaimed I accruedNat).get? "to" = - some (claimSrcValue I) := by - rw [claimInternalAfterOwedLocals, store_get_ne _ _ (by decide)] - rw [claimInternalAfterInternalLocals, store_get_ne _ _ (by decide)] - rw [claimInternalAfterClaimedLocals, store_get_ne _ _ (by decide), - claimInternalConfigLocals] - rw [store_get_ne _ _ (by decide), claimInternalAfterShouldLocals] - rw [store_get_ne _ _ (by decide), claimInternalAfterRescaleLocals] - rw [store_get_ne _ _ (by decide), claimInternalAfterTokenLocals] - rw [store_get_ne _ _ (by decide), claimInternalStore] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), store_get_self] - -theorem claimInternalAfterOwedLocals_owed - (evm evmClaimed : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (claimInternalAfterOwedLocals evm evmClaimed I accruedNat).get? "owed" = - some (.int (Int.ofNat (claimInternalOwedNat evmClaimed I accruedNat))) := by - rw [claimInternalAfterOwedLocals, store_get_self] - -theorem claimDoTransferOutStore_token (I : ExecutionEnv) (slot0 amount : UInt256) : - (claimDoTransferOutStore I slot0 amount).get? "token" = - some (getRewardOwedTokenValueFromSlot0 slot0) := by - rw [claimDoTransferOutStore, store_get_self] - -theorem claimDoTransferOutStore_to (I : ExecutionEnv) (slot0 amount : UInt256) : - (claimDoTransferOutStore I slot0 amount).get? "to" = some (claimSrcValue I) := by - rw [claimDoTransferOutStore, store_get_ne _ _ (by decide), store_get_self] - -theorem claimDoTransferOutStore_amount (I : ExecutionEnv) (slot0 amount : UInt256) : - (claimDoTransferOutStore I slot0 amount).get? "amount" = - some (.int (Int.ofNat amount.toNat)) := by - rw [claimDoTransferOutStore, store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_self] - -theorem claimTransferCallStore_success - (I : ExecutionEnv) (slot0 amount : UInt256) (success : Bool) : - (claimTransferCallStore I slot0 amount success).get? "success" = - some (.bool success) := by - rw [claimTransferCallStore, store_get_self] - -theorem evalStorageRef_claim_rewardsClaimed_of {locals : Store} - (evm : EVM.State) (I : ExecutionEnv) - (hcomet : locals.get? "comet" = some (claimCometValue I)) - (hsrc : locals.get? "src" = some (claimSrcValue I)) : - evalStorageRef config { contract := contract, locals := locals } evm - (rewardsClaimedRef (.var "comet") (.var "src")) = - .ok { base := "rewardsClaimed", - steps := [.mindex (.address (AccountAddress.ofNat - (claimCometWord I).toNat)), - .mindex (.address (AccountAddress.ofNat - (claimSrcWord I).toNat))] } := by - simp only [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, rewardsClaimedRef, - evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, valueToKey?, - Std.HashMap.get?_eq_getElem?] - rw [← Std.HashMap.get?_eq_getElem?, hcomet] - rw [← Std.HashMap.get?_eq_getElem?, hsrc] - -theorem evalExpr_claim_claimed_of {locals : Store} (evm : EVM.State) - (I : ExecutionEnv) - (hcomet : locals.get? "comet" = some (claimCometValue I)) - (hsrc : locals.get? "src" = some (claimSrcValue I)) - (hbase : locals.get? "rewardsClaimed" = none) : - evalExpr? config { contract := contract, locals := locals } evm - (.storage (rewardsClaimedRef (.var "comet") (.var "src"))) = - .ok (.int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (getRewardOwedRewardsClaimedSlotOf I)).toNat)) := by - have her := evalStorageRef_claim_rewardsClaimed_of evm I hcomet hsrc - have hty : storageTypeAt? contract.storage - { base := "rewardsClaimed", - steps := [.mindex (.address (AccountAddress.ofNat (claimCometWord I).toNat)), - .mindex (.address (AccountAddress.ofNat (claimSrcWord I).toNat))] } = - some (.elem (.int uint256Int)) := by - simp [storageTypeAt?, contract, storageDecls, List.find?, List.foldlM, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardsClaimed", - steps := [.mindex (.address (AccountAddress.ofNat (claimCometWord I).toNat)), - .mindex (.address (AccountAddress.ofNat (claimSrcWord I).toNat))] } = - fun _ => some (fieldLoc (getRewardOwedRewardsClaimedSlotOf I) 0 32 - (by decide) (.int uint256Int)) := by - rfl - rw [evalExpr_storage_scalar (hbase := hbase) (her := her) (hty := hty) (hloc := hloc)] - congr 1 - exact cometRewardsStorageLocLoad_uint256 evm (getRewardOwedRewardsClaimedSlotOf I) - -theorem evalExpr_claim_claimed_config (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config - { contract := contract, locals := claimInternalConfigLocals evm I } evm - (.storage (rewardsClaimedRef (.var "comet") (.var "src"))) = - .ok (.int (Int.ofNat (getRewardOwedClaimedLoad evm I).toNat)) := by - exact evalExpr_claim_claimed_of evm I - (claimInternalConfigLocals_comet evm I) - (claimInternalConfigLocals_src evm I) - (claimInternalConfigLocals_no_rewardsClaimed evm I) - -theorem evalExprs_claim_getRewardAccrued_args_of {locals : Store} (evm : EVM.State) - (I : ExecutionEnv) (slot0 multiplier : UInt256) - (hcomet : locals.get? "comet" = some (claimCometValue I)) - (hsrc : locals.get? "src" = some (claimSrcValue I)) - (hrescale : - locals.get? "rescaleFactor" = - some (.int (Int.ofNat (rewardConfigRescaleFromSlot0 slot0).toNat))) - (hshould : - locals.get? "shouldUpscale" = - some (wordToElem .bool (rewardConfigShouldUpscaleRawFromSlot0 slot0))) - (hmult : locals.get? "multiplier" = some (.int (Int.ofNat multiplier.toNat))) : - evalExprs? config { contract := contract, locals := locals } evm - [.var "comet", .var "src", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"] = - .ok (getRewardAccruedArgs I slot0 multiplier) := by - simp only [getRewardAccruedArgs, evalExprs?, - evalExpr_claim_comet_of evm I hcomet, - evalExpr_claim_src_of evm I hsrc, EvalResult.bind, bind, - evalExpr?, EvalResult.ofOption] - rw [hrescale, hshould, hmult] - simp [claimCometValue, claimCometWord, claimSrcValue, claimSrcWord, - getRewardOwedCometValue, getRewardOwedCometWord, getRewardOwedAccountValue, - getRewardOwedAccountWord] - rfl - -theorem evalExprs_claim_getRewardAccruedArgs_afterClaimed - (evm evmClaimed : EVM.State) (I : ExecutionEnv) : - evalExprs? config - { contract := contract, locals := claimInternalAfterClaimedLocals evm evmClaimed I } - evmClaimed - [.var "comet", .var "src", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"] = - .ok (getRewardAccruedArgs I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) := by - exact evalExprs_claim_getRewardAccrued_args_of evmClaimed I - (getRewardOwedSlot0Load evm I) (getRewardOwedMultiplierLoad evm I) - (claimInternalAfterClaimedLocals_comet evm evmClaimed I) - (claimInternalAfterClaimedLocals_src evm evmClaimed I) - (claimInternalAfterClaimedLocals_rescaleFactor evm evmClaimed I) - (claimInternalAfterClaimedLocals_shouldUpscale evm evmClaimed I) - (claimInternalAfterClaimedLocals_multiplier evm evmClaimed I) - -theorem evalExpr_claimInternal_shouldAccrue_false - (evm : EVM.State) (I : ExecutionEnv) - (hzero : claimShouldAccrueWord I = ⟨0⟩) : - evalExpr? config { contract := contract, locals := claimInternalConfigLocals evm I } - evm (.var "shouldAccrue") = .ok (.bool false) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [claimInternalConfigLocals_shouldAccrue] - simp [claimShouldAccrueValue, wordToElem, hzero] - -theorem evalExpr_claimInternal_shouldAccrue_true - (evm : EVM.State) (I : ExecutionEnv) - (hone : claimShouldAccrueWord I = ⟨1⟩) : - evalExpr? config { contract := contract, locals := claimInternalConfigLocals evm I } - evm (.var "shouldAccrue") = .ok (.bool true) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [claimInternalConfigLocals_shouldAccrue] - simp [claimShouldAccrueValue, wordToElem, hone] - -theorem evalExpr_claimInternal_accrued_gt_claimed_false - (evm evmClaimed evmRun : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) - (hle : accruedNat ≤ (getRewardOwedClaimedLoad evmClaimed I).toNat) : - evalExpr? config - { contract := contract, locals := claimInternalAfterInternalLocals evm evmClaimed I accruedNat } - evmRun (.binary .gt (.var "accrued") (.var "claimed")) = .ok (.bool false) := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [claimInternalAfterInternalLocals_accrued, - claimInternalAfterInternalLocals_claimed] - have hgtFalse : - ¬ (↑(getRewardOwedClaimedLoad evmClaimed I).toNat : Int) < ↑accruedNat := by - intro hgt - exact (not_lt_of_ge hle) (by exact_mod_cast hgt) - simp [evalBinaryOp?, hgtFalse] - -theorem evalExpr_claimInternal_accrued_gt_claimed_true - (evm evmClaimed evmRun : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) - (hlt : (getRewardOwedClaimedLoad evmClaimed I).toNat < accruedNat) : - evalExpr? config - { contract := contract, locals := claimInternalAfterInternalLocals evm evmClaimed I accruedNat } - evmRun (.binary .gt (.var "accrued") (.var "claimed")) = .ok (.bool true) := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [claimInternalAfterInternalLocals_accrued, - claimInternalAfterInternalLocals_claimed] - have hgtTrue : - (↑(getRewardOwedClaimedLoad evmClaimed I).toNat : Int) < ↑accruedNat := by - exact_mod_cast hlt - simp [evalBinaryOp?, hgtTrue] - -theorem evalExpr_claimInternal_owed_at - (evm evmClaimed evmRun : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) - (hlt : (getRewardOwedClaimedLoad evmClaimed I).toNat < accruedNat) : - evalExpr? config - { contract := contract, locals := claimInternalAfterInternalLocals evm evmClaimed I accruedNat } - evmRun (.binary .sub (.var "accrued") (.var "claimed")) = - .ok (.int (Int.ofNat (claimInternalOwedNat evmClaimed I accruedNat))) := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [claimInternalAfterInternalLocals_accrued, - claimInternalAfterInternalLocals_claimed] - have hsub : - (↑accruedNat - ↑(getRewardOwedClaimedLoad evmClaimed I).toNat : Int) = - ↑(accruedNat - (getRewardOwedClaimedLoad evmClaimed I).toNat) := by - omega - simp [evalBinaryOp?, claimInternalOwedNat, hsub] - -theorem evalExprs_claim_transferArgs_afterOwed - (evm evmClaimed evmRun : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) - {amount : UInt256} - (hamount : amount.toNat = claimInternalOwedNat evmClaimed I accruedNat) : - evalExprs? config - { contract := contract, locals := claimInternalAfterOwedLocals evm evmClaimed I accruedNat } - evmRun [.var "to", .var "owed"] = - .ok (claimTransferArgs I amount) := by - simp only [claimTransferArgs, evalExprs?, evalExpr?, EvalResult.ofOption, - EvalResult.bind, bind] - rw [claimInternalAfterOwedLocals_to, claimInternalAfterOwedLocals_owed] - rw [hamount] - rfl - -theorem evalExpr_claimDoTransferOut_var_token - (evm : EVM.State) (I : ExecutionEnv) (slot0 amount : UInt256) : - evalExpr? config { contract := contract, locals := claimDoTransferOutStore I slot0 amount } - evm (.var "token") = .ok (getRewardOwedTokenValueFromSlot0 slot0) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [claimDoTransferOutStore_token] - -theorem evalExpr_claimDoTransferOut_var_to - (evm : EVM.State) (I : ExecutionEnv) (slot0 amount : UInt256) : - evalExpr? config { contract := contract, locals := claimDoTransferOutStore I slot0 amount } - evm (.var "to") = .ok (claimSrcValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [claimDoTransferOutStore_to] - -theorem evalExpr_claimDoTransferOut_var_amount - (evm : EVM.State) (I : ExecutionEnv) (slot0 amount : UInt256) : - evalExpr? config { contract := contract, locals := claimDoTransferOutStore I slot0 amount } - evm (.var "amount") = .ok (.int (Int.ofNat amount.toNat)) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [claimDoTransferOutStore_amount] - -theorem evalExprs_claimDoTransferOut_transfer_args - (evm : EVM.State) (I : ExecutionEnv) (slot0 amount : UInt256) : - evalExprs? config { contract := contract, locals := claimDoTransferOutStore I slot0 amount } - evm [.var "to", .var "amount"] = .ok (claimTransferArgs I amount) := by - simp only [claimTransferArgs, evalExprs?, evalExpr_claimDoTransferOut_var_to, - evalExpr_claimDoTransferOut_var_amount, EvalResult.bind, bind] - rfl - -theorem bindParams_claimDoTransferOut - (I : ExecutionEnv) (slot0 amount : UInt256) : - bindParams? doTransferOutFunction.params - [getRewardOwedTokenValueFromSlot0 slot0, claimSrcValue I, - .int (Int.ofNat amount.toNat)] = - some (claimDoTransferOutStore I slot0 amount) := by - simp [doTransferOutFunction, getRewardOwedTokenValueFromSlot0, claimDoTransferOutStore, - claimSrcValue, bindParams?] - -theorem evalExpr_claimTransfer_success - (evm : EVM.State) (I : ExecutionEnv) (slot0 amount : UInt256) (success : Bool) : - evalExpr? config - { contract := contract, locals := claimTransferCallStore I slot0 amount success } evm - (.var "success") = .ok (.bool success) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [claimTransferCallStore_success] - -theorem assignRewardsClaimed_afterInternal - (evm evmClaimed evmRun : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) - (haccrued : accruedNat < UInt256.size) : - assignStorageRef? config - { contract := contract, locals := claimInternalAfterInternalLocals evm evmClaimed I accruedNat } - evmRun .storage (rewardsClaimedRef (.var "comet") (.var "src")) - (.int (Int.ofNat accruedNat)) = - .ok - ({ contract := contract, - locals := claimInternalAfterInternalLocals evm evmClaimed I accruedNat }, - Solm.EVM.storageStore evmRun evmRun.executionEnv.codeOwner - (getRewardOwedRewardsClaimedSlotOf I) (UInt256.ofNat accruedNat)) := by - let er : EvaledStorageRef := - { base := "rewardsClaimed", - steps := [.mindex (.address (AccountAddress.ofNat (claimCometWord I).toNat)), - .mindex (.address (AccountAddress.ofNat (claimSrcWord I).toNat))] } - let loc : StorageLoc := uint256Loc (getRewardOwedRewardsClaimedSlotOf I) - have her : - evalStorageRef config - { contract := contract, - locals := claimInternalAfterInternalLocals evm evmClaimed I accruedNat } evmRun - (rewardsClaimedRef (.var "comet") (.var "src")) = .ok er := by - simpa [er] using evalStorageRef_claim_rewardsClaimed_of evmRun I - (claimInternalAfterInternalLocals_comet evm evmClaimed I accruedNat) - (claimInternalAfterInternalLocals_src evm evmClaimed I accruedNat) - have hty : - storageTypeAt? contract.storage er = some (.elem (.int uint256Int)) := by - simp [er, storageTypeAt?, contract, storageDecls, List.find?, List.foldlM, - storageTypeStep?] - have hloc : config.storage.layout er = fun _ => some loc := by - rfl - have hstore : - storageLocStore evmRun loc (.int (Int.ofNat accruedNat)) = - some (Solm.EVM.storageStore evmRun evmRun.executionEnv.codeOwner - (getRewardOwedRewardsClaimedSlotOf I) (UInt256.ofNat accruedNat)) := by - have hvalToNat : (UInt256.ofNat accruedNat).toNat = accruedNat := - UInt256.toNat_ofNat_of_lt haccrued - simpa [loc, hvalToNat] using - storageLocStore_uint256 evmRun (getRewardOwedRewardsClaimedSlotOf I) - (UInt256.ofNat accruedNat) - exact assignStorageRef_storage_scalar_value (cfg := config) - (solm := - { contract := contract, locals := claimInternalAfterInternalLocals evm evmClaimed I accruedNat }) - (evm := evmRun) - (evm' := Solm.EVM.storageStore evmRun evmRun.executionEnv.codeOwner - (getRewardOwedRewardsClaimedSlotOf I) (UInt256.ofNat accruedNat)) - (slot := rewardsClaimedRef (.var "comet") (.var "src")) (er := er) - (ty := .elem (.int uint256Int)) (loc := loc) - (value := .int (Int.ofNat accruedNat)) - (claimInternalAfterInternalLocals_no_rewardsClaimed evm evmClaimed I accruedNat) - her hty hloc (by trivial) hstore - -theorem claimDoTransferOutBodyReverts_callFailure - (evm evm' : EVM.State) (I : ExecutionEnv) (slot0 amount : UInt256) {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (claimTransferTarget slot0)) - "transfer" 0 (claimTransferArgs I amount) (false, evm', out) true) : - ExecFuncBody config - { contract := contract, locals := claimDoTransferOutStore I slot0 amount } - evm doTransferOutFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config - { contract := contract, locals := claimDoTransferOutStore I slot0 amount } evm - [ .externalCall (.var "token") "transfer" (.intLit 0) - [.var "to", .var "amount"] "success", - .require (.var "success") ] .reverted - exact ExecBlock.consRevert - (ExecStmt.externalCallFailure - (evalExpr_claimDoTransferOut_var_token evm I slot0 amount) - (by simp [evalExpr?, pure]) - (evalExprs_claimDoTransferOut_transfer_args evm I slot0 amount) - hcall) - -theorem claimDoTransferOutBodyReverts_decode - (evm evm' : EVM.State) (I : ExecutionEnv) (slot0 amount : UInt256) {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (claimTransferTarget slot0)) - "transfer" 0 (claimTransferArgs I amount) (true, evm', out) true) - (hdec : config.externalABI.decode? "transfer" out = none) : - ExecFuncBody config - { contract := contract, locals := claimDoTransferOutStore I slot0 amount } - evm doTransferOutFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config - { contract := contract, locals := claimDoTransferOutStore I slot0 amount } evm - [ .externalCall (.var "token") "transfer" (.intLit 0) - [.var "to", .var "amount"] "success", - .require (.var "success") ] .reverted - exact ExecBlock.consRevert - (ExecStmt.externalCallReturnDecodeRevert - (evalExpr_claimDoTransferOut_var_token evm I slot0 amount) - (by simp [evalExpr?, pure]) - (evalExprs_claimDoTransferOut_transfer_args evm I slot0 amount) - hcall hdec) - -set_option maxHeartbeats 1000000 in -theorem claimDoTransferOutBodyReverts_false - (evm evm' : EVM.State) (I : ExecutionEnv) (slot0 amount : UInt256) {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (claimTransferTarget slot0)) - "transfer" 0 (claimTransferArgs I amount) (true, evm', out) true) - (hdec : config.externalABI.decode? "transfer" out = some [.bool false]) : - ExecFuncBody config - { contract := contract, locals := claimDoTransferOutStore I slot0 amount } - evm doTransferOutFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config - { contract := contract, locals := claimDoTransferOutStore I slot0 amount } evm - [ .externalCall (.var "token") "transfer" (.intLit 0) - [.var "to", .var "amount"] "success", - .require (.var "success") ] .reverted - refine ExecBlock.consNormal - (solm' := - { contract := contract, - locals := (claimDoTransferOutStore I slot0 amount).insert "success" - (collapseReturns [.bool false]) }) - (evm' := evm') ?_ ?_ - · exact ExecStmt.externalCallSuccess - (cfg := config) - (solm := { contract := contract, locals := claimDoTransferOutStore I slot0 amount }) - (evm := evm) - (receiver := .var "token") (target := claimTransferTarget slot0) - (eth := .intLit 0) (sendVal := 0) - (args := [.var "to", .var "amount"]) (argVals := claimTransferArgs I amount) - (name := "transfer") (retVar := "success") - (evm' := evm') (out := out) (perm := true) (value := [.bool false]) - (evalExpr_claimDoTransferOut_var_token evm I slot0 amount) - (by simp [evalExpr?, pure]) - (evalExprs_claimDoTransferOut_transfer_args evm I slot0 amount) - hcall hdec - · simpa [claimTransferCallStore, collapseReturns] using - (ExecBlock.consRevert - (ExecStmt.requireFalse (evalExpr_claimTransfer_success evm' I slot0 amount false))) - -set_option maxHeartbeats 1000000 in -theorem claimDoTransferOutBodyReturns_true - (evm evm' : EVM.State) (I : ExecutionEnv) (slot0 amount : UInt256) {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (claimTransferTarget slot0)) - "transfer" 0 (claimTransferArgs I amount) (true, evm', out) true) - (hdec : config.externalABI.decode? "transfer" out = some [.bool true]) : - ExecFuncBody config - { contract := contract, locals := claimDoTransferOutStore I slot0 amount } - evm doTransferOutFunction.body - (.returned - { contract := contract, locals := claimTransferCallStore I slot0 amount true } - evm' none) := by - refine ExecFuncBody.execBlockOK ?_ - change ExecBlock config - { contract := contract, locals := claimDoTransferOutStore I slot0 amount } evm - [ .externalCall (.var "token") "transfer" (.intLit 0) - [.var "to", .var "amount"] "success", - .require (.var "success") ] - (.ok { contract := contract, locals := claimTransferCallStore I slot0 amount true } evm') - refine ExecBlock.consNormal - (solm' := - { contract := contract, - locals := (claimDoTransferOutStore I slot0 amount).insert "success" - (collapseReturns [.bool true]) }) - (evm' := evm') ?_ ?_ - · exact ExecStmt.externalCallSuccess - (cfg := config) - (solm := { contract := contract, locals := claimDoTransferOutStore I slot0 amount }) - (evm := evm) - (receiver := .var "token") (target := claimTransferTarget slot0) - (eth := .intLit 0) (sendVal := 0) - (args := [.var "to", .var "amount"]) (argVals := claimTransferArgs I amount) - (name := "transfer") (retVar := "success") - (evm' := evm') (out := out) (perm := true) (value := [.bool true]) - (evalExpr_claimDoTransferOut_var_token evm I slot0 amount) - (by simp [evalExpr?, pure]) - (evalExprs_claimDoTransferOut_transfer_args evm I slot0 amount) - hcall hdec - · simpa [claimTransferCallStore, collapseReturns] using - (ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_claimTransfer_success evm' I slot0 amount true)) - ExecBlock.nil) - -/-! ## `claimInternal` reward-config scratch memory -/ - -noncomputable abbrev claimRewardConfigHashMem (I : ExecutionEnv) : ByteArray := - twoWordHashMem (claimCometWord I) ⟨1⟩ solcFreePtrMem - -noncomputable abbrev claimConfigAllocMem (I : ExecutionEnv) : ByteArray := - writeWord (claimRewardConfigHashMem I) 64 (⟨256⟩ : UInt256) - -noncomputable abbrev claimConfigTokenMem (I : ExecutionEnv) (slot0 : UInt256) : ByteArray := - writeWord (claimConfigAllocMem I) 128 (rewardConfigTokenFromSlot0 slot0) - -noncomputable abbrev claimConfigRescaleMem (I : ExecutionEnv) (slot0 : UInt256) : ByteArray := - writeWord (claimConfigTokenMem I slot0) 160 (rewardConfigRescaleFromSlot0 slot0) - -noncomputable abbrev claimConfigShouldMem (I : ExecutionEnv) (slot0 : UInt256) : ByteArray := - writeWord (claimConfigRescaleMem I slot0) 192 (rewardConfigShouldUpscaleFromSlot0 slot0) - -noncomputable abbrev claimConfigMultiplierMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) : ByteArray := - writeWord (claimConfigShouldMem I slot0) 224 multiplier - -noncomputable abbrev claimInvalidRewardConfigSelectorMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) : ByteArray := - writeWord (claimConfigMultiplierMem I slot0 multiplier) 256 - (UInt256.shiftLeft (⟨1311535579⟩ : UInt256) ⟨225⟩) - -noncomputable abbrev claimInvalidRewardConfigArgMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) : ByteArray := - writeWord (claimInvalidRewardConfigSelectorMem I slot0 multiplier) 260 (claimCometWord I) - -noncomputable abbrev claimClaimedInnerHashMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) : ByteArray := - twoWordHashMem (UInt256.land (claimCometWord I) solcAddrMask) ⟨2⟩ - (claimConfigMultiplierMem I slot0 multiplier) - -noncomputable abbrev claimClaimedOuterHashMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) : ByteArray := - twoWordHashMem (UInt256.land (claimSrcWord I) solcAddrMask) - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - (claimClaimedInnerHashMem I slot0 multiplier) - -noncomputable abbrev claimBaseTrackingSelectorMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) : ByteArray := - writeWord (claimClaimedOuterHashMem I slot0 multiplier) 256 - (UInt256.shiftLeft (⟨719776253⟩ : UInt256) ⟨226⟩) - -noncomputable abbrev claimBaseTrackingCalldataMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) : ByteArray := - writeWord (claimBaseTrackingSelectorMem I slot0 multiplier) 260 (claimSrcWord I) - -abbrev claimBaseTrackingCallPc : UInt256 := getRewardOwedBaseTrackingCallPc - -abbrev claimBaseTrackingCallSize : UInt256 := getRewardOwedBaseTrackingCallSize - -abbrev claimBaseTrackingCallAw : UInt256 := UInt256.ofNat 10 - -abbrev claimBaseTrackingPostCallTail (I : ExecutionEnv) (claimed : UInt256) : List UInt256 := - [ ⟨128⟩, - ⟨256⟩, - ⟨3432⟩, - ⟨128⟩, - ⟨0⟩, - claimSrcWord I, - solcAddrMask, - ⟨32⟩, - claimed, - UInt256.land (claimSrcWord I) solcAddrMask, - UInt256.land (claimCometWord I) solcAddrMask, - ⟨64⟩, - ⟨1001⟩, - ⟨64⟩, - ⟨0⟩ ] - -abbrev claimBaseTrackingPostCallStack (I : ExecutionEnv) (z : Bool) (claimed : UInt256) : - List UInt256 := - (if z then ⟨1⟩ else ⟨0⟩) :: claimBaseTrackingPostCallTail I claimed - -noncomputable abbrev claimBaseTrackingPostCallMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut : ByteArray) : ByteArray := - baseOut.write 0 (claimBaseTrackingCalldataMem I slot0 multiplier) 256 - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat - -noncomputable abbrev claimBaseTrackingPostDecodeMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut : ByteArray) : ByteArray := - writeWord (claimBaseTrackingPostCallMem I slot0 multiplier baseOut) 64 - (⟨288⟩ : UInt256) - -abbrev claimRewardsClaimedBaseSlot : UInt256 := - ⟨16344734836896974401298970600416103014985972868941485175496275033332075043944⟩ - -noncomputable abbrev claimTransferInnerHashMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut : ByteArray) : ByteArray := - twoWordHashMem (UInt256.land (claimCometWord I) solcAddrMask) ⟨2⟩ - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - -noncomputable abbrev claimTransferOuterHashMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut : ByteArray) : ByteArray := - twoWordHashMem (UInt256.land (claimSrcWord I) solcAddrMask) - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - (claimTransferInnerHashMem I slot0 multiplier baseOut) - -noncomputable abbrev claimTransferSelectorMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut : ByteArray) : ByteArray := - (UInt256.toByteArray withdrawTokenTransferSelectorShifted).write 0 - (claimTransferOuterHashMem I slot0 multiplier baseOut) 288 32 - -noncomputable abbrev claimTransferArgsMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut : ByteArray) - (recipient : UInt256) : ByteArray := - (UInt256.toByteArray recipient).write 0 - (claimTransferSelectorMem I slot0 multiplier baseOut) 292 32 - -noncomputable abbrev claimTransferCalldataMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut : ByteArray) - (recipient value : UInt256) : ByteArray := - (UInt256.toByteArray value).write 0 - (claimTransferArgsMem I slot0 multiplier baseOut recipient) 324 32 - -abbrev claimTransferCallPc : UInt256 := withdrawTokenTransferCallPc - -abbrev claimTransferCallSize : UInt256 := withdrawTokenTransferCallSize - -abbrev claimTransferCallAw : UInt256 := UInt256.ofNat 12 - -abbrev claimTransferPostCallTail (I : ExecutionEnv) (amount : UInt256) : List UInt256 := - [ ⟨288⟩, - claimSrcWord I, - amount, - ⟨3531⟩, - ⟨128⟩, - solcAddrMask, - claimSrcWord I, - solcAddrMask, - ⟨32⟩, - claimRewardsClaimedBaseSlot, - UInt256.land (claimSrcWord I) solcAddrMask, - amount, - ⟨64⟩, - ⟨1001⟩, - ⟨64⟩, - ⟨0⟩ ] - -abbrev claimTransferPostCallStack (z : Bool) (I : ExecutionEnv) (amount : UInt256) : - List UInt256 := - (if z then ⟨1⟩ else ⟨0⟩) :: claimTransferPostCallTail I amount - -noncomputable abbrev claimTransferPostCallMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut out : ByteArray) - (amount : UInt256) : ByteArray := - out.write 0 - (claimTransferCalldataMem I slot0 multiplier baseOut (claimSrcWord I) amount) - 288 (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat - -abbrev claimTransferPostCallAw : UInt256 := - UInt256.ofNat (MachineState.M claimTransferCallAw.toNat (⟨288⟩ : UInt256).toNat - (⟨32⟩ : UInt256).toNat) - -theorem claimTransferTarget_eq_targetWord (slot0 : UInt256) : - EVM.address (claimTransferTarget slot0) = - AccountAddress.ofUInt256 (UInt256.land solcAddrMask (rewardConfigTokenFromSlot0 slot0)) := by - have hclean : - UInt256.land solcAddrMask (rewardConfigTokenFromSlot0 slot0) = - rewardConfigTokenFromSlot0 slot0 := by - rw [u256_land_comm solcAddrMask (rewardConfigTokenFromSlot0 slot0)] - exact rewardConfigTokenFromSlot0_clean slot0 - rw [hclean, accountAddress_ofUInt256_eq_ofNat_toNat] - apply Fin.ext - simp [claimTransferTarget, EVM.address, EVM.uintN] - exact Nat.mod_eq_of_lt (AccountAddress.ofNat (rewardConfigTokenFromSlot0 slot0).toNat).isLt - -noncomputable abbrev claimBaseTrackingPostShortDecodeMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut : ByteArray) : ByteArray := - (UInt256.toByteArray ((⟨256⟩ : UInt256) + - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat baseOut.size + ⟨31⟩))).write 0 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut) 64 32 - -abbrev claimBaseTrackingPostCallAw : UInt256 := - UInt256.ofNat (MachineState.M - (MachineState.M claimBaseTrackingCallAw.toNat - (⟨256⟩ : UInt256).toNat claimBaseTrackingCallSize.toNat) - (⟨256⟩ : UInt256).toNat (⟨32⟩ : UInt256).toNat) - -abbrev claimBaseTrackingReturnWord (out : ByteArray) : UInt256 := - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) - -theorem claimRewardConfigHashMem_size (I : ExecutionEnv) : - (claimRewardConfigHashMem I).size = 96 := by - unfold claimRewardConfigHashMem - rw [twoWordHashMem_size_of_ge] - · exact solcFreePtrMem_size - · rw [solcFreePtrMem_size] - decide - -theorem claimRewardConfigHashMem_keccakSlot (I : ExecutionEnv) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((claimRewardConfigHashMem I).readWithPadding 0 64))) = - solcMappingSlot ⟨1⟩ (claimCometWord I) := by - unfold claimRewardConfigHashMem - exact twoWordHashMem_solcMappingSlot_of_ge ⟨1⟩ (claimCometWord I) - (by rw [solcFreePtrMem_size]; decide) - -theorem claimRewardConfigHashMem_mload64 (I : ExecutionEnv) : - (if (⟨64⟩ : UInt256).toNat ≥ (claimRewardConfigHashMem I).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 3 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimRewardConfigHashMem I).readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - ⟨128⟩ := by - have hread : - (claimRewardConfigHashMem I).readWithPadding 64 32 = - UInt256.toByteArray (⟨128⟩ : UInt256) := by - simpa [claimRewardConfigHashMem] using - (twoWordHashMem_read64_of_ge (mem := solcFreePtrMem) (key := claimCometWord I) - (slot := ⟨1⟩) (by rw [solcFreePtrMem_size])).trans solcFreePtrMem_read64 - rw [if_neg] - · rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide, hread, - fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - · rw [claimRewardConfigHashMem_size] - native_decide - -theorem claimConfigAllocMem_size (I : ExecutionEnv) : - (claimConfigAllocMem I).size = 96 := by - unfold claimConfigAllocMem - rw [writeWord_size] - · rw [claimRewardConfigHashMem_size] - native_decide - · rw [claimRewardConfigHashMem_size] - native_decide - -theorem claimConfigAllocMem_read64 (I : ExecutionEnv) : - (claimConfigAllocMem I).readWithPadding 64 32 = - UInt256.toByteArray (⟨256⟩ : UInt256) := by - simpa [claimConfigAllocMem] using - writeWord_read_back (claimRewardConfigHashMem I) 64 (⟨256⟩ : UInt256) - (by rw [claimRewardConfigHashMem_size]; native_decide) - -theorem claimConfigTokenMem_size (I : ExecutionEnv) (slot0 : UInt256) : - (claimConfigTokenMem I slot0).size = 160 := by - unfold claimConfigTokenMem - rw [writeWord_size] - · rw [claimConfigAllocMem_size] - native_decide - · rw [claimConfigAllocMem_size] - native_decide - -theorem claimConfigRescaleMem_size (I : ExecutionEnv) (slot0 : UInt256) : - (claimConfigRescaleMem I slot0).size = 192 := by - unfold claimConfigRescaleMem - rw [writeWord_size] - · rw [claimConfigTokenMem_size] - native_decide - · rw [claimConfigTokenMem_size] - native_decide - -theorem claimConfigShouldMem_size (I : ExecutionEnv) (slot0 : UInt256) : - (claimConfigShouldMem I slot0).size = 224 := by - unfold claimConfigShouldMem - rw [writeWord_size] - · rw [claimConfigRescaleMem_size] - native_decide - · rw [claimConfigRescaleMem_size] - native_decide - -theorem claimConfigMultiplierMem_size (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (claimConfigMultiplierMem I slot0 multiplier).size = 256 := by - unfold claimConfigMultiplierMem - rw [writeWord_size] - · rw [claimConfigShouldMem_size] - native_decide - · rw [claimConfigShouldMem_size] - native_decide - -theorem claimConfigTokenMem_read64 (I : ExecutionEnv) (slot0 : UInt256) : - (claimConfigTokenMem I slot0).readWithPadding 64 32 = - UInt256.toByteArray (⟨256⟩ : UInt256) := by - simpa [claimConfigTokenMem] using - writeWord_read_preserved (claimConfigAllocMem I) 128 64 - (rewardConfigTokenFromSlot0 slot0) - (by rw [claimConfigAllocMem_size]; native_decide) - (by - left - rw [claimConfigAllocMem_size] - constructor <;> norm_num) - |>.trans (claimConfigAllocMem_read64 I) - -theorem claimConfigRescaleMem_read64 (I : ExecutionEnv) (slot0 : UInt256) : - (claimConfigRescaleMem I slot0).readWithPadding 64 32 = - UInt256.toByteArray (⟨256⟩ : UInt256) := by - simpa [claimConfigRescaleMem] using - writeWord_read_preserved (claimConfigTokenMem I slot0) 160 64 - (rewardConfigRescaleFromSlot0 slot0) - (by rw [claimConfigTokenMem_size]; native_decide) - (by - left - rw [claimConfigTokenMem_size] - constructor <;> norm_num) - |>.trans (claimConfigTokenMem_read64 I slot0) - -theorem claimConfigShouldMem_read64 (I : ExecutionEnv) (slot0 : UInt256) : - (claimConfigShouldMem I slot0).readWithPadding 64 32 = - UInt256.toByteArray (⟨256⟩ : UInt256) := by - simpa [claimConfigShouldMem] using - writeWord_read_preserved (claimConfigRescaleMem I slot0) 192 64 - (rewardConfigShouldUpscaleFromSlot0 slot0) - (by rw [claimConfigRescaleMem_size]; native_decide) - (by - left - rw [claimConfigRescaleMem_size] - constructor <;> norm_num) - |>.trans (claimConfigRescaleMem_read64 I slot0) - -theorem claimConfigMultiplierMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (claimConfigMultiplierMem I slot0 multiplier).readWithPadding 64 32 = - UInt256.toByteArray (⟨256⟩ : UInt256) := by - simpa [claimConfigMultiplierMem] using - writeWord_read_preserved (claimConfigShouldMem I slot0) 224 64 multiplier - (by rw [claimConfigShouldMem_size]; native_decide) - (by - left - rw [claimConfigShouldMem_size] - constructor <;> norm_num) - |>.trans (claimConfigShouldMem_read64 I slot0) - -theorem claimConfigMultiplierMem_mload64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (claimConfigMultiplierMem I slot0 multiplier).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 8 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimConfigMultiplierMem I slot0 multiplier).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - ⟨256⟩ := by - rw [if_neg] - · rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide, claimConfigMultiplierMem_read64, - fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - · rw [claimConfigMultiplierMem_size] - native_decide - -theorem claimClaimedInnerHashMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (claimClaimedInnerHashMem I slot0 multiplier).readWithPadding 64 32 = - UInt256.toByteArray (⟨256⟩ : UInt256) := by - unfold claimClaimedInnerHashMem - rw [twoWordHashMem_read64_of_ge] - · exact claimConfigMultiplierMem_read64 I slot0 multiplier - · rw [claimConfigMultiplierMem_size] - decide - -theorem claimClaimedInnerHashMem_size_ge256 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - 256 ≤ (claimClaimedInnerHashMem I slot0 multiplier).size := by - unfold claimClaimedInnerHashMem - rw [twoWordHashMem_size_of_ge] - · rw [claimConfigMultiplierMem_size] - · rw [claimConfigMultiplierMem_size] - decide - -theorem claimClaimedOuterHashMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (claimClaimedOuterHashMem I slot0 multiplier).readWithPadding 64 32 = - UInt256.toByteArray (⟨256⟩ : UInt256) := by - unfold claimClaimedOuterHashMem - rw [twoWordHashMem_read64_of_ge] - · exact claimClaimedInnerHashMem_read64 I slot0 multiplier - · exact le_trans (by norm_num) <| claimClaimedInnerHashMem_size_ge256 I slot0 multiplier - -theorem claimClaimedOuterHashMem_size_ge256 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - 256 ≤ (claimClaimedOuterHashMem I slot0 multiplier).size := by - unfold claimClaimedOuterHashMem - rw [twoWordHashMem_size_of_ge] - · exact claimClaimedInnerHashMem_size_ge256 I slot0 multiplier - · exact le_trans (by norm_num) <| claimClaimedInnerHashMem_size_ge256 I slot0 multiplier - -theorem claimClaimedOuterHashMem_mload64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (claimClaimedOuterHashMem I slot0 multiplier).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 8 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimClaimedOuterHashMem I slot0 multiplier).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - ⟨256⟩ := by - apply mloadWordValue_of_readWithPadding - · simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] using - (lt_of_lt_of_le (by norm_num : 64 < 256) <| - claimClaimedOuterHashMem_size_ge256 I slot0 multiplier) - · native_decide - · exact claimClaimedOuterHashMem_read64 I slot0 multiplier - -theorem claimClaimedOuterHashMem_keccakSlot - (I : ExecutionEnv) (slot0 multiplier : UInt256) - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((claimClaimedOuterHashMem I slot0 multiplier) - |>.readWithPadding 0 64))) = - getRewardOwedRewardsClaimedSlotOf I := by - have hhash : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((claimClaimedOuterHashMem I slot0 multiplier) - |>.readWithPadding 0 64))) = - solcMappingSlot - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - (UInt256.land (claimSrcWord I) solcAddrMask) := by - unfold claimClaimedOuterHashMem - exact twoWordHashMem_solcMappingSlot_of_ge - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - (UInt256.land (claimSrcWord I) solcAddrMask) - (le_trans (by norm_num) <| claimClaimedInnerHashMem_size_ge256 I slot0 multiplier) - rw [hhash] - rw [solcAddrMask_clean - (by simpa [claimCometWord, calldataWord] using hcanonComet)] - rw [solcAddrMask_clean - (by simpa [claimSrcWord, calldataWord] using hcanonSrc)] - rw [getRewardOwedRewardsClaimedSlotOf_eq_solc I - (by simpa [getRewardOwedCometWord, claimCometWord] using hcanonComet) - (by simpa [getRewardOwedAccountWord, claimSrcWord] using hcanonSrc)] - -theorem claimBaseTrackingSelectorMem_size_ge288 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - 288 ≤ (claimBaseTrackingSelectorMem I slot0 multiplier).size := by - unfold claimBaseTrackingSelectorMem - have hsize := writeWord_size - (claimClaimedOuterHashMem I slot0 multiplier) 256 - (UInt256.shiftLeft (⟨719776253⟩ : UInt256) ⟨226⟩) - (by - have hge := claimClaimedOuterHashMem_size_ge256 I slot0 multiplier - have hle : 256 - (claimClaimedOuterHashMem I slot0 multiplier).size = 0 := by - omega - rw [hle] - native_decide) - rw [hsize] - exact le_max_right _ _ - -theorem claimBaseTrackingCalldataMem_size_ge292 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - 292 ≤ (claimBaseTrackingCalldataMem I slot0 multiplier).size := by - unfold claimBaseTrackingCalldataMem - have hsize := writeWord_size - (claimBaseTrackingSelectorMem I slot0 multiplier) 260 (claimSrcWord I) - (by - have hge := claimBaseTrackingSelectorMem_size_ge288 I slot0 multiplier - have hle : 260 - (claimBaseTrackingSelectorMem I slot0 multiplier).size = 0 := by - omega - rw [hle] - native_decide) - rw [hsize] - have hge := claimBaseTrackingSelectorMem_size_ge288 I slot0 multiplier - omega - -theorem claimBaseTrackingCalldataMem_read256_4 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (claimBaseTrackingCalldataMem I slot0 multiplier).readWithPadding 256 4 = - baseTrackingAccruedSelector := by - unfold claimBaseTrackingCalldataMem - unfold Reasoning.Theory.writeWord - rw [write32_read_below_len _ _ 260 256 4 (by rw [toByteArray_size]) - (by - have hge := claimBaseTrackingSelectorMem_size_ge288 I slot0 multiplier - omega) - (by norm_num) - (by - have hge := claimBaseTrackingSelectorMem_size_ge288 I slot0 multiplier - omega) - (by norm_num) (by norm_num)] - unfold claimBaseTrackingSelectorMem - rw [writeWord_read_window - (claimClaimedOuterHashMem I slot0 multiplier) 256 0 4 - (UInt256.shiftLeft (⟨719776253⟩ : UInt256) ⟨226⟩) - (by norm_num) (by norm_num) (by norm_num) - (by - have hge := claimClaimedOuterHashMem_size_ge256 I slot0 multiplier - have hle : 256 - (claimClaimedOuterHashMem I slot0 multiplier).size = 0 := by - omega - rw [hle] - native_decide)] - native_decide - -theorem claimBaseTrackingCalldataMem_read260_32 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (claimBaseTrackingCalldataMem I slot0 multiplier).readWithPadding 260 32 = - UInt256.toByteArray (claimSrcWord I) := by - unfold claimBaseTrackingCalldataMem - unfold Reasoning.Theory.writeWord - rw [write32_read_back _ _ _ (by rw [toByteArray_size]) - (by - have hge := claimBaseTrackingSelectorMem_size_ge288 I slot0 multiplier - omega)] - exact toByteArray_extract_all (claimSrcWord I) - -theorem claimBaseTrackingCalldataMem_read256_36 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (claimBaseTrackingCalldataMem I slot0 multiplier).readWithPadding 256 36 = - baseTrackingAccruedSelector ++ UInt256.toByteArray (claimSrcWord I) := by - rw [byteArray_readWithPadding_split _ 256 4 32 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) - (by exact claimBaseTrackingCalldataMem_size_ge292 I slot0 multiplier)] - rw [claimBaseTrackingCalldataMem_read256_4 I slot0 multiplier, - claimBaseTrackingCalldataMem_read260_32 I slot0 multiplier] - -set_option maxHeartbeats 1000000 in -theorem claimBaseTrackingCalldataMem_encode_args - (I : ExecutionEnv) (slot0 multiplier : UInt256) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) : - config.externalABI.encode? "baseTrackingAccrued" (getRewardAccruedBaseTrackingArgs I) = - some ((claimBaseTrackingCalldataMem I slot0 multiplier) - |>.readWithPadding 256 claimBaseTrackingCallSize.toNat) := by - rw [show claimBaseTrackingCallSize.toNat = 36 from rfl] - rw [claimBaseTrackingCalldataMem_read256_36 I slot0 multiplier] - change compoundRewardsExternalABI.encode? "baseTrackingAccrued" - (getRewardAccruedBaseTrackingArgs I) = - some (baseTrackingAccruedSelector ++ UInt256.toByteArray (claimSrcWord I)) - have haccountWord : - EVM.word (AccountAddress.ofNat (claimSrcWord I).toNat).val = claimSrcWord I := by - change UInt256.ofNat (AccountAddress.ofNat (claimSrcWord I).toNat).val = claimSrcWord I - have haddr : - (AccountAddress.ofNat (claimSrcWord I).toNat).val = (claimSrcWord I).toNat := by - have hcanonAddr : (claimSrcWord I).toNat < AccountAddress.size := by - simpa [EVM.addressModulus, EVM.twoPow, AccountAddress.size] using hcanonSrc - unfold AccountAddress.ofNat - exact Nat.mod_eq_of_lt hcanonAddr - rw [haddr] - exact u256_ofNat_toNat (claimSrcWord I) - unfold compoundRewardsExternalABI ABI.encodeCallWithSelector? ABI.encodeABIValues? - simp [getRewardAccruedBaseTrackingArgs, getRewardOwedAccountValue, getRewardOwedAccountWord, - claimSrcValue, claimSrcWord, addr, ABI.abiTupleHeadSize?, ABI.staticABIEncodedSize?, - ABI.isDynamicABIType, ABI.encodeABIValue?, ABI.encodeABIWord?, ABI.encodeABIValuesFrom?, - haccountWord, word_toBytesBE_toByteArray_eq_toByteArray] - -theorem claimBaseTrackingSelectorMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (claimBaseTrackingSelectorMem I slot0 multiplier).readWithPadding 64 32 = - UInt256.toByteArray (⟨256⟩ : UInt256) := by - unfold claimBaseTrackingSelectorMem - exact (writeWord_read_preserved - (claimClaimedOuterHashMem I slot0 multiplier) 256 64 - (UInt256.shiftLeft (⟨719776253⟩ : UInt256) ⟨226⟩) - (by - have hge := claimClaimedOuterHashMem_size_ge256 I slot0 multiplier - have hle : 256 - (claimClaimedOuterHashMem I slot0 multiplier).size = 0 := by - omega - rw [hle] - native_decide) - (by - have hge := claimClaimedOuterHashMem_size_ge256 I slot0 multiplier - left - constructor <;> omega) - ).trans (claimClaimedOuterHashMem_read64 I slot0 multiplier) - -theorem claimBaseTrackingCalldataMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (claimBaseTrackingCalldataMem I slot0 multiplier).readWithPadding 64 32 = - UInt256.toByteArray (⟨256⟩ : UInt256) := by - unfold claimBaseTrackingCalldataMem - exact (writeWord_read_preserved - (claimBaseTrackingSelectorMem I slot0 multiplier) 260 64 (claimSrcWord I) - (by - have hge := claimBaseTrackingSelectorMem_size_ge288 I slot0 multiplier - have hle : 260 - (claimBaseTrackingSelectorMem I slot0 multiplier).size = 0 := by - omega - rw [hle] - native_decide) - (by - have hge := claimBaseTrackingSelectorMem_size_ge288 I slot0 multiplier - left - constructor <;> omega) - ).trans (claimBaseTrackingSelectorMem_read64 I slot0 multiplier) - -theorem claimBaseTrackingPostCallMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).readWithPadding 64 32 = - UInt256.toByteArray (⟨256⟩ : UInt256) := by - unfold claimBaseTrackingPostCallMem - by_cases hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat = 0 - · rw [hlen, byteArray_write_len_zero] - exact claimBaseTrackingCalldataMem_read64 I slot0 multiplier - · have hsrc : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat ≤ baseOut.size := - getRewardOwedPostCallLen_le_out_size hbaseSize - rw [write_read_below_gen_extend baseOut - (claimBaseTrackingCalldataMem I slot0 multiplier) 256 - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat 64 - hlen hsrc - (by - have hge := claimBaseTrackingCalldataMem_size_ge292 I slot0 multiplier - omega) - (by norm_num)] - exact claimBaseTrackingCalldataMem_read64 I slot0 multiplier - -theorem claimBaseTrackingPostCallMem_size_ge256 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - 256 ≤ (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size := by - unfold claimBaseTrackingPostCallMem - by_cases hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat = 0 - · rw [hlen, byteArray_write_len_zero] - have hge := claimBaseTrackingCalldataMem_size_ge292 I slot0 multiplier - omega - · have hsrc : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat ≤ baseOut.size := - getRewardOwedPostCallLen_le_out_size hbaseSize - let len := (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat - let base := claimBaseTrackingCalldataMem I slot0 multiplier - have hdest : 256 ≤ base.size := by - have hge := claimBaseTrackingCalldataMem_size_ge292 I slot0 multiplier - simpa [base] using le_trans (by norm_num : 256 ≤ 292) hge - by_cases hin : 256 + len ≤ base.size - · rw [write_eq_gen baseOut base 256 len (by simpa [len] using hlen) - (by simpa [len] using hsrc) hin] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract] - omega - · have hext : base.size < 256 + len := Nat.lt_of_not_ge hin - rw [write_eq_gen_extend baseOut base 256 len (by simpa [len] using hlen) - (by simpa [len] using hsrc) hdest hext] - rw [ByteArray.size_append, ByteArray.size_extract, ByteArray.size_extract] - omega - -theorem claimBaseTrackingPostCallMem_read256_of_size_ge - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).readWithPadding 256 32 = - baseOut.extract 0 32 := by - unfold claimBaseTrackingPostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := baseOut.size) - (by decide) hout32 hbaseSize - rw [hlen] - exact write32_read_back baseOut - (claimBaseTrackingCalldataMem I slot0 multiplier) - 256 hout32 - (by - have hge := claimBaseTrackingCalldataMem_size_ge292 I slot0 multiplier - omega) - -theorem claimBaseTrackingPostCallMem_size_ge288 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - 288 ≤ (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size := by - unfold claimBaseTrackingPostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := baseOut.size) - (by decide) hout32 hbaseSize - rw [hlen] - rw [write32_eq baseOut (claimBaseTrackingCalldataMem I slot0 multiplier) - 256 hout32 - (by - have hge := claimBaseTrackingCalldataMem_size_ge292 I slot0 multiplier - omega)] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract] - have hbase := claimBaseTrackingCalldataMem_size_ge292 I slot0 multiplier - omega - -theorem claimBaseTrackingPostCallMem_size_ge292 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - 292 ≤ (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size := by - unfold claimBaseTrackingPostCallMem - by_cases hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat = 0 - · rw [hlen, byteArray_write_len_zero] - exact claimBaseTrackingCalldataMem_size_ge292 I slot0 multiplier - · have hsrc : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat ≤ baseOut.size := - getRewardOwedPostCallLen_le_out_size hbaseSize - let len := (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat - let base := claimBaseTrackingCalldataMem I slot0 multiplier - have hbase292 : 292 ≤ base.size := by - simpa [base] using claimBaseTrackingCalldataMem_size_ge292 I slot0 multiplier - have hdest : 256 ≤ base.size := le_trans (by norm_num) hbase292 - by_cases hin : 256 + len ≤ base.size - · rw [write_eq_gen baseOut base 256 len (by simpa [len] using hlen) - (by simpa [len] using hsrc) hin] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract] - omega - · have hext : base.size < 256 + len := Nat.lt_of_not_ge hin - rw [write_eq_gen_extend baseOut base 256 len (by simpa [len] using hlen) - (by simpa [len] using hsrc) hdest hext] - rw [ByteArray.size_append, ByteArray.size_extract, ByteArray.size_extract] - omega - -theorem claimBaseTrackingPostCallMem_mload256_haw : - ¬ (⟨256⟩ : UInt256) ≥ claimBaseTrackingPostCallAw * ⟨32⟩ := by - native_decide - -theorem claimBaseTrackingPostDecodeMem_read256_of_size_ge - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).readWithPadding 256 32 = - baseOut.extract 0 32 := by - unfold claimBaseTrackingPostDecodeMem - rw [writeWord_read_preserved] - · exact claimBaseTrackingPostCallMem_read256_of_size_ge - I slot0 multiplier hout32 hbaseSize - · have hge := claimBaseTrackingPostCallMem_size_ge288 - I slot0 multiplier hout32 hbaseSize - have hle : - 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide - · right - have hge := claimBaseTrackingPostCallMem_size_ge288 - I slot0 multiplier hout32 hbaseSize - constructor <;> omega - -theorem claimBaseTrackingPostDecodeMem_mload256_of_size_ge - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨256⟩ : UInt256).toNat ≥ - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).size - ∨ (⟨256⟩ : UInt256) ≥ claimBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - |>.readWithPadding (⟨256⟩ : UInt256).toNat 32))) = - claimBaseTrackingReturnWord baseOut := by - trans UInt256.ofNat - (fromByteArrayBigEndian - ((claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).readWithPadding - (⟨256⟩ : UInt256).toNat 32)) - · exact mloadValue_eq_readWithPadding_of_lt_size - (mem := claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - (aw := claimBaseTrackingPostCallAw) - (off := ⟨256⟩) - (memSize := (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).size) - rfl - (by - rw [show (⟨256⟩ : UInt256).toNat = 256 from by decide] - unfold claimBaseTrackingPostDecodeMem - rw [writeWord_size] - · have hsz := claimBaseTrackingPostCallMem_size_ge288 - I slot0 multiplier hout32 hbaseSize - omega - · have hsz := claimBaseTrackingPostCallMem_size_ge288 - I slot0 multiplier hout32 hbaseSize - have hle : - 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide) - claimBaseTrackingPostCallMem_mload256_haw - · rw [show (⟨256⟩ : UInt256).toNat = 256 from by decide, - claimBaseTrackingPostDecodeMem_read256_of_size_ge - I slot0 multiplier hout32 hbaseSize] - -theorem claimBaseTrackingPostCallMem_read_below256 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) {read : ℕ} (hbelow : read + 32 ≤ 256) : - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).readWithPadding read 32 = - (claimBaseTrackingCalldataMem I slot0 multiplier).readWithPadding read 32 := by - unfold claimBaseTrackingPostCallMem - by_cases hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat = 0 - · rw [hlen, byteArray_write_len_zero] - · have hsrc : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat ≤ baseOut.size := - getRewardOwedPostCallLen_le_out_size hbaseSize - rw [write_read_below_gen_extend baseOut - (claimBaseTrackingCalldataMem I slot0 multiplier) 256 - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat read - hlen hsrc - (by - have hge := claimBaseTrackingCalldataMem_size_ge292 I slot0 multiplier - omega) - hbelow] - -theorem claimConfigMultiplierMem_read128 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (claimConfigMultiplierMem I slot0 multiplier).readWithPadding 128 32 = - UInt256.toByteArray (rewardConfigTokenFromSlot0 slot0) := by - unfold claimConfigMultiplierMem - rw [writeWord_read_preserved] - · unfold claimConfigShouldMem - rw [writeWord_read_preserved] - · unfold claimConfigRescaleMem - rw [writeWord_read_preserved] - · unfold claimConfigTokenMem - exact writeWord_read_back (claimConfigAllocMem I) 128 - (rewardConfigTokenFromSlot0 slot0) - (by rw [claimConfigAllocMem_size]; native_decide) - · rw [claimConfigTokenMem_size] - native_decide - · left - rw [claimConfigTokenMem_size] - constructor <;> norm_num - · rw [claimConfigRescaleMem_size] - native_decide - · left - rw [claimConfigRescaleMem_size] - constructor <;> norm_num - · rw [claimConfigShouldMem_size] - native_decide - · left - rw [claimConfigShouldMem_size] - constructor <;> norm_num - -theorem claimConfigMultiplierMem_read160 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (claimConfigMultiplierMem I slot0 multiplier).readWithPadding 160 32 = - UInt256.toByteArray (rewardConfigRescaleFromSlot0 slot0) := by - unfold claimConfigMultiplierMem - rw [writeWord_read_preserved] - · unfold claimConfigShouldMem - rw [writeWord_read_preserved] - · unfold claimConfigRescaleMem - exact writeWord_read_back (claimConfigTokenMem I slot0) 160 - (rewardConfigRescaleFromSlot0 slot0) - (by rw [claimConfigTokenMem_size]; native_decide) - · rw [claimConfigRescaleMem_size] - native_decide - · left - rw [claimConfigRescaleMem_size] - constructor <;> norm_num - · rw [claimConfigShouldMem_size] - native_decide - · left - rw [claimConfigShouldMem_size] - constructor <;> norm_num - -theorem claimConfigMultiplierMem_read192 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (claimConfigMultiplierMem I slot0 multiplier).readWithPadding 192 32 = - UInt256.toByteArray (rewardConfigShouldUpscaleFromSlot0 slot0) := by - unfold claimConfigMultiplierMem - rw [writeWord_read_preserved] - · unfold claimConfigShouldMem - exact writeWord_read_back (claimConfigRescaleMem I slot0) 192 - (rewardConfigShouldUpscaleFromSlot0 slot0) - (by rw [claimConfigRescaleMem_size]; native_decide) - · rw [claimConfigShouldMem_size] - native_decide - · left - rw [claimConfigShouldMem_size] - constructor <;> norm_num - -theorem claimConfigMultiplierMem_read224 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (claimConfigMultiplierMem I slot0 multiplier).readWithPadding 224 32 = - UInt256.toByteArray multiplier := by - unfold claimConfigMultiplierMem - exact writeWord_read_back (claimConfigShouldMem I slot0) 224 multiplier - (by rw [claimConfigShouldMem_size]; native_decide) - -theorem claimBaseTrackingCalldataMem_read_config - (I : ExecutionEnv) (slot0 multiplier : UInt256) {read : ℕ} - (hbelow : read + 32 ≤ 256) (habove : 64 ≤ read) {val : UInt256} - (hcfg : - (claimConfigMultiplierMem I slot0 multiplier).readWithPadding read 32 = - UInt256.toByteArray val) : - (claimBaseTrackingCalldataMem I slot0 multiplier).readWithPadding read 32 = - UInt256.toByteArray val := by - unfold claimBaseTrackingCalldataMem - rw [writeWord_read_preserved] - · unfold claimBaseTrackingSelectorMem - rw [writeWord_read_preserved] - · unfold claimClaimedOuterHashMem - rw [twoWordHashMem_read_above64_of_ge] - · unfold claimClaimedInnerHashMem - rw [twoWordHashMem_read_above64_of_ge] - · exact hcfg - · have hge := claimConfigMultiplierMem_size I slot0 multiplier - omega - · exact habove - · have hge := claimClaimedInnerHashMem_size_ge256 I slot0 multiplier - omega - · exact habove - · have hge := claimClaimedOuterHashMem_size_ge256 I slot0 multiplier - have hle : 256 - (claimClaimedOuterHashMem I slot0 multiplier).size = 0 := by - omega - rw [hle] - native_decide - · left - have hge := claimClaimedOuterHashMem_size_ge256 I slot0 multiplier - constructor <;> omega - · have hge := claimBaseTrackingSelectorMem_size_ge288 I slot0 multiplier - have hle : 260 - (claimBaseTrackingSelectorMem I slot0 multiplier).size = 0 := by - omega - rw [hle] - native_decide - · left - have hge := claimBaseTrackingSelectorMem_size_ge288 I slot0 multiplier - constructor <;> omega - -theorem claimBaseTrackingPostDecodeMem_read_config - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) {read : ℕ} - (hbelow : read + 32 ≤ 256) (habove : 96 ≤ read) {val : UInt256} - (hcfg : - (claimConfigMultiplierMem I slot0 multiplier).readWithPadding read 32 = - UInt256.toByteArray val) : - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).readWithPadding read 32 = - UInt256.toByteArray val := by - unfold claimBaseTrackingPostDecodeMem - rw [writeWord_read_preserved] - · rw [claimBaseTrackingPostCallMem_read_below256 I slot0 multiplier hbaseSize hbelow] - exact claimBaseTrackingCalldataMem_read_config I slot0 multiplier hbelow - (by omega) hcfg - · have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - have hle : - 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide - · right - have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - constructor <;> omega - -theorem claimBaseTrackingPostDecodeMem_read128 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).readWithPadding 128 32 = - UInt256.toByteArray (rewardConfigTokenFromSlot0 slot0) := - claimBaseTrackingPostDecodeMem_read_config I slot0 multiplier hbaseSize - (by norm_num) (by norm_num) (claimConfigMultiplierMem_read128 I slot0 multiplier) - -theorem claimBaseTrackingPostDecodeMem_read160 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).readWithPadding 160 32 = - UInt256.toByteArray (rewardConfigRescaleFromSlot0 slot0) := - claimBaseTrackingPostDecodeMem_read_config I slot0 multiplier hbaseSize - (by norm_num) (by norm_num) (claimConfigMultiplierMem_read160 I slot0 multiplier) - -theorem claimBaseTrackingPostDecodeMem_read192 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).readWithPadding 192 32 = - UInt256.toByteArray (rewardConfigShouldUpscaleFromSlot0 slot0) := - claimBaseTrackingPostDecodeMem_read_config I slot0 multiplier hbaseSize - (by norm_num) (by norm_num) (claimConfigMultiplierMem_read192 I slot0 multiplier) - -theorem claimBaseTrackingPostDecodeMem_read224 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).readWithPadding 224 32 = - UInt256.toByteArray multiplier := - claimBaseTrackingPostDecodeMem_read_config I slot0 multiplier hbaseSize - (by norm_num) (by norm_num) (claimConfigMultiplierMem_read224 I slot0 multiplier) - -theorem claimBaseTrackingPostDecodeMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).readWithPadding 64 32 = - UInt256.toByteArray (⟨288⟩ : UInt256) := by - unfold claimBaseTrackingPostDecodeMem - exact writeWord_read_back (claimBaseTrackingPostCallMem I slot0 multiplier baseOut) 64 - (⟨288⟩ : UInt256) - (by - have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - have hle : 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide) - -theorem claimBaseTrackingPostDecodeMem_mload64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).size - ∨ (⟨64⟩ : UInt256) ≥ claimBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - |>.readWithPadding (⟨64⟩ : UInt256).toNat 32))) = ⟨288⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := claimBaseTrackingPostCallAw) - (v := ⟨288⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold claimBaseTrackingPostDecodeMem - rw [writeWord_size] - · have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - omega - · have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - have hle : - 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact claimBaseTrackingPostDecodeMem_read64 I slot0 multiplier hbaseSize) - -theorem claimBaseTrackingPostDecodeMem_size_ge292 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - 292 ≤ (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).size := by - unfold claimBaseTrackingPostDecodeMem - rw [writeWord_size] - · have hge := claimBaseTrackingPostCallMem_size_ge292 I slot0 multiplier hbaseSize - omega - · have hge := claimBaseTrackingPostCallMem_size_ge292 I slot0 multiplier hbaseSize - have hle : - 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide - -theorem claimTransferInnerHashMem_size_ge292 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - 292 ≤ (claimTransferInnerHashMem I slot0 multiplier baseOut).size := by - unfold claimTransferInnerHashMem - rw [twoWordHashMem_size_of_ge] - · exact claimBaseTrackingPostDecodeMem_size_ge292 I slot0 multiplier hbaseSize - · have hge := claimBaseTrackingPostDecodeMem_size_ge292 I slot0 multiplier hbaseSize - omega - -theorem claimTransferOuterHashMem_size_ge292 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - 292 ≤ (claimTransferOuterHashMem I slot0 multiplier baseOut).size := by - unfold claimTransferOuterHashMem - rw [twoWordHashMem_size_of_ge] - · exact claimTransferInnerHashMem_size_ge292 I slot0 multiplier hbaseSize - · have hge := claimTransferInnerHashMem_size_ge292 I slot0 multiplier hbaseSize - omega - -theorem claimTransferInnerHashMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - (claimTransferInnerHashMem I slot0 multiplier baseOut).readWithPadding 64 32 = - UInt256.toByteArray (⟨288⟩ : UInt256) := by - unfold claimTransferInnerHashMem - rw [twoWordHashMem_read64_of_ge] - · exact claimBaseTrackingPostDecodeMem_read64 I slot0 multiplier hbaseSize - · have hge := claimBaseTrackingPostDecodeMem_size_ge292 I slot0 multiplier hbaseSize - omega - -theorem claimTransferOuterHashMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - (claimTransferOuterHashMem I slot0 multiplier baseOut).readWithPadding 64 32 = - UInt256.toByteArray (⟨288⟩ : UInt256) := by - unfold claimTransferOuterHashMem - rw [twoWordHashMem_read64_of_ge] - · exact claimTransferInnerHashMem_read64 I slot0 multiplier hbaseSize - · have hge := claimTransferInnerHashMem_size_ge292 I slot0 multiplier hbaseSize - omega - -theorem claimTransferOuterHashMem_mload64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ - (claimTransferOuterHashMem I slot0 multiplier baseOut).size - ∨ (⟨64⟩ : UInt256) ≥ claimBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimTransferOuterHashMem I slot0 multiplier baseOut) - |>.readWithPadding (⟨64⟩ : UInt256).toNat 32))) = ⟨288⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := claimBaseTrackingPostCallAw) - (v := ⟨288⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - have hge := claimTransferOuterHashMem_size_ge292 I slot0 multiplier hbaseSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact claimTransferOuterHashMem_read64 I slot0 multiplier hbaseSize) - -theorem claimTransferSelectorMem_size_ge320 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - 320 ≤ (claimTransferSelectorMem I slot0 multiplier baseOut).size := by - unfold claimTransferSelectorMem - exact toByteArray_write_size_ge_off_add32 withdrawTokenTransferSelectorShifted - (claimTransferOuterHashMem I slot0 multiplier baseOut) 288 - (lt_of_le_of_lt (Nat.sub_le 288 _) (by native_decide)) - -theorem claimTransferArgsMem_size_ge324 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (recipient : UInt256) (hbaseSize : baseOut.size < UInt256.size) : - 324 ≤ (claimTransferArgsMem I slot0 multiplier baseOut recipient).size := by - unfold claimTransferArgsMem - exact toByteArray_write_size_ge_off_add32 recipient - (claimTransferSelectorMem I slot0 multiplier baseOut) 292 - (lt_of_le_of_lt (Nat.sub_le 292 _) (by native_decide)) - -theorem claimTransferCalldataMem_size_ge356 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (recipient value : UInt256) (hbaseSize : baseOut.size < UInt256.size) : - 356 ≤ (claimTransferCalldataMem I slot0 multiplier baseOut recipient value).size := by - unfold claimTransferCalldataMem - exact toByteArray_write_size_ge_off_add32 value - (claimTransferArgsMem I slot0 multiplier baseOut recipient) 324 - (lt_of_le_of_lt (Nat.sub_le 324 _) (by native_decide)) - -theorem claimTransferCalldataMem_read288_4 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (recipient value : UInt256) (hbaseSize : baseOut.size < UInt256.size) : - (claimTransferCalldataMem I slot0 multiplier baseOut recipient value).readWithPadding - 288 4 = transferSelector := by - unfold claimTransferCalldataMem - rw [write32_read_below_len _ _ 324 288 4 (by rw [toByteArray_size]) - (by exact claimTransferArgsMem_size_ge324 I slot0 multiplier recipient hbaseSize) - (by omega) - (by - have hge := claimTransferArgsMem_size_ge324 I slot0 multiplier recipient hbaseSize - omega) - (by norm_num) (by norm_num)] - unfold claimTransferArgsMem - rw [write32_read_below_len _ _ 292 288 4 (by rw [toByteArray_size]) - (by - have hge := claimTransferSelectorMem_size_ge320 I slot0 multiplier hbaseSize - omega) - (by omega) - (by - have hge := claimTransferSelectorMem_size_ge320 I slot0 multiplier hbaseSize - omega) - (by norm_num) (by norm_num)] - unfold claimTransferSelectorMem - rw [write32_read_prefix_len _ _ 288 4 (by rw [toByteArray_size]) - (by - have hge := claimTransferOuterHashMem_size_ge292 I slot0 multiplier hbaseSize - omega) - (by norm_num) (by norm_num) (by norm_num)] - native_decide - -theorem claimTransferCalldataMem_read292_32 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (recipient value : UInt256) (hbaseSize : baseOut.size < UInt256.size) : - (claimTransferCalldataMem I slot0 multiplier baseOut recipient value).readWithPadding - 292 32 = UInt256.toByteArray recipient := by - unfold claimTransferCalldataMem - rw [write32_read_below _ _ 324 292 (by rw [toByteArray_size]) - (by exact claimTransferArgsMem_size_ge324 I slot0 multiplier recipient hbaseSize) - (by omega)] - unfold claimTransferArgsMem - rw [write32_read_back _ _ _ (by rw [toByteArray_size]) - (by - have hge := claimTransferSelectorMem_size_ge320 I slot0 multiplier hbaseSize - omega)] - exact toByteArray_extract_all recipient - -theorem claimTransferCalldataMem_read324_32 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (recipient value : UInt256) (hbaseSize : baseOut.size < UInt256.size) : - (claimTransferCalldataMem I slot0 multiplier baseOut recipient value).readWithPadding - 324 32 = UInt256.toByteArray value := by - unfold claimTransferCalldataMem - rw [write32_read_back _ _ _ (by rw [toByteArray_size]) - (by exact claimTransferArgsMem_size_ge324 I slot0 multiplier recipient hbaseSize)] - exact toByteArray_extract_all value - -theorem claimTransferCalldataMem_read288_68 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (recipient value : UInt256) (hbaseSize : baseOut.size < UInt256.size) : - (claimTransferCalldataMem I slot0 multiplier baseOut recipient value).readWithPadding - 288 68 = - transferSelector ++ UInt256.toByteArray recipient ++ UInt256.toByteArray value := by - rw [byteArray_readWithPadding_split _ 288 4 64 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) - (by exact claimTransferCalldataMem_size_ge356 I slot0 multiplier recipient value hbaseSize)] - rw [byteArray_readWithPadding_split _ 292 32 32 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) - (by exact claimTransferCalldataMem_size_ge356 I slot0 multiplier recipient value hbaseSize)] - rw [claimTransferCalldataMem_read288_4 I slot0 multiplier recipient value hbaseSize, - claimTransferCalldataMem_read292_32 I slot0 multiplier recipient value hbaseSize, - claimTransferCalldataMem_read324_32 I slot0 multiplier recipient value hbaseSize, - ByteArray.append_assoc] - -theorem claimTransferCalldataMem_encode - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (recipient : AccountAddress) (value : UInt256) - (hbaseSize : baseOut.size < UInt256.size) : - config.externalABI.encode? "transfer" - [.address recipient, .int (Int.ofNat value.toNat)] = - some ((claimTransferCalldataMem I slot0 multiplier baseOut - (UInt256.ofNat recipient.val) value).readWithPadding 288 68) := by - rw [claimTransferCalldataMem_read288_68 I slot0 multiplier - (UInt256.ofNat recipient.val) value hbaseSize] - change compoundRewardsExternalABI.encode? "transfer" - [.address recipient, .int (Int.ofNat value.toNat)] = - some (transferSelector ++ - (UInt256.ofNat recipient.val).toByteArray ++ UInt256.toByteArray value) - have hvalueWord : EVM.word value.toNat = value := by - exact u256_ofNat_toNat value - have hrecipientWord : EVM.word recipient.val = UInt256.ofNat recipient.val := by - apply u256_inj - rfl - have hvalueLt : value.toNat < EVM.twoPow 256 := by - change value.val.val < UInt256.size - exact value.val.isLt - unfold compoundRewardsExternalABI ABI.encodeCallWithSelector? ABI.encodeABIValues? - simp [addr, uint256, uint256Int, ABI.abiTupleHeadSize?, ABI.staticABIEncodedSize?, - ABI.isDynamicABIType, ABI.encodeABIValue?, ABI.encodeABIWord?, ABI.encodeABIValuesFrom?, - hvalueLt, hrecipientWord, hvalueWord, word_toBytesBE_toByteArray_eq_toByteArray] - rw [ByteArray.append_assoc] - -set_option maxHeartbeats 1000000 in -theorem claimTransferCalldataMem_encode_args - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (amount : UInt256) (hbaseSize : baseOut.size < UInt256.size) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) : - config.externalABI.encode? "transfer" (claimTransferArgs I amount) = - some ((claimTransferCalldataMem I slot0 multiplier baseOut - (claimSrcWord I) amount).readWithPadding 288 claimTransferCallSize.toNat) := by - have hsz : claimTransferCallSize.toNat = 68 := by - unfold claimTransferCallSize - rw [withdrawTokenTransferCallSize_eq] - rfl - rw [hsz] - have hround : - UInt256.ofNat (AccountAddress.ofNat (claimSrcWord I).toNat).val = - claimSrcWord I := - u256_of_accountAddress_ofNat_toNat_of_canonical hcanonSrc - have henc := claimTransferCalldataMem_encode - (I := I) (slot0 := slot0) (multiplier := multiplier) - (baseOut := baseOut) - (recipient := AccountAddress.ofNat (claimSrcWord I).toNat) - (value := amount) hbaseSize - change config.externalABI.encode? "transfer" - [.address (AccountAddress.ofNat (claimSrcWord I).toNat), - .int (Int.ofNat amount.toNat)] = - some ((claimTransferCalldataMem I slot0 multiplier baseOut - (claimSrcWord I) amount).readWithPadding 288 68) - rw [hround] at henc - exact henc - -theorem claimBaseTrackingPostDecodeMem_mload128 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨128⟩ : UInt256).toNat ≥ - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).size - ∨ (⟨128⟩ : UInt256) ≥ claimBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - |>.readWithPadding (⟨128⟩ : UInt256).toNat 32))) = - rewardConfigTokenFromSlot0 slot0 := by - exact mloadWordValue_of_readWithPadding - (off := (⟨128⟩ : UInt256)) (aw := claimBaseTrackingPostCallAw) - (v := rewardConfigTokenFromSlot0 slot0) - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - unfold claimBaseTrackingPostDecodeMem - rw [writeWord_size] - · have hge := claimBaseTrackingPostCallMem_size_ge288 - I slot0 multiplier hout32 hbaseSize - omega - · have hge := claimBaseTrackingPostCallMem_size_ge288 - I slot0 multiplier hout32 hbaseSize - have hle : - 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide) - (by native_decide) - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - exact claimBaseTrackingPostDecodeMem_read128 I slot0 multiplier hbaseSize) - -theorem claimBaseTrackingPostDecodeMem_mload160 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨160⟩ : UInt256).toNat ≥ - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).size - ∨ (⟨160⟩ : UInt256) ≥ claimBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - |>.readWithPadding (⟨160⟩ : UInt256).toNat 32))) = - rewardConfigRescaleFromSlot0 slot0 := by - exact mloadWordValue_of_readWithPadding - (off := (⟨160⟩ : UInt256)) (aw := claimBaseTrackingPostCallAw) - (v := rewardConfigRescaleFromSlot0 slot0) - (by - rw [show (⟨160⟩ : UInt256).toNat = 160 from by decide] - unfold claimBaseTrackingPostDecodeMem - rw [writeWord_size] - · have hge := claimBaseTrackingPostCallMem_size_ge288 - I slot0 multiplier hout32 hbaseSize - omega - · have hge := claimBaseTrackingPostCallMem_size_ge288 - I slot0 multiplier hout32 hbaseSize - have hle : - 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide) - (by native_decide) - (by - rw [show (⟨160⟩ : UInt256).toNat = 160 from by decide] - exact claimBaseTrackingPostDecodeMem_read160 I slot0 multiplier hbaseSize) - -theorem claimBaseTrackingPostDecodeMem_mload192 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨192⟩ : UInt256).toNat ≥ - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).size - ∨ (⟨192⟩ : UInt256) ≥ claimBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - |>.readWithPadding (⟨192⟩ : UInt256).toNat 32))) = - rewardConfigShouldUpscaleFromSlot0 slot0 := by - exact mloadWordValue_of_readWithPadding - (off := (⟨192⟩ : UInt256)) (aw := claimBaseTrackingPostCallAw) - (v := rewardConfigShouldUpscaleFromSlot0 slot0) - (by - rw [show (⟨192⟩ : UInt256).toNat = 192 from by decide] - unfold claimBaseTrackingPostDecodeMem - rw [writeWord_size] - · have hge := claimBaseTrackingPostCallMem_size_ge288 - I slot0 multiplier hout32 hbaseSize - omega - · have hge := claimBaseTrackingPostCallMem_size_ge288 - I slot0 multiplier hout32 hbaseSize - have hle : - 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide) - (by native_decide) - (by - rw [show (⟨192⟩ : UInt256).toNat = 192 from by decide] - exact claimBaseTrackingPostDecodeMem_read192 I slot0 multiplier hbaseSize) - -theorem claimBaseTrackingPostDecodeMem_mload224 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨224⟩ : UInt256).toNat ≥ - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut).size - ∨ (⟨224⟩ : UInt256) ≥ claimBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - |>.readWithPadding (⟨224⟩ : UInt256).toNat 32))) = - multiplier := by - exact mloadWordValue_of_readWithPadding - (off := (⟨224⟩ : UInt256)) (aw := claimBaseTrackingPostCallAw) - (v := multiplier) - (by - rw [show (⟨224⟩ : UInt256).toNat = 224 from by decide] - unfold claimBaseTrackingPostDecodeMem - rw [writeWord_size] - · have hge := claimBaseTrackingPostCallMem_size_ge288 - I slot0 multiplier hout32 hbaseSize - omega - · have hge := claimBaseTrackingPostCallMem_size_ge288 - I slot0 multiplier hout32 hbaseSize - have hle : - 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide) - (by native_decide) - (by - rw [show (⟨224⟩ : UInt256).toNat = 224 from by decide] - exact claimBaseTrackingPostDecodeMem_read224 I slot0 multiplier hbaseSize) - -theorem claimBaseTrackingPostCallMem_mload64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut : ByteArray} - (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size - ∨ (⟨64⟩ : UInt256) ≥ claimBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimBaseTrackingPostCallMem I slot0 multiplier baseOut) - |>.readWithPadding (⟨64⟩ : UInt256).toNat 32))) = ⟨256⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := claimBaseTrackingPostCallAw) - (v := ⟨256⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact claimBaseTrackingPostCallMem_read64 I slot0 multiplier hbaseSize) - -theorem cometRewardsDecode_claim_ok {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) - (hbool : claimShouldAccrueWord I = ⟨0⟩ ∨ claimShouldAccrueWord I = ⟨1⟩) : - decodeCalldataWithMode config.abiDecodeMode (claimTransition.params.map Param.name) - (transitionSignature claimTransition).paramTypes I.calldata = some (claimStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "src", "shouldAccrue"] - [addr, addr, boolTy] I.calldata = _ - change decodeCalldata ["comet", "src", "shouldAccrue"] - [.elem .address, .elem .address, .elem .bool] I.calldata = - some ((((∅ : Store).insert "comet" - (.address (AccountAddress.ofNat (calldataWord I.calldata 4).toNat))).insert "src" - (.address (AccountAddress.ofNat (calldataWord I.calldata 36).toNat))).insert - "shouldAccrue" (wordToElem .bool (calldataWord I.calldata 68))) - simpa [claimCometWord, claimSrcWord, claimShouldAccrueWord, calldataWord] using - decodeCalldata_address_address_bool_ok (cd := I.calldata) - (x := "comet") (y := "src") (z := "shouldAccrue") hsz100 hbig hcanonComet - hcanonSrc hbool - -theorem cometRewardsDecode_claim_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 100) : - decodeCalldataWithMode config.abiDecodeMode (claimTransition.params.map Param.name) - (transitionSignature claimTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "src", "shouldAccrue"] - [addr, addr, boolTy] I.calldata = none - change decodeCalldata ["comet", "src", "shouldAccrue"] - [.elem .address, .elem .address, .elem .bool] I.calldata = none - exact decodeCalldata_address_address_bool_none_short - (cd := I.calldata) (x := "comet") (y := "src") (z := "shouldAccrue") hsz4 hshort - -theorem cometRewardsDecode_claim_none_noncanon_comet {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hncComet : ¬ (claimCometWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (claimTransition.params.map Param.name) - (transitionSignature claimTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "src", "shouldAccrue"] - [addr, addr, boolTy] I.calldata = none - change decodeCalldata ["comet", "src", "shouldAccrue"] - [.elem .address, .elem .address, .elem .bool] I.calldata = none - simpa [claimCometWord, calldataWord] using - decodeCalldata_address_address_bool_none_noncanon0 - (cd := I.calldata) (x := "comet") (y := "src") (z := "shouldAccrue") - hsz100 hbig hncComet - -theorem cometRewardsDecode_claim_none_noncanon_src {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hncSrc : ¬ (claimSrcWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (claimTransition.params.map Param.name) - (transitionSignature claimTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "src", "shouldAccrue"] - [addr, addr, boolTy] I.calldata = none - change decodeCalldata ["comet", "src", "shouldAccrue"] - [.elem .address, .elem .address, .elem .bool] I.calldata = none - simpa [claimCometWord, claimSrcWord, calldataWord] using - decodeCalldata_address_address_bool_none_noncanon1 - (cd := I.calldata) (x := "comet") (y := "src") (z := "shouldAccrue") - hsz100 hbig hcanonComet hncSrc - -theorem cometRewardsDecode_claim_none_noncanon_bool {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) - (hnz : claimShouldAccrueWord I ≠ ⟨0⟩) (hno : claimShouldAccrueWord I ≠ ⟨1⟩) : - decodeCalldataWithMode config.abiDecodeMode (claimTransition.params.map Param.name) - (transitionSignature claimTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "src", "shouldAccrue"] - [addr, addr, boolTy] I.calldata = none - change decodeCalldata ["comet", "src", "shouldAccrue"] - [.elem .address, .elem .address, .elem .bool] I.calldata = none - simpa [claimCometWord, claimSrcWord, claimShouldAccrueWord, calldataWord] using - decodeCalldata_address_address_bool_none_noncanon2 - (cd := I.calldata) (x := "comet") (y := "src") (z := "shouldAccrue") - hsz100 hbig hcanonComet hcanonSrc hnz hno - -theorem cometRewardsDecode_claim_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (claimTransition.params.map Param.name) - (transitionSignature claimTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "src", "shouldAccrue"] - [addr, addr, boolTy] I.calldata = none - change decodeCalldata ["comet", "src", "shouldAccrue"] - [.elem .address, .elem .address, .elem .bool] I.calldata = none - exact decodeCalldata_address_address_bool_none_huge - (cd := I.calldata) (x := "comet") (y := "src") (z := "shouldAccrue") hbig - -theorem cometRewardsClaimSelector_size {I : ExecutionEnv} - (hsel : selIs I (cometRewardsSelBytes 8)) : - 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (cometRewardsSelBytes 8) rfl hsel - -theorem cometRewardsDispatch_claim {cd : ByteArray} - (hsel : (cometRewardsSelBytes 8 == cd.extract 0 4) = true) : - dispatchMsg contract cd = some claimTransition := by - refine dispatchMsg_eq_some_of_split - (pre := []) - (post := [claimToTransition, getRewardOwedTransition, governorTransition, - rewardConfigTransition, rewardsClaimedTransition, setRewardConfigTransition, - setRewardConfigWithMultiplierTransition, setRewardsClaimedTransition, - transferGovernorTransition, withdrawTokenTransition]) - rfl rfl ?_ (by rw [selectorOf, claimSelectorBytes]; exact hsel) - intro t ht - simp at ht - -theorem cometRewardsClaimCalldataCheckOk {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hhi : I.calldata.size < 2 ^ 255 + 4) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨0⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨0⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - simpa using - solcCalldataStaticLenCheckOk (sz := I.calldata.size) (words := 3) - (by simpa using hsz100) hhi hsize - -theorem cometRewardsClaimCalldataCheckShort {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hshort : I.calldata.size < 100) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 hsz4 hsize] - simpa using - solcCalldataStaticLenCheckShort (sz := I.calldata.size) (words := 3) - hsz4 (by simpa using hshort) hsize (by norm_num) - -theorem cometRewardsClaimCalldataCheckHuge {I : ExecutionEnv} - (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - simpa using - solcCalldataStaticLenCheckHuge (sz := I.calldata.size) (words := 3) - hbig hsize (by norm_num) - -theorem cometRewardsClaimX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz4 : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hshort : I.calldata.size < 100) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) claimPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsClaimCalldataCheckShort (I := I) hsz4 hsize hshort - obtain ⟨_, _, rd942⟩ := hreach - have rd951 := evm_run rd942 with [jumpdest, pop, pop, pop, callvalue] - rw [hwv] at rd951 - have rd963 := evm_run rd951 with [ - push2 ⟨670⟩, jumpiNT (by decide), - push1 ⟨96⟩, calldatasize, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd963 - rw [hslt] at rd963 - exact evm_run rd963 with [ - push2 ⟨670⟩, jumpiT (by decide) (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsClaimX_hugearg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) claimPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsClaimCalldataCheckHuge (I := I) hsize hbig - obtain ⟨_, _, rd942⟩ := hreach - have rd951 := evm_run rd942 with [jumpdest, pop, pop, pop, callvalue] - rw [hwv] at rd951 - have rd963 := evm_run rd951 with [ - push2 ⟨670⟩, jumpiNT (by decide), - push1 ⟨96⟩, calldatasize, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd963 - rw [hslt] at rd963 - exact evm_run rd963 with [ - push2 ⟨670⟩, jumpiT (by decide) (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsClaimX_dec2831_comet {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) claimPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2831⟩ - [⟨970⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt := cometRewardsClaimCalldataCheckOk (I := I) hsz100 hsize hhi - obtain ⟨_, _, rd942⟩ := hreach - have rd951 := evm_run rd942 with [jumpdest, pop, pop, pop, callvalue] - rw [hwv] at rd951 - have rd963 := evm_run rd951 with [ - push2 ⟨670⟩, jumpiNT (by decide), - push1 ⟨96⟩, calldatasize, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd963 - rw [hslt] at rd963 - exact ⟨_, _, evm_run rd963 with [ - push2 ⟨670⟩, jumpiNT (by decide), - push2 ⟨970⟩, push2 ⟨2831⟩, jump (by native_decide)]⟩ - -theorem cometRewardsClaimX_dec970_comet {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) claimPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨970⟩ - [claimCometWord I, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2831⟩ := - cometRewardsClaimX_dec2831_comet (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hsz100 hsize hhi - hreach - exact ⟨_, _, evm_run rd2831 with [ - jumpdest, push1 ⟨4⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32) := by - exact solcAddrMask_clean (by - simpa [claimCometWord, calldataWord] using hcanonComet) - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean] - exact u256_sub_self _), - jump (by native_decide)]⟩ - -theorem cometRewardsClaimX_dec2853_src {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) claimPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2853⟩ - [⟨978⟩, claimCometWord I, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd970⟩ := - cometRewardsClaimX_dec970_comet (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz100 hsize hhi hcanonComet hreach - exact ⟨_, _, evm_run rd970 with [ - jumpdest, push2 ⟨978⟩, push2 ⟨2853⟩, jump (by native_decide)]⟩ - -theorem cometRewardsClaimX_dec978_src {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) claimPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨978⟩ - [claimSrcWord I, claimCometWord I, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2853⟩ := - cometRewardsClaimX_dec2853_src (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz100 hsize hhi hcanonComet hreach - exact ⟨_, _, evm_run rd2853 with [ - jumpdest, push1 ⟨36⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32) := by - exact solcAddrMask_clean (by - simpa [claimSrcWord, calldataWord] using hcanonSrc) - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean] - exact u256_sub_self _), - jump (by native_decide)]⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimX_noncanon_comet {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hnc : UInt256.eq (claimCometWord I) - (UInt256.land (claimCometWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) claimPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2831⟩ := - cometRewardsClaimX_dec2831_comet (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hsz100 hsize hhi - hreach - exact evm_run rd2831 with [ - jumpdest, push1 ⟨4⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hclean : - UInt256.eq (claimCometWord I) - (UInt256.land (claimCometWord I) solcAddrMask) = ⟨1⟩ := by - have heq' : claimCometWord I = - UInt256.land (claimCometWord I) solcAddrMask := by - simpa [claimCometWord, calldataWord] using heq - rw [← heq'] - exact uInt256_eq_self _ - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimX_noncanon_src {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hnc : UInt256.eq (claimSrcWord I) - (UInt256.land (claimSrcWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) claimPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2853⟩ := - cometRewardsClaimX_dec2853_src (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz100 hsize hhi hcanonComet hreach - exact evm_run rd2853 with [ - jumpdest, push1 ⟨36⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hclean : - UInt256.eq (claimSrcWord I) - (UInt256.land (claimSrcWord I) solcAddrMask) = ⟨1⟩ := by - have heq' : claimSrcWord I = - UInt256.land (claimSrcWord I) solcAddrMask := by - simpa [claimSrcWord, calldataWord] using heq - rw [← heq'] - exact uInt256_eq_self _ - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimX_noncanon_bool {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) - (hnz : claimShouldAccrueWord I ≠ ⟨0⟩) (hno : claimShouldAccrueWord I ≠ ⟨1⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) claimPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let word : UInt256 := claimShouldAccrueWord I - have hnzWord : word ≠ ⟨0⟩ := by simpa [word] using hnz - have hnoWord : word ≠ ⟨1⟩ := by simpa [word] using hno - have hiszero : UInt256.isZero word = ⟨0⟩ := isZero_eq_zero_of_ne hnzWord - have hsub : UInt256.sub word (UInt256.isZero (UInt256.isZero word)) ≠ ⟨0⟩ := by - rw [hiszero, show UInt256.isZero (⟨0⟩ : UInt256) = ⟨1⟩ by native_decide] - exact u256_sub_ne_zero_of_ne hnoWord - obtain ⟨_, _, rd978⟩ := - cometRewardsClaimX_dec978_src (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz100 hsize hhi hcanonComet hcanonSrc hreach - have rd992 := evm_run rd978 with [ - jumpdest, push1 ⟨68⟩, calldataload, swap1, dup2, iszero, iszero, dup3, sub] - exact evm_run rd992 with [ - push2 ⟨1004⟩, - jumpiT (by simpa [word, claimShouldAccrueWord, calldataWord] using hsub) (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsClaimX_dec3298_internal {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) - (hbool : claimShouldAccrueWord I = ⟨0⟩ ∨ claimShouldAccrueWord I = ⟨1⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) claimPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3298⟩ - [claimCometWord I, claimSrcWord I, claimSrcWord I, claimShouldAccrueWord I, ⟨1001⟩, - ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hboolSub : - UInt256.sub (claimShouldAccrueWord I) - (UInt256.isZero (UInt256.isZero (claimShouldAccrueWord I))) = ⟨0⟩ := by - rcases hbool with hzero | hone - · rw [hzero] - native_decide - · rw [hone] - native_decide - obtain ⟨_, _, rd978⟩ := - cometRewardsClaimX_dec978_src (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz100 hsize hhi hcanonComet hcanonSrc hreach - have rd992₀ := evm_run rd978 with [ - jumpdest, push1 ⟨68⟩, calldataload, swap1, dup2, iszero, iszero, dup3, sub] - have rd992 := rd992₀ - have hboolSub' : - UInt256.sub (uInt256OfByteArray (I.calldata.readBytes (⟨68⟩ : UInt256).toNat 32)) - (UInt256.isZero - (UInt256.isZero - (uInt256OfByteArray (I.calldata.readBytes (⟨68⟩ : UInt256).toNat 32)))) = - ⟨0⟩ := by - simpa [claimShouldAccrueWord, calldataWord] using hboolSub - rw [hboolSub'] at rd992 - exact ⟨_, _, evm_run rd992 with [ - push2 ⟨1004⟩, jumpiNT (by native_decide), - dup1, push2 ⟨1001⟩, swap4, push2 ⟨3298⟩, jump (by native_decide)]⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_tokenZero_of_reach {cA gh bl σ σ₀ A I} {g : Sat256} - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (htokenZero : rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨3298⟩ - [claimCometWord I, claimSrcWord I, claimSrcWord I, claimShouldAccrueWord I, ⟨1001⟩, - ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd3298⟩ := hreach - have hslot : getRewardOwedRewardConfigSlotOf I = - solcMappingSlot ⟨1⟩ (claimCometWord I) := by - simpa [getRewardOwedCometWord, claimCometWord] using - getRewardOwedRewardConfigSlotOf_eq_solc I - (by simpa [getRewardOwedCometWord, claimCometWord] using hcanonComet) - let slot0 := getRewardOwedRewardConfigSlot0Word σ I - let multiplier := getRewardOwedMultiplierWord σ I - have rd3327pre := evm_run rd3298 with [ - jumpdest, push1 ⟨0⟩, push1 ⟨1⟩, dup1, push1 ⟨160⟩, shl, sub, dup1, - dup4, and, swap5, dup6, dup4, - raw mstore 0 (wordAt0Mem (claimCometWord I) solcFreePtrMem) (UInt256.ofNat 3) - (by decide) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, solcAddrMask_clean hcanonComet] - unfold wordAt0Mem - rfl) - (by decide) (by evm_ov), - push1 ⟨32⟩, swap3, push1 ⟨1⟩, dup5, - raw mstore 0 (claimRewardConfigHashMem I) (UInt256.ofNat 3) (by decide) - mem_cost - (by - unfold claimRewardConfigHashMem twoWordHashMem wordAt32Mem wordAt0Mem - rfl) - (by decide) (by evm_ov), - push1 ⟨64⟩, swap8, dup9, dup3] - have rd3327 := rd3327pre.keccak256 0 (solcMappingSlot ⟨1⟩ (claimCometWord I)) - (UInt256.ofNat 3) (by decide) mem_cost (claimRewardConfigHashMem_keccakSlot I) - (by decide) (by evm_ov) - rw [← hslot] at rd3327 - have rd3330 := evm_run rd3327 with [swap1, dup10] - have rd3330' := evm_run rd3330 with [ - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost (claimRewardConfigHashMem_mload64 I) (by decide) (by evm_ov)] - have rd3340 := evm_run rd3330' with [ - swap2, push2 ⟨3340⟩, dup4, push2 ⟨3025⟩, jump (by jump_dest), - jumpdest, push1 ⟨128⟩, dup2, add, swap1, dup2, lt, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, lor, - push2 ⟨3003⟩, jumpiNT (by native_decide), - push1 ⟨64⟩, - raw mstore 0 (claimConfigAllocMem I) (UInt256.ofNat 3) (by decide) mem_cost - (by - unfold claimConfigAllocMem claimRewardConfigHashMem twoWordHashMem wordAt32Mem wordAt0Mem - rfl) - (by decide) (by evm_ov), - jump (by jump_dest), jumpdest] - have rdAfterSloadPre := evm_run rd3340 with [push1 ⟨1⟩, dup2] - obtain ⟨_, _, rdAfterSload⟩ := rdAfterSloadPre.sload (by decide) (by evm_ov) - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (getRewardOwedRewardConfigSlot0Word σ I :: _) (claimConfigAllocMem I) - (UInt256.ofNat 3) ByteArray.empty (cA, σ) _ _ at rdAfterSload - rw [show getRewardOwedRewardConfigSlot0Word σ I = slot0 from rfl] at rdAfterSload - have rdBeforeMultiplier := evm_run rdAfterSload with [ - swap2, push1 ⟨255⟩, dup9, dup5, and, swap4, dup5, dup8, - raw mstore 6 (claimConfigTokenMem I slot0) (UInt256.ofNat 5) (by decide) mem_cost - (by - unfold claimConfigTokenMem claimConfigAllocMem claimRewardConfigHashMem - unfold twoWordHashMem wordAt32Mem wordAt0Mem - unfold rewardConfigTokenFromSlot0 slot0 - rfl) - (by decide) (by evm_ov), - dup4, dup1, push1 ⟨64⟩, shl, sub, dup2, push1 ⟨160⟩, shr, and, - dup12, dup9, add, - raw mstore 3 (claimConfigRescaleMem I slot0) (UInt256.ofNat 6) (by decide) - mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩ = - UInt256.ofNat (2 ^ 64 - 1) from by native_decide] - unfold claimConfigRescaleMem claimConfigTokenMem claimConfigAllocMem - unfold claimRewardConfigHashMem twoWordHashMem wordAt32Mem wordAt0Mem - unfold rewardConfigRescaleFromSlot0 - unfold rewardConfigTokenFromSlot0 slot0 - rfl) - (by decide) (by evm_ov), - push1 ⟨224⟩, shr, and, iszero, iszero, dup14, dup7, add, - raw mstore 3 (claimConfigShouldMem I slot0) (UInt256.ofNat 7) (by decide) - mem_cost - (by - unfold claimConfigShouldMem claimConfigRescaleMem claimConfigTokenMem - unfold claimConfigAllocMem claimRewardConfigHashMem twoWordHashMem wordAt32Mem wordAt0Mem - unfold rewardConfigShouldUpscaleFromSlot0 - unfold rewardConfigShouldUpscaleRawFromSlot0 rewardConfigRescaleFromSlot0 - unfold rewardConfigTokenFromSlot0 slot0 - rfl) - (by decide) (by evm_ov), - add] - obtain ⟨_, _, rdAfterMultiplier⟩ := rdBeforeMultiplier.sload (by decide) (by evm_ov) - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (getRewardOwedMultiplierWord σ I :: _) (claimConfigShouldMem I slot0) - (UInt256.ofNat 7) ByteArray.empty (cA, σ) _ _ at rdAfterMultiplier - rw [show getRewardOwedMultiplierWord σ I = multiplier from rfl] at rdAfterMultiplier - have rd3387 := evm_run rdAfterMultiplier with [ - push1 ⟨96⟩, dup5, add, - raw mstore 3 (claimConfigMultiplierMem I slot0 multiplier) (UInt256.ofNat 8) - (by decide) mem_cost - (by - unfold claimConfigMultiplierMem claimConfigShouldMem claimConfigRescaleMem - unfold claimConfigTokenMem claimConfigAllocMem claimRewardConfigHashMem - unfold twoWordHashMem wordAt32Mem wordAt0Mem - unfold rewardConfigShouldUpscaleFromSlot0 rewardConfigShouldUpscaleRawFromSlot0 - unfold rewardConfigRescaleFromSlot0 rewardConfigTokenFromSlot0 slot0 multiplier - rfl) - (by decide) (by evm_ov), - iszero] - have htokenZeroSlot : rewardConfigTokenFromSlot0 slot0 = ⟨0⟩ := by - simpa [slot0] using htokenZero - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (UInt256.isZero (rewardConfigTokenFromSlot0 slot0) :: _) - (claimConfigMultiplierMem I slot0 multiplier) (UInt256.ofNat 8) - ByteArray.empty (cA, σ) _ _ at rd3387 - rw [htokenZeroSlot] at rd3387 - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (⟨1⟩ :: _) (claimConfigMultiplierMem I slot0 multiplier) - (UInt256.ofNat 8) ByteArray.empty (cA, σ) _ _ at rd3387 - have rd3636 := evm_run rd3387 with [ - push2 ⟨3636⟩, jumpiT (by native_decide) (by jump_dest)] - have rd3656 := evm_run rd3636 with [ - jumpdest, dup10, - raw mload 0 ⟨256⟩ (UInt256.ofNat 8) (by decide) mem_cost - (claimConfigMultiplierMem_mload64 I slot0 multiplier) (by decide) (by evm_ov), - push4 ⟨1311535579⟩, push1 ⟨225⟩, shl, dup2, - raw mstore 3 (claimInvalidRewardConfigSelectorMem I slot0 multiplier) (UInt256.ofNat 9) - (by decide) mem_cost - (by - unfold claimInvalidRewardConfigSelectorMem claimConfigMultiplierMem claimConfigShouldMem - unfold claimConfigRescaleMem claimConfigTokenMem claimConfigAllocMem - unfold claimRewardConfigHashMem twoWordHashMem wordAt32Mem wordAt0Mem - unfold rewardConfigShouldUpscaleFromSlot0 - unfold rewardConfigShouldUpscaleRawFromSlot0 rewardConfigRescaleFromSlot0 - unfold rewardConfigTokenFromSlot0 slot0 multiplier - rfl) - (by decide) (by evm_ov), - push1 ⟨4⟩, dup2, add, dup11, swap1, - raw mstore 3 (claimInvalidRewardConfigArgMem I slot0 multiplier) (UInt256.ofNat 10) - (by decide) mem_cost - (by - unfold claimInvalidRewardConfigArgMem claimInvalidRewardConfigSelectorMem - unfold claimConfigMultiplierMem claimConfigShouldMem claimConfigRescaleMem - unfold claimConfigTokenMem claimConfigAllocMem claimRewardConfigHashMem - unfold twoWordHashMem wordAt32Mem wordAt0Mem - unfold rewardConfigShouldUpscaleFromSlot0 rewardConfigShouldUpscaleRawFromSlot0 - unfold rewardConfigRescaleFromSlot0 rewardConfigTokenFromSlot0 slot0 multiplier - rw [show ((⟨256⟩ : UInt256) + ⟨4⟩).toNat = 260 from by native_decide] - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, solcAddrMask_clean hcanonComet] - unfold Reasoning.Theory.writeWord - rfl) - (by decide) (by evm_ov), - push1 ⟨36⟩, swap1] - exact evm_run rd3656 with [raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_noAccrue_call_baseTracking - {cA gh bl σ σ₀ A I} {g : Sat256} - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) - (htokenNZ : - rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) ≠ ⟨0⟩) - (hshouldZero : claimShouldAccrueWord I = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨3298⟩ - [claimCometWord I, claimSrcWord I, claimSrcWord I, claimShouldAccrueWord I, ⟨1001⟩, - ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ gasArg k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) claimBaseTrackingCallPc - (gasArg :: UInt256.land (claimCometWord I) solcAddrMask :: - ⟨256⟩ :: claimBaseTrackingCallSize :: ⟨256⟩ :: ⟨32⟩ :: - claimBaseTrackingPostCallTail I (getRewardOwedClaimedWord σ I)) - (claimBaseTrackingCalldataMem I (getRewardOwedRewardConfigSlot0Word σ I) - (getRewardOwedMultiplierWord σ I)) - claimBaseTrackingCallAw ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd3298⟩ := hreach - have hslot : getRewardOwedRewardConfigSlotOf I = - solcMappingSlot ⟨1⟩ (claimCometWord I) := by - simpa [getRewardOwedCometWord, claimCometWord] using - getRewardOwedRewardConfigSlotOf_eq_solc I - (by simpa [getRewardOwedCometWord, claimCometWord] using hcanonComet) - let slot0 := getRewardOwedRewardConfigSlot0Word σ I - let multiplier := getRewardOwedMultiplierWord σ I - have rd3327pre := evm_run rd3298 with [ - jumpdest, push1 ⟨0⟩, push1 ⟨1⟩, dup1, push1 ⟨160⟩, shl, sub, dup1, - dup4, and, swap5, dup6, dup4, - raw mstore 0 (wordAt0Mem (claimCometWord I) solcFreePtrMem) (UInt256.ofNat 3) - (by decide) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, solcAddrMask_clean hcanonComet] - unfold wordAt0Mem - rfl) - (by decide) (by evm_ov), - push1 ⟨32⟩, swap3, push1 ⟨1⟩, dup5, - raw mstore 0 (claimRewardConfigHashMem I) (UInt256.ofNat 3) (by decide) - mem_cost - (by - unfold claimRewardConfigHashMem twoWordHashMem wordAt32Mem wordAt0Mem - rfl) - (by decide) (by evm_ov), - push1 ⟨64⟩, swap8, dup9, dup3] - have rd3327 := rd3327pre.keccak256 0 (solcMappingSlot ⟨1⟩ (claimCometWord I)) - (UInt256.ofNat 3) (by decide) mem_cost (claimRewardConfigHashMem_keccakSlot I) - (by decide) (by evm_ov) - rw [← hslot] at rd3327 - have rd3330 := evm_run rd3327 with [swap1, dup10] - have rd3330' := evm_run rd3330 with [ - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost (claimRewardConfigHashMem_mload64 I) (by decide) (by evm_ov)] - have rd3340 := evm_run rd3330' with [ - swap2, push2 ⟨3340⟩, dup4, push2 ⟨3025⟩, jump (by jump_dest), - jumpdest, push1 ⟨128⟩, dup2, add, swap1, dup2, lt, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, lor, - push2 ⟨3003⟩, jumpiNT (by native_decide), - push1 ⟨64⟩, - raw mstore 0 (claimConfigAllocMem I) (UInt256.ofNat 3) (by decide) mem_cost - (by - unfold claimConfigAllocMem claimRewardConfigHashMem twoWordHashMem wordAt32Mem wordAt0Mem - rfl) - (by decide) (by evm_ov), - jump (by jump_dest), jumpdest] - have rdAfterSloadPre := evm_run rd3340 with [push1 ⟨1⟩, dup2] - obtain ⟨_, _, rdAfterSload⟩ := rdAfterSloadPre.sload (by decide) (by evm_ov) - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (getRewardOwedRewardConfigSlot0Word σ I :: _) (claimConfigAllocMem I) - (UInt256.ofNat 3) ByteArray.empty (cA, σ) _ _ at rdAfterSload - rw [show getRewardOwedRewardConfigSlot0Word σ I = slot0 from rfl] at rdAfterSload - have rdBeforeMultiplier := evm_run rdAfterSload with [ - swap2, push1 ⟨255⟩, dup9, dup5, and, swap4, dup5, dup8, - raw mstore 6 (claimConfigTokenMem I slot0) (UInt256.ofNat 5) (by decide) mem_cost - (by - unfold claimConfigTokenMem claimConfigAllocMem claimRewardConfigHashMem - unfold twoWordHashMem wordAt32Mem wordAt0Mem - unfold rewardConfigTokenFromSlot0 slot0 - rfl) - (by decide) (by evm_ov), - dup4, dup1, push1 ⟨64⟩, shl, sub, dup2, push1 ⟨160⟩, shr, and, - dup12, dup9, add, - raw mstore 3 (claimConfigRescaleMem I slot0) (UInt256.ofNat 6) (by decide) - mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩ = - UInt256.ofNat (2 ^ 64 - 1) from by native_decide] - unfold claimConfigRescaleMem claimConfigTokenMem claimConfigAllocMem - unfold claimRewardConfigHashMem twoWordHashMem wordAt32Mem wordAt0Mem - unfold rewardConfigRescaleFromSlot0 - unfold rewardConfigTokenFromSlot0 slot0 - rfl) - (by decide) (by evm_ov), - push1 ⟨224⟩, shr, and, iszero, iszero, dup14, dup7, add, - raw mstore 3 (claimConfigShouldMem I slot0) (UInt256.ofNat 7) (by decide) - mem_cost - (by - unfold claimConfigShouldMem claimConfigRescaleMem claimConfigTokenMem - unfold claimConfigAllocMem claimRewardConfigHashMem twoWordHashMem wordAt32Mem wordAt0Mem - unfold rewardConfigShouldUpscaleFromSlot0 - unfold rewardConfigShouldUpscaleRawFromSlot0 rewardConfigRescaleFromSlot0 - unfold rewardConfigTokenFromSlot0 slot0 - rfl) - (by decide) (by evm_ov), - add] - obtain ⟨_, _, rdAfterMultiplier⟩ := rdBeforeMultiplier.sload (by decide) (by evm_ov) - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (getRewardOwedMultiplierWord σ I :: _) (claimConfigShouldMem I slot0) - (UInt256.ofNat 7) ByteArray.empty (cA, σ) _ _ at rdAfterMultiplier - rw [show getRewardOwedMultiplierWord σ I = multiplier from rfl] at rdAfterMultiplier - have rd3387 := evm_run rdAfterMultiplier with [ - push1 ⟨96⟩, dup5, add, - raw mstore 3 (claimConfigMultiplierMem I slot0 multiplier) (UInt256.ofNat 8) - (by decide) mem_cost - (by - unfold claimConfigMultiplierMem claimConfigShouldMem claimConfigRescaleMem - unfold claimConfigTokenMem claimConfigAllocMem claimRewardConfigHashMem - unfold twoWordHashMem wordAt32Mem wordAt0Mem - unfold rewardConfigShouldUpscaleFromSlot0 rewardConfigShouldUpscaleRawFromSlot0 - unfold rewardConfigRescaleFromSlot0 rewardConfigTokenFromSlot0 slot0 multiplier - rfl) - (by decide) (by evm_ov), - iszero] - have htokenNZSlot : rewardConfigTokenFromSlot0 slot0 ≠ ⟨0⟩ := by - simpa [slot0] using htokenNZ - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (UInt256.isZero (rewardConfigTokenFromSlot0 slot0) :: _) - (claimConfigMultiplierMem I slot0 multiplier) (UInt256.ofNat 8) - ByteArray.empty (cA, σ) _ _ at rd3387 - rw [isZero_eq_zero_of_ne htokenNZSlot] at rd3387 - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (⟨0⟩ :: _) (claimConfigMultiplierMem I slot0 multiplier) - (UInt256.ofNat 8) ByteArray.empty (cA, σ) _ _ at rd3387 - have rd3396 := evm_run rd3387 with [ - push2 ⟨3636⟩, jumpiNT (by native_decide), - push2 ⟨3556⟩, jumpiNT (by simpa [hshouldZero])] - have rd3400 := evm_run rd3396 with [ - jumpdest, dup8, dup3, - raw mstore 0 - (wordAt0Mem (UInt256.land (claimCometWord I) solcAddrMask) - (claimConfigMultiplierMem I slot0 multiplier)) - (UInt256.ofNat 8) (by native_decide) mem_cost - (by - unfold wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have rd3404 := evm_run rd3400 with [ - push1 ⟨2⟩, dup6, - raw mstore 0 (claimClaimedInnerHashMem I slot0 multiplier) - (UInt256.ofNat 8) (by native_decide) mem_cost - (by - unfold claimClaimedInnerHashMem twoWordHashMem wordAt32Mem wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have hinnerHash : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((claimClaimedInnerHashMem I slot0 multiplier) - |>.readWithPadding 0 64))) = - solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask) := by - unfold claimClaimedInnerHashMem - exact twoWordHashMem_solcMappingSlot_of_ge ⟨2⟩ - (UInt256.land (claimCometWord I) solcAddrMask) - (by rw [claimConfigMultiplierMem_size]; decide) - have rd3411pre := evm_run rd3404 with [push2 ⟨3432⟩, dup2, dup11, dup5] - have rd3411 := rd3411pre.keccak256 0 - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - (UInt256.ofNat 8) (by native_decide) mem_cost - hinnerHash (by native_decide) (by evm_ov) - have rd3419 := evm_run rd3411 with [ - swap9, dup7, dup2, and, swap10, dup11, push1 ⟨0⟩, - raw mstore 0 - (wordAt0Mem (UInt256.land (claimSrcWord I) solcAddrMask) - (claimClaimedInnerHashMem I slot0 multiplier)) - (UInt256.ofNat 8) (by native_decide) mem_cost - (by - unfold wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have rd3421 := evm_run rd3419 with [ - dup9, - raw mstore 0 (claimClaimedOuterHashMem I slot0 multiplier) - (UInt256.ofNat 8) (by native_decide) mem_cost - (by - unfold claimClaimedOuterHashMem twoWordHashMem wordAt32Mem wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have houterHash := claimClaimedOuterHashMem_keccakSlot I slot0 multiplier - hcanonComet hcanonSrc - have rd3426pre := (evm_run rd3421 with [dup12, push1 ⟨0⟩]).keccak256 0 - (getRewardOwedRewardsClaimedSlotOf I) - (UInt256.ofNat 8) (by native_decide) mem_cost - houterHash (by native_decide) (by evm_ov) - obtain ⟨_, _, rd3427₀⟩ := rd3426pre.sload (by native_decide) (by evm_ov) - obtain ⟨_, _, rd3427⟩ : ∃ k1 C1, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨3427⟩ - [getRewardOwedClaimedWord σ I, claimSrcWord I, ⟨128⟩, ⟨3432⟩, ⟨128⟩, - ⟨0⟩, claimSrcWord I, solcAddrMask, ⟨32⟩, claimCometWord I, - UInt256.land (claimSrcWord I) solcAddrMask, - UInt256.land (claimCometWord I) solcAddrMask, ⟨64⟩, ⟨1001⟩, ⟨64⟩, ⟨0⟩] - (claimClaimedOuterHashMem I slot0 multiplier) - (UInt256.ofNat 8) ByteArray.empty (cA, σ) k1 C1 := by - exact ⟨_, _, by - simpa [getRewardOwedClaimedWord] using rd3427₀⟩ - have rd3679 := evm_run rd3427 with [swap9, push2 ⟨3679⟩, jump (by jump_dest)] - have rd3682 := evm_run rd3679 with [ - jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨256⟩ (UInt256.ofNat 8) (by native_decide) - mem_cost - (claimClaimedOuterHashMem_mload64 I slot0 multiplier) - (by native_decide) (by evm_ov)] - have rd3692 := evm_run rd3682 with [ - push4 ⟨719776253⟩, push1 ⟨226⟩, shl, dup2, - raw mstore 3 (claimBaseTrackingSelectorMem I slot0 multiplier) - (UInt256.ofNat 9) (by native_decide) mem_cost - (by - unfold claimBaseTrackingSelectorMem - rfl) - (by native_decide) (by evm_ov)] - have hcleanSrc : - UInt256.land solcAddrMask (claimSrcWord I) = claimSrcWord I := by - rw [u256_land_comm] - exact solcAddrMask_clean hcanonSrc - have rd3708 := evm_run rd3692 with [ - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, swap3, dup4, and, - push1 ⟨4⟩, dup3, add, - raw mstore 3 (claimBaseTrackingCalldataMem I slot0 multiplier) - claimBaseTrackingCallAw (by native_decide) mem_cost - (by - rw [show ((⟨256⟩ : UInt256) + ⟨4⟩).toNat = 260 from by native_decide] - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - rw [hcleanSrc] - unfold claimBaseTrackingCalldataMem claimBaseTrackingSelectorMem - rfl) - (by native_decide) (by evm_ov)] - obtain ⟨gasArg, rd3723⟩ := evm_run rd3708 with [ - swap3, swap2, push1 ⟨32⟩, swap2, dup5, swap2, push1 ⟨36⟩, - swap2, dup4, swap2, and, gas] - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] at rd3723 - rw [u256_land_comm solcAddrMask (claimCometWord I)] at rd3723 - exact ⟨gasArg, _, _, by - simpa [claimBaseTrackingCallPc, claimBaseTrackingCallSize, claimBaseTrackingPostCallTail, - claimBaseTrackingCallAw] using rd3723⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_noAccrue_call_baseTracking_made - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) - (hdepth : I.depth.val < 1024) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (htokenNZ : - rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ_evm I) ≠ ⟨0⟩) - (hshouldZero : claimShouldAccrueWord I = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ_evm σ₀ g A I) ⟨3298⟩ - [claimCometWord I, claimSrcWord I, claimSrcWord I, claimShouldAccrueWord I, ⟨1001⟩, - ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ_evm) k C) : - ∃ cA' σ'_evm σ'_solm A'_solm z baseOut k' C', - typedCallViaEVM config - (initState cA gh bl σ_solm σ₀ g A I) - (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (z, - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' }, - baseOut) false ∧ - accountMapEquiv σ'_evm σ'_solm ∧ - RD cometRewardsBytecode I g (initState cA gh bl σ_evm σ₀ g A I) - (claimBaseTrackingCallPc + ⟨1⟩) - (claimBaseTrackingPostCallStack I z (getRewardOwedClaimedWord σ_evm I)) - (claimBaseTrackingPostCallMem I (getRewardOwedRewardConfigSlot0Word σ_evm I) - (getRewardOwedMultiplierWord σ_evm I) baseOut) - claimBaseTrackingPostCallAw baseOut (cA', σ'_evm) k' C' ∧ - baseOut.size < UInt256.size ∧ - baseOut.size < 2 ^ 255 := by - let slot0 := getRewardOwedRewardConfigSlot0Word σ_evm I - let multiplier := getRewardOwedMultiplierWord σ_evm I - obtain ⟨gasArg, k0, C0, rd3723⟩ := - cometRewardsClaimInternalX_noAccrue_call_baseTracking - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hcanonComet hcanonSrc htokenNZ - hshouldZero hreach - have rd3723Call : - RD cometRewardsBytecode I g (initState cA gh bl σ_evm σ₀ g A I) - claimBaseTrackingCallPc - (gasArg :: UInt256.land (claimCometWord I) solcAddrMask :: - ⟨256⟩ :: claimBaseTrackingCallSize :: ⟨256⟩ :: ⟨32⟩ :: - claimBaseTrackingPostCallTail I (getRewardOwedClaimedWord σ_evm I)) - (claimBaseTrackingCalldataMem I slot0 multiplier) - claimBaseTrackingCallAw ByteArray.empty (cA, σ_evm) k0 C0 := by - simpa [slot0, multiplier, claimBaseTrackingPostCallTail] using rd3723 - have hdecCall : - decode cometRewardsBytecode claimBaseTrackingCallPc = - some (.STATICCALL, .none) := by - unfold claimBaseTrackingCallPc getRewardOwedBaseTrackingCallPc - native_decide - obtain ⟨cA', σ'_evm, z, baseOut, A_in, callGas, k', C', hΘ, rd3724, - _houtSize⟩ := - RD.solcStaticcall (t := - claimBaseTrackingPostCallTail I (getRewardOwedClaimedWord σ_evm I)) - rd3723Call hdecCall hdepth - (by simp [claimBaseTrackingPostCallTail]) - obtain ⟨g'', A'_evm, hΘeq⟩ := hΘ - let evmEBase : EVM.State := initState cA gh bl σ_evm σ₀ g A I - let evmSBase : EVM.State := initState cA gh bl σ_solm σ₀ g A I - have houtSmall : baseOut.size < 2 ^ 138 := by - exact Theta_returnData_size_lt_2pow138_of_eq - (blob := I.blobVersionedHashes) (cA := cA) - (gh := (initState cA gh bl σ_evm σ₀ g A I).genesisBlockHeader) - (blocks := (initState cA gh bl σ_evm σ₀ g A I).blocks) - (σ := σ_evm) - (σ₀ := (initState cA gh bl σ_evm σ₀ g A I).σ₀) - (A := A_in) - (s := AccountAddress.ofUInt256 (UInt256.ofNat I.codeOwner)) - (o := I.sender) - (r := AccountAddress.ofUInt256 (UInt256.land (claimCometWord I) solcAddrMask)) - (c := toExecute σ_evm - (AccountAddress.ofUInt256 (UInt256.land (claimCometWord I) solcAddrMask))) - (g := callGas) (p := UInt256.ofNat I.gasPrice) - (v := ⟨0⟩) (v' := ⟨0⟩) - (d := (claimBaseTrackingCalldataMem I slot0 multiplier) - |>.readWithPadding 256 claimBaseTrackingCallSize.toNat) - (e := I.depth + 1) (H := I.header) (w := false) - hΘeq - (by exact Ethereum.EVM.ByteArray.readWithPadding_size_lt_uint256 _ _ _) - have houtUInt : baseOut.size < UInt256.size := by - have hsz : UInt256.size = 2 ^ 256 := by decide - omega - have hdepthNeI : I.depth ≠ 1024 := by - intro hEq - rw [hEq] at hdepth - exact absurd hdepth (by decide) - have hdepthNe : evmEBase.executionEnv.depth ≠ 1024 := by - simpa [evmEBase, initState] using hdepthNeI - have htgt : - EVM.address (getRewardOwedCometTarget I) = - AccountAddress.ofUInt256 (UInt256.land (claimCometWord I) solcAddrMask) := by - simpa [getRewardOwedCometWord, claimCometWord] using - getRewardOwedCometTarget_eq_targetWord I - (by simpa [getRewardOwedCometWord, claimCometWord] using hcanonComet) - have hcd := claimBaseTrackingCalldataMem_encode_args I slot0 multiplier hcanonSrc - have hcallE : - typedCallViaEVM config evmEBase - (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (z, - { evmEBase with - accountMap := σ'_evm - substate := A'_evm - createdAccounts := cA' }, - baseOut) false := by - refine callCoincides - (cfg := config) (evm := evmEBase) - (name := "baseTrackingAccrued") (args := getRewardAccruedBaseTrackingArgs I) - (tgt := EVM.address (getRewardOwedCometTarget I)) - (targetWord := UInt256.land (claimCometWord I) solcAddrMask) - (cA' := cA') (σ' := σ'_evm) (A' := A'_evm) (A_in := A_in) - (z := z) (o := baseOut) (g'' := g'') (callGas := callGas) - (mem := claimBaseTrackingCalldataMem I slot0 multiplier) - (inOff := ⟨256⟩) (inSize := claimBaseTrackingCallSize) - (callPerm := false) - hdepthNe htgt hcd ?_ - simpa [evmEBase, initState] using hΘeq - obtain ⟨σ'_solm, A'_solm, hcallSolm, hPostAccounts'⟩ := - typedCallViaEVM_accountMapEquiv - (evm_solm := evmSBase) hcallE - (by simpa [evmEBase, evmSBase, initState] using hAccounts) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase, initState]) - exact ⟨cA', σ'_evm, σ'_solm, A'_solm, z, baseOut, k', C', - by - simpa [evmSBase, initState] using hcallSolm, - hPostAccounts', - by - simpa [claimBaseTrackingPostCallStack, claimBaseTrackingPostCallTail, - claimBaseTrackingPostCallMem, claimBaseTrackingPostCallAw, claimBaseTrackingCallSize, - slot0, multiplier] using rd3724, - houtUInt, - by omega⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_after_baseTracking_failure - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier claimed : UInt256} {baseOut : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (claimBaseTrackingCallPc + ⟨1⟩) - (claimBaseTrackingPostCallStack I false claimed) - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C) - (hbaseSize : baseOut.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have rd3724 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3724⟩ - (⟨0⟩ :: claimBaseTrackingPostCallTail I claimed) - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C := by - simpa [claimBaseTrackingCallPc, claimBaseTrackingPostCallStack, - claimBaseTrackingPostCallTail] using rd - have rd3876 := evm_run rd3724 with [ - swap2, dup3, iszero, push2 ⟨3876⟩, jumpiT (by native_decide) (by jump_dest)] - have rd3879 := evm_run rd3876 with [ - jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨256⟩ claimBaseTrackingPostCallAw (by native_decide) - mem_cost - (claimBaseTrackingPostCallMem_mload64 I slot0 multiplier hbaseSize) - (by native_decide) (by evm_ov)] - let rdsz : UInt256 := UInt256.ofNat baseOut.size - have hrdsz_toNat : rdsz.toNat = baseOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hbaseSize - have rd3883pre := evm_run rd3879 with [returndatasize, push1 ⟨0⟩, dup3] - let mem2 : ByteArray := - baseOut.write 0 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut) - 256 rdsz.toNat - let aw2 : UInt256 := - UInt256.ofNat (MachineState.M claimBaseTrackingPostCallAw.toNat 256 rdsz.toNat) - have rd3884 := RD.returndatacopy - (Cₘ aw2 - Cₘ claimBaseTrackingPostCallAw) mem2 aw2 rd3883pre - (by native_decide) - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, hrdsz_toNat]; omega) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, aw2, rdsz] - change - Cₘ (UInt256.ofNat - (MachineState.M claimBaseTrackingPostCallAw.toNat 256 - (UInt256.ofNat baseOut.size).toNat)) - - Cₘ claimBaseTrackingPostCallAw = - Cₘ (UInt256.ofNat - (MachineState.M claimBaseTrackingPostCallAw.toNat 256 - (UInt256.ofNat baseOut.size).toNat)) - - Cₘ claimBaseTrackingPostCallAw - rfl) - (by rfl) - (by rfl) - (by simp) - have rd3886 := evm_run rd3884 with [returndatasize, swap1] - exact RD.rev - (Cₘ (UInt256.ofNat (MachineState.M aw2.toNat 256 rdsz.toNat)) - Cₘ aw2) - rd3886 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, rdsz] - change - Cₘ (UInt256.ofNat - (MachineState.M aw2.toNat 256 (UInt256.ofNat baseOut.size).toNat)) - - Cₘ aw2 = - Cₘ (UInt256.ofNat - (MachineState.M aw2.toNat 256 (UInt256.ofNat baseOut.size).toNat)) - - Cₘ aw2 - rfl) - (by simp) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_noAccrue_callDepthLimit - {cA gh bl σ σ₀ A I} {g : Sat256} - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) - (htokenNZ : - rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) ≠ ⟨0⟩) - (hshouldZero : claimShouldAccrueWord I = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨3298⟩ - [claimCometWord I, claimSrcWord I, claimSrcWord I, claimShouldAccrueWord I, ⟨1001⟩, - ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hdepth : I.depth = 1024) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨gasArg, k0, C0, rd3723⟩ := - cometRewardsClaimInternalX_noAccrue_call_baseTracking - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hcanonComet hcanonSrc htokenNZ - hshouldZero hreach - let slot0 := getRewardOwedRewardConfigSlot0Word σ I - let multiplier := getRewardOwedMultiplierWord σ I - have rd3723Call : - RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - claimBaseTrackingCallPc - (gasArg :: UInt256.land (claimCometWord I) solcAddrMask :: - ⟨256⟩ :: claimBaseTrackingCallSize :: ⟨256⟩ :: ⟨32⟩ :: - claimBaseTrackingPostCallTail I (getRewardOwedClaimedWord σ I)) - (claimBaseTrackingCalldataMem I slot0 multiplier) - claimBaseTrackingCallAw ByteArray.empty (cA, σ) k0 C0 := by - simpa [slot0, multiplier, claimBaseTrackingPostCallTail] using rd3723 - have hdecCall : - decode cometRewardsBytecode claimBaseTrackingCallPc = - some (.STATICCALL, .none) := by - unfold claimBaseTrackingCallPc getRewardOwedBaseTrackingCallPc - native_decide - have hdepthInit : - (initState cA gh bl σ σ₀ g A I).executionEnv.depth = 1024 := by - simpa [initState] using hdepth - obtain ⟨k', C', rdPost₀⟩ := - RD.solcStaticcallDepthLimit - (t := claimBaseTrackingPostCallTail I (getRewardOwedClaimedWord σ I)) - rd3723Call hdecCall hdepthInit (by simp [claimBaseTrackingPostCallTail]) - have rdPost : - RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) - (claimBaseTrackingCallPc + ⟨1⟩) - (claimBaseTrackingPostCallStack I false (getRewardOwedClaimedWord σ I)) - (claimBaseTrackingPostCallMem I slot0 multiplier ByteArray.empty) - claimBaseTrackingPostCallAw ByteArray.empty (cA, σ) k' C' := by - simpa [claimBaseTrackingPostCallStack, claimBaseTrackingPostCallTail, - claimBaseTrackingPostCallMem, claimBaseTrackingPostCallAw, claimBaseTrackingCallSize, - slot0, multiplier] using rdPost₀ - exact cometRewardsClaimInternalX_after_baseTracking_failure - (slot0 := slot0) (multiplier := multiplier) - (claimed := getRewardOwedClaimedWord σ I) rdPost (by simp [UInt256.size]) - -set_option maxHeartbeats 2000000 in -theorem cometRewardsClaimInternalX_after_baseTracking_short_revert - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier claimed : UInt256} {baseOut : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (claimBaseTrackingCallPc + ⟨1⟩) - (claimBaseTrackingPostCallStack I true claimed) - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C) - (hshort : baseOut.size < 32) (hbaseSize : baseOut.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let rdsz : UInt256 := UInt256.ofNat baseOut.size - have hrdsz_toNat : rdsz.toNat = baseOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hbaseSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨1⟩ := by - apply ugt_one - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hshort - have rd3724 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3724⟩ - (⟨1⟩ :: claimBaseTrackingPostCallTail I claimed) - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C := by - simpa [claimBaseTrackingCallPc, claimBaseTrackingPostCallStack, - claimBaseTrackingPostCallTail] using rd - have rd3855₀ := evm_run rd3724 with [ - swap2, dup3, iszero, push2 ⟨3876⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap3, push2 ⟨3844⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push2 ⟨3869⟩, swap2, swap3, pop, push1 ⟨32⟩, - returndatasize, dup2, gt] - have rd3855 := rd3855₀ - rw [show UInt256.ofNat baseOut.size = rdsz from rfl, hgt] at rd3855 - let rounded : UInt256 := - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat baseOut.size + ⟨31⟩) - let ptr : UInt256 := (⟨256⟩ : UInt256) + rounded - have hroundedLe : rounded.toNat ≤ baseOut.size + 31 := by - unfold rounded - rw [uland_toNat] - refine le_trans Nat.and_le_right ?_ - rw [uadd_toNat, UInt256.toNat_ofNat_of_lt hbaseSize, - show (⟨31⟩ : UInt256).toNat = 31 from by decide] - exact Nat.mod_le _ _ - have hptr_toNat : ptr.toNat = 256 + rounded.toNat := by - unfold ptr - rw [uadd_toNat, show (⟨256⟩ : UInt256).toNat = 256 from by decide] - exact Nat.mod_eq_of_lt (by - have hroundSmall : rounded.toNat < 64 := by omega - have hsz : UInt256.size = 2 ^ 256 := by decide - omega) - have hltPtr : UInt256.lt ptr (⟨256⟩ : UInt256) = ⟨0⟩ := by - apply ult_zero - rw [hptr_toNat, show (⟨256⟩ : UInt256).toNat = 256 from by decide] - omega - have hmax64 : - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩).toNat = - 18446744073709551615 := by - native_decide - have hgtPtr : - UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - rw [hptr_toNat, hmax64] - omega - have hallocOk : - UInt256.lor (UInt256.lt ptr (⟨256⟩ : UInt256)) - (UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = ⟨0⟩ := by - rw [hltPtr, hgtPtr] - native_decide - have rd3071 := evm_run rd3855 with [ - push2 ⟨734⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, pop, returndatasize, push2 ⟨709⟩, jump (by jump_dest), - jumpdest, push2 ⟨719⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, - jumpiNT (by simpa [ptr, rounded] using hallocOk), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 - (claimBaseTrackingPostShortDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]) - (by native_decide) (by evm_ov)] - have rd3106 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3106⟩, - jump (by jump_dest)] - have hlenCheck : - UInt256.slt (UInt256.sub ((⟨256⟩ : UInt256) + rdsz) ⟨256⟩) ⟨32⟩ = - ⟨1⟩ := by - simpa [rdsz] using - solcReturnStaticLenCheckShort (base := 256) (words := 1) (by simpa using hshort) - (by norm_num [UInt256.size]) - (by - have hsz : UInt256.size = 2 ^ 256 := by decide - omega) - (by norm_num) - have rd3114₀ := evm_run rd3106 with [ - jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, slt] - have rd3114 := rd3114₀ - rw [hlenCheck] at rd3114 - have rd1004 := evm_run rd3114 with [ - push2 ⟨1004⟩, jumpiT (by native_decide) (by jump_dest)] - exact evm_run rd1004 with [ - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsClaimInternalX_after_baseTracking_noncanon_revert - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier claimed : UInt256} {baseOut : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (claimBaseTrackingCallPc + ⟨1⟩) - (claimBaseTrackingPostCallStack I true claimed) - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : ¬ (claimBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let baseWord : UInt256 := claimBaseTrackingReturnWord baseOut - have hbase64' : ¬ baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - let rdsz : UInt256 := UInt256.ofNat baseOut.size - have hrdsz_toNat : rdsz.toNat = baseOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hbaseSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hout32 - have rd3724 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3724⟩ - (⟨1⟩ :: claimBaseTrackingPostCallTail I claimed) - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C := by - simpa [claimBaseTrackingCallPc, claimBaseTrackingPostCallStack, - claimBaseTrackingPostCallTail] using rd - have rd3855₀ := evm_run rd3724 with [ - swap2, dup3, iszero, push2 ⟨3876⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap3, push2 ⟨3844⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push2 ⟨3869⟩, swap2, swap3, pop, push1 ⟨32⟩, - returndatasize, dup2, gt] - have rd3855 := rd3855₀ - rw [show UInt256.ofNat baseOut.size = rdsz from rfl, hgt] at rd3855 - have rd3071 := evm_run rd3855 with [ - push2 ⟨734⟩, jumpiNT (by native_decide), - push2 ⟨719⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), - push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold claimBaseTrackingPostDecodeMem Reasoning.Theory.writeWord - rfl) - (by native_decide) (by evm_ov)] - have rd3106 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3106⟩, - jump (by jump_dest), jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, - slt, push2 ⟨1004⟩, jumpiNT (by native_decide)] - have rd3129 := evm_run rd3106 with [ - raw mload 0 baseWord claimBaseTrackingPostCallAw (by native_decide) - mem_cost - (by - simpa [baseWord] using - claimBaseTrackingPostDecodeMem_mload256_of_size_ge - I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, and, dup2, sub] - have hnotClean : UInt256.land baseWord uint64Mask ≠ baseWord := - uint64Mask_not_clean hbase64' - have hneq : - baseWord ≠ - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) := by - intro hEq - exact hnotClean (by simpa [uint64Mask] using hEq.symm) - have hsub : - UInt256.sub baseWord - (UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) ≠ ⟨0⟩ := - u256_sub_ne_zero_of_ne hneq - have rd1004 := evm_run rd3129 with [ - push2 ⟨1004⟩, jumpiT hsub (by jump_dest)] - exact evm_run rd1004 with [ - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsClaimInternalX_after_baseTracking_decode_ok - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier claimed : UInt256} {baseOut : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (claimBaseTrackingCallPc + ⟨1⟩) - (claimBaseTrackingPostCallStack I true claimed) - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : (claimBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) : - ∃ k' C', RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3740⟩ - [⟨128⟩, claimBaseTrackingReturnWord baseOut, ⟨3432⟩, - ⟨128⟩, ⟨0⟩, claimSrcWord I, solcAddrMask, ⟨32⟩, claimed, - UInt256.land (claimSrcWord I) solcAddrMask, - UInt256.land (claimCometWord I) solcAddrMask, ⟨64⟩, ⟨1001⟩, ⟨64⟩, ⟨0⟩] - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k' C' := by - let baseWord : UInt256 := claimBaseTrackingReturnWord baseOut - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - let rdsz : UInt256 := UInt256.ofNat baseOut.size - have hrdsz_toNat : rdsz.toNat = baseOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hbaseSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hout32 - have rd3724 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3724⟩ - (⟨1⟩ :: claimBaseTrackingPostCallTail I claimed) - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C := by - simpa [claimBaseTrackingCallPc, claimBaseTrackingPostCallStack, - claimBaseTrackingPostCallTail] using rd - have rd3855₀ := evm_run rd3724 with [ - swap2, dup3, iszero, push2 ⟨3876⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap3, push2 ⟨3844⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push2 ⟨3869⟩, swap2, swap3, pop, push1 ⟨32⟩, - returndatasize, dup2, gt] - have rd3855 := rd3855₀ - rw [show UInt256.ofNat baseOut.size = rdsz from rfl, hgt] at rd3855 - have rd3071 := evm_run rd3855 with [ - push2 ⟨734⟩, jumpiNT (by native_decide), - push2 ⟨719⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), - push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold claimBaseTrackingPostDecodeMem Reasoning.Theory.writeWord - rfl) - (by native_decide) (by evm_ov)] - have rd3106 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3106⟩, - jump (by jump_dest), jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, - slt, push2 ⟨1004⟩, jumpiNT (by native_decide)] - have rd3129 := evm_run rd3106 with [ - raw mload 0 baseWord claimBaseTrackingPostCallAw (by native_decide) - mem_cost - (by - simpa [baseWord] using - claimBaseTrackingPostDecodeMem_mload256_of_size_ge - I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, and, dup2, sub] - have hclean : UInt256.land baseWord uint64Mask = baseWord := - uint64Mask_clean hbase64' - have hcleanExpanded : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using hclean - have hsub : - UInt256.sub baseWord - (UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) = ⟨0⟩ := by - rw [hcleanExpanded] - exact u256_sub_self baseWord - have rd3129zero := rd3129 - rw [hsub] at rd3129zero - have rd3869 := evm_run rd3129zero with [ - push2 ⟨1004⟩, jumpiNT (by native_decide), swap1, jump (by jump_dest)] - have rd3739 := evm_run rd3869 with [ - jumpdest, swap1, codesize, push2 ⟨3738⟩, jump (by jump_dest), - jumpdest, pop] - exact ⟨_, _, by - simpa [baseWord, claimBaseTrackingReturnWord] using rd3739⟩ - -set_option maxHeartbeats 2000000 in -theorem cometRewardsClaimInternalX_getRewardAccrued_upscale_success - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3740⟩ - [⟨128⟩, claimBaseTrackingReturnWord baseOut, ⟨3432⟩, - ⟨128⟩, ⟨0⟩, claimSrcWord I, solcAddrMask, ⟨32⟩, claimed, - UInt256.land (claimSrcWord I) solcAddrMask, - UInt256.land (claimCometWord I) solcAddrMask, ⟨64⟩, ⟨1001⟩, ⟨64⟩, ⟨0⟩] - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : (claimBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 ≠ ⟨0⟩) - (hscaled : - getRewardAccruedScaledNat multiplier - (getRewardAccruedUpscaledNat slot0 (claimBaseTrackingReturnWord baseOut)) < - UInt256.size) : - ∃ k' C', RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3432⟩ - [ UInt256.ofNat - (getRewardAccruedReturnNat multiplier - (getRewardAccruedUpscaledNat slot0 (claimBaseTrackingReturnWord baseOut))), - ⟨128⟩, ⟨0⟩, claimSrcWord I, solcAddrMask, ⟨32⟩, claimed, - UInt256.land (claimSrcWord I) solcAddrMask, - UInt256.land (claimCometWord I) solcAddrMask, ⟨64⟩, ⟨1001⟩, ⟨64⟩, ⟨0⟩] - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k' C' := by - let baseWord : UInt256 := claimBaseTrackingReturnWord baseOut - let upNat : ℕ := getRewardAccruedUpscaledNat slot0 baseWord - let scaledNat : ℕ := getRewardAccruedScaledNat multiplier upNat - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have hup : upNat < UInt256.size := by - simpa [upNat, baseWord] using - getRewardAccruedUpscaledNat_lt_size_of_base64 - (slot0 := slot0) (accrued := baseWord) hbase64' - have hrescale64 : (rewardConfigRescaleFromSlot0 slot0).toNat < EVM.twoPow 64 := by - simpa [rewardConfigRescaleFromSlot0, EVM.twoPow] using - rewardConfigRescaleWord_lt slot0 - have hbaseClean : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using uint64Mask_clean hbase64' - have hbaseCleanLeft : - UInt256.land - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) - baseWord = baseWord := by - rw [u256_land_comm] - exact hbaseClean - have hrescaleClean : - UInt256.land (rewardConfigRescaleFromSlot0 slot0) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - rewardConfigRescaleFromSlot0 slot0 := by - simpa [uint64Mask] using uint64Mask_clean hrescale64 - have hshouldWord : - rewardConfigShouldUpscaleFromSlot0 slot0 = ⟨1⟩ := - rewardConfigShouldUpscaleFromSlot0_eq_one_of_raw_ne_zero hshould - have hshouldIsZero : - UInt256.isZero (rewardConfigShouldUpscaleFromSlot0 slot0) = ⟨0⟩ := by - rw [hshouldWord] - native_decide - have hfirstMulLt : - baseWord.toNat * (rewardConfigRescaleFromSlot0 slot0).toNat < UInt256.size := by - simpa [upNat, baseWord, getRewardAccruedUpscaledNat] using hup - have hfirstFlag : - UInt256.land - (UInt256.gt (rewardConfigRescaleFromSlot0 slot0) - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) baseWord)) - (UInt256.isZero (UInt256.isZero baseWord)) = ⟨0⟩ := - checkedMulOverflowFlag_zero baseWord (rewardConfigRescaleFromSlot0 slot0) hfirstMulLt - have hfirstFlagLeft : - UInt256.land (UInt256.isZero (UInt256.isZero baseWord)) - (UInt256.gt (rewardConfigRescaleFromSlot0 slot0) - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) baseWord)) = ⟨0⟩ := by - rw [u256_land_comm] - exact hfirstFlag - have hfirstMulWord : - UInt256.mul baseWord (rewardConfigRescaleFromSlot0 slot0) = UInt256.ofNat upNat := by - simpa [upNat, baseWord, getRewardAccruedUpscaledNat] using - u256_mul_eq_ofNat_of_lt baseWord (rewardConfigRescaleFromSlot0 slot0) hfirstMulLt - have hupWordToNat : (UInt256.ofNat upNat).toNat = upNat := - UInt256.toNat_ofNat_of_lt hup - have hsecondMulLt : - (UInt256.ofNat upNat).toNat * multiplier.toNat < UInt256.size := by - simpa [hupWordToNat, upNat, baseWord, scaledNat] using hscaled - have hsecondFlag : - UInt256.land - (UInt256.gt multiplier - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) (UInt256.ofNat upNat))) - (UInt256.isZero (UInt256.isZero (UInt256.ofNat upNat))) = ⟨0⟩ := - checkedMulOverflowFlag_zero (UInt256.ofNat upNat) multiplier hsecondMulLt - have hsecondFlagLeft : - UInt256.land (UInt256.isZero (UInt256.isZero (UInt256.ofNat upNat))) - (UInt256.gt multiplier - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) (UInt256.ofNat upNat))) = - ⟨0⟩ := by - rw [u256_land_comm] - exact hsecondFlag - have hsecondMulWord : - UInt256.mul (UInt256.ofNat upNat) multiplier = UInt256.ofNat scaledNat := by - calc - UInt256.mul (UInt256.ofNat upNat) multiplier = - UInt256.ofNat ((UInt256.ofNat upNat).toNat * multiplier.toNat) := - u256_mul_eq_ofNat_of_lt (UInt256.ofNat upNat) multiplier hsecondMulLt - _ = UInt256.ofNat scaledNat := by - simp [scaledNat, getRewardAccruedScaledNat, hupWordToNat] - have hdivWord : - UInt256.div (UInt256.ofNat scaledNat) (⟨1000000000000000000⟩ : UInt256) = - UInt256.ofNat (getRewardAccruedReturnNat multiplier upNat) := by - simpa [scaledNat, getRewardAccruedReturnNat] using - u256_div_factorScale_ofNat (n := scaledNat) - (by simpa [scaledNat, upNat, baseWord] using hscaled) - have rd3758 := evm_run rd with [ - push1 ⟨64⟩, dup2, add, - raw mload 0 (rewardConfigShouldUpscaleFromSlot0 slot0) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload192 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap3, dup4, and, - swap3, swap1, iszero] - have rd3758' := rd3758 - rw [hbaseCleanLeft, hshouldIsZero] at rd3758' - have rd3769pre := evm_run rd3758' with [ - push2 ⟨3808⟩, jumpiNT (by native_decide), - swap1, push1 ⟨96⟩, push2 ⟨3794⟩] - have rd3769 := rd3769pre.pushConst (⟨1000000000000000000⟩ : UInt256) - (width := 8) (op := .PUSH8) (by decide) (by native_decide) (by evm_ov) - have rd3671 := evm_run rd3769 with [ - swap5, push2 ⟨3804⟩, swap5, push1 ⟨32⟩, dup6, add, - raw mload 0 (rewardConfigRescaleFromSlot0 slot0) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload160 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - and, swap1, push2 ⟨3660⟩, jump (by jump_dest), - jumpdest, dup1, push1 ⟨0⟩, not, div, dup3, gt, dup2, iszero, iszero, and] - have rd3671' := rd3671 - rw [hrescaleClean, hfirstFlagLeft] at rd3671' - have rd3794 := evm_run rd3671' with [ - push2 ⟨3252⟩, jumpiNT (by native_decide), mul, swap1, jump (by jump_dest), - jumpdest] - have rd3794' := rd3794 - rw [hfirstMulWord] at rd3794' - have rd3671₂ := evm_run rd3794' with [ - swap2, jumpdest, add, - raw mload 0 multiplier claimBaseTrackingPostCallAw - (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload224 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - swap1, push2 ⟨3660⟩, jump (by jump_dest), - jumpdest, dup1, push1 ⟨0⟩, not, div, dup3, gt, dup2, iszero, iszero, and] - have rd3671₂' := rd3671₂ - rw [hsecondFlagLeft] at rd3671₂' - have rd3804 := evm_run rd3671₂' with [ - push2 ⟨3252⟩, jumpiNT (by native_decide), mul, swap1, jump (by jump_dest), - jumpdest] - have rd3804' := rd3804 - rw [hsecondMulWord] at rd3804' - have rd3432 := evm_run rd3804' with [ - div, swap1, jump (by jump_dest)] - rw [hdivWord] at rd3432 - exact ⟨_, _, by - simpa [baseWord, upNat, scaledNat, claimBaseTrackingReturnWord] using rd3432⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_panic12_from3161 - {cA gh bl σ σ₀ A I} {g : Sat256} {mem rdata : ByteArray} - {stack : List UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3161⟩ - stack mem claimBaseTrackingPostCallAw rdata acc k C) - (hov : stack.length + 2 ≤ 1024) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hsel : - UInt256.shiftLeft (⟨0x4e487b71⟩ : UInt256) ⟨224⟩ = - setRewardConfigPanicSelector := by - rfl - have rd3172₀ := evm_run rd with [ - jumpdest, push4 ⟨0x4e487b71⟩, push1 ⟨224⟩, shl, push1 ⟨0⟩] - have rd3172 := rd3172₀ - rw [hsel] at rd3172 - have rd3173 := evm_run rd3172 with [ - raw mstore 0 (setRewardConfigPanicMem0 mem) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov)] - have rd3178 := evm_run rd3173 with [ - push1 ⟨18⟩, push1 ⟨4⟩, - raw mstore 0 (setRewardConfigPanicMem ⟨18⟩ mem) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov), - push1 ⟨36⟩, push1 ⟨0⟩] - exact evm_run rd3178 with [raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_panic11_from3252 - {cA gh bl σ σ₀ A I} {g : Sat256} {mem rdata : ByteArray} - {stack : List UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3252⟩ - stack mem claimBaseTrackingPostCallAw rdata acc k C) - (hov : stack.length + 2 ≤ 1024) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hsel : - UInt256.shiftLeft (⟨0x4e487b71⟩ : UInt256) ⟨224⟩ = - setRewardConfigPanicSelector := by - rfl - have rd3263₀ := evm_run rd with [ - jumpdest, push4 ⟨0x4e487b71⟩, push1 ⟨224⟩, shl, push1 ⟨0⟩] - have rd3263 := rd3263₀ - rw [hsel] at rd3263 - have rd3264 := evm_run rd3263 with [ - raw mstore 0 (setRewardConfigPanicMem0 mem) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov)] - have rd3269 := evm_run rd3264 with [ - push1 ⟨17⟩, push1 ⟨4⟩, - raw mstore 0 (setRewardConfigPanicMem ⟨17⟩ mem) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov), - push1 ⟨36⟩, push1 ⟨0⟩] - exact evm_run rd3269 with [raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsClaimInternalX_getRewardAccrued_upscale_overflow_revert - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3740⟩ - [⟨128⟩, claimBaseTrackingReturnWord baseOut, ⟨3432⟩, - ⟨128⟩, ⟨0⟩, claimSrcWord I, solcAddrMask, ⟨32⟩, claimed, - UInt256.land (claimSrcWord I) solcAddrMask, - UInt256.land (claimCometWord I) solcAddrMask, ⟨64⟩, ⟨1001⟩, ⟨64⟩, ⟨0⟩] - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : (claimBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 ≠ ⟨0⟩) - (hover : - UInt256.size ≤ getRewardAccruedScaledNat multiplier - (getRewardAccruedUpscaledNat slot0 (claimBaseTrackingReturnWord baseOut))) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let baseWord : UInt256 := claimBaseTrackingReturnWord baseOut - let upNat : ℕ := getRewardAccruedUpscaledNat slot0 baseWord - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have hup : upNat < UInt256.size := by - simpa [upNat, baseWord] using - getRewardAccruedUpscaledNat_lt_size_of_base64 - (slot0 := slot0) (accrued := baseWord) hbase64' - have hrescale64 : (rewardConfigRescaleFromSlot0 slot0).toNat < EVM.twoPow 64 := by - simpa [rewardConfigRescaleFromSlot0, EVM.twoPow] using - rewardConfigRescaleWord_lt slot0 - have hbaseClean : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using uint64Mask_clean hbase64' - have hbaseCleanLeft : - UInt256.land - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) - baseWord = baseWord := by - rw [u256_land_comm] - exact hbaseClean - have hrescaleClean : - UInt256.land (rewardConfigRescaleFromSlot0 slot0) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - rewardConfigRescaleFromSlot0 slot0 := by - simpa [uint64Mask] using uint64Mask_clean hrescale64 - have hshouldWord : - rewardConfigShouldUpscaleFromSlot0 slot0 = ⟨1⟩ := - rewardConfigShouldUpscaleFromSlot0_eq_one_of_raw_ne_zero hshould - have hshouldIsZero : - UInt256.isZero (rewardConfigShouldUpscaleFromSlot0 slot0) = ⟨0⟩ := by - rw [hshouldWord] - native_decide - have hfirstMulLt : - baseWord.toNat * (rewardConfigRescaleFromSlot0 slot0).toNat < UInt256.size := by - simpa [upNat, baseWord, getRewardAccruedUpscaledNat] using hup - have hfirstFlag : - UInt256.land (UInt256.isZero (UInt256.isZero baseWord)) - (UInt256.gt (rewardConfigRescaleFromSlot0 slot0) - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) baseWord)) = ⟨0⟩ := by - rw [u256_land_comm] - exact checkedMulOverflowFlag_zero baseWord (rewardConfigRescaleFromSlot0 slot0) - hfirstMulLt - have hfirstMulWord : - UInt256.mul baseWord (rewardConfigRescaleFromSlot0 slot0) = UInt256.ofNat upNat := by - simpa [upNat, baseWord, getRewardAccruedUpscaledNat] using - u256_mul_eq_ofNat_of_lt baseWord (rewardConfigRescaleFromSlot0 slot0) hfirstMulLt - have hupWordToNat : (UInt256.ofNat upNat).toNat = upNat := - UInt256.toNat_ofNat_of_lt hup - have hsecondOver : - UInt256.size ≤ (UInt256.ofNat upNat).toNat * multiplier.toNat := by - simpa [hupWordToNat, upNat, baseWord, getRewardAccruedScaledNat] using hover - have hsecondFlag : - UInt256.land (UInt256.isZero (UInt256.isZero (UInt256.ofNat upNat))) - (UInt256.gt multiplier - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) (UInt256.ofNat upNat))) = - ⟨1⟩ := - checkedMulOverflowFlag_one (UInt256.ofNat upNat) multiplier hsecondOver - have rd3758 := evm_run rd with [ - push1 ⟨64⟩, dup2, add, - raw mload 0 (rewardConfigShouldUpscaleFromSlot0 slot0) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload192 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap3, dup4, and, - swap3, swap1, iszero] - have rd3758' := rd3758 - rw [hbaseCleanLeft, hshouldIsZero] at rd3758' - have rd3769pre := evm_run rd3758' with [ - push2 ⟨3808⟩, jumpiNT (by native_decide), - swap1, push1 ⟨96⟩, push2 ⟨3794⟩] - have rd3769 := rd3769pre.pushConst (⟨1000000000000000000⟩ : UInt256) - (width := 8) (op := .PUSH8) (by decide) (by native_decide) (by evm_ov) - have rd3671 := evm_run rd3769 with [ - swap5, push2 ⟨3804⟩, swap5, push1 ⟨32⟩, dup6, add, - raw mload 0 (rewardConfigRescaleFromSlot0 slot0) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload160 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - and, swap1, push2 ⟨3660⟩, jump (by jump_dest), - jumpdest, dup1, push1 ⟨0⟩, not, div, dup3, gt, dup2, iszero, iszero, and] - have rd3671' := rd3671 - rw [hrescaleClean, hfirstFlag] at rd3671' - have rd3794 := evm_run rd3671' with [ - push2 ⟨3252⟩, jumpiNT (by native_decide), mul, swap1, jump (by jump_dest), - jumpdest] - have rd3794' := rd3794 - rw [hfirstMulWord] at rd3794' - have rd3671₂ := evm_run rd3794' with [ - swap2, jumpdest, add, - raw mload 0 multiplier claimBaseTrackingPostCallAw - (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload224 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - swap1, push2 ⟨3660⟩, jump (by jump_dest), - jumpdest, dup1, push1 ⟨0⟩, not, div, dup3, gt, dup2, iszero, iszero, and] - have rd3671₂' := rd3671₂ - rw [hsecondFlag] at rd3671₂' - have rd3252 := evm_run rd3671₂' with [ - push2 ⟨3252⟩, jumpiT (by native_decide) (by jump_dest)] - exact cometRewardsClaimInternalX_panic11_from3252 rd3252 (by simp) - -set_option maxHeartbeats 2000000 in -theorem cometRewardsClaimInternalX_getRewardAccrued_downscale_success - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3740⟩ - [⟨128⟩, claimBaseTrackingReturnWord baseOut, ⟨3432⟩, - ⟨128⟩, ⟨0⟩, claimSrcWord I, solcAddrMask, ⟨32⟩, claimed, - UInt256.land (claimSrcWord I) solcAddrMask, - UInt256.land (claimCometWord I) solcAddrMask, ⟨64⟩, ⟨1001⟩, ⟨64⟩, ⟨0⟩] - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : (claimBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 = ⟨0⟩) - (hrescaleNZ : rewardConfigRescaleFromSlot0 slot0 ≠ ⟨0⟩) - (hscaled : - getRewardAccruedScaledNat multiplier - (getRewardAccruedDownscaledNat slot0 (claimBaseTrackingReturnWord baseOut)) < - UInt256.size) : - ∃ k' C', RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3432⟩ - [ UInt256.ofNat - (getRewardAccruedReturnNat multiplier - (getRewardAccruedDownscaledNat slot0 (claimBaseTrackingReturnWord baseOut))), - ⟨128⟩, ⟨0⟩, claimSrcWord I, solcAddrMask, ⟨32⟩, claimed, - UInt256.land (claimSrcWord I) solcAddrMask, - UInt256.land (claimCometWord I) solcAddrMask, ⟨64⟩, ⟨1001⟩, ⟨64⟩, ⟨0⟩] - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k' C' := by - let baseWord : UInt256 := claimBaseTrackingReturnWord baseOut - let downNat : ℕ := getRewardAccruedDownscaledNat slot0 baseWord - let scaledNat : ℕ := getRewardAccruedScaledNat multiplier downNat - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have hbaseClean : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using uint64Mask_clean hbase64' - have hbaseCleanLeft : - UInt256.land - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) - baseWord = baseWord := by - rw [u256_land_comm] - exact hbaseClean - have hrescale64 : (rewardConfigRescaleFromSlot0 slot0).toNat < EVM.twoPow 64 := by - simpa [rewardConfigRescaleFromSlot0, EVM.twoPow] using - rewardConfigRescaleWord_lt slot0 - have hrescaleClean : - UInt256.land (rewardConfigRescaleFromSlot0 slot0) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - rewardConfigRescaleFromSlot0 slot0 := by - simpa [uint64Mask] using uint64Mask_clean hrescale64 - have hshouldWord : - rewardConfigShouldUpscaleFromSlot0 slot0 = ⟨0⟩ := - rewardConfigShouldUpscaleFromSlot0_eq_zero_of_raw_zero hshould - have hshouldIsZero : - UInt256.isZero (rewardConfigShouldUpscaleFromSlot0 slot0) = ⟨1⟩ := by - rw [hshouldWord] - native_decide - have hrescaleIsZero : UInt256.isZero (rewardConfigRescaleFromSlot0 slot0) = ⟨0⟩ := - isZero_eq_zero_of_ne hrescaleNZ - have hdownWord : - UInt256.div baseWord (rewardConfigRescaleFromSlot0 slot0) = UInt256.ofNat downNat := by - simpa [downNat, baseWord, getRewardAccruedDownscaledNat] using - u256_div_eq_ofNat baseWord (rewardConfigRescaleFromSlot0 slot0) - have hdownLt : downNat < UInt256.size := by - have hle : downNat ≤ baseWord.toNat := by - simpa [downNat, getRewardAccruedDownscaledNat] using - Nat.div_le_self baseWord.toNat (rewardConfigRescaleFromSlot0 slot0).toNat - exact lt_of_le_of_lt hle baseWord.val.isLt - have hdownWordToNat : (UInt256.ofNat downNat).toNat = downNat := - UInt256.toNat_ofNat_of_lt hdownLt - have hsecondMulLt : - (UInt256.ofNat downNat).toNat * multiplier.toNat < UInt256.size := by - simpa [hdownWordToNat, downNat, baseWord, scaledNat] using hscaled - have hsecondFlag : - UInt256.land - (UInt256.gt multiplier - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) (UInt256.ofNat downNat))) - (UInt256.isZero (UInt256.isZero (UInt256.ofNat downNat))) = ⟨0⟩ := - checkedMulOverflowFlag_zero (UInt256.ofNat downNat) multiplier hsecondMulLt - have hsecondFlagLeft : - UInt256.land (UInt256.isZero (UInt256.isZero (UInt256.ofNat downNat))) - (UInt256.gt multiplier - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) (UInt256.ofNat downNat))) = - ⟨0⟩ := by - rw [u256_land_comm] - exact hsecondFlag - have hsecondMulWord : - UInt256.mul (UInt256.ofNat downNat) multiplier = UInt256.ofNat scaledNat := by - calc - UInt256.mul (UInt256.ofNat downNat) multiplier = - UInt256.ofNat ((UInt256.ofNat downNat).toNat * multiplier.toNat) := - u256_mul_eq_ofNat_of_lt (UInt256.ofNat downNat) multiplier hsecondMulLt - _ = UInt256.ofNat scaledNat := by - simp [scaledNat, getRewardAccruedScaledNat, hdownWordToNat] - have hdivWord : - UInt256.div (UInt256.ofNat scaledNat) (⟨1000000000000000000⟩ : UInt256) = - UInt256.ofNat (getRewardAccruedReturnNat multiplier downNat) := by - simpa [scaledNat, getRewardAccruedReturnNat] using - u256_div_factorScale_ofNat (n := scaledNat) - (by simpa [scaledNat, downNat, baseWord] using hscaled) - have rd3758 := evm_run rd with [ - push1 ⟨64⟩, dup2, add, - raw mload 0 (rewardConfigShouldUpscaleFromSlot0 slot0) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload192 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap3, dup4, and, - swap3, swap1, iszero] - have rd3758' := rd3758 - rw [hbaseCleanLeft, hshouldIsZero] at rd3758' - have rd3817 := evm_run rd3758' with [ - push2 ⟨3808⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push1 ⟨32⟩, dup3, add, - raw mload 0 (rewardConfigRescaleFromSlot0 slot0) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload160 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - and, swap1, dup2, iszero] - have rd3817' := rd3817 - rw [hrescaleClean, hrescaleIsZero] at rd3817' - have rd3827pre := evm_run rd3817' with [ - push2 ⟨3161⟩, jumpiNT (by native_decide), - push1 ⟨96⟩, push2 ⟨3804⟩, swap3] - have rd3828 := rd3827pre.pushConst (⟨1000000000000000000⟩ : UInt256) - (width := 8) (op := .PUSH8) (by decide) (by native_decide) (by evm_ov) - have rd3796 := evm_run rd3828 with [ - swap5, div, swap2, push2 ⟨3796⟩, jump (by jump_dest), jumpdest] - have rd3796' := rd3796 - rw [hdownWord] at rd3796' - have rd3671₂ := evm_run rd3796' with [ - add, - raw mload 0 multiplier claimBaseTrackingPostCallAw - (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload224 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - swap1, push2 ⟨3660⟩, jump (by jump_dest), - jumpdest, dup1, push1 ⟨0⟩, not, div, dup3, gt, dup2, iszero, iszero, and] - have rd3671₂' := rd3671₂ - rw [hsecondFlagLeft] at rd3671₂' - have rd3804 := evm_run rd3671₂' with [ - push2 ⟨3252⟩, jumpiNT (by native_decide), mul, swap1, jump (by jump_dest), - jumpdest] - have rd3804' := rd3804 - rw [hsecondMulWord] at rd3804' - have rd3432 := evm_run rd3804' with [ - div, swap1, jump (by jump_dest)] - rw [hdivWord] at rd3432 - exact ⟨_, _, by - simpa [baseWord, downNat, scaledNat, claimBaseTrackingReturnWord] using rd3432⟩ - -set_option maxHeartbeats 2000000 in -theorem cometRewardsClaimInternalX_getRewardAccrued_downscale_zero_revert - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3740⟩ - [⟨128⟩, claimBaseTrackingReturnWord baseOut, ⟨3432⟩, - ⟨128⟩, ⟨0⟩, claimSrcWord I, solcAddrMask, ⟨32⟩, claimed, - UInt256.land (claimSrcWord I) solcAddrMask, - UInt256.land (claimCometWord I) solcAddrMask, ⟨64⟩, ⟨1001⟩, ⟨64⟩, ⟨0⟩] - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : (claimBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 = ⟨0⟩) - (hrescaleZero : rewardConfigRescaleFromSlot0 slot0 = ⟨0⟩) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let baseWord : UInt256 := claimBaseTrackingReturnWord baseOut - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have hbaseClean : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using uint64Mask_clean hbase64' - have hbaseCleanLeft : - UInt256.land - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) - baseWord = baseWord := by - rw [u256_land_comm] - exact hbaseClean - have hrescaleClean : - UInt256.land (rewardConfigRescaleFromSlot0 slot0) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - rewardConfigRescaleFromSlot0 slot0 := by - rw [hrescaleZero] - native_decide - have hshouldWord : - rewardConfigShouldUpscaleFromSlot0 slot0 = ⟨0⟩ := - rewardConfigShouldUpscaleFromSlot0_eq_zero_of_raw_zero hshould - have hshouldIsZero : - UInt256.isZero (rewardConfigShouldUpscaleFromSlot0 slot0) = ⟨1⟩ := by - rw [hshouldWord] - native_decide - have hrescaleIsZero : UInt256.isZero (rewardConfigRescaleFromSlot0 slot0) = ⟨1⟩ := by - rw [hrescaleZero] - native_decide - have rd3758 := evm_run rd with [ - push1 ⟨64⟩, dup2, add, - raw mload 0 (rewardConfigShouldUpscaleFromSlot0 slot0) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload192 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap3, dup4, and, - swap3, swap1, iszero] - have rd3758' := rd3758 - rw [hbaseCleanLeft, hshouldIsZero] at rd3758' - have rd3817 := evm_run rd3758' with [ - push2 ⟨3808⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push1 ⟨32⟩, dup3, add, - raw mload 0 (rewardConfigRescaleFromSlot0 slot0) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload160 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - and, swap1, dup2, iszero] - have rd3817' := rd3817 - rw [hrescaleClean, hrescaleIsZero] at rd3817' - have rd3161 := evm_run rd3817' with [ - push2 ⟨3161⟩, jumpiT (by native_decide) (by jump_dest)] - exact cometRewardsClaimInternalX_panic12_from3161 rd3161 (by simp) - -set_option maxHeartbeats 2000000 in -theorem cometRewardsClaimInternalX_getRewardAccrued_downscale_overflow_revert - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3740⟩ - [⟨128⟩, claimBaseTrackingReturnWord baseOut, ⟨3432⟩, - ⟨128⟩, ⟨0⟩, claimSrcWord I, solcAddrMask, ⟨32⟩, claimed, - UInt256.land (claimSrcWord I) solcAddrMask, - UInt256.land (claimCometWord I) solcAddrMask, ⟨64⟩, ⟨1001⟩, ⟨64⟩, ⟨0⟩] - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : (claimBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 = ⟨0⟩) - (hrescaleNZ : rewardConfigRescaleFromSlot0 slot0 ≠ ⟨0⟩) - (hover : - UInt256.size ≤ getRewardAccruedScaledNat multiplier - (getRewardAccruedDownscaledNat slot0 (claimBaseTrackingReturnWord baseOut))) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let baseWord : UInt256 := claimBaseTrackingReturnWord baseOut - let downNat : ℕ := getRewardAccruedDownscaledNat slot0 baseWord - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have hbaseClean : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using uint64Mask_clean hbase64' - have hbaseCleanLeft : - UInt256.land - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) - baseWord = baseWord := by - rw [u256_land_comm] - exact hbaseClean - have hrescale64 : (rewardConfigRescaleFromSlot0 slot0).toNat < EVM.twoPow 64 := by - simpa [rewardConfigRescaleFromSlot0, EVM.twoPow] using - rewardConfigRescaleWord_lt slot0 - have hrescaleClean : - UInt256.land (rewardConfigRescaleFromSlot0 slot0) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - rewardConfigRescaleFromSlot0 slot0 := by - simpa [uint64Mask] using uint64Mask_clean hrescale64 - have hshouldWord : - rewardConfigShouldUpscaleFromSlot0 slot0 = ⟨0⟩ := - rewardConfigShouldUpscaleFromSlot0_eq_zero_of_raw_zero hshould - have hshouldIsZero : - UInt256.isZero (rewardConfigShouldUpscaleFromSlot0 slot0) = ⟨1⟩ := by - rw [hshouldWord] - native_decide - have hrescaleIsZero : UInt256.isZero (rewardConfigRescaleFromSlot0 slot0) = ⟨0⟩ := - isZero_eq_zero_of_ne hrescaleNZ - have hdownWord : - UInt256.div baseWord (rewardConfigRescaleFromSlot0 slot0) = UInt256.ofNat downNat := by - simpa [downNat, baseWord, getRewardAccruedDownscaledNat] using - u256_div_eq_ofNat baseWord (rewardConfigRescaleFromSlot0 slot0) - have hdownLt : downNat < UInt256.size := by - have hle : downNat ≤ baseWord.toNat := by - simpa [downNat, getRewardAccruedDownscaledNat] using - Nat.div_le_self baseWord.toNat (rewardConfigRescaleFromSlot0 slot0).toNat - exact lt_of_le_of_lt hle baseWord.val.isLt - have hdownWordToNat : (UInt256.ofNat downNat).toNat = downNat := - UInt256.toNat_ofNat_of_lt hdownLt - have hsecondOver : - UInt256.size ≤ (UInt256.ofNat downNat).toNat * multiplier.toNat := by - simpa [hdownWordToNat, downNat, baseWord, getRewardAccruedScaledNat] using hover - have hsecondFlag : - UInt256.land (UInt256.isZero (UInt256.isZero (UInt256.ofNat downNat))) - (UInt256.gt multiplier - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) (UInt256.ofNat downNat))) = - ⟨1⟩ := - checkedMulOverflowFlag_one (UInt256.ofNat downNat) multiplier hsecondOver - have rd3758 := evm_run rd with [ - push1 ⟨64⟩, dup2, add, - raw mload 0 (rewardConfigShouldUpscaleFromSlot0 slot0) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload192 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap3, dup4, and, - swap3, swap1, iszero] - have rd3758' := rd3758 - rw [hbaseCleanLeft, hshouldIsZero] at rd3758' - have rd3817 := evm_run rd3758' with [ - push2 ⟨3808⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push1 ⟨32⟩, dup3, add, - raw mload 0 (rewardConfigRescaleFromSlot0 slot0) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload160 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - and, swap1, dup2, iszero] - have rd3817' := rd3817 - rw [hrescaleClean, hrescaleIsZero] at rd3817' - have rd3827pre := evm_run rd3817' with [ - push2 ⟨3161⟩, jumpiNT (by native_decide), - push1 ⟨96⟩, push2 ⟨3804⟩, swap3] - have rd3828 := rd3827pre.pushConst (⟨1000000000000000000⟩ : UInt256) - (width := 8) (op := .PUSH8) (by decide) (by native_decide) (by evm_ov) - have rd3796 := evm_run rd3828 with [ - swap5, div, swap2, push2 ⟨3796⟩, jump (by jump_dest), jumpdest] - have rd3796' := rd3796 - rw [hdownWord] at rd3796' - have rd3671₂ := evm_run rd3796' with [ - add, - raw mload 0 multiplier claimBaseTrackingPostCallAw - (by native_decide) mem_cost - (claimBaseTrackingPostDecodeMem_mload224 I slot0 multiplier hout32 hbaseSize) - (by native_decide) (by evm_ov), - swap1, push2 ⟨3660⟩, jump (by jump_dest), - jumpdest, dup1, push1 ⟨0⟩, not, div, dup3, gt, dup2, iszero, iszero, and] - have rd3671₂' := rd3671₂ - rw [hsecondFlag] at rd3671₂' - have rd3252 := evm_run rd3671₂' with [ - push2 ⟨3252⟩, jumpiT (by native_decide) (by jump_dest)] - exact cometRewardsClaimInternalX_panic11_from3252 rd3252 (by simp) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_after_getRewardAccrued_no_transfer - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier accrued claimed : UInt256} {baseOut : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3432⟩ - [ accrued, ⟨128⟩, ⟨0⟩, claimSrcWord I, solcAddrMask, ⟨32⟩, claimed, - UInt256.land (claimSrcWord I) solcAddrMask, - UInt256.land (claimCometWord I) solcAddrMask, ⟨64⟩, ⟨1001⟩, ⟨64⟩, ⟨0⟩] - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C) - (hle : accrued.toNat ≤ claimed.toNat) (hbaseSize : baseOut.size < UInt256.size) : - RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) acc ByteArray.empty := by - have hgtWord : UInt256.gt accrued claimed = ⟨0⟩ := ugt_zero hle - have rd3436₀ := evm_run rd with [jumpdest, dup7, dup2, gt] - have rd3436 := rd3436₀ - rw [hgtWord] at rd3436 - have rd1001 := evm_run rd3436 with [ - push2 ⟨3452⟩, jumpiNT (by native_decide), - jumpdest, pop, pop, pop, pop, pop, pop, pop, pop, pop, pop, - jump (by jump_dest), jumpdest] - have rd1003 := evm_run rd1001 with [ - raw mload 0 ⟨288⟩ claimBaseTrackingPostCallAw (by native_decide) - mem_cost (claimBaseTrackingPostDecodeMem_mload64 I slot0 multiplier hbaseSize) - (by native_decide) (by evm_ov)] - exact RD.ret 0 ByteArray.empty rd1003 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, - claimBaseTrackingPostCallAw] - native_decide) - (by exact byteArray_readWithPadding_zero _ 288) - (by simp) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_after_getRewardAccrued_to_transfer - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier accrued claimed : UInt256} {baseOut : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3432⟩ - [ accrued, ⟨128⟩, ⟨0⟩, claimSrcWord I, solcAddrMask, ⟨32⟩, claimed, - UInt256.land (claimSrcWord I) solcAddrMask, - UInt256.land (claimCometWord I) solcAddrMask, ⟨64⟩, ⟨1001⟩, ⟨64⟩, ⟨0⟩] - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C) - (hperm : I.perm = true) - (hcanonComet : (claimCometWord I).toNat < EVM.addressModulus) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) - (hbaseSize : baseOut.size < UInt256.size) - (hlt : claimed.toNat < accrued.toNat) : - ∃ k' C', - RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3915⟩ - [ rewardConfigTokenFromSlot0 slot0, - claimSrcWord I, - accrued.sub claimed, - ⟨3531⟩, - ⟨128⟩, - solcAddrMask, - claimSrcWord I, - solcAddrMask, - ⟨32⟩, - claimRewardsClaimedBaseSlot, - UInt256.land (claimSrcWord I) solcAddrMask, - accrued.sub claimed, - ⟨64⟩, - ⟨1001⟩, - ⟨64⟩, - ⟨0⟩ ] - (claimTransferOuterHashMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut - (acc.1, - sstoreAccountMap I.codeOwner acc.2 (getRewardOwedRewardsClaimedSlotOf I) - accrued) - k' C' := by - have hgtWord : UInt256.gt accrued claimed = ⟨1⟩ := ugt_one hlt - have rd3436₀ := evm_run rd with [jumpdest, dup7, dup2, gt] - have rd3436 := rd3436₀ - rw [hgtWord] at rd3436 - have rd3452 := evm_run rd3436 with [ - push2 ⟨3452⟩, jumpiT (by native_decide) (by jump_dest), jumpdest] - have rd3459 := evm_run rd3452 with [ - dup10, dup6, swap4, push2 ⟨3498⟩] - have rd3492pre := - RD.pushConst (op := .PUSH32) (width := 32) rd3459 claimRewardsClaimedBaseSlot - (by decide) (by native_decide) - (by evm_ov) - have rd3241 := evm_run rd3492pre with [ - swap10, dup5, push2 ⟨3241⟩, jump (by jump_dest)] - have rd3245₀ := evm_run rd3241 with [jumpdest, dup2, dup2, lt] - have hltWord : UInt256.lt accrued claimed = ⟨0⟩ := ult_zero (le_of_lt hlt) - have rd3245 := rd3245₀ - rw [hltWord] at rd3245 - have rd3498 := evm_run rd3245 with [ - push2 ⟨3252⟩, jumpiNT (by native_decide), - sub, swap1, jump (by jump_dest), jumpdest] - let postDecodeMem := claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut - let innerMem := claimTransferInnerHashMem I slot0 multiplier baseOut - let outerMem := claimTransferOuterHashMem I slot0 multiplier baseOut - have hpostDecodeSize64 : 64 ≤ postDecodeMem.size := by - dsimp [postDecodeMem, claimBaseTrackingPostDecodeMem] - rw [writeWord_size] - · have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - omega - · have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - have hle : - 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide - have rd3501 := evm_run rd3498 with [ - swap11, dup2, - raw mstore 0 - (wordAt0Mem (UInt256.land (claimCometWord I) solcAddrMask) postDecodeMem) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (by - dsimp [postDecodeMem] - unfold wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have rd3505 := evm_run rd3501 with [ - push1 ⟨2⟩, dup9, - raw mstore 0 innerMem claimBaseTrackingPostCallAw (by native_decide) mem_cost - (by - dsimp [innerMem, claimTransferInnerHashMem, postDecodeMem] - unfold twoWordHashMem wordAt32Mem wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have hinnerHash : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC (innerMem.readWithPadding 0 64))) = - solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask) := by - dsimp [innerMem, claimTransferInnerHashMem] - exact twoWordHashMem_solcMappingSlot_of_ge ⟨2⟩ - (UInt256.land (claimCometWord I) solcAddrMask) hpostDecodeSize64 - have rd3506 := rd3505.keccak256 0 - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - hinnerHash (by native_decide) (by evm_ov) - have rd3510 := evm_run rd3506 with [ - dup9, push1 ⟨0⟩, - raw mstore 0 - (wordAt0Mem (UInt256.land (claimSrcWord I) solcAddrMask) innerMem) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (by - dsimp [innerMem] - unfold wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have rd3512 := evm_run rd3510 with [ - dup7, - raw mstore 0 outerMem claimBaseTrackingPostCallAw (by native_decide) mem_cost - (by - dsimp [outerMem, claimTransferOuterHashMem, innerMem, claimTransferInnerHashMem] - unfold twoWordHashMem wordAt32Mem wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have hinnerMemSize64 : 64 ≤ innerMem.size := by - dsimp [innerMem, claimTransferInnerHashMem] - rw [twoWordHashMem_size_of_ge - (UInt256.land (claimCometWord I) solcAddrMask) ⟨2⟩ hpostDecodeSize64] - exact hpostDecodeSize64 - have houterHashRaw : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC (outerMem.readWithPadding 0 64))) = - solcMappingSlot - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - (UInt256.land (claimSrcWord I) solcAddrMask) := by - dsimp [outerMem, claimTransferOuterHashMem] - exact twoWordHashMem_solcMappingSlot_of_ge - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - (UInt256.land (claimSrcWord I) solcAddrMask) hinnerMemSize64 - have houterHash : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC (outerMem.readWithPadding 0 64))) = - getRewardOwedRewardsClaimedSlotOf I := by - rw [houterHashRaw] - rw [solcAddrMask_clean - (by simpa [claimCometWord, calldataWord] using hcanonComet)] - rw [solcAddrMask_clean - (by simpa [claimSrcWord, calldataWord] using hcanonSrc)] - rw [getRewardOwedRewardsClaimedSlotOf_eq_solc I - (by simpa [getRewardOwedCometWord, claimCometWord] using hcanonComet) - (by simpa [getRewardOwedAccountWord, claimSrcWord] using hcanonSrc)] - have rd3516pre := (evm_run rd3512 with [dup10, push1 ⟨0⟩]).keccak256 0 - (getRewardOwedRewardsClaimedSlotOf I) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - houterHash (by native_decide) (by evm_ov) - obtain ⟨_, _, rd3518⟩ := rd3516pre.sstore hperm (by native_decide) (by evm_ov) - have hpostDecodeSize160 : 160 ≤ postDecodeMem.size := by - dsimp [postDecodeMem, claimBaseTrackingPostDecodeMem] - rw [writeWord_size] - · have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - omega - · have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - have hle : - 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide - have hinnerMemSize160 : 160 ≤ innerMem.size := by - dsimp [innerMem, claimTransferInnerHashMem] - rw [twoWordHashMem_size_of_ge - (UInt256.land (claimCometWord I) solcAddrMask) ⟨2⟩ hpostDecodeSize64] - exact hpostDecodeSize160 - have houterMemSize160 : 160 ≤ outerMem.size := by - dsimp [outerMem, claimTransferOuterHashMem] - rw [twoWordHashMem_size_of_ge - (UInt256.land (claimSrcWord I) solcAddrMask) - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - hinnerMemSize64] - exact hinnerMemSize160 - have houterMem_read128 : - outerMem.readWithPadding 128 32 = - UInt256.toByteArray (rewardConfigTokenFromSlot0 slot0) := by - dsimp [outerMem, claimTransferOuterHashMem, innerMem, claimTransferInnerHashMem, - postDecodeMem] - rw [twoWordHashMem_read_above64_of_ge] - · rw [twoWordHashMem_read_above64_of_ge] - · exact claimBaseTrackingPostDecodeMem_read128 I slot0 multiplier hbaseSize - · exact hpostDecodeSize160 - · norm_num - · exact hinnerMemSize160 - · norm_num - have houterMem_mload128 : - (if (⟨128⟩ : UInt256).toNat ≥ outerMem.size - ∨ (⟨128⟩ : UInt256) ≥ claimBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - (outerMem.readWithPadding (⟨128⟩ : UInt256).toNat 32))) = - rewardConfigTokenFromSlot0 slot0 := by - exact mloadWordValue_of_readWithPadding - (off := (⟨128⟩ : UInt256)) (aw := claimBaseTrackingPostCallAw) - (v := rewardConfigTokenFromSlot0 slot0) - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - omega) - (by native_decide) - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - exact houterMem_read128) - have rd3530 := evm_run rd3518 with [ - push2 ⟨3531⟩, dup9, dup5, dup5, dup5, - raw mload 0 (rewardConfigTokenFromSlot0 slot0) claimBaseTrackingPostCallAw - (by native_decide) mem_cost houterMem_mload128 (by native_decide) (by evm_ov), - and, push2 ⟨3915⟩, jump (by jump_dest)] - have htokenClean := rewardConfigTokenFromSlot0_clean slot0 - rw [htokenClean] at rd3530 - exact ⟨_, _, by - simpa [outerMem, innerMem, postDecodeMem, claimTransferOuterHashMem, - claimTransferInnerHashMem] using rd3530⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_call_transfer_from3915 - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier amount : UInt256} {baseOut : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3915⟩ - [ rewardConfigTokenFromSlot0 slot0, - claimSrcWord I, - amount, - ⟨3531⟩, - ⟨128⟩, - solcAddrMask, - claimSrcWord I, - solcAddrMask, - ⟨32⟩, - claimRewardsClaimedBaseSlot, - UInt256.land (claimSrcWord I) solcAddrMask, - amount, - ⟨64⟩, - ⟨1001⟩, - ⟨64⟩, - ⟨0⟩ ] - (claimTransferOuterHashMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) - (hbaseSize : baseOut.size < UInt256.size) : - ∃ gasArg k' C', - RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - claimTransferCallPc - (gasArg :: UInt256.land solcAddrMask (rewardConfigTokenFromSlot0 slot0) :: - ⟨0⟩ :: ⟨288⟩ :: claimTransferCallSize :: ⟨288⟩ :: ⟨32⟩ :: - claimTransferPostCallTail I amount) - (claimTransferCalldataMem I slot0 multiplier baseOut (claimSrcWord I) amount) - claimTransferCallAw baseOut acc k' C' := by - have hcleanTo : - UInt256.land (claimSrcWord I) solcAddrMask = claimSrcWord I := by - exact solcAddrMask_clean (by simpa [claimSrcWord, calldataWord] using hcanonSrc) - have rd3932 := evm_run rd with [ - jumpdest, push1 ⟨32⟩, push1 ⟨64⟩, - raw mload 0 ⟨288⟩ claimBaseTrackingPostCallAw (by native_decide) - mem_cost (claimTransferOuterHashMem_mload64 I slot0 multiplier hbaseSize) - (by native_decide) (by evm_ov), - dup1, swap3, push4 ⟨2835717307⟩, push1 ⟨224⟩, shl, dup3, - raw mstore 0 (claimTransferSelectorMem I slot0 multiplier baseOut) - (UInt256.ofNat 10) (by native_decide) mem_cost - (by - rw [show (⟨288⟩ : UInt256).toNat = 288 from by decide]) - (by native_decide) (by evm_ov)] - have rd3949 := evm_run rd3932 with [ - dup2, push1 ⟨0⟩, dup2, push2 ⟨3950⟩, dup10, dup10, push1 ⟨4⟩, dup5, - add, push2 ⟨3888⟩, jump (by native_decide)] - have rd3901₀ := evm_run rd3949 with [ - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, swap1, swap2, and, - dup2] - have rd3901 := rd3901₀ - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] at rd3901 - have rd3902 := evm_run rd3901 with [ - raw mstore 3 (claimTransferArgsMem I slot0 multiplier baseOut (claimSrcWord I)) - (UInt256.ofNat 11) (by decide) mem_cost - (by - rw [show (⟨288⟩ : UInt256) + ⟨4⟩ = ⟨292⟩ from by decide, - show (⟨292⟩ : UInt256).toNat = 292 from by decide] - unfold claimTransferArgsMem - rw [hcleanTo]) - (by native_decide) (by evm_ov)] - have rd3913 := evm_run rd3902 with [ - push1 ⟨32⟩, dup2, add, swap2, swap1, swap2, - raw mstore 3 (claimTransferCalldataMem I slot0 multiplier baseOut (claimSrcWord I) amount) - claimTransferCallAw (by decide) mem_cost - (by - rw [show (⟨288⟩ : UInt256) + ⟨4⟩ + ⟨32⟩ = ⟨324⟩ from by decide, - show (⟨324⟩ : UInt256).toNat = 324 from by decide]) - (by native_decide) (by evm_ov), - push1 ⟨64⟩, add, swap1] - have rd3962₀ := evm_run rd3913 with [ - jump (by native_decide), jumpdest, sub, swap3, push1 ⟨1⟩, push1 ⟨1⟩, - push1 ⟨160⟩, shl, sub, and] - have rd3962 := rd3962₀ - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] at rd3962 - obtain ⟨gasArg, rd3963⟩ := evm_run rd3962 with [gas] - exact ⟨gasArg, _, _, by - simpa [claimTransferCallPc, claimTransferCallSize, claimTransferPostCallTail, - claimTransferCallAw] using rd3963⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_call_transfer_made_from3915 - {cA gh bl σ₀ σ_start A I} {g : UInt256} - {cAcur : Batteries.RBSet AccountAddress compare} {σcur_evm : AccountMap} - {slot0 multiplier amount : UInt256} {baseOut : ByteArray} {k C : ℕ} - (evmSolm : EVM.State) - (hperm : I.perm = true) - (hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus) - (hdepth : I.depth.val < 1024) - (hbaseSize : baseOut.size < UInt256.size) - (hAccounts : accountMapEquiv σcur_evm evmSolm.accountMap) - (hCreated : evmSolm.createdAccounts = cAcur) - (hGenesis : evmSolm.genesisBlockHeader = gh) - (hBlocks : evmSolm.blocks = bl) - (hOriginal : evmSolm.σ₀ = σ₀) - (hEnv : evmSolm.executionEnv = I) - (rd3915 : RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_start σ₀ (Sat256.ofUInt256 g) A I) ⟨3915⟩ - [ rewardConfigTokenFromSlot0 slot0, - claimSrcWord I, - amount, - ⟨3531⟩, - ⟨128⟩, - solcAddrMask, - claimSrcWord I, - solcAddrMask, - ⟨32⟩, - claimRewardsClaimedBaseSlot, - UInt256.land (claimSrcWord I) solcAddrMask, - amount, - ⟨64⟩, - ⟨1001⟩, - ⟨64⟩, - ⟨0⟩ ] - (claimTransferOuterHashMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut (cAcur, σcur_evm) k C) : - ∃ cA' σ'_evm σ'_solm A'_solm z out k' C', - typedCallViaEVM config evmSolm - (EVM.address (claimTransferTarget slot0)) "transfer" 0 - (claimTransferArgs I amount) - (z, - { evmSolm with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' }, - out) true ∧ - accountMapEquiv σ'_evm σ'_solm ∧ - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_start σ₀ (Sat256.ofUInt256 g) A I) - (claimTransferCallPc + ⟨1⟩) (claimTransferPostCallStack z I amount) - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw out (cA', σ'_evm) k' C' ∧ - out.size < 2 ^ 255 := by - obtain ⟨gasArg, k0, C0, rd3963⟩ := - cometRewardsClaimInternalX_call_transfer_from3915 - (cA := cA) (gh := gh) (bl := bl) (σ := σ_start) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) (slot0 := slot0) (multiplier := multiplier) - (amount := amount) (baseOut := baseOut) rd3915 hcanonSrc hbaseSize - have rd3963Call : - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_start σ₀ (Sat256.ofUInt256 g) A I) - claimTransferCallPc - (gasArg :: UInt256.land solcAddrMask (rewardConfigTokenFromSlot0 slot0) :: - ⟨0⟩ :: ⟨288⟩ :: claimTransferCallSize :: ⟨288⟩ :: ⟨32⟩ :: - claimTransferPostCallTail I amount) - (claimTransferCalldataMem I slot0 multiplier baseOut (claimSrcWord I) amount) - claimTransferCallAw baseOut (cAcur, σcur_evm) k0 C0 := by - simpa [claimTransferPostCallTail] using rd3963 - have hdecCall : - decode cometRewardsBytecode claimTransferCallPc = some (.CALL, .none) := by - unfold claimTransferCallPc - rw [withdrawTokenTransferCallPc_eq] - native_decide - obtain ⟨cA', σ'_evm, z, out, A_in, callGas, k', C', hΘ, rd3964, houtSize⟩ := - RD.call (t := claimTransferPostCallTail I amount) rd3963Call hdecCall hdepth - (by simp [claimTransferPostCallTail]) - obtain ⟨g'', A'_evm, hΘeq⟩ := hΘ - let evmEvm : EVM.State := - initState cAcur gh bl σcur_evm σ₀ (Sat256.ofUInt256 g) evmSolm.substate I - have houtSmall : out.size < 2 ^ 138 := by - exact Theta_returnData_size_lt_2pow138_of_eq - (blob := I.blobVersionedHashes) (cA := cAcur) - (gh := - (initState cA gh bl σ_start σ₀ (Sat256.ofUInt256 g) A I).genesisBlockHeader) - (blocks := (initState cA gh bl σ_start σ₀ (Sat256.ofUInt256 g) A I).blocks) - (σ := σcur_evm) - (σ₀ := (initState cA gh bl σ_start σ₀ (Sat256.ofUInt256 g) A I).σ₀) - (A := A_in) - (s := AccountAddress.ofUInt256 (UInt256.ofNat I.codeOwner)) - (o := I.sender) - (r := AccountAddress.ofUInt256 - (UInt256.land solcAddrMask (rewardConfigTokenFromSlot0 slot0))) - (c := toExecute σcur_evm - (AccountAddress.ofUInt256 - (UInt256.land solcAddrMask (rewardConfigTokenFromSlot0 slot0)))) - (g := callGas) (p := UInt256.ofNat I.gasPrice) - (v := ⟨0⟩) (v' := ⟨0⟩) - (d := (claimTransferCalldataMem I slot0 multiplier baseOut (claimSrcWord I) amount) - |>.readWithPadding (⟨288⟩ : UInt256).toNat claimTransferCallSize.toNat) - (e := I.depth + 1) (H := I.header) (w := I.perm) - hΘeq - (by exact Ethereum.EVM.ByteArray.readWithPadding_size_lt_uint256 _ _ _) - have houtSign : out.size < 2 ^ 255 := by omega - have hdepthNeI : I.depth ≠ 1024 := by - intro hEq - rw [hEq] at hdepth - exact absurd hdepth (by decide) - have hdepthNe : evmEvm.executionEnv.depth ≠ 1024 := by - simpa [evmEvm, initState] using hdepthNeI - have htgt := claimTransferTarget_eq_targetWord slot0 - have hcd := - claimTransferCalldataMem_encode_args - I slot0 multiplier amount hbaseSize hcanonSrc - have hcallE : - typedCallViaEVM config evmEvm - (EVM.address (claimTransferTarget slot0)) "transfer" 0 - (claimTransferArgs I amount) - (z, - { evmEvm with - accountMap := σ'_evm - substate := A'_evm - createdAccounts := cA' }, - out) true := by - refine callCoincides - (cfg := config) (evm := evmEvm) - (name := "transfer") (args := claimTransferArgs I amount) - (tgt := EVM.address (claimTransferTarget slot0)) - (targetWord := UInt256.land solcAddrMask (rewardConfigTokenFromSlot0 slot0)) - (cA' := cA') (σ' := σ'_evm) (A' := A'_evm) (A_in := A_in) - (z := z) (o := out) (g'' := g'') (callGas := callGas) - (mem := claimTransferCalldataMem I slot0 multiplier baseOut (claimSrcWord I) amount) - (inOff := ⟨288⟩) (inSize := claimTransferCallSize) - (callPerm := true) - hdepthNe htgt hcd ?_ - simpa [evmEvm, initState, hperm] using hΘeq - obtain ⟨σ'_solm, A'_solm, hcallSolm, hPostAccounts⟩ := - typedCallViaEVM_accountMapEquiv - (evm_solm := evmSolm) hcallE - (by simpa [evmEvm, initState] using hAccounts) - (by simp [evmEvm, initState, hOriginal]) - (by simp [evmEvm, initState, hCreated]) - (by simp [evmEvm, initState, hGenesis]) - (by simp [evmEvm, initState, hBlocks]) - (by simp [evmEvm, initState]) - (by simp [evmEvm, initState, hEnv]) - exact ⟨cA', σ'_evm, σ'_solm, A'_solm, z, out, k', C', - hcallSolm, hPostAccounts, by - simpa [claimTransferPostCallStack, claimTransferPostCallTail, - claimTransferPostCallMem, claimTransferPostCallAw, claimTransferCallSize] - using rd3964, - houtSign⟩ - -theorem claimTransferPostCallMem_read288_of_size_ge - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut out : ByteArray} - (amount : UInt256) (hbaseSize : baseOut.size < UInt256.size) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (claimTransferPostCallMem I slot0 multiplier baseOut out amount).readWithPadding 288 32 = - out.extract 0 32 := by - unfold claimTransferPostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := out.size) - (by decide) hout32 houtSize - rw [hlen] - exact write32_read_back out - (claimTransferCalldataMem I slot0 multiplier baseOut (claimSrcWord I) amount) - 288 hout32 - (by - have hge := - claimTransferCalldataMem_size_ge356 I slot0 multiplier (claimSrcWord I) amount - hbaseSize - omega) - -theorem claimTransferPostCallMem_size_ge320 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut out : ByteArray} - (amount : UInt256) (hbaseSize : baseOut.size < UInt256.size) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - 320 ≤ (claimTransferPostCallMem I slot0 multiplier baseOut out amount).size := by - unfold claimTransferPostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := out.size) - (by decide) hout32 houtSize - rw [hlen] - rw [write32_eq out - (claimTransferCalldataMem I slot0 multiplier baseOut (claimSrcWord I) amount) - 288 hout32 - (by - have hge := - claimTransferCalldataMem_size_ge356 I slot0 multiplier (claimSrcWord I) amount - hbaseSize - omega)] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract] - have hbase := - claimTransferCalldataMem_size_ge356 I slot0 multiplier (claimSrcWord I) amount - hbaseSize - omega - -theorem claimTransferPostCallMem_mload288_haw : - ¬ (⟨288⟩ : UInt256) ≥ claimTransferPostCallAw * ⟨32⟩ := by - native_decide - -theorem claimTransferPostCallMem_mload288_of_size_ge - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut out : ByteArray} - (amount : UInt256) (hbaseSize : baseOut.size < UInt256.size) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (if (⟨288⟩ : UInt256).toNat ≥ - (claimTransferPostCallMem I slot0 multiplier baseOut out amount).size - ∨ (⟨288⟩ : UInt256) ≥ claimTransferPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimTransferPostCallMem I slot0 multiplier baseOut out amount) - |>.readWithPadding (⟨288⟩ : UInt256).toNat 32))) = - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) := by - exact mloadValue_eq_readWithPadding_of_lt_size - (mem := claimTransferPostCallMem I slot0 multiplier baseOut out amount) - (aw := claimTransferPostCallAw) - (off := ⟨288⟩) - (memSize := (claimTransferPostCallMem I slot0 multiplier baseOut out amount).size) - rfl - (by - rw [show (⟨288⟩ : UInt256).toNat = 288 from by decide] - exact lt_of_lt_of_le (by omega) - (claimTransferPostCallMem_size_ge320 - I slot0 multiplier amount hbaseSize hout32 houtSize)) - claimTransferPostCallMem_mload288_haw - |>.trans (by - rw [show (⟨288⟩ : UInt256).toNat = 288 from by decide, - claimTransferPostCallMem_read288_of_size_ge - I slot0 multiplier amount hbaseSize hout32 houtSize]) - -noncomputable abbrev claimTransferPostDecodeMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut out : ByteArray) - (amount : UInt256) : ByteArray := - (UInt256.toByteArray (⟨320⟩ : UInt256)).write 0 - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) 64 32 - -theorem claimTransferPostDecodeMem_read288_of_size_ge - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut out : ByteArray} - (amount : UInt256) (hbaseSize : baseOut.size < UInt256.size) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (claimTransferPostDecodeMem I slot0 multiplier baseOut out amount).readWithPadding 288 32 = - out.extract 0 32 := by - unfold claimTransferPostDecodeMem - rw [write32_read_above (UInt256.toByteArray (⟨320⟩ : UInt256)) - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) 64 288 - (by rw [toByteArray_size]) - (by - have hge := claimTransferPostCallMem_size_ge320 - I slot0 multiplier amount hbaseSize hout32 houtSize - omega) - (by omega) - (by - have hge := claimTransferPostCallMem_size_ge320 - I slot0 multiplier amount hbaseSize hout32 houtSize - omega)] - exact claimTransferPostCallMem_read288_of_size_ge - I slot0 multiplier amount hbaseSize hout32 houtSize - -theorem claimTransferPostDecodeMem_mload288_of_size_ge - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut out : ByteArray} - (amount : UInt256) (hbaseSize : baseOut.size < UInt256.size) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (if (⟨288⟩ : UInt256).toNat ≥ - (claimTransferPostDecodeMem I slot0 multiplier baseOut out amount).size - ∨ (⟨288⟩ : UInt256) ≥ claimTransferPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimTransferPostDecodeMem I slot0 multiplier baseOut out amount) - |>.readWithPadding (⟨288⟩ : UInt256).toNat 32))) = - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) := by - exact mloadValue_eq_readWithPadding_of_lt_size - (mem := claimTransferPostDecodeMem I slot0 multiplier baseOut out amount) - (aw := claimTransferPostCallAw) (off := ⟨288⟩) - (memSize := (claimTransferPostDecodeMem I slot0 multiplier baseOut out amount).size) - rfl - (by - rw [show (⟨288⟩ : UInt256).toNat = 288 from by decide] - unfold claimTransferPostDecodeMem - rw [write32_eq (UInt256.toByteArray (⟨320⟩ : UInt256)) - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) 64 - (by rw [toByteArray_size]) - (by - have hge := claimTransferPostCallMem_size_ge320 - I slot0 multiplier amount hbaseSize hout32 houtSize - omega)] - simp - have hsz := claimTransferPostCallMem_size_ge320 - I slot0 multiplier amount hbaseSize hout32 houtSize - omega) - claimTransferPostCallMem_mload288_haw - |>.trans (by - rw [show (⟨288⟩ : UInt256).toNat = 288 from by decide, - claimTransferPostDecodeMem_read288_of_size_ge - I slot0 multiplier amount hbaseSize hout32 houtSize]) - -theorem claimTransferPostDecodeMem_mload64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {baseOut out : ByteArray} - (amount : UInt256) (hbaseSize : baseOut.size < UInt256.size) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ - (claimTransferPostDecodeMem I slot0 multiplier baseOut out amount).size - ∨ (⟨64⟩ : UInt256) ≥ claimTransferPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((claimTransferPostDecodeMem I slot0 multiplier baseOut out amount) - |>.readWithPadding (⟨64⟩ : UInt256).toNat 32))) = ⟨320⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := claimTransferPostCallAw) (v := ⟨320⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold claimTransferPostDecodeMem - rw [write32_eq (UInt256.toByteArray (⟨320⟩ : UInt256)) - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) 64 - (by rw [toByteArray_size]) - (by - have hge := claimTransferPostCallMem_size_ge320 - I slot0 multiplier amount hbaseSize hout32 houtSize - omega)] - simp - have hsz := claimTransferPostCallMem_size_ge320 - I slot0 multiplier amount hbaseSize hout32 houtSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold claimTransferPostDecodeMem - rw [write32_read_back _ _ 64 (by rw [toByteArray_size]) - (by - have hge := claimTransferPostCallMem_size_ge320 - I slot0 multiplier amount hbaseSize hout32 houtSize - omega)] - rw [show (UInt256.toByteArray (⟨320⟩ : UInt256)).extract 0 32 = - UInt256.toByteArray (⟨320⟩ : UInt256) by - rw [show 32 = (UInt256.toByteArray (⟨320⟩ : UInt256)).size by - rw [toByteArray_size]] - exact byteArray_extract_self _]) - -noncomputable abbrev claimTransferPostShortDecodeMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut out : ByteArray) - (amount : UInt256) : ByteArray := - (UInt256.toByteArray ((⟨288⟩ : UInt256) + - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat out.size + ⟨31⟩))).write 0 - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) 64 32 - -noncomputable abbrev claimTransferOutFailedSelectorMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut out : ByteArray) - (amount : UInt256) : ByteArray := - (UInt256.toByteArray withdrawTokenTransferOutFailedSelectorShifted).write 0 - (claimTransferPostDecodeMem I slot0 multiplier baseOut out amount) 320 32 - -noncomputable abbrev claimTransferOutFailedArgsMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut out : ByteArray) - (amount : UInt256) : ByteArray := - (UInt256.toByteArray (UInt256.land (claimSrcWord I) solcAddrMask)).write 0 - (claimTransferOutFailedSelectorMem I slot0 multiplier baseOut out amount) 324 32 - -noncomputable abbrev claimTransferOutFailedMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (baseOut out : ByteArray) - (amount : UInt256) : ByteArray := - (UInt256.toByteArray amount).write 0 - (claimTransferOutFailedArgsMem I slot0 multiplier baseOut out amount) 356 32 - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_after_transfer_failure - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier amount : UInt256} {baseOut out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (claimTransferCallPc + ⟨1⟩) (claimTransferPostCallStack false I amount) - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw out acc k C) - (houtSize : out.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have rd3964 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3964⟩ (claimTransferPostCallStack false I amount) - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw out acc k C := by - unfold claimTransferCallPc at rd - simpa [withdrawTokenTransferCallPc_eq] using rd - have rd3876 := evm_run rd3964 with [ - swap1, dup2, iszero, push2 ⟨3876⟩, - jumpiT (by native_decide) (by jump_dest)] - let fp : UInt256 := - if (⟨64⟩ : UInt256).toNat ≥ - (claimTransferPostCallMem I slot0 multiplier baseOut out amount).size - ∨ (⟨64⟩ : UInt256) ≥ claimTransferPostCallAw * ⟨32⟩ then - ⟨0⟩ - else - UInt256.ofNat (fromByteArrayBigEndian - ((claimTransferPostCallMem I slot0 multiplier baseOut out amount) - |>.readWithPadding (⟨64⟩ : UInt256).toNat 32)) - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have rd3880pre := evm_run rd3876 with [jumpdest, push1 ⟨64⟩] - have rd3880 := RD.mload 0 fp claimTransferPostCallAw rd3880pre (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, - claimTransferPostCallAw, claimTransferCallSize] - native_decide) - (by rfl) - (by native_decide) - (by simp) - have rd3884pre := evm_run rd3880 with [returndatasize, push1 ⟨0⟩, dup3] - let mem2 : ByteArray := - out.write 0 (claimTransferPostCallMem I slot0 multiplier baseOut out amount) - fp.toNat rdsz.toNat - let aw2 : UInt256 := - UInt256.ofNat (MachineState.M claimTransferPostCallAw.toNat fp.toNat rdsz.toNat) - have rd3885 := RD.returndatacopy - (Cₘ aw2 - Cₘ claimTransferPostCallAw) mem2 aw2 rd3884pre (by native_decide) - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, hrdsz_toNat]; omega) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, aw2, rdsz]) - (by rfl) - (by rfl) - (by simp) - have rd3887 := evm_run rd3885 with [returndatasize, swap1] - exact RD.rev - (Cₘ (UInt256.ofNat (MachineState.M aw2.toNat fp.toNat rdsz.toNat)) - Cₘ aw2) - rd3887 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, rdsz]) - (by simp) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_after_transfer_toBoolCheck - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier amount : UInt256} {baseOut out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (claimTransferCallPc + ⟨1⟩) (claimTransferPostCallStack true I amount) - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw out acc k C) - (hbaseSize : baseOut.size < UInt256.size) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - ∃ k' C', RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3287⟩ - (UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) :: ⟨4044⟩ :: - claimSrcWord I :: amount :: ⟨3531⟩ :: ⟨128⟩ :: solcAddrMask :: - claimSrcWord I :: solcAddrMask :: ⟨32⟩ :: claimRewardsClaimedBaseSlot :: - UInt256.land (claimSrcWord I) solcAddrMask :: amount :: ⟨64⟩ :: ⟨1001⟩ :: - ⟨64⟩ :: ⟨0⟩ :: []) - (claimTransferPostDecodeMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw out acc k' C' := by - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hout32 - have rd3964 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3964⟩ (claimTransferPostCallStack true I amount) - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw out acc k C := by - unfold claimTransferCallPc at rd - simpa [withdrawTokenTransferCallPc_eq] using rd - have rd4031₀ := evm_run rd3964 with [ - swap1, dup2, iszero, push2 ⟨3876⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨4020⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push2 ⟨4044⟩, swap2, pop, push1 ⟨32⟩, returndatasize, dup2, gt] - have rd4031 := rd4031₀ - rw [show UInt256.ofNat out.size = rdsz from rfl, hgt] at rd4031 - have rd3071 := evm_run rd4031 with [ - push2 ⟨2249⟩, jumpiNT (by native_decide), - push2 ⟨2235⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, add, - swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, swap1, dup3, - lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (claimTransferPostDecodeMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold claimTransferPostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd3274 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3274⟩, - jump (by jump_dest)] - have rd3286 := evm_run rd3274 with [ - jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, slt, push2 ⟨1004⟩, - jumpiNT (by native_decide)] - exact ⟨_, _, evm_run rd3286 with [ - raw mload 0 (UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32))) - claimTransferPostCallAw (by native_decide) mem_cost - (claimTransferPostDecodeMem_mload288_of_size_ge - I slot0 multiplier amount hbaseSize hout32 houtSize) - (by native_decide) (by evm_ov)]⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_after_transfer_short_revert - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier amount : UInt256} {baseOut out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (claimTransferCallPc + ⟨1⟩) (claimTransferPostCallStack true I amount) - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw out acc k C) - (hshort : out.size < 32) (houtSize : out.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨1⟩ := by - apply ugt_one - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hshort - have rd3964 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3964⟩ (claimTransferPostCallStack true I amount) - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw out acc k C := by - unfold claimTransferCallPc at rd - simpa [withdrawTokenTransferCallPc_eq] using rd - have rd4031₀ := evm_run rd3964 with [ - swap1, dup2, iszero, push2 ⟨3876⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨4020⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push2 ⟨4044⟩, swap2, pop, push1 ⟨32⟩, returndatasize, dup2, gt] - have rd4031 := rd4031₀ - rw [show UInt256.ofNat out.size = rdsz from rfl, hgt] at rd4031 - let rounded : UInt256 := - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat out.size + ⟨31⟩) - let ptr : UInt256 := (⟨288⟩ : UInt256) + rounded - have hroundedLe : rounded.toNat ≤ out.size + 31 := by - unfold rounded - rw [uland_toNat] - refine le_trans Nat.and_le_right ?_ - rw [uadd_toNat, UInt256.toNat_ofNat_of_lt houtSize, - show (⟨31⟩ : UInt256).toNat = 31 from by decide] - exact Nat.mod_le _ _ - have hptr_toNat : ptr.toNat = 288 + rounded.toNat := by - unfold ptr - rw [uadd_toNat, show (⟨288⟩ : UInt256).toNat = 288 from by decide] - exact Nat.mod_eq_of_lt (by - have hroundSmall : rounded.toNat < 64 := by omega - have hsz : UInt256.size = 2 ^ 256 := by decide - omega) - have hltPtr : UInt256.lt ptr (⟨288⟩ : UInt256) = ⟨0⟩ := by - apply ult_zero - rw [hptr_toNat, show (⟨288⟩ : UInt256).toNat = 288 from by decide] - omega - have hmax64 : - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩).toNat = - 18446744073709551615 := by - native_decide - have hgtPtr : - UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - rw [hptr_toNat, hmax64] - omega - have hallocOk : - UInt256.lor (UInt256.lt ptr (⟨288⟩ : UInt256)) - (UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = ⟨0⟩ := by - rw [hltPtr, hgtPtr] - native_decide - have rd3071 := evm_run rd4031 with [ - push2 ⟨2249⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, pop, returndatasize, push2 ⟨2225⟩, jump (by jump_dest), - jumpdest, push2 ⟨2235⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, add, - swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, swap1, dup3, - lt, lor, push2 ⟨3003⟩, jumpiNT (by simpa [ptr, rounded] using hallocOk), - push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (claimTransferPostShortDecodeMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]) - (by native_decide) (by evm_ov)] - have rd3274 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3274⟩, - jump (by jump_dest)] - have hlenCheck : - UInt256.slt (UInt256.sub ((⟨288⟩ : UInt256) + rdsz) ⟨288⟩) ⟨32⟩ = ⟨1⟩ := by - simpa [rdsz] using - solcReturnStaticLenCheckShort (base := 288) (words := 1) (by simpa using hshort) - (by norm_num [UInt256.size]) - (by - have hsz : UInt256.size = 2 ^ 256 := by decide - omega) - (by norm_num) - have rd3282₀ := evm_run rd3274 with [ - jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, slt] - have rd3282 := rd3282₀ - rw [hlenCheck] at rd3282 - have rd1004 := evm_run rd3282 with [ - push2 ⟨1004⟩, jumpiT (by native_decide) (by jump_dest)] - exact evm_run rd1004 with [ - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_after_transfer_noncanon_revert - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier amount : UInt256} {baseOut out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (claimTransferCallPc + ⟨1⟩) (claimTransferPostCallStack true I amount) - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw out acc k C) - (hbaseSize : baseOut.size < UInt256.size) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) - (hnz : UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) ≠ ⟨0⟩) - (hno : UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) ≠ ⟨1⟩) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let word : UInt256 := UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) - have hnzWord : word ≠ ⟨0⟩ := by simpa [word] using hnz - have hnoWord : word ≠ ⟨1⟩ := by simpa [word] using hno - have hiszero : UInt256.isZero word = ⟨0⟩ := isZero_eq_zero_of_ne hnzWord - have hsub : UInt256.sub word (UInt256.isZero (⟨0⟩ : UInt256)) ≠ ⟨0⟩ := by - rw [show UInt256.isZero (⟨0⟩ : UInt256) = ⟨1⟩ by native_decide] - exact u256_sub_ne_zero_of_ne hnoWord - obtain ⟨kBool, CBool, rd3287₀⟩ := - cometRewardsClaimInternalX_after_transfer_toBoolCheck - (slot0 := slot0) (multiplier := multiplier) (amount := amount) - rd hbaseSize hout32 houtSize - have rd3287 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3287⟩ - (word :: ⟨4044⟩ :: claimSrcWord I :: amount :: ⟨3531⟩ :: ⟨128⟩ :: - solcAddrMask :: claimSrcWord I :: solcAddrMask :: ⟨32⟩ :: - claimRewardsClaimedBaseSlot :: UInt256.land (claimSrcWord I) solcAddrMask :: - amount :: ⟨64⟩ :: ⟨1001⟩ :: ⟨64⟩ :: ⟨0⟩ :: []) - (claimTransferPostDecodeMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw out acc kBool CBool := by - simpa [word] using rd3287₀ - have rd3292 := evm_run rd3287 with [dup1, iszero, iszero, dup2, sub] - rw [hiszero] at rd3292 - have rd1004 := evm_run rd3292 with [ - push2 ⟨1004⟩, jumpiT hsub (by jump_dest)] - exact evm_run rd1004 with [ - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_after_transfer_false_revert - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier amount : UInt256} {baseOut out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (claimTransferCallPc + ⟨1⟩) (claimTransferPostCallStack true I amount) - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw out acc k C) - (hbaseSize : baseOut.size < UInt256.size) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) - (hword : UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) = ⟨0⟩) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd3287₀⟩ := - cometRewardsClaimInternalX_after_transfer_toBoolCheck - (slot0 := slot0) (multiplier := multiplier) (amount := amount) - rd hbaseSize hout32 houtSize - have rd3287 := rd3287₀ - rw [hword] at rd3287 - have rd3988 := evm_run rd3287 with [ - dup1, iszero, iszero, dup2, sub, push2 ⟨1004⟩, jumpiNT (by native_decide), - swap1, jump (by jump_dest), jumpdest, codesize, push2 ⟨3978⟩, jump (by jump_dest), - jumpdest, pop, iszero, push2 ⟨3988⟩, jumpiT (by native_decide) (by jump_dest)] - have rd3994 := evm_run rd3988 with [jumpdest, push2 ⟨4016⟩, push1 ⟨64⟩] - have rd3995 := evm_run rd3994 with [ - raw mload 0 ⟨320⟩ claimTransferPostCallAw (by native_decide) - mem_cost (claimTransferPostDecodeMem_mload64 - I slot0 multiplier amount hbaseSize hout32 houtSize) - (by native_decide) (by evm_ov)] - have rd4007 := evm_run rd3995 with [ - swap3, dup4, swap3, push4 withdrawTokenTransferOutFailedSelectorWord, - push1 ⟨224⟩, shl, dup5, - raw mstore 0 (claimTransferOutFailedSelectorMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨320⟩ : UInt256).toNat = 320 from by decide]) - (by native_decide) (by evm_ov)] - have rd3901 := evm_run rd4007 with [ - push1 ⟨4⟩, dup5, add, push2 ⟨3888⟩, jump (by jump_dest), - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, swap1, swap2, - and, dup2] - have rd3902 := evm_run rd3901 with [ - raw mstore 0 (claimTransferOutFailedArgsMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw (by native_decide) mem_cost - (by - rw [show ((⟨320⟩ : UInt256) + ⟨4⟩).toNat = 324 from by native_decide] - unfold claimTransferOutFailedArgsMem - rfl) - (by native_decide) (by evm_ov)] - have rd3909 := evm_run rd3902 with [ - push1 ⟨32⟩, dup2, add, swap2, swap1, swap2, - raw mstore (Cₘ (UInt256.ofNat 13) - Cₘ claimTransferPostCallAw) - (claimTransferOutFailedMem I slot0 multiplier baseOut out amount) (UInt256.ofNat 13) - (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, - claimTransferPostCallAw] - native_decide) - (by - rw [show ((⟨320⟩ : UInt256) + ⟨4⟩ + ⟨32⟩).toNat = 356 from by native_decide]) - (by native_decide) (by evm_ov)] - exact evm_run rd3909 with [ - push1 ⟨64⟩, add, swap1, jump (by jump_dest), jumpdest, sub, swap1, - raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsClaimInternalX_after_transfer_true_return - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier amount : UInt256} {baseOut out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (claimTransferCallPc + ⟨1⟩) (claimTransferPostCallStack true I amount) - (claimTransferPostCallMem I slot0 multiplier baseOut out amount) - claimTransferPostCallAw out acc k C) - (hbaseSize : baseOut.size < UInt256.size) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) - (hword : UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) = ⟨1⟩) : - RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) acc ByteArray.empty := by - obtain ⟨_, _, rd3287₀⟩ := - cometRewardsClaimInternalX_after_transfer_toBoolCheck - (slot0 := slot0) (multiplier := multiplier) (amount := amount) - rd hbaseSize hout32 houtSize - have rd3287 := rd3287₀ - rw [hword] at rd3287 - have rd3978 := evm_run rd3287 with [ - dup1, iszero, iszero, dup2, sub, push2 ⟨1004⟩, jumpiNT (by native_decide), - swap1, jump (by jump_dest), jumpdest, codesize, push2 ⟨3978⟩, jump (by jump_dest)] - have rd3531 := evm_run rd3978 with [ - jumpdest, pop, iszero, push2 ⟨3988⟩, jumpiNT (by native_decide), - pop, pop, jump (by jump_dest), jumpdest] - have rd1001 := evm_run rd3531 with [ - pop, pop, pop, pop, pop, pop, pop, pop, pop, - jump (by jump_dest), jumpdest] - have rd1003 := evm_run rd1001 with [ - raw mload 0 ⟨320⟩ claimTransferPostCallAw (by native_decide) - mem_cost (claimTransferPostDecodeMem_mload64 - I slot0 multiplier amount hbaseSize hout32 houtSize) - (by native_decide) (by evm_ov)] - exact RD.ret 0 ByteArray.empty rd1003 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, claimTransferPostCallAw] - native_decide) - (by exact byteArray_readWithPadding_zero _ 320) - (by simp) - -theorem cometRewardsClaimInternalBodyReverts_tokenZero (evm : EVM.State) (I : ExecutionEnv) - (hz : rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evm I) = ⟨0⟩) : - ExecFuncBody config { contract := contract, locals := claimInternalStore I } evm - claimInternalFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [claimInternalFunction, checkedExternalCallStmts, claimInternalConfigLocals, - claimInternalAfterShouldLocals, claimInternalAfterRescaleLocals, - claimInternalAfterTokenLocals] using - (((((ABlock.start.letStep - (evalExpr_getRewardOwed_token_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalStore_comet I) - (claimInternalStore_no_rewardConfig I))).letStep - (evalExpr_getRewardOwed_rescale_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterTokenLocals_comet evm I) - (claimInternalAfterTokenLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_shouldUpscale_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterRescaleLocals_comet evm I) - (claimInternalAfterRescaleLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_multiplier_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterShouldLocals_comet evm I) - (claimInternalAfterShouldLocals_no_rewardConfig evm I))).requireRevert - (evalExpr_getRewardOwed_token_ne_zero_false_of evm (getRewardOwedSlot0Load evm I) - (claimInternalConfigLocals_token evm I) hz)) - -theorem cometRewardsClaimInternalBodyReverts_noAccrue_getRewardAccrued - (evm evmBase : EVM.State) (I : ExecutionEnv) {baseOut : ByteArray} - (hnz : rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evm I) ≠ ⟨0⟩) - (hshouldZero : claimShouldAccrueWord I = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (false, evmBase, baseOut) false) : - ExecFuncBody config { contract := contract, locals := claimInternalStore I } evm - claimInternalFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hinner : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I) } - evm getRewardAccruedFunction.body .reverted := by - exact getRewardAccruedBodyReverts_callFailure evm evmBase I - (getRewardOwedSlot0Load evm I) (getRewardOwedMultiplierLoad evm I) hcallBase - have hrest : - ExecBlock config { contract := contract, locals := claimInternalConfigLocals evm I } - evm - [ .ite (.var "shouldAccrue") - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "src"] "_accrued") - [], - .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "src"))), - .internalCall "getRewardAccrued" - [.var "comet", .var "src", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"] "accrued", - .ite (.binary .gt (.var "accrued") (.var "claimed")) - [ .letDecl "owed" (some uint256) - (.binary .sub (.var "accrued") (.var "claimed")), - .assign .storage (rewardsClaimedRef (.var "comet") (.var "src")) - (.var "accrued"), - .internalCall "doTransferOut" [.var "token", .var "to", .var "owed"] - "_sent" ] - [] ] - .reverted := by - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := claimInternalConfigLocals evm I }) - (evm' := evm) ?hite ?_ - · exact ExecStmt.iteFalse - (evalExpr_claimInternal_shouldAccrue_false evm I hshouldZero) - ExecBlock.nil - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := claimInternalAfterClaimedLocals evm evm I }) - (evm' := evm) ?hclaimed ?_ - · exact ExecStmt.letDecl (evalExpr_claim_claimed_config evm I) - refine ExecBlock.consRevert ?_ - exact internalCallFunctionRevert - (cfg := config) - (caller := - { contract := contract, - locals := claimInternalAfterClaimedLocals evm evm I }) - (evm := evm) - (name := "getRewardAccrued") (retVar := "accrued") - (args := [.var "comet", .var "src", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"]) - (argVals := getRewardAccruedArgs I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (callee := getRewardAccruedFunction) - (locals := getRewardAccruedStore I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (evalExprs_claim_getRewardAccruedArgs_afterClaimed evm evm I) - lookupCallable_getRewardAccrued - (bindParams_getRewardAccrued I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - hinner - simpa [claimInternalFunction, checkedExternalCallStmts, claimInternalConfigLocals, - claimInternalAfterShouldLocals, claimInternalAfterRescaleLocals, - claimInternalAfterTokenLocals] using - (((((ABlock.start.letStep - (evalExpr_getRewardOwed_token_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalStore_comet I) - (claimInternalStore_no_rewardConfig I))).letStep - (evalExpr_getRewardOwed_rescale_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterTokenLocals_comet evm I) - (claimInternalAfterTokenLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_shouldUpscale_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterRescaleLocals_comet evm I) - (claimInternalAfterRescaleLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_multiplier_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterShouldLocals_comet evm I) - (claimInternalAfterShouldLocals_no_rewardConfig evm I))).requireStep - (evalExpr_getRewardOwed_token_ne_zero_true_of evm (getRewardOwedSlot0Load evm I) - (claimInternalConfigLocals_token evm I) hnz)).run hrest - -theorem cometRewardsClaimInternalBodyReverts_noAccrue_getRewardAccrued_decode - (evm evmBase : EVM.State) (I : ExecutionEnv) {baseOut : ByteArray} - (hnz : rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evm I) ≠ ⟨0⟩) - (hshouldZero : claimShouldAccrueWord I = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseTrackingAccrued" baseOut = none) : - ExecFuncBody config { contract := contract, locals := claimInternalStore I } evm - claimInternalFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hinner : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I) } - evm getRewardAccruedFunction.body .reverted := by - exact getRewardAccruedBodyReverts_decode evm evmBase I - (getRewardOwedSlot0Load evm I) (getRewardOwedMultiplierLoad evm I) - hcallBase hdecBase - have hrest : - ExecBlock config { contract := contract, locals := claimInternalConfigLocals evm I } - evm - [ .ite (.var "shouldAccrue") - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "src"] "_accrued") - [], - .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "src"))), - .internalCall "getRewardAccrued" - [.var "comet", .var "src", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"] "accrued", - .ite (.binary .gt (.var "accrued") (.var "claimed")) - [ .letDecl "owed" (some uint256) - (.binary .sub (.var "accrued") (.var "claimed")), - .assign .storage (rewardsClaimedRef (.var "comet") (.var "src")) - (.var "accrued"), - .internalCall "doTransferOut" [.var "token", .var "to", .var "owed"] - "_sent" ] - [] ] - .reverted := by - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := claimInternalConfigLocals evm I }) - (evm' := evm) ?hite ?_ - · exact ExecStmt.iteFalse - (evalExpr_claimInternal_shouldAccrue_false evm I hshouldZero) - ExecBlock.nil - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := claimInternalAfterClaimedLocals evm evm I }) - (evm' := evm) ?hclaimed ?_ - · exact ExecStmt.letDecl (evalExpr_claim_claimed_config evm I) - refine ExecBlock.consRevert ?_ - exact internalCallFunctionRevert - (cfg := config) - (caller := - { contract := contract, - locals := claimInternalAfterClaimedLocals evm evm I }) - (evm := evm) - (name := "getRewardAccrued") (retVar := "accrued") - (args := [.var "comet", .var "src", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"]) - (argVals := getRewardAccruedArgs I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (callee := getRewardAccruedFunction) - (locals := getRewardAccruedStore I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (evalExprs_claim_getRewardAccruedArgs_afterClaimed evm evm I) - lookupCallable_getRewardAccrued - (bindParams_getRewardAccrued I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - hinner - simpa [claimInternalFunction, checkedExternalCallStmts, claimInternalConfigLocals, - claimInternalAfterShouldLocals, claimInternalAfterRescaleLocals, - claimInternalAfterTokenLocals] using - (((((ABlock.start.letStep - (evalExpr_getRewardOwed_token_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalStore_comet I) - (claimInternalStore_no_rewardConfig I))).letStep - (evalExpr_getRewardOwed_rescale_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterTokenLocals_comet evm I) - (claimInternalAfterTokenLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_shouldUpscale_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterRescaleLocals_comet evm I) - (claimInternalAfterRescaleLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_multiplier_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterShouldLocals_comet evm I) - (claimInternalAfterShouldLocals_no_rewardConfig evm I))).requireStep - (evalExpr_getRewardOwed_token_ne_zero_true_of evm (getRewardOwedSlot0Load evm I) - (claimInternalConfigLocals_token evm I) hnz)).run hrest - -theorem cometRewardsClaimInternalBodyReverts_noAccrue_getRewardAccrued_inner - (evm : EVM.State) (I : ExecutionEnv) - (hnz : rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evm I) ≠ ⟨0⟩) - (hshouldZero : claimShouldAccrueWord I = ⟨0⟩) - (hinner : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I) } - evm getRewardAccruedFunction.body .reverted) : - ExecFuncBody config { contract := contract, locals := claimInternalStore I } evm - claimInternalFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hrest : - ExecBlock config { contract := contract, locals := claimInternalConfigLocals evm I } - evm - [ .ite (.var "shouldAccrue") - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "src"] "_accrued") - [], - .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "src"))), - .internalCall "getRewardAccrued" - [.var "comet", .var "src", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"] "accrued", - .ite (.binary .gt (.var "accrued") (.var "claimed")) - [ .letDecl "owed" (some uint256) - (.binary .sub (.var "accrued") (.var "claimed")), - .assign .storage (rewardsClaimedRef (.var "comet") (.var "src")) - (.var "accrued"), - .internalCall "doTransferOut" [.var "token", .var "to", .var "owed"] - "_sent" ] - [] ] - .reverted := by - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := claimInternalConfigLocals evm I }) - (evm' := evm) ?hite ?_ - · exact ExecStmt.iteFalse - (evalExpr_claimInternal_shouldAccrue_false evm I hshouldZero) - ExecBlock.nil - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := claimInternalAfterClaimedLocals evm evm I }) - (evm' := evm) ?hclaimed ?_ - · exact ExecStmt.letDecl (evalExpr_claim_claimed_config evm I) - refine ExecBlock.consRevert ?_ - exact internalCallFunctionRevert - (cfg := config) - (caller := - { contract := contract, - locals := claimInternalAfterClaimedLocals evm evm I }) - (evm := evm) - (name := "getRewardAccrued") (retVar := "accrued") - (args := [.var "comet", .var "src", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"]) - (argVals := getRewardAccruedArgs I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (callee := getRewardAccruedFunction) - (locals := getRewardAccruedStore I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (evalExprs_claim_getRewardAccruedArgs_afterClaimed evm evm I) - lookupCallable_getRewardAccrued - (bindParams_getRewardAccrued I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - hinner - simpa [claimInternalFunction, checkedExternalCallStmts, claimInternalConfigLocals, - claimInternalAfterShouldLocals, claimInternalAfterRescaleLocals, - claimInternalAfterTokenLocals] using - (((((ABlock.start.letStep - (evalExpr_getRewardOwed_token_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalStore_comet I) - (claimInternalStore_no_rewardConfig I))).letStep - (evalExpr_getRewardOwed_rescale_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterTokenLocals_comet evm I) - (claimInternalAfterTokenLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_shouldUpscale_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterRescaleLocals_comet evm I) - (claimInternalAfterRescaleLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_multiplier_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterShouldLocals_comet evm I) - (claimInternalAfterShouldLocals_no_rewardConfig evm I))).requireStep - (evalExpr_getRewardOwed_token_ne_zero_true_of evm (getRewardOwedSlot0Load evm I) - (claimInternalConfigLocals_token evm I) hnz)).run hrest - -theorem cometRewardsClaimInternalBodyReturns_noAccrue_noTransfer - (evm evmBase : EVM.State) (I : ExecutionEnv) {accruedNat : ℕ} - {calleeSolm : Frame} - (hnz : rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evm I) ≠ ⟨0⟩) - (hshouldZero : claimShouldAccrueWord I = ⟨0⟩) - (hinner : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I) } - evm getRewardAccruedFunction.body - (.returned calleeSolm evmBase (some [.int (Int.ofNat accruedNat)]))) - (hle : accruedNat ≤ (getRewardOwedClaimedLoad evm I).toNat) : - ExecFuncBody config { contract := contract, locals := claimInternalStore I } evm - claimInternalFunction.body - (.returned - { contract := contract, locals := claimInternalAfterInternalLocals evm evm I accruedNat } - evmBase none) := by - refine ExecFuncBody.execBlockOK ?_ - have hrest : - ExecBlock config { contract := contract, locals := claimInternalConfigLocals evm I } - evm - [ .ite (.var "shouldAccrue") - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "src"] "_accrued") - [], - .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "src"))), - .internalCall "getRewardAccrued" - [.var "comet", .var "src", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"] "accrued", - .ite (.binary .gt (.var "accrued") (.var "claimed")) - [ .letDecl "owed" (some uint256) - (.binary .sub (.var "accrued") (.var "claimed")), - .assign .storage (rewardsClaimedRef (.var "comet") (.var "src")) - (.var "accrued"), - .internalCall "doTransferOut" [.var "token", .var "to", .var "owed"] - "_sent" ] - [] ] - (.ok - { contract := contract, locals := claimInternalAfterInternalLocals evm evm I accruedNat } - evmBase) := by - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := claimInternalConfigLocals evm I }) - (evm' := evm) ?hite ?_ - · exact ExecStmt.iteFalse - (evalExpr_claimInternal_shouldAccrue_false evm I hshouldZero) - ExecBlock.nil - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := claimInternalAfterClaimedLocals evm evm I }) - (evm' := evm) ?hclaimed ?_ - · exact ExecStmt.letDecl (evalExpr_claim_claimed_config evm I) - refine ExecBlock.consNormal - (solm' := - { contract := contract, locals := claimInternalAfterInternalLocals evm evm I accruedNat }) - (evm' := evmBase) ?hinternal ?_ - · simpa [resumeAfterInternalCall, claimInternalAfterInternalLocals, collapseReturns] - using internalCallFunctionReturn - (cfg := config) - (caller := - { contract := contract, - locals := claimInternalAfterClaimedLocals evm evm I }) - (evm := evm) (calleeEvm := evmBase) - (name := "getRewardAccrued") (retVar := "accrued") - (args := [.var "comet", .var "src", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"]) - (argVals := getRewardAccruedArgs I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (callee := getRewardAccruedFunction) - (locals := getRewardAccruedStore I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (calleeSolm := calleeSolm) - (value := some [.int (Int.ofNat accruedNat)]) - (evalExprs_claim_getRewardAccruedArgs_afterClaimed evm evm I) - lookupCallable_getRewardAccrued - (bindParams_getRewardAccrued I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - hinner - refine ExecBlock.consNormal - (solm' := - { contract := contract, locals := claimInternalAfterInternalLocals evm evm I accruedNat }) - (evm' := evmBase) ?hiteClaim ?_ - · exact ExecStmt.iteFalse - (evalExpr_claimInternal_accrued_gt_claimed_false evm evm evmBase I accruedNat hle) - ExecBlock.nil - exact ExecBlock.nil - simpa [claimInternalFunction, checkedExternalCallStmts, claimInternalConfigLocals, - claimInternalAfterShouldLocals, claimInternalAfterRescaleLocals, - claimInternalAfterTokenLocals] using - (((((ABlock.start.letStep - (evalExpr_getRewardOwed_token_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalStore_comet I) - (claimInternalStore_no_rewardConfig I))).letStep - (evalExpr_getRewardOwed_rescale_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterTokenLocals_comet evm I) - (claimInternalAfterTokenLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_shouldUpscale_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterRescaleLocals_comet evm I) - (claimInternalAfterRescaleLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_multiplier_of evm I - (by - simpa [claimCometValue, claimCometWord, getRewardOwedCometValue, - getRewardOwedCometWord] using claimInternalAfterShouldLocals_comet evm I) - (claimInternalAfterShouldLocals_no_rewardConfig evm I))).requireStep - (evalExpr_getRewardOwed_token_ne_zero_true_of evm (getRewardOwedSlot0Load evm I) - (claimInternalConfigLocals_token evm I) hnz)).run hrest - -theorem cometRewardsClaimBodyReverts_internal - (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hinner : - ExecFuncBody config { contract := contract, locals := claimInternalStore I } evm - claimInternalFunction.body .reverted) : - ExecTransitionBody config contract evm (claimStore I) - claimTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (claimFrame evm I) evm - (.internalCall "claimInternal" - [.var "comet", .var "src", .var "src", .var "shouldAccrue"] "_claim") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := claimFrame evm I) (evm := evm) - (name := "claimInternal") (retVar := "_claim") - (args := [.var "comet", .var "src", .var "src", .var "shouldAccrue"]) - (argVals := claimInternalArgs I) (callee := claimInternalFunction) - (locals := claimInternalStore I) - (evalExprs_claim_internalArgs_frame evm I) - (by simpa [claimFrame] using lookupCallable_claimInternal) - (bindParams_claimInternal I) - (by simpa [claimFrame] using hinner) - simpa [claimTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - ((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - change evalExpr? config { contract := contract, locals := claimStore I } evm - (.env .msgData) = .ok (.bytes evm.executionEnv.calldata) - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (claimStore I) hsize)).run - (ExecBlock.consRevert hstmt)) - -theorem cometRewardsClaimBodyReturns_internal - (evm evm' : EVM.State) (I : ExecutionEnv) {calleeSolm : Frame} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hinner : - ExecFuncBody config { contract := contract, locals := claimInternalStore I } evm - claimInternalFunction.body (.returned calleeSolm evm' none)) : - ExecTransitionBody config contract evm (claimStore I) - claimTransition.body - (.returned (resumeAfterInternalCall (claimFrame evm I) "_claim" none) evm' none) := by - refine ExecFuncBody.execBlockOK ?_ - have hstmt : - ExecStmt config (claimFrame evm I) evm - (.internalCall "claimInternal" - [.var "comet", .var "src", .var "src", .var "shouldAccrue"] "_claim") - (.ok (resumeAfterInternalCall (claimFrame evm I) "_claim" none) evm') := by - exact internalCallFunctionReturn - (cfg := config) (caller := claimFrame evm I) (evm := evm) - (calleeEvm := evm') (name := "claimInternal") (retVar := "_claim") - (args := [.var "comet", .var "src", .var "src", .var "shouldAccrue"]) - (argVals := claimInternalArgs I) (callee := claimInternalFunction) - (locals := claimInternalStore I) (calleeSolm := calleeSolm) - (value := none) - (evalExprs_claim_internalArgs_frame evm I) - (by simpa [claimFrame] using lookupCallable_claimInternal) - (bindParams_claimInternal I) - (by simpa [claimFrame] using hinner) - simpa [claimTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - ((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - change evalExpr? config { contract := contract, locals := claimStore I } evm - (.env .msgData) = .ok (.bytes evm.executionEnv.calldata) - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (claimStore I) hsize)).run - (ExecBlock.consNormal hstmt ExecBlock.nil)) - -set_option maxHeartbeats 2000000 in -/-- `claim(address,address,bool)` body, reached at pc 942. -/ -theorem cometRewardsClaimBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hsel : selIs I (cometRewardsSelBytes 8)) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) claimPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have _hperm : I.perm = true := hperm - have hsz4 := cometRewardsClaimSelector_size hsel - have hd := cometRewardsDispatch_claim (cd := I.calldata) hsel - by_cases hsz100 : 100 ≤ I.calldata.size - · by_cases hhi : I.calldata.size < 2 ^ 255 + 4 - · by_cases hcanonComet : (claimCometWord I).toNat < EVM.addressModulus - · by_cases hcanonSrc : (claimSrcWord I).toNat < EVM.addressModulus - · by_cases hzero : claimShouldAccrueWord I = ⟨0⟩ - · have hdec := cometRewardsDecode_claim_ok - (I := I) hsz100 hhi hcanonComet hcanonSrc (Or.inl hzero) - have hslotWord : - getRewardOwedRewardConfigSlot0Word σ_evm I = - getRewardOwedRewardConfigSlot0Word σ_solm I := - accountMapEquiv_storage_findD hAccounts I.codeOwner - (getRewardOwedRewardConfigSlotOf I) ⟨0⟩ - by_cases htokenZero : - rewardConfigTokenFromSlot0 - (getRewardOwedRewardConfigSlot0Word σ_evm I) = ⟨0⟩ - · let evmSolm : EVM.State := - initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I - have htokenZeroSolm : - rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evmSolm I) = ⟨0⟩ := by - have hload : - getRewardOwedSlot0Load evmSolm I = - getRewardOwedRewardConfigSlot0Word σ_solm I := by - simp [evmSolm, getRewardOwedSlot0Load, getRewardOwedRewardConfigSlot0Word, - initState, Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - rw [hload, ← hslotWord] - exact htokenZero - have hbody : - ExecTransitionBody config contract evmSolm (claimStore I) - claimTransition.body .reverted := by - exact cometRewardsClaimBodyReverts_internal evmSolm I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - (cometRewardsClaimInternalBodyReverts_tokenZero evmSolm I htokenZeroSolm) - have hreach3298 := - cometRewardsClaimX_dec3298_internal (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanonComet hcanonSrc (Or.inl hzero) hreach - exact (cometRewardsClaimInternalX_tokenZero_of_reach - (g := Sat256.ofUInt256 g) hcanonComet htokenZero hreach3298) - |>.reEquivExecutionRevert hcode hd hdec hbody - · let evmSolm : EVM.State := - initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I - have htokenNZSolm : - rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evmSolm I) ≠ ⟨0⟩ := by - have hload : - getRewardOwedSlot0Load evmSolm I = - getRewardOwedRewardConfigSlot0Word σ_solm I := by - simp [evmSolm, getRewardOwedSlot0Load, getRewardOwedRewardConfigSlot0Word, - initState, Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - rw [hload, ← hslotWord] - exact htokenZero - have hreach3298 := - cometRewardsClaimX_dec3298_internal (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanonComet hcanonSrc (Or.inl hzero) hreach - by_cases hdepth : I.depth.val < 1024 - · obtain ⟨cA', σ'_evm, σ'_solm, A'_solm, z, baseOut, k', C', - hcallBaseSolm, hPostAccounts, rdBasePost, hbaseOutSize, hbaseOutHi⟩ := - cometRewardsClaimInternalX_noAccrue_call_baseTracking_made - (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) - (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) - hcanonComet hcanonSrc hdepth hAccounts htokenZero hzero hreach3298 - let evmBase : EVM.State := - { initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } - cases z - · have hinner : - ExecFuncBody config - { contract := contract, locals := claimInternalStore I } - evmSolm claimInternalFunction.body .reverted := by - exact cometRewardsClaimInternalBodyReverts_noAccrue_getRewardAccrued - evmSolm evmBase I htokenNZSolm hzero - (by simpa [evmSolm, evmBase] using hcallBaseSolm) - have hbody : - ExecTransitionBody config contract evmSolm (claimStore I) - claimTransition.body .reverted := by - exact cometRewardsClaimBodyReverts_internal evmSolm I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - hinner - have hrev : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - exact cometRewardsClaimInternalX_after_baseTracking_failure - (slot0 := getRewardOwedRewardConfigSlot0Word σ_evm I) - (multiplier := getRewardOwedMultiplierWord σ_evm I) - (claimed := getRewardOwedClaimedWord σ_evm I) - rdBasePost hbaseOutSize - exact hrev.reEquivExecutionRevert hcode hd hdec hbody - · by_cases hbaseShort : baseOut.size < 32 - · have hdecBase := - cometRewardsBaseTrackingAccrued_decode_none_short - (out := baseOut) hbaseShort - have hinner : - ExecFuncBody config - { contract := contract, locals := claimInternalStore I } - evmSolm claimInternalFunction.body .reverted := by - exact - cometRewardsClaimInternalBodyReverts_noAccrue_getRewardAccrued_decode - evmSolm evmBase I htokenNZSolm hzero - (by simpa [evmSolm, evmBase] using hcallBaseSolm) - hdecBase - have hbody : - ExecTransitionBody config contract evmSolm (claimStore I) - claimTransition.body .reverted := by - exact cometRewardsClaimBodyReverts_internal evmSolm I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - hinner - have hrev : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - exact cometRewardsClaimInternalX_after_baseTracking_short_revert - (slot0 := getRewardOwedRewardConfigSlot0Word σ_evm I) - (multiplier := getRewardOwedMultiplierWord σ_evm I) - (claimed := getRewardOwedClaimedWord σ_evm I) - rdBasePost hbaseShort hbaseOutSize - exact hrev.reEquivExecutionRevert hcode hd hdec hbody - · have hbase32 : 32 ≤ baseOut.size := Nat.le_of_not_gt hbaseShort - by_cases hbaseWord : - fromByteArrayBigEndian (baseOut.extract 0 32) < EVM.twoPow 64 - · let baseAccrued : UInt256 := claimBaseTrackingReturnWord baseOut - have hbaseToNat : - baseAccrued.toNat = - fromByteArrayBigEndian (baseOut.extract 0 32) := by - simpa [baseAccrued, claimBaseTrackingReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt hbase32) - have hbase64 : baseAccrued.toNat < EVM.twoPow 64 := by - rw [hbaseToNat] - exact hbaseWord - have hdecBase : - config.externalABI.decode? "baseTrackingAccrued" baseOut = - some [.int (Int.ofNat baseAccrued.toNat)] := by - rw [hbaseToNat] - exact cometRewardsBaseTrackingAccrued_decode_ok - (out := baseOut) hbase32 hbaseOutHi hbaseWord - let slotE := getRewardOwedRewardConfigSlot0Word σ_evm I - let mulE := getRewardOwedMultiplierWord σ_evm I - let claimedE := getRewardOwedClaimedWord σ_evm I - have hslotLoadSolm : - getRewardOwedSlot0Load evmSolm I = - getRewardOwedRewardConfigSlot0Word σ_solm I := by - simp [evmSolm, getRewardOwedSlot0Load, - getRewardOwedRewardConfigSlot0Word, initState, - Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - have hslotLoadEvm : - getRewardOwedSlot0Load evmSolm I = slotE := by - rw [hslotLoadSolm, ← hslotWord] - have hmulWord : - getRewardOwedMultiplierWord σ_evm I = - getRewardOwedMultiplierWord σ_solm I := by - simpa [getRewardOwedMultiplierWord] using - accountMapEquiv_storage_findD hAccounts I.codeOwner - (getRewardOwedRewardConfigSlotOf I + (⟨1⟩ : UInt256)) ⟨0⟩ - have hmulLoadSolm : - getRewardOwedMultiplierLoad evmSolm I = - getRewardOwedMultiplierWord σ_solm I := by - simp [evmSolm, getRewardOwedMultiplierLoad, - getRewardOwedMultiplierWord, initState, - Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - have hmulLoadEvm : - getRewardOwedMultiplierLoad evmSolm I = mulE := by - rw [hmulLoadSolm, ← hmulWord] - have hclaimedWord : - getRewardOwedClaimedWord σ_evm I = - getRewardOwedClaimedWord σ_solm I := - accountMapEquiv_storage_findD hAccounts I.codeOwner - (getRewardOwedRewardsClaimedSlotOf I) ⟨0⟩ - have hclaimedLoadSolm : - getRewardOwedClaimedLoad evmSolm I = - getRewardOwedClaimedWord σ_solm I := by - simp [evmSolm, getRewardOwedClaimedLoad, - getRewardOwedClaimedWord, initState, - Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - have hclaimedLoadEvm : - getRewardOwedClaimedLoad evmSolm I = claimedE := by - rw [hclaimedLoadSolm, ← hclaimedWord] - obtain ⟨_, _, rd3740⟩ := - cometRewardsClaimInternalX_after_baseTracking_decode_ok - (slot0 := slotE) (multiplier := mulE) (claimed := claimedE) - rdBasePost hbase32 hbaseOutSize - (by simpa [baseAccrued] using hbase64) - by_cases hshould : - rewardConfigShouldUpscaleRawFromSlot0 slotE ≠ ⟨0⟩ - · let upNat := getRewardAccruedUpscaledNat slotE baseAccrued - let accruedNat := getRewardAccruedReturnNat mulE upNat - have hup : upNat < UInt256.size := by - simpa [upNat] using - getRewardAccruedUpscaledNat_lt_size_of_base64 - (slot0 := slotE) (accrued := baseAccrued) hbase64 - by_cases hscaled : - getRewardAccruedScaledNat mulE upNat < UInt256.size - · have hinnerAccrued : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) } - evmSolm getRewardAccruedFunction.body - (.returned - (getRewardAccruedAfterAssignedScaledFrame I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) - baseAccrued - (getRewardAccruedUpscaledNat - (getRewardOwedSlot0Load evmSolm I) baseAccrued)) - evmBase - (some [.int (Int.ofNat accruedNat)])) := by - simpa [hslotLoadEvm, hmulLoadEvm, upNat, accruedNat] using - getRewardAccruedBodyReturns_upscale - evmSolm evmBase I slotE mulE baseAccrued - (by simpa [evmSolm, evmBase] using hcallBaseSolm) - hdecBase hshould hup hscaled - obtain ⟨_, _, rd3432⟩ := - cometRewardsClaimInternalX_getRewardAccrued_upscale_success - (slot0 := slotE) (multiplier := mulE) (claimed := claimedE) - rd3740 hbase32 hbaseOutSize - (by simpa [baseAccrued] using hbase64) - hshould hscaled - have haccruedNatLt : accruedNat < UInt256.size := by - dsimp [accruedNat, getRewardAccruedReturnNat] - exact lt_of_le_of_lt (Nat.div_le_self _ _) hscaled - by_cases hleClaimed : accruedNat ≤ claimedE.toNat - · have hinnerClaim : - ExecFuncBody config - { contract := contract, locals := claimInternalStore I } - evmSolm claimInternalFunction.body - (.returned - { contract := contract, - locals := - claimInternalAfterInternalLocals evmSolm evmSolm I - accruedNat } - evmBase none) := by - exact - cometRewardsClaimInternalBodyReturns_noAccrue_noTransfer - evmSolm evmBase I htokenNZSolm hzero hinnerAccrued - (by - rw [hclaimedLoadEvm] - exact hleClaimed) - have hbody : - ExecTransitionBody config contract evmSolm (claimStore I) - claimTransition.body - (.returned - (resumeAfterInternalCall (claimFrame evmSolm I) "_claim" none) - evmBase none) := by - exact cometRewardsClaimBodyReturns_internal evmSolm evmBase I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - hinnerClaim - have hret := - cometRewardsClaimInternalX_after_getRewardAccrued_no_transfer - (slot0 := slotE) (multiplier := mulE) - (accrued := UInt256.ofNat accruedNat) - (claimed := claimedE) - (by simpa [upNat, accruedNat, baseAccrued] using rd3432) - (by - rw [UInt256.toNat_ofNat_of_lt haccruedNatLt] - exact hleClaimed) - hbaseOutSize - exact hret.reEquivExecutionGenAccountMapEquiv hcode hd hdec hbody - (by simp [evmBase]) - (by simpa [evmBase] using hPostAccounts) - (returnEquiv.fallthrough rfl rfl (by native_decide)) - · sorry - · have hinnerAccrued : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) } - evmSolm getRewardAccruedFunction.body .reverted := by - exact getRewardAccruedBodyReverts_upscale_scaledOverflow - evmSolm evmBase I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) - baseAccrued - (by simpa [evmSolm, evmBase] using hcallBaseSolm) - hdecBase - (by simpa [hslotLoadEvm] using hshould) - (by simpa [hslotLoadEvm, upNat] using hup) - (by - rw [hslotLoadEvm, hmulLoadEvm] - simpa [upNat] using Nat.le_of_not_gt hscaled) - have hinnerClaim : - ExecFuncBody config - { contract := contract, locals := claimInternalStore I } - evmSolm claimInternalFunction.body .reverted := by - exact - cometRewardsClaimInternalBodyReverts_noAccrue_getRewardAccrued_inner - evmSolm I htokenNZSolm hzero hinnerAccrued - have hbody : - ExecTransitionBody config contract evmSolm (claimStore I) - claimTransition.body .reverted := by - exact cometRewardsClaimBodyReverts_internal evmSolm I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - hinnerClaim - have hrev : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - exact - cometRewardsClaimInternalX_getRewardAccrued_upscale_overflow_revert - (slot0 := slotE) (multiplier := mulE) (claimed := claimedE) - rd3740 hbase32 hbaseOutSize - (by simpa [baseAccrued] using hbase64) - hshould (Nat.le_of_not_gt hscaled) - exact hrev.reEquivExecutionRevert hcode hd hdec hbody - · have hshouldZero : - rewardConfigShouldUpscaleRawFromSlot0 slotE = ⟨0⟩ := by - by_contra hz - exact hshould hz - by_cases hrescaleZero : - rewardConfigRescaleFromSlot0 slotE = ⟨0⟩ - · have hinnerAccrued : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) } - evmSolm getRewardAccruedFunction.body .reverted := by - exact getRewardAccruedBodyReverts_downscale_zero - evmSolm evmBase I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) - baseAccrued - (by simpa [evmSolm, evmBase] using hcallBaseSolm) - hdecBase - (by simpa [hslotLoadEvm] using hshouldZero) - (by simpa [hslotLoadEvm] using hrescaleZero) - have hinnerClaim : - ExecFuncBody config - { contract := contract, locals := claimInternalStore I } - evmSolm claimInternalFunction.body .reverted := by - exact - cometRewardsClaimInternalBodyReverts_noAccrue_getRewardAccrued_inner - evmSolm I htokenNZSolm hzero hinnerAccrued - have hbody : - ExecTransitionBody config contract evmSolm (claimStore I) - claimTransition.body .reverted := by - exact cometRewardsClaimBodyReverts_internal evmSolm I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - hinnerClaim - have hrev : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - exact - cometRewardsClaimInternalX_getRewardAccrued_downscale_zero_revert - (slot0 := slotE) (multiplier := mulE) (claimed := claimedE) - rd3740 hbase32 hbaseOutSize - (by simpa [baseAccrued] using hbase64) - hshouldZero hrescaleZero - exact hrev.reEquivExecutionRevert hcode hd hdec hbody - · let downNat := getRewardAccruedDownscaledNat slotE baseAccrued - let accruedNat := getRewardAccruedReturnNat mulE downNat - by_cases hscaled : - getRewardAccruedScaledNat mulE downNat < UInt256.size - · have hinnerAccrued : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) } - evmSolm getRewardAccruedFunction.body - (.returned - (getRewardAccruedAfterAssignedScaledFrame I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) - baseAccrued - (getRewardAccruedDownscaledNat - (getRewardOwedSlot0Load evmSolm I) baseAccrued)) - evmBase - (some [.int (Int.ofNat accruedNat)])) := by - simpa [hslotLoadEvm, hmulLoadEvm, downNat, accruedNat] using - getRewardAccruedBodyReturns_downscale - evmSolm evmBase I slotE mulE baseAccrued - (by simpa [evmSolm, evmBase] using hcallBaseSolm) - hdecBase hshouldZero hrescaleZero hscaled - obtain ⟨_, _, rd3432⟩ := - cometRewardsClaimInternalX_getRewardAccrued_downscale_success - (slot0 := slotE) (multiplier := mulE) (claimed := claimedE) - rd3740 hbase32 hbaseOutSize - (by simpa [baseAccrued] using hbase64) - hshouldZero hrescaleZero hscaled - have haccruedNatLt : accruedNat < UInt256.size := by - dsimp [accruedNat, getRewardAccruedReturnNat] - exact lt_of_le_of_lt (Nat.div_le_self _ _) hscaled - by_cases hleClaimed : accruedNat ≤ claimedE.toNat - · have hinnerClaim : - ExecFuncBody config - { contract := contract, locals := claimInternalStore I } - evmSolm claimInternalFunction.body - (.returned - { contract := contract, - locals := - claimInternalAfterInternalLocals evmSolm evmSolm I - accruedNat } - evmBase none) := by - exact - cometRewardsClaimInternalBodyReturns_noAccrue_noTransfer - evmSolm evmBase I htokenNZSolm hzero hinnerAccrued - (by - rw [hclaimedLoadEvm] - exact hleClaimed) - have hbody : - ExecTransitionBody config contract evmSolm (claimStore I) - claimTransition.body - (.returned - (resumeAfterInternalCall - (claimFrame evmSolm I) "_claim" none) - evmBase none) := by - exact cometRewardsClaimBodyReturns_internal evmSolm evmBase I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - hinnerClaim - have hret := - cometRewardsClaimInternalX_after_getRewardAccrued_no_transfer - (slot0 := slotE) (multiplier := mulE) - (accrued := UInt256.ofNat accruedNat) - (claimed := claimedE) - (by simpa [downNat, accruedNat, baseAccrued] using rd3432) - (by - rw [UInt256.toNat_ofNat_of_lt haccruedNatLt] - exact hleClaimed) - hbaseOutSize - exact hret.reEquivExecutionGenAccountMapEquiv hcode hd hdec hbody - (by simp [evmBase]) - (by simpa [evmBase] using hPostAccounts) - (returnEquiv.fallthrough rfl rfl (by native_decide)) - · sorry - · have hinnerAccrued : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) } - evmSolm getRewardAccruedFunction.body .reverted := by - exact getRewardAccruedBodyReverts_downscale_scaledOverflow - evmSolm evmBase I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) - baseAccrued - (by simpa [evmSolm, evmBase] using hcallBaseSolm) - hdecBase - (by simpa [hslotLoadEvm] using hshouldZero) - (by simpa [hslotLoadEvm] using hrescaleZero) - (by - rw [hslotLoadEvm, hmulLoadEvm] - simpa [downNat] using Nat.le_of_not_gt hscaled) - have hinnerClaim : - ExecFuncBody config - { contract := contract, locals := claimInternalStore I } - evmSolm claimInternalFunction.body .reverted := by - exact - cometRewardsClaimInternalBodyReverts_noAccrue_getRewardAccrued_inner - evmSolm I htokenNZSolm hzero hinnerAccrued - have hbody : - ExecTransitionBody config contract evmSolm (claimStore I) - claimTransition.body .reverted := by - exact cometRewardsClaimBodyReverts_internal evmSolm I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - hinnerClaim - have hrev : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - exact - cometRewardsClaimInternalX_getRewardAccrued_downscale_overflow_revert - (slot0 := slotE) (multiplier := mulE) (claimed := claimedE) - rd3740 hbase32 hbaseOutSize - (by simpa [baseAccrued] using hbase64) - hshouldZero hrescaleZero (Nat.le_of_not_gt hscaled) - exact hrev.reEquivExecutionRevert hcode hd hdec hbody - · have hdecBase := - cometRewardsBaseTrackingAccrued_decode_none_noncanon - (out := baseOut) hbase32 hbaseOutHi hbaseWord - have hinner : - ExecFuncBody config - { contract := contract, locals := claimInternalStore I } - evmSolm claimInternalFunction.body .reverted := by - exact - cometRewardsClaimInternalBodyReverts_noAccrue_getRewardAccrued_decode - evmSolm evmBase I htokenNZSolm hzero - (by simpa [evmSolm, evmBase] using hcallBaseSolm) - hdecBase - have hbody : - ExecTransitionBody config contract evmSolm (claimStore I) - claimTransition.body .reverted := by - exact cometRewardsClaimBodyReverts_internal evmSolm I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - hinner - have hreturnToNat : - (claimBaseTrackingReturnWord baseOut).toNat = - fromByteArrayBigEndian (baseOut.extract 0 32) := by - simpa [claimBaseTrackingReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt hbase32) - have hbaseNo : - ¬ (claimBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64 := by - intro hlt - exact hbaseWord (by rw [← hreturnToNat]; exact hlt) - have hrev : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - exact cometRewardsClaimInternalX_after_baseTracking_noncanon_revert - (slot0 := getRewardOwedRewardConfigSlot0Word σ_evm I) - (multiplier := getRewardOwedMultiplierWord σ_evm I) - (claimed := getRewardOwedClaimedWord σ_evm I) - rdBasePost hbase32 hbaseOutSize hbaseNo - exact hrev.reEquivExecutionRevert hcode hd hdec hbody - · have hdepth1024 : I.depth = 1024 := - Fin.ext (by - have hlt := I.depth.isLt - have hge : 1024 ≤ I.depth.val := Nat.le_of_not_gt hdepth - omega) - let evmFail : EVM.State := - { evmSolm with - substate := - (evmSolm.addAccessedAccount - (EVM.address (getRewardOwedCometTarget I))).substate } - have hcallS : - typedCallViaEVM config evmSolm - (EVM.address (getRewardOwedCometTarget I)) "baseTrackingAccrued" 0 - (getRewardAccruedBaseTrackingArgs I) - (false, evmFail, ByteArray.empty) false := by - exact callNotMade_depthLimit - (cfg := config) (evm := evmSolm) - (tgt := EVM.address (getRewardOwedCometTarget I)) - (name := "baseTrackingAccrued") - (args := getRewardAccruedBaseTrackingArgs I) - (calldata := - (claimBaseTrackingCalldataMem I - (getRewardOwedRewardConfigSlot0Word σ_solm I) - (getRewardOwedMultiplierWord σ_solm I)).readWithPadding - 256 claimBaseTrackingCallSize.toNat) - (callPerm := false) - (claimBaseTrackingCalldataMem_encode_args I - (getRewardOwedRewardConfigSlot0Word σ_solm I) - (getRewardOwedMultiplierWord σ_solm I) hcanonSrc) - (by simpa [evmSolm, initState] using hdepth1024) - have hinner : - ExecFuncBody config - { contract := contract, locals := claimInternalStore I } - evmSolm claimInternalFunction.body .reverted := by - exact cometRewardsClaimInternalBodyReverts_noAccrue_getRewardAccrued - evmSolm evmFail I htokenNZSolm hzero hcallS - have hbody : - ExecTransitionBody config contract evmSolm (claimStore I) - claimTransition.body .reverted := by - exact cometRewardsClaimBodyReverts_internal evmSolm I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - hinner - exact (cometRewardsClaimInternalX_noAccrue_callDepthLimit - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - hcanonComet hcanonSrc htokenZero hzero hreach3298 hdepth1024) - |>.reEquivExecutionRevert hcode hd hdec hbody - · by_cases hone : claimShouldAccrueWord I = ⟨1⟩ - · have hdec := cometRewardsDecode_claim_ok - (I := I) hsz100 hhi hcanonComet hcanonSrc (Or.inr hone) - have hslotWord : - getRewardOwedRewardConfigSlot0Word σ_evm I = - getRewardOwedRewardConfigSlot0Word σ_solm I := - accountMapEquiv_storage_findD hAccounts I.codeOwner - (getRewardOwedRewardConfigSlotOf I) ⟨0⟩ - by_cases htokenZero : - rewardConfigTokenFromSlot0 - (getRewardOwedRewardConfigSlot0Word σ_evm I) = ⟨0⟩ - · let evmSolm : EVM.State := - initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I - have htokenZeroSolm : - rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evmSolm I) = ⟨0⟩ := by - have hload : - getRewardOwedSlot0Load evmSolm I = - getRewardOwedRewardConfigSlot0Word σ_solm I := by - simp [evmSolm, getRewardOwedSlot0Load, getRewardOwedRewardConfigSlot0Word, - initState, Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - rw [hload, ← hslotWord] - exact htokenZero - have hbody : - ExecTransitionBody config contract evmSolm (claimStore I) - claimTransition.body .reverted := by - exact cometRewardsClaimBodyReverts_internal evmSolm I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - (cometRewardsClaimInternalBodyReverts_tokenZero evmSolm I htokenZeroSolm) - have hreach3298 := - cometRewardsClaimX_dec3298_internal (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanonComet hcanonSrc (Or.inr hone) hreach - exact (cometRewardsClaimInternalX_tokenZero_of_reach - (g := Sat256.ofUInt256 g) hcanonComet htokenZero hreach3298) - |>.reEquivExecutionRevert hcode hd hdec hbody - · sorry - · have hdec := cometRewardsDecode_claim_none_noncanon_bool - (I := I) hsz100 hhi hcanonComet hcanonSrc hzero hone - exact (cometRewardsClaimX_noncanon_bool (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanonComet hcanonSrc hzero hone hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hdec := cometRewardsDecode_claim_none_noncanon_src - (I := I) hsz100 hhi hcanonComet hcanonSrc - have hnc : UInt256.eq (claimSrcWord I) - (UInt256.land (claimSrcWord I) solcAddrMask) = ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanonSrc (solcAddrCanonical_of_clean he)) - exact (cometRewardsClaimX_noncanon_src (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanonComet hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hdec := cometRewardsDecode_claim_none_noncanon_comet - (I := I) hsz100 hhi hcanonComet - have hnc : UInt256.eq (claimCometWord I) - (UInt256.land (claimCometWord I) solcAddrMask) = ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanonComet (solcAddrCanonical_of_clean he)) - exact (cometRewardsClaimX_noncanon_comet (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hbig : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - have hdec := cometRewardsDecode_claim_none_huge (I := I) hbig - exact (cometRewardsClaimX_hugearg (g := Sat256.ofUInt256 g) - hwv hsize hbig hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hshort : I.calldata.size < 100 := by omega - have hdec := cometRewardsDecode_claim_none_short (I := I) hsz4 hshort - exact (cometRewardsClaimX_shortarg (g := Sat256.ofUInt256 g) - hwv hsz4 hsize hshort hreach) - |>.reEquivDecodingFailed hcode hd hdec - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/ClaimTo.lean b/Benchmarks/CompoundIII/CometRewards/ClaimTo.lean deleted file mode 100644 index d7ce375f..00000000 --- a/Benchmarks/CompoundIII/CometRewards/ClaimTo.lean +++ /dev/null @@ -1,20 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.Common - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.CompoundIII.CometRewards - -/-- `claimTo(address,address,address,bool)` body, reached at pc 2044. -/ -theorem cometRewardsClaimToBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hsel : selIs I (cometRewardsSelBytes 4)) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) claimToPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/Common.lean b/Benchmarks/CompoundIII/CometRewards/Common.lean deleted file mode 100644 index d33c0d96..00000000 --- a/Benchmarks/CompoundIII/CometRewards/Common.lean +++ /dev/null @@ -1,1617 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.Trusted -import Benchmarks.CompoundIII.CometRewards.Spec -import Reasoning.ABI -import Reasoning.Dispatch -import Reasoning.Memory -import Reasoning.Reach -import Reasoning.Solc -import Reasoning.SolmBody -import Mathlib.Tactic.IntervalCases - -/-! -# CometRewards shared proof scaffold - -This file records the bytecode dispatch order and the exact body-entry stack shapes produced by -the via-IR dispatcher. The prefix is not the standard `solcDispatchReachBody` prefix, so the -`cometRewardsReach...` lemmas are local proof obligations rather than uses of the generic driver. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace Benchmarks.CompoundIII.CometRewards - -/-- The 4-byte function selector word the dispatcher computes from `calldata[0:32]`. -/ -abbrev cometRewardsSelWord (I : ExecutionEnv) : UInt256 := - UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes 0 32)) ⟨224⟩ - -/-- The 4-byte selector of `I`'s calldata equals `sel`. -/ -abbrev selIs (I : ExecutionEnv) (sel : ByteArray) : Prop := - (sel == I.calldata.extract 0 4) = true - -theorem selectorFalseOfMatch {I : ExecutionEnv} {want other : ByteArray} - (hne : other ≠ want) (hsel : selIs I want) : - (other == I.calldata.extract 0 4) = false := by - by_cases hother : (other == I.calldata.extract 0 4) = true - · have hotherEq : other = I.calldata.extract 0 4 := by - apply ByteArray.ext - rw [show (other == I.calldata.extract 0 4) = - (other.data == (I.calldata.extract 0 4).data) from rfl] at hother - exact beq_iff_eq.mp hother - have hwantEq : want = I.calldata.extract 0 4 := by - apply ByteArray.ext - change (want == I.calldata.extract 0 4) = true at hsel - rw [show (want == I.calldata.extract 0 4) = - (want.data == (I.calldata.extract 0 4).data) from rfl] at hsel - exact beq_iff_eq.mp hsel - exact False.elim (hne (by rw [hotherEq, hwantEq])) - · cases h : other == I.calldata.extract 0 4 <;> simp_all - -/-! ## ABI decode helpers not yet in `Reasoning.ABI` -/ - --- LIBRARY CANDIDATE: generalizes `Reasoning.Theory.decodeScalarWords_address_address_uint256_ok` --- by replacing the third scalar word with a canonical bool. -theorem decodeScalarWords_address_address_bool_ok {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) - (hlen32 : ((bytes.drop 32).take 32).length = 32) - (hlen64 : ((bytes.drop 64).take 32).length = 32) - (hcanon0 : (ABI.bytesToWord (bytes.take 32)).toNat < EVM.addressModulus) - (hcanon32 : (ABI.bytesToWord ((bytes.drop 32).take 32)).toNat < EVM.addressModulus) - (hbool64 : - ABI.bytesToWord ((bytes.drop 64).take 32) = ⟨0⟩ ∨ - ABI.bytesToWord ((bytes.drop 64).take 32) = ⟨1⟩) : - decodeScalarWords? [.elem .address, .elem .address, .elem .bool] bytes 0 = - some [.address (Ethereum.AccountAddress.ofNat (ABI.bytesToWord (bytes.take 32)).toNat), - .address (Ethereum.AccountAddress.ofNat - (ABI.bytesToWord ((bytes.drop 32).take 32)).toNat), - wordToElem .bool (ABI.bytesToWord ((bytes.drop 64).take 32))] := by - simp only [decodeScalarWords?, Nat.zero_add] - rw [decodeScalarWord_address_ok (start := 0) (by simpa using hlen0) - (by simpa using hcanon0)] - simp only [Option.bind, bind] - rw [decodeScalarWord_address_ok (start := 32) hlen32 hcanon32] - rcases hbool64 with hzero | hone - · rw [decodeScalarWord_bool_ok_zero (start := 64) hlen64 hzero] - simp [wordToElem, hzero] - · rw [decodeScalarWord_bool_ok_one (start := 64) hlen64 hone] - simp [wordToElem, hone] - --- LIBRARY CANDIDATE: address,address,bool scalar-list noncanonical first address branch. -theorem decodeScalarWords_address_address_bool_none_noncanon0 {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) - (hnc0 : ¬ (ABI.bytesToWord (bytes.take 32)).toNat < EVM.addressModulus) : - decodeScalarWords? [.elem .address, .elem .address, .elem .bool] bytes 0 = none := by - simp only [decodeScalarWords?, Nat.zero_add] - rw [decodeScalarWord_address_none_noncanon (start := 0) (by simpa using hlen0) - (by simpa using hnc0)] - simp only [Option.bind, bind] - --- LIBRARY CANDIDATE: address,address,bool scalar-list noncanonical second address branch. -theorem decodeScalarWords_address_address_bool_none_noncanon1 {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) - (hlen32 : ((bytes.drop 32).take 32).length = 32) - (hcanon0 : (ABI.bytesToWord (bytes.take 32)).toNat < EVM.addressModulus) - (hnc32 : ¬ (ABI.bytesToWord ((bytes.drop 32).take 32)).toNat < EVM.addressModulus) : - decodeScalarWords? [.elem .address, .elem .address, .elem .bool] bytes 0 = none := by - simp only [decodeScalarWords?, Nat.zero_add] - rw [decodeScalarWord_address_ok (start := 0) (by simpa using hlen0) - (by simpa using hcanon0)] - simp only [Option.bind, bind] - rw [decodeScalarWord_address_none_noncanon (start := 32) hlen32 hnc32] - --- LIBRARY CANDIDATE: address,address,bool scalar-list noncanonical bool branch. -theorem decodeScalarWords_address_address_bool_none_noncanon2 {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) - (hlen32 : ((bytes.drop 32).take 32).length = 32) - (hlen64 : ((bytes.drop 64).take 32).length = 32) - (hcanon0 : (ABI.bytesToWord (bytes.take 32)).toNat < EVM.addressModulus) - (hcanon32 : (ABI.bytesToWord ((bytes.drop 32).take 32)).toNat < EVM.addressModulus) - (hnz64 : ABI.bytesToWord ((bytes.drop 64).take 32) ≠ ⟨0⟩) - (hno64 : ABI.bytesToWord ((bytes.drop 64).take 32) ≠ ⟨1⟩) : - decodeScalarWords? [.elem .address, .elem .address, .elem .bool] bytes 0 = none := by - simp only [decodeScalarWords?, Nat.zero_add] - rw [decodeScalarWord_address_ok (start := 0) (by simpa using hlen0) - (by simpa using hcanon0)] - simp only [Option.bind, bind] - rw [decodeScalarWord_address_ok (start := 32) hlen32 hcanon32] - rw [decodeScalarWord_bool_none_noncanon (start := 64) hlen64 hnz64 hno64] - --- LIBRARY CANDIDATE: address,address,bool scalar-list short calldata branch. -theorem decodeScalarWords_address_address_bool_none_short {bytes : List UInt8} - (hshort : bytes.length < 96) : - decodeScalarWords? [.elem .address, .elem .address, .elem .bool] bytes 0 = none := by - simp only [decodeScalarWords?, Nat.zero_add] - by_cases h32 : bytes.length < 32 - · have htake0n : ¬ (bytes.take 32).length = 32 := by - rw [List.length_take] - omega - rw [decodeScalarWord_address_none_short (start := 0) (by simpa using htake0n)] - simp only [Option.bind, bind] - · have htake0 : (bytes.take 32).length = 32 := by - rw [List.length_take] - omega - by_cases h64 : bytes.length < 64 - · have htake32n : ¬ ((bytes.drop 32).take 32).length = 32 := by - rw [List.length_take, List.length_drop] - omega - by_cases hcanon0 : (ABI.bytesToWord (bytes.take 32)).toNat < EVM.addressModulus - · rw [decodeScalarWord_address_ok (start := 0) (by simpa using htake0) - (by simpa using hcanon0)] - simp only [Option.bind, bind] - rw [decodeScalarWord_address_none_short (start := 32) htake32n] - · rw [decodeScalarWord_address_none_noncanon (start := 0) (by simpa using htake0) - (by simpa using hcanon0)] - simp only [Option.bind, bind] - · have htake32 : ((bytes.drop 32).take 32).length = 32 := by - rw [List.length_take, List.length_drop] - omega - have htake64n : ¬ ((bytes.drop 64).take 32).length = 32 := by - rw [List.length_take, List.length_drop] - omega - by_cases hcanon0 : (ABI.bytesToWord (bytes.take 32)).toNat < EVM.addressModulus - · by_cases hcanon32 : - (ABI.bytesToWord ((bytes.drop 32).take 32)).toNat < EVM.addressModulus - · rw [decodeScalarWord_address_ok (start := 0) (by simpa using htake0) - (by simpa using hcanon0)] - simp only [Option.bind, bind] - rw [decodeScalarWord_address_ok (start := 32) htake32 hcanon32] - rw [decodeScalarWord_bool_none_short (start := 64) htake64n] - · rw [decodeScalarWord_address_ok (start := 0) (by simpa using htake0) - (by simpa using hcanon0)] - simp only [Option.bind, bind] - rw [decodeScalarWord_address_none_noncanon (start := 32) htake32 hcanon32] - · rw [decodeScalarWord_address_none_noncanon (start := 0) (by simpa using htake0) - (by simpa using hcanon0)] - simp only [Option.bind, bind] - --- LIBRARY CANDIDATE: ABI calldata decoding for `(address,address,bool)`. -theorem decodeCalldata_address_address_bool_ok {cd : ByteArray} {x y z : Solm.Ident} - (hsz100 : 100 ≤ cd.size) (hbig : cd.size < 2 ^ 255 + 4) - (hcanon0 : (calldataWord cd 4).toNat < EVM.addressModulus) - (hcanon1 : (calldataWord cd 36).toNat < EVM.addressModulus) - (hbool : calldataWord cd 68 = ⟨0⟩ ∨ calldataWord cd 68 = ⟨1⟩) : - decodeCalldata [x, y, z] [.elem .address, .elem .address, .elem .bool] cd = - some ((((∅ : Solm.Store).insert x - (.address (Ethereum.AccountAddress.ofNat (calldataWord cd 4).toNat))).insert y - (.address (Ethereum.AccountAddress.ofNat (calldataWord cd 36).toNat))).insert z - (wordToElem .bool (calldataWord cd 68))) := by - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake4 : ((cd.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have htake36 : ((cd.toList.drop 36).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have htake68 : ((cd.toList.drop 68).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have hword4 : ABI.bytesToWord ((cd.toList.drop 4).take 32) = calldataWord cd 4 := - decode_word_at_eq cd 4 (by omega) (by norm_num) - have hword36 : ABI.bytesToWord ((cd.toList.drop 36).take 32) = calldataWord cd 36 := - decode_word_at_eq cd 36 (by omega) (by norm_num) - have hword68 : ABI.bytesToWord ((cd.toList.drop 68).take 32) = calldataWord cd 68 := - decode_word_at_eq cd 68 (by omega) (by norm_num) - have htake36' : ((cd.toList.drop 4).drop 32 |>.take 32).length = 32 := by - simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using htake36 - have htake68' : ((cd.toList.drop 4).drop 64 |>.take 32).length = 32 := by - simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using htake68 - rw [decodeCalldata_scalarWords_eq (names := [x, y, z]) - (types := [.elem .address, .elem .address, .elem .bool]) (cd := cd) (by decide)] - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - rw [if_neg (by rintro ⟨_, hc⟩; rw [List.length_drop, htlen] at hc; omega)] - rw [decodeScalarWords_address_address_bool_ok (bytes := cd.toList.drop 4) htake4 - htake36' htake68' - (by rw [hword4]; exact hcanon0) - (by rw [show ABI.bytesToWord (((cd.toList.drop 4).drop 32).take 32) = - calldataWord cd 36 from by simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, - Nat.add_assoc] using hword36]; exact hcanon1) - (by - rcases hbool with hzero | hone - · left - rw [show ABI.bytesToWord (((cd.toList.drop 4).drop 64).take 32) = - calldataWord cd 68 from by - simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using hword68] - exact hzero - · right - rw [show ABI.bytesToWord (((cd.toList.drop 4).drop 64).take 32) = - calldataWord cd 68 from by - simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using hword68] - exact hone)] - change decodeCalldata.insertValues [x, y, z] - [.address (Ethereum.AccountAddress.ofNat - (ABI.bytesToWord ((cd.toList.drop 4).take 32)).toNat), - .address (Ethereum.AccountAddress.ofNat - (ABI.bytesToWord (((cd.toList.drop 4).drop 32).take 32)).toNat), - wordToElem .bool (ABI.bytesToWord (((cd.toList.drop 4).drop 64).take 32))] ∅ = - some ((((∅ : Solm.Store).insert x - (.address (Ethereum.AccountAddress.ofNat (calldataWord cd 4).toNat))).insert y - (.address (Ethereum.AccountAddress.ofNat (calldataWord cd 36).toNat))).insert z - (wordToElem .bool (calldataWord cd 68))) - simp [decodeCalldata.insertValues] - rw [hword4, hword36, hword68] - --- LIBRARY CANDIDATE: ABI calldata noncanonical first address branch for `(address,address,bool)`. -theorem decodeCalldata_address_address_bool_none_noncanon0 {cd : ByteArray} - {x y z : Solm.Ident} - (hsz100 : 100 ≤ cd.size) (hbig : cd.size < 2 ^ 255 + 4) - (hnc0 : ¬ (calldataWord cd 4).toNat < EVM.addressModulus) : - decodeCalldata [x, y, z] [.elem .address, .elem .address, .elem .bool] cd = none := by - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake4 : ((cd.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have hword4 : ABI.bytesToWord ((cd.toList.drop 4).take 32) = calldataWord cd 4 := - decode_word_at_eq cd 4 (by omega) (by norm_num) - rw [decodeCalldata_scalarWords_eq (names := [x, y, z]) - (types := [.elem .address, .elem .address, .elem .bool]) (cd := cd) (by decide)] - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - rw [if_neg (by rintro ⟨_, hc⟩; rw [List.length_drop, htlen] at hc; omega)] - rw [decodeScalarWords_address_address_bool_none_noncanon0 (bytes := cd.toList.drop 4) - htake4 (by rw [hword4]; exact hnc0)] - --- LIBRARY CANDIDATE: ABI calldata noncanonical second address branch for `(address,address,bool)`. -theorem decodeCalldata_address_address_bool_none_noncanon1 {cd : ByteArray} - {x y z : Solm.Ident} - (hsz100 : 100 ≤ cd.size) (hbig : cd.size < 2 ^ 255 + 4) - (hcanon0 : (calldataWord cd 4).toNat < EVM.addressModulus) - (hnc1 : ¬ (calldataWord cd 36).toNat < EVM.addressModulus) : - decodeCalldata [x, y, z] [.elem .address, .elem .address, .elem .bool] cd = none := by - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake4 : ((cd.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have htake36 : ((cd.toList.drop 36).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have hword4 : ABI.bytesToWord ((cd.toList.drop 4).take 32) = calldataWord cd 4 := - decode_word_at_eq cd 4 (by omega) (by norm_num) - have hword36 : ABI.bytesToWord ((cd.toList.drop 36).take 32) = calldataWord cd 36 := - decode_word_at_eq cd 36 (by omega) (by norm_num) - have htake36' : ((cd.toList.drop 4).drop 32 |>.take 32).length = 32 := by - simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using htake36 - rw [decodeCalldata_scalarWords_eq (names := [x, y, z]) - (types := [.elem .address, .elem .address, .elem .bool]) (cd := cd) (by decide)] - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - rw [if_neg (by rintro ⟨_, hc⟩; rw [List.length_drop, htlen] at hc; omega)] - rw [decodeScalarWords_address_address_bool_none_noncanon1 (bytes := cd.toList.drop 4) - htake4 htake36' - (by rw [hword4]; exact hcanon0) - (by rw [show ABI.bytesToWord (((cd.toList.drop 4).drop 32).take 32) = - calldataWord cd 36 from by simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, - Nat.add_assoc] using hword36]; exact hnc1)] - --- LIBRARY CANDIDATE: ABI calldata noncanonical bool branch for `(address,address,bool)`. -theorem decodeCalldata_address_address_bool_none_noncanon2 {cd : ByteArray} - {x y z : Solm.Ident} - (hsz100 : 100 ≤ cd.size) (hbig : cd.size < 2 ^ 255 + 4) - (hcanon0 : (calldataWord cd 4).toNat < EVM.addressModulus) - (hcanon1 : (calldataWord cd 36).toNat < EVM.addressModulus) - (hnz2 : calldataWord cd 68 ≠ ⟨0⟩) (hno2 : calldataWord cd 68 ≠ ⟨1⟩) : - decodeCalldata [x, y, z] [.elem .address, .elem .address, .elem .bool] cd = none := by - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake4 : ((cd.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have htake36 : ((cd.toList.drop 36).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have htake68 : ((cd.toList.drop 68).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have hword4 : ABI.bytesToWord ((cd.toList.drop 4).take 32) = calldataWord cd 4 := - decode_word_at_eq cd 4 (by omega) (by norm_num) - have hword36 : ABI.bytesToWord ((cd.toList.drop 36).take 32) = calldataWord cd 36 := - decode_word_at_eq cd 36 (by omega) (by norm_num) - have hword68 : ABI.bytesToWord ((cd.toList.drop 68).take 32) = calldataWord cd 68 := - decode_word_at_eq cd 68 (by omega) (by norm_num) - have htake36' : ((cd.toList.drop 4).drop 32 |>.take 32).length = 32 := by - simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using htake36 - have htake68' : ((cd.toList.drop 4).drop 64 |>.take 32).length = 32 := by - simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using htake68 - rw [decodeCalldata_scalarWords_eq (names := [x, y, z]) - (types := [.elem .address, .elem .address, .elem .bool]) (cd := cd) (by decide)] - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - rw [if_neg (by rintro ⟨_, hc⟩; rw [List.length_drop, htlen] at hc; omega)] - rw [decodeScalarWords_address_address_bool_none_noncanon2 (bytes := cd.toList.drop 4) - htake4 htake36' htake68' - (by rw [hword4]; exact hcanon0) - (by rw [show ABI.bytesToWord (((cd.toList.drop 4).drop 32).take 32) = - calldataWord cd 36 from by simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, - Nat.add_assoc] using hword36]; exact hcanon1) - (by - rw [show ABI.bytesToWord (((cd.toList.drop 4).drop 64).take 32) = - calldataWord cd 68 from by - simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using hword68] - exact hnz2) - (by - rw [show ABI.bytesToWord (((cd.toList.drop 4).drop 64).take 32) = - calldataWord cd 68 from by - simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using hword68] - exact hno2)] - --- LIBRARY CANDIDATE: ABI calldata short branch for `(address,address,bool)`. -theorem decodeCalldata_address_address_bool_none_short {cd : ByteArray} - {x y z : Solm.Ident} (hsz4 : 4 ≤ cd.size) (hshort : cd.size < 100) : - decodeCalldata [x, y, z] [.elem .address, .elem .address, .elem .bool] cd = none := by - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [decodeCalldata_scalarWords_eq (names := [x, y, z]) - (types := [.elem .address, .elem .address, .elem .bool]) (cd := cd) (by decide)] - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - rw [if_neg (by rintro ⟨_, hc⟩; rw [List.length_drop, htlen] at hc; omega)] - rw [decodeScalarWords_address_address_bool_none_short (bytes := cd.toList.drop 4) (by - rw [List.length_drop, htlen] - omega)] - --- LIBRARY CANDIDATE: ABI calldata huge branch for `(address,address,bool)`. -theorem decodeCalldata_address_address_bool_none_huge {cd : ByteArray} - {x y z : Solm.Ident} (hbig : 2 ^ 255 + 4 ≤ cd.size) : - decodeCalldata [x, y, z] [.elem .address, .elem .address, .elem .bool] cd = none := by - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [decodeCalldata_scalarWords_eq (names := [x, y, z]) - (types := [.elem .address, .elem .address, .elem .bool]) (cd := cd) (by decide)] - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - rw [if_pos] - exact ⟨rfl, by rw [List.length_drop, htlen]; omega⟩ - -/-! ## Dispatch order and body PCs -/ - -/-- Function selectors in bytecode dispatch-arm order. -/ -def cometRewardsSelBytes : ℕ → ByteArray - | 0 => ⟨#[0x01, 0xe3, 0x36, 0x67]⟩ -- withdrawToken(address,address,uint256) - | 1 => ⟨#[0x0c, 0x34, 0x0a, 0x24]⟩ -- governor() - | 2 => ⟨#[0x22, 0x89, 0xb6, 0xb8]⟩ -- rewardConfig(address) - | 3 => ⟨#[0x41, 0xe0, 0xca, 0xd6]⟩ -- getRewardOwed(address,address) - | 4 => ⟨#[0x4f, 0xf8, 0x5d, 0x94]⟩ -- claimTo(address,address,address,bool) - | 5 => ⟨#[0x63, 0x94, 0xf1, 0x61]⟩ -- setRewardsClaimed(address,address[],uint256[]) - | 6 => ⟨#[0x65, 0xe1, 0x23, 0x92]⟩ -- rewardsClaimed(address,address) - | 7 => ⟨#[0x95, 0xe3, 0x6d, 0x2c]⟩ -- setRewardConfig(address,address) - | 8 => ⟨#[0xb7, 0x03, 0x4f, 0x7e]⟩ -- claim(address,address,bool) - | 9 => ⟨#[0xb8, 0xcc, 0x9c, 0xe6]⟩ -- transferGovernor(address) - | _ => ⟨#[0xcd, 0xc0, 0xca, 0x09]⟩ -- setRewardConfigWithMultiplier(...) - -theorem cometRewardsSelectorEq0 (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) : - UInt256.eq (⟨0x01e33667⟩ : UInt256) (cometRewardsSelWord I) = - if cometRewardsSelBytes 0 == I.calldata.extract 0 4 then ⟨1⟩ else ⟨0⟩ := by - simpa [cometRewardsSelWord, cometRewardsSelBytes] using - (evmSelectorDecode (cd := I.calldata) hsz 0x01 0xe3 0x36 0x67 - (⟨0x01e33667⟩ : UInt256) (by native_decide)) - -theorem cometRewardsSelectorEq1 (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) : - UInt256.eq (⟨0x0c340a24⟩ : UInt256) (cometRewardsSelWord I) = - if cometRewardsSelBytes 1 == I.calldata.extract 0 4 then ⟨1⟩ else ⟨0⟩ := by - simpa [cometRewardsSelWord, cometRewardsSelBytes] using - (evmSelectorDecode (cd := I.calldata) hsz 0x0c 0x34 0x0a 0x24 - (⟨0x0c340a24⟩ : UInt256) (by native_decide)) - -theorem cometRewardsSelectorEq2 (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) : - UInt256.eq (⟨0x2289b6b8⟩ : UInt256) (cometRewardsSelWord I) = - if cometRewardsSelBytes 2 == I.calldata.extract 0 4 then ⟨1⟩ else ⟨0⟩ := by - simpa [cometRewardsSelWord, cometRewardsSelBytes] using - (evmSelectorDecode (cd := I.calldata) hsz 0x22 0x89 0xb6 0xb8 - (⟨0x2289b6b8⟩ : UInt256) (by native_decide)) - -theorem cometRewardsSelectorEq3 (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) : - UInt256.eq (⟨0x41e0cad6⟩ : UInt256) (cometRewardsSelWord I) = - if cometRewardsSelBytes 3 == I.calldata.extract 0 4 then ⟨1⟩ else ⟨0⟩ := by - simpa [cometRewardsSelWord, cometRewardsSelBytes] using - (evmSelectorDecode (cd := I.calldata) hsz 0x41 0xe0 0xca 0xd6 - (⟨0x41e0cad6⟩ : UInt256) (by native_decide)) - -theorem cometRewardsSelectorEq4 (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) : - UInt256.eq (⟨0x4ff85d94⟩ : UInt256) (cometRewardsSelWord I) = - if cometRewardsSelBytes 4 == I.calldata.extract 0 4 then ⟨1⟩ else ⟨0⟩ := by - simpa [cometRewardsSelWord, cometRewardsSelBytes] using - (evmSelectorDecode (cd := I.calldata) hsz 0x4f 0xf8 0x5d 0x94 - (⟨0x4ff85d94⟩ : UInt256) (by native_decide)) - -theorem cometRewardsSelectorEq5 (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) : - UInt256.eq (⟨0x6394f161⟩ : UInt256) (cometRewardsSelWord I) = - if cometRewardsSelBytes 5 == I.calldata.extract 0 4 then ⟨1⟩ else ⟨0⟩ := by - simpa [cometRewardsSelWord, cometRewardsSelBytes] using - (evmSelectorDecode (cd := I.calldata) hsz 0x63 0x94 0xf1 0x61 - (⟨0x6394f161⟩ : UInt256) (by native_decide)) - -theorem cometRewardsSelectorEq6 (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) : - UInt256.eq (⟨0x65e12392⟩ : UInt256) (cometRewardsSelWord I) = - if cometRewardsSelBytes 6 == I.calldata.extract 0 4 then ⟨1⟩ else ⟨0⟩ := by - simpa [cometRewardsSelWord, cometRewardsSelBytes] using - (evmSelectorDecode (cd := I.calldata) hsz 0x65 0xe1 0x23 0x92 - (⟨0x65e12392⟩ : UInt256) (by native_decide)) - -theorem cometRewardsSelectorEq7 (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) : - UInt256.eq (⟨0x95e36d2c⟩ : UInt256) (cometRewardsSelWord I) = - if cometRewardsSelBytes 7 == I.calldata.extract 0 4 then ⟨1⟩ else ⟨0⟩ := by - simpa [cometRewardsSelWord, cometRewardsSelBytes] using - (evmSelectorDecode (cd := I.calldata) hsz 0x95 0xe3 0x6d 0x2c - (⟨0x95e36d2c⟩ : UInt256) (by native_decide)) - -theorem cometRewardsSelectorEq8 (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) : - UInt256.eq (⟨0xb7034f7e⟩ : UInt256) (cometRewardsSelWord I) = - if cometRewardsSelBytes 8 == I.calldata.extract 0 4 then ⟨1⟩ else ⟨0⟩ := by - simpa [cometRewardsSelWord, cometRewardsSelBytes] using - (evmSelectorDecode (cd := I.calldata) hsz 0xb7 0x03 0x4f 0x7e - (⟨0xb7034f7e⟩ : UInt256) (by native_decide)) - -theorem cometRewardsSelectorEq9 (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) : - UInt256.eq (⟨0xb8cc9ce6⟩ : UInt256) (cometRewardsSelWord I) = - if cometRewardsSelBytes 9 == I.calldata.extract 0 4 then ⟨1⟩ else ⟨0⟩ := by - simpa [cometRewardsSelWord, cometRewardsSelBytes] using - (evmSelectorDecode (cd := I.calldata) hsz 0xb8 0xcc 0x9c 0xe6 - (⟨0xb8cc9ce6⟩ : UInt256) (by native_decide)) - -theorem cometRewardsSelectorEq10 (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) : - UInt256.eq (⟨0xcdc0ca09⟩ : UInt256) (cometRewardsSelWord I) = - if cometRewardsSelBytes 10 == I.calldata.extract 0 4 then ⟨1⟩ else ⟨0⟩ := by - simpa [cometRewardsSelWord, cometRewardsSelBytes] using - (evmSelectorDecode (cd := I.calldata) hsz 0xcd 0xc0 0xca 0x09 - (⟨0xcdc0ca09⟩ : UInt256) (by native_decide)) - -abbrev withdrawTokenPc : UInt256 := ⟨2758⟩ -abbrev governorPc : UInt256 := ⟨2717⟩ -abbrev rewardConfigPc : UInt256 := ⟨2615⟩ -abbrev getRewardOwedPc : UInt256 := ⟨2266⟩ -abbrev claimToPc : UInt256 := ⟨2044⟩ -abbrev setRewardsClaimedPc : UInt256 := ⟨1723⟩ -abbrev rewardsClaimedPc : UInt256 := ⟨1644⟩ -abbrev setRewardConfigPc : UInt256 := ⟨1009⟩ -abbrev claimPc : UInt256 := ⟨942⟩ -abbrev transferGovernorPc : UInt256 := ⟨801⟩ -abbrev setRewardConfigWithMultiplierPc : UInt256 := ⟨159⟩ - -/-! ## Body-entry stack shapes -/ - -/-- Stack at `withdrawToken` after the first selector arm jumps. -/ -abbrev dispatchArm0Stack (I : ExecutionEnv) : List UInt256 := - [⟨128⟩, cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - -/-- Stack at arms 1 through 9 after the selected arm jumps. -/ -abbrev dispatchArmMidStack (I : ExecutionEnv) : List UInt256 := - [cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - -/-- Stack at `setRewardConfigWithMultiplier`, the final arm without a trailing selector word. -/ -abbrev dispatchArmLastStack (_I : ExecutionEnv) : List UInt256 := - [⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - -/-! ## Solm dispatch facts -/ - -theorem cometRewardsDispatch_none_short {cd : ByteArray} (h : cd.size < 4) : - dispatchMsg contract cd = none := by - rw [dispatchMsg_eq_dispatchList contract cd (by rfl)] - change dispatchList - [claimTransition, claimToTransition, getRewardOwedTransition, governorTransition, - rewardConfigTransition, rewardsClaimedTransition, setRewardConfigTransition, - setRewardConfigWithMultiplierTransition, setRewardsClaimedTransition, - transferGovernorTransition, withdrawTokenTransition] cd = none - exact dispatchList_none_short _ (by - intro t ht - simp at ht - rcases ht with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, claimSelectorBytes]; rfl - · rw [selectorOf, claimToSelectorBytes]; rfl - · rw [selectorOf, getRewardOwedSelectorBytes]; rfl - · rw [selectorOf, governorSelectorBytes]; rfl - · rw [selectorOf, rewardConfigSelectorBytes]; rfl - · rw [selectorOf, rewardsClaimedSelectorBytes]; rfl - · rw [selectorOf, setRewardConfigSelectorBytes]; rfl - · rw [selectorOf, setRewardConfigWithMultiplierSelectorBytes]; rfl - · rw [selectorOf, setRewardsClaimedSelectorBytes]; rfl - · rw [selectorOf, transferGovernorSelectorBytes]; rfl - · rw [selectorOf, withdrawTokenSelectorBytes]; rfl) h - -theorem cometRewardsDispatch_none_nomatch {cd : ByteArray} - (hnm : ∀ i, i < 11 → (cometRewardsSelBytes i == cd.extract 0 4) = false) : - dispatchMsg contract cd = none := by - apply dispatchMsg_none_of_all_ne (hfallback := by rfl) - intro t ht - simp [contract, transitions] at ht - rcases ht with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, claimSelectorBytes] - simpa [cometRewardsSelBytes] using hnm 8 (by omega) - · rw [selectorOf, claimToSelectorBytes] - simpa [cometRewardsSelBytes] using hnm 4 (by omega) - · rw [selectorOf, getRewardOwedSelectorBytes] - simpa [cometRewardsSelBytes] using hnm 3 (by omega) - · rw [selectorOf, governorSelectorBytes] - simpa [cometRewardsSelBytes] using hnm 1 (by omega) - · rw [selectorOf, rewardConfigSelectorBytes] - simpa [cometRewardsSelBytes] using hnm 2 (by omega) - · rw [selectorOf, rewardsClaimedSelectorBytes] - simpa [cometRewardsSelBytes] using hnm 6 (by omega) - · rw [selectorOf, setRewardConfigSelectorBytes] - simpa [cometRewardsSelBytes] using hnm 7 (by omega) - · rw [selectorOf, setRewardConfigWithMultiplierSelectorBytes] - simpa [cometRewardsSelBytes] using hnm 10 (by omega) - · rw [selectorOf, setRewardsClaimedSelectorBytes] - simpa [cometRewardsSelBytes] using hnm 5 (by omega) - · rw [selectorOf, transferGovernorSelectorBytes] - simpa [cometRewardsSelBytes] using hnm 9 (by omega) - · rw [selectorOf, withdrawTokenSelectorBytes] - simpa [cometRewardsSelBytes] using hnm 0 (by omega) - -theorem cometRewardsBodyReverts_nonPayable (t : TransitionDecl) (ht : t ∈ contract.transitions) - (evm : EVM.State) (locals : Store) (h : evm.executionEnv.weiValue ≠ ⟨0⟩) : - ExecTransitionBody config contract evm locals t.body .reverted := by - simp [contract, transitions] at ht - rcases ht with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> - exact bodyReverts_nonPayable h - -theorem cometRewardsStorageLocLoad_address_offset0 (evm : EVM.State) (slot : UInt256) : - storageLocLoad evm (fieldLoc slot 0 20 (by decide) .address) = - .address (AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) - solcAddrMask).toNat) := by - simpa [fieldLoc, loc, addressOffset0Loc] using storageLocLoad_address_offset0 evm slot - -theorem cometRewardsStorageLocLoad_uint256 (evm : EVM.State) (slot : UInt256) : - storageLocLoad evm (fieldLoc slot 0 32 (by decide) (.int uint256Int)) = - .int (Int.ofNat (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot).toNat) := by - simpa [fieldLoc, loc, uint256Loc] using storageLocLoad_uint256 evm slot - -theorem cometRewardsCalldataGuard_true (evm : EVM.State) (locals : Store) - (h : evm.executionEnv.calldata.size < 2 ^ 255 + 4) : - evalExpr? config - { contract := contract, locals := locals.insert "__calldata" (.bytes evm.executionEnv.calldata) } - evm (.binary .lt (.arrayLength .localVar calldataGuardRef) (.intLit calldataSizeLimit)) = - .ok (.bool true) := by - simp only [evalExpr?, EvalResult.bind, bind, pure, calldataGuardRef, calldataSizeLimit, - evalBinaryOp?, readLocalPath?] - norm_num - omega - -theorem cometRewardsCalldataGuard_false (evm : EVM.State) (locals : Store) - (h : 2 ^ 255 + 4 ≤ evm.executionEnv.calldata.size) : - evalExpr? config - { contract := contract, locals := locals.insert "__calldata" (.bytes evm.executionEnv.calldata) } - evm (.binary .lt (.arrayLength .localVar calldataGuardRef) (.intLit calldataSizeLimit)) = - .ok (.bool false) := by - simp only [evalExpr?, EvalResult.bind, bind, pure, calldataGuardRef, calldataSizeLimit, - evalBinaryOp?, readLocalPath?] - norm_num - omega - -theorem cometRewardsCalldataSizeAddNot3_eq_sub4 {n : ℕ} - (h4 : 4 ≤ n) (hn : n < UInt256.size) : - UInt256.add (UInt256.ofNat n) (UInt256.lnot (⟨3⟩ : UInt256)) = - UInt256.sub (UInt256.ofNat n) ⟨4⟩ := by - apply u256_inj - change (UInt256.ofNat n + UInt256.lnot (⟨3⟩ : UInt256)).toNat = - (UInt256.sub (UInt256.ofNat n) ⟨4⟩).toNat - rw [uadd_toNat] - have hnNat : (UInt256.ofNat n).toNat = n := ulit_toNat' n hn - have h4word : ((⟨4⟩ : UInt256).toNat = 4) := by decide - have hlnot : (UInt256.lnot (⟨3⟩ : UInt256)).toNat = UInt256.size - 4 := by - unfold UInt256.lnot - decide - have hsub : (UInt256.sub (UInt256.ofNat n) ⟨4⟩).toNat = n - 4 := by - rw [usub_ofNat_word_toNat (by rw [h4word]; exact h4) hn] - rw [h4word] - rw [hnNat, hlnot, hsub] - have hadd : n + (UInt256.size - 4) = UInt256.size + (n - 4) := by omega - rw [hadd, Nat.add_mod_left] - apply Nat.mod_eq_of_lt - omega - -/-! ## Shared prefix revert traces -/ - -theorem cometRewardsX_short {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) (hsz : I.calldata.size < 4) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - set s0 := initState cA gh bl σ σ₀ g A I with hs0 - have hee0 : s0.executionEnv = I := by rw [hs0]; simp [initState] - have hcode0 : s0.executionEnv.code = cometRewardsBytecode := by - rw [hee0]; exact hcode - have hpc0 : s0.machineState.pc = ⟨0⟩ := by rw [hs0]; simp [initState]; rfl - have hgas0 : s0.machineState.gasAvailable = g.subNat 0 := by - rw [hs0]; simp [initState, Sat256.subNat] - have hstk0 : s0.machineState.stack = [] := by rw [hs0]; simp [initState]; rfl - have haw0 : s0.machineState.activeWords = UInt256.ofNat 0 := by - rw [hs0]; simp [initState]; rfl - have hmem0 : s0.machineState.memory = ByteArray.empty := by - rw [hs0]; simp [initState]; rfl - have hrdata0 : s0.machineState.returnData = ByteArray.empty := by - rw [hs0]; simp [initState]; rfl - have hacc0 : (s0.createdAccounts, s0.accountMap) = (cA, σ) := by - rw [hs0]; simp [initState] - have hX0 : - X (g.toNat + 1) (D_J cometRewardsBytecode 0) s0 = - X (g.toNat + 1 - 0) (D_J cometRewardsBytecode 0) s0 := rfl - have rd0 : RD cometRewardsBytecode I g s0 ⟨0⟩ [] ByteArray.empty - (UInt256.ofNat 0) ByteArray.empty (cA, σ) 0 0 := by - exact RD.startWith (rdata := ByteArray.empty) hcode0 hpc0 hstk0 hgas0 (by omega) - (by omega) hX0 hmem0 haw0 hrdata0 hacc0 hee0 ⟨rfl, rfl, rfl⟩ - have rd := evm_run rd0 with [ - push1 ⟨128⟩, push1 ⟨64⟩, dup2, dup2, - raw mstore 9 solcFreePtrMem (UInt256.ofNat 3) (by native_decide) mem_cost - (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; rfl) - (by decide) (by evm_ov), - push1 ⟨4⟩, swap2, dup3, calldatasize, lt, iszero, push2 ⟨22⟩, - jumpiNT (isZero_eq_zero_of_ne (lt_four_ne_zero_of_lt hsz))] - exact (rd.solcPush1Dup1Revert0 (by decide) (by decide) (by decide) (by evm_ov) : - RDrev cometRewardsBytecode g s0) - -theorem cometRewardsX_nomatch {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) - (hnm : ∀ i, i < 11 → (cometRewardsSelBytes i == I.calldata.extract 0 4) = false) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have heq0 : - UInt256.eq (⟨0x01e33667⟩ : UInt256) - ((uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)).shiftRight - ⟨224⟩) = ⟨0⟩ := by - simp [cometRewardsSelectorEq0 I hsz, hnm 0 (by omega)] - have heq1 : - UInt256.eq (⟨0x0c340a24⟩ : UInt256) - ((uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)).shiftRight - ⟨224⟩) = ⟨0⟩ := by - simp [cometRewardsSelectorEq1 I hsz, hnm 1 (by omega)] - have heq2 : - UInt256.eq (⟨0x2289b6b8⟩ : UInt256) - ((uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)).shiftRight - ⟨224⟩) = ⟨0⟩ := by - simp [cometRewardsSelectorEq2 I hsz, hnm 2 (by omega)] - have heq3 : - UInt256.eq (⟨0x41e0cad6⟩ : UInt256) - ((uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)).shiftRight - ⟨224⟩) = ⟨0⟩ := by - simp [cometRewardsSelectorEq3 I hsz, hnm 3 (by omega)] - have heq4 : - UInt256.eq (⟨0x4ff85d94⟩ : UInt256) - ((uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)).shiftRight - ⟨224⟩) = ⟨0⟩ := by - simp [cometRewardsSelectorEq4 I hsz, hnm 4 (by omega)] - have heq5 : - UInt256.eq (⟨0x6394f161⟩ : UInt256) - ((uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)).shiftRight - ⟨224⟩) = ⟨0⟩ := by - simp [cometRewardsSelectorEq5 I hsz, hnm 5 (by omega)] - have heq6 : - UInt256.eq (⟨0x65e12392⟩ : UInt256) - ((uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)).shiftRight - ⟨224⟩) = ⟨0⟩ := by - simp [cometRewardsSelectorEq6 I hsz, hnm 6 (by omega)] - have heq7 : - UInt256.eq (⟨0x95e36d2c⟩ : UInt256) - ((uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)).shiftRight - ⟨224⟩) = ⟨0⟩ := by - simp [cometRewardsSelectorEq7 I hsz, hnm 7 (by omega)] - have heq8 : - UInt256.eq (⟨0xb7034f7e⟩ : UInt256) - ((uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)).shiftRight - ⟨224⟩) = ⟨0⟩ := by - simp [cometRewardsSelectorEq8 I hsz, hnm 8 (by omega)] - have heq9 : - UInt256.eq (⟨0xb8cc9ce6⟩ : UInt256) - ((uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)).shiftRight - ⟨224⟩) = ⟨0⟩ := by - simp [cometRewardsSelectorEq9 I hsz, hnm 9 (by omega)] - have heq10 : - UInt256.eq (⟨0xcdc0ca09⟩ : UInt256) - ((uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)).shiftRight - ⟨224⟩) = ⟨0⟩ := by - simp [cometRewardsSelectorEq10 I hsz, hnm 10 (by omega)] - set s0 := initState cA gh bl σ σ₀ g A I with hs0 - have hee0 : s0.executionEnv = I := by rw [hs0]; simp [initState] - have hcode0 : s0.executionEnv.code = cometRewardsBytecode := by - rw [hee0]; exact hcode - have hpc0 : s0.machineState.pc = ⟨0⟩ := by rw [hs0]; simp [initState]; rfl - have hgas0 : s0.machineState.gasAvailable = g.subNat 0 := by - rw [hs0]; simp [initState, Sat256.subNat] - have hstk0 : s0.machineState.stack = [] := by rw [hs0]; simp [initState]; rfl - have haw0 : s0.machineState.activeWords = UInt256.ofNat 0 := by - rw [hs0]; simp [initState]; rfl - have hmem0 : s0.machineState.memory = ByteArray.empty := by - rw [hs0]; simp [initState]; rfl - have hrdata0 : s0.machineState.returnData = ByteArray.empty := by - rw [hs0]; simp [initState]; rfl - have hacc0 : (s0.createdAccounts, s0.accountMap) = (cA, σ) := by - rw [hs0]; simp [initState] - have hX0 : - X (g.toNat + 1) (D_J cometRewardsBytecode 0) s0 = - X (g.toNat + 1 - 0) (D_J cometRewardsBytecode 0) s0 := rfl - have rd0 : RD cometRewardsBytecode I g s0 ⟨0⟩ [] ByteArray.empty - (UInt256.ofNat 0) ByteArray.empty (cA, σ) 0 0 := by - exact RD.startWith (rdata := ByteArray.empty) hcode0 hpc0 hstk0 hgas0 (by omega) - (by omega) hX0 hmem0 haw0 hrdata0 hacc0 hee0 ⟨rfl, rfl, rfl⟩ - have rd := evm_run rd0 with [ - push1 ⟨128⟩, push1 ⟨64⟩, dup2, dup2, - raw mstore 9 solcFreePtrMem (UInt256.ofNat 3) (by native_decide) mem_cost - (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; rfl) - (by decide) (by evm_ov), - push1 ⟨4⟩, swap2, dup3, calldatasize, lt] - rw [show (⟨4⟩ : UInt256) = UInt256.ofNat 4 from rfl, - lt_four_eq_zero_of_ge hsz hsize] at rd - have rd := evm_run rd with [iszero] - rw [show UInt256.isZero (⟨0⟩ : UInt256) = ⟨1⟩ from by decide] at rd - have rd := evm_run rd with [ - push2 ⟨22⟩, jumpiT one_ne_zero_uint (by native_decide), jumpdest, - push1 ⟨0⟩, swap3, push1 ⟨224⟩, swap2, dup5, calldataload, dup4, shr, swap1, - dup2, push4 ⟨0x01e33667⟩, eq] - rw [heq0] at rd - have rd := evm_run rd with [push2 ⟨2758⟩, jumpiNT (by decide), pop, - dup1, push4 ⟨0x0c340a24⟩, eq] - rw [heq1] at rd - have rd := evm_run rd with [push2 ⟨2717⟩, jumpiNT (by decide), - dup1, push4 ⟨0x2289b6b8⟩, eq] - rw [heq2] at rd - have rd := evm_run rd with [push2 ⟨2615⟩, jumpiNT (by decide), - dup1, push4 ⟨0x41e0cad6⟩, eq] - rw [heq3] at rd - have rd := evm_run rd with [push2 ⟨2266⟩, jumpiNT (by decide), - dup1, push4 ⟨0x4ff85d94⟩, eq] - rw [heq4] at rd - have rd := evm_run rd with [push2 ⟨2044⟩, jumpiNT (by decide), - dup1, push4 ⟨0x6394f161⟩, eq] - rw [heq5] at rd - have rd := evm_run rd with [push2 ⟨1723⟩, jumpiNT (by decide), - dup1, push4 ⟨0x65e12392⟩, eq] - rw [heq6] at rd - have rd := evm_run rd with [push2 ⟨1644⟩, jumpiNT (by decide), - dup1, push4 ⟨0x95e36d2c⟩, eq] - rw [heq7] at rd - have rd := evm_run rd with [push2 ⟨1009⟩, jumpiNT (by decide), - dup1, push4 ⟨0xb7034f7e⟩, eq] - rw [heq8] at rd - have rd := evm_run rd with [push2 ⟨942⟩, jumpiNT (by decide), - dup1, push4 ⟨0xb8cc9ce6⟩, eq] - rw [heq9] at rd - have rd := evm_run rd with [push2 ⟨801⟩, jumpiNT (by decide), - push4 ⟨0xcdc0ca09⟩, eq] - rw [heq10] at rd - have rd := evm_run rd with [push2 ⟨159⟩, jumpiNT (by decide)] - exact (rd.solcPush1Dup1Revert0 (by decide) (by decide) (by decide) (by evm_ov) : - RDrev cometRewardsBytecode g s0) - -theorem cometRewardsReachFirstArm {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨34⟩ - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C := by - set s0 := initState cA gh bl σ σ₀ g A I with hs0 - have hee0 : s0.executionEnv = I := by rw [hs0]; simp [initState] - have hcode0 : s0.executionEnv.code = cometRewardsBytecode := by - rw [hee0]; exact hcode - have hpc0 : s0.machineState.pc = ⟨0⟩ := by rw [hs0]; simp [initState]; rfl - have hgas0 : s0.machineState.gasAvailable = g.subNat 0 := by - rw [hs0]; simp [initState, Sat256.subNat] - have hstk0 : s0.machineState.stack = [] := by rw [hs0]; simp [initState]; rfl - have haw0 : s0.machineState.activeWords = UInt256.ofNat 0 := by - rw [hs0]; simp [initState]; rfl - have hmem0 : s0.machineState.memory = ByteArray.empty := by - rw [hs0]; simp [initState]; rfl - have hrdata0 : s0.machineState.returnData = ByteArray.empty := by - rw [hs0]; simp [initState]; rfl - have hacc0 : (s0.createdAccounts, s0.accountMap) = (cA, σ) := by - rw [hs0]; simp [initState] - have hX0 : - X (g.toNat + 1) (D_J cometRewardsBytecode 0) s0 = - X (g.toNat + 1 - 0) (D_J cometRewardsBytecode 0) s0 := rfl - have rd0 : RD cometRewardsBytecode I g s0 ⟨0⟩ [] ByteArray.empty - (UInt256.ofNat 0) ByteArray.empty (cA, σ) 0 0 := by - exact RD.startWith (rdata := ByteArray.empty) hcode0 hpc0 hstk0 hgas0 (by omega) - (by omega) hX0 hmem0 haw0 hrdata0 hacc0 hee0 ⟨rfl, rfl, rfl⟩ - have rd := evm_run rd0 with [ - push1 ⟨128⟩, push1 ⟨64⟩, dup2, dup2, - raw mstore 9 solcFreePtrMem (UInt256.ofNat 3) (by native_decide) mem_cost - (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; rfl) - (by decide) (by evm_ov), - push1 ⟨4⟩, swap2, dup3, calldatasize, lt] - rw [show (⟨4⟩ : UInt256) = UInt256.ofNat 4 from rfl, - lt_four_eq_zero_of_ge hsz hsize] at rd - have rd := evm_run rd with [iszero] - rw [show UInt256.isZero (⟨0⟩ : UInt256) = ⟨1⟩ from by decide] at rd - have rd := evm_run rd with [ - push2 ⟨22⟩, jumpiT one_ne_zero_uint (by native_decide), jumpdest, - push1 ⟨0⟩, swap3, push1 ⟨224⟩, swap2, dup5, calldataload, dup4, shr, swap1] - exact ⟨_, _, by simpa [hs0, dispatchArm0Stack, cometRewardsSelWord] using rd⟩ - -/-! ## Via-IR dispatcher reach obligations -/ - -theorem cometRewardsReachWithdrawToken {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (cometRewardsSelBytes 0)) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C := by - obtain ⟨_, _, rd⟩ := cometRewardsReachFirstArm (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode hsz hsize - have heq0 : UInt256.eq (⟨0x01e33667⟩ : UInt256) (cometRewardsSelWord I) = ⟨1⟩ := by - simp [cometRewardsSelectorEq0 I hsz, hsel] - have rd := evm_run rd with [dup2, push4 ⟨0x01e33667⟩, eq] - rw [heq0] at rd - exact ⟨_, _, evm_run rd with [push2 ⟨2758⟩, jumpiT one_ne_zero_uint (by native_decide)]⟩ - -theorem cometRewardsReachGovernor {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (cometRewardsSelBytes 1)) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) governorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C := by - obtain ⟨_, _, rd⟩ := cometRewardsReachFirstArm (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode hsz hsize - have h0false : (cometRewardsSelBytes 0 == I.calldata.extract 0 4) = false := - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 1) - (other := cometRewardsSelBytes 0) (by native_decide) hsel - have heq0 : UInt256.eq (⟨0x01e33667⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq0 I hsz, h0false] - have heq1 : UInt256.eq (⟨0x0c340a24⟩ : UInt256) (cometRewardsSelWord I) = ⟨1⟩ := by - simp [cometRewardsSelectorEq1 I hsz, hsel] - have rd := evm_run rd with [dup2, push4 ⟨0x01e33667⟩, eq] - rw [heq0] at rd - have rd := evm_run rd with [push2 ⟨2758⟩, jumpiNT (by decide), pop, - dup1, push4 ⟨0x0c340a24⟩, eq] - rw [heq1] at rd - exact ⟨_, _, evm_run rd with [push2 ⟨2717⟩, jumpiT one_ne_zero_uint (by native_decide)]⟩ - -theorem cometRewardsReachRewardConfig {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (cometRewardsSelBytes 2)) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) rewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C := by - obtain ⟨_, _, rd⟩ := cometRewardsReachFirstArm (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode hsz hsize - have h0false : (cometRewardsSelBytes 0 == I.calldata.extract 0 4) = false := - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 2) - (other := cometRewardsSelBytes 0) (by native_decide) hsel - have h1false : (cometRewardsSelBytes 1 == I.calldata.extract 0 4) = false := - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 2) - (other := cometRewardsSelBytes 1) (by native_decide) hsel - have heq0 : UInt256.eq (⟨0x01e33667⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq0 I hsz, h0false] - have heq1 : UInt256.eq (⟨0x0c340a24⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq1 I hsz, h1false] - have heq2 : UInt256.eq (⟨0x2289b6b8⟩ : UInt256) (cometRewardsSelWord I) = ⟨1⟩ := by - simp [cometRewardsSelectorEq2 I hsz, hsel] - have rd := evm_run rd with [dup2, push4 ⟨0x01e33667⟩, eq] - rw [heq0] at rd - have rd := evm_run rd with [push2 ⟨2758⟩, jumpiNT (by decide), pop, - dup1, push4 ⟨0x0c340a24⟩, eq] - rw [heq1] at rd - have rd := evm_run rd with [push2 ⟨2717⟩, jumpiNT (by decide), - dup1, push4 ⟨0x2289b6b8⟩, eq] - rw [heq2] at rd - exact ⟨_, _, evm_run rd with [push2 ⟨2615⟩, jumpiT one_ne_zero_uint (by native_decide)]⟩ - -theorem cometRewardsReachGetRewardOwed {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (cometRewardsSelBytes 3)) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C := by - obtain ⟨_, _, rd⟩ := cometRewardsReachFirstArm (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode hsz hsize - have h0false : (cometRewardsSelBytes 0 == I.calldata.extract 0 4) = false := - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 3) - (other := cometRewardsSelBytes 0) (by native_decide) hsel - have h1false : (cometRewardsSelBytes 1 == I.calldata.extract 0 4) = false := - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 3) - (other := cometRewardsSelBytes 1) (by native_decide) hsel - have h2false : (cometRewardsSelBytes 2 == I.calldata.extract 0 4) = false := - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 3) - (other := cometRewardsSelBytes 2) (by native_decide) hsel - have heq0 : UInt256.eq (⟨0x01e33667⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq0 I hsz, h0false] - have heq1 : UInt256.eq (⟨0x0c340a24⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq1 I hsz, h1false] - have heq2 : UInt256.eq (⟨0x2289b6b8⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq2 I hsz, h2false] - have heq3 : UInt256.eq (⟨0x41e0cad6⟩ : UInt256) (cometRewardsSelWord I) = ⟨1⟩ := by - simp [cometRewardsSelectorEq3 I hsz, hsel] - have rd := evm_run rd with [dup2, push4 ⟨0x01e33667⟩, eq] - rw [heq0] at rd - have rd := evm_run rd with [push2 ⟨2758⟩, jumpiNT (by decide), pop, - dup1, push4 ⟨0x0c340a24⟩, eq] - rw [heq1] at rd - have rd := evm_run rd with [push2 ⟨2717⟩, jumpiNT (by decide), - dup1, push4 ⟨0x2289b6b8⟩, eq] - rw [heq2] at rd - have rd := evm_run rd with [push2 ⟨2615⟩, jumpiNT (by decide), - dup1, push4 ⟨0x41e0cad6⟩, eq] - rw [heq3] at rd - exact ⟨_, _, evm_run rd with [push2 ⟨2266⟩, jumpiT one_ne_zero_uint (by native_decide)]⟩ - -theorem cometRewardsReachClaimTo {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (cometRewardsSelBytes 4)) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) claimToPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C := by - obtain ⟨_, _, rd⟩ := cometRewardsReachFirstArm (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode hsz hsize - have h0false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 4) - (other := cometRewardsSelBytes 0) (by native_decide) hsel - have h1false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 4) - (other := cometRewardsSelBytes 1) (by native_decide) hsel - have h2false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 4) - (other := cometRewardsSelBytes 2) (by native_decide) hsel - have h3false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 4) - (other := cometRewardsSelBytes 3) (by native_decide) hsel - have heq0 : UInt256.eq (⟨0x01e33667⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq0 I hsz, h0false] - have heq1 : UInt256.eq (⟨0x0c340a24⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq1 I hsz, h1false] - have heq2 : UInt256.eq (⟨0x2289b6b8⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq2 I hsz, h2false] - have heq3 : UInt256.eq (⟨0x41e0cad6⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq3 I hsz, h3false] - have heq4 : UInt256.eq (⟨0x4ff85d94⟩ : UInt256) (cometRewardsSelWord I) = ⟨1⟩ := by - simp [cometRewardsSelectorEq4 I hsz, hsel] - have rd := evm_run rd with [dup2, push4 ⟨0x01e33667⟩, eq] - rw [heq0] at rd - have rd := evm_run rd with [push2 ⟨2758⟩, jumpiNT (by decide), pop, - dup1, push4 ⟨0x0c340a24⟩, eq] - rw [heq1] at rd - have rd := evm_run rd with [push2 ⟨2717⟩, jumpiNT (by decide), - dup1, push4 ⟨0x2289b6b8⟩, eq] - rw [heq2] at rd - have rd := evm_run rd with [push2 ⟨2615⟩, jumpiNT (by decide), - dup1, push4 ⟨0x41e0cad6⟩, eq] - rw [heq3] at rd - have rd := evm_run rd with [push2 ⟨2266⟩, jumpiNT (by decide), - dup1, push4 ⟨0x4ff85d94⟩, eq] - rw [heq4] at rd - exact ⟨_, _, evm_run rd with [push2 ⟨2044⟩, jumpiT one_ne_zero_uint (by native_decide)]⟩ - -theorem cometRewardsReachSetRewardsClaimed {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (cometRewardsSelBytes 5)) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - setRewardsClaimedPc (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) - ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd⟩ := cometRewardsReachFirstArm (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode hsz hsize - have h0false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 5) - (other := cometRewardsSelBytes 0) (by native_decide) hsel - have h1false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 5) - (other := cometRewardsSelBytes 1) (by native_decide) hsel - have h2false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 5) - (other := cometRewardsSelBytes 2) (by native_decide) hsel - have h3false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 5) - (other := cometRewardsSelBytes 3) (by native_decide) hsel - have h4false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 5) - (other := cometRewardsSelBytes 4) (by native_decide) hsel - have heq0 : UInt256.eq (⟨0x01e33667⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq0 I hsz, h0false] - have heq1 : UInt256.eq (⟨0x0c340a24⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq1 I hsz, h1false] - have heq2 : UInt256.eq (⟨0x2289b6b8⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq2 I hsz, h2false] - have heq3 : UInt256.eq (⟨0x41e0cad6⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq3 I hsz, h3false] - have heq4 : UInt256.eq (⟨0x4ff85d94⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq4 I hsz, h4false] - have heq5 : UInt256.eq (⟨0x6394f161⟩ : UInt256) (cometRewardsSelWord I) = ⟨1⟩ := by - simp [cometRewardsSelectorEq5 I hsz, hsel] - have rd := evm_run rd with [dup2, push4 ⟨0x01e33667⟩, eq] - rw [heq0] at rd - have rd := evm_run rd with [push2 ⟨2758⟩, jumpiNT (by decide), pop, - dup1, push4 ⟨0x0c340a24⟩, eq] - rw [heq1] at rd - have rd := evm_run rd with [push2 ⟨2717⟩, jumpiNT (by decide), - dup1, push4 ⟨0x2289b6b8⟩, eq] - rw [heq2] at rd - have rd := evm_run rd with [push2 ⟨2615⟩, jumpiNT (by decide), - dup1, push4 ⟨0x41e0cad6⟩, eq] - rw [heq3] at rd - have rd := evm_run rd with [push2 ⟨2266⟩, jumpiNT (by decide), - dup1, push4 ⟨0x4ff85d94⟩, eq] - rw [heq4] at rd - have rd := evm_run rd with [push2 ⟨2044⟩, jumpiNT (by decide), - dup1, push4 ⟨0x6394f161⟩, eq] - rw [heq5] at rd - exact ⟨_, _, evm_run rd with [push2 ⟨1723⟩, jumpiT one_ne_zero_uint (by native_decide)]⟩ - -theorem cometRewardsReachRewardsClaimed {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (cometRewardsSelBytes 6)) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) rewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C := by - obtain ⟨_, _, rd⟩ := cometRewardsReachFirstArm (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode hsz hsize - have h0false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 6) - (other := cometRewardsSelBytes 0) (by native_decide) hsel - have h1false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 6) - (other := cometRewardsSelBytes 1) (by native_decide) hsel - have h2false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 6) - (other := cometRewardsSelBytes 2) (by native_decide) hsel - have h3false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 6) - (other := cometRewardsSelBytes 3) (by native_decide) hsel - have h4false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 6) - (other := cometRewardsSelBytes 4) (by native_decide) hsel - have h5false := selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 6) - (other := cometRewardsSelBytes 5) (by native_decide) hsel - have heq0 : UInt256.eq (⟨0x01e33667⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq0 I hsz, h0false] - have heq1 : UInt256.eq (⟨0x0c340a24⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq1 I hsz, h1false] - have heq2 : UInt256.eq (⟨0x2289b6b8⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq2 I hsz, h2false] - have heq3 : UInt256.eq (⟨0x41e0cad6⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq3 I hsz, h3false] - have heq4 : UInt256.eq (⟨0x4ff85d94⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq4 I hsz, h4false] - have heq5 : UInt256.eq (⟨0x6394f161⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq5 I hsz, h5false] - have heq6 : UInt256.eq (⟨0x65e12392⟩ : UInt256) (cometRewardsSelWord I) = ⟨1⟩ := by - simp [cometRewardsSelectorEq6 I hsz, hsel] - have rd := evm_run rd with [dup2, push4 ⟨0x01e33667⟩, eq] - rw [heq0] at rd - have rd := evm_run rd with [push2 ⟨2758⟩, jumpiNT (by decide), pop, - dup1, push4 ⟨0x0c340a24⟩, eq] - rw [heq1] at rd - have rd := evm_run rd with [push2 ⟨2717⟩, jumpiNT (by decide), - dup1, push4 ⟨0x2289b6b8⟩, eq] - rw [heq2] at rd - have rd := evm_run rd with [push2 ⟨2615⟩, jumpiNT (by decide), - dup1, push4 ⟨0x41e0cad6⟩, eq] - rw [heq3] at rd - have rd := evm_run rd with [push2 ⟨2266⟩, jumpiNT (by decide), - dup1, push4 ⟨0x4ff85d94⟩, eq] - rw [heq4] at rd - have rd := evm_run rd with [push2 ⟨2044⟩, jumpiNT (by decide), - dup1, push4 ⟨0x6394f161⟩, eq] - rw [heq5] at rd - have rd := evm_run rd with [push2 ⟨1723⟩, jumpiNT (by decide), - dup1, push4 ⟨0x65e12392⟩, eq] - rw [heq6] at rd - exact ⟨_, _, evm_run rd with [push2 ⟨1644⟩, jumpiT one_ne_zero_uint (by native_decide)]⟩ - -theorem cometRewardsReachSetRewardConfig {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (cometRewardsSelBytes 7)) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C := by - obtain ⟨_, _, rd⟩ := cometRewardsReachFirstArm (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode hsz hsize - have heq0 : UInt256.eq (⟨0x01e33667⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq0 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 7) - (other := cometRewardsSelBytes 0) (by native_decide) hsel] - have heq1 : UInt256.eq (⟨0x0c340a24⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq1 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 7) - (other := cometRewardsSelBytes 1) (by native_decide) hsel] - have heq2 : UInt256.eq (⟨0x2289b6b8⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq2 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 7) - (other := cometRewardsSelBytes 2) (by native_decide) hsel] - have heq3 : UInt256.eq (⟨0x41e0cad6⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq3 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 7) - (other := cometRewardsSelBytes 3) (by native_decide) hsel] - have heq4 : UInt256.eq (⟨0x4ff85d94⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq4 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 7) - (other := cometRewardsSelBytes 4) (by native_decide) hsel] - have heq5 : UInt256.eq (⟨0x6394f161⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq5 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 7) - (other := cometRewardsSelBytes 5) (by native_decide) hsel] - have heq6 : UInt256.eq (⟨0x65e12392⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq6 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 7) - (other := cometRewardsSelBytes 6) (by native_decide) hsel] - have heq7 : UInt256.eq (⟨0x95e36d2c⟩ : UInt256) (cometRewardsSelWord I) = ⟨1⟩ := by - simp [cometRewardsSelectorEq7 I hsz, hsel] - have rd := evm_run rd with [dup2, push4 ⟨0x01e33667⟩, eq] - rw [heq0] at rd - have rd := evm_run rd with [push2 ⟨2758⟩, jumpiNT (by decide), pop, - dup1, push4 ⟨0x0c340a24⟩, eq] - rw [heq1] at rd - have rd := evm_run rd with [push2 ⟨2717⟩, jumpiNT (by decide), - dup1, push4 ⟨0x2289b6b8⟩, eq] - rw [heq2] at rd - have rd := evm_run rd with [push2 ⟨2615⟩, jumpiNT (by decide), - dup1, push4 ⟨0x41e0cad6⟩, eq] - rw [heq3] at rd - have rd := evm_run rd with [push2 ⟨2266⟩, jumpiNT (by decide), - dup1, push4 ⟨0x4ff85d94⟩, eq] - rw [heq4] at rd - have rd := evm_run rd with [push2 ⟨2044⟩, jumpiNT (by decide), - dup1, push4 ⟨0x6394f161⟩, eq] - rw [heq5] at rd - have rd := evm_run rd with [push2 ⟨1723⟩, jumpiNT (by decide), - dup1, push4 ⟨0x65e12392⟩, eq] - rw [heq6] at rd - have rd := evm_run rd with [push2 ⟨1644⟩, jumpiNT (by decide), - dup1, push4 ⟨0x95e36d2c⟩, eq] - rw [heq7] at rd - exact ⟨_, _, evm_run rd with [push2 ⟨1009⟩, jumpiT one_ne_zero_uint (by native_decide)]⟩ - -theorem cometRewardsReachClaim {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (cometRewardsSelBytes 8)) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) claimPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C := by - obtain ⟨_, _, rd⟩ := cometRewardsReachFirstArm (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode hsz hsize - have heq0 : UInt256.eq (⟨0x01e33667⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq0 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 8) - (other := cometRewardsSelBytes 0) (by native_decide) hsel] - have heq1 : UInt256.eq (⟨0x0c340a24⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq1 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 8) - (other := cometRewardsSelBytes 1) (by native_decide) hsel] - have heq2 : UInt256.eq (⟨0x2289b6b8⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq2 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 8) - (other := cometRewardsSelBytes 2) (by native_decide) hsel] - have heq3 : UInt256.eq (⟨0x41e0cad6⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq3 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 8) - (other := cometRewardsSelBytes 3) (by native_decide) hsel] - have heq4 : UInt256.eq (⟨0x4ff85d94⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq4 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 8) - (other := cometRewardsSelBytes 4) (by native_decide) hsel] - have heq5 : UInt256.eq (⟨0x6394f161⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq5 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 8) - (other := cometRewardsSelBytes 5) (by native_decide) hsel] - have heq6 : UInt256.eq (⟨0x65e12392⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq6 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 8) - (other := cometRewardsSelBytes 6) (by native_decide) hsel] - have heq7 : UInt256.eq (⟨0x95e36d2c⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq7 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 8) - (other := cometRewardsSelBytes 7) (by native_decide) hsel] - have heq8 : UInt256.eq (⟨0xb7034f7e⟩ : UInt256) (cometRewardsSelWord I) = ⟨1⟩ := by - simp [cometRewardsSelectorEq8 I hsz, hsel] - have rd := evm_run rd with [dup2, push4 ⟨0x01e33667⟩, eq] - rw [heq0] at rd - have rd := evm_run rd with [push2 ⟨2758⟩, jumpiNT (by decide), pop, - dup1, push4 ⟨0x0c340a24⟩, eq] - rw [heq1] at rd - have rd := evm_run rd with [push2 ⟨2717⟩, jumpiNT (by decide), - dup1, push4 ⟨0x2289b6b8⟩, eq] - rw [heq2] at rd - have rd := evm_run rd with [push2 ⟨2615⟩, jumpiNT (by decide), - dup1, push4 ⟨0x41e0cad6⟩, eq] - rw [heq3] at rd - have rd := evm_run rd with [push2 ⟨2266⟩, jumpiNT (by decide), - dup1, push4 ⟨0x4ff85d94⟩, eq] - rw [heq4] at rd - have rd := evm_run rd with [push2 ⟨2044⟩, jumpiNT (by decide), - dup1, push4 ⟨0x6394f161⟩, eq] - rw [heq5] at rd - have rd := evm_run rd with [push2 ⟨1723⟩, jumpiNT (by decide), - dup1, push4 ⟨0x65e12392⟩, eq] - rw [heq6] at rd - have rd := evm_run rd with [push2 ⟨1644⟩, jumpiNT (by decide), - dup1, push4 ⟨0x95e36d2c⟩, eq] - rw [heq7] at rd - have rd := evm_run rd with [push2 ⟨1009⟩, jumpiNT (by decide), - dup1, push4 ⟨0xb7034f7e⟩, eq] - rw [heq8] at rd - exact ⟨_, _, evm_run rd with [push2 ⟨942⟩, jumpiT one_ne_zero_uint (by native_decide)]⟩ - -theorem cometRewardsReachTransferGovernor {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (cometRewardsSelBytes 9)) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - transferGovernorPc (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) - ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd⟩ := cometRewardsReachFirstArm (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode hsz hsize - have heq0 : UInt256.eq (⟨0x01e33667⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq0 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 9) - (other := cometRewardsSelBytes 0) (by native_decide) hsel] - have heq1 : UInt256.eq (⟨0x0c340a24⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq1 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 9) - (other := cometRewardsSelBytes 1) (by native_decide) hsel] - have heq2 : UInt256.eq (⟨0x2289b6b8⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq2 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 9) - (other := cometRewardsSelBytes 2) (by native_decide) hsel] - have heq3 : UInt256.eq (⟨0x41e0cad6⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq3 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 9) - (other := cometRewardsSelBytes 3) (by native_decide) hsel] - have heq4 : UInt256.eq (⟨0x4ff85d94⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq4 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 9) - (other := cometRewardsSelBytes 4) (by native_decide) hsel] - have heq5 : UInt256.eq (⟨0x6394f161⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq5 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 9) - (other := cometRewardsSelBytes 5) (by native_decide) hsel] - have heq6 : UInt256.eq (⟨0x65e12392⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq6 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 9) - (other := cometRewardsSelBytes 6) (by native_decide) hsel] - have heq7 : UInt256.eq (⟨0x95e36d2c⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq7 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 9) - (other := cometRewardsSelBytes 7) (by native_decide) hsel] - have heq8 : UInt256.eq (⟨0xb7034f7e⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq8 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 9) - (other := cometRewardsSelBytes 8) (by native_decide) hsel] - have heq9 : UInt256.eq (⟨0xb8cc9ce6⟩ : UInt256) (cometRewardsSelWord I) = ⟨1⟩ := by - simp [cometRewardsSelectorEq9 I hsz, hsel] - have rd := evm_run rd with [dup2, push4 ⟨0x01e33667⟩, eq] - rw [heq0] at rd - have rd := evm_run rd with [push2 ⟨2758⟩, jumpiNT (by decide), pop, - dup1, push4 ⟨0x0c340a24⟩, eq] - rw [heq1] at rd - have rd := evm_run rd with [push2 ⟨2717⟩, jumpiNT (by decide), - dup1, push4 ⟨0x2289b6b8⟩, eq] - rw [heq2] at rd - have rd := evm_run rd with [push2 ⟨2615⟩, jumpiNT (by decide), - dup1, push4 ⟨0x41e0cad6⟩, eq] - rw [heq3] at rd - have rd := evm_run rd with [push2 ⟨2266⟩, jumpiNT (by decide), - dup1, push4 ⟨0x4ff85d94⟩, eq] - rw [heq4] at rd - have rd := evm_run rd with [push2 ⟨2044⟩, jumpiNT (by decide), - dup1, push4 ⟨0x6394f161⟩, eq] - rw [heq5] at rd - have rd := evm_run rd with [push2 ⟨1723⟩, jumpiNT (by decide), - dup1, push4 ⟨0x65e12392⟩, eq] - rw [heq6] at rd - have rd := evm_run rd with [push2 ⟨1644⟩, jumpiNT (by decide), - dup1, push4 ⟨0x95e36d2c⟩, eq] - rw [heq7] at rd - have rd := evm_run rd with [push2 ⟨1009⟩, jumpiNT (by decide), - dup1, push4 ⟨0xb7034f7e⟩, eq] - rw [heq8] at rd - have rd := evm_run rd with [push2 ⟨942⟩, jumpiNT (by decide), - dup1, push4 ⟨0xb8cc9ce6⟩, eq] - rw [heq9] at rd - exact ⟨_, _, evm_run rd with [push2 ⟨801⟩, jumpiT one_ne_zero_uint (by native_decide)]⟩ - -theorem cometRewardsReachSetRewardConfigWithMultiplier {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = cometRewardsBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (cometRewardsSelBytes 10)) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - setRewardConfigWithMultiplierPc (dispatchArmLastStack I) solcFreePtrMem - (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd⟩ := cometRewardsReachFirstArm (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode hsz hsize - have heq0 : UInt256.eq (⟨0x01e33667⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq0 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 10) - (other := cometRewardsSelBytes 0) (by native_decide) hsel] - have heq1 : UInt256.eq (⟨0x0c340a24⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq1 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 10) - (other := cometRewardsSelBytes 1) (by native_decide) hsel] - have heq2 : UInt256.eq (⟨0x2289b6b8⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq2 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 10) - (other := cometRewardsSelBytes 2) (by native_decide) hsel] - have heq3 : UInt256.eq (⟨0x41e0cad6⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq3 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 10) - (other := cometRewardsSelBytes 3) (by native_decide) hsel] - have heq4 : UInt256.eq (⟨0x4ff85d94⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq4 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 10) - (other := cometRewardsSelBytes 4) (by native_decide) hsel] - have heq5 : UInt256.eq (⟨0x6394f161⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq5 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 10) - (other := cometRewardsSelBytes 5) (by native_decide) hsel] - have heq6 : UInt256.eq (⟨0x65e12392⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq6 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 10) - (other := cometRewardsSelBytes 6) (by native_decide) hsel] - have heq7 : UInt256.eq (⟨0x95e36d2c⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq7 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 10) - (other := cometRewardsSelBytes 7) (by native_decide) hsel] - have heq8 : UInt256.eq (⟨0xb7034f7e⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq8 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 10) - (other := cometRewardsSelBytes 8) (by native_decide) hsel] - have heq9 : UInt256.eq (⟨0xb8cc9ce6⟩ : UInt256) (cometRewardsSelWord I) = ⟨0⟩ := by - simp [cometRewardsSelectorEq9 I hsz, - selectorFalseOfMatch (I := I) (want := cometRewardsSelBytes 10) - (other := cometRewardsSelBytes 9) (by native_decide) hsel] - have heq10 : UInt256.eq (⟨0xcdc0ca09⟩ : UInt256) (cometRewardsSelWord I) = ⟨1⟩ := by - simp [cometRewardsSelectorEq10 I hsz, hsel] - have rd := evm_run rd with [dup2, push4 ⟨0x01e33667⟩, eq] - rw [heq0] at rd - have rd := evm_run rd with [push2 ⟨2758⟩, jumpiNT (by decide), pop, - dup1, push4 ⟨0x0c340a24⟩, eq] - rw [heq1] at rd - have rd := evm_run rd with [push2 ⟨2717⟩, jumpiNT (by decide), - dup1, push4 ⟨0x2289b6b8⟩, eq] - rw [heq2] at rd - have rd := evm_run rd with [push2 ⟨2615⟩, jumpiNT (by decide), - dup1, push4 ⟨0x41e0cad6⟩, eq] - rw [heq3] at rd - have rd := evm_run rd with [push2 ⟨2266⟩, jumpiNT (by decide), - dup1, push4 ⟨0x4ff85d94⟩, eq] - rw [heq4] at rd - have rd := evm_run rd with [push2 ⟨2044⟩, jumpiNT (by decide), - dup1, push4 ⟨0x6394f161⟩, eq] - rw [heq5] at rd - have rd := evm_run rd with [push2 ⟨1723⟩, jumpiNT (by decide), - dup1, push4 ⟨0x65e12392⟩, eq] - rw [heq6] at rd - have rd := evm_run rd with [push2 ⟨1644⟩, jumpiNT (by decide), - dup1, push4 ⟨0x95e36d2c⟩, eq] - rw [heq7] at rd - have rd := evm_run rd with [push2 ⟨1009⟩, jumpiNT (by decide), - dup1, push4 ⟨0xb7034f7e⟩, eq] - rw [heq8] at rd - have rd := evm_run rd with [push2 ⟨942⟩, jumpiNT (by decide), - dup1, push4 ⟨0xb8cc9ce6⟩, eq] - rw [heq9] at rd - have rd := evm_run rd with [push2 ⟨801⟩, jumpiNT (by decide), - push4 ⟨0xcdc0ca09⟩, eq] - rw [heq10] at rd - exact ⟨_, _, evm_run rd with [push2 ⟨159⟩, jumpiT one_ne_zero_uint (by native_decide)]⟩ - -/-! ## Body-entry nonpayable reverts -/ - -theorem cometRewardsX_withdrawToken_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd⟩ := hreach - exact evm_run rd with [ - jumpdest, dup6, dup6, dup5, swap3, callvalue, - push2 ⟨938⟩, jumpiT hwv (by native_decide), - jumpdest, dup3, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsX_governor_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) governorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd⟩ := hreach - exact evm_run rd with [ - jumpdest, pop, pop, pop, callvalue, - push2 ⟨670⟩, jumpiT hwv (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsX_rewardConfig_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd⟩ := hreach - exact evm_run rd with [ - jumpdest, dup4, dup6, dup5, callvalue, - push2 ⟨670⟩, jumpiT hwv (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsX_getRewardOwed_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd⟩ := hreach - exact evm_run rd with [ - jumpdest, pop, swap3, swap1, swap3, callvalue, - push2 ⟨670⟩, jumpiT hwv (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsX_claimTo_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) claimToPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd⟩ := hreach - exact evm_run rd with [ - jumpdest, pop, dup4, dup4, callvalue, - push2 ⟨670⟩, jumpiT hwv (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsX_setRewardsClaimed_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd⟩ := hreach - exact evm_run rd with [ - jumpdest, pop, dup4, dup4, callvalue, - push2 ⟨670⟩, jumpiT hwv (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsX_rewardsClaimed_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd⟩ := hreach - exact evm_run rd with [ - jumpdest, pop, pop, pop, callvalue, - push2 ⟨670⟩, jumpiT hwv (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsX_setRewardConfig_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd⟩ := hreach - exact evm_run rd with [ - jumpdest, pop, swap1, callvalue, - push2 ⟨797⟩, jumpiT hwv (by native_decide), - jumpdest, dup4, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsX_claim_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) claimPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd⟩ := hreach - exact evm_run rd with [ - jumpdest, pop, pop, pop, callvalue, - push2 ⟨670⟩, jumpiT hwv (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsX_transferGovernor_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) transferGovernorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd⟩ := hreach - exact evm_run rd with [ - jumpdest, dup5, dup3, dup6, callvalue, - push2 ⟨938⟩, jumpiT hwv (by native_decide), - jumpdest, dup3, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsX_setRewardConfigWithMultiplier_callvalue_ne {cA gh bl σ σ₀ A I} - {g : Sat256} - (hwv : I.weiValue ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigWithMultiplierPc - (dispatchArmLastStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd⟩ := hreach - exact evm_run rd with [ - jumpdest, callvalue, - push2 ⟨797⟩, jumpiT hwv (by native_decide), - jumpdest, dup4, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -/-! ## Shared revert obligations -/ - -theorem cometRewardsNoDispatch {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hnm : ∀ i, i < 11 → (cometRewardsSelBytes i == I.calldata.extract 0 4) = false) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - by_cases hshort : I.calldata.size < 4 - · exact (cometRewardsX_short (g := Sat256.ofUInt256 g) hcode hshort) - |>.reEquivNoDispatch hcode (cometRewardsDispatch_none_short hshort) - · exact (cometRewardsX_nomatch (g := Sat256.ofUInt256 g) hcode (by omega) hsize hnm) - |>.reEquivNoDispatch hcode (cometRewardsDispatch_none_nomatch hnm) - -theorem cometRewardsShortRevert {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) (hsz : I.calldata.size < 4) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - exact (cometRewardsX_short (g := Sat256.ofUInt256 g) hcode hsz) - |>.reEquivNoDispatch hcode (cometRewardsDispatch_none_short hsz) - -theorem cometRewardsNonPayable {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hwv : I.weiValue ≠ ⟨0⟩) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hrev : RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - by_cases hsz : 4 ≤ I.calldata.size - · by_cases h0 : selIs I (cometRewardsSelBytes 0) - · exact cometRewardsX_withdrawToken_callvalue_ne hwv - (cometRewardsReachWithdrawToken hcode hsz hsize h0) - · by_cases h1 : selIs I (cometRewardsSelBytes 1) - · exact cometRewardsX_governor_callvalue_ne hwv - (cometRewardsReachGovernor hcode hsz hsize h1) - · by_cases h2 : selIs I (cometRewardsSelBytes 2) - · exact cometRewardsX_rewardConfig_callvalue_ne hwv - (cometRewardsReachRewardConfig hcode hsz hsize h2) - · by_cases h3 : selIs I (cometRewardsSelBytes 3) - · exact cometRewardsX_getRewardOwed_callvalue_ne hwv - (cometRewardsReachGetRewardOwed hcode hsz hsize h3) - · by_cases h4 : selIs I (cometRewardsSelBytes 4) - · exact cometRewardsX_claimTo_callvalue_ne hwv - (cometRewardsReachClaimTo hcode hsz hsize h4) - · by_cases h5 : selIs I (cometRewardsSelBytes 5) - · exact cometRewardsX_setRewardsClaimed_callvalue_ne hwv - (cometRewardsReachSetRewardsClaimed hcode hsz hsize h5) - · by_cases h6 : selIs I (cometRewardsSelBytes 6) - · exact cometRewardsX_rewardsClaimed_callvalue_ne hwv - (cometRewardsReachRewardsClaimed hcode hsz hsize h6) - · by_cases h7 : selIs I (cometRewardsSelBytes 7) - · exact cometRewardsX_setRewardConfig_callvalue_ne hwv - (cometRewardsReachSetRewardConfig hcode hsz hsize h7) - · by_cases h8 : selIs I (cometRewardsSelBytes 8) - · exact cometRewardsX_claim_callvalue_ne hwv - (cometRewardsReachClaim hcode hsz hsize h8) - · by_cases h9 : selIs I (cometRewardsSelBytes 9) - · exact cometRewardsX_transferGovernor_callvalue_ne hwv - (cometRewardsReachTransferGovernor hcode hsz hsize h9) - · by_cases h10 : selIs I (cometRewardsSelBytes 10) - · exact cometRewardsX_setRewardConfigWithMultiplier_callvalue_ne hwv - (cometRewardsReachSetRewardConfigWithMultiplier hcode hsz hsize h10) - · exact cometRewardsX_nomatch hcode hsz hsize (by - intro i hi - interval_cases i - · simpa [selIs, cometRewardsSelBytes] using h0 - · simpa [selIs, cometRewardsSelBytes] using h1 - · simpa [selIs, cometRewardsSelBytes] using h2 - · simpa [selIs, cometRewardsSelBytes] using h3 - · simpa [selIs, cometRewardsSelBytes] using h4 - · simpa [selIs, cometRewardsSelBytes] using h5 - · simpa [selIs, cometRewardsSelBytes] using h6 - · simpa [selIs, cometRewardsSelBytes] using h7 - · simpa [selIs, cometRewardsSelBytes] using h8 - · simpa [selIs, cometRewardsSelBytes] using h9 - · simpa [selIs, cometRewardsSelBytes] using h10) - · exact cometRewardsX_short hcode (by omega) - exact hrev.reEquivElim hcode fun _ _ hrevXi => by - by_cases hdisp : dispatchMsg contract I.calldata = none - · exact reEquiv_noDispatch hdisp hrevXi - · obtain ⟨t, ht⟩ := Option.ne_none_iff_exists'.mp hdisp - have htmem : t ∈ contract.transitions := by - rw [dispatchMsg_eq_dispatchList contract I.calldata (by rfl)] at ht - exact dispatchList_some_mem ht - by_cases hdec : decodeCalldataWithMode config.abiDecodeMode (t.params.map Param.name) - (transitionSignature t).paramTypes I.calldata = none - · exact reEquiv_decodingFailed ht hdec hrevXi - · obtain ⟨callargs, hca⟩ := Option.ne_none_iff_exists'.mp hdec - exact reEquiv_execution ht hca - (cometRewardsBodyReverts_nonPayable t htmem - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - callargs (by simp only [initState]; exact hwv)) - (by rw [hrevXi]; exact execResultsEquiv.revert rfl rfl) - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/Constructor.lean b/Benchmarks/CompoundIII/CometRewards/Constructor.lean deleted file mode 100644 index a0f6015e..00000000 --- a/Benchmarks/CompoundIII/CometRewards/Constructor.lean +++ /dev/null @@ -1,753 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.Common -import Reasoning.Initcode -import Solm.Equiv - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace Benchmarks.CompoundIII.CometRewards - -/-! -# Compound III CometRewards constructor correctness - -The constructor has one `address governor_` argument. The optimized creation code copies the -single appended ABI word, validates it as a canonical address, stores it into slot 0, then returns -the deployed runtime bytecode. --/ - -theorem cometRewardsCreationBytecode_size : cometRewardsCreationBytecode.size = 4207 := by - native_decide - -theorem cometRewardsRuntimeBytecode_size : cometRewardsBytecode.size = 4063 := by - native_decide - -theorem cometRewardsCreation_runtime_window : - cometRewardsCreationBytecode.extract 144 (144 + 4063) = cometRewardsBytecode := by - native_decide - -noncomputable def cometRewardsCtorArgTail (governor : AccountAddress) : ByteArray := - (EVM.Word.toBytesBE (EVM.word governor)).toByteArray - -noncomputable def cometRewardsCtorCode (governor : AccountAddress) : ByteArray := - cometRewardsCreationBytecode ++ cometRewardsCtorArgTail governor - -theorem cometRewardsCtorArgTail_size (governor : AccountAddress) : - (cometRewardsCtorArgTail governor).size = 32 := by - unfold cometRewardsCtorArgTail - rw [word_toBytesBE_toByteArray_size] - -theorem cometRewardsCtorCode_size (governor : AccountAddress) : - (cometRewardsCtorCode governor).size = 4239 := by - rw [cometRewardsCtorCode, ByteArray.size_append, cometRewardsCreationBytecode_size, - cometRewardsCtorArgTail_size] - -theorem cometRewardsCreation_decode_append (tail : ByteArray) (pc : UInt256) - (hpc : pc.toNat < 144) : - decode (cometRewardsCreationBytecode ++ tail) pc = - decode cometRewardsCreationBytecode pc := - Reasoning.Theory.decode_append_left_window cometRewardsCreationBytecode tail pc - (by rw [cometRewardsCreationBytecode_size]; omega) - (by rw [cometRewardsCreationBytecode_size]; norm_num) - -macro "comet_rewards_ctor_decode" : tactic => - `(tactic| - (first - | rw [cometRewardsCreation_decode_append _ _ (by decide)] - | (unfold cometRewardsCtorCode; rw [cometRewardsCreation_decode_append _ _ (by decide)]); - native_decide)) - -macro "comet_rewards_ctor_jd" : tactic => - `(tactic| - (first - | (apply Reasoning.Theory.D_J_contains_append_left; native_decide) - | (unfold cometRewardsCtorCode; apply Reasoning.Theory.D_J_contains_append_left; - native_decide))) - -open Lean in -macro "comet_rewards_ctor_run " base:term " with " "[" steps:evmStep,* "]" : term => do - let mut acc := base - for s in steps.getElems do - match s with - | `(evmStep| raw $op:ident $args*) => - acc <- `($(acc).$op $args*) - | `(evmStep| $op:ident $args*) => - match op.getId with - | `jump => acc <- `($(acc).jump (by comet_rewards_ctor_decode) $(args[0]!) - (by evm_ov)) - | `jumpiT => acc <- `($(acc).jumpiT (by comet_rewards_ctor_decode) $(args[0]!) - $(args[1]!) (by evm_ov)) - | `jumpiNT => acc <- `($(acc).jumpiNT (by comet_rewards_ctor_decode) $(args[0]!) - (by evm_ov)) - | _ => acc <- `($(acc).$op $args* (by comet_rewards_ctor_decode) - (by evm_ov)) - | _ => Macro.throwUnsupported - return acc - -theorem cometRewardsDeployment_shape {args : List Value} {deployedInitcode : ByteArray} : - config.selfDeployment cometRewardsCreationBytecode args = some deployedInitcode → - ∃ governor : AccountAddress, - args = [.address governor] ∧ deployedInitcode = cometRewardsCtorCode governor := by - intro h - cases args with - | nil => - simp [config, genSolidityConstructorDeployment, contract, constructorDecl, addr, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?] at h - | cons arg rest => - cases rest with - | cons arg2 rest => - cases arg <;> - simp [config, genSolidityConstructorDeployment, contract, constructorDecl, addr, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - | nil => - cases arg with - | address governor => - simp [config, genSolidityConstructorDeployment, contract, constructorDecl, addr, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - exact ⟨governor, rfl, h.symm⟩ - | int i => - simp [config, genSolidityConstructorDeployment, contract, constructorDecl, addr, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - | bool b => - simp [config, genSolidityConstructorDeployment, contract, constructorDecl, addr, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - | array xs => - simp [config, genSolidityConstructorDeployment, contract, constructorDecl, addr, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - | tuple xs => - simp [config, genSolidityConstructorDeployment, contract, constructorDecl, addr, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - | fixedBytes n bs => - simp [config, genSolidityConstructorDeployment, contract, constructorDecl, addr, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - | bytes bs => - simp [config, genSolidityConstructorDeployment, contract, constructorDecl, addr, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - | struct name fields => - simp [config, genSolidityConstructorDeployment, contract, constructorDecl, addr, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - | unit => - simp [config, genSolidityConstructorDeployment, contract, constructorDecl, addr, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - | storageRef er ty => - simp [config, genSolidityConstructorDeployment, contract, constructorDecl, addr, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - -noncomputable def cometRewardsCtorFreePtrMem : ByteArray := - (UInt256.toByteArray (⟨160⟩ : UInt256)).write 0 ByteArray.empty 64 32 - -noncomputable def cometRewardsCtorArgMem (governor : AccountAddress) : ByteArray := - (UInt256.toByteArray (EVM.word governor)).write 0 cometRewardsCtorFreePtrMem 128 32 - -noncomputable def cometRewardsCtorReturnMem (governor : AccountAddress) : ByteArray := - (cometRewardsCtorCode governor).write 144 (cometRewardsCtorArgMem governor) 160 4063 - -theorem write_from_gap_eq (src base : ByteArray) (srcAddr off len : ℕ) - (hlen : len ≠ 0) (hsrc : srcAddr + len ≤ src.size) - (hoff : base.size ≤ off) (hgap : off - base.size < USize.size) : - src.write srcAddr base off len = - base ++ ffi.ByteArray.zeroes (USize.ofNat (off - base.size)) ++ - src.extract srcAddr (srcAddr + len) := by - have hpz : (ffi.ByteArray.zeroes (USize.ofNat (off - base.size))).data.size = - off - base.size := by - rw [show (ffi.ByteArray.zeroes (USize.ofNat (off - base.size))).data.size - = (ffi.ByteArray.zeroes (USize.ofNat (off - base.size))).size from rfl, - ByteArray_zeroes_size, USize.toNat_ofNat_of_lt' hgap] - apply ByteArray.ext - unfold ByteArray.write - rw [if_neg hlen, if_neg (show ¬ srcAddr ≥ src.size from by omega)] - simp only [ByteArray.data_copySlice, ByteArray.data_append, ByteArray.data_extract, - show (⟨↑(off - base.size)⟩ : USize) = USize.ofNat (off - base.size) from rfl] - have hDsz : - (base.data ++ (ffi.ByteArray.zeroes (USize.ofNat (off - base.size))).data).size = - off := by - rw [Array.size_append, hpz] - show base.size + (off - base.size) = off - omega - have hcopy : min len (src.size - srcAddr) = len := by omega - rw [hcopy, - show min base.size (off + len) - (off + len) = 0 from by omega, - show (ffi.ByteArray.zeroes (⟨↑(0:ℕ)⟩ : USize)).data = (#[] : Array UInt8) from by - rw [show (⟨↑(0:ℕ)⟩ : USize) = USize.ofNat 0 from rfl, - zeroes_zero (n := USize.ofNat 0) (by rw [USize.toNat_ofNat_of_lt' (by omega)])] - rfl] - rw [Array.append_empty] - rw [Array.extract_eq_self_of_le (by rw [hDsz])] - rw [show srcAddr + (len + 0) = srcAddr + len from by omega] - rw [show min (len + 0) (src.data.size - srcAddr) = len from by - have : src.data.size = src.size := rfl - omega] - have htail : - (base.data ++ (ffi.ByteArray.zeroes (USize.ofNat (off - base.size))).data).extract - (off + len) = #[] := by - apply Array.extract_eq_empty_of_le - rw [hDsz] - omega - rw [htail, Array.append_empty] - -theorem cometRewardsCtorArg_extract (governor : AccountAddress) : - (cometRewardsCtorCode governor).extract 4207 (4207 + 32) = - (EVM.Word.toBytesBE (EVM.word governor)).toByteArray := by - unfold cometRewardsCtorCode cometRewardsCtorArgTail - exact extract_append_right' cometRewardsCreationBytecode - (EVM.Word.toBytesBE (EVM.word governor)).toByteArray 4207 (4207 + 32) - cometRewardsCreationBytecode_size.symm - (by rw [cometRewardsCreationBytecode_size, word_toBytesBE_toByteArray_size]) - -theorem cometRewardsCtorArgMem_codecopy (governor : AccountAddress) : - (cometRewardsCtorCode governor).write 4207 cometRewardsCtorFreePtrMem 128 32 = - cometRewardsCtorArgMem governor := by - have hcopy : - (cometRewardsCtorCode governor).write 4207 cometRewardsCtorFreePtrMem 128 32 = - cometRewardsCtorFreePtrMem ++ ffi.ByteArray.zeroes (USize.ofNat 32) ++ - (cometRewardsCtorCode governor).extract 4207 (4207 + 32) := by - have hfreeSize : cometRewardsCtorFreePtrMem.size = 96 := by - unfold cometRewardsCtorFreePtrMem - native_decide - simpa [hfreeSize] using write_from_gap_eq (cometRewardsCtorCode governor) cometRewardsCtorFreePtrMem - 4207 128 32 (by decide) (by rw [cometRewardsCtorCode_size]) - (by rw [hfreeSize]; omega) - (by rw [hfreeSize]; native_decide) - unfold cometRewardsCtorArgMem - rw [hcopy, cometRewardsCtorArg_extract, word_toBytesBE_toByteArray_eq_toByteArray] - rw [toByteArray_write_eq (EVM.word governor) cometRewardsCtorFreePtrMem 128] - · have hgap32 : 128 - cometRewardsCtorFreePtrMem.size = 32 := by - unfold cometRewardsCtorFreePtrMem - native_decide - rw [hgap32] - · unfold cometRewardsCtorFreePtrMem - native_decide - · unfold cometRewardsCtorFreePtrMem - native_decide - -theorem cometRewardsCtorFreePtrMem_size : cometRewardsCtorFreePtrMem.size = 96 := by - unfold cometRewardsCtorFreePtrMem - native_decide - -theorem cometRewardsCtorArgMem_size (governor : AccountAddress) : - (cometRewardsCtorArgMem governor).size = 160 := by - unfold cometRewardsCtorArgMem - rw [toByteArray_write_eq (EVM.word governor) cometRewardsCtorFreePtrMem 128] - · rw [ByteArray.size_append, ByteArray.size_append, cometRewardsCtorFreePtrMem_size, - ByteArray_zeroes_size, USize.toNat_ofNat_of_lt' (by native_decide), toByteArray_size] - · rw [cometRewardsCtorFreePtrMem_size] - omega - · rw [cometRewardsCtorFreePtrMem_size] - native_decide - -theorem cometRewardsCtorArgMem_read128 (governor : AccountAddress) : - (cometRewardsCtorArgMem governor).readWithPadding 128 32 = - UInt256.toByteArray (EVM.word governor) := by - unfold cometRewardsCtorArgMem - exact toByteArray_write_read_back_of_gap (EVM.word governor) cometRewardsCtorFreePtrMem 128 - (by rw [cometRewardsCtorFreePtrMem_size]; native_decide) - -theorem cometRewardsCtorArgMem_mload128 (governor : AccountAddress) : - (if (⟨128⟩ : UInt256).toNat ≥ (cometRewardsCtorArgMem governor).size - ∨ (⟨128⟩ : UInt256) ≥ (UInt256.ofNat 5) * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat (fromByteArrayBigEndian - ((cometRewardsCtorArgMem governor).readWithPadding 128 32))) = - EVM.word governor := by - exact mloadWordValue_of_readWithPadding - (mem := cometRewardsCtorArgMem governor) (aw := UInt256.ofNat 5) - (off := ⟨128⟩) (v := EVM.word governor) - (by - have hsz := cometRewardsCtorArgMem_size governor - have h128 : (⟨128⟩ : UInt256).toNat = 128 := by decide - rw [h128, hsz] - omega) - (by decide) - (cometRewardsCtorArgMem_read128 governor) - -theorem cometRewardsCtorArgMem_read64 (governor : AccountAddress) : - (cometRewardsCtorArgMem governor).readWithPadding 64 32 = - UInt256.toByteArray (⟨160⟩ : UInt256) := by - unfold cometRewardsCtorArgMem - rw [toByteArray_write_read_below_of_gap (EVM.word governor) cometRewardsCtorFreePtrMem - 128 64] - · unfold cometRewardsCtorFreePtrMem - exact toByteArray_write_read_back_of_gap (⟨160⟩ : UInt256) ByteArray.empty 64 - (by native_decide) - · rw [cometRewardsCtorFreePtrMem_size] - · omega - · rw [cometRewardsCtorFreePtrMem_size] - native_decide - -theorem cometRewardsCtorArgMem_mload64 (governor : AccountAddress) : - (if (⟨64⟩ : UInt256).toNat ≥ (cometRewardsCtorArgMem governor).size - ∨ (⟨64⟩ : UInt256) ≥ (UInt256.ofNat 5) * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat (fromByteArrayBigEndian - ((cometRewardsCtorArgMem governor).readWithPadding 64 32))) = - (⟨160⟩ : UInt256) := by - exact mloadWordValue_of_readWithPadding - (mem := cometRewardsCtorArgMem governor) (aw := UInt256.ofNat 5) - (off := ⟨64⟩) (v := (⟨160⟩ : UInt256)) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide, - cometRewardsCtorArgMem_size] - omega) - (by decide) - (cometRewardsCtorArgMem_read64 governor) - -theorem cometRewardsCtorReturnMem_codecopy (governor : AccountAddress) : - (cometRewardsCtorCode governor).write 144 (cometRewardsCtorArgMem governor) 160 4063 = - cometRewardsCtorReturnMem governor := rfl - -theorem cometRewardsCtorReturnMem_read (governor : AccountAddress) : - (cometRewardsCtorReturnMem governor).readWithPadding 160 4063 = cometRewardsBytecode := by - unfold cometRewardsCtorReturnMem - rw [show (160 : Nat) = (cometRewardsCtorArgMem governor).size by - rw [cometRewardsCtorArgMem_size]] - rw [readWithPadding_eq_extract' _ (cometRewardsCtorArgMem governor).size 4063 - (by decide) (by decide) (by - rw [write_end_size_from (cometRewardsCtorCode governor) - (cometRewardsCtorArgMem governor) 144 4063 (by decide) - (by rw [cometRewardsCtorCode_size]; omega)] - )] - rw [write_end_extract_tail_from (cometRewardsCtorCode governor) - (cometRewardsCtorArgMem governor) 144 4063 (by decide) - (by rw [cometRewardsCtorCode_size]; omega)] - have hleft : - (cometRewardsCtorCode governor).extract 144 (144 + 4063) = - cometRewardsCreationBytecode.extract 144 (144 + 4063) := by - have h := byteArray_extract_append_left cometRewardsCreationBytecode - (cometRewardsCtorArgTail governor) 144 (144 + 4063) - (by rw [cometRewardsCreationBytecode_size]) - simpa [cometRewardsCtorCode] using h - rw [hleft, cometRewardsCreation_runtime_window] - -theorem cometRewardsCtorGovernorWord_toNat (governor : AccountAddress) : - (EVM.word governor).toNat = governor.val := by - exact ulit_toNat' _ (lt_of_lt_of_le governor.isLt - (show AccountAddress.size ≤ UInt256.size from by decide)) - -theorem cometRewardsCtorGovernor_ofNat (governor : AccountAddress) : - AccountAddress.ofNat (EVM.word governor).toNat = governor := by - apply Fin.ext - unfold AccountAddress.ofNat - rw [cometRewardsCtorGovernorWord_toNat, Fin.val_ofNat] - exact Nat.mod_eq_of_lt governor.isLt - -theorem cometRewardsCtorGovernorWord_canonical (governor : AccountAddress) : - (EVM.word governor).toNat < EVM.addressModulus := by - rw [cometRewardsCtorGovernorWord_toNat] - simp [EVM.addressModulus, EVM.twoPow, AccountAddress.size] - -def cometRewardsCtorStoredWord (σ : AccountMap) (I : ExecutionEnv) - (governor : AccountAddress) : UInt256 := - setAddressOffset0Word - (σ.find? I.codeOwner |>.option ⟨0⟩ (fun ac => ac.storage.findD ⟨0⟩ ⟨0⟩)) - (EVM.word governor) - -def cometRewardsCtorPostState (evm : EVM.State) (governor : AccountAddress) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (setAddressOffset0Word - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - (EVM.word governor)) - -theorem cometRewardsCtorOverflowCheck : - UInt256.lor - (UInt256.lt (⟨160⟩ : UInt256) (⟨128⟩ : UInt256)) - (UInt256.gt (⟨160⟩ : UInt256) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) = - ⟨0⟩ := by - native_decide - -theorem cometRewardsCtorArgRoomCheck : - UInt256.slt (UInt256.sub (⟨160⟩ : UInt256) ⟨128⟩) ⟨32⟩ = ⟨0⟩ := by - native_decide - -theorem cometRewardsCtorArgEnd : - (⟨128⟩ : UInt256) + ⟨32⟩ = ⟨160⟩ := by - native_decide - -theorem cometRewardsCtorRoundedLen : - UInt256.land (UInt256.lnot (⟨31⟩ : UInt256)) ((⟨32⟩ : UInt256) + ⟨31⟩) = - (⟨32⟩ : UInt256) := by - native_decide - -theorem cometRewardsCtorNewFreePtr : - (⟨128⟩ : UInt256) + UInt256.land (UInt256.lnot (⟨31⟩ : UInt256)) - ((⟨32⟩ : UInt256) + ⟨31⟩) = - (⟨160⟩ : UInt256) := by - native_decide - -theorem cometRewardsCtorCleanAddressCheck (governor : AccountAddress) : - UInt256.sub (EVM.word governor) - (UInt256.land (EVM.word governor) solcAddrMask) = ⟨0⟩ := by - have hclean := solcAddrMask_clean (cometRewardsCtorGovernorWord_canonical governor) - rw [hclean] - exact u256_sub_self _ - -theorem cometRewardsCtorMaskedGovernor (governor : AccountAddress) : - UInt256.land (EVM.word governor) solcAddrMask = EVM.word governor := by - exact solcAddrMask_clean (cometRewardsCtorGovernorWord_canonical governor) - -theorem cometRewardsInitcodeNonpayableRevert - {createdAccounts : Batteries.RBSet AccountAddress compare} - {genesisBlockHeader : BlockHeader} - {blocks : ProcessedBlocks} - {σ : AccountMap} - {σ₀ : AccountMap} - {A : Substate} - {I : ExecutionEnv} - {g : Sat256} - (tail : ByteArray) - (hcode : I.code = cometRewardsCreationBytecode ++ tail) - (hwv : I.weiValue ≠ ⟨0⟩) : - RDrev (cometRewardsCreationBytecode ++ tail) g - (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) := by - have rd0 : - RD (cometRewardsCreationBytecode ++ tail) I g - (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) ⟨0⟩ [] - ByteArray.empty (UInt256.ofNat 0) ByteArray.empty (createdAccounts, σ) 0 0 := - RD.initState hcode - have rd116 := comet_rewards_ctor_run rd0 with [ - push1 ⟨128⟩, callvalue, push2 ⟨116⟩, - jumpiT hwv (by comet_rewards_ctor_jd), - jumpdest] - exact rd116.solcPush1Dup1Revert0 - (by comet_rewards_ctor_decode) (by comet_rewards_ctor_decode) - (by comet_rewards_ctor_decode) (by simp) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsInitcodeSuccess - {createdAccounts : Batteries.RBSet AccountAddress compare} - {genesisBlockHeader : BlockHeader} - {blocks : ProcessedBlocks} - {σ : AccountMap} - {σ₀ : AccountMap} - {A : Substate} - {I : ExecutionEnv} - {g : Sat256} - (governor : AccountAddress) - (hcode : I.code = cometRewardsCtorCode governor) - (hperm : I.perm = true) - (hwv : I.weiValue = ⟨0⟩) : - RDret (cometRewardsCtorCode governor) g - (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) - (createdAccounts, sstoreAccountMap I.codeOwner σ ⟨0⟩ - (cometRewardsCtorStoredWord σ I governor)) - cometRewardsBytecode := by - have rd0 : - RD (cometRewardsCtorCode governor) I g - (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) ⟨0⟩ [] - ByteArray.empty (UInt256.ofNat 0) ByteArray.empty (createdAccounts, σ) 0 0 := - RD.initState hcode - let oldGovernorSlot : UInt256 := - (σ.find? I.codeOwner |>.option ⟨0⟩ (fun ac => ac.storage.findD ⟨0⟩ ⟨0⟩)) - let governorStoreWord : UInt256 := cometRewardsCtorStoredWord σ I governor - have hcodesize : UInt256.ofNat (cometRewardsCtorCode governor).size = (⟨4239⟩ : UInt256) := by - apply u256_inj - rw [cometRewardsCtorCode_size] - native_decide - have harglen : - UInt256.sub (UInt256.ofNat (cometRewardsCtorCode governor).size) ⟨4207⟩ = - (⟨32⟩ : UInt256) := by - rw [hcodesize] - native_decide - have hrounded : - UInt256.land (UInt256.lnot (⟨31⟩ : UInt256)) - (UInt256.add - (UInt256.sub (UInt256.ofNat (cometRewardsCtorCode governor).size) ⟨4207⟩) - ⟨31⟩) = - (⟨32⟩ : UInt256) := by - rw [harglen] - native_decide - have hnewFree : - UInt256.add ⟨128⟩ - (UInt256.land (UInt256.lnot (⟨31⟩ : UInt256)) - (UInt256.add - (UInt256.sub (UInt256.ofNat (cometRewardsCtorCode governor).size) ⟨4207⟩) - ⟨31⟩)) = - (⟨160⟩ : UInt256) := by - rw [hrounded] - native_decide - have rdBeforeCopy := comet_rewards_ctor_run rd0 with [ - push1 ⟨128⟩, callvalue, push2 ⟨116⟩, - jumpiNT hwv, - push1 ⟨31⟩, push2 ⟨4207⟩, codesize, dup2, swap1, sub, swap2, - dup3, add, push1 ⟨31⟩, not, and, dup4, add, swap2, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup4, gt, - dup5, dup5, lt, lor] - rw [harglen] at rdBeforeCopy - rw [cometRewardsCtorNewFreePtr, cometRewardsCtorOverflowCheck] at rdBeforeCopy - have rdBeforeCodecopy := comet_rewards_ctor_run rdBeforeCopy with [ - push2 ⟨121⟩, jumpiNT (by decide), - dup1, dup5, swap3, push1 ⟨32⟩, swap5, push1 ⟨64⟩, - raw mstore 9 cometRewardsCtorFreePtrMem (UInt256.ofNat 3) - (by comet_rewards_ctor_decode) - mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold cometRewardsCtorFreePtrMem - rfl) - (by decide) (by evm_ov), - dup4] - have rdAfterCodecopy := comet_rewards_ctor_run rdBeforeCodecopy with [ - raw codecopy 6 (cometRewardsCtorArgMem governor) (UInt256.ofNat 5) - (by comet_rewards_ctor_decode) - mem_cost - (cometRewardsCtorArgMem_codecopy governor) - (by decide) (by evm_ov), - dup2, add, sub, slt] - rw [cometRewardsCtorArgEnd, cometRewardsCtorArgRoomCheck] at rdAfterCodecopy - have rdBeforeMload := comet_rewards_ctor_run rdAfterCodecopy with [ - push2 ⟨116⟩, jumpiNT (by decide)] - have rdBeforeClean := comet_rewards_ctor_run rdBeforeMload with [ - raw mload 0 (EVM.word governor) (UInt256.ofNat 5) - (by comet_rewards_ctor_decode) - mem_cost - (cometRewardsCtorArgMem_mload128 governor) - (by decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup2, and, swap1, - dup2, swap1, sub] - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, - cometRewardsCtorCleanAddressCheck governor] at rdBeforeClean - rw [cometRewardsCtorMaskedGovernor governor] at rdBeforeClean - have rdBeforeSload := comet_rewards_ctor_run rdBeforeClean with [ - push2 ⟨116⟩, jumpiNT (by decide), push1 ⟨0⟩, dup1] - obtain ⟨_, _, rdAfterSload0⟩ := rdBeforeSload.sload - (by comet_rewards_ctor_decode) (by evm_ov) - obtain ⟨_, _, rdAfterSload⟩ : - ∃ k C, RD (cometRewardsCtorCode governor) I g - (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) ⟨86⟩ - [oldGovernorSlot, ⟨0⟩, EVM.word governor] - (cometRewardsCtorArgMem governor) (UInt256.ofNat 5) ByteArray.empty - (createdAccounts, σ) k C := by - exact ⟨_, _, by simpa [oldGovernorSlot] using rdAfterSload0⟩ - have rdBeforeStore := comet_rewards_ctor_run rdAfterSload with [ - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, and, - swap2, swap1, swap2, lor, swap1] - have hpacked : - UInt256.lor - (UInt256.land (UInt256.lnot solcAddrMask) oldGovernorSlot) - (EVM.word governor) = - governorStoreWord := by - unfold governorStoreWord cometRewardsCtorStoredWord oldGovernorSlot setAddressOffset0Word - rw [u256_land_comm (UInt256.lnot solcAddrMask) _, cometRewardsCtorMaskedGovernor governor] - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] at rdBeforeStore - rw [hpacked] at rdBeforeStore - obtain ⟨_, _, rdAfterStore⟩ := rdBeforeStore.sstore hperm - (by comet_rewards_ctor_decode) (by evm_ov) - have rdBeforeReturn := comet_rewards_ctor_run rdAfterStore with [ - push1 ⟨64⟩, - raw mload 0 ⟨160⟩ (UInt256.ofNat 5) - (by comet_rewards_ctor_decode) - mem_cost - (cometRewardsCtorArgMem_mload64 governor) - (by decide) (by evm_ov), - push2 ⟨4063⟩, swap1, dup2, push2 ⟨144⟩, dup3, - raw codecopy 415 (cometRewardsCtorReturnMem governor) (UInt256.ofNat 132) - (by comet_rewards_ctor_decode) - mem_cost - (cometRewardsCtorReturnMem_codecopy governor) - (by decide) (by evm_ov)] - exact rdBeforeReturn.ret 0 cometRewardsBytecode - (by comet_rewards_ctor_decode) - mem_cost - (cometRewardsCtorReturnMem_read governor) - (by evm_ov) - -def cometRewardsCtorLocals (governor : AccountAddress) : Store := - Std.HashMap.ofList - (List.zip (contract.ctor.params.map Param.name) [.address governor]) - -theorem cometRewardsCtorLocals_get_governorParam (governor : AccountAddress) : - (cometRewardsCtorLocals governor).get? "governor_" = some (.address governor) := by - unfold cometRewardsCtorLocals - simp [contract, constructorDecl] - -theorem cometRewardsCtorLocals_get_governorStorage (governor : AccountAddress) : - (cometRewardsCtorLocals governor).get? "governor" = none := by - unfold cometRewardsCtorLocals - simp [contract, constructorDecl] - -theorem cometRewardsCtorAssignGovernor (evm : EVM.State) (governor : AccountAddress) : - assignStorageRef? config - { contract := contract, locals := cometRewardsCtorLocals governor } - evm .storage governorRef (.address governor) = - .ok ({ contract := contract, locals := cometRewardsCtorLocals governor }, - cometRewardsCtorPostState evm governor) := by - have her : evalStorageRef config - { contract := contract, locals := cometRewardsCtorLocals governor } evm governorRef = - .ok { base := "governor", steps := [] } := by - simp [evalStorageRef, evalStorageRefSteps, governorRef, EvalResult.bind, pure, bind] - have hty : storageTypeAt? contract.storage - ({ base := "governor", steps := [] } : EvaledStorageRef) = some (.elem .address) := by - decide - have hstore : - storageLocStore evm (fieldLoc ⟨0⟩ 0 20 (by decide) .address) (.address governor) = - some (cometRewardsCtorPostState evm governor) := by - have h := storageLocStore_address_offset0 evm ⟨0⟩ (EVM.word governor) - (cometRewardsCtorGovernorWord_canonical governor) - rw [cometRewardsCtorGovernor_ofNat] at h - simpa [cometRewardsCtorPostState, fieldLoc, loc, addressOffset0Loc] using h - exact assignStorageRef_storage_scalar_value (cfg := config) - (solm := { contract := contract, locals := cometRewardsCtorLocals governor }) - (evm := evm) (evm' := cometRewardsCtorPostState evm governor) - (slot := governorRef) (er := { base := "governor", steps := [] }) - (ty := .elem .address) (loc := fieldLoc ⟨0⟩ 0 20 (by decide) .address) - (value := .address governor) - (cometRewardsCtorLocals_get_governorStorage governor) - her hty (by rfl) (by trivial) hstore - -theorem cometRewardsCtorBodyReturns (evm : EVM.State) (governor : AccountAddress) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) : - ExecTransitionBody config contract evm (cometRewardsCtorLocals governor) contract.ctor.body - (.returned { contract := contract, locals := cometRewardsCtorLocals governor } - (cometRewardsCtorPostState evm governor) none) := by - refine ExecFuncBody.execBlockOK ?_ - simpa [contract, constructorDecl, nonpayable] using - ((ABlock.start.requireStep (evalCallvalueEq_true (cfg := config) - (solm := { contract := contract, locals := cometRewardsCtorLocals governor }) - (evm := evm) hwv)).run - (ExecBlock.consNormal - (ExecStmt.assign - (by - show evalExpr? config - { contract := contract, locals := cometRewardsCtorLocals governor } evm - (.var "governor_") = .ok (.address governor) - simp only [evalExpr?, cometRewardsCtorLocals_get_governorParam, - EvalResult.ofOption]) - (cometRewardsCtorAssignGovernor evm governor)) - ExecBlock.nil)) - -theorem cometRewardsSolmCtorExecSuccess - {createdAccounts : Batteries.RBSet AccountAddress compare} - {genesisBlockHeader : BlockHeader} - {blocks : ProcessedBlocks} - {σ : AccountMap} - {σ₀ : AccountMap} - {g : UInt256} - {A : Substate} - {I : ExecutionEnv} - (governor : AccountAddress) - (hwv : I.weiValue = ⟨0⟩) : - solmCtorExec config contract [.address governor] createdAccounts genesisBlockHeader blocks - σ σ₀ g A I - (.returned - { contract := contract, locals := cometRewardsCtorLocals governor } - (cometRewardsCtorPostState - (initState createdAccounts genesisBlockHeader blocks σ σ₀ (Sat256.ofUInt256 g) A I) - governor) - none) := by - refine solmCtorExec.intro - (evmState := initState createdAccounts genesisBlockHeader blocks σ σ₀ (Sat256.ofUInt256 g) A I) - (argsStore := cometRewardsCtorLocals governor) - ?_ rfl ?_ ?_ - · rfl - · simp [cometRewardsCtorLocals, contract, constructorDecl] - · exact cometRewardsCtorBodyReturns - (initState createdAccounts genesisBlockHeader blocks σ σ₀ (Sat256.ofUInt256 g) A I) - governor (by simpa [initState] using hwv) - -theorem cometRewardsSolmCtorExecReverts_nonpayable - {createdAccounts : Batteries.RBSet AccountAddress compare} - {genesisBlockHeader : BlockHeader} - {blocks : ProcessedBlocks} - {σ : AccountMap} - {σ₀ : AccountMap} - {g : UInt256} - {A : Substate} - {I : ExecutionEnv} - (governor : AccountAddress) - (hwv : I.weiValue ≠ ⟨0⟩) : - solmCtorExec config contract [.address governor] - createdAccounts genesisBlockHeader blocks σ σ₀ g A I .reverted := by - refine solmCtorExec.intro - (evmState := initState createdAccounts genesisBlockHeader blocks σ σ₀ (Sat256.ofUInt256 g) A I) - (argsStore := cometRewardsCtorLocals governor) - ?_ rfl ?_ ?_ - · rfl - · simp [cometRewardsCtorLocals, contract, constructorDecl] - · exact bodyReverts_nonPayable (cfg := config) (contract := contract) - (locals := cometRewardsCtorLocals governor) hwv - -/-- The optimized creation bytecode refines the Solm constructor specification. -/ -theorem cometRewardsConstructorCorrect : - constructorEquivalence config cometRewardsCreationBytecode contract cometRewardsBytecode := by - refine constructorEquivalence.intro ?_ - intro createdAccounts genesisBlockHeader blocks σ_evm σ_solm σ₀ g A I - args deployedInitcode hdeploy hcode _hcalldata hperm hσ - rcases cometRewardsDeployment_shape hdeploy with ⟨governor, hargs, hdeployed⟩ - subst args - by_cases hwv : I.weiValue = ⟨0⟩ - · have hcodeCtor : I.code = cometRewardsCtorCode governor := by - rw [hcode, hdeployed] - have hrd := cometRewardsInitcodeSuccess - (createdAccounts := createdAccounts) (genesisBlockHeader := genesisBlockHeader) - (blocks := blocks) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) governor hcodeCtor hperm hwv - rcases hrd with hOOG | ⟨s, hX, hacc⟩ - · exact constructorEquivalenceFor.outOfGas - (Xi_error_of_X (g := g) (by - rw [← hcodeCtor] at hOOG - simpa [Sat256.ofUInt256] using hOOG)) - · have hsuccess := Xi_success_of_X (g := g) (by - rw [← hcodeCtor] at hX - simpa [Sat256.ofUInt256] using hX) - have hcA : s.createdAccounts = createdAccounts := congrArg Prod.fst hacc - have hσ' : s.accountMap = - sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (cometRewardsCtorStoredWord σ_evm I governor) := by - exact congrArg Prod.snd hacc - rw [hcA, hσ'] at hsuccess - refine constructorEquivalenceFor.execution hsuccess - (cometRewardsSolmCtorExecSuccess - (createdAccounts := createdAccounts) (genesisBlockHeader := genesisBlockHeader) - (blocks := blocks) (σ := σ_solm) (σ₀ := σ₀) (g := g) (A := A) (I := I) - governor hwv) ?_ - refine ctorResultEquiv.success rfl rfl ?_ ?_ rfl - · simp [cometRewardsCtorPostState, initState, storageStore_createdAccounts] - · have hOldSlot : - (σ_evm.find? I.codeOwner |>.option ⟨0⟩ - (fun ac => ac.storage.findD ⟨0⟩ ⟨0⟩)) = - (σ_solm.find? I.codeOwner |>.option ⟨0⟩ - (fun ac => ac.storage.findD ⟨0⟩ ⟨0⟩)) := by - exact accountMapEquiv_storage_findD hσ I.codeOwner ⟨0⟩ ⟨0⟩ - have hstored : - cometRewardsCtorStoredWord σ_evm I governor = - cometRewardsCtorStoredWord σ_solm I governor := by - simp [cometRewardsCtorStoredWord, hOldSlot] - simp [cometRewardsCtorPostState, initState, storageStore_accountMap, - Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - change accountMapEquiv - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (cometRewardsCtorStoredWord σ_evm I governor)) - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (cometRewardsCtorStoredWord σ_solm I governor)) - rw [← hstored] - exact accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (cometRewardsCtorStoredWord σ_evm I governor) hσ - · let tail := cometRewardsCtorArgTail governor - have hcodeTail : I.code = cometRewardsCreationBytecode ++ tail := by - rw [hcode, hdeployed] - rfl - have hrd := cometRewardsInitcodeNonpayableRevert - (createdAccounts := createdAccounts) (genesisBlockHeader := genesisBlockHeader) - (blocks := blocks) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) tail hcodeTail hwv - rcases hrd.xiResult hcodeTail with hOOG | ⟨g', o, hrev⟩ - · exact constructorEquivalenceFor.outOfGas (by simpa [Sat256.ofUInt256] using hOOG) - · refine constructorEquivalenceFor.execution (by simpa [Sat256.ofUInt256] using hrev) - (cometRewardsSolmCtorExecReverts_nonpayable - (createdAccounts := createdAccounts) (genesisBlockHeader := genesisBlockHeader) - (blocks := blocks) (σ := σ_solm) (σ₀ := σ₀) (g := g) (A := A) (I := I) - governor hwv) ?_ - exact ctorResultEquiv.revert rfl rfl - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/Correct.lean b/Benchmarks/CompoundIII/CometRewards/Correct.lean deleted file mode 100644 index 4f415163..00000000 --- a/Benchmarks/CompoundIII/CometRewards/Correct.lean +++ /dev/null @@ -1,89 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.Claim -import Benchmarks.CompoundIII.CometRewards.ClaimTo -import Benchmarks.CompoundIII.CometRewards.Constructor -import Benchmarks.CompoundIII.CometRewards.GetRewardOwed -import Benchmarks.CompoundIII.CometRewards.Governor -import Benchmarks.CompoundIII.CometRewards.RewardConfig -import Benchmarks.CompoundIII.CometRewards.RewardsClaimed -import Benchmarks.CompoundIII.CometRewards.SetRewardConfig -import Benchmarks.CompoundIII.CometRewards.SetRewardConfigWithMultiplier -import Benchmarks.CompoundIII.CometRewards.SetRewardsClaimed -import Benchmarks.CompoundIII.CometRewards.TransferGovernor -import Benchmarks.CompoundIII.CometRewards.WithdrawToken -import Solm.Equiv - -/-! -# Compound III CometRewards benchmark correctness scaffold - -This file assembles the CometRewards runtime dispatcher. Function-body correctness obligations -live in their own files; shared via-IR dispatcher reach obligations live in `Common.lean`. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.CompoundIII.CometRewards - -theorem cometRewardsCorrect : - runtimeEquivalence config cometRewardsBytecode contract := by - refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm - hAccounts => ?_⟩ - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz : 4 ≤ I.calldata.size - · by_cases h0 : selIs I (cometRewardsSelBytes 0) - · exact cometRewardsWithdrawTokenBodyCore hcode hsize hperm hwv h0 - (cometRewardsReachWithdrawToken hcode hsz hsize h0) hAccounts - · by_cases h1 : selIs I (cometRewardsSelBytes 1) - · exact cometRewardsGovernorBodyCore hcode hsize hperm hwv h1 - (cometRewardsReachGovernor hcode hsz hsize h1) hAccounts - · by_cases h2 : selIs I (cometRewardsSelBytes 2) - · exact cometRewardsRewardConfigBodyCore hcode hsize hperm hwv h2 - (cometRewardsReachRewardConfig hcode hsz hsize h2) hAccounts - · by_cases h3 : selIs I (cometRewardsSelBytes 3) - · exact cometRewardsGetRewardOwedBodyCore hcode hsize hperm hwv h3 - (cometRewardsReachGetRewardOwed hcode hsz hsize h3) hAccounts - · by_cases h4 : selIs I (cometRewardsSelBytes 4) - · exact cometRewardsClaimToBodyCore hcode hsize hperm hwv h4 - (cometRewardsReachClaimTo hcode hsz hsize h4) hAccounts - · by_cases h5 : selIs I (cometRewardsSelBytes 5) - · exact cometRewardsSetRewardsClaimedBodyCore hcode hsize hperm hwv h5 - (cometRewardsReachSetRewardsClaimed hcode hsz hsize h5) hAccounts - · by_cases h6 : selIs I (cometRewardsSelBytes 6) - · exact cometRewardsRewardsClaimedBodyCore hcode hsize hperm hwv h6 - (cometRewardsReachRewardsClaimed hcode hsz hsize h6) hAccounts - · by_cases h7 : selIs I (cometRewardsSelBytes 7) - · exact cometRewardsSetRewardConfigBodyCore hcode hsize hperm hwv h7 - (cometRewardsReachSetRewardConfig hcode hsz hsize h7) hAccounts - · by_cases h8 : selIs I (cometRewardsSelBytes 8) - · exact cometRewardsClaimBodyCore hcode hsize hperm hwv h8 - (cometRewardsReachClaim hcode hsz hsize h8) hAccounts - · by_cases h9 : selIs I (cometRewardsSelBytes 9) - · exact cometRewardsTransferGovernorBodyCore hcode hsize hperm hwv h9 - (cometRewardsReachTransferGovernor hcode hsz hsize h9) hAccounts - · by_cases h10 : selIs I (cometRewardsSelBytes 10) - · exact cometRewardsSetRewardConfigWithMultiplierBodyCore hcode hsize - hperm hwv h10 - (cometRewardsReachSetRewardConfigWithMultiplier hcode hsz hsize - h10) - hAccounts - · refine cometRewardsNoDispatch hcode hsize hperm hwv ?_ - intro i hi - interval_cases i - · simpa [selIs, cometRewardsSelBytes] using h0 - · simpa [selIs, cometRewardsSelBytes] using h1 - · simpa [selIs, cometRewardsSelBytes] using h2 - · simpa [selIs, cometRewardsSelBytes] using h3 - · simpa [selIs, cometRewardsSelBytes] using h4 - · simpa [selIs, cometRewardsSelBytes] using h5 - · simpa [selIs, cometRewardsSelBytes] using h6 - · simpa [selIs, cometRewardsSelBytes] using h7 - · simpa [selIs, cometRewardsSelBytes] using h8 - · simpa [selIs, cometRewardsSelBytes] using h9 - · simpa [selIs, cometRewardsSelBytes] using h10 - · exact cometRewardsShortRevert hcode hsize hperm hwv (by omega) - · exact cometRewardsNonPayable hcode hsize hwv - -theorem cometRewardsContractCorrect : - contractEquivalence config cometRewardsCreationBytecode cometRewardsBytecode contract := - contractEquivalence.intro cometRewardsConstructorCorrect cometRewardsCorrect - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/GetRewardOwed.lean b/Benchmarks/CompoundIII/CometRewards/GetRewardOwed.lean deleted file mode 100644 index bf0c238c..00000000 --- a/Benchmarks/CompoundIII/CometRewards/GetRewardOwed.lean +++ /dev/null @@ -1,7855 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.RewardConfig -import Benchmarks.CompoundIII.CometRewards.RewardsClaimed -import Benchmarks.CompoundIII.CometRewards.SetRewardConfigWithMultiplier -import Reasoning.ExternalCall - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace Benchmarks.CompoundIII.CometRewards - -/-! ## `getRewardOwed(address,address)` ABI and storage setup -/ - -abbrev getRewardOwedCometWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -abbrev getRewardOwedAccountWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 36 - -abbrev getRewardOwedCometValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (getRewardOwedCometWord I).toNat) - -abbrev getRewardOwedAccountValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (getRewardOwedAccountWord I).toNat) - -abbrev getRewardOwedStore (I : ExecutionEnv) : Store := - ((∅ : Store).insert "comet" (getRewardOwedCometValue I)).insert "account" - (getRewardOwedAccountValue I) - -abbrev getRewardOwedFrame (evm : EVM.State) (I : ExecutionEnv) : Frame := - { contract := contract, - locals := (getRewardOwedStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) } - -def getRewardOwedRewardConfigSlotOf (I : ExecutionEnv) : UInt256 := - rewardConfigSlot (.address (AccountAddress.ofNat (getRewardOwedCometWord I).toNat)) - -def getRewardOwedRewardsClaimedSlotOf (I : ExecutionEnv) : UInt256 := - rewardsClaimedSlot - (.address (AccountAddress.ofNat (getRewardOwedCometWord I).toNat)) - (.address (AccountAddress.ofNat (getRewardOwedAccountWord I).toNat)) - -def getRewardOwedRewardConfigSlot0Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - σ.find? I.codeOwner |>.option ⟨0⟩ - (fun acc => acc.storage.findD (getRewardOwedRewardConfigSlotOf I) ⟨0⟩) - -def getRewardOwedMultiplierWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - σ.find? I.codeOwner |>.option ⟨0⟩ - (fun acc => acc.storage.findD (getRewardOwedRewardConfigSlotOf I + ⟨1⟩) ⟨0⟩) - -def getRewardOwedClaimedWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - σ.find? I.codeOwner |>.option ⟨0⟩ - (fun acc => acc.storage.findD (getRewardOwedRewardsClaimedSlotOf I) ⟨0⟩) - -abbrev getRewardOwedTokenWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) - -abbrev getRewardOwedRescaleWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - rewardConfigRescaleFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) - -abbrev getRewardOwedShouldUpscaleRawWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - rewardConfigShouldUpscaleRawFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) - -abbrev getRewardOwedShouldUpscaleWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - rewardConfigShouldUpscaleFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) - -abbrev getRewardOwedSlot0Load (evm : EVM.State) (I : ExecutionEnv) : UInt256 := - Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (getRewardOwedRewardConfigSlotOf I) - -abbrev getRewardOwedMultiplierLoad (evm : EVM.State) (I : ExecutionEnv) : UInt256 := - Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (getRewardOwedRewardConfigSlotOf I + ⟨1⟩) - -abbrev getRewardOwedClaimedLoad (evm : EVM.State) (I : ExecutionEnv) : UInt256 := - Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (getRewardOwedRewardsClaimedSlotOf I) - -abbrev getRewardOwedTokenValueFromSlot0 (slot0 : UInt256) : Value := - .address (AccountAddress.ofNat (rewardConfigTokenFromSlot0 slot0).toNat) - -abbrev getRewardOwedRescaleValueFromSlot0 (slot0 : UInt256) : Value := - .int (Int.ofNat (rewardConfigRescaleFromSlot0 slot0).toNat) - -abbrev getRewardOwedShouldUpscaleValueFromSlot0 (slot0 : UInt256) : Value := - wordToElem .bool (rewardConfigShouldUpscaleRawFromSlot0 slot0) - -abbrev getRewardOwedMultiplierValue (multiplier : UInt256) : Value := - .int (Int.ofNat multiplier.toNat) - -abbrev getRewardOwedBaseLocals (evm : EVM.State) (I : ExecutionEnv) : Store := - (getRewardOwedStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) - -abbrev getRewardOwedAfterTokenLocals (evm : EVM.State) (I : ExecutionEnv) : Store := - (getRewardOwedBaseLocals evm I).insert "token" - (getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I)) - -abbrev getRewardOwedAfterRescaleLocals (evm : EVM.State) (I : ExecutionEnv) : Store := - (getRewardOwedAfterTokenLocals evm I).insert "rescaleFactor" - (getRewardOwedRescaleValueFromSlot0 (getRewardOwedSlot0Load evm I)) - -abbrev getRewardOwedAfterShouldLocals (evm : EVM.State) (I : ExecutionEnv) : Store := - (getRewardOwedAfterRescaleLocals evm I).insert "shouldUpscale" - (getRewardOwedShouldUpscaleValueFromSlot0 (getRewardOwedSlot0Load evm I)) - -abbrev getRewardOwedConfigLocals (evm : EVM.State) (I : ExecutionEnv) : Store := - (getRewardOwedAfterShouldLocals evm I).insert "multiplier" - (getRewardOwedMultiplierValue (getRewardOwedMultiplierLoad evm I)) - -abbrev getRewardOwedAfterAccrueLocals (evm : EVM.State) (I : ExecutionEnv) : Store := - (getRewardOwedConfigLocals evm I).insert "_accrued" .unit - -abbrev getRewardOwedAfterClaimedLocals - (evm evmAcc : EVM.State) (I : ExecutionEnv) : Store := - (getRewardOwedAfterAccrueLocals evm I).insert "claimed" - (.int (Int.ofNat (getRewardOwedClaimedLoad evmAcc I).toNat)) - -abbrev getRewardOwedAfterInternalLocals - (evm evmAcc : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : Store := - (getRewardOwedAfterClaimedLocals evm evmAcc I).insert "accrued" - (.int (Int.ofNat accruedNat)) - -abbrev getRewardOwedOwedNat (evmAcc : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - ℕ := - if (getRewardOwedClaimedLoad evmAcc I).toNat < accruedNat then - accruedNat - (getRewardOwedClaimedLoad evmAcc I).toNat - else - 0 - -abbrev getRewardOwedAfterOwedLocals - (evm evmAcc : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : Store := - (getRewardOwedAfterInternalLocals evm evmAcc I accruedNat).insert "owed" - (.int (Int.ofNat (getRewardOwedOwedNat evmAcc I accruedNat))) - -abbrev getRewardOwedArgs (I : ExecutionEnv) : List Value := - [getRewardOwedCometValue I, getRewardOwedAccountValue I] - -abbrev getRewardOwedAccrueAccountArgs (I : ExecutionEnv) : List Value := - [getRewardOwedAccountValue I] - -abbrev getRewardOwedCometTarget (I : ExecutionEnv) : AccountAddress := - AccountAddress.ofNat (getRewardOwedCometWord I).toNat - -abbrev getRewardOwedAccrueAccountCallPc : UInt256 := ⟨2450⟩ - -abbrev getRewardOwedAccrueAccountCallSize : UInt256 := ⟨36⟩ - -abbrev getRewardOwedBaseTrackingCallPc : UInt256 := ⟨3723⟩ - -abbrev getRewardOwedBaseTrackingCallSize : UInt256 := ⟨36⟩ - -abbrev getRewardAccruedArgs (I : ExecutionEnv) (slot0 multiplier : UInt256) : - List Value := - [ getRewardOwedCometValue I, - getRewardOwedAccountValue I, - .int (Int.ofNat (rewardConfigRescaleFromSlot0 slot0).toNat), - wordToElem .bool (rewardConfigShouldUpscaleRawFromSlot0 slot0), - .int (Int.ofNat multiplier.toNat) ] - -abbrev getRewardAccruedStore (I : ExecutionEnv) (slot0 multiplier : UInt256) : Store := - (((((∅ : Store).insert "multiplier" (.int (Int.ofNat multiplier.toNat))).insert - "shouldUpscale" (wordToElem .bool (rewardConfigShouldUpscaleRawFromSlot0 slot0))).insert - "rescaleFactor" (.int (Int.ofNat (rewardConfigRescaleFromSlot0 slot0).toNat))).insert - "account" (getRewardOwedAccountValue I)).insert "comet" (getRewardOwedCometValue I) - -abbrev getRewardAccruedBaseTrackingArgs (I : ExecutionEnv) : List Value := - [getRewardOwedAccountValue I] - -abbrev getRewardAccruedAfterBaseLocals - (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) : Store := - (getRewardAccruedStore I slot0 multiplier).insert "accrued" - (.int (Int.ofNat accrued.toNat)) - -abbrev getRewardAccruedAfterBaseFrame - (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) : Frame := - { contract := contract, locals := getRewardAccruedAfterBaseLocals I slot0 multiplier accrued } - -abbrev getRewardAccruedUpscaledNat (slot0 accrued : UInt256) : ℕ := - accrued.toNat * (rewardConfigRescaleFromSlot0 slot0).toNat - -abbrev getRewardAccruedDownscaledNat (slot0 accrued : UInt256) : ℕ := - accrued.toNat / (rewardConfigRescaleFromSlot0 slot0).toNat - -abbrev getRewardAccruedAfterBranchLocals - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accruedNat : ℕ) : Store := - (getRewardAccruedStore I slot0 multiplier).insert "accrued" - (.int (Int.ofNat accruedNat)) - -abbrev getRewardAccruedAfterBranchFrame - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accruedNat : ℕ) : Frame := - { contract := contract, locals := getRewardAccruedAfterBranchLocals I slot0 multiplier accruedNat } - -abbrev getRewardAccruedScaledNat (multiplier : UInt256) (accruedNat : ℕ) : ℕ := - accruedNat * multiplier.toNat - -abbrev getRewardAccruedAfterScaledLocals - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accruedNat : ℕ) : Store := - (getRewardAccruedAfterBranchLocals I slot0 multiplier accruedNat).insert "scaled" - (.int (Int.ofNat (getRewardAccruedScaledNat multiplier accruedNat))) - -abbrev getRewardAccruedAfterScaledFrame - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accruedNat : ℕ) : Frame := - { contract := contract, locals := getRewardAccruedAfterScaledLocals I slot0 multiplier accruedNat } - -abbrev getRewardAccruedReturnNat (multiplier : UInt256) (accruedNat : ℕ) : ℕ := - getRewardAccruedScaledNat multiplier accruedNat / factorScale.toNat - -theorem getRewardAccruedUpscaledNat_lt_size_of_base64 {slot0 accrued : UInt256} - (hacc : accrued.toNat < EVM.twoPow 64) : - getRewardAccruedUpscaledNat slot0 accrued < UInt256.size := by - have haccLt : accrued.toNat < 2 ^ 64 := by - simpa [EVM.twoPow] using hacc - have hresLt : (rewardConfigRescaleFromSlot0 slot0).toNat < 2 ^ 64 := by - simpa [rewardConfigRescaleFromSlot0, EVM.twoPow] using - rewardConfigRescaleWord_lt slot0 - have haccLe : accrued.toNat ≤ 2 ^ 64 - 1 := by omega - have hresLe : (rewardConfigRescaleFromSlot0 slot0).toNat ≤ 2 ^ 64 - 1 := by omega - have hmul : - accrued.toNat * (rewardConfigRescaleFromSlot0 slot0).toNat ≤ - (2 ^ 64 - 1) * (2 ^ 64 - 1) := - Nat.mul_le_mul haccLe hresLe - have hbound : (2 ^ 64 - 1) * (2 ^ 64 - 1) < UInt256.size := by - norm_num [UInt256.size] - exact lt_of_le_of_lt hmul hbound - -theorem u256_land_zero_right (a : UInt256) : UInt256.land a ⟨0⟩ = ⟨0⟩ := by - apply u256_inj - rw [u256_land_toNat] - change Nat.land a.toNat 0 % UInt256.size = 0 - have hland : Nat.land a.toNat 0 = 0 := by - exact Nat.and_zero a.toNat - rw [hland] - rfl - -theorem u256_mul_eq_ofNat_of_lt (a b : UInt256) - (h : a.toNat * b.toNat < UInt256.size) : - UInt256.mul a b = UInt256.ofNat (a.toNat * b.toNat) := by - apply u256_inj - rw [u256_mul_toNat, UInt256.toNat_ofNat_of_lt h, Nat.mod_eq_of_lt h] - -theorem checkedMulOverflowFlag_zero (a b : UInt256) - (h : a.toNat * b.toNat < UInt256.size) : - UInt256.land - (UInt256.gt b (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) a)) - (UInt256.isZero (UInt256.isZero a)) = ⟨0⟩ := by - by_cases ha0 : a = ⟨0⟩ - · have hiz : UInt256.isZero (UInt256.isZero a) = ⟨0⟩ := by - rw [ha0] - native_decide - rw [hiz] - exact u256_land_zero_right _ - · have hmax : (UInt256.lnot (⟨0⟩ : UInt256)).toNat = UInt256.size - 1 := by - unfold UInt256.lnot - decide - have haNatNZ : a.toNat ≠ 0 := by - intro hz - exact ha0 (uint256_toNat_eq_zero hz) - have haPos : 0 < a.toNat := Nat.pos_of_ne_zero haNatNZ - have hmulLe : b.toNat * a.toNat ≤ UInt256.size - 1 := by - rw [Nat.mul_comm] - omega - have hdivLe : - b.toNat ≤ (UInt256.size - 1) / a.toNat := - (Nat.le_div_iff_mul_le haPos).2 hmulLe - have hgt : - UInt256.gt b (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) a) = ⟨0⟩ := by - apply ugt_zero - rw [udiv_toNat, hmax] - exact hdivLe - rw [hgt, u256_land_comm] - exact u256_land_zero_right _ - -theorem checkedMulOverflowFlag_one (a b : UInt256) - (hover : UInt256.size ≤ a.toNat * b.toNat) : - UInt256.land (UInt256.isZero (UInt256.isZero a)) - (UInt256.gt b (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) a)) = ⟨1⟩ := by - have hmax : (UInt256.lnot (⟨0⟩ : UInt256)).toNat = UInt256.size - 1 := by - unfold UInt256.lnot - decide - have haNZ : a ≠ ⟨0⟩ := by - intro hzero - have hto := congrArg UInt256.toNat hzero - rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl] at hto - have hprod : a.toNat * b.toNat = 0 := by - rw [hto] - exact Nat.zero_mul b.toNat - have hpos : 0 < UInt256.size := by norm_num [UInt256.size] - omega - have haNatNZ : a.toNat ≠ 0 := by - intro hz - exact haNZ (uint256_toNat_eq_zero hz) - have haPos : 0 < a.toNat := Nat.pos_of_ne_zero haNatNZ - have hgt : - UInt256.gt b (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) a) = ⟨1⟩ := by - apply ugt_one - rw [udiv_toNat, hmax] - have hltDiv : (UInt256.size - 1) / a.toNat < b.toNat := by - rw [Nat.div_lt_iff_lt_mul haPos] - rw [Nat.mul_comm] - have hpos : 0 < UInt256.size := by norm_num [UInt256.size] - omega - exact hltDiv - have hisz : UInt256.isZero (UInt256.isZero a) = ⟨1⟩ := by - rw [isZero_eq_zero_of_ne haNZ] - native_decide - rw [hisz, hgt] - native_decide - -theorem rewardConfigShouldUpscaleFromSlot0_eq_one_of_raw_ne_zero {slot0 : UInt256} - (h : rewardConfigShouldUpscaleRawFromSlot0 slot0 ≠ ⟨0⟩) : - rewardConfigShouldUpscaleFromSlot0 slot0 = ⟨1⟩ := by - unfold rewardConfigShouldUpscaleFromSlot0 - rw [isZero_eq_zero_of_ne h] - native_decide - -theorem rewardConfigShouldUpscaleFromSlot0_eq_zero_of_raw_zero {slot0 : UInt256} - (h : rewardConfigShouldUpscaleRawFromSlot0 slot0 = ⟨0⟩) : - rewardConfigShouldUpscaleFromSlot0 slot0 = ⟨0⟩ := by - unfold rewardConfigShouldUpscaleFromSlot0 - rw [h] - native_decide - -theorem u256_div_factorScale_ofNat {n : ℕ} (hn : n < UInt256.size) : - UInt256.div (UInt256.ofNat n) (⟨1000000000000000000⟩ : UInt256) = - UInt256.ofNat (n / factorScale.toNat) := by - have hfactor : - (⟨1000000000000000000⟩ : UInt256).toNat = factorScale.toNat := by - native_decide - have hretLt : n / factorScale.toNat < UInt256.size := by - exact lt_of_le_of_lt (Nat.div_le_self n factorScale.toNat) hn - apply u256_inj - rw [udiv_toNat, UInt256.toNat_ofNat_of_lt hn, hfactor, - UInt256.toNat_ofNat_of_lt hretLt] - -theorem u256_div_eq_ofNat (a b : UInt256) : - UInt256.div a b = UInt256.ofNat (a.toNat / b.toNat) := by - have hlt : a.toNat / b.toNat < UInt256.size := - lt_of_le_of_lt (Nat.div_le_self a.toNat b.toNat) a.val.isLt - apply u256_inj - rw [udiv_toNat, UInt256.toNat_ofNat_of_lt hlt] - -abbrev getRewardAccruedAfterAssignedLocals - (I : ExecutionEnv) (slot0 multiplier oldAccrued : UInt256) (accruedNat : ℕ) : - Store := - (getRewardAccruedAfterBaseLocals I slot0 multiplier oldAccrued).insert "accrued" - (.int (Int.ofNat accruedNat)) - -abbrev getRewardAccruedAfterAssignedFrame - (I : ExecutionEnv) (slot0 multiplier oldAccrued : UInt256) (accruedNat : ℕ) : - Frame := - { contract := contract, - locals := getRewardAccruedAfterAssignedLocals I slot0 multiplier oldAccrued accruedNat } - -abbrev getRewardAccruedAfterAssignedScaledLocals - (I : ExecutionEnv) (slot0 multiplier oldAccrued : UInt256) (accruedNat : ℕ) : - Store := - (getRewardAccruedAfterAssignedLocals I slot0 multiplier oldAccrued accruedNat).insert - "scaled" (.int (Int.ofNat (getRewardAccruedScaledNat multiplier accruedNat))) - -abbrev getRewardAccruedAfterAssignedScaledFrame - (I : ExecutionEnv) (slot0 multiplier oldAccrued : UInt256) (accruedNat : ℕ) : - Frame := - { contract := contract, - locals := getRewardAccruedAfterAssignedScaledLocals I slot0 multiplier oldAccrued accruedNat } - -theorem getRewardOwedStore_comet (I : ExecutionEnv) : - (getRewardOwedStore I).get? "comet" = some (getRewardOwedCometValue I) := by - rw [getRewardOwedStore, store_get_ne _ _ (by decide), store_get_self] - -theorem getRewardOwedStore_account (I : ExecutionEnv) : - (getRewardOwedStore I).get? "account" = some (getRewardOwedAccountValue I) := by - rw [getRewardOwedStore, store_get_self] - -theorem getRewardOwedFrame_comet (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedFrame evm I).locals.get? "comet" = some (getRewardOwedCometValue I) := by - rw [getRewardOwedFrame] - rw [store_get_ne _ _ (by decide), getRewardOwedStore_comet] - -theorem getRewardOwedFrame_account (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedFrame evm I).locals.get? "account" = - some (getRewardOwedAccountValue I) := by - rw [getRewardOwedFrame] - rw [store_get_ne _ _ (by decide), getRewardOwedStore_account] - -theorem getRewardOwedFrame_no_rewardConfig (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedFrame evm I).locals.get? "rewardConfig" = none := by - rw [getRewardOwedFrame] - rw [store_get_ne _ _ (by decide)] - rw [getRewardOwedStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - simp - -theorem getRewardOwedFrame_no_rewardsClaimed (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedFrame evm I).locals.get? "rewardsClaimed" = none := by - rw [getRewardOwedFrame] - rw [store_get_ne _ _ (by decide)] - rw [getRewardOwedStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - simp - -theorem evalExpr_getRewardOwed_comet_of {locals : Store} (evm : EVM.State) - (I : ExecutionEnv) - (hcomet : locals.get? "comet" = some (getRewardOwedCometValue I)) : - evalExpr? config { contract := contract, locals := locals } evm (.var "comet") = - .ok (getRewardOwedCometValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hcomet] - -theorem evalExpr_getRewardOwed_account_of {locals : Store} (evm : EVM.State) - (I : ExecutionEnv) - (haccount : locals.get? "account" = some (getRewardOwedAccountValue I)) : - evalExpr? config { contract := contract, locals := locals } evm (.var "account") = - .ok (getRewardOwedAccountValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [haccount] - -theorem evalExprs_getRewardOwed_args_of {locals : Store} (evm : EVM.State) - (I : ExecutionEnv) - (hcomet : locals.get? "comet" = some (getRewardOwedCometValue I)) - (haccount : locals.get? "account" = some (getRewardOwedAccountValue I)) : - evalExprs? config { contract := contract, locals := locals } evm - [.var "comet", .var "account"] = .ok (getRewardOwedArgs I) := by - simp only [getRewardOwedArgs, evalExprs?, evalExpr_getRewardOwed_comet_of evm I hcomet, - evalExpr_getRewardOwed_account_of evm I haccount, EvalResult.bind, bind] - rfl - -theorem evalExprs_getRewardOwed_accrueAccountArgs_of {locals : Store} (evm : EVM.State) - (I : ExecutionEnv) - (haccount : locals.get? "account" = some (getRewardOwedAccountValue I)) : - evalExprs? config { contract := contract, locals := locals } evm [.var "account"] = - .ok (getRewardOwedAccrueAccountArgs I) := by - simp only [getRewardOwedAccrueAccountArgs, evalExprs?, - evalExpr_getRewardOwed_account_of evm I haccount, EvalResult.bind, bind] - rfl - -theorem evalStorageRef_getRewardOwed_rewardConfig_field_of {locals : Store} - (evm : EVM.State) (I : ExecutionEnv) (field : Ident) - (hcomet : locals.get? "comet" = some (getRewardOwedCometValue I)) : - evalStorageRef config { contract := contract, locals := locals } evm - (rewardConfigF (.var "comet") field) = - .ok { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (getRewardOwedCometWord I).toNat)), .field field] } := by - simp only [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, rewardConfigF, - evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, valueToKey?, - Std.HashMap.get?_eq_getElem?] - rw [← Std.HashMap.get?_eq_getElem?, hcomet] - -theorem evalExpr_getRewardOwed_token_of {locals : Store} (evm : EVM.State) - (I : ExecutionEnv) - (hcomet : locals.get? "comet" = some (getRewardOwedCometValue I)) - (hbase : locals.get? "rewardConfig" = none) : - evalExpr? config { contract := contract, locals := locals } evm - (.storage (rewardConfigF (.var "comet") "token")) = - .ok (.address (AccountAddress.ofNat - (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (getRewardOwedRewardConfigSlotOf I)) - solcAddrMask).toNat)) := by - have her := evalStorageRef_getRewardOwed_rewardConfig_field_of evm I "token" hcomet - have hty : storageTypeAt? contract.storage - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (getRewardOwedCometWord I).toNat)), - .field "token"] } = - some (.elem .address) := by - simp [storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (getRewardOwedCometWord I).toNat)), - .field "token"] } = - fun _ => some (fieldLoc (slotAdd (getRewardOwedRewardConfigSlotOf I) 0) 0 20 - (by decide) .address) := by - rfl - rw [evalExpr_storage_scalar (hbase := hbase) (her := her) (hty := hty) (hloc := hloc)] - congr 1 - rw [slotAdd_zero] - exact cometRewardsStorageLocLoad_address_offset0 evm (getRewardOwedRewardConfigSlotOf I) - -theorem evalExpr_getRewardOwed_rescale_of {locals : Store} (evm : EVM.State) - (I : ExecutionEnv) - (hcomet : locals.get? "comet" = some (getRewardOwedCometValue I)) - (hbase : locals.get? "rewardConfig" = none) : - evalExpr? config { contract := contract, locals := locals } evm - (.storage (rewardConfigF (.var "comet") "rescaleFactor")) = - .ok (.int (Int.ofNat - (UInt256.land - (UInt256.shiftRight - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (getRewardOwedRewardConfigSlotOf I)) - ⟨160⟩) - (UInt256.ofNat (2 ^ 64 - 1))).toNat)) := by - have her := evalStorageRef_getRewardOwed_rewardConfig_field_of evm I "rescaleFactor" hcomet - have hty : storageTypeAt? contract.storage - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (getRewardOwedCometWord I).toNat)), - .field "rescaleFactor"] } = - some (.elem (.int uint64Int)) := by - simp [storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (getRewardOwedCometWord I).toNat)), - .field "rescaleFactor"] } = - fun _ => some (fieldLoc (slotAdd (getRewardOwedRewardConfigSlotOf I) 0) 20 8 - (by decide) (.int uint64Int)) := by - rfl - rw [evalExpr_storage_scalar (hbase := hbase) (her := her) (hty := hty) (hloc := hloc)] - congr 1 - rw [slotAdd_zero] - exact cometRewardsStorageLocLoad_uint64_offset20 evm (getRewardOwedRewardConfigSlotOf I) - -theorem evalExpr_getRewardOwed_shouldUpscale_of {locals : Store} (evm : EVM.State) - (I : ExecutionEnv) - (hcomet : locals.get? "comet" = some (getRewardOwedCometValue I)) - (hbase : locals.get? "rewardConfig" = none) : - evalExpr? config { contract := contract, locals := locals } evm - (.storage (rewardConfigF (.var "comet") "shouldUpscale")) = - .ok (wordToElem .bool - (UInt256.land - (UInt256.shiftRight - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (getRewardOwedRewardConfigSlotOf I)) - ⟨224⟩) - ⟨255⟩)) := by - have her := evalStorageRef_getRewardOwed_rewardConfig_field_of evm I "shouldUpscale" hcomet - have hty : storageTypeAt? contract.storage - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (getRewardOwedCometWord I).toNat)), - .field "shouldUpscale"] } = - some (.elem .bool) := by - simp [storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (getRewardOwedCometWord I).toNat)), - .field "shouldUpscale"] } = - fun _ => some (fieldLoc (slotAdd (getRewardOwedRewardConfigSlotOf I) 0) 28 1 - (by decide) .bool) := by - rfl - rw [evalExpr_storage_scalar (hbase := hbase) (her := her) (hty := hty) (hloc := hloc)] - congr 1 - rw [slotAdd_zero] - exact cometRewardsStorageLocLoad_bool_offset28 evm (getRewardOwedRewardConfigSlotOf I) - -theorem evalExpr_getRewardOwed_multiplier_of {locals : Store} (evm : EVM.State) - (I : ExecutionEnv) - (hcomet : locals.get? "comet" = some (getRewardOwedCometValue I)) - (hbase : locals.get? "rewardConfig" = none) : - evalExpr? config { contract := contract, locals := locals } evm - (.storage (rewardConfigF (.var "comet") "multiplier")) = - .ok (.int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (getRewardOwedRewardConfigSlotOf I + ⟨1⟩)).toNat)) := by - have her := evalStorageRef_getRewardOwed_rewardConfig_field_of evm I "multiplier" hcomet - have hty : storageTypeAt? contract.storage - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (getRewardOwedCometWord I).toNat)), - .field "multiplier"] } = - some (.elem (.int uint256Int)) := by - simp [storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (getRewardOwedCometWord I).toNat)), - .field "multiplier"] } = - fun _ => some (fieldLoc (slotAdd (getRewardOwedRewardConfigSlotOf I) 1) 0 32 - (by decide) (.int uint256Int)) := by - rfl - rw [evalExpr_storage_scalar (hbase := hbase) (her := her) (hty := hty) (hloc := hloc)] - congr 1 - rw [slotAdd_one] - rw [cometRewardsStorageLocLoad_uint256] - -theorem evalStorageRef_getRewardOwed_rewardsClaimed_of {locals : Store} - (evm : EVM.State) (I : ExecutionEnv) - (hcomet : locals.get? "comet" = some (getRewardOwedCometValue I)) - (haccount : locals.get? "account" = some (getRewardOwedAccountValue I)) : - evalStorageRef config { contract := contract, locals := locals } evm - (rewardsClaimedRef (.var "comet") (.var "account")) = - .ok { base := "rewardsClaimed", - steps := [.mindex (.address (AccountAddress.ofNat - (getRewardOwedCometWord I).toNat)), - .mindex (.address (AccountAddress.ofNat - (getRewardOwedAccountWord I).toNat))] } := by - simp only [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, rewardsClaimedRef, - evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, valueToKey?, - Std.HashMap.get?_eq_getElem?] - rw [← Std.HashMap.get?_eq_getElem?, hcomet] - rw [← Std.HashMap.get?_eq_getElem?, haccount] - -theorem evalExpr_getRewardOwed_claimed_of {locals : Store} (evm : EVM.State) - (I : ExecutionEnv) - (hcomet : locals.get? "comet" = some (getRewardOwedCometValue I)) - (haccount : locals.get? "account" = some (getRewardOwedAccountValue I)) - (hbase : locals.get? "rewardsClaimed" = none) : - evalExpr? config { contract := contract, locals := locals } evm - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))) = - .ok (.int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (getRewardOwedRewardsClaimedSlotOf I)).toNat)) := by - have her := evalStorageRef_getRewardOwed_rewardsClaimed_of evm I hcomet haccount - have hty : storageTypeAt? contract.storage - { base := "rewardsClaimed", - steps := [.mindex (.address (AccountAddress.ofNat (getRewardOwedCometWord I).toNat)), - .mindex (.address (AccountAddress.ofNat - (getRewardOwedAccountWord I).toNat))] } = - some (.elem (.int uint256Int)) := by - simp [storageTypeAt?, contract, storageDecls, List.find?, List.foldlM, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardsClaimed", - steps := [.mindex (.address (AccountAddress.ofNat (getRewardOwedCometWord I).toNat)), - .mindex (.address (AccountAddress.ofNat - (getRewardOwedAccountWord I).toNat))] } = - fun _ => some (fieldLoc (getRewardOwedRewardsClaimedSlotOf I) 0 32 - (by decide) (.int uint256Int)) := by - rfl - rw [evalExpr_storage_scalar (hbase := hbase) (her := her) (hty := hty) (hloc := hloc)] - congr 1 - exact cometRewardsStorageLocLoad_uint256 evm (getRewardOwedRewardsClaimedSlotOf I) - -theorem getRewardOwedAccountAddress_ofNat_masked_ne_zero_of_ne (w : UInt256) - (h : UInt256.land w solcAddrMask ≠ ⟨0⟩) : - AccountAddress.ofNat (UInt256.land w solcAddrMask).toNat ≠ AccountAddress.ofNat 0 := by - intro haddr - apply h - apply u256_inj - have hval := congrArg (fun a : AccountAddress => a.val) haddr - have hcanon := solcAddrMask_result_canonical w - have hmod : - (UInt256.land w solcAddrMask).toNat % AccountAddress.size = - (UInt256.land w solcAddrMask).toNat := by - exact Nat.mod_eq_of_lt (by - simpa [EVM.addressModulus, EVM.twoPow, AccountAddress.size] using hcanon) - simp [AccountAddress.ofNat, hmod] at hval - simpa [UInt256.toNat] using hval - -theorem evalExpr_getRewardOwed_zeroAddr_of {locals : Store} (evm : EVM.State) : - evalExpr? config { contract := contract, locals := locals } evm zeroAddr = - .ok (.address (AccountAddress.ofNat 0)) := by - simp [zeroAddr, addrSt, evalExpr?, castValue?, EvalResult.bind, EvalResult.ofOption, - pure, bind] - -theorem evalExpr_getRewardOwed_token_ne_zero_true_of {locals : Store} - (evm : EVM.State) (slot0 : UInt256) - (htoken : - locals.get? "token" = some (getRewardOwedTokenValueFromSlot0 slot0)) - (hnz : rewardConfigTokenFromSlot0 slot0 ≠ ⟨0⟩) : - evalExpr? config { contract := contract, locals := locals } evm - (.binary .ne (.var "token") zeroAddr) = .ok (.bool true) := by - simp only [evalExpr?, EvalResult.bind, EvalResult.ofOption, htoken, - evalExpr_getRewardOwed_zeroAddr_of, bind, evalBinaryOp?] - have haddr := getRewardOwedAccountAddress_ofNat_masked_ne_zero_of_ne slot0 hnz - rw [show ((getRewardOwedTokenValueFromSlot0 slot0 : Value) == - .address (AccountAddress.ofNat 0)) = false by - simp [getRewardOwedTokenValueFromSlot0, rewardConfigTokenFromSlot0, BEq.beq, haddr]] - rfl - -theorem evalExpr_getRewardOwed_token_ne_zero_false_of {locals : Store} - (evm : EVM.State) (slot0 : UInt256) - (htoken : - locals.get? "token" = some (getRewardOwedTokenValueFromSlot0 slot0)) - (hz : rewardConfigTokenFromSlot0 slot0 = ⟨0⟩) : - evalExpr? config { contract := contract, locals := locals } evm - (.binary .ne (.var "token") zeroAddr) = .ok (.bool false) := by - simp only [evalExpr?, EvalResult.bind, EvalResult.ofOption, htoken, - evalExpr_getRewardOwed_zeroAddr_of, bind, evalBinaryOp?] - simp [getRewardOwedTokenValueFromSlot0, rewardConfigTokenFromSlot0, BEq.beq, hz] - -theorem getRewardOwedAfterTokenLocals_comet (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterTokenLocals evm I).get? "comet" = - some (getRewardOwedCometValue I) := by - rw [getRewardOwedAfterTokenLocals, getRewardOwedBaseLocals] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), getRewardOwedStore_comet] - -theorem getRewardOwedAfterTokenLocals_no_rewardConfig (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterTokenLocals evm I).get? "rewardConfig" = none := by - rw [getRewardOwedAfterTokenLocals, getRewardOwedBaseLocals] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - rw [getRewardOwedStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - simp - -theorem getRewardOwedAfterRescaleLocals_comet (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterRescaleLocals evm I).get? "comet" = - some (getRewardOwedCometValue I) := by - rw [getRewardOwedAfterRescaleLocals, store_get_ne _ _ (by decide), - getRewardOwedAfterTokenLocals_comet] - -theorem getRewardOwedAfterRescaleLocals_no_rewardConfig (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterRescaleLocals evm I).get? "rewardConfig" = none := by - rw [getRewardOwedAfterRescaleLocals, store_get_ne _ _ (by decide), - getRewardOwedAfterTokenLocals_no_rewardConfig] - -theorem getRewardOwedAfterShouldLocals_comet (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterShouldLocals evm I).get? "comet" = - some (getRewardOwedCometValue I) := by - rw [getRewardOwedAfterShouldLocals, store_get_ne _ _ (by decide), - getRewardOwedAfterRescaleLocals_comet] - -theorem getRewardOwedAfterShouldLocals_no_rewardConfig (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterShouldLocals evm I).get? "rewardConfig" = none := by - rw [getRewardOwedAfterShouldLocals, store_get_ne _ _ (by decide), - getRewardOwedAfterRescaleLocals_no_rewardConfig] - -theorem getRewardOwedConfigLocals_comet (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedConfigLocals evm I).get? "comet" = - some (getRewardOwedCometValue I) := by - rw [getRewardOwedConfigLocals, getRewardOwedAfterShouldLocals, - getRewardOwedAfterRescaleLocals, getRewardOwedAfterTokenLocals, - getRewardOwedBaseLocals] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), getRewardOwedStore_comet] - -theorem getRewardOwedConfigLocals_account (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedConfigLocals evm I).get? "account" = - some (getRewardOwedAccountValue I) := by - rw [getRewardOwedConfigLocals, getRewardOwedAfterShouldLocals, - getRewardOwedAfterRescaleLocals, getRewardOwedAfterTokenLocals, - getRewardOwedBaseLocals] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), getRewardOwedStore_account] - -theorem getRewardOwedConfigLocals_token (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedConfigLocals evm I).get? "token" = - some (getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [getRewardOwedConfigLocals, getRewardOwedAfterShouldLocals, - getRewardOwedAfterRescaleLocals, getRewardOwedAfterTokenLocals] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_self] - -theorem getRewardOwedConfigLocals_rescaleFactor (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedConfigLocals evm I).get? "rescaleFactor" = - some (getRewardOwedRescaleValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [getRewardOwedConfigLocals, getRewardOwedAfterShouldLocals, - getRewardOwedAfterRescaleLocals] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), store_get_self] - -theorem getRewardOwedConfigLocals_shouldUpscale (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedConfigLocals evm I).get? "shouldUpscale" = - some (getRewardOwedShouldUpscaleValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [getRewardOwedConfigLocals, getRewardOwedAfterShouldLocals] - rw [store_get_ne _ _ (by decide), store_get_self] - -theorem getRewardOwedConfigLocals_multiplier (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedConfigLocals evm I).get? "multiplier" = - some (getRewardOwedMultiplierValue (getRewardOwedMultiplierLoad evm I)) := by - rw [getRewardOwedConfigLocals, store_get_self] - -theorem getRewardOwedConfigLocals_no_rewardsClaimed (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedConfigLocals evm I).get? "rewardsClaimed" = none := by - rw [getRewardOwedConfigLocals, getRewardOwedAfterShouldLocals, - getRewardOwedAfterRescaleLocals, getRewardOwedAfterTokenLocals, - getRewardOwedBaseLocals] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide)] - rw [getRewardOwedStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - simp - -theorem getRewardOwedAfterAccrueLocals_comet (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterAccrueLocals evm I).get? "comet" = - some (getRewardOwedCometValue I) := by - rw [getRewardOwedAfterAccrueLocals, store_get_ne _ _ (by decide), - getRewardOwedConfigLocals_comet] - -theorem getRewardOwedAfterAccrueLocals_account (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterAccrueLocals evm I).get? "account" = - some (getRewardOwedAccountValue I) := by - rw [getRewardOwedAfterAccrueLocals, store_get_ne _ _ (by decide), - getRewardOwedConfigLocals_account] - -theorem getRewardOwedAfterAccrueLocals_no_rewardsClaimed - (evm : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterAccrueLocals evm I).get? "rewardsClaimed" = none := by - rw [getRewardOwedAfterAccrueLocals, store_get_ne _ _ (by decide), - getRewardOwedConfigLocals_no_rewardsClaimed] - -theorem getRewardOwedAfterClaimedLocals_comet - (evm evmAcc : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterClaimedLocals evm evmAcc I).get? "comet" = - some (getRewardOwedCometValue I) := by - rw [getRewardOwedAfterClaimedLocals, store_get_ne _ _ (by decide), - getRewardOwedAfterAccrueLocals_comet] - -theorem getRewardOwedAfterClaimedLocals_account - (evm evmAcc : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterClaimedLocals evm evmAcc I).get? "account" = - some (getRewardOwedAccountValue I) := by - rw [getRewardOwedAfterClaimedLocals, store_get_ne _ _ (by decide), - getRewardOwedAfterAccrueLocals_account] - -theorem getRewardOwedAfterClaimedLocals_rescaleFactor - (evm evmAcc : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterClaimedLocals evm evmAcc I).get? "rescaleFactor" = - some (getRewardOwedRescaleValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [getRewardOwedAfterClaimedLocals, getRewardOwedAfterAccrueLocals, - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - getRewardOwedConfigLocals_rescaleFactor] - -theorem getRewardOwedAfterClaimedLocals_shouldUpscale - (evm evmAcc : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterClaimedLocals evm evmAcc I).get? "shouldUpscale" = - some (getRewardOwedShouldUpscaleValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [getRewardOwedAfterClaimedLocals, getRewardOwedAfterAccrueLocals, - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - getRewardOwedConfigLocals_shouldUpscale] - -theorem getRewardOwedAfterClaimedLocals_multiplier - (evm evmAcc : EVM.State) (I : ExecutionEnv) : - (getRewardOwedAfterClaimedLocals evm evmAcc I).get? "multiplier" = - some (getRewardOwedMultiplierValue (getRewardOwedMultiplierLoad evm I)) := by - rw [getRewardOwedAfterClaimedLocals, getRewardOwedAfterAccrueLocals, - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - getRewardOwedConfigLocals_multiplier] - -theorem getRewardOwedAfterInternalLocals_token - (evm evmAcc : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (getRewardOwedAfterInternalLocals evm evmAcc I accruedNat).get? "token" = - some (getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [getRewardOwedAfterInternalLocals, getRewardOwedAfterClaimedLocals, - getRewardOwedAfterAccrueLocals, store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - getRewardOwedConfigLocals_token] - -theorem getRewardOwedAfterInternalLocals_accrued - (evm evmAcc : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (getRewardOwedAfterInternalLocals evm evmAcc I accruedNat).get? "accrued" = - some (.int (Int.ofNat accruedNat)) := by - rw [getRewardOwedAfterInternalLocals, store_get_self] - -theorem getRewardOwedAfterInternalLocals_claimed - (evm evmAcc : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (getRewardOwedAfterInternalLocals evm evmAcc I accruedNat).get? "claimed" = - some (.int (Int.ofNat (getRewardOwedClaimedLoad evmAcc I).toNat)) := by - rw [getRewardOwedAfterInternalLocals, store_get_ne _ _ (by decide), - getRewardOwedAfterClaimedLocals, store_get_self] - -theorem getRewardOwedAfterOwedLocals_token - (evm evmAcc : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (getRewardOwedAfterOwedLocals evm evmAcc I accruedNat).get? "token" = - some (getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I)) := by - rw [getRewardOwedAfterOwedLocals, store_get_ne _ _ (by decide), - getRewardOwedAfterInternalLocals_token] - -theorem getRewardOwedAfterOwedLocals_owed - (evm evmAcc : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - (getRewardOwedAfterOwedLocals evm evmAcc I accruedNat).get? "owed" = - some (.int (Int.ofNat (getRewardOwedOwedNat evmAcc I accruedNat))) := by - rw [getRewardOwedAfterOwedLocals, store_get_self] - -theorem getRewardAccruedStore_comet (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (getRewardAccruedStore I slot0 multiplier).get? "comet" = - some (getRewardOwedCometValue I) := by - rw [getRewardAccruedStore, store_get_self] - -theorem getRewardAccruedStore_account (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (getRewardAccruedStore I slot0 multiplier).get? "account" = - some (getRewardOwedAccountValue I) := by - rw [getRewardAccruedStore, store_get_ne _ _ (by decide), store_get_self] - -theorem getRewardAccruedStore_rescaleFactor (I : ExecutionEnv) - (slot0 multiplier : UInt256) : - (getRewardAccruedStore I slot0 multiplier).get? "rescaleFactor" = - some (.int (Int.ofNat (rewardConfigRescaleFromSlot0 slot0).toNat)) := by - rw [getRewardAccruedStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_self] - -theorem getRewardAccruedStore_shouldUpscale (I : ExecutionEnv) - (slot0 multiplier : UInt256) : - (getRewardAccruedStore I slot0 multiplier).get? "shouldUpscale" = - some (wordToElem .bool (rewardConfigShouldUpscaleRawFromSlot0 slot0)) := by - rw [getRewardAccruedStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_self] - -theorem getRewardAccruedStore_multiplier (I : ExecutionEnv) - (slot0 multiplier : UInt256) : - (getRewardAccruedStore I slot0 multiplier).get? "multiplier" = - some (.int (Int.ofNat multiplier.toNat)) := by - rw [getRewardAccruedStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), store_get_self] - -theorem getRewardAccruedAfterBaseLocals_accrued - (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) : - (getRewardAccruedAfterBaseLocals I slot0 multiplier accrued).get? "accrued" = - some (.int (Int.ofNat accrued.toNat)) := by - rw [getRewardAccruedAfterBaseLocals, store_get_self] - -theorem getRewardAccruedAfterBaseLocals_rescaleFactor - (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) : - (getRewardAccruedAfterBaseLocals I slot0 multiplier accrued).get? "rescaleFactor" = - some (.int (Int.ofNat (rewardConfigRescaleFromSlot0 slot0).toNat)) := by - rw [getRewardAccruedAfterBaseLocals, store_get_ne _ _ (by decide), - getRewardAccruedStore_rescaleFactor] - -theorem getRewardAccruedAfterBaseLocals_shouldUpscale - (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) : - (getRewardAccruedAfterBaseLocals I slot0 multiplier accrued).get? "shouldUpscale" = - some (wordToElem .bool (rewardConfigShouldUpscaleRawFromSlot0 slot0)) := by - rw [getRewardAccruedAfterBaseLocals, store_get_ne _ _ (by decide), - getRewardAccruedStore_shouldUpscale] - -theorem getRewardAccruedAfterBaseLocals_multiplier - (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) : - (getRewardAccruedAfterBaseLocals I slot0 multiplier accrued).get? "multiplier" = - some (.int (Int.ofNat multiplier.toNat)) := by - rw [getRewardAccruedAfterBaseLocals, store_get_ne _ _ (by decide), - getRewardAccruedStore_multiplier] - -theorem getRewardAccruedAfterBranchLocals_accrued - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accruedNat : ℕ) : - (getRewardAccruedAfterBranchLocals I slot0 multiplier accruedNat).get? "accrued" = - some (.int (Int.ofNat accruedNat)) := by - rw [getRewardAccruedAfterBranchLocals, store_get_self] - -theorem getRewardAccruedAfterBranchLocals_multiplier - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accruedNat : ℕ) : - (getRewardAccruedAfterBranchLocals I slot0 multiplier accruedNat).get? "multiplier" = - some (.int (Int.ofNat multiplier.toNat)) := by - rw [getRewardAccruedAfterBranchLocals, store_get_ne _ _ (by decide), - getRewardAccruedStore_multiplier] - -theorem getRewardAccruedAfterScaledLocals_scaled - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accruedNat : ℕ) : - (getRewardAccruedAfterScaledLocals I slot0 multiplier accruedNat).get? "scaled" = - some (.int (Int.ofNat (getRewardAccruedScaledNat multiplier accruedNat))) := by - rw [getRewardAccruedAfterScaledLocals, store_get_self] - -theorem getRewardAccruedAfterAssignedLocals_accrued - (I : ExecutionEnv) (slot0 multiplier oldAccrued : UInt256) (accruedNat : ℕ) : - (getRewardAccruedAfterAssignedLocals I slot0 multiplier oldAccrued accruedNat).get? - "accrued" = some (.int (Int.ofNat accruedNat)) := by - rw [getRewardAccruedAfterAssignedLocals, store_get_self] - -theorem getRewardAccruedAfterAssignedLocals_multiplier - (I : ExecutionEnv) (slot0 multiplier oldAccrued : UInt256) (accruedNat : ℕ) : - (getRewardAccruedAfterAssignedLocals I slot0 multiplier oldAccrued accruedNat).get? - "multiplier" = some (.int (Int.ofNat multiplier.toNat)) := by - rw [getRewardAccruedAfterAssignedLocals, store_get_ne _ _ (by decide), - getRewardAccruedAfterBaseLocals_multiplier] - -theorem getRewardAccruedAfterAssignedScaledLocals_scaled - (I : ExecutionEnv) (slot0 multiplier oldAccrued : UInt256) (accruedNat : ℕ) : - (getRewardAccruedAfterAssignedScaledLocals I slot0 multiplier oldAccrued accruedNat).get? - "scaled" = - some (.int (Int.ofNat (getRewardAccruedScaledNat multiplier accruedNat))) := by - rw [getRewardAccruedAfterAssignedScaledLocals, store_get_self] - -theorem bindParams_getRewardAccrued (I : ExecutionEnv) (slot0 multiplier : UInt256) : - bindParams? getRewardAccruedFunction.params (getRewardAccruedArgs I slot0 multiplier) = - some (getRewardAccruedStore I slot0 multiplier) := by - simp [getRewardAccruedFunction, getRewardAccruedArgs, getRewardAccruedStore, bindParams?] - -theorem lookupCallable_getRewardAccrued : - lookupCallable? contract "getRewardAccrued" = - some getRewardAccruedFunction.toCallable := by - rfl - -theorem evalExprs_getRewardAccrued_args_of {locals : Store} (evm : EVM.State) - (I : ExecutionEnv) (slot0 multiplier : UInt256) - (hcomet : locals.get? "comet" = some (getRewardOwedCometValue I)) - (haccount : locals.get? "account" = some (getRewardOwedAccountValue I)) - (hrescale : - locals.get? "rescaleFactor" = - some (.int (Int.ofNat (rewardConfigRescaleFromSlot0 slot0).toNat))) - (hshould : - locals.get? "shouldUpscale" = - some (wordToElem .bool (rewardConfigShouldUpscaleRawFromSlot0 slot0))) - (hmult : locals.get? "multiplier" = some (.int (Int.ofNat multiplier.toNat))) : - evalExprs? config { contract := contract, locals := locals } evm - [.var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"] = - .ok (getRewardAccruedArgs I slot0 multiplier) := by - simp only [getRewardAccruedArgs, evalExprs?, - evalExpr_getRewardOwed_comet_of evm I hcomet, - evalExpr_getRewardOwed_account_of evm I haccount, EvalResult.bind, bind, - evalExpr?, EvalResult.ofOption] - rw [hrescale, hshould, hmult] - rfl - -theorem evalExprs_getRewardAccrued_baseTrackingArgs (evm : EVM.State) - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - evalExprs? config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } - evm [.var "account"] = .ok (getRewardAccruedBaseTrackingArgs I) := by - simp only [getRewardAccruedBaseTrackingArgs, evalExprs?, - evalExpr_getRewardOwed_account_of evm I - (getRewardAccruedStore_account I slot0 multiplier), EvalResult.bind, bind] - rfl - -theorem evalExpr_getRewardAccrued_shouldUpscale_true (evm : EVM.State) - (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) - (htrue : rewardConfigShouldUpscaleRawFromSlot0 slot0 ≠ ⟨0⟩) : - evalExpr? config (getRewardAccruedAfterBaseFrame I slot0 multiplier accrued) evm - (.var "shouldUpscale") = .ok (.bool true) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getRewardAccruedAfterBaseLocals_shouldUpscale] - simp [wordToElem] - intro hz - apply htrue - apply u256_inj - simpa [UInt256.toNat] using hz - -theorem evalExpr_getRewardAccrued_shouldUpscale_false (evm : EVM.State) - (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) - (hfalse : rewardConfigShouldUpscaleRawFromSlot0 slot0 = ⟨0⟩) : - evalExpr? config (getRewardAccruedAfterBaseFrame I slot0 multiplier accrued) evm - (.var "shouldUpscale") = .ok (.bool false) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getRewardAccruedAfterBaseLocals_shouldUpscale] - simp [wordToElem, hfalse] - -theorem evalExpr_getRewardAccrued_upscaled (evm : EVM.State) - (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) - (hup : getRewardAccruedUpscaledNat slot0 accrued < UInt256.size) : - evalExpr? config (getRewardAccruedAfterBaseFrame I slot0 multiplier accrued) evm - (u256 (.binary .mul (.var "accrued") (.var "rescaleFactor"))) = - .ok (.int (Int.ofNat (getRewardAccruedUpscaledNat slot0 accrued))) := by - simp only [u256, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [getRewardAccruedAfterBaseLocals_accrued, - getRewardAccruedAfterBaseLocals_rescaleFactor] - simp only [evalBinaryOp?, getRewardAccruedUpscaledNat] - have hnonneg : - ¬ (↑accrued.toNat * ↑(rewardConfigRescaleFromSlot0 slot0).toNat : Int) < 0 := by - rw [show (↑accrued.toNat * ↑(rewardConfigRescaleFromSlot0 slot0).toNat : Int) = - ↑(accrued.toNat * (rewardConfigRescaleFromSlot0 slot0).toNat) by norm_num] - omega - have hltInt : - ¬ (115792089237316195423570985008687907853269984665640564039457584007913129639936 : Int) ≤ - (↑accrued.toNat * ↑(rewardConfigRescaleFromSlot0 slot0).toNat : Int) := by - rw [show (↑accrued.toNat * ↑(rewardConfigRescaleFromSlot0 slot0).toNat : Int) = - ↑(accrued.toNat * (rewardConfigRescaleFromSlot0 slot0).toNat) by norm_num] - intro hle - have hleNat : UInt256.size ≤ accrued.toNat * (rewardConfigRescaleFromSlot0 slot0).toNat := by - norm_num [UInt256.size] - exact_mod_cast hle - exact (Nat.not_le_of_gt hup) hleNat - simpa [uint256Int, hnonneg, hltInt, pure] - -theorem evalExpr_getRewardAccrued_downscaled (evm : EVM.State) - (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) - (hrescaleNZ : rewardConfigRescaleFromSlot0 slot0 ≠ ⟨0⟩) : - evalExpr? config (getRewardAccruedAfterBaseFrame I slot0 multiplier accrued) evm - (.binary .div (.var "accrued") (.var "rescaleFactor")) = - .ok (.int (Int.ofNat (getRewardAccruedDownscaledNat slot0 accrued))) := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [getRewardAccruedAfterBaseLocals_accrued, - getRewardAccruedAfterBaseLocals_rescaleFactor] - have hrescaleNat : (rewardConfigRescaleFromSlot0 slot0).toNat ≠ 0 := by - intro hz - apply hrescaleNZ - apply u256_inj - simpa [UInt256.toNat] using hz - have hrescaleInt : ¬ (↑(rewardConfigRescaleFromSlot0 slot0).toNat : Int) = 0 := by - intro hz - apply hrescaleNat - exact_mod_cast hz - simp only [evalBinaryOp?, getRewardAccruedDownscaledNat] - by_cases hz : Int.ofNat (rewardConfigRescaleFromSlot0 slot0).toNat = 0 - · exact False.elim (hrescaleInt hz) - · simp only [hz, ↓reduceIte] - have hdiv : - Int.ofNat accrued.toNat / Int.ofNat (rewardConfigRescaleFromSlot0 slot0).toNat = - Int.ofNat (accrued.toNat / (rewardConfigRescaleFromSlot0 slot0).toNat) := - Int.ofNat_ediv_ofNat - rw [hdiv] - -theorem evalExpr_getRewardAccrued_downscaled_revert_zero (evm : EVM.State) - (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) - (hrescaleZero : rewardConfigRescaleFromSlot0 slot0 = ⟨0⟩) : - evalExpr? config (getRewardAccruedAfterBaseFrame I slot0 multiplier accrued) evm - (.binary .div (.var "accrued") (.var "rescaleFactor")) = .revert := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [getRewardAccruedAfterBaseLocals_accrued, - getRewardAccruedAfterBaseLocals_rescaleFactor] - have hrescaleNat : (rewardConfigRescaleFromSlot0 slot0).toNat = 0 := by - rw [hrescaleZero] - rfl - simp [evalBinaryOp?, hrescaleNat] - -theorem evalExpr_getRewardAccrued_scaled (evm : EVM.State) - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accruedNat : ℕ) - (hscaled : getRewardAccruedScaledNat multiplier accruedNat < UInt256.size) : - evalExpr? config (getRewardAccruedAfterBranchFrame I slot0 multiplier accruedNat) evm - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))) = - .ok (.int (Int.ofNat (getRewardAccruedScaledNat multiplier accruedNat))) := by - simp only [u256, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [getRewardAccruedAfterBranchLocals_accrued, - getRewardAccruedAfterBranchLocals_multiplier] - simp only [evalBinaryOp?, getRewardAccruedScaledNat] - have hnonneg : ¬ (↑accruedNat * ↑multiplier.toNat : Int) < 0 := by - rw [show (↑accruedNat * ↑multiplier.toNat : Int) = - ↑(accruedNat * multiplier.toNat) by norm_num] - omega - have hltInt : - ¬ (115792089237316195423570985008687907853269984665640564039457584007913129639936 : Int) ≤ - (↑accruedNat * ↑multiplier.toNat : Int) := by - rw [show (↑accruedNat * ↑multiplier.toNat : Int) = - ↑(accruedNat * multiplier.toNat) by norm_num] - intro hle - have hleNat : UInt256.size ≤ accruedNat * multiplier.toNat := by - norm_num [UInt256.size] - exact_mod_cast hle - exact (Nat.not_le_of_gt hscaled) hleNat - simpa [uint256Int, hnonneg, hltInt, pure] - -theorem evalExpr_getRewardAccrued_return (evm : EVM.State) - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accruedNat : ℕ) : - evalExpr? config (getRewardAccruedAfterScaledFrame I slot0 multiplier accruedNat) evm - (.binary .div (.var "scaled") (.intLit factorScale)) = - .ok (.int (Int.ofNat (getRewardAccruedReturnNat multiplier accruedNat))) := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [getRewardAccruedAfterScaledLocals_scaled] - simp [evalBinaryOp?, getRewardAccruedReturnNat, factorScale] - -theorem evalExpr_getRewardAccrued_scaled_assigned (evm : EVM.State) - (I : ExecutionEnv) (slot0 multiplier oldAccrued : UInt256) (accruedNat : ℕ) - (hscaled : getRewardAccruedScaledNat multiplier accruedNat < UInt256.size) : - evalExpr? config - (getRewardAccruedAfterAssignedFrame I slot0 multiplier oldAccrued accruedNat) evm - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))) = - .ok (.int (Int.ofNat (getRewardAccruedScaledNat multiplier accruedNat))) := by - simp only [u256, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [getRewardAccruedAfterAssignedLocals_accrued, - getRewardAccruedAfterAssignedLocals_multiplier] - simp only [evalBinaryOp?, getRewardAccruedScaledNat] - have hnonneg : ¬ (↑accruedNat * ↑multiplier.toNat : Int) < 0 := by - rw [show (↑accruedNat * ↑multiplier.toNat : Int) = - ↑(accruedNat * multiplier.toNat) by norm_num] - omega - have hltInt : - ¬ (115792089237316195423570985008687907853269984665640564039457584007913129639936 : Int) ≤ - (↑accruedNat * ↑multiplier.toNat : Int) := by - rw [show (↑accruedNat * ↑multiplier.toNat : Int) = - ↑(accruedNat * multiplier.toNat) by norm_num] - intro hle - have hleNat : UInt256.size ≤ accruedNat * multiplier.toNat := by - norm_num [UInt256.size] - exact_mod_cast hle - exact (Nat.not_le_of_gt hscaled) hleNat - simpa [uint256Int, hnonneg, hltInt, pure] - -theorem evalExpr_getRewardAccrued_scaled_assigned_revert (evm : EVM.State) - (I : ExecutionEnv) (slot0 multiplier oldAccrued : UInt256) (accruedNat : ℕ) - (hover : UInt256.size ≤ getRewardAccruedScaledNat multiplier accruedNat) : - evalExpr? config - (getRewardAccruedAfterAssignedFrame I slot0 multiplier oldAccrued accruedNat) evm - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))) = .revert := by - simp only [u256, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [getRewardAccruedAfterAssignedLocals_accrued, - getRewardAccruedAfterAssignedLocals_multiplier] - simp only [evalBinaryOp?, getRewardAccruedScaledNat] - have hnonneg : ¬ (↑accruedNat * ↑multiplier.toNat : Int) < 0 := by - rw [show (↑accruedNat * ↑multiplier.toNat : Int) = - ↑(accruedNat * multiplier.toNat) by norm_num] - omega - have hgeInt : - (115792089237316195423570985008687907853269984665640564039457584007913129639936 : - Int) ≤ - (↑accruedNat * ↑multiplier.toNat : Int) := by - rw [show (↑accruedNat * ↑multiplier.toNat : Int) = - ↑(accruedNat * multiplier.toNat) by norm_num] - norm_num [UInt256.size] at hover ⊢ - exact_mod_cast hover - simpa [uint256Int, hnonneg, hgeInt, pure] - -theorem evalExpr_getRewardAccrued_return_assigned (evm : EVM.State) - (I : ExecutionEnv) (slot0 multiplier oldAccrued : UInt256) (accruedNat : ℕ) : - evalExpr? config - (getRewardAccruedAfterAssignedScaledFrame I slot0 multiplier oldAccrued accruedNat) evm - (.binary .div (.var "scaled") (.intLit factorScale)) = - .ok (.int (Int.ofNat (getRewardAccruedReturnNat multiplier accruedNat))) := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [getRewardAccruedAfterAssignedScaledLocals_scaled] - simp [evalBinaryOp?, getRewardAccruedReturnNat, factorScale] - -theorem getRewardAccruedBaseTrackingCallSuccess - (evm evmBase : EVM.State) (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) - {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (true, evmBase, out) false) - (hdec : config.externalABI.decode? "baseTrackingAccrued" out = - some [.int (Int.ofNat accrued.toNat)]) : - ExecBlock config { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } - evm - [ .externalCall (.var "comet") "baseTrackingAccrued" (.intLit 0) - [.var "account"] "accrued" false] - (.ok (getRewardAccruedAfterBaseFrame I slot0 multiplier accrued) evmBase) := by - exact externalCallVarSuccess (cfg := config) (C := contract) - (evm := evm) (evm' := evmBase) (locals := getRewardAccruedStore I slot0 multiplier) - (receiver := "comet") (retVar := "accrued") (name := "baseTrackingAccrued") - (target := getRewardOwedCometTarget I) (sendVal := 0) - (args := [.var "account"]) (argVals := getRewardAccruedBaseTrackingArgs I) - (out := out) (perm := false) (value := [.int (Int.ofNat accrued.toNat)]) - (getRewardAccruedStore_comet I slot0 multiplier) - (evalExprs_getRewardAccrued_baseTrackingArgs evm I slot0 multiplier) - hcall hdec - -theorem assignGetRewardAccrued_upscaled - (evm : EVM.State) (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) : - assignStorageRef? config (getRewardAccruedAfterBaseFrame I slot0 multiplier accrued) evm - .localVar { base := "accrued" } - (.int (Int.ofNat (getRewardAccruedUpscaledNat slot0 accrued))) = - .ok (getRewardAccruedAfterAssignedFrame I slot0 multiplier accrued - (getRewardAccruedUpscaledNat slot0 accrued), evm) := by - simp [assignStorageRef?, updateLocalPath?, getRewardAccruedAfterBaseFrame, - getRewardAccruedAfterBaseLocals, getRewardAccruedAfterAssignedFrame, - getRewardAccruedAfterAssignedLocals, EvalResult.bind, bind, pure] - -theorem assignGetRewardAccrued_downscaled - (evm : EVM.State) (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) : - assignStorageRef? config (getRewardAccruedAfterBaseFrame I slot0 multiplier accrued) evm - .localVar { base := "accrued" } - (.int (Int.ofNat (getRewardAccruedDownscaledNat slot0 accrued))) = - .ok (getRewardAccruedAfterAssignedFrame I slot0 multiplier accrued - (getRewardAccruedDownscaledNat slot0 accrued), evm) := by - simp [assignStorageRef?, updateLocalPath?, getRewardAccruedAfterBaseFrame, - getRewardAccruedAfterBaseLocals, getRewardAccruedAfterAssignedFrame, - getRewardAccruedAfterAssignedLocals, EvalResult.bind, bind, pure] - -theorem getRewardAccruedBodyReverts_callFailure - (evm evm' : EVM.State) (I : ExecutionEnv) (slot0 multiplier : UInt256) - {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (false, evm', out) false) : - ExecFuncBody config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } - evm getRewardAccruedFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } evm - [ .externalCall (.var "comet") "baseTrackingAccrued" (.intLit 0) - [.var "account"] "accrued" false, - .ite (.var "shouldUpscale") - [ .assign .localVar { base := "accrued" } - (u256 (.binary .mul (.var "accrued") (.var "rescaleFactor"))) ] - [ .assign .localVar { base := "accrued" } - (.binary .div (.var "accrued") (.var "rescaleFactor")) ], - .letDecl "scaled" (some uint256) - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))), - .return [.binary .div (.var "scaled") (.intLit factorScale)] ] .reverted - exact ExecBlock.consRevert - (ExecStmt.externalCallFailure - (evalExpr_getRewardOwed_comet_of evm I (getRewardAccruedStore_comet I slot0 multiplier)) - (by simp [evalExpr?, pure]) - (evalExprs_getRewardAccrued_baseTrackingArgs evm I slot0 multiplier) - hcall) - -theorem getRewardAccruedBodyReverts_decode - (evm evm' : EVM.State) (I : ExecutionEnv) (slot0 multiplier : UInt256) - {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (true, evm', out) false) - (hdec : config.externalABI.decode? "baseTrackingAccrued" out = none) : - ExecFuncBody config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } - evm getRewardAccruedFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } evm - [ .externalCall (.var "comet") "baseTrackingAccrued" (.intLit 0) - [.var "account"] "accrued" false, - .ite (.var "shouldUpscale") - [ .assign .localVar { base := "accrued" } - (u256 (.binary .mul (.var "accrued") (.var "rescaleFactor"))) ] - [ .assign .localVar { base := "accrued" } - (.binary .div (.var "accrued") (.var "rescaleFactor")) ], - .letDecl "scaled" (some uint256) - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))), - .return [.binary .div (.var "scaled") (.intLit factorScale)] ] .reverted - exact ExecBlock.consRevert - (ExecStmt.externalCallReturnDecodeRevert - (evalExpr_getRewardOwed_comet_of evm I (getRewardAccruedStore_comet I slot0 multiplier)) - (by simp [evalExpr?, pure]) - (evalExprs_getRewardAccrued_baseTrackingArgs evm I slot0 multiplier) - hcall hdec) - -theorem getRewardAccruedBodyReturns_upscale - (evm evmBase : EVM.State) (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) - {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (true, evmBase, out) false) - (hdec : config.externalABI.decode? "baseTrackingAccrued" out = - some [.int (Int.ofNat accrued.toNat)]) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 ≠ ⟨0⟩) - (hup : getRewardAccruedUpscaledNat slot0 accrued < UInt256.size) - (hscaled : - getRewardAccruedScaledNat multiplier (getRewardAccruedUpscaledNat slot0 accrued) < - UInt256.size) : - ExecFuncBody config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } - evm getRewardAccruedFunction.body - (.returned - (getRewardAccruedAfterAssignedScaledFrame I slot0 multiplier accrued - (getRewardAccruedUpscaledNat slot0 accrued)) - evmBase - (some [.int (Int.ofNat (getRewardAccruedReturnNat multiplier - (getRewardAccruedUpscaledNat slot0 accrued)))])) := by - refine ExecFuncBody.execBlockRet ?_ - change ExecBlock config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } evm - [ .externalCall (.var "comet") "baseTrackingAccrued" (.intLit 0) - [.var "account"] "accrued" false, - .ite (.var "shouldUpscale") - [ .assign .localVar { base := "accrued" } - (u256 (.binary .mul (.var "accrued") (.var "rescaleFactor"))) ] - [ .assign .localVar { base := "accrued" } - (.binary .div (.var "accrued") (.var "rescaleFactor")) ], - .letDecl "scaled" (some uint256) - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))), - .return [.binary .div (.var "scaled") (.intLit factorScale)] ] - (.returned - (getRewardAccruedAfterAssignedScaledFrame I slot0 multiplier accrued - (getRewardAccruedUpscaledNat slot0 accrued)) - evmBase - (some [.int (Int.ofNat (getRewardAccruedReturnNat multiplier - (getRewardAccruedUpscaledNat slot0 accrued)))])) - have hcallBlock := - getRewardAccruedBaseTrackingCallSuccess evm evmBase I slot0 multiplier accrued - hcall hdec - have hrest : - ExecBlock config (getRewardAccruedAfterBaseFrame I slot0 multiplier accrued) evmBase - [ .ite (.var "shouldUpscale") - [ .assign .localVar { base := "accrued" } - (u256 (.binary .mul (.var "accrued") (.var "rescaleFactor"))) ] - [ .assign .localVar { base := "accrued" } - (.binary .div (.var "accrued") (.var "rescaleFactor")) ], - .letDecl "scaled" (some uint256) - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))), - .return [.binary .div (.var "scaled") (.intLit factorScale)] ] - (.returned - (getRewardAccruedAfterAssignedScaledFrame I slot0 multiplier accrued - (getRewardAccruedUpscaledNat slot0 accrued)) - evmBase - (some [.int (Int.ofNat (getRewardAccruedReturnNat multiplier - (getRewardAccruedUpscaledNat slot0 accrued)))])) := by - refine ExecBlock.consNormal - (solm' := getRewardAccruedAfterAssignedFrame I slot0 multiplier accrued - (getRewardAccruedUpscaledNat slot0 accrued)) - (evm' := evmBase) ?hite ?_ - · refine ExecStmt.iteTrue - (evalExpr_getRewardAccrued_shouldUpscale_true evmBase I slot0 multiplier accrued - hshould) - ?_ - refine ExecBlock.consNormal ?hassign ExecBlock.nil - exact ExecStmt.assign - (evalExpr_getRewardAccrued_upscaled evmBase I slot0 multiplier accrued hup) - (assignGetRewardAccrued_upscaled evmBase I slot0 multiplier accrued) - refine ExecBlock.consNormal - (solm' := getRewardAccruedAfterAssignedScaledFrame I slot0 multiplier accrued - (getRewardAccruedUpscaledNat slot0 accrued)) - (evm' := evmBase) ?hscaledStmt ?_ - · exact ExecStmt.letDecl - (evalExpr_getRewardAccrued_scaled_assigned evmBase I slot0 multiplier accrued - (getRewardAccruedUpscaledNat slot0 accrued) hscaled) - exact ExecBlock.consReturn - (ExecStmt.return (evalExprs?_singleton - (evalExpr_getRewardAccrued_return_assigned evmBase I slot0 multiplier accrued - (getRewardAccruedUpscaledNat slot0 accrued)))) - exact execBlock_append hcallBlock hrest - -theorem getRewardAccruedBodyReturns_downscale - (evm evmBase : EVM.State) (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) - {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (true, evmBase, out) false) - (hdec : config.externalABI.decode? "baseTrackingAccrued" out = - some [.int (Int.ofNat accrued.toNat)]) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 = ⟨0⟩) - (hrescaleNZ : rewardConfigRescaleFromSlot0 slot0 ≠ ⟨0⟩) - (hscaled : - getRewardAccruedScaledNat multiplier (getRewardAccruedDownscaledNat slot0 accrued) < - UInt256.size) : - ExecFuncBody config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } - evm getRewardAccruedFunction.body - (.returned - (getRewardAccruedAfterAssignedScaledFrame I slot0 multiplier accrued - (getRewardAccruedDownscaledNat slot0 accrued)) - evmBase - (some [.int (Int.ofNat (getRewardAccruedReturnNat multiplier - (getRewardAccruedDownscaledNat slot0 accrued)))])) := by - refine ExecFuncBody.execBlockRet ?_ - change ExecBlock config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } evm - [ .externalCall (.var "comet") "baseTrackingAccrued" (.intLit 0) - [.var "account"] "accrued" false, - .ite (.var "shouldUpscale") - [ .assign .localVar { base := "accrued" } - (u256 (.binary .mul (.var "accrued") (.var "rescaleFactor"))) ] - [ .assign .localVar { base := "accrued" } - (.binary .div (.var "accrued") (.var "rescaleFactor")) ], - .letDecl "scaled" (some uint256) - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))), - .return [.binary .div (.var "scaled") (.intLit factorScale)] ] - (.returned - (getRewardAccruedAfterAssignedScaledFrame I slot0 multiplier accrued - (getRewardAccruedDownscaledNat slot0 accrued)) - evmBase - (some [.int (Int.ofNat (getRewardAccruedReturnNat multiplier - (getRewardAccruedDownscaledNat slot0 accrued)))])) - have hcallBlock := - getRewardAccruedBaseTrackingCallSuccess evm evmBase I slot0 multiplier accrued - hcall hdec - have hrest : - ExecBlock config (getRewardAccruedAfterBaseFrame I slot0 multiplier accrued) evmBase - [ .ite (.var "shouldUpscale") - [ .assign .localVar { base := "accrued" } - (u256 (.binary .mul (.var "accrued") (.var "rescaleFactor"))) ] - [ .assign .localVar { base := "accrued" } - (.binary .div (.var "accrued") (.var "rescaleFactor")) ], - .letDecl "scaled" (some uint256) - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))), - .return [.binary .div (.var "scaled") (.intLit factorScale)] ] - (.returned - (getRewardAccruedAfterAssignedScaledFrame I slot0 multiplier accrued - (getRewardAccruedDownscaledNat slot0 accrued)) - evmBase - (some [.int (Int.ofNat (getRewardAccruedReturnNat multiplier - (getRewardAccruedDownscaledNat slot0 accrued)))])) := by - refine ExecBlock.consNormal - (solm' := getRewardAccruedAfterAssignedFrame I slot0 multiplier accrued - (getRewardAccruedDownscaledNat slot0 accrued)) - (evm' := evmBase) ?hite ?_ - · refine ExecStmt.iteFalse - (evalExpr_getRewardAccrued_shouldUpscale_false evmBase I slot0 multiplier accrued - hshould) - ?_ - refine ExecBlock.consNormal ?hassign ExecBlock.nil - exact ExecStmt.assign - (evalExpr_getRewardAccrued_downscaled evmBase I slot0 multiplier accrued hrescaleNZ) - (assignGetRewardAccrued_downscaled evmBase I slot0 multiplier accrued) - refine ExecBlock.consNormal - (solm' := getRewardAccruedAfterAssignedScaledFrame I slot0 multiplier accrued - (getRewardAccruedDownscaledNat slot0 accrued)) - (evm' := evmBase) ?hscaledStmt ?_ - · exact ExecStmt.letDecl - (evalExpr_getRewardAccrued_scaled_assigned evmBase I slot0 multiplier accrued - (getRewardAccruedDownscaledNat slot0 accrued) hscaled) - exact ExecBlock.consReturn - (ExecStmt.return (evalExprs?_singleton - (evalExpr_getRewardAccrued_return_assigned evmBase I slot0 multiplier accrued - (getRewardAccruedDownscaledNat slot0 accrued)))) - exact execBlock_append hcallBlock hrest - -theorem getRewardAccruedBodyReverts_downscale_zero - (evm evmBase : EVM.State) (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) - {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (true, evmBase, out) false) - (hdec : config.externalABI.decode? "baseTrackingAccrued" out = - some [.int (Int.ofNat accrued.toNat)]) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 = ⟨0⟩) - (hrescaleZero : rewardConfigRescaleFromSlot0 slot0 = ⟨0⟩) : - ExecFuncBody config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } - evm getRewardAccruedFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } evm - [ .externalCall (.var "comet") "baseTrackingAccrued" (.intLit 0) - [.var "account"] "accrued" false, - .ite (.var "shouldUpscale") - [ .assign .localVar { base := "accrued" } - (u256 (.binary .mul (.var "accrued") (.var "rescaleFactor"))) ] - [ .assign .localVar { base := "accrued" } - (.binary .div (.var "accrued") (.var "rescaleFactor")) ], - .letDecl "scaled" (some uint256) - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))), - .return [.binary .div (.var "scaled") (.intLit factorScale)] ] .reverted - have hcallBlock := - getRewardAccruedBaseTrackingCallSuccess evm evmBase I slot0 multiplier accrued - hcall hdec - have hrest : - ExecBlock config (getRewardAccruedAfterBaseFrame I slot0 multiplier accrued) evmBase - [ .ite (.var "shouldUpscale") - [ .assign .localVar { base := "accrued" } - (u256 (.binary .mul (.var "accrued") (.var "rescaleFactor"))) ] - [ .assign .localVar { base := "accrued" } - (.binary .div (.var "accrued") (.var "rescaleFactor")) ], - .letDecl "scaled" (some uint256) - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))), - .return [.binary .div (.var "scaled") (.intLit factorScale)] ] - .reverted := by - refine ExecBlock.consRevert (ExecStmt.iteFalse - (evalExpr_getRewardAccrued_shouldUpscale_false evmBase I slot0 multiplier accrued - hshould) ?_) - exact ExecBlock.consRevert (ExecStmt.assignExprRevert - (evalExpr_getRewardAccrued_downscaled_revert_zero evmBase I slot0 multiplier - accrued hrescaleZero)) - exact execBlock_append hcallBlock hrest - -theorem getRewardAccruedBodyReverts_upscale_scaledOverflow - (evm evmBase : EVM.State) (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) - {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (true, evmBase, out) false) - (hdec : config.externalABI.decode? "baseTrackingAccrued" out = - some [.int (Int.ofNat accrued.toNat)]) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 ≠ ⟨0⟩) - (hup : getRewardAccruedUpscaledNat slot0 accrued < UInt256.size) - (hover : - UInt256.size ≤ - getRewardAccruedScaledNat multiplier (getRewardAccruedUpscaledNat slot0 accrued)) : - ExecFuncBody config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } - evm getRewardAccruedFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } evm - [ .externalCall (.var "comet") "baseTrackingAccrued" (.intLit 0) - [.var "account"] "accrued" false, - .ite (.var "shouldUpscale") - [ .assign .localVar { base := "accrued" } - (u256 (.binary .mul (.var "accrued") (.var "rescaleFactor"))) ] - [ .assign .localVar { base := "accrued" } - (.binary .div (.var "accrued") (.var "rescaleFactor")) ], - .letDecl "scaled" (some uint256) - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))), - .return [.binary .div (.var "scaled") (.intLit factorScale)] ] .reverted - have hcallBlock := - getRewardAccruedBaseTrackingCallSuccess evm evmBase I slot0 multiplier accrued - hcall hdec - have hrest : - ExecBlock config (getRewardAccruedAfterBaseFrame I slot0 multiplier accrued) evmBase - [ .ite (.var "shouldUpscale") - [ .assign .localVar { base := "accrued" } - (u256 (.binary .mul (.var "accrued") (.var "rescaleFactor"))) ] - [ .assign .localVar { base := "accrued" } - (.binary .div (.var "accrued") (.var "rescaleFactor")) ], - .letDecl "scaled" (some uint256) - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))), - .return [.binary .div (.var "scaled") (.intLit factorScale)] ] - .reverted := by - refine ExecBlock.consNormal - (solm' := getRewardAccruedAfterAssignedFrame I slot0 multiplier accrued - (getRewardAccruedUpscaledNat slot0 accrued)) - (evm' := evmBase) ?hite ?_ - · refine ExecStmt.iteTrue - (evalExpr_getRewardAccrued_shouldUpscale_true evmBase I slot0 multiplier accrued - hshould) - ?_ - refine ExecBlock.consNormal ?hassign ExecBlock.nil - exact ExecStmt.assign - (evalExpr_getRewardAccrued_upscaled evmBase I slot0 multiplier accrued hup) - (assignGetRewardAccrued_upscaled evmBase I slot0 multiplier accrued) - exact ExecBlock.consRevert (ExecStmt.letDeclRevert - (evalExpr_getRewardAccrued_scaled_assigned_revert evmBase I slot0 multiplier accrued - (getRewardAccruedUpscaledNat slot0 accrued) hover)) - exact execBlock_append hcallBlock hrest - -theorem getRewardAccruedBodyReverts_downscale_scaledOverflow - (evm evmBase : EVM.State) (I : ExecutionEnv) (slot0 multiplier accrued : UInt256) - {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (true, evmBase, out) false) - (hdec : config.externalABI.decode? "baseTrackingAccrued" out = - some [.int (Int.ofNat accrued.toNat)]) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 = ⟨0⟩) - (hrescaleNZ : rewardConfigRescaleFromSlot0 slot0 ≠ ⟨0⟩) - (hover : - UInt256.size ≤ - getRewardAccruedScaledNat multiplier (getRewardAccruedDownscaledNat slot0 accrued)) : - ExecFuncBody config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } - evm getRewardAccruedFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config - { contract := contract, locals := getRewardAccruedStore I slot0 multiplier } evm - [ .externalCall (.var "comet") "baseTrackingAccrued" (.intLit 0) - [.var "account"] "accrued" false, - .ite (.var "shouldUpscale") - [ .assign .localVar { base := "accrued" } - (u256 (.binary .mul (.var "accrued") (.var "rescaleFactor"))) ] - [ .assign .localVar { base := "accrued" } - (.binary .div (.var "accrued") (.var "rescaleFactor")) ], - .letDecl "scaled" (some uint256) - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))), - .return [.binary .div (.var "scaled") (.intLit factorScale)] ] .reverted - have hcallBlock := - getRewardAccruedBaseTrackingCallSuccess evm evmBase I slot0 multiplier accrued - hcall hdec - have hrest : - ExecBlock config (getRewardAccruedAfterBaseFrame I slot0 multiplier accrued) evmBase - [ .ite (.var "shouldUpscale") - [ .assign .localVar { base := "accrued" } - (u256 (.binary .mul (.var "accrued") (.var "rescaleFactor"))) ] - [ .assign .localVar { base := "accrued" } - (.binary .div (.var "accrued") (.var "rescaleFactor")) ], - .letDecl "scaled" (some uint256) - (u256 (.binary .mul (.var "accrued") (.var "multiplier"))), - .return [.binary .div (.var "scaled") (.intLit factorScale)] ] - .reverted := by - refine ExecBlock.consNormal - (solm' := getRewardAccruedAfterAssignedFrame I slot0 multiplier accrued - (getRewardAccruedDownscaledNat slot0 accrued)) - (evm' := evmBase) ?hite ?_ - · refine ExecStmt.iteFalse - (evalExpr_getRewardAccrued_shouldUpscale_false evmBase I slot0 multiplier accrued - hshould) - ?_ - refine ExecBlock.consNormal ?hassign ExecBlock.nil - exact ExecStmt.assign - (evalExpr_getRewardAccrued_downscaled evmBase I slot0 multiplier accrued hrescaleNZ) - (assignGetRewardAccrued_downscaled evmBase I slot0 multiplier accrued) - exact ExecBlock.consRevert (ExecStmt.letDeclRevert - (evalExpr_getRewardAccrued_scaled_assigned_revert evmBase I slot0 multiplier accrued - (getRewardAccruedDownscaledNat slot0 accrued) hover)) - exact execBlock_append hcallBlock hrest - -theorem evalExpr_getRewardOwed_claimed_afterAccrue - (evm evmAcc : EVM.State) (I : ExecutionEnv) : - evalExpr? config - { contract := contract, locals := getRewardOwedAfterAccrueLocals evm I } evmAcc - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))) = - .ok (.int (Int.ofNat (getRewardOwedClaimedLoad evmAcc I).toNat)) := by - exact evalExpr_getRewardOwed_claimed_of evmAcc I - (getRewardOwedAfterAccrueLocals_comet evm I) - (getRewardOwedAfterAccrueLocals_account evm I) - (getRewardOwedAfterAccrueLocals_no_rewardsClaimed evm I) - -theorem evalExprs_getRewardOwed_getRewardAccruedArgs_afterClaimed - (evm evmAcc : EVM.State) (I : ExecutionEnv) : - evalExprs? config - { contract := contract, locals := getRewardOwedAfterClaimedLocals evm evmAcc I } - evmAcc - [.var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"] = - .ok (getRewardAccruedArgs I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) := by - exact evalExprs_getRewardAccrued_args_of evmAcc I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I) - (getRewardOwedAfterClaimedLocals_comet evm evmAcc I) - (getRewardOwedAfterClaimedLocals_account evm evmAcc I) - (getRewardOwedAfterClaimedLocals_rescaleFactor evm evmAcc I) - (getRewardOwedAfterClaimedLocals_shouldUpscale evm evmAcc I) - (getRewardOwedAfterClaimedLocals_multiplier evm evmAcc I) - -theorem evalExpr_getRewardOwed_owed_at - (evm evmAcc evmRun : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - evalExpr? config - { contract := contract, locals := getRewardOwedAfterInternalLocals evm evmAcc I accruedNat } - evmRun - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)) = - .ok (.int (Int.ofNat (getRewardOwedOwedNat evmAcc I accruedNat))) := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [getRewardOwedAfterInternalLocals_accrued, - getRewardOwedAfterInternalLocals_claimed] - by_cases hlt : (getRewardOwedClaimedLoad evmAcc I).toNat < accruedNat - · have hgtInt : (↑(getRewardOwedClaimedLoad evmAcc I).toNat : Int) < ↑accruedNat := by - exact_mod_cast hlt - simp [evalBinaryOp?, hgtInt, getRewardOwedOwedNat, hlt] - have hsub : (↑accruedNat - ↑(getRewardOwedClaimedLoad evmAcc I).toNat : Int) = - ↑(accruedNat - (getRewardOwedClaimedLoad evmAcc I).toNat) := by - omega - rw [hsub] - · have hgtFalse : ¬ (↑(getRewardOwedClaimedLoad evmAcc I).toNat : Int) < ↑accruedNat := by - intro h - exact hlt (by exact_mod_cast h) - simp [evalBinaryOp?, hgtFalse, getRewardOwedOwedNat, hlt, pure] - -theorem evalExpr_getRewardOwed_owed - (evm evmAcc : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - evalExpr? config - { contract := contract, locals := getRewardOwedAfterInternalLocals evm evmAcc I accruedNat } - evmAcc - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)) = - .ok (.int (Int.ofNat (getRewardOwedOwedNat evmAcc I accruedNat))) := by - exact evalExpr_getRewardOwed_owed_at evm evmAcc evmAcc I accruedNat - -theorem evalExpr_getRewardOwed_returnTuple_at - (evm evmAcc evmRun : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - evalExpr? config - { contract := contract, locals := getRewardOwedAfterOwedLocals evm evmAcc I accruedNat } - evmRun (.tupleLit [.var "token", .var "owed"]) = - .ok (.tuple [getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I), - .int (Int.ofNat (getRewardOwedOwedNat evmAcc I accruedNat))]) := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind, evalExprList?] - rw [getRewardOwedAfterOwedLocals_token, getRewardOwedAfterOwedLocals_owed] - rfl - -theorem evalExpr_getRewardOwed_returnTuple - (evm evmAcc : EVM.State) (I : ExecutionEnv) (accruedNat : ℕ) : - evalExpr? config - { contract := contract, locals := getRewardOwedAfterOwedLocals evm evmAcc I accruedNat } - evmAcc (.tupleLit [.var "token", .var "owed"]) = - .ok (.tuple [getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I), - .int (Int.ofNat (getRewardOwedOwedNat evmAcc I accruedNat))]) := by - exact evalExpr_getRewardOwed_returnTuple_at evm evmAcc evmAcc I accruedNat - -theorem cometRewardsGetRewardOwedBodyReturns_upscale - (evm evmAcc evmBase : EVM.State) (I : ExecutionEnv) {accrueOut baseOut : ByteArray} - {baseAccrued : UInt256} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hnz : rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evm I) ≠ ⟨0⟩) - (hguard : - evalExpr? config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (.binary .gt (.extCodeSize (.var "comet")) (.intLit 0)) = .ok (.bool true)) - (hcallAccrue : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "accrueAccount" 0 (getRewardOwedAccrueAccountArgs I) - (true, evmAcc, accrueOut) true) - (hdecAccrue : config.externalABI.decode? "accrueAccount" accrueOut = some []) - (hcallBase : - typedCallViaEVM config evmAcc (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseTrackingAccrued" baseOut = - some [.int (Int.ofNat baseAccrued.toNat)]) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 (getRewardOwedSlot0Load evm I) ≠ ⟨0⟩) - (hup : getRewardAccruedUpscaledNat (getRewardOwedSlot0Load evm I) baseAccrued < - UInt256.size) - (hscaled : getRewardAccruedScaledNat (getRewardOwedMultiplierLoad evm I) - (getRewardAccruedUpscaledNat (getRewardOwedSlot0Load evm I) baseAccrued) < - UInt256.size) : - ExecTransitionBody config contract evm (getRewardOwedStore I) - getRewardOwedTransition.body - (.returned - { contract := contract, - locals := getRewardOwedAfterOwedLocals evm evmAcc I - (getRewardAccruedReturnNat (getRewardOwedMultiplierLoad evm I) - (getRewardAccruedUpscaledNat (getRewardOwedSlot0Load evm I) baseAccrued)) } - evmBase - (some [.tuple - [ getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I), - .int (Int.ofNat (getRewardOwedOwedNat evmAcc I - (getRewardAccruedReturnNat (getRewardOwedMultiplierLoad evm I) - (getRewardAccruedUpscaledNat (getRewardOwedSlot0Load evm I) - baseAccrued)))) ]])) := by - refine ExecFuncBody.execBlockRet ?_ - let accruedNat := getRewardAccruedReturnNat (getRewardOwedMultiplierLoad evm I) - (getRewardAccruedUpscaledNat (getRewardOwedSlot0Load evm I) baseAccrued) - have hcheckedSmall : - ExecBlock config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued") - (.ok { contract := contract, locals := getRewardOwedAfterAccrueLocals evm I } - evmAcc) := by - simpa [checkedExternalCallStmts, getRewardOwedAfterAccrueLocals, collapseReturns] - using checkedExternalCallVarSuccess (cfg := config) (C := contract) - (evm := evm) (evm' := evmAcc) (locals := getRewardOwedConfigLocals evm I) - (receiver := "comet") (retVar := "_accrued") (name := "accrueAccount") - (target := getRewardOwedCometTarget I) (sendVal := 0) - (args := [.var "account"]) (argVals := getRewardOwedAccrueAccountArgs I) - (out := accrueOut) (perm := true) (value := []) - hguard (getRewardOwedConfigLocals_comet evm I) - (evalExprs_getRewardOwed_accrueAccountArgs_of evm I - (getRewardOwedConfigLocals_account evm I)) - hcallAccrue hdecAccrue - have hrest : - ExecBlock config { contract := contract, locals := getRewardOwedAfterAccrueLocals evm I } - evmAcc - [ .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))), - .internalCall "getRewardAccrued" - [ .var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier" ] "accrued", - .letDecl "owed" (some uint256) - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)), - .return [(.tupleLit [.var "token", .var "owed"])] ] - (.returned - { contract := contract, - locals := getRewardOwedAfterOwedLocals evm evmAcc I accruedNat } - evmBase - (some [.tuple - [ getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I), - .int (Int.ofNat (getRewardOwedOwedNat evmAcc I accruedNat)) ]])) := by - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := getRewardOwedAfterClaimedLocals evm evmAcc I }) - (evm' := evmAcc) ?hclaimed ?_ - · exact ExecStmt.letDecl (evalExpr_getRewardOwed_claimed_afterAccrue evm evmAcc I) - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := getRewardOwedAfterInternalLocals evm evmAcc I accruedNat }) - (evm' := evmBase) ?hinternal ?_ - · simpa [resumeAfterInternalCall, getRewardOwedAfterInternalLocals, collapseReturns] - using internalCallFunctionReturn - (cfg := config) - (caller := { contract := contract, locals := getRewardOwedAfterClaimedLocals evm evmAcc I }) - (evm := evmAcc) (calleeEvm := evmBase) - (name := "getRewardAccrued") (retVar := "accrued") - (args := [.var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"]) - (argVals := getRewardAccruedArgs I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (callee := getRewardAccruedFunction) - (locals := getRewardAccruedStore I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (calleeSolm := getRewardAccruedAfterAssignedScaledFrame I - (getRewardOwedSlot0Load evm I) (getRewardOwedMultiplierLoad evm I) baseAccrued - (getRewardAccruedUpscaledNat (getRewardOwedSlot0Load evm I) baseAccrued)) - (value := some [.int (Int.ofNat accruedNat)]) - (evalExprs_getRewardOwed_getRewardAccruedArgs_afterClaimed evm evmAcc I) - lookupCallable_getRewardAccrued - (bindParams_getRewardAccrued I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (by - dsimp [accruedNat] - exact getRewardAccruedBodyReturns_upscale evmAcc evmBase I - (getRewardOwedSlot0Load evm I) (getRewardOwedMultiplierLoad evm I) - baseAccrued hcallBase hdecBase hshould hup hscaled) - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := getRewardOwedAfterOwedLocals evm evmAcc I accruedNat }) - (evm' := evmBase) ?howed ?_ - · exact ExecStmt.letDecl - (evalExpr_getRewardOwed_owed_at evm evmAcc evmBase I accruedNat) - exact ExecBlock.consReturn - (ExecStmt.return (evalExprs?_singleton - (evalExpr_getRewardOwed_returnTuple_at evm evmAcc evmBase I accruedNat))) - have htail : - ExecBlock config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued" ++ - [ .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))), - .internalCall "getRewardAccrued" - [ .var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier" ] "accrued", - .letDecl "owed" (some uint256) - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)), - .return [(.tupleLit [.var "token", .var "owed"])] ]) - (.returned - { contract := contract, - locals := getRewardOwedAfterOwedLocals evm evmAcc I accruedNat } - evmBase - (some [.tuple - [ getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I), - .int (Int.ofNat (getRewardOwedOwedNat evmAcc I accruedNat)) ]])) := by - exact execBlock_append hcheckedSmall hrest - have hprefix : - ABlock config evm { contract := contract, locals := getRewardOwedStore I } - getRewardOwedTransition.body - { contract := contract, locals := getRewardOwedConfigLocals evm I } - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued" ++ - [ .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))), - .internalCall "getRewardAccrued" - [ .var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier" ] "accrued", - .letDecl "owed" (some uint256) - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)), - .return [(.tupleLit [.var "token", .var "owed"])] ]) := by - simpa [getRewardOwedTransition, externalEntryGuard, nonpayable, calldataSizeGuard, - checkedExternalCallStmts, getRewardOwedConfigLocals, getRewardOwedAfterShouldLocals, - getRewardOwedAfterRescaleLocals, getRewardOwedAfterTokenLocals, - getRewardOwedBaseLocals] using - (((((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (getRewardOwedStore I) hsize)).letStep - (evalExpr_getRewardOwed_token_of evm I (getRewardOwedFrame_comet evm I) - (getRewardOwedFrame_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_rescale_of evm I - (getRewardOwedAfterTokenLocals_comet evm I) - (getRewardOwedAfterTokenLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_shouldUpscale_of evm I - (getRewardOwedAfterRescaleLocals_comet evm I) - (getRewardOwedAfterRescaleLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_multiplier_of evm I - (getRewardOwedAfterShouldLocals_comet evm I) - (getRewardOwedAfterShouldLocals_no_rewardConfig evm I))).requireStep - (evalExpr_getRewardOwed_token_ne_zero_true_of evm (getRewardOwedSlot0Load evm I) - (getRewardOwedConfigLocals_token evm I) hnz) - exact hprefix.run htail - -theorem cometRewardsGetRewardOwedBodyReturns_downscale - (evm evmAcc evmBase : EVM.State) (I : ExecutionEnv) {accrueOut baseOut : ByteArray} - {baseAccrued : UInt256} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hnz : rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evm I) ≠ ⟨0⟩) - (hguard : - evalExpr? config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (.binary .gt (.extCodeSize (.var "comet")) (.intLit 0)) = .ok (.bool true)) - (hcallAccrue : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "accrueAccount" 0 (getRewardOwedAccrueAccountArgs I) - (true, evmAcc, accrueOut) true) - (hdecAccrue : config.externalABI.decode? "accrueAccount" accrueOut = some []) - (hcallBase : - typedCallViaEVM config evmAcc (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseTrackingAccrued" baseOut = - some [.int (Int.ofNat baseAccrued.toNat)]) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 (getRewardOwedSlot0Load evm I) = ⟨0⟩) - (hrescaleNZ : rewardConfigRescaleFromSlot0 (getRewardOwedSlot0Load evm I) ≠ ⟨0⟩) - (hscaled : getRewardAccruedScaledNat (getRewardOwedMultiplierLoad evm I) - (getRewardAccruedDownscaledNat (getRewardOwedSlot0Load evm I) baseAccrued) < - UInt256.size) : - ExecTransitionBody config contract evm (getRewardOwedStore I) - getRewardOwedTransition.body - (.returned - { contract := contract, - locals := getRewardOwedAfterOwedLocals evm evmAcc I - (getRewardAccruedReturnNat (getRewardOwedMultiplierLoad evm I) - (getRewardAccruedDownscaledNat (getRewardOwedSlot0Load evm I) baseAccrued)) } - evmBase - (some [.tuple - [ getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I), - .int (Int.ofNat (getRewardOwedOwedNat evmAcc I - (getRewardAccruedReturnNat (getRewardOwedMultiplierLoad evm I) - (getRewardAccruedDownscaledNat (getRewardOwedSlot0Load evm I) - baseAccrued)))) ]])) := by - refine ExecFuncBody.execBlockRet ?_ - let accruedNat := getRewardAccruedReturnNat (getRewardOwedMultiplierLoad evm I) - (getRewardAccruedDownscaledNat (getRewardOwedSlot0Load evm I) baseAccrued) - have hcheckedSmall : - ExecBlock config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued") - (.ok { contract := contract, locals := getRewardOwedAfterAccrueLocals evm I } - evmAcc) := by - simpa [checkedExternalCallStmts, getRewardOwedAfterAccrueLocals, collapseReturns] - using checkedExternalCallVarSuccess (cfg := config) (C := contract) - (evm := evm) (evm' := evmAcc) (locals := getRewardOwedConfigLocals evm I) - (receiver := "comet") (retVar := "_accrued") (name := "accrueAccount") - (target := getRewardOwedCometTarget I) (sendVal := 0) - (args := [.var "account"]) (argVals := getRewardOwedAccrueAccountArgs I) - (out := accrueOut) (perm := true) (value := []) - hguard (getRewardOwedConfigLocals_comet evm I) - (evalExprs_getRewardOwed_accrueAccountArgs_of evm I - (getRewardOwedConfigLocals_account evm I)) - hcallAccrue hdecAccrue - have hrest : - ExecBlock config { contract := contract, locals := getRewardOwedAfterAccrueLocals evm I } - evmAcc - [ .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))), - .internalCall "getRewardAccrued" - [ .var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier" ] "accrued", - .letDecl "owed" (some uint256) - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)), - .return [(.tupleLit [.var "token", .var "owed"])] ] - (.returned - { contract := contract, - locals := getRewardOwedAfterOwedLocals evm evmAcc I accruedNat } - evmBase - (some [.tuple - [ getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I), - .int (Int.ofNat (getRewardOwedOwedNat evmAcc I accruedNat)) ]])) := by - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := getRewardOwedAfterClaimedLocals evm evmAcc I }) - (evm' := evmAcc) ?hclaimed ?_ - · exact ExecStmt.letDecl (evalExpr_getRewardOwed_claimed_afterAccrue evm evmAcc I) - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := getRewardOwedAfterInternalLocals evm evmAcc I accruedNat }) - (evm' := evmBase) ?hinternal ?_ - · simpa [resumeAfterInternalCall, getRewardOwedAfterInternalLocals, collapseReturns] - using internalCallFunctionReturn - (cfg := config) - (caller := { contract := contract, locals := getRewardOwedAfterClaimedLocals evm evmAcc I }) - (evm := evmAcc) (calleeEvm := evmBase) - (name := "getRewardAccrued") (retVar := "accrued") - (args := [.var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"]) - (argVals := getRewardAccruedArgs I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (callee := getRewardAccruedFunction) - (locals := getRewardAccruedStore I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (calleeSolm := getRewardAccruedAfterAssignedScaledFrame I - (getRewardOwedSlot0Load evm I) (getRewardOwedMultiplierLoad evm I) baseAccrued - (getRewardAccruedDownscaledNat (getRewardOwedSlot0Load evm I) baseAccrued)) - (value := some [.int (Int.ofNat accruedNat)]) - (evalExprs_getRewardOwed_getRewardAccruedArgs_afterClaimed evm evmAcc I) - lookupCallable_getRewardAccrued - (bindParams_getRewardAccrued I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (by - dsimp [accruedNat] - exact getRewardAccruedBodyReturns_downscale evmAcc evmBase I - (getRewardOwedSlot0Load evm I) (getRewardOwedMultiplierLoad evm I) - baseAccrued hcallBase hdecBase hshould hrescaleNZ hscaled) - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := getRewardOwedAfterOwedLocals evm evmAcc I accruedNat }) - (evm' := evmBase) ?howed ?_ - · exact ExecStmt.letDecl - (evalExpr_getRewardOwed_owed_at evm evmAcc evmBase I accruedNat) - exact ExecBlock.consReturn - (ExecStmt.return (evalExprs?_singleton - (evalExpr_getRewardOwed_returnTuple_at evm evmAcc evmBase I accruedNat))) - have htail : - ExecBlock config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued" ++ - [ .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))), - .internalCall "getRewardAccrued" - [ .var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier" ] "accrued", - .letDecl "owed" (some uint256) - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)), - .return [(.tupleLit [.var "token", .var "owed"])] ]) - (.returned - { contract := contract, - locals := getRewardOwedAfterOwedLocals evm evmAcc I accruedNat } - evmBase - (some [.tuple - [ getRewardOwedTokenValueFromSlot0 (getRewardOwedSlot0Load evm I), - .int (Int.ofNat (getRewardOwedOwedNat evmAcc I accruedNat)) ]])) := by - exact execBlock_append hcheckedSmall hrest - have hprefix : - ABlock config evm { contract := contract, locals := getRewardOwedStore I } - getRewardOwedTransition.body - { contract := contract, locals := getRewardOwedConfigLocals evm I } - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued" ++ - [ .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))), - .internalCall "getRewardAccrued" - [ .var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier" ] "accrued", - .letDecl "owed" (some uint256) - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)), - .return [(.tupleLit [.var "token", .var "owed"])] ]) := by - simpa [getRewardOwedTransition, externalEntryGuard, nonpayable, calldataSizeGuard, - checkedExternalCallStmts, getRewardOwedConfigLocals, getRewardOwedAfterShouldLocals, - getRewardOwedAfterRescaleLocals, getRewardOwedAfterTokenLocals, - getRewardOwedBaseLocals] using - (((((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (getRewardOwedStore I) hsize)).letStep - (evalExpr_getRewardOwed_token_of evm I (getRewardOwedFrame_comet evm I) - (getRewardOwedFrame_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_rescale_of evm I - (getRewardOwedAfterTokenLocals_comet evm I) - (getRewardOwedAfterTokenLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_shouldUpscale_of evm I - (getRewardOwedAfterRescaleLocals_comet evm I) - (getRewardOwedAfterRescaleLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_multiplier_of evm I - (getRewardOwedAfterShouldLocals_comet evm I) - (getRewardOwedAfterShouldLocals_no_rewardConfig evm I))).requireStep - (evalExpr_getRewardOwed_token_ne_zero_true_of evm (getRewardOwedSlot0Load evm I) - (getRewardOwedConfigLocals_token evm I) hnz) - exact hprefix.run htail - -theorem getRewardOwedRewardConfigSlotOf_eq_solc (I : ExecutionEnv) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) : - getRewardOwedRewardConfigSlotOf I = - solcMappingSlot ⟨1⟩ (getRewardOwedCometWord I) := by - unfold getRewardOwedRewardConfigSlotOf rewardConfigSlot - rw [keyValueToWord_address_of_canonical _ hcanonComet] - rfl - -theorem getRewardOwedRewardsClaimedSlotOf_eq_solc (I : ExecutionEnv) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) : - getRewardOwedRewardsClaimedSlotOf I = - solcMappingSlot (solcMappingSlot ⟨2⟩ (getRewardOwedCometWord I)) - (getRewardOwedAccountWord I) := by - unfold getRewardOwedRewardsClaimedSlotOf rewardsClaimedSlot rewardsClaimedCometSlot - rw [keyValueToWord_address_of_canonical _ hcanonComet, - keyValueToWord_address_of_canonical _ hcanonAccount] - rfl - -theorem wordAt0Mem_size_of_ge {mem : ByteArray} (word : UInt256) - (hmem : 32 ≤ mem.size) : - (wordAt0Mem word mem).size = mem.size := by - unfold wordAt0Mem - rw [write32_eq _ _ _ (by rw [toByteArray_size]) (by omega), - ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, toByteArray_size] - omega - -theorem wordAt32Mem_size_of_ge {mem : ByteArray} (word : UInt256) - (hmem : 64 ≤ mem.size) : - (wordAt32Mem word mem).size = mem.size := by - unfold wordAt32Mem - rw [write32_eq _ _ _ (by rw [toByteArray_size]) (by omega), - ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, toByteArray_size] - omega - -theorem twoWordHashMem_size_of_ge {mem : ByteArray} (key slot : UInt256) - (hmem : 64 ≤ mem.size) : - (twoWordHashMem key slot mem).size = mem.size := by - unfold twoWordHashMem - rw [wordAt32Mem_size_of_ge slot (by - rw [wordAt0Mem_size_of_ge key (by omega)] - exact hmem)] - exact wordAt0Mem_size_of_ge key (by omega) - -theorem twoWordHashMem_read0_of_ge {mem : ByteArray} (key slot : UInt256) - (hmem : 64 ≤ mem.size) : - (twoWordHashMem key slot mem).readWithPadding 0 32 = UInt256.toByteArray key := by - unfold twoWordHashMem wordAt32Mem - rw [write32_read_below _ _ 32 0 (by rw [toByteArray_size]) - (by rw [wordAt0Mem_size_of_ge key (by omega)]; omega) (by omega)] - unfold wordAt0Mem - rw [write32_read_back _ _ _ (by rw [toByteArray_size]) (by omega)] - apply ByteArray.ext - rw [ByteArray.data_extract] - exact Array.extract_eq_self_of_le (by - change (UInt256.toByteArray key).size ≤ 32 - rw [toByteArray_size]) - -theorem twoWordHashMem_read32_of_ge {mem : ByteArray} (key slot : UInt256) - (hmem : 64 ≤ mem.size) : - (twoWordHashMem key slot mem).readWithPadding 32 32 = UInt256.toByteArray slot := by - unfold twoWordHashMem wordAt32Mem - rw [write32_read_back _ _ _ (by rw [toByteArray_size]) - (by rw [wordAt0Mem_size_of_ge key (by omega)]; omega)] - apply ByteArray.ext - rw [ByteArray.data_extract] - exact Array.extract_eq_self_of_le (by - change (UInt256.toByteArray slot).size ≤ 32 - rw [toByteArray_size]) - -set_option maxHeartbeats 800000 in -theorem twoWordHashMem_read0_64_of_ge {mem : ByteArray} (key slot : UInt256) - (hmem : 64 ≤ mem.size) : - (twoWordHashMem key slot mem).readWithPadding 0 64 = - UInt256.toByteArray key ++ UInt256.toByteArray slot := by - rw [readWithPadding_eq_extract' _ 0 64 (by norm_num) (by norm_num) - (by rw [twoWordHashMem_size_of_ge key slot hmem]; omega)] - have hleft : - (twoWordHashMem key slot mem).extract 0 32 = UInt256.toByteArray key := by - rw [← readWithPadding_eq_extract _ 0 - (by rw [twoWordHashMem_size_of_ge key slot hmem]; omega), - twoWordHashMem_read0_of_ge key slot hmem] - have hright : - (twoWordHashMem key slot mem).extract 32 64 = UInt256.toByteArray slot := by - rw [← readWithPadding_eq_extract _ 32 - (by rw [twoWordHashMem_size_of_ge key slot hmem]; omega), - twoWordHashMem_read32_of_ge key slot hmem] - rw [show (twoWordHashMem key slot mem).extract 0 64 = - (twoWordHashMem key slot mem).extract 0 32 ++ - (twoWordHashMem key slot mem).extract 32 64 by - rw [ByteArray.extract_append_extract] - norm_num] - rw [hleft, hright] - -theorem twoWordHashMem_read64_of_ge {mem : ByteArray} (key slot : UInt256) - (hmem : 96 ≤ mem.size) : - (twoWordHashMem key slot mem).readWithPadding 64 32 = - mem.readWithPadding 64 32 := by - unfold twoWordHashMem wordAt32Mem - rw [write32_read_above _ _ 32 64 (by rw [toByteArray_size]) - (by rw [wordAt0Mem_size_of_ge key (by omega)]; omega) (by omega) - (by rw [wordAt0Mem_size_of_ge key (by omega)]; omega)] - unfold wordAt0Mem - rw [write32_read_above _ _ 0 64 (by rw [toByteArray_size]) (by omega) - (by omega) (by omega)] - -theorem twoWordHashMem_solcMappingSlot_of_ge (baseSlot key : UInt256) - {mem : ByteArray} (hmem : 64 ≤ mem.size) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((twoWordHashMem key baseSlot mem).readWithPadding 0 64))) = - solcMappingSlot baseSlot key := by - rw [twoWordHashMem_read0_64_of_ge key baseSlot hmem] - unfold solcMappingSlot - exact mappingSlot_single key baseSlot - -noncomputable abbrev getRewardOwedAlloc64Mem : ByteArray := - writeWord solcFreePtrMem 64 (⟨192⟩ : UInt256) - -noncomputable abbrev getRewardOwedConfigZeroMem : ByteArray := - writeCascade getRewardOwedAlloc64Mem [(128, (⟨0⟩ : UInt256)), (160, (⟨0⟩ : UInt256))] - -noncomputable abbrev getRewardOwedRewardConfigHashMem (I : ExecutionEnv) : ByteArray := - twoWordHashMem (getRewardOwedCometWord I) ⟨1⟩ getRewardOwedConfigZeroMem - -noncomputable abbrev getRewardOwedConfigAllocMem (I : ExecutionEnv) : ByteArray := - writeWord (getRewardOwedRewardConfigHashMem I) 64 (⟨320⟩ : UInt256) - -noncomputable abbrev getRewardOwedConfigTokenMem - (I : ExecutionEnv) (slot0 : UInt256) : ByteArray := - writeWord (getRewardOwedConfigAllocMem I) 192 (rewardConfigTokenFromSlot0 slot0) - -noncomputable abbrev getRewardOwedConfigRescaleMem - (I : ExecutionEnv) (slot0 : UInt256) : ByteArray := - writeWord (getRewardOwedConfigTokenMem I slot0) 224 (rewardConfigRescaleFromSlot0 slot0) - -noncomputable abbrev getRewardOwedConfigShouldMem - (I : ExecutionEnv) (slot0 : UInt256) : ByteArray := - writeWord (getRewardOwedConfigRescaleMem I slot0) 256 - (rewardConfigShouldUpscaleFromSlot0 slot0) - -noncomputable abbrev getRewardOwedConfigMultiplierMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) : ByteArray := - writeWord (getRewardOwedConfigShouldMem I slot0) 288 multiplier - -noncomputable abbrev getRewardOwedInvalidRewardConfigSelectorMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) : ByteArray := - writeWord (getRewardOwedConfigMultiplierMem I slot0 multiplier) 320 - (UInt256.shiftLeft (⟨1311535579⟩ : UInt256) ⟨225⟩) - -noncomputable abbrev getRewardOwedInvalidRewardConfigArgMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) : ByteArray := - writeWord (getRewardOwedInvalidRewardConfigSelectorMem I slot0 multiplier) 324 - (getRewardOwedCometWord I) - -noncomputable abbrev getRewardOwedAccrueAccountSelectorMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) : ByteArray := - writeWord (getRewardOwedConfigMultiplierMem I slot0 multiplier) 320 - (UInt256.shiftLeft (⟨3219561613⟩ : UInt256) ⟨224⟩) - -noncomputable abbrev getRewardOwedAccrueAccountCalldataMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) : ByteArray := - writeWord (getRewardOwedAccrueAccountSelectorMem I slot0 multiplier) 324 - (getRewardOwedAccountWord I) - -abbrev getRewardOwedAccrueAccountPostCallTail (I : ExecutionEnv) : List UInt256 := - [ ⟨320⟩, - UInt256.land (getRewardOwedAccountWord I) solcAddrMask, - getRewardOwedAccountWord I, - getRewardOwedCometWord I, - ⟨0⟩, - UInt256.land (getRewardOwedCometWord I) solcAddrMask, - solcAddrMask, - ⟨32⟩, - ⟨192⟩, - ⟨64⟩ ] - -abbrev getRewardOwedAccrueAccountPostCallStack (z : Bool) (I : ExecutionEnv) : - List UInt256 := - (if z then ⟨1⟩ else ⟨0⟩) :: getRewardOwedAccrueAccountPostCallTail I - -noncomputable abbrev getRewardOwedAccrueAccountPostCallMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (out : ByteArray) : ByteArray := - out.write 0 (getRewardOwedAccrueAccountCalldataMem I slot0 multiplier) 320 - (min (⟨0⟩ : UInt256) (UInt256.ofNat out.size)).toNat - -abbrev getRewardOwedAccrueAccountPostCallAw : UInt256 := - UInt256.ofNat (MachineState.M - (MachineState.M (UInt256.ofNat 12).toNat (⟨320⟩ : UInt256).toNat - getRewardOwedAccrueAccountCallSize.toNat) - (⟨320⟩ : UInt256).toNat (⟨0⟩ : UInt256).toNat) - -noncomputable abbrev getRewardOwedAccrueAccountAfterAllocMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (out : ByteArray) : ByteArray := - writeWord (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier out) 64 - (⟨320⟩ : UInt256) - -noncomputable abbrev getRewardOwedClaimedInnerHashMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (out : ByteArray) : ByteArray := - twoWordHashMem (UInt256.land (getRewardOwedCometWord I) solcAddrMask) ⟨2⟩ - (getRewardOwedAccrueAccountAfterAllocMem I slot0 multiplier out) - -noncomputable abbrev getRewardOwedClaimedOuterHashMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (out : ByteArray) : ByteArray := - twoWordHashMem (UInt256.land (getRewardOwedAccountWord I) solcAddrMask) - (solcMappingSlot ⟨2⟩ (UInt256.land (getRewardOwedCometWord I) solcAddrMask)) - (getRewardOwedClaimedInnerHashMem I slot0 multiplier out) - -noncomputable abbrev getRewardOwedBaseTrackingSelectorMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (out : ByteArray) : ByteArray := - writeWord (getRewardOwedClaimedOuterHashMem I slot0 multiplier out) 320 - (UInt256.shiftLeft (⟨719776253⟩ : UInt256) ⟨226⟩) - -noncomputable abbrev getRewardOwedBaseTrackingCalldataMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (out : ByteArray) : ByteArray := - writeWord (getRewardOwedBaseTrackingSelectorMem I slot0 multiplier out) 324 - (getRewardOwedAccountWord I) - -abbrev getRewardOwedBaseTrackingPostCallTail (claimed : UInt256) : List UInt256 := - [ ⟨192⟩, - ⟨320⟩, - ⟨2499⟩, - claimed, - ⟨0⟩, - solcAddrMask, - ⟨32⟩, - ⟨192⟩, - ⟨64⟩ ] - -abbrev getRewardOwedBaseTrackingPostCallStack (z : Bool) (claimed : UInt256) : - List UInt256 := - (if z then ⟨1⟩ else ⟨0⟩) :: getRewardOwedBaseTrackingPostCallTail claimed - -abbrev getRewardOwedBaseTrackingCallAw : UInt256 := - getRewardOwedAccrueAccountPostCallAw - -noncomputable abbrev getRewardOwedBaseTrackingPostCallMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) : - ByteArray := - baseOut.write 0 (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier accrueOut) 320 - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat - -abbrev getRewardOwedBaseTrackingPostCallAw : UInt256 := - UInt256.ofNat (MachineState.M - (MachineState.M getRewardOwedBaseTrackingCallAw.toNat - (⟨320⟩ : UInt256).toNat getRewardOwedBaseTrackingCallSize.toNat) - (⟨320⟩ : UInt256).toNat (⟨32⟩ : UInt256).toNat) - -abbrev getRewardOwedBaseTrackingReturnWord (out : ByteArray) : UInt256 := - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) - -noncomputable abbrev getRewardOwedBaseTrackingPostDecodeMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) : - ByteArray := - writeWord (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) 64 - (⟨352⟩ : UInt256) - -noncomputable abbrev getRewardOwedBaseTrackingPostShortDecodeMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) : - ByteArray := - writeWord (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) 64 - ((⟨320⟩ : UInt256) + - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat baseOut.size + ⟨31⟩)) - -def getRewardOwedReturnBytes (token owed : UInt256) : ByteArray := - UInt256.toByteArray token ++ UInt256.toByteArray owed - -abbrev getRewardOwedReturnOwedWord (claimed accrued : UInt256) : UInt256 := - if claimed.toNat < accrued.toNat then - UInt256.ofNat (accrued.toNat - claimed.toNat) - else - ⟨0⟩ - -noncomputable abbrev getRewardOwedReturnAllocMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) : - ByteArray := - writeWord (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) 64 - (⟨416⟩ : UInt256) - -noncomputable abbrev getRewardOwedReturnStructTokenMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) : - ByteArray := - writeWord (getRewardOwedReturnAllocMem I slot0 multiplier accrueOut baseOut) 352 - (rewardConfigTokenFromSlot0 slot0) - -noncomputable abbrev getRewardOwedReturnStructOwedMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) - (owed : UInt256) : - ByteArray := - writeWord (getRewardOwedReturnStructTokenMem I slot0 multiplier accrueOut baseOut) 384 owed - -noncomputable abbrev getRewardOwedReturnCopyTokenMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) - (owed : UInt256) : - ByteArray := - writeWord (getRewardOwedReturnStructOwedMem I slot0 multiplier accrueOut baseOut owed) 416 - (rewardConfigTokenFromSlot0 slot0) - -noncomputable abbrev getRewardOwedReturnMem - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) - (owed : UInt256) : - ByteArray := - writeWord (getRewardOwedReturnCopyTokenMem I slot0 multiplier accrueOut baseOut owed) 448 owed - -theorem getRewardOwedAlloc64Mem_size : - getRewardOwedAlloc64Mem.size = 96 := by - simpa [getRewardOwedAlloc64Mem, solcFreePtrMem_size] using - writeWord_size solcFreePtrMem 64 (⟨192⟩ : UInt256) - (by rw [solcFreePtrMem_size]; native_decide) - -theorem getRewardOwedConfigZeroMem_size : - getRewardOwedConfigZeroMem.size = 192 := by - simpa [getRewardOwedConfigZeroMem] using - writeCascade_size_of_base getRewardOwedAlloc64Mem - [(128, (⟨0⟩ : UInt256)), (160, (⟨0⟩ : UInt256))] - getRewardOwedAlloc64Mem_size - (by - dsimp [WriteGapsOk] - constructor - · native_decide - constructor - · native_decide - · trivial) - (by native_decide) - -theorem getRewardOwedAlloc64Mem_read64 : - getRewardOwedAlloc64Mem.readWithPadding 64 32 = - UInt256.toByteArray (⟨192⟩ : UInt256) := by - simpa [getRewardOwedAlloc64Mem] using - writeWord_read_back solcFreePtrMem 64 (⟨192⟩ : UInt256) - (by rw [solcFreePtrMem_size]; native_decide) - -theorem getRewardOwedConfigZeroMem_read64 : - getRewardOwedConfigZeroMem.readWithPadding 64 32 = - UInt256.toByteArray (⟨192⟩ : UInt256) := by - rw [getRewardOwedConfigZeroMem] - rw [writeCascade_read_preserved_of_base getRewardOwedAlloc64Mem - [(128, (⟨0⟩ : UInt256)), (160, (⟨0⟩ : UInt256))] - getRewardOwedAlloc64Mem_size (by - dsimp [WindowDisjointFromWrites] - constructor - · native_decide - constructor - · left - constructor <;> norm_num - constructor - · native_decide - constructor - · left - constructor <;> norm_num - · trivial)] - exact getRewardOwedAlloc64Mem_read64 - -theorem getRewardOwedRewardConfigHashMem_keccakSlot (I : ExecutionEnv) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((getRewardOwedRewardConfigHashMem I).readWithPadding 0 64))) = - solcMappingSlot ⟨1⟩ (getRewardOwedCometWord I) := by - unfold getRewardOwedRewardConfigHashMem - exact twoWordHashMem_solcMappingSlot_of_ge ⟨1⟩ (getRewardOwedCometWord I) - (by rw [getRewardOwedConfigZeroMem_size]; decide) - -theorem getRewardOwedRewardConfigHashMem_mload64 (I : ExecutionEnv) : - (if (⟨64⟩ : UInt256).toNat ≥ (getRewardOwedRewardConfigHashMem I).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 6 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((getRewardOwedRewardConfigHashMem I).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - ⟨192⟩ := by - have hsizeHash : (getRewardOwedRewardConfigHashMem I).size = 192 := by - unfold getRewardOwedRewardConfigHashMem - rw [twoWordHashMem_size_of_ge] - · exact getRewardOwedConfigZeroMem_size - · rw [getRewardOwedConfigZeroMem_size] - decide - have hread : - (getRewardOwedRewardConfigHashMem I).readWithPadding 64 32 = - UInt256.toByteArray (⟨192⟩ : UInt256) := by - unfold getRewardOwedRewardConfigHashMem - rw [twoWordHashMem_read64_of_ge] - · exact getRewardOwedConfigZeroMem_read64 - · rw [getRewardOwedConfigZeroMem_size] - decide - rw [if_neg] - · rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide, hread, - fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - · rw [hsizeHash] - native_decide - -theorem getRewardOwedConfigAllocMem_size (I : ExecutionEnv) : - (getRewardOwedConfigAllocMem I).size = 192 := by - have hhash : (getRewardOwedRewardConfigHashMem I).size = 192 := by - unfold getRewardOwedRewardConfigHashMem - rw [twoWordHashMem_size_of_ge] - · exact getRewardOwedConfigZeroMem_size - · rw [getRewardOwedConfigZeroMem_size] - decide - unfold getRewardOwedConfigAllocMem - rw [writeWord_size] - · rw [hhash] - native_decide - · rw [hhash] - native_decide - -theorem getRewardOwedConfigAllocMem_read64 (I : ExecutionEnv) : - (getRewardOwedConfigAllocMem I).readWithPadding 64 32 = - UInt256.toByteArray (⟨320⟩ : UInt256) := by - have hhash : (getRewardOwedRewardConfigHashMem I).size = 192 := by - unfold getRewardOwedRewardConfigHashMem - rw [twoWordHashMem_size_of_ge] - · exact getRewardOwedConfigZeroMem_size - · rw [getRewardOwedConfigZeroMem_size] - decide - simpa [getRewardOwedConfigAllocMem] using - writeWord_read_back (getRewardOwedRewardConfigHashMem I) 64 (⟨320⟩ : UInt256) - (by rw [hhash]; native_decide) - -theorem getRewardOwedConfigTokenMem_size (I : ExecutionEnv) (slot0 : UInt256) : - (getRewardOwedConfigTokenMem I slot0).size = 224 := by - unfold getRewardOwedConfigTokenMem - rw [writeWord_size] - · rw [getRewardOwedConfigAllocMem_size] - native_decide - · rw [getRewardOwedConfigAllocMem_size] - native_decide - -theorem getRewardOwedConfigRescaleMem_size (I : ExecutionEnv) (slot0 : UInt256) : - (getRewardOwedConfigRescaleMem I slot0).size = 256 := by - unfold getRewardOwedConfigRescaleMem - rw [writeWord_size] - · rw [getRewardOwedConfigTokenMem_size] - native_decide - · rw [getRewardOwedConfigTokenMem_size] - native_decide - -theorem getRewardOwedConfigShouldMem_size (I : ExecutionEnv) (slot0 : UInt256) : - (getRewardOwedConfigShouldMem I slot0).size = 288 := by - unfold getRewardOwedConfigShouldMem - rw [writeWord_size] - · rw [getRewardOwedConfigRescaleMem_size] - native_decide - · rw [getRewardOwedConfigRescaleMem_size] - native_decide - -theorem getRewardOwedConfigMultiplierMem_size - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (getRewardOwedConfigMultiplierMem I slot0 multiplier).size = 320 := by - unfold getRewardOwedConfigMultiplierMem - rw [writeWord_size] - · rw [getRewardOwedConfigShouldMem_size] - native_decide - · rw [getRewardOwedConfigShouldMem_size] - native_decide - -theorem getRewardOwedConfigTokenMem_read64 (I : ExecutionEnv) (slot0 : UInt256) : - (getRewardOwedConfigTokenMem I slot0).readWithPadding 64 32 = - UInt256.toByteArray (⟨320⟩ : UInt256) := by - simpa [getRewardOwedConfigTokenMem] using - writeWord_read_preserved (getRewardOwedConfigAllocMem I) 192 64 - (rewardConfigTokenFromSlot0 slot0) - (by rw [getRewardOwedConfigAllocMem_size]; native_decide) - (by - left - rw [getRewardOwedConfigAllocMem_size] - constructor <;> norm_num) - |>.trans (getRewardOwedConfigAllocMem_read64 I) - -theorem getRewardOwedConfigRescaleMem_read64 (I : ExecutionEnv) (slot0 : UInt256) : - (getRewardOwedConfigRescaleMem I slot0).readWithPadding 64 32 = - UInt256.toByteArray (⟨320⟩ : UInt256) := by - simpa [getRewardOwedConfigRescaleMem] using - writeWord_read_preserved (getRewardOwedConfigTokenMem I slot0) 224 64 - (rewardConfigRescaleFromSlot0 slot0) - (by rw [getRewardOwedConfigTokenMem_size]; native_decide) - (by - left - rw [getRewardOwedConfigTokenMem_size] - constructor <;> norm_num) - |>.trans (getRewardOwedConfigTokenMem_read64 I slot0) - -theorem getRewardOwedConfigShouldMem_read64 (I : ExecutionEnv) (slot0 : UInt256) : - (getRewardOwedConfigShouldMem I slot0).readWithPadding 64 32 = - UInt256.toByteArray (⟨320⟩ : UInt256) := by - simpa [getRewardOwedConfigShouldMem] using - writeWord_read_preserved (getRewardOwedConfigRescaleMem I slot0) 256 64 - (rewardConfigShouldUpscaleFromSlot0 slot0) - (by rw [getRewardOwedConfigRescaleMem_size]; native_decide) - (by - left - rw [getRewardOwedConfigRescaleMem_size] - constructor <;> norm_num) - |>.trans (getRewardOwedConfigRescaleMem_read64 I slot0) - -theorem getRewardOwedConfigMultiplierMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (getRewardOwedConfigMultiplierMem I slot0 multiplier).readWithPadding 64 32 = - UInt256.toByteArray (⟨320⟩ : UInt256) := by - simpa [getRewardOwedConfigMultiplierMem] using - writeWord_read_preserved (getRewardOwedConfigShouldMem I slot0) 288 64 multiplier - (by rw [getRewardOwedConfigShouldMem_size]; native_decide) - (by - left - rw [getRewardOwedConfigShouldMem_size] - constructor <;> norm_num) - |>.trans (getRewardOwedConfigShouldMem_read64 I slot0) - -theorem getRewardOwedConfigMultiplierMem_mload64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (getRewardOwedConfigMultiplierMem I slot0 multiplier).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 10 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((getRewardOwedConfigMultiplierMem I slot0 multiplier).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - ⟨320⟩ := by - rw [if_neg] - · rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide, - getRewardOwedConfigMultiplierMem_read64, - fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - · rw [getRewardOwedConfigMultiplierMem_size] - native_decide - -theorem getRewardOwedAccrueAccountSelectorMem_size - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (getRewardOwedAccrueAccountSelectorMem I slot0 multiplier).size = 352 := by - unfold getRewardOwedAccrueAccountSelectorMem - rw [writeWord_size] - · rw [getRewardOwedConfigMultiplierMem_size] - native_decide - · rw [getRewardOwedConfigMultiplierMem_size] - native_decide - -theorem getRewardOwedAccrueAccountCalldataMem_size - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (getRewardOwedAccrueAccountCalldataMem I slot0 multiplier).size = 356 := by - unfold getRewardOwedAccrueAccountCalldataMem - rw [writeWord_size] - · rw [getRewardOwedAccrueAccountSelectorMem_size] - native_decide - · rw [getRewardOwedAccrueAccountSelectorMem_size] - native_decide - -theorem getRewardOwedAccrueAccountCalldataMem_read320_4 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (getRewardOwedAccrueAccountCalldataMem I slot0 multiplier).readWithPadding 320 4 = - accrueAccountSelector := by - unfold getRewardOwedAccrueAccountCalldataMem - unfold Reasoning.Theory.writeWord - rw [write32_read_below_len _ _ 324 320 4 (by rw [toByteArray_size]) - (by rw [getRewardOwedAccrueAccountSelectorMem_size]; norm_num) - (by norm_num) - (by rw [getRewardOwedAccrueAccountSelectorMem_size]; norm_num) - (by norm_num) (by norm_num)] - unfold getRewardOwedAccrueAccountSelectorMem - unfold Reasoning.Theory.writeWord - rw [write32_read_prefix_len _ _ 320 4 (by rw [toByteArray_size]) - (by rw [getRewardOwedConfigMultiplierMem_size]) - (by norm_num) (by norm_num) (by norm_num)] - native_decide - -theorem getRewardOwedAccrueAccountCalldataMem_read324_32 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (getRewardOwedAccrueAccountCalldataMem I slot0 multiplier).readWithPadding 324 32 = - UInt256.toByteArray (getRewardOwedAccountWord I) := by - unfold getRewardOwedAccrueAccountCalldataMem - unfold Reasoning.Theory.writeWord - rw [write32_read_back _ _ _ (by rw [toByteArray_size]) - (by rw [getRewardOwedAccrueAccountSelectorMem_size]; norm_num)] - rw [show (UInt256.toByteArray (getRewardOwedAccountWord I)).extract 0 32 = - UInt256.toByteArray (getRewardOwedAccountWord I) by - rw [show 32 = (UInt256.toByteArray (getRewardOwedAccountWord I)).size by - rw [toByteArray_size]] - exact byteArray_extract_self _] - -theorem getRewardOwedAccrueAccountCalldataMem_read320_36 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (getRewardOwedAccrueAccountCalldataMem I slot0 multiplier).readWithPadding 320 36 = - accrueAccountSelector ++ UInt256.toByteArray (getRewardOwedAccountWord I) := by - rw [byteArray_readWithPadding_split _ 320 4 32 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) - (by simp [getRewardOwedAccrueAccountCalldataMem_size])] - rw [getRewardOwedAccrueAccountCalldataMem_read320_4, - getRewardOwedAccrueAccountCalldataMem_read324_32] - -set_option maxHeartbeats 1000000 in -theorem getRewardOwedAccrueAccountCalldataMem_encode_args - (I : ExecutionEnv) - (slot0 multiplier : UInt256) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) : - config.externalABI.encode? "accrueAccount" (getRewardOwedAccrueAccountArgs I) = - some ((getRewardOwedAccrueAccountCalldataMem I slot0 multiplier) - |>.readWithPadding 320 getRewardOwedAccrueAccountCallSize.toNat) := by - rw [show getRewardOwedAccrueAccountCallSize.toNat = 36 from rfl] - rw [getRewardOwedAccrueAccountCalldataMem_read320_36] - change compoundRewardsExternalABI.encode? "accrueAccount" (getRewardOwedAccrueAccountArgs I) = - some (accrueAccountSelector ++ UInt256.toByteArray (getRewardOwedAccountWord I)) - have haccountWord : - EVM.word (AccountAddress.ofNat (getRewardOwedAccountWord I).toNat).val = - getRewardOwedAccountWord I := by - change UInt256.ofNat (AccountAddress.ofNat (getRewardOwedAccountWord I).toNat).val = - getRewardOwedAccountWord I - have haddr : - (AccountAddress.ofNat (getRewardOwedAccountWord I).toNat).val = - (getRewardOwedAccountWord I).toNat := by - have hcanonAddr : (getRewardOwedAccountWord I).toNat < AccountAddress.size := by - simpa [EVM.addressModulus, EVM.twoPow, AccountAddress.size] using hcanonAccount - unfold AccountAddress.ofNat - exact Nat.mod_eq_of_lt hcanonAddr - rw [haddr] - exact u256_ofNat_toNat (getRewardOwedAccountWord I) - unfold compoundRewardsExternalABI ABI.encodeCallWithSelector? ABI.encodeABIValues? - simp [getRewardOwedAccrueAccountArgs, getRewardOwedAccountValue, addr, - ABI.abiTupleHeadSize?, ABI.staticABIEncodedSize?, ABI.isDynamicABIType, - ABI.encodeABIValue?, ABI.encodeABIWord?, ABI.encodeABIValuesFrom?, haccountWord, - word_toBytesBE_toByteArray_eq_toByteArray] - -theorem getRewardOwedPostCallLen_le_out_size {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat ≤ out.size := by - by_cases houtSmall : out.size < 32 - · have hnotle : ¬ (⟨32⟩ : UInt256) ≤ UInt256.ofNat out.size := by - intro hle - have hlev : (32 : Nat) ≤ (UInt256.ofNat out.size).toNat := by - simpa [UInt256.toNat] using hle - rw [UInt256.toNat_ofNat_of_lt houtSize] at hlev - omega - simp [min, hnotle, UInt256.toNat_ofNat_of_lt houtSize] - · have hle : (⟨32⟩ : UInt256) ≤ UInt256.ofNat out.size := by - change (⟨32⟩ : UInt256).val ≤ (UInt256.ofNat out.size).val - change (32 : Nat) ≤ (UInt256.ofNat out.size).toNat - rw [UInt256.toNat_ofNat_of_lt houtSize] - omega - simp [min, hle] - change (32 : Nat) ≤ out.size - omega - -theorem getRewardOwedAccrueAccountPostCallMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier out).readWithPadding - 64 32 = - UInt256.toByteArray ⟨320⟩ := by - dsimp [getRewardOwedAccrueAccountPostCallMem] - have hle : (⟨0⟩ : UInt256) ≤ UInt256.ofNat out.size := by - change (0 : Nat) ≤ (UInt256.ofNat out.size).toNat - exact Nat.zero_le _ - rw [show (min (⟨0⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 0 by - simp [min, hle]] - rw [byteArray_write_len_zero] - unfold getRewardOwedAccrueAccountCalldataMem - unfold Reasoning.Theory.writeWord - rw [write32_read_below _ _ 324 64 (by rw [toByteArray_size]) - (by rw [getRewardOwedAccrueAccountSelectorMem_size]; norm_num) - (by norm_num)] - unfold getRewardOwedAccrueAccountSelectorMem - exact (writeWord_read_preserved - (getRewardOwedConfigMultiplierMem I slot0 multiplier) 320 64 - (UInt256.shiftLeft (⟨3219561613⟩ : UInt256) ⟨224⟩) - (by rw [getRewardOwedConfigMultiplierMem_size]; native_decide) - (by - left - rw [getRewardOwedConfigMultiplierMem_size] - constructor <;> norm_num)).trans - (getRewardOwedConfigMultiplierMem_read64 I slot0 multiplier) - -theorem getRewardOwedAccrueAccountPostCallMem_size_ge320 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - 320 ≤ (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier out).size := by - dsimp [getRewardOwedAccrueAccountPostCallMem] - have hle : (⟨0⟩ : UInt256) ≤ UInt256.ofNat out.size := by - change (0 : Nat) ≤ (UInt256.ofNat out.size).toNat - exact Nat.zero_le _ - rw [show (min (⟨0⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 0 by - simp [min, hle]] - rw [byteArray_write_len_zero] - rw [getRewardOwedAccrueAccountCalldataMem_size] - norm_num - -theorem getRewardOwedAccrueAccountAfterAllocMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (getRewardOwedAccrueAccountAfterAllocMem I slot0 multiplier out).readWithPadding - 64 32 = - UInt256.toByteArray ⟨320⟩ := by - unfold getRewardOwedAccrueAccountAfterAllocMem - exact writeWord_read_back - (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier out) 64 - (⟨320⟩ : UInt256) - (by - have hge := getRewardOwedAccrueAccountPostCallMem_size_ge320 - I slot0 multiplier houtSize - have hzero : - 64 - (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier out).size = 0 := by - omega - rw [hzero] - native_decide) - -theorem getRewardOwedAccrueAccountAfterAllocMem_size_ge320 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - 320 ≤ (getRewardOwedAccrueAccountAfterAllocMem I slot0 multiplier out).size := by - unfold getRewardOwedAccrueAccountAfterAllocMem - rw [writeWord_size] - · have hge := getRewardOwedAccrueAccountPostCallMem_size_ge320 - I slot0 multiplier houtSize - omega - · have hge := getRewardOwedAccrueAccountPostCallMem_size_ge320 - I slot0 multiplier houtSize - have hzero : - 64 - (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier out).size = 0 := by - omega - rw [hzero] - native_decide - -theorem getRewardOwedClaimedInnerHashMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (getRewardOwedClaimedInnerHashMem I slot0 multiplier out).readWithPadding - 64 32 = - UInt256.toByteArray ⟨320⟩ := by - unfold getRewardOwedClaimedInnerHashMem - rw [twoWordHashMem_read64_of_ge] - · exact getRewardOwedAccrueAccountAfterAllocMem_read64 I slot0 multiplier houtSize - · exact le_trans (by norm_num) <| - getRewardOwedAccrueAccountAfterAllocMem_size_ge320 I slot0 multiplier houtSize - -theorem getRewardOwedClaimedInnerHashMem_size_ge320 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - 320 ≤ (getRewardOwedClaimedInnerHashMem I slot0 multiplier out).size := by - unfold getRewardOwedClaimedInnerHashMem - rw [twoWordHashMem_size_of_ge] - · exact getRewardOwedAccrueAccountAfterAllocMem_size_ge320 I slot0 multiplier houtSize - · exact le_trans (by norm_num) <| - getRewardOwedAccrueAccountAfterAllocMem_size_ge320 I slot0 multiplier houtSize - -theorem getRewardOwedClaimedOuterHashMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (getRewardOwedClaimedOuterHashMem I slot0 multiplier out).readWithPadding - 64 32 = - UInt256.toByteArray ⟨320⟩ := by - unfold getRewardOwedClaimedOuterHashMem - rw [twoWordHashMem_read64_of_ge] - · exact getRewardOwedClaimedInnerHashMem_read64 I slot0 multiplier houtSize - · exact le_trans (by norm_num) <| - getRewardOwedClaimedInnerHashMem_size_ge320 I slot0 multiplier houtSize - -theorem getRewardOwedClaimedOuterHashMem_size_ge320 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - 320 ≤ (getRewardOwedClaimedOuterHashMem I slot0 multiplier out).size := by - unfold getRewardOwedClaimedOuterHashMem - rw [twoWordHashMem_size_of_ge] - · exact getRewardOwedClaimedInnerHashMem_size_ge320 I slot0 multiplier houtSize - · exact le_trans (by norm_num) <| - getRewardOwedClaimedInnerHashMem_size_ge320 I slot0 multiplier houtSize - -theorem getRewardOwedClaimedOuterHashMem_mload64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ - (getRewardOwedClaimedOuterHashMem I slot0 multiplier out).size - ∨ (⟨64⟩ : UInt256) ≥ getRewardOwedBaseTrackingCallAw * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((getRewardOwedClaimedOuterHashMem I slot0 multiplier out).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - ⟨320⟩ := by - apply mloadWordValue_of_readWithPadding - · simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] using - (lt_of_lt_of_le (by norm_num : 64 < 320) <| - getRewardOwedClaimedOuterHashMem_size_ge320 I slot0 multiplier houtSize) - · native_decide - · exact getRewardOwedClaimedOuterHashMem_read64 I slot0 multiplier houtSize - -set_option maxHeartbeats 1000000 in -theorem getRewardOwedClaimedInnerHashMem_keccakSlot - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((getRewardOwedClaimedInnerHashMem I slot0 multiplier out) - |>.readWithPadding 0 64))) = - solcMappingSlot ⟨2⟩ (getRewardOwedCometWord I) := by - unfold getRewardOwedClaimedInnerHashMem - rw [twoWordHashMem_solcMappingSlot_of_ge] - · exact congrArg (fun x => solcMappingSlot ⟨2⟩ x) - (solcAddrMask_clean (by simpa [getRewardOwedCometWord, calldataWord] using hcanonComet)) - · exact le_trans (by norm_num) <| - getRewardOwedAccrueAccountAfterAllocMem_size_ge320 I slot0 multiplier houtSize - -set_option maxHeartbeats 1000000 in -theorem getRewardOwedClaimedOuterHashMem_keccakSlot - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((getRewardOwedClaimedOuterHashMem I slot0 multiplier out) - |>.readWithPadding 0 64))) = - getRewardOwedRewardsClaimedSlotOf I := by - have hhash : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((getRewardOwedClaimedOuterHashMem I slot0 multiplier out) - |>.readWithPadding 0 64))) = - solcMappingSlot - (solcMappingSlot ⟨2⟩ (UInt256.land (getRewardOwedCometWord I) solcAddrMask)) - (UInt256.land (getRewardOwedAccountWord I) solcAddrMask) := by - unfold getRewardOwedClaimedOuterHashMem - exact twoWordHashMem_solcMappingSlot_of_ge - (solcMappingSlot ⟨2⟩ (UInt256.land (getRewardOwedCometWord I) solcAddrMask)) - (UInt256.land (getRewardOwedAccountWord I) solcAddrMask) - (le_trans (by norm_num) <| - getRewardOwedClaimedInnerHashMem_size_ge320 I slot0 multiplier houtSize) - rw [hhash] - rw [solcAddrMask_clean - (by simpa [getRewardOwedCometWord, calldataWord] using hcanonComet)] - rw [solcAddrMask_clean - (by simpa [getRewardOwedAccountWord, calldataWord] using hcanonAccount)] - rw [getRewardOwedRewardsClaimedSlotOf_eq_solc I hcanonComet hcanonAccount] - -theorem getRewardOwedBaseTrackingSelectorMem_size_ge352 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - 352 ≤ (getRewardOwedBaseTrackingSelectorMem I slot0 multiplier out).size := by - unfold getRewardOwedBaseTrackingSelectorMem - have hsize := writeWord_size - (getRewardOwedClaimedOuterHashMem I slot0 multiplier out) 320 - (UInt256.shiftLeft (⟨719776253⟩ : UInt256) ⟨226⟩) - (by - have hge := getRewardOwedClaimedOuterHashMem_size_ge320 I slot0 multiplier houtSize - have hle : 320 - - (getRewardOwedClaimedOuterHashMem I slot0 multiplier out).size = 0 := by - omega - rw [hle] - native_decide) - rw [hsize] - exact le_max_right _ _ - -theorem getRewardOwedBaseTrackingCalldataMem_size_ge356 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - 356 ≤ (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier out).size := by - unfold getRewardOwedBaseTrackingCalldataMem - have hsize := writeWord_size - (getRewardOwedBaseTrackingSelectorMem I slot0 multiplier out) 324 - (getRewardOwedAccountWord I) - (by - have hge := getRewardOwedBaseTrackingSelectorMem_size_ge352 - I slot0 multiplier houtSize - have hle : 324 - - (getRewardOwedBaseTrackingSelectorMem I slot0 multiplier out).size = 0 := by - omega - rw [hle] - native_decide) - rw [hsize] - have hge := getRewardOwedBaseTrackingSelectorMem_size_ge352 - I slot0 multiplier houtSize - omega - -theorem getRewardOwedBaseTrackingCalldataMem_read320_4 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier out).readWithPadding - 320 4 = - baseTrackingAccruedSelector := by - unfold getRewardOwedBaseTrackingCalldataMem - unfold Reasoning.Theory.writeWord - rw [write32_read_below_len _ _ 324 320 4 (by rw [toByteArray_size]) - (by - have hge := getRewardOwedBaseTrackingSelectorMem_size_ge352 - I slot0 multiplier houtSize - omega) - (by norm_num) - (by - have hge := getRewardOwedBaseTrackingSelectorMem_size_ge352 - I slot0 multiplier houtSize - omega) - (by norm_num) (by norm_num)] - unfold getRewardOwedBaseTrackingSelectorMem - rw [writeWord_read_window - (getRewardOwedClaimedOuterHashMem I slot0 multiplier out) 320 0 4 - (UInt256.shiftLeft (⟨719776253⟩ : UInt256) ⟨226⟩) - (by norm_num) (by norm_num) (by norm_num) - (by - have hge := getRewardOwedClaimedOuterHashMem_size_ge320 - I slot0 multiplier houtSize - have hle : 320 - - (getRewardOwedClaimedOuterHashMem I slot0 multiplier out).size = 0 := by - omega - rw [hle] - native_decide)] - native_decide - -theorem getRewardOwedBaseTrackingCalldataMem_read324_32 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier out).readWithPadding - 324 32 = - UInt256.toByteArray (getRewardOwedAccountWord I) := by - unfold getRewardOwedBaseTrackingCalldataMem - unfold Reasoning.Theory.writeWord - rw [write32_read_back _ _ _ (by rw [toByteArray_size]) - (by - have hge := getRewardOwedBaseTrackingSelectorMem_size_ge352 - I slot0 multiplier houtSize - omega)] - exact toByteArray_extract_all (getRewardOwedAccountWord I) - -theorem getRewardOwedBaseTrackingCalldataMem_read320_36 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier out).readWithPadding - 320 36 = - baseTrackingAccruedSelector ++ UInt256.toByteArray (getRewardOwedAccountWord I) := by - rw [byteArray_readWithPadding_split _ 320 4 32 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) - (by - exact getRewardOwedBaseTrackingCalldataMem_size_ge356 - I slot0 multiplier houtSize)] - rw [getRewardOwedBaseTrackingCalldataMem_read320_4 I slot0 multiplier houtSize, - getRewardOwedBaseTrackingCalldataMem_read324_32 I slot0 multiplier houtSize] - -set_option maxHeartbeats 1000000 in -theorem getRewardOwedBaseTrackingCalldataMem_encode_args - (I : ExecutionEnv) - (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) : - config.externalABI.encode? "baseTrackingAccrued" (getRewardAccruedBaseTrackingArgs I) = - some ((getRewardOwedBaseTrackingCalldataMem I slot0 multiplier out) - |>.readWithPadding 320 getRewardOwedBaseTrackingCallSize.toNat) := by - rw [show getRewardOwedBaseTrackingCallSize.toNat = 36 from rfl] - rw [getRewardOwedBaseTrackingCalldataMem_read320_36 I slot0 multiplier houtSize] - change compoundRewardsExternalABI.encode? "baseTrackingAccrued" - (getRewardAccruedBaseTrackingArgs I) = - some (baseTrackingAccruedSelector ++ UInt256.toByteArray (getRewardOwedAccountWord I)) - have haccountWord : - EVM.word (AccountAddress.ofNat (getRewardOwedAccountWord I).toNat).val = - getRewardOwedAccountWord I := by - change UInt256.ofNat (AccountAddress.ofNat (getRewardOwedAccountWord I).toNat).val = - getRewardOwedAccountWord I - have haddr : - (AccountAddress.ofNat (getRewardOwedAccountWord I).toNat).val = - (getRewardOwedAccountWord I).toNat := by - have hcanonAddr : (getRewardOwedAccountWord I).toNat < AccountAddress.size := by - simpa [EVM.addressModulus, EVM.twoPow, AccountAddress.size] using hcanonAccount - unfold AccountAddress.ofNat - exact Nat.mod_eq_of_lt hcanonAddr - rw [haddr] - exact u256_ofNat_toNat (getRewardOwedAccountWord I) - unfold compoundRewardsExternalABI ABI.encodeCallWithSelector? ABI.encodeABIValues? - simp [getRewardAccruedBaseTrackingArgs, getRewardOwedAccountValue, addr, - ABI.abiTupleHeadSize?, ABI.staticABIEncodedSize?, ABI.isDynamicABIType, - ABI.encodeABIValue?, ABI.encodeABIWord?, ABI.encodeABIValuesFrom?, haccountWord, - word_toBytesBE_toByteArray_eq_toByteArray] - -theorem getRewardOwedBaseTrackingSelectorMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (getRewardOwedBaseTrackingSelectorMem I slot0 multiplier out).readWithPadding 64 32 = - UInt256.toByteArray ⟨320⟩ := by - unfold getRewardOwedBaseTrackingSelectorMem - exact (writeWord_read_preserved - (getRewardOwedClaimedOuterHashMem I slot0 multiplier out) 320 64 - (UInt256.shiftLeft (⟨719776253⟩ : UInt256) ⟨226⟩) - (by - have hge := getRewardOwedClaimedOuterHashMem_size_ge320 I slot0 multiplier houtSize - have hle : - 320 - (getRewardOwedClaimedOuterHashMem I slot0 multiplier out).size = 0 := by - omega - rw [hle] - native_decide) - (by - left - have hge := getRewardOwedClaimedOuterHashMem_size_ge320 I slot0 multiplier houtSize - constructor <;> omega)).trans - (getRewardOwedClaimedOuterHashMem_read64 I slot0 multiplier houtSize) - -theorem getRewardOwedBaseTrackingCalldataMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier out).readWithPadding 64 32 = - UInt256.toByteArray ⟨320⟩ := by - unfold getRewardOwedBaseTrackingCalldataMem - exact (writeWord_read_preserved - (getRewardOwedBaseTrackingSelectorMem I slot0 multiplier out) 324 64 - (getRewardOwedAccountWord I) - (by - have hge := getRewardOwedBaseTrackingSelectorMem_size_ge352 I slot0 multiplier houtSize - have hle : - 324 - (getRewardOwedBaseTrackingSelectorMem I slot0 multiplier out).size = 0 := by - omega - rw [hle] - native_decide) - (by - left - have hge := getRewardOwedBaseTrackingSelectorMem_size_ge352 I slot0 multiplier houtSize - constructor <;> omega)).trans - (getRewardOwedBaseTrackingSelectorMem_read64 I slot0 multiplier houtSize) - -theorem getRewardOwedBaseTrackingPostCallMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) (hbaseSize : baseOut.size < UInt256.size) : - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut).readWithPadding - 64 32 = - UInt256.toByteArray ⟨320⟩ := by - unfold getRewardOwedBaseTrackingPostCallMem - by_cases hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat = 0 - · rw [hlen, byteArray_write_len_zero] - exact getRewardOwedBaseTrackingCalldataMem_read64 I slot0 multiplier haccrueSize - · have hsrc : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat ≤ baseOut.size := - getRewardOwedPostCallLen_le_out_size hbaseSize - rw [write_read_below_gen_extend baseOut - (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier accrueOut) 320 - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat 64 - hlen hsrc - (by - have hge := getRewardOwedBaseTrackingCalldataMem_size_ge356 - I slot0 multiplier haccrueSize - omega) - (by norm_num)] - exact getRewardOwedBaseTrackingCalldataMem_read64 I slot0 multiplier haccrueSize - -theorem getRewardOwedBaseTrackingPostCallMem_size_ge320 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) (hbaseSize : baseOut.size < UInt256.size) : - 320 ≤ (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut).size := by - unfold getRewardOwedBaseTrackingPostCallMem - by_cases hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat = 0 - · rw [hlen, byteArray_write_len_zero] - have hge := getRewardOwedBaseTrackingCalldataMem_size_ge356 I slot0 multiplier haccrueSize - omega - · have hsrc : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat ≤ baseOut.size := - getRewardOwedPostCallLen_le_out_size hbaseSize - let len := (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat - let base := getRewardOwedBaseTrackingCalldataMem I slot0 multiplier accrueOut - have hdest : 320 ≤ base.size := by - have hge := getRewardOwedBaseTrackingCalldataMem_size_ge356 I slot0 multiplier - haccrueSize - simpa [base] using le_trans (by norm_num : 320 ≤ 356) hge - by_cases hin : 320 + len ≤ base.size - · rw [write_eq_gen baseOut base 320 len (by simpa [len] using hlen) - (by simpa [len] using hsrc) hin] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract] - omega - · have hext : base.size < 320 + len := Nat.lt_of_not_ge hin - rw [write_eq_gen_extend baseOut base 320 len (by simpa [len] using hlen) - (by simpa [len] using hsrc) hdest hext] - rw [ByteArray.size_append, ByteArray.size_extract, ByteArray.size_extract] - omega - -theorem getRewardOwedBaseTrackingPostCallMem_mload64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut).size - ∨ (⟨64⟩ : UInt256) ≥ getRewardOwedBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) - |>.readWithPadding (⟨64⟩ : UInt256).toNat 32))) = ⟨320⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := getRewardOwedBaseTrackingPostCallAw) - (v := ⟨320⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - have hge := getRewardOwedBaseTrackingPostCallMem_size_ge320 - I slot0 multiplier haccrueSize hbaseSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact getRewardOwedBaseTrackingPostCallMem_read64 - I slot0 multiplier haccrueSize hbaseSize) - -theorem getRewardOwedBaseTrackingPostCallMem_read320_of_size_ge - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut).readWithPadding - 320 32 = - baseOut.extract 0 32 := by - unfold getRewardOwedBaseTrackingPostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := baseOut.size) - (by decide) hout32 hbaseSize - rw [hlen] - exact write32_read_back baseOut - (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier accrueOut) - 320 hout32 - (by - have hge := getRewardOwedBaseTrackingCalldataMem_size_ge356 - I slot0 multiplier haccrueSize - omega) - -theorem getRewardOwedBaseTrackingPostCallMem_size_ge352 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - 352 ≤ (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut).size := by - unfold getRewardOwedBaseTrackingPostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := baseOut.size) - (by decide) hout32 hbaseSize - rw [hlen] - rw [write32_eq baseOut - (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier accrueOut) 320 hout32 - (by - have hge := getRewardOwedBaseTrackingCalldataMem_size_ge356 - I slot0 multiplier haccrueSize - omega)] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract] - have hbase := getRewardOwedBaseTrackingCalldataMem_size_ge356 I slot0 multiplier - haccrueSize - omega - -theorem getRewardOwedBaseTrackingPostCallMem_mload320_haw : - ¬ (⟨320⟩ : UInt256) ≥ getRewardOwedBaseTrackingPostCallAw * ⟨32⟩ := by - native_decide - -theorem getRewardOwedBaseTrackingPostCallMem_mload320_of_size_ge - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨320⟩ : UInt256).toNat ≥ - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut).size - ∨ (⟨320⟩ : UInt256) ≥ getRewardOwedBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) - |>.readWithPadding (⟨320⟩ : UInt256).toNat 32))) = - getRewardOwedBaseTrackingReturnWord baseOut := by - exact mloadValue_eq_readWithPadding_of_lt_size - (mem := getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) - (aw := getRewardOwedBaseTrackingPostCallAw) - (off := ⟨320⟩) - (memSize := (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut).size) - rfl - (by - rw [show (⟨320⟩ : UInt256).toNat = 320 from by decide] - exact lt_of_lt_of_le (by omega) - (getRewardOwedBaseTrackingPostCallMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize)) - getRewardOwedBaseTrackingPostCallMem_mload320_haw - |>.trans (by - rw [show (⟨320⟩ : UInt256).toNat = 320 from by decide, - getRewardOwedBaseTrackingPostCallMem_read320_of_size_ge - I slot0 multiplier haccrueSize hout32 hbaseSize] - ) - -theorem getRewardOwedBaseTrackingPostDecodeMem_read320_of_size_ge - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).readWithPadding - 320 32 = - baseOut.extract 0 32 := by - unfold getRewardOwedBaseTrackingPostDecodeMem - rw [writeWord_read_preserved] - · exact getRewardOwedBaseTrackingPostCallMem_read320_of_size_ge - I slot0 multiplier haccrueSize hout32 hbaseSize - · have hge := getRewardOwedBaseTrackingPostCallMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize - have hle : - 64 - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut).size = - 0 := by - omega - rw [hle] - native_decide - · right - have hge := getRewardOwedBaseTrackingPostCallMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize - constructor <;> omega - -theorem getRewardOwedBaseTrackingPostDecodeMem_mload320_of_size_ge - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨320⟩ : UInt256).toNat ≥ - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).size - ∨ (⟨320⟩ : UInt256) ≥ getRewardOwedBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - |>.readWithPadding (⟨320⟩ : UInt256).toNat 32))) = - getRewardOwedBaseTrackingReturnWord baseOut := by - exact mloadValue_eq_readWithPadding_of_lt_size - (mem := getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - (aw := getRewardOwedBaseTrackingPostCallAw) - (off := ⟨320⟩) - (memSize := - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).size) - rfl - (by - rw [show (⟨320⟩ : UInt256).toNat = 320 from by decide] - unfold getRewardOwedBaseTrackingPostDecodeMem - rw [writeWord_size] - · have hsz := getRewardOwedBaseTrackingPostCallMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize - omega - · have hsz := getRewardOwedBaseTrackingPostCallMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize - have hle : - 64 - - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut).size = - 0 := by - omega - rw [hle] - native_decide) - getRewardOwedBaseTrackingPostCallMem_mload320_haw - |>.trans (by - rw [show (⟨320⟩ : UInt256).toNat = 320 from by decide, - getRewardOwedBaseTrackingPostDecodeMem_read320_of_size_ge - I slot0 multiplier haccrueSize hout32 hbaseSize] - ) - -theorem getRewardOwedBaseTrackingPostDecodeMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).readWithPadding - 64 32 = - UInt256.toByteArray ⟨352⟩ := by - unfold getRewardOwedBaseTrackingPostDecodeMem - exact writeWord_read_back - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) 64 - (⟨352⟩ : UInt256) - (by - have hge := getRewardOwedBaseTrackingPostCallMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize - have hle : - 64 - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut).size = - 0 := by - omega - rw [hle] - native_decide) - -theorem getRewardOwedBaseTrackingPostDecodeMem_size_ge352 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - 352 ≤ - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).size := by - unfold getRewardOwedBaseTrackingPostDecodeMem - rw [writeWord_size] - · exact getRewardOwedBaseTrackingPostCallMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize - |>.trans (le_max_left _ _) - · have hge := getRewardOwedBaseTrackingPostCallMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize - have hle : - 64 - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut).size = - 0 := by - omega - rw [hle] - native_decide - -theorem getRewardOwedBaseTrackingPostDecodeMem_mload64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).size - ∨ (⟨64⟩ : UInt256) ≥ getRewardOwedBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - |>.readWithPadding (⟨64⟩ : UInt256).toNat 32))) = ⟨352⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := getRewardOwedBaseTrackingPostCallAw) - (v := ⟨352⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - have hge := getRewardOwedBaseTrackingPostDecodeMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact getRewardOwedBaseTrackingPostDecodeMem_read64 - I slot0 multiplier haccrueSize hout32 hbaseSize) - -theorem twoWordHashMem_read_above64_of_ge {mem : ByteArray} (key slot : UInt256) - {read : ℕ} (hmem : read + 32 ≤ mem.size) (habove : 64 ≤ read) : - (twoWordHashMem key slot mem).readWithPadding read 32 = - mem.readWithPadding read 32 := by - unfold twoWordHashMem wordAt32Mem - rw [write32_read_above _ _ 32 read (by rw [toByteArray_size]) - (by rw [wordAt0Mem_size_of_ge key (by omega)]; omega) (by omega) - (by rw [wordAt0Mem_size_of_ge key (by omega)]; omega)] - unfold wordAt0Mem - rw [write32_read_above _ _ 0 read (by rw [toByteArray_size]) - (by omega) (by omega) hmem] - -theorem getRewardOwedAccrueAccountPostCallMem_read_below320 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {out : ByteArray} - (houtSize : out.size < UInt256.size) {read : ℕ} (hbelow : read + 32 ≤ 320) : - (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier out).readWithPadding - read 32 = - (getRewardOwedAccrueAccountCalldataMem I slot0 multiplier).readWithPadding read 32 := by - dsimp [getRewardOwedAccrueAccountPostCallMem] - have hle : (⟨0⟩ : UInt256) ≤ UInt256.ofNat out.size := by - change (0 : Nat) ≤ (UInt256.ofNat out.size).toNat - exact Nat.zero_le _ - rw [show (min (⟨0⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 0 by - simp [min, hle]] - rw [byteArray_write_len_zero] - -theorem getRewardOwedBaseTrackingPostCallMem_read_below320 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) (hbaseSize : baseOut.size < UInt256.size) - {read : ℕ} (hbelow : read + 32 ≤ 320) : - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut).readWithPadding - read 32 = - (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier accrueOut).readWithPadding - read 32 := by - unfold getRewardOwedBaseTrackingPostCallMem - by_cases hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat = 0 - · rw [hlen, byteArray_write_len_zero] - · have hsrc : - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat ≤ baseOut.size := - getRewardOwedPostCallLen_le_out_size hbaseSize - rw [write_read_below_gen_extend baseOut - (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier accrueOut) 320 - (min (⟨32⟩ : UInt256) (UInt256.ofNat baseOut.size)).toNat read - hlen hsrc - (by - have hge := getRewardOwedBaseTrackingCalldataMem_size_ge356 - I slot0 multiplier haccrueSize - omega) - hbelow] - -theorem getRewardOwedConfigMultiplierMem_read224 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (getRewardOwedConfigMultiplierMem I slot0 multiplier).readWithPadding 224 32 = - UInt256.toByteArray (rewardConfigRescaleFromSlot0 slot0) := by - unfold getRewardOwedConfigMultiplierMem - rw [writeWord_read_preserved] - · unfold getRewardOwedConfigShouldMem - rw [writeWord_read_preserved] - · unfold getRewardOwedConfigRescaleMem - exact writeWord_read_back (getRewardOwedConfigTokenMem I slot0) 224 - (rewardConfigRescaleFromSlot0 slot0) - (by rw [getRewardOwedConfigTokenMem_size]; native_decide) - · rw [getRewardOwedConfigRescaleMem_size] - native_decide - · left - rw [getRewardOwedConfigRescaleMem_size] - constructor <;> norm_num - · rw [getRewardOwedConfigShouldMem_size] - native_decide - · left - rw [getRewardOwedConfigShouldMem_size] - constructor <;> norm_num - -theorem getRewardOwedConfigMultiplierMem_read256 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (getRewardOwedConfigMultiplierMem I slot0 multiplier).readWithPadding 256 32 = - UInt256.toByteArray (rewardConfigShouldUpscaleFromSlot0 slot0) := by - unfold getRewardOwedConfigMultiplierMem - rw [writeWord_read_preserved] - · unfold getRewardOwedConfigShouldMem - exact writeWord_read_back (getRewardOwedConfigRescaleMem I slot0) 256 - (rewardConfigShouldUpscaleFromSlot0 slot0) - (by rw [getRewardOwedConfigRescaleMem_size]; native_decide) - · rw [getRewardOwedConfigShouldMem_size] - native_decide - · left - rw [getRewardOwedConfigShouldMem_size] - constructor <;> norm_num - -theorem getRewardOwedConfigMultiplierMem_read288 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (getRewardOwedConfigMultiplierMem I slot0 multiplier).readWithPadding 288 32 = - UInt256.toByteArray multiplier := by - unfold getRewardOwedConfigMultiplierMem - exact writeWord_read_back (getRewardOwedConfigShouldMem I slot0) 288 multiplier - (by rw [getRewardOwedConfigShouldMem_size]; native_decide) - -theorem getRewardOwedConfigMultiplierMem_read192 - (I : ExecutionEnv) (slot0 multiplier : UInt256) : - (getRewardOwedConfigMultiplierMem I slot0 multiplier).readWithPadding 192 32 = - UInt256.toByteArray (rewardConfigTokenFromSlot0 slot0) := by - unfold getRewardOwedConfigMultiplierMem - rw [writeWord_read_preserved] - · unfold getRewardOwedConfigShouldMem - rw [writeWord_read_preserved] - · unfold getRewardOwedConfigRescaleMem - rw [writeWord_read_preserved] - · unfold getRewardOwedConfigTokenMem - exact writeWord_read_back (getRewardOwedConfigAllocMem I) 192 - (rewardConfigTokenFromSlot0 slot0) - (by rw [getRewardOwedConfigAllocMem_size]; native_decide) - · rw [getRewardOwedConfigTokenMem_size] - native_decide - · left - rw [getRewardOwedConfigTokenMem_size] - constructor <;> norm_num - · rw [getRewardOwedConfigRescaleMem_size] - native_decide - · left - rw [getRewardOwedConfigRescaleMem_size] - constructor <;> norm_num - · rw [getRewardOwedConfigShouldMem_size] - native_decide - · left - rw [getRewardOwedConfigShouldMem_size] - constructor <;> norm_num - -theorem getRewardOwedBaseTrackingPostDecodeMem_read_config - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) (hbaseSize : baseOut.size < UInt256.size) - {read : ℕ} (hbelow : read + 32 ≤ 320) (habove : 96 ≤ read) {val : UInt256} - (hcfg : - (getRewardOwedConfigMultiplierMem I slot0 multiplier).readWithPadding read 32 = - UInt256.toByteArray val) : - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).readWithPadding - read 32 = - UInt256.toByteArray val := by - unfold getRewardOwedBaseTrackingPostDecodeMem - rw [writeWord_read_preserved] - · rw [getRewardOwedBaseTrackingPostCallMem_read_below320 - I slot0 multiplier haccrueSize hbaseSize hbelow] - unfold getRewardOwedBaseTrackingCalldataMem - rw [writeWord_read_preserved] - · unfold getRewardOwedBaseTrackingSelectorMem - rw [writeWord_read_preserved] - · unfold getRewardOwedClaimedOuterHashMem - rw [twoWordHashMem_read_above64_of_ge] - · unfold getRewardOwedClaimedInnerHashMem - rw [twoWordHashMem_read_above64_of_ge] - · unfold getRewardOwedAccrueAccountAfterAllocMem - rw [writeWord_read_preserved] - · rw [getRewardOwedAccrueAccountPostCallMem_read_below320 - I slot0 multiplier haccrueSize hbelow] - unfold getRewardOwedAccrueAccountCalldataMem - rw [writeWord_read_preserved] - · unfold getRewardOwedAccrueAccountSelectorMem - rw [writeWord_read_preserved] - · exact hcfg - · rw [getRewardOwedConfigMultiplierMem_size] - native_decide - · left - rw [getRewardOwedConfigMultiplierMem_size] - exact ⟨hbelow, hbelow⟩ - · have hge := getRewardOwedAccrueAccountSelectorMem_size - I slot0 multiplier - have hle : - 324 - (getRewardOwedAccrueAccountSelectorMem I slot0 multiplier).size = - 0 := by - rw [hge] - rw [hle] - native_decide - · left - have hsz := getRewardOwedAccrueAccountSelectorMem_size I slot0 multiplier - rw [hsz] - constructor <;> omega - · have hge := getRewardOwedAccrueAccountPostCallMem_size_ge320 - I slot0 multiplier haccrueSize - have hle : - 64 - (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier accrueOut).size = - 0 := by - omega - rw [hle] - native_decide - · right - have hge := getRewardOwedAccrueAccountPostCallMem_size_ge320 - I slot0 multiplier haccrueSize - constructor <;> omega - · have hge := getRewardOwedAccrueAccountAfterAllocMem_size_ge320 - I slot0 multiplier haccrueSize - omega - · omega - · have hge := getRewardOwedClaimedInnerHashMem_size_ge320 - I slot0 multiplier haccrueSize - omega - · omega - · have hge := getRewardOwedClaimedOuterHashMem_size_ge320 - I slot0 multiplier haccrueSize - have hle : - 320 - (getRewardOwedClaimedOuterHashMem I slot0 multiplier accrueOut).size = 0 := by - omega - rw [hle] - native_decide - · left - have hge := getRewardOwedClaimedOuterHashMem_size_ge320 - I slot0 multiplier haccrueSize - constructor <;> omega - · have hge := getRewardOwedBaseTrackingSelectorMem_size_ge352 - I slot0 multiplier haccrueSize - have hle : - 324 - (getRewardOwedBaseTrackingSelectorMem I slot0 multiplier accrueOut).size = 0 := by - omega - rw [hle] - native_decide - · left - have hge := getRewardOwedBaseTrackingSelectorMem_size_ge352 - I slot0 multiplier haccrueSize - constructor <;> omega - · have hge := getRewardOwedBaseTrackingPostCallMem_size_ge320 - I slot0 multiplier haccrueSize hbaseSize - have hle : - 64 - - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut).size = 0 := by - omega - rw [hle] - native_decide - · right - have hge := getRewardOwedBaseTrackingPostCallMem_size_ge320 - I slot0 multiplier haccrueSize hbaseSize - constructor <;> omega - -theorem getRewardOwedBaseTrackingPostDecodeMem_read224 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) (hbaseSize : baseOut.size < UInt256.size) : - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).readWithPadding - 224 32 = - UInt256.toByteArray (rewardConfigRescaleFromSlot0 slot0) := - getRewardOwedBaseTrackingPostDecodeMem_read_config - I slot0 multiplier haccrueSize hbaseSize (by norm_num) (by norm_num) - (getRewardOwedConfigMultiplierMem_read224 I slot0 multiplier) - -theorem getRewardOwedBaseTrackingPostDecodeMem_read192 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) (hbaseSize : baseOut.size < UInt256.size) : - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).readWithPadding - 192 32 = - UInt256.toByteArray (rewardConfigTokenFromSlot0 slot0) := - getRewardOwedBaseTrackingPostDecodeMem_read_config - I slot0 multiplier haccrueSize hbaseSize (by norm_num) (by norm_num) - (getRewardOwedConfigMultiplierMem_read192 I slot0 multiplier) - -theorem getRewardOwedBaseTrackingPostDecodeMem_read256 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) (hbaseSize : baseOut.size < UInt256.size) : - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).readWithPadding - 256 32 = - UInt256.toByteArray (rewardConfigShouldUpscaleFromSlot0 slot0) := - getRewardOwedBaseTrackingPostDecodeMem_read_config - I slot0 multiplier haccrueSize hbaseSize (by norm_num) (by norm_num) - (getRewardOwedConfigMultiplierMem_read256 I slot0 multiplier) - -theorem getRewardOwedBaseTrackingPostDecodeMem_read288 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) (hbaseSize : baseOut.size < UInt256.size) : - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).readWithPadding - 288 32 = - UInt256.toByteArray multiplier := - getRewardOwedBaseTrackingPostDecodeMem_read_config - I slot0 multiplier haccrueSize hbaseSize (by norm_num) (by norm_num) - (getRewardOwedConfigMultiplierMem_read288 I slot0 multiplier) - -theorem getRewardOwedBaseTrackingPostDecodeMem_mload224 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨224⟩ : UInt256).toNat ≥ - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).size - ∨ (⟨224⟩ : UInt256) ≥ getRewardOwedBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - |>.readWithPadding (⟨224⟩ : UInt256).toNat 32))) = - rewardConfigRescaleFromSlot0 slot0 := by - exact mloadWordValue_of_readWithPadding - (off := (⟨224⟩ : UInt256)) (aw := getRewardOwedBaseTrackingPostCallAw) - (v := rewardConfigRescaleFromSlot0 slot0) - (by - rw [show (⟨224⟩ : UInt256).toNat = 224 from by decide] - have hge := getRewardOwedBaseTrackingPostDecodeMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize - omega) - (by native_decide) - (by - rw [show (⟨224⟩ : UInt256).toNat = 224 from by decide] - exact getRewardOwedBaseTrackingPostDecodeMem_read224 - I slot0 multiplier haccrueSize hbaseSize) - -theorem getRewardOwedBaseTrackingPostDecodeMem_mload192 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨192⟩ : UInt256).toNat ≥ - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).size - ∨ (⟨192⟩ : UInt256) ≥ getRewardOwedBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - |>.readWithPadding (⟨192⟩ : UInt256).toNat 32))) = - rewardConfigTokenFromSlot0 slot0 := by - exact mloadWordValue_of_readWithPadding - (off := (⟨192⟩ : UInt256)) (aw := getRewardOwedBaseTrackingPostCallAw) - (v := rewardConfigTokenFromSlot0 slot0) - (by - rw [show (⟨192⟩ : UInt256).toNat = 192 from by decide] - have hge := getRewardOwedBaseTrackingPostDecodeMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize - omega) - (by native_decide) - (by - rw [show (⟨192⟩ : UInt256).toNat = 192 from by decide] - exact getRewardOwedBaseTrackingPostDecodeMem_read192 - I slot0 multiplier haccrueSize hbaseSize) - -theorem getRewardOwedBaseTrackingPostDecodeMem_mload256 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨256⟩ : UInt256).toNat ≥ - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).size - ∨ (⟨256⟩ : UInt256) ≥ getRewardOwedBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - |>.readWithPadding (⟨256⟩ : UInt256).toNat 32))) = - rewardConfigShouldUpscaleFromSlot0 slot0 := by - exact mloadWordValue_of_readWithPadding - (off := (⟨256⟩ : UInt256)) (aw := getRewardOwedBaseTrackingPostCallAw) - (v := rewardConfigShouldUpscaleFromSlot0 slot0) - (by - rw [show (⟨256⟩ : UInt256).toNat = 256 from by decide] - have hge := getRewardOwedBaseTrackingPostDecodeMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize - omega) - (by native_decide) - (by - rw [show (⟨256⟩ : UInt256).toNat = 256 from by decide] - exact getRewardOwedBaseTrackingPostDecodeMem_read256 - I slot0 multiplier haccrueSize hbaseSize) - -theorem getRewardOwedBaseTrackingPostDecodeMem_mload288 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨288⟩ : UInt256).toNat ≥ - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut).size - ∨ (⟨288⟩ : UInt256) ≥ getRewardOwedBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - |>.readWithPadding (⟨288⟩ : UInt256).toNat 32))) = - multiplier := by - exact mloadWordValue_of_readWithPadding - (off := (⟨288⟩ : UInt256)) (aw := getRewardOwedBaseTrackingPostCallAw) - (v := multiplier) - (by - rw [show (⟨288⟩ : UInt256).toNat = 288 from by decide] - have hge := getRewardOwedBaseTrackingPostDecodeMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize - omega) - (by native_decide) - (by - rw [show (⟨288⟩ : UInt256).toNat = 288 from by decide] - exact getRewardOwedBaseTrackingPostDecodeMem_read288 - I slot0 multiplier haccrueSize hbaseSize) - -theorem rewardConfigTokenFromSlot0_clean (slot0 : UInt256) : - UInt256.land (rewardConfigTokenFromSlot0 slot0) solcAddrMask = - rewardConfigTokenFromSlot0 slot0 := by - simpa [rewardConfigTokenFromSlot0] using - solcAddrMask_clean (solcAddrMask_result_canonical slot0) - -theorem getRewardOwedReturnAllocMem_size_ge352 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - 352 ≤ (getRewardOwedReturnAllocMem I slot0 multiplier accrueOut baseOut).size := by - unfold getRewardOwedReturnAllocMem - rw [writeWord_size] - · exact (getRewardOwedBaseTrackingPostDecodeMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize).trans (le_max_left _ _) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 64 (by norm_num)) - -theorem getRewardOwedReturnStructTokenMem_size_ge384 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - 384 ≤ - (getRewardOwedReturnStructTokenMem I slot0 multiplier accrueOut baseOut).size := by - unfold getRewardOwedReturnStructTokenMem - rw [writeWord_size] - · omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 352 (by norm_num)) - -theorem getRewardOwedReturnStructOwedMem_size_ge416 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (owed : UInt256) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - 416 ≤ - (getRewardOwedReturnStructOwedMem I slot0 multiplier accrueOut baseOut owed).size := by - unfold getRewardOwedReturnStructOwedMem - rw [writeWord_size] - · omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 384 (by norm_num)) - -theorem getRewardOwedReturnCopyTokenMem_size_ge448 - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) - (owed : UInt256) : - 448 ≤ (getRewardOwedReturnCopyTokenMem I slot0 multiplier accrueOut baseOut owed).size := by - unfold getRewardOwedReturnCopyTokenMem - rw [writeWord_size] - · omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 416 (by norm_num)) - -theorem getRewardOwedReturnMem_size_ge480 - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) - (owed : UInt256) : - 480 ≤ (getRewardOwedReturnMem I slot0 multiplier accrueOut baseOut owed).size := by - unfold getRewardOwedReturnMem - rw [writeWord_size] - · omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 448 (by norm_num)) - -theorem getRewardOwedReturnAllocMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) : - (getRewardOwedReturnAllocMem I slot0 multiplier accrueOut baseOut).readWithPadding - 64 32 = - UInt256.toByteArray (⟨416⟩ : UInt256) := by - unfold getRewardOwedReturnAllocMem - exact writeWord_read_back - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) 64 - (⟨416⟩ : UInt256) - (lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 64 (by norm_num))) - -theorem getRewardOwedReturnStructTokenMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (getRewardOwedReturnStructTokenMem I slot0 multiplier accrueOut baseOut).readWithPadding - 64 32 = - UInt256.toByteArray (⟨416⟩ : UInt256) := by - unfold getRewardOwedReturnStructTokenMem - rw [writeWord_read_preserved] - · exact getRewardOwedReturnAllocMem_read64 I slot0 multiplier accrueOut baseOut - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 352 (by norm_num)) - · left - constructor - · norm_num - · have hsz := getRewardOwedReturnAllocMem_size_ge352 - I slot0 multiplier haccrueSize hout32 hbaseSize - omega - -theorem getRewardOwedReturnStructOwedMem_read64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (owed : UInt256) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (getRewardOwedReturnStructOwedMem I slot0 multiplier accrueOut baseOut owed).readWithPadding - 64 32 = - UInt256.toByteArray (⟨416⟩ : UInt256) := by - unfold getRewardOwedReturnStructOwedMem - rw [writeWord_read_preserved] - · exact getRewardOwedReturnStructTokenMem_read64 - I slot0 multiplier haccrueSize hout32 hbaseSize - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 384 (by norm_num)) - · left - constructor - · norm_num - · have hsz := getRewardOwedReturnStructTokenMem_size_ge384 - I slot0 multiplier haccrueSize hout32 hbaseSize - omega - -theorem getRewardOwedReturnStructOwedMem_mload64 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (owed : UInt256) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ - (getRewardOwedReturnStructOwedMem I slot0 multiplier accrueOut baseOut owed).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 13 * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((getRewardOwedReturnStructOwedMem I slot0 multiplier accrueOut baseOut owed) - |>.readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - ⟨416⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := UInt256.ofNat 13) (v := ⟨416⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - have hsz := getRewardOwedReturnStructOwedMem_size_ge416 - I slot0 multiplier owed haccrueSize hout32 hbaseSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact getRewardOwedReturnStructOwedMem_read64 - I slot0 multiplier owed haccrueSize hout32 hbaseSize) - -theorem getRewardOwedReturnMem_readWord416 - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) - (owed : UInt256) : - (getRewardOwedReturnMem I slot0 multiplier accrueOut baseOut owed).readWithPadding - 416 32 = - UInt256.toByteArray (rewardConfigTokenFromSlot0 slot0) := by - unfold getRewardOwedReturnMem - rw [writeWord_read_preserved] - · unfold getRewardOwedReturnCopyTokenMem - exact writeWord_read_back - (getRewardOwedReturnStructOwedMem I slot0 multiplier accrueOut baseOut owed) 416 - (rewardConfigTokenFromSlot0 slot0) - (lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 416 (by norm_num))) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 448 (by norm_num)) - · left - constructor - · norm_num - · exact getRewardOwedReturnCopyTokenMem_size_ge448 - I slot0 multiplier accrueOut baseOut owed - -theorem getRewardOwedReturnMem_readWord448 - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) - (owed : UInt256) : - (getRewardOwedReturnMem I slot0 multiplier accrueOut baseOut owed).readWithPadding - 448 32 = - UInt256.toByteArray owed := by - unfold getRewardOwedReturnMem - exact writeWord_read_back - (getRewardOwedReturnCopyTokenMem I slot0 multiplier accrueOut baseOut owed) 448 owed - (lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 448 (by norm_num))) - -theorem getRewardOwedReturnStructOwedMem_read384 - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) - (owed : UInt256) : - (getRewardOwedReturnStructOwedMem I slot0 multiplier accrueOut baseOut owed).readWithPadding - 384 32 = - UInt256.toByteArray owed := by - unfold getRewardOwedReturnStructOwedMem - exact writeWord_read_back - (getRewardOwedReturnStructTokenMem I slot0 multiplier accrueOut baseOut) 384 owed - (lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 384 (by norm_num))) - -theorem getRewardOwedReturnCopyTokenMem_read384 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (owed : UInt256) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (getRewardOwedReturnCopyTokenMem I slot0 multiplier accrueOut baseOut owed).readWithPadding - 384 32 = - UInt256.toByteArray owed := by - unfold getRewardOwedReturnCopyTokenMem - rw [writeWord_read_preserved] - · exact getRewardOwedReturnStructOwedMem_read384 - I slot0 multiplier accrueOut baseOut owed - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 416 (by norm_num)) - · left - constructor - · norm_num - · have hsz := getRewardOwedReturnStructOwedMem_size_ge416 - I slot0 multiplier owed haccrueSize hout32 hbaseSize - omega - -theorem getRewardOwedReturnCopyTokenMem_mload384 - (I : ExecutionEnv) (slot0 multiplier : UInt256) {accrueOut baseOut : ByteArray} - (owed : UInt256) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - (if (⟨384⟩ : UInt256).toNat ≥ - (getRewardOwedReturnCopyTokenMem I slot0 multiplier accrueOut baseOut owed).size - ∨ (⟨384⟩ : UInt256) ≥ UInt256.ofNat 14 * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((getRewardOwedReturnCopyTokenMem I slot0 multiplier accrueOut baseOut owed) - |>.readWithPadding (⟨384⟩ : UInt256).toNat 32))) = - owed := by - exact mloadWordValue_of_readWithPadding - (off := (⟨384⟩ : UInt256)) (aw := UInt256.ofNat 14) (v := owed) - (by - rw [show (⟨384⟩ : UInt256).toNat = 384 from by decide] - have hsz := getRewardOwedReturnCopyTokenMem_size_ge448 - I slot0 multiplier accrueOut baseOut owed - omega) - (by native_decide) - (by - rw [show (⟨384⟩ : UInt256).toNat = 384 from by decide] - exact getRewardOwedReturnCopyTokenMem_read384 - I slot0 multiplier owed haccrueSize hout32 hbaseSize) - -theorem getRewardOwedReturnMem_read416 - (I : ExecutionEnv) (slot0 multiplier : UInt256) (accrueOut baseOut : ByteArray) - (owed : UInt256) : - (getRewardOwedReturnMem I slot0 multiplier accrueOut baseOut owed).readWithPadding 416 64 = - getRewardOwedReturnBytes (rewardConfigTokenFromSlot0 slot0) owed := by - rw [byteArray_readWithPadding_split _ 416 32 32 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num)] - · rw [getRewardOwedReturnMem_readWord416, getRewardOwedReturnMem_readWord448] - rfl - · exact getRewardOwedReturnMem_size_ge480 I slot0 multiplier accrueOut baseOut owed - -theorem getRewardOwedEncodeReturnValue_tuple (slot0 owed : UInt256) : - encodeReturnValue? (.tuple [addr, uint256]) - (.tuple [getRewardOwedTokenValueFromSlot0 slot0, .int (Int.ofNat owed.toNat)]) = - some (getRewardOwedReturnBytes (rewardConfigTokenFromSlot0 slot0) owed) := by - have htoken : - encodeABIValue? addr (getRewardOwedTokenValueFromSlot0 slot0) = - some (EVM.Word.toBytesBE (rewardConfigTokenFromSlot0 slot0)) := by - simpa [addr, getRewardOwedTokenValueFromSlot0, rewardConfigTokenFromSlot0] using - rewardConfigEncodeABIValue_masked_address slot0 - have hclaimed : - encodeABIValue? uint256 (.int (Int.ofNat owed.toNat)) = - some (EVM.Word.toBytesBE owed) := by - simpa [uint256, uint256Int] using rewardConfigEncodeABIValue_uint256 owed - have htuple : - encodeABIValue? (.tuple [addr, uint256]) - (.tuple [getRewardOwedTokenValueFromSlot0 slot0, .int (Int.ofNat owed.toNat)]) = - some (EVM.Word.toBytesBE (rewardConfigTokenFromSlot0 slot0) ++ - EVM.Word.toBytesBE owed) := by - simp only [encodeABIValue?] - simp only [encodeABIValues?, encodeABIValuesFrom?, htoken, hclaimed, bind, Option.bind] - simp [addr, uint256, uint256Int, abiTupleHeadSize?, staticABIEncodedSize?, - isDynamicABIType] - unfold getRewardOwedReturnBytes - rw [toByteArray_eq_toBytesBE (rewardConfigTokenFromSlot0 slot0), - toByteArray_eq_toBytesBE owed] - simp only [encodeReturnValue?, encodeReturnValues?, encodeABIValues?, encodeABIValuesFrom?, - htuple, bind, Option.bind] - simp [addr, uint256, uint256Int, abiTupleHeadSize?, staticABIEncodedSize?, - isDynamicABIType] - apply congrArg some - apply ByteArray.ext - simp [ByteArray.data_append] - -theorem getRewardOwedSub_eq_ofNat {accrued claimed : UInt256} - (h : claimed.toNat ≤ accrued.toNat) : - UInt256.sub accrued claimed = - UInt256.ofNat (accrued.toNat - claimed.toNat) := by - apply u256_inj - rw [usub_toNat (a := accrued) (b := claimed) h] - rw [UInt256.toNat_ofNat_of_lt] - exact lt_of_le_of_lt (Nat.sub_le _ _) accrued.val.isLt - -theorem getRewardOwedOwedNat_lt (claimed : UInt256) {accruedNat : ℕ} - (haccrued : accruedNat < UInt256.size) : - (if claimed.toNat < accruedNat then accruedNat - claimed.toNat else 0) < UInt256.size := by - by_cases hlt : claimed.toNat < accruedNat - · simp [hlt] - exact lt_of_le_of_lt (Nat.sub_le _ _) haccrued - · simp [hlt, UInt256.size] - -theorem getRewardOwedReturnOwedWord_of_ofNat - (claimed : UInt256) {accruedNat : ℕ} (haccrued : accruedNat < UInt256.size) : - getRewardOwedReturnOwedWord claimed (UInt256.ofNat accruedNat) = - UInt256.ofNat - (if claimed.toNat < accruedNat then accruedNat - claimed.toNat else 0) := by - unfold getRewardOwedReturnOwedWord - rw [UInt256.toNat_ofNat_of_lt haccrued] - by_cases hlt : claimed.toNat < accruedNat - · simp [hlt] - · simp [hlt] - rfl - -set_option maxHeartbeats 2000000 in -theorem cometRewardsGetRewardOwedX_return_from2519 - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {accrueOut baseOut : ByteArray} - {owed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2519⟩ - [⟨192⟩, solcAddrMask, ⟨32⟩, owed, ⟨64⟩] - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) acc - (getRewardOwedReturnBytes (rewardConfigTokenFromSlot0 slot0) owed) := by - have htokenClean := rewardConfigTokenFromSlot0_clean slot0 - have rd2525₀ := evm_run rd with [ - jumpdest, - raw mload 0 (rewardConfigTokenFromSlot0 slot0) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload192 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - and] - have rd2525 := rd2525₀ - rw [htokenClean] at rd2525 - have rd2976 := evm_run rd2525 with [ - swap2, dup2, dup5, - raw mload 0 (⟨352⟩ : UInt256) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload64 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - push2 ⟨2534⟩, dup2, push2 ⟨2976⟩, jump (by jump_dest), - jumpdest, push1 ⟨64⟩, dup2, add, swap1, dup2, lt, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, lor, - push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩] - have rd2534 := evm_run rd2976 with [ - raw mstore 0 - (getRewardOwedReturnAllocMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold getRewardOwedReturnAllocMem Reasoning.Theory.writeWord - rfl) - (by native_decide) (by evm_ov), - jump (by jump_dest), jumpdest] - have rd2538 := evm_run rd2534 with [ - dup5, dup2, - raw mstore 0 - (getRewardOwedReturnStructTokenMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨352⟩ : UInt256).toNat = 352 from by decide] - unfold getRewardOwedReturnStructTokenMem Reasoning.Theory.writeWord - rfl) - (by native_decide) (by evm_ov)] - have rd2542 := evm_run rd2538 with [ - add, swap1, dup2, - raw mstore 3 - (getRewardOwedReturnStructOwedMem I slot0 multiplier accrueOut baseOut owed) - (UInt256.ofNat 13) (by native_decide) mem_cost - (by - rw [show ((⟨352⟩ : UInt256) + ⟨32⟩).toNat = 384 from by native_decide] - unfold getRewardOwedReturnStructOwedMem Reasoning.Theory.writeWord - rfl) - (by native_decide) (by evm_ov)] - have rd2546 := evm_run rd2542 with [ - dup4, - raw mload 0 (⟨416⟩ : UInt256) - (UInt256.ofNat 13) (by native_decide) mem_cost - (getRewardOwedReturnStructOwedMem_mload64 - I slot0 multiplier owed haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - swap3, dup4, - raw mstore 3 - (getRewardOwedReturnCopyTokenMem I slot0 multiplier accrueOut baseOut owed) - (UInt256.ofNat 14) (by native_decide) mem_cost - (by - rw [show (⟨416⟩ : UInt256).toNat = 416 from by decide] - unfold getRewardOwedReturnCopyTokenMem Reasoning.Theory.writeWord - rfl) - (by native_decide) (by evm_ov)] - have rd2552 := evm_run rd2546 with [ - raw mload 0 owed - (UInt256.ofNat 14) (by native_decide) mem_cost - (by - rw [show ((⟨352⟩ : UInt256) + ⟨32⟩).toNat = 384 from by native_decide] - exact getRewardOwedReturnCopyTokenMem_mload384 - I slot0 multiplier owed haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - swap1, dup3, add, - raw mstore 3 - (getRewardOwedReturnMem I slot0 multiplier accrueOut baseOut owed) - (UInt256.ofNat 15) (by native_decide) mem_cost - (by - rw [show ((⟨416⟩ : UInt256) + ⟨32⟩).toNat = 448 from by native_decide] - unfold getRewardOwedReturnMem Reasoning.Theory.writeWord - rfl) - (by native_decide) (by evm_ov)] - exact evm_run rd2552 with [ - raw ret 0 - (getRewardOwedReturnBytes (rewardConfigTokenFromSlot0 slot0) owed) - (by native_decide) mem_cost - (by - rw [show (⟨416⟩ : UInt256).toNat = 416 from by decide, - show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact getRewardOwedReturnMem_read416 I slot0 multiplier accrueOut baseOut owed) - (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsGetRewardOwedX_return_from2499 - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {accrueOut baseOut : ByteArray} - {accrued claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2499⟩ - [accrued, claimed, ⟨0⟩, solcAddrMask, ⟨32⟩, ⟨192⟩, ⟨64⟩] - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) : - RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) acc - (getRewardOwedReturnBytes (rewardConfigTokenFromSlot0 slot0) - (getRewardOwedReturnOwedWord claimed accrued)) := by - by_cases hgt : claimed.toNat < accrued.toNat - · have hgtWord : UInt256.gt accrued claimed = ⟨1⟩ := ugt_one hgt - have hltWord : UInt256.lt accrued claimed = ⟨0⟩ := ult_zero (le_of_lt hgt) - have hsubWord : - UInt256.sub accrued claimed = - UInt256.ofNat (accrued.toNat - claimed.toNat) := - getRewardOwedSub_eq_ofNat (le_of_lt hgt) - have rd2504₀ := evm_run rd with [jumpdest, dup2, dup2, gt, iszero] - have rd2504 := rd2504₀ - rw [hgtWord, show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ by decide] at rd2504 - have rd3241 := evm_run rd2504 with [ - push2 ⟨2553⟩, jumpiNT (by native_decide), - push2 ⟨2517⟩, swap3, pop, push2 ⟨3241⟩, jump (by jump_dest)] - have rd3249₀ := evm_run rd3241 with [jumpdest, dup2, dup2, lt] - have rd3249 := rd3249₀ - rw [hltWord] at rd3249 - have rd2517 := evm_run rd3249 with [ - push2 ⟨3252⟩, jumpiNT (by native_decide), - sub, swap1, jump (by jump_dest), jumpdest] - have rd2519 := evm_run rd2517 with [swap3] - rw [hsubWord] at rd2519 - simpa [getRewardOwedReturnOwedWord, hgt] using - cometRewardsGetRewardOwedX_return_from2519 - (slot0 := slot0) (multiplier := multiplier) - (accrueOut := accrueOut) (baseOut := baseOut) - (owed := UInt256.ofNat (accrued.toNat - claimed.toNat)) - rd2519 haccrueSize hout32 hbaseSize - · have hle : accrued.toNat ≤ claimed.toNat := by omega - have hgtWord : UInt256.gt accrued claimed = ⟨0⟩ := ugt_zero hle - have rd2504₀ := evm_run rd with [jumpdest, dup2, dup2, gt, iszero] - have rd2504 := rd2504₀ - rw [hgtWord, show UInt256.isZero (⟨0⟩ : UInt256) = ⟨1⟩ by decide] at rd2504 - have rd2519 := evm_run rd2504 with [ - push2 ⟨2553⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, pop, pop, swap3, push2 ⟨2519⟩, jump (by jump_dest)] - simpa [getRewardOwedReturnOwedWord, hgt] using - cometRewardsGetRewardOwedX_return_from2519 - (slot0 := slot0) (multiplier := multiplier) - (accrueOut := accrueOut) (baseOut := baseOut) - (owed := (⟨0⟩ : UInt256)) - rd2519 haccrueSize hout32 hbaseSize - -theorem cometRewardsBaseTrackingAccrued_decode_none_short {out : ByteArray} - (hshort : out.size < 32) : - config.externalABI.decode? "baseTrackingAccrued" out = none := by - change compoundRewardsExternalABI.decode? "baseTrackingAccrued" out = none - unfold compoundRewardsExternalABI decodeReturn? - simpa [uint64] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_uint64_none_short (returndata := out) hshort) - -theorem cometRewardsBaseTrackingAccrued_decode_ok {out : ByteArray} - (hlo : 32 ≤ out.size) (hhi : out.size < 2 ^ 255) - (hword : fromByteArrayBigEndian (out.extract 0 32) < EVM.twoPow 64) : - config.externalABI.decode? "baseTrackingAccrued" out = - some [.int (Int.ofNat (fromByteArrayBigEndian (out.extract 0 32)))] := by - change compoundRewardsExternalABI.decode? "baseTrackingAccrued" out = - some [.int (Int.ofNat (fromByteArrayBigEndian (out.extract 0 32)))] - unfold compoundRewardsExternalABI decodeReturn? - simpa [uint64] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_uint64_ok (returndata := out) hlo hhi hword) - -theorem cometRewardsBaseTrackingAccrued_decode_none_noncanon {out : ByteArray} - (hlo : 32 ≤ out.size) (hhi : out.size < 2 ^ 255) - (hword : ¬ fromByteArrayBigEndian (out.extract 0 32) < EVM.twoPow 64) : - config.externalABI.decode? "baseTrackingAccrued" out = none := by - change compoundRewardsExternalABI.decode? "baseTrackingAccrued" out = none - unfold compoundRewardsExternalABI decodeReturn? - simpa [uint64] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_uint64_none_noncanon (returndata := out) hlo hhi hword) - -theorem getRewardOwedCometTarget_eq_targetWord (I : ExecutionEnv) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) : - EVM.address (getRewardOwedCometTarget I) = - AccountAddress.ofUInt256 (UInt256.land (getRewardOwedCometWord I) solcAddrMask) := by - have hclean : - UInt256.land (getRewardOwedCometWord I) solcAddrMask = getRewardOwedCometWord I := by - exact solcAddrMask_clean (by simpa [getRewardOwedCometWord, calldataWord] using hcanonComet) - rw [hclean, accountAddress_ofUInt256_eq_ofNat_toNat] - apply Fin.ext - simp [EVM.address, EVM.uintN, getRewardOwedCometTarget] - exact Nat.mod_eq_of_lt (AccountAddress.ofNat (getRewardOwedCometWord I).toNat).isLt - -set_option maxHeartbeats 1000000 in -theorem evalExpr_getRewardOwed_extCodeSizeGuard_false - (evm : EVM.State) (I : ExecutionEnv) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hzero : - Reasoning.Theory.extCodeSizeWord evm.accountMap - (UInt256.land (getRewardOwedCometWord I) solcAddrMask) = ⟨0⟩) : - evalExpr? config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (.binary .gt (.extCodeSize (.var "comet")) (.intLit 0)) = .ok (.bool false) := by - have haddr : - AccountAddress.ofNat (getRewardOwedCometWord I).toNat = - AccountAddress.ofUInt256 (UInt256.land (getRewardOwedCometWord I) solcAddrMask) := by - rw [← accountAddress_ofUInt256_eq_ofNat_toNat] - congr 1 - exact (solcAddrMask_clean (by simpa [getRewardOwedCometWord, calldataWord] using - hcanonComet)).symm - simp only [evalExpr?, EvalResult.bind, bind, EvalResult.ofOption] - rw [getRewardOwedConfigLocals_comet] - simp only [getRewardOwedCometValue, haddr, State.lookupAccount] - have hword : - EVM.Word.ofNat - (Option.option 0 (fun acc => acc.code.size) - (evm.accountMap.find? - (AccountAddress.ofUInt256 - (UInt256.land (getRewardOwedCometWord I) solcAddrMask)))) = - (⟨0⟩ : UInt256) := by - cases hacc : evm.accountMap.find? - (AccountAddress.ofUInt256 (UInt256.land (getRewardOwedCometWord I) solcAddrMask)) - · decide - · simpa [Reasoning.Theory.extCodeSizeWord, Function.comp, Option.option, - EVM.Word.ofNat, hacc] using hzero - rw [hword] - decide - -set_option maxHeartbeats 1000000 in -theorem evalExpr_getRewardOwed_extCodeSizeGuard_true - (evm : EVM.State) (I : ExecutionEnv) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hnz : - Reasoning.Theory.extCodeSizeWord evm.accountMap - (UInt256.land (getRewardOwedCometWord I) solcAddrMask) ≠ ⟨0⟩) : - evalExpr? config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (.binary .gt (.extCodeSize (.var "comet")) (.intLit 0)) = .ok (.bool true) := by - have haddr : - AccountAddress.ofNat (getRewardOwedCometWord I).toNat = - AccountAddress.ofUInt256 (UInt256.land (getRewardOwedCometWord I) solcAddrMask) := by - rw [← accountAddress_ofUInt256_eq_ofNat_toNat] - congr 1 - exact (solcAddrMask_clean (by simpa [getRewardOwedCometWord, calldataWord] using - hcanonComet)).symm - simp only [evalExpr?, EvalResult.bind, bind, EvalResult.ofOption] - rw [getRewardOwedConfigLocals_comet] - simp only [getRewardOwedCometValue, haddr, State.lookupAccount] - let codeWord : UInt256 := - EVM.Word.ofNat - (Option.option 0 (fun acc => acc.code.size) - (evm.accountMap.find? - (AccountAddress.ofUInt256 - (UInt256.land (getRewardOwedCometWord I) solcAddrMask)))) - have hwordNZ : codeWord ≠ ⟨0⟩ := by - cases hacc : evm.accountMap.find? - (AccountAddress.ofUInt256 (UInt256.land (getRewardOwedCometWord I) solcAddrMask)) - · simpa [codeWord, Reasoning.Theory.extCodeSizeWord, Function.comp, - Option.option, EVM.Word.ofNat, hacc] using hnz - · simpa [codeWord, Reasoning.Theory.extCodeSizeWord, Function.comp, - Option.option, EVM.Word.ofNat, hacc] using hnz - have hpos : 0 < codeWord.toNat := by - by_contra hnot - have hz : codeWord.toNat = 0 := by omega - exact hwordNZ (u256_inj hz) - have hposInt : (0 : Int) < (codeWord.toNat : Int) := by - exact_mod_cast hpos - change evalBinaryOp? .gt (.int (Int.ofNat codeWord.toNat)) (.int 0) = - .ok (.bool true) - simp [evalBinaryOp?, hposInt] - exact hpos - -theorem cometRewardsDecode_getRewardOwed_ok {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (getRewardOwedTransition.params.map Param.name) - (transitionSignature getRewardOwedTransition).paramTypes I.calldata = - some (getRewardOwedStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "account"] [addr, addr] - I.calldata = _ - simpa [config, getRewardOwedStore, getRewardOwedCometValue, getRewardOwedAccountValue, - getRewardOwedCometWord, getRewardOwedAccountWord, calldataWord] - using decodeCalldata_address_address_ok (cd := I.calldata) (x := "comet") - (y := "account") hsz68 hbig hcanonComet hcanonAccount - -theorem cometRewardsDecode_getRewardOwed_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 68) : - decodeCalldataWithMode config.abiDecodeMode (getRewardOwedTransition.params.map Param.name) - (transitionSignature getRewardOwedTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "account"] [addr, addr] - I.calldata = none - simpa [config, addr] using decodeCalldata_address_address_none_short - (cd := I.calldata) (x := "comet") (y := "account") hsz4 hshort - -theorem cometRewardsDecode_getRewardOwed_none_noncanon_comet {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hncComet : ¬ (getRewardOwedCometWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (getRewardOwedTransition.params.map Param.name) - (transitionSignature getRewardOwedTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "account"] [addr, addr] - I.calldata = none - simpa [config, addr, getRewardOwedCometWord, calldataWord] - using decodeCalldata_address_address_none_noncanon0 - (cd := I.calldata) (x := "comet") (y := "account") hsz68 hbig hncComet - -theorem cometRewardsDecode_getRewardOwed_none_noncanon_account {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hncAccount : ¬ (getRewardOwedAccountWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (getRewardOwedTransition.params.map Param.name) - (transitionSignature getRewardOwedTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "account"] [addr, addr] - I.calldata = none - simpa [config, addr, getRewardOwedCometWord, getRewardOwedAccountWord, calldataWord] - using decodeCalldata_address_address_none_noncanon1 - (cd := I.calldata) (x := "comet") (y := "account") - hsz68 hbig hcanonComet hncAccount - -theorem cometRewardsDecode_getRewardOwed_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (getRewardOwedTransition.params.map Param.name) - (transitionSignature getRewardOwedTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "account"] [addr, addr] - I.calldata = none - simpa [config, addr] using decodeCalldata_address_address_none_huge - (cd := I.calldata) (x := "comet") (y := "account") hbig - -theorem cometRewardsGetRewardOwedSelector_size {I : ExecutionEnv} - (hsel : selIs I (cometRewardsSelBytes 3)) : - 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (cometRewardsSelBytes 3) rfl hsel - -theorem cometRewardsDispatch_getRewardOwed {cd : ByteArray} - (hsel : (cometRewardsSelBytes 3 == cd.extract 0 4) = true) : - dispatchMsg contract cd = some getRewardOwedTransition := by - have hcd : cd.extract 0 4 = cometRewardsSelBytes 3 := - (byteArray_eq_of_beq hsel).symm - refine dispatchMsg_eq_some_of_split - (pre := [claimTransition, claimToTransition]) - (post := [governorTransition, rewardConfigTransition, rewardsClaimedTransition, - setRewardConfigTransition, setRewardConfigWithMultiplierTransition, - setRewardsClaimedTransition, transferGovernorTransition, withdrawTokenTransition]) - rfl rfl ?_ (by rw [selectorOf, getRewardOwedSelectorBytes]; exact hsel) - intro t ht - simp only [List.mem_cons, List.not_mem_nil, or_false] at ht - rcases ht with rfl | rfl - · rw [selectorOf, claimSelectorBytes, hcd] - decide - · rw [selectorOf, claimToSelectorBytes, hcd] - decide - -theorem cometRewardsGetRewardOwedCalldataCheckOk {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hhi : I.calldata.size < 2 ^ 255 + 4) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨0⟩ := - cometRewardsRewardsClaimedCalldataCheckOk (I := I) hsz68 hsize hhi - -theorem cometRewardsGetRewardOwedCalldataCheckShort {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hshort : I.calldata.size < 68) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨1⟩ := - cometRewardsRewardsClaimedCalldataCheckShort (I := I) hsz4 hsize hshort - -theorem cometRewardsGetRewardOwedCalldataCheckHuge {I : ExecutionEnv} - (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨1⟩ := - cometRewardsRewardsClaimedCalldataCheckHuge (I := I) hsize hbig - -theorem cometRewardsGetRewardOwedX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz4 : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hshort : I.calldata.size < 68) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsGetRewardOwedCalldataCheckShort (I := I) hsz4 hsize hshort - obtain ⟨_, _, rd2266⟩ := hreach - have rd2272 := evm_run rd2266 with [jumpdest, pop, swap3, swap1, swap3, callvalue] - rw [hwv] at rd2272 - have rd2283 := evm_run rd2272 with [ - push2 ⟨670⟩, jumpiNT (by decide), - dup3, push1 ⟨3⟩, not, calldatasize, add, slt] - rw [hslt] at rd2283 - exact evm_run rd2283 with [ - push2 ⟨670⟩, jumpiT (by decide) (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsGetRewardOwedX_hugearg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsGetRewardOwedCalldataCheckHuge (I := I) hsize hbig - obtain ⟨_, _, rd2266⟩ := hreach - have rd2272 := evm_run rd2266 with [jumpdest, pop, swap3, swap1, swap3, callvalue] - rw [hwv] at rd2272 - have rd2283 := evm_run rd2272 with [ - push2 ⟨670⟩, jumpiNT (by decide), - dup3, push1 ⟨3⟩, not, calldatasize, add, slt] - rw [hslt] at rd2283 - exact evm_run rd2283 with [ - push2 ⟨670⟩, jumpiT (by decide) (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsGetRewardOwedX_dec2831_comet {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2831⟩ - [⟨2298⟩, ⟨224⟩, ⟨4⟩, ⟨0⟩, ⟨255⟩, ⟨64⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt := cometRewardsGetRewardOwedCalldataCheckOk (I := I) hsz68 hsize hhi - obtain ⟨_, _, rd2266⟩ := hreach - have rd2272 := evm_run rd2266 with [jumpdest, pop, swap3, swap1, swap3, callvalue] - rw [hwv] at rd2272 - have rd2283 := evm_run rd2272 with [ - push2 ⟨670⟩, jumpiNT (by decide), - dup3, push1 ⟨3⟩, not, calldatasize, add, slt] - rw [hslt] at rd2283 - exact ⟨_, _, evm_run rd2283 with [ - push2 ⟨670⟩, jumpiNT (by decide), - push1 ⟨255⟩, swap3, swap4, push2 ⟨2298⟩, push2 ⟨2831⟩, - jump (by native_decide)]⟩ - -theorem cometRewardsGetRewardOwedX_dec2298_comet {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2298⟩ - [getRewardOwedCometWord I, ⟨224⟩, ⟨4⟩, ⟨0⟩, ⟨255⟩, ⟨64⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2831⟩ := - cometRewardsGetRewardOwedX_dec2831_comet (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hsz68 hsize hhi hreach - exact ⟨_, _, evm_run rd2831 with [ - jumpdest, push1 ⟨4⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32) := by - exact solcAddrMask_clean (by - simpa [getRewardOwedCometWord, calldataWord] using hcanonComet) - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean] - exact u256_sub_self _), - jump (by native_decide)]⟩ - -theorem cometRewardsGetRewardOwedX_dec2853_account {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2853⟩ - [⟨2307⟩, ⟨0⟩, ⟨224⟩, ⟨4⟩, getRewardOwedCometWord I, ⟨255⟩, ⟨64⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2298⟩ := - cometRewardsGetRewardOwedX_dec2298_comet (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hreach - exact ⟨_, _, evm_run rd2298 with [ - jumpdest, swap3, push2 ⟨2307⟩, push2 ⟨2853⟩, jump (by native_decide)]⟩ - -theorem cometRewardsGetRewardOwedX_dec2307_account {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2307⟩ - [getRewardOwedAccountWord I, ⟨0⟩, ⟨224⟩, ⟨4⟩, getRewardOwedCometWord I, - ⟨255⟩, ⟨64⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2853⟩ := - cometRewardsGetRewardOwedX_dec2853_account (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hreach - exact ⟨_, _, evm_run rd2853 with [ - jumpdest, push1 ⟨36⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32) := by - exact solcAddrMask_clean (by - simpa [getRewardOwedAccountWord, calldataWord] using hcanonAccount) - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean] - exact u256_sub_self _), - jump (by native_decide)]⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsGetRewardOwedX_noncanon_comet {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hnc : UInt256.eq (getRewardOwedCometWord I) - (UInt256.land (getRewardOwedCometWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2831⟩ := - cometRewardsGetRewardOwedX_dec2831_comet (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hsz68 hsize hhi hreach - exact evm_run rd2831 with [ - jumpdest, push1 ⟨4⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hclean : - UInt256.eq (getRewardOwedCometWord I) - (UInt256.land (getRewardOwedCometWord I) solcAddrMask) = ⟨1⟩ := by - have heq' : getRewardOwedCometWord I = - UInt256.land (getRewardOwedCometWord I) solcAddrMask := by - simpa [getRewardOwedCometWord, calldataWord] using heq - rw [← heq'] - exact uInt256_eq_self _ - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsGetRewardOwedX_noncanon_account {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hnc : UInt256.eq (getRewardOwedAccountWord I) - (UInt256.land (getRewardOwedAccountWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2853⟩ := - cometRewardsGetRewardOwedX_dec2853_account (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hreach - exact evm_run rd2853 with [ - jumpdest, push1 ⟨36⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hclean : - UInt256.eq (getRewardOwedAccountWord I) - (UInt256.land (getRewardOwedAccountWord I) solcAddrMask) = ⟨1⟩ := by - have heq' : getRewardOwedAccountWord I = - UInt256.land (getRewardOwedAccountWord I) solcAddrMask := by - simpa [getRewardOwedAccountWord, calldataWord] using heq - rw [← heq'] - exact uInt256_eq_self _ - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -end Benchmarks.CompoundIII.CometRewards - -theorem Reasoning.Reach.dup12_xstep {s : State} {code : ByteArray} - {pcv a b c d e f gg hh ii jj kk ll : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.DUP12, .none)) - (hstk : s.machineState.stack = - a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t) - (hov : t.length + 13 ≤ 1024) : - Xstep (D_J code 0) s = - (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok - (stSwap s - (ll :: a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t), - .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.DUP12, .none) := by - rw [hcode, hpc] - exact hdec - rw [← hcode, step_dup12 s hd, hstk] - have hov' : - ¬ ((a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t).length - 12 - + 13 > 1024) := by - simp only [List.length_cons] - omega - simp only [if_neg hov', GasConstants.Gverylow, stSwap] - -theorem Reasoning.Reach.RD.dup12 - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d e f gg hh ii jj kk ll : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc - (a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t) - mem aw rdata acc k C) - (hdec : decode code pc = some (.DUP12, .none)) (hov : t.length + 13 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) - (ll :: a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t) - mem aw rdata acc (k + 1) (C + 3) := - h.stepSwap (fun _ hc hp hs => Reasoning.Reach.dup12_xstep hc hp hdec hs hov) - -namespace Benchmarks.CompoundIII.CometRewards - -set_option maxHeartbeats 1000000 in -theorem cometRewardsGetRewardOwedX_configLoaded {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2410⟩ - [ UInt256.isZero - (rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I)), - ⟨4⟩, - getRewardOwedAccountWord I, - getRewardOwedCometWord I, - ⟨0⟩, - UInt256.land (getRewardOwedCometWord I) solcAddrMask, - solcAddrMask, - ⟨32⟩, - ⟨192⟩, - ⟨64⟩ ] - (getRewardOwedConfigMultiplierMem I (getRewardOwedRewardConfigSlot0Word σ I) - (getRewardOwedMultiplierWord σ I)) - (UInt256.ofNat 10) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2307⟩ := - cometRewardsGetRewardOwedX_dec2307_account (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hcanonAccount hreach - have hslot := getRewardOwedRewardConfigSlotOf_eq_solc I hcanonComet - let slot0 := getRewardOwedRewardConfigSlot0Word σ I - let multiplier := getRewardOwedMultiplierWord σ I - have rd2355 := evm_run rd2307 with [ - jumpdest, swap4, dup7, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - swap5, push2 ⟨2320⟩, dup7, push2 ⟨2976⟩, jump (by jump_dest), - jumpdest, push1 ⟨64⟩, dup2, add, swap1, dup2, lt, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, lor, - push2 ⟨3003⟩, jumpiNT (by native_decide), - push1 ⟨64⟩, - raw mstore 0 getRewardOwedAlloc64Mem (UInt256.ofNat 3) (by decide) mem_cost - (by unfold getRewardOwedAlloc64Mem Reasoning.Theory.writeWord; rfl) - (by decide) (by evm_ov), - jump (by jump_dest), - jumpdest, dup3, dup7, - raw mstore 6 (writeCascade getRewardOwedAlloc64Mem [(128, (⟨0⟩ : UInt256))]) - (UInt256.ofNat 5) (by decide) mem_cost - (by - unfold getRewardOwedAlloc64Mem Reasoning.Theory.writeCascade - Reasoning.Theory.writeWord - rfl) (by decide) (by evm_ov), - dup3, push1 ⟨32⟩, dup1, swap8, add, - raw mstore 3 getRewardOwedConfigZeroMem (UInt256.ofNat 6) (by decide) mem_cost - (by - unfold getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem - unfold Reasoning.Theory.writeCascade Reasoning.Theory.writeWord - rfl) - (by decide) (by evm_ov), - push1 ⟨1⟩, dup1, push1 ⟨160⟩, shl, sub, swap5, dup6, dup4, and, - swap5, dup6, dup6, - raw mstore 0 (wordAt0Mem (getRewardOwedCometWord I) getRewardOwedConfigZeroMem) - (UInt256.ofNat 6) (by decide) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, solcAddrMask_clean hcanonComet] - unfold getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem - unfold Reasoning.Theory.writeCascade wordAt0Mem Reasoning.Theory.writeWord - rfl) (by decide) (by evm_ov), - push1 ⟨1⟩, dup9, - raw mstore 0 (getRewardOwedRewardConfigHashMem I) (UInt256.ofNat 6) (by decide) mem_cost - (by - unfold getRewardOwedRewardConfigHashMem getRewardOwedConfigZeroMem - unfold getRewardOwedAlloc64Mem twoWordHashMem wordAt32Mem wordAt0Mem - unfold Reasoning.Theory.writeCascade Reasoning.Theory.writeWord - rfl) - (by decide) (by evm_ov), - push1 ⟨1⟩, dup11, dup7, - raw keccak256 0 (solcMappingSlot ⟨1⟩ (getRewardOwedCometWord I)) - (UInt256.ofNat 6) (by decide) mem_cost - (getRewardOwedRewardConfigHashMem_keccakSlot I) (by decide) (by evm_ov)] - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2355⟩ - [solcMappingSlot ⟨1⟩ (getRewardOwedCometWord I), ⟨1⟩, ⟨224⟩, ⟨4⟩, - getRewardOwedAccountWord I, getRewardOwedCometWord I, ⟨0⟩, - UInt256.land (getRewardOwedCometWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩), - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩, - ⟨32⟩, ⟨255⟩, ⟨64⟩] - (getRewardOwedRewardConfigHashMem I) (UInt256.ofNat 6) ByteArray.empty - (cA, σ) _ _ at rd2355 - rw [← hslot] at rd2355 - have rd2356 := Reasoning.Reach.RD.dup12 rd2355 (by native_decide) (by decide) - have rd2358 := evm_run rd2356 with [ - raw mload 0 ⟨192⟩ (UInt256.ofNat 6) (by decide) - mem_cost (getRewardOwedRewardConfigHashMem_mload64 I) (by decide) (by evm_ov), - swap11] - have rd2359 := Reasoning.Reach.RD.dup12 rd2358 (by native_decide) (by decide) - have rd2368 := evm_run rd2359 with [ - swap4, push2 ⟨2368⟩, dup6, push2 ⟨3025⟩, jump (by jump_dest), - jumpdest, push1 ⟨128⟩, dup2, add, swap1, dup2, lt, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, lor, - push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩, - raw mstore 0 (getRewardOwedConfigAllocMem I) (UInt256.ofNat 6) (by decide) mem_cost - (by - unfold getRewardOwedConfigAllocMem getRewardOwedRewardConfigHashMem getRewardOwedConfigZeroMem - unfold getRewardOwedAlloc64Mem twoWordHashMem wordAt32Mem wordAt0Mem - unfold Reasoning.Theory.writeCascade Reasoning.Theory.writeWord - rfl) - (by decide) (by evm_ov), - jump (by jump_dest), jumpdest] - have rdAfterSloadPre := evm_run rd2368 with [dup3] - obtain ⟨_, _, rdAfterSload⟩ := rdAfterSloadPre.sload (by decide) (by evm_ov) - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (getRewardOwedRewardConfigSlot0Word σ I :: _) (getRewardOwedConfigAllocMem I) - (UInt256.ofNat 6) ByteArray.empty (cA, σ) _ _ at rdAfterSload - rw [show getRewardOwedRewardConfigSlot0Word σ I = slot0 from rfl] at rdAfterSload - have rd2409pre := evm_run rdAfterSload with [ - swap1, dup12, dup3, and, dup1, swap7, - raw mstore 3 (getRewardOwedConfigTokenMem I slot0) (UInt256.ofNat 7) (by decide) mem_cost - (by - unfold getRewardOwedConfigTokenMem getRewardOwedConfigAllocMem - unfold getRewardOwedRewardConfigHashMem getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem - unfold twoWordHashMem wordAt32Mem wordAt0Mem Reasoning.Theory.writeCascade - unfold Reasoning.Theory.writeWord rewardConfigTokenFromSlot0 slot0 - rfl) - (by decide) (by evm_ov), - dup14, dup14, dup7, dup1, push1 ⟨64⟩, shl, sub, dup5, push1 ⟨160⟩, shr, and, - swap2, add, - raw mstore 3 (getRewardOwedConfigRescaleMem I slot0) (UInt256.ofNat 8) (by decide) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩ = - UInt256.ofNat (2 ^ 64 - 1) from by native_decide] - unfold getRewardOwedConfigRescaleMem getRewardOwedConfigTokenMem getRewardOwedConfigAllocMem - unfold getRewardOwedRewardConfigHashMem getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem - unfold twoWordHashMem wordAt32Mem wordAt0Mem Reasoning.Theory.writeCascade - unfold Reasoning.Theory.writeWord rewardConfigRescaleFromSlot0 - unfold rewardConfigTokenFromSlot0 slot0 - rfl) (by decide) (by evm_ov), - shr, and, iszero, iszero, dup13, dup13, add, - raw mstore 3 (getRewardOwedConfigShouldMem I slot0) (UInt256.ofNat 9) (by decide) mem_cost - (by - unfold getRewardOwedConfigShouldMem getRewardOwedConfigRescaleMem - unfold getRewardOwedConfigTokenMem getRewardOwedConfigAllocMem getRewardOwedRewardConfigHashMem - unfold getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem twoWordHashMem wordAt32Mem wordAt0Mem - unfold Reasoning.Theory.writeCascade Reasoning.Theory.writeWord - unfold rewardConfigShouldUpscaleFromSlot0 rewardConfigShouldUpscaleRawFromSlot0 - unfold rewardConfigRescaleFromSlot0 rewardConfigTokenFromSlot0 slot0 - rfl) (by decide) (by evm_ov), - add] - obtain ⟨_, _, rdAfterMultiplier⟩ := rd2409pre.sload (by decide) (by evm_ov) - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (getRewardOwedMultiplierWord σ I :: _) (getRewardOwedConfigShouldMem I slot0) - (UInt256.ofNat 9) ByteArray.empty (cA, σ) _ _ at rdAfterMultiplier - rw [show getRewardOwedMultiplierWord σ I = multiplier from rfl] at rdAfterMultiplier - have rd2409 := evm_run rdAfterMultiplier with [ - push1 ⟨96⟩, dup11, add, - raw mstore 3 (getRewardOwedConfigMultiplierMem I slot0 multiplier) (UInt256.ofNat 10) - (by decide) mem_cost - (by - unfold getRewardOwedConfigMultiplierMem getRewardOwedConfigShouldMem - unfold getRewardOwedConfigRescaleMem getRewardOwedConfigTokenMem getRewardOwedConfigAllocMem - unfold getRewardOwedRewardConfigHashMem getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem - unfold twoWordHashMem wordAt32Mem wordAt0Mem Reasoning.Theory.writeCascade - unfold Reasoning.Theory.writeWord - unfold rewardConfigShouldUpscaleFromSlot0 rewardConfigShouldUpscaleRawFromSlot0 - unfold rewardConfigRescaleFromSlot0 rewardConfigTokenFromSlot0 slot0 multiplier - rfl) - (by decide) (by evm_ov), - iszero] - have hmask : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by - decide - rw [hmask] at rd2409 - exact ⟨_, _, by - convert rd2409 using 1⟩ - -theorem cometRewardsGetRewardOwedX_accrueNoCode {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) - (hnz : rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) ≠ ⟨0⟩) - (hnoCode : - Reasoning.Theory.extCodeSizeWord σ - (UInt256.land (getRewardOwedCometWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2410⟩ := - cometRewardsGetRewardOwedX_configLoaded (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hcanonAccount hreach - have htokenNZ : - UInt256.isZero (rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I)) = - ⟨0⟩ := by - exact isZero_eq_zero_of_ne hnz - rw [htokenNZ] at rd2410 - have rd2414 := evm_run rd2410 with [ - push2 ⟨2592⟩, jumpiNT (by decide)] - have rd2415 := evm_run rd2414 with [dup5] - obtain ⟨_, _, rd2416⟩ := - Reasoning.Reach.RD.extcodesize rd2415 (by native_decide) - (by simp only [List.length_cons, List.length_nil]; omega) - rw [hnoCode] at rd2416 - have rd2420 := evm_run rd2416 with [iszero, push2 ⟨797⟩] - exact evm_run rd2420 with [ - jumpiT (by native_decide) (by jump_dest), - jumpdest, dup4, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsGetRewardOwedX_call_accrueAccount {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) - (hnz : rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) ≠ ⟨0⟩) - (hcodeSize : - Reasoning.Theory.extCodeSizeWord σ - (UInt256.land (getRewardOwedCometWord I) solcAddrMask) ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ gasArg k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - getRewardOwedAccrueAccountCallPc - [ gasArg, - UInt256.land (getRewardOwedCometWord I) solcAddrMask, - ⟨0⟩, - ⟨320⟩, - getRewardOwedAccrueAccountCallSize, - ⟨320⟩, - ⟨0⟩, - ⟨320⟩, - UInt256.land (getRewardOwedAccountWord I) solcAddrMask, - getRewardOwedAccountWord I, - getRewardOwedCometWord I, - ⟨0⟩, - UInt256.land (getRewardOwedCometWord I) solcAddrMask, - solcAddrMask, - ⟨32⟩, - ⟨192⟩, - ⟨64⟩ ] - (getRewardOwedAccrueAccountCalldataMem I (getRewardOwedRewardConfigSlot0Word σ I) - (getRewardOwedMultiplierWord σ I)) - getRewardOwedAccrueAccountPostCallAw ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2410⟩ := - cometRewardsGetRewardOwedX_configLoaded (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hcanonAccount hreach - let slot0 := getRewardOwedRewardConfigSlot0Word σ I - let multiplier := getRewardOwedMultiplierWord σ I - have htokenNZ : - UInt256.isZero (rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I)) = - ⟨0⟩ := by - exact isZero_eq_zero_of_ne hnz - rw [htokenNZ] at rd2410 - have rd2414 := evm_run rd2410 with [ - push2 ⟨2592⟩, jumpiNT (by decide)] - have rd2415 := evm_run rd2414 with [dup5] - obtain ⟨_, _, rd2416⟩ := - Reasoning.Reach.RD.extcodesize rd2415 (by native_decide) - (by simp only [List.length_cons, List.length_nil]; omega) - have rd2417 := evm_run rd2416 with [iszero] - rw [isZero_eq_zero_of_ne hcodeSize] at rd2417 - have rd2421 := evm_run rd2417 with [ - push2 ⟨797⟩, jumpiNT (by decide)] - have hcleanAccount : - UInt256.land (getRewardOwedAccountWord I) solcAddrMask = - getRewardOwedAccountWord I := by - exact solcAddrMask_clean (by simpa [getRewardOwedAccountWord, calldataWord] using - hcanonAccount) - have rd2433 := evm_run rd2421 with [ - dup9, - raw mload 0 ⟨320⟩ (UInt256.ofNat 10) (by decide) - mem_cost (getRewardOwedConfigMultiplierMem_mload64 I slot0 multiplier) - (by decide) (by evm_ov), - push4 ⟨3219561613⟩, push1 ⟨224⟩, shl, dup2, - raw mstore 3 (getRewardOwedAccrueAccountSelectorMem I slot0 multiplier) - (UInt256.ofNat 11) (by decide) mem_cost - (by - unfold getRewardOwedAccrueAccountSelectorMem getRewardOwedConfigMultiplierMem - unfold getRewardOwedConfigShouldMem getRewardOwedConfigRescaleMem - unfold getRewardOwedConfigTokenMem getRewardOwedConfigAllocMem - unfold getRewardOwedRewardConfigHashMem getRewardOwedConfigZeroMem - unfold getRewardOwedAlloc64Mem twoWordHashMem wordAt32Mem wordAt0Mem - unfold Reasoning.Theory.writeCascade Reasoning.Theory.writeWord - unfold rewardConfigShouldUpscaleFromSlot0 rewardConfigShouldUpscaleRawFromSlot0 - unfold rewardConfigRescaleFromSlot0 rewardConfigTokenFromSlot0 slot0 multiplier - rfl) - (by decide) (by evm_ov)] - have rd2442 := evm_run rd2433 with [ - dup3, dup8, and, swap2, dup2, add, dup3, swap1, - raw mstore 3 (getRewardOwedAccrueAccountCalldataMem I slot0 multiplier) - getRewardOwedAccrueAccountPostCallAw (by decide) mem_cost - (by - rw [show ((⟨320⟩ : UInt256) + ⟨4⟩).toNat = 324 from by native_decide] - rw [u256_land_comm solcAddrMask (getRewardOwedAccountWord I), hcleanAccount] - unfold getRewardOwedAccrueAccountCalldataMem getRewardOwedAccrueAccountSelectorMem - unfold getRewardOwedConfigMultiplierMem getRewardOwedConfigShouldMem - unfold getRewardOwedConfigRescaleMem getRewardOwedConfigTokenMem - unfold getRewardOwedConfigAllocMem getRewardOwedRewardConfigHashMem - unfold getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem twoWordHashMem - unfold wordAt32Mem wordAt0Mem Reasoning.Theory.writeCascade - unfold Reasoning.Theory.writeWord rewardConfigShouldUpscaleFromSlot0 - unfold rewardConfigShouldUpscaleRawFromSlot0 rewardConfigRescaleFromSlot0 - unfold rewardConfigTokenFromSlot0 slot0 multiplier - rfl) - (by decide) (by evm_ov)] - obtain ⟨gasArg, rd2450⟩ := evm_run rd2442 with [ - dup5, dup2, push1 ⟨36⟩, dup2, dup4, dup11, gas] - rw [u256_land_comm solcAddrMask (getRewardOwedAccountWord I)] at rd2450 - exact ⟨gasArg, _, _, by - convert rd2450 using 1⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsGetRewardOwedX_call_accrueAccount_made - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) - (hnz : rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ_evm I) ≠ ⟨0⟩) - (hcodeSize : - Reasoning.Theory.extCodeSizeWord σ_evm - (UInt256.land (getRewardOwedCometWord I) solcAddrMask) ≠ ⟨0⟩) - (hdepth : I.depth.val < 1024) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - ∃ cA' σ'_evm σ'_solm A'_solm z out k C, - typedCallViaEVM config - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (EVM.address (getRewardOwedCometTarget I)) "accrueAccount" 0 - (getRewardOwedAccrueAccountArgs I) - (z, - { initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' }, - out) true ∧ - accountMapEquiv σ'_evm σ'_solm ∧ - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (getRewardOwedAccrueAccountCallPc + ⟨1⟩) - (getRewardOwedAccrueAccountPostCallStack z I) - (getRewardOwedAccrueAccountPostCallMem I - (getRewardOwedRewardConfigSlot0Word σ_evm I) - (getRewardOwedMultiplierWord σ_evm I) out) - getRewardOwedAccrueAccountPostCallAw out (cA', σ'_evm) k C ∧ - out.size < UInt256.size := by - obtain ⟨gasArg, k0, C0, rd2450⟩ := - cometRewardsGetRewardOwedX_call_accrueAccount (cA := cA) (gh := gh) (bl := bl) - (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hcanonComet hcanonAccount hnz hcodeSize hreach - have rd2450Call : - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - getRewardOwedAccrueAccountCallPc - (gasArg :: UInt256.land (getRewardOwedCometWord I) solcAddrMask :: ⟨0⟩ :: - ⟨320⟩ :: getRewardOwedAccrueAccountCallSize :: ⟨320⟩ :: ⟨0⟩ :: - getRewardOwedAccrueAccountPostCallTail I) - (getRewardOwedAccrueAccountCalldataMem I (getRewardOwedRewardConfigSlot0Word σ_evm I) - (getRewardOwedMultiplierWord σ_evm I)) - getRewardOwedAccrueAccountPostCallAw ByteArray.empty (cA, σ_evm) k0 C0 := by - simpa [getRewardOwedAccrueAccountPostCallTail] using rd2450 - have hdecCall : - decode cometRewardsBytecode getRewardOwedAccrueAccountCallPc = some (.CALL, .none) := by - unfold getRewardOwedAccrueAccountCallPc - native_decide - obtain ⟨cA', σ'_evm, z, out, A_in, callGas, k', C', hΘ, rd2451, houtSize⟩ := - Reasoning.Reach.RD.call (t := getRewardOwedAccrueAccountPostCallTail I) - rd2450Call hdecCall hdepth - (by simp [getRewardOwedAccrueAccountPostCallTail]) - obtain ⟨g'', A'_evm, hΘeq⟩ := hΘ - have hdepthNeI : I.depth ≠ 1024 := by - intro hEq - rw [hEq] at hdepth - exact absurd hdepth (by decide) - have hdepthNe : - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.depth ≠ - 1024 := by - simpa [initState] using hdepthNeI - have htgt := getRewardOwedCometTarget_eq_targetWord I hcanonComet - have hcd := getRewardOwedAccrueAccountCalldataMem_encode_args I - (getRewardOwedRewardConfigSlot0Word σ_evm I) - (getRewardOwedMultiplierWord σ_evm I) hcanonAccount - have hcallE : - typedCallViaEVM config - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (EVM.address (getRewardOwedCometTarget I)) "accrueAccount" 0 - (getRewardOwedAccrueAccountArgs I) - (z, - { initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_evm - substate := A'_evm - createdAccounts := cA' }, - out) true := by - refine callCoincides - (cfg := config) - (evm := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (name := "accrueAccount") (args := getRewardOwedAccrueAccountArgs I) - (tgt := EVM.address (getRewardOwedCometTarget I)) - (targetWord := UInt256.land (getRewardOwedCometWord I) solcAddrMask) - (cA' := cA') (σ' := σ'_evm) (A' := A'_evm) (A_in := A_in) - (z := z) (o := out) (g'' := g'') (callGas := callGas) - (mem := getRewardOwedAccrueAccountCalldataMem I - (getRewardOwedRewardConfigSlot0Word σ_evm I) - (getRewardOwedMultiplierWord σ_evm I)) - (inOff := ⟨320⟩) (inSize := getRewardOwedAccrueAccountCallSize) - (callPerm := true) - hdepthNe htgt hcd ?_ - simpa [initState, hperm] using hΘeq - obtain ⟨σ'_solm, A'_solm, hcallSolm, hPostAccounts⟩ := - typedCallViaEVM_initState_accountMapEquiv hcallE hAccounts - exact ⟨cA', σ'_evm, σ'_solm, A'_solm, z, out, k', C', - hcallSolm, hPostAccounts, by - simpa [getRewardOwedAccrueAccountPostCallStack, - getRewardOwedAccrueAccountPostCallTail, getRewardOwedAccrueAccountPostCallMem, - getRewardOwedAccrueAccountPostCallAw, getRewardOwedAccrueAccountCallSize] - using rd2451, - houtSize⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsGetRewardOwedX_after_accrueAccount_failure - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (getRewardOwedAccrueAccountCallPc + ⟨1⟩) - (getRewardOwedAccrueAccountPostCallStack false I) - (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier out) - getRewardOwedAccrueAccountPostCallAw out acc k C) - (houtSize : out.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have rd2451 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨2451⟩ (getRewardOwedAccrueAccountPostCallStack false I) - (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier out) - getRewardOwedAccrueAccountPostCallAw out acc k C := by - simpa [getRewardOwedAccrueAccountCallPc] using rd - have rd2582 := evm_run rd2451 with [ - dup1, iszero, push2 ⟨2582⟩, jumpiT (by native_decide) (by jump_dest)] - let fp : UInt256 := - if (⟨64⟩ : UInt256).toNat ≥ - (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier out).size - ∨ (⟨64⟩ : UInt256) ≥ getRewardOwedAccrueAccountPostCallAw * ⟨32⟩ then - ⟨0⟩ - else - UInt256.ofNat (fromByteArrayBigEndian - ((getRewardOwedAccrueAccountPostCallMem I slot0 multiplier out).readWithPadding - (⟨64⟩ : UInt256).toNat 32)) - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have rd2583pre := evm_run rd2582 with [jumpdest, dup11] - have rd2584 := Reasoning.Reach.RD.mload 0 fp getRewardOwedAccrueAccountPostCallAw - rd2583pre (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, - getRewardOwedAccrueAccountPostCallAw, getRewardOwedAccrueAccountCallSize] - native_decide) - (by rfl) - (by native_decide) - (by simp) - have rd2587pre := evm_run rd2584 with [returndatasize, dup8, dup3] - let mem2 : ByteArray := - out.write 0 (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier out) - fp.toNat rdsz.toNat - let aw2 : UInt256 := - UInt256.ofNat (MachineState.M getRewardOwedAccrueAccountPostCallAw.toNat fp.toNat - rdsz.toNat) - have rd2588 := Reasoning.Reach.RD.returndatacopy - (Cₘ aw2 - Cₘ getRewardOwedAccrueAccountPostCallAw) mem2 aw2 rd2587pre - (by native_decide) - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, hrdsz_toNat]; omega) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, aw2, rdsz]) - (by rfl) - (by rfl) - (by simp) - have rd2590 := evm_run rd2588 with [returndatasize, swap1] - exact Reasoning.Reach.RD.rev - (Cₘ (UInt256.ofNat (MachineState.M aw2.toNat fp.toNat rdsz.toNat)) - Cₘ aw2) - rd2590 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, rdsz]) - (by simp) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsGetRewardOwedX_call_baseTrackingAccrued - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {accrueOut : ByteArray} - {cA' : Batteries.RBSet AccountAddress compare} {σ' : AccountMap} {k C : ℕ} - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) - (houtSize : accrueOut.size < UInt256.size) - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (getRewardOwedAccrueAccountCallPc + ⟨1⟩) - (getRewardOwedAccrueAccountPostCallStack true I) - (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier accrueOut) - getRewardOwedAccrueAccountPostCallAw accrueOut (cA', σ') k C) : - ∃ gasArg k' C', RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedBaseTrackingCallPc - (gasArg :: UInt256.land (getRewardOwedCometWord I) solcAddrMask :: - ⟨320⟩ :: getRewardOwedBaseTrackingCallSize :: ⟨320⟩ :: ⟨32⟩ :: - getRewardOwedBaseTrackingPostCallTail (getRewardOwedClaimedWord σ' I)) - (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier accrueOut) - getRewardOwedBaseTrackingCallAw accrueOut (cA', σ') k' C' := by - have rd2451 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨2451⟩ - [⟨1⟩, ⟨320⟩, UInt256.land (getRewardOwedAccountWord I) solcAddrMask, - getRewardOwedAccountWord I, getRewardOwedCometWord I, ⟨0⟩, - UInt256.land (getRewardOwedCometWord I) solcAddrMask, solcAddrMask, - ⟨32⟩, ⟨192⟩, ⟨64⟩] - (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier accrueOut) - getRewardOwedAccrueAccountPostCallAw accrueOut (cA', σ') k C := by - simpa [getRewardOwedAccrueAccountCallPc, - getRewardOwedAccrueAccountPostCallStack, getRewardOwedAccrueAccountPostCallTail] using rd - have rd2466 := evm_run rd2451 with [ - dup1, iszero, push2 ⟨2582⟩, jumpiNT (by native_decide), - swap1, dup10, swap4, swap3, swap2, push2 ⟨2561⟩, - jumpiT (by native_decide) (by jump_dest), - jumpdest, swap5, push2 ⟨2575⟩, push2 ⟨2499⟩, swap6, swap7, - push2 ⟨3052⟩, jump (by jump_dest)] - have rd2466' := evm_run rd2466 with [ - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, gt, - push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩, - raw mstore 0 (getRewardOwedAccrueAccountAfterAllocMem I slot0 multiplier accrueOut) - getRewardOwedAccrueAccountPostCallAw (by native_decide) mem_cost - (by - unfold getRewardOwedAccrueAccountAfterAllocMem - rfl) - (by native_decide) (by evm_ov), - jump (by jump_dest), jumpdest, swap5, swap4, push2 ⟨2466⟩, - jump (by jump_dest)] - have rd2475pre := evm_run rd2466' with [ - jumpdest, pop, dup5, swap6, push2 ⟨2499⟩, swap5, swap6] - have rd2476 := evm_run rd2475pre with [ - raw mstore 0 - (wordAt0Mem (UInt256.land (getRewardOwedCometWord I) solcAddrMask) - (getRewardOwedAccrueAccountAfterAllocMem I slot0 multiplier accrueOut)) - getRewardOwedAccrueAccountPostCallAw (by native_decide) mem_cost - (by - unfold wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have rd2480 := evm_run rd2476 with [ - push1 ⟨2⟩, dup9, - raw mstore 0 (getRewardOwedClaimedInnerHashMem I slot0 multiplier accrueOut) - getRewardOwedAccrueAccountPostCallAw (by native_decide) mem_cost - (by - unfold getRewardOwedClaimedInnerHashMem twoWordHashMem wordAt32Mem - rfl) - (by native_decide) (by evm_ov)] - have hinnerHash : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((getRewardOwedClaimedInnerHashMem I slot0 multiplier accrueOut) - |>.readWithPadding 0 64))) = - solcMappingSlot ⟨2⟩ (UInt256.land (getRewardOwedCometWord I) solcAddrMask) := by - unfold getRewardOwedClaimedInnerHashMem - exact twoWordHashMem_solcMappingSlot_of_ge ⟨2⟩ - (UInt256.land (getRewardOwedCometWord I) solcAddrMask) - (le_trans (by norm_num) <| - getRewardOwedAccrueAccountAfterAllocMem_size_ge320 I slot0 multiplier houtSize) - have rd2482pre := evm_run rd2480 with [dup10, dup7] - have rd2483 := rd2482pre.keccak256 0 - (solcMappingSlot ⟨2⟩ (UInt256.land (getRewardOwedCometWord I) solcAddrMask)) - getRewardOwedAccrueAccountPostCallAw (by native_decide) mem_cost - hinnerHash (by native_decide) (by evm_ov) - have rd2487 := evm_run rd2483 with [ - swap1, push1 ⟨0⟩, - raw mstore 0 - (wordAt0Mem (UInt256.land (getRewardOwedAccountWord I) solcAddrMask) - (getRewardOwedClaimedInnerHashMem I slot0 multiplier accrueOut)) - getRewardOwedAccrueAccountPostCallAw (by native_decide) mem_cost - (by - unfold wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have rd2489 := evm_run rd2487 with [ - dup8, - raw mstore 0 (getRewardOwedClaimedOuterHashMem I slot0 multiplier accrueOut) - getRewardOwedAccrueAccountPostCallAw (by native_decide) mem_cost - (by - unfold getRewardOwedClaimedOuterHashMem twoWordHashMem wordAt32Mem - rfl) - (by native_decide) (by evm_ov)] - have houterHash := - getRewardOwedClaimedOuterHashMem_keccakSlot I slot0 multiplier houtSize - hcanonComet hcanonAccount - have rd2493pre := (evm_run rd2489 with [dup9, push1 ⟨0⟩]).keccak256 0 - (getRewardOwedRewardsClaimedSlotOf I) - getRewardOwedAccrueAccountPostCallAw (by native_decide) mem_cost - houterHash (by native_decide) (by evm_ov) - obtain ⟨_, _, rd2494₀⟩ := rd2493pre.sload (by native_decide) (by evm_ov) - obtain ⟨_, _, rd2494⟩ : ∃ k1 C1, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨2494⟩ - [getRewardOwedClaimedWord σ' I, getRewardOwedAccountWord I, ⟨192⟩, - ⟨2499⟩, getRewardOwedCometWord I, ⟨0⟩, solcAddrMask, ⟨32⟩, - ⟨192⟩, ⟨64⟩] - (getRewardOwedClaimedOuterHashMem I slot0 multiplier accrueOut) - getRewardOwedAccrueAccountPostCallAw accrueOut (cA', σ') k1 C1 := by - exact ⟨_, _, by - simpa [getRewardOwedClaimedWord] using rd2494₀⟩ - have rd3679 := evm_run rd2494 with [ - swap4, push2 ⟨3679⟩, jump (by jump_dest)] - have hcleanAccount : - UInt256.land (getRewardOwedAccountWord I) solcAddrMask = - getRewardOwedAccountWord I := by - exact solcAddrMask_clean (by simpa [getRewardOwedAccountWord, calldataWord] using - hcanonAccount) - have rd3682 := evm_run rd3679 with [ - jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨320⟩ getRewardOwedBaseTrackingCallAw (by native_decide) - mem_cost - (getRewardOwedClaimedOuterHashMem_mload64 I slot0 multiplier houtSize) - (by native_decide) (by evm_ov)] - have rd3692 := evm_run rd3682 with [ - push4 ⟨719776253⟩, push1 ⟨226⟩, shl, dup2, - raw mstore 0 (getRewardOwedBaseTrackingSelectorMem I slot0 multiplier accrueOut) - getRewardOwedBaseTrackingCallAw (by native_decide) mem_cost - (by - unfold getRewardOwedBaseTrackingSelectorMem - rfl) - (by native_decide) (by evm_ov)] - have rd3708 := evm_run rd3692 with [ - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, swap3, dup4, and, - push1 ⟨4⟩, dup3, add, - raw mstore 0 (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier accrueOut) - getRewardOwedBaseTrackingCallAw (by native_decide) mem_cost - (by - rw [show ((⟨320⟩ : UInt256) + ⟨4⟩).toNat = 324 from by native_decide] - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - rw [u256_land_comm solcAddrMask (getRewardOwedAccountWord I), hcleanAccount] - unfold getRewardOwedBaseTrackingCalldataMem getRewardOwedBaseTrackingSelectorMem - rfl) - (by native_decide) (by evm_ov)] - obtain ⟨gasArg, rd3723⟩ := evm_run rd3708 with [ - swap3, swap2, push1 ⟨32⟩, swap2, dup5, swap2, push1 ⟨36⟩, - swap2, dup4, swap2, and, gas] - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] at rd3723 - rw [u256_land_comm solcAddrMask (getRewardOwedCometWord I)] at rd3723 - exact ⟨gasArg, _, _, by - simpa [getRewardOwedBaseTrackingCallPc, getRewardOwedBaseTrackingCallSize, - getRewardOwedBaseTrackingPostCallTail] using rd3723⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsGetRewardOwedX_call_baseTrackingAccrued_made - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {accrueOut : ByteArray} - {cA' : Batteries.RBSet AccountAddress compare} {σ'_evm σ'_solm : AccountMap} - {A'_solm : Substate} {k C : ℕ} - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) - (hdepth : I.depth.val < 1024) - (hPostAccounts : accountMapEquiv σ'_evm σ'_solm) - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ_evm σ₀ g A I) - (getRewardOwedAccrueAccountCallPc + ⟨1⟩) - (getRewardOwedAccrueAccountPostCallStack true I) - (getRewardOwedAccrueAccountPostCallMem I slot0 multiplier accrueOut) - getRewardOwedAccrueAccountPostCallAw accrueOut (cA', σ'_evm) k C) - (haccrueOutSize : accrueOut.size < UInt256.size) : - ∃ cA'' σ''_evm σ''_solm A''_solm z baseOut k' C', - typedCallViaEVM config - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } - (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (z, - { { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' }, - baseOut) false ∧ - accountMapEquiv σ''_evm σ''_solm ∧ - RD cometRewardsBytecode I g (initState cA gh bl σ_evm σ₀ g A I) - (getRewardOwedBaseTrackingCallPc + ⟨1⟩) - (getRewardOwedBaseTrackingPostCallStack z (getRewardOwedClaimedWord σ'_evm I)) - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut (cA'', σ''_evm) k' C' ∧ - baseOut.size < UInt256.size ∧ - baseOut.size < 2 ^ 255 := by - obtain ⟨gasArg, k0, C0, rd3723⟩ := - cometRewardsGetRewardOwedX_call_baseTrackingAccrued - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := g) (slot0 := slot0) (multiplier := multiplier) - (accrueOut := accrueOut) (cA' := cA') (σ' := σ'_evm) - hcanonComet hcanonAccount haccrueOutSize rd - have rd3723Call : - RD cometRewardsBytecode I g (initState cA gh bl σ_evm σ₀ g A I) - getRewardOwedBaseTrackingCallPc - (gasArg :: UInt256.land (getRewardOwedCometWord I) solcAddrMask :: - ⟨320⟩ :: getRewardOwedBaseTrackingCallSize :: ⟨320⟩ :: ⟨32⟩ :: - getRewardOwedBaseTrackingPostCallTail (getRewardOwedClaimedWord σ'_evm I)) - (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier accrueOut) - getRewardOwedBaseTrackingCallAw accrueOut (cA', σ'_evm) k0 C0 := by - simpa [getRewardOwedBaseTrackingPostCallTail] using rd3723 - have hdecCall : - decode cometRewardsBytecode getRewardOwedBaseTrackingCallPc = - some (.STATICCALL, .none) := by - unfold getRewardOwedBaseTrackingCallPc - native_decide - obtain ⟨cA'', σ''_evm, z, baseOut, A_in, callGas, k', C', hΘ, rd3724, - _houtSize⟩ := - RD.solcStaticcall (t := - getRewardOwedBaseTrackingPostCallTail (getRewardOwedClaimedWord σ'_evm I)) - rd3723Call hdecCall hdepth - (by simp [getRewardOwedBaseTrackingPostCallTail]) - obtain ⟨g'', A''_evm, hΘeq⟩ := hΘ - let evmEBase : EVM.State := - { initState cA gh bl σ_evm σ₀ g A I with - accountMap := σ'_evm - substate := A'_solm - createdAccounts := cA' } - let evmSBase : EVM.State := - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } - have houtSmall : baseOut.size < 2 ^ 138 := by - exact Theta_returnData_size_lt_2pow138_of_eq - (blob := I.blobVersionedHashes) (cA := cA') - (gh := (initState cA gh bl σ_evm σ₀ g A I).genesisBlockHeader) - (blocks := (initState cA gh bl σ_evm σ₀ g A I).blocks) - (σ := σ'_evm) - (σ₀ := (initState cA gh bl σ_evm σ₀ g A I).σ₀) - (A := A_in) - (s := AccountAddress.ofUInt256 (UInt256.ofNat I.codeOwner)) - (o := I.sender) - (r := AccountAddress.ofUInt256 (UInt256.land (getRewardOwedCometWord I) solcAddrMask)) - (c := toExecute σ'_evm - (AccountAddress.ofUInt256 (UInt256.land (getRewardOwedCometWord I) solcAddrMask))) - (g := callGas) (p := UInt256.ofNat I.gasPrice) - (v := ⟨0⟩) (v' := ⟨0⟩) - (d := (getRewardOwedBaseTrackingCalldataMem I slot0 multiplier accrueOut) - |>.readWithPadding 320 getRewardOwedBaseTrackingCallSize.toNat) - (e := I.depth + 1) (H := I.header) (w := false) - hΘeq - (by exact Ethereum.EVM.ByteArray.readWithPadding_size_lt_uint256 _ _ _) - have houtUInt : baseOut.size < UInt256.size := by - have hsz : UInt256.size = 2 ^ 256 := by decide - omega - have hdepthNeI : I.depth ≠ 1024 := by - intro hEq - rw [hEq] at hdepth - exact absurd hdepth (by decide) - have hdepthNe : evmEBase.executionEnv.depth ≠ 1024 := by - simpa [evmEBase, initState] using hdepthNeI - have htgt := getRewardOwedCometTarget_eq_targetWord I hcanonComet - have hcd := getRewardOwedBaseTrackingCalldataMem_encode_args I slot0 multiplier - haccrueOutSize hcanonAccount - have hcallE : - typedCallViaEVM config evmEBase - (EVM.address (getRewardOwedCometTarget I)) - "baseTrackingAccrued" 0 (getRewardAccruedBaseTrackingArgs I) - (z, - { evmEBase with - accountMap := σ''_evm - substate := A''_evm - createdAccounts := cA'' }, - baseOut) false := by - refine callCoincides - (cfg := config) (evm := evmEBase) - (name := "baseTrackingAccrued") (args := getRewardAccruedBaseTrackingArgs I) - (tgt := EVM.address (getRewardOwedCometTarget I)) - (targetWord := UInt256.land (getRewardOwedCometWord I) solcAddrMask) - (cA' := cA'') (σ' := σ''_evm) (A' := A''_evm) (A_in := A_in) - (z := z) (o := baseOut) (g'' := g'') (callGas := callGas) - (mem := getRewardOwedBaseTrackingCalldataMem I slot0 multiplier accrueOut) - (inOff := ⟨320⟩) (inSize := getRewardOwedBaseTrackingCallSize) - (callPerm := false) - hdepthNe htgt hcd ?_ - simpa [evmEBase, initState] using hΘeq - obtain ⟨σ''_solm, A''_solm, hcallSolm, hPostAccounts'⟩ := - typedCallViaEVM_accountMapEquiv - (evm_solm := evmSBase) hcallE - (by simpa [evmEBase, evmSBase, initState] using hPostAccounts) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase]) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase]) - (by simp [evmEBase, evmSBase, initState]) - exact ⟨cA'', σ''_evm, σ''_solm, A''_solm, z, baseOut, k', C', - by - simpa [evmSBase, initState] using hcallSolm, - hPostAccounts', - by - simpa [getRewardOwedBaseTrackingPostCallStack, - getRewardOwedBaseTrackingPostCallTail, getRewardOwedBaseTrackingPostCallMem, - getRewardOwedBaseTrackingPostCallAw, getRewardOwedBaseTrackingCallSize] - using rd3724, - houtUInt, - by omega⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsGetRewardOwedX_after_baseTracking_failure - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {accrueOut baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (getRewardOwedBaseTrackingCallPc + ⟨1⟩) - (getRewardOwedBaseTrackingPostCallStack false claimed) - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C) - (haccrueSize : accrueOut.size < UInt256.size) - (hbaseSize : baseOut.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have rd3724 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3724⟩ - [⟨0⟩, ⟨192⟩, ⟨320⟩, ⟨2499⟩, claimed, ⟨0⟩, solcAddrMask, ⟨32⟩, - ⟨192⟩, ⟨64⟩] - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C := by - simpa [getRewardOwedBaseTrackingCallPc, getRewardOwedBaseTrackingPostCallStack, - getRewardOwedBaseTrackingPostCallTail] using rd - have rd3876 := evm_run rd3724 with [ - swap2, dup3, iszero, push2 ⟨3876⟩, jumpiT (by native_decide) (by jump_dest)] - have rd3879 := evm_run rd3876 with [ - jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨320⟩ getRewardOwedBaseTrackingPostCallAw (by native_decide) - mem_cost - (getRewardOwedBaseTrackingPostCallMem_mload64 - I slot0 multiplier haccrueSize hbaseSize) - (by native_decide) (by evm_ov)] - let rdsz : UInt256 := UInt256.ofNat baseOut.size - have hrdsz_toNat : rdsz.toNat = baseOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hbaseSize - have rd3883pre := evm_run rd3879 with [returndatasize, push1 ⟨0⟩, dup3] - let mem2 : ByteArray := - baseOut.write 0 - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) - 320 rdsz.toNat - let aw2 : UInt256 := - UInt256.ofNat (MachineState.M getRewardOwedBaseTrackingPostCallAw.toNat 320 rdsz.toNat) - have rd3884 := RD.returndatacopy - (Cₘ aw2 - Cₘ getRewardOwedBaseTrackingPostCallAw) mem2 aw2 rd3883pre - (by native_decide) - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, hrdsz_toNat]; omega) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, aw2, rdsz] - change - Cₘ (UInt256.ofNat - (MachineState.M getRewardOwedBaseTrackingPostCallAw.toNat 320 - (UInt256.ofNat baseOut.size).toNat)) - - Cₘ getRewardOwedBaseTrackingPostCallAw = - Cₘ (UInt256.ofNat - (MachineState.M getRewardOwedBaseTrackingPostCallAw.toNat 320 - (UInt256.ofNat baseOut.size).toNat)) - - Cₘ getRewardOwedBaseTrackingPostCallAw - rfl) - (by rfl) - (by rfl) - (by simp) - have rd3886 := evm_run rd3884 with [returndatasize, swap1] - exact RD.rev - (Cₘ (UInt256.ofNat (MachineState.M aw2.toNat 320 rdsz.toNat)) - Cₘ aw2) - rd3886 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, rdsz] - change - Cₘ (UInt256.ofNat - (MachineState.M aw2.toNat 320 (UInt256.ofNat baseOut.size).toNat)) - - Cₘ aw2 = - Cₘ (UInt256.ofNat - (MachineState.M aw2.toNat 320 (UInt256.ofNat baseOut.size).toNat)) - - Cₘ aw2 - rfl) - (by simp) - -set_option maxHeartbeats 2000000 in -theorem cometRewardsGetRewardOwedX_after_baseTracking_short_revert - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {accrueOut baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (getRewardOwedBaseTrackingCallPc + ⟨1⟩) - (getRewardOwedBaseTrackingPostCallStack true claimed) - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C) - (hshort : baseOut.size < 32) (hbaseSize : baseOut.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let rdsz : UInt256 := UInt256.ofNat baseOut.size - have hrdsz_toNat : rdsz.toNat = baseOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hbaseSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨1⟩ := by - apply ugt_one - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hshort - have rd3724 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3724⟩ - [⟨1⟩, ⟨192⟩, ⟨320⟩, ⟨2499⟩, claimed, ⟨0⟩, solcAddrMask, ⟨32⟩, - ⟨192⟩, ⟨64⟩] - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C := by - simpa [getRewardOwedBaseTrackingCallPc, getRewardOwedBaseTrackingPostCallStack, - getRewardOwedBaseTrackingPostCallTail] using rd - have rd3855₀ := evm_run rd3724 with [ - swap2, dup3, iszero, push2 ⟨3876⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap3, push2 ⟨3844⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push2 ⟨3869⟩, swap2, swap3, pop, push1 ⟨32⟩, - returndatasize, dup2, gt] - have rd3855 := rd3855₀ - rw [show UInt256.ofNat baseOut.size = rdsz from rfl, hgt] at rd3855 - let rounded : UInt256 := - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat baseOut.size + ⟨31⟩) - let ptr : UInt256 := (⟨320⟩ : UInt256) + rounded - have hroundedLe : rounded.toNat ≤ baseOut.size + 31 := by - unfold rounded - rw [uland_toNat] - refine le_trans Nat.and_le_right ?_ - rw [uadd_toNat, UInt256.toNat_ofNat_of_lt hbaseSize, - show (⟨31⟩ : UInt256).toNat = 31 from by decide] - exact Nat.mod_le _ _ - have hptr_toNat : ptr.toNat = 320 + rounded.toNat := by - unfold ptr - rw [uadd_toNat, show (⟨320⟩ : UInt256).toNat = 320 from by decide] - exact Nat.mod_eq_of_lt (by - have hroundSmall : rounded.toNat < 64 := by omega - have hsz : UInt256.size = 2 ^ 256 := by decide - omega) - have hltPtr : UInt256.lt ptr (⟨320⟩ : UInt256) = ⟨0⟩ := by - apply ult_zero - rw [hptr_toNat, show (⟨320⟩ : UInt256).toNat = 320 from by decide] - omega - have hmax64 : - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩).toNat = - 18446744073709551615 := by - native_decide - have hgtPtr : - UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - rw [hptr_toNat, hmax64] - omega - have hallocOk : - UInt256.lor (UInt256.lt ptr (⟨320⟩ : UInt256)) - (UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = ⟨0⟩ := by - rw [hltPtr, hgtPtr] - native_decide - have rd3071 := evm_run rd3855 with [ - push2 ⟨734⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, pop, returndatasize, push2 ⟨709⟩, jump (by jump_dest), - jumpdest, push2 ⟨719⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, - jumpiNT (by simpa [ptr, rounded] using hallocOk), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 - (getRewardOwedBaseTrackingPostShortDecodeMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold getRewardOwedBaseTrackingPostShortDecodeMem Reasoning.Theory.writeWord - rfl) - (by native_decide) (by evm_ov)] - have rd3106 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3106⟩, - jump (by jump_dest)] - have hlenCheck : - UInt256.slt (UInt256.sub ((⟨320⟩ : UInt256) + rdsz) ⟨320⟩) ⟨32⟩ = - ⟨1⟩ := by - simpa [rdsz] using - solcReturnStaticLenCheckShort (base := 320) (words := 1) (by simpa using hshort) - (by norm_num [UInt256.size]) - (by - have hsz : UInt256.size = 2 ^ 256 := by decide - omega) - (by norm_num) - have rd3114₀ := evm_run rd3106 with [ - jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, slt] - have rd3114 := rd3114₀ - rw [hlenCheck] at rd3114 - have rd1004 := evm_run rd3114 with [ - push2 ⟨1004⟩, jumpiT (by native_decide) (by jump_dest)] - exact evm_run rd1004 with [ - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsGetRewardOwedX_after_baseTracking_decode_ok - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {accrueOut baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (getRewardOwedBaseTrackingCallPc + ⟨1⟩) - (getRewardOwedBaseTrackingPostCallStack true claimed) - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : (getRewardOwedBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) : - ∃ k' C', RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3740⟩ - [⟨192⟩, getRewardOwedBaseTrackingReturnWord baseOut, ⟨2499⟩, claimed, - ⟨0⟩, solcAddrMask, ⟨32⟩, ⟨192⟩, ⟨64⟩] - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k' C' := by - let baseWord : UInt256 := getRewardOwedBaseTrackingReturnWord baseOut - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - let rdsz : UInt256 := UInt256.ofNat baseOut.size - have hrdsz_toNat : rdsz.toNat = baseOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hbaseSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hout32 - have rd3724 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3724⟩ - [⟨1⟩, ⟨192⟩, ⟨320⟩, ⟨2499⟩, claimed, ⟨0⟩, solcAddrMask, ⟨32⟩, - ⟨192⟩, ⟨64⟩] - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C := by - simpa [getRewardOwedBaseTrackingCallPc, getRewardOwedBaseTrackingPostCallStack, - getRewardOwedBaseTrackingPostCallTail] using rd - have rd3855₀ := evm_run rd3724 with [ - swap2, dup3, iszero, push2 ⟨3876⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap3, push2 ⟨3844⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push2 ⟨3869⟩, swap2, swap3, pop, push1 ⟨32⟩, - returndatasize, dup2, gt] - have rd3855 := rd3855₀ - rw [show UInt256.ofNat baseOut.size = rdsz from rfl, hgt] at rd3855 - have rd3071 := evm_run rd3855 with [ - push2 ⟨734⟩, jumpiNT (by native_decide), - push2 ⟨719⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), - push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold getRewardOwedBaseTrackingPostDecodeMem Reasoning.Theory.writeWord - rfl) - (by native_decide) (by evm_ov)] - have rd3106 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3106⟩, - jump (by jump_dest), jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, - slt, push2 ⟨1004⟩, jumpiNT (by native_decide)] - have rd3129 := evm_run rd3106 with [ - raw mload 0 baseWord getRewardOwedBaseTrackingPostCallAw (by native_decide) - mem_cost - (by - simpa [baseWord] using - getRewardOwedBaseTrackingPostDecodeMem_mload320_of_size_ge - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, and, dup2, sub] - have hclean : UInt256.land baseWord uint64Mask = baseWord := - uint64Mask_clean hbase64' - have hcleanExpanded : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using hclean - have hsub : - UInt256.sub baseWord - (UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) = ⟨0⟩ := by - rw [hcleanExpanded] - exact u256_sub_self baseWord - have rd3129zero := rd3129 - rw [hsub] at rd3129zero - have rd3869 := evm_run rd3129zero with [ - push2 ⟨1004⟩, jumpiNT (by native_decide), swap1, jump (by jump_dest)] - have rd3739 := evm_run rd3869 with [ - jumpdest, swap1, codesize, push2 ⟨3738⟩, jump (by jump_dest), - jumpdest, pop] - exact ⟨_, _, by - simpa [baseWord, getRewardOwedBaseTrackingReturnWord] using rd3739⟩ - -set_option maxHeartbeats 2000000 in -theorem cometRewardsGetRewardOwedX_getRewardAccrued_upscale_success - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {accrueOut baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3740⟩ - [⟨192⟩, getRewardOwedBaseTrackingReturnWord baseOut, ⟨2499⟩, claimed, - ⟨0⟩, solcAddrMask, ⟨32⟩, ⟨192⟩, ⟨64⟩] - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : (getRewardOwedBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 ≠ ⟨0⟩) - (hscaled : - getRewardAccruedScaledNat multiplier - (getRewardAccruedUpscaledNat slot0 (getRewardOwedBaseTrackingReturnWord baseOut)) < - UInt256.size) : - ∃ k' C', RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2499⟩ - [ UInt256.ofNat - (getRewardAccruedReturnNat multiplier - (getRewardAccruedUpscaledNat slot0 - (getRewardOwedBaseTrackingReturnWord baseOut))), - claimed, ⟨0⟩, solcAddrMask, ⟨32⟩, ⟨192⟩, ⟨64⟩] - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k' C' := by - let baseWord : UInt256 := getRewardOwedBaseTrackingReturnWord baseOut - let upNat : ℕ := getRewardAccruedUpscaledNat slot0 baseWord - let scaledNat : ℕ := getRewardAccruedScaledNat multiplier upNat - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have hup : upNat < UInt256.size := by - simpa [upNat, baseWord] using - getRewardAccruedUpscaledNat_lt_size_of_base64 - (slot0 := slot0) (accrued := baseWord) hbase64' - have hrescale64 : (rewardConfigRescaleFromSlot0 slot0).toNat < EVM.twoPow 64 := by - simpa [rewardConfigRescaleFromSlot0, EVM.twoPow] using - rewardConfigRescaleWord_lt slot0 - have hbaseClean : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using uint64Mask_clean hbase64' - have hbaseCleanLeft : - UInt256.land - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) - baseWord = baseWord := by - rw [u256_land_comm] - exact hbaseClean - have hrescaleClean : - UInt256.land (rewardConfigRescaleFromSlot0 slot0) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - rewardConfigRescaleFromSlot0 slot0 := by - simpa [uint64Mask] using uint64Mask_clean hrescale64 - have hshouldWord : - rewardConfigShouldUpscaleFromSlot0 slot0 = ⟨1⟩ := - rewardConfigShouldUpscaleFromSlot0_eq_one_of_raw_ne_zero hshould - have hshouldIsZero : - UInt256.isZero (rewardConfigShouldUpscaleFromSlot0 slot0) = ⟨0⟩ := by - rw [hshouldWord] - native_decide - have hfirstMulLt : - baseWord.toNat * (rewardConfigRescaleFromSlot0 slot0).toNat < UInt256.size := by - simpa [upNat, baseWord, getRewardAccruedUpscaledNat] using hup - have hfirstFlag : - UInt256.land - (UInt256.gt (rewardConfigRescaleFromSlot0 slot0) - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) baseWord)) - (UInt256.isZero (UInt256.isZero baseWord)) = ⟨0⟩ := - checkedMulOverflowFlag_zero baseWord (rewardConfigRescaleFromSlot0 slot0) hfirstMulLt - have hfirstFlagLeft : - UInt256.land (UInt256.isZero (UInt256.isZero baseWord)) - (UInt256.gt (rewardConfigRescaleFromSlot0 slot0) - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) baseWord)) = ⟨0⟩ := by - rw [u256_land_comm] - exact hfirstFlag - have hfirstMulWord : - UInt256.mul baseWord (rewardConfigRescaleFromSlot0 slot0) = UInt256.ofNat upNat := by - simpa [upNat, baseWord, getRewardAccruedUpscaledNat] using - u256_mul_eq_ofNat_of_lt baseWord (rewardConfigRescaleFromSlot0 slot0) hfirstMulLt - have hupWordToNat : (UInt256.ofNat upNat).toNat = upNat := - UInt256.toNat_ofNat_of_lt hup - have hsecondMulLt : - (UInt256.ofNat upNat).toNat * multiplier.toNat < UInt256.size := by - simpa [hupWordToNat, upNat, baseWord, scaledNat] using hscaled - have hsecondFlag : - UInt256.land - (UInt256.gt multiplier - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) (UInt256.ofNat upNat))) - (UInt256.isZero (UInt256.isZero (UInt256.ofNat upNat))) = ⟨0⟩ := - checkedMulOverflowFlag_zero (UInt256.ofNat upNat) multiplier hsecondMulLt - have hsecondFlagLeft : - UInt256.land (UInt256.isZero (UInt256.isZero (UInt256.ofNat upNat))) - (UInt256.gt multiplier - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) (UInt256.ofNat upNat))) = - ⟨0⟩ := by - rw [u256_land_comm] - exact hsecondFlag - have hsecondMulWord : - UInt256.mul (UInt256.ofNat upNat) multiplier = UInt256.ofNat scaledNat := by - calc - UInt256.mul (UInt256.ofNat upNat) multiplier = - UInt256.ofNat ((UInt256.ofNat upNat).toNat * multiplier.toNat) := - u256_mul_eq_ofNat_of_lt (UInt256.ofNat upNat) multiplier hsecondMulLt - _ = UInt256.ofNat scaledNat := by - simp [scaledNat, getRewardAccruedScaledNat, hupWordToNat] - have hdivWord : - UInt256.div (UInt256.ofNat scaledNat) (⟨1000000000000000000⟩ : UInt256) = - UInt256.ofNat (getRewardAccruedReturnNat multiplier upNat) := by - simpa [scaledNat, getRewardAccruedReturnNat] using - u256_div_factorScale_ofNat (n := scaledNat) - (by simpa [scaledNat, upNat, baseWord] using hscaled) - have rd3758 := evm_run rd with [ - push1 ⟨64⟩, dup2, add, - raw mload 0 (rewardConfigShouldUpscaleFromSlot0 slot0) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload256 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap3, dup4, and, - swap3, swap1, iszero] - have rd3758' := rd3758 - rw [hbaseCleanLeft, hshouldIsZero] at rd3758' - have rd3769pre := evm_run rd3758' with [ - push2 ⟨3808⟩, jumpiNT (by native_decide), - swap1, push1 ⟨96⟩, push2 ⟨3794⟩] - have rd3769 := rd3769pre.pushConst (⟨1000000000000000000⟩ : UInt256) - (width := 8) (op := .PUSH8) (by decide) (by native_decide) (by evm_ov) - have rd3671 := evm_run rd3769 with [ - swap5, push2 ⟨3804⟩, swap5, push1 ⟨32⟩, dup6, add, - raw mload 0 (rewardConfigRescaleFromSlot0 slot0) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload224 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - and, swap1, push2 ⟨3660⟩, jump (by jump_dest), - jumpdest, dup1, push1 ⟨0⟩, not, div, dup3, gt, dup2, iszero, iszero, and] - have rd3671' := rd3671 - rw [hrescaleClean, hfirstFlagLeft] at rd3671' - have rd3794 := evm_run rd3671' with [ - push2 ⟨3252⟩, jumpiNT (by native_decide), mul, swap1, jump (by jump_dest), - jumpdest] - have rd3794' := rd3794 - rw [hfirstMulWord] at rd3794' - have rd3671₂ := evm_run rd3794' with [ - swap2, jumpdest, add, - raw mload 0 multiplier getRewardOwedBaseTrackingPostCallAw - (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload288 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - swap1, push2 ⟨3660⟩, jump (by jump_dest), - jumpdest, dup1, push1 ⟨0⟩, not, div, dup3, gt, dup2, iszero, iszero, and] - have rd3671₂' := rd3671₂ - rw [hsecondFlagLeft] at rd3671₂' - have rd3804 := evm_run rd3671₂' with [ - push2 ⟨3252⟩, jumpiNT (by native_decide), mul, swap1, jump (by jump_dest), - jumpdest] - have rd3804' := rd3804 - rw [hsecondMulWord] at rd3804' - have rd2499 := evm_run rd3804' with [ - div, swap1, jump (by jump_dest)] - rw [hdivWord] at rd2499 - exact ⟨_, _, by - simpa [baseWord, upNat, scaledNat, getRewardOwedBaseTrackingReturnWord] using rd2499⟩ - -set_option maxHeartbeats 2000000 in -theorem cometRewardsGetRewardOwedX_getRewardAccrued_downscale_success - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {accrueOut baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3740⟩ - [⟨192⟩, getRewardOwedBaseTrackingReturnWord baseOut, ⟨2499⟩, claimed, - ⟨0⟩, solcAddrMask, ⟨32⟩, ⟨192⟩, ⟨64⟩] - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : (getRewardOwedBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 = ⟨0⟩) - (hrescaleNZ : rewardConfigRescaleFromSlot0 slot0 ≠ ⟨0⟩) - (hscaled : - getRewardAccruedScaledNat multiplier - (getRewardAccruedDownscaledNat slot0 (getRewardOwedBaseTrackingReturnWord baseOut)) < - UInt256.size) : - ∃ k' C', RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2499⟩ - [ UInt256.ofNat - (getRewardAccruedReturnNat multiplier - (getRewardAccruedDownscaledNat slot0 - (getRewardOwedBaseTrackingReturnWord baseOut))), - claimed, ⟨0⟩, solcAddrMask, ⟨32⟩, ⟨192⟩, ⟨64⟩] - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k' C' := by - let baseWord : UInt256 := getRewardOwedBaseTrackingReturnWord baseOut - let downNat : ℕ := getRewardAccruedDownscaledNat slot0 baseWord - let scaledNat : ℕ := getRewardAccruedScaledNat multiplier downNat - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have hbaseClean : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using uint64Mask_clean hbase64' - have hbaseCleanLeft : - UInt256.land - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) - baseWord = baseWord := by - rw [u256_land_comm] - exact hbaseClean - have hrescale64 : (rewardConfigRescaleFromSlot0 slot0).toNat < EVM.twoPow 64 := by - simpa [rewardConfigRescaleFromSlot0, EVM.twoPow] using - rewardConfigRescaleWord_lt slot0 - have hrescaleClean : - UInt256.land (rewardConfigRescaleFromSlot0 slot0) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - rewardConfigRescaleFromSlot0 slot0 := by - simpa [uint64Mask] using uint64Mask_clean hrescale64 - have hshouldWord : - rewardConfigShouldUpscaleFromSlot0 slot0 = ⟨0⟩ := - rewardConfigShouldUpscaleFromSlot0_eq_zero_of_raw_zero hshould - have hshouldIsZero : - UInt256.isZero (rewardConfigShouldUpscaleFromSlot0 slot0) = ⟨1⟩ := by - rw [hshouldWord] - native_decide - have hrescaleIsZero : UInt256.isZero (rewardConfigRescaleFromSlot0 slot0) = ⟨0⟩ := - isZero_eq_zero_of_ne hrescaleNZ - have hdownWord : - UInt256.div baseWord (rewardConfigRescaleFromSlot0 slot0) = UInt256.ofNat downNat := by - simpa [downNat, baseWord, getRewardAccruedDownscaledNat] using - u256_div_eq_ofNat baseWord (rewardConfigRescaleFromSlot0 slot0) - have hdownLt : downNat < UInt256.size := by - have hle : downNat ≤ baseWord.toNat := by - simpa [downNat, getRewardAccruedDownscaledNat] using - Nat.div_le_self baseWord.toNat (rewardConfigRescaleFromSlot0 slot0).toNat - exact lt_of_le_of_lt hle baseWord.val.isLt - have hdownWordToNat : (UInt256.ofNat downNat).toNat = downNat := - UInt256.toNat_ofNat_of_lt hdownLt - have hsecondMulLt : - (UInt256.ofNat downNat).toNat * multiplier.toNat < UInt256.size := by - simpa [hdownWordToNat, downNat, baseWord, scaledNat] using hscaled - have hsecondFlag : - UInt256.land - (UInt256.gt multiplier - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) (UInt256.ofNat downNat))) - (UInt256.isZero (UInt256.isZero (UInt256.ofNat downNat))) = ⟨0⟩ := - checkedMulOverflowFlag_zero (UInt256.ofNat downNat) multiplier hsecondMulLt - have hsecondFlagLeft : - UInt256.land (UInt256.isZero (UInt256.isZero (UInt256.ofNat downNat))) - (UInt256.gt multiplier - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) (UInt256.ofNat downNat))) = - ⟨0⟩ := by - rw [u256_land_comm] - exact hsecondFlag - have hsecondMulWord : - UInt256.mul (UInt256.ofNat downNat) multiplier = UInt256.ofNat scaledNat := by - calc - UInt256.mul (UInt256.ofNat downNat) multiplier = - UInt256.ofNat ((UInt256.ofNat downNat).toNat * multiplier.toNat) := - u256_mul_eq_ofNat_of_lt (UInt256.ofNat downNat) multiplier hsecondMulLt - _ = UInt256.ofNat scaledNat := by - simp [scaledNat, getRewardAccruedScaledNat, hdownWordToNat] - have hdivWord : - UInt256.div (UInt256.ofNat scaledNat) (⟨1000000000000000000⟩ : UInt256) = - UInt256.ofNat (getRewardAccruedReturnNat multiplier downNat) := by - simpa [scaledNat, getRewardAccruedReturnNat] using - u256_div_factorScale_ofNat (n := scaledNat) - (by simpa [scaledNat, downNat, baseWord] using hscaled) - have rd3758 := evm_run rd with [ - push1 ⟨64⟩, dup2, add, - raw mload 0 (rewardConfigShouldUpscaleFromSlot0 slot0) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload256 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap3, dup4, and, - swap3, swap1, iszero] - have rd3758' := rd3758 - rw [hbaseCleanLeft, hshouldIsZero] at rd3758' - have rd3817 := evm_run rd3758' with [ - push2 ⟨3808⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push1 ⟨32⟩, dup3, add, - raw mload 0 (rewardConfigRescaleFromSlot0 slot0) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload224 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - and, swap1, dup2, iszero] - have rd3817' := rd3817 - rw [hrescaleClean, hrescaleIsZero] at rd3817' - have rd3827pre := evm_run rd3817' with [ - push2 ⟨3161⟩, jumpiNT (by native_decide), - push1 ⟨96⟩, push2 ⟨3804⟩, swap3] - have rd3828 := rd3827pre.pushConst (⟨1000000000000000000⟩ : UInt256) - (width := 8) (op := .PUSH8) (by decide) (by native_decide) (by evm_ov) - have rd3796 := evm_run rd3828 with [ - swap5, div, swap2, push2 ⟨3796⟩, jump (by jump_dest), jumpdest] - have rd3796' := rd3796 - rw [hdownWord] at rd3796' - have rd3671₂ := evm_run rd3796' with [ - add, - raw mload 0 multiplier getRewardOwedBaseTrackingPostCallAw - (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload288 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - swap1, push2 ⟨3660⟩, jump (by jump_dest), - jumpdest, dup1, push1 ⟨0⟩, not, div, dup3, gt, dup2, iszero, iszero, and] - have rd3671₂' := rd3671₂ - rw [hsecondFlagLeft] at rd3671₂' - have rd3804 := evm_run rd3671₂' with [ - push2 ⟨3252⟩, jumpiNT (by native_decide), mul, swap1, jump (by jump_dest), - jumpdest] - have rd3804' := rd3804 - rw [hsecondMulWord] at rd3804' - have rd2499 := evm_run rd3804' with [ - div, swap1, jump (by jump_dest)] - rw [hdivWord] at rd2499 - exact ⟨_, _, by - simpa [baseWord, downNat, scaledNat, getRewardOwedBaseTrackingReturnWord] using rd2499⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsGetRewardOwedX_panic12_from3161 - {cA gh bl σ σ₀ A I} {g : Sat256} {mem rdata : ByteArray} - {stack : List UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3161⟩ - stack mem getRewardOwedBaseTrackingPostCallAw rdata acc k C) - (hov : stack.length + 2 ≤ 1024) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hsel : - UInt256.shiftLeft (⟨0x4e487b71⟩ : UInt256) ⟨224⟩ = - setRewardConfigPanicSelector := by - rfl - have rd3172₀ := evm_run rd with [ - jumpdest, push4 ⟨0x4e487b71⟩, push1 ⟨224⟩, shl, push1 ⟨0⟩] - have rd3172 := rd3172₀ - rw [hsel] at rd3172 - have rd3173 := evm_run rd3172 with [ - raw mstore 0 (setRewardConfigPanicMem0 mem) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov)] - have rd3178 := evm_run rd3173 with [ - push1 ⟨18⟩, push1 ⟨4⟩, - raw mstore 0 (setRewardConfigPanicMem ⟨18⟩ mem) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov), - push1 ⟨36⟩, push1 ⟨0⟩] - exact evm_run rd3178 with [raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsGetRewardOwedX_panic11_from3252 - {cA gh bl σ σ₀ A I} {g : Sat256} {mem rdata : ByteArray} - {stack : List UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3252⟩ - stack mem getRewardOwedBaseTrackingPostCallAw rdata acc k C) - (hov : stack.length + 2 ≤ 1024) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hsel : - UInt256.shiftLeft (⟨0x4e487b71⟩ : UInt256) ⟨224⟩ = - setRewardConfigPanicSelector := by - rfl - have rd3263₀ := evm_run rd with [ - jumpdest, push4 ⟨0x4e487b71⟩, push1 ⟨224⟩, shl, push1 ⟨0⟩] - have rd3263 := rd3263₀ - rw [hsel] at rd3263 - have rd3264 := evm_run rd3263 with [ - raw mstore 0 (setRewardConfigPanicMem0 mem) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov)] - have rd3269 := evm_run rd3264 with [ - push1 ⟨17⟩, push1 ⟨4⟩, - raw mstore 0 (setRewardConfigPanicMem ⟨17⟩ mem) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov), - push1 ⟨36⟩, push1 ⟨0⟩] - exact evm_run rd3269 with [raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsGetRewardOwedX_getRewardAccrued_downscale_zero_revert - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {accrueOut baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3740⟩ - [⟨192⟩, getRewardOwedBaseTrackingReturnWord baseOut, ⟨2499⟩, claimed, - ⟨0⟩, solcAddrMask, ⟨32⟩, ⟨192⟩, ⟨64⟩] - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : (getRewardOwedBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 = ⟨0⟩) - (hrescaleZero : rewardConfigRescaleFromSlot0 slot0 = ⟨0⟩) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let baseWord : UInt256 := getRewardOwedBaseTrackingReturnWord baseOut - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have hbaseClean : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using uint64Mask_clean hbase64' - have hbaseCleanLeft : - UInt256.land - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) - baseWord = baseWord := by - rw [u256_land_comm] - exact hbaseClean - have hrescaleClean : - UInt256.land (rewardConfigRescaleFromSlot0 slot0) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - rewardConfigRescaleFromSlot0 slot0 := by - rw [hrescaleZero] - native_decide - have hshouldWord : - rewardConfigShouldUpscaleFromSlot0 slot0 = ⟨0⟩ := - rewardConfigShouldUpscaleFromSlot0_eq_zero_of_raw_zero hshould - have hshouldIsZero : - UInt256.isZero (rewardConfigShouldUpscaleFromSlot0 slot0) = ⟨1⟩ := by - rw [hshouldWord] - native_decide - have hrescaleIsZero : UInt256.isZero (rewardConfigRescaleFromSlot0 slot0) = ⟨1⟩ := by - rw [hrescaleZero] - native_decide - have rd3758 := evm_run rd with [ - push1 ⟨64⟩, dup2, add, - raw mload 0 (rewardConfigShouldUpscaleFromSlot0 slot0) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload256 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap3, dup4, and, - swap3, swap1, iszero] - have rd3758' := rd3758 - rw [hbaseCleanLeft, hshouldIsZero] at rd3758' - have rd3817 := evm_run rd3758' with [ - push2 ⟨3808⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push1 ⟨32⟩, dup3, add, - raw mload 0 (rewardConfigRescaleFromSlot0 slot0) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload224 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - and, swap1, dup2, iszero] - have rd3817' := rd3817 - rw [hrescaleClean, hrescaleIsZero] at rd3817' - have rd3161 := evm_run rd3817' with [ - push2 ⟨3161⟩, jumpiT (by native_decide) (by jump_dest)] - exact cometRewardsGetRewardOwedX_panic12_from3161 rd3161 (by simp) - -set_option maxHeartbeats 2000000 in -theorem cometRewardsGetRewardOwedX_getRewardAccrued_upscale_overflow_revert - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {accrueOut baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3740⟩ - [⟨192⟩, getRewardOwedBaseTrackingReturnWord baseOut, ⟨2499⟩, claimed, - ⟨0⟩, solcAddrMask, ⟨32⟩, ⟨192⟩, ⟨64⟩] - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : (getRewardOwedBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 ≠ ⟨0⟩) - (hover : - UInt256.size ≤ getRewardAccruedScaledNat multiplier - (getRewardAccruedUpscaledNat slot0 (getRewardOwedBaseTrackingReturnWord baseOut))) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let baseWord : UInt256 := getRewardOwedBaseTrackingReturnWord baseOut - let upNat : ℕ := getRewardAccruedUpscaledNat slot0 baseWord - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have hup : upNat < UInt256.size := by - simpa [upNat, baseWord] using - getRewardAccruedUpscaledNat_lt_size_of_base64 - (slot0 := slot0) (accrued := baseWord) hbase64' - have hrescale64 : (rewardConfigRescaleFromSlot0 slot0).toNat < EVM.twoPow 64 := by - simpa [rewardConfigRescaleFromSlot0, EVM.twoPow] using - rewardConfigRescaleWord_lt slot0 - have hbaseClean : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using uint64Mask_clean hbase64' - have hbaseCleanLeft : - UInt256.land - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) - baseWord = baseWord := by - rw [u256_land_comm] - exact hbaseClean - have hrescaleClean : - UInt256.land (rewardConfigRescaleFromSlot0 slot0) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - rewardConfigRescaleFromSlot0 slot0 := by - simpa [uint64Mask] using uint64Mask_clean hrescale64 - have hshouldWord : - rewardConfigShouldUpscaleFromSlot0 slot0 = ⟨1⟩ := - rewardConfigShouldUpscaleFromSlot0_eq_one_of_raw_ne_zero hshould - have hshouldIsZero : - UInt256.isZero (rewardConfigShouldUpscaleFromSlot0 slot0) = ⟨0⟩ := by - rw [hshouldWord] - native_decide - have hfirstMulLt : - baseWord.toNat * (rewardConfigRescaleFromSlot0 slot0).toNat < UInt256.size := by - simpa [upNat, baseWord, getRewardAccruedUpscaledNat] using hup - have hfirstFlag : - UInt256.land (UInt256.isZero (UInt256.isZero baseWord)) - (UInt256.gt (rewardConfigRescaleFromSlot0 slot0) - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) baseWord)) = ⟨0⟩ := by - rw [u256_land_comm] - exact checkedMulOverflowFlag_zero baseWord (rewardConfigRescaleFromSlot0 slot0) - hfirstMulLt - have hfirstMulWord : - UInt256.mul baseWord (rewardConfigRescaleFromSlot0 slot0) = UInt256.ofNat upNat := by - simpa [upNat, baseWord, getRewardAccruedUpscaledNat] using - u256_mul_eq_ofNat_of_lt baseWord (rewardConfigRescaleFromSlot0 slot0) hfirstMulLt - have hupWordToNat : (UInt256.ofNat upNat).toNat = upNat := - UInt256.toNat_ofNat_of_lt hup - have hsecondOver : - UInt256.size ≤ (UInt256.ofNat upNat).toNat * multiplier.toNat := by - simpa [hupWordToNat, upNat, baseWord, getRewardAccruedScaledNat] using hover - have hsecondFlag : - UInt256.land (UInt256.isZero (UInt256.isZero (UInt256.ofNat upNat))) - (UInt256.gt multiplier - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) (UInt256.ofNat upNat))) = - ⟨1⟩ := - checkedMulOverflowFlag_one (UInt256.ofNat upNat) multiplier hsecondOver - have rd3758 := evm_run rd with [ - push1 ⟨64⟩, dup2, add, - raw mload 0 (rewardConfigShouldUpscaleFromSlot0 slot0) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload256 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap3, dup4, and, - swap3, swap1, iszero] - have rd3758' := rd3758 - rw [hbaseCleanLeft, hshouldIsZero] at rd3758' - have rd3769pre := evm_run rd3758' with [ - push2 ⟨3808⟩, jumpiNT (by native_decide), - swap1, push1 ⟨96⟩, push2 ⟨3794⟩] - have rd3769 := rd3769pre.pushConst (⟨1000000000000000000⟩ : UInt256) - (width := 8) (op := .PUSH8) (by decide) (by native_decide) (by evm_ov) - have rd3671 := evm_run rd3769 with [ - swap5, push2 ⟨3804⟩, swap5, push1 ⟨32⟩, dup6, add, - raw mload 0 (rewardConfigRescaleFromSlot0 slot0) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload224 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - and, swap1, push2 ⟨3660⟩, jump (by jump_dest), - jumpdest, dup1, push1 ⟨0⟩, not, div, dup3, gt, dup2, iszero, iszero, and] - have rd3671' := rd3671 - rw [hrescaleClean, hfirstFlag] at rd3671' - have rd3794 := evm_run rd3671' with [ - push2 ⟨3252⟩, jumpiNT (by native_decide), mul, swap1, jump (by jump_dest), - jumpdest] - have rd3794' := rd3794 - rw [hfirstMulWord] at rd3794' - have rd3671₂ := evm_run rd3794' with [ - swap2, jumpdest, add, - raw mload 0 multiplier getRewardOwedBaseTrackingPostCallAw - (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload288 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - swap1, push2 ⟨3660⟩, jump (by jump_dest), - jumpdest, dup1, push1 ⟨0⟩, not, div, dup3, gt, dup2, iszero, iszero, and] - have rd3671₂' := rd3671₂ - rw [hsecondFlag] at rd3671₂' - have rd3252 := evm_run rd3671₂' with [ - push2 ⟨3252⟩, jumpiT (by native_decide) (by jump_dest)] - exact cometRewardsGetRewardOwedX_panic11_from3252 rd3252 (by simp) - -set_option maxHeartbeats 2000000 in -theorem cometRewardsGetRewardOwedX_getRewardAccrued_downscale_overflow_revert - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {accrueOut baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3740⟩ - [⟨192⟩, getRewardOwedBaseTrackingReturnWord baseOut, ⟨2499⟩, claimed, - ⟨0⟩, solcAddrMask, ⟨32⟩, ⟨192⟩, ⟨64⟩] - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : (getRewardOwedBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) - (hshould : rewardConfigShouldUpscaleRawFromSlot0 slot0 = ⟨0⟩) - (hrescaleNZ : rewardConfigRescaleFromSlot0 slot0 ≠ ⟨0⟩) - (hover : - UInt256.size ≤ getRewardAccruedScaledNat multiplier - (getRewardAccruedDownscaledNat slot0 (getRewardOwedBaseTrackingReturnWord baseOut))) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let baseWord : UInt256 := getRewardOwedBaseTrackingReturnWord baseOut - let downNat : ℕ := getRewardAccruedDownscaledNat slot0 baseWord - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have hbaseClean : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using uint64Mask_clean hbase64' - have hbaseCleanLeft : - UInt256.land - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) - baseWord = baseWord := by - rw [u256_land_comm] - exact hbaseClean - have hrescale64 : (rewardConfigRescaleFromSlot0 slot0).toNat < EVM.twoPow 64 := by - simpa [rewardConfigRescaleFromSlot0, EVM.twoPow] using - rewardConfigRescaleWord_lt slot0 - have hrescaleClean : - UInt256.land (rewardConfigRescaleFromSlot0 slot0) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - rewardConfigRescaleFromSlot0 slot0 := by - simpa [uint64Mask] using uint64Mask_clean hrescale64 - have hshouldWord : - rewardConfigShouldUpscaleFromSlot0 slot0 = ⟨0⟩ := - rewardConfigShouldUpscaleFromSlot0_eq_zero_of_raw_zero hshould - have hshouldIsZero : - UInt256.isZero (rewardConfigShouldUpscaleFromSlot0 slot0) = ⟨1⟩ := by - rw [hshouldWord] - native_decide - have hrescaleIsZero : UInt256.isZero (rewardConfigRescaleFromSlot0 slot0) = ⟨0⟩ := - isZero_eq_zero_of_ne hrescaleNZ - have hdownWord : - UInt256.div baseWord (rewardConfigRescaleFromSlot0 slot0) = UInt256.ofNat downNat := by - simpa [downNat, baseWord, getRewardAccruedDownscaledNat] using - u256_div_eq_ofNat baseWord (rewardConfigRescaleFromSlot0 slot0) - have hdownLt : downNat < UInt256.size := by - have hle : downNat ≤ baseWord.toNat := by - simpa [downNat, getRewardAccruedDownscaledNat] using - Nat.div_le_self baseWord.toNat (rewardConfigRescaleFromSlot0 slot0).toNat - exact lt_of_le_of_lt hle baseWord.val.isLt - have hdownWordToNat : (UInt256.ofNat downNat).toNat = downNat := - UInt256.toNat_ofNat_of_lt hdownLt - have hsecondOver : - UInt256.size ≤ (UInt256.ofNat downNat).toNat * multiplier.toNat := by - simpa [hdownWordToNat, downNat, baseWord, getRewardAccruedScaledNat] using hover - have hsecondFlag : - UInt256.land (UInt256.isZero (UInt256.isZero (UInt256.ofNat downNat))) - (UInt256.gt multiplier - (UInt256.div (UInt256.lnot (⟨0⟩ : UInt256)) (UInt256.ofNat downNat))) = - ⟨1⟩ := - checkedMulOverflowFlag_one (UInt256.ofNat downNat) multiplier hsecondOver - have rd3758 := evm_run rd with [ - push1 ⟨64⟩, dup2, add, - raw mload 0 (rewardConfigShouldUpscaleFromSlot0 slot0) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload256 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap3, dup4, and, - swap3, swap1, iszero] - have rd3758' := rd3758 - rw [hbaseCleanLeft, hshouldIsZero] at rd3758' - have rd3817 := evm_run rd3758' with [ - push2 ⟨3808⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push1 ⟨32⟩, dup3, add, - raw mload 0 (rewardConfigRescaleFromSlot0 slot0) - getRewardOwedBaseTrackingPostCallAw (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload224 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - and, swap1, dup2, iszero] - have rd3817' := rd3817 - rw [hrescaleClean, hrescaleIsZero] at rd3817' - have rd3827pre := evm_run rd3817' with [ - push2 ⟨3161⟩, jumpiNT (by native_decide), - push1 ⟨96⟩, push2 ⟨3804⟩, swap3] - have rd3828 := rd3827pre.pushConst (⟨1000000000000000000⟩ : UInt256) - (width := 8) (op := .PUSH8) (by decide) (by native_decide) (by evm_ov) - have rd3796 := evm_run rd3828 with [ - swap5, div, swap2, push2 ⟨3796⟩, jump (by jump_dest), jumpdest] - have rd3796' := rd3796 - rw [hdownWord] at rd3796' - have rd3671₂ := evm_run rd3796' with [ - add, - raw mload 0 multiplier getRewardOwedBaseTrackingPostCallAw - (by native_decide) mem_cost - (getRewardOwedBaseTrackingPostDecodeMem_mload288 - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - swap1, push2 ⟨3660⟩, jump (by jump_dest), - jumpdest, dup1, push1 ⟨0⟩, not, div, dup3, gt, dup2, iszero, iszero, and] - have rd3671₂' := rd3671₂ - rw [hsecondFlag] at rd3671₂' - have rd3252 := evm_run rd3671₂' with [ - push2 ⟨3252⟩, jumpiT (by native_decide) (by jump_dest)] - exact cometRewardsGetRewardOwedX_panic11_from3252 rd3252 (by simp) - -set_option maxHeartbeats 2000000 in -theorem cometRewardsGetRewardOwedX_after_baseTracking_noncanon_revert - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier : UInt256} {accrueOut baseOut : ByteArray} - {claimed : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (getRewardOwedBaseTrackingCallPc + ⟨1⟩) - (getRewardOwedBaseTrackingPostCallStack true claimed) - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C) - (haccrueSize : accrueOut.size < UInt256.size) - (hout32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hbase64 : ¬ (getRewardOwedBaseTrackingReturnWord baseOut).toNat < EVM.twoPow 64) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let baseWord : UInt256 := getRewardOwedBaseTrackingReturnWord baseOut - have hbase64' : ¬ baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - let rdsz : UInt256 := UInt256.ofNat baseOut.size - have hrdsz_toNat : rdsz.toNat = baseOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hbaseSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hout32 - have rd3724 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3724⟩ - [⟨1⟩, ⟨192⟩, ⟨320⟩, ⟨2499⟩, claimed, ⟨0⟩, solcAddrMask, ⟨32⟩, - ⟨192⟩, ⟨64⟩] - (getRewardOwedBaseTrackingPostCallMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw baseOut acc k C := by - simpa [getRewardOwedBaseTrackingCallPc, getRewardOwedBaseTrackingPostCallStack, - getRewardOwedBaseTrackingPostCallTail] using rd - have rd3855₀ := evm_run rd3724 with [ - swap2, dup3, iszero, push2 ⟨3876⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap3, push2 ⟨3844⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push2 ⟨3869⟩, swap2, swap3, pop, push1 ⟨32⟩, - returndatasize, dup2, gt] - have rd3855 := rd3855₀ - rw [show UInt256.ofNat baseOut.size = rdsz from rfl, hgt] at rd3855 - have rd3071 := evm_run rd3855 with [ - push2 ⟨734⟩, jumpiNT (by native_decide), - push2 ⟨719⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), - push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 - (getRewardOwedBaseTrackingPostDecodeMem I slot0 multiplier accrueOut baseOut) - getRewardOwedBaseTrackingPostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold getRewardOwedBaseTrackingPostDecodeMem Reasoning.Theory.writeWord - rfl) - (by native_decide) (by evm_ov)] - have rd3106 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3106⟩, - jump (by jump_dest), jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, - slt, push2 ⟨1004⟩, jumpiNT (by native_decide)] - have rd3129 := evm_run rd3106 with [ - raw mload 0 baseWord getRewardOwedBaseTrackingPostCallAw (by native_decide) - mem_cost - (by - simpa [baseWord] using - getRewardOwedBaseTrackingPostDecodeMem_mload320_of_size_ge - I slot0 multiplier haccrueSize hout32 hbaseSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, and, dup2, sub] - have hnotClean : UInt256.land baseWord uint64Mask ≠ baseWord := - uint64Mask_not_clean hbase64' - have hneq : - baseWord ≠ - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) := by - intro hEq - exact hnotClean (by simpa [uint64Mask] using hEq.symm) - have hsub : - UInt256.sub baseWord - (UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) ≠ ⟨0⟩ := - u256_sub_ne_zero_of_ne hneq - have rd1004 := evm_run rd3129 with [ - push2 ⟨1004⟩, jumpiT hsub (by jump_dest)] - exact evm_run rd1004 with [ - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsGetRewardOwedX_callDepthLimit {cA gh bl σ σ₀ A I} {g : UInt256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) - (hnz : rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) ≠ ⟨0⟩) - (hcodeSize : - Reasoning.Theory.extCodeSizeWord σ - (UInt256.land (getRewardOwedCometWord I) solcAddrMask) ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) - (hdepth : I.depth = 1024) : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - obtain ⟨gasArg, k0, C0, rd2450⟩ := - cometRewardsGetRewardOwedX_call_accrueAccount (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hcanonComet hcanonAccount hnz hcodeSize hreach - have rd2450Call : - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) - getRewardOwedAccrueAccountCallPc - (gasArg :: UInt256.land (getRewardOwedCometWord I) solcAddrMask :: ⟨0⟩ :: - ⟨320⟩ :: getRewardOwedAccrueAccountCallSize :: ⟨320⟩ :: ⟨0⟩ :: - getRewardOwedAccrueAccountPostCallTail I) - (getRewardOwedAccrueAccountCalldataMem I (getRewardOwedRewardConfigSlot0Word σ I) - (getRewardOwedMultiplierWord σ I)) - getRewardOwedAccrueAccountPostCallAw ByteArray.empty (cA, σ) k0 C0 := by - simpa [getRewardOwedAccrueAccountPostCallTail] using rd2450 - have hdecCall : - decode cometRewardsBytecode getRewardOwedAccrueAccountCallPc = some (.CALL, .none) := by - unfold getRewardOwedAccrueAccountCallPc - native_decide - have hdepthInit : - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).executionEnv.depth = 1024 := by - simpa [initState] using hdepth - obtain ⟨k', C', rdPost₀⟩ := - RD.callDepthLimit (t := getRewardOwedAccrueAccountPostCallTail I) - rd2450Call hdecCall hdepthInit (by simp [getRewardOwedAccrueAccountPostCallTail]) - have rdPost : - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) - (getRewardOwedAccrueAccountCallPc + ⟨1⟩) - (getRewardOwedAccrueAccountPostCallStack false I) - (getRewardOwedAccrueAccountPostCallMem I - (getRewardOwedRewardConfigSlot0Word σ I) (getRewardOwedMultiplierWord σ I) - ByteArray.empty) - getRewardOwedAccrueAccountPostCallAw ByteArray.empty (cA, σ) k' C' := by - simpa [getRewardOwedAccrueAccountPostCallStack, getRewardOwedAccrueAccountPostCallTail, - getRewardOwedAccrueAccountPostCallMem, getRewardOwedAccrueAccountPostCallAw, - getRewardOwedAccrueAccountCallSize] using rdPost₀ - exact cometRewardsGetRewardOwedX_after_accrueAccount_failure - (slot0 := getRewardOwedRewardConfigSlot0Word σ I) - (multiplier := getRewardOwedMultiplierWord σ I) rdPost (by simp [UInt256.size]) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsGetRewardOwedX_tokenZero {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus) - (htokenZero : rewardConfigTokenFromSlot0 (getRewardOwedRewardConfigSlot0Word σ I) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2307⟩ := - cometRewardsGetRewardOwedX_dec2307_account (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hcanonAccount hreach - have hslot := getRewardOwedRewardConfigSlotOf_eq_solc I hcanonComet - let slot0 := getRewardOwedRewardConfigSlot0Word σ I - let multiplier := getRewardOwedMultiplierWord σ I - have rd2355 := evm_run rd2307 with [ - jumpdest, swap4, dup7, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - swap5, push2 ⟨2320⟩, dup7, push2 ⟨2976⟩, jump (by jump_dest), - jumpdest, push1 ⟨64⟩, dup2, add, swap1, dup2, lt, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, lor, - push2 ⟨3003⟩, jumpiNT (by native_decide), - push1 ⟨64⟩, - raw mstore 0 getRewardOwedAlloc64Mem (UInt256.ofNat 3) (by decide) mem_cost - (by unfold getRewardOwedAlloc64Mem Reasoning.Theory.writeWord; rfl) - (by decide) (by evm_ov), - jump (by jump_dest), - jumpdest, dup3, dup7, - raw mstore 6 (writeCascade getRewardOwedAlloc64Mem [(128, (⟨0⟩ : UInt256))]) - (UInt256.ofNat 5) (by decide) mem_cost - (by - unfold getRewardOwedAlloc64Mem Reasoning.Theory.writeCascade - Reasoning.Theory.writeWord - rfl) (by decide) (by evm_ov), - dup3, push1 ⟨32⟩, dup1, swap8, add, - raw mstore 3 getRewardOwedConfigZeroMem (UInt256.ofNat 6) (by decide) mem_cost - (by - unfold getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem - unfold Reasoning.Theory.writeCascade Reasoning.Theory.writeWord - rfl) - (by decide) (by evm_ov), - push1 ⟨1⟩, dup1, push1 ⟨160⟩, shl, sub, swap5, dup6, dup4, and, - swap5, dup6, dup6, - raw mstore 0 (wordAt0Mem (getRewardOwedCometWord I) getRewardOwedConfigZeroMem) - (UInt256.ofNat 6) (by decide) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, solcAddrMask_clean hcanonComet] - unfold getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem - unfold Reasoning.Theory.writeCascade wordAt0Mem Reasoning.Theory.writeWord - rfl) (by decide) (by evm_ov), - push1 ⟨1⟩, dup9, - raw mstore 0 (getRewardOwedRewardConfigHashMem I) (UInt256.ofNat 6) (by decide) mem_cost - (by - unfold getRewardOwedRewardConfigHashMem getRewardOwedConfigZeroMem - unfold getRewardOwedAlloc64Mem twoWordHashMem wordAt32Mem wordAt0Mem - unfold Reasoning.Theory.writeCascade Reasoning.Theory.writeWord - rfl) - (by decide) (by evm_ov), - push1 ⟨1⟩, dup11, dup7, - raw keccak256 0 (solcMappingSlot ⟨1⟩ (getRewardOwedCometWord I)) - (UInt256.ofNat 6) (by decide) mem_cost - (getRewardOwedRewardConfigHashMem_keccakSlot I) (by decide) (by evm_ov)] - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2355⟩ - [solcMappingSlot ⟨1⟩ (getRewardOwedCometWord I), ⟨1⟩, ⟨224⟩, ⟨4⟩, - getRewardOwedAccountWord I, getRewardOwedCometWord I, ⟨0⟩, - UInt256.land (getRewardOwedCometWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩), - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩, - ⟨32⟩, ⟨255⟩, ⟨64⟩] - (getRewardOwedRewardConfigHashMem I) (UInt256.ofNat 6) ByteArray.empty - (cA, σ) _ _ at rd2355 - rw [← hslot] at rd2355 - have rd2356 := Reasoning.Reach.RD.dup12 rd2355 (by native_decide) (by decide) - have rd2358 := evm_run rd2356 with [ - raw mload 0 ⟨192⟩ (UInt256.ofNat 6) (by decide) - mem_cost (getRewardOwedRewardConfigHashMem_mload64 I) (by decide) (by evm_ov), - swap11] - have rd2359 := Reasoning.Reach.RD.dup12 rd2358 (by native_decide) (by decide) - have rd2368 := evm_run rd2359 with [ - swap4, push2 ⟨2368⟩, dup6, push2 ⟨3025⟩, jump (by jump_dest), - jumpdest, push1 ⟨128⟩, dup2, add, swap1, dup2, lt, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, lor, - push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩, - raw mstore 0 (getRewardOwedConfigAllocMem I) (UInt256.ofNat 6) (by decide) mem_cost - (by - unfold getRewardOwedConfigAllocMem getRewardOwedRewardConfigHashMem getRewardOwedConfigZeroMem - unfold getRewardOwedAlloc64Mem twoWordHashMem wordAt32Mem wordAt0Mem - unfold Reasoning.Theory.writeCascade Reasoning.Theory.writeWord - rfl) - (by decide) (by evm_ov), - jump (by jump_dest), jumpdest] - have rdAfterSloadPre := evm_run rd2368 with [dup3] - obtain ⟨_, _, rdAfterSload⟩ := rdAfterSloadPre.sload (by decide) (by evm_ov) - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (getRewardOwedRewardConfigSlot0Word σ I :: _) (getRewardOwedConfigAllocMem I) - (UInt256.ofNat 6) ByteArray.empty (cA, σ) _ _ at rdAfterSload - rw [show getRewardOwedRewardConfigSlot0Word σ I = slot0 from rfl] at rdAfterSload - have rd2409pre := evm_run rdAfterSload with [ - swap1, dup12, dup3, and, dup1, swap7, - raw mstore 3 (getRewardOwedConfigTokenMem I slot0) (UInt256.ofNat 7) (by decide) mem_cost - (by - unfold getRewardOwedConfigTokenMem getRewardOwedConfigAllocMem - unfold getRewardOwedRewardConfigHashMem getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem - unfold twoWordHashMem wordAt32Mem wordAt0Mem Reasoning.Theory.writeCascade - unfold Reasoning.Theory.writeWord rewardConfigTokenFromSlot0 slot0 - rfl) - (by decide) (by evm_ov), - dup14, dup14, dup7, dup1, push1 ⟨64⟩, shl, sub, dup5, push1 ⟨160⟩, shr, and, - swap2, add, - raw mstore 3 (getRewardOwedConfigRescaleMem I slot0) (UInt256.ofNat 8) (by decide) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩ = - UInt256.ofNat (2 ^ 64 - 1) from by native_decide] - unfold getRewardOwedConfigRescaleMem getRewardOwedConfigTokenMem getRewardOwedConfigAllocMem - unfold getRewardOwedRewardConfigHashMem getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem - unfold twoWordHashMem wordAt32Mem wordAt0Mem Reasoning.Theory.writeCascade - unfold Reasoning.Theory.writeWord rewardConfigRescaleFromSlot0 - unfold rewardConfigTokenFromSlot0 slot0 - rfl) (by decide) (by evm_ov), - shr, and, iszero, iszero, dup13, dup13, add, - raw mstore 3 (getRewardOwedConfigShouldMem I slot0) (UInt256.ofNat 9) (by decide) mem_cost - (by - unfold getRewardOwedConfigShouldMem getRewardOwedConfigRescaleMem - unfold getRewardOwedConfigTokenMem getRewardOwedConfigAllocMem getRewardOwedRewardConfigHashMem - unfold getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem twoWordHashMem wordAt32Mem wordAt0Mem - unfold Reasoning.Theory.writeCascade Reasoning.Theory.writeWord - unfold rewardConfigShouldUpscaleFromSlot0 rewardConfigShouldUpscaleRawFromSlot0 - unfold rewardConfigRescaleFromSlot0 rewardConfigTokenFromSlot0 slot0 - rfl) (by decide) (by evm_ov), - add] - obtain ⟨_, _, rdAfterMultiplier⟩ := rd2409pre.sload (by decide) (by evm_ov) - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (getRewardOwedMultiplierWord σ I :: _) (getRewardOwedConfigShouldMem I slot0) - (UInt256.ofNat 9) ByteArray.empty (cA, σ) _ _ at rdAfterMultiplier - rw [show getRewardOwedMultiplierWord σ I = multiplier from rfl] at rdAfterMultiplier - have rd2409 := evm_run rdAfterMultiplier with [ - push1 ⟨96⟩, dup11, add, - raw mstore 3 (getRewardOwedConfigMultiplierMem I slot0 multiplier) (UInt256.ofNat 10) (by decide) - mem_cost - (by - unfold getRewardOwedConfigMultiplierMem getRewardOwedConfigShouldMem - unfold getRewardOwedConfigRescaleMem getRewardOwedConfigTokenMem getRewardOwedConfigAllocMem - unfold getRewardOwedRewardConfigHashMem getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem - unfold twoWordHashMem wordAt32Mem wordAt0Mem Reasoning.Theory.writeCascade - unfold Reasoning.Theory.writeWord - unfold rewardConfigShouldUpscaleFromSlot0 rewardConfigShouldUpscaleRawFromSlot0 - unfold rewardConfigRescaleFromSlot0 rewardConfigTokenFromSlot0 slot0 multiplier - rfl) - (by decide) (by evm_ov), - iszero] - have htokenZeroSlot : rewardConfigTokenFromSlot0 slot0 = ⟨0⟩ := by - simpa [slot0] using htokenZero - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (UInt256.isZero (rewardConfigTokenFromSlot0 slot0) :: _) - (getRewardOwedConfigMultiplierMem I slot0 multiplier) (UInt256.ofNat 10) - ByteArray.empty (cA, σ) _ _ at rd2409 - rw [htokenZeroSlot] at rd2409 - change RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) _ - (⟨1⟩ :: _) (getRewardOwedConfigMultiplierMem I slot0 multiplier) - (UInt256.ofNat 10) ByteArray.empty (cA, σ) _ _ at rd2409 - have rd2592 := evm_run rd2409 with [ - push2 ⟨2592⟩, jumpiT (by native_decide) (by jump_dest)] - have rd2614 := evm_run rd2592 with [ - jumpdest, dup9, - raw mload 0 ⟨320⟩ (UInt256.ofNat 10) (by decide) mem_cost - (getRewardOwedConfigMultiplierMem_mload64 I slot0 multiplier) - (by decide) (by evm_ov), - push4 ⟨1311535579⟩, push1 ⟨225⟩, shl, dup2, - raw mstore 3 (getRewardOwedInvalidRewardConfigSelectorMem I slot0 multiplier) (UInt256.ofNat 11) - (by decide) mem_cost - (by - unfold getRewardOwedInvalidRewardConfigSelectorMem getRewardOwedConfigMultiplierMem - unfold getRewardOwedConfigShouldMem getRewardOwedConfigRescaleMem getRewardOwedConfigTokenMem - unfold getRewardOwedConfigAllocMem getRewardOwedRewardConfigHashMem getRewardOwedConfigZeroMem - unfold getRewardOwedAlloc64Mem twoWordHashMem wordAt32Mem wordAt0Mem - unfold Reasoning.Theory.writeCascade Reasoning.Theory.writeWord - unfold rewardConfigShouldUpscaleFromSlot0 rewardConfigShouldUpscaleRawFromSlot0 - unfold rewardConfigRescaleFromSlot0 rewardConfigTokenFromSlot0 slot0 multiplier - rfl) - (by decide) (by evm_ov), - swap1, dup2, add, dup6, swap1, - raw mstore 3 (getRewardOwedInvalidRewardConfigArgMem I slot0 multiplier) (UInt256.ofNat 12) - (by decide) mem_cost - (by - unfold getRewardOwedInvalidRewardConfigArgMem getRewardOwedInvalidRewardConfigSelectorMem - unfold getRewardOwedConfigMultiplierMem getRewardOwedConfigShouldMem getRewardOwedConfigRescaleMem - unfold getRewardOwedConfigTokenMem getRewardOwedConfigAllocMem getRewardOwedRewardConfigHashMem - unfold getRewardOwedConfigZeroMem getRewardOwedAlloc64Mem twoWordHashMem wordAt32Mem wordAt0Mem - unfold Reasoning.Theory.writeCascade Reasoning.Theory.writeWord - unfold rewardConfigShouldUpscaleFromSlot0 rewardConfigShouldUpscaleRawFromSlot0 - unfold rewardConfigRescaleFromSlot0 rewardConfigTokenFromSlot0 slot0 multiplier - rw [show ((⟨320⟩ : UInt256) + ⟨4⟩).toNat = 324 from by native_decide] - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, solcAddrMask_clean hcanonComet]) - (by decide) (by evm_ov), - push1 ⟨36⟩, swap1] - exact evm_run rd2614 with [raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -theorem cometRewardsGetRewardOwedBodyReverts_tokenZero (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hz : rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evm I) = ⟨0⟩) : - ExecTransitionBody config contract evm (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [getRewardOwedTransition, externalEntryGuard, nonpayable, calldataSizeGuard, - checkedExternalCallStmts] using - (((((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (getRewardOwedStore I) hsize)).letStep - (evalExpr_getRewardOwed_token_of evm I (getRewardOwedFrame_comet evm I) - (getRewardOwedFrame_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_rescale_of evm I - (getRewardOwedAfterTokenLocals_comet evm I) - (getRewardOwedAfterTokenLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_shouldUpscale_of evm I - (getRewardOwedAfterRescaleLocals_comet evm I) - (getRewardOwedAfterRescaleLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_multiplier_of evm I - (getRewardOwedAfterShouldLocals_comet evm I) - (getRewardOwedAfterShouldLocals_no_rewardConfig evm I))).requireRevert - (evalExpr_getRewardOwed_token_ne_zero_false_of evm (getRewardOwedSlot0Load evm I) - (getRewardOwedConfigLocals_token evm I) hz) - -theorem cometRewardsGetRewardOwedBodyReverts_accrueNoCode (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hnz : rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evm I) ≠ ⟨0⟩) - (hguard : - evalExpr? config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (.binary .gt (.extCodeSize (.var "comet")) (.intLit 0)) = .ok (.bool false)) : - ExecTransitionBody config contract evm (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hcheckedSmall : - ExecBlock config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued") - .reverted := by - exact checkedExternalCallVarNoCode (cfg := config) (C := contract) - (evm := evm) (locals := getRewardOwedConfigLocals evm I) - (receiver := "comet") (retVar := "_accrued") (name := "accrueAccount") - (sendVal := 0) (args := [.var "account"]) (perm := true) hguard - have hchecked : - ExecBlock config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued" ++ - [ .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))), - .internalCall "getRewardAccrued" - [ .var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier" ] "accrued", - .letDecl "owed" (some uint256) - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)), - .return [(.tupleLit [.var "token", .var "owed"])] ]) - .reverted := by - exact execBlock_append_term hcheckedSmall (by intro f e h; cases h) - have hprefix : - ABlock config evm { contract := contract, locals := getRewardOwedStore I } - getRewardOwedTransition.body - { contract := contract, locals := getRewardOwedConfigLocals evm I } - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued" ++ - [ .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))), - .internalCall "getRewardAccrued" - [ .var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier" ] "accrued", - .letDecl "owed" (some uint256) - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)), - .return [(.tupleLit [.var "token", .var "owed"])] ]) := by - simpa [getRewardOwedTransition, externalEntryGuard, nonpayable, calldataSizeGuard, - checkedExternalCallStmts, getRewardOwedConfigLocals, getRewardOwedAfterShouldLocals, - getRewardOwedAfterRescaleLocals, getRewardOwedAfterTokenLocals, - getRewardOwedBaseLocals] using - (((((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - change evalExpr? config { contract := contract, locals := getRewardOwedStore I } evm - (.env .msgData) = .ok (.bytes evm.executionEnv.calldata) - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (getRewardOwedStore I) hsize)).letStep - (evalExpr_getRewardOwed_token_of evm I (getRewardOwedFrame_comet evm I) - (getRewardOwedFrame_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_rescale_of evm I - (getRewardOwedAfterTokenLocals_comet evm I) - (getRewardOwedAfterTokenLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_shouldUpscale_of evm I - (getRewardOwedAfterRescaleLocals_comet evm I) - (getRewardOwedAfterRescaleLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_multiplier_of evm I - (getRewardOwedAfterShouldLocals_comet evm I) - (getRewardOwedAfterShouldLocals_no_rewardConfig evm I))).requireStep - (evalExpr_getRewardOwed_token_ne_zero_true_of evm (getRewardOwedSlot0Load evm I) - (getRewardOwedConfigLocals_token evm I) hnz) - exact hprefix.run hchecked - -theorem cometRewardsGetRewardOwedBodyReverts_accrueFailure - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hnz : rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evm I) ≠ ⟨0⟩) - (hguard : - evalExpr? config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (.binary .gt (.extCodeSize (.var "comet")) (.intLit 0)) = .ok (.bool true)) - (hcall : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "accrueAccount" 0 (getRewardOwedAccrueAccountArgs I) - (false, evm', out) true) : - ExecTransitionBody config contract evm (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hcheckedSmall : - ExecBlock config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued") - .reverted := by - exact checkedExternalCallVarFailure (cfg := config) (C := contract) - (evm := evm) (evm' := evm') (locals := getRewardOwedConfigLocals evm I) - (receiver := "comet") (retVar := "_accrued") (name := "accrueAccount") - (target := getRewardOwedCometTarget I) (sendVal := 0) - (args := [.var "account"]) (argVals := getRewardOwedAccrueAccountArgs I) - (out := out) (perm := true) - hguard (getRewardOwedConfigLocals_comet evm I) - (evalExprs_getRewardOwed_accrueAccountArgs_of evm I - (getRewardOwedConfigLocals_account evm I)) - hcall - have hchecked : - ExecBlock config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued" ++ - [ .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))), - .internalCall "getRewardAccrued" - [ .var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier" ] "accrued", - .letDecl "owed" (some uint256) - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)), - .return [(.tupleLit [.var "token", .var "owed"])] ]) - .reverted := by - exact execBlock_append_term hcheckedSmall (by intro f e h; cases h) - have hprefix : - ABlock config evm { contract := contract, locals := getRewardOwedStore I } - getRewardOwedTransition.body - { contract := contract, locals := getRewardOwedConfigLocals evm I } - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued" ++ - [ .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))), - .internalCall "getRewardAccrued" - [ .var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier" ] "accrued", - .letDecl "owed" (some uint256) - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)), - .return [(.tupleLit [.var "token", .var "owed"])] ]) := by - simpa [getRewardOwedTransition, externalEntryGuard, nonpayable, calldataSizeGuard, - checkedExternalCallStmts, getRewardOwedConfigLocals, getRewardOwedAfterShouldLocals, - getRewardOwedAfterRescaleLocals, getRewardOwedAfterTokenLocals, - getRewardOwedBaseLocals] using - (((((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - change evalExpr? config { contract := contract, locals := getRewardOwedStore I } evm - (.env .msgData) = .ok (.bytes evm.executionEnv.calldata) - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (getRewardOwedStore I) hsize)).letStep - (evalExpr_getRewardOwed_token_of evm I (getRewardOwedFrame_comet evm I) - (getRewardOwedFrame_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_rescale_of evm I - (getRewardOwedAfterTokenLocals_comet evm I) - (getRewardOwedAfterTokenLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_shouldUpscale_of evm I - (getRewardOwedAfterRescaleLocals_comet evm I) - (getRewardOwedAfterRescaleLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_multiplier_of evm I - (getRewardOwedAfterShouldLocals_comet evm I) - (getRewardOwedAfterShouldLocals_no_rewardConfig evm I))).requireStep - (evalExpr_getRewardOwed_token_ne_zero_true_of evm (getRewardOwedSlot0Load evm I) - (getRewardOwedConfigLocals_token evm I) hnz) - exact hprefix.run hchecked - -theorem cometRewardsGetRewardOwedBodyReverts_getRewardAccrued - (evm evmAcc : EVM.State) (I : ExecutionEnv) {accrueOut : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hnz : rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evm I) ≠ ⟨0⟩) - (hguard : - evalExpr? config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (.binary .gt (.extCodeSize (.var "comet")) (.intLit 0)) = .ok (.bool true)) - (hcallAccrue : - typedCallViaEVM config evm (EVM.address (getRewardOwedCometTarget I)) - "accrueAccount" 0 (getRewardOwedAccrueAccountArgs I) - (true, evmAcc, accrueOut) true) - (hdecAccrue : config.externalABI.decode? "accrueAccount" accrueOut = some []) - (hinner : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I) } - evmAcc getRewardAccruedFunction.body .reverted) : - ExecTransitionBody config contract evm (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hcheckedSmall : - ExecBlock config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued") - (.ok { contract := contract, locals := getRewardOwedAfterAccrueLocals evm I } - evmAcc) := by - simpa [checkedExternalCallStmts, getRewardOwedAfterAccrueLocals, collapseReturns] - using checkedExternalCallVarSuccess (cfg := config) (C := contract) - (evm := evm) (evm' := evmAcc) (locals := getRewardOwedConfigLocals evm I) - (receiver := "comet") (retVar := "_accrued") (name := "accrueAccount") - (target := getRewardOwedCometTarget I) (sendVal := 0) - (args := [.var "account"]) (argVals := getRewardOwedAccrueAccountArgs I) - (out := accrueOut) (perm := true) (value := []) - hguard (getRewardOwedConfigLocals_comet evm I) - (evalExprs_getRewardOwed_accrueAccountArgs_of evm I - (getRewardOwedConfigLocals_account evm I)) - hcallAccrue hdecAccrue - have hrest : - ExecBlock config { contract := contract, locals := getRewardOwedAfterAccrueLocals evm I } - evmAcc - [ .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))), - .internalCall "getRewardAccrued" - [ .var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier" ] "accrued", - .letDecl "owed" (some uint256) - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)), - .return [(.tupleLit [.var "token", .var "owed"])] ] - .reverted := by - refine ExecBlock.consNormal - (solm' := { contract := contract, locals := getRewardOwedAfterClaimedLocals evm evmAcc I }) - (evm' := evmAcc) ?hclaimed ?_ - · exact ExecStmt.letDecl (evalExpr_getRewardOwed_claimed_afterAccrue evm evmAcc I) - refine ExecBlock.consRevert ?_ - exact internalCallFunctionRevert - (cfg := config) - (caller := { contract := contract, locals := getRewardOwedAfterClaimedLocals evm evmAcc I }) - (evm := evmAcc) - (name := "getRewardAccrued") (retVar := "accrued") - (args := [.var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier"]) - (argVals := getRewardAccruedArgs I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (callee := getRewardAccruedFunction) - (locals := getRewardAccruedStore I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - (evalExprs_getRewardOwed_getRewardAccruedArgs_afterClaimed evm evmAcc I) - lookupCallable_getRewardAccrued - (bindParams_getRewardAccrued I (getRewardOwedSlot0Load evm I) - (getRewardOwedMultiplierLoad evm I)) - hinner - have hchecked : - ExecBlock config { contract := contract, locals := getRewardOwedConfigLocals evm I } evm - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued" ++ - [ .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))), - .internalCall "getRewardAccrued" - [ .var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier" ] "accrued", - .letDecl "owed" (some uint256) - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)), - .return [(.tupleLit [.var "token", .var "owed"])] ]) - .reverted := by - exact execBlock_append hcheckedSmall hrest - have hprefix : - ABlock config evm { contract := contract, locals := getRewardOwedStore I } - getRewardOwedTransition.body - { contract := contract, locals := getRewardOwedConfigLocals evm I } - (checkedExternalCallStmts (.var "comet") "accrueAccount" (.intLit 0) - [.var "account"] "_accrued" ++ - [ .letDecl "claimed" (some uint256) - (.storage (rewardsClaimedRef (.var "comet") (.var "account"))), - .internalCall "getRewardAccrued" - [ .var "comet", .var "account", .var "rescaleFactor", - .var "shouldUpscale", .var "multiplier" ] "accrued", - .letDecl "owed" (some uint256) - (.ite (.binary .gt (.var "accrued") (.var "claimed")) - (.binary .sub (.var "accrued") (.var "claimed")) - (.intLit 0)), - .return [(.tupleLit [.var "token", .var "owed"])] ]) := by - simpa [getRewardOwedTransition, externalEntryGuard, nonpayable, calldataSizeGuard, - checkedExternalCallStmts, getRewardOwedConfigLocals, getRewardOwedAfterShouldLocals, - getRewardOwedAfterRescaleLocals, getRewardOwedAfterTokenLocals, - getRewardOwedBaseLocals] using - (((((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - change evalExpr? config { contract := contract, locals := getRewardOwedStore I } evm - (.env .msgData) = .ok (.bytes evm.executionEnv.calldata) - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (getRewardOwedStore I) hsize)).letStep - (evalExpr_getRewardOwed_token_of evm I (getRewardOwedFrame_comet evm I) - (getRewardOwedFrame_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_rescale_of evm I - (getRewardOwedAfterTokenLocals_comet evm I) - (getRewardOwedAfterTokenLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_shouldUpscale_of evm I - (getRewardOwedAfterRescaleLocals_comet evm I) - (getRewardOwedAfterRescaleLocals_no_rewardConfig evm I))).letStep - (evalExpr_getRewardOwed_multiplier_of evm I - (getRewardOwedAfterShouldLocals_comet evm I) - (getRewardOwedAfterShouldLocals_no_rewardConfig evm I))).requireStep - (evalExpr_getRewardOwed_token_ne_zero_true_of evm (getRewardOwedSlot0Load evm I) - (getRewardOwedConfigLocals_token evm I) hnz) - exact hprefix.run hchecked - -set_option maxHeartbeats 10000000 in -/-- `getRewardOwed(address,address)` body, reached at pc 2266. -/ -theorem cometRewardsGetRewardOwedBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hsel : selIs I (cometRewardsSelBytes 3)) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) getRewardOwedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have _hperm : I.perm = true := hperm - have hsz4 := cometRewardsGetRewardOwedSelector_size hsel - have hd := cometRewardsDispatch_getRewardOwed (cd := I.calldata) hsel - by_cases hsz68 : 68 ≤ I.calldata.size - · by_cases hhi : I.calldata.size < 2 ^ 255 + 4 - · by_cases hcanonComet : (getRewardOwedCometWord I).toNat < EVM.addressModulus - · by_cases hcanonAccount : (getRewardOwedAccountWord I).toNat < EVM.addressModulus - · have hdec := - cometRewardsDecode_getRewardOwed_ok (I := I) hsz68 hhi hcanonComet - hcanonAccount - have hslotWord : - getRewardOwedRewardConfigSlot0Word σ_evm I = - getRewardOwedRewardConfigSlot0Word σ_solm I := - accountMapEquiv_storage_findD hAccounts I.codeOwner - (getRewardOwedRewardConfigSlotOf I) ⟨0⟩ - have hmulWord : - getRewardOwedMultiplierWord σ_evm I = - getRewardOwedMultiplierWord σ_solm I := by - simpa [getRewardOwedMultiplierWord] using - accountMapEquiv_storage_findD hAccounts I.codeOwner - (getRewardOwedRewardConfigSlotOf I + (⟨1⟩ : UInt256)) (⟨0⟩ : UInt256) - by_cases htokenZero : - rewardConfigTokenFromSlot0 - (getRewardOwedRewardConfigSlot0Word σ_evm I) = ⟨0⟩ - · let evmSolm : EVM.State := - initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I - have htokenZeroSolm : - rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evmSolm I) = ⟨0⟩ := by - have hload : - getRewardOwedSlot0Load evmSolm I = - getRewardOwedRewardConfigSlot0Word σ_solm I := by - simp [evmSolm, getRewardOwedSlot0Load, getRewardOwedRewardConfigSlot0Word, - initState, Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - rw [hload, ← hslotWord] - exact htokenZero - have hbody : - ExecTransitionBody config contract evmSolm (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - exact cometRewardsGetRewardOwedBodyReverts_tokenZero evmSolm I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - htokenZeroSolm - exact (cometRewardsGetRewardOwedX_tokenZero (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hcanonComet hcanonAccount htokenZero hreach) - |>.reEquivExecutionRevert hcode hd hdec hbody - · let evmSolm : EVM.State := - initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I - by_cases hnoCode : - Reasoning.Theory.extCodeSizeWord σ_evm - (UInt256.land (getRewardOwedCometWord I) solcAddrMask) = ⟨0⟩ - · have htokenNZSolm : - rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evmSolm I) ≠ ⟨0⟩ := by - have hload : - getRewardOwedSlot0Load evmSolm I = - getRewardOwedRewardConfigSlot0Word σ_solm I := by - simp [evmSolm, getRewardOwedSlot0Load, getRewardOwedRewardConfigSlot0Word, - initState, Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - rw [hload, ← hslotWord] - exact htokenZero - have hnoCodeSolm : - Reasoning.Theory.extCodeSizeWord σ_solm - (UInt256.land (getRewardOwedCometWord I) solcAddrMask) = ⟨0⟩ := by - rw [← extCodeSizeWord_accountMapEquiv hAccounts - (UInt256.land (getRewardOwedCometWord I) solcAddrMask)] - exact hnoCode - have hguard : - evalExpr? config - { contract := contract, locals := getRewardOwedConfigLocals evmSolm I } evmSolm - (.binary .gt (.extCodeSize (.var "comet")) (.intLit 0)) = - .ok (.bool false) := by - exact evalExpr_getRewardOwed_extCodeSizeGuard_false evmSolm I - hcanonComet (by simpa [evmSolm, initState] using hnoCodeSolm) - have hbody : - ExecTransitionBody config contract evmSolm (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - exact cometRewardsGetRewardOwedBodyReverts_accrueNoCode evmSolm I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - htokenNZSolm hguard - exact (cometRewardsGetRewardOwedX_accrueNoCode (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hcanonComet hcanonAccount htokenZero hnoCode hreach) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have htokenNZSolm : - rewardConfigTokenFromSlot0 (getRewardOwedSlot0Load evmSolm I) ≠ ⟨0⟩ := by - have hload : - getRewardOwedSlot0Load evmSolm I = - getRewardOwedRewardConfigSlot0Word σ_solm I := by - simp [evmSolm, getRewardOwedSlot0Load, getRewardOwedRewardConfigSlot0Word, - initState, Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - rw [hload, ← hslotWord] - exact htokenZero - have hcodeSizeSolm : - Reasoning.Theory.extCodeSizeWord σ_solm - (UInt256.land (getRewardOwedCometWord I) solcAddrMask) ≠ ⟨0⟩ := by - intro hz - exact hnoCode ((extCodeSizeWord_accountMapEquiv hAccounts - (UInt256.land (getRewardOwedCometWord I) solcAddrMask)).trans hz) - have hguard : - evalExpr? config - { contract := contract, locals := getRewardOwedConfigLocals evmSolm I } evmSolm - (.binary .gt (.extCodeSize (.var "comet")) (.intLit 0)) = - .ok (.bool true) := by - exact evalExpr_getRewardOwed_extCodeSizeGuard_true evmSolm I - hcanonComet (by simpa [evmSolm, initState] using hcodeSizeSolm) - by_cases hdepth : I.depth.val < 1024 - · obtain ⟨cA', σ'_evm, σ'_solm, A'_solm, z, out, k', C', - hcallSolm, hPostAccounts, rdPost, houtSize⟩ := - cometRewardsGetRewardOwedX_call_accrueAccount_made - (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) - (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hperm hwv hsz68 hsize hhi hcanonComet hcanonAccount htokenZero - hnoCode hdepth hreach hAccounts - cases z - · have hbody : - ExecTransitionBody config contract evmSolm (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - exact cometRewardsGetRewardOwedBodyReverts_accrueFailure evmSolm - { initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } - I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - htokenNZSolm hguard hcallSolm - have hrev : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - exact cometRewardsGetRewardOwedX_after_accrueAccount_failure - (slot0 := getRewardOwedRewardConfigSlot0Word σ_evm I) - (multiplier := getRewardOwedMultiplierWord σ_evm I) - rdPost houtSize - exact hrev.reEquivExecutionRevert hcode hd hdec hbody - · let evmAcc : EVM.State := - { initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } - have hdecAccrue : - config.externalABI.decode? "accrueAccount" out = some [] := by - simp [config, compoundRewardsExternalABI, decodeVoid?] - have hclaimedWord : - getRewardOwedClaimedWord σ'_evm I = - getRewardOwedClaimedWord σ'_solm I := - accountMapEquiv_storage_findD hPostAccounts I.codeOwner - (getRewardOwedRewardsClaimedSlotOf I) ⟨0⟩ - obtain ⟨cA'', σ''_evm, σ''_solm, A''_solm, zBase, baseOut, - kBase, CBase, hcallBaseSolm, hBaseAccounts, rdBasePost, - hbaseOutSize, hbaseOutHi⟩ := - cometRewardsGetRewardOwedX_call_baseTrackingAccrued_made - (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) - (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) - (slot0 := getRewardOwedRewardConfigSlot0Word σ_evm I) - (multiplier := getRewardOwedMultiplierWord σ_evm I) - (accrueOut := out) (cA' := cA') (σ'_evm := σ'_evm) - (σ'_solm := σ'_solm) (A'_solm := A'_solm) - hcanonComet hcanonAccount hdepth hPostAccounts rdPost houtSize - let evmBase : EVM.State := - { evmAcc with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' } - cases zBase - · have hinner : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) } - evmAcc getRewardAccruedFunction.body .reverted := by - exact getRewardAccruedBodyReverts_callFailure evmAcc evmBase I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) - (by simpa [evmAcc, evmBase] using hcallBaseSolm) - have hbody : - ExecTransitionBody config contract evmSolm (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - exact cometRewardsGetRewardOwedBodyReverts_getRewardAccrued - evmSolm evmAcc I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - htokenNZSolm hguard - (by simpa [evmAcc] using hcallSolm) - hdecAccrue hinner - have hrev : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - exact cometRewardsGetRewardOwedX_after_baseTracking_failure - (slot0 := getRewardOwedRewardConfigSlot0Word σ_evm I) - (multiplier := getRewardOwedMultiplierWord σ_evm I) - rdBasePost houtSize hbaseOutSize - exact hrev.reEquivExecutionRevert hcode hd hdec hbody - · by_cases hbaseShort : baseOut.size < 32 - · have hdecBase := - cometRewardsBaseTrackingAccrued_decode_none_short - (out := baseOut) hbaseShort - have hinner : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) } - evmAcc getRewardAccruedFunction.body .reverted := by - exact getRewardAccruedBodyReverts_decode evmAcc evmBase I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) - (by simpa [evmAcc, evmBase] using hcallBaseSolm) - hdecBase - have hbody : - ExecTransitionBody config contract evmSolm (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - exact cometRewardsGetRewardOwedBodyReverts_getRewardAccrued - evmSolm evmAcc I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - htokenNZSolm hguard - (by simpa [evmAcc] using hcallSolm) - hdecAccrue hinner - have hrev : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - exact cometRewardsGetRewardOwedX_after_baseTracking_short_revert - (slot0 := getRewardOwedRewardConfigSlot0Word σ_evm I) - (multiplier := getRewardOwedMultiplierWord σ_evm I) - rdBasePost hbaseShort hbaseOutSize - exact hrev.reEquivExecutionRevert hcode hd hdec hbody - · have hbase32 : 32 ≤ baseOut.size := by omega - by_cases hbaseWord : - fromByteArrayBigEndian (baseOut.extract 0 32) < EVM.twoPow 64 - · let baseAccrued : UInt256 := getRewardOwedBaseTrackingReturnWord baseOut - let slotE : UInt256 := getRewardOwedRewardConfigSlot0Word σ_evm I - let mulE : UInt256 := getRewardOwedMultiplierWord σ_evm I - let claimedE : UInt256 := getRewardOwedClaimedWord σ'_evm I - have hbaseToNat : - baseAccrued.toNat = - fromByteArrayBigEndian (baseOut.extract 0 32) := by - simpa [baseAccrued, getRewardOwedBaseTrackingReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt hbase32) - have hbase64 : baseAccrued.toNat < EVM.twoPow 64 := by - rw [hbaseToNat] - exact hbaseWord - have hdecBase : - config.externalABI.decode? "baseTrackingAccrued" baseOut = - some [.int (Int.ofNat baseAccrued.toNat)] := by - have hdecBase0 := - cometRewardsBaseTrackingAccrued_decode_ok - (out := baseOut) hbase32 hbaseOutHi hbaseWord - simpa [hbaseToNat] using hdecBase0 - have hslotLoadSolm : - getRewardOwedSlot0Load evmSolm I = - getRewardOwedRewardConfigSlot0Word σ_solm I := by - simp [evmSolm, getRewardOwedSlot0Load, - getRewardOwedRewardConfigSlot0Word, initState, - Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - have hslotLoadEvm : - getRewardOwedSlot0Load evmSolm I = slotE := by - rw [hslotLoadSolm, ← hslotWord] - have hmulLoadSolm : - getRewardOwedMultiplierLoad evmSolm I = - getRewardOwedMultiplierWord σ_solm I := by - simp [evmSolm, getRewardOwedMultiplierLoad, - getRewardOwedMultiplierWord, initState, - Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - have hmulLoadEvm : - getRewardOwedMultiplierLoad evmSolm I = mulE := by - rw [hmulLoadSolm, ← hmulWord] - have hclaimedLoadSolm : - getRewardOwedClaimedLoad evmAcc I = - getRewardOwedClaimedWord σ'_solm I := by - simp [evmAcc, getRewardOwedClaimedLoad, - getRewardOwedClaimedWord, initState, - Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - have hclaimedLoadEvm : - getRewardOwedClaimedLoad evmAcc I = claimedE := by - rw [hclaimedLoadSolm, ← hclaimedWord] - obtain ⟨_, _, rd3740⟩ := - cometRewardsGetRewardOwedX_after_baseTracking_decode_ok - (slot0 := slotE) (multiplier := mulE) - rdBasePost houtSize hbase32 hbaseOutSize - (by simpa [baseAccrued] using hbase64) - by_cases hshould : - rewardConfigShouldUpscaleRawFromSlot0 slotE ≠ ⟨0⟩ - · let upNat := getRewardAccruedUpscaledNat slotE baseAccrued - let accruedNat := getRewardAccruedReturnNat mulE upNat - have hup : upNat < UInt256.size := by - simpa [upNat] using - getRewardAccruedUpscaledNat_lt_size_of_base64 - (slot0 := slotE) (accrued := baseAccrued) hbase64 - by_cases hscaled : - getRewardAccruedScaledNat mulE upNat < UInt256.size - · have hinner : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) } - evmAcc getRewardAccruedFunction.body - (.returned - (getRewardAccruedAfterAssignedScaledFrame I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) - baseAccrued - (getRewardAccruedUpscaledNat - (getRewardOwedSlot0Load evmSolm I) baseAccrued)) - evmBase - (some [.int (Int.ofNat accruedNat)])) := by - simpa [hslotLoadEvm, hmulLoadEvm, upNat, accruedNat] using - getRewardAccruedBodyReturns_upscale - evmAcc evmBase I slotE mulE baseAccrued - (by simpa [evmAcc, evmBase] using hcallBaseSolm) - hdecBase hshould hup hscaled - have hbody : - ExecTransitionBody config contract evmSolm (getRewardOwedStore I) - getRewardOwedTransition.body - (.returned - { contract := contract, - locals := getRewardOwedAfterOwedLocals evmSolm evmAcc I - accruedNat } - evmBase - (some [.tuple - [ getRewardOwedTokenValueFromSlot0 - (getRewardOwedSlot0Load evmSolm I), - .int (Int.ofNat - (getRewardOwedOwedNat evmAcc I accruedNat)) ]])) := by - simpa [hslotLoadEvm, hmulLoadEvm, upNat, accruedNat] using - cometRewardsGetRewardOwedBodyReturns_upscale - evmSolm evmAcc evmBase I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - htokenNZSolm hguard - (by simpa [evmAcc] using hcallSolm) - hdecAccrue - (by simpa [evmAcc, evmBase] using hcallBaseSolm) - hdecBase - (by simpa [hslotLoadEvm] using hshould) - (by simpa [hslotLoadEvm, upNat] using hup) - (by simpa [hslotLoadEvm, hmulLoadEvm, upNat] using hscaled) - obtain ⟨_, _, rd2499⟩ := - cometRewardsGetRewardOwedX_getRewardAccrued_upscale_success - (slot0 := slotE) (multiplier := mulE) - rd3740 houtSize hbase32 hbaseOutSize - (by simpa [baseAccrued] using hbase64) - hshould hscaled - have hret := - cometRewardsGetRewardOwedX_return_from2499 - (slot0 := slotE) (multiplier := mulE) - rd2499 houtSize hbase32 hbaseOutSize - have haccruedNatLt : accruedNat < UInt256.size := by - dsimp [accruedNat, getRewardAccruedReturnNat] - exact lt_of_le_of_lt (Nat.div_le_self _ _) hscaled - have hOwedNatLt : - getRewardOwedOwedNat evmAcc I accruedNat < UInt256.size := by - simpa [getRewardOwedOwedNat, hclaimedLoadEvm] using - getRewardOwedOwedNat_lt claimedE haccruedNatLt - have hOwedWord : - getRewardOwedReturnOwedWord claimedE (UInt256.ofNat accruedNat) = - UInt256.ofNat (getRewardOwedOwedNat evmAcc I accruedNat) := by - rw [getRewardOwedReturnOwedWord_of_ofNat claimedE haccruedNatLt] - simp [getRewardOwedOwedNat, hclaimedLoadEvm] - exact hret.reEquivExecutionGenAccountMapEquiv - hcode hd hdec hbody rfl hBaseAccounts - (returnEquiv.returned rfl (by - have henc := - getRewardOwedEncodeReturnValue_tuple - (getRewardOwedSlot0Load evmSolm I) - (UInt256.ofNat (getRewardOwedOwedNat evmAcc I accruedNat)) - rw [UInt256.toNat_ofNat_of_lt hOwedNatLt] at henc - simpa [getRewardOwedTransition, hslotLoadEvm, slotE, claimedE, - baseAccrued, upNat, accruedNat, hOwedWord] using henc)) - · have hinner : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) } - evmAcc getRewardAccruedFunction.body .reverted := by - exact getRewardAccruedBodyReverts_upscale_scaledOverflow - evmAcc evmBase I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) - baseAccrued - (by simpa [evmAcc, evmBase] using hcallBaseSolm) - hdecBase - (by simpa [hslotLoadEvm] using hshould) - (by simpa [hslotLoadEvm, upNat] using hup) - (by - rw [hslotLoadEvm, hmulLoadEvm] - simpa [upNat] using Nat.le_of_not_gt hscaled) - have hbody : - ExecTransitionBody config contract evmSolm (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - exact cometRewardsGetRewardOwedBodyReverts_getRewardAccrued - evmSolm evmAcc I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - htokenNZSolm hguard - (by simpa [evmAcc] using hcallSolm) - hdecAccrue hinner - have hrev : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - exact - cometRewardsGetRewardOwedX_getRewardAccrued_upscale_overflow_revert - (slot0 := slotE) (multiplier := mulE) - rd3740 houtSize hbase32 hbaseOutSize - (by simpa [baseAccrued] using hbase64) - hshould (Nat.le_of_not_gt hscaled) - exact hrev.reEquivExecutionRevert hcode hd hdec hbody - · have hshouldZero : - rewardConfigShouldUpscaleRawFromSlot0 slotE = ⟨0⟩ := by - by_contra hz - exact hshould hz - by_cases hrescaleZero : - rewardConfigRescaleFromSlot0 slotE = ⟨0⟩ - · have hinner : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) } - evmAcc getRewardAccruedFunction.body .reverted := by - exact getRewardAccruedBodyReverts_downscale_zero - evmAcc evmBase I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) - baseAccrued - (by simpa [evmAcc, evmBase] using hcallBaseSolm) - hdecBase - (by simpa [hslotLoadEvm] using hshouldZero) - (by simpa [hslotLoadEvm] using hrescaleZero) - have hbody : - ExecTransitionBody config contract evmSolm (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - exact cometRewardsGetRewardOwedBodyReverts_getRewardAccrued - evmSolm evmAcc I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - htokenNZSolm hguard - (by simpa [evmAcc] using hcallSolm) - hdecAccrue hinner - have hrev : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - exact - cometRewardsGetRewardOwedX_getRewardAccrued_downscale_zero_revert - (slot0 := slotE) (multiplier := mulE) - rd3740 houtSize hbase32 hbaseOutSize - (by simpa [baseAccrued] using hbase64) - hshouldZero hrescaleZero - exact hrev.reEquivExecutionRevert hcode hd hdec hbody - · let downNat := getRewardAccruedDownscaledNat slotE baseAccrued - let accruedNat := getRewardAccruedReturnNat mulE downNat - by_cases hscaled : - getRewardAccruedScaledNat mulE downNat < UInt256.size - · have hinner : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) } - evmAcc getRewardAccruedFunction.body - (.returned - (getRewardAccruedAfterAssignedScaledFrame I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) - baseAccrued - (getRewardAccruedDownscaledNat - (getRewardOwedSlot0Load evmSolm I) baseAccrued)) - evmBase - (some [.int (Int.ofNat accruedNat)])) := by - simpa [hslotLoadEvm, hmulLoadEvm, downNat, accruedNat] using - getRewardAccruedBodyReturns_downscale - evmAcc evmBase I slotE mulE baseAccrued - (by simpa [evmAcc, evmBase] using hcallBaseSolm) - hdecBase hshouldZero hrescaleZero hscaled - have hbody : - ExecTransitionBody config contract evmSolm - (getRewardOwedStore I) getRewardOwedTransition.body - (.returned - { contract := contract, - locals := getRewardOwedAfterOwedLocals evmSolm evmAcc I - accruedNat } - evmBase - (some [.tuple - [ getRewardOwedTokenValueFromSlot0 - (getRewardOwedSlot0Load evmSolm I), - .int (Int.ofNat - (getRewardOwedOwedNat evmAcc I accruedNat)) ]])) := by - simpa [hslotLoadEvm, hmulLoadEvm, downNat, accruedNat] using - cometRewardsGetRewardOwedBodyReturns_downscale - evmSolm evmAcc evmBase I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - htokenNZSolm hguard - (by simpa [evmAcc] using hcallSolm) - hdecAccrue - (by simpa [evmAcc, evmBase] using hcallBaseSolm) - hdecBase - (by simpa [hslotLoadEvm] using hshouldZero) - (by simpa [hslotLoadEvm] using hrescaleZero) - (by simpa [hslotLoadEvm, hmulLoadEvm, downNat] using hscaled) - obtain ⟨_, _, rd2499⟩ := - cometRewardsGetRewardOwedX_getRewardAccrued_downscale_success - (slot0 := slotE) (multiplier := mulE) - rd3740 houtSize hbase32 hbaseOutSize - (by simpa [baseAccrued] using hbase64) - hshouldZero hrescaleZero hscaled - have hret := - cometRewardsGetRewardOwedX_return_from2499 - (slot0 := slotE) (multiplier := mulE) - rd2499 houtSize hbase32 hbaseOutSize - have haccruedNatLt : accruedNat < UInt256.size := by - dsimp [accruedNat, getRewardAccruedReturnNat] - exact lt_of_le_of_lt (Nat.div_le_self _ _) hscaled - have hOwedNatLt : - getRewardOwedOwedNat evmAcc I accruedNat < UInt256.size := by - simpa [getRewardOwedOwedNat, hclaimedLoadEvm] using - getRewardOwedOwedNat_lt claimedE haccruedNatLt - have hOwedWord : - getRewardOwedReturnOwedWord claimedE - (UInt256.ofNat accruedNat) = - UInt256.ofNat - (getRewardOwedOwedNat evmAcc I accruedNat) := by - rw [getRewardOwedReturnOwedWord_of_ofNat claimedE haccruedNatLt] - simp [getRewardOwedOwedNat, hclaimedLoadEvm] - exact hret.reEquivExecutionGenAccountMapEquiv - hcode hd hdec hbody rfl hBaseAccounts - (returnEquiv.returned rfl (by - have henc := - getRewardOwedEncodeReturnValue_tuple - (getRewardOwedSlot0Load evmSolm I) - (UInt256.ofNat (getRewardOwedOwedNat evmAcc I accruedNat)) - rw [UInt256.toNat_ofNat_of_lt hOwedNatLt] at henc - simpa [getRewardOwedTransition, hslotLoadEvm, slotE, claimedE, - baseAccrued, downNat, accruedNat, hOwedWord] using henc)) - · have hinner : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) } - evmAcc getRewardAccruedFunction.body .reverted := by - exact getRewardAccruedBodyReverts_downscale_scaledOverflow - evmAcc evmBase I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) - baseAccrued - (by simpa [evmAcc, evmBase] using hcallBaseSolm) - hdecBase - (by simpa [hslotLoadEvm] using hshouldZero) - (by simpa [hslotLoadEvm] using hrescaleZero) - (by - rw [hslotLoadEvm, hmulLoadEvm] - simpa [downNat] using Nat.le_of_not_gt hscaled) - have hbody : - ExecTransitionBody config contract evmSolm - (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - exact cometRewardsGetRewardOwedBodyReverts_getRewardAccrued - evmSolm evmAcc I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - htokenNZSolm hguard - (by simpa [evmAcc] using hcallSolm) - hdecAccrue hinner - have hrev : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - exact - cometRewardsGetRewardOwedX_getRewardAccrued_downscale_overflow_revert - (slot0 := slotE) (multiplier := mulE) - rd3740 houtSize hbase32 hbaseOutSize - (by simpa [baseAccrued] using hbase64) - hshouldZero hrescaleZero (Nat.le_of_not_gt hscaled) - exact hrev.reEquivExecutionRevert hcode hd hdec hbody - · have hdecBase := - cometRewardsBaseTrackingAccrued_decode_none_noncanon - (out := baseOut) hbase32 hbaseOutHi hbaseWord - have hinner : - ExecFuncBody config - { contract := contract, - locals := getRewardAccruedStore I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) } - evmAcc getRewardAccruedFunction.body .reverted := by - exact getRewardAccruedBodyReverts_decode evmAcc evmBase I - (getRewardOwedSlot0Load evmSolm I) - (getRewardOwedMultiplierLoad evmSolm I) - (by simpa [evmAcc, evmBase] using hcallBaseSolm) - hdecBase - have hbody : - ExecTransitionBody config contract evmSolm (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - exact cometRewardsGetRewardOwedBodyReverts_getRewardAccrued - evmSolm evmAcc I - (by simp only [evmSolm, initState]; exact hwv) - (by simp only [evmSolm, initState]; exact hhi) - htokenNZSolm hguard - (by simpa [evmAcc] using hcallSolm) - hdecAccrue hinner - have hbaseNo : - ¬ (getRewardOwedBaseTrackingReturnWord baseOut).toNat < - EVM.twoPow 64 := by - intro hlt - have hto : - (getRewardOwedBaseTrackingReturnWord baseOut).toNat = - fromByteArrayBigEndian (baseOut.extract 0 32) := by - simpa [getRewardOwedBaseTrackingReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt hbase32) - exact hbaseWord (by rw [← hto]; exact hlt) - have hrev : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - exact - cometRewardsGetRewardOwedX_after_baseTracking_noncanon_revert - (slot0 := getRewardOwedRewardConfigSlot0Word σ_evm I) - (multiplier := getRewardOwedMultiplierWord σ_evm I) - rdBasePost houtSize hbase32 hbaseOutSize hbaseNo - exact hrev.reEquivExecutionRevert hcode hd hdec hbody - · have hdepth1024 : I.depth = 1024 := - Fin.ext (by - have hlt := I.depth.isLt - have hge : 1024 ≤ I.depth.val := Nat.le_of_not_gt hdepth - omega) - let evmInit : EVM.State := - initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I - let evmFail : EVM.State := - { evmInit with - substate := - (evmInit.addAccessedAccount - (EVM.address (getRewardOwedCometTarget I))).substate } - have hcallS : - typedCallViaEVM config evmInit - (EVM.address (getRewardOwedCometTarget I)) "accrueAccount" 0 - (getRewardOwedAccrueAccountArgs I) - (false, evmFail, ByteArray.empty) true := by - exact callNotMade_depthLimit - (cfg := config) (evm := evmInit) - (tgt := EVM.address (getRewardOwedCometTarget I)) - (name := "accrueAccount") (args := getRewardOwedAccrueAccountArgs I) - (calldata := - (getRewardOwedAccrueAccountCalldataMem I - (getRewardOwedRewardConfigSlot0Word σ_solm I) - (getRewardOwedMultiplierWord σ_solm I)).readWithPadding - 320 getRewardOwedAccrueAccountCallSize.toNat) - (callPerm := true) - (getRewardOwedAccrueAccountCalldataMem_encode_args I - (getRewardOwedRewardConfigSlot0Word σ_solm I) - (getRewardOwedMultiplierWord σ_solm I) hcanonAccount) - (by simpa [evmInit, initState] using hdepth1024) - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (getRewardOwedStore I) - getRewardOwedTransition.body .reverted := by - exact cometRewardsGetRewardOwedBodyReverts_accrueFailure - evmInit evmFail I - (by simp only [evmInit, initState]; exact hwv) - (by simp only [evmInit, evmSolm]; exact hhi) - (by simpa [evmInit, evmSolm] using htokenNZSolm) - (by simpa [evmInit, evmSolm] using hguard) - hcallS - exact (cometRewardsGetRewardOwedX_callDepthLimit - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hcanonAccount htokenZero hnoCode - hreach hdepth1024) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have hdec := cometRewardsDecode_getRewardOwed_none_noncanon_account - (I := I) hsz68 hhi hcanonComet hcanonAccount - have hnc : UInt256.eq (getRewardOwedAccountWord I) - (UInt256.land (getRewardOwedAccountWord I) solcAddrMask) = ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanonAccount (solcAddrCanonical_of_clean he)) - exact (cometRewardsGetRewardOwedX_noncanon_account (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hcanonComet hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hdec := cometRewardsDecode_getRewardOwed_none_noncanon_comet - (I := I) hsz68 hhi hcanonComet - have hnc : UInt256.eq (getRewardOwedCometWord I) - (UInt256.land (getRewardOwedCometWord I) solcAddrMask) = ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanonComet (solcAddrCanonical_of_clean he)) - exact (cometRewardsGetRewardOwedX_noncanon_comet (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hbig : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - have hdec := cometRewardsDecode_getRewardOwed_none_huge (I := I) hbig - exact (cometRewardsGetRewardOwedX_hugearg (g := Sat256.ofUInt256 g) - hwv hsize hbig hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hshort : I.calldata.size < 68 := by omega - have hdec := cometRewardsDecode_getRewardOwed_none_short (I := I) hsz4 hshort - exact (cometRewardsGetRewardOwedX_shortarg (g := Sat256.ofUInt256 g) - hwv hsz4 hsize hshort hreach) - |>.reEquivDecodingFailed hcode hd hdec - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/Governor.lean b/Benchmarks/CompoundIII/CometRewards/Governor.lean deleted file mode 100644 index 893e248a..00000000 --- a/Benchmarks/CompoundIII/CometRewards/Governor.lean +++ /dev/null @@ -1,238 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.Common - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace Benchmarks.CompoundIII.CometRewards - -/-! ## `governor()` getter -/ - -def governorWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - σ.find? I.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD ⟨0⟩ ⟨0⟩) - -abbrev governorReturnWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (governorWord σ I) solcAddrMask - -abbrev calldataFrame (evm : EVM.State) (locals : Store) : Frame := - Frame.mk contract (locals.insert "__calldata" (.bytes evm.executionEnv.calldata)) - -theorem cometRewardsGovernorBodyReturns (evm : EVM.State) (locals : Store) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hlocals : locals.get? "governor" = none) : - ExecTransitionBody config contract evm locals governorTransition.body - (.returned (calldataFrame evm locals) evm - (some [(.address (AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat))])) := by - refine ExecFuncBody.execBlockRet ?_ - simpa [governorTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm locals hsize)).returns (by - have her : evalStorageRef config - (calldataFrame evm locals) - evm governorRef = .ok { base := "governor", steps := [] } := by - simp [evalStorageRef, evalStorageRefSteps, governorRef, EvalResult.bind, pure, bind] - have hty : storageTypeAt? contract.storage - ({ base := "governor", steps := [] } : EvaledStorageRef) = some (.elem .address) := by - decide - rw [evalExpr_storage_scalar (t := .address) - (hbase := by - change (locals.insert "__calldata" (.bytes evm.executionEnv.calldata)).get? - "governor" = none - rw [store_get_ne locals (k := "__calldata") (a := "governor") - (.bytes evm.executionEnv.calldata) (by decide)] - exact hlocals) - (her := her) - (hty := hty) (hloc := by rfl), cometRewardsStorageLocLoad_address_offset0]) - -theorem cometRewardsGovernorBodyRevertsHuge (evm : EVM.State) (locals : Store) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hbig : 2 ^ 255 + 4 ≤ evm.executionEnv.calldata.size) : - ExecTransitionBody config contract evm locals governorTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [governorTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireRevert - (cometRewardsCalldataGuard_false evm locals hbig)) - -theorem cometRewardsGovernorSelector_size {I : ExecutionEnv} - (hsel : selIs I (cometRewardsSelBytes 1)) : - 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (cometRewardsSelBytes 1) rfl hsel - -theorem cometRewardsDispatch_governor {cd : ByteArray} - (hsel : (cometRewardsSelBytes 1 == cd.extract 0 4) = true) : - dispatchMsg contract cd = some governorTransition := by - have hcd : cd.extract 0 4 = cometRewardsSelBytes 1 := - (byteArray_eq_of_beq hsel).symm - refine dispatchMsg_eq_some_of_split - (pre := [claimTransition, claimToTransition, getRewardOwedTransition]) - (post := [rewardConfigTransition, rewardsClaimedTransition, setRewardConfigTransition, - setRewardConfigWithMultiplierTransition, setRewardsClaimedTransition, - transferGovernorTransition, withdrawTokenTransition]) - rfl rfl ?_ (by rw [selectorOf, governorSelectorBytes]; exact hsel) - intro t ht - simp only [List.mem_cons, List.not_mem_nil, or_false] at ht - rcases ht with rfl | rfl | rfl - · rw [selectorOf, claimSelectorBytes, hcd] - decide - · rw [selectorOf, claimToSelectorBytes, hcd] - decide - · rw [selectorOf, getRewardOwedSelectorBytes, hcd] - decide - -theorem cometRewardsDecode_governor {I : ExecutionEnv} (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (governorTransition.params.map Param.name) - (transitionSignature governorTransition).paramTypes I.calldata = some ∅ := by - show decodeCalldataWithMode config.abiDecodeMode [] [] I.calldata = some ∅ - exact decodeCalldataWithMode_empty_ok hsz - -theorem cometRewardsGovernorCalldataCheckOk {I : ExecutionEnv} - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hhi : I.calldata.size < 2 ^ 255 + 4) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨0⟩ = ⟨0⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨0⟩ = ⟨0⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 hsz hsize] - simpa using - solcCalldataStaticLenCheckOk (sz := I.calldata.size) (words := 0) - (by omega) hhi hsize - -theorem cometRewardsGovernorCalldataCheckHuge {I : ExecutionEnv} - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨0⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨0⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 hsz hsize] - simpa using - solcCalldataStaticLenCheckHuge (sz := I.calldata.size) (words := 0) - hbig hsize (by norm_num) - -theorem cometRewardsX_governor {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) - (hhi : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) governorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (governorReturnWord σ I)) := by - have hslt := cometRewardsGovernorCalldataCheckOk (I := I) hsz hsize hhi - obtain ⟨_, _, rd2717⟩ := hreach - have rd2726 := evm_run rd2717 with [ - jumpdest, pop, pop, pop, callvalue] - rw [hwv] at rd2726 - have rd2732 := evm_run rd2726 with [ - push2 ⟨670⟩, jumpiNT (by decide), - dup2, push1 ⟨3⟩, not, calldatasize, add, slt] - rw [hslt] at rd2732 - have rd2738 := evm_run rd2732 with [ - push2 ⟨670⟩, jumpiNT (by decide), swap1] - obtain ⟨_, _, rd2739⟩ := rd2738.sload (by decide) (by evm_ov) - have rd2754 := evm_run rd2739 with [ - swap1, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, swap1, swap2, and, dup2, - raw mstore 6 (solcReturnMem (governorReturnWord σ I)) (UInt256.ofNat 5) - (by decide) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - rfl) - (by decide) (by evm_ov), - push1 ⟨32⟩, swap1] - exact evm_run rd2754 with [ - raw ret 0 (UInt256.toByteArray (governorReturnWord σ I)) (by decide) - mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - show (⟨32⟩ : UInt256).toNat = 32 from by decide] - exact solcReturnMem_read128 (governorReturnWord σ I)) - (by evm_ov)] - -theorem cometRewardsX_governor_huge {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) governorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsGovernorCalldataCheckHuge (I := I) hsz hsize hbig - obtain ⟨_, _, rd2717⟩ := hreach - have rd2726 := evm_run rd2717 with [ - jumpdest, pop, pop, pop, callvalue] - rw [hwv] at rd2726 - have rd2732 := evm_run rd2726 with [ - push2 ⟨670⟩, jumpiNT (by decide), - dup2, push1 ⟨3⟩, not, calldatasize, add, slt] - rw [hslt] at rd2732 - exact evm_run rd2732 with [ - push2 ⟨670⟩, jumpiT (by decide) (by native_decide), - jumpdest, pop, dup1, - raw rev 0 (by decide) mem_cost (by evm_ov)] - -/-- `governor()` body, reached at pc 2717. -/ -theorem cometRewardsGovernorBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hsel : selIs I (cometRewardsSelBytes 1)) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) governorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have _hperm : I.perm = true := hperm - have hsz := cometRewardsGovernorSelector_size hsel - have hd := cometRewardsDispatch_governor (cd := I.calldata) hsel - have hdec := cometRewardsDecode_governor (I := I) hsz - by_cases hhi : I.calldata.size < 2 ^ 255 + 4 - · have hword : governorWord σ_evm I = governorWord σ_solm I := - accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ ⟨0⟩ - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) ∅ - governorTransition.body - (.returned - (calldataFrame (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) ∅) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (some [(.address (AccountAddress.ofNat (governorReturnWord σ_solm I).toNat))])) := by - simpa [governorWord, governorReturnWord, initState, Solm.EVM.storageLoad, - State.lookupAccount] using - cometRewardsGovernorBodyReturns - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) ∅ - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - (by simp) - exact (cometRewardsX_governor (g := Sat256.ofUInt256 g) hwv hsz hsize hhi hreach) - |>.reEquivExecutionTransport hcode hd hdec hbody - (by simp [governorReturnWord, hword]) hAccounts - (returnEquiv_of_encode - (solcAddressReturnEncoding (addrTy := addr) rfl (governorWord σ_evm I))) - · have hbig : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) ∅ - governorTransition.body .reverted := by - exact cometRewardsGovernorBodyRevertsHuge - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) ∅ - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hbig) - exact (cometRewardsX_governor_huge (g := Sat256.ofUInt256 g) hwv hsz hsize hbig hreach) - |>.reEquivExecutionRevert hcode hd hdec hbody - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/RewardConfig.lean b/Benchmarks/CompoundIII/CometRewards/RewardConfig.lean deleted file mode 100644 index 077274a3..00000000 --- a/Benchmarks/CompoundIII/CometRewards/RewardConfig.lean +++ /dev/null @@ -1,1042 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.Common -import Reasoning.MemCascade - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 10000000 - -namespace Benchmarks.CompoundIII.CometRewards - -/-! ## `rewardConfig(address)` public mapping getter -/ - -abbrev rewardConfigArgWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -abbrev rewardConfigArgValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (rewardConfigArgWord I).toNat) - -abbrev rewardConfigStore (I : ExecutionEnv) : Store := - (∅ : Store).insert "arg0" (rewardConfigArgValue I) - -def rewardConfigSlotOf (I : ExecutionEnv) : UInt256 := - rewardConfigSlot (.address (AccountAddress.ofNat (rewardConfigArgWord I).toNat)) - -def rewardConfigSlot0Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - σ.find? I.codeOwner |>.option ⟨0⟩ - (fun acc => acc.storage.findD (rewardConfigSlotOf I) ⟨0⟩) - -def rewardConfigMultiplierWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - σ.find? I.codeOwner |>.option ⟨0⟩ - (fun acc => acc.storage.findD (rewardConfigSlotOf I + ⟨1⟩) ⟨0⟩) - -abbrev rewardConfigTokenWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (rewardConfigSlot0Word σ I) solcAddrMask - -abbrev rewardConfigRescaleWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.shiftRight (rewardConfigSlot0Word σ I) ⟨160⟩) - (UInt256.ofNat (2 ^ 64 - 1)) - -abbrev rewardConfigShouldUpscaleRawWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.shiftRight (rewardConfigSlot0Word σ I) ⟨224⟩) ⟨255⟩ - -abbrev rewardConfigShouldUpscaleWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.isZero (UInt256.isZero (rewardConfigShouldUpscaleRawWord σ I)) - -abbrev rewardConfigTokenFromSlot0 (slot0 : UInt256) : UInt256 := - UInt256.land slot0 solcAddrMask - -abbrev rewardConfigRescaleFromSlot0 (slot0 : UInt256) : UInt256 := - UInt256.land (UInt256.shiftRight slot0 ⟨160⟩) (UInt256.ofNat (2 ^ 64 - 1)) - -abbrev rewardConfigShouldUpscaleRawFromSlot0 (slot0 : UInt256) : UInt256 := - UInt256.land (UInt256.shiftRight slot0 ⟨224⟩) ⟨255⟩ - -abbrev rewardConfigShouldUpscaleFromSlot0 (slot0 : UInt256) : UInt256 := - UInt256.isZero (UInt256.isZero (rewardConfigShouldUpscaleRawFromSlot0 slot0)) - -def rewardConfigReturnValues (slot0 multiplier : UInt256) : List Value := - [ .address (AccountAddress.ofNat (rewardConfigTokenFromSlot0 slot0).toNat), - .int (↑(rewardConfigRescaleFromSlot0 slot0).toNat), - wordToElem .bool (rewardConfigShouldUpscaleRawFromSlot0 slot0), - .int (↑multiplier.toNat) ] - -noncomputable def rewardConfigHashMem (comet : UInt256) : ByteArray := - twoWordHashMem comet ⟨1⟩ solcFreePtrMem - -def rewardConfigReturnWrites - (token rescale shouldUpscale multiplier : UInt256) : List (Nat × UInt256) := - [(128, token), (160, rescale), (192, shouldUpscale), (224, multiplier)] - -noncomputable def rewardConfigReturnMem - (comet token rescale shouldUpscale multiplier : UInt256) : ByteArray := - writeCascade (rewardConfigHashMem comet) - (rewardConfigReturnWrites token rescale shouldUpscale multiplier) - -def rewardConfigReturnBytes (token rescale shouldUpscale multiplier : UInt256) : ByteArray := - UInt256.toByteArray token ++ - (UInt256.toByteArray rescale ++ - (UInt256.toByteArray shouldUpscale ++ UInt256.toByteArray multiplier)) - -theorem rewardConfigShiftRight160_eq_div (w : UInt256) : - UInt256.shiftRight w (⟨160⟩ : UInt256) = - UInt256.div w (UInt256.ofNat (256 ^ 20)) := by - apply u256_inj - unfold UInt256.shiftRight UInt256.div UInt256.toNat - simp [Fin.shiftRight_val, Nat.shiftRight_eq_div_pow, - show 160 % UInt256.size = 160 by native_decide] - norm_num [UInt256.ofNat, Id.run] - rw [show 1461501637330902918203684832716283019655932542976 % UInt256.size = - 1461501637330902918203684832716283019655932542976 by native_decide] - -theorem rewardConfigShiftRight224_eq_div (w : UInt256) : - UInt256.shiftRight w (⟨224⟩ : UInt256) = - UInt256.div w (UInt256.ofNat (256 ^ 28)) := by - apply u256_inj - unfold UInt256.shiftRight UInt256.div UInt256.toNat - simp [Fin.shiftRight_val, Nat.shiftRight_eq_div_pow, - show 224 % UInt256.size = 224 by native_decide] - norm_num [UInt256.ofNat, Id.run] - rw [show 26959946667150639794667015087019630673637144422540572481103610249216 % - UInt256.size = - 26959946667150639794667015087019630673637144422540572481103610249216 by native_decide] - -theorem cometRewardsStorageLocLoad_uint64_offset20 (evm : EVM.State) (slot : UInt256) : - storageLocLoad evm (fieldLoc slot 20 8 (by decide) (.int uint64Int)) = - .int (Int.ofNat (UInt256.land - (UInt256.shiftRight (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) ⟨160⟩) - (UInt256.ofNat (2 ^ 64 - 1))).toNat) := by - rw [rewardConfigShiftRight160_eq_div] - simpa [fieldLoc, loc] using - @storageLocLoad_uint_offset evm slot (⟨20, by decide⟩ : Fin 32) - (⟨8, by decide⟩ : Fin 33) (⟨64, by decide⟩ : ABI.BitWidth) - (by decide) (by decide) (by decide) - -theorem cometRewardsStorageLocLoad_bool_offset28 (evm : EVM.State) (slot : UInt256) : - storageLocLoad evm (fieldLoc slot 28 1 (by decide) .bool) = - wordToElem .bool (UInt256.land - (UInt256.shiftRight (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) ⟨224⟩) - ⟨255⟩) := by - rw [rewardConfigShiftRight224_eq_div] - unfold storageLocLoad fieldLoc loc - apply congrArg (wordToElem .bool) - apply u256_inj - change fromBytes' - ((EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).1.extract 28 (28 + 1)) = _ - rw [List.extract_eq_take_drop] - simpa [Nat.add_sub_cancel_left] using - fromBytes'_drop_take_wordLE_land_div_mask - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) 28 1 - (by decide) (by decide) - -theorem rewardConfigSlotOf_eq_solc (I : ExecutionEnv) - (hcanon : (rewardConfigArgWord I).toNat < EVM.addressModulus) : - rewardConfigSlotOf I = solcMappingSlot ⟨1⟩ (rewardConfigArgWord I) := by - unfold rewardConfigSlotOf rewardConfigSlot - rw [keyValueToWord_address_of_canonical _ hcanon] - rfl - -theorem rewardConfigHashMem_size (comet : UInt256) : - (rewardConfigHashMem comet).size = 96 := by - exact twoWordHashMem_size_96 comet ⟨1⟩ solcFreePtrMem_size - -theorem rewardConfigHashMem_read64 (comet : UInt256) : - (rewardConfigHashMem comet).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - exact twoWordHashMem_read64 comet ⟨1⟩ solcFreePtrMem_size solcFreePtrMem_read64 - -theorem rewardConfigHashMem_mload64 (comet : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (rewardConfigHashMem comet).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 3 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian ((rewardConfigHashMem comet).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨128⟩ := by - exact mloadFreePtrValue (by rw [rewardConfigHashMem_size]; decide) (by decide) - (rewardConfigHashMem_read64 comet) - -theorem rewardConfigKeccakSlot (comet : UInt256) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((rewardConfigHashMem comet).readWithPadding 0 64))) = - solcMappingSlot ⟨1⟩ comet := by - rw [rewardConfigHashMem, twoWordHashMem_read0_64 comet ⟨1⟩ solcFreePtrMem_size] - unfold solcMappingSlot - exact mappingSlot_single comet ⟨1⟩ - -theorem rewardConfigReturnMem_size (comet token rescale shouldUpscale multiplier : UInt256) : - (rewardConfigReturnMem comet token rescale shouldUpscale multiplier).size = 256 := by - unfold rewardConfigReturnMem rewardConfigReturnWrites - exact writeCascade_size_of_base (rewardConfigHashMem comet) - [(128, token), (160, rescale), (192, shouldUpscale), (224, multiplier)] - (rewardConfigHashMem_size comet) - (by simpa [WriteGapsOk] using (lt_usize 32 (by norm_num))) (by rfl) - -theorem rewardConfigReturnMem_readWord128 - (comet token rescale shouldUpscale multiplier : UInt256) : - (rewardConfigReturnMem comet token rescale shouldUpscale multiplier).readWithPadding 128 32 = - UInt256.toByteArray token := by - unfold rewardConfigReturnMem rewardConfigReturnWrites - exact writeCascade_read_word_of_head_of_base (rewardConfigHashMem comet) token - [(160, rescale), (192, shouldUpscale), (224, multiplier)] - (rewardConfigHashMem_size comet) (by exact lt_usize _ (by norm_num)) (by - simp [WindowDisjointFromWrites]) - -theorem rewardConfigReturnMem_readWord160 - (comet token rescale shouldUpscale multiplier : UInt256) : - (rewardConfigReturnMem comet token rescale shouldUpscale multiplier).readWithPadding 160 32 = - UInt256.toByteArray rescale := by - unfold rewardConfigReturnMem rewardConfigReturnWrites - rw [writeCascade_cons] - have hbase : (writeWord (rewardConfigHashMem comet) 128 token).size = 160 := by - rw [writeWord_size] - · rw [rewardConfigHashMem_size] - norm_num - · rw [rewardConfigHashMem_size] - native_decide - exact writeCascade_read_word_of_head_of_base - (writeWord (rewardConfigHashMem comet) 128 token) rescale - [(192, shouldUpscale), (224, multiplier)] hbase (by exact lt_usize _ (by norm_num)) (by - simp [WindowDisjointFromWrites]) - -theorem rewardConfigReturnMem_readWord192 - (comet token rescale shouldUpscale multiplier : UInt256) : - (rewardConfigReturnMem comet token rescale shouldUpscale multiplier).readWithPadding 192 32 = - UInt256.toByteArray shouldUpscale := by - unfold rewardConfigReturnMem rewardConfigReturnWrites - rw [writeCascade_cons, writeCascade_cons] - have hbase0 : (writeWord (rewardConfigHashMem comet) 128 token).size = 160 := by - rw [writeWord_size] - · rw [rewardConfigHashMem_size] - norm_num - · rw [rewardConfigHashMem_size] - native_decide - have hbase : - (writeWord (writeWord (rewardConfigHashMem comet) 128 token) 160 rescale).size = - 192 := by - rw [writeWord_size] - · rw [hbase0] - norm_num - · rw [hbase0] - native_decide - exact writeCascade_read_word_of_head_of_base - (writeWord (writeWord (rewardConfigHashMem comet) 128 token) 160 rescale) - shouldUpscale [(224, multiplier)] hbase (by exact lt_usize _ (by norm_num)) (by - simp [WindowDisjointFromWrites]) - -theorem rewardConfigReturnMem_readWord224 - (comet token rescale shouldUpscale multiplier : UInt256) : - (rewardConfigReturnMem comet token rescale shouldUpscale multiplier).readWithPadding 224 32 = - UInt256.toByteArray multiplier := by - unfold rewardConfigReturnMem rewardConfigReturnWrites - rw [writeCascade_cons, writeCascade_cons, writeCascade_cons] - have hbase0 : (writeWord (rewardConfigHashMem comet) 128 token).size = 160 := by - rw [writeWord_size] - · rw [rewardConfigHashMem_size] - norm_num - · rw [rewardConfigHashMem_size] - native_decide - have hbase1 : - (writeWord (writeWord (rewardConfigHashMem comet) 128 token) 160 rescale).size = - 192 := by - rw [writeWord_size] - · rw [hbase0] - norm_num - · rw [hbase0] - native_decide - have hbase : - (writeWord - (writeWord (writeWord (rewardConfigHashMem comet) 128 token) 160 rescale) - 192 shouldUpscale).size = 224 := by - rw [writeWord_size] - · rw [hbase1] - norm_num - · rw [hbase1] - native_decide - exact writeCascade_read_word_of_head_of_base - (writeWord - (writeWord (writeWord (rewardConfigHashMem comet) 128 token) 160 rescale) - 192 shouldUpscale) - multiplier [] hbase (by exact lt_usize _ (by norm_num)) (by - simp [WindowDisjointFromWrites]) - -theorem rewardConfigReturnMem_read128 (comet token rescale shouldUpscale multiplier : UInt256) : - (rewardConfigReturnMem comet token rescale shouldUpscale multiplier).readWithPadding 128 128 = - rewardConfigReturnBytes token rescale shouldUpscale multiplier := by - rw [byteArray_readWithPadding_split _ 128 32 96 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by - rw [rewardConfigReturnMem_size])] - rw [byteArray_readWithPadding_split _ 160 32 64 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by - rw [rewardConfigReturnMem_size])] - rw [byteArray_readWithPadding_split _ 192 32 32 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by - rw [rewardConfigReturnMem_size])] - rw [rewardConfigReturnMem_readWord128, rewardConfigReturnMem_readWord160, - rewardConfigReturnMem_readWord192, rewardConfigReturnMem_readWord224] - rfl - -theorem rewardConfigRescaleWord_lt (w : UInt256) : - (UInt256.land (UInt256.shiftRight w ⟨160⟩) - (UInt256.ofNat (2 ^ 64 - 1))).toNat < EVM.twoPow 64 := by - rw [u256_land_toNat] - have hmask : - (UInt256.ofNat (2 ^ 64 - 1)).toNat = 2 ^ 64 - 1 := by - exact ulit_toNat' _ (by norm_num [UInt256.size]) - rw [hmask] - have hle : Nat.land (UInt256.shiftRight w ⟨160⟩).toNat (2 ^ 64 - 1) ≤ 2 ^ 64 - 1 := - nat_land_le_right _ _ - have hltSize : - Nat.land (UInt256.shiftRight w ⟨160⟩).toNat (2 ^ 64 - 1) < UInt256.size := by - exact lt_of_le_of_lt hle (by norm_num [UInt256.size]) - rw [Nat.mod_eq_of_lt hltSize] - change _ < 2 ^ 64 - omega - -theorem rewardConfigEncodeABIWord_uint64 (v : UInt256) (h64 : v.toNat < EVM.twoPow 64) : - encodeABIWord? (.elem (.int uint64Int)) (.int (↑v.toNat)) = some v := by - have hword : EVM.word v.toNat = v := by - show UInt256.ofNat v.toNat = v - exact u256_ofNat_toNat v - rw [uint64Int] - simp only [encodeABIWord?, Int.ofNat_eq_natCast] - rw [if_neg (by norm_num : ¬ (64 = 0))] - rw [if_pos] - · exact congrArg some hword - · constructor - · exact Int.natCast_nonneg _ - · exact_mod_cast h64 - -theorem rewardConfigEncodeABIValue_uint64 (v : UInt256) (h64 : v.toNat < EVM.twoPow 64) : - encodeABIValue? (.elem (.int uint64Int)) (.int (↑v.toNat)) = - some (EVM.Word.toBytesBE v) := by - simp [encodeABIValue?, rewardConfigEncodeABIWord_uint64 v h64] - -theorem rewardConfigEncodeABIWord_uint256 (v : UInt256) : - encodeABIWord? (.elem (.int uint256Int)) (.int (↑v.toNat)) = some v := by - have hword : EVM.word v.toNat = v := by - show UInt256.ofNat v.toNat = v - exact u256_ofNat_toNat v - have hltNat : v.toNat < EVM.twoPow 256 := by - change v.val.val < EVM.twoPow 256 - exact v.val.isLt - rw [uint256Int] - simp only [encodeABIWord?, Int.ofNat_eq_natCast] - rw [if_neg (by norm_num : ¬ (256 = 0))] - rw [if_pos] - · exact congrArg some hword - · constructor - · exact Int.natCast_nonneg _ - · exact_mod_cast hltNat - -theorem rewardConfigEncodeABIValue_uint256 (v : UInt256) : - encodeABIValue? (.elem (.int uint256Int)) (.int (↑v.toNat)) = - some (EVM.Word.toBytesBE v) := by - simp [encodeABIValue?, rewardConfigEncodeABIWord_uint256 v] - -theorem rewardConfigEncodeABIWord_bool_word (w : UInt256) : - encodeABIWord? (.elem .bool) (wordToElem .bool w) = - some (UInt256.isZero (UInt256.isZero w)) := by - by_cases hval : w.val = 0 - · have hz : w = ⟨0⟩ := by - apply u256_inj - exact congrArg Fin.val hval - simp [encodeABIWord?, wordToElem, hz, - show UInt256.isZero (⟨0⟩ : UInt256) = ⟨1⟩ by decide, - show UInt256.isZero (⟨1⟩ : UInt256) = ⟨0⟩ by decide] - native_decide - · have hnz : w ≠ ⟨0⟩ := by - intro hz - apply hval - rw [hz] - have hiz : UInt256.isZero w = ⟨0⟩ := isZero_eq_zero_of_ne hnz - simp [encodeABIWord?, wordToElem, hval, hiz, - show UInt256.isZero (⟨0⟩ : UInt256) = ⟨1⟩ by decide] - native_decide - -theorem rewardConfigEncodeABIValue_bool_word (w : UInt256) : - encodeABIValue? (.elem .bool) (wordToElem .bool w) = - some (EVM.Word.toBytesBE (UInt256.isZero (UInt256.isZero w))) := by - simp [encodeABIValue?, rewardConfigEncodeABIWord_bool_word w] - -theorem rewardConfigEncodeABIWord_masked_address (w : UInt256) : - encodeABIWord? (.elem .address) - (.address (AccountAddress.ofNat (UInt256.land w solcAddrMask).toNat)) = - some (UInt256.land w solcAddrMask) := by - have hcanon := solcAddrMask_result_canonical w - have haddrMod : (UInt256.land w solcAddrMask).toNat % AccountAddress.size = - (UInt256.land w solcAddrMask).toNat := by - apply Nat.mod_eq_of_lt - simpa [EVM.addressModulus, EVM.twoPow, AccountAddress.size] using hcanon - have hword : EVM.word (UInt256.land w solcAddrMask).toNat = UInt256.land w solcAddrMask := - u256_ofNat_toNat _ - simp [encodeABIWord?, AccountAddress.ofNat, haddrMod, hword] - -theorem rewardConfigEncodeABIValue_masked_address (w : UInt256) : - encodeABIValue? (.elem .address) - (.address (AccountAddress.ofNat (UInt256.land w solcAddrMask).toNat)) = - some (EVM.Word.toBytesBE (UInt256.land w solcAddrMask)) := by - simp [encodeABIValue?, rewardConfigEncodeABIWord_masked_address w] - -theorem encodeReturnValues_four_static {ty0 ty1 ty2 ty3 : ABIType} - {v0 v1 v2 v3 : Value} {w0 w1 w2 w3 : UInt256} - (hhead : abiTupleHeadSize? [ty0, ty1, ty2, ty3] = some 128) - (hd0 : isDynamicABIType ty0 = false) (hd1 : isDynamicABIType ty1 = false) - (hd2 : isDynamicABIType ty2 = false) (hd3 : isDynamicABIType ty3 = false) - (h0 : encodeABIValue? ty0 v0 = some (EVM.Word.toBytesBE w0)) - (h1 : encodeABIValue? ty1 v1 = some (EVM.Word.toBytesBE w1)) - (h2 : encodeABIValue? ty2 v2 = some (EVM.Word.toBytesBE w2)) - (h3 : encodeABIValue? ty3 v3 = some (EVM.Word.toBytesBE w3)) : - encodeReturnValues? [ty0, ty1, ty2, ty3] [v0, v1, v2, v3] = - some (UInt256.toByteArray w0 ++ - (UInt256.toByteArray w1 ++ (UInt256.toByteArray w2 ++ UInt256.toByteArray w3))) := by - rw [toByteArray_eq_toBytesBE w0, toByteArray_eq_toBytesBE w1, - toByteArray_eq_toBytesBE w2, toByteArray_eq_toBytesBE w3] - simp only [encodeReturnValues?, encodeABIValues?, hhead, bind, Option.bind] - simp only [encodeABIValuesFrom?, h0, h1, h2, h3, hd0, hd1, hd2, hd3, - Bool.false_eq_true, if_false, List.nil_append, List.append_nil] - apply congrArg some - apply ByteArray.ext - simp [ByteArray.data_append] - -theorem rewardConfigReturnEncoding (slot0 multiplier : UInt256) : - encodeReturnValues? [addr, uint64, boolTy, uint256] - (rewardConfigReturnValues slot0 multiplier) = - some (rewardConfigReturnBytes (rewardConfigTokenFromSlot0 slot0) - (rewardConfigRescaleFromSlot0 slot0) (rewardConfigShouldUpscaleFromSlot0 slot0) - multiplier) := by - unfold rewardConfigReturnValues rewardConfigReturnBytes rewardConfigTokenFromSlot0 - rewardConfigRescaleFromSlot0 rewardConfigShouldUpscaleRawFromSlot0 - rewardConfigShouldUpscaleFromSlot0 - exact encodeReturnValues_four_static - (ty0 := addr) (ty1 := uint64) (ty2 := boolTy) (ty3 := uint256) - (hhead := by native_decide) - (hd0 := by native_decide) (hd1 := by native_decide) - (hd2 := by native_decide) (hd3 := by native_decide) - (h0 := rewardConfigEncodeABIValue_masked_address slot0) - (h1 := rewardConfigEncodeABIValue_uint64 _ - (by simpa using rewardConfigRescaleWord_lt slot0)) - (h2 := rewardConfigEncodeABIValue_bool_word _) - (h3 := rewardConfigEncodeABIValue_uint256 multiplier) - -theorem cometRewardsDecode_rewardConfig_ok {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanon : (rewardConfigArgWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (rewardConfigTransition.params.map Param.name) - (transitionSignature rewardConfigTransition).paramTypes I.calldata = - some (rewardConfigStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["arg0"] [addr] I.calldata = _ - simpa [config, rewardConfigStore, rewardConfigArgValue, rewardConfigArgWord, calldataWord] - using decodeCalldata_address_ok (cd := I.calldata) (x := "arg0") hsz36 hbig hcanon - -theorem cometRewardsDecode_rewardConfig_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 36) : - decodeCalldataWithMode config.abiDecodeMode (rewardConfigTransition.params.map Param.name) - (transitionSignature rewardConfigTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["arg0"] [addr] I.calldata = none - simpa [config, addr] using decodeCalldata_address_none_short - (cd := I.calldata) (x := "arg0") hsz4 hshort - -theorem cometRewardsDecode_rewardConfig_none_noncanon {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hnc : ¬ (rewardConfigArgWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (rewardConfigTransition.params.map Param.name) - (transitionSignature rewardConfigTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["arg0"] [addr] I.calldata = none - simpa [config, addr, rewardConfigArgWord, calldataWord] - using decodeCalldata_address_none_noncanon - (cd := I.calldata) (x := "arg0") hsz36 hbig hnc - -theorem cometRewardsDecode_rewardConfig_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (rewardConfigTransition.params.map Param.name) - (transitionSignature rewardConfigTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["arg0"] [addr] I.calldata = none - simpa [config, addr] using decodeCalldata_address_none_huge - (cd := I.calldata) (x := "arg0") hbig - -theorem cometRewardsRewardConfigSelector_size {I : ExecutionEnv} - (hsel : selIs I (cometRewardsSelBytes 2)) : - 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (cometRewardsSelBytes 2) rfl hsel - -theorem cometRewardsDispatch_rewardConfig {cd : ByteArray} - (hsel : (cometRewardsSelBytes 2 == cd.extract 0 4) = true) : - dispatchMsg contract cd = some rewardConfigTransition := by - have hcd : cd.extract 0 4 = cometRewardsSelBytes 2 := - (byteArray_eq_of_beq hsel).symm - refine dispatchMsg_eq_some_of_split - (pre := [claimTransition, claimToTransition, getRewardOwedTransition, governorTransition]) - (post := [rewardsClaimedTransition, setRewardConfigTransition, - setRewardConfigWithMultiplierTransition, setRewardsClaimedTransition, - transferGovernorTransition, withdrawTokenTransition]) - rfl rfl ?_ (by rw [selectorOf, rewardConfigSelectorBytes]; exact hsel) - intro t ht - simp only [List.mem_cons, List.not_mem_nil, or_false] at ht - rcases ht with rfl | rfl | rfl | rfl - · rw [selectorOf, claimSelectorBytes, hcd] - decide - · rw [selectorOf, claimToSelectorBytes, hcd] - decide - · rw [selectorOf, getRewardOwedSelectorBytes, hcd] - decide - · rw [selectorOf, governorSelectorBytes, hcd] - decide - -theorem cometRewardsRewardConfigCalldataCheckOk {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hhi : I.calldata.size < 2 ^ 255 + 4) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨32⟩ = ⟨0⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨32⟩ = ⟨0⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - exact solcDecodeLenCheckOk_4_32 hsz36 hhi hsize - -theorem cometRewardsRewardConfigCalldataCheckShort {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hshort : I.calldata.size < 36) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨32⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨32⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 hsz4 hsize] - exact solcDecodeLenCheckShort_4_32 hsz4 hshort hsize - -theorem cometRewardsRewardConfigCalldataCheckHuge {I : ExecutionEnv} - (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨32⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨32⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - exact solcDecodeLenCheckHuge_4_32 hbig hsize - -theorem cometRewardsRewardConfigX_dec2831_arg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2831⟩ - [⟨2661⟩, solcAddrMask, ⟨0⟩, ⟨64⟩, ⟨255⟩, ⟨64⟩, ⟨224⟩, - solcAddrMask, ⟨128⟩, cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt := cometRewardsRewardConfigCalldataCheckOk (I := I) hsz36 hsize hhi - obtain ⟨_, _, rd2615⟩ := hreach - have rd2624 := evm_run rd2615 with [ - jumpdest, dup4, dup6, dup5, callvalue] - rw [hwv] at rd2624 - have rd2636 := evm_run rd2624 with [ - push2 ⟨670⟩, jumpiNT (by decide), - push1 ⟨32⟩, calldatasize, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd2636 - rw [hslt] at rd2636 - have rd2660 := evm_run rd2636 with [ - push2 ⟨670⟩, jumpiNT (by decide), - push1 ⟨128⟩, swap3, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, swap3, - push1 ⟨255⟩, swap1, dup3, swap1, dup6, - push2 ⟨2661⟩, push2 ⟨2831⟩] - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] at rd2660 - exact ⟨_, _, evm_run rd2660 with [jump (by native_decide)]⟩ - -theorem cometRewardsRewardConfigX_dec2661_arg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon : (rewardConfigArgWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2661⟩ - [rewardConfigArgWord I, solcAddrMask, ⟨0⟩, ⟨64⟩, ⟨255⟩, ⟨64⟩, ⟨224⟩, - solcAddrMask, ⟨128⟩, cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2831⟩ := - cometRewardsRewardConfigX_dec2831_arg (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hsz36 hsize hhi hreach - exact ⟨_, _, evm_run rd2831 with [ - jumpdest, push1 ⟨4⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32) := by - exact solcAddrMask_clean (by - simpa [rewardConfigArgWord, calldataWord] using hcanon) - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean] - exact u256_sub_self _), - jump (by native_decide)]⟩ - -theorem cometRewardsRewardConfigX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz4 : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hshort : I.calldata.size < 36) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsRewardConfigCalldataCheckShort (I := I) hsz4 hsize hshort - obtain ⟨_, _, rd2615⟩ := hreach - have rd2624 := evm_run rd2615 with [ - jumpdest, dup4, dup6, dup5, callvalue] - rw [hwv] at rd2624 - have rd2636 := evm_run rd2624 with [ - push2 ⟨670⟩, jumpiNT (by decide), - push1 ⟨32⟩, calldatasize, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd2636 - rw [hslt] at rd2636 - exact evm_run rd2636 with [ - push2 ⟨670⟩, jumpiT (by decide) (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsRewardConfigX_hugearg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsRewardConfigCalldataCheckHuge (I := I) hsize hbig - obtain ⟨_, _, rd2615⟩ := hreach - have rd2624 := evm_run rd2615 with [ - jumpdest, dup4, dup6, dup5, callvalue] - rw [hwv] at rd2624 - have rd2636 := evm_run rd2624 with [ - push2 ⟨670⟩, jumpiNT (by decide), - push1 ⟨32⟩, calldatasize, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd2636 - rw [hslt] at rd2636 - exact evm_run rd2636 with [ - push2 ⟨670⟩, jumpiT (by decide) (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsRewardConfigX_noncanon_arg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hnc : UInt256.eq (rewardConfigArgWord I) - (UInt256.land (rewardConfigArgWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2831⟩ := - cometRewardsRewardConfigX_dec2831_arg (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hsz36 hsize hhi hreach - exact evm_run rd2831 with [ - jumpdest, push1 ⟨4⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hclean : - UInt256.eq (rewardConfigArgWord I) - (UInt256.land (rewardConfigArgWord I) solcAddrMask) = ⟨1⟩ := by - have heq' : rewardConfigArgWord I = - UInt256.land (rewardConfigArgWord I) solcAddrMask := by - simpa [rewardConfigArgWord, calldataWord] using heq - rw [← heq'] - exact uInt256_eq_self _ - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsX_rewardConfig {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon : (rewardConfigArgWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (rewardConfigReturnBytes - (rewardConfigTokenWord σ I) (rewardConfigRescaleWord σ I) - (rewardConfigShouldUpscaleWord σ I) (rewardConfigMultiplierWord σ I)) := by - obtain ⟨_, _, rd2661⟩ := - cometRewardsRewardConfigX_dec2661_arg (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz36 hsize hhi hcanon hreach - have hslot := rewardConfigSlotOf_eq_solc I hcanon - have hkeccak := rewardConfigKeccakSlot (rewardConfigArgWord I) - have rd2674 := evm_run rd2661 with [ - jumpdest, and, dup2, - raw mstore 0 (wordAt0Mem (rewardConfigArgWord I) solcFreePtrMem) - (UInt256.ofNat 3) (by decide) mem_cost - (by - rw [solcAddrMask_clean hcanon] - rfl) - (by decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨32⟩, - raw mstore 0 (rewardConfigHashMem (rewardConfigArgWord I)) - (UInt256.ofNat 3) (by decide) mem_cost - (by rfl) (by decide) (by evm_ov), - raw keccak256 0 (solcMappingSlot ⟨1⟩ (rewardConfigArgWord I)) - (UInt256.ofNat 3) (by decide) mem_cost hkeccak (by decide) (by evm_ov)] - rw [← hslot] at rd2674 - have rd2675 := evm_run rd2674 with [push1 ⟨1⟩, dup2] - obtain ⟨_, _, rd2676⟩ := rd2675.sload (by decide) (by evm_ov) - have rd2677 := evm_run rd2676 with [swap2, add] - obtain ⟨_, _, rd2678⟩ := rd2677.sload (by decide) (by evm_ov) - have rd2716 := evm_run rd2678 with [ - swap4, dup4, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) mem_cost - (rewardConfigHashMem_mload64 (rewardConfigArgWord I)) (by decide) (by evm_ov), - swap6, dup3, and, dup7, - raw mstore 6 - (writeCascade (rewardConfigHashMem (rewardConfigArgWord I)) - [(128, rewardConfigTokenWord σ I)]) - (UInt256.ofNat 5) (by decide) mem_cost - (by rfl) - (by decide) (by evm_ov), - push1 ⟨1⟩, dup1, push1 ⟨64⟩, shl, sub, dup3, push1 ⟨160⟩, shr, and, - push1 ⟨32⟩, dup8, add, - raw mstore 3 - (writeCascade (rewardConfigHashMem (rewardConfigArgWord I)) - [(128, rewardConfigTokenWord σ I), (160, rewardConfigRescaleWord σ I)]) - (UInt256.ofNat 6) (by decide) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩ = - UInt256.ofNat (2 ^ 64 - 1) from by native_decide] - rfl) - (by decide) (by evm_ov), - shr, and, iszero, iszero, swap1, dup4, add, - raw mstore 3 - (writeCascade (rewardConfigHashMem (rewardConfigArgWord I)) - [(128, rewardConfigTokenWord σ I), (160, rewardConfigRescaleWord σ I), - (192, rewardConfigShouldUpscaleWord σ I)]) - (UInt256.ofNat 7) (by decide) mem_cost - (by rfl) (by decide) (by evm_ov), - push1 ⟨96⟩, dup3, add, - raw mstore 3 - (rewardConfigReturnMem (rewardConfigArgWord I) - (rewardConfigTokenWord σ I) (rewardConfigRescaleWord σ I) - (rewardConfigShouldUpscaleWord σ I) (rewardConfigMultiplierWord σ I)) - (UInt256.ofNat 8) (by decide) mem_cost - (by rfl) (by decide) (by evm_ov)] - exact evm_run rd2716 with [ - raw ret 0 - (rewardConfigReturnBytes - (rewardConfigTokenWord σ I) (rewardConfigRescaleWord σ I) - (rewardConfigShouldUpscaleWord σ I) (rewardConfigMultiplierWord σ I)) - (by decide) mem_cost - (by - exact rewardConfigReturnMem_read128 (rewardConfigArgWord I) - (rewardConfigTokenWord σ I) (rewardConfigRescaleWord σ I) - (rewardConfigShouldUpscaleWord σ I) (rewardConfigMultiplierWord σ I)) - (by evm_ov)] - -theorem slotAdd_zero (slot : UInt256) : - slotAdd slot 0 = slot := by - unfold slotAdd - rw [show UInt256.ofNat 0 = (⟨0⟩ : UInt256) from rfl, u256_add_comm, u256_zero_add] - -theorem slotAdd_one (slot : UInt256) : - slotAdd slot 1 = slot + ⟨1⟩ := by - rfl - -theorem rewardConfigStore_arg0 (I : ExecutionEnv) : - (rewardConfigStore I).get? "arg0" = some (rewardConfigArgValue I) := by - rw [rewardConfigStore, store_get_self] - -theorem evalStorageRef_rewardConfig_field (evm : EVM.State) (I : ExecutionEnv) - (field : Ident) : - evalStorageRef config - { contract := contract, - locals := (rewardConfigStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) } - evm (rewardConfigF (.var "arg0") field) = - .ok { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (rewardConfigArgWord I).toNat)), .field field] } := by - simp only [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, rewardConfigF, - evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, valueToKey?, - Std.HashMap.get?_eq_getElem?] - rw [← Std.HashMap.get?_eq_getElem?] - rw [store_get_ne _ _ (by decide), rewardConfigStore_arg0] - -theorem evalExpr_rewardConfig_token (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config - { contract := contract, - locals := (rewardConfigStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) } - evm (.storage (rewardConfigF (.var "arg0") "token")) = - .ok (.address (AccountAddress.ofNat - (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (rewardConfigSlotOf I)) - solcAddrMask).toNat)) := by - have her := evalStorageRef_rewardConfig_field evm I "token" - have hty : storageTypeAt? contract.storage - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (rewardConfigArgWord I).toNat)), - .field "token"] } = - some (.elem .address) := by - simp [storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (rewardConfigArgWord I).toNat)), - .field "token"] } = - fun _ => some (fieldLoc (slotAdd (rewardConfigSlotOf I) 0) 0 20 - (by decide) .address) := by - rfl - rw [evalExpr_storage_scalar - (hbase := by - change ((rewardConfigStore I).insert "__calldata" - (.bytes evm.executionEnv.calldata)).get? "rewardConfig" = none - rw [store_get_ne _ _ (by decide)] - rw [rewardConfigStore, store_get_ne _ _ (by decide)] - simp) - (her := her) (hty := hty) (hloc := hloc)] - congr 1 - rw [slotAdd_zero] - exact cometRewardsStorageLocLoad_address_offset0 evm (rewardConfigSlotOf I) - -theorem evalExpr_rewardConfig_rescale (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config - { contract := contract, - locals := (rewardConfigStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) } - evm (.storage (rewardConfigF (.var "arg0") "rescaleFactor")) = - .ok (.int (Int.ofNat - (UInt256.land - (UInt256.shiftRight - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (rewardConfigSlotOf I)) - ⟨160⟩) - (UInt256.ofNat (2 ^ 64 - 1))).toNat)) := by - have her := evalStorageRef_rewardConfig_field evm I "rescaleFactor" - have hty : storageTypeAt? contract.storage - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (rewardConfigArgWord I).toNat)), - .field "rescaleFactor"] } = - some (.elem (.int uint64Int)) := by - simp [storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (rewardConfigArgWord I).toNat)), - .field "rescaleFactor"] } = - fun _ => some (fieldLoc (slotAdd (rewardConfigSlotOf I) 0) 20 8 - (by decide) (.int uint64Int)) := by - rfl - rw [evalExpr_storage_scalar - (hbase := by - change ((rewardConfigStore I).insert "__calldata" - (.bytes evm.executionEnv.calldata)).get? "rewardConfig" = none - rw [store_get_ne _ _ (by decide)] - rw [rewardConfigStore, store_get_ne _ _ (by decide)] - simp) - (her := her) (hty := hty) (hloc := hloc)] - congr 1 - rw [slotAdd_zero] - exact cometRewardsStorageLocLoad_uint64_offset20 evm (rewardConfigSlotOf I) - -theorem evalExpr_rewardConfig_shouldUpscale (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config - { contract := contract, - locals := (rewardConfigStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) } - evm (.storage (rewardConfigF (.var "arg0") "shouldUpscale")) = - .ok (wordToElem .bool - (UInt256.land - (UInt256.shiftRight - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (rewardConfigSlotOf I)) - ⟨224⟩) - ⟨255⟩)) := by - have her := evalStorageRef_rewardConfig_field evm I "shouldUpscale" - have hty : storageTypeAt? contract.storage - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (rewardConfigArgWord I).toNat)), - .field "shouldUpscale"] } = - some (.elem .bool) := by - simp [storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (rewardConfigArgWord I).toNat)), - .field "shouldUpscale"] } = - fun _ => some (fieldLoc (slotAdd (rewardConfigSlotOf I) 0) 28 1 - (by decide) .bool) := by - rfl - rw [evalExpr_storage_scalar - (hbase := by - change ((rewardConfigStore I).insert "__calldata" - (.bytes evm.executionEnv.calldata)).get? "rewardConfig" = none - rw [store_get_ne _ _ (by decide)] - rw [rewardConfigStore, store_get_ne _ _ (by decide)] - simp) - (her := her) (hty := hty) (hloc := hloc)] - congr 1 - rw [slotAdd_zero] - exact cometRewardsStorageLocLoad_bool_offset28 evm (rewardConfigSlotOf I) - -theorem evalExpr_rewardConfig_multiplier (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config - { contract := contract, - locals := (rewardConfigStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) } - evm (.storage (rewardConfigF (.var "arg0") "multiplier")) = - .ok (.int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (rewardConfigSlotOf I + ⟨1⟩)).toNat)) := by - have her := evalStorageRef_rewardConfig_field evm I "multiplier" - have hty : storageTypeAt? contract.storage - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (rewardConfigArgWord I).toNat)), - .field "multiplier"] } = - some (.elem (.int uint256Int)) := by - simp [storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (rewardConfigArgWord I).toNat)), - .field "multiplier"] } = - fun _ => some (fieldLoc (slotAdd (rewardConfigSlotOf I) 1) 0 32 - (by decide) (.int uint256Int)) := by - rfl - rw [evalExpr_storage_scalar - (hbase := by - change ((rewardConfigStore I).insert "__calldata" - (.bytes evm.executionEnv.calldata)).get? "rewardConfig" = none - rw [store_get_ne _ _ (by decide)] - rw [rewardConfigStore, store_get_ne _ _ (by decide)] - simp) - (her := her) (hty := hty) (hloc := hloc)] - congr 1 - rw [slotAdd_one] - rw [cometRewardsStorageLocLoad_uint256] - -abbrev rewardConfigSourceReturnValues (evm : EVM.State) (I : ExecutionEnv) : List Value := - rewardConfigReturnValues - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (rewardConfigSlotOf I)) - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (rewardConfigSlotOf I + ⟨1⟩)) - -theorem evalExprList_rewardConfig_return (evm : EVM.State) (I : ExecutionEnv) : - evalExprs? config - { contract := contract, - locals := (rewardConfigStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) } - evm - [.storage (rewardConfigF (.var "arg0") "token"), - .storage (rewardConfigF (.var "arg0") "rescaleFactor"), - .storage (rewardConfigF (.var "arg0") "shouldUpscale"), - .storage (rewardConfigF (.var "arg0") "multiplier")] = - .ok (rewardConfigSourceReturnValues evm I) := by - simp only [evalExprs?, evalExpr_rewardConfig_token, evalExpr_rewardConfig_rescale, - evalExpr_rewardConfig_shouldUpscale, evalExpr_rewardConfig_multiplier, EvalResult.bind, - bind, pure, rewardConfigSourceReturnValues, rewardConfigReturnValues, - rewardConfigTokenFromSlot0, rewardConfigRescaleFromSlot0, - rewardConfigShouldUpscaleRawFromSlot0, Int.ofNat_eq_natCast] - -theorem cometRewardsRewardConfigBodyReturns (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) : - ExecTransitionBody config contract evm (rewardConfigStore I) rewardConfigTransition.body - (.returned - { contract := contract, - locals := (rewardConfigStore I).insert "__calldata" - (.bytes evm.executionEnv.calldata) } - evm - (some (rewardConfigSourceReturnValues evm I))) := by - refine ExecFuncBody.execBlockRet ?_ - simpa [rewardConfigTransition, externalEntryGuard, nonpayable, calldataSizeGuard, - rewardConfigF] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (rewardConfigStore I) hsize)).run - (ExecBlock.consReturn - (ExecStmt.return (evalExprList_rewardConfig_return evm I))) - -set_option maxHeartbeats 4000000 -/-- `rewardConfig(address)` body, reached at pc 2615. -/ -theorem cometRewardsRewardConfigBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hsel : selIs I (cometRewardsSelBytes 2)) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) rewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have _hperm : I.perm = true := hperm - have hsz4 := cometRewardsRewardConfigSelector_size hsel - have hd := cometRewardsDispatch_rewardConfig (cd := I.calldata) hsel - by_cases hsz36 : 36 ≤ I.calldata.size - · by_cases hhi : I.calldata.size < 2 ^ 255 + 4 - · by_cases hcanon : (rewardConfigArgWord I).toNat < EVM.addressModulus - · have hdec := cometRewardsDecode_rewardConfig_ok (I := I) hsz36 hhi hcanon - have hword0 : - rewardConfigSlot0Word σ_evm I = rewardConfigSlot0Word σ_solm I := - accountMapEquiv_storage_findD hAccounts I.codeOwner (rewardConfigSlotOf I) ⟨0⟩ - have hword1 : - rewardConfigMultiplierWord σ_evm I = rewardConfigMultiplierWord σ_solm I := - accountMapEquiv_storage_findD hAccounts I.codeOwner - (rewardConfigSlotOf I + (⟨1⟩ : UInt256)) ⟨0⟩ - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (rewardConfigStore I) - rewardConfigTransition.body - (.returned - { contract := contract, - locals := (rewardConfigStore I).insert "__calldata" (.bytes I.calldata) } - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (some (rewardConfigReturnValues - (rewardConfigSlot0Word σ_solm I) - (rewardConfigMultiplierWord σ_solm I)))) := by - simpa [rewardConfigSourceReturnValues, rewardConfigSlot0Word, - rewardConfigMultiplierWord, initState, Solm.EVM.storageLoad, State.lookupAccount] - using cometRewardsRewardConfigBodyReturns - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - exact (cometRewardsX_rewardConfig (g := Sat256.ofUInt256 g) - hwv hsz36 hsize hhi hcanon hreach) - |>.reEquivExecutionTransport hcode hd hdec hbody - (by rw [← hword0, ← hword1]) - hAccounts - (returnEquiv.returned rfl - (by - simpa [rewardConfigReturnValues, rewardConfigTokenFromSlot0, - rewardConfigRescaleFromSlot0, rewardConfigShouldUpscaleFromSlot0, - rewardConfigShouldUpscaleRawFromSlot0, addr, uint64, boolTy, uint256] - using rewardConfigReturnEncoding - (rewardConfigSlot0Word σ_evm I) (rewardConfigMultiplierWord σ_evm I))) - · have hdec := cometRewardsDecode_rewardConfig_none_noncanon - (I := I) hsz36 hhi hcanon - have hnc : UInt256.eq (rewardConfigArgWord I) - (UInt256.land (rewardConfigArgWord I) solcAddrMask) = ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanon (solcAddrCanonical_of_clean he)) - exact (cometRewardsRewardConfigX_noncanon_arg (g := Sat256.ofUInt256 g) - hwv hsz36 hsize hhi hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hbig : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - have hdec := cometRewardsDecode_rewardConfig_none_huge (I := I) hbig - exact (cometRewardsRewardConfigX_hugearg (g := Sat256.ofUInt256 g) - hwv hsize hbig hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hshort : I.calldata.size < 36 := by omega - have hdec := cometRewardsDecode_rewardConfig_none_short (I := I) hsz4 hshort - exact (cometRewardsRewardConfigX_shortarg (g := Sat256.ofUInt256 g) - hwv hsz4 hsize hshort hreach) - |>.reEquivDecodingFailed hcode hd hdec - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/RewardsClaimed.lean b/Benchmarks/CompoundIII/CometRewards/RewardsClaimed.lean deleted file mode 100644 index bd55a1b5..00000000 --- a/Benchmarks/CompoundIII/CometRewards/RewardsClaimed.lean +++ /dev/null @@ -1,698 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.Common - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace Benchmarks.CompoundIII.CometRewards - -/-! ## `rewardsClaimed(address,address)` getter -/ - -abbrev rewardsClaimedCometWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -abbrev rewardsClaimedAccountWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 36 - -abbrev rewardsClaimedCometValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (rewardsClaimedCometWord I).toNat) - -abbrev rewardsClaimedAccountValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (rewardsClaimedAccountWord I).toNat) - -abbrev rewardsClaimedStore (I : ExecutionEnv) : Store := - ((∅ : Store).insert "arg0" (rewardsClaimedCometValue I)).insert "arg1" - (rewardsClaimedAccountValue I) - -def rewardsClaimedSlotOf (I : ExecutionEnv) : UInt256 := - rewardsClaimedSlot - (.address (AccountAddress.ofNat (rewardsClaimedCometWord I).toNat)) - (.address (AccountAddress.ofNat (rewardsClaimedAccountWord I).toNat)) - -def rewardsClaimedWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - σ.find? I.codeOwner |>.option ⟨0⟩ - (fun acc => acc.storage.findD (rewardsClaimedSlotOf I) ⟨0⟩) - -noncomputable def rewardsClaimedInnerHashMem (comet : UInt256) : ByteArray := - twoWordHashMem comet ⟨2⟩ solcFreePtrMem - -noncomputable def rewardsClaimedOuterHashMem (comet account : UInt256) : ByteArray := - twoWordHashMem account (solcMappingSlot ⟨2⟩ comet) (rewardsClaimedInnerHashMem comet) - -noncomputable def rewardsClaimedReturnMem - (comet account val : UInt256) : ByteArray := - solcScratchReturnMem (rewardsClaimedOuterHashMem comet account) val - -theorem rewardsClaimedInnerHashMem_size (comet : UInt256) : - (rewardsClaimedInnerHashMem comet).size = 96 := by - exact twoWordHashMem_size_96 comet ⟨2⟩ solcFreePtrMem_size - -theorem rewardsClaimedInnerHashMem_read64 (comet : UInt256) : - (rewardsClaimedInnerHashMem comet).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - exact twoWordHashMem_read64 comet ⟨2⟩ solcFreePtrMem_size solcFreePtrMem_read64 - -theorem rewardsClaimedInnerKeccakSlot (comet : UInt256) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((rewardsClaimedInnerHashMem comet).readWithPadding 0 64))) = - solcMappingSlot ⟨2⟩ comet := by - rw [rewardsClaimedInnerHashMem, twoWordHashMem_read0_64 comet ⟨2⟩ solcFreePtrMem_size] - unfold solcMappingSlot - exact mappingSlot_single comet ⟨2⟩ - -theorem rewardsClaimedOuterHashMem_size (comet account : UInt256) : - (rewardsClaimedOuterHashMem comet account).size = 96 := by - exact twoWordHashMem_size_96 account (solcMappingSlot ⟨2⟩ comet) - (rewardsClaimedInnerHashMem_size comet) - -theorem rewardsClaimedOuterHashMem_read64 (comet account : UInt256) : - (rewardsClaimedOuterHashMem comet account).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - exact twoWordHashMem_read64 account (solcMappingSlot ⟨2⟩ comet) - (rewardsClaimedInnerHashMem_size comet) (rewardsClaimedInnerHashMem_read64 comet) - -theorem rewardsClaimedOuterHashMem_mload64 (comet account : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (rewardsClaimedOuterHashMem comet account).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 3 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((rewardsClaimedOuterHashMem comet account).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - ⟨128⟩ := by - exact mloadFreePtrValue - (by rw [rewardsClaimedOuterHashMem_size]; decide) (by decide) - (rewardsClaimedOuterHashMem_read64 comet account) - -theorem rewardsClaimedOuterKeccakSlot (comet account : UInt256) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((rewardsClaimedOuterHashMem comet account).readWithPadding 0 64))) = - solcMappingSlot (solcMappingSlot ⟨2⟩ comet) account := by - rw [rewardsClaimedOuterHashMem, twoWordHashMem_read0_64 account - (solcMappingSlot ⟨2⟩ comet) (rewardsClaimedInnerHashMem_size comet)] - unfold solcMappingSlot - exact mappingSlot_single account (solcMappingSlot ⟨2⟩ comet) - -theorem rewardsClaimedReturnMem_mload64 (comet account val : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (rewardsClaimedReturnMem comet account val).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 5 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((rewardsClaimedReturnMem comet account val).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - ⟨128⟩ := by - exact solcScratchReturnMem_mload64 val (rewardsClaimedOuterHashMem_size comet account) - (rewardsClaimedOuterHashMem_read64 comet account) - -theorem rewardsClaimedReturnMem_read128 (comet account val : UInt256) : - (rewardsClaimedReturnMem comet account val).readWithPadding 128 32 = - UInt256.toByteArray val := by - exact solcScratchReturnMem_read128 val (rewardsClaimedOuterHashMem_size comet account) - -theorem rewardsClaimedSlotOf_eq_solc (I : ExecutionEnv) - (hcanonComet : (rewardsClaimedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (rewardsClaimedAccountWord I).toNat < EVM.addressModulus) : - rewardsClaimedSlotOf I = - solcMappingSlot (solcMappingSlot ⟨2⟩ (rewardsClaimedCometWord I)) - (rewardsClaimedAccountWord I) := by - unfold rewardsClaimedSlotOf rewardsClaimedSlot rewardsClaimedCometSlot - rw [keyValueToWord_address_of_canonical _ hcanonComet, - keyValueToWord_address_of_canonical _ hcanonAccount] - rfl - -theorem cometRewardsDecode_rewardsClaimed_ok {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (rewardsClaimedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (rewardsClaimedAccountWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (rewardsClaimedTransition.params.map Param.name) - (transitionSignature rewardsClaimedTransition).paramTypes I.calldata = - some (rewardsClaimedStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["arg0", "arg1"] [addr, addr] - I.calldata = _ - simpa [config, rewardsClaimedStore, rewardsClaimedCometValue, rewardsClaimedAccountValue, - rewardsClaimedCometWord, rewardsClaimedAccountWord, calldataWord] - using decodeCalldata_address_address_ok (cd := I.calldata) (x := "arg0") (y := "arg1") - hsz68 hbig hcanonComet hcanonAccount - -theorem cometRewardsDecode_rewardsClaimed_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 68) : - decodeCalldataWithMode config.abiDecodeMode (rewardsClaimedTransition.params.map Param.name) - (transitionSignature rewardsClaimedTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["arg0", "arg1"] [addr, addr] - I.calldata = none - simpa [config, addr] using decodeCalldata_address_address_none_short - (cd := I.calldata) (x := "arg0") (y := "arg1") hsz4 hshort - -theorem cometRewardsDecode_rewardsClaimed_none_noncanon_comet {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hncComet : ¬ (rewardsClaimedCometWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (rewardsClaimedTransition.params.map Param.name) - (transitionSignature rewardsClaimedTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["arg0", "arg1"] [addr, addr] - I.calldata = none - simpa [config, addr, rewardsClaimedCometWord, calldataWord] - using decodeCalldata_address_address_none_noncanon0 - (cd := I.calldata) (x := "arg0") (y := "arg1") hsz68 hbig hncComet - -theorem cometRewardsDecode_rewardsClaimed_none_noncanon_account {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (rewardsClaimedCometWord I).toNat < EVM.addressModulus) - (hncAccount : ¬ (rewardsClaimedAccountWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (rewardsClaimedTransition.params.map Param.name) - (transitionSignature rewardsClaimedTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["arg0", "arg1"] [addr, addr] - I.calldata = none - simpa [config, addr, rewardsClaimedCometWord, rewardsClaimedAccountWord, calldataWord] - using decodeCalldata_address_address_none_noncanon1 - (cd := I.calldata) (x := "arg0") (y := "arg1") - hsz68 hbig hcanonComet hncAccount - -theorem cometRewardsDecode_rewardsClaimed_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (rewardsClaimedTransition.params.map Param.name) - (transitionSignature rewardsClaimedTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["arg0", "arg1"] [addr, addr] - I.calldata = none - simpa [config, addr] using decodeCalldata_address_address_none_huge - (cd := I.calldata) (x := "arg0") (y := "arg1") hbig - -theorem rewardsClaimedStore_arg0 (I : ExecutionEnv) : - (rewardsClaimedStore I).get? "arg0" = some (rewardsClaimedCometValue I) := by - rw [rewardsClaimedStore, store_get_ne _ _ (by decide), store_get_self] - -theorem rewardsClaimedStore_arg1 (I : ExecutionEnv) : - (rewardsClaimedStore I).get? "arg1" = some (rewardsClaimedAccountValue I) := by - rw [rewardsClaimedStore, store_get_self] - -theorem rewardsClaimedStore_arg0_getElem? (I : ExecutionEnv) : - (rewardsClaimedStore I)["arg0"]? = some (rewardsClaimedCometValue I) := by - rw [← Std.HashMap.get?_eq_getElem?, rewardsClaimedStore_arg0] - -theorem rewardsClaimedStore_arg1_getElem? (I : ExecutionEnv) : - (rewardsClaimedStore I)["arg1"]? = some (rewardsClaimedAccountValue I) := by - rw [← Std.HashMap.get?_eq_getElem?, rewardsClaimedStore_arg1] - -theorem evalExpr_rewardsClaimed_storage (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config - { contract := contract, - locals := (rewardsClaimedStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) } - evm (.storage (rewardsClaimedRef (.var "arg0") (.var "arg1"))) = - .ok (.int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (rewardsClaimedSlotOf I)).toNat)) := by - have her : evalStorageRef config - { contract := contract, - locals := (rewardsClaimedStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) } - evm (rewardsClaimedRef (.var "arg0") (.var "arg1")) = - .ok { base := "rewardsClaimed", - steps := [.mindex (.address (AccountAddress.ofNat - (rewardsClaimedCometWord I).toNat)), - .mindex (.address (AccountAddress.ofNat - (rewardsClaimedAccountWord I).toNat))] } := by - simp only [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, rewardsClaimedRef, - evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, valueToKey?, - Std.HashMap.get?_eq_getElem?] - rw [← Std.HashMap.get?_eq_getElem?] - rw [store_get_ne _ _ (by decide), rewardsClaimedStore_arg0] - rw [← Std.HashMap.get?_eq_getElem?] - rw [store_get_ne _ _ (by decide), rewardsClaimedStore_arg1] - have hty : storageTypeAt? contract.storage - { base := "rewardsClaimed", - steps := [.mindex (.address (AccountAddress.ofNat (rewardsClaimedCometWord I).toNat)), - .mindex (.address (AccountAddress.ofNat - (rewardsClaimedAccountWord I).toNat))] } = - some (.elem (.int uint256Int)) := by - simp [storageTypeAt?, contract, storageDecls, List.find?, List.foldlM, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardsClaimed", - steps := [.mindex (.address (AccountAddress.ofNat (rewardsClaimedCometWord I).toNat)), - .mindex (.address (AccountAddress.ofNat - (rewardsClaimedAccountWord I).toNat))] } = - fun _ => some (fieldLoc (rewardsClaimedSlotOf I) 0 32 (by decide) (.int uint256Int)) := by - rfl - rw [evalExpr_storage_scalar - (hbase := by - change ((rewardsClaimedStore I).insert "__calldata" - (.bytes evm.executionEnv.calldata)).get? "rewardsClaimed" = none - rw [store_get_ne _ _ (by decide)] - rw [rewardsClaimedStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - simp) - (her := her) (hty := hty) (hloc := hloc)] - congr 1 - exact cometRewardsStorageLocLoad_uint256 evm (rewardsClaimedSlotOf I) - -theorem cometRewardsRewardsClaimedBodyReturns (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) : - ExecTransitionBody config contract evm (rewardsClaimedStore I) rewardsClaimedTransition.body - (.returned - { contract := contract, - locals := (rewardsClaimedStore I).insert "__calldata" - (.bytes evm.executionEnv.calldata) } - evm - (some [(.int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (rewardsClaimedSlotOf I)).toNat))])) := by - refine ExecFuncBody.execBlockRet ?_ - simpa [rewardsClaimedTransition, externalEntryGuard, nonpayable, calldataSizeGuard, - rewardsClaimedRef] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (rewardsClaimedStore I) hsize)).returns (by - exact evalExpr_rewardsClaimed_storage evm I) - -theorem cometRewardsRewardsClaimedSelector_size {I : ExecutionEnv} - (hsel : selIs I (cometRewardsSelBytes 6)) : - 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (cometRewardsSelBytes 6) rfl hsel - -theorem cometRewardsDispatch_rewardsClaimed {cd : ByteArray} - (hsel : (cometRewardsSelBytes 6 == cd.extract 0 4) = true) : - dispatchMsg contract cd = some rewardsClaimedTransition := by - have hcd : cd.extract 0 4 = cometRewardsSelBytes 6 := - (byteArray_eq_of_beq hsel).symm - refine dispatchMsg_eq_some_of_split - (pre := [claimTransition, claimToTransition, getRewardOwedTransition, governorTransition, - rewardConfigTransition]) - (post := [setRewardConfigTransition, setRewardConfigWithMultiplierTransition, - setRewardsClaimedTransition, transferGovernorTransition, withdrawTokenTransition]) - rfl rfl ?_ (by rw [selectorOf, rewardsClaimedSelectorBytes]; exact hsel) - intro t ht - simp only [List.mem_cons, List.not_mem_nil, or_false] at ht - rcases ht with rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, claimSelectorBytes, hcd]; decide - · rw [selectorOf, claimToSelectorBytes, hcd]; decide - · rw [selectorOf, getRewardOwedSelectorBytes, hcd]; decide - · rw [selectorOf, governorSelectorBytes, hcd]; decide - · rw [selectorOf, rewardConfigSelectorBytes, hcd]; decide - -theorem cometRewardsRewardsClaimedCalldataCheckOk {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hhi : I.calldata.size < 2 ^ 255 + 4) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨0⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨0⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - exact solcDecodeLenCheckOk_4_64 hsz68 hhi hsize - -theorem cometRewardsRewardsClaimedCalldataCheckShort {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hshort : I.calldata.size < 68) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 hsz4 hsize] - exact solcDecodeLenCheckShort_4_64 hsz4 hshort hsize - -theorem cometRewardsRewardsClaimedCalldataCheckHuge {I : ExecutionEnv} - (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - exact solcDecodeLenCheckHuge_4_64 hbig hsize - -theorem cometRewardsRewardsClaimedX_dec2831_comet {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2831⟩ - [⟨1674⟩, ⟨0⟩, ⟨64⟩, ⟨32⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt := cometRewardsRewardsClaimedCalldataCheckOk (I := I) hsz68 hsize hhi - obtain ⟨_, _, rd1644⟩ := hreach - have rd1653 := evm_run rd1644 with [jumpdest, pop, pop, pop, callvalue] - rw [hwv] at rd1653 - have rd1660 := evm_run rd1653 with [ - push2 ⟨670⟩, jumpiNT (by decide), - dup1, push1 ⟨3⟩, not, calldatasize, add, slt] - rw [hslt] at rd1660 - exact ⟨_, _, evm_run rd1660 with [ - push2 ⟨670⟩, jumpiNT (by decide), - push1 ⟨32⟩, swap2, push2 ⟨1674⟩, push2 ⟨2831⟩, jump (by native_decide)]⟩ - -theorem cometRewardsRewardsClaimedX_dec1674_comet {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (rewardsClaimedCometWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1674⟩ - [rewardsClaimedCometWord I, ⟨0⟩, ⟨64⟩, ⟨32⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2831⟩ := - cometRewardsRewardsClaimedX_dec2831_comet (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hsz68 hsize hhi hreach - exact ⟨_, _, evm_run rd2831 with [ - jumpdest, push1 ⟨4⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32) := by - exact solcAddrMask_clean (by - simpa [rewardsClaimedCometWord, calldataWord] using hcanonComet) - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean] - exact u256_sub_self _), - jump (by native_decide)]⟩ - -theorem cometRewardsRewardsClaimedX_dec2853_account {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (rewardsClaimedCometWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2853⟩ - [⟨1683⟩, ⟨64⟩, rewardsClaimedCometWord I, ⟨0⟩, ⟨64⟩, ⟨32⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd1674⟩ := - cometRewardsRewardsClaimedX_dec1674_comet (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hreach - exact ⟨_, _, evm_run rd1674 with [ - jumpdest, dup3, push2 ⟨1683⟩, push2 ⟨2853⟩, jump (by native_decide)]⟩ - -theorem cometRewardsRewardsClaimedX_dec1683_account {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (rewardsClaimedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (rewardsClaimedAccountWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1683⟩ - [rewardsClaimedAccountWord I, ⟨64⟩, rewardsClaimedCometWord I, - ⟨0⟩, ⟨64⟩, ⟨32⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2853⟩ := - cometRewardsRewardsClaimedX_dec2853_account (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hreach - exact ⟨_, _, evm_run rd2853 with [ - jumpdest, push1 ⟨36⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32) := by - exact solcAddrMask_clean (by - simpa [rewardsClaimedAccountWord, calldataWord] using hcanonAccount) - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean] - exact u256_sub_self _), - jump (by native_decide)]⟩ - -set_option maxHeartbeats 2000000 in -theorem cometRewardsX_rewardsClaimed {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (rewardsClaimedCometWord I).toNat < EVM.addressModulus) - (hcanonAccount : (rewardsClaimedAccountWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (rewardsClaimedWord σ I)) := by - obtain ⟨_, _, rd1683⟩ := - cometRewardsRewardsClaimedX_dec1683_account (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hcanonAccount hreach - have hinner := rewardsClaimedInnerKeccakSlot (rewardsClaimedCometWord I) - have houter := rewardsClaimedOuterKeccakSlot - (rewardsClaimedCometWord I) (rewardsClaimedAccountWord I) - have hslot := rewardsClaimedSlotOf_eq_solc I hcanonComet hcanonAccount - have rd1716 := evm_run rd1683 with [ - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, swap3, dup4, and, - dup5, - raw mstore 0 (wordAt0Mem (rewardsClaimedCometWord I) solcFreePtrMem) - (UInt256.ofNat 3) (by decide) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, solcAddrMask_clean_left hcanonComet] - rfl) - (by decide) (by evm_ov), - push1 ⟨2⟩, dup7, - raw mstore 0 (rewardsClaimedInnerHashMem (rewardsClaimedCometWord I)) - (UInt256.ofNat 3) (by decide) mem_cost - (by rfl) (by decide) (by evm_ov), - swap3, - raw keccak256 0 (solcMappingSlot ⟨2⟩ (rewardsClaimedCometWord I)) - (UInt256.ofNat 3) (by decide) mem_cost hinner (by decide) (by evm_ov), - swap2, and, push1 ⟨0⟩, swap1, dup2, - raw mstore 0 - (wordAt0Mem (rewardsClaimedAccountWord I) - (rewardsClaimedInnerHashMem (rewardsClaimedCometWord I))) - (UInt256.ofNat 3) (by decide) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, solcAddrMask_clean hcanonAccount] - rfl) - (by decide) (by evm_ov), - swap1, dup4, - raw mstore 0 - (rewardsClaimedOuterHashMem (rewardsClaimedCometWord I) - (rewardsClaimedAccountWord I)) - (UInt256.ofNat 3) (by decide) mem_cost - (by rfl) (by decide) (by evm_ov), - dup2, swap1, - raw keccak256 0 - (solcMappingSlot (solcMappingSlot ⟨2⟩ (rewardsClaimedCometWord I)) - (rewardsClaimedAccountWord I)) - (UInt256.ofNat 3) (by decide) mem_cost houter (by decide) (by evm_ov)] - rw [← hslot] at rd1716 - obtain ⟨_, _, rd1717⟩ := rd1716.sload (by decide) (by evm_ov) - have rd1722 := evm_run rd1717 with [ - swap1, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) mem_cost - (rewardsClaimedOuterHashMem_mload64 - (rewardsClaimedCometWord I) (rewardsClaimedAccountWord I)) - (by decide) (by evm_ov), - swap1, dup2, - raw mstore 6 - (rewardsClaimedReturnMem (rewardsClaimedCometWord I) - (rewardsClaimedAccountWord I) (rewardsClaimedWord σ I)) - (UInt256.ofNat 5) (by decide) mem_cost - (by rfl) (by decide) (by evm_ov)] - exact evm_run rd1722 with [ - raw ret 0 (UInt256.toByteArray (rewardsClaimedWord σ I)) (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - show (⟨32⟩ : UInt256).toNat = 32 from by decide] - exact rewardsClaimedReturnMem_read128 - (rewardsClaimedCometWord I) (rewardsClaimedAccountWord I) - (rewardsClaimedWord σ I)) - (by evm_ov)] - -theorem cometRewardsRewardsClaimedX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz4 : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hshort : I.calldata.size < 68) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsRewardsClaimedCalldataCheckShort (I := I) hsz4 hsize hshort - obtain ⟨_, _, rd1644⟩ := hreach - have rd1653 := evm_run rd1644 with [jumpdest, pop, pop, pop, callvalue] - rw [hwv] at rd1653 - have rd1660 := evm_run rd1653 with [ - push2 ⟨670⟩, jumpiNT (by decide), - dup1, push1 ⟨3⟩, not, calldatasize, add, slt] - rw [hslt] at rd1660 - exact evm_run rd1660 with [ - push2 ⟨670⟩, jumpiT (by decide) (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsRewardsClaimedX_hugearg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsRewardsClaimedCalldataCheckHuge (I := I) hsize hbig - obtain ⟨_, _, rd1644⟩ := hreach - have rd1653 := evm_run rd1644 with [jumpdest, pop, pop, pop, callvalue] - rw [hwv] at rd1653 - have rd1660 := evm_run rd1653 with [ - push2 ⟨670⟩, jumpiNT (by decide), - dup1, push1 ⟨3⟩, not, calldatasize, add, slt] - rw [hslt] at rd1660 - exact evm_run rd1660 with [ - push2 ⟨670⟩, jumpiT (by decide) (by native_decide), - jumpdest, pop, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsRewardsClaimedX_noncanon_comet {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hnc : UInt256.eq (rewardsClaimedCometWord I) - (UInt256.land (rewardsClaimedCometWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2831⟩ := - cometRewardsRewardsClaimedX_dec2831_comet (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hsz68 hsize hhi hreach - exact evm_run rd2831 with [ - jumpdest, push1 ⟨4⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hclean : - UInt256.eq (rewardsClaimedCometWord I) - (UInt256.land (rewardsClaimedCometWord I) solcAddrMask) = ⟨1⟩ := by - have heq' : rewardsClaimedCometWord I = - UInt256.land (rewardsClaimedCometWord I) solcAddrMask := by - simpa [rewardsClaimedCometWord, calldataWord] using heq - rw [← heq'] - exact uInt256_eq_self _ - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsRewardsClaimedX_noncanon_account {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (rewardsClaimedCometWord I).toNat < EVM.addressModulus) - (hnc : UInt256.eq (rewardsClaimedAccountWord I) - (UInt256.land (rewardsClaimedAccountWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) rewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2853⟩ := - cometRewardsRewardsClaimedX_dec2853_account (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hreach - exact evm_run rd2853 with [ - jumpdest, push1 ⟨36⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hclean : - UInt256.eq (rewardsClaimedAccountWord I) - (UInt256.land (rewardsClaimedAccountWord I) solcAddrMask) = ⟨1⟩ := by - have heq' : rewardsClaimedAccountWord I = - UInt256.land (rewardsClaimedAccountWord I) solcAddrMask := by - simpa [rewardsClaimedAccountWord, calldataWord] using heq - rw [← heq'] - exact uInt256_eq_self _ - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -/-- `rewardsClaimed(address,address)` body, reached at pc 1644. -/ -theorem cometRewardsRewardsClaimedBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hsel : selIs I (cometRewardsSelBytes 6)) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) rewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have _hperm : I.perm = true := hperm - have hsz4 := cometRewardsRewardsClaimedSelector_size hsel - have hd := cometRewardsDispatch_rewardsClaimed (cd := I.calldata) hsel - by_cases hsz68 : 68 ≤ I.calldata.size - · by_cases hhi : I.calldata.size < 2 ^ 255 + 4 - · by_cases hcanonComet : (rewardsClaimedCometWord I).toNat < EVM.addressModulus - · by_cases hcanonAccount : (rewardsClaimedAccountWord I).toNat < EVM.addressModulus - · have hdec := - cometRewardsDecode_rewardsClaimed_ok (I := I) hsz68 hhi hcanonComet hcanonAccount - have hslot := rewardsClaimedSlotOf_eq_solc I hcanonComet hcanonAccount - have hword : rewardsClaimedWord σ_evm I = rewardsClaimedWord σ_solm I := - accountMapEquiv_storage_findD hAccounts I.codeOwner (rewardsClaimedSlotOf I) ⟨0⟩ - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (rewardsClaimedStore I) - rewardsClaimedTransition.body - (.returned - { contract := contract, - locals := (rewardsClaimedStore I).insert "__calldata" - (.bytes I.calldata) } - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (some [(.int (Int.ofNat (rewardsClaimedWord σ_solm I).toNat))])) := by - simpa [rewardsClaimedWord, initState, Solm.EVM.storageLoad, State.lookupAccount] - using cometRewardsRewardsClaimedBodyReturns - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - exact (cometRewardsX_rewardsClaimed (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hcanonComet hcanonAccount hreach) - |>.reEquivExecutionTransport hcode hd hdec hbody (by rw [← hword]) - hAccounts - (returnEquiv_of_encode - (by simpa [uint256] using uint256ReturnEncoding (rewardsClaimedWord σ_evm I))) - · have hdec := cometRewardsDecode_rewardsClaimed_none_noncanon_account - (I := I) hsz68 hhi hcanonComet hcanonAccount - have hnc : UInt256.eq (rewardsClaimedAccountWord I) - (UInt256.land (rewardsClaimedAccountWord I) solcAddrMask) = ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanonAccount (solcAddrCanonical_of_clean he)) - exact (cometRewardsRewardsClaimedX_noncanon_account (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hcanonComet hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hdec := cometRewardsDecode_rewardsClaimed_none_noncanon_comet - (I := I) hsz68 hhi hcanonComet - have hnc : UInt256.eq (rewardsClaimedCometWord I) - (UInt256.land (rewardsClaimedCometWord I) solcAddrMask) = ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanonComet (solcAddrCanonical_of_clean he)) - exact (cometRewardsRewardsClaimedX_noncanon_comet (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hbig : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - have hdec := cometRewardsDecode_rewardsClaimed_none_huge (I := I) hbig - exact (cometRewardsRewardsClaimedX_hugearg (g := Sat256.ofUInt256 g) - hwv hsize hbig hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hshort : I.calldata.size < 68 := by omega - have hdec := cometRewardsDecode_rewardsClaimed_none_short (I := I) hsz4 hshort - exact (cometRewardsRewardsClaimedX_shortarg (g := Sat256.ofUInt256 g) - hwv hsz4 hsize hshort hreach) - |>.reEquivDecodingFailed hcode hd hdec - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/Scratch.lean b/Benchmarks/CompoundIII/CometRewards/Scratch.lean deleted file mode 100644 index 8b2b377c..00000000 --- a/Benchmarks/CompoundIII/CometRewards/Scratch.lean +++ /dev/null @@ -1,192 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.Claim - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace Benchmarks.CompoundIII.CometRewards - -theorem scratch_claim_transfer_state - {cA gh bl σ σ₀ A I} {g : Sat256} - {slot0 multiplier accrued claimed : UInt256} {baseOut : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3432⟩ - [ accrued, ⟨128⟩, ⟨0⟩, claimSrcWord I, solcAddrMask, ⟨32⟩, claimed, - UInt256.land (claimSrcWord I) solcAddrMask, - UInt256.land (claimCometWord I) solcAddrMask, ⟨64⟩, ⟨1001⟩, ⟨64⟩, ⟨0⟩] - (claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut) - claimBaseTrackingPostCallAw baseOut acc k C) - (hperm : I.perm = true) - (hbaseSize : baseOut.size < UInt256.size) - (hlt : claimed.toNat < accrued.toNat) : - True := by - have hgtWord : UInt256.gt accrued claimed = ⟨1⟩ := ugt_one hlt - have rd3436₀ := evm_run rd with [jumpdest, dup7, dup2, gt] - have rd3436 := rd3436₀ - rw [hgtWord] at rd3436 - have rd3452 := evm_run rd3436 with [ - push2 ⟨3452⟩, jumpiT (by native_decide) (by jump_dest), jumpdest] - let rewardsClaimedBaseSlot : UInt256 := - ⟨16344734836896974401298970600416103014985972868941485175496275033332075043944⟩ - have rd3459 := evm_run rd3452 with [ - dup10, dup6, swap4, push2 ⟨3498⟩] - have rd3492pre := - RD.pushConst (op := .PUSH32) (width := 32) rd3459 rewardsClaimedBaseSlot - (by decide) (by native_decide) - (by evm_ov) - have rd3241 := evm_run rd3492pre with [ - swap10, dup5, push2 ⟨3241⟩, jump (by jump_dest)] - have rd3245₀ := evm_run rd3241 with [jumpdest, dup2, dup2, lt] - have hltWord : UInt256.lt accrued claimed = ⟨0⟩ := ult_zero (le_of_lt hlt) - have rd3245 := rd3245₀ - rw [hltWord] at rd3245 - have rd3498 := evm_run rd3245 with [ - push2 ⟨3252⟩, jumpiNT (by native_decide), - sub, swap1, jump (by jump_dest), jumpdest] - let postDecodeMem := claimBaseTrackingPostDecodeMem I slot0 multiplier baseOut - let innerMem := - twoWordHashMem (UInt256.land (claimCometWord I) solcAddrMask) ⟨2⟩ postDecodeMem - let outerMem := - twoWordHashMem (UInt256.land (claimSrcWord I) solcAddrMask) - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) innerMem - have hpostDecodeSize64 : 64 ≤ postDecodeMem.size := by - dsimp [postDecodeMem, claimBaseTrackingPostDecodeMem] - rw [writeWord_size] - · have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - omega - · have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - have hle : - 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide - have rd3501 := evm_run rd3498 with [ - swap11, dup2, - raw mstore 0 - (wordAt0Mem (UInt256.land (claimCometWord I) solcAddrMask) postDecodeMem) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (by - dsimp [postDecodeMem] - unfold wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have rd3505 := evm_run rd3501 with [ - push1 ⟨2⟩, dup9, - raw mstore 0 innerMem claimBaseTrackingPostCallAw (by native_decide) mem_cost - (by - dsimp [innerMem, postDecodeMem] - unfold twoWordHashMem wordAt32Mem wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have hinnerHash : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((innerMem).readWithPadding 0 64))) = - solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask) := by - dsimp [innerMem] - exact twoWordHashMem_solcMappingSlot_of_ge ⟨2⟩ - (UInt256.land (claimCometWord I) solcAddrMask) hpostDecodeSize64 - have rd3506 := rd3505.keccak256 0 - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - hinnerHash (by native_decide) (by evm_ov) - have rd3510 := evm_run rd3506 with [ - dup9, push1 ⟨0⟩, - raw mstore 0 - (wordAt0Mem (UInt256.land (claimSrcWord I) solcAddrMask) innerMem) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - (by - dsimp [innerMem] - unfold wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have rd3512 := evm_run rd3510 with [ - dup7, - raw mstore 0 outerMem claimBaseTrackingPostCallAw (by native_decide) mem_cost - (by - dsimp [outerMem, innerMem] - unfold twoWordHashMem wordAt32Mem wordAt0Mem - rfl) - (by native_decide) (by evm_ov)] - have hinnerMemSize64 : 64 ≤ innerMem.size := by - dsimp [innerMem] - rw [twoWordHashMem_size_of_ge - (UInt256.land (claimCometWord I) solcAddrMask) ⟨2⟩ hpostDecodeSize64] - exact hpostDecodeSize64 - have houterHash : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((outerMem).readWithPadding 0 64))) = - solcMappingSlot - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - (UInt256.land (claimSrcWord I) solcAddrMask) := by - dsimp [outerMem] - exact twoWordHashMem_solcMappingSlot_of_ge - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - (UInt256.land (claimSrcWord I) solcAddrMask) hinnerMemSize64 - have rd3516pre := (evm_run rd3512 with [dup10, push1 ⟨0⟩]).keccak256 0 - (solcMappingSlot - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - (UInt256.land (claimSrcWord I) solcAddrMask)) - claimBaseTrackingPostCallAw (by native_decide) mem_cost - houterHash (by native_decide) (by evm_ov) - obtain ⟨_, _, rd3518⟩ := rd3516pre.sstore hperm (by native_decide) (by evm_ov) - have hpostDecodeSize160 : 160 ≤ postDecodeMem.size := by - dsimp [postDecodeMem, claimBaseTrackingPostDecodeMem] - rw [writeWord_size] - · have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - omega - · have hge := claimBaseTrackingPostCallMem_size_ge256 I slot0 multiplier hbaseSize - have hle : - 64 - (claimBaseTrackingPostCallMem I slot0 multiplier baseOut).size = 0 := by - omega - rw [hle] - native_decide - have hinnerMemSize160 : 160 ≤ innerMem.size := by - dsimp [innerMem] - rw [twoWordHashMem_size_of_ge - (UInt256.land (claimCometWord I) solcAddrMask) ⟨2⟩ hpostDecodeSize64] - exact hpostDecodeSize160 - have houterMemSize160 : 160 ≤ outerMem.size := by - dsimp [outerMem] - rw [twoWordHashMem_size_of_ge - (UInt256.land (claimSrcWord I) solcAddrMask) - (solcMappingSlot ⟨2⟩ (UInt256.land (claimCometWord I) solcAddrMask)) - hinnerMemSize64] - exact hinnerMemSize160 - have houterMem_read128 : - outerMem.readWithPadding 128 32 = - UInt256.toByteArray (rewardConfigTokenFromSlot0 slot0) := by - dsimp [outerMem, innerMem, postDecodeMem] - rw [twoWordHashMem_read_above64_of_ge] - · rw [twoWordHashMem_read_above64_of_ge] - · exact claimBaseTrackingPostDecodeMem_read128 I slot0 multiplier hbaseSize - · exact hpostDecodeSize160 - · norm_num - · exact hinnerMemSize160 - · norm_num - have houterMem_mload128 : - (if (⟨128⟩ : UInt256).toNat ≥ outerMem.size - ∨ (⟨128⟩ : UInt256) ≥ claimBaseTrackingPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - (outerMem.readWithPadding (⟨128⟩ : UInt256).toNat 32))) = - rewardConfigTokenFromSlot0 slot0 := by - exact mloadWordValue_of_readWithPadding - (off := (⟨128⟩ : UInt256)) (aw := claimBaseTrackingPostCallAw) - (v := rewardConfigTokenFromSlot0 slot0) - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - omega) - (by native_decide) - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - exact houterMem_read128) - have rd3530 := evm_run rd3518 with [ - push2 ⟨3531⟩, dup9, dup5, dup5, dup5, - raw mload 0 (rewardConfigTokenFromSlot0 slot0) claimBaseTrackingPostCallAw - (by native_decide) mem_cost houterMem_mload128 (by native_decide) (by evm_ov), - and, push2 ⟨3915⟩, jump (by jump_dest)] - trivial - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/SetRewardConfig.lean b/Benchmarks/CompoundIII/CometRewards/SetRewardConfig.lean deleted file mode 100644 index c1198457..00000000 --- a/Benchmarks/CompoundIII/CometRewards/SetRewardConfig.lean +++ /dev/null @@ -1,7109 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.RewardConfig -import Benchmarks.CompoundIII.CometRewards.SetRewardConfigWithMultiplier -import Benchmarks.CompoundIII.CometRewards.TransferGovernor -import Reasoning.ExternalCall - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace Benchmarks.CompoundIII.CometRewards - -/-! ## `setRewardConfig(address,address)` ABI and source setup -/ - -abbrev setRewardConfigCometWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -abbrev setRewardConfigTokenWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 36 - -abbrev setRewardConfigCometValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat) - -abbrev setRewardConfigTokenValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat) - -abbrev setRewardConfigMultiplierValue : Value := - .int factorScale - -abbrev setRewardConfigStore (I : ExecutionEnv) : Store := - ((∅ : Store).insert "comet" (setRewardConfigCometValue I)).insert "token" - (setRewardConfigTokenValue I) - -abbrev setRewardConfigBodyStore (I : ExecutionEnv) : Store := - (((∅ : Store).insert "multiplier" setRewardConfigMultiplierValue).insert "token" - (setRewardConfigTokenValue I)).insert "comet" (setRewardConfigCometValue I) - -abbrev setRewardConfigArgs (I : ExecutionEnv) : List Value := - [setRewardConfigCometValue I, setRewardConfigTokenValue I, setRewardConfigMultiplierValue] - -abbrev setRewardConfigFrame (evm : EVM.State) (I : ExecutionEnv) : Frame := - { contract := contract, - locals := (setRewardConfigStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) } - -abbrev setRewardConfigBodyFrame (_evm : EVM.State) (I : ExecutionEnv) : Frame := - { contract := contract, locals := setRewardConfigBodyStore I } - -def setRewardConfigSlotOf (I : ExecutionEnv) : UInt256 := - rewardConfigSlot (.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - -theorem setRewardConfigSlotOf_eq_solc (I : ExecutionEnv) - (hcanon : (setRewardConfigCometWord I).toNat < EVM.addressModulus) : - setRewardConfigSlotOf I = solcMappingSlot ⟨1⟩ (setRewardConfigCometWord I) := by - unfold setRewardConfigSlotOf rewardConfigSlot - rw [keyValueToWord_address_of_canonical _ hcanon] - rfl - -theorem setRewardConfigStore_comet (I : ExecutionEnv) : - (setRewardConfigStore I).get? "comet" = some (setRewardConfigCometValue I) := by - rw [setRewardConfigStore, store_get_ne _ _ (by decide), store_get_self] - -theorem setRewardConfigStore_token (I : ExecutionEnv) : - (setRewardConfigStore I).get? "token" = some (setRewardConfigTokenValue I) := by - rw [setRewardConfigStore, store_get_self] - -theorem setRewardConfigBodyStore_comet (I : ExecutionEnv) : - (setRewardConfigBodyStore I).get? "comet" = some (setRewardConfigCometValue I) := by - rw [setRewardConfigBodyStore, store_get_self] - -theorem setRewardConfigBodyStore_token (I : ExecutionEnv) : - (setRewardConfigBodyStore I).get? "token" = some (setRewardConfigTokenValue I) := by - rw [setRewardConfigBodyStore, store_get_ne _ _ (by decide), store_get_self] - -theorem setRewardConfigBodyStore_multiplier (I : ExecutionEnv) : - (setRewardConfigBodyStore I).get? "multiplier" = some setRewardConfigMultiplierValue := by - rw [setRewardConfigBodyStore, store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_self] - -theorem setRewardConfigBodyStore_governor (I : ExecutionEnv) : - (setRewardConfigBodyStore I).get? "governor" = none := by - rw [setRewardConfigBodyStore, store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - native_decide - -theorem setRewardConfigBodyStore_rewardConfig (I : ExecutionEnv) : - (setRewardConfigBodyStore I).get? "rewardConfig" = none := by - rw [setRewardConfigBodyStore, store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - native_decide - -theorem evalExpr_setRewardConfig_comet (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (setRewardConfigFrame evm I) evm (.var "comet") = - .ok (setRewardConfigCometValue I) := by - simp only [setRewardConfigFrame, evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigStore_comet] - -theorem evalExpr_setRewardConfig_token (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (setRewardConfigFrame evm I) evm (.var "token") = - .ok (setRewardConfigTokenValue I) := by - simp only [setRewardConfigFrame, evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigStore_token] - -theorem evalExpr_setRewardConfig_factorScale (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (setRewardConfigFrame evm I) evm (.intLit factorScale) = - .ok setRewardConfigMultiplierValue := by - unfold evalExpr? setRewardConfigMultiplierValue - rfl - -theorem evalExprs_setRewardConfig_args (evm : EVM.State) (I : ExecutionEnv) : - evalExprs? config (setRewardConfigFrame evm I) evm - [.var "comet", .var "token", (.intLit factorScale)] = - .ok (setRewardConfigArgs I) := by - simp only [setRewardConfigArgs, evalExprs?, evalExpr_setRewardConfig_comet, - evalExpr_setRewardConfig_token, evalExpr_setRewardConfig_factorScale, - EvalResult.bind, bind] - rfl - -theorem evalExpr_setRewardConfig_body_comet (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (setRewardConfigBodyFrame evm I) evm (.var "comet") = - .ok (setRewardConfigCometValue I) := by - simp only [setRewardConfigBodyFrame, evalExpr?, EvalResult.ofOption] - rw [setRewardConfigBodyStore_comet] - -theorem evalExpr_setRewardConfig_body_token (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (setRewardConfigBodyFrame evm I) evm (.var "token") = - .ok (setRewardConfigTokenValue I) := by - simp only [setRewardConfigBodyFrame, evalExpr?, EvalResult.ofOption] - rw [setRewardConfigBodyStore_token] - -theorem evalExpr_setRewardConfig_body_multiplier (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (setRewardConfigBodyFrame evm I) evm (.var "multiplier") = - .ok setRewardConfigMultiplierValue := by - simp only [setRewardConfigBodyFrame, evalExpr?, EvalResult.ofOption] - rw [setRewardConfigBodyStore_multiplier] - -theorem lookupCallable_setRewardConfigWithMultiplierBody_from_setRewardConfig : - lookupCallable? contract "setRewardConfigWithMultiplierBody" = - some setRewardConfigWithMultiplierFunction.toCallable := by - rfl - -theorem bindParams_setRewardConfigWithMultiplier_from_setRewardConfig (I : ExecutionEnv) : - bindParams? setRewardConfigWithMultiplierFunction.params (setRewardConfigArgs I) = - some (setRewardConfigBodyStore I) := by - simp [setRewardConfigWithMultiplierFunction, setRewardConfigArgs, setRewardConfigBodyStore, - setRewardConfigCometValue, setRewardConfigTokenValue, setRewardConfigMultiplierValue, - bindParams?, factorScale] - -theorem evalExpr_setRewardConfig_body_governor (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (setRewardConfigBodyFrame evm I) evm (.storage governorRef) = - .ok (.address (AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat)) := by - have her : evalStorageRef config (setRewardConfigBodyFrame evm I) evm - governorRef = .ok { base := "governor", steps := [] } := by - simp [evalStorageRef, evalStorageRefSteps, governorRef, EvalResult.bind, pure, bind] - have hty : storageTypeAt? contract.storage - ({ base := "governor", steps := [] } : EvaledStorageRef) = some (.elem .address) := by - decide - rw [evalExpr_storage_scalar - (hbase := by - change (setRewardConfigBodyStore I).get? "governor" = none - exact setRewardConfigBodyStore_governor I) - (her := her) (hty := hty) (hloc := by rfl), - cometRewardsStorageLocLoad_address_offset0] - -theorem evalExpr_setRewardConfig_body_sender (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (setRewardConfigBodyFrame evm I) evm sender = - .ok (.address evm.executionEnv.source) := by - simp [sender, evalExpr?, envValue, pure] - -theorem evalExpr_setRewardConfig_body_auth_false (evm : EVM.State) (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask ≠ - solcSourceWord evm.executionEnv) : - evalExpr? config (setRewardConfigBodyFrame evm I) evm - (.binary .eq sender (.storage governorRef)) = .ok (.bool false) := by - simp only [evalExpr?, evalExpr_setRewardConfig_body_sender, - evalExpr_setRewardConfig_body_governor, bind, EvalResult.bind, evalBinaryOp?] - have haddr : - evm.executionEnv.source ≠ - AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat := by - intro haddr - exact hgov (by - exact solcWord_eq_of_maskedAddress_eq_source (I := evm.executionEnv) haddr.symm) - rw [show ((.address evm.executionEnv.source : Value) == - .address (AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat)) = false by - simp [BEq.beq, haddr]] - -theorem evalExpr_setRewardConfig_body_auth_true (evm : EVM.State) (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) : - evalExpr? config (setRewardConfigBodyFrame evm I) evm - (.binary .eq sender (.storage governorRef)) = .ok (.bool true) := by - simp only [evalExpr?, evalExpr_setRewardConfig_body_sender, - evalExpr_setRewardConfig_body_governor, bind, EvalResult.bind, evalBinaryOp?] - rw [solcMaskedAddress_eq_source_of_word_eq (I := evm.executionEnv) hgov] - simp [BEq.beq] - -theorem evalStorageRef_setRewardConfig_body_rewardConfig_field - (evm : EVM.State) (I : ExecutionEnv) (field : Ident) : - evalStorageRef config (setRewardConfigBodyFrame evm I) evm - (rewardConfigF (.var "comet") field) = - .ok { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigCometWord I).toNat)), - .field field] } := by - simp only [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, rewardConfigF, - evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, valueToKey?, - Std.HashMap.get?_eq_getElem?] - rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigBodyStore_comet] - -theorem evalExpr_setRewardConfig_body_rewardConfig_token (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigBodyFrame evm I) evm - (.storage (rewardConfigF (.var "comet") "token")) = - .ok (.address (AccountAddress.ofNat - (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigSlotOf I)) - solcAddrMask).toNat)) := by - have her := evalStorageRef_setRewardConfig_body_rewardConfig_field evm I "token" - have hty : storageTypeAt? contract.storage - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigCometWord I).toNat)), - .field "token"] } = - some (.elem .address) := by - simp [storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigCometWord I).toNat)), - .field "token"] } = - fun _ => some (fieldLoc (slotAdd (setRewardConfigSlotOf I) 0) 0 - 20 (by decide) .address) := by - rfl - rw [evalExpr_storage_scalar - (hbase := by - change (setRewardConfigBodyStore I).get? "rewardConfig" = none - exact setRewardConfigBodyStore_rewardConfig I) - (her := her) (hty := hty) (hloc := hloc)] - congr 1 - rw [slotAdd_zero] - exact cometRewardsStorageLocLoad_address_offset0 evm (setRewardConfigSlotOf I) - -theorem evalExpr_setRewardConfig_body_zeroAddr (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigBodyFrame evm I) evm zeroAddr = - .ok (.address (AccountAddress.ofNat 0)) := by - simp [zeroAddr, addrSt, evalExpr?, castValue?, EvalResult.bind, EvalResult.ofOption, - pure, bind] - -theorem setRewardConfigAccountAddress_ofNat_masked_ne_zero_of_ne (w : UInt256) - (h : UInt256.land w solcAddrMask ≠ ⟨0⟩) : - AccountAddress.ofNat (UInt256.land w solcAddrMask).toNat ≠ AccountAddress.ofNat 0 := by - intro haddr - apply h - apply u256_inj - have hval := congrArg (fun a : AccountAddress => a.val) haddr - have hcanon := solcAddrMask_result_canonical w - have hmod : - (UInt256.land w solcAddrMask).toNat % AccountAddress.size = - (UInt256.land w solcAddrMask).toNat := by - exact Nat.mod_eq_of_lt (by - simpa [EVM.addressModulus, EVM.twoPow, AccountAddress.size] using hcanon) - simp [AccountAddress.ofNat, hmod] at hval - simpa [UInt256.toNat] using hval - -theorem evalExpr_setRewardConfig_body_token_zero_true (evm : EVM.State) - (I : ExecutionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) : - evalExpr? config (setRewardConfigBodyFrame evm I) evm - (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr) = - .ok (.bool true) := by - simp only [evalExpr?, evalExpr_setRewardConfig_body_rewardConfig_token, - evalExpr_setRewardConfig_body_zeroAddr, bind, EvalResult.bind, evalBinaryOp?] - rw [htoken] - simp [BEq.beq] - -theorem evalExpr_setRewardConfig_body_token_zero_false (evm : EVM.State) - (I : ExecutionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask ≠ ⟨0⟩) : - evalExpr? config (setRewardConfigBodyFrame evm I) evm - (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr) = - .ok (.bool false) := by - simp only [evalExpr?, evalExpr_setRewardConfig_body_rewardConfig_token, - evalExpr_setRewardConfig_body_zeroAddr, bind, EvalResult.bind, evalBinaryOp?] - have haddr := setRewardConfigAccountAddress_ofNat_masked_ne_zero_of_ne - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) htoken - rw [show ((.address (AccountAddress.ofNat - (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigSlotOf I)) - solcAddrMask).toNat) : Value) == - .address (AccountAddress.ofNat 0)) = false by - simp [BEq.beq, haddr]] - -theorem setRewardConfigFunctionBodyReverts_auth - (evm : EVM.State) (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask ≠ - solcSourceWord evm.executionEnv) : - ExecFuncBody config (setRewardConfigBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [setRewardConfigWithMultiplierFunction] using - ExecBlock.consRevert - (ExecStmt.requireFalse (evalExpr_setRewardConfig_body_auth_false evm I hgov)) - -theorem setRewardConfigFunctionBodyReverts_configured - (evm : EVM.State) (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask ≠ ⟨0⟩) : - ExecFuncBody config (setRewardConfigBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [setRewardConfigWithMultiplierFunction] using - ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_auth_true evm I hgov)) - (ExecBlock.consRevert - (ExecStmt.requireFalse - (evalExpr_setRewardConfig_body_token_zero_false evm I htoken))) - -theorem setRewardConfigFunctionBodyReverts_baseCallFailure - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcall : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (false, evm', out) false) : - ExecFuncBody config (setRewardConfigBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_token_zero_true evm I htoken)) ?_ - exact ExecBlock.consRevert - (ExecStmt.externalCallFailure - (cfg := config) (evm := evm) (evm' := evm') - (solm := { contract := contract, locals := setRewardConfigBodyStore I }) - (receiver := .var "comet") (retVar := "accrualScale") (name := "baseAccrualScale") - (target := AccountAddress.ofNat (setRewardConfigCometWord I).toNat) - (eth := .intLit 0) (sendVal := 0) (args := []) (argVals := []) (out := out) - (perm := false) - (evalExpr_setRewardConfig_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcall) - -theorem setRewardConfigFunctionBodyReverts_baseDecodeFailure - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcall : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evm', out) false) - (hdec : config.externalABI.decode? "baseAccrualScale" out = none) : - ExecFuncBody config (setRewardConfigBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_token_zero_true evm I htoken)) ?_ - exact ExecBlock.consRevert - (ExecStmt.externalCallReturnDecodeRevert - (evalExpr_setRewardConfig_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcall hdec) - -theorem setRewardConfigFunctionBodyReverts_decimalsCallFailure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (false, evmDec, decOut) false) : - ExecFuncBody config (setRewardConfigBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfig_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigBodyStore I).insert "accrualScale" baseValue } - evmBase (.var "token") = - .ok (setRewardConfigTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigBodyStore_token] - exact ExecBlock.consRevert - (ExecStmt.externalCallFailure - (cfg := config) (evm := evmBase) (evm' := evmDec) - (solm := - { contract := contract, - locals := (setRewardConfigBodyStore I).insert "accrualScale" baseValue }) - (receiver := .var "token") (retVar := "tokenDecimals") (name := "decimals") - (target := AccountAddress.ofNat (setRewardConfigTokenWord I).toNat) - (eth := .intLit 0) (sendVal := 0) (args := []) (argVals := []) (out := decOut) - (perm := false) - htokenExpr - (by simp [evalExpr?, pure]) - (by rfl) - hcallDec) - -theorem setRewardConfigFunctionBodyReverts_decimalsDecodeFailure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : config.externalABI.decode? "decimals" decOut = none) : - ExecFuncBody config (setRewardConfigBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfig_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigBodyStore I).insert "accrualScale" baseValue } - evmBase (.var "token") = - .ok (setRewardConfigTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigBodyStore_token] - exact ExecBlock.consRevert - (ExecStmt.externalCallReturnDecodeRevert - htokenExpr - (by simp [evalExpr?, pure]) - (by rfl) - hcallDec hdecDec) - -theorem setRewardConfigFunctionBodyReverts_pow10Failure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} {decNat : ℕ} - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hgt : 77 < decNat) : - ExecFuncBody config (setRewardConfigBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfig_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigBodyStore I).insert "accrualScale" baseValue } - evmBase (.var "token") = - .ok (setRewardConfigTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigBodyStore_token] - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - htokenExpr - (by simp [evalExpr?, pure]) - (by rfl) - hcallDec hdecDec) ?_ - let afterDecimals : Frame := - { contract := contract, - locals := - ((setRewardConfigBodyStore I).insert "accrualScale" baseValue).insert - "tokenDecimals" (.int (Int.ofNat decNat)) } - have hpowArgs : - evalExprs? config afterDecimals evmDec [.var "tokenDecimals"] = - .ok [.int (Int.ofNat decNat)] := by - simp only [afterDecimals, evalExprs?, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - exact ExecBlock.consRevert - (internalCallFunctionRevert - (cfg := config) (caller := afterDecimals) (evm := evmDec) - (name := "pow10") (retVar := "tokenScale256") (args := [.var "tokenDecimals"]) - (argVals := [.int (Int.ofNat decNat)]) - (callee := pow10Function) (locals := pow10Store decNat) - hpowArgs lookupCallable_pow10 (bindParams_pow10 decNat) - (by simpa [afterDecimals] using pow10FunctionBodyReverts_gt77 evmDec hgt)) - -theorem setRewardConfigFunctionBodyReverts_safe64Failure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} {decNat : ℕ} - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hgt64 : 2 ^ 64 - 1 < (10 : ℕ) ^ decNat) : - ExecFuncBody config (setRewardConfigBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfig_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigBodyStore I).insert "accrualScale" baseValue } - evmBase (.var "token") = - .ok (setRewardConfigTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigBodyStore_token] - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - htokenExpr - (by simp [evalExpr?, pure]) - (by rfl) - hcallDec hdecDec) ?_ - let afterDecimals : Frame := - { contract := contract, - locals := - ((setRewardConfigBodyStore I).insert "accrualScale" baseValue).insert - "tokenDecimals" (.int (Int.ofNat decNat)) } - have hpowArgs : - evalExprs? config afterDecimals evmDec [.var "tokenDecimals"] = - .ok [.int (Int.ofNat decNat)] := by - simp only [afterDecimals, evalExprs?, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := afterDecimals) (evm := evmDec) (calleeEvm := evmDec) - (name := "pow10") (retVar := "tokenScale256") (args := [.var "tokenDecimals"]) - (argVals := [.int (Int.ofNat decNat)]) - (callee := pow10Function) (locals := pow10Store decNat) - (calleeSolm := { contract := contract, locals := pow10Store decNat }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hpowArgs lookupCallable_pow10 (bindParams_pow10 decNat) - (by simpa using pow10FunctionBodyReturns_le77 evmDec hle77)) ?_ - let afterPow10 : Frame := - resumeAfterInternalCall afterDecimals "tokenScale256" - (some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - have hsafeArgs : - evalExprs? config afterPow10 evmDec [.var "tokenScale256"] = - .ok [.int (Int.ofNat ((10 : ℕ) ^ decNat))] := by - simp only [afterPow10, afterDecimals, resumeAfterInternalCall, evalExprs?, evalExpr?, - EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - exact ExecBlock.consRevert - (internalCallFunctionRevert - (cfg := config) (caller := afterPow10) (evm := evmDec) - (name := "safe64") (retVar := "tokenScale") (args := [.var "tokenScale256"]) - (argVals := [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - (callee := safe64Function) (locals := safe64Store ((10 : ℕ) ^ decNat)) - hsafeArgs lookupCallable_safe64 (bindParams_safe64 ((10 : ℕ) ^ decNat)) - (by simpa [afterPow10] using safe64FunctionBodyReverts_gt evmDec hgt64)) - -abbrev setRewardConfigMultiplierWord : UInt256 := - ⟨1000000000000000000⟩ - -theorem setRewardConfigMultiplierValue_eq_word : - setRewardConfigMultiplierValue = .int (Int.ofNat setRewardConfigMultiplierWord.toNat) := by - unfold setRewardConfigMultiplierValue setRewardConfigMultiplierWord factorScale - native_decide - -def setRewardConfigWrapperSourceAfterToken (evm : EVM.State) (I : ExecutionEnv) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I) - (setRewardConfigSlot0AfterToken - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - (setRewardConfigTokenWord I)) - -def setRewardConfigWrapperSourceAfterRescale (evm : EVM.State) (I : ExecutionEnv) - (rescale : UInt256) : EVM.State := - Solm.EVM.storageStore (setRewardConfigWrapperSourceAfterToken evm I) - (setRewardConfigWrapperSourceAfterToken evm I).executionEnv.codeOwner - (setRewardConfigSlotOf I) - (setRewardConfigUInt64Offset20Word - (Solm.EVM.storageLoad (setRewardConfigWrapperSourceAfterToken evm I) - (setRewardConfigWrapperSourceAfterToken evm I).executionEnv.codeOwner - (setRewardConfigSlotOf I)) - rescale) - -def setRewardConfigWrapperSourceAfterShouldUpscale (evm : EVM.State) (I : ExecutionEnv) - (rescale : UInt256) (shouldUpscale : Bool) : EVM.State := - let evmRescale := setRewardConfigWrapperSourceAfterRescale evm I rescale - Solm.EVM.storageStore evmRescale evmRescale.executionEnv.codeOwner (setRewardConfigSlotOf I) - (setRewardConfigBoolOffset28Word - (Solm.EVM.storageLoad evmRescale evmRescale.executionEnv.codeOwner - (setRewardConfigSlotOf I)) - (if shouldUpscale then ⟨1⟩ else ⟨0⟩)) - -def setRewardConfigWrapperSourceFinal (evm : EVM.State) (I : ExecutionEnv) - (rescale : UInt256) (shouldUpscale : Bool) : EVM.State := - let evmBool := setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale shouldUpscale - Solm.EVM.storageStore evmBool evmBool.executionEnv.codeOwner - (setRewardConfigSlotOf I + ⟨1⟩) setRewardConfigMultiplierWord - -theorem setRewardConfigWrapperSourceFinal_false (evm : EVM.State) (I : ExecutionEnv) - (rescale : UInt256) : - setRewardConfigWrapperSourceFinal evm I rescale false = - Solm.EVM.storageStore - (setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale false) - (setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale false).executionEnv.codeOwner - (setRewardConfigSlotOf I + ⟨1⟩) setRewardConfigMultiplierWord := by - rfl - -theorem setRewardConfigWrapperSourceFinal_true (evm : EVM.State) (I : ExecutionEnv) - (rescale : UInt256) : - setRewardConfigWrapperSourceFinal evm I rescale true = - Solm.EVM.storageStore - (setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale true) - (setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale true).executionEnv.codeOwner - (setRewardConfigSlotOf I + ⟨1⟩) setRewardConfigMultiplierWord := by - rfl - -set_option maxHeartbeats 5000000 in -theorem setRewardConfigWrapperSourceFinal_accountMap_equiv - (evm : EVM.State) (I : ExecutionEnv) (rescale : UInt256) (shouldUpscale : Bool) : - accountMapEquiv - (sstoreAccountMap evm.executionEnv.codeOwner - (sstoreAccountMap evm.executionEnv.codeOwner evm.accountMap - (setRewardConfigSlotOf I) - (setRewardConfigSlot0Final - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - (setRewardConfigTokenWord I) rescale - (if shouldUpscale then ⟨1⟩ else ⟨0⟩))) - (setRewardConfigSlotOf I + ⟨1⟩) - setRewardConfigMultiplierWord) - (setRewardConfigWrapperSourceFinal evm I rescale shouldUpscale).accountMap := by - let owner := evm.executionEnv.codeOwner - let slot := setRewardConfigSlotOf I - let bit : UInt256 := if shouldUpscale then ⟨1⟩ else ⟨0⟩ - let old := Solm.EVM.storageLoad evm owner slot - let tokenWord := setRewardConfigSlot0AfterToken old (setRewardConfigTokenWord I) - let rescaleWord := setRewardConfigSlot0AfterRescale old (setRewardConfigTokenWord I) rescale - let finalWord := setRewardConfigSlot0Final old (setRewardConfigTokenWord I) rescale bit - cases hacc : evm.accountMap.find? owner with - | none => - have htoken : setRewardConfigWrapperSourceAfterToken evm I = evm := by - unfold setRewardConfigWrapperSourceAfterToken - simpa [owner, slot] using - storageStore_absent evm owner hacc slot - (setRewardConfigSlot0AfterToken old (setRewardConfigTokenWord I)) - have hrescale : setRewardConfigWrapperSourceAfterRescale evm I rescale = evm := by - unfold setRewardConfigWrapperSourceAfterRescale - rw [htoken] - simpa [owner, slot] using - storageStore_absent evm owner hacc slot - (setRewardConfigUInt64Offset20Word old rescale) - have hbool : - setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale shouldUpscale = evm := by - unfold setRewardConfigWrapperSourceAfterShouldUpscale - rw [hrescale] - simpa [owner, slot, bit] using - storageStore_absent evm owner hacc slot - (setRewardConfigBoolOffset28Word old bit) - have hsource : - setRewardConfigWrapperSourceFinal evm I rescale shouldUpscale = evm := by - unfold setRewardConfigWrapperSourceFinal - rw [hbool] - simpa [owner, slot] using - storageStore_absent evm owner hacc (slot + ⟨1⟩) setRewardConfigMultiplierWord - have hleft : - sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot finalWord) - (slot + ⟨1⟩) setRewardConfigMultiplierWord = - evm.accountMap := by - unfold sstoreAccountMap - rw [hacc] - simp [Option.option] - rw [hacc] - rw [hsource] - simpa [owner, slot, bit, old, finalWord, hleft] using - accountMapEquiv_refl evm.accountMap - | some acc => - have hcollapse0 : - accountMapEquiv - (sstoreAccountMap owner evm.accountMap slot finalWord) - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot finalWord) := - accountMapEquiv_sstoreAccountMap_self_update evm.accountMap owner slot tokenWord finalWord - have hcollapse1 : - accountMapEquiv - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot finalWord) - (sstoreAccountMap owner - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot rescaleWord) - slot finalWord) := - accountMapEquiv_sstoreAccountMap_self_update - (sstoreAccountMap owner evm.accountMap slot tokenWord) owner slot rescaleWord finalWord - have hcollapseSlot : - accountMapEquiv - (sstoreAccountMap owner evm.accountMap slot finalWord) - (sstoreAccountMap owner - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot rescaleWord) - slot finalWord) := - accountMapEquiv.trans hcollapse0 hcollapse1 - have hcollapse := - accountMapEquiv_sstoreAccountMap - (σ := sstoreAccountMap owner evm.accountMap slot finalWord) - (τ := sstoreAccountMap owner - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot rescaleWord) - slot finalWord) - owner (slot + ⟨1⟩) setRewardConfigMultiplierWord hcollapseSlot - have hsource : - (setRewardConfigWrapperSourceFinal evm I rescale shouldUpscale).accountMap = - sstoreAccountMap owner - (sstoreAccountMap owner - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot rescaleWord) - slot finalWord) - (slot + ⟨1⟩) setRewardConfigMultiplierWord := by - have htokenMap : - (setRewardConfigWrapperSourceAfterToken evm I).accountMap = - sstoreAccountMap owner evm.accountMap slot tokenWord := by - unfold setRewardConfigWrapperSourceAfterToken - simpa [owner, slot, old, tokenWord] using - storageStore_accountMap evm owner slot tokenWord - have htokenEnv : - (setRewardConfigWrapperSourceAfterToken evm I).executionEnv = evm.executionEnv := by - unfold setRewardConfigWrapperSourceAfterToken - simpa [owner, slot, old, tokenWord] using - storageStore_executionEnv evm owner slot tokenWord - have hloadToken : - Solm.EVM.storageLoad (setRewardConfigWrapperSourceAfterToken evm I) - (setRewardConfigWrapperSourceAfterToken evm I).executionEnv.codeOwner slot = - tokenWord := by - unfold setRewardConfigWrapperSourceAfterToken - rw [storageStore_executionEnv] - simpa [owner, slot, old, tokenWord] using - storageLoad_storageStore_same_present evm owner hacc slot tokenWord - have hloadTokenOwner : - Solm.EVM.storageLoad (setRewardConfigWrapperSourceAfterToken evm I) - evm.executionEnv.codeOwner slot = tokenWord := by - simpa [htokenEnv] using hloadToken - have hrescaleMap : - (setRewardConfigWrapperSourceAfterRescale evm I rescale).accountMap = - sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot rescaleWord := by - unfold setRewardConfigWrapperSourceAfterRescale - simp [setRewardConfigWrapperSourceAfterToken, owner, slot, old, tokenWord, - rescaleWord, setRewardConfigSlot0AfterRescale, storageStore_accountMap, - storageStore_executionEnv, - storageLoad_storageStore_same_present evm owner hacc slot tokenWord] - have hrescaleEnv : - (setRewardConfigWrapperSourceAfterRescale evm I rescale).executionEnv = - evm.executionEnv := by - unfold setRewardConfigWrapperSourceAfterRescale - rw [storageStore_executionEnv] - exact htokenEnv - have haccToken : - ∃ acc', - (setRewardConfigWrapperSourceAfterToken evm I).accountMap.find? owner = some acc' := by - rw [htokenMap] - unfold sstoreAccountMap - rw [hacc] - simp [Option.option] - exact ⟨_, accountMap_find_insert_self _ _ _⟩ - rcases haccToken with ⟨accToken, haccToken⟩ - have haccTokenOwner : - (setRewardConfigWrapperSourceAfterToken evm I).accountMap.find? - (setRewardConfigWrapperSourceAfterToken evm I).executionEnv.codeOwner = - some accToken := by - simpa [htokenEnv] using haccToken - have hloadRescale : - Solm.EVM.storageLoad (setRewardConfigWrapperSourceAfterRescale evm I rescale) - (setRewardConfigWrapperSourceAfterRescale evm I rescale).executionEnv.codeOwner - slot = rescaleWord := by - unfold setRewardConfigWrapperSourceAfterRescale - rw [storageStore_executionEnv] - simpa [slot, rescaleWord, setRewardConfigSlot0AfterRescale, hloadToken] using - storageLoad_storageStore_same_present - (setRewardConfigWrapperSourceAfterToken evm I) - (setRewardConfigWrapperSourceAfterToken evm I).executionEnv.codeOwner - haccTokenOwner slot rescaleWord - have hloadRescaleOwner : - Solm.EVM.storageLoad (setRewardConfigWrapperSourceAfterRescale evm I rescale) - evm.executionEnv.codeOwner slot = rescaleWord := by - simpa [hrescaleEnv] using hloadRescale - have hboolMap : - (setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale shouldUpscale).accountMap = - sstoreAccountMap owner - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot rescaleWord) - slot finalWord := by - unfold setRewardConfigWrapperSourceAfterShouldUpscale - simp [hrescaleMap, hrescaleEnv, hloadRescaleOwner, owner, slot, bit, finalWord, - rescaleWord, setRewardConfigSlot0Final, setRewardConfigSlot0AfterRescale, - storageStore_accountMap] - have hboolEnv : - (setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale shouldUpscale).executionEnv = - evm.executionEnv := by - unfold setRewardConfigWrapperSourceAfterShouldUpscale - simp [hrescaleEnv, owner, slot, bit, finalWord, setRewardConfigSlot0Final, - storageStore_executionEnv] - unfold setRewardConfigWrapperSourceFinal - simp [hboolMap, hboolEnv, owner, slot, storageStore_accountMap] - rw [hsource] - simpa [owner, slot, bit, old, finalWord] using hcollapse - -def setRewardConfigWrapperAfterDecimalsFrame (I : ExecutionEnv) (baseWord : UInt256) - (decNat : ℕ) : Frame := - { contract := contract, - locals := - ((setRewardConfigBodyStore I).insert "accrualScale" - (.int (Int.ofNat baseWord.toNat))).insert "tokenDecimals" (.int (Int.ofNat decNat)) } - -def setRewardConfigWrapperAfterPow10Frame (I : ExecutionEnv) (baseWord : UInt256) - (decNat : ℕ) : Frame := - resumeAfterInternalCall (setRewardConfigWrapperAfterDecimalsFrame I baseWord decNat) - "tokenScale256" (some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - -def setRewardConfigWrapperAfterSafe64Frame (I : ExecutionEnv) (baseWord : UInt256) - (decNat : ℕ) : Frame := - resumeAfterInternalCall (setRewardConfigWrapperAfterPow10Frame I baseWord decNat) - "tokenScale" (some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - -theorem evalStorageRef_setRewardConfigWrapper_rewardConfig_field_of_comet - (evm : EVM.State) (I : ExecutionEnv) (field : Ident) {locals : Store} - (hcomet : locals.get? "comet" = some (setRewardConfigCometValue I)) : - evalStorageRef config { contract := contract, locals := locals } evm - (rewardConfigF (.var "comet") field) = - .ok { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigCometWord I).toNat)), - .field field] } := by - simp only [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, rewardConfigF, - evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, valueToKey?, - Std.HashMap.get?_eq_getElem?] - rw [← Std.HashMap.get?_eq_getElem?] - rw [hcomet] - -theorem setRewardConfigWrapperAfterSafe64Frame_rewardConfig_none (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) : - (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat).locals.get? "rewardConfig" = - none := by - simp only [setRewardConfigWrapperAfterSafe64Frame, setRewardConfigWrapperAfterPow10Frame, - setRewardConfigWrapperAfterDecimalsFrame, resumeAfterInternalCall] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - setRewardConfigBodyStore_rewardConfig] - -theorem setRewardConfigWrapperAfterSafe64Frame_comet (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) : - (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat).locals.get? "comet" = - some (setRewardConfigCometValue I) := by - simp only [setRewardConfigWrapperAfterSafe64Frame, setRewardConfigWrapperAfterPow10Frame, - setRewardConfigWrapperAfterDecimalsFrame, resumeAfterInternalCall] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - setRewardConfigBodyStore_comet] - -theorem setRewardConfigWrapperAfterSafe64Frame_accrualScale (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) : - (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat).locals.get? "accrualScale" = - some (.int (Int.ofNat baseWord.toNat)) := by - simp only [setRewardConfigWrapperAfterSafe64Frame, setRewardConfigWrapperAfterPow10Frame, - setRewardConfigWrapperAfterDecimalsFrame, resumeAfterInternalCall] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_self] - -theorem setRewardConfigWrapperAfterSafe64Frame_tokenScale (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) : - (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat).locals.get? "tokenScale" = - some (.int (Int.ofNat ((10 : ℕ) ^ decNat))) := by - simp only [setRewardConfigWrapperAfterSafe64Frame, resumeAfterInternalCall, collapseReturns] - rw [store_get_self] - -theorem setRewardConfigWrapperAfterSafe64Frame_token (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) : - (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat).locals.get? "token" = - some (setRewardConfigTokenValue I) := by - simp only [setRewardConfigWrapperAfterSafe64Frame, setRewardConfigWrapperAfterPow10Frame, - setRewardConfigWrapperAfterDecimalsFrame, resumeAfterInternalCall] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - setRewardConfigBodyStore_token] - -theorem setRewardConfigWrapperAfterSafe64Frame_multiplier (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) : - (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat).locals.get? "multiplier" = - some setRewardConfigMultiplierValue := by - simp only [setRewardConfigWrapperAfterSafe64Frame, setRewardConfigWrapperAfterPow10Frame, - setRewardConfigWrapperAfterDecimalsFrame, resumeAfterInternalCall] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - setRewardConfigBodyStore_multiplier] - -theorem setRewardConfigWrapperAssign_token_afterSafe64 (evm : EVM.State) (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) - (hcanonToken : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) : - assignStorageRef? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - evm .storage (rewardConfigF (.var "comet") "token") (setRewardConfigTokenValue I) = - .ok (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat, - setRewardConfigWrapperSourceAfterToken evm I) := by - let er : EvaledStorageRef := - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)), - .field "token"] } - let loc : StorageLoc := - fieldLoc (slotAdd (setRewardConfigSlotOf I) 0) 0 20 (by decide) .address - have her : - evalStorageRef config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) evm - (rewardConfigF (.var "comet") "token") = .ok er := by - exact evalStorageRef_setRewardConfigWrapper_rewardConfig_field_of_comet - (evm := evm) (I := I) (field := "token") - (setRewardConfigWrapperAfterSafe64Frame_comet I baseWord decNat) - have hty : storageTypeAt? contract.storage er = some (.elem .address) := by - simp [er, storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hstore : - storageLocStore evm loc (setRewardConfigTokenValue I) = - some (setRewardConfigWrapperSourceAfterToken evm I) := by - rw [show loc = fieldLoc (slotAdd (setRewardConfigSlotOf I) 0) 0 20 - (by decide) .address from rfl, slotAdd_zero] - simpa [setRewardConfigWrapperSourceAfterToken, setRewardConfigSlot0AfterToken, - setRewardConfigTokenValue, fieldLoc, loc, addressOffset0Loc] using - storageLocStore_address_offset0 evm (setRewardConfigSlotOf I) - (setRewardConfigTokenWord I) hcanonToken - exact assignStorageRef_storage_scalar_value (cfg := config) - (solm := setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (evm := evm) (evm' := setRewardConfigWrapperSourceAfterToken evm I) - (slot := rewardConfigF (.var "comet") "token") (er := er) - (ty := .elem .address) (loc := loc) (value := setRewardConfigTokenValue I) - (setRewardConfigWrapperAfterSafe64Frame_rewardConfig_none I baseWord decNat) - her hty (by rfl) (by trivial) hstore - -theorem setRewardConfigWrapperAssign_rescale_afterSafe64 (evm : EVM.State) - (I : ExecutionEnv) (baseWord rescale : UInt256) (decNat : ℕ) : - assignStorageRef? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceAfterToken evm I) .storage - (rewardConfigF (.var "comet") "rescaleFactor") (.int (Int.ofNat rescale.toNat)) = - .ok (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat, - setRewardConfigWrapperSourceAfterRescale evm I rescale) := by - let er : EvaledStorageRef := - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)), - .field "rescaleFactor"] } - let loc : StorageLoc := - fieldLoc (slotAdd (setRewardConfigSlotOf I) 0) 20 8 (by decide) (.int uint64Int) - have her : - evalStorageRef config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceAfterToken evm I) - (rewardConfigF (.var "comet") "rescaleFactor") = .ok er := by - exact evalStorageRef_setRewardConfigWrapper_rewardConfig_field_of_comet - (evm := setRewardConfigWrapperSourceAfterToken evm I) (I := I) - (field := "rescaleFactor") - (setRewardConfigWrapperAfterSafe64Frame_comet I baseWord decNat) - have hty : storageTypeAt? contract.storage er = some (.elem (.int uint64Int)) := by - simp [er, storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hstore : - storageLocStore (setRewardConfigWrapperSourceAfterToken evm I) loc - (.int (Int.ofNat rescale.toNat)) = - some (setRewardConfigWrapperSourceAfterRescale evm I rescale) := by - rw [show loc = fieldLoc (slotAdd (setRewardConfigSlotOf I) 0) 20 8 - (by decide) (.int uint64Int) from rfl, slotAdd_zero] - simpa [setRewardConfigWrapperSourceAfterRescale] using - setRewardConfigStorageLocStore_uint64_offset20 - (setRewardConfigWrapperSourceAfterToken evm I) (setRewardConfigSlotOf I) rescale - exact assignStorageRef_storage_scalar_value (cfg := config) - (solm := setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (evm := setRewardConfigWrapperSourceAfterToken evm I) - (evm' := setRewardConfigWrapperSourceAfterRescale evm I rescale) - (slot := rewardConfigF (.var "comet") "rescaleFactor") (er := er) - (ty := .elem (.int uint64Int)) (loc := loc) - (value := .int (Int.ofNat rescale.toNat)) - (setRewardConfigWrapperAfterSafe64Frame_rewardConfig_none I baseWord decNat) - her hty (by rfl) (by trivial) hstore - -theorem setRewardConfigWrapperAssign_shouldUpscale_false_afterSafe64 (evm : EVM.State) - (I : ExecutionEnv) (baseWord rescale : UInt256) (decNat : ℕ) : - assignStorageRef? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceAfterRescale evm I rescale) .storage - (rewardConfigF (.var "comet") "shouldUpscale") (.bool false) = - .ok (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat, - setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale false) := by - let er : EvaledStorageRef := - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)), - .field "shouldUpscale"] } - let loc : StorageLoc := - fieldLoc (slotAdd (setRewardConfigSlotOf I) 0) 28 1 (by decide) .bool - have her : - evalStorageRef config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceAfterRescale evm I rescale) - (rewardConfigF (.var "comet") "shouldUpscale") = .ok er := by - exact evalStorageRef_setRewardConfigWrapper_rewardConfig_field_of_comet - (evm := setRewardConfigWrapperSourceAfterRescale evm I rescale) (I := I) - (field := "shouldUpscale") - (setRewardConfigWrapperAfterSafe64Frame_comet I baseWord decNat) - have hty : storageTypeAt? contract.storage er = some (.elem .bool) := by - simp [er, storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hstore : - storageLocStore (setRewardConfigWrapperSourceAfterRescale evm I rescale) loc (.bool false) = - some (setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale false) := by - rw [show loc = fieldLoc (slotAdd (setRewardConfigSlotOf I) 0) 28 1 - (by decide) .bool from rfl, slotAdd_zero] - simpa [setRewardConfigWrapperSourceAfterShouldUpscale] using - setRewardConfigStorageLocStore_bool_false_offset28 - (setRewardConfigWrapperSourceAfterRescale evm I rescale) (setRewardConfigSlotOf I) - exact assignStorageRef_storage_scalar_value (cfg := config) - (solm := setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (evm := setRewardConfigWrapperSourceAfterRescale evm I rescale) - (evm' := setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale false) - (slot := rewardConfigF (.var "comet") "shouldUpscale") (er := er) - (ty := .elem .bool) (loc := loc) (value := .bool false) - (setRewardConfigWrapperAfterSafe64Frame_rewardConfig_none I baseWord decNat) - her hty (by rfl) (by trivial) hstore - -theorem setRewardConfigWrapperAssign_shouldUpscale_true_afterSafe64 (evm : EVM.State) - (I : ExecutionEnv) (baseWord rescale : UInt256) (decNat : ℕ) : - assignStorageRef? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceAfterRescale evm I rescale) .storage - (rewardConfigF (.var "comet") "shouldUpscale") (.bool true) = - .ok (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat, - setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale true) := by - let er : EvaledStorageRef := - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)), - .field "shouldUpscale"] } - let loc : StorageLoc := - fieldLoc (slotAdd (setRewardConfigSlotOf I) 0) 28 1 (by decide) .bool - have her : - evalStorageRef config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceAfterRescale evm I rescale) - (rewardConfigF (.var "comet") "shouldUpscale") = .ok er := by - exact evalStorageRef_setRewardConfigWrapper_rewardConfig_field_of_comet - (evm := setRewardConfigWrapperSourceAfterRescale evm I rescale) (I := I) - (field := "shouldUpscale") - (setRewardConfigWrapperAfterSafe64Frame_comet I baseWord decNat) - have hty : storageTypeAt? contract.storage er = some (.elem .bool) := by - simp [er, storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hstore : - storageLocStore (setRewardConfigWrapperSourceAfterRescale evm I rescale) loc (.bool true) = - some (setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale true) := by - rw [show loc = fieldLoc (slotAdd (setRewardConfigSlotOf I) 0) 28 1 - (by decide) .bool from rfl, slotAdd_zero] - simpa [setRewardConfigWrapperSourceAfterShouldUpscale] using - setRewardConfigStorageLocStore_bool_true_offset28 - (setRewardConfigWrapperSourceAfterRescale evm I rescale) (setRewardConfigSlotOf I) - exact assignStorageRef_storage_scalar_value (cfg := config) - (solm := setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (evm := setRewardConfigWrapperSourceAfterRescale evm I rescale) - (evm' := setRewardConfigWrapperSourceAfterShouldUpscale evm I rescale true) - (slot := rewardConfigF (.var "comet") "shouldUpscale") (er := er) - (ty := .elem .bool) (loc := loc) (value := .bool true) - (setRewardConfigWrapperAfterSafe64Frame_rewardConfig_none I baseWord decNat) - her hty (by rfl) (by trivial) hstore - -set_option maxHeartbeats 5000000 in -theorem setRewardConfigWrapperAssign_multiplier_afterSafe64_state - (evm : EVM.State) (I : ExecutionEnv) (baseWord : UInt256) (decNat : ℕ) : - assignStorageRef? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - evm .storage (rewardConfigF (.var "comet") "multiplier") - setRewardConfigMultiplierValue = - .ok (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat, - Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (setRewardConfigSlotOf I + ⟨1⟩) setRewardConfigMultiplierWord) := by - let er : EvaledStorageRef := - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)), - .field "multiplier"] } - let loc : StorageLoc := uint256Loc (setRewardConfigSlotOf I + ⟨1⟩) - have her : - evalStorageRef config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) evm - (rewardConfigF (.var "comet") "multiplier") = .ok er := by - exact evalStorageRef_setRewardConfigWrapper_rewardConfig_field_of_comet - (evm := evm) (I := I) (field := "multiplier") - (setRewardConfigWrapperAfterSafe64Frame_comet I baseWord decNat) - have hty : storageTypeAt? contract.storage er = some (.elem (.int uint256Int)) := by - simp [er, storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hloc : config.storage.layout er = fun _ => some loc := by - rw [show loc = fieldLoc (slotAdd (setRewardConfigSlotOf I) 1) 0 32 - (by decide) (.int uint256Int) by - dsimp [loc] - rw [slotAdd_one] - rfl] - rfl - have hstore : - storageLocStore evm loc setRewardConfigMultiplierValue = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (setRewardConfigSlotOf I + ⟨1⟩) setRewardConfigMultiplierWord) := by - let slot1 := setRewardConfigSlotOf I + ⟨1⟩ - change storageLocStore evm (uint256Loc slot1) setRewardConfigMultiplierValue = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner slot1 - setRewardConfigMultiplierWord) - rw [setRewardConfigMultiplierValue_eq_word] - exact storageLocStore_uint256 evm slot1 setRewardConfigMultiplierWord - apply assignStorageRef_storage_scalar_value - (er := er) (ty := .elem (.int uint256Int)) (loc := loc) - · exact setRewardConfigWrapperAfterSafe64Frame_rewardConfig_none I baseWord decNat - · exact her - · exact hty - · exact hloc - · trivial - · exact hstore - -set_option maxHeartbeats 1000000 in -theorem setRewardConfigFunctionBodyReturns_downscale - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseWord rescale : UInt256} {decNat : ℕ} - (hcanonToken : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : - config.externalABI.decode? "baseAccrualScale" baseOut = - some [.int (Int.ofNat baseWord.toNat)]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ decNat ≤ 2 ^ 64 - 1) - (hrescale : rescale.toNat = baseWord.toNat / (10 : ℕ) ^ decNat) - (hgt : (10 : ℕ) ^ decNat < baseWord.toNat) : - ExecFuncBody config (setRewardConfigBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body - (.returned (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceFinal evmDec I rescale false) none) := by - refine ExecFuncBody.execBlockOK ?_ - change ExecBlock config (setRewardConfigBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - (.ok (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceFinal evmDec I rescale false)) - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfig_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigBodyStore I).insert "accrualScale" - (.int (Int.ofNat baseWord.toNat)) } - evmBase (.var "token") = .ok (setRewardConfigTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigBodyStore_token] - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess htokenExpr (by simp [evalExpr?, pure]) (by rfl) - hcallDec hdecDec) ?_ - have hpowArgs : - evalExprs? config (setRewardConfigWrapperAfterDecimalsFrame I baseWord decNat) evmDec - [.var "tokenDecimals"] = .ok [.int (Int.ofNat decNat)] := by - simp only [setRewardConfigWrapperAfterDecimalsFrame, evalExprs?, evalExpr?, - EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigWrapperAfterDecimalsFrame I baseWord decNat) - (evm := evmDec) (calleeEvm := evmDec) - (name := "pow10") (retVar := "tokenScale256") (args := [.var "tokenDecimals"]) - (argVals := [.int (Int.ofNat decNat)]) - (callee := pow10Function) (locals := pow10Store decNat) - (calleeSolm := { contract := contract, locals := pow10Store decNat }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hpowArgs lookupCallable_pow10 (bindParams_pow10 decNat) - (by simpa using pow10FunctionBodyReturns_le77 evmDec hle77)) ?_ - have hsafeArgs : - evalExprs? config (setRewardConfigWrapperAfterPow10Frame I baseWord decNat) evmDec - [.var "tokenScale256"] = .ok [.int (Int.ofNat ((10 : ℕ) ^ decNat))] := by - simp only [setRewardConfigWrapperAfterPow10Frame, setRewardConfigWrapperAfterDecimalsFrame, - resumeAfterInternalCall, evalExprs?, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigWrapperAfterPow10Frame I baseWord decNat) - (evm := evmDec) (calleeEvm := evmDec) - (name := "safe64") (retVar := "tokenScale") (args := [.var "tokenScale256"]) - (argVals := [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - (callee := safe64Function) (locals := safe64Store ((10 : ℕ) ^ decNat)) - (calleeSolm := { contract := contract, locals := safe64Store ((10 : ℕ) ^ decNat) }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hsafeArgs lookupCallable_safe64 (bindParams_safe64 ((10 : ℕ) ^ decNat)) - (by simpa using safe64FunctionBodyReturns_le evmDec hsafe64)) ?_ - have hcond : - evalExpr? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) evmDec - (.binary .gt (.var "accrualScale") (.var "tokenScale")) = .ok (.bool true) := by - have hgtInt : (10 : ℤ) ^ decNat < (baseWord.toNat : ℤ) := by - exact_mod_cast hgt - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - repeat rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigWrapperAfterSafe64Frame_accrualScale, - setRewardConfigWrapperAfterSafe64Frame_tokenScale] - simpa [evalBinaryOp?] using hgtInt - refine ExecBlock.consNormal (ExecStmt.iteTrue hcond ?_) ExecBlock.nil - have htokenRhs : - evalExpr? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) evmDec - (.var "token") = .ok (setRewardConfigTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setRewardConfigWrapperAfterSafe64Frame_token] - refine ExecBlock.consNormal - (ExecStmt.assign htokenRhs - (setRewardConfigWrapperAssign_token_afterSafe64 evmDec I baseWord decNat hcanonToken)) ?_ - have hrescaleRhs : - evalExpr? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceAfterToken evmDec I) - (.binary .div (.var "accrualScale") (.var "tokenScale")) = - .ok (.int (Int.ofNat rescale.toNat)) := by - rw [hrescale] - have hpowPos : (10 : ℕ) ^ decNat ≠ 0 := by positivity - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - repeat rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigWrapperAfterSafe64Frame_accrualScale, - setRewardConfigWrapperAfterSafe64Frame_tokenScale] - simp [evalBinaryOp?, hpowPos] - refine ExecBlock.consNormal - (ExecStmt.assign hrescaleRhs - (setRewardConfigWrapperAssign_rescale_afterSafe64 evmDec I baseWord rescale decNat)) ?_ - have hfalseRhs : - evalExpr? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceAfterRescale evmDec I rescale) (.boolLit false) = - .ok (.bool false) := by - simp [evalExpr?, pure] - refine ExecBlock.consNormal - (ExecStmt.assign hfalseRhs - (setRewardConfigWrapperAssign_shouldUpscale_false_afterSafe64 - evmDec I baseWord rescale decNat)) ?_ - have hmultRhs : - evalExpr? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceAfterShouldUpscale evmDec I rescale false) - (.var "multiplier") = .ok setRewardConfigMultiplierValue := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setRewardConfigWrapperAfterSafe64Frame_multiplier] - rw [setRewardConfigWrapperSourceFinal_false] - exact ExecBlock.consNormal - (ExecStmt.assign hmultRhs - (setRewardConfigWrapperAssign_multiplier_afterSafe64_state - (setRewardConfigWrapperSourceAfterShouldUpscale evmDec I rescale false) I - baseWord decNat)) - ExecBlock.nil - -set_option maxHeartbeats 1000000 in -theorem setRewardConfigFunctionBodyReturns_upscale - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseWord rescale : UInt256} {decNat : ℕ} - (hcanonToken : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : - config.externalABI.decode? "baseAccrualScale" baseOut = - some [.int (Int.ofNat baseWord.toNat)]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ decNat ≤ 2 ^ 64 - 1) - (hrescale : rescale.toNat = (10 : ℕ) ^ decNat / baseWord.toNat) - (hle : baseWord.toNat ≤ (10 : ℕ) ^ decNat) - (hbaseNZ : baseWord.toNat ≠ 0) : - ExecFuncBody config (setRewardConfigBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body - (.returned (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceFinal evmDec I rescale true) none) := by - refine ExecFuncBody.execBlockOK ?_ - change ExecBlock config (setRewardConfigBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - (.ok (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceFinal evmDec I rescale true)) - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfig_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigBodyStore I).insert "accrualScale" - (.int (Int.ofNat baseWord.toNat)) } - evmBase (.var "token") = .ok (setRewardConfigTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigBodyStore_token] - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess htokenExpr (by simp [evalExpr?, pure]) (by rfl) - hcallDec hdecDec) ?_ - have hpowArgs : - evalExprs? config (setRewardConfigWrapperAfterDecimalsFrame I baseWord decNat) evmDec - [.var "tokenDecimals"] = .ok [.int (Int.ofNat decNat)] := by - simp only [setRewardConfigWrapperAfterDecimalsFrame, evalExprs?, evalExpr?, - EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigWrapperAfterDecimalsFrame I baseWord decNat) - (evm := evmDec) (calleeEvm := evmDec) - (name := "pow10") (retVar := "tokenScale256") (args := [.var "tokenDecimals"]) - (argVals := [.int (Int.ofNat decNat)]) - (callee := pow10Function) (locals := pow10Store decNat) - (calleeSolm := { contract := contract, locals := pow10Store decNat }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hpowArgs lookupCallable_pow10 (bindParams_pow10 decNat) - (by simpa using pow10FunctionBodyReturns_le77 evmDec hle77)) ?_ - have hsafeArgs : - evalExprs? config (setRewardConfigWrapperAfterPow10Frame I baseWord decNat) evmDec - [.var "tokenScale256"] = .ok [.int (Int.ofNat ((10 : ℕ) ^ decNat))] := by - simp only [setRewardConfigWrapperAfterPow10Frame, setRewardConfigWrapperAfterDecimalsFrame, - resumeAfterInternalCall, evalExprs?, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigWrapperAfterPow10Frame I baseWord decNat) - (evm := evmDec) (calleeEvm := evmDec) - (name := "safe64") (retVar := "tokenScale") (args := [.var "tokenScale256"]) - (argVals := [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - (callee := safe64Function) (locals := safe64Store ((10 : ℕ) ^ decNat)) - (calleeSolm := { contract := contract, locals := safe64Store ((10 : ℕ) ^ decNat) }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hsafeArgs lookupCallable_safe64 (bindParams_safe64 ((10 : ℕ) ^ decNat)) - (by simpa using safe64FunctionBodyReturns_le evmDec hsafe64)) ?_ - have hcond : - evalExpr? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) evmDec - (.binary .gt (.var "accrualScale") (.var "tokenScale")) = .ok (.bool false) := by - have hnotNat : ¬ (10 : ℕ) ^ decNat < baseWord.toNat := by omega - have hnotInt : ¬ (10 : ℤ) ^ decNat < (baseWord.toNat : ℤ) := by - intro hlt - exact hnotNat (by exact_mod_cast hlt) - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - repeat rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigWrapperAfterSafe64Frame_accrualScale, - setRewardConfigWrapperAfterSafe64Frame_tokenScale] - simpa [evalBinaryOp?] using hnotInt - refine ExecBlock.consNormal (ExecStmt.iteFalse hcond ?_) ExecBlock.nil - have htokenRhs : - evalExpr? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) evmDec - (.var "token") = .ok (setRewardConfigTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setRewardConfigWrapperAfterSafe64Frame_token] - refine ExecBlock.consNormal - (ExecStmt.assign htokenRhs - (setRewardConfigWrapperAssign_token_afterSafe64 evmDec I baseWord decNat hcanonToken)) ?_ - have hrescaleRhs : - evalExpr? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceAfterToken evmDec I) - (.binary .div (.var "tokenScale") (.var "accrualScale")) = - .ok (.int (Int.ofNat rescale.toNat)) := by - rw [hrescale] - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - repeat rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigWrapperAfterSafe64Frame_accrualScale, - setRewardConfigWrapperAfterSafe64Frame_tokenScale] - simp [evalBinaryOp?, hbaseNZ] - refine ExecBlock.consNormal - (ExecStmt.assign hrescaleRhs - (setRewardConfigWrapperAssign_rescale_afterSafe64 evmDec I baseWord rescale decNat)) ?_ - have htrueRhs : - evalExpr? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceAfterRescale evmDec I rescale) (.boolLit true) = - .ok (.bool true) := by - simp [evalExpr?, pure] - refine ExecBlock.consNormal - (ExecStmt.assign htrueRhs - (setRewardConfigWrapperAssign_shouldUpscale_true_afterSafe64 - evmDec I baseWord rescale decNat)) ?_ - have hmultRhs : - evalExpr? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceAfterShouldUpscale evmDec I rescale true) - (.var "multiplier") = .ok setRewardConfigMultiplierValue := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setRewardConfigWrapperAfterSafe64Frame_multiplier] - rw [setRewardConfigWrapperSourceFinal_true] - exact ExecBlock.consNormal - (ExecStmt.assign hmultRhs - (setRewardConfigWrapperAssign_multiplier_afterSafe64_state - (setRewardConfigWrapperSourceAfterShouldUpscale evmDec I rescale true) I - baseWord decNat)) - ExecBlock.nil - -set_option maxHeartbeats 1000000 in -theorem setRewardConfigFunctionBodyReverts_upscaleZero - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseWord : UInt256} {decNat : ℕ} - (hcanonToken : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : - config.externalABI.decode? "baseAccrualScale" baseOut = - some [.int (Int.ofNat baseWord.toNat)]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ decNat ≤ 2 ^ 64 - 1) - (hbase0 : baseWord.toNat = 0) : - ExecFuncBody config (setRewardConfigBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_setRewardConfig_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfig_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigBodyStore I).insert "accrualScale" - (.int (Int.ofNat baseWord.toNat)) } - evmBase (.var "token") = .ok (setRewardConfigTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigBodyStore_token] - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess htokenExpr (by simp [evalExpr?, pure]) (by rfl) - hcallDec hdecDec) ?_ - have hpowArgs : - evalExprs? config (setRewardConfigWrapperAfterDecimalsFrame I baseWord decNat) evmDec - [.var "tokenDecimals"] = .ok [.int (Int.ofNat decNat)] := by - simp only [setRewardConfigWrapperAfterDecimalsFrame, evalExprs?, evalExpr?, - EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigWrapperAfterDecimalsFrame I baseWord decNat) - (evm := evmDec) (calleeEvm := evmDec) - (name := "pow10") (retVar := "tokenScale256") (args := [.var "tokenDecimals"]) - (argVals := [.int (Int.ofNat decNat)]) - (callee := pow10Function) (locals := pow10Store decNat) - (calleeSolm := { contract := contract, locals := pow10Store decNat }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hpowArgs lookupCallable_pow10 (bindParams_pow10 decNat) - (by simpa using pow10FunctionBodyReturns_le77 evmDec hle77)) ?_ - have hsafeArgs : - evalExprs? config (setRewardConfigWrapperAfterPow10Frame I baseWord decNat) evmDec - [.var "tokenScale256"] = .ok [.int (Int.ofNat ((10 : ℕ) ^ decNat))] := by - simp only [setRewardConfigWrapperAfterPow10Frame, setRewardConfigWrapperAfterDecimalsFrame, - resumeAfterInternalCall, evalExprs?, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigWrapperAfterPow10Frame I baseWord decNat) - (evm := evmDec) (calleeEvm := evmDec) - (name := "safe64") (retVar := "tokenScale") (args := [.var "tokenScale256"]) - (argVals := [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - (callee := safe64Function) (locals := safe64Store ((10 : ℕ) ^ decNat)) - (calleeSolm := { contract := contract, locals := safe64Store ((10 : ℕ) ^ decNat) }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hsafeArgs lookupCallable_safe64 (bindParams_safe64 ((10 : ℕ) ^ decNat)) - (by simpa using safe64FunctionBodyReturns_le evmDec hsafe64)) ?_ - have hcond : - evalExpr? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) evmDec - (.binary .gt (.var "accrualScale") (.var "tokenScale")) = .ok (.bool false) := by - have hnotNat : ¬ (10 : ℕ) ^ decNat < baseWord.toNat := by - rw [hbase0] - exact Nat.not_lt_zero _ - have hnotInt : ¬ (10 : ℤ) ^ decNat < (baseWord.toNat : ℤ) := by - intro hlt - exact hnotNat (by exact_mod_cast hlt) - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - repeat rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigWrapperAfterSafe64Frame_accrualScale, - setRewardConfigWrapperAfterSafe64Frame_tokenScale] - simpa [evalBinaryOp?] using hnotInt - refine ExecBlock.consRevert (ExecStmt.iteFalse hcond ?_) - have htokenRhs : - evalExpr? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) evmDec - (.var "token") = .ok (setRewardConfigTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setRewardConfigWrapperAfterSafe64Frame_token] - refine ExecBlock.consNormal - (ExecStmt.assign htokenRhs - (setRewardConfigWrapperAssign_token_afterSafe64 evmDec I baseWord decNat hcanonToken)) ?_ - have hrescaleRhs : - evalExpr? config (setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (setRewardConfigWrapperSourceAfterToken evmDec I) - (.binary .div (.var "tokenScale") (.var "accrualScale")) = .revert := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - repeat rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigWrapperAfterSafe64Frame_accrualScale, - setRewardConfigWrapperAfterSafe64Frame_tokenScale] - simp [evalBinaryOp?, hbase0] - exact ExecBlock.consRevert (ExecStmt.assignExprRevert hrescaleRhs) - -theorem cometRewardsSetRewardConfigBodyReturns_downscale - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseWord rescale : UInt256} {decNat : ℕ} - (hcanonToken : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : - config.externalABI.decode? "baseAccrualScale" baseOut = - some [.int (Int.ofNat baseWord.toNat)]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ decNat ≤ 2 ^ 64 - 1) - (hrescale : rescale.toNat = baseWord.toNat / (10 : ℕ) ^ decNat) - (hgt : (10 : ℕ) ^ decNat < baseWord.toNat) : - ExecTransitionBody config contract evm (setRewardConfigStore I) - setRewardConfigTransition.body - (.returned (resumeAfterInternalCall (setRewardConfigFrame evm I) "_set" none) - (setRewardConfigWrapperSourceFinal evmDec I rescale false) none) := by - refine ExecFuncBody.execBlockOK ?_ - have hstmt : - ExecStmt config (setRewardConfigFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", (.intLit factorScale)] "_set") - (.ok (resumeAfterInternalCall (setRewardConfigFrame evm I) "_set" none) - (setRewardConfigWrapperSourceFinal evmDec I rescale false)) := by - exact internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigFrame evm I) (evm := evm) - (calleeEvm := setRewardConfigWrapperSourceFinal evmDec I rescale false) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", (.intLit factorScale)]) - (argVals := setRewardConfigArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigBodyStore I) - (calleeSolm := setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (value := none) - (evalExprs_setRewardConfig_args evm I) - (by simpa [setRewardConfigFrame] using - lookupCallable_setRewardConfigWithMultiplierBody_from_setRewardConfig) - (bindParams_setRewardConfigWithMultiplier_from_setRewardConfig I) - (by - simpa [setRewardConfigFrame, setRewardConfigBodyFrame] using - setRewardConfigFunctionBodyReturns_downscale - evm evmBase evmDec I hcanonToken hgov htoken hcallBase hdecBase hcallDec hdecDec - hle77 hsafe64 hrescale hgt) - simpa [setRewardConfigTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigStore I) hsize)).run - (ExecBlock.consNormal hstmt ExecBlock.nil) - -theorem cometRewardsSetRewardConfigBodyReturns_upscale - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseWord rescale : UInt256} {decNat : ℕ} - (hcanonToken : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : - config.externalABI.decode? "baseAccrualScale" baseOut = - some [.int (Int.ofNat baseWord.toNat)]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ decNat ≤ 2 ^ 64 - 1) - (hrescale : rescale.toNat = (10 : ℕ) ^ decNat / baseWord.toNat) - (hle : baseWord.toNat ≤ (10 : ℕ) ^ decNat) - (hbaseNZ : baseWord.toNat ≠ 0) : - ExecTransitionBody config contract evm (setRewardConfigStore I) - setRewardConfigTransition.body - (.returned (resumeAfterInternalCall (setRewardConfigFrame evm I) "_set" none) - (setRewardConfigWrapperSourceFinal evmDec I rescale true) none) := by - refine ExecFuncBody.execBlockOK ?_ - have hstmt : - ExecStmt config (setRewardConfigFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", (.intLit factorScale)] "_set") - (.ok (resumeAfterInternalCall (setRewardConfigFrame evm I) "_set" none) - (setRewardConfigWrapperSourceFinal evmDec I rescale true)) := by - exact internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigFrame evm I) (evm := evm) - (calleeEvm := setRewardConfigWrapperSourceFinal evmDec I rescale true) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", (.intLit factorScale)]) - (argVals := setRewardConfigArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigBodyStore I) - (calleeSolm := setRewardConfigWrapperAfterSafe64Frame I baseWord decNat) - (value := none) - (evalExprs_setRewardConfig_args evm I) - (by simpa [setRewardConfigFrame] using - lookupCallable_setRewardConfigWithMultiplierBody_from_setRewardConfig) - (bindParams_setRewardConfigWithMultiplier_from_setRewardConfig I) - (by - simpa [setRewardConfigFrame, setRewardConfigBodyFrame] using - setRewardConfigFunctionBodyReturns_upscale - evm evmBase evmDec I hcanonToken hgov htoken hcallBase hdecBase hcallDec hdecDec - hle77 hsafe64 hrescale hle hbaseNZ) - simpa [setRewardConfigTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigStore I) hsize)).run - (ExecBlock.consNormal hstmt ExecBlock.nil) - -theorem cometRewardsSetRewardConfigBodyReverts_upscaleZero - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseWord : UInt256} {decNat : ℕ} - (hcanonToken : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : - config.externalABI.decode? "baseAccrualScale" baseOut = - some [.int (Int.ofNat baseWord.toNat)]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ decNat ≤ 2 ^ 64 - 1) - (hbase0 : baseWord.toNat = 0) : - ExecTransitionBody config contract evm (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", (.intLit factorScale)] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", (.intLit factorScale)]) - (argVals := setRewardConfigArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigBodyStore I) - (evalExprs_setRewardConfig_args evm I) - (by simpa [setRewardConfigFrame] using - lookupCallable_setRewardConfigWithMultiplierBody_from_setRewardConfig) - (bindParams_setRewardConfigWithMultiplier_from_setRewardConfig I) - (by - simpa [setRewardConfigFrame, setRewardConfigBodyFrame] using - setRewardConfigFunctionBodyReverts_upscaleZero - evm evmBase evmDec I hcanonToken hgov htoken hcallBase hdecBase hcallDec hdecDec - hle77 hsafe64 hbase0) - simpa [setRewardConfigTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigBodyReverts_auth - (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask ≠ - solcSourceWord evm.executionEnv) : - ExecTransitionBody config contract evm (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", (.intLit factorScale)] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", (.intLit factorScale)]) - (argVals := setRewardConfigArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigBodyStore I) - (evalExprs_setRewardConfig_args evm I) - (by simpa [setRewardConfigFrame] using - lookupCallable_setRewardConfigWithMultiplierBody_from_setRewardConfig) - (bindParams_setRewardConfigWithMultiplier_from_setRewardConfig I) - (by - simpa [setRewardConfigFrame, setRewardConfigBodyFrame] using - setRewardConfigFunctionBodyReverts_auth evm I hgov) - simpa [setRewardConfigTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigBodyReverts_configured - (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask ≠ ⟨0⟩) : - ExecTransitionBody config contract evm (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", (.intLit factorScale)] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", (.intLit factorScale)]) - (argVals := setRewardConfigArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigBodyStore I) - (evalExprs_setRewardConfig_args evm I) - (by simpa [setRewardConfigFrame] using - lookupCallable_setRewardConfigWithMultiplierBody_from_setRewardConfig) - (bindParams_setRewardConfigWithMultiplier_from_setRewardConfig I) - (by - simpa [setRewardConfigFrame, setRewardConfigBodyFrame] using - setRewardConfigFunctionBodyReverts_configured evm I hgov htoken) - simpa [setRewardConfigTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigBodyReverts_baseCallFailure - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcall : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (false, evm', out) false) : - ExecTransitionBody config contract evm (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", (.intLit factorScale)] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", (.intLit factorScale)]) - (argVals := setRewardConfigArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigBodyStore I) - (evalExprs_setRewardConfig_args evm I) - (by simpa [setRewardConfigFrame] using - lookupCallable_setRewardConfigWithMultiplierBody_from_setRewardConfig) - (bindParams_setRewardConfigWithMultiplier_from_setRewardConfig I) - (by - simpa [setRewardConfigFrame, setRewardConfigBodyFrame] using - setRewardConfigFunctionBodyReverts_baseCallFailure evm evm' I hgov htoken hcall) - simpa [setRewardConfigTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigBodyReverts_baseDecodeFailure - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcall : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evm', out) false) - (hdec : config.externalABI.decode? "baseAccrualScale" out = none) : - ExecTransitionBody config contract evm (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", (.intLit factorScale)] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", (.intLit factorScale)]) - (argVals := setRewardConfigArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigBodyStore I) - (evalExprs_setRewardConfig_args evm I) - (by simpa [setRewardConfigFrame] using - lookupCallable_setRewardConfigWithMultiplierBody_from_setRewardConfig) - (bindParams_setRewardConfigWithMultiplier_from_setRewardConfig I) - (by - simpa [setRewardConfigFrame, setRewardConfigBodyFrame] using - setRewardConfigFunctionBodyReverts_baseDecodeFailure evm evm' I hgov htoken hcall hdec) - simpa [setRewardConfigTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigBodyReverts_decimalsCallFailure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (false, evmDec, decOut) false) : - ExecTransitionBody config contract evm (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", (.intLit factorScale)] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", (.intLit factorScale)]) - (argVals := setRewardConfigArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigBodyStore I) - (evalExprs_setRewardConfig_args evm I) - (by simpa [setRewardConfigFrame] using - lookupCallable_setRewardConfigWithMultiplierBody_from_setRewardConfig) - (bindParams_setRewardConfigWithMultiplier_from_setRewardConfig I) - (by - simpa [setRewardConfigFrame, setRewardConfigBodyFrame] using - setRewardConfigFunctionBodyReverts_decimalsCallFailure - evm evmBase evmDec I hgov htoken hcallBase hdecBase hcallDec) - simpa [setRewardConfigTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigBodyReverts_decimalsDecodeFailure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : config.externalABI.decode? "decimals" decOut = none) : - ExecTransitionBody config contract evm (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", (.intLit factorScale)] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", (.intLit factorScale)]) - (argVals := setRewardConfigArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigBodyStore I) - (evalExprs_setRewardConfig_args evm I) - (by simpa [setRewardConfigFrame] using - lookupCallable_setRewardConfigWithMultiplierBody_from_setRewardConfig) - (bindParams_setRewardConfigWithMultiplier_from_setRewardConfig I) - (by - simpa [setRewardConfigFrame, setRewardConfigBodyFrame] using - setRewardConfigFunctionBodyReverts_decimalsDecodeFailure - evm evmBase evmDec I hgov htoken hcallBase hdecBase hcallDec hdecDec) - simpa [setRewardConfigTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigBodyReverts_pow10Failure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} {decNat : ℕ} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hgt : 77 < decNat) : - ExecTransitionBody config contract evm (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", (.intLit factorScale)] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", (.intLit factorScale)]) - (argVals := setRewardConfigArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigBodyStore I) - (evalExprs_setRewardConfig_args evm I) - (by simpa [setRewardConfigFrame] using - lookupCallable_setRewardConfigWithMultiplierBody_from_setRewardConfig) - (bindParams_setRewardConfigWithMultiplier_from_setRewardConfig I) - (by - simpa [setRewardConfigFrame, setRewardConfigBodyFrame] using - setRewardConfigFunctionBodyReverts_pow10Failure - evm evmBase evmDec I hgov htoken hcallBase hdecBase hcallDec hdecDec hgt) - simpa [setRewardConfigTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigBodyReverts_safe64Failure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} {decNat : ℕ} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hgt64 : 2 ^ 64 - 1 < (10 : ℕ) ^ decNat) : - ExecTransitionBody config contract evm (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", (.intLit factorScale)] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", (.intLit factorScale)]) - (argVals := setRewardConfigArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigBodyStore I) - (evalExprs_setRewardConfig_args evm I) - (by simpa [setRewardConfigFrame] using - lookupCallable_setRewardConfigWithMultiplierBody_from_setRewardConfig) - (bindParams_setRewardConfigWithMultiplier_from_setRewardConfig I) - (by - simpa [setRewardConfigFrame, setRewardConfigBodyFrame] using - setRewardConfigFunctionBodyReverts_safe64Failure - evm evmBase evmDec I hgov htoken hcallBase hdecBase hcallDec hdecDec - hle77 hgt64) - simpa [setRewardConfigTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsDecode_setRewardConfig_ok {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hcanonToken : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (setRewardConfigTransition.params.map Param.name) - (transitionSignature setRewardConfigTransition).paramTypes I.calldata = - some (setRewardConfigStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "token"] [addr, addr] - I.calldata = _ - simpa [config, setRewardConfigStore, setRewardConfigCometValue, setRewardConfigTokenValue, - setRewardConfigCometWord, setRewardConfigTokenWord, calldataWord] - using decodeCalldata_address_address_ok (cd := I.calldata) (x := "comet") (y := "token") - hsz68 hbig hcanonComet hcanonToken - -theorem cometRewardsDecode_setRewardConfig_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 68) : - decodeCalldataWithMode config.abiDecodeMode (setRewardConfigTransition.params.map Param.name) - (transitionSignature setRewardConfigTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "token"] [addr, addr] - I.calldata = none - simpa [config, addr] using decodeCalldata_address_address_none_short - (cd := I.calldata) (x := "comet") (y := "token") hsz4 hshort - -theorem cometRewardsDecode_setRewardConfig_none_noncanon_comet {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hncComet : ¬ (setRewardConfigCometWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (setRewardConfigTransition.params.map Param.name) - (transitionSignature setRewardConfigTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "token"] [addr, addr] - I.calldata = none - simpa [config, addr, setRewardConfigCometWord, calldataWord] - using decodeCalldata_address_address_none_noncanon0 - (cd := I.calldata) (x := "comet") (y := "token") hsz68 hbig hncComet - -theorem cometRewardsDecode_setRewardConfig_none_noncanon_token {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hncToken : ¬ (setRewardConfigTokenWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (setRewardConfigTransition.params.map Param.name) - (transitionSignature setRewardConfigTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "token"] [addr, addr] - I.calldata = none - simpa [config, addr, setRewardConfigCometWord, setRewardConfigTokenWord, calldataWord] - using decodeCalldata_address_address_none_noncanon1 - (cd := I.calldata) (x := "comet") (y := "token") hsz68 hbig hcanonComet hncToken - -theorem cometRewardsDecode_setRewardConfig_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (setRewardConfigTransition.params.map Param.name) - (transitionSignature setRewardConfigTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "token"] [addr, addr] - I.calldata = none - simpa [config, addr] using decodeCalldata_address_address_none_huge - (cd := I.calldata) (x := "comet") (y := "token") hbig - -theorem cometRewardsSetRewardConfigSelector_size {I : ExecutionEnv} - (hsel : selIs I (cometRewardsSelBytes 7)) : - 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (cometRewardsSelBytes 7) rfl hsel - -theorem cometRewardsDispatch_setRewardConfig {cd : ByteArray} - (hsel : (cometRewardsSelBytes 7 == cd.extract 0 4) = true) : - dispatchMsg contract cd = some setRewardConfigTransition := by - refine dispatchMsg_eq_some_of_split - (pre := [claimTransition, claimToTransition, getRewardOwedTransition, governorTransition, - rewardConfigTransition, rewardsClaimedTransition]) - (post := [setRewardConfigWithMultiplierTransition, setRewardsClaimedTransition, - transferGovernorTransition, withdrawTokenTransition]) - rfl rfl ?_ (by rw [selectorOf, setRewardConfigSelectorBytes]; exact hsel) - have hcd : cd.extract 0 4 = cometRewardsSelBytes 7 := - (byteArray_eq_of_beq hsel).symm - intro t ht - simp only [List.mem_cons, List.not_mem_nil, or_false] at ht - rcases ht with rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, claimSelectorBytes, hcd] - decide - · rw [selectorOf, claimToSelectorBytes, hcd] - decide - · rw [selectorOf, getRewardOwedSelectorBytes, hcd] - decide - · rw [selectorOf, governorSelectorBytes, hcd] - decide - · rw [selectorOf, rewardConfigSelectorBytes, hcd] - decide - · rw [selectorOf, rewardsClaimedSelectorBytes, hcd] - decide - -theorem cometRewardsSetRewardConfigCalldataCheckOk {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hhi : I.calldata.size < 2 ^ 255 + 4) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨0⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨0⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - simpa using - solcCalldataStaticLenCheckOk (sz := I.calldata.size) (words := 2) - (by simpa using hsz68) hhi hsize - -theorem cometRewardsSetRewardConfigCalldataCheckShort {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hshort : I.calldata.size < 68) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 hsz4 hsize] - simpa using - solcCalldataStaticLenCheckShort (sz := I.calldata.size) (words := 2) - hsz4 (by simpa using hshort) hsize (by norm_num) - -theorem cometRewardsSetRewardConfigCalldataCheckHuge {I : ExecutionEnv} - (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨64⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - simpa using - solcCalldataStaticLenCheckHuge (sz := I.calldata.size) (words := 2) - hbig hsize (by norm_num) - -theorem cometRewardsSetRewardConfigX_shortarg - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz4 : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hshort : I.calldata.size < 68) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsSetRewardConfigCalldataCheckShort (I := I) hsz4 hsize hshort - obtain ⟨_, _, rd1009⟩ := hreach - have rd1012 := evm_run rd1009 with [jumpdest, pop, swap1, callvalue] - rw [hwv] at rd1012 - have rd1024 := evm_run rd1012 with [ - push2 ⟨797⟩, jumpiNT (by decide), - dup3, push1 ⟨3⟩, not, calldatasize, add, slt] - rw [hslt] at rd1024 - exact evm_run rd1024 with [ - push2 ⟨797⟩, jumpiT (by decide) (by native_decide), - jumpdest, dup4, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsSetRewardConfigX_hugearg - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsSetRewardConfigCalldataCheckHuge (I := I) hsize hbig - obtain ⟨_, _, rd1009⟩ := hreach - have rd1012 := evm_run rd1009 with [jumpdest, pop, swap1, callvalue] - rw [hwv] at rd1012 - have rd1024 := evm_run rd1012 with [ - push2 ⟨797⟩, jumpiNT (by decide), - dup3, push1 ⟨3⟩, not, calldatasize, add, slt] - rw [hslt] at rd1024 - exact evm_run rd1024 with [ - push2 ⟨797⟩, jumpiT (by decide) (by native_decide), - jumpdest, dup4, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_dec1044_args - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1044⟩ - [setRewardConfigTokenWord I, ⟨224⟩, setRewardConfigCometWord I, ⟨4⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt := cometRewardsSetRewardConfigCalldataCheckOk (I := I) hsz68 hsize hhi - obtain ⟨_, _, rd1009⟩ := hreach - have rd1012 := evm_run rd1009 with [jumpdest, pop, swap1, callvalue] - rw [hwv] at rd1012 - have rd1024 := evm_run rd1012 with [ - push2 ⟨797⟩, jumpiNT (by decide), - dup3, push1 ⟨3⟩, not, calldatasize, add, slt] - rw [hslt] at rd1024 - have rd2831 := evm_run rd1024 with [ - push2 ⟨797⟩, jumpiNT (by decide), push2 ⟨1035⟩, push2 ⟨2831⟩, - jump (by native_decide)] - have rd1035 := evm_run rd2831 with [ - jumpdest, push1 ⟨4⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, - dup3, and, dup3, sub, push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land (setRewardConfigCometWord I) solcAddrMask = - setRewardConfigCometWord I := by - exact solcAddrMask_clean (by - simpa [setRewardConfigCometWord, calldataWord] using hcanon0) - have hclean' : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32) := by - simpa [setRewardConfigCometWord, calldataWord] using hclean - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean'] - exact u256_sub_self _), - jump (by native_decide)] - have rd2853 := evm_run rd1035 with [ - jumpdest, swap1, push2 ⟨1044⟩, push2 ⟨2853⟩, jump (by native_decide)] - exact ⟨_, _, evm_run rd2853 with [ - jumpdest, push1 ⟨36⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, - dup3, and, dup3, sub, push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land (setRewardConfigTokenWord I) solcAddrMask = - setRewardConfigTokenWord I := by - exact solcAddrMask_clean (by - simpa [setRewardConfigTokenWord, calldataWord] using hcanon1) - have hclean' : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32) := by - simpa [setRewardConfigTokenWord, calldataWord] using hclean - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean'] - exact u256_sub_self _), - jump (by native_decide)]⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_noncanon_comet - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hnc : UInt256.eq (setRewardConfigCometWord I) - (UInt256.land (setRewardConfigCometWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsSetRewardConfigCalldataCheckOk (I := I) hsz68 hsize hhi - obtain ⟨_, _, rd1009⟩ := hreach - have rd1012 := evm_run rd1009 with [jumpdest, pop, swap1, callvalue] - rw [hwv] at rd1012 - have rd1024 := evm_run rd1012 with [ - push2 ⟨797⟩, jumpiNT (by decide), - dup3, push1 ⟨3⟩, not, calldatasize, add, slt] - rw [hslt] at rd1024 - have rd2831 := evm_run rd1024 with [ - push2 ⟨797⟩, jumpiNT (by decide), push2 ⟨1035⟩, push2 ⟨2831⟩, - jump (by native_decide)] - exact evm_run rd2831 with [ - jumpdest, push1 ⟨4⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, - dup3, and, dup3, sub, push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hraw : - UInt256.eq - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - (UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask) = ⟨1⟩ := by - rw [← heq] - exact uInt256_eq_self _ - have hclean : - UInt256.eq (setRewardConfigCometWord I) - (UInt256.land (setRewardConfigCometWord I) solcAddrMask) = ⟨1⟩ := by - simpa [setRewardConfigCometWord, calldataWord] using hraw - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_noncanon_token - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hnc : UInt256.eq (setRewardConfigTokenWord I) - (UInt256.land (setRewardConfigTokenWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsSetRewardConfigCalldataCheckOk (I := I) hsz68 hsize hhi - obtain ⟨_, _, rd1009⟩ := hreach - have rd1012 := evm_run rd1009 with [jumpdest, pop, swap1, callvalue] - rw [hwv] at rd1012 - have rd1024 := evm_run rd1012 with [ - push2 ⟨797⟩, jumpiNT (by decide), - dup3, push1 ⟨3⟩, not, calldatasize, add, slt] - rw [hslt] at rd1024 - have rd2831 := evm_run rd1024 with [ - push2 ⟨797⟩, jumpiNT (by decide), push2 ⟨1035⟩, push2 ⟨2831⟩, - jump (by native_decide)] - have rd1035 := evm_run rd2831 with [ - jumpdest, push1 ⟨4⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, - dup3, and, dup3, sub, push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32) := by - have hclean' : - UInt256.land (setRewardConfigCometWord I) solcAddrMask = - setRewardConfigCometWord I := by - exact solcAddrMask_clean (by - simpa [setRewardConfigCometWord, calldataWord] using hcanon0) - simpa [setRewardConfigCometWord, calldataWord] using hclean' - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean] - exact u256_sub_self _), - jump (by native_decide)] - have rd2853 := evm_run rd1035 with [ - jumpdest, swap1, push2 ⟨1044⟩, push2 ⟨2853⟩, jump (by native_decide)] - exact evm_run rd2853 with [ - jumpdest, push1 ⟨36⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, - dup3, and, dup3, sub, push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hraw : - UInt256.eq - (uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32)) - (UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32)) - solcAddrMask) = ⟨1⟩ := by - rw [← heq] - exact uInt256_eq_self _ - have hclean : - UInt256.eq (setRewardConfigTokenWord I) - (UInt256.land (setRewardConfigTokenWord I) solcAddrMask) = ⟨1⟩ := by - simpa [setRewardConfigTokenWord, calldataWord] using hraw - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_revert_auth - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I ≠ solcSourceWord I) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd1044⟩ := - cometRewardsSetRewardConfigX_dec1044_args - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hsz68 hsize hhi hcanon0 hcanon1 hreach - have rd1047 := evm_run rd1044 with [jumpdest, push1 ⟨0⟩] - obtain ⟨_, _, rd1048₀⟩ := rd1047.sload (by decide) (by evm_ov) - obtain ⟨_, _, rd1048⟩ : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨1048⟩ - [governorWord σ I, setRewardConfigTokenWord I, ⟨224⟩, - setRewardConfigCometWord I, ⟨4⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by simpa [governorWord] using rd1048₀⟩ - have rd1065₀ := evm_run rd1048 with [ - swap1, swap4, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, - swap4, swap1, swap2, dup5, and, caller, sub] - have rd1065 := rd1065₀ - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] at rd1065 - have hsub : UInt256.sub (solcSourceWord I) (governorReturnWord σ I) ≠ ⟨0⟩ := by - exact u256_sub_ne_zero_of_ne (by - intro h - exact hauth h.symm) - have hsub' : - UInt256.sub (UInt256.ofNat I.source.val) (UInt256.land solcAddrMask (governorWord σ I)) ≠ - ⟨0⟩ := by - simpa [solcSourceWord, governorReturnWord, u256_land_comm solcAddrMask (governorWord σ I)] - using hsub - exact evm_run rd1065 with [ - push2 ⟨1622⟩, jumpiT hsub' (by native_decide), - jumpdest, dup6, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - push4 ⟨431085831⟩, push1 ⟨227⟩, shl, dup2, - raw mstore 6 (solcReturnMem transferGovernorUnauthorizedSelector) - (UInt256.ofNat 5) (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - rfl) - (by decide) (by evm_ov), - caller, dup2, dup5, add, - raw mstore 3 (transferGovernorUnauthorizedMem (solcSourceWord I)) - (UInt256.ofNat 6) (by decide) mem_cost - (by - rw [show (⟨4⟩ : UInt256) + ⟨128⟩ = ⟨132⟩ from by decide, - show (⟨132⟩ : UInt256).toNat = 132 from by decide] - unfold transferGovernorUnauthorizedMem solcSourceWord - rfl) - (by decide) (by evm_ov), - push1 ⟨36⟩, swap1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_auth_ok - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1069⟩ - [setRewardConfigCometWord I, ⟨4⟩, ⟨224⟩, solcAddrMask, - setRewardConfigTokenWord I, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd1044⟩ := - cometRewardsSetRewardConfigX_dec1044_args - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hsz68 hsize hhi hcanon0 hcanon1 hreach - have rd1047 := evm_run rd1044 with [jumpdest, push1 ⟨0⟩] - obtain ⟨_, _, rd1048₀⟩ := rd1047.sload (by decide) (by evm_ov) - obtain ⟨_, _, rd1048⟩ : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨1048⟩ - [governorWord σ I, setRewardConfigTokenWord I, ⟨224⟩, - setRewardConfigCometWord I, ⟨4⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by simpa [governorWord] using rd1048₀⟩ - have rd1065₀ := evm_run rd1048 with [ - swap1, swap4, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, - swap4, swap1, swap2, dup5, and, caller, sub] - have rd1065 := rd1065₀ - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] at rd1065 - have hsub : - UInt256.sub (UInt256.ofNat I.source.val) (UInt256.land solcAddrMask (governorWord σ I)) = - ⟨0⟩ := by - have hgov : - UInt256.land solcAddrMask (governorWord σ I) = UInt256.ofNat I.source.val := by - simpa [governorReturnWord, solcSourceWord, - u256_land_comm solcAddrMask (governorWord σ I)] using hauth - rw [hgov] - exact u256_sub_self _ - rw [hsub] at rd1065 - exact ⟨_, _, evm_run rd1065 with [push2 ⟨1622⟩, jumpiNT (by decide)]⟩ - -def setRewardConfigWrapperAlreadyConfiguredSelector : UInt256 := - UInt256.shiftLeft (⟨977536693⟩ : UInt256) ⟨224⟩ - -noncomputable def setRewardConfigWrapperAlreadyConfiguredSelectorMem (comet : UInt256) : - ByteArray := - (UInt256.toByteArray setRewardConfigWrapperAlreadyConfiguredSelector).write 0 - (rewardConfigHashMem comet) 128 32 - -noncomputable def setRewardConfigWrapperAlreadyConfiguredMem (comet : UInt256) : ByteArray := - (UInt256.toByteArray comet).write 0 - (setRewardConfigWrapperAlreadyConfiguredSelectorMem comet) 132 32 - -set_option maxHeartbeats 10000000 in -theorem cometRewardsSetRewardConfigX_revert_configured - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (htoken : UInt256.land (solcSlotWord σ I (setRewardConfigSlotOf I)) solcAddrMask ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd1069⟩ := - cometRewardsSetRewardConfigX_auth_ok - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hsz68 hsize hhi hcanon0 hcanon1 hauth hreach - have hcleanComet : - UInt256.land (setRewardConfigCometWord I) solcAddrMask = - setRewardConfigCometWord I := by - exact solcAddrMask_clean (by - simpa [setRewardConfigCometWord, calldataWord] using hcanon0) - have hcleanCometLeft : - UInt256.land solcAddrMask (setRewardConfigCometWord I) = - setRewardConfigCometWord I := by - rw [u256_land_comm solcAddrMask (setRewardConfigCometWord I)] - exact hcleanComet - have hslot := setRewardConfigSlotOf_eq_solc I hcanon0 - have hkeccak := rewardConfigKeccakSlot (setRewardConfigCometWord I) - have rd1076₀ := evm_run rd1069 with [ - dup4, and, swap2, dup3, push1 ⟨0⟩, - raw mstore 0 (wordAt0Mem (setRewardConfigCometWord I) solcFreePtrMem) - (UInt256.ofNat 3) (by decide) mem_cost - (by - rw [hcleanCometLeft] - rfl) - (by decide) (by evm_ov)] - have rd1076 := rd1076₀ - rw [hcleanCometLeft] at rd1076 - have rd1089 := evm_run rd1076 with [ - push1 ⟨1⟩, swap4, push1 ⟨32⟩, swap1, dup6, dup3, - raw mstore 0 (rewardConfigHashMem (setRewardConfigCometWord I)) - (UInt256.ofNat 3) (by decide) mem_cost - (by rfl) (by decide) (by evm_ov), - dup1, dup9, push1 ⟨0⟩] - have rd1090₀ := rd1089.keccak256 0 - (solcMappingSlot ⟨1⟩ (setRewardConfigCometWord I)) - (UInt256.ofNat 3) (by decide) mem_cost hkeccak (by decide) (by evm_ov) - have rd1090 := rd1090₀ - rw [← hslot] at rd1090 - obtain ⟨_, _, rd1091₀⟩ := rd1090.sload (by decide) (by evm_ov) - obtain ⟨_, _, rd1091⟩ : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨1091⟩ - [solcSlotWord σ I (setRewardConfigSlotOf I), solcAddrMask, solcAddrMask, ⟨32⟩, - ⟨224⟩, ⟨4⟩, setRewardConfigCometWord I, ⟨1⟩, setRewardConfigTokenWord I, - ⟨64⟩, ⟨0⟩] - (rewardConfigHashMem (setRewardConfigCometWord I)) - (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by simpa [solcSlotWord] using rd1091₀⟩ - have rd1092 := evm_run rd1091 with [and] - have rd1599 := evm_run rd1092 with [ - push2 ⟨1599⟩, jumpiT htoken (by native_decide)] - have rd1602 := evm_run rd1599 with [ - jumpdest, dup8, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost - (rewardConfigHashMem_mload64 (setRewardConfigCometWord I)) - (by decide) (by evm_ov)] - have rd1612 := evm_run rd1602 with [ - push4 ⟨977536693⟩, push1 ⟨224⟩, shl, dup2, - raw mstore 6 - (setRewardConfigWrapperAlreadyConfiguredSelectorMem (setRewardConfigCometWord I)) - (UInt256.ofNat 5) (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - unfold setRewardConfigWrapperAlreadyConfiguredSelectorMem - rfl) - (by decide) (by evm_ov)] - have rd1618 := evm_run rd1612 with [ - dup1, dup6, add, dup7, swap1, - raw mstore 3 - (setRewardConfigWrapperAlreadyConfiguredMem (setRewardConfigCometWord I)) - (UInt256.ofNat 6) (by decide) mem_cost - (by - rw [show (⟨4⟩ : UInt256) + ⟨128⟩ = ⟨132⟩ from by decide, - show (⟨132⟩ : UInt256).toNat = 132 from by decide] - unfold setRewardConfigWrapperAlreadyConfiguredMem - rfl) - (by decide) (by evm_ov)] - exact evm_run rd1618 with [ - push1 ⟨36⟩, swap1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 10000000 in -theorem cometRewardsSetRewardConfigX_configured_ok - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (htoken : UInt256.land (solcSlotWord σ I (setRewardConfigSlotOf I)) solcAddrMask = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1096⟩ - [solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, setRewardConfigCometWord I, ⟨1⟩, - setRewardConfigTokenWord I, ⟨64⟩, ⟨0⟩] - (rewardConfigHashMem (setRewardConfigCometWord I)) - (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd1069⟩ := - cometRewardsSetRewardConfigX_auth_ok - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hsz68 hsize hhi hcanon0 hcanon1 hauth hreach - have hcleanComet : - UInt256.land (setRewardConfigCometWord I) solcAddrMask = - setRewardConfigCometWord I := by - exact solcAddrMask_clean (by - simpa [setRewardConfigCometWord, calldataWord] using hcanon0) - have hcleanCometLeft : - UInt256.land solcAddrMask (setRewardConfigCometWord I) = - setRewardConfigCometWord I := by - rw [u256_land_comm solcAddrMask (setRewardConfigCometWord I)] - exact hcleanComet - have hslot := setRewardConfigSlotOf_eq_solc I hcanon0 - have hkeccak := rewardConfigKeccakSlot (setRewardConfigCometWord I) - have rd1076₀ := evm_run rd1069 with [ - dup4, and, swap2, dup3, push1 ⟨0⟩, - raw mstore 0 (wordAt0Mem (setRewardConfigCometWord I) solcFreePtrMem) - (UInt256.ofNat 3) (by decide) mem_cost - (by - rw [hcleanCometLeft] - rfl) - (by decide) (by evm_ov)] - have rd1076 := rd1076₀ - rw [hcleanCometLeft] at rd1076 - have rd1089 := evm_run rd1076 with [ - push1 ⟨1⟩, swap4, push1 ⟨32⟩, swap1, dup6, dup3, - raw mstore 0 (rewardConfigHashMem (setRewardConfigCometWord I)) - (UInt256.ofNat 3) (by decide) mem_cost - (by rfl) (by decide) (by evm_ov), - dup1, dup9, push1 ⟨0⟩] - have rd1090₀ := rd1089.keccak256 0 - (solcMappingSlot ⟨1⟩ (setRewardConfigCometWord I)) - (UInt256.ofNat 3) (by decide) mem_cost hkeccak (by decide) (by evm_ov) - have rd1090 := rd1090₀ - rw [← hslot] at rd1090 - obtain ⟨_, _, rd1091₀⟩ := rd1090.sload (by decide) (by evm_ov) - obtain ⟨_, _, rd1091⟩ : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨1091⟩ - [solcSlotWord σ I (setRewardConfigSlotOf I), solcAddrMask, solcAddrMask, ⟨32⟩, - ⟨224⟩, ⟨4⟩, setRewardConfigCometWord I, ⟨1⟩, setRewardConfigTokenWord I, - ⟨64⟩, ⟨0⟩] - (rewardConfigHashMem (setRewardConfigCometWord I)) - (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by simpa [solcSlotWord] using rd1091₀⟩ - have rd1092 := evm_run rd1091 with [and] - rw [htoken] at rd1092 - exact ⟨_, _, evm_run rd1092 with [push2 ⟨1599⟩, jumpiNT (by decide)]⟩ - -def setRewardConfigWrapperBaseAccrualScaleSelectorShifted : UInt256 := - UInt256.shiftLeft (⟨1359440587⟩ : UInt256) ⟨225⟩ - -noncomputable def setRewardConfigWrapperBaseAccrualScaleCalldataMem - (I : ExecutionEnv) : ByteArray := - (UInt256.toByteArray setRewardConfigWrapperBaseAccrualScaleSelectorShifted).write 0 - (rewardConfigHashMem (setRewardConfigCometWord I)) 128 32 - -theorem setRewardConfigWrapperBaseAccrualScaleCalldataMem_read128_4 - (I : ExecutionEnv) : - (setRewardConfigWrapperBaseAccrualScaleCalldataMem I).readWithPadding 128 4 = - baseAccrualScaleSelector := by - unfold setRewardConfigWrapperBaseAccrualScaleCalldataMem - rw [toByteArray_write_read_window_of_gap - (b := setRewardConfigWrapperBaseAccrualScaleSelectorShifted) - (mem := rewardConfigHashMem (setRewardConfigCometWord I)) - (off := 128) (start := 0) (len := 4) - (by norm_num) (by norm_num) (by norm_num) - (by rw [rewardConfigHashMem_size]; exact lt_usize 32 (by norm_num))] - native_decide - -theorem setRewardConfigWrapperBaseAccrualScaleCalldataMem_encode (I : ExecutionEnv) : - config.externalABI.encode? "baseAccrualScale" [] = - some ((setRewardConfigWrapperBaseAccrualScaleCalldataMem I).readWithPadding 128 4) := by - rw [setRewardConfigWrapperBaseAccrualScaleCalldataMem_read128_4] - rfl - -abbrev setRewardConfigWrapperBasePostCallTail (I : ExecutionEnv) : List UInt256 := - [setRewardConfigTokenWord I, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, ⟨128⟩, ⟨64⟩, ⟨0⟩] - -abbrev setRewardConfigWrapperBasePostCallStack (z : Bool) (I : ExecutionEnv) : - List UInt256 := - (if z then ⟨1⟩ else ⟨0⟩) :: setRewardConfigWrapperBasePostCallTail I - -noncomputable abbrev setRewardConfigWrapperBasePostCallMem - (I : ExecutionEnv) (out : ByteArray) : ByteArray := - out.write 0 (setRewardConfigWrapperBaseAccrualScaleCalldataMem I) 128 - (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat - -abbrev setRewardConfigWrapperBasePostCallAw : UInt256 := - UInt256.ofNat (MachineState.M - (MachineState.M (UInt256.ofNat 5).toNat (⟨128⟩ : UInt256).toNat - (⟨4⟩ : UInt256).toNat) - (⟨128⟩ : UInt256).toNat (⟨32⟩ : UInt256).toNat) - -theorem setRewardConfigWrapperBaseTarget_eq_targetWord (I : ExecutionEnv) : - EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat) = - AccountAddress.ofUInt256 (setRewardConfigCometWord I) := by - rw [accountAddress_ofUInt256_eq_ofNat_toNat] - apply Fin.ext - simp [EVM.address, EVM.uintN] - exact Nat.mod_eq_of_lt (AccountAddress.ofNat (setRewardConfigCometWord I).toNat).isLt - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_call_baseAccrualScale - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (htoken : UInt256.land (solcSlotWord σ I (setRewardConfigSlotOf I)) solcAddrMask = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ gasArg k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨1115⟩ - [gasArg, setRewardConfigCometWord I, ⟨128⟩, ⟨4⟩, ⟨128⟩, ⟨32⟩, - setRewardConfigTokenWord I, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, ⟨128⟩, ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperBaseAccrualScaleCalldataMem I) - (UInt256.ofNat 5) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd1096⟩ := - cometRewardsSetRewardConfigX_configured_ok - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hsz68 hsize hhi hcanon0 hcanon1 hauth htoken hreach - have rd1108 := evm_run rd1096 with [ - dup8, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost - (rewardConfigHashMem_mload64 (setRewardConfigCometWord I)) - (by decide) (by evm_ov), - push4 ⟨1359440587⟩, push1 ⟨225⟩, shl, dup2, - raw mstore 6 (setRewardConfigWrapperBaseAccrualScaleCalldataMem I) - (UInt256.ofNat 5) (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - unfold setRewardConfigWrapperBaseAccrualScaleCalldataMem - rfl) - (by decide) (by evm_ov)] - have rd1114 := evm_run rd1108 with [ - swap7, dup3, dup9, dup7, dup2, dup10] - obtain ⟨gasArg, rd1115⟩ := evm_run rd1114 with [gas] - exact ⟨gasArg, _, _, by simpa using rd1115⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_call_baseAccrualScale_made - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ_evm I = solcSourceWord I) - (htoken : UInt256.land (solcSlotWord σ_evm I (setRewardConfigSlotOf I)) solcAddrMask = ⟨0⟩) - (hdepth : I.depth.val < 1024) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - ∃ cA' σ'_evm σ'_solm A'_solm z out k C, - typedCallViaEVM config - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] - (z, - { initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' }, - out) false ∧ - accountMapEquiv σ'_evm σ'_solm ∧ - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨1116⟩ (setRewardConfigWrapperBasePostCallStack z I) - (setRewardConfigWrapperBasePostCallMem I out) setRewardConfigWrapperBasePostCallAw out - (cA', σ'_evm) k C ∧ - out.size < 2 ^ 255 := by - obtain ⟨gasArg, k0, C0, rd1115⟩ := - cometRewardsSetRewardConfigX_call_baseAccrualScale - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hcanon0 hcanon1 hauth htoken hreach - have rd1115Call : - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨1115⟩ - (gasArg :: setRewardConfigCometWord I :: ⟨128⟩ :: ⟨4⟩ :: - ⟨128⟩ :: ⟨32⟩ :: setRewardConfigWrapperBasePostCallTail I) - (setRewardConfigWrapperBaseAccrualScaleCalldataMem I) - (UInt256.ofNat 5) ByteArray.empty (cA, σ_evm) k0 C0 := by - simpa [setRewardConfigWrapperBasePostCallTail] using rd1115 - have hdecCall : - decode cometRewardsBytecode (⟨1115⟩ : UInt256) = some (.STATICCALL, .none) := by - native_decide - obtain ⟨cA', σ'_evm, z, out, A_in, callGas, k', C', hΘ, rd1116, _houtSize⟩ := - RD.solcStaticcall (t := setRewardConfigWrapperBasePostCallTail I) rd1115Call hdecCall - hdepth (by simp [setRewardConfigWrapperBasePostCallTail]) - obtain ⟨g'', A'_evm, hΘeq⟩ := hΘ - have houtSmall : out.size < 2 ^ 138 := by - exact Theta_returnData_size_lt_2pow138_of_eq - (blob := I.blobVersionedHashes) (cA := cA) - (gh := (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I).genesisBlockHeader) - (blocks := (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I).blocks) - (σ := σ_evm) - (σ₀ := (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I).σ₀) - (A := A_in) - (s := AccountAddress.ofUInt256 (UInt256.ofNat I.codeOwner)) - (o := I.sender) - (r := AccountAddress.ofUInt256 (setRewardConfigCometWord I)) - (c := toExecute σ_evm (AccountAddress.ofUInt256 (setRewardConfigCometWord I))) - (g := callGas) (p := UInt256.ofNat I.gasPrice) - (v := ⟨0⟩) (v' := ⟨0⟩) - (d := (setRewardConfigWrapperBaseAccrualScaleCalldataMem I).readWithPadding 128 4) - (e := I.depth + 1) (H := I.header) (w := false) - hΘeq - (by exact Ethereum.EVM.ByteArray.readWithPadding_size_lt_uint256 _ _ _) - have houtSign : out.size < 2 ^ 255 := by omega - have hdepthNeI : I.depth ≠ 1024 := by - intro hEq - rw [hEq] at hdepth - exact absurd hdepth (by decide) - have hdepthNe : - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.depth ≠ - 1024 := by - simpa [initState] using hdepthNeI - have htgt := setRewardConfigWrapperBaseTarget_eq_targetWord I - have hcd := setRewardConfigWrapperBaseAccrualScaleCalldataMem_encode I - have hcallE : - typedCallViaEVM config - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] - (z, - { initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_evm - substate := A'_evm - createdAccounts := cA' }, - out) false := by - refine callCoincides - (cfg := config) - (evm := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (name := "baseAccrualScale") (args := []) - (tgt := EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - (targetWord := setRewardConfigCometWord I) - (cA' := cA') (σ' := σ'_evm) (A' := A'_evm) (A_in := A_in) - (z := z) (o := out) (g'' := g'') (callGas := callGas) - (mem := setRewardConfigWrapperBaseAccrualScaleCalldataMem I) - (inOff := ⟨128⟩) (inSize := ⟨4⟩) (callPerm := false) - hdepthNe htgt hcd ?_ - simpa [initState] using hΘeq - obtain ⟨σ'_solm, A'_solm, hcallSolm, hPostAccounts⟩ := - typedCallViaEVM_initState_accountMapEquiv hcallE hAccounts - exact ⟨cA', σ'_evm, σ'_solm, A'_solm, z, out, k', C', - hcallSolm, hPostAccounts, by - simpa [setRewardConfigWrapperBasePostCallStack, setRewardConfigWrapperBasePostCallTail, - setRewardConfigWrapperBasePostCallMem, setRewardConfigWrapperBasePostCallAw] using rd1116, - houtSign⟩ - -theorem setRewardConfigWrapperBaseAccrualScaleCalldataMem_read64 (I : ExecutionEnv) : - (setRewardConfigWrapperBaseAccrualScaleCalldataMem I).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - unfold setRewardConfigWrapperBaseAccrualScaleCalldataMem - rw [toByteArray_write_read_below_of_gap - (b := setRewardConfigWrapperBaseAccrualScaleSelectorShifted) - (mem := rewardConfigHashMem (setRewardConfigCometWord I)) - (off := 128) (read := 64) - (by have hsz := rewardConfigHashMem_size (setRewardConfigCometWord I); omega) - (by norm_num) - (by rw [rewardConfigHashMem_size]; exact lt_usize 32 (by norm_num))] - exact rewardConfigHashMem_read64 (setRewardConfigCometWord I) - -theorem setRewardConfigWrapperBaseAccrualScaleCalldataMem_size_ge128 - (I : ExecutionEnv) : - 128 ≤ (setRewardConfigWrapperBaseAccrualScaleCalldataMem I).size := by - unfold setRewardConfigWrapperBaseAccrualScaleCalldataMem - have h160 := - toByteArray_write_size_ge_off_add32 setRewardConfigWrapperBaseAccrualScaleSelectorShifted - (rewardConfigHashMem (setRewardConfigCometWord I)) 128 - (by rw [rewardConfigHashMem_size]; exact lt_usize 32 (by norm_num)) - omega - -theorem setRewardConfigWrapperBasePostCallMem_read64 (I : ExecutionEnv) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (setRewardConfigWrapperBasePostCallMem I out).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - dsimp [setRewardConfigWrapperBasePostCallMem] - by_cases hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 0 - · rw [hlen, byteArray_write_len_zero] - exact setRewardConfigWrapperBaseAccrualScaleCalldataMem_read64 I - · have hsrc : - (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat ≤ out.size := by - exact setRewardConfigBasePostCallLen_le_out_size houtSize - rw [write_read_below_gen_extend out - (setRewardConfigWrapperBaseAccrualScaleCalldataMem I) 128 - (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat 64 - hlen hsrc (setRewardConfigWrapperBaseAccrualScaleCalldataMem_size_ge128 I) - (by norm_num)] - exact setRewardConfigWrapperBaseAccrualScaleCalldataMem_read64 I - -theorem setRewardConfigWrapperBasePostCallMem_size_ge128 (I : ExecutionEnv) - {out : ByteArray} (houtSize : out.size < UInt256.size) : - 128 ≤ (setRewardConfigWrapperBasePostCallMem I out).size := by - dsimp [setRewardConfigWrapperBasePostCallMem] - by_cases hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 0 - · rw [hlen, byteArray_write_len_zero] - exact setRewardConfigWrapperBaseAccrualScaleCalldataMem_size_ge128 I - · have hsrc : - (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat ≤ out.size := by - exact setRewardConfigBasePostCallLen_le_out_size houtSize - let len := (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat - let base := setRewardConfigWrapperBaseAccrualScaleCalldataMem I - have hdest : 128 ≤ base.size := - setRewardConfigWrapperBaseAccrualScaleCalldataMem_size_ge128 I - by_cases hin : 128 + len ≤ base.size - · rw [write_eq_gen out base 128 len (by simpa [len] using hlen) - (by simpa [len] using hsrc) hin] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract] - omega - · have hext : base.size < 128 + len := Nat.lt_of_not_ge hin - rw [write_eq_gen_extend out base 128 len (by simpa [len] using hlen) - (by simpa [len] using hsrc) hdest hext] - rw [ByteArray.size_append, ByteArray.size_extract, ByteArray.size_extract] - omega - -theorem setRewardConfigWrapperBasePostCallMem_mload64 (I : ExecutionEnv) - {out : ByteArray} (houtSize : out.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ (setRewardConfigWrapperBasePostCallMem I out).size - ∨ (⟨64⟩ : UInt256) ≥ setRewardConfigWrapperBasePostCallAw * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigWrapperBasePostCallMem I out).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨128⟩ := by - apply mloadFreePtrValue - · exact lt_of_lt_of_le (by norm_num) - (setRewardConfigWrapperBasePostCallMem_size_ge128 I houtSize) - · native_decide - · exact setRewardConfigWrapperBasePostCallMem_read64 I houtSize - -theorem setRewardConfigWrapperBasePostCallMem_read128_of_size_ge (I : ExecutionEnv) - {out : ByteArray} (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (setRewardConfigWrapperBasePostCallMem I out).readWithPadding 128 32 = - out.extract 0 32 := by - unfold setRewardConfigWrapperBasePostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := out.size) - (by decide) hout32 houtSize - rw [hlen] - exact write32_read_back out - (setRewardConfigWrapperBaseAccrualScaleCalldataMem I) - 128 hout32 (by exact setRewardConfigWrapperBaseAccrualScaleCalldataMem_size_ge128 I) - -theorem setRewardConfigWrapperBasePostCallMem_size_ge160 (I : ExecutionEnv) - {out : ByteArray} (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - 160 ≤ (setRewardConfigWrapperBasePostCallMem I out).size := by - unfold setRewardConfigWrapperBasePostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := out.size) - (by decide) hout32 houtSize - rw [hlen] - rw [write32_eq out (setRewardConfigWrapperBaseAccrualScaleCalldataMem I) 128 hout32 - (by exact setRewardConfigWrapperBaseAccrualScaleCalldataMem_size_ge128 I)] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract] - have hbase := setRewardConfigWrapperBaseAccrualScaleCalldataMem_size_ge128 I - omega - -theorem setRewardConfigWrapperBasePostCallMem_mload128_haw : - ¬ (⟨128⟩ : UInt256) ≥ setRewardConfigWrapperBasePostCallAw * ⟨32⟩ := by - native_decide - -theorem setRewardConfigWrapperBasePostCallMem_mload128_of_size_ge - (I : ExecutionEnv) {out : ByteArray} - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (if (⟨128⟩ : UInt256).toNat ≥ (setRewardConfigWrapperBasePostCallMem I out).size - ∨ (⟨128⟩ : UInt256) ≥ setRewardConfigWrapperBasePostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigWrapperBasePostCallMem I out).readWithPadding - (⟨128⟩ : UInt256).toNat 32))) = - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) := by - exact mloadValue_eq_readWithPadding_of_lt_size - (mem := setRewardConfigWrapperBasePostCallMem I out) - (aw := setRewardConfigWrapperBasePostCallAw) - (off := ⟨128⟩) (memSize := (setRewardConfigWrapperBasePostCallMem I out).size) - rfl - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - exact lt_of_lt_of_le (by omega) - (setRewardConfigWrapperBasePostCallMem_size_ge160 I hout32 houtSize)) - setRewardConfigWrapperBasePostCallMem_mload128_haw - |>.trans (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - setRewardConfigWrapperBasePostCallMem_read128_of_size_ge I hout32 houtSize]) - -noncomputable abbrev setRewardConfigWrapperBasePostDecodeMem - (I : ExecutionEnv) (out : ByteArray) : ByteArray := - (UInt256.toByteArray (⟨160⟩ : UInt256)).write 0 - (setRewardConfigWrapperBasePostCallMem I out) 64 32 - -theorem setRewardConfigWrapperBasePostDecodeMem_read128_of_size_ge - (I : ExecutionEnv) {out : ByteArray} - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (setRewardConfigWrapperBasePostDecodeMem I out).readWithPadding 128 32 = - out.extract 0 32 := by - unfold setRewardConfigWrapperBasePostDecodeMem - rw [write32_read_above (UInt256.toByteArray (⟨160⟩ : UInt256)) - (setRewardConfigWrapperBasePostCallMem I out) 64 128 - (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigWrapperBasePostCallMem_size_ge160 I hout32 houtSize)) - (by omega) - (by - exact le_trans (by omega) - (setRewardConfigWrapperBasePostCallMem_size_ge160 I hout32 houtSize))] - exact setRewardConfigWrapperBasePostCallMem_read128_of_size_ge I hout32 houtSize - -theorem setRewardConfigWrapperBasePostDecodeMem_mload128_of_size_ge - (I : ExecutionEnv) {out : ByteArray} - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (if (⟨128⟩ : UInt256).toNat ≥ (setRewardConfigWrapperBasePostDecodeMem I out).size - ∨ (⟨128⟩ : UInt256) ≥ setRewardConfigWrapperBasePostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigWrapperBasePostDecodeMem I out).readWithPadding - (⟨128⟩ : UInt256).toNat 32))) = - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) := by - exact mloadValue_eq_readWithPadding_of_lt_size - (mem := setRewardConfigWrapperBasePostDecodeMem I out) - (aw := setRewardConfigWrapperBasePostCallAw) - (off := ⟨128⟩) (memSize := (setRewardConfigWrapperBasePostDecodeMem I out).size) - rfl - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - unfold setRewardConfigWrapperBasePostDecodeMem - rw [write32_eq (UInt256.toByteArray (⟨160⟩ : UInt256)) - (setRewardConfigWrapperBasePostCallMem I out) 64 (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigWrapperBasePostCallMem_size_ge160 I hout32 houtSize))] - simp - have hsz := setRewardConfigWrapperBasePostCallMem_size_ge160 I hout32 houtSize - omega) - setRewardConfigWrapperBasePostCallMem_mload128_haw - |>.trans (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - setRewardConfigWrapperBasePostDecodeMem_read128_of_size_ge I hout32 houtSize]) - -theorem setRewardConfigWrapperBasePostDecodeMem_read64 - (I : ExecutionEnv) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) : - (setRewardConfigWrapperBasePostDecodeMem I baseOut).readWithPadding 64 32 = - UInt256.toByteArray ⟨160⟩ := by - unfold setRewardConfigWrapperBasePostDecodeMem - rw [write32_read_back _ _ 64 (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigWrapperBasePostCallMem_size_ge160 I hout32 houtSize))] - rw [show (UInt256.toByteArray (⟨160⟩ : UInt256)).extract 0 32 = - UInt256.toByteArray (⟨160⟩ : UInt256) by - rw [show 32 = (UInt256.toByteArray (⟨160⟩ : UInt256)).size by - rw [toByteArray_size]] - exact byteArray_extract_self _] - -theorem setRewardConfigWrapperBasePostDecodeMem_size_ge160 - (I : ExecutionEnv) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) : - 160 ≤ (setRewardConfigWrapperBasePostDecodeMem I baseOut).size := by - unfold setRewardConfigWrapperBasePostDecodeMem - exact le_trans (setRewardConfigWrapperBasePostCallMem_size_ge160 I hout32 houtSize) - (byteArray_write_size_ge_base_of_le (UInt256.toByteArray (⟨160⟩ : UInt256)) - (setRewardConfigWrapperBasePostCallMem I baseOut) (by rw [toByteArray_size]) - (by - have hbase := setRewardConfigWrapperBasePostCallMem_size_ge160 I hout32 houtSize - omega)) - -theorem setRewardConfigWrapperBasePostDecodeMem_mload64 - (I : ExecutionEnv) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ (setRewardConfigWrapperBasePostDecodeMem I baseOut).size - ∨ (⟨64⟩ : UInt256) ≥ setRewardConfigWrapperBasePostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigWrapperBasePostDecodeMem I baseOut).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨160⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := setRewardConfigWrapperBasePostCallAw) - (v := ⟨160⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - have hge := setRewardConfigWrapperBasePostDecodeMem_size_ge160 I - (baseOut := baseOut) hout32 houtSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact setRewardConfigWrapperBasePostDecodeMem_read64 I hout32 houtSize) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_after_baseAccrualScale_failure - {cA gh bl σ σ₀ A I} {g : Sat256} {out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1116⟩ (setRewardConfigWrapperBasePostCallStack false I) - (setRewardConfigWrapperBasePostCallMem I out) setRewardConfigWrapperBasePostCallAw out - acc k C) - (houtSize : out.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have rd1116 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1116⟩ - [⟨0⟩, setRewardConfigTokenWord I, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, ⟨128⟩, ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperBasePostCallMem I out) setRewardConfigWrapperBasePostCallAw out - acc k C := by - simpa [setRewardConfigWrapperBasePostCallStack, - setRewardConfigWrapperBasePostCallTail] using rd - have rd1117 := RD.swap8 rd1116 (by native_decide) (by simp) - have rd1588 := evm_run rd1117 with [ - dup9, iszero, push2 ⟨1588⟩, jumpiT (by native_decide) (by jump_dest)] - have rd1591 := evm_run rd1588 with [ - jumpdest, dup10, - raw mload 0 ⟨128⟩ setRewardConfigWrapperBasePostCallAw (by native_decide) - mem_cost (setRewardConfigWrapperBasePostCallMem_mload64 I houtSize) - (by native_decide) (by evm_ov)] - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have rd1595pre := evm_run rd1591 with [returndatasize, push1 ⟨0⟩, dup3] - let mem2 : ByteArray := - out.write 0 (setRewardConfigWrapperBasePostCallMem I out) 128 rdsz.toNat - let aw2 : UInt256 := - UInt256.ofNat (MachineState.M setRewardConfigWrapperBasePostCallAw.toNat 128 rdsz.toNat) - have rd1596 := RD.returndatacopy - (Cₘ aw2 - Cₘ setRewardConfigWrapperBasePostCallAw) mem2 aw2 rd1595pre - (by native_decide) - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, hrdsz_toNat]; omega) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, aw2, rdsz] - rw [show (⟨128⟩ : UInt256).toNat = 128 from rfl]) - (by rfl) - (by rfl) - (by simp) - have rd1599 := evm_run rd1596 with [returndatasize, swap1] - exact RD.rev - (Cₘ (UInt256.ofNat (MachineState.M aw2.toNat 128 rdsz.toNat)) - Cₘ aw2) - rd1599 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, rdsz] - rw [show (⟨128⟩ : UInt256).toNat = 128 from rfl]) - (by simp) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_baseAccrualScale_callDepthLimit - {cA gh bl σ σ₀ A I} {g : UInt256} - (hwv : I.weiValue = ⟨0⟩) (hsz68 : 68 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (htoken : UInt256.land (solcSlotWord σ I (setRewardConfigSlotOf I)) solcAddrMask = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) - (hdepth : I.depth = 1024) : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - obtain ⟨gasArg, k0, C0, rd1115⟩ := - cometRewardsSetRewardConfigX_call_baseAccrualScale - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hcanon0 hcanon1 hauth htoken hreach - have rd1115Call : - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨1115⟩ - (gasArg :: setRewardConfigCometWord I :: ⟨128⟩ :: ⟨4⟩ :: - ⟨128⟩ :: ⟨32⟩ :: setRewardConfigWrapperBasePostCallTail I) - (setRewardConfigWrapperBaseAccrualScaleCalldataMem I) - (UInt256.ofNat 5) ByteArray.empty (cA, σ) k0 C0 := by - simpa [setRewardConfigWrapperBasePostCallTail] using rd1115 - have hdecCall : - decode cometRewardsBytecode (⟨1115⟩ : UInt256) = some (.STATICCALL, .none) := by - native_decide - have hdepthInit : - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).executionEnv.depth = 1024 := by - simpa [initState] using hdepth - obtain ⟨k', C', rdPost₀⟩ := - RD.solcStaticcallDepthLimit (t := setRewardConfigWrapperBasePostCallTail I) - rd1115Call hdecCall hdepthInit (by simp [setRewardConfigWrapperBasePostCallTail]) - have rdPost : - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) - ⟨1116⟩ (setRewardConfigWrapperBasePostCallStack false I) - (setRewardConfigWrapperBasePostCallMem I ByteArray.empty) - setRewardConfigWrapperBasePostCallAw ByteArray.empty (cA, σ) k' C' := by - simpa [setRewardConfigWrapperBasePostCallStack, setRewardConfigWrapperBasePostCallTail, - setRewardConfigWrapperBasePostCallMem, setRewardConfigWrapperBasePostCallAw] using rdPost₀ - exact cometRewardsSetRewardConfigX_after_baseAccrualScale_failure rdPost - (by simp [UInt256.size]) - -noncomputable abbrev setRewardConfigWrapperBasePostShortDecodeMem - (I : ExecutionEnv) (out : ByteArray) : ByteArray := - (UInt256.toByteArray ((⟨128⟩ : UInt256) + - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat out.size + ⟨31⟩))).write 0 - (setRewardConfigWrapperBasePostCallMem I out) 64 32 - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigX_after_baseAccrualScale_short_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1116⟩ (setRewardConfigWrapperBasePostCallStack true I) - (setRewardConfigWrapperBasePostCallMem I out) setRewardConfigWrapperBasePostCallAw out - acc k C) - (hshort : out.size < 32) (houtSize : out.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨1⟩ := by - apply ugt_one - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hshort - have rd1116 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1116⟩ - [⟨1⟩, setRewardConfigTokenWord I, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, ⟨128⟩, ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperBasePostCallMem I out) setRewardConfigWrapperBasePostCallAw out - acc k C := by - simpa [setRewardConfigWrapperBasePostCallStack, - setRewardConfigWrapperBasePostCallTail] using rd - have rd1117 := RD.swap8 rd1116 (by native_decide) (by simp) - have rd1125 := evm_run rd1117 with [ - dup9, iszero, push2 ⟨1588⟩, jumpiNT (by native_decide), - push1 ⟨0⟩] - have rd1126 := rdSwap9 rd1125 (by native_decide) (by simp) - have rd1555 := evm_run rd1126 with [ - push2 ⟨1555⟩, jumpiT (by native_decide) (by jump_dest)] - have rd1558 := evm_run rd1555 with [ - jumpdest, dup3, swap2] - have rd1559 := rdSwap9 rd1558 (by native_decide) (by simp) - have rd1568₀ := evm_run rd1559 with [ - pop, push2 ⟨1581⟩, swap1, dup5, returndatasize, dup7, gt] - have rd1568 := rd1568₀ - rw [show UInt256.ofNat out.size = rdsz from rfl, hgt] at rd1568 - let rounded : UInt256 := - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat out.size + ⟨31⟩) - let ptr : UInt256 := (⟨128⟩ : UInt256) + rounded - have hroundedLe : rounded.toNat ≤ out.size + 31 := by - unfold rounded - rw [uland_toNat] - refine le_trans Nat.and_le_right ?_ - rw [uadd_toNat, UInt256.toNat_ofNat_of_lt houtSize, - show (⟨31⟩ : UInt256).toNat = 31 from by decide] - exact Nat.mod_le _ _ - have hptr_toNat : ptr.toNat = 128 + rounded.toNat := by - unfold ptr - rw [uadd_toNat, show (⟨128⟩ : UInt256).toNat = 128 from by decide] - exact Nat.mod_eq_of_lt (by - have hroundSmall : rounded.toNat < 64 := by omega - have hsz : UInt256.size = 2 ^ 256 := by decide - omega) - have hltPtr : UInt256.lt ptr (⟨128⟩ : UInt256) = ⟨0⟩ := by - apply ult_zero - rw [hptr_toNat, show (⟨128⟩ : UInt256).toNat = 128 from by decide] - omega - have hmax64 : - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩).toNat = - 18446744073709551615 := by - native_decide - have hgtPtr : - UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - rw [hptr_toNat, hmax64] - omega - have hallocOk : - UInt256.lor (UInt256.lt ptr (⟨128⟩ : UInt256)) - (UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = ⟨0⟩ := by - rw [hltPtr, hgtPtr] - native_decide - have rd3071 := evm_run rd1568 with [ - push2 ⟨734⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, pop, returndatasize, push2 ⟨709⟩, jump (by jump_dest), - jumpdest, push2 ⟨719⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, - jumpiNT (by simpa [ptr, rounded] using hallocOk), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigWrapperBasePostShortDecodeMem I out) - setRewardConfigWrapperBasePostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]) - (by native_decide) (by evm_ov)] - have rd3106 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3106⟩, - jump (by jump_dest)] - have hlenCheck : - UInt256.slt (UInt256.sub ((⟨128⟩ : UInt256) + rdsz) ⟨128⟩) ⟨32⟩ = ⟨1⟩ := by - simpa [rdsz] using solcDecodeEndLenCheckShort_128_32 (len := out.size) hshort - have rd3114₀ := evm_run rd3106 with [ - jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, slt] - have rd3114 := rd3114₀ - rw [hlenCheck] at rd3114 - have rd1004 := evm_run rd3114 with [ - push2 ⟨1004⟩, jumpiT (by native_decide) (by jump_dest)] - exact evm_run rd1004 with [ - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigX_after_baseAccrualScale_noncanon_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1116⟩ (setRewardConfigWrapperBasePostCallStack true I) - (setRewardConfigWrapperBasePostCallMem I out) setRewardConfigWrapperBasePostCallAw out - acc k C) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) - (hbase64 : ¬ (setRewardConfigBaseReturnWord out).toNat < EVM.twoPow 64) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let baseWord : UInt256 := setRewardConfigBaseReturnWord out - have hbase64' : ¬ baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have rd1116 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1116⟩ - [⟨1⟩, setRewardConfigTokenWord I, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, ⟨128⟩, ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperBasePostCallMem I out) setRewardConfigWrapperBasePostCallAw out - acc k C := by - simpa [setRewardConfigWrapperBasePostCallStack, - setRewardConfigWrapperBasePostCallTail] using rd - have rd1117 := RD.swap8 rd1116 (by native_decide) (by simp) - have rd1125 := evm_run rd1117 with [ - dup9, iszero, push2 ⟨1588⟩, jumpiNT (by native_decide), - push1 ⟨0⟩] - have rd1126 := rdSwap9 rd1125 (by native_decide) (by simp) - have rd1555 := evm_run rd1126 with [ - push2 ⟨1555⟩, jumpiT (by native_decide) (by jump_dest)] - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hout32 - have rd1558 := evm_run rd1555 with [ - jumpdest, dup3, swap2] - have rd1559 := rdSwap9 rd1558 (by native_decide) (by simp) - have rd1568₀ := evm_run rd1559 with [ - pop, push2 ⟨1581⟩, swap1, dup5, returndatasize, dup7, gt] - have rd1568 := rd1568₀ - rw [show UInt256.ofNat out.size = rdsz from rfl, hgt] at rd1568 - have rd3071 := evm_run rd1568 with [ - push2 ⟨734⟩, jumpiNT (by native_decide), - push2 ⟨719⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), - push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigWrapperBasePostDecodeMem I out) - setRewardConfigWrapperBasePostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigWrapperBasePostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd3106 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3106⟩, - jump (by jump_dest), jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, - slt, push2 ⟨1004⟩, jumpiNT (by native_decide)] - have rd3129 := evm_run rd3106 with [ - raw mload 0 baseWord setRewardConfigWrapperBasePostCallAw (by native_decide) - mem_cost - (by - simpa [baseWord, setRewardConfigBaseReturnWord] using - setRewardConfigWrapperBasePostDecodeMem_mload128_of_size_ge I hout32 houtSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, and, dup2, sub] - have hnotClean : UInt256.land baseWord uint64Mask ≠ baseWord := - uint64Mask_not_clean hbase64' - have hneq : - baseWord ≠ - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) := by - intro hEq - exact hnotClean (by simpa [uint64Mask] using hEq.symm) - have hsub : - UInt256.sub baseWord - (UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) ≠ ⟨0⟩ := - u256_sub_ne_zero_of_ne hneq - have rd1004 := evm_run rd3129 with [ - push2 ⟨1004⟩, jumpiT hsub (by jump_dest)] - exact evm_run rd1004 with [ - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -abbrev setRewardConfigWrapperAfterBaseDecodeStack (baseWord : UInt256) - (I : ExecutionEnv) : List UInt256 := - [solcAddrMask, setRewardConfigTokenWord I, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, baseWord, ⟨64⟩, ⟨0⟩] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigX_after_baseAccrualScale_decode_ok - {cA gh bl σ σ₀ A I} {g : Sat256} {out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1116⟩ (setRewardConfigWrapperBasePostCallStack true I) - (setRewardConfigWrapperBasePostCallMem I out) setRewardConfigWrapperBasePostCallAw out - acc k C) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) - (hbase64 : (setRewardConfigBaseReturnWord out).toNat < EVM.twoPow 64) : - ∃ k' C', RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1130⟩ - (setRewardConfigWrapperAfterBaseDecodeStack (setRewardConfigBaseReturnWord out) I) - (setRewardConfigWrapperBasePostDecodeMem I out) setRewardConfigWrapperBasePostCallAw out - acc k' C' := by - let baseWord : UInt256 := setRewardConfigBaseReturnWord out - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have rd1116 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1116⟩ - [⟨1⟩, setRewardConfigTokenWord I, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, ⟨128⟩, ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperBasePostCallMem I out) setRewardConfigWrapperBasePostCallAw out - acc k C := by - simpa [setRewardConfigWrapperBasePostCallStack, - setRewardConfigWrapperBasePostCallTail] using rd - have rd1117 := RD.swap8 rd1116 (by native_decide) (by simp) - have rd1125 := evm_run rd1117 with [ - dup9, iszero, push2 ⟨1588⟩, jumpiNT (by native_decide), - push1 ⟨0⟩] - have rd1126 := rdSwap9 rd1125 (by native_decide) (by simp) - have rd1555 := evm_run rd1126 with [ - push2 ⟨1555⟩, jumpiT (by native_decide) (by jump_dest)] - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hout32 - have rd1558 := evm_run rd1555 with [ - jumpdest, dup3, swap2] - have rd1559 := rdSwap9 rd1558 (by native_decide) (by simp) - have rd1568₀ := evm_run rd1559 with [ - pop, push2 ⟨1581⟩, swap1, dup5, returndatasize, dup7, gt] - have rd1568 := rd1568₀ - rw [show UInt256.ofNat out.size = rdsz from rfl, hgt] at rd1568 - have rd3071 := evm_run rd1568 with [ - push2 ⟨734⟩, jumpiNT (by native_decide), - push2 ⟨719⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), - push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigWrapperBasePostDecodeMem I out) - setRewardConfigWrapperBasePostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigWrapperBasePostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd3106 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3106⟩, - jump (by jump_dest), jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, - slt, push2 ⟨1004⟩, jumpiNT (by native_decide)] - have rd3129 := evm_run rd3106 with [ - raw mload 0 baseWord setRewardConfigWrapperBasePostCallAw (by native_decide) - mem_cost - (by - simpa [baseWord, setRewardConfigBaseReturnWord] using - setRewardConfigWrapperBasePostDecodeMem_mload128_of_size_ge I hout32 houtSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, and, dup2, sub] - have hclean : UInt256.land baseWord uint64Mask = baseWord := - uint64Mask_clean hbase64' - have hcleanExpanded : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using hclean - have hsub : - UInt256.sub baseWord - (UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) = ⟨0⟩ := by - rw [hcleanExpanded] - exact u256_sub_self baseWord - have rd3129zero := rd3129 - rw [hsub] at rd3129zero - have rd1581 := evm_run rd3129zero with [ - push2 ⟨1004⟩, jumpiNT (by native_decide), swap1, jump (by jump_dest)] - have rd1582 := evm_run rd1581 with [jumpdest] - have rd1583 := RD.swap8 rd1582 (by native_decide) (by simp) - have rd1130 := evm_run rd1583 with [swap1, push2 ⟨1130⟩, jump (by jump_dest)] - exact ⟨_, _, by - simpa [baseWord, setRewardConfigWrapperAfterBaseDecodeStack, - setRewardConfigBaseReturnWord] using rd1130⟩ - -noncomputable def setRewardConfigWrapperDecimalsCalldataMem - (I : ExecutionEnv) (baseOut : ByteArray) : ByteArray := - (UInt256.toByteArray setRewardConfigDecimalsSelectorShifted).write 0 - (setRewardConfigWrapperBasePostDecodeMem I baseOut) 160 32 - -theorem setRewardConfigWrapperDecimalsCalldataMem_read160_4 - (I : ExecutionEnv) (baseOut : ByteArray) : - (setRewardConfigWrapperDecimalsCalldataMem I baseOut).readWithPadding 160 4 = - decimalsSelector := by - unfold setRewardConfigWrapperDecimalsCalldataMem - rw [toByteArray_write_read_window_of_gap - (b := setRewardConfigDecimalsSelectorShifted) - (mem := setRewardConfigWrapperBasePostDecodeMem I baseOut) - (off := 160) (start := 0) (len := 4) - (by norm_num) (by norm_num) (by norm_num) - (by - exact lt_of_le_of_lt (Nat.sub_le _ _) - (lt_usize 160 (by norm_num)))] - native_decide - -theorem setRewardConfigWrapperDecimalsCalldataMem_encode - (I : ExecutionEnv) (baseOut : ByteArray) : - config.externalABI.encode? "decimals" [] = - some ((setRewardConfigWrapperDecimalsCalldataMem I baseOut).readWithPadding 160 4) := by - rw [setRewardConfigWrapperDecimalsCalldataMem_read160_4] - rfl - -abbrev setRewardConfigWrapperDecimalsTargetWord (I : ExecutionEnv) : UInt256 := - UInt256.land solcAddrMask (setRewardConfigTokenWord I) - -theorem setRewardConfigWrapperDecimalsTarget_eq_targetWord (I : ExecutionEnv) - (hcanon : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) : - EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat) = - AccountAddress.ofUInt256 (setRewardConfigWrapperDecimalsTargetWord I) := by - have hcleanLeft : - UInt256.land (setRewardConfigTokenWord I) solcAddrMask = - setRewardConfigTokenWord I := by - exact solcAddrMask_clean (by - simpa [setRewardConfigTokenWord, calldataWord] using hcanon) - have hclean : - UInt256.land solcAddrMask (setRewardConfigTokenWord I) = - setRewardConfigTokenWord I := by - rw [u256_land_comm solcAddrMask (setRewardConfigTokenWord I), hcleanLeft] - rw [setRewardConfigWrapperDecimalsTargetWord, hclean, - accountAddress_ofUInt256_eq_ofNat_toNat] - apply Fin.ext - simp [EVM.address, EVM.uintN] - exact Nat.mod_eq_of_lt (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat).isLt - -abbrev setRewardConfigWrapperDecimalsCallAw : UInt256 := - UInt256.ofNat (MachineState.M setRewardConfigWrapperBasePostCallAw.toNat 160 32) - -abbrev setRewardConfigWrapperDecimalsPostCallAw : UInt256 := - UInt256.ofNat (MachineState.M - (MachineState.M setRewardConfigWrapperDecimalsCallAw.toNat 160 4) 160 32) - -abbrev setRewardConfigWrapperDecimalsPostCallTail (baseWord : UInt256) - (I : ExecutionEnv) : List UInt256 := - [⟨160⟩, baseWord, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, setRewardConfigWrapperDecimalsTargetWord I, - ⟨64⟩, ⟨0⟩] - -abbrev setRewardConfigWrapperDecimalsPostCallStack (z : Bool) (baseWord : UInt256) - (I : ExecutionEnv) : List UInt256 := - (if z then ⟨1⟩ else ⟨0⟩) :: setRewardConfigWrapperDecimalsPostCallTail baseWord I - -noncomputable abbrev setRewardConfigWrapperDecimalsPostCallMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) : ByteArray := - decOut.write 0 (setRewardConfigWrapperDecimalsCalldataMem I baseOut) 160 - (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat - -theorem setRewardConfigWrapperDecimalsCalldataMem_size_ge192 - (I : ExecutionEnv) (baseOut : ByteArray) : - 192 ≤ (setRewardConfigWrapperDecimalsCalldataMem I baseOut).size := by - unfold setRewardConfigWrapperDecimalsCalldataMem - exact toByteArray_write_size_ge_off_add32 setRewardConfigDecimalsSelectorShifted - (setRewardConfigWrapperBasePostDecodeMem I baseOut) 160 - (by - exact lt_of_le_of_lt (Nat.sub_le _ _) - (lt_usize 160 (by norm_num))) - -theorem setRewardConfigWrapperDecimalsCalldataMem_read64 - (I : ExecutionEnv) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) : - (setRewardConfigWrapperDecimalsCalldataMem I baseOut).readWithPadding 64 32 = - UInt256.toByteArray ⟨160⟩ := by - unfold setRewardConfigWrapperDecimalsCalldataMem - rw [toByteArray_write_read_below_of_gap - (b := setRewardConfigDecimalsSelectorShifted) - (mem := setRewardConfigWrapperBasePostDecodeMem I baseOut) - (off := 160) (read := 64) - (by - exact le_trans (by omega) - (setRewardConfigWrapperBasePostDecodeMem_size_ge160 I hout32 houtSize)) - (by norm_num) - (by - exact lt_of_le_of_lt (Nat.sub_le _ _) - (lt_usize 160 (by norm_num)))] - exact setRewardConfigWrapperBasePostDecodeMem_read64 I hout32 houtSize - -theorem setRewardConfigWrapperDecimalsPostCallMem_size_ge96 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (hdecSize : decOut.size < UInt256.size) : - 96 ≤ (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut).size := by - unfold setRewardConfigWrapperDecimalsPostCallMem - have hbase := setRewardConfigWrapperDecimalsCalldataMem_size_ge192 I baseOut - have hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat ≤ decOut.size := - setRewardConfigBasePostCallLen_le_out_size hdecSize - exact le_trans (by omega) - (byteArray_write_size_ge_base_of_le decOut - (setRewardConfigWrapperDecimalsCalldataMem I baseOut) hlen (by omega)) - -theorem setRewardConfigWrapperDecimalsPostCallMem_read64 - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) - (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut).readWithPadding 64 32 = - UInt256.toByteArray ⟨160⟩ := by - unfold setRewardConfigWrapperDecimalsPostCallMem - by_cases hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat = 0 - · rw [hlen, byteArray_write_len_zero] - exact setRewardConfigWrapperDecimalsCalldataMem_read64 I hout32 houtSize - · have hsrc : - (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat ≤ decOut.size := - setRewardConfigBasePostCallLen_le_out_size hdecSize - rw [write_read_below_gen_extend decOut - (setRewardConfigWrapperDecimalsCalldataMem I baseOut) - 160 (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat 64 - hlen hsrc (by - have hbase := setRewardConfigWrapperDecimalsCalldataMem_size_ge192 I baseOut - omega) - (by norm_num)] - exact setRewardConfigWrapperDecimalsCalldataMem_read64 I hout32 houtSize - -theorem setRewardConfigWrapperDecimalsPostCallMem_mload64 - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) - (hdecSize : decOut.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut).size - ∨ (⟨64⟩ : UInt256) ≥ setRewardConfigWrapperDecimalsPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨160⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := setRewardConfigWrapperDecimalsPostCallAw) - (v := ⟨160⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - have hge := setRewardConfigWrapperDecimalsPostCallMem_size_ge96 I - (baseOut := baseOut) (decOut := decOut) hdecSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact setRewardConfigWrapperDecimalsPostCallMem_read64 I hout32 houtSize hdecSize) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_call_decimals - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut : ByteArray} {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1130⟩ - (setRewardConfigWrapperAfterBaseDecodeStack baseWord I) - (setRewardConfigWrapperBasePostDecodeMem I baseOut) setRewardConfigWrapperBasePostCallAw - baseOut acc k C) - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) : - ∃ gasArg k' C', RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨1153⟩ - [gasArg, setRewardConfigWrapperDecimalsTargetWord I, ⟨160⟩, ⟨4⟩, ⟨160⟩, - ⟨32⟩, ⟨160⟩, baseWord, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, setRewardConfigWrapperDecimalsTargetWord I, - ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperDecimalsCalldataMem I baseOut) - setRewardConfigWrapperDecimalsCallAw baseOut acc k' C' := by - have hcleanToken : - UInt256.land solcAddrMask (setRewardConfigTokenWord I) = - setRewardConfigWrapperDecimalsTargetWord I := by - rfl - have rd1130 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1130⟩ - [solcAddrMask, setRewardConfigTokenWord I, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, baseWord, ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperBasePostDecodeMem I baseOut) setRewardConfigWrapperBasePostCallAw - baseOut acc k C := by - simpa [setRewardConfigWrapperAfterBaseDecodeStack] using rd - have rd1135₀ := evm_run rd1130 with [ - jumpdest, pop, dup2, and, swap7] - have rd1135 := rd1135₀ - rw [hcleanToken] at rd1135 - have rd1147 := evm_run rd1135 with [ - dup9, - raw mload 0 ⟨160⟩ setRewardConfigWrapperBasePostCallAw (by native_decide) - mem_cost (setRewardConfigWrapperBasePostDecodeMem_mload64 I hout32 houtSize) - (by native_decide) (by evm_ov), - push4 ⟨826074471⟩, push1 ⟨224⟩, shl, dup2, - raw mstore 3 (setRewardConfigWrapperDecimalsCalldataMem I baseOut) - setRewardConfigWrapperDecimalsCallAw (by native_decide) mem_cost - (by - rw [show (⟨160⟩ : UInt256).toNat = 160 from by decide] - unfold setRewardConfigWrapperDecimalsCalldataMem - rfl) - (by native_decide) (by evm_ov)] - have rd1152 := evm_run rd1147 with [ - dup4, dup2, dup8, dup2, dup13] - obtain ⟨gasArg, rd1153⟩ := evm_run rd1152 with [gas] - exact ⟨gasArg, _, _, by simpa using rd1153⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_call_decimals_made - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} - {baseOut : ByteArray} {baseWord : UInt256} - {cA' : Batteries.RBSet AccountAddress compare} {σ'_evm σ'_solm : AccountMap} - {A'_solm : Substate} {k C : ℕ} - (hcanon1 : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hdepth : I.depth.val < 1024) - (hPostAccounts : accountMapEquiv σ'_evm σ'_solm) - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ_evm σ₀ g A I) ⟨1130⟩ - (setRewardConfigWrapperAfterBaseDecodeStack baseWord I) - (setRewardConfigWrapperBasePostDecodeMem I baseOut) setRewardConfigWrapperBasePostCallAw - baseOut (cA', σ'_evm) k C) - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) : - ∃ cA'' σ''_evm σ''_solm A''_solm z out k' C', - typedCallViaEVM config - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] - (z, - { { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' }, - out) false ∧ - accountMapEquiv σ''_evm σ''_solm ∧ - RD cometRewardsBytecode I g (initState cA gh bl σ_evm σ₀ g A I) ⟨1154⟩ - (setRewardConfigWrapperDecimalsPostCallStack z baseWord I) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut out) - setRewardConfigWrapperDecimalsPostCallAw out (cA'', σ''_evm) k' C' ∧ - out.size < 2 ^ 255 := by - obtain ⟨gasArg, k0, C0, rd1153⟩ := - cometRewardsSetRewardConfigX_call_decimals (rd := rd) hout32 houtSize - have rd1153Call : - RD cometRewardsBytecode I g (initState cA gh bl σ_evm σ₀ g A I) ⟨1153⟩ - (gasArg :: setRewardConfigWrapperDecimalsTargetWord I :: ⟨160⟩ :: ⟨4⟩ :: - ⟨160⟩ :: ⟨32⟩ :: setRewardConfigWrapperDecimalsPostCallTail baseWord I) - (setRewardConfigWrapperDecimalsCalldataMem I baseOut) - setRewardConfigWrapperDecimalsCallAw baseOut (cA', σ'_evm) k0 C0 := by - simpa [setRewardConfigWrapperDecimalsPostCallTail] using rd1153 - have hdecCall : - decode cometRewardsBytecode (⟨1153⟩ : UInt256) = some (.STATICCALL, .none) := by - native_decide - obtain ⟨cA'', σ''_evm, z, out, A_in, callGas, k', C', hΘ, rd1154, _houtSize⟩ := - RD.solcStaticcall (t := setRewardConfigWrapperDecimalsPostCallTail baseWord I) - rd1153Call hdecCall hdepth (by simp [setRewardConfigWrapperDecimalsPostCallTail]) - obtain ⟨g'', A''_evm, hΘeq⟩ := hΘ - let evmEBase : EVM.State := - { initState cA gh bl σ_evm σ₀ g A I with - accountMap := σ'_evm - substate := A'_solm - createdAccounts := cA' } - let evmSBase : EVM.State := - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } - have houtSmall : out.size < 2 ^ 138 := by - exact Theta_returnData_size_lt_2pow138_of_eq - (blob := I.blobVersionedHashes) (cA := cA') - (gh := (initState cA gh bl σ_evm σ₀ g A I).genesisBlockHeader) - (blocks := (initState cA gh bl σ_evm σ₀ g A I).blocks) - (σ := σ'_evm) - (σ₀ := (initState cA gh bl σ_evm σ₀ g A I).σ₀) - (A := A_in) - (s := AccountAddress.ofUInt256 (UInt256.ofNat I.codeOwner)) - (o := I.sender) - (r := AccountAddress.ofUInt256 (setRewardConfigWrapperDecimalsTargetWord I)) - (c := toExecute σ'_evm - (AccountAddress.ofUInt256 (setRewardConfigWrapperDecimalsTargetWord I))) - (g := callGas) (p := UInt256.ofNat I.gasPrice) - (v := ⟨0⟩) (v' := ⟨0⟩) - (d := (setRewardConfigWrapperDecimalsCalldataMem I baseOut).readWithPadding 160 4) - (e := I.depth + 1) (H := I.header) (w := false) - hΘeq - (by exact Ethereum.EVM.ByteArray.readWithPadding_size_lt_uint256 _ _ _) - have houtSign : out.size < 2 ^ 255 := by omega - have hdepthNeI : I.depth ≠ 1024 := by - intro hEq - rw [hEq] at hdepth - exact absurd hdepth (by decide) - have hdepthNe : evmEBase.executionEnv.depth ≠ 1024 := by - simpa [evmEBase, initState] using hdepthNeI - have htgt := setRewardConfigWrapperDecimalsTarget_eq_targetWord I hcanon1 - have hcd := setRewardConfigWrapperDecimalsCalldataMem_encode I baseOut - have hcallE : - typedCallViaEVM config evmEBase - (EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - "decimals" 0 [] - (z, - { evmEBase with - accountMap := σ''_evm - substate := A''_evm - createdAccounts := cA'' }, - out) false := by - refine callCoincides - (cfg := config) (evm := evmEBase) - (name := "decimals") (args := []) - (tgt := EVM.address (AccountAddress.ofNat (setRewardConfigTokenWord I).toNat)) - (targetWord := setRewardConfigWrapperDecimalsTargetWord I) - (cA' := cA'') (σ' := σ''_evm) (A' := A''_evm) (A_in := A_in) - (z := z) (o := out) (g'' := g'') (callGas := callGas) - (mem := setRewardConfigWrapperDecimalsCalldataMem I baseOut) - (inOff := ⟨160⟩) (inSize := ⟨4⟩) (callPerm := false) - hdepthNe htgt hcd ?_ - simpa [evmEBase, initState] using hΘeq - obtain ⟨σ''_solm, A''_solm, hcallSolm, hPostAccounts'⟩ := - typedCallViaEVM_accountMapEquiv - (evm_solm := evmSBase) hcallE - (by simpa [evmEBase, evmSBase, initState] using hPostAccounts) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase]) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase]) - (by simp [evmEBase, evmSBase, initState]) - exact ⟨cA'', σ''_evm, σ''_solm, A''_solm, z, out, k', C', - by - simpa [evmSBase, initState] using hcallSolm, - hPostAccounts', - by - simpa [setRewardConfigWrapperDecimalsPostCallStack, - setRewardConfigWrapperDecimalsPostCallTail, setRewardConfigWrapperDecimalsPostCallMem, - setRewardConfigWrapperDecimalsPostCallAw] using rd1154, - houtSign⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_after_decimals_failure - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1154⟩ - (setRewardConfigWrapperDecimalsPostCallStack false baseWord I) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C) - (hbase32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hdecSize : decOut.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have rd1154 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1154⟩ - [⟨0⟩, ⟨160⟩, baseWord, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, setRewardConfigWrapperDecimalsTargetWord I, - ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C := by - simpa [setRewardConfigWrapperDecimalsPostCallStack, - setRewardConfigWrapperDecimalsPostCallTail] using rd - have rd741 := evm_run rd1154 with [ - swap1, dup2, iszero, push2 ⟨741⟩, jumpiT (by native_decide) (by jump_dest)] - have rd744 := evm_run rd741 with [ - jumpdest, dup11, - raw mload 0 ⟨160⟩ setRewardConfigWrapperDecimalsPostCallAw (by native_decide) - mem_cost - (setRewardConfigWrapperDecimalsPostCallMem_mload64 I hbase32 hbaseSize hdecSize) - (by native_decide) (by evm_ov)] - let rdsz : UInt256 := UInt256.ofNat decOut.size - have hrdsz_toNat : rdsz.toNat = decOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hdecSize - have rd748pre := evm_run rd744 with [returndatasize, push1 ⟨0⟩, dup3] - let mem2 : ByteArray := - decOut.write 0 (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) 160 rdsz.toNat - let aw2 : UInt256 := - UInt256.ofNat (MachineState.M setRewardConfigWrapperDecimalsPostCallAw.toNat 160 rdsz.toNat) - have rd748 := RD.returndatacopy - (Cₘ aw2 - Cₘ setRewardConfigWrapperDecimalsPostCallAw) mem2 aw2 rd748pre - (by native_decide) - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, hrdsz_toNat]; omega) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, aw2, rdsz] - rw [show (⟨160⟩ : UInt256).toNat = 160 from rfl]) - (by rfl) - (by rfl) - (by simp) - have rd751 := evm_run rd748 with [returndatasize, swap1] - exact RD.rev - (Cₘ (UInt256.ofNat (MachineState.M aw2.toNat 160 rdsz.toNat)) - Cₘ aw2) - rd751 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, rdsz] - rw [show (⟨160⟩ : UInt256).toNat = 160 from rfl]) - (by simp) - -noncomputable abbrev setRewardConfigWrapperDecimalsPostShortDecodeMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) : ByteArray := - (UInt256.toByteArray ((⟨160⟩ : UInt256) + - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat decOut.size + ⟨31⟩))).write 0 - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) 64 32 - -noncomputable abbrev setRewardConfigWrapperDecimalsPostDecodeMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) : ByteArray := - (UInt256.toByteArray (⟨192⟩ : UInt256)).write 0 - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) 64 32 - -theorem setRewardConfigWrapperDecimalsPostCallMem_read160_of_size_ge - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut).readWithPadding 160 32 = - decOut.extract 0 32 := by - unfold setRewardConfigWrapperDecimalsPostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := decOut.size) - (by decide) hdec32 hdecSize - rw [hlen] - rw [write32_read_back decOut (setRewardConfigWrapperDecimalsCalldataMem I baseOut) 160 - (by exact hdec32) - (by - have hbase := setRewardConfigWrapperDecimalsCalldataMem_size_ge192 I baseOut - omega)] - -theorem setRewardConfigWrapperDecimalsPostCallMem_size_ge192 - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 192 ≤ (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut).size := by - unfold setRewardConfigWrapperDecimalsPostCallMem - have hbase := setRewardConfigWrapperDecimalsCalldataMem_size_ge192 I baseOut - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := decOut.size) - (by decide) hdec32 hdecSize - rw [hlen] - exact le_trans hbase - (byteArray_write_size_ge_base_of_le decOut - (setRewardConfigWrapperDecimalsCalldataMem I baseOut) hdec32 (by omega)) - -theorem setRewardConfigWrapperDecimalsPostDecodeMem_read160_of_size_ge - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut).readWithPadding 160 32 = - decOut.extract 0 32 := by - unfold setRewardConfigWrapperDecimalsPostDecodeMem - rw [write32_read_above (UInt256.toByteArray (⟨192⟩ : UInt256)) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) 64 160 - (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigWrapperDecimalsPostCallMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize)) - (by omega) - (by - exact le_trans (by omega) - (setRewardConfigWrapperDecimalsPostCallMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize))] - exact setRewardConfigWrapperDecimalsPostCallMem_read160_of_size_ge I hdec32 hdecSize - -theorem setRewardConfigWrapperDecimalsPostDecodeMem_mload160_of_size_ge - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨160⟩ : UInt256).toNat ≥ - (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut).size - ∨ (⟨160⟩ : UInt256) ≥ setRewardConfigWrapperDecimalsPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut).readWithPadding - (⟨160⟩ : UInt256).toNat 32))) = - UInt256.ofNat (fromByteArrayBigEndian (decOut.extract 0 32)) := by - exact mloadValue_eq_readWithPadding_of_lt_size - (mem := setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut) - (aw := setRewardConfigWrapperDecimalsPostCallAw) - (off := ⟨160⟩) - (memSize := (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut).size) - rfl - (by - rw [show (⟨160⟩ : UInt256).toNat = 160 from by decide] - unfold setRewardConfigWrapperDecimalsPostDecodeMem - rw [write32_eq (UInt256.toByteArray (⟨192⟩ : UInt256)) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) 64 - (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigWrapperDecimalsPostCallMem_size_ge192 I hdec32 hdecSize))] - simp - have hsz := setRewardConfigWrapperDecimalsPostCallMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize - omega) - (by native_decide) - |>.trans (by - rw [show (⟨160⟩ : UInt256).toNat = 160 from by decide, - setRewardConfigWrapperDecimalsPostDecodeMem_read160_of_size_ge I hdec32 hdecSize]) - -theorem setRewardConfigWrapperDecimalsPostDecodeMem_mload64_of_size_ge - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ - (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut).size - ∨ (⟨64⟩ : UInt256) ≥ setRewardConfigWrapperDecimalsPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨192⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := setRewardConfigWrapperDecimalsPostCallAw) (v := ⟨192⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigWrapperDecimalsPostDecodeMem - rw [write32_eq (UInt256.toByteArray (⟨192⟩ : UInt256)) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) 64 - (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigWrapperDecimalsPostCallMem_size_ge192 I hdec32 hdecSize))] - simp - have hsz := setRewardConfigWrapperDecimalsPostCallMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigWrapperDecimalsPostDecodeMem - rw [write32_read_back _ _ 64 (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigWrapperDecimalsPostCallMem_size_ge192 I hdec32 hdecSize))] - rw [show (UInt256.toByteArray (⟨192⟩ : UInt256)).extract 0 32 = - UInt256.toByteArray (⟨192⟩ : UInt256) by - rw [show 32 = (UInt256.toByteArray (⟨192⟩ : UInt256)).size by - rw [toByteArray_size]] - exact byteArray_extract_self _]) - -theorem setRewardConfigWrapperDecimalsPostDecodeMem_size_ge192 - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 192 ≤ (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut).size := by - unfold setRewardConfigWrapperDecimalsPostDecodeMem - exact le_trans - (setRewardConfigWrapperDecimalsPostCallMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize) - (byteArray_write_size_ge_base_of_le (UInt256.toByteArray (⟨192⟩ : UInt256)) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) (by rw [toByteArray_size]) - (by - have hbase := - setRewardConfigWrapperDecimalsPostCallMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize - omega)) - -noncomputable def setRewardConfigWrapperSuccessFreeMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) : ByteArray := - Reasoning.Theory.writeWord (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut) - 64 ⟨320⟩ - -noncomputable def setRewardConfigWrapperSuccessTokenMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) : ByteArray := - Reasoning.Theory.writeWord (setRewardConfigWrapperSuccessFreeMem I baseOut decOut) 192 - (setRewardConfigWrapperDecimalsTargetWord I) - -noncomputable def setRewardConfigWrapperSuccessRescaleMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale : UInt256) : ByteArray := - Reasoning.Theory.writeWord (setRewardConfigWrapperSuccessTokenMem I baseOut decOut) 224 rescale - -noncomputable def setRewardConfigWrapperSuccessBitMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale bit : UInt256) : ByteArray := - Reasoning.Theory.writeWord (setRewardConfigWrapperSuccessRescaleMem I baseOut decOut rescale) - 256 bit - -noncomputable def setRewardConfigWrapperSuccessMultiplierMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale bit : UInt256) : ByteArray := - Reasoning.Theory.writeWord (setRewardConfigWrapperSuccessBitMem I baseOut decOut rescale bit) - 288 setRewardConfigMultiplierWord - -noncomputable def setRewardConfigWrapperSuccessCometMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale bit : UInt256) : ByteArray := - Reasoning.Theory.writeWord - (setRewardConfigWrapperSuccessMultiplierMem I baseOut decOut rescale bit) - 0 (setRewardConfigCometWord I) - -noncomputable def setRewardConfigWrapperSuccessArgsMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale bit : UInt256) : ByteArray := - Reasoning.Theory.writeWord - (setRewardConfigWrapperSuccessCometMem I baseOut decOut rescale bit) 32 ⟨1⟩ - -theorem setRewardConfigWrapperSuccessFreeMem_size_ge192 - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 192 ≤ (setRewardConfigWrapperSuccessFreeMem I baseOut decOut).size := by - unfold setRewardConfigWrapperSuccessFreeMem Reasoning.Theory.writeWord - have hbase := setRewardConfigWrapperDecimalsPostDecodeMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize - exact le_trans hbase - (byteArray_write_size_ge_base_of_le (UInt256.toByteArray (⟨320⟩ : UInt256)) - (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut) - (by rw [toByteArray_size]) (by omega)) - -theorem setRewardConfigWrapperSuccessTokenMem_size_ge224 - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 224 ≤ (setRewardConfigWrapperSuccessTokenMem I baseOut decOut).size := by - have hfree := setRewardConfigWrapperSuccessFreeMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize - unfold setRewardConfigWrapperSuccessTokenMem - rw [writeWord_size] - · omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 192 (by norm_num)) - -theorem setRewardConfigWrapperSuccessRescaleMem_size_ge256 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 256 ≤ (setRewardConfigWrapperSuccessRescaleMem I baseOut decOut rescale).size := by - have htoken := setRewardConfigWrapperSuccessTokenMem_size_ge224 I (baseOut := baseOut) - hdec32 hdecSize - unfold setRewardConfigWrapperSuccessRescaleMem - rw [writeWord_size] - · omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 224 (by norm_num)) - -theorem setRewardConfigWrapperSuccessBitMem_size_ge288 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 288 ≤ (setRewardConfigWrapperSuccessBitMem I baseOut decOut rescale bit).size := by - have hrescale := setRewardConfigWrapperSuccessRescaleMem_size_ge256 I (baseOut := baseOut) - rescale hdec32 hdecSize - unfold setRewardConfigWrapperSuccessBitMem - rw [writeWord_size] - · omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 256 (by norm_num)) - -theorem setRewardConfigWrapperSuccessMultiplierMem_size_ge320 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 320 ≤ (setRewardConfigWrapperSuccessMultiplierMem I baseOut decOut rescale bit).size := by - have hbit := setRewardConfigWrapperSuccessBitMem_size_ge288 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - unfold setRewardConfigWrapperSuccessMultiplierMem - rw [writeWord_size] - · omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 288 (by norm_num)) - -theorem setRewardConfigWrapperSuccessCometMem_size_ge320 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 320 ≤ (setRewardConfigWrapperSuccessCometMem I baseOut decOut rescale bit).size := by - unfold setRewardConfigWrapperSuccessCometMem - rw [writeWord_size] - · have hmul := setRewardConfigWrapperSuccessMultiplierMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - -theorem setRewardConfigWrapperSuccessArgsMem_size_ge320 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 320 ≤ (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).size := by - unfold setRewardConfigWrapperSuccessArgsMem - rw [writeWord_size] - · have hcomet := setRewardConfigWrapperSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - -theorem setRewardConfigWrapperSuccessArgsMem_read0 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 0 32 = - UInt256.toByteArray (setRewardConfigCometWord I) := by - unfold setRewardConfigWrapperSuccessArgsMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessCometMem - rw [writeWord_read_back] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - · left - have hcomet := setRewardConfigWrapperSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - constructor <;> omega - -theorem setRewardConfigWrapperSuccessArgsMem_read32 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 32 32 = - UInt256.toByteArray (⟨1⟩ : UInt256) := by - unfold setRewardConfigWrapperSuccessArgsMem - rw [writeWord_read_back] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - -theorem setRewardConfigWrapperSuccessArgsMem_read0_64 - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 0 64 = - UInt256.toByteArray (setRewardConfigCometWord I) ++ - UInt256.toByteArray (⟨1⟩ : UInt256) := by - rw [byteArray_readWithPadding_split _ 0 32 32 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num)] - · rw [setRewardConfigWrapperSuccessArgsMem_read0 I rescale bit hdec32 hdecSize, - setRewardConfigWrapperSuccessArgsMem_read32 I rescale bit hdec32 hdecSize] - · have hsize := setRewardConfigWrapperSuccessArgsMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega - -theorem setRewardConfigWrapperSuccessArgsMem_keccakSlot - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC - ((setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding - 0 64))) = - solcMappingSlot ⟨1⟩ (setRewardConfigCometWord I) := by - rw [setRewardConfigWrapperSuccessArgsMem_read0_64 I baseOut decOut rescale bit - hdec32 hdecSize] - unfold solcMappingSlot - exact mappingSlot_single (setRewardConfigCometWord I) ⟨1⟩ - -theorem setRewardConfigWrapperSuccessArgsMem_read64 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 64 32 = - UInt256.toByteArray (⟨320⟩ : UInt256) := by - unfold setRewardConfigWrapperSuccessArgsMem setRewardConfigWrapperSuccessCometMem - rw [writeWord_read_preserved, writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessMultiplierMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessBitMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessRescaleMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessTokenMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessFreeMem - rw [writeWord_read_back] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 64 (by norm_num)) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 192 (by norm_num)) - · left - have hfree := setRewardConfigWrapperSuccessFreeMem_size_ge192 I - (baseOut := baseOut) hdec32 hdecSize - constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 224 (by norm_num)) - · left - have htoken := setRewardConfigWrapperSuccessTokenMem_size_ge224 I - (baseOut := baseOut) hdec32 hdecSize - constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 256 (by norm_num)) - · left - have hrescale := setRewardConfigWrapperSuccessRescaleMem_size_ge256 I - (baseOut := baseOut) rescale hdec32 hdecSize - constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 288 (by norm_num)) - · left - have hbit := setRewardConfigWrapperSuccessBitMem_size_ge288 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - · right - have hmul := setRewardConfigWrapperSuccessMultiplierMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - · right - have hcomet : - 320 ≤ (Reasoning.Theory.writeWord - (setRewardConfigWrapperSuccessMultiplierMem I baseOut decOut rescale bit) 0 - (setRewardConfigCometWord I)).size := by - simpa [setRewardConfigWrapperSuccessCometMem] using - setRewardConfigWrapperSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - constructor <;> omega - -theorem setRewardConfigWrapperSuccessArgsMem_mload64 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).size - ∨ (⟨64⟩ : UInt256) ≥ (⟨10⟩ : UInt256) * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨320⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := (⟨10⟩ : UInt256)) (v := ⟨320⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - have hsize := setRewardConfigWrapperSuccessArgsMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact setRewardConfigWrapperSuccessArgsMem_read64 I rescale bit hdec32 hdecSize) - -theorem setRewardConfigWrapperSuccessArgsMem_read192 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 192 32 = - UInt256.toByteArray (setRewardConfigWrapperDecimalsTargetWord I) := by - have htoken := setRewardConfigWrapperSuccessTokenMem_size_ge224 I (baseOut := baseOut) - hdec32 hdecSize - have hrescale := setRewardConfigWrapperSuccessRescaleMem_size_ge256 I (baseOut := baseOut) - rescale hdec32 hdecSize - have hbit := setRewardConfigWrapperSuccessBitMem_size_ge288 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hmul := setRewardConfigWrapperSuccessMultiplierMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hcomet := setRewardConfigWrapperSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - unfold setRewardConfigWrapperSuccessArgsMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessCometMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessMultiplierMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessBitMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessRescaleMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessTokenMem - rw [writeWord_read_back] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 192 (by norm_num)) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 224 (by norm_num)) - · left; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 256 (by norm_num)) - · left; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 288 (by norm_num)) - · left; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - · right; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - · right; constructor <;> omega - -theorem setRewardConfigWrapperSuccessArgsMem_read224 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 224 32 = - UInt256.toByteArray rescale := by - have hrescale := setRewardConfigWrapperSuccessRescaleMem_size_ge256 I (baseOut := baseOut) - rescale hdec32 hdecSize - have hbit := setRewardConfigWrapperSuccessBitMem_size_ge288 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hmul := setRewardConfigWrapperSuccessMultiplierMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hcomet := setRewardConfigWrapperSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - unfold setRewardConfigWrapperSuccessArgsMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessCometMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessMultiplierMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessBitMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessRescaleMem - rw [writeWord_read_back] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 224 (by norm_num)) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 256 (by norm_num)) - · left; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 288 (by norm_num)) - · left; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - · right; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - · right; constructor <;> omega - -theorem setRewardConfigWrapperSuccessArgsMem_read256 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 256 32 = - UInt256.toByteArray bit := by - have hbit := setRewardConfigWrapperSuccessBitMem_size_ge288 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hmul := setRewardConfigWrapperSuccessMultiplierMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hcomet := setRewardConfigWrapperSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - unfold setRewardConfigWrapperSuccessArgsMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessCometMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessMultiplierMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessBitMem - rw [writeWord_read_back] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 256 (by norm_num)) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 288 (by norm_num)) - · left; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - · right; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - · right; constructor <;> omega - -theorem setRewardConfigWrapperSuccessArgsMem_read288 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 288 32 = - UInt256.toByteArray setRewardConfigMultiplierWord := by - have hmul := setRewardConfigWrapperSuccessMultiplierMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hcomet := setRewardConfigWrapperSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - unfold setRewardConfigWrapperSuccessArgsMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessCometMem - rw [writeWord_read_preserved] - · unfold setRewardConfigWrapperSuccessMultiplierMem - rw [writeWord_read_back] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 288 (by norm_num)) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - · right; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - · right; constructor <;> omega - -theorem setRewardConfigWrapperSuccessArgsMem_mload192 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨192⟩ : UInt256).toNat ≥ - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).size - ∨ (⟨192⟩ : UInt256) ≥ (⟨10⟩ : UInt256) * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding - (⟨192⟩ : UInt256).toNat 32))) = - setRewardConfigWrapperDecimalsTargetWord I := by - exact mloadWordValue_of_readWithPadding - (off := (⟨192⟩ : UInt256)) (aw := (⟨10⟩ : UInt256)) - (v := setRewardConfigWrapperDecimalsTargetWord I) - (by - rw [show (⟨192⟩ : UInt256).toNat = 192 from by decide] - have hsize := setRewardConfigWrapperSuccessArgsMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega) - (by native_decide) - (by - rw [show (⟨192⟩ : UInt256).toNat = 192 from by decide] - exact setRewardConfigWrapperSuccessArgsMem_read192 I rescale bit hdec32 hdecSize) - -theorem setRewardConfigWrapperSuccessArgsMem_mload224 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨224⟩ : UInt256).toNat ≥ - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).size - ∨ (⟨224⟩ : UInt256) ≥ (⟨10⟩ : UInt256) * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding - (⟨224⟩ : UInt256).toNat 32))) = rescale := by - exact mloadWordValue_of_readWithPadding - (off := (⟨224⟩ : UInt256)) (aw := (⟨10⟩ : UInt256)) (v := rescale) - (by - rw [show (⟨224⟩ : UInt256).toNat = 224 from by decide] - have hsize := setRewardConfigWrapperSuccessArgsMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega) - (by native_decide) - (by - rw [show (⟨224⟩ : UInt256).toNat = 224 from by decide] - exact setRewardConfigWrapperSuccessArgsMem_read224 I rescale bit hdec32 hdecSize) - -theorem setRewardConfigWrapperSuccessArgsMem_mload256 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨256⟩ : UInt256).toNat ≥ - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).size - ∨ (⟨256⟩ : UInt256) ≥ (⟨10⟩ : UInt256) * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding - (⟨256⟩ : UInt256).toNat 32))) = bit := by - exact mloadWordValue_of_readWithPadding - (off := (⟨256⟩ : UInt256)) (aw := (⟨10⟩ : UInt256)) (v := bit) - (by - rw [show (⟨256⟩ : UInt256).toNat = 256 from by decide] - have hsize := setRewardConfigWrapperSuccessArgsMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega) - (by native_decide) - (by - rw [show (⟨256⟩ : UInt256).toNat = 256 from by decide] - exact setRewardConfigWrapperSuccessArgsMem_read256 I rescale bit hdec32 hdecSize) - -theorem setRewardConfigWrapperSuccessArgsMem_mload288 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨288⟩ : UInt256).toNat ≥ - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).size - ∨ (⟨288⟩ : UInt256) ≥ (⟨10⟩ : UInt256) * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale bit).readWithPadding - (⟨288⟩ : UInt256).toNat 32))) = setRewardConfigMultiplierWord := by - exact mloadWordValue_of_readWithPadding - (off := (⟨288⟩ : UInt256)) (aw := (⟨10⟩ : UInt256)) - (v := setRewardConfigMultiplierWord) - (by - rw [show (⟨288⟩ : UInt256).toNat = 288 from by decide] - have hsize := setRewardConfigWrapperSuccessArgsMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega) - (by native_decide) - (by - rw [show (⟨288⟩ : UInt256).toNat = 288 from by decide] - exact setRewardConfigWrapperSuccessArgsMem_read288 I rescale bit hdec32 hdecSize) - -set_option maxHeartbeats 1000000 in -private theorem setRewardConfigWrapperSlot0RuntimeBase_toNat - (old token rescale : UInt256) : - (UInt256.lor - (UInt256.lor - (UInt256.land (UInt256.shiftLeft (⟨0xffffff⟩ : UInt256) ⟨232⟩) old) - (UInt256.land token solcAddrMask)) - (UInt256.land (UInt256.shiftLeft rescale ⟨160⟩) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)))).toNat = - token.toNat % 2 ^ 160 + 2 ^ 160 * (rescale.toNat % 2 ^ 64) + - 2 ^ 232 * (old.toNat / 2 ^ 232) := by - let low : Nat := token.toNat % 2 ^ 160 - let mid : Nat := rescale.toNat % 2 ^ 64 - let high : Nat := old.toNat / 2 ^ 232 - have hlow : low < 2 ^ 160 := by - exact Nat.mod_lt _ (by norm_num) - have hmid : mid < 2 ^ 64 := by - exact Nat.mod_lt _ (by norm_num) - have hhigh : high < 2 ^ 24 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 232 * 2 ^ 24 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - exact old.val.isLt - have hpackedLt : - low + 2 ^ 160 * mid + 2 ^ 232 * high < UInt256.size := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hmidle : mid ≤ 2 ^ 64 - 1 := Nat.le_pred_of_lt hmid - have hhighle : high ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hhigh - have hmidterm : 2 ^ 160 * mid ≤ 2 ^ 160 * (2 ^ 64 - 1) := - Nat.mul_le_mul_left _ hmidle - have hhiterm : 2 ^ 232 * high ≤ 2 ^ 232 * (2 ^ 24 - 1) := - Nat.mul_le_mul_left _ hhighle - have hmax : (2 ^ 160 - 1) + 2 ^ 160 * (2 ^ 64 - 1) + - 2 ^ 232 * (2 ^ 24 - 1) < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - have htokenLow : - (UInt256.land token solcAddrMask).toNat = low := by - rw [u256_land_toNat] - have hmask : solcAddrMask.toNat = 2 ^ 160 - 1 := by - native_decide - rw [hmask, nat_land_mask_eq_mod] - have hlt : token.toNat % 2 ^ 160 < UInt256.size := by - have h := Nat.mod_lt token.toNat (by norm_num : 0 < 2 ^ 160) - norm_num [UInt256.size] at h ⊢ - omega - rw [Nat.mod_eq_of_lt hlt] - have hOldHigh : - (((⟨0xffffff⟩ : UInt256).shiftLeft ⟨232⟩).land old).toNat = - high * 2 ^ 232 := by - rw [u256_land_toNat] - have hmask : (((⟨0xffffff⟩ : UInt256).shiftLeft ⟨232⟩).toNat) = - 2 ^ 256 - 2 ^ 232 := by - native_decide - rw [hmask] - rw [nat_land_comm] - rw [natLandClearLow old.toNat 232 (by norm_num) (by - change old.val.val < 2 ^ 256 - exact old.val.isLt)] - have hlt : old.toNat / 2 ^ 232 * 2 ^ 232 < UInt256.size := - lt_of_le_of_lt (Nat.div_mul_le_self _ _) old.val.isLt - rw [Nat.mod_eq_of_lt hlt] - have hlowHigh : - ((((⟨0xffffff⟩ : UInt256).shiftLeft ⟨232⟩).land old).lor - (token.land solcAddrMask)).toNat = - low + high * 2 ^ 232 := by - rw [u256_lor_toNat, hOldHigh, htokenLow] - rw [nat_lor_comm] - rw [nat_lor_shift_add low high 232 - (lt_of_lt_of_le hlow (Nat.pow_le_pow_right (by norm_num) (by norm_num)))] - have hlt : low + high * 2 ^ 232 < UInt256.size := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hhighle : high ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hhigh - have hhiterm : high * 2 ^ 232 ≤ (2 ^ 24 - 1) * 2 ^ 232 := - Nat.mul_le_mul_right _ hhighle - have hmax : (2 ^ 160 - 1) + (2 ^ 24 - 1) * 2 ^ 232 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - rw [Nat.mod_eq_of_lt hlt] - have hmidWord : - ((rescale.shiftLeft ⟨160⟩).land - (((⟨1⟩ : UInt256).shiftLeft ⟨224⟩).sub - ((⟨1⟩ : UInt256).shiftLeft ⟨160⟩))).toNat = - mid * 2 ^ 160 := by - rw [u256_land_toNat] - have hmask : - ((((⟨1⟩ : UInt256).shiftLeft ⟨224⟩).sub - ((⟨1⟩ : UInt256).shiftLeft ⟨160⟩)).toNat) = - (2 : Nat) ^ 224 - 2 ^ 160 := by - native_decide - have hshift : - (rescale.shiftLeft ⟨160⟩).toNat = - (rescale.toNat <<< 160) % 2 ^ 256 := by - unfold UInt256.shiftLeft UInt256.toNat - show (Fin.shiftLeft rescale.val (⟨160⟩ : UInt256).val).val = _ - unfold Fin.shiftLeft - rw [show (⟨160⟩ : UInt256).val = 160 by rfl] - change (rescale.toNat <<< 160) % UInt256.size = - (rescale.toNat <<< 160) % 2 ^ 256 - norm_num [UInt256.size] - rw [hshift, hmask, setRewardConfigNatLandShiftLeft160_mid64] - have hlt : mid * 2 ^ 160 < UInt256.size := by - calc - mid * 2 ^ 160 < 2 ^ 64 * 2 ^ 160 := - Nat.mul_lt_mul_of_pos_right hmid (by norm_num) - _ = 2 ^ 224 := by rw [← Nat.pow_add] - _ < UInt256.size := by norm_num [UInt256.size] - rw [Nat.mod_eq_of_lt hlt] - rw [u256_lor_toNat, hlowHigh, hmidWord] - have hlor : - Nat.lor (low + high * 2 ^ 232) (mid * 2 ^ 160) = - low + mid * 2 ^ 160 + high * 2 ^ 232 := by - rw [show high * 2 ^ 232 = (high * 2 ^ 8) * 2 ^ 224 by ring] - exact setRewardConfigNatLorPacked160_224 low mid (high * 2 ^ 8) hlow hmid - rw [hlor] - rw [show low + mid * 2 ^ 160 + high * 2 ^ 232 = - low + 2 ^ 160 * mid + 2 ^ 232 * high by ring] - exact Nat.mod_eq_of_lt hpackedLt - -private theorem setRewardConfigWrapperSlot0Down_bytecodeExpr_runtime - (old token rescale : UInt256) : - UInt256.lor - (UInt256.lor - (UInt256.lor - (UInt256.land (UInt256.shiftLeft (⟨0xffffff⟩ : UInt256) ⟨232⟩) old) - (UInt256.land token solcAddrMask)) - (UInt256.land (UInt256.shiftLeft rescale ⟨160⟩) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)))) - (UInt256.land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨0⟩ : UInt256))) ⟨224⟩) - (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩)) = - setRewardConfigSlot0Down old token rescale := by - apply u256_inj - have hprefix : - UInt256.land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨0⟩ : UInt256))) ⟨224⟩) - (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩) = (⟨0⟩ : UInt256) := by - native_decide - rw [hprefix, u256_lor_zero, setRewardConfigSlot0Down_toNat] - exact setRewardConfigWrapperSlot0RuntimeBase_toNat old token rescale - -set_option maxHeartbeats 1000000 in -private theorem setRewardConfigWrapperSlot0Up_bytecodeExpr_runtime_toNat - (old token rescale : UInt256) : - (UInt256.lor - (UInt256.lor - (UInt256.lor - (UInt256.land (UInt256.shiftLeft (⟨0xffffff⟩ : UInt256) ⟨232⟩) old) - (UInt256.land token solcAddrMask)) - (UInt256.land (UInt256.shiftLeft rescale ⟨160⟩) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)))) - (UInt256.land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨1⟩ : UInt256))) ⟨224⟩) - (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩))).toNat = - token.toNat % 2 ^ 160 + 2 ^ 160 * (rescale.toNat % 2 ^ 64) + - 2 ^ 224 + 2 ^ 232 * (old.toNat / 2 ^ 232) := by - let low : Nat := token.toNat % 2 ^ 160 - let mid : Nat := rescale.toNat % 2 ^ 64 - let high : Nat := old.toNat / 2 ^ 232 - have hlow : low < 2 ^ 160 := by - exact Nat.mod_lt _ (by norm_num) - have hmid : mid < 2 ^ 64 := by - exact Nat.mod_lt _ (by norm_num) - have hhigh : high < 2 ^ 24 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 232 * 2 ^ 24 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - exact old.val.isLt - have hlow224 : low + 2 ^ 160 * mid < 2 ^ 224 := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hmidle : mid ≤ 2 ^ 64 - 1 := Nat.le_pred_of_lt hmid - have hmidterm : 2 ^ 160 * mid ≤ 2 ^ 160 * (2 ^ 64 - 1) := - Nat.mul_le_mul_left _ hmidle - have hmax : (2 ^ 160 - 1) + 2 ^ 160 * (2 ^ 64 - 1) < 2 ^ 224 := by - norm_num [Nat.pow_add] - omega - have hfinalLt : - low + 2 ^ 160 * mid + 2 ^ 224 + 2 ^ 232 * high < UInt256.size := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hmidle : mid ≤ 2 ^ 64 - 1 := Nat.le_pred_of_lt hmid - have hhighle : high ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hhigh - have hmidterm : 2 ^ 160 * mid ≤ 2 ^ 160 * (2 ^ 64 - 1) := - Nat.mul_le_mul_left _ hmidle - have hhiterm : 2 ^ 232 * high ≤ 2 ^ 232 * (2 ^ 24 - 1) := - Nat.mul_le_mul_left _ hhighle - have hmax : (2 ^ 160 - 1) + 2 ^ 160 * (2 ^ 64 - 1) + 2 ^ 224 + - 2 ^ 232 * (2 ^ 24 - 1) < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - have hbase : - (UInt256.lor - (UInt256.lor - (UInt256.land (UInt256.shiftLeft (⟨0xffffff⟩ : UInt256) ⟨232⟩) old) - (UInt256.land token solcAddrMask)) - (UInt256.land (UInt256.shiftLeft rescale ⟨160⟩) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)))).toNat = - low + 2 ^ 160 * mid + 2 ^ 232 * high := by - simpa [low, mid, high] using - setRewardConfigWrapperSlot0RuntimeBase_toNat old token rescale - have hprefix : - (UInt256.land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨1⟩ : UInt256))) ⟨224⟩) - (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩)).toNat = 2 ^ 224 := by - native_decide - rw [u256_lor_toNat, hbase, hprefix] - have hlor : - Nat.lor (low + 2 ^ 160 * mid + 2 ^ 232 * high) (2 ^ 224) = - low + 2 ^ 160 * mid + 2 ^ 224 + 2 ^ 232 * high := by - rw [show low + 2 ^ 160 * mid + 2 ^ 232 * high = - (low + 2 ^ 160 * mid) + high * 2 ^ 232 by ring] - rw [show (2 : Nat) ^ 224 = 1 * 2 ^ 224 by ring] - rw [setRewardConfigNatLorPacked224_232 (low + 2 ^ 160 * mid) 1 high - hlow224 (by norm_num)] - ring - rw [hlor, Nat.mod_eq_of_lt hfinalLt] - -private theorem setRewardConfigWrapperSlot0Up_bytecodeExpr_runtime - (old token rescale : UInt256) : - UInt256.lor - (UInt256.lor - (UInt256.lor - (UInt256.land (UInt256.shiftLeft (⟨0xffffff⟩ : UInt256) ⟨232⟩) old) - (UInt256.land token solcAddrMask)) - (UInt256.land (UInt256.shiftLeft rescale ⟨160⟩) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)))) - (UInt256.land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨1⟩ : UInt256))) ⟨224⟩) - (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩)) = - setRewardConfigSlot0Up old token rescale := by - apply u256_inj - rw [setRewardConfigWrapperSlot0Up_bytecodeExpr_runtime_toNat, - setRewardConfigSlot0Up_toNat] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigX_after_decimals_short_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1154⟩ - (setRewardConfigWrapperDecimalsPostCallStack true baseWord I) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C) - (hshort : decOut.size < 32) - (hdecSize : decOut.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let rdsz : UInt256 := UInt256.ofNat decOut.size - have hrdsz_toNat : rdsz.toNat = decOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hdecSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨1⟩ := by - apply ugt_one - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hshort - have rd1154 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1154⟩ - [⟨1⟩, ⟨160⟩, baseWord, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, setRewardConfigWrapperDecimalsTargetWord I, - ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C := by - simpa [setRewardConfigWrapperDecimalsPostCallStack, - setRewardConfigWrapperDecimalsPostCallTail] using rd - have rd1506₀ := evm_run rd1154 with [ - swap1, dup2, iszero, push2 ⟨741⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨1499⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, dup5, dup2, dup2, returndatasize, dup4, gt] - have rd1506 := rd1506₀ - rw [show UInt256.ofNat decOut.size = rdsz from rfl, hgt] at rd1506 - let rounded : UInt256 := - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat decOut.size + ⟨31⟩) - let ptr : UInt256 := (⟨160⟩ : UInt256) + rounded - have hroundedLe : rounded.toNat ≤ decOut.size + 31 := by - unfold rounded - rw [uland_toNat] - refine le_trans Nat.and_le_right ?_ - rw [uadd_toNat, UInt256.toNat_ofNat_of_lt hdecSize, - show (⟨31⟩ : UInt256).toNat = 31 from by decide] - exact Nat.mod_le _ _ - have hptr_toNat : ptr.toNat = 160 + rounded.toNat := by - unfold ptr - rw [uadd_toNat, show (⟨160⟩ : UInt256).toNat = 160 from by decide] - exact Nat.mod_eq_of_lt (by - have hroundSmall : rounded.toNat < 64 := by omega - have hsz : UInt256.size = 2 ^ 256 := by decide - omega) - have hltPtr : UInt256.lt ptr (⟨160⟩ : UInt256) = ⟨0⟩ := by - apply ult_zero - rw [hptr_toNat, show (⟨160⟩ : UInt256).toNat = 160 from by decide] - omega - have hmax64 : - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩).toNat = - 18446744073709551615 := by - native_decide - have hgtPtr : - UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - rw [hptr_toNat, hmax64] - omega - have hallocOk : - UInt256.lor (UInt256.lt ptr (⟨160⟩ : UInt256)) - (UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = ⟨0⟩ := by - rw [hltPtr, hgtPtr] - native_decide - have rd3071 := evm_run rd1506 with [ - push2 ⟨1548⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, pop, returndatasize, push2 ⟨1510⟩, jump (by jump_dest), - jumpdest, push2 ⟨1520⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, - jumpiNT (by simpa [ptr, rounded] using hallocOk), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigWrapperDecimalsPostShortDecodeMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]) - (by native_decide) (by evm_ov)] - have rd1520 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest] - have hlenCheck : - UInt256.slt (UInt256.sub ((⟨160⟩ : UInt256) + rdsz) ⟨160⟩) ⟨32⟩ = ⟨1⟩ := by - simpa [rdsz] using - solcReturnStaticLenCheckShort (base := 160) (words := 1) (by simpa using hshort) - (by norm_num [UInt256.size]) - (by - have hcap : (2 : ℕ) ^ 255 + 160 < UInt256.size := by norm_num [UInt256.size] - have hhi : decOut.size < 2 ^ 255 := by omega - omega) - (by norm_num) - have rd1524₀ := evm_run rd1520 with [ - dup2, add, sub, slt] - have rd1524 := rd1524₀ - rw [hlenCheck] at rd1524 - have rd670 := evm_run rd1524 with [ - push2 ⟨670⟩, jumpiT (by native_decide) (by jump_dest)] - exact evm_run rd670 with [jumpdest, pop, dup1, raw rev 0 (by native_decide) mem_cost - (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigX_after_decimals_noncanon_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1154⟩ - (setRewardConfigWrapperDecimalsPostCallStack true baseWord I) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : ¬ (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let decWord : UInt256 := setRewardConfigDecimalsReturnWord decOut - have hdec8' : ¬ decWord.toNat < EVM.twoPow 8 := by - simpa [decWord] using hdec8 - let rdsz : UInt256 := UInt256.ofNat decOut.size - have hrdsz_toNat : rdsz.toNat = decOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hdecSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hdec32 - have rd1154 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1154⟩ - [⟨1⟩, ⟨160⟩, baseWord, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, setRewardConfigWrapperDecimalsTargetWord I, - ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C := by - simpa [setRewardConfigWrapperDecimalsPostCallStack, - setRewardConfigWrapperDecimalsPostCallTail] using rd - have rd1506₀ := evm_run rd1154 with [ - swap1, dup2, iszero, push2 ⟨741⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨1499⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, dup5, dup2, dup2, returndatasize, dup4, gt] - have rd1506 := rd1506₀ - rw [show UInt256.ofNat decOut.size = rdsz from rfl, hgt] at rd1506 - have rd3071 := evm_run rd1506 with [ - push2 ⟨1548⟩, jumpiNT (by native_decide), - jumpdest, push2 ⟨1520⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigWrapperDecimalsPostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd1524 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, sub, slt, - push2 ⟨670⟩, jumpiNT (by native_decide)] - have rd1536 := evm_run rd1524 with [ - raw mload 0 decWord setRewardConfigWrapperDecimalsPostCallAw (by native_decide) - mem_cost - (by - simpa [decWord, setRewardConfigDecimalsReturnWord] using - setRewardConfigWrapperDecimalsPostDecodeMem_mload160_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap1, push1 ⟨255⟩, dup3, and, dup3, sub] - have hnotClean : UInt256.land decWord uint8Mask ≠ decWord := - uint8Mask_not_clean hdec8' - have hneq : decWord ≠ UInt256.land decWord uint8Mask := by - intro hEq - exact hnotClean hEq.symm - have hsub : UInt256.sub decWord (UInt256.land decWord uint8Mask) ≠ ⟨0⟩ := - u256_sub_ne_zero_of_ne hneq - have rd667 := evm_run rd1536 with [ - push2 ⟨667⟩, jumpiT (by simpa [uint8Mask] using hsub) (by jump_dest)] - exact evm_run rd667 with [jumpdest, dup1, raw rev 0 (by native_decide) mem_cost - (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigX_after_decimals_pow10_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1154⟩ - (setRewardConfigWrapperDecimalsPostCallStack true baseWord I) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) - (hgt77 : 77 < (setRewardConfigDecimalsReturnWord decOut).toNat) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let decWord : UInt256 := setRewardConfigDecimalsReturnWord decOut - have hdec8' : decWord.toNat < EVM.twoPow 8 := by - simpa [decWord] using hdec8 - have hgt77' : 77 < decWord.toNat := by - simpa [decWord] using hgt77 - let rdsz : UInt256 := UInt256.ofNat decOut.size - have hrdsz_toNat : rdsz.toNat = decOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hdecSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hdec32 - have rd1154 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1154⟩ - [⟨1⟩, ⟨160⟩, baseWord, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, setRewardConfigWrapperDecimalsTargetWord I, - ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C := by - simpa [setRewardConfigWrapperDecimalsPostCallStack, - setRewardConfigWrapperDecimalsPostCallTail] using rd - have rd1506₀ := evm_run rd1154 with [ - swap1, dup2, iszero, push2 ⟨741⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨1499⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, dup5, dup2, dup2, returndatasize, dup4, gt] - have rd1506 := rd1506₀ - rw [show UInt256.ofNat decOut.size = rdsz from rfl, hgt] at rd1506 - have rd3071 := evm_run rd1506 with [ - push2 ⟨1548⟩, jumpiNT (by native_decide), - jumpdest, push2 ⟨1520⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigWrapperDecimalsPostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd1524 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, sub, slt, - push2 ⟨670⟩, jumpiNT (by native_decide)] - have rd1536 := evm_run rd1524 with [ - raw mload 0 decWord setRewardConfigWrapperDecimalsPostCallAw (by native_decide) - mem_cost - (by - simpa [decWord, setRewardConfigDecimalsReturnWord] using - setRewardConfigWrapperDecimalsPostDecodeMem_mload160_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap1, push1 ⟨255⟩, dup3, and, dup3, sub] - have hclean : UInt256.land decWord uint8Mask = decWord := - uint8Mask_clean hdec8' - have hsubZero : - UInt256.sub decWord (UInt256.land decWord uint8Mask) = ⟨0⟩ := by - rw [hclean] - exact u256_sub_self decWord - have rd1536zero := rd1536 - rw [show UInt256.sub decWord (UInt256.land decWord ⟨255⟩) = ⟨0⟩ by - simpa [uint8Mask] using hsubZero] at rd1536zero - have rd1176 := evm_run rd1536zero with [ - push2 ⟨667⟩, jumpiNT (by native_decide), pop, push1 ⟨255⟩, - push2 ⟨1168⟩, jump (by jump_dest), jumpdest, pop, push1 ⟨255⟩, and, - push1 ⟨77⟩, dup2, gt] - have hgt77Word : - UInt256.gt (UInt256.land (⟨255⟩ : UInt256) decWord) (⟨77⟩ : UInt256) = ⟨1⟩ := by - rw [u256_land_comm (⟨255⟩ : UInt256) decWord] - rw [show UInt256.land decWord ⟨255⟩ = decWord by simpa [uint8Mask] using hclean] - apply ugt_one - rw [show (⟨77⟩ : UInt256).toNat = 77 from by decide] - exact hgt77' - have rd1176gt := rd1176 - rw [hgt77Word] at rd1176gt - have rd1478 := evm_run rd1176gt with [ - push2 ⟨1478⟩, jumpiT (by native_decide) (by jump_dest)] - have hsel : - UInt256.shiftLeft (⟨0x4e487b71⟩ : UInt256) ⟨224⟩ = - setRewardConfigPanicSelector := by - rfl - have rd1492₀ := evm_run rd1478 with [ - jumpdest, push1 ⟨17⟩, dup7, push4 ⟨0x4e487b71⟩, push1 ⟨224⟩, shl, - push1 ⟨0⟩] - have rd1492 := rd1492₀ - rw [hsel] at rd1492 - have rd1493 := evm_run rd1492 with [ - raw mstore 0 - (setRewardConfigPanicMem0 (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut)) - setRewardConfigWrapperDecimalsPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov)] - have rd1498 := evm_run rd1493 with [ - raw mstore 0 - (setRewardConfigPanicMem ⟨17⟩ - (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut)) - setRewardConfigWrapperDecimalsPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov), - push1 ⟨36⟩, push1 ⟨0⟩] - exact evm_run rd1498 with [raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 3000000 in -theorem cometRewardsSetRewardConfigX_after_decimals_safe64_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1154⟩ - (setRewardConfigWrapperDecimalsPostCallStack true baseWord I) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) - (hle77 : (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 77) - (hgt64 : 2 ^ 64 - 1 < (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let decWord : UInt256 := setRewardConfigDecimalsReturnWord decOut - have hdec8' : decWord.toNat < EVM.twoPow 8 := by - simpa [decWord] using hdec8 - have hle77' : decWord.toNat ≤ 77 := by - simpa [decWord] using hle77 - have hgt64' : 2 ^ 64 - 1 < (10 : ℕ) ^ decWord.toNat := by - simpa [decWord] using hgt64 - let rdsz : UInt256 := UInt256.ofNat decOut.size - have hrdsz_toNat : rdsz.toNat = decOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hdecSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hdec32 - have rd1154 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1154⟩ - [⟨1⟩, ⟨160⟩, baseWord, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, setRewardConfigWrapperDecimalsTargetWord I, - ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C := by - simpa [setRewardConfigWrapperDecimalsPostCallStack, - setRewardConfigWrapperDecimalsPostCallTail] using rd - have rd1506₀ := evm_run rd1154 with [ - swap1, dup2, iszero, push2 ⟨741⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨1499⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, dup5, dup2, dup2, returndatasize, dup4, gt] - have rd1506 := rd1506₀ - rw [show UInt256.ofNat decOut.size = rdsz from rfl, hgt] at rd1506 - have rd3071 := evm_run rd1506 with [ - push2 ⟨1548⟩, jumpiNT (by native_decide), - jumpdest, push2 ⟨1520⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigWrapperDecimalsPostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd1524 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, sub, slt, - push2 ⟨670⟩, jumpiNT (by native_decide)] - have rd1536 := evm_run rd1524 with [ - raw mload 0 decWord setRewardConfigWrapperDecimalsPostCallAw (by native_decide) - mem_cost - (by - simpa [decWord, setRewardConfigDecimalsReturnWord] using - setRewardConfigWrapperDecimalsPostDecodeMem_mload160_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap1, push1 ⟨255⟩, dup3, and, dup3, sub] - have hclean : UInt256.land decWord uint8Mask = decWord := - uint8Mask_clean hdec8' - have hsubZero : - UInt256.sub decWord (UInt256.land decWord uint8Mask) = ⟨0⟩ := by - rw [hclean] - exact u256_sub_self decWord - have rd1536zero := rd1536 - rw [show UInt256.sub decWord (UInt256.land decWord ⟨255⟩) = ⟨0⟩ by - simpa [uint8Mask] using hsubZero] at rd1536zero - have rd1176 := evm_run rd1536zero with [ - push2 ⟨667⟩, jumpiNT (by native_decide), pop, push1 ⟨255⟩, - push2 ⟨1168⟩, jump (by jump_dest), jumpdest, pop, push1 ⟨255⟩, and, - push1 ⟨77⟩, dup2, gt] - have hle77Word : - UInt256.gt (UInt256.land (⟨255⟩ : UInt256) decWord) (⟨77⟩ : UInt256) = ⟨0⟩ := by - rw [u256_land_comm (⟨255⟩ : UInt256) decWord] - rw [show UInt256.land decWord ⟨255⟩ = decWord by simpa [uint8Mask] using hclean] - apply ugt_zero - rw [show (⟨77⟩ : UInt256).toNat = 77 from by decide] - exact hle77' - have rd1176le := rd1176 - rw [hle77Word] at rd1176le - let tokenScale : UInt256 := UInt256.exp (⟨10⟩ : UInt256) decWord - have htokenScale_toNat : tokenScale.toNat = (10 : ℕ) ^ decWord.toNat := by - unfold tokenScale - rw [← u256_ofNat_toNat decWord] - interval_cases decWord.toNat <;> native_decide - have rd1194 := evm_run rd1176le with [ - push2 ⟨1478⟩, jumpiNT (by native_decide), push1 ⟨10⟩, exp, - push1 ⟨1⟩, dup1, push1 ⟨64⟩, shl, sub, swap6, dup7, dup3, gt] - have hmax64 : - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩).toNat = - 18446744073709551615 := by - native_decide - have hgtToken : - UInt256.gt tokenScale (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨1⟩ := by - apply ugt_one - rw [htokenScale_toNat, hmax64] - exact hgt64' - have hmaskedDec : UInt256.land (⟨255⟩ : UInt256) decWord = decWord := by - rw [u256_land_comm (⟨255⟩ : UInt256) decWord] - simpa [uint8Mask] using hclean - have rd1194gt := rd1194 - rw [show UInt256.gt (UInt256.exp (⟨10⟩ : UInt256) - (UInt256.land (⟨255⟩ : UInt256) decWord)) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨1⟩ by - rw [hmaskedDec] - simpa [tokenScale] using hgtToken] at rd1194gt - have rd1458 := evm_run rd1194gt with [ - push2 ⟨1458⟩, jumpiT (by native_decide) (by jump_dest)] - have hsel : - UInt256.shiftLeft (⟨0x4809a3⟩ : UInt256) ⟨226⟩ = - setRewardConfigInvalidUInt64Selector := by - rfl - have rd1463pre := evm_run rd1458 with [ - jumpdest, push1 ⟨36⟩, swap2] - have rd1463 := rdDup12 rd1463pre (by native_decide) (by simp) - have rd1464 := evm_run rd1463 with [ - raw mload 0 ⟨192⟩ setRewardConfigWrapperDecimalsPostCallAw (by native_decide) mem_cost - (setRewardConfigWrapperDecimalsPostDecodeMem_mload64_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov)] - have rd1465 := evm_run rd1464 with [ - swap2] - have rd1469 := rd1465.pushConst (⟨0x4809a3⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) (by native_decide) (by evm_ov) - have rd1472₀ := evm_run rd1469 with [ - push1 ⟨226⟩, shl, dup4] - have rd1472 := rd1472₀ - rw [hsel] at rd1472 - let awInvalidSelector : UInt256 := - UInt256.ofNat (MachineState.M setRewardConfigWrapperDecimalsPostCallAw.toNat - (⟨192⟩ : UInt256).toNat 32) - let awInvalidArg : UInt256 := - UInt256.ofNat (MachineState.M awInvalidSelector.toNat - ((⟨192⟩ : UInt256) + ⟨4⟩).toNat 32) - have rd1473 := evm_run rd1472 with [ - raw mstore (Cₘ awInvalidSelector - Cₘ setRewardConfigWrapperDecimalsPostCallAw) - (setRewardConfigInvalidUInt64SelectorMem - (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut)) - awInvalidSelector (by native_decide) mem_cost - (by unfold setRewardConfigInvalidUInt64SelectorMem; rfl) - (by rfl) (by evm_ov)] - have rd1477 := evm_run rd1473 with [ - dup3, add, - raw mstore (Cₘ awInvalidArg - Cₘ awInvalidSelector) - (setRewardConfigInvalidUInt64Mem tokenScale - (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut)) - awInvalidArg (by native_decide) mem_cost - (by - unfold setRewardConfigInvalidUInt64Mem setRewardConfigInvalidUInt64SelectorMem tokenScale - rw [hmaskedDec] - rw [show ((⟨192⟩ : UInt256) + ⟨4⟩).toNat = 196 from by native_decide]) - (by rfl) (by evm_ov)] - exact evm_run rd1477 with [raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigX_after_decimals_safe64_prefix - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1154⟩ - (setRewardConfigWrapperDecimalsPostCallStack true baseWord I) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) - (hle77 : (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 2 ^ 64 - 1) - (hbase64 : baseWord.toNat < EVM.twoPow 64) : - ∃ tokenScale k' C', - tokenScale.toNat = (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat ∧ - UInt256.land baseWord (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = baseWord ∧ - UInt256.land - (UInt256.exp (⟨10⟩ : UInt256) - (UInt256.land (⟨255⟩ : UInt256) (setRewardConfigDecimalsReturnWord decOut))) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = - tokenScale ∧ - UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) - (UInt256.land - (UInt256.exp (⟨10⟩ : UInt256) - (UInt256.land (⟨255⟩ : UInt256) - (setRewardConfigDecimalsReturnWord decOut))) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = - tokenScale ∧ - RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1208⟩ - [UInt256.gt baseWord tokenScale, baseWord, tokenScale, solcAddrMask, ⟨32⟩, ⟨224⟩, - ((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩, - setRewardConfigCometWord I, ⟨1⟩, setRewardConfigWrapperDecimalsTargetWord I, - ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k' C' := by - let decWord : UInt256 := setRewardConfigDecimalsReturnWord decOut - have hdec8' : decWord.toNat < EVM.twoPow 8 := by - simpa [decWord] using hdec8 - have hle77' : decWord.toNat ≤ 77 := by - simpa [decWord] using hle77 - have hsafe64' : (10 : ℕ) ^ decWord.toNat ≤ 2 ^ 64 - 1 := by - simpa [decWord] using hsafe64 - let rdsz : UInt256 := UInt256.ofNat decOut.size - have hrdsz_toNat : rdsz.toNat = decOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hdecSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hdec32 - have rd1154 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨1154⟩ - [⟨1⟩, ⟨160⟩, baseWord, solcAddrMask, ⟨32⟩, ⟨224⟩, ⟨4⟩, - setRewardConfigCometWord I, ⟨1⟩, setRewardConfigWrapperDecimalsTargetWord I, - ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C := by - simpa [setRewardConfigWrapperDecimalsPostCallStack, - setRewardConfigWrapperDecimalsPostCallTail] using rd - have rd1506₀ := evm_run rd1154 with [ - swap1, dup2, iszero, push2 ⟨741⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨1499⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, dup5, dup2, dup2, returndatasize, dup4, gt] - have rd1506 := rd1506₀ - rw [show UInt256.ofNat decOut.size = rdsz from rfl, hgt] at rd1506 - have rd3071 := evm_run rd1506 with [ - push2 ⟨1548⟩, jumpiNT (by native_decide), - jumpdest, push2 ⟨1520⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigWrapperDecimalsPostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd1524 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, sub, slt, - push2 ⟨670⟩, jumpiNT (by native_decide)] - have rd1536 := evm_run rd1524 with [ - raw mload 0 decWord setRewardConfigWrapperDecimalsPostCallAw (by native_decide) - mem_cost - (by - simpa [decWord, setRewardConfigDecimalsReturnWord] using - setRewardConfigWrapperDecimalsPostDecodeMem_mload160_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap1, push1 ⟨255⟩, dup3, and, dup3, sub] - have hclean : UInt256.land decWord uint8Mask = decWord := - uint8Mask_clean hdec8' - have hsubZero : - UInt256.sub decWord (UInt256.land decWord uint8Mask) = ⟨0⟩ := by - rw [hclean] - exact u256_sub_self decWord - have rd1536zero := rd1536 - rw [show UInt256.sub decWord (UInt256.land decWord ⟨255⟩) = ⟨0⟩ by - simpa [uint8Mask] using hsubZero] at rd1536zero - have rd1176 := evm_run rd1536zero with [ - push2 ⟨667⟩, jumpiNT (by native_decide), pop, push1 ⟨255⟩, - push2 ⟨1168⟩, jump (by jump_dest), jumpdest, pop, push1 ⟨255⟩, and, - push1 ⟨77⟩, dup2, gt] - have hle77Word : - UInt256.gt (UInt256.land (⟨255⟩ : UInt256) decWord) (⟨77⟩ : UInt256) = ⟨0⟩ := by - rw [u256_land_comm (⟨255⟩ : UInt256) decWord] - rw [show UInt256.land decWord ⟨255⟩ = decWord by simpa [uint8Mask] using hclean] - apply ugt_zero - rw [show (⟨77⟩ : UInt256).toNat = 77 from by decide] - exact hle77' - have rd1176le := rd1176 - rw [hle77Word] at rd1176le - let tokenScale : UInt256 := UInt256.exp (⟨10⟩ : UInt256) decWord - have htokenScale_toNat : tokenScale.toNat = (10 : ℕ) ^ decWord.toNat := by - unfold tokenScale - rw [← u256_ofNat_toNat decWord] - interval_cases decWord.toNat <;> native_decide - have rd1194 := evm_run rd1176le with [ - push2 ⟨1478⟩, jumpiNT (by native_decide), push1 ⟨10⟩, exp, - push1 ⟨1⟩, dup1, push1 ⟨64⟩, shl, sub, swap6, dup7, dup3, gt] - have hmax64 : - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩).toNat = - 18446744073709551615 := by - native_decide - have hgtToken : - UInt256.gt tokenScale (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - rw [htokenScale_toNat, hmax64] - exact hsafe64' - have hmaskedDec : UInt256.land (⟨255⟩ : UInt256) decWord = decWord := by - rw [u256_land_comm (⟨255⟩ : UInt256) decWord] - simpa [uint8Mask] using hclean - have rd1194le := rd1194 - rw [show UInt256.gt (UInt256.exp (⟨10⟩ : UInt256) - (UInt256.land (⟨255⟩ : UInt256) decWord)) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ by - rw [hmaskedDec] - simpa [tokenScale] using hgtToken] at rd1194le - have rd1208 := evm_run rd1194le with [ - push2 ⟨1458⟩, jumpiNT (by native_decide), pop, dup6, and, swap1, - dup2, dup7, dup3, and, gt] - have htokenScale64 : tokenScale.toNat < EVM.twoPow 64 := by - rw [htokenScale_toNat] - have hpow : (10 : ℕ) ^ decWord.toNat < 2 ^ 64 := by omega - simpa [EVM.twoPow] using hpow - have hbaseClean : - UInt256.land baseWord (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = baseWord := by - simpa [uint64Mask] using uint64Mask_clean hbase64 - have htokenClean : - UInt256.land (UInt256.exp (⟨10⟩ : UInt256) (UInt256.land (⟨255⟩ : UInt256) decWord)) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = tokenScale := by - rw [hmaskedDec] - simpa [tokenScale, uint64Mask] using uint64Mask_clean htokenScale64 - have htokenCleanDirect : - UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) - (UInt256.exp (⟨10⟩ : UInt256) (UInt256.land (⟨255⟩ : UInt256) decWord)) = - tokenScale := by - rw [u256_land_comm (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) - (UInt256.exp (⟨10⟩ : UInt256) (UInt256.land (⟨255⟩ : UInt256) decWord))] - exact htokenClean - have htokenCleanMaskLeft : - UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) tokenScale = - tokenScale := by - rw [u256_land_comm (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) tokenScale] - simpa [uint64Mask] using uint64Mask_clean htokenScale64 - have htokenCleanLeft : - UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) - (UInt256.land - (UInt256.exp (⟨10⟩ : UInt256) (UInt256.land (⟨255⟩ : UInt256) decWord)) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = tokenScale := by - rw [htokenClean] - exact htokenCleanMaskLeft - have rd1208clean := rd1208 - rw [hbaseClean, htokenCleanDirect] at rd1208clean - obtain ⟨k1208, C1208, rd1208final⟩ : ∃ k1208 C1208, - RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1208⟩ - [UInt256.gt baseWord tokenScale, baseWord, tokenScale, solcAddrMask, ⟨32⟩, ⟨224⟩, - ((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩, - setRewardConfigCometWord I, ⟨1⟩, setRewardConfigWrapperDecimalsTargetWord I, - ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k1208 C1208 := by - exact ⟨_, _, by - simpa [decWord, tokenScale] using rd1208clean⟩ - refine ⟨tokenScale, k1208, C1208, ?_⟩ - refine ⟨?_, hbaseClean, ?_, ?_, rd1208final⟩ - · simpa [decWord] using htokenScale_toNat - · simpa [decWord] using htokenClean - · simpa [decWord] using htokenCleanLeft - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_after_decimals_upscale_zero_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1154⟩ - (setRewardConfigWrapperDecimalsPostCallStack true baseWord I) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) - (hle77 : (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 2 ^ 64 - 1) - (hbase64 : baseWord.toNat < EVM.twoPow 64) - (hle : baseWord.toNat ≤ - (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat) - (hbase0 : baseWord = ⟨0⟩) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨tokenScale, _, _, htokenScale_toNat, hbaseClean, _htokenClean, - _htokenCleanLeft, rd1208⟩ := - cometRewardsSetRewardConfigX_after_decimals_safe64_prefix - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (baseOut := baseOut) (decOut := decOut) - (baseWord := baseWord) (acc := acc) (k := k) (C := C) - rd hdec32 hdecSize hdec8 hle77 hsafe64 hbase64 - have hupWord : UInt256.gt baseWord tokenScale = ⟨0⟩ := by - apply ugt_zero - rw [htokenScale_toNat] - exact hle - have rd1208up := rd1208 - rw [hupWord] at rd1208up - have rd1337 := evm_run rd1208up with [ - push1 ⟨0⟩, eq, push2 ⟨1337⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest] - have rd3137 := evm_run rd1337 with [ - push2 ⟨1346⟩, swap2, push2 ⟨3137⟩, jump (by jump_dest)] - have rd3156pre := evm_run rd3137 with [ - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap2, dup3, and, - swap2, swap1, dup3, iszero] - have hdenZero : - UInt256.isZero - (UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) baseWord) = - ⟨1⟩ := by - rw [hbase0] - native_decide - have rd3156 := rd3156pre - rw [hdenZero] at rd3156 - have rd3161 := evm_run rd3156 with [ - push2 ⟨3161⟩, jumpiT (by native_decide) (by jump_dest)] - have hsel : - UInt256.shiftLeft (⟨0x4e487b71⟩ : UInt256) ⟨224⟩ = - setRewardConfigPanicSelector := by - rfl - have rd3172₀ := evm_run rd3161 with [ - jumpdest, push4 ⟨0x4e487b71⟩, push1 ⟨224⟩, shl, push1 ⟨0⟩] - have rd3172 := rd3172₀ - rw [hsel] at rd3172 - have rd3173 := evm_run rd3172 with [ - raw mstore 0 - (setRewardConfigPanicMem0 (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut)) - setRewardConfigWrapperDecimalsPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov)] - have rd3178 := evm_run rd3173 with [ - push1 ⟨18⟩, push1 ⟨4⟩, - raw mstore 0 - (setRewardConfigPanicMem ⟨18⟩ - (setRewardConfigWrapperDecimalsPostDecodeMem I baseOut decOut)) - setRewardConfigWrapperDecimalsPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov), - push1 ⟨36⟩, push1 ⟨0⟩] - exact evm_run rd3178 with [raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_after_decimals_downscale_success - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord rescale : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1154⟩ - (setRewardConfigWrapperDecimalsPostCallStack true baseWord I) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C) - (hperm : I.perm = true) - (hcanon0 : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) - (hle77 : (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 2 ^ 64 - 1) - (hbase64 : baseWord.toNat < EVM.twoPow 64) - (hdown : (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat < baseWord.toNat) - (hrescale : rescale.toNat = - baseWord.toNat / (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat) : - RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) - (acc.1, - sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner acc.2 (setRewardConfigSlotOf I) - (setRewardConfigSlot0Down - (solcSlotWord acc.2 I (setRewardConfigSlotOf I)) - (setRewardConfigTokenWord I) rescale)) - (setRewardConfigSlotOf I + ⟨1⟩) - setRewardConfigMultiplierWord) - ByteArray.empty := by - obtain ⟨tokenScale, _, _, htokenScale_toNat, hbaseClean, _htokenClean, - _htokenCleanLeft, rd1208⟩ := - cometRewardsSetRewardConfigX_after_decimals_safe64_prefix - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (baseOut := baseOut) (decOut := decOut) - (baseWord := baseWord) (acc := acc) (k := k) (C := C) - rd hdec32 hdecSize hdec8 hle77 hsafe64 hbase64 - have hdownWord : UInt256.gt baseWord tokenScale = ⟨1⟩ := by - apply ugt_one - rw [htokenScale_toNat] - exact hdown - have htokenScale64 : tokenScale.toNat < EVM.twoPow 64 := by - rw [htokenScale_toNat] - have hpow : - (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat < 2 ^ 64 := by - omega - simpa [EVM.twoPow] using hpow - have htokenCleanMaskLeft : - UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) tokenScale = - tokenScale := by - rw [u256_land_comm (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) tokenScale] - simpa [uint64Mask] using uint64Mask_clean htokenScale64 - have htokenNZ : tokenScale ≠ ⟨0⟩ := by - intro hzero - have hto := congrArg UInt256.toNat hzero - rw [htokenScale_toNat, show (⟨0⟩ : UInt256).toNat = 0 from rfl] at hto - have hpos : 0 < (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat := by - positivity - omega - have hrescaleWord : UInt256.div baseWord tokenScale = rescale := by - apply u256_inj - rw [udiv_toNat, htokenScale_toNat, hrescale] - have hrescale64 : rescale.toNat < EVM.twoPow 64 := by - rw [hrescale] - have hdiv := Nat.div_le_self baseWord.toNat - ((10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat) - have hbase64' : baseWord.toNat < 2 ^ 64 := by - simpa [EVM.twoPow] using hbase64 - simpa [EVM.twoPow] using lt_of_le_of_lt hdiv hbase64' - have hrescaleClean : - UInt256.land rescale (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = rescale := by - simpa [uint64Mask] using uint64Mask_clean hrescale64 - have rd1208down := rd1208 - rw [hdownWord] at rd1208down - have rd1224 := evm_run rd1208down with [ - push1 ⟨0⟩, eq, push2 ⟨1337⟩, jumpiNT (by native_decide), - swap1, push2 ⟨1224⟩, swap2, push2 ⟨3137⟩, jump (by jump_dest), - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap2, dup3, and, - swap2, swap1, dup3, iszero] - rw [show UInt256.isZero - (UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) tokenScale) = - ⟨0⟩ by - rw [htokenCleanMaskLeft] - exact isZero_eq_zero_of_ne htokenNZ] at rd1224 - have rd1224ret := evm_run rd1224 with [ - push2 ⟨3161⟩, jumpiNT (by native_decide), and, div, swap1, jump (by jump_dest), - jumpdest] - have rd1224rescale := rd1224ret - rw [hbaseClean, htokenCleanMaskLeft, hrescaleWord] at rd1224rescale - have rd1237 := evm_run rd1224rescale with [ - swap4, dup9, - raw mload 0 ⟨192⟩ setRewardConfigWrapperDecimalsPostCallAw (by native_decide) - mem_cost - (setRewardConfigWrapperDecimalsPostDecodeMem_mload64_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap8, push2 ⟨1237⟩, dup10, push2 ⟨3025⟩, jump (by jump_dest), - jumpdest, push1 ⟨128⟩, dup2, add, swap1, dup2, lt, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, lor, - push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩, - raw mstore 0 (setRewardConfigWrapperSuccessFreeMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessFreeMem Reasoning.Theory.writeWord; rfl) - (by native_decide) (by evm_ov), - jump (by jump_dest), jumpdest] - have rd1239 := evm_run rd1237 with [ - dup9, - raw mstore 3 (setRewardConfigWrapperSuccessTokenMem I baseOut decOut) - (⟨7⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessTokenMem; rfl) - (by native_decide) (by evm_ov)] - have rd1244pre := evm_run rd1239 with [ - dup3, dup9, add, swap5, and] - have rd1244 := rd1244pre - rw [hrescaleClean] at rd1244 - have rd1246 := evm_run rd1244 with [ - dup5, - raw mstore 3 (setRewardConfigWrapperSuccessRescaleMem I baseOut decOut rescale) - (⟨8⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessRescaleMem; rfl) - (by native_decide) (by evm_ov)] - have rd1255 := evm_run rd1246 with [ - dup6, dup9, dup9, add, swap3, push1 ⟨0⟩, dup5, - raw mstore 3 (setRewardConfigWrapperSuccessBitMem I baseOut decOut rescale ⟨0⟩) - (⟨9⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessBitMem; rfl) - (by native_decide) (by evm_ov)] - have rd1260 := evm_run rd1255 with [ - push1 ⟨96⟩, dup10, add, swap7] - have rd1270 := rd1260.pushConst setRewardConfigMultiplierWord - (width := 8) (op := .PUSH8) (by decide) (by native_decide) (by evm_ov) - have rd1271 := evm_run rd1270 with [ - dup9, - raw mstore 3 - (setRewardConfigWrapperSuccessMultiplierMem I baseOut decOut rescale ⟨0⟩) - (⟨10⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessMultiplierMem; rfl) - (by native_decide) (by evm_ov)] - have rd1274 := evm_run rd1271 with [ - push1 ⟨0⟩, - raw mstore 0 (setRewardConfigWrapperSuccessCometMem I baseOut decOut rescale ⟨0⟩) - (⟨10⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessCometMem; rfl) - (by native_decide) (by evm_ov)] - have rd1275 := evm_run rd1274 with [ - raw mstore 0 (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale ⟨0⟩) - (⟨10⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessArgsMem; rfl) - (by native_decide) (by evm_ov)] - have hslot := setRewardConfigSlotOf_eq_solc I hcanon0 - have hkeccak := - setRewardConfigWrapperSuccessArgsMem_keccakSlot I baseOut decOut rescale ⟨0⟩ - hdec32 hdecSize - have rd1279pre := evm_run rd1275 with [dup8, push1 ⟨0⟩] - have rd1279₀ := rd1279pre.keccak256 0 - (solcMappingSlot ⟨1⟩ (setRewardConfigCometWord I)) - (⟨10⟩ : UInt256) (by native_decide) mem_cost hkeccak (by native_decide) (by evm_ov) - have rd1279 := rd1279₀ - rw [← hslot] at rd1279 - have rd1285pre := evm_run rd1279 with [ - swap7, - raw mload 0 (setRewardConfigWrapperDecimalsTargetWord I) (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigWrapperSuccessArgsMem_mload192 I rescale ⟨0⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - and, swap1, dup7] - obtain ⟨_, _, rd1285⟩ := rd1285pre.sload (by native_decide) (by evm_ov) - have rd1317 := evm_run rd1285 with [ - swap4, push1 ⟨1⟩, push1 ⟨160⟩, shl, push1 ⟨1⟩, push1 ⟨224⟩, shl, sub, - swap1, - raw mload 0 rescale (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigWrapperSuccessArgsMem_mload224 I rescale ⟨0⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - push1 ⟨160⟩, shl, and, swap3, push1 ⟨255⟩, push1 ⟨224⟩, shl, swap2, - raw mload 0 (⟨0⟩ : UInt256) (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigWrapperSuccessArgsMem_mload256 I rescale ⟨0⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - iszero, iszero, swap1, shl, and, swap3] - have rd1322 := rd1317.pushConst (⟨0xffffff⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) (by native_decide) (by evm_ov) - have rd1329 := evm_run rd1322 with [ - push1 ⟨232⟩, shl, and, lor, lor, lor, dup4] - let oldSlot : UInt256 := solcSlotWord acc.2 I (setRewardConfigSlotOf I) - have rd1329packed := rd1329 - rw [show - UInt256.lor - (UInt256.lor - (UInt256.lor - (UInt256.land (UInt256.shiftLeft (⟨0xffffff⟩ : UInt256) ⟨232⟩) oldSlot) - (UInt256.land (setRewardConfigWrapperDecimalsTargetWord I) solcAddrMask)) - (UInt256.land (UInt256.shiftLeft rescale ⟨160⟩) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)))) - (UInt256.land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨0⟩ : UInt256))) ⟨224⟩) - (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩)) = - setRewardConfigSlot0Down oldSlot (setRewardConfigWrapperDecimalsTargetWord I) rescale by - exact setRewardConfigWrapperSlot0Down_bytecodeExpr_runtime oldSlot - (setRewardConfigWrapperDecimalsTargetWord I) rescale] at rd1329packed - obtain ⟨_, _, rd1329fold⟩ : ∃ k' C', - RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1330⟩ - [setRewardConfigSlotOf I, - setRewardConfigSlot0Down oldSlot (setRewardConfigWrapperDecimalsTargetWord I) - rescale, - ⟨192⟩ + ⟨96⟩, ⟨1⟩, setRewardConfigSlotOf I, ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale ⟨0⟩) - (⟨10⟩ : UInt256) decOut (acc.1, acc.2) k' C' := by - exact ⟨_, _, by simpa [oldSlot, solcSlotWord] using rd1329packed⟩ - have htargetWord : - setRewardConfigWrapperDecimalsTargetWord I = setRewardConfigTokenWord I := by - unfold setRewardConfigWrapperDecimalsTargetWord - rw [u256_land_comm solcAddrMask (setRewardConfigTokenWord I)] - exact solcAddrMask_clean hcanon1 - rw [htargetWord] at rd1329fold - obtain ⟨_, _, rd1330⟩ := rd1329fold.sstore hperm (by native_decide) (by evm_ov) - have rd1333pre := evm_run rd1330 with [ - raw mload 0 setRewardConfigMultiplierWord (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigWrapperSuccessArgsMem_mload288 I rescale ⟨0⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap2, add] - obtain ⟨_, _, rd1334⟩ := rd1333pre.sstore hperm (by native_decide) (by evm_ov) - have rd1335 := evm_run rd1334 with [ - raw mload 0 ⟨320⟩ (⟨10⟩ : UInt256) (by native_decide) - mem_cost - (setRewardConfigWrapperSuccessArgsMem_mload64 I rescale ⟨0⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov)] - have rdret : RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) - (acc.1, - sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner acc.2 (setRewardConfigSlotOf I) - (setRewardConfigSlot0Down oldSlot (setRewardConfigTokenWord I) rescale)) - (setRewardConfigSlotOf I + ⟨1⟩) - setRewardConfigMultiplierWord) - ByteArray.empty := by - exact RD.ret 0 ByteArray.empty rd1335 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk] - native_decide) - (by - rw [show (⟨320⟩ : UInt256).toNat = 320 from by decide, - show (⟨0⟩ : UInt256).toNat = 0 from by decide] - exact byteArray_readWithPadding_zero _ 320) - (by simp) - simpa [oldSlot] using rdret - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigX_after_decimals_upscale_success - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord rescale : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1154⟩ - (setRewardConfigWrapperDecimalsPostCallStack true baseWord I) - (setRewardConfigWrapperDecimalsPostCallMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw decOut acc k C) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) - (hle77 : (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 2 ^ 64 - 1) - (hbase64 : baseWord.toNat < EVM.twoPow 64) - (hperm : I.perm = true) - (hcanon0 : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hle : baseWord.toNat ≤ - (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat) - (hbaseNZ : baseWord.toNat ≠ 0) - (hrescale : rescale.toNat = - (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat / baseWord.toNat) : - RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) - (acc.1, - sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner acc.2 (setRewardConfigSlotOf I) - (setRewardConfigSlot0Up - (solcSlotWord acc.2 I (setRewardConfigSlotOf I)) - (setRewardConfigTokenWord I) rescale)) - (setRewardConfigSlotOf I + ⟨1⟩) - setRewardConfigMultiplierWord) - ByteArray.empty := by - obtain ⟨tokenScale, _, _, htokenScale_toNat, hbaseClean, _htokenClean, - _htokenCleanLeft, rd1208⟩ := - cometRewardsSetRewardConfigX_after_decimals_safe64_prefix - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (baseOut := baseOut) (decOut := decOut) - (baseWord := baseWord) (acc := acc) (k := k) (C := C) - rd hdec32 hdecSize hdec8 hle77 hsafe64 hbase64 - have hupWord : UInt256.gt baseWord tokenScale = ⟨0⟩ := by - apply ugt_zero - rw [htokenScale_toNat] - exact hle - have rd1208up := rd1208 - rw [hupWord] at rd1208up - have rd1337 := evm_run rd1208up with [ - push1 ⟨0⟩, eq, push2 ⟨1337⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest] - have rd3137 := evm_run rd1337 with [ - push2 ⟨1346⟩, swap2, push2 ⟨3137⟩, jump (by jump_dest)] - have rd3156pre := evm_run rd3137 with [ - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap2, dup3, and, - swap2, swap1, dup3, iszero] - have hbaseNZWord : - UInt256.isZero - (UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) baseWord) = - ⟨0⟩ := by - rw [u256_land_comm (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) baseWord] - rw [hbaseClean] - exact isZero_eq_zero_of_ne (by - intro hzero - exact hbaseNZ (by - rw [hzero] - rfl)) - have rd3156 := rd3156pre - rw [hbaseNZWord] at rd3156 - have rd1346 := evm_run rd3156 with [ - push2 ⟨3161⟩, jumpiNT (by native_decide), and, div, swap1, jump (by jump_dest), - jumpdest] - have htokenScale64 : tokenScale.toNat < EVM.twoPow 64 := by - rw [htokenScale_toNat] - have hpow : - (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat < 2 ^ 64 := by - omega - simpa [EVM.twoPow] using hpow - have htokenCleanRight : - UInt256.land tokenScale (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = - tokenScale := by - simpa [uint64Mask] using uint64Mask_clean htokenScale64 - have hbaseCleanLeft : - UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) baseWord = - baseWord := by - rw [u256_land_comm (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) baseWord] - exact hbaseClean - have hrescaleWord : UInt256.div tokenScale baseWord = rescale := by - apply u256_inj - rw [udiv_toNat, htokenScale_toNat, hrescale] - have rd1346rescale := rd1346 - rw [htokenCleanRight, hbaseCleanLeft, hrescaleWord] at rd1346rescale - have hrescale64 : rescale.toNat < EVM.twoPow 64 := by - rw [hrescale] - have hdiv := - Nat.div_le_self ((10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat) - baseWord.toNat - have hpow : - (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat < 2 ^ 64 := by - omega - exact lt_of_le_of_lt hdiv (by simpa [EVM.twoPow] using hpow) - have hrescaleClean : - UInt256.land rescale (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = rescale := by - simpa [uint64Mask] using uint64Mask_clean hrescale64 - have rd1359 := evm_run rd1346rescale with [ - swap4, dup9, - raw mload 0 ⟨192⟩ setRewardConfigWrapperDecimalsPostCallAw (by native_decide) - mem_cost - (setRewardConfigWrapperDecimalsPostDecodeMem_mload64_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap8, push2 ⟨1359⟩, dup10, push2 ⟨3025⟩, jump (by jump_dest), - jumpdest, push1 ⟨128⟩, dup2, add, swap1, dup2, lt, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, lor, - push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩, - raw mstore 0 (setRewardConfigWrapperSuccessFreeMem I baseOut decOut) - setRewardConfigWrapperDecimalsPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessFreeMem Reasoning.Theory.writeWord; rfl) - (by native_decide) (by evm_ov), - jump (by jump_dest), jumpdest] - have rd1361 := evm_run rd1359 with [ - dup9, - raw mstore 3 (setRewardConfigWrapperSuccessTokenMem I baseOut decOut) - (⟨7⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessTokenMem; rfl) - (by native_decide) (by evm_ov)] - have rd1366pre := evm_run rd1361 with [ - dup3, dup9, add, swap5, and] - have rd1366 := rd1366pre - rw [hrescaleClean] at rd1366 - have rd1368 := evm_run rd1366 with [ - dup5, - raw mstore 3 (setRewardConfigWrapperSuccessRescaleMem I baseOut decOut rescale) - (⟨8⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessRescaleMem; rfl) - (by native_decide) (by evm_ov)] - have rd1376 := evm_run rd1368 with [ - dup6, dup9, dup9, add, swap3, dup2, dup5, - raw mstore 3 (setRewardConfigWrapperSuccessBitMem I baseOut decOut rescale ⟨1⟩) - (⟨9⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessBitMem; rfl) - (by native_decide) (by evm_ov)] - have rd1381 := evm_run rd1376 with [ - push1 ⟨96⟩, dup10, add, swap7] - have rd1391 := rd1381.pushConst setRewardConfigMultiplierWord - (width := 8) (op := .PUSH8) (by decide) (by native_decide) (by evm_ov) - have rd1392 := evm_run rd1391 with [ - dup9, - raw mstore 3 - (setRewardConfigWrapperSuccessMultiplierMem I baseOut decOut rescale ⟨1⟩) - (⟨10⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessMultiplierMem; rfl) - (by native_decide) (by evm_ov)] - have rd1395 := evm_run rd1392 with [ - push1 ⟨0⟩, - raw mstore 0 (setRewardConfigWrapperSuccessCometMem I baseOut decOut rescale ⟨1⟩) - (⟨10⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessCometMem; rfl) - (by native_decide) (by evm_ov)] - have rd1396 := evm_run rd1395 with [ - raw mstore 0 (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale ⟨1⟩) - (⟨10⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigWrapperSuccessArgsMem; rfl) - (by native_decide) (by evm_ov)] - have hslot := setRewardConfigSlotOf_eq_solc I hcanon0 - have hkeccak := - setRewardConfigWrapperSuccessArgsMem_keccakSlot I baseOut decOut rescale ⟨1⟩ - hdec32 hdecSize - have rd1400pre := evm_run rd1396 with [dup8, push1 ⟨0⟩] - have rd1400₀ := rd1400pre.keccak256 0 - (solcMappingSlot ⟨1⟩ (setRewardConfigCometWord I)) - (⟨10⟩ : UInt256) (by native_decide) mem_cost hkeccak (by native_decide) (by evm_ov) - have rd1400 := rd1400₀ - rw [← hslot] at rd1400 - have rd1406pre := evm_run rd1400 with [ - swap7, - raw mload 0 (setRewardConfigWrapperDecimalsTargetWord I) (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigWrapperSuccessArgsMem_mload192 I rescale ⟨1⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - and, swap1, dup7] - obtain ⟨_, _, rd1406⟩ := rd1406pre.sload (by native_decide) (by evm_ov) - have rd1438 := evm_run rd1406 with [ - swap4, push1 ⟨1⟩, push1 ⟨160⟩, shl, push1 ⟨1⟩, push1 ⟨224⟩, shl, sub, - swap1, - raw mload 0 rescale (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigWrapperSuccessArgsMem_mload224 I rescale ⟨1⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - push1 ⟨160⟩, shl, and, swap3, push1 ⟨255⟩, push1 ⟨224⟩, shl, swap2, - raw mload 0 (⟨1⟩ : UInt256) (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigWrapperSuccessArgsMem_mload256 I rescale ⟨1⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - iszero, iszero, swap1, shl, and, swap3] - have rd1443 := rd1438.pushConst (⟨0xffffff⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) (by native_decide) (by evm_ov) - have rd1450 := evm_run rd1443 with [ - push1 ⟨232⟩, shl, and, lor, lor, lor, dup4] - let oldSlot : UInt256 := solcSlotWord acc.2 I (setRewardConfigSlotOf I) - have rd1450packed := rd1450 - rw [show - UInt256.lor - (UInt256.lor - (UInt256.lor - (UInt256.land (UInt256.shiftLeft (⟨0xffffff⟩ : UInt256) ⟨232⟩) oldSlot) - (UInt256.land (setRewardConfigWrapperDecimalsTargetWord I) solcAddrMask)) - (UInt256.land (UInt256.shiftLeft rescale ⟨160⟩) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)))) - (UInt256.land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨1⟩ : UInt256))) ⟨224⟩) - (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩)) = - setRewardConfigSlot0Up oldSlot (setRewardConfigWrapperDecimalsTargetWord I) rescale by - exact setRewardConfigWrapperSlot0Up_bytecodeExpr_runtime oldSlot - (setRewardConfigWrapperDecimalsTargetWord I) rescale] at rd1450packed - obtain ⟨_, _, rd1450fold⟩ : ∃ k' C', - RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1451⟩ - [setRewardConfigSlotOf I, - setRewardConfigSlot0Up oldSlot (setRewardConfigWrapperDecimalsTargetWord I) - rescale, - ⟨192⟩ + ⟨96⟩, ⟨1⟩, setRewardConfigSlotOf I, ⟨64⟩, ⟨0⟩] - (setRewardConfigWrapperSuccessArgsMem I baseOut decOut rescale ⟨1⟩) - (⟨10⟩ : UInt256) decOut (acc.1, acc.2) k' C' := by - exact ⟨_, _, by simpa [oldSlot, solcSlotWord] using rd1450packed⟩ - have htargetWord : - setRewardConfigWrapperDecimalsTargetWord I = setRewardConfigTokenWord I := by - unfold setRewardConfigWrapperDecimalsTargetWord - rw [u256_land_comm solcAddrMask (setRewardConfigTokenWord I)] - exact solcAddrMask_clean hcanon1 - rw [htargetWord] at rd1450fold - obtain ⟨_, _, rd1451⟩ := rd1450fold.sstore hperm (by native_decide) (by evm_ov) - have rd1454pre := evm_run rd1451 with [ - raw mload 0 setRewardConfigMultiplierWord (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigWrapperSuccessArgsMem_mload288 I rescale ⟨1⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap2, add] - obtain ⟨_, _, rd1455⟩ := rd1454pre.sstore hperm (by native_decide) (by evm_ov) - have rd1456 := evm_run rd1455 with [ - raw mload 0 ⟨320⟩ (⟨10⟩ : UInt256) (by native_decide) - mem_cost - (setRewardConfigWrapperSuccessArgsMem_mload64 I rescale ⟨1⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov)] - have rdret : RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) - (acc.1, - sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner acc.2 (setRewardConfigSlotOf I) - (setRewardConfigSlot0Up oldSlot (setRewardConfigTokenWord I) rescale)) - (setRewardConfigSlotOf I + ⟨1⟩) - setRewardConfigMultiplierWord) - ByteArray.empty := by - exact RD.ret 0 ByteArray.empty rd1456 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk] - native_decide) - (by - rw [show (⟨320⟩ : UInt256).toNat = 320 from by decide, - show (⟨0⟩ : UInt256).toNat = 0 from by decide] - exact byteArray_readWithPadding_zero _ 320) - (by simp) - simpa [oldSlot] using rdret - -theorem cometRewardsSetRewardConfigBodyCore_auth_revert - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hwv : I.weiValue = ⟨0⟩) (hsel : selIs I (cometRewardsSelBytes 7)) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsz68 : 68 ≤ I.calldata.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ_evm I ≠ solcSourceWord I) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hd := cometRewardsDispatch_setRewardConfig (cd := I.calldata) hsel - have hdec := cometRewardsDecode_setRewardConfig_ok (I := I) hsz68 hhi hcanon0 hcanon1 - have hgovWord : governorWord σ_evm I = governorWord σ_solm I := - accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ ⟨0⟩ - have hgovRet : governorReturnWord σ_evm I = governorReturnWord σ_solm I := by - simp [governorReturnWord, hgovWord] - have hauthSolm : governorReturnWord σ_solm I ≠ solcSourceWord I := by - intro h - exact hauth (by rw [hgovRet, h]) - have hgovSolm : - UInt256.land (Solm.EVM.storageLoad - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.codeOwner - ⟨0⟩) solcAddrMask ≠ - solcSourceWord - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv := by - simpa [governorReturnWord, governorWord, initState, Solm.EVM.storageLoad, - State.lookupAccount] using hauthSolm - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) setRewardConfigTransition.body .reverted := by - exact cometRewardsSetRewardConfigBodyReverts_auth - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - exact (cometRewardsSetRewardConfigX_revert_auth - (g := Sat256.ofUInt256 g) hwv hsz68 hsize hhi hcanon0 hcanon1 hauth hreach) - |>.reEquivExecutionRevert hcode hd hdec hbody - -/-- `setRewardConfig(address,address)` body, reached at pc 1009. -/ -theorem cometRewardsSetRewardConfigBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hsel : selIs I (cometRewardsSelBytes 7)) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) setRewardConfigPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have _hperm : I.perm = true := hperm - have hsz4 := cometRewardsSetRewardConfigSelector_size hsel - have hd := cometRewardsDispatch_setRewardConfig (cd := I.calldata) hsel - by_cases hsz68 : 68 ≤ I.calldata.size - · by_cases hhi : I.calldata.size < 2 ^ 255 + 4 - · by_cases hcanonComet : (setRewardConfigCometWord I).toNat < EVM.addressModulus - · by_cases hcanonToken : (setRewardConfigTokenWord I).toNat < EVM.addressModulus - · have hdec := - cometRewardsDecode_setRewardConfig_ok (I := I) hsz68 hhi hcanonComet hcanonToken - by_cases hauth : governorReturnWord σ_evm I ≠ solcSourceWord I - · exact cometRewardsSetRewardConfigBodyCore_auth_revert - hcode hsize hwv hsel hreach hAccounts hsz68 hhi hcanonComet hcanonToken hauth - · have hauthEq : governorReturnWord σ_evm I = solcSourceWord I := - Classical.not_not.mp hauth - have hgovWord : governorWord σ_evm I = governorWord σ_solm I := - accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ ⟨0⟩ - have hgovRet : - governorReturnWord σ_evm I = governorReturnWord σ_solm I := by - simp [governorReturnWord, hgovWord] - have hauthSolm : governorReturnWord σ_solm I = solcSourceWord I := by - rw [← hgovRet] - exact hauthEq - have hgovSolm : - UInt256.land (Solm.EVM.storageLoad - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.codeOwner - ⟨0⟩) solcAddrMask = - solcSourceWord - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv := by - simpa [governorReturnWord, governorWord, initState, Solm.EVM.storageLoad, - State.lookupAccount] using hauthSolm - have hslotWord : - solcSlotWord σ_evm I (setRewardConfigSlotOf I) = - solcSlotWord σ_solm I (setRewardConfigSlotOf I) := - accountMapEquiv_storage_findD hAccounts I.codeOwner - (setRewardConfigSlotOf I) ⟨0⟩ - by_cases hconfigured : - UInt256.land (solcSlotWord σ_evm I (setRewardConfigSlotOf I)) - solcAddrMask ≠ ⟨0⟩ - · have hconfiguredSolm : - UInt256.land (Solm.EVM.storageLoad - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.codeOwner - (setRewardConfigSlotOf I)) solcAddrMask ≠ ⟨0⟩ := by - simpa [initState, Solm.EVM.storageLoad, State.lookupAccount, solcSlotWord, - hslotWord] using hconfigured - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) setRewardConfigTransition.body .reverted := by - exact cometRewardsSetRewardConfigBodyReverts_configured - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - hconfiguredSolm - exact (cometRewardsSetRewardConfigX_revert_configured - (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hcanonComet hcanonToken hauthEq hconfigured hreach) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have htokenZero : - UInt256.land (solcSlotWord σ_evm I (setRewardConfigSlotOf I)) - solcAddrMask = ⟨0⟩ := by - exact Classical.not_not.mp hconfigured - have htokenZeroSolm : - UInt256.land (Solm.EVM.storageLoad - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.codeOwner - (setRewardConfigSlotOf I)) solcAddrMask = ⟨0⟩ := by - simpa [initState, Solm.EVM.storageLoad, State.lookupAccount, solcSlotWord, - hslotWord] using htokenZero - by_cases hdepth : I.depth.val < 1024 - · obtain ⟨cA', σ'_evm, σ'_solm, A'_solm, z, out, kPost, CPost, - hcallS, hPostAccounts, rdPost, houtSign⟩ := - cometRewardsSetRewardConfigX_call_baseAccrualScale_made - (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) - (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hcanonToken hauthEq htokenZero hdepth - hreach hAccounts - let evmPost : EVM.State := - { initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } - have houtSize : out.size < UInt256.size := lt_size_of_lt_sign houtSign - cases z - · have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - exact cometRewardsSetRewardConfigBodyReverts_baseCallFailure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - exact - (cometRewardsSetRewardConfigX_after_baseAccrualScale_failure - rdPost houtSize) - |>.reEquivExecutionRevert hcode hd hdec hbody - · by_cases hshort : out.size < 32 - · have hdecBase := cometRewardsBaseAccrualScale_decode_none_short - (out := out) hshort - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - exact cometRewardsSetRewardConfigBodyReverts_baseDecodeFailure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - exact - (cometRewardsSetRewardConfigX_after_baseAccrualScale_short_revert - rdPost hshort houtSize) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have hout32 : 32 ≤ out.size := by omega - by_cases hbaseWord : - fromByteArrayBigEndian (out.extract 0 32) < EVM.twoPow 64 - · have hdecBase := cometRewardsBaseAccrualScale_decode_ok - (out := out) hout32 houtSign hbaseWord - obtain ⟨kBase, CBase, rdBase⟩ := - cometRewardsSetRewardConfigX_after_baseAccrualScale_decode_ok - rdPost hout32 houtSize (by - have hto : - (setRewardConfigBaseReturnWord out).toNat = - fromByteArrayBigEndian (out.extract 0 32) := by - simpa [setRewardConfigBaseReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt hout32) - rw [hto] - exact hbaseWord) - obtain ⟨cA'', σ''_evm, σ''_solm, A''_solm, zDec, outDec, - kDec, CDec, hcallDec, hPostAccountsDec, rdDecPost, - houtDecSign⟩ := - cometRewardsSetRewardConfigX_call_decimals_made - (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) - (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) (baseOut := out) - (baseWord := setRewardConfigBaseReturnWord out) - (cA' := cA') (σ'_evm := σ'_evm) (σ'_solm := σ'_solm) - (A'_solm := A'_solm) - hcanonToken hdepth hPostAccounts rdBase hout32 houtSize - cases zDec - · let evmDecFail : EVM.State := - { evmPost with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' } - have houtDecSize : outDec.size < UInt256.size := - lt_size_of_lt_sign houtDecSign - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - exact - cometRewardsSetRewardConfigBodyReverts_decimalsCallFailure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecFail I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - (by simpa [evmPost, evmDecFail] using hcallDec) - exact - (cometRewardsSetRewardConfigX_after_decimals_failure - rdDecPost hout32 houtSize houtDecSize) - |>.reEquivExecutionRevert hcode hd hdec hbody - · by_cases hdecShort : outDec.size < 32 - · let evmDecPost : EVM.State := - { evmPost with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' } - have houtDecSize : outDec.size < UInt256.size := - lt_size_of_lt_sign houtDecSign - have hdecDecimals := cometRewardsDecimals_decode_none_short - (out := outDec) hdecShort - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - exact - cometRewardsSetRewardConfigBodyReverts_decimalsDecodeFailure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimals - exact - (cometRewardsSetRewardConfigX_after_decimals_short_revert - rdDecPost hdecShort houtDecSize) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have houtDec32 : 32 ≤ outDec.size := le_of_not_gt hdecShort - by_cases hdecWord : - fromByteArrayBigEndian (outDec.extract 0 32) < EVM.twoPow 8 - · have hdecDecimals := cometRewardsDecimals_decode_ok - (out := outDec) houtDec32 houtDecSign hdecWord - have htoDec : - (setRewardConfigDecimalsReturnWord outDec).toNat = - fromByteArrayBigEndian (outDec.extract 0 32) := by - simpa [setRewardConfigDecimalsReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt houtDec32) - by_cases hle77 : - fromByteArrayBigEndian (outDec.extract 0 32) ≤ 77 - · let evmDecPost : EVM.State := - { evmPost with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' } - have houtDecSize : outDec.size < UInt256.size := - lt_size_of_lt_sign houtDecSign - by_cases hsafe64 : - (10 : ℕ) ^ - fromByteArrayBigEndian (outDec.extract 0 32) ≤ - 2 ^ 64 - 1 - · have hdec8Return : - (setRewardConfigDecimalsReturnWord outDec).toNat < - EVM.twoPow 8 := by - rw [htoDec] - exact hdecWord - have hle77Return : - (setRewardConfigDecimalsReturnWord outDec).toNat ≤ 77 := by - rw [htoDec] - exact hle77 - have hsafe64Return : - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat ≤ - 2 ^ 64 - 1 := by - rw [htoDec] - exact hsafe64 - have hbaseTo : - (setRewardConfigBaseReturnWord out).toNat = - fromByteArrayBigEndian (out.extract 0 32) := by - simpa [setRewardConfigBaseReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt hout32) - have hbase64Return : - (setRewardConfigBaseReturnWord out).toNat < EVM.twoPow 64 := by - rw [hbaseTo] - exact hbaseWord - have hdecBaseReturn : - config.externalABI.decode? "baseAccrualScale" out = - some [.int (Int.ofNat - (setRewardConfigBaseReturnWord out).toNat)] := by - rw [hbaseTo] - exact hdecBase - have hdecDecimalsReturn : - config.externalABI.decode? "decimals" outDec = - some [.int (Int.ofNat - (setRewardConfigDecimalsReturnWord outDec).toNat)] := by - rw [htoDec] - exact hdecDecimals - by_cases hdown : - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat < - (setRewardConfigBaseReturnWord out).toNat - · let rescale : UInt256 := UInt256.ofNat - ((setRewardConfigBaseReturnWord out).toNat / - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat) - have hquotLt : - (setRewardConfigBaseReturnWord out).toNat / - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat < - UInt256.size := by - exact lt_of_le_of_lt - (Nat.div_le_self _ _) - (lt_of_lt_of_le hbase64Return - (by norm_num [EVM.twoPow, UInt256.size])) - have hrescale : - rescale.toNat = - (setRewardConfigBaseReturnWord out).toNat / - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat := by - simpa [rescale] using UInt256.toNat_ofNat_of_lt hquotLt - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) - setRewardConfigTransition.body - (.returned - (resumeAfterInternalCall - (setRewardConfigFrame - (initState cA gh bl σ_solm σ₀ - (Sat256.ofUInt256 g) A I) I) "_set" none) - (setRewardConfigWrapperSourceFinal evmDecPost I rescale false) - none) := by - exact - cometRewardsSetRewardConfigBodyReturns_downscale - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I - hcanonToken - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBaseReturn - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimalsReturn hle77Return hsafe64Return - hrescale hdown - have hslotPost : - solcSlotWord σ''_evm I (setRewardConfigSlotOf I) = - solcSlotWord σ''_solm I (setRewardConfigSlotOf I) := - accountMapEquiv_storage_findD hPostAccountsDec I.codeOwner - (setRewardConfigSlotOf I) ⟨0⟩ - have hIdeal := - accountMapEquiv_sstoreAccountMap I.codeOwner - (setRewardConfigSlotOf I + ⟨1⟩) - setRewardConfigMultiplierWord - (accountMapEquiv_sstoreAccountMap I.codeOwner - (setRewardConfigSlotOf I) - (setRewardConfigSlot0Down - (solcSlotWord σ''_solm I (setRewardConfigSlotOf I)) - (setRewardConfigTokenWord I) rescale) - hPostAccountsDec) - have hsourceAccounts := - setRewardConfigWrapperSourceFinal_accountMap_equiv - evmDecPost I rescale false - have hAccountsPost := accountMapEquiv.trans - (by simpa [hslotPost] using hIdeal) - (by - simpa [evmDecPost, evmPost, initState, solcSlotWord, - Solm.EVM.storageLoad, State.lookupAccount, - setRewardConfigSlot0Down] using hsourceAccounts) - have hcreated : - cA'' = - (setRewardConfigWrapperSourceFinal evmDecPost I rescale false).createdAccounts := by - simp [setRewardConfigWrapperSourceFinal, - setRewardConfigWrapperSourceAfterShouldUpscale, - setRewardConfigWrapperSourceAfterRescale, - setRewardConfigWrapperSourceAfterToken, evmDecPost, - storageStore_createdAccounts] - exact - (cometRewardsSetRewardConfigX_after_decimals_downscale_success - rdDecPost hperm hcanonComet hcanonToken houtDec32 - houtDecSize hdec8Return hle77Return hsafe64Return - hbase64Return hdown hrescale) - |>.reEquivExecutionGenAccountMapEquiv hcode hd hdec hbody - hcreated - (by simpa [evmDecPost, hslotPost.symm] using hAccountsPost) - (returnEquiv.fallthrough rfl (by rfl) (by native_decide)) - · have hupLe : - (setRewardConfigBaseReturnWord out).toNat ≤ - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat := - Nat.le_of_not_gt hdown - by_cases hbaseZero : - (setRewardConfigBaseReturnWord out).toNat = 0 - · have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - exact - cometRewardsSetRewardConfigBodyReverts_upscaleZero - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I hcanonToken - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBaseReturn - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimalsReturn hle77Return hsafe64Return hbaseZero - have hbaseWordZero : setRewardConfigBaseReturnWord out = ⟨0⟩ := by - apply u256_inj - simpa using hbaseZero - exact - (cometRewardsSetRewardConfigX_after_decimals_upscale_zero_revert - rdDecPost houtDec32 houtDecSize hdec8Return - hle77Return hsafe64Return hbase64Return hupLe - hbaseWordZero) - |>.reEquivExecutionRevert hcode hd hdec hbody - · let rescale : UInt256 := UInt256.ofNat - ((10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat / - (setRewardConfigBaseReturnWord out).toNat) - have hquotLt : - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat / - (setRewardConfigBaseReturnWord out).toNat < - UInt256.size := by - have hdiv := - Nat.div_le_self - ((10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat) - (setRewardConfigBaseReturnWord out).toNat - have hpowLt : - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat < - 2 ^ 64 := by - omega - exact lt_of_le_of_lt hdiv (by - norm_num [UInt256.size] at hpowLt ⊢ - omega) - have hrescale : - rescale.toNat = - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat / - (setRewardConfigBaseReturnWord out).toNat := by - simpa [rescale] using UInt256.toNat_ofNat_of_lt hquotLt - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) - setRewardConfigTransition.body - (.returned - (resumeAfterInternalCall - (setRewardConfigFrame - (initState cA gh bl σ_solm σ₀ - (Sat256.ofUInt256 g) A I) I) "_set" none) - (setRewardConfigWrapperSourceFinal evmDecPost I rescale true) - none) := by - exact - cometRewardsSetRewardConfigBodyReturns_upscale - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I hcanonToken - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBaseReturn - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimalsReturn hle77Return hsafe64Return - hrescale hupLe hbaseZero - have hslotPost : - solcSlotWord σ''_evm I (setRewardConfigSlotOf I) = - solcSlotWord σ''_solm I (setRewardConfigSlotOf I) := - accountMapEquiv_storage_findD hPostAccountsDec I.codeOwner - (setRewardConfigSlotOf I) ⟨0⟩ - have hIdeal := - accountMapEquiv_sstoreAccountMap I.codeOwner - (setRewardConfigSlotOf I + ⟨1⟩) - setRewardConfigMultiplierWord - (accountMapEquiv_sstoreAccountMap I.codeOwner - (setRewardConfigSlotOf I) - (setRewardConfigSlot0Up - (solcSlotWord σ''_solm I (setRewardConfigSlotOf I)) - (setRewardConfigTokenWord I) rescale) - hPostAccountsDec) - have hsourceAccounts := - setRewardConfigWrapperSourceFinal_accountMap_equiv - evmDecPost I rescale true - have hAccountsPost := accountMapEquiv.trans - (by simpa [hslotPost] using hIdeal) - (by - simpa [evmDecPost, evmPost, initState, solcSlotWord, - Solm.EVM.storageLoad, State.lookupAccount, - setRewardConfigSlot0Up] using hsourceAccounts) - have hcreated : - cA'' = - (setRewardConfigWrapperSourceFinal evmDecPost I rescale true).createdAccounts := by - simp [setRewardConfigWrapperSourceFinal, - setRewardConfigWrapperSourceAfterShouldUpscale, - setRewardConfigWrapperSourceAfterRescale, - setRewardConfigWrapperSourceAfterToken, evmDecPost, - storageStore_createdAccounts] - exact - (cometRewardsSetRewardConfigX_after_decimals_upscale_success - rdDecPost houtDec32 houtDecSize hdec8Return - hle77Return hsafe64Return hbase64Return hperm - hcanonComet hcanonToken hupLe hbaseZero hrescale) - |>.reEquivExecutionGenAccountMapEquiv hcode hd hdec hbody - hcreated - (by simpa [evmDecPost, hslotPost.symm] using hAccountsPost) - (returnEquiv.fallthrough rfl (by rfl) (by native_decide)) - · have hgt64 : - 2 ^ 64 - 1 < - (10 : ℕ) ^ - fromByteArrayBigEndian (outDec.extract 0 32) := - Nat.lt_of_not_ge hsafe64 - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ - (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - exact - cometRewardsSetRewardConfigBodyReverts_safe64Failure - (initState cA gh bl σ_solm σ₀ - (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimals - hle77 - hgt64 - have hdec8Return : - (setRewardConfigDecimalsReturnWord outDec).toNat < - EVM.twoPow 8 := by - rw [htoDec] - exact hdecWord - have hle77Return : - (setRewardConfigDecimalsReturnWord outDec).toNat ≤ 77 := by - rw [htoDec] - exact hle77 - have hgt64Return : - 2 ^ 64 - 1 < - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat := by - rw [htoDec] - exact hgt64 - exact - (cometRewardsSetRewardConfigX_after_decimals_safe64_revert - rdDecPost houtDec32 houtDecSize hdec8Return hle77Return - hgt64Return) - |>.reEquivExecutionRevert hcode hd hdec hbody - · let evmDecPost : EVM.State := - { evmPost with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' } - have houtDecSize : outDec.size < UInt256.size := - lt_size_of_lt_sign houtDecSign - have hgt77 : - 77 < fromByteArrayBigEndian (outDec.extract 0 32) := - Nat.lt_of_not_ge hle77 - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - exact - cometRewardsSetRewardConfigBodyReverts_pow10Failure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimals - hgt77 - have hdec8Return : - (setRewardConfigDecimalsReturnWord outDec).toNat < - EVM.twoPow 8 := by - rw [htoDec] - exact hdecWord - have hgt77Return : - 77 < (setRewardConfigDecimalsReturnWord outDec).toNat := by - rw [htoDec] - exact hgt77 - exact - (cometRewardsSetRewardConfigX_after_decimals_pow10_revert - rdDecPost houtDec32 houtDecSize hdec8Return hgt77Return) - |>.reEquivExecutionRevert hcode hd hdec hbody - · let evmDecPost : EVM.State := - { evmPost with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' } - have houtDecSize : outDec.size < UInt256.size := - lt_size_of_lt_sign houtDecSign - have hdecDecimals := - cometRewardsDecimals_decode_none_noncanon - (out := outDec) houtDec32 houtDecSign hdecWord - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - exact - cometRewardsSetRewardConfigBodyReverts_decimalsDecodeFailure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimals - have hdecNo : - ¬ (setRewardConfigDecimalsReturnWord outDec).toNat < - EVM.twoPow 8 := by - intro hlt - have hto : - (setRewardConfigDecimalsReturnWord outDec).toNat = - fromByteArrayBigEndian (outDec.extract 0 32) := by - simpa [setRewardConfigDecimalsReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt houtDec32) - exact hdecWord (by - rw [← hto] - exact hlt) - exact - (cometRewardsSetRewardConfigX_after_decimals_noncanon_revert - rdDecPost houtDec32 houtDecSize hdecNo) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have hdecBase := cometRewardsBaseAccrualScale_decode_none_noncanon - (out := out) hout32 houtSign hbaseWord - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - exact cometRewardsSetRewardConfigBodyReverts_baseDecodeFailure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - have hbaseNo : - ¬ (setRewardConfigBaseReturnWord out).toNat < EVM.twoPow 64 := by - intro hlt - have hto : - (setRewardConfigBaseReturnWord out).toNat = - fromByteArrayBigEndian (out.extract 0 32) := by - simpa [setRewardConfigBaseReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt hout32) - exact hbaseWord (by - rw [← hto] - exact hlt) - exact - (cometRewardsSetRewardConfigX_after_baseAccrualScale_noncanon_revert - rdPost hout32 houtSize hbaseNo) - |>.reEquivExecutionRevert hcode hd hdec hbody - · rw [not_lt] at hdepth - have hdepth1024 : I.depth = 1024 := Fin.ext (by - have := I.depth.isLt - omega) - let evmInit : EVM.State := - initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I - let evmFail : EVM.State := - { evmInit with - substate := - (evmInit.addAccessedAccount - (EVM.address (AccountAddress.ofNat - (setRewardConfigCometWord I).toNat))).substate } - have hcallS : - typedCallViaEVM config evmInit - (EVM.address (AccountAddress.ofNat (setRewardConfigCometWord I).toNat)) - "baseAccrualScale" 0 [] - (false, evmFail, ByteArray.empty) false := by - exact callNotMade_depthLimit - (cfg := config) (evm := evmInit) - (tgt := EVM.address (AccountAddress.ofNat - (setRewardConfigCometWord I).toNat)) - (name := "baseAccrualScale") (args := []) - (calldata := (setRewardConfigWrapperBaseAccrualScaleCalldataMem I) - |>.readWithPadding 128 4) - (callPerm := false) - (setRewardConfigWrapperBaseAccrualScaleCalldataMem_encode I) - (by simpa [evmInit, initState] using hdepth1024) - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigStore I) - setRewardConfigTransition.body .reverted := by - exact cometRewardsSetRewardConfigBodyReverts_baseCallFailure - evmInit evmFail I - (by simp only [evmInit, initState]; exact hwv) - (by simp only [evmInit, initState]; exact hhi) - (by simpa [evmInit] using hgovSolm) - (by simpa [evmInit] using htokenZeroSolm) - hcallS - exact (cometRewardsSetRewardConfigX_baseAccrualScale_callDepthLimit - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := g) - hwv hsz68 hsize hhi hcanonComet hcanonToken hauthEq htokenZero hreach - hdepth1024) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have hdec := cometRewardsDecode_setRewardConfig_none_noncanon_token - (I := I) hsz68 hhi hcanonComet hcanonToken - have hnc : UInt256.eq (setRewardConfigTokenWord I) - (UInt256.land (setRewardConfigTokenWord I) solcAddrMask) = ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanonToken (solcAddrCanonical_of_clean he)) - exact (cometRewardsSetRewardConfigX_noncanon_token (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hcanonComet hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hdec := cometRewardsDecode_setRewardConfig_none_noncanon_comet - (I := I) hsz68 hhi hcanonComet - have hnc : UInt256.eq (setRewardConfigCometWord I) - (UInt256.land (setRewardConfigCometWord I) solcAddrMask) = ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanonComet (solcAddrCanonical_of_clean he)) - exact (cometRewardsSetRewardConfigX_noncanon_comet (g := Sat256.ofUInt256 g) - hwv hsz68 hsize hhi hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hbig : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - have hdec := cometRewardsDecode_setRewardConfig_none_huge (I := I) hbig - exact (cometRewardsSetRewardConfigX_hugearg (g := Sat256.ofUInt256 g) - hwv hsize hbig hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hshort : I.calldata.size < 68 := by omega - have hdec := cometRewardsDecode_setRewardConfig_none_short (I := I) hsz4 hshort - exact (cometRewardsSetRewardConfigX_shortarg (g := Sat256.ofUInt256 g) - hwv hsz4 hsize hshort hreach) - |>.reEquivDecodingFailed hcode hd hdec - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/SetRewardConfigWithMultiplier.lean b/Benchmarks/CompoundIII/CometRewards/SetRewardConfigWithMultiplier.lean deleted file mode 100644 index f0c206bf..00000000 --- a/Benchmarks/CompoundIII/CometRewards/SetRewardConfigWithMultiplier.lean +++ /dev/null @@ -1,9345 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.RewardConfig -import Benchmarks.CompoundIII.CometRewards.TransferGovernor -import Reasoning.ExternalCall -import Reasoning.MemCascade - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace Benchmarks.CompoundIII.CometRewards - -/-! ## `setRewardConfigWithMultiplier(address,address,uint256)` -/ - -abbrev setRewardConfigWithMultiplierCometWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -abbrev setRewardConfigWithMultiplierTokenWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 36 - -abbrev setRewardConfigWithMultiplierMultiplierWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 68 - -abbrev setRewardConfigWithMultiplierCometValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat) - -abbrev setRewardConfigWithMultiplierTokenValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat) - -abbrev setRewardConfigWithMultiplierMultiplierValue (I : ExecutionEnv) : Value := - .int (Int.ofNat (setRewardConfigWithMultiplierMultiplierWord I).toNat) - -abbrev setRewardConfigWithMultiplierStore (I : ExecutionEnv) : Store := - (((∅ : Store).insert "comet" (setRewardConfigWithMultiplierCometValue I)).insert - "token" (setRewardConfigWithMultiplierTokenValue I)).insert "multiplier" - (setRewardConfigWithMultiplierMultiplierValue I) - -abbrev setRewardConfigWithMultiplierBodyStore (I : ExecutionEnv) : Store := - (((∅ : Store).insert "multiplier" (setRewardConfigWithMultiplierMultiplierValue I)).insert - "token" (setRewardConfigWithMultiplierTokenValue I)).insert "comet" - (setRewardConfigWithMultiplierCometValue I) - -abbrev setRewardConfigWithMultiplierArgs (I : ExecutionEnv) : List Value := - [setRewardConfigWithMultiplierCometValue I, setRewardConfigWithMultiplierTokenValue I, - setRewardConfigWithMultiplierMultiplierValue I] - -abbrev setRewardConfigWithMultiplierFrame (evm : EVM.State) (I : ExecutionEnv) : Frame := - { contract := contract, - locals := (setRewardConfigWithMultiplierStore I).insert "__calldata" - (.bytes evm.executionEnv.calldata) } - -abbrev setRewardConfigWithMultiplierBodyFrame (_evm : EVM.State) (I : ExecutionEnv) : Frame := - { contract := contract, locals := setRewardConfigWithMultiplierBodyStore I } - -def setRewardConfigWithMultiplierSlotOf (I : ExecutionEnv) : UInt256 := - rewardConfigSlot (.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)) - -theorem setRewardConfigWithMultiplierSlotOf_eq_solc (I : ExecutionEnv) - (hcanon : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) : - setRewardConfigWithMultiplierSlotOf I = - solcMappingSlot ⟨1⟩ (setRewardConfigWithMultiplierCometWord I) := by - unfold setRewardConfigWithMultiplierSlotOf rewardConfigSlot - rw [keyValueToWord_address_of_canonical _ hcanon] - rfl - -theorem setRewardConfigWithMultiplierStore_comet (I : ExecutionEnv) : - (setRewardConfigWithMultiplierStore I).get? "comet" = - some (setRewardConfigWithMultiplierCometValue I) := by - rw [setRewardConfigWithMultiplierStore, store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_self] - -theorem setRewardConfigWithMultiplierStore_token (I : ExecutionEnv) : - (setRewardConfigWithMultiplierStore I).get? "token" = - some (setRewardConfigWithMultiplierTokenValue I) := by - rw [setRewardConfigWithMultiplierStore, store_get_ne _ _ (by decide), store_get_self] - -theorem setRewardConfigWithMultiplierStore_multiplier (I : ExecutionEnv) : - (setRewardConfigWithMultiplierStore I).get? "multiplier" = - some (setRewardConfigWithMultiplierMultiplierValue I) := by - rw [setRewardConfigWithMultiplierStore, store_get_self] - -theorem setRewardConfigWithMultiplierStore_governor (I : ExecutionEnv) : - (setRewardConfigWithMultiplierStore I).get? "governor" = none := by - rw [setRewardConfigWithMultiplierStore, store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - native_decide - -theorem setRewardConfigWithMultiplierStore_rewardConfig (I : ExecutionEnv) : - (setRewardConfigWithMultiplierStore I).get? "rewardConfig" = none := by - rw [setRewardConfigWithMultiplierStore, store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - native_decide - -theorem setRewardConfigWithMultiplierBodyStore_comet (I : ExecutionEnv) : - (setRewardConfigWithMultiplierBodyStore I).get? "comet" = - some (setRewardConfigWithMultiplierCometValue I) := by - rw [setRewardConfigWithMultiplierBodyStore, store_get_self] - -theorem setRewardConfigWithMultiplierBodyStore_token (I : ExecutionEnv) : - (setRewardConfigWithMultiplierBodyStore I).get? "token" = - some (setRewardConfigWithMultiplierTokenValue I) := by - rw [setRewardConfigWithMultiplierBodyStore, store_get_ne _ _ (by decide), store_get_self] - -theorem setRewardConfigWithMultiplierBodyStore_multiplier (I : ExecutionEnv) : - (setRewardConfigWithMultiplierBodyStore I).get? "multiplier" = - some (setRewardConfigWithMultiplierMultiplierValue I) := by - rw [setRewardConfigWithMultiplierBodyStore, store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_self] - -theorem setRewardConfigWithMultiplierBodyStore_governor (I : ExecutionEnv) : - (setRewardConfigWithMultiplierBodyStore I).get? "governor" = none := by - rw [setRewardConfigWithMultiplierBodyStore, store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - native_decide - -theorem setRewardConfigWithMultiplierBodyStore_rewardConfig (I : ExecutionEnv) : - (setRewardConfigWithMultiplierBodyStore I).get? "rewardConfig" = none := by - rw [setRewardConfigWithMultiplierBodyStore, store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide)] - native_decide - -theorem evalExpr_setRewardConfigWithMultiplier_comet (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierFrame evm I) evm (.var "comet") = - .ok (setRewardConfigWithMultiplierCometValue I) := by - simp only [setRewardConfigWithMultiplierFrame, evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigWithMultiplierStore_comet] - -theorem evalExpr_setRewardConfigWithMultiplier_token (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierFrame evm I) evm (.var "token") = - .ok (setRewardConfigWithMultiplierTokenValue I) := by - simp only [setRewardConfigWithMultiplierFrame, evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigWithMultiplierStore_token] - -theorem evalExpr_setRewardConfigWithMultiplier_multiplier (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierFrame evm I) evm (.var "multiplier") = - .ok (setRewardConfigWithMultiplierMultiplierValue I) := by - simp only [setRewardConfigWithMultiplierFrame, evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigWithMultiplierStore_multiplier] - -theorem evalExprs_setRewardConfigWithMultiplier_args (evm : EVM.State) - (I : ExecutionEnv) : - evalExprs? config (setRewardConfigWithMultiplierFrame evm I) evm - [.var "comet", .var "token", .var "multiplier"] = - .ok (setRewardConfigWithMultiplierArgs I) := by - simp only [setRewardConfigWithMultiplierArgs, evalExprs?, - evalExpr_setRewardConfigWithMultiplier_comet, - evalExpr_setRewardConfigWithMultiplier_token, - evalExpr_setRewardConfigWithMultiplier_multiplier, EvalResult.bind, bind] - rfl - -theorem evalExpr_setRewardConfigWithMultiplier_body_comet (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierBodyFrame evm I) evm (.var "comet") = - .ok (setRewardConfigWithMultiplierCometValue I) := by - simp only [setRewardConfigWithMultiplierBodyFrame, evalExpr?, EvalResult.ofOption] - rw [setRewardConfigWithMultiplierBodyStore_comet] - -theorem evalExpr_setRewardConfigWithMultiplier_body_token (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierBodyFrame evm I) evm (.var "token") = - .ok (setRewardConfigWithMultiplierTokenValue I) := by - simp only [setRewardConfigWithMultiplierBodyFrame, evalExpr?, EvalResult.ofOption] - rw [setRewardConfigWithMultiplierBodyStore_token] - -theorem evalExpr_setRewardConfigWithMultiplier_body_multiplier (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierBodyFrame evm I) evm (.var "multiplier") = - .ok (setRewardConfigWithMultiplierMultiplierValue I) := by - simp only [setRewardConfigWithMultiplierBodyFrame, evalExpr?, EvalResult.ofOption] - rw [setRewardConfigWithMultiplierBodyStore_multiplier] - -theorem bindParams_setRewardConfigWithMultiplier (I : ExecutionEnv) : - bindParams? setRewardConfigWithMultiplierFunction.params - (setRewardConfigWithMultiplierArgs I) = - some (setRewardConfigWithMultiplierBodyStore I) := by - simp [setRewardConfigWithMultiplierFunction, setRewardConfigWithMultiplierArgs, - setRewardConfigWithMultiplierCometValue, setRewardConfigWithMultiplierTokenValue, - setRewardConfigWithMultiplierMultiplierValue, setRewardConfigWithMultiplierBodyStore, - bindParams?] - -theorem lookupCallable_setRewardConfigWithMultiplierBody : - lookupCallable? contract "setRewardConfigWithMultiplierBody" = - some setRewardConfigWithMultiplierFunction.toCallable := by - rfl - -theorem lookupCallable_pow10 : - lookupCallable? contract "pow10" = some pow10Function.toCallable := by - rfl - -theorem lookupCallable_safe64 : - lookupCallable? contract "safe64" = some safe64Function.toCallable := by - rfl - -abbrev pow10Store (n : ℕ) : Store := - (∅ : Store).insert "n" (.int (Int.ofNat n)) - -abbrev safe64Store (n : ℕ) : Store := - (∅ : Store).insert "n" (.int (Int.ofNat n)) - -theorem bindParams_pow10 (n : ℕ) : - bindParams? pow10Function.params [.int (Int.ofNat n)] = some (pow10Store n) := by - simp [pow10Function, pow10Store, bindParams?] - -theorem bindParams_safe64 (n : ℕ) : - bindParams? safe64Function.params [.int (Int.ofNat n)] = some (safe64Store n) := by - simp [safe64Function, safe64Store, bindParams?] - -theorem evalExpr_pow10_bound_false (evm : EVM.State) {n : ℕ} (hgt : 77 < n) : - evalExpr? config { contract := contract, locals := pow10Store n } evm - (.binary .le (.var "n") (.intLit 77)) = .ok (.bool false) := by - have hle : ¬ Int.ofNat n ≤ (77 : Int) := by - intro hn - have hnNat : n ≤ 77 := Int.ofNat_le.mp hn - omega - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind, pow10Store] - rw [store_get_self] - simp [evalBinaryOp?] - exact hgt - -theorem pow10FunctionBodyReverts_gt77 (evm : EVM.State) {n : ℕ} (hgt : 77 < n) : - ExecFuncBody config { contract := contract, locals := pow10Store n } evm - pow10Function.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [pow10Function] using - ExecBlock.consRevert - (ExecStmt.requireFalse (evalExpr_pow10_bound_false evm hgt)) - -theorem evalExpr_pow10_bound_true (evm : EVM.State) {n : ℕ} (hle : n ≤ 77) : - evalExpr? config { contract := contract, locals := pow10Store n } evm - (.binary .le (.var "n") (.intLit 77)) = .ok (.bool true) := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind, pow10Store] - rw [store_get_self] - simp [evalBinaryOp?] - exact hle - -theorem evalExpr_pow10_return (evm : EVM.State) {n : ℕ} (hle : n ≤ 77) : - evalExpr? config { contract := contract, locals := pow10Store n } evm - (u256 (.binary .exp (.intLit 10) (.var "n"))) = - .ok (.int ((10 : Int) ^ n)) := by - simp only [u256, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind, pow10Store] - rw [store_get_self] - simp [evalBinaryOp?] - rw [if_neg (by omega)] - simp only [uint256Int] - have hpowNat : (10 : ℕ) ^ n ≤ 10 ^ 77 := - Nat.pow_le_pow_right (by norm_num) hle - have hbound : (10 : ℕ) ^ n < 2 ^ 256 := - lt_of_le_of_lt hpowNat (by norm_num) - rw [if_neg] - · rfl - · push Not - constructor - · positivity - · exact_mod_cast hbound - -theorem pow10FunctionBodyReturns_le77 (evm : EVM.State) {n : ℕ} (hle : n ≤ 77) : - ExecFuncBody config { contract := contract, locals := pow10Store n } evm - pow10Function.body - (.returned { contract := contract, locals := pow10Store n } evm - (some [.int ((10 : Int) ^ n)])) := by - refine ExecFuncBody.execBlockRet ?_ - simpa [pow10Function] using - ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_pow10_bound_true evm hle)) - (ExecBlock.consReturn - (ExecStmt.return (by - simp [evalExprs?, evalExpr_pow10_return evm hle, EvalResult.bind, bind] - rfl))) - -theorem evalExpr_safe64_bound_false (evm : EVM.State) {n : ℕ} - (hgt : 2 ^ 64 - 1 < n) : - evalExpr? config { contract := contract, locals := safe64Store n } evm - (.binary .le (.var "n") (.intLit maxUint64)) = .ok (.bool false) := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind, safe64Store] - rw [store_get_self] - simp [evalBinaryOp?, maxUint64] - exact hgt - -theorem evalExpr_safe64_bound_true (evm : EVM.State) {n : ℕ} - (hle : n ≤ 2 ^ 64 - 1) : - evalExpr? config { contract := contract, locals := safe64Store n } evm - (.binary .le (.var "n") (.intLit maxUint64)) = .ok (.bool true) := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind, safe64Store] - rw [store_get_self] - simp [evalBinaryOp?, maxUint64] - exact hle - -theorem evalExpr_safe64_return (evm : EVM.State) {n : ℕ} (hle : n ≤ 2 ^ 64 - 1) : - evalExpr? config { contract := contract, locals := safe64Store n } evm - (u64 (.var "n")) = .ok (.int (Int.ofNat n)) := by - simp only [u64, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind, safe64Store] - rw [store_get_self] - simp [uint64Int] - rw [if_neg] - · rfl - · push Not - constructor - · omega - · exact Nat.lt_succ_of_le hle - -theorem safe64FunctionBodyReverts_gt (evm : EVM.State) {n : ℕ} - (hgt : 2 ^ 64 - 1 < n) : - ExecFuncBody config { contract := contract, locals := safe64Store n } evm - safe64Function.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [safe64Function] using - ExecBlock.consRevert - (ExecStmt.requireFalse (evalExpr_safe64_bound_false evm hgt)) - -theorem safe64FunctionBodyReturns_le (evm : EVM.State) {n : ℕ} - (hle : n ≤ 2 ^ 64 - 1) : - ExecFuncBody config { contract := contract, locals := safe64Store n } evm - safe64Function.body - (.returned { contract := contract, locals := safe64Store n } evm - (some [.int (Int.ofNat n)])) := by - refine ExecFuncBody.execBlockRet ?_ - simpa [safe64Function] using - ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_safe64_bound_true evm hle)) - (ExecBlock.consReturn - (ExecStmt.return (by - simp [evalExprs?, evalExpr_safe64_return evm hle, EvalResult.bind, bind] - rfl))) - -theorem evalExpr_setRewardConfigWithMultiplier_governor (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierFrame evm I) evm (.storage governorRef) = - .ok (.address (AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat)) := by - have her : evalStorageRef config (setRewardConfigWithMultiplierFrame evm I) evm - governorRef = .ok { base := "governor", steps := [] } := by - simp [evalStorageRef, evalStorageRefSteps, governorRef, EvalResult.bind, pure, bind] - have hty : storageTypeAt? contract.storage - ({ base := "governor", steps := [] } : EvaledStorageRef) = some (.elem .address) := by - decide - rw [evalExpr_storage_scalar - (hbase := by - change ((setRewardConfigWithMultiplierStore I).insert "__calldata" - (.bytes evm.executionEnv.calldata)).get? "governor" = none - rw [store_get_ne _ _ (by decide)] - exact setRewardConfigWithMultiplierStore_governor I) - (her := her) (hty := hty) (hloc := by rfl), - cometRewardsStorageLocLoad_address_offset0] - -theorem evalExpr_setRewardConfigWithMultiplier_body_governor (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierBodyFrame evm I) evm (.storage governorRef) = - .ok (.address (AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat)) := by - have her : evalStorageRef config (setRewardConfigWithMultiplierBodyFrame evm I) evm - governorRef = .ok { base := "governor", steps := [] } := by - simp [evalStorageRef, evalStorageRefSteps, governorRef, EvalResult.bind, pure, bind] - have hty : storageTypeAt? contract.storage - ({ base := "governor", steps := [] } : EvaledStorageRef) = some (.elem .address) := by - decide - rw [evalExpr_storage_scalar - (hbase := by - change (setRewardConfigWithMultiplierBodyStore I).get? "governor" = none - exact setRewardConfigWithMultiplierBodyStore_governor I) - (her := her) (hty := hty) (hloc := by rfl), - cometRewardsStorageLocLoad_address_offset0] - -theorem evalExpr_setRewardConfigWithMultiplier_sender (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierFrame evm I) evm sender = - .ok (.address evm.executionEnv.source) := by - simp [sender, evalExpr?, envValue, pure] - -theorem evalExpr_setRewardConfigWithMultiplier_body_sender (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierBodyFrame evm I) evm sender = - .ok (.address evm.executionEnv.source) := by - simp [sender, evalExpr?, envValue, pure] - -theorem evalExpr_setRewardConfigWithMultiplier_auth_true (evm : EVM.State) - (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) : - evalExpr? config (setRewardConfigWithMultiplierFrame evm I) evm - (.binary .eq sender (.storage governorRef)) = .ok (.bool true) := by - simp only [evalExpr?, evalExpr_setRewardConfigWithMultiplier_sender, - evalExpr_setRewardConfigWithMultiplier_governor, bind, EvalResult.bind, evalBinaryOp?] - rw [solcMaskedAddress_eq_source_of_word_eq (I := evm.executionEnv) hgov] - simp [BEq.beq] - -theorem evalExpr_setRewardConfigWithMultiplier_body_auth_true (evm : EVM.State) - (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) : - evalExpr? config (setRewardConfigWithMultiplierBodyFrame evm I) evm - (.binary .eq sender (.storage governorRef)) = .ok (.bool true) := by - simp only [evalExpr?, evalExpr_setRewardConfigWithMultiplier_body_sender, - evalExpr_setRewardConfigWithMultiplier_body_governor, bind, EvalResult.bind, evalBinaryOp?] - rw [solcMaskedAddress_eq_source_of_word_eq (I := evm.executionEnv) hgov] - simp [BEq.beq] - -theorem evalExpr_setRewardConfigWithMultiplier_auth_false (evm : EVM.State) - (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask ≠ - solcSourceWord evm.executionEnv) : - evalExpr? config (setRewardConfigWithMultiplierFrame evm I) evm - (.binary .eq sender (.storage governorRef)) = .ok (.bool false) := by - simp only [evalExpr?, evalExpr_setRewardConfigWithMultiplier_sender, - evalExpr_setRewardConfigWithMultiplier_governor, bind, EvalResult.bind, evalBinaryOp?] - have haddr : - evm.executionEnv.source ≠ - AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat := by - intro haddr - exact hgov (by - exact solcWord_eq_of_maskedAddress_eq_source (I := evm.executionEnv) haddr.symm) - rw [show ((.address evm.executionEnv.source : Value) == - .address (AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat)) = false by - simp [BEq.beq, haddr]] - -theorem evalExpr_setRewardConfigWithMultiplier_body_auth_false (evm : EVM.State) - (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask ≠ - solcSourceWord evm.executionEnv) : - evalExpr? config (setRewardConfigWithMultiplierBodyFrame evm I) evm - (.binary .eq sender (.storage governorRef)) = .ok (.bool false) := by - simp only [evalExpr?, evalExpr_setRewardConfigWithMultiplier_body_sender, - evalExpr_setRewardConfigWithMultiplier_body_governor, bind, EvalResult.bind, evalBinaryOp?] - have haddr : - evm.executionEnv.source ≠ - AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat := by - intro haddr - exact hgov (by - exact solcWord_eq_of_maskedAddress_eq_source (I := evm.executionEnv) haddr.symm) - rw [show ((.address evm.executionEnv.source : Value) == - .address (AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat)) = false by - simp [BEq.beq, haddr]] - -theorem evalStorageRef_setRewardConfigWithMultiplier_rewardConfig_field - (evm : EVM.State) (I : ExecutionEnv) (field : Ident) : - evalStorageRef config (setRewardConfigWithMultiplierFrame evm I) evm - (rewardConfigF (.var "comet") field) = - .ok { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)), - .field field] } := by - simp only [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, rewardConfigF, - evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, valueToKey?, - Std.HashMap.get?_eq_getElem?] - rw [← Std.HashMap.get?_eq_getElem?] - rw [store_get_ne _ _ (by decide), setRewardConfigWithMultiplierStore_comet] - -theorem evalStorageRef_setRewardConfigWithMultiplier_body_rewardConfig_field - (evm : EVM.State) (I : ExecutionEnv) (field : Ident) : - evalStorageRef config (setRewardConfigWithMultiplierBodyFrame evm I) evm - (rewardConfigF (.var "comet") field) = - .ok { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)), - .field field] } := by - simp only [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, rewardConfigF, - evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, valueToKey?, - Std.HashMap.get?_eq_getElem?] - rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigWithMultiplierBodyStore_comet] - -theorem evalExpr_setRewardConfigWithMultiplier_rewardConfig_token (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierFrame evm I) evm - (.storage (rewardConfigF (.var "comet") "token")) = - .ok (.address (AccountAddress.ofNat - (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask).toNat)) := by - have her := evalStorageRef_setRewardConfigWithMultiplier_rewardConfig_field evm I "token" - have hty : storageTypeAt? contract.storage - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)), - .field "token"] } = - some (.elem .address) := by - simp [storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)), - .field "token"] } = - fun _ => some (fieldLoc (slotAdd (setRewardConfigWithMultiplierSlotOf I) 0) 0 - 20 (by decide) .address) := by - rfl - rw [evalExpr_storage_scalar - (hbase := by - change ((setRewardConfigWithMultiplierStore I).insert "__calldata" - (.bytes evm.executionEnv.calldata)).get? "rewardConfig" = none - rw [store_get_ne _ _ (by decide)] - exact setRewardConfigWithMultiplierStore_rewardConfig I) - (her := her) (hty := hty) (hloc := hloc)] - congr 1 - rw [slotAdd_zero] - exact cometRewardsStorageLocLoad_address_offset0 evm - (setRewardConfigWithMultiplierSlotOf I) - -theorem evalExpr_setRewardConfigWithMultiplier_body_rewardConfig_token (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierBodyFrame evm I) evm - (.storage (rewardConfigF (.var "comet") "token")) = - .ok (.address (AccountAddress.ofNat - (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask).toNat)) := by - have her := evalStorageRef_setRewardConfigWithMultiplier_body_rewardConfig_field evm I "token" - have hty : storageTypeAt? contract.storage - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)), - .field "token"] } = - some (.elem .address) := by - simp [storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hloc : config.storage.layout - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)), - .field "token"] } = - fun _ => some (fieldLoc (slotAdd (setRewardConfigWithMultiplierSlotOf I) 0) 0 - 20 (by decide) .address) := by - rfl - rw [evalExpr_storage_scalar - (hbase := by - change (setRewardConfigWithMultiplierBodyStore I).get? "rewardConfig" = none - exact setRewardConfigWithMultiplierBodyStore_rewardConfig I) - (her := her) (hty := hty) (hloc := hloc)] - congr 1 - rw [slotAdd_zero] - exact cometRewardsStorageLocLoad_address_offset0 evm - (setRewardConfigWithMultiplierSlotOf I) - -theorem evalExpr_setRewardConfigWithMultiplier_zeroAddr (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierFrame evm I) evm zeroAddr = - .ok (.address (AccountAddress.ofNat 0)) := by - simp [zeroAddr, addrSt, evalExpr?, castValue?, EvalResult.bind, EvalResult.ofOption, - pure, bind] - -theorem evalExpr_setRewardConfigWithMultiplier_body_zeroAddr (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? config (setRewardConfigWithMultiplierBodyFrame evm I) evm zeroAddr = - .ok (.address (AccountAddress.ofNat 0)) := by - simp [zeroAddr, addrSt, evalExpr?, castValue?, EvalResult.bind, EvalResult.ofOption, - pure, bind] - -theorem evalExpr_setRewardConfigWithMultiplier_token_zero_true (evm : EVM.State) - (I : ExecutionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) : - evalExpr? config (setRewardConfigWithMultiplierFrame evm I) evm - (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr) = - .ok (.bool true) := by - simp only [evalExpr?, evalExpr_setRewardConfigWithMultiplier_rewardConfig_token, - evalExpr_setRewardConfigWithMultiplier_zeroAddr, bind, EvalResult.bind, evalBinaryOp?] - rw [htoken] - simp [BEq.beq] - -theorem evalExpr_setRewardConfigWithMultiplier_body_token_zero_true (evm : EVM.State) - (I : ExecutionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) : - evalExpr? config (setRewardConfigWithMultiplierBodyFrame evm I) evm - (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr) = - .ok (.bool true) := by - simp only [evalExpr?, evalExpr_setRewardConfigWithMultiplier_body_rewardConfig_token, - evalExpr_setRewardConfigWithMultiplier_body_zeroAddr, bind, EvalResult.bind, evalBinaryOp?] - rw [htoken] - simp [BEq.beq] - -theorem accountAddress_ofNat_masked_ne_zero_of_ne (w : UInt256) - (h : UInt256.land w solcAddrMask ≠ ⟨0⟩) : - AccountAddress.ofNat (UInt256.land w solcAddrMask).toNat ≠ AccountAddress.ofNat 0 := by - intro haddr - apply h - apply u256_inj - have hval := congrArg (fun a : AccountAddress => a.val) haddr - have hcanon := solcAddrMask_result_canonical w - have hmod : - (UInt256.land w solcAddrMask).toNat % AccountAddress.size = - (UInt256.land w solcAddrMask).toNat := by - exact Nat.mod_eq_of_lt (by - simpa [EVM.addressModulus, EVM.twoPow, AccountAddress.size] using hcanon) - simp [AccountAddress.ofNat, hmod] at hval - simpa [UInt256.toNat] using hval - -theorem evalExpr_setRewardConfigWithMultiplier_body_token_zero_false (evm : EVM.State) - (I : ExecutionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask ≠ ⟨0⟩) : - evalExpr? config (setRewardConfigWithMultiplierBodyFrame evm I) evm - (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr) = - .ok (.bool false) := by - simp only [evalExpr?, evalExpr_setRewardConfigWithMultiplier_body_rewardConfig_token, - evalExpr_setRewardConfigWithMultiplier_body_zeroAddr, bind, EvalResult.bind, evalBinaryOp?] - have haddr := accountAddress_ofNat_masked_ne_zero_of_ne - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) htoken - rw [show ((.address (AccountAddress.ofNat - (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask).toNat) : Value) == - .address (AccountAddress.ofNat 0)) = false by - simp [BEq.beq, haddr]] - -theorem setRewardConfigWithMultiplierFunctionBodyReverts_auth - (evm : EVM.State) (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask ≠ - solcSourceWord evm.executionEnv) : - ExecFuncBody config (setRewardConfigWithMultiplierBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [setRewardConfigWithMultiplierFunction] using - ExecBlock.consRevert - (ExecStmt.requireFalse - (evalExpr_setRewardConfigWithMultiplier_body_auth_false evm I hgov)) - -theorem setRewardConfigWithMultiplierFunctionBodyReverts_configured - (evm : EVM.State) (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask ≠ ⟨0⟩) : - ExecFuncBody config (setRewardConfigWithMultiplierBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [setRewardConfigWithMultiplierFunction] using - ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_auth_true evm I hgov)) - (ExecBlock.consRevert - (ExecStmt.requireFalse - (evalExpr_setRewardConfigWithMultiplier_body_token_zero_false evm I htoken))) - -theorem setRewardConfigWithMultiplierFunctionBodyReverts_baseCallFailure - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcall : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (false, evm', out) false) : - ExecFuncBody config (setRewardConfigWithMultiplierBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigWithMultiplierBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_token_zero_true evm I htoken)) ?_ - exact ExecBlock.consRevert - (ExecStmt.externalCallFailure - (cfg := config) (evm := evm) (evm' := evm') - (solm := { contract := contract, locals := setRewardConfigWithMultiplierBodyStore I }) - (receiver := .var "comet") (retVar := "accrualScale") (name := "baseAccrualScale") - (target := AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat) - (eth := .intLit 0) (sendVal := 0) (args := []) (argVals := []) (out := out) - (perm := false) - (evalExpr_setRewardConfigWithMultiplier_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcall) - -theorem setRewardConfigWithMultiplierFunctionBodyReverts_baseDecodeFailure - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcall : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evm', out) false) - (hdec : config.externalABI.decode? "baseAccrualScale" out = none) : - ExecFuncBody config (setRewardConfigWithMultiplierBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigWithMultiplierBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_token_zero_true evm I htoken)) ?_ - exact ExecBlock.consRevert - (ExecStmt.externalCallReturnDecodeRevert - (evalExpr_setRewardConfigWithMultiplier_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcall hdec) - -theorem setRewardConfigWithMultiplierFunctionBodyReverts_decimalsCallFailure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (false, evmDec, decOut) false) : - ExecFuncBody config (setRewardConfigWithMultiplierBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigWithMultiplierBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfigWithMultiplier_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigWithMultiplierBodyStore I).insert "accrualScale" baseValue } - evmBase (.var "token") = - .ok (setRewardConfigWithMultiplierTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigWithMultiplierBodyStore_token] - exact ExecBlock.consRevert - (ExecStmt.externalCallFailure - (cfg := config) (evm := evmBase) (evm' := evmDec) - (solm := - { contract := contract, - locals := (setRewardConfigWithMultiplierBodyStore I).insert "accrualScale" baseValue }) - (receiver := .var "token") (retVar := "tokenDecimals") (name := "decimals") - (target := AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat) - (eth := .intLit 0) (sendVal := 0) (args := []) (argVals := []) (out := decOut) - (perm := false) - htokenExpr - (by simp [evalExpr?, pure]) - (by rfl) - hcallDec) - -theorem setRewardConfigWithMultiplierFunctionBodyReverts_decimalsDecodeFailure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : config.externalABI.decode? "decimals" decOut = none) : - ExecFuncBody config (setRewardConfigWithMultiplierBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigWithMultiplierBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfigWithMultiplier_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigWithMultiplierBodyStore I).insert "accrualScale" baseValue } - evmBase (.var "token") = - .ok (setRewardConfigWithMultiplierTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigWithMultiplierBodyStore_token] - exact ExecBlock.consRevert - (ExecStmt.externalCallReturnDecodeRevert - htokenExpr - (by simp [evalExpr?, pure]) - (by rfl) - hcallDec hdecDec) - -theorem setRewardConfigWithMultiplierFunctionBodyReverts_pow10Failure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} {decNat : ℕ} - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hgt : 77 < decNat) : - ExecFuncBody config (setRewardConfigWithMultiplierBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigWithMultiplierBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfigWithMultiplier_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigWithMultiplierBodyStore I).insert "accrualScale" baseValue } - evmBase (.var "token") = - .ok (setRewardConfigWithMultiplierTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigWithMultiplierBodyStore_token] - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - htokenExpr - (by simp [evalExpr?, pure]) - (by rfl) - hcallDec hdecDec) ?_ - let afterDecimals : Frame := - { contract := contract, - locals := - ((setRewardConfigWithMultiplierBodyStore I).insert "accrualScale" baseValue).insert - "tokenDecimals" (.int (Int.ofNat decNat)) } - have hpowArgs : - evalExprs? config afterDecimals evmDec [.var "tokenDecimals"] = - .ok [.int (Int.ofNat decNat)] := by - simp only [afterDecimals, evalExprs?, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - exact ExecBlock.consRevert - (internalCallFunctionRevert - (cfg := config) (caller := afterDecimals) (evm := evmDec) - (name := "pow10") (retVar := "tokenScale256") (args := [.var "tokenDecimals"]) - (argVals := [.int (Int.ofNat decNat)]) - (callee := pow10Function) (locals := pow10Store decNat) - hpowArgs lookupCallable_pow10 (bindParams_pow10 decNat) - (by simpa [afterDecimals] using pow10FunctionBodyReverts_gt77 evmDec hgt)) - -theorem setRewardConfigWithMultiplierFunctionBodyReverts_safe64Failure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} {decNat : ℕ} - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hgt64 : 2 ^ 64 - 1 < (10 : ℕ) ^ decNat) : - ExecFuncBody config (setRewardConfigWithMultiplierBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigWithMultiplierBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfigWithMultiplier_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigWithMultiplierBodyStore I).insert "accrualScale" baseValue } - evmBase (.var "token") = - .ok (setRewardConfigWithMultiplierTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigWithMultiplierBodyStore_token] - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - htokenExpr - (by simp [evalExpr?, pure]) - (by rfl) - hcallDec hdecDec) ?_ - let afterDecimals : Frame := - { contract := contract, - locals := - ((setRewardConfigWithMultiplierBodyStore I).insert "accrualScale" baseValue).insert - "tokenDecimals" (.int (Int.ofNat decNat)) } - have hpowArgs : - evalExprs? config afterDecimals evmDec [.var "tokenDecimals"] = - .ok [.int (Int.ofNat decNat)] := by - simp only [afterDecimals, evalExprs?, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := afterDecimals) (evm := evmDec) (calleeEvm := evmDec) - (name := "pow10") (retVar := "tokenScale256") (args := [.var "tokenDecimals"]) - (argVals := [.int (Int.ofNat decNat)]) - (callee := pow10Function) (locals := pow10Store decNat) - (calleeSolm := { contract := contract, locals := pow10Store decNat }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hpowArgs lookupCallable_pow10 (bindParams_pow10 decNat) - (by simpa using pow10FunctionBodyReturns_le77 evmDec hle77)) ?_ - let afterPow10 : Frame := - resumeAfterInternalCall afterDecimals "tokenScale256" - (some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - have hsafeArgs : - evalExprs? config afterPow10 evmDec [.var "tokenScale256"] = - .ok [.int (Int.ofNat ((10 : ℕ) ^ decNat))] := by - simp only [afterPow10, afterDecimals, resumeAfterInternalCall, evalExprs?, evalExpr?, - EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - exact ExecBlock.consRevert - (internalCallFunctionRevert - (cfg := config) (caller := afterPow10) (evm := evmDec) - (name := "safe64") (retVar := "tokenScale") (args := [.var "tokenScale256"]) - (argVals := [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - (callee := safe64Function) (locals := safe64Store ((10 : ℕ) ^ decNat)) - hsafeArgs lookupCallable_safe64 (bindParams_safe64 ((10 : ℕ) ^ decNat)) - (by simpa [afterPow10] using safe64FunctionBodyReverts_gt evmDec hgt64)) - -theorem cometRewardsSetRewardConfigWithMultiplierBodyReverts_auth - (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask ≠ - solcSourceWord evm.executionEnv) : - ExecTransitionBody config contract evm (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigWithMultiplierFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", .var "multiplier"] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigWithMultiplierFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", .var "multiplier"]) - (argVals := setRewardConfigWithMultiplierArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigWithMultiplierBodyStore I) - (evalExprs_setRewardConfigWithMultiplier_args evm I) - (by simpa [setRewardConfigWithMultiplierFrame] using - lookupCallable_setRewardConfigWithMultiplierBody) - (bindParams_setRewardConfigWithMultiplier I) - (by - simpa [setRewardConfigWithMultiplierFrame, - setRewardConfigWithMultiplierBodyFrame] using - setRewardConfigWithMultiplierFunctionBodyReverts_auth evm I hgov) - simpa [setRewardConfigWithMultiplierTransition, externalEntryGuard, nonpayable, - calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigWithMultiplierStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigWithMultiplierBodyReverts_configured - (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask ≠ ⟨0⟩) : - ExecTransitionBody config contract evm (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigWithMultiplierFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", .var "multiplier"] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigWithMultiplierFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", .var "multiplier"]) - (argVals := setRewardConfigWithMultiplierArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigWithMultiplierBodyStore I) - (evalExprs_setRewardConfigWithMultiplier_args evm I) - (by simpa [setRewardConfigWithMultiplierFrame] using - lookupCallable_setRewardConfigWithMultiplierBody) - (bindParams_setRewardConfigWithMultiplier I) - (by - simpa [setRewardConfigWithMultiplierFrame, - setRewardConfigWithMultiplierBodyFrame] using - setRewardConfigWithMultiplierFunctionBodyReverts_configured evm I hgov htoken) - simpa [setRewardConfigWithMultiplierTransition, externalEntryGuard, nonpayable, - calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigWithMultiplierStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigWithMultiplierBodyReverts_baseCallFailure - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcall : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (false, evm', out) false) : - ExecTransitionBody config contract evm (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigWithMultiplierFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", .var "multiplier"] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigWithMultiplierFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", .var "multiplier"]) - (argVals := setRewardConfigWithMultiplierArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigWithMultiplierBodyStore I) - (evalExprs_setRewardConfigWithMultiplier_args evm I) - (by simpa [setRewardConfigWithMultiplierFrame] using - lookupCallable_setRewardConfigWithMultiplierBody) - (bindParams_setRewardConfigWithMultiplier I) - (by - simpa [setRewardConfigWithMultiplierFrame, - setRewardConfigWithMultiplierBodyFrame] using - setRewardConfigWithMultiplierFunctionBodyReverts_baseCallFailure - evm evm' I hgov htoken hcall) - simpa [setRewardConfigWithMultiplierTransition, externalEntryGuard, nonpayable, - calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigWithMultiplierStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigWithMultiplierBodyReverts_baseDecodeFailure - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcall : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evm', out) false) - (hdec : config.externalABI.decode? "baseAccrualScale" out = none) : - ExecTransitionBody config contract evm (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigWithMultiplierFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", .var "multiplier"] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigWithMultiplierFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", .var "multiplier"]) - (argVals := setRewardConfigWithMultiplierArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigWithMultiplierBodyStore I) - (evalExprs_setRewardConfigWithMultiplier_args evm I) - (by simpa [setRewardConfigWithMultiplierFrame] using - lookupCallable_setRewardConfigWithMultiplierBody) - (bindParams_setRewardConfigWithMultiplier I) - (by - simpa [setRewardConfigWithMultiplierFrame, - setRewardConfigWithMultiplierBodyFrame] using - setRewardConfigWithMultiplierFunctionBodyReverts_baseDecodeFailure - evm evm' I hgov htoken hcall hdec) - simpa [setRewardConfigWithMultiplierTransition, externalEntryGuard, nonpayable, - calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigWithMultiplierStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigWithMultiplierBodyReverts_decimalsCallFailure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (false, evmDec, decOut) false) : - ExecTransitionBody config contract evm (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigWithMultiplierFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", .var "multiplier"] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigWithMultiplierFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", .var "multiplier"]) - (argVals := setRewardConfigWithMultiplierArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigWithMultiplierBodyStore I) - (evalExprs_setRewardConfigWithMultiplier_args evm I) - (by simpa [setRewardConfigWithMultiplierFrame] using - lookupCallable_setRewardConfigWithMultiplierBody) - (bindParams_setRewardConfigWithMultiplier I) - (by - simpa [setRewardConfigWithMultiplierFrame, - setRewardConfigWithMultiplierBodyFrame] using - setRewardConfigWithMultiplierFunctionBodyReverts_decimalsCallFailure - evm evmBase evmDec I hgov htoken hcallBase hdecBase hcallDec) - simpa [setRewardConfigWithMultiplierTransition, externalEntryGuard, nonpayable, - calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigWithMultiplierStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigWithMultiplierBodyReverts_decimalsDecodeFailure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : config.externalABI.decode? "decimals" decOut = none) : - ExecTransitionBody config contract evm (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigWithMultiplierFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", .var "multiplier"] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigWithMultiplierFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", .var "multiplier"]) - (argVals := setRewardConfigWithMultiplierArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigWithMultiplierBodyStore I) - (evalExprs_setRewardConfigWithMultiplier_args evm I) - (by simpa [setRewardConfigWithMultiplierFrame] using - lookupCallable_setRewardConfigWithMultiplierBody) - (bindParams_setRewardConfigWithMultiplier I) - (by - simpa [setRewardConfigWithMultiplierFrame, - setRewardConfigWithMultiplierBodyFrame] using - setRewardConfigWithMultiplierFunctionBodyReverts_decimalsDecodeFailure - evm evmBase evmDec I hgov htoken hcallBase hdecBase hcallDec hdecDec) - simpa [setRewardConfigWithMultiplierTransition, externalEntryGuard, nonpayable, - calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigWithMultiplierStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigWithMultiplierBodyReverts_pow10Failure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} {decNat : ℕ} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hgt : 77 < decNat) : - ExecTransitionBody config contract evm (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigWithMultiplierFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", .var "multiplier"] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigWithMultiplierFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", .var "multiplier"]) - (argVals := setRewardConfigWithMultiplierArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigWithMultiplierBodyStore I) - (evalExprs_setRewardConfigWithMultiplier_args evm I) - (by simpa [setRewardConfigWithMultiplierFrame] using - lookupCallable_setRewardConfigWithMultiplierBody) - (bindParams_setRewardConfigWithMultiplier I) - (by - simpa [setRewardConfigWithMultiplierFrame, - setRewardConfigWithMultiplierBodyFrame] using - setRewardConfigWithMultiplierFunctionBodyReverts_pow10Failure - evm evmBase evmDec I hgov htoken hcallBase hdecBase hcallDec hdecDec hgt) - simpa [setRewardConfigWithMultiplierTransition, externalEntryGuard, nonpayable, - calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigWithMultiplierStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsSetRewardConfigWithMultiplierBodyReverts_safe64Failure - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseValue : Value} {decNat : ℕ} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : config.externalABI.decode? "baseAccrualScale" baseOut = some [baseValue]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hgt64 : 2 ^ 64 - 1 < (10 : ℕ) ^ decNat) : - ExecTransitionBody config contract evm (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigWithMultiplierFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", .var "multiplier"] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigWithMultiplierFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", .var "multiplier"]) - (argVals := setRewardConfigWithMultiplierArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigWithMultiplierBodyStore I) - (evalExprs_setRewardConfigWithMultiplier_args evm I) - (by simpa [setRewardConfigWithMultiplierFrame] using - lookupCallable_setRewardConfigWithMultiplierBody) - (bindParams_setRewardConfigWithMultiplier I) - (by - simpa [setRewardConfigWithMultiplierFrame, - setRewardConfigWithMultiplierBodyFrame] using - setRewardConfigWithMultiplierFunctionBodyReverts_safe64Failure - evm evmBase evmDec I hgov htoken hcallBase hdecBase hcallDec hdecDec - hle77 hgt64) - simpa [setRewardConfigWithMultiplierTransition, externalEntryGuard, nonpayable, - calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigWithMultiplierStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -theorem cometRewardsDecode_setRewardConfigWithMultiplier_ok {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) - (hcanonToken : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode - (setRewardConfigWithMultiplierTransition.params.map Param.name) - (transitionSignature setRewardConfigWithMultiplierTransition).paramTypes I.calldata = - some (setRewardConfigWithMultiplierStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "token", "multiplier"] - [addr, addr, uint256] I.calldata = _ - change decodeCalldata ["comet", "token", "multiplier"] - [.elem .address, .elem .address, abiUInt256] I.calldata = - some ((((∅ : Store).insert "comet" - (.address (AccountAddress.ofNat (calldataWord I.calldata 4).toNat))).insert "token" - (.address (AccountAddress.ofNat (calldataWord I.calldata 36).toNat))).insert - "multiplier" (.int (Int.ofNat (calldataWord I.calldata 68).toNat))) - exact decodeCalldata_address_address_uint256_ok (cd := I.calldata) - (x := "comet") (y := "token") (z := "multiplier") hsz100 hbig hcanonComet - hcanonToken - -theorem cometRewardsDecode_setRewardConfigWithMultiplier_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 100) : - decodeCalldataWithMode config.abiDecodeMode - (setRewardConfigWithMultiplierTransition.params.map Param.name) - (transitionSignature setRewardConfigWithMultiplierTransition).paramTypes I.calldata = - none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "token", "multiplier"] - [addr, addr, uint256] I.calldata = none - change decodeCalldata ["comet", "token", "multiplier"] - [.elem .address, .elem .address, abiUInt256] I.calldata = none - exact decodeCalldata_address_address_uint256_none_short - (cd := I.calldata) (x := "comet") (y := "token") (z := "multiplier") hsz4 hshort - -theorem cometRewardsDecode_setRewardConfigWithMultiplier_none_noncanon_comet - {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hncComet : ¬ (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode - (setRewardConfigWithMultiplierTransition.params.map Param.name) - (transitionSignature setRewardConfigWithMultiplierTransition).paramTypes I.calldata = - none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "token", "multiplier"] - [addr, addr, uint256] I.calldata = none - change decodeCalldata ["comet", "token", "multiplier"] - [.elem .address, .elem .address, abiUInt256] I.calldata = none - simpa [setRewardConfigWithMultiplierCometWord, calldataWord] using - decodeCalldata_address_address_uint256_none_noncanon0 - (cd := I.calldata) (x := "comet") (y := "token") (z := "multiplier") hsz100 - hbig hncComet - -theorem cometRewardsDecode_setRewardConfigWithMultiplier_none_noncanon_token - {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanonComet : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) - (hncToken : ¬ (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode - (setRewardConfigWithMultiplierTransition.params.map Param.name) - (transitionSignature setRewardConfigWithMultiplierTransition).paramTypes I.calldata = - none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "token", "multiplier"] - [addr, addr, uint256] I.calldata = none - change decodeCalldata ["comet", "token", "multiplier"] - [.elem .address, .elem .address, abiUInt256] I.calldata = none - simpa [setRewardConfigWithMultiplierCometWord, setRewardConfigWithMultiplierTokenWord, - calldataWord] using - decodeCalldata_address_address_uint256_none_noncanon1 - (cd := I.calldata) (x := "comet") (y := "token") (z := "multiplier") hsz100 - hbig hcanonComet hncToken - -theorem cometRewardsDecode_setRewardConfigWithMultiplier_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode - (setRewardConfigWithMultiplierTransition.params.map Param.name) - (transitionSignature setRewardConfigWithMultiplierTransition).paramTypes I.calldata = - none := by - show decodeCalldataWithMode config.abiDecodeMode ["comet", "token", "multiplier"] - [addr, addr, uint256] I.calldata = none - change decodeCalldata ["comet", "token", "multiplier"] - [.elem .address, .elem .address, abiUInt256] I.calldata = none - exact decodeCalldata_address_address_uint256_none_huge - (cd := I.calldata) (x := "comet") (y := "token") (z := "multiplier") hbig - -theorem cometRewardsSetRewardConfigWithMultiplierSelector_size {I : ExecutionEnv} - (hsel : selIs I (cometRewardsSelBytes 10)) : - 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (cometRewardsSelBytes 10) rfl hsel - -theorem cometRewardsDispatch_setRewardConfigWithMultiplier {cd : ByteArray} - (hsel : (cometRewardsSelBytes 10 == cd.extract 0 4) = true) : - dispatchMsg contract cd = some setRewardConfigWithMultiplierTransition := by - refine dispatchMsg_eq_some_of_split - (pre := [claimTransition, claimToTransition, getRewardOwedTransition, governorTransition, - rewardConfigTransition, rewardsClaimedTransition, setRewardConfigTransition]) - (post := [setRewardsClaimedTransition, transferGovernorTransition, withdrawTokenTransition]) - rfl rfl ?_ (by rw [selectorOf, setRewardConfigWithMultiplierSelectorBytes]; exact hsel) - have hcd : cd.extract 0 4 = cometRewardsSelBytes 10 := - (byteArray_eq_of_beq hsel).symm - intro t ht - simp only [List.mem_cons, List.not_mem_nil, or_false] at ht - rcases ht with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, claimSelectorBytes, hcd] - decide - · rw [selectorOf, claimToSelectorBytes, hcd] - decide - · rw [selectorOf, getRewardOwedSelectorBytes, hcd] - decide - · rw [selectorOf, governorSelectorBytes, hcd] - decide - · rw [selectorOf, rewardConfigSelectorBytes, hcd] - decide - · rw [selectorOf, rewardsClaimedSelectorBytes, hcd] - decide - · rw [selectorOf, setRewardConfigSelectorBytes, hcd] - decide - -theorem cometRewardsSetRewardConfigWithMultiplierCalldataCheckOk {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hhi : I.calldata.size < 2 ^ 255 + 4) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨0⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨0⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - simpa using - solcCalldataStaticLenCheckOk (sz := I.calldata.size) (words := 3) - (by simpa using hsz100) hhi hsize - -theorem cometRewardsSetRewardConfigWithMultiplierCalldataCheckShort {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hshort : I.calldata.size < 100) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 hsz4 hsize] - simpa using - solcCalldataStaticLenCheckShort (sz := I.calldata.size) (words := 3) - hsz4 (by simpa using hshort) hsize (by norm_num) - -theorem cometRewardsSetRewardConfigWithMultiplierCalldataCheckHuge {I : ExecutionEnv} - (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - simpa using - solcCalldataStaticLenCheckHuge (sz := I.calldata.size) (words := 3) - hbig hsize (by norm_num) - -theorem cometRewardsSetRewardConfigWithMultiplierX_dec2875_args - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigWithMultiplierPc - (dispatchArmLastStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2875⟩ - [UInt256.ofNat I.calldata.size, ⟨173⟩, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd159⟩ := hreach - have rd161 := evm_run rd159 with [jumpdest, callvalue] - rw [hwv] at rd161 - have rd172 := evm_run rd161 with [ - push2 ⟨797⟩, jumpiNT (by decide), - push2 ⟨173⟩, calldatasize, push2 ⟨2875⟩] - exact ⟨_, _, evm_run rd172 with [jump (by native_decide)]⟩ - -theorem cometRewardsSetRewardConfigWithMultiplierX_shortarg - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz4 : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hshort : I.calldata.size < 100) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigWithMultiplierPc - (dispatchArmLastStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsSetRewardConfigWithMultiplierCalldataCheckShort - (I := I) hsz4 hsize hshort - obtain ⟨_, _, rd2875⟩ := - cometRewardsSetRewardConfigWithMultiplierX_dec2875_args - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hreach - have rd2884 := evm_run rd2875 with [ - jumpdest, push1 ⟨96⟩, swap1, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd2884 - rw [hslt] at rd2884 - exact evm_run rd2884 with [ - push2 ⟨1004⟩, jumpiT (by decide) (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsSetRewardConfigWithMultiplierX_hugearg - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigWithMultiplierPc - (dispatchArmLastStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsSetRewardConfigWithMultiplierCalldataCheckHuge - (I := I) hsize hbig - obtain ⟨_, _, rd2875⟩ := - cometRewardsSetRewardConfigWithMultiplierX_dec2875_args - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hreach - have rd2884 := evm_run rd2875 with [ - jumpdest, push1 ⟨96⟩, swap1, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd2884 - rw [hslt] at rd2884 - exact evm_run rd2884 with [ - push2 ⟨1004⟩, jumpiT (by decide) (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_dec173_args - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigWithMultiplierPc - (dispatchArmLastStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨173⟩ - [setRewardConfigWithMultiplierMultiplierWord I, - setRewardConfigWithMultiplierTokenWord I, - setRewardConfigWithMultiplierCometWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt := cometRewardsSetRewardConfigWithMultiplierCalldataCheckOk - (I := I) hsz100 hsize hhi - obtain ⟨_, _, rd2875⟩ := - cometRewardsSetRewardConfigWithMultiplierX_dec2875_args - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hreach - have rd2884 := evm_run rd2875 with [ - jumpdest, push1 ⟨96⟩, swap1, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd2884 - rw [hslt] at rd2884 - have rd2888 := evm_run rd2884 with [ - push2 ⟨1004⟩, jumpiNT (by decide)] - have rd2909 := evm_run rd2888 with [ - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, - swap1, push1 ⟨4⟩, calldataload, dup3, dup2, and, dup2, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land (setRewardConfigWithMultiplierCometWord I) solcAddrMask = - setRewardConfigWithMultiplierCometWord I := by - exact solcAddrMask_clean (by - simpa [setRewardConfigWithMultiplierCometWord, calldataWord] using hcanon0) - have hclean' : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32) := by - simpa [setRewardConfigWithMultiplierCometWord, calldataWord] using hclean - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean'] - exact u256_sub_self _), - swap2] - have rd2922 := evm_run rd2909 with [ - push1 ⟨36⟩, calldataload, swap1, dup2, and, dup2, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land (setRewardConfigWithMultiplierTokenWord I) solcAddrMask = - setRewardConfigWithMultiplierTokenWord I := by - exact solcAddrMask_clean (by - simpa [setRewardConfigWithMultiplierTokenWord, calldataWord] using hcanon1) - have hclean' : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32) := by - simpa [setRewardConfigWithMultiplierTokenWord, calldataWord] using hclean - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean'] - exact u256_sub_self _), - swap1] - have rd2927 := evm_run rd2922 with [ - push1 ⟨68⟩, calldataload, swap1] - exact ⟨_, _, evm_run rd2927 with [jump (by native_decide)]⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_noncanon_comet - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hnc : UInt256.eq (setRewardConfigWithMultiplierCometWord I) - (UInt256.land (setRewardConfigWithMultiplierCometWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigWithMultiplierPc - (dispatchArmLastStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsSetRewardConfigWithMultiplierCalldataCheckOk - (I := I) hsz100 hsize hhi - obtain ⟨_, _, rd2875⟩ := - cometRewardsSetRewardConfigWithMultiplierX_dec2875_args - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hreach - have rd2884 := evm_run rd2875 with [ - jumpdest, push1 ⟨96⟩, swap1, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd2884 - rw [hslt] at rd2884 - have rd2888 := evm_run rd2884 with [ - push2 ⟨1004⟩, jumpiNT (by decide)] - exact evm_run rd2888 with [ - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, - swap1, push1 ⟨4⟩, calldataload, dup3, dup2, and, dup2, sub, - push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hraw : - UInt256.eq - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - (UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask) = ⟨1⟩ := by - rw [← heq] - exact uInt256_eq_self _ - have hclean : - UInt256.eq (setRewardConfigWithMultiplierCometWord I) - (UInt256.land (setRewardConfigWithMultiplierCometWord I) solcAddrMask) = - ⟨1⟩ := by - simpa [setRewardConfigWithMultiplierCometWord, calldataWord] using hraw - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_noncanon_token - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) - (hnc : UInt256.eq (setRewardConfigWithMultiplierTokenWord I) - (UInt256.land (setRewardConfigWithMultiplierTokenWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigWithMultiplierPc - (dispatchArmLastStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsSetRewardConfigWithMultiplierCalldataCheckOk - (I := I) hsz100 hsize hhi - obtain ⟨_, _, rd2875⟩ := - cometRewardsSetRewardConfigWithMultiplierX_dec2875_args - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hreach - have rd2884 := evm_run rd2875 with [ - jumpdest, push1 ⟨96⟩, swap1, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd2884 - rw [hslt] at rd2884 - have rd2888 := evm_run rd2884 with [ - push2 ⟨1004⟩, jumpiNT (by decide)] - have rd2909 := evm_run rd2888 with [ - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, - swap1, push1 ⟨4⟩, calldataload, dup3, dup2, and, dup2, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32) := by - have hclean' : - UInt256.land (setRewardConfigWithMultiplierCometWord I) solcAddrMask = - setRewardConfigWithMultiplierCometWord I := by - exact solcAddrMask_clean (by - simpa [setRewardConfigWithMultiplierCometWord, calldataWord] using hcanon0) - simpa [setRewardConfigWithMultiplierCometWord, calldataWord] using hclean' - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean] - exact u256_sub_self _), - swap2] - exact evm_run rd2909 with [ - push1 ⟨36⟩, calldataload, swap1, dup2, and, dup2, sub, - push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hraw : - UInt256.eq - (uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32)) - (UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32)) - solcAddrMask) = ⟨1⟩ := by - rw [← heq] - exact uInt256_eq_self _ - have hclean : - UInt256.eq (setRewardConfigWithMultiplierTokenWord I) - (UInt256.land (setRewardConfigWithMultiplierTokenWord I) solcAddrMask) = - ⟨1⟩ := by - simpa [setRewardConfigWithMultiplierTokenWord, calldataWord] using hraw - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_revert_auth - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I ≠ solcSourceWord I) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigWithMultiplierPc - (dispatchArmLastStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd173⟩ := - cometRewardsSetRewardConfigWithMultiplierX_dec173_args - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hsz100 hsize hhi hcanon0 hcanon1 hreach - have rd189 := evm_run rd173 with [ - jumpdest, swap2, swap3, swap1, swap4, - push1 ⟨1⟩, dup1, push1 ⟨160⟩, shl, sub, swap4, dup5, push1 ⟨0⟩] - obtain ⟨_, _, rd190₀⟩ := rd189.sload (by decide) (by evm_ov) - obtain ⟨_, _, rd190⟩ : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨190⟩ - [governorWord σ I, - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩, - setRewardConfigWithMultiplierTokenWord I, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by simpa [governorWord] using rd190₀⟩ - have rd193₀ := evm_run rd190 with [and, caller, sub] - have rd193 := rd193₀ - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] at rd193 - have hsub : UInt256.sub (solcSourceWord I) (governorReturnWord σ I) ≠ ⟨0⟩ := by - exact u256_sub_ne_zero_of_ne (by - intro h - exact hauth h.symm) - have hsub' : - UInt256.sub (UInt256.ofNat I.source.val) (UInt256.land (governorWord σ I) solcAddrMask) ≠ - ⟨0⟩ := by - simpa [solcSourceWord, governorReturnWord] using hsub - exact evm_run rd193 with [ - push2 ⟨775⟩, jumpiT hsub' (by native_decide), - jumpdest, dup7, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - push4 ⟨431085831⟩, push1 ⟨227⟩, shl, dup2, - raw mstore 6 (solcReturnMem transferGovernorUnauthorizedSelector) - (UInt256.ofNat 5) (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - rfl) - (by decide) (by evm_ov), - caller, dup2, dup6, add, - raw mstore 3 (transferGovernorUnauthorizedMem (solcSourceWord I)) - (UInt256.ofNat 6) (by decide) mem_cost - (by - rw [show (⟨4⟩ : UInt256) + ⟨128⟩ = ⟨132⟩ from by decide, - show (⟨132⟩ : UInt256).toNat = 132 from by decide] - unfold transferGovernorUnauthorizedMem solcSourceWord - rfl) - (by decide) (by evm_ov), - push1 ⟨36⟩, swap1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_auth_ok - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigWithMultiplierPc - (dispatchArmLastStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨197⟩ - [setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, solcAddrMask, - setRewardConfigWithMultiplierTokenWord I, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd173⟩ := - cometRewardsSetRewardConfigWithMultiplierX_dec173_args - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hsz100 hsize hhi hcanon0 hcanon1 hreach - have rd189 := evm_run rd173 with [ - jumpdest, swap2, swap3, swap1, swap4, - push1 ⟨1⟩, dup1, push1 ⟨160⟩, shl, sub, swap4, dup5, push1 ⟨0⟩] - obtain ⟨_, _, rd190₀⟩ := rd189.sload (by decide) (by evm_ov) - obtain ⟨_, _, rd190⟩ : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨190⟩ - [governorWord σ I, - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩, - setRewardConfigWithMultiplierTokenWord I, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by simpa [governorWord] using rd190₀⟩ - have rd193₀ := evm_run rd190 with [and, caller, sub] - have rd193 := rd193₀ - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] at rd193 - have hsub : - UInt256.sub (UInt256.ofNat I.source.val) - (UInt256.land (governorWord σ I) solcAddrMask) = ⟨0⟩ := by - have hgov : - UInt256.land (governorWord σ I) solcAddrMask = UInt256.ofNat I.source.val := by - simpa [governorReturnWord, solcSourceWord] using hauth - rw [hgov] - exact u256_sub_self _ - rw [hsub] at rd193 - exact ⟨_, _, evm_run rd193 with [push2 ⟨775⟩, jumpiNT (by decide)]⟩ - -def setRewardConfigAlreadyConfiguredSelector : UInt256 := - UInt256.shiftLeft (⟨977536693⟩ : UInt256) ⟨224⟩ - -noncomputable def setRewardConfigAlreadyConfiguredSelectorMem (comet : UInt256) : ByteArray := - (UInt256.toByteArray setRewardConfigAlreadyConfiguredSelector).write 0 - (rewardConfigHashMem comet) 128 32 - -noncomputable def setRewardConfigAlreadyConfiguredMem (comet : UInt256) : ByteArray := - (UInt256.toByteArray comet).write 0 - (setRewardConfigAlreadyConfiguredSelectorMem comet) 132 32 - -def setRewardConfigBaseAccrualScaleSelectorShifted : UInt256 := - UInt256.shiftLeft (⟨1359440587⟩ : UInt256) ⟨225⟩ - -noncomputable def setRewardConfigBaseAccrualScaleCalldataMem (I : ExecutionEnv) : - ByteArray := - (UInt256.toByteArray setRewardConfigBaseAccrualScaleSelectorShifted).write 0 - (rewardConfigHashMem (setRewardConfigWithMultiplierCometWord I)) 128 32 - -theorem setRewardConfigBaseAccrualScaleCalldataMem_read128_4 (I : ExecutionEnv) : - (setRewardConfigBaseAccrualScaleCalldataMem I).readWithPadding 128 4 = - baseAccrualScaleSelector := by - unfold setRewardConfigBaseAccrualScaleCalldataMem - rw [toByteArray_write_read_window_of_gap - (b := setRewardConfigBaseAccrualScaleSelectorShifted) - (mem := rewardConfigHashMem (setRewardConfigWithMultiplierCometWord I)) - (off := 128) (start := 0) (len := 4) - (by norm_num) (by norm_num) (by norm_num) - (by rw [rewardConfigHashMem_size]; exact lt_usize 32 (by norm_num))] - native_decide - -theorem setRewardConfigBaseAccrualScaleCalldataMem_encode (I : ExecutionEnv) : - config.externalABI.encode? "baseAccrualScale" [] = - some ((setRewardConfigBaseAccrualScaleCalldataMem I).readWithPadding 128 4) := by - rw [setRewardConfigBaseAccrualScaleCalldataMem_read128_4] - rfl - -abbrev setRewardConfigBasePostCallTail (I : ExecutionEnv) : List UInt256 := - [setRewardConfigWithMultiplierTokenWord I, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, ⟨128⟩, ⟨64⟩, ⟨0⟩] - -abbrev setRewardConfigBasePostCallStack (z : Bool) (I : ExecutionEnv) : List UInt256 := - (if z then ⟨1⟩ else ⟨0⟩) :: setRewardConfigBasePostCallTail I - -noncomputable abbrev setRewardConfigBasePostCallMem - (I : ExecutionEnv) (out : ByteArray) : ByteArray := - out.write 0 (setRewardConfigBaseAccrualScaleCalldataMem I) 128 - (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat - -abbrev setRewardConfigBasePostCallAw : UInt256 := - UInt256.ofNat (MachineState.M - (MachineState.M (UInt256.ofNat 5).toNat (⟨128⟩ : UInt256).toNat - (⟨4⟩ : UInt256).toNat) - (⟨128⟩ : UInt256).toNat (⟨32⟩ : UInt256).toNat) - -theorem setRewardConfigBaseTarget_eq_targetWord (I : ExecutionEnv) : - EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat) = - AccountAddress.ofUInt256 (setRewardConfigWithMultiplierCometWord I) := by - rw [accountAddress_ofUInt256_eq_ofNat_toNat] - apply Fin.ext - simp [EVM.address, EVM.uintN] - exact Nat.mod_eq_of_lt (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat).isLt - -theorem setRewardConfigBaseAccrualScaleCalldataMem_read64 (I : ExecutionEnv) : - (setRewardConfigBaseAccrualScaleCalldataMem I).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - unfold setRewardConfigBaseAccrualScaleCalldataMem - rw [toByteArray_write_read_below_of_gap - (b := setRewardConfigBaseAccrualScaleSelectorShifted) - (mem := rewardConfigHashMem (setRewardConfigWithMultiplierCometWord I)) - (off := 128) (read := 64) - (by have hsz := rewardConfigHashMem_size (setRewardConfigWithMultiplierCometWord I); omega) - (by norm_num) - (by rw [rewardConfigHashMem_size]; exact lt_usize 32 (by norm_num))] - exact rewardConfigHashMem_read64 (setRewardConfigWithMultiplierCometWord I) - -theorem setRewardConfigBaseAccrualScaleCalldataMem_size_ge128 (I : ExecutionEnv) : - 128 ≤ (setRewardConfigBaseAccrualScaleCalldataMem I).size := by - unfold setRewardConfigBaseAccrualScaleCalldataMem - have h160 := - toByteArray_write_size_ge_off_add32 setRewardConfigBaseAccrualScaleSelectorShifted - (rewardConfigHashMem (setRewardConfigWithMultiplierCometWord I)) 128 - (by rw [rewardConfigHashMem_size]; exact lt_usize 32 (by norm_num)) - omega - -theorem setRewardConfigBasePostCallLen_le_out_size {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat ≤ out.size := by - by_cases houtSmall : out.size < 32 - · have hnotle : ¬ (⟨32⟩ : UInt256) ≤ UInt256.ofNat out.size := by - intro hle - have hlev : (32 : Nat) ≤ (UInt256.ofNat out.size).toNat := by - simpa [UInt256.toNat] using hle - rw [UInt256.toNat_ofNat_of_lt houtSize] at hlev - omega - simp [min, hnotle, UInt256.toNat_ofNat_of_lt houtSize] - · have hle : (⟨32⟩ : UInt256) ≤ UInt256.ofNat out.size := by - change (⟨32⟩ : UInt256).val ≤ (UInt256.ofNat out.size).val - change (32 : Nat) ≤ (UInt256.ofNat out.size).toNat - rw [UInt256.toNat_ofNat_of_lt houtSize] - omega - simp [min, hle] - change (32 : Nat) ≤ out.size - omega - -theorem setRewardConfigBasePostCallMem_read64 (I : ExecutionEnv) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (setRewardConfigBasePostCallMem I out).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - dsimp [setRewardConfigBasePostCallMem] - by_cases hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 0 - · rw [hlen, byteArray_write_len_zero] - exact setRewardConfigBaseAccrualScaleCalldataMem_read64 I - · have hsrc : - (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat ≤ out.size := by - exact setRewardConfigBasePostCallLen_le_out_size houtSize - rw [write_read_below_gen_extend out (setRewardConfigBaseAccrualScaleCalldataMem I) - 128 (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat 64 - hlen hsrc (setRewardConfigBaseAccrualScaleCalldataMem_size_ge128 I) - (by norm_num)] - exact setRewardConfigBaseAccrualScaleCalldataMem_read64 I - -theorem setRewardConfigBasePostCallMem_size_ge128 (I : ExecutionEnv) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - 128 ≤ (setRewardConfigBasePostCallMem I out).size := by - dsimp [setRewardConfigBasePostCallMem] - by_cases hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 0 - · rw [hlen, byteArray_write_len_zero] - exact setRewardConfigBaseAccrualScaleCalldataMem_size_ge128 I - · have hsrc : - (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat ≤ out.size := by - exact setRewardConfigBasePostCallLen_le_out_size houtSize - let len := (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat - let base := setRewardConfigBaseAccrualScaleCalldataMem I - have hdest : 128 ≤ base.size := setRewardConfigBaseAccrualScaleCalldataMem_size_ge128 I - by_cases hin : 128 + len ≤ base.size - · rw [write_eq_gen out base 128 len (by simpa [len] using hlen) (by simpa [len] using hsrc) - hin] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract] - omega - · have hext : base.size < 128 + len := Nat.lt_of_not_ge hin - rw [write_eq_gen_extend out base 128 len (by simpa [len] using hlen) - (by simpa [len] using hsrc) hdest hext] - rw [ByteArray.size_append, ByteArray.size_extract, ByteArray.size_extract] - omega - -theorem setRewardConfigBasePostCallMem_mload64 (I : ExecutionEnv) {out : ByteArray} - (houtSize : out.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ (setRewardConfigBasePostCallMem I out).size - ∨ (⟨64⟩ : UInt256) ≥ setRewardConfigBasePostCallAw * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigBasePostCallMem I out).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨128⟩ := by - apply mloadFreePtrValue - · exact lt_of_lt_of_le (by norm_num) (setRewardConfigBasePostCallMem_size_ge128 I houtSize) - · native_decide - · exact setRewardConfigBasePostCallMem_read64 I houtSize - -def uint64Mask : UInt256 := - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩ - -def uint8Int : IntType := .uint ⟨8, by decide⟩ - -def uint8 : ABIType := .elem (.int uint8Int) - -theorem uint64Mask_toNat : uint64Mask.toNat = 2 ^ 64 - 1 := by - native_decide - -theorem uint64Mask_clean {w : UInt256} (h64 : w.toNat < EVM.twoPow 64) : - UInt256.land w uint64Mask = w := by - apply u256_inj - show (UInt256.land w uint64Mask).toNat = w.toNat - have h64' : w.toNat < 2 ^ 64 := by - simpa [EVM.twoPow] using h64 - rw [u256_land_toNat, uint64Mask_toNat, nat_land_mask_eq_mod, - Nat.mod_eq_of_lt h64'] - exact Nat.mod_eq_of_lt w.val.isLt - -theorem uint64Mask_not_clean {w : UInt256} (h64 : ¬ w.toNat < EVM.twoPow 64) : - UInt256.land w uint64Mask ≠ w := by - intro hclean - have hto := congrArg UInt256.toNat hclean - have hsmall : w.toNat % 2 ^ 64 < UInt256.size := by - have hmod := Nat.mod_lt w.toNat (by norm_num : 0 < 2 ^ 64) - have hsz : UInt256.size = 2 ^ 256 := by decide - omega - rw [u256_land_toNat, uint64Mask_toNat, nat_land_mask_eq_mod, - Nat.mod_eq_of_lt hsmall] at hto - have hlt := Nat.mod_lt w.toNat (by norm_num : 0 < 2 ^ 64) - rw [hto] at hlt - exact h64 (by simpa [EVM.twoPow] using hlt) - -def uint8Mask : UInt256 := ⟨255⟩ - -theorem uint8Mask_toNat : uint8Mask.toNat = 2 ^ 8 - 1 := by - native_decide - -theorem uint8Mask_clean {w : UInt256} (h8 : w.toNat < EVM.twoPow 8) : - UInt256.land w uint8Mask = w := by - apply u256_inj - show (UInt256.land w uint8Mask).toNat = w.toNat - have h8' : w.toNat < 2 ^ 8 := by - simpa [EVM.twoPow] using h8 - rw [u256_land_toNat, uint8Mask_toNat, nat_land_mask_eq_mod, - Nat.mod_eq_of_lt h8'] - exact Nat.mod_eq_of_lt w.val.isLt - -theorem uint8Mask_not_clean {w : UInt256} (h8 : ¬ w.toNat < EVM.twoPow 8) : - UInt256.land w uint8Mask ≠ w := by - intro hclean - have hto := congrArg UInt256.toNat hclean - have hsmall : w.toNat % 2 ^ 8 < UInt256.size := by - have hmod := Nat.mod_lt w.toNat (by norm_num : 0 < 2 ^ 8) - have hsz : UInt256.size = 2 ^ 256 := by decide - omega - rw [u256_land_toNat, uint8Mask_toNat, nat_land_mask_eq_mod, - Nat.mod_eq_of_lt hsmall] at hto - have hlt := Nat.mod_lt w.toNat (by norm_num : 0 < 2 ^ 8) - rw [hto] at hlt - exact h8 (by simpa [EVM.twoPow] using hlt) - -def setRewardConfigUInt64Offset20Word (old val : UInt256) : UInt256 := - UInt256.lor - (UInt256.land old - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)))) - (UInt256.land (UInt256.shiftLeft val ⟨160⟩) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩))) - -def setRewardConfigBoolOffset28Word (old bit : UInt256) : UInt256 := - UInt256.lor - (UInt256.land old (UInt256.lnot (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩))) - (UInt256.land (UInt256.shiftLeft bit ⟨224⟩) - (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩)) - -theorem setRewardConfigUInt64Offset20Nat_lt_size (old val : UInt256) : - old.toNat % 2 ^ 160 + 2 ^ 160 * (val.toNat % 2 ^ 64) + - 2 ^ 224 * (old.toNat / 2 ^ 224) < UInt256.size := by - have h0 : old.toNat % 2 ^ 160 < 2 ^ 160 := Nat.mod_lt _ (by norm_num) - have h1 : val.toNat % 2 ^ 64 < 2 ^ 64 := Nat.mod_lt _ (by norm_num) - have h2 : old.toNat / 2 ^ 224 < 2 ^ 32 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 224 * 2 ^ 32 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - exact old.val.isLt - have h0le : old.toNat % 2 ^ 160 ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt h0 - have h1le : val.toNat % 2 ^ 64 ≤ 2 ^ 64 - 1 := Nat.le_pred_of_lt h1 - have h2le : old.toNat / 2 ^ 224 ≤ 2 ^ 32 - 1 := Nat.le_pred_of_lt h2 - have h1term : 2 ^ 160 * (val.toNat % 2 ^ 64) ≤ 2 ^ 160 * (2 ^ 64 - 1) := - Nat.mul_le_mul_left _ h1le - have h2term : 2 ^ 224 * (old.toNat / 2 ^ 224) ≤ 2 ^ 224 * (2 ^ 32 - 1) := - Nat.mul_le_mul_left _ h2le - have hmax : (2 ^ 160 - 1) + 2 ^ 160 * (2 ^ 64 - 1) + - 2 ^ 224 * (2 ^ 32 - 1) < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - -theorem setRewardConfigUInt64Mask_toNat_lt (v : UInt256) : - (UInt256.land v uint64Mask).toNat < 2 ^ 64 := by - rw [u256_land_toNat, uint64Mask_toNat] - have hle : Nat.land v.toNat (2 ^ 64 - 1) ≤ 2 ^ 64 - 1 := nat_land_le_right _ _ - have hltSize : Nat.land v.toNat (2 ^ 64 - 1) < UInt256.size := by - have hlt : Nat.land v.toNat (2 ^ 64 - 1) < 2 ^ 64 := by omega - norm_num [UInt256.size] at hlt ⊢ - omega - rw [Nat.mod_eq_of_lt hltSize] - omega - -theorem setRewardConfigShiftLeft160_uint64Mask_toNat (v : UInt256) : - (UInt256.shiftLeft (UInt256.land v uint64Mask) ⟨160⟩).toNat = - (UInt256.land v uint64Mask).toNat * 2 ^ 160 := by - unfold UInt256.shiftLeft UInt256.toNat - show (Fin.shiftLeft (UInt256.land v uint64Mask).val (⟨160⟩ : UInt256).val).val = _ - unfold Fin.shiftLeft - rw [show (⟨160⟩ : UInt256).val = 160 by rfl] - change ((UInt256.land v uint64Mask).toNat <<< 160) % UInt256.size = - (UInt256.land v uint64Mask).toNat * 2 ^ 160 - rw [Nat.shiftLeft_eq, Nat.mod_eq_of_lt] - have hsmall := setRewardConfigUInt64Mask_toNat_lt v - calc - (UInt256.land v uint64Mask).val.val * 2 ^ 160 < 2 ^ 64 * 2 ^ 160 := - Nat.mul_lt_mul_of_pos_right hsmall (by norm_num) - _ = 2 ^ 224 := by rw [← Nat.pow_add] - _ < UInt256.size := by norm_num [UInt256.size] - -set_option maxRecDepth 2000000 in -theorem setRewardConfigNatLandClearMiddle160_224 (n : Nat) (hn : n < 2 ^ 256) : - Nat.land n ((2 : Nat) ^ 160 - 1 + ((2 : Nat) ^ 256 - 2 ^ 224)) = - n % 2 ^ 160 + (n / 2 ^ 224) * 2 ^ 224 := by - have hhighMask : (2 : Nat) ^ 256 - 2 ^ 224 = (2 ^ 32 - 1) * 2 ^ 224 := by - norm_num [Nat.pow_add] - have hmask : - (2 : Nat) ^ 160 - 1 + ((2 : Nat) ^ 256 - 2 ^ 224) = - Nat.lor (2 ^ 160 - 1) ((2 ^ 32 - 1) * 2 ^ 224) := by - rw [hhighMask] - rw [nat_lor_shift_add (2 ^ 160 - 1) (2 ^ 32 - 1) 224] - norm_num - have hrhs : - n % 2 ^ 160 + (n / 2 ^ 224) * 2 ^ 224 = - Nat.lor (n % 2 ^ 160) ((n / 2 ^ 224) * 2 ^ 224) := by - rw [nat_lor_shift_add (n % 2 ^ 160) (n / 2 ^ 224) 224] - exact lt_of_lt_of_le (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 160)) - (Nat.pow_le_pow_right (by norm_num) (by norm_num)) - rw [hmask, hrhs] - apply Nat.eq_of_testBit_eq - intro i - change (n &&& ((2 ^ 160 - 1) ||| ((2 ^ 32 - 1) * 2 ^ 224))).testBit i = - ((n % 2 ^ 160) ||| (n / 2 ^ 224 * 2 ^ 224)).testBit i - rw [Nat.testBit_and, Nat.testBit_or, Nat.testBit_or, - Nat.testBit_two_pow_sub_one, Nat.testBit_mul_two_pow, - Nat.testBit_mul_two_pow, Nat.testBit_mod_two_pow] - by_cases hi160 : i < 160 - · have hi224 : i < 224 := by omega - simp [hi160, hi224] - · by_cases hi224 : i < 224 - · have hnot224 : ¬ 224 ≤ i := by omega - simp [hi160, hnot224] - · have h224 : 224 ≤ i := Nat.le_of_not_gt hi224 - by_cases hi256 : i < 256 - · have hlow32 : i - 224 < 32 := by omega - simp [hi160, h224] - rw [show Nat.testBit 4294967295 (i - 224) = true by - change Nat.testBit (2 ^ 32 - 1) (i - 224) = true - rw [Nat.testBit_two_pow_sub_one] - simp [hlow32]] - simp - change n.testBit i = (n / 2 ^ 224).testBit (i - 224) - exact (divPow_testBit n 224 i h224).symm - · have hnbit : n.testBit i = false := - Nat.testBit_lt_two_pow (lt_of_lt_of_le hn - (Nat.pow_le_pow_right (by norm_num) (by omega : (256 : Nat) ≤ i))) - have hq : n / 2 ^ 224 < 2 ^ 32 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 224 * 2 ^ 32 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - exact hn - have hqbit : (n / 2 ^ 224).testBit (i - 224) = false := - Nat.testBit_lt_two_pow - (lt_of_lt_of_le hq (Nat.pow_le_pow_right (by norm_num) - (by omega : (32 : Nat) ≤ i - 224))) - simp [hi160, h224, hnbit] - simpa [show - 26959946667150639794667015087019630673637144422540572481103610249216 = - (2 : Nat) ^ 224 by norm_num] using hqbit - -theorem setRewardConfigNatLandShiftLeft160_mid64 (n : Nat) : - Nat.land ((n <<< 160) % 2 ^ 256) ((2 : Nat) ^ 224 - 2 ^ 160) = - (n % 2 ^ 64) * 2 ^ 160 := by - apply Nat.eq_of_testBit_eq - intro i - rw [show (2 : Nat) ^ 224 - 2 ^ 160 = (2 ^ 64 - 1) * 2 ^ 160 by - norm_num [Nat.pow_add]] - change (((n <<< 160) % 2 ^ 256) &&& ((2 ^ 64 - 1) * 2 ^ 160)).testBit i = - (n % 2 ^ 64 * 2 ^ 160).testBit i - rw [Nat.testBit_and, Nat.testBit_mod_two_pow, Nat.testBit_mul_two_pow, - Nat.testBit_mul_two_pow, Nat.testBit_mod_two_pow, testBit_shiftLeft] - by_cases hi160 : i < 160 - · simp [hi160] - · have h160 : 160 ≤ i := Nat.le_of_not_gt hi160 - by_cases hi224 : i < 224 - · have h64 : i - 160 < 64 := by omega - have hi256 : i < 256 := by omega - simp [hi160, h160, hi256, h64] - rw [show Nat.testBit 18446744073709551615 (i - 160) = true by - change Nat.testBit (2 ^ 64 - 1) (i - 160) = true - rw [Nat.testBit_two_pow_sub_one] - simp [h64]] - simp - · have hnot64 : ¬ i - 160 < 64 := by omega - by_cases hi256 : i < 256 - · simp [hi160, h160, hi256, hnot64] - rw [show Nat.testBit 18446744073709551615 (i - 160) = false by - change Nat.testBit (2 ^ 64 - 1) (i - 160) = false - rw [Nat.testBit_two_pow_sub_one] - simp [hnot64]] - simp - · simp [hi160, h160, hi256, hnot64] - -theorem setRewardConfigNatLorPacked160_224 (low mid high : Nat) - (hlow : low < 2 ^ 160) (hmid : mid < 2 ^ 64) : - Nat.lor (low + high * 2 ^ 224) (mid * 2 ^ 160) = - low + mid * 2 ^ 160 + high * 2 ^ 224 := by - have hlow224 : low < 2 ^ 224 := - lt_of_lt_of_le hlow (Nat.pow_le_pow_right (by norm_num) (by norm_num)) - have hclear : low + high * 2 ^ 224 = Nat.lor low (high * 2 ^ 224) := by - rw [nat_lor_shift_add low high 224 hlow224] - rw [hclear] - rw [show Nat.lor (Nat.lor low (high * 2 ^ 224)) (mid * 2 ^ 160) = - Nat.lor low (Nat.lor (mid * 2 ^ 160) (high * 2 ^ 224)) by - calc - Nat.lor (Nat.lor low (high * 2 ^ 224)) (mid * 2 ^ 160) - = Nat.lor low (Nat.lor (high * 2 ^ 224) (mid * 2 ^ 160)) := - Nat.lor_assoc low (high * 2 ^ 224) (mid * 2 ^ 160) - _ = Nat.lor low (Nat.lor (mid * 2 ^ 160) (high * 2 ^ 224)) := by - rw [nat_lor_comm (high * 2 ^ 224) (mid * 2 ^ 160)]] - rw [nat_lor_shift_add (mid * 2 ^ 160) high 224] - · rw [show mid * 2 ^ 160 + high * 2 ^ 224 = - (mid + high * 2 ^ 64) * 2 ^ 160 by ring] - rw [nat_lor_shift_add low (mid + high * 2 ^ 64) 160 hlow] - ring - · calc - mid * 2 ^ 160 < 2 ^ 64 * 2 ^ 160 := - Nat.mul_lt_mul_of_pos_right hmid (by norm_num) - _ = 2 ^ 224 := by rw [← Nat.pow_add] - -set_option maxRecDepth 2000000 in -theorem setRewardConfigUInt64Offset20Word_toNat (old val : UInt256) : - (setRewardConfigUInt64Offset20Word old val).toNat = - old.toNat % 2 ^ 160 + 2 ^ 160 * (val.toNat % 2 ^ 64) + - 2 ^ 224 * (old.toNat / 2 ^ 224) := by - unfold setRewardConfigUInt64Offset20Word - rw [u256_lor_toNat, u256_land_toNat, u256_land_toNat] - have hclearMask : - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩))).toNat = - 2 ^ 160 - 1 + ((2 : Nat) ^ 256 - 2 ^ 224) := by - native_decide - have hmidMask : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).toNat = - (2 : Nat) ^ 224 - 2 ^ 160 := by - native_decide - rw [hclearMask, hmidMask] - have hshift : - (UInt256.shiftLeft val ⟨160⟩).toNat = (val.toNat <<< 160) % 2 ^ 256 := by - unfold UInt256.shiftLeft UInt256.toNat - show (Fin.shiftLeft val.val (⟨160⟩ : UInt256).val).val = _ - unfold Fin.shiftLeft - rw [show (⟨160⟩ : UInt256).val = 160 by rfl] - change (val.toNat <<< 160) % UInt256.size = (val.toNat <<< 160) % 2 ^ 256 - norm_num [UInt256.size] - rw [hshift] - rw [setRewardConfigNatLandClearMiddle160_224 old.toNat (by - change old.val.val < 2 ^ 256 - exact old.val.isLt)] - rw [setRewardConfigNatLandShiftLeft160_mid64 val.toNat] - have hclearLt : - old.toNat % 2 ^ 160 + old.toNat / 2 ^ 224 * 2 ^ 224 < UInt256.size := by - have hlow : old.toNat % 2 ^ 160 < 2 ^ 160 := Nat.mod_lt _ (by norm_num) - have hq : old.toNat / 2 ^ 224 < 2 ^ 32 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 224 * 2 ^ 32 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - exact old.val.isLt - have hlowle : old.toNat % 2 ^ 160 ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hqle : old.toNat / 2 ^ 224 ≤ 2 ^ 32 - 1 := Nat.le_pred_of_lt hq - have hqterm : old.toNat / 2 ^ 224 * 2 ^ 224 ≤ (2 ^ 32 - 1) * 2 ^ 224 := - Nat.mul_le_mul_right _ hqle - have hmax : (2 ^ 160 - 1) + (2 ^ 32 - 1) * 2 ^ 224 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - have hmidLt : (val.toNat % 2 ^ 64) * 2 ^ 160 < UInt256.size := by - have h := Nat.mod_lt val.toNat (by norm_num : 0 < 2 ^ 64) - calc - (val.toNat % 2 ^ 64) * 2 ^ 160 < 2 ^ 64 * 2 ^ 160 := - Nat.mul_lt_mul_of_pos_right h (by norm_num) - _ = 2 ^ 224 := by rw [← Nat.pow_add] - _ < UInt256.size := by norm_num [UInt256.size] - rw [Nat.mod_eq_of_lt hclearLt, Nat.mod_eq_of_lt hmidLt] - have hlow : old.toNat % 2 ^ 160 < 2 ^ 160 := Nat.mod_lt _ (by norm_num) - have hmid : val.toNat % 2 ^ 64 < 2 ^ 64 := Nat.mod_lt _ (by norm_num) - have hlor : - Nat.lor - (old.toNat % 2 ^ 160 + old.toNat / 2 ^ 224 * 2 ^ 224) - (val.toNat % 2 ^ 64 * 2 ^ 160) = - old.toNat % 2 ^ 160 + val.toNat % 2 ^ 64 * 2 ^ 160 + - old.toNat / 2 ^ 224 * 2 ^ 224 := - setRewardConfigNatLorPacked160_224 - (old.toNat % 2 ^ 160) (val.toNat % 2 ^ 64) - (old.toNat / 2 ^ 224) hlow hmid - have hlorLt : - Nat.lor - (old.toNat % 2 ^ 160 + old.toNat / 2 ^ 224 * 2 ^ 224) - (val.toNat % 2 ^ 64 * 2 ^ 160) < UInt256.size := by - rw [hlor] - simpa [Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc, - Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] - using setRewardConfigUInt64Offset20Nat_lt_size old val - rw [Nat.mod_eq_of_lt hlorLt, hlor] - ring - -theorem setRewardConfigBoolOffset28Nat_lt_size (old bit : UInt256) : - old.toNat % 2 ^ 224 + 2 ^ 224 * (bit.toNat % 2 ^ 8) + - 2 ^ 232 * (old.toNat / 2 ^ 232) < UInt256.size := by - have h0 : old.toNat % 2 ^ 224 < 2 ^ 224 := Nat.mod_lt _ (by norm_num) - have h1 : bit.toNat % 2 ^ 8 < 2 ^ 8 := Nat.mod_lt _ (by norm_num) - have h2 : old.toNat / 2 ^ 232 < 2 ^ 24 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 232 * 2 ^ 24 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - exact old.val.isLt - have h0le : old.toNat % 2 ^ 224 ≤ 2 ^ 224 - 1 := Nat.le_pred_of_lt h0 - have h1le : bit.toNat % 2 ^ 8 ≤ 2 ^ 8 - 1 := Nat.le_pred_of_lt h1 - have h2le : old.toNat / 2 ^ 232 ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt h2 - have h1term : 2 ^ 224 * (bit.toNat % 2 ^ 8) ≤ 2 ^ 224 * (2 ^ 8 - 1) := - Nat.mul_le_mul_left _ h1le - have h2term : 2 ^ 232 * (old.toNat / 2 ^ 232) ≤ 2 ^ 232 * (2 ^ 24 - 1) := - Nat.mul_le_mul_left _ h2le - have hmax : (2 ^ 224 - 1) + 2 ^ 224 * (2 ^ 8 - 1) + - 2 ^ 232 * (2 ^ 24 - 1) < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - -theorem setRewardConfigUInt8Mask_toNat_lt (v : UInt256) : - (UInt256.land v ⟨255⟩).toNat < 2 ^ 8 := by - rw [u256_land_toNat] - have hle : Nat.land v.toNat (⟨255⟩ : UInt256).toNat ≤ (⟨255⟩ : UInt256).toNat := - nat_land_le_right _ _ - have hmask : (⟨255⟩ : UInt256).toNat = 2 ^ 8 - 1 := by native_decide - rw [hmask] at hle ⊢ - have hltSize : Nat.land v.toNat (2 ^ 8 - 1) < UInt256.size := by - have hlt : Nat.land v.toNat (2 ^ 8 - 1) < 2 ^ 8 := by omega - norm_num [UInt256.size] at hlt ⊢ - omega - rw [Nat.mod_eq_of_lt hltSize] - omega - -theorem setRewardConfigShiftLeft224_uint8Mask_toNat (v : UInt256) : - (UInt256.shiftLeft (UInt256.land v ⟨255⟩) ⟨224⟩).toNat = - (UInt256.land v ⟨255⟩).toNat * 2 ^ 224 := by - unfold UInt256.shiftLeft UInt256.toNat - show (Fin.shiftLeft (UInt256.land v ⟨255⟩).val (⟨224⟩ : UInt256).val).val = _ - unfold Fin.shiftLeft - rw [show (⟨224⟩ : UInt256).val = 224 by rfl] - change ((UInt256.land v ⟨255⟩).toNat <<< 224) % UInt256.size = - (UInt256.land v ⟨255⟩).toNat * 2 ^ 224 - rw [Nat.shiftLeft_eq, Nat.mod_eq_of_lt] - have hsmall := setRewardConfigUInt8Mask_toNat_lt v - calc - (UInt256.land v ⟨255⟩).val.val * 2 ^ 224 < 2 ^ 8 * 2 ^ 224 := - Nat.mul_lt_mul_of_pos_right hsmall (by norm_num) - _ = 2 ^ 232 := by rw [← Nat.pow_add] - _ < UInt256.size := by norm_num [UInt256.size] - -set_option maxRecDepth 2000000 in -theorem setRewardConfigNatLandClearMiddle224_232 (n : Nat) (hn : n < 2 ^ 256) : - Nat.land n ((2 : Nat) ^ 224 - 1 + ((2 : Nat) ^ 256 - 2 ^ 232)) = - n % 2 ^ 224 + (n / 2 ^ 232) * 2 ^ 232 := by - have hhighMask : (2 : Nat) ^ 256 - 2 ^ 232 = (2 ^ 24 - 1) * 2 ^ 232 := by - norm_num [Nat.pow_add] - have hmask : - (2 : Nat) ^ 224 - 1 + ((2 : Nat) ^ 256 - 2 ^ 232) = - Nat.lor (2 ^ 224 - 1) ((2 ^ 24 - 1) * 2 ^ 232) := by - rw [hhighMask] - rw [nat_lor_shift_add (2 ^ 224 - 1) (2 ^ 24 - 1) 232] - norm_num - have hrhs : - n % 2 ^ 224 + (n / 2 ^ 232) * 2 ^ 232 = - Nat.lor (n % 2 ^ 224) ((n / 2 ^ 232) * 2 ^ 232) := by - rw [nat_lor_shift_add (n % 2 ^ 224) (n / 2 ^ 232) 232] - exact lt_of_lt_of_le (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 224)) - (Nat.pow_le_pow_right (by norm_num) (by norm_num)) - rw [hmask, hrhs] - apply Nat.eq_of_testBit_eq - intro i - change (n &&& ((2 ^ 224 - 1) ||| ((2 ^ 24 - 1) * 2 ^ 232))).testBit i = - ((n % 2 ^ 224) ||| (n / 2 ^ 232 * 2 ^ 232)).testBit i - rw [Nat.testBit_and, Nat.testBit_or, Nat.testBit_or, - Nat.testBit_two_pow_sub_one, Nat.testBit_mul_two_pow, - Nat.testBit_mul_two_pow, Nat.testBit_mod_two_pow] - by_cases hi224 : i < 224 - · have hi232 : i < 232 := by omega - simp [hi224, hi232] - · by_cases hi232 : i < 232 - · have hnot232 : ¬ 232 ≤ i := by omega - simp [hi224, hnot232] - · have h232 : 232 ≤ i := Nat.le_of_not_gt hi232 - by_cases hi256 : i < 256 - · have hlow24 : i - 232 < 24 := by omega - simp [hi224, h232] - rw [show Nat.testBit 16777215 (i - 232) = true by - change Nat.testBit (2 ^ 24 - 1) (i - 232) = true - rw [Nat.testBit_two_pow_sub_one] - simp [hlow24]] - simp - change n.testBit i = (n / 2 ^ 232).testBit (i - 232) - exact (divPow_testBit n 232 i h232).symm - · have hnbit : n.testBit i = false := - Nat.testBit_lt_two_pow (lt_of_lt_of_le hn - (Nat.pow_le_pow_right (by norm_num) (by omega : (256 : Nat) ≤ i))) - have hq : n / 2 ^ 232 < 2 ^ 24 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 232 * 2 ^ 24 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - exact hn - have hqbit : (n / 2 ^ 232).testBit (i - 232) = false := - Nat.testBit_lt_two_pow - (lt_of_lt_of_le hq (Nat.pow_le_pow_right (by norm_num) - (by omega : (24 : Nat) ≤ i - 232))) - simp [hi224, h232, hnbit] - simpa [show - 6901746346790563787434755862277025452451108972170386555162524223799296 = - (2 : Nat) ^ 232 by norm_num] using hqbit - -theorem setRewardConfigNatLandShiftLeft224_mid8 (n : Nat) : - Nat.land ((n <<< 224) % 2 ^ 256) (((2 : Nat) ^ 8 - 1) * 2 ^ 224) = - (n % 2 ^ 8) * 2 ^ 224 := by - apply Nat.eq_of_testBit_eq - intro i - change (((n <<< 224) % 2 ^ 256) &&& ((2 ^ 8 - 1) * 2 ^ 224)).testBit i = - (n % 2 ^ 8 * 2 ^ 224).testBit i - rw [Nat.testBit_and, Nat.testBit_mod_two_pow, Nat.testBit_mul_two_pow, - Nat.testBit_mul_two_pow, Nat.testBit_mod_two_pow, testBit_shiftLeft] - by_cases hi224 : i < 224 - · simp [hi224] - · have h224 : 224 ≤ i := Nat.le_of_not_gt hi224 - by_cases hi232 : i < 232 - · have h8 : i - 224 < 8 := by omega - have hi256 : i < 256 := by omega - simp [hi224, h224, hi256, h8] - rw [show Nat.testBit 255 (i - 224) = true by - change Nat.testBit (2 ^ 8 - 1) (i - 224) = true - rw [Nat.testBit_two_pow_sub_one] - simp [h8]] - simp - · have hnot8 : ¬ i - 224 < 8 := by omega - by_cases hi256 : i < 256 - · simp [hi224, h224, hi256, hnot8] - rw [show Nat.testBit 255 (i - 224) = false by - change Nat.testBit (2 ^ 8 - 1) (i - 224) = false - rw [Nat.testBit_two_pow_sub_one] - simp [hnot8]] - simp - · simp [hi224, h224, hi256, hnot8] - -theorem setRewardConfigNatLorPacked224_232 (low mid high : Nat) - (hlow : low < 2 ^ 224) (hmid : mid < 2 ^ 8) : - Nat.lor (low + high * 2 ^ 232) (mid * 2 ^ 224) = - low + mid * 2 ^ 224 + high * 2 ^ 232 := by - have hlow232 : low < 2 ^ 232 := - lt_of_lt_of_le hlow (Nat.pow_le_pow_right (by norm_num) (by norm_num)) - have hclear : low + high * 2 ^ 232 = Nat.lor low (high * 2 ^ 232) := by - rw [nat_lor_shift_add low high 232 hlow232] - rw [hclear] - rw [show Nat.lor (Nat.lor low (high * 2 ^ 232)) (mid * 2 ^ 224) = - Nat.lor low (Nat.lor (mid * 2 ^ 224) (high * 2 ^ 232)) by - calc - Nat.lor (Nat.lor low (high * 2 ^ 232)) (mid * 2 ^ 224) - = Nat.lor low (Nat.lor (high * 2 ^ 232) (mid * 2 ^ 224)) := - Nat.lor_assoc low (high * 2 ^ 232) (mid * 2 ^ 224) - _ = Nat.lor low (Nat.lor (mid * 2 ^ 224) (high * 2 ^ 232)) := by - rw [nat_lor_comm (high * 2 ^ 232) (mid * 2 ^ 224)]] - rw [nat_lor_shift_add (mid * 2 ^ 224) high 232] - · rw [show mid * 2 ^ 224 + high * 2 ^ 232 = - (mid + high * 2 ^ 8) * 2 ^ 224 by ring] - rw [nat_lor_shift_add low (mid + high * 2 ^ 8) 224 hlow] - ring - · calc - mid * 2 ^ 224 < 2 ^ 8 * 2 ^ 224 := - Nat.mul_lt_mul_of_pos_right hmid (by norm_num) - _ = 2 ^ 232 := by rw [← Nat.pow_add] - -set_option maxRecDepth 2000000 in -theorem setRewardConfigBoolOffset28Word_toNat (old bit : UInt256) : - (setRewardConfigBoolOffset28Word old bit).toNat = - old.toNat % 2 ^ 224 + 2 ^ 224 * (bit.toNat % 2 ^ 8) + - 2 ^ 232 * (old.toNat / 2 ^ 232) := by - unfold setRewardConfigBoolOffset28Word - rw [u256_lor_toNat, u256_land_toNat, u256_land_toNat] - have hclearMask : - (UInt256.lnot (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩)).toNat = - 2 ^ 224 - 1 + ((2 : Nat) ^ 256 - 2 ^ 232) := by - native_decide - have hmidMask : - (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩).toNat = - ((2 : Nat) ^ 8 - 1) * 2 ^ 224 := by - native_decide - rw [hclearMask, hmidMask] - have hshift : - (UInt256.shiftLeft bit ⟨224⟩).toNat = (bit.toNat <<< 224) % 2 ^ 256 := by - unfold UInt256.shiftLeft UInt256.toNat - show (Fin.shiftLeft bit.val (⟨224⟩ : UInt256).val).val = _ - unfold Fin.shiftLeft - rw [show (⟨224⟩ : UInt256).val = 224 by rfl] - change (bit.toNat <<< 224) % UInt256.size = (bit.toNat <<< 224) % 2 ^ 256 - norm_num [UInt256.size] - rw [hshift] - rw [setRewardConfigNatLandClearMiddle224_232 old.toNat (by - change old.val.val < 2 ^ 256 - exact old.val.isLt)] - rw [setRewardConfigNatLandShiftLeft224_mid8 bit.toNat] - have hclearLt : - old.toNat % 2 ^ 224 + old.toNat / 2 ^ 232 * 2 ^ 232 < UInt256.size := by - have hlow : old.toNat % 2 ^ 224 < 2 ^ 224 := Nat.mod_lt _ (by norm_num) - have hq : old.toNat / 2 ^ 232 < 2 ^ 24 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 232 * 2 ^ 24 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - exact old.val.isLt - have hlowle : old.toNat % 2 ^ 224 ≤ 2 ^ 224 - 1 := Nat.le_pred_of_lt hlow - have hqle : old.toNat / 2 ^ 232 ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hq - have hqterm : old.toNat / 2 ^ 232 * 2 ^ 232 ≤ (2 ^ 24 - 1) * 2 ^ 232 := - Nat.mul_le_mul_right _ hqle - have hmax : (2 ^ 224 - 1) + (2 ^ 24 - 1) * 2 ^ 232 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - have hmidLt : (bit.toNat % 2 ^ 8) * 2 ^ 224 < UInt256.size := by - have h := Nat.mod_lt bit.toNat (by norm_num : 0 < 2 ^ 8) - calc - (bit.toNat % 2 ^ 8) * 2 ^ 224 < 2 ^ 8 * 2 ^ 224 := - Nat.mul_lt_mul_of_pos_right h (by norm_num) - _ = 2 ^ 232 := by rw [← Nat.pow_add] - _ < UInt256.size := by norm_num [UInt256.size] - rw [Nat.mod_eq_of_lt hclearLt, Nat.mod_eq_of_lt hmidLt] - have hlow : old.toNat % 2 ^ 224 < 2 ^ 224 := Nat.mod_lt _ (by norm_num) - have hmid : bit.toNat % 2 ^ 8 < 2 ^ 8 := Nat.mod_lt _ (by norm_num) - have hlor : - Nat.lor - (old.toNat % 2 ^ 224 + old.toNat / 2 ^ 232 * 2 ^ 232) - (bit.toNat % 2 ^ 8 * 2 ^ 224) = - old.toNat % 2 ^ 224 + bit.toNat % 2 ^ 8 * 2 ^ 224 + - old.toNat / 2 ^ 232 * 2 ^ 232 := - setRewardConfigNatLorPacked224_232 - (old.toNat % 2 ^ 224) (bit.toNat % 2 ^ 8) - (old.toNat / 2 ^ 232) hlow hmid - have hlorLt : - Nat.lor - (old.toNat % 2 ^ 224 + old.toNat / 2 ^ 232 * 2 ^ 232) - (bit.toNat % 2 ^ 8 * 2 ^ 224) < UInt256.size := by - rw [hlor] - simpa [Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc, - Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] - using setRewardConfigBoolOffset28Nat_lt_size old bit - rw [Nat.mod_eq_of_lt hlorLt, hlor] - ring - -def setRewardConfigSlot0AfterToken (old token : UInt256) : UInt256 := - setAddressOffset0Word old token - -theorem setRewardConfigAddressOffset0Word_toNat_masked (old addr : UInt256) : - (setAddressOffset0Word old addr).toNat = - addr.toNat % 2 ^ 160 + old.toNat / 2 ^ 160 * 2 ^ 160 := by - unfold setAddressOffset0Word - rw [u256_lor_toNat, addressOffset0High160Mask_toNat, u256_land_toNat] - have hmask : solcAddrMask.toNat = 2 ^ 160 - 1 := by - native_decide - rw [hmask, nat_land_mask_eq_mod] - have haddrLt : addr.toNat % 2 ^ 160 < UInt256.size := by - have h := Nat.mod_lt addr.toNat (by norm_num : 0 < 2 ^ 160) - norm_num [UInt256.size] at h ⊢ - omega - rw [Nat.mod_eq_of_lt haddrLt] - rw [nat_lor_comm] - rw [nat_lor_shift_add (addr.toNat % 2 ^ 160) (old.toNat / 2 ^ 160) 160 - (Nat.mod_lt _ (by norm_num))] - have hsumLt : - addr.toNat % 2 ^ 160 + old.toNat / 2 ^ 160 * 2 ^ 160 < UInt256.size := by - have hlow : addr.toNat % 2 ^ 160 < 2 ^ 160 := Nat.mod_lt _ (by norm_num) - have hq : old.toNat / 2 ^ 160 < 2 ^ 96 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 160 * 2 ^ 96 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - exact old.val.isLt - have hlowle : addr.toNat % 2 ^ 160 ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hqle : old.toNat / 2 ^ 160 ≤ 2 ^ 96 - 1 := Nat.le_pred_of_lt hq - have hqterm : - old.toNat / 2 ^ 160 * 2 ^ 160 ≤ (2 ^ 96 - 1) * 2 ^ 160 := - Nat.mul_le_mul_right _ hqle - have hmax : (2 ^ 160 - 1) + (2 ^ 96 - 1) * 2 ^ 160 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - rw [Nat.mod_eq_of_lt hsumLt] - -def setRewardConfigSlot0AfterRescale (old token rescale : UInt256) : UInt256 := - setRewardConfigUInt64Offset20Word (setRewardConfigSlot0AfterToken old token) rescale - -def setRewardConfigSlot0Final (old token rescale bit : UInt256) : UInt256 := - setRewardConfigBoolOffset28Word (setRewardConfigSlot0AfterRescale old token rescale) bit - -abbrev setRewardConfigSlot0Down (old token rescale : UInt256) : UInt256 := - setRewardConfigSlot0Final old token rescale ⟨0⟩ - -abbrev setRewardConfigSlot0Up (old token rescale : UInt256) : UInt256 := - setRewardConfigSlot0Final old token rescale ⟨1⟩ - -set_option maxHeartbeats 1000000 in -theorem setRewardConfigSlot0Down_toNat (old token rescale : UInt256) : - (setRewardConfigSlot0Down old token rescale).toNat = - token.toNat % 2 ^ 160 + 2 ^ 160 * (rescale.toNat % 2 ^ 64) + - 2 ^ 232 * (old.toNat / 2 ^ 232) := by - unfold setRewardConfigSlot0Down setRewardConfigSlot0Final - setRewardConfigSlot0AfterRescale setRewardConfigSlot0AfterToken - rw [setRewardConfigBoolOffset28Word_toNat, setRewardConfigUInt64Offset20Word_toNat] - rw [show (⟨0⟩ : UInt256).toNat % 2 ^ 8 = 0 by rfl] - simp only [mul_zero, add_zero] - have haddrNat := setRewardConfigAddressOffset0Word_toNat_masked old token - let low : Nat := token.toNat % 2 ^ 160 - let mid : Nat := rescale.toNat % 2 ^ 64 - let q160 : Nat := old.toNat / 2 ^ 160 - let q224 : Nat := old.toNat / 2 ^ 224 - have hlow : low < 2 ^ 160 := by - exact Nat.mod_lt _ (by norm_num) - have hmid : mid < 2 ^ 64 := by - exact Nat.mod_lt _ (by norm_num) - have hlow224 : low + 2 ^ 160 * mid < 2 ^ 224 := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hmidle : mid ≤ 2 ^ 64 - 1 := Nat.le_pred_of_lt hmid - have hmidterm : 2 ^ 160 * mid ≤ 2 ^ 160 * (2 ^ 64 - 1) := - Nat.mul_le_mul_left _ hmidle - have hmax : (2 ^ 160 - 1) + 2 ^ 160 * (2 ^ 64 - 1) < 2 ^ 224 := by - norm_num [Nat.pow_add] - omega - have haddr_mod160 : - (setAddressOffset0Word old token).toNat % 2 ^ 160 = low := by - rw [haddrNat] - change (low + q160 * 2 ^ 160) % 2 ^ 160 = low - rw [Nat.add_mul_mod_self_right, Nat.mod_eq_of_lt hlow] - have haddr_div160 : - (low + q160 * 2 ^ 160) / 2 ^ 160 = q160 := by - rw [Nat.add_mul_div_right _ _ (by norm_num : 0 < 2 ^ 160)] - rw [Nat.div_eq_of_lt hlow] - simp - have haddr_div224 : - (setAddressOffset0Word old token).toNat / 2 ^ 224 = q224 := by - rw [haddrNat] - change (low + q160 * 2 ^ 160) / 2 ^ 224 = q224 - rw [show (2 : Nat) ^ 224 = 2 ^ 160 * 2 ^ 64 by rw [← Nat.pow_add]] - rw [← Nat.div_div_eq_div_mul] - rw [haddr_div160] - change old.toNat / 2 ^ 160 / 2 ^ 64 = old.toNat / 2 ^ 224 - rw [Nat.div_div_eq_div_mul] - rw [show (2 : Nat) ^ 160 * 2 ^ 64 = 2 ^ 224 by rw [← Nat.pow_add]] - have hslot1_mod224 : - ((setAddressOffset0Word old token).toNat % 2 ^ 160 + - 2 ^ 160 * (rescale.toNat % 2 ^ 64) + - 2 ^ 224 * ((setAddressOffset0Word old token).toNat / 2 ^ 224)) % - 2 ^ 224 = - low + 2 ^ 160 * mid := by - rw [haddr_mod160, haddr_div224] - change (low + 2 ^ 160 * mid + 2 ^ 224 * q224) % 2 ^ 224 = - low + 2 ^ 160 * mid - rw [show low + 2 ^ 160 * mid + 2 ^ 224 * q224 = - low + 2 ^ 160 * mid + q224 * 2 ^ 224 by ring] - rw [Nat.add_mul_mod_self_right] - exact Nat.mod_eq_of_lt hlow224 - have hslot1_div224 : - (low + 2 ^ 160 * mid + q224 * 2 ^ 224) / 2 ^ 224 = q224 := by - rw [show low + 2 ^ 160 * mid + q224 * 2 ^ 224 = - (low + 2 ^ 160 * mid) + q224 * 2 ^ 224 by ring] - rw [Nat.add_mul_div_right _ _ (by norm_num : 0 < 2 ^ 224)] - rw [Nat.div_eq_of_lt hlow224] - simp - have hslot1_div232 : - ((setAddressOffset0Word old token).toNat % 2 ^ 160 + - 2 ^ 160 * (rescale.toNat % 2 ^ 64) + - 2 ^ 224 * ((setAddressOffset0Word old token).toNat / 2 ^ 224)) / - 2 ^ 232 = - old.toNat / 2 ^ 232 := by - rw [haddr_mod160, haddr_div224] - change (low + 2 ^ 160 * mid + 2 ^ 224 * q224) / 2 ^ 232 = - old.toNat / 2 ^ 232 - rw [show low + 2 ^ 160 * mid + 2 ^ 224 * q224 = - low + 2 ^ 160 * mid + q224 * 2 ^ 224 by ring] - rw [show (2 : Nat) ^ 232 = 2 ^ 224 * 2 ^ 8 by rw [← Nat.pow_add]] - rw [← Nat.div_div_eq_div_mul] - rw [hslot1_div224] - change old.toNat / 2 ^ 224 / 2 ^ 8 = old.toNat / 2 ^ 232 - rw [Nat.div_div_eq_div_mul] - rw [show (2 : Nat) ^ 224 * 2 ^ 8 = 2 ^ 232 by rw [← Nat.pow_add]] - rw [hslot1_mod224, hslot1_div232] - -set_option maxHeartbeats 1000000 in -theorem setRewardConfigSlot0Up_toNat (old token rescale : UInt256) : - (setRewardConfigSlot0Up old token rescale).toNat = - token.toNat % 2 ^ 160 + 2 ^ 160 * (rescale.toNat % 2 ^ 64) + - 2 ^ 224 + 2 ^ 232 * (old.toNat / 2 ^ 232) := by - unfold setRewardConfigSlot0Up setRewardConfigSlot0Final - setRewardConfigSlot0AfterRescale setRewardConfigSlot0AfterToken - rw [setRewardConfigBoolOffset28Word_toNat, setRewardConfigUInt64Offset20Word_toNat] - rw [show (⟨1⟩ : UInt256).toNat % 2 ^ 8 = 1 by rfl] - have haddrNat := setRewardConfigAddressOffset0Word_toNat_masked old token - let low : Nat := token.toNat % 2 ^ 160 - let mid : Nat := rescale.toNat % 2 ^ 64 - let q160 : Nat := old.toNat / 2 ^ 160 - let q224 : Nat := old.toNat / 2 ^ 224 - have hlow : low < 2 ^ 160 := by - exact Nat.mod_lt _ (by norm_num) - have hmid : mid < 2 ^ 64 := by - exact Nat.mod_lt _ (by norm_num) - have hlow224 : low + 2 ^ 160 * mid < 2 ^ 224 := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hmidle : mid ≤ 2 ^ 64 - 1 := Nat.le_pred_of_lt hmid - have hmidterm : 2 ^ 160 * mid ≤ 2 ^ 160 * (2 ^ 64 - 1) := - Nat.mul_le_mul_left _ hmidle - have hmax : (2 ^ 160 - 1) + 2 ^ 160 * (2 ^ 64 - 1) < 2 ^ 224 := by - norm_num [Nat.pow_add] - omega - have haddr_mod160 : - (setAddressOffset0Word old token).toNat % 2 ^ 160 = low := by - rw [haddrNat] - change (low + q160 * 2 ^ 160) % 2 ^ 160 = low - rw [Nat.add_mul_mod_self_right, Nat.mod_eq_of_lt hlow] - have haddr_div160 : - (low + q160 * 2 ^ 160) / 2 ^ 160 = q160 := by - rw [Nat.add_mul_div_right _ _ (by norm_num : 0 < 2 ^ 160)] - rw [Nat.div_eq_of_lt hlow] - simp - have haddr_div224 : - (setAddressOffset0Word old token).toNat / 2 ^ 224 = q224 := by - rw [haddrNat] - change (low + q160 * 2 ^ 160) / 2 ^ 224 = q224 - rw [show (2 : Nat) ^ 224 = 2 ^ 160 * 2 ^ 64 by rw [← Nat.pow_add]] - rw [← Nat.div_div_eq_div_mul] - rw [haddr_div160] - change old.toNat / 2 ^ 160 / 2 ^ 64 = old.toNat / 2 ^ 224 - rw [Nat.div_div_eq_div_mul] - rw [show (2 : Nat) ^ 160 * 2 ^ 64 = 2 ^ 224 by rw [← Nat.pow_add]] - have hslot1_mod224 : - ((setAddressOffset0Word old token).toNat % 2 ^ 160 + - 2 ^ 160 * (rescale.toNat % 2 ^ 64) + - 2 ^ 224 * ((setAddressOffset0Word old token).toNat / 2 ^ 224)) % - 2 ^ 224 = - low + 2 ^ 160 * mid := by - rw [haddr_mod160, haddr_div224] - change (low + 2 ^ 160 * mid + 2 ^ 224 * q224) % 2 ^ 224 = - low + 2 ^ 160 * mid - rw [show low + 2 ^ 160 * mid + 2 ^ 224 * q224 = - low + 2 ^ 160 * mid + q224 * 2 ^ 224 by ring] - rw [Nat.add_mul_mod_self_right] - exact Nat.mod_eq_of_lt hlow224 - have hslot1_div224 : - (low + 2 ^ 160 * mid + q224 * 2 ^ 224) / 2 ^ 224 = q224 := by - rw [show low + 2 ^ 160 * mid + q224 * 2 ^ 224 = - (low + 2 ^ 160 * mid) + q224 * 2 ^ 224 by ring] - rw [Nat.add_mul_div_right _ _ (by norm_num : 0 < 2 ^ 224)] - rw [Nat.div_eq_of_lt hlow224] - simp - have hslot1_div232 : - ((setAddressOffset0Word old token).toNat % 2 ^ 160 + - 2 ^ 160 * (rescale.toNat % 2 ^ 64) + - 2 ^ 224 * ((setAddressOffset0Word old token).toNat / 2 ^ 224)) / - 2 ^ 232 = - old.toNat / 2 ^ 232 := by - rw [haddr_mod160, haddr_div224] - change (low + 2 ^ 160 * mid + 2 ^ 224 * q224) / 2 ^ 232 = - old.toNat / 2 ^ 232 - rw [show low + 2 ^ 160 * mid + 2 ^ 224 * q224 = - low + 2 ^ 160 * mid + q224 * 2 ^ 224 by ring] - rw [show (2 : Nat) ^ 232 = 2 ^ 224 * 2 ^ 8 by rw [← Nat.pow_add]] - rw [← Nat.div_div_eq_div_mul] - rw [hslot1_div224] - change old.toNat / 2 ^ 224 / 2 ^ 8 = old.toNat / 2 ^ 232 - rw [Nat.div_div_eq_div_mul] - rw [show (2 : Nat) ^ 224 * 2 ^ 8 = 2 ^ 232 by rw [← Nat.pow_add]] - rw [hslot1_mod224, hslot1_div232] - ring - -set_option maxHeartbeats 1000000 in -private theorem setRewardConfigSlot0Down_bytecodeExpr_toNat - (old token rescale : UInt256) : - (((UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩).land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨0⟩ : UInt256))) ⟨224⟩)).lor - ((((UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).land - (UInt256.shiftLeft rescale ⟨160⟩)).lor - ((UInt256.land solcAddrMask token).lor - (UInt256.land old - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩))))))).toNat = - token.toNat % 2 ^ 160 + 2 ^ 160 * (rescale.toNat % 2 ^ 64) + - 2 ^ 232 * (old.toNat / 2 ^ 232) := by - let low : Nat := token.toNat % 2 ^ 160 - let mid : Nat := rescale.toNat % 2 ^ 64 - let high : Nat := old.toNat / 2 ^ 232 - have hlow : low < 2 ^ 160 := by - exact Nat.mod_lt _ (by norm_num) - have hmid : mid < 2 ^ 64 := by - exact Nat.mod_lt _ (by norm_num) - have hhigh : high < 2 ^ 24 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 232 * 2 ^ 24 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - exact old.val.isLt - have hpackedLt : low + 2 ^ 160 * mid + 2 ^ 232 * high < UInt256.size := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hmidle : mid ≤ 2 ^ 64 - 1 := Nat.le_pred_of_lt hmid - have hhighle : high ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hhigh - have hmidterm : 2 ^ 160 * mid ≤ 2 ^ 160 * (2 ^ 64 - 1) := - Nat.mul_le_mul_left _ hmidle - have hhiterm : 2 ^ 232 * high ≤ 2 ^ 232 * (2 ^ 24 - 1) := - Nat.mul_le_mul_left _ hhighle - have hmax : (2 ^ 160 - 1) + 2 ^ 160 * (2 ^ 64 - 1) + - 2 ^ 232 * (2 ^ 24 - 1) < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - have htokenLow : - (UInt256.land solcAddrMask token).toNat = low := by - rw [u256_land_comm solcAddrMask token, u256_land_toNat] - have hmask : solcAddrMask.toNat = 2 ^ 160 - 1 := by - native_decide - rw [hmask, nat_land_mask_eq_mod] - have hlt : token.toNat % 2 ^ 160 < UInt256.size := by - have h := Nat.mod_lt token.toNat (by norm_num : 0 < 2 ^ 160) - norm_num [UInt256.size] at h ⊢ - omega - rw [Nat.mod_eq_of_lt hlt] - have hOldHigh : - (UInt256.land old - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩))).toNat = high * 2 ^ 232 := by - rw [u256_land_toNat] - have hmask : - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩)).toNat = 2 ^ 256 - 2 ^ 232 := by - native_decide - rw [hmask] - rw [natLandClearLow old.toNat 232 (by norm_num) (by - change old.val.val < 2 ^ 256 - exact old.val.isLt)] - have hlt : old.toNat / 2 ^ 232 * 2 ^ 232 < UInt256.size := - lt_of_le_of_lt (Nat.div_mul_le_self _ _) old.val.isLt - rw [Nat.mod_eq_of_lt hlt] - have hlowHigh : - ((UInt256.land solcAddrMask token).lor - (UInt256.land old - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩)))).toNat = - low + high * 2 ^ 232 := by - rw [u256_lor_toNat, htokenLow, hOldHigh] - rw [nat_lor_shift_add low high 232 - (lt_of_lt_of_le hlow (Nat.pow_le_pow_right (by norm_num) (by norm_num)))] - have hlt : low + high * 2 ^ 232 < UInt256.size := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hhighle : high ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hhigh - have hhiterm : high * 2 ^ 232 ≤ (2 ^ 24 - 1) * 2 ^ 232 := - Nat.mul_le_mul_right _ hhighle - have hmax : (2 ^ 160 - 1) + (2 ^ 24 - 1) * 2 ^ 232 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - rw [Nat.mod_eq_of_lt hlt] - have hmidWord : - ((UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).land - (UInt256.shiftLeft rescale ⟨160⟩)).toNat = - mid * 2 ^ 160 := by - rw [u256_land_comm, u256_land_toNat] - have hmask : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).toNat = - (2 : Nat) ^ 224 - 2 ^ 160 := by - native_decide - have hshift : - (UInt256.shiftLeft rescale ⟨160⟩).toNat = - (rescale.toNat <<< 160) % 2 ^ 256 := by - unfold UInt256.shiftLeft UInt256.toNat - show (Fin.shiftLeft rescale.val (⟨160⟩ : UInt256).val).val = _ - unfold Fin.shiftLeft - rw [show (⟨160⟩ : UInt256).val = 160 by rfl] - change (rescale.toNat <<< 160) % UInt256.size = - (rescale.toNat <<< 160) % 2 ^ 256 - norm_num [UInt256.size] - rw [hshift, hmask, setRewardConfigNatLandShiftLeft160_mid64] - have hlt : mid * 2 ^ 160 < UInt256.size := by - calc - mid * 2 ^ 160 < 2 ^ 64 * 2 ^ 160 := - Nat.mul_lt_mul_of_pos_right hmid (by norm_num) - _ = 2 ^ 224 := by rw [← Nat.pow_add] - _ < UInt256.size := by norm_num [UInt256.size] - rw [Nat.mod_eq_of_lt hlt] - have hpacked : - ((((UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).land - (UInt256.shiftLeft rescale ⟨160⟩)).lor - ((UInt256.land solcAddrMask token).lor - (UInt256.land old - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩)))))).toNat = - low + 2 ^ 160 * mid + 2 ^ 232 * high := by - rw [u256_lor_toNat, hmidWord, hlowHigh] - rw [nat_lor_comm] - have hlor : - Nat.lor (low + high * 2 ^ 232) (mid * 2 ^ 160) = - low + mid * 2 ^ 160 + high * 2 ^ 232 := by - rw [show high * 2 ^ 232 = (high * 2 ^ 8) * 2 ^ 224 by ring] - exact setRewardConfigNatLorPacked160_224 low mid (high * 2 ^ 8) hlow hmid - rw [hlor] - rw [show low + mid * 2 ^ 160 + high * 2 ^ 232 = - low + 2 ^ 160 * mid + 2 ^ 232 * high by ring] - exact Nat.mod_eq_of_lt hpackedLt - have hprefix : - (UInt256.land (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨0⟩ : UInt256))) ⟨224⟩)) = - (⟨0⟩ : UInt256) := by - native_decide - rw [hprefix] - rw [show UInt256.lor (⟨0⟩ : UInt256) - ((((UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).land - (UInt256.shiftLeft rescale ⟨160⟩)).lor - ((UInt256.land solcAddrMask token).lor - (UInt256.land old - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩)))))) = - ((((UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).land - (UInt256.shiftLeft rescale ⟨160⟩)).lor - ((UInt256.land solcAddrMask token).lor - (UInt256.land old - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩)))))) by - rw [u256_lor_comm] - exact u256_lor_zero _] - rw [hpacked] - -private theorem setRewardConfigSlot0Down_bytecodeExpr - (old token rescale : UInt256) : - ((UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩).land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨0⟩ : UInt256))) ⟨224⟩)).lor - ((((UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).land - (UInt256.shiftLeft rescale ⟨160⟩)).lor - ((UInt256.land solcAddrMask token).lor - (UInt256.land old - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩)))))) = - setRewardConfigSlot0Down old token rescale := by - apply u256_inj - rw [setRewardConfigSlot0Down_bytecodeExpr_toNat, setRewardConfigSlot0Down_toNat] - -set_option maxHeartbeats 1000000 in -private theorem setRewardConfigSlot0Up_bytecodeExpr_toNat - (old token rescale : UInt256) : - (((UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩).land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨1⟩ : UInt256))) ⟨224⟩)).lor - ((((UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).land - (UInt256.shiftLeft rescale ⟨160⟩)).lor - ((UInt256.land solcAddrMask token).lor - (UInt256.land old - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩))))))).toNat = - token.toNat % 2 ^ 160 + 2 ^ 160 * (rescale.toNat % 2 ^ 64) + - 2 ^ 224 + 2 ^ 232 * (old.toNat / 2 ^ 232) := by - let low : Nat := token.toNat % 2 ^ 160 - let mid : Nat := rescale.toNat % 2 ^ 64 - let high : Nat := old.toNat / 2 ^ 232 - have hlow : low < 2 ^ 160 := by - exact Nat.mod_lt _ (by norm_num) - have hmid : mid < 2 ^ 64 := by - exact Nat.mod_lt _ (by norm_num) - have hhigh : high < 2 ^ 24 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 232 * 2 ^ 24 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - exact old.val.isLt - have hlow224 : low + 2 ^ 160 * mid < 2 ^ 224 := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hmidle : mid ≤ 2 ^ 64 - 1 := Nat.le_pred_of_lt hmid - have hmidterm : 2 ^ 160 * mid ≤ 2 ^ 160 * (2 ^ 64 - 1) := - Nat.mul_le_mul_left _ hmidle - have hmax : (2 ^ 160 - 1) + 2 ^ 160 * (2 ^ 64 - 1) < 2 ^ 224 := by - norm_num [Nat.pow_add] - omega - have hpackedLt : - low + 2 ^ 160 * mid + 2 ^ 232 * high < UInt256.size := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hmidle : mid ≤ 2 ^ 64 - 1 := Nat.le_pred_of_lt hmid - have hhighle : high ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hhigh - have hmidterm : 2 ^ 160 * mid ≤ 2 ^ 160 * (2 ^ 64 - 1) := - Nat.mul_le_mul_left _ hmidle - have hhiterm : 2 ^ 232 * high ≤ 2 ^ 232 * (2 ^ 24 - 1) := - Nat.mul_le_mul_left _ hhighle - have hmax : (2 ^ 160 - 1) + 2 ^ 160 * (2 ^ 64 - 1) + - 2 ^ 232 * (2 ^ 24 - 1) < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - have hfinalLt : - low + 2 ^ 160 * mid + 2 ^ 224 + 2 ^ 232 * high < UInt256.size := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hmidle : mid ≤ 2 ^ 64 - 1 := Nat.le_pred_of_lt hmid - have hhighle : high ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hhigh - have hmidterm : 2 ^ 160 * mid ≤ 2 ^ 160 * (2 ^ 64 - 1) := - Nat.mul_le_mul_left _ hmidle - have hhiterm : 2 ^ 232 * high ≤ 2 ^ 232 * (2 ^ 24 - 1) := - Nat.mul_le_mul_left _ hhighle - have hmax : (2 ^ 160 - 1) + 2 ^ 160 * (2 ^ 64 - 1) + 2 ^ 224 + - 2 ^ 232 * (2 ^ 24 - 1) < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - have htokenLow : - (UInt256.land solcAddrMask token).toNat = low := by - rw [u256_land_comm solcAddrMask token, u256_land_toNat] - have hmask : solcAddrMask.toNat = 2 ^ 160 - 1 := by - native_decide - rw [hmask, nat_land_mask_eq_mod] - have hlt : token.toNat % 2 ^ 160 < UInt256.size := by - have h := Nat.mod_lt token.toNat (by norm_num : 0 < 2 ^ 160) - norm_num [UInt256.size] at h ⊢ - omega - rw [Nat.mod_eq_of_lt hlt] - have hOldHigh : - (UInt256.land old - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩))).toNat = high * 2 ^ 232 := by - rw [u256_land_toNat] - have hmask : - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩)).toNat = 2 ^ 256 - 2 ^ 232 := by - native_decide - rw [hmask] - rw [natLandClearLow old.toNat 232 (by norm_num) (by - change old.val.val < 2 ^ 256 - exact old.val.isLt)] - have hlt : old.toNat / 2 ^ 232 * 2 ^ 232 < UInt256.size := - lt_of_le_of_lt (Nat.div_mul_le_self _ _) old.val.isLt - rw [Nat.mod_eq_of_lt hlt] - have hlowHigh : - ((UInt256.land solcAddrMask token).lor - (UInt256.land old - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩)))).toNat = - low + high * 2 ^ 232 := by - rw [u256_lor_toNat, htokenLow, hOldHigh] - rw [nat_lor_shift_add low high 232 - (lt_of_lt_of_le hlow (Nat.pow_le_pow_right (by norm_num) (by norm_num)))] - have hlt : low + high * 2 ^ 232 < UInt256.size := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hhighle : high ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hhigh - have hhiterm : high * 2 ^ 232 ≤ (2 ^ 24 - 1) * 2 ^ 232 := - Nat.mul_le_mul_right _ hhighle - have hmax : (2 ^ 160 - 1) + (2 ^ 24 - 1) * 2 ^ 232 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - rw [Nat.mod_eq_of_lt hlt] - have hmidWord : - ((UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).land - (UInt256.shiftLeft rescale ⟨160⟩)).toNat = - mid * 2 ^ 160 := by - rw [u256_land_comm, u256_land_toNat] - have hmask : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).toNat = - (2 : Nat) ^ 224 - 2 ^ 160 := by - native_decide - have hshift : - (UInt256.shiftLeft rescale ⟨160⟩).toNat = - (rescale.toNat <<< 160) % 2 ^ 256 := by - unfold UInt256.shiftLeft UInt256.toNat - show (Fin.shiftLeft rescale.val (⟨160⟩ : UInt256).val).val = _ - unfold Fin.shiftLeft - rw [show (⟨160⟩ : UInt256).val = 160 by rfl] - change (rescale.toNat <<< 160) % UInt256.size = - (rescale.toNat <<< 160) % 2 ^ 256 - norm_num [UInt256.size] - rw [hshift, hmask, setRewardConfigNatLandShiftLeft160_mid64] - have hlt : mid * 2 ^ 160 < UInt256.size := by - calc - mid * 2 ^ 160 < 2 ^ 64 * 2 ^ 160 := - Nat.mul_lt_mul_of_pos_right hmid (by norm_num) - _ = 2 ^ 224 := by rw [← Nat.pow_add] - _ < UInt256.size := by norm_num [UInt256.size] - rw [Nat.mod_eq_of_lt hlt] - have hpacked : - ((((UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).land - (UInt256.shiftLeft rescale ⟨160⟩)).lor - ((UInt256.land solcAddrMask token).lor - (UInt256.land old - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩)))))).toNat = - low + 2 ^ 160 * mid + 2 ^ 232 * high := by - rw [u256_lor_toNat, hmidWord, hlowHigh] - rw [nat_lor_comm] - have hlor : - Nat.lor (low + high * 2 ^ 232) (mid * 2 ^ 160) = - low + mid * 2 ^ 160 + high * 2 ^ 232 := by - rw [show high * 2 ^ 232 = (high * 2 ^ 8) * 2 ^ 224 by ring] - exact setRewardConfigNatLorPacked160_224 low mid (high * 2 ^ 8) hlow hmid - rw [hlor] - rw [show low + mid * 2 ^ 160 + high * 2 ^ 232 = - low + 2 ^ 160 * mid + 2 ^ 232 * high by ring] - exact Nat.mod_eq_of_lt hpackedLt - have hprefix : - (UInt256.land (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨1⟩ : UInt256))) ⟨224⟩)) = - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩ := by - native_decide - rw [hprefix] - rw [u256_lor_toNat, hpacked] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩).toNat = 2 ^ 224 by - native_decide] - rw [nat_lor_comm] - have hlor : - Nat.lor (low + 2 ^ 160 * mid + 2 ^ 232 * high) (2 ^ 224) = - low + 2 ^ 160 * mid + 2 ^ 224 + 2 ^ 232 * high := by - rw [show low + 2 ^ 160 * mid + 2 ^ 232 * high = - (low + 2 ^ 160 * mid) + high * 2 ^ 232 by ring] - rw [show (2 : Nat) ^ 224 = 1 * 2 ^ 224 by ring] - rw [setRewardConfigNatLorPacked224_232 (low + 2 ^ 160 * mid) 1 high - hlow224 (by norm_num)] - ring - rw [hlor, Nat.mod_eq_of_lt hfinalLt] - -private theorem setRewardConfigSlot0Up_bytecodeExpr - (old token rescale : UInt256) : - ((UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩).land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨1⟩ : UInt256))) ⟨224⟩)).lor - ((((UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).land - (UInt256.shiftLeft rescale ⟨160⟩)).lor - ((UInt256.land solcAddrMask token).lor - (UInt256.land old - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩)))))) = - setRewardConfigSlot0Up old token rescale := by - apply u256_inj - rw [setRewardConfigSlot0Up_bytecodeExpr_toNat, setRewardConfigSlot0Up_toNat] - -set_option maxHeartbeats 1000000 in -private theorem setRewardConfigSlot0Up_bytecodeExpr_runtime_toNat - (old token rescale : UInt256) : - (UInt256.lor - (UInt256.lor - (UInt256.lor - (UInt256.land (UInt256.shiftLeft (⟨0xffffff⟩ : UInt256) ⟨232⟩) old) - (UInt256.land token solcAddrMask)) - (UInt256.land (UInt256.shiftLeft rescale ⟨160⟩) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)))) - (UInt256.land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨1⟩ : UInt256))) ⟨224⟩) - (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩))).toNat = - token.toNat % 2 ^ 160 + 2 ^ 160 * (rescale.toNat % 2 ^ 64) + - 2 ^ 224 + 2 ^ 232 * (old.toNat / 2 ^ 232) := by - let low : Nat := token.toNat % 2 ^ 160 - let mid : Nat := rescale.toNat % 2 ^ 64 - let high : Nat := old.toNat / 2 ^ 232 - have hlow : low < 2 ^ 160 := by - exact Nat.mod_lt _ (by norm_num) - have hmid : mid < 2 ^ 64 := by - exact Nat.mod_lt _ (by norm_num) - have hhigh : high < 2 ^ 24 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 232 * 2 ^ 24 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - exact old.val.isLt - have hlow224 : low + 2 ^ 160 * mid < 2 ^ 224 := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hmidle : mid ≤ 2 ^ 64 - 1 := Nat.le_pred_of_lt hmid - have hmidterm : 2 ^ 160 * mid ≤ 2 ^ 160 * (2 ^ 64 - 1) := - Nat.mul_le_mul_left _ hmidle - have hmax : (2 ^ 160 - 1) + 2 ^ 160 * (2 ^ 64 - 1) < 2 ^ 224 := by - norm_num [Nat.pow_add] - omega - have hpackedLt : - low + 2 ^ 160 * mid + 2 ^ 232 * high < UInt256.size := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hmidle : mid ≤ 2 ^ 64 - 1 := Nat.le_pred_of_lt hmid - have hhighle : high ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hhigh - have hmidterm : 2 ^ 160 * mid ≤ 2 ^ 160 * (2 ^ 64 - 1) := - Nat.mul_le_mul_left _ hmidle - have hhiterm : 2 ^ 232 * high ≤ 2 ^ 232 * (2 ^ 24 - 1) := - Nat.mul_le_mul_left _ hhighle - have hmax : (2 ^ 160 - 1) + 2 ^ 160 * (2 ^ 64 - 1) + - 2 ^ 232 * (2 ^ 24 - 1) < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - have hfinalLt : - low + 2 ^ 160 * mid + 2 ^ 224 + 2 ^ 232 * high < UInt256.size := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hmidle : mid ≤ 2 ^ 64 - 1 := Nat.le_pred_of_lt hmid - have hhighle : high ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hhigh - have hmidterm : 2 ^ 160 * mid ≤ 2 ^ 160 * (2 ^ 64 - 1) := - Nat.mul_le_mul_left _ hmidle - have hhiterm : 2 ^ 232 * high ≤ 2 ^ 232 * (2 ^ 24 - 1) := - Nat.mul_le_mul_left _ hhighle - have hmax : (2 ^ 160 - 1) + 2 ^ 160 * (2 ^ 64 - 1) + 2 ^ 224 + - 2 ^ 232 * (2 ^ 24 - 1) < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - have htokenLow : - (token.land solcAddrMask).toNat = low := by - rw [u256_land_toNat] - have hmask : solcAddrMask.toNat = 2 ^ 160 - 1 := by - native_decide - rw [hmask, nat_land_mask_eq_mod] - have hlt : token.toNat % 2 ^ 160 < UInt256.size := by - have h := Nat.mod_lt token.toNat (by norm_num : 0 < 2 ^ 160) - norm_num [UInt256.size] at h ⊢ - omega - rw [Nat.mod_eq_of_lt hlt] - have hOldHigh : - (((⟨0xffffff⟩ : UInt256).shiftLeft ⟨232⟩).land old).toNat = - high * 2 ^ 232 := by - rw [u256_land_toNat] - have hmask : (((⟨0xffffff⟩ : UInt256).shiftLeft ⟨232⟩).toNat) = - 2 ^ 256 - 2 ^ 232 := by - native_decide - rw [hmask] - rw [nat_land_comm] - rw [natLandClearLow old.toNat 232 (by norm_num) (by - change old.val.val < 2 ^ 256 - exact old.val.isLt)] - have hlt : old.toNat / 2 ^ 232 * 2 ^ 232 < UInt256.size := - lt_of_le_of_lt (Nat.div_mul_le_self _ _) old.val.isLt - rw [Nat.mod_eq_of_lt hlt] - have hlowHigh : - ((((⟨0xffffff⟩ : UInt256).shiftLeft ⟨232⟩).land old).lor - (token.land solcAddrMask)).toNat = - low + high * 2 ^ 232 := by - rw [u256_lor_toNat, hOldHigh, htokenLow] - rw [nat_lor_comm] - rw [nat_lor_shift_add low high 232 - (lt_of_lt_of_le hlow (Nat.pow_le_pow_right (by norm_num) (by norm_num)))] - have hlt : low + high * 2 ^ 232 < UInt256.size := by - have hlowle : low ≤ 2 ^ 160 - 1 := Nat.le_pred_of_lt hlow - have hhighle : high ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hhigh - have hhiterm : high * 2 ^ 232 ≤ (2 ^ 24 - 1) * 2 ^ 232 := - Nat.mul_le_mul_right _ hhighle - have hmax : (2 ^ 160 - 1) + (2 ^ 24 - 1) * 2 ^ 232 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - rw [Nat.mod_eq_of_lt hlt] - have hmidWord : - ((rescale.shiftLeft ⟨160⟩).land - (((⟨1⟩ : UInt256).shiftLeft ⟨224⟩).sub - ((⟨1⟩ : UInt256).shiftLeft ⟨160⟩))).toNat = - mid * 2 ^ 160 := by - rw [u256_land_toNat] - have hmask : - ((((⟨1⟩ : UInt256).shiftLeft ⟨224⟩).sub - ((⟨1⟩ : UInt256).shiftLeft ⟨160⟩)).toNat) = - (2 : Nat) ^ 224 - 2 ^ 160 := by - native_decide - have hshift : - (rescale.shiftLeft ⟨160⟩).toNat = - (rescale.toNat <<< 160) % 2 ^ 256 := by - unfold UInt256.shiftLeft UInt256.toNat - show (Fin.shiftLeft rescale.val (⟨160⟩ : UInt256).val).val = _ - unfold Fin.shiftLeft - rw [show (⟨160⟩ : UInt256).val = 160 by rfl] - change (rescale.toNat <<< 160) % UInt256.size = - (rescale.toNat <<< 160) % 2 ^ 256 - norm_num [UInt256.size] - rw [hshift, hmask, setRewardConfigNatLandShiftLeft160_mid64] - have hlt : mid * 2 ^ 160 < UInt256.size := by - calc - mid * 2 ^ 160 < 2 ^ 64 * 2 ^ 160 := - Nat.mul_lt_mul_of_pos_right hmid (by norm_num) - _ = 2 ^ 224 := by rw [← Nat.pow_add] - _ < UInt256.size := by norm_num [UInt256.size] - rw [Nat.mod_eq_of_lt hlt] - have hpacked : - (((((⟨0xffffff⟩ : UInt256).shiftLeft ⟨232⟩).land old).lor - (token.land solcAddrMask)).lor - ((rescale.shiftLeft ⟨160⟩).land - (((⟨1⟩ : UInt256).shiftLeft ⟨224⟩).sub - ((⟨1⟩ : UInt256).shiftLeft ⟨160⟩)))).toNat = - low + 2 ^ 160 * mid + 2 ^ 232 * high := by - rw [u256_lor_toNat, hlowHigh, hmidWord] - have hlor : - Nat.lor (low + high * 2 ^ 232) (mid * 2 ^ 160) = - low + mid * 2 ^ 160 + high * 2 ^ 232 := by - rw [show high * 2 ^ 232 = (high * 2 ^ 8) * 2 ^ 224 by ring] - exact setRewardConfigNatLorPacked160_224 low mid (high * 2 ^ 8) hlow hmid - rw [hlor] - rw [show low + mid * 2 ^ 160 + high * 2 ^ 232 = - low + 2 ^ 160 * mid + 2 ^ 232 * high by ring] - exact Nat.mod_eq_of_lt hpackedLt - have hprefix : - ((((⟨1⟩ : UInt256).isZero.isZero).shiftLeft ⟨224⟩).land - ((⟨255⟩ : UInt256).shiftLeft ⟨224⟩)).toNat = 2 ^ 224 := by - native_decide - rw [u256_lor_toNat, hpacked, hprefix] - have hlor : - Nat.lor (low + 2 ^ 160 * mid + 2 ^ 232 * high) (2 ^ 224) = - low + 2 ^ 160 * mid + 2 ^ 224 + 2 ^ 232 * high := by - rw [show low + 2 ^ 160 * mid + 2 ^ 232 * high = - (low + 2 ^ 160 * mid) + high * 2 ^ 232 by ring] - rw [show (2 : Nat) ^ 224 = 1 * 2 ^ 224 by ring] - rw [setRewardConfigNatLorPacked224_232 (low + 2 ^ 160 * mid) 1 high - hlow224 (by norm_num)] - ring - rw [hlor, Nat.mod_eq_of_lt hfinalLt] - -private theorem setRewardConfigSlot0Up_bytecodeExpr_runtime - (old token rescale : UInt256) : - UInt256.lor - (UInt256.lor - (UInt256.lor - (UInt256.land (UInt256.shiftLeft (⟨0xffffff⟩ : UInt256) ⟨232⟩) old) - (UInt256.land token solcAddrMask)) - (UInt256.land (UInt256.shiftLeft rescale ⟨160⟩) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)))) - (UInt256.land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨1⟩ : UInt256))) ⟨224⟩) - (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩)) = - setRewardConfigSlot0Up old token rescale := by - apply u256_inj - rw [setRewardConfigSlot0Up_bytecodeExpr_runtime_toNat, setRewardConfigSlot0Up_toNat] - -set_option maxHeartbeats 1000000 in -theorem setRewardConfigStorageLocStore_uint64_offset20 (evm : EVM.State) - (slot val : UInt256) : - storageLocStore evm (fieldLoc slot 20 8 (by decide) (.int uint64Int)) - (.int (Int.ofNat val.toNat)) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner slot - (setRewardConfigUInt64Offset20Word - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) val)) := by - unfold storageLocStore storageLocWriteWord fieldLoc loc - simp only [valueToWord, wordOfInt_ofNat_toNat, bind, Option.bind, pure] - congr 2 - apply u256_inj - change fromBytes' - ((EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).1.take 20 ++ - (EVM.Word.toBytesLEWithSizeProof val).1.take 8 ++ - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).1.drop 28) = - (setRewardConfigUInt64Offset20Word - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) val).toNat - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE_land_mask - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) 20 (by decide)] - rw [fromBytes'_take_wordLE_land_mask val 8 (by decide)] - rw [fromBytes'_drop_wordLE - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) 28] - have hlen20 : - ((EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).1.take 20).length = 20 := by - rw [List.length_take, - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).2] - norm_num - have hlen8 : ((EVM.Word.toBytesLEWithSizeProof val).1.take 8).length = 8 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof val).2] - norm_num - rw [List.length_append, hlen20, hlen8] - norm_num [Nat.pow_add] - rw [setRewardConfigUInt64Offset20Word_toNat] - rw [u256_land_toNat] - rw [show (UInt256.ofNat 1461501637330902918203684832716283019655932542975 : - UInt256).toNat = 2 ^ 160 - 1 by native_decide, nat_land_mask_eq_mod] - have hlowLt : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot).toNat % 2 ^ 160 < - UInt256.size := by - have h := Nat.mod_lt (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot).toNat - (by norm_num : 0 < 2 ^ 160) - norm_num [UInt256.size] at h ⊢ - omega - rw [Nat.mod_eq_of_lt hlowLt] - rw [u256_land_toNat] - rw [show (UInt256.ofNat 18446744073709551615 : UInt256).toNat = 2 ^ 64 - 1 by - native_decide, nat_land_mask_eq_mod] - have hvalLt : val.toNat % 2 ^ 64 < UInt256.size := by - have h := Nat.mod_lt val.toNat (by norm_num : 0 < 2 ^ 64) - norm_num [UInt256.size] at h ⊢ - omega - rw [Nat.mod_eq_of_lt hvalLt] - ring - -set_option maxHeartbeats 1000000 in -theorem setRewardConfigStorageLocStore_bool_false_offset28 (evm : EVM.State) - (slot : UInt256) : - storageLocStore evm (fieldLoc slot 28 1 (by decide) .bool) (.bool false) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner slot - (setRewardConfigBoolOffset28Word - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) ⟨0⟩)) := by - unfold storageLocStore storageLocWriteWord fieldLoc loc - simp only [valueToWord, Bool.toUInt256_false, bind, Option.bind, pure] - congr 2 - apply u256_inj - change fromBytes' - ((EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).1.take 28 ++ - (EVM.Word.toBytesLEWithSizeProof (⟨0⟩ : UInt256)).1.take 1 ++ - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).1.drop 29) = - (setRewardConfigBoolOffset28Word - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) ⟨0⟩).toNat - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) 28] - rw [fromBytes'_take_wordLE (⟨0⟩ : UInt256) 1] - rw [fromBytes'_drop_wordLE - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) 29] - have hlen28 : - ((EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).1.take 28).length = 28 := by - rw [List.length_take, - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).2] - norm_num - have hlen1 : ((EVM.Word.toBytesLEWithSizeProof (⟨0⟩ : UInt256)).1.take 1).length = 1 := by - native_decide - rw [List.length_append, hlen28, hlen1] - norm_num [Nat.pow_add] - rw [setRewardConfigBoolOffset28Word_toNat] - norm_num - -set_option maxHeartbeats 1000000 in -theorem setRewardConfigStorageLocStore_bool_true_offset28 (evm : EVM.State) - (slot : UInt256) : - storageLocStore evm (fieldLoc slot 28 1 (by decide) .bool) (.bool true) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner slot - (setRewardConfigBoolOffset28Word - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) ⟨1⟩)) := by - unfold storageLocStore storageLocWriteWord fieldLoc loc - simp only [valueToWord, Bool.toUInt256_true, bind, Option.bind, pure] - congr 2 - apply u256_inj - change fromBytes' - ((EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).1.take 28 ++ - (EVM.Word.toBytesLEWithSizeProof (⟨1⟩ : UInt256)).1.take 1 ++ - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).1.drop 29) = - (setRewardConfigBoolOffset28Word - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) ⟨1⟩).toNat - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) 28] - rw [fromBytes'_take_wordLE (⟨1⟩ : UInt256) 1] - rw [fromBytes'_drop_wordLE - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) 29] - have hlen28 : - ((EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).1.take 28).length = 28 := by - rw [List.length_take, - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).2] - norm_num - have hlen1 : ((EVM.Word.toBytesLEWithSizeProof (⟨1⟩ : UInt256)).1.take 1).length = 1 := by - native_decide - rw [List.length_append, hlen28, hlen1] - norm_num [Nat.pow_add] - rw [setRewardConfigBoolOffset28Word_toNat] - norm_num - -def setRewardConfigSourceAfterToken (evm : EVM.State) (I : ExecutionEnv) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I) - (setRewardConfigSlot0AfterToken - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - (setRewardConfigWithMultiplierTokenWord I)) - -def setRewardConfigSourceAfterRescale (evm : EVM.State) (I : ExecutionEnv) - (rescale : UInt256) : EVM.State := - Solm.EVM.storageStore (setRewardConfigSourceAfterToken evm I) - (setRewardConfigSourceAfterToken evm I).executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I) - (setRewardConfigUInt64Offset20Word - (Solm.EVM.storageLoad (setRewardConfigSourceAfterToken evm I) - (setRewardConfigSourceAfterToken evm I).executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - rescale) - -def setRewardConfigSourceAfterShouldUpscale (evm : EVM.State) (I : ExecutionEnv) - (rescale : UInt256) (shouldUpscale : Bool) : EVM.State := - let evmRescale := setRewardConfigSourceAfterRescale evm I rescale - Solm.EVM.storageStore evmRescale evmRescale.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I) - (setRewardConfigBoolOffset28Word - (Solm.EVM.storageLoad evmRescale evmRescale.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - (if shouldUpscale then ⟨1⟩ else ⟨0⟩)) - -def setRewardConfigSourceFinal (evm : EVM.State) (I : ExecutionEnv) - (rescale : UInt256) (shouldUpscale : Bool) : EVM.State := - let evmBool := setRewardConfigSourceAfterShouldUpscale evm I rescale shouldUpscale - Solm.EVM.storageStore evmBool evmBool.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I + ⟨1⟩) - (setRewardConfigWithMultiplierMultiplierWord I) - -theorem setRewardConfigSourceFinal_false (evm : EVM.State) (I : ExecutionEnv) - (rescale : UInt256) : - setRewardConfigSourceFinal evm I rescale false = - Solm.EVM.storageStore (setRewardConfigSourceAfterShouldUpscale evm I rescale false) - (setRewardConfigSourceAfterShouldUpscale evm I rescale false).executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I + ⟨1⟩) - (setRewardConfigWithMultiplierMultiplierWord I) := by - rfl - -theorem setRewardConfigSourceFinal_true (evm : EVM.State) (I : ExecutionEnv) - (rescale : UInt256) : - setRewardConfigSourceFinal evm I rescale true = - Solm.EVM.storageStore (setRewardConfigSourceAfterShouldUpscale evm I rescale true) - (setRewardConfigSourceAfterShouldUpscale evm I rescale true).executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I + ⟨1⟩) - (setRewardConfigWithMultiplierMultiplierWord I) := by - rfl - -set_option maxHeartbeats 5000000 in -theorem setRewardConfigSourceFinal_accountMap_equiv - (evm : EVM.State) (I : ExecutionEnv) (rescale : UInt256) (shouldUpscale : Bool) : - accountMapEquiv - (sstoreAccountMap evm.executionEnv.codeOwner - (sstoreAccountMap evm.executionEnv.codeOwner evm.accountMap - (setRewardConfigWithMultiplierSlotOf I) - (setRewardConfigSlot0Final - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - (setRewardConfigWithMultiplierTokenWord I) rescale - (if shouldUpscale then ⟨1⟩ else ⟨0⟩))) - (setRewardConfigWithMultiplierSlotOf I + ⟨1⟩) - (setRewardConfigWithMultiplierMultiplierWord I)) - (setRewardConfigSourceFinal evm I rescale shouldUpscale).accountMap := by - let owner := evm.executionEnv.codeOwner - let slot := setRewardConfigWithMultiplierSlotOf I - let bit : UInt256 := if shouldUpscale then ⟨1⟩ else ⟨0⟩ - let old := Solm.EVM.storageLoad evm owner slot - let tokenWord := setRewardConfigSlot0AfterToken old (setRewardConfigWithMultiplierTokenWord I) - let rescaleWord := setRewardConfigSlot0AfterRescale old - (setRewardConfigWithMultiplierTokenWord I) rescale - let finalWord := setRewardConfigSlot0Final old - (setRewardConfigWithMultiplierTokenWord I) rescale bit - cases hacc : evm.accountMap.find? owner with - | none => - have htoken : setRewardConfigSourceAfterToken evm I = evm := by - unfold setRewardConfigSourceAfterToken - simpa [owner, slot] using - storageStore_absent evm owner hacc slot - (setRewardConfigSlot0AfterToken old (setRewardConfigWithMultiplierTokenWord I)) - have hrescale : setRewardConfigSourceAfterRescale evm I rescale = evm := by - unfold setRewardConfigSourceAfterRescale - rw [htoken] - simpa [owner, slot] using - storageStore_absent evm owner hacc slot - (setRewardConfigUInt64Offset20Word old rescale) - have hbool : setRewardConfigSourceAfterShouldUpscale evm I rescale shouldUpscale = evm := by - unfold setRewardConfigSourceAfterShouldUpscale - rw [hrescale] - simpa [owner, slot, bit] using - storageStore_absent evm owner hacc slot - (setRewardConfigBoolOffset28Word old bit) - have hsource : setRewardConfigSourceFinal evm I rescale shouldUpscale = evm := by - unfold setRewardConfigSourceFinal - rw [hbool] - simpa [owner, slot] using - storageStore_absent evm owner hacc (slot + ⟨1⟩) - (setRewardConfigWithMultiplierMultiplierWord I) - have hleft : - sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot finalWord) - (slot + ⟨1⟩) (setRewardConfigWithMultiplierMultiplierWord I) = - evm.accountMap := by - unfold sstoreAccountMap - rw [hacc] - simp [Option.option] - rw [hacc] - rw [hsource] - simpa [owner, slot, bit, old, finalWord, hleft] using - accountMapEquiv_refl evm.accountMap - | some acc => - have hcollapse0 : - accountMapEquiv - (sstoreAccountMap owner evm.accountMap slot finalWord) - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot finalWord) := - accountMapEquiv_sstoreAccountMap_self_update evm.accountMap owner slot tokenWord finalWord - have hcollapse1 : - accountMapEquiv - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot finalWord) - (sstoreAccountMap owner - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot rescaleWord) - slot finalWord) := - accountMapEquiv_sstoreAccountMap_self_update - (sstoreAccountMap owner evm.accountMap slot tokenWord) owner slot rescaleWord finalWord - have hcollapseSlot : - accountMapEquiv - (sstoreAccountMap owner evm.accountMap slot finalWord) - (sstoreAccountMap owner - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot rescaleWord) - slot finalWord) := - accountMapEquiv.trans hcollapse0 hcollapse1 - have hcollapse := - accountMapEquiv_sstoreAccountMap - (σ := sstoreAccountMap owner evm.accountMap slot finalWord) - (τ := sstoreAccountMap owner - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot rescaleWord) - slot finalWord) - owner (slot + ⟨1⟩) (setRewardConfigWithMultiplierMultiplierWord I) hcollapseSlot - have hsource : - (setRewardConfigSourceFinal evm I rescale shouldUpscale).accountMap = - sstoreAccountMap owner - (sstoreAccountMap owner - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot rescaleWord) - slot finalWord) - (slot + ⟨1⟩) (setRewardConfigWithMultiplierMultiplierWord I) := by - have htokenMap : - (setRewardConfigSourceAfterToken evm I).accountMap = - sstoreAccountMap owner evm.accountMap slot tokenWord := by - unfold setRewardConfigSourceAfterToken - simpa [owner, slot, old, tokenWord] using - storageStore_accountMap evm owner slot tokenWord - have htokenEnv : - (setRewardConfigSourceAfterToken evm I).executionEnv = evm.executionEnv := by - unfold setRewardConfigSourceAfterToken - simpa [owner, slot, old, tokenWord] using - storageStore_executionEnv evm owner slot tokenWord - have hloadToken : - Solm.EVM.storageLoad (setRewardConfigSourceAfterToken evm I) - (setRewardConfigSourceAfterToken evm I).executionEnv.codeOwner slot = tokenWord := by - unfold setRewardConfigSourceAfterToken - rw [storageStore_executionEnv] - simpa [owner, slot, old, tokenWord] using - storageLoad_storageStore_same_present evm owner hacc slot tokenWord - have hloadTokenOwner : - Solm.EVM.storageLoad (setRewardConfigSourceAfterToken evm I) - evm.executionEnv.codeOwner slot = tokenWord := by - simpa [htokenEnv] using hloadToken - have hrescaleMap : - (setRewardConfigSourceAfterRescale evm I rescale).accountMap = - sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot rescaleWord := by - unfold setRewardConfigSourceAfterRescale - simp [setRewardConfigSourceAfterToken, owner, slot, old, tokenWord, - rescaleWord, setRewardConfigSlot0AfterRescale, storageStore_accountMap, - storageStore_executionEnv, - storageLoad_storageStore_same_present evm owner hacc slot tokenWord] - have hrescaleEnv : - (setRewardConfigSourceAfterRescale evm I rescale).executionEnv = evm.executionEnv := by - unfold setRewardConfigSourceAfterRescale - rw [storageStore_executionEnv] - exact htokenEnv - have haccToken : - ∃ acc', - (setRewardConfigSourceAfterToken evm I).accountMap.find? owner = some acc' := by - rw [htokenMap] - unfold sstoreAccountMap - rw [hacc] - simp [Option.option] - exact ⟨_, accountMap_find_insert_self _ _ _⟩ - rcases haccToken with ⟨accToken, haccToken⟩ - have haccTokenOwner : - (setRewardConfigSourceAfterToken evm I).accountMap.find? - (setRewardConfigSourceAfterToken evm I).executionEnv.codeOwner = some accToken := by - simpa [htokenEnv] using haccToken - have hloadRescale : - Solm.EVM.storageLoad (setRewardConfigSourceAfterRescale evm I rescale) - (setRewardConfigSourceAfterRescale evm I rescale).executionEnv.codeOwner slot = - rescaleWord := by - unfold setRewardConfigSourceAfterRescale - rw [storageStore_executionEnv] - simpa [slot, rescaleWord, setRewardConfigSlot0AfterRescale, hloadToken] using - storageLoad_storageStore_same_present - (setRewardConfigSourceAfterToken evm I) - (setRewardConfigSourceAfterToken evm I).executionEnv.codeOwner - haccTokenOwner slot rescaleWord - have hloadRescaleOwner : - Solm.EVM.storageLoad (setRewardConfigSourceAfterRescale evm I rescale) - evm.executionEnv.codeOwner slot = rescaleWord := by - simpa [hrescaleEnv] using hloadRescale - have hboolMap : - (setRewardConfigSourceAfterShouldUpscale evm I rescale shouldUpscale).accountMap = - sstoreAccountMap owner - (sstoreAccountMap owner - (sstoreAccountMap owner evm.accountMap slot tokenWord) slot rescaleWord) - slot finalWord := by - unfold setRewardConfigSourceAfterShouldUpscale - simp [hrescaleMap, hrescaleEnv, hloadRescaleOwner, owner, slot, bit, finalWord, - rescaleWord, setRewardConfigSlot0Final, setRewardConfigSlot0AfterRescale, - storageStore_accountMap] - have hboolEnv : - (setRewardConfigSourceAfterShouldUpscale evm I rescale shouldUpscale).executionEnv = - evm.executionEnv := by - unfold setRewardConfigSourceAfterShouldUpscale - simp [hrescaleEnv, owner, slot, bit, finalWord, setRewardConfigSlot0Final, - storageStore_executionEnv] - unfold setRewardConfigSourceFinal - simp [hboolMap, hboolEnv, owner, slot, storageStore_accountMap] - rw [hsource] - simpa [owner, slot, bit, old, finalWord] using hcollapse - -def setRewardConfigAfterDecimalsFrame (I : ExecutionEnv) (baseWord : UInt256) - (decNat : ℕ) : Frame := - { contract := contract, - locals := - ((setRewardConfigWithMultiplierBodyStore I).insert "accrualScale" - (.int (Int.ofNat baseWord.toNat))).insert "tokenDecimals" (.int (Int.ofNat decNat)) } - -def setRewardConfigAfterPow10Frame (I : ExecutionEnv) (baseWord : UInt256) - (decNat : ℕ) : Frame := - resumeAfterInternalCall (setRewardConfigAfterDecimalsFrame I baseWord decNat) - "tokenScale256" (some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - -def setRewardConfigAfterSafe64Frame (I : ExecutionEnv) (baseWord : UInt256) - (decNat : ℕ) : Frame := - resumeAfterInternalCall (setRewardConfigAfterPow10Frame I baseWord decNat) - "tokenScale" (some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - -theorem evalStorageRef_setRewardConfigWithMultiplier_rewardConfig_field_of_comet - (evm : EVM.State) (I : ExecutionEnv) (field : Ident) {locals : Store} - (hcomet : - locals.get? "comet" = some (setRewardConfigWithMultiplierCometValue I)) : - evalStorageRef config { contract := contract, locals := locals } evm - (rewardConfigF (.var "comet") field) = - .ok { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)), - .field field] } := by - simp only [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, rewardConfigF, - evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, valueToKey?, - Std.HashMap.get?_eq_getElem?] - rw [← Std.HashMap.get?_eq_getElem?] - rw [hcomet] - -theorem setRewardConfigAfterSafe64Frame_rewardConfig_none (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) : - (setRewardConfigAfterSafe64Frame I baseWord decNat).locals.get? "rewardConfig" = none := by - simp only [setRewardConfigAfterSafe64Frame, setRewardConfigAfterPow10Frame, - setRewardConfigAfterDecimalsFrame, resumeAfterInternalCall] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - setRewardConfigWithMultiplierBodyStore_rewardConfig] - -theorem setRewardConfigAfterSafe64Frame_comet (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) : - (setRewardConfigAfterSafe64Frame I baseWord decNat).locals.get? "comet" = - some (setRewardConfigWithMultiplierCometValue I) := by - simp only [setRewardConfigAfterSafe64Frame, setRewardConfigAfterPow10Frame, - setRewardConfigAfterDecimalsFrame, resumeAfterInternalCall] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - setRewardConfigWithMultiplierBodyStore_comet] - -theorem setRewardConfigAfterSafe64Frame_accrualScale (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) : - (setRewardConfigAfterSafe64Frame I baseWord decNat).locals.get? "accrualScale" = - some (.int (Int.ofNat baseWord.toNat)) := by - simp only [setRewardConfigAfterSafe64Frame, setRewardConfigAfterPow10Frame, - setRewardConfigAfterDecimalsFrame, resumeAfterInternalCall] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_self] - -theorem setRewardConfigAfterSafe64Frame_tokenScale (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) : - (setRewardConfigAfterSafe64Frame I baseWord decNat).locals.get? "tokenScale" = - some (.int (Int.ofNat ((10 : ℕ) ^ decNat))) := by - simp only [setRewardConfigAfterSafe64Frame, resumeAfterInternalCall, collapseReturns] - rw [store_get_self] - -theorem setRewardConfigAfterSafe64Frame_token (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) : - (setRewardConfigAfterSafe64Frame I baseWord decNat).locals.get? "token" = - some (setRewardConfigWithMultiplierTokenValue I) := by - simp only [setRewardConfigAfterSafe64Frame, setRewardConfigAfterPow10Frame, - setRewardConfigAfterDecimalsFrame, resumeAfterInternalCall] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - setRewardConfigWithMultiplierBodyStore_token] - -theorem setRewardConfigAfterSafe64Frame_multiplier (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) : - (setRewardConfigAfterSafe64Frame I baseWord decNat).locals.get? "multiplier" = - some (setRewardConfigWithMultiplierMultiplierValue I) := by - simp only [setRewardConfigAfterSafe64Frame, setRewardConfigAfterPow10Frame, - setRewardConfigAfterDecimalsFrame, resumeAfterInternalCall] - rw [store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - setRewardConfigWithMultiplierBodyStore_multiplier] - -theorem setRewardConfigAssign_token_afterSafe64 (evm : EVM.State) (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) - (hcanonToken : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) : - assignStorageRef? config (setRewardConfigAfterSafe64Frame I baseWord decNat) evm .storage - (rewardConfigF (.var "comet") "token") (setRewardConfigWithMultiplierTokenValue I) = - .ok (setRewardConfigAfterSafe64Frame I baseWord decNat, - setRewardConfigSourceAfterToken evm I) := by - let er : EvaledStorageRef := - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)), - .field "token"] } - let loc : StorageLoc := - fieldLoc (slotAdd (setRewardConfigWithMultiplierSlotOf I) 0) 0 20 (by decide) .address - have her : - evalStorageRef config (setRewardConfigAfterSafe64Frame I baseWord decNat) evm - (rewardConfigF (.var "comet") "token") = .ok er := by - exact evalStorageRef_setRewardConfigWithMultiplier_rewardConfig_field_of_comet - (evm := evm) (I := I) (field := "token") - (setRewardConfigAfterSafe64Frame_comet I baseWord decNat) - have hty : storageTypeAt? contract.storage er = some (.elem .address) := by - simp [er, storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hstore : - storageLocStore evm loc (setRewardConfigWithMultiplierTokenValue I) = - some (setRewardConfigSourceAfterToken evm I) := by - rw [show loc = fieldLoc (slotAdd (setRewardConfigWithMultiplierSlotOf I) 0) 0 20 - (by decide) .address from rfl, slotAdd_zero] - simpa [setRewardConfigSourceAfterToken, setRewardConfigSlot0AfterToken, - setRewardConfigWithMultiplierTokenValue, fieldLoc, loc, addressOffset0Loc] using - storageLocStore_address_offset0 evm (setRewardConfigWithMultiplierSlotOf I) - (setRewardConfigWithMultiplierTokenWord I) hcanonToken - exact assignStorageRef_storage_scalar_value (cfg := config) - (solm := setRewardConfigAfterSafe64Frame I baseWord decNat) - (evm := evm) (evm' := setRewardConfigSourceAfterToken evm I) - (slot := rewardConfigF (.var "comet") "token") (er := er) - (ty := .elem .address) (loc := loc) - (value := setRewardConfigWithMultiplierTokenValue I) - (setRewardConfigAfterSafe64Frame_rewardConfig_none I baseWord decNat) - her hty (by rfl) (by trivial) hstore - -theorem setRewardConfigAssign_rescale_afterSafe64 (evm : EVM.State) (I : ExecutionEnv) - (baseWord rescale : UInt256) (decNat : ℕ) : - assignStorageRef? config (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceAfterToken evm I) .storage - (rewardConfigF (.var "comet") "rescaleFactor") (.int (Int.ofNat rescale.toNat)) = - .ok (setRewardConfigAfterSafe64Frame I baseWord decNat, - setRewardConfigSourceAfterRescale evm I rescale) := by - let er : EvaledStorageRef := - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)), - .field "rescaleFactor"] } - let loc : StorageLoc := - fieldLoc (slotAdd (setRewardConfigWithMultiplierSlotOf I) 0) 20 8 (by decide) - (.int uint64Int) - have her : - evalStorageRef config (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceAfterToken evm I) - (rewardConfigF (.var "comet") "rescaleFactor") = .ok er := by - exact evalStorageRef_setRewardConfigWithMultiplier_rewardConfig_field_of_comet - (evm := setRewardConfigSourceAfterToken evm I) (I := I) (field := "rescaleFactor") - (setRewardConfigAfterSafe64Frame_comet I baseWord decNat) - have hty : storageTypeAt? contract.storage er = some (.elem (.int uint64Int)) := by - simp [er, storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hstore : - storageLocStore (setRewardConfigSourceAfterToken evm I) loc - (.int (Int.ofNat rescale.toNat)) = - some (setRewardConfigSourceAfterRescale evm I rescale) := by - rw [show loc = fieldLoc (slotAdd (setRewardConfigWithMultiplierSlotOf I) 0) 20 8 - (by decide) (.int uint64Int) from rfl, slotAdd_zero] - simpa [setRewardConfigSourceAfterRescale] using - setRewardConfigStorageLocStore_uint64_offset20 - (setRewardConfigSourceAfterToken evm I) (setRewardConfigWithMultiplierSlotOf I) rescale - exact assignStorageRef_storage_scalar_value (cfg := config) - (solm := setRewardConfigAfterSafe64Frame I baseWord decNat) - (evm := setRewardConfigSourceAfterToken evm I) - (evm' := setRewardConfigSourceAfterRescale evm I rescale) - (slot := rewardConfigF (.var "comet") "rescaleFactor") (er := er) - (ty := .elem (.int uint64Int)) (loc := loc) - (value := .int (Int.ofNat rescale.toNat)) - (setRewardConfigAfterSafe64Frame_rewardConfig_none I baseWord decNat) - her hty (by rfl) (by trivial) hstore - -theorem setRewardConfigAssign_shouldUpscale_false_afterSafe64 (evm : EVM.State) - (I : ExecutionEnv) (baseWord rescale : UInt256) (decNat : ℕ) : - assignStorageRef? config (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceAfterRescale evm I rescale) .storage - (rewardConfigF (.var "comet") "shouldUpscale") (.bool false) = - .ok (setRewardConfigAfterSafe64Frame I baseWord decNat, - setRewardConfigSourceAfterShouldUpscale evm I rescale false) := by - let er : EvaledStorageRef := - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)), - .field "shouldUpscale"] } - let loc : StorageLoc := - fieldLoc (slotAdd (setRewardConfigWithMultiplierSlotOf I) 0) 28 1 (by decide) .bool - have her : - evalStorageRef config (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceAfterRescale evm I rescale) - (rewardConfigF (.var "comet") "shouldUpscale") = .ok er := by - exact evalStorageRef_setRewardConfigWithMultiplier_rewardConfig_field_of_comet - (evm := setRewardConfigSourceAfterRescale evm I rescale) (I := I) - (field := "shouldUpscale") - (setRewardConfigAfterSafe64Frame_comet I baseWord decNat) - have hty : storageTypeAt? contract.storage er = some (.elem .bool) := by - simp [er, storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hstore : - storageLocStore (setRewardConfigSourceAfterRescale evm I rescale) loc (.bool false) = - some (setRewardConfigSourceAfterShouldUpscale evm I rescale false) := by - rw [show loc = fieldLoc (slotAdd (setRewardConfigWithMultiplierSlotOf I) 0) 28 1 - (by decide) .bool from rfl, slotAdd_zero] - simpa [setRewardConfigSourceAfterShouldUpscale] using - setRewardConfigStorageLocStore_bool_false_offset28 - (setRewardConfigSourceAfterRescale evm I rescale) (setRewardConfigWithMultiplierSlotOf I) - exact assignStorageRef_storage_scalar_value (cfg := config) - (solm := setRewardConfigAfterSafe64Frame I baseWord decNat) - (evm := setRewardConfigSourceAfterRescale evm I rescale) - (evm' := setRewardConfigSourceAfterShouldUpscale evm I rescale false) - (slot := rewardConfigF (.var "comet") "shouldUpscale") (er := er) - (ty := .elem .bool) (loc := loc) (value := .bool false) - (setRewardConfigAfterSafe64Frame_rewardConfig_none I baseWord decNat) - her hty (by rfl) (by trivial) hstore - -theorem setRewardConfigAssign_shouldUpscale_true_afterSafe64 (evm : EVM.State) - (I : ExecutionEnv) (baseWord rescale : UInt256) (decNat : ℕ) : - assignStorageRef? config (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceAfterRescale evm I rescale) .storage - (rewardConfigF (.var "comet") "shouldUpscale") (.bool true) = - .ok (setRewardConfigAfterSafe64Frame I baseWord decNat, - setRewardConfigSourceAfterShouldUpscale evm I rescale true) := by - let er : EvaledStorageRef := - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)), - .field "shouldUpscale"] } - let loc : StorageLoc := - fieldLoc (slotAdd (setRewardConfigWithMultiplierSlotOf I) 0) 28 1 (by decide) .bool - have her : - evalStorageRef config (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceAfterRescale evm I rescale) - (rewardConfigF (.var "comet") "shouldUpscale") = .ok er := by - exact evalStorageRef_setRewardConfigWithMultiplier_rewardConfig_field_of_comet - (evm := setRewardConfigSourceAfterRescale evm I rescale) (I := I) - (field := "shouldUpscale") - (setRewardConfigAfterSafe64Frame_comet I baseWord decNat) - have hty : storageTypeAt? contract.storage er = some (.elem .bool) := by - simp [er, storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hstore : - storageLocStore (setRewardConfigSourceAfterRescale evm I rescale) loc (.bool true) = - some (setRewardConfigSourceAfterShouldUpscale evm I rescale true) := by - rw [show loc = fieldLoc (slotAdd (setRewardConfigWithMultiplierSlotOf I) 0) 28 1 - (by decide) .bool from rfl, slotAdd_zero] - simpa [setRewardConfigSourceAfterShouldUpscale] using - setRewardConfigStorageLocStore_bool_true_offset28 - (setRewardConfigSourceAfterRescale evm I rescale) (setRewardConfigWithMultiplierSlotOf I) - exact assignStorageRef_storage_scalar_value (cfg := config) - (solm := setRewardConfigAfterSafe64Frame I baseWord decNat) - (evm := setRewardConfigSourceAfterRescale evm I rescale) - (evm' := setRewardConfigSourceAfterShouldUpscale evm I rescale true) - (slot := rewardConfigF (.var "comet") "shouldUpscale") (er := er) - (ty := .elem .bool) (loc := loc) (value := .bool true) - (setRewardConfigAfterSafe64Frame_rewardConfig_none I baseWord decNat) - her hty (by rfl) (by trivial) hstore - -set_option maxHeartbeats 5000000 in -theorem setRewardConfigAssign_multiplier_afterSafe64_state (evm : EVM.State) (I : ExecutionEnv) - (baseWord : UInt256) (decNat : ℕ) : - assignStorageRef? config (setRewardConfigAfterSafe64Frame I baseWord decNat) - evm .storage - (rewardConfigF (.var "comet") "multiplier") (setRewardConfigWithMultiplierMultiplierValue I) = - .ok (setRewardConfigAfterSafe64Frame I baseWord decNat, - Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I + ⟨1⟩) - (setRewardConfigWithMultiplierMultiplierWord I)) := by - let er : EvaledStorageRef := - { base := "rewardConfig", - steps := [.mindex (.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)), - .field "multiplier"] } - let loc : StorageLoc := - uint256Loc (setRewardConfigWithMultiplierSlotOf I + ⟨1⟩) - have her : - evalStorageRef config (setRewardConfigAfterSafe64Frame I baseWord decNat) - evm - (rewardConfigF (.var "comet") "multiplier") = .ok er := by - exact evalStorageRef_setRewardConfigWithMultiplier_rewardConfig_field_of_comet - (evm := evm) (I := I) - (field := "multiplier") - (setRewardConfigAfterSafe64Frame_comet I baseWord decNat) - have hty : storageTypeAt? contract.storage er = some (.elem (.int uint256Int)) := by - simp [er, storageTypeAt?, contract, storageDecls, RewardConfigStructTy, storageTypeStep?] - have hloc : config.storage.layout er = fun _ => some loc := by - rw [show loc = fieldLoc (slotAdd (setRewardConfigWithMultiplierSlotOf I) 1) 0 32 - (by decide) (.int uint256Int) by - dsimp [loc] - rw [slotAdd_one] - rfl] - rfl - have hstore : - storageLocStore evm - loc (setRewardConfigWithMultiplierMultiplierValue I) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I + ⟨1⟩) - (setRewardConfigWithMultiplierMultiplierWord I)) := by - let slot1 := setRewardConfigWithMultiplierSlotOf I + ⟨1⟩ - change storageLocStore evm - (uint256Loc slot1) - (.int (Int.ofNat (setRewardConfigWithMultiplierMultiplierWord I).toNat)) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner - slot1 - (setRewardConfigWithMultiplierMultiplierWord I)) - exact storageLocStore_uint256 evm slot1 (setRewardConfigWithMultiplierMultiplierWord I) - have hbase := setRewardConfigAfterSafe64Frame_rewardConfig_none I baseWord decNat - apply assignStorageRef_storage_scalar_value - (er := er) (ty := .elem (.int uint256Int)) (loc := loc) - · exact hbase - · exact her - · exact hty - · exact hloc - · trivial - · exact hstore - -set_option maxHeartbeats 1000000 in -theorem setRewardConfigWithMultiplierFunctionBodyReturns_downscale - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseWord rescale : UInt256} {decNat : ℕ} - (hcanonToken : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : - config.externalABI.decode? "baseAccrualScale" baseOut = - some [.int (Int.ofNat baseWord.toNat)]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ decNat ≤ 2 ^ 64 - 1) - (hrescale : rescale.toNat = baseWord.toNat / (10 : ℕ) ^ decNat) - (hgt : (10 : ℕ) ^ decNat < baseWord.toNat) : - ExecFuncBody config (setRewardConfigWithMultiplierBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body - (.returned (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceFinal evmDec I rescale false) none) := by - refine ExecFuncBody.execBlockOK ?_ - change ExecBlock config (setRewardConfigWithMultiplierBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - (.ok (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceFinal evmDec I rescale false)) - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfigWithMultiplier_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigWithMultiplierBodyStore I).insert "accrualScale" - (.int (Int.ofNat baseWord.toNat)) } - evmBase (.var "token") = - .ok (setRewardConfigWithMultiplierTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigWithMultiplierBodyStore_token] - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - htokenExpr - (by simp [evalExpr?, pure]) - (by rfl) - hcallDec hdecDec) ?_ - have hpowArgs : - evalExprs? config (setRewardConfigAfterDecimalsFrame I baseWord decNat) evmDec - [.var "tokenDecimals"] = .ok [.int (Int.ofNat decNat)] := by - simp only [setRewardConfigAfterDecimalsFrame, evalExprs?, evalExpr?, EvalResult.ofOption, - EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigAfterDecimalsFrame I baseWord decNat) - (evm := evmDec) (calleeEvm := evmDec) - (name := "pow10") (retVar := "tokenScale256") (args := [.var "tokenDecimals"]) - (argVals := [.int (Int.ofNat decNat)]) - (callee := pow10Function) (locals := pow10Store decNat) - (calleeSolm := { contract := contract, locals := pow10Store decNat }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hpowArgs lookupCallable_pow10 (bindParams_pow10 decNat) - (by simpa using pow10FunctionBodyReturns_le77 evmDec hle77)) ?_ - have hsafeArgs : - evalExprs? config (setRewardConfigAfterPow10Frame I baseWord decNat) evmDec - [.var "tokenScale256"] = .ok [.int (Int.ofNat ((10 : ℕ) ^ decNat))] := by - simp only [setRewardConfigAfterPow10Frame, setRewardConfigAfterDecimalsFrame, - resumeAfterInternalCall, evalExprs?, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigAfterPow10Frame I baseWord decNat) - (evm := evmDec) (calleeEvm := evmDec) - (name := "safe64") (retVar := "tokenScale") (args := [.var "tokenScale256"]) - (argVals := [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - (callee := safe64Function) (locals := safe64Store ((10 : ℕ) ^ decNat)) - (calleeSolm := { contract := contract, locals := safe64Store ((10 : ℕ) ^ decNat) }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hsafeArgs lookupCallable_safe64 (bindParams_safe64 ((10 : ℕ) ^ decNat)) - (by simpa using safe64FunctionBodyReturns_le evmDec hsafe64)) ?_ - have hcond : - evalExpr? config (setRewardConfigAfterSafe64Frame I baseWord decNat) evmDec - (.binary .gt (.var "accrualScale") (.var "tokenScale")) = .ok (.bool true) := by - have hgtInt : (10 : ℤ) ^ decNat < (baseWord.toNat : ℤ) := by - exact_mod_cast hgt - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - repeat rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigAfterSafe64Frame_accrualScale, - setRewardConfigAfterSafe64Frame_tokenScale] - simpa [evalBinaryOp?] using hgtInt - refine ExecBlock.consNormal (ExecStmt.iteTrue hcond ?_) ExecBlock.nil - have htokenRhs : - evalExpr? config (setRewardConfigAfterSafe64Frame I baseWord decNat) evmDec (.var "token") = - .ok (setRewardConfigWithMultiplierTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setRewardConfigAfterSafe64Frame_token] - refine ExecBlock.consNormal - (ExecStmt.assign htokenRhs - (setRewardConfigAssign_token_afterSafe64 evmDec I baseWord decNat hcanonToken)) ?_ - have hrescaleRhs : - evalExpr? config (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceAfterToken evmDec I) - (.binary .div (.var "accrualScale") (.var "tokenScale")) = - .ok (.int (Int.ofNat rescale.toNat)) := by - rw [hrescale] - have hpowPos : (10 : ℕ) ^ decNat ≠ 0 := by positivity - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - repeat rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigAfterSafe64Frame_accrualScale, - setRewardConfigAfterSafe64Frame_tokenScale] - simp [evalBinaryOp?, hpowPos] - refine ExecBlock.consNormal - (ExecStmt.assign hrescaleRhs - (setRewardConfigAssign_rescale_afterSafe64 evmDec I baseWord rescale decNat)) ?_ - have hfalseRhs : - evalExpr? config (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceAfterRescale evmDec I rescale) (.boolLit false) = .ok (.bool false) := by - simp [evalExpr?, pure] - refine ExecBlock.consNormal - (ExecStmt.assign hfalseRhs - (setRewardConfigAssign_shouldUpscale_false_afterSafe64 evmDec I baseWord rescale decNat)) ?_ - have hmultRhs : - evalExpr? config (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceAfterShouldUpscale evmDec I rescale false) (.var "multiplier") = - .ok (setRewardConfigWithMultiplierMultiplierValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setRewardConfigAfterSafe64Frame_multiplier] - rw [setRewardConfigSourceFinal_false] - exact ExecBlock.consNormal - (ExecStmt.assign hmultRhs - (setRewardConfigAssign_multiplier_afterSafe64_state - (setRewardConfigSourceAfterShouldUpscale evmDec I rescale false) I baseWord decNat)) - ExecBlock.nil - -set_option maxHeartbeats 1000000 in -theorem setRewardConfigWithMultiplierFunctionBodyReturns_upscale - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseWord rescale : UInt256} {decNat : ℕ} - (hcanonToken : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : - config.externalABI.decode? "baseAccrualScale" baseOut = - some [.int (Int.ofNat baseWord.toNat)]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ decNat ≤ 2 ^ 64 - 1) - (hrescale : rescale.toNat = (10 : ℕ) ^ decNat / baseWord.toNat) - (hle : baseWord.toNat ≤ (10 : ℕ) ^ decNat) - (hbaseNZ : baseWord.toNat ≠ 0) : - ExecFuncBody config (setRewardConfigWithMultiplierBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body - (.returned (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceFinal evmDec I rescale true) none) := by - refine ExecFuncBody.execBlockOK ?_ - change ExecBlock config (setRewardConfigWithMultiplierBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - (.ok (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceFinal evmDec I rescale true)) - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfigWithMultiplier_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigWithMultiplierBodyStore I).insert "accrualScale" - (.int (Int.ofNat baseWord.toNat)) } - evmBase (.var "token") = - .ok (setRewardConfigWithMultiplierTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigWithMultiplierBodyStore_token] - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - htokenExpr - (by simp [evalExpr?, pure]) - (by rfl) - hcallDec hdecDec) ?_ - have hpowArgs : - evalExprs? config (setRewardConfigAfterDecimalsFrame I baseWord decNat) evmDec - [.var "tokenDecimals"] = .ok [.int (Int.ofNat decNat)] := by - simp only [setRewardConfigAfterDecimalsFrame, evalExprs?, evalExpr?, EvalResult.ofOption, - EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigAfterDecimalsFrame I baseWord decNat) - (evm := evmDec) (calleeEvm := evmDec) - (name := "pow10") (retVar := "tokenScale256") (args := [.var "tokenDecimals"]) - (argVals := [.int (Int.ofNat decNat)]) - (callee := pow10Function) (locals := pow10Store decNat) - (calleeSolm := { contract := contract, locals := pow10Store decNat }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hpowArgs lookupCallable_pow10 (bindParams_pow10 decNat) - (by simpa using pow10FunctionBodyReturns_le77 evmDec hle77)) ?_ - have hsafeArgs : - evalExprs? config (setRewardConfigAfterPow10Frame I baseWord decNat) evmDec - [.var "tokenScale256"] = .ok [.int (Int.ofNat ((10 : ℕ) ^ decNat))] := by - simp only [setRewardConfigAfterPow10Frame, setRewardConfigAfterDecimalsFrame, - resumeAfterInternalCall, evalExprs?, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigAfterPow10Frame I baseWord decNat) - (evm := evmDec) (calleeEvm := evmDec) - (name := "safe64") (retVar := "tokenScale") (args := [.var "tokenScale256"]) - (argVals := [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - (callee := safe64Function) (locals := safe64Store ((10 : ℕ) ^ decNat)) - (calleeSolm := { contract := contract, locals := safe64Store ((10 : ℕ) ^ decNat) }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hsafeArgs lookupCallable_safe64 (bindParams_safe64 ((10 : ℕ) ^ decNat)) - (by simpa using safe64FunctionBodyReturns_le evmDec hsafe64)) ?_ - have hcond : - evalExpr? config (setRewardConfigAfterSafe64Frame I baseWord decNat) evmDec - (.binary .gt (.var "accrualScale") (.var "tokenScale")) = .ok (.bool false) := by - have hnotNat : ¬ (10 : ℕ) ^ decNat < baseWord.toNat := by omega - have hnotInt : ¬ (10 : ℤ) ^ decNat < (baseWord.toNat : ℤ) := by - intro hlt - exact hnotNat (by exact_mod_cast hlt) - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - repeat rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigAfterSafe64Frame_accrualScale, - setRewardConfigAfterSafe64Frame_tokenScale] - simpa [evalBinaryOp?] using hnotInt - refine ExecBlock.consNormal (ExecStmt.iteFalse hcond ?_) ExecBlock.nil - have htokenRhs : - evalExpr? config (setRewardConfigAfterSafe64Frame I baseWord decNat) evmDec (.var "token") = - .ok (setRewardConfigWithMultiplierTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setRewardConfigAfterSafe64Frame_token] - refine ExecBlock.consNormal - (ExecStmt.assign htokenRhs - (setRewardConfigAssign_token_afterSafe64 evmDec I baseWord decNat hcanonToken)) ?_ - have hrescaleRhs : - evalExpr? config (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceAfterToken evmDec I) - (.binary .div (.var "tokenScale") (.var "accrualScale")) = - .ok (.int (Int.ofNat rescale.toNat)) := by - rw [hrescale] - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - repeat rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigAfterSafe64Frame_accrualScale, - setRewardConfigAfterSafe64Frame_tokenScale] - simp [evalBinaryOp?, hbaseNZ] - refine ExecBlock.consNormal - (ExecStmt.assign hrescaleRhs - (setRewardConfigAssign_rescale_afterSafe64 evmDec I baseWord rescale decNat)) ?_ - have htrueRhs : - evalExpr? config (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceAfterRescale evmDec I rescale) (.boolLit true) = .ok (.bool true) := by - simp [evalExpr?, pure] - refine ExecBlock.consNormal - (ExecStmt.assign htrueRhs - (setRewardConfigAssign_shouldUpscale_true_afterSafe64 evmDec I baseWord rescale decNat)) ?_ - have hmultRhs : - evalExpr? config (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceAfterShouldUpscale evmDec I rescale true) (.var "multiplier") = - .ok (setRewardConfigWithMultiplierMultiplierValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setRewardConfigAfterSafe64Frame_multiplier] - rw [setRewardConfigSourceFinal_true] - exact ExecBlock.consNormal - (ExecStmt.assign hmultRhs - (setRewardConfigAssign_multiplier_afterSafe64_state - (setRewardConfigSourceAfterShouldUpscale evmDec I rescale true) I baseWord decNat)) - ExecBlock.nil - -set_option maxHeartbeats 1000000 in -theorem setRewardConfigWithMultiplierFunctionBodyReverts_upscaleZero - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseWord : UInt256} {decNat : ℕ} - (hcanonToken : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : - config.externalABI.decode? "baseAccrualScale" baseOut = - some [.int (Int.ofNat baseWord.toNat)]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ decNat ≤ 2 ^ 64 - 1) - (hbase0 : baseWord.toNat = 0) : - ExecFuncBody config (setRewardConfigWithMultiplierBodyFrame evm I) evm - setRewardConfigWithMultiplierFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config (setRewardConfigWithMultiplierBodyFrame evm I) evm - [ .require (.binary .eq sender (.storage governorRef)), - .require (.binary .eq (.storage (rewardConfigF (.var "comet") "token")) zeroAddr), - .externalCall (.var "comet") "baseAccrualScale" (.intLit 0) [] "accrualScale" false, - .externalCall (.var "token") "decimals" (.intLit 0) [] "tokenDecimals" false, - .internalCall "pow10" [.var "tokenDecimals"] "tokenScale256", - .internalCall "safe64" [.var "tokenScale256"] "tokenScale", - .ite (.binary .gt (.var "accrualScale") (.var "tokenScale")) - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "accrualScale") (.var "tokenScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit false), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] - [ .assign .storage (rewardConfigF (.var "comet") "token") (.var "token"), - .assign .storage (rewardConfigF (.var "comet") "rescaleFactor") - (.binary .div (.var "tokenScale") (.var "accrualScale")), - .assign .storage (rewardConfigF (.var "comet") "shouldUpscale") (.boolLit true), - .assign .storage (rewardConfigF (.var "comet") "multiplier") (.var "multiplier") ] ] - .reverted - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_auth_true evm I hgov)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setRewardConfigWithMultiplier_body_token_zero_true evm I htoken)) ?_ - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (evalExpr_setRewardConfigWithMultiplier_body_comet evm I) - (by simp [evalExpr?, pure]) - (by rfl) - hcallBase hdecBase) ?_ - have htokenExpr : - evalExpr? config - { contract := contract, - locals := (setRewardConfigWithMultiplierBodyStore I).insert "accrualScale" - (.int (Int.ofNat baseWord.toNat)) } - evmBase (.var "token") = - .ok (setRewardConfigWithMultiplierTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), setRewardConfigWithMultiplierBodyStore_token] - refine ExecBlock.consNormal - (ExecStmt.externalCallSuccess - htokenExpr - (by simp [evalExpr?, pure]) - (by rfl) - hcallDec hdecDec) ?_ - have hpowArgs : - evalExprs? config (setRewardConfigAfterDecimalsFrame I baseWord decNat) evmDec - [.var "tokenDecimals"] = .ok [.int (Int.ofNat decNat)] := by - simp only [setRewardConfigAfterDecimalsFrame, evalExprs?, evalExpr?, EvalResult.ofOption, - EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigAfterDecimalsFrame I baseWord decNat) - (evm := evmDec) (calleeEvm := evmDec) - (name := "pow10") (retVar := "tokenScale256") (args := [.var "tokenDecimals"]) - (argVals := [.int (Int.ofNat decNat)]) - (callee := pow10Function) (locals := pow10Store decNat) - (calleeSolm := { contract := contract, locals := pow10Store decNat }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hpowArgs lookupCallable_pow10 (bindParams_pow10 decNat) - (by simpa using pow10FunctionBodyReturns_le77 evmDec hle77)) ?_ - have hsafeArgs : - evalExprs? config (setRewardConfigAfterPow10Frame I baseWord decNat) evmDec - [.var "tokenScale256"] = .ok [.int (Int.ofNat ((10 : ℕ) ^ decNat))] := by - simp only [setRewardConfigAfterPow10Frame, setRewardConfigAfterDecimalsFrame, - resumeAfterInternalCall, evalExprs?, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - rw [store_get_self] - rfl - refine ExecBlock.consNormal - (internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigAfterPow10Frame I baseWord decNat) - (evm := evmDec) (calleeEvm := evmDec) - (name := "safe64") (retVar := "tokenScale") (args := [.var "tokenScale256"]) - (argVals := [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - (callee := safe64Function) (locals := safe64Store ((10 : ℕ) ^ decNat)) - (calleeSolm := { contract := contract, locals := safe64Store ((10 : ℕ) ^ decNat) }) - (value := some [.int (Int.ofNat ((10 : ℕ) ^ decNat))]) - hsafeArgs lookupCallable_safe64 (bindParams_safe64 ((10 : ℕ) ^ decNat)) - (by simpa using safe64FunctionBodyReturns_le evmDec hsafe64)) ?_ - have hcond : - evalExpr? config (setRewardConfigAfterSafe64Frame I baseWord decNat) evmDec - (.binary .gt (.var "accrualScale") (.var "tokenScale")) = .ok (.bool false) := by - have hnotNat : ¬ (10 : ℕ) ^ decNat < baseWord.toNat := by - rw [hbase0] - exact Nat.not_lt_zero _ - have hnotInt : ¬ (10 : ℤ) ^ decNat < (baseWord.toNat : ℤ) := by - intro hlt - exact hnotNat (by exact_mod_cast hlt) - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - repeat rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigAfterSafe64Frame_accrualScale, - setRewardConfigAfterSafe64Frame_tokenScale] - simpa [evalBinaryOp?] using hnotInt - refine ExecBlock.consRevert (ExecStmt.iteFalse hcond ?_) - have htokenRhs : - evalExpr? config (setRewardConfigAfterSafe64Frame I baseWord decNat) evmDec (.var "token") = - .ok (setRewardConfigWithMultiplierTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setRewardConfigAfterSafe64Frame_token] - refine ExecBlock.consNormal - (ExecStmt.assign htokenRhs - (setRewardConfigAssign_token_afterSafe64 evmDec I baseWord decNat hcanonToken)) ?_ - have hrescaleRhs : - evalExpr? config (setRewardConfigAfterSafe64Frame I baseWord decNat) - (setRewardConfigSourceAfterToken evmDec I) - (.binary .div (.var "tokenScale") (.var "accrualScale")) = .revert := by - simp only [evalExpr?, EvalResult.ofOption, EvalResult.bind, bind] - repeat rw [← Std.HashMap.get?_eq_getElem?] - rw [setRewardConfigAfterSafe64Frame_accrualScale, - setRewardConfigAfterSafe64Frame_tokenScale] - simp [evalBinaryOp?, hbase0] - exact ExecBlock.consRevert (ExecStmt.assignExprRevert hrescaleRhs) - -theorem cometRewardsSetRewardConfigWithMultiplierBodyReturns_downscale - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseWord rescale : UInt256} {decNat : ℕ} - (hcanonToken : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : - config.externalABI.decode? "baseAccrualScale" baseOut = - some [.int (Int.ofNat baseWord.toNat)]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ decNat ≤ 2 ^ 64 - 1) - (hrescale : rescale.toNat = baseWord.toNat / (10 : ℕ) ^ decNat) - (hgt : (10 : ℕ) ^ decNat < baseWord.toNat) : - ExecTransitionBody config contract evm (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body - (.returned (resumeAfterInternalCall (setRewardConfigWithMultiplierFrame evm I) "_set" none) - (setRewardConfigSourceFinal evmDec I rescale false) none) := by - refine ExecFuncBody.execBlockOK ?_ - have hstmt : - ExecStmt config (setRewardConfigWithMultiplierFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", .var "multiplier"] "_set") - (.ok (resumeAfterInternalCall (setRewardConfigWithMultiplierFrame evm I) "_set" none) - (setRewardConfigSourceFinal evmDec I rescale false)) := by - exact internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigWithMultiplierFrame evm I) (evm := evm) - (calleeEvm := setRewardConfigSourceFinal evmDec I rescale false) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", .var "multiplier"]) - (argVals := setRewardConfigWithMultiplierArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigWithMultiplierBodyStore I) - (calleeSolm := setRewardConfigAfterSafe64Frame I baseWord decNat) - (value := none) - (evalExprs_setRewardConfigWithMultiplier_args evm I) - (by simpa [setRewardConfigWithMultiplierFrame] using - lookupCallable_setRewardConfigWithMultiplierBody) - (bindParams_setRewardConfigWithMultiplier I) - (by - simpa [setRewardConfigWithMultiplierFrame, - setRewardConfigWithMultiplierBodyFrame] using - setRewardConfigWithMultiplierFunctionBodyReturns_downscale - evm evmBase evmDec I hcanonToken hgov htoken hcallBase hdecBase hcallDec hdecDec - hle77 hsafe64 hrescale hgt) - simpa [setRewardConfigWithMultiplierTransition, externalEntryGuard, nonpayable, - calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigWithMultiplierStore I) hsize)).run - (ExecBlock.consNormal hstmt ExecBlock.nil) - -theorem cometRewardsSetRewardConfigWithMultiplierBodyReturns_upscale - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseWord rescale : UInt256} {decNat : ℕ} - (hcanonToken : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : - config.externalABI.decode? "baseAccrualScale" baseOut = - some [.int (Int.ofNat baseWord.toNat)]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ decNat ≤ 2 ^ 64 - 1) - (hrescale : rescale.toNat = (10 : ℕ) ^ decNat / baseWord.toNat) - (hle : baseWord.toNat ≤ (10 : ℕ) ^ decNat) - (hbaseNZ : baseWord.toNat ≠ 0) : - ExecTransitionBody config contract evm (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body - (.returned (resumeAfterInternalCall (setRewardConfigWithMultiplierFrame evm I) "_set" none) - (setRewardConfigSourceFinal evmDec I rescale true) none) := by - refine ExecFuncBody.execBlockOK ?_ - have hstmt : - ExecStmt config (setRewardConfigWithMultiplierFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", .var "multiplier"] "_set") - (.ok (resumeAfterInternalCall (setRewardConfigWithMultiplierFrame evm I) "_set" none) - (setRewardConfigSourceFinal evmDec I rescale true)) := by - exact internalCallFunctionReturn - (cfg := config) (caller := setRewardConfigWithMultiplierFrame evm I) (evm := evm) - (calleeEvm := setRewardConfigSourceFinal evmDec I rescale true) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", .var "multiplier"]) - (argVals := setRewardConfigWithMultiplierArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigWithMultiplierBodyStore I) - (calleeSolm := setRewardConfigAfterSafe64Frame I baseWord decNat) - (value := none) - (evalExprs_setRewardConfigWithMultiplier_args evm I) - (by simpa [setRewardConfigWithMultiplierFrame] using - lookupCallable_setRewardConfigWithMultiplierBody) - (bindParams_setRewardConfigWithMultiplier I) - (by - simpa [setRewardConfigWithMultiplierFrame, - setRewardConfigWithMultiplierBodyFrame] using - setRewardConfigWithMultiplierFunctionBodyReturns_upscale - evm evmBase evmDec I hcanonToken hgov htoken hcallBase hdecBase hcallDec hdecDec - hle77 hsafe64 hrescale hle hbaseNZ) - simpa [setRewardConfigWithMultiplierTransition, externalEntryGuard, nonpayable, - calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigWithMultiplierStore I) hsize)).run - (ExecBlock.consNormal hstmt ExecBlock.nil) - -theorem cometRewardsSetRewardConfigWithMultiplierBodyReverts_upscaleZero - (evm evmBase evmDec : EVM.State) (I : ExecutionEnv) {baseOut decOut : ByteArray} - {baseWord : UInt256} {decNat : ℕ} - (hcanonToken : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (htoken : - UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩) - (hcallBase : - typedCallViaEVM config evm - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] (true, evmBase, baseOut) false) - (hdecBase : - config.externalABI.decode? "baseAccrualScale" baseOut = - some [.int (Int.ofNat baseWord.toNat)]) - (hcallDec : - typedCallViaEVM config evmBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] (true, evmDec, decOut) false) - (hdecDec : - config.externalABI.decode? "decimals" decOut = some [.int (Int.ofNat decNat)]) - (hle77 : decNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ decNat ≤ 2 ^ 64 - 1) - (hbase0 : baseWord.toNat = 0) : - ExecTransitionBody config contract evm (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (setRewardConfigWithMultiplierFrame evm I) evm - (.internalCall "setRewardConfigWithMultiplierBody" - [.var "comet", .var "token", .var "multiplier"] "_set") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := setRewardConfigWithMultiplierFrame evm I) (evm := evm) - (name := "setRewardConfigWithMultiplierBody") (retVar := "_set") - (args := [.var "comet", .var "token", .var "multiplier"]) - (argVals := setRewardConfigWithMultiplierArgs I) - (callee := setRewardConfigWithMultiplierFunction) - (locals := setRewardConfigWithMultiplierBodyStore I) - (evalExprs_setRewardConfigWithMultiplier_args evm I) - (by simpa [setRewardConfigWithMultiplierFrame] using - lookupCallable_setRewardConfigWithMultiplierBody) - (bindParams_setRewardConfigWithMultiplier I) - (by - simpa [setRewardConfigWithMultiplierFrame, - setRewardConfigWithMultiplierBodyFrame] using - setRewardConfigWithMultiplierFunctionBodyReverts_upscaleZero - evm evmBase evmDec I hcanonToken hgov htoken hcallBase hdecBase hcallDec hdecDec - hle77 hsafe64 hbase0) - simpa [setRewardConfigWithMultiplierTransition, externalEntryGuard, nonpayable, - calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (setRewardConfigWithMultiplierStore I) hsize)).run - (ExecBlock.consRevert hstmt) - -def setRewardConfigPanicSelector : UInt256 := - UInt256.shiftLeft (⟨0x4e487b71⟩ : UInt256) ⟨224⟩ - -def setRewardConfigInvalidUInt64Selector : UInt256 := - UInt256.shiftLeft (⟨0x4809a3⟩ : UInt256) ⟨226⟩ - -noncomputable def setRewardConfigPanicMem0 (mem : ByteArray) : ByteArray := - (UInt256.toByteArray setRewardConfigPanicSelector).write 0 mem 0 32 - -noncomputable def setRewardConfigPanicMem (code : UInt256) (mem : ByteArray) : ByteArray := - (UInt256.toByteArray code).write 0 (setRewardConfigPanicMem0 mem) 4 32 - -noncomputable def setRewardConfigInvalidUInt64SelectorMem (mem : ByteArray) : ByteArray := - (UInt256.toByteArray setRewardConfigInvalidUInt64Selector).write 0 mem 192 32 - -noncomputable def setRewardConfigInvalidUInt64Mem (n : UInt256) (mem : ByteArray) : - ByteArray := - (UInt256.toByteArray n).write 0 (setRewardConfigInvalidUInt64SelectorMem mem) 196 32 - -theorem setRewardConfigBasePostCallMem_read128_of_size_ge (I : ExecutionEnv) - {out : ByteArray} (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (setRewardConfigBasePostCallMem I out).readWithPadding 128 32 = - out.extract 0 32 := by - unfold setRewardConfigBasePostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := out.size) - (by decide) hout32 houtSize - rw [hlen] - exact write32_read_back out - (setRewardConfigBaseAccrualScaleCalldataMem I) - 128 hout32 (by exact setRewardConfigBaseAccrualScaleCalldataMem_size_ge128 I) - -theorem setRewardConfigBasePostCallMem_size_ge160 (I : ExecutionEnv) {out : ByteArray} - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - 160 ≤ (setRewardConfigBasePostCallMem I out).size := by - unfold setRewardConfigBasePostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := out.size) - (by decide) hout32 houtSize - rw [hlen] - rw [write32_eq out (setRewardConfigBaseAccrualScaleCalldataMem I) 128 hout32 - (by exact setRewardConfigBaseAccrualScaleCalldataMem_size_ge128 I)] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract] - have hbase := setRewardConfigBaseAccrualScaleCalldataMem_size_ge128 I - omega - -theorem setRewardConfigBasePostCallMem_mload128_haw : - ¬ (⟨128⟩ : UInt256) ≥ setRewardConfigBasePostCallAw * ⟨32⟩ := by - native_decide - -theorem setRewardConfigBasePostCallMem_mload128_of_size_ge (I : ExecutionEnv) - {out : ByteArray} (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (if (⟨128⟩ : UInt256).toNat ≥ (setRewardConfigBasePostCallMem I out).size - ∨ (⟨128⟩ : UInt256) ≥ setRewardConfigBasePostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigBasePostCallMem I out).readWithPadding - (⟨128⟩ : UInt256).toNat 32))) = - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) := by - exact mloadValue_eq_readWithPadding_of_lt_size - (mem := setRewardConfigBasePostCallMem I out) (aw := setRewardConfigBasePostCallAw) - (off := ⟨128⟩) (memSize := (setRewardConfigBasePostCallMem I out).size) - rfl - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - exact lt_of_lt_of_le (by omega) - (setRewardConfigBasePostCallMem_size_ge160 I hout32 houtSize)) - setRewardConfigBasePostCallMem_mload128_haw - |>.trans (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - setRewardConfigBasePostCallMem_read128_of_size_ge I hout32 houtSize]) - -noncomputable abbrev setRewardConfigBasePostDecodeMem (I : ExecutionEnv) - (out : ByteArray) : ByteArray := - (UInt256.toByteArray (⟨160⟩ : UInt256)).write 0 - (setRewardConfigBasePostCallMem I out) 64 32 - -theorem setRewardConfigBasePostDecodeMem_read128_of_size_ge (I : ExecutionEnv) - {out : ByteArray} (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (setRewardConfigBasePostDecodeMem I out).readWithPadding 128 32 = - out.extract 0 32 := by - unfold setRewardConfigBasePostDecodeMem - rw [write32_read_above (UInt256.toByteArray (⟨160⟩ : UInt256)) - (setRewardConfigBasePostCallMem I out) 64 128 - (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigBasePostCallMem_size_ge160 I hout32 houtSize)) - (by omega) - (by - exact le_trans (by omega) - (setRewardConfigBasePostCallMem_size_ge160 I hout32 houtSize))] - exact setRewardConfigBasePostCallMem_read128_of_size_ge I hout32 houtSize - -theorem setRewardConfigBasePostDecodeMem_mload128_of_size_ge (I : ExecutionEnv) - {out : ByteArray} (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (if (⟨128⟩ : UInt256).toNat ≥ (setRewardConfigBasePostDecodeMem I out).size - ∨ (⟨128⟩ : UInt256) ≥ setRewardConfigBasePostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigBasePostDecodeMem I out).readWithPadding - (⟨128⟩ : UInt256).toNat 32))) = - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) := by - exact mloadValue_eq_readWithPadding_of_lt_size - (mem := setRewardConfigBasePostDecodeMem I out) (aw := setRewardConfigBasePostCallAw) - (off := ⟨128⟩) (memSize := (setRewardConfigBasePostDecodeMem I out).size) - rfl - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - unfold setRewardConfigBasePostDecodeMem - rw [write32_eq (UInt256.toByteArray (⟨160⟩ : UInt256)) - (setRewardConfigBasePostCallMem I out) 64 (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigBasePostCallMem_size_ge160 I hout32 houtSize))] - simp - have hsz := setRewardConfigBasePostCallMem_size_ge160 I hout32 houtSize - omega) - setRewardConfigBasePostCallMem_mload128_haw - |>.trans (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - setRewardConfigBasePostDecodeMem_read128_of_size_ge I hout32 houtSize]) - -theorem setRewardConfigBasePostDecodeMem_mload64 (I : ExecutionEnv) {out : ByteArray} - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ (setRewardConfigBasePostDecodeMem I out).size - ∨ (⟨64⟩ : UInt256) ≥ setRewardConfigBasePostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigBasePostDecodeMem I out).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨160⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := setRewardConfigBasePostCallAw) (v := ⟨160⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigBasePostDecodeMem - rw [write32_eq (UInt256.toByteArray (⟨160⟩ : UInt256)) - (setRewardConfigBasePostCallMem I out) 64 (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigBasePostCallMem_size_ge160 I hout32 houtSize))] - simp - have hsz := setRewardConfigBasePostCallMem_size_ge160 I hout32 houtSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigBasePostDecodeMem - rw [write32_read_back _ _ 64 (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigBasePostCallMem_size_ge160 I hout32 houtSize))] - rw [show (UInt256.toByteArray (⟨160⟩ : UInt256)).extract 0 32 = - UInt256.toByteArray (⟨160⟩ : UInt256) by - rw [show 32 = (UInt256.toByteArray (⟨160⟩ : UInt256)).size by - rw [toByteArray_size]] - exact byteArray_extract_self _]) - -theorem decodeReturnValueWithMode_modern_uint64_none_short {returndata : ByteArray} - (hshort : returndata.size < 32) : - ABI.decodeReturnValueWithMode? DecodeMode.modern uint64 returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have htake0n : ¬ ((returndata.toList.drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, hlen] - omega - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [uint64]) - (returndata := returndata) (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - simp only [decodeScalarWords?] - unfold decodeScalarWord? ABI.readWord? ABI.readBytes? uint64 uint64Int - rw [if_neg htake0n] - rfl - -theorem decodeReturnValueWithMode_modern_uint64_ok {returndata : ByteArray} - (hlo : 32 ≤ returndata.size) (hhi : returndata.size < 2 ^ 255) - (hword : fromByteArrayBigEndian (returndata.extract 0 32) < EVM.twoPow 64) : - ABI.decodeReturnValueWithMode? DecodeMode.modern uint64 returndata = - some (.int (Int.ofNat (fromByteArrayBigEndian (returndata.extract 0 32)))) := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have htake0 : ((returndata.toList.drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, hlen] - omega - have hwordList := bytesToWord_take32_eq_extract0_32 (returndata := returndata) - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [uint64]) - (returndata := returndata) (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - simp only [decodeScalarWords?] - unfold decodeScalarWord? ABI.readWord? ABI.readBytes? uint64 uint64Int - rw [if_pos htake0] - simp only [bind, Option.bind] - rw [List.drop_zero] - rw [hwordList] - have hlt256 : - fromByteArrayBigEndian (returndata.extract 0 32) < UInt256.size := - lt_trans hword (by native_decide) - have hval : - (UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))).toNat = - fromByteArrayBigEndian (returndata.extract 0 32) := - UInt256.toNat_ofNat_of_lt hlt256 - have hguardNat : - (UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))).toNat < - EVM.twoPow 64 := by - rw [hval] - exact hword - have hguard : - ↑(UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))).val < - EVM.twoPow 64 := by - simpa [UInt256.toNat] using hguardNat - simp [ABI.decodeABIWord?, hguard] - simpa [UInt256.toNat] using hval - -theorem decodeReturnValueWithMode_modern_uint64_none_noncanon {returndata : ByteArray} - (hlo : 32 ≤ returndata.size) (hhi : returndata.size < 2 ^ 255) - (hword : ¬ fromByteArrayBigEndian (returndata.extract 0 32) < EVM.twoPow 64) : - ABI.decodeReturnValueWithMode? DecodeMode.modern uint64 returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have htake0 : ((returndata.toList.drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, hlen] - omega - have hwordList := bytesToWord_take32_eq_extract0_32 (returndata := returndata) - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [uint64]) - (returndata := returndata) (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - simp only [decodeScalarWords?] - unfold decodeScalarWord? ABI.readWord? ABI.readBytes? uint64 uint64Int - rw [if_pos htake0] - simp only [bind, Option.bind] - rw [List.drop_zero] - rw [hwordList] - have hval : - (UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))).toNat = - fromByteArrayBigEndian (returndata.extract 0 32) := - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt hlo) - have hguardNat : - ¬ (UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))).toNat < - EVM.twoPow 64 := by - intro hlt - exact hword (by - rw [← hval] - exact hlt) - have hguard : - ¬ ↑(UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))).val < - EVM.twoPow 64 := by - simpa [UInt256.toNat] using hguardNat - simp [ABI.decodeABIWord?, hguard] - -theorem decodeReturnValueWithMode_modern_uint64_none_huge {returndata : ByteArray} - (hhi : 2 ^ 255 ≤ returndata.size) : - ABI.decodeReturnValueWithMode? DecodeMode.modern uint64 returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [uint64]) - (returndata := returndata) (by decide)] - rw [if_pos (by exact ⟨by simp, by rw [hlen]; exact hhi⟩)] - -theorem decodeReturnValueWithMode_modern_uint8_none_short {returndata : ByteArray} - (hshort : returndata.size < 32) : - ABI.decodeReturnValueWithMode? DecodeMode.modern uint8 returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have htake0n : ¬ ((returndata.toList.drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, hlen] - omega - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [uint8]) - (returndata := returndata) (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - simp only [decodeScalarWords?] - unfold decodeScalarWord? ABI.readWord? ABI.readBytes? uint8 uint8Int - rw [if_neg htake0n] - rfl - -theorem decodeReturnValueWithMode_modern_uint8_ok {returndata : ByteArray} - (hlo : 32 ≤ returndata.size) (hhi : returndata.size < 2 ^ 255) - (hword : fromByteArrayBigEndian (returndata.extract 0 32) < EVM.twoPow 8) : - ABI.decodeReturnValueWithMode? DecodeMode.modern uint8 returndata = - some (.int (Int.ofNat (fromByteArrayBigEndian (returndata.extract 0 32)))) := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have htake0 : ((returndata.toList.drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, hlen] - omega - have hwordList := bytesToWord_take32_eq_extract0_32 (returndata := returndata) - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [uint8]) - (returndata := returndata) (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - simp only [decodeScalarWords?] - unfold decodeScalarWord? ABI.readWord? ABI.readBytes? uint8 uint8Int - rw [if_pos htake0] - simp only [bind, Option.bind] - rw [List.drop_zero] - rw [hwordList] - have hlt256 : - fromByteArrayBigEndian (returndata.extract 0 32) < UInt256.size := - lt_trans hword (by native_decide) - have hval : - (UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))).toNat = - fromByteArrayBigEndian (returndata.extract 0 32) := - UInt256.toNat_ofNat_of_lt hlt256 - have hguardNat : - (UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))).toNat < - EVM.twoPow 8 := by - rw [hval] - exact hword - have hguard : - ↑(UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))).val < - EVM.twoPow 8 := by - simpa [UInt256.toNat] using hguardNat - simp [ABI.decodeABIWord?, hguard] - simpa [UInt256.toNat] using hval - -theorem decodeReturnValueWithMode_modern_uint8_none_noncanon {returndata : ByteArray} - (hlo : 32 ≤ returndata.size) (hhi : returndata.size < 2 ^ 255) - (hword : ¬ fromByteArrayBigEndian (returndata.extract 0 32) < EVM.twoPow 8) : - ABI.decodeReturnValueWithMode? DecodeMode.modern uint8 returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have htake0 : ((returndata.toList.drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, hlen] - omega - have hwordList := bytesToWord_take32_eq_extract0_32 (returndata := returndata) - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [uint8]) - (returndata := returndata) (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - simp only [decodeScalarWords?] - unfold decodeScalarWord? ABI.readWord? ABI.readBytes? uint8 uint8Int - rw [if_pos htake0] - simp only [bind, Option.bind] - rw [List.drop_zero] - rw [hwordList] - have hval : - (UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))).toNat = - fromByteArrayBigEndian (returndata.extract 0 32) := - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt hlo) - have hguardNat : - ¬ (UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))).toNat < - EVM.twoPow 8 := by - intro hlt - exact hword (by - rw [← hval] - exact hlt) - have hguard : - ¬ ↑(UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))).val < - EVM.twoPow 8 := by - simpa [UInt256.toNat] using hguardNat - simp [ABI.decodeABIWord?, hguard] - -theorem decodeReturnValueWithMode_modern_uint8_none_huge {returndata : ByteArray} - (hhi : 2 ^ 255 ≤ returndata.size) : - ABI.decodeReturnValueWithMode? DecodeMode.modern uint8 returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [uint8]) - (returndata := returndata) (by decide)] - rw [if_pos (by exact ⟨by simp, by rw [hlen]; exact hhi⟩)] - -theorem cometRewardsBaseAccrualScale_decode_none_short {out : ByteArray} - (hshort : out.size < 32) : - config.externalABI.decode? "baseAccrualScale" out = none := by - change compoundRewardsExternalABI.decode? "baseAccrualScale" out = none - unfold compoundRewardsExternalABI decodeReturn? - simpa [uint64] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_uint64_none_short (returndata := out) hshort) - -theorem cometRewardsBaseAccrualScale_decode_ok {out : ByteArray} - (hlo : 32 ≤ out.size) (hhi : out.size < 2 ^ 255) - (hword : fromByteArrayBigEndian (out.extract 0 32) < EVM.twoPow 64) : - config.externalABI.decode? "baseAccrualScale" out = - some [.int (Int.ofNat (fromByteArrayBigEndian (out.extract 0 32)))] := by - change compoundRewardsExternalABI.decode? "baseAccrualScale" out = - some [.int (Int.ofNat (fromByteArrayBigEndian (out.extract 0 32)))] - unfold compoundRewardsExternalABI decodeReturn? - simpa [uint64] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_uint64_ok (returndata := out) hlo hhi hword) - -theorem cometRewardsBaseAccrualScale_decode_none_noncanon {out : ByteArray} - (hlo : 32 ≤ out.size) (hhi : out.size < 2 ^ 255) - (hword : ¬ fromByteArrayBigEndian (out.extract 0 32) < EVM.twoPow 64) : - config.externalABI.decode? "baseAccrualScale" out = none := by - change compoundRewardsExternalABI.decode? "baseAccrualScale" out = none - unfold compoundRewardsExternalABI decodeReturn? - simpa [uint64] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_uint64_none_noncanon (returndata := out) hlo hhi hword) - -theorem cometRewardsBaseAccrualScale_decode_none_huge {out : ByteArray} - (hhi : 2 ^ 255 ≤ out.size) : - config.externalABI.decode? "baseAccrualScale" out = none := by - change compoundRewardsExternalABI.decode? "baseAccrualScale" out = none - unfold compoundRewardsExternalABI decodeReturn? - simpa [uint64] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_uint64_none_huge (returndata := out) hhi) - -theorem cometRewardsDecimals_decode_none_short {out : ByteArray} - (hshort : out.size < 32) : - config.externalABI.decode? "decimals" out = none := by - change compoundRewardsExternalABI.decode? "decimals" out = none - unfold compoundRewardsExternalABI decodeReturn? - simpa [uint8] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_uint8_none_short (returndata := out) hshort) - -theorem cometRewardsDecimals_decode_ok {out : ByteArray} - (hlo : 32 ≤ out.size) (hhi : out.size < 2 ^ 255) - (hword : fromByteArrayBigEndian (out.extract 0 32) < EVM.twoPow 8) : - config.externalABI.decode? "decimals" out = - some [.int (Int.ofNat (fromByteArrayBigEndian (out.extract 0 32)))] := by - change compoundRewardsExternalABI.decode? "decimals" out = - some [.int (Int.ofNat (fromByteArrayBigEndian (out.extract 0 32)))] - unfold compoundRewardsExternalABI decodeReturn? - simpa [uint8] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_uint8_ok (returndata := out) hlo hhi hword) - -theorem cometRewardsDecimals_decode_none_noncanon {out : ByteArray} - (hlo : 32 ≤ out.size) (hhi : out.size < 2 ^ 255) - (hword : ¬ fromByteArrayBigEndian (out.extract 0 32) < EVM.twoPow 8) : - config.externalABI.decode? "decimals" out = none := by - change compoundRewardsExternalABI.decode? "decimals" out = none - unfold compoundRewardsExternalABI decodeReturn? - simpa [uint8] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_uint8_none_noncanon (returndata := out) hlo hhi hword) - -theorem cometRewardsDecimals_decode_none_huge {out : ByteArray} - (hhi : 2 ^ 255 ≤ out.size) : - config.externalABI.decode? "decimals" out = none := by - change compoundRewardsExternalABI.decode? "decimals" out = none - unfold compoundRewardsExternalABI decodeReturn? - simpa [uint8] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_uint8_none_huge (returndata := out) hhi) - -set_option maxHeartbeats 10000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_revert_configured - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (htoken : UInt256.land - (solcSlotWord σ I (setRewardConfigWithMultiplierSlotOf I)) solcAddrMask ≠ ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigWithMultiplierPc - (dispatchArmLastStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd197⟩ := - cometRewardsSetRewardConfigWithMultiplierX_auth_ok - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hsz100 hsize hhi hcanon0 hcanon1 hauth hreach - have hcleanComet : - UInt256.land (setRewardConfigWithMultiplierCometWord I) solcAddrMask = - setRewardConfigWithMultiplierCometWord I := by - exact solcAddrMask_clean (by - simpa [setRewardConfigWithMultiplierCometWord, calldataWord] using hcanon0) - have hcleanCometLeft : - UInt256.land solcAddrMask (setRewardConfigWithMultiplierCometWord I) = - setRewardConfigWithMultiplierCometWord I := by - rw [u256_land_comm solcAddrMask (setRewardConfigWithMultiplierCometWord I)] - exact hcleanComet - have hslot := setRewardConfigWithMultiplierSlotOf_eq_solc I hcanon0 - have hkeccak := rewardConfigKeccakSlot (setRewardConfigWithMultiplierCometWord I) - have rd203₀ := evm_run rd197 with [ - dup5, and, dup1, push1 ⟨0⟩, - raw mstore 0 - (wordAt0Mem (setRewardConfigWithMultiplierCometWord I) solcFreePtrMem) - (UInt256.ofNat 3) (by decide) mem_cost - (by - rw [hcleanCometLeft] - rfl) - (by decide) (by evm_ov)] - have rd203 := rd203₀ - rw [hcleanCometLeft] at rd203 - have rd215 := evm_run rd203 with [ - push1 ⟨1⟩, swap5, push1 ⟨32⟩, dup7, dup2, - raw mstore 0 (rewardConfigHashMem (setRewardConfigWithMultiplierCometWord I)) - (UInt256.ofNat 3) (by decide) mem_cost - (by rfl) (by decide) (by evm_ov), - dup2, dup10, push1 ⟨0⟩] - have rd216₀ := rd215.keccak256 0 - (solcMappingSlot ⟨1⟩ (setRewardConfigWithMultiplierCometWord I)) - (UInt256.ofNat 3) (by decide) mem_cost hkeccak (by decide) (by evm_ov) - have rd216 := rd216₀ - rw [← hslot] at rd216 - obtain ⟨_, _, rd217₀⟩ := rd216.sload (by decide) (by evm_ov) - obtain ⟨_, _, rd217⟩ : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨217⟩ - [solcSlotWord σ I (setRewardConfigWithMultiplierSlotOf I), solcAddrMask, ⟨32⟩, - solcAddrMask, setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigWithMultiplierTokenWord I, ⟨64⟩, ⟨0⟩] - (rewardConfigHashMem (setRewardConfigWithMultiplierCometWord I)) - (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by simpa [solcSlotWord] using rd217₀⟩ - have rd218 := evm_run rd217 with [and] - have rd752 := evm_run rd218 with [ - push2 ⟨752⟩, jumpiT htoken (by native_decide)] - have rd755 := evm_run rd752 with [ - jumpdest, dup9, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost - (rewardConfigHashMem_mload64 (setRewardConfigWithMultiplierCometWord I)) - (by decide) (by evm_ov)] - have rd766 := evm_run rd755 with [ - push4 ⟨977536693⟩, push1 ⟨224⟩, shl, dup2, - raw mstore 6 - (setRewardConfigAlreadyConfiguredSelectorMem (setRewardConfigWithMultiplierCometWord I)) - (UInt256.ofNat 5) (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - unfold setRewardConfigAlreadyConfiguredSelectorMem - rfl) - (by decide) (by evm_ov)] - have rd771 := evm_run rd766 with [ - dup1, dup7, add, dup5, swap1, - raw mstore 3 - (setRewardConfigAlreadyConfiguredMem (setRewardConfigWithMultiplierCometWord I)) - (UInt256.ofNat 6) (by decide) mem_cost - (by - rw [show (⟨4⟩ : UInt256) + ⟨128⟩ = ⟨132⟩ from by decide, - show (⟨132⟩ : UInt256).toNat = 132 from by decide] - unfold setRewardConfigAlreadyConfiguredMem - rfl) - (by decide) (by evm_ov)] - exact evm_run rd771 with [ - push1 ⟨36⟩, swap1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 10000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_configured_ok - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (htoken : UInt256.land - (solcSlotWord σ I (setRewardConfigWithMultiplierSlotOf I)) solcAddrMask = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigWithMultiplierPc - (dispatchArmLastStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨222⟩ - [⟨32⟩, solcAddrMask, setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigWithMultiplierTokenWord I, ⟨64⟩, ⟨0⟩] - (rewardConfigHashMem (setRewardConfigWithMultiplierCometWord I)) - (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd197⟩ := - cometRewardsSetRewardConfigWithMultiplierX_auth_ok - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hsz100 hsize hhi hcanon0 hcanon1 hauth hreach - have hcleanComet : - UInt256.land (setRewardConfigWithMultiplierCometWord I) solcAddrMask = - setRewardConfigWithMultiplierCometWord I := by - exact solcAddrMask_clean (by - simpa [setRewardConfigWithMultiplierCometWord, calldataWord] using hcanon0) - have hcleanCometLeft : - UInt256.land solcAddrMask (setRewardConfigWithMultiplierCometWord I) = - setRewardConfigWithMultiplierCometWord I := by - rw [u256_land_comm solcAddrMask (setRewardConfigWithMultiplierCometWord I)] - exact hcleanComet - have hslot := setRewardConfigWithMultiplierSlotOf_eq_solc I hcanon0 - have hkeccak := rewardConfigKeccakSlot (setRewardConfigWithMultiplierCometWord I) - have rd203₀ := evm_run rd197 with [ - dup5, and, dup1, push1 ⟨0⟩, - raw mstore 0 - (wordAt0Mem (setRewardConfigWithMultiplierCometWord I) solcFreePtrMem) - (UInt256.ofNat 3) (by decide) mem_cost - (by - rw [hcleanCometLeft] - rfl) - (by decide) (by evm_ov)] - have rd203 := rd203₀ - rw [hcleanCometLeft] at rd203 - have rd215 := evm_run rd203 with [ - push1 ⟨1⟩, swap5, push1 ⟨32⟩, dup7, dup2, - raw mstore 0 (rewardConfigHashMem (setRewardConfigWithMultiplierCometWord I)) - (UInt256.ofNat 3) (by decide) mem_cost - (by rfl) (by decide) (by evm_ov), - dup2, dup10, push1 ⟨0⟩] - have rd216₀ := rd215.keccak256 0 - (solcMappingSlot ⟨1⟩ (setRewardConfigWithMultiplierCometWord I)) - (UInt256.ofNat 3) (by decide) mem_cost hkeccak (by decide) (by evm_ov) - have rd216 := rd216₀ - rw [← hslot] at rd216 - obtain ⟨_, _, rd217₀⟩ := rd216.sload (by decide) (by evm_ov) - obtain ⟨_, _, rd217⟩ : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨217⟩ - [solcSlotWord σ I (setRewardConfigWithMultiplierSlotOf I), solcAddrMask, ⟨32⟩, - solcAddrMask, setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigWithMultiplierTokenWord I, ⟨64⟩, ⟨0⟩] - (rewardConfigHashMem (setRewardConfigWithMultiplierCometWord I)) - (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by simpa [solcSlotWord] using rd217₀⟩ - have rd218 := evm_run rd217 with [and] - rw [htoken] at rd218 - exact ⟨_, _, evm_run rd218 with [push2 ⟨752⟩, jumpiNT (by decide)]⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_call_baseAccrualScale - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (htoken : UInt256.land - (solcSlotWord σ I (setRewardConfigWithMultiplierSlotOf I)) solcAddrMask = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) setRewardConfigWithMultiplierPc - (dispatchArmLastStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ gasArg k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨241⟩ - [gasArg, setRewardConfigWithMultiplierCometWord I, ⟨128⟩, ⟨4⟩, ⟨128⟩, - ⟨32⟩, setRewardConfigWithMultiplierTokenWord I, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, ⟨128⟩, ⟨64⟩, ⟨0⟩] - (setRewardConfigBaseAccrualScaleCalldataMem I) - (UInt256.ofNat 5) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd222⟩ := - cometRewardsSetRewardConfigWithMultiplierX_configured_ok - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hsz100 hsize hhi hcanon0 hcanon1 hauth htoken hreach - have rd234 := evm_run rd222 with [ - dup9, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost - (rewardConfigHashMem_mload64 (setRewardConfigWithMultiplierCometWord I)) - (by decide) (by evm_ov), - push4 ⟨1359440587⟩, push1 ⟨225⟩, shl, dup2, - raw mstore 6 (setRewardConfigBaseAccrualScaleCalldataMem I) - (UInt256.ofNat 5) (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - unfold setRewardConfigBaseAccrualScaleCalldataMem - rfl) - (by decide) (by evm_ov)] - have rd240 := evm_run rd234 with [ - swap8, dup2, dup10, dup8, dup2, dup8] - obtain ⟨gasArg, rd241⟩ := evm_run rd240 with [gas] - exact ⟨gasArg, _, _, by simpa using rd241⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_call_baseAccrualScale_made - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ_evm I = solcSourceWord I) - (htoken : UInt256.land - (solcSlotWord σ_evm I (setRewardConfigWithMultiplierSlotOf I)) solcAddrMask = ⟨0⟩) - (hdepth : I.depth.val < 1024) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - setRewardConfigWithMultiplierPc (dispatchArmLastStack I) solcFreePtrMem - (UInt256.ofNat 3) ByteArray.empty (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - ∃ cA' σ'_evm σ'_solm A'_solm z out k C, - typedCallViaEVM config - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] - (z, - { initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' }, - out) false ∧ - accountMapEquiv σ'_evm σ'_solm ∧ - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨242⟩ (setRewardConfigBasePostCallStack z I) - (setRewardConfigBasePostCallMem I out) setRewardConfigBasePostCallAw out - (cA', σ'_evm) k C ∧ - out.size < 2 ^ 255 := by - obtain ⟨gasArg, k0, C0, rd241⟩ := - cometRewardsSetRewardConfigWithMultiplierX_call_baseAccrualScale - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanon0 hcanon1 hauth htoken hreach - have rd241Call : - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨241⟩ - (gasArg :: setRewardConfigWithMultiplierCometWord I :: ⟨128⟩ :: ⟨4⟩ :: - ⟨128⟩ :: ⟨32⟩ :: setRewardConfigBasePostCallTail I) - (setRewardConfigBaseAccrualScaleCalldataMem I) - (UInt256.ofNat 5) ByteArray.empty (cA, σ_evm) k0 C0 := by - simpa [setRewardConfigBasePostCallTail] using rd241 - have hdecCall : - decode cometRewardsBytecode (⟨241⟩ : UInt256) = some (.STATICCALL, .none) := by - native_decide - obtain ⟨cA', σ'_evm, z, out, A_in, callGas, k', C', hΘ, rd242, _houtSize⟩ := - RD.solcStaticcall (t := setRewardConfigBasePostCallTail I) rd241Call hdecCall - hdepth (by simp [setRewardConfigBasePostCallTail]) - obtain ⟨g'', A'_evm, hΘeq⟩ := hΘ - have houtSmall : out.size < 2 ^ 138 := by - exact Theta_returnData_size_lt_2pow138_of_eq - (blob := I.blobVersionedHashes) (cA := cA) - (gh := (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I).genesisBlockHeader) - (blocks := (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I).blocks) - (σ := σ_evm) - (σ₀ := (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I).σ₀) - (A := A_in) - (s := AccountAddress.ofUInt256 (UInt256.ofNat I.codeOwner)) - (o := I.sender) - (r := AccountAddress.ofUInt256 (setRewardConfigWithMultiplierCometWord I)) - (c := toExecute σ_evm - (AccountAddress.ofUInt256 (setRewardConfigWithMultiplierCometWord I))) - (g := callGas) (p := UInt256.ofNat I.gasPrice) - (v := ⟨0⟩) (v' := ⟨0⟩) - (d := (setRewardConfigBaseAccrualScaleCalldataMem I).readWithPadding 128 4) - (e := I.depth + 1) (H := I.header) (w := false) - hΘeq - (by exact Ethereum.EVM.ByteArray.readWithPadding_size_lt_uint256 _ _ _) - have houtSign : out.size < 2 ^ 255 := by omega - have hdepthNeI : I.depth ≠ 1024 := by - intro hEq - rw [hEq] at hdepth - exact absurd hdepth (by decide) - have hdepthNe : - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.depth ≠ - 1024 := by - simpa [initState] using hdepthNeI - have htgt := setRewardConfigBaseTarget_eq_targetWord I - have hcd := setRewardConfigBaseAccrualScaleCalldataMem_encode I - have hcallE : - typedCallViaEVM config - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] - (z, - { initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_evm - substate := A'_evm - createdAccounts := cA' }, - out) false := by - refine callCoincides - (cfg := config) - (evm := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (name := "baseAccrualScale") (args := []) - (tgt := EVM.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)) - (targetWord := setRewardConfigWithMultiplierCometWord I) - (cA' := cA') (σ' := σ'_evm) (A' := A'_evm) (A_in := A_in) - (z := z) (o := out) (g'' := g'') (callGas := callGas) - (mem := setRewardConfigBaseAccrualScaleCalldataMem I) - (inOff := ⟨128⟩) (inSize := ⟨4⟩) (callPerm := false) - hdepthNe htgt hcd ?_ - simpa [initState] using hΘeq - obtain ⟨σ'_solm, A'_solm, hcallSolm, hPostAccounts⟩ := - typedCallViaEVM_initState_accountMapEquiv hcallE hAccounts - exact ⟨cA', σ'_evm, σ'_solm, A'_solm, z, out, k', C', - hcallSolm, hPostAccounts, by - simpa [setRewardConfigBasePostCallStack, setRewardConfigBasePostCallTail, - setRewardConfigBasePostCallMem, setRewardConfigBasePostCallAw] using rd242, - houtSign⟩ - -theorem rdSwap9 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d e f x h i j : UInt256} {t : List UInt256} - (rd : RD code ee g s0 pc (a :: b :: c :: d :: e :: f :: x :: h :: i :: j :: t) - mem aw rdata acc k C) - (hdec : decode code pc = some (.SWAP9, .none)) (hov : t.length + 10 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) - (j :: b :: c :: d :: e :: f :: x :: h :: i :: a :: t) - mem aw rdata acc (k + 1) (C + 3) := - rd.stepSwap (fun s hc hp hs => by - have hd : decode s.executionEnv.code s.machineState.pc = some (.SWAP9, .none) := by - rw [hc, hp] - exact hdec - rw [← hc, step_swap9 s hd, hs] - have hov' : - ¬ ((a :: b :: c :: d :: e :: f :: x :: h :: i :: j :: t).length - 10 + 10 > - 1024) := by - simp only [List.length_cons] - omega - simp only [if_neg hov', GasConstants.Gverylow, stSwap]) - -theorem dup12_xstep {s : State} {code : ByteArray} - {pcv a b c d e f gg hh ii jj kk ll : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.DUP12, .none)) - (hstk : s.machineState.stack = - a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t) - (hov : t.length + 13 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok - (stSwap s - (ll :: a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t), - .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.DUP12, .none) := by - rw [hcode, hpc]; exact hdec - rw [← hcode, step_dup12 s hd, hstk] - have hov' : - ¬ ((a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t).length - 12 - + 13 > 1024) := by - simp only [List.length_cons] - omega - simp only [if_neg hov', GasConstants.Gverylow, stSwap] - -theorem rdDup12 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d e f gg hh ii jj kk ll : UInt256} {t : List UInt256} - (rd : RD code ee g s0 pc - (a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t) - mem aw rdata acc k C) - (hdec : decode code pc = some (.DUP12, .none)) (hov : t.length + 13 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) - (ll :: a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t) - mem aw rdata acc (k + 1) (C + 3) := - rd.stepSwap (fun _ hc hp hs => dup12_xstep hc hp hdec hs hov) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_after_baseAccrualScale_failure - {cA gh bl σ σ₀ A I} {g : Sat256} {out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨242⟩ (setRewardConfigBasePostCallStack false I) - (setRewardConfigBasePostCallMem I out) setRewardConfigBasePostCallAw out acc k C) - (houtSize : out.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have rd242 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨242⟩ - [⟨0⟩, setRewardConfigWithMultiplierTokenWord I, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, ⟨128⟩, ⟨64⟩, ⟨0⟩] - (setRewardConfigBasePostCallMem I out) setRewardConfigBasePostCallAw out acc k C := by - simpa [setRewardConfigBasePostCallStack, setRewardConfigBasePostCallTail] using rd - have rd243 := rdSwap9 rd242 (by native_decide) (by simp) - have rd741 := evm_run rd243 with [ - dup10, iszero, push2 ⟨741⟩, jumpiT (by native_decide) (by jump_dest)] - have rd744 := evm_run rd741 with [ - jumpdest, dup11, - raw mload 0 ⟨128⟩ setRewardConfigBasePostCallAw (by native_decide) - mem_cost (setRewardConfigBasePostCallMem_mload64 I houtSize) - (by native_decide) (by evm_ov)] - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have rd748pre := evm_run rd744 with [returndatasize, push1 ⟨0⟩, dup3] - let mem2 : ByteArray := - out.write 0 (setRewardConfigBasePostCallMem I out) 128 rdsz.toNat - let aw2 : UInt256 := - UInt256.ofNat (MachineState.M setRewardConfigBasePostCallAw.toNat 128 rdsz.toNat) - have rd748 := RD.returndatacopy - (Cₘ aw2 - Cₘ setRewardConfigBasePostCallAw) mem2 aw2 rd748pre - (by native_decide) - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, hrdsz_toNat]; omega) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, aw2, rdsz] - rw [show (⟨128⟩ : UInt256).toNat = 128 from rfl]) - (by rfl) - (by rfl) - (by simp) - have rd751 := evm_run rd748 with [returndatasize, swap1] - exact RD.rev - (Cₘ (UInt256.ofNat (MachineState.M aw2.toNat 128 rdsz.toNat)) - Cₘ aw2) - rd751 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, rdsz] - rw [show (⟨128⟩ : UInt256).toNat = 128 from rfl]) - (by simp) - -abbrev setRewardConfigBaseReturnWord (out : ByteArray) : UInt256 := - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) - -abbrev setRewardConfigAfterBaseDecodeStack (baseWord : UInt256) - (I : ExecutionEnv) : List UInt256 := - [solcAddrMask, setRewardConfigWithMultiplierTokenWord I, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, baseWord, ⟨64⟩, ⟨0⟩] - -abbrev setRewardConfigDecimalsSelectorWord : UInt256 := ⟨826074471⟩ - -abbrev setRewardConfigDecimalsSelectorShifted : UInt256 := - UInt256.shiftLeft setRewardConfigDecimalsSelectorWord ⟨224⟩ - -noncomputable def setRewardConfigDecimalsCalldataMem - (I : ExecutionEnv) (baseOut : ByteArray) : ByteArray := - (UInt256.toByteArray setRewardConfigDecimalsSelectorShifted).write 0 - (setRewardConfigBasePostDecodeMem I baseOut) 160 32 - -theorem setRewardConfigDecimalsCalldataMem_read160_4 - (I : ExecutionEnv) (baseOut : ByteArray) : - (setRewardConfigDecimalsCalldataMem I baseOut).readWithPadding 160 4 = - decimalsSelector := by - unfold setRewardConfigDecimalsCalldataMem - rw [toByteArray_write_read_window_of_gap - (b := setRewardConfigDecimalsSelectorShifted) - (mem := setRewardConfigBasePostDecodeMem I baseOut) - (off := 160) (start := 0) (len := 4) - (by norm_num) (by norm_num) (by norm_num) - (by - exact lt_of_le_of_lt (Nat.sub_le _ _) - (lt_usize 160 (by norm_num)))] - native_decide - -theorem setRewardConfigDecimalsCalldataMem_encode - (I : ExecutionEnv) (baseOut : ByteArray) : - config.externalABI.encode? "decimals" [] = - some ((setRewardConfigDecimalsCalldataMem I baseOut).readWithPadding 160 4) := by - rw [setRewardConfigDecimalsCalldataMem_read160_4] - rfl - -abbrev setRewardConfigDecimalsTargetWord (I : ExecutionEnv) : UInt256 := - UInt256.land solcAddrMask (setRewardConfigWithMultiplierTokenWord I) - -theorem setRewardConfigDecimalsTarget_eq_targetWord (I : ExecutionEnv) - (hcanon : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) : - EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat) = - AccountAddress.ofUInt256 (setRewardConfigDecimalsTargetWord I) := by - have hcleanLeft : - UInt256.land (setRewardConfigWithMultiplierTokenWord I) solcAddrMask = - setRewardConfigWithMultiplierTokenWord I := by - exact solcAddrMask_clean (by - simpa [setRewardConfigWithMultiplierTokenWord, calldataWord] using hcanon) - have hclean : - UInt256.land solcAddrMask (setRewardConfigWithMultiplierTokenWord I) = - setRewardConfigWithMultiplierTokenWord I := by - rw [u256_land_comm solcAddrMask (setRewardConfigWithMultiplierTokenWord I), hcleanLeft] - rw [setRewardConfigDecimalsTargetWord, hclean, accountAddress_ofUInt256_eq_ofNat_toNat] - apply Fin.ext - simp [EVM.address, EVM.uintN] - exact Nat.mod_eq_of_lt (AccountAddress.ofNat - (setRewardConfigWithMultiplierTokenWord I).toNat).isLt - -abbrev setRewardConfigDecimalsCallAw : UInt256 := - UInt256.ofNat (MachineState.M setRewardConfigBasePostCallAw.toNat 160 32) - -abbrev setRewardConfigDecimalsPostCallAw : UInt256 := - UInt256.ofNat (MachineState.M - (MachineState.M setRewardConfigDecimalsCallAw.toNat 160 4) 160 32) - -abbrev setRewardConfigDecimalsPostCallTail (baseWord : UInt256) - (I : ExecutionEnv) : List UInt256 := - [⟨160⟩, baseWord, ⟨32⟩, solcAddrMask, setRewardConfigWithMultiplierCometWord I, - ⟨224⟩, ⟨4⟩, setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigDecimalsTargetWord I, ⟨64⟩, ⟨0⟩] - -abbrev setRewardConfigDecimalsPostCallStack (z : Bool) (baseWord : UInt256) - (I : ExecutionEnv) : List UInt256 := - (if z then ⟨1⟩ else ⟨0⟩) :: setRewardConfigDecimalsPostCallTail baseWord I - -noncomputable abbrev setRewardConfigDecimalsPostCallMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) : ByteArray := - decOut.write 0 (setRewardConfigDecimalsCalldataMem I baseOut) 160 - (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat - -theorem byteArray_write_size_ge_base_of_le (src base : ByteArray) {dest len : ℕ} - (hsrc : len ≤ src.size) (hdest : dest ≤ base.size) : - base.size ≤ (src.write 0 base dest len).size := by - by_cases hlen : len = 0 - · subst len - rw [byteArray_write_len_zero] - · by_cases hin : dest + len ≤ base.size - · rw [write_eq_gen src base dest len hlen hsrc hin] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract] - omega - · have hext : base.size < dest + len := Nat.lt_of_not_ge hin - rw [write_eq_gen_extend src base dest len hlen hsrc hdest hext] - rw [ByteArray.size_append, ByteArray.size_extract, ByteArray.size_extract] - omega - -theorem setRewardConfigBasePostDecodeMem_read64 - (I : ExecutionEnv) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) : - (setRewardConfigBasePostDecodeMem I baseOut).readWithPadding 64 32 = - UInt256.toByteArray ⟨160⟩ := by - unfold setRewardConfigBasePostDecodeMem - rw [write32_read_back _ _ 64 (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigBasePostCallMem_size_ge160 I hout32 houtSize))] - rw [show (UInt256.toByteArray (⟨160⟩ : UInt256)).extract 0 32 = - UInt256.toByteArray (⟨160⟩ : UInt256) by - rw [show 32 = (UInt256.toByteArray (⟨160⟩ : UInt256)).size by - rw [toByteArray_size]] - exact byteArray_extract_self _] - -theorem setRewardConfigBasePostDecodeMem_size_ge160 - (I : ExecutionEnv) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) : - 160 ≤ (setRewardConfigBasePostDecodeMem I baseOut).size := by - unfold setRewardConfigBasePostDecodeMem - exact le_trans (setRewardConfigBasePostCallMem_size_ge160 I hout32 houtSize) - (byteArray_write_size_ge_base_of_le (UInt256.toByteArray (⟨160⟩ : UInt256)) - (setRewardConfigBasePostCallMem I baseOut) (by rw [toByteArray_size]) - (by - have hbase := setRewardConfigBasePostCallMem_size_ge160 I hout32 houtSize - omega)) - -theorem setRewardConfigDecimalsCalldataMem_size_ge192 - (I : ExecutionEnv) (baseOut : ByteArray) : - 192 ≤ (setRewardConfigDecimalsCalldataMem I baseOut).size := by - unfold setRewardConfigDecimalsCalldataMem - exact toByteArray_write_size_ge_off_add32 setRewardConfigDecimalsSelectorShifted - (setRewardConfigBasePostDecodeMem I baseOut) 160 - (by - exact lt_of_le_of_lt (Nat.sub_le _ _) - (lt_usize 160 (by norm_num))) - -theorem setRewardConfigDecimalsCalldataMem_read64 - (I : ExecutionEnv) {baseOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) : - (setRewardConfigDecimalsCalldataMem I baseOut).readWithPadding 64 32 = - UInt256.toByteArray ⟨160⟩ := by - unfold setRewardConfigDecimalsCalldataMem - rw [toByteArray_write_read_below_of_gap - (b := setRewardConfigDecimalsSelectorShifted) - (mem := setRewardConfigBasePostDecodeMem I baseOut) - (off := 160) (read := 64) - (by - exact le_trans (by omega) - (setRewardConfigBasePostDecodeMem_size_ge160 I hout32 houtSize)) - (by norm_num) - (by - exact lt_of_le_of_lt (Nat.sub_le _ _) - (lt_usize 160 (by norm_num)))] - exact setRewardConfigBasePostDecodeMem_read64 I hout32 houtSize - -theorem setRewardConfigDecimalsPostCallMem_size_ge96 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (hdecSize : decOut.size < UInt256.size) : - 96 ≤ (setRewardConfigDecimalsPostCallMem I baseOut decOut).size := by - unfold setRewardConfigDecimalsPostCallMem - have hbase := setRewardConfigDecimalsCalldataMem_size_ge192 I baseOut - have hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat ≤ decOut.size := - setRewardConfigBasePostCallLen_le_out_size hdecSize - exact le_trans (by omega) - (byteArray_write_size_ge_base_of_le decOut - (setRewardConfigDecimalsCalldataMem I baseOut) hlen (by omega)) - -theorem setRewardConfigDecimalsPostCallMem_read64 - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) - (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigDecimalsPostCallMem I baseOut decOut).readWithPadding 64 32 = - UInt256.toByteArray ⟨160⟩ := by - unfold setRewardConfigDecimalsPostCallMem - by_cases hlen : - (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat = 0 - · rw [hlen, byteArray_write_len_zero] - exact setRewardConfigDecimalsCalldataMem_read64 I hout32 houtSize - · have hsrc : - (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat ≤ decOut.size := - setRewardConfigBasePostCallLen_le_out_size hdecSize - rw [write_read_below_gen_extend decOut (setRewardConfigDecimalsCalldataMem I baseOut) - 160 (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat 64 - hlen hsrc (by - have hbase := setRewardConfigDecimalsCalldataMem_size_ge192 I baseOut - omega) - (by norm_num)] - exact setRewardConfigDecimalsCalldataMem_read64 I hout32 houtSize - -theorem setRewardConfigDecimalsPostCallMem_mload64 - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) - (hdecSize : decOut.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ (setRewardConfigDecimalsPostCallMem I baseOut decOut).size - ∨ (⟨64⟩ : UInt256) ≥ setRewardConfigDecimalsPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigDecimalsPostCallMem I baseOut decOut).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨160⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := setRewardConfigDecimalsPostCallAw) (v := ⟨160⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - have hge := setRewardConfigDecimalsPostCallMem_size_ge96 I (baseOut := baseOut) - (decOut := decOut) hdecSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact setRewardConfigDecimalsPostCallMem_read64 I hout32 houtSize hdecSize) - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_after_baseAccrualScale_decode_ok - {cA gh bl σ σ₀ A I} {g : Sat256} {out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨242⟩ (setRewardConfigBasePostCallStack true I) - (setRewardConfigBasePostCallMem I out) setRewardConfigBasePostCallAw out acc k C) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) - (hbase64 : (setRewardConfigBaseReturnWord out).toNat < EVM.twoPow 64) : - ∃ k' C', RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨256⟩ - (setRewardConfigAfterBaseDecodeStack (setRewardConfigBaseReturnWord out) I) - (setRewardConfigBasePostDecodeMem I out) setRewardConfigBasePostCallAw out acc k' C' := by - let baseWord : UInt256 := setRewardConfigBaseReturnWord out - have hbase64' : baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have rd242 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨242⟩ - [⟨1⟩, setRewardConfigWithMultiplierTokenWord I, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, ⟨128⟩, ⟨64⟩, ⟨0⟩] - (setRewardConfigBasePostCallMem I out) setRewardConfigBasePostCallAw out acc k C := by - simpa [setRewardConfigBasePostCallStack, setRewardConfigBasePostCallTail] using rd - have rd243 := rdSwap9 rd242 (by native_decide) (by simp) - have rd692 := evm_run rd243 with [ - dup10, iszero, push2 ⟨741⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap10, push2 ⟨692⟩, jumpiT (by native_decide) (by jump_dest)] - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hout32 - have rd708₀ := evm_run rd692 with [ - jumpdest, dup4, swap2, swap10, pop, push2 ⟨727⟩, swap1, dup4, - returndatasize, dup6, gt] - have rd708 := rd708₀ - rw [show UInt256.ofNat out.size = rdsz from rfl, hgt] at rd708 - have rd3071 := evm_run rd708 with [ - push2 ⟨734⟩, jumpiNT (by native_decide), - jumpdest, push2 ⟨719⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), - push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigBasePostDecodeMem I out) setRewardConfigBasePostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigBasePostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd3106 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3106⟩, - jump (by jump_dest), jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, - slt, push2 ⟨1004⟩, jumpiNT (by native_decide)] - have rd3129 := evm_run rd3106 with [ - raw mload 0 baseWord setRewardConfigBasePostCallAw (by native_decide) - mem_cost - (by - simpa [baseWord, setRewardConfigBaseReturnWord] using - setRewardConfigBasePostDecodeMem_mload128_of_size_ge I hout32 houtSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, and, dup2, sub] - have hclean : UInt256.land baseWord uint64Mask = baseWord := - uint64Mask_clean hbase64' - have hcleanExpanded : - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = baseWord := by - simpa [uint64Mask] using hclean - have hsub : - UInt256.sub baseWord - (UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) = ⟨0⟩ := by - rw [hcleanExpanded] - exact u256_sub_self baseWord - have rd3129zero := rd3129 - rw [hsub] at rd3129zero - have rd727 := evm_run rd3129zero with [ - push2 ⟨1004⟩, jumpiNT (by native_decide), swap1, jump (by jump_dest)] - have rd728 := evm_run rd727 with [jumpdest] - have rd729 := rdSwap9 rd728 (by native_decide) (by simp) - have rd256 := evm_run rd729 with [swap1, push2 ⟨256⟩, jump (by jump_dest)] - exact ⟨_, _, by - simpa [baseWord, setRewardConfigAfterBaseDecodeStack, - setRewardConfigBaseReturnWord] using rd256⟩ - -noncomputable abbrev setRewardConfigBasePostShortDecodeMem - (I : ExecutionEnv) (out : ByteArray) : ByteArray := - (UInt256.toByteArray ((⟨128⟩ : UInt256) + - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat out.size + ⟨31⟩))).write 0 - (setRewardConfigBasePostCallMem I out) 64 32 - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_after_baseAccrualScale_short_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨242⟩ (setRewardConfigBasePostCallStack true I) - (setRewardConfigBasePostCallMem I out) setRewardConfigBasePostCallAw out acc k C) - (hshort : out.size < 32) (houtSize : out.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨1⟩ := by - apply ugt_one - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hshort - have rd242 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨242⟩ - [⟨1⟩, setRewardConfigWithMultiplierTokenWord I, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, ⟨128⟩, ⟨64⟩, ⟨0⟩] - (setRewardConfigBasePostCallMem I out) setRewardConfigBasePostCallAw out acc k C := by - simpa [setRewardConfigBasePostCallStack, setRewardConfigBasePostCallTail] using rd - have rd243 := rdSwap9 rd242 (by native_decide) (by simp) - have rd692 := evm_run rd243 with [ - dup10, iszero, push2 ⟨741⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap10, push2 ⟨692⟩, jumpiT (by native_decide) (by jump_dest)] - have rd708₀ := evm_run rd692 with [ - jumpdest, dup4, swap2, swap10, pop, push2 ⟨727⟩, swap1, dup4, - returndatasize, dup6, gt] - have rd708 := rd708₀ - rw [show UInt256.ofNat out.size = rdsz from rfl, hgt] at rd708 - let rounded : UInt256 := - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat out.size + ⟨31⟩) - let ptr : UInt256 := (⟨128⟩ : UInt256) + rounded - have hroundedLe : rounded.toNat ≤ out.size + 31 := by - unfold rounded - rw [uland_toNat] - refine le_trans Nat.and_le_right ?_ - rw [uadd_toNat, UInt256.toNat_ofNat_of_lt houtSize, - show (⟨31⟩ : UInt256).toNat = 31 from by decide] - exact Nat.mod_le _ _ - have hptr_toNat : ptr.toNat = 128 + rounded.toNat := by - unfold ptr - rw [uadd_toNat, show (⟨128⟩ : UInt256).toNat = 128 from by decide] - exact Nat.mod_eq_of_lt (by - have hroundSmall : rounded.toNat < 64 := by omega - have hsz : UInt256.size = 2 ^ 256 := by decide - omega) - have hltPtr : UInt256.lt ptr (⟨128⟩ : UInt256) = ⟨0⟩ := by - apply ult_zero - rw [hptr_toNat, show (⟨128⟩ : UInt256).toNat = 128 from by decide] - omega - have hmax64 : - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩).toNat = - 18446744073709551615 := by - native_decide - have hgtPtr : - UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - rw [hptr_toNat, hmax64] - omega - have hallocOk : - UInt256.lor (UInt256.lt ptr (⟨128⟩ : UInt256)) - (UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = ⟨0⟩ := by - rw [hltPtr, hgtPtr] - native_decide - have rd3071 := evm_run rd708 with [ - push2 ⟨734⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, pop, returndatasize, push2 ⟨709⟩, jump (by jump_dest), - jumpdest, push2 ⟨719⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, - jumpiNT (by simpa [ptr, rounded] using hallocOk), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigBasePostShortDecodeMem I out) setRewardConfigBasePostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]) - (by native_decide) (by evm_ov)] - have rd3106 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3106⟩, - jump (by jump_dest)] - have hlenCheck : - UInt256.slt (UInt256.sub ((⟨128⟩ : UInt256) + rdsz) ⟨128⟩) ⟨32⟩ = ⟨1⟩ := by - simpa [rdsz] using solcDecodeEndLenCheckShort_128_32 (len := out.size) hshort - have rd3114₀ := evm_run rd3106 with [ - jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, slt] - have rd3114 := rd3114₀ - rw [hlenCheck] at rd3114 - have rd1004 := evm_run rd3114 with [ - push2 ⟨1004⟩, jumpiT (by native_decide) (by jump_dest)] - exact evm_run rd1004 with [ - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_after_baseAccrualScale_noncanon_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨242⟩ (setRewardConfigBasePostCallStack true I) - (setRewardConfigBasePostCallMem I out) setRewardConfigBasePostCallAw out acc k C) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) - (hbase64 : ¬ (setRewardConfigBaseReturnWord out).toNat < EVM.twoPow 64) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let baseWord : UInt256 := setRewardConfigBaseReturnWord out - have hbase64' : ¬ baseWord.toNat < EVM.twoPow 64 := by - simpa [baseWord] using hbase64 - have rd242 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨242⟩ - [⟨1⟩, setRewardConfigWithMultiplierTokenWord I, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, ⟨128⟩, ⟨64⟩, ⟨0⟩] - (setRewardConfigBasePostCallMem I out) setRewardConfigBasePostCallAw out acc k C := by - simpa [setRewardConfigBasePostCallStack, setRewardConfigBasePostCallTail] using rd - have rd243 := rdSwap9 rd242 (by native_decide) (by simp) - have rd692 := evm_run rd243 with [ - dup10, iszero, push2 ⟨741⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap10, push2 ⟨692⟩, jumpiT (by native_decide) (by jump_dest)] - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hout32 - have rd708₀ := evm_run rd692 with [ - jumpdest, dup4, swap2, swap10, pop, push2 ⟨727⟩, swap1, dup4, - returndatasize, dup6, gt] - have rd708 := rd708₀ - rw [show UInt256.ofNat out.size = rdsz from rfl, hgt] at rd708 - have rd3071 := evm_run rd708 with [ - push2 ⟨734⟩, jumpiNT (by native_decide), - jumpdest, push2 ⟨719⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), - push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigBasePostDecodeMem I out) setRewardConfigBasePostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigBasePostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd3106 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3106⟩, - jump (by jump_dest), jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, - slt, push2 ⟨1004⟩, jumpiNT (by native_decide)] - have rd3129 := evm_run rd3106 with [ - raw mload 0 baseWord setRewardConfigBasePostCallAw (by native_decide) - mem_cost - (by - simpa [baseWord, setRewardConfigBaseReturnWord] using - setRewardConfigBasePostDecodeMem_mload128_of_size_ge I hout32 houtSize) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, and, dup2, sub] - have hnotClean : UInt256.land baseWord uint64Mask ≠ baseWord := - uint64Mask_not_clean hbase64' - have hneq : - baseWord ≠ - UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) := by - intro hEq - exact hnotClean (by simpa [uint64Mask] using hEq.symm) - have hsub : - UInt256.sub baseWord - (UInt256.land baseWord - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) ≠ ⟨0⟩ := - u256_sub_ne_zero_of_ne hneq - have rd1004 := evm_run rd3129 with [ - push2 ⟨1004⟩, jumpiT hsub (by jump_dest)] - exact evm_run rd1004 with [ - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_call_decimals - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut : ByteArray} {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨256⟩ - (setRewardConfigAfterBaseDecodeStack baseWord I) - (setRewardConfigBasePostDecodeMem I baseOut) setRewardConfigBasePostCallAw - baseOut acc k C) - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) : - ∃ gasArg k' C', RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨279⟩ - [gasArg, setRewardConfigDecimalsTargetWord I, ⟨160⟩, ⟨4⟩, ⟨160⟩, - ⟨32⟩, ⟨160⟩, baseWord, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigDecimalsTargetWord I, ⟨64⟩, ⟨0⟩] - (setRewardConfigDecimalsCalldataMem I baseOut) setRewardConfigDecimalsCallAw - baseOut acc k' C' := by - have rd262₀ := evm_run rd with [ - jumpdest, pop, dup3, and, swap8, dup10] - obtain ⟨k262, C262, rd262⟩ : ∃ k262 C262, - RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨262⟩ - [⟨64⟩, baseWord, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigDecimalsTargetWord I, ⟨64⟩, ⟨0⟩] - (setRewardConfigBasePostDecodeMem I baseOut) setRewardConfigBasePostCallAw - baseOut acc k262 C262 := by - exact ⟨_, _, by - simpa [setRewardConfigAfterBaseDecodeStack, setRewardConfigDecimalsTargetWord, - u256_land_comm] using rd262₀⟩ - have rd263 := evm_run rd262 with [ - raw mload 0 ⟨160⟩ setRewardConfigBasePostCallAw (by native_decide) - mem_cost - (setRewardConfigBasePostDecodeMem_mload64 I hout32 houtSize) - (by native_decide) (by evm_ov)] - have rd273 := evm_run rd263 with [ - push4 ⟨826074471⟩, push1 ⟨224⟩, shl, dup2, - raw mstore 3 (setRewardConfigDecimalsCalldataMem I baseOut) - setRewardConfigDecimalsCallAw (by native_decide) mem_cost - (by - rw [show (⟨160⟩ : UInt256).toNat = 160 from by decide] - unfold setRewardConfigDecimalsCalldataMem - rfl) - (by native_decide) (by evm_ov)] - have rd278 := evm_run rd273 with [ - dup3, dup2, dup9, dup2, dup14] - obtain ⟨gasArg, rd279⟩ := evm_run rd278 with [gas] - exact ⟨gasArg, _, _, by simpa [setRewardConfigDecimalsTargetWord] using rd279⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_call_decimals_made - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} - {baseOut : ByteArray} {baseWord : UInt256} - {cA' : Batteries.RBSet AccountAddress compare} {σ'_evm σ'_solm : AccountMap} - {A'_solm : Substate} {k C : ℕ} - (hcanon1 : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hdepth : I.depth.val < 1024) - (hPostAccounts : accountMapEquiv σ'_evm σ'_solm) - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ_evm σ₀ g A I) ⟨256⟩ - (setRewardConfigAfterBaseDecodeStack baseWord I) - (setRewardConfigBasePostDecodeMem I baseOut) setRewardConfigBasePostCallAw - baseOut (cA', σ'_evm) k C) - (hout32 : 32 ≤ baseOut.size) (houtSize : baseOut.size < UInt256.size) : - ∃ cA'' σ''_evm σ''_solm A''_solm z out k' C', - typedCallViaEVM config - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] - (z, - { { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' }, - out) false ∧ - accountMapEquiv σ''_evm σ''_solm ∧ - RD cometRewardsBytecode I g (initState cA gh bl σ_evm σ₀ g A I) ⟨280⟩ - (setRewardConfigDecimalsPostCallStack z baseWord I) - (setRewardConfigDecimalsPostCallMem I baseOut out) setRewardConfigDecimalsPostCallAw - out (cA'', σ''_evm) k' C' ∧ - out.size < 2 ^ 255 := by - obtain ⟨gasArg, k0, C0, rd279⟩ := - cometRewardsSetRewardConfigWithMultiplierX_call_decimals - (rd := rd) hout32 houtSize - have rd279Call : - RD cometRewardsBytecode I g (initState cA gh bl σ_evm σ₀ g A I) ⟨279⟩ - (gasArg :: setRewardConfigDecimalsTargetWord I :: ⟨160⟩ :: ⟨4⟩ :: - ⟨160⟩ :: ⟨32⟩ :: setRewardConfigDecimalsPostCallTail baseWord I) - (setRewardConfigDecimalsCalldataMem I baseOut) setRewardConfigDecimalsCallAw - baseOut (cA', σ'_evm) k0 C0 := by - simpa [setRewardConfigDecimalsPostCallTail] using rd279 - have hdecCall : - decode cometRewardsBytecode (⟨279⟩ : UInt256) = some (.STATICCALL, .none) := by - native_decide - obtain ⟨cA'', σ''_evm, z, out, A_in, callGas, k', C', hΘ, rd280, _houtSize⟩ := - RD.solcStaticcall (t := setRewardConfigDecimalsPostCallTail baseWord I) - rd279Call hdecCall hdepth (by simp [setRewardConfigDecimalsPostCallTail]) - obtain ⟨g'', A''_evm, hΘeq⟩ := hΘ - let evmEBase : EVM.State := - { initState cA gh bl σ_evm σ₀ g A I with - accountMap := σ'_evm - substate := A'_solm - createdAccounts := cA' } - let evmSBase : EVM.State := - { initState cA gh bl σ_solm σ₀ g A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } - have houtSmall : out.size < 2 ^ 138 := by - exact Theta_returnData_size_lt_2pow138_of_eq - (blob := I.blobVersionedHashes) (cA := cA') - (gh := (initState cA gh bl σ_evm σ₀ g A I).genesisBlockHeader) - (blocks := (initState cA gh bl σ_evm σ₀ g A I).blocks) - (σ := σ'_evm) - (σ₀ := (initState cA gh bl σ_evm σ₀ g A I).σ₀) - (A := A_in) - (s := AccountAddress.ofUInt256 (UInt256.ofNat I.codeOwner)) - (o := I.sender) - (r := AccountAddress.ofUInt256 (setRewardConfigDecimalsTargetWord I)) - (c := toExecute σ'_evm - (AccountAddress.ofUInt256 (setRewardConfigDecimalsTargetWord I))) - (g := callGas) (p := UInt256.ofNat I.gasPrice) - (v := ⟨0⟩) (v' := ⟨0⟩) - (d := (setRewardConfigDecimalsCalldataMem I baseOut).readWithPadding 160 4) - (e := I.depth + 1) (H := I.header) (w := false) - hΘeq - (by exact Ethereum.EVM.ByteArray.readWithPadding_size_lt_uint256 _ _ _) - have houtSign : out.size < 2 ^ 255 := by omega - have hdepthNeI : I.depth ≠ 1024 := by - intro hEq - rw [hEq] at hdepth - exact absurd hdepth (by decide) - have hdepthNe : evmEBase.executionEnv.depth ≠ 1024 := by - simpa [evmEBase, initState] using hdepthNeI - have htgt := setRewardConfigDecimalsTarget_eq_targetWord I hcanon1 - have hcd := setRewardConfigDecimalsCalldataMem_encode I baseOut - have hcallE : - typedCallViaEVM config evmEBase - (EVM.address (AccountAddress.ofNat (setRewardConfigWithMultiplierTokenWord I).toNat)) - "decimals" 0 [] - (z, - { evmEBase with - accountMap := σ''_evm - substate := A''_evm - createdAccounts := cA'' }, - out) false := by - refine callCoincides - (cfg := config) (evm := evmEBase) - (name := "decimals") (args := []) - (tgt := EVM.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierTokenWord I).toNat)) - (targetWord := setRewardConfigDecimalsTargetWord I) - (cA' := cA'') (σ' := σ''_evm) (A' := A''_evm) (A_in := A_in) - (z := z) (o := out) (g'' := g'') (callGas := callGas) - (mem := setRewardConfigDecimalsCalldataMem I baseOut) - (inOff := ⟨160⟩) (inSize := ⟨4⟩) (callPerm := false) - hdepthNe htgt hcd ?_ - simpa [evmEBase, initState] using hΘeq - obtain ⟨σ''_solm, A''_solm, hcallSolm, hPostAccounts'⟩ := - typedCallViaEVM_accountMapEquiv - (evm_solm := evmSBase) hcallE - (by simpa [evmEBase, evmSBase, initState] using hPostAccounts) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase]) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase, initState]) - (by simp [evmEBase, evmSBase]) - (by simp [evmEBase, evmSBase, initState]) - exact ⟨cA'', σ''_evm, σ''_solm, A''_solm, z, out, k', C', - by - simpa [evmSBase, initState] using hcallSolm, - hPostAccounts', - by - simpa [setRewardConfigDecimalsPostCallStack, setRewardConfigDecimalsPostCallTail, - setRewardConfigDecimalsPostCallMem, setRewardConfigDecimalsPostCallAw] using rd280, - houtSign⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_after_decimals_failure - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨280⟩ - (setRewardConfigDecimalsPostCallStack false baseWord I) - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C) - (hbase32 : 32 ≤ baseOut.size) (hbaseSize : baseOut.size < UInt256.size) - (hdecSize : decOut.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have rd280 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨280⟩ - [⟨0⟩, ⟨160⟩, baseWord, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigDecimalsTargetWord I, ⟨64⟩, ⟨0⟩] - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C := by - simpa [setRewardConfigDecimalsPostCallStack, setRewardConfigDecimalsPostCallTail] using rd - have rd681 := evm_run rd280 with [ - swap1, dup2, iszero, push2 ⟨681⟩, jumpiT (by native_decide) (by jump_dest)] - have rd682 := evm_run rd681 with [jumpdest] - have rd683 := rdDup12 rd682 (by native_decide) (by simp) - have rd684 := evm_run rd683 with [ - raw mload 0 ⟨160⟩ setRewardConfigDecimalsPostCallAw (by native_decide) - mem_cost - (setRewardConfigDecimalsPostCallMem_mload64 I hbase32 hbaseSize hdecSize) - (by native_decide) (by evm_ov)] - let rdsz : UInt256 := UInt256.ofNat decOut.size - have hrdsz_toNat : rdsz.toNat = decOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hdecSize - have rd688pre := evm_run rd684 with [returndatasize, push1 ⟨0⟩, dup3] - let mem2 : ByteArray := - decOut.write 0 (setRewardConfigDecimalsPostCallMem I baseOut decOut) 160 rdsz.toNat - let aw2 : UInt256 := - UInt256.ofNat (MachineState.M setRewardConfigDecimalsPostCallAw.toNat 160 rdsz.toNat) - have rd688 := RD.returndatacopy - (Cₘ aw2 - Cₘ setRewardConfigDecimalsPostCallAw) mem2 aw2 rd688pre - (by native_decide) - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, hrdsz_toNat]; omega) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, aw2, rdsz] - rw [show (⟨160⟩ : UInt256).toNat = 160 from rfl]) - (by rfl) - (by rfl) - (by simp) - have rd691 := evm_run rd688 with [returndatasize, swap1] - exact RD.rev - (Cₘ (UInt256.ofNat (MachineState.M aw2.toNat 160 rdsz.toNat)) - Cₘ aw2) - rd691 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, rdsz] - rw [show (⟨160⟩ : UInt256).toNat = 160 from rfl]) - (by simp) - -noncomputable abbrev setRewardConfigDecimalsPostShortDecodeMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) : ByteArray := - (UInt256.toByteArray ((⟨160⟩ : UInt256) + - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat decOut.size + ⟨31⟩))).write 0 - (setRewardConfigDecimalsPostCallMem I baseOut decOut) 64 32 - -noncomputable abbrev setRewardConfigDecimalsPostDecodeMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) : ByteArray := - (UInt256.toByteArray (⟨192⟩ : UInt256)).write 0 - (setRewardConfigDecimalsPostCallMem I baseOut decOut) 64 32 - -theorem setRewardConfigDecimalsPostCallMem_read160_of_size_ge - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigDecimalsPostCallMem I baseOut decOut).readWithPadding 160 32 = - decOut.extract 0 32 := by - unfold setRewardConfigDecimalsPostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := decOut.size) - (by decide) hdec32 hdecSize - rw [hlen] - rw [write32_read_back decOut (setRewardConfigDecimalsCalldataMem I baseOut) 160 - (by exact hdec32) - (by - have hbase := setRewardConfigDecimalsCalldataMem_size_ge192 I baseOut - omega)] - -theorem setRewardConfigDecimalsPostCallMem_size_ge192 - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 192 ≤ (setRewardConfigDecimalsPostCallMem I baseOut decOut).size := by - unfold setRewardConfigDecimalsPostCallMem - have hbase := setRewardConfigDecimalsCalldataMem_size_ge192 I baseOut - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat decOut.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := decOut.size) - (by decide) hdec32 hdecSize - rw [hlen] - exact le_trans hbase - (byteArray_write_size_ge_base_of_le decOut - (setRewardConfigDecimalsCalldataMem I baseOut) hdec32 (by omega)) - -theorem setRewardConfigDecimalsPostDecodeMem_read160_of_size_ge - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigDecimalsPostDecodeMem I baseOut decOut).readWithPadding 160 32 = - decOut.extract 0 32 := by - unfold setRewardConfigDecimalsPostDecodeMem - rw [write32_read_above (UInt256.toByteArray (⟨192⟩ : UInt256)) - (setRewardConfigDecimalsPostCallMem I baseOut decOut) 64 160 - (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigDecimalsPostCallMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize)) - (by omega) - (by - exact le_trans (by omega) - (setRewardConfigDecimalsPostCallMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize))] - exact setRewardConfigDecimalsPostCallMem_read160_of_size_ge I hdec32 hdecSize - -theorem setRewardConfigDecimalsPostDecodeMem_mload160_of_size_ge - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨160⟩ : UInt256).toNat ≥ - (setRewardConfigDecimalsPostDecodeMem I baseOut decOut).size - ∨ (⟨160⟩ : UInt256) ≥ setRewardConfigDecimalsPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigDecimalsPostDecodeMem I baseOut decOut).readWithPadding - (⟨160⟩ : UInt256).toNat 32))) = - UInt256.ofNat (fromByteArrayBigEndian (decOut.extract 0 32)) := by - exact mloadValue_eq_readWithPadding_of_lt_size - (mem := setRewardConfigDecimalsPostDecodeMem I baseOut decOut) - (aw := setRewardConfigDecimalsPostCallAw) - (off := ⟨160⟩) - (memSize := (setRewardConfigDecimalsPostDecodeMem I baseOut decOut).size) - rfl - (by - rw [show (⟨160⟩ : UInt256).toNat = 160 from by decide] - unfold setRewardConfigDecimalsPostDecodeMem - rw [write32_eq (UInt256.toByteArray (⟨192⟩ : UInt256)) - (setRewardConfigDecimalsPostCallMem I baseOut decOut) 64 - (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigDecimalsPostCallMem_size_ge192 I hdec32 hdecSize))] - simp - have hsz := setRewardConfigDecimalsPostCallMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize - omega) - (by native_decide) - |>.trans (by - rw [show (⟨160⟩ : UInt256).toNat = 160 from by decide, - setRewardConfigDecimalsPostDecodeMem_read160_of_size_ge I hdec32 hdecSize]) - -theorem setRewardConfigDecimalsPostDecodeMem_mload64_of_size_ge - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ - (setRewardConfigDecimalsPostDecodeMem I baseOut decOut).size - ∨ (⟨64⟩ : UInt256) ≥ setRewardConfigDecimalsPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigDecimalsPostDecodeMem I baseOut decOut).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨192⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := setRewardConfigDecimalsPostCallAw) (v := ⟨192⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigDecimalsPostDecodeMem - rw [write32_eq (UInt256.toByteArray (⟨192⟩ : UInt256)) - (setRewardConfigDecimalsPostCallMem I baseOut decOut) 64 - (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigDecimalsPostCallMem_size_ge192 I hdec32 hdecSize))] - simp - have hsz := setRewardConfigDecimalsPostCallMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigDecimalsPostDecodeMem - rw [write32_read_back _ _ 64 (by rw [toByteArray_size]) - (by - exact le_trans (by omega) - (setRewardConfigDecimalsPostCallMem_size_ge192 I hdec32 hdecSize))] - rw [show (UInt256.toByteArray (⟨192⟩ : UInt256)).extract 0 32 = - UInt256.toByteArray (⟨192⟩ : UInt256) by - rw [show 32 = (UInt256.toByteArray (⟨192⟩ : UInt256)).size by - rw [toByteArray_size]] - exact byteArray_extract_self _]) - -abbrev setRewardConfigDecimalsReturnWord (out : ByteArray) : UInt256 := - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) - -theorem setRewardConfigDecimalsPostDecodeMem_size_ge192 - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 192 ≤ (setRewardConfigDecimalsPostDecodeMem I baseOut decOut).size := by - unfold setRewardConfigDecimalsPostDecodeMem - exact le_trans - (setRewardConfigDecimalsPostCallMem_size_ge192 I (baseOut := baseOut) hdec32 hdecSize) - (byteArray_write_size_ge_base_of_le (UInt256.toByteArray (⟨192⟩ : UInt256)) - (setRewardConfigDecimalsPostCallMem I baseOut decOut) (by rw [toByteArray_size]) - (by - have hbase := - setRewardConfigDecimalsPostCallMem_size_ge192 I (baseOut := baseOut) hdec32 hdecSize - omega)) - -noncomputable def setRewardConfigSuccessFreeMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) : ByteArray := - Reasoning.Theory.writeWord (setRewardConfigDecimalsPostDecodeMem I baseOut decOut) 64 ⟨320⟩ - -noncomputable def setRewardConfigSuccessTokenMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) : ByteArray := - Reasoning.Theory.writeWord (setRewardConfigSuccessFreeMem I baseOut decOut) 192 - (setRewardConfigDecimalsTargetWord I) - -noncomputable def setRewardConfigSuccessRescaleMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale : UInt256) : ByteArray := - Reasoning.Theory.writeWord (setRewardConfigSuccessTokenMem I baseOut decOut) 224 rescale - -noncomputable def setRewardConfigSuccessBitMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale bit : UInt256) : ByteArray := - Reasoning.Theory.writeWord (setRewardConfigSuccessRescaleMem I baseOut decOut rescale) 256 bit - -noncomputable def setRewardConfigSuccessMultiplierMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale bit : UInt256) : ByteArray := - Reasoning.Theory.writeWord (setRewardConfigSuccessBitMem I baseOut decOut rescale bit) 288 - (setRewardConfigWithMultiplierMultiplierWord I) - -noncomputable def setRewardConfigSuccessCometMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale bit : UInt256) : ByteArray := - Reasoning.Theory.writeWord - (setRewardConfigSuccessMultiplierMem I baseOut decOut rescale bit) - 0 (setRewardConfigWithMultiplierCometWord I) - -noncomputable def setRewardConfigSuccessArgsMem - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale bit : UInt256) : ByteArray := - Reasoning.Theory.writeWord - (setRewardConfigSuccessCometMem I baseOut decOut rescale bit) 32 ⟨1⟩ - -theorem setRewardConfigSuccessFreeMem_size_ge192 - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 192 ≤ (setRewardConfigSuccessFreeMem I baseOut decOut).size := by - unfold setRewardConfigSuccessFreeMem Reasoning.Theory.writeWord - have hbase := setRewardConfigDecimalsPostDecodeMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize - exact le_trans hbase - (byteArray_write_size_ge_base_of_le (UInt256.toByteArray (⟨320⟩ : UInt256)) - (setRewardConfigDecimalsPostDecodeMem I baseOut decOut) (by rw [toByteArray_size]) - (by omega)) - -theorem setRewardConfigSuccessTokenMem_size_ge224 - (I : ExecutionEnv) {baseOut decOut : ByteArray} - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 224 ≤ (setRewardConfigSuccessTokenMem I baseOut decOut).size := by - have hfree := setRewardConfigSuccessFreeMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize - unfold setRewardConfigSuccessTokenMem - rw [writeWord_size] - · omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 192 (by norm_num)) - -theorem setRewardConfigSuccessRescaleMem_size_ge256 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 256 ≤ (setRewardConfigSuccessRescaleMem I baseOut decOut rescale).size := by - have htoken := setRewardConfigSuccessTokenMem_size_ge224 I (baseOut := baseOut) - hdec32 hdecSize - unfold setRewardConfigSuccessRescaleMem - rw [writeWord_size] - · omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 224 (by norm_num)) - -theorem setRewardConfigSuccessBitMem_size_ge288 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 288 ≤ (setRewardConfigSuccessBitMem I baseOut decOut rescale bit).size := by - have hrescale := setRewardConfigSuccessRescaleMem_size_ge256 I (baseOut := baseOut) - rescale hdec32 hdecSize - unfold setRewardConfigSuccessBitMem - rw [writeWord_size] - · omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 256 (by norm_num)) - -theorem setRewardConfigSuccessMultiplierMem_size_ge320 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 320 ≤ (setRewardConfigSuccessMultiplierMem I baseOut decOut rescale bit).size := by - have hbit := setRewardConfigSuccessBitMem_size_ge288 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - unfold setRewardConfigSuccessMultiplierMem - rw [writeWord_size] - · omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 288 (by norm_num)) - -theorem setRewardConfigSuccessCometMem_size_ge320 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 320 ≤ (setRewardConfigSuccessCometMem I baseOut decOut rescale bit).size := by - unfold setRewardConfigSuccessCometMem - rw [writeWord_size] - · have hmul := setRewardConfigSuccessMultiplierMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - -theorem setRewardConfigSuccessArgsMem_size_ge320 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - 320 ≤ (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).size := by - unfold setRewardConfigSuccessArgsMem - rw [writeWord_size] - · have hcomet := setRewardConfigSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - -theorem setRewardConfigSuccessArgsMem_read0 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 0 32 = - UInt256.toByteArray (setRewardConfigWithMultiplierCometWord I) := by - unfold setRewardConfigSuccessArgsMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessCometMem - rw [writeWord_read_back] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - · left - have hcomet := setRewardConfigSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - constructor <;> omega - -theorem setRewardConfigSuccessArgsMem_read32 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 32 32 = - UInt256.toByteArray (⟨1⟩ : UInt256) := by - unfold setRewardConfigSuccessArgsMem - rw [writeWord_read_back] - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - -theorem setRewardConfigSuccessArgsMem_read0_64 - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 0 64 = - UInt256.toByteArray (setRewardConfigWithMultiplierCometWord I) ++ - UInt256.toByteArray (⟨1⟩ : UInt256) := by - rw [byteArray_readWithPadding_split _ 0 32 32 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num)] - · rw [setRewardConfigSuccessArgsMem_read0 I rescale bit hdec32 hdecSize, - setRewardConfigSuccessArgsMem_read32 I rescale bit hdec32 hdecSize] - · have hsize := setRewardConfigSuccessArgsMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega - -theorem setRewardConfigSuccessArgsMem_keccakSlot - (I : ExecutionEnv) (baseOut decOut : ByteArray) (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC - ((setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 0 64))) = - solcMappingSlot ⟨1⟩ (setRewardConfigWithMultiplierCometWord I) := by - rw [setRewardConfigSuccessArgsMem_read0_64 I baseOut decOut rescale bit hdec32 hdecSize] - unfold solcMappingSlot - exact mappingSlot_single (setRewardConfigWithMultiplierCometWord I) ⟨1⟩ - -theorem setRewardConfigSuccessArgsMem_read64 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 64 32 = - UInt256.toByteArray (⟨320⟩ : UInt256) := by - unfold setRewardConfigSuccessArgsMem setRewardConfigSuccessCometMem - rw [writeWord_read_preserved, writeWord_read_preserved] - · unfold setRewardConfigSuccessMultiplierMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessBitMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessRescaleMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessTokenMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessFreeMem - rw [writeWord_read_back] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 64 (by norm_num)) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 192 (by norm_num)) - · left - have hfree := setRewardConfigSuccessFreeMem_size_ge192 I (baseOut := baseOut) - hdec32 hdecSize - constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 224 (by norm_num)) - · left - have htoken := setRewardConfigSuccessTokenMem_size_ge224 I (baseOut := baseOut) - hdec32 hdecSize - constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 256 (by norm_num)) - · left - have hrescale := setRewardConfigSuccessRescaleMem_size_ge256 I (baseOut := baseOut) - rescale hdec32 hdecSize - constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 288 (by norm_num)) - · left - have hbit := setRewardConfigSuccessBitMem_size_ge288 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - · right - have hmul := setRewardConfigSuccessMultiplierMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - · right - have hcomet : - 320 ≤ (Reasoning.Theory.writeWord - (setRewardConfigSuccessMultiplierMem I baseOut decOut rescale bit) 0 - (setRewardConfigWithMultiplierCometWord I)).size := by - simpa [setRewardConfigSuccessCometMem] using - setRewardConfigSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - constructor <;> omega - -theorem setRewardConfigSuccessArgsMem_mload64 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ - (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).size - ∨ (⟨64⟩ : UInt256) ≥ (⟨10⟩ : UInt256) * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨320⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := (⟨10⟩ : UInt256)) (v := ⟨320⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - have hsize := setRewardConfigSuccessArgsMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact setRewardConfigSuccessArgsMem_read64 I rescale bit hdec32 hdecSize) - -theorem setRewardConfigSuccessArgsMem_read192 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 192 32 = - UInt256.toByteArray (setRewardConfigDecimalsTargetWord I) := by - have htoken := setRewardConfigSuccessTokenMem_size_ge224 I (baseOut := baseOut) - hdec32 hdecSize - have hrescale := setRewardConfigSuccessRescaleMem_size_ge256 I (baseOut := baseOut) - rescale hdec32 hdecSize - have hbit := setRewardConfigSuccessBitMem_size_ge288 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hmul := setRewardConfigSuccessMultiplierMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hcomet := setRewardConfigSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - unfold setRewardConfigSuccessArgsMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessCometMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessMultiplierMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessBitMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessRescaleMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessTokenMem - rw [writeWord_read_back] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 192 (by norm_num)) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 224 (by norm_num)) - · left; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 256 (by norm_num)) - · left; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 288 (by norm_num)) - · left; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - · right; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - · right; constructor <;> omega - -theorem setRewardConfigSuccessArgsMem_read224 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 224 32 = - UInt256.toByteArray rescale := by - have hrescale := setRewardConfigSuccessRescaleMem_size_ge256 I (baseOut := baseOut) - rescale hdec32 hdecSize - have hbit := setRewardConfigSuccessBitMem_size_ge288 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hmul := setRewardConfigSuccessMultiplierMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hcomet := setRewardConfigSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - unfold setRewardConfigSuccessArgsMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessCometMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessMultiplierMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessBitMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessRescaleMem - rw [writeWord_read_back] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 224 (by norm_num)) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 256 (by norm_num)) - · left; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 288 (by norm_num)) - · left; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - · right; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - · right; constructor <;> omega - -theorem setRewardConfigSuccessArgsMem_read256 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 256 32 = - UInt256.toByteArray bit := by - have hbit := setRewardConfigSuccessBitMem_size_ge288 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hmul := setRewardConfigSuccessMultiplierMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hcomet := setRewardConfigSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - unfold setRewardConfigSuccessArgsMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessCometMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessMultiplierMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessBitMem - rw [writeWord_read_back] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 256 (by norm_num)) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 288 (by norm_num)) - · left; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - · right; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - · right; constructor <;> omega - -theorem setRewardConfigSuccessArgsMem_read288 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding 288 32 = - UInt256.toByteArray (setRewardConfigWithMultiplierMultiplierWord I) := by - have hmul := setRewardConfigSuccessMultiplierMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - have hcomet := setRewardConfigSuccessCometMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - unfold setRewardConfigSuccessArgsMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessCometMem - rw [writeWord_read_preserved] - · unfold setRewardConfigSuccessMultiplierMem - rw [writeWord_read_back] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 288 (by norm_num)) - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 0 (by norm_num)) - · right; constructor <;> omega - · exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_usize 32 (by norm_num)) - · right; constructor <;> omega - -theorem setRewardConfigSuccessArgsMem_mload192 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨192⟩ : UInt256).toNat ≥ - (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).size - ∨ (⟨192⟩ : UInt256) ≥ (⟨10⟩ : UInt256) * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding - (⟨192⟩ : UInt256).toNat 32))) = - setRewardConfigDecimalsTargetWord I := by - exact mloadWordValue_of_readWithPadding - (off := (⟨192⟩ : UInt256)) (aw := (⟨10⟩ : UInt256)) - (v := setRewardConfigDecimalsTargetWord I) - (by - rw [show (⟨192⟩ : UInt256).toNat = 192 from by decide] - have hsize := setRewardConfigSuccessArgsMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega) - (by native_decide) - (by - rw [show (⟨192⟩ : UInt256).toNat = 192 from by decide] - exact setRewardConfigSuccessArgsMem_read192 I rescale bit hdec32 hdecSize) - -theorem setRewardConfigSuccessArgsMem_mload224 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨224⟩ : UInt256).toNat ≥ - (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).size - ∨ (⟨224⟩ : UInt256) ≥ (⟨10⟩ : UInt256) * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding - (⟨224⟩ : UInt256).toNat 32))) = rescale := by - exact mloadWordValue_of_readWithPadding - (off := (⟨224⟩ : UInt256)) (aw := (⟨10⟩ : UInt256)) (v := rescale) - (by - rw [show (⟨224⟩ : UInt256).toNat = 224 from by decide] - have hsize := setRewardConfigSuccessArgsMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega) - (by native_decide) - (by - rw [show (⟨224⟩ : UInt256).toNat = 224 from by decide] - exact setRewardConfigSuccessArgsMem_read224 I rescale bit hdec32 hdecSize) - -theorem setRewardConfigSuccessArgsMem_mload256 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨256⟩ : UInt256).toNat ≥ - (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).size - ∨ (⟨256⟩ : UInt256) ≥ (⟨10⟩ : UInt256) * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding - (⟨256⟩ : UInt256).toNat 32))) = bit := by - exact mloadWordValue_of_readWithPadding - (off := (⟨256⟩ : UInt256)) (aw := (⟨10⟩ : UInt256)) (v := bit) - (by - rw [show (⟨256⟩ : UInt256).toNat = 256 from by decide] - have hsize := setRewardConfigSuccessArgsMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega) - (by native_decide) - (by - rw [show (⟨256⟩ : UInt256).toNat = 256 from by decide] - exact setRewardConfigSuccessArgsMem_read256 I rescale bit hdec32 hdecSize) - -theorem setRewardConfigSuccessArgsMem_mload288 - (I : ExecutionEnv) {baseOut decOut : ByteArray} (rescale bit : UInt256) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) : - (if (⟨288⟩ : UInt256).toNat ≥ - (setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).size - ∨ (⟨288⟩ : UInt256) ≥ (⟨10⟩ : UInt256) * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setRewardConfigSuccessArgsMem I baseOut decOut rescale bit).readWithPadding - (⟨288⟩ : UInt256).toNat 32))) = - setRewardConfigWithMultiplierMultiplierWord I := by - exact mloadWordValue_of_readWithPadding - (off := (⟨288⟩ : UInt256)) (aw := (⟨10⟩ : UInt256)) - (v := setRewardConfigWithMultiplierMultiplierWord I) - (by - rw [show (⟨288⟩ : UInt256).toNat = 288 from by decide] - have hsize := setRewardConfigSuccessArgsMem_size_ge320 I (baseOut := baseOut) - rescale bit hdec32 hdecSize - omega) - (by native_decide) - (by - rw [show (⟨288⟩ : UInt256).toNat = 288 from by decide] - exact setRewardConfigSuccessArgsMem_read288 I rescale bit hdec32 hdecSize) - -private abbrev setRewardConfigAfterDecimalsSafe64BranchPc : UInt256 := - ⟨294⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + - ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + UInt256.ofNat 2 + - ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - UInt256.ofNat 3 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_after_decimals_safe64_prefix - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨280⟩ - (setRewardConfigDecimalsPostCallStack true baseWord I) - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) - (hle77 : (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 2 ^ 64 - 1) - (hbase64 : baseWord.toNat < EVM.twoPow 64) : - ∃ tokenScale k' C', - tokenScale.toNat = (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat ∧ - UInt256.land baseWord (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = baseWord ∧ - UInt256.land - (UInt256.exp (⟨10⟩ : UInt256) - (UInt256.land (⟨255⟩ : UInt256) - (setRewardConfigDecimalsReturnWord decOut))) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = - tokenScale ∧ - UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) - (UInt256.land - (UInt256.exp (⟨10⟩ : UInt256) - (UInt256.land (⟨255⟩ : UInt256) - (setRewardConfigDecimalsReturnWord decOut))) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = - tokenScale ∧ - RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - setRewardConfigAfterDecimalsSafe64BranchPc - [UInt256.gt baseWord tokenScale, baseWord, tokenScale, ⟨32⟩, ⟨1⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, - ((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigDecimalsTargetWord I, ⟨64⟩, ⟨0⟩] - (setRewardConfigDecimalsPostDecodeMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k' C' := by - let decWord : UInt256 := setRewardConfigDecimalsReturnWord decOut - have hdec8' : decWord.toNat < EVM.twoPow 8 := by - simpa [decWord] using hdec8 - have hle77' : decWord.toNat ≤ 77 := by - simpa [decWord] using hle77 - have hsafe64' : (10 : ℕ) ^ decWord.toNat ≤ 2 ^ 64 - 1 := by - simpa [decWord] using hsafe64 - let rdsz : UInt256 := UInt256.ofNat decOut.size - have hrdsz_toNat : rdsz.toNat = decOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hdecSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hdec32 - have rd280 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨280⟩ - [⟨1⟩, ⟨160⟩, baseWord, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigDecimalsTargetWord I, ⟨64⟩, ⟨0⟩] - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C := by - simpa [setRewardConfigDecimalsPostCallStack, setRewardConfigDecimalsPostCallTail] using rd - have rd625₀ := evm_run rd280 with [ - swap1, dup2, iszero, push2 ⟨681⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨618⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, dup4, dup2, dup2, returndatasize, dup4, gt] - have rd625 := rd625₀ - rw [show UInt256.ofNat decOut.size = rdsz from rfl, hgt] at rd625 - have rd3071 := evm_run rd625 with [ - push2 ⟨674⟩, jumpiNT (by native_decide), - jumpdest, push2 ⟨639⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigDecimalsPostDecodeMem I baseOut decOut) - setRewardConfigDecimalsPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigDecimalsPostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd648 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, sub, slt, - push2 ⟨670⟩, jumpiNT (by native_decide)] - have rd656 := evm_run rd648 with [ - raw mload 0 decWord setRewardConfigDecimalsPostCallAw (by native_decide) - mem_cost - (by - simpa [decWord, setRewardConfigDecimalsReturnWord] using - setRewardConfigDecimalsPostDecodeMem_mload160_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap1, push1 ⟨255⟩, dup3, and, dup3, sub] - have hclean : UInt256.land decWord uint8Mask = decWord := - uint8Mask_clean hdec8' - have hsubZero : - UInt256.sub decWord (UInt256.land decWord uint8Mask) = ⟨0⟩ := by - rw [hclean] - exact u256_sub_self decWord - have rd656zero := rd656 - rw [show UInt256.sub decWord (UInt256.land decWord ⟨255⟩) = ⟨0⟩ by - simpa [uint8Mask] using hsubZero] at rd656zero - have rd302 := evm_run rd656zero with [ - push2 ⟨667⟩, jumpiNT (by native_decide), pop, push1 ⟨255⟩, - push2 ⟨294⟩, jump (by jump_dest), jumpdest, pop, push1 ⟨255⟩, and, - push1 ⟨77⟩, dup2, gt] - have hle77Word : - UInt256.gt (UInt256.land (⟨255⟩ : UInt256) decWord) (⟨77⟩ : UInt256) = ⟨0⟩ := by - rw [u256_land_comm (⟨255⟩ : UInt256) decWord] - rw [show UInt256.land decWord ⟨255⟩ = decWord by simpa [uint8Mask] using hclean] - apply ugt_zero - rw [show (⟨77⟩ : UInt256).toNat = 77 from by decide] - exact hle77' - have rd302le := rd302 - rw [hle77Word] at rd302le - let tokenScale : UInt256 := UInt256.exp (⟨10⟩ : UInt256) decWord - have htokenScale_toNat : tokenScale.toNat = (10 : ℕ) ^ decWord.toNat := by - unfold tokenScale - rw [← u256_ofNat_toNat decWord] - interval_cases decWord.toNat <;> native_decide - have rd320 := evm_run rd302le with [ - push2 ⟨597⟩, jumpiNT (by native_decide), push1 ⟨10⟩, exp, - push1 ⟨1⟩, dup1, push1 ⟨64⟩, shl, sub, swap7, dup8, dup3, gt] - have hmax64 : - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩).toNat = - 18446744073709551615 := by - native_decide - have hgtToken : - UInt256.gt tokenScale (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - rw [htokenScale_toNat, hmax64] - exact hsafe64' - have hmaskedDec : UInt256.land (⟨255⟩ : UInt256) decWord = decWord := by - rw [u256_land_comm (⟨255⟩ : UInt256) decWord] - simpa [uint8Mask] using hclean - have rd320le := rd320 - rw [show UInt256.gt (UInt256.exp (⟨10⟩ : UInt256) - (UInt256.land (⟨255⟩ : UInt256) decWord)) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ by - rw [hmaskedDec] - simpa [tokenScale] using hgtToken] at rd320le - have rd337 := evm_run rd320le with [ - push2 ⟨577⟩, jumpiNT (by native_decide), pop, swap1, dup7, dup10, swap4, swap3, - and, swap1, dup2, dup9, dup3, and, gt] - have htokenScale64 : tokenScale.toNat < EVM.twoPow 64 := by - rw [htokenScale_toNat] - have hpow : (10 : ℕ) ^ decWord.toNat < 2 ^ 64 := by omega - simpa [EVM.twoPow] using hpow - have hbaseClean : - UInt256.land baseWord (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = baseWord := by - simpa [uint64Mask] using uint64Mask_clean hbase64 - have htokenClean : - UInt256.land (UInt256.exp (⟨10⟩ : UInt256) (UInt256.land (⟨255⟩ : UInt256) decWord)) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = tokenScale := by - rw [hmaskedDec] - simpa [tokenScale, uint64Mask] using uint64Mask_clean htokenScale64 - have htokenCleanMaskLeft : - UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) tokenScale = - tokenScale := by - rw [u256_land_comm (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) tokenScale] - simpa [uint64Mask] using uint64Mask_clean htokenScale64 - have htokenCleanLeft : - UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) - (UInt256.land - (UInt256.exp (⟨10⟩ : UInt256) (UInt256.land (⟨255⟩ : UInt256) decWord)) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = tokenScale := by - rw [htokenClean] - exact htokenCleanMaskLeft - have rd337clean := rd337 - rw [hbaseClean, htokenClean] at rd337clean - obtain ⟨k337, C337, rd337final⟩ : ∃ k337 C337, - RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - setRewardConfigAfterDecimalsSafe64BranchPc - [UInt256.gt baseWord tokenScale, baseWord, tokenScale, ⟨32⟩, ⟨1⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, - ((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigDecimalsTargetWord I, ⟨64⟩, ⟨0⟩] - (setRewardConfigDecimalsPostDecodeMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k337 C337 := by - exact ⟨_, _, by - simpa [setRewardConfigAfterDecimalsSafe64BranchPc, decWord, tokenScale] using - rd337clean⟩ - refine ⟨tokenScale, k337, C337, ?_⟩ - refine ⟨?_, hbaseClean, ?_, ?_, rd337final⟩ - · simpa [decWord] using htokenScale_toNat - · simpa [decWord] using htokenClean - · simpa [decWord] using htokenCleanLeft - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_after_decimals_noncanon_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨280⟩ - (setRewardConfigDecimalsPostCallStack true baseWord I) - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : ¬ (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let decWord : UInt256 := setRewardConfigDecimalsReturnWord decOut - have hdec8' : ¬ decWord.toNat < EVM.twoPow 8 := by - simpa [decWord] using hdec8 - let rdsz : UInt256 := UInt256.ofNat decOut.size - have hrdsz_toNat : rdsz.toNat = decOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hdecSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hdec32 - have rd280 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨280⟩ - [⟨1⟩, ⟨160⟩, baseWord, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigDecimalsTargetWord I, ⟨64⟩, ⟨0⟩] - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C := by - simpa [setRewardConfigDecimalsPostCallStack, setRewardConfigDecimalsPostCallTail] using rd - have rd625₀ := evm_run rd280 with [ - swap1, dup2, iszero, push2 ⟨681⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨618⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, dup4, dup2, dup2, returndatasize, dup4, gt] - have rd625 := rd625₀ - rw [show UInt256.ofNat decOut.size = rdsz from rfl, hgt] at rd625 - have rd3071 := evm_run rd625 with [ - push2 ⟨674⟩, jumpiNT (by native_decide), - jumpdest, push2 ⟨639⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigDecimalsPostDecodeMem I baseOut decOut) - setRewardConfigDecimalsPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigDecimalsPostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd648 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, sub, slt, - push2 ⟨670⟩, jumpiNT (by native_decide)] - have rd656 := evm_run rd648 with [ - raw mload 0 decWord setRewardConfigDecimalsPostCallAw (by native_decide) - mem_cost - (by - simpa [decWord, setRewardConfigDecimalsReturnWord] using - setRewardConfigDecimalsPostDecodeMem_mload160_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap1, push1 ⟨255⟩, dup3, and, dup3, sub] - have hnotClean : UInt256.land decWord uint8Mask ≠ decWord := - uint8Mask_not_clean hdec8' - have hneq : decWord ≠ UInt256.land decWord uint8Mask := by - intro hEq - exact hnotClean hEq.symm - have hsub : UInt256.sub decWord (UInt256.land decWord uint8Mask) ≠ ⟨0⟩ := - u256_sub_ne_zero_of_ne hneq - have rd667 := evm_run rd656 with [ - push2 ⟨667⟩, jumpiT (by simpa [uint8Mask] using hsub) (by jump_dest)] - exact evm_run rd667 with [jumpdest, dup1, raw rev 0 (by native_decide) mem_cost - (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_after_decimals_pow10_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨280⟩ - (setRewardConfigDecimalsPostCallStack true baseWord I) - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) - (hgt77 : 77 < (setRewardConfigDecimalsReturnWord decOut).toNat) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let decWord : UInt256 := setRewardConfigDecimalsReturnWord decOut - have hdec8' : decWord.toNat < EVM.twoPow 8 := by - simpa [decWord] using hdec8 - have hgt77' : 77 < decWord.toNat := by - simpa [decWord] using hgt77 - let rdsz : UInt256 := UInt256.ofNat decOut.size - have hrdsz_toNat : rdsz.toNat = decOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hdecSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hdec32 - have rd280 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨280⟩ - [⟨1⟩, ⟨160⟩, baseWord, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigDecimalsTargetWord I, ⟨64⟩, ⟨0⟩] - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C := by - simpa [setRewardConfigDecimalsPostCallStack, setRewardConfigDecimalsPostCallTail] using rd - have rd625₀ := evm_run rd280 with [ - swap1, dup2, iszero, push2 ⟨681⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨618⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, dup4, dup2, dup2, returndatasize, dup4, gt] - have rd625 := rd625₀ - rw [show UInt256.ofNat decOut.size = rdsz from rfl, hgt] at rd625 - have rd3071 := evm_run rd625 with [ - push2 ⟨674⟩, jumpiNT (by native_decide), - jumpdest, push2 ⟨639⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigDecimalsPostDecodeMem I baseOut decOut) - setRewardConfigDecimalsPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigDecimalsPostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd648 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, sub, slt, - push2 ⟨670⟩, jumpiNT (by native_decide)] - have rd656 := evm_run rd648 with [ - raw mload 0 decWord setRewardConfigDecimalsPostCallAw (by native_decide) - mem_cost - (by - simpa [decWord, setRewardConfigDecimalsReturnWord] using - setRewardConfigDecimalsPostDecodeMem_mload160_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap1, push1 ⟨255⟩, dup3, and, dup3, sub] - have hclean : UInt256.land decWord uint8Mask = decWord := - uint8Mask_clean hdec8' - have hsubZero : - UInt256.sub decWord (UInt256.land decWord uint8Mask) = ⟨0⟩ := by - rw [hclean] - exact u256_sub_self decWord - have rd656zero := rd656 - rw [show UInt256.sub decWord (UInt256.land decWord ⟨255⟩) = ⟨0⟩ by - simpa [uint8Mask] using hsubZero] at rd656zero - have rd302 := evm_run rd656zero with [ - push2 ⟨667⟩, jumpiNT (by native_decide), pop, push1 ⟨255⟩, - push2 ⟨294⟩, jump (by jump_dest), jumpdest, pop, push1 ⟨255⟩, and, - push1 ⟨77⟩, dup2, gt] - have hgt77Word : - UInt256.gt (UInt256.land (⟨255⟩ : UInt256) decWord) (⟨77⟩ : UInt256) = ⟨1⟩ := by - rw [u256_land_comm (⟨255⟩ : UInt256) decWord] - rw [show UInt256.land decWord ⟨255⟩ = decWord by simpa [uint8Mask] using hclean] - apply ugt_one - rw [show (⟨77⟩ : UInt256).toNat = 77 from by decide] - exact hgt77' - have rd302gt := rd302 - rw [hgt77Word] at rd302gt - have rd597 := evm_run rd302gt with [ - push2 ⟨597⟩, jumpiT (by native_decide) (by jump_dest)] - have hsel : - UInt256.shiftLeft (⟨0x4e487b71⟩ : UInt256) ⟨224⟩ = - setRewardConfigPanicSelector := by - rfl - have rd611₀ := evm_run rd597 with [ - jumpdest, push1 ⟨17⟩, dup8, push4 ⟨0x4e487b71⟩, push1 ⟨224⟩, shl, - push1 ⟨0⟩] - have rd611 := rd611₀ - rw [hsel] at rd611 - have rd612 := evm_run rd611 with [ - raw mstore 0 (setRewardConfigPanicMem0 (setRewardConfigDecimalsPostDecodeMem I baseOut decOut)) - setRewardConfigDecimalsPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov)] - have rd613 := evm_run rd612 with [ - raw mstore 0 - (setRewardConfigPanicMem ⟨17⟩ (setRewardConfigDecimalsPostDecodeMem I baseOut decOut)) - setRewardConfigDecimalsPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov), - push1 ⟨36⟩, push1 ⟨0⟩] - exact evm_run rd613 with [raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 3000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_after_decimals_safe64_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨280⟩ - (setRewardConfigDecimalsPostCallStack true baseWord I) - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) - (hle77 : (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 77) - (hgt64 : 2 ^ 64 - 1 < (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let decWord : UInt256 := setRewardConfigDecimalsReturnWord decOut - have hdec8' : decWord.toNat < EVM.twoPow 8 := by - simpa [decWord] using hdec8 - have hle77' : decWord.toNat ≤ 77 := by - simpa [decWord] using hle77 - have hgt64' : 2 ^ 64 - 1 < (10 : ℕ) ^ decWord.toNat := by - simpa [decWord] using hgt64 - let rdsz : UInt256 := UInt256.ofNat decOut.size - have hrdsz_toNat : rdsz.toNat = decOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hdecSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hdec32 - have rd280 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨280⟩ - [⟨1⟩, ⟨160⟩, baseWord, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigDecimalsTargetWord I, ⟨64⟩, ⟨0⟩] - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C := by - simpa [setRewardConfigDecimalsPostCallStack, setRewardConfigDecimalsPostCallTail] using rd - have rd625₀ := evm_run rd280 with [ - swap1, dup2, iszero, push2 ⟨681⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨618⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, dup4, dup2, dup2, returndatasize, dup4, gt] - have rd625 := rd625₀ - rw [show UInt256.ofNat decOut.size = rdsz from rfl, hgt] at rd625 - have rd3071 := evm_run rd625 with [ - push2 ⟨674⟩, jumpiNT (by native_decide), - jumpdest, push2 ⟨639⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigDecimalsPostDecodeMem I baseOut decOut) - setRewardConfigDecimalsPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigDecimalsPostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd648 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, sub, slt, - push2 ⟨670⟩, jumpiNT (by native_decide)] - have rd656 := evm_run rd648 with [ - raw mload 0 decWord setRewardConfigDecimalsPostCallAw (by native_decide) - mem_cost - (by - simpa [decWord, setRewardConfigDecimalsReturnWord] using - setRewardConfigDecimalsPostDecodeMem_mload160_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap1, push1 ⟨255⟩, dup3, and, dup3, sub] - have hclean : UInt256.land decWord uint8Mask = decWord := - uint8Mask_clean hdec8' - have hsubZero : - UInt256.sub decWord (UInt256.land decWord uint8Mask) = ⟨0⟩ := by - rw [hclean] - exact u256_sub_self decWord - have rd656zero := rd656 - rw [show UInt256.sub decWord (UInt256.land decWord ⟨255⟩) = ⟨0⟩ by - simpa [uint8Mask] using hsubZero] at rd656zero - have rd302 := evm_run rd656zero with [ - push2 ⟨667⟩, jumpiNT (by native_decide), pop, push1 ⟨255⟩, - push2 ⟨294⟩, jump (by jump_dest), jumpdest, pop, push1 ⟨255⟩, and, - push1 ⟨77⟩, dup2, gt] - have hle77Word : - UInt256.gt (UInt256.land (⟨255⟩ : UInt256) decWord) (⟨77⟩ : UInt256) = ⟨0⟩ := by - rw [u256_land_comm (⟨255⟩ : UInt256) decWord] - rw [show UInt256.land decWord ⟨255⟩ = decWord by simpa [uint8Mask] using hclean] - apply ugt_zero - rw [show (⟨77⟩ : UInt256).toNat = 77 from by decide] - exact hle77' - have rd302le := rd302 - rw [hle77Word] at rd302le - let tokenScale : UInt256 := UInt256.exp (⟨10⟩ : UInt256) decWord - have hpowBound : (10 : ℕ) ^ decWord.toNat < UInt256.size := by - have hpowLe : (10 : ℕ) ^ decWord.toNat ≤ 10 ^ 77 := - Nat.pow_le_pow_right (by norm_num) hle77' - exact lt_of_le_of_lt hpowLe (by norm_num [UInt256.size]) - have htokenScale_toNat : tokenScale.toNat = (10 : ℕ) ^ decWord.toNat := by - unfold tokenScale - rw [← u256_ofNat_toNat decWord] - interval_cases decWord.toNat <;> native_decide - have rd320 := evm_run rd302le with [ - push2 ⟨597⟩, jumpiNT (by native_decide), push1 ⟨10⟩, exp, - push1 ⟨1⟩, dup1, push1 ⟨64⟩, shl, sub, swap7, dup8, dup3, gt] - have hmax64 : - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩).toNat = - 18446744073709551615 := by - native_decide - have hgtToken : - UInt256.gt tokenScale (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨1⟩ := by - apply ugt_one - rw [htokenScale_toNat, hmax64] - exact hgt64' - have hmaskedDec : UInt256.land (⟨255⟩ : UInt256) decWord = decWord := by - rw [u256_land_comm (⟨255⟩ : UInt256) decWord] - simpa [uint8Mask] using hclean - have rd320gt := rd320 - rw [show UInt256.gt (UInt256.exp (⟨10⟩ : UInt256) - (UInt256.land (⟨255⟩ : UInt256) decWord)) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨1⟩ by - rw [hmaskedDec] - simpa [tokenScale] using hgtToken] at rd320gt - have rd577 := evm_run rd320gt with [ - push2 ⟨577⟩, jumpiT (by native_decide) (by jump_dest)] - have hsel : - UInt256.shiftLeft (⟨0x4809a3⟩ : UInt256) ⟨226⟩ = - setRewardConfigInvalidUInt64Selector := by - rfl - have rd582 := evm_run rd577 with [ - jumpdest, push1 ⟨36⟩, swap2, dup13] - have rd583 := evm_run rd582 with [ - raw mload 0 ⟨192⟩ setRewardConfigDecimalsPostCallAw (by native_decide) mem_cost - (setRewardConfigDecimalsPostDecodeMem_mload64_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov)] - have rd584 := evm_run rd583 with [ - swap2] - have rd588 := rd584.pushConst (⟨0x4809a3⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) (by native_decide) (by evm_ov) - have rd592₀ := evm_run rd588 with [ - push1 ⟨226⟩, shl, dup4] - have rd592 := rd592₀ - rw [hsel] at rd592 - let awInvalidSelector : UInt256 := - UInt256.ofNat (MachineState.M setRewardConfigDecimalsPostCallAw.toNat - (⟨192⟩ : UInt256).toNat 32) - let awInvalidArg : UInt256 := - UInt256.ofNat (MachineState.M awInvalidSelector.toNat - ((⟨192⟩ : UInt256) + ⟨4⟩).toNat 32) - have rd593 := evm_run rd592 with [ - raw mstore (Cₘ awInvalidSelector - Cₘ setRewardConfigDecimalsPostCallAw) - (setRewardConfigInvalidUInt64SelectorMem - (setRewardConfigDecimalsPostDecodeMem I baseOut decOut)) - awInvalidSelector (by native_decide) mem_cost - (by unfold setRewardConfigInvalidUInt64SelectorMem; rfl) - (by rfl) (by evm_ov)] - have rd596 := evm_run rd593 with [ - dup3, add, - raw mstore (Cₘ awInvalidArg - Cₘ awInvalidSelector) - (setRewardConfigInvalidUInt64Mem tokenScale - (setRewardConfigDecimalsPostDecodeMem I baseOut decOut)) - awInvalidArg (by native_decide) mem_cost - (by - unfold setRewardConfigInvalidUInt64Mem setRewardConfigInvalidUInt64SelectorMem tokenScale - rw [hmaskedDec] - rw [show ((⟨192⟩ : UInt256) + ⟨4⟩).toNat = 196 from by native_decide]) - (by rfl) (by evm_ov)] - exact evm_run rd596 with [raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_after_decimals_short_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨280⟩ - (setRewardConfigDecimalsPostCallStack true baseWord I) - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C) - (hshort : decOut.size < 32) - (hdecSize : decOut.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let rdsz : UInt256 := UInt256.ofNat decOut.size - have hrdsz_toNat : rdsz.toNat = decOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hdecSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨1⟩ := by - apply ugt_one - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hshort - have rd280 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨280⟩ - [⟨1⟩, ⟨160⟩, baseWord, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigDecimalsTargetWord I, ⟨64⟩, ⟨0⟩] - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C := by - simpa [setRewardConfigDecimalsPostCallStack, setRewardConfigDecimalsPostCallTail] using rd - have rd625₀ := evm_run rd280 with [ - swap1, dup2, iszero, push2 ⟨681⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨618⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, dup4, dup2, dup2, returndatasize, dup4, gt] - have rd625 := rd625₀ - rw [show UInt256.ofNat decOut.size = rdsz from rfl, hgt] at rd625 - let rounded : UInt256 := - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat decOut.size + ⟨31⟩) - let ptr : UInt256 := (⟨160⟩ : UInt256) + rounded - have hroundedLe : rounded.toNat ≤ decOut.size + 31 := by - unfold rounded - rw [uland_toNat] - refine le_trans Nat.and_le_right ?_ - rw [uadd_toNat, UInt256.toNat_ofNat_of_lt hdecSize, - show (⟨31⟩ : UInt256).toNat = 31 from by decide] - exact Nat.mod_le _ _ - have hptr_toNat : ptr.toNat = 160 + rounded.toNat := by - unfold ptr - rw [uadd_toNat, show (⟨160⟩ : UInt256).toNat = 160 from by decide] - exact Nat.mod_eq_of_lt (by - have hroundSmall : rounded.toNat < 64 := by omega - have hsz : UInt256.size = 2 ^ 256 := by decide - omega) - have hltPtr : UInt256.lt ptr (⟨160⟩ : UInt256) = ⟨0⟩ := by - apply ult_zero - rw [hptr_toNat, show (⟨160⟩ : UInt256).toNat = 160 from by decide] - omega - have hmax64 : - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩).toNat = - 18446744073709551615 := by - native_decide - have hgtPtr : - UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - rw [hptr_toNat, hmax64] - omega - have hallocOk : - UInt256.lor (UInt256.lt ptr (⟨160⟩ : UInt256)) - (UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = ⟨0⟩ := by - rw [hltPtr, hgtPtr] - native_decide - have rd3071 := evm_run rd625 with [ - push2 ⟨674⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, pop, returndatasize, push2 ⟨629⟩, jump (by jump_dest), - jumpdest, push2 ⟨639⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, - jumpiNT (by simpa [ptr, rounded] using hallocOk), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigDecimalsPostShortDecodeMem I baseOut decOut) - setRewardConfigDecimalsPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]) - (by native_decide) (by evm_ov)] - have rd639 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest] - have hlenCheck : - UInt256.slt (UInt256.sub ((⟨160⟩ : UInt256) + rdsz) ⟨160⟩) ⟨32⟩ = ⟨1⟩ := by - simpa [rdsz] using - solcReturnStaticLenCheckShort (base := 160) (words := 1) (by simpa using hshort) - (by norm_num [UInt256.size]) - (by - have hcap : (2 : ℕ) ^ 255 + 160 < UInt256.size := by norm_num [UInt256.size] - have hhi : decOut.size < 2 ^ 255 := by omega - omega) - (by norm_num) - have rd644₀ := evm_run rd639 with [ - dup2, add, sub, slt] - have rd644 := rd644₀ - rw [hlenCheck] at rd644 - have rd670 := evm_run rd644 with [ - push2 ⟨670⟩, jumpiT (by native_decide) (by jump_dest)] - exact evm_run rd670 with [jumpdest, pop, dup1, raw rev 0 (by native_decide) mem_cost - (by evm_ov)] - -set_option maxHeartbeats 2000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_after_decimals_downscale_success - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord rescale : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨280⟩ - (setRewardConfigDecimalsPostCallStack true baseWord I) - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C) - (hperm : I.perm = true) - (hcanon0 : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) - (hle77 : (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 2 ^ 64 - 1) - (hbase64 : baseWord.toNat < EVM.twoPow 64) - (hdown : (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat < baseWord.toNat) - (hrescale : rescale.toNat = - baseWord.toNat / (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat) : - RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) - (acc.1, - sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner acc.2 (setRewardConfigWithMultiplierSlotOf I) - (setRewardConfigSlot0Down - (solcSlotWord acc.2 I (setRewardConfigWithMultiplierSlotOf I)) - (setRewardConfigWithMultiplierTokenWord I) rescale)) - (setRewardConfigWithMultiplierSlotOf I + ⟨1⟩) - (setRewardConfigWithMultiplierMultiplierWord I)) - ByteArray.empty := by - let decWord : UInt256 := setRewardConfigDecimalsReturnWord decOut - have hdec8' : decWord.toNat < EVM.twoPow 8 := by - simpa [decWord] using hdec8 - have hle77' : decWord.toNat ≤ 77 := by - simpa [decWord] using hle77 - have hsafe64' : (10 : ℕ) ^ decWord.toNat ≤ 2 ^ 64 - 1 := by - simpa [decWord] using hsafe64 - have hdown' : (10 : ℕ) ^ decWord.toNat < baseWord.toNat := by - simpa [decWord] using hdown - have hrescale' : rescale.toNat = baseWord.toNat / (10 : ℕ) ^ decWord.toNat := by - simpa [decWord] using hrescale - let rdsz : UInt256 := UInt256.ofNat decOut.size - have hrdsz_toNat : rdsz.toNat = decOut.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt hdecSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hdec32 - have rd280 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨280⟩ - [⟨1⟩, ⟨160⟩, baseWord, ⟨32⟩, solcAddrMask, - setRewardConfigWithMultiplierCometWord I, ⟨224⟩, ⟨4⟩, - setRewardConfigWithMultiplierMultiplierWord I, ⟨1⟩, - setRewardConfigDecimalsTargetWord I, ⟨64⟩, ⟨0⟩] - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C := by - simpa [setRewardConfigDecimalsPostCallStack, setRewardConfigDecimalsPostCallTail] using rd - have rd625₀ := evm_run rd280 with [ - swap1, dup2, iszero, push2 ⟨681⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨618⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, dup4, dup2, dup2, returndatasize, dup4, gt] - have rd625 := rd625₀ - rw [show UInt256.ofNat decOut.size = rdsz from rfl, hgt] at rd625 - have rd3071 := evm_run rd625 with [ - push2 ⟨674⟩, jumpiNT (by native_decide), - jumpdest, push2 ⟨639⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, - add, swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, - swap1, dup3, lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (setRewardConfigDecimalsPostDecodeMem I baseOut decOut) - setRewardConfigDecimalsPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold setRewardConfigDecimalsPostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd648 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, sub, slt, - push2 ⟨670⟩, jumpiNT (by native_decide)] - have rd656 := evm_run rd648 with [ - raw mload 0 decWord setRewardConfigDecimalsPostCallAw (by native_decide) - mem_cost - (by - simpa [decWord, setRewardConfigDecimalsReturnWord] using - setRewardConfigDecimalsPostDecodeMem_mload160_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap1, push1 ⟨255⟩, dup3, and, dup3, sub] - have hclean : UInt256.land decWord uint8Mask = decWord := - uint8Mask_clean hdec8' - have hsubZero : - UInt256.sub decWord (UInt256.land decWord uint8Mask) = ⟨0⟩ := by - rw [hclean] - exact u256_sub_self decWord - have rd656zero := rd656 - rw [show UInt256.sub decWord (UInt256.land decWord ⟨255⟩) = ⟨0⟩ by - simpa [uint8Mask] using hsubZero] at rd656zero - have rd302 := evm_run rd656zero with [ - push2 ⟨667⟩, jumpiNT (by native_decide), pop, push1 ⟨255⟩, - push2 ⟨294⟩, jump (by jump_dest), jumpdest, pop, push1 ⟨255⟩, and, - push1 ⟨77⟩, dup2, gt] - have hle77Word : - UInt256.gt (UInt256.land (⟨255⟩ : UInt256) decWord) (⟨77⟩ : UInt256) = ⟨0⟩ := by - rw [u256_land_comm (⟨255⟩ : UInt256) decWord] - rw [show UInt256.land decWord ⟨255⟩ = decWord by simpa [uint8Mask] using hclean] - apply ugt_zero - rw [show (⟨77⟩ : UInt256).toNat = 77 from by decide] - exact hle77' - have rd302le := rd302 - rw [hle77Word] at rd302le - let tokenScale : UInt256 := UInt256.exp (⟨10⟩ : UInt256) decWord - have htokenScale_toNat : tokenScale.toNat = (10 : ℕ) ^ decWord.toNat := by - unfold tokenScale - rw [← u256_ofNat_toNat decWord] - interval_cases decWord.toNat <;> native_decide - have rd320 := evm_run rd302le with [ - push2 ⟨597⟩, jumpiNT (by native_decide), push1 ⟨10⟩, exp, - push1 ⟨1⟩, dup1, push1 ⟨64⟩, shl, sub, swap7, dup8, dup3, gt] - have hmax64 : - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩).toNat = - 18446744073709551615 := by - native_decide - have hgtToken : - UInt256.gt tokenScale (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - rw [htokenScale_toNat, hmax64] - exact hsafe64' - have hmaskedDec : UInt256.land (⟨255⟩ : UInt256) decWord = decWord := by - rw [u256_land_comm (⟨255⟩ : UInt256) decWord] - simpa [uint8Mask] using hclean - have rd320le := rd320 - rw [show UInt256.gt (UInt256.exp (⟨10⟩ : UInt256) - (UInt256.land (⟨255⟩ : UInt256) decWord)) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ by - rw [hmaskedDec] - simpa [tokenScale] using hgtToken] at rd320le - have rd337 := evm_run rd320le with [ - push2 ⟨577⟩, jumpiNT (by native_decide), pop, swap1, dup7, dup10, swap4, swap3, - and, swap1, dup2, dup9, dup3, and, gt] - have htokenScale64 : tokenScale.toNat < EVM.twoPow 64 := by - rw [htokenScale_toNat] - have hpow : (10 : ℕ) ^ decWord.toNat < 2 ^ 64 := by omega - simpa [EVM.twoPow] using hpow - have hbaseClean : - UInt256.land baseWord (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = baseWord := by - simpa [uint64Mask] using uint64Mask_clean hbase64 - have htokenClean : - UInt256.land (UInt256.exp (⟨10⟩ : UInt256) (UInt256.land (⟨255⟩ : UInt256) decWord)) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = tokenScale := by - rw [hmaskedDec] - simpa [tokenScale, uint64Mask] using uint64Mask_clean htokenScale64 - have htokenCleanMaskLeft : - UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) tokenScale = - tokenScale := by - rw [u256_land_comm (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) tokenScale] - simpa [uint64Mask] using uint64Mask_clean htokenScale64 - have htokenCleanLeft : - UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) - (UInt256.land - (UInt256.exp (⟨10⟩ : UInt256) (UInt256.land (⟨255⟩ : UInt256) decWord)) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = tokenScale := by - rw [htokenClean] - exact htokenCleanMaskLeft - have hdownWord : - UInt256.gt - (UInt256.land baseWord (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) - (UInt256.land - (UInt256.exp (⟨10⟩ : UInt256) (UInt256.land (⟨255⟩ : UInt256) decWord)) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = ⟨1⟩ := by - rw [hbaseClean, htokenClean] - apply ugt_one - rw [htokenScale_toNat] - exact hdown' - have htokenNZ : tokenScale ≠ ⟨0⟩ := by - intro hzero - have hto := congrArg UInt256.toNat hzero - rw [htokenScale_toNat, show (⟨0⟩ : UInt256).toNat = 0 from rfl] at hto - have hpos : 0 < (10 : ℕ) ^ decWord.toNat := by positivity - omega - have hrescaleWord : - UInt256.div baseWord tokenScale = rescale := by - apply u256_inj - rw [udiv_toNat, htokenScale_toNat, hrescale'] - have hrescale64 : rescale.toNat < EVM.twoPow 64 := by - rw [hrescale'] - have hdiv := Nat.div_le_self baseWord.toNat ((10 : ℕ) ^ decWord.toNat) - have hbase64' : baseWord.toNat < 2 ^ 64 := by - simpa [EVM.twoPow] using hbase64 - simpa [EVM.twoPow] using lt_of_le_of_lt hdiv hbase64' - have hrescaleClean : - UInt256.land rescale (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = rescale := by - simpa [uint64Mask] using uint64Mask_clean hrescale64 - have rd337down := rd337 - rw [hdownWord] at rd337down - have rd354 := evm_run rd337down with [ - push1 ⟨0⟩, eq, push2 ⟨466⟩, jumpiNT (by native_decide), - swap1, push2 ⟨354⟩, swap2, push2 ⟨3137⟩, jump (by jump_dest), - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap2, dup3, and, - swap2, swap1, dup3, iszero] - rw [show UInt256.isZero - (UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) - (UInt256.land - (UInt256.exp (⟨10⟩ : UInt256) (UInt256.land (⟨255⟩ : UInt256) decWord)) - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩))) = ⟨0⟩ by - rw [htokenCleanLeft] - exact isZero_eq_zero_of_ne htokenNZ] at rd354 - have rd354ret := evm_run rd354 with [ - push2 ⟨3161⟩, jumpiNT (by native_decide), and, div, swap1, jump (by jump_dest), - jumpdest] - rw [hbaseClean, htokenCleanLeft, hrescaleWord] at rd354ret - have rd354rescale := rd354ret - have rd367pre := evm_run rd354rescale with [ - swap6, dup11, - raw mload 0 ⟨192⟩ setRewardConfigDecimalsPostCallAw (by native_decide) - mem_cost - (setRewardConfigDecimalsPostDecodeMem_mload64_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap10, push2 ⟨367⟩] - have rd367arg := rdDup12 rd367pre (by native_decide) (by simp) - have rd367 := evm_run rd367arg with [ - push2 ⟨3025⟩, jump (by jump_dest), - jumpdest, push1 ⟨128⟩, dup2, add, swap1, dup2, lt, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, lor, - push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩, - raw mstore 0 (setRewardConfigSuccessFreeMem I baseOut decOut) - setRewardConfigDecimalsPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigSuccessFreeMem Reasoning.Theory.writeWord; rfl) - (by native_decide) (by evm_ov), - jump (by jump_dest), jumpdest] - have rd369 := evm_run rd367 with [ - dup11, - raw mstore 3 (setRewardConfigSuccessTokenMem I baseOut decOut) - (⟨7⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigSuccessTokenMem; rfl) - (by native_decide) (by evm_ov)] - have rd372 := evm_run rd369 with [swap1, swap6, and] - rw [hrescaleClean] at rd372 - have rd378 := evm_run rd372 with [ - dup6, dup10, add, swap1, dup2, - raw mstore 3 (setRewardConfigSuccessRescaleMem I baseOut decOut rescale) - (⟨8⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigSuccessRescaleMem; rfl) - (by native_decide) (by evm_ov)] - have rd386 := evm_run rd378 with [ - push1 ⟨0⟩, dup11, dup11, add, dup2, dup2, - raw mstore 3 (setRewardConfigSuccessBitMem I baseOut decOut rescale ⟨0⟩) - (⟨9⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigSuccessBitMem; rfl) - (by native_decide) (by evm_ov)] - have rd389pre := evm_run rd386 with [push1 ⟨96⟩] - have rd390arg := rdDup12 rd389pre (by native_decide) (by simp) - have rd391 := evm_run rd390arg with [add] - have rd392 := rdSwap9 rd391 (by native_decide) (by simp) - have rd393 := evm_run rd392 with [ - dup10, - raw mstore 3 (setRewardConfigSuccessMultiplierMem I baseOut decOut rescale ⟨0⟩) - (⟨10⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigSuccessMultiplierMem; rfl) - (by native_decide) (by evm_ov)] - have rd397 := evm_run rd393 with [ - swap5, dup2, - raw mstore 0 (setRewardConfigSuccessCometMem I baseOut decOut rescale ⟨0⟩) - (⟨10⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigSuccessCometMem; rfl) - (by native_decide) (by evm_ov)] - have rd401 := evm_run rd397 with [ - swap2, swap1, swap6, - raw mstore 0 (setRewardConfigSuccessArgsMem I baseOut decOut rescale ⟨0⟩) - (⟨10⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigSuccessArgsMem; rfl) - (by native_decide) (by evm_ov)] - have hslot := setRewardConfigWithMultiplierSlotOf_eq_solc I hcanon0 - have hkeccak := - setRewardConfigSuccessArgsMem_keccakSlot I baseOut decOut rescale ⟨0⟩ hdec32 hdecSize - have rd404pre := evm_run rd401 with [dup9, swap1] - have rd404₀ := rd404pre.keccak256 0 - (solcMappingSlot ⟨1⟩ (setRewardConfigWithMultiplierCometWord I)) - (⟨10⟩ : UInt256) (by native_decide) mem_cost hkeccak (by native_decide) (by evm_ov) - have rd404 := rd404₀ - rw [← hslot] at rd404 - have rd406 := evm_run rd404 with [ - swap7, - raw mload 0 (setRewardConfigDecimalsTargetWord I) (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigSuccessArgsMem_mload192 I rescale ⟨0⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - dup8] - obtain ⟨_, _, rd408⟩ := rd406.sload (by native_decide) (by evm_ov) - have rd412 := evm_run rd408 with [ - swap5, - raw mload 0 rescale (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigSuccessArgsMem_mload224 I rescale ⟨0⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap3, - raw mload 0 (⟨0⟩ : UInt256) (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigSuccessArgsMem_mload256 I rescale ⟨0⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov)] - have rd459 := evm_run rd412 with [ - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨232⟩, shl, sub, not, swap1, swap6, and, - swap2, and, lor, push1 ⟨160⟩, swap2, swap1, swap2, shl, - push1 ⟨1⟩, push1 ⟨160⟩, shl, push1 ⟨1⟩, push1 ⟨224⟩, shl, sub, and, lor, - swap2, iszero, iszero, swap1, shl, push1 ⟨255⟩, push1 ⟨224⟩, shl, and, lor, - dup4] - let oldSlot : UInt256 := solcSlotWord acc.2 I (setRewardConfigWithMultiplierSlotOf I) - have rd459packed := rd459 - rw [show - ((UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩).land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨0⟩ : UInt256))) ⟨224⟩)).lor - ((((UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)).land - (UInt256.shiftLeft rescale ⟨160⟩)).lor - ((UInt256.land solcAddrMask (setRewardConfigDecimalsTargetWord I)).lor - (UInt256.land oldSlot - (UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩) - ⟨1⟩)))))) = - setRewardConfigSlot0Down oldSlot (setRewardConfigDecimalsTargetWord I) rescale by - exact setRewardConfigSlot0Down_bytecodeExpr oldSlot - (setRewardConfigDecimalsTargetWord I) rescale] at rd459packed - obtain ⟨_, _, rd459fold⟩ : ∃ k' C', - RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨459⟩ - [setRewardConfigWithMultiplierSlotOf I, - setRewardConfigSlot0Down oldSlot (setRewardConfigDecimalsTargetWord I) rescale, - ⟨192⟩ + ⟨96⟩, ⟨1⟩, setRewardConfigWithMultiplierSlotOf I, ⟨64⟩, ⟨0⟩] - (setRewardConfigSuccessArgsMem I baseOut decOut rescale ⟨0⟩) (⟨10⟩ : UInt256) - decOut (acc.1, acc.2) k' C' := by - exact ⟨_, _, by simpa [oldSlot, solcSlotWord] using rd459packed⟩ - have htargetWord : - setRewardConfigDecimalsTargetWord I = setRewardConfigWithMultiplierTokenWord I := by - unfold setRewardConfigDecimalsTargetWord - rw [u256_land_comm solcAddrMask (setRewardConfigWithMultiplierTokenWord I)] - exact solcAddrMask_clean hcanon1 - rw [htargetWord] at rd459fold - obtain ⟨_, _, rd460⟩ := rd459fold.sstore hperm (by native_decide) (by evm_ov) - have rd463pre := evm_run rd460 with [ - raw mload 0 (setRewardConfigWithMultiplierMultiplierWord I) (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigSuccessArgsMem_mload288 I rescale ⟨0⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap2, add] - obtain ⟨_, _, rd464⟩ := rd463pre.sstore hperm (by native_decide) (by evm_ov) - have rd465 := evm_run rd464 with [ - raw mload 0 ⟨320⟩ (⟨10⟩ : UInt256) (by native_decide) - mem_cost - (setRewardConfigSuccessArgsMem_mload64 I rescale ⟨0⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov)] - have rdret : RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) - (acc.1, - sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner acc.2 (setRewardConfigWithMultiplierSlotOf I) - (setRewardConfigSlot0Down oldSlot (setRewardConfigWithMultiplierTokenWord I) - rescale)) - (setRewardConfigWithMultiplierSlotOf I + ⟨1⟩) - (setRewardConfigWithMultiplierMultiplierWord I)) - ByteArray.empty := by - exact RD.ret 0 ByteArray.empty rd465 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk] - native_decide) - (by - rw [show (⟨320⟩ : UInt256).toNat = 320 from by decide, - show (⟨0⟩ : UInt256).toNat = 0 from by decide] - exact byteArray_readWithPadding_zero _ 320) - (by simp) - simpa [oldSlot] using rdret - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_after_decimals_upscale_zero_revert - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨280⟩ - (setRewardConfigDecimalsPostCallStack true baseWord I) - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) - (hle77 : (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 2 ^ 64 - 1) - (hbase64 : baseWord.toNat < EVM.twoPow 64) - (hle : baseWord.toNat ≤ - (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat) - (hbase0 : baseWord = ⟨0⟩) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨tokenScale, _, _, htokenScale_toNat, hbaseClean, _htokenClean, - _htokenCleanLeft, rd337⟩ := - cometRewardsSetRewardConfigWithMultiplierX_after_decimals_safe64_prefix - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (baseOut := baseOut) (decOut := decOut) - (baseWord := baseWord) (acc := acc) (k := k) (C := C) - rd hdec32 hdecSize hdec8 hle77 hsafe64 hbase64 - have hupWord : UInt256.gt baseWord tokenScale = ⟨0⟩ := by - apply ugt_zero - rw [htokenScale_toNat] - exact hle - have rd337up := rd337 - rw [hupWord] at rd337up - have rd466 := evm_run rd337up with [ - push1 ⟨0⟩, eq, push2 ⟨466⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest] - have rd3137 := evm_run rd466 with [ - push2 ⟨475⟩, swap2, push2 ⟨3137⟩, jump (by jump_dest)] - have rd3156pre := evm_run rd3137 with [ - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap2, dup3, and, - swap2, swap1, dup3, iszero] - have hdenZero : - UInt256.isZero - (UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) baseWord) = - ⟨1⟩ := by - rw [hbase0] - native_decide - have rd3156 := rd3156pre - rw [hdenZero] at rd3156 - have rd3161 := evm_run rd3156 with [ - push2 ⟨3161⟩, jumpiT (by native_decide) (by jump_dest)] - have hsel : - UInt256.shiftLeft (⟨0x4e487b71⟩ : UInt256) ⟨224⟩ = - setRewardConfigPanicSelector := by - rfl - have rd3172₀ := evm_run rd3161 with [ - jumpdest, push4 ⟨0x4e487b71⟩, push1 ⟨224⟩, shl, push1 ⟨0⟩] - have rd3172 := rd3172₀ - rw [hsel] at rd3172 - have rd3173 := evm_run rd3172 with [ - raw mstore 0 (setRewardConfigPanicMem0 (setRewardConfigDecimalsPostDecodeMem I baseOut decOut)) - setRewardConfigDecimalsPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov)] - have rd3178 := evm_run rd3173 with [ - push1 ⟨18⟩, push1 ⟨4⟩, - raw mstore 0 - (setRewardConfigPanicMem ⟨18⟩ (setRewardConfigDecimalsPostDecodeMem I baseOut decOut)) - setRewardConfigDecimalsPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigPanicMem setRewardConfigPanicMem0; rfl) - (by native_decide) (by evm_ov), - push1 ⟨36⟩, push1 ⟨0⟩] - exact evm_run rd3178 with [raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_after_decimals_upscale_success - {cA gh bl σ σ₀ A I} {g : Sat256} {baseOut decOut : ByteArray} - {baseWord rescale : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨280⟩ - (setRewardConfigDecimalsPostCallStack true baseWord I) - (setRewardConfigDecimalsPostCallMem I baseOut decOut) setRewardConfigDecimalsPostCallAw - decOut acc k C) - (hdec32 : 32 ≤ decOut.size) (hdecSize : decOut.size < UInt256.size) - (hdec8 : (setRewardConfigDecimalsReturnWord decOut).toNat < EVM.twoPow 8) - (hle77 : (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 77) - (hsafe64 : (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat ≤ 2 ^ 64 - 1) - (hbase64 : baseWord.toNat < EVM.twoPow 64) - (hperm : I.perm = true) - (hcanon0 : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hle : baseWord.toNat ≤ - (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat) - (hbaseNZ : baseWord.toNat ≠ 0) - (hrescale : rescale.toNat = - (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat / baseWord.toNat) : - RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) - (acc.1, - sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner acc.2 (setRewardConfigWithMultiplierSlotOf I) - (setRewardConfigSlot0Up - (solcSlotWord acc.2 I (setRewardConfigWithMultiplierSlotOf I)) - (setRewardConfigWithMultiplierTokenWord I) rescale)) - (setRewardConfigWithMultiplierSlotOf I + ⟨1⟩) - (setRewardConfigWithMultiplierMultiplierWord I)) - ByteArray.empty := by - obtain ⟨tokenScale, _, _, htokenScale_toNat, hbaseClean, _htokenClean, - _htokenCleanLeft, rd337⟩ := - cometRewardsSetRewardConfigWithMultiplierX_after_decimals_safe64_prefix - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (baseOut := baseOut) (decOut := decOut) - (baseWord := baseWord) (acc := acc) (k := k) (C := C) - rd hdec32 hdecSize hdec8 hle77 hsafe64 hbase64 - have hupWord : UInt256.gt baseWord tokenScale = ⟨0⟩ := by - apply ugt_zero - rw [htokenScale_toNat] - exact hle - have rd337up := rd337 - rw [hupWord] at rd337up - have rd466 := evm_run rd337up with [ - push1 ⟨0⟩, eq, push2 ⟨466⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest] - have rd3137 := evm_run rd466 with [ - push2 ⟨475⟩, swap2, push2 ⟨3137⟩, jump (by jump_dest)] - have rd3156pre := evm_run rd3137 with [ - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, swap2, dup3, and, - swap2, swap1, dup3, iszero] - have hbaseNZWord : UInt256.isZero - (UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) baseWord) = - ⟨0⟩ := by - rw [u256_land_comm (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) baseWord] - rw [hbaseClean] - exact isZero_eq_zero_of_ne (by - intro hzero - exact hbaseNZ (by - rw [hzero] - rfl)) - have rd3156 := rd3156pre - rw [hbaseNZWord] at rd3156 - have rd475 := evm_run rd3156 with [ - push2 ⟨3161⟩, jumpiNT (by native_decide), and, div, swap1, jump (by jump_dest), - jumpdest] - have htokenScale64 : tokenScale.toNat < EVM.twoPow 64 := by - rw [htokenScale_toNat] - have hpow : - (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat < 2 ^ 64 := by - omega - simpa [EVM.twoPow] using hpow - have htokenCleanRight : - UInt256.land tokenScale (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = - tokenScale := by - simpa [uint64Mask] using uint64Mask_clean htokenScale64 - have hbaseCleanLeft : - UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) baseWord = - baseWord := by - rw [u256_land_comm (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) baseWord] - exact hbaseClean - have hrescaleWord : UInt256.div tokenScale baseWord = rescale := by - apply u256_inj - rw [udiv_toNat, htokenScale_toNat, hrescale] - have rd475rescale := rd475 - rw [htokenCleanRight, hbaseCleanLeft, hrescaleWord] at rd475rescale - have rd488pre := evm_run rd475rescale with [ - swap6, dup11, - raw mload 0 ⟨192⟩ setRewardConfigDecimalsPostCallAw (by native_decide) - mem_cost - (setRewardConfigDecimalsPostDecodeMem_mload64_of_size_ge I hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap10, push2 ⟨488⟩] - have rd488arg := rdDup12 rd488pre (by native_decide) (by simp) - have rd488 := evm_run rd488arg with [ - push2 ⟨3025⟩, jump (by jump_dest), - jumpdest, push1 ⟨128⟩, dup2, add, swap1, dup2, lt, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, lor, - push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩, - raw mstore 0 (setRewardConfigSuccessFreeMem I baseOut decOut) - setRewardConfigDecimalsPostCallAw (by native_decide) mem_cost - (by unfold setRewardConfigSuccessFreeMem Reasoning.Theory.writeWord; rfl) - (by native_decide) (by evm_ov), - jump (by jump_dest), jumpdest] - have hrescale64 : rescale.toNat < EVM.twoPow 64 := by - rw [hrescale] - have hdiv := - Nat.div_le_self ((10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat) - baseWord.toNat - have hpow : - (10 : ℕ) ^ (setRewardConfigDecimalsReturnWord decOut).toNat < 2 ^ 64 := by - omega - exact lt_of_le_of_lt hdiv (by simpa [EVM.twoPow] using hpow) - have hrescaleClean : - UInt256.land rescale (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = rescale := by - simpa [uint64Mask] using uint64Mask_clean hrescale64 - have rd490 := evm_run rd488 with [ - dup11, - raw mstore 3 (setRewardConfigSuccessTokenMem I baseOut decOut) - (⟨7⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigSuccessTokenMem; rfl) - (by native_decide) (by evm_ov)] - have rd495pre := evm_run rd490 with [ - dup2, dup11, add, swap7, and] - have rd495 := rd495pre - rw [hrescaleClean] at rd495 - have rd497 := evm_run rd495 with [ - dup7, - raw mstore 3 (setRewardConfigSuccessRescaleMem I baseOut decOut rescale) - (⟨8⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigSuccessRescaleMem; rfl) - (by native_decide) (by evm_ov)] - have rd504 := evm_run rd497 with [ - dup10, dup10, add, swap4, dup3, dup6, - raw mstore 3 (setRewardConfigSuccessBitMem I baseOut decOut rescale ⟨1⟩) - (⟨9⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigSuccessBitMem; rfl) - (by native_decide) (by evm_ov)] - have rd511 := evm_run rd504 with [ - push1 ⟨96⟩, dup11, add, swap8, dup9, - raw mstore 3 (setRewardConfigSuccessMultiplierMem I baseOut decOut rescale ⟨1⟩) - (⟨10⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigSuccessMultiplierMem; rfl) - (by native_decide) (by evm_ov)] - have rd514 := evm_run rd511 with [ - push1 ⟨0⟩, - raw mstore 0 (setRewardConfigSuccessCometMem I baseOut decOut rescale ⟨1⟩) - (⟨10⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigSuccessCometMem; rfl) - (by native_decide) (by evm_ov)] - have rd515 := evm_run rd514 with [ - raw mstore 0 (setRewardConfigSuccessArgsMem I baseOut decOut rescale ⟨1⟩) - (⟨10⟩ : UInt256) (by native_decide) mem_cost - (by unfold setRewardConfigSuccessArgsMem; rfl) - (by native_decide) (by evm_ov)] - have hslot := setRewardConfigWithMultiplierSlotOf_eq_solc I hcanon0 - have hkeccak := - setRewardConfigSuccessArgsMem_keccakSlot I baseOut decOut rescale ⟨1⟩ hdec32 hdecSize - have rd519pre := evm_run rd515 with [dup8, push1 ⟨0⟩] - have rd519₀ := rd519pre.keccak256 0 - (solcMappingSlot ⟨1⟩ (setRewardConfigWithMultiplierCometWord I)) - (⟨10⟩ : UInt256) (by native_decide) mem_cost hkeccak (by native_decide) (by evm_ov) - have rd519 := rd519₀ - rw [← hslot] at rd519 - have rd524 := evm_run rd519 with [ - swap7, - raw mload 0 (setRewardConfigDecimalsTargetWord I) (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigSuccessArgsMem_mload192 I rescale ⟨1⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - and, swap1, dup7] - obtain ⟨_, _, rd525⟩ := rd524.sload (by native_decide) (by evm_ov) - have rd557 := evm_run rd525 with [ - swap4, push1 ⟨1⟩, push1 ⟨160⟩, shl, push1 ⟨1⟩, push1 ⟨224⟩, shl, sub, - swap1, - raw mload 0 rescale (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigSuccessArgsMem_mload224 I rescale ⟨1⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - push1 ⟨160⟩, shl, and, swap3, push1 ⟨255⟩, push1 ⟨224⟩, shl, swap2, - raw mload 0 (⟨1⟩ : UInt256) (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigSuccessArgsMem_mload256 I rescale ⟨1⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - iszero, iszero, swap1, shl, and, swap3] - have rd562 := rd557.pushConst (⟨0xffffff⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) (by native_decide) (by evm_ov) - have rd569 := evm_run rd562 with [ - push1 ⟨232⟩, shl, and, lor, lor, lor, dup4] - let oldSlot : UInt256 := solcSlotWord acc.2 I (setRewardConfigWithMultiplierSlotOf I) - have rd569packed := rd569 - rw [show - UInt256.lor - (UInt256.lor - (UInt256.lor - (UInt256.land (UInt256.shiftLeft (⟨0xffffff⟩ : UInt256) ⟨232⟩) oldSlot) - (UInt256.land (setRewardConfigDecimalsTargetWord I) solcAddrMask)) - (UInt256.land (UInt256.shiftLeft rescale ⟨160⟩) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩)))) - (UInt256.land - (UInt256.shiftLeft (UInt256.isZero (UInt256.isZero (⟨1⟩ : UInt256))) ⟨224⟩) - (UInt256.shiftLeft (⟨255⟩ : UInt256) ⟨224⟩)) = - setRewardConfigSlot0Up oldSlot (setRewardConfigDecimalsTargetWord I) rescale by - exact setRewardConfigSlot0Up_bytecodeExpr_runtime oldSlot - (setRewardConfigDecimalsTargetWord I) rescale] at rd569packed - obtain ⟨_, _, rd569fold⟩ : ∃ k' C', - RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨570⟩ - [setRewardConfigWithMultiplierSlotOf I, - setRewardConfigSlot0Up oldSlot (setRewardConfigDecimalsTargetWord I) rescale, - ⟨192⟩ + ⟨96⟩, ⟨1⟩, setRewardConfigWithMultiplierSlotOf I, ⟨64⟩, ⟨0⟩] - (setRewardConfigSuccessArgsMem I baseOut decOut rescale ⟨1⟩) (⟨10⟩ : UInt256) - decOut (acc.1, acc.2) k' C' := by - exact ⟨_, _, by simpa [oldSlot, solcSlotWord] using rd569packed⟩ - have htargetWord : - setRewardConfigDecimalsTargetWord I = setRewardConfigWithMultiplierTokenWord I := by - unfold setRewardConfigDecimalsTargetWord - rw [u256_land_comm solcAddrMask (setRewardConfigWithMultiplierTokenWord I)] - exact solcAddrMask_clean hcanon1 - rw [htargetWord] at rd569fold - obtain ⟨_, _, rd570⟩ := rd569fold.sstore hperm (by native_decide) (by evm_ov) - have rd573pre := evm_run rd570 with [ - raw mload 0 (setRewardConfigWithMultiplierMultiplierWord I) (⟨10⟩ : UInt256) - (by native_decide) mem_cost - (setRewardConfigSuccessArgsMem_mload288 I rescale ⟨1⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov), - swap2, add] - obtain ⟨_, _, rd574⟩ := rd573pre.sstore hperm (by native_decide) (by evm_ov) - have rd575 := evm_run rd574 with [ - raw mload 0 ⟨320⟩ (⟨10⟩ : UInt256) (by native_decide) - mem_cost - (setRewardConfigSuccessArgsMem_mload64 I rescale ⟨1⟩ hdec32 hdecSize) - (by native_decide) (by evm_ov)] - have rdret : RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) - (acc.1, - sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner acc.2 (setRewardConfigWithMultiplierSlotOf I) - (setRewardConfigSlot0Up oldSlot (setRewardConfigWithMultiplierTokenWord I) - rescale)) - (setRewardConfigWithMultiplierSlotOf I + ⟨1⟩) - (setRewardConfigWithMultiplierMultiplierWord I)) - ByteArray.empty := by - exact RD.ret 0 ByteArray.empty rd575 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk] - native_decide) - (by - rw [show (⟨320⟩ : UInt256).toNat = 320 from by decide, - show (⟨0⟩ : UInt256).toNat = 0 from by decide] - exact byteArray_readWithPadding_zero _ 320) - (by simp) - simpa [oldSlot] using rdret - -set_option maxHeartbeats 1000000 in -theorem cometRewardsSetRewardConfigWithMultiplierX_baseAccrualScale_callDepthLimit - {cA gh bl σ σ₀ A I} {g : UInt256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus) - (hcanon1 : (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (htoken : UInt256.land - (solcSlotWord σ I (setRewardConfigWithMultiplierSlotOf I)) solcAddrMask = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) - setRewardConfigWithMultiplierPc (dispatchArmLastStack I) solcFreePtrMem - (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hdepth : I.depth = 1024) : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - obtain ⟨gasArg, k0, C0, rd241⟩ := - cometRewardsSetRewardConfigWithMultiplierX_call_baseAccrualScale - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanon0 hcanon1 hauth htoken hreach - have rd241Call : - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) ⟨241⟩ - (gasArg :: setRewardConfigWithMultiplierCometWord I :: ⟨128⟩ :: ⟨4⟩ :: - ⟨128⟩ :: ⟨32⟩ :: setRewardConfigBasePostCallTail I) - (setRewardConfigBaseAccrualScaleCalldataMem I) - (UInt256.ofNat 5) ByteArray.empty (cA, σ) k0 C0 := by - simpa [setRewardConfigBasePostCallTail] using rd241 - have hdecCall : - decode cometRewardsBytecode (⟨241⟩ : UInt256) = some (.STATICCALL, .none) := by - native_decide - have hdepthInit : - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).executionEnv.depth = 1024 := by - simpa [initState] using hdepth - obtain ⟨k', C', rdPost₀⟩ := - RD.solcStaticcallDepthLimit (t := setRewardConfigBasePostCallTail I) - rd241Call hdecCall hdepthInit (by simp [setRewardConfigBasePostCallTail]) - have rdPost : - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) - ⟨242⟩ (setRewardConfigBasePostCallStack false I) - (setRewardConfigBasePostCallMem I ByteArray.empty) setRewardConfigBasePostCallAw - ByteArray.empty (cA, σ) k' C' := by - simpa [setRewardConfigBasePostCallStack, setRewardConfigBasePostCallTail, - setRewardConfigBasePostCallMem, setRewardConfigBasePostCallAw] using rdPost₀ - exact cometRewardsSetRewardConfigWithMultiplierX_after_baseAccrualScale_failure rdPost - (by simp [UInt256.size]) - -/-- `setRewardConfigWithMultiplier(address,address,uint256)` body, reached at pc 159. -/ -theorem cometRewardsSetRewardConfigWithMultiplierBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} - {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hsel : selIs I (cometRewardsSelBytes 10)) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - setRewardConfigWithMultiplierPc (dispatchArmLastStack I) solcFreePtrMem - (UInt256.ofNat 3) ByteArray.empty (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have _hperm : I.perm = true := hperm - have hsz4 := cometRewardsSetRewardConfigWithMultiplierSelector_size hsel - have hd := cometRewardsDispatch_setRewardConfigWithMultiplier (cd := I.calldata) hsel - by_cases hsz100 : 100 ≤ I.calldata.size - · by_cases hhi : I.calldata.size < 2 ^ 255 + 4 - · by_cases hcanon0 : - (setRewardConfigWithMultiplierCometWord I).toNat < EVM.addressModulus - · by_cases hcanon1 : - (setRewardConfigWithMultiplierTokenWord I).toNat < EVM.addressModulus - · have hdec := - cometRewardsDecode_setRewardConfigWithMultiplier_ok - (I := I) hsz100 hhi hcanon0 hcanon1 - have hgovWord : governorWord σ_evm I = governorWord σ_solm I := - accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ ⟨0⟩ - have hgovRet : - governorReturnWord σ_evm I = governorReturnWord σ_solm I := by - simp [governorReturnWord, hgovWord] - have hslotWord : - solcSlotWord σ_evm I (setRewardConfigWithMultiplierSlotOf I) = - solcSlotWord σ_solm I (setRewardConfigWithMultiplierSlotOf I) := - accountMapEquiv_storage_findD hAccounts I.codeOwner - (setRewardConfigWithMultiplierSlotOf I) ⟨0⟩ - by_cases hauth : governorReturnWord σ_evm I = solcSourceWord I - · have hauthSolm : governorReturnWord σ_solm I = solcSourceWord I := by - rw [← hgovRet] - exact hauth - have hgovSolm : - UInt256.land (Solm.EVM.storageLoad - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.codeOwner - ⟨0⟩) solcAddrMask = - solcSourceWord - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv := by - simpa [governorReturnWord, governorWord, initState, Solm.EVM.storageLoad, - State.lookupAccount] using hauthSolm - by_cases hconfigured : - UInt256.land - (solcSlotWord σ_evm I (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask ≠ ⟨0⟩ - · have hconfiguredSolm : - UInt256.land (Solm.EVM.storageLoad - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) solcAddrMask ≠ ⟨0⟩ := by - simpa [initState, Solm.EVM.storageLoad, State.lookupAccount, solcSlotWord, - hslotWord] using hconfigured - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - exact cometRewardsSetRewardConfigWithMultiplierBodyReverts_configured - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - hconfiguredSolm - exact (cometRewardsSetRewardConfigWithMultiplierX_revert_configured - (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanon0 hcanon1 hauth hconfigured hreach) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have htokenZero : - UInt256.land - (solcSlotWord σ_evm I (setRewardConfigWithMultiplierSlotOf I)) - solcAddrMask = ⟨0⟩ := by - exact Classical.not_not.mp hconfigured - have htokenZeroSolm : - UInt256.land (Solm.EVM.storageLoad - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.codeOwner - (setRewardConfigWithMultiplierSlotOf I)) solcAddrMask = ⟨0⟩ := by - simpa [initState, Solm.EVM.storageLoad, State.lookupAccount, solcSlotWord, - hslotWord] using htokenZero - by_cases hdepth : I.depth.val < 1024 - · obtain ⟨cA', σ'_evm, σ'_solm, A'_solm, z, out, kPost, CPost, - hcallS, hPostAccounts, rdPost, houtSign⟩ := - cometRewardsSetRewardConfigWithMultiplierX_call_baseAccrualScale_made - (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) - (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz100 hsize hhi hcanon0 hcanon1 hauth htokenZero hdepth - hreach hAccounts - let evmPost : EVM.State := - { initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } - have houtSize : out.size < UInt256.size := lt_size_of_lt_sign houtSign - cases z - · have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - exact cometRewardsSetRewardConfigWithMultiplierBodyReverts_baseCallFailure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - exact - (cometRewardsSetRewardConfigWithMultiplierX_after_baseAccrualScale_failure - rdPost houtSize) - |>.reEquivExecutionRevert hcode hd hdec hbody - · by_cases hshort : out.size < 32 - · have hdecBase := cometRewardsBaseAccrualScale_decode_none_short - (out := out) hshort - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - exact cometRewardsSetRewardConfigWithMultiplierBodyReverts_baseDecodeFailure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - exact - (cometRewardsSetRewardConfigWithMultiplierX_after_baseAccrualScale_short_revert - rdPost hshort houtSize) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have hout32 : 32 ≤ out.size := by omega - by_cases hbaseWord : - fromByteArrayBigEndian (out.extract 0 32) < EVM.twoPow 64 - · have hdecBase := cometRewardsBaseAccrualScale_decode_ok - (out := out) hout32 houtSign hbaseWord - have hbase64 : - (setRewardConfigBaseReturnWord out).toNat < EVM.twoPow 64 := by - have hto : - (setRewardConfigBaseReturnWord out).toNat = - fromByteArrayBigEndian (out.extract 0 32) := by - simpa [setRewardConfigBaseReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt hout32) - rw [hto] - exact hbaseWord - obtain ⟨kBase, CBase, rdBaseDecoded⟩ := - cometRewardsSetRewardConfigWithMultiplierX_after_baseAccrualScale_decode_ok - rdPost hout32 houtSize hbase64 - obtain ⟨cA'', σ''_evm, σ''_solm, A''_solm, zDec, outDec, - kDec, CDec, hcallDec, hPostAccountsDec, rdDecPost, - houtDecSign⟩ := - cometRewardsSetRewardConfigWithMultiplierX_call_decimals_made - (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) - (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) (baseOut := out) - (baseWord := setRewardConfigBaseReturnWord out) - (cA' := cA') (σ'_evm := σ'_evm) (σ'_solm := σ'_solm) - (A'_solm := A'_solm) - hcanon1 hdepth hPostAccounts rdBaseDecoded hout32 houtSize - cases zDec - · let evmDecFail : EVM.State := - { evmPost with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' } - have houtDecSize : outDec.size < UInt256.size := - lt_size_of_lt_sign houtDecSign - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - exact - cometRewardsSetRewardConfigWithMultiplierBodyReverts_decimalsCallFailure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecFail I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - (by simpa [evmPost, evmDecFail] using hcallDec) - exact - (cometRewardsSetRewardConfigWithMultiplierX_after_decimals_failure - rdDecPost hout32 houtSize houtDecSize) - |>.reEquivExecutionRevert hcode hd hdec hbody - · by_cases hdecShort : outDec.size < 32 - · let evmDecPost : EVM.State := - { evmPost with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' } - have houtDecSize : outDec.size < UInt256.size := - lt_size_of_lt_sign houtDecSign - have hdecDecimals := cometRewardsDecimals_decode_none_short - (out := outDec) hdecShort - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - exact - cometRewardsSetRewardConfigWithMultiplierBodyReverts_decimalsDecodeFailure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimals - exact - (cometRewardsSetRewardConfigWithMultiplierX_after_decimals_short_revert - rdDecPost hdecShort houtDecSize) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have houtDec32 : 32 ≤ outDec.size := le_of_not_gt hdecShort - by_cases hdecWord : - fromByteArrayBigEndian (outDec.extract 0 32) < EVM.twoPow 8 - · have hdecDecimals := cometRewardsDecimals_decode_ok - (out := outDec) houtDec32 houtDecSign hdecWord - have htoDec : - (setRewardConfigDecimalsReturnWord outDec).toNat = - fromByteArrayBigEndian (outDec.extract 0 32) := by - simpa [setRewardConfigDecimalsReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt houtDec32) - by_cases hle77 : - fromByteArrayBigEndian (outDec.extract 0 32) ≤ 77 - · let evmDecPost : EVM.State := - { evmPost with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' } - have houtDecSize : outDec.size < UInt256.size := - lt_size_of_lt_sign houtDecSign - by_cases hsafe64 : - (10 : ℕ) ^ - fromByteArrayBigEndian (outDec.extract 0 32) ≤ - 2 ^ 64 - 1 - · have hdec8Return : - (setRewardConfigDecimalsReturnWord outDec).toNat < - EVM.twoPow 8 := by - rw [htoDec] - exact hdecWord - have hle77Return : - (setRewardConfigDecimalsReturnWord outDec).toNat ≤ 77 := by - rw [htoDec] - exact hle77 - have hsafe64Return : - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat ≤ - 2 ^ 64 - 1 := by - rw [htoDec] - exact hsafe64 - have hbaseTo : - (setRewardConfigBaseReturnWord out).toNat = - fromByteArrayBigEndian (out.extract 0 32) := by - simpa [setRewardConfigBaseReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt hout32) - have hdecBaseReturn : - config.externalABI.decode? "baseAccrualScale" out = - some [.int (Int.ofNat - (setRewardConfigBaseReturnWord out).toNat)] := by - rw [hbaseTo] - exact hdecBase - have hdecDecimalsReturn : - config.externalABI.decode? "decimals" outDec = - some [.int (Int.ofNat - (setRewardConfigDecimalsReturnWord outDec).toNat)] := by - rw [htoDec] - exact hdecDecimals - by_cases hdown : - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat < - (setRewardConfigBaseReturnWord out).toNat - · let rescale : UInt256 := UInt256.ofNat - ((setRewardConfigBaseReturnWord out).toNat / - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat) - have hquotLt : - (setRewardConfigBaseReturnWord out).toNat / - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat < - UInt256.size := by - exact lt_of_le_of_lt - (Nat.div_le_self _ _) - (lt_of_lt_of_le hbase64 (by norm_num [EVM.twoPow, UInt256.size])) - have hrescale : - rescale.toNat = - (setRewardConfigBaseReturnWord out).toNat / - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat := by - simpa [rescale] using UInt256.toNat_ofNat_of_lt hquotLt - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body - (.returned - (resumeAfterInternalCall - (setRewardConfigWithMultiplierFrame - (initState cA gh bl σ_solm σ₀ - (Sat256.ofUInt256 g) A I) I) "_set" none) - (setRewardConfigSourceFinal evmDecPost I rescale false) - none) := by - exact - cometRewardsSetRewardConfigWithMultiplierBodyReturns_downscale - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I - hcanon1 - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBaseReturn - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimalsReturn hle77Return hsafe64Return - hrescale hdown - have hslotPost : - solcSlotWord σ''_evm I - (setRewardConfigWithMultiplierSlotOf I) = - solcSlotWord σ''_solm I - (setRewardConfigWithMultiplierSlotOf I) := - accountMapEquiv_storage_findD hPostAccountsDec I.codeOwner - (setRewardConfigWithMultiplierSlotOf I) ⟨0⟩ - have hIdeal := - accountMapEquiv_sstoreAccountMap I.codeOwner - (setRewardConfigWithMultiplierSlotOf I + ⟨1⟩) - (setRewardConfigWithMultiplierMultiplierWord I) - (accountMapEquiv_sstoreAccountMap I.codeOwner - (setRewardConfigWithMultiplierSlotOf I) - (setRewardConfigSlot0Down - (solcSlotWord σ''_solm I - (setRewardConfigWithMultiplierSlotOf I)) - (setRewardConfigWithMultiplierTokenWord I) rescale) - hPostAccountsDec) - have hsourceAccounts := - setRewardConfigSourceFinal_accountMap_equiv evmDecPost I - rescale false - have hAccountsPost := accountMapEquiv.trans - (by simpa [hslotPost] using hIdeal) - (by - simpa [evmDecPost, evmPost, initState, solcSlotWord, - Solm.EVM.storageLoad, State.lookupAccount, - setRewardConfigSlot0Down] using hsourceAccounts) - have hcreated : - cA'' = - (setRewardConfigSourceFinal evmDecPost I rescale false).createdAccounts := by - simp [setRewardConfigSourceFinal, - setRewardConfigSourceAfterShouldUpscale, - setRewardConfigSourceAfterRescale, - setRewardConfigSourceAfterToken, evmDecPost, - storageStore_createdAccounts] - exact - (cometRewardsSetRewardConfigWithMultiplierX_after_decimals_downscale_success - rdDecPost hperm hcanon0 hcanon1 houtDec32 houtDecSize - hdec8Return hle77Return hsafe64Return hbase64 hdown - hrescale) - |>.reEquivExecutionGenAccountMapEquiv hcode hd hdec hbody - hcreated (by simpa [evmDecPost, hslotPost.symm] using hAccountsPost) - (returnEquiv.fallthrough rfl (by rfl) (by native_decide)) - · have hupLe : - (setRewardConfigBaseReturnWord out).toNat ≤ - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat := - Nat.le_of_not_gt hdown - by_cases hbaseZero : - (setRewardConfigBaseReturnWord out).toNat = 0 - · have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - exact - cometRewardsSetRewardConfigWithMultiplierBodyReverts_upscaleZero - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I hcanon1 - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBaseReturn - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimalsReturn hle77Return hsafe64Return hbaseZero - have hbaseWordZero : setRewardConfigBaseReturnWord out = ⟨0⟩ := by - apply u256_inj - simpa using hbaseZero - exact - (cometRewardsSetRewardConfigWithMultiplierX_after_decimals_upscale_zero_revert - rdDecPost houtDec32 houtDecSize hdec8Return - hle77Return hsafe64Return hbase64 hupLe hbaseWordZero) - |>.reEquivExecutionRevert hcode hd hdec hbody - · let rescale : UInt256 := UInt256.ofNat - ((10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat / - (setRewardConfigBaseReturnWord out).toNat) - have hquotLt : - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat / - (setRewardConfigBaseReturnWord out).toNat < - UInt256.size := by - have hdiv := - Nat.div_le_self - ((10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat) - (setRewardConfigBaseReturnWord out).toNat - have hpowLt : (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat < - 2 ^ 64 := by omega - exact lt_of_le_of_lt hdiv (by - norm_num [UInt256.size] at hpowLt ⊢ - omega) - have hrescale : - rescale.toNat = - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat / - (setRewardConfigBaseReturnWord out).toNat := by - simpa [rescale] using UInt256.toNat_ofNat_of_lt hquotLt - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body - (.returned - (resumeAfterInternalCall - (setRewardConfigWithMultiplierFrame - (initState cA gh bl σ_solm σ₀ - (Sat256.ofUInt256 g) A I) I) "_set" none) - (setRewardConfigSourceFinal evmDecPost I rescale true) - none) := by - exact - cometRewardsSetRewardConfigWithMultiplierBodyReturns_upscale - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I hcanon1 - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBaseReturn - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimalsReturn hle77Return hsafe64Return - hrescale hupLe hbaseZero - have hslotPost : - solcSlotWord σ''_evm I - (setRewardConfigWithMultiplierSlotOf I) = - solcSlotWord σ''_solm I - (setRewardConfigWithMultiplierSlotOf I) := - accountMapEquiv_storage_findD hPostAccountsDec I.codeOwner - (setRewardConfigWithMultiplierSlotOf I) ⟨0⟩ - have hIdeal := - accountMapEquiv_sstoreAccountMap I.codeOwner - (setRewardConfigWithMultiplierSlotOf I + ⟨1⟩) - (setRewardConfigWithMultiplierMultiplierWord I) - (accountMapEquiv_sstoreAccountMap I.codeOwner - (setRewardConfigWithMultiplierSlotOf I) - (setRewardConfigSlot0Up - (solcSlotWord σ''_solm I - (setRewardConfigWithMultiplierSlotOf I)) - (setRewardConfigWithMultiplierTokenWord I) rescale) - hPostAccountsDec) - have hsourceAccounts := - setRewardConfigSourceFinal_accountMap_equiv evmDecPost I - rescale true - have hAccountsPost := accountMapEquiv.trans - (by simpa [hslotPost] using hIdeal) - (by - simpa [evmDecPost, evmPost, initState, solcSlotWord, - Solm.EVM.storageLoad, State.lookupAccount, - setRewardConfigSlot0Up] using hsourceAccounts) - have hcreated : - cA'' = - (setRewardConfigSourceFinal evmDecPost I rescale true).createdAccounts := by - simp [setRewardConfigSourceFinal, - setRewardConfigSourceAfterShouldUpscale, - setRewardConfigSourceAfterRescale, - setRewardConfigSourceAfterToken, evmDecPost, - storageStore_createdAccounts] - exact - (cometRewardsSetRewardConfigWithMultiplierX_after_decimals_upscale_success - rdDecPost houtDec32 houtDecSize hdec8Return - hle77Return hsafe64Return hbase64 hperm hcanon0 - hcanon1 hupLe hbaseZero hrescale) - |>.reEquivExecutionGenAccountMapEquiv hcode hd hdec hbody - hcreated (by simpa [evmDecPost, hslotPost.symm] using hAccountsPost) - (returnEquiv.fallthrough rfl (by rfl) (by native_decide)) - · have hgt64 : - 2 ^ 64 - 1 < - (10 : ℕ) ^ - fromByteArrayBigEndian (outDec.extract 0 32) := - Nat.lt_of_not_ge hsafe64 - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - exact - cometRewardsSetRewardConfigWithMultiplierBodyReverts_safe64Failure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimals - hle77 - hgt64 - have hdec8Return : - (setRewardConfigDecimalsReturnWord outDec).toNat < - EVM.twoPow 8 := by - rw [htoDec] - exact hdecWord - have hle77Return : - (setRewardConfigDecimalsReturnWord outDec).toNat ≤ 77 := by - rw [htoDec] - exact hle77 - have hgt64Return : - 2 ^ 64 - 1 < - (10 : ℕ) ^ - (setRewardConfigDecimalsReturnWord outDec).toNat := by - rw [htoDec] - exact hgt64 - exact - (cometRewardsSetRewardConfigWithMultiplierX_after_decimals_safe64_revert - rdDecPost houtDec32 houtDecSize hdec8Return hle77Return - hgt64Return) - |>.reEquivExecutionRevert hcode hd hdec hbody - · let evmDecPost : EVM.State := - { evmPost with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' } - have houtDecSize : outDec.size < UInt256.size := - lt_size_of_lt_sign houtDecSign - have hgt77 : - 77 < fromByteArrayBigEndian (outDec.extract 0 32) := - Nat.lt_of_not_ge hle77 - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - exact - cometRewardsSetRewardConfigWithMultiplierBodyReverts_pow10Failure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimals - hgt77 - have hdec8Return : - (setRewardConfigDecimalsReturnWord outDec).toNat < - EVM.twoPow 8 := by - rw [htoDec] - exact hdecWord - have hgt77Return : - 77 < (setRewardConfigDecimalsReturnWord outDec).toNat := by - rw [htoDec] - exact hgt77 - exact - (cometRewardsSetRewardConfigWithMultiplierX_after_decimals_pow10_revert - rdDecPost houtDec32 houtDecSize hdec8Return hgt77Return) - |>.reEquivExecutionRevert hcode hd hdec hbody - · let evmDecPost : EVM.State := - { evmPost with - accountMap := σ''_solm - substate := A''_solm - createdAccounts := cA'' } - have houtDecSize : outDec.size < UInt256.size := - lt_size_of_lt_sign houtDecSign - have hdecDecimals := - cometRewardsDecimals_decode_none_noncanon - (out := outDec) houtDec32 houtDecSign hdecWord - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - exact - cometRewardsSetRewardConfigWithMultiplierBodyReverts_decimalsDecodeFailure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost evmDecPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - (by simpa [evmPost, evmDecPost] using hcallDec) - hdecDecimals - have hdecNo : - ¬ (setRewardConfigDecimalsReturnWord outDec).toNat < - EVM.twoPow 8 := by - intro hlt - have hto : - (setRewardConfigDecimalsReturnWord outDec).toNat = - fromByteArrayBigEndian (outDec.extract 0 32) := by - simpa [setRewardConfigDecimalsReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt houtDec32) - exact hdecWord (by - rw [← hto] - exact hlt) - exact - (cometRewardsSetRewardConfigWithMultiplierX_after_decimals_noncanon_revert - rdDecPost houtDec32 houtDecSize hdecNo) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have hdecBase := cometRewardsBaseAccrualScale_decode_none_noncanon - (out := out) hout32 houtSign hbaseWord - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - exact cometRewardsSetRewardConfigWithMultiplierBodyReverts_baseDecodeFailure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - htokenZeroSolm - (by simpa [evmPost] using hcallS) - hdecBase - have hbaseNo : - ¬ (setRewardConfigBaseReturnWord out).toNat < EVM.twoPow 64 := by - intro hlt - have hto : - (setRewardConfigBaseReturnWord out).toNat = - fromByteArrayBigEndian (out.extract 0 32) := by - simpa [setRewardConfigBaseReturnWord] using - UInt256.toNat_ofNat_of_lt - (fromByteArrayBigEndian_extract0_32_lt hout32) - exact hbaseWord (by - rw [← hto] - exact hlt) - exact - (cometRewardsSetRewardConfigWithMultiplierX_after_baseAccrualScale_noncanon_revert - rdPost hout32 houtSize hbaseNo) - |>.reEquivExecutionRevert hcode hd hdec hbody - · rw [not_lt] at hdepth - have hdepth1024 : I.depth = 1024 := Fin.ext (by - have := I.depth.isLt - omega) - let evmInit : EVM.State := - initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I - let evmFail : EVM.State := - { evmInit with - substate := - (evmInit.addAccessedAccount - (EVM.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat))).substate } - have hcallS : - typedCallViaEVM config evmInit - (EVM.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)) - "baseAccrualScale" 0 [] - (false, evmFail, ByteArray.empty) false := by - exact callNotMade_depthLimit - (cfg := config) (evm := evmInit) - (tgt := EVM.address (AccountAddress.ofNat - (setRewardConfigWithMultiplierCometWord I).toNat)) - (name := "baseAccrualScale") (args := []) - (calldata := (setRewardConfigBaseAccrualScaleCalldataMem I) - |>.readWithPadding 128 4) - (callPerm := false) - (setRewardConfigBaseAccrualScaleCalldataMem_encode I) - (by simpa [evmInit, initState] using hdepth1024) - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - exact cometRewardsSetRewardConfigWithMultiplierBodyReverts_baseCallFailure - evmInit evmFail I - (by simp only [evmInit, initState]; exact hwv) - (by simp only [evmInit, initState]; exact hhi) - (by simpa [evmInit] using hgovSolm) - (by simpa [evmInit] using htokenZeroSolm) - hcallS - exact (cometRewardsSetRewardConfigWithMultiplierX_baseAccrualScale_callDepthLimit - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := g) - hwv hsz100 hsize hhi hcanon0 hcanon1 hauth htokenZero hreach - hdepth1024) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have hauthSolm : - governorReturnWord σ_solm I ≠ solcSourceWord I := by - intro hbad - exact hauth (by - rw [hgovRet] - exact hbad) - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (setRewardConfigWithMultiplierStore I) - setRewardConfigWithMultiplierTransition.body .reverted := by - exact cometRewardsSetRewardConfigWithMultiplierBodyReverts_auth - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - (by - simpa [governorReturnWord, governorWord, initState, Solm.EVM.storageLoad, - State.lookupAccount] using hauthSolm) - exact (cometRewardsSetRewardConfigWithMultiplierX_revert_auth - (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanon0 hcanon1 hauth hreach) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have hdec := - cometRewardsDecode_setRewardConfigWithMultiplier_none_noncanon_token - (I := I) hsz100 hhi hcanon0 hcanon1 - have hnc : UInt256.eq (setRewardConfigWithMultiplierTokenWord I) - (UInt256.land (setRewardConfigWithMultiplierTokenWord I) solcAddrMask) = - ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanon1 (solcAddrCanonical_of_clean he)) - exact (cometRewardsSetRewardConfigWithMultiplierX_noncanon_token - (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanon0 hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hdec := - cometRewardsDecode_setRewardConfigWithMultiplier_none_noncanon_comet - (I := I) hsz100 hhi hcanon0 - have hnc : UInt256.eq (setRewardConfigWithMultiplierCometWord I) - (UInt256.land (setRewardConfigWithMultiplierCometWord I) solcAddrMask) = - ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanon0 (solcAddrCanonical_of_clean he)) - exact (cometRewardsSetRewardConfigWithMultiplierX_noncanon_comet - (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hbig : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - have hdec := cometRewardsDecode_setRewardConfigWithMultiplier_none_huge (I := I) hbig - exact (cometRewardsSetRewardConfigWithMultiplierX_hugearg - (g := Sat256.ofUInt256 g) hwv hsize hbig hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hshort : I.calldata.size < 100 := by omega - have hdec := - cometRewardsDecode_setRewardConfigWithMultiplier_none_short (I := I) hsz4 hshort - exact (cometRewardsSetRewardConfigWithMultiplierX_shortarg - (g := Sat256.ofUInt256 g) hwv hsz4 hsize hshort hreach) - |>.reEquivDecodingFailed hcode hd hdec - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/SetRewardsClaimed.lean b/Benchmarks/CompoundIII/CometRewards/SetRewardsClaimed.lean deleted file mode 100644 index 807694cb..00000000 --- a/Benchmarks/CompoundIII/CometRewards/SetRewardsClaimed.lean +++ /dev/null @@ -1,21 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.Common - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.CompoundIII.CometRewards - -/-- `setRewardsClaimed(address,address[],uint256[])` body, reached at pc 1723. -/ -theorem cometRewardsSetRewardsClaimedBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} - {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hsel : selIs I (cometRewardsSelBytes 5)) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) setRewardsClaimedPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/TransferGovernor.lean b/Benchmarks/CompoundIII/CometRewards/TransferGovernor.lean deleted file mode 100644 index b789d87f..00000000 --- a/Benchmarks/CompoundIII/CometRewards/TransferGovernor.lean +++ /dev/null @@ -1,725 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.Common -import Benchmarks.CompoundIII.CometRewards.Governor - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace Benchmarks.CompoundIII.CometRewards - -/-! ## `transferGovernor(address)` -/ - -abbrev transferGovernorNewGovernorWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -abbrev transferGovernorNewGovernorValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (transferGovernorNewGovernorWord I).toNat) - -abbrev transferGovernorStore (I : ExecutionEnv) : Store := - (∅ : Store).insert "newGovernor" (transferGovernorNewGovernorValue I) - -def transferGovernorStoredWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - setAddressOffset0Word (governorWord σ I) (transferGovernorNewGovernorWord I) - -def transferGovernorPostState (evm : EVM.State) (I : ExecutionEnv) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (setAddressOffset0Word - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - (transferGovernorNewGovernorWord I)) - -abbrev transferGovernorFrame (evm : EVM.State) (I : ExecutionEnv) : Frame := - { contract := contract, - locals := (transferGovernorStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) } - -theorem cometRewardsDecode_transferGovernor_ok {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanon : (transferGovernorNewGovernorWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode - (transferGovernorTransition.params.map Param.name) - (transitionSignature transferGovernorTransition).paramTypes I.calldata = - some (transferGovernorStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["newGovernor"] [addr] I.calldata = _ - simpa [config, transferGovernorStore, transferGovernorNewGovernorValue, - transferGovernorNewGovernorWord, calldataWord] - using decodeCalldata_address_ok (cd := I.calldata) (x := "newGovernor") - hsz36 hbig hcanon - -theorem cometRewardsDecode_transferGovernor_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 36) : - decodeCalldataWithMode config.abiDecodeMode - (transferGovernorTransition.params.map Param.name) - (transitionSignature transferGovernorTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["newGovernor"] [addr] I.calldata = none - simpa [config, addr] using decodeCalldata_address_none_short - (cd := I.calldata) (x := "newGovernor") hsz4 hshort - -theorem cometRewardsDecode_transferGovernor_none_noncanon {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hnc : ¬ (transferGovernorNewGovernorWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode - (transferGovernorTransition.params.map Param.name) - (transitionSignature transferGovernorTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["newGovernor"] [addr] I.calldata = none - simpa [config, addr, transferGovernorNewGovernorWord, calldataWord] - using decodeCalldata_address_none_noncanon - (cd := I.calldata) (x := "newGovernor") hsz36 hbig hnc - -theorem cometRewardsDecode_transferGovernor_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode - (transferGovernorTransition.params.map Param.name) - (transitionSignature transferGovernorTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["newGovernor"] [addr] I.calldata = none - simpa [config, addr] using decodeCalldata_address_none_huge - (cd := I.calldata) (x := "newGovernor") hbig - -theorem cometRewardsTransferGovernorSelector_size {I : ExecutionEnv} - (hsel : selIs I (cometRewardsSelBytes 9)) : - 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (cometRewardsSelBytes 9) rfl hsel - -theorem cometRewardsDispatch_transferGovernor {cd : ByteArray} - (hsel : (cometRewardsSelBytes 9 == cd.extract 0 4) = true) : - dispatchMsg contract cd = some transferGovernorTransition := by - have hcd : cd.extract 0 4 = cometRewardsSelBytes 9 := - (byteArray_eq_of_beq hsel).symm - refine dispatchMsg_eq_some_of_split - (pre := [claimTransition, claimToTransition, getRewardOwedTransition, governorTransition, - rewardConfigTransition, rewardsClaimedTransition, setRewardConfigTransition, - setRewardConfigWithMultiplierTransition, setRewardsClaimedTransition]) - (post := [withdrawTokenTransition]) - rfl rfl ?_ (by rw [selectorOf, transferGovernorSelectorBytes]; exact hsel) - intro t ht - simp only [List.mem_cons, List.not_mem_nil, or_false] at ht - rcases ht with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, claimSelectorBytes, hcd] - decide - · rw [selectorOf, claimToSelectorBytes, hcd] - decide - · rw [selectorOf, getRewardOwedSelectorBytes, hcd] - decide - · rw [selectorOf, governorSelectorBytes, hcd] - decide - · rw [selectorOf, rewardConfigSelectorBytes, hcd] - decide - · rw [selectorOf, rewardsClaimedSelectorBytes, hcd] - decide - · rw [selectorOf, setRewardConfigSelectorBytes, hcd] - decide - · rw [selectorOf, setRewardConfigWithMultiplierSelectorBytes, hcd] - decide - · rw [selectorOf, setRewardsClaimedSelectorBytes, hcd] - decide - -theorem cometRewardsTransferGovernorCalldataCheckOk {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hhi : I.calldata.size < 2 ^ 255 + 4) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨32⟩ = ⟨0⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨32⟩ = ⟨0⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - exact solcDecodeLenCheckOk_4_32 hsz36 hhi hsize - -theorem cometRewardsTransferGovernorCalldataCheckShort {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hshort : I.calldata.size < 36) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨32⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨32⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 hsz4 hsize] - exact solcDecodeLenCheckShort_4_32 hsz4 hshort hsize - -theorem cometRewardsTransferGovernorCalldataCheckHuge {I : ExecutionEnv} - (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨32⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨32⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - exact solcDecodeLenCheckHuge_4_32 hbig hsize - -theorem cometRewardsTransferGovernorX_dec2831_newGovernor {cA gh bl σ σ₀ A I} - {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) transferGovernorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2831⟩ - [⟨829⟩, ⟨64⟩, ⟨4⟩, ⟨0⟩, cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt := cometRewardsTransferGovernorCalldataCheckOk (I := I) hsz36 hsize hhi - obtain ⟨_, _, rd801⟩ := hreach - have rd806 := evm_run rd801 with [ - jumpdest, dup5, dup3, dup6, callvalue] - rw [hwv] at rd806 - have rd818 := evm_run rd806 with [ - push2 ⟨938⟩, jumpiNT (by decide), - push1 ⟨32⟩, calldatasize, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd818 - rw [hslt] at rd818 - have rd828 := evm_run rd818 with [ - push2 ⟨938⟩, jumpiNT (by decide), - push2 ⟨829⟩, push2 ⟨2831⟩] - exact ⟨_, _, evm_run rd828 with [jump (by native_decide)]⟩ - -theorem cometRewardsTransferGovernorX_dec829_newGovernor {cA gh bl σ σ₀ A I} - {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon : (transferGovernorNewGovernorWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) transferGovernorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨829⟩ - [transferGovernorNewGovernorWord I, ⟨64⟩, ⟨4⟩, ⟨0⟩, cometRewardsSelWord I, - ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2831⟩ := - cometRewardsTransferGovernorX_dec2831_newGovernor (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hsz36 hsize hhi hreach - exact ⟨_, _, evm_run rd2831 with [ - jumpdest, push1 ⟨4⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32) := by - exact solcAddrMask_clean (by - simpa [transferGovernorNewGovernorWord, calldataWord] using hcanon) - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean] - exact u256_sub_self _), - jump (by native_decide)]⟩ - -theorem cometRewardsTransferGovernorX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz4 : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hshort : I.calldata.size < 36) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) transferGovernorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsTransferGovernorCalldataCheckShort (I := I) hsz4 hsize hshort - obtain ⟨_, _, rd801⟩ := hreach - have rd806 := evm_run rd801 with [ - jumpdest, dup5, dup3, dup6, callvalue] - rw [hwv] at rd806 - have rd818 := evm_run rd806 with [ - push2 ⟨938⟩, jumpiNT (by decide), - push1 ⟨32⟩, calldatasize, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd818 - rw [hslt] at rd818 - exact evm_run rd818 with [ - push2 ⟨938⟩, jumpiT (by decide) (by native_decide), - jumpdest, dup3, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsTransferGovernorX_hugearg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) transferGovernorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsTransferGovernorCalldataCheckHuge (I := I) hsize hbig - obtain ⟨_, _, rd801⟩ := hreach - have rd806 := evm_run rd801 with [ - jumpdest, dup5, dup3, dup6, callvalue] - rw [hwv] at rd806 - have rd818 := evm_run rd806 with [ - push2 ⟨938⟩, jumpiNT (by decide), - push1 ⟨32⟩, calldatasize, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd818 - rw [hslt] at rd818 - exact evm_run rd818 with [ - push2 ⟨938⟩, jumpiT (by decide) (by native_decide), - jumpdest, dup3, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsTransferGovernorX_noncanon_newGovernor {cA gh bl σ σ₀ A I} - {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hnc : UInt256.eq (transferGovernorNewGovernorWord I) - (UInt256.land (transferGovernorNewGovernorWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) transferGovernorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2831⟩ := - cometRewardsTransferGovernorX_dec2831_newGovernor (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hsz36 hsize hhi hreach - exact evm_run rd2831 with [ - jumpdest, push1 ⟨4⟩, calldataload, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, dup3, sub, - push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hclean : - UInt256.eq (transferGovernorNewGovernorWord I) - (UInt256.land (transferGovernorNewGovernorWord I) solcAddrMask) = ⟨1⟩ := by - have heq' : transferGovernorNewGovernorWord I = - UInt256.land (transferGovernorNewGovernorWord I) solcAddrMask := by - simpa [transferGovernorNewGovernorWord, calldataWord] using heq - rw [← heq'] - exact uInt256_eq_self _ - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem transferGovernorStoredWord_evm_expr (σ : AccountMap) (I : ExecutionEnv) : - UInt256.lor - (UInt256.land (transferGovernorNewGovernorWord I) solcAddrMask) - (UInt256.land (UInt256.lnot solcAddrMask) (governorWord σ I)) = - transferGovernorStoredWord σ I := by - unfold transferGovernorStoredWord setAddressOffset0Word - rw [u256_land_comm (UInt256.lnot solcAddrMask) (governorWord σ I)] - exact u256_lor_comm - (UInt256.land (transferGovernorNewGovernorWord I) solcAddrMask) - (UInt256.land (governorWord σ I) (UInt256.lnot solcAddrMask)) - -theorem solcWord_eq_of_maskedAddress_eq_source {w : UInt256} {I : ExecutionEnv} - (h : AccountAddress.ofNat (UInt256.land w solcAddrMask).toNat = I.source) : - UInt256.land w solcAddrMask = solcSourceWord I := by - apply u256_inj - have hcanon := solcAddrMask_result_canonical w - have hval := congrArg Fin.val h - unfold AccountAddress.ofNat at hval - rw [Fin.val_ofNat] at hval - rw [solcSourceWord_toNat] - rw [Nat.mod_eq_of_lt (by - simpa [EVM.addressModulus, EVM.twoPow, AccountAddress.size] using hcanon)] at hval - exact hval - -theorem transferGovernorStore_newGovernor (I : ExecutionEnv) : - (transferGovernorStore I).get? "newGovernor" = - some (transferGovernorNewGovernorValue I) := by - rw [transferGovernorStore, store_get_self] - -theorem transferGovernorStore_governor (I : ExecutionEnv) : - (transferGovernorStore I).get? "governor" = none := by - rw [transferGovernorStore, store_get_ne _ _ (by decide)] - native_decide - -theorem evalExpr_transferGovernor_newGovernor (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (transferGovernorFrame evm I) evm (.var "newGovernor") = - .ok (transferGovernorNewGovernorValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), transferGovernorStore_newGovernor] - -theorem evalExpr_transferGovernor_governor (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (transferGovernorFrame evm I) evm (.storage governorRef) = - .ok (.address (AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat)) := by - have her : evalStorageRef config - (transferGovernorFrame evm I) evm governorRef = - .ok { base := "governor", steps := [] } := by - simp [evalStorageRef, evalStorageRefSteps, governorRef, EvalResult.bind, pure, bind] - have hty : storageTypeAt? contract.storage - ({ base := "governor", steps := [] } : EvaledStorageRef) = some (.elem .address) := by - decide - rw [evalExpr_storage_scalar (t := .address) - (hbase := by - change ((transferGovernorStore I).insert "__calldata" - (.bytes evm.executionEnv.calldata)).get? "governor" = none - rw [store_get_ne _ _ (by decide)] - exact transferGovernorStore_governor I) - (her := her) (hty := hty) (hloc := by rfl), - cometRewardsStorageLocLoad_address_offset0] - -theorem evalExpr_transferGovernor_sender (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (transferGovernorFrame evm I) evm sender = - .ok (.address evm.executionEnv.source) := by - simp [sender, evalExpr?, envValue, pure] - -theorem evalExpr_transferGovernor_auth_true (evm : EVM.State) (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) : - evalExpr? config (transferGovernorFrame evm I) evm - (.binary .eq sender (.storage governorRef)) = .ok (.bool true) := by - simp only [evalExpr?, evalExpr_transferGovernor_sender, evalExpr_transferGovernor_governor, - bind, EvalResult.bind, evalBinaryOp?] - rw [solcMaskedAddress_eq_source_of_word_eq (I := evm.executionEnv) hgov] - simp [BEq.beq] - -theorem evalExpr_transferGovernor_auth_false (evm : EVM.State) (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask ≠ - solcSourceWord evm.executionEnv) : - evalExpr? config (transferGovernorFrame evm I) evm - (.binary .eq sender (.storage governorRef)) = .ok (.bool false) := by - simp only [evalExpr?, evalExpr_transferGovernor_sender, evalExpr_transferGovernor_governor, - bind, EvalResult.bind, evalBinaryOp?] - have haddr : - evm.executionEnv.source ≠ - AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat := by - intro haddr - exact hgov (by - exact solcWord_eq_of_maskedAddress_eq_source (I := evm.executionEnv) haddr.symm) - rw [show ((.address evm.executionEnv.source : Value) == - .address (AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat)) = false by - simp [BEq.beq, haddr]] - -theorem transferGovernorAssignGovernor (evm : EVM.State) (I : ExecutionEnv) - (hcanon : (transferGovernorNewGovernorWord I).toNat < EVM.addressModulus) : - assignStorageRef? config (transferGovernorFrame evm I) - evm .storage governorRef (transferGovernorNewGovernorValue I) = - .ok (transferGovernorFrame evm I, transferGovernorPostState evm I) := by - have her : evalStorageRef config - (transferGovernorFrame evm I) evm governorRef = - .ok { base := "governor", steps := [] } := by - simp [evalStorageRef, evalStorageRefSteps, governorRef, EvalResult.bind, pure, bind] - have hty : storageTypeAt? contract.storage - ({ base := "governor", steps := [] } : EvaledStorageRef) = some (.elem .address) := by - decide - have hstore : - storageLocStore evm (fieldLoc ⟨0⟩ 0 20 (by decide) .address) - (transferGovernorNewGovernorValue I) = - some (transferGovernorPostState evm I) := by - simpa [transferGovernorPostState, transferGovernorNewGovernorValue, - fieldLoc, loc, addressOffset0Loc] using - storageLocStore_address_offset0 evm ⟨0⟩ - (transferGovernorNewGovernorWord I) hcanon - exact assignStorageRef_storage_scalar_value (cfg := config) - (solm := transferGovernorFrame evm I) - (evm := evm) (evm' := transferGovernorPostState evm I) - (slot := governorRef) (er := { base := "governor", steps := [] }) - (ty := .elem .address) (loc := fieldLoc ⟨0⟩ 0 20 (by decide) .address) - (value := transferGovernorNewGovernorValue I) - (by - change ((transferGovernorStore I).insert "__calldata" - (.bytes evm.executionEnv.calldata)).get? "governor" = none - rw [store_get_ne _ _ (by decide)] - exact transferGovernorStore_governor I) - her hty (by rfl) (by trivial) hstore - -theorem cometRewardsTransferGovernorBodyReturns (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (hcanon : (transferGovernorNewGovernorWord I).toNat < EVM.addressModulus) : - ExecTransitionBody config contract evm (transferGovernorStore I) - transferGovernorTransition.body - (.returned - (transferGovernorFrame evm I) - (transferGovernorPostState evm I) none) := by - refine ExecFuncBody.execBlockOK ?_ - simpa [transferGovernorTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - ((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (transferGovernorStore I) hsize)).requireStep - (evalExpr_transferGovernor_auth_true evm I hgov)).run - (ExecBlock.consNormal - (ExecStmt.assign (evalExpr_transferGovernor_newGovernor evm I) - (transferGovernorAssignGovernor evm I hcanon)) - ExecBlock.nil) - -theorem cometRewardsTransferGovernorBodyReverts_auth (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask ≠ - solcSourceWord evm.executionEnv) : - ExecTransitionBody config contract evm (transferGovernorStore I) - transferGovernorTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [transferGovernorTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - ((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (transferGovernorStore I) hsize)).requireRevert - (evalExpr_transferGovernor_auth_false evm I hgov)) - -theorem cometRewardsTransferGovernorBodyRevertsHuge (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hbig : 2 ^ 255 + 4 ≤ evm.executionEnv.calldata.size) : - ExecTransitionBody config contract evm (transferGovernorStore I) - transferGovernorTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [transferGovernorTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireRevert - (cometRewardsCalldataGuard_false evm (transferGovernorStore I) hbig)) - -def transferGovernorUnauthorizedSelector : UInt256 := - UInt256.shiftLeft (⟨431085831⟩ : UInt256) ⟨227⟩ - -noncomputable def transferGovernorUnauthorizedMem (caller : UInt256) : ByteArray := - (UInt256.toByteArray caller).write 0 - (solcReturnMem transferGovernorUnauthorizedSelector) 132 32 - -set_option maxHeartbeats 1000000 in -theorem cometRewardsX_transferGovernor_success {cA gh bl σ σ₀ A I} {g : Sat256} - (hperm : I.perm = true) - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon : (transferGovernorNewGovernorWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) transferGovernorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) - (cA, sstoreAccountMap I.codeOwner σ ⟨0⟩ (transferGovernorStoredWord σ I)) - ByteArray.empty := by - obtain ⟨_, _, rd829⟩ := - cometRewardsTransferGovernorX_dec829_newGovernor (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz36 hsize hhi hcanon hreach - have rd831 := evm_run rd829 with [jumpdest, dup4] - obtain ⟨_, _, rd832₀⟩ := rd831.sload (by decide) (by evm_ov) - obtain ⟨_, _, rd832⟩ : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨832⟩ - [governorWord σ I, transferGovernorNewGovernorWord I, ⟨64⟩, ⟨4⟩, ⟨0⟩, - cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by simpa [governorWord] using rd832₀⟩ - have rd856₀ := evm_run rd832 with [ - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup1, dup3, and, - swap5, swap2, swap4, swap3, swap1, swap2, caller, dup7, swap1, sub] - have rd856 := rd856₀ - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] at rd856 - rw [show UInt256.sub (solcSourceWord I) (governorReturnWord σ I) = ⟨0⟩ by - rw [← hauth, u256_sub_self]] at rd856 - have rd857 := evm_run rd856 with [push2 ⟨915⟩, jumpiNT (by decide)] - have rd873₀ := evm_run rd857 with [ - pop, and, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, swap3, swap1, - swap3, and, dup3] - have rd874₀ := RD.lor rd873₀ (by decide) (by evm_ov) - have rd874 := rd874₀ - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] at rd874 - rw [transferGovernorStoredWord_evm_expr] at rd874 - have rd875 := evm_run rd874 with [dup5] - obtain ⟨_, _, rd876₀⟩ := rd875.sstore hperm (by decide) (by evm_ov) - obtain ⟨_, _, rd876⟩ : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨876⟩ - [⟨64⟩, UInt256.land (transferGovernorNewGovernorWord I) solcAddrMask, - governorReturnWord σ I, ⟨0⟩, cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, sstoreAccountMap I.codeOwner σ ⟨0⟩ (transferGovernorStoredWord σ I)) k C := by - exact ⟨_, _, by simpa [governorReturnWord] using rd876₀⟩ - have rd878 := evm_run rd876 with [ - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - swap2] - have rd911 := rd878.pushConst - (⟨50513617581459704403207506987288494667897455834126950341013904819243569522016⟩ : - UInt256) - (width := 32) (op := .PUSH32) (by decide) (by decide) (by evm_ov) - have rd913 := evm_run rd911 with [dup5, dup5] - have rd914 := rd913.log3 0 (UInt256.ofNat 3) (by decide) hperm mem_cost - (by decide) (by evm_ov) - exact evm_run rd914 with [ - raw ret 0 ByteArray.empty (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - show (⟨0⟩ : UInt256).toNat = 0 from by decide] - exact byteArray_readWithPadding_zero _ 128) - (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsX_transferGovernor_revert_auth {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon : (transferGovernorNewGovernorWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I ≠ solcSourceWord I) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) transferGovernorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd829⟩ := - cometRewardsTransferGovernorX_dec829_newGovernor (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz36 hsize hhi hcanon hreach - have rd831 := evm_run rd829 with [jumpdest, dup4] - obtain ⟨_, _, rd832₀⟩ := rd831.sload (by decide) (by evm_ov) - obtain ⟨_, _, rd832⟩ : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨832⟩ - [governorWord σ I, transferGovernorNewGovernorWord I, ⟨64⟩, ⟨4⟩, ⟨0⟩, - cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by simpa [governorWord] using rd832₀⟩ - have rd856₀ := evm_run rd832 with [ - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup1, dup3, and, - swap5, swap2, swap4, swap3, swap1, swap2, caller, dup7, swap1, sub] - have rd856 := rd856₀ - have hsub : UInt256.sub (solcSourceWord I) (governorReturnWord σ I) ≠ ⟨0⟩ := by - exact u256_sub_ne_zero_of_ne (by - intro h - exact hauth h.symm) - exact evm_run rd856 with [ - push2 ⟨915⟩, jumpiT (by simpa using hsub) (by native_decide), - jumpdest, push1 ⟨36⟩, swap1, dup5, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - swap1, push4 ⟨431085831⟩, push1 ⟨227⟩, shl, dup3, - raw mstore 6 (solcReturnMem transferGovernorUnauthorizedSelector) - (UInt256.ofNat 5) (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - rfl) - (by decide) (by evm_ov), - caller, swap1, dup3, add, - raw mstore 3 (transferGovernorUnauthorizedMem (solcSourceWord I)) - (UInt256.ofNat 6) (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256) + ⟨4⟩ = ⟨132⟩ from by decide, - show (⟨132⟩ : UInt256).toNat = 132 from by decide] - unfold transferGovernorUnauthorizedMem solcSourceWord - rfl) - (by decide) (by evm_ov), - raw rev 0 (by decide) mem_cost (by evm_ov)] - -/-- `transferGovernor(address)` body, reached at pc 801. -/ -theorem cometRewardsTransferGovernorBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hsel : selIs I (cometRewardsSelBytes 9)) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) transferGovernorPc - (dispatchArmMidStack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have _hperm : I.perm = true := hperm - have hsz4 := cometRewardsTransferGovernorSelector_size hsel - have hd := cometRewardsDispatch_transferGovernor (cd := I.calldata) hsel - by_cases hsz36 : 36 ≤ I.calldata.size - · by_cases hhi : I.calldata.size < 2 ^ 255 + 4 - · by_cases hcanon : (transferGovernorNewGovernorWord I).toNat < EVM.addressModulus - · have hdec := cometRewardsDecode_transferGovernor_ok (I := I) hsz36 hhi hcanon - have hword : governorWord σ_evm I = governorWord σ_solm I := - accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ ⟨0⟩ - have hretWord : governorReturnWord σ_evm I = governorReturnWord σ_solm I := by - simp [governorReturnWord, hword] - by_cases hauth : governorReturnWord σ_evm I = solcSourceWord I - · have hauthSolm : governorReturnWord σ_solm I = solcSourceWord I := by - rw [← hretWord] - exact hauth - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (transferGovernorStore I) - transferGovernorTransition.body - (.returned - (transferGovernorFrame - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I) - (transferGovernorPostState - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I) - none) := by - exact cometRewardsTransferGovernorBodyReturns - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - (by - simpa [governorReturnWord, governorWord, initState, Solm.EVM.storageLoad, - State.lookupAccount] using hauthSolm) - hcanon - have hstored : - transferGovernorStoredWord σ_evm I = transferGovernorStoredWord σ_solm I := by - simp [transferGovernorStoredWord, hword] - have hcreated : - (cA, sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (transferGovernorStoredWord σ_evm I)).1 = - (transferGovernorPostState - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I).createdAccounts := by - simp [transferGovernorPostState, initState, storageStore_createdAccounts] - have hAccountsPost : - accountMapEquiv - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (transferGovernorStoredWord σ_evm I)) - (transferGovernorPostState - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I).accountMap := by - unfold transferGovernorPostState - rw [storageStore_accountMap] - change accountMapEquiv - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (transferGovernorStoredWord σ_evm I)) - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (transferGovernorStoredWord σ_solm I)) - rw [← hstored] - exact accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (transferGovernorStoredWord σ_evm I) hAccounts - exact (cometRewardsX_transferGovernor_success (g := Sat256.ofUInt256 g) - hperm hwv hsz36 hsize hhi hcanon hauth hreach) - |>.reEquivExecutionGenAccountMapEquiv hcode hd hdec hbody hcreated - hAccountsPost - (returnEquiv.fallthrough rfl (by rfl) (by native_decide)) - · have hauthSolm : - governorReturnWord σ_solm I ≠ solcSourceWord I := by - intro hbad - exact hauth (by - rw [hretWord] - exact hbad) - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (transferGovernorStore I) - transferGovernorTransition.body .reverted := by - exact cometRewardsTransferGovernorBodyReverts_auth - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - (by - simpa [governorReturnWord, governorWord, initState, Solm.EVM.storageLoad, - State.lookupAccount] using hauthSolm) - exact (cometRewardsX_transferGovernor_revert_auth (g := Sat256.ofUInt256 g) - hwv hsz36 hsize hhi hcanon hauth hreach) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have hdec := cometRewardsDecode_transferGovernor_none_noncanon - (I := I) hsz36 hhi hcanon - have hnc : UInt256.eq (transferGovernorNewGovernorWord I) - (UInt256.land (transferGovernorNewGovernorWord I) solcAddrMask) = ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanon (solcAddrCanonical_of_clean he)) - exact (cometRewardsTransferGovernorX_noncanon_newGovernor (g := Sat256.ofUInt256 g) - hwv hsz36 hsize hhi hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hbig : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - have hdec := cometRewardsDecode_transferGovernor_none_huge (I := I) hbig - exact (cometRewardsTransferGovernorX_hugearg (g := Sat256.ofUInt256 g) - hwv hsize hbig hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hshort : I.calldata.size < 36 := by omega - have hdec := cometRewardsDecode_transferGovernor_none_short (I := I) hsz4 hshort - exact (cometRewardsTransferGovernorX_shortarg (g := Sat256.ofUInt256 g) - hwv hsz4 hsize hshort hreach) - |>.reEquivDecodingFailed hcode hd hdec - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/WithdrawToken.lean b/Benchmarks/CompoundIII/CometRewards/WithdrawToken.lean deleted file mode 100644 index e905e8a8..00000000 --- a/Benchmarks/CompoundIII/CometRewards/WithdrawToken.lean +++ /dev/null @@ -1,2431 +0,0 @@ -import Benchmarks.CompoundIII.CometRewards.Common -import Benchmarks.CompoundIII.CometRewards.Governor -import Benchmarks.CompoundIII.CometRewards.TransferGovernor -import Reasoning.ExternalCall - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace Benchmarks.CompoundIII.CometRewards - -/-! ## `withdrawToken(address,address,uint256)` -/ - -abbrev withdrawTokenTokenWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -abbrev withdrawTokenToWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 36 - -abbrev withdrawTokenAmountWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 68 - -abbrev withdrawTokenTokenValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (withdrawTokenTokenWord I).toNat) - -abbrev withdrawTokenToValue (I : ExecutionEnv) : Value := - .address (AccountAddress.ofNat (withdrawTokenToWord I).toNat) - -abbrev withdrawTokenAmountValue (I : ExecutionEnv) : Value := - .int (Int.ofNat (withdrawTokenAmountWord I).toNat) - -abbrev withdrawTokenStore (I : ExecutionEnv) : Store := - (((∅ : Store).insert "token" (withdrawTokenTokenValue I)).insert "to" - (withdrawTokenToValue I)).insert "amount" (withdrawTokenAmountValue I) - -abbrev withdrawTokenFrame (evm : EVM.State) (I : ExecutionEnv) : Frame := - { contract := contract, - locals := (withdrawTokenStore I).insert "__calldata" (.bytes evm.executionEnv.calldata) } - -abbrev withdrawTokenArgs (I : ExecutionEnv) : List Value := - [withdrawTokenTokenValue I, withdrawTokenToValue I, withdrawTokenAmountValue I] - -abbrev withdrawTokenTransferArgs (I : ExecutionEnv) : List Value := - [withdrawTokenToValue I, withdrawTokenAmountValue I] - -abbrev withdrawTokenTransferTarget (I : ExecutionEnv) : AccountAddress := - AccountAddress.ofNat (withdrawTokenTokenWord I).toNat - -abbrev doTransferOutStore (I : ExecutionEnv) : Store := - (((∅ : Store).insert "amount" (withdrawTokenAmountValue I)).insert "to" - (withdrawTokenToValue I)).insert "token" (withdrawTokenTokenValue I) - -abbrev withdrawTokenCallStore (I : ExecutionEnv) (success : Bool) : Store := - (doTransferOutStore I).insert "success" (.bool success) - -abbrev withdrawTokenTransferSelectorWord : UInt256 := ⟨2835717307⟩ - -abbrev withdrawTokenTransferSelectorShifted : UInt256 := - UInt256.shiftLeft withdrawTokenTransferSelectorWord ⟨224⟩ - -noncomputable def withdrawTokenTransferSelectorMem : ByteArray := - (UInt256.toByteArray withdrawTokenTransferSelectorShifted).write 0 solcFreePtrMem 128 32 - -noncomputable def withdrawTokenTransferArgsMem (recipient : UInt256) : ByteArray := - (UInt256.toByteArray recipient).write 0 withdrawTokenTransferSelectorMem 132 32 - -noncomputable def withdrawTokenTransferCalldataMem (recipient value : UInt256) : ByteArray := - (UInt256.toByteArray value).write 0 (withdrawTokenTransferArgsMem recipient) 164 32 - -abbrev withdrawTokenTransferCallPc : UInt256 := - (⟨3950⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + UInt256.ofNat 2 + - UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ - -abbrev withdrawTokenTransferCallSize : UInt256 := - ((⟨64⟩ : UInt256) + (⟨128⟩ + ⟨4⟩)).sub ⟨128⟩ - -abbrev withdrawTokenPostCallTail (I : ExecutionEnv) : List UInt256 := - [⟨128⟩, withdrawTokenToWord I, withdrawTokenAmountWord I, ⟨1001⟩, ⟨64⟩, ⟨0⟩, - ⟨4⟩, cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - -abbrev withdrawTokenPostCallStack (z : Bool) (I : ExecutionEnv) : List UInt256 := - (if z then ⟨1⟩ else ⟨0⟩) :: withdrawTokenPostCallTail I - -noncomputable abbrev withdrawTokenPostCallMem (I : ExecutionEnv) (out : ByteArray) : ByteArray := - out.write 0 - (withdrawTokenTransferCalldataMem (withdrawTokenToWord I) (withdrawTokenAmountWord I)) - 128 (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat - -abbrev withdrawTokenPostCallAw : UInt256 := - UInt256.ofNat (MachineState.M - (MachineState.M (UInt256.ofNat 7).toNat (⟨128⟩ : UInt256).toNat - withdrawTokenTransferCallSize.toNat) - (⟨128⟩ : UInt256).toNat (⟨32⟩ : UInt256).toNat) - -theorem withdrawTokenTransferCallPc_eq : - withdrawTokenTransferCallPc = ⟨3963⟩ := by - native_decide - -theorem withdrawTokenTransferCallSize_eq : - withdrawTokenTransferCallSize = ⟨68⟩ := by - native_decide - -theorem u256_of_accountAddress_ofNat_toNat_of_canonical {w : UInt256} - (hw : w.toNat < EVM.addressModulus) : - UInt256.ofNat (AccountAddress.ofNat w.toNat).val = w := by - apply u256_inj - rw [ulit_toNat' _ (lt_trans (AccountAddress.ofNat w.toNat).isLt - (by decide : AccountAddress.size < UInt256.size))] - simp [AccountAddress.ofNat] - exact Nat.mod_eq_of_lt hw - -theorem withdrawTokenStore_token (I : ExecutionEnv) : - (withdrawTokenStore I).get? "token" = some (withdrawTokenTokenValue I) := by - rw [withdrawTokenStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_self] - -theorem withdrawTokenStore_to (I : ExecutionEnv) : - (withdrawTokenStore I).get? "to" = some (withdrawTokenToValue I) := by - rw [withdrawTokenStore, store_get_ne _ _ (by decide), store_get_self] - -theorem withdrawTokenStore_amount (I : ExecutionEnv) : - (withdrawTokenStore I).get? "amount" = some (withdrawTokenAmountValue I) := by - rw [withdrawTokenStore, store_get_self] - -theorem withdrawTokenCallStore_success (I : ExecutionEnv) (success : Bool) : - (withdrawTokenCallStore I success).get? "success" = some (.bool success) := by - rw [withdrawTokenCallStore, store_get_self] - -theorem doTransferOutStore_token (I : ExecutionEnv) : - (doTransferOutStore I).get? "token" = some (withdrawTokenTokenValue I) := by - rw [doTransferOutStore, store_get_self] - -theorem doTransferOutStore_to (I : ExecutionEnv) : - (doTransferOutStore I).get? "to" = some (withdrawTokenToValue I) := by - rw [doTransferOutStore, store_get_ne _ _ (by decide), store_get_self] - -theorem doTransferOutStore_amount (I : ExecutionEnv) : - (doTransferOutStore I).get? "amount" = some (withdrawTokenAmountValue I) := by - rw [doTransferOutStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_self] - -theorem evalExpr_withdrawToken_var_token (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config { contract := contract, locals := withdrawTokenStore I } evm - (.var "token") = .ok (withdrawTokenTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [withdrawTokenStore_token] - -theorem evalExpr_withdrawToken_var_to (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config { contract := contract, locals := withdrawTokenStore I } evm - (.var "to") = .ok (withdrawTokenToValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [withdrawTokenStore_to] - -theorem evalExpr_withdrawToken_var_amount (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config { contract := contract, locals := withdrawTokenStore I } evm - (.var "amount") = .ok (withdrawTokenAmountValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [withdrawTokenStore_amount] - -theorem evalExprs_withdrawToken_args (evm : EVM.State) (I : ExecutionEnv) : - evalExprs? config { contract := contract, locals := withdrawTokenStore I } evm - [.var "token", .var "to", .var "amount"] = .ok (withdrawTokenArgs I) := by - simp only [withdrawTokenArgs, evalExprs?, evalExpr_withdrawToken_var_token, - evalExpr_withdrawToken_var_to, evalExpr_withdrawToken_var_amount, EvalResult.bind, bind] - rfl - -theorem evalExprs_withdrawToken_transfer_args (evm : EVM.State) (I : ExecutionEnv) : - evalExprs? config { contract := contract, locals := withdrawTokenStore I } evm - [.var "to", .var "amount"] = .ok (withdrawTokenTransferArgs I) := by - simp only [withdrawTokenTransferArgs, evalExprs?, evalExpr_withdrawToken_var_to, - evalExpr_withdrawToken_var_amount, EvalResult.bind, bind] - rfl - -theorem evalExpr_withdrawToken_success (evm : EVM.State) (I : ExecutionEnv) (success : Bool) : - evalExpr? config { contract := contract, locals := withdrawTokenCallStore I success } evm - (.var "success") = .ok (.bool success) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [withdrawTokenCallStore_success] - -theorem evalExpr_withdrawToken_frame_token (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (withdrawTokenFrame evm I) evm - (.var "token") = .ok (withdrawTokenTokenValue I) := by - simp only [withdrawTokenFrame, evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), withdrawTokenStore_token] - -theorem evalExpr_withdrawToken_frame_to (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (withdrawTokenFrame evm I) evm - (.var "to") = .ok (withdrawTokenToValue I) := by - simp only [withdrawTokenFrame, evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), withdrawTokenStore_to] - -theorem evalExpr_withdrawToken_frame_amount (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (withdrawTokenFrame evm I) evm - (.var "amount") = .ok (withdrawTokenAmountValue I) := by - simp only [withdrawTokenFrame, evalExpr?, EvalResult.ofOption] - rw [store_get_ne _ _ (by decide), withdrawTokenStore_amount] - -theorem evalExprs_withdrawToken_frame_args (evm : EVM.State) (I : ExecutionEnv) : - evalExprs? config (withdrawTokenFrame evm I) evm - [.var "token", .var "to", .var "amount"] = .ok (withdrawTokenArgs I) := by - simp only [withdrawTokenArgs, evalExprs?, evalExpr_withdrawToken_frame_token, - evalExpr_withdrawToken_frame_to, evalExpr_withdrawToken_frame_amount, EvalResult.bind, bind] - rfl - -theorem evalExpr_doTransferOut_var_token (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config { contract := contract, locals := doTransferOutStore I } evm - (.var "token") = .ok (withdrawTokenTokenValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [doTransferOutStore_token] - -theorem evalExpr_doTransferOut_var_to (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config { contract := contract, locals := doTransferOutStore I } evm - (.var "to") = .ok (withdrawTokenToValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [doTransferOutStore_to] - -theorem evalExpr_doTransferOut_var_amount (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config { contract := contract, locals := doTransferOutStore I } evm - (.var "amount") = .ok (withdrawTokenAmountValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [doTransferOutStore_amount] - -theorem evalExprs_doTransferOut_transfer_args (evm : EVM.State) (I : ExecutionEnv) : - evalExprs? config { contract := contract, locals := doTransferOutStore I } evm - [.var "to", .var "amount"] = .ok (withdrawTokenTransferArgs I) := by - simp only [withdrawTokenTransferArgs, evalExprs?, evalExpr_doTransferOut_var_to, - evalExpr_doTransferOut_var_amount, EvalResult.bind, bind] - rfl - -theorem bindParams_doTransferOut (I : ExecutionEnv) : - bindParams? doTransferOutFunction.params (withdrawTokenArgs I) = - some (doTransferOutStore I) := by - simp [doTransferOutFunction, withdrawTokenArgs, withdrawTokenTokenValue, doTransferOutStore, - withdrawTokenToValue, withdrawTokenAmountValue, bindParams?] - -theorem lookupCallable_doTransferOut : - lookupCallable? contract "doTransferOut" = some doTransferOutFunction.toCallable := by - rfl - -theorem withdrawTokenTransferSelectorMem_size : - withdrawTokenTransferSelectorMem.size = 160 := - solcReturnMem_size withdrawTokenTransferSelectorShifted - -theorem withdrawTokenTransferArgsMem_size (recipient : UInt256) : - (withdrawTokenTransferArgsMem recipient).size = 164 := by - unfold withdrawTokenTransferArgsMem - rw [write32_eq _ _ _ (by rw [toByteArray_size]) - (by rw [withdrawTokenTransferSelectorMem_size]; omega), - ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, withdrawTokenTransferSelectorMem_size, - toByteArray_size] - omega - -theorem withdrawTokenTransferCalldataMem_size (recipient value : UInt256) : - (withdrawTokenTransferCalldataMem recipient value).size = 196 := by - unfold withdrawTokenTransferCalldataMem - rw [write32_eq _ _ _ (by rw [toByteArray_size]) - (by rw [withdrawTokenTransferArgsMem_size])] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, withdrawTokenTransferArgsMem_size, - toByteArray_size] - omega - -theorem withdrawTokenTransferCalldataMem_read128_4 (recipient value : UInt256) : - (withdrawTokenTransferCalldataMem recipient value).readWithPadding 128 4 = - transferSelector := by - unfold withdrawTokenTransferCalldataMem - rw [write32_read_below_len _ _ 164 128 4 (by rw [toByteArray_size]) - (by rw [withdrawTokenTransferArgsMem_size]) - (by omega) - (by rw [withdrawTokenTransferArgsMem_size]; omega) - (by norm_num) (by norm_num)] - unfold withdrawTokenTransferArgsMem - rw [write32_read_below_len _ _ 132 128 4 (by rw [toByteArray_size]) - (by rw [withdrawTokenTransferSelectorMem_size]; omega) (by omega) - (by rw [withdrawTokenTransferSelectorMem_size]; omega) - (by norm_num) (by norm_num)] - have hzero32 : (ffi.ByteArray.zeroes (USize.ofNat 32)).size = 32 := by - rw [ByteArray_zeroes_size] - exact USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num)) - rw [show withdrawTokenTransferSelectorMem = - solcReturnMem withdrawTokenTransferSelectorShifted from rfl] - rw [readWithPadding_eq_extract' _ 128 4 (by norm_num) (by norm_num) - (by rw [solcReturnMem_size]; omega)] - rw [solcReturnMem_eq] - rw [extract_append_right_window - (solcFreePtrMem ++ ffi.ByteArray.zeroes (USize.ofNat 32)) - (UInt256.toByteArray withdrawTokenTransferSelectorShifted) 128 132 (by - simp [ByteArray.size_append, solcFreePtrMem_size, hzero32])] - rw [ByteArray.size_append, solcFreePtrMem_size, hzero32] - native_decide - -theorem withdrawTokenTransferCalldataMem_read132_32 (recipient value : UInt256) : - (withdrawTokenTransferCalldataMem recipient value).readWithPadding 132 32 = - UInt256.toByteArray recipient := by - unfold withdrawTokenTransferCalldataMem - rw [write32_read_below _ _ 164 132 (by rw [toByteArray_size]) - (by rw [withdrawTokenTransferArgsMem_size]) - (by omega)] - unfold withdrawTokenTransferArgsMem - rw [write32_read_back _ _ _ (by rw [toByteArray_size]) - (by rw [withdrawTokenTransferSelectorMem_size]; omega)] - rw [show (UInt256.toByteArray recipient).extract 0 32 = UInt256.toByteArray recipient by - rw [show 32 = (UInt256.toByteArray recipient).size by rw [toByteArray_size]] - exact byteArray_extract_self _] - -theorem withdrawTokenTransferCalldataMem_read164_32 (recipient value : UInt256) : - (withdrawTokenTransferCalldataMem recipient value).readWithPadding 164 32 = - UInt256.toByteArray value := by - unfold withdrawTokenTransferCalldataMem - rw [write32_read_back _ _ _ (by rw [toByteArray_size]) - (by rw [withdrawTokenTransferArgsMem_size])] - rw [show (UInt256.toByteArray value).extract 0 32 = UInt256.toByteArray value by - rw [show 32 = (UInt256.toByteArray value).size by rw [toByteArray_size]] - exact byteArray_extract_self _] - -theorem withdrawTokenTransferCalldataMem_read128_68 (recipient value : UInt256) : - (withdrawTokenTransferCalldataMem recipient value).readWithPadding 128 68 = - transferSelector ++ UInt256.toByteArray recipient ++ UInt256.toByteArray value := by - rw [byteArray_readWithPadding_split _ 128 4 64 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) - (by simp [withdrawTokenTransferCalldataMem_size])] - rw [byteArray_readWithPadding_split _ 132 32 32 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) - (by simp [withdrawTokenTransferCalldataMem_size])] - rw [withdrawTokenTransferCalldataMem_read128_4, - withdrawTokenTransferCalldataMem_read132_32, - withdrawTokenTransferCalldataMem_read164_32, ByteArray.append_assoc] - -theorem withdrawTokenTransferCalldataMem_encode (recipient : AccountAddress) (value : UInt256) : - config.externalABI.encode? "transfer" - [.address recipient, .int (Int.ofNat value.toNat)] = - some ((withdrawTokenTransferCalldataMem (UInt256.ofNat recipient.val) value) - |>.readWithPadding 128 68) := by - rw [withdrawTokenTransferCalldataMem_read128_68] - change compoundRewardsExternalABI.encode? "transfer" - [.address recipient, .int (Int.ofNat value.toNat)] = - some (transferSelector ++ - (UInt256.ofNat recipient.val).toByteArray ++ UInt256.toByteArray value) - have hvalueWord : EVM.word value.toNat = value := by - exact u256_ofNat_toNat value - have hrecipientWord : EVM.word recipient.val = UInt256.ofNat recipient.val := by - apply u256_inj - rfl - have hvalueLt : value.toNat < EVM.twoPow 256 := by - change value.val.val < UInt256.size - exact value.val.isLt - unfold compoundRewardsExternalABI ABI.encodeCallWithSelector? ABI.encodeABIValues? - simp [addr, uint256, uint256Int, ABI.abiTupleHeadSize?, ABI.staticABIEncodedSize?, - ABI.isDynamicABIType, ABI.encodeABIValue?, ABI.encodeABIWord?, ABI.encodeABIValuesFrom?, - hvalueLt, hrecipientWord, hvalueWord, word_toBytesBE_toByteArray_eq_toByteArray] - rw [ByteArray.append_assoc] - -theorem withdrawTokenTransferTarget_eq_targetWord (I : ExecutionEnv) - (hcanon0 : (withdrawTokenTokenWord I).toNat < EVM.addressModulus) : - EVM.address (withdrawTokenTransferTarget I) = - AccountAddress.ofUInt256 (UInt256.land solcAddrMask (withdrawTokenTokenWord I)) := by - have hcleanLeft : - UInt256.land (withdrawTokenTokenWord I) solcAddrMask = withdrawTokenTokenWord I := by - exact solcAddrMask_clean (by simpa [withdrawTokenTokenWord, calldataWord] using hcanon0) - have hclean : - UInt256.land solcAddrMask (withdrawTokenTokenWord I) = withdrawTokenTokenWord I := by - rw [u256_land_comm solcAddrMask (withdrawTokenTokenWord I), hcleanLeft] - rw [hclean, accountAddress_ofUInt256_eq_ofNat_toNat] - apply Fin.ext - simp [EVM.address, EVM.uintN] - exact Nat.mod_eq_of_lt (AccountAddress.ofNat (withdrawTokenTokenWord I).toNat).isLt - -set_option maxHeartbeats 1000000 in -theorem withdrawTokenTransferCalldataMem_encode_args (I : ExecutionEnv) - (hcanon1 : (withdrawTokenToWord I).toNat < EVM.addressModulus) : - config.externalABI.encode? "transfer" (withdrawTokenTransferArgs I) = - some ((withdrawTokenTransferCalldataMem (withdrawTokenToWord I) (withdrawTokenAmountWord I)) - |>.readWithPadding 128 withdrawTokenTransferCallSize.toNat) := by - have hsz : withdrawTokenTransferCallSize.toNat = 68 := by - rw [withdrawTokenTransferCallSize_eq] - rfl - rw [hsz] - have hround : - UInt256.ofNat (AccountAddress.ofNat (withdrawTokenToWord I).toNat).val = - withdrawTokenToWord I := - u256_of_accountAddress_ofNat_toNat_of_canonical hcanon1 - have henc := withdrawTokenTransferCalldataMem_encode - (recipient := AccountAddress.ofNat (withdrawTokenToWord I).toNat) - (value := withdrawTokenAmountWord I) - change config.externalABI.encode? "transfer" - [.address (AccountAddress.ofNat (withdrawTokenToWord I).toNat), - .int (Int.ofNat (withdrawTokenAmountWord I).toNat)] = - some ((withdrawTokenTransferCalldataMem (withdrawTokenToWord I) - (withdrawTokenAmountWord I)).readWithPadding 128 68) - rw [hround] at henc - exact henc - -theorem decodeReturnValueWithMode_modern_bool_none_short {returndata : ByteArray} - (hshort : returndata.size < 32) : - ABI.decodeReturnValueWithMode? DecodeMode.modern abiBool returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have htake0n : ¬ ((returndata.toList.drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, hlen] - omega - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [ABIType.elem ElemType.bool]) - (returndata := returndata) (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - simp only [decodeScalarWords?] - have hscalar : - decodeScalarWord? (ABIType.elem ElemType.bool) - returndata.toList 0 = none := by - simpa [abiBool] using - (decodeScalarWord_bool_none_short (bytes := returndata.toList) (start := 0) htake0n) - rw [hscalar] - rfl - -theorem decodeReturnValueWithMode_modern_bool_false {returndata : ByteArray} - (hlo : 32 ≤ returndata.size) (hhi : returndata.size < 2 ^ 255) - (hword : UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32)) = ⟨0⟩) : - ABI.decodeReturnValueWithMode? DecodeMode.modern abiBool returndata = - some (.bool false) := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have htake0 : ((returndata.toList.drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, hlen] - omega - have hwordList := bytesToWord_take32_eq_extract0_32 (returndata := returndata) - have hzero : ABI.bytesToWord ((returndata.toList.drop 0).take 32) = ⟨0⟩ := by - simpa [List.drop_zero, hwordList] using hword - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [ABIType.elem ElemType.bool]) - (returndata := returndata) (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - simp only [decodeScalarWords?] - have hscalar : - decodeScalarWord? (ABIType.elem ElemType.bool) - returndata.toList 0 = some (.bool false, 0 + 32) := by - simpa [abiBool] using - (decodeScalarWord_bool_ok_zero (bytes := returndata.toList) (start := 0) htake0 hzero) - rw [hscalar] - rfl - -theorem decodeReturnValueWithMode_modern_bool_true {returndata : ByteArray} - (hlo : 32 ≤ returndata.size) (hhi : returndata.size < 2 ^ 255) - (hword : UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32)) = ⟨1⟩) : - ABI.decodeReturnValueWithMode? DecodeMode.modern abiBool returndata = - some (.bool true) := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have htake0 : ((returndata.toList.drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, hlen] - omega - have hwordList := bytesToWord_take32_eq_extract0_32 (returndata := returndata) - have hone : ABI.bytesToWord ((returndata.toList.drop 0).take 32) = ⟨1⟩ := by - simpa [List.drop_zero, hwordList] using hword - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [ABIType.elem ElemType.bool]) - (returndata := returndata) (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - simp only [decodeScalarWords?] - have hscalar : - decodeScalarWord? (ABIType.elem ElemType.bool) - returndata.toList 0 = some (.bool true, 0 + 32) := by - simpa [abiBool] using - (decodeScalarWord_bool_ok_one (bytes := returndata.toList) (start := 0) htake0 hone) - rw [hscalar] - rfl - -theorem decodeReturnValueWithMode_modern_bool_none_noncanon {returndata : ByteArray} - (hlo : 32 ≤ returndata.size) (hhi : returndata.size < 2 ^ 255) - (hnz : UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32)) ≠ ⟨0⟩) - (hno : UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32)) ≠ ⟨1⟩) : - ABI.decodeReturnValueWithMode? DecodeMode.modern abiBool returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have htake0 : ((returndata.toList.drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, hlen] - omega - have hwordList := bytesToWord_take32_eq_extract0_32 (returndata := returndata) - have hnzList : ABI.bytesToWord ((returndata.toList.drop 0).take 32) ≠ ⟨0⟩ := by - intro hzero - exact hnz (by simpa [List.drop_zero, hwordList] using hzero) - have hnoList : ABI.bytesToWord ((returndata.toList.drop 0).take 32) ≠ ⟨1⟩ := by - intro hone - exact hno (by simpa [List.drop_zero, hwordList] using hone) - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [ABIType.elem ElemType.bool]) - (returndata := returndata) (by decide)] - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - simp only [decodeScalarWords?] - have hscalar : - decodeScalarWord? (ABIType.elem ElemType.bool) - returndata.toList 0 = none := by - simpa [abiBool] using - (decodeScalarWord_bool_none_noncanon (bytes := returndata.toList) (start := 0) - htake0 hnzList hnoList) - rw [hscalar] - rfl - -theorem decodeReturnValueWithMode_modern_bool_none_huge {returndata : ByteArray} - (hhi : 2 ^ 255 ≤ returndata.size) : - ABI.decodeReturnValueWithMode? DecodeMode.modern abiBool returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValue? - rw [decodeReturnValues_scalarWords_eq (types := [ABIType.elem ElemType.bool]) - (returndata := returndata) (by decide)] - rw [if_pos (by exact ⟨by simp, by rw [hlen]; exact hhi⟩)] - -theorem cometRewardsTransfer_decode_none_short {out : ByteArray} - (hshort : out.size < 32) : - config.externalABI.decode? "transfer" out = none := by - change compoundRewardsExternalABI.decode? "transfer" out = none - unfold compoundRewardsExternalABI decodeReturn? - simpa [boolTy, abiBool] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_bool_none_short (returndata := out) hshort) - -theorem cometRewardsTransfer_decode_none_huge {out : ByteArray} - (hhi : 2 ^ 255 ≤ out.size) : - config.externalABI.decode? "transfer" out = none := by - change compoundRewardsExternalABI.decode? "transfer" out = none - unfold compoundRewardsExternalABI decodeReturn? - simpa [boolTy, abiBool] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_bool_none_huge (returndata := out) hhi) - -theorem cometRewardsTransfer_decode_false {out : ByteArray} - (hlo : 32 ≤ out.size) (hhi : out.size < 2 ^ 255) - (hword : UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) = ⟨0⟩) : - config.externalABI.decode? "transfer" out = some [.bool false] := by - change compoundRewardsExternalABI.decode? "transfer" out = some [.bool false] - unfold compoundRewardsExternalABI decodeReturn? - simpa [boolTy, abiBool] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_bool_false (returndata := out) hlo hhi hword) - -theorem cometRewardsTransfer_decode_true {out : ByteArray} - (hlo : 32 ≤ out.size) (hhi : out.size < 2 ^ 255) - (hword : UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) = ⟨1⟩) : - config.externalABI.decode? "transfer" out = some [.bool true] := by - change compoundRewardsExternalABI.decode? "transfer" out = some [.bool true] - unfold compoundRewardsExternalABI decodeReturn? - simpa [boolTy, abiBool] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_bool_true (returndata := out) hlo hhi hword) - -theorem cometRewardsTransfer_decode_none_noncanon {out : ByteArray} - (hlo : 32 ≤ out.size) (hhi : out.size < 2 ^ 255) - (hnz : UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) ≠ ⟨0⟩) - (hno : UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) ≠ ⟨1⟩) : - config.externalABI.decode? "transfer" out = none := by - change compoundRewardsExternalABI.decode? "transfer" out = none - unfold compoundRewardsExternalABI decodeReturn? - simpa [boolTy, abiBool] using - congrArg (fun x => x.map fun v => [v]) - (decodeReturnValueWithMode_modern_bool_none_noncanon (returndata := out) hlo hhi hnz hno) - -theorem doTransferOutBodyReverts_callFailure - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (withdrawTokenTransferTarget I)) - "transfer" 0 (withdrawTokenTransferArgs I) (false, evm', out) true) : - ExecFuncBody config { contract := contract, locals := doTransferOutStore I } evm - doTransferOutFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config { contract := contract, locals := doTransferOutStore I } evm - [ .externalCall (.var "token") "transfer" (.intLit 0) - [.var "to", .var "amount"] "success", - .require (.var "success") ] .reverted - exact ExecBlock.consRevert - (ExecStmt.externalCallFailure - (evalExpr_doTransferOut_var_token evm I) - (by simp [evalExpr?, pure]) - (evalExprs_doTransferOut_transfer_args evm I) - hcall) - -theorem doTransferOutBodyReverts_decode - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (withdrawTokenTransferTarget I)) - "transfer" 0 (withdrawTokenTransferArgs I) (true, evm', out) true) - (hdec : config.externalABI.decode? "transfer" out = none) : - ExecFuncBody config { contract := contract, locals := doTransferOutStore I } evm - doTransferOutFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config { contract := contract, locals := doTransferOutStore I } evm - [ .externalCall (.var "token") "transfer" (.intLit 0) - [.var "to", .var "amount"] "success", - .require (.var "success") ] .reverted - exact ExecBlock.consRevert - (ExecStmt.externalCallReturnDecodeRevert - (evalExpr_doTransferOut_var_token evm I) - (by simp [evalExpr?, pure]) - (evalExprs_doTransferOut_transfer_args evm I) - hcall hdec) - -set_option maxHeartbeats 1000000 in -theorem doTransferOutBodyReverts_false - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (withdrawTokenTransferTarget I)) - "transfer" 0 (withdrawTokenTransferArgs I) (true, evm', out) true) - (hdec : config.externalABI.decode? "transfer" out = some [.bool false]) : - ExecFuncBody config { contract := contract, locals := doTransferOutStore I } evm - doTransferOutFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - change ExecBlock config { contract := contract, locals := doTransferOutStore I } evm - [ .externalCall (.var "token") "transfer" (.intLit 0) - [.var "to", .var "amount"] "success", - .require (.var "success") ] .reverted - refine ExecBlock.consNormal - (solm' := - { contract := contract, - locals := (doTransferOutStore I).insert "success" (collapseReturns [.bool false]) }) - (evm' := evm') ?_ ?_ - · exact ExecStmt.externalCallSuccess - (cfg := config) - (solm := { contract := contract, locals := doTransferOutStore I }) - (evm := evm) - (receiver := .var "token") (target := withdrawTokenTransferTarget I) - (eth := .intLit 0) (sendVal := 0) - (args := [.var "to", .var "amount"]) (argVals := withdrawTokenTransferArgs I) - (name := "transfer") (retVar := "success") - (evm' := evm') (out := out) (perm := true) (value := [.bool false]) - (evalExpr_doTransferOut_var_token evm I) - (by simp [evalExpr?, pure]) - (evalExprs_doTransferOut_transfer_args evm I) - hcall hdec - · simpa [withdrawTokenCallStore, collapseReturns] using - (ExecBlock.consRevert - (ExecStmt.requireFalse (evalExpr_withdrawToken_success evm' I false))) - -set_option maxHeartbeats 1000000 in -theorem doTransferOutBodyReturns_true - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hcall : - typedCallViaEVM config evm (EVM.address (withdrawTokenTransferTarget I)) - "transfer" 0 (withdrawTokenTransferArgs I) (true, evm', out) true) - (hdec : config.externalABI.decode? "transfer" out = some [.bool true]) : - ExecFuncBody config { contract := contract, locals := doTransferOutStore I } evm - doTransferOutFunction.body - (.returned { contract := contract, locals := withdrawTokenCallStore I true } evm' none) := by - refine ExecFuncBody.execBlockOK ?_ - change ExecBlock config { contract := contract, locals := doTransferOutStore I } evm - [ .externalCall (.var "token") "transfer" (.intLit 0) - [.var "to", .var "amount"] "success", - .require (.var "success") ] - (.ok { contract := contract, locals := withdrawTokenCallStore I true } evm') - refine ExecBlock.consNormal - (solm' := - { contract := contract, - locals := (doTransferOutStore I).insert "success" (collapseReturns [.bool true]) }) - (evm' := evm') ?_ ?_ - · exact ExecStmt.externalCallSuccess - (cfg := config) - (solm := { contract := contract, locals := doTransferOutStore I }) - (evm := evm) - (receiver := .var "token") (target := withdrawTokenTransferTarget I) - (eth := .intLit 0) (sendVal := 0) - (args := [.var "to", .var "amount"]) (argVals := withdrawTokenTransferArgs I) - (name := "transfer") (retVar := "success") - (evm' := evm') (out := out) (perm := true) (value := [.bool true]) - (evalExpr_doTransferOut_var_token evm I) - (by simp [evalExpr?, pure]) - (evalExprs_doTransferOut_transfer_args evm I) - hcall hdec - · simpa [withdrawTokenCallStore, collapseReturns] using - (ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_withdrawToken_success evm' I true)) - ExecBlock.nil) - -theorem cometRewardsDecode_withdrawToken_ok {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (withdrawTokenTokenWord I).toNat < EVM.addressModulus) - (hcanon1 : (withdrawTokenToWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode - (withdrawTokenTransition.params.map Param.name) - (transitionSignature withdrawTokenTransition).paramTypes I.calldata = - some (withdrawTokenStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["token", "to", "amount"] - [addr, addr, uint256] I.calldata = _ - change decodeCalldata ["token", "to", "amount"] [.elem .address, .elem .address, abiUInt256] - I.calldata = - some ((((∅ : Store).insert "token" - (.address (AccountAddress.ofNat (calldataWord I.calldata 4).toNat))).insert "to" - (.address (AccountAddress.ofNat (calldataWord I.calldata 36).toNat))).insert "amount" - (.int (Int.ofNat (calldataWord I.calldata 68).toNat))) - exact decodeCalldata_address_address_uint256_ok (cd := I.calldata) - (x := "token") (y := "to") (z := "amount") hsz100 hbig hcanon0 hcanon1 - -theorem cometRewardsDecode_withdrawToken_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 100) : - decodeCalldataWithMode config.abiDecodeMode - (withdrawTokenTransition.params.map Param.name) - (transitionSignature withdrawTokenTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["token", "to", "amount"] - [addr, addr, uint256] I.calldata = none - change decodeCalldata ["token", "to", "amount"] [.elem .address, .elem .address, abiUInt256] - I.calldata = none - exact decodeCalldata_address_address_uint256_none_short - (cd := I.calldata) (x := "token") (y := "to") (z := "amount") hsz4 hshort - -theorem cometRewardsDecode_withdrawToken_none_noncanon_token {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hnc0 : ¬ (withdrawTokenTokenWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode - (withdrawTokenTransition.params.map Param.name) - (transitionSignature withdrawTokenTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["token", "to", "amount"] - [addr, addr, uint256] I.calldata = none - change decodeCalldata ["token", "to", "amount"] [.elem .address, .elem .address, abiUInt256] - I.calldata = none - simpa [withdrawTokenTokenWord, calldataWord] using - decodeCalldata_address_address_uint256_none_noncanon0 - (cd := I.calldata) (x := "token") (y := "to") (z := "amount") hsz100 hbig hnc0 - -theorem cometRewardsDecode_withdrawToken_none_noncanon_to {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (withdrawTokenTokenWord I).toNat < EVM.addressModulus) - (hnc1 : ¬ (withdrawTokenToWord I).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode - (withdrawTokenTransition.params.map Param.name) - (transitionSignature withdrawTokenTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["token", "to", "amount"] - [addr, addr, uint256] I.calldata = none - change decodeCalldata ["token", "to", "amount"] [.elem .address, .elem .address, abiUInt256] - I.calldata = none - simpa [withdrawTokenTokenWord, withdrawTokenToWord, calldataWord] using - decodeCalldata_address_address_uint256_none_noncanon1 - (cd := I.calldata) (x := "token") (y := "to") (z := "amount") hsz100 hbig - hcanon0 hnc1 - -theorem cometRewardsDecode_withdrawToken_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode - (withdrawTokenTransition.params.map Param.name) - (transitionSignature withdrawTokenTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["token", "to", "amount"] - [addr, addr, uint256] I.calldata = none - change decodeCalldata ["token", "to", "amount"] [.elem .address, .elem .address, abiUInt256] - I.calldata = none - exact decodeCalldata_address_address_uint256_none_huge - (cd := I.calldata) (x := "token") (y := "to") (z := "amount") hbig - -theorem cometRewardsWithdrawTokenSelector_size {I : ExecutionEnv} - (hsel : selIs I (cometRewardsSelBytes 0)) : - 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (cometRewardsSelBytes 0) rfl hsel - -theorem cometRewardsDispatch_withdrawToken {cd : ByteArray} - (hsel : (cometRewardsSelBytes 0 == cd.extract 0 4) = true) : - dispatchMsg contract cd = some withdrawTokenTransition := by - refine dispatchMsg_eq_some_of_split - (pre := [claimTransition, claimToTransition, getRewardOwedTransition, governorTransition, - rewardConfigTransition, rewardsClaimedTransition, setRewardConfigTransition, - setRewardConfigWithMultiplierTransition, setRewardsClaimedTransition, transferGovernorTransition]) - (post := []) - rfl rfl ?_ (by rw [selectorOf, withdrawTokenSelectorBytes]; exact hsel) - have hcd : cd.extract 0 4 = cometRewardsSelBytes 0 := - (byteArray_eq_of_beq hsel).symm - intro t ht - simp only [List.mem_cons, List.not_mem_nil, or_false] at ht - rcases ht with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, claimSelectorBytes, hcd] - decide - · rw [selectorOf, claimToSelectorBytes, hcd] - decide - · rw [selectorOf, getRewardOwedSelectorBytes, hcd] - decide - · rw [selectorOf, governorSelectorBytes, hcd] - decide - · rw [selectorOf, rewardConfigSelectorBytes, hcd] - decide - · rw [selectorOf, rewardsClaimedSelectorBytes, hcd] - decide - · rw [selectorOf, setRewardConfigSelectorBytes, hcd] - decide - · rw [selectorOf, setRewardConfigWithMultiplierSelectorBytes, hcd] - decide - · rw [selectorOf, setRewardsClaimedSelectorBytes, hcd] - decide - · rw [selectorOf, transferGovernorSelectorBytes, hcd] - decide - -theorem cometRewardsWithdrawTokenCalldataCheckOk {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hhi : I.calldata.size < 2 ^ 255 + 4) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨0⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨0⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - simpa using - solcCalldataStaticLenCheckOk (sz := I.calldata.size) (words := 3) - (by simpa using hsz100) hhi hsize - -theorem cometRewardsWithdrawTokenCalldataCheckShort {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hshort : I.calldata.size < 100) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 hsz4 hsize] - simpa using - solcCalldataStaticLenCheckShort (sz := I.calldata.size) (words := 3) - hsz4 (by simpa using hshort) hsize (by norm_num) - -theorem cometRewardsWithdrawTokenCalldataCheckHuge {I : ExecutionEnv} - (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - UInt256.slt - ((UInt256.ofNat I.calldata.size) + (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨1⟩ := by - change UInt256.slt - (UInt256.add (UInt256.ofNat I.calldata.size) (UInt256.lnot (⟨3⟩ : UInt256))) - ⟨96⟩ = ⟨1⟩ - rw [cometRewardsCalldataSizeAddNot3_eq_sub4 (by omega) hsize] - simpa using - solcCalldataStaticLenCheckHuge (sz := I.calldata.size) (words := 3) - hbig hsize (by norm_num) - -theorem withdrawTokenStore_governor (I : ExecutionEnv) : - (withdrawTokenStore I).get? "governor" = none := by - rw [withdrawTokenStore, store_get_ne _ _ (by decide), store_get_ne _ _ (by decide), - store_get_ne _ _ (by decide)] - native_decide - -theorem evalExpr_withdrawToken_governor (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (withdrawTokenFrame evm I) evm (.storage governorRef) = - .ok (.address (AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat)) := by - have her : evalStorageRef config - (withdrawTokenFrame evm I) evm governorRef = - .ok { base := "governor", steps := [] } := by - simp [evalStorageRef, evalStorageRefSteps, governorRef, EvalResult.bind, pure, bind] - have hty : storageTypeAt? contract.storage - ({ base := "governor", steps := [] } : EvaledStorageRef) = some (.elem .address) := by - decide - rw [evalExpr_storage_scalar (t := .address) - (hbase := by - change ((withdrawTokenStore I).insert "__calldata" - (.bytes evm.executionEnv.calldata)).get? "governor" = none - rw [store_get_ne _ _ (by decide)] - exact withdrawTokenStore_governor I) - (her := her) (hty := hty) (hloc := by rfl), - cometRewardsStorageLocLoad_address_offset0] - -theorem evalExpr_withdrawToken_sender (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config (withdrawTokenFrame evm I) evm sender = - .ok (.address evm.executionEnv.source) := by - simp [sender, evalExpr?, envValue, pure] - -theorem evalExpr_withdrawToken_auth_false (evm : EVM.State) (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask ≠ - solcSourceWord evm.executionEnv) : - evalExpr? config (withdrawTokenFrame evm I) evm - (.binary .eq sender (.storage governorRef)) = .ok (.bool false) := by - simp only [evalExpr?, evalExpr_withdrawToken_sender, evalExpr_withdrawToken_governor, - bind, EvalResult.bind, evalBinaryOp?] - have haddr : - evm.executionEnv.source ≠ - AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat := by - intro haddr - exact hgov (by - exact solcWord_eq_of_maskedAddress_eq_source (I := evm.executionEnv) haddr.symm) - rw [show ((.address evm.executionEnv.source : Value) == - .address (AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat)) = false by - simp [BEq.beq, haddr]] - -theorem evalExpr_withdrawToken_auth_true (evm : EVM.State) (I : ExecutionEnv) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) : - evalExpr? config (withdrawTokenFrame evm I) evm - (.binary .eq sender (.storage governorRef)) = .ok (.bool true) := by - simp only [evalExpr?, evalExpr_withdrawToken_sender, evalExpr_withdrawToken_governor, - bind, EvalResult.bind, evalBinaryOp?] - have haddr : - evm.executionEnv.source = - AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat := by - rw [hgov] - rw [← accountAddress_ofUInt256_eq_ofNat_toNat] - simpa [solcSourceWord] using - (accountAddress_roundtrip evm.executionEnv.source).symm - rw [show ((.address evm.executionEnv.source : Value) == - .address (AccountAddress.ofNat - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - solcAddrMask).toNat)) = true by - simp [BEq.beq, haddr]] - -theorem cometRewardsWithdrawTokenBodyReverts_auth (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask ≠ - solcSourceWord evm.executionEnv) : - ExecTransitionBody config contract evm (withdrawTokenStore I) - withdrawTokenTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [withdrawTokenTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - ((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (withdrawTokenStore I) hsize)).requireRevert - (evalExpr_withdrawToken_auth_false evm I hgov)) - -theorem cometRewardsWithdrawTokenBodyRevertsHuge (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hbig : 2 ^ 255 + 4 ≤ evm.executionEnv.calldata.size) : - ExecTransitionBody config contract evm (withdrawTokenStore I) - withdrawTokenTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [withdrawTokenTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireRevert - (cometRewardsCalldataGuard_false evm (withdrawTokenStore I) hbig)) - -theorem cometRewardsWithdrawTokenBodyReverts_callFailure - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (hcall : - typedCallViaEVM config evm (EVM.address (withdrawTokenTransferTarget I)) - "transfer" 0 (withdrawTokenTransferArgs I) (false, evm', out) true) : - ExecTransitionBody config contract evm (withdrawTokenStore I) - withdrawTokenTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (withdrawTokenFrame evm I) evm - (.internalCall "doTransferOut" [.var "token", .var "to", .var "amount"] "_sent") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := withdrawTokenFrame evm I) (evm := evm) - (name := "doTransferOut") (retVar := "_sent") - (args := [.var "token", .var "to", .var "amount"]) - (argVals := withdrawTokenArgs I) (callee := doTransferOutFunction) - (locals := doTransferOutStore I) - (evalExprs_withdrawToken_frame_args evm I) - (by simpa [withdrawTokenFrame] using lookupCallable_doTransferOut) - (bindParams_doTransferOut I) - (by - simpa [withdrawTokenFrame] using - (doTransferOutBodyReverts_callFailure evm evm' I hcall)) - simpa [withdrawTokenTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (withdrawTokenStore I) hsize)).requireStep - (evalExpr_withdrawToken_auth_true evm I hgov)).run - (ExecBlock.consRevert hstmt)) - -theorem cometRewardsWithdrawTokenBodyReverts_decode - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (hcall : - typedCallViaEVM config evm (EVM.address (withdrawTokenTransferTarget I)) - "transfer" 0 (withdrawTokenTransferArgs I) (true, evm', out) true) - (hdec : config.externalABI.decode? "transfer" out = none) : - ExecTransitionBody config contract evm (withdrawTokenStore I) - withdrawTokenTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (withdrawTokenFrame evm I) evm - (.internalCall "doTransferOut" [.var "token", .var "to", .var "amount"] "_sent") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := withdrawTokenFrame evm I) (evm := evm) - (name := "doTransferOut") (retVar := "_sent") - (args := [.var "token", .var "to", .var "amount"]) - (argVals := withdrawTokenArgs I) (callee := doTransferOutFunction) - (locals := doTransferOutStore I) - (evalExprs_withdrawToken_frame_args evm I) - (by simpa [withdrawTokenFrame] using lookupCallable_doTransferOut) - (bindParams_doTransferOut I) - (by - simpa [withdrawTokenFrame] using - (doTransferOutBodyReverts_decode evm evm' I hcall hdec)) - simpa [withdrawTokenTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (withdrawTokenStore I) hsize)).requireStep - (evalExpr_withdrawToken_auth_true evm I hgov)).run - (ExecBlock.consRevert hstmt)) - -theorem cometRewardsWithdrawTokenBodyReverts_false - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (hcall : - typedCallViaEVM config evm (EVM.address (withdrawTokenTransferTarget I)) - "transfer" 0 (withdrawTokenTransferArgs I) (true, evm', out) true) - (hdec : config.externalABI.decode? "transfer" out = some [.bool false]) : - ExecTransitionBody config contract evm (withdrawTokenStore I) - withdrawTokenTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hstmt : - ExecStmt config (withdrawTokenFrame evm I) evm - (.internalCall "doTransferOut" [.var "token", .var "to", .var "amount"] "_sent") - .reverted := by - exact internalCallFunctionRevert - (cfg := config) (caller := withdrawTokenFrame evm I) (evm := evm) - (name := "doTransferOut") (retVar := "_sent") - (args := [.var "token", .var "to", .var "amount"]) - (argVals := withdrawTokenArgs I) (callee := doTransferOutFunction) - (locals := doTransferOutStore I) - (evalExprs_withdrawToken_frame_args evm I) - (by simpa [withdrawTokenFrame] using lookupCallable_doTransferOut) - (bindParams_doTransferOut I) - (by - simpa [withdrawTokenFrame] using - (doTransferOutBodyReverts_false evm evm' I hcall hdec)) - simpa [withdrawTokenTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (withdrawTokenStore I) hsize)).requireStep - (evalExpr_withdrawToken_auth_true evm I hgov)).run - (ExecBlock.consRevert hstmt)) - -theorem cometRewardsWithdrawTokenBodyReturns_true - (evm evm' : EVM.State) (I : ExecutionEnv) {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hsize : evm.executionEnv.calldata.size < 2 ^ 255 + 4) - (hgov : - UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) solcAddrMask = - solcSourceWord evm.executionEnv) - (hcall : - typedCallViaEVM config evm (EVM.address (withdrawTokenTransferTarget I)) - "transfer" 0 (withdrawTokenTransferArgs I) (true, evm', out) true) - (hdec : config.externalABI.decode? "transfer" out = some [.bool true]) : - ExecTransitionBody config contract evm (withdrawTokenStore I) - withdrawTokenTransition.body - (.returned (resumeAfterInternalCall (withdrawTokenFrame evm I) "_sent" none) evm' none) := by - refine ExecFuncBody.execBlockOK ?_ - have hstmt : - ExecStmt config (withdrawTokenFrame evm I) evm - (.internalCall "doTransferOut" [.var "token", .var "to", .var "amount"] "_sent") - (.ok (resumeAfterInternalCall (withdrawTokenFrame evm I) "_sent" none) evm') := by - exact internalCallFunctionReturn - (cfg := config) (caller := withdrawTokenFrame evm I) (evm := evm) - (calleeEvm := evm') (name := "doTransferOut") (retVar := "_sent") - (args := [.var "token", .var "to", .var "amount"]) - (argVals := withdrawTokenArgs I) (callee := doTransferOutFunction) - (locals := doTransferOutStore I) - (calleeSolm := { contract := contract, locals := withdrawTokenCallStore I true }) - (value := none) - (evalExprs_withdrawToken_frame_args evm I) - (by simpa [withdrawTokenFrame] using lookupCallable_doTransferOut) - (bindParams_doTransferOut I) - (by - simpa [withdrawTokenFrame] using - (doTransferOutBodyReturns_true evm evm' I hcall hdec)) - simpa [withdrawTokenTransition, externalEntryGuard, nonpayable, calldataSizeGuard] using - (((((ABlock.start.requireStep (evalCallvalueEq_true hwv)).letStep (by - simp [evalExpr?, envValue, pure])).requireStep - (cometRewardsCalldataGuard_true evm (withdrawTokenStore I) hsize)).requireStep - (evalExpr_withdrawToken_auth_true evm I hgov)).run - (ExecBlock.consNormal hstmt ExecBlock.nil)) - -theorem cometRewardsWithdrawTokenX_dec2875_args {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2875⟩ - [UInt256.ofNat I.calldata.size, ⟨2776⟩, ⟨128⟩, ⟨64⟩, ⟨0⟩, ⟨4⟩, - cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2758⟩ := hreach - have rd2764 := evm_run rd2758 with [ - jumpdest, dup6, dup6, dup5, swap3, callvalue] - rw [hwv] at rd2764 - have rd2775 := evm_run rd2764 with [ - push2 ⟨938⟩, jumpiNT (by decide), - push2 ⟨2776⟩, calldatasize, push2 ⟨2875⟩] - exact ⟨_, _, evm_run rd2775 with [jump (by native_decide)]⟩ - -theorem cometRewardsWithdrawTokenX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz4 : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hshort : I.calldata.size < 100) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsWithdrawTokenCalldataCheckShort (I := I) hsz4 hsize hshort - obtain ⟨_, _, rd2875⟩ := - cometRewardsWithdrawTokenX_dec2875_args (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hreach - have rd2884 := evm_run rd2875 with [ - jumpdest, push1 ⟨96⟩, swap1, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd2884 - rw [hslt] at rd2884 - exact evm_run rd2884 with [ - push2 ⟨1004⟩, jumpiT (by decide) (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsWithdrawTokenX_hugearg {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsWithdrawTokenCalldataCheckHuge (I := I) hsize hbig - obtain ⟨_, _, rd2875⟩ := - cometRewardsWithdrawTokenX_dec2875_args (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hreach - have rd2884 := evm_run rd2875 with [ - jumpdest, push1 ⟨96⟩, swap1, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd2884 - rw [hslt] at rd2884 - exact evm_run rd2884 with [ - push2 ⟨1004⟩, jumpiT (by decide) (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -theorem cometRewardsWithdrawTokenX_dec2776_args {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (withdrawTokenTokenWord I).toNat < EVM.addressModulus) - (hcanon1 : (withdrawTokenToWord I).toNat < EVM.addressModulus) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2776⟩ - [withdrawTokenAmountWord I, withdrawTokenToWord I, withdrawTokenTokenWord I, - ⟨128⟩, ⟨64⟩, ⟨0⟩, ⟨4⟩, cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt := cometRewardsWithdrawTokenCalldataCheckOk (I := I) hsz100 hsize hhi - obtain ⟨_, _, rd2875⟩ := - cometRewardsWithdrawTokenX_dec2875_args (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hreach - have rd2884 := evm_run rd2875 with [ - jumpdest, push1 ⟨96⟩, swap1, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd2884 - rw [hslt] at rd2884 - have rd2888 := evm_run rd2884 with [ - push2 ⟨1004⟩, jumpiNT (by decide)] - have rd2909 := evm_run rd2888 with [ - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, - swap1, push1 ⟨4⟩, calldataload, dup3, dup2, and, dup2, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land (withdrawTokenTokenWord I) solcAddrMask = - withdrawTokenTokenWord I := by - exact solcAddrMask_clean (by - simpa [withdrawTokenTokenWord, calldataWord] using hcanon0) - have hclean' : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32) := by - simpa [withdrawTokenTokenWord, calldataWord] using hclean - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean'] - exact u256_sub_self _), - swap2] - have rd2922 := evm_run rd2909 with [ - push1 ⟨36⟩, calldataload, swap1, dup2, and, dup2, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land (withdrawTokenToWord I) solcAddrMask = - withdrawTokenToWord I := by - exact solcAddrMask_clean (by - simpa [withdrawTokenToWord, calldataWord] using hcanon1) - have hclean' : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32) := by - simpa [withdrawTokenToWord, calldataWord] using hclean - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean'] - exact u256_sub_self _), - swap1] - have rd2927 := evm_run rd2922 with [ - push1 ⟨68⟩, calldataload, swap1] - exact ⟨_, _, evm_run rd2927 with [jump (by native_decide)]⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsWithdrawTokenX_noncanon_token {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hnc : UInt256.eq (withdrawTokenTokenWord I) - (UInt256.land (withdrawTokenTokenWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsWithdrawTokenCalldataCheckOk (I := I) hsz100 hsize hhi - obtain ⟨_, _, rd2875⟩ := - cometRewardsWithdrawTokenX_dec2875_args (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hreach - have rd2884 := evm_run rd2875 with [ - jumpdest, push1 ⟨96⟩, swap1, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd2884 - rw [hslt] at rd2884 - have rd2888 := evm_run rd2884 with [ - push2 ⟨1004⟩, jumpiNT (by decide)] - exact evm_run rd2888 with [ - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, - swap1, push1 ⟨4⟩, calldataload, dup3, dup2, and, dup2, sub, - push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hraw : - UInt256.eq - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - (UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask) = ⟨1⟩ := by - rw [← heq] - exact uInt256_eq_self _ - have hclean : - UInt256.eq (withdrawTokenTokenWord I) - (UInt256.land (withdrawTokenTokenWord I) solcAddrMask) = ⟨1⟩ := by - simpa [withdrawTokenTokenWord, calldataWord] using hraw - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsWithdrawTokenX_noncanon_to {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (withdrawTokenTokenWord I).toNat < EVM.addressModulus) - (hnc : UInt256.eq (withdrawTokenToWord I) - (UInt256.land (withdrawTokenToWord I) solcAddrMask) = ⟨0⟩) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt := cometRewardsWithdrawTokenCalldataCheckOk (I := I) hsz100 hsize hhi - obtain ⟨_, _, rd2875⟩ := - cometRewardsWithdrawTokenX_dec2875_args (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hwv hreach - have rd2884 := evm_run rd2875 with [ - jumpdest, push1 ⟨96⟩, swap1, push1 ⟨3⟩, not, add, slt] - rw [show UInt256.lnot (⟨3⟩ : UInt256) + UInt256.ofNat I.calldata.size = - UInt256.ofNat I.calldata.size + UInt256.lnot (⟨3⟩ : UInt256) - from u256_add_comm _ _] at rd2884 - rw [hslt] at rd2884 - have rd2888 := evm_run rd2884 with [ - push2 ⟨1004⟩, jumpiNT (by decide)] - have rd2909 := evm_run rd2888 with [ - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, - swap1, push1 ⟨4⟩, calldataload, dup3, dup2, and, dup2, sub, - push2 ⟨1004⟩, - jumpiNT (by - have hclean : - UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - solcAddrMask = - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32) := by - have hclean' : - UInt256.land (withdrawTokenTokenWord I) solcAddrMask = - withdrawTokenTokenWord I := by - exact solcAddrMask_clean (by - simpa [withdrawTokenTokenWord, calldataWord] using hcanon0) - simpa [withdrawTokenTokenWord, calldataWord] using hclean' - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide, hclean] - exact u256_sub_self _), - swap2] - exact evm_run rd2909 with [ - push1 ⟨36⟩, calldataload, swap1, dup2, and, dup2, sub, - push2 ⟨1004⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] - exact u256_sub_ne_zero_of_ne (by - intro heq - have hraw : - UInt256.eq - (uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32)) - (UInt256.land - (uInt256OfByteArray (I.calldata.readBytes (⟨36⟩ : UInt256).toNat 32)) - solcAddrMask) = ⟨1⟩ := by - rw [← heq] - exact uInt256_eq_self _ - have hclean : - UInt256.eq (withdrawTokenToWord I) - (UInt256.land (withdrawTokenToWord I) solcAddrMask) = ⟨1⟩ := by - simpa [withdrawTokenToWord, calldataWord] using hraw - rw [hclean] at hnc - exact (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnc)) - (by native_decide), - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsX_withdrawToken_revert_auth {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (withdrawTokenTokenWord I).toNat < EVM.addressModulus) - (hcanon1 : (withdrawTokenToWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I ≠ solcSourceWord I) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2776⟩ := - cometRewardsWithdrawTokenX_dec2776_args (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz100 hsize hhi hcanon0 hcanon1 hreach - have rd2778 := evm_run rd2776 with [jumpdest, dup6] - obtain ⟨_, _, rd2779₀⟩ := rd2778.sload (by decide) (by evm_ov) - obtain ⟨_, _, rd2779⟩ : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨2779⟩ - [governorWord σ I, withdrawTokenAmountWord I, withdrawTokenToWord I, - withdrawTokenTokenWord I, ⟨128⟩, ⟨64⟩, ⟨0⟩, ⟨4⟩, - cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by simpa [governorWord] using rd2779₀⟩ - have rd2796₀ := evm_run rd2779 with [ - swap1, swap4, swap2, swap3, swap2, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, and, caller, sub] - have rd2796 := rd2796₀ - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] at rd2796 - have hsub : UInt256.sub (solcSourceWord I) (governorReturnWord σ I) ≠ ⟨0⟩ := by - exact u256_sub_ne_zero_of_ne (by - intro h - exact hauth h.symm) - have hsub' : - UInt256.sub (UInt256.ofNat I.source.val) (UInt256.land solcAddrMask (governorWord σ I)) ≠ - ⟨0⟩ := by - simpa [solcSourceWord, governorReturnWord, - u256_land_comm solcAddrMask (governorWord σ I)] using hsub - exact evm_run rd2796 with [ - push2 ⟨2811⟩, jumpiT hsub' (by native_decide), - jumpdest, push4 ⟨431085831⟩, push1 ⟨227⟩, shl, dup2, - raw mstore 6 (solcReturnMem transferGovernorUnauthorizedSelector) - (UInt256.ofNat 5) (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - rfl) - (by decide) (by evm_ov), - caller, dup8, dup3, add, - raw mstore 3 (transferGovernorUnauthorizedMem (solcSourceWord I)) - (UInt256.ofNat 6) (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256) + ⟨4⟩ = ⟨132⟩ from by decide, - show (⟨132⟩ : UInt256).toNat = 132 from by decide] - unfold transferGovernorUnauthorizedMem solcSourceWord - rfl) - (by decide) (by evm_ov), - push1 ⟨36⟩, swap1, raw rev 0 (by decide) mem_cost (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem cometRewardsWithdrawTokenX_dec3915_transfer {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (withdrawTokenTokenWord I).toNat < EVM.addressModulus) - (hcanon1 : (withdrawTokenToWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3915⟩ - [withdrawTokenTokenWord I, withdrawTokenToWord I, withdrawTokenAmountWord I, - ⟨1001⟩, ⟨64⟩, ⟨0⟩, ⟨4⟩, cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2776⟩ := - cometRewardsWithdrawTokenX_dec2776_args (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz100 hsize hhi hcanon0 hcanon1 hreach - have rd2778 := evm_run rd2776 with [jumpdest, dup6] - obtain ⟨_, _, rd2779₀⟩ := rd2778.sload (by decide) (by evm_ov) - obtain ⟨_, _, rd2779⟩ : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) ⟨2779⟩ - [governorWord σ I, withdrawTokenAmountWord I, withdrawTokenToWord I, - withdrawTokenTokenWord I, ⟨128⟩, ⟨64⟩, ⟨0⟩, ⟨4⟩, - cometRewardsSelWord I, ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by simpa [governorWord] using rd2779₀⟩ - have rd2796₀ := evm_run rd2779 with [ - swap1, swap4, swap2, swap3, swap2, swap1, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, and, caller, sub] - have rd2796 := rd2796₀ - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] at rd2796 - have hsub' : - UInt256.sub (UInt256.ofNat I.source.val) (UInt256.land solcAddrMask (governorWord σ I)) = - ⟨0⟩ := by - have hgovsrc : - UInt256.land (governorWord σ I) solcAddrMask = UInt256.ofNat I.source.val := by - simpa [governorReturnWord, solcSourceWord] using hauth - rw [u256_land_comm solcAddrMask (governorWord σ I), hgovsrc] - exact u256_sub_self _ - have rd2800 := evm_run rd2796 with [ - push2 ⟨2811⟩, jumpiNT (by simpa using hsub')] - have rd2810 := evm_run rd2800 with [ - pop, swap1, push2 ⟨1001⟩, swap3, swap2, push2 ⟨3915⟩] - exact ⟨_, _, evm_run rd2810 with [jump (by native_decide)]⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsWithdrawTokenX_call_transfer {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (withdrawTokenTokenWord I).toNat < EVM.addressModulus) - (hcanon1 : (withdrawTokenToWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (hreach : ∃ k C, RD cometRewardsBytecode I g - (initState cA gh bl σ σ₀ g A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ gasArg k C, RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - withdrawTokenTransferCallPc - [gasArg, UInt256.land solcAddrMask (withdrawTokenTokenWord I), ⟨0⟩, ⟨128⟩, - withdrawTokenTransferCallSize, ⟨128⟩, ⟨32⟩, ⟨128⟩, withdrawTokenToWord I, - withdrawTokenAmountWord I, ⟨1001⟩, ⟨64⟩, ⟨0⟩, ⟨4⟩, cometRewardsSelWord I, - ⟨4⟩, ⟨224⟩, ⟨64⟩, ⟨0⟩] - (withdrawTokenTransferCalldataMem (withdrawTokenToWord I) (withdrawTokenAmountWord I)) - (UInt256.ofNat 7) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd3915⟩ := - cometRewardsWithdrawTokenX_dec3915_transfer (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hwv hsz100 hsize hhi hcanon0 hcanon1 hauth hreach - have hcleanTo : - UInt256.land (withdrawTokenToWord I) solcAddrMask = withdrawTokenToWord I := by - exact solcAddrMask_clean (by simpa [withdrawTokenToWord, calldataWord] using hcanon1) - have rd3932 := evm_run rd3915 with [ - jumpdest, push1 ⟨32⟩, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - dup1, swap3, push4 ⟨2835717307⟩, push1 ⟨224⟩, shl, dup3, - raw mstore 6 withdrawTokenTransferSelectorMem (UInt256.ofNat 5) - (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - rfl) - (by decide) (by evm_ov)] - have rd3949 := evm_run rd3932 with [ - dup2, push1 ⟨0⟩, dup2, push2 ⟨3950⟩, dup10, dup10, push1 ⟨4⟩, dup5, - add, push2 ⟨3888⟩, jump (by native_decide)] - have rd3901₀ := evm_run rd3949 with [ - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, swap1, swap2, and, - dup2] - have rd3901 := rd3901₀ - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] at rd3901 - have rd3902 := evm_run rd3901 with [ - raw mstore 3 (withdrawTokenTransferArgsMem (withdrawTokenToWord I)) (UInt256.ofNat 6) - (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256) + ⟨4⟩ = ⟨132⟩ from by decide, - show (⟨132⟩ : UInt256).toNat = 132 from by decide] - unfold withdrawTokenTransferArgsMem - rw [hcleanTo]) - (by decide) (by evm_ov)] - have rd3913 := evm_run rd3902 with [ - push1 ⟨32⟩, dup2, add, swap2, swap1, swap2, - raw mstore 3 (withdrawTokenTransferCalldataMem (withdrawTokenToWord I) - (withdrawTokenAmountWord I)) (UInt256.ofNat 7) - (by decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256) + ⟨4⟩ + ⟨32⟩ = ⟨164⟩ from by decide, - show (⟨164⟩ : UInt256).toNat = 164 from by decide] - unfold withdrawTokenTransferCalldataMem - rfl) - (by decide) (by evm_ov), - push1 ⟨64⟩, add, swap1] - have rd3962₀ := evm_run rd3913 with [ - jump (by native_decide), jumpdest, sub, swap3, push1 ⟨1⟩, push1 ⟨1⟩, - push1 ⟨160⟩, shl, sub, and] - have rd3962 := rd3962₀ - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] at rd3962 - obtain ⟨gasArg, rd3963⟩ := evm_run rd3962 with [gas] - exact ⟨gasArg, _, _, by - simpa [withdrawTokenTransferCallPc, withdrawTokenTransferCallSize] using rd3963⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsWithdrawTokenX_call_transfer_made - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hsz100 : 100 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (withdrawTokenTokenWord I).toNat < EVM.addressModulus) - (hcanon1 : (withdrawTokenToWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ_evm I = solcSourceWord I) - (hdepth : I.depth.val < 1024) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - ∃ cA' σ'_evm σ'_solm A'_solm z out k C, - typedCallViaEVM config - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (EVM.address (withdrawTokenTransferTarget I)) "transfer" 0 - (withdrawTokenTransferArgs I) - (z, - { initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' }, - out) true ∧ - accountMapEquiv σ'_evm σ'_solm ∧ - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (withdrawTokenTransferCallPc + ⟨1⟩) (withdrawTokenPostCallStack z I) - (withdrawTokenPostCallMem I out) withdrawTokenPostCallAw out - (cA', σ'_evm) k C ∧ - out.size < 2 ^ 255 := by - obtain ⟨gasArg, _k0, _C0, rd3963⟩ := - cometRewardsWithdrawTokenX_call_transfer (cA := cA) (gh := gh) (bl := bl) - (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanon0 hcanon1 hauth hreach - have rd3963Call : - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - withdrawTokenTransferCallPc - (gasArg :: UInt256.land solcAddrMask (withdrawTokenTokenWord I) :: ⟨0⟩ :: - ⟨128⟩ :: withdrawTokenTransferCallSize :: ⟨128⟩ :: ⟨32⟩ :: - withdrawTokenPostCallTail I) - (withdrawTokenTransferCalldataMem (withdrawTokenToWord I) - (withdrawTokenAmountWord I)) (UInt256.ofNat 7) ByteArray.empty - (cA, σ_evm) _k0 _C0 := by - simpa [withdrawTokenPostCallTail] using rd3963 - have hdecCall : - decode cometRewardsBytecode withdrawTokenTransferCallPc = some (.CALL, .none) := by - rw [withdrawTokenTransferCallPc_eq] - native_decide - obtain ⟨cA', σ'_evm, z, out, A_in, callGas, k', C', hΘ, rd3964, houtSize⟩ := - RD.call (t := withdrawTokenPostCallTail I) rd3963Call hdecCall hdepth - (by simp [withdrawTokenPostCallTail]) - obtain ⟨g'', A'_evm, hΘeq⟩ := hΘ - have houtSmall : out.size < 2 ^ 138 := by - exact Theta_returnData_size_lt_2pow138_of_eq - (blob := I.blobVersionedHashes) (cA := cA) - (gh := (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I).genesisBlockHeader) - (blocks := (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I).blocks) - (σ := σ_evm) - (σ₀ := (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I).σ₀) - (A := A_in) - (s := AccountAddress.ofUInt256 (UInt256.ofNat I.codeOwner)) - (o := I.sender) - (r := AccountAddress.ofUInt256 (UInt256.land solcAddrMask (withdrawTokenTokenWord I))) - (c := toExecute σ_evm - (AccountAddress.ofUInt256 (UInt256.land solcAddrMask (withdrawTokenTokenWord I)))) - (g := callGas) (p := UInt256.ofNat I.gasPrice) - (v := ⟨0⟩) (v' := ⟨0⟩) - (d := (withdrawTokenTransferCalldataMem (withdrawTokenToWord I) - (withdrawTokenAmountWord I)).readWithPadding (⟨128⟩ : UInt256).toNat - withdrawTokenTransferCallSize.toNat) - (e := I.depth + 1) (H := I.header) (w := I.perm) - hΘeq - (by exact Ethereum.EVM.ByteArray.readWithPadding_size_lt_uint256 _ _ _) - have houtSign : out.size < 2 ^ 255 := by omega - have hdepthNeI : I.depth ≠ 1024 := by - intro hEq - rw [hEq] at hdepth - exact absurd hdepth (by decide) - have hdepthNe : - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.depth ≠ - 1024 := by - simpa [initState] using hdepthNeI - have htgt := withdrawTokenTransferTarget_eq_targetWord I hcanon0 - have hcd := withdrawTokenTransferCalldataMem_encode_args I hcanon1 - have hcallE : - typedCallViaEVM config - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (EVM.address (withdrawTokenTransferTarget I)) "transfer" 0 - (withdrawTokenTransferArgs I) - (z, - { initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_evm - substate := A'_evm - createdAccounts := cA' }, - out) true := by - refine callCoincides - (cfg := config) - (evm := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (name := "transfer") (args := withdrawTokenTransferArgs I) - (tgt := EVM.address (withdrawTokenTransferTarget I)) - (targetWord := UInt256.land solcAddrMask (withdrawTokenTokenWord I)) - (cA' := cA') (σ' := σ'_evm) (A' := A'_evm) (A_in := A_in) - (z := z) (o := out) (g'' := g'') (callGas := callGas) - (mem := withdrawTokenTransferCalldataMem (withdrawTokenToWord I) - (withdrawTokenAmountWord I)) - (inOff := ⟨128⟩) (inSize := withdrawTokenTransferCallSize) - (callPerm := true) - hdepthNe htgt hcd ?_ - simpa [initState, hperm] using hΘeq - obtain ⟨σ'_solm, A'_solm, hcallSolm, hPostAccounts⟩ := - typedCallViaEVM_initState_accountMapEquiv hcallE hAccounts - exact ⟨cA', σ'_evm, σ'_solm, A'_solm, z, out, k', C', - hcallSolm, hPostAccounts, by - simpa [withdrawTokenPostCallStack, withdrawTokenPostCallTail, - withdrawTokenPostCallMem, withdrawTokenPostCallAw] using rd3964, - houtSign⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsWithdrawTokenX_afterCall_failure {cA gh bl σ σ₀ A I} {g : Sat256} - {out : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (withdrawTokenTransferCallPc + ⟨1⟩) (withdrawTokenPostCallStack false I) - (withdrawTokenPostCallMem I out) withdrawTokenPostCallAw out acc k C) - (houtSize : out.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - have rd3964 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3964⟩ (withdrawTokenPostCallStack false I) - (withdrawTokenPostCallMem I out) withdrawTokenPostCallAw out acc k C := by - simpa [withdrawTokenTransferCallPc_eq] using rd - have rd3876 := evm_run rd3964 with [ - swap1, dup2, iszero, push2 ⟨3876⟩, - jumpiT (by native_decide) (by jump_dest)] - let fp : UInt256 := - if (⟨64⟩ : UInt256).toNat ≥ (withdrawTokenPostCallMem I out).size - ∨ (⟨64⟩ : UInt256) ≥ withdrawTokenPostCallAw * ⟨32⟩ then - ⟨0⟩ - else - UInt256.ofNat (fromByteArrayBigEndian - ((withdrawTokenPostCallMem I out).readWithPadding (⟨64⟩ : UInt256).toNat 32)) - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have rd3880pre := evm_run rd3876 with [jumpdest, push1 ⟨64⟩] - have rd3880 := RD.mload 0 fp withdrawTokenPostCallAw rd3880pre (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, - withdrawTokenPostCallAw, withdrawTokenTransferCallSize] - native_decide) - (by rfl) - (by native_decide) - (by simp) - have rd3884pre := evm_run rd3880 with [returndatasize, push1 ⟨0⟩, dup3] - let mem2 : ByteArray := - out.write 0 (withdrawTokenPostCallMem I out) fp.toNat rdsz.toNat - let aw2 : UInt256 := - UInt256.ofNat (MachineState.M withdrawTokenPostCallAw.toNat fp.toNat rdsz.toNat) - have rd3885 := RD.returndatacopy - (Cₘ aw2 - Cₘ withdrawTokenPostCallAw) mem2 aw2 rd3884pre (by native_decide) - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, hrdsz_toNat]; omega) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, aw2, rdsz]) - (by rfl) - (by rfl) - (by simp) - have rd3887 := evm_run rd3885 with [returndatasize, swap1] - exact RD.rev - (Cₘ (UInt256.ofNat (MachineState.M aw2.toNat fp.toNat rdsz.toNat)) - Cₘ aw2) - rd3887 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, rdsz]) - (by simp) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsWithdrawTokenX_callDepthLimit {cA gh bl σ σ₀ A I} {g : UInt256} - (hwv : I.weiValue = ⟨0⟩) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hcanon0 : (withdrawTokenTokenWord I).toNat < EVM.addressModulus) - (hcanon1 : (withdrawTokenToWord I).toNat < EVM.addressModulus) - (hauth : governorReturnWord σ I = solcSourceWord I) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) - (hdepth : I.depth = 1024) : - RDrev cometRewardsBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) := by - obtain ⟨gasArg, k0, C0, rd3963⟩ := - cometRewardsWithdrawTokenX_call_transfer (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanon0 hcanon1 hauth hreach - have rd3963Call : - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) - withdrawTokenTransferCallPc - (gasArg :: UInt256.land solcAddrMask (withdrawTokenTokenWord I) :: ⟨0⟩ :: - ⟨128⟩ :: withdrawTokenTransferCallSize :: ⟨128⟩ :: ⟨32⟩ :: - withdrawTokenPostCallTail I) - (withdrawTokenTransferCalldataMem (withdrawTokenToWord I) - (withdrawTokenAmountWord I)) (UInt256.ofNat 7) ByteArray.empty - (cA, σ) k0 C0 := by - simpa [withdrawTokenPostCallTail] using rd3963 - have hdecCall : - decode cometRewardsBytecode withdrawTokenTransferCallPc = some (.CALL, .none) := by - rw [withdrawTokenTransferCallPc_eq] - native_decide - have hdepthInit : - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I).executionEnv.depth = 1024 := by - simpa [initState] using hdepth - obtain ⟨k', C', rdPost₀⟩ := - RD.callDepthLimit (t := withdrawTokenPostCallTail I) rd3963Call hdecCall - hdepthInit (by simp [withdrawTokenPostCallTail]) - have rdPost : - RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) - (withdrawTokenTransferCallPc + ⟨1⟩) (withdrawTokenPostCallStack false I) - (withdrawTokenPostCallMem I ByteArray.empty) withdrawTokenPostCallAw - ByteArray.empty (cA, σ) k' C' := by - simpa [withdrawTokenPostCallStack, withdrawTokenPostCallTail, withdrawTokenPostCallMem, - withdrawTokenPostCallAw, withdrawTokenTransferCallSize] using rdPost₀ - exact cometRewardsWithdrawTokenX_afterCall_failure rdPost (by simp [UInt256.size]) - -theorem withdrawTokenPostCallMem_read128_of_size_ge (I : ExecutionEnv) {out : ByteArray} - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (withdrawTokenPostCallMem I out).readWithPadding 128 32 = - out.extract 0 32 := by - unfold withdrawTokenPostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := out.size) - (by decide) hout32 houtSize - rw [hlen] - exact write32_read_back out - (withdrawTokenTransferCalldataMem (withdrawTokenToWord I) (withdrawTokenAmountWord I)) - 128 hout32 (by rw [withdrawTokenTransferCalldataMem_size]; omega) - -theorem withdrawTokenPostCallMem_size_ge160 (I : ExecutionEnv) {out : ByteArray} - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - 160 ≤ (withdrawTokenPostCallMem I out).size := by - unfold withdrawTokenPostCallMem - have hlen : (min (⟨32⟩ : UInt256) (UInt256.ofNat out.size)).toNat = 32 := by - simpa using umin_ofNat_right_toNat_of_ge (c := 32) (n := out.size) - (by decide) hout32 houtSize - rw [hlen] - rw [write32_eq out - (withdrawTokenTransferCalldataMem (withdrawTokenToWord I) (withdrawTokenAmountWord I)) - 128 hout32 (by rw [withdrawTokenTransferCalldataMem_size]; omega)] - simp [withdrawTokenTransferCalldataMem_size] - omega - -theorem withdrawTokenPostCallMem_mload128_haw : - ¬ (⟨128⟩ : UInt256) ≥ withdrawTokenPostCallAw * ⟨32⟩ := by - native_decide - -theorem withdrawTokenPostCallMem_mload128_of_size_ge (I : ExecutionEnv) {out : ByteArray} - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (if (⟨128⟩ : UInt256).toNat ≥ (withdrawTokenPostCallMem I out).size - ∨ (⟨128⟩ : UInt256) ≥ withdrawTokenPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((withdrawTokenPostCallMem I out).readWithPadding - (⟨128⟩ : UInt256).toNat 32))) = - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) := by - exact mloadValue_eq_readWithPadding_of_lt_size - (mem := withdrawTokenPostCallMem I out) (aw := withdrawTokenPostCallAw) - (off := ⟨128⟩) (memSize := (withdrawTokenPostCallMem I out).size) - rfl - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - exact lt_of_lt_of_le (by omega) (withdrawTokenPostCallMem_size_ge160 I hout32 houtSize)) - withdrawTokenPostCallMem_mload128_haw - |>.trans (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - withdrawTokenPostCallMem_read128_of_size_ge I hout32 houtSize]) - -noncomputable abbrev withdrawTokenPostDecodeMem (I : ExecutionEnv) (out : ByteArray) : - ByteArray := - (UInt256.toByteArray (⟨160⟩ : UInt256)).write 0 (withdrawTokenPostCallMem I out) 64 32 - -theorem withdrawTokenPostDecodeMem_read128_of_size_ge (I : ExecutionEnv) {out : ByteArray} - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (withdrawTokenPostDecodeMem I out).readWithPadding 128 32 = - out.extract 0 32 := by - unfold withdrawTokenPostDecodeMem - rw [write32_read_above (UInt256.toByteArray (⟨160⟩ : UInt256)) - (withdrawTokenPostCallMem I out) 64 128 - (by rw [toByteArray_size]) - (by exact le_trans (by omega) (withdrawTokenPostCallMem_size_ge160 I hout32 houtSize)) - (by omega) - (by exact le_trans (by omega) (withdrawTokenPostCallMem_size_ge160 I hout32 houtSize))] - exact withdrawTokenPostCallMem_read128_of_size_ge I hout32 houtSize - -theorem withdrawTokenPostDecodeMem_mload128_of_size_ge (I : ExecutionEnv) {out : ByteArray} - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (if (⟨128⟩ : UInt256).toNat ≥ (withdrawTokenPostDecodeMem I out).size - ∨ (⟨128⟩ : UInt256) ≥ withdrawTokenPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((withdrawTokenPostDecodeMem I out).readWithPadding - (⟨128⟩ : UInt256).toNat 32))) = - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) := by - exact mloadValue_eq_readWithPadding_of_lt_size - (mem := withdrawTokenPostDecodeMem I out) (aw := withdrawTokenPostCallAw) - (off := ⟨128⟩) (memSize := (withdrawTokenPostDecodeMem I out).size) - rfl - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - unfold withdrawTokenPostDecodeMem - rw [write32_eq (UInt256.toByteArray (⟨160⟩ : UInt256)) - (withdrawTokenPostCallMem I out) 64 (by rw [toByteArray_size]) - (by exact le_trans (by omega) (withdrawTokenPostCallMem_size_ge160 I hout32 houtSize))] - simp - have hsz := withdrawTokenPostCallMem_size_ge160 I hout32 houtSize - omega) - withdrawTokenPostCallMem_mload128_haw - |>.trans (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - withdrawTokenPostDecodeMem_read128_of_size_ge I hout32 houtSize]) - -theorem withdrawTokenPostDecodeMem_mload64 (I : ExecutionEnv) {out : ByteArray} - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ (withdrawTokenPostDecodeMem I out).size - ∨ (⟨64⟩ : UInt256) ≥ withdrawTokenPostCallAw * ⟨32⟩ then - ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((withdrawTokenPostDecodeMem I out).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨160⟩ := by - exact mloadWordValue_of_readWithPadding - (off := (⟨64⟩ : UInt256)) (aw := withdrawTokenPostCallAw) (v := ⟨160⟩) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold withdrawTokenPostDecodeMem - rw [write32_eq (UInt256.toByteArray (⟨160⟩ : UInt256)) - (withdrawTokenPostCallMem I out) 64 (by rw [toByteArray_size]) - (by exact le_trans (by omega) (withdrawTokenPostCallMem_size_ge160 I hout32 houtSize))] - simp - have hsz := withdrawTokenPostCallMem_size_ge160 I hout32 houtSize - omega) - (by native_decide) - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold withdrawTokenPostDecodeMem - rw [write32_read_back _ _ 64 (by rw [toByteArray_size]) - (by exact le_trans (by omega) (withdrawTokenPostCallMem_size_ge160 I hout32 houtSize))] - rw [show (UInt256.toByteArray (⟨160⟩ : UInt256)).extract 0 32 = - UInt256.toByteArray (⟨160⟩ : UInt256) by - rw [show 32 = (UInt256.toByteArray (⟨160⟩ : UInt256)).size by - rw [toByteArray_size]] - exact byteArray_extract_self _]) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsWithdrawTokenX_afterCall_toBoolCheck {cA gh bl σ σ₀ A I} {g : Sat256} - {out : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (withdrawTokenTransferCallPc + ⟨1⟩) (withdrawTokenPostCallStack true I) - (withdrawTokenPostCallMem I out) withdrawTokenPostCallAw out acc k C) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) : - ∃ k' C', RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3287⟩ - (UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) :: ⟨4044⟩ :: - withdrawTokenToWord I :: withdrawTokenAmountWord I :: ⟨1001⟩ :: ⟨64⟩ :: - ⟨0⟩ :: ⟨4⟩ :: cometRewardsSelWord I :: ⟨4⟩ :: ⟨224⟩ :: ⟨64⟩ :: ⟨0⟩ :: []) - (withdrawTokenPostDecodeMem I out) withdrawTokenPostCallAw out acc k' C' := by - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨0⟩ := by - apply ugt_zero - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hout32 - have rd3964 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3964⟩ (withdrawTokenPostCallStack true I) - (withdrawTokenPostCallMem I out) withdrawTokenPostCallAw out acc k C := by - simpa [withdrawTokenTransferCallPc_eq] using rd - have rd4031₀ := evm_run rd3964 with [ - swap1, dup2, iszero, push2 ⟨3876⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨4020⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push2 ⟨4044⟩, swap2, pop, push1 ⟨32⟩, returndatasize, dup2, gt] - have rd4031 := rd4031₀ - rw [show UInt256.ofNat out.size = rdsz from rfl, hgt] at rd4031 - have rd3071 := evm_run rd4031 with [ - push2 ⟨2249⟩, jumpiNT (by native_decide), - push2 ⟨2235⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, add, - swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, swap1, dup3, - lt, lor, push2 ⟨3003⟩, jumpiNT (by native_decide), push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (withdrawTokenPostDecodeMem I out) withdrawTokenPostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - unfold withdrawTokenPostDecodeMem - rfl) - (by native_decide) (by evm_ov)] - have rd3274 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3274⟩, - jump (by jump_dest)] - have rd3286 := evm_run rd3274 with [ - jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, slt, push2 ⟨1004⟩, - jumpiNT (by native_decide)] - exact ⟨_, _, evm_run rd3286 with [ - raw mload 0 (UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32))) - withdrawTokenPostCallAw (by native_decide) mem_cost - (withdrawTokenPostDecodeMem_mload128_of_size_ge I hout32 houtSize) - (by native_decide) (by evm_ov)]⟩ - -set_option maxHeartbeats 1000000 in -theorem cometRewardsWithdrawTokenX_afterCall_true_return {cA gh bl σ σ₀ A I} {g : Sat256} - {out : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (withdrawTokenTransferCallPc + ⟨1⟩) (withdrawTokenPostCallStack true I) - (withdrawTokenPostCallMem I out) withdrawTokenPostCallAw out acc k C) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) - (hword : UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) = ⟨1⟩) : - RDret cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) acc ByteArray.empty := by - obtain ⟨_, _, rd3287₀⟩ := - cometRewardsWithdrawTokenX_afterCall_toBoolCheck (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) rd hout32 houtSize - have rd3287 := rd3287₀ - rw [hword] at rd3287 - have rd3978 := evm_run rd3287 with [ - dup1, iszero, iszero, dup2, sub, push2 ⟨1004⟩, jumpiNT (by native_decide), - swap1, jump (by jump_dest), jumpdest, codesize, push2 ⟨3978⟩, jump (by jump_dest)] - have rd1001 := evm_run rd3978 with [ - jumpdest, pop, iszero, push2 ⟨3988⟩, jumpiNT (by native_decide), - pop, pop, jump (by jump_dest), jumpdest] - have rd1003 := evm_run rd1001 with [ - raw mload 0 ⟨160⟩ withdrawTokenPostCallAw (by native_decide) - mem_cost (withdrawTokenPostDecodeMem_mload64 I hout32 houtSize) - (by native_decide) (by evm_ov)] - exact RD.ret 0 ByteArray.empty rd1003 (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, withdrawTokenPostCallAw] - native_decide) - (by exact byteArray_readWithPadding_zero _ 160) - (by simp) - -set_option maxHeartbeats 1000000 in -theorem cometRewardsWithdrawTokenX_afterCall_noncanon_revert {cA gh bl σ σ₀ A I} - {g : Sat256} {out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (withdrawTokenTransferCallPc + ⟨1⟩) (withdrawTokenPostCallStack true I) - (withdrawTokenPostCallMem I out) withdrawTokenPostCallAw out acc k C) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) - (hnz : UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) ≠ ⟨0⟩) - (hno : UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) ≠ ⟨1⟩) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let word : UInt256 := UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) - have hnzWord : word ≠ ⟨0⟩ := by simpa [word] using hnz - have hnoWord : word ≠ ⟨1⟩ := by simpa [word] using hno - have hiszero : UInt256.isZero word = ⟨0⟩ := isZero_eq_zero_of_ne hnzWord - have hcanon : UInt256.isZero (UInt256.isZero word) = ⟨1⟩ := by - rw [hiszero] - native_decide - have hsub : UInt256.sub word (UInt256.isZero (⟨0⟩ : UInt256)) ≠ ⟨0⟩ := by - rw [show UInt256.isZero (⟨0⟩ : UInt256) = ⟨1⟩ by native_decide] - exact u256_sub_ne_zero_of_ne hnoWord - obtain ⟨kBool, CBool, rd3287₀⟩ := - cometRewardsWithdrawTokenX_afterCall_toBoolCheck (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) rd hout32 houtSize - have rd3287 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3287⟩ - (word :: ⟨4044⟩ :: withdrawTokenToWord I :: withdrawTokenAmountWord I :: ⟨1001⟩ :: - ⟨64⟩ :: ⟨0⟩ :: ⟨4⟩ :: cometRewardsSelWord I :: ⟨4⟩ :: ⟨224⟩ :: ⟨64⟩ :: - ⟨0⟩ :: []) - (withdrawTokenPostDecodeMem I out) withdrawTokenPostCallAw out acc kBool CBool := by - simpa [word] using rd3287₀ - have rd3292 := evm_run rd3287 with [dup1, iszero, iszero, dup2, sub] - rw [hiszero] at rd3292 - have rd1004 := evm_run rd3292 with [ - push2 ⟨1004⟩, jumpiT hsub (by jump_dest)] - exact evm_run rd1004 with [ - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -noncomputable abbrev withdrawTokenPostShortDecodeMem (I : ExecutionEnv) (out : ByteArray) : - ByteArray := - (UInt256.toByteArray ((⟨128⟩ : UInt256) + - UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat out.size + ⟨31⟩))).write 0 - (withdrawTokenPostCallMem I out) 64 32 - -set_option maxHeartbeats 1000000 in -theorem cometRewardsWithdrawTokenX_afterCall_short_revert {cA gh bl σ σ₀ A I} - {g : Sat256} {out : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (withdrawTokenTransferCallPc + ⟨1⟩) (withdrawTokenPostCallStack true I) - (withdrawTokenPostCallMem I out) withdrawTokenPostCallAw out acc k C) - (hshort : out.size < 32) (houtSize : out.size < UInt256.size) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - let rdsz : UInt256 := UInt256.ofNat out.size - have hrdsz_toNat : rdsz.toNat = out.size := by - simpa [rdsz] using UInt256.toNat_ofNat_of_lt houtSize - have hgt : UInt256.gt (⟨32⟩ : UInt256) rdsz = ⟨1⟩ := by - apply ugt_one - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide, hrdsz_toNat] - exact hshort - have rd3964 : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - ⟨3964⟩ (withdrawTokenPostCallStack true I) - (withdrawTokenPostCallMem I out) withdrawTokenPostCallAw out acc k C := by - simpa [withdrawTokenTransferCallPc_eq] using rd - have rd4031₀ := evm_run rd3964 with [ - swap1, dup2, iszero, push2 ⟨3876⟩, jumpiNT (by native_decide), - push1 ⟨0⟩, swap2, push2 ⟨4020⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, push2 ⟨4044⟩, swap2, pop, push1 ⟨32⟩, returndatasize, dup2, gt] - have rd4031 := rd4031₀ - rw [show UInt256.ofNat out.size = rdsz from rfl, hgt] at rd4031 - let rounded : UInt256 := UInt256.land (UInt256.lnot ⟨31⟩) (UInt256.ofNat out.size + ⟨31⟩) - let ptr : UInt256 := (⟨128⟩ : UInt256) + rounded - have hroundedLe : rounded.toNat ≤ out.size + 31 := by - unfold rounded - rw [uland_toNat] - refine le_trans Nat.and_le_right ?_ - rw [uadd_toNat, UInt256.toNat_ofNat_of_lt houtSize, - show (⟨31⟩ : UInt256).toNat = 31 from by decide] - exact Nat.mod_le _ _ - have hptr_toNat : ptr.toNat = 128 + rounded.toNat := by - unfold ptr - rw [uadd_toNat, show (⟨128⟩ : UInt256).toNat = 128 from by decide] - exact Nat.mod_eq_of_lt (by - have hroundSmall : rounded.toNat < 64 := by omega - have hsz : UInt256.size = 2 ^ 256 := by decide - omega) - have hltPtr : UInt256.lt ptr (⟨128⟩ : UInt256) = ⟨0⟩ := by - apply ult_zero - rw [hptr_toNat, show (⟨128⟩ : UInt256).toNat = 128 from by decide] - omega - have hmax64 : - (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩).toNat = - 18446744073709551615 := by - native_decide - have hgtPtr : - UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - rw [hptr_toNat, hmax64] - omega - have hallocOk : - UInt256.lor (UInt256.lt ptr (⟨128⟩ : UInt256)) - (UInt256.gt ptr (((⟨1⟩ : UInt256).shiftLeft ⟨64⟩).sub ⟨1⟩)) = ⟨0⟩ := by - rw [hltPtr, hgtPtr] - native_decide - have rd3071 := evm_run rd4031 with [ - push2 ⟨2249⟩, jumpiT (by native_decide) (by jump_dest), - jumpdest, pop, returndatasize, push2 ⟨2225⟩, jump (by jump_dest), - jumpdest, push2 ⟨2235⟩, dup2, dup4, push2 ⟨3071⟩, jump (by jump_dest), - jumpdest, push1 ⟨31⟩, swap1, swap2, add, push1 ⟨31⟩, not, and, dup2, add, - swap1, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup3, gt, swap1, dup3, - lt, lor, push2 ⟨3003⟩, jumpiNT (by simpa [ptr, rounded] using hallocOk), - push1 ⟨64⟩] - have rd3105 := evm_run rd3071 with [ - raw mstore 0 (withdrawTokenPostShortDecodeMem I out) withdrawTokenPostCallAw - (by native_decide) mem_cost - (by - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]) - (by native_decide) (by evm_ov)] - have rd3274 := evm_run rd3105 with [ - jump (by jump_dest), jumpdest, dup2, add, swap1, push2 ⟨3274⟩, - jump (by jump_dest)] - have hlenCheck : - UInt256.slt (UInt256.sub ((⟨128⟩ : UInt256) + rdsz) ⟨128⟩) ⟨32⟩ = ⟨1⟩ := by - simpa [rdsz] using solcDecodeEndLenCheckShort_128_32 (len := out.size) hshort - have rd3282₀ := evm_run rd3274 with [ - jumpdest, swap1, dup2, push1 ⟨32⟩, swap2, sub, slt] - have rd3282 := rd3282₀ - rw [hlenCheck] at rd3282 - have rd1004 := evm_run rd3282 with [ - push2 ⟨1004⟩, jumpiT (by native_decide) (by jump_dest)] - exact evm_run rd1004 with [ - jumpdest, push1 ⟨0⟩, dup1, raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -abbrev withdrawTokenTransferOutFailedSelectorWord : UInt256 := ⟨1881067739⟩ - -abbrev withdrawTokenTransferOutFailedSelectorShifted : UInt256 := - UInt256.shiftLeft withdrawTokenTransferOutFailedSelectorWord ⟨224⟩ - -noncomputable abbrev withdrawTokenTransferOutFailedSelectorMem - (I : ExecutionEnv) (out : ByteArray) : ByteArray := - (UInt256.toByteArray withdrawTokenTransferOutFailedSelectorShifted).write 0 - (withdrawTokenPostDecodeMem I out) 160 32 - -noncomputable abbrev withdrawTokenTransferOutFailedArgsMem - (I : ExecutionEnv) (out : ByteArray) : ByteArray := - (UInt256.toByteArray (UInt256.land (withdrawTokenToWord I) solcAddrMask)).write 0 - (withdrawTokenTransferOutFailedSelectorMem I out) 164 32 - -noncomputable abbrev withdrawTokenTransferOutFailedMem - (I : ExecutionEnv) (out : ByteArray) : ByteArray := - (UInt256.toByteArray (withdrawTokenAmountWord I)).write 0 - (withdrawTokenTransferOutFailedArgsMem I out) 196 32 - -set_option maxHeartbeats 1000000 in -theorem cometRewardsWithdrawTokenX_afterCall_false_revert {cA gh bl σ σ₀ A I} {g : Sat256} - {out : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (rd : RD cometRewardsBytecode I g (initState cA gh bl σ σ₀ g A I) - (withdrawTokenTransferCallPc + ⟨1⟩) (withdrawTokenPostCallStack true I) - (withdrawTokenPostCallMem I out) withdrawTokenPostCallAw out acc k C) - (hout32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) - (hword : UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) = ⟨0⟩) : - RDrev cometRewardsBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd3287₀⟩ := - cometRewardsWithdrawTokenX_afterCall_toBoolCheck (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) rd hout32 houtSize - have rd3287 := rd3287₀ - rw [hword] at rd3287 - have rd3988 := evm_run rd3287 with [ - dup1, iszero, iszero, dup2, sub, push2 ⟨1004⟩, jumpiNT (by native_decide), - swap1, jump (by jump_dest), jumpdest, codesize, push2 ⟨3978⟩, jump (by jump_dest), - jumpdest, pop, iszero, push2 ⟨3988⟩, jumpiT (by native_decide) (by jump_dest)] - have rd3994 := evm_run rd3988 with [jumpdest, push2 ⟨4016⟩, push1 ⟨64⟩] - have rd3995 := evm_run rd3994 with [ - raw mload 0 ⟨160⟩ withdrawTokenPostCallAw (by native_decide) - mem_cost (withdrawTokenPostDecodeMem_mload64 I hout32 houtSize) - (by native_decide) (by evm_ov)] - have rd4007 := evm_run rd3995 with [ - swap3, dup4, swap3, push4 withdrawTokenTransferOutFailedSelectorWord, - push1 ⟨224⟩, shl, dup5, - raw mstore 0 (withdrawTokenTransferOutFailedSelectorMem I out) - withdrawTokenPostCallAw (by native_decide) mem_cost - (by - rw [show (⟨160⟩ : UInt256).toNat = 160 from by decide]) - (by native_decide) (by evm_ov)] - have rd3901 := evm_run rd4007 with [ - push1 ⟨4⟩, dup5, add, push2 ⟨3888⟩, jump (by jump_dest), - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, swap1, swap2, - and, dup2] - have rd3902 := evm_run rd3901 with [ - raw mstore 0 (withdrawTokenTransferOutFailedArgsMem I out) - withdrawTokenPostCallAw (by native_decide) mem_cost - (by - rw [show ((⟨160⟩ : UInt256) + ⟨4⟩).toNat = 164 from by native_decide] - unfold withdrawTokenTransferOutFailedArgsMem - rfl) - (by native_decide) (by evm_ov)] - have rd3909 := evm_run rd3902 with [ - push1 ⟨32⟩, dup2, add, swap2, swap1, swap2, - raw mstore (Cₘ (UInt256.ofNat 8) - Cₘ withdrawTokenPostCallAw) - (withdrawTokenTransferOutFailedMem I out) (UInt256.ofNat 8) - (by native_decide) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, - withdrawTokenPostCallAw] - native_decide) - (by - rw [show ((⟨160⟩ : UInt256) + ⟨4⟩ + ⟨32⟩).toNat = 196 from by native_decide]) - (by native_decide) (by evm_ov)] - exact evm_run rd3909 with [ - push1 ⟨64⟩, add, swap1, jump (by jump_dest), jumpdest, sub, swap1, - raw rev 0 (by native_decide) mem_cost (by evm_ov)] - -/-- `withdrawToken(address,address,uint256)` body, reached at pc 2758. -/ -theorem cometRewardsWithdrawTokenBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = cometRewardsBytecode) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) (hwv : I.weiValue = ⟨0⟩) - (hsel : selIs I (cometRewardsSelBytes 0)) - (hreach : ∃ k C, RD cometRewardsBytecode I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) withdrawTokenPc - (dispatchArm0Stack I) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have _hperm : I.perm = true := hperm - have hsz4 := cometRewardsWithdrawTokenSelector_size hsel - have hd := cometRewardsDispatch_withdrawToken (cd := I.calldata) hsel - by_cases hsz100 : 100 ≤ I.calldata.size - · by_cases hhi : I.calldata.size < 2 ^ 255 + 4 - · by_cases hcanon0 : (withdrawTokenTokenWord I).toNat < EVM.addressModulus - · by_cases hcanon1 : (withdrawTokenToWord I).toNat < EVM.addressModulus - · have hdec := - cometRewardsDecode_withdrawToken_ok (I := I) hsz100 hhi hcanon0 hcanon1 - have hword : governorWord σ_evm I = governorWord σ_solm I := - accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ ⟨0⟩ - have hretWord : governorReturnWord σ_evm I = governorReturnWord σ_solm I := by - simp [governorReturnWord, hword] - by_cases hauth : governorReturnWord σ_evm I = solcSourceWord I - · have hauthSolm : governorReturnWord σ_solm I = solcSourceWord I := by - rw [← hretWord] - exact hauth - have hgovSolm : - UInt256.land (Solm.EVM.storageLoad - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.codeOwner - ⟨0⟩) solcAddrMask = - solcSourceWord - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv := by - simpa [governorReturnWord, governorWord, initState, Solm.EVM.storageLoad, - State.lookupAccount] using hauthSolm - by_cases hdepth : I.depth.val < 1024 - · obtain ⟨cA', σ'_evm, σ'_solm, A'_solm, z, out, kPost, CPost, - hcallS, hPostAccounts, rdPost, houtSign⟩ := - cometRewardsWithdrawTokenX_call_transfer_made - (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) - (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := g) - hperm hwv hsz100 hsize hhi hcanon0 hcanon1 hauth hdepth hreach - hAccounts - let evmPost : EVM.State := - { initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σ'_solm - substate := A'_solm - createdAccounts := cA' } - have houtSize : out.size < UInt256.size := lt_size_of_lt_sign houtSign - cases z - · have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (withdrawTokenStore I) - withdrawTokenTransition.body .reverted := by - exact cometRewardsWithdrawTokenBodyReverts_callFailure - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - (by simpa [evmPost] using hcallS) - exact (cometRewardsWithdrawTokenX_afterCall_failure rdPost houtSize) - |>.reEquivExecutionRevert hcode hd hdec hbody - · by_cases hshort : out.size < 32 - · have hdecTransfer := cometRewardsTransfer_decode_none_short - (out := out) hshort - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (withdrawTokenStore I) - withdrawTokenTransition.body .reverted := by - exact cometRewardsWithdrawTokenBodyReverts_decode - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - (by simpa [evmPost] using hcallS) - hdecTransfer - exact (cometRewardsWithdrawTokenX_afterCall_short_revert - rdPost hshort houtSize) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have hout32 : 32 ≤ out.size := by omega - let word : UInt256 := - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) - by_cases hzero : word = ⟨0⟩ - · have hdecTransfer := cometRewardsTransfer_decode_false - (out := out) hout32 houtSign (by simpa [word] using hzero) - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (withdrawTokenStore I) - withdrawTokenTransition.body .reverted := by - exact cometRewardsWithdrawTokenBodyReverts_false - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - (by simpa [evmPost] using hcallS) - hdecTransfer - exact (cometRewardsWithdrawTokenX_afterCall_false_revert - rdPost hout32 houtSize (by simpa [word] using hzero)) - |>.reEquivExecutionRevert hcode hd hdec hbody - · by_cases hone : word = ⟨1⟩ - · have hdecTransfer := cometRewardsTransfer_decode_true - (out := out) hout32 houtSign (by simpa [word] using hone) - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (withdrawTokenStore I) - withdrawTokenTransition.body - (.returned - (resumeAfterInternalCall - (withdrawTokenFrame - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I) - "_sent" none) - evmPost none) := by - exact cometRewardsWithdrawTokenBodyReturns_true - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - (by simpa [evmPost] using hcallS) - hdecTransfer - exact (cometRewardsWithdrawTokenX_afterCall_true_return - rdPost hout32 houtSize (by simpa [word] using hone)) - |>.reEquivExecutionGenAccountMapEquiv hcode hd hdec hbody - (by simp [evmPost]) - (by simpa [evmPost] using hPostAccounts) - (returnEquiv.fallthrough rfl rfl (by native_decide)) - · have hdecTransfer := cometRewardsTransfer_decode_none_noncanon - (out := out) hout32 houtSign - (by simpa [word] using hzero) - (by simpa [word] using hone) - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (withdrawTokenStore I) - withdrawTokenTransition.body .reverted := by - exact cometRewardsWithdrawTokenBodyReverts_decode - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - evmPost I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - hgovSolm - (by simpa [evmPost] using hcallS) - hdecTransfer - exact (cometRewardsWithdrawTokenX_afterCall_noncanon_revert - rdPost hout32 houtSize - (by simpa [word] using hzero) - (by simpa [word] using hone)) - |>.reEquivExecutionRevert hcode hd hdec hbody - · rw [not_lt] at hdepth - have hdepth1024 : I.depth = 1024 := Fin.ext (by have := I.depth.isLt; omega) - let evmInit : EVM.State := - initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I - let evmFail : EVM.State := - { evmInit with - substate := - (evmInit.addAccessedAccount - (EVM.address (withdrawTokenTransferTarget I))).substate } - have hcallS : - typedCallViaEVM config evmInit - (EVM.address (withdrawTokenTransferTarget I)) "transfer" 0 - (withdrawTokenTransferArgs I) - (false, evmFail, ByteArray.empty) true := by - exact callNotMade_depthLimit - (cfg := config) (evm := evmInit) - (tgt := EVM.address (withdrawTokenTransferTarget I)) - (name := "transfer") (args := withdrawTokenTransferArgs I) - (calldata := - (withdrawTokenTransferCalldataMem - (withdrawTokenToWord I) (withdrawTokenAmountWord I)).readWithPadding - 128 withdrawTokenTransferCallSize.toNat) - (callPerm := true) - (withdrawTokenTransferCalldataMem_encode_args I hcanon1) - (by simpa [evmInit, initState] using hdepth1024) - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (withdrawTokenStore I) - withdrawTokenTransition.body .reverted := by - exact cometRewardsWithdrawTokenBodyReverts_callFailure - evmInit evmFail I - (by simp only [evmInit, initState]; exact hwv) - (by simp only [evmInit, initState]; exact hhi) - (by simpa [evmInit] using hgovSolm) - hcallS - exact (cometRewardsWithdrawTokenX_callDepthLimit - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := g) - hwv hsz100 hsize hhi hcanon0 hcanon1 hauth hreach hdepth1024) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have hauthSolm : - governorReturnWord σ_solm I ≠ solcSourceWord I := by - intro hbad - exact hauth (by - rw [hretWord] - exact hbad) - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (withdrawTokenStore I) - withdrawTokenTransition.body .reverted := by - exact cometRewardsWithdrawTokenBodyReverts_auth - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I - (by simp only [initState]; exact hwv) - (by simp only [initState]; exact hhi) - (by - simpa [governorReturnWord, governorWord, initState, Solm.EVM.storageLoad, - State.lookupAccount] using hauthSolm) - exact (cometRewardsX_withdrawToken_revert_auth (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanon0 hcanon1 hauth hreach) - |>.reEquivExecutionRevert hcode hd hdec hbody - · have hdec := cometRewardsDecode_withdrawToken_none_noncanon_to - (I := I) hsz100 hhi hcanon0 hcanon1 - have hnc : UInt256.eq (withdrawTokenToWord I) - (UInt256.land (withdrawTokenToWord I) solcAddrMask) = ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanon1 (solcAddrCanonical_of_clean he)) - exact (cometRewardsWithdrawTokenX_noncanon_to (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hcanon0 hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hdec := cometRewardsDecode_withdrawToken_none_noncanon_token - (I := I) hsz100 hhi hcanon0 - have hnc : UInt256.eq (withdrawTokenTokenWord I) - (UInt256.land (withdrawTokenTokenWord I) solcAddrMask) = ⟨0⟩ := - uInt256_eq_zero_of_ne - (fun he => hcanon0 (solcAddrCanonical_of_clean he)) - exact (cometRewardsWithdrawTokenX_noncanon_token (g := Sat256.ofUInt256 g) - hwv hsz100 hsize hhi hnc hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hbig : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - have hdec := cometRewardsDecode_withdrawToken_none_huge (I := I) hbig - exact (cometRewardsWithdrawTokenX_hugearg (g := Sat256.ofUInt256 g) - hwv hsize hbig hreach) - |>.reEquivDecodingFailed hcode hd hdec - · have hshort : I.calldata.size < 100 := by omega - have hdec := cometRewardsDecode_withdrawToken_none_short (I := I) hsz4 hshort - exact (cometRewardsWithdrawTokenX_shortarg (g := Sat256.ofUInt256 g) - hwv hsz4 hsize hshort hreach) - |>.reEquivDecodingFailed hcode hd hdec - -end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/EAS/Attester/Attest.lean b/Benchmarks/EAS/Attester/Attest.lean deleted file mode 100644 index e0ee0eb1..00000000 --- a/Benchmarks/EAS/Attester/Attest.lean +++ /dev/null @@ -1,3883 +0,0 @@ -import Benchmarks.EAS.Attester.Common -import Reasoning.ExternalCall - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -/-! ## `attest(bytes32,uint256)` -/ - -def attesterAttestSchemaBytes (I : ExecutionEnv) : List UInt8 := - (I.calldata.toList.drop 4).take 32 - -def attesterAttestSchemaWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -def attesterAttestInputWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 36 - -def attesterAttestStore (I : ExecutionEnv) : Store := - ((∅ : Store).insert "schema" (.fixedBytes bytes32Width (attesterAttestSchemaBytes I))).insert - "input" (.int (Int.ofNat (attesterAttestInputWord I).toNat)) - -def attesterAttestDataValue (I : ExecutionEnv) : Value := - .tuple - [.address (AccountAddress.ofNat 0), .int 0, .bool true, - .fixedBytes bytes32Width ((EVM.Word.ofNat 0).toBytesBE.drop (32 - (bytes32Width.val + 1))), - .bytes (UInt256.toByteArray (attesterAttestInputWord I)), .int 0] - -def attesterAttestRequestValue (I : ExecutionEnv) : Value := - .tuple [.fixedBytes bytes32Width (attesterAttestSchemaBytes I), attesterAttestDataValue I] - -def attesterAttestArgVals (I : ExecutionEnv) : List Value := - [attesterAttestRequestValue I] - -/-! Local reachability support for `MCOPY`. - -The shared `Reasoning.Reach` layer has copy combinators for calldata/code/returndata, but not for -EIP-5656 `MCOPY`. The runtime generated for `attest` uses `MCOPY` while ABI-encoding the nested -request tuple, so we prove the same wrapper locally from evmlean's `step_mcopy` theorem. -/ - -private def stMcopy (s : State) (a b c : UInt256) (t : List UInt256) : State := - { s with machineState := { s.machineState with - pc := s.machineState.pc + ⟨1⟩, - stack := t, - memory := s.machineState.memory.write b.toNat s.machineState.memory a.toNat c.toNat, - activeWords := UInt256.ofNat - (MachineState.M s.machineState.activeWords.toNat (max a.toNat b.toNat) c.toNat), - execLength := s.machineState.execLength + 1, - gasAvailable := - (s.machineState.gasAvailable.subNat (memoryExpansionCost s .MCOPY)).subNat - (GasConstants.Gverylow + GasConstants.Gcopy * ((c.toNat + 31) / 32)) } } - -private theorem mcopy_xstep {s : State} {code : ByteArray} {pcv a b c : UInt256} - {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.MCOPY, .none)) - (hstk : s.machineState.stack = a :: b :: c :: t) - (hov : t.length ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < memoryExpansionCost s .MCOPY - then .error .OutOfGass - else if (s.machineState.gasAvailable.subNat (memoryExpansionCost s .MCOPY)).toNat - < GasConstants.Gverylow + GasConstants.Gcopy * ((c.toNat + 31) / 32) - then .error .OutOfGass - else .ok (stMcopy s a b c t, .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.MCOPY, .none) := by - rw [hcode, hpc] - exact hdec - rw [← hcode, step_mcopy s hd, hstk] - by_cases hg1 : s.machineState.gasAvailable.toNat < memoryExpansionCost s .MCOPY - · simp only [hg1, if_true] - · by_cases hg2 : (s.machineState.gasAvailable.subNat (memoryExpansionCost s .MCOPY)).toNat - < GasConstants.Gverylow + GasConstants.Gcopy * ((c.toNat + 31) / 32) - · simp only [hg1, hg2, if_true, if_false] - · have hov' : ¬ ((a :: b :: c :: t).length - 3 + 0 > 1024) := by - simp only [List.length_cons] - omega - simp only [hg1, hg2, hov', if_false, stMcopy] - -private theorem RD.mcopyLocal {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c : UInt256} {t : List UInt256} (mcost : ℕ) - (memout : ByteArray) (awout : UInt256) - (h : RD code ee g s0 pc (a :: b :: c :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.MCOPY, .none)) - (hmc : ∀ s : State, s.machineState.activeWords = aw → - s.machineState.stack = a :: b :: c :: t → - memoryExpansionCost s .MCOPY = mcost) - (hmemout : mem.write b.toNat mem a.toNat c.toNat = memout) - (hawout : UInt256.ofNat (MachineState.M aw.toNat (max a.toNat b.toNat) c.toNat) = awout) - (hov : t.length ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) t memout awout rdata acc - (k + 1) - (C + (mcost + (GasConstants.Gverylow + GasConstants.Gcopy * ((c.toNat + 31) / 32)))) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, hee, - hworld⟩ - · exact Or.inl hoog - · have hmcS : memoryExpansionCost s .MCOPY = mcost := hmc s haw hstk - have st := mcopy_xstep hcode hpc hdec hstk hov - rw [hmcS] at st - rw [collapse_two_stage] at st - by_cases gg : - g.toNat < C + (mcost + - (GasConstants.Gverylow + GasConstants.Gcopy * ((c.toNat + 31) / 32))) - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · have hcost_pos : - 0 < mcost + (GasConstants.Gverylow + GasConstants.Gcopy * ((c.toNat + 31) / 32)) := by - simp [GasConstants.Gverylow] - refine Or.inr ⟨stMcopy s a b c t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, by omega, - by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [stMcopy] - exact hcode - · simp only [stMcopy] - rw [hpc] - · rfl - · simp only [stMcopy, hmcS] - rw [hgas, Sat256.subNat_sub_add_of_sub_sub, Sat256.subNat_sub_add_of_sub_sub] - · simp only [stMcopy] - rw [hmem, hmemout] - · simp only [stMcopy] - rw [haw, hawout] - · simp only [stMcopy] - exact hrdata - · simp only [stMcopy] - exact hacc - · exact hee - · exact hworld - -private theorem byteArray_toList_toByteArray (b : ByteArray) : - b.toList.toByteArray = b := by - apply ByteArray.ext - apply Array.toList_inj.mp - rw [byteArray_toList_eq] - simp - -private theorem toByteArray_uInt256OfByteArray_of_size {arr : ByteArray} - (hsize : arr.size = 32) : - UInt256.toByteArray (uInt256OfByteArray arr) = arr := by - rw [← word_toBytesBE_toByteArray_eq_toByteArray (uInt256OfByteArray arr), - toBytesBE_uInt256OfByteArray_of_size hsize, byteArray_toList_toByteArray] - -def attesterAttestExternalCalldata (I : ExecutionEnv) : ByteArray := - attestSelector ++ - UInt256.toByteArray ⟨32⟩ ++ - UInt256.toByteArray (attesterAttestSchemaWord I) ++ - UInt256.toByteArray ⟨64⟩ ++ - UInt256.toByteArray ⟨0⟩ ++ - UInt256.toByteArray ⟨0⟩ ++ - UInt256.toByteArray ⟨1⟩ ++ - UInt256.toByteArray ⟨0⟩ ++ - UInt256.toByteArray ⟨192⟩ ++ - UInt256.toByteArray ⟨0⟩ ++ - UInt256.toByteArray ⟨32⟩ ++ - UInt256.toByteArray (attesterAttestInputWord I) - -private abbrev attesterWriteWord (mem : ByteArray) (off : Nat) (w : UInt256) : ByteArray := - (UInt256.toByteArray w).write 0 mem off 32 - -def attesterAttestEasWord (v : AttesterImmutables) : UInt256 := - EVM.Word.ofNat v.eas.toNat - -def attesterAttestTargetWord (v : AttesterImmutables) : UInt256 := - UInt256.land solcAddrMask (attesterAttestEasWord v) - -theorem attesterAttestEasWord_canonical (v : AttesterImmutables) : - (attesterAttestEasWord v).toNat < EVM.addressModulus := by - change (UInt256.ofNat v.eas.val).toNat < EVM.addressModulus - rw [UInt256.toNat_ofNat_of_lt] - · change v.eas.val < AccountAddress.size - exact v.eas.isLt - · exact lt_of_lt_of_le v.eas.isLt (by decide) - -theorem attesterAttestEasWord_clean (v : AttesterImmutables) : - UInt256.land solcAddrMask (attesterAttestEasWord v) = - attesterAttestEasWord v := - solcAddrMask_clean_left (attesterAttestEasWord_canonical v) - -theorem attesterAttestTargetWord_eq_easWord (v : AttesterImmutables) : - attesterAttestTargetWord v = attesterAttestEasWord v := by - unfold attesterAttestTargetWord - rw [attesterAttestEasWord_clean] - -theorem attesterAttestTarget_eq (v : AttesterImmutables) : - EVM.address v.eas = AccountAddress.ofUInt256 (attesterAttestTargetWord v) := by - rw [attesterAttestTargetWord_eq_easWord] - have hleft : EVM.address (v.eas : Nat) = v.eas := by - apply Fin.ext - simp [EVM.address, EVM.uintN] - exact Nat.mod_eq_of_lt v.eas.isLt - have hright : AccountAddress.ofUInt256 (attesterAttestEasWord v) = v.eas := by - change AccountAddress.ofUInt256 (UInt256.ofNat v.eas.val) = v.eas - have hv : (UInt256.ofNat v.eas.val).val = v.eas.val := by - show (Fin.ofNat UInt256.size v.eas.val).val = v.eas.val - simp only [Fin.ofNat] - exact Nat.mod_eq_of_lt (lt_of_lt_of_le v.eas.isLt (by decide)) - apply Fin.ext - simp [AccountAddress.ofUInt256, hv] - exact Nat.mod_eq_of_lt v.eas.isLt - rw [hleft, hright] - -def attesterAttestMem192 : ByteArray := - attesterWriteWord solcFreePtrMem 64 ⟨192⟩ - -def attesterAttestMemSchema (I : ExecutionEnv) : ByteArray := - attesterWriteWord attesterAttestMem192 128 (attesterAttestSchemaWord I) - -def attesterAttestMem384 (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestMemSchema I) 64 ⟨384⟩ - -def attesterAttestMemRecipient (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestMem384 I) 192 ⟨0⟩ - -def attesterAttestMemExpiration (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestMemRecipient I) 224 ⟨0⟩ - -def attesterAttestMemRevocable (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestMemExpiration I) 256 ⟨1⟩ - -def attesterAttestMemRefUID (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestMemRevocable I) 288 ⟨0⟩ - -def attesterAttestMemInputWord (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestMemRefUID I) 416 (attesterAttestInputWord I) - -def attesterAttestMemBytesLen (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestMemInputWord I) 384 ⟨32⟩ - -def attesterAttestMem448 (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestMemBytesLen I) 64 ⟨448⟩ - -def attesterAttestMemDataOffset (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestMem448 I) 320 ⟨384⟩ - -def attesterAttestMemDataPad (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestMemDataOffset I) 352 ⟨0⟩ - -def attesterAttestSourceMem (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestMemDataPad I) 160 ⟨192⟩ - -def attesterAttestSelectorWord : UInt256 := - UInt256.shiftLeft (UInt256.land ⟨0xffffffff⟩ ⟨0xf17325e7⟩) ⟨224⟩ - -def attesterAttestCallMemSelector (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestSourceMem I) 448 attesterAttestSelectorWord - -def attesterAttestCallMemArgOffset (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestCallMemSelector I) 452 ⟨32⟩ - -def attesterAttestCallMemSchema (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestCallMemArgOffset I) 484 (attesterAttestSchemaWord I) - -def attesterAttestCallMemDataOffset (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestCallMemSchema I) 516 ⟨64⟩ - -def attesterAttestCallMemRecipient (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestCallMemDataOffset I) 548 ⟨0⟩ - -def attesterAttestCallMemExpiration (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestCallMemRecipient I) 580 ⟨0⟩ - -def attesterAttestCallMemRevocable (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestCallMemExpiration I) 612 ⟨1⟩ - -def attesterAttestCallMemRefUID (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestCallMemRevocable I) 644 ⟨0⟩ - -def attesterAttestCallMemBytesOffset (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestCallMemRefUID I) 676 ⟨192⟩ - -def attesterAttestCallMemBytesLen (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestCallMemBytesOffset I) 740 ⟨32⟩ - -def attesterAttestCallMemBytesData (I : ExecutionEnv) : ByteArray := - (attesterAttestCallMemBytesLen I).write 416 (attesterAttestCallMemBytesLen I) 772 32 - -def attesterAttestCallMemPad (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestCallMemBytesData I) 804 ⟨0⟩ - -def attesterAttestCallMemValue (I : ExecutionEnv) : ByteArray := - attesterWriteWord (attesterAttestCallMemPad I) 708 ⟨0⟩ - -def attesterAttestCallMem (I : ExecutionEnv) : ByteArray := - attesterAttestCallMemValue I - -private theorem attesterWriteWord_size_eq_max (mem : ByteArray) (off : Nat) (w : UInt256) - (hgap : off - mem.size < USize.size) : - (attesterWriteWord mem off w).size = max mem.size (off + 32) := by - unfold attesterWriteWord - by_cases hoff : off ≤ mem.size - · rw [toByteArray_write32_size_of_le mem w off mem.size (max mem.size (off + 32)) rfl - hoff rfl] - · have hge : mem.size ≤ off := by omega - rw [toByteArray_write32_size_of_ge mem w off mem.size (off + 32) rfl hge hgap rfl] - rw [max_eq_right (by omega)] - -private theorem attesterWriteWord_read_below_len (mem : ByteArray) (off : Nat) - (w : UInt256) (read len : Nat) - (hread : read + len ≤ mem.size) (hbelow : read + len ≤ off) - (hpos : 0 < len) (hlen64 : len < 2 ^ 64) - (hgap : off - mem.size < USize.size) : - (attesterWriteWord mem off w).readWithPadding read len = - mem.readWithPadding read len := by - exact toByteArray_write_read_below_len_of_gap w mem off read len hread hbelow hpos hlen64 hgap - -private theorem attesterWriteWord_read_above_len (mem : ByteArray) (off : Nat) - (w : UInt256) (read len : Nat) - (hoff : off ≤ mem.size) (habove : off + 32 ≤ read) (hin : read + len ≤ mem.size) - (hpos : 0 < len) (hlen64 : len < 2 ^ 64) : - (attesterWriteWord mem off w).readWithPadding read len = - mem.readWithPadding read len := by - unfold attesterWriteWord - exact write32_read_above_len _ _ off read len (by rw [toByteArray_size]) hoff habove hin - hpos hlen64 - -private theorem attesterWriteWord_read_back (mem : ByteArray) (off : Nat) (w : UInt256) - (hgap : off - mem.size < USize.size) : - (attesterWriteWord mem off w).readWithPadding off 32 = UInt256.toByteArray w := by - exact toByteArray_write_read_back_of_gap w mem off hgap - -private theorem attesterToByteArray_write_eq_nat (v : UInt256) (mem : ByteArray) (off : ℕ) - (hoff : mem.size ≤ off) : - (UInt256.toByteArray v).write 0 mem off 32 = - mem ++ ffi.ByteArray.zeroes (off - mem.size) ++ UInt256.toByteArray v := by - have hsz : (UInt256.toByteArray v).data.size = 32 := UInt256.toByteArrayWithSizeProof v |>.2 - have hpz : (ffi.ByteArray.zeroes (off - mem.size)).data.size = off - mem.size := by - rw [show (ffi.ByteArray.zeroes (off - mem.size)).data.size = - (ffi.ByteArray.zeroes (off - mem.size)).size from rfl, ByteArray_zeroes_size] - apply ByteArray.ext - unfold ByteArray.write - rw [if_neg (by decide : ¬ ((32 : ℕ) = 0)), - if_neg (show ¬ (0 ≥ (UInt256.toByteArray v).size) from by - rw [show (UInt256.toByteArray v).size = 32 from hsz]; omega)] - simp only [ByteArray.data_copySlice, ByteArray.data_append] - have hv : v.toByteArray.size = 32 := hsz - have hDsz : (mem.data ++ (ffi.ByteArray.zeroes (off - mem.size)).data).size = off := by - rw [Array.size_append, hpz] - show mem.size + (off - mem.size) = off - omega - rw [hv, show (min 32 (32 - 0) : ℕ) = 32 from rfl, - show min mem.size (off + 32) - (off + 32) = 0 from by omega, - show (ffi.ByteArray.zeroes 0).data = (#[] : Array UInt8) from by - rw [zeroes_zero (n := 0) (by rfl)] - rfl] - rw [Array.append_empty] - rw [Array.extract_eq_self_of_le (by rw [hDsz]), - Array.extract_eq_self_of_le (show v.toByteArray.data.size ≤ 0 + (32 + 0) from by rw [hsz]), - Array.extract_eq_empty_of_le (by rw [hDsz]; omega), - Array.append_empty] - -private theorem attesterWriteWord_size_eq_max_nat (mem : ByteArray) (off : Nat) (w : UInt256) : - (attesterWriteWord mem off w).size = max mem.size (off + 32) := by - unfold attesterWriteWord - by_cases hoff : off ≤ mem.size - · rw [toByteArray_write32_size_of_le mem w off mem.size (max mem.size (off + 32)) rfl - hoff rfl] - · have hge : mem.size ≤ off := by omega - rw [attesterToByteArray_write_eq_nat w mem off hge] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray_zeroes_size, toByteArray_size] - rw [max_eq_right (by omega)] - omega - -private theorem attesterWriteWord_read_back_nat (mem : ByteArray) (off : Nat) (w : UInt256) : - (attesterWriteWord mem off w).readWithPadding off 32 = UInt256.toByteArray w := by - unfold attesterWriteWord - by_cases hle : off ≤ mem.size - · rw [write32_read_back _ _ off (by rw [toByteArray_size]) hle] - rw [show 32 = (UInt256.toByteArray w).size by rw [toByteArray_size]] - exact byteArray_extract_self _ - · have hge : mem.size ≤ off := by omega - rw [attesterToByteArray_write_eq_nat w mem off hge] - rw [readWithPadding_eq_extract _ off (by - rw [ByteArray.size_append, ByteArray.size_append, ByteArray_zeroes_size, toByteArray_size] - omega)] - rw [extract_append_right_window - (mem ++ ffi.ByteArray.zeroes (off - mem.size)) - (UInt256.toByteArray w) off (off + 32) (by - rw [ByteArray.size_append, ByteArray_zeroes_size] - omega)] - rw [ByteArray.size_append, ByteArray_zeroes_size] - rw [show off - (mem.size + (off - mem.size)) = 0 by omega, - show off + 32 - (mem.size + (off - mem.size)) = 32 by omega] - rw [show (UInt256.toByteArray w).extract 0 32 = UInt256.toByteArray w from by - rw [show 32 = (UInt256.toByteArray w).size by rw [toByteArray_size]] - exact byteArray_extract_self _] - -private theorem attesterWriteWord_read_below_len_nat (mem : ByteArray) (off : Nat) - (w : UInt256) (read len : Nat) - (hread : read + len ≤ mem.size) (hbelow : read + len ≤ off) - (hpos : 0 < len) (hlen64 : len < 2 ^ 64) : - (attesterWriteWord mem off w).readWithPadding read len = - mem.readWithPadding read len := by - unfold attesterWriteWord - by_cases hle : off ≤ mem.size - · exact write32_read_below_len _ _ off read len (by rw [toByteArray_size]) hle - hbelow hread hpos hlen64 - · have hge : mem.size ≤ off := by omega - rw [attesterToByteArray_write_eq_nat w mem off hge] - rw [readWithPadding_eq_extract' _ read len hpos hlen64 (by - rw [ByteArray.size_append, ByteArray.size_append, ByteArray_zeroes_size, toByteArray_size] - omega)] - rw [extract_append_left _ _ _ _ (by - rw [ByteArray.size_append, ByteArray_zeroes_size] - omega)] - rw [extract_append_left _ _ _ _ hread] - exact (readWithPadding_eq_extract' _ read len hpos hlen64 hread).symm - -private theorem write_read_below_end_from_len (src base : ByteArray) - (srcAddr writeLen read len : Nat) - (hwrite : writeLen ≠ 0) (hsrc : srcAddr + writeLen ≤ src.size) - (hread : read + len ≤ base.size) (hbelow : read + len ≤ base.size) - (hpos : 0 < len) (hlen64 : len < 2 ^ 64) : - (src.write srcAddr base base.size writeLen).readWithPadding read len = - base.readWithPadding read len := by - rw [write_at_end_eq_from src base srcAddr writeLen hwrite hsrc] - rw [readWithPadding_eq_extract' _ read len hpos hlen64 (by - rw [ByteArray.size_append, ByteArray.size_extract] - omega)] - rw [extract_append_left _ _ _ _ hbelow] - exact (readWithPadding_eq_extract' base read len hpos hlen64 hread).symm - -theorem attesterAttestMem192_size : attesterAttestMem192.size = 96 := by - unfold attesterAttestMem192 - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [solcFreePtrMem_size] - exact lt_usize _ (by norm_num)), - solcFreePtrMem_size] - norm_num - -theorem attesterAttestMemSchema_size (I : ExecutionEnv) : - (attesterAttestMemSchema I).size = 160 := by - unfold attesterAttestMemSchema - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestMem192_size] - exact lt_usize _ (by norm_num)), - attesterAttestMem192_size] - norm_num - -theorem attesterAttestMem384_size (I : ExecutionEnv) : - (attesterAttestMem384 I).size = 160 := by - unfold attesterAttestMem384 - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestMemSchema_size] - exact lt_usize _ (by norm_num)), - attesterAttestMemSchema_size] - norm_num - -theorem attesterAttestMemRecipient_size (I : ExecutionEnv) : - (attesterAttestMemRecipient I).size = 224 := by - unfold attesterAttestMemRecipient - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestMem384_size] - exact lt_usize _ (by norm_num)), - attesterAttestMem384_size] - norm_num - -theorem attesterAttestMemExpiration_size (I : ExecutionEnv) : - (attesterAttestMemExpiration I).size = 256 := by - unfold attesterAttestMemExpiration - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestMemRecipient_size] - exact lt_usize _ (by norm_num)), - attesterAttestMemRecipient_size] - norm_num - -theorem attesterAttestMemRevocable_size (I : ExecutionEnv) : - (attesterAttestMemRevocable I).size = 288 := by - unfold attesterAttestMemRevocable - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestMemExpiration_size] - exact lt_usize _ (by norm_num)), - attesterAttestMemExpiration_size] - norm_num - -theorem attesterAttestMemRefUID_size (I : ExecutionEnv) : - (attesterAttestMemRefUID I).size = 320 := by - unfold attesterAttestMemRefUID - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestMemRevocable_size] - exact lt_usize _ (by norm_num)), - attesterAttestMemRevocable_size] - norm_num - -theorem attesterAttestMemInputWord_size (I : ExecutionEnv) : - (attesterAttestMemInputWord I).size = 448 := by - unfold attesterAttestMemInputWord - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestMemRefUID_size] - exact lt_usize _ (by norm_num)), - attesterAttestMemRefUID_size] - norm_num - -theorem attesterAttestMemBytesLen_size (I : ExecutionEnv) : - (attesterAttestMemBytesLen I).size = 448 := by - unfold attesterAttestMemBytesLen - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestMemInputWord_size] - exact lt_usize _ (by norm_num)), - attesterAttestMemInputWord_size] - norm_num - -theorem attesterAttestMem448_size (I : ExecutionEnv) : - (attesterAttestMem448 I).size = 448 := by - unfold attesterAttestMem448 - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestMemBytesLen_size] - exact lt_usize _ (by norm_num)), - attesterAttestMemBytesLen_size] - norm_num - -theorem attesterAttestMemDataOffset_size (I : ExecutionEnv) : - (attesterAttestMemDataOffset I).size = 448 := by - unfold attesterAttestMemDataOffset - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestMem448_size] - exact lt_usize _ (by norm_num)), - attesterAttestMem448_size] - norm_num - -theorem attesterAttestMemDataPad_size (I : ExecutionEnv) : - (attesterAttestMemDataPad I).size = 448 := by - unfold attesterAttestMemDataPad - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestMemDataOffset_size] - exact lt_usize _ (by norm_num)), - attesterAttestMemDataOffset_size] - norm_num - -theorem attesterAttestSourceMem_size (I : ExecutionEnv) : - (attesterAttestSourceMem I).size = 448 := by - unfold attesterAttestSourceMem - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestMemDataPad_size] - exact lt_usize _ (by norm_num)), - attesterAttestMemDataPad_size] - norm_num - -theorem attesterAttestMem192_read64 : - attesterAttestMem192.readWithPadding 64 32 = UInt256.toByteArray ⟨192⟩ := by - unfold attesterAttestMem192 - exact attesterWriteWord_read_back _ _ _ (by - rw [solcFreePtrMem_size] - exact lt_usize _ (by norm_num)) - -theorem attesterAttestMemSchema_read64 (I : ExecutionEnv) : - (attesterAttestMemSchema I).readWithPadding 64 32 = UInt256.toByteArray ⟨192⟩ := by - unfold attesterAttestMemSchema - rw [attesterWriteWord_read_below_len _ 128 _ 64 32 - (by rw [attesterAttestMem192_size]) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestMem192_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestMem192_read64 - -theorem attesterAttestMem384_read64 (I : ExecutionEnv) : - (attesterAttestMem384 I).readWithPadding 64 32 = UInt256.toByteArray ⟨384⟩ := by - unfold attesterAttestMem384 - exact attesterWriteWord_read_back _ _ _ (by - rw [attesterAttestMemSchema_size] - exact lt_usize _ (by norm_num)) - -theorem attesterAttestMemRecipient_read64 (I : ExecutionEnv) : - (attesterAttestMemRecipient I).readWithPadding 64 32 = UInt256.toByteArray ⟨384⟩ := by - unfold attesterAttestMemRecipient - rw [attesterWriteWord_read_below_len _ 192 _ 64 32 - (by rw [attesterAttestMem384_size]; norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestMem384_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestMem384_read64 I - -theorem attesterAttestMemExpiration_read64 (I : ExecutionEnv) : - (attesterAttestMemExpiration I).readWithPadding 64 32 = UInt256.toByteArray ⟨384⟩ := by - unfold attesterAttestMemExpiration - rw [attesterWriteWord_read_below_len _ 224 _ 64 32 - (by rw [attesterAttestMemRecipient_size]; norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestMemRecipient_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestMemRecipient_read64 I - -theorem attesterAttestMemRevocable_read64 (I : ExecutionEnv) : - (attesterAttestMemRevocable I).readWithPadding 64 32 = UInt256.toByteArray ⟨384⟩ := by - unfold attesterAttestMemRevocable - rw [attesterWriteWord_read_below_len _ 256 _ 64 32 - (by rw [attesterAttestMemExpiration_size]; norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestMemExpiration_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestMemExpiration_read64 I - -theorem attesterAttestMemRefUID_read64 (I : ExecutionEnv) : - (attesterAttestMemRefUID I).readWithPadding 64 32 = UInt256.toByteArray ⟨384⟩ := by - unfold attesterAttestMemRefUID - rw [attesterWriteWord_read_below_len _ 288 _ 64 32 - (by rw [attesterAttestMemRevocable_size]; norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestMemRevocable_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestMemRevocable_read64 I - -theorem attesterAttestMemInputWord_read64 (I : ExecutionEnv) : - (attesterAttestMemInputWord I).readWithPadding 64 32 = UInt256.toByteArray ⟨384⟩ := by - unfold attesterAttestMemInputWord - rw [attesterWriteWord_read_below_len _ 416 _ 64 32 - (by rw [attesterAttestMemRefUID_size]; norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestMemRefUID_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestMemRefUID_read64 I - -theorem attesterAttestMem448_read64 (I : ExecutionEnv) : - (attesterAttestMem448 I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestMem448 - exact attesterWriteWord_read_back _ _ _ (by - rw [attesterAttestMemBytesLen_size] - exact lt_usize _ (by norm_num)) - -theorem attesterAttestMemDataOffset_read64 (I : ExecutionEnv) : - (attesterAttestMemDataOffset I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestMemDataOffset - rw [attesterWriteWord_read_below_len _ 320 _ 64 32 - (by rw [attesterAttestMem448_size]; norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestMem448_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestMem448_read64 I - -theorem attesterAttestMemDataPad_read64 (I : ExecutionEnv) : - (attesterAttestMemDataPad I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestMemDataPad - rw [attesterWriteWord_read_below_len _ 352 _ 64 32 - (by rw [attesterAttestMemDataOffset_size]; norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestMemDataOffset_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestMemDataOffset_read64 I - -theorem attesterAttestSourceMem_read64 (I : ExecutionEnv) : - (attesterAttestSourceMem I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestSourceMem - rw [attesterWriteWord_read_below_len _ 160 _ 64 32 - (by rw [attesterAttestMemDataPad_size]; norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestMemDataPad_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestMemDataPad_read64 I - -theorem attesterAttestSourceMem_read128 (I : ExecutionEnv) : - (attesterAttestSourceMem I).readWithPadding 128 32 = - UInt256.toByteArray (attesterAttestSchemaWord I) := by - change (writeCascade attesterAttestMem192 - [(128, attesterAttestSchemaWord I), (64, (⟨384⟩ : UInt256)), (192, (⟨0⟩ : UInt256)), - (224, (⟨0⟩ : UInt256)), (256, (⟨1⟩ : UInt256)), (288, (⟨0⟩ : UInt256)), - (416, attesterAttestInputWord I), (384, (⟨32⟩ : UInt256)), (64, (⟨448⟩ : UInt256)), - (320, (⟨384⟩ : UInt256)), (352, (⟨0⟩ : UInt256)), (160, (⟨192⟩ : UInt256))]).readWithPadding - 128 32 = UInt256.toByteArray (attesterAttestSchemaWord I) - exact writeCascade_read_word_of_head_of_base attesterAttestMem192 - (word := attesterAttestSchemaWord I) - (rest := [(64, (⟨384⟩ : UInt256)), (192, (⟨0⟩ : UInt256)), - (224, (⟨0⟩ : UInt256)), (256, (⟨1⟩ : UInt256)), (288, (⟨0⟩ : UInt256)), - (416, attesterAttestInputWord I), (384, (⟨32⟩ : UInt256)), (64, (⟨448⟩ : UInt256)), - (320, (⟨384⟩ : UInt256)), (352, (⟨0⟩ : UInt256)), (160, (⟨192⟩ : UInt256))]) - (hbase := attesterAttestMem192_size) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites] - native_decide) - -theorem attesterAttestSourceMem_read160 (I : ExecutionEnv) : - (attesterAttestSourceMem I).readWithPadding 160 32 = UInt256.toByteArray ⟨192⟩ := by - unfold attesterAttestSourceMem - exact attesterWriteWord_read_back _ _ _ (by - rw [attesterAttestMemDataPad_size] - exact lt_usize _ (by norm_num)) - -theorem attesterAttestSourceMem_read192 (I : ExecutionEnv) : - (attesterAttestSourceMem I).readWithPadding 192 32 = UInt256.toByteArray ⟨0⟩ := by - change (writeCascade (attesterAttestMem384 I) - [(192, (⟨0⟩ : UInt256)), (224, (⟨0⟩ : UInt256)), (256, (⟨1⟩ : UInt256)), - (288, (⟨0⟩ : UInt256)), (416, attesterAttestInputWord I), - (384, (⟨32⟩ : UInt256)), (64, (⟨448⟩ : UInt256)), - (320, (⟨384⟩ : UInt256)), (352, (⟨0⟩ : UInt256)), - (160, (⟨192⟩ : UInt256))]).readWithPadding 192 32 = - UInt256.toByteArray ⟨0⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestMem384 I) - (word := (⟨0⟩ : UInt256)) - (rest := [(224, (⟨0⟩ : UInt256)), (256, (⟨1⟩ : UInt256)), - (288, (⟨0⟩ : UInt256)), (416, attesterAttestInputWord I), - (384, (⟨32⟩ : UInt256)), (64, (⟨448⟩ : UInt256)), - (320, (⟨384⟩ : UInt256)), (352, (⟨0⟩ : UInt256)), - (160, (⟨192⟩ : UInt256))]) - (hbase := attesterAttestMem384_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites] - native_decide) - -theorem attesterAttestSourceMem_read224 (I : ExecutionEnv) : - (attesterAttestSourceMem I).readWithPadding 224 32 = UInt256.toByteArray ⟨0⟩ := by - change (writeCascade (attesterAttestMemRecipient I) - [(224, (⟨0⟩ : UInt256)), (256, (⟨1⟩ : UInt256)), (288, (⟨0⟩ : UInt256)), - (416, attesterAttestInputWord I), (384, (⟨32⟩ : UInt256)), - (64, (⟨448⟩ : UInt256)), (320, (⟨384⟩ : UInt256)), - (352, (⟨0⟩ : UInt256)), (160, (⟨192⟩ : UInt256))]).readWithPadding 224 32 = - UInt256.toByteArray ⟨0⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestMemRecipient I) - (word := (⟨0⟩ : UInt256)) - (rest := [(256, (⟨1⟩ : UInt256)), (288, (⟨0⟩ : UInt256)), - (416, attesterAttestInputWord I), (384, (⟨32⟩ : UInt256)), - (64, (⟨448⟩ : UInt256)), (320, (⟨384⟩ : UInt256)), - (352, (⟨0⟩ : UInt256)), (160, (⟨192⟩ : UInt256))]) - (hbase := attesterAttestMemRecipient_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites] - native_decide) - -theorem attesterAttestSourceMem_read256 (I : ExecutionEnv) : - (attesterAttestSourceMem I).readWithPadding 256 32 = UInt256.toByteArray ⟨1⟩ := by - change (writeCascade (attesterAttestMemExpiration I) - [(256, (⟨1⟩ : UInt256)), (288, (⟨0⟩ : UInt256)), - (416, attesterAttestInputWord I), (384, (⟨32⟩ : UInt256)), - (64, (⟨448⟩ : UInt256)), (320, (⟨384⟩ : UInt256)), - (352, (⟨0⟩ : UInt256)), (160, (⟨192⟩ : UInt256))]).readWithPadding 256 32 = - UInt256.toByteArray ⟨1⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestMemExpiration I) - (word := (⟨1⟩ : UInt256)) - (rest := [(288, (⟨0⟩ : UInt256)), (416, attesterAttestInputWord I), - (384, (⟨32⟩ : UInt256)), (64, (⟨448⟩ : UInt256)), - (320, (⟨384⟩ : UInt256)), (352, (⟨0⟩ : UInt256)), - (160, (⟨192⟩ : UInt256))]) - (hbase := attesterAttestMemExpiration_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites] - native_decide) - -theorem attesterAttestSourceMem_read288 (I : ExecutionEnv) : - (attesterAttestSourceMem I).readWithPadding 288 32 = UInt256.toByteArray ⟨0⟩ := by - change (writeCascade (attesterAttestMemRevocable I) - [(288, (⟨0⟩ : UInt256)), (416, attesterAttestInputWord I), - (384, (⟨32⟩ : UInt256)), (64, (⟨448⟩ : UInt256)), - (320, (⟨384⟩ : UInt256)), (352, (⟨0⟩ : UInt256)), - (160, (⟨192⟩ : UInt256))]).readWithPadding 288 32 = UInt256.toByteArray ⟨0⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestMemRevocable I) - (word := (⟨0⟩ : UInt256)) - (rest := [(416, attesterAttestInputWord I), (384, (⟨32⟩ : UInt256)), - (64, (⟨448⟩ : UInt256)), (320, (⟨384⟩ : UInt256)), - (352, (⟨0⟩ : UInt256)), (160, (⟨192⟩ : UInt256))]) - (hbase := attesterAttestMemRevocable_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites] - native_decide) - -theorem attesterAttestSourceMem_read320 (I : ExecutionEnv) : - (attesterAttestSourceMem I).readWithPadding 320 32 = UInt256.toByteArray ⟨384⟩ := by - change (writeCascade (attesterAttestMem448 I) - [(320, (⟨384⟩ : UInt256)), (352, (⟨0⟩ : UInt256)), - (160, (⟨192⟩ : UInt256))]).readWithPadding 320 32 = UInt256.toByteArray ⟨384⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestMem448 I) - (word := (⟨384⟩ : UInt256)) - (rest := [(352, (⟨0⟩ : UInt256)), (160, (⟨192⟩ : UInt256))]) - (hbase := attesterAttestMem448_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites]) - -theorem attesterAttestSourceMem_read352 (I : ExecutionEnv) : - (attesterAttestSourceMem I).readWithPadding 352 32 = UInt256.toByteArray ⟨0⟩ := by - change (writeCascade (attesterAttestMemDataOffset I) - [(352, (⟨0⟩ : UInt256)), (160, (⟨192⟩ : UInt256))]).readWithPadding 352 32 = - UInt256.toByteArray ⟨0⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestMemDataOffset I) - (word := (⟨0⟩ : UInt256)) (rest := [(160, (⟨192⟩ : UInt256))]) - (hbase := attesterAttestMemDataOffset_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites]) - -theorem attesterAttestSourceMem_read384 (I : ExecutionEnv) : - (attesterAttestSourceMem I).readWithPadding 384 32 = UInt256.toByteArray ⟨32⟩ := by - change (writeCascade (attesterAttestMemInputWord I) - [(384, (⟨32⟩ : UInt256)), (64, (⟨448⟩ : UInt256)), - (320, (⟨384⟩ : UInt256)), (352, (⟨0⟩ : UInt256)), - (160, (⟨192⟩ : UInt256))]).readWithPadding 384 32 = UInt256.toByteArray ⟨32⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestMemInputWord I) - (word := (⟨32⟩ : UInt256)) - (rest := [(64, (⟨448⟩ : UInt256)), (320, (⟨384⟩ : UInt256)), - (352, (⟨0⟩ : UInt256)), (160, (⟨192⟩ : UInt256))]) - (hbase := attesterAttestMemInputWord_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites]) - -theorem attesterAttestSourceMem_read416 (I : ExecutionEnv) : - (attesterAttestSourceMem I).readWithPadding 416 32 = - UInt256.toByteArray (attesterAttestInputWord I) := by - change (writeCascade (attesterAttestMemRefUID I) - [(416, attesterAttestInputWord I), (384, (⟨32⟩ : UInt256)), - (64, (⟨448⟩ : UInt256)), (320, (⟨384⟩ : UInt256)), - (352, (⟨0⟩ : UInt256)), (160, (⟨192⟩ : UInt256))]).readWithPadding - 416 32 = UInt256.toByteArray (attesterAttestInputWord I) - exact writeCascade_read_word_of_head_of_base (attesterAttestMemRefUID I) - (word := attesterAttestInputWord I) - (rest := [(384, (⟨32⟩ : UInt256)), (64, (⟨448⟩ : UInt256)), - (320, (⟨384⟩ : UInt256)), (352, (⟨0⟩ : UInt256)), (160, (⟨192⟩ : UInt256))]) - (hbase := attesterAttestMemRefUID_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites]) - -theorem attesterAttestCallMemSelector_size (I : ExecutionEnv) : - (attesterAttestCallMemSelector I).size = 480 := by - unfold attesterAttestCallMemSelector - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestSourceMem_size] - exact lt_usize _ (by norm_num)), - attesterAttestSourceMem_size] - norm_num - -theorem attesterAttestCallMemArgOffset_size (I : ExecutionEnv) : - (attesterAttestCallMemArgOffset I).size = 484 := by - unfold attesterAttestCallMemArgOffset - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestCallMemSelector_size] - exact lt_usize _ (by norm_num)), - attesterAttestCallMemSelector_size] - norm_num - -theorem attesterAttestCallMemSchema_size (I : ExecutionEnv) : - (attesterAttestCallMemSchema I).size = 516 := by - unfold attesterAttestCallMemSchema - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestCallMemArgOffset_size] - exact lt_usize _ (by norm_num)), - attesterAttestCallMemArgOffset_size] - norm_num - -theorem attesterAttestCallMemDataOffset_size (I : ExecutionEnv) : - (attesterAttestCallMemDataOffset I).size = 548 := by - unfold attesterAttestCallMemDataOffset - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestCallMemSchema_size] - exact lt_usize _ (by norm_num)), - attesterAttestCallMemSchema_size] - norm_num - -theorem attesterAttestCallMemRecipient_size (I : ExecutionEnv) : - (attesterAttestCallMemRecipient I).size = 580 := by - unfold attesterAttestCallMemRecipient - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestCallMemDataOffset_size] - exact lt_usize _ (by norm_num)), - attesterAttestCallMemDataOffset_size] - norm_num - -theorem attesterAttestCallMemExpiration_size (I : ExecutionEnv) : - (attesterAttestCallMemExpiration I).size = 612 := by - unfold attesterAttestCallMemExpiration - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestCallMemRecipient_size] - exact lt_usize _ (by norm_num)), - attesterAttestCallMemRecipient_size] - norm_num - -theorem attesterAttestCallMemRevocable_size (I : ExecutionEnv) : - (attesterAttestCallMemRevocable I).size = 644 := by - unfold attesterAttestCallMemRevocable - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestCallMemExpiration_size] - exact lt_usize _ (by norm_num)), - attesterAttestCallMemExpiration_size] - norm_num - -theorem attesterAttestCallMemRefUID_size (I : ExecutionEnv) : - (attesterAttestCallMemRefUID I).size = 676 := by - unfold attesterAttestCallMemRefUID - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestCallMemRevocable_size] - exact lt_usize _ (by norm_num)), - attesterAttestCallMemRevocable_size] - norm_num - -theorem attesterAttestCallMemBytesOffset_size (I : ExecutionEnv) : - (attesterAttestCallMemBytesOffset I).size = 708 := by - unfold attesterAttestCallMemBytesOffset - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestCallMemRefUID_size] - exact lt_usize _ (by norm_num)), - attesterAttestCallMemRefUID_size] - norm_num - -theorem attesterAttestCallMemBytesLen_size (I : ExecutionEnv) : - (attesterAttestCallMemBytesLen I).size = 772 := by - unfold attesterAttestCallMemBytesLen - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestCallMemBytesOffset_size] - exact lt_usize _ (by norm_num)), - attesterAttestCallMemBytesOffset_size] - norm_num - -theorem attesterAttestCallMemBytesData_size (I : ExecutionEnv) : - (attesterAttestCallMemBytesData I).size = 804 := by - unfold attesterAttestCallMemBytesData - rw [show (772 : Nat) = (attesterAttestCallMemBytesLen I).size by - rw [attesterAttestCallMemBytesLen_size]] - rw [write_end_size_from (attesterAttestCallMemBytesLen I) - (attesterAttestCallMemBytesLen I) 416 32 (by norm_num) - (by rw [attesterAttestCallMemBytesLen_size]; norm_num)] - rw [attesterAttestCallMemBytesLen_size] - -theorem attesterAttestCallMemPad_size (I : ExecutionEnv) : - (attesterAttestCallMemPad I).size = 836 := by - unfold attesterAttestCallMemPad - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestCallMemBytesData_size] - exact lt_usize _ (by norm_num)), - attesterAttestCallMemBytesData_size] - norm_num - -theorem attesterAttestCallMemValue_size (I : ExecutionEnv) : - (attesterAttestCallMemValue I).size = 836 := by - unfold attesterAttestCallMemValue - rw [attesterWriteWord_size_eq_max _ _ _ (by - rw [attesterAttestCallMemPad_size] - exact lt_usize _ (by norm_num)), - attesterAttestCallMemPad_size] - norm_num - -theorem attesterAttestCallMem_size (I : ExecutionEnv) : - (attesterAttestCallMem I).size = 836 := by - unfold attesterAttestCallMem - exact attesterAttestCallMemValue_size I - -theorem attesterAttestCallMemSelector_read64 (I : ExecutionEnv) : - (attesterAttestCallMemSelector I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMemSelector - rw [attesterWriteWord_read_below_len _ 448 _ 64 32 - (by rw [attesterAttestSourceMem_size]; norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestSourceMem_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestSourceMem_read64 I - -theorem attesterAttestCallMemArgOffset_read64 (I : ExecutionEnv) : - (attesterAttestCallMemArgOffset I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMemArgOffset - rw [attesterWriteWord_read_below_len _ 452 _ 64 32 - (by rw [attesterAttestCallMemSelector_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemSelector_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemSelector_read64 I - -theorem attesterAttestCallMemSelector_read128 (I : ExecutionEnv) : - (attesterAttestCallMemSelector I).readWithPadding 128 32 = - UInt256.toByteArray (attesterAttestSchemaWord I) := by - unfold attesterAttestCallMemSelector - rw [attesterWriteWord_read_below_len _ 448 _ 128 32 - (by rw [attesterAttestSourceMem_size]; norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestSourceMem_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestSourceMem_read128 I - -theorem attesterAttestCallMemArgOffset_read128 (I : ExecutionEnv) : - (attesterAttestCallMemArgOffset I).readWithPadding 128 32 = - UInt256.toByteArray (attesterAttestSchemaWord I) := by - unfold attesterAttestCallMemArgOffset - rw [attesterWriteWord_read_below_len _ 452 _ 128 32 - (by rw [attesterAttestCallMemSelector_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemSelector_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemSelector_read128 I - -theorem attesterAttestCallMemSelector_read160 (I : ExecutionEnv) : - (attesterAttestCallMemSelector I).readWithPadding 160 32 = UInt256.toByteArray ⟨192⟩ := by - unfold attesterAttestCallMemSelector - rw [attesterWriteWord_read_below_len _ 448 _ 160 32 - (by rw [attesterAttestSourceMem_size]; norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestSourceMem_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestSourceMem_read160 I - -theorem attesterAttestCallMemArgOffset_read160 (I : ExecutionEnv) : - (attesterAttestCallMemArgOffset I).readWithPadding 160 32 = UInt256.toByteArray ⟨192⟩ := by - unfold attesterAttestCallMemArgOffset - rw [attesterWriteWord_read_below_len _ 452 _ 160 32 - (by rw [attesterAttestCallMemSelector_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemSelector_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemSelector_read160 I - -theorem attesterAttestCallMemSelector_read320 (I : ExecutionEnv) : - (attesterAttestCallMemSelector I).readWithPadding 320 32 = UInt256.toByteArray ⟨384⟩ := by - unfold attesterAttestCallMemSelector - rw [attesterWriteWord_read_below_len _ 448 _ 320 32 - (by rw [attesterAttestSourceMem_size]; norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestSourceMem_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestSourceMem_read320 I - -theorem attesterAttestCallMemArgOffset_read320 (I : ExecutionEnv) : - (attesterAttestCallMemArgOffset I).readWithPadding 320 32 = UInt256.toByteArray ⟨384⟩ := by - unfold attesterAttestCallMemArgOffset - rw [attesterWriteWord_read_below_len _ 452 _ 320 32 - (by rw [attesterAttestCallMemSelector_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemSelector_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemSelector_read320 I - -theorem attesterAttestCallMemSchema_read64 (I : ExecutionEnv) : - (attesterAttestCallMemSchema I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMemSchema - rw [attesterWriteWord_read_below_len _ 484 _ 64 32 - (by rw [attesterAttestCallMemArgOffset_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemArgOffset_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemArgOffset_read64 I - -theorem attesterAttestCallMemSchema_read160 (I : ExecutionEnv) : - (attesterAttestCallMemSchema I).readWithPadding 160 32 = UInt256.toByteArray ⟨192⟩ := by - unfold attesterAttestCallMemSchema - rw [attesterWriteWord_read_below_len _ 484 _ 160 32 - (by rw [attesterAttestCallMemArgOffset_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemArgOffset_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemArgOffset_read160 I - -theorem attesterAttestCallMemSchema_read320 (I : ExecutionEnv) : - (attesterAttestCallMemSchema I).readWithPadding 320 32 = UInt256.toByteArray ⟨384⟩ := by - unfold attesterAttestCallMemSchema - rw [attesterWriteWord_read_below_len _ 484 _ 320 32 - (by rw [attesterAttestCallMemArgOffset_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemArgOffset_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemArgOffset_read320 I - -theorem attesterAttestCallMemDataOffset_read64 (I : ExecutionEnv) : - (attesterAttestCallMemDataOffset I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMemDataOffset - rw [attesterWriteWord_read_below_len _ 516 _ 64 32 - (by rw [attesterAttestCallMemSchema_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemSchema_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemSchema_read64 I - -private theorem attesterAttestCallMemDataOffset_read_source (I : ExecutionEnv) - {read : Nat} {w : UInt256} (hbelow : read + 32 ≤ 448) - (hsrc : (attesterAttestSourceMem I).readWithPadding read 32 = UInt256.toByteArray w) : - (attesterAttestCallMemDataOffset I).readWithPadding read 32 = UInt256.toByteArray w := by - unfold attesterAttestCallMemDataOffset - rw [attesterWriteWord_read_below_len _ 516 _ read 32 - (by rw [attesterAttestCallMemSchema_size]; omega) (by omega) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemSchema_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemSchema - rw [attesterWriteWord_read_below_len _ 484 _ read 32 - (by rw [attesterAttestCallMemArgOffset_size]; omega) (by omega) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemArgOffset_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemArgOffset - rw [attesterWriteWord_read_below_len _ 452 _ read 32 - (by rw [attesterAttestCallMemSelector_size]; omega) (by omega) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemSelector_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemSelector - rw [attesterWriteWord_read_below_len _ 448 _ read 32 - (by rw [attesterAttestSourceMem_size]; omega) (by omega) (by norm_num) - (by norm_num) - (by rw [attesterAttestSourceMem_size]; exact lt_usize _ (by norm_num))] - exact hsrc - -theorem attesterAttestCallMemDataOffset_read192 (I : ExecutionEnv) : - (attesterAttestCallMemDataOffset I).readWithPadding 192 32 = UInt256.toByteArray ⟨0⟩ := by - exact attesterAttestCallMemDataOffset_read_source I (by norm_num) - (attesterAttestSourceMem_read192 I) - -theorem attesterAttestCallMemDataOffset_read224 (I : ExecutionEnv) : - (attesterAttestCallMemDataOffset I).readWithPadding 224 32 = UInt256.toByteArray ⟨0⟩ := by - exact attesterAttestCallMemDataOffset_read_source I (by norm_num) - (attesterAttestSourceMem_read224 I) - -theorem attesterAttestCallMemDataOffset_read256 (I : ExecutionEnv) : - (attesterAttestCallMemDataOffset I).readWithPadding 256 32 = UInt256.toByteArray ⟨1⟩ := by - exact attesterAttestCallMemDataOffset_read_source I (by norm_num) - (attesterAttestSourceMem_read256 I) - -theorem attesterAttestCallMemDataOffset_read288 (I : ExecutionEnv) : - (attesterAttestCallMemDataOffset I).readWithPadding 288 32 = UInt256.toByteArray ⟨0⟩ := by - exact attesterAttestCallMemDataOffset_read_source I (by norm_num) - (attesterAttestSourceMem_read288 I) - -theorem attesterAttestCallMemDataOffset_read320 (I : ExecutionEnv) : - (attesterAttestCallMemDataOffset I).readWithPadding 320 32 = UInt256.toByteArray ⟨384⟩ := by - exact attesterAttestCallMemDataOffset_read_source I (by norm_num) - (attesterAttestSourceMem_read320 I) - -theorem attesterAttestCallMemDataOffset_read352 (I : ExecutionEnv) : - (attesterAttestCallMemDataOffset I).readWithPadding 352 32 = UInt256.toByteArray ⟨0⟩ := by - exact attesterAttestCallMemDataOffset_read_source I (by norm_num) - (attesterAttestSourceMem_read352 I) - -theorem attesterAttestCallMemDataOffset_read384 (I : ExecutionEnv) : - (attesterAttestCallMemDataOffset I).readWithPadding 384 32 = UInt256.toByteArray ⟨32⟩ := by - exact attesterAttestCallMemDataOffset_read_source I (by norm_num) - (attesterAttestSourceMem_read384 I) - -theorem attesterAttestCallMemRecipient_read224 (I : ExecutionEnv) : - (attesterAttestCallMemRecipient I).readWithPadding 224 32 = UInt256.toByteArray ⟨0⟩ := by - unfold attesterAttestCallMemRecipient - rw [attesterWriteWord_read_below_len _ 548 _ 224 32 - (by rw [attesterAttestCallMemDataOffset_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemDataOffset_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemDataOffset_read224 I - -theorem attesterAttestCallMemExpiration_read256 (I : ExecutionEnv) : - (attesterAttestCallMemExpiration I).readWithPadding 256 32 = UInt256.toByteArray ⟨1⟩ := by - unfold attesterAttestCallMemExpiration - rw [attesterWriteWord_read_below_len _ 580 _ 256 32 - (by rw [attesterAttestCallMemRecipient_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemRecipient_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemRecipient - rw [attesterWriteWord_read_below_len _ 548 _ 256 32 - (by rw [attesterAttestCallMemDataOffset_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemDataOffset_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemDataOffset_read256 I - -theorem attesterAttestCallMemRevocable_read288 (I : ExecutionEnv) : - (attesterAttestCallMemRevocable I).readWithPadding 288 32 = UInt256.toByteArray ⟨0⟩ := by - unfold attesterAttestCallMemRevocable - rw [attesterWriteWord_read_below_len _ 612 _ 288 32 - (by rw [attesterAttestCallMemExpiration_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemExpiration_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemExpiration - rw [attesterWriteWord_read_below_len _ 580 _ 288 32 - (by rw [attesterAttestCallMemRecipient_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemRecipient_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemRecipient - rw [attesterWriteWord_read_below_len _ 548 _ 288 32 - (by rw [attesterAttestCallMemDataOffset_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemDataOffset_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemDataOffset_read288 I - -theorem attesterAttestCallMemRefUID_read320 (I : ExecutionEnv) : - (attesterAttestCallMemRefUID I).readWithPadding 320 32 = UInt256.toByteArray ⟨384⟩ := by - unfold attesterAttestCallMemRefUID - rw [attesterWriteWord_read_below_len _ 644 _ 320 32 - (by rw [attesterAttestCallMemRevocable_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemRevocable_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemRevocable - rw [attesterWriteWord_read_below_len _ 612 _ 320 32 - (by rw [attesterAttestCallMemExpiration_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemExpiration_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemExpiration - rw [attesterWriteWord_read_below_len _ 580 _ 320 32 - (by rw [attesterAttestCallMemRecipient_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemRecipient_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemRecipient - rw [attesterWriteWord_read_below_len _ 548 _ 320 32 - (by rw [attesterAttestCallMemDataOffset_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemDataOffset_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemDataOffset_read320 I - -theorem attesterAttestCallMemBytesOffset_read384 (I : ExecutionEnv) : - (attesterAttestCallMemBytesOffset I).readWithPadding 384 32 = UInt256.toByteArray ⟨32⟩ := by - unfold attesterAttestCallMemBytesOffset - rw [attesterWriteWord_read_below_len _ 676 _ 384 32 - (by rw [attesterAttestCallMemRefUID_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemRefUID_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemRefUID - rw [attesterWriteWord_read_below_len _ 644 _ 384 32 - (by rw [attesterAttestCallMemRevocable_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemRevocable_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemRevocable - rw [attesterWriteWord_read_below_len _ 612 _ 384 32 - (by rw [attesterAttestCallMemExpiration_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemExpiration_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemExpiration - rw [attesterWriteWord_read_below_len _ 580 _ 384 32 - (by rw [attesterAttestCallMemRecipient_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemRecipient_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemRecipient - rw [attesterWriteWord_read_below_len _ 548 _ 384 32 - (by rw [attesterAttestCallMemDataOffset_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemDataOffset_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemDataOffset_read384 I - -theorem attesterAttestCallMemPad_read352 (I : ExecutionEnv) : - (attesterAttestCallMemPad I).readWithPadding 352 32 = UInt256.toByteArray ⟨0⟩ := by - unfold attesterAttestCallMemPad - rw [attesterWriteWord_read_below_len _ 804 _ 352 32 - (by rw [attesterAttestCallMemBytesData_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemBytesData_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemBytesData - rw [show (772 : Nat) = (attesterAttestCallMemBytesLen I).size by - rw [attesterAttestCallMemBytesLen_size]] - rw [write_read_below_end_from (attesterAttestCallMemBytesLen I) - (attesterAttestCallMemBytesLen I) 416 32 352 (by norm_num) - (by rw [attesterAttestCallMemBytesLen_size]; norm_num) - (by rw [attesterAttestCallMemBytesLen_size]; norm_num)] - unfold attesterAttestCallMemBytesLen - rw [attesterWriteWord_read_below_len _ 740 _ 352 32 - (by rw [attesterAttestCallMemBytesOffset_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemBytesOffset_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemBytesOffset - rw [attesterWriteWord_read_below_len _ 676 _ 352 32 - (by rw [attesterAttestCallMemRefUID_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemRefUID_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemRefUID - rw [attesterWriteWord_read_below_len _ 644 _ 352 32 - (by rw [attesterAttestCallMemRevocable_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemRevocable_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemRevocable - rw [attesterWriteWord_read_below_len _ 612 _ 352 32 - (by rw [attesterAttestCallMemExpiration_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemExpiration_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemExpiration - rw [attesterWriteWord_read_below_len _ 580 _ 352 32 - (by rw [attesterAttestCallMemRecipient_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemRecipient_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemRecipient - rw [attesterWriteWord_read_below_len _ 548 _ 352 32 - (by rw [attesterAttestCallMemDataOffset_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemDataOffset_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemDataOffset_read352 I - -theorem attesterAttestCallMemRecipient_read64 (I : ExecutionEnv) : - (attesterAttestCallMemRecipient I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMemRecipient - rw [attesterWriteWord_read_below_len _ 548 _ 64 32 - (by rw [attesterAttestCallMemDataOffset_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemDataOffset_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemDataOffset_read64 I - -theorem attesterAttestCallMemExpiration_read64 (I : ExecutionEnv) : - (attesterAttestCallMemExpiration I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMemExpiration - rw [attesterWriteWord_read_below_len _ 580 _ 64 32 - (by rw [attesterAttestCallMemRecipient_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemRecipient_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemRecipient_read64 I - -theorem attesterAttestCallMemRevocable_read64 (I : ExecutionEnv) : - (attesterAttestCallMemRevocable I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMemRevocable - rw [attesterWriteWord_read_below_len _ 612 _ 64 32 - (by rw [attesterAttestCallMemExpiration_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemExpiration_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemExpiration_read64 I - -theorem attesterAttestCallMemRefUID_read64 (I : ExecutionEnv) : - (attesterAttestCallMemRefUID I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMemRefUID - rw [attesterWriteWord_read_below_len _ 644 _ 64 32 - (by rw [attesterAttestCallMemRevocable_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemRevocable_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemRevocable_read64 I - -theorem attesterAttestCallMemBytesOffset_read64 (I : ExecutionEnv) : - (attesterAttestCallMemBytesOffset I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMemBytesOffset - rw [attesterWriteWord_read_below_len _ 676 _ 64 32 - (by rw [attesterAttestCallMemRefUID_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemRefUID_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemRefUID_read64 I - -theorem attesterAttestCallMemBytesLen_read64 (I : ExecutionEnv) : - (attesterAttestCallMemBytesLen I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMemBytesLen - rw [attesterWriteWord_read_below_len _ 740 _ 64 32 - (by rw [attesterAttestCallMemBytesOffset_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemBytesOffset_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemBytesOffset_read64 I - -theorem attesterAttestCallMemBytesData_read64 (I : ExecutionEnv) : - (attesterAttestCallMemBytesData I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMemBytesData - rw [show (772 : Nat) = (attesterAttestCallMemBytesLen I).size by - rw [attesterAttestCallMemBytesLen_size]] - rw [write_read_below_end_from (attesterAttestCallMemBytesLen I) - (attesterAttestCallMemBytesLen I) 416 32 64 (by norm_num) - (by rw [attesterAttestCallMemBytesLen_size]; norm_num) - (by rw [attesterAttestCallMemBytesLen_size]; norm_num)] - exact attesterAttestCallMemBytesLen_read64 I - -theorem attesterAttestCallMemPad_read64 (I : ExecutionEnv) : - (attesterAttestCallMemPad I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMemPad - rw [attesterWriteWord_read_below_len _ 804 _ 64 32 - (by rw [attesterAttestCallMemBytesData_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemBytesData_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemBytesData_read64 I - -theorem attesterAttestCallMemValue_read64 (I : ExecutionEnv) : - (attesterAttestCallMemValue I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMemValue - rw [attesterWriteWord_read_below_len _ 708 _ 64 32 - (by rw [attesterAttestCallMemPad_size]; norm_num) (by norm_num) (by norm_num) - (by norm_num) - (by rw [attesterAttestCallMemPad_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemPad_read64 I - -theorem attesterAttestCallMem_read64 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 64 32 = UInt256.toByteArray ⟨448⟩ := by - unfold attesterAttestCallMem - exact attesterAttestCallMemValue_read64 I - -theorem attesterAttestMin32_toNat_of_ge {n : ℕ} - (h32 : 32 ≤ n) (hsize : n < UInt256.size) : - (min (⟨32⟩ : UInt256) (UInt256.ofNat n)).toNat = 32 := - umin_ofNat_right_toNat_of_ge (c := 32) (n := n) (by norm_num [UInt256.size]) h32 hsize - -theorem attesterAttestMin32_toNat_of_lt {n : ℕ} - (h : n < 32) : - (min (⟨32⟩ : UInt256) (UInt256.ofNat n)).toNat = n := by - have hsize : n < UInt256.size := by - have h32 : 32 < UInt256.size := by norm_num [UInt256.size] - omega - exact umin_ofNat_right_toNat_of_lt (c := 32) (n := n) - (by norm_num [UInt256.size]) h hsize - -theorem attesterAttestReturnWrite_size (I : ExecutionEnv) (o : ByteArray) - (ho32 : 32 ≤ o.size) : - (o.write 0 (attesterAttestCallMem I) 448 32).size = 836 := by - rw [write_eq_gen o (attesterAttestCallMem I) 448 32 (by norm_num) ho32 - (by rw [attesterAttestCallMem_size]; norm_num)] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, attesterAttestCallMem_size] - omega - -theorem attesterAttestReturnWrite_read64 (I : ExecutionEnv) (o : ByteArray) - (ho32 : 32 ≤ o.size) : - (o.write 0 (attesterAttestCallMem I) 448 32).readWithPadding 64 32 = - UInt256.toByteArray ⟨448⟩ := by - rw [write_read_below_gen o (attesterAttestCallMem I) 448 32 64 - (by norm_num) ho32 (by rw [attesterAttestCallMem_size]; norm_num) (by norm_num)] - exact attesterAttestCallMem_read64 I - -theorem attesterAttestReturnWrite_read64_of_len (I : ExecutionEnv) (o : ByteArray) - {len : ℕ} (hlenSrc : len ≤ o.size) (hlenMax : len ≤ 32) : - (o.write 0 (attesterAttestCallMem I) 448 len).readWithPadding 64 32 = - UInt256.toByteArray ⟨448⟩ := by - by_cases hlen : len = 0 - · subst len - rw [byteArray_write_len_zero] - exact attesterAttestCallMem_read64 I - · rw [write_read_below_gen o (attesterAttestCallMem I) 448 len 64 - hlen hlenSrc (by rw [attesterAttestCallMem_size]; omega) (by norm_num)] - exact attesterAttestCallMem_read64 I - -theorem attesterAttestReturnWrite_size_of_len (I : ExecutionEnv) (o : ByteArray) - {len : ℕ} (hlenSrc : len ≤ o.size) (hlenMax : len ≤ 32) : - (o.write 0 (attesterAttestCallMem I) 448 len).size = 836 := by - by_cases hlen : len = 0 - · subst len - rw [byteArray_write_len_zero, attesterAttestCallMem_size] - · rw [write_eq_gen o (attesterAttestCallMem I) 448 len hlen hlenSrc - (by rw [attesterAttestCallMem_size]; omega)] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, attesterAttestCallMem_size] - omega - -theorem attesterAttestReturnWrite_mload64_of_len (I : ExecutionEnv) (o : ByteArray) - {len : ℕ} (hlenSrc : len ≤ o.size) (hlenMax : len ≤ 32) : - (if (⟨64⟩ : UInt256).toNat ≥ (o.write 0 (attesterAttestCallMem I) 448 len).size ∨ - (⟨64⟩ : UInt256) ≥ ⟨27⟩ * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((o.write 0 (attesterAttestCallMem I) 448 len).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨448⟩ := by - exact mloadWordValue_of_readWithPadding - (by rw [attesterAttestReturnWrite_size_of_len I o hlenSrc hlenMax]; decide) - (by decide) - (by simpa using attesterAttestReturnWrite_read64_of_len I o hlenSrc hlenMax) - -theorem attesterAttestReturnWrite_read448_word (I : ExecutionEnv) (o : ByteArray) - (ho32 : 32 ≤ o.size) : - (o.write 0 (attesterAttestCallMem I) 448 32).readWithPadding 448 32 = - UInt256.toByteArray (uInt256OfByteArray (o.extract 0 32)) := by - rw [write32_read_back o (attesterAttestCallMem I) 448 ho32 - (by rw [attesterAttestCallMem_size]; norm_num)] - exact (toByteArray_uInt256OfByteArray_of_size - (by rw [ByteArray.size_extract]; omega)).symm - -def attesterAttestReturnDecodeFreePtr (o : ByteArray) : UInt256 := - UInt256.add ⟨448⟩ - (UInt256.land (UInt256.add (UInt256.ofNat o.size) ⟨31⟩) (UInt256.lnot ⟨31⟩)) - -noncomputable def attesterAttestReturnDecodeMem (I : ExecutionEnv) (o : ByteArray) : ByteArray := - (UInt256.toByteArray (attesterAttestReturnDecodeFreePtr o)).write 0 - (o.write 0 (attesterAttestCallMem I) 448 32) 64 32 - -theorem attesterAttestReturnDecodeMem_size (I : ExecutionEnv) (o : ByteArray) - (ho32 : 32 ≤ o.size) : - (attesterAttestReturnDecodeMem I o).size = 836 := by - unfold attesterAttestReturnDecodeMem - rw [write32_eq _ _ 64 (by rw [toByteArray_size]) - (by rw [attesterAttestReturnWrite_size I o ho32]; norm_num)] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, toByteArray_size, - attesterAttestReturnWrite_size I o ho32] - omega - -theorem attesterAttestReturnDecodeMem_read64 (I : ExecutionEnv) (o : ByteArray) - (ho32 : 32 ≤ o.size) : - (attesterAttestReturnDecodeMem I o).readWithPadding 64 32 = - UInt256.toByteArray (attesterAttestReturnDecodeFreePtr o) := by - unfold attesterAttestReturnDecodeMem - exact toByteArray_write32_read_back _ _ 64 - (by rw [attesterAttestReturnWrite_size I o ho32]; norm_num) - -theorem attesterAttestReturnDecodeMem_read448_word (I : ExecutionEnv) (o : ByteArray) - (ho32 : 32 ≤ o.size) : - (attesterAttestReturnDecodeMem I o).readWithPadding 448 32 = - UInt256.toByteArray (uInt256OfByteArray (o.extract 0 32)) := by - unfold attesterAttestReturnDecodeMem - rw [write32_read_above (UInt256.toByteArray (attesterAttestReturnDecodeFreePtr o)) - (o.write 0 (attesterAttestCallMem I) 448 32) 64 448 - (by rw [toByteArray_size]) - (by rw [attesterAttestReturnWrite_size I o ho32]; norm_num) - (by norm_num) - (by rw [attesterAttestReturnWrite_size I o ho32]; norm_num)] - exact attesterAttestReturnWrite_read448_word I o ho32 - -private theorem attesterAttestReturnDecodeRounded_le (o : ByteArray) - (ho255 : o.size < 2 ^ 255) : - (UInt256.land (UInt256.add (UInt256.ofNat o.size) ⟨31⟩) (UInt256.lnot ⟨31⟩)).toNat - ≤ o.size + 31 := by - have hosz : (UInt256.ofNat o.size).toNat = o.size := - ulit_toNat' o.size (lt_size_of_lt_sign ho255) - have hadd : - (UInt256.add (UInt256.ofNat o.size) (⟨31⟩ : UInt256)).toNat = o.size + 31 := by - change (((UInt256.ofNat o.size) + (⟨31⟩ : UInt256)).toNat = o.size + 31) - rw [uadd_toNat, hosz, show (⟨31⟩ : UInt256).toNat = 31 by decide] - rw [Nat.mod_eq_of_lt] - have hcap : 2 ^ 255 + 31 < UInt256.size := by norm_num [UInt256.size] - omega - rw [uland_toNat, hadd] - exact Nat.and_le_left - -theorem attesterAttestReturnDecodeFreePtr_toNat (o : ByteArray) - (ho255 : o.size < 2 ^ 255) : - (attesterAttestReturnDecodeFreePtr o).toNat = - 448 + - (UInt256.land (UInt256.add (UInt256.ofNat o.size) ⟨31⟩) - (UInt256.lnot ⟨31⟩)).toNat := by - unfold attesterAttestReturnDecodeFreePtr - change (((⟨448⟩ : UInt256) + - UInt256.land (UInt256.add (UInt256.ofNat o.size) ⟨31⟩) - (UInt256.lnot ⟨31⟩)).toNat = - 448 + - (UInt256.land (UInt256.add (UInt256.ofNat o.size) ⟨31⟩) - (UInt256.lnot ⟨31⟩)).toNat) - rw [uadd_toNat, show (⟨448⟩ : UInt256).toNat = 448 by decide] - rw [Nat.mod_eq_of_lt] - have hround := attesterAttestReturnDecodeRounded_le o ho255 - have hcap : 448 + (o.size + 31) < UInt256.size := by - have hsign : 2 ^ 255 + 479 < UInt256.size := by norm_num [UInt256.size] - omega - omega - -theorem attesterAttestReturnDecodeFreePtr_ge448 (o : ByteArray) - (ho255 : o.size < 2 ^ 255) : - 448 ≤ (attesterAttestReturnDecodeFreePtr o).toNat := by - rw [attesterAttestReturnDecodeFreePtr_toNat o ho255] - omega - -theorem attesterAttestReturnDecodeFreePtr_add32_lt (o : ByteArray) - (ho255 : o.size < 2 ^ 255) : - (attesterAttestReturnDecodeFreePtr o).toNat + 32 < UInt256.size := by - rw [attesterAttestReturnDecodeFreePtr_toNat o ho255] - have hround := attesterAttestReturnDecodeRounded_le o ho255 - have hcap : 448 + (o.size + 31) + 32 < UInt256.size := by - have hsign : 2 ^ 255 + 511 < UInt256.size := by norm_num [UInt256.size] - omega - omega - -theorem attesterAttestReturnDecodeFreePtr_add63_lt (o : ByteArray) - (ho255 : o.size < 2 ^ 255) : - (attesterAttestReturnDecodeFreePtr o).toNat + 63 < UInt256.size := by - rw [attesterAttestReturnDecodeFreePtr_toNat o ho255] - have hround := attesterAttestReturnDecodeRounded_le o ho255 - have hcap : 448 + (o.size + 31) + 63 < UInt256.size := by - have hsign : 2 ^ 255 + 542 < UInt256.size := by norm_num [UInt256.size] - omega - omega - -theorem attesterAttestReturnDecodeFreePtr_add32_sub (o : ByteArray) - (ho255 : o.size < 2 ^ 255) : - UInt256.sub (UInt256.add ⟨32⟩ (attesterAttestReturnDecodeFreePtr o)) - (attesterAttestReturnDecodeFreePtr o) = ⟨32⟩ := by - let fp := attesterAttestReturnDecodeFreePtr o - have hfit : fp.toNat + 32 < UInt256.size := - attesterAttestReturnDecodeFreePtr_add32_lt o ho255 - apply u256_inj - change (UInt256.sub ((⟨32⟩ : UInt256) + fp) fp).toNat = (⟨32⟩ : UInt256).toNat - rw [usub_toNat] - · rw [uadd_lit32_toNat fp hfit] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - omega - · rw [uadd_lit32_toNat fp hfit] - omega - -theorem solcDecodeEndLenCheckOk_448_32 {len : ℕ} - (hlen : 32 ≤ len) (hhi : len < 2 ^ 255) : - UInt256.slt (UInt256.sub (UInt256.add ⟨448⟩ (UInt256.ofNat len)) ⟨448⟩) ⟨32⟩ = - ⟨0⟩ := by - exact solcReturnStaticLenCheckOk (base := 448) (words := 1) (by simpa using hlen) hhi - (by norm_num [UInt256.size]) - (by - have hcap : 2 ^ 255 + 448 < UInt256.size := by norm_num [UInt256.size] - omega) - -theorem solcDecodeEndLenCheckShort_448_32 {len : ℕ} - (hshort : len < 32) : - UInt256.slt (UInt256.sub (UInt256.add ⟨448⟩ (UInt256.ofNat len)) ⟨448⟩) ⟨32⟩ = - ⟨1⟩ := by - exact solcReturnStaticLenCheckShort (base := 448) (words := 1) (by simpa using hshort) - (by norm_num [UInt256.size]) - (by - have hcap : 448 + 32 < UInt256.size := by norm_num [UInt256.size] - omega) - (by norm_num) - -theorem solcDecodeEndLenCheckHuge_448_32 {len : ℕ} - (hhi : 2 ^ 255 ≤ len) (hlo : len < UInt256.size) : - UInt256.slt (UInt256.sub (UInt256.add ⟨448⟩ (UInt256.ofNat len)) ⟨448⟩) ⟨32⟩ = - ⟨1⟩ := by - exact solcReturnStaticLenCheckHuge (base := 448) (words := 1) hhi hlo - (by norm_num [UInt256.size]) (by norm_num) - -theorem attesterAttestCallMemBytesLen_read448_4 (I : ExecutionEnv) : - (attesterAttestCallMemBytesLen I).readWithPadding 448 4 = attestSelector := by - change (writeCascade (attesterAttestSourceMem I) - [(448, attesterAttestSelectorWord), (452, (⟨32⟩ : UInt256)), - (484, attesterAttestSchemaWord I), (516, (⟨64⟩ : UInt256)), - (548, (⟨0⟩ : UInt256)), (580, (⟨0⟩ : UInt256)), - (612, (⟨1⟩ : UInt256)), (644, (⟨0⟩ : UInt256)), - (676, (⟨192⟩ : UInt256)), (740, (⟨32⟩ : UInt256))]).readWithPadding - 448 4 = attestSelector - rw [writeCascade_read_window_of_head (attesterAttestSourceMem I) 448 0 4 - attesterAttestSelectorWord - [(452, (⟨32⟩ : UInt256)), (484, attesterAttestSchemaWord I), - (516, (⟨64⟩ : UInt256)), (548, (⟨0⟩ : UInt256)), - (580, (⟨0⟩ : UInt256)), (612, (⟨1⟩ : UInt256)), - (644, (⟨0⟩ : UInt256)), (676, (⟨192⟩ : UInt256)), - (740, (⟨32⟩ : UInt256))] - (by rw [attesterAttestSourceMem_size]; native_decide) - (by - rw [attesterAttestSourceMem_size] - simp [WindowDisjointFromWrites] - native_decide) - (by norm_num) (by norm_num) (by norm_num)] - unfold attesterAttestSelectorWord attestSelector selectorBytes - native_decide - -theorem attesterAttestCallMemBytesLen_read416 (I : ExecutionEnv) : - (attesterAttestCallMemBytesLen I).readWithPadding 416 32 = - UInt256.toByteArray (attesterAttestInputWord I) := by - change (writeCascade (attesterAttestSourceMem I) - [(448, attesterAttestSelectorWord), (452, (⟨32⟩ : UInt256)), - (484, attesterAttestSchemaWord I), (516, (⟨64⟩ : UInt256)), - (548, (⟨0⟩ : UInt256)), (580, (⟨0⟩ : UInt256)), - (612, (⟨1⟩ : UInt256)), (644, (⟨0⟩ : UInt256)), - (676, (⟨192⟩ : UInt256)), (740, (⟨32⟩ : UInt256))]).readWithPadding - 416 32 = UInt256.toByteArray (attesterAttestInputWord I) - rw [writeCascade_read_preserved_of_base (attesterAttestSourceMem I) - [(448, attesterAttestSelectorWord), (452, (⟨32⟩ : UInt256)), - (484, attesterAttestSchemaWord I), (516, (⟨64⟩ : UInt256)), - (548, (⟨0⟩ : UInt256)), (580, (⟨0⟩ : UInt256)), - (612, (⟨1⟩ : UInt256)), (644, (⟨0⟩ : UInt256)), - (676, (⟨192⟩ : UInt256)), (740, (⟨32⟩ : UInt256))] - (hbase := attesterAttestSourceMem_size I) - (hwin := by - simp [WindowDisjointFromWrites] - native_decide)] - exact attesterAttestSourceMem_read416 I - -theorem attesterAttestCallMemBytesLen_read452 (I : ExecutionEnv) : - (attesterAttestCallMemBytesLen I).readWithPadding 452 32 = - UInt256.toByteArray ⟨32⟩ := by - change (writeCascade (attesterAttestCallMemSelector I) - [(452, (⟨32⟩ : UInt256)), (484, attesterAttestSchemaWord I), - (516, (⟨64⟩ : UInt256)), (548, (⟨0⟩ : UInt256)), - (580, (⟨0⟩ : UInt256)), (612, (⟨1⟩ : UInt256)), - (644, (⟨0⟩ : UInt256)), (676, (⟨192⟩ : UInt256)), - (740, (⟨32⟩ : UInt256))]).readWithPadding 452 32 = UInt256.toByteArray ⟨32⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestCallMemSelector I) - (word := (⟨32⟩ : UInt256)) - (rest := [(484, attesterAttestSchemaWord I), (516, (⟨64⟩ : UInt256)), - (548, (⟨0⟩ : UInt256)), (580, (⟨0⟩ : UInt256)), - (612, (⟨1⟩ : UInt256)), (644, (⟨0⟩ : UInt256)), - (676, (⟨192⟩ : UInt256)), (740, (⟨32⟩ : UInt256))]) - (hbase := attesterAttestCallMemSelector_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites] - native_decide) - -theorem attesterAttestCallMemBytesLen_read484 (I : ExecutionEnv) : - (attesterAttestCallMemBytesLen I).readWithPadding 484 32 = - UInt256.toByteArray (attesterAttestSchemaWord I) := by - change (writeCascade (attesterAttestCallMemArgOffset I) - [(484, attesterAttestSchemaWord I), (516, (⟨64⟩ : UInt256)), - (548, (⟨0⟩ : UInt256)), (580, (⟨0⟩ : UInt256)), - (612, (⟨1⟩ : UInt256)), (644, (⟨0⟩ : UInt256)), - (676, (⟨192⟩ : UInt256)), (740, (⟨32⟩ : UInt256))]).readWithPadding - 484 32 = UInt256.toByteArray (attesterAttestSchemaWord I) - exact writeCascade_read_word_of_head_of_base (attesterAttestCallMemArgOffset I) - (word := attesterAttestSchemaWord I) - (rest := [(516, (⟨64⟩ : UInt256)), (548, (⟨0⟩ : UInt256)), - (580, (⟨0⟩ : UInt256)), (612, (⟨1⟩ : UInt256)), - (644, (⟨0⟩ : UInt256)), (676, (⟨192⟩ : UInt256)), - (740, (⟨32⟩ : UInt256))]) - (hbase := attesterAttestCallMemArgOffset_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites] - native_decide) - -theorem attesterAttestCallMemBytesLen_read516 (I : ExecutionEnv) : - (attesterAttestCallMemBytesLen I).readWithPadding 516 32 = - UInt256.toByteArray ⟨64⟩ := by - change (writeCascade (attesterAttestCallMemSchema I) - [(516, (⟨64⟩ : UInt256)), (548, (⟨0⟩ : UInt256)), - (580, (⟨0⟩ : UInt256)), (612, (⟨1⟩ : UInt256)), - (644, (⟨0⟩ : UInt256)), (676, (⟨192⟩ : UInt256)), - (740, (⟨32⟩ : UInt256))]).readWithPadding 516 32 = UInt256.toByteArray ⟨64⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestCallMemSchema I) - (word := (⟨64⟩ : UInt256)) - (rest := [(548, (⟨0⟩ : UInt256)), (580, (⟨0⟩ : UInt256)), - (612, (⟨1⟩ : UInt256)), (644, (⟨0⟩ : UInt256)), - (676, (⟨192⟩ : UInt256)), (740, (⟨32⟩ : UInt256))]) - (hbase := attesterAttestCallMemSchema_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites] - native_decide) - -theorem attesterAttestCallMemBytesLen_read548 (I : ExecutionEnv) : - (attesterAttestCallMemBytesLen I).readWithPadding 548 32 = - UInt256.toByteArray ⟨0⟩ := by - change (writeCascade (attesterAttestCallMemDataOffset I) - [(548, (⟨0⟩ : UInt256)), (580, (⟨0⟩ : UInt256)), - (612, (⟨1⟩ : UInt256)), (644, (⟨0⟩ : UInt256)), - (676, (⟨192⟩ : UInt256)), (740, (⟨32⟩ : UInt256))]).readWithPadding - 548 32 = UInt256.toByteArray ⟨0⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestCallMemDataOffset I) - (word := (⟨0⟩ : UInt256)) - (rest := [(580, (⟨0⟩ : UInt256)), (612, (⟨1⟩ : UInt256)), - (644, (⟨0⟩ : UInt256)), (676, (⟨192⟩ : UInt256)), - (740, (⟨32⟩ : UInt256))]) - (hbase := attesterAttestCallMemDataOffset_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites] - native_decide) - -theorem attesterAttestCallMemBytesLen_read580 (I : ExecutionEnv) : - (attesterAttestCallMemBytesLen I).readWithPadding 580 32 = - UInt256.toByteArray ⟨0⟩ := by - change (writeCascade (attesterAttestCallMemRecipient I) - [(580, (⟨0⟩ : UInt256)), (612, (⟨1⟩ : UInt256)), - (644, (⟨0⟩ : UInt256)), (676, (⟨192⟩ : UInt256)), - (740, (⟨32⟩ : UInt256))]).readWithPadding 580 32 = UInt256.toByteArray ⟨0⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestCallMemRecipient I) - (word := (⟨0⟩ : UInt256)) - (rest := [(612, (⟨1⟩ : UInt256)), (644, (⟨0⟩ : UInt256)), - (676, (⟨192⟩ : UInt256)), (740, (⟨32⟩ : UInt256))]) - (hbase := attesterAttestCallMemRecipient_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites] - native_decide) - -theorem attesterAttestCallMemBytesLen_read612 (I : ExecutionEnv) : - (attesterAttestCallMemBytesLen I).readWithPadding 612 32 = - UInt256.toByteArray ⟨1⟩ := by - change (writeCascade (attesterAttestCallMemExpiration I) - [(612, (⟨1⟩ : UInt256)), (644, (⟨0⟩ : UInt256)), - (676, (⟨192⟩ : UInt256)), (740, (⟨32⟩ : UInt256))]).readWithPadding - 612 32 = UInt256.toByteArray ⟨1⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestCallMemExpiration I) - (word := (⟨1⟩ : UInt256)) - (rest := [(644, (⟨0⟩ : UInt256)), (676, (⟨192⟩ : UInt256)), - (740, (⟨32⟩ : UInt256))]) - (hbase := attesterAttestCallMemExpiration_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites] - native_decide) - -theorem attesterAttestCallMemBytesLen_read644 (I : ExecutionEnv) : - (attesterAttestCallMemBytesLen I).readWithPadding 644 32 = - UInt256.toByteArray ⟨0⟩ := by - change (writeCascade (attesterAttestCallMemRevocable I) - [(644, (⟨0⟩ : UInt256)), (676, (⟨192⟩ : UInt256)), - (740, (⟨32⟩ : UInt256))]).readWithPadding 644 32 = UInt256.toByteArray ⟨0⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestCallMemRevocable I) - (word := (⟨0⟩ : UInt256)) - (rest := [(676, (⟨192⟩ : UInt256)), (740, (⟨32⟩ : UInt256))]) - (hbase := attesterAttestCallMemRevocable_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites] - native_decide) - -theorem attesterAttestCallMemBytesLen_read676 (I : ExecutionEnv) : - (attesterAttestCallMemBytesLen I).readWithPadding 676 32 = - UInt256.toByteArray ⟨192⟩ := by - change (writeCascade (attesterAttestCallMemRefUID I) - [(676, (⟨192⟩ : UInt256)), (740, (⟨32⟩ : UInt256))]).readWithPadding - 676 32 = UInt256.toByteArray ⟨192⟩ - exact writeCascade_read_word_of_head_of_base (attesterAttestCallMemRefUID I) - (word := (⟨192⟩ : UInt256)) - (rest := [(740, (⟨32⟩ : UInt256))]) - (hbase := attesterAttestCallMemRefUID_size I) (hgap := by native_decide +revert) - (hlater := by - simp [WindowDisjointFromWrites] - native_decide) - -theorem attesterAttestCallMemBytesLen_read740 (I : ExecutionEnv) : - (attesterAttestCallMemBytesLen I).readWithPadding 740 32 = - UInt256.toByteArray ⟨32⟩ := by - unfold attesterAttestCallMemBytesLen - exact attesterWriteWord_read_back _ _ _ (by - rw [attesterAttestCallMemBytesOffset_size] - exact lt_usize _ (by norm_num)) - -private theorem attesterAttestCallMem_read_before_value_len (I : ExecutionEnv) - {read len : Nat} {bytes : ByteArray} - (hbelowValue : read + len ≤ 708) (hpos : 0 < len) (hlen64 : len < 2 ^ 64) - (hpre : (attesterAttestCallMemBytesLen I).readWithPadding read len = bytes) : - (attesterAttestCallMem I).readWithPadding read len = bytes := by - unfold attesterAttestCallMem attesterAttestCallMemValue - rw [attesterWriteWord_read_below_len _ 708 _ read len - (by rw [attesterAttestCallMemPad_size]; omega) hbelowValue hpos hlen64 - (by rw [attesterAttestCallMemPad_size]; exact lt_usize _ (by omega))] - unfold attesterAttestCallMemPad - rw [attesterWriteWord_read_below_len _ 804 _ read len - (by rw [attesterAttestCallMemBytesData_size]; omega) (by omega) hpos hlen64 - (by rw [attesterAttestCallMemBytesData_size]; exact lt_usize _ (by omega))] - unfold attesterAttestCallMemBytesData - rw [show (772 : Nat) = (attesterAttestCallMemBytesLen I).size by - rw [attesterAttestCallMemBytesLen_size]] - rw [write_read_below_end_from_len (attesterAttestCallMemBytesLen I) - (attesterAttestCallMemBytesLen I) 416 32 read len (by norm_num) - (by rw [attesterAttestCallMemBytesLen_size]; norm_num) - (by rw [attesterAttestCallMemBytesLen_size]; omega) - (by rw [attesterAttestCallMemBytesLen_size]; omega) - hpos hlen64] - exact hpre - -theorem attesterAttestCallMem_read448_4 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 448 4 = attestSelector := by - exact attesterAttestCallMem_read_before_value_len I (by norm_num) (by norm_num) - (by norm_num) (attesterAttestCallMemBytesLen_read448_4 I) - -theorem attesterAttestCallMem_read452 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 452 32 = UInt256.toByteArray ⟨32⟩ := by - exact attesterAttestCallMem_read_before_value_len I (by norm_num) (by norm_num) - (by norm_num) (attesterAttestCallMemBytesLen_read452 I) - -theorem attesterAttestCallMem_read484 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 484 32 = - UInt256.toByteArray (attesterAttestSchemaWord I) := by - exact attesterAttestCallMem_read_before_value_len I (by norm_num) (by norm_num) - (by norm_num) (attesterAttestCallMemBytesLen_read484 I) - -theorem attesterAttestCallMem_read516 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 516 32 = UInt256.toByteArray ⟨64⟩ := by - exact attesterAttestCallMem_read_before_value_len I (by norm_num) (by norm_num) - (by norm_num) (attesterAttestCallMemBytesLen_read516 I) - -theorem attesterAttestCallMem_read548 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 548 32 = UInt256.toByteArray ⟨0⟩ := by - exact attesterAttestCallMem_read_before_value_len I (by norm_num) (by norm_num) - (by norm_num) (attesterAttestCallMemBytesLen_read548 I) - -theorem attesterAttestCallMem_read580 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 580 32 = UInt256.toByteArray ⟨0⟩ := by - exact attesterAttestCallMem_read_before_value_len I (by norm_num) (by norm_num) - (by norm_num) (attesterAttestCallMemBytesLen_read580 I) - -theorem attesterAttestCallMem_read612 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 612 32 = UInt256.toByteArray ⟨1⟩ := by - exact attesterAttestCallMem_read_before_value_len I (by norm_num) (by norm_num) - (by norm_num) (attesterAttestCallMemBytesLen_read612 I) - -theorem attesterAttestCallMem_read644 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 644 32 = UInt256.toByteArray ⟨0⟩ := by - exact attesterAttestCallMem_read_before_value_len I (by norm_num) (by norm_num) - (by norm_num) (attesterAttestCallMemBytesLen_read644 I) - -theorem attesterAttestCallMem_read676 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 676 32 = UInt256.toByteArray ⟨192⟩ := by - exact attesterAttestCallMem_read_before_value_len I (by norm_num) (by norm_num) - (by norm_num) (attesterAttestCallMemBytesLen_read676 I) - -theorem attesterAttestCallMem_read708 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 708 32 = UInt256.toByteArray ⟨0⟩ := by - unfold attesterAttestCallMem attesterAttestCallMemValue - exact attesterWriteWord_read_back _ _ _ (by - rw [attesterAttestCallMemPad_size] - exact lt_usize _ (by norm_num)) - -theorem attesterAttestCallMem_read740 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 740 32 = UInt256.toByteArray ⟨32⟩ := by - unfold attesterAttestCallMem attesterAttestCallMemValue - rw [attesterWriteWord_read_above_len _ 708 _ 740 32 - (by rw [attesterAttestCallMemPad_size]; norm_num) (by norm_num) - (by rw [attesterAttestCallMemPad_size]; norm_num) (by norm_num) (by norm_num)] - unfold attesterAttestCallMemPad - rw [attesterWriteWord_read_below_len _ 804 _ 740 32 - (by rw [attesterAttestCallMemBytesData_size]; norm_num) (by norm_num) - (by norm_num) (by norm_num) - (by rw [attesterAttestCallMemBytesData_size]; exact lt_usize _ (by norm_num))] - unfold attesterAttestCallMemBytesData - rw [show (772 : Nat) = (attesterAttestCallMemBytesLen I).size by - rw [attesterAttestCallMemBytesLen_size]] - rw [write_read_below_end_from (attesterAttestCallMemBytesLen I) - (attesterAttestCallMemBytesLen I) 416 32 740 (by norm_num) - (by rw [attesterAttestCallMemBytesLen_size]; norm_num) - (by rw [attesterAttestCallMemBytesLen_size])] - exact attesterAttestCallMemBytesLen_read740 I - -theorem attesterAttestCallMemBytesData_read772 (I : ExecutionEnv) : - (attesterAttestCallMemBytesData I).readWithPadding 772 32 = - UInt256.toByteArray (attesterAttestInputWord I) := by - unfold attesterAttestCallMemBytesData - rw [show (772 : Nat) = (attesterAttestCallMemBytesLen I).size by - rw [attesterAttestCallMemBytesLen_size]] - rw [readWithPadding_eq_extract' _ (attesterAttestCallMemBytesLen I).size 32 - (by norm_num) (by norm_num) (by - rw [write_end_size_from (attesterAttestCallMemBytesLen I) - (attesterAttestCallMemBytesLen I) 416 32 (by norm_num) - (by rw [attesterAttestCallMemBytesLen_size]; norm_num)])] - rw [write_end_extract_tail_from (attesterAttestCallMemBytesLen I) - (attesterAttestCallMemBytesLen I) 416 32 (by norm_num) - (by rw [attesterAttestCallMemBytesLen_size]; norm_num)] - rw [← readWithPadding_eq_extract' (attesterAttestCallMemBytesLen I) 416 32 - (by norm_num) (by norm_num) (by rw [attesterAttestCallMemBytesLen_size]; norm_num)] - exact attesterAttestCallMemBytesLen_read416 I - -theorem attesterAttestCallMem_read772 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 772 32 = - UInt256.toByteArray (attesterAttestInputWord I) := by - unfold attesterAttestCallMem attesterAttestCallMemValue - rw [attesterWriteWord_read_above_len _ 708 _ 772 32 - (by rw [attesterAttestCallMemPad_size]; norm_num) (by norm_num) - (by rw [attesterAttestCallMemPad_size]; norm_num) (by norm_num) (by norm_num)] - unfold attesterAttestCallMemPad - rw [attesterWriteWord_read_below_len _ 804 _ 772 32 - (by rw [attesterAttestCallMemBytesData_size]) (by norm_num) - (by norm_num) (by norm_num) - (by rw [attesterAttestCallMemBytesData_size]; exact lt_usize _ (by norm_num))] - exact attesterAttestCallMemBytesData_read772 I - -theorem attesterAttestCallMem_read448_356 (I : ExecutionEnv) : - (attesterAttestCallMem I).readWithPadding 448 356 = - attesterAttestExternalCalldata I := by - rw [show (356 : Nat) = 4 + 352 by norm_num] - rw [byteArray_readWithPadding_split (attesterAttestCallMem I) 448 4 352 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestCallMem_size]; norm_num)] - rw [attesterAttestCallMem_read448_4] - rw [show (352 : Nat) = 32 + 320 by norm_num] - rw [byteArray_readWithPadding_split (attesterAttestCallMem I) 452 32 320 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestCallMem_size]; norm_num)] - rw [attesterAttestCallMem_read452] - rw [show (320 : Nat) = 32 + 288 by norm_num] - rw [byteArray_readWithPadding_split (attesterAttestCallMem I) 484 32 288 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestCallMem_size]; norm_num)] - rw [attesterAttestCallMem_read484] - rw [show (288 : Nat) = 32 + 256 by norm_num] - rw [byteArray_readWithPadding_split (attesterAttestCallMem I) 516 32 256 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestCallMem_size]; norm_num)] - rw [attesterAttestCallMem_read516] - rw [show (256 : Nat) = 32 + 224 by norm_num] - rw [byteArray_readWithPadding_split (attesterAttestCallMem I) 548 32 224 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestCallMem_size]; norm_num)] - rw [attesterAttestCallMem_read548] - rw [show (224 : Nat) = 32 + 192 by norm_num] - rw [byteArray_readWithPadding_split (attesterAttestCallMem I) 580 32 192 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestCallMem_size]; norm_num)] - rw [attesterAttestCallMem_read580] - rw [show (192 : Nat) = 32 + 160 by norm_num] - rw [byteArray_readWithPadding_split (attesterAttestCallMem I) 612 32 160 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestCallMem_size]; norm_num)] - rw [attesterAttestCallMem_read612] - rw [show (160 : Nat) = 32 + 128 by norm_num] - rw [byteArray_readWithPadding_split (attesterAttestCallMem I) 644 32 128 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestCallMem_size]; norm_num)] - rw [attesterAttestCallMem_read644] - rw [show (128 : Nat) = 32 + 96 by norm_num] - rw [byteArray_readWithPadding_split (attesterAttestCallMem I) 676 32 96 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestCallMem_size]; norm_num)] - rw [attesterAttestCallMem_read676] - rw [show (96 : Nat) = 32 + 64 by norm_num] - rw [byteArray_readWithPadding_split (attesterAttestCallMem I) 708 32 64 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestCallMem_size]; norm_num)] - rw [attesterAttestCallMem_read708] - rw [show (64 : Nat) = 32 + 32 by norm_num] - rw [byteArray_readWithPadding_split (attesterAttestCallMem I) 740 32 32 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterAttestCallMem_size]; norm_num)] - rw [attesterAttestCallMem_read740, attesterAttestCallMem_read772] - unfold attesterAttestExternalCalldata - apply ByteArray.ext - simp [ByteArray.data_append, Array.append_assoc] - -theorem attesterAttestSchemaBytes_eq_toBytesBE {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) : - attesterAttestSchemaBytes I = EVM.Word.toBytesBE (attesterAttestSchemaWord I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have hlen : (attesterAttestSchemaBytes I).length = 32 := by - simp [attesterAttestSchemaBytes, List.length_take, List.length_drop, htlen] - omega - have hword : ABI.bytesToWord (attesterAttestSchemaBytes I) = - attesterAttestSchemaWord I := by - simpa [attesterAttestSchemaBytes, attesterAttestSchemaWord, calldataWord, - show (⟨4⟩ : UInt256).toNat = 4 from by decide] - using decode_word_at_eq I.calldata 4 (by omega) (by norm_num) - rw [← hword] - exact (toBytesBE_bytesToWord_of_length hlen).symm - -theorem attesterEncodeAttest_eq (v : AttesterImmutables) {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) : - (config v).externalABI.encode? "attest" (attesterAttestArgVals I) = - some (attesterAttestExternalCalldata I) := by - have hschema := attesterAttestSchemaBytes_eq_toBytesBE (I := I) hsz68 - have hschemaLen : (EVM.Word.toBytesBE (attesterAttestSchemaWord I)).length = 32 := by - simpa using word_toBytesBE_toByteArray_size (attesterAttestSchemaWord I) - have hinputSize : (UInt256.toByteArray (attesterAttestInputWord I)).size = 32 := - toByteArray_size _ - have hinputListLen : - (UInt256.toByteArray (attesterAttestInputWord I)).toList.length = 32 := by - rw [byteArray_toList_eq, Array.length_toList] - exact hinputSize - have hpow64 : 0 < EVM.twoPow 64 := by norm_num [EVM.twoPow] - have hpow256 : 0 < EVM.twoPow 256 := by norm_num [EVM.twoPow] - have hzeroLen : (EVM.Word.ofNat 0).toBytesBE.length = 32 := by - simpa [list_toByteArray_size] using word_toBytesBE_toByteArray_size (EVM.Word.ofNat 0) - have hword32 : EVM.Word.ofNat 32 = (⟨32⟩ : UInt256) := by native_decide - have hword64 : EVM.Word.ofNat 64 = (⟨64⟩ : UInt256) := by native_decide - have hword192 : EVM.Word.ofNat 192 = (⟨192⟩ : UInt256) := by native_decide - have hwordNat0 : EVM.Word.ofNat 0 = (⟨0⟩ : UInt256) := by native_decide - have hword0 : EVM.word 0 = (⟨0⟩ : UInt256) := rfl - have haddr0Word : EVM.word ↑(AccountAddress.ofNat 0) = (⟨0⟩ : UInt256) := by native_decide - have honeWord : UInt256.ofNat 1 = (⟨1⟩ : UInt256) := UInt256_ofNat_1 - simp [config, attesterExternalABI, ABI.encodeCallWithSelector?, ABI.encodeABIValues?, - ABI.encodeABIValuesFrom?, ABI.encodeABIValue?, ABI.encodeABIWord?, ABI.encodeABIArrayElems?, - ABI.encodeABIStaticArrayElems?, ABI.encodeABIDynamicArrayElemsFrom?, - ABI.abiTupleHeadSize?, ABI.staticABIEncodedSize?, ABI.staticABIEncodedSizeList?, - ABI.isDynamicABIType, ABI.isDynamicABITypeList, - attesterAttestArgVals, attesterAttestRequestValue, attesterAttestDataValue, - attesterAttestExternalCalldata, attestationRequestTy, attestationRequestDataTy, - addr, uint64, uint64Int, boolTy, bytes32, bytes32Width, bytesTy, uint256, uint256Int, - attestSelector, selectorBytes, hschema, hschemaLen, hinputSize, hinputListLen, hpow64, - hpow256, hzeroLen, ABI.natBytes, - ABI.padRightToWord, ABI.paddedSize, ABI.zeroBytes, - word_toBytesBE_toByteArray_eq_toByteArray, list_toByteArray_append] - apply ByteArray.ext - simp [ByteArray.data_append, ByteArray.append_assoc, byteArray_toList_toByteArray, - hword32, hword64, hword192, hwordNat0, hword0, haddr0Word, honeWord] - -@[simp] theorem attesterAbiEncodeUint256Call (w : UInt256) : - attesterExternalABI.encode? "__abi_encode_uint256" [.int (Int.ofNat w.toNat)] = - some (abiEncodeUint256Selector ++ UInt256.toByteArray w) := by - have hword : EVM.word w.toNat = w := by - show UInt256.ofNat w.toNat = w - exact u256_ofNat_toNat w - have hlt : w.toNat < EVM.twoPow 256 := by - change w.val.val < EVM.twoPow 256 - exact w.val.isLt - simp [attesterExternalABI, ABI.encodeCallWithSelector?, ABI.encodeABIValues?, - ABI.encodeABIValuesFrom?, ABI.encodeABIValue?, ABI.encodeABIWord?, - ABI.abiTupleHeadSize?, ABI.staticABIEncodedSize?, ABI.isDynamicABIType, - abiEncodeUint256Selector, selectorBytes, uint256, uint256Int, hword, hlt, - word_toBytesBE_toByteArray_eq_toByteArray] - -@[simp] theorem attesterAbiEncodeUint256Slice (w : UInt256) : - sliceBytes? (abiEncodeUint256Selector ++ UInt256.toByteArray w) 4 36 = - .ok (.bytes (UInt256.toByteArray w)) := by - unfold sliceBytes? - simp [abiEncodeUint256Selector, selectorBytes] - rw [show ({ data := #[0, 0, 0, 0] } : ByteArray).size = 4 by rfl] - simp - rw [extract_append_right'] - · rfl - · rw [show ({ data := #[0, 0, 0, 0] } : ByteArray).size = 4 by rfl, toByteArray_size] - -@[simp] theorem attesterEvalAbiEncodeUint256Input (v : AttesterImmutables) - (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := attesterAttestStore I } evm - (abiEncodeUint256 (.var "input")) = - .ok (.bytes (UInt256.toByteArray (attesterAttestInputWord I))) := by - simp [abiEncodeUint256, evalExpr?, evalExprList?, EvalResult.bind, bind, pure, - EvalResult.ofOption, attesterAttestStore, config] - have hcall : - attesterExternalABI.encode? "__abi_encode_uint256" - [Value.int ↑(attesterAttestInputWord I).toNat] = - some (abiEncodeUint256Selector ++ UInt256.toByteArray (attesterAttestInputWord I)) := by - simpa using attesterAbiEncodeUint256Call (attesterAttestInputWord I) - rw [hcall] - simp [attesterAbiEncodeUint256Slice] - -theorem attesterEvalAttestArgs (v : AttesterImmutables) (evm : EVM.State) - (I : ExecutionEnv) : - evalExprs? (config v) - { contract := contract v, locals := attesterAttestStore I } evm - [attestationRequest (.var "schema") (.var "input")] = - .ok (attesterAttestArgVals I) := by - have habi := attesterEvalAbiEncodeUint256Input v evm I - simp [attesterAttestStore, attesterAttestInputWord] at habi - simp [attesterAttestArgVals, attesterAttestRequestValue, attesterAttestDataValue, - attestationRequest, attestationData, attesterAttestStore, - attesterAttestInputWord, evalExprs?, evalExprList?, evalExpr?, EvalResult.bind, - bind, pure, EvalResult.ofOption, castValue?, zeroAddr, zeroBytes32, addrSt, bytes32St, - selectorBytes, abiEncodeUint256Selector, uint256, uint256Int, habi, - Std.HashMap.getElem_insert] - -theorem attesterDecodeABIValues_bytes32_uint256_ok {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) - (hlen32 : ((bytes.drop 32).take 32).length = 32) : - decodeABIValues? [bytes32, uint256] bytes 0 0 64 64 = - some ([.fixedBytes bytes32Width (bytes.take 32), - .int (Int.ofNat (ABI.bytesToWord ((bytes.drop 32).take 32)).toNat)], 64) := by - simp [decodeABIValues?, bytes32, bytes32Width, uint256, uint256Int, isDynamicABIType, - staticABIEncodedSize?, decodeABIValue?, readBytes?, zeroPadding?, hlen0] - simp [readWord?, readBytes?, decodeABIWord?, hlen32] - rw [if_pos] - · simp [UInt256.toNat] - · exact (ABI.bytesToWord ((bytes.drop 32).take 32)).val.isLt - -theorem attesterDecodeABIValues_bytes32_uint256_none_short {bytes : List UInt8} - (hshort : bytes.length < 64) : - decodeABIValues? [bytes32, uint256] bytes 0 0 64 64 = none := by - simp only [decodeABIValues?, bytes32, bytes32Width, uint256, uint256Int, isDynamicABIType, - Bool.false_eq_true, if_false, staticABIEncodedSize?, bind, Option.bind, Nat.zero_add] - by_cases h32 : bytes.length < 32 - · have htake0n : ¬ (bytes.take 32).length = 32 := by - rw [List.length_take] - omega - have hnot : ¬ 32 ≤ bytes.length := by omega - simp [decodeABIValue?, readBytes?, zeroPadding?, hnot] - · have htake0 : (bytes.take 32).length = 32 := by - rw [List.length_take] - omega - have htake32n : ¬ ((bytes.drop 32).take 32).length = 32 := by - rw [List.length_take, List.length_drop] - omega - simp [decodeABIValue?, readBytes?, zeroPadding?, htake0] - have hnot : ¬ 32 ≤ bytes.length - 32 := by - rw [List.length_take, List.length_drop] at htake32n - omega - simp [readWord?, readBytes?, hnot] - -theorem attesterDecodeABIValues_bytes32_ok {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) : - decodeABIValues? [bytes32] bytes 0 0 32 32 = - some ([.fixedBytes bytes32Width (bytes.take 32)], 32) := by - simp [decodeABIValues?, bytes32, bytes32Width, isDynamicABIType, - staticABIEncodedSize?, decodeABIValue?, readBytes?, zeroPadding?, hlen0] - -theorem attesterDecodeABIValues_bytes32_none_short {bytes : List UInt8} - (hshort : bytes.length < 32) : - decodeABIValues? [bytes32] bytes 0 0 32 32 = none := by - have hnot : ¬ 32 ≤ bytes.length := by omega - simp [decodeABIValues?, bytes32, bytes32Width, isDynamicABIType, - staticABIEncodedSize?, decodeABIValue?, readBytes?, zeroPadding?, hnot] - -theorem attesterDecodeReturnValue_bytes32_ok {returndata : ByteArray} - (hlo : 32 ≤ returndata.size) (hhi : returndata.size < 2 ^ 255) : - ABI.decodeReturnValue? bytes32 returndata = - some (.fixedBytes bytes32Width - (EVM.Word.toBytesBE (uInt256OfByteArray (returndata.extract 0 32)))) := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake0 : (returndata.toList.take 32).length = 32 := by - rw [List.length_take, hlen] - omega - have hwordList := bytesToWord_take32_eq_extract0_32 (returndata := returndata) - have hword : ABI.bytesToWord (returndata.toList.take 32) = - uInt256OfByteArray (returndata.extract 0 32) := by - rw [hwordList, uInt256OfByteArray_eq] - have hbytes : - EVM.Word.toBytesBE (uInt256OfByteArray (returndata.extract 0 32)) = - returndata.toList.take 32 := by - rw [← hword] - exact toBytesBE_bytesToWord_of_length htake0 - rw [hbytes] - unfold ABI.decodeReturnValue? ABI.decodeReturnValues? - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - rw [show ABI.abiTupleHeadSize? [bytes32] = some 32 by native_decide] - simp only [bind, Option.bind] - rw [attesterDecodeABIValues_bytes32_ok (bytes := returndata.toList) htake0] - -theorem attesterDecodeReturnValue_bytes32_none_short {returndata : ByteArray} - (hshort : returndata.size < 32) : - ABI.decodeReturnValue? bytes32 returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - unfold ABI.decodeReturnValue? ABI.decodeReturnValues? - rw [if_neg (by - rintro ⟨_, hhuge⟩ - rw [hlen] at hhuge - omega)] - rw [show ABI.abiTupleHeadSize? [bytes32] = some 32 by native_decide] - simp only [bind, Option.bind] - rw [attesterDecodeABIValues_bytes32_none_short (bytes := returndata.toList) (by rw [hlen]; omega)] - -theorem attesterDecodeReturnValue_bytes32_none_huge {returndata : ByteArray} - (hhuge : 2 ^ 255 ≤ returndata.size) : - ABI.decodeReturnValue? bytes32 returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - unfold ABI.decodeReturnValue? ABI.decodeReturnValues? - rw [if_pos (by exact ⟨by simp, by rw [hlen]; exact hhuge⟩)] - -theorem attesterDecode_attest_return_ok (v : AttesterImmutables) {o : ByteArray} - (ho32 : 32 ≤ o.size) (ho255 : o.size < 2 ^ 255) : - (config v).externalABI.decode? "attest" o = - some [.fixedBytes bytes32Width - (EVM.Word.toBytesBE (uInt256OfByteArray (o.extract 0 32)))] := by - change decodeReturn? bytes32 o = - some [.fixedBytes bytes32Width - (EVM.Word.toBytesBE (uInt256OfByteArray (o.extract 0 32)))] - unfold decodeReturn? - rw [attesterDecodeReturnValue_bytes32_ok ho32 ho255] - rfl - -theorem attesterDecode_attest_return_none_short (v : AttesterImmutables) {o : ByteArray} - (hshort : o.size < 32) : - (config v).externalABI.decode? "attest" o = none := by - change decodeReturn? bytes32 o = none - unfold decodeReturn? - rw [attesterDecodeReturnValue_bytes32_none_short hshort] - rfl - -theorem attesterDecode_attest_return_none_huge (v : AttesterImmutables) {o : ByteArray} - (hhuge : 2 ^ 255 ≤ o.size) : - (config v).externalABI.decode? "attest" o = none := by - change decodeReturn? bytes32 o = none - unfold decodeReturn? - rw [attesterDecodeReturnValue_bytes32_none_huge hhuge] - rfl - -theorem attesterDecode_attest_ok (v : AttesterImmutables) {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) : - decodeCalldataWithMode (config v).abiDecodeMode - ((attestTransition v).params.map Param.name) - (transitionSignature (attestTransition v)).paramTypes I.calldata = - some (attesterAttestStore I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake4 : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have htake36 : ((I.calldata.toList.drop 36).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have hword36 : ABI.bytesToWord ((I.calldata.toList.drop 36).take 32) = - calldataWord I.calldata 36 := by - exact decode_word_at_eq I.calldata 36 (by omega) (by norm_num) - show decodeCalldata ["schema", "input"] [bytes32, uint256] I.calldata = - some (attesterAttestStore I) - unfold decodeCalldata - rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - rw [if_neg (by simp [bytes32, uint256, isDynamicABIType])] - rw [if_neg (by rintro ⟨_, hc⟩; rw [List.length_drop, htlen] at hc; omega)] - rw [if_neg (by simp [solcTotalSizeDynamicGuard])] - simp only [decodeCalldata.decodeArgs] - rw [show abiTupleHeadSize? [bytes32, uint256] = some 64 by native_decide] - simp only [bind, Option.bind] - rw [attesterDecodeABIValues_bytes32_uint256_ok (bytes := I.calldata.toList.drop 4) - (by simpa using htake4) - (by simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using htake36)] - rw [if_neg (by rw [List.length_drop, htlen]; omega : - ¬ (I.calldata.toList.drop 4).length < 64)] - simp [decodeCalldata.insertValues, attesterAttestStore, attesterAttestSchemaBytes, - attesterAttestInputWord] - rw [hword36] - -theorem attesterDecode_attest_none_short (v : AttesterImmutables) {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 68) : - decodeCalldataWithMode (config v).abiDecodeMode - ((attestTransition v).params.map Param.name) - (transitionSignature (attestTransition v)).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - show decodeCalldata ["schema", "input"] [bytes32, uint256] I.calldata = none - unfold decodeCalldata - rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - rw [if_neg (by simp [bytes32, uint256, isDynamicABIType])] - rw [if_neg (by rintro ⟨_, hc⟩; rw [List.length_drop, htlen] at hc; omega)] - rw [if_neg (by simp [solcTotalSizeDynamicGuard])] - simp only [decodeCalldata.decodeArgs] - rw [show abiTupleHeadSize? [bytes32, uint256] = some 64 by native_decide] - simp only [bind, Option.bind] - rw [attesterDecodeABIValues_bytes32_uint256_none_short - (bytes := I.calldata.toList.drop 4) (by rw [List.length_drop, htlen]; omega)] - rw [if_pos (by rw [List.length_drop, htlen]; omega : - (I.calldata.toList.drop 4).length < 64)] - -theorem attesterDecode_attest_none_huge (v : AttesterImmutables) {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - ((attestTransition v).params.map Param.name) - (transitionSignature (attestTransition v)).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - show decodeCalldata ["schema", "input"] [bytes32, uint256] I.calldata = none - unfold decodeCalldata - rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - rw [if_neg (by simp [bytes32, uint256, isDynamicABIType])] - rw [if_pos] - · exact ⟨rfl, by rw [List.length_drop, htlen]; omega⟩ - -theorem attesterAttestBodySuccess (v : AttesterImmutables) - (evm evm' : EVM.State) (locals : Store) {argVals : List Value} - {out : ByteArray} {uid : Value} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hargs : evalExprs? (config v) { contract := contract v, locals := locals } evm - [attestationRequest (.var "schema") (.var "input")] = .ok argVals) - (hcall : typedCallViaEVM (config v) evm (EVM.address v.eas) "attest" 0 argVals - (true, evm', out)) - (hdec : (config v).externalABI.decode? "attest" out = some [uid]) : - ExecTransitionBody (config v) (contract v) evm locals (attestTransition v).body - (.returned { contract := contract v, locals := locals.insert "uid" uid } evm' - (some [uid])) := by - exact ExecFuncBody.execBlockRet <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) <| - ExecBlock.consNormal - (ExecStmt.externalCallSuccess - (attesterEvalEasExpr v { contract := contract v, locals := locals } evm) - (by simp [evalExpr?, pure]) hargs hcall hdec) <| - ExecBlock.consReturn (ExecStmt.return (by - simp [evalExprs?, evalExpr?, EvalResult.bind, bind, pure, collapseReturns, - EvalResult.ofOption])) - -theorem attesterAttestBodyCallFailure (v : AttesterImmutables) - (evm evm' : EVM.State) (locals : Store) {argVals : List Value} - {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hargs : evalExprs? (config v) { contract := contract v, locals := locals } evm - [attestationRequest (.var "schema") (.var "input")] = .ok argVals) - (hcall : typedCallViaEVM (config v) evm (EVM.address v.eas) "attest" 0 argVals - (false, evm', out)) : - ExecTransitionBody (config v) (contract v) evm locals (attestTransition v).body .reverted := by - exact ExecFuncBody.execBlockRevert <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) <| - ExecBlock.consRevert - (ExecStmt.externalCallFailure - (attesterEvalEasExpr v { contract := contract v, locals := locals } evm) - (by simp [evalExpr?, pure]) hargs hcall) - -theorem attesterAttestBodyDecodeRevert (v : AttesterImmutables) - (evm evm' : EVM.State) (locals : Store) {argVals : List Value} - {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hargs : evalExprs? (config v) { contract := contract v, locals := locals } evm - [attestationRequest (.var "schema") (.var "input")] = .ok argVals) - (hcall : typedCallViaEVM (config v) evm (EVM.address v.eas) "attest" 0 argVals - (true, evm', out)) - (hdec : (config v).externalABI.decode? "attest" out = none) : - ExecTransitionBody (config v) (contract v) evm locals (attestTransition v).body .reverted := by - exact ExecFuncBody.execBlockRevert <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) <| - ExecBlock.consRevert - (ExecStmt.externalCallReturnDecodeRevert - (attesterEvalEasExpr v { contract := contract v, locals := locals } evm) - (by simp [evalExpr?, pure]) hargs hcall hdec) - -theorem attesterX_attestWrapper {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = true) : - ∃ k C, RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨140⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C := by - have h0 := solcGuardPrologueRD (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode - (by attester_decode) (by attester_decode) (by attester_decode) - (by attester_decode) (by attester_decode) (by attester_decode) - obtain ⟨_, _, h17⟩ := solcGuardCallvalueZero - (ctgt := (⟨15⟩ : UInt256)) (opC := .PUSH2) (wC := 2) - h0 hwv (by decide) (by attester_decode) - (by attester_decode) (by attester_decode) - (by attester_decode) (attesterGuardJumpdest v) - obtain ⟨k25, C25, h25raw⟩ := solcCalldataOk - (bodyPc := (⟨17⟩ : UInt256)) (selLoadTgt := attesterDispatchRevertPc) - (opR := .PUSH2) (wR := 2) - h17 hsz hsize (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) - have h25 : - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨25⟩ : UInt256) - [] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k25 C25 := by - simpa using h25raw - obtain ⟨k30, C30, h30raw⟩ := solcSelectorLoad h25 - (by attester_decode) (by attester_decode) (by attester_decode) (by attester_decode) (by simp) - have h30 : - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) attesterFirstArmPc - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k30 C30 := by - simpa [attesterFirstArmPc, solcSelectorWord] using h30raw - have heqMultiRevoke := attesterMultiRevokeEqZero I hsz hmultiRevoke - have heqMultiAttest := attesterMultiAttestEqZero I hsz hmultiAttest - have heqAttest := attesterAttestEqNonzero I hsz hattest - exact ⟨_, _, h30 - |>.selectorArmNotTaken (selNat := (⟨0x13fde550⟩ : UInt256)) - (tgt := (⟨78⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqMultiRevoke (by simp) - |>.selectorArmNotTaken (selNat := (⟨0x54e1db35⟩ : UInt256)) - (tgt := (⟨99⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqMultiAttest (by simp) - |>.selectorArmTaken (selNat := (⟨0x72b9966d⟩ : UInt256)) - (tgt := (⟨140⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqAttest - (attesterAttestWrapperJumpdest v) (by simp)⟩ - -theorem attesterX_attestToDecoder {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨140⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2281⟩ : UInt256) - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨154⟩, ⟨159⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd140⟩ := hreach - exact ⟨_, _, evm_run rd140 with [ - raw jumpdest (by attester_decode) (by evm_ov), - raw push2 ⟨159⟩ (by attester_decode) (by evm_ov), - raw push2 ⟨154⟩ (by attester_decode) (by evm_ov), - raw calldatasize (by attester_decode) (by evm_ov), - raw push1 ⟨4⟩ (by attester_decode) (by evm_ov), - raw push2 ⟨2281⟩ (by attester_decode) (by evm_ov), - raw jump (by attester_decode) (attesterAttestDecoderJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_attestDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨1⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨140⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2281⟩ := attesterX_attestToDecoder (v := v) hreach - exact evm_run rd2281 with [ - raw jumpdest (by attester_decode_at v, ⟨2281⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2282⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2283⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2284⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2286⟩, 0x83, .DUP4) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2287⟩, 0x85, .DUP6) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2288⟩, 0x03, .SUB) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2289⟩, 0x12, .SLT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2290⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2298⟩ (by attester_decode_at v, ⟨2291⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2294⟩, 0x57, .JUMPI) (by rw [hslt]; decide) - (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2295⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2296⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2297⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_attestDecodeShort {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hshort : I.calldata.size < 68) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = true) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨1⟩ := - solcDecodeLenCheckShort_4_64 hsz4 hshort hsize - exact attesterX_attestDecodeRevert (v := v) hslt - (attesterX_attestWrapper (g := g) v hcode hwv hsz4 hsize hmultiRevoke hmultiAttest hattest) - -theorem attesterX_attestDecodeHuge {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = true) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨1⟩ := - solcDecodeLenCheckHuge_4_64 hbig hsize - exact attesterX_attestDecodeRevert (v := v) hslt - (attesterX_attestWrapper (g := g) v hcode hwv hsz4 hsize hmultiRevoke hmultiAttest hattest) - -theorem attesterX_attestDecoded {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨140⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1595⟩ : UInt256) - [attesterAttestInputWord I, attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨0⟩ := - solcDecodeLenCheckOk_4_64 hsz68 hsmall hsize - obtain ⟨_, _, rd2281⟩ := attesterX_attestToDecoder (v := v) hreach - have rd154 := evm_run rd2281 with [ - raw jumpdest (by attester_decode_at v, ⟨2281⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2282⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2283⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2284⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2286⟩, 0x83, .DUP4) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2287⟩, 0x85, .DUP6) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2288⟩, 0x03, .SUB) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2289⟩, 0x12, .SLT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2290⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2298⟩ (by attester_decode_at v, ⟨2291⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2294⟩, 0x57, .JUMPI) - (by rw [hslt]; decide) (attesterAttestDecodeOkJumpdest v) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨2298⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2299⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2300⟩, 0x50, .POP) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2301⟩, 0x80, .DUP1) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2302⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2303⟩, 0x92, .SWAP3) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2304⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2306⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2307⟩, 0x91, .SWAP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨2308⟩, 0x01, .ADD) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2309⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2310⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2311⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨2312⟩, 0x56, .JUMP) - (attesterAttestDecodedJumpdest v) (by evm_ov)] - have rd1595 := evm_run rd154 with [ - raw jumpdest (by attester_decode_at v, ⟨154⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push2 ⟨1595⟩ (by attester_decode_at v, ⟨155⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨158⟩, 0x56, .JUMP) - (attesterAttestBodyJumpdest v) (by evm_ov)] - exact ⟨_, _, by - simpa [attesterAttestInputWord, attesterAttestSchemaWord, calldataWord, - show (⟨4⟩ : UInt256).toNat = 4 from by decide, - show (⟨36⟩ : UInt256).toNat = 36 from by decide] using rd1595⟩ - -set_option maxRecDepth 10000 in -theorem attesterX_attestToEncodeTail {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨140⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1737⟩ : UInt256) - [⟨448⟩, ⟨320⟩, ⟨192⟩, ⟨160⟩, ⟨128⟩, ⟨0xf17325e7⟩, - attesterAttestTargetWord v, ⟨0⟩, attesterAttestInputWord I, - attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - (attesterAttestMemInputWord I) (UInt256.ofNat 14) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd1595⟩ := attesterX_attestDecoded (v := v) hsz68 hsize hsmall hreach - have rd1597 := evm_run rd1595 with [ - raw jumpdest (by attester_decode_at v, ⟨1595⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨1596⟩, 0x5f, .PUSH0) (by evm_ov)] - have rd1630 := rd1597.pushConst (attesterAttestEasWord v) (width := 32) (op := .PUSH32) - (by decide) (attesterDecodeEasWord1597 v) (by evm_ov) - have rd1737 := evm_run rd1630 with [ - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨1630⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨1632⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨160⟩ (by attester_decode_at v, ⟨1634⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨1636⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨1637⟩, 0x03, .SUB) (by evm_ov), - raw and (by attester_decode_at v, ⟨1638⟩, 0x16, .AND) (by evm_ov), - raw push4 ⟨0xf17325e7⟩ (by attester_decode_at v, ⟨1639⟩, 0x63, (.Push .PUSH4)) - (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1644⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) - (by attester_decode_at v, ⟨1646⟩, 0x51, .MLOAD) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1647⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1648⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1650⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1651⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mstore 0 attesterAttestMem192 (UInt256.ofNat 3) - (by attester_decode_at v, ⟨1653⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1654⟩, 0x80, .DUP1) (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨1655⟩, 0x86, .DUP7) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1656⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 6 (attesterAttestMemSchema I) (UInt256.ofNat 5) - (by attester_decode_at v, ⟨1657⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1658⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1660⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1661⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨192⟩ (UInt256.ofNat 5) - (by attester_decode_at v, ⟨1663⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestMemSchema_size I]; decide) (by decide) - (attesterAttestMemSchema_read64 I)) - (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1664⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨192⟩ (by attester_decode_at v, ⟨1665⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1667⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1668⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mstore 0 (attesterAttestMem384 I) (UInt256.ofNat 5) - (by attester_decode_at v, ⟨1670⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1671⟩, 0x80, .DUP1) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨1672⟩, 0x5f, .PUSH0) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨1673⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨1675⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨160⟩ (by attester_decode_at v, ⟨1677⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨1679⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨1680⟩, 0x03, .SUB) (by evm_ov), - raw and (by attester_decode_at v, ⟨1681⟩, 0x16, .AND) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1682⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 6 (attesterAttestMemRecipient I) (UInt256.ofNat 7) - (by attester_decode_at v, ⟨1683⟩, 0x52, .MSTORE) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] - rw [show UInt256.land solcAddrMask (⟨0⟩ : UInt256) = ⟨0⟩ by decide] - rw [show (⟨192⟩ : UInt256).toNat = 192 by decide] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1684⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1686⟩, 0x01, .ADD) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨1687⟩, 0x5f, .PUSH0) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨1688⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨1690⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1692⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨1694⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨1695⟩, 0x03, .SUB) (by evm_ov), - raw and (by attester_decode_at v, ⟨1696⟩, 0x16, .AND) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1697⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 3 (attesterAttestMemExpiration I) (UInt256.ofNat 8) - (by attester_decode_at v, ⟨1698⟩, 0x52, .MSTORE) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩ = - (⟨18446744073709551615⟩ : UInt256) by decide] - rw [show UInt256.land (⟨18446744073709551615⟩ : UInt256) ⟨0⟩ = ⟨0⟩ by decide] - rw [show ((⟨32⟩ : UInt256) + ⟨192⟩).toNat = 224 by decide] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1699⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1701⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨1702⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨1704⟩, 0x15, .ISZERO) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨1705⟩, 0x15, .ISZERO) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1706⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 3 (attesterAttestMemRevocable I) (UInt256.ofNat 9) - (by attester_decode_at v, ⟨1707⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1708⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1710⟩, 0x01, .ADD) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨1711⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1712⟩, 0x80, .DUP1) (by evm_ov), - raw shl (by attester_decode_at v, ⟨1713⟩, 0x1b, .SHL) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1714⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 3 (attesterAttestMemRefUID I) (UInt256.ofNat 10) - (by attester_decode_at v, ⟨1715⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1716⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1718⟩, 0x01, .ADD) (by evm_ov), - raw dup8 (by attester_decode_at v, ⟨1719⟩, 0x87, .DUP8) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1720⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨384⟩ (UInt256.ofNat 10) - (by attester_decode_at v, ⟨1722⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestMemRefUID_size I]; decide) (by decide) - (attesterAttestMemRefUID_read64 I)) - (by decide) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1723⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1725⟩, 0x01, .ADD) (by evm_ov), - raw push2 ⟨1737⟩ (by attester_decode_at v, ⟨1726⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨1729⟩, 0x91, .SWAP2) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1730⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 12 (attesterAttestMemInputWord I) (UInt256.ofNat 14) - (by attester_decode_at v, ⟨1731⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1732⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1734⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1735⟩, 0x90, .SWAP1) (by evm_ov), - raw jump (by attester_decode_at v, ⟨1736⟩, 0x56, .JUMP) - (attesterAttestEncodeTailJumpdest v) (by evm_ov)] - exact ⟨_, _, by - simpa [attesterAttestTargetWord, attesterAttestEasWord, - show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask from by decide] using rd1737⟩ - -set_option maxRecDepth 10000 in -theorem attesterX_attestToEncodeRequest {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨140⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨3106⟩ : UInt256) - [⟨452⟩, ⟨128⟩, ⟨1792⟩, ⟨0xf17325e7⟩, attesterAttestTargetWord v, ⟨0⟩, - attesterAttestInputWord I, attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - (attesterAttestCallMemSelector I) (UInt256.ofNat 15) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd1737⟩ := - attesterX_attestToEncodeTail (v := v) hsz68 hsize hsmall hreach - have rd3106 := evm_run rd1737 with [ - raw jumpdest (by attester_decode_at v, ⟨1737⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1738⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨384⟩ (UInt256.ofNat 14) - (by attester_decode_at v, ⟨1740⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestMemInputWord_size I]; decide) (by decide) - (attesterAttestMemInputWord_read64 I)) - (by decide) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1741⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1743⟩, 0x81, .DUP2) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1744⟩, 0x83, .DUP4) (by evm_ov), - raw sub (by attester_decode_at v, ⟨1745⟩, 0x03, .SUB) (by evm_ov), - raw sub (by attester_decode_at v, ⟨1746⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1747⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 0 (attesterAttestMemBytesLen I) (UInt256.ofNat 14) - (by attester_decode_at v, ⟨1748⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1749⟩, 0x90, .SWAP1) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1750⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mstore 0 (attesterAttestMem448 I) (UInt256.ofNat 14) - (by attester_decode_at v, ⟨1752⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1753⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 0 (attesterAttestMemDataOffset I) (UInt256.ofNat 14) - (by attester_decode_at v, ⟨1754⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1755⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1757⟩, 0x01, .ADD) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨1758⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1759⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 0 (attesterAttestMemDataPad I) (UInt256.ofNat 14) - (by attester_decode_at v, ⟨1760⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1761⟩, 0x50, .POP) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1762⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 0 (attesterAttestSourceMem I) (UInt256.ofNat 14) - (by attester_decode_at v, ⟨1763⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1764⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1765⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨448⟩ (UInt256.ofNat 14) - (by attester_decode_at v, ⟨1767⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestSourceMem_size I]; decide) (by decide) - (attesterAttestSourceMem_read64 I)) - (by decide) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1768⟩, 0x82, .DUP3) (by evm_ov), - raw push4 ⟨0xffffffff⟩ (by attester_decode_at v, ⟨1769⟩, 0x63, (.Push .PUSH4)) - (by evm_ov), - raw and (by attester_decode_at v, ⟨1774⟩, 0x16, .AND) (by evm_ov), - raw push1 ⟨224⟩ (by attester_decode_at v, ⟨1775⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨1777⟩, 0x1b, .SHL) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1778⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 3 (attesterAttestCallMemSelector I) (UInt256.ofNat 15) - (by attester_decode_at v, ⟨1779⟩, 0x52, .MSTORE) mem_cost - (by - rw [show UInt256.land (⟨0xffffffff⟩ : UInt256) ⟨0xf17325e7⟩ = ⟨0xf17325e7⟩ - by decide] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨4⟩ (by attester_decode_at v, ⟨1780⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1782⟩, 0x01, .ADD) (by evm_ov), - raw push2 ⟨1792⟩ (by attester_decode_at v, ⟨1783⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨1786⟩, 0x91, .SWAP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1787⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨3106⟩ (by attester_decode_at v, ⟨1788⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨1791⟩, 0x56, .JUMP) - (attesterAttestEncodeRequestJumpdest v) (by evm_ov)] - exact ⟨_, _, rd3106⟩ - -set_option maxRecDepth 10000 in -theorem attesterX_attestToTupleEncoder {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨140⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2604⟩ : UInt256) - [⟨192⟩, ⟨548⟩, ⟨3142⟩, ⟨192⟩, ⟨0⟩, ⟨452⟩, ⟨128⟩, ⟨1792⟩, - ⟨0xf17325e7⟩, attesterAttestTargetWord v, ⟨0⟩, attesterAttestInputWord I, - attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - (attesterAttestCallMemDataOffset I) (UInt256.ofNat 18) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd3106⟩ := - attesterX_attestToEncodeRequest (v := v) hsz68 hsize hsmall hreach - have rd2604 := evm_run rd3106 with [ - raw jumpdest (by attester_decode_at v, ⟨3106⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨3107⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨3109⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 3 (attesterAttestCallMemArgOffset I) (UInt256.ofNat 16) - (by attester_decode_at v, ⟨3110⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨3111⟩, 0x81, .DUP2) (by evm_ov), - raw mload 0 (attesterAttestSchemaWord I) (UInt256.ofNat 16) - (by attester_decode_at v, ⟨3112⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestCallMemArgOffset_size I]; decide) (by decide) - (attesterAttestCallMemArgOffset_read128 I)) - (by decide) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨3113⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨3115⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨3116⟩, 0x01, .ADD) (by evm_ov), - raw mstore 3 (attesterAttestCallMemSchema I) (UInt256.ofNat 17) - (by attester_decode_at v, ⟨3117⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨3118⟩, 0x5f, .PUSH0) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨3119⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨3121⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨3122⟩, 0x01, .ADD) (by evm_ov), - raw mload 0 ⟨192⟩ (UInt256.ofNat 17) - (by attester_decode_at v, ⟨3123⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestCallMemSchema_size I]; decide) (by decide) - (by - rw [show ((⟨128⟩ : UInt256) + ⟨32⟩).toNat = 160 by decide] - exact attesterAttestCallMemSchema_read160 I)) - (by decide) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨3124⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨3126⟩, 0x80, .DUP1) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨3127⟩, 0x84, .DUP5) (by evm_ov), - raw add (by attester_decode_at v, ⟨3128⟩, 0x01, .ADD) (by evm_ov), - raw mstore 3 (attesterAttestCallMemDataOffset I) (UInt256.ofNat 18) - (by attester_decode_at v, ⟨3129⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw push2 ⟨3142⟩ (by attester_decode_at v, ⟨3130⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw push1 ⟨96⟩ (by attester_decode_at v, ⟨3133⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨3135⟩, 0x84, .DUP5) (by evm_ov), - raw add (by attester_decode_at v, ⟨3136⟩, 0x01, .ADD) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨3137⟩, 0x82, .DUP3) (by evm_ov), - raw push2 ⟨2604⟩ (by attester_decode_at v, ⟨3138⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨3141⟩, 0x56, .JUMP) - (attesterAttestEncodeTupleJumpdest v) (by evm_ov)] - exact ⟨_, _, by - simpa [show ((⟨452⟩ : UInt256) + ⟨96⟩) = (⟨548⟩ : UInt256) by decide] - using rd2604⟩ - -set_option maxRecDepth 10000 in -set_option maxHeartbeats 1000000 in -theorem attesterX_attestEncodeTuple {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨140⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨3142⟩ : UInt256) - [⟨804⟩, ⟨192⟩, ⟨0⟩, ⟨452⟩, ⟨128⟩, ⟨1792⟩, ⟨0xf17325e7⟩, - attesterAttestTargetWord v, ⟨0⟩, attesterAttestInputWord I, - attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - (attesterAttestCallMem I) (UInt256.ofNat 27) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2604⟩ := - attesterX_attestToTupleEncoder (v := v) hsz68 hsize hsmall hreach - have rd2688_raw := evm_run rd2604 with [ - raw jumpdest (by attester_decode_at v, ⟨2604⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2605⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2607⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨160⟩ (by attester_decode_at v, ⟨2608⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2610⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2611⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2612⟩, 0x81, .DUP2) (by evm_ov), - raw mload 0 ⟨0⟩ (UInt256.ofNat 18) - (by attester_decode_at v, ⟨2613⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestCallMemDataOffset_size I]; decide) (by decide) - (attesterAttestCallMemDataOffset_read192 I)) - (by decide) (by evm_ov), - raw and (by attester_decode_at v, ⟨2614⟩, 0x16, .AND) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2615⟩, 0x82, .DUP3) (by evm_ov), - raw mstore 3 (attesterAttestCallMemRecipient I) (UInt256.ofNat 19) - (by attester_decode_at v, ⟨2616⟩, 0x52, .MSTORE) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] - rw [show UInt256.land (⟨0⟩ : UInt256) solcAddrMask = ⟨0⟩ by decide] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2617⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2619⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2621⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2623⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2624⟩, 0x03, .SUB) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2625⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2627⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨2628⟩, 0x01, .ADD) (by evm_ov), - raw mload 0 ⟨0⟩ (UInt256.ofNat 19) - (by attester_decode_at v, ⟨2629⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestCallMemRecipient_size I]; decide) (by decide) - (by - rw [show ((⟨192⟩ : UInt256) + ⟨32⟩).toNat = 224 by decide] - exact attesterAttestCallMemRecipient_read224 I)) - (by decide) (by evm_ov), - raw and (by attester_decode_at v, ⟨2630⟩, 0x16, .AND) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2631⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2633⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2634⟩, 0x01, .ADD) (by evm_ov), - raw mstore 3 (attesterAttestCallMemExpiration I) (UInt256.ofNat 20) - (by attester_decode_at v, ⟨2635⟩, 0x52, .MSTORE) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩ = - (⟨18446744073709551615⟩ : UInt256) by decide] - rw [show UInt256.land (⟨0⟩ : UInt256) (⟨18446744073709551615⟩ : UInt256) = - ⟨0⟩ by decide] - rw [show ((⟨548⟩ : UInt256) + ⟨32⟩).toNat = 580 by decide] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2636⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2638⟩, 0x81, .DUP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨2639⟩, 0x01, .ADD) (by evm_ov), - raw mload 0 ⟨1⟩ (UInt256.ofNat 20) - (by attester_decode_at v, ⟨2640⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestCallMemExpiration_size I]; decide) (by decide) - (by - rw [show ((⟨192⟩ : UInt256) + ⟨64⟩).toNat = 256 by decide] - exact attesterAttestCallMemExpiration_read256 I)) - (by decide) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2641⟩, 0x15, .ISZERO) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2642⟩, 0x15, .ISZERO) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2643⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2645⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2646⟩, 0x01, .ADD) (by evm_ov), - raw mstore 3 (attesterAttestCallMemRevocable I) (UInt256.ofNat 21) - (by attester_decode_at v, ⟨2647⟩, 0x52, .MSTORE) mem_cost - (by - rw [show ((⟨548⟩ : UInt256) + ⟨64⟩).toNat = 612 by decide] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨96⟩ (by attester_decode_at v, ⟨2648⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2650⟩, 0x81, .DUP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨2651⟩, 0x01, .ADD) (by evm_ov), - raw mload 0 ⟨0⟩ (UInt256.ofNat 21) - (by attester_decode_at v, ⟨2652⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestCallMemRevocable_size I]; decide) (by decide) - (by - rw [show ((⟨192⟩ : UInt256) + ⟨96⟩).toNat = 288 by decide] - exact attesterAttestCallMemRevocable_read288 I)) - (by decide) (by evm_ov), - raw push1 ⟨96⟩ (by attester_decode_at v, ⟨2653⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2655⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2656⟩, 0x01, .ADD) (by evm_ov), - raw mstore 3 (attesterAttestCallMemRefUID I) (UInt256.ofNat 22) - (by attester_decode_at v, ⟨2657⟩, 0x52, .MSTORE) mem_cost - (by - rw [show ((⟨548⟩ : UInt256) + ⟨96⟩).toNat = 644 by decide] - rfl) - (by decide) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2658⟩, 0x5f, .PUSH0) (by evm_ov), - raw push1 ⟨128⟩ (by attester_decode_at v, ⟨2659⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2661⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨2662⟩, 0x01, .ADD) (by evm_ov), - raw mload 0 ⟨384⟩ (UInt256.ofNat 22) - (by attester_decode_at v, ⟨2663⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestCallMemRefUID_size I]; decide) (by decide) - (by - rw [show ((⟨192⟩ : UInt256) + ⟨128⟩).toNat = 320 by decide] - exact attesterAttestCallMemRefUID_read320 I)) - (by decide) (by evm_ov), - raw push1 ⟨192⟩ (by attester_decode_at v, ⟨2664⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨128⟩ (by attester_decode_at v, ⟨2666⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2668⟩, 0x85, .DUP6) (by evm_ov), - raw add (by attester_decode_at v, ⟨2669⟩, 0x01, .ADD) (by evm_ov), - raw mstore 4 (attesterAttestCallMemBytesOffset I) (UInt256.ofNat 23) - (by attester_decode_at v, ⟨2670⟩, 0x52, .MSTORE) mem_cost - (by - rw [show ((⟨548⟩ : UInt256) + ⟨128⟩).toNat = 676 by decide] - rfl) - (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2671⟩, 0x80, .DUP1) (by evm_ov), - raw mload 0 ⟨32⟩ (UInt256.ofNat 23) - (by attester_decode_at v, ⟨2672⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestCallMemBytesOffset_size I]; decide) (by decide) - (attesterAttestCallMemBytesOffset_read384 I)) - (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2673⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨192⟩ (by attester_decode_at v, ⟨2674⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨2676⟩, 0x86, .DUP7) (by evm_ov), - raw add (by attester_decode_at v, ⟨2677⟩, 0x01, .ADD) (by evm_ov), - raw mstore 6 (attesterAttestCallMemBytesLen I) (UInt256.ofNat 25) - (by attester_decode_at v, ⟨2678⟩, 0x52, .MSTORE) mem_cost - (by - rw [show ((⟨548⟩ : UInt256) + ⟨192⟩).toNat = 740 by decide] - rfl) - (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2679⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2680⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2682⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2683⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨224⟩ (by attester_decode_at v, ⟨2684⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup8 (by attester_decode_at v, ⟨2686⟩, 0x87, .DUP8) (by evm_ov), - raw add (by attester_decode_at v, ⟨2687⟩, 0x01, .ADD) (by evm_ov)] - have hrd2688 : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2688⟩ : UInt256) - [⟨772⟩, ⟨416⟩, ⟨32⟩, ⟨32⟩, ⟨384⟩, ⟨0⟩, ⟨192⟩, ⟨548⟩, - ⟨3142⟩, ⟨192⟩, ⟨0⟩, ⟨452⟩, ⟨128⟩, ⟨1792⟩, ⟨0xf17325e7⟩, - attesterAttestTargetWord v, ⟨0⟩, attesterAttestInputWord I, - attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - (attesterAttestCallMemBytesLen I) (UInt256.ofNat 25) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by - simpa [ - show ((⟨192⟩ : UInt256) + ⟨32⟩) = (⟨224⟩ : UInt256) by decide, - show ((⟨548⟩ : UInt256) + ⟨32⟩) = (⟨580⟩ : UInt256) by decide, - show ((⟨192⟩ : UInt256) + ⟨64⟩) = (⟨256⟩ : UInt256) by decide, - show ((⟨548⟩ : UInt256) + ⟨64⟩) = (⟨612⟩ : UInt256) by decide, - show ((⟨192⟩ : UInt256) + ⟨96⟩) = (⟨288⟩ : UInt256) by decide, - show ((⟨548⟩ : UInt256) + ⟨96⟩) = (⟨644⟩ : UInt256) by decide, - show ((⟨192⟩ : UInt256) + ⟨128⟩) = (⟨320⟩ : UInt256) by decide, - show ((⟨548⟩ : UInt256) + ⟨128⟩) = (⟨676⟩ : UInt256) by decide, - show ((⟨548⟩ : UInt256) + ⟨192⟩) = (⟨740⟩ : UInt256) by decide, - show ((⟨384⟩ : UInt256) + ⟨32⟩) = (⟨416⟩ : UInt256) by decide, - show ((⟨548⟩ : UInt256) + ⟨224⟩) = (⟨772⟩ : UInt256) by decide, - show UInt256.isZero (⟨1⟩ : UInt256) = (⟨0⟩ : UInt256) by decide, - show UInt256.isZero (⟨0⟩ : UInt256) = (⟨1⟩ : UInt256) by decide, - show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide, - show UInt256.land (⟨0⟩ : UInt256) solcAddrMask = (⟨0⟩ : UInt256) by decide, - show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩ = - (⟨18446744073709551615⟩ : UInt256) by decide, - show UInt256.land (⟨0⟩ : UInt256) (⟨18446744073709551615⟩ : UInt256) = - (⟨0⟩ : UInt256) by decide] using rd2688_raw⟩ - obtain ⟨_, _, rd2688⟩ := hrd2688 - have rd2689_raw := RD.mcopyLocal 3 (attesterAttestCallMemBytesData I) (UInt256.ofNat 26) - rd2688 - (by attester_decode_at v, ⟨2688⟩, 0x5e, .MCOPY) - (by - intro s haw hstk - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk] - native_decide) - (by rfl) - (by decide) - (by evm_ov) - have hrd2689 : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2689⟩ : UInt256) - [⟨32⟩, ⟨384⟩, ⟨0⟩, ⟨192⟩, ⟨548⟩, ⟨3142⟩, ⟨192⟩, ⟨0⟩, - ⟨452⟩, ⟨128⟩, ⟨1792⟩, ⟨0xf17325e7⟩, attesterAttestTargetWord v, - ⟨0⟩, attesterAttestInputWord I, attesterAttestSchemaWord I, ⟨159⟩, - solcSelectorWord I] - (attesterAttestCallMemBytesData I) (UInt256.ofNat 26) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by - simpa [show ((⟨2688⟩ : UInt256) + ⟨1⟩) = (⟨2689⟩ : UInt256) by decide] - using rd2689_raw⟩ - obtain ⟨_, _, rd2689⟩ := hrd2689 - have rd2701_raw := evm_run rd2689 with [ - raw push0 (by attester_decode_at v, ⟨2689⟩, 0x5f, .PUSH0) (by evm_ov), - raw push1 ⟨224⟩ (by attester_decode_at v, ⟨2690⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2692⟩, 0x82, .DUP3) (by evm_ov), - raw dup8 (by attester_decode_at v, ⟨2693⟩, 0x87, .DUP8) (by evm_ov), - raw add (by attester_decode_at v, ⟨2694⟩, 0x01, .ADD) (by evm_ov), - raw add (by attester_decode_at v, ⟨2695⟩, 0x01, .ADD) (by evm_ov), - raw mstore 3 (attesterAttestCallMemPad I) (UInt256.ofNat 27) - (by attester_decode_at v, ⟨2696⟩, 0x52, .MSTORE) mem_cost - (by - rw [show (((⟨548⟩ : UInt256) + ⟨32⟩) + ⟨224⟩).toNat = 804 by decide] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨160⟩ (by attester_decode_at v, ⟨2697⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2699⟩, 0x84, .DUP5) (by evm_ov), - raw add (by attester_decode_at v, ⟨2700⟩, 0x01, .ADD) (by evm_ov)] - have hrd2701 : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2701⟩ : UInt256) - [⟨352⟩, ⟨32⟩, ⟨384⟩, ⟨0⟩, ⟨192⟩, ⟨548⟩, ⟨3142⟩, ⟨192⟩, - ⟨0⟩, ⟨452⟩, ⟨128⟩, ⟨1792⟩, ⟨0xf17325e7⟩, - attesterAttestTargetWord v, ⟨0⟩, attesterAttestInputWord I, - attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - (attesterAttestCallMemPad I) (UInt256.ofNat 27) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by - simpa [ - show (((⟨548⟩ : UInt256) + ⟨32⟩) + ⟨224⟩) = (⟨804⟩ : UInt256) by decide, - show ((⟨192⟩ : UInt256) + ⟨160⟩) = (⟨352⟩ : UInt256) by decide] - using rd2701_raw⟩ - obtain ⟨_, _, rd2701⟩ := hrd2701 - have rd2707_raw := evm_run rd2701 with [ - raw mload 0 ⟨0⟩ (UInt256.ofNat 27) - (by attester_decode_at v, ⟨2701⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestCallMemPad_size I]; decide) (by decide) - (by simpa using attesterAttestCallMemPad_read352 I)) - (by decide) (by evm_ov), - raw push1 ⟨160⟩ (by attester_decode_at v, ⟨2702⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨2704⟩, 0x86, .DUP7) (by evm_ov), - raw add (by attester_decode_at v, ⟨2705⟩, 0x01, .ADD) (by evm_ov), - raw mstore 0 (attesterAttestCallMemValue I) (UInt256.ofNat 27) - (by attester_decode_at v, ⟨2706⟩, 0x52, .MSTORE) mem_cost - (by - rw [show ((⟨548⟩ : UInt256) + ⟨160⟩).toNat = 708 by decide] - rfl) - (by decide) (by evm_ov)] - have hrd2707 : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2707⟩ : UInt256) - [⟨32⟩, ⟨384⟩, ⟨0⟩, ⟨192⟩, ⟨548⟩, ⟨3142⟩, ⟨192⟩, ⟨0⟩, - ⟨452⟩, ⟨128⟩, ⟨1792⟩, ⟨0xf17325e7⟩, attesterAttestTargetWord v, - ⟨0⟩, attesterAttestInputWord I, attesterAttestSchemaWord I, ⟨159⟩, - solcSelectorWord I] - (attesterAttestCallMemValue I) (UInt256.ofNat 27) ByteArray.empty (cA, σ) k C := by - exact ⟨_, _, by - simpa [show ((⟨548⟩ : UInt256) + ⟨160⟩) = (⟨708⟩ : UInt256) by decide] - using rd2707_raw⟩ - obtain ⟨_, _, rd2707⟩ := hrd2707 - have rd3142 := evm_run rd2707 with [ - raw push1 ⟨224⟩ (by attester_decode_at v, ⟨2707⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨31⟩ (by attester_decode_at v, ⟨2709⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw not (by attester_decode_at v, ⟨2711⟩, 0x19, .NOT) (by evm_ov), - raw push1 ⟨31⟩ (by attester_decode_at v, ⟨2712⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2714⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2715⟩, 0x01, .ADD) (by evm_ov), - raw and (by attester_decode_at v, ⟨2716⟩, 0x16, .AND) (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨2717⟩, 0x86, .DUP7) (by evm_ov), - raw add (by attester_decode_at v, ⟨2718⟩, 0x01, .ADD) (by evm_ov), - raw add (by attester_decode_at v, ⟨2719⟩, 0x01, .ADD) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2720⟩, 0x92, .SWAP3) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2721⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2722⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2723⟩, 0x50, .POP) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2724⟩, 0x92, .SWAP3) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2725⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2726⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2727⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨2728⟩, 0x56, .JUMP) - (attesterAttestEncodeTupleReturnJumpdest v) (by evm_ov)] - exact ⟨_, _, by - simpa [attesterAttestCallMem, - show UInt256.land ((⟨32⟩ : UInt256) + ⟨31⟩) (UInt256.lnot ⟨31⟩) = - (⟨32⟩ : UInt256) by decide, - show ((⟨548⟩ : UInt256) + ⟨32⟩) = (⟨580⟩ : UInt256) by decide, - show ((⟨580⟩ : UInt256) + ⟨224⟩) = (⟨804⟩ : UInt256) by decide] - using rd3142⟩ - -set_option maxRecDepth 10000 in -theorem attesterX_attestToExternalCall {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨140⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1804⟩ : UInt256) - [attesterAttestTargetWord v, ⟨0⟩, ⟨448⟩, ⟨356⟩, ⟨448⟩, ⟨32⟩, - ⟨804⟩, ⟨0xf17325e7⟩, attesterAttestTargetWord v, ⟨0⟩, - attesterAttestInputWord I, attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - (attesterAttestCallMem I) (UInt256.ofNat 27) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd3142⟩ := - attesterX_attestEncodeTuple (v := v) hsz68 hsize hsmall hreach - have rd1804 := evm_run rd3142 with [ - raw jumpdest (by attester_decode_at v, ⟨3142⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap5 (by attester_decode_at v, ⟨3143⟩, 0x94, .SWAP5) (by evm_ov), - raw swap4 (by attester_decode_at v, ⟨3144⟩, 0x93, .SWAP4) (by evm_ov), - raw pop (by attester_decode_at v, ⟨3145⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨3146⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨3147⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨3148⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨3149⟩, 0x56, .JUMP) - (attesterAttestCallDataEncodedJumpdest v) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨1792⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1793⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1795⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨448⟩ (UInt256.ofNat 27) - (by attester_decode_at v, ⟨1797⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestCallMem_size I]; decide) (by decide) - (attesterAttestCallMem_read64 I)) - (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1798⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1799⟩, 0x83, .DUP4) (by evm_ov), - raw sub (by attester_decode_at v, ⟨1800⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1801⟩, 0x81, .DUP2) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨1802⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup8 (by attester_decode_at v, ⟨1803⟩, 0x87, .DUP8) (by evm_ov)] - exact ⟨_, _, by - simpa [show UInt256.sub (⟨804⟩ : UInt256) ⟨448⟩ = (⟨356⟩ : UInt256) by decide] - using rd1804⟩ - -theorem attesterX_attestPostCall {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨140⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) - (hperm : I.perm = true) (hdepth : I.depth.val < 1024) : - ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) - (o : ByteArray) (A' : Substate) (k' C' : ℕ), - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1804⟩ + ⟨1⟩ + ⟨1⟩) - ((if z then ⟨1⟩ else ⟨0⟩) :: - ⟨804⟩ :: ⟨0xf17325e7⟩ :: attesterAttestTargetWord v :: ⟨0⟩ :: - attesterAttestInputWord I :: attesterAttestSchemaWord I :: ⟨159⟩ :: - solcSelectorWord I :: []) - (o.write 0 (attesterAttestCallMem I) 448 - (min (⟨32⟩ : UInt256) (UInt256.ofNat o.size)).toNat) - ⟨27⟩ o (cA', σ') k' C' - ∧ typedCallViaEVM (config v) (initState cA gh bl σ σ₀ g A I) - (EVM.address v.eas) "attest" 0 (attesterAttestArgVals I) - (z, { initState cA gh bl σ σ₀ g A I with - accountMap := σ', substate := A', createdAccounts := cA' }, o) true - ∧ o.size < UInt256.size := by - obtain ⟨_, _, rd1804⟩ := - attesterX_attestToExternalCall (v := v) hsz68 hsize hsmall hreach - obtain ⟨gv, rd1805⟩ := - rd1804.gas (by attester_decode_at v, ⟨1804⟩, 0x5a, .GAS) (by evm_ov) - obtain ⟨cA', σ', z, o, A_in, callGas, k', C', hTheta, rd1806, hosz⟩ := - rd1805.call (by attester_decode_at v, ⟨1805⟩, 0xf1, .CALL) hdepth (by evm_ov) - obtain ⟨g'', A', hΘ⟩ := hTheta - refine ⟨cA', σ', z, o, A', k', C', ?_, ?_, hosz⟩ - · have haw : - UInt256.ofNat (MachineState.M (MachineState.M (UInt256.ofNat 27).toNat - (⟨448⟩ : UInt256).toNat (⟨356⟩ : UInt256).toNat) - (⟨448⟩ : UInt256).toNat (⟨32⟩ : UInt256).toNat) = (⟨27⟩ : UInt256) := by - decide - exact haw ▸ rd1806 - · refine callCoincides (A_in := A_in) (g'' := g'') (callGas := callGas) - (callPerm := true) (targetWord := attesterAttestTargetWord v) - (mem := attesterAttestCallMem I) (inOff := ⟨448⟩) (inSize := ⟨356⟩) - (hdepth := fun h => absurd hdepth (by rw [show I.depth = (1024 : Fin 1025) from h]; decide)) - (htgt := attesterAttestTarget_eq v) (hcd := ?_) (hΘ := ?_) - · rw [show (⟨448⟩ : UInt256).toNat = 448 by decide, - show (⟨356⟩ : UInt256).toNat = 356 by decide, - attesterAttestCallMem_read448_356] - exact attesterEncodeAttest_eq v hsz68 - · simpa [initState, hperm] using hΘ - -theorem attesterX_attestPostRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {k C : ℕ} {rest : List UInt256} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1804⟩ + ⟨1⟩ + ⟨1⟩) (⟨0⟩ :: rest) mem aw rdata acc k C) - (hov : rest.length + 4 ≤ 1024) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have rd1813 : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1804⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩) - (UInt256.isZero ⟨0⟩ :: rest) mem aw rdata acc _ _ := - evm_run rd with [ - raw iszero (by attester_decode_at v, ⟨1806⟩, 0x15, .ISZERO) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1807⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨1808⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨1820⟩ (by attester_decode_at v, ⟨1809⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨1812⟩, 0x57, .JUMPI) (by decide) - (by evm_ov)] - have rd1814 := RD.returndatasize rd1813 - (by - rw [show (⟨1804⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩) - = (⟨1813⟩ : UInt256) by decide] - attester_decode_at v, ⟨1813⟩, 0x3d, .RETURNDATASIZE) - (by simp only [List.length_cons]; omega) - have rd1815 := RD.push0 rd1814 - (by - rw [show (⟨1804⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩ + ⟨1⟩) - = (⟨1814⟩ : UInt256) by decide] - attester_decode_at v, ⟨1814⟩, 0x5f, .PUSH0) - (by simp only [List.length_cons]; omega) - have rd1816 := RD.dup1 rd1815 - (by - rw [show (⟨1804⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) - = (⟨1815⟩ : UInt256) by decide] - attester_decode_at v, ⟨1815⟩, 0x80, .DUP1) - (by simp only [List.length_cons]; omega) - have rd1817 : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1804⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩ + - ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) - (UInt256.isZero ⟨0⟩ :: rest) - (rdata.write 0 mem 0 (UInt256.ofNat rdata.size).toNat) - (UInt256.ofNat (MachineState.M aw.toNat 0 (UInt256.ofNat rdata.size).toNat)) - rdata acc _ _ := - RD.returndatacopy - (Cₘ (UInt256.ofNat (MachineState.M aw.toNat 0 (UInt256.ofNat rdata.size).toNat)) - Cₘ aw) - (rdata.write 0 mem 0 (UInt256.ofNat rdata.size).toNat) - (UInt256.ofNat (MachineState.M aw.toNat 0 (UInt256.ofNat rdata.size).toNat)) - rd1816 - (by - rw [show (⟨1804⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) - = (⟨1816⟩ : UInt256) by decide] - attester_decode_at v, ⟨1816⟩, 0x3e, .RETURNDATACOPY) - (by - rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, Nat.zero_add] - rw [show (UInt256.ofNat rdata.size).toNat = rdata.size % UInt256.size from rfl] - exact Nat.mod_le _ _) - (by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', hstks, haws, - List.getElem!_cons_zero, List.getElem!_cons_succ, - show (⟨0⟩ : UInt256).toNat = 0 from rfl]) - rfl rfl (by simp only [List.length_cons]; omega) - have rd1818 := RD.returndatasize rd1817 - (by - rw [show (⟨1804⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) - = (⟨1817⟩ : UInt256) by decide] - attester_decode_at v, ⟨1817⟩, 0x3d, .RETURNDATASIZE) - (by simp only [List.length_cons]; omega) - have rd1819 := RD.push0 rd1818 - (by - rw [show (⟨1804⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) - = (⟨1818⟩ : UInt256) by decide] - attester_decode_at v, ⟨1818⟩, 0x5f, .PUSH0) - (by simp only [List.length_cons]; omega) - exact RD.rev _ rd1819 - (by - rw [show (⟨1804⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) - = (⟨1819⟩ : UInt256) by decide] - attester_decode_at v, ⟨1819⟩, 0xfd, .REVERT) - (fun s haws hstks => by rw [memExpRevertZeroOff s hstks, haws]) - (by simp only [List.length_cons]; omega) - -theorem attesterX_attestCallDepthLimit {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsz68 : 68 ≤ I.calldata.size) (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = true) - (hdepth : I.depth = 1024) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd1804⟩ := - attesterX_attestToExternalCall (v := v) hsz68 hsize hsmall - (attesterX_attestWrapper (g := g) v hcode hwv hsz4 hsize - hmultiRevoke hmultiAttest hattest) - obtain ⟨_, rd1805⟩ := - rd1804.gas (by attester_decode_at v, ⟨1804⟩, 0x5a, .GAS) (by evm_ov) - obtain ⟨_, _, rd1806⟩ := - rd1805.callDepthLimit (by attester_decode_at v, ⟨1805⟩, 0xf1, .CALL) - hdepth (by evm_ov) - exact attesterX_attestPostRevert (v := v) rd1806 (by simp) - -theorem attesterX_attestCallSuccessToReturnDecodeMem {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem o : ByteArray} {k C : ℕ} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1804⟩ + ⟨1⟩ + ⟨1⟩) - [⟨1⟩, ⟨804⟩, ⟨0xf17325e7⟩, attesterAttestTargetWord v, ⟨0⟩, - attesterAttestInputWord I, attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - mem ⟨27⟩ o acc k C) - (hfp : (if (⟨64⟩ : UInt256).toNat ≥ mem.size ∨ - (⟨64⟩ : UInt256) ≥ ⟨27⟩ * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (mem.readWithPadding (⟨64⟩ : UInt256).toNat 32))) = ⟨448⟩) : - ∃ k' C', RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) ⟨3150⟩ - [⟨448⟩, UInt256.add ⟨448⟩ (UInt256.ofNat o.size), ⟨1856⟩, ⟨0⟩, - attesterAttestInputWord I, attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - ((UInt256.toByteArray (attesterAttestReturnDecodeFreePtr o)).write 0 mem 64 32) - ⟨27⟩ o acc k' C' := by - have rd1828 := evm_run rd with [ - raw iszero (by attester_decode_at v, ⟨1806⟩, 0x15, .ISZERO) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1807⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨1808⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨1820⟩ (by attester_decode_at v, ⟨1809⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨1812⟩, 0x57, .JUMPI) (by decide) - (attesterAttestCallOkJumpdest v) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨1820⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1821⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1822⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1823⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1824⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1825⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨448⟩ ⟨27⟩ (by attester_decode_at v, ⟨1827⟩, 0x51, .MLOAD) - mem_cost hfp (by decide) (by evm_ov)] - refine ⟨_, _, by - simpa [attesterAttestReturnDecodeFreePtr] using evm_run rd1828 with [ - raw returndatasize (by attester_decode_at v, ⟨1828⟩, 0x3d, .RETURNDATASIZE) - (by evm_ov), - raw push1 ⟨31⟩ (by attester_decode_at v, ⟨1829⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw not (by attester_decode_at v, ⟨1831⟩, 0x19, .NOT) (by evm_ov), - raw push1 ⟨31⟩ (by attester_decode_at v, ⟨1832⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1834⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨1835⟩, 0x01, .ADD) (by evm_ov), - raw and (by attester_decode_at v, ⟨1836⟩, 0x16, .AND) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1837⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨1838⟩, 0x01, .ADD) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1839⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1840⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw mstore 0 ((UInt256.toByteArray (attesterAttestReturnDecodeFreePtr o)).write 0 mem 64 32) - ⟨27⟩ (by attester_decode_at v, ⟨1842⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1843⟩, 0x50, .POP) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1844⟩, 0x81, .DUP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨1845⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1846⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨1856⟩ (by attester_decode_at v, ⟨1847⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨1850⟩, 0x91, .SWAP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1851⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨3150⟩ (by attester_decode_at v, ⟨1852⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jump (by attester_decode_at v, ⟨1855⟩, 0x56, .JUMP) - (attesterAttestReturnDecodeJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_attestCallSuccessToReturnDecode {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {o : ByteArray} {k C : ℕ} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1804⟩ + ⟨1⟩ + ⟨1⟩) - [⟨1⟩, ⟨804⟩, ⟨0xf17325e7⟩, attesterAttestTargetWord v, ⟨0⟩, - attesterAttestInputWord I, attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - (o.write 0 (attesterAttestCallMem I) 448 32) ⟨27⟩ o acc k C) - (ho32 : 32 ≤ o.size) : - ∃ k' C', RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) ⟨3150⟩ - [⟨448⟩, UInt256.add ⟨448⟩ (UInt256.ofNat o.size), ⟨1856⟩, ⟨0⟩, - attesterAttestInputWord I, attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - (attesterAttestReturnDecodeMem I o) ⟨27⟩ o acc k' C' := by - have hfp : - (if (⟨64⟩ : UInt256).toNat ≥ (o.write 0 (attesterAttestCallMem I) 448 32).size ∨ - (⟨64⟩ : UInt256) ≥ ⟨27⟩ * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat (fromByteArrayBigEndian - ((o.write 0 (attesterAttestCallMem I) 448 32).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨448⟩ := - mloadWordValue_of_readWithPadding - (by rw [attesterAttestReturnWrite_size I o ho32]; decide) - (by decide) - (by simpa using attesterAttestReturnWrite_read64 I o ho32) - obtain ⟨k', C', rd3150⟩ := attesterX_attestCallSuccessToReturnDecodeMem - (v := v) rd hfp - exact ⟨k', C', by simpa [attesterAttestReturnDecodeMem] using rd3150⟩ - -theorem attesterX_attestReturnDecodeOk {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {o : ByteArray} {k C : ℕ} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) ⟨3150⟩ - [⟨448⟩, UInt256.add ⟨448⟩ (UInt256.ofNat o.size), ⟨1856⟩, ⟨0⟩, - attesterAttestInputWord I, attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - (attesterAttestReturnDecodeMem I o) ⟨27⟩ o acc k C) - (ho32 : 32 ≤ o.size) (ho255 : o.size < 2 ^ 255) : - ∃ k' C', RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) ⟨1856⟩ - [uInt256OfByteArray (o.extract 0 32), ⟨0⟩, attesterAttestInputWord I, - attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - (attesterAttestReturnDecodeMem I o) ⟨27⟩ o acc k' C' := by - refine ⟨_, _, evm_run rd with [ - raw jumpdest (by attester_decode_at v, ⟨3150⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨3151⟩, 0x5f, .PUSH0) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨3152⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨3154⟩, 0x82, .DUP3) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨3155⟩, 0x84, .DUP5) (by evm_ov), - raw sub (by attester_decode_at v, ⟨3156⟩, 0x03, .SUB) (by evm_ov), - raw slt (by attester_decode_at v, ⟨3157⟩, 0x12, .SLT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨3158⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨3166⟩ (by attester_decode_at v, ⟨3159⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨3162⟩, 0x57, .JUMPI) - (by rw [solcDecodeEndLenCheckOk_448_32 ho32 ho255]; decide) - (attesterAttestReturnDecodeOkJumpdest v) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨3166⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨3167⟩, 0x50, .POP) (by evm_ov), - raw mload 0 (uInt256OfByteArray (o.extract 0 32)) ⟨27⟩ - (by attester_decode_at v, ⟨3168⟩, 0x51, .MLOAD) mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterAttestReturnDecodeMem_size I o ho32]; decide) - (by decide) - (attesterAttestReturnDecodeMem_read448_word I o ho32)) - (by decide) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨3169⟩, 0x91, .SWAP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨3170⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨3171⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨3172⟩, 0x56, .JUMP) - (attesterAttestAfterReturnDecodeJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_attestReturnDecodeShortReverts {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem o : ByteArray} {aw : UInt256} {k C : ℕ} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) ⟨3150⟩ - [⟨448⟩, UInt256.add ⟨448⟩ (UInt256.ofNat o.size), ⟨1856⟩, ⟨0⟩, - attesterAttestInputWord I, attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - mem aw o acc k C) - (ho : o.size < 32) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - exact evm_run rd with [ - raw jumpdest (by attester_decode_at v, ⟨3150⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨3151⟩, 0x5f, .PUSH0) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨3152⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨3154⟩, 0x82, .DUP3) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨3155⟩, 0x84, .DUP5) (by evm_ov), - raw sub (by attester_decode_at v, ⟨3156⟩, 0x03, .SUB) (by evm_ov), - raw slt (by attester_decode_at v, ⟨3157⟩, 0x12, .SLT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨3158⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨3166⟩ (by attester_decode_at v, ⟨3159⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨3162⟩, 0x57, .JUMPI) - (by rw [solcDecodeEndLenCheckShort_448_32 ho]; decide) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨3163⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨3164⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨3165⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_attestReturnDecodeHugeReverts {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem o : ByteArray} {aw : UInt256} {k C : ℕ} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) ⟨3150⟩ - [⟨448⟩, UInt256.add ⟨448⟩ (UInt256.ofNat o.size), ⟨1856⟩, ⟨0⟩, - attesterAttestInputWord I, attesterAttestSchemaWord I, ⟨159⟩, solcSelectorWord I] - mem aw o acc k C) - (hhi : 2 ^ 255 ≤ o.size) (hlo : o.size < UInt256.size) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - exact evm_run rd with [ - raw jumpdest (by attester_decode_at v, ⟨3150⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨3151⟩, 0x5f, .PUSH0) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨3152⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨3154⟩, 0x82, .DUP3) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨3155⟩, 0x84, .DUP5) (by evm_ov), - raw sub (by attester_decode_at v, ⟨3156⟩, 0x03, .SUB) (by evm_ov), - raw slt (by attester_decode_at v, ⟨3157⟩, 0x12, .SLT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨3158⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨3166⟩ (by attester_decode_at v, ⟨3159⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨3162⟩, 0x57, .JUMPI) - (by rw [solcDecodeEndLenCheckHuge_448_32 hhi hlo]; decide) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨3163⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨3164⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨3165⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -noncomputable def attesterAttestPublicReturnMem (I : ExecutionEnv) (o : ByteArray) - (uid : UInt256) : ByteArray := - attesterWriteWord (attesterAttestReturnDecodeMem I o) - (attesterAttestReturnDecodeFreePtr o).toNat uid - -def attesterAttestPublicReturnAw (o : ByteArray) : UInt256 := - UInt256.ofNat (MachineState.M (⟨27⟩ : UInt256).toNat - (attesterAttestReturnDecodeFreePtr o).toNat 32) - -def attesterAttestPublicReturnAwAfterMload (o : ByteArray) : UInt256 := - UInt256.ofNat (MachineState.M (attesterAttestPublicReturnAw o).toNat - (⟨64⟩ : UInt256).toNat 32) - -theorem attesterAttestPublicReturnMem_size (I : ExecutionEnv) (o : ByteArray) - (uid : UInt256) (ho32 : 32 ≤ o.size) : - (attesterAttestPublicReturnMem I o uid).size = - max 836 ((attesterAttestReturnDecodeFreePtr o).toNat + 32) := by - unfold attesterAttestPublicReturnMem - rw [attesterWriteWord_size_eq_max_nat, attesterAttestReturnDecodeMem_size I o ho32] - -theorem attesterAttestPublicReturnMem_read64 (I : ExecutionEnv) (o : ByteArray) - (uid : UInt256) (ho32 : 32 ≤ o.size) (ho255 : o.size < 2 ^ 255) : - (attesterAttestPublicReturnMem I o uid).readWithPadding 64 32 = - UInt256.toByteArray (attesterAttestReturnDecodeFreePtr o) := by - unfold attesterAttestPublicReturnMem - rw [attesterWriteWord_read_below_len_nat] - · exact attesterAttestReturnDecodeMem_read64 I o ho32 - · rw [attesterAttestReturnDecodeMem_size I o ho32] - norm_num - · exact le_trans (by norm_num : 64 + 32 ≤ 448) - (attesterAttestReturnDecodeFreePtr_ge448 o ho255) - · norm_num - · norm_num - -theorem attesterAttestPublicReturnMem_readUid (I : ExecutionEnv) (o : ByteArray) - (uid : UInt256) : - (attesterAttestPublicReturnMem I o uid).readWithPadding - (attesterAttestReturnDecodeFreePtr o).toNat 32 = - UInt256.toByteArray uid := by - unfold attesterAttestPublicReturnMem - exact attesterWriteWord_read_back_nat _ _ _ - -theorem attesterAttestReturnDecodeMem_mload64 (I : ExecutionEnv) (o : ByteArray) - (ho32 : 32 ≤ o.size) : - (if (⟨64⟩ : UInt256).toNat ≥ (attesterAttestReturnDecodeMem I o).size ∨ - (⟨64⟩ : UInt256) ≥ ⟨27⟩ * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((attesterAttestReturnDecodeMem I o).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - attesterAttestReturnDecodeFreePtr o := by - exact mloadWordValue_of_readWithPadding - (by rw [attesterAttestReturnDecodeMem_size I o ho32]; decide) - (by decide) - (by simpa using attesterAttestReturnDecodeMem_read64 I o ho32) - -private theorem attesterAttestPublicReturnAw_toNat (o : ByteArray) - (ho255 : o.size < 2 ^ 255) : - (attesterAttestPublicReturnAw o).toNat = - MachineState.M 27 (attesterAttestReturnDecodeFreePtr o).toNat 32 := by - unfold attesterAttestPublicReturnAw - exact ulit_toNat' _ (by - simp [MachineState.M] - have hfp := attesterAttestReturnDecodeFreePtr_add63_lt o ho255 - have hdivle : - ((attesterAttestReturnDecodeFreePtr o).toNat + 32 + 31) / 32 - ≤ (attesterAttestReturnDecodeFreePtr o).toNat + 32 + 31 := - Nat.div_le_self _ _ - constructor - · rw [show (⟨27⟩ : UInt256).toNat = 27 by decide] - norm_num [UInt256.size] - · omega) - -private theorem attesterAttestPublicReturnAw_ge27 (o : ByteArray) - (ho255 : o.size < 2 ^ 255) : - 27 ≤ (attesterAttestPublicReturnAw o).toNat := by - rw [attesterAttestPublicReturnAw_toNat o ho255] - simp [MachineState.M] - -private theorem attesterAttestPublicReturnAw_mul32_toNat (o : ByteArray) - (ho255 : o.size < 2 ^ 255) : - (attesterAttestPublicReturnAw o * (⟨32⟩ : UInt256)).toNat = - (attesterAttestPublicReturnAw o).toNat * 32 := by - apply umul_toNat - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - rw [attesterAttestPublicReturnAw_toNat o ho255] - simp [MachineState.M] - have hfp := attesterAttestReturnDecodeFreePtr_add63_lt o ho255 - have hdiv : ((attesterAttestReturnDecodeFreePtr o).toNat + 32 + 31) / 32 * 32 - ≤ (attesterAttestReturnDecodeFreePtr o).toNat + 32 + 31 := - Nat.div_mul_le_self _ _ - by_cases hle : 27 ≤ ((attesterAttestReturnDecodeFreePtr o).toNat + 32 + 31) / 32 - · rw [max_eq_right hle] - omega - · rw [max_eq_left (by omega)] - norm_num [UInt256.size] - -private theorem attesterAttestPublicReturnAw_mload64 (o : ByteArray) - (ho255 : o.size < 2 ^ 255) : - ¬ (⟨64⟩ : UInt256) ≥ attesterAttestPublicReturnAw o * ⟨32⟩ := by - intro h - have hle : (attesterAttestPublicReturnAw o * (⟨32⟩ : UInt256)).toNat ≤ 64 := by - exact h - rw [attesterAttestPublicReturnAw_mul32_toNat o ho255] at hle - have hge := attesterAttestPublicReturnAw_ge27 o ho255 - omega - -theorem attesterAttestPublicReturnMem_mload64 (I : ExecutionEnv) (o : ByteArray) - (uid : UInt256) (ho32 : 32 ≤ o.size) (ho255 : o.size < 2 ^ 255) : - (if (⟨64⟩ : UInt256).toNat ≥ (attesterAttestPublicReturnMem I o uid).size ∨ - (⟨64⟩ : UInt256) ≥ attesterAttestPublicReturnAw o * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((attesterAttestPublicReturnMem I o uid).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - attesterAttestReturnDecodeFreePtr o := by - exact mloadWordValue_of_readWithPadding - (by - rw [attesterAttestPublicReturnMem_size I o uid ho32] - rw [show (⟨64⟩ : UInt256).toNat = 64 by decide] - exact lt_of_lt_of_le (by norm_num : 64 < 836) - (le_max_left _ _)) - (attesterAttestPublicReturnAw_mload64 o ho255) - (by simpa using attesterAttestPublicReturnMem_read64 I o uid ho32 ho255) - -theorem attesterX_attestPublicReturnWith {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {o : ByteArray} {uid : UInt256} {k C : ℕ} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) ⟨1856⟩ - [uid, ⟨0⟩, attesterAttestInputWord I, attesterAttestSchemaWord I, ⟨159⟩, - solcSelectorWord I] - (attesterAttestReturnDecodeMem I o) ⟨27⟩ o acc k C) - (hmload64 : - (if (⟨64⟩ : UInt256).toNat ≥ (attesterAttestReturnDecodeMem I o).size ∨ - (⟨64⟩ : UInt256) ≥ ⟨27⟩ * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((attesterAttestReturnDecodeMem I o).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - attesterAttestReturnDecodeFreePtr o) - (hmemoutLoad64 : - (if (⟨64⟩ : UInt256).toNat ≥ (attesterAttestPublicReturnMem I o uid).size ∨ - (⟨64⟩ : UInt256) ≥ attesterAttestPublicReturnAw o * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((attesterAttestPublicReturnMem I o uid).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - attesterAttestReturnDecodeFreePtr o) - (hsub : - UInt256.sub (UInt256.add ⟨32⟩ (attesterAttestReturnDecodeFreePtr o)) - (attesterAttestReturnDecodeFreePtr o) = ⟨32⟩) - (hread : - (attesterAttestPublicReturnMem I o uid).readWithPadding - (attesterAttestReturnDecodeFreePtr o).toNat 32 = - UInt256.toByteArray uid) : - RDret (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) acc - (UInt256.toByteArray uid) := by - have rd159 : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) ⟨159⟩ - [uid, solcSelectorWord I] (attesterAttestReturnDecodeMem I o) ⟨27⟩ o acc _ _ := - evm_run rd with [ - raw jumpdest (by attester_decode_at v, ⟨1856⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap4 (by attester_decode_at v, ⟨1857⟩, 0x93, .SWAP4) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨1858⟩, 0x92, .SWAP3) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1859⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1860⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1861⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨1862⟩, 0x56, .JUMP) - (attesterAttestPublicReturnJumpdest v) (by evm_ov)] - exact evm_run rd159 with [ - raw jumpdest (by attester_decode_at v, ⟨159⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨160⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw mload 0 (attesterAttestReturnDecodeFreePtr o) ⟨27⟩ - (by attester_decode_at v, ⟨162⟩, 0x51, .MLOAD) mem_cost hmload64 - (by decide) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨163⟩, 0x90, .SWAP1) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨164⟩, 0x81, .DUP2) (by evm_ov), - raw mstore - (Cₘ (attesterAttestPublicReturnAw o) - Cₘ (⟨27⟩ : UInt256)) - (attesterAttestPublicReturnMem I o uid) (attesterAttestPublicReturnAw o) - (by attester_decode_at v, ⟨165⟩, 0x52, .MSTORE) - (by - intro s haw hstk - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, - List.getElem!_cons_zero, List.getElem!_cons_succ, - attesterAttestPublicReturnAw]) - (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨166⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw add (by attester_decode_at v, ⟨168⟩, 0x01, .ADD) (by evm_ov), - raw push2 ⟨131⟩ (by attester_decode_at v, ⟨169⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jump (by attester_decode_at v, ⟨172⟩, 0x56, .JUMP) - (attesterAttestFinalReturnJumpdest v) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨131⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨132⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw mload - (Cₘ (attesterAttestPublicReturnAwAfterMload o) - - Cₘ (attesterAttestPublicReturnAw o)) - (attesterAttestReturnDecodeFreePtr o) (attesterAttestPublicReturnAwAfterMload o) - (by attester_decode_at v, ⟨134⟩, 0x51, .MLOAD) - (by - intro s haw hstk - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, - List.getElem!_cons_zero, List.getElem!_cons_succ, - attesterAttestPublicReturnAwAfterMload]) - hmemoutLoad64 (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨135⟩, 0x80, .DUP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨136⟩, 0x91, .SWAP2) (by evm_ov), - raw sub (by attester_decode_at v, ⟨137⟩, 0x03, .SUB) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨138⟩, 0x90, .SWAP1) (by evm_ov), - raw ret - (Cₘ (UInt256.ofNat (MachineState.M (attesterAttestPublicReturnAwAfterMload o).toNat - (attesterAttestReturnDecodeFreePtr o).toNat - (UInt256.sub (UInt256.add ⟨32⟩ (attesterAttestReturnDecodeFreePtr o)) - (attesterAttestReturnDecodeFreePtr o)).toNat)) - - Cₘ (attesterAttestPublicReturnAwAfterMload o)) - (UInt256.toByteArray uid) - (by attester_decode_at v, ⟨139⟩, 0xf3, .RETURN) - (by - intro s haw hstk - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haw, hstk, - List.getElem!_cons_zero, List.getElem!_cons_succ] - rfl) - (by - change (attesterAttestPublicReturnMem I o uid).readWithPadding - (attesterAttestReturnDecodeFreePtr o).toNat - (UInt256.sub (UInt256.add ⟨32⟩ (attesterAttestReturnDecodeFreePtr o)) - (attesterAttestReturnDecodeFreePtr o)).toNat = - UInt256.toByteArray uid - rw [hsub] - exact hread) - (by evm_ov)] - -theorem attesterAttestBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (v : AttesterImmutables) {code : ByteArray} - (hpatch : patchRuntime attesterBytecode (patches v) = some code) - (hcode : I.code = code) - (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) - (hwv : I.weiValue = ⟨0⟩) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hpatched : code = patchedRuntime v := code_eq_patchedRuntime_of_patch hpatch - have hIcode : I.code = patchedRuntime v := hcode.trans hpatched - have hsz4 : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I attesterAttestSelBytes attesterAttestSelBytes_size hattest - have hd := attesterDispatch_attest v hattest - by_cases hsz68 : 68 ≤ I.calldata.size - · by_cases hsmall : I.calldata.size < 2 ^ 255 + 4 - · let gS : Sat256 := Sat256.ofUInt256 g - let evmEvm : EVM.State := initState cA gh bl σ_evm σ₀ gS A I - let evmSolm : EVM.State := initState cA gh bl σ_solm σ₀ gS A I - have hdec := attesterDecode_attest_ok v hsz68 hsmall - have hwvSolm : evmSolm.executionEnv.weiValue = ⟨0⟩ := by - simp [evmSolm, initState, hwv] - have hargsSolm : - evalExprs? (config v) - { contract := contract v, locals := attesterAttestStore I } evmSolm - [attestationRequest (.var "schema") (.var "input")] = - .ok (attesterAttestArgVals I) := - attesterEvalAttestArgs v evmSolm I - by_cases hdepth : I.depth.val < 1024 - · have hreach := - attesterX_attestWrapper (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := gS) v hIcode hwv hsz4 hsize - hmultiRevoke hmultiAttest hattest - obtain ⟨cA', σ', z, o, A', k', C', rd1806, hcallEvm, hosize⟩ := - attesterX_attestPostCall (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := gS) v hsz68 hsize hsmall hreach - hperm hdepth - let evmPostEvm : EVM.State := - { evmEvm with accountMap := σ', substate := A', createdAccounts := cA' } - have hcallEvm' : - typedCallViaEVM (config v) evmEvm (EVM.address v.eas) "attest" 0 - (attesterAttestArgVals I) (z, evmPostEvm, o) true := by - simpa [evmEvm, evmPostEvm] using hcallEvm - obtain ⟨σSolmPost, ASolmPost, hcallSolm, hStateCall⟩ := - typedCallViaEVM_initState_EVMStateEquiv (hcall := hcallEvm') - (by simp [evmEvm, evmSolm, evmPostEvm, initState]) hAccounts - let evmPostSolm : EVM.State := - { evmSolm with accountMap := σSolmPost, substate := ASolmPost, createdAccounts := cA' } - have hcallSolm' : - typedCallViaEVM (config v) evmSolm (EVM.address v.eas) "attest" 0 - (attesterAttestArgVals I) (z, evmPostSolm, o) true := by - simpa [evmPostSolm] using hcallSolm - have hStateCall' : EVMStateEquiv evmPostEvm evmPostSolm := by - simpa [evmPostSolm] using hStateCall - cases z - · simp only [Bool.false_eq_true, if_false] at rd1806 hcallSolm' - have hrdrev := attesterX_attestPostRevert (v := v) rd1806 (by simp) - have hbody := - attesterAttestBodyCallFailure v evmSolm evmPostSolm - (attesterAttestStore I) hwvSolm hargsSolm hcallSolm' - exact hrdrev.reEquivExecutionRevert hIcode hd hdec hbody - · simp only [Bool.true_eq_false, if_true] at rd1806 hcallSolm' - by_cases ho255 : o.size < 2 ^ 255 - · by_cases ho32 : 32 ≤ o.size - · rw [attesterAttestMin32_toNat_of_ge ho32 hosize] at rd1806 - obtain ⟨_, _, rd3150⟩ := - attesterX_attestCallSuccessToReturnDecode (v := v) rd1806 ho32 - obtain ⟨_, _, rd1856⟩ := - attesterX_attestReturnDecodeOk (v := v) rd3150 ho32 ho255 - have hrdret := - attesterX_attestPublicReturnWith (v := v) rd1856 - (attesterAttestReturnDecodeMem_mload64 I o ho32) - (attesterAttestPublicReturnMem_mload64 I o - (uInt256OfByteArray (o.extract 0 32)) ho32 ho255) - (attesterAttestReturnDecodeFreePtr_add32_sub o ho255) - (attesterAttestPublicReturnMem_readUid I o - (uInt256OfByteArray (o.extract 0 32))) - have hretdec := attesterDecode_attest_return_ok v ho32 ho255 - have hbody := - attesterAttestBodySuccess v evmSolm evmPostSolm - (attesterAttestStore I) hwvSolm hargsSolm hcallSolm' hretdec - have henc : - returnEquiv - (UInt256.toByteArray (uInt256OfByteArray (o.extract 0 32))) - (some [.fixedBytes bytes32Width - (EVM.Word.toBytesBE (uInt256OfByteArray (o.extract 0 32)))]) - (attestTransition v).returnType := by - simpa [attestTransition, bytes32, bytes32Width] using - returnEquiv_of_encode - (bytes32ReturnEncoding (uInt256OfByteArray (o.extract 0 32))) - exact hrdret.reEquivExecutionGenEVMStateEquiv hIcode hd hdec hbody - rfl (accountMapEquiv.refl σ') hStateCall' henc - · have ho32lt : o.size < 32 := by omega - rw [attesterAttestMin32_toNat_of_lt ho32lt] at rd1806 - have hfp := - attesterAttestReturnWrite_mload64_of_len I o - (by omega : o.size ≤ o.size) - (by omega : o.size ≤ 32) - obtain ⟨_, _, rd3150⟩ := - attesterX_attestCallSuccessToReturnDecodeMem (v := v) rd1806 hfp - have hrdrev := - attesterX_attestReturnDecodeShortReverts (v := v) rd3150 ho32lt - have hretdec := attesterDecode_attest_return_none_short v ho32lt - have hbody := - attesterAttestBodyDecodeRevert v evmSolm evmPostSolm - (attesterAttestStore I) hwvSolm hargsSolm hcallSolm' hretdec - exact hrdrev.reEquivExecutionRevert hIcode hd hdec hbody - · have hhi : 2 ^ 255 ≤ o.size := by omega - have ho32 : 32 ≤ o.size := by omega - rw [attesterAttestMin32_toNat_of_ge ho32 hosize] at rd1806 - obtain ⟨_, _, rd3150⟩ := - attesterX_attestCallSuccessToReturnDecode (v := v) rd1806 ho32 - have hrdrev := - attesterX_attestReturnDecodeHugeReverts (v := v) rd3150 hhi hosize - have hretdec := attesterDecode_attest_return_none_huge v hhi - have hbody := - attesterAttestBodyDecodeRevert v evmSolm evmPostSolm - (attesterAttestStore I) hwvSolm hargsSolm hcallSolm' hretdec - exact hrdrev.reEquivExecutionRevert hIcode hd hdec hbody - · have hdepth1024 : I.depth = 1024 := by - apply Fin.ext - have hlt := I.depth.isLt - rw [not_lt] at hdepth - omega - have hrdrev := - attesterX_attestCallDepthLimit (cA := cA) (gh := gh) (bl := bl) - (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) (g := gS) v hIcode hwv - hsz4 hsize hsz68 hsmall hmultiRevoke hmultiAttest hattest hdepth1024 - have hdepthInit : evmSolm.executionEnv.depth = 1024 := by - simpa [evmSolm, initState] using hdepth1024 - have hcallSolm : - typedCallViaEVM (config v) evmSolm (EVM.address v.eas) "attest" 0 - (attesterAttestArgVals I) - (false, - { evmSolm with - substate := (evmSolm.addAccessedAccount (EVM.address v.eas)).substate }, - ByteArray.empty) - true := - callNotMade_depthLimit - (cfg := config v) (evm := evmSolm) (tgt := EVM.address v.eas) - (name := "attest") (args := attesterAttestArgVals I) (callPerm := true) - (attesterEncodeAttest_eq v hsz68) hdepthInit - have hbody := - attesterAttestBodyCallFailure v evmSolm - ({ evmSolm with - substate := (evmSolm.addAccessedAccount (EVM.address v.eas)).substate }) - (attesterAttestStore I) hwvSolm hargsSolm hcallSolm - exact hrdrev.reEquivExecutionRevert hIcode hd hdec hbody - · have hbig : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - have hdec := attesterDecode_attest_none_huge v hbig - exact (attesterX_attestDecodeHuge (g := Sat256.ofUInt256 g) v hIcode hwv hsz4 hsize hbig - hmultiRevoke hmultiAttest hattest) - |>.reEquivDecodingFailed hIcode hd hdec - · have hshort : I.calldata.size < 68 := by omega - have hdec := attesterDecode_attest_none_short v hsz4 hshort - exact (attesterX_attestDecodeShort (g := Sat256.ofUInt256 g) v hIcode hwv hsz4 hsize hshort - hmultiRevoke hmultiAttest hattest) - |>.reEquivDecodingFailed hIcode hd hdec - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/Common.lean b/Benchmarks/EAS/Attester/Common.lean deleted file mode 100644 index e14934dc..00000000 --- a/Benchmarks/EAS/Attester/Common.lean +++ /dev/null @@ -1,1851 +0,0 @@ -import Benchmarks.EAS.Attester.Trusted -import Reasoning.Dispatch -import Reasoning.Initcode -import Reasoning.MemCascade -import Reasoning.Solc -import Reasoning.SolmBody -import Solm.Equiv - -/-! -# Shared Attester proof helpers --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -set_option maxRecDepth 10000 - -abbrev attesterFirstArmPc : UInt256 := ⟨30⟩ - -@[simp] theorem wordBytesBEArray_size (w : UInt256) : - ({ data := (EVM.Word.toBytesBE w).toArray } : ByteArray).size = 32 := by - simpa using word_toBytesBE_toByteArray_size w - -@[simp] theorem wordBytesBEArray_eq_toByteArray (w : UInt256) : - ({ data := (EVM.Word.toBytesBE w).toArray } : ByteArray) = UInt256.toByteArray w := by - apply ByteArray.ext - have h := congrArg ByteArray.data (word_toBytesBE_toByteArray_eq_toByteArray w) - simpa using h - -@[simp] theorem attesterBytecode_size : attesterBytecode.size = 3186 := by - native_decide +revert - -@[simp] theorem attesterCreationBytecode_size : attesterCreationBytecode.size = 3371 := by - native_decide +revert - -def runtimeWrites (v : AttesterImmutables) : List (Nat × UInt256) := - [ (722, EVM.Word.ofNat v.eas.toNat), - (1465, EVM.Word.ofNat v.eas.toNat), - (1598, EVM.Word.ofNat v.eas.toNat), - (1939, EVM.Word.ofNat v.eas.toNat) ] - -noncomputable def patchedRuntime (v : AttesterImmutables) : ByteArray := - writeCascade attesterBytecode (runtimeWrites v) - -theorem spliceBytes_toByteArray_eq_writeWord (mem : ByteArray) (off : Nat) (w : UInt256) - (h : off + 32 ≤ mem.size) : - spliceBytes? mem off (UInt256.toByteArray w) = some (writeWord mem off w) := by - unfold spliceBytes? Reasoning.Theory.writeWord - rw [toByteArray_size, if_pos h] - rw [write32_eq _ _ _ (by rw [toByteArray_size]) (by omega)] - rw [toByteArray_extract_all] - -theorem patchRuntime_eq_patchedRuntime (v : AttesterImmutables) : - patchRuntime attesterBytecode (patches v) = some (patchedRuntime v) := by - simp [patchedRuntime, patchRuntime, patches, patchesFrom, offsets, immValues, wordBytes?, - valueToWord, List.lookup_cons, runtimeWrites, writeCascade] - rw [spliceBytes_toByteArray_eq_writeWord attesterBytecode 722] - · simp - have hgap722 : 722 - attesterBytecode.size < USize.size := by - rw [attesterBytecode_size] - norm_num - have hsize722 : - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)).size = 3186 := by - rw [writeWord_size _ _ _ hgap722] - rw [attesterBytecode_size] - norm_num - have h1465 := spliceBytes_toByteArray_eq_writeWord - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat) - (by rw [hsize722]; norm_num) - cases hsp1465 : spliceBytes? - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (UInt256.toByteArray (EVM.Word.ofNat v.eas.toNat)) with - | none => - rw [hsp1465] at h1465 - cases h1465 - | some p1465 => - rw [hsp1465] at h1465 - cases h1465 - have hgap1465 : - 1465 - (writeWord attesterBytecode 722 - (EVM.Word.ofNat v.eas.toNat)).size < USize.size := by - rw [hsize722] - norm_num - have hsize1465 : - (writeWord - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)).size = 3186 := by - rw [writeWord_size _ _ _ hgap1465] - rw [hsize722] - norm_num - have h1598 := spliceBytes_toByteArray_eq_writeWord - (writeWord - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)) 1598 - (EVM.Word.ofNat v.eas.toNat) - (by rw [hsize1465]; norm_num) - cases hsp1598 : spliceBytes? - (writeWord - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)) 1598 - (UInt256.toByteArray (EVM.Word.ofNat v.eas.toNat)) with - | none => - rw [hsp1598] at h1598 - cases h1598 - | some p1598 => - rw [hsp1598] at h1598 - cases h1598 - have hgap1598 : - 1598 - (writeWord - (writeWord attesterBytecode 722 - (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)).size < USize.size := by - rw [hsize1465] - norm_num - have hsize1598 : - (writeWord - (writeWord - (writeWord attesterBytecode 722 - (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)) 1598 - (EVM.Word.ofNat v.eas.toNat)).size = 3186 := by - rw [writeWord_size _ _ _ hgap1598] - rw [hsize1465] - norm_num - have h1939 := spliceBytes_toByteArray_eq_writeWord - (writeWord - (writeWord - (writeWord attesterBytecode 722 - (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)) 1598 - (EVM.Word.ofNat v.eas.toNat)) 1939 - (EVM.Word.ofNat v.eas.toNat) - (by rw [hsize1598]; norm_num) - cases hsp1939 : spliceBytes? - (writeWord - (writeWord - (writeWord attesterBytecode 722 - (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)) 1598 - (EVM.Word.ofNat v.eas.toNat)) 1939 - (UInt256.toByteArray (EVM.Word.ofNat v.eas.toNat)) with - | none => - rw [hsp1939] at h1939 - cases h1939 - | some p1939 => - rw [hsp1939] at h1939 - cases h1939 - change - (spliceBytes? - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (UInt256.toByteArray (EVM.Word.ofNat v.eas.toNat))).bind - (fun init => - (spliceBytes? init 1598 - (UInt256.toByteArray (EVM.Word.ofNat v.eas.toNat))).bind - (fun init => - spliceBytes? init 1939 - (UInt256.toByteArray (EVM.Word.ofNat v.eas.toNat)))) = - some - (writeWord - (writeWord - (writeWord - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)) - 1598 (EVM.Word.ofNat v.eas.toNat)) - 1939 (EVM.Word.ofNat v.eas.toNat)) - rw [hsp1465] - simp only [Option.bind] - rw [hsp1598] - change - spliceBytes? - (writeWord - (writeWord - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)) - 1598 (EVM.Word.ofNat v.eas.toNat)) - 1939 (UInt256.toByteArray (EVM.Word.ofNat v.eas.toNat)) = - some - (writeWord - (writeWord - (writeWord - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)) - 1598 (EVM.Word.ofNat v.eas.toNat)) - 1939 (EVM.Word.ofNat v.eas.toNat)) - rw [hsp1939] - · rw [attesterBytecode_size] - norm_num - -theorem code_eq_patchedRuntime_of_patch {v : AttesterImmutables} {code : ByteArray} - (hcode : patchRuntime attesterBytecode (patches v) = some code) : - code = patchedRuntime v := by - rw [patchRuntime_eq_patchedRuntime] at hcode - cases hcode - rfl - -theorem patchedRuntime_size (v : AttesterImmutables) : (patchedRuntime v).size = 3186 := by - unfold patchedRuntime - exact writeCascade_size_of_base attesterBytecode (runtimeWrites v) (base := 3186) (out := 3186) - (by native_decide) (by simp [runtimeWrites, WriteGapsOk]) - (by simp [runtimeWrites, writeCascadeSize]) - -theorem writeCascade_extract_preserved_len - (mem : ByteArray) (writes : List (Nat × UInt256)) (read len : Nat) - (hwin : WindowDisjointFromWrites mem.size read len writes) - (hpos : 0 < len) (hlen64 : len < 2 ^ 64) - (hout : read + len ≤ (writeCascade mem writes).size) - (hin : read + len ≤ mem.size) : - (writeCascade mem writes).extract read (read + len) = - mem.extract read (read + len) := by - rw [← readWithPadding_eq_extract' (writeCascade mem writes) read len hpos hlen64 hout] - rw [← readWithPadding_eq_extract' mem read len hpos hlen64 hin] - exact writeCascade_read_preserved_len mem writes read len hwin hpos hlen64 - -theorem patchedRuntime_extract_preserved_len (v : AttesterImmutables) (read len : Nat) - (hwin : WindowDisjointFromWrites 3186 read len (runtimeWrites v)) - (hpos : 0 < len) (hlen64 : len < 2 ^ 64) (hin : read + len ≤ 3186) : - (patchedRuntime v).extract read (read + len) = - attesterBytecode.extract read (read + len) := by - unfold patchedRuntime - exact writeCascade_extract_preserved_len attesterBytecode (runtimeWrites v) read len - (by simpa [attesterBytecode_size] using hwin) hpos hlen64 - (by change read + len ≤ (patchedRuntime v).size; rw [patchedRuntime_size v]; exact hin) - (by rw [attesterBytecode_size]; exact hin) - -theorem patchedRuntime_extract'_preserved_len (v : AttesterImmutables) (read len : Nat) - (hwin : WindowDisjointFromWrites 3186 read len (runtimeWrites v)) - (hlen64 : read + len < 2 ^ 64) (hin : read + len ≤ 3186) : - (patchedRuntime v).extract' read (read + len) = - attesterBytecode.extract' read (read + len) := by - by_cases hpos : 0 < len - · unfold ByteArray.extract' - have hguard : (decide (read < 2 ^ 64) && decide (read + len < 2 ^ 64)) = true := by - rw [decide_eq_true (by omega : read < 2 ^ 64), decide_eq_true hlen64] - rfl - rw [if_pos hguard, if_pos hguard] - exact patchedRuntime_extract_preserved_len v read len hwin hpos (by omega) hin - · have hlen0 : len = 0 := by omega - subst hlen0 - simp [ByteArray.extract'] - -theorem get?_eq_of_extract_one (a b : ByteArray) (i : Nat) - (ha : i < a.size) (hb : i < b.size) - (h : a.extract i (i + 1) = b.extract i (i + 1)) : - a.get? i = b.get? i := by - unfold ByteArray.get? - simp only [dif_pos ha, dif_pos hb] - have h0 : (a.extract i (i + 1)).get? 0 = (b.extract i (i + 1)).get? 0 := by rw [h] - unfold ByteArray.get? at h0 - have hsa : 0 < (a.extract i (i + 1)).size := by rw [ByteArray.size_extract]; omega - have hsb : 0 < (b.extract i (i + 1)).size := by rw [ByteArray.size_extract]; omega - simp only [dif_pos hsa, dif_pos hsb] at h0 - have hla : (a.extract i (i + 1)).get 0 hsa = a.get i ha := by - change (a.extract i (i + 1))[0] = a[i] - simpa using ByteArray.get_extract (a := a) (start := i) (stop := i + 1) (i := 0) hsa - have hlb : (b.extract i (i + 1)).get 0 hsb = b.get i hb := by - change (b.extract i (i + 1))[0] = b[i] - simpa using ByteArray.get_extract (a := b) (start := i) (stop := i + 1) (i := 0) hsb - rw [hla, hlb] at h0 - exact h0 - -theorem patchedRuntime_get?_preserved (v : AttesterImmutables) (i : Nat) - (hwin : WindowDisjointFromWrites 3186 i 1 (runtimeWrites v)) (hi : i + 1 ≤ 3186) : - (patchedRuntime v).get? i = attesterBytecode.get? i := by - exact get?_eq_of_extract_one (patchedRuntime v) attesterBytecode i - (by rw [patchedRuntime_size v]; omega) - (by rw [attesterBytecode_size]; omega) - (patchedRuntime_extract_preserved_len v i 1 hwin (by norm_num) (by norm_num) hi) - -theorem decode_eq_of_get?_arg_eq (a b : ByteArray) (pc : UInt256) - (hget : a.get? pc.toNat = b.get? pc.toNat) - (harg : ∀ byte instr, - b.get? pc.toNat = some byte → parseInstr byte = some instr → - a.extract' (pc.toNat + 1) (pc.toNat + 1 + argOnNBytesOfInstr instr) = - b.extract' (pc.toNat + 1) (pc.toNat + 1 + argOnNBytesOfInstr instr)) : - decode a pc = decode b pc := by - unfold decode - rw [hget] - cases hb : b.get? pc.toNat with - | none => rfl - | some byte => - cases hi : parseInstr byte with - | none => simp [hi] - | some instr => - simp [hi] - by_cases hn : argOnNBytesOfInstr instr = 0 - · simp [hn] - · simp [hn] - rw [harg byte instr hb hi] - -theorem patchedRuntime_decode_preserved (v : AttesterImmutables) (pc : UInt256) - (hgetwin : WindowDisjointFromWrites 3186 pc.toNat 1 (runtimeWrites v)) - (hgethi : pc.toNat + 1 ≤ 3186) - (hargwin : ∀ byte instr, - attesterBytecode.get? pc.toNat = some byte → parseInstr byte = some instr → - WindowDisjointFromWrites 3186 (pc.toNat + 1) (argOnNBytesOfInstr instr) - (runtimeWrites v)) - (harghi : ∀ byte instr, - attesterBytecode.get? pc.toNat = some byte → parseInstr byte = some instr → - pc.toNat + 1 + argOnNBytesOfInstr instr ≤ 3186) : - decode (patchedRuntime v) pc = decode attesterBytecode pc := by - refine decode_eq_of_get?_arg_eq (patchedRuntime v) attesterBytecode pc - (patchedRuntime_get?_preserved v pc.toNat hgetwin hgethi) ?_ - intro byte instr hbyte hinstr - exact patchedRuntime_extract'_preserved_len v (pc.toNat + 1) (argOnNBytesOfInstr instr) - (hargwin byte instr hbyte hinstr) - (by have h := harghi byte instr hbyte hinstr; omega) - (harghi byte instr hbyte hinstr) - -theorem patchedRuntime_decode_preserved_of_parse (v : AttesterImmutables) (pc : UInt256) - (byte : UInt8) (instr : Operation) - (hbyte : attesterBytecode.get? pc.toNat = some byte) - (hinstr : parseInstr byte = some instr) - (hgetwin : WindowDisjointFromWrites 3186 pc.toNat 1 (runtimeWrites v)) - (hgethi : pc.toNat + 1 ≤ 3186) - (hargwin : - WindowDisjointFromWrites 3186 (pc.toNat + 1) (argOnNBytesOfInstr instr) - (runtimeWrites v)) - (harghi : pc.toNat + 1 + argOnNBytesOfInstr instr ≤ 3186) : - decode (patchedRuntime v) pc = decode attesterBytecode pc := by - refine patchedRuntime_decode_preserved v pc hgetwin hgethi ?_ ?_ - · intro byte' instr' hbyte' hinstr' - rw [hbyte] at hbyte' - cases hbyte' - rw [hinstr] at hinstr' - cases hinstr' - exact hargwin - · intro byte' instr' hbyte' hinstr' - rw [hbyte] at hbyte' - cases hbyte' - rw [hinstr] at hinstr' - cases hinstr' - exact harghi - -theorem attesterAccountAddress_ofNat_toNat (a : AccountAddress) : - AccountAddress.ofNat (↑a : Nat) = a := by - apply Fin.ext - unfold AccountAddress.ofNat - rw [Fin.val_ofNat] - exact Nat.mod_eq_of_lt a.isLt - -theorem attesterEvalAddrLit (cfg : Config) (frame : Frame) (evm : EVM.State) - (a : AccountAddress) : - evalExpr? cfg frame evm (addrLit a) = .ok (.address a) := by - simp only [addrLit, evalExpr?, EvalResult.bind, bind, pure, castValue?] - rw [if_neg] - · simp [EvalResult.ofOption, attesterAccountAddress_ofNat_toNat] - · exact not_lt.mpr (Int.natCast_nonneg (↑a : Nat)) - -theorem attesterEvalEasExpr (v : AttesterImmutables) (frame : Frame) (evm : EVM.State) : - evalExpr? (config v) frame evm (easExpr v) = .ok (.address v.eas) := by - exact attesterEvalAddrLit (config v) frame evm v.eas - -/-- Trusted jump-destination fact for the non-payable guard target in the patched runtime. -/ -axiom attesterGuardJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨15⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the dispatch no-match/short-calldata revert target. -/ -axiom attesterDispatchRevertJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨74⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the `multiRevoke(bytes32[],bytes32[][])` wrapper entry. -/ -axiom attesterMultiRevokeWrapperJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨78⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the post-decode `multiRevoke(bytes32[],bytes32[][])` wrapper block. -/ -axiom attesterMultiRevokeDecodedJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨92⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the `multiRevoke(bytes32[],bytes32[][])` function body entry. -/ -axiom attesterMultiRevokeBodyJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨192⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the `multiAttest(bytes32[],uint256[][])` wrapper entry. -/ -axiom attesterMultiAttestWrapperJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨99⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the post-decode `multiAttest(bytes32[],uint256[][])` wrapper block. -/ -axiom attesterMultiAttestDecodedJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨113⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the `multiAttest(bytes32[],uint256[][])` function body entry. -/ -axiom attesterMultiAttestBodyJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨828⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the shared two-dynamic-argument ABI decoder. -/ -axiom attesterDynamic2DecoderJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2109⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the successful first length check in the shared dynamic decoder. -/ -axiom attesterDynamic2DecodeHeadOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2128⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the successful first offset check in the shared dynamic decoder. -/ -axiom attesterDynamic2FirstOffsetOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2149⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the shared dynamic-array decoder routine. -/ -axiom attesterDynamicArrayDecoderJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2038⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the `attest(bytes32,uint256)` wrapper entry. -/ -axiom attesterAttestWrapperJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨140⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the `attest(bytes32,uint256)` ABI decoder. -/ -axiom attesterAttestDecoderJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2281⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the successful `attest(bytes32,uint256)` decode branch. -/ -axiom attesterAttestDecodeOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2298⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the post-decode `attest(bytes32,uint256)` wrapper block. -/ -axiom attesterAttestDecodedJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨154⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the `attest(bytes32,uint256)` function body entry. -/ -axiom attesterAttestBodyJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨1595⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the `attest(bytes32,uint256)` ABI encoder return. -/ -axiom attesterAttestEncodeTailJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨1737⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the `attest(bytes32,uint256)` calldata-encoded block. -/ -axiom attesterAttestCallDataEncodedJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨1792⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the shared `AttestationRequest` ABI encoder entry. -/ -axiom attesterAttestEncodeRequestJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨3106⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the shared `AttestationRequestData` tuple encoder entry. -/ -axiom attesterAttestEncodeTupleJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2604⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the shared `AttestationRequestData` tuple encoder return. -/ -axiom attesterAttestEncodeTupleReturnJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨3142⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the successful external `attest` call branch. -/ -axiom attesterAttestCallOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨1820⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the external `attest` return decoder entry. -/ -axiom attesterAttestReturnDecodeJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨3150⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the successful external `attest` return decoder branch. -/ -axiom attesterAttestReturnDecodeOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨3166⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the post-return-decoder `attest(bytes32,uint256)` body block. -/ -axiom attesterAttestAfterReturnDecodeJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨1856⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the shared public one-word return wrapper. -/ -axiom attesterAttestPublicReturnJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨159⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the final `RETURN` block of the public wrapper. -/ -axiom attesterAttestFinalReturnJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨131⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the `revoke(bytes32,bytes32)` wrapper entry. -/ -axiom attesterRevokeWrapperJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨173⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the post-decode `revoke(bytes32,bytes32)` wrapper block. -/ -axiom attesterRevokeDecodedJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨187⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the `revoke(bytes32,bytes32)` function body entry. -/ -axiom attesterRevokeBodyJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨1863⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the successful external-code-size check in `revoke`. -/ -axiom attesterRevokeExtcodesizeOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2012⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the successful external `revoke` call branch. -/ -axiom attesterRevokeCallOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2030⟩ : UInt256) = true - -/-- Trusted jump-destination fact for public wrappers that finish without return data. -/ -axiom attesterNoReturnDoneJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨97⟩ : UInt256) = true - -theorem writeWord_size_of_inside (mem : ByteArray) (off : Nat) (word : UInt256) - (hinside : off + 32 ≤ mem.size) : - (Reasoning.Theory.writeWord mem off word).size = mem.size := by - have hgap : off - mem.size < USize.size := by - have hoff : off ≤ mem.size := by omega - rw [Nat.sub_eq_zero_of_le hoff] - exact lt_usize 0 (by norm_num) - rw [writeWord_size mem off word hgap] - exact max_eq_left hinside - -set_option maxHeartbeats 1000000 in -theorem decode_writeWord_below (mem : ByteArray) (off : Nat) (word : UInt256) - (pc : UInt256) - (hwin : pc.toNat + 33 ≤ off) - (hinside : off + 32 ≤ mem.size) - (hsize : mem.size < 2 ^ 64) : - decode (Reasoning.Theory.writeWord mem off word) pc = decode mem pc := by - have hwrite : - Reasoning.Theory.writeWord mem off word = - mem.extract 0 off ++ UInt256.toByteArray word ++ mem.extract (off + 32) mem.size := by - unfold Reasoning.Theory.writeWord - rw [write32_eq _ _ off (by rw [toByteArray_size]) (by omega)] - rw [toByteArray_extract_all] - have hprefixSize : (mem.extract 0 off).size = off := by - rw [ByteArray.size_extract] - omega - have hsplit : mem.extract 0 off ++ mem.extract off mem.size = mem := by - have h := (ByteArray.extract_append_extract (a := mem) (i := 0) (j := off) (k := mem.size)) - simpa [Nat.min_eq_left (Nat.zero_le off), Nat.max_eq_right (by omega), - ByteArray.extract_zero_size] using h - calc - decode (Reasoning.Theory.writeWord mem off word) pc = - decode (mem.extract 0 off) pc := by - rw [hwrite] - rw [ByteArray.append_assoc] - exact decode_append_left_window (mem.extract 0 off) - (UInt256.toByteArray word ++ mem.extract (off + 32) mem.size) pc - (by rw [hprefixSize]; exact hwin) - (by rw [hprefixSize]; omega) - _ = decode (mem.extract 0 off ++ mem.extract off mem.size) pc := by - symm - exact decode_append_left_window (mem.extract 0 off) (mem.extract off mem.size) pc - (by rw [hprefixSize]; exact hwin) - (by rw [hprefixSize]; omega) - _ = decode mem pc := by rw [hsplit] - -theorem decode_patchedRuntime_eq_attesterBytecode (v : AttesterImmutables) - (pc : UInt256) (hwin : pc.toNat + 33 ≤ 722) : - decode (patchedRuntime v) pc = decode attesterBytecode pc := by - let w : UInt256 := EVM.Word.ofNat v.eas.toNat - change - decode (writeCascade attesterBytecode [(722, w), (1465, w), (1598, w), (1939, w)]) - pc = decode attesterBytecode pc - simp only [writeCascade] - have hs0 : attesterBytecode.size = 3186 := attesterBytecode_size - have hs1 : (writeWord attesterBytecode 722 w).size = 3186 := by - rw [writeWord_size_of_inside attesterBytecode 722 w (by rw [hs0]; norm_num), hs0] - have hs2 : (writeWord (writeWord attesterBytecode 722 w) 1465 w).size = 3186 := by - rw [writeWord_size_of_inside (writeWord attesterBytecode 722 w) 1465 w - (by rw [hs1]; norm_num), hs1] - have hs3 : - (writeWord (writeWord (writeWord attesterBytecode 722 w) 1465 w) 1598 w).size = - 3186 := by - rw [writeWord_size_of_inside - (writeWord (writeWord attesterBytecode 722 w) 1465 w) 1598 w - (by rw [hs2]; norm_num), hs2] - rw [decode_writeWord_below - (writeWord (writeWord (writeWord attesterBytecode 722 w) 1465 w) 1598 w) - 1939 w pc (by omega) (by rw [hs3]; norm_num) (by rw [hs3]; norm_num)] - rw [decode_writeWord_below - (writeWord (writeWord attesterBytecode 722 w) 1465 w) - 1598 w pc (by omega) (by rw [hs2]; norm_num) (by rw [hs2]; norm_num)] - rw [decode_writeWord_below - (writeWord attesterBytecode 722 w) - 1465 w pc (by omega) (by rw [hs1]; norm_num) (by rw [hs1]; norm_num)] - rw [decode_writeWord_below - attesterBytecode 722 w pc hwin (by rw [hs0]; norm_num) (by rw [hs0]; norm_num)] - -theorem uInt256OfByteArray_toByteArray (w : UInt256) : - uInt256OfByteArray (UInt256.toByteArray w) = w := by - rw [uInt256OfByteArray_eq, fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - -theorem patchedRuntime_word722 (v : AttesterImmutables) : - (patchedRuntime v).extract' 722 (722 + 32) = - UInt256.toByteArray (EVM.Word.ofNat v.eas.toNat) := by - unfold patchedRuntime runtimeWrites - unfold ByteArray.extract' - rw [if_pos (by native_decide)] - rw [← readWithPadding_eq_extract' _ 722 32 (by norm_num) (by norm_num)] - · refine writeCascade_read_word_of_head_of_base attesterBytecode - (base := 3186) (EVM.Word.ofNat v.eas.toNat) - [ (1465, EVM.Word.ofNat v.eas.toNat), - (1598, EVM.Word.ofNat v.eas.toNat), - (1939, EVM.Word.ofNat v.eas.toNat) ] ?_ ?_ ?_ - · exact attesterBytecode_size - · norm_num - · simp [WindowDisjointFromWrites] - · change 722 + 32 ≤ (patchedRuntime v).size - rw [patchedRuntime_size v] - norm_num - -theorem patchedRuntime_word1465 (v : AttesterImmutables) : - (patchedRuntime v).extract' 1465 (1465 + 32) = - UInt256.toByteArray (EVM.Word.ofNat v.eas.toNat) := by - unfold patchedRuntime runtimeWrites - unfold ByteArray.extract' - rw [if_pos (by native_decide)] - rw [← readWithPadding_eq_extract' _ 1465 32 (by norm_num) (by norm_num)] - · rw [writeCascade_cons] - refine writeCascade_read_word_of_head_of_base - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) - (base := 3186) (EVM.Word.ofNat v.eas.toNat) - [ (1598, EVM.Word.ofNat v.eas.toNat), - (1939, EVM.Word.ofNat v.eas.toNat) ] ?_ ?_ ?_ - · rw [writeWord_size_of_inside attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat) - (by rw [attesterBytecode_size]; norm_num), attesterBytecode_size] - · norm_num - · simp [WindowDisjointFromWrites] - · change 1465 + 32 ≤ (patchedRuntime v).size - rw [patchedRuntime_size v] - norm_num - -theorem patchedRuntime_word1598 (v : AttesterImmutables) : - (patchedRuntime v).extract' 1598 (1598 + 32) = - UInt256.toByteArray (EVM.Word.ofNat v.eas.toNat) := by - unfold patchedRuntime runtimeWrites - unfold ByteArray.extract' - rw [if_pos (by native_decide)] - rw [← readWithPadding_eq_extract' _ 1598 32 (by norm_num) (by norm_num)] - · rw [writeCascade_cons, writeCascade_cons] - refine writeCascade_read_word_of_head_of_base - (writeWord (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)) - (base := 3186) (EVM.Word.ofNat v.eas.toNat) - [ (1939, EVM.Word.ofNat v.eas.toNat) ] ?_ ?_ ?_ - · have hs1 : - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)).size = 3186 := by - rw [writeWord_size_of_inside attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat) - (by rw [attesterBytecode_size]; norm_num), attesterBytecode_size] - rw [writeWord_size_of_inside - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat) (by rw [hs1]; norm_num), hs1] - · norm_num - · simp [WindowDisjointFromWrites] - · change 1598 + 32 ≤ (patchedRuntime v).size - rw [patchedRuntime_size v] - norm_num - -theorem patchedRuntime_word1939 (v : AttesterImmutables) : - (patchedRuntime v).extract' 1939 (1939 + 32) = - UInt256.toByteArray (EVM.Word.ofNat v.eas.toNat) := by - unfold patchedRuntime runtimeWrites - unfold ByteArray.extract' - rw [if_pos (by native_decide)] - rw [← readWithPadding_eq_extract' _ 1939 32 (by norm_num) (by norm_num)] - · rw [writeCascade_cons, writeCascade_cons, writeCascade_cons] - refine writeCascade_read_word_of_head_of_base - (writeWord - (writeWord (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)) 1598 (EVM.Word.ofNat v.eas.toNat)) - (base := 3186) (EVM.Word.ofNat v.eas.toNat) [] ?_ ?_ ?_ - · have hs1 : - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)).size = 3186 := by - rw [writeWord_size_of_inside attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat) - (by rw [attesterBytecode_size]; norm_num), attesterBytecode_size] - have hs2 : - (writeWord (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)).size = 3186 := by - rw [writeWord_size_of_inside - (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat) (by rw [hs1]; norm_num), hs1] - rw [writeWord_size_of_inside - (writeWord (writeWord attesterBytecode 722 (EVM.Word.ofNat v.eas.toNat)) 1465 - (EVM.Word.ofNat v.eas.toNat)) 1598 (EVM.Word.ofNat v.eas.toNat) - (by rw [hs2]; norm_num), hs2] - · norm_num - · simp [WindowDisjointFromWrites] - · change 1939 + 32 ≤ (patchedRuntime v).size - rw [patchedRuntime_size v] - norm_num - -theorem attesterDecodeEasWord721 (v : AttesterImmutables) : - decode (patchedRuntime v) ⟨721⟩ = - some (.Push .PUSH32, some (EVM.Word.ofNat v.eas.toNat, 32)) := by - unfold decode - rw [show (⟨721⟩ : UInt256).toNat = 721 by native_decide] - rw [patchedRuntime_get?_preserved v 721] - · have hget : attesterBytecode.get? 721 = some 0x7f := by native_decide - rw [hget] - simp [parseInstr, argOnNBytesOfInstr] - rw [patchedRuntime_word722 v] - rw [uInt256OfByteArray_toByteArray] - rfl - · simp [runtimeWrites, WindowDisjointFromWrites] - · norm_num - -theorem attesterDecodeEasWord1464 (v : AttesterImmutables) : - decode (patchedRuntime v) ⟨1464⟩ = - some (.Push .PUSH32, some (EVM.Word.ofNat v.eas.toNat, 32)) := by - unfold decode - rw [show (⟨1464⟩ : UInt256).toNat = 1464 by native_decide] - rw [patchedRuntime_get?_preserved v 1464] - · have hget : attesterBytecode.get? 1464 = some 0x7f := by native_decide - rw [hget] - simp [parseInstr, argOnNBytesOfInstr] - rw [patchedRuntime_word1465 v] - rw [uInt256OfByteArray_toByteArray] - rfl - · simp [runtimeWrites, WindowDisjointFromWrites] - · norm_num - -theorem attesterDecodeEasWord1597 (v : AttesterImmutables) : - decode (patchedRuntime v) ⟨1597⟩ = - some (.Push .PUSH32, some (EVM.Word.ofNat v.eas.toNat, 32)) := by - unfold decode - rw [show (⟨1597⟩ : UInt256).toNat = 1597 by native_decide] - rw [patchedRuntime_get?_preserved v 1597] - · have hget : attesterBytecode.get? 1597 = some 0x7f := by native_decide - rw [hget] - simp [parseInstr, argOnNBytesOfInstr] - rw [patchedRuntime_word1598 v] - rw [uInt256OfByteArray_toByteArray] - rfl - · simp [runtimeWrites, WindowDisjointFromWrites] - · norm_num - -theorem attesterDecodeEasWord1938 (v : AttesterImmutables) : - decode (patchedRuntime v) ⟨1938⟩ = - some (.Push .PUSH32, some (EVM.Word.ofNat v.eas.toNat, 32)) := by - unfold decode - rw [show (⟨1938⟩ : UInt256).toNat = 1938 by native_decide] - rw [patchedRuntime_get?_preserved v 1938] - · have hget : attesterBytecode.get? 1938 = some 0x7f := by native_decide - rw [hget] - simp [parseInstr, argOnNBytesOfInstr] - rw [patchedRuntime_word1939 v] - rw [uInt256OfByteArray_toByteArray] - rfl - · simp [runtimeWrites, WindowDisjointFromWrites] - · norm_num - -def attesterSelIs (I : ExecutionEnv) (sel : ByteArray) : Prop := - (sel == I.calldata.extract 0 4) = true - -abbrev attesterDispatchRevertPc : UInt256 := ⟨74⟩ - -def attesterRuntimeSelBytes : ℕ → ByteArray - | 0 => attesterMultiRevokeSelBytes - | 1 => attesterMultiAttestSelBytes - | 2 => attesterAttestSelBytes - | _ => attesterRevokeSelBytes - -macro "attester_runtime_decide" : tactic => - `(tactic| - (simp only [solcGuardTgtOp, solcGuardTgt, solcGuardTgtWidth, solcGuardJumpiPc, - solcDispatchBodyPc, solcCalldataRevertPushPc, solcCalldataRevertTgtOp, - solcCalldataRevertTgt, solcCalldataRevertTgtWidth, solcCalldataJumpiPc, - solcSelectorLoadPc, solcFirstArmPcFromPrefix, pushAt, nthArmPc, armSelNat, - armTgtOp, armTgt, armTgtWidth, selArmPush4Pc, selArmEqPc, selArmPushTgtPc, - selArmJumpiPc, selArmNextPc, attesterFirstArmPc, attesterDispatchRevertPc]; - repeat - (rw [decode_patchedRuntime_eq_attesterBytecode _ _ (by native_decide)]; - simp only [solcGuardTgtOp, solcGuardTgt, solcGuardTgtWidth, solcGuardJumpiPc, - solcDispatchBodyPc, solcCalldataRevertPushPc, solcCalldataRevertTgtOp, - solcCalldataRevertTgt, solcCalldataRevertTgtWidth, solcCalldataJumpiPc, - solcSelectorLoadPc, solcFirstArmPcFromPrefix, pushAt, nthArmPc, armSelNat, - armTgtOp, armTgt, armTgtWidth, selArmPush4Pc, selArmEqPc, selArmPushTgtPc, - selArmJumpiPc, selArmNextPc, attesterFirstArmPc, attesterDispatchRevertPc]); - native_decide +revert)) - -macro "attester_decode" : tactic => - `(tactic| - (first - | rw [decode_patchedRuntime_eq_attesterBytecode _ _ (by native_decide)] - native_decide - | rw [patchedRuntime_decode_preserved_of_parse] - · native_decide - · native_decide - · native_decide - · first - | native_decide - | norm_num [runtimeWrites, WindowDisjointFromWrites, UInt256.toNat, UInt256.size] - · first - | native_decide - | norm_num [UInt256.toNat, UInt256.size] - · first - | native_decide - | norm_num [runtimeWrites, WindowDisjointFromWrites, UInt256.toNat, UInt256.size, - argOnNBytesOfInstr] - · first - | native_decide - | norm_num [UInt256.toNat, UInt256.size, argOnNBytesOfInstr] - | rw [patchedRuntime_decode_preserved] - · native_decide - · first - | native_decide - | norm_num [runtimeWrites, WindowDisjointFromWrites, UInt256.toNat, UInt256.size] - · first - | native_decide - | norm_num [UInt256.toNat, UInt256.size] - · intro byte instr hbyte hinstr - first - | revert hbyte hinstr - native_decide - | have hle := argOnNBytesOfInstr_le_32 instr - simp [runtimeWrites, WindowDisjointFromWrites, UInt256.toNat, UInt256.size] - omega - · intro byte instr hbyte hinstr - first - | revert hbyte hinstr - native_decide - | have hle := argOnNBytesOfInstr_le_32 instr - simp [UInt256.toNat, UInt256.size] - omega)) - -syntax "attester_decode_at " term "," term "," term "," term : tactic -macro_rules - | `(tactic| attester_decode_at $varg, $pc, $byte, $instr) => - `(tactic| - (change decode (patchedRuntime $varg) ($pc : UInt256) = _; - rw [(patchedRuntime_decode_preserved_of_parse $varg ($pc : UInt256) ($byte : UInt8) - $instr (by native_decide) (by native_decide) - (by norm_num [runtimeWrites, WindowDisjointFromWrites, UInt256.toNat, UInt256.size]) - (by norm_num [UInt256.toNat, UInt256.size]) - (by norm_num [runtimeWrites, WindowDisjointFromWrites, UInt256.toNat, UInt256.size, - argOnNBytesOfInstr]) - (by norm_num [UInt256.toNat, UInt256.size, argOnNBytesOfInstr]))]; - native_decide)) - -theorem attesterMultiRevokeSelBytes_size : attesterMultiRevokeSelBytes.size = 4 := rfl -theorem attesterMultiAttestSelBytes_size : attesterMultiAttestSelBytes.size = 4 := rfl -theorem attesterAttestSelBytes_size : attesterAttestSelBytes.size = 4 := rfl -theorem attesterRevokeSelBytes_size : attesterRevokeSelBytes.size = 4 := rfl - -theorem attesterDispatch_none_short (v : AttesterImmutables) {cd : ByteArray} - (hcd : cd.size < 4) : - dispatchMsg (contract v) cd = none := by - rw [dispatchMsg_eq_dispatchList (contract v) cd (by rfl) (by rfl)] - exact dispatchList_none_short (contract v).transitions - (by - intro t ht - simp [contract, transitions] at ht - rcases ht with rfl | rfl | rfl | rfl - · rw [attestSelectorOf v]; exact attesterAttestSelBytes_size - · rw [multiAttestSelectorOf v]; exact attesterMultiAttestSelBytes_size - · rw [multiRevokeSelectorOf v]; exact attesterMultiRevokeSelBytes_size - · rw [revokeSelectorOf v]; exact attesterRevokeSelBytes_size) - hcd - -theorem attesterDispatch_none_nomatch (v : AttesterImmutables) {cd : ByteArray} - (hmultiRevoke : (attesterMultiRevokeSelBytes == cd.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == cd.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == cd.extract 0 4) = false) - (hrevoke : (attesterRevokeSelBytes == cd.extract 0 4) = false) : - dispatchMsg (contract v) cd = none := by - apply dispatchMsg_none_of_all_ne (hfallback := by rfl) (hreceive := by rfl) - intro t ht - simp [contract, transitions] at ht - rcases ht with rfl | rfl | rfl | rfl - · rw [attestSelectorOf v]; exact hattest - · rw [multiAttestSelectorOf v]; exact hmultiAttest - · rw [multiRevokeSelectorOf v]; exact hmultiRevoke - · rw [revokeSelectorOf v]; exact hrevoke - -theorem attesterSelectorMismatchOfHit {miss hit x : ByteArray} - (hne : miss ≠ hit) (hhit : (hit == x) = true) : - (miss == x) = false := by - by_cases hmiss : (miss == x) = true - · have hmissEq : miss = x := byteArray_eq_of_beq hmiss - have hhitEq : hit = x := byteArray_eq_of_beq hhit - exact False.elim (hne (hmissEq.trans hhitEq.symm)) - · exact Bool.eq_false_of_not_eq_true hmiss - -theorem attesterAttestSelBytes_ne_multiAttestSelBytes : - attesterAttestSelBytes ≠ attesterMultiAttestSelBytes := by - native_decide - -theorem attesterAttestSelBytes_ne_multiRevokeSelBytes : - attesterAttestSelBytes ≠ attesterMultiRevokeSelBytes := by - native_decide - -theorem attesterMultiAttestSelBytes_ne_multiRevokeSelBytes : - attesterMultiAttestSelBytes ≠ attesterMultiRevokeSelBytes := by - native_decide - -theorem attesterDispatch_attest (v : AttesterImmutables) {cd : ByteArray} - (hattest : (attesterAttestSelBytes == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some (attestTransition v) := by - apply dispatchMsg_eq_some_of_split (contract := contract v) - (pre := []) (post := [multiAttestTransition v, multiRevokeTransition v, revokeTransition v]) - (ti := attestTransition v) (cd := cd) (hfallback := by rfl) - · simp [contract, transitions] - · intro t ht - simp at ht - · rw [attestSelectorOf v] - exact hattest - -theorem attesterDispatch_multiAttest (v : AttesterImmutables) {cd : ByteArray} - (hmultiAttest : (attesterMultiAttestSelBytes == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some (multiAttestTransition v) := by - apply dispatchMsg_eq_some_of_split (contract := contract v) - (pre := [attestTransition v]) (post := [multiRevokeTransition v, revokeTransition v]) - (ti := multiAttestTransition v) (cd := cd) (hfallback := by rfl) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with rfl - rw [attestSelectorOf v] - exact attesterSelectorMismatchOfHit attesterAttestSelBytes_ne_multiAttestSelBytes hmultiAttest - · rw [multiAttestSelectorOf v] - exact hmultiAttest - -theorem attesterDispatch_multiRevoke (v : AttesterImmutables) {cd : ByteArray} - (hmultiRevoke : (attesterMultiRevokeSelBytes == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some (multiRevokeTransition v) := by - apply dispatchMsg_eq_some_of_split (contract := contract v) - (pre := [attestTransition v, multiAttestTransition v]) (post := [revokeTransition v]) - (ti := multiRevokeTransition v) (cd := cd) (hfallback := by rfl) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with rfl | rfl - · rw [attestSelectorOf v] - exact attesterSelectorMismatchOfHit attesterAttestSelBytes_ne_multiRevokeSelBytes hmultiRevoke - · rw [multiAttestSelectorOf v] - exact attesterSelectorMismatchOfHit attesterMultiAttestSelBytes_ne_multiRevokeSelBytes - hmultiRevoke - · rw [multiRevokeSelectorOf v] - exact hmultiRevoke - -theorem attesterDispatch_revoke (v : AttesterImmutables) {cd : ByteArray} - (hmultiRevoke : (attesterMultiRevokeSelBytes == cd.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == cd.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == cd.extract 0 4) = false) - (hrevoke : (attesterRevokeSelBytes == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some (revokeTransition v) := by - apply dispatchMsg_eq_some_of_split (contract := contract v) - (pre := [attestTransition v, multiAttestTransition v, multiRevokeTransition v]) (post := []) - (ti := revokeTransition v) (cd := cd) (hfallback := by rfl) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with rfl | rfl | rfl - · rw [attestSelectorOf v] - exact hattest - · rw [multiAttestSelectorOf v] - exact hmultiAttest - · rw [multiRevokeSelectorOf v] - exact hmultiRevoke - · rw [revokeSelectorOf v] - exact hrevoke - -theorem attesterMultiRevokeEqZero (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) : - UInt256.eq (⟨0x13fde550⟩ : UInt256) (solcSelectorWord I) = ⟨0⟩ := by - simpa [solcSelectorWord, attesterMultiRevokeSelBytes, hmultiRevoke] using - (evmSelectorDecode (cd := I.calldata) hsz - (0x13 : UInt8) (0xfd : UInt8) (0xe5 : UInt8) (0x50 : UInt8) - (⟨0x13fde550⟩ : UInt256) (by native_decide)) - -theorem attesterMultiRevokeEqNonzero (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = true) : - UInt256.eq (⟨0x13fde550⟩ : UInt256) (solcSelectorWord I) ≠ ⟨0⟩ := by - have h : - UInt256.eq (⟨0x13fde550⟩ : UInt256) (solcSelectorWord I) = ⟨1⟩ := by - simpa [solcSelectorWord, attesterMultiRevokeSelBytes, hmultiRevoke] using - (evmSelectorDecode (cd := I.calldata) hsz - (0x13 : UInt8) (0xfd : UInt8) (0xe5 : UInt8) (0x50 : UInt8) - (⟨0x13fde550⟩ : UInt256) (by native_decide)) - rw [h] - decide - -theorem attesterMultiAttestEqZero (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) : - UInt256.eq (⟨0x54e1db35⟩ : UInt256) (solcSelectorWord I) = ⟨0⟩ := by - simpa [solcSelectorWord, attesterMultiAttestSelBytes, hmultiAttest] using - (evmSelectorDecode (cd := I.calldata) hsz - (0x54 : UInt8) (0xe1 : UInt8) (0xdb : UInt8) (0x35 : UInt8) - (⟨0x54e1db35⟩ : UInt256) (by native_decide)) - -theorem attesterMultiAttestEqNonzero (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = true) : - UInt256.eq (⟨0x54e1db35⟩ : UInt256) (solcSelectorWord I) ≠ ⟨0⟩ := by - have h : - UInt256.eq (⟨0x54e1db35⟩ : UInt256) (solcSelectorWord I) = ⟨1⟩ := by - simpa [solcSelectorWord, attesterMultiAttestSelBytes, hmultiAttest] using - (evmSelectorDecode (cd := I.calldata) hsz - (0x54 : UInt8) (0xe1 : UInt8) (0xdb : UInt8) (0x35 : UInt8) - (⟨0x54e1db35⟩ : UInt256) (by native_decide)) - rw [h] - decide - -theorem attesterAttestEqZero (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = false) : - UInt256.eq (⟨0x72b9966d⟩ : UInt256) (solcSelectorWord I) = ⟨0⟩ := by - simpa [solcSelectorWord, attesterAttestSelBytes, hattest] using - (evmSelectorDecode (cd := I.calldata) hsz - (0x72 : UInt8) (0xb9 : UInt8) (0x96 : UInt8) (0x6d : UInt8) - (⟨0x72b9966d⟩ : UInt256) (by native_decide)) - -theorem attesterAttestEqNonzero (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = true) : - UInt256.eq (⟨0x72b9966d⟩ : UInt256) (solcSelectorWord I) ≠ ⟨0⟩ := by - have h : - UInt256.eq (⟨0x72b9966d⟩ : UInt256) (solcSelectorWord I) = ⟨1⟩ := by - simpa [solcSelectorWord, attesterAttestSelBytes, hattest] using - (evmSelectorDecode (cd := I.calldata) hsz - (0x72 : UInt8) (0xb9 : UInt8) (0x96 : UInt8) (0x6d : UInt8) - (⟨0x72b9966d⟩ : UInt256) (by native_decide)) - rw [h] - decide - -theorem attesterRevokeEqZero (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) - (hrevoke : (attesterRevokeSelBytes == I.calldata.extract 0 4) = false) : - UInt256.eq (⟨0xc2664610⟩ : UInt256) (solcSelectorWord I) = ⟨0⟩ := by - simpa [solcSelectorWord, attesterRevokeSelBytes, hrevoke] using - (evmSelectorDecode (cd := I.calldata) hsz - (0xc2 : UInt8) (0x66 : UInt8) (0x46 : UInt8) (0x10 : UInt8) - (⟨0xc2664610⟩ : UInt256) (by native_decide)) - -theorem attesterRevokeEqNonzero (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) - (hrevoke : (attesterRevokeSelBytes == I.calldata.extract 0 4) = true) : - UInt256.eq (⟨0xc2664610⟩ : UInt256) (solcSelectorWord I) ≠ ⟨0⟩ := by - have h : - UInt256.eq (⟨0xc2664610⟩ : UInt256) (solcSelectorWord I) = ⟨1⟩ := by - simpa [solcSelectorWord, attesterRevokeSelBytes, hrevoke] using - (evmSelectorDecode (cd := I.calldata) hsz - (0xc2 : UInt8) (0x66 : UInt8) (0x46 : UInt8) (0x10 : UInt8) - (⟨0xc2664610⟩ : UInt256) (by native_decide)) - rw [h] - decide - -theorem attesterX_callvalue_ne {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue ≠ ⟨0⟩) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have h0 := solcGuardPrologueRD (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode - (by attester_decode) (by attester_decode) (by attester_decode) - (by attester_decode) (by attester_decode) (by attester_decode) - have h12 := h0 - |>.push2 (⟨15⟩ : UInt256) (by attester_decode) - (by simp only [List.length_cons, List.length_nil]; omega) - |>.jumpiNT (by attester_decode) (isZero_eq_zero_of_ne hwv) - (by simp only [List.length_cons, List.length_nil]; omega) - exact h12.push0 (by attester_decode) (by simp) - |>.dup1 (by attester_decode) (by simp) - |>.rev 0 (by attester_decode) (fun s _ hstks => memExpRevert0 s hstks) (by simp) - -theorem attesterX_short {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) - (hwv : I.weiValue = ⟨0⟩) (hshort : I.calldata.size < 4) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have h0 := solcGuardPrologueRD (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode - (by attester_decode) (by attester_decode) (by attester_decode) - (by attester_decode) (by attester_decode) (by attester_decode) - obtain ⟨_, _, h17⟩ := solcGuardCallvalueZero - (ctgt := (⟨15⟩ : UInt256)) (opC := .PUSH2) (wC := 2) - h0 hwv (by decide) (by attester_decode) - (by attester_decode) (by attester_decode) - (by attester_decode) (attesterGuardJumpdest v) - have h74 := h17 - |>.push1 ⟨4⟩ (by attester_decode) (by simp) - |>.calldatasize (by attester_decode) (by simp) - |>.lt (by attester_decode) (by simp) - |>.push2 attesterDispatchRevertPc (by attester_decode) - (by simp only [List.length_cons, List.length_nil]; omega) - |>.jumpiT (by attester_decode) (lt_four_ne_zero_of_lt hshort) - (attesterDispatchRevertJumpdest v) (by simp only [List.length_nil]; omega) - |>.jumpdest (by attester_decode) (by simp) - exact h74.push0 (by attester_decode) (by simp) - |>.dup1 (by attester_decode) (by simp) - |>.rev 0 (by attester_decode) (fun s _ hstks => memExpRevert0 s hstks) (by simp) - -theorem attesterX_noMatch {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = false) - (hrevoke : (attesterRevokeSelBytes == I.calldata.extract 0 4) = false) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have h0 := solcGuardPrologueRD (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode - (by attester_decode) (by attester_decode) (by attester_decode) - (by attester_decode) (by attester_decode) (by attester_decode) - obtain ⟨_, _, h17⟩ := solcGuardCallvalueZero - (ctgt := (⟨15⟩ : UInt256)) (opC := .PUSH2) (wC := 2) - h0 hwv (by decide) (by attester_decode) - (by attester_decode) (by attester_decode) - (by attester_decode) (attesterGuardJumpdest v) - obtain ⟨k25, C25, h25raw⟩ := solcCalldataOk - (bodyPc := (⟨17⟩ : UInt256)) (selLoadTgt := attesterDispatchRevertPc) - (opR := .PUSH2) (wR := 2) - h17 hsz hsize (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) - have h25 : - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨25⟩ : UInt256) - [] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k25 C25 := by - simpa using h25raw - obtain ⟨k30, C30, h30raw⟩ := solcSelectorLoad h25 - (by attester_decode) (by attester_decode) (by attester_decode) (by attester_decode) (by simp) - have h30 : - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) attesterFirstArmPc - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k30 C30 := by - simpa [attesterFirstArmPc, solcSelectorWord] using h30raw - have heqMultiRevoke := attesterMultiRevokeEqZero I hsz hmultiRevoke - have heqMultiAttest := attesterMultiAttestEqZero I hsz hmultiAttest - have heqAttest := attesterAttestEqZero I hsz hattest - have heqRevoke := attesterRevokeEqZero I hsz hrevoke - have h74 := h30 - |>.selectorArmNotTaken (selNat := (⟨0x13fde550⟩ : UInt256)) - (tgt := (⟨78⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqMultiRevoke (by simp) - |>.selectorArmNotTaken (selNat := (⟨0x54e1db35⟩ : UInt256)) - (tgt := (⟨99⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqMultiAttest (by simp) - |>.selectorArmNotTaken (selNat := (⟨0x72b9966d⟩ : UInt256)) - (tgt := (⟨140⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqAttest (by simp) - |>.selectorArmNotTaken (selNat := (⟨0xc2664610⟩ : UInt256)) - (tgt := (⟨173⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqRevoke (by simp) - |>.jumpdest (by attester_decode) (by simp) - exact h74.push0 (by attester_decode) (by simp) - |>.dup1 (by attester_decode) (by simp) - |>.rev 0 (by attester_decode) (fun s _ hstks => memExpRevert0 s hstks) (by simp) - -theorem attesterX_multiRevokeWrapper {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = true) : - ∃ k C, RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨78⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C := by - have h0 := solcGuardPrologueRD (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode - (by attester_decode) (by attester_decode) (by attester_decode) - (by attester_decode) (by attester_decode) (by attester_decode) - obtain ⟨_, _, h17⟩ := solcGuardCallvalueZero - (ctgt := (⟨15⟩ : UInt256)) (opC := .PUSH2) (wC := 2) - h0 hwv (by decide) (by attester_decode) - (by attester_decode) (by attester_decode) - (by attester_decode) (attesterGuardJumpdest v) - obtain ⟨k25, C25, h25raw⟩ := solcCalldataOk - (bodyPc := (⟨17⟩ : UInt256)) (selLoadTgt := attesterDispatchRevertPc) - (opR := .PUSH2) (wR := 2) - h17 hsz hsize (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) - have h25 : - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨25⟩ : UInt256) - [] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k25 C25 := by - simpa using h25raw - obtain ⟨k30, C30, h30raw⟩ := solcSelectorLoad h25 - (by attester_decode) (by attester_decode) (by attester_decode) (by attester_decode) (by simp) - have h30 : - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) attesterFirstArmPc - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k30 C30 := by - simpa [attesterFirstArmPc, solcSelectorWord] using h30raw - have heqMultiRevoke := attesterMultiRevokeEqNonzero I hsz hmultiRevoke - exact ⟨_, _, h30 - |>.selectorArmTaken (selNat := (⟨0x13fde550⟩ : UInt256)) - (tgt := (⟨78⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqMultiRevoke - (attesterMultiRevokeWrapperJumpdest v) (by simp)⟩ - -theorem attesterX_multiAttestWrapper {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = true) : - ∃ k C, RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨99⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C := by - have h0 := solcGuardPrologueRD (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode - (by attester_decode) (by attester_decode) (by attester_decode) - (by attester_decode) (by attester_decode) (by attester_decode) - obtain ⟨_, _, h17⟩ := solcGuardCallvalueZero - (ctgt := (⟨15⟩ : UInt256)) (opC := .PUSH2) (wC := 2) - h0 hwv (by decide) (by attester_decode) - (by attester_decode) (by attester_decode) - (by attester_decode) (attesterGuardJumpdest v) - obtain ⟨k25, C25, h25raw⟩ := solcCalldataOk - (bodyPc := (⟨17⟩ : UInt256)) (selLoadTgt := attesterDispatchRevertPc) - (opR := .PUSH2) (wR := 2) - h17 hsz hsize (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) - have h25 : - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨25⟩ : UInt256) - [] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k25 C25 := by - simpa using h25raw - obtain ⟨k30, C30, h30raw⟩ := solcSelectorLoad h25 - (by attester_decode) (by attester_decode) (by attester_decode) (by attester_decode) (by simp) - have h30 : - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) attesterFirstArmPc - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k30 C30 := by - simpa [attesterFirstArmPc, solcSelectorWord] using h30raw - have heqMultiRevoke := attesterMultiRevokeEqZero I hsz hmultiRevoke - have heqMultiAttest := attesterMultiAttestEqNonzero I hsz hmultiAttest - exact ⟨_, _, h30 - |>.selectorArmNotTaken (selNat := (⟨0x13fde550⟩ : UInt256)) - (tgt := (⟨78⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqMultiRevoke (by simp) - |>.selectorArmTaken (selNat := (⟨0x54e1db35⟩ : UInt256)) - (tgt := (⟨99⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqMultiAttest - (attesterMultiAttestWrapperJumpdest v) (by simp)⟩ - -theorem attesterX_multiRevokeToDecoder {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨78⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2109⟩ : UInt256) - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨92⟩, ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd78⟩ := hreach - exact ⟨_, _, evm_run rd78 with [ - raw jumpdest (by attester_decode_at v, ⟨78⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push2 ⟨97⟩ (by attester_decode_at v, ⟨79⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw push2 ⟨92⟩ (by attester_decode_at v, ⟨82⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw calldatasize (by attester_decode_at v, ⟨85⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw push1 ⟨4⟩ (by attester_decode_at v, ⟨86⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push2 ⟨2109⟩ (by attester_decode_at v, ⟨88⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨91⟩, 0x56, .JUMP) - (attesterDynamic2DecoderJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiAttestToDecoder {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨99⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2109⟩ : UInt256) - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨113⟩, ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd99⟩ := hreach - exact ⟨_, _, evm_run rd99 with [ - raw jumpdest (by attester_decode_at v, ⟨99⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push2 ⟨118⟩ (by attester_decode_at v, ⟨100⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw push2 ⟨113⟩ (by attester_decode_at v, ⟨103⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw calldatasize (by attester_decode_at v, ⟨106⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw push1 ⟨4⟩ (by attester_decode_at v, ⟨107⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push2 ⟨2109⟩ (by attester_decode_at v, ⟨109⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨112⟩, 0x56, .JUMP) - (attesterDynamic2DecoderJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_dynamic2DecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨1⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2109⟩ : UInt256) - [⟨4⟩, UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2109⟩ := hreach - exact evm_run rd2109 with [ - raw jumpdest (by attester_decode_at v, ⟨2109⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2110⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2111⟩, 0x80, .DUP1) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2112⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2113⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2114⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2116⟩, 0x85, .DUP6) (by evm_ov), - raw dup8 (by attester_decode_at v, ⟨2117⟩, 0x87, .DUP8) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2118⟩, 0x03, .SUB) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2119⟩, 0x12, .SLT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2120⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2128⟩ (by attester_decode_at v, ⟨2121⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2124⟩, 0x57, .JUMPI) (by rw [hslt]; decide) - (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2125⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2126⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2127⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_dynamic2DecodeHeadOk {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨0⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2109⟩ : UInt256) - [⟨4⟩, UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2128⟩ : UInt256) - [⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, - decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2109⟩ := hreach - exact ⟨_, _, evm_run rd2109 with [ - raw jumpdest (by attester_decode_at v, ⟨2109⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2110⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2111⟩, 0x80, .DUP1) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2112⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2113⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2114⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2116⟩, 0x85, .DUP6) (by evm_ov), - raw dup8 (by attester_decode_at v, ⟨2117⟩, 0x87, .DUP8) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2118⟩, 0x03, .SUB) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2119⟩, 0x12, .SLT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2120⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2128⟩ (by attester_decode_at v, ⟨2121⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2124⟩, 0x57, .JUMPI) - (by rw [hslt]; decide) (attesterDynamic2DecodeHeadOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_dynamic2FirstOffsetOk {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2128⟩ : UInt256) - [⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, - decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2149⟩ : UInt256) - [calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2128⟩ := hreach - have hgt : - UInt256.gt (calldataWord I.calldata 4) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - have hmaxToNat : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = - solcMaxU64 := by - native_decide - rw [hmaxToNat] - exact Nat.le_of_not_gt hoffMax - exact ⟨_, _, evm_run rd2128 with [ - raw jumpdest (by attester_decode_at v, ⟨2128⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2129⟩, 0x84, .DUP5) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2130⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2131⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2133⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2135⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2137⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2138⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2139⟩, 0x81, .DUP2) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2140⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2141⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2149⟩ (by attester_decode_at v, ⟨2142⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2145⟩, 0x57, .JUMPI) - (by - change UInt256.isZero - (UInt256.gt (calldataWord I.calldata 4) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) ≠ ⟨0⟩ - rw [hgt] - decide) - (attesterDynamic2FirstOffsetOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_dynamic2FirstOffsetHugeReverts {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hoff : solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2128⟩ : UInt256) - [⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, - decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2128⟩ := hreach - have hgt : - UInt256.gt (calldataWord I.calldata 4) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨1⟩ := by - apply ugt_one - have hmaxToNat : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = - solcMaxU64 := by - native_decide - rw [hmaxToNat] - exact hoff - exact evm_run rd2128 with [ - raw jumpdest (by attester_decode_at v, ⟨2128⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2129⟩, 0x84, .DUP5) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2130⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2131⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2133⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2135⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2137⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2138⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2139⟩, 0x81, .DUP2) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2140⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2141⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2149⟩ (by attester_decode_at v, ⟨2142⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2145⟩, 0x57, .JUMPI) - (by - change UInt256.isZero - (UInt256.gt (calldataWord I.calldata 4) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) = ⟨0⟩ - rw [hgt] - decide) - (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2146⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2147⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2148⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_dynamic2FirstArrayDecoderEntry {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2149⟩ : UInt256) - [calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2038⟩ : UInt256) - [UInt256.add ⟨4⟩ (calldataWord I.calldata 4), UInt256.ofNat I.calldata.size, - ⟨2161⟩, calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2149⟩ := hreach - exact ⟨_, _, evm_run rd2149 with [ - raw jumpdest (by attester_decode_at v, ⟨2149⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push2 ⟨2161⟩ (by attester_decode_at v, ⟨2150⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw dup8 (by attester_decode_at v, ⟨2153⟩, 0x87, .DUP8) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2154⟩, 0x82, .DUP3) (by evm_ov), - raw dup9 (by attester_decode_at v, ⟨2155⟩, 0x88, .DUP9) (by evm_ov), - raw add (by attester_decode_at v, ⟨2156⟩, 0x01, .ADD) (by evm_ov), - raw push2 ⟨2038⟩ (by attester_decode_at v, ⟨2157⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨2160⟩, 0x56, .JUMP) - (attesterDynamicArrayDecoderJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeDecodeShort {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hshort : I.calldata.size < 68) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = true) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨1⟩ := - solcDecodeLenCheckShort_4_64 hsz4 hshort hsize - exact attesterX_dynamic2DecodeRevert (v := v) hslt - (attesterX_multiRevokeToDecoder (v := v) - (attesterX_multiRevokeWrapper (g := g) v hcode hwv hsz4 hsize hmultiRevoke)) - -theorem attesterX_multiRevokeDecodeHeadOk {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsz68 : 68 ≤ I.calldata.size) (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = true) : - ∃ k C, RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨2128⟩ : UInt256) - [⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, - ⟨92⟩, ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨0⟩ := - solcDecodeLenCheckOk_4_64 hsz68 hsmall hsize - exact attesterX_dynamic2DecodeHeadOk (v := v) hslt - (attesterX_multiRevokeToDecoder (v := v) - (attesterX_multiRevokeWrapper (g := g) v hcode hwv hsz4 hsize hmultiRevoke)) - -theorem attesterX_multiRevokeDecodeHuge {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = true) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨1⟩ := - solcDecodeLenCheckHuge_4_64 hbig hsize - exact attesterX_dynamic2DecodeRevert (v := v) hslt - (attesterX_multiRevokeToDecoder (v := v) - (attesterX_multiRevokeWrapper (g := g) v hcode hwv hsz4 hsize hmultiRevoke)) - -theorem attesterX_multiAttestDecodeShort {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hshort : I.calldata.size < 68) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = true) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨1⟩ := - solcDecodeLenCheckShort_4_64 hsz4 hshort hsize - exact attesterX_dynamic2DecodeRevert (v := v) hslt - (attesterX_multiAttestToDecoder (v := v) - (attesterX_multiAttestWrapper (g := g) v hcode hwv hsz4 hsize hmultiRevoke - hmultiAttest)) - -theorem attesterX_multiAttestDecodeHeadOk {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsz68 : 68 ≤ I.calldata.size) (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = true) : - ∃ k C, RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨2128⟩ : UInt256) - [⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, - ⟨113⟩, ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨0⟩ := - solcDecodeLenCheckOk_4_64 hsz68 hsmall hsize - exact attesterX_dynamic2DecodeHeadOk (v := v) hslt - (attesterX_multiAttestToDecoder (v := v) - (attesterX_multiAttestWrapper (g := g) v hcode hwv hsz4 hsize hmultiRevoke - hmultiAttest)) - -theorem attesterX_multiAttestDecodeHuge {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = true) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨1⟩ := - solcDecodeLenCheckHuge_4_64 hbig hsize - exact attesterX_dynamic2DecodeRevert (v := v) hslt - (attesterX_multiAttestToDecoder (v := v) - (attesterX_multiAttestWrapper (g := g) v hcode hwv hsz4 hsize hmultiRevoke - hmultiAttest)) - -private theorem decodeABIValues_twoDynamicArrays_shape {elem0 elem1 : ABIType} - {bytes : List UInt8} {values : List Value} {endOffset : Nat} - (hvals : - decodeABIValues? [.dynamicArray elem0, .dynamicArray (.dynamicArray elem1)] - bytes 0 0 64 64 = some (values, endOffset)) : - ∃ xs ys : List Value, values = [.array xs, .array ys] := by - rw [decodeABIValues?] at hvals - simp [isDynamicABIType, bind, Option.bind] at hvals - cases hread0 : readNat? bytes 0 with - | none => simp [hread0] at hvals - | some off0 => - by_cases hmax0 : solcMaxLen DecodeMode.modern < off0 - · simp [hread0] at hvals - have hle : off0 ≤ solcMaxU64 := hvals.1 - simp [solcMaxLen] at hmax0 - omega - · simp [hread0] at hvals - cases hv0 : decodeABIValue? (.dynamicArray elem0) bytes off0 with - | none => simp [hv0] at hvals - | some p0 => - rcases p0 with ⟨v0, end0⟩ - obtain ⟨xs, hv0arr⟩ := decodeABIValue_dynamicArray_is_array hv0 - simp [hv0] at hvals - cases hrest : - decodeABIValues? [.dynamicArray (.dynamicArray elem1)] - bytes 0 32 64 (max 64 end0) with - | none => simp [hrest] at hvals - | some prest => - rcases prest with ⟨valuesRest, endRest⟩ - simp [hrest] at hvals - rw [decodeABIValues?] at hrest - simp [isDynamicABIType, bind, Option.bind] at hrest - cases hread1 : readNat? bytes 32 with - | none => simp [hread1] at hrest - | some off1 => - by_cases hmax1 : solcMaxLen DecodeMode.modern < off1 - · simp [hread1] at hrest - have hle : off1 ≤ solcMaxU64 := hrest.1 - simp [solcMaxLen] at hmax1 - omega - · simp [hread1] at hrest - cases hv1 : - decodeABIValue? (.dynamicArray (.dynamicArray elem1)) bytes off1 with - | none => simp [hv1] at hrest - | some p1 => - rcases p1 with ⟨v1, end1⟩ - obtain ⟨ys, hv1arr⟩ := decodeABIValue_dynamicArray_is_array hv1 - simp [hv1] at hrest - rcases hrest with ⟨_hoff1le, hrestEq⟩ - simp [decodeABIValues?] at hrestEq - rcases hrestEq with ⟨hvaluesRestEq, _hendRestEq⟩ - rcases hvals with ⟨_hoff0le, hvalsEq⟩ - rcases hvalsEq with ⟨hvaluesEq, _hendEq⟩ - cases hvaluesRestEq - refine ⟨xs, ys, ?_⟩ - rw [← hvaluesEq, hv0arr, hv1arr] - -theorem attesterDecodeCalldata_twoDynamicArrays_none_firstOffsetHuge {cd : ByteArray} - {name0 name1 : Ident} {elem0 elem1 : ABIType} - (hsz68 : 68 ≤ cd.size) - (hoff : solcMaxU64 < (calldataWord cd 4).toNat) : - decodeCalldata [name0, name1] [.dynamicArray elem0, .dynamicArray (.dynamicArray elem1)] - cd = none := by - unfold decodeCalldata - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - by_cases hdyn : - ([ABIType.dynamicArray elem0, ABIType.dynamicArray (ABIType.dynamicArray elem1)].any - isDynamicABIType = true ∧ - 2 ^ 255 ≤ cd.toList.length) - · rw [if_pos hdyn] - · rw [if_neg hdyn] - by_cases hargsHuge : - [ABIType.dynamicArray elem0, ABIType.dynamicArray (ABIType.dynamicArray elem1)].isEmpty = - false ∧ - 2 ^ 255 ≤ (cd.toList.drop 4).length - · rw [if_pos hargsHuge] - · rw [if_neg hargsHuge] - have hread := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) - simp [decodeCalldata.decodeArgs, decodeABIValues?, isDynamicABIType, - abiTupleHeadSize?, bind, Option.bind, solcMaxLen, hread, hoff] - -theorem attesterDecodeCalldata_twoDynamicArrays_firstOffsetMax {cd : ByteArray} - {callargs : Store} {name0 name1 : Ident} {elem0 elem1 : ABIType} - (hsz68 : 68 ≤ cd.size) - (hdec : decodeCalldata [name0, name1] [.dynamicArray elem0, .dynamicArray (.dynamicArray elem1)] - cd = some callargs) : - ¬ solcMaxU64 < (calldataWord cd 4).toNat := by - unfold decodeCalldata at hdec - simp [decodeCalldata.decodeArgs, abiTupleHeadSize?, isDynamicABIType, - bind, Option.bind] at hdec - rcases hdec with ⟨_hlen4, _hhuge, _hargHuge, _htotalHuge, hdec⟩ - by_cases hshort : cd.toList.length - 4 < 64 - · simp [hshort] at hdec - · simp [hshort] at hdec - cases hvals : - decodeABIValues? [.dynamicArray elem0, .dynamicArray (.dynamicArray elem1)] - (List.drop 4 cd.toList) 0 0 64 64 with - | none => - simp [hvals] at hdec - | some p => - simp [hvals] at hdec - rw [decodeABIValues?] at hvals - simp [isDynamicABIType, bind, Option.bind] at hvals - cases hread0 : readNat? (List.drop 4 cd.toList) 0 with - | none => simp [hread0] at hvals - | some off0 => - by_cases hmax0 : solcMaxLen DecodeMode.modern < off0 - · simp [hread0] at hvals - have hle : off0 ≤ solcMaxU64 := hvals.1 - simp [solcMaxLen] at hmax0 - omega - · have hreadWord := readNat_drop4_zero_eq_calldataWord (cd := cd) - (by omega : 36 ≤ cd.size) - rw [hread0] at hreadWord - cases hreadWord - simpa [solcMaxLen] using hmax0 - -theorem attesterDecodeCalldata_twoDynamicArrays_shape {cd : ByteArray} {callargs : Store} - {name0 name1 : Ident} {elem0 elem1 : ABIType} - (hne : (name1 == name0) = false) - (hdec : decodeCalldata [name0, name1] [.dynamicArray elem0, .dynamicArray (.dynamicArray elem1)] - cd = some callargs) : - ∃ xs ys : List Value, - callargs.get? name0 = some (.array xs) ∧ - callargs.get? name1 = some (.array ys) := by - unfold decodeCalldata at hdec - simp [decodeCalldata.decodeArgs, abiTupleHeadSize?, isDynamicABIType, - bind, Option.bind] at hdec - rcases hdec with ⟨_hlen4, _hhuge, _hargHuge, _htotalHuge, hdec⟩ - by_cases hshort : cd.toList.length - 4 < 64 - · simp [hshort] at hdec - · simp [hshort] at hdec - cases hvals : - decodeABIValues? [.dynamicArray elem0, .dynamicArray (.dynamicArray elem1)] - (List.drop 4 cd.toList) 0 0 64 64 with - | none => - simp [hvals] at hdec - | some p => - rcases p with ⟨values, endOffset⟩ - simp [hvals] at hdec - obtain ⟨xs, ys, hshape⟩ := decodeABIValues_twoDynamicArrays_shape hvals - cases hshape - simp [decodeCalldata.insertValues] at hdec - cases hdec - refine ⟨xs, ys, ?_, ?_⟩ - · simp [Std.HashMap.get?_eq_getElem?, Std.HashMap.getElem_insert, hne] - · simp [Std.HashMap.get?_eq_getElem?] - -private theorem evalAnd_false_left {cfg : Config} {solm : Frame} {evm : EVM.State} - {lhs rhs : Expr} - (hleft : evalExpr? cfg solm evm lhs = .ok (.bool false)) : - evalExpr? cfg solm evm (.binary .and lhs rhs) = .ok (.bool false) := by - simp [evalExpr?, hleft, EvalResult.bind, bind, pure] - -private theorem evalAnd_true_right_false {cfg : Config} {solm : Frame} {evm : EVM.State} - {lhs rhs : Expr} - (hleft : evalExpr? cfg solm evm lhs = .ok (.bool true)) - (hright : evalExpr? cfg solm evm rhs = .ok (.bool false)) : - evalExpr? cfg solm evm (.binary .and lhs rhs) = .ok (.bool false) := by - simp [evalExpr?, hleft, hright, EvalResult.bind, bind, pure] - -private theorem evalBinaryEq_of {cfg : Config} {solm : Frame} {evm : EVM.State} - {lhs rhs : Expr} {v₁ v₂ value : Value} - (hleft : evalExpr? cfg solm evm lhs = .ok v₁) - (hright : evalExpr? cfg solm evm rhs = .ok v₂) - (hop : evalBinaryOp? .eq v₁ v₂ = .ok value) : - evalExpr? cfg solm evm (.binary .eq lhs rhs) = .ok value := by - simp [evalExpr?, hleft, hright, hop, EvalResult.bind, bind] - -theorem attesterEvalMultiLengthGuardFalse (v : AttesterImmutables) - (evm : EVM.State) (locals : Store) {secondName : Ident} - {schemas second : List Value} - (hSecond : - (locals.insert "schemaLength" (.int (Int.ofNat schemas.length)))[secondName]? = - some (.array second)) - (hbad : schemas.length = 0 ∨ schemas.length ≠ second.length) : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.binary .and - (.binary .ne (.var "schemaLength") (.intLit 0)) - (.binary .eq (.var "schemaLength") (lenLocal secondName))) = - .ok (.bool false) := by - rcases hbad with hzero | hne - · have hleft : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.binary .ne (.var "schemaLength") (.intLit 0)) = - .ok (.bool false) := by - simp [evalExpr?, evalBinaryOp?, hzero, - EvalResult.bind, EvalResult.ofOption, bind, pure] - exact evalAnd_false_left hleft - · by_cases hzero : schemas.length = 0 - · have hleft : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.binary .ne (.var "schemaLength") (.intLit 0)) = - .ok (.bool false) := by - simp [evalExpr?, evalBinaryOp?, hzero, - EvalResult.bind, EvalResult.ofOption, bind, pure] - exact evalAnd_false_left hleft - · have hleft : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.binary .ne (.var "schemaLength") (.intLit 0)) = - .ok (.bool true) := by - simp [evalExpr?, evalBinaryOp?, hzero, - EvalResult.bind, EvalResult.ofOption, bind, pure] - have hright : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.binary .eq (.var "schemaLength") (lenLocal secondName)) = - .ok (.bool false) := by - have hvar : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.var "schemaLength") = - .ok (.int (Int.ofNat schemas.length)) := by - simp [evalExpr?, EvalResult.ofOption] - have hlen : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (lenLocal secondName) = - .ok (.int (Int.ofNat second.length)) := by - simp [evalExpr?, lenLocal, localRef, readLocalPath?, - EvalResult.bind, bind, pure] - have hSecond' : - (Std.HashMap.insert locals "schemaLength" (Value.int ↑schemas.length))[secondName]? = - some (.array second) := by - simpa using hSecond - rw [hSecond'] - have hop : - evalBinaryOp? .eq (.int (Int.ofNat schemas.length)) - (.int (Int.ofNat second.length)) = .ok (.bool false) := by - simpa [evalBinaryOp?] using hne - exact evalBinaryEq_of hvar hlen hop - exact evalAnd_true_right_false hleft hright - -theorem attesterBodyReverts_nonPayable (v : AttesterImmutables) (t : TransitionDecl) - (ht : t ∈ (contract v).transitions) (evm : EVM.State) (callargs : Store) - (hwv : evm.executionEnv.weiValue ≠ ⟨0⟩) : - ExecTransitionBody (config v) (contract v) evm callargs t.body .reverted := by - simp [contract, transitions] at ht - rcases ht with rfl | rfl | rfl | rfl <;> exact bodyReverts_nonPayable hwv - -/-- `callvalue != 0` reverts in the shared non-payable guard before ABI dispatch. -/ -theorem attesterNonPayable {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (v : AttesterImmutables) {code : ByteArray} - (hpatch : patchRuntime attesterBytecode (patches v) = some code) - (hcode : I.code = code) - (hwv : I.weiValue ≠ ⟨0⟩) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hpatched : code = patchedRuntime v := code_eq_patchedRuntime_of_patch hpatch - have hIcode : I.code = patchedRuntime v := hcode.trans hpatched - exact (attesterX_callvalue_ne (g := Sat256.ofUInt256 g) v hIcode hwv).reEquivElim hIcode - fun _ _ hrev => by - by_cases hdisp : dispatchMsg (contract v) I.calldata = none - · exact reEquiv_noDispatch hdisp hrev - · obtain ⟨t, ht⟩ := Option.ne_none_iff_exists'.mp hdisp - have htmem : t ∈ (contract v).transitions := by - rw [dispatchMsg_eq_dispatchList (contract v) I.calldata (by rfl)] at ht - exact dispatchList_some_mem ht - by_cases hdec : decodeCalldataWithMode (config v).abiDecodeMode - (t.params.map Param.name) (transitionSignature t).paramTypes I.calldata = none - · exact reEquiv_decodingFailed ht hdec hrev - · obtain ⟨callargs, hca⟩ := Option.ne_none_iff_exists'.mp hdec - exact reEquiv_execution ht hca - (attesterBodyReverts_nonPayable v t htmem - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - callargs (by simp only [initState]; exact hwv)) - (by rw [hrev]; exact execResultsEquiv.revert rfl rfl) - -/-- Calldata shorter than the 4-byte selector falls through to the shared revert path. -/ -theorem attesterNoDispatchShort {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (v : AttesterImmutables) {code : ByteArray} - (hpatch : patchRuntime attesterBytecode (patches v) = some code) - (hcode : I.code = code) - (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hwv : I.weiValue = ⟨0⟩) - (hshort : I.calldata.size < 4) - (_hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hpatched : code = patchedRuntime v := code_eq_patchedRuntime_of_patch hpatch - have hIcode : I.code = patchedRuntime v := hcode.trans hpatched - exact (attesterX_short (g := Sat256.ofUInt256 g) v hIcode hwv hshort) - |>.reEquivNoDispatch hIcode (attesterDispatch_none_short v hshort) - -/-- No public Attester selector matched, so the dispatcher reaches the shared revert path. -/ -theorem attesterNoDispatchNoMatch {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (v : AttesterImmutables) {code : ByteArray} - (hpatch : patchRuntime attesterBytecode (patches v) = some code) - (hcode : I.code = code) - (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = false) - (hrevoke : (attesterRevokeSelBytes == I.calldata.extract 0 4) = false) - (_hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hpatched : code = patchedRuntime v := code_eq_patchedRuntime_of_patch hpatch - have hIcode : I.code = patchedRuntime v := hcode.trans hpatched - exact (attesterX_noMatch (g := Sat256.ofUInt256 g) v hIcode hwv hsz4 hsize - hmultiRevoke hmultiAttest hattest hrevoke) - |>.reEquivNoDispatch hIcode - (attesterDispatch_none_nomatch v hmultiRevoke hmultiAttest hattest hrevoke) - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/Constructor.lean b/Benchmarks/EAS/Attester/Constructor.lean deleted file mode 100644 index 34cd5076..00000000 --- a/Benchmarks/EAS/Attester/Constructor.lean +++ /dev/null @@ -1,936 +0,0 @@ -import Benchmarks.EAS.Attester.Common -import Reasoning.Initcode -import Solm.Equiv - -/-! -# EAS Attester constructor correctness stub - -Parameterized over the constructor-set immutable `_eas`. The constructor returns runtime bytecode -with `_eas` patched into the template at the offsets recorded in `Immutables.lean`; the proof is -left as the benchmark target. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -set_option maxHeartbeats 1500000 -set_option maxRecDepth 10000 - -noncomputable def attesterCtorTail (eas : EVM.Address) : ByteArray := - (EVM.Word.toBytesBE (EVM.Word.ofNat eas.toNat)).toByteArray - -noncomputable def attesterCtorCode (eas : EVM.Address) : ByteArray := - attesterCreationBytecode ++ attesterCtorTail eas - -def attesterCtorArgLocals (v : AttesterImmutables) (eas : EVM.Address) : Store := - Std.HashMap.ofList - (List.zip ((contract v).ctor.params.map Param.name) [.address eas]) - -def attesterCtorFinalLocals (v : AttesterImmutables) (eas : EVM.Address) : Store := - (attesterCtorArgLocals v eas).insert "imm_eas" (.address eas) - -theorem attesterCtorDeployment_shape {args : List Value} {deployedInitcode : ByteArray} - (v : AttesterImmutables) : - (config v).selfDeployment attesterCreationBytecode args = some deployedInitcode → - ∃ eas : EVM.Address, - args = [.address eas] ∧ - deployedInitcode = attesterCreationBytecode ++ attesterCtorTail eas := by - intro h - cases args with - | nil => - simp [config, genSolidityConstructorDeployment, constructorDecl, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, addr, - staticABIEncodedSize?, isDynamicABIType] at h - | cons arg rest => - cases rest with - | cons _ _ => - cases arg <;> - simp [config, genSolidityConstructorDeployment, constructorDecl, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, addr, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - | nil => - cases arg with - | address eas => - simp [config, genSolidityConstructorDeployment, constructorDecl, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, addr, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - refine ⟨eas, rfl, ?_⟩ - simpa [attesterCtorTail] using h.symm - | _ => - simp [config, genSolidityConstructorDeployment, constructorDecl, - encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, addr, - staticABIEncodedSize?, isDynamicABIType, encodeABIValue?, encodeABIWord?] at h - -theorem attesterCtorArgLocals_get_eas (v : AttesterImmutables) (eas : EVM.Address) : - (attesterCtorArgLocals v eas).get? "eas" = some (.address eas) := by - grind [attesterCtorArgLocals, contract, constructorDecl] - -theorem attesterCtorFinalLocals_get_eas (v : AttesterImmutables) (eas : EVM.Address) : - (attesterCtorFinalLocals v eas).get? "eas" = some (.address eas) := by - grind [attesterCtorFinalLocals, attesterCtorArgLocals, contract, constructorDecl] - -theorem attesterCtorFinalLocals_get_imm_eas (v : AttesterImmutables) (eas : EVM.Address) : - (attesterCtorFinalLocals v eas).get? "imm_eas" = some (.address eas) := by - grind [attesterCtorFinalLocals, attesterCtorArgLocals, contract, constructorDecl] - -theorem attesterCtorRuntimeCodeOf (v : AttesterImmutables) (eas : EVM.Address) : - runtimeCodeOf attesterBytecode (attesterCtorFinalLocals v eas) = - some (patchedRuntime { eas := eas }) := by - unfold runtimeCodeOf patchesFrom offsets wordBytes? - simp [List.foldrM] - rw [show (attesterCtorFinalLocals v eas)["imm_eas"]? = some (.address eas) by - exact attesterCtorFinalLocals_get_imm_eas v eas] - simp [valueToWord] - simpa [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup_cons] using - (patchRuntime_eq_patchedRuntime (v := { eas := eas })) - -theorem evalExpr_ctor_eas_ne_zero_true (v : AttesterImmutables) (evm : EVM.State) - (eas : EVM.Address) (hne : eas ≠ .ofNat 0) : - evalExpr? (config v) { contract := contract v, locals := attesterCtorArgLocals v eas } evm - (.binary .ne (.var "eas") zeroAddr) = .ok (.bool true) := by - simp only [zeroAddr, addrSt, evalExpr?, castValue?, EvalResult.ofOption, - EvalResult.bind, bind, pure] - rw [attesterCtorArgLocals_get_eas] - simp [evalBinaryOp?, hne] - -theorem evalExpr_ctor_eas_ne_zero_false (v : AttesterImmutables) (evm : EVM.State) - (eas : EVM.Address) (heq : eas = .ofNat 0) : - evalExpr? (config v) { contract := contract v, locals := attesterCtorArgLocals v eas } evm - (.binary .ne (.var "eas") zeroAddr) = .ok (.bool false) := by - simp only [zeroAddr, addrSt, evalExpr?, castValue?, EvalResult.ofOption, - EvalResult.bind, bind, pure] - rw [attesterCtorArgLocals_get_eas] - simp [evalBinaryOp?, heq] - -theorem attesterCtorBodyReturns (v : AttesterImmutables) (evm : EVM.State) - (eas : EVM.Address) (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hne : eas ≠ .ofNat 0) : - ExecTransitionBody (config v) (contract v) evm - (attesterCtorArgLocals v eas) (contract v).ctor.body - (.returned - { contract := contract v - locals := attesterCtorFinalLocals v eas } - evm none) := by - simp only [contract, constructorDecl, nonpayable] - refine ExecFuncBody.execBlockOK ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue - (evalExpr_ctor_eas_ne_zero_true v evm eas hne)) ?_ - simpa [attesterCtorFinalLocals] using - (ExecBlock.consNormal (ExecStmt.letDecl (value := .address eas) (by - show evalExpr? (config v) - { contract := contract v, locals := attesterCtorArgLocals v eas } evm - (.var "eas") = .ok (.address eas) - have hget : (attesterCtorArgLocals v eas).get? "eas" = some (.address eas) := - attesterCtorArgLocals_get_eas v eas - simp only [evalExpr?, EvalResult.ofOption] - rw [hget])) ExecBlock.nil) - -theorem attesterCtorBodyReverts_zero (v : AttesterImmutables) (evm : EVM.State) - (eas : EVM.Address) (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (heq : eas = .ofNat 0) : - ExecTransitionBody (config v) (contract v) evm - (attesterCtorArgLocals v eas) (contract v).ctor.body .reverted := by - simp only [contract, constructorDecl, nonpayable] - refine ExecFuncBody.execBlockRevert ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) ?_ - exact ExecBlock.consRevert (ExecStmt.requireFalse - (evalExpr_ctor_eas_ne_zero_false v evm eas heq)) - -theorem attesterSolmCtorExecSuccess - {createdAccounts : Batteries.RBSet AccountAddress compare} - {genesisBlockHeader : BlockHeader} - {blocks : ProcessedBlocks} - {σ : AccountMap} - {σ₀ : AccountMap} - {g : UInt256} - {A : Substate} - {I : ExecutionEnv} - (v : AttesterImmutables) (eas : EVM.Address) - (hwv : I.weiValue = ⟨0⟩) (hne : eas ≠ .ofNat 0) : - solmCtorExec (config v) (contract v) [.address eas] - createdAccounts genesisBlockHeader blocks σ σ₀ g A I - (.returned - { contract := contract v - locals := attesterCtorFinalLocals v eas } - (initState createdAccounts genesisBlockHeader blocks σ σ₀ (Sat256.ofUInt256 g) A I) - none) := by - refine solmCtorExec.intro - (evmState := initState createdAccounts genesisBlockHeader blocks σ σ₀ (Sat256.ofUInt256 g) A I) - (argsStore := attesterCtorArgLocals v eas) - ?_ rfl ?_ ?_ - · rfl - · simp [attesterCtorArgLocals, contract, constructorDecl] - · exact attesterCtorBodyReturns v _ eas (by simp [initState, hwv]) hne - -theorem attesterSolmCtorExecReverts_zero - {createdAccounts : Batteries.RBSet AccountAddress compare} - {genesisBlockHeader : BlockHeader} - {blocks : ProcessedBlocks} - {σ : AccountMap} - {σ₀ : AccountMap} - {g : UInt256} - {A : Substate} - {I : ExecutionEnv} - (v : AttesterImmutables) (eas : EVM.Address) - (hwv : I.weiValue = ⟨0⟩) (heq : eas = .ofNat 0) : - solmCtorExec (config v) (contract v) [.address eas] - createdAccounts genesisBlockHeader blocks σ σ₀ g A I .reverted := by - refine solmCtorExec.intro - (evmState := initState createdAccounts genesisBlockHeader blocks σ σ₀ (Sat256.ofUInt256 g) A I) - (argsStore := attesterCtorArgLocals v eas) - ?_ rfl ?_ ?_ - · rfl - · simp [attesterCtorArgLocals, contract, constructorDecl] - · exact attesterCtorBodyReverts_zero v _ eas (by simp [initState, hwv]) heq - -theorem attesterSolmCtorExecReverts_nonpayable - {createdAccounts : Batteries.RBSet AccountAddress compare} - {genesisBlockHeader : BlockHeader} - {blocks : ProcessedBlocks} - {σ : AccountMap} - {σ₀ : AccountMap} - {g : UInt256} - {A : Substate} - {I : ExecutionEnv} - (v : AttesterImmutables) (eas : EVM.Address) - (hwv : I.weiValue ≠ ⟨0⟩) : - solmCtorExec (config v) (contract v) [.address eas] - createdAccounts genesisBlockHeader blocks σ σ₀ g A I .reverted := by - refine solmCtorExec.intro - (evmState := initState createdAccounts genesisBlockHeader blocks σ σ₀ (Sat256.ofUInt256 g) A I) - (argsStore := attesterCtorArgLocals v eas) - ?_ rfl ?_ ?_ - · rfl - · simp [attesterCtorArgLocals, contract, constructorDecl] - · simpa [contract, constructorDecl, nonpayable] using - (bodyReverts_nonPayable (cfg := config v) (contract := contract v) - (evm := initState createdAccounts genesisBlockHeader blocks σ σ₀ - (Sat256.ofUInt256 g) A I) - (locals := attesterCtorArgLocals v eas) - (rest := - [ .require (.binary .ne (.var "eas") zeroAddr), - .letDecl "imm_eas" (some addr) (.var "eas") ]) - (by simp [initState, hwv])) - -theorem attesterCtorCreation_decode_append (tail : ByteArray) (pc : UInt256) - (hpc : pc.toNat + 33 ≤ attesterCreationBytecode.size) : - decode (attesterCreationBytecode ++ tail) pc = - decode attesterCreationBytecode pc := - Reasoning.Theory.decode_append_left_window attesterCreationBytecode tail pc hpc - (by rw [attesterCreationBytecode_size]; norm_num) - -macro "attester_ctor_decode" : tactic => - `(tactic| - (first - | rw [attesterCtorCreation_decode_append _ _ (by - rw [attesterCreationBytecode_size] - native_decide)] - | (unfold attesterCtorCode; rw [attesterCtorCreation_decode_append _ _ (by - rw [attesterCreationBytecode_size] - native_decide)]); - native_decide)) - -macro "attester_ctor_jd" : tactic => - `(tactic| - (first - | (apply Reasoning.Theory.D_J_contains_append_left; native_decide) - | (unfold attesterCtorCode; apply Reasoning.Theory.D_J_contains_append_left; native_decide))) - -open Lean in -macro "attester_ctor_run " base:term " with " "[" steps:evmStep,* "]" : term => do - let mut acc := base - for s in steps.getElems do - match s with - | `(evmStep| raw $op:ident $args*) => - acc ← `($(acc).$op $args*) - | `(evmStep| $op:ident $args*) => - match op.getId with - | `jump => acc ← `($(acc).jump (by attester_ctor_decode) $(args[0]!) (by evm_ov)) - | `jumpiT => acc ← `($(acc).jumpiT (by attester_ctor_decode) $(args[0]!) $(args[1]!) - (by evm_ov)) - | `jumpiNT => acc ← `($(acc).jumpiNT (by attester_ctor_decode) $(args[0]!) (by evm_ov)) - | _ => acc ← `($(acc).$op $args* (by attester_ctor_decode) (by evm_ov)) - | _ => Macro.throwUnsupported - return acc - -noncomputable def attesterCtorFreePtrMem : ByteArray := - writeWord ByteArray.empty 64 (⟨160⟩ : UInt256) - -theorem write_from_gap_eq (src base : ByteArray) (srcAddr destAddr len : Nat) - (hlen : len ≠ 0) (hsrc : srcAddr + len ≤ src.size) (hge : base.size ≤ destAddr) - (_hgap : destAddr - base.size < USize.size) : - src.write srcAddr base destAddr len = - base ++ ffi.ByteArray.zeroes (destAddr - base.size) ++ - src.extract srcAddr (srcAddr + len) := by - apply ByteArray.ext - unfold ByteArray.write - rw [if_neg hlen, if_neg (show ¬ srcAddr ≥ src.size from by omega)] - have hcopy : min len (src.size - srcAddr) = len := by omega - have htail : min base.size (destAddr + len) - (destAddr + len) = 0 := by omega - simp only [hcopy, htail, ByteArray.data_copySlice, ByteArray.data_append, - ByteArray.data_extract] - have hpz : (ffi.ByteArray.zeroes (destAddr - base.size)).data.size = - destAddr - base.size := by - rw [show (ffi.ByteArray.zeroes (destAddr - base.size)).data.size = - (ffi.ByteArray.zeroes (destAddr - base.size)).size from rfl, - ByteArray_zeroes_size] - have hDsz : - (base.data ++ - (ffi.ByteArray.zeroes (destAddr - base.size)).data).size = - destAddr := by - rw [Array.size_append, hpz, show base.data.size = base.size from rfl] - omega - rw [show (ffi.ByteArray.zeroes 0).data = (#[] : Array UInt8) from by - rw [zeroes_zero (n := 0) (by rfl)] - rfl] - simp only [Array.append_empty, Nat.add_zero] - rw [show min len (src.data.size - srcAddr) = len by - have : src.data.size = src.size := rfl - omega] - rw [Array.extract_eq_self_of_le (by rw [hDsz])] - rw [show (base.data ++ - (ffi.ByteArray.zeroes (destAddr - base.size)).data).extract - (destAddr + len) = (#[] : Array UInt8) from by - apply Array.extract_eq_empty_of_le - rw [hDsz] - omega] - simp [Array.append_assoc] - -theorem write0_eq_extract_from_of_base_le (src base : ByteArray) (srcAddr len : Nat) - (hlen : len ≠ 0) (hsrc : srcAddr + len ≤ src.size) (hbase : base.size ≤ len) : - src.write srcAddr base 0 len = src.extract srcAddr (srcAddr + len) := by - apply ByteArray.ext - rw [write0_data_from src base srcAddr len hlen hsrc] - rw [show base.data.extract len base.data.size = (#[] : Array UInt8) from by - apply Array.extract_eq_empty_of_le - rw [show base.data.size = base.size from rfl] - simpa using hbase] - simp - -theorem attesterCtorTail_size (eas : EVM.Address) : - (attesterCtorTail eas).size = 32 := by - unfold attesterCtorTail - rw [word_toBytesBE_toByteArray_size] - -theorem attesterCtorCode_size (eas : EVM.Address) : - (attesterCtorCode eas).size = 3403 := by - rw [attesterCtorCode, ByteArray.size_append, attesterCreationBytecode_size, - attesterCtorTail_size] - -theorem attesterCtorCode_tail_window (eas : EVM.Address) : - (attesterCtorCode eas).extract 3371 (3371 + 32) = attesterCtorTail eas := by - unfold attesterCtorCode - exact extract_append_right' attesterCreationBytecode (attesterCtorTail eas) 3371 - (3371 + 32) attesterCreationBytecode_size.symm - (by rw [attesterCreationBytecode_size, attesterCtorTail_size]) - -theorem attesterCtorCreation_runtime_window : - attesterCreationBytecode.extract 185 (185 + 3186) = attesterBytecode := by - native_decide +revert - -theorem attesterCtorCode_runtime_window (eas : EVM.Address) : - (attesterCtorCode eas).extract 185 (185 + 3186) = attesterBytecode := by - unfold attesterCtorCode - rw [extract_append_left attesterCreationBytecode (attesterCtorTail eas) 185 (185 + 3186) - (by rw [attesterCreationBytecode_size])] - exact attesterCtorCreation_runtime_window - -noncomputable def attesterCtorArgMem (eas : EVM.Address) : ByteArray := - attesterCtorFreePtrMem ++ ffi.ByteArray.zeroes 64 ++ attesterCtorTail eas - -noncomputable def attesterCtorArgFreeMem (eas : EVM.Address) : ByteArray := - writeWord (attesterCtorArgMem eas) 64 (⟨192⟩ : UInt256) - -theorem attesterCtorFreePtrMem_size : attesterCtorFreePtrMem.size = 96 := by - unfold attesterCtorFreePtrMem - rw [writeWord_size] - · rfl - · exact lt_usize _ (by norm_num) - -theorem attesterCtorArgMem_size (eas : EVM.Address) : - (attesterCtorArgMem eas).size = 192 := by - unfold attesterCtorArgMem - rw [ByteArray.size_append, ByteArray.size_append, attesterCtorFreePtrMem_size, - ByteArray_zeroes_size, attesterCtorTail_size] - -theorem attesterCtorArgFreeMem_size (eas : EVM.Address) : - (attesterCtorArgFreeMem eas).size = 192 := by - unfold attesterCtorArgFreeMem - rw [writeWord_size] - · rw [attesterCtorArgMem_size] - rfl - · rw [attesterCtorArgMem_size] - exact lt_usize _ (by norm_num) - -theorem attesterCtorFreePtrMem_mload64 : - (if (⟨64⟩ : UInt256).toNat ≥ attesterCtorFreePtrMem.size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 3 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (attesterCtorFreePtrMem.readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨160⟩ := by - apply mloadWordValue_of_readWithPadding - · rw [attesterCtorFreePtrMem_size] - decide - · decide - · change attesterCtorFreePtrMem.readWithPadding 64 32 = - UInt256.toByteArray (⟨160⟩ : UInt256) - unfold attesterCtorFreePtrMem - exact writeWord_read_back ByteArray.empty 64 (⟨160⟩ : UInt256) - (by exact lt_usize _ (by norm_num)) - -theorem attesterCtorArg_codecopy_mem (eas : EVM.Address) : - (attesterCtorCode eas).write 3371 attesterCtorFreePtrMem 160 32 = - attesterCtorArgMem eas := by - unfold attesterCtorArgMem - rw [write_from_gap_eq] - · rw [attesterCtorFreePtrMem_size] - rw [show 160 - 96 = 64 by norm_num] - rw [attesterCtorCode_tail_window] - · norm_num - · rw [attesterCtorCode_size] - · rw [attesterCtorFreePtrMem_size] - norm_num - · rw [attesterCtorFreePtrMem_size] - exact lt_usize _ (by norm_num) - -theorem attesterCtorArgMem_read160 (eas : EVM.Address) : - (attesterCtorArgMem eas).readWithPadding 160 32 = - UInt256.toByteArray (EVM.Word.ofNat eas.toNat) := by - rw [readWithPadding_eq_extract' _ 160 32 (by norm_num) (by norm_num) - (by rw [attesterCtorArgMem_size])] - unfold attesterCtorArgMem attesterCtorTail - set preBuf := attesterCtorFreePtrMem ++ ffi.ByteArray.zeroes 64 - have hpreBuf : preBuf.size = 160 := by - unfold preBuf - rw [ByteArray.size_append, attesterCtorFreePtrMem_size, ByteArray_zeroes_size] - rw [extract_append_right_window preBuf - (EVM.Word.toBytesBE (EVM.Word.ofNat eas.toNat)).toByteArray 160 (160 + 32) - (by rw [hpreBuf]), hpreBuf] - norm_num - have hself := - byteArray_extract_self (EVM.Word.toBytesBE (EVM.Word.ofNat eas.toNat)).toByteArray - simpa [word_toBytesBE_toByteArray_eq_toByteArray] using hself - -theorem attesterCtorArgFreeMem_read160 (eas : EVM.Address) : - (attesterCtorArgFreeMem eas).readWithPadding 160 32 = - UInt256.toByteArray (EVM.Word.ofNat eas.toNat) := by - unfold attesterCtorArgFreeMem - rw [writeWord_read_preserved] - · exact attesterCtorArgMem_read160 eas - · rw [attesterCtorArgMem_size] - exact lt_usize _ (by norm_num) - · right - constructor - · norm_num - · rw [attesterCtorArgMem_size] - -theorem attesterCtorArgFreeMem_mload64 (eas : EVM.Address) : - (if (⟨64⟩ : UInt256).toNat ≥ (attesterCtorArgFreeMem eas).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 6 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((attesterCtorArgFreeMem eas).readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨192⟩ := by - apply mloadWordValue_of_readWithPadding - · rw [attesterCtorArgFreeMem_size] - decide - · decide - · change (attesterCtorArgFreeMem eas).readWithPadding 64 32 = - UInt256.toByteArray (⟨192⟩ : UInt256) - unfold attesterCtorArgFreeMem - rw [writeWord_read_back] - rw [attesterCtorArgMem_size] - exact lt_usize _ (by norm_num) - -theorem attesterCtorArgFreeMem_mload160 (eas : EVM.Address) : - (if (⟨160⟩ : UInt256).toNat ≥ (attesterCtorArgFreeMem eas).size - ∨ (⟨160⟩ : UInt256) ≥ UInt256.ofNat 6 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((attesterCtorArgFreeMem eas).readWithPadding (⟨160⟩ : UInt256).toNat 32))) - = EVM.Word.ofNat eas.toNat := by - apply mloadWordValue_of_readWithPadding - · rw [attesterCtorArgFreeMem_size] - decide - · decide - · simpa [show (⟨160⟩ : UInt256).toNat = 160 from by decide] using - attesterCtorArgFreeMem_read160 eas - -noncomputable def attesterCtorDecodedMem (eas : EVM.Address) : ByteArray := - writeWord (attesterCtorArgFreeMem eas) 128 (EVM.Word.ofNat eas.toNat) - -noncomputable def attesterCtorPatchedRuntime (eas : EVM.Address) : ByteArray := - writeCascade attesterBytecode - [ (722, EVM.Word.ofNat eas.toNat), (1465, EVM.Word.ofNat eas.toNat), - (1598, EVM.Word.ofNat eas.toNat), (1939, EVM.Word.ofNat eas.toNat) ] - -noncomputable def attesterCtorInvalidEASMem (eas : EVM.Address) : ByteArray := - writeWord (attesterCtorArgFreeMem eas) 192 - (UInt256.shiftLeft (⟨1102841855⟩ : UInt256) ⟨225⟩) - -theorem attesterCtorDecodedMem_size (eas : EVM.Address) : - (attesterCtorDecodedMem eas).size = 192 := by - unfold attesterCtorDecodedMem - rw [writeWord_size] - · rw [attesterCtorArgFreeMem_size] - rfl - · rw [attesterCtorArgFreeMem_size] - exact lt_usize _ (by norm_num) - -theorem attesterCtorDecodedMem_read128 (eas : EVM.Address) : - (attesterCtorDecodedMem eas).readWithPadding 128 32 = - UInt256.toByteArray (EVM.Word.ofNat eas.toNat) := by - unfold attesterCtorDecodedMem - rw [writeWord_read_back] - rw [attesterCtorArgFreeMem_size] - exact lt_usize _ (by norm_num) - -theorem attesterCtorDecodedMem_mload128 (eas : EVM.Address) : - (if (⟨128⟩ : UInt256).toNat ≥ (attesterCtorDecodedMem eas).size - ∨ (⟨128⟩ : UInt256) ≥ UInt256.ofNat 6 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((attesterCtorDecodedMem eas).readWithPadding (⟨128⟩ : UInt256).toNat 32))) - = EVM.Word.ofNat eas.toNat := by - apply mloadWordValue_of_readWithPadding - · rw [attesterCtorDecodedMem_size] - decide - · decide - · simpa [show (⟨128⟩ : UInt256).toNat = 128 from by decide] using - attesterCtorDecodedMem_read128 eas - -theorem attesterCtorInvalidEASMem_size (eas : EVM.Address) : - (attesterCtorInvalidEASMem eas).size = 224 := by - unfold attesterCtorInvalidEASMem - rw [writeWord_size] - · rw [attesterCtorArgFreeMem_size] - rfl - · rw [attesterCtorArgFreeMem_size] - exact lt_usize _ (by norm_num) - -theorem attesterCtorInvalidEASMem_read64 (eas : EVM.Address) : - (attesterCtorInvalidEASMem eas).readWithPadding 64 32 = - UInt256.toByteArray (⟨192⟩ : UInt256) := by - unfold attesterCtorInvalidEASMem - rw [writeWord_read_preserved] - · unfold attesterCtorArgFreeMem - rw [writeWord_read_back] - rw [attesterCtorArgMem_size] - exact lt_usize _ (by norm_num) - · rw [attesterCtorArgFreeMem_size] - exact lt_usize _ (by norm_num) - · left - constructor - · norm_num - · rw [attesterCtorArgFreeMem_size] - norm_num - -theorem attesterCtorInvalidEASMem_mload64 (eas : EVM.Address) : - (if (⟨64⟩ : UInt256).toNat ≥ (attesterCtorInvalidEASMem eas).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 7 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((attesterCtorInvalidEASMem eas).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) - = ⟨192⟩ := by - apply mloadWordValue_of_readWithPadding - · rw [attesterCtorInvalidEASMem_size] - decide - · decide - · simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] using - attesterCtorInvalidEASMem_read64 eas - -theorem attesterCtorRuntime_codecopy_mem (eas : EVM.Address) : - (attesterCtorCode eas).write 185 (attesterCtorDecodedMem eas) 0 3186 = - attesterBytecode := by - rw [write0_eq_extract_from_of_base_le] - · exact attesterCtorCode_runtime_window eas - · norm_num - · rw [attesterCtorCode_size] - norm_num - · rw [attesterCtorDecodedMem_size] - norm_num - -theorem attesterCtorPatchedRuntime_eq_patchedRuntime (eas : EVM.Address) : - attesterCtorPatchedRuntime eas = patchedRuntime { eas := eas } := by - unfold attesterCtorPatchedRuntime patchedRuntime runtimeWrites - rfl - -theorem attesterCtorPatchedRuntime_size (eas : EVM.Address) : - (attesterCtorPatchedRuntime eas).size = 3186 := by - unfold attesterCtorPatchedRuntime - exact writeCascade_size_of_base attesterBytecode - [ (722, EVM.Word.ofNat eas.toNat), (1465, EVM.Word.ofNat eas.toNat), - (1598, EVM.Word.ofNat eas.toNat), (1939, EVM.Word.ofNat eas.toNat) ] - (base := 3186) (out := 3186) - (by native_decide) (by simp [WriteGapsOk]) (by simp [writeCascadeSize]) - -theorem attesterCtorPatchedRuntime_read (eas : EVM.Address) : - (attesterCtorPatchedRuntime eas).readWithPadding 0 3186 = - patchedRuntime { eas := eas } := by - rw [readWithPadding_eq_extract' _ 0 3186 (by norm_num) (by norm_num) - (by rw [attesterCtorPatchedRuntime_size])] - rw [show 3186 = (attesterCtorPatchedRuntime eas).size by - rw [attesterCtorPatchedRuntime_size]] - have hself := byteArray_extract_self (attesterCtorPatchedRuntime eas) - simpa [attesterCtorPatchedRuntime_eq_patchedRuntime, Nat.zero_add] using hself - -theorem attesterEasWord_canonical (eas : EVM.Address) : - (EVM.Word.ofNat eas.toNat).toNat < EVM.addressModulus := by - change (UInt256.ofNat eas.val).toNat < EVM.addressModulus - rw [UInt256.toNat_ofNat_of_lt] - · change eas.val < AccountAddress.size - exact eas.isLt - · exact lt_of_lt_of_le eas.isLt (by decide) - -theorem attesterEasWord_toNat (eas : EVM.Address) : - (EVM.Word.ofNat eas.toNat).toNat = eas.toNat := by - change (UInt256.ofNat eas.val).toNat = eas.val - rw [UInt256.toNat_ofNat_of_lt] - exact lt_of_lt_of_le eas.isLt (by decide) - -theorem attesterEasWord_clean (eas : EVM.Address) : - UInt256.land (EVM.Word.ofNat eas.toNat) solcAddrMask = - EVM.Word.ofNat eas.toNat := - solcAddrMask_clean (attesterEasWord_canonical eas) - -theorem attesterEasWord_ne_zero (eas : EVM.Address) (hne : eas ≠ .ofNat 0) : - EVM.Word.ofNat eas.toNat ≠ (⟨0⟩ : UInt256) := by - intro hzero - apply hne - apply Fin.ext - have hto := congrArg UInt256.toNat hzero - rw [attesterEasWord_toNat eas] at hto - simpa [AccountAddress.ofNat] using hto - -theorem attesterEasWord_zero (eas : EVM.Address) (heq : eas = .ofNat 0) : - EVM.Word.ofNat eas.toNat = (⟨0⟩ : UInt256) := by - subst eas - change UInt256.ofNat (Fin.ofNat AccountAddress.size 0).val = (⟨0⟩ : UInt256) - native_decide - -theorem attesterCtorInitcodeToBody - {createdAccounts : Batteries.RBSet AccountAddress compare} - {genesisBlockHeader : BlockHeader} - {blocks : ProcessedBlocks} - {σ : AccountMap} - {σ₀ : AccountMap} - {A : Substate} - {I : ExecutionEnv} - {g : Sat256} - (eas : EVM.Address) - (hcode : I.code = attesterCtorCode eas) - (hwv : I.weiValue = ⟨0⟩) : - ∃ k C, RD (attesterCtorCode eas) I g - (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) ⟨43⟩ - [EVM.Word.ofNat eas.toNat] - (attesterCtorArgFreeMem eas) (UInt256.ofNat 6) - ByteArray.empty (createdAccounts, σ) k C := by - have rd0 : - RD (attesterCtorCode eas) I g - (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) ⟨0⟩ [] - ByteArray.empty (UInt256.ofNat 0) ByteArray.empty (createdAccounts, σ) 0 0 := - RD.initState hcode - have rd97 := attester_ctor_run rd0 with [ - push1 ⟨160⟩, push1 ⟨64⟩, - raw mstore 9 attesterCtorFreePtrMem (UInt256.ofNat 3) (by attester_ctor_decode) - mem_cost - (by - unfold attesterCtorFreePtrMem Reasoning.Theory.writeWord - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]) - (by decide) (by evm_ov), - callvalue, dup1, iszero, push1 ⟨14⟩, - jumpiT (by rw [hwv]; decide) (by attester_ctor_jd), - jumpdest, pop, push1 ⟨64⟩, - raw mload 0 ⟨160⟩ (UInt256.ofNat 3) (by attester_ctor_decode) - mem_cost attesterCtorFreePtrMem_mload64 (by decide) (by evm_ov), - push2 ⟨3371⟩, codesize, sub, dup1, push2 ⟨3371⟩, dup4, - raw codecopy 9 (attesterCtorArgMem eas) (UInt256.ofNat 6) - (by attester_ctor_decode) - (fun s haws hstks => by - set_option linter.unusedSimpArgs false in - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero, List.getElem!_cons_succ] - rw [attesterCtorCode_size] - decide) - (by - rw [show ((UInt256.ofNat (attesterCtorCode eas).size).sub - (⟨3371⟩ : UInt256)).toNat = 32 by - rw [attesterCtorCode_size] - decide] - exact attesterCtorArg_codecopy_mem eas) - (by - rw [attesterCtorCode_size] - decide) - (by evm_ov), - dup2, add, push1 ⟨64⟩, dup2, swap1, - raw mstore 0 (attesterCtorArgFreeMem eas) (UInt256.ofNat 6) - (by attester_ctor_decode) mem_cost - (by - rw [show (⟨160⟩ : UInt256) + - (UInt256.ofNat (attesterCtorCode eas).size).sub ⟨3371⟩ = - (⟨192⟩ : UInt256) by - rw [attesterCtorCode_size] - decide] - unfold attesterCtorArgFreeMem Reasoning.Theory.writeWord - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]) - (by decide) (by evm_ov), - push1 ⟨43⟩, swap2, push1 ⟨97⟩, jump (by attester_ctor_jd)] - have rd43 := attester_ctor_run rd97 with [ - jumpdest, push0, push1 ⟨32⟩, dup3, dup5, sub, slt, iszero, - push1 ⟨112⟩, - jumpiT (by - rw [show (⟨160⟩ : UInt256) + - (UInt256.ofNat (attesterCtorCode eas).size).sub ⟨3371⟩ = - (⟨192⟩ : UInt256) by - rw [attesterCtorCode_size] - decide] - decide) (by attester_ctor_jd), - jumpdest, dup2, - raw mload 0 (EVM.Word.ofNat eas.toNat) (UInt256.ofNat 6) (by attester_ctor_decode) - mem_cost (attesterCtorArgFreeMem_mload160 eas) (by decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup2, and, dup2, eq, - push1 ⟨133⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] - rw [attesterEasWord_clean eas] - rw [uInt256_eq_self] - decide) (by attester_ctor_jd), - jumpdest, swap4, swap3, pop, pop, pop, jump (by attester_ctor_jd)] - exact ⟨_, _, rd43⟩ - -theorem attesterCtorInitcodeSuccess - {createdAccounts : Batteries.RBSet AccountAddress compare} - {genesisBlockHeader : BlockHeader} - {blocks : ProcessedBlocks} - {σ : AccountMap} - {σ₀ : AccountMap} - {A : Substate} - {I : ExecutionEnv} - {g : Sat256} - (eas : EVM.Address) - (hcode : I.code = attesterCtorCode eas) - (hwv : I.weiValue = ⟨0⟩) (hne : eas ≠ .ofNat 0) : - RDret (attesterCtorCode eas) g - (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) (createdAccounts, σ) - (patchedRuntime { eas := eas }) := by - obtain ⟨_, _, rd43⟩ := attesterCtorInitcodeToBody - (createdAccounts := createdAccounts) (genesisBlockHeader := genesisBlockHeader) - (blocks := blocks) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - eas hcode hwv - have rd140 := attester_ctor_run rd43 with [ - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup2, and, - push1 ⟨81⟩, - jumpiT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] - rw [attesterEasWord_clean eas] - exact attesterEasWord_ne_zero eas hne) (by attester_ctor_jd), - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, and, - push1 ⟨128⟩, - raw mstore 0 (attesterCtorDecodedMem eas) (UInt256.ofNat 6) - (by attester_ctor_decode) mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] - rw [solcAddrMask_clean_left (attesterEasWord_canonical eas)] - unfold attesterCtorDecodedMem Reasoning.Theory.writeWord - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide]) - (by decide) (by evm_ov), - push1 ⟨140⟩, jump (by attester_ctor_jd)] - exact attester_ctor_run rd140 with [ - jumpdest, push1 ⟨128⟩, - raw mload 0 (EVM.Word.ofNat eas.toNat) (UInt256.ofNat 6) - (by attester_ctor_decode) mem_cost (attesterCtorDecodedMem_mload128 eas) - (by decide) (by evm_ov), - push2 ⟨3186⟩, push2 ⟨185⟩, push0, - raw codecopy 301 attesterBytecode (UInt256.ofNat 100) - (by attester_ctor_decode) mem_cost (attesterCtorRuntime_codecopy_mem eas) - (by decide) (by evm_ov), - push0, dup2, dup2, push2 ⟨722⟩, add, - raw mstore 0 (writeWord attesterBytecode 722 (EVM.Word.ofNat eas.toNat)) - (UInt256.ofNat 100) - (by attester_ctor_decode) mem_cost - (by - unfold Reasoning.Theory.writeWord - rw [show ((⟨722⟩ : UInt256) + ⟨0⟩).toNat = 722 from by decide]) - (by decide) (by evm_ov), - dup2, dup2, push2 ⟨1465⟩, add, - raw mstore 0 - (writeWord (writeWord attesterBytecode 722 (EVM.Word.ofNat eas.toNat)) 1465 - (EVM.Word.ofNat eas.toNat)) - (UInt256.ofNat 100) - (by attester_ctor_decode) mem_cost - (by - unfold Reasoning.Theory.writeWord - rw [show ((⟨1465⟩ : UInt256) + ⟨0⟩).toNat = 1465 from by decide]) - (by decide) (by evm_ov), - dup2, dup2, push2 ⟨1598⟩, add, - raw mstore 0 - (writeWord - (writeWord (writeWord attesterBytecode 722 (EVM.Word.ofNat eas.toNat)) 1465 - (EVM.Word.ofNat eas.toNat)) 1598 (EVM.Word.ofNat eas.toNat)) - (UInt256.ofNat 100) - (by attester_ctor_decode) mem_cost - (by - unfold Reasoning.Theory.writeWord - rw [show ((⟨1598⟩ : UInt256) + ⟨0⟩).toNat = 1598 from by decide]) - (by decide) (by evm_ov), - push2 ⟨1939⟩, add, - raw mstore 0 (attesterCtorPatchedRuntime eas) (UInt256.ofNat 100) - (by attester_ctor_decode) mem_cost - (by - simp [attesterCtorPatchedRuntime, Reasoning.Theory.writeCascade, - Reasoning.Theory.writeWord, - show ((⟨1939⟩ : UInt256) + ⟨0⟩).toNat = 1939 from by decide]) - (by decide) (by evm_ov), - push2 ⟨3186⟩, push0, - raw ret 0 (patchedRuntime { eas := eas }) - (by attester_ctor_decode) mem_cost (attesterCtorPatchedRuntime_read eas) (by evm_ov)] - -theorem attesterCtorInitcodeZeroRevert - {createdAccounts : Batteries.RBSet AccountAddress compare} - {genesisBlockHeader : BlockHeader} - {blocks : ProcessedBlocks} - {σ : AccountMap} - {σ₀ : AccountMap} - {A : Substate} - {I : ExecutionEnv} - {g : Sat256} - (eas : EVM.Address) - (hcode : I.code = attesterCtorCode eas) - (hwv : I.weiValue = ⟨0⟩) (heq : eas = .ofNat 0) : - RDrev (attesterCtorCode eas) g - (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) := by - obtain ⟨_, _, rd43⟩ := attesterCtorInitcodeToBody - (createdAccounts := createdAccounts) (genesisBlockHeader := genesisBlockHeader) - (blocks := blocks) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - eas hcode hwv - have rd57 := attester_ctor_run rd43 with [ - jumpdest, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup2, and, - push1 ⟨81⟩, - jumpiNT (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide] - rw [attesterEasWord_clean eas] - rw [attesterEasWord_zero eas heq])] - exact attester_ctor_run rd57 with [ - push1 ⟨64⟩, - raw mload 0 ⟨192⟩ (UInt256.ofNat 6) - (by attester_ctor_decode) mem_cost (attesterCtorArgFreeMem_mload64 eas) - (by decide) (by evm_ov), - push4 ⟨1102841855⟩, push1 ⟨225⟩, shl, dup2, - raw mstore 3 (attesterCtorInvalidEASMem eas) (UInt256.ofNat 7) - (by attester_ctor_decode) mem_cost - (by - unfold attesterCtorInvalidEASMem Reasoning.Theory.writeWord - rw [show (⟨192⟩ : UInt256).toNat = 192 from by decide]) - (by decide) (by evm_ov), - push1 ⟨4⟩, add, push1 ⟨64⟩, - raw mload 0 ⟨192⟩ (UInt256.ofNat 7) - (by attester_ctor_decode) mem_cost (attesterCtorInvalidEASMem_mload64 eas) - (by decide) (by evm_ov), - dup1, swap2, sub, swap1, - raw rev 0 (by attester_ctor_decode) mem_cost (by evm_ov)] - -theorem attesterCtorInitcodeNonpayableRevert - {createdAccounts : Batteries.RBSet AccountAddress compare} - {genesisBlockHeader : BlockHeader} - {blocks : ProcessedBlocks} - {σ : AccountMap} - {σ₀ : AccountMap} - {A : Substate} - {I : ExecutionEnv} - {g : Sat256} - (tail : ByteArray) - (hcode : I.code = attesterCreationBytecode ++ tail) - (hwv : I.weiValue ≠ ⟨0⟩) : - RDrev (attesterCreationBytecode ++ tail) g - (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) := by - have rd0 : - RD (attesterCreationBytecode ++ tail) I g - (initState createdAccounts genesisBlockHeader blocks σ σ₀ g A I) ⟨0⟩ [] - ByteArray.empty (UInt256.ofNat 0) ByteArray.empty (createdAccounts, σ) 0 0 := - RD.initState hcode - have rd11 := attester_ctor_run rd0 with [ - push1 ⟨160⟩, push1 ⟨64⟩, - raw mstore 9 attesterCtorFreePtrMem (UInt256.ofNat 3) - (by attester_ctor_decode) - mem_cost - (by - unfold attesterCtorFreePtrMem Reasoning.Theory.writeWord - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]) - (by decide) (by evm_ov), - callvalue, dup1, iszero, push1 ⟨14⟩, jumpiNT (isZero_eq_zero_of_ne hwv)] - exact rd11.push0 (by attester_ctor_decode) (by simp) - |>.dup1 (by attester_ctor_decode) (by simp) - |>.rev 0 (by attester_ctor_decode) (fun s _ hstks => memExpRevert0 s hstks) (by simp) - -theorem attesterConstructorCorrect (v : AttesterImmutables) : - constructorEquivalenceWith (config v) attesterCreationBytecode (contract v) - (runtimeCodeOf attesterBytecode) := by - refine constructorEquivalenceWith.intro ?_ - intro createdAccounts genesisBlockHeader blocks σ_evm σ_solm σ₀ g A I - args deployedInitcode hdeploy hcode _hcalldata _hperm hσ - rcases attesterCtorDeployment_shape v hdeploy with ⟨eas, hargs, hdeployed⟩ - subst args - rw [hdeployed] at hcode - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hzero : eas = .ofNat 0 - · have hcodeCtor : I.code = attesterCtorCode eas := by - simpa [attesterCtorCode] using hcode - have hrd := attesterCtorInitcodeZeroRevert - (createdAccounts := createdAccounts) (genesisBlockHeader := genesisBlockHeader) - (blocks := blocks) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) eas hcodeCtor hwv hzero - rcases hrd.xiResult hcodeCtor with hOOG | ⟨g', o, hrev⟩ - · exact constructorEquivalenceForWith.outOfGas - (by simpa [Sat256.ofUInt256] using hOOG) - · refine constructorEquivalenceForWith.execution - (by simpa [Sat256.ofUInt256] using hrev) - (attesterSolmCtorExecReverts_zero - (createdAccounts := createdAccounts) (genesisBlockHeader := genesisBlockHeader) - (blocks := blocks) (σ := σ_solm) (σ₀ := σ₀) (g := g) (A := A) (I := I) - v eas hwv hzero) ?_ - exact ctorResultEquivWith.revert rfl rfl - · have hcodeCtor : I.code = attesterCtorCode eas := by - simpa [attesterCtorCode] using hcode - have hrd := attesterCtorInitcodeSuccess - (createdAccounts := createdAccounts) (genesisBlockHeader := genesisBlockHeader) - (blocks := blocks) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) eas hcodeCtor hwv hzero - rcases hrd.xiResult hcodeCtor with hOOG | ⟨g', A', hsuccess⟩ - · exact constructorEquivalenceForWith.outOfGas - (by simpa [Sat256.ofUInt256] using hOOG) - · refine constructorEquivalenceForWith.execution - (by simpa [Sat256.ofUInt256] using hsuccess) - (attesterSolmCtorExecSuccess - (createdAccounts := createdAccounts) (genesisBlockHeader := genesisBlockHeader) - (blocks := blocks) (σ := σ_solm) (σ₀ := σ₀) (g := g) (A := A) (I := I) - v eas hwv hzero) ?_ - refine ctorResultEquivWith.success rfl rfl ?_ ?_ ?_ - · rfl - · simpa [initState] using hσ - · exact attesterCtorRuntimeCodeOf v eas - · have hrd := attesterCtorInitcodeNonpayableRevert - (createdAccounts := createdAccounts) (genesisBlockHeader := genesisBlockHeader) - (blocks := blocks) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) - (tail := attesterCtorTail eas) hcode hwv - rcases hrd.xiResult hcode with hOOG | ⟨g', o, hrev⟩ - · exact constructorEquivalenceForWith.outOfGas - (by simpa [Sat256.ofUInt256] using hOOG) - · refine constructorEquivalenceForWith.execution - (by simpa [Sat256.ofUInt256] using hrev) - (attesterSolmCtorExecReverts_nonpayable - (createdAccounts := createdAccounts) (genesisBlockHeader := genesisBlockHeader) - (blocks := blocks) (σ := σ_solm) (σ₀ := σ₀) (g := g) (A := A) (I := I) - v eas hwv) ?_ - exact ctorResultEquivWith.revert rfl rfl - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/Correct.lean b/Benchmarks/EAS/Attester/Correct.lean deleted file mode 100644 index 9f566971..00000000 --- a/Benchmarks/EAS/Attester/Correct.lean +++ /dev/null @@ -1,65 +0,0 @@ -import Benchmarks.EAS.Attester.Constructor -import Benchmarks.EAS.Attester.Attest -import Benchmarks.EAS.Attester.MultiAttest -import Benchmarks.EAS.Attester.MultiRevoke -import Benchmarks.EAS.Attester.Revoke -import Solm.Equiv - -/-! -# EAS Attester benchmark correctness stub - -For each immutable value `v`, the deployed runtime is the solc template patched with `_eas` -(`patchRuntime attesterBytecode (patches v) = some code`), and runtime equivalence is stated -against `contract v`. Proofs are intentionally left as targets. --/ - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.EAS.Attester.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.EAS.Attester - -theorem attesterCorrect (v : AttesterImmutables) {code : ByteArray} - (hcode : patchRuntime attesterBytecode (patches v) = some code) : - runtimeEquivalence (config v) code (contract v) := by - refine runtimeEquivalence.intro ?_ - intro cA gh bl σ_evm σ_solm σ₀ g A I hIcode hsize hperm hAccounts - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hshort : I.calldata.size < 4 - · exact attesterNoDispatchShort v hcode hIcode hsize hperm hwv hshort hAccounts - · have hsz4 : 4 ≤ I.calldata.size := by omega - by_cases hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = true - · exact attesterMultiRevokeBodyCore v hcode hIcode hsize hperm hwv hmultiRevoke hAccounts - · have hmultiRevokeF : - (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false := - Bool.eq_false_of_not_eq_true hmultiRevoke - by_cases hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = true - · exact attesterMultiAttestBodyCore v hcode hIcode hsize hperm hwv - hmultiRevokeF hmultiAttest hAccounts - · have hmultiAttestF : - (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false := - Bool.eq_false_of_not_eq_true hmultiAttest - by_cases hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = true - · exact attesterAttestBodyCore v hcode hIcode hsize hperm hwv - hmultiRevokeF hmultiAttestF hattest hAccounts - · have hattestF : - (attesterAttestSelBytes == I.calldata.extract 0 4) = false := - Bool.eq_false_of_not_eq_true hattest - by_cases hrevoke : (attesterRevokeSelBytes == I.calldata.extract 0 4) = true - · exact attesterRevokeBodyCore v hcode hIcode hsize hperm hwv - hmultiRevokeF hmultiAttestF hattestF hrevoke hAccounts - · have hrevokeF : - (attesterRevokeSelBytes == I.calldata.extract 0 4) = false := - Bool.eq_false_of_not_eq_true hrevoke - exact attesterNoDispatchNoMatch v hcode hIcode hsize hperm hwv hsz4 - hmultiRevokeF hmultiAttestF hattestF hrevokeF hAccounts - · exact attesterNonPayable v hcode hIcode hwv - -theorem attesterContractCorrect (v : AttesterImmutables) {code : ByteArray} - (hcode : patchRuntime attesterBytecode (patches v) = some code) : - contractEquivalenceWith (config v) attesterCreationBytecode code (contract v) - (runtimeCodeOf attesterBytecode) := - contractEquivalenceWith.intro - (attesterConstructorCorrect v) - (attesterCorrect v hcode) - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/DynamicArray.lean b/Benchmarks/EAS/Attester/DynamicArray.lean deleted file mode 100644 index 1e6bc0f3..00000000 --- a/Benchmarks/EAS/Attester/DynamicArray.lean +++ /dev/null @@ -1,2800 +0,0 @@ -import Benchmarks.EAS.Attester.Common - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Reasoning.Reach - -theorem swap9_xstep {s : State} {code : ByteArray} - {pcv a b c d e f gg hh ii jj : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.SWAP9, .none)) - (hstk : s.machineState.stack = a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: t) - (hov : t.length + 10 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok (stSwap s (jj :: b :: c :: d :: e :: f :: gg :: hh :: ii :: a :: t), - .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.SWAP9, .none) := by - rw [hcode, hpc]; exact hdec - rw [← hcode, step_swap9 s hd, hstk] - have hov' : - ¬ ((a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: t).length - 10 + 10 > - 1024) := by - simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Gverylow, stSwap] - -theorem RD.swap9 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d e f gg hh ii jj : UInt256} {t : List UInt256} - (rd : RD code ee g s0 pc (a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: t) - mem aw rdata acc k C) - (hdec : decode code pc = some (.SWAP9, .none)) (hov : t.length + 10 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) - (jj :: b :: c :: d :: e :: f :: gg :: hh :: ii :: a :: t) - mem aw rdata acc (k + 1) (C + 3) := - rd.stepSwap (fun _ hc hp hs => swap9_xstep hc hp hdec hs hov) - -end Reasoning.Reach - -namespace Benchmarks.EAS.Attester - -/-! Shared facts for the solc dynamic-array ABI decoder used by the multi entrypoints. -/ - -/-- Trusted jump-destination fact for the successful length-word check in the shared dynamic-array decoder. -/ -axiom attesterDynamicArrayLengthOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2054⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the successful array-length max check. -/ -axiom attesterDynamicArrayLengthMaxOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2076⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the successful first-array payload bound check. -/ -axiom attesterDynamicArrayPayloadOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2102⟩ : UInt256) = true - -/-- Trusted jump-destination fact for returning from the first dynamic-array decoder call. -/ -axiom attesterDynamic2FirstArrayReturnJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2161⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the second top-level dynamic-offset max check. -/ -axiom attesterDynamic2SecondOffsetOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2191⟩ : UInt256) = true - -/-- Trusted jump-destination fact for returning from the second dynamic-array decoder call. -/ -axiom attesterDynamic2SecondArrayReturnJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2203⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the short-circuited `multiRevoke` body length guard. -/ -axiom attesterMultiRevokeLengthGuardJoinJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨206⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the successful `multiRevoke` body length guard. -/ -axiom attesterMultiRevokeLengthGuardOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨236⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the successful `multiRevoke` outer-array allocation bound. -/ -axiom attesterMultiRevokeAllocLengthMaxOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨261⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the `multiRevoke` outer-array initializer loop head. -/ -axiom attesterMultiRevokeOuterArrayInitLoopJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨291⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the short-circuited `multiAttest` body length guard. -/ -axiom attesterMultiAttestLengthGuardJoinJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨844⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the successful `multiAttest` body length guard. -/ -axiom attesterMultiAttestLengthGuardOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨874⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the successful `multiAttest` outer-array allocation bound. -/ -axiom attesterMultiAttestAllocLengthMaxOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨899⟩ : UInt256) = true - -/-- Trusted jump-destination fact for the `multiAttest` outer-array initializer loop head. -/ -axiom attesterMultiAttestOuterArrayInitLoopJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨929⟩ : UInt256) = true - -def attesterRequireSelectorMem : ByteArray := - (UInt256.toByteArray (UInt256.shiftLeft (⟨3036299187⟩ : UInt256) ⟨224⟩)).write - 0 solcFreePtrMem 128 32 - -theorem attesterRequireSelectorMem_size : attesterRequireSelectorMem.size = 160 := by - unfold attesterRequireSelectorMem - rw [toByteArray_write_eq _ _ _ (by rw [solcFreePtrMem_size]; omega) - (by rw [solcFreePtrMem_size]; exact lt_usize _ (by norm_num))] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray_zeroes_size, toByteArray_size, - solcFreePtrMem_size] - -theorem attesterRequireSelectorMem_read64 : - attesterRequireSelectorMem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by - unfold attesterRequireSelectorMem - rw [toByteArray_write_read_below_of_gap _ _ 128 64 - (by rw [solcFreePtrMem_size]) - (by omega) - (by rw [solcFreePtrMem_size]; exact lt_usize _ (by norm_num))] - exact solcFreePtrMem_read64 - -theorem attesterRequireSelectorMem_mload64 : - (if (⟨64⟩ : UInt256).toNat ≥ attesterRequireSelectorMem.size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 5 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - (attesterRequireSelectorMem.readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - ⟨128⟩ := - mloadFreePtrValue (by rw [attesterRequireSelectorMem_size]; decide) (by decide) - attesterRequireSelectorMem_read64 - -theorem decodeABIArrayDynamicElemsFrom_length {ty : ABIType} {n : Nat} - {bytes : List UInt8} {base headCursor headSize maxEnd : Nat} - {values : List Value} {endOffset : Nat} - (h : decodeABIArrayDynamicElemsFrom? ty n bytes base headCursor headSize maxEnd = - some (values, endOffset)) : - values.length = n := by - induction n generalizing headCursor maxEnd values endOffset with - | zero => - simp [decodeABIArrayDynamicElemsFrom?] at h - rcases h with ⟨hvalues, _⟩ - cases hvalues - rfl - | succ n ih => - rw [decodeABIArrayDynamicElemsFrom?] at h - cases hread : readNat? bytes (base + headCursor) with - | none => simp [hread] at h - | some relativeOffset => - simp [hread] at h - cases hval : decodeABIValue? ty bytes (base + relativeOffset) with - | none => simp [hval] at h - | some p => - rcases p with ⟨value, valueEnd⟩ - simp [hval] at h - cases hrest : - decodeABIArrayDynamicElemsFrom? ty n bytes base (headCursor + 32) - headSize (max maxEnd valueEnd) with - | none => simp [hrest] at h - | some q => - rcases q with ⟨valuesRest, restEnd⟩ - simp [hrest] at h - rcases h with ⟨hvalues, _hend⟩ - cases hvalues - rw [List.length_cons, ih hrest] - -theorem decodeABIArrayDynamicElems_length {ty : ABIType} {n : Nat} - {bytes : List UInt8} {base : Nat} {values : List Value} {endOffset : Nat} - (h : decodeABIArrayDynamicElems? ty n bytes base = some (values, endOffset)) : - values.length = n := by - unfold decodeABIArrayDynamicElems? at h - exact decodeABIArrayDynamicElemsFrom_length h - -theorem decodeABIValue_dynamicArray_dynamic_facts {elem : ABIType} - {bytes : List UInt8} {start : Nat} {values : List Value} {endOffset : Nat} - (h : decodeABIValue? (.dynamicArray (.dynamicArray elem)) bytes start = - some (.array values, endOffset)) : - ∃ len, readNat? bytes start = some len ∧ ¬ solcMaxU64 < len ∧ values.length = len := by - unfold decodeABIValue? at h - cases hread : readNat? bytes start with - | none => simp [hread] at h - | some len => - by_cases hmax : solcMaxU64 < len - · simp [hread, hmax] at h - · simp [hread, hmax, isDynamicABIType] at h - cases hvals : decodeABIArrayDynamicElems? (.dynamicArray elem) len bytes (start + 32) with - | none => simp [hvals] at h - | some p => - rcases p with ⟨vals, end'⟩ - simp [hvals] at h - rcases h with ⟨hvalues, _hend⟩ - refine ⟨len, rfl, hmax, ?_⟩ - rw [← hvalues] - exact decodeABIArrayDynamicElems_length hvals - -theorem decodeABIValue_dynamicArray_bytes32_facts - {bytes : List UInt8} {start : Nat} {values : List Value} {endOffset : Nat} - (h : decodeABIValue? (.dynamicArray bytes32) bytes start = - some (.array values, endOffset)) : - ∃ len, readNat? bytes start = some len ∧ ¬ solcMaxU64 < len ∧ values.length = len := by - unfold decodeABIValue? at h - cases hread : readNat? bytes start with - | none => simp [hread] at h - | some len => - by_cases hmax : solcMaxU64 < len - · simp [hread, hmax] at h - · simp [hread, hmax, bytes32, isDynamicABIType] at h - cases hstatic : - decodeABIArrayStaticElems? (ABIType.elem (ElemType.bytes bytes32Width)) len 32 bytes - (start + 32) with - | none => - change ((decodeABIArrayStaticElems? - (ABIType.elem (ElemType.bytes bytes32Width)) len 32 bytes (start + 32)).bind - fun p => some (Value.array p.1, p.2)) = - some (Value.array values, endOffset) at h - rw [hstatic] at h - simp at h - | some p => - rcases p with ⟨vals, end'⟩ - change ((decodeABIArrayStaticElems? - (ABIType.elem (ElemType.bytes bytes32Width)) len 32 bytes (start + 32)).bind - fun p => some (Value.array p.1, p.2)) = - some (Value.array values, endOffset) at h - rw [hstatic] at h - simp at h - rcases h with ⟨hvalues, _hend⟩ - refine ⟨len, rfl, hmax, ?_⟩ - rw [← hvalues] - obtain ⟨_hend, _hle, hlen⟩ := - decodeABIArrayStaticElems_elem32_facts - (elem := .bytes bytes32Width) (readNat?_some_length hread) hstatic - exact hlen - -theorem attesterDecodeCalldata_twoDynamicArrays_none_totalHuge {cd : ByteArray} - {name0 name1 : Ident} {elem0 elem1 : ABIType} - (hbig : 2 ^ 255 ≤ cd.size) : - decodeCalldata [name0, name1] [.dynamicArray elem0, .dynamicArray (.dynamicArray elem1)] - cd = none := by - unfold decodeCalldata - by_cases hlt4 : cd.toList.length < 4 - · rw [if_pos hlt4] - · rw [if_neg hlt4] - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have hdyn : - [ABIType.dynamicArray elem0, ABIType.dynamicArray (ABIType.dynamicArray elem1)].any - isDynamicABIType = true ∧ - 2 ^ 255 ≤ cd.toList.length := by - exact ⟨by simp [isDynamicABIType], by rw [htlen]; exact hbig⟩ - rw [if_pos hdyn] - -theorem attesterDecodeCalldata_twoDynamicArrays_none_firstLengthShort {cd : ByteArray} - {name0 name1 : Ident} {elem0 elem1 : ABIType} - (hsz68 : 68 ≤ cd.size) - (hoffMax : ¬ solcMaxU64 < (calldataWord cd 4).toNat) - (hshort : cd.size < 4 + (calldataWord cd 4).toNat + 32) : - decodeCalldata [name0, name1] [.dynamicArray elem0, .dynamicArray (.dynamicArray elem1)] - cd = none := by - unfold decodeCalldata - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - by_cases hdyn : - ([ABIType.dynamicArray elem0, ABIType.dynamicArray (ABIType.dynamicArray elem1)].any - isDynamicABIType = true ∧ - 2 ^ 255 ≤ cd.toList.length) - · rw [if_pos hdyn] - · rw [if_neg hdyn] - by_cases hargsHuge : - [ABIType.dynamicArray elem0, ABIType.dynamicArray (ABIType.dynamicArray elem1)].isEmpty = - false ∧ - 2 ^ 255 ≤ (cd.toList.drop 4).length - · rw [if_pos hargsHuge] - · rw [if_neg hargsHuge] - have hreadOff := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) - have hreadLen : - readNat? (cd.toList.drop 4) (calldataWord cd 4).toNat = none := by - unfold readNat? readWord? readBytes? - have hlen : - ¬ (((cd.toList.drop 4).drop (calldataWord cd 4).toNat).take 32).length = 32 := by - rw [List.length_take, List.length_drop, List.length_drop, htlen] - omega - rw [if_neg hlen] - rfl - simp [decodeCalldata.decodeArgs, decodeABIValues?, decodeABIValue?, isDynamicABIType, - abiTupleHeadSize?, bind, Option.bind, solcMaxLen, hreadOff, hoffMax, hreadLen] - -theorem attesterDecodeCalldata_twoDynamicArrays_none_firstLengthHuge {cd : ByteArray} - {name0 name1 : Ident} {elem0 elem1 : ABIType} - (hsz68 : 68 ≤ cd.size) - (hoffMax : ¬ solcMaxU64 < (calldataWord cd 4).toNat) - (hlenWord : 4 + (calldataWord cd 4).toNat + 32 ≤ cd.size) - (hlenHuge : solcMaxU64 < - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) : - decodeCalldata [name0, name1] [.dynamicArray elem0, .dynamicArray (.dynamicArray elem1)] - cd = none := by - unfold decodeCalldata - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - by_cases hdyn : - ([ABIType.dynamicArray elem0, ABIType.dynamicArray (ABIType.dynamicArray elem1)].any - isDynamicABIType = true ∧ - 2 ^ 255 ≤ cd.toList.length) - · rw [if_pos hdyn] - · rw [if_neg hdyn] - by_cases hargsHuge : - [ABIType.dynamicArray elem0, ABIType.dynamicArray (ABIType.dynamicArray elem1)].isEmpty = - false ∧ - 2 ^ 255 ≤ (cd.toList.drop 4).length - · rw [if_pos hargsHuge] - · rw [if_neg hargsHuge] - have hreadOff := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) - have hreadLen := readNat_drop4_dynamic_eq_calldataWord - (cd := cd) hlenWord - simp [decodeCalldata.decodeArgs, decodeABIValues?, decodeABIValue?, isDynamicABIType, - abiTupleHeadSize?, bind, Option.bind, solcMaxLen, hreadOff, hoffMax, hreadLen, - hlenHuge] - -theorem attesterDecodeCalldata_twoDynamicArrays_none_firstBytes32PayloadShort {cd : ByteArray} - {name0 name1 : Ident} {elem1 : ABIType} - (hsz68 : 68 ≤ cd.size) - (hoffMax : ¬ solcMaxU64 < (calldataWord cd 4).toNat) - (hlenWord : 4 + (calldataWord cd 4).toNat + 32 ≤ cd.size) - (hlenMax : ¬ solcMaxU64 < - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) - (hpayload : cd.size < - 4 + (calldataWord cd 4).toNat + 32 + - 32 * (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) : - decodeCalldata [name0, name1] [.dynamicArray bytes32, .dynamicArray (.dynamicArray elem1)] - cd = none := by - unfold decodeCalldata - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - by_cases hdyn : - ([ABIType.dynamicArray bytes32, ABIType.dynamicArray (ABIType.dynamicArray elem1)].any - isDynamicABIType = true ∧ - 2 ^ 255 ≤ cd.toList.length) - · rw [if_pos hdyn] - · rw [if_neg hdyn] - by_cases hargsHuge : - [ABIType.dynamicArray bytes32, ABIType.dynamicArray (ABIType.dynamicArray elem1)].isEmpty = - false ∧ - 2 ^ 255 ≤ (cd.toList.drop 4).length - · rw [if_pos hargsHuge] - · rw [if_neg hargsHuge] - rw [if_neg (by simp [solcTotalSizeDynamicGuard])] - have hreadOff := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) - have hreadLen := readNat_drop4_dynamic_eq_calldataWord - (cd := cd) hlenWord - have hstaticNone : - decodeABIArrayStaticElems? bytes32 - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat 32 - (cd.toList.drop 4) ((calldataWord cd 4).toNat + 32) = none := by - cases hstatic : - decodeABIArrayStaticElems? bytes32 - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat 32 - (cd.toList.drop 4) ((calldataWord cd 4).toNat + 32) with - | none => rfl - | some p => - rcases p with ⟨values, endOffset⟩ - have hstart : - (calldataWord cd 4).toNat + 32 ≤ (cd.toList.drop 4).length := by - rw [List.length_drop, htlen] - omega - obtain ⟨hend, hle, _hlen⟩ := - decodeABIArrayStaticElems_elem32_facts - (elem := .bytes bytes32Width) hstart hstatic - rw [hend] at hle - rw [List.length_drop, htlen] at hle - omega - have hstaticSize : staticABIEncodedSize? bytes32 = some 32 := by - native_decide - have hstaticSize' : - staticABIEncodedSize? (ABIType.elem (ElemType.bytes bytes32Width)) = some 32 := by - simpa [bytes32] using hstaticSize - have hstaticNone' : - decodeABIArrayStaticElems? (ABIType.elem (ElemType.bytes bytes32Width)) - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat 32 - (cd.toList.drop 4) ((calldataWord cd 4).toNat + 32) = none := by - simpa [bytes32] using hstaticNone - simp [decodeCalldata.decodeArgs, decodeABIValues?, decodeABIValue?, isDynamicABIType, - abiTupleHeadSize?, bind, Option.bind, solcMaxLen, bytes32, hreadOff, hoffMax, hreadLen, - hlenMax, hstaticSize', hstaticNone'] - -theorem readNat_drop4_32_eq_calldataWord {cd : ByteArray} - (hsz68 : 68 ≤ cd.size) : - readNat? (cd.toList.drop 4) 32 = some (calldataWord cd 36).toNat := by - unfold readNat? readWord? - have hread : readBytes? (cd.toList.drop 4) 32 32 = - some (((cd.toList.drop 4).drop 32).take 32) := by - unfold readBytes? - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have hlen : (((cd.toList.drop 4).drop 32).take 32).length = 32 := by - rw [List.length_take, List.length_drop, List.length_drop, htlen] - omega - rw [if_pos hlen] - rw [hread] - have hword : - bytesToWord (((cd.toList.drop 4).drop 32).take 32) = calldataWord cd 36 := by - have h := decode_word_at_eq cd 36 (by omega) (by norm_num) - simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using h - simp only [Option.bind, bind, hword] - rfl - -theorem readNat_drop4_at_eq_calldataWord {cd : ByteArray} {off : Nat} - (hlenWord : 4 + off + 32 ≤ cd.size) : - readNat? (cd.toList.drop 4) off = some (calldataWord cd (4 + off)).toNat := by - unfold readNat? readWord? - have hread : readBytes? (cd.toList.drop 4) off 32 = - some (((cd.toList.drop 4).drop off).take 32) := by - unfold readBytes? - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have hlen : (((cd.toList.drop 4).drop off).take 32).length = 32 := by - rw [List.length_take, List.length_drop, List.length_drop, htlen] - omega - rw [if_pos hlen] - rw [hread] - have hword : - bytesToWord (((cd.toList.drop 4).drop off).take 32) = - calldataWord cd (4 + off) := by - have h := decode_word_at_eq_any cd (4 + off) hlenWord - simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using h - simp only [Option.bind, bind, hword] - rfl - -theorem readNat_drop4_at_none_of_short {cd : ByteArray} {off : Nat} - (hshort : cd.size < 4 + off + 32) : - readNat? (cd.toList.drop 4) off = none := by - unfold readNat? readWord? readBytes? - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have hlen : - ¬ (((cd.toList.drop 4).drop off).take 32).length = 32 := by - rw [List.length_take, List.length_drop, List.length_drop, htlen] - omega - rw [if_neg hlen] - rfl - -theorem attesterDecodeCalldata_twoDynamicArrays_lengths {cd : ByteArray} {callargs : Store} - {name0 name1 : Ident} {elem1 : ABIType} - (hne : (name1 == name0) = false) - (hdec : decodeCalldata [name0, name1] [.dynamicArray bytes32, - .dynamicArray (.dynamicArray elem1)] cd = some callargs) : - ∃ xs ys : List Value, - callargs.get? name0 = some (.array xs) ∧ - callargs.get? name1 = some (.array ys) ∧ - xs.length = (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat ∧ - ys.length = (calldataWord cd (4 + (calldataWord cd 36).toNat)).toNat := by - unfold decodeCalldata at hdec - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - simp [decodeCalldata.decodeArgs, abiTupleHeadSize?, isDynamicABIType, - bind, Option.bind] at hdec - rcases hdec with ⟨_hlen4, _hhuge, _hargHuge, _htotalHuge, hdec⟩ - by_cases hshort : cd.toList.length - 4 < 64 - · simp [hshort] at hdec - · simp [hshort] at hdec - have hsz68 : 68 ≤ cd.size := by - rw [htlen] at hshort - omega - cases hvals : - decodeABIValues? [.dynamicArray bytes32, .dynamicArray (.dynamicArray elem1)] - (List.drop 4 cd.toList) 0 0 64 64 with - | none => - simp [hvals] at hdec - | some p => - rcases p with ⟨values, endOffset⟩ - simp [hvals] at hdec - rw [decodeABIValues?] at hvals - simp [isDynamicABIType, bind, Option.bind] at hvals - cases hread0 : readNat? (List.drop 4 cd.toList) 0 with - | none => simp [hread0] at hvals - | some off0 => - by_cases hmax0 : solcMaxLen DecodeMode.modern < off0 - · simp [hread0] at hvals - have hle : off0 ≤ solcMaxU64 := hvals.1 - simp [solcMaxLen] at hmax0 - omega - · simp [hread0] at hvals - cases hv0 : decodeABIValue? (.dynamicArray bytes32) (List.drop 4 cd.toList) off0 with - | none => simp [hv0] at hvals - | some p0 => - rcases p0 with ⟨v0, end0⟩ - obtain ⟨xs, hv0arr⟩ := decodeABIValue_dynamicArray_is_array hv0 - have hv0xs : - decodeABIValue? (.dynamicArray bytes32) (List.drop 4 cd.toList) off0 = - some (.array xs, end0) := by - simpa [hv0arr] using hv0 - obtain ⟨len0, hreadLen0, _hlen0Max, hxsLen⟩ := - decodeABIValue_dynamicArray_bytes32_facts hv0xs - simp [hv0] at hvals - cases hrest : - decodeABIValues? [.dynamicArray (.dynamicArray elem1)] - (List.drop 4 cd.toList) 0 32 64 (max 64 end0) with - | none => simp [hrest] at hvals - | some prest => - rcases prest with ⟨valuesRest, endRest⟩ - simp [hrest] at hvals - rw [decodeABIValues?] at hrest - simp [isDynamicABIType, bind, Option.bind] at hrest - cases hread1 : readNat? (List.drop 4 cd.toList) 32 with - | none => simp [hread1] at hrest - | some off1 => - by_cases hmax1 : solcMaxLen DecodeMode.modern < off1 - · simp [hread1] at hrest - have hle : off1 ≤ solcMaxU64 := hrest.1 - simp [solcMaxLen] at hmax1 - omega - · simp [hread1] at hrest - cases hv1 : - decodeABIValue? (.dynamicArray (.dynamicArray elem1)) - (List.drop 4 cd.toList) off1 with - | none => simp [hv1] at hrest - | some p1 => - rcases p1 with ⟨v1, end1⟩ - obtain ⟨ys, hv1arr⟩ := decodeABIValue_dynamicArray_is_array hv1 - have hv1ys : - decodeABIValue? (.dynamicArray (.dynamicArray elem1)) - (List.drop 4 cd.toList) off1 = - some (.array ys, end1) := by - simpa [hv1arr] using hv1 - obtain ⟨len1, hreadLen1, _hlen1Max, hysLen⟩ := - decodeABIValue_dynamicArray_dynamic_facts hv1ys - simp [hv1] at hrest - rcases hrest with ⟨_hoff1le, hrestEq⟩ - simp [decodeABIValues?] at hrestEq - rcases hrestEq with ⟨hvaluesRestEq, _hendRestEq⟩ - rcases hvals with ⟨_hoff0le, hvalsEq⟩ - rcases hvalsEq with ⟨hvaluesEq, _hendEq⟩ - cases hvaluesRestEq - rw [← hvaluesEq, hv0arr, hv1arr] at hdec - simp [decodeCalldata.insertValues] at hdec - cases hdec - have hreadOff0 := readNat_drop4_zero_eq_calldataWord - (cd := cd) (by omega : 36 ≤ cd.size) - rw [hread0] at hreadOff0 - cases hreadOff0 - have hreadOff1 := readNat_drop4_32_eq_calldataWord - (cd := cd) hsz68 - rw [hread1] at hreadOff1 - cases hreadOff1 - have hlen0Word : - readNat? (cd.toList.drop 4) (calldataWord cd 4).toNat = - some (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat := by - have hbound := readNat?_some_length hreadLen0 - exact readNat_drop4_at_eq_calldataWord - (cd := cd) (off := (calldataWord cd 4).toNat) (by - rw [List.length_drop, htlen] at hbound - omega) - have hlen0Eq : - len0 = - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat := - Option.some.inj (hreadLen0.symm.trans hlen0Word) - have hlen1Word : - readNat? (cd.toList.drop 4) (calldataWord cd 36).toNat = - some (calldataWord cd (4 + (calldataWord cd 36).toNat)).toNat := by - have hbound := readNat?_some_length hreadLen1 - exact readNat_drop4_at_eq_calldataWord - (cd := cd) (off := (calldataWord cd 36).toNat) (by - rw [List.length_drop, htlen] at hbound - omega) - have hlen1Eq : - len1 = - (calldataWord cd (4 + (calldataWord cd 36).toNat)).toNat := - Option.some.inj (hreadLen1.symm.trans hlen1Word) - refine ⟨xs, ys, ?_, ?_, ?_, ?_⟩ - · simp [Std.HashMap.get?_eq_getElem?, Std.HashMap.getElem_insert, hne] - · simp [Std.HashMap.get?_eq_getElem?] - · exact hxsLen.trans hlen0Eq - · exact hysLen.trans hlen1Eq - -theorem decodeABIArrayDynamicElemsFrom_none_head_short {ty : ABIType} - {bytes : List UInt8} {base headCursor headSize maxEnd n : Nat} - (hshort : bytes.length < base + headCursor + 32 * (n + 1)) : - decodeABIArrayDynamicElemsFrom? ty (n + 1) bytes base headCursor headSize maxEnd = none := by - induction n generalizing headCursor maxEnd with - | zero => - unfold decodeABIArrayDynamicElemsFrom? - have hread : readNat? bytes (base + headCursor) = none := by - unfold readNat? readWord? readBytes? - have hlen : ¬ ((bytes.drop (base + headCursor)).take 32).length = 32 := by - rw [List.length_take, List.length_drop] - omega - rw [if_neg hlen] - rfl - simp [hread] - | succ n ih => - unfold decodeABIArrayDynamicElemsFrom? - cases hread : readNat? bytes (base + headCursor) with - | none => simp - | some relativeOffset => - simp - cases hval : decodeABIValue? ty bytes (base + relativeOffset) with - | none => simp - | some p => - rcases p with ⟨value, valueEnd⟩ - simp - have hshort' : bytes.length < base + (headCursor + 32) + 32 * (n + 1) := by - omega - rw [ih (headCursor := headCursor + 32) - (maxEnd := max maxEnd valueEnd) hshort'] - simp - -theorem decodeABIArrayDynamicElems_none_head_short {ty : ABIType} - {bytes : List UInt8} {base n : Nat} - (hshort : bytes.length < base + 32 * (n + 1)) : - decodeABIArrayDynamicElems? ty (n + 1) bytes base = none := by - simpa [decodeABIArrayDynamicElems?, Nat.mul_comm] using - decodeABIArrayDynamicElemsFrom_none_head_short - (ty := ty) (bytes := bytes) (base := base) (headCursor := 0) - (headSize := (n + 1) * 32) (maxEnd := base + (n + 1) * 32) - (by simpa [Nat.add_assoc] using hshort) - -theorem attesterDecodeCalldata_twoDynamicArrays_none_secondOffsetHuge {cd : ByteArray} - {name0 name1 : Ident} {elem1 : ABIType} - (hsz68 : 68 ≤ cd.size) - (hoff0Max : ¬ solcMaxU64 < (calldataWord cd 4).toNat) - (hlenWord : 4 + (calldataWord cd 4).toNat + 32 ≤ cd.size) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) - (hpayload0 : - 4 + (calldataWord cd 4).toNat + 32 + - 32 * (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat ≤ - cd.size) - (hoff1Huge : solcMaxU64 < (calldataWord cd 36).toNat) : - decodeCalldata [name0, name1] [.dynamicArray bytes32, .dynamicArray (.dynamicArray elem1)] - cd = none := by - unfold decodeCalldata - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - by_cases hdyn : - ([ABIType.dynamicArray bytes32, ABIType.dynamicArray (ABIType.dynamicArray elem1)].any - isDynamicABIType = true ∧ - 2 ^ 255 ≤ cd.toList.length) - · rw [if_pos hdyn] - · rw [if_neg hdyn] - by_cases hargsHuge : - [ABIType.dynamicArray bytes32, ABIType.dynamicArray (ABIType.dynamicArray elem1)].isEmpty = - false ∧ - 2 ^ 255 ≤ (cd.toList.drop 4).length - · rw [if_pos hargsHuge] - · rw [if_neg hargsHuge] - rw [if_neg (by simp [solcTotalSizeDynamicGuard])] - have hread0 := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) - have hreadLen0 := readNat_drop4_dynamic_eq_calldataWord - (cd := cd) hlenWord - have hread1 := readNat_drop4_32_eq_calldataWord (cd := cd) hsz68 - have hstaticSize : staticABIEncodedSize? bytes32 = some 32 := by - native_decide - have hstaticSize' : - staticABIEncodedSize? (ABIType.elem (ElemType.bytes bytes32Width)) = some 32 := by - simpa [bytes32] using hstaticSize - obtain ⟨values0, hstatic0, _hlen0⟩ := - decodeABIArrayStaticElems_bytes32_exists_of_length - (n := (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) - (bytes := cd.toList.drop 4) - (start := (calldataWord cd 4).toNat + 32) (by - rw [List.length_drop, htlen] - omega) - have hstatic0' : - decodeABIArrayStaticElems? (ABIType.elem (ElemType.bytes bytes32Width)) - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat 32 - (cd.toList.drop 4) ((calldataWord cd 4).toNat + 32) = - some (values0, - (calldataWord cd 4).toNat + 32 + - 32 * (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) := by - simpa [bytes32] using hstatic0 - simp [decodeCalldata.decodeArgs, decodeABIValues?, decodeABIValue?, isDynamicABIType, - abiTupleHeadSize?, bind, Option.bind, solcMaxLen, bytes32, hread0, hoff0Max, - hreadLen0, hlen0Max, hstaticSize', hstatic0', hread1, hoff1Huge] - -theorem attesterDecodeCalldata_twoDynamicArrays_none_secondLengthShort {cd : ByteArray} - {name0 name1 : Ident} {elem1 : ABIType} - (hsz68 : 68 ≤ cd.size) - (hoff0Max : ¬ solcMaxU64 < (calldataWord cd 4).toNat) - (hlen0Word : 4 + (calldataWord cd 4).toNat + 32 ≤ cd.size) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) - (hpayload0 : - 4 + (calldataWord cd 4).toNat + 32 + - 32 * (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat ≤ - cd.size) - (hoff1Max : ¬ solcMaxU64 < (calldataWord cd 36).toNat) - (hshort1 : cd.size < 4 + (calldataWord cd 36).toNat + 32) : - decodeCalldata [name0, name1] [.dynamicArray bytes32, .dynamicArray (.dynamicArray elem1)] - cd = none := by - unfold decodeCalldata - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - by_cases hdyn : - ([ABIType.dynamicArray bytes32, ABIType.dynamicArray (ABIType.dynamicArray elem1)].any - isDynamicABIType = true ∧ - 2 ^ 255 ≤ cd.toList.length) - · rw [if_pos hdyn] - · rw [if_neg hdyn] - by_cases hargsHuge : - [ABIType.dynamicArray bytes32, ABIType.dynamicArray (ABIType.dynamicArray elem1)].isEmpty = - false ∧ - 2 ^ 255 ≤ (cd.toList.drop 4).length - · rw [if_pos hargsHuge] - · rw [if_neg hargsHuge] - rw [if_neg (by simp [solcTotalSizeDynamicGuard])] - have hread0 := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) - have hreadLen0 := readNat_drop4_dynamic_eq_calldataWord - (cd := cd) hlen0Word - have hread1 := readNat_drop4_32_eq_calldataWord (cd := cd) hsz68 - have hreadLen1 : - readNat? (cd.toList.drop 4) (calldataWord cd 36).toNat = none := - readNat_drop4_at_none_of_short - (cd := cd) (off := (calldataWord cd 36).toNat) hshort1 - have hstaticSize : staticABIEncodedSize? bytes32 = some 32 := by - native_decide - have hstaticSize' : - staticABIEncodedSize? (ABIType.elem (ElemType.bytes bytes32Width)) = some 32 := by - simpa [bytes32] using hstaticSize - obtain ⟨values0, hstatic0, _hlen0⟩ := - decodeABIArrayStaticElems_bytes32_exists_of_length - (n := (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) - (bytes := cd.toList.drop 4) - (start := (calldataWord cd 4).toNat + 32) (by - rw [List.length_drop, htlen] - omega) - have hstatic0' : - decodeABIArrayStaticElems? (ABIType.elem (ElemType.bytes bytes32Width)) - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat 32 - (cd.toList.drop 4) ((calldataWord cd 4).toNat + 32) = - some (values0, - (calldataWord cd 4).toNat + 32 + - 32 * (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) := by - simpa [bytes32] using hstatic0 - simp [decodeCalldata.decodeArgs, decodeABIValues?, decodeABIValue?, isDynamicABIType, - abiTupleHeadSize?, bind, Option.bind, solcMaxLen, bytes32, hread0, hoff0Max, - hreadLen0, hlen0Max, hstaticSize', hstatic0', hread1, hoff1Max, hreadLen1] - -theorem attesterDecodeCalldata_twoDynamicArrays_none_secondLengthHuge {cd : ByteArray} - {name0 name1 : Ident} {elem1 : ABIType} - (hsz68 : 68 ≤ cd.size) - (hoff0Max : ¬ solcMaxU64 < (calldataWord cd 4).toNat) - (hlen0Word : 4 + (calldataWord cd 4).toNat + 32 ≤ cd.size) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) - (hpayload0 : - 4 + (calldataWord cd 4).toNat + 32 + - 32 * (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat ≤ - cd.size) - (hoff1Max : ¬ solcMaxU64 < (calldataWord cd 36).toNat) - (hlen1Word : 4 + (calldataWord cd 36).toNat + 32 ≤ cd.size) - (hlen1Huge : solcMaxU64 < - (calldataWord cd (4 + (calldataWord cd 36).toNat)).toNat) : - decodeCalldata [name0, name1] [.dynamicArray bytes32, .dynamicArray (.dynamicArray elem1)] - cd = none := by - unfold decodeCalldata - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - by_cases hdyn : - ([ABIType.dynamicArray bytes32, ABIType.dynamicArray (ABIType.dynamicArray elem1)].any - isDynamicABIType = true ∧ - 2 ^ 255 ≤ cd.toList.length) - · rw [if_pos hdyn] - · rw [if_neg hdyn] - by_cases hargsHuge : - [ABIType.dynamicArray bytes32, ABIType.dynamicArray (ABIType.dynamicArray elem1)].isEmpty = - false ∧ - 2 ^ 255 ≤ (cd.toList.drop 4).length - · rw [if_pos hargsHuge] - · rw [if_neg hargsHuge] - rw [if_neg (by simp [solcTotalSizeDynamicGuard])] - have hread0 := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) - have hreadLen0 := readNat_drop4_dynamic_eq_calldataWord - (cd := cd) hlen0Word - have hread1 := readNat_drop4_32_eq_calldataWord (cd := cd) hsz68 - have hreadLen1 := readNat_drop4_at_eq_calldataWord - (cd := cd) (off := (calldataWord cd 36).toNat) hlen1Word - have hstaticSize : staticABIEncodedSize? bytes32 = some 32 := by - native_decide - have hstaticSize' : - staticABIEncodedSize? (ABIType.elem (ElemType.bytes bytes32Width)) = some 32 := by - simpa [bytes32] using hstaticSize - obtain ⟨values0, hstatic0, _hlen0⟩ := - decodeABIArrayStaticElems_bytes32_exists_of_length - (n := (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) - (bytes := cd.toList.drop 4) - (start := (calldataWord cd 4).toNat + 32) (by - rw [List.length_drop, htlen] - omega) - have hstatic0' : - decodeABIArrayStaticElems? (ABIType.elem (ElemType.bytes bytes32Width)) - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat 32 - (cd.toList.drop 4) ((calldataWord cd 4).toNat + 32) = - some (values0, - (calldataWord cd 4).toNat + 32 + - 32 * (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) := by - simpa [bytes32] using hstatic0 - simp [decodeCalldata.decodeArgs, decodeABIValues?, decodeABIValue?, isDynamicABIType, - abiTupleHeadSize?, bind, Option.bind, solcMaxLen, bytes32, hread0, hoff0Max, - hreadLen0, hlen0Max, hstaticSize', hstatic0', hread1, hoff1Max, hreadLen1, - hlen1Huge] - -theorem attesterDecodeCalldata_twoDynamicArrays_none_secondPayloadShort {cd : ByteArray} - {name0 name1 : Ident} {elem1 : ABIType} - (hsz68 : 68 ≤ cd.size) - (hoff0Max : ¬ solcMaxU64 < (calldataWord cd 4).toNat) - (hlen0Word : 4 + (calldataWord cd 4).toNat + 32 ≤ cd.size) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) - (hpayload0 : - 4 + (calldataWord cd 4).toNat + 32 + - 32 * (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat ≤ - cd.size) - (hoff1Max : ¬ solcMaxU64 < (calldataWord cd 36).toNat) - (hlen1Word : 4 + (calldataWord cd 36).toNat + 32 ≤ cd.size) - (hlen1Max : ¬ solcMaxU64 < - (calldataWord cd (4 + (calldataWord cd 36).toNat)).toNat) - (hpayload1 : - cd.size < - 4 + (calldataWord cd 36).toNat + 32 + - 32 * (calldataWord cd (4 + (calldataWord cd 36).toNat)).toNat) : - decodeCalldata [name0, name1] [.dynamicArray bytes32, .dynamicArray (.dynamicArray elem1)] - cd = none := by - unfold decodeCalldata - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - by_cases hdyn : - ([ABIType.dynamicArray bytes32, ABIType.dynamicArray (ABIType.dynamicArray elem1)].any - isDynamicABIType = true ∧ - 2 ^ 255 ≤ cd.toList.length) - · rw [if_pos hdyn] - · rw [if_neg hdyn] - by_cases hargsHuge : - [ABIType.dynamicArray bytes32, ABIType.dynamicArray (ABIType.dynamicArray elem1)].isEmpty = - false ∧ - 2 ^ 255 ≤ (cd.toList.drop 4).length - · rw [if_pos hargsHuge] - · rw [if_neg hargsHuge] - rw [if_neg (by simp [solcTotalSizeDynamicGuard])] - have hread0 := readNat_drop4_zero_eq_calldataWord (cd := cd) (by omega : 36 ≤ cd.size) - have hreadLen0 := readNat_drop4_dynamic_eq_calldataWord - (cd := cd) hlen0Word - have hread1 := readNat_drop4_32_eq_calldataWord (cd := cd) hsz68 - have hreadLen1 := readNat_drop4_at_eq_calldataWord - (cd := cd) (off := (calldataWord cd 36).toNat) hlen1Word - have hlen1Pos : - 0 < (calldataWord cd (4 + (calldataWord cd 36).toNat)).toNat := by - by_contra hzero - have hzero' : - (calldataWord cd (4 + (calldataWord cd 36).toNat)).toNat = 0 := by - omega - rw [hzero'] at hpayload1 - omega - obtain ⟨n, hlen1Eq⟩ := - Nat.exists_eq_succ_of_ne_zero (Nat.ne_of_gt hlen1Pos) - have hdynamicNone : - decodeABIArrayDynamicElems? (.dynamicArray elem1) - (calldataWord cd (4 + (calldataWord cd 36).toNat)).toNat - (cd.toList.drop 4) ((calldataWord cd 36).toNat + 32) = none := by - rw [hlen1Eq] - apply decodeABIArrayDynamicElems_none_head_short - rw [List.length_drop, htlen] - omega - have hstaticSize : staticABIEncodedSize? bytes32 = some 32 := by - native_decide - have hstaticSize' : - staticABIEncodedSize? (ABIType.elem (ElemType.bytes bytes32Width)) = some 32 := by - simpa [bytes32] using hstaticSize - obtain ⟨values0, hstatic0, _hlen0⟩ := - decodeABIArrayStaticElems_bytes32_exists_of_length - (n := (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) - (bytes := cd.toList.drop 4) - (start := (calldataWord cd 4).toNat + 32) (by - rw [List.length_drop, htlen] - omega) - have hstatic0' : - decodeABIArrayStaticElems? (ABIType.elem (ElemType.bytes bytes32Width)) - (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat 32 - (cd.toList.drop 4) ((calldataWord cd 4).toNat + 32) = - some (values0, - (calldataWord cd 4).toNat + 32 + - 32 * (calldataWord cd (4 + (calldataWord cd 4).toNat)).toNat) := by - simpa [bytes32] using hstatic0 - simp [decodeCalldata.decodeArgs, decodeABIValues?, decodeABIValue?, isDynamicABIType, - abiTupleHeadSize?, bind, Option.bind, solcMaxLen, bytes32, hread0, hoff0Max, - hreadLen0, hlen0Max, hstaticSize', hstatic0', hread1, hoff1Max, hreadLen1, - hlen1Max, hdynamicNone] - -theorem attesterDynamicArrayStart_toNat {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) : - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)).toNat = - 4 + (calldataWord I.calldata 4).toNat := by - change (((⟨4⟩ : UInt256) + calldataWord I.calldata 4).toNat = - 4 + (calldataWord I.calldata 4).toNat) - rw [uadd_toNat] - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - exact Nat.mod_eq_of_lt (by - have hoffLe : (calldataWord I.calldata 4).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - norm_num [solcMaxU64, UInt256.size] at hoffLe ⊢ - omega) - -abbrev attesterFirstArrayStartWord (I : ExecutionEnv) : UInt256 := - UInt256.add ⟨4⟩ (calldataWord I.calldata 4) - -abbrev attesterFirstArrayLengthWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata (attesterFirstArrayStartWord I).toNat - -abbrev attesterFirstArrayPayloadEndWord (I : ExecutionEnv) : UInt256 := - (attesterFirstArrayStartWord I + - UInt256.shiftLeft (attesterFirstArrayLengthWord I) ⟨5⟩) + ⟨32⟩ - -abbrev attesterSecondArrayStartWord (I : ExecutionEnv) : UInt256 := - UInt256.add ⟨4⟩ (calldataWord I.calldata 36) - -abbrev attesterSecondArrayLengthWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata (attesterSecondArrayStartWord I).toNat - -abbrev attesterSecondArrayPayloadEndWord (I : ExecutionEnv) : UInt256 := - (attesterSecondArrayStartWord I + - UInt256.shiftLeft (attesterSecondArrayLengthWord I) ⟨5⟩) + ⟨32⟩ - -abbrev attesterMultiOuterArrayAllocEndWord (I : ExecutionEnv) : UInt256 := - (⟨128⟩ : UInt256) + - ((⟨32⟩ : UInt256) + UInt256.mul (⟨32⟩ : UInt256) (attesterFirstArrayLengthWord I)) - -abbrev attesterMultiOuterArrayLenMem (I : ExecutionEnv) : ByteArray := - (UInt256.toByteArray (attesterFirstArrayLengthWord I)).write 0 solcFreePtrMem 128 32 - -abbrev attesterMultiOuterArrayAllocMem (I : ExecutionEnv) : ByteArray := - (UInt256.toByteArray (attesterMultiOuterArrayAllocEndWord I)).write 0 - (attesterMultiOuterArrayLenMem I) 64 32 - -abbrev attesterMloadWord (mem : ByteArray) (aw off : UInt256) : UInt256 := - if off.toNat ≥ mem.size ∨ off ≥ aw * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat (fromByteArrayBigEndian (mem.readWithPadding off.toNat 32)) - -abbrev attesterMloadAw (aw off : UInt256) : UInt256 := - UInt256.ofNat (MachineState.M aw.toNat off.toNat 32) - -abbrev attesterMultiOuterArrayInitFreeWord (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMloadWord mem aw ⟨64⟩ - -abbrev attesterMultiOuterArrayInitAwAfterMload (aw : UInt256) : UInt256 := - attesterMloadAw aw ⟨64⟩ - -abbrev attesterMultiOuterArrayInitFreeMem (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)).write 0 mem 64 32 - -abbrev attesterMultiOuterArrayInitFreeAw (aw : UInt256) : UInt256 := - UInt256.ofNat (MachineState.M (attesterMultiOuterArrayInitAwAfterMload aw).toNat 64 32) - -abbrev attesterMultiOuterArrayInitZeroMem (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (⟨0⟩ : UInt256)).write 0 - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat 32 - -abbrev attesterMultiOuterArrayInitZeroAw (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiOuterArrayInitFreeAw aw).toNat - (attesterMultiOuterArrayInitFreeWord mem aw).toNat 32) - -abbrev attesterMultiOuterArrayInitOffsetWord (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMultiOuterArrayInitFreeWord mem aw + (⟨32⟩ : UInt256) - -abbrev attesterMultiOuterArrayInitOffsetMem (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (⟨96⟩ : UInt256)).write 0 - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiOuterArrayInitOffsetWord mem aw).toNat 32 - -abbrev attesterMultiOuterArrayInitOffsetAw (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiOuterArrayInitZeroAw mem aw).toNat - (attesterMultiOuterArrayInitOffsetWord mem aw).toNat 32) - -abbrev attesterMultiOuterArrayInitStepMem - (slot : UInt256) (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (attesterMultiOuterArrayInitFreeWord mem aw)).write 0 - (attesterMultiOuterArrayInitOffsetMem mem aw) slot.toNat 32 - -abbrev attesterMultiOuterArrayInitStepAw - (slot : UInt256) (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiOuterArrayInitOffsetAw mem aw).toNat slot.toNat 32) - -theorem attesterDynamicArrayStart31_toNat {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) : - ((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨31⟩).toNat = - 4 + (calldataWord I.calldata 4).toNat + 31 := by - rw [uadd_toNat] - rw [attesterDynamicArrayStart_toNat (I := I) hoffMax] - rw [show (⟨31⟩ : UInt256).toNat = 31 from by decide] - exact Nat.mod_eq_of_lt (by - have hoffLe : (calldataWord I.calldata 4).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - norm_num [solcMaxU64, UInt256.size] at hoffLe ⊢ - omega) - -theorem attesterSecondArrayStart_toNat {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) : - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)).toNat = - 4 + (calldataWord I.calldata 36).toNat := by - change (((⟨4⟩ : UInt256) + calldataWord I.calldata 36).toNat = - 4 + (calldataWord I.calldata 36).toNat) - rw [uadd_toNat] - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - exact Nat.mod_eq_of_lt (by - have hoffLe : (calldataWord I.calldata 36).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - norm_num [solcMaxU64, UInt256.size] at hoffLe ⊢ - omega) - -theorem attesterFirstArrayLengthWord_toNat {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) : - (attesterFirstArrayLengthWord I).toNat = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat := by - unfold attesterFirstArrayLengthWord - rw [attesterDynamicArrayStart_toNat (I := I) hoffMax] - -theorem attesterSecondArrayLengthWord_toNat {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) : - (attesterSecondArrayLengthWord I).toNat = - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat := by - unfold attesterSecondArrayLengthWord - rw [attesterSecondArrayStart_toNat (I := I) hoffMax] - -theorem attesterFirstArrayLengthWord_isZero_of_nat_eq_zero {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hzero : - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat = 0) : - UInt256.isZero (attesterFirstArrayLengthWord I) = ⟨1⟩ := by - have hword : attesterFirstArrayLengthWord I = ⟨0⟩ := by - apply u256_inj - rw [attesterFirstArrayLengthWord_toNat (I := I) hoffMax, hzero] - decide - rw [hword] - decide - -theorem attesterFirstArrayLengthWord_isZero_of_nat_ne_zero {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hnonzero : - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0) : - UInt256.isZero (attesterFirstArrayLengthWord I) = ⟨0⟩ := by - apply isZero_eq_zero_of_ne - intro hword - have hnat := congrArg UInt256.toNat hword - rw [attesterFirstArrayLengthWord_toNat (I := I) hoffMax] at hnat - exact hnonzero (by simpa using hnat) - -theorem attesterArrayLengthWords_eq_one_of_nat_eq {I : ExecutionEnv} - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hoff1Max : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (heq : - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) : - UInt256.eq (attesterSecondArrayLengthWord I) (attesterFirstArrayLengthWord I) = ⟨1⟩ := by - have hword : attesterSecondArrayLengthWord I = attesterFirstArrayLengthWord I := by - apply u256_inj - rw [attesterSecondArrayLengthWord_toNat (I := I) hoff1Max, - attesterFirstArrayLengthWord_toNat (I := I) hoff0Max, heq] - rw [hword] - exact uInt256_eq_self _ - -theorem attesterArrayLengthWords_eq_zero_of_nat_ne {I : ExecutionEnv} - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hoff1Max : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hne : - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat ≠ - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) : - UInt256.eq (attesterSecondArrayLengthWord I) (attesterFirstArrayLengthWord I) = ⟨0⟩ := by - apply uInt256_eq_zero_of_ne - intro hone - have hword := uInt256_eq_one_eq hone - have hnat := congrArg UInt256.toNat hword - rw [attesterSecondArrayLengthWord_toNat (I := I) hoff1Max, - attesterFirstArrayLengthWord_toNat (I := I) hoff0Max] at hnat - exact hne hnat - -theorem attesterSecondArrayStart31_toNat {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) : - ((UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨31⟩).toNat = - 4 + (calldataWord I.calldata 36).toNat + 31 := by - rw [uadd_toNat] - rw [attesterSecondArrayStart_toNat (I := I) hoffMax] - rw [show (⟨31⟩ : UInt256).toNat = 31 from by decide] - exact Nat.mod_eq_of_lt (by - have hoffLe : (calldataWord I.calldata 36).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - norm_num [solcMaxU64, UInt256.size] at hoffLe ⊢ - omega) - -theorem attesterShiftLeft5_toNat_of_le (a : UInt256) - (ha : a.toNat ≤ solcMaxU64) : - (UInt256.shiftLeft a ⟨5⟩).toNat = 32 * a.toNat := by - unfold UInt256.shiftLeft - rw [if_neg (by decide : ¬ ((⟨5⟩ : UInt256).val ≥ 256))] - change (((a.toNat <<< (⟨5⟩ : UInt256).val.val) % UInt256.size)) = 32 * a.toNat - rw [show (⟨5⟩ : UInt256).val.val = 5 by decide] - rw [Nat.shiftLeft_eq] - rw [Nat.mul_comm] - exact Nat.mod_eq_of_lt (by - norm_num [solcMaxU64, UInt256.size] at ha ⊢ - omega) - -theorem attesterFirstArrayPayloadEnd_toNat {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlenMax : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) : - (attesterFirstArrayPayloadEndWord I).toNat = - 4 + (calldataWord I.calldata 4).toNat + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat + 32 := by - have hstartToNat : (attesterFirstArrayStartWord I).toNat = - 4 + (calldataWord I.calldata 4).toNat := - attesterDynamicArrayStart_toNat (I := I) hoffMax - have hlenLeRaw : (attesterFirstArrayLengthWord I).toNat ≤ solcMaxU64 := by - unfold attesterFirstArrayLengthWord - rw [hstartToNat] - exact Nat.le_of_not_gt hlenMax - have hlenRawEq : - (attesterFirstArrayLengthWord I).toNat = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat := by - unfold attesterFirstArrayLengthWord - rw [hstartToNat] - have hshiftToNat : - (UInt256.shiftLeft (attesterFirstArrayLengthWord I) ⟨5⟩).toNat = - 32 * (attesterFirstArrayLengthWord I).toNat := - attesterShiftLeft5_toNat_of_le (attesterFirstArrayLengthWord I) hlenLeRaw - unfold attesterFirstArrayPayloadEndWord - rw [uadd_toNat] - have hstartShift : - (attesterFirstArrayStartWord I + - UInt256.shiftLeft (attesterFirstArrayLengthWord I) ⟨5⟩).toNat = - 4 + (calldataWord I.calldata 4).toNat + - 32 * (attesterFirstArrayLengthWord I).toNat := by - rw [uadd_toNat, hstartToNat, hshiftToNat] - exact Nat.mod_eq_of_lt (by - have hoffLe : (calldataWord I.calldata 4).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - have hlenLe : (attesterFirstArrayLengthWord I).toNat ≤ solcMaxU64 := hlenLeRaw - norm_num [solcMaxU64, UInt256.size] at hoffLe hlenLe ⊢ - omega) - rw [hstartShift] - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide] - rw [hlenRawEq] - exact Nat.mod_eq_of_lt (by - have hoffLe : (calldataWord I.calldata 4).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - have hlenLe : (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ≤ - solcMaxU64 := Nat.le_of_not_gt hlenMax - norm_num [solcMaxU64, UInt256.size] at hoffLe hlenLe ⊢ - omega) - -theorem attesterSecondArrayPayloadEnd_toNat {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hlenMax : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) : - (attesterSecondArrayPayloadEndWord I).toNat = - 4 + (calldataWord I.calldata 36).toNat + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat + 32 := by - have hstartToNat : (attesterSecondArrayStartWord I).toNat = - 4 + (calldataWord I.calldata 36).toNat := - attesterSecondArrayStart_toNat (I := I) hoffMax - have hlenLeRaw : (attesterSecondArrayLengthWord I).toNat ≤ solcMaxU64 := by - unfold attesterSecondArrayLengthWord - rw [hstartToNat] - exact Nat.le_of_not_gt hlenMax - have hlenRawEq : - (attesterSecondArrayLengthWord I).toNat = - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat := by - unfold attesterSecondArrayLengthWord - rw [hstartToNat] - have hshiftToNat : - (UInt256.shiftLeft (attesterSecondArrayLengthWord I) ⟨5⟩).toNat = - 32 * (attesterSecondArrayLengthWord I).toNat := - attesterShiftLeft5_toNat_of_le (attesterSecondArrayLengthWord I) hlenLeRaw - unfold attesterSecondArrayPayloadEndWord - rw [uadd_toNat] - have hstartShift : - (attesterSecondArrayStartWord I + - UInt256.shiftLeft (attesterSecondArrayLengthWord I) ⟨5⟩).toNat = - 4 + (calldataWord I.calldata 36).toNat + - 32 * (attesterSecondArrayLengthWord I).toNat := by - rw [uadd_toNat, hstartToNat, hshiftToNat] - exact Nat.mod_eq_of_lt (by - have hoffLe : (calldataWord I.calldata 36).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - have hlenLe : (attesterSecondArrayLengthWord I).toNat ≤ solcMaxU64 := hlenLeRaw - norm_num [solcMaxU64, UInt256.size] at hoffLe hlenLe ⊢ - omega) - rw [hstartShift] - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide] - rw [hlenRawEq] - exact Nat.mod_eq_of_lt (by - have hoffLe : (calldataWord I.calldata 36).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - have hlenLe : (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat ≤ - solcMaxU64 := Nat.le_of_not_gt hlenMax - norm_num [solcMaxU64, UInt256.size] at hoffLe hlenLe ⊢ - omega) - -theorem attesterDynamicArrayPayloadGuardGtOne_of_short {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlenMax : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hsize : I.calldata.size < UInt256.size) - (hpayloadShort : I.calldata.size < - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) : - UInt256.gt (attesterFirstArrayPayloadEndWord I) (UInt256.ofNat I.calldata.size) = - ⟨1⟩ := by - apply ugt_one - rw [attesterFirstArrayPayloadEnd_toNat (I := I) hoffMax hlenMax] - rw [ulit_toNat' I.calldata.size hsize] - omega - -theorem attesterDynamicArrayPayloadGuardGtZero_of_ok {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlenMax : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hsize : I.calldata.size < UInt256.size) - (hpayloadOk : - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat - ≤ I.calldata.size) : - UInt256.gt (attesterFirstArrayPayloadEndWord I) (UInt256.ofNat I.calldata.size) = - ⟨0⟩ := by - apply ugt_zero - rw [attesterFirstArrayPayloadEnd_toNat (I := I) hoffMax hlenMax] - rw [ulit_toNat' I.calldata.size hsize] - omega - -theorem attesterDynamicArrayLengthGuardSltZero_of_short {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hsizeSigned : I.calldata.size < 2 ^ 255) - (hshort : I.calldata.size < 4 + (calldataWord I.calldata 4).toNat + 32) : - UInt256.slt ((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨31⟩) - (UInt256.ofNat I.calldata.size) = ⟨0⟩ := by - have hstart31 := attesterDynamicArrayStart31_toNat (I := I) hoffMax - apply slt_lit_zero (m := I.calldata.size) - · exact hsizeSigned - · rw [hstart31] - omega - · rw [hstart31] - have hoffLe : (calldataWord I.calldata 4).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - norm_num [solcMaxU64] at hoffLe ⊢ - omega - -theorem attesterDynamicArrayLengthGuardSltZero_of_sizeHuge {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hbig : 2 ^ 255 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) : - UInt256.slt ((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨31⟩) - (UInt256.ofNat I.calldata.size) = ⟨0⟩ := by - apply slt_zero_low_high - · rw [attesterDynamicArrayStart31_toNat (I := I) hoffMax] - have hoffLe : (calldataWord I.calldata 4).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - norm_num [solcMaxU64] at hoffLe ⊢ - omega - · rw [ulit_toNat' I.calldata.size hsize] - exact hbig - -theorem attesterSecondArrayLengthGuardSltZero_of_short {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hsizeSigned : I.calldata.size < 2 ^ 255) - (hshort : I.calldata.size < 4 + (calldataWord I.calldata 36).toNat + 32) : - UInt256.slt ((UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨31⟩) - (UInt256.ofNat I.calldata.size) = ⟨0⟩ := by - have hstart31 := attesterSecondArrayStart31_toNat (I := I) hoffMax - apply slt_lit_zero (m := I.calldata.size) - · exact hsizeSigned - · rw [hstart31] - omega - · rw [hstart31] - have hoffLe : (calldataWord I.calldata 36).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - norm_num [solcMaxU64] at hoffLe ⊢ - omega - -theorem attesterSecondArrayPayloadGuardGtOne_of_short {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hlenMax : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) - (hsize : I.calldata.size < UInt256.size) - (hpayloadShort : I.calldata.size < - 4 + (calldataWord I.calldata 36).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) : - UInt256.gt (attesterSecondArrayPayloadEndWord I) (UInt256.ofNat I.calldata.size) = - ⟨1⟩ := by - apply ugt_one - rw [attesterSecondArrayPayloadEnd_toNat (I := I) hoffMax hlenMax] - rw [ulit_toNat' I.calldata.size hsize] - omega - -theorem attesterSecondArrayPayloadGuardGtZero_of_ok {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hlenMax : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) - (hsize : I.calldata.size < UInt256.size) - (hpayloadOk : - 4 + (calldataWord I.calldata 36).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat - ≤ I.calldata.size) : - UInt256.gt (attesterSecondArrayPayloadEndWord I) (UInt256.ofNat I.calldata.size) = - ⟨0⟩ := by - apply ugt_zero - rw [attesterSecondArrayPayloadEnd_toNat (I := I) hoffMax hlenMax] - rw [ulit_toNat' I.calldata.size hsize] - omega - -theorem attesterX_dynamicArrayLengthGuardOk {ret decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hsizeSigned : I.calldata.size < 2 ^ 255) - (hlenWord : 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2038⟩ : UInt256) - [UInt256.add ⟨4⟩ (calldataWord I.calldata 4), UInt256.ofNat I.calldata.size, - ret, calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2054⟩ : UInt256) - [⟨0⟩, ⟨0⟩, UInt256.add ⟨4⟩ (calldataWord I.calldata 4), - UInt256.ofNat I.calldata.size, ret, calldataWord I.calldata 4, - ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, - decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2038⟩ := hreach - have hstart31ToNat := attesterDynamicArrayStart31_toNat (I := I) hoffMax - have hslt : - UInt256.slt ((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨31⟩) - (UInt256.ofNat I.calldata.size) = ⟨1⟩ := by - apply slt_lit_one_low (m := I.calldata.size) - · exact hsizeSigned - · rw [hstart31ToNat] - omega - exact ⟨_, _, evm_run rd2038 with [ - raw jumpdest (by attester_decode_at v, ⟨2038⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2039⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2040⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2041⟩, 0x83, .DUP4) (by evm_ov), - raw push1 ⟨31⟩ (by attester_decode_at v, ⟨2042⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2044⟩, 0x84, .DUP5) (by evm_ov), - raw add (by attester_decode_at v, ⟨2045⟩, 0x01, .ADD) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2046⟩, 0x12, .SLT) (by evm_ov), - raw push2 ⟨2054⟩ (by attester_decode_at v, ⟨2047⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2050⟩, 0x57, .JUMPI) - (by rw [hslt]; decide) (attesterDynamicArrayLengthOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_dynamicArrayLengthGuardReverts {ret decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hslt : - UInt256.slt ((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨31⟩) - (UInt256.ofNat I.calldata.size) = ⟨0⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2038⟩ : UInt256) - [UInt256.add ⟨4⟩ (calldataWord I.calldata 4), UInt256.ofNat I.calldata.size, - ret, calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2038⟩ := hreach - exact evm_run rd2038 with [ - raw jumpdest (by attester_decode_at v, ⟨2038⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2039⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2040⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2041⟩, 0x83, .DUP4) (by evm_ov), - raw push1 ⟨31⟩ (by attester_decode_at v, ⟨2042⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2044⟩, 0x84, .DUP5) (by evm_ov), - raw add (by attester_decode_at v, ⟨2045⟩, 0x01, .ADD) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2046⟩, 0x12, .SLT) (by evm_ov), - raw push2 ⟨2054⟩ (by attester_decode_at v, ⟨2047⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2050⟩, 0x57, .JUMPI) - (by rw [hslt]) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2051⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2052⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2053⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_dynamicArrayLengthMaxOk {ret decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlenMax : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2054⟩ : UInt256) - [⟨0⟩, ⟨0⟩, UInt256.add ⟨4⟩ (calldataWord I.calldata 4), - UInt256.ofNat I.calldata.size, ret, calldataWord I.calldata 4, - ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, - decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2076⟩ : UInt256) - [calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)).toNat, ⟨0⟩, - UInt256.add ⟨4⟩ (calldataWord I.calldata 4), UInt256.ofNat I.calldata.size, - ret, calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2054⟩ := hreach - have hstartToNat := attesterDynamicArrayStart_toNat (I := I) hoffMax - have hgt : - UInt256.gt (calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)).toNat) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - have hmaxToNat : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = - solcMaxU64 := by - native_decide - rw [hstartToNat, hmaxToNat] - exact Nat.le_of_not_gt hlenMax - exact ⟨_, _, evm_run rd2054 with [ - raw jumpdest (by attester_decode_at v, ⟨2054⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2055⟩, 0x50, .POP) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2056⟩, 0x81, .DUP2) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2057⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2058⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2060⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2062⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2064⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2065⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2066⟩, 0x81, .DUP2) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2067⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2068⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2076⟩ (by attester_decode_at v, ⟨2069⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2072⟩, 0x57, .JUMPI) - (by - change UInt256.isZero - (UInt256.gt - (calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)).toNat) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) ≠ ⟨0⟩ - rw [hgt] - decide) - (attesterDynamicArrayLengthMaxOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_dynamicArrayLengthMaxHugeReverts {ret decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlenHuge : solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2054⟩ : UInt256) - [⟨0⟩, ⟨0⟩, UInt256.add ⟨4⟩ (calldataWord I.calldata 4), - UInt256.ofNat I.calldata.size, ret, calldataWord I.calldata 4, - ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, - decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2054⟩ := hreach - have hstartToNat := attesterDynamicArrayStart_toNat (I := I) hoffMax - have hgt : - UInt256.gt (calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)).toNat) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨1⟩ := by - apply ugt_one - have hmaxToNat : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = - solcMaxU64 := by - native_decide - rw [hstartToNat, hmaxToNat] - exact hlenHuge - exact evm_run rd2054 with [ - raw jumpdest (by attester_decode_at v, ⟨2054⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2055⟩, 0x50, .POP) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2056⟩, 0x81, .DUP2) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2057⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2058⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2060⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2062⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2064⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2065⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2066⟩, 0x81, .DUP2) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2067⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2068⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2076⟩ (by attester_decode_at v, ⟨2069⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2072⟩, 0x57, .JUMPI) - (by - change UInt256.isZero - (UInt256.gt - (calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)).toNat) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) = ⟨0⟩ - rw [hgt] - decide) - (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2073⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2074⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2075⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_dynamicArrayPayloadGuardOk {ret decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hgt : - UInt256.gt - (((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + - UInt256.shiftLeft - (calldataWord I.calldata - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)).toNat) ⟨5⟩) + ⟨32⟩) - (UInt256.ofNat I.calldata.size) = ⟨0⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2076⟩ : UInt256) - [calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)).toNat, ⟨0⟩, - UInt256.add ⟨4⟩ (calldataWord I.calldata 4), UInt256.ofNat I.calldata.size, - ret, calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2102⟩ : UInt256) - [calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)).toNat, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - UInt256.add ⟨4⟩ (calldataWord I.calldata 4), UInt256.ofNat I.calldata.size, - ret, calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2076⟩ := hreach - exact ⟨_, _, evm_run rd2076 with [ - raw jumpdest (by attester_decode_at v, ⟨2076⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2077⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2079⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2080⟩, 0x01, .ADD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2081⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2082⟩, 0x50, .POP) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2083⟩, 0x83, .DUP4) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2084⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2086⟩, 0x82, .DUP3) (by evm_ov), - raw push1 ⟨5⟩ (by attester_decode_at v, ⟨2087⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2089⟩, 0x1b, .SHL) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2090⟩, 0x85, .DUP6) (by evm_ov), - raw add (by attester_decode_at v, ⟨2091⟩, 0x01, .ADD) (by evm_ov), - raw add (by attester_decode_at v, ⟨2092⟩, 0x01, .ADD) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2093⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2094⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2102⟩ (by attester_decode_at v, ⟨2095⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2098⟩, 0x57, .JUMPI) - (by rw [hgt]; decide) (attesterDynamicArrayPayloadOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_dynamicArrayPayloadGuardReverts {ret decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hgt : - UInt256.gt - (((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + - UInt256.shiftLeft - (calldataWord I.calldata - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)).toNat) ⟨5⟩) + ⟨32⟩) - (UInt256.ofNat I.calldata.size) = ⟨1⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2076⟩ : UInt256) - [calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)).toNat, ⟨0⟩, - UInt256.add ⟨4⟩ (calldataWord I.calldata 4), UInt256.ofNat I.calldata.size, - ret, calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2076⟩ := hreach - exact evm_run rd2076 with [ - raw jumpdest (by attester_decode_at v, ⟨2076⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2077⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2079⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2080⟩, 0x01, .ADD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2081⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2082⟩, 0x50, .POP) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2083⟩, 0x83, .DUP4) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2084⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2086⟩, 0x82, .DUP3) (by evm_ov), - raw push1 ⟨5⟩ (by attester_decode_at v, ⟨2087⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2089⟩, 0x1b, .SHL) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2090⟩, 0x85, .DUP6) (by evm_ov), - raw add (by attester_decode_at v, ⟨2091⟩, 0x01, .ADD) (by evm_ov), - raw add (by attester_decode_at v, ⟨2092⟩, 0x01, .ADD) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2093⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2094⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2102⟩ (by attester_decode_at v, ⟨2095⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2098⟩, 0x57, .JUMPI) - (by rw [hgt]; decide) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2099⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2100⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2101⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_dynamicArrayPayloadOkToFirstReturn {decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2102⟩ : UInt256) - [attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - UInt256.add ⟨4⟩ (calldataWord I.calldata 4), UInt256.ofNat I.calldata.size, - ⟨2161⟩, calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2161⟩ : UInt256) - [attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2102⟩ := hreach - exact ⟨_, _, evm_run rd2102 with [ - raw jumpdest (by attester_decode_at v, ⟨2102⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2103⟩, 0x92, .SWAP3) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2104⟩, 0x50, .POP) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2105⟩, 0x92, .SWAP3) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2106⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2107⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨2108⟩, 0x56, .JUMP) - (attesterDynamic2FirstArrayReturnJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_dynamic2SecondOffsetOk {decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hoff1Max : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2161⟩ : UInt256) - [attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2191⟩ : UInt256) - [calldataWord I.calldata 36, ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2161⟩ := hreach - have hgt : - UInt256.gt (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - have hmaxToNat : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = - solcMaxU64 := by - native_decide - rw [hmaxToNat] - exact Nat.le_of_not_gt hoff1Max - exact ⟨_, _, evm_run rd2161 with [ - raw jumpdest (by attester_decode_at v, ⟨2161⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2162⟩, 0x90, .SWAP1) (by evm_ov), - raw swap6 (by attester_decode_at v, ⟨2163⟩, 0x95, .SWAP6) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2164⟩, 0x50, .POP) (by evm_ov), - raw swap4 (by attester_decode_at v, ⟨2165⟩, 0x93, .SWAP4) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2166⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2167⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2168⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2170⟩, 0x85, .DUP6) (by evm_ov), - raw add (by attester_decode_at v, ⟨2171⟩, 0x01, .ADD) (by simp), - raw calldataload (by attester_decode_at v, ⟨2172⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2173⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2175⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2177⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2179⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2180⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2181⟩, 0x81, .DUP2) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2182⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2183⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2191⟩ (by attester_decode_at v, ⟨2184⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2187⟩, 0x57, .JUMPI) - (by - change UInt256.isZero - (UInt256.gt (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) ≠ ⟨0⟩ - rw [hgt] - decide) - (attesterDynamic2SecondOffsetOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_dynamic2SecondOffsetHugeReverts {decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hoff1Huge : solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2161⟩ : UInt256) - [attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2161⟩ := hreach - have hgt : - UInt256.gt (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨1⟩ := by - apply ugt_one - have hmaxToNat : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = - solcMaxU64 := by - native_decide - rw [hmaxToNat] - exact hoff1Huge - exact evm_run rd2161 with [ - raw jumpdest (by attester_decode_at v, ⟨2161⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2162⟩, 0x90, .SWAP1) (by evm_ov), - raw swap6 (by attester_decode_at v, ⟨2163⟩, 0x95, .SWAP6) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2164⟩, 0x50, .POP) (by evm_ov), - raw swap4 (by attester_decode_at v, ⟨2165⟩, 0x93, .SWAP4) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2166⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2167⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2168⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2170⟩, 0x85, .DUP6) (by evm_ov), - raw add (by attester_decode_at v, ⟨2171⟩, 0x01, .ADD) (by simp), - raw calldataload (by attester_decode_at v, ⟨2172⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2173⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2175⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2177⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2179⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2180⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2181⟩, 0x81, .DUP2) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2182⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2183⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2191⟩ (by attester_decode_at v, ⟨2184⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2187⟩, 0x57, .JUMPI) - (by - change UInt256.isZero - (UInt256.gt (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) = ⟨0⟩ - rw [hgt] - decide) - (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2188⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2189⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2190⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_dynamic2SecondArrayDecoderEntry {decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2191⟩ : UInt256) - [calldataWord I.calldata 36, ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2038⟩ : UInt256) - [UInt256.add ⟨4⟩ (calldataWord I.calldata 36), UInt256.ofNat I.calldata.size, - ⟨2203⟩, calldataWord I.calldata 36, ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2191⟩ := hreach - exact ⟨_, _, evm_run rd2191 with [ - raw jumpdest (by attester_decode_at v, ⟨2191⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push2 ⟨2203⟩ (by attester_decode_at v, ⟨2192⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw dup8 (by attester_decode_at v, ⟨2195⟩, 0x87, .DUP8) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2196⟩, 0x82, .DUP3) (by evm_ov), - raw dup9 (by attester_decode_at v, ⟨2197⟩, 0x88, .DUP9) (by evm_ov), - raw add (by attester_decode_at v, ⟨2198⟩, 0x01, .ADD) (by evm_ov), - raw push2 ⟨2038⟩ (by attester_decode_at v, ⟨2199⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨2202⟩, 0x56, .JUMP) - (attesterDynamicArrayDecoderJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_secondArrayLengthGuardOk {decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hsizeSigned : I.calldata.size < 2 ^ 255) - (hlenWord : 4 + (calldataWord I.calldata 36).toNat + 32 ≤ I.calldata.size) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2038⟩ : UInt256) - [UInt256.add ⟨4⟩ (calldataWord I.calldata 36), UInt256.ofNat I.calldata.size, - ⟨2203⟩, calldataWord I.calldata 36, ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2054⟩ : UInt256) - [⟨0⟩, ⟨0⟩, UInt256.add ⟨4⟩ (calldataWord I.calldata 36), - UInt256.ofNat I.calldata.size, ⟨2203⟩, calldataWord I.calldata 36, - ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2038⟩ := hreach - have hstart31ToNat := attesterSecondArrayStart31_toNat (I := I) hoffMax - have hslt : - UInt256.slt ((UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨31⟩) - (UInt256.ofNat I.calldata.size) = ⟨1⟩ := by - apply slt_lit_one_low (m := I.calldata.size) - · exact hsizeSigned - · rw [hstart31ToNat] - omega - exact ⟨_, _, evm_run rd2038 with [ - raw jumpdest (by attester_decode_at v, ⟨2038⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2039⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2040⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2041⟩, 0x83, .DUP4) (by evm_ov), - raw push1 ⟨31⟩ (by attester_decode_at v, ⟨2042⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2044⟩, 0x84, .DUP5) (by evm_ov), - raw add (by attester_decode_at v, ⟨2045⟩, 0x01, .ADD) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2046⟩, 0x12, .SLT) (by evm_ov), - raw push2 ⟨2054⟩ (by attester_decode_at v, ⟨2047⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2050⟩, 0x57, .JUMPI) - (by rw [hslt]; decide) (attesterDynamicArrayLengthOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_secondArrayLengthGuardReverts {decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hslt : - UInt256.slt ((UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨31⟩) - (UInt256.ofNat I.calldata.size) = ⟨0⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2038⟩ : UInt256) - [UInt256.add ⟨4⟩ (calldataWord I.calldata 36), UInt256.ofNat I.calldata.size, - ⟨2203⟩, calldataWord I.calldata 36, ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2038⟩ := hreach - exact evm_run rd2038 with [ - raw jumpdest (by attester_decode_at v, ⟨2038⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2039⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2040⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2041⟩, 0x83, .DUP4) (by evm_ov), - raw push1 ⟨31⟩ (by attester_decode_at v, ⟨2042⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2044⟩, 0x84, .DUP5) (by evm_ov), - raw add (by attester_decode_at v, ⟨2045⟩, 0x01, .ADD) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2046⟩, 0x12, .SLT) (by evm_ov), - raw push2 ⟨2054⟩ (by attester_decode_at v, ⟨2047⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2050⟩, 0x57, .JUMPI) - (by rw [hslt]) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2051⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2052⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2053⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_secondArrayLengthMaxOk {decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hlenMax : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2054⟩ : UInt256) - [⟨0⟩, ⟨0⟩, UInt256.add ⟨4⟩ (calldataWord I.calldata 36), - UInt256.ofNat I.calldata.size, ⟨2203⟩, calldataWord I.calldata 36, - ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2076⟩ : UInt256) - [calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)).toNat, ⟨0⟩, - UInt256.add ⟨4⟩ (calldataWord I.calldata 36), UInt256.ofNat I.calldata.size, - ⟨2203⟩, calldataWord I.calldata 36, ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2054⟩ := hreach - have hstartToNat := attesterSecondArrayStart_toNat (I := I) hoffMax - have hgt : - UInt256.gt (calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)).toNat) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - have hmaxToNat : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = - solcMaxU64 := by - native_decide - rw [hstartToNat, hmaxToNat] - exact Nat.le_of_not_gt hlenMax - exact ⟨_, _, evm_run rd2054 with [ - raw jumpdest (by attester_decode_at v, ⟨2054⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2055⟩, 0x50, .POP) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2056⟩, 0x81, .DUP2) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2057⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2058⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2060⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2062⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2064⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2065⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2066⟩, 0x81, .DUP2) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2067⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2068⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2076⟩ (by attester_decode_at v, ⟨2069⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2072⟩, 0x57, .JUMPI) - (by - change UInt256.isZero - (UInt256.gt - (calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)).toNat) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) ≠ ⟨0⟩ - rw [hgt] - decide) - (attesterDynamicArrayLengthMaxOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_secondArrayLengthMaxHugeReverts {decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hlenHuge : solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2054⟩ : UInt256) - [⟨0⟩, ⟨0⟩, UInt256.add ⟨4⟩ (calldataWord I.calldata 36), - UInt256.ofNat I.calldata.size, ⟨2203⟩, calldataWord I.calldata 36, - ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2054⟩ := hreach - have hstartToNat := attesterSecondArrayStart_toNat (I := I) hoffMax - have hgt : - UInt256.gt (calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)).toNat) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨1⟩ := by - apply ugt_one - have hmaxToNat : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = - solcMaxU64 := by - native_decide - rw [hstartToNat, hmaxToNat] - exact hlenHuge - exact evm_run rd2054 with [ - raw jumpdest (by attester_decode_at v, ⟨2054⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2055⟩, 0x50, .POP) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2056⟩, 0x81, .DUP2) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2057⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2058⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2060⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2062⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2064⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2065⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2066⟩, 0x81, .DUP2) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2067⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2068⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2076⟩ (by attester_decode_at v, ⟨2069⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2072⟩, 0x57, .JUMPI) - (by - change UInt256.isZero - (UInt256.gt - (calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)).toNat) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) = ⟨0⟩ - rw [hgt] - decide) - (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2073⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2074⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2075⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_secondArrayPayloadGuardOk {decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hgt : - UInt256.gt - (((UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + - UInt256.shiftLeft - (calldataWord I.calldata - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)).toNat) ⟨5⟩) + ⟨32⟩) - (UInt256.ofNat I.calldata.size) = ⟨0⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2076⟩ : UInt256) - [calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)).toNat, ⟨0⟩, - UInt256.add ⟨4⟩ (calldataWord I.calldata 36), UInt256.ofNat I.calldata.size, - ⟨2203⟩, calldataWord I.calldata 36, ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2102⟩ : UInt256) - [calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)).toNat, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - UInt256.add ⟨4⟩ (calldataWord I.calldata 36), UInt256.ofNat I.calldata.size, - ⟨2203⟩, calldataWord I.calldata 36, ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2076⟩ := hreach - exact ⟨_, _, evm_run rd2076 with [ - raw jumpdest (by attester_decode_at v, ⟨2076⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2077⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2079⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2080⟩, 0x01, .ADD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2081⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2082⟩, 0x50, .POP) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2083⟩, 0x83, .DUP4) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2084⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2086⟩, 0x82, .DUP3) (by evm_ov), - raw push1 ⟨5⟩ (by attester_decode_at v, ⟨2087⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2089⟩, 0x1b, .SHL) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2090⟩, 0x85, .DUP6) (by evm_ov), - raw add (by attester_decode_at v, ⟨2091⟩, 0x01, .ADD) (by evm_ov), - raw add (by attester_decode_at v, ⟨2092⟩, 0x01, .ADD) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2093⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2094⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2102⟩ (by attester_decode_at v, ⟨2095⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2098⟩, 0x57, .JUMPI) - (by rw [hgt]; decide) (attesterDynamicArrayPayloadOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_secondArrayPayloadGuardReverts {decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hgt : - UInt256.gt - (((UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + - UInt256.shiftLeft - (calldataWord I.calldata - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)).toNat) ⟨5⟩) + ⟨32⟩) - (UInt256.ofNat I.calldata.size) = ⟨1⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2076⟩ : UInt256) - [calldataWord I.calldata (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)).toNat, ⟨0⟩, - UInt256.add ⟨4⟩ (calldataWord I.calldata 36), UInt256.ofNat I.calldata.size, - ⟨2203⟩, calldataWord I.calldata 36, ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2076⟩ := hreach - exact evm_run rd2076 with [ - raw jumpdest (by attester_decode_at v, ⟨2076⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2077⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2079⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2080⟩, 0x01, .ADD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2081⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2082⟩, 0x50, .POP) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2083⟩, 0x83, .DUP4) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2084⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2086⟩, 0x82, .DUP3) (by evm_ov), - raw push1 ⟨5⟩ (by attester_decode_at v, ⟨2087⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2089⟩, 0x1b, .SHL) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2090⟩, 0x85, .DUP6) (by evm_ov), - raw add (by attester_decode_at v, ⟨2091⟩, 0x01, .ADD) (by evm_ov), - raw add (by attester_decode_at v, ⟨2092⟩, 0x01, .ADD) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2093⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2094⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2102⟩ (by attester_decode_at v, ⟨2095⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2098⟩, 0x57, .JUMPI) - (by rw [hgt]; decide) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2099⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2100⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2101⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_secondArrayPayloadOkToSecondReturn {decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2102⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - UInt256.add ⟨4⟩ (calldataWord I.calldata 36), UInt256.ofNat I.calldata.size, - ⟨2203⟩, calldataWord I.calldata 36, ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2203⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - calldataWord I.calldata 36, ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2102⟩ := hreach - exact ⟨_, _, evm_run rd2102 with [ - raw jumpdest (by attester_decode_at v, ⟨2102⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2103⟩, 0x92, .SWAP3) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2104⟩, 0x50, .POP) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2105⟩, 0x92, .SWAP3) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2106⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2107⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨2108⟩, 0x56, .JUMP) - (attesterDynamic2SecondArrayReturnJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_dynamic2DecodeDone {decodeOk retPc : UInt256} - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hdecodeJumpdest : (D_J (patchedRuntime v) 0).contains decodeOk = true) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2203⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - calldataWord I.calldata 36, ⟨0⟩, ⟨0⟩, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, ⟨4⟩, - UInt256.ofNat I.calldata.size, decodeOk, retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) decodeOk - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - retPc, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd2203⟩ := hreach - exact ⟨_, _, evm_run rd2203 with [ - raw jumpdest (by attester_decode_at v, ⟨2203⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap6 (by attester_decode_at v, ⟨2204⟩, 0x95, .SWAP6) (by evm_ov), - raw swap9 (by attester_decode_at v, ⟨2205⟩, 0x98, .SWAP9) (by evm_ov), - raw swap5 (by attester_decode_at v, ⟨2206⟩, 0x94, .SWAP5) (by evm_ov), - raw swap8 (by attester_decode_at v, ⟨2207⟩, 0x97, .SWAP8) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2208⟩, 0x50, .POP) (by evm_ov), - raw swap6 (by attester_decode_at v, ⟨2209⟩, 0x95, .SWAP6) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2210⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2211⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2212⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2213⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨2214⟩, 0x56, .JUMP) - hdecodeJumpdest (by evm_ov)]⟩ - -theorem attesterX_multiRevokeDecodedToBody {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨92⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨192⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd92⟩ := hreach - exact ⟨_, _, evm_run rd92 with [ - raw jumpdest (by attester_decode_at v, ⟨92⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push2 ⟨192⟩ (by attester_decode_at v, ⟨93⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨96⟩, 0x56, .JUMP) - (attesterMultiRevokeBodyJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeLengthZeroReverts {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hzero : UInt256.isZero (attesterFirstArrayLengthWord I) = ⟨1⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨192⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd192⟩ := hreach - exact evm_run rd192 with [ - raw jumpdest (by attester_decode_at v, ⟨192⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨193⟩, 0x82, .DUP3) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨194⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨195⟩, 0x15, .ISZERO) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨196⟩, 0x80, .DUP1) (by evm_ov), - raw push2 ⟨206⟩ (by attester_decode_at v, ⟨197⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨200⟩, 0x57, .JUMPI) - (by rw [hzero]; decide) (attesterMultiRevokeLengthGuardJoinJumpdest v) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨206⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨207⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨236⟩ (by attester_decode_at v, ⟨208⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨211⟩, 0x57, .JUMPI) - (by rw [hzero]; decide) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨212⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by attester_decode_at v, ⟨214⟩, 0x51, .MLOAD) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - raw push4 ⟨3036299187⟩ (by attester_decode_at v, ⟨215⟩, 0x63, (.Push .PUSH4)) - (by evm_ov), - raw push1 ⟨224⟩ (by attester_decode_at v, ⟨220⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨222⟩, 0x1b, .SHL) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨223⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 6 attesterRequireSelectorMem (UInt256.ofNat 5) - (by attester_decode_at v, ⟨224⟩, 0x52, .MSTORE) - mem_cost (by - unfold attesterRequireSelectorMem - rw [show (⟨128⟩ : UInt256).toNat = 128 by decide]) - (by decide) (by evm_ov), - raw push1 ⟨4⟩ (by attester_decode_at v, ⟨225⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨227⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨228⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 5) (by attester_decode_at v, ⟨230⟩, 0x51, .MLOAD) - mem_cost attesterRequireSelectorMem_mload64 (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨231⟩, 0x80, .DUP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨232⟩, 0x91, .SWAP2) (by evm_ov), - raw sub (by attester_decode_at v, ⟨233⟩, 0x03, .SUB) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨234⟩, 0x90, .SWAP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨235⟩, 0xfd, .REVERT) - mem_cost (by evm_ov)] - -theorem attesterX_multiRevokeLengthMismatchReverts {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hnonzero : UInt256.isZero (attesterFirstArrayLengthWord I) = ⟨0⟩) - (hneq : - UInt256.eq (attesterSecondArrayLengthWord I) (attesterFirstArrayLengthWord I) = ⟨0⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨192⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd192⟩ := hreach - exact evm_run rd192 with [ - raw jumpdest (by attester_decode_at v, ⟨192⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨193⟩, 0x82, .DUP3) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨194⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨195⟩, 0x15, .ISZERO) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨196⟩, 0x80, .DUP1) (by evm_ov), - raw push2 ⟨206⟩ (by attester_decode_at v, ⟨197⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨200⟩, 0x57, .JUMPI) - (by rw [hnonzero]) (by evm_ov), - raw pop (by attester_decode_at v, ⟨201⟩, 0x50, .POP) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨202⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨203⟩, 0x82, .DUP3) (by evm_ov), - raw eq (by attester_decode_at v, ⟨204⟩, 0x14, .EQ) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨205⟩, 0x15, .ISZERO) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨206⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨207⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨236⟩ (by attester_decode_at v, ⟨208⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨211⟩, 0x57, .JUMPI) - (by rw [hneq]; decide) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨212⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by attester_decode_at v, ⟨214⟩, 0x51, .MLOAD) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - raw push4 ⟨3036299187⟩ (by attester_decode_at v, ⟨215⟩, 0x63, (.Push .PUSH4)) - (by evm_ov), - raw push1 ⟨224⟩ (by attester_decode_at v, ⟨220⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨222⟩, 0x1b, .SHL) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨223⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 6 attesterRequireSelectorMem (UInt256.ofNat 5) - (by attester_decode_at v, ⟨224⟩, 0x52, .MSTORE) - mem_cost (by - unfold attesterRequireSelectorMem - rw [show (⟨128⟩ : UInt256).toNat = 128 by decide]) - (by decide) (by evm_ov), - raw push1 ⟨4⟩ (by attester_decode_at v, ⟨225⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨227⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨228⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 5) (by attester_decode_at v, ⟨230⟩, 0x51, .MLOAD) - mem_cost attesterRequireSelectorMem_mload64 (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨231⟩, 0x80, .DUP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨232⟩, 0x91, .SWAP2) (by evm_ov), - raw sub (by attester_decode_at v, ⟨233⟩, 0x03, .SUB) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨234⟩, 0x90, .SWAP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨235⟩, 0xfd, .REVERT) - mem_cost (by evm_ov)] - -theorem attesterX_multiRevokeLengthGuardOk {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hnonzero : UInt256.isZero (attesterFirstArrayLengthWord I) = ⟨0⟩) - (heq : - UInt256.eq (attesterSecondArrayLengthWord I) (attesterFirstArrayLengthWord I) = ⟨1⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨192⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨236⟩ : UInt256) - [attesterFirstArrayLengthWord I, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd192⟩ := hreach - exact ⟨_, _, evm_run rd192 with [ - raw jumpdest (by attester_decode_at v, ⟨192⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨193⟩, 0x82, .DUP3) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨194⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨195⟩, 0x15, .ISZERO) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨196⟩, 0x80, .DUP1) (by evm_ov), - raw push2 ⟨206⟩ (by attester_decode_at v, ⟨197⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨200⟩, 0x57, .JUMPI) - (by rw [hnonzero]) (by evm_ov), - raw pop (by attester_decode_at v, ⟨201⟩, 0x50, .POP) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨202⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨203⟩, 0x82, .DUP3) (by evm_ov), - raw eq (by attester_decode_at v, ⟨204⟩, 0x14, .EQ) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨205⟩, 0x15, .ISZERO) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨206⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨207⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨236⟩ (by attester_decode_at v, ⟨208⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨211⟩, 0x57, .JUMPI) - (by rw [heq]; decide) (attesterMultiRevokeLengthGuardOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeLengthGuardOk_of_lengths {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) {schemas schemaUids : List Value} - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hoff1Max : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hSchemasLen : - schemas.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hSchemaUidsLen : - schemaUids.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) - (hnonzero : schemas.length ≠ 0) - (heqLen : schemas.length = schemaUids.length) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨192⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨236⟩ : UInt256) - [attesterFirstArrayLengthWord I, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hrawFirstNe : - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by omega) - have hrawEq : - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat := by - omega - have hnonzeroEvm := - attesterFirstArrayLengthWord_isZero_of_nat_ne_zero (I := I) hoff0Max hrawFirstNe - have heqEvm := - attesterArrayLengthWords_eq_one_of_nat_eq (I := I) hoff0Max hoff1Max hrawEq - exact attesterX_multiRevokeLengthGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) v hnonzeroEvm heqEvm hreach - -theorem attesterX_multiRevokeAllocLengthMaxOk {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨236⟩ : UInt256) - [attesterFirstArrayLengthWord I, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨261⟩ : UInt256) - [attesterFirstArrayLengthWord I, ⟨0⟩, attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd236⟩ := hreach - have hgt : - UInt256.gt (attesterFirstArrayLengthWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - have hmaxToNat : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = - solcMaxU64 := by - native_decide - rw [attesterFirstArrayLengthWord_toNat (I := I) hoff0Max, hmaxToNat] - exact Nat.le_of_not_gt hlen0Max - exact ⟨_, _, evm_run rd236 with [ - raw jumpdest (by attester_decode_at v, ⟨236⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨237⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨238⟩, 0x81, .DUP2) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨239⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨241⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨243⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨245⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨246⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨247⟩, 0x81, .DUP2) (by evm_ov), - raw gt (by attester_decode_at v, ⟨248⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨249⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨261⟩ (by attester_decode_at v, ⟨250⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨253⟩, 0x57, .JUMPI) - (by - rw [hgt] - decide) - (attesterMultiRevokeAllocLengthMaxOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeOuterArrayInitEntry {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hnonzero : UInt256.isZero (attesterFirstArrayLengthWord I) = ⟨0⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨261⟩ : UInt256) - [attesterFirstArrayLengthWord I, ⟨0⟩, attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨291⟩ : UInt256) - [((⟨32⟩ : UInt256) + ⟨128⟩), attesterFirstArrayLengthWord I, ⟨128⟩, ⟨0⟩, - attesterFirstArrayLengthWord I, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayAllocMem I) (UInt256.ofNat 5) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd261⟩ := hreach - exact ⟨_, _, evm_run rd261 with [ - raw jumpdest (by attester_decode_at v, ⟨261⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨262⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by attester_decode_at v, ⟨264⟩, 0x51, .MLOAD) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨265⟩, 0x90, .SWAP1) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨266⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨267⟩, 0x82, .DUP3) (by evm_ov), - raw mstore 6 (attesterMultiOuterArrayLenMem I) (UInt256.ofNat 5) - (by attester_decode_at v, ⟨268⟩, 0x52, .MSTORE) - mem_cost (by rfl) (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨269⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨270⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mul (by attester_decode_at v, ⟨272⟩, 0x02, .MUL) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨273⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨275⟩, 0x01, .ADD) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨276⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨277⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨278⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mstore 0 (attesterMultiOuterArrayAllocMem I) (UInt256.ofNat 5) - (by attester_decode_at v, ⟨280⟩, 0x52, .MSTORE) - mem_cost (by rfl) (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨281⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨282⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨330⟩ (by attester_decode_at v, ⟨283⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨286⟩, 0x57, .JUMPI) - (by rw [hnonzero]) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨287⟩, 0x81, .DUP2) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨288⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨290⟩, 0x01, .ADD) (by evm_ov)]⟩ - -theorem attesterX_multiAttestDecodedToBody {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨113⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨828⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd113⟩ := hreach - exact ⟨_, _, evm_run rd113 with [ - raw jumpdest (by attester_decode_at v, ⟨113⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push2 ⟨828⟩ (by attester_decode_at v, ⟨114⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨117⟩, 0x56, .JUMP) - (attesterMultiAttestBodyJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiAttestLengthZeroReverts {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hzero : UInt256.isZero (attesterFirstArrayLengthWord I) = ⟨1⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨828⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd828⟩ := hreach - exact evm_run rd828 with [ - raw jumpdest (by attester_decode_at v, ⟨828⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨96⟩ (by attester_decode_at v, ⟨829⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨831⟩, 0x83, .DUP4) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨832⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨833⟩, 0x15, .ISZERO) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨834⟩, 0x80, .DUP1) (by evm_ov), - raw push2 ⟨844⟩ (by attester_decode_at v, ⟨835⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨838⟩, 0x57, .JUMPI) - (by rw [hzero]; decide) (attesterMultiAttestLengthGuardJoinJumpdest v) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨844⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨845⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨874⟩ (by attester_decode_at v, ⟨846⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨849⟩, 0x57, .JUMPI) - (by rw [hzero]; decide) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨850⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by attester_decode_at v, ⟨852⟩, 0x51, .MLOAD) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - raw push4 ⟨3036299187⟩ (by attester_decode_at v, ⟨853⟩, 0x63, (.Push .PUSH4)) - (by evm_ov), - raw push1 ⟨224⟩ (by attester_decode_at v, ⟨858⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨860⟩, 0x1b, .SHL) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨861⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 6 attesterRequireSelectorMem (UInt256.ofNat 5) - (by attester_decode_at v, ⟨862⟩, 0x52, .MSTORE) - mem_cost (by - unfold attesterRequireSelectorMem - rw [show (⟨128⟩ : UInt256).toNat = 128 by decide]) - (by decide) (by evm_ov), - raw push1 ⟨4⟩ (by attester_decode_at v, ⟨863⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨865⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨866⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 5) (by attester_decode_at v, ⟨868⟩, 0x51, .MLOAD) - mem_cost attesterRequireSelectorMem_mload64 (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨869⟩, 0x80, .DUP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨870⟩, 0x91, .SWAP2) (by evm_ov), - raw sub (by attester_decode_at v, ⟨871⟩, 0x03, .SUB) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨872⟩, 0x90, .SWAP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨873⟩, 0xfd, .REVERT) - mem_cost (by evm_ov)] - -theorem attesterX_multiAttestLengthMismatchReverts {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hnonzero : UInt256.isZero (attesterFirstArrayLengthWord I) = ⟨0⟩) - (hneq : - UInt256.eq (attesterSecondArrayLengthWord I) (attesterFirstArrayLengthWord I) = ⟨0⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨828⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd828⟩ := hreach - exact evm_run rd828 with [ - raw jumpdest (by attester_decode_at v, ⟨828⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨96⟩ (by attester_decode_at v, ⟨829⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨831⟩, 0x83, .DUP4) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨832⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨833⟩, 0x15, .ISZERO) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨834⟩, 0x80, .DUP1) (by evm_ov), - raw push2 ⟨844⟩ (by attester_decode_at v, ⟨835⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨838⟩, 0x57, .JUMPI) - (by rw [hnonzero]) (by evm_ov), - raw pop (by attester_decode_at v, ⟨839⟩, 0x50, .POP) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨840⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨841⟩, 0x83, .DUP4) (by evm_ov), - raw eq (by attester_decode_at v, ⟨842⟩, 0x14, .EQ) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨843⟩, 0x15, .ISZERO) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨844⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨845⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨874⟩ (by attester_decode_at v, ⟨846⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨849⟩, 0x57, .JUMPI) - (by rw [hneq]; decide) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨850⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by attester_decode_at v, ⟨852⟩, 0x51, .MLOAD) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - raw push4 ⟨3036299187⟩ (by attester_decode_at v, ⟨853⟩, 0x63, (.Push .PUSH4)) - (by evm_ov), - raw push1 ⟨224⟩ (by attester_decode_at v, ⟨858⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨860⟩, 0x1b, .SHL) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨861⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 6 attesterRequireSelectorMem (UInt256.ofNat 5) - (by attester_decode_at v, ⟨862⟩, 0x52, .MSTORE) - mem_cost (by - unfold attesterRequireSelectorMem - rw [show (⟨128⟩ : UInt256).toNat = 128 by decide]) - (by decide) (by evm_ov), - raw push1 ⟨4⟩ (by attester_decode_at v, ⟨863⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨865⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨866⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 5) (by attester_decode_at v, ⟨868⟩, 0x51, .MLOAD) - mem_cost attesterRequireSelectorMem_mload64 (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨869⟩, 0x80, .DUP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨870⟩, 0x91, .SWAP2) (by evm_ov), - raw sub (by attester_decode_at v, ⟨871⟩, 0x03, .SUB) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨872⟩, 0x90, .SWAP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨873⟩, 0xfd, .REVERT) - mem_cost (by evm_ov)] - -theorem attesterX_multiAttestLengthGuardOk {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hnonzero : UInt256.isZero (attesterFirstArrayLengthWord I) = ⟨0⟩) - (heq : - UInt256.eq (attesterSecondArrayLengthWord I) (attesterFirstArrayLengthWord I) = ⟨1⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨828⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨874⟩ : UInt256) - [attesterFirstArrayLengthWord I, ⟨96⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd828⟩ := hreach - exact ⟨_, _, evm_run rd828 with [ - raw jumpdest (by attester_decode_at v, ⟨828⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨96⟩ (by attester_decode_at v, ⟨829⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨831⟩, 0x83, .DUP4) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨832⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨833⟩, 0x15, .ISZERO) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨834⟩, 0x80, .DUP1) (by evm_ov), - raw push2 ⟨844⟩ (by attester_decode_at v, ⟨835⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨838⟩, 0x57, .JUMPI) - (by rw [hnonzero]) (by evm_ov), - raw pop (by attester_decode_at v, ⟨839⟩, 0x50, .POP) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨840⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨841⟩, 0x83, .DUP4) (by evm_ov), - raw eq (by attester_decode_at v, ⟨842⟩, 0x14, .EQ) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨843⟩, 0x15, .ISZERO) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨844⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨845⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨874⟩ (by attester_decode_at v, ⟨846⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨849⟩, 0x57, .JUMPI) - (by rw [heq]; decide) (attesterMultiAttestLengthGuardOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiAttestLengthGuardOk_of_lengths {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) {schemas schemaInputs : List Value} - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hoff1Max : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hSchemasLen : - schemas.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hSchemaInputsLen : - schemaInputs.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) - (hnonzero : schemas.length ≠ 0) - (heqLen : schemas.length = schemaInputs.length) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨828⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨874⟩ : UInt256) - [attesterFirstArrayLengthWord I, ⟨96⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hrawFirstNe : - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by omega) - have hrawEq : - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat := by - omega - have hnonzeroEvm := - attesterFirstArrayLengthWord_isZero_of_nat_ne_zero (I := I) hoff0Max hrawFirstNe - have heqEvm := - attesterArrayLengthWords_eq_one_of_nat_eq (I := I) hoff0Max hoff1Max hrawEq - exact attesterX_multiAttestLengthGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) v hnonzeroEvm heqEvm hreach - -theorem attesterX_multiAttestAllocLengthMaxOk {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨874⟩ : UInt256) - [attesterFirstArrayLengthWord I, ⟨96⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨899⟩ : UInt256) - [attesterFirstArrayLengthWord I, ⟨0⟩, attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd874⟩ := hreach - have hgt : - UInt256.gt (attesterFirstArrayLengthWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - have hmaxToNat : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = - solcMaxU64 := by - native_decide - rw [attesterFirstArrayLengthWord_toNat (I := I) hoff0Max, hmaxToNat] - exact Nat.le_of_not_gt hlen0Max - exact ⟨_, _, evm_run rd874 with [ - raw jumpdest (by attester_decode_at v, ⟨874⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨875⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨876⟩, 0x81, .DUP2) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨877⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨879⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨881⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨883⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨884⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨885⟩, 0x81, .DUP2) (by evm_ov), - raw gt (by attester_decode_at v, ⟨886⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨887⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨899⟩ (by attester_decode_at v, ⟨888⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨891⟩, 0x57, .JUMPI) - (by - rw [hgt] - decide) - (attesterMultiAttestAllocLengthMaxOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiAttestOuterArrayInitEntry {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hnonzero : UInt256.isZero (attesterFirstArrayLengthWord I) = ⟨0⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨899⟩ : UInt256) - [attesterFirstArrayLengthWord I, ⟨0⟩, attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨929⟩ : UInt256) - [((⟨32⟩ : UInt256) + ⟨128⟩), attesterFirstArrayLengthWord I, ⟨128⟩, ⟨0⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - (attesterMultiOuterArrayAllocMem I) (UInt256.ofNat 5) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd899⟩ := hreach - exact ⟨_, _, evm_run rd899 with [ - raw jumpdest (by attester_decode_at v, ⟨899⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨900⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by attester_decode_at v, ⟨902⟩, 0x51, .MLOAD) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨903⟩, 0x90, .SWAP1) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨904⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨905⟩, 0x82, .DUP3) (by evm_ov), - raw mstore 6 (attesterMultiOuterArrayLenMem I) (UInt256.ofNat 5) - (by attester_decode_at v, ⟨906⟩, 0x52, .MSTORE) - mem_cost (by rfl) (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨907⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨908⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mul (by attester_decode_at v, ⟨910⟩, 0x02, .MUL) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨911⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨913⟩, 0x01, .ADD) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨914⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨915⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨916⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mstore 0 (attesterMultiOuterArrayAllocMem I) (UInt256.ofNat 5) - (by attester_decode_at v, ⟨918⟩, 0x52, .MSTORE) - mem_cost (by rfl) (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨919⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨920⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨968⟩ (by attester_decode_at v, ⟨921⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨924⟩, 0x57, .JUMPI) - (by rw [hnonzero]) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨925⟩, 0x81, .DUP2) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨926⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨928⟩, 0x01, .ADD) (by evm_ov)]⟩ - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/InnerArray.lean b/Benchmarks/EAS/Attester/InnerArray.lean deleted file mode 100644 index e38c3a27..00000000 --- a/Benchmarks/EAS/Attester/InnerArray.lean +++ /dev/null @@ -1,485 +0,0 @@ -import Benchmarks.EAS.Attester.NestedArray - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -/-! Bytecode facts for the shared inner dynamic-array decoder used inside multi calls. -/ - -set_option maxRecDepth 30000 in -set_option maxHeartbeats 3000000 in -theorem attesterInnerArrayDecoderJumpdests (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨475⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨1113⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨518⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨555⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨589⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨608⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨2353⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨2374⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨2399⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨2422⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨381⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨420⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨445⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨1019⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨1058⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨1083⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨798⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨816⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨2460⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨2516⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨2545⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨2568⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨2592⟩ : UInt256) = true ∧ - (D_J (patchedRuntime v) 0).contains (⟨775⟩ : UInt256) = true := by - unfold D_J - attester_dj_step v, 0, (.Push .PUSH1); attester_dj_step v, 2, (.Push .PUSH1); attester_dj_step v, 4, .MSTORE; attester_dj_step v, 5, .CALLVALUE; attester_dj_step v, 6, .DUP1; attester_dj_step v, 7, .ISZERO; attester_dj_step v, 8, (.Push .PUSH2); attester_dj_step v, 11, .JUMPI - attester_dj_step v, 12, (.Push .PUSH0); attester_dj_step v, 13, .DUP1; attester_dj_step v, 14, .REVERT; attester_dj_step v, 15, .JUMPDEST; attester_dj_step v, 16, .POP; attester_dj_step v, 17, (.Push .PUSH1); attester_dj_step v, 19, .CALLDATASIZE; attester_dj_step v, 20, .LT - attester_dj_step v, 21, (.Push .PUSH2); attester_dj_step v, 24, .JUMPI; attester_dj_step v, 25, (.Push .PUSH0); attester_dj_step v, 26, .CALLDATALOAD; attester_dj_step v, 27, (.Push .PUSH1); attester_dj_step v, 29, .SHR; attester_dj_step v, 30, .DUP1; attester_dj_step v, 31, (.Push .PUSH4) - attester_dj_step v, 36, .EQ; attester_dj_step v, 37, (.Push .PUSH2); attester_dj_step v, 40, .JUMPI; attester_dj_step v, 41, .DUP1; attester_dj_step v, 42, (.Push .PUSH4); attester_dj_step v, 47, .EQ; attester_dj_step v, 48, (.Push .PUSH2); attester_dj_step v, 51, .JUMPI - attester_dj_step v, 52, .DUP1; attester_dj_step v, 53, (.Push .PUSH4); attester_dj_step v, 58, .EQ; attester_dj_step v, 59, (.Push .PUSH2); attester_dj_step v, 62, .JUMPI; attester_dj_step v, 63, .DUP1; attester_dj_step v, 64, (.Push .PUSH4); attester_dj_step v, 69, .EQ - attester_dj_step v, 70, (.Push .PUSH2); attester_dj_step v, 73, .JUMPI; attester_dj_step v, 74, .JUMPDEST; attester_dj_step v, 75, (.Push .PUSH0); attester_dj_step v, 76, .DUP1; attester_dj_step v, 77, .REVERT; attester_dj_step v, 78, .JUMPDEST; attester_dj_step v, 79, (.Push .PUSH2) - attester_dj_step v, 82, (.Push .PUSH2); attester_dj_step v, 85, .CALLDATASIZE; attester_dj_step v, 86, (.Push .PUSH1); attester_dj_step v, 88, (.Push .PUSH2); attester_dj_step v, 91, .JUMP; attester_dj_step v, 92, .JUMPDEST; attester_dj_step v, 93, (.Push .PUSH2); attester_dj_step v, 96, .JUMP - attester_dj_step v, 97, .JUMPDEST; attester_dj_step v, 98, .STOP; attester_dj_step v, 99, .JUMPDEST; attester_dj_step v, 100, (.Push .PUSH2); attester_dj_step v, 103, (.Push .PUSH2); attester_dj_step v, 106, .CALLDATASIZE; attester_dj_step v, 107, (.Push .PUSH1); attester_dj_step v, 109, (.Push .PUSH2) - attester_dj_step v, 112, .JUMP; attester_dj_step v, 113, .JUMPDEST; attester_dj_step v, 114, (.Push .PUSH2); attester_dj_step v, 117, .JUMP; attester_dj_step v, 118, .JUMPDEST; attester_dj_step v, 119, (.Push .PUSH1); attester_dj_step v, 121, .MLOAD; attester_dj_step v, 122, (.Push .PUSH2) - attester_dj_step v, 125, .SWAP2; attester_dj_step v, 126, .SWAP1; attester_dj_step v, 127, (.Push .PUSH2); attester_dj_step v, 130, .JUMP; attester_dj_step v, 131, .JUMPDEST; attester_dj_step v, 132, (.Push .PUSH1); attester_dj_step v, 134, .MLOAD; attester_dj_step v, 135, .DUP1 - attester_dj_step v, 136, .SWAP2; attester_dj_step v, 137, .SUB; attester_dj_step v, 138, .SWAP1; attester_dj_step v, 139, .RETURN; attester_dj_step v, 140, .JUMPDEST; attester_dj_step v, 141, (.Push .PUSH2); attester_dj_step v, 144, (.Push .PUSH2); attester_dj_step v, 147, .CALLDATASIZE - attester_dj_step v, 148, (.Push .PUSH1); attester_dj_step v, 150, (.Push .PUSH2); attester_dj_step v, 153, .JUMP; attester_dj_step v, 154, .JUMPDEST; attester_dj_step v, 155, (.Push .PUSH2); attester_dj_step v, 158, .JUMP; attester_dj_step v, 159, .JUMPDEST; attester_dj_step v, 160, (.Push .PUSH1) - attester_dj_step v, 162, .MLOAD; attester_dj_step v, 163, .SWAP1; attester_dj_step v, 164, .DUP2; attester_dj_step v, 165, .MSTORE; attester_dj_step v, 166, (.Push .PUSH1); attester_dj_step v, 168, .ADD; attester_dj_step v, 169, (.Push .PUSH2); attester_dj_step v, 172, .JUMP - attester_dj_step v, 173, .JUMPDEST; attester_dj_step v, 174, (.Push .PUSH2); attester_dj_step v, 177, (.Push .PUSH2); attester_dj_step v, 180, .CALLDATASIZE; attester_dj_step v, 181, (.Push .PUSH1); attester_dj_step v, 183, (.Push .PUSH2); attester_dj_step v, 186, .JUMP; attester_dj_step v, 187, .JUMPDEST - attester_dj_step v, 188, (.Push .PUSH2); attester_dj_step v, 191, .JUMP; attester_dj_step v, 192, .JUMPDEST; attester_dj_step v, 193, .DUP3; attester_dj_step v, 194, .DUP1; attester_dj_step v, 195, .ISZERO; attester_dj_step v, 196, .DUP1; attester_dj_step v, 197, (.Push .PUSH2) - attester_dj_step v, 200, .JUMPI; attester_dj_step v, 201, .POP; attester_dj_step v, 202, .DUP1; attester_dj_step v, 203, .DUP3; attester_dj_step v, 204, .EQ; attester_dj_step v, 205, .ISZERO; attester_dj_step v, 206, .JUMPDEST; attester_dj_step v, 207, .ISZERO - attester_dj_step v, 208, (.Push .PUSH2); attester_dj_step v, 211, .JUMPI; attester_dj_step v, 212, (.Push .PUSH1); attester_dj_step v, 214, .MLOAD; attester_dj_step v, 215, (.Push .PUSH4); attester_dj_step v, 220, (.Push .PUSH1); attester_dj_step v, 222, .SHL; attester_dj_step v, 223, .DUP2 - attester_dj_step v, 224, .MSTORE; attester_dj_step v, 225, (.Push .PUSH1); attester_dj_step v, 227, .ADD; attester_dj_step v, 228, (.Push .PUSH1); attester_dj_step v, 230, .MLOAD; attester_dj_step v, 231, .DUP1; attester_dj_step v, 232, .SWAP2; attester_dj_step v, 233, .SUB - attester_dj_step v, 234, .SWAP1; attester_dj_step v, 235, .REVERT; attester_dj_step v, 236, .JUMPDEST; attester_dj_step v, 237, (.Push .PUSH0); attester_dj_step v, 238, .DUP2; attester_dj_step v, 239, (.Push .PUSH1); attester_dj_step v, 241, (.Push .PUSH1); attester_dj_step v, 243, (.Push .PUSH1) - attester_dj_step v, 245, .SHL; attester_dj_step v, 246, .SUB; attester_dj_step v, 247, .DUP2; attester_dj_step v, 248, .GT; attester_dj_step v, 249, .ISZERO; attester_dj_step v, 250, (.Push .PUSH2); attester_dj_step v, 253, .JUMPI; attester_dj_step v, 254, (.Push .PUSH2) - attester_dj_step v, 257, (.Push .PUSH2); attester_dj_step v, 260, .JUMP; attester_dj_step v, 261, .JUMPDEST; attester_dj_step v, 262, (.Push .PUSH1); attester_dj_step v, 264, .MLOAD; attester_dj_step v, 265, .SWAP1; attester_dj_step v, 266, .DUP1; attester_dj_step v, 267, .DUP3 - attester_dj_step v, 268, .MSTORE; attester_dj_step v, 269, .DUP1; attester_dj_step v, 270, (.Push .PUSH1); attester_dj_step v, 272, .MUL; attester_dj_step v, 273, (.Push .PUSH1); attester_dj_step v, 275, .ADD; attester_dj_step v, 276, .DUP3; attester_dj_step v, 277, .ADD - attester_dj_step v, 278, (.Push .PUSH1); attester_dj_step v, 280, .MSTORE; attester_dj_step v, 281, .DUP1; attester_dj_step v, 282, .ISZERO; attester_dj_step v, 283, (.Push .PUSH2); attester_dj_step v, 286, .JUMPI; attester_dj_step v, 287, .DUP2; attester_dj_step v, 288, (.Push .PUSH1) - attester_dj_step v, 290, .ADD; attester_dj_step v, 291, .JUMPDEST; attester_dj_step v, 292, (.Push .PUSH1); attester_dj_step v, 294, .DUP1; attester_dj_step v, 295, .MLOAD; attester_dj_step v, 296, .DUP1; attester_dj_step v, 297, .DUP3; attester_dj_step v, 298, .ADD - attester_dj_step v, 299, .SWAP1; attester_dj_step v, 300, .SWAP2; attester_dj_step v, 301, .MSTORE; attester_dj_step v, 302, (.Push .PUSH0); attester_dj_step v, 303, .DUP2; attester_dj_step v, 304, .MSTORE; attester_dj_step v, 305, (.Push .PUSH1); attester_dj_step v, 307, (.Push .PUSH1) - attester_dj_step v, 309, .DUP3; attester_dj_step v, 310, .ADD; attester_dj_step v, 311, .MSTORE; attester_dj_step v, 312, .DUP2; attester_dj_step v, 313, .MSTORE; attester_dj_step v, 314, (.Push .PUSH1); attester_dj_step v, 316, .ADD; attester_dj_step v, 317, .SWAP1 - attester_dj_step v, 318, (.Push .PUSH1); attester_dj_step v, 320, .SWAP1; attester_dj_step v, 321, .SUB; attester_dj_step v, 322, .SWAP1; attester_dj_step v, 323, .DUP2; attester_dj_step v, 324, (.Push .PUSH2); attester_dj_step v, 327, .JUMPI; attester_dj_step v, 328, .SWAP1 - attester_dj_step v, 329, .POP; attester_dj_step v, 330, .JUMPDEST; attester_dj_step v, 331, .POP; attester_dj_step v, 332, .SWAP1; attester_dj_step v, 333, .POP; attester_dj_step v, 334, (.Push .PUSH0); attester_dj_step v, 335, .JUMPDEST; attester_dj_step v, 336, .DUP3 - attester_dj_step v, 337, .DUP2; attester_dj_step v, 338, .LT; attester_dj_step v, 339, .ISZERO; attester_dj_step v, 340, (.Push .PUSH2); attester_dj_step v, 343, .JUMPI; attester_dj_step v, 344, .CALLDATASIZE; attester_dj_step v, 345, (.Push .PUSH0); attester_dj_step v, 346, .DUP7 - attester_dj_step v, 347, .DUP7; attester_dj_step v, 348, .DUP5; attester_dj_step v, 349, .DUP2; attester_dj_step v, 350, .DUP2; attester_dj_step v, 351, .LT; attester_dj_step v, 352, (.Push .PUSH2); attester_dj_step v, 355, .JUMPI; attester_dj_step v, 356, (.Push .PUSH2) - attester_dj_step v, 359, (.Push .PUSH2); attester_dj_step v, 362, .JUMP; attester_dj_step v, 363, .JUMPDEST; attester_dj_step v, 364, .SWAP1; attester_dj_step v, 365, .POP; attester_dj_step v, 366, (.Push .PUSH1); attester_dj_step v, 368, .MUL; attester_dj_step v, 369, .DUP2 - attester_dj_step v, 370, .ADD; attester_dj_step v, 371, .SWAP1; attester_dj_step v, 372, (.Push .PUSH2); attester_dj_step v, 375, .SWAP2; attester_dj_step v, 376, .SWAP1; attester_dj_step v, 377, (.Push .PUSH2); attester_dj_step v, 380, .JUMP; attester_dj_step v, 381, .JUMPDEST - attester_dj_step v, 382, .SWAP1; attester_dj_step v, 383, .SWAP3; attester_dj_step v, 384, .POP; attester_dj_step v, 385, .SWAP1; attester_dj_step v, 386, .POP; attester_dj_step v, 387, .DUP1; attester_dj_step v, 388, (.Push .PUSH0); attester_dj_step v, 389, .DUP2 - attester_dj_step v, 390, .SWAP1; attester_dj_step v, 391, .SUB; attester_dj_step v, 392, (.Push .PUSH2); attester_dj_step v, 395, .JUMPI; attester_dj_step v, 396, (.Push .PUSH1); attester_dj_step v, 398, .MLOAD; attester_dj_step v, 399, (.Push .PUSH4); attester_dj_step v, 404, (.Push .PUSH1) - attester_dj_step v, 406, .SHL; attester_dj_step v, 407, .DUP2; attester_dj_step v, 408, .MSTORE; attester_dj_step v, 409, (.Push .PUSH1); attester_dj_step v, 411, .ADD; attester_dj_step v, 412, (.Push .PUSH1); attester_dj_step v, 414, .MLOAD; attester_dj_step v, 415, .DUP1 - attester_dj_step v, 416, .SWAP2; attester_dj_step v, 417, .SUB; attester_dj_step v, 418, .SWAP1; attester_dj_step v, 419, .REVERT; attester_dj_step v, 420, .JUMPDEST; attester_dj_step v, 421, (.Push .PUSH0); attester_dj_step v, 422, .DUP2; attester_dj_step v, 423, (.Push .PUSH1) - attester_dj_step v, 425, (.Push .PUSH1); attester_dj_step v, 427, (.Push .PUSH1); attester_dj_step v, 429, .SHL; attester_dj_step v, 430, .SUB; attester_dj_step v, 431, .DUP2; attester_dj_step v, 432, .GT; attester_dj_step v, 433, .ISZERO; attester_dj_step v, 434, (.Push .PUSH2) - attester_dj_step v, 437, .JUMPI; attester_dj_step v, 438, (.Push .PUSH2); attester_dj_step v, 441, (.Push .PUSH2); attester_dj_step v, 444, .JUMP; attester_dj_step v, 445, .JUMPDEST; attester_dj_step v, 446, (.Push .PUSH1); attester_dj_step v, 448, .MLOAD; attester_dj_step v, 449, .SWAP1 - attester_dj_step v, 450, .DUP1; attester_dj_step v, 451, .DUP3; attester_dj_step v, 452, .MSTORE; attester_dj_step v, 453, .DUP1; attester_dj_step v, 454, (.Push .PUSH1); attester_dj_step v, 456, .MUL; attester_dj_step v, 457, (.Push .PUSH1); attester_dj_step v, 459, .ADD - attester_dj_step v, 460, .DUP3; attester_dj_step v, 461, .ADD; attester_dj_step v, 462, (.Push .PUSH1); attester_dj_step v, 464, .MSTORE; attester_dj_step v, 465, .DUP1; attester_dj_step v, 466, .ISZERO; attester_dj_step v, 467, (.Push .PUSH2); attester_dj_step v, 470, .JUMPI - attester_dj_step v, 471, .DUP2; attester_dj_step v, 472, (.Push .PUSH1); attester_dj_step v, 474, .ADD; attester_dj_step v, 475, .JUMPDEST; attester_dj_step v, 476, (.Push .PUSH1); attester_dj_step v, 478, .DUP1; attester_dj_step v, 479, .MLOAD; attester_dj_step v, 480, .DUP1 - attester_dj_step v, 481, .DUP3; attester_dj_step v, 482, .ADD; attester_dj_step v, 483, .SWAP1; attester_dj_step v, 484, .SWAP2; attester_dj_step v, 485, .MSTORE; attester_dj_step v, 486, (.Push .PUSH0); attester_dj_step v, 487, .DUP1; attester_dj_step v, 488, .DUP3 - attester_dj_step v, 489, .MSTORE; attester_dj_step v, 490, (.Push .PUSH1); attester_dj_step v, 492, .DUP3; attester_dj_step v, 493, .ADD; attester_dj_step v, 494, .MSTORE; attester_dj_step v, 495, .DUP2; attester_dj_step v, 496, .MSTORE; attester_dj_step v, 497, (.Push .PUSH1) - attester_dj_step v, 499, .ADD; attester_dj_step v, 500, .SWAP1; attester_dj_step v, 501, (.Push .PUSH1); attester_dj_step v, 503, .SWAP1; attester_dj_step v, 504, .SUB; attester_dj_step v, 505, .SWAP1; attester_dj_step v, 506, .DUP2; attester_dj_step v, 507, (.Push .PUSH2) - attester_dj_step v, 510, .JUMPI; attester_dj_step v, 511, .SWAP1; attester_dj_step v, 512, .POP; attester_dj_step v, 513, .JUMPDEST; attester_dj_step v, 514, .POP; attester_dj_step v, 515, .SWAP1; attester_dj_step v, 516, .POP; attester_dj_step v, 517, (.Push .PUSH0) - attester_dj_step v, 518, .JUMPDEST; attester_dj_step v, 519, .DUP3; attester_dj_step v, 520, .DUP2; attester_dj_step v, 521, .LT; attester_dj_step v, 522, .ISZERO; attester_dj_step v, 523, (.Push .PUSH2); attester_dj_step v, 526, .JUMPI; attester_dj_step v, 527, (.Push .PUSH1) - attester_dj_step v, 529, .MLOAD; attester_dj_step v, 530, .DUP1; attester_dj_step v, 531, (.Push .PUSH1); attester_dj_step v, 533, .ADD; attester_dj_step v, 534, (.Push .PUSH1); attester_dj_step v, 536, .MSTORE; attester_dj_step v, 537, .DUP1; attester_dj_step v, 538, .DUP7 - attester_dj_step v, 539, .DUP7; attester_dj_step v, 540, .DUP5; attester_dj_step v, 541, .DUP2; attester_dj_step v, 542, .DUP2; attester_dj_step v, 543, .LT; attester_dj_step v, 544, (.Push .PUSH2); attester_dj_step v, 547, .JUMPI; attester_dj_step v, 548, (.Push .PUSH2) - attester_dj_step v, 551, (.Push .PUSH2); attester_dj_step v, 554, .JUMP; attester_dj_step v, 555, .JUMPDEST; attester_dj_step v, 556, .SWAP1; attester_dj_step v, 557, .POP; attester_dj_step v, 558, (.Push .PUSH1); attester_dj_step v, 560, .MUL; attester_dj_step v, 561, .ADD - attester_dj_step v, 562, .CALLDATALOAD; attester_dj_step v, 563, .DUP2; attester_dj_step v, 564, .MSTORE; attester_dj_step v, 565, (.Push .PUSH1); attester_dj_step v, 567, .ADD; attester_dj_step v, 568, (.Push .PUSH0); attester_dj_step v, 569, .DUP2; attester_dj_step v, 570, .MSTORE - attester_dj_step v, 571, .POP; attester_dj_step v, 572, .DUP3; attester_dj_step v, 573, .DUP3; attester_dj_step v, 574, .DUP2; attester_dj_step v, 575, .MLOAD; attester_dj_step v, 576, .DUP2; attester_dj_step v, 577, .LT; attester_dj_step v, 578, (.Push .PUSH2) - attester_dj_step v, 581, .JUMPI; attester_dj_step v, 582, (.Push .PUSH2); attester_dj_step v, 585, (.Push .PUSH2); attester_dj_step v, 588, .JUMP; attester_dj_step v, 589, .JUMPDEST; attester_dj_step v, 590, (.Push .PUSH1); attester_dj_step v, 592, .SWAP1; attester_dj_step v, 593, .DUP2 - attester_dj_step v, 594, .MUL; attester_dj_step v, 595, .SWAP2; attester_dj_step v, 596, .SWAP1; attester_dj_step v, 597, .SWAP2; attester_dj_step v, 598, .ADD; attester_dj_step v, 599, .ADD; attester_dj_step v, 600, .MSTORE; attester_dj_step v, 601, (.Push .PUSH1) - attester_dj_step v, 603, .ADD; attester_dj_step v, 604, (.Push .PUSH2); attester_dj_step v, 607, .JUMP; attester_dj_step v, 608, .JUMPDEST; attester_dj_step v, 609, .POP; attester_dj_step v, 610, (.Push .PUSH1); attester_dj_step v, 612, .MLOAD; attester_dj_step v, 613, .DUP1 - attester_dj_step v, 614, (.Push .PUSH1); attester_dj_step v, 616, .ADD; attester_dj_step v, 617, (.Push .PUSH1); attester_dj_step v, 619, .MSTORE; attester_dj_step v, 620, .DUP1; attester_dj_step v, 621, .DUP13; attester_dj_step v, 622, .DUP13; attester_dj_step v, 623, .DUP9 - attester_dj_step v, 624, .DUP2; attester_dj_step v, 625, .DUP2; attester_dj_step v, 626, .LT; attester_dj_step v, 627, (.Push .PUSH2); attester_dj_step v, 630, .JUMPI; attester_dj_step v, 631, (.Push .PUSH2); attester_dj_step v, 634, (.Push .PUSH2); attester_dj_step v, 637, .JUMP - attester_dj_step v, 638, .JUMPDEST; attester_dj_step v, 639, .SWAP1; attester_dj_step v, 640, .POP; attester_dj_step v, 641, (.Push .PUSH1); attester_dj_step v, 643, .MUL; attester_dj_step v, 644, .ADD; attester_dj_step v, 645, .CALLDATALOAD; attester_dj_step v, 646, .DUP2 - attester_dj_step v, 647, .MSTORE; attester_dj_step v, 648, (.Push .PUSH1); attester_dj_step v, 650, .ADD; attester_dj_step v, 651, .DUP3; attester_dj_step v, 652, .DUP2; attester_dj_step v, 653, .MSTORE; attester_dj_step v, 654, .POP; attester_dj_step v, 655, .DUP7 - attester_dj_step v, 656, .DUP7; attester_dj_step v, 657, .DUP2; attester_dj_step v, 658, .MLOAD; attester_dj_step v, 659, .DUP2; attester_dj_step v, 660, .LT; attester_dj_step v, 661, (.Push .PUSH2); attester_dj_step v, 664, .JUMPI; attester_dj_step v, 665, (.Push .PUSH2) - attester_dj_step v, 668, (.Push .PUSH2); attester_dj_step v, 671, .JUMP; attester_dj_step v, 672, .JUMPDEST; attester_dj_step v, 673, (.Push .PUSH1); attester_dj_step v, 675, .MUL; attester_dj_step v, 676, (.Push .PUSH1); attester_dj_step v, 678, .ADD; attester_dj_step v, 679, .ADD - attester_dj_step v, 680, .DUP2; attester_dj_step v, 681, .SWAP1; attester_dj_step v, 682, .MSTORE; attester_dj_step v, 683, .POP; attester_dj_step v, 684, .POP; attester_dj_step v, 685, .POP; attester_dj_step v, 686, .POP; attester_dj_step v, 687, .POP - attester_dj_step v, 688, .DUP1; attester_dj_step v, 689, (.Push .PUSH1); attester_dj_step v, 691, .ADD; attester_dj_step v, 692, .SWAP1; attester_dj_step v, 693, .POP; attester_dj_step v, 694, (.Push .PUSH2); attester_dj_step v, 697, .JUMP; attester_dj_step v, 698, .JUMPDEST - attester_dj_step v, 699, .POP; attester_dj_step v, 700, (.Push .PUSH1); attester_dj_step v, 702, .MLOAD; attester_dj_step v, 703, (.Push .PUSH4); attester_dj_step v, 708, (.Push .PUSH1); attester_dj_step v, 710, .SHL; attester_dj_step v, 711, .DUP2; attester_dj_step v, 712, .MSTORE - attester_dj_step v, 713, (.Push .PUSH1); attester_dj_step v, 715, (.Push .PUSH1); attester_dj_step v, 717, (.Push .PUSH1); attester_dj_step v, 719, .SHL; attester_dj_step v, 720, .SUB; attester_dj_step v, 721, (.Push .PUSH32); attester_dj_step v, 754, .AND; attester_dj_step v, 755, .SWAP1 - attester_dj_step v, 756, (.Push .PUSH4); attester_dj_step v, 761, .SWAP1; attester_dj_step v, 762, (.Push .PUSH2); attester_dj_step v, 765, .SWAP1; attester_dj_step v, 766, .DUP5; attester_dj_step v, 767, .SWAP1; attester_dj_step v, 768, (.Push .PUSH1); attester_dj_step v, 770, .ADD - attester_dj_step v, 771, (.Push .PUSH2); attester_dj_step v, 774, .JUMP; attester_dj_step v, 775, .JUMPDEST; attester_dj_step v, 776, (.Push .PUSH0); attester_dj_step v, 777, (.Push .PUSH1); attester_dj_step v, 779, .MLOAD; attester_dj_step v, 780, .DUP1; attester_dj_step v, 781, .DUP4 - attester_dj_step v, 782, .SUB; attester_dj_step v, 783, .DUP2; attester_dj_step v, 784, (.Push .PUSH0); attester_dj_step v, 785, .DUP8; attester_dj_step v, 786, .DUP1; attester_dj_step v, 787, .EXTCODESIZE; attester_dj_step v, 788, .ISZERO; attester_dj_step v, 789, .DUP1 - attester_dj_step v, 790, .ISZERO; attester_dj_step v, 791, (.Push .PUSH2); attester_dj_step v, 794, .JUMPI; attester_dj_step v, 795, (.Push .PUSH0); attester_dj_step v, 796, .DUP1; attester_dj_step v, 797, .REVERT; attester_dj_step v, 798, .JUMPDEST; attester_dj_step v, 799, .POP - attester_dj_step v, 800, .GAS; attester_dj_step v, 801, .CALL; attester_dj_step v, 802, .ISZERO; attester_dj_step v, 803, .DUP1; attester_dj_step v, 804, .ISZERO; attester_dj_step v, 805, (.Push .PUSH2); attester_dj_step v, 808, .JUMPI; attester_dj_step v, 809, .RETURNDATASIZE - attester_dj_step v, 810, (.Push .PUSH0); attester_dj_step v, 811, .DUP1; attester_dj_step v, 812, .RETURNDATACOPY; attester_dj_step v, 813, .RETURNDATASIZE; attester_dj_step v, 814, (.Push .PUSH0); attester_dj_step v, 815, .REVERT; attester_dj_step v, 816, .JUMPDEST; attester_dj_step v, 817, .POP - attester_dj_step v, 818, .POP; attester_dj_step v, 819, .POP; attester_dj_step v, 820, .POP; attester_dj_step v, 821, .POP; attester_dj_step v, 822, .POP; attester_dj_step v, 823, .POP; attester_dj_step v, 824, .POP; attester_dj_step v, 825, .POP - attester_dj_step v, 826, .POP; attester_dj_step v, 827, .JUMP; attester_dj_step v, 828, .JUMPDEST; attester_dj_step v, 829, (.Push .PUSH1); attester_dj_step v, 831, .DUP4; attester_dj_step v, 832, .DUP1; attester_dj_step v, 833, .ISZERO; attester_dj_step v, 834, .DUP1 - attester_dj_step v, 835, (.Push .PUSH2); attester_dj_step v, 838, .JUMPI; attester_dj_step v, 839, .POP; attester_dj_step v, 840, .DUP1; attester_dj_step v, 841, .DUP4; attester_dj_step v, 842, .EQ; attester_dj_step v, 843, .ISZERO; attester_dj_step v, 844, .JUMPDEST - attester_dj_step v, 845, .ISZERO; attester_dj_step v, 846, (.Push .PUSH2); attester_dj_step v, 849, .JUMPI; attester_dj_step v, 850, (.Push .PUSH1); attester_dj_step v, 852, .MLOAD; attester_dj_step v, 853, (.Push .PUSH4); attester_dj_step v, 858, (.Push .PUSH1); attester_dj_step v, 860, .SHL - attester_dj_step v, 861, .DUP2; attester_dj_step v, 862, .MSTORE; attester_dj_step v, 863, (.Push .PUSH1); attester_dj_step v, 865, .ADD; attester_dj_step v, 866, (.Push .PUSH1); attester_dj_step v, 868, .MLOAD; attester_dj_step v, 869, .DUP1; attester_dj_step v, 870, .SWAP2 - attester_dj_step v, 871, .SUB; attester_dj_step v, 872, .SWAP1; attester_dj_step v, 873, .REVERT; attester_dj_step v, 874, .JUMPDEST; attester_dj_step v, 875, (.Push .PUSH0); attester_dj_step v, 876, .DUP2; attester_dj_step v, 877, (.Push .PUSH1); attester_dj_step v, 879, (.Push .PUSH1) - attester_dj_step v, 881, (.Push .PUSH1); attester_dj_step v, 883, .SHL; attester_dj_step v, 884, .SUB; attester_dj_step v, 885, .DUP2; attester_dj_step v, 886, .GT; attester_dj_step v, 887, .ISZERO; attester_dj_step v, 888, (.Push .PUSH2); attester_dj_step v, 891, .JUMPI - attester_dj_step v, 892, (.Push .PUSH2); attester_dj_step v, 895, (.Push .PUSH2); attester_dj_step v, 898, .JUMP; attester_dj_step v, 899, .JUMPDEST; attester_dj_step v, 900, (.Push .PUSH1); attester_dj_step v, 902, .MLOAD; attester_dj_step v, 903, .SWAP1; attester_dj_step v, 904, .DUP1 - attester_dj_step v, 905, .DUP3; attester_dj_step v, 906, .MSTORE; attester_dj_step v, 907, .DUP1; attester_dj_step v, 908, (.Push .PUSH1); attester_dj_step v, 910, .MUL; attester_dj_step v, 911, (.Push .PUSH1); attester_dj_step v, 913, .ADD; attester_dj_step v, 914, .DUP3 - attester_dj_step v, 915, .ADD; attester_dj_step v, 916, (.Push .PUSH1); attester_dj_step v, 918, .MSTORE; attester_dj_step v, 919, .DUP1; attester_dj_step v, 920, .ISZERO; attester_dj_step v, 921, (.Push .PUSH2); attester_dj_step v, 924, .JUMPI; attester_dj_step v, 925, .DUP2 - attester_dj_step v, 926, (.Push .PUSH1); attester_dj_step v, 928, .ADD; attester_dj_step v, 929, .JUMPDEST; attester_dj_step v, 930, (.Push .PUSH1); attester_dj_step v, 932, .DUP1; attester_dj_step v, 933, .MLOAD; attester_dj_step v, 934, .DUP1; attester_dj_step v, 935, .DUP3 - attester_dj_step v, 936, .ADD; attester_dj_step v, 937, .SWAP1; attester_dj_step v, 938, .SWAP2; attester_dj_step v, 939, .MSTORE; attester_dj_step v, 940, (.Push .PUSH0); attester_dj_step v, 941, .DUP2; attester_dj_step v, 942, .MSTORE; attester_dj_step v, 943, (.Push .PUSH1) - attester_dj_step v, 945, (.Push .PUSH1); attester_dj_step v, 947, .DUP3; attester_dj_step v, 948, .ADD; attester_dj_step v, 949, .MSTORE; attester_dj_step v, 950, .DUP2; attester_dj_step v, 951, .MSTORE; attester_dj_step v, 952, (.Push .PUSH1); attester_dj_step v, 954, .ADD - attester_dj_step v, 955, .SWAP1; attester_dj_step v, 956, (.Push .PUSH1); attester_dj_step v, 958, .SWAP1; attester_dj_step v, 959, .SUB; attester_dj_step v, 960, .SWAP1; attester_dj_step v, 961, .DUP2; attester_dj_step v, 962, (.Push .PUSH2); attester_dj_step v, 965, .JUMPI - attester_dj_step v, 966, .SWAP1; attester_dj_step v, 967, .POP; attester_dj_step v, 968, .JUMPDEST; attester_dj_step v, 969, .POP; attester_dj_step v, 970, .SWAP1; attester_dj_step v, 971, .POP; attester_dj_step v, 972, (.Push .PUSH0); attester_dj_step v, 973, .JUMPDEST - attester_dj_step v, 974, .DUP3; attester_dj_step v, 975, .DUP2; attester_dj_step v, 976, .LT; attester_dj_step v, 977, .ISZERO; attester_dj_step v, 978, (.Push .PUSH2); attester_dj_step v, 981, .JUMPI; attester_dj_step v, 982, .CALLDATASIZE; attester_dj_step v, 983, (.Push .PUSH0) - attester_dj_step v, 984, .DUP8; attester_dj_step v, 985, .DUP8; attester_dj_step v, 986, .DUP5; attester_dj_step v, 987, .DUP2; attester_dj_step v, 988, .DUP2; attester_dj_step v, 989, .LT; attester_dj_step v, 990, (.Push .PUSH2); attester_dj_step v, 993, .JUMPI - attester_dj_step v, 994, (.Push .PUSH2); attester_dj_step v, 997, (.Push .PUSH2); attester_dj_step v, 1000, .JUMP; attester_dj_step v, 1001, .JUMPDEST; attester_dj_step v, 1002, .SWAP1; attester_dj_step v, 1003, .POP; attester_dj_step v, 1004, (.Push .PUSH1); attester_dj_step v, 1006, .MUL - attester_dj_step v, 1007, .DUP2; attester_dj_step v, 1008, .ADD; attester_dj_step v, 1009, .SWAP1; attester_dj_step v, 1010, (.Push .PUSH2); attester_dj_step v, 1013, .SWAP2; attester_dj_step v, 1014, .SWAP1; attester_dj_step v, 1015, (.Push .PUSH2); attester_dj_step v, 1018, .JUMP - attester_dj_step v, 1019, .JUMPDEST; attester_dj_step v, 1020, .SWAP1; attester_dj_step v, 1021, .SWAP3; attester_dj_step v, 1022, .POP; attester_dj_step v, 1023, .SWAP1; attester_dj_step v, 1024, .POP; attester_dj_step v, 1025, .DUP1; attester_dj_step v, 1026, (.Push .PUSH0) - attester_dj_step v, 1027, .DUP2; attester_dj_step v, 1028, .SWAP1; attester_dj_step v, 1029, .SUB; attester_dj_step v, 1030, (.Push .PUSH2); attester_dj_step v, 1033, .JUMPI; attester_dj_step v, 1034, (.Push .PUSH1); attester_dj_step v, 1036, .MLOAD; attester_dj_step v, 1037, (.Push .PUSH4) - attester_dj_step v, 1042, (.Push .PUSH1); attester_dj_step v, 1044, .SHL; attester_dj_step v, 1045, .DUP2; attester_dj_step v, 1046, .MSTORE; attester_dj_step v, 1047, (.Push .PUSH1); attester_dj_step v, 1049, .ADD; attester_dj_step v, 1050, (.Push .PUSH1); attester_dj_step v, 1052, .MLOAD - attester_dj_step v, 1053, .DUP1; attester_dj_step v, 1054, .SWAP2; attester_dj_step v, 1055, .SUB; attester_dj_step v, 1056, .SWAP1; attester_dj_step v, 1057, .REVERT; attester_dj_step v, 1058, .JUMPDEST; attester_dj_step v, 1059, (.Push .PUSH0); attester_dj_step v, 1060, .DUP2 - attester_dj_step v, 1061, (.Push .PUSH1); attester_dj_step v, 1063, (.Push .PUSH1); attester_dj_step v, 1065, (.Push .PUSH1); attester_dj_step v, 1067, .SHL; attester_dj_step v, 1068, .SUB; attester_dj_step v, 1069, .DUP2; attester_dj_step v, 1070, .GT; attester_dj_step v, 1071, .ISZERO - attester_dj_step v, 1072, (.Push .PUSH2); attester_dj_step v, 1075, .JUMPI; attester_dj_step v, 1076, (.Push .PUSH2); attester_dj_step v, 1079, (.Push .PUSH2); attester_dj_step v, 1082, .JUMP; attester_dj_step v, 1083, .JUMPDEST; attester_dj_step v, 1084, (.Push .PUSH1); attester_dj_step v, 1086, .MLOAD - attester_dj_step v, 1087, .SWAP1; attester_dj_step v, 1088, .DUP1; attester_dj_step v, 1089, .DUP3; attester_dj_step v, 1090, .MSTORE; attester_dj_step v, 1091, .DUP1; attester_dj_step v, 1092, (.Push .PUSH1); attester_dj_step v, 1094, .MUL; attester_dj_step v, 1095, (.Push .PUSH1) - attester_dj_step v, 1097, .ADD; attester_dj_step v, 1098, .DUP3; attester_dj_step v, 1099, .ADD; attester_dj_step v, 1100, (.Push .PUSH1); attester_dj_step v, 1102, .MSTORE; attester_dj_step v, 1103, .DUP1; attester_dj_step v, 1104, .ISZERO; attester_dj_step v, 1105, (.Push .PUSH2) - attester_dj_step v, 1108, .JUMPI; attester_dj_step v, 1109, .DUP2; attester_dj_step v, 1110, (.Push .PUSH1); attester_dj_step v, 1112, .ADD; attester_dj_step v, 1113, .JUMPDEST; attester_dj_step v, 1114, (.Push .PUSH1); attester_dj_step v, 1116, .DUP1; attester_dj_step v, 1117, .MLOAD - attester_dj_step v, 1118, (.Push .PUSH1); attester_dj_step v, 1120, .DUP2; attester_dj_step v, 1121, .ADD; attester_dj_step v, 1122, .DUP3; attester_dj_step v, 1123, .MSTORE; attester_dj_step v, 1124, (.Push .PUSH0); attester_dj_step v, 1125, .DUP1; attester_dj_step v, 1126, .DUP3 - attester_dj_step v, 1127, .MSTORE; attester_dj_step v, 1128, (.Push .PUSH1); attester_dj_step v, 1130, .DUP1; attester_dj_step v, 1131, .DUP4; attester_dj_step v, 1132, .ADD; attester_dj_step v, 1133, .DUP3; attester_dj_step v, 1134, .SWAP1; attester_dj_step v, 1135, .MSTORE - attester_dj_step v, 1136, .SWAP3; attester_dj_step v, 1137, .DUP3; attester_dj_step v, 1138, .ADD; attester_dj_step v, 1139, .DUP2; attester_dj_step v, 1140, .SWAP1; attester_dj_step v, 1141, .MSTORE; attester_dj_step v, 1142, (.Push .PUSH1); attester_dj_step v, 1144, .DUP1 - attester_dj_step v, 1145, .DUP4; attester_dj_step v, 1146, .ADD; attester_dj_step v, 1147, .DUP3; attester_dj_step v, 1148, .SWAP1; attester_dj_step v, 1149, .MSTORE; attester_dj_step v, 1150, (.Push .PUSH1); attester_dj_step v, 1152, .DUP4; attester_dj_step v, 1153, .ADD - attester_dj_step v, 1154, .MSTORE; attester_dj_step v, 1155, (.Push .PUSH1); attester_dj_step v, 1157, .DUP3; attester_dj_step v, 1158, .ADD; attester_dj_step v, 1159, .MSTORE; attester_dj_step v, 1160, .DUP3; attester_dj_step v, 1161, .MSTORE; attester_dj_step v, 1162, (.Push .PUSH0) - attester_dj_step v, 1163, .NOT; attester_dj_step v, 1164, .SWAP1; attester_dj_step v, 1165, .SWAP3; attester_dj_step v, 1166, .ADD; attester_dj_step v, 1167, .SWAP2; attester_dj_step v, 1168, .ADD; attester_dj_step v, 1169, .DUP2; attester_dj_step v, 1170, (.Push .PUSH2) - attester_dj_step v, 1173, .JUMPI; attester_dj_step v, 1174, .SWAP1; attester_dj_step v, 1175, .POP; attester_dj_step v, 1176, .JUMPDEST; attester_dj_step v, 1177, .POP; attester_dj_step v, 1178, .SWAP1; attester_dj_step v, 1179, .POP; attester_dj_step v, 1180, (.Push .PUSH0) - attester_dj_step v, 1181, .JUMPDEST; attester_dj_step v, 1182, .DUP3; attester_dj_step v, 1183, .DUP2; attester_dj_step v, 1184, .LT; attester_dj_step v, 1185, .ISZERO; attester_dj_step v, 1186, (.Push .PUSH2); attester_dj_step v, 1189, .JUMPI; attester_dj_step v, 1190, (.Push .PUSH1) - attester_dj_step v, 1192, .MLOAD; attester_dj_step v, 1193, .DUP1; attester_dj_step v, 1194, (.Push .PUSH1); attester_dj_step v, 1196, .ADD; attester_dj_step v, 1197, (.Push .PUSH1); attester_dj_step v, 1199, .MSTORE; attester_dj_step v, 1200, .DUP1; attester_dj_step v, 1201, (.Push .PUSH0) - attester_dj_step v, 1202, (.Push .PUSH1); attester_dj_step v, 1204, (.Push .PUSH1); attester_dj_step v, 1206, (.Push .PUSH1); attester_dj_step v, 1208, .SHL; attester_dj_step v, 1209, .SUB; attester_dj_step v, 1210, .AND; attester_dj_step v, 1211, .DUP2; attester_dj_step v, 1212, .MSTORE - attester_dj_step v, 1213, (.Push .PUSH1); attester_dj_step v, 1215, .ADD; attester_dj_step v, 1216, (.Push .PUSH0); attester_dj_step v, 1217, (.Push .PUSH1); attester_dj_step v, 1219, (.Push .PUSH1); attester_dj_step v, 1221, (.Push .PUSH1); attester_dj_step v, 1223, .SHL; attester_dj_step v, 1224, .SUB - attester_dj_step v, 1225, .AND; attester_dj_step v, 1226, .DUP2; attester_dj_step v, 1227, .MSTORE; attester_dj_step v, 1228, (.Push .PUSH1); attester_dj_step v, 1230, .ADD; attester_dj_step v, 1231, (.Push .PUSH1); attester_dj_step v, 1233, .ISZERO; attester_dj_step v, 1234, .ISZERO - attester_dj_step v, 1235, .DUP2; attester_dj_step v, 1236, .MSTORE; attester_dj_step v, 1237, (.Push .PUSH1); attester_dj_step v, 1239, .ADD; attester_dj_step v, 1240, (.Push .PUSH0); attester_dj_step v, 1241, .DUP1; attester_dj_step v, 1242, .SHL; attester_dj_step v, 1243, .DUP2 - attester_dj_step v, 1244, .MSTORE; attester_dj_step v, 1245, (.Push .PUSH1); attester_dj_step v, 1247, .ADD; attester_dj_step v, 1248, .DUP7; attester_dj_step v, 1249, .DUP7; attester_dj_step v, 1250, .DUP5; attester_dj_step v, 1251, .DUP2; attester_dj_step v, 1252, .DUP2 - attester_dj_step v, 1253, .LT; attester_dj_step v, 1254, (.Push .PUSH2); attester_dj_step v, 1257, .JUMPI; attester_dj_step v, 1258, (.Push .PUSH2); attester_dj_step v, 1261, (.Push .PUSH2); attester_dj_step v, 1264, .JUMP; attester_dj_step v, 1265, .JUMPDEST; attester_dj_step v, 1266, .SWAP1 - attester_dj_step v, 1267, .POP; attester_dj_step v, 1268, (.Push .PUSH1); attester_dj_step v, 1270, .MUL; attester_dj_step v, 1271, .ADD; attester_dj_step v, 1272, .CALLDATALOAD; attester_dj_step v, 1273, (.Push .PUSH1); attester_dj_step v, 1275, .MLOAD; attester_dj_step v, 1276, (.Push .PUSH1) - attester_dj_step v, 1278, .ADD; attester_dj_step v, 1279, (.Push .PUSH2); attester_dj_step v, 1282, .SWAP2; attester_dj_step v, 1283, .DUP2; attester_dj_step v, 1284, .MSTORE; attester_dj_step v, 1285, (.Push .PUSH1); attester_dj_step v, 1287, .ADD; attester_dj_step v, 1288, .SWAP1 - attester_dj_step v, 1289, .JUMP; attester_dj_step v, 1290, .JUMPDEST; attester_dj_step v, 1291, (.Push .PUSH1); attester_dj_step v, 1293, .MLOAD; attester_dj_step v, 1294, (.Push .PUSH1); attester_dj_step v, 1296, .DUP2; attester_dj_step v, 1297, .DUP4; attester_dj_step v, 1298, .SUB - attester_dj_step v, 1299, .SUB; attester_dj_step v, 1300, .DUP2; attester_dj_step v, 1301, .MSTORE; attester_dj_step v, 1302, .SWAP1; attester_dj_step v, 1303, (.Push .PUSH1); attester_dj_step v, 1305, .MSTORE; attester_dj_step v, 1306, .DUP2; attester_dj_step v, 1307, .MSTORE - attester_dj_step v, 1308, (.Push .PUSH1); attester_dj_step v, 1310, .ADD; attester_dj_step v, 1311, (.Push .PUSH0); attester_dj_step v, 1312, .DUP2; attester_dj_step v, 1313, .MSTORE; attester_dj_step v, 1314, .POP; attester_dj_step v, 1315, .DUP3; attester_dj_step v, 1316, .DUP3 - attester_dj_step v, 1317, .DUP2; attester_dj_step v, 1318, .MLOAD; attester_dj_step v, 1319, .DUP2; attester_dj_step v, 1320, .LT; attester_dj_step v, 1321, (.Push .PUSH2); attester_dj_step v, 1324, .JUMPI; attester_dj_step v, 1325, (.Push .PUSH2); attester_dj_step v, 1328, (.Push .PUSH2) - attester_dj_step v, 1331, .JUMP; attester_dj_step v, 1332, .JUMPDEST; attester_dj_step v, 1333, (.Push .PUSH1); attester_dj_step v, 1335, .SWAP1; attester_dj_step v, 1336, .DUP2; attester_dj_step v, 1337, .MUL; attester_dj_step v, 1338, .SWAP2; attester_dj_step v, 1339, .SWAP1 - attester_dj_step v, 1340, .SWAP2; attester_dj_step v, 1341, .ADD; attester_dj_step v, 1342, .ADD; attester_dj_step v, 1343, .MSTORE; attester_dj_step v, 1344, (.Push .PUSH1); attester_dj_step v, 1346, .ADD; attester_dj_step v, 1347, (.Push .PUSH2); attester_dj_step v, 1350, .JUMP - attester_dj_step v, 1351, .JUMPDEST; attester_dj_step v, 1352, .POP; attester_dj_step v, 1353, (.Push .PUSH1); attester_dj_step v, 1355, .MLOAD; attester_dj_step v, 1356, .DUP1; attester_dj_step v, 1357, (.Push .PUSH1); attester_dj_step v, 1359, .ADD; attester_dj_step v, 1360, (.Push .PUSH1) - attester_dj_step v, 1362, .MSTORE; attester_dj_step v, 1363, .DUP1; attester_dj_step v, 1364, .DUP14; attester_dj_step v, 1365, .DUP14; attester_dj_step v, 1366, .DUP9; attester_dj_step v, 1367, .DUP2; attester_dj_step v, 1368, .DUP2; attester_dj_step v, 1369, .LT - attester_dj_step v, 1370, (.Push .PUSH2); attester_dj_step v, 1373, .JUMPI; attester_dj_step v, 1374, (.Push .PUSH2); attester_dj_step v, 1377, (.Push .PUSH2); attester_dj_step v, 1380, .JUMP; attester_dj_step v, 1381, .JUMPDEST; attester_dj_step v, 1382, .SWAP1; attester_dj_step v, 1383, .POP - attester_dj_step v, 1384, (.Push .PUSH1); attester_dj_step v, 1386, .MUL; attester_dj_step v, 1387, .ADD; attester_dj_step v, 1388, .CALLDATALOAD; attester_dj_step v, 1389, .DUP2; attester_dj_step v, 1390, .MSTORE; attester_dj_step v, 1391, (.Push .PUSH1); attester_dj_step v, 1393, .ADD - attester_dj_step v, 1394, .DUP3; attester_dj_step v, 1395, .DUP2; attester_dj_step v, 1396, .MSTORE; attester_dj_step v, 1397, .POP; attester_dj_step v, 1398, .DUP7; attester_dj_step v, 1399, .DUP7; attester_dj_step v, 1400, .DUP2; attester_dj_step v, 1401, .MLOAD - attester_dj_step v, 1402, .DUP2; attester_dj_step v, 1403, .LT; attester_dj_step v, 1404, (.Push .PUSH2); attester_dj_step v, 1407, .JUMPI; attester_dj_step v, 1408, (.Push .PUSH2); attester_dj_step v, 1411, (.Push .PUSH2); attester_dj_step v, 1414, .JUMP; attester_dj_step v, 1415, .JUMPDEST - attester_dj_step v, 1416, (.Push .PUSH1); attester_dj_step v, 1418, .MUL; attester_dj_step v, 1419, (.Push .PUSH1); attester_dj_step v, 1421, .ADD; attester_dj_step v, 1422, .ADD; attester_dj_step v, 1423, .DUP2; attester_dj_step v, 1424, .SWAP1; attester_dj_step v, 1425, .MSTORE - attester_dj_step v, 1426, .POP; attester_dj_step v, 1427, .POP; attester_dj_step v, 1428, .POP; attester_dj_step v, 1429, .POP; attester_dj_step v, 1430, .POP; attester_dj_step v, 1431, .DUP1; attester_dj_step v, 1432, (.Push .PUSH1); attester_dj_step v, 1434, .ADD - attester_dj_step v, 1435, .SWAP1; attester_dj_step v, 1436, .POP; attester_dj_step v, 1437, (.Push .PUSH2); attester_dj_step v, 1440, .JUMP; attester_dj_step v, 1441, .JUMPDEST; attester_dj_step v, 1442, .POP; attester_dj_step v, 1443, (.Push .PUSH1); attester_dj_step v, 1445, .MLOAD - attester_dj_step v, 1446, (.Push .PUSH4); attester_dj_step v, 1451, (.Push .PUSH1); attester_dj_step v, 1453, .SHL; attester_dj_step v, 1454, .DUP2; attester_dj_step v, 1455, .MSTORE; attester_dj_step v, 1456, (.Push .PUSH1); attester_dj_step v, 1458, (.Push .PUSH1); attester_dj_step v, 1460, (.Push .PUSH1) - attester_dj_step v, 1462, .SHL; attester_dj_step v, 1463, .SUB; attester_dj_step v, 1464, (.Push .PUSH32); attester_dj_step v, 1497, .AND; attester_dj_step v, 1498, .SWAP1; attester_dj_step v, 1499, (.Push .PUSH4); attester_dj_step v, 1504, .SWAP1; attester_dj_step v, 1505, (.Push .PUSH2) - attester_dj_step v, 1508, .SWAP1; attester_dj_step v, 1509, .DUP5; attester_dj_step v, 1510, .SWAP1; attester_dj_step v, 1511, (.Push .PUSH1); attester_dj_step v, 1513, .ADD; attester_dj_step v, 1514, (.Push .PUSH2); attester_dj_step v, 1517, .JUMP; attester_dj_step v, 1518, .JUMPDEST - attester_dj_step v, 1519, (.Push .PUSH0); attester_dj_step v, 1520, (.Push .PUSH1); attester_dj_step v, 1522, .MLOAD; attester_dj_step v, 1523, .DUP1; attester_dj_step v, 1524, .DUP4; attester_dj_step v, 1525, .SUB; attester_dj_step v, 1526, .DUP2; attester_dj_step v, 1527, (.Push .PUSH0) - attester_dj_step v, 1528, .DUP8; attester_dj_step v, 1529, .GAS; attester_dj_step v, 1530, .CALL; attester_dj_step v, 1531, .ISZERO; attester_dj_step v, 1532, .DUP1; attester_dj_step v, 1533, .ISZERO; attester_dj_step v, 1534, (.Push .PUSH2); attester_dj_step v, 1537, .JUMPI - attester_dj_step v, 1538, .RETURNDATASIZE; attester_dj_step v, 1539, (.Push .PUSH0); attester_dj_step v, 1540, .DUP1; attester_dj_step v, 1541, .RETURNDATACOPY; attester_dj_step v, 1542, .RETURNDATASIZE; attester_dj_step v, 1543, (.Push .PUSH0); attester_dj_step v, 1544, .REVERT; attester_dj_step v, 1545, .JUMPDEST - attester_dj_step v, 1546, .POP; attester_dj_step v, 1547, .POP; attester_dj_step v, 1548, .POP; attester_dj_step v, 1549, .POP; attester_dj_step v, 1550, (.Push .PUSH1); attester_dj_step v, 1552, .MLOAD; attester_dj_step v, 1553, .RETURNDATASIZE; attester_dj_step v, 1554, (.Push .PUSH0) - attester_dj_step v, 1555, .DUP3; attester_dj_step v, 1556, .RETURNDATACOPY; attester_dj_step v, 1557, (.Push .PUSH1); attester_dj_step v, 1559, .RETURNDATASIZE; attester_dj_step v, 1560, .SWAP1; attester_dj_step v, 1561, .DUP2; attester_dj_step v, 1562, .ADD; attester_dj_step v, 1563, (.Push .PUSH1) - attester_dj_step v, 1565, .NOT; attester_dj_step v, 1566, .AND; attester_dj_step v, 1567, .DUP3; attester_dj_step v, 1568, .ADD; attester_dj_step v, 1569, (.Push .PUSH1); attester_dj_step v, 1571, .MSTORE; attester_dj_step v, 1572, (.Push .PUSH2); attester_dj_step v, 1575, .SWAP2 - attester_dj_step v, 1576, .SWAP1; attester_dj_step v, 1577, .DUP2; attester_dj_step v, 1578, .ADD; attester_dj_step v, 1579, .SWAP1; attester_dj_step v, 1580, (.Push .PUSH2); attester_dj_step v, 1583, .JUMP; attester_dj_step v, 1584, .JUMPDEST; attester_dj_step v, 1585, .SWAP8 - attester_dj_step v, 1586, .SWAP7; attester_dj_step v, 1587, .POP; attester_dj_step v, 1588, .POP; attester_dj_step v, 1589, .POP; attester_dj_step v, 1590, .POP; attester_dj_step v, 1591, .POP; attester_dj_step v, 1592, .POP; attester_dj_step v, 1593, .POP - attester_dj_step v, 1594, .JUMP; attester_dj_step v, 1595, .JUMPDEST; attester_dj_step v, 1596, (.Push .PUSH0); attester_dj_step v, 1597, (.Push .PUSH32); attester_dj_step v, 1630, (.Push .PUSH1); attester_dj_step v, 1632, (.Push .PUSH1); attester_dj_step v, 1634, (.Push .PUSH1); attester_dj_step v, 1636, .SHL - attester_dj_step v, 1637, .SUB; attester_dj_step v, 1638, .AND; attester_dj_step v, 1639, (.Push .PUSH4); attester_dj_step v, 1644, (.Push .PUSH1); attester_dj_step v, 1646, .MLOAD; attester_dj_step v, 1647, .DUP1; attester_dj_step v, 1648, (.Push .PUSH1); attester_dj_step v, 1650, .ADD - attester_dj_step v, 1651, (.Push .PUSH1); attester_dj_step v, 1653, .MSTORE; attester_dj_step v, 1654, .DUP1; attester_dj_step v, 1655, .DUP7; attester_dj_step v, 1656, .DUP2; attester_dj_step v, 1657, .MSTORE; attester_dj_step v, 1658, (.Push .PUSH1); attester_dj_step v, 1660, .ADD - attester_dj_step v, 1661, (.Push .PUSH1); attester_dj_step v, 1663, .MLOAD; attester_dj_step v, 1664, .DUP1; attester_dj_step v, 1665, (.Push .PUSH1); attester_dj_step v, 1667, .ADD; attester_dj_step v, 1668, (.Push .PUSH1); attester_dj_step v, 1670, .MSTORE; attester_dj_step v, 1671, .DUP1 - attester_dj_step v, 1672, (.Push .PUSH0); attester_dj_step v, 1673, (.Push .PUSH1); attester_dj_step v, 1675, (.Push .PUSH1); attester_dj_step v, 1677, (.Push .PUSH1); attester_dj_step v, 1679, .SHL; attester_dj_step v, 1680, .SUB; attester_dj_step v, 1681, .AND; attester_dj_step v, 1682, .DUP2 - attester_dj_step v, 1683, .MSTORE; attester_dj_step v, 1684, (.Push .PUSH1); attester_dj_step v, 1686, .ADD; attester_dj_step v, 1687, (.Push .PUSH0); attester_dj_step v, 1688, (.Push .PUSH1); attester_dj_step v, 1690, (.Push .PUSH1); attester_dj_step v, 1692, (.Push .PUSH1); attester_dj_step v, 1694, .SHL - attester_dj_step v, 1695, .SUB; attester_dj_step v, 1696, .AND; attester_dj_step v, 1697, .DUP2; attester_dj_step v, 1698, .MSTORE; attester_dj_step v, 1699, (.Push .PUSH1); attester_dj_step v, 1701, .ADD; attester_dj_step v, 1702, (.Push .PUSH1); attester_dj_step v, 1704, .ISZERO - attester_dj_step v, 1705, .ISZERO; attester_dj_step v, 1706, .DUP2; attester_dj_step v, 1707, .MSTORE; attester_dj_step v, 1708, (.Push .PUSH1); attester_dj_step v, 1710, .ADD; attester_dj_step v, 1711, (.Push .PUSH0); attester_dj_step v, 1712, .DUP1; attester_dj_step v, 1713, .SHL - attester_dj_step v, 1714, .DUP2; attester_dj_step v, 1715, .MSTORE; attester_dj_step v, 1716, (.Push .PUSH1); attester_dj_step v, 1718, .ADD; attester_dj_step v, 1719, .DUP8; attester_dj_step v, 1720, (.Push .PUSH1); attester_dj_step v, 1722, .MLOAD; attester_dj_step v, 1723, (.Push .PUSH1) - attester_dj_step v, 1725, .ADD; attester_dj_step v, 1726, (.Push .PUSH2); attester_dj_step v, 1729, .SWAP2; attester_dj_step v, 1730, .DUP2; attester_dj_step v, 1731, .MSTORE; attester_dj_step v, 1732, (.Push .PUSH1); attester_dj_step v, 1734, .ADD; attester_dj_step v, 1735, .SWAP1 - attester_dj_step v, 1736, .JUMP; attester_dj_step v, 1737, .JUMPDEST; attester_dj_step v, 1738, (.Push .PUSH1); attester_dj_step v, 1740, .MLOAD; attester_dj_step v, 1741, (.Push .PUSH1); attester_dj_step v, 1743, .DUP2; attester_dj_step v, 1744, .DUP4; attester_dj_step v, 1745, .SUB - attester_dj_step v, 1746, .SUB; attester_dj_step v, 1747, .DUP2; attester_dj_step v, 1748, .MSTORE; attester_dj_step v, 1749, .SWAP1; attester_dj_step v, 1750, (.Push .PUSH1); attester_dj_step v, 1752, .MSTORE; attester_dj_step v, 1753, .DUP2; attester_dj_step v, 1754, .MSTORE - attester_dj_step v, 1755, (.Push .PUSH1); attester_dj_step v, 1757, .ADD; attester_dj_step v, 1758, (.Push .PUSH0); attester_dj_step v, 1759, .DUP2; attester_dj_step v, 1760, .MSTORE; attester_dj_step v, 1761, .POP; attester_dj_step v, 1762, .DUP2; attester_dj_step v, 1763, .MSTORE - attester_dj_step v, 1764, .POP; attester_dj_step v, 1765, (.Push .PUSH1); attester_dj_step v, 1767, .MLOAD; attester_dj_step v, 1768, .DUP3; attester_dj_step v, 1769, (.Push .PUSH4); attester_dj_step v, 1774, .AND; attester_dj_step v, 1775, (.Push .PUSH1); attester_dj_step v, 1777, .SHL - attester_dj_step v, 1778, .DUP2; attester_dj_step v, 1779, .MSTORE; attester_dj_step v, 1780, (.Push .PUSH1); attester_dj_step v, 1782, .ADD; attester_dj_step v, 1783, (.Push .PUSH2); attester_dj_step v, 1786, .SWAP2; attester_dj_step v, 1787, .SWAP1; attester_dj_step v, 1788, (.Push .PUSH2) - attester_dj_step v, 1791, .JUMP; attester_dj_step v, 1792, .JUMPDEST; attester_dj_step v, 1793, (.Push .PUSH1); attester_dj_step v, 1795, (.Push .PUSH1); attester_dj_step v, 1797, .MLOAD; attester_dj_step v, 1798, .DUP1; attester_dj_step v, 1799, .DUP4; attester_dj_step v, 1800, .SUB - attester_dj_step v, 1801, .DUP2; attester_dj_step v, 1802, (.Push .PUSH0); attester_dj_step v, 1803, .DUP8; attester_dj_step v, 1804, .GAS; attester_dj_step v, 1805, .CALL; attester_dj_step v, 1806, .ISZERO; attester_dj_step v, 1807, .DUP1; attester_dj_step v, 1808, .ISZERO - attester_dj_step v, 1809, (.Push .PUSH2); attester_dj_step v, 1812, .JUMPI; attester_dj_step v, 1813, .RETURNDATASIZE; attester_dj_step v, 1814, (.Push .PUSH0); attester_dj_step v, 1815, .DUP1; attester_dj_step v, 1816, .RETURNDATACOPY; attester_dj_step v, 1817, .RETURNDATASIZE; attester_dj_step v, 1818, (.Push .PUSH0) - attester_dj_step v, 1819, .REVERT; attester_dj_step v, 1820, .JUMPDEST; attester_dj_step v, 1821, .POP; attester_dj_step v, 1822, .POP; attester_dj_step v, 1823, .POP; attester_dj_step v, 1824, .POP; attester_dj_step v, 1825, (.Push .PUSH1); attester_dj_step v, 1827, .MLOAD - attester_dj_step v, 1828, .RETURNDATASIZE; attester_dj_step v, 1829, (.Push .PUSH1); attester_dj_step v, 1831, .NOT; attester_dj_step v, 1832, (.Push .PUSH1); attester_dj_step v, 1834, .DUP3; attester_dj_step v, 1835, .ADD; attester_dj_step v, 1836, .AND; attester_dj_step v, 1837, .DUP3 - attester_dj_step v, 1838, .ADD; attester_dj_step v, 1839, .DUP1; attester_dj_step v, 1840, (.Push .PUSH1); attester_dj_step v, 1842, .MSTORE; attester_dj_step v, 1843, .POP; attester_dj_step v, 1844, .DUP2; attester_dj_step v, 1845, .ADD; attester_dj_step v, 1846, .SWAP1 - attester_dj_step v, 1847, (.Push .PUSH2); attester_dj_step v, 1850, .SWAP2; attester_dj_step v, 1851, .SWAP1; attester_dj_step v, 1852, (.Push .PUSH2); attester_dj_step v, 1855, .JUMP; attester_dj_step v, 1856, .JUMPDEST; attester_dj_step v, 1857, .SWAP4; attester_dj_step v, 1858, .SWAP3 - attester_dj_step v, 1859, .POP; attester_dj_step v, 1860, .POP; attester_dj_step v, 1861, .POP; attester_dj_step v, 1862, .JUMP; attester_dj_step v, 1863, .JUMPDEST; attester_dj_step v, 1864, (.Push .PUSH1); attester_dj_step v, 1866, .DUP1; attester_dj_step v, 1867, .MLOAD - attester_dj_step v, 1868, .DUP1; attester_dj_step v, 1869, .DUP3; attester_dj_step v, 1870, .ADD; attester_dj_step v, 1871, .DUP3; attester_dj_step v, 1872, .MSTORE; attester_dj_step v, 1873, .DUP4; attester_dj_step v, 1874, .DUP2; attester_dj_step v, 1875, .MSTORE - attester_dj_step v, 1876, .DUP2; attester_dj_step v, 1877, .MLOAD; attester_dj_step v, 1878, .DUP1; attester_dj_step v, 1879, .DUP4; attester_dj_step v, 1880, .ADD; attester_dj_step v, 1881, .DUP4; attester_dj_step v, 1882, .MSTORE; attester_dj_step v, 1883, .DUP4 - attester_dj_step v, 1884, .DUP2; attester_dj_step v, 1885, .MSTORE; attester_dj_step v, 1886, (.Push .PUSH0); attester_dj_step v, 1887, (.Push .PUSH1); attester_dj_step v, 1889, .DUP1; attester_dj_step v, 1890, .DUP4; attester_dj_step v, 1891, .ADD; attester_dj_step v, 1892, .SWAP2 - attester_dj_step v, 1893, .SWAP1; attester_dj_step v, 1894, .SWAP2; attester_dj_step v, 1895, .MSTORE; attester_dj_step v, 1896, .DUP1; attester_dj_step v, 1897, .DUP4; attester_dj_step v, 1898, .ADD; attester_dj_step v, 1899, .SWAP2; attester_dj_step v, 1900, .DUP3 - attester_dj_step v, 1901, .MSTORE; attester_dj_step v, 1902, .SWAP3; attester_dj_step v, 1903, .MLOAD; attester_dj_step v, 1904, (.Push .PUSH4); attester_dj_step v, 1909, (.Push .PUSH1); attester_dj_step v, 1911, .SHL; attester_dj_step v, 1912, .DUP2; attester_dj_step v, 1913, .MSTORE - attester_dj_step v, 1914, .SWAP2; attester_dj_step v, 1915, .MLOAD; attester_dj_step v, 1916, (.Push .PUSH1); attester_dj_step v, 1918, .DUP4; attester_dj_step v, 1919, .ADD; attester_dj_step v, 1920, .MSTORE; attester_dj_step v, 1921, .MLOAD; attester_dj_step v, 1922, .DUP1 - attester_dj_step v, 1923, .MLOAD; attester_dj_step v, 1924, (.Push .PUSH1); attester_dj_step v, 1926, .DUP4; attester_dj_step v, 1927, .ADD; attester_dj_step v, 1928, .MSTORE; attester_dj_step v, 1929, .SWAP1; attester_dj_step v, 1930, .SWAP2; attester_dj_step v, 1931, .ADD - attester_dj_step v, 1932, .MLOAD; attester_dj_step v, 1933, (.Push .PUSH1); attester_dj_step v, 1935, .DUP3; attester_dj_step v, 1936, .ADD; attester_dj_step v, 1937, .MSTORE; attester_dj_step v, 1938, (.Push .PUSH32); attester_dj_step v, 1971, (.Push .PUSH1); attester_dj_step v, 1973, (.Push .PUSH1) - attester_dj_step v, 1975, (.Push .PUSH1); attester_dj_step v, 1977, .SHL; attester_dj_step v, 1978, .SUB; attester_dj_step v, 1979, .AND; attester_dj_step v, 1980, .SWAP1; attester_dj_step v, 1981, (.Push .PUSH4); attester_dj_step v, 1986, .SWAP1; attester_dj_step v, 1987, (.Push .PUSH1) - attester_dj_step v, 1989, .ADD; attester_dj_step v, 1990, (.Push .PUSH0); attester_dj_step v, 1991, (.Push .PUSH1); attester_dj_step v, 1993, .MLOAD; attester_dj_step v, 1994, .DUP1; attester_dj_step v, 1995, .DUP4; attester_dj_step v, 1996, .SUB; attester_dj_step v, 1997, .DUP2 - attester_dj_step v, 1998, (.Push .PUSH0); attester_dj_step v, 1999, .DUP8; attester_dj_step v, 2000, .DUP1; attester_dj_step v, 2001, .EXTCODESIZE; attester_dj_step v, 2002, .ISZERO; attester_dj_step v, 2003, .DUP1; attester_dj_step v, 2004, .ISZERO; attester_dj_step v, 2005, (.Push .PUSH2) - attester_dj_step v, 2008, .JUMPI; attester_dj_step v, 2009, (.Push .PUSH0); attester_dj_step v, 2010, .DUP1; attester_dj_step v, 2011, .REVERT; attester_dj_step v, 2012, .JUMPDEST; attester_dj_step v, 2013, .POP; attester_dj_step v, 2014, .GAS; attester_dj_step v, 2015, .CALL - attester_dj_step v, 2016, .ISZERO; attester_dj_step v, 2017, .DUP1; attester_dj_step v, 2018, .ISZERO; attester_dj_step v, 2019, (.Push .PUSH2); attester_dj_step v, 2022, .JUMPI; attester_dj_step v, 2023, .RETURNDATASIZE; attester_dj_step v, 2024, (.Push .PUSH0); attester_dj_step v, 2025, .DUP1 - attester_dj_step v, 2026, .RETURNDATACOPY; attester_dj_step v, 2027, .RETURNDATASIZE; attester_dj_step v, 2028, (.Push .PUSH0); attester_dj_step v, 2029, .REVERT; attester_dj_step v, 2030, .JUMPDEST; attester_dj_step v, 2031, .POP; attester_dj_step v, 2032, .POP; attester_dj_step v, 2033, .POP - attester_dj_step v, 2034, .POP; attester_dj_step v, 2035, .POP; attester_dj_step v, 2036, .POP; attester_dj_step v, 2037, .JUMP; attester_dj_step v, 2038, .JUMPDEST; attester_dj_step v, 2039, (.Push .PUSH0); attester_dj_step v, 2040, .DUP1; attester_dj_step v, 2041, .DUP4 - attester_dj_step v, 2042, (.Push .PUSH1); attester_dj_step v, 2044, .DUP5; attester_dj_step v, 2045, .ADD; attester_dj_step v, 2046, .SLT; attester_dj_step v, 2047, (.Push .PUSH2); attester_dj_step v, 2050, .JUMPI; attester_dj_step v, 2051, (.Push .PUSH0); attester_dj_step v, 2052, .DUP1 - attester_dj_step v, 2053, .REVERT; attester_dj_step v, 2054, .JUMPDEST; attester_dj_step v, 2055, .POP; attester_dj_step v, 2056, .DUP2; attester_dj_step v, 2057, .CALLDATALOAD; attester_dj_step v, 2058, (.Push .PUSH1); attester_dj_step v, 2060, (.Push .PUSH1); attester_dj_step v, 2062, (.Push .PUSH1) - attester_dj_step v, 2064, .SHL; attester_dj_step v, 2065, .SUB; attester_dj_step v, 2066, .DUP2; attester_dj_step v, 2067, .GT; attester_dj_step v, 2068, .ISZERO; attester_dj_step v, 2069, (.Push .PUSH2); attester_dj_step v, 2072, .JUMPI; attester_dj_step v, 2073, (.Push .PUSH0) - attester_dj_step v, 2074, .DUP1; attester_dj_step v, 2075, .REVERT; attester_dj_step v, 2076, .JUMPDEST; attester_dj_step v, 2077, (.Push .PUSH1); attester_dj_step v, 2079, .DUP4; attester_dj_step v, 2080, .ADD; attester_dj_step v, 2081, .SWAP2; attester_dj_step v, 2082, .POP - attester_dj_step v, 2083, .DUP4; attester_dj_step v, 2084, (.Push .PUSH1); attester_dj_step v, 2086, .DUP3; attester_dj_step v, 2087, (.Push .PUSH1); attester_dj_step v, 2089, .SHL; attester_dj_step v, 2090, .DUP6; attester_dj_step v, 2091, .ADD; attester_dj_step v, 2092, .ADD - attester_dj_step v, 2093, .GT; attester_dj_step v, 2094, .ISZERO; attester_dj_step v, 2095, (.Push .PUSH2); attester_dj_step v, 2098, .JUMPI; attester_dj_step v, 2099, (.Push .PUSH0); attester_dj_step v, 2100, .DUP1; attester_dj_step v, 2101, .REVERT; attester_dj_step v, 2102, .JUMPDEST - attester_dj_step v, 2103, .SWAP3; attester_dj_step v, 2104, .POP; attester_dj_step v, 2105, .SWAP3; attester_dj_step v, 2106, .SWAP1; attester_dj_step v, 2107, .POP; attester_dj_step v, 2108, .JUMP; attester_dj_step v, 2109, .JUMPDEST; attester_dj_step v, 2110, (.Push .PUSH0) - attester_dj_step v, 2111, .DUP1; attester_dj_step v, 2112, (.Push .PUSH0); attester_dj_step v, 2113, .DUP1; attester_dj_step v, 2114, (.Push .PUSH1); attester_dj_step v, 2116, .DUP6; attester_dj_step v, 2117, .DUP8; attester_dj_step v, 2118, .SUB; attester_dj_step v, 2119, .SLT - attester_dj_step v, 2120, .ISZERO; attester_dj_step v, 2121, (.Push .PUSH2); attester_dj_step v, 2124, .JUMPI; attester_dj_step v, 2125, (.Push .PUSH0); attester_dj_step v, 2126, .DUP1; attester_dj_step v, 2127, .REVERT; attester_dj_step v, 2128, .JUMPDEST; attester_dj_step v, 2129, .DUP5 - attester_dj_step v, 2130, .CALLDATALOAD; attester_dj_step v, 2131, (.Push .PUSH1); attester_dj_step v, 2133, (.Push .PUSH1); attester_dj_step v, 2135, (.Push .PUSH1); attester_dj_step v, 2137, .SHL; attester_dj_step v, 2138, .SUB; attester_dj_step v, 2139, .DUP2; attester_dj_step v, 2140, .GT - attester_dj_step v, 2141, .ISZERO; attester_dj_step v, 2142, (.Push .PUSH2); attester_dj_step v, 2145, .JUMPI; attester_dj_step v, 2146, (.Push .PUSH0); attester_dj_step v, 2147, .DUP1; attester_dj_step v, 2148, .REVERT; attester_dj_step v, 2149, .JUMPDEST; attester_dj_step v, 2150, (.Push .PUSH2) - attester_dj_step v, 2153, .DUP8; attester_dj_step v, 2154, .DUP3; attester_dj_step v, 2155, .DUP9; attester_dj_step v, 2156, .ADD; attester_dj_step v, 2157, (.Push .PUSH2); attester_dj_step v, 2160, .JUMP; attester_dj_step v, 2161, .JUMPDEST; attester_dj_step v, 2162, .SWAP1 - attester_dj_step v, 2163, .SWAP6; attester_dj_step v, 2164, .POP; attester_dj_step v, 2165, .SWAP4; attester_dj_step v, 2166, .POP; attester_dj_step v, 2167, .POP; attester_dj_step v, 2168, (.Push .PUSH1); attester_dj_step v, 2170, .DUP6; attester_dj_step v, 2171, .ADD - attester_dj_step v, 2172, .CALLDATALOAD; attester_dj_step v, 2173, (.Push .PUSH1); attester_dj_step v, 2175, (.Push .PUSH1); attester_dj_step v, 2177, (.Push .PUSH1); attester_dj_step v, 2179, .SHL; attester_dj_step v, 2180, .SUB; attester_dj_step v, 2181, .DUP2; attester_dj_step v, 2182, .GT - attester_dj_step v, 2183, .ISZERO; attester_dj_step v, 2184, (.Push .PUSH2); attester_dj_step v, 2187, .JUMPI; attester_dj_step v, 2188, (.Push .PUSH0); attester_dj_step v, 2189, .DUP1; attester_dj_step v, 2190, .REVERT; attester_dj_step v, 2191, .JUMPDEST; attester_dj_step v, 2192, (.Push .PUSH2) - attester_dj_step v, 2195, .DUP8; attester_dj_step v, 2196, .DUP3; attester_dj_step v, 2197, .DUP9; attester_dj_step v, 2198, .ADD; attester_dj_step v, 2199, (.Push .PUSH2); attester_dj_step v, 2202, .JUMP; attester_dj_step v, 2203, .JUMPDEST; attester_dj_step v, 2204, .SWAP6 - attester_dj_step v, 2205, .SWAP9; attester_dj_step v, 2206, .SWAP5; attester_dj_step v, 2207, .SWAP8; attester_dj_step v, 2208, .POP; attester_dj_step v, 2209, .SWAP6; attester_dj_step v, 2210, .POP; attester_dj_step v, 2211, .POP; attester_dj_step v, 2212, .POP - attester_dj_step v, 2213, .POP; attester_dj_step v, 2214, .JUMP; attester_dj_step v, 2215, .JUMPDEST; attester_dj_step v, 2216, (.Push .PUSH1); attester_dj_step v, 2218, .DUP1; attester_dj_step v, 2219, .DUP3; attester_dj_step v, 2220, .MSTORE; attester_dj_step v, 2221, .DUP3 - attester_dj_step v, 2222, .MLOAD; attester_dj_step v, 2223, .DUP3; attester_dj_step v, 2224, .DUP3; attester_dj_step v, 2225, .ADD; attester_dj_step v, 2226, .DUP2; attester_dj_step v, 2227, .SWAP1; attester_dj_step v, 2228, .MSTORE; attester_dj_step v, 2229, (.Push .PUSH0) - attester_dj_step v, 2230, .SWAP2; attester_dj_step v, 2231, .DUP5; attester_dj_step v, 2232, .ADD; attester_dj_step v, 2233, .SWAP1; attester_dj_step v, 2234, (.Push .PUSH1); attester_dj_step v, 2236, .DUP5; attester_dj_step v, 2237, .ADD; attester_dj_step v, 2238, .SWAP1 - attester_dj_step v, 2239, .DUP4; attester_dj_step v, 2240, .JUMPDEST; attester_dj_step v, 2241, .DUP2; attester_dj_step v, 2242, .DUP2; attester_dj_step v, 2243, .LT; attester_dj_step v, 2244, .ISZERO; attester_dj_step v, 2245, (.Push .PUSH2); attester_dj_step v, 2248, .JUMPI - attester_dj_step v, 2249, .DUP4; attester_dj_step v, 2250, .MLOAD; attester_dj_step v, 2251, .DUP4; attester_dj_step v, 2252, .MSTORE; attester_dj_step v, 2253, (.Push .PUSH1); attester_dj_step v, 2255, .SWAP4; attester_dj_step v, 2256, .DUP5; attester_dj_step v, 2257, .ADD - attester_dj_step v, 2258, .SWAP4; attester_dj_step v, 2259, .SWAP1; attester_dj_step v, 2260, .SWAP3; attester_dj_step v, 2261, .ADD; attester_dj_step v, 2262, .SWAP2; attester_dj_step v, 2263, (.Push .PUSH1); attester_dj_step v, 2265, .ADD; attester_dj_step v, 2266, (.Push .PUSH2) - attester_dj_step v, 2269, .JUMP; attester_dj_step v, 2270, .JUMPDEST; attester_dj_step v, 2271, .POP; attester_dj_step v, 2272, .SWAP1; attester_dj_step v, 2273, .SWAP6; attester_dj_step v, 2274, .SWAP5; attester_dj_step v, 2275, .POP; attester_dj_step v, 2276, .POP - attester_dj_step v, 2277, .POP; attester_dj_step v, 2278, .POP; attester_dj_step v, 2279, .POP; attester_dj_step v, 2280, .JUMP; attester_dj_step v, 2281, .JUMPDEST; attester_dj_step v, 2282, (.Push .PUSH0); attester_dj_step v, 2283, .DUP1; attester_dj_step v, 2284, (.Push .PUSH1) - attester_dj_step v, 2286, .DUP4; attester_dj_step v, 2287, .DUP6; attester_dj_step v, 2288, .SUB; attester_dj_step v, 2289, .SLT; attester_dj_step v, 2290, .ISZERO; attester_dj_step v, 2291, (.Push .PUSH2); attester_dj_step v, 2294, .JUMPI; attester_dj_step v, 2295, (.Push .PUSH0) - attester_dj_step v, 2296, .DUP1; attester_dj_step v, 2297, .REVERT; attester_dj_step v, 2298, .JUMPDEST; attester_dj_step v, 2299, .POP; attester_dj_step v, 2300, .POP; attester_dj_step v, 2301, .DUP1; attester_dj_step v, 2302, .CALLDATALOAD; attester_dj_step v, 2303, .SWAP3 - attester_dj_step v, 2304, (.Push .PUSH1); attester_dj_step v, 2306, .SWAP1; attester_dj_step v, 2307, .SWAP2; attester_dj_step v, 2308, .ADD; attester_dj_step v, 2309, .CALLDATALOAD; attester_dj_step v, 2310, .SWAP2; attester_dj_step v, 2311, .POP; attester_dj_step v, 2312, .JUMP - attester_dj_step v, 2313, .JUMPDEST; attester_dj_step v, 2314, (.Push .PUSH4); attester_dj_step v, 2319, (.Push .PUSH1); attester_dj_step v, 2321, .SHL; attester_dj_step v, 2322, (.Push .PUSH0); attester_dj_step v, 2323, .MSTORE; attester_dj_step v, 2324, (.Push .PUSH1); attester_dj_step v, 2326, (.Push .PUSH1) - attester_dj_step v, 2328, .MSTORE; attester_dj_step v, 2329, (.Push .PUSH1); attester_dj_step v, 2331, (.Push .PUSH0); attester_dj_step v, 2332, .REVERT; attester_dj_step v, 2333, .JUMPDEST; attester_dj_step v, 2334, (.Push .PUSH4); attester_dj_step v, 2339, (.Push .PUSH1); attester_dj_step v, 2341, .SHL - attester_dj_step v, 2342, (.Push .PUSH0); attester_dj_step v, 2343, .MSTORE; attester_dj_step v, 2344, (.Push .PUSH1); attester_dj_step v, 2346, (.Push .PUSH1); attester_dj_step v, 2348, .MSTORE; attester_dj_step v, 2349, (.Push .PUSH1); attester_dj_step v, 2351, (.Push .PUSH0); attester_dj_step v, 2352, .REVERT - attester_dj_step v, 2353, .JUMPDEST; attester_dj_step v, 2354, (.Push .PUSH0); attester_dj_step v, 2355, .DUP1; attester_dj_step v, 2356, .DUP4; attester_dj_step v, 2357, .CALLDATALOAD; attester_dj_step v, 2358, (.Push .PUSH1); attester_dj_step v, 2360, .NOT; attester_dj_step v, 2361, .DUP5 - attester_dj_step v, 2362, .CALLDATASIZE; attester_dj_step v, 2363, .SUB; attester_dj_step v, 2364, .ADD; attester_dj_step v, 2365, .DUP2; attester_dj_step v, 2366, .SLT; attester_dj_step v, 2367, (.Push .PUSH2); attester_dj_step v, 2370, .JUMPI; attester_dj_step v, 2371, (.Push .PUSH0) - attester_dj_step v, 2372, .DUP1; attester_dj_step v, 2373, .REVERT; attester_dj_step v, 2374, .JUMPDEST; attester_dj_step v, 2375, .DUP4; attester_dj_step v, 2376, .ADD; attester_dj_step v, 2377, .DUP1; attester_dj_step v, 2378, .CALLDATALOAD; attester_dj_step v, 2379, .SWAP2 - attester_dj_step v, 2380, .POP; attester_dj_step v, 2381, (.Push .PUSH1); attester_dj_step v, 2383, (.Push .PUSH1); attester_dj_step v, 2385, (.Push .PUSH1); attester_dj_step v, 2387, .SHL; attester_dj_step v, 2388, .SUB; attester_dj_step v, 2389, .DUP3; attester_dj_step v, 2390, .GT - attester_dj_step v, 2391, .ISZERO; attester_dj_step v, 2392, (.Push .PUSH2); attester_dj_step v, 2395, .JUMPI; attester_dj_step v, 2396, (.Push .PUSH0); attester_dj_step v, 2397, .DUP1; attester_dj_step v, 2398, .REVERT; attester_dj_step v, 2399, .JUMPDEST - attester_dj_step v, 2400, (.Push .PUSH1); attester_dj_step v, 2402, .ADD; attester_dj_step v, 2403, .SWAP2; attester_dj_step v, 2404, .POP; attester_dj_step v, 2405, (.Push .PUSH1); attester_dj_step v, 2407, .DUP2; attester_dj_step v, 2408, .SWAP1; attester_dj_step v, 2409, .SHL - attester_dj_step v, 2410, .CALLDATASIZE; attester_dj_step v, 2411, .SUB; attester_dj_step v, 2412, .DUP3; attester_dj_step v, 2413, .SGT; attester_dj_step v, 2414, .ISZERO; attester_dj_step v, 2415, (.Push .PUSH2); attester_dj_step v, 2418, .JUMPI; attester_dj_step v, 2419, (.Push .PUSH0) - attester_dj_step v, 2420, .DUP1; attester_dj_step v, 2421, .REVERT; attester_dj_step v, 2422, .JUMPDEST - attester_dj_step v, 2423, (.Push .PUSH0); attester_dj_step v, 2424, (.Push .PUSH1); attester_dj_step v, 2426, .DUP3; attester_dj_step v, 2427, .ADD; attester_dj_step v, 2428, (.Push .PUSH1); attester_dj_step v, 2430, .DUP4; attester_dj_step v, 2431, .MSTORE; attester_dj_step v, 2432, .DUP1 - attester_dj_step v, 2433, .DUP5; attester_dj_step v, 2434, .MLOAD; attester_dj_step v, 2435, .DUP1; attester_dj_step v, 2436, .DUP4; attester_dj_step v, 2437, .MSTORE; attester_dj_step v, 2438, (.Push .PUSH1); attester_dj_step v, 2440, .DUP6; attester_dj_step v, 2441, .ADD - attester_dj_step v, 2442, .SWAP2; attester_dj_step v, 2443, .POP; attester_dj_step v, 2444, (.Push .PUSH1); attester_dj_step v, 2446, .DUP2; attester_dj_step v, 2447, (.Push .PUSH1); attester_dj_step v, 2449, .SHL; attester_dj_step v, 2450, .DUP7; attester_dj_step v, 2451, .ADD - attester_dj_step v, 2452, .ADD; attester_dj_step v, 2453, .SWAP3; attester_dj_step v, 2454, .POP; attester_dj_step v, 2455, (.Push .PUSH1); attester_dj_step v, 2457, .DUP7; attester_dj_step v, 2458, .ADD; attester_dj_step v, 2459, (.Push .PUSH0); attester_dj_step v, 2460, .JUMPDEST - attester_dj_step v, 2461, .DUP3; attester_dj_step v, 2462, .DUP2; attester_dj_step v, 2463, .LT; attester_dj_step v, 2464, .ISZERO; attester_dj_step v, 2465, (.Push .PUSH2); attester_dj_step v, 2468, .JUMPI; attester_dj_step v, 2469, .DUP7; attester_dj_step v, 2470, .DUP6 - attester_dj_step v, 2471, .SUB; attester_dj_step v, 2472, (.Push .PUSH1); attester_dj_step v, 2474, .NOT; attester_dj_step v, 2475, .ADD; attester_dj_step v, 2476, .DUP5; attester_dj_step v, 2477, .MSTORE; attester_dj_step v, 2478, .DUP2; attester_dj_step v, 2479, .MLOAD - attester_dj_step v, 2480, .DUP1; attester_dj_step v, 2481, .MLOAD; attester_dj_step v, 2482, .DUP7; attester_dj_step v, 2483, .MSTORE; attester_dj_step v, 2484, (.Push .PUSH1); attester_dj_step v, 2486, .SWAP1; attester_dj_step v, 2487, .DUP2; attester_dj_step v, 2488, .ADD - attester_dj_step v, 2489, .MLOAD; attester_dj_step v, 2490, (.Push .PUSH1); attester_dj_step v, 2492, .DUP3; attester_dj_step v, 2493, .DUP9; attester_dj_step v, 2494, .ADD; attester_dj_step v, 2495, .DUP2; attester_dj_step v, 2496, .SWAP1; attester_dj_step v, 2497, .MSTORE - attester_dj_step v, 2498, .DUP2; attester_dj_step v, 2499, .MLOAD; attester_dj_step v, 2500, .SWAP1; attester_dj_step v, 2501, .DUP9; attester_dj_step v, 2502, .ADD; attester_dj_step v, 2503, .DUP2; attester_dj_step v, 2504, .SWAP1; attester_dj_step v, 2505, .MSTORE - attester_dj_step v, 2506, .SWAP2; attester_dj_step v, 2507, .ADD; attester_dj_step v, 2508, .SWAP1; attester_dj_step v, 2509, (.Push .PUSH0); attester_dj_step v, 2510, .SWAP1; attester_dj_step v, 2511, (.Push .PUSH1); attester_dj_step v, 2513, .DUP9; attester_dj_step v, 2514, .ADD - attester_dj_step v, 2515, .SWAP1; attester_dj_step v, 2516, .JUMPDEST; attester_dj_step v, 2517, .DUP1; attester_dj_step v, 2518, .DUP4; attester_dj_step v, 2519, .LT; attester_dj_step v, 2520, .ISZERO; attester_dj_step v, 2521, (.Push .PUSH2); attester_dj_step v, 2524, .JUMPI - attester_dj_step v, 2525, (.Push .PUSH2); attester_dj_step v, 2528, .DUP3; attester_dj_step v, 2529, .DUP6; attester_dj_step v, 2530, .MLOAD; attester_dj_step v, 2531, .DUP1; attester_dj_step v, 2532, .MLOAD; attester_dj_step v, 2533, .DUP3; attester_dj_step v, 2534, .MSTORE - attester_dj_step v, 2535, (.Push .PUSH1); attester_dj_step v, 2537, .SWAP1; attester_dj_step v, 2538, .DUP2; attester_dj_step v, 2539, .ADD; attester_dj_step v, 2540, .MLOAD; attester_dj_step v, 2541, .SWAP2; attester_dj_step v, 2542, .ADD; attester_dj_step v, 2543, .MSTORE - attester_dj_step v, 2544, .JUMP; attester_dj_step v, 2545, .JUMPDEST; attester_dj_step v, 2546, (.Push .PUSH1); attester_dj_step v, 2548, .DUP3; attester_dj_step v, 2549, .ADD; attester_dj_step v, 2550, .SWAP2; attester_dj_step v, 2551, .POP; attester_dj_step v, 2552, (.Push .PUSH1) - attester_dj_step v, 2554, .DUP5; attester_dj_step v, 2555, .ADD; attester_dj_step v, 2556, .SWAP4; attester_dj_step v, 2557, .POP; attester_dj_step v, 2558, (.Push .PUSH1); attester_dj_step v, 2560, .DUP4; attester_dj_step v, 2561, .ADD; attester_dj_step v, 2562, .SWAP3 - attester_dj_step v, 2563, .POP; attester_dj_step v, 2564, (.Push .PUSH2); attester_dj_step v, 2567, .JUMP; attester_dj_step v, 2568, .JUMPDEST; attester_dj_step v, 2569, .POP; attester_dj_step v, 2570, .SWAP7; attester_dj_step v, 2571, .POP; attester_dj_step v, 2572, .POP - attester_dj_step v, 2573, .POP; attester_dj_step v, 2574, (.Push .PUSH1); attester_dj_step v, 2576, .SWAP4; attester_dj_step v, 2577, .DUP5; attester_dj_step v, 2578, .ADD; attester_dj_step v, 2579, .SWAP4; attester_dj_step v, 2580, .SWAP2; attester_dj_step v, 2581, .SWAP1 - attester_dj_step v, 2582, .SWAP2; attester_dj_step v, 2583, .ADD; attester_dj_step v, 2584, .SWAP1; attester_dj_step v, 2585, (.Push .PUSH1); attester_dj_step v, 2587, .ADD; attester_dj_step v, 2588, (.Push .PUSH2); attester_dj_step v, 2591, .JUMP; attester_dj_step v, 2592, .JUMPDEST - rw [Reasoning.Theory.D_J_aux_acc (patchedRuntime v) 2593] - repeat' constructor - all_goals - rw [Array.toList_append, List.mem_append] - apply Or.inl - native_decide - -theorem attesterMultiRevokeInnerArrayInitLoopJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨475⟩ : UInt256) = true := -by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h475 - -theorem attesterMultiAttestInnerArrayInitLoopJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨1113⟩ : UInt256) = true := -by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h1113 - -theorem attesterMultiRevokeInnerArrayCopyLoopJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨518⟩ : UInt256) = true := by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h518 - -theorem attesterMultiRevokeInnerArrayCopyElementOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨555⟩ : UInt256) = true := by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h555 - -theorem attesterMultiRevokeInnerArrayCopyStoreOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨589⟩ : UInt256) = true := by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h589 - -theorem attesterMultiRevokeInnerArrayCopyExitJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨608⟩ : UInt256) = true := by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h608 - -theorem attesterInnerArrayDecoderJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2353⟩ : UInt256) = true := -by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h2353 - -theorem attesterInnerArrayOffsetOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2374⟩ : UInt256) = true := -by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h2374 - -theorem attesterInnerArrayLengthOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2399⟩ : UInt256) = true := -by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h2399 - -theorem attesterMultiRevokeEncodeRequestsJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2422⟩ : UInt256) = true := -by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h2422 - -theorem attesterMultiRevokeInnerArrayReturnJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨381⟩ : UInt256) = true := -by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, - _h2422, h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h381 - -theorem attesterMultiRevokeInnerNonemptyOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨420⟩ : UInt256) = true := -by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h420 - -theorem attesterMultiRevokeInnerLengthMaxOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨445⟩ : UInt256) = true := -by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h445 - -theorem attesterMultiAttestInnerArrayReturnJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨1019⟩ : UInt256) = true := -by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h1019 - -theorem attesterMultiAttestInnerNonemptyOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨1058⟩ : UInt256) = true := -by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h1058 - -theorem attesterMultiAttestInnerLengthMaxOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨1083⟩ : UInt256) = true := -by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h1083 - -theorem attesterMultiRevokeExtcodesizeOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨798⟩ : UInt256) = true := by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h798 - -theorem attesterMultiRevokeCallOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨816⟩ : UInt256) = true := by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, h816, - _h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h816 - -theorem attesterMultiRevokeEncodeOuterLoopJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2460⟩ : UInt256) = true := by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - h2460, _h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h2460 - -theorem attesterMultiRevokeEncodeInnerLoopJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2516⟩ : UInt256) = true := by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, h2516, _h2545, _h2568, _h2592, _h775⟩ - exact h2516 - -theorem attesterMultiRevokeEncodeInnerReturnJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2545⟩ : UInt256) = true := by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, h2545, _h2568, _h2592, _h775⟩ - exact h2545 - -theorem attesterMultiRevokeEncodeInnerExitJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2568⟩ : UInt256) = true := by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, h2568, _h2592, _h775⟩ - exact h2568 - -theorem attesterMultiRevokeEncodeOuterExitJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨2592⟩ : UInt256) = true := by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, h2592, _h775⟩ - exact h2592 - -theorem attesterMultiRevokeEncoderReturnJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨775⟩ : UInt256) = true := by - rcases attesterInnerArrayDecoderJumpdests v with - ⟨_h475, _h1113, _h518, _h555, _h589, _h608, _h2353, _h2374, _h2399, _h2422, - _h381, _h420, _h445, _h1019, _h1058, _h1083, _h798, _h816, - _h2460, _h2516, _h2545, _h2568, _h2592, h775⟩ - exact h775 - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/InnerArrayCopy.lean b/Benchmarks/EAS/Attester/InnerArrayCopy.lean deleted file mode 100644 index c31d408f..00000000 --- a/Benchmarks/EAS/Attester/InnerArrayCopy.lean +++ /dev/null @@ -1,1927 +0,0 @@ -import Benchmarks.EAS.Attester.InnerArrayInit - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -theorem attesterMloadWord_of_readWithPadding - {mem : ByteArray} {aw base len : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (haw : ¬ base ≥ aw * ⟨32⟩) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) : - attesterMloadWord mem aw base = len := by - unfold attesterMloadWord - rw [if_neg (not_or.mpr ⟨by omega, haw⟩), hread, - fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - -theorem attesterMloadWord_writeWord_preserved - {mem : ByteArray} {aw base len writeOff writeVal : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (haw : ¬ base ≥ aw * ⟨32⟩) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (hgap : writeOff.toNat - mem.size < USize.size) - (hdisj : - (base.toNat + 32 ≤ writeOff.toNat ∧ base.toNat + 32 ≤ mem.size) ∨ - (writeOff.toNat + 32 ≤ base.toNat ∧ base.toNat + 32 ≤ mem.size)) : - attesterMloadWord - ((UInt256.toByteArray writeVal).write 0 mem writeOff.toNat 32) - aw base = len := by - apply attesterMloadWord_of_readWithPadding - · have hsize := writeWord_size mem writeOff.toNat writeVal hgap - unfold Reasoning.Theory.writeWord at hsize - rw [hsize] - omega - · exact haw - · change (Reasoning.Theory.writeWord mem writeOff.toNat writeVal).readWithPadding base.toNat 32 = - UInt256.toByteArray len - rw [writeWord_read_preserved_len mem writeOff.toNat base.toNat 32 writeVal - hgap hdisj (by norm_num) (by norm_num), hread] - -theorem attesterReadWithPadding_writeWord_preserved_above - {mem : ByteArray} {base writeOff : Nat} {len writeVal : UInt256} - (hmem : base + 32 ≤ mem.size) - (hgap : writeOff - mem.size < USize.size) - (habove : base + 32 ≤ writeOff) - (hread : mem.readWithPadding base 32 = UInt256.toByteArray len) : - (Reasoning.Theory.writeWord mem writeOff writeVal).readWithPadding base 32 = - UInt256.toByteArray len := by - rw [writeWord_read_preserved_len mem writeOff base 32 writeVal hgap - (Or.inl ⟨habove, hmem⟩) (by norm_num) (by norm_num), hread] - -theorem attesterReadWithPadding_writeWord_preserved_below - {mem : ByteArray} {base writeOff : Nat} {len writeVal : UInt256} - (hmem : base + 32 ≤ mem.size) - (hgap : writeOff - mem.size < USize.size) - (hbelow : writeOff + 32 ≤ base) - (hread : mem.readWithPadding base 32 = UInt256.toByteArray len) : - (Reasoning.Theory.writeWord mem writeOff writeVal).readWithPadding base 32 = - UInt256.toByteArray len := by - rw [writeWord_read_preserved_len mem writeOff base 32 writeVal hgap - (Or.inr ⟨hbelow, hmem⟩) (by norm_num) (by norm_num), hread] - -theorem attesterMultiOuterArrayLenMem_size (I : ExecutionEnv) : - (attesterMultiOuterArrayLenMem I).size = 160 := by - unfold attesterMultiOuterArrayLenMem - rw [toByteArray_write_eq _ _ _ (by rw [solcFreePtrMem_size]; omega) - (by rw [solcFreePtrMem_size]; exact lt_usize _ (by norm_num))] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray_zeroes_size, - toByteArray_size, solcFreePtrMem_size] - -theorem attesterMultiOuterArrayAllocMem_size (I : ExecutionEnv) : - (attesterMultiOuterArrayAllocMem I).size = 160 := by - unfold attesterMultiOuterArrayAllocMem - change (Reasoning.Theory.writeWord (attesterMultiOuterArrayLenMem I) 64 - (attesterMultiOuterArrayAllocEndWord I)).size = 160 - rw [writeWord_size_of_inside _ _ _ - (by rw [attesterMultiOuterArrayLenMem_size I]; omega), - attesterMultiOuterArrayLenMem_size] - -theorem attesterMultiOuterArrayAllocMem_read64 (I : ExecutionEnv) : - (attesterMultiOuterArrayAllocMem I).readWithPadding 64 32 = - UInt256.toByteArray (attesterMultiOuterArrayAllocEndWord I) := by - unfold attesterMultiOuterArrayAllocMem - change (Reasoning.Theory.writeWord (attesterMultiOuterArrayLenMem I) 64 - (attesterMultiOuterArrayAllocEndWord I)).readWithPadding 64 32 = - UInt256.toByteArray (attesterMultiOuterArrayAllocEndWord I) - exact toByteArray_write_read_back_of_gap - (attesterMultiOuterArrayAllocEndWord I) (attesterMultiOuterArrayLenMem I) 64 - (by - rw [attesterMultiOuterArrayLenMem_size I] - exact lt_usize 0 (by norm_num)) - -theorem attesterMultiOuterArrayAllocMem_mload64 (I : ExecutionEnv) : - attesterMloadWord (attesterMultiOuterArrayAllocMem I) (UInt256.ofNat 5) ⟨64⟩ = - attesterMultiOuterArrayAllocEndWord I := by - unfold attesterMloadWord - rw [if_neg] - · rw [show (⟨64⟩ : UInt256).toNat = 64 by decide] - rw [attesterMultiOuterArrayAllocMem_read64 I, fromByteArrayBigEndian_toByteArray, - u256_ofNat_toNat] - · rw [not_or] - constructor - · rw [attesterMultiOuterArrayAllocMem_size I] - decide - · decide - -theorem attesterInnerArrayAllocMem_readWithPadding_len - {len : UInt256} {mem : ByteArray} {aw : UInt256} - (hgapLen : - (attesterInnerArrayAllocFreeWord mem aw).toNat - mem.size < USize.size) - (hgapFree : - 64 - (attesterInnerArrayAllocLenMem len mem aw).size < USize.size) - (h64 : 64 + 32 ≤ (attesterInnerArrayAllocFreeWord mem aw).toNat) : - (attesterInnerArrayAllocMem len mem aw).readWithPadding - (attesterInnerArrayAllocFreeWord mem aw).toNat 32 = - UInt256.toByteArray len := by - let base := attesterInnerArrayAllocFreeWord mem aw - have hreadLen : - (attesterInnerArrayAllocLenMem len mem aw).readWithPadding base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord mem base.toNat len).readWithPadding - base.toNat 32 = UInt256.toByteArray len - exact toByteArray_write_read_back_of_gap len mem base.toNat hgapLen - have hmemLen : - base.toNat + 32 ≤ (attesterInnerArrayAllocLenMem len mem aw).size := by - have hsize := writeWord_size mem base.toNat len hgapLen - unfold Reasoning.Theory.writeWord at hsize - rw [hsize] - omega - change (Reasoning.Theory.writeWord - (attesterInnerArrayAllocLenMem len mem aw) 64 - (attesterInnerArrayAllocEndWord len mem aw)).readWithPadding - base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_below - (mem := attesterInnerArrayAllocLenMem len mem aw) - (base := base.toNat) (writeOff := 64) (len := len) - (writeVal := attesterInnerArrayAllocEndWord len mem aw) - hmemLen hgapFree h64 hreadLen - -theorem attesterInnerArrayAllocMem_mloadLen - {len : UInt256} {mem : ByteArray} {aw : UInt256} - (hgapLen : - (attesterInnerArrayAllocFreeWord mem aw).toNat - mem.size < USize.size) - (hgapFree : - 64 - (attesterInnerArrayAllocLenMem len mem aw).size < USize.size) - (h64 : 64 + 32 ≤ (attesterInnerArrayAllocFreeWord mem aw).toNat) - (haw : - ¬ attesterInnerArrayAllocFreeWord mem aw ≥ - attesterInnerArrayAllocAw len mem aw * (⟨32⟩ : UInt256)) : - attesterMloadWord - (attesterInnerArrayAllocMem len mem aw) - (attesterInnerArrayAllocAw len mem aw) - (attesterInnerArrayAllocFreeWord mem aw) = len := by - let base := attesterInnerArrayAllocFreeWord mem aw - have hread := - attesterInnerArrayAllocMem_readWithPadding_len - (len := len) (mem := mem) (aw := aw) hgapLen hgapFree h64 - have hmem : - base.toNat + 32 ≤ (attesterInnerArrayAllocMem len mem aw).size := by - have hsize1 := writeWord_size mem base.toNat len hgapLen - have hsize2 := writeWord_size (attesterInnerArrayAllocLenMem len mem aw) - 64 (attesterInnerArrayAllocEndWord len mem aw) hgapFree - unfold Reasoning.Theory.writeWord at hsize1 hsize2 - rw [hsize2, hsize1] - omega - exact attesterMloadWord_of_readWithPadding hmem haw (by simpa [base] using hread) - -theorem attesterMultiRevokeInnerArrayInitStep_readWithPadding_preserved - {base slot len : UInt256} {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (hgap64 : 64 - mem.size < USize.size) - (hgapFree : - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - - (attesterMultiOuterArrayInitFreeMem mem aw).size < USize.size) - (hgapSecond : - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - - (attesterMultiOuterArrayInitZeroMem mem aw).size < USize.size) - (hgapSlot : - slot.toNat - - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw).size < USize.size) - (h64 : 64 + 32 ≤ base.toNat) - (hfree : - base.toNat + 32 ≤ (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (hsecond : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat) - (hslot : base.toNat + 32 ≤ slot.toNat) : - (attesterMultiRevokeInnerArrayInitStepMem slot mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - have hread1 : - (attesterMultiOuterArrayInitFreeMem mem aw).readWithPadding base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)).readWithPadding - base.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_below - (mem := mem) (base := base.toNat) (writeOff := 64) - (len := len) - (writeVal := - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)) - hmem hgap64 h64 hread - have hmem1 : - base.toNat + 32 ≤ (attesterMultiOuterArrayInitFreeMem mem aw).size := by - have hsize := writeWord_size mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) hgap64 - unfold Reasoning.Theory.writeWord at hsize - rw [hsize] - omega - have hread2 : - (attesterMultiOuterArrayInitZeroMem mem aw).readWithPadding base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256)).readWithPadding base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above - (mem := attesterMultiOuterArrayInitFreeMem mem aw) - (base := base.toNat) - (writeOff := (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (len := len) (writeVal := (⟨0⟩ : UInt256)) - hmem1 hgapFree hfree hread1 - have hmem2 : - base.toNat + 32 ≤ (attesterMultiOuterArrayInitZeroMem mem aw).size := by - have hsize := writeWord_size - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256) hgapFree - unfold Reasoning.Theory.writeWord at hsize - rw [hsize] - omega - have hread3 : - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).readWithPadding base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above - (mem := attesterMultiOuterArrayInitZeroMem mem aw) - (base := base.toNat) - (writeOff := (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat) - (len := len) (writeVal := (⟨0⟩ : UInt256)) - hmem2 hgapSecond hsecond hread2 - have hmem3 : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw).size := by - have hsize := writeWord_size - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - (⟨0⟩ : UInt256) hgapSecond - unfold Reasoning.Theory.writeWord at hsize - rw [hsize] - omega - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw) - slot.toNat (attesterMultiOuterArrayInitFreeWord mem aw)).readWithPadding - base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above - (mem := attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw) - (base := base.toNat) (writeOff := slot.toNat) (len := len) - (writeVal := attesterMultiOuterArrayInitFreeWord mem aw) - hmem3 hgapSlot hslot hread3 - -theorem attesterMultiRevokeInnerArrayInitStep_mloadLen_of_readWithPadding - {base slot len : UInt256} {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (haw : - ¬ base ≥ - attesterMultiRevokeInnerArrayInitStepAw slot mem aw * (⟨32⟩ : UInt256)) - (hgap64 : 64 - mem.size < USize.size) - (hgapFree : - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - - (attesterMultiOuterArrayInitFreeMem mem aw).size < USize.size) - (hgapSecond : - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - - (attesterMultiOuterArrayInitZeroMem mem aw).size < USize.size) - (hgapSlot : - slot.toNat - - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw).size < USize.size) - (h64 : 64 + 32 ≤ base.toNat) - (hfree : - base.toNat + 32 ≤ (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (hsecond : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat) - (hslot : base.toNat + 32 ≤ slot.toNat) : - attesterMloadWord - (attesterMultiRevokeInnerArrayInitStepMem slot mem aw) - (attesterMultiRevokeInnerArrayInitStepAw slot mem aw) - base = len := by - have hreadStep := - attesterMultiRevokeInnerArrayInitStep_readWithPadding_preserved - (base := base) (slot := slot) (len := len) (mem := mem) (aw := aw) - hmem hread hgap64 hgapFree hgapSecond hgapSlot h64 hfree hsecond hslot - have hmemStep : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem slot mem aw).size := by - have hsize1 := writeWord_size mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) hgap64 - have hsize2 := writeWord_size - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256) hgapFree - have hsize3 := writeWord_size - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - (⟨0⟩ : UInt256) hgapSecond - have hsize4 := writeWord_size - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw) - slot.toNat (attesterMultiOuterArrayInitFreeWord mem aw) hgapSlot - unfold Reasoning.Theory.writeWord at hsize1 hsize2 hsize3 hsize4 - rw [hsize4, hsize3, hsize2, hsize1] - omega - exact attesterMloadWord_of_readWithPadding hmemStep haw hreadStep - -theorem attesterX_multiRevokeOuterArrayInitLoopWithStateInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (Inv : Nat → AttesterMultiOuterArrayInitState → Prop) - (hremaining : - ∀ n a, Inv n a → a.remaining = UInt256.ofNat (n + 1)) - (hbound : - ∀ n a, Inv n a → n + 1 < UInt256.size) - (hstep : - ∀ n a, Inv (n + 1) a → Inv n (attesterMultiOuterArrayInitStepState a)) - (hinit : - Inv (len.toNat - 1) - { slot := slot, remaining := len, mem := mem, aw := aw }) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨291⟩ : UInt256) - [slot, len, base, ⟨0⟩, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ a' k' C', - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv 0 a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterArrayInitExitStack I base len a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k' C' := by - let stk := attesterMultiRevokeOuterArrayInitStack I base len - let memOf : AttesterMultiOuterArrayInitState → ByteArray := fun a => a.mem - let awOf : AttesterMultiOuterArrayInitState → UInt256 := fun a => a.aw - let exitStk := attesterMultiRevokeOuterArrayInitExitStack I base len - let exitMem := attesterMultiOuterArrayInitFinalMem - let exitAw := attesterMultiOuterArrayInitFinalAw - have hexit : - ∀ a, Inv 0 a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨291⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨335⟩ : UInt256) (exitStk a) (exitMem a) (exitAw a) - ByteArray.empty (cA, σ) k' C' := by - intro a hInv k C rd - have hrem : a.remaining = (⟨1⟩ : UInt256) := by - simpa using hremaining 0 a hInv - exact attesterX_multiRevokeOuterArrayInitFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (mem := a.mem) (aw := a.aw) - (by - simpa [stk, memOf, awOf, hrem, attesterMultiRevokeOuterArrayInitStack] - using rd) - have hbody : - ∀ n a, Inv (n + 1) a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨291⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ a' k' C', - Inv n a' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨291⟩ : UInt256) (stk a') (memOf a') (awOf a') - ByteArray.empty (cA, σ) k' C' := by - intro n a hInv k C rd - let a' := attesterMultiOuterArrayInitStepState a - have hsub : - UInt256.sub a.remaining (⟨1⟩ : UInt256) = UInt256.ofNat (n + 1) := by - rw [hremaining (n + 1) a hInv] - simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using - attester_u256_ofNat_succ_sub_one (n := n + 1) - (hbound (n + 1) a hInv) - have hnext : UInt256.sub a.remaining (⟨1⟩ : UInt256) ≠ ⟨0⟩ := by - rw [hsub] - exact attester_u256_ofNat_pos_ne_zero - (n := n + 1) (by omega) (by - have := hbound (n + 1) a hInv - omega) - obtain ⟨k', C', rd'⟩ := - attesterX_multiRevokeOuterArrayInitNonFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (remaining := a.remaining) (mem := a.mem) (aw := a.aw) hnext - (by - simpa [stk, memOf, awOf, attesterMultiRevokeOuterArrayInitStack] - using rd) - refine ⟨a', k', C', hstep n a hInv, ?_⟩ - simpa [a', stk, memOf, awOf, attesterMultiRevokeOuterArrayInitStack, - attesterMultiOuterArrayInitStepState] using rd' - let a0 : AttesterMultiOuterArrayInitState := - { slot := slot, remaining := len, mem := mem, aw := aw } - obtain ⟨a', k', C', hInvFinal, rdFinal⟩ := - RD.whileLoopCarryExit - (code := patchedRuntime v) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) - (rdata := ByteArray.empty) (acc := (cA, σ)) - (header := (⟨291⟩ : UInt256)) (exit := (⟨335⟩ : UInt256)) - Inv stk memOf awOf exitStk exitMem exitAw hexit hbody - (len.toNat - 1) a0 (by simpa [a0] using hinit) k C - (by - simpa [a0, stk, memOf, awOf, attesterMultiRevokeOuterArrayInitStack] - using hreach) - exact ⟨a', k', C', by simpa using hremaining 0 a' hInvFinal, - hInvFinal, rdFinal⟩ - -theorem attesterX_multiAttestOuterArrayInitLoopWithStateInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (Inv : Nat → AttesterMultiOuterArrayInitState → Prop) - (hremaining : - ∀ n a, Inv n a → a.remaining = UInt256.ofNat (n + 1)) - (hbound : - ∀ n a, Inv n a → n + 1 < UInt256.size) - (hstep : - ∀ n a, Inv (n + 1) a → Inv n (attesterMultiOuterArrayInitStepState a)) - (hinit : - Inv (len.toNat - 1) - { slot := slot, remaining := len, mem := mem, aw := aw }) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨929⟩ : UInt256) - [slot, len, base, ⟨0⟩, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ a' k' C', - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv 0 a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨973⟩ : UInt256) - (attesterMultiAttestOuterArrayInitExitStack I base len a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k' C' := by - let stk := attesterMultiAttestOuterArrayInitStack I base len - let memOf : AttesterMultiOuterArrayInitState → ByteArray := fun a => a.mem - let awOf : AttesterMultiOuterArrayInitState → UInt256 := fun a => a.aw - let exitStk := attesterMultiAttestOuterArrayInitExitStack I base len - let exitMem := attesterMultiOuterArrayInitFinalMem - let exitAw := attesterMultiOuterArrayInitFinalAw - have hexit : - ∀ a, Inv 0 a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨929⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨973⟩ : UInt256) (exitStk a) (exitMem a) (exitAw a) - ByteArray.empty (cA, σ) k' C' := by - intro a hInv k C rd - have hrem : a.remaining = (⟨1⟩ : UInt256) := by - simpa using hremaining 0 a hInv - exact attesterX_multiAttestOuterArrayInitFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (mem := a.mem) (aw := a.aw) - (by - simpa [stk, memOf, awOf, hrem, attesterMultiAttestOuterArrayInitStack] - using rd) - have hbody : - ∀ n a, Inv (n + 1) a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨929⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ a' k' C', - Inv n a' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨929⟩ : UInt256) (stk a') (memOf a') (awOf a') - ByteArray.empty (cA, σ) k' C' := by - intro n a hInv k C rd - let a' := attesterMultiOuterArrayInitStepState a - have hsub : - UInt256.sub a.remaining (⟨1⟩ : UInt256) = UInt256.ofNat (n + 1) := by - rw [hremaining (n + 1) a hInv] - simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using - attester_u256_ofNat_succ_sub_one (n := n + 1) - (hbound (n + 1) a hInv) - have hnext : UInt256.sub a.remaining (⟨1⟩ : UInt256) ≠ ⟨0⟩ := by - rw [hsub] - exact attester_u256_ofNat_pos_ne_zero - (n := n + 1) (by omega) (by - have := hbound (n + 1) a hInv - omega) - obtain ⟨k', C', rd'⟩ := - attesterX_multiAttestOuterArrayInitNonFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (remaining := a.remaining) (mem := a.mem) (aw := a.aw) hnext - (by - simpa [stk, memOf, awOf, attesterMultiAttestOuterArrayInitStack] - using rd) - refine ⟨a', k', C', hstep n a hInv, ?_⟩ - simpa [a', stk, memOf, awOf, attesterMultiAttestOuterArrayInitStack, - attesterMultiOuterArrayInitStepState] using rd' - let a0 : AttesterMultiOuterArrayInitState := - { slot := slot, remaining := len, mem := mem, aw := aw } - obtain ⟨a', k', C', hInvFinal, rdFinal⟩ := - RD.whileLoopCarryExit - (code := patchedRuntime v) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) - (rdata := ByteArray.empty) (acc := (cA, σ)) - (header := (⟨929⟩ : UInt256)) (exit := (⟨973⟩ : UInt256)) - Inv stk memOf awOf exitStk exitMem exitAw hexit hbody - (len.toNat - 1) a0 (by simpa [a0] using hinit) k C - (by - simpa [a0, stk, memOf, awOf, attesterMultiAttestOuterArrayInitStack] - using hreach) - exact ⟨a', k', C', by simpa using hremaining 0 a' hInvFinal, - hInvFinal, rdFinal⟩ - -theorem attesterX_multiRevokeInnerArrayInitLoopWithStateInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len payload : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (Inv : Nat → AttesterMultiRevokeInnerArrayInitState → Prop) - (hremaining : - ∀ n a, Inv n a → a.remaining = UInt256.ofNat (n + 1)) - (hbound : - ∀ n a, Inv n a → n + 1 < UInt256.size) - (hstep : - ∀ n a, Inv (n + 1) a → Inv n (attesterMultiRevokeInnerArrayInitStepState a)) - (hinit : - Inv (len.toNat - 1) - { slot := slot, remaining := len, mem := mem, aw := aw }) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - [slot, len, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ a' k' C', - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv 0 a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (attesterMultiRevokeInnerArrayInitExitStack I base len payload a') - (attesterMultiRevokeInnerArrayInitFinalMem a') - (attesterMultiRevokeInnerArrayInitFinalAw a') - ByteArray.empty (cA, σ) k' C' := by - let stk := attesterMultiRevokeInnerArrayInitStack I base len payload - let memOf : AttesterMultiRevokeInnerArrayInitState → ByteArray := fun a => a.mem - let awOf : AttesterMultiRevokeInnerArrayInitState → UInt256 := fun a => a.aw - let exitStk := attesterMultiRevokeInnerArrayInitExitStack I base len payload - let exitMem := attesterMultiRevokeInnerArrayInitFinalMem - let exitAw := attesterMultiRevokeInnerArrayInitFinalAw - have hexit : - ∀ a, Inv 0 a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨475⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨518⟩ : UInt256) (exitStk a) (exitMem a) (exitAw a) - ByteArray.empty (cA, σ) k' C' := by - intro a hInv k C rd - have hrem : a.remaining = (⟨1⟩ : UInt256) := by - simpa using hremaining 0 a hInv - exact attesterX_multiRevokeInnerArrayInitFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (payload := payload) (mem := a.mem) (aw := a.aw) - (by - simpa [stk, memOf, awOf, hrem, attesterMultiRevokeInnerArrayInitStack] - using rd) - have hbody : - ∀ n a, Inv (n + 1) a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨475⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ a' k' C', - Inv n a' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨475⟩ : UInt256) (stk a') (memOf a') (awOf a') - ByteArray.empty (cA, σ) k' C' := by - intro n a hInv k C rd - let a' := attesterMultiRevokeInnerArrayInitStepState a - have hsub : - UInt256.sub a.remaining (⟨1⟩ : UInt256) = UInt256.ofNat (n + 1) := by - rw [hremaining (n + 1) a hInv] - simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using - attester_u256_ofNat_succ_sub_one (n := n + 1) - (hbound (n + 1) a hInv) - have hnext : UInt256.sub a.remaining (⟨1⟩ : UInt256) ≠ ⟨0⟩ := by - rw [hsub] - exact attester_u256_ofNat_pos_ne_zero - (n := n + 1) (by omega) (by - have := hbound (n + 1) a hInv - omega) - obtain ⟨k', C', rd'⟩ := - attesterX_multiRevokeInnerArrayInitNonFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (payload := payload) (remaining := a.remaining) (mem := a.mem) - (aw := a.aw) hnext - (by - simpa [stk, memOf, awOf, attesterMultiRevokeInnerArrayInitStack] - using rd) - refine ⟨a', k', C', hstep n a hInv, ?_⟩ - simpa [a', stk, memOf, awOf, attesterMultiRevokeInnerArrayInitStack, - attesterMultiRevokeInnerArrayInitStepState] using rd' - let a0 : AttesterMultiRevokeInnerArrayInitState := - { slot := slot, remaining := len, mem := mem, aw := aw } - obtain ⟨a', k', C', hInvFinal, rdFinal⟩ := - RD.whileLoopCarryExit - (code := patchedRuntime v) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) - (rdata := ByteArray.empty) (acc := (cA, σ)) - (header := (⟨475⟩ : UInt256)) (exit := (⟨518⟩ : UInt256)) - Inv stk memOf awOf exitStk exitMem exitAw hexit hbody - (len.toNat - 1) a0 (by simpa [a0] using hinit) k C - (by - simpa [a0, stk, memOf, awOf, attesterMultiRevokeInnerArrayInitStack] - using hreach) - exact ⟨a', k', C', by simpa using hremaining 0 a' hInvFinal, - hInvFinal, rdFinal⟩ - -theorem attesterX_multiAttestInnerArrayInitLoopWithStateInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len payload : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (Inv : Nat → AttesterMultiAttestInnerArrayInitState → Prop) - (hremaining : - ∀ n a, Inv n a → a.remaining = UInt256.ofNat (n + 1)) - (hbound : - ∀ n a, Inv n a → n + 1 < UInt256.size) - (hstep : - ∀ n a, Inv (n + 1) a → Inv n (attesterMultiAttestInnerArrayInitStepState a)) - (hinit : - Inv (len.toNat - 1) - { slot := slot, remaining := len, mem := mem, aw := aw }) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1113⟩ : UInt256) - [slot, len, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ a' k' C', - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv 0 a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1181⟩ : UInt256) - (attesterMultiAttestInnerArrayInitExitStack I base len payload a') - (attesterMultiAttestInnerArrayInitFinalMem a') - (attesterMultiAttestInnerArrayInitFinalAw a') - ByteArray.empty (cA, σ) k' C' := by - let stk := attesterMultiAttestInnerArrayInitStack I base len payload - let memOf : AttesterMultiAttestInnerArrayInitState → ByteArray := fun a => a.mem - let awOf : AttesterMultiAttestInnerArrayInitState → UInt256 := fun a => a.aw - let exitStk := attesterMultiAttestInnerArrayInitExitStack I base len payload - let exitMem := attesterMultiAttestInnerArrayInitFinalMem - let exitAw := attesterMultiAttestInnerArrayInitFinalAw - have hexit : - ∀ a, Inv 0 a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1113⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1181⟩ : UInt256) (exitStk a) (exitMem a) (exitAw a) - ByteArray.empty (cA, σ) k' C' := by - intro a hInv k C rd - have hrem : a.remaining = (⟨1⟩ : UInt256) := by - simpa using hremaining 0 a hInv - exact attesterX_multiAttestInnerArrayInitFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (payload := payload) (mem := a.mem) (aw := a.aw) - (by - simpa [stk, memOf, awOf, hrem, attesterMultiAttestInnerArrayInitStack] - using rd) - have hbody : - ∀ n a, Inv (n + 1) a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1113⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ a' k' C', - Inv n a' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1113⟩ : UInt256) (stk a') (memOf a') (awOf a') - ByteArray.empty (cA, σ) k' C' := by - intro n a hInv k C rd - let a' := attesterMultiAttestInnerArrayInitStepState a - have hsub : - attesterMultiAttestInnerArrayInitDecRemaining a.remaining = - UInt256.ofNat (n + 1) := by - rw [hremaining (n + 1) a hInv] - simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using - attester_u256_ofNat_succ_add_lnot_zero (n := n + 1) - (hbound (n + 1) a hInv) - have hnext : - attesterMultiAttestInnerArrayInitDecRemaining a.remaining ≠ ⟨0⟩ := by - rw [hsub] - exact attester_u256_ofNat_pos_ne_zero - (n := n + 1) (by omega) (by - have := hbound (n + 1) a hInv - omega) - obtain ⟨k', C', rd'⟩ := - attesterX_multiAttestInnerArrayInitNonFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (payload := payload) (remaining := a.remaining) (mem := a.mem) - (aw := a.aw) hnext - (by - simpa [stk, memOf, awOf, attesterMultiAttestInnerArrayInitStack] - using rd) - refine ⟨a', k', C', hstep n a hInv, ?_⟩ - simpa [a', stk, memOf, awOf, attesterMultiAttestInnerArrayInitStack, - attesterMultiAttestInnerArrayInitStepState] using rd' - let a0 : AttesterMultiAttestInnerArrayInitState := - { slot := slot, remaining := len, mem := mem, aw := aw } - obtain ⟨a', k', C', hInvFinal, rdFinal⟩ := - RD.whileLoopCarryExit - (code := patchedRuntime v) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) - (rdata := ByteArray.empty) (acc := (cA, σ)) - (header := (⟨1113⟩ : UInt256)) (exit := (⟨1181⟩ : UInt256)) - Inv stk memOf awOf exitStk exitMem exitAw hexit hbody - (len.toNat - 1) a0 (by simpa [a0] using hinit) k C - (by - simpa [a0, stk, memOf, awOf, attesterMultiAttestInnerArrayInitStack] - using hreach) - exact ⟨a', k', C', by simpa using hremaining 0 a' hInvFinal, - hInvFinal, rdFinal⟩ - -theorem attesterX_multiRevokeFirstInnerArrayInitProgressWithStateInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (hlenNe : attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩) - (Inv : - AttesterMultiOuterArrayInitState → Nat → - AttesterMultiRevokeInnerArrayInitState → Prop) - (hremaining : - ∀ a n b, Inv a n b → b.remaining = UInt256.ofNat (n + 1)) - (hbound : - ∀ a n b, Inv a n b → n + 1 < UInt256.size) - (hstep : - ∀ a n b, Inv a (n + 1) b → - Inv a n (attesterMultiRevokeInnerArrayInitStepState b)) - (hinit : - ∀ a, a.remaining = (⟨1⟩ : UInt256) → - Inv a ((attesterFirstInnerArrayLengthWord I).toNat - 1) - { slot := - ((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)), - remaining := attesterFirstInnerArrayLengthWord I, - mem := - attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a), - aw := - attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a) }) - (hprogress : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - (((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) :: - attesterFirstInnerArrayLengthWord I :: - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') :: - ⟨0⟩ :: - attesterFirstInnerArrayLengthWord I :: - attesterFirstInnerArrayLengthWord I :: - (attesterFirstInnerArrayStartWord I + ⟨32⟩) :: - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I]) - (attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ByteArray.empty (cA, σ) k C) : - ∃ a' b' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - Inv a' 0 b' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (attesterMultiRevokeInnerArrayInitExitStack I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - b') - (attesterMultiRevokeInnerArrayInitFinalMem b') - (attesterMultiRevokeInnerArrayInitFinalAw b') - ByteArray.empty (cA, σ) k C := by - obtain ⟨a', k0, C0, hrem, rd0⟩ := hprogress - have hlenNatNe : (attesterFirstInnerArrayLengthWord I).toNat ≠ 0 := by - intro hzero - apply hlenNe - apply u256_inj - simpa using hzero - obtain ⟨b', k1, C1, hbrem, hInv, rd1⟩ := - attesterX_multiRevokeInnerArrayInitLoopWithStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (Inv := Inv a') (slot := - ((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a'))) - (base := - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (len := attesterFirstInnerArrayLengthWord I) - (payload := attesterFirstInnerArrayStartWord I + ⟨32⟩) - (mem := - attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (aw := - attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (k := k0) (C := C0) - (hremaining a') (hbound a') (hstep a') (hinit a' hrem) - (by simpa using rd0) - exact ⟨a', b', k1, C1, hrem, hbrem, hInv, rd1⟩ - -abbrev attesterMultiRevokeInnerArrayCopyFreeWord - (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMloadWord mem aw ⟨64⟩ - -abbrev attesterMultiRevokeInnerArrayCopyAwAfterMload - (aw : UInt256) : UInt256 := - attesterMloadAw aw ⟨64⟩ - -abbrev attesterMultiRevokeInnerArrayCopyFreeBumpWord - (mem : ByteArray) (aw : UInt256) : UInt256 := - (⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw - -abbrev attesterMultiRevokeInnerArrayCopyFreeMem - (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw)).write 0 mem 64 32 - -abbrev attesterMultiRevokeInnerArrayCopyFreeAw - (_mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiRevokeInnerArrayCopyAwAfterMload aw).toNat 64 32) - -abbrev attesterMultiRevokeInnerArrayCopyCalldataOffset - (payload idx : UInt256) : UInt256 := - UInt256.mul (⟨32⟩ : UInt256) idx + payload - -abbrev attesterMultiRevokeInnerArrayCopyUidWord - (I : ExecutionEnv) (payload idx : UInt256) : UInt256 := - calldataWord I.calldata - (attesterMultiRevokeInnerArrayCopyCalldataOffset payload idx).toNat - -abbrev attesterMultiRevokeInnerArrayCopyUidMem - (I : ExecutionEnv) (payload idx : UInt256) (mem : ByteArray) (aw : UInt256) : - ByteArray := - (UInt256.toByteArray - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)).write 0 - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat 32 - -abbrev attesterMultiRevokeInnerArrayCopyUidAw - (_idx : UInt256) (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiRevokeInnerArrayCopyFreeAw mem aw).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat 32) - -abbrev attesterMultiRevokeInnerArrayCopyZeroWord - (mem : ByteArray) (aw : UInt256) : UInt256 := - (⟨32⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw - -abbrev attesterMultiRevokeInnerArrayCopyZeroMem - (I : ExecutionEnv) (payload idx : UInt256) (mem : ByteArray) (aw : UInt256) : - ByteArray := - (UInt256.toByteArray (⟨0⟩ : UInt256)).write 0 - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat 32 - -abbrev attesterMultiRevokeInnerArrayCopyZeroAw - (_I : ExecutionEnv) (_payload idx : UInt256) (mem : ByteArray) (aw : UInt256) : - UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiRevokeInnerArrayCopyUidAw idx mem aw).toNat - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat 32) - -abbrev attesterMultiRevokeInnerArrayCopySlotWord - (base idx : UInt256) : UInt256 := - (UInt256.mul (⟨32⟩ : UInt256) idx + base) + (⟨32⟩ : UInt256) - -abbrev attesterMultiRevokeInnerArrayCopyStepMem - (I : ExecutionEnv) (base payload idx : UInt256) (mem : ByteArray) (aw : UInt256) : - ByteArray := - (UInt256.toByteArray (attesterMultiRevokeInnerArrayCopyFreeWord mem aw)).write 0 - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat 32 - -abbrev attesterMultiRevokeInnerArrayCopyStepAw - (I : ExecutionEnv) (base payload idx : UInt256) (mem : ByteArray) (aw : UInt256) : - UInt256 := - UInt256.ofNat - (MachineState.M - (attesterMloadAw - (attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw) base).toNat - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat 32) - -abbrev attesterMultiRevokeInnerArrayCopyNextIdx (idx : UInt256) : UInt256 := - (⟨1⟩ : UInt256) + idx - -structure AttesterMultiRevokeInnerArrayCopyState where - idx : UInt256 - mem : ByteArray - aw : UInt256 - -abbrev attesterMultiRevokeInnerArrayCopyStack - (base len payload : UInt256) (tail : List UInt256) - (a : AttesterMultiRevokeInnerArrayCopyState) : List UInt256 := - a.idx :: base :: len :: len :: payload :: tail - -abbrev attesterMultiRevokeInnerArrayCopyStepState - (I : ExecutionEnv) (base payload : UInt256) - (a : AttesterMultiRevokeInnerArrayCopyState) : - AttesterMultiRevokeInnerArrayCopyState := - { idx := attesterMultiRevokeInnerArrayCopyNextIdx a.idx, - mem := attesterMultiRevokeInnerArrayCopyStepMem I base payload a.idx a.mem a.aw, - aw := attesterMultiRevokeInnerArrayCopyStepAw I base payload a.idx a.mem a.aw } - -private theorem attesterMultiRevokeInnerArrayCopyNextIdx_ofNat - {len n : Nat} - (hle : n + 1 ≤ len) (hlen : len < UInt256.size) : - attesterMultiRevokeInnerArrayCopyNextIdx - (UInt256.ofNat (len - (n + 1))) = - UInt256.ofNat (len - n) := by - apply u256_inj - unfold attesterMultiRevokeInnerArrayCopyNextIdx - rw [uadd_toNat] - rw [show (⟨1⟩ : UInt256).toNat = 1 by decide] - rw [ulit_toNat' (len - (n + 1)) (by omega)] - rw [ulit_toNat' (len - n) (by omega)] - have hsum : 1 + (len - (n + 1)) = len - n := by omega - rw [hsum] - exact Nat.mod_eq_of_lt (by omega) - -private theorem attesterMultiRevokeInnerArrayCopyStep_readWithPadding_preserved - {I : ExecutionEnv} {base payload idx len : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (hgap64 : 64 - mem.size < USize.size) - (hgapUid : - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).size < USize.size) - (hgapZero : - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size < USize.size) - (hgapSlot : - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).size < USize.size) - (h64 : 64 + 32 ≤ base.toNat) - (huid : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) - (hslot : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat) : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - have hread1 : - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw)).readWithPadding - base.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_below - (mem := mem) (base := base.toNat) (writeOff := 64) - (len := len) (writeVal := attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw) - hmem hgap64 h64 hread - have hmem1 : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).size := by - have hsize := writeWord_size mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw) hgap64 - unfold Reasoning.Theory.writeWord at hsize - rw [hsize] - omega - have hread2 : - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)).readWithPadding - base.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above - (mem := attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (base := base.toNat) - (writeOff := (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (len := len) - (writeVal := attesterMultiRevokeInnerArrayCopyUidWord I payload idx) - hmem1 hgapUid huid hread1 - have hmem2 : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size := by - have hsize := writeWord_size (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx) hgapUid - unfold Reasoning.Theory.writeWord at hsize - rw [hsize] - omega - have hread3 : - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).readWithPadding base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above - (mem := attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (base := base.toNat) - (writeOff := (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) - (len := len) (writeVal := (⟨0⟩ : UInt256)) - hmem2 hgapZero hzero hread2 - have hmem3 : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).size := by - have hsize := writeWord_size - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256) hgapZero - unfold Reasoning.Theory.writeWord at hsize - rw [hsize] - omega - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw)).readWithPadding - base.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above - (mem := attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (base := base.toNat) - (writeOff := (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat) - (len := len) - (writeVal := attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - hmem3 hgapSlot hslot hread3 - -private theorem attesterMultiRevokeInnerArrayCopyZero_readWithPadding_preserved - {I : ExecutionEnv} {base payload idx len : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (hgap64 : 64 - mem.size < USize.size) - (hgapUid : - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).size < USize.size) - (hgapZero : - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size < USize.size) - (h64 : 64 + 32 ≤ base.toNat) - (huid : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) : - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - have hread1 : - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw)).readWithPadding - base.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_below - (mem := mem) (base := base.toNat) (writeOff := 64) - (len := len) (writeVal := attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw) - hmem hgap64 h64 hread - have hmem1 : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).size := by - have hsize := writeWord_size mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw) hgap64 - unfold Reasoning.Theory.writeWord at hsize - rw [hsize] - omega - have hread2 : - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)).readWithPadding - base.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above - (mem := attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (base := base.toNat) - (writeOff := (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (len := len) - (writeVal := attesterMultiRevokeInnerArrayCopyUidWord I payload idx) - hmem1 hgapUid huid hread1 - have hmem2 : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size := by - have hsize := writeWord_size (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx) hgapUid - unfold Reasoning.Theory.writeWord at hsize - rw [hsize] - omega - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).readWithPadding base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above - (mem := attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (base := base.toNat) - (writeOff := (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) - (len := len) (writeVal := (⟨0⟩ : UInt256)) - hmem2 hgapZero hzero hread2 - -private theorem attesterMultiRevokeInnerArrayCopyZero_mloadLen_of_readWithPadding - {I : ExecutionEnv} {base payload idx len : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (haw : - ¬ base ≥ - attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw * (⟨32⟩ : UInt256)) - (hgap64 : 64 - mem.size < USize.size) - (hgapUid : - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).size < USize.size) - (hgapZero : - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size < USize.size) - (h64 : 64 + 32 ≤ base.toNat) - (huid : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) : - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw) - base = len := by - have hreadZero := - attesterMultiRevokeInnerArrayCopyZero_readWithPadding_preserved - (I := I) (base := base) (payload := payload) (idx := idx) - (len := len) (mem := mem) (aw := aw) - hmem hread hgap64 hgapUid hgapZero h64 huid hzero - have hmemZero : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).size := by - have hsize1 := writeWord_size mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw) hgap64 - have hsize2 := writeWord_size (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx) hgapUid - have hsize3 := writeWord_size - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256) hgapZero - unfold Reasoning.Theory.writeWord at hsize1 hsize2 hsize3 - rw [hsize3, hsize2, hsize1] - omega - exact attesterMloadWord_of_readWithPadding hmemZero haw hreadZero - -theorem attesterMultiRevokeInnerArrayCopyZero_mloadLen - {I : ExecutionEnv} {base payload idx len : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (haw : - ¬ base ≥ - attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw * (⟨32⟩ : UInt256)) - (hgap64 : 64 - mem.size < USize.size) - (hgapUid : - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).size < USize.size) - (hgapZero : - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size < USize.size) - (h64 : 64 + 32 ≤ base.toNat) - (huid : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) : - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw) - base = len := - attesterMultiRevokeInnerArrayCopyZero_mloadLen_of_readWithPadding - (I := I) (base := base) (payload := payload) (idx := idx) - (len := len) (mem := mem) (aw := aw) - hmem hread haw hgap64 hgapUid hgapZero h64 huid hzero - -theorem attesterMultiRevokeInnerArrayCopyStep_readWithPadding - {I : ExecutionEnv} {base payload idx len : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (hgap64 : 64 - mem.size < USize.size) - (hgapUid : - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).size < USize.size) - (hgapZero : - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size < USize.size) - (hgapSlot : - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).size < USize.size) - (h64 : 64 + 32 ≤ base.toNat) - (huid : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) - (hslot : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat) : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := - attesterMultiRevokeInnerArrayCopyStep_readWithPadding_preserved - (I := I) (base := base) (payload := payload) (idx := idx) - (len := len) (mem := mem) (aw := aw) - hmem hread hgap64 hgapUid hgapZero hgapSlot h64 huid hzero hslot - -theorem attesterX_multiRevokeInnerArrayCopyExit - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx base len payload : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hge : UInt256.lt idx len = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (idx :: base :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨608⟩ : UInt256) - (idx :: base :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - have hcond : UInt256.isZero (UInt256.lt idx len) ≠ ⟨0⟩ := by - rw [hge] - decide - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨518⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨519⟩, 0x82, .DUP3) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨520⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨521⟩, 0x10, .LT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨522⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨608⟩ (by attester_decode_at v, ⟨523⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨526⟩, 0x57, .JUMPI) - hcond (attesterMultiRevokeInnerArrayCopyExitJumpdest v) (by evm_ov)]⟩ - -set_option maxHeartbeats 1500000 in -theorem attesterX_multiRevokeInnerArrayCopyNonFinalIteration - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx base len payload : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hlt : UInt256.lt idx len = ⟨1⟩) - (hloadLt : - UInt256.lt idx - (attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw) - base) = ⟨1⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (idx :: base :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (attesterMultiRevokeInnerArrayCopyNextIdx idx :: - base :: len :: len :: payload :: tail) - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload idx mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterMultiRevokeInnerArrayCopyFreeWord mem aw - let aw1 := attesterMultiRevokeInnerArrayCopyAwAfterMload aw - let bump := attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw - let mem1 := attesterMultiRevokeInnerArrayCopyFreeMem mem aw - let aw2 := attesterMultiRevokeInnerArrayCopyFreeAw mem aw - let cdOff := attesterMultiRevokeInnerArrayCopyCalldataOffset payload idx - let uid := attesterMultiRevokeInnerArrayCopyUidWord I payload idx - let mem2 := attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw - let aw3 := attesterMultiRevokeInnerArrayCopyUidAw idx mem aw - let zeroWord := attesterMultiRevokeInnerArrayCopyZeroWord mem aw - let mem3 := attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw - let aw4 := attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw - let loadLen := attesterMloadWord mem3 aw4 base - let aw5 := attesterMloadAw aw4 base - let slot := attesterMultiRevokeInnerArrayCopySlotWord base idx - let mem4 := attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw - let aw6 := attesterMultiRevokeInnerArrayCopyStepAw I base payload idx mem aw - have hcostMload64 : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = (⟨64⟩ : UInt256) :: idx :: base :: len :: len :: payload :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreFree : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = (⟨64⟩ : UInt256) :: bump :: free :: idx :: base :: len :: - len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreUid : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = free :: uid :: free :: free :: idx :: base :: len :: - len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = zeroWord :: (⟨0⟩ : UInt256) :: zeroWord :: free :: - idx :: base :: len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw4 - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostMloadBase : - ∀ s : State, - s.machineState.activeWords = aw4 → - s.machineState.stack = base :: idx :: base :: free :: idx :: base :: len :: - len :: payload :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw5 - Cₘ aw4 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSlot : - ∀ s : State, - s.machineState.activeWords = aw5 → - s.machineState.stack = slot :: free :: idx :: base :: len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw6 - Cₘ aw5 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hrd527 : ∃ k527 C527, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨527⟩ : UInt256) - (idx :: base :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k527 C527 := by - exact ⟨_, _, by - simpa using evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨518⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨519⟩, 0x82, .DUP3) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨520⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨521⟩, 0x10, .LT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨522⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨608⟩ (by attester_decode_at v, ⟨523⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨526⟩, 0x57, .JUMPI) - (by rw [hlt]; decide) (by evm_ov)]⟩ - obtain ⟨_, _, rd527⟩ := hrd527 - exact ⟨_, _, by - simpa [free, aw1, bump, mem1, aw2, cdOff, uid, mem2, aw3, - zeroWord, mem3, aw4, loadLen, aw5, slot, mem4, aw6, - attesterMultiRevokeInnerArrayCopyNextIdx] using - evm_run rd527 with [ - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨527⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨529⟩, 0x51, .MLOAD) - hcostMload64 (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨530⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨531⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨533⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨534⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨536⟩, 0x52, .MSTORE) - hcostStoreFree (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨537⟩, 0x80, .DUP1) (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨538⟩, 0x86, .DUP7) (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨539⟩, 0x86, .DUP7) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨540⟩, 0x84, .DUP5) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨541⟩, 0x81, .DUP2) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨542⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨543⟩, 0x10, .LT) (by evm_ov), - raw push2 ⟨555⟩ (by attester_decode_at v, ⟨544⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨547⟩, 0x57, .JUMPI) - (by rw [hlt]; decide) - (attesterMultiRevokeInnerArrayCopyElementOkJumpdest v) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨555⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨556⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨557⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨558⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mul (by attester_decode_at v, ⟨560⟩, 0x02, .MUL) (by evm_ov), - raw add (by attester_decode_at v, ⟨561⟩, 0x01, .ADD) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨562⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨563⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨564⟩, 0x52, .MSTORE) - hcostStoreUid (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨565⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨567⟩, 0x01, .ADD) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨568⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨569⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw4 - Cₘ aw3) mem3 aw4 - (by attester_decode_at v, ⟨570⟩, 0x52, .MSTORE) - hcostStoreZero (by rfl) (by rfl) (by evm_ov), - raw pop (by attester_decode_at v, ⟨571⟩, 0x50, .POP) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨572⟩, 0x82, .DUP3) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨573⟩, 0x82, .DUP3) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨574⟩, 0x81, .DUP2) (by evm_ov), - raw mload (Cₘ aw5 - Cₘ aw4) loadLen aw5 - (by attester_decode_at v, ⟨575⟩, 0x51, .MLOAD) - hcostMloadBase (by rfl) (by rfl) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨576⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨577⟩, 0x10, .LT) (by evm_ov), - raw push2 ⟨589⟩ (by attester_decode_at v, ⟨578⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨581⟩, 0x57, .JUMPI) - (by rw [hloadLt]; decide) - (attesterMultiRevokeInnerArrayCopyStoreOkJumpdest v) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨589⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨590⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨592⟩, 0x90, .SWAP1) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨593⟩, 0x81, .DUP2) (by evm_ov), - raw mul (by attester_decode_at v, ⟨594⟩, 0x02, .MUL) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨595⟩, 0x91, .SWAP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨596⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨597⟩, 0x91, .SWAP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨598⟩, 0x01, .ADD) (by evm_ov), - raw add (by attester_decode_at v, ⟨599⟩, 0x01, .ADD) (by evm_ov), - raw mstore (Cₘ aw6 - Cₘ aw5) mem4 aw6 - (by attester_decode_at v, ⟨600⟩, 0x52, .MSTORE) - hcostStoreSlot (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨601⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨603⟩, 0x01, .ADD) (by evm_ov), - raw push2 ⟨518⟩ (by attester_decode_at v, ⟨604⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨607⟩, 0x56, .JUMP) - (attesterMultiRevokeInnerArrayCopyLoopJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeInnerArrayCopyNonFinalIterationOfLenReadable - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx base len payload : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hlt : UInt256.lt idx len = ⟨1⟩) - (hloadLen : - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw) - base = len) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (idx :: base :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (attesterMultiRevokeInnerArrayCopyNextIdx idx :: - base :: len :: len :: payload :: tail) - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload idx mem aw) - ByteArray.empty (cA, σ) k' C' := by - exact attesterX_multiRevokeInnerArrayCopyNonFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (base := base) (len := len) (payload := payload) - (tail := tail) (mem := mem) (aw := aw) (k := k) (C := C) - htail hlt (by rw [hloadLen, hlt]) hreach - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeInnerArrayCopyLoopWithReadInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base len payload : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hread0 : - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload (⟨0⟩ : UInt256) mem aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload (⟨0⟩ : UInt256) mem aw) - base = len) - (hreadStep : - ∀ n a, - a.idx = UInt256.ofNat (len.toNat - (n + 1)) → - n + 1 ≤ len.toNat → - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload a.idx a.mem a.aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload a.idx a.mem a.aw) - base = len → - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload - (attesterMultiRevokeInnerArrayCopyStepState I base payload a).idx - (attesterMultiRevokeInnerArrayCopyStepState I base payload a).mem - (attesterMultiRevokeInnerArrayCopyStepState I base payload a).aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload - (attesterMultiRevokeInnerArrayCopyStepState I base payload a).idx - (attesterMultiRevokeInnerArrayCopyStepState I base payload a).mem - (attesterMultiRevokeInnerArrayCopyStepState I base payload a).aw) - base = len) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - ((⟨0⟩ : UInt256) :: base :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ a' k' C', - a'.idx = len ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨608⟩ : UInt256) - (attesterMultiRevokeInnerArrayCopyStack base len payload tail a') - a'.mem a'.aw ByteArray.empty (cA, σ) k' C' := by - let Inv : Nat → AttesterMultiRevokeInnerArrayCopyState → Prop := - fun n a => - a.idx = UInt256.ofNat (len.toNat - n) ∧ - n ≤ len.toNat ∧ - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload a.idx a.mem a.aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload a.idx a.mem a.aw) - base = len - let stk := attesterMultiRevokeInnerArrayCopyStack base len payload tail - let memOf : AttesterMultiRevokeInnerArrayCopyState → ByteArray := fun a => a.mem - let awOf : AttesterMultiRevokeInnerArrayCopyState → UInt256 := fun a => a.aw - have hexit : - ∀ a, Inv 0 a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨518⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨608⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k' C' := by - intro a hInv k C rd - have hidxLen : a.idx = len := by - rw [hInv.1] - simpa using (u256_ofNat_toNat len) - have hge : UInt256.lt a.idx len = (⟨0⟩ : UInt256) := by - rw [hidxLen] - exact ult_zero (a := len) (b := len) (by rfl) - exact attesterX_multiRevokeInnerArrayCopyExit - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := a.idx) (base := base) (len := len) (payload := payload) - (tail := tail) (mem := a.mem) (aw := a.aw) (k := k) (C := C) - htail hge - (by simpa [stk, memOf, awOf, attesterMultiRevokeInnerArrayCopyStack] using rd) - have hbody : - ∀ n a, Inv (n + 1) a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨518⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ a' k' C', - Inv n a' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨518⟩ : UInt256) (stk a') (memOf a') (awOf a') - ByteArray.empty (cA, σ) k' C' := by - intro n a hInv k C rd - let a' := attesterMultiRevokeInnerArrayCopyStepState I base payload a - have hidxNat : a.idx.toNat = len.toNat - (n + 1) := by - rw [hInv.1] - exact ulit_toNat' (len.toNat - (n + 1)) - (lt_of_le_of_lt (Nat.sub_le _ _) len.val.isLt) - have hltNat : a.idx.toNat < len.toNat := by - have hle : n + 1 ≤ len.toNat := hInv.2.1 - omega - have hlt : UInt256.lt a.idx len = (⟨1⟩ : UInt256) := - ult_one hltNat - obtain ⟨k', C', rd'⟩ := - attesterX_multiRevokeInnerArrayCopyNonFinalIterationOfLenReadable - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := a.idx) (base := base) (len := len) (payload := payload) - (tail := tail) (mem := a.mem) (aw := a.aw) (k := k) (C := C) - htail hlt hInv.2.2 - (by simpa [stk, memOf, awOf, attesterMultiRevokeInnerArrayCopyStack] using rd) - refine ⟨a', k', C', ?_, ?_⟩ - · constructor - · have hnext : - attesterMultiRevokeInnerArrayCopyNextIdx a.idx = - UInt256.ofNat (len.toNat - n) := by - rw [hInv.1] - exact attesterMultiRevokeInnerArrayCopyNextIdx_ofNat - (len := len.toNat) (n := n) hInv.2.1 len.val.isLt - simpa [a', attesterMultiRevokeInnerArrayCopyStepState] using hnext - · constructor - · have := hInv.2.1 - omega - · exact hreadStep n a hInv.1 hInv.2.1 hInv.2.2 - · simpa [a', stk, memOf, awOf, attesterMultiRevokeInnerArrayCopyStack, - attesterMultiRevokeInnerArrayCopyStepState] using rd' - let a0 : AttesterMultiRevokeInnerArrayCopyState := - { idx := (⟨0⟩ : UInt256), mem := mem, aw := aw } - have hInv0 : Inv len.toNat a0 := by - constructor - · have hsub : len.toNat - len.toNat = 0 := by omega - rw [hsub] - apply u256_inj - rfl - · constructor - · omega - · simpa [a0] using hread0 - obtain ⟨a', k', C', hInvFinal, rdFinal⟩ := - RD.whileLoopCarryExit - (code := patchedRuntime v) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) - (rdata := ByteArray.empty) (acc := (cA, σ)) - (header := (⟨518⟩ : UInt256)) (exit := (⟨608⟩ : UInt256)) - Inv stk memOf awOf stk memOf awOf hexit hbody - len.toNat a0 hInv0 k C - (by - simpa [a0, stk, memOf, awOf, attesterMultiRevokeInnerArrayCopyStack] - using hreach) - exact ⟨a', k', C', by - have hidx := hInvFinal.1 - rw [hidx] - simpa using (u256_ofNat_toNat len), rdFinal⟩ - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeInnerArrayCopyLoopWithStateInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base len payload : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (Inv : Nat → AttesterMultiRevokeInnerArrayCopyState → Prop) - (hidx : - ∀ n a, Inv n a → a.idx = UInt256.ofNat (len.toNat - n)) - (hle : ∀ n a, Inv n a → n ≤ len.toNat) - (hload : - ∀ n a, Inv n a → - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload a.idx a.mem a.aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload a.idx a.mem a.aw) - base = len) - (hstep : - ∀ n a, Inv (n + 1) a → - Inv n (attesterMultiRevokeInnerArrayCopyStepState I base payload a)) - (hinit : - Inv len.toNat - { idx := (⟨0⟩ : UInt256), mem := mem, aw := aw }) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - ((⟨0⟩ : UInt256) :: base :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ a' k' C', - a'.idx = len ∧ - Inv 0 a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨608⟩ : UInt256) - (attesterMultiRevokeInnerArrayCopyStack base len payload tail a') - a'.mem a'.aw ByteArray.empty (cA, σ) k' C' := by - let stk := attesterMultiRevokeInnerArrayCopyStack base len payload tail - let memOf : AttesterMultiRevokeInnerArrayCopyState → ByteArray := fun a => a.mem - let awOf : AttesterMultiRevokeInnerArrayCopyState → UInt256 := fun a => a.aw - have hexit : - ∀ a, Inv 0 a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨518⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨608⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k' C' := by - intro a hInv k C rd - have hidxLen : a.idx = len := by - rw [hidx 0 a hInv] - simpa using (u256_ofNat_toNat len) - have hge : UInt256.lt a.idx len = (⟨0⟩ : UInt256) := by - rw [hidxLen] - exact ult_zero (a := len) (b := len) (by rfl) - exact attesterX_multiRevokeInnerArrayCopyExit - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := a.idx) (base := base) (len := len) (payload := payload) - (tail := tail) (mem := a.mem) (aw := a.aw) (k := k) (C := C) - htail hge - (by simpa [stk, memOf, awOf, attesterMultiRevokeInnerArrayCopyStack] using rd) - have hbody : - ∀ n a, Inv (n + 1) a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨518⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ a' k' C', - Inv n a' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨518⟩ : UInt256) (stk a') (memOf a') (awOf a') - ByteArray.empty (cA, σ) k' C' := by - intro n a hInv k C rd - let a' := attesterMultiRevokeInnerArrayCopyStepState I base payload a - have hidxNat : a.idx.toNat = len.toNat - (n + 1) := by - rw [hidx (n + 1) a hInv] - exact ulit_toNat' (len.toNat - (n + 1)) - (lt_of_le_of_lt (Nat.sub_le _ _) len.val.isLt) - have hltNat : a.idx.toNat < len.toNat := by - have hle' : n + 1 ≤ len.toNat := hle (n + 1) a hInv - omega - have hlt : UInt256.lt a.idx len = (⟨1⟩ : UInt256) := - ult_one hltNat - obtain ⟨k', C', rd'⟩ := - attesterX_multiRevokeInnerArrayCopyNonFinalIterationOfLenReadable - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := a.idx) (base := base) (len := len) (payload := payload) - (tail := tail) (mem := a.mem) (aw := a.aw) (k := k) (C := C) - htail hlt (hload (n + 1) a hInv) - (by simpa [stk, memOf, awOf, attesterMultiRevokeInnerArrayCopyStack] using rd) - refine ⟨a', k', C', hstep n a hInv, ?_⟩ - simpa [a', stk, memOf, awOf, attesterMultiRevokeInnerArrayCopyStack, - attesterMultiRevokeInnerArrayCopyStepState] using rd' - let a0 : AttesterMultiRevokeInnerArrayCopyState := - { idx := (⟨0⟩ : UInt256), mem := mem, aw := aw } - obtain ⟨a', k', C', hInvFinal, rdFinal⟩ := - RD.whileLoopCarryExit - (code := patchedRuntime v) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) - (rdata := ByteArray.empty) (acc := (cA, σ)) - (header := (⟨518⟩ : UInt256)) (exit := (⟨608⟩ : UInt256)) - Inv stk memOf awOf stk memOf awOf hexit hbody - len.toNat a0 (by simpa [a0] using hinit) k C - (by - simpa [a0, stk, memOf, awOf, attesterMultiRevokeInnerArrayCopyStack] - using hreach) - exact ⟨a', k', C', - by - rw [hidx 0 a' hInvFinal] - simpa using (u256_ofNat_toNat len), - hInvFinal, rdFinal⟩ - -theorem attesterX_multiRevokeFirstInnerArrayCopyProgressWithReadInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (hprogress : - ∃ (a' : AttesterMultiOuterArrayInitState), - ∃ (b' : AttesterMultiRevokeInnerArrayInitState), - ∃ k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (attesterMultiRevokeInnerArrayInitExitStack I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - b') - (attesterMultiRevokeInnerArrayInitFinalMem b') - (attesterMultiRevokeInnerArrayInitFinalAw b') - ByteArray.empty (cA, σ) k C) - (hread0 : - ∀ (a' : AttesterMultiOuterArrayInitState) - (b' : AttesterMultiRevokeInnerArrayInitState), - a'.remaining = (⟨1⟩ : UInt256) → - b'.remaining = (⟨1⟩ : UInt256) → - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - (⟨0⟩ : UInt256) - (attesterMultiRevokeInnerArrayInitFinalMem b') - (attesterMultiRevokeInnerArrayInitFinalAw b')) - (attesterMultiRevokeInnerArrayCopyZeroAw I - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - (⟨0⟩ : UInt256) - (attesterMultiRevokeInnerArrayInitFinalMem b') - (attesterMultiRevokeInnerArrayInitFinalAw b')) - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) = - attesterFirstInnerArrayLengthWord I) - (hreadStep : - ∀ (a' : AttesterMultiOuterArrayInitState) n s, - s.idx = - UInt256.ofNat - ((attesterFirstInnerArrayLengthWord I).toNat - (n + 1)) → - n + 1 ≤ (attesterFirstInnerArrayLengthWord I).toNat → - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I - (attesterFirstInnerArrayStartWord I + ⟨32⟩) s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I - (attesterFirstInnerArrayStartWord I + ⟨32⟩) s.idx s.mem s.aw) - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) = - attesterFirstInnerArrayLengthWord I → - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - (attesterMultiRevokeInnerArrayCopyStepState I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) s).idx - (attesterMultiRevokeInnerArrayCopyStepState I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) s).mem - (attesterMultiRevokeInnerArrayCopyStepState I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) s).aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - (attesterMultiRevokeInnerArrayCopyStepState I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) s).idx - (attesterMultiRevokeInnerArrayCopyStepState I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) s).mem - (attesterMultiRevokeInnerArrayCopyStepState I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) s).aw) - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) = - attesterFirstInnerArrayLengthWord I) : - ∃ (a' : AttesterMultiOuterArrayInitState), - ∃ (b' : AttesterMultiRevokeInnerArrayInitState), - ∃ (c' : AttesterMultiRevokeInnerArrayCopyState), - ∃ k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - c'.idx = attesterFirstInnerArrayLengthWord I ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨608⟩ : UInt256) - (attesterMultiRevokeInnerArrayCopyStack - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - c') - c'.mem c'.aw ByteArray.empty (cA, σ) k C := by - obtain ⟨a', b', k0, C0, harem, hbrem, rd0⟩ := hprogress - obtain ⟨c', k1, C1, hcidx, rd1⟩ := - attesterX_multiRevokeInnerArrayCopyLoopWithReadInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (len := attesterFirstInnerArrayLengthWord I) - (payload := attesterFirstInnerArrayStartWord I + ⟨32⟩) - (tail := [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I]) - (mem := attesterMultiRevokeInnerArrayInitFinalMem b') - (aw := attesterMultiRevokeInnerArrayInitFinalAw b') - (k := k0) (C := C0) (by simp) - (hread0 a' b' harem hbrem) - (hreadStep a') (by simpa [attesterMultiRevokeInnerArrayInitExitStack] using rd0) - exact ⟨a', b', c', k1, C1, harem, hbrem, hcidx, rd1⟩ - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/InnerArrayEVM.lean b/Benchmarks/EAS/Attester/InnerArrayEVM.lean deleted file mode 100644 index 9233a405..00000000 --- a/Benchmarks/EAS/Attester/InnerArrayEVM.lean +++ /dev/null @@ -1,1845 +0,0 @@ -import Benchmarks.EAS.Attester.InnerArray - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -private theorem attester_add_mul_zero_right (p : UInt256) : - p + UInt256.mul (⟨32⟩ : UInt256) ⟨0⟩ = p := by - apply u256_inj - rw [uadd_toNat] - have hmul : (UInt256.mul (⟨32⟩ : UInt256) ⟨0⟩).toNat = 0 := by decide - rw [hmul, Nat.add_zero] - exact Nat.mod_eq_of_lt p.val.isLt - -private theorem attester_pc363_after_inner_setup : - ((((((((((((⟨363⟩ : UInt256) + ⟨1⟩) + ⟨1⟩) + ⟨1⟩) + - UInt256.ofNat 2) + ⟨1⟩) + ⟨1⟩) + ⟨1⟩) + ⟨1⟩) + - UInt256.ofNat 3) + ⟨1⟩) + ⟨1⟩) + UInt256.ofNat 3 = - (⟨380⟩ : UInt256) := by - native_decide - -private theorem attester_pc1001_after_inner_setup : - ((((((((((((⟨1001⟩ : UInt256) + ⟨1⟩) + ⟨1⟩) + ⟨1⟩) + - UInt256.ofNat 2) + ⟨1⟩) + ⟨1⟩) + ⟨1⟩) + ⟨1⟩) + - UInt256.ofNat 3) + ⟨1⟩) + ⟨1⟩) + UInt256.ofNat 3 = - (⟨1018⟩ : UInt256) := by - native_decide - -private theorem attester_first_inner_start_add32_comm (I : ExecutionEnv) : - (⟨32⟩ : UInt256) + attesterFirstInnerArrayStartWord I = - attesterFirstInnerArrayStartWord I + ⟨32⟩ := by - exact u256_add_comm _ _ - -theorem attesterX_multiRevokeFirstInnerArrayDecoderSetup - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {l p sz base len fp ret sel : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨363⟩ : UInt256) - [⟨0⟩, l, p, ⟨0⟩, sz, ⟨0⟩, base, len, l, p, len, fp, ret, sel] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨380⟩ : UInt256) - [⟨2353⟩, p, p, ⟨381⟩, ⟨0⟩, sz, ⟨0⟩, base, len, l, p, len, fp, ret, sel] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, by - simpa [attester_add_mul_zero_right, attester_pc363_after_inner_setup] using - (evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨363⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨364⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨365⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨366⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mul (by attester_decode_at v, ⟨368⟩, 0x02, .MUL) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨369⟩, 0x81, .DUP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨370⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨371⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨381⟩ (by attester_decode_at v, ⟨372⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨375⟩, 0x91, .SWAP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨376⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨2353⟩ (by attester_decode_at v, ⟨377⟩, 0x61, (.Push .PUSH2)) (by evm_ov)])⟩ - -theorem attesterX_multiRevokeFirstInnerArrayDecoderEntry - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {l p sz base len fp ret sel : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨363⟩ : UInt256) - [⟨0⟩, l, p, ⟨0⟩, sz, ⟨0⟩, base, len, l, p, len, fp, ret, sel] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2353⟩ : UInt256) - [p, p, ⟨381⟩, ⟨0⟩, sz, ⟨0⟩, base, len, l, p, len, fp, ret, sel] - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd0⟩ := - attesterX_multiRevokeFirstInnerArrayDecoderSetup - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (l := l) (p := p) (sz := sz) (base := base) (len := len) - (fp := fp) (ret := ret) (sel := sel) - (mem := mem) (aw := aw) (k := k) (C := C) hreach - exact ⟨_, _, evm_run rd0 with [ - raw jump (by attester_decode_at v, ⟨380⟩, 0x56, .JUMP) - (attesterInnerArrayDecoderJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeFirstInnerArrayDecoderEntryFromOuterSecond - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨363⟩ : UInt256) - [⟨0⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2353⟩ : UInt256) - [(UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - have hsetup : ∃ k0 C0, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨380⟩ : UInt256) - [⟨2353⟩, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k0 C0 := by - exact ⟨_, _, by - simpa [attester_add_mul_zero_right, attester_pc363_after_inner_setup] using - (evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨363⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨364⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨365⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨366⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mul (by attester_decode_at v, ⟨368⟩, 0x02, .MUL) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨369⟩, 0x81, .DUP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨370⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨371⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨381⟩ (by attester_decode_at v, ⟨372⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨375⟩, 0x91, .SWAP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨376⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨2353⟩ (by attester_decode_at v, ⟨377⟩, 0x61, (.Push .PUSH2)) (by evm_ov)])⟩ - obtain ⟨k0, C0, rd0⟩ := hsetup - exact ⟨_, _, evm_run rd0 with [ - raw jump (by attester_decode_at v, ⟨380⟩, 0x56, .JUMP) - (attesterInnerArrayDecoderJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeFirstInnerArrayOffsetOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hslt : - UInt256.slt (attesterFirstInnerArrayOffsetWord I) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2353⟩ : UInt256) - [attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2374⟩ : UInt256) - [attesterFirstInnerArrayOffsetWord I, ⟨0⟩, ⟨0⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2353⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2354⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2355⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2356⟩, 0x83, .DUP4) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2357⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw push1 ⟨30⟩ (by attester_decode_at v, ⟨2358⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw not (by attester_decode_at v, ⟨2360⟩, 0x19, .NOT) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2361⟩, 0x84, .DUP5) (by evm_ov), - raw calldatasize (by attester_decode_at v, ⟨2362⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2363⟩, 0x03, .SUB) (by evm_ov), - raw add (by attester_decode_at v, ⟨2364⟩, 0x01, .ADD) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2365⟩, 0x81, .DUP2) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2366⟩, 0x12, .SLT) (by evm_ov), - raw push2 ⟨2374⟩ (by attester_decode_at v, ⟨2367⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2370⟩, 0x57, .JUMPI) - (by - change UInt256.slt (attesterFirstInnerArrayOffsetWord I) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)) - (UInt256.lnot (⟨30⟩ : UInt256))) ≠ ⟨0⟩ - rw [hslt] - decide) - (attesterInnerArrayOffsetOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeFirstInnerArrayLengthMaxOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hgt : - UInt256.gt (attesterFirstInnerArrayLengthWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2374⟩ : UInt256) - [attesterFirstInnerArrayOffsetWord I, ⟨0⟩, ⟨0⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2399⟩ : UInt256) - [attesterFirstInnerArrayStartWord I, - attesterFirstInnerArrayLengthWord I, - ⟨0⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2374⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2375⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2376⟩, 0x01, .ADD) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2377⟩, 0x80, .DUP1) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2378⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2379⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2380⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2381⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2383⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2385⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2387⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2388⟩, 0x03, .SUB) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2389⟩, 0x82, .DUP3) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2390⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2391⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2399⟩ (by attester_decode_at v, ⟨2392⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2395⟩, 0x57, .JUMPI) - (by - change UInt256.isZero - (UInt256.gt (attesterFirstInnerArrayLengthWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) ≠ ⟨0⟩ - rw [hgt] - decide) - (attesterInnerArrayLengthOkJumpdest v) (by evm_ov)]⟩ - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeFirstInnerArrayPayloadSetup - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2399⟩ : UInt256) - [attesterFirstInnerArrayStartWord I, - attesterFirstInnerArrayLengthWord I, - ⟨0⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2405⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, by - simpa [attester_first_inner_start_add32_comm] using - (evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2399⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2400⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨2402⟩, 0x01, .ADD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2403⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2404⟩, 0x50, .POP) (by evm_ov)])⟩ - -theorem attesterX_multiRevokeFirstInnerArrayPayloadGuardOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hsgt : - UInt256.sgt (attesterFirstInnerArrayStartWord I + ⟨32⟩) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft (attesterFirstInnerArrayLengthWord I) ⟨5⟩)) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2405⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2102⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw push1 ⟨5⟩ (by attester_decode_at v, ⟨2405⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2407⟩, 0x81, .DUP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2408⟩, 0x90, .SWAP1) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2409⟩, 0x1b, .SHL) (by evm_ov), - raw calldatasize (by attester_decode_at v, ⟨2410⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2411⟩, 0x03, .SUB) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2412⟩, 0x82, .DUP3) (by evm_ov), - raw sgt (by attester_decode_at v, ⟨2413⟩, 0x13, .SGT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2414⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2102⟩ (by attester_decode_at v, ⟨2415⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2418⟩, 0x57, .JUMPI) - (by - rw [hsgt] - decide) - (attesterDynamicArrayPayloadOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeFirstInnerArrayReturn - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2102⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨381⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2102⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2103⟩, 0x92, .SWAP3) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2104⟩, 0x50, .POP) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2105⟩, 0x92, .SWAP3) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2106⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2107⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨2108⟩, 0x56, .JUMP) - (attesterMultiRevokeInnerArrayReturnJumpdest v) (by evm_ov)]⟩ - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeFirstInnerArrayPayloadOkToReturn - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hsgt : - UInt256.sgt (attesterFirstInnerArrayStartWord I + ⟨32⟩) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft (attesterFirstInnerArrayLengthWord I) ⟨5⟩)) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2399⟩ : UInt256) - [attesterFirstInnerArrayStartWord I, - attesterFirstInnerArrayLengthWord I, - ⟨0⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨381⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd2405⟩ := - attesterX_multiRevokeFirstInnerArrayPayloadSetup - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (mem := mem) (aw := aw) (k := k) (C := C) hreach - obtain ⟨k1, C1, rd2102⟩ := - attesterX_multiRevokeFirstInnerArrayPayloadGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hsgt - (mem := mem) (aw := aw) (k := k0) (C := C0) rd2405 - exact attesterX_multiRevokeFirstInnerArrayReturn - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (mem := mem) (aw := aw) (k := k1) (C := C1) rd2102 - -theorem attesterX_multiRevokeFirstInnerArrayReturnCleanup - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨381⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨387⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨381⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨382⟩, 0x90, .SWAP1) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨383⟩, 0x92, .SWAP3) (by evm_ov), - raw pop (by attester_decode_at v, ⟨384⟩, 0x50, .POP) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨385⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨386⟩, 0x50, .POP) (by evm_ov)]⟩ - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeFirstInnerArrayLengthZeroReverts - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hlenZero : attesterFirstInnerArrayLengthWord I = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨381⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨k0, C0, rd3870⟩ := - attesterX_multiRevokeFirstInnerArrayReturnCleanup - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (mem := mem) (aw := aw) (k := k) (C := C) hreach - let len := attesterFirstInnerArrayLengthWord I - let payload := attesterFirstInnerArrayStartWord I + ⟨32⟩ - let tail := - [attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - have rd387 : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨387⟩ : UInt256) - (len :: payload :: ⟨0⟩ :: ⟨128⟩ :: tail) - mem aw ByteArray.empty (cA, σ) k0 C0 := by - simpa [len, payload, tail] using rd3870 - let free := - if (⟨64⟩ : UInt256).toNat ≥ mem.size ∨ (⟨64⟩ : UInt256) ≥ aw * ⟨32⟩ then - (⟨0⟩ : UInt256) - else - UInt256.ofNat (fromByteArrayBigEndian (mem.readWithPadding (⟨64⟩ : UInt256).toNat 32)) - let aw1 := UInt256.ofNat (MachineState.M aw.toNat (⟨64⟩ : UInt256).toNat 32) - let selector := UInt256.shiftLeft (⟨3036299187⟩ : UInt256) ⟨224⟩ - let mem1 := selector.toByteArray.write 0 mem free.toNat 32 - let aw2 := UInt256.ofNat (MachineState.M aw1.toNat free.toNat 32) - let freeAfter := - if (⟨64⟩ : UInt256).toNat ≥ mem1.size ∨ (⟨64⟩ : UInt256) ≥ aw2 * ⟨32⟩ then - (⟨0⟩ : UInt256) - else - UInt256.ofNat (fromByteArrayBigEndian (mem1.readWithPadding (⟨64⟩ : UInt256).toNat 32)) - let aw3 := UInt256.ofNat (MachineState.M aw2.toNat (⟨64⟩ : UInt256).toNat 32) - let revLen := UInt256.sub ((⟨4⟩ : UInt256) + free) freeAfter - let revAw := UInt256.ofNat (MachineState.M aw3.toNat freeAfter.toNat revLen.toNat) - have hcostMload64 : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - (⟨64⟩ : UInt256) :: len :: len :: payload :: ⟨0⟩ :: ⟨128⟩ :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostMstoreSelector : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - free :: selector :: free :: len :: len :: payload :: ⟨0⟩ :: ⟨128⟩ :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostMload64After : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - (⟨64⟩ : UInt256) :: ((⟨4⟩ : UInt256) + free) :: len :: len :: - payload :: ⟨0⟩ :: ⟨128⟩ :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostRevert : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - freeAfter :: revLen :: len :: len :: payload :: ⟨0⟩ :: ⟨128⟩ :: tail → - memoryExpansionCost s .REVERT = Cₘ revAw - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero, List.getElem!_cons_succ] - rfl - exact evm_run rd387 with [ - raw dup1 (by attester_decode_at v, ⟨387⟩, 0x80, .DUP1) (by simp [tail]), - raw push0 (by attester_decode_at v, ⟨388⟩, 0x5f, .PUSH0) (by simp [tail]), - raw dup2 (by attester_decode_at v, ⟨389⟩, 0x81, .DUP2) (by simp [tail]), - raw swap1 (by attester_decode_at v, ⟨390⟩, 0x90, .SWAP1) (by simp [tail]), - raw sub (by attester_decode_at v, ⟨391⟩, 0x03, .SUB) (by simp [tail]), - raw push2 ⟨420⟩ (by attester_decode_at v, ⟨392⟩, 0x61, (.Push .PUSH2)) - (by simp [tail]), - raw jumpiNT (by attester_decode_at v, ⟨395⟩, 0x57, .JUMPI) - (by - rw [show len = (⟨0⟩ : UInt256) by simpa [len] using hlenZero] - native_decide) - (by simp [tail]), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨396⟩, 0x60, (.Push .PUSH1)) - (by simp [tail]), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨398⟩, 0x51, .MLOAD) - hcostMload64 (by rfl) (by rfl) (by simp [tail]), - raw push4 ⟨3036299187⟩ (by attester_decode_at v, ⟨399⟩, 0x63, (.Push .PUSH4)) - (by simp [tail]), - raw push1 ⟨224⟩ (by attester_decode_at v, ⟨404⟩, 0x60, (.Push .PUSH1)) - (by simp [tail]), - raw shl (by attester_decode_at v, ⟨406⟩, 0x1b, .SHL) (by simp [tail]), - raw dup2 (by attester_decode_at v, ⟨407⟩, 0x81, .DUP2) (by simp [tail]), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨408⟩, 0x52, .MSTORE) - hcostMstoreSelector (by rfl) (by rfl) (by simp [tail]), - raw push1 ⟨4⟩ (by attester_decode_at v, ⟨409⟩, 0x60, (.Push .PUSH1)) - (by simp [tail]), - raw add (by attester_decode_at v, ⟨411⟩, 0x01, .ADD) (by simp [tail]), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨412⟩, 0x60, (.Push .PUSH1)) - (by simp [tail]), - raw mload (Cₘ aw3 - Cₘ aw2) freeAfter aw3 - (by attester_decode_at v, ⟨414⟩, 0x51, .MLOAD) - hcostMload64After (by rfl) (by rfl) (by simp [tail]), - raw dup1 (by attester_decode_at v, ⟨415⟩, 0x80, .DUP1) (by simp [tail]), - raw swap2 (by attester_decode_at v, ⟨416⟩, 0x91, .SWAP2) (by simp [tail]), - raw sub (by attester_decode_at v, ⟨417⟩, 0x03, .SUB) (by simp [tail]), - raw swap1 (by attester_decode_at v, ⟨418⟩, 0x90, .SWAP1) (by simp [tail]), - raw rev (Cₘ revAw - Cₘ aw3) - (by attester_decode_at v, ⟨419⟩, 0xfd, .REVERT) - hcostRevert (by simp [tail])] - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeFirstInnerArrayNonemptyGuardOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hlenNe : attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨387⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨420⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - have rd388 := RD.dup1 hreach - (by attester_decode_at v, ⟨387⟩, 0x80, .DUP1) (by evm_ov) - have rd389 := RD.push0 rd388 - (by attester_decode_at v, ⟨388⟩, 0x5f, .PUSH0) (by evm_ov) - have rd390 := RD.dup2 rd389 - (by attester_decode_at v, ⟨389⟩, 0x81, .DUP2) (by evm_ov) - have rd391 := RD.swap1 rd390 - (by attester_decode_at v, ⟨390⟩, 0x90, .SWAP1) (by evm_ov) - have rd392 := RD.sub rd391 - (by attester_decode_at v, ⟨391⟩, 0x03, .SUB) (by evm_ov) - have rd395 := RD.push2 rd392 ⟨420⟩ - (by attester_decode_at v, ⟨392⟩, 0x61, (.Push .PUSH2)) (by evm_ov) - have hcond : - UInt256.sub (⟨0⟩ : UInt256) (attesterFirstInnerArrayLengthWord I) ≠ ⟨0⟩ := - u256_zero_sub_ne_zero hlenNe - have rd420 := RD.jumpiT rd395 - (by attester_decode_at v, ⟨395⟩, 0x57, .JUMPI) - hcond (attesterMultiRevokeInnerNonemptyOkJumpdest v) (by evm_ov) - exact ⟨_, _, by simpa using rd420⟩ - -theorem attesterX_multiRevokeFirstInnerArrayNonemptyOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hlenNe : attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨381⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨420⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd387⟩ := - attesterX_multiRevokeFirstInnerArrayReturnCleanup - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (mem := mem) (aw := aw) (k := k) (C := C) hreach - exact attesterX_multiRevokeFirstInnerArrayNonemptyGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hlenNe - (mem := mem) (aw := aw) (k := k0) (C := C0) rd387 - -theorem attesterX_multiRevokeFirstInnerArrayLengthAllocMaxOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hgt : - UInt256.gt (attesterFirstInnerArrayLengthWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨420⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨445⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, ⟨0⟩, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨420⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨421⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨422⟩, 0x81, .DUP2) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨423⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨425⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨427⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨429⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨430⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨431⟩, 0x81, .DUP2) (by evm_ov), - raw gt (by attester_decode_at v, ⟨432⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨433⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨445⟩ (by attester_decode_at v, ⟨434⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨437⟩, 0x57, .JUMPI) - (by - rw [hgt] - decide) - (attesterMultiRevokeInnerLengthMaxOkJumpdest v) (by evm_ov)]⟩ - -abbrev attesterInnerArrayAllocFreeWord (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMloadWord mem aw ⟨64⟩ - -abbrev attesterInnerArrayAllocAwAfterMload (aw : UInt256) : UInt256 := - attesterMloadAw aw ⟨64⟩ - -abbrev attesterInnerArrayAllocLenMem - (len : UInt256) (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray len).write 0 mem - (attesterInnerArrayAllocFreeWord mem aw).toNat 32 - -abbrev attesterInnerArrayAllocLenAw - (_len : UInt256) (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterInnerArrayAllocAwAfterMload aw).toNat - (attesterInnerArrayAllocFreeWord mem aw).toNat 32) - -abbrev attesterInnerArrayAllocEndWord - (len : UInt256) (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterInnerArrayAllocFreeWord mem aw + - ((⟨32⟩ : UInt256) + UInt256.mul (⟨32⟩ : UInt256) len) - -abbrev attesterInnerArrayAllocMem - (len : UInt256) (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (attesterInnerArrayAllocEndWord len mem aw)).write 0 - (attesterInnerArrayAllocLenMem len mem aw) 64 32 - -abbrev attesterInnerArrayAllocAw - (len : UInt256) (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterInnerArrayAllocLenAw len mem aw).toNat 64 32) - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeFirstInnerArrayAllocToInitLoop - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {len payload : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hlenNe : len ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨445⟩ : UInt256) - (len :: ⟨0⟩ :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - (((⟨32⟩ : UInt256) + attesterInnerArrayAllocFreeWord mem aw) :: - len :: attesterInnerArrayAllocFreeWord mem aw :: ⟨0⟩ :: len :: len :: payload :: tail) - (attesterInnerArrayAllocMem len mem aw) - (attesterInnerArrayAllocAw len mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterInnerArrayAllocFreeWord mem aw - let aw1 := attesterInnerArrayAllocAwAfterMload aw - let mem1 := attesterInnerArrayAllocLenMem len mem aw - let aw2 := attesterInnerArrayAllocLenAw len mem aw - let endWord := attesterInnerArrayAllocEndWord len mem aw - let mem2 := attesterInnerArrayAllocMem len mem aw - let aw3 := attesterInnerArrayAllocAw len mem aw - have hcostMload : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - (⟨64⟩ : UInt256) :: len :: ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreLen : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - free :: len :: len :: free :: ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreFreePtr : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - (⟨64⟩ : UInt256) :: endWord :: len :: free :: ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, endWord, mem2, aw3] using - evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨445⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨446⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨448⟩, 0x51, .MLOAD) - hcostMload (by rfl) (by rfl) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨449⟩, 0x90, .SWAP1) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨450⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨451⟩, 0x82, .DUP3) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨452⟩, 0x52, .MSTORE) - hcostStoreLen (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨453⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨454⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mul (by attester_decode_at v, ⟨456⟩, 0x02, .MUL) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨457⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨459⟩, 0x01, .ADD) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨460⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨461⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨462⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨464⟩, 0x52, .MSTORE) - hcostStoreFreePtr (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨465⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨466⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨513⟩ (by attester_decode_at v, ⟨467⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨470⟩, 0x57, .JUMPI) - (isZero_eq_zero_of_ne hlenNe) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨471⟩, 0x81, .DUP2) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨472⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨474⟩, 0x01, .ADD) (by evm_ov)]⟩ - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiAttestFirstInnerArrayAllocToInitLoop - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {len payload : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hlenNe : len ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1083⟩ : UInt256) - (len :: ⟨0⟩ :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1113⟩ : UInt256) - (((⟨32⟩ : UInt256) + attesterInnerArrayAllocFreeWord mem aw) :: - len :: attesterInnerArrayAllocFreeWord mem aw :: ⟨0⟩ :: len :: len :: payload :: tail) - (attesterInnerArrayAllocMem len mem aw) - (attesterInnerArrayAllocAw len mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterInnerArrayAllocFreeWord mem aw - let aw1 := attesterInnerArrayAllocAwAfterMload aw - let mem1 := attesterInnerArrayAllocLenMem len mem aw - let aw2 := attesterInnerArrayAllocLenAw len mem aw - let endWord := attesterInnerArrayAllocEndWord len mem aw - let mem2 := attesterInnerArrayAllocMem len mem aw - let aw3 := attesterInnerArrayAllocAw len mem aw - have hcostMload : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - (⟨64⟩ : UInt256) :: len :: ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreLen : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - free :: len :: len :: free :: ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreFreePtr : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - (⟨64⟩ : UInt256) :: endWord :: len :: free :: ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, endWord, mem2, aw3] using - evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨1083⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1084⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨1086⟩, 0x51, .MLOAD) - hcostMload (by rfl) (by rfl) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1087⟩, 0x90, .SWAP1) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1088⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1089⟩, 0x82, .DUP3) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨1090⟩, 0x52, .MSTORE) - hcostStoreLen (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1091⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1092⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mul (by attester_decode_at v, ⟨1094⟩, 0x02, .MUL) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1095⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1097⟩, 0x01, .ADD) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1098⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨1099⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1100⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨1102⟩, 0x52, .MSTORE) - hcostStoreFreePtr (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1103⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨1104⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨1176⟩ (by attester_decode_at v, ⟨1105⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨1108⟩, 0x57, .JUMPI) - (isZero_eq_zero_of_ne hlenNe) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1109⟩, 0x81, .DUP2) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1110⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1112⟩, 0x01, .ADD) (by evm_ov)]⟩ - -set_option maxHeartbeats 3000000 in -theorem attesterX_multiRevokeFirstInnerArrayAllocProgress - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (hlenNe : attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩) - (hprogress : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨445⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, ⟨0⟩, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C) : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - (((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) :: - attesterFirstInnerArrayLengthWord I :: - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') :: - ⟨0⟩ :: - attesterFirstInnerArrayLengthWord I :: - attesterFirstInnerArrayLengthWord I :: - (attesterFirstInnerArrayStartWord I + ⟨32⟩) :: - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I]) - (attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ByteArray.empty (cA, σ) k C := by - obtain ⟨a', k0, C0, hrem, rd0⟩ := hprogress - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokeFirstInnerArrayAllocToInitLoop - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (len := attesterFirstInnerArrayLengthWord I) - (payload := attesterFirstInnerArrayStartWord I + ⟨32⟩) - (tail := [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I]) - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) (by simp) hlenNe rd0 - exact ⟨a', k1, C1, hrem, rd1⟩ - -set_option maxHeartbeats 3000000 in -theorem attesterX_multiAttestFirstInnerArrayAllocProgress - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (hlenNe : attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩) - (hprogress : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1083⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, ⟨0⟩, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C) : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1113⟩ : UInt256) - (((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) :: - attesterFirstInnerArrayLengthWord I :: - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') :: - ⟨0⟩ :: - attesterFirstInnerArrayLengthWord I :: - attesterFirstInnerArrayLengthWord I :: - (attesterFirstInnerArrayStartWord I + ⟨32⟩) :: - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I]) - (attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ByteArray.empty (cA, σ) k C := by - obtain ⟨a', k0, C0, hrem, rd0⟩ := hprogress - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiAttestFirstInnerArrayAllocToInitLoop - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (len := attesterFirstInnerArrayLengthWord I) - (payload := attesterFirstInnerArrayStartWord I + ⟨32⟩) - (tail := [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I]) - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) (by simp) hlenNe rd0 - exact ⟨a', k1, C1, hrem, rd1⟩ - -theorem attesterX_multiAttestFirstInnerArrayDecoderSetup - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {l p sz base len tag fp ret sel : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1001⟩ : UInt256) - [⟨0⟩, l, p, ⟨0⟩, sz, ⟨0⟩, base, len, tag, l, p, len, fp, ret, sel] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1018⟩ : UInt256) - [⟨2353⟩, p, p, ⟨1019⟩, ⟨0⟩, sz, ⟨0⟩, base, len, tag, l, p, len, fp, ret, sel] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, by - simpa [attester_add_mul_zero_right, attester_pc1001_after_inner_setup] using - (evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨1001⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1002⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1003⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1004⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mul (by attester_decode_at v, ⟨1006⟩, 0x02, .MUL) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1007⟩, 0x81, .DUP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨1008⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1009⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨1019⟩ (by attester_decode_at v, ⟨1010⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨1013⟩, 0x91, .SWAP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1014⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨2353⟩ (by attester_decode_at v, ⟨1015⟩, 0x61, (.Push .PUSH2)) (by evm_ov)])⟩ - -theorem attesterX_multiAttestFirstInnerArrayDecoderEntry - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {l p sz base len tag fp ret sel : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1001⟩ : UInt256) - [⟨0⟩, l, p, ⟨0⟩, sz, ⟨0⟩, base, len, tag, l, p, len, fp, ret, sel] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2353⟩ : UInt256) - [p, p, ⟨1019⟩, ⟨0⟩, sz, ⟨0⟩, base, len, tag, l, p, len, fp, ret, sel] - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd0⟩ := - attesterX_multiAttestFirstInnerArrayDecoderSetup - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (l := l) (p := p) (sz := sz) (base := base) (len := len) - (tag := tag) (fp := fp) (ret := ret) (sel := sel) - (mem := mem) (aw := aw) (k := k) (C := C) hreach - exact ⟨_, _, evm_run rd0 with [ - raw jump (by attester_decode_at v, ⟨1018⟩, 0x56, .JUMP) - (attesterInnerArrayDecoderJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiAttestFirstInnerArrayDecoderEntryFromOuterSecond - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1001⟩ : UInt256) - [⟨0⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2353⟩ : UInt256) - [(UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨1019⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - have hsetup : ∃ k0 C0, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1018⟩ : UInt256) - [⟨2353⟩, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨1019⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k0 C0 := by - exact ⟨_, _, by - simpa [attester_add_mul_zero_right, attester_pc1001_after_inner_setup] using - (evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨1001⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1002⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1003⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1004⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mul (by attester_decode_at v, ⟨1006⟩, 0x02, .MUL) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1007⟩, 0x81, .DUP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨1008⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1009⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨1019⟩ (by attester_decode_at v, ⟨1010⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨1013⟩, 0x91, .SWAP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1014⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨2353⟩ (by attester_decode_at v, ⟨1015⟩, 0x61, (.Push .PUSH2)) (by evm_ov)])⟩ - obtain ⟨k0, C0, rd0⟩ := hsetup - exact ⟨_, _, evm_run rd0 with [ - raw jump (by attester_decode_at v, ⟨1018⟩, 0x56, .JUMP) - (attesterInnerArrayDecoderJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiAttestFirstInnerArrayOffsetOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hslt : - UInt256.slt (attesterFirstInnerArrayOffsetWord I) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2353⟩ : UInt256) - [attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨1019⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2374⟩ : UInt256) - [attesterFirstInnerArrayOffsetWord I, ⟨0⟩, ⟨0⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨1019⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2353⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2354⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2355⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2356⟩, 0x83, .DUP4) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2357⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw push1 ⟨30⟩ (by attester_decode_at v, ⟨2358⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw not (by attester_decode_at v, ⟨2360⟩, 0x19, .NOT) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2361⟩, 0x84, .DUP5) (by evm_ov), - raw calldatasize (by attester_decode_at v, ⟨2362⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2363⟩, 0x03, .SUB) (by evm_ov), - raw add (by attester_decode_at v, ⟨2364⟩, 0x01, .ADD) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2365⟩, 0x81, .DUP2) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2366⟩, 0x12, .SLT) (by evm_ov), - raw push2 ⟨2374⟩ (by attester_decode_at v, ⟨2367⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2370⟩, 0x57, .JUMPI) - (by - change UInt256.slt (attesterFirstInnerArrayOffsetWord I) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)) - (UInt256.lnot (⟨30⟩ : UInt256))) ≠ ⟨0⟩ - rw [hslt] - decide) - (attesterInnerArrayOffsetOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiAttestFirstInnerArrayLengthMaxOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hgt : - UInt256.gt (attesterFirstInnerArrayLengthWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2374⟩ : UInt256) - [attesterFirstInnerArrayOffsetWord I, ⟨0⟩, ⟨0⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨1019⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2399⟩ : UInt256) - [attesterFirstInnerArrayStartWord I, - attesterFirstInnerArrayLengthWord I, - ⟨0⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨1019⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2374⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2375⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2376⟩, 0x01, .ADD) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2377⟩, 0x80, .DUP1) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2378⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2379⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2380⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2381⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2383⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2385⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2387⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2388⟩, 0x03, .SUB) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2389⟩, 0x82, .DUP3) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2390⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2391⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2399⟩ (by attester_decode_at v, ⟨2392⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2395⟩, 0x57, .JUMPI) - (by - change UInt256.isZero - (UInt256.gt (attesterFirstInnerArrayLengthWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) ≠ ⟨0⟩ - rw [hgt] - decide) - (attesterInnerArrayLengthOkJumpdest v) (by evm_ov)]⟩ - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiAttestFirstInnerArrayPayloadSetup - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2399⟩ : UInt256) - [attesterFirstInnerArrayStartWord I, - attesterFirstInnerArrayLengthWord I, - ⟨0⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨1019⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2405⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨1019⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, by - simpa [attester_first_inner_start_add32_comm] using - (evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2399⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2400⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨2402⟩, 0x01, .ADD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2403⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2404⟩, 0x50, .POP) (by evm_ov)])⟩ - -theorem attesterX_multiAttestFirstInnerArrayPayloadGuardOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hsgt : - UInt256.sgt (attesterFirstInnerArrayStartWord I + ⟨32⟩) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft (attesterFirstInnerArrayLengthWord I) ⟨5⟩)) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2405⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨1019⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2102⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨1019⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw push1 ⟨5⟩ (by attester_decode_at v, ⟨2405⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2407⟩, 0x81, .DUP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2408⟩, 0x90, .SWAP1) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2409⟩, 0x1b, .SHL) (by evm_ov), - raw calldatasize (by attester_decode_at v, ⟨2410⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2411⟩, 0x03, .SUB) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2412⟩, 0x82, .DUP3) (by evm_ov), - raw sgt (by attester_decode_at v, ⟨2413⟩, 0x13, .SGT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2414⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2102⟩ (by attester_decode_at v, ⟨2415⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2418⟩, 0x57, .JUMPI) - (by - rw [hsgt] - decide) - (attesterDynamicArrayPayloadOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiAttestFirstInnerArrayReturn - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2102⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨1019⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1019⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2102⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2103⟩, 0x92, .SWAP3) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2104⟩, 0x50, .POP) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2105⟩, 0x92, .SWAP3) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2106⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2107⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨2108⟩, 0x56, .JUMP) - (attesterMultiAttestInnerArrayReturnJumpdest v) (by evm_ov)]⟩ - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiAttestFirstInnerArrayPayloadOkToReturn - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hsgt : - UInt256.sgt (attesterFirstInnerArrayStartWord I + ⟨32⟩) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft (attesterFirstInnerArrayLengthWord I) ⟨5⟩)) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2399⟩ : UInt256) - [attesterFirstInnerArrayStartWord I, - attesterFirstInnerArrayLengthWord I, - ⟨0⟩, - attesterSecondArrayPayloadStartWord I, - attesterSecondArrayPayloadStartWord I, - ⟨1019⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1019⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd2405⟩ := - attesterX_multiAttestFirstInnerArrayPayloadSetup - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (mem := mem) (aw := aw) (k := k) (C := C) hreach - obtain ⟨k1, C1, rd2102⟩ := - attesterX_multiAttestFirstInnerArrayPayloadGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hsgt - (mem := mem) (aw := aw) (k := k0) (C := C0) rd2405 - exact attesterX_multiAttestFirstInnerArrayReturn - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (mem := mem) (aw := aw) (k := k1) (C := C1) rd2102 - -theorem attesterX_multiAttestFirstInnerArrayReturnCleanup - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1019⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1025⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨1019⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1020⟩, 0x90, .SWAP1) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨1021⟩, 0x92, .SWAP3) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1022⟩, 0x50, .POP) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1023⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1024⟩, 0x50, .POP) (by evm_ov)]⟩ - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiAttestFirstInnerArrayLengthZeroReverts - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hlenZero : attesterFirstInnerArrayLengthWord I = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1019⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨k0, C0, rd1025_0⟩ := - attesterX_multiAttestFirstInnerArrayReturnCleanup - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (mem := mem) (aw := aw) (k := k) (C := C) hreach - let len := attesterFirstInnerArrayLengthWord I - let payload := attesterFirstInnerArrayStartWord I + ⟨32⟩ - let tail := - [attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - have rd1025 : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1025⟩ : UInt256) - (len :: payload :: ⟨0⟩ :: ⟨128⟩ :: tail) - mem aw ByteArray.empty (cA, σ) k0 C0 := by - simpa [len, payload, tail] using rd1025_0 - let free := - if (⟨64⟩ : UInt256).toNat ≥ mem.size ∨ (⟨64⟩ : UInt256) ≥ aw * ⟨32⟩ then - (⟨0⟩ : UInt256) - else - UInt256.ofNat (fromByteArrayBigEndian (mem.readWithPadding (⟨64⟩ : UInt256).toNat 32)) - let aw1 := UInt256.ofNat (MachineState.M aw.toNat (⟨64⟩ : UInt256).toNat 32) - let selector := UInt256.shiftLeft (⟨3036299187⟩ : UInt256) ⟨224⟩ - let mem1 := selector.toByteArray.write 0 mem free.toNat 32 - let aw2 := UInt256.ofNat (MachineState.M aw1.toNat free.toNat 32) - let freeAfter := - if (⟨64⟩ : UInt256).toNat ≥ mem1.size ∨ (⟨64⟩ : UInt256) ≥ aw2 * ⟨32⟩ then - (⟨0⟩ : UInt256) - else - UInt256.ofNat (fromByteArrayBigEndian (mem1.readWithPadding (⟨64⟩ : UInt256).toNat 32)) - let aw3 := UInt256.ofNat (MachineState.M aw2.toNat (⟨64⟩ : UInt256).toNat 32) - let revLen := UInt256.sub ((⟨4⟩ : UInt256) + free) freeAfter - let revAw := UInt256.ofNat (MachineState.M aw3.toNat freeAfter.toNat revLen.toNat) - have hcostMload64 : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - (⟨64⟩ : UInt256) :: len :: len :: payload :: ⟨0⟩ :: ⟨128⟩ :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostMstoreSelector : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - free :: selector :: free :: len :: len :: payload :: ⟨0⟩ :: ⟨128⟩ :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostMload64After : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - (⟨64⟩ : UInt256) :: ((⟨4⟩ : UInt256) + free) :: len :: len :: - payload :: ⟨0⟩ :: ⟨128⟩ :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostRevert : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - freeAfter :: revLen :: len :: len :: payload :: ⟨0⟩ :: ⟨128⟩ :: tail → - memoryExpansionCost s .REVERT = Cₘ revAw - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero, List.getElem!_cons_succ] - rfl - exact evm_run rd1025 with [ - raw dup1 (by attester_decode_at v, ⟨1025⟩, 0x80, .DUP1) (by simp [tail]), - raw push0 (by attester_decode_at v, ⟨1026⟩, 0x5f, .PUSH0) (by simp [tail]), - raw dup2 (by attester_decode_at v, ⟨1027⟩, 0x81, .DUP2) (by simp [tail]), - raw swap1 (by attester_decode_at v, ⟨1028⟩, 0x90, .SWAP1) (by simp [tail]), - raw sub (by attester_decode_at v, ⟨1029⟩, 0x03, .SUB) (by simp [tail]), - raw push2 ⟨1058⟩ (by attester_decode_at v, ⟨1030⟩, 0x61, (.Push .PUSH2)) - (by simp [tail]), - raw jumpiNT (by attester_decode_at v, ⟨1033⟩, 0x57, .JUMPI) - (by - rw [show len = (⟨0⟩ : UInt256) by simpa [len] using hlenZero] - native_decide) - (by simp [tail]), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1034⟩, 0x60, (.Push .PUSH1)) - (by simp [tail]), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨1036⟩, 0x51, .MLOAD) - hcostMload64 (by rfl) (by rfl) (by simp [tail]), - raw push4 ⟨3036299187⟩ (by attester_decode_at v, ⟨1037⟩, 0x63, (.Push .PUSH4)) - (by simp [tail]), - raw push1 ⟨224⟩ (by attester_decode_at v, ⟨1042⟩, 0x60, (.Push .PUSH1)) - (by simp [tail]), - raw shl (by attester_decode_at v, ⟨1044⟩, 0x1b, .SHL) (by simp [tail]), - raw dup2 (by attester_decode_at v, ⟨1045⟩, 0x81, .DUP2) (by simp [tail]), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨1046⟩, 0x52, .MSTORE) - hcostMstoreSelector (by rfl) (by rfl) (by simp [tail]), - raw push1 ⟨4⟩ (by attester_decode_at v, ⟨1047⟩, 0x60, (.Push .PUSH1)) - (by simp [tail]), - raw add (by attester_decode_at v, ⟨1049⟩, 0x01, .ADD) (by simp [tail]), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1050⟩, 0x60, (.Push .PUSH1)) - (by simp [tail]), - raw mload (Cₘ aw3 - Cₘ aw2) freeAfter aw3 - (by attester_decode_at v, ⟨1052⟩, 0x51, .MLOAD) - hcostMload64After (by rfl) (by rfl) (by simp [tail]), - raw dup1 (by attester_decode_at v, ⟨1053⟩, 0x80, .DUP1) (by simp [tail]), - raw swap2 (by attester_decode_at v, ⟨1054⟩, 0x91, .SWAP2) (by simp [tail]), - raw sub (by attester_decode_at v, ⟨1055⟩, 0x03, .SUB) (by simp [tail]), - raw swap1 (by attester_decode_at v, ⟨1056⟩, 0x90, .SWAP1) (by simp [tail]), - raw rev (Cₘ revAw - Cₘ aw3) - (by attester_decode_at v, ⟨1057⟩, 0xfd, .REVERT) - hcostRevert (by simp [tail])] - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiAttestFirstInnerArrayNonemptyGuardOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hlenNe : attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1025⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1058⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - have rd1026 := RD.dup1 hreach - (by attester_decode_at v, ⟨1025⟩, 0x80, .DUP1) (by evm_ov) - have rd1027 := RD.push0 rd1026 - (by attester_decode_at v, ⟨1026⟩, 0x5f, .PUSH0) (by evm_ov) - have rd1028 := RD.dup2 rd1027 - (by attester_decode_at v, ⟨1027⟩, 0x81, .DUP2) (by evm_ov) - have rd1029 := RD.swap1 rd1028 - (by attester_decode_at v, ⟨1028⟩, 0x90, .SWAP1) (by evm_ov) - have rd1030 := RD.sub rd1029 - (by attester_decode_at v, ⟨1029⟩, 0x03, .SUB) (by evm_ov) - have rd1033 := RD.push2 rd1030 ⟨1058⟩ - (by attester_decode_at v, ⟨1030⟩, 0x61, (.Push .PUSH2)) (by evm_ov) - have hcond : - UInt256.sub (⟨0⟩ : UInt256) (attesterFirstInnerArrayLengthWord I) ≠ ⟨0⟩ := - u256_zero_sub_ne_zero hlenNe - have rd1058 := RD.jumpiT rd1033 - (by attester_decode_at v, ⟨1033⟩, 0x57, .JUMPI) - hcond (attesterMultiAttestInnerNonemptyOkJumpdest v) (by evm_ov) - exact ⟨_, _, by simpa using rd1058⟩ - -theorem attesterX_multiAttestFirstInnerArrayNonemptyOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hlenNe : attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1019⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1058⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd1025⟩ := - attesterX_multiAttestFirstInnerArrayReturnCleanup - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (mem := mem) (aw := aw) (k := k) (C := C) hreach - exact attesterX_multiAttestFirstInnerArrayNonemptyGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hlenNe - (mem := mem) (aw := aw) (k := k0) (C := C0) rd1025 - -theorem attesterX_multiAttestFirstInnerArrayLengthAllocMaxOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {mem : ByteArray} {aw : UInt256} {k C} - (hgt : - UInt256.gt (attesterFirstInnerArrayLengthWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1058⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1083⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, ⟨0⟩, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨1058⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨1059⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1060⟩, 0x81, .DUP2) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨1061⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨1063⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1065⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨1067⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨1068⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1069⟩, 0x81, .DUP2) (by evm_ov), - raw gt (by attester_decode_at v, ⟨1070⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨1071⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨1083⟩ (by attester_decode_at v, ⟨1072⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨1075⟩, 0x57, .JUMPI) - (by - rw [hgt] - decide) - (attesterMultiAttestInnerLengthMaxOkJumpdest v) (by evm_ov)]⟩ - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/InnerArrayInit.lean b/Benchmarks/EAS/Attester/InnerArrayInit.lean deleted file mode 100644 index e78d508a..00000000 --- a/Benchmarks/EAS/Attester/InnerArrayInit.lean +++ /dev/null @@ -1,1439 +0,0 @@ -import Benchmarks.EAS.Attester.InnerArrayEVM - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -abbrev attesterMultiRevokeInnerArrayInitSecondZeroWord - (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMultiOuterArrayInitFreeWord mem aw + (⟨32⟩ : UInt256) - -abbrev attesterMultiRevokeInnerArrayInitSecondZeroMem - (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (⟨0⟩ : UInt256)).write 0 - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat 32 - -abbrev attesterMultiRevokeInnerArrayInitSecondZeroAw - (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiOuterArrayInitZeroAw mem aw).toNat - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat 32) - -abbrev attesterMultiRevokeInnerArrayInitStepMem - (slot : UInt256) (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (attesterMultiOuterArrayInitFreeWord mem aw)).write 0 - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw) slot.toNat 32 - -abbrev attesterMultiRevokeInnerArrayInitStepAw - (slot : UInt256) (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiRevokeInnerArrayInitSecondZeroAw mem aw).toNat - slot.toNat 32) - -structure AttesterMultiRevokeInnerArrayInitState where - slot : UInt256 - remaining : UInt256 - mem : ByteArray - aw : UInt256 - -abbrev attesterMultiRevokeInnerArrayInitStack - (I : ExecutionEnv) (base len payload : UInt256) - (a : AttesterMultiRevokeInnerArrayInitState) : List UInt256 := - [a.slot, a.remaining, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - -abbrev attesterMultiRevokeInnerArrayInitExitStack - (I : ExecutionEnv) (base len payload : UInt256) - (_a : AttesterMultiRevokeInnerArrayInitState) : List UInt256 := - [⟨0⟩, base, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - -abbrev attesterMultiRevokeInnerArrayInitStepState - (a : AttesterMultiRevokeInnerArrayInitState) : - AttesterMultiRevokeInnerArrayInitState := - { slot := (⟨32⟩ : UInt256) + a.slot, - remaining := UInt256.sub a.remaining ⟨1⟩, - mem := attesterMultiRevokeInnerArrayInitStepMem a.slot a.mem a.aw, - aw := attesterMultiRevokeInnerArrayInitStepAw a.slot a.mem a.aw } - -abbrev attesterMultiRevokeInnerArrayInitFinalMem - (a : AttesterMultiRevokeInnerArrayInitState) : ByteArray := - attesterMultiRevokeInnerArrayInitStepMem a.slot a.mem a.aw - -abbrev attesterMultiRevokeInnerArrayInitFinalAw - (a : AttesterMultiRevokeInnerArrayInitState) : UInt256 := - attesterMultiRevokeInnerArrayInitStepAw a.slot a.mem a.aw - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeInnerArrayInitFinalIteration - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len payload : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - [slot, (⟨1⟩ : UInt256), base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - [⟨0⟩, base, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiRevokeInnerArrayInitStepMem slot mem aw) - (attesterMultiRevokeInnerArrayInitStepAw slot mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterMultiOuterArrayInitFreeWord mem aw - let aw1 := attesterMultiOuterArrayInitAwAfterMload aw - let mem1 := attesterMultiOuterArrayInitFreeMem mem aw - let aw2 := attesterMultiOuterArrayInitFreeAw aw - let mem2 := attesterMultiOuterArrayInitZeroMem mem aw - let aw3 := attesterMultiOuterArrayInitZeroAw mem aw - let second := attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw - let mem3 := attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw - let aw4 := attesterMultiRevokeInnerArrayInitSecondZeroAw mem aw - let mem4 := attesterMultiRevokeInnerArrayInitStepMem slot mem aw - let aw5 := attesterMultiRevokeInnerArrayInitStepAw slot mem aw - have hcostMload : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - [⟨64⟩, ⟨64⟩, slot, (⟨1⟩ : UInt256), base, ⟨0⟩, - len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStore64 : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - [⟨64⟩, ((⟨64⟩ : UInt256) + free), free, slot, - (⟨1⟩ : UInt256), base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - [free, (⟨0⟩ : UInt256), ⟨0⟩, free, slot, - (⟨1⟩ : UInt256), base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSecondZero : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - [second, (⟨0⟩ : UInt256), free, slot, (⟨1⟩ : UInt256), - base, ⟨0⟩, len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw4 - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSlot : - ∀ s : State, - s.machineState.activeWords = aw4 → - s.machineState.stack = - [slot, free, slot, (⟨1⟩ : UInt256), base, ⟨0⟩, - len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw5 - Cₘ aw4 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hrd497 : ∃ k497 C497, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨497⟩ : UInt256) - [slot, (⟨1⟩ : UInt256), base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem4 aw5 ByteArray.empty (cA, σ) k497 C497 := by - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, second, mem3, aw4, mem4, aw5] using - evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨475⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨476⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨478⟩, 0x80, .DUP1) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨479⟩, 0x51, .MLOAD) - hcostMload (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨480⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨481⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨482⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨483⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨484⟩, 0x91, .SWAP2) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨485⟩, 0x52, .MSTORE) - hcostStore64 (by rfl) (by rfl) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨486⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨487⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨488⟩, 0x82, .DUP3) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨489⟩, 0x52, .MSTORE) - hcostStoreZero (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨490⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨492⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨493⟩, 0x01, .ADD) (by evm_ov), - raw mstore (Cₘ aw4 - Cₘ aw3) mem3 aw4 - (by attester_decode_at v, ⟨494⟩, 0x52, .MSTORE) - hcostStoreSecondZero (by rfl) (by rfl) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨495⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw5 - Cₘ aw4) mem4 aw5 - (by attester_decode_at v, ⟨496⟩, 0x52, .MSTORE) - hcostStoreSlot (by rfl) (by rfl) (by evm_ov)]⟩ - obtain ⟨_, _, rd497⟩ := hrd497 - have hrd511 : ∃ k511 C511, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨511⟩ : UInt256) - [((⟨32⟩ : UInt256) + slot), ⟨0⟩, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem4 aw5 ByteArray.empty (cA, σ) k511 C511 := by - exact ⟨_, _, by - simpa using - evm_run rd497 with [ - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨497⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨499⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨500⟩, 0x90, .SWAP1) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨501⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨503⟩, 0x90, .SWAP1) (by evm_ov), - raw sub (by attester_decode_at v, ⟨504⟩, 0x03, .SUB) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨505⟩, 0x90, .SWAP1) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨506⟩, 0x81, .DUP2) (by evm_ov), - raw push2 ⟨475⟩ (by attester_decode_at v, ⟨507⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨510⟩, 0x57, .JUMPI) - (by native_decide) (by evm_ov)]⟩ - obtain ⟨_, _, rd511⟩ := hrd511 - have rd518 := evm_run rd511 with [ - raw swap1 (by attester_decode_at v, ⟨511⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨512⟩, 0x50, .POP) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨513⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨514⟩, 0x50, .POP) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨515⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨516⟩, 0x50, .POP) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨517⟩, 0x5f, .PUSH0) (by evm_ov)] - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, second, mem3, aw4, mem4, aw5] using rd518⟩ - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeInnerArrayInitNonFinalIteration - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len payload remaining : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hnext : UInt256.sub remaining (⟨1⟩ : UInt256) ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - [slot, remaining, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - [((⟨32⟩ : UInt256) + slot), UInt256.sub remaining ⟨1⟩, - base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiRevokeInnerArrayInitStepMem slot mem aw) - (attesterMultiRevokeInnerArrayInitStepAw slot mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterMultiOuterArrayInitFreeWord mem aw - let aw1 := attesterMultiOuterArrayInitAwAfterMload aw - let mem1 := attesterMultiOuterArrayInitFreeMem mem aw - let aw2 := attesterMultiOuterArrayInitFreeAw aw - let mem2 := attesterMultiOuterArrayInitZeroMem mem aw - let aw3 := attesterMultiOuterArrayInitZeroAw mem aw - let second := attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw - let mem3 := attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw - let aw4 := attesterMultiRevokeInnerArrayInitSecondZeroAw mem aw - let mem4 := attesterMultiRevokeInnerArrayInitStepMem slot mem aw - let aw5 := attesterMultiRevokeInnerArrayInitStepAw slot mem aw - have hcostMload : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - [⟨64⟩, ⟨64⟩, slot, remaining, base, ⟨0⟩, - len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStore64 : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - [⟨64⟩, ((⟨64⟩ : UInt256) + free), free, slot, - remaining, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - [free, (⟨0⟩ : UInt256), ⟨0⟩, free, slot, - remaining, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSecondZero : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - [second, (⟨0⟩ : UInt256), free, slot, remaining, - base, ⟨0⟩, len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw4 - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSlot : - ∀ s : State, - s.machineState.activeWords = aw4 → - s.machineState.stack = - [slot, free, slot, remaining, base, ⟨0⟩, - len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw5 - Cₘ aw4 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hrd497 : ∃ k497 C497, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨497⟩ : UInt256) - [slot, remaining, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem4 aw5 ByteArray.empty (cA, σ) k497 C497 := by - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, second, mem3, aw4, mem4, aw5] using - evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨475⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨476⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨478⟩, 0x80, .DUP1) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨479⟩, 0x51, .MLOAD) - hcostMload (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨480⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨481⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨482⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨483⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨484⟩, 0x91, .SWAP2) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨485⟩, 0x52, .MSTORE) - hcostStore64 (by rfl) (by rfl) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨486⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨487⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨488⟩, 0x82, .DUP3) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨489⟩, 0x52, .MSTORE) - hcostStoreZero (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨490⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨492⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨493⟩, 0x01, .ADD) (by evm_ov), - raw mstore (Cₘ aw4 - Cₘ aw3) mem3 aw4 - (by attester_decode_at v, ⟨494⟩, 0x52, .MSTORE) - hcostStoreSecondZero (by rfl) (by rfl) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨495⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw5 - Cₘ aw4) mem4 aw5 - (by attester_decode_at v, ⟨496⟩, 0x52, .MSTORE) - hcostStoreSlot (by rfl) (by rfl) (by evm_ov)]⟩ - obtain ⟨_, _, rd497⟩ := hrd497 - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, second, mem3, aw4, mem4, aw5] using - evm_run rd497 with [ - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨497⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨499⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨500⟩, 0x90, .SWAP1) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨501⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨503⟩, 0x90, .SWAP1) (by evm_ov), - raw sub (by attester_decode_at v, ⟨504⟩, 0x03, .SUB) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨505⟩, 0x90, .SWAP1) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨506⟩, 0x81, .DUP2) (by evm_ov), - raw push2 ⟨475⟩ (by attester_decode_at v, ⟨507⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨510⟩, 0x57, .JUMPI) - (by simpa using hnext) - (attesterMultiRevokeInnerArrayInitLoopJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeInnerArrayInitLoop - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len payload : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hlenNe : len.toNat ≠ 0) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - [slot, len, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ a' k' C', - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (attesterMultiRevokeInnerArrayInitExitStack I base len payload a') - (attesterMultiRevokeInnerArrayInitFinalMem a') - (attesterMultiRevokeInnerArrayInitFinalAw a') - ByteArray.empty (cA, σ) k' C' := by - let Inv : Nat → AttesterMultiRevokeInnerArrayInitState → Prop := - fun n a => a.remaining = UInt256.ofNat (n + 1) ∧ n + 1 < UInt256.size - let stk := attesterMultiRevokeInnerArrayInitStack I base len payload - let memOf : AttesterMultiRevokeInnerArrayInitState → ByteArray := fun a => a.mem - let awOf : AttesterMultiRevokeInnerArrayInitState → UInt256 := fun a => a.aw - let exitStk := attesterMultiRevokeInnerArrayInitExitStack I base len payload - let exitMem := attesterMultiRevokeInnerArrayInitFinalMem - let exitAw := attesterMultiRevokeInnerArrayInitFinalAw - have hexit : - ∀ a, Inv 0 a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨475⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨518⟩ : UInt256) (exitStk a) (exitMem a) (exitAw a) - ByteArray.empty (cA, σ) k' C' := by - intro a hInv k C rd - have hrem : a.remaining = (⟨1⟩ : UInt256) := by - simpa [Inv] using hInv.1 - exact attesterX_multiRevokeInnerArrayInitFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (payload := payload) (mem := a.mem) (aw := a.aw) - (by - simpa [stk, memOf, awOf, hrem, attesterMultiRevokeInnerArrayInitStack] - using rd) - have hbody : - ∀ n a, Inv (n + 1) a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨475⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ a' k' C', - Inv n a' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨475⟩ : UInt256) (stk a') (memOf a') (awOf a') - ByteArray.empty (cA, σ) k' C' := by - intro n a hInv k C rd - let a' := attesterMultiRevokeInnerArrayInitStepState a - have hsub : - UInt256.sub a.remaining (⟨1⟩ : UInt256) = UInt256.ofNat (n + 1) := by - rw [hInv.1] - simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using - attester_u256_ofNat_succ_sub_one (n := n + 1) - (by simpa [Inv, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using hInv.2) - have hnext : UInt256.sub a.remaining (⟨1⟩ : UInt256) ≠ ⟨0⟩ := by - rw [hsub] - exact attester_u256_ofNat_pos_ne_zero - (n := n + 1) (by omega) (by - have hlt : n + 1 < UInt256.size := by - have := hInv.2 - omega - exact hlt) - obtain ⟨k', C', rd'⟩ := - attesterX_multiRevokeInnerArrayInitNonFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (payload := payload) (remaining := a.remaining) (mem := a.mem) (aw := a.aw) - hnext - (by - simpa [stk, memOf, awOf, attesterMultiRevokeInnerArrayInitStack] - using rd) - refine ⟨a', k', C', ?_, ?_⟩ - · constructor - · simpa [a', attesterMultiRevokeInnerArrayInitStepState] using hsub - · have := hInv.2 - omega - · simpa [a', stk, memOf, awOf, attesterMultiRevokeInnerArrayInitStack, - attesterMultiRevokeInnerArrayInitStepState] using rd' - let a0 : AttesterMultiRevokeInnerArrayInitState := - { slot := slot, remaining := len, mem := mem, aw := aw } - have hInv0 : Inv (len.toNat - 1) a0 := by - constructor - · have hsucc : (len.toNat - 1) + 1 = len.toNat := by omega - simpa [a0, hsucc] using (u256_ofNat_toNat len).symm - · have hsucc : (len.toNat - 1) + 1 = len.toNat := by omega - rw [hsucc] - exact len.val.isLt - obtain ⟨a', k', C', hInvFinal, rdFinal⟩ := - RD.whileLoopCarryExit - (code := patchedRuntime v) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) - (rdata := ByteArray.empty) (acc := (cA, σ)) - (header := (⟨475⟩ : UInt256)) (exit := (⟨518⟩ : UInt256)) - Inv stk memOf awOf exitStk exitMem exitAw hexit hbody - (len.toNat - 1) a0 hInv0 k C - (by - simpa [a0, stk, memOf, awOf, attesterMultiRevokeInnerArrayInitStack] - using hreach) - exact ⟨a', k', C', by simpa [Inv] using hInvFinal.1, rdFinal⟩ - -theorem attesterX_multiRevokeFirstInnerArrayInitProgress - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (hlenNe : attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩) - (hprogress : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - (((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) :: - attesterFirstInnerArrayLengthWord I :: - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') :: - ⟨0⟩ :: - attesterFirstInnerArrayLengthWord I :: - attesterFirstInnerArrayLengthWord I :: - (attesterFirstInnerArrayStartWord I + ⟨32⟩) :: - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I]) - (attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ByteArray.empty (cA, σ) k C) : - ∃ a' b' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (attesterMultiRevokeInnerArrayInitExitStack I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - b') - (attesterMultiRevokeInnerArrayInitFinalMem b') - (attesterMultiRevokeInnerArrayInitFinalAw b') - ByteArray.empty (cA, σ) k C := by - obtain ⟨a', k0, C0, hrem, rd0⟩ := hprogress - have hlenNatNe : (attesterFirstInnerArrayLengthWord I).toNat ≠ 0 := by - intro hzero - apply hlenNe - apply u256_inj - simpa using hzero - obtain ⟨b', k1, C1, hbrem, rd1⟩ := - attesterX_multiRevokeInnerArrayInitLoop - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (slot := - ((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a'))) - (base := - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (len := attesterFirstInnerArrayLengthWord I) - (payload := attesterFirstInnerArrayStartWord I + ⟨32⟩) - (mem := - attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (aw := - attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (k := k0) (C := C0) hlenNatNe - (by simpa using rd0) - exact ⟨a', b', k1, C1, hrem, hbrem, rd1⟩ - -abbrev attesterMultiAttestInnerArrayInitFreeBumpWord - (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMultiOuterArrayInitFreeWord mem aw + (⟨192⟩ : UInt256) - -abbrev attesterMultiAttestInnerArrayInitFreeMem - (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (attesterMultiAttestInnerArrayInitFreeBumpWord mem aw)).write 0 - mem 64 32 - -abbrev attesterMultiAttestInnerArrayInitFreeAw - (_mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiOuterArrayInitAwAfterMload aw).toNat 64 32) - -abbrev attesterMultiAttestInnerArrayInitField32Word - (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMultiOuterArrayInitFreeWord mem aw + (⟨32⟩ : UInt256) - -abbrev attesterMultiAttestInnerArrayInitField64Word - (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMultiOuterArrayInitFreeWord mem aw + (⟨64⟩ : UInt256) - -abbrev attesterMultiAttestInnerArrayInitField96Word - (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMultiOuterArrayInitFreeWord mem aw + (⟨96⟩ : UInt256) - -abbrev attesterMultiAttestInnerArrayInitField128Word - (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMultiOuterArrayInitFreeWord mem aw + (⟨128⟩ : UInt256) - -abbrev attesterMultiAttestInnerArrayInitField160Word - (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMultiOuterArrayInitFreeWord mem aw + (⟨160⟩ : UInt256) - -abbrev attesterMultiAttestInnerArrayInitZero0Mem - (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (⟨0⟩ : UInt256)).write 0 - (attesterMultiAttestInnerArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat 32 - -abbrev attesterMultiAttestInnerArrayInitZero0Aw - (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiAttestInnerArrayInitFreeAw mem aw).toNat - (attesterMultiOuterArrayInitFreeWord mem aw).toNat 32) - -abbrev attesterMultiAttestInnerArrayInitZero32Mem - (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (⟨0⟩ : UInt256)).write 0 - (attesterMultiAttestInnerArrayInitZero0Mem mem aw) - (attesterMultiAttestInnerArrayInitField32Word mem aw).toNat 32 - -abbrev attesterMultiAttestInnerArrayInitZero32Aw - (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiAttestInnerArrayInitZero0Aw mem aw).toNat - (attesterMultiAttestInnerArrayInitField32Word mem aw).toNat 32) - -abbrev attesterMultiAttestInnerArrayInitZero64Mem - (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (⟨0⟩ : UInt256)).write 0 - (attesterMultiAttestInnerArrayInitZero32Mem mem aw) - (attesterMultiAttestInnerArrayInitField64Word mem aw).toNat 32 - -abbrev attesterMultiAttestInnerArrayInitZero64Aw - (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiAttestInnerArrayInitZero32Aw mem aw).toNat - (attesterMultiAttestInnerArrayInitField64Word mem aw).toNat 32) - -abbrev attesterMultiAttestInnerArrayInitZero96Mem - (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (⟨0⟩ : UInt256)).write 0 - (attesterMultiAttestInnerArrayInitZero64Mem mem aw) - (attesterMultiAttestInnerArrayInitField96Word mem aw).toNat 32 - -abbrev attesterMultiAttestInnerArrayInitZero96Aw - (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiAttestInnerArrayInitZero64Aw mem aw).toNat - (attesterMultiAttestInnerArrayInitField96Word mem aw).toNat 32) - -abbrev attesterMultiAttestInnerArrayInitDataOffsetMem - (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (⟨96⟩ : UInt256)).write 0 - (attesterMultiAttestInnerArrayInitZero96Mem mem aw) - (attesterMultiAttestInnerArrayInitField128Word mem aw).toNat 32 - -abbrev attesterMultiAttestInnerArrayInitDataOffsetAw - (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiAttestInnerArrayInitZero96Aw mem aw).toNat - (attesterMultiAttestInnerArrayInitField128Word mem aw).toNat 32) - -abbrev attesterMultiAttestInnerArrayInitZero160Mem - (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (⟨0⟩ : UInt256)).write 0 - (attesterMultiAttestInnerArrayInitDataOffsetMem mem aw) - (attesterMultiAttestInnerArrayInitField160Word mem aw).toNat 32 - -abbrev attesterMultiAttestInnerArrayInitZero160Aw - (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiAttestInnerArrayInitDataOffsetAw mem aw).toNat - (attesterMultiAttestInnerArrayInitField160Word mem aw).toNat 32) - -abbrev attesterMultiAttestInnerArrayInitStepMem - (slot : UInt256) (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (attesterMultiOuterArrayInitFreeWord mem aw)).write 0 - (attesterMultiAttestInnerArrayInitZero160Mem mem aw) slot.toNat 32 - -abbrev attesterMultiAttestInnerArrayInitStepAw - (slot : UInt256) (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiAttestInnerArrayInitZero160Aw mem aw).toNat - slot.toNat 32) - -abbrev attesterMultiAttestInnerArrayInitDecRemaining - (remaining : UInt256) : UInt256 := - remaining + UInt256.lnot (⟨0⟩ : UInt256) - -theorem attester_u256_ofNat_succ_add_lnot_zero {n : Nat} - (hn : n + 1 < UInt256.size) : - attesterMultiAttestInnerArrayInitDecRemaining (UInt256.ofNat (n + 1)) = - UInt256.ofNat n := by - apply u256_inj - have hlnot0 : (UInt256.lnot (⟨0⟩ : UInt256)).toNat = UInt256.size - 1 := by - unfold UInt256.lnot - decide - have hsum : n + 1 + (UInt256.size - 1) = UInt256.size + n := by - omega - rw [attesterMultiAttestInnerArrayInitDecRemaining, uadd_toNat, - ulit_toNat' (n + 1) hn, hlnot0, hsum, Nat.add_mod_left, - ulit_toNat' n (by omega)] - exact Nat.mod_eq_of_lt (by omega) - -structure AttesterMultiAttestInnerArrayInitState where - slot : UInt256 - remaining : UInt256 - mem : ByteArray - aw : UInt256 - -abbrev attesterMultiAttestInnerArrayInitStack - (I : ExecutionEnv) (base len payload : UInt256) - (a : AttesterMultiAttestInnerArrayInitState) : List UInt256 := - [a.slot, a.remaining, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - -abbrev attesterMultiAttestInnerArrayInitExitStack - (I : ExecutionEnv) (base len payload : UInt256) - (_a : AttesterMultiAttestInnerArrayInitState) : List UInt256 := - [⟨0⟩, base, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - -abbrev attesterMultiAttestInnerArrayInitStepState - (a : AttesterMultiAttestInnerArrayInitState) : - AttesterMultiAttestInnerArrayInitState := - { slot := (⟨32⟩ : UInt256) + a.slot, - remaining := attesterMultiAttestInnerArrayInitDecRemaining a.remaining, - mem := attesterMultiAttestInnerArrayInitStepMem a.slot a.mem a.aw, - aw := attesterMultiAttestInnerArrayInitStepAw a.slot a.mem a.aw } - -abbrev attesterMultiAttestInnerArrayInitFinalMem - (a : AttesterMultiAttestInnerArrayInitState) : ByteArray := - attesterMultiAttestInnerArrayInitStepMem a.slot a.mem a.aw - -abbrev attesterMultiAttestInnerArrayInitFinalAw - (a : AttesterMultiAttestInnerArrayInitState) : UInt256 := - attesterMultiAttestInnerArrayInitStepAw a.slot a.mem a.aw - -set_option maxHeartbeats 1500000 in -theorem attesterX_multiAttestInnerArrayInitStores - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len payload remaining : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1113⟩ : UInt256) - [slot, remaining, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1162⟩ : UInt256) - [⟨32⟩, slot, remaining, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - (attesterMultiAttestInnerArrayInitStepMem slot mem aw) - (attesterMultiAttestInnerArrayInitStepAw slot mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterMultiOuterArrayInitFreeWord mem aw - let aw1 := attesterMultiOuterArrayInitAwAfterMload aw - let bump := attesterMultiAttestInnerArrayInitFreeBumpWord mem aw - let mem1 := attesterMultiAttestInnerArrayInitFreeMem mem aw - let aw2 := attesterMultiAttestInnerArrayInitFreeAw mem aw - let field32 := attesterMultiAttestInnerArrayInitField32Word mem aw - let mem2 := attesterMultiAttestInnerArrayInitZero0Mem mem aw - let aw3 := attesterMultiAttestInnerArrayInitZero0Aw mem aw - let mem3 := attesterMultiAttestInnerArrayInitZero32Mem mem aw - let aw4 := attesterMultiAttestInnerArrayInitZero32Aw mem aw - let field64 := attesterMultiAttestInnerArrayInitField64Word mem aw - let mem4 := attesterMultiAttestInnerArrayInitZero64Mem mem aw - let aw5 := attesterMultiAttestInnerArrayInitZero64Aw mem aw - let field96 := attesterMultiAttestInnerArrayInitField96Word mem aw - let mem5 := attesterMultiAttestInnerArrayInitZero96Mem mem aw - let aw6 := attesterMultiAttestInnerArrayInitZero96Aw mem aw - let field128 := attesterMultiAttestInnerArrayInitField128Word mem aw - let mem6 := attesterMultiAttestInnerArrayInitDataOffsetMem mem aw - let aw7 := attesterMultiAttestInnerArrayInitDataOffsetAw mem aw - let field160 := attesterMultiAttestInnerArrayInitField160Word mem aw - let mem7 := attesterMultiAttestInnerArrayInitZero160Mem mem aw - let aw8 := attesterMultiAttestInnerArrayInitZero160Aw mem aw - let mem8 := attesterMultiAttestInnerArrayInitStepMem slot mem aw - let aw9 := attesterMultiAttestInnerArrayInitStepAw slot mem aw - have hcostMload : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - [⟨64⟩, ⟨64⟩, slot, remaining, base, ⟨0⟩, - len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreFreePtr : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - [⟨64⟩, bump, free, ⟨64⟩, slot, remaining, base, ⟨0⟩, - len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero0 : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - [free, (⟨0⟩ : UInt256), ⟨0⟩, free, ⟨64⟩, - slot, remaining, base, ⟨0⟩, len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero32 : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - [field32, (⟨0⟩ : UInt256), ⟨32⟩, ⟨0⟩, free, ⟨64⟩, - slot, remaining, base, ⟨0⟩, len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw4 - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero64 : - ∀ s : State, - s.machineState.activeWords = aw4 → - s.machineState.stack = - [field64, (⟨0⟩ : UInt256), ⟨0⟩, free, ⟨32⟩, - slot, remaining, base, ⟨0⟩, len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw5 - Cₘ aw4 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero96 : - ∀ s : State, - s.machineState.activeWords = aw5 → - s.machineState.stack = - [field96, (⟨0⟩ : UInt256), ⟨96⟩, ⟨0⟩, free, ⟨32⟩, - slot, remaining, base, ⟨0⟩, len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw6 - Cₘ aw5 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreDataOffset : - ∀ s : State, - s.machineState.activeWords = aw6 → - s.machineState.stack = - [field128, (⟨96⟩ : UInt256), ⟨0⟩, free, ⟨32⟩, - slot, remaining, base, ⟨0⟩, len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw7 - Cₘ aw6 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero160 : - ∀ s : State, - s.machineState.activeWords = aw7 → - s.machineState.stack = - [field160, (⟨0⟩ : UInt256), free, ⟨32⟩, - slot, remaining, base, ⟨0⟩, len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw8 - Cₘ aw7 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSlot : - ∀ s : State, - s.machineState.activeWords = aw8 → - s.machineState.stack = - [slot, free, ⟨32⟩, slot, remaining, base, ⟨0⟩, - len, len, payload, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw9 - Cₘ aw8 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - exact ⟨_, _, by - simpa [free, aw1, bump, mem1, aw2, field32, mem2, aw3, mem3, aw4, - field64, mem4, aw5, field96, mem5, aw6, field128, mem6, aw7, - field160, mem7, aw8, mem8, aw9] using - evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨1113⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1114⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1116⟩, 0x80, .DUP1) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨1117⟩, 0x51, .MLOAD) - hcostMload (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨192⟩ (by attester_decode_at v, ⟨1118⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1120⟩, 0x81, .DUP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨1121⟩, 0x01, .ADD) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1122⟩, 0x82, .DUP3) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨1123⟩, 0x52, .MSTORE) - hcostStoreFreePtr (by rfl) (by rfl) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨1124⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1125⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1126⟩, 0x82, .DUP3) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨1127⟩, 0x52, .MSTORE) - hcostStoreZero0 (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1128⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1130⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1131⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨1132⟩, 0x01, .ADD) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1133⟩, 0x82, .DUP3) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1134⟩, 0x90, .SWAP1) (by evm_ov), - raw mstore (Cₘ aw4 - Cₘ aw3) mem3 aw4 - (by attester_decode_at v, ⟨1135⟩, 0x52, .MSTORE) - hcostStoreZero32 (by rfl) (by rfl) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨1136⟩, 0x92, .SWAP3) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1137⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨1138⟩, 0x01, .ADD) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1139⟩, 0x81, .DUP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1140⟩, 0x90, .SWAP1) (by evm_ov), - raw mstore (Cₘ aw5 - Cₘ aw4) mem4 aw5 - (by attester_decode_at v, ⟨1141⟩, 0x52, .MSTORE) - hcostStoreZero64 (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨96⟩ (by attester_decode_at v, ⟨1142⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1144⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1145⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨1146⟩, 0x01, .ADD) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1147⟩, 0x82, .DUP3) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1148⟩, 0x90, .SWAP1) (by evm_ov), - raw mstore (Cₘ aw6 - Cₘ aw5) mem5 aw6 - (by attester_decode_at v, ⟨1149⟩, 0x52, .MSTORE) - hcostStoreZero96 (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨128⟩ (by attester_decode_at v, ⟨1150⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1152⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨1153⟩, 0x01, .ADD) (by evm_ov), - raw mstore (Cₘ aw7 - Cₘ aw6) mem6 aw7 - (by attester_decode_at v, ⟨1154⟩, 0x52, .MSTORE) - hcostStoreDataOffset (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨160⟩ (by attester_decode_at v, ⟨1155⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1157⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨1158⟩, 0x01, .ADD) (by evm_ov), - raw mstore (Cₘ aw8 - Cₘ aw7) mem7 aw8 - (by attester_decode_at v, ⟨1159⟩, 0x52, .MSTORE) - hcostStoreZero160 (by rfl) (by rfl) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1160⟩, 0x82, .DUP3) (by evm_ov), - raw mstore (Cₘ aw9 - Cₘ aw8) mem8 aw9 - (by attester_decode_at v, ⟨1161⟩, 0x52, .MSTORE) - hcostStoreSlot (by rfl) (by rfl) (by evm_ov)]⟩ - -theorem attesterX_multiAttestInnerArrayInitFinalIteration - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len payload : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1113⟩ : UInt256) - [slot, (⟨1⟩ : UInt256), base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1181⟩ : UInt256) - [⟨0⟩, base, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - (attesterMultiAttestInnerArrayInitStepMem slot mem aw) - (attesterMultiAttestInnerArrayInitStepAw slot mem aw) - ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd1162⟩ := - attesterX_multiAttestInnerArrayInitStores - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (slot := slot) (base := base) (len := len) (payload := payload) - (remaining := (⟨1⟩ : UInt256)) (mem := mem) (aw := aw) - (k := k) (C := C) hreach - exact ⟨_, _, by - simpa [attesterMultiAttestInnerArrayInitDecRemaining] using - evm_run rd1162 with [ - raw push0 (by attester_decode_at v, ⟨1162⟩, 0x5f, .PUSH0) (by evm_ov), - raw not (by attester_decode_at v, ⟨1163⟩, 0x19, .NOT) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1164⟩, 0x90, .SWAP1) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨1165⟩, 0x92, .SWAP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨1166⟩, 0x01, .ADD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨1167⟩, 0x91, .SWAP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨1168⟩, 0x01, .ADD) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1169⟩, 0x81, .DUP2) (by evm_ov), - raw push2 ⟨1113⟩ (by attester_decode_at v, ⟨1170⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨1173⟩, 0x57, .JUMPI) - (by native_decide) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1174⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1175⟩, 0x50, .POP) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨1176⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1177⟩, 0x50, .POP) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1178⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨1179⟩, 0x50, .POP) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨1180⟩, 0x5f, .PUSH0) (by evm_ov)]⟩ - -theorem attesterX_multiAttestInnerArrayInitNonFinalIteration - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len payload remaining : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hnext : attesterMultiAttestInnerArrayInitDecRemaining remaining ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1113⟩ : UInt256) - [slot, remaining, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1113⟩ : UInt256) - [((⟨32⟩ : UInt256) + slot), - attesterMultiAttestInnerArrayInitDecRemaining remaining, - base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - (attesterMultiAttestInnerArrayInitStepMem slot mem aw) - (attesterMultiAttestInnerArrayInitStepAw slot mem aw) - ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd1162⟩ := - attesterX_multiAttestInnerArrayInitStores - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (slot := slot) (base := base) (len := len) (payload := payload) - (remaining := remaining) (mem := mem) (aw := aw) - (k := k) (C := C) hreach - exact ⟨_, _, by - simpa [attesterMultiAttestInnerArrayInitDecRemaining] using - evm_run rd1162 with [ - raw push0 (by attester_decode_at v, ⟨1162⟩, 0x5f, .PUSH0) (by evm_ov), - raw not (by attester_decode_at v, ⟨1163⟩, 0x19, .NOT) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1164⟩, 0x90, .SWAP1) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨1165⟩, 0x92, .SWAP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨1166⟩, 0x01, .ADD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨1167⟩, 0x91, .SWAP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨1168⟩, 0x01, .ADD) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1169⟩, 0x81, .DUP2) (by evm_ov), - raw push2 ⟨1113⟩ (by attester_decode_at v, ⟨1170⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨1173⟩, 0x57, .JUMPI) - (by simpa [attesterMultiAttestInnerArrayInitDecRemaining] using hnext) - (attesterMultiAttestInnerArrayInitLoopJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiAttestInnerArrayInitLoop - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len payload : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hlenNe : len.toNat ≠ 0) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1113⟩ : UInt256) - [slot, len, base, ⟨0⟩, len, len, payload, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ a' k' C', - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1181⟩ : UInt256) - (attesterMultiAttestInnerArrayInitExitStack I base len payload a') - (attesterMultiAttestInnerArrayInitFinalMem a') - (attesterMultiAttestInnerArrayInitFinalAw a') - ByteArray.empty (cA, σ) k' C' := by - let Inv : Nat → AttesterMultiAttestInnerArrayInitState → Prop := - fun n a => a.remaining = UInt256.ofNat (n + 1) ∧ n + 1 < UInt256.size - let stk := attesterMultiAttestInnerArrayInitStack I base len payload - let memOf : AttesterMultiAttestInnerArrayInitState → ByteArray := fun a => a.mem - let awOf : AttesterMultiAttestInnerArrayInitState → UInt256 := fun a => a.aw - let exitStk := attesterMultiAttestInnerArrayInitExitStack I base len payload - let exitMem := attesterMultiAttestInnerArrayInitFinalMem - let exitAw := attesterMultiAttestInnerArrayInitFinalAw - have hexit : - ∀ a, Inv 0 a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1113⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1181⟩ : UInt256) (exitStk a) (exitMem a) (exitAw a) - ByteArray.empty (cA, σ) k' C' := by - intro a hInv k C rd - have hrem : a.remaining = (⟨1⟩ : UInt256) := by - simpa [Inv] using hInv.1 - exact attesterX_multiAttestInnerArrayInitFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (payload := payload) (mem := a.mem) (aw := a.aw) - (by - simpa [stk, memOf, awOf, hrem, attesterMultiAttestInnerArrayInitStack] - using rd) - have hbody : - ∀ n a, Inv (n + 1) a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1113⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ a' k' C', - Inv n a' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨1113⟩ : UInt256) (stk a') (memOf a') (awOf a') - ByteArray.empty (cA, σ) k' C' := by - intro n a hInv k C rd - let a' := attesterMultiAttestInnerArrayInitStepState a - have hsub : - attesterMultiAttestInnerArrayInitDecRemaining a.remaining = - UInt256.ofNat (n + 1) := by - rw [hInv.1] - simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using - attester_u256_ofNat_succ_add_lnot_zero (n := n + 1) - (by simpa [Inv, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using hInv.2) - have hnext : - attesterMultiAttestInnerArrayInitDecRemaining a.remaining ≠ ⟨0⟩ := by - rw [hsub] - exact attester_u256_ofNat_pos_ne_zero - (n := n + 1) (by omega) (by - have hlt : n + 1 < UInt256.size := by - have := hInv.2 - omega - exact hlt) - obtain ⟨k', C', rd'⟩ := - attesterX_multiAttestInnerArrayInitNonFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (payload := payload) (remaining := a.remaining) (mem := a.mem) (aw := a.aw) - hnext - (by - simpa [stk, memOf, awOf, attesterMultiAttestInnerArrayInitStack] - using rd) - refine ⟨a', k', C', ?_, ?_⟩ - · constructor - · simpa [a', attesterMultiAttestInnerArrayInitStepState] using hsub - · have := hInv.2 - omega - · simpa [a', stk, memOf, awOf, attesterMultiAttestInnerArrayInitStack, - attesterMultiAttestInnerArrayInitStepState] using rd' - let a0 : AttesterMultiAttestInnerArrayInitState := - { slot := slot, remaining := len, mem := mem, aw := aw } - have hInv0 : Inv (len.toNat - 1) a0 := by - constructor - · have hsucc : (len.toNat - 1) + 1 = len.toNat := by omega - simpa [a0, hsucc] using (u256_ofNat_toNat len).symm - · have hsucc : (len.toNat - 1) + 1 = len.toNat := by omega - rw [hsucc] - exact len.val.isLt - obtain ⟨a', k', C', hInvFinal, rdFinal⟩ := - RD.whileLoopCarryExit - (code := patchedRuntime v) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) - (rdata := ByteArray.empty) (acc := (cA, σ)) - (header := (⟨1113⟩ : UInt256)) (exit := (⟨1181⟩ : UInt256)) - Inv stk memOf awOf exitStk exitMem exitAw hexit hbody - (len.toNat - 1) a0 hInv0 k C - (by - simpa [a0, stk, memOf, awOf, attesterMultiAttestInnerArrayInitStack] - using hreach) - exact ⟨a', k', C', by simpa [Inv] using hInvFinal.1, rdFinal⟩ - -theorem attesterX_multiAttestFirstInnerArrayInitProgress - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (hlenNe : attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩) - (hprogress : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1113⟩ : UInt256) - (((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) :: - attesterFirstInnerArrayLengthWord I :: - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') :: - ⟨0⟩ :: - attesterFirstInnerArrayLengthWord I :: - attesterFirstInnerArrayLengthWord I :: - (attesterFirstInnerArrayStartWord I + ⟨32⟩) :: - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I]) - (attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ByteArray.empty (cA, σ) k C) : - ∃ a' b' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1181⟩ : UInt256) - (attesterMultiAttestInnerArrayInitExitStack I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - b') - (attesterMultiAttestInnerArrayInitFinalMem b') - (attesterMultiAttestInnerArrayInitFinalAw b') - ByteArray.empty (cA, σ) k C := by - obtain ⟨a', k0, C0, hrem, rd0⟩ := hprogress - have hlenNatNe : (attesterFirstInnerArrayLengthWord I).toNat ≠ 0 := by - intro hzero - apply hlenNe - apply u256_inj - simpa using hzero - obtain ⟨b', k1, C1, hbrem, rd1⟩ := - attesterX_multiAttestInnerArrayInitLoop - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (slot := - ((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a'))) - (base := - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (len := attesterFirstInnerArrayLengthWord I) - (payload := attesterFirstInnerArrayStartWord I + ⟨32⟩) - (mem := - attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (aw := - attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (k := k0) (C := C0) hlenNatNe - (by simpa using rd0) - exact ⟨a', b', k1, C1, hrem, hbrem, rd1⟩ - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/MultiAttest.lean b/Benchmarks/EAS/Attester/MultiAttest.lean deleted file mode 100644 index f5052c57..00000000 --- a/Benchmarks/EAS/Attester/MultiAttest.lean +++ /dev/null @@ -1,1376 +0,0 @@ -import Benchmarks.EAS.Attester.MultiSource -import Benchmarks.EAS.Attester.InnerArrayCopy - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -/-! ## `multiAttest(bytes32[],uint256[][])` -/ - -theorem attesterDecode_multiAttest_none_short (v : AttesterImmutables) {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 68) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - show decodeCalldata ["schemas", "schemaInputs"] [bytes32Array, uint256NestedArray] - I.calldata = none - unfold decodeCalldata - rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - rw [if_neg (by rintro ⟨_, hbig⟩; rw [htlen] at hbig; omega)] - rw [if_neg (by rintro ⟨_, hbig⟩; rw [List.length_drop, htlen] at hbig; omega)] - rw [if_neg (by rintro ⟨_, hbig⟩; rw [htlen] at hbig; omega)] - simp only [decodeCalldata.decodeArgs] - rw [show abiTupleHeadSize? [bytes32Array, uint256NestedArray] = some 64 by native_decide] - simp only [bind, Option.bind] - have hargsShort : (I.calldata.toList.drop 4).length < 64 := by - rw [List.length_drop, htlen] - omega - rw [if_pos hargsShort] - -theorem attesterDecode_multiAttest_none_huge (v : AttesterImmutables) {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - show decodeCalldata ["schemas", "schemaInputs"] [bytes32Array, uint256NestedArray] - I.calldata = none - unfold decodeCalldata - rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - rw [if_pos] - · exact ⟨by native_decide, by rw [htlen]; omega⟩ - -theorem attesterDecode_multiAttest_none_totalHuge (v : AttesterImmutables) {I : ExecutionEnv} - (hbig : 2 ^ 255 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaInputs"] [bytes32Array, uint256NestedArray] - I.calldata = none - simpa [bytes32Array, uint256NestedArray, uint256Array] using - attesterDecodeCalldata_twoDynamicArrays_none_totalHuge - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaInputs") - (elem0 := bytes32) (elem1 := uint256) hbig - -theorem attesterDecode_multiAttest_none_firstOffsetHuge (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoff : solcMaxU64 < (calldataWord I.calldata 4).toNat) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaInputs"] [bytes32Array, uint256NestedArray] - I.calldata = none - simpa [bytes32Array, uint256NestedArray, uint256Array] using - attesterDecodeCalldata_twoDynamicArrays_none_firstOffsetHuge - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaInputs") - (elem0 := bytes32) (elem1 := uint256) hsz68 hoff - -theorem attesterDecode_multiAttest_none_firstLengthShort (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hshort : I.calldata.size < 4 + (calldataWord I.calldata 4).toNat + 32) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaInputs"] [bytes32Array, uint256NestedArray] - I.calldata = none - simpa [bytes32Array, uint256NestedArray, uint256Array] using - attesterDecodeCalldata_twoDynamicArrays_none_firstLengthShort - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaInputs") - (elem0 := bytes32) (elem1 := uint256) hsz68 hoffMax hshort - -theorem attesterDecode_multiAttest_none_firstLengthHuge (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlenWord : 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size) - (hlenHuge : solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaInputs"] [bytes32Array, uint256NestedArray] - I.calldata = none - simpa [bytes32Array, uint256NestedArray, uint256Array] using - attesterDecodeCalldata_twoDynamicArrays_none_firstLengthHuge - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaInputs") - (elem0 := bytes32) (elem1 := uint256) hsz68 hoffMax hlenWord hlenHuge - -theorem attesterDecode_multiAttest_none_firstPayloadShort (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlenWord : 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size) - (hlenMax : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hpayload : I.calldata.size < - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaInputs"] [bytes32Array, uint256NestedArray] - I.calldata = none - simpa [bytes32Array, uint256NestedArray, uint256Array] using - attesterDecodeCalldata_twoDynamicArrays_none_firstBytes32PayloadShort - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaInputs") - (elem1 := uint256) hsz68 hoffMax hlenWord hlenMax hpayload - -theorem attesterDecode_multiAttest_none_secondOffsetHuge (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlenWord : 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hpayload0 : - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ≤ - I.calldata.size) - (hoff1Huge : solcMaxU64 < (calldataWord I.calldata 36).toNat) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaInputs"] [bytes32Array, uint256NestedArray] - I.calldata = none - simpa [bytes32Array, uint256NestedArray, uint256Array] using - attesterDecodeCalldata_twoDynamicArrays_none_secondOffsetHuge - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaInputs") - (elem1 := uint256) hsz68 hoff0Max hlenWord hlen0Max hpayload0 hoff1Huge - -theorem attesterDecode_multiAttest_none_secondLengthShort (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlen0Word : 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hpayload0 : - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ≤ - I.calldata.size) - (hoff1Max : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hshort1 : I.calldata.size < 4 + (calldataWord I.calldata 36).toNat + 32) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaInputs"] [bytes32Array, uint256NestedArray] - I.calldata = none - simpa [bytes32Array, uint256NestedArray, uint256Array] using - attesterDecodeCalldata_twoDynamicArrays_none_secondLengthShort - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaInputs") - (elem1 := uint256) hsz68 hoff0Max hlen0Word hlen0Max hpayload0 hoff1Max hshort1 - -theorem attesterDecode_multiAttest_none_secondLengthHuge (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlen0Word : 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hpayload0 : - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ≤ - I.calldata.size) - (hoff1Max : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hlen1Word : 4 + (calldataWord I.calldata 36).toNat + 32 ≤ I.calldata.size) - (hlen1Huge : solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaInputs"] [bytes32Array, uint256NestedArray] - I.calldata = none - simpa [bytes32Array, uint256NestedArray, uint256Array] using - attesterDecodeCalldata_twoDynamicArrays_none_secondLengthHuge - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaInputs") - (elem1 := uint256) hsz68 hoff0Max hlen0Word hlen0Max hpayload0 hoff1Max hlen1Word - hlen1Huge - -theorem attesterDecode_multiAttest_none_secondPayloadShort (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlen0Word : 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hpayload0 : - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ≤ - I.calldata.size) - (hoff1Max : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hlen1Word : 4 + (calldataWord I.calldata 36).toNat + 32 ≤ I.calldata.size) - (hlen1Max : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) - (hpayload1 : - I.calldata.size < - 4 + (calldataWord I.calldata 36).toNat + 32 + - 32 * (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaInputs"] [bytes32Array, uint256NestedArray] - I.calldata = none - simpa [bytes32Array, uint256NestedArray, uint256Array] using - attesterDecodeCalldata_twoDynamicArrays_none_secondPayloadShort - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaInputs") - (elem1 := uint256) hsz68 hoff0Max hlen0Word hlen0Max hpayload0 hoff1Max hlen1Word - hlen1Max hpayload1 - -theorem attesterDecode_multiAttest_some_shape (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = - some callargs) : - ∃ schemas schemaInputs : List Value, - callargs.get? "schemas" = some (.array schemas) ∧ - callargs.get? "schemaInputs" = some (.array schemaInputs) := by - have hdec' : - decodeCalldata ["schemas", "schemaInputs"] - [.dynamicArray bytes32, .dynamicArray (.dynamicArray uint256)] I.calldata = - some callargs := by - simpa [decodeCalldataWithMode, config, multiAttestTransition, transitionSignature, - bytes32Array, uint256NestedArray, uint256Array] using hdec - exact attesterDecodeCalldata_twoDynamicArrays_shape - (name0 := "schemas") (name1 := "schemaInputs") - (elem0 := bytes32) (elem1 := uint256) (cd := I.calldata) - (by native_decide) hdec' - -theorem attesterDecode_multiAttest_some_shape_lengths (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = - some callargs) : - ∃ schemas schemaInputs : List Value, - callargs.get? "schemas" = some (.array schemas) ∧ - callargs.get? "schemaInputs" = some (.array schemaInputs) ∧ - schemas.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ∧ - schemaInputs.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat := by - have hdec' : - decodeCalldata ["schemas", "schemaInputs"] - [.dynamicArray bytes32, .dynamicArray (.dynamicArray uint256)] I.calldata = - some callargs := by - simpa [decodeCalldataWithMode, config, multiAttestTransition, transitionSignature, - bytes32Array, uint256NestedArray, uint256Array] using hdec - exact attesterDecodeCalldata_twoDynamicArrays_lengths - (name0 := "schemas") (name1 := "schemaInputs") - (elem1 := uint256) (cd := I.calldata) - (by native_decide) hdec' - -theorem attesterDecode_multiAttest_good_lengths_of_not_bad (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} - (hnotBad : - ¬ ∃ callargs schemas schemaInputs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = - some callargs ∧ - callargs.get? "schemas" = some (.array schemas) ∧ - callargs.get? "schemaInputs" = some (.array schemaInputs) ∧ - schemas.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ∧ - schemaInputs.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat ∧ - (schemas.length = 0 ∨ schemas.length ≠ schemaInputs.length)) - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = - some callargs) : - ∃ schemas schemaInputs : List Value, - callargs.get? "schemas" = some (.array schemas) ∧ - callargs.get? "schemaInputs" = some (.array schemaInputs) ∧ - schemas.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ∧ - schemaInputs.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat ∧ - schemas.length ≠ 0 ∧ schemas.length = schemaInputs.length := by - obtain ⟨schemas, schemaInputs, hSchemas, hSchemaInputs, hSchemasLen, hSchemaInputsLen⟩ := - attesterDecode_multiAttest_some_shape_lengths v hdec - have hnonzero : schemas.length ≠ 0 := by - intro hzero - exact hnotBad ⟨callargs, schemas, schemaInputs, hdec, hSchemas, hSchemaInputs, - hSchemasLen, hSchemaInputsLen, Or.inl hzero⟩ - have heq : schemas.length = schemaInputs.length := by - by_contra hne - exact hnotBad ⟨callargs, schemas, schemaInputs, hdec, hSchemas, hSchemaInputs, - hSchemasLen, hSchemaInputsLen, Or.inr hne⟩ - exact ⟨schemas, schemaInputs, hSchemas, hSchemaInputs, hSchemasLen, hSchemaInputsLen, - hnonzero, heq⟩ - -theorem attesterMultiAttestBodySchemaGuardReverts (v : AttesterImmutables) - (evm : EVM.State) (locals : Store) {schemas schemaInputs : List Value} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hSchemas : locals.get? "schemas" = some (.array schemas)) - (hSchemaInputs : locals.get? "schemaInputs" = some (.array schemaInputs)) - (hbad : schemas.length = 0 ∨ schemas.length ≠ schemaInputs.length) : - ExecTransitionBody (config v) (contract v) evm locals - (multiAttestTransition v).body .reverted := by - have hSchemasElem : locals["schemas"]? = some (.array schemas) := by - rw [← Std.HashMap.get?_eq_getElem?] - exact hSchemas - have hSchemaInputsElem (n : Nat) : - (locals.insert "schemaLength" (.int (Int.ofNat n)))["schemaInputs"]? = - some (.array schemaInputs) := by - rw [Std.HashMap.getElem?_insert] - simp - rw [← Std.HashMap.get?_eq_getElem?] - exact hSchemaInputs - refine ExecFuncBody.execBlockRevert ?_ - simp [multiAttestTransition, nonpayable] - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl (value := .int (Int.ofNat schemas.length)) ?_) ?_ - · simp [evalExpr?, lenLocal, localRef, hSchemasElem, readLocalPath?, - EvalResult.bind, bind, pure] - · refine ExecBlock.consRevert (ExecStmt.requireFalse ?_) - exact attesterEvalMultiLengthGuardFalse (v := v) (evm := evm) (locals := locals) - (secondName := "schemaInputs") (schemas := schemas) (second := schemaInputs) - (hSchemaInputsElem schemas.length) hbad - -theorem attesterMultiAttestBodyFirstInputLengthZeroReverts (v : AttesterImmutables) - (evm : EVM.State) (locals : Store) {schemas rest : List Value} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hSchemas : locals.get? "schemas" = some (.array schemas)) - (hSchemaInputs : locals.get? "schemaInputs" = some (.array (.array [] :: rest))) - (hSchemasNe : schemas.length ≠ 0) - (hSchemasLen : schemas.length = (.array [] :: rest).length) : - ExecTransitionBody (config v) (contract v) evm locals - (multiAttestTransition v).body .reverted := by - have hSchemasElem : locals["schemas"]? = some (.array schemas) := by - rw [← Std.HashMap.get?_eq_getElem?] - exact hSchemas - refine ExecFuncBody.execBlockRevert ?_ - simp [multiAttestTransition, nonpayable] - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl (value := .int (Int.ofNat schemas.length)) ?_) ?_ - · simp [evalExpr?, lenLocal, localRef, hSchemasElem, readLocalPath?, - EvalResult.bind, bind, pure] - · have hguard : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.binary .and - (.binary .ne (.var "schemaLength") (.intLit 0)) - (.binary .eq (.var "schemaLength") (lenLocal "schemaInputs"))) = - .ok (.bool true) := by - have hleft : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.binary .ne (.var "schemaLength") (.intLit 0)) = - .ok (.bool true) := by - simp [evalExpr?, evalBinaryOp?, hSchemasNe, - EvalResult.bind, EvalResult.ofOption, bind, pure] - have hright : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.binary .eq (.var "schemaLength") (lenLocal "schemaInputs")) = - .ok (.bool true) := by - have hSchemaInputsElem : - (locals.insert "schemaLength" (.int (Int.ofNat schemas.length)))["schemaInputs"]? = - some (.array (.array [] :: rest)) := by - rw [Std.HashMap.getElem?_insert] - simp - rw [← Std.HashMap.get?_eq_getElem?] - exact hSchemaInputs - have hSchemaInputsGet : - (locals.insert "schemaLength" (.int (Int.ofNat schemas.length))).get? - "schemaInputs" = - some (.array (.array [] :: rest)) := by - simpa [Std.HashMap.get?_eq_getElem?] using hSchemaInputsElem - have hvar : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.var "schemaLength") = - .ok (.int (Int.ofNat schemas.length)) := by - simp [evalExpr?, EvalResult.ofOption] - have hlen : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (lenLocal "schemaInputs") = - .ok (.int (Int.ofNat (.array [] :: rest).length)) := by - simp only [evalExpr?, lenLocal, localRef, readLocalPath?, EvalResult.bind, - bind, pure] - rw [hSchemaInputsGet] - rfl - have hop : - evalBinaryOp? .eq (.int (Int.ofNat schemas.length)) - (.int (Int.ofNat (.array [] :: rest).length)) = .ok (.bool true) := by - simp [evalBinaryOp?, hSchemasLen] - exact attesterEvalBinaryEq hvar hlen hop - exact attesterEvalAndTrue hleft hright - refine ExecBlock.consNormal (ExecStmt.requireTrue hguard) ?_ - let defaultRequest : Value := - .tuple [.fixedBytes bytes32Width (List.replicate 32 0), .array []] - let multiRequests : Value := - .array (List.replicate schemas.length defaultRequest) - have hmultiRequests : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.newArray multiAttestationRequestSt (.var "schemaLength")) = - .ok multiRequests := by - simp [multiRequests, defaultRequest, evalExpr?, multiAttestationRequestSt, - attestationRequestDataSt, addrSt, uint64St, boolSt, bytes32St, uint256St, - bytes32Width, defaultValue?, defaultValues?, EvalResult.bind, - EvalResult.ofOption, bind, pure] - refine ExecBlock.consNormal - (ExecStmt.letDecl (value := multiRequests) hmultiRequests) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (value := .int 0) ?_) ?_ - · simp [evalExpr?, pure] - · refine ExecBlock.consRevert (ExecStmt.whileRevert ?_ ?_) - · have hiEval : - evalExpr? (config v) - { contract := contract v, - locals := (((locals.insert "schemaLength" - (.int (Int.ofNat schemas.length))).insert - "multiRequests" multiRequests).insert "i" (.int 0)) } evm - (.var "i") = .ok (.int 0) := by - simp [evalExpr?, EvalResult.ofOption, Std.HashMap.get?_eq_getElem?] - have hschemaLengthEval : - evalExpr? (config v) - { contract := contract v, - locals := (((locals.insert "schemaLength" - (.int (Int.ofNat schemas.length))).insert - "multiRequests" multiRequests).insert "i" (.int 0)) } evm - (.var "schemaLength") = .ok (.int (Int.ofNat schemas.length)) := by - simp [evalExpr?, EvalResult.ofOption, Std.HashMap.get?_eq_getElem?, - Std.HashMap.getElem_insert] - have hposNat : 0 < schemas.length := Nat.pos_of_ne_zero hSchemasNe - have hpos : (0 : Int) < Int.ofNat schemas.length := by - exact Int.natCast_pos.mpr hposNat - have hop : - evalBinaryOp? .lt (.int 0) (.int (Int.ofNat schemas.length)) = - .ok (.bool true) := by - simpa [evalBinaryOp?, hpos] - exact attesterEvalBinaryLt hiEval hschemaLengthEval hop - · refine ExecBlock.consNormal (ExecStmt.letDecl (value := .array []) ?_) ?_ - · have hbaseEval : - evalExpr? (config v) - { contract := contract v, - locals := (((locals.insert "schemaLength" - (.int (Int.ofNat schemas.length))).insert - "multiRequests" multiRequests).insert "i" (.int 0)) } evm - (.var "schemaInputs") = .ok (.array (.array [] :: rest)) := by - have hSchemaInputsGet : - ((((locals.insert "schemaLength" (.int (Int.ofNat schemas.length))).insert - "multiRequests" multiRequests).insert "i" (.int 0)).get? - "schemaInputs") = - some (.array (.array [] :: rest)) := by - rw [Std.HashMap.get?_eq_getElem?] - rw [Std.HashMap.getElem?_insert] - simp - rw [Std.HashMap.getElem?_insert] - simp - rw [Std.HashMap.getElem?_insert] - simp - rw [← Std.HashMap.get?_eq_getElem?] - exact hSchemaInputs - simp only [evalExpr?, EvalResult.ofOption] - rw [hSchemaInputsGet] - have hiEval : - evalExpr? (config v) - { contract := contract v, - locals := (((locals.insert "schemaLength" - (.int (Int.ofNat schemas.length))).insert - "multiRequests" multiRequests).insert "i" (.int 0)) } evm - (.var "i") = .ok (.int 0) := by - simp [evalExpr?, EvalResult.ofOption, Std.HashMap.get?_eq_getElem?] - have hindex : - evalIndex? (.array (.array [] :: rest)) (.int 0) = .ok (.array []) := by - simp [evalIndex?, normalizeRawBoolWord?] - rfl - exact attesterEvalIndex hbaseEval hiEval hindex - · refine ExecBlock.consNormal (ExecStmt.letDecl (value := .int 0) ?_) ?_ - · simp [evalExpr?, lenLocal, localRef, readLocalPath?, - EvalResult.bind, bind, pure] - · refine ExecBlock.consRevert (ExecStmt.requireFalse ?_) - simp [evalExpr?, evalBinaryOp?, - EvalResult.bind, EvalResult.ofOption, bind, pure] - -set_option maxHeartbeats 1000000 in -theorem attesterMultiAttestBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (v : AttesterImmutables) {code : ByteArray} - (hpatch : patchRuntime attesterBytecode (patches v) = some code) - (hcode : I.code = code) - (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) - (hwv : I.weiValue = ⟨0⟩) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hpatched : code = patchedRuntime v := code_eq_patchedRuntime_of_patch hpatch - have hIcode : I.code = patchedRuntime v := hcode.trans hpatched - have hsz4 : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I attesterMultiAttestSelBytes attesterMultiAttestSelBytes_size - hmultiAttest - have hd := attesterDispatch_multiAttest v hmultiAttest - by_cases hsz68 : 68 ≤ I.calldata.size - · by_cases hsmall : I.calldata.size < 2 ^ 255 + 4 - · by_cases hoff0 : solcMaxU64 < (calldataWord I.calldata 4).toNat - · have hdec := attesterDecode_multiAttest_none_firstOffsetHuge v hsz68 hoff0 - have hreach2128 := - attesterX_multiAttestDecodeHeadOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hIcode hwv hsz4 hsize hsz68 hsmall hmultiRevoke hmultiAttest - exact (attesterX_dynamic2FirstOffsetHugeReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff0 hreach2128) - |>.reEquivDecodingFailed hIcode hd hdec - · have hreach2128 := - attesterX_multiAttestDecodeHeadOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hIcode hwv hsz4 hsize hsz68 hsmall hmultiRevoke hmultiAttest - have hreach2149 := - attesterX_dynamic2FirstOffsetOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff0 hreach2128 - have hreach2038 := - attesterX_dynamic2FirstArrayDecoderEntry - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hreach2149 - by_cases hsizeSigned : I.calldata.size < 2 ^ 255 - · by_cases hlenWord : - 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size - · have _hreach2054 := - attesterX_dynamicArrayLengthGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff0 hsizeSigned hlenWord hreach2038 - by_cases hlenHuge : solcMaxU64 < - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat - · have hdec := attesterDecode_multiAttest_none_firstLengthHuge - v hsz68 hoff0 hlenWord hlenHuge - exact (attesterX_dynamicArrayLengthMaxHugeReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff0 hlenHuge _hreach2054) - |>.reEquivDecodingFailed hIcode hd hdec - · have _hreach2076 := - attesterX_dynamicArrayLengthMaxOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff0 hlenHuge _hreach2054 - by_cases hpayload : - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ≤ - I.calldata.size - · have hgt := - attesterDynamicArrayPayloadGuardGtZero_of_ok - (I := I) hoff0 hlenHuge hsize hpayload - have _hreach2102 := - attesterX_dynamicArrayPayloadGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hgt _hreach2076 - have _hreach2161 := - attesterX_dynamicArrayPayloadOkToFirstReturn - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v _hreach2102 - by_cases hoff1 : solcMaxU64 < (calldataWord I.calldata 36).toNat - · have hdec := attesterDecode_multiAttest_none_secondOffsetHuge - v hsz68 hoff0 hlenWord hlenHuge hpayload hoff1 - exact (attesterX_dynamic2SecondOffsetHugeReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff1 _hreach2161) - |>.reEquivDecodingFailed hIcode hd hdec - · have _hreach2191 := - attesterX_dynamic2SecondOffsetOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff1 _hreach2161 - have _hreach2038Second := - attesterX_dynamic2SecondArrayDecoderEntry - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v _hreach2191 - by_cases hlen1Word : - 4 + (calldataWord I.calldata 36).toNat + 32 ≤ I.calldata.size - · have _hreach2054Second := - attesterX_secondArrayLengthGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff1 hsizeSigned hlen1Word _hreach2038Second - by_cases hlen1Huge : solcMaxU64 < - (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat - · have hdec := attesterDecode_multiAttest_none_secondLengthHuge - v hsz68 hoff0 hlenWord hlenHuge hpayload hoff1 hlen1Word hlen1Huge - exact (attesterX_secondArrayLengthMaxHugeReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff1 hlen1Huge _hreach2054Second) - |>.reEquivDecodingFailed hIcode hd hdec - · have _hreach2076Second := - attesterX_secondArrayLengthMaxOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff1 hlen1Huge _hreach2054Second - by_cases hpayload1 : - 4 + (calldataWord I.calldata 36).toNat + 32 + - 32 * (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat ≤ - I.calldata.size - · have hgt := - attesterSecondArrayPayloadGuardGtZero_of_ok - (I := I) hoff1 hlen1Huge hsize hpayload1 - have _hreach2102Second := - attesterX_secondArrayPayloadGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hgt _hreach2076Second - have _hreach2203 := - attesterX_secondArrayPayloadOkToSecondReturn - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v _hreach2102Second - have _hreachDecoded := - attesterX_dynamic2DecodeDone - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v (attesterMultiAttestDecodedJumpdest v) _hreach2203 - have _hreachBody := - attesterX_multiAttestDecodedToBody - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v _hreachDecoded - by_cases hbadDec : - ∃ callargs schemas schemaInputs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes - I.calldata = some callargs ∧ - callargs.get? "schemas" = some (.array schemas) ∧ - callargs.get? "schemaInputs" = some (.array schemaInputs) ∧ - schemas.length = - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ∧ - schemaInputs.length = - (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat ∧ - (schemas.length = 0 ∨ schemas.length ≠ schemaInputs.length) - · rcases hbadDec with - ⟨callargs, schemas, schemaInputs, hdecFull, hSchemas, hSchemaInputs, - hSchemasLen, hSchemaInputsLen, hbad⟩ - have hwvSolm : - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.weiValue = - ⟨0⟩ := by - simpa [initState] using hwv - by_cases hzeroSchemas : schemas.length = 0 - · have hrawZero : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat = 0 := by - omega - have hzeroEvm := - attesterFirstArrayLengthWord_isZero_of_nat_eq_zero - (I := I) hoff0 hrawZero - have hrdrev := - attesterX_multiAttestLengthZeroReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hzeroEvm _hreachBody - have hbody := - attesterMultiAttestBodySchemaGuardReverts v - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - callargs hwvSolm hSchemas hSchemaInputs (Or.inl hzeroSchemas) - exact hrdrev.reEquivExecutionRevert hIcode hd hdecFull hbody - · by_cases heqSchemas : schemas.length = schemaInputs.length - · exfalso - rcases hbad with hzero | hne - · exact hzeroSchemas hzero - · exact hne heqSchemas - · have hrawFirstNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hzeroSchemas (by omega) - have hrawNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat ≠ - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat := by - intro hrawEq - exact heqSchemas (by omega) - have hnonzeroEvm := - attesterFirstArrayLengthWord_isZero_of_nat_ne_zero - (I := I) hoff0 hrawFirstNe - have hneqEvm := - attesterArrayLengthWords_eq_zero_of_nat_ne - (I := I) hoff0 hoff1 hrawNe - have hrdrev := - attesterX_multiAttestLengthMismatchReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hnonzeroEvm hneqEvm - _hreachBody - have hbody := - attesterMultiAttestBodySchemaGuardReverts v - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - callargs hwvSolm hSchemas hSchemaInputs (Or.inr heqSchemas) - exact hrdrev.reEquivExecutionRevert hIcode hd hdecFull hbody - · have _hguardProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes - I.calldata = some callargs → - ∃ k C, RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨874⟩ : UInt256) - [attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaInputs, _hSchemas, _hSchemaInputs, - hSchemasLen, hSchemaInputsLen, hnonzero, heqLen⟩ := - attesterDecode_multiAttest_good_lengths_of_not_bad v - hbadDec hdecFull - exact attesterX_multiAttestLengthGuardOk_of_lengths - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hoff0 hoff1 hSchemasLen - hSchemaInputsLen hnonzero heqLen _hreachBody - have _hallocProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes - I.calldata = some callargs → - ∃ k C, RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨899⟩ : UInt256) - [attesterFirstArrayLengthWord I, ⟨0⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C := by - intro callargs hdecFull - exact attesterX_multiAttestAllocLengthMaxOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hoff0 hlenHuge - (_hguardProgress callargs hdecFull) - have _hinitProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes - I.calldata = some callargs → - ∃ k C, RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨929⟩ : UInt256) - [((⟨32⟩ : UInt256) + ⟨128⟩), - attesterFirstArrayLengthWord I, ⟨128⟩, ⟨0⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - (attesterMultiOuterArrayAllocMem I) (UInt256.ofNat 5) - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaInputs, _hSchemas, _hSchemaInputs, - hSchemasLen, _hSchemaInputsLen, hnonzero, _heqLen⟩ := - attesterDecode_multiAttest_good_lengths_of_not_bad v - hbadDec hdecFull - have hrawFirstNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by omega) - have hnonzeroEvm := - attesterFirstArrayLengthWord_isZero_of_nat_ne_zero - (I := I) hoff0 hrawFirstNe - exact attesterX_multiAttestOuterArrayInitEntry - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hnonzeroEvm - (_hallocProgress callargs hdecFull) - have _houterInitProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨973⟩ : UInt256) - (attesterMultiAttestOuterArrayInitExitStack I - ⟨128⟩ (attesterFirstArrayLengthWord I) a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaInputs, _hSchemas, _hSchemaInputs, - _hSchemasLen, _hSchemaInputsLen, hnonzero, _heqLen⟩ := - attesterDecode_multiAttest_good_lengths_of_not_bad v - hbadDec hdecFull - have hrawFirstNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by omega) - have hlenNe : - (attesterFirstArrayLengthWord I).toNat ≠ 0 := by - rw [attesterFirstArrayLengthWord_toNat (I := I) hoff0] - exact hrawFirstNe - obtain ⟨k0, C0, rd0⟩ := _hinitProgress callargs hdecFull - exact attesterX_multiAttestOuterArrayInitLoop - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (slot := ((⟨32⟩ : UInt256) + ⟨128⟩)) - (base := ⟨128⟩) - (len := attesterFirstArrayLengthWord I) - (mem := attesterMultiOuterArrayAllocMem I) - (aw := UInt256.ofNat 5) (k := k0) (C := C0) hlenNe rd0 - have _houterLoopFirstGuard : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨982⟩ : UInt256) - (attesterMultiAttestOuterArrayInitExitStack I - ⟨128⟩ (attesterFirstArrayLengthWord I) a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaInputs, _hSchemas, _hSchemaInputs, - _hSchemasLen, _hSchemaInputsLen, hnonzero, _heqLen⟩ := - attesterDecode_multiAttest_good_lengths_of_not_bad v - hbadDec hdecFull - have hrawFirstNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by omega) - have hlenNe : - (attesterFirstArrayLengthWord I).toNat ≠ 0 := by - rw [attesterFirstArrayLengthWord_toNat (I := I) hoff0] - exact hrawFirstNe - obtain ⟨a', k0, C0, hrem, rd0⟩ := - _houterInitProgress callargs hdecFull - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiAttestOuterSourceLoopFirstGuard - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (base := ⟨128⟩) - (len := attesterFirstArrayLengthWord I) - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) hlenNe - (by - simpa [attesterMultiAttestOuterArrayInitExitStack] - using rd0) - exact ⟨a', k1, C1, hrem, by - simpa [attesterMultiAttestOuterArrayInitExitStack] - using rd1⟩ - have _houterSecondArrayAccessOk : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨1001⟩ : UInt256) - [⟨0⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaInputs, _hSchemas, _hSchemaInputs, - _hSchemasLen, hSchemaInputsLen, hnonzero, heqLen⟩ := - attesterDecode_multiAttest_good_lengths_of_not_bad v - hbadDec hdecFull - have hrawSecondNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by - calc - schemas.length = schemaInputs.length := heqLen - _ = (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat := - hSchemaInputsLen - _ = 0 := hrawZero) - have hsecondLenNe : - (attesterSecondArrayLengthWord I).toNat ≠ 0 := by - rw [attesterSecondArrayLengthWord_toNat (I := I) hoff1] - exact hrawSecondNe - obtain ⟨a', k0, C0, hrem, rd0⟩ := - _houterLoopFirstGuard callargs hdecFull - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiAttestOuterSecondArrayAccessOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (base := ⟨128⟩) - (len := attesterFirstArrayLengthWord I) - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) hsecondLenNe - (by - simpa [attesterMultiAttestOuterArrayInitExitStack] - using rd0) - exact ⟨a', k1, C1, hrem, rd1⟩ - have _hinnerDecoderEntry : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨2353⟩ : UInt256) - [(UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨1019⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, - ⟨128⟩, attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨a', k0, C0, hrem, rd0⟩ := - _houterSecondArrayAccessOk callargs hdecFull - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiAttestFirstInnerArrayDecoderEntryFromOuterSecond - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) rd0 - exact ⟨a', k1, C1, hrem, rd1⟩ - have _hinnerDecoderReturn : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨1019⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, - ⟨128⟩, attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaInputs, _hSchemas, hSchemaInputs, - _hSchemasLen, _hSchemaInputsLen, hnonzero, heqLen⟩ := - attesterDecode_multiAttest_good_lengths_of_not_bad v - hbadDec hdecFull - have hSchemaInputsNe : schemaInputs.length ≠ 0 := by - intro hzero - exact hnonzero (by rw [heqLen, hzero]) - obtain ⟨n, relativeOffset, inner, innerEnd, valuesRest, restEnd, - _hlen, _hlenMax, hreadFirst, hinner, _hrest, - _hshape, _hend⟩ := - attesterDecode_multiAttest_first_inner_decode v - hdecFull hSchemaInputs hSchemaInputsNe - obtain ⟨hoffsetOk, hlenOk, hpayloadOk⟩ := - attesterFirstInnerArrayGuardFacts_of_decode - (I := I) (elem := .int uint256Int) - hoff1 hreadFirst - (by simpa [uint256] using hinner) - hsizeSigned - obtain ⟨a', k0, C0, hrem, rd0⟩ := - _hinnerDecoderEntry callargs hdecFull - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiAttestFirstInnerArrayOffsetOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hoffsetOk - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) - (by simpa [attesterSecondArrayPayloadStartWord] using rd0) - obtain ⟨k2, C2, rd2⟩ := - attesterX_multiAttestFirstInnerArrayLengthMaxOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hlenOk - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k1) (C := C1) rd1 - obtain ⟨k3, C3, rd3⟩ := - attesterX_multiAttestFirstInnerArrayPayloadOkToReturn - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hpayloadOk - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k2) (C := C2) rd2 - exact ⟨a', k3, C3, hrem, rd3⟩ - by_cases hzeroBranch : - ∃ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes - I.calldata = some callargs ∧ - attesterFirstInnerArrayLengthWord I = ⟨0⟩ - · rcases hzeroBranch with ⟨callargs, hdecFull, hinnerLenZeroWord⟩ - obtain ⟨schemas, schemaInputs, hSchemas, hSchemaInputs, - _hSchemasLen, _hSchemaInputsLen, hnonzero, heqLen⟩ := - attesterDecode_multiAttest_good_lengths_of_not_bad v - hbadDec hdecFull - have hSchemaInputsNe : schemaInputs.length ≠ 0 := by - intro hzero - exact hnonzero (by rw [heqLen, hzero]) - obtain ⟨n, relativeOffset, inner, innerEnd, valuesRest, restEnd, - _hlen, _hlenMax, hreadFirst, hinner, _hrest, - hshape, _hend⟩ := - attesterDecode_multiAttest_first_inner_decode v - hdecFull hSchemaInputs hSchemaInputsNe - have hinnerLenWord : - (attesterFirstInnerArrayLengthWord I).toNat = inner.length := - attesterFirstInnerArrayLengthWord_toNat_of_decode - (I := I) (elem := .int uint256Int) - hoff1 hreadFirst - (by simpa [uint256] using hinner) - hsizeSigned - have hinnerLenZero : inner.length = 0 := by - rw [← hinnerLenWord] - simp [hinnerLenZeroWord] - have hinnerNil : inner = [] := by - simpa using hinnerLenZero - have hshapeEmpty : schemaInputs = .array [] :: valuesRest := by - simpa [hinnerNil] using hshape - have hSchemaInputsEmpty : - callargs.get? "schemaInputs" = - some (.array (.array [] :: valuesRest)) := by - simpa [hshapeEmpty] using hSchemaInputs - have hSchemasLenEmpty : - schemas.length = (.array [] :: valuesRest).length := by - calc - schemas.length = schemaInputs.length := heqLen - _ = (.array [] :: valuesRest).length := by rw [hshapeEmpty] - obtain ⟨a', k3, C3, _hrem, rd3⟩ := - _hinnerDecoderReturn callargs hdecFull - have hrdrev := - attesterX_multiAttestFirstInnerArrayLengthZeroReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k3) (C := C3) - hinnerLenZeroWord rd3 - have hwvSolm : - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.weiValue = - ⟨0⟩ := by - simpa [initState] using hwv - have hbody := - attesterMultiAttestBodyFirstInputLengthZeroReverts v - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - callargs hwvSolm hSchemas hSchemaInputsEmpty hnonzero - hSchemasLenEmpty - exact hrdrev.reEquivExecutionRevert hIcode hd hdecFull hbody - · have _hfirstInnerNonemptyProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (⟨1083⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, ⟨0⟩, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ - (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaInputs, _hSchemas, hSchemaInputs, - _hSchemasLen, _hSchemaInputsLen, hnonzero, heqLen⟩ := - attesterDecode_multiAttest_good_lengths_of_not_bad v - hbadDec hdecFull - have hSchemaInputsNe : schemaInputs.length ≠ 0 := by - intro hzero - exact hnonzero (by rw [heqLen, hzero]) - obtain ⟨n, relativeOffset, inner, innerEnd, valuesRest, restEnd, - _hlen, _hlenMax, hreadFirst, hinner, _hrest, - _hshape, _hend⟩ := - attesterDecode_multiAttest_first_inner_decode v - hdecFull hSchemaInputs hSchemaInputsNe - obtain ⟨_hoffsetOk, hlenOk, _hpayloadOk⟩ := - attesterFirstInnerArrayGuardFacts_of_decode - (I := I) (elem := .int uint256Int) - hoff1 hreadFirst - (by simpa [uint256] using hinner) - hsizeSigned - have hinnerLenNeWord : - attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩ := by - intro hzero - exact hzeroBranch ⟨callargs, hdecFull, hzero⟩ - obtain ⟨a', k0, C0, hrem, rd0⟩ := - _hinnerDecoderReturn callargs hdecFull - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiAttestFirstInnerArrayNonemptyOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hinnerLenNeWord - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) rd0 - obtain ⟨k2, C2, rd2⟩ := - attesterX_multiAttestFirstInnerArrayLengthAllocMaxOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hlenOk - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k1) (C := C1) rd1 - exact ⟨a', k2, C2, hrem, rd2⟩ - have _hfirstInnerAllocProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (⟨1113⟩ : UInt256) - (((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) :: - attesterFirstInnerArrayLengthWord I :: - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') :: - ⟨0⟩ :: - attesterFirstInnerArrayLengthWord I :: - attesterFirstInnerArrayLengthWord I :: - (attesterFirstInnerArrayStartWord I + ⟨32⟩) :: - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, ⟨96⟩, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ - (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I]) - (attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - have hinnerLenNeWord : - attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩ := by - intro hzero - exact hzeroBranch ⟨callargs, hdecFull, hzero⟩ - exact attesterX_multiAttestFirstInnerArrayAllocProgress - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hinnerLenNeWord - (_hfirstInnerNonemptyProgress callargs hdecFull) - have _hfirstInnerInitProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' b' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (⟨1181⟩ : UInt256) - (attesterMultiAttestInnerArrayInitExitStack I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - b') - (attesterMultiAttestInnerArrayInitFinalMem b') - (attesterMultiAttestInnerArrayInitFinalAw b') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - have hinnerLenNeWord : - attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩ := by - intro hzero - exact hzeroBranch ⟨callargs, hdecFull, hzero⟩ - exact attesterX_multiAttestFirstInnerArrayInitProgress - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hinnerLenNeWord - (_hfirstInnerAllocProgress callargs hdecFull) - sorry - · have hpayload1Short : - I.calldata.size < - 4 + (calldataWord I.calldata 36).toNat + 32 + - 32 * (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat := by - omega - have hdec := attesterDecode_multiAttest_none_secondPayloadShort - v hsz68 hoff0 hlenWord hlenHuge hpayload hoff1 hlen1Word - hlen1Huge hpayload1Short - have hgt := - attesterSecondArrayPayloadGuardGtOne_of_short - (I := I) hoff1 hlen1Huge hsize hpayload1Short - exact (attesterX_secondArrayPayloadGuardReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hgt _hreach2076Second) - |>.reEquivDecodingFailed hIcode hd hdec - · have hshort1 : - I.calldata.size < 4 + (calldataWord I.calldata 36).toNat + 32 := by - omega - have hdec := attesterDecode_multiAttest_none_secondLengthShort - v hsz68 hoff0 hlenWord hlenHuge hpayload hoff1 hshort1 - have hslt := - attesterSecondArrayLengthGuardSltZero_of_short - (I := I) hoff1 hsizeSigned hshort1 - exact (attesterX_secondArrayLengthGuardReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hslt _hreach2038Second) - |>.reEquivDecodingFailed hIcode hd hdec - · have hpayloadShort : - I.calldata.size < - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat := by - omega - have hdec := attesterDecode_multiAttest_none_firstPayloadShort - v hsz68 hoff0 hlenWord hlenHuge hpayloadShort - have hgt := - attesterDynamicArrayPayloadGuardGtOne_of_short - (I := I) hoff0 hlenHuge hsize hpayloadShort - exact (attesterX_dynamicArrayPayloadGuardReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hgt _hreach2076) - |>.reEquivDecodingFailed hIcode hd hdec - · have hshortLen : - I.calldata.size < 4 + (calldataWord I.calldata 4).toNat + 32 := by - omega - have hdec := attesterDecode_multiAttest_none_firstLengthShort - v hsz68 hoff0 hshortLen - have hslt := - attesterDynamicArrayLengthGuardSltZero_of_short - (I := I) hoff0 hsizeSigned hshortLen - exact (attesterX_dynamicArrayLengthGuardReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hslt hreach2038) - |>.reEquivDecodingFailed hIcode hd hdec - · have hbigSigned : 2 ^ 255 ≤ I.calldata.size := by omega - have hdec := attesterDecode_multiAttest_none_totalHuge v hbigSigned - have hslt := - attesterDynamicArrayLengthGuardSltZero_of_sizeHuge - (I := I) hoff0 hbigSigned hsize - exact (attesterX_dynamicArrayLengthGuardReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hslt hreach2038) - |>.reEquivDecodingFailed hIcode hd hdec - · have hbig : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - have hdec := attesterDecode_multiAttest_none_huge v hbig - exact (attesterX_multiAttestDecodeHuge (g := Sat256.ofUInt256 g) v hIcode hwv hsz4 - hsize hbig hmultiRevoke hmultiAttest) - |>.reEquivDecodingFailed hIcode hd hdec - · have hshort : I.calldata.size < 68 := by omega - have hdec := attesterDecode_multiAttest_none_short v hsz4 hshort - exact (attesterX_multiAttestDecodeShort (g := Sat256.ofUInt256 g) v hIcode hwv hsz4 - hsize hshort hmultiRevoke hmultiAttest) - |>.reEquivDecodingFailed hIcode hd hdec - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/MultiRevoke.lean b/Benchmarks/EAS/Attester/MultiRevoke.lean deleted file mode 100644 index a8a19d12..00000000 --- a/Benchmarks/EAS/Attester/MultiRevoke.lean +++ /dev/null @@ -1,3088 +0,0 @@ -import Benchmarks.EAS.Attester.MultiSource -import Benchmarks.EAS.Attester.InnerArrayCopy -import Benchmarks.EAS.Attester.MultiRevokeMemory -import Benchmarks.EAS.Attester.MultiRevokeProgress -import Benchmarks.EAS.Attester.MultiRevokeEVM -import Benchmarks.EAS.Attester.MultiRevokePostCall -import Benchmarks.EAS.Attester.MultiRevokePostLoop -import Benchmarks.EAS.Attester.MultiRevokeContinuation -import Benchmarks.EAS.Attester.MultiRevokeLoopRun -import Benchmarks.EAS.Attester.MultiRevokeEncoderABI - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -/-! ## `multiRevoke(bytes32[],bytes32[][])` -/ - -theorem attesterDecode_multiRevoke_none_short (v : AttesterImmutables) {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 68) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - show decodeCalldata ["schemas", "schemaUids"] [bytes32Array, bytes32NestedArray] - I.calldata = none - unfold decodeCalldata - rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - rw [if_neg (by rintro ⟨_, hbig⟩; rw [htlen] at hbig; omega)] - rw [if_neg (by rintro ⟨_, hbig⟩; rw [List.length_drop, htlen] at hbig; omega)] - rw [if_neg (by rintro ⟨_, hbig⟩; rw [htlen] at hbig; omega)] - simp only [decodeCalldata.decodeArgs] - rw [show abiTupleHeadSize? [bytes32Array, bytes32NestedArray] = some 64 by native_decide] - simp only [bind, Option.bind] - have hargsShort : (I.calldata.toList.drop 4).length < 64 := by - rw [List.length_drop, htlen] - omega - rw [if_pos hargsShort] - -theorem attesterDecode_multiRevoke_none_huge (v : AttesterImmutables) {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - show decodeCalldata ["schemas", "schemaUids"] [bytes32Array, bytes32NestedArray] - I.calldata = none - unfold decodeCalldata - rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - rw [if_pos] - · exact ⟨by native_decide, by rw [htlen]; omega⟩ - -theorem attesterDecode_multiRevoke_none_totalHuge (v : AttesterImmutables) {I : ExecutionEnv} - (hbig : 2 ^ 255 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaUids"] [bytes32Array, bytes32NestedArray] - I.calldata = none - simpa [bytes32Array, bytes32NestedArray] using - attesterDecodeCalldata_twoDynamicArrays_none_totalHuge - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaUids") - (elem0 := bytes32) (elem1 := bytes32) hbig - -theorem attesterDecode_multiRevoke_none_firstOffsetHuge (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoff : solcMaxU64 < (calldataWord I.calldata 4).toNat) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaUids"] [bytes32Array, bytes32NestedArray] - I.calldata = none - simpa [bytes32Array, bytes32NestedArray] using - attesterDecodeCalldata_twoDynamicArrays_none_firstOffsetHuge - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaUids") - (elem0 := bytes32) (elem1 := bytes32) hsz68 hoff - -theorem attesterDecode_multiRevoke_none_firstLengthShort (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hshort : I.calldata.size < 4 + (calldataWord I.calldata 4).toNat + 32) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaUids"] [bytes32Array, bytes32NestedArray] - I.calldata = none - simpa [bytes32Array, bytes32NestedArray] using - attesterDecodeCalldata_twoDynamicArrays_none_firstLengthShort - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaUids") - (elem0 := bytes32) (elem1 := bytes32) hsz68 hoffMax hshort - -theorem attesterDecode_multiRevoke_none_firstLengthHuge (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlenWord : 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size) - (hlenHuge : solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaUids"] [bytes32Array, bytes32NestedArray] - I.calldata = none - simpa [bytes32Array, bytes32NestedArray] using - attesterDecodeCalldata_twoDynamicArrays_none_firstLengthHuge - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaUids") - (elem0 := bytes32) (elem1 := bytes32) hsz68 hoffMax hlenWord hlenHuge - -theorem attesterDecode_multiRevoke_none_firstPayloadShort (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlenWord : 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size) - (hlenMax : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hpayload : I.calldata.size < - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaUids"] [bytes32Array, bytes32NestedArray] - I.calldata = none - simpa [bytes32Array, bytes32NestedArray] using - attesterDecodeCalldata_twoDynamicArrays_none_firstBytes32PayloadShort - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaUids") - (elem1 := bytes32) hsz68 hoffMax hlenWord hlenMax hpayload - -theorem attesterDecode_multiRevoke_none_secondOffsetHuge (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlenWord : 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hpayload0 : - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ≤ - I.calldata.size) - (hoff1Huge : solcMaxU64 < (calldataWord I.calldata 36).toNat) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaUids"] [bytes32Array, bytes32NestedArray] - I.calldata = none - simpa [bytes32Array, bytes32NestedArray] using - attesterDecodeCalldata_twoDynamicArrays_none_secondOffsetHuge - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaUids") - (elem1 := bytes32) hsz68 hoff0Max hlenWord hlen0Max hpayload0 hoff1Huge - -theorem attesterDecode_multiRevoke_none_secondLengthShort (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlen0Word : 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hpayload0 : - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ≤ - I.calldata.size) - (hoff1Max : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hshort1 : I.calldata.size < 4 + (calldataWord I.calldata 36).toNat + 32) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaUids"] [bytes32Array, bytes32NestedArray] - I.calldata = none - simpa [bytes32Array, bytes32NestedArray] using - attesterDecodeCalldata_twoDynamicArrays_none_secondLengthShort - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaUids") - (elem1 := bytes32) hsz68 hoff0Max hlen0Word hlen0Max hpayload0 hoff1Max hshort1 - -theorem attesterDecode_multiRevoke_none_secondLengthHuge (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlen0Word : 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hpayload0 : - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ≤ - I.calldata.size) - (hoff1Max : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hlen1Word : 4 + (calldataWord I.calldata 36).toNat + 32 ≤ I.calldata.size) - (hlen1Huge : solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaUids"] [bytes32Array, bytes32NestedArray] - I.calldata = none - simpa [bytes32Array, bytes32NestedArray] using - attesterDecodeCalldata_twoDynamicArrays_none_secondLengthHuge - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaUids") - (elem1 := bytes32) hsz68 hoff0Max hlen0Word hlen0Max hpayload0 hoff1Max hlen1Word - hlen1Huge - -theorem attesterDecode_multiRevoke_none_secondPayloadShort (v : AttesterImmutables) - {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hlen0Word : 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hpayload0 : - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ≤ - I.calldata.size) - (hoff1Max : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hlen1Word : 4 + (calldataWord I.calldata 36).toNat + 32 ≤ I.calldata.size) - (hlen1Max : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) - (hpayload1 : - I.calldata.size < - 4 + (calldataWord I.calldata 36).toNat + 32 + - 32 * (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat) : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = none := by - show decodeCalldata ["schemas", "schemaUids"] [bytes32Array, bytes32NestedArray] - I.calldata = none - simpa [bytes32Array, bytes32NestedArray] using - attesterDecodeCalldata_twoDynamicArrays_none_secondPayloadShort - (cd := I.calldata) (name0 := "schemas") (name1 := "schemaUids") - (elem1 := bytes32) hsz68 hoff0Max hlen0Word hlen0Max hpayload0 hoff1Max hlen1Word - hlen1Max hpayload1 - -theorem attesterDecode_multiRevoke_some_shape (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) : - ∃ schemas schemaUids : List Value, - callargs.get? "schemas" = some (.array schemas) ∧ - callargs.get? "schemaUids" = some (.array schemaUids) := by - have hdec' : - decodeCalldata ["schemas", "schemaUids"] - [.dynamicArray bytes32, .dynamicArray (.dynamicArray bytes32)] I.calldata = - some callargs := by - simpa [decodeCalldataWithMode, config, multiRevokeTransition, transitionSignature, - bytes32Array, bytes32NestedArray] using hdec - exact attesterDecodeCalldata_twoDynamicArrays_shape - (name0 := "schemas") (name1 := "schemaUids") - (elem0 := bytes32) (elem1 := bytes32) (cd := I.calldata) - (by native_decide) hdec' - -theorem attesterDecode_multiRevoke_some_shape_lengths (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) : - ∃ schemas schemaUids : List Value, - callargs.get? "schemas" = some (.array schemas) ∧ - callargs.get? "schemaUids" = some (.array schemaUids) ∧ - schemas.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ∧ - schemaUids.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat := by - have hdec' : - decodeCalldata ["schemas", "schemaUids"] - [.dynamicArray bytes32, .dynamicArray (.dynamicArray bytes32)] I.calldata = - some callargs := by - simpa [decodeCalldataWithMode, config, multiRevokeTransition, transitionSignature, - bytes32Array, bytes32NestedArray] using hdec - exact attesterDecodeCalldata_twoDynamicArrays_lengths - (name0 := "schemas") (name1 := "schemaUids") - (elem1 := bytes32) (cd := I.calldata) - (by native_decide) hdec' - -theorem attesterDecode_multiRevoke_good_lengths_of_not_bad (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} - (hnotBad : - ¬ ∃ callargs schemas schemaUids, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs ∧ - callargs.get? "schemas" = some (.array schemas) ∧ - callargs.get? "schemaUids" = some (.array schemaUids) ∧ - schemas.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ∧ - schemaUids.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat ∧ - (schemas.length = 0 ∨ schemas.length ≠ schemaUids.length)) - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) : - ∃ schemas schemaUids : List Value, - callargs.get? "schemas" = some (.array schemas) ∧ - callargs.get? "schemaUids" = some (.array schemaUids) ∧ - schemas.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ∧ - schemaUids.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat ∧ - schemas.length ≠ 0 ∧ schemas.length = schemaUids.length := by - obtain ⟨schemas, schemaUids, hSchemas, hSchemaUids, hSchemasLen, hSchemaUidsLen⟩ := - attesterDecode_multiRevoke_some_shape_lengths v hdec - have hnonzero : schemas.length ≠ 0 := by - intro hzero - exact hnotBad ⟨callargs, schemas, schemaUids, hdec, hSchemas, hSchemaUids, - hSchemasLen, hSchemaUidsLen, Or.inl hzero⟩ - have heq : schemas.length = schemaUids.length := by - by_contra hne - exact hnotBad ⟨callargs, schemas, schemaUids, hdec, hSchemas, hSchemaUids, - hSchemasLen, hSchemaUidsLen, Or.inr hne⟩ - exact ⟨schemas, schemaUids, hSchemas, hSchemaUids, hSchemasLen, hSchemaUidsLen, - hnonzero, heq⟩ - -theorem attesterX_multiRevokeOuterArrayInitProgressWithFreeInvariant_raw - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (hoff0Max : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hoff1Max : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hlen0Max : ¬ solcMaxU64 < - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hrawFirstNe : - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0) - (hrawEq : - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨192⟩ : UInt256) - [attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterArrayInitExitStack I ⟨128⟩ - (attesterFirstArrayLengthWord I) a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C := by - have hnonzeroEvm := - attesterFirstArrayLengthWord_isZero_of_nat_ne_zero - (I := I) hoff0Max hrawFirstNe - have heqEvm := - attesterArrayLengthWords_eq_one_of_nat_eq - (I := I) hoff0Max hoff1Max hrawEq - have hguard := - attesterX_multiRevokeLengthGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hnonzeroEvm heqEvm hreach - have halloc := - attesterX_multiRevokeAllocLengthMaxOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hoff0Max hlen0Max hguard - have hentry := - attesterX_multiRevokeOuterArrayInitEntry - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hnonzeroEvm halloc - have hlenNe : (attesterFirstArrayLengthWord I).toNat ≠ 0 := by - rw [attesterFirstArrayLengthWord_toNat (I := I) hoff0Max] - exact hrawFirstNe - have hlenMax : (attesterFirstArrayLengthWord I).toNat ≤ solcMaxU64 := by - rw [attesterFirstArrayLengthWord_toNat (I := I) hoff0Max] - exact Nat.le_of_not_gt hlen0Max - exact - attesterX_multiRevokeOuterArrayInitProgressWithFreeInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hlenNe hlenMax hentry - -theorem attesterMultiRevokeBodySchemaGuardReverts (v : AttesterImmutables) - (evm : EVM.State) (locals : Store) {schemas schemaUids : List Value} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hSchemas : locals.get? "schemas" = some (.array schemas)) - (hSchemaUids : locals.get? "schemaUids" = some (.array schemaUids)) - (hbad : schemas.length = 0 ∨ schemas.length ≠ schemaUids.length) : - ExecTransitionBody (config v) (contract v) evm locals - (multiRevokeTransition v).body .reverted := by - have hSchemasElem : locals["schemas"]? = some (.array schemas) := by - rw [← Std.HashMap.get?_eq_getElem?] - exact hSchemas - have hSchemaUidsElem (n : Nat) : - (locals.insert "schemaLength" (.int (Int.ofNat n)))["schemaUids"]? = - some (.array schemaUids) := by - rw [Std.HashMap.getElem?_insert] - simp - rw [← Std.HashMap.get?_eq_getElem?] - exact hSchemaUids - refine ExecFuncBody.execBlockRevert ?_ - simp [multiRevokeTransition, nonpayable] - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl (value := .int (Int.ofNat schemas.length)) ?_) ?_ - · simp [evalExpr?, lenLocal, localRef, hSchemasElem, readLocalPath?, - EvalResult.bind, bind, pure] - · refine ExecBlock.consRevert (ExecStmt.requireFalse ?_) - exact attesterEvalMultiLengthGuardFalse (v := v) (evm := evm) (locals := locals) - (secondName := "schemaUids") (schemas := schemas) (second := schemaUids) - (hSchemaUidsElem schemas.length) hbad - -theorem attesterMultiRevokeBodyFirstUidLengthZeroReverts (v : AttesterImmutables) - (evm : EVM.State) (locals : Store) {schemas rest : List Value} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hSchemas : locals.get? "schemas" = some (.array schemas)) - (hSchemaUids : locals.get? "schemaUids" = some (.array (.array [] :: rest))) - (hSchemasNe : schemas.length ≠ 0) - (hSchemasLen : schemas.length = (.array [] :: rest).length) : - ExecTransitionBody (config v) (contract v) evm locals - (multiRevokeTransition v).body .reverted := by - have hSchemasElem : locals["schemas"]? = some (.array schemas) := by - rw [← Std.HashMap.get?_eq_getElem?] - exact hSchemas - refine ExecFuncBody.execBlockRevert ?_ - simp [multiRevokeTransition, nonpayable] - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl (value := .int (Int.ofNat schemas.length)) ?_) ?_ - · simp [evalExpr?, lenLocal, localRef, hSchemasElem, readLocalPath?, - EvalResult.bind, bind, pure] - · have hguard : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.binary .and - (.binary .ne (.var "schemaLength") (.intLit 0)) - (.binary .eq (.var "schemaLength") (lenLocal "schemaUids"))) = - .ok (.bool true) := by - have hleft : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.binary .ne (.var "schemaLength") (.intLit 0)) = - .ok (.bool true) := by - simp [evalExpr?, evalBinaryOp?, hSchemasNe, - EvalResult.bind, EvalResult.ofOption, bind, pure] - have hright : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.binary .eq (.var "schemaLength") (lenLocal "schemaUids")) = - .ok (.bool true) := by - have hSchemaUidsElem : - (locals.insert "schemaLength" (.int (Int.ofNat schemas.length)))["schemaUids"]? = - some (.array (.array [] :: rest)) := by - rw [Std.HashMap.getElem?_insert] - simp - rw [← Std.HashMap.get?_eq_getElem?] - exact hSchemaUids - have hSchemaUidsGet : - (locals.insert "schemaLength" (.int (Int.ofNat schemas.length))).get? - "schemaUids" = - some (.array (.array [] :: rest)) := by - simpa [Std.HashMap.get?_eq_getElem?] using hSchemaUidsElem - have hvar : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.var "schemaLength") = - .ok (.int (Int.ofNat schemas.length)) := by - simp [evalExpr?, EvalResult.ofOption] - have hlen : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (lenLocal "schemaUids") = - .ok (.int (Int.ofNat (.array [] :: rest).length)) := by - simp only [evalExpr?, lenLocal, localRef, readLocalPath?, EvalResult.bind, - bind, pure] - rw [hSchemaUidsGet] - rfl - have hop : - evalBinaryOp? .eq (.int (Int.ofNat schemas.length)) - (.int (Int.ofNat (.array [] :: rest).length)) = .ok (.bool true) := by - simp [evalBinaryOp?, hSchemasLen] - exact attesterEvalBinaryEq hvar hlen hop - exact attesterEvalAndTrue hleft hright - refine ExecBlock.consNormal (ExecStmt.requireTrue hguard) ?_ - let defaultRequest : Value := - .tuple [.fixedBytes bytes32Width (List.replicate 32 0), .array []] - let multiRequests : Value := - .array (List.replicate schemas.length defaultRequest) - have hmultiRequests : - evalExpr? (config v) - { contract := contract v, - locals := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) } evm - (.newArray multiRevocationRequestSt (.var "schemaLength")) = - .ok multiRequests := by - simp [multiRequests, defaultRequest, evalExpr?, multiRevocationRequestSt, - revocationRequestDataSt, bytes32St, uint256St, bytes32Width, - defaultValue?, defaultValues?, EvalResult.bind, EvalResult.ofOption, bind, pure] - refine ExecBlock.consNormal - (ExecStmt.letDecl (value := multiRequests) hmultiRequests) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (value := .int 0) ?_) ?_ - · simp [evalExpr?, pure] - · refine ExecBlock.consRevert (ExecStmt.whileRevert ?_ ?_) - · have hiEval : - evalExpr? (config v) - { contract := contract v, - locals := (((locals.insert "schemaLength" - (.int (Int.ofNat schemas.length))).insert - "multiRequests" multiRequests).insert "i" (.int 0)) } evm - (.var "i") = .ok (.int 0) := by - simp [evalExpr?, EvalResult.ofOption, Std.HashMap.get?_eq_getElem?] - have hschemaLengthEval : - evalExpr? (config v) - { contract := contract v, - locals := (((locals.insert "schemaLength" - (.int (Int.ofNat schemas.length))).insert - "multiRequests" multiRequests).insert "i" (.int 0)) } evm - (.var "schemaLength") = .ok (.int (Int.ofNat schemas.length)) := by - simp [evalExpr?, EvalResult.ofOption, Std.HashMap.get?_eq_getElem?, - Std.HashMap.getElem_insert] - have hposNat : 0 < schemas.length := Nat.pos_of_ne_zero hSchemasNe - have hpos : (0 : Int) < Int.ofNat schemas.length := by - exact Int.natCast_pos.mpr hposNat - have hop : - evalBinaryOp? .lt (.int 0) (.int (Int.ofNat schemas.length)) = - .ok (.bool true) := by - simpa [evalBinaryOp?, hpos] - exact attesterEvalBinaryLt hiEval hschemaLengthEval hop - · refine ExecBlock.consNormal (ExecStmt.letDecl (value := .array []) ?_) ?_ - · have hbaseEval : - evalExpr? (config v) - { contract := contract v, - locals := (((locals.insert "schemaLength" - (.int (Int.ofNat schemas.length))).insert - "multiRequests" multiRequests).insert "i" (.int 0)) } evm - (.var "schemaUids") = .ok (.array (.array [] :: rest)) := by - have hSchemaUidsGet : - ((((locals.insert "schemaLength" (.int (Int.ofNat schemas.length))).insert - "multiRequests" multiRequests).insert "i" (.int 0)).get? - "schemaUids") = - some (.array (.array [] :: rest)) := by - rw [Std.HashMap.get?_eq_getElem?] - rw [Std.HashMap.getElem?_insert] - simp - rw [Std.HashMap.getElem?_insert] - simp - rw [Std.HashMap.getElem?_insert] - simp - rw [← Std.HashMap.get?_eq_getElem?] - exact hSchemaUids - simp only [evalExpr?, EvalResult.ofOption] - rw [hSchemaUidsGet] - have hiEval : - evalExpr? (config v) - { contract := contract v, - locals := (((locals.insert "schemaLength" - (.int (Int.ofNat schemas.length))).insert - "multiRequests" multiRequests).insert "i" (.int 0)) } evm - (.var "i") = .ok (.int 0) := by - simp [evalExpr?, EvalResult.ofOption, Std.HashMap.get?_eq_getElem?] - have hindex : - evalIndex? (.array (.array [] :: rest)) (.int 0) = .ok (.array []) := by - simp [evalIndex?, normalizeRawBoolWord?] - rfl - exact attesterEvalIndex hbaseEval hiEval hindex - · refine ExecBlock.consNormal (ExecStmt.letDecl (value := .int 0) ?_) ?_ - · simp [evalExpr?, lenLocal, localRef, readLocalPath?, - EvalResult.bind, bind, pure] - · refine ExecBlock.consRevert (ExecStmt.requireFalse ?_) - simp [evalExpr?, evalBinaryOp?, - EvalResult.bind, EvalResult.ofOption, bind, pure] - -theorem attesterMultiRevokeBodySuccess (v : AttesterImmutables) - (evm evm' : EVM.State) (locals : Store) {schemas schemaUids : List Value} - {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hSchemas : locals.get? "schemas" = some (.array schemas)) - (hSchemaUids : locals.get? "schemaUids" = some (.array schemaUids)) - (hSchemasNe : schemas.length ≠ 0) - (hSchemasBound : schemas.length < 2 ^ 256) - (hLenEq : schemaUids.length = schemas.length) - (hSchemaNorm : ∀ {idx schema}, lookupNth? schemas idx = some schema → - normalizeRawBoolWord? schema = .ok schema) - (hUidssOk : ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length ≠ 0 ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid)) - (hguard : - ∀ locals' : Store, - locals'.get? "multiRequests" = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) → - evalExpr? (config v) { contract := contract v, locals := locals' } evm - (.binary .gt (.extCodeSize (easExpr v)) (.intLit 0)) = .ok (.bool true)) - (hcall : - ∀ locals' : Store, - locals'.get? "multiRequests" = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) → - typedCallViaEVM (config v) evm (EVM.address v.eas) "multiRevoke" 0 - [.array (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)] - (true, evm', out)) - (hdec : (config v).externalABI.decode? "multiRevoke" out = some []) : - ∃ loopLocals : Store, - loopLocals.get? "multiRequests" = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) ∧ - ExecTransitionBody (config v) (contract v) evm locals - (multiRevokeTransition v).body - (.returned - { contract := contract v, - locals := loopLocals.insert "_multiRevoke" (collapseReturns []) } evm' none) := by - let L1 := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) - have hschemaLengthExpr : - evalExpr? (config v) { contract := contract v, locals := locals } evm - (lenLocal "schemas") = .ok (.int (Int.ofNat schemas.length)) := - attesterEvalLocalArrayLength hSchemas - have hschemaLengthL1 : - L1.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) := by - simp [L1] - have hschemaUidsL1 : L1.get? "schemaUids" = some (.array schemaUids) := by - simpa [L1] using - (attesterStoreGetInsertOfNe (locals := locals) (name := "schemaUids") - (other := "schemaLength") (value := .int (Int.ofNat schemas.length)) - hSchemaUids (by decide)) - have hschemasL1 : L1.get? "schemas" = some (.array schemas) := by - simpa [L1] using - (attesterStoreGetInsertOfNe (locals := locals) (name := "schemas") - (other := "schemaLength") (value := .int (Int.ofNat schemas.length)) - hSchemas (by decide)) - have hguardSchema : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .and - (.binary .ne (.var "schemaLength") (.intLit 0)) - (.binary .eq (.var "schemaLength") (lenLocal "schemaUids"))) = - .ok (.bool true) := by - have hleft : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .ne (.var "schemaLength") (.intLit 0)) = - .ok (.bool true) := - attesterEvalUInt256NeZeroTrue (attesterEvalVarOfGet hschemaLengthL1) hSchemasNe - have hright : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .eq (.var "schemaLength") (lenLocal "schemaUids")) = - .ok (.bool true) := by - have hlenExpr : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (lenLocal "schemaUids") = .ok (.int (Int.ofNat schemaUids.length)) := - attesterEvalLocalArrayLength hschemaUidsL1 - have hop : - evalBinaryOp? .eq (.int (Int.ofNat schemas.length)) - (.int (Int.ofNat schemaUids.length)) = .ok (.bool true) := by - simp [evalBinaryOp?, hLenEq] - exact attesterEvalBinaryEq (attesterEvalVarOfGet hschemaLengthL1) hlenExpr hop - exact attesterEvalAndTrue hleft hright - have hmultiRequestsExpr : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.newArray multiRevocationRequestSt (.var "schemaLength")) = - .ok (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) := - attesterEvalNewMultiRevokeRequestArray (attesterEvalVarOfGet hschemaLengthL1) - let L2 := L1.insert "multiRequests" - (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) - have hschemasL2 : L2.get? "schemas" = some (.array schemas) := by - simpa [L2] using - (attesterStoreGetInsertOfNe (locals := L1) (name := "schemas") - (other := "multiRequests") - (value := .array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) - hschemasL1 (by decide)) - have hschemaUidsL2 : L2.get? "schemaUids" = some (.array schemaUids) := by - simpa [L2] using - (attesterStoreGetInsertOfNe (locals := L1) (name := "schemaUids") - (other := "multiRequests") - (value := .array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) - hschemaUidsL1 (by decide)) - have hschemaLengthL2 : - L2.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) := by - simpa [L2] using - (attesterStoreGetInsertOfNe (locals := L1) (name := "schemaLength") - (other := "multiRequests") - (value := .array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) - hschemaLengthL1 (by decide)) - have hrequestsL2 : - L2.get? "multiRequests" = - some (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) := by - simp [L2] - let L3 := L2.insert "i" (.int 0) - have hschemasL3 : L3.get? "schemas" = some (.array schemas) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "schemas") - (other := "i") (value := .int 0) hschemasL2 (by decide)) - have hschemaUidsL3 : L3.get? "schemaUids" = some (.array schemaUids) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "schemaUids") - (other := "i") (value := .int 0) hschemaUidsL2 (by decide)) - have hschemaLengthL3 : - L3.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "schemaLength") - (other := "i") (value := .int 0) hschemaLengthL2 (by decide)) - have hrequestsL3 : - L3.get? "multiRequests" = - some (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "multiRequests") - (other := "i") (value := .int 0) hrequestsL2 (by decide)) - have hiL3 : L3.get? "i" = some (.int 0) := by - simp [L3] - obtain ⟨loopLocals, hloop, hrequestsDone, _hiDone⟩ := - attesterMultiRevokeOuterSourceLoop - (imm := v) (evm := evm) (schemas := schemas) (schemaUids := schemaUids) - (locals := L3) hSchemasBound hLenEq hSchemaNorm hUidssOk - hschemasL3 hschemaUidsL3 hschemaLengthL3 hrequestsL3 hiL3 - have hargs : - evalExprs? (config v) { contract := contract v, locals := loopLocals } evm - [.var "multiRequests"] = - .ok - [.array (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)] := by - have hrequestsDoneElem : - loopLocals["multiRequests"]? = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) := by - rw [← Std.HashMap.get?_eq_getElem?] - exact hrequestsDone - simp [evalExprs?, evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, - hrequestsDoneElem] - have hiExpr : - evalExpr? (config v) { contract := contract v, locals := L2 } evm - (.intLit 0) = .ok (.int 0) := by - simp [evalExpr?, pure] - refine ⟨loopLocals, hrequestsDone, ExecFuncBody.execBlockOK ?_⟩ - simp [multiRevokeTransition, nonpayable] - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) ?_ - refine ExecBlock.consNormal (by simpa [L1] using ExecStmt.letDecl hschemaLengthExpr) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue hguardSchema) ?_ - refine ExecBlock.consNormal (by simpa [L2] using ExecStmt.letDecl hmultiRequestsExpr) ?_ - refine ExecBlock.consNormal (by simpa [L3] using ExecStmt.letDecl hiExpr) ?_ - refine ExecBlock.consNormal hloop ?_ - exact checkedExternalCallSuccess - (receiver := easExpr v) (retVar := "_multiRevoke") (name := "multiRevoke") - (sendVal := 0) (args := [.var "multiRequests"]) - (hguard loopLocals hrequestsDone) - (attesterEvalEasExpr v { contract := contract v, locals := loopLocals } evm) - hargs (hcall loopLocals hrequestsDone) hdec - -theorem attesterDecode_multiRevoke_return_ok (v : AttesterImmutables) (out : ByteArray) : - (config v).externalABI.decode? "multiRevoke" out = some [] := by - simp [config, attesterExternalABI, decodeVoid?] - -theorem attesterMultiRevokeBodyLoopSuccess (v : AttesterImmutables) - (evm evm' : EVM.State) (locals loopLocals : Store) {schemas schemaUids : List Value} - {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hSchemas : locals.get? "schemas" = some (.array schemas)) - (hSchemaUids : locals.get? "schemaUids" = some (.array schemaUids)) - (hSchemasNe : schemas.length ≠ 0) - (hLenEq : schemaUids.length = schemas.length) - (hloop : - ExecStmt (config v) - { contract := contract v, - locals := - (((locals.insert "schemaLength" (.int (Int.ofNat schemas.length))).insert - "multiRequests" - (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault))).insert - "i" (.int 0)) } evm - (.while attesterMultiRevokeOuterSourceLoopCond attesterMultiRevokeOuterSourceLoopBody) - (.ok { contract := contract v, locals := loopLocals } evm)) - (hrequestsDone : - loopLocals.get? "multiRequests" = - some (.array (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids))) - (hguard : - ∀ locals' : Store, - locals'.get? "multiRequests" = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) → - evalExpr? (config v) { contract := contract v, locals := locals' } evm - (.binary .gt (.extCodeSize (easExpr v)) (.intLit 0)) = .ok (.bool true)) - (hcall : - ∀ locals' : Store, - locals'.get? "multiRequests" = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) → - typedCallViaEVM (config v) evm (EVM.address v.eas) "multiRevoke" 0 - [.array (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)] - (true, evm', out)) - (hdec : (config v).externalABI.decode? "multiRevoke" out = some []) : - ExecTransitionBody (config v) (contract v) evm locals - (multiRevokeTransition v).body - (.returned - { contract := contract v, - locals := loopLocals.insert "_multiRevoke" (collapseReturns []) } evm' none) := by - let L1 := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) - have hschemaLengthExpr : - evalExpr? (config v) { contract := contract v, locals := locals } evm - (lenLocal "schemas") = .ok (.int (Int.ofNat schemas.length)) := - attesterEvalLocalArrayLength hSchemas - have hschemaLengthL1 : - L1.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) := by - simp [L1] - have hschemaUidsL1 : L1.get? "schemaUids" = some (.array schemaUids) := by - simpa [L1] using - (attesterStoreGetInsertOfNe (locals := locals) (name := "schemaUids") - (other := "schemaLength") (value := .int (Int.ofNat schemas.length)) - hSchemaUids (by decide)) - have hguardSchema : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .and - (.binary .ne (.var "schemaLength") (.intLit 0)) - (.binary .eq (.var "schemaLength") (lenLocal "schemaUids"))) = - .ok (.bool true) := by - have hleft : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .ne (.var "schemaLength") (.intLit 0)) = - .ok (.bool true) := - attesterEvalUInt256NeZeroTrue (attesterEvalVarOfGet hschemaLengthL1) hSchemasNe - have hright : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .eq (.var "schemaLength") (lenLocal "schemaUids")) = - .ok (.bool true) := by - have hlenExpr : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (lenLocal "schemaUids") = .ok (.int (Int.ofNat schemaUids.length)) := - attesterEvalLocalArrayLength hschemaUidsL1 - have hop : - evalBinaryOp? .eq (.int (Int.ofNat schemas.length)) - (.int (Int.ofNat schemaUids.length)) = .ok (.bool true) := by - simp [evalBinaryOp?, hLenEq] - exact attesterEvalBinaryEq (attesterEvalVarOfGet hschemaLengthL1) hlenExpr hop - exact attesterEvalAndTrue hleft hright - have hmultiRequestsExpr : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.newArray multiRevocationRequestSt (.var "schemaLength")) = - .ok (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) := - attesterEvalNewMultiRevokeRequestArray (attesterEvalVarOfGet hschemaLengthL1) - let L2 := L1.insert "multiRequests" - (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) - have hiExpr : - evalExpr? (config v) { contract := contract v, locals := L2 } evm - (.intLit 0) = .ok (.int 0) := by - simp [evalExpr?, pure] - have hargs : - evalExprs? (config v) { contract := contract v, locals := loopLocals } evm - [.var "multiRequests"] = - .ok - [.array (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)] := by - have hrequestsDoneElem : - loopLocals["multiRequests"]? = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) := by - rw [← Std.HashMap.get?_eq_getElem?] - exact hrequestsDone - simp [evalExprs?, evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, - hrequestsDoneElem] - refine ExecFuncBody.execBlockOK ?_ - simp [multiRevokeTransition, nonpayable] - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) ?_ - refine ExecBlock.consNormal (by simpa [L1] using ExecStmt.letDecl hschemaLengthExpr) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue hguardSchema) ?_ - refine ExecBlock.consNormal (by simpa [L2] using ExecStmt.letDecl hmultiRequestsExpr) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl hiExpr) ?_ - refine ExecBlock.consNormal (by simpa [L1, L2] using hloop) ?_ - exact checkedExternalCallSuccess - (receiver := easExpr v) (retVar := "_multiRevoke") (name := "multiRevoke") - (sendVal := 0) (args := [.var "multiRequests"]) - (hguard loopLocals hrequestsDone) - (attesterEvalEasExpr v { contract := contract v, locals := loopLocals } evm) - hargs (hcall loopLocals hrequestsDone) hdec - -theorem attesterMultiRevokeBodyLoopCallFailure (v : AttesterImmutables) - (evm evm' : EVM.State) (locals loopLocals : Store) {schemas schemaUids : List Value} - {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hSchemas : locals.get? "schemas" = some (.array schemas)) - (hSchemaUids : locals.get? "schemaUids" = some (.array schemaUids)) - (hSchemasNe : schemas.length ≠ 0) - (hLenEq : schemaUids.length = schemas.length) - (hloop : - ExecStmt (config v) - { contract := contract v, - locals := - (((locals.insert "schemaLength" (.int (Int.ofNat schemas.length))).insert - "multiRequests" - (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault))).insert - "i" (.int 0)) } evm - (.while attesterMultiRevokeOuterSourceLoopCond attesterMultiRevokeOuterSourceLoopBody) - (.ok { contract := contract v, locals := loopLocals } evm)) - (hrequestsDone : - loopLocals.get? "multiRequests" = - some (.array (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids))) - (hguard : - ∀ locals' : Store, - locals'.get? "multiRequests" = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) → - evalExpr? (config v) { contract := contract v, locals := locals' } evm - (.binary .gt (.extCodeSize (easExpr v)) (.intLit 0)) = .ok (.bool true)) - (hcall : - ∀ locals' : Store, - locals'.get? "multiRequests" = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) → - typedCallViaEVM (config v) evm (EVM.address v.eas) "multiRevoke" 0 - [.array (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)] - (false, evm', out)) : - ExecTransitionBody (config v) (contract v) evm locals - (multiRevokeTransition v).body .reverted := by - let L1 := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) - have hschemaLengthExpr : - evalExpr? (config v) { contract := contract v, locals := locals } evm - (lenLocal "schemas") = .ok (.int (Int.ofNat schemas.length)) := - attesterEvalLocalArrayLength hSchemas - have hschemaLengthL1 : - L1.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) := by - simp [L1] - have hschemaUidsL1 : L1.get? "schemaUids" = some (.array schemaUids) := by - simpa [L1] using - (attesterStoreGetInsertOfNe (locals := locals) (name := "schemaUids") - (other := "schemaLength") (value := .int (Int.ofNat schemas.length)) - hSchemaUids (by decide)) - have hguardSchema : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .and - (.binary .ne (.var "schemaLength") (.intLit 0)) - (.binary .eq (.var "schemaLength") (lenLocal "schemaUids"))) = - .ok (.bool true) := by - have hleft : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .ne (.var "schemaLength") (.intLit 0)) = - .ok (.bool true) := - attesterEvalUInt256NeZeroTrue (attesterEvalVarOfGet hschemaLengthL1) hSchemasNe - have hright : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .eq (.var "schemaLength") (lenLocal "schemaUids")) = - .ok (.bool true) := by - have hlenExpr : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (lenLocal "schemaUids") = .ok (.int (Int.ofNat schemaUids.length)) := - attesterEvalLocalArrayLength hschemaUidsL1 - have hop : - evalBinaryOp? .eq (.int (Int.ofNat schemas.length)) - (.int (Int.ofNat schemaUids.length)) = .ok (.bool true) := by - simp [evalBinaryOp?, hLenEq] - exact attesterEvalBinaryEq (attesterEvalVarOfGet hschemaLengthL1) hlenExpr hop - exact attesterEvalAndTrue hleft hright - have hmultiRequestsExpr : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.newArray multiRevocationRequestSt (.var "schemaLength")) = - .ok (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) := - attesterEvalNewMultiRevokeRequestArray (attesterEvalVarOfGet hschemaLengthL1) - let L2 := L1.insert "multiRequests" - (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) - have hiExpr : - evalExpr? (config v) { contract := contract v, locals := L2 } evm - (.intLit 0) = .ok (.int 0) := by - simp [evalExpr?, pure] - have hargs : - evalExprs? (config v) { contract := contract v, locals := loopLocals } evm - [.var "multiRequests"] = - .ok - [.array (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)] := by - have hrequestsDoneElem : - loopLocals["multiRequests"]? = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) := by - rw [← Std.HashMap.get?_eq_getElem?] - exact hrequestsDone - simp [evalExprs?, evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, - hrequestsDoneElem] - refine ExecFuncBody.execBlockRevert ?_ - simp [multiRevokeTransition, nonpayable] - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) ?_ - refine ExecBlock.consNormal (by simpa [L1] using ExecStmt.letDecl hschemaLengthExpr) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue hguardSchema) ?_ - refine ExecBlock.consNormal (by simpa [L2] using ExecStmt.letDecl hmultiRequestsExpr) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl hiExpr) ?_ - refine ExecBlock.consNormal (by simpa [L1, L2] using hloop) ?_ - exact checkedExternalCallFailure - (receiver := easExpr v) (retVar := "_multiRevoke") (name := "multiRevoke") - (sendVal := 0) (args := [.var "multiRequests"]) - (hguard loopLocals hrequestsDone) - (attesterEvalEasExpr v { contract := contract v, locals := loopLocals } evm) - hargs (hcall loopLocals hrequestsDone) - -theorem attesterMultiRevokeBodyLoopNoCode (v : AttesterImmutables) - (evm : EVM.State) (locals loopLocals : Store) {schemas schemaUids : List Value} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hSchemas : locals.get? "schemas" = some (.array schemas)) - (hSchemaUids : locals.get? "schemaUids" = some (.array schemaUids)) - (hSchemasNe : schemas.length ≠ 0) - (hLenEq : schemaUids.length = schemas.length) - (hloop : - ExecStmt (config v) - { contract := contract v, - locals := - (((locals.insert "schemaLength" (.int (Int.ofNat schemas.length))).insert - "multiRequests" - (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault))).insert - "i" (.int 0)) } evm - (.while attesterMultiRevokeOuterSourceLoopCond attesterMultiRevokeOuterSourceLoopBody) - (.ok { contract := contract v, locals := loopLocals } evm)) - (hrequestsDone : - loopLocals.get? "multiRequests" = - some (.array (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids))) - (hguard : - ∀ locals' : Store, - locals'.get? "multiRequests" = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) → - evalExpr? (config v) { contract := contract v, locals := locals' } evm - (.binary .gt (.extCodeSize (easExpr v)) (.intLit 0)) = .ok (.bool false)) : - ExecTransitionBody (config v) (contract v) evm locals - (multiRevokeTransition v).body .reverted := by - let L1 := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) - have hschemaLengthExpr : - evalExpr? (config v) { contract := contract v, locals := locals } evm - (lenLocal "schemas") = .ok (.int (Int.ofNat schemas.length)) := - attesterEvalLocalArrayLength hSchemas - have hschemaLengthL1 : - L1.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) := by - simp [L1] - have hschemaUidsL1 : L1.get? "schemaUids" = some (.array schemaUids) := by - simpa [L1] using - (attesterStoreGetInsertOfNe (locals := locals) (name := "schemaUids") - (other := "schemaLength") (value := .int (Int.ofNat schemas.length)) - hSchemaUids (by decide)) - have hguardSchema : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .and - (.binary .ne (.var "schemaLength") (.intLit 0)) - (.binary .eq (.var "schemaLength") (lenLocal "schemaUids"))) = - .ok (.bool true) := by - have hleft : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .ne (.var "schemaLength") (.intLit 0)) = - .ok (.bool true) := - attesterEvalUInt256NeZeroTrue (attesterEvalVarOfGet hschemaLengthL1) hSchemasNe - have hright : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .eq (.var "schemaLength") (lenLocal "schemaUids")) = - .ok (.bool true) := by - have hlenExpr : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (lenLocal "schemaUids") = .ok (.int (Int.ofNat schemaUids.length)) := - attesterEvalLocalArrayLength hschemaUidsL1 - have hop : - evalBinaryOp? .eq (.int (Int.ofNat schemas.length)) - (.int (Int.ofNat schemaUids.length)) = .ok (.bool true) := by - simp [evalBinaryOp?, hLenEq] - exact attesterEvalBinaryEq (attesterEvalVarOfGet hschemaLengthL1) hlenExpr hop - exact attesterEvalAndTrue hleft hright - have hmultiRequestsExpr : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.newArray multiRevocationRequestSt (.var "schemaLength")) = - .ok (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) := - attesterEvalNewMultiRevokeRequestArray (attesterEvalVarOfGet hschemaLengthL1) - let L2 := L1.insert "multiRequests" - (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) - have hiExpr : - evalExpr? (config v) { contract := contract v, locals := L2 } evm - (.intLit 0) = .ok (.int 0) := by - simp [evalExpr?, pure] - refine ExecFuncBody.execBlockRevert ?_ - simp [multiRevokeTransition, nonpayable] - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) ?_ - refine ExecBlock.consNormal (by simpa [L1] using ExecStmt.letDecl hschemaLengthExpr) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue hguardSchema) ?_ - refine ExecBlock.consNormal (by simpa [L2] using ExecStmt.letDecl hmultiRequestsExpr) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl hiExpr) ?_ - refine ExecBlock.consNormal (by simpa [L1, L2] using hloop) ?_ - exact checkedExternalCallNoCode - (receiver := easExpr v) (retVar := "_multiRevoke") (name := "multiRevoke") - (sendVal := 0) (args := [.var "multiRequests"]) - (hguard loopLocals hrequestsDone) - -theorem attesterMultiRevokeBodyLoopReverts (v : AttesterImmutables) - (evm : EVM.State) (locals : Store) {schemas schemaUids : List Value} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hSchemas : locals.get? "schemas" = some (.array schemas)) - (hSchemaUids : locals.get? "schemaUids" = some (.array schemaUids)) - (hSchemasNe : schemas.length ≠ 0) - (hLenEq : schemaUids.length = schemas.length) - (hloop : - ExecStmt (config v) - { contract := contract v, - locals := - (((locals.insert "schemaLength" (.int (Int.ofNat schemas.length))).insert - "multiRequests" - (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault))).insert - "i" (.int 0)) } evm - (.while attesterMultiRevokeOuterSourceLoopCond attesterMultiRevokeOuterSourceLoopBody) - .reverted) : - ExecTransitionBody (config v) (contract v) evm locals - (multiRevokeTransition v).body .reverted := by - let L1 := locals.insert "schemaLength" (.int (Int.ofNat schemas.length)) - have hschemaLengthExpr : - evalExpr? (config v) { contract := contract v, locals := locals } evm - (lenLocal "schemas") = .ok (.int (Int.ofNat schemas.length)) := - attesterEvalLocalArrayLength hSchemas - have hschemaLengthL1 : - L1.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) := by - simp [L1] - have hschemaUidsL1 : L1.get? "schemaUids" = some (.array schemaUids) := by - simpa [L1] using - (attesterStoreGetInsertOfNe (locals := locals) (name := "schemaUids") - (other := "schemaLength") (value := .int (Int.ofNat schemas.length)) - hSchemaUids (by decide)) - have hguardSchema : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .and - (.binary .ne (.var "schemaLength") (.intLit 0)) - (.binary .eq (.var "schemaLength") (lenLocal "schemaUids"))) = - .ok (.bool true) := by - have hleft : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .ne (.var "schemaLength") (.intLit 0)) = - .ok (.bool true) := - attesterEvalUInt256NeZeroTrue (attesterEvalVarOfGet hschemaLengthL1) hSchemasNe - have hright : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.binary .eq (.var "schemaLength") (lenLocal "schemaUids")) = - .ok (.bool true) := by - have hlenExpr : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (lenLocal "schemaUids") = .ok (.int (Int.ofNat schemaUids.length)) := - attesterEvalLocalArrayLength hschemaUidsL1 - have hop : - evalBinaryOp? .eq (.int (Int.ofNat schemas.length)) - (.int (Int.ofNat schemaUids.length)) = .ok (.bool true) := by - simp [evalBinaryOp?, hLenEq] - exact attesterEvalBinaryEq (attesterEvalVarOfGet hschemaLengthL1) hlenExpr hop - exact attesterEvalAndTrue hleft hright - have hmultiRequestsExpr : - evalExpr? (config v) { contract := contract v, locals := L1 } evm - (.newArray multiRevocationRequestSt (.var "schemaLength")) = - .ok (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) := - attesterEvalNewMultiRevokeRequestArray (attesterEvalVarOfGet hschemaLengthL1) - let L2 := L1.insert "multiRequests" - (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) - have hiExpr : - evalExpr? (config v) { contract := contract v, locals := L2 } evm - (.intLit 0) = .ok (.int 0) := by - simp [evalExpr?, pure] - refine ExecFuncBody.execBlockRevert ?_ - simp [multiRevokeTransition, nonpayable] - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) ?_ - refine ExecBlock.consNormal (by simpa [L1] using ExecStmt.letDecl hschemaLengthExpr) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue hguardSchema) ?_ - refine ExecBlock.consNormal (by simpa [L2] using ExecStmt.letDecl hmultiRequestsExpr) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl hiExpr) ?_ - simpa [L1, L2] using ExecBlock.consRevert hloop - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevoke_postEncoder_fromDone - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (v : AttesterImmutables) {callargs LDone LStart : Store} - {schemas schemaUids : List Value} - {endPtr outerBase schemaLen secondLen secondPayload schemaPayload selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (hIcode : I.code = patchedRuntime v) - (hd : dispatchMsg (contract v) I.calldata = some (multiRevokeTransition v)) - (hdec : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hperm : I.perm = true) - (hwv : I.weiValue = ⟨0⟩) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hSchemas : callargs.get? "schemas" = some (.array schemas)) - (hSchemaUids : callargs.get? "schemaUids" = some (.array schemaUids)) - (hSchemasNe : schemas.length ≠ 0) - (hLenEq : schemaUids.length = schemas.length) - (hLStart : - LStart = - (((callargs.insert "schemaLength" (.int (Int.ofNat schemas.length))).insert - "multiRequests" - (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault))).insert - "i" (.int 0))) - (hloop : - ExecStmt (config v) { contract := contract v, locals := LStart } - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (.while attesterMultiRevokeOuterSourceLoopCond attesterMultiRevokeOuterSourceLoopBody) - (.ok { contract := contract v, locals := LDone } - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I))) - (hrequestsDone : - LDone.get? "multiRequests" = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids))) - (rd775 : - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨775⟩ : UInt256) - [endPtr, attesterMultiRevokeSelectorLow, attesterMultiRevokeTargetWord v, - outerBase, schemaLen, secondLen, secondPayload, schemaLen, schemaPayload, - ⟨97⟩, selector] - mem aw ByteArray.empty (cA, σ_evm) k C) - (hcd : - (config v).externalABI.encode? "multiRevoke" - [.array (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)] = - some - (mem.readWithPadding (attesterMultiRevokeCallFree mem aw).toNat - (UInt256.sub endPtr (attesterMultiRevokeCallFree mem aw)).toNat)) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl - σ_evm σ_solm σ₀ g A I := by - let gS : Sat256 := Sat256.ofUInt256 g - let evmEvm : EVM.State := initState cA gh bl σ_evm σ₀ gS A I - let evmSolm : EVM.State := initState cA gh bl σ_solm σ₀ gS A I - have hwvSolm : evmSolm.executionEnv.weiValue = ⟨0⟩ := by - simpa [evmSolm, initState, gS] using hwv - have hloopForBody : - ExecStmt (config v) - { contract := contract v, - locals := - (((callargs.insert "schemaLength" (.int (Int.ofNat schemas.length))).insert - "multiRequests" - (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault))).insert - "i" (.int 0)) } evmSolm - (.while attesterMultiRevokeOuterSourceLoopCond attesterMultiRevokeOuterSourceLoopBody) - (.ok { contract := contract v, locals := LDone } evmSolm) := by - simpa [evmSolm, gS, hLStart] using hloop - obtain ⟨k787, C787, rd787⟩ := - attesterX_multiRevokeEncoderReturnToExtcodesize - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := gS) v rd775 - by_cases hcodeSizeEvm : - Reasoning.Theory.extCodeSizeWord σ_evm - (attesterMultiRevokeTargetWord v) = ⟨0⟩ - · have hrdrev := - attesterX_multiRevokeNoCodeAtExtcodesize - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := gS) v rd787 hcodeSizeEvm (by simp) - have hcodeSizeSolm : - Reasoning.Theory.extCodeSizeWord σ_solm - (attesterMultiRevokeTargetWord v) = ⟨0⟩ := - attesterMultiRevokeCodeSize_zero_accountMapEquiv v hAccounts hcodeSizeEvm - have hcodeSolmRaw := - attesterMultiRevokeEasCode_zero_of_codeSize_zero - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := gS) v hcodeSizeSolm - have haddr : EVM.address v.eas = v.eas := by - apply Fin.ext - simp [EVM.address, EVM.uintN] - exact Nat.mod_eq_of_lt v.eas.isLt - have hcodeSolm : - (UInt256.ofNat - ((evmSolm.lookupAccount v.eas).option 0 (fun acc => acc.code.size))).toNat = - 0 := by - simpa [evmSolm, haddr] using hcodeSolmRaw - have hguard : - ∀ locals' : Store, - locals'.get? "multiRequests" = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) → - evalExpr? (config v) { contract := contract v, locals := locals' } evmSolm - (.binary .gt (.extCodeSize (easExpr v)) (.intLit 0)) = .ok (.bool false) := by - intro locals' _hrequests - exact attesterMultiRevokeEvalExtCodeGuard_false v - (attesterEvalEasExpr v { contract := contract v, locals := locals' } evmSolm) - hcodeSolm - have hbody := - attesterMultiRevokeBodyLoopNoCode v evmSolm callargs LDone - hwvSolm hSchemas hSchemaUids hSchemasNe hLenEq hloopForBody - hrequestsDone hguard - exact hrdrev.reEquivExecutionRevert hIcode hd hdec hbody - · have hcodeSizeSolmNe : - Reasoning.Theory.extCodeSizeWord σ_solm - (attesterMultiRevokeTargetWord v) ≠ ⟨0⟩ := - attesterMultiRevokeCodeSize_ne_accountMapEquiv v hAccounts hcodeSizeEvm - have hcodeSolmRaw := - attesterMultiRevokeEasCode_pos_of_codeSize_ne - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := gS) v hcodeSizeSolmNe - have haddr : EVM.address v.eas = v.eas := by - apply Fin.ext - simp [EVM.address, EVM.uintN] - exact Nat.mod_eq_of_lt v.eas.isLt - have hcodeSolm : - 0 < (UInt256.ofNat - ((evmSolm.lookupAccount v.eas).option 0 (fun acc => acc.code.size))).toNat := by - simpa [evmSolm, haddr] using hcodeSolmRaw - have hguard : - ∀ locals' : Store, - locals'.get? "multiRequests" = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) → - evalExpr? (config v) { contract := contract v, locals := locals' } evmSolm - (.binary .gt (.extCodeSize (easExpr v)) (.intLit 0)) = .ok (.bool true) := by - intro locals' _hrequests - exact attesterMultiRevokeEvalExtCodeGuard_true v - (attesterEvalEasExpr v { contract := contract v, locals := locals' } evmSolm) - hcodeSolm - by_cases hdepth : I.depth.val < 1024 - · obtain ⟨cA', σ', z, o, A', k802, C802, rd802, hcallEvm, hosize⟩ := - attesterX_multiRevokeCallAtExtcodesize - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := gS) v - (args := [.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)]) - rd787 hcodeSizeEvm (attesterMultiRevokeTarget_eq v) hcd hperm hdepth - (by simp) - let evmPostEvm : EVM.State := - { evmEvm with accountMap := σ', substate := A', createdAccounts := cA' } - have hcallEvm' : - typedCallViaEVM (config v) evmEvm (EVM.address v.eas) "multiRevoke" 0 - [.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)] - (z, evmPostEvm, o) true := by - simpa [evmEvm, evmPostEvm, gS] using hcallEvm - obtain ⟨σSolmPost, ASolmPost, hcallSolm, hStateCall⟩ := - typedCallViaEVM_initState_EVMStateEquiv (hcall := hcallEvm') - (by simp [evmEvm, evmPostEvm, initState, gS]) hAccounts - let evmPostSolm : EVM.State := - { evmSolm with - accountMap := σSolmPost, substate := ASolmPost, createdAccounts := cA' } - have hcallSolm' : - typedCallViaEVM (config v) evmSolm (EVM.address v.eas) "multiRevoke" 0 - [.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)] - (z, evmPostSolm, o) true := by - simpa [evmPostSolm] using hcallSolm - have hStateCall' : EVMStateEquiv evmPostEvm evmPostSolm := by - simpa [evmPostSolm] using hStateCall - cases z - · simp only [Bool.false_eq_true, if_false] at rd802 hcallSolm' - have hrdrev := attesterX_multiRevokePostRevert (v := v) rd802 hosize (by simp) - have hbody := - attesterMultiRevokeBodyLoopCallFailure v evmSolm evmPostSolm - callargs LDone hwvSolm hSchemas hSchemaUids hSchemasNe hLenEq - hloopForBody hrequestsDone hguard (fun _ _ => hcallSolm') - exact hrdrev.reEquivExecutionRevert hIcode hd hdec hbody - · simp only [if_true] at rd802 hcallSolm' - have hrdret := attesterX_multiRevokeSuccessStop (v := v) rd802 - have hretdec := attesterDecode_multiRevoke_return_ok v o - have hbody := - attesterMultiRevokeBodyLoopSuccess v evmSolm evmPostSolm - callargs LDone hwvSolm hSchemas hSchemaUids hSchemasNe hLenEq - hloopForBody hrequestsDone hguard (fun _ _ => hcallSolm') hretdec - have henc : - returnEquiv ByteArray.empty none (multiRevokeTransition v).returnType := by - rw [show (multiRevokeTransition v).returnType = [] by rfl] - exact returnEquiv.fallthrough rfl (by rfl) (by native_decide) - exact hrdret.reEquivExecutionGenEVMStateEquiv hIcode hd hdec hbody - rfl (accountMapEquiv.refl σ') hStateCall' henc - · have hdepth1024 : I.depth = 1024 := by - apply Fin.ext - have hlt := I.depth.isLt - rw [not_lt] at hdepth - omega - have hrdrev := - attesterX_multiRevokeCallDepthLimitAtExtcodesize - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := gS) v rd787 hcodeSizeEvm hdepth1024 - (by simp) - have hdepthInit : evmSolm.executionEnv.depth = 1024 := by - simpa [evmSolm, initState, gS] using hdepth1024 - have hcallSolm : - typedCallViaEVM (config v) evmSolm (EVM.address v.eas) "multiRevoke" 0 - [.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)] - (false, - { evmSolm with - substate := (evmSolm.addAccessedAccount (EVM.address v.eas)).substate }, - ByteArray.empty) - true := - callNotMade_depthLimit - (cfg := config v) (evm := evmSolm) (tgt := EVM.address v.eas) - (name := "multiRevoke") - (args := [.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)]) - (callPerm := true) hcd hdepthInit - have hbody := - attesterMultiRevokeBodyLoopCallFailure v evmSolm - ({ evmSolm with - substate := (evmSolm.addAccessedAccount (EVM.address v.eas)).substate }) - callargs LDone hwvSolm hSchemas hSchemaUids hSchemasNe hLenEq - hloopForBody hrequestsDone hguard (fun _ _ => hcallSolm) - exact hrdrev.reEquivExecutionRevert hIcode hd hdec hbody - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevokeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (v : AttesterImmutables) {code : ByteArray} - (hpatch : patchRuntime attesterBytecode (patches v) = some code) - (hcode : I.code = code) - (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) - (hwv : I.weiValue = ⟨0⟩) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hpatched : code = patchedRuntime v := code_eq_patchedRuntime_of_patch hpatch - have hIcode : I.code = patchedRuntime v := hcode.trans hpatched - have hsz4 : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I attesterMultiRevokeSelBytes attesterMultiRevokeSelBytes_size - hmultiRevoke - have hd := attesterDispatch_multiRevoke v hmultiRevoke - by_cases hsz68 : 68 ≤ I.calldata.size - · by_cases hsmall : I.calldata.size < 2 ^ 255 + 4 - · by_cases hoff0 : solcMaxU64 < (calldataWord I.calldata 4).toNat - · have hdec := attesterDecode_multiRevoke_none_firstOffsetHuge v hsz68 hoff0 - have hreach2128 := - attesterX_multiRevokeDecodeHeadOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hIcode hwv hsz4 hsize hsz68 hsmall hmultiRevoke - exact (attesterX_dynamic2FirstOffsetHugeReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff0 hreach2128) - |>.reEquivDecodingFailed hIcode hd hdec - · have hreach2128 := - attesterX_multiRevokeDecodeHeadOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hIcode hwv hsz4 hsize hsz68 hsmall hmultiRevoke - have hreach2149 := - attesterX_dynamic2FirstOffsetOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff0 hreach2128 - have hreach2038 := - attesterX_dynamic2FirstArrayDecoderEntry - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hreach2149 - by_cases hsizeSigned : I.calldata.size < 2 ^ 255 - · by_cases hlenWord : - 4 + (calldataWord I.calldata 4).toNat + 32 ≤ I.calldata.size - · have _hreach2054 := - attesterX_dynamicArrayLengthGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff0 hsizeSigned hlenWord hreach2038 - by_cases hlenHuge : solcMaxU64 < - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat - · have hdec := attesterDecode_multiRevoke_none_firstLengthHuge - v hsz68 hoff0 hlenWord hlenHuge - exact (attesterX_dynamicArrayLengthMaxHugeReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff0 hlenHuge _hreach2054) - |>.reEquivDecodingFailed hIcode hd hdec - · have _hreach2076 := - attesterX_dynamicArrayLengthMaxOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff0 hlenHuge _hreach2054 - by_cases hpayload : - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ≤ - I.calldata.size - · have hgt := - attesterDynamicArrayPayloadGuardGtZero_of_ok - (I := I) hoff0 hlenHuge hsize hpayload - have _hreach2102 := - attesterX_dynamicArrayPayloadGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hgt _hreach2076 - have _hreach2161 := - attesterX_dynamicArrayPayloadOkToFirstReturn - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v _hreach2102 - by_cases hoff1 : solcMaxU64 < (calldataWord I.calldata 36).toNat - · have hdec := attesterDecode_multiRevoke_none_secondOffsetHuge - v hsz68 hoff0 hlenWord hlenHuge hpayload hoff1 - exact (attesterX_dynamic2SecondOffsetHugeReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff1 _hreach2161) - |>.reEquivDecodingFailed hIcode hd hdec - · have _hreach2191 := - attesterX_dynamic2SecondOffsetOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff1 _hreach2161 - have _hreach2038Second := - attesterX_dynamic2SecondArrayDecoderEntry - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v _hreach2191 - by_cases hlen1Word : - 4 + (calldataWord I.calldata 36).toNat + 32 ≤ I.calldata.size - · have _hreach2054Second := - attesterX_secondArrayLengthGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff1 hsizeSigned hlen1Word _hreach2038Second - by_cases hlen1Huge : solcMaxU64 < - (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat - · have hdec := attesterDecode_multiRevoke_none_secondLengthHuge - v hsz68 hoff0 hlenWord hlenHuge hpayload hoff1 hlen1Word hlen1Huge - exact (attesterX_secondArrayLengthMaxHugeReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff1 hlen1Huge _hreach2054Second) - |>.reEquivDecodingFailed hIcode hd hdec - · have _hreach2076Second := - attesterX_secondArrayLengthMaxOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hoff1 hlen1Huge _hreach2054Second - by_cases hpayload1 : - 4 + (calldataWord I.calldata 36).toNat + 32 + - 32 * (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat ≤ - I.calldata.size - · have hgt := - attesterSecondArrayPayloadGuardGtZero_of_ok - (I := I) hoff1 hlen1Huge hsize hpayload1 - have _hreach2102Second := - attesterX_secondArrayPayloadGuardOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hgt _hreach2076Second - have _hreach2203 := - attesterX_secondArrayPayloadOkToSecondReturn - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v _hreach2102Second - have _hreachDecoded := - attesterX_dynamic2DecodeDone - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v (attesterMultiRevokeDecodedJumpdest v) _hreach2203 - have _hreachBody := - attesterX_multiRevokeDecodedToBody - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v _hreachDecoded - by_cases hbadDec : - ∃ callargs schemas schemaUids, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs ∧ - callargs.get? "schemas" = some (.array schemas) ∧ - callargs.get? "schemaUids" = some (.array schemaUids) ∧ - schemas.length = - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ∧ - schemaUids.length = - (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat ∧ - (schemas.length = 0 ∨ schemas.length ≠ schemaUids.length) - · rcases hbadDec with - ⟨callargs, schemas, schemaUids, hdecFull, hSchemas, hSchemaUids, - hSchemasLen, hSchemaUidsLen, hbad⟩ - have hwvSolm : - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.weiValue = - ⟨0⟩ := by - simpa [initState] using hwv - by_cases hzeroSchemas : schemas.length = 0 - · have hrawZero : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat = 0 := by - omega - have hzeroEvm := - attesterFirstArrayLengthWord_isZero_of_nat_eq_zero - (I := I) hoff0 hrawZero - have hrdrev := - attesterX_multiRevokeLengthZeroReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hzeroEvm _hreachBody - have hbody := - attesterMultiRevokeBodySchemaGuardReverts v - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - callargs hwvSolm hSchemas hSchemaUids (Or.inl hzeroSchemas) - exact hrdrev.reEquivExecutionRevert hIcode hd hdecFull hbody - · by_cases heqSchemas : schemas.length = schemaUids.length - · exfalso - rcases hbad with hzero | hne - · exact hzeroSchemas hzero - · exact hne heqSchemas - · have hrawFirstNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hzeroSchemas (by omega) - have hrawNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat ≠ - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat := by - intro hrawEq - exact heqSchemas (by omega) - have hnonzeroEvm := - attesterFirstArrayLengthWord_isZero_of_nat_ne_zero - (I := I) hoff0 hrawFirstNe - have hneqEvm := - attesterArrayLengthWords_eq_zero_of_nat_ne - (I := I) hoff0 hoff1 hrawNe - have hrdrev := - attesterX_multiRevokeLengthMismatchReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hnonzeroEvm hneqEvm - _hreachBody - have hbody := - attesterMultiRevokeBodySchemaGuardReverts v - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - callargs hwvSolm hSchemas hSchemaUids (Or.inr heqSchemas) - exact hrdrev.reEquivExecutionRevert hIcode hd hdecFull hbody - · have _hguardProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ k C, RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨236⟩ : UInt256) - [attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, _hSchemaUids, - hSchemasLen, hSchemaUidsLen, hnonzero, heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - exact attesterX_multiRevokeLengthGuardOk_of_lengths - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hoff0 hoff1 hSchemasLen - hSchemaUidsLen hnonzero heqLen _hreachBody - have _hallocProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ k C, RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨261⟩ : UInt256) - [attesterFirstArrayLengthWord I, ⟨0⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ_evm) k C := by - intro callargs hdecFull - exact attesterX_multiRevokeAllocLengthMaxOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hoff0 hlenHuge - (_hguardProgress callargs hdecFull) - have _hinitProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ k C, RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨291⟩ : UInt256) - [((⟨32⟩ : UInt256) + ⟨128⟩), - attesterFirstArrayLengthWord I, ⟨128⟩, ⟨0⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayAllocMem I) (UInt256.ofNat 5) - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, _hSchemaUids, - hSchemasLen, _hSchemaUidsLen, hnonzero, _heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hrawFirstNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by omega) - have hnonzeroEvm := - attesterFirstArrayLengthWord_isZero_of_nat_ne_zero - (I := I) hoff0 hrawFirstNe - exact attesterX_multiRevokeOuterArrayInitEntry - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hnonzeroEvm - (_hallocProgress callargs hdecFull) - have _houterInitProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterArrayInitExitStack I - ⟨128⟩ (attesterFirstArrayLengthWord I) a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, _hSchemaUids, - _hSchemasLen, _hSchemaUidsLen, hnonzero, _heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hrawFirstNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by omega) - have hlenNe : - (attesterFirstArrayLengthWord I).toNat ≠ 0 := by - rw [attesterFirstArrayLengthWord_toNat (I := I) hoff0] - exact hrawFirstNe - obtain ⟨k0, C0, rd0⟩ := _hinitProgress callargs hdecFull - exact attesterX_multiRevokeOuterArrayInitLoop - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (slot := ((⟨32⟩ : UInt256) + ⟨128⟩)) - (base := ⟨128⟩) - (len := attesterFirstArrayLengthWord I) - (mem := attesterMultiOuterArrayAllocMem I) - (aw := UInt256.ofNat 5) (k := k0) (C := C0) hlenNe rd0 - have _houterInitProgressFree : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterArrayInitExitStack I - ⟨128⟩ (attesterFirstArrayLengthWord I) a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, _hSchemaUids, - hSchemasLen, _hSchemaUidsLen, hnonzero, _heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hrawFirstNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by omega) - have hlenNe : - (attesterFirstArrayLengthWord I).toNat ≠ 0 := by - rw [attesterFirstArrayLengthWord_toNat (I := I) hoff0] - exact hrawFirstNe - have hlenMaxWord : - (attesterFirstArrayLengthWord I).toNat ≤ solcMaxU64 := by - rw [attesterFirstArrayLengthWord_toNat (I := I) hoff0] - omega - exact attesterX_multiRevokeOuterArrayInitProgressWithFreeInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - hlenNe hlenMaxWord (_hinitProgress callargs hdecFull) - have _houterLoopFirstGuard : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨344⟩ : UInt256) - (attesterMultiRevokeOuterArrayInitExitStack I - ⟨128⟩ (attesterFirstArrayLengthWord I) a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, _hSchemaUids, - _hSchemasLen, _hSchemaUidsLen, hnonzero, _heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hrawFirstNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by omega) - have hlenNe : - (attesterFirstArrayLengthWord I).toNat ≠ 0 := by - rw [attesterFirstArrayLengthWord_toNat (I := I) hoff0] - exact hrawFirstNe - obtain ⟨a', k0, C0, hrem, rd0⟩ := - _houterInitProgress callargs hdecFull - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokeOuterSourceLoopFirstGuard - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (base := ⟨128⟩) - (len := attesterFirstArrayLengthWord I) - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) hlenNe - (by - simpa [attesterMultiRevokeOuterArrayInitExitStack] - using rd0) - exact ⟨a', k1, C1, hrem, by - simpa [attesterMultiRevokeOuterArrayInitExitStack] - using rd1⟩ - have _houterLoopFirstGuardFree : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨344⟩ : UInt256) - (attesterMultiRevokeOuterArrayInitExitStack I - ⟨128⟩ (attesterFirstArrayLengthWord I) a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, _hSchemaUids, - _hSchemasLen, _hSchemaUidsLen, hnonzero, _heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hrawFirstNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by omega) - have hlenNe : - (attesterFirstArrayLengthWord I).toNat ≠ 0 := by - rw [attesterFirstArrayLengthWord_toNat (I := I) hoff0] - exact hrawFirstNe - exact attesterX_multiRevokeOuterSourceLoopFirstGuardWithInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (attesterMultiRevokeOuterInitFreeInv I 0) - hlenNe (_houterInitProgressFree callargs hdecFull) - have _houterSecondArrayAccessCheck : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨355⟩ : UInt256) - [⟨363⟩, ⟨1⟩, ⟨0⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, _hSchemaUids, - _hSchemasLen, hSchemaUidsLen, hnonzero, heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hrawSecondNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by - calc - schemas.length = schemaUids.length := heqLen - _ = (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat := - hSchemaUidsLen - _ = 0 := hrawZero) - have hsecondLenNe : - (attesterSecondArrayLengthWord I).toNat ≠ 0 := by - rw [attesterSecondArrayLengthWord_toNat (I := I) hoff1] - exact hrawSecondNe - obtain ⟨a', k0, C0, hrem, rd0⟩ := - _houterLoopFirstGuard callargs hdecFull - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokeOuterSecondArrayAccessCheck - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (base := ⟨128⟩) - (len := attesterFirstArrayLengthWord I) - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) hsecondLenNe - (by - simpa [attesterMultiRevokeOuterArrayInitExitStack] - using rd0) - exact ⟨a', k1, C1, hrem, rd1⟩ - have _houterSecondArrayAccessOk : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨363⟩ : UInt256) - [⟨0⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, _hSchemaUids, - _hSchemasLen, hSchemaUidsLen, hnonzero, heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hrawSecondNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by - calc - schemas.length = schemaUids.length := heqLen - _ = (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat := - hSchemaUidsLen - _ = 0 := hrawZero) - have hsecondLenNe : - (attesterSecondArrayLengthWord I).toNat ≠ 0 := by - rw [attesterSecondArrayLengthWord_toNat (I := I) hoff1] - exact hrawSecondNe - obtain ⟨a', k0, C0, hrem, rd0⟩ := - _houterLoopFirstGuard callargs hdecFull - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokeOuterSecondArrayAccessOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (base := ⟨128⟩) - (len := attesterFirstArrayLengthWord I) - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) hsecondLenNe - (by - simpa [attesterMultiRevokeOuterArrayInitExitStack] - using rd0) - exact ⟨a', k1, C1, hrem, rd1⟩ - have _houterSecondArrayAccessOkFree : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨363⟩ : UInt256) - [⟨0⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, _hSchemaUids, - _hSchemasLen, hSchemaUidsLen, hnonzero, heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hrawSecondNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat ≠ 0 := by - intro hrawZero - exact hnonzero (by - calc - schemas.length = schemaUids.length := heqLen - _ = (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat := - hSchemaUidsLen - _ = 0 := hrawZero) - have hsecondLenNe : - (attesterSecondArrayLengthWord I).toNat ≠ 0 := by - rw [attesterSecondArrayLengthWord_toNat (I := I) hoff1] - exact hrawSecondNe - exact attesterX_multiRevokeOuterSecondArrayAccessOkWithInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (attesterMultiRevokeOuterInitFreeInv I 0) - hsecondLenNe - (_houterLoopFirstGuardFree callargs hdecFull) - have _hinnerDecoderEntry : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨2353⟩ : UInt256) - [(UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, - ⟨128⟩, attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨a', k0, C0, hrem, rd0⟩ := - _houterSecondArrayAccessOk callargs hdecFull - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokeFirstInnerArrayDecoderEntryFromOuterSecond - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) rd0 - exact ⟨a', k1, C1, hrem, rd1⟩ - have _hinnerDecoderEntryFree : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨2353⟩ : UInt256) - [(UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, - ⟨128⟩, attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - exact attesterX_multiRevokeFirstInnerArrayDecoderEntryWithInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (attesterMultiRevokeOuterInitFreeInv I 0) - (_houterSecondArrayAccessOkFree callargs hdecFull) - have _hinnerDecoderReturn : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨381⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, - ⟨128⟩, attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, hSchemaUids, - _hSchemasLen, _hSchemaUidsLen, hnonzero, heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hSchemaUidsNe : schemaUids.length ≠ 0 := by - intro hzero - exact hnonzero (by rw [heqLen, hzero]) - obtain ⟨n, relativeOffset, inner, innerEnd, valuesRest, restEnd, - _hlen, _hlenMax, hreadFirst, hinner, _hrest, - _hshape, _hend⟩ := - attesterDecode_multiRevoke_first_inner_decode v - hdecFull hSchemaUids hSchemaUidsNe - obtain ⟨hoffsetOk, hlenOk, hpayloadOk⟩ := - attesterFirstInnerArrayGuardFacts_of_decode - (I := I) (elem := .bytes bytes32Width) - hoff1 hreadFirst - (by simpa [bytes32] using hinner) - hsizeSigned - obtain ⟨a', k0, C0, hrem, rd0⟩ := - _hinnerDecoderEntry callargs hdecFull - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokeFirstInnerArrayOffsetOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hoffsetOk - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) - (by simpa [attesterSecondArrayPayloadStartWord] using rd0) - obtain ⟨k2, C2, rd2⟩ := - attesterX_multiRevokeFirstInnerArrayLengthMaxOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hlenOk - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k1) (C := C1) rd1 - obtain ⟨k3, C3, rd3⟩ := - attesterX_multiRevokeFirstInnerArrayPayloadOkToReturn - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hpayloadOk - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k2) (C := C2) rd2 - exact ⟨a', k3, C3, hrem, rd3⟩ - have _hinnerDecoderReturnFree : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (⟨381⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, - ⟨128⟩, attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, hSchemaUids, - _hSchemasLen, _hSchemaUidsLen, hnonzero, heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hSchemaUidsNe : schemaUids.length ≠ 0 := by - intro hzero - exact hnonzero (by rw [heqLen, hzero]) - obtain ⟨n, relativeOffset, inner, innerEnd, valuesRest, restEnd, - _hlen, _hlenMax, hreadFirst, hinner, _hrest, - _hshape, _hend⟩ := - attesterDecode_multiRevoke_first_inner_decode v - hdecFull hSchemaUids hSchemaUidsNe - obtain ⟨hoffsetOk, hlenOk, hpayloadOk⟩ := - attesterFirstInnerArrayGuardFacts_of_decode - (I := I) (elem := .bytes bytes32Width) - hoff1 hreadFirst - (by simpa [bytes32] using hinner) - hsizeSigned - exact attesterX_multiRevokeFirstInnerArrayDecoderReturnWithInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (attesterMultiRevokeOuterInitFreeInv I 0) - hoffsetOk hlenOk hpayloadOk - (_hinnerDecoderEntryFree callargs hdecFull) - by_cases hzeroBranch : - ∃ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs ∧ - attesterFirstInnerArrayLengthWord I = ⟨0⟩ - · rcases hzeroBranch with ⟨callargs, hdecFull, hinnerLenZeroWord⟩ - obtain ⟨schemas, schemaUids, hSchemas, hSchemaUids, - _hSchemasLen, _hSchemaUidsLen, hnonzero, heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hSchemaUidsNe : schemaUids.length ≠ 0 := by - intro hzero - exact hnonzero (by rw [heqLen, hzero]) - obtain ⟨n, relativeOffset, inner, innerEnd, valuesRest, restEnd, - _hlen, _hlenMax, hreadFirst, hinner, _hrest, - hshape, _hend⟩ := - attesterDecode_multiRevoke_first_inner_decode v - hdecFull hSchemaUids hSchemaUidsNe - have hinnerLenWord : - (attesterFirstInnerArrayLengthWord I).toNat = inner.length := - attesterFirstInnerArrayLengthWord_toNat_of_decode - (I := I) (elem := .bytes bytes32Width) - hoff1 hreadFirst - (by simpa [bytes32] using hinner) - hsizeSigned - have hinnerLenZero : inner.length = 0 := by - rw [← hinnerLenWord] - simp [hinnerLenZeroWord] - have hinnerNil : inner = [] := by - simpa using hinnerLenZero - have hshapeEmpty : schemaUids = .array [] :: valuesRest := by - simpa [hinnerNil] using hshape - have hSchemaUidsEmpty : - callargs.get? "schemaUids" = - some (.array (.array [] :: valuesRest)) := by - simpa [hshapeEmpty] using hSchemaUids - have hSchemasLenEmpty : - schemas.length = (.array [] :: valuesRest).length := by - calc - schemas.length = schemaUids.length := heqLen - _ = (.array [] :: valuesRest).length := by rw [hshapeEmpty] - obtain ⟨a', k3, C3, _hrem, rd3⟩ := - _hinnerDecoderReturn callargs hdecFull - have hrdrev := - attesterX_multiRevokeFirstInnerArrayLengthZeroReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k3) (C := C3) - hinnerLenZeroWord rd3 - have hwvSolm : - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.weiValue = - ⟨0⟩ := by - simpa [initState] using hwv - have hbody := - attesterMultiRevokeBodyFirstUidLengthZeroReverts v - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - callargs hwvSolm hSchemas hSchemaUidsEmpty hnonzero - hSchemasLenEmpty - exact hrdrev.reEquivExecutionRevert hIcode hd hdecFull hbody - · have _hfirstInnerNonemptyProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (⟨445⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, ⟨0⟩, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ - (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, hSchemaUids, - _hSchemasLen, _hSchemaUidsLen, hnonzero, heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hSchemaUidsNe : schemaUids.length ≠ 0 := by - intro hzero - exact hnonzero (by rw [heqLen, hzero]) - obtain ⟨n, relativeOffset, inner, innerEnd, valuesRest, restEnd, - _hlen, _hlenMax, hreadFirst, hinner, _hrest, - _hshape, _hend⟩ := - attesterDecode_multiRevoke_first_inner_decode v - hdecFull hSchemaUids hSchemaUidsNe - obtain ⟨_hoffsetOk, hlenOk, _hpayloadOk⟩ := - attesterFirstInnerArrayGuardFacts_of_decode - (I := I) (elem := .bytes bytes32Width) - hoff1 hreadFirst - (by simpa [bytes32] using hinner) - hsizeSigned - have hinnerLenNeWord : - attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩ := by - intro hzero - exact hzeroBranch ⟨callargs, hdecFull, hzero⟩ - obtain ⟨a', k0, C0, hrem, rd0⟩ := - _hinnerDecoderReturn callargs hdecFull - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokeFirstInnerArrayNonemptyOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hinnerLenNeWord - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) rd0 - obtain ⟨k2, C2, rd2⟩ := - attesterX_multiRevokeFirstInnerArrayLengthAllocMaxOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hlenOk - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k1) (C := C1) rd1 - exact ⟨a', k2, C2, hrem, rd2⟩ - have _hfirstInnerNonemptyProgressFree : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (⟨445⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, ⟨0⟩, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ - (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, hSchemaUids, - _hSchemasLen, _hSchemaUidsLen, hnonzero, heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hSchemaUidsNe : schemaUids.length ≠ 0 := by - intro hzero - exact hnonzero (by rw [heqLen, hzero]) - obtain ⟨n, relativeOffset, inner, innerEnd, valuesRest, restEnd, - _hlen, _hlenMax, hreadFirst, hinner, _hrest, - _hshape, _hend⟩ := - attesterDecode_multiRevoke_first_inner_decode v - hdecFull hSchemaUids hSchemaUidsNe - obtain ⟨_hoffsetOk, hlenOk, _hpayloadOk⟩ := - attesterFirstInnerArrayGuardFacts_of_decode - (I := I) (elem := .bytes bytes32Width) - hoff1 hreadFirst - (by simpa [bytes32] using hinner) - hsizeSigned - have hinnerLenNeWord : - attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩ := by - intro hzero - exact hzeroBranch ⟨callargs, hdecFull, hzero⟩ - exact attesterX_multiRevokeFirstInnerArrayNonemptyProgressWithInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (attesterMultiRevokeOuterInitFreeInv I 0) - hinnerLenNeWord hlenOk - (_hinnerDecoderReturnFree callargs hdecFull) - have _hfirstInnerAllocProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (⟨475⟩ : UInt256) - (((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) :: - attesterFirstInnerArrayLengthWord I :: - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') :: - ⟨0⟩ :: - attesterFirstInnerArrayLengthWord I :: - attesterFirstInnerArrayLengthWord I :: - (attesterFirstInnerArrayStartWord I + ⟨32⟩) :: - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ - (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I]) - (attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - have hinnerLenNeWord : - attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩ := by - intro hzero - exact hzeroBranch ⟨callargs, hdecFull, hzero⟩ - exact attesterX_multiRevokeFirstInnerArrayAllocProgress - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hinnerLenNeWord - (_hfirstInnerNonemptyProgress callargs hdecFull) - have _hfirstInnerAllocProgressFree : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (⟨475⟩ : UInt256) - (((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) :: - attesterFirstInnerArrayLengthWord I :: - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') :: - ⟨0⟩ :: - attesterFirstInnerArrayLengthWord I :: - attesterFirstInnerArrayLengthWord I :: - (attesterFirstInnerArrayStartWord I + ⟨32⟩) :: - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ - (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I]) - (attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - have hinnerLenNeWord : - attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩ := by - intro hzero - exact hzeroBranch ⟨callargs, hdecFull, hzero⟩ - exact attesterX_multiRevokeFirstInnerArrayAllocProgressWithInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (attesterMultiRevokeOuterInitFreeInv I 0) - hinnerLenNeWord - (_hfirstInnerNonemptyProgressFree callargs hdecFull) - have _hfirstInnerInitProgress : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' b' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (⟨518⟩ : UInt256) - (attesterMultiRevokeInnerArrayInitExitStack I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - b') - (attesterMultiRevokeInnerArrayInitFinalMem b') - (attesterMultiRevokeInnerArrayInitFinalAw b') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - have hinnerLenNeWord : - attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩ := by - intro hzero - exact hzeroBranch ⟨callargs, hdecFull, hzero⟩ - exact attesterX_multiRevokeFirstInnerArrayInitProgress - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hinnerLenNeWord - (_hfirstInnerAllocProgress callargs hdecFull) - have _hfirstInnerInitProgressFree : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' b' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeInnerInitReadInv I a' 0 b' ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (⟨518⟩ : UInt256) - (attesterMultiRevokeInnerArrayInitExitStack I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - b') - (attesterMultiRevokeInnerArrayInitFinalMem b') - (attesterMultiRevokeInnerArrayInitFinalAw b') - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, hSchemaUids, - _hSchemasLen, _hSchemaUidsLen, hnonzero, heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hSchemaUidsNe : schemaUids.length ≠ 0 := by - intro hzero - exact hnonzero (by rw [heqLen, hzero]) - obtain ⟨n, relativeOffset, inner, innerEnd, valuesRest, restEnd, - _hlen, _hinnerMax, hreadFirst, hinner, _hrest, - _hshape, _hend⟩ := - attesterDecode_multiRevoke_first_inner_decode v - hdecFull hSchemaUids hSchemaUidsNe - have hinnerLenNeWord : - attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩ := by - intro hzero - exact hzeroBranch ⟨callargs, hdecFull, hzero⟩ - have hinnerLenMaxWord : - (attesterFirstInnerArrayLengthWord I).toNat ≤ solcMaxU64 := - attesterFirstInnerArrayLengthWord_le_solcMaxU64_of_decode - (I := I) (elem := .bytes bytes32Width) - hoff1 hreadFirst - (by simpa [bytes32] using hinner) - hsizeSigned - exact attesterX_multiRevokeFirstInnerArrayInitProgressWithReadInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - hinnerLenNeWord hinnerLenMaxWord - (_hfirstInnerAllocProgressFree callargs hdecFull) - have _hfirstInnerCopyProgressFree : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' b' c' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeInnerInitReadInv I a' 0 b' ∧ - c'.idx = attesterFirstInnerArrayLengthWord I ∧ - attesterMultiRevokeInnerCopyReadInv I a' b' 0 c' ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (⟨608⟩ : UInt256) - (attesterMultiRevokeInnerArrayCopyStack - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ - (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - c') - c'.mem c'.aw - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - exact attesterX_multiRevokeFirstInnerArrayCopyProgressWithReadStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (_hfirstInnerInitProgressFree callargs hdecFull) - have _hfirstOuterLoopProgressFree : - ∀ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs → - ∃ a' b' c' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeInnerInitReadInv I a' 0 b' ∧ - c'.idx = attesterFirstInnerArrayLengthWord I ∧ - attesterMultiRevokeInnerCopyReadInv I a' b' 0 c' ∧ - RD (patchedRuntime v) I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (⟨335⟩ : UInt256) - [attesterMultiRevokePostCopyNextIdx (⟨0⟩ : UInt256), - ⟨128⟩, attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ - (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiRevokePostCopyOuterMem - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ⟨128⟩ I - ((UInt256.add ⟨4⟩ - (calldataWord I.calldata 4)) + ⟨32⟩) - (⟨0⟩ : UInt256) c'.mem c'.aw) - (attesterMultiRevokePostCopyOuterAw - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ⟨128⟩ I - ((UInt256.add ⟨4⟩ - (calldataWord I.calldata 4)) + ⟨32⟩) - (⟨0⟩ : UInt256) c'.mem c'.aw) - ByteArray.empty (cA, σ_evm) k C := by - intro callargs hdecFull - obtain ⟨schemas, schemaUids, _hSchemas, _hSchemaUids, - hSchemasLen, _hSchemaUidsLen, hnonzero, _heqLen⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hrawFirstNe : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat ≠ - 0 := by - intro hrawZero - exact hnonzero (by omega) - have hlenNe : - (attesterFirstArrayLengthWord I).toNat ≠ 0 := by - rw [attesterFirstArrayLengthWord_toNat (I := I) hoff0] - exact hrawFirstNe - have hidxSchema : - UInt256.lt (⟨0⟩ : UInt256) - (attesterFirstArrayLengthWord I) = ⟨1⟩ := - attesterUInt256_lt_zero_of_toNat_ne_zero hlenNe - exact - attesterX_multiRevokeFirstInnerCopyToOuterLoopWithReadInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hidxSchema - (_hfirstInnerCopyProgressFree callargs hdecFull) - by_cases hdecSome : - ∃ callargs, - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = some callargs - · rcases hdecSome with ⟨callargs, hdecFull⟩ - obtain ⟨schemas, schemaUids, hSchemas, hSchemaUids, - hSchemasLen, hSchemaUidsLen, hSchemasNe, hLenEqRaw⟩ := - attesterDecode_multiRevoke_good_lengths_of_not_bad v - hbadDec hdecFull - have hSchemasLenMax : schemas.length ≤ solcMaxU64 := by - rw [hSchemasLen] - exact Nat.le_of_not_gt hlenHuge - have hSchemasBound : schemas.length < 2 ^ 256 := by - exact lt_of_le_of_lt hSchemasLenMax (by native_decide) - have hLenEq : schemaUids.length = schemas.length := hLenEqRaw.symm - have hSchemaNorm : - ∀ {idx schema}, lookupNth? schemas idx = some schema → - normalizeRawBoolWord? schema = .ok schema := by - intro idx schema hlookup - exact attesterDecode_multiRevoke_schema_norm v - hdecFull hSchemas hlookup - have hUidssShape : - ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid) := by - intro idx value hlookup - exact attesterDecode_multiRevoke_schemaUids_shape v - hdecFull hSchemaUids hlookup - obtain ⟨cursor, L, k0, C0, hL, hInv0, rd335⟩ := - attesterX_multiRevokeOuterInitToLoopInv - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - hSchemas hSchemaUids hSchemasLen hSchemaUidsLen - hoff0 hoff1 hSchemasLenMax - (_houterInitProgressFree callargs hdecFull) - have hInv0Solm : - AttesterMultiRevokeOuterLoopInv cA σ_evm I schemas schemaUids - schemas.length cursor L - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) := by - simpa [AttesterMultiRevokeOuterLoopInv] using hInv0 - have hloopResult := - AttesterMultiRevokeOuterLoopInv.run_or_revert - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (callargs := callargs) (schemas := schemas) - (schemaUids := schemaUids) - hdecFull hSchemas hSchemaUids hoff0 hoff1 hsizeSigned - hSchemasBound hSchemasLenMax hLenEq - hSchemaNorm hUidssShape - hInv0Solm k0 C0 rd335 - rcases hloopResult with hdone | hrev - · rcases hdone with - ⟨aDone, LDone, evmDone, kDone, CDone, - hloop, hInvDone, rd698⟩ - have hdoneFacts := - AttesterMultiRevokeOuterLoopInv.done - (cA := cA) (σ := σ_evm) (I := I) - (schemas := schemas) (schemaUids := schemaUids) - (a := aDone) (L := LDone) (evm := evmDone) - hInvDone - have hUidssOk : - ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length ≠ 0 ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid) := - AttesterMultiRevokeOuterLoopInv.done_uidss_ok - (cA := cA) (σ := σ_evm) (I := I) - (schemas := schemas) (schemaUids := schemaUids) - (a := aDone) (L := LDone) (evm := evmDone) - hLenEq hInvDone - have hUidssArray : - ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, value = .array uids := by - intro idx value hlookup - rcases hUidssOk hlookup with - ⟨uids, hvalue, _hne, _hbound, _hnorm⟩ - exact ⟨uids, hvalue⟩ - have hrequestsAll : - attesterMultiRevokeRequestValuesPrefix schemas.length - schemas schemaUids = - attesterMultiRevokeRequestValues schemas schemaUids := - attesterMultiRevokeRequestValuesPrefix_all - hLenEq hUidssArray - obtain ⟨LDoneSolm, hloopSolm, hInvDoneSolm⟩ := - attesterMultiRevokeOuterSourceLoop_from_inv - (imm := v) - (evm := - initState cA gh bl σ_solm σ₀ - (Sat256.ofUInt256 g) A I) - (schemas := schemas) (schemaUids := schemaUids) - hSchemasBound hLenEq hSchemaNorm hUidssOk - schemas.length L - (AttesterMultiRevokeOuterLoopInv.source hInv0Solm) - have hrequestsDoneSolm : - LDoneSolm.get? "multiRequests" = - some (.array - (attesterMultiRevokeRequestValuesPrefix - schemas.length schemas schemaUids)) := by - rcases hInvDoneSolm with - ⟨iDone, _hschemasDone, _hschemaUidsDone, - _hschemaLengthDone, hrequestsDone, - _hiDone, hvariantDone, _hleDone⟩ - have hiDoneLen : iDone = schemas.length := by - omega - simpa [hiDoneLen] using hrequestsDone - obtain ⟨k2422, C2422, rd2422⟩ := - attesterX_multiRevokeDoneToEncoder - (cA := cA) (gh := gh) (bl := bl) - (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - hInvDone rd698 - have hloadEncoder := - attesterMultiRevokeEncoderPreambleLoad_fromDone - (cA := cA) (σ := σ_evm) (I := I) - (schemas := schemas) (schemaUids := schemaUids) - (a := aDone) (L := LDone) (evm := evmDone) - hInvDone - obtain ⟨k2460, C2460, rd2460⟩ := - attesterX_multiRevokeEncoderPreambleToOuterLoop - (cA := cA) (gh := gh) (bl := bl) - (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - hloadEncoder rd2422 - let encoderTail : List UInt256 := - [attesterMultiRevokeSelectorLow, - attesterMultiRevokeTargetWord v, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - have hencoderTail : encoderTail.length ≤ 1000 := by - simp [encoderTail] - have hencoderInnerTail : encoderTail.length + 9 ≤ 1000 := by - simp [encoderTail] - obtain ⟨encDone, k775, C775, hencExact, hencIdx, rd775⟩ := - attesterX_multiRevokeEncoderLoopToReturnExactState - (cA := cA) (gh := gh) (bl := bl) - (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v - (idx := (⟨0⟩ : UInt256)) - (srcHead := ⟨128⟩ + ⟨32⟩) - (len := attesterFirstArrayLengthWord I) - (dstHead := - ⟨4⟩ + attesterMultiRevokeCallFree aDone.mem aDone.aw + - ⟨64⟩) - (endPtr := - ⟨4⟩ + attesterMultiRevokeCallFree aDone.mem aDone.aw + - (attesterFirstArrayLengthWord I).shiftLeft ⟨5⟩ + - ⟨64⟩) - (scratch := (⟨0⟩ : UInt256)) - (dst := - ⟨4⟩ + attesterMultiRevokeCallFree aDone.mem aDone.aw) - (src := (⟨128⟩ : UInt256)) - (tail := encoderTail) - (mem := - attesterMultiRevokeEncoderLengthMem - (attesterMultiRevokeCallMemAfterSelector aDone.mem aDone.aw) - (⟨4⟩ + attesterMultiRevokeCallFree aDone.mem aDone.aw) - (attesterFirstArrayLengthWord I)) - (aw := - attesterMultiRevokeEncoderAwAfterLength - (attesterMultiRevokeCallAwAfterSelector aDone.mem aDone.aw) - (⟨4⟩ + attesterMultiRevokeCallFree aDone.mem aDone.aw) - ⟨128⟩) - (k := k2460) (C := C2460) - hencoderTail hencoderInnerTail rfl - (by - simpa [encoderTail] using rd2460) - have hcd : - (config v).externalABI.encode? "multiRevoke" - [.array - (attesterMultiRevokeRequestValuesPrefix - schemas.length schemas schemaUids)] = - some - (encDone.mem.readWithPadding - (attesterMultiRevokeCallFree - encDone.mem encDone.aw).toNat - (UInt256.sub encDone.endPtr - (attesterMultiRevokeCallFree - encDone.mem encDone.aw)).toNat) := by - have hReadLayout : - AttesterMultiRevokeRequestsReadLayoutBounded - schemas schemaUids schemas.length aDone.mem - aDone.outerBase - (aDone.outerBase.toNat + 32 + - 32 * schemas.length) - (attesterInnerArrayAllocFreeWord - aDone.mem aDone.aw).toNat := - AttesterMultiRevokeOuterLoopInv.done_readLayout - (cA := cA) (σ := σ_evm) (I := I) - (schemas := schemas) (schemaUids := schemaUids) - (a := aDone) (L := LDone) (evm := evmDone) - hInvDone - obtain ⟨words, hwords⟩ := - attesterMultiRevokeRequestArrayElemsWords?_some_of_readLayoutBounded - (schemas := schemas) (schemaUids := schemaUids) - (mem := aDone.mem) (outerBase := aDone.outerBase) - (contentLo := - aDone.outerBase.toNat + 32 + 32 * schemas.length) - (bound := - (attesterInnerArrayAllocFreeWord - aDone.mem aDone.aw).toNat) - hLenEq hUidssArray hReadLayout - rw [hrequestsAll] - rw [attesterExternalABIEncode_multiRevokeRequestArray] - rw [hwords] - simp - exact ?_ - exact - attesterMultiRevoke_postEncoder_fromDone - (cA := cA) (gh := gh) (bl := bl) - (σ_evm := σ_evm) (σ_solm := σ_solm) - (σ₀ := σ₀) (A := A) (I := I) - (g := g) v - (callargs := callargs) (LDone := LDoneSolm) - (LStart := L) (schemas := schemas) - (schemaUids := schemaUids) - (endPtr := encDone.endPtr) - (outerBase := ⟨128⟩) - (schemaLen := attesterFirstArrayLengthWord I) - (secondLen := attesterSecondArrayLengthWord I) - (secondPayload := attesterSecondArrayPayloadStartWord I) - (schemaPayload := - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩) - (selector := solcSelectorWord I) - (mem := encDone.mem) (aw := encDone.aw) - (k := k775) (C := C775) - hIcode hd hdecFull hperm hwv hAccounts - hSchemas hSchemaUids hSchemasNe hLenEq - hL hloopSolm hrequestsDoneSolm - (by - simpa [encoderTail] using rd775) - hcd - · have hbodyRev : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - callargs (multiRevokeTransition v).body .reverted := by - subst L - exact attesterMultiRevokeBodyLoopReverts v - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - callargs hwv hSchemas hSchemaUids hSchemasNe hLenEq hrev.1 - exact hrev.2.reEquivExecutionRevert hIcode hd hdecFull hbodyRev - · have hdecNone : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata = none := by - cases hdecMaybe : - decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes - I.calldata with - | none => rfl - | some callargs => - exact False.elim (hdecSome ⟨callargs, hdecMaybe⟩) - by_cases hrawZero : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat = 0 - · have hzeroEvm := - attesterFirstArrayLengthWord_isZero_of_nat_eq_zero - (I := I) hoff0 hrawZero - have hrdrev := - attesterX_multiRevokeLengthZeroReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hzeroEvm _hreachBody - exact hrdrev.reEquivDecodingFailed hIcode hd hdecNone - · by_cases hrawEq : - (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat = - (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat - · exact ?_ - · have hnonzeroEvm := - attesterFirstArrayLengthWord_isZero_of_nat_ne_zero - (I := I) hoff0 hrawZero - have hneqEvm := - attesterArrayLengthWords_eq_zero_of_nat_ne - (I := I) hoff0 hoff1 hrawEq - have hrdrev := - attesterX_multiRevokeLengthMismatchReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) v hnonzeroEvm hneqEvm - _hreachBody - exact hrdrev.reEquivDecodingFailed hIcode hd hdecNone - · have hpayload1Short : - I.calldata.size < - 4 + (calldataWord I.calldata 36).toNat + 32 + - 32 * (calldataWord I.calldata - (4 + (calldataWord I.calldata 36).toNat)).toNat := - by - omega - have hdec := attesterDecode_multiRevoke_none_secondPayloadShort - v hsz68 hoff0 hlenWord hlenHuge hpayload hoff1 hlen1Word - hlen1Huge hpayload1Short - have hgt := - attesterSecondArrayPayloadGuardGtOne_of_short - (I := I) hoff1 hlen1Huge hsize hpayload1Short - exact (attesterX_secondArrayPayloadGuardReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hgt _hreach2076Second) - |>.reEquivDecodingFailed hIcode hd hdec - · have hshort1 : - I.calldata.size < 4 + (calldataWord I.calldata 36).toNat + 32 := by - omega - have hdec := attesterDecode_multiRevoke_none_secondLengthShort - v hsz68 hoff0 hlenWord hlenHuge hpayload hoff1 hshort1 - have hslt := - attesterSecondArrayLengthGuardSltZero_of_short - (I := I) hoff1 hsizeSigned hshort1 - exact (attesterX_secondArrayLengthGuardReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hslt _hreach2038Second) - |>.reEquivDecodingFailed hIcode hd hdec - · have hpayloadShort : - I.calldata.size < - 4 + (calldataWord I.calldata 4).toNat + 32 + - 32 * (calldataWord I.calldata - (4 + (calldataWord I.calldata 4).toNat)).toNat := by - omega - have hdec := attesterDecode_multiRevoke_none_firstPayloadShort - v hsz68 hoff0 hlenWord hlenHuge hpayloadShort - have hgt := - attesterDynamicArrayPayloadGuardGtOne_of_short - (I := I) hoff0 hlenHuge hsize hpayloadShort - exact (attesterX_dynamicArrayPayloadGuardReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hgt _hreach2076) - |>.reEquivDecodingFailed hIcode hd hdec - · have hshortLen : - I.calldata.size < 4 + (calldataWord I.calldata 4).toNat + 32 := by - omega - have hdec := attesterDecode_multiRevoke_none_firstLengthShort - v hsz68 hoff0 hshortLen - have hslt := - attesterDynamicArrayLengthGuardSltZero_of_short - (I := I) hoff0 hsizeSigned hshortLen - exact (attesterX_dynamicArrayLengthGuardReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hslt hreach2038) - |>.reEquivDecodingFailed hIcode hd hdec - · have hbigSigned : 2 ^ 255 ≤ I.calldata.size := by omega - have hdec := attesterDecode_multiRevoke_none_totalHuge v hbigSigned - have hslt := - attesterDynamicArrayLengthGuardSltZero_of_sizeHuge - (I := I) hoff0 hbigSigned hsize - exact (attesterX_dynamicArrayLengthGuardReverts - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - v hslt hreach2038) - |>.reEquivDecodingFailed hIcode hd hdec - · have hbig : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - have hdec := attesterDecode_multiRevoke_none_huge v hbig - exact (attesterX_multiRevokeDecodeHuge (g := Sat256.ofUInt256 g) v hIcode hwv hsz4 - hsize hbig hmultiRevoke) - |>.reEquivDecodingFailed hIcode hd hdec - · have hshort : I.calldata.size < 68 := by omega - have hdec := attesterDecode_multiRevoke_none_short v hsz4 hshort - exact (attesterX_multiRevokeDecodeShort (g := Sat256.ofUInt256 g) v hIcode hwv hsz4 - hsize hshort hmultiRevoke) - |>.reEquivDecodingFailed hIcode hd hdec - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/MultiRevokeContinuation.lean b/Benchmarks/EAS/Attester/MultiRevokeContinuation.lean deleted file mode 100644 index 66424bcd..00000000 --- a/Benchmarks/EAS/Attester/MultiRevokeContinuation.lean +++ /dev/null @@ -1,4745 +0,0 @@ -import Benchmarks.EAS.Attester.MultiRevokeProgress -import Benchmarks.EAS.Attester.MultiRevokeEVM -import Benchmarks.EAS.Attester.MultiRevokeEncoderLayout -import Benchmarks.EAS.Attester.MultiSource - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -/-- Coupled variant-indexed loop rule for a Solm `while` loop and the matching EVM loop. - -This is the `while` analogue of `Reasoning.Reach.RD.execForLoopOrRevertCarryFull`: each -successful source body step must produce the next carried source/EVM state, while a reverting -source body may be paired directly with an EVM `RDrev`. --/ -theorem attesterExecWhileOrRevertCarryFull {cfg : Config} {contract : ContractDecl} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {rdata : ByteArray} {α : Type} - (header bodyHeader exit : UInt256) (condExpr : Expr) (body : List Stmt) - (Inv : Nat → α → Store → EVM.State → Prop) (stk : α → List UInt256) - (mem : α → ByteArray) (aw : α → UInt256) - (acc : α → Batteries.RBSet AccountAddress compare × AccountMap) - (exitStk : α → List UInt256) (exitMem : α → ByteArray) (exitAw : α → UInt256) - (hfalse : ∀ a L evm, Inv 0 a L evm → - evalExpr? cfg { contract := contract, locals := L } evm condExpr = .ok (.bool false)) - (hexit : ∀ a L evm, Inv 0 a L evm → ∀ k C, - RD code ee g s0 header (stk a) (mem a) (aw a) rdata (acc a) k C → - ∃ k' C', - RD code ee g s0 exit (exitStk a) (exitMem a) (exitAw a) rdata (acc a) k' C') - (htrue : ∀ v a L evm, Inv (v + 1) a L evm → - evalExpr? cfg { contract := contract, locals := L } evm condExpr = .ok (.bool true)) - (henter : ∀ v a L evm, Inv (v + 1) a L evm → ∀ k C, - RD code ee g s0 header (stk a) (mem a) (aw a) rdata (acc a) k C → - ∃ k' C', - RD code ee g s0 bodyHeader (stk a) (mem a) (aw a) rdata (acc a) k' C') - (hbody : ∀ v a L evm, Inv (v + 1) a L evm → ∀ k C, - RD code ee g s0 bodyHeader (stk a) (mem a) (aw a) rdata (acc a) k C → - (ExecBlock cfg { contract := contract, locals := L } evm body .reverted ∧ - RDrev code g s0) ∨ - ∃ a' L' evm' k' C', - (ExecBlock cfg { contract := contract, locals := L } evm body - (.ok { contract := contract, locals := L' } evm') ∨ - ExecBlock cfg { contract := contract, locals := L } evm body - (.continue { contract := contract, locals := L' } evm')) ∧ - Inv v a' L' evm' ∧ - RD code ee g s0 header (stk a') (mem a') (aw a') rdata (acc a') k' C') : - ∀ v a L evm, Inv v a L evm → ∀ k C, - RD code ee g s0 header (stk a) (mem a) (aw a) rdata (acc a) k C → - (∃ a' L' evm' k' C', - ExecStmt cfg { contract := contract, locals := L } evm (.while condExpr body) - (.ok { contract := contract, locals := L' } evm') ∧ - Inv 0 a' L' evm' ∧ - RD code ee g s0 exit (exitStk a') (exitMem a') (exitAw a') rdata - (acc a') k' C') ∨ - (ExecStmt cfg { contract := contract, locals := L } evm (.while condExpr body) - .reverted ∧ - RDrev code g s0) := by - intro v - induction v with - | zero => - intro a L evm hInv k C rd - obtain ⟨k', C', rdExit⟩ := hexit a L evm hInv k C rd - exact .inl ⟨a, L, evm, k', C', ExecStmt.whileFalse (hfalse a L evm hInv), - hInv, rdExit⟩ - | succ v ih => - intro a L evm hInv k C rd - obtain ⟨k1, C1, rdBody⟩ := henter v a L evm hInv k C rd - rcases hbody v a L evm hInv k1 C1 rdBody with hrev | hstep - · exact .inr ⟨ExecStmt.whileRevert (htrue v a L evm hInv) hrev.1, hrev.2⟩ - · rcases hstep with ⟨a', L', evm', k2, C2, hbodyStep, hInv', rdNext⟩ - rcases ih a' L' evm' hInv' k2 C2 rdNext with hdone | hloopRev - · rcases hdone with ⟨a'', L'', evm'', k', C', hloop, hInv0, rdExit⟩ - rcases hbodyStep with hbodyOk | hbodyCont - · exact .inl ⟨a'', L'', evm'', k', C', - ExecStmt.whileTrue (htrue v a L evm hInv) hbodyOk hloop, hInv0, rdExit⟩ - · exact .inl ⟨a'', L'', evm'', k', C', - ExecStmt.whileContinue (htrue v a L evm hInv) hbodyCont hloop, hInv0, - rdExit⟩ - · rcases hloopRev with ⟨hloop, hrdRev⟩ - rcases hbodyStep with hbodyOk | hbodyCont - · exact .inr - ⟨ExecStmt.whileTrue (htrue v a L evm hInv) hbodyOk hloop, hrdRev⟩ - · exact .inr - ⟨ExecStmt.whileContinue (htrue v a L evm hInv) hbodyCont hloop, hrdRev⟩ - -structure AttesterMultiRevokeOuterLoopCursor where - idx : UInt256 - outerBase : UInt256 - schemaLen : UInt256 - secondLen : UInt256 - secondPayload : UInt256 - schemaPayload : UInt256 - ret : UInt256 - selector : UInt256 - mem : ByteArray - aw : UInt256 - acc : Batteries.RBSet AccountAddress compare × AccountMap - -def attesterMultiRevokeOuterLoopStack - (a : AttesterMultiRevokeOuterLoopCursor) : List UInt256 := - [a.idx, a.outerBase, a.schemaLen, a.secondLen, a.secondPayload, a.schemaLen, - a.schemaPayload, a.ret, a.selector] - -def attesterMultiRevokeOuterLoopBudgetChunk : Nat := - 128 + 160 * solcMaxU64 - -def attesterMultiRevokeEncoderOutputBudget (schemaLen : Nat) : Nat := - 4 + 64 + attesterMultiRevokeOuterLoopBudgetChunk * schemaLen - -def AttesterReadPreservedBefore (mem₀ mem₁ : ByteArray) (bound : Nat) : Prop := - ∀ {read : Nat} {word : UInt256}, - read + 32 ≤ mem₀.size → - mem₀.readWithPadding read 32 = word.toByteArray → - 64 + 32 ≤ read → - read + 32 ≤ bound → - read + 32 ≤ mem₁.size ∧ - mem₁.readWithPadding read 32 = word.toByteArray - -theorem AttesterReadPreservedBefore_innerAlloc - {len : UInt256} {mem : ByteArray} {aw base : UInt256} - (hbase : base = attesterInnerArrayAllocFreeWord mem aw) : - AttesterReadPreservedBefore mem (attesterInnerArrayAllocMem len mem aw) base.toNat := by - intro read word hmem hread hread64 hbefore - have hreadLt : read < UInt256.size := by - have hbaseLt : base.toNat < UInt256.size := base.val.isLt - omega - let readWord : UInt256 := UInt256.ofNat read - have hreadWordToNat : readWord.toNat = read := ulit_toNat' read hreadLt - constructor - · exact le_trans hmem attesterInnerArrayAllocMem_size_ge - · have hpreserve := - attesterInnerArrayAllocMem_readWithPadding_at_nat - (readBase := readWord) (len := len) (readLen := word) - (mem := mem) (aw := aw) - (by simpa [readWord, hreadWordToNat] using hmem) - (by simpa [readWord, hreadWordToNat] using hread) - (by simpa [readWord, hreadWordToNat] using hread64) - (by simpa [readWord, hreadWordToNat, hbase] using hbefore) - simpa [readWord, hreadWordToNat] using hpreserve - -def AttesterMultiRevokeOuterLoopInv - (cA : Batteries.RBSet AccountAddress compare) (σ : AccountMap) - (I : ExecutionEnv) (schemas schemaUids : List Value) - (fuel : Nat) (a : AttesterMultiRevokeOuterLoopCursor) - (L : Store) (_evm : EVM.State) : Prop := - ∃ i : Nat, - L.get? "schemas" = some (.array schemas) ∧ - L.get? "schemaUids" = some (.array schemaUids) ∧ - L.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) ∧ - L.get? "multiRequests" = - some (.array (attesterMultiRevokeRequestValuesPrefix i schemas schemaUids)) ∧ - L.get? "i" = some (.int (Int.ofNat i)) ∧ - i + fuel = schemas.length ∧ - i ≤ schemas.length ∧ - (∀ {idx value}, idx < i → lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length ≠ 0 ∧ - uids.length ≤ solcMaxU64 ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid)) ∧ - i < UInt256.size ∧ - a.idx = UInt256.ofNat i ∧ - a.idx.toNat = i ∧ - a.outerBase = (⟨128⟩ : UInt256) ∧ - a.schemaLen = attesterFirstArrayLengthWord I ∧ - a.schemaLen.toNat = schemas.length ∧ - a.secondLen = attesterSecondArrayLengthWord I ∧ - a.secondLen.toNat = schemaUids.length ∧ - a.secondPayload = attesterSecondArrayPayloadStartWord I ∧ - a.schemaPayload = (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩ ∧ - a.ret = (⟨97⟩ : UInt256) ∧ - a.selector = solcSelectorWord I ∧ - a.acc = (cA, σ) ∧ - 3 ≤ a.aw.toNat ∧ - a.aw.toNat * 32 < UInt256.size ∧ - a.mem.readWithPadding a.outerBase.toNat 32 = UInt256.toByteArray a.schemaLen ∧ - a.outerBase.toNat + 32 ≤ a.mem.size ∧ - 64 + 32 ≤ a.outerBase.toNat ∧ - 64 + 32 ≤ (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat ∧ - a.outerBase.toNat + 32 ≤ (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat ∧ - a.outerBase.toNat + 32 + 32 * schemas.length ≤ - (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat ∧ - AttesterMultiRevokeRequestsReadLayoutBounded schemas schemaUids i a.mem a.outerBase - (a.outerBase.toNat + 32 + 32 * schemas.length) - (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat ∧ - (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat + - attesterMultiRevokeEncoderOutputBudget schemas.length + 128 + - attesterMultiRevokeOuterLoopBudgetChunk * fuel < UInt256.size - -theorem AttesterMultiRevokeOuterLoopInv.source - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - {I : ExecutionEnv} {schemas schemaUids : List Value} - {fuel : Nat} {a : AttesterMultiRevokeOuterLoopCursor} {L : Store} {evm : EVM.State} - (hInv : AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids fuel a L evm) : - attesterMultiRevokeOuterSourceLoopInv schemas schemaUids fuel L := by - rcases hInv with - ⟨i, hschemas, hschemaUids, hschemaLength, hrequests, hi, hvariant, hile, - _hprocessed, _hisize, _hidx, _hidxToNat, _houterBase, _hschemaLen, - _hschemaLenToNat, _hsecondLen, _hsecondLenToNat, _hsecondPayload, - _hschemaPayload, _hret, _hselector, _hacc, _hawGe, _hawMul, _houterRead, - _houterMemSize, _houter64, _hbaseGe, _houterBeforeBase, - _houterSlotsBeforeBase, _hreadLayout, _hfreeBudget⟩ - exact ⟨i, hschemas, hschemaUids, hschemaLength, hrequests, hi, hvariant, hile⟩ - -theorem AttesterMultiRevokeOuterLoopInv.done - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - {I : ExecutionEnv} {schemas schemaUids : List Value} - {a : AttesterMultiRevokeOuterLoopCursor} {L : Store} {evm : EVM.State} - (hInv : AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids 0 a L evm) : - L.get? "multiRequests" = - some (.array (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) ∧ - L.get? "i" = some (.int (Int.ofNat schemas.length)) ∧ - a.idx = UInt256.ofNat schemas.length ∧ - a.idx.toNat = schemas.length ∧ - a.acc = (cA, σ) := by - rcases hInv with - ⟨i, _hschemas, _hschemaUids, _hschemaLength, hrequests, hi, hvariant, _hile, - _hprocessed, _hisize, hidx, hidxToNat, _houterBase, _hschemaLen, - _hschemaLenToNat, _hsecondLen, _hsecondLenToNat, _hsecondPayload, - _hschemaPayload, _hret, _hselector, hacc, _hawGe, _hawMul, _houterRead, - _houterMemSize, _houter64, _hbaseGe, _houterBeforeBase, - _houterSlotsBeforeBase, _hreadLayout, _hfreeBudget⟩ - have hidone : i = schemas.length := by omega - subst hidone - exact ⟨hrequests, hi, hidx, hidxToNat, hacc⟩ - -theorem AttesterMultiRevokeOuterLoopInv.cond_false - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - {I : ExecutionEnv} {schemas schemaUids : List Value} - {a : AttesterMultiRevokeOuterLoopCursor} {L : Store} {evm : EVM.State} - (hInv : AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids 0 a L evm) : - UInt256.lt a.idx a.schemaLen = ⟨0⟩ := by - rcases hInv with - ⟨i, _hschemas, _hschemaUids, _hschemaLength, _hrequests, _hi, hvariant, - _hile, _hprocessed, _hisize, _hidx, hidxToNat, _houterBase, _hschemaLen, - hschemaLenToNat, _hsecondLen, _hsecondLenToNat, _hsecondPayload, - _hschemaPayload, _hret, _hselector, _hacc, _hawGe, _hawMul, _houterRead, - _houterMemSize, _houter64, _hbaseGe, _houterBeforeBase, - _houterSlotsBeforeBase, _hreadLayout, _hfreeBudget⟩ - apply ult_zero - rw [hidxToNat, hschemaLenToNat] - omega - -theorem AttesterMultiRevokeOuterLoopInv.cond_true - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - {I : ExecutionEnv} {schemas schemaUids : List Value} - {fuel : Nat} {a : AttesterMultiRevokeOuterLoopCursor} {L : Store} {evm : EVM.State} - (hInv : AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids (fuel + 1) a L evm) : - UInt256.lt a.idx a.schemaLen = ⟨1⟩ := by - rcases hInv with - ⟨i, _hschemas, _hschemaUids, _hschemaLength, _hrequests, _hi, hvariant, - _hile, _hprocessed, _hisize, _hidx, hidxToNat, _houterBase, _hschemaLen, - hschemaLenToNat, _hsecondLen, _hsecondLenToNat, _hsecondPayload, - _hschemaPayload, _hret, _hselector, _hacc, _hawGe, _hawMul, _houterRead, - _houterMemSize, _houter64, _hbaseGe, _houterBeforeBase, - _houterSlotsBeforeBase, _hreadLayout, _hfreeBudget⟩ - apply ult_one - rw [hidxToNat, hschemaLenToNat] - omega - -/-- BlindAuction-style runner for the `multiRevoke` outer source loop. - -The only loop-specific proof obligation is `hbody`: one source body execution from PC 344 -must either pair with an EVM revert, or produce the next cursor back at PC 335. The false -branch exits through PC 698 and the true branch enters PC 344. --/ -theorem attesterMultiRevokeOuterLoop_from_bodyOutcome_or_revert - {cA gh bl σ σ₀ A I} {g : Sat256} (imm : AttesterImmutables) - (Inv : Nat → AttesterMultiRevokeOuterLoopCursor → Store → EVM.State → Prop) - (hfalse : ∀ a L evm, Inv 0 a L evm → - evalExpr? (config imm) { contract := contract imm, locals := L } evm - attesterMultiRevokeOuterSourceLoopCond = .ok (.bool false)) - (hexit : ∀ a L evm, Inv 0 a L evm → ∀ k C, - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a) a.mem a.aw ByteArray.empty a.acc k C → - ∃ k' C', - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨698⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a) a.mem a.aw ByteArray.empty a.acc k' C') - (htrue : ∀ fuel a L evm, Inv (fuel + 1) a L evm → - evalExpr? (config imm) { contract := contract imm, locals := L } evm - attesterMultiRevokeOuterSourceLoopCond = .ok (.bool true)) - (henter : ∀ fuel a L evm, Inv (fuel + 1) a L evm → ∀ k C, - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a) a.mem a.aw ByteArray.empty a.acc k C → - ∃ k' C', - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨344⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a) a.mem a.aw ByteArray.empty a.acc k' C') - (hbody : ∀ fuel a L evm, Inv (fuel + 1) a L evm → ∀ k C, - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨344⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a) a.mem a.aw ByteArray.empty a.acc k C → - (ExecBlock (config imm) { contract := contract imm, locals := L } evm - attesterMultiRevokeOuterSourceLoopBody .reverted ∧ - RDrev (patchedRuntime imm) g (initState cA gh bl σ σ₀ g A I)) ∨ - ∃ a' L' evm' k' C', - (ExecBlock (config imm) { contract := contract imm, locals := L } evm - attesterMultiRevokeOuterSourceLoopBody - (.ok { contract := contract imm, locals := L' } evm') ∨ - ExecBlock (config imm) { contract := contract imm, locals := L } evm - attesterMultiRevokeOuterSourceLoopBody - (.continue { contract := contract imm, locals := L' } evm')) ∧ - Inv fuel a' L' evm' ∧ - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a') a'.mem a'.aw ByteArray.empty a'.acc k' C') : - ∀ fuel a L evm, Inv fuel a L evm → ∀ k C, - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a) a.mem a.aw ByteArray.empty a.acc k C → - (∃ a' L' evm' k' C', - ExecStmt (config imm) { contract := contract imm, locals := L } evm - (.while attesterMultiRevokeOuterSourceLoopCond attesterMultiRevokeOuterSourceLoopBody) - (.ok { contract := contract imm, locals := L' } evm') ∧ - Inv 0 a' L' evm' ∧ - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨698⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a') a'.mem a'.aw ByteArray.empty a'.acc k' C') ∨ - (ExecStmt (config imm) { contract := contract imm, locals := L } evm - (.while attesterMultiRevokeOuterSourceLoopCond attesterMultiRevokeOuterSourceLoopBody) - .reverted ∧ - RDrev (patchedRuntime imm) g (initState cA gh bl σ σ₀ g A I)) := by - exact - attesterExecWhileOrRevertCarryFull - (cfg := config imm) (contract := contract imm) - (code := patchedRuntime imm) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) (rdata := ByteArray.empty) - (header := (⟨335⟩ : UInt256)) (bodyHeader := (⟨344⟩ : UInt256)) - (exit := (⟨698⟩ : UInt256)) - (condExpr := attesterMultiRevokeOuterSourceLoopCond) - (body := attesterMultiRevokeOuterSourceLoopBody) - (Inv := Inv) (stk := attesterMultiRevokeOuterLoopStack) - (mem := fun a => a.mem) (aw := fun a => a.aw) (acc := fun a => a.acc) - (exitStk := attesterMultiRevokeOuterLoopStack) - (exitMem := fun a => a.mem) (exitAw := fun a => a.aw) - hfalse hexit htrue henter hbody - -/-- Variant of `attesterMultiRevokeOuterLoop_from_bodyOutcome_or_revert` for iteration -lemmas that start from the loop header itself. This matches the current `multiRevoke` -EVM helpers, which include the bytecode guard step in the per-iteration theorem. --/ -theorem attesterMultiRevokeOuterLoop_from_headerBodyOutcome_or_revert - {cA gh bl σ σ₀ A I} {g : Sat256} (imm : AttesterImmutables) - (Inv : Nat → AttesterMultiRevokeOuterLoopCursor → Store → EVM.State → Prop) - (hfalse : ∀ a L evm, Inv 0 a L evm → - evalExpr? (config imm) { contract := contract imm, locals := L } evm - attesterMultiRevokeOuterSourceLoopCond = .ok (.bool false)) - (hexit : ∀ a L evm, Inv 0 a L evm → ∀ k C, - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a) a.mem a.aw ByteArray.empty a.acc k C → - ∃ k' C', - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨698⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a) a.mem a.aw ByteArray.empty a.acc k' C') - (htrue : ∀ fuel a L evm, Inv (fuel + 1) a L evm → - evalExpr? (config imm) { contract := contract imm, locals := L } evm - attesterMultiRevokeOuterSourceLoopCond = .ok (.bool true)) - (hbody : ∀ fuel a L evm, Inv (fuel + 1) a L evm → ∀ k C, - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a) a.mem a.aw ByteArray.empty a.acc k C → - (ExecBlock (config imm) { contract := contract imm, locals := L } evm - attesterMultiRevokeOuterSourceLoopBody .reverted ∧ - RDrev (patchedRuntime imm) g (initState cA gh bl σ σ₀ g A I)) ∨ - ∃ a' L' evm' k' C', - (ExecBlock (config imm) { contract := contract imm, locals := L } evm - attesterMultiRevokeOuterSourceLoopBody - (.ok { contract := contract imm, locals := L' } evm') ∨ - ExecBlock (config imm) { contract := contract imm, locals := L } evm - attesterMultiRevokeOuterSourceLoopBody - (.continue { contract := contract imm, locals := L' } evm')) ∧ - Inv fuel a' L' evm' ∧ - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a') a'.mem a'.aw ByteArray.empty a'.acc k' C') : - ∀ fuel a L evm, Inv fuel a L evm → ∀ k C, - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a) a.mem a.aw ByteArray.empty a.acc k C → - (∃ a' L' evm' k' C', - ExecStmt (config imm) { contract := contract imm, locals := L } evm - (.while attesterMultiRevokeOuterSourceLoopCond attesterMultiRevokeOuterSourceLoopBody) - (.ok { contract := contract imm, locals := L' } evm') ∧ - Inv 0 a' L' evm' ∧ - RD (patchedRuntime imm) I g (initState cA gh bl σ σ₀ g A I) (⟨698⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a') a'.mem a'.aw ByteArray.empty a'.acc k' C') ∨ - (ExecStmt (config imm) { contract := contract imm, locals := L } evm - (.while attesterMultiRevokeOuterSourceLoopCond attesterMultiRevokeOuterSourceLoopBody) - .reverted ∧ - RDrev (patchedRuntime imm) g (initState cA gh bl σ σ₀ g A I)) := by - refine - attesterExecWhileOrRevertCarryFull - (cfg := config imm) (contract := contract imm) - (code := patchedRuntime imm) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) (rdata := ByteArray.empty) - (header := (⟨335⟩ : UInt256)) (bodyHeader := (⟨335⟩ : UInt256)) - (exit := (⟨698⟩ : UInt256)) - (condExpr := attesterMultiRevokeOuterSourceLoopCond) - (body := attesterMultiRevokeOuterSourceLoopBody) - (Inv := Inv) (stk := attesterMultiRevokeOuterLoopStack) - (mem := fun a => a.mem) (aw := fun a => a.aw) (acc := fun a => a.acc) - (exitStk := attesterMultiRevokeOuterLoopStack) - (exitMem := fun a => a.mem) (exitAw := fun a => a.aw) - hfalse hexit htrue ?_ hbody - intro _fuel _a _L _evm _hInv k C rd - exact ⟨k, C, rd⟩ - -theorem attesterUInt256_lt_zero_of_toNat_ne_zero {x : UInt256} - (hne : x.toNat ≠ 0) : - UInt256.lt (⟨0⟩ : UInt256) x = ⟨1⟩ := by - apply ult_one - rw [show (⟨0⟩ : UInt256).toNat = 0 by decide] - omega - -private theorem attester_slt_one_low_at {a b : UInt256} - (hlt : a.toNat < b.toNat) (hb : b.toNat < 2 ^ 255) : - UInt256.slt a b = ⟨1⟩ := by - unfold UInt256.slt UInt256.sltBool UInt256.fromBool Bool.toUInt256 - rw [if_neg (by omega : ¬ a.toNat ≥ 2 ^ 255), - if_neg (by omega : ¬ b.toNat ≥ 2 ^ 255)] - rw [decide_eq_true (show a < b by - show a.toNat < b.toNat - exact hlt)] - native_decide - -private theorem attester_sgt_zero_low_at {a b : UInt256} - (hle : a.toNat ≤ b.toNat) (hb : b.toNat < 2 ^ 255) : - UInt256.sgt a b = ⟨0⟩ := by - unfold UInt256.sgt UInt256.sgtBool UInt256.fromBool Bool.toUInt256 - rw [if_neg (by omega : ¬ a.toNat ≥ 2 ^ 255), - if_neg (by omega : ¬ b.toNat ≥ 2 ^ 255)] - rw [decide_eq_false (show ¬ a > b by - show ¬ a.toNat > b.toNat - omega)] - native_decide - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevokeInnerArrayGuardFacts_of_decode_at {I : ExecutionEnv} - {idx len relativeOffset : Nat} {inner : List Value} {innerEnd : Nat} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hlenRead : readNat? (I.calldata.toList.drop 4) - (calldataWord I.calldata 36).toNat = some len) - (hlenMax : ¬ solcMaxLen DecodeMode.modern < len) - (hidx : idx < len) - (hreadAt : readNat? (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32 + 32 * idx) = - some relativeOffset) - (hinner : decodeABIValue? (.dynamicArray bytes32) (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) = - some (.array inner, innerEnd)) - (hsizeSigned : I.calldata.size < 2 ^ 255) : - UInt256.lt (UInt256.ofNat idx) (attesterSecondArrayLengthWord I) = ⟨1⟩ ∧ - UInt256.slt - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩ ∧ - UInt256.gt - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - ⟨0⟩ ∧ - UInt256.sgt - (attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) ⟨5⟩)) = - ⟨0⟩ ∧ - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat = - inner.length := by - have hinner' : - decodeABIValue? (.dynamicArray (.elem (ElemType.bytes bytes32Width))) - (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) = - some (.array inner, innerEnd) := by - simpa [bytes32] using hinner - obtain ⟨innerLen, hreadLen, hinnerLenMax, hend, hendLe, hlenValues⟩ := - decodeABIValue_dynamicArray_elem32_facts hinner' - have hsize : I.calldata.size < UInt256.size := lt_size_of_lt_sign hsizeSigned - have hdropLen : (I.calldata.toList.drop 4).length = I.calldata.size - 4 := by - rw [List.length_drop] - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [htlen] - have hbaseToNat : - (attesterSecondArrayPayloadStartWord I).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 := - attesterSecondArrayPayloadStart_toNat (I := I) hoffMax - have hlenReadEq : - len = (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat := - readNat_drop4_at_some_eq_calldataWord (cd := I.calldata) hlenRead - have hsecondLenToNat : - (attesterSecondArrayLengthWord I).toNat = len := by - rw [attesterSecondArrayLengthWord_toNat (I := I) hoffMax, ← hlenReadEq] - have hlenLeU64 : len ≤ solcMaxU64 := by - exact Nat.le_of_not_gt (by simpa [solcMaxLen] using hlenMax) - have hidxSize : idx < UInt256.size := by - norm_num [solcMaxU64, UInt256.size] at hlenLeU64 ⊢ - omega - have hidxWordToNat : (UInt256.ofNat idx).toNat = idx := - ulit_toNat' idx hidxSize - have hidxSecond : - UInt256.lt (UInt256.ofNat idx) (attesterSecondArrayLengthWord I) = ⟨1⟩ := by - apply ult_one - rw [hidxWordToNat, hsecondLenToNat] - exact hidx - have hoffLe : (calldataWord I.calldata 36).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - have hinnerLenReadSizeEarly := readNat?_some_length hreadLen - have hinnerHeadInCalldataEarly : - 4 + ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) + 32 ≤ - I.calldata.size := by - rw [hdropLen] at hinnerLenReadSizeEarly - omega - have hmulToNat : - (UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat idx)).toNat = - 32 * idx := by - rw [u256_mul_toNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide, hidxWordToNat] - exact Nat.mod_eq_of_lt (by - norm_num [solcMaxU64, UInt256.size] at hlenLeU64 ⊢ - omega) - have hheadToNat : - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx)).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 + 32 * idx := by - unfold attesterMultiRevokeInnerArrayHeadWord - rw [uadd_toNat, hbaseToNat, hmulToNat] - exact Nat.mod_eq_of_lt (by - norm_num [solcMaxU64, UInt256.size] at hoffLe hlenLeU64 ⊢ - omega) - have hoffWordToNat : - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat = - relativeOffset := by - unfold attesterMultiRevokeInnerArrayOffsetWord - rw [hheadToNat] - have hreadEq := - readNat_drop4_at_some_eq_calldataWord (cd := I.calldata) hreadAt - simpa [Nat.add_assoc] using hreadEq.symm - have hstartToNat : - (attesterMultiRevokeInnerArrayStartWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 + relativeOffset := by - unfold attesterMultiRevokeInnerArrayStartWord - rw [uadd_toNat, hbaseToNat, hoffWordToNat] - exact Nat.mod_eq_of_lt (by - omega) - have hlenWordToNat : - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat = - innerLen := by - unfold attesterMultiRevokeInnerArrayLengthWord - rw [hstartToNat] - have hreadEq := - readNat_drop4_at_some_eq_calldataWord (cd := I.calldata) hreadLen - simpa [Nat.add_assoc] using hreadEq.symm - have hinnerLenWordOk : - UInt256.gt - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - ⟨0⟩ := by - apply ugt_zero - have hmaxToNat : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = - solcMaxU64 := by - native_decide - rw [hlenWordToNat, hmaxToNat] - exact Nat.le_of_not_gt hinnerLenMax - have hinnerLenReadSize := readNat?_some_length hreadLen - have hinnerHeadInCalldata : - 4 + ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) + 32 ≤ - I.calldata.size := by - rw [hdropLen] at hinnerLenReadSize - omega - have hpayloadInCalldata : - 4 + ((calldataWord I.calldata 36).toNat + 32 + relativeOffset + 32 + - 32 * innerLen) ≤ I.calldata.size := by - rw [hend] at hendLe - rw [hdropLen] at hendLe - omega - have hsubHeadToNat : - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)).toNat = - I.calldata.size - (4 + (calldataWord I.calldata 36).toNat + 32) := by - rw [usub_toNat] - · rw [ulit_toNat' I.calldata.size hsize, hbaseToNat] - · rw [ulit_toNat' I.calldata.size hsize, hbaseToNat] - omega - have hrhsOffsetToNat : - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)) - (UInt256.lnot (⟨30⟩ : UInt256))).toNat = - I.calldata.size - (4 + (calldataWord I.calldata 36).toNat + 32) - 31 := by - change ((UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I) + UInt256.lnot (⟨30⟩ : UInt256)).toNat = - I.calldata.size - (4 + (calldataWord I.calldata 36).toNat + 32) - 31) - rw [uadd_toNat, hsubHeadToNat] - have hlnot : (UInt256.lnot (⟨30⟩ : UInt256)).toNat = UInt256.size - 31 := by - native_decide - rw [hlnot] - have hsplit : - I.calldata.size - (4 + (calldataWord I.calldata 36).toNat + 32) + - (UInt256.size - 31) = - UInt256.size + - (I.calldata.size - (4 + (calldataWord I.calldata 36).toNat + 32) - 31) := by - omega - rw [hsplit, Nat.add_mod_left] - exact Nat.mod_eq_of_lt (by - have hleSub : - I.calldata.size - (4 + (calldataWord I.calldata 36).toNat + 32) - 31 ≤ - I.calldata.size := by - omega - exact lt_of_le_of_lt hleSub hsize) - have hoffsetGuard : - UInt256.slt - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩ := by - apply attester_slt_one_low_at - · rw [hoffWordToNat, hrhsOffsetToNat] - omega - · rw [hrhsOffsetToNat] - omega - have hinnerPayloadStartToNat : - (attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 + relativeOffset + 32 := by - unfold attesterMultiRevokeInnerArrayPayloadWord - rw [uadd_toNat, hstartToNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide] - exact Nat.mod_eq_of_lt (by - omega) - have hshiftLenToNat : - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) ⟨5⟩).toNat = - 32 * innerLen := by - have hle : - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat ≤ - solcMaxU64 := by - rw [hlenWordToNat] - exact Nat.le_of_not_gt hinnerLenMax - simpa [hlenWordToNat] using - attesterShiftLeft5_toNat_of_le - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) hle - have hsubPayloadToNat : - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) ⟨5⟩)).toNat = - I.calldata.size - 32 * innerLen := by - rw [usub_toNat] - · rw [ulit_toNat' I.calldata.size hsize, hshiftLenToNat] - · rw [ulit_toNat' I.calldata.size hsize, hshiftLenToNat] - omega - have hpayloadGuard : - UInt256.sgt - (attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) ⟨5⟩)) = - ⟨0⟩ := by - apply attester_sgt_zero_low_at - · rw [hinnerPayloadStartToNat, hsubPayloadToNat] - omega - · rw [hsubPayloadToNat] - omega - exact ⟨hidxSecond, hoffsetGuard, hinnerLenWordOk, hpayloadGuard, by - rw [hlenWordToNat, hlenValues]⟩ - -theorem attesterMultiRevokeInnerArrayCurrentFacts_of_decode_at - (v : AttesterImmutables) {I : ExecutionEnv} {callargs : Store} - {schemaUids inner : List Value} {idx : Nat} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hSchemaUids : callargs.get? "schemaUids" = some (.array schemaUids)) - (hlookup : lookupNth? schemaUids idx = some (.array inner)) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hsizeSigned : I.calldata.size < 2 ^ 255) : - UInt256.lt (UInt256.ofNat idx) (attesterSecondArrayLengthWord I) = ⟨1⟩ ∧ - UInt256.slt - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩ ∧ - UInt256.gt - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - ⟨0⟩ ∧ - UInt256.sgt - (attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) ⟨5⟩)) = - ⟨0⟩ ∧ - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat = - inner.length ∧ - inner.length ≤ solcMaxU64 ∧ - (inner.length = 0 → - attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx)) = - ⟨0⟩) ∧ - (inner.length ≠ 0 → - attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx)) ≠ - ⟨0⟩) := by - obtain ⟨len, relativeOffset, innerEnd, hlenRead, hlenMax, hidx, hreadAt, - hinner⟩ := - attesterDecode_multiRevoke_inner_decode_at v hdec hSchemaUids hlookup - obtain ⟨hidxSecond, hoffsetOk, hlenOk, hpayloadOk, hlenToNat⟩ := - attesterMultiRevokeInnerArrayGuardFacts_of_decode_at - (I := I) (idx := idx) (len := len) (relativeOffset := relativeOffset) - (inner := inner) (innerEnd := innerEnd) - hoffMax hlenRead hlenMax hidx hreadAt hinner hsizeSigned - have hinnerLengthLe : inner.length ≤ solcMaxU64 := by - rw [← hlenToNat] - apply Nat.le_of_not_gt - intro hgt - have hmaxToNat : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = - solcMaxU64 := by - native_decide - have hgtWord : UInt256.gt - (attesterMultiRevokeInnerArrayLengthWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = - ⟨1⟩ := by - apply ugt_one - rw [hmaxToNat] - exact hgt - rw [hgtWord] at hlenOk - exact (by decide : (⟨1⟩ : UInt256) ≠ (⟨0⟩ : UInt256)) hlenOk - refine ⟨hidxSecond, hoffsetOk, hlenOk, hpayloadOk, hlenToNat, hinnerLengthLe, ?_, ?_⟩ - · intro hzero - exact uint256_toNat_eq_zero (by rw [hlenToNat, hzero]) - · intro hne hzero - have hzeroNat := congrArg UInt256.toNat hzero - rw [hlenToNat] at hzeroNat - exact hne hzeroNat - -abbrev attesterMultiRevokeInnerArrayInitStackAt - (base len payload : UInt256) (tail : List UInt256) - (a : AttesterMultiRevokeInnerArrayInitState) : List UInt256 := - a.slot :: a.remaining :: base :: ⟨0⟩ :: len :: len :: payload :: tail - -abbrev attesterMultiRevokeInnerArrayInitExitStackAt - (base len payload : UInt256) (tail : List UInt256) - (_a : AttesterMultiRevokeInnerArrayInitState) : List UInt256 := - ⟨0⟩ :: base :: len :: len :: payload :: tail - -structure attesterMultiRevokeInnerInitReadInvAt - (I : ExecutionEnv) (base len outerBase schemaLen : UInt256) - (n : Nat) (b : AttesterMultiRevokeInnerArrayInitState) : Prop where - remaining : b.remaining = UInt256.ofNat (n + 1) - bound : n + 1 < UInt256.size - awGe : 3 ≤ b.aw.toNat - awMul : b.aw.toNat * 32 < UInt256.size - read : b.mem.readWithPadding base.toNat 32 = UInt256.toByteArray len - memSize : base.toNat + 32 ≤ b.mem.size - le : n + 1 ≤ len.toNat - baseGe : 64 + 32 ≤ base.toNat - freeGe : base.toNat + 32 ≤ (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat - freeExact : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat = - base.toNat + 32 + 32 * len.toNat + 64 * (len.toNat - (n + 1)) - freeBound : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + - 64 * (n + 1) < UInt256.size - freeSpare : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + - 64 * (n + 1) + 64 * len.toNat + 96 < UInt256.size - slotGe : base.toNat + 32 ≤ b.slot.toNat - slotBound : b.slot.toNat + 32 * (n + 1) + 63 < UInt256.size - baseSlot63 : base.toNat + 32 + 32 * len.toNat + 63 < UInt256.size - outerRead : b.mem.readWithPadding outerBase.toNat 32 = UInt256.toByteArray schemaLen - outerMemSize : outerBase.toNat + 32 ≤ b.mem.size - outer64 : 64 + 32 ≤ outerBase.toNat - outerBeforeBase : outerBase.toNat + 32 ≤ base.toNat - -theorem attesterMultiRevokeInnerInitReadInvAt_remaining - {I : ExecutionEnv} {base len outerBase schemaLen : UInt256} - {n : Nat} {b : AttesterMultiRevokeInnerArrayInitState} - (hInv : attesterMultiRevokeInnerInitReadInvAt I base len outerBase schemaLen n b) : - b.remaining = UInt256.ofNat (n + 1) := by - exact hInv.remaining - -theorem attesterMultiRevokeInnerInitReadInvAt_bound - {I : ExecutionEnv} {base len outerBase schemaLen : UInt256} - {n : Nat} {b : AttesterMultiRevokeInnerArrayInitState} - (hInv : attesterMultiRevokeInnerInitReadInvAt I base len outerBase schemaLen n b) : - n + 1 < UInt256.size := by - exact hInv.bound - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevokeInnerInitReadInvAt_step - {I : ExecutionEnv} {base len outerBase schemaLen : UInt256} - {n : Nat} {b : AttesterMultiRevokeInnerArrayInitState} - (hInv : - attesterMultiRevokeInnerInitReadInvAt I base len outerBase schemaLen (n + 1) b) : - attesterMultiRevokeInnerInitReadInvAt I base len outerBase schemaLen n - (attesterMultiRevokeInnerArrayInitStepState b) := by - have hbound := hInv.bound - have hfreeBound := hInv.freeBound - have hfreeSpare := hInv.freeSpare - have hslotBound := hInv.slotBound - have hfree63 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 63 < - UInt256.size := by - have hmul : 63 ≤ 64 * ((n + 1) + 1) := by nlinarith - omega - have hfree32 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 32 < - UInt256.size := by - omega - have hsecondToNat : - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat = - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 32 := - attesterMultiRevokeInnerArrayInitSecondZeroWord_toNat - (mem := b.mem) (aw := b.aw) hfree32 - have hsecondGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - rw [hsecondToNat] - exact le_trans hInv.freeGe (Nat.le_add_right _ _) - have houterFree : - outerBase.toNat + 32 ≤ (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat := by - exact le_trans hInv.outerBeforeBase - (le_trans (Nat.le_add_right base.toNat 32) hInv.freeGe) - have houterSecond : - outerBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - rw [hsecondToNat] - exact le_trans houterFree (Nat.le_add_right _ _) - have houterSlot : outerBase.toNat + 32 ≤ b.slot.toNat := by - exact le_trans hInv.outerBeforeBase - (le_trans (Nat.le_add_right base.toNat 32) hInv.slotGe) - have hsecond63 : - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat + 63 < - UInt256.size := by - rw [hsecondToNat] - have hmul : 95 ≤ 64 * ((n + 1) + 1) := by nlinarith - omega - have hslot63 : b.slot.toNat + 63 < UInt256.size := by - have hmul : 63 ≤ 32 * ((n + 1) + 1) := by nlinarith - omega - have hawStep := - attesterMultiRevokeInnerArrayInitStepAw_bounds - (slot := b.slot) (mem := b.mem) (aw := b.aw) - hInv.awGe hInv.awMul hfree63 hsecond63 hslot63 - have hreadStep : - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := - attesterMultiRevokeInnerArrayInitStep_readWithPadding_nat - (base := base) (slot := b.slot) (len := len) (mem := b.mem) (aw := b.aw) - hInv.memSize hInv.read hInv.baseGe hInv.freeGe hsecondGe hInv.slotGe - have hmemStep : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).size := - attesterMultiRevokeInnerArrayInitStep_base_size - (base := base) (slot := b.slot) (len := len) (mem := b.mem) (aw := b.aw) - hInv.memSize - have hreadOuterStep : - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray schemaLen := - attesterMultiRevokeInnerArrayInitStep_readWithPadding_nat - (base := outerBase) (slot := b.slot) (len := schemaLen) - (mem := b.mem) (aw := b.aw) - hInv.outerMemSize hInv.outerRead hInv.outer64 houterFree houterSecond houterSlot - have houterMemStep : - outerBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).size := - le_trans hInv.outerMemSize attesterMultiRevokeInnerArrayInitStep_size_ge - have hfree96 : - 64 + 32 ≤ (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat := by - have hbase96 : 64 + 32 ≤ base.toNat + 32 := - le_trans hInv.baseGe (Nat.le_add_right base.toNat 32) - exact le_trans hbase96 hInv.freeGe - have hsecond96 : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - have hbase96 : 64 + 32 ≤ base.toNat + 32 := - le_trans hInv.baseGe (Nat.le_add_right base.toNat 32) - exact le_trans hbase96 hsecondGe - have hslot96 : 64 + 32 ≤ b.slot.toNat := by - have hbase96 : 64 + 32 ≤ base.toNat + 32 := - le_trans hInv.baseGe (Nat.le_add_right base.toNat 32) - exact le_trans hbase96 hInv.slotGe - have hfree64 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 64 < - UInt256.size := by - omega - have hfreeStepToNat : - (attesterMultiOuterArrayInitFreeWord - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw) - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw)).toNat = - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 64 := - attesterMultiRevokeInnerArrayInitStep_freeWord_toNat - (slot := b.slot) (mem := b.mem) (aw := b.aw) - hfree96 hsecond96 hslot96 hawStep.2 hawStep.1 hfree64 - have hslot32 : b.slot.toNat + 32 < UInt256.size := by - omega - have hslotStepToNat : - (((⟨32⟩ : UInt256) + b.slot).toNat) = b.slot.toNat + 32 := - uadd_lit32_toNat b.slot hslot32 - exact - { remaining := by - change UInt256.sub b.remaining (⟨1⟩ : UInt256) = UInt256.ofNat (n + 1) - rw [hInv.remaining] - simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using - attester_u256_ofNat_succ_sub_one (n := n + 1) hInv.bound - bound := by omega - awGe := by - change 3 ≤ (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw).toNat - exact hawStep.1 - awMul := by - change - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw).toNat * 32 < - UInt256.size - exact hawStep.2 - read := by - change - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len - exact hreadStep - memSize := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).size - exact hmemStep - le := by - have hle := hInv.le - omega - baseGe := hInv.baseGe - freeGe := by - change base.toNat + 32 ≤ - (attesterMultiOuterArrayInitFreeWord - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw) - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw)).toNat - rw [hfreeStepToNat] - omega - freeExact := by - change - (attesterMultiOuterArrayInitFreeWord - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw) - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw)).toNat = - base.toNat + 32 + 32 * len.toNat + 64 * (len.toNat - (n + 1)) - rw [hfreeStepToNat, hInv.freeExact] - have hsub : - len.toNat - (n + 1) = - len.toNat - ((n + 1) + 1) + 1 := by - have hle := hInv.le - omega - rw [hsub] - nlinarith - freeBound := by - change - (attesterMultiOuterArrayInitFreeWord - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw) - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw)).toNat + - 64 * (n + 1) < - UInt256.size - rw [hfreeStepToNat] - omega - freeSpare := by - change - (attesterMultiOuterArrayInitFreeWord - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw) - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw)).toNat + - 64 * (n + 1) + 64 * len.toNat + 96 < - UInt256.size - rw [hfreeStepToNat] - have hspare : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + - 64 * ((n + 1) + 1) + 64 * len.toNat + 96 < - UInt256.size := by - simpa using hInv.freeSpare - omega - slotGe := by - change base.toNat + 32 ≤ (((⟨32⟩ : UInt256) + b.slot).toNat) - rw [hslotStepToNat] - exact le_trans hInv.slotGe (Nat.le_add_right _ _) - slotBound := by - change (((⟨32⟩ : UInt256) + b.slot).toNat) + 32 * (n + 1) + 63 < - UInt256.size - rw [hslotStepToNat] - omega - baseSlot63 := hInv.baseSlot63 - outerRead := by - change - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray schemaLen - exact hreadOuterStep - outerMemSize := by - change outerBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).size - exact houterMemStep - outer64 := hInv.outer64 - outerBeforeBase := hInv.outerBeforeBase } - -theorem AttesterReadPreservedBefore_innerInitStep - {I : ExecutionEnv} {mem₀ : ByteArray} - {base len outerBase schemaLen : UInt256} - {n : Nat} {b : AttesterMultiRevokeInnerArrayInitState} - (hInv : - attesterMultiRevokeInnerInitReadInvAt I base len outerBase schemaLen (n + 1) b) - (hpres : AttesterReadPreservedBefore mem₀ b.mem base.toNat) : - AttesterReadPreservedBefore mem₀ - (attesterMultiRevokeInnerArrayInitStepState b).mem base.toNat := by - intro read word hmem0 hread0 hread64 hbefore - rcases hpres hmem0 hread0 hread64 hbefore with ⟨hmem, hread⟩ - have hreadLt : read < UInt256.size := by - have hbaseLt : base.toNat < UInt256.size := base.val.isLt - omega - let readWord : UInt256 := UInt256.ofNat read - have hreadWordToNat : readWord.toNat = read := ulit_toNat' read hreadLt - have hfree32 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 32 < - UInt256.size := by - have hfb := hInv.freeBound - omega - have hsecondToNat : - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat = - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 32 := - attesterMultiRevokeInnerArrayInitSecondZeroWord_toNat - (mem := b.mem) (aw := b.aw) hfree32 - have hfree : - read + 32 ≤ (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat := by - exact le_trans hbefore (le_trans (Nat.le_add_right base.toNat 32) hInv.freeGe) - have hsecond : - read + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - rw [hsecondToNat] - exact le_trans hfree (Nat.le_add_right _ _) - have hslot : read + 32 ≤ b.slot.toNat := by - exact le_trans hbefore - (le_trans (Nat.le_add_right base.toNat 32) hInv.slotGe) - constructor - · change read + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).size - exact le_trans hmem attesterMultiRevokeInnerArrayInitStep_size_ge - · change - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).readWithPadding - read 32 = - UInt256.toByteArray word - have hstep := - attesterMultiRevokeInnerArrayInitStep_readWithPadding_nat - (base := readWord) (slot := b.slot) (len := word) - (mem := b.mem) (aw := b.aw) - (by simpa [readWord, hreadWordToNat] using hmem) - (by simpa [readWord, hreadWordToNat] using hread) - (by simpa [readWord, hreadWordToNat] using hread64) - (by simpa [readWord, hreadWordToNat] using hfree) - (by simpa [readWord, hreadWordToNat] using hsecond) - (by simpa [readWord, hreadWordToNat] using hslot) - simpa [readWord, hreadWordToNat] using hstep - -theorem AttesterReadPreservedBefore_innerInitFinal - {I : ExecutionEnv} {mem₀ : ByteArray} - {base len outerBase schemaLen : UInt256} - {b : AttesterMultiRevokeInnerArrayInitState} - (hInv : attesterMultiRevokeInnerInitReadInvAt I base len outerBase schemaLen 0 b) - (hpres : AttesterReadPreservedBefore mem₀ b.mem base.toNat) : - AttesterReadPreservedBefore mem₀ - (attesterMultiRevokeInnerArrayInitFinalMem b) base.toNat := by - intro read word hmem0 hread0 hread64 hbefore - rcases hpres hmem0 hread0 hread64 hbefore with ⟨hmem, hread⟩ - have hreadLt : read < UInt256.size := by - have hbaseLt : base.toNat < UInt256.size := base.val.isLt - omega - let readWord : UInt256 := UInt256.ofNat read - have hreadWordToNat : readWord.toNat = read := ulit_toNat' read hreadLt - have hfree32 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 32 < - UInt256.size := by - have hfb := hInv.freeBound - omega - have hsecondToNat : - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat = - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 32 := - attesterMultiRevokeInnerArrayInitSecondZeroWord_toNat - (mem := b.mem) (aw := b.aw) hfree32 - have hfree : - read + 32 ≤ (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat := by - exact le_trans hbefore (le_trans (Nat.le_add_right base.toNat 32) hInv.freeGe) - have hsecond : - read + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - rw [hsecondToNat] - exact le_trans hfree (Nat.le_add_right _ _) - have hslot : read + 32 ≤ b.slot.toNat := by - exact le_trans hbefore - (le_trans (Nat.le_add_right base.toNat 32) hInv.slotGe) - constructor - · change read + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).size - exact le_trans hmem attesterMultiRevokeInnerArrayInitStep_size_ge - · change - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).readWithPadding - read 32 = - UInt256.toByteArray word - have hstep := - attesterMultiRevokeInnerArrayInitStep_readWithPadding_nat - (base := readWord) (slot := b.slot) (len := word) - (mem := b.mem) (aw := b.aw) - (by simpa [readWord, hreadWordToNat] using hmem) - (by simpa [readWord, hreadWordToNat] using hread) - (by simpa [readWord, hreadWordToNat] using hread64) - (by simpa [readWord, hreadWordToNat] using hfree) - (by simpa [readWord, hreadWordToNat] using hsecond) - (by simpa [readWord, hreadWordToNat] using hslot) - simpa [readWord, hreadWordToNat] using hstep - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevokeInnerInitReadInvAt_init - {I : ExecutionEnv} {base len outerBase schemaLen : UInt256} - {mem : ByteArray} {aw : UInt256} - (hlenNe : len.toNat ≠ 0) - (hawGe : 3 ≤ aw.toNat) - (hawMul : aw.toNat * 32 < UInt256.size) - (hbaseGe : 64 + 32 ≤ base.toNat) - (hbaseSpare : base.toNat + 32 + 160 * len.toNat + 96 < UInt256.size) - (houterRead : mem.readWithPadding outerBase.toNat 32 = UInt256.toByteArray schemaLen) - (houterMemSize : outerBase.toNat + 32 ≤ mem.size) - (houter64 : 64 + 32 ≤ outerBase.toNat) - (houterBeforeBase : outerBase.toNat + 32 ≤ base.toNat) - (hbaseEq : base = attesterInnerArrayAllocFreeWord mem aw) : - attesterMultiRevokeInnerInitReadInvAt I base len outerBase schemaLen - (len.toNat - 1) - { slot := ((⟨32⟩ : UInt256) + base), - remaining := len, - mem := attesterInnerArrayAllocMem len mem aw, - aw := attesterInnerArrayAllocAw len mem aw } := by - have hlenSucc : len.toNat - 1 + 1 = len.toNat := by omega - have hbase63 : base.toNat + 63 < UInt256.size := by - have hpos : 1 ≤ len.toNat := Nat.succ_le_of_lt (Nat.pos_of_ne_zero hlenNe) - nlinarith - have hallocAw := - attesterInnerArrayAllocAw_bounds - (len := len) (mem := mem) (aw := aw) - hawGe hawMul (by simpa [← hbaseEq] using hbase63) - have hallocBound : - base.toNat + 32 + 32 * len.toNat < UInt256.size := by - have hpos : 0 ≤ len.toNat := Nat.zero_le _ - nlinarith - have hallocFreeToNat : - (attesterInnerArrayAllocFreeWord - (attesterInnerArrayAllocMem len mem aw) - (attesterInnerArrayAllocAw len mem aw)).toNat = - base.toNat + 32 + 32 * len.toNat := by - rw [hbaseEq] - exact attesterInnerArrayAllocMem_freeWord_toNat - (len := len) (mem := mem) (aw := aw) - hallocAw.2 hallocAw.1 (by simpa [hbaseEq] using hallocBound) - have hslotToNat : - (((⟨32⟩ : UInt256) + base).toNat) = base.toNat + 32 := - uadd_lit32_toNat base (by omega) - have hallocOuterRead : - (attesterInnerArrayAllocMem len mem aw).readWithPadding outerBase.toNat 32 = - UInt256.toByteArray schemaLen := by - simpa [hbaseEq] using - (attesterInnerArrayAllocMem_readWithPadding_at_nat - (readBase := outerBase) (len := len) - (readLen := schemaLen) (mem := mem) (aw := aw) - houterMemSize houterRead houter64 - (by simpa [hbaseEq] using houterBeforeBase)) - have hallocOuterMem : - outerBase.toNat + 32 ≤ (attesterInnerArrayAllocMem len mem aw).size := - le_trans houterMemSize attesterInnerArrayAllocMem_size_ge - exact - { remaining := by - simpa [hlenSucc] using (u256_ofNat_toNat len).symm - bound := by - rw [hlenSucc] - exact len.val.isLt - awGe := by - change 3 ≤ (attesterInnerArrayAllocAw len mem aw).toNat - exact hallocAw.1 - awMul := by - change (attesterInnerArrayAllocAw len mem aw).toNat * 32 < UInt256.size - exact hallocAw.2 - read := by - simpa [← hbaseEq] using - (attesterInnerArrayAllocMem_readWithPadding_len_nat - (len := len) (mem := mem) (aw := aw) - (by simpa [← hbaseEq] using hbaseGe)) - memSize := by - simpa [← hbaseEq] using - (attesterInnerArrayAllocMem_base_size - (len := len) (mem := mem) (aw := aw)) - le := by - rw [hlenSucc] - baseGe := hbaseGe - freeGe := by - change base.toNat + 32 ≤ - (attesterInnerArrayAllocFreeWord - (attesterInnerArrayAllocMem len mem aw) - (attesterInnerArrayAllocAw len mem aw)).toNat - rw [hallocFreeToNat] - omega - freeExact := by - change - (attesterInnerArrayAllocFreeWord - (attesterInnerArrayAllocMem len mem aw) - (attesterInnerArrayAllocAw len mem aw)).toNat = - base.toNat + 32 + 32 * len.toNat + - 64 * (len.toNat - (len.toNat - 1 + 1)) - rw [hallocFreeToNat] - have hzero : len.toNat - (len.toNat - 1 + 1) = 0 := by - omega - rw [hzero] - omega - freeBound := by - change - (attesterInnerArrayAllocFreeWord - (attesterInnerArrayAllocMem len mem aw) - (attesterInnerArrayAllocAw len mem aw)).toNat + - 64 * (len.toNat - 1 + 1) < UInt256.size - rw [hallocFreeToNat, hlenSucc] - nlinarith - freeSpare := by - change - (attesterInnerArrayAllocFreeWord - (attesterInnerArrayAllocMem len mem aw) - (attesterInnerArrayAllocAw len mem aw)).toNat + - 64 * (len.toNat - 1 + 1) + 64 * len.toNat + 96 < - UInt256.size - rw [hallocFreeToNat, hlenSucc] - nlinarith - slotGe := by - change base.toNat + 32 ≤ (((⟨32⟩ : UInt256) + base).toNat) - rw [hslotToNat] - slotBound := by - change (((⟨32⟩ : UInt256) + base).toNat) + - 32 * (len.toNat - 1 + 1) + 63 < UInt256.size - rw [hslotToNat, hlenSucc] - have hpos : 0 ≤ len.toNat := Nat.zero_le _ - nlinarith - baseSlot63 := by - have hpos : 0 ≤ len.toNat := Nat.zero_le _ - nlinarith - outerRead := hallocOuterRead - outerMemSize := hallocOuterMem - outer64 := houter64 - outerBeforeBase := houterBeforeBase } - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeInnerArrayInitFinalIterationAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len payload : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - (slot :: (⟨1⟩ : UInt256) :: base :: ⟨0⟩ :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - ((⟨0⟩ : UInt256) :: base :: len :: len :: payload :: tail) - (attesterMultiRevokeInnerArrayInitStepMem slot mem aw) - (attesterMultiRevokeInnerArrayInitStepAw slot mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterMultiOuterArrayInitFreeWord mem aw - let aw1 := attesterMultiOuterArrayInitAwAfterMload aw - let mem1 := attesterMultiOuterArrayInitFreeMem mem aw - let aw2 := attesterMultiOuterArrayInitFreeAw aw - let mem2 := attesterMultiOuterArrayInitZeroMem mem aw - let aw3 := attesterMultiOuterArrayInitZeroAw mem aw - let second := attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw - let mem3 := attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw - let aw4 := attesterMultiRevokeInnerArrayInitSecondZeroAw mem aw - let mem4 := attesterMultiRevokeInnerArrayInitStepMem slot mem aw - let aw5 := attesterMultiRevokeInnerArrayInitStepAw slot mem aw - have hcostMload : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - (⟨64⟩ : UInt256) :: ⟨64⟩ :: slot :: (⟨1⟩ : UInt256) :: base :: - ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStore64 : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - (⟨64⟩ : UInt256) :: ((⟨64⟩ : UInt256) + free) :: free :: slot :: - (⟨1⟩ : UInt256) :: base :: ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - free :: (⟨0⟩ : UInt256) :: ⟨0⟩ :: free :: slot :: - (⟨1⟩ : UInt256) :: base :: ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSecondZero : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - second :: (⟨0⟩ : UInt256) :: free :: slot :: (⟨1⟩ : UInt256) :: - base :: ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw4 - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSlot : - ∀ s : State, - s.machineState.activeWords = aw4 → - s.machineState.stack = - slot :: free :: slot :: (⟨1⟩ : UInt256) :: base :: ⟨0⟩ :: - len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw5 - Cₘ aw4 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hrd497 : ∃ k497 C497, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨497⟩ : UInt256) - (slot :: (⟨1⟩ : UInt256) :: base :: ⟨0⟩ :: len :: len :: payload :: tail) - mem4 aw5 ByteArray.empty (cA, σ) k497 C497 := by - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, second, mem3, aw4, mem4, aw5] using - evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨475⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨476⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨478⟩, 0x80, .DUP1) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨479⟩, 0x51, .MLOAD) - hcostMload (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨480⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨481⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨482⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨483⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨484⟩, 0x91, .SWAP2) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨485⟩, 0x52, .MSTORE) - hcostStore64 (by rfl) (by rfl) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨486⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨487⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨488⟩, 0x82, .DUP3) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨489⟩, 0x52, .MSTORE) - hcostStoreZero (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨490⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨492⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨493⟩, 0x01, .ADD) (by evm_ov), - raw mstore (Cₘ aw4 - Cₘ aw3) mem3 aw4 - (by attester_decode_at v, ⟨494⟩, 0x52, .MSTORE) - hcostStoreSecondZero (by rfl) (by rfl) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨495⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw5 - Cₘ aw4) mem4 aw5 - (by attester_decode_at v, ⟨496⟩, 0x52, .MSTORE) - hcostStoreSlot (by rfl) (by rfl) (by evm_ov)]⟩ - obtain ⟨_, _, rd497⟩ := hrd497 - have hrd511 : ∃ k511 C511, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨511⟩ : UInt256) - (((⟨32⟩ : UInt256) + slot) :: ⟨0⟩ :: base :: ⟨0⟩ :: - len :: len :: payload :: tail) - mem4 aw5 ByteArray.empty (cA, σ) k511 C511 := by - exact ⟨_, _, by - simpa using - evm_run rd497 with [ - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨497⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨499⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨500⟩, 0x90, .SWAP1) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨501⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨503⟩, 0x90, .SWAP1) (by evm_ov), - raw sub (by attester_decode_at v, ⟨504⟩, 0x03, .SUB) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨505⟩, 0x90, .SWAP1) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨506⟩, 0x81, .DUP2) (by evm_ov), - raw push2 ⟨475⟩ (by attester_decode_at v, ⟨507⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨510⟩, 0x57, .JUMPI) - (by native_decide) (by evm_ov)]⟩ - obtain ⟨_, _, rd511⟩ := hrd511 - have rd518 := evm_run rd511 with [ - raw swap1 (by attester_decode_at v, ⟨511⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨512⟩, 0x50, .POP) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨513⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨514⟩, 0x50, .POP) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨515⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨516⟩, 0x50, .POP) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨517⟩, 0x5f, .PUSH0) (by evm_ov)] - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, second, mem3, aw4, mem4, aw5] using rd518⟩ - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeInnerArrayInitNonFinalIterationAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len payload remaining : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hnext : UInt256.sub remaining (⟨1⟩ : UInt256) ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - (slot :: remaining :: base :: ⟨0⟩ :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - (((⟨32⟩ : UInt256) + slot) :: UInt256.sub remaining ⟨1⟩ :: - base :: ⟨0⟩ :: len :: len :: payload :: tail) - (attesterMultiRevokeInnerArrayInitStepMem slot mem aw) - (attesterMultiRevokeInnerArrayInitStepAw slot mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterMultiOuterArrayInitFreeWord mem aw - let aw1 := attesterMultiOuterArrayInitAwAfterMload aw - let mem1 := attesterMultiOuterArrayInitFreeMem mem aw - let aw2 := attesterMultiOuterArrayInitFreeAw aw - let mem2 := attesterMultiOuterArrayInitZeroMem mem aw - let aw3 := attesterMultiOuterArrayInitZeroAw mem aw - let second := attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw - let mem3 := attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw - let aw4 := attesterMultiRevokeInnerArrayInitSecondZeroAw mem aw - let mem4 := attesterMultiRevokeInnerArrayInitStepMem slot mem aw - let aw5 := attesterMultiRevokeInnerArrayInitStepAw slot mem aw - have hcostMload : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - (⟨64⟩ : UInt256) :: ⟨64⟩ :: slot :: remaining :: base :: - ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStore64 : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - (⟨64⟩ : UInt256) :: ((⟨64⟩ : UInt256) + free) :: free :: slot :: - remaining :: base :: ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - free :: (⟨0⟩ : UInt256) :: ⟨0⟩ :: free :: slot :: - remaining :: base :: ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSecondZero : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - second :: (⟨0⟩ : UInt256) :: free :: slot :: remaining :: - base :: ⟨0⟩ :: len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw4 - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSlot : - ∀ s : State, - s.machineState.activeWords = aw4 → - s.machineState.stack = - slot :: free :: slot :: remaining :: base :: ⟨0⟩ :: - len :: len :: payload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw5 - Cₘ aw4 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hrd497 : ∃ k497 C497, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨497⟩ : UInt256) - (slot :: remaining :: base :: ⟨0⟩ :: len :: len :: payload :: tail) - mem4 aw5 ByteArray.empty (cA, σ) k497 C497 := by - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, second, mem3, aw4, mem4, aw5] using - evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨475⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨476⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨478⟩, 0x80, .DUP1) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨479⟩, 0x51, .MLOAD) - hcostMload (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨480⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨481⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨482⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨483⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨484⟩, 0x91, .SWAP2) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨485⟩, 0x52, .MSTORE) - hcostStore64 (by rfl) (by rfl) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨486⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨487⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨488⟩, 0x82, .DUP3) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨489⟩, 0x52, .MSTORE) - hcostStoreZero (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨490⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨492⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨493⟩, 0x01, .ADD) (by evm_ov), - raw mstore (Cₘ aw4 - Cₘ aw3) mem3 aw4 - (by attester_decode_at v, ⟨494⟩, 0x52, .MSTORE) - hcostStoreSecondZero (by rfl) (by rfl) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨495⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw5 - Cₘ aw4) mem4 aw5 - (by attester_decode_at v, ⟨496⟩, 0x52, .MSTORE) - hcostStoreSlot (by rfl) (by rfl) (by evm_ov)]⟩ - obtain ⟨_, _, rd497⟩ := hrd497 - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, second, mem3, aw4, mem4, aw5] using - evm_run rd497 with [ - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨497⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨499⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨500⟩, 0x90, .SWAP1) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨501⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨503⟩, 0x90, .SWAP1) (by evm_ov), - raw sub (by attester_decode_at v, ⟨504⟩, 0x03, .SUB) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨505⟩, 0x90, .SWAP1) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨506⟩, 0x81, .DUP2) (by evm_ov), - raw push2 ⟨475⟩ (by attester_decode_at v, ⟨507⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨510⟩, 0x57, .JUMPI) - (by simpa using hnext) - (attesterMultiRevokeInnerArrayInitLoopJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeInnerArrayInitLoopWithStateInvariantAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len payload : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (Inv : Nat → AttesterMultiRevokeInnerArrayInitState → Prop) - (hremaining : - ∀ n a, Inv n a → a.remaining = UInt256.ofNat (n + 1)) - (hbound : - ∀ n a, Inv n a → n + 1 < UInt256.size) - (hstep : - ∀ n a, Inv (n + 1) a → Inv n (attesterMultiRevokeInnerArrayInitStepState a)) - (hinit : - Inv (len.toNat - 1) - { slot := slot, remaining := len, mem := mem, aw := aw }) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - (slot :: len :: base :: ⟨0⟩ :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ a' k' C', - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv 0 a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (attesterMultiRevokeInnerArrayInitExitStackAt base len payload tail a') - (attesterMultiRevokeInnerArrayInitFinalMem a') - (attesterMultiRevokeInnerArrayInitFinalAw a') - ByteArray.empty (cA, σ) k' C' := by - let stk := attesterMultiRevokeInnerArrayInitStackAt base len payload tail - let memOf : AttesterMultiRevokeInnerArrayInitState → ByteArray := fun a => a.mem - let awOf : AttesterMultiRevokeInnerArrayInitState → UInt256 := fun a => a.aw - let exitStk := attesterMultiRevokeInnerArrayInitExitStackAt base len payload tail - let exitMem := attesterMultiRevokeInnerArrayInitFinalMem - let exitAw := attesterMultiRevokeInnerArrayInitFinalAw - have hexit : - ∀ a, Inv 0 a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨475⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨518⟩ : UInt256) (exitStk a) (exitMem a) (exitAw a) - ByteArray.empty (cA, σ) k' C' := by - intro a hInv k C rd - have hrem : a.remaining = (⟨1⟩ : UInt256) := by - simpa using hremaining 0 a hInv - exact attesterX_multiRevokeInnerArrayInitFinalIterationAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (payload := payload) (tail := tail) (mem := a.mem) (aw := a.aw) - (k := k) (C := C) htail - (by - simpa [stk, memOf, awOf, exitStk, exitMem, exitAw, hrem, - attesterMultiRevokeInnerArrayInitStackAt] using rd) - have hbody : - ∀ n a, Inv (n + 1) a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨475⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ a' k' C', - Inv n a' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨475⟩ : UInt256) (stk a') (memOf a') (awOf a') - ByteArray.empty (cA, σ) k' C' := by - intro n a hInv k C rd - let a' := attesterMultiRevokeInnerArrayInitStepState a - have hsub : - UInt256.sub a.remaining (⟨1⟩ : UInt256) = UInt256.ofNat (n + 1) := by - rw [hremaining (n + 1) a hInv] - simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using - attester_u256_ofNat_succ_sub_one (n := n + 1) - (hbound (n + 1) a hInv) - have hnext : UInt256.sub a.remaining (⟨1⟩ : UInt256) ≠ ⟨0⟩ := by - rw [hsub] - exact attester_u256_ofNat_pos_ne_zero - (n := n + 1) (by omega) (by - have := hbound (n + 1) a hInv - omega) - obtain ⟨k', C', rd'⟩ := - attesterX_multiRevokeInnerArrayInitNonFinalIterationAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (payload := payload) (remaining := a.remaining) (tail := tail) - (mem := a.mem) (aw := a.aw) (k := k) (C := C) htail hnext - (by - simpa [stk, memOf, awOf, attesterMultiRevokeInnerArrayInitStackAt] - using rd) - refine ⟨a', k', C', hstep n a hInv, ?_⟩ - simpa [a', stk, memOf, awOf, attesterMultiRevokeInnerArrayInitStackAt, - attesterMultiRevokeInnerArrayInitStepState] using rd' - let a0 : AttesterMultiRevokeInnerArrayInitState := - { slot := slot, remaining := len, mem := mem, aw := aw } - obtain ⟨a', k', C', hInvFinal, rdFinal⟩ := - RD.whileLoopCarryExit - (code := patchedRuntime v) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) - (rdata := ByteArray.empty) (acc := (cA, σ)) - (header := (⟨475⟩ : UInt256)) (exit := (⟨518⟩ : UInt256)) - Inv stk memOf awOf exitStk exitMem exitAw hexit hbody - (len.toNat - 1) a0 (by simpa [a0] using hinit) k C - (by - simpa [a0, stk, memOf, awOf, attesterMultiRevokeInnerArrayInitStackAt] - using hreach) - exact ⟨a', k', C', by simpa using hremaining 0 a' hInvFinal, - hInvFinal, rdFinal⟩ - -theorem attesterX_multiRevokeInnerArrayReturnCleanupAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {len payload sz idx outerBase schemaLen secondLen secondPayload schemaPayload - ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨381⟩ : UInt256) - [len, payload, ⟨0⟩, sz, idx, outerBase, schemaLen, secondLen, - secondPayload, schemaLen, schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨387⟩ : UInt256) - [len, payload, idx, outerBase, schemaLen, secondLen, secondPayload, - schemaLen, schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨381⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨382⟩, 0x90, .SWAP1) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨383⟩, 0x92, .SWAP3) (by evm_ov), - raw pop (by attester_decode_at v, ⟨384⟩, 0x50, .POP) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨385⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨386⟩, 0x50, .POP) (by evm_ov)]⟩ - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeInnerArrayLengthZeroRevertsAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {len payload sz idx outerBase schemaLen secondLen secondPayload schemaPayload - ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hlenZero : len = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨381⟩ : UInt256) - [len, payload, ⟨0⟩, sz, idx, outerBase, schemaLen, secondLen, - secondPayload, schemaLen, schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨k0, C0, rd3870⟩ := - attesterX_multiRevokeInnerArrayReturnCleanupAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (len := len) (payload := payload) (sz := sz) (idx := idx) - (outerBase := outerBase) (schemaLen := schemaLen) (secondLen := secondLen) - (secondPayload := secondPayload) (schemaPayload := schemaPayload) - (ret := ret) (selector := selector) (mem := mem) (aw := aw) - (k := k) (C := C) hreach - let tail := [schemaLen, secondLen, secondPayload, schemaLen, schemaPayload, ret, selector] - have rd387 : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨387⟩ : UInt256) - (len :: payload :: idx :: outerBase :: tail) - mem aw ByteArray.empty (cA, σ) k0 C0 := by - simpa [tail] using rd3870 - let free := - if (⟨64⟩ : UInt256).toNat ≥ mem.size ∨ (⟨64⟩ : UInt256) ≥ aw * ⟨32⟩ then - (⟨0⟩ : UInt256) - else - UInt256.ofNat (fromByteArrayBigEndian (mem.readWithPadding (⟨64⟩ : UInt256).toNat 32)) - let aw1 := UInt256.ofNat (MachineState.M aw.toNat (⟨64⟩ : UInt256).toNat 32) - let revertSelector := UInt256.shiftLeft (⟨3036299187⟩ : UInt256) ⟨224⟩ - let mem1 := revertSelector.toByteArray.write 0 mem free.toNat 32 - let aw2 := UInt256.ofNat (MachineState.M aw1.toNat free.toNat 32) - let freeAfter := - if (⟨64⟩ : UInt256).toNat ≥ mem1.size ∨ (⟨64⟩ : UInt256) ≥ aw2 * ⟨32⟩ then - (⟨0⟩ : UInt256) - else - UInt256.ofNat (fromByteArrayBigEndian (mem1.readWithPadding (⟨64⟩ : UInt256).toNat 32)) - let aw3 := UInt256.ofNat (MachineState.M aw2.toNat (⟨64⟩ : UInt256).toNat 32) - let revLen := UInt256.sub ((⟨4⟩ : UInt256) + free) freeAfter - let revAw := UInt256.ofNat (MachineState.M aw3.toNat freeAfter.toNat revLen.toNat) - have hcostMload64 : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - (⟨64⟩ : UInt256) :: len :: len :: payload :: idx :: outerBase :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostMstoreSelector : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - free :: revertSelector :: free :: len :: len :: payload :: idx :: outerBase :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostMload64After : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - (⟨64⟩ : UInt256) :: ((⟨4⟩ : UInt256) + free) :: len :: len :: - payload :: idx :: outerBase :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostRevert : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - freeAfter :: revLen :: len :: len :: payload :: idx :: outerBase :: tail → - memoryExpansionCost s .REVERT = Cₘ revAw - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero, List.getElem!_cons_succ] - rfl - exact evm_run rd387 with [ - raw dup1 (by attester_decode_at v, ⟨387⟩, 0x80, .DUP1) (by simp [tail]), - raw push0 (by attester_decode_at v, ⟨388⟩, 0x5f, .PUSH0) (by simp [tail]), - raw dup2 (by attester_decode_at v, ⟨389⟩, 0x81, .DUP2) (by simp [tail]), - raw swap1 (by attester_decode_at v, ⟨390⟩, 0x90, .SWAP1) (by simp [tail]), - raw sub (by attester_decode_at v, ⟨391⟩, 0x03, .SUB) (by simp [tail]), - raw push2 ⟨420⟩ (by attester_decode_at v, ⟨392⟩, 0x61, (.Push .PUSH2)) - (by simp [tail]), - raw jumpiNT (by attester_decode_at v, ⟨395⟩, 0x57, .JUMPI) - (by - rw [show len = (⟨0⟩ : UInt256) by simpa using hlenZero] - native_decide) - (by simp [tail]), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨396⟩, 0x60, (.Push .PUSH1)) - (by simp [tail]), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨398⟩, 0x51, .MLOAD) - hcostMload64 (by rfl) (by rfl) (by simp [tail]), - raw push4 ⟨3036299187⟩ (by attester_decode_at v, ⟨399⟩, 0x63, (.Push .PUSH4)) - (by simp [tail]), - raw push1 ⟨224⟩ (by attester_decode_at v, ⟨404⟩, 0x60, (.Push .PUSH1)) - (by simp [tail]), - raw shl (by attester_decode_at v, ⟨406⟩, 0x1b, .SHL) (by simp [tail]), - raw dup2 (by attester_decode_at v, ⟨407⟩, 0x81, .DUP2) (by simp [tail]), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨408⟩, 0x52, .MSTORE) - hcostMstoreSelector (by rfl) (by rfl) (by simp [tail]), - raw push1 ⟨4⟩ (by attester_decode_at v, ⟨409⟩, 0x60, (.Push .PUSH1)) - (by simp [tail]), - raw add (by attester_decode_at v, ⟨411⟩, 0x01, .ADD) (by simp [tail]), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨412⟩, 0x60, (.Push .PUSH1)) - (by simp [tail]), - raw mload (Cₘ aw3 - Cₘ aw2) freeAfter aw3 - (by attester_decode_at v, ⟨414⟩, 0x51, .MLOAD) - hcostMload64After (by rfl) (by rfl) (by simp [tail]), - raw dup1 (by attester_decode_at v, ⟨415⟩, 0x80, .DUP1) (by simp [tail]), - raw swap2 (by attester_decode_at v, ⟨416⟩, 0x91, .SWAP2) (by simp [tail]), - raw sub (by attester_decode_at v, ⟨417⟩, 0x03, .SUB) (by simp [tail]), - raw swap1 (by attester_decode_at v, ⟨418⟩, 0x90, .SWAP1) (by simp [tail]), - raw rev (Cₘ revAw - Cₘ aw3) - (by attester_decode_at v, ⟨419⟩, 0xfd, .REVERT) - hcostRevert (by simp [tail])] - -theorem attesterX_multiRevokeInnerArrayNonemptyGuardOkAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {len payload idx outerBase schemaLen secondLen secondPayload schemaPayload - ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hlenNe : len ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨387⟩ : UInt256) - [len, payload, idx, outerBase, schemaLen, secondLen, secondPayload, - schemaLen, schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨420⟩ : UInt256) - [len, len, payload, idx, outerBase, schemaLen, secondLen, secondPayload, - schemaLen, schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k' C' := by - have rd388 := RD.dup1 hreach - (by attester_decode_at v, ⟨387⟩, 0x80, .DUP1) (by evm_ov) - have rd389 := RD.push0 rd388 - (by attester_decode_at v, ⟨388⟩, 0x5f, .PUSH0) (by evm_ov) - have rd390 := RD.dup2 rd389 - (by attester_decode_at v, ⟨389⟩, 0x81, .DUP2) (by evm_ov) - have rd391 := RD.swap1 rd390 - (by attester_decode_at v, ⟨390⟩, 0x90, .SWAP1) (by evm_ov) - have rd392 := RD.sub rd391 - (by attester_decode_at v, ⟨391⟩, 0x03, .SUB) (by evm_ov) - have rd395 := RD.push2 rd392 ⟨420⟩ - (by attester_decode_at v, ⟨392⟩, 0x61, (.Push .PUSH2)) (by evm_ov) - have hcond : UInt256.sub (⟨0⟩ : UInt256) len ≠ ⟨0⟩ := - u256_zero_sub_ne_zero hlenNe - have rd420 := RD.jumpiT rd395 - (by attester_decode_at v, ⟨395⟩, 0x57, .JUMPI) - hcond (attesterMultiRevokeInnerNonemptyOkJumpdest v) (by evm_ov) - exact ⟨_, _, by simpa using rd420⟩ - -theorem attesterX_multiRevokeInnerArrayNonemptyOkAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {len payload sz idx outerBase schemaLen secondLen secondPayload schemaPayload - ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hlenNe : len ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨381⟩ : UInt256) - [len, payload, ⟨0⟩, sz, idx, outerBase, schemaLen, secondLen, - secondPayload, schemaLen, schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨420⟩ : UInt256) - [len, len, payload, idx, outerBase, schemaLen, secondLen, secondPayload, - schemaLen, schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd387⟩ := - attesterX_multiRevokeInnerArrayReturnCleanupAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (len := len) (payload := payload) (sz := sz) (idx := idx) - (outerBase := outerBase) (schemaLen := schemaLen) (secondLen := secondLen) - (secondPayload := secondPayload) (schemaPayload := schemaPayload) - (ret := ret) (selector := selector) (mem := mem) (aw := aw) - (k := k) (C := C) hreach - exact attesterX_multiRevokeInnerArrayNonemptyGuardOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (len := len) (payload := payload) (idx := idx) (outerBase := outerBase) - (schemaLen := schemaLen) (secondLen := secondLen) - (secondPayload := secondPayload) (schemaPayload := schemaPayload) - (ret := ret) (selector := selector) (mem := mem) (aw := aw) - (k := k0) (C := C0) hlenNe rd387 - -theorem attesterX_multiRevokeInnerArrayLengthAllocMaxOkAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {len payload : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hgt : - UInt256.gt len - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨420⟩ : UInt256) - (len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨445⟩ : UInt256) - (len :: ⟨0⟩ :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨420⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨421⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨422⟩, 0x81, .DUP2) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨423⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨425⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨427⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨429⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨430⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨431⟩, 0x81, .DUP2) (by evm_ov), - raw gt (by attester_decode_at v, ⟨432⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨433⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨445⟩ (by attester_decode_at v, ⟨434⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨437⟩, 0x57, .JUMPI) - (by - rw [hgt] - decide) - (attesterMultiRevokeInnerLengthMaxOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeInnerArrayNonemptyAndLengthOkAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {len payload sz idx outerBase schemaLen secondLen secondPayload schemaPayload - ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hlenNe : len ≠ ⟨0⟩) - (hgt : - UInt256.gt len - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨381⟩ : UInt256) - [len, payload, ⟨0⟩, sz, idx, outerBase, schemaLen, secondLen, - secondPayload, schemaLen, schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨445⟩ : UInt256) - [len, ⟨0⟩, len, len, payload, idx, outerBase, schemaLen, secondLen, - secondPayload, schemaLen, schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd420⟩ := - attesterX_multiRevokeInnerArrayNonemptyOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (len := len) (payload := payload) (sz := sz) (idx := idx) - (outerBase := outerBase) (schemaLen := schemaLen) (secondLen := secondLen) - (secondPayload := secondPayload) (schemaPayload := schemaPayload) - (ret := ret) (selector := selector) (mem := mem) (aw := aw) - (k := k) (C := C) hlenNe hreach - exact attesterX_multiRevokeInnerArrayLengthAllocMaxOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (len := len) (payload := payload) - (tail := [idx, outerBase, schemaLen, secondLen, secondPayload, - schemaLen, schemaPayload, ret, selector]) - (mem := mem) (aw := aw) (k := k0) (C := C0) (by simp) hgt - (by simpa using rd420) - -theorem attesterX_multiRevokeInnerDecoderToAllocAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx outerBase schemaLen secondLen secondPayload schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hoffsetOk : - UInt256.slt - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) secondPayload) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩) - (hlenOk : - UInt256.gt - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hpayloadOk : - UInt256.sgt - (attesterMultiRevokeInnerArrayPayloadWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) ⟨5⟩)) = ⟨0⟩) - (hlenNe : - attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx) ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨363⟩ : UInt256) - [idx, secondLen, secondPayload, ⟨0⟩, UInt256.ofNat I.calldata.size, - idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨445⟩ : UInt256) - [attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx), - ⟨0⟩, - attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx), - attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx), - attesterMultiRevokeInnerArrayPayloadWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx), - idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k' C' := by - let head := attesterMultiRevokeInnerArrayHeadWord secondPayload idx - let innerLen := attesterMultiRevokeInnerArrayLengthWord I secondPayload head - let innerPayload := attesterMultiRevokeInnerArrayPayloadWord I secondPayload head - let tail := - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - obtain ⟨k0, C0, rd2353⟩ := - attesterX_multiRevokeInnerArrayDecoderEntryAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (l := secondLen) (p := secondPayload) - (sz := UInt256.ofNat I.calldata.size) (base := outerBase) - (len := schemaLen) (fp := schemaPayload) (ret := ret) (sel := selector) - (mem := mem) (aw := aw) (k := k) (C := C) hreach - obtain ⟨k1, C1, rd2374⟩ := - attesterX_multiRevokeInnerArrayOffsetOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := secondPayload) (head := head) (ret := ⟨381⟩) - (sz := UInt256.ofNat I.calldata.size) (tail := tail) - (mem := mem) (aw := aw) (k := k0) (C := C0) - (by simp [tail]) (by simpa [head] using hoffsetOk) - (by simpa [head, tail] using rd2353) - obtain ⟨k2, C2, rd2399⟩ := - attesterX_multiRevokeInnerArrayLengthMaxOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := secondPayload) (head := head) (ret := ⟨381⟩) - (sz := UInt256.ofNat I.calldata.size) (tail := tail) - (mem := mem) (aw := aw) (k := k1) (C := C1) - (by simp [tail]) (by simpa [head, innerLen] using hlenOk) - (by simpa [head, tail] using rd2374) - obtain ⟨k3, C3, rd381⟩ := - attesterX_multiRevokeInnerArrayPayloadOkToReturnAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := secondPayload) (head := head) (ret := ⟨381⟩) - (sz := UInt256.ofNat I.calldata.size) (tail := tail) - (mem := mem) (aw := aw) (k := k2) (C := C2) - (by simp [tail]) (by simpa [head, innerLen, innerPayload] using hpayloadOk) - (attesterMultiRevokeInnerArrayReturnJumpdest v) - (by simpa [head, innerLen, tail] using rd2399) - exact attesterX_multiRevokeInnerArrayNonemptyAndLengthOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (len := innerLen) (payload := innerPayload) - (sz := UInt256.ofNat I.calldata.size) (idx := idx) (outerBase := outerBase) - (schemaLen := schemaLen) (secondLen := secondLen) - (secondPayload := secondPayload) (schemaPayload := schemaPayload) - (ret := ret) (selector := selector) (mem := mem) (aw := aw) - (k := k3) (C := C3) (by simpa [head, innerLen] using hlenNe) - (by simpa [head, innerLen] using hlenOk) - (by simpa [head, innerLen, innerPayload, tail] using rd381) - -theorem attesterX_multiRevokeOuterIterationLengthZeroRevertsAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx outerBase schemaLen secondLen secondPayload schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hidxSchema : UInt256.lt idx schemaLen = ⟨1⟩) - (hidxSecond : UInt256.lt idx secondLen = ⟨1⟩) - (hoffsetOk : - UInt256.slt - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) secondPayload) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩) - (hlenOk : - UInt256.gt - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hpayloadOk : - UInt256.sgt - (attesterMultiRevokeInnerArrayPayloadWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) ⟨5⟩)) = ⟨0⟩) - (hlenZero : - attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - let head := attesterMultiRevokeInnerArrayHeadWord secondPayload idx - let innerLen := attesterMultiRevokeInnerArrayLengthWord I secondPayload head - let innerPayload := attesterMultiRevokeInnerArrayPayloadWord I secondPayload head - let tail := - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - obtain ⟨k0, C0, rd344⟩ := - attesterX_multiRevokeOuterSourceLoopGuard - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k) (C := C) hidxSchema hreach - obtain ⟨k1, C1, rd363⟩ := - attesterX_multiRevokeOuterSecondArrayAccessOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k0) (C := C0) hidxSecond rd344 - obtain ⟨k2, C2, rd2353⟩ := - attesterX_multiRevokeInnerArrayDecoderEntryAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (l := secondLen) (p := secondPayload) - (sz := UInt256.ofNat I.calldata.size) (base := outerBase) - (len := schemaLen) (fp := schemaPayload) (ret := ret) (sel := selector) - (mem := mem) (aw := aw) (k := k1) (C := C1) rd363 - obtain ⟨k3, C3, rd2374⟩ := - attesterX_multiRevokeInnerArrayOffsetOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := secondPayload) (head := head) (ret := ⟨381⟩) - (sz := UInt256.ofNat I.calldata.size) (tail := tail) - (mem := mem) (aw := aw) (k := k2) (C := C2) - (by simp [tail]) (by simpa [head] using hoffsetOk) - (by simpa [head, tail] using rd2353) - obtain ⟨k4, C4, rd2399⟩ := - attesterX_multiRevokeInnerArrayLengthMaxOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := secondPayload) (head := head) (ret := ⟨381⟩) - (sz := UInt256.ofNat I.calldata.size) (tail := tail) - (mem := mem) (aw := aw) (k := k3) (C := C3) - (by simp [tail]) (by simpa [head, innerLen] using hlenOk) - (by simpa [head, tail] using rd2374) - obtain ⟨k5, C5, rd381⟩ := - attesterX_multiRevokeInnerArrayPayloadOkToReturnAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := secondPayload) (head := head) (ret := ⟨381⟩) - (sz := UInt256.ofNat I.calldata.size) (tail := tail) - (mem := mem) (aw := aw) (k := k4) (C := C4) - (by simp [tail]) (by simpa [head, innerLen, innerPayload] using hpayloadOk) - (attesterMultiRevokeInnerArrayReturnJumpdest v) - (by simpa [head, innerLen, tail] using rd2399) - exact attesterX_multiRevokeInnerArrayLengthZeroRevertsAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (len := innerLen) (payload := innerPayload) (sz := UInt256.ofNat I.calldata.size) - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k5) (C := C5) - (by simpa [head, innerLen] using hlenZero) - (by simpa [head, innerLen, innerPayload, tail] using rd381) - -theorem attesterX_multiRevokeOuterIterationOffsetRevertsAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx outerBase schemaLen secondLen secondPayload schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hidxSchema : UInt256.lt idx schemaLen = ⟨1⟩) - (hidxSecond : UInt256.lt idx secondLen = ⟨1⟩) - (hoffsetBad : - UInt256.slt - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) secondPayload) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - let head := attesterMultiRevokeInnerArrayHeadWord secondPayload idx - let tail := - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - obtain ⟨k0, C0, rd344⟩ := - attesterX_multiRevokeOuterSourceLoopGuard - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k) (C := C) hidxSchema hreach - obtain ⟨k1, C1, rd363⟩ := - attesterX_multiRevokeOuterSecondArrayAccessOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k0) (C := C0) hidxSecond rd344 - obtain ⟨k2, C2, rd2353⟩ := - attesterX_multiRevokeInnerArrayDecoderEntryAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (l := secondLen) (p := secondPayload) - (sz := UInt256.ofNat I.calldata.size) (base := outerBase) - (len := schemaLen) (fp := schemaPayload) (ret := ret) (sel := selector) - (mem := mem) (aw := aw) (k := k1) (C := C1) rd363 - exact - attesterX_multiRevokeInnerArrayOffsetRevertsAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := secondPayload) (head := head) (ret := ⟨381⟩) - (sz := UInt256.ofNat I.calldata.size) (tail := tail) - (mem := mem) (aw := aw) (k := k2) (C := C2) - (by simp [tail]) (by simpa [head] using hoffsetBad) - (by simpa [head, tail] using rd2353) - -theorem attesterX_multiRevokeOuterIterationLengthMaxRevertsAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx outerBase schemaLen secondLen secondPayload schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hidxSchema : UInt256.lt idx schemaLen = ⟨1⟩) - (hidxSecond : UInt256.lt idx secondLen = ⟨1⟩) - (hoffsetOk : - UInt256.slt - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) secondPayload) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩) - (hlenBad : - UInt256.gt - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨1⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - let head := attesterMultiRevokeInnerArrayHeadWord secondPayload idx - let tail := - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - obtain ⟨k0, C0, rd344⟩ := - attesterX_multiRevokeOuterSourceLoopGuard - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k) (C := C) hidxSchema hreach - obtain ⟨k1, C1, rd363⟩ := - attesterX_multiRevokeOuterSecondArrayAccessOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k0) (C := C0) hidxSecond rd344 - obtain ⟨k2, C2, rd2353⟩ := - attesterX_multiRevokeInnerArrayDecoderEntryAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (l := secondLen) (p := secondPayload) - (sz := UInt256.ofNat I.calldata.size) (base := outerBase) - (len := schemaLen) (fp := schemaPayload) (ret := ret) (sel := selector) - (mem := mem) (aw := aw) (k := k1) (C := C1) rd363 - obtain ⟨k3, C3, rd2374⟩ := - attesterX_multiRevokeInnerArrayOffsetOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := secondPayload) (head := head) (ret := ⟨381⟩) - (sz := UInt256.ofNat I.calldata.size) (tail := tail) - (mem := mem) (aw := aw) (k := k2) (C := C2) - (by simp [tail]) (by simpa [head] using hoffsetOk) - (by simpa [head, tail] using rd2353) - exact - attesterX_multiRevokeInnerArrayLengthMaxRevertsAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := secondPayload) (head := head) (ret := ⟨381⟩) - (sz := UInt256.ofNat I.calldata.size) (tail := tail) - (mem := mem) (aw := aw) (k := k3) (C := C3) - (by simp [tail]) (by simpa [head] using hlenBad) - (by simpa [head, tail] using rd2374) - -theorem attesterX_multiRevokeOuterIterationPayloadRevertsAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx outerBase schemaLen secondLen secondPayload schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hidxSchema : UInt256.lt idx schemaLen = ⟨1⟩) - (hidxSecond : UInt256.lt idx secondLen = ⟨1⟩) - (hoffsetOk : - UInt256.slt - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) secondPayload) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩) - (hlenOk : - UInt256.gt - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hpayloadBad : - UInt256.sgt - (attesterMultiRevokeInnerArrayPayloadWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) ⟨5⟩)) = ⟨1⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - let head := attesterMultiRevokeInnerArrayHeadWord secondPayload idx - let innerLen := attesterMultiRevokeInnerArrayLengthWord I secondPayload head - let tail := - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - obtain ⟨k0, C0, rd344⟩ := - attesterX_multiRevokeOuterSourceLoopGuard - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k) (C := C) hidxSchema hreach - obtain ⟨k1, C1, rd363⟩ := - attesterX_multiRevokeOuterSecondArrayAccessOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k0) (C := C0) hidxSecond rd344 - obtain ⟨k2, C2, rd2353⟩ := - attesterX_multiRevokeInnerArrayDecoderEntryAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (l := secondLen) (p := secondPayload) - (sz := UInt256.ofNat I.calldata.size) (base := outerBase) - (len := schemaLen) (fp := schemaPayload) (ret := ret) (sel := selector) - (mem := mem) (aw := aw) (k := k1) (C := C1) rd363 - obtain ⟨k3, C3, rd2374⟩ := - attesterX_multiRevokeInnerArrayOffsetOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := secondPayload) (head := head) (ret := ⟨381⟩) - (sz := UInt256.ofNat I.calldata.size) (tail := tail) - (mem := mem) (aw := aw) (k := k2) (C := C2) - (by simp [tail]) (by simpa [head] using hoffsetOk) - (by simpa [head, tail] using rd2353) - obtain ⟨k4, C4, rd2399⟩ := - attesterX_multiRevokeInnerArrayLengthMaxOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := secondPayload) (head := head) (ret := ⟨381⟩) - (sz := UInt256.ofNat I.calldata.size) (tail := tail) - (mem := mem) (aw := aw) (k := k3) (C := C3) - (by simp [tail]) (by simpa [head, innerLen] using hlenOk) - (by simpa [head, tail] using rd2374) - obtain ⟨k5, C5, rd2405⟩ := - attesterX_multiRevokeInnerArrayPayloadSetupAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := secondPayload) (head := head) (ret := ⟨381⟩) - (sz := UInt256.ofNat I.calldata.size) (tail := tail) - (mem := mem) (aw := aw) (k := k4) (C := C4) - (by simp [tail]) - (by simpa [head, innerLen, tail] using rd2399) - exact - attesterX_multiRevokeInnerArrayPayloadGuardRevertsAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := secondPayload) (head := head) (ret := ⟨381⟩) - (sz := UInt256.ofNat I.calldata.size) (tail := tail) - (mem := mem) (aw := aw) (k := k5) (C := C5) - (by simp [tail]) (by simpa [head, innerLen] using hpayloadBad) - (by simpa [head, innerLen, tail] using rd2405) - -theorem attesterX_multiRevokeOuterIterationToAllocAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx outerBase schemaLen secondLen secondPayload schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hidxSchema : UInt256.lt idx schemaLen = ⟨1⟩) - (hidxSecond : UInt256.lt idx secondLen = ⟨1⟩) - (hoffsetOk : - UInt256.slt - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) secondPayload) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩) - (hlenOk : - UInt256.gt - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hpayloadOk : - UInt256.sgt - (attesterMultiRevokeInnerArrayPayloadWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) ⟨5⟩)) = ⟨0⟩) - (hlenNe : - attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx) ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨445⟩ : UInt256) - [attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx), - ⟨0⟩, - attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx), - attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx), - attesterMultiRevokeInnerArrayPayloadWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx), - idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd344⟩ := - attesterX_multiRevokeOuterSourceLoopGuard - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k) (C := C) hidxSchema hreach - obtain ⟨k1, C1, rd363⟩ := - attesterX_multiRevokeOuterSecondArrayAccessOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k0) (C := C0) hidxSecond rd344 - exact attesterX_multiRevokeInnerDecoderToAllocAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k1) (C := C1) - hoffsetOk hlenOk hpayloadOk hlenNe rd363 - -theorem attesterX_multiRevokeOuterIterationToInnerInitAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx outerBase schemaLen secondLen secondPayload schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hidxSchema : UInt256.lt idx schemaLen = ⟨1⟩) - (hidxSecond : UInt256.lt idx secondLen = ⟨1⟩) - (hoffsetOk : - UInt256.slt - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) secondPayload) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩) - (hlenOk : - UInt256.gt - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hpayloadOk : - UInt256.sgt - (attesterMultiRevokeInnerArrayPayloadWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) ⟨5⟩)) = ⟨0⟩) - (hlenNe : - attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx) ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - [((⟨32⟩ : UInt256) + attesterInnerArrayAllocFreeWord mem aw), - attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx), - attesterInnerArrayAllocFreeWord mem aw, - ⟨0⟩, - attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx), - attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx), - attesterMultiRevokeInnerArrayPayloadWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx), - idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - (attesterInnerArrayAllocMem - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - mem aw) - (attesterInnerArrayAllocAw - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - mem aw) - ByteArray.empty (cA, σ) k' C' := by - let head := attesterMultiRevokeInnerArrayHeadWord secondPayload idx - let innerLen := attesterMultiRevokeInnerArrayLengthWord I secondPayload head - let innerPayload := attesterMultiRevokeInnerArrayPayloadWord I secondPayload head - let tail := - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - obtain ⟨k0, C0, rd445⟩ := - attesterX_multiRevokeOuterIterationToAllocAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k) (C := C) - hidxSchema hidxSecond hoffsetOk hlenOk hpayloadOk hlenNe hreach - obtain ⟨k1, C1, rd475⟩ := - attesterX_multiRevokeFirstInnerArrayAllocToInitLoop - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (len := innerLen) (payload := innerPayload) (tail := tail) - (mem := mem) (aw := aw) (k := k0) (C := C0) - (by simp [tail]) (by simpa [head, innerLen] using hlenNe) - (by simpa [head, innerLen, innerPayload, tail] using rd445) - exact ⟨k1, C1, by - simpa [head, innerLen, innerPayload, tail] using rd475⟩ - -theorem attesterX_multiRevokeInnerCopyToOuterLoopAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {innerIdx base innerLen payload idx outerBase schemaLen secondLen secondPayload - schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hidxSchema : UInt256.lt idx schemaLen = ⟨1⟩) - (hmem : outerBase.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding outerBase.toNat 32 = - UInt256.toByteArray schemaLen) - (hawMul : aw.toNat * 32 < UInt256.size) - (houter64 : 64 + 32 ≤ outerBase.toNat) - (hbase : outerBase.toNat + 32 ≤ base.toNat) - (hfree : - base.toNat + 32 ≤ (attesterMultiRevokePostCopyFreeWord mem aw).toNat) - (hfree96 : - (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 96 < UInt256.size) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨608⟩ : UInt256) - [innerIdx, base, innerLen, innerLen, payload, idx, outerBase, schemaLen, - secondLen, secondPayload, schemaLen, schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [attesterMultiRevokePostCopyNextIdx idx, outerBase, schemaLen, - secondLen, secondPayload, schemaLen, schemaPayload, ret, selector] - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx mem aw) - ByteArray.empty (cA, σ) k' C' := by - have hmloadOuter : - attesterMloadWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataAw base I schemaPayload idx mem aw) - outerBase = schemaLen := by - exact attesterMultiRevokePostCopyDataMem_mloadOuter - (base := base) (outerBase := outerBase) (len := schemaLen) - (schemaPayload := schemaPayload) (idx := idx) (mem := mem) (aw := aw) - hmem hread hawMul houter64 hbase hfree hfree96 - have hidxOuter : - UInt256.lt idx - (attesterMloadWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataAw base I schemaPayload idx mem aw) - outerBase) = ⟨1⟩ := by - rw [hmloadOuter] - exact hidxSchema - exact attesterX_multiRevokePostInnerCopyToOuterLoop - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (innerIdx := innerIdx) (base := base) (innerLen := innerLen) - (payload := payload) (idx := idx) (outerBase := outerBase) - (schemaLen := schemaLen) (secondLen := secondLen) - (secondPayload := secondPayload) (schemaPayload := schemaPayload) - (ret := ret) (selector := selector) (mem := mem) (aw := aw) - (k := k) (C := C) hidxSchema hidxOuter hreach - -structure attesterMultiRevokeInnerCopyReadInvAt - (I : ExecutionEnv) (base len payload outerBase schemaLen : UInt256) - (n : Nat) (s : AttesterMultiRevokeInnerArrayCopyState) : Prop where - idx : s.idx = UInt256.ofNat (len.toNat - n) - le : n ≤ len.toNat - awGe : 3 ≤ s.aw.toNat - awMul : s.aw.toNat * 32 < UInt256.size - read : s.mem.readWithPadding base.toNat 32 = UInt256.toByteArray len - memSize : base.toNat + 32 ≤ s.mem.size - baseGe : 64 + 32 ≤ base.toNat - base63 : base.toNat + 63 < UInt256.size - freeGe : base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat - freeExact : - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat = - base.toNat + 32 + 96 * len.toNat + 64 * (len.toNat - n) - freeSpare : - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + - 64 * n + 96 < UInt256.size - zeroGe : base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord s.mem s.aw).toNat - slotGe : base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopySlotWord base s.idx).toNat - slot63 : (attesterMultiRevokeInnerArrayCopySlotWord base s.idx).toNat + 63 < UInt256.size - baseSlot63 : base.toNat + 32 + 32 * len.toNat + 63 < UInt256.size - outerRead : s.mem.readWithPadding outerBase.toNat 32 = UInt256.toByteArray schemaLen - outerMemSize : outerBase.toNat + 32 ≤ s.mem.size - outer64 : 64 + 32 ≤ outerBase.toNat - outerBeforeBase : outerBase.toNat + 32 ≤ base.toNat - layout : AttesterMultiRevokeInnerCopyReadLayout I base len payload (len.toNat - n) s.mem - -theorem attesterMultiRevokeInnerCopyReadInvAt_idx - {I : ExecutionEnv} {base len payload outerBase schemaLen : UInt256} - {n : Nat} {s : AttesterMultiRevokeInnerArrayCopyState} - (hInv : attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen n s) : - s.idx = UInt256.ofNat (len.toNat - n) := by - exact hInv.idx - -theorem attesterMultiRevokeInnerCopyReadInvAt_le - {I : ExecutionEnv} {base len payload outerBase schemaLen : UInt256} - {n : Nat} {s : AttesterMultiRevokeInnerArrayCopyState} - (hInv : attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen n s) : - n ≤ len.toNat := by - exact hInv.le - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevokeInnerCopyReadInvAt_init - {I : ExecutionEnv} {base len payload outerBase schemaLen : UInt256} - {b : AttesterMultiRevokeInnerArrayInitState} - (hInv : attesterMultiRevokeInnerInitReadInvAt I base len outerBase schemaLen 0 b) : - attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen len.toNat - (attesterMultiRevokeInnerCopyInitState b) := by - have hInvOrig := hInv - have hfree63 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 63 < - UInt256.size := by - have hfb := hInv.freeBound - omega - have hfree32 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 32 < - UInt256.size := by - omega - have hsecondToNat : - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat = - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 32 := - attesterMultiRevokeInnerArrayInitSecondZeroWord_toNat - (mem := b.mem) (aw := b.aw) hfree32 - have hsecondGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - rw [hsecondToNat] - exact le_trans hInv.freeGe (Nat.le_add_right _ _) - have hsecond63 : - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat + 63 < - UInt256.size := by - rw [hsecondToNat] - have hspare := hInv.freeSpare - omega - have hslot63 : b.slot.toNat + 63 < UInt256.size := by - have hslotBound := hInv.slotBound - omega - have hawStep := - attesterMultiRevokeInnerArrayInitStepAw_bounds - (slot := b.slot) (mem := b.mem) (aw := b.aw) - hInv.awGe hInv.awMul hfree63 hsecond63 hslot63 - have hreadStep : - (attesterMultiRevokeInnerArrayInitFinalMem b).readWithPadding base.toNat 32 = - UInt256.toByteArray len := by - change - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len - exact attesterMultiRevokeInnerArrayInitStep_readWithPadding_nat - (base := base) (slot := b.slot) (len := len) (mem := b.mem) (aw := b.aw) - hInv.memSize hInv.read hInv.baseGe hInv.freeGe hsecondGe hInv.slotGe - have hmemStep : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayInitFinalMem b).size := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).size - exact attesterMultiRevokeInnerArrayInitStep_base_size - (base := base) (slot := b.slot) (len := len) (mem := b.mem) (aw := b.aw) - hInv.memSize - have houterFree : - outerBase.toNat + 32 ≤ (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat := by - exact le_trans hInv.outerBeforeBase - (le_trans (Nat.le_add_right base.toNat 32) hInv.freeGe) - have houterSecond : - outerBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - rw [hsecondToNat] - exact le_trans houterFree (Nat.le_add_right _ _) - have houterSlot : outerBase.toNat + 32 ≤ b.slot.toNat := by - exact le_trans hInv.outerBeforeBase - (le_trans (Nat.le_add_right base.toNat 32) hInv.slotGe) - have hreadOuterStep : - (attesterMultiRevokeInnerArrayInitFinalMem b).readWithPadding outerBase.toNat 32 = - UInt256.toByteArray schemaLen := by - change - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray schemaLen - exact attesterMultiRevokeInnerArrayInitStep_readWithPadding_nat - (base := outerBase) (slot := b.slot) (len := schemaLen) - (mem := b.mem) (aw := b.aw) - hInv.outerMemSize hInv.outerRead hInv.outer64 houterFree houterSecond houterSlot - have houterMemStep : - outerBase.toNat + 32 ≤ (attesterMultiRevokeInnerArrayInitFinalMem b).size := by - change outerBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).size - exact le_trans hInv.outerMemSize attesterMultiRevokeInnerArrayInitStep_size_ge - have hfree96 : - 64 + 32 ≤ (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat := by - have hbase96 : 64 + 32 ≤ base.toNat + 32 := - le_trans hInv.baseGe (Nat.le_add_right base.toNat 32) - exact le_trans hbase96 hInv.freeGe - have hsecond96 : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - have hbase96 : 64 + 32 ≤ base.toNat + 32 := - le_trans hInv.baseGe (Nat.le_add_right base.toNat 32) - exact le_trans hbase96 hsecondGe - have hslot96 : 64 + 32 ≤ b.slot.toNat := by - have hbase96 : 64 + 32 ≤ base.toNat + 32 := - le_trans hInv.baseGe (Nat.le_add_right base.toNat 32) - exact le_trans hbase96 hInv.slotGe - have hfree64 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 64 < - UInt256.size := by - have hfb := hInv.freeBound - omega - have hfreeStepToNat : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat = - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 64 := by - change - (attesterMultiOuterArrayInitFreeWord - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw) - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw)).toNat = - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 64 - exact attesterMultiRevokeInnerArrayInitStep_freeWord_toNat - (slot := b.slot) (mem := b.mem) (aw := b.aw) - hfree96 hsecond96 hslot96 hawStep.2 hawStep.1 hfree64 - have hfreeFinalGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat := by - rw [hfreeStepToNat] - exact le_trans hInv.freeGe (Nat.le_add_right _ _) - have hfreeFinalSpare : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat + - 64 * len.toNat + 96 < UInt256.size := by - rw [hfreeStepToNat] - have hspare := hInv.freeSpare - omega - have hfreeFinal32 : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat + 32 < - UInt256.size := by - omega - have hzeroToNat : - (attesterMultiRevokeInnerArrayCopyZeroWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat + 32 := - attesterMultiRevokeInnerArrayCopyZeroWord_toNat hfreeFinal32 - have hzeroGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat := by - rw [hzeroToNat] - exact le_trans hfreeFinalGe (Nat.le_add_right _ _) - have hbase63 : base.toNat + 63 < UInt256.size := by - have hbaseSlot := hInv.baseSlot63 - omega - have hslot0Bound : - base.toNat + 32 + 32 * (⟨0⟩ : UInt256).toNat + 63 < UInt256.size := by - change base.toNat + 32 + 32 * 0 + 63 < UInt256.size - have hbaseSlot := hInv.baseSlot63 - omega - have hslot0ToNat : - (attesterMultiRevokeInnerArrayCopySlotWord base (⟨0⟩ : UInt256)).toNat = - base.toNat + 32 + 32 * (⟨0⟩ : UInt256).toNat := - attesterMultiRevokeInnerArrayCopySlotWord_toNat (by omega) - have hslot0Ge : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base (⟨0⟩ : UInt256)).toNat := - attesterMultiRevokeInnerArrayCopySlotWord_above_base (by omega) - have hslot0_63 : - (attesterMultiRevokeInnerArrayCopySlotWord base (⟨0⟩ : UInt256)).toNat + 63 < - UInt256.size := by - rw [hslot0ToNat] - simpa using hslot0Bound - have hidx0 : - (⟨0⟩ : UInt256) = UInt256.ofNat (len.toNat - len.toNat) := by - rw [show len.toNat - len.toNat = 0 by omega] - apply u256_inj - rfl - exact - { idx := by simpa using hidx0 - le := le_rfl - awGe := by - change 3 ≤ (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw).toNat - exact hawStep.1 - awMul := by - change - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw).toNat * 32 < - UInt256.size - exact hawStep.2 - read := by - change - (attesterMultiRevokeInnerArrayInitFinalMem b).readWithPadding base.toNat 32 = - UInt256.toByteArray len - exact hreadStep - memSize := by - change base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayInitFinalMem b).size - exact hmemStep - baseGe := hInv.baseGe - base63 := hbase63 - freeGe := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat - exact hfreeFinalGe - freeExact := by - change - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat = - base.toNat + 32 + 96 * len.toNat + 64 * (len.toNat - len.toNat) - rw [hfreeStepToNat, hInv.freeExact] - have hsub : len.toNat - (0 + 1) + 1 = len.toNat := by - have hle := hInv.le - omega - have hzero : len.toNat - len.toNat = 0 := by omega - rw [hzero] - nlinarith - freeSpare := by - change - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat + - 64 * len.toNat + 96 < - UInt256.size - exact hfreeFinalSpare - zeroGe := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat - exact hzeroGe - slotGe := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base (⟨0⟩ : UInt256)).toNat - exact hslot0Ge - slot63 := by - change - (attesterMultiRevokeInnerArrayCopySlotWord base (⟨0⟩ : UInt256)).toNat + 63 < - UInt256.size - exact hslot0_63 - baseSlot63 := hInv.baseSlot63 - outerRead := by - change (attesterMultiRevokeInnerArrayInitFinalMem b).readWithPadding outerBase.toNat 32 = - UInt256.toByteArray schemaLen - exact hreadOuterStep - outerMemSize := by - change outerBase.toNat + 32 ≤ (attesterMultiRevokeInnerArrayInitFinalMem b).size - exact houterMemStep - outer64 := hInv.outer64 - outerBeforeBase := hInv.outerBeforeBase - layout := by - intro j hj - omega } - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevokeInnerCopyReadInvAt_step - {I : ExecutionEnv} {base len payload outerBase schemaLen : UInt256} - {n : Nat} {s : AttesterMultiRevokeInnerArrayCopyState} - (hInv : attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen - (n + 1) s) : - attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen n - (attesterMultiRevokeInnerArrayCopyStepState I base payload s) := by - have hbaseGe' : 64 + 32 ≤ base.toNat := hInv.baseGe - have hbase63' : base.toNat + 63 < UInt256.size := hInv.base63 - have hfreeGe' : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat := hInv.freeGe - have hzeroGe' : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord s.mem s.aw).toNat := hInv.zeroGe - have hslotGe' : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base s.idx).toNat := hInv.slotGe - have hslot63' : - (attesterMultiRevokeInnerArrayCopySlotWord base s.idx).toNat + 63 < - UInt256.size := hInv.slot63 - have hnextIdx : - attesterMultiRevokeInnerArrayCopyNextIdx s.idx = - UInt256.ofNat (len.toNat - n) := by - rw [hInv.idx] - exact attesterMultiRevokeInnerArrayCopyNextIdx_ofNat_progress - (len := len.toNat) (n := n) hInv.le len.val.isLt - have hnextIdxToNat : - (attesterMultiRevokeInnerArrayCopyNextIdx s.idx).toNat = len.toNat - n := by - rw [hnextIdx] - exact ulit_toNat' (len.toNat - n) - (lt_of_le_of_lt (Nat.sub_le _ _) len.val.isLt) - have hfree63 : - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 63 < - UInt256.size := by - have hspare := hInv.freeSpare - omega - have hfree32 : - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 32 < - UInt256.size := by - have hspare := hInv.freeSpare - omega - have hzeroToNat : - (attesterMultiRevokeInnerArrayCopyZeroWord s.mem s.aw).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 32 := - attesterMultiRevokeInnerArrayCopyZeroWord_toNat hfree32 - have hzero63 : - (attesterMultiRevokeInnerArrayCopyZeroWord s.mem s.aw).toNat + 63 < - UInt256.size := by - rw [hzeroToNat] - have hspare := hInv.freeSpare - omega - have hawStep := - attesterMultiRevokeInnerArrayCopyStepAw_bounds - (I := I) (base := base) (payload := payload) (idx := s.idx) - (mem := s.mem) (aw := s.aw) - hInv.awGe hInv.awMul hbase63' hfree63 hzero63 hslot63' - have hreadStep : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := - attesterMultiRevokeInnerArrayCopyStep_readWithPadding_nat - (I := I) (base := base) (payload := payload) (idx := s.idx) - (len := len) (mem := s.mem) (aw := s.aw) - hInv.memSize hInv.read hbaseGe' hfreeGe' hzeroGe' hslotGe' - have hmemStep : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).size := - attesterMultiRevokeInnerArrayCopyStep_base_size - (I := I) (base := base) (payload := payload) (idx := s.idx) - (mem := s.mem) (aw := s.aw) hInv.memSize - have houterFree : - outerBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat := by - exact le_trans hInv.outerBeforeBase (by omega) - have houterZero : - outerBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord s.mem s.aw).toNat := by - exact le_trans hInv.outerBeforeBase (by omega) - have houterSlot : - outerBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base s.idx).toNat := by - exact le_trans hInv.outerBeforeBase (by omega) - have hreadOuterStep : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray schemaLen := by - exact attesterMultiRevokeInnerArrayCopyStep_readWithPadding_at_nat - (I := I) (readBase := outerBase) (base := base) (payload := payload) - (idx := s.idx) (len := schemaLen) (mem := s.mem) (aw := s.aw) - hInv.outerMemSize hInv.outerRead hInv.outer64 houterFree houterZero houterSlot - have houterMemStep : - outerBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).size := - le_trans hInv.outerMemSize attesterMultiRevokeInnerArrayCopyStep_size_ge - have hfree96 : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat := by - have hbase96 : 64 + 32 ≤ base.toNat + 32 := by omega - exact le_trans hbase96 hfreeGe' - have hzero96 : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord s.mem s.aw).toNat := by - have hbase96 : 64 + 32 ≤ base.toNat + 32 := by omega - exact le_trans hbase96 hzeroGe' - have hslot96 : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopySlotWord base s.idx).toNat := by - have hbase96 : 64 + 32 ≤ base.toNat + 32 := by omega - exact le_trans hbase96 hslotGe' - have hfree64 : - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 64 < - UInt256.size := by - omega - have hfreeStepToNat : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 64 := - attesterMultiRevokeInnerArrayCopyStep_freeWord_toNat - (I := I) (base := base) (payload := payload) (idx := s.idx) - (mem := s.mem) (aw := s.aw) - hfree96 hzero96 hslot96 hawStep.2 hawStep.1 hfree64 - have hfreeStepGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat := by - rw [hfreeStepToNat] - exact le_trans hfreeGe' (Nat.le_add_right _ _) - have hfreeStepSpare : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat + - 64 * n + 96 < UInt256.size := by - rw [hfreeStepToNat] - have hspare := hInv.freeSpare - omega - have hfreeStep32 : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat + - 32 < UInt256.size := by - omega - have hzeroStepToNat : - (attesterMultiRevokeInnerArrayCopyZeroWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat + - 32 := - attesterMultiRevokeInnerArrayCopyZeroWord_toNat hfreeStep32 - have hzeroStepGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat := by - rw [hzeroStepToNat] - exact le_trans hfreeStepGe (Nat.le_add_right _ _) - have hslotNextBound : - base.toNat + 32 + - 32 * (attesterMultiRevokeInnerArrayCopyNextIdx s.idx).toNat + 63 < - UInt256.size := by - rw [hnextIdxToNat] - have hleLen : 32 * (len.toNat - n) ≤ 32 * len.toNat := - Nat.mul_le_mul_left 32 (Nat.sub_le _ _) - exact lt_of_le_of_lt (by omega) hInv.baseSlot63 - have hslotNextToNat : - (attesterMultiRevokeInnerArrayCopySlotWord base - (attesterMultiRevokeInnerArrayCopyNextIdx s.idx)).toNat = - base.toNat + 32 + - 32 * (attesterMultiRevokeInnerArrayCopyNextIdx s.idx).toNat := - attesterMultiRevokeInnerArrayCopySlotWord_toNat (by omega) - have hslotNextGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base - (attesterMultiRevokeInnerArrayCopyNextIdx s.idx)).toNat := - attesterMultiRevokeInnerArrayCopySlotWord_above_base (by omega) - have hslotNext63 : - (attesterMultiRevokeInnerArrayCopySlotWord base - (attesterMultiRevokeInnerArrayCopyNextIdx s.idx)).toNat + 63 < - UInt256.size := by - rw [hslotNextToNat] - exact hslotNextBound - exact - { idx := by - change attesterMultiRevokeInnerArrayCopyNextIdx s.idx = - UInt256.ofNat (len.toNat - n) - exact hnextIdx - le := by - have hle := hInv.le - omega - awGe := by - change 3 ≤ (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw).toNat - exact hawStep.1 - awMul := by - change - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw).toNat * - 32 < - UInt256.size - exact hawStep.2 - read := by - change - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len - exact hreadStep - memSize := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).size - exact hmemStep - baseGe := hInv.baseGe - base63 := hInv.base63 - freeGe := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat - exact hfreeStepGe - freeExact := by - change - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat = - base.toNat + 32 + 96 * len.toNat + 64 * (len.toNat - n) - rw [hfreeStepToNat, hInv.freeExact] - have hsub : - len.toNat - n = len.toNat - (n + 1) + 1 := by - have hle := hInv.le - omega - rw [hsub] - nlinarith - freeSpare := by - change - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat + - 64 * n + 96 < - UInt256.size - exact hfreeStepSpare - zeroGe := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat - exact hzeroStepGe - slotGe := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base - (attesterMultiRevokeInnerArrayCopyNextIdx s.idx)).toNat - exact hslotNextGe - slot63 := by - change - (attesterMultiRevokeInnerArrayCopySlotWord base - (attesterMultiRevokeInnerArrayCopyNextIdx s.idx)).toNat + 63 < - UInt256.size - exact hslotNext63 - baseSlot63 := hInv.baseSlot63 - outerRead := by - change - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray schemaLen - exact hreadOuterStep - outerMemSize := by - change outerBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).size - exact houterMemStep - outer64 := hInv.outer64 - outerBeforeBase := hInv.outerBeforeBase - layout := by - change AttesterMultiRevokeInnerCopyReadLayout I base len payload - (len.toNat - n) - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - exact AttesterMultiRevokeInnerCopyReadLayout_step - (I := I) (base := base) (len := len) (payload := payload) - (idx := s.idx) (mem := s.mem) (aw := s.aw) (n := n) - hInv.idx hInv.le hInv.baseGe hInv.baseSlot63 hInv.freeExact - hInv.freeSpare hInv.layout } - -theorem AttesterReadPreservedBefore_innerCopyStep - {I : ExecutionEnv} {mem₀ : ByteArray} - {base len payload outerBase schemaLen : UInt256} - {n : Nat} {s : AttesterMultiRevokeInnerArrayCopyState} - (hInv : attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen - (n + 1) s) - (hpres : AttesterReadPreservedBefore mem₀ s.mem base.toNat) : - AttesterReadPreservedBefore mem₀ - (attesterMultiRevokeInnerArrayCopyStepState I base payload s).mem base.toNat := by - intro read word hmem0 hread0 hread64 hbefore - rcases hpres hmem0 hread0 hread64 hbefore with ⟨hmem, hread⟩ - have hreadLt : read < UInt256.size := by - have hbaseLt : base.toNat < UInt256.size := base.val.isLt - omega - let readWord : UInt256 := UInt256.ofNat read - have hreadWordToNat : readWord.toNat = read := ulit_toNat' read hreadLt - have hfree : - read + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat := by - exact le_trans hbefore (le_trans (Nat.le_add_right base.toNat 32) hInv.freeGe) - have hzero : - read + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord s.mem s.aw).toNat := by - exact le_trans hbefore (le_trans (Nat.le_add_right base.toNat 32) hInv.zeroGe) - have hslot : - read + 32 ≤ (attesterMultiRevokeInnerArrayCopySlotWord base s.idx).toNat := by - exact le_trans hbefore (le_trans (Nat.le_add_right base.toNat 32) hInv.slotGe) - constructor - · change read + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).size - exact le_trans hmem attesterMultiRevokeInnerArrayCopyStep_size_ge - · change - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).readWithPadding - read 32 = - UInt256.toByteArray word - have hstep := - attesterMultiRevokeInnerArrayCopyStep_readWithPadding_at_nat - (I := I) (readBase := readWord) (base := base) (payload := payload) - (idx := s.idx) (len := word) (mem := s.mem) (aw := s.aw) - (by simpa [readWord, hreadWordToNat] using hmem) - (by simpa [readWord, hreadWordToNat] using hread) - (by simpa [readWord, hreadWordToNat] using hread64) - (by simpa [readWord, hreadWordToNat] using hfree) - (by simpa [readWord, hreadWordToNat] using hzero) - (by simpa [readWord, hreadWordToNat] using hslot) - simpa [readWord, hreadWordToNat] using hstep - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeInnerArrayCopyLoopWithReadInvariantAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base len payload outerBase schemaLen : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hinit : - attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen len.toNat - { idx := (⟨0⟩ : UInt256), mem := mem, aw := aw }) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - ((⟨0⟩ : UInt256) :: base :: len :: len :: payload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ s' k' C', - s'.idx = len ∧ - attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen 0 s' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨608⟩ : UInt256) - (attesterMultiRevokeInnerArrayCopyStack base len payload tail s') - s'.mem s'.aw ByteArray.empty (cA, σ) k' C' := by - let Inv := attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen - have hload : - ∀ n s, Inv n s → - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload s.idx s.mem s.aw) - base = len := by - intro n s hInv - have hfree96 : - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 96 < - UInt256.size := by - have hspare := hInv.freeSpare - omega - exact attesterMultiRevokeInnerArrayCopyZero_mloadLen_of_bounds_nat - (I := I) (base := base) (payload := payload) (idx := s.idx) - (len := len) (mem := s.mem) (aw := s.aw) - hInv.memSize hInv.read hInv.awGe hInv.awMul hfree96 hInv.baseGe hInv.freeGe hInv.zeroGe - exact attesterX_multiRevokeInnerArrayCopyLoopWithStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := base) (len := len) (payload := payload) (tail := tail) - (mem := mem) (aw := aw) (k := k) (C := C) htail - (Inv := Inv) - (fun n s hInv => attesterMultiRevokeInnerCopyReadInvAt_idx hInv) - (fun n s hInv => attesterMultiRevokeInnerCopyReadInvAt_le hInv) - hload - (fun n s hInv => attesterMultiRevokeInnerCopyReadInvAt_step hInv) - (by simpa [Inv] using hinit) - hreach - -theorem attesterX_multiRevokeInnerCopyLoopToOuterLoopAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base len payload idx outerBase schemaLen secondLen secondPayload schemaPayload - ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hidxSchema : UInt256.lt idx schemaLen = ⟨1⟩) - (hinit : - attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen len.toNat - { idx := (⟨0⟩ : UInt256), mem := mem, aw := aw }) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - ((⟨0⟩ : UInt256) :: base :: len :: len :: payload :: - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector]) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ s' k' C', - s'.idx = len ∧ - attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen 0 s' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [attesterMultiRevokePostCopyNextIdx idx, outerBase, schemaLen, - secondLen, secondPayload, schemaLen, schemaPayload, ret, selector] - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx s'.mem s'.aw) - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx s'.mem s'.aw) - ByteArray.empty (cA, σ) k' C' := by - obtain ⟨s', k0, C0, hsidx, hInv, rd608⟩ := - attesterX_multiRevokeInnerArrayCopyLoopWithReadInvariantAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := base) (len := len) (payload := payload) - (outerBase := outerBase) (schemaLen := schemaLen) - (tail := [idx, outerBase, schemaLen, secondLen, secondPayload, - schemaLen, schemaPayload, ret, selector]) - (mem := mem) (aw := aw) (k := k) (C := C) (by simp) hinit hreach - obtain ⟨k1, C1, rd335⟩ := - attesterX_multiRevokeInnerCopyToOuterLoopAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (innerIdx := s'.idx) (base := base) (innerLen := len) - (payload := payload) (idx := idx) (outerBase := outerBase) - (schemaLen := schemaLen) (secondLen := secondLen) - (secondPayload := secondPayload) (schemaPayload := schemaPayload) - (ret := ret) (selector := selector) (mem := s'.mem) (aw := s'.aw) - (k := k0) (C := C0) hidxSchema - hInv.outerMemSize hInv.outerRead hInv.awMul hInv.outer64 - hInv.outerBeforeBase hInv.freeGe hInv.freeSpare - (by simpa [hsidx, attesterMultiRevokeInnerArrayCopyStack] using rd608) - exact ⟨s', k1, C1, hsidx, hInv, rd335⟩ - -theorem attesterX_multiRevokeInnerCopyLoopToOuterLoopPreservedAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base len payload idx outerBase schemaLen secondLen secondPayload schemaPayload - ret selector : UInt256} - {mem₀ mem : ByteArray} {aw : UInt256} {k C} - (hidxSchema : UInt256.lt idx schemaLen = ⟨1⟩) - (hinit : - attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen len.toNat - { idx := (⟨0⟩ : UInt256), mem := mem, aw := aw }) - (hpresInit : - AttesterReadPreservedBefore mem₀ mem base.toNat) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - ((⟨0⟩ : UInt256) :: base :: len :: len :: payload :: - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector]) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ s' k' C', - s'.idx = len ∧ - attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen 0 s' ∧ - AttesterReadPreservedBefore mem₀ s'.mem base.toNat ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [attesterMultiRevokePostCopyNextIdx idx, outerBase, schemaLen, - secondLen, secondPayload, schemaLen, schemaPayload, ret, selector] - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx s'.mem s'.aw) - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx s'.mem s'.aw) - ByteArray.empty (cA, σ) k' C' := by - let Inv : Nat → AttesterMultiRevokeInnerArrayCopyState → Prop := - fun n s => - attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen n s ∧ - AttesterReadPreservedBefore mem₀ s.mem base.toNat - have hload : - ∀ n s, Inv n s → - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload s.idx s.mem s.aw) - base = len := by - intro n s hInv - have hfree96 : - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 96 < - UInt256.size := by - have hspare := hInv.1.freeSpare - omega - exact attesterMultiRevokeInnerArrayCopyZero_mloadLen_of_bounds_nat - (I := I) (base := base) (payload := payload) (idx := s.idx) - (len := len) (mem := s.mem) (aw := s.aw) - hInv.1.memSize hInv.1.read hInv.1.awGe hInv.1.awMul hfree96 - hInv.1.baseGe hInv.1.freeGe hInv.1.zeroGe - obtain ⟨s', k0, C0, hsidx, hInv, rd608⟩ := - attesterX_multiRevokeInnerArrayCopyLoopWithStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := base) (len := len) (payload := payload) - (tail := [idx, outerBase, schemaLen, secondLen, secondPayload, - schemaLen, schemaPayload, ret, selector]) - (mem := mem) (aw := aw) (k := k) (C := C) (by simp) - (Inv := Inv) - (fun n s hInv => attesterMultiRevokeInnerCopyReadInvAt_idx hInv.1) - (fun n s hInv => attesterMultiRevokeInnerCopyReadInvAt_le hInv.1) - hload - (fun n s hInv => - ⟨attesterMultiRevokeInnerCopyReadInvAt_step hInv.1, - AttesterReadPreservedBefore_innerCopyStep hInv.1 hInv.2⟩) - (by exact ⟨hinit, hpresInit⟩) - hreach - obtain ⟨k1, C1, rd335⟩ := - attesterX_multiRevokeInnerCopyToOuterLoopAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (innerIdx := s'.idx) (base := base) (innerLen := len) - (payload := payload) (idx := idx) (outerBase := outerBase) - (schemaLen := schemaLen) (secondLen := secondLen) - (secondPayload := secondPayload) (schemaPayload := schemaPayload) - (ret := ret) (selector := selector) (mem := s'.mem) (aw := s'.aw) - (k := k0) (C := C0) hidxSchema - hInv.1.outerMemSize hInv.1.outerRead hInv.1.awMul hInv.1.outer64 - hInv.1.outerBeforeBase hInv.1.freeGe hInv.1.freeSpare - (by simpa [hsidx, attesterMultiRevokeInnerArrayCopyStack] using rd608) - exact ⟨s', k1, C1, hsidx, hInv.1, hInv.2, rd335⟩ - -theorem attesterMultiRevokePostCopyOuterMem_readOuter_from_copyInvAt - {I : ExecutionEnv} {base len payload outerBase schemaLen schemaPayload idx : UInt256} - {s : AttesterMultiRevokeInnerArrayCopyState} - (hInv : attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen 0 s) - (hslotBound : outerBase.toNat + 32 + 32 * idx.toNat < UInt256.size) : - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx s.mem s.aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray schemaLen ∧ - outerBase.toNat + 32 ≤ - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx s.mem s.aw).size := by - exact attesterMultiRevokePostCopyOuterMem_readOuter_and_size - (base := base) (outerBase := outerBase) (len := schemaLen) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - hInv.outerMemSize hInv.outerRead hInv.outer64 hInv.outerBeforeBase - (by - simpa [attesterMultiRevokePostCopyFreeWord, - attesterMultiRevokeInnerArrayCopyFreeWord] using hInv.freeGe) - (by - simpa [attesterMultiRevokePostCopyFreeWord, - attesterMultiRevokeInnerArrayCopyFreeWord] using hInv.freeSpare) - hslotBound - -theorem attesterMultiRevokePostCopyOuter_cursorFacts_from_copyInvAt - {I : ExecutionEnv} {base len payload outerBase schemaLen schemaPayload idx : UInt256} - {s : AttesterMultiRevokeInnerArrayCopyState} - (hInv : attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen 0 s) - (hslotBound : outerBase.toNat + 32 + 32 * idx.toNat + 63 < UInt256.size) : - ((attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx s.mem s.aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray schemaLen ∧ - outerBase.toNat + 32 ≤ - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx s.mem s.aw).size) ∧ - 3 ≤ (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx s.mem s.aw).toNat ∧ - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx s.mem s.aw).toNat * - 32 < UInt256.size ∧ - (attesterInnerArrayAllocFreeWord - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx s.mem s.aw) - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx s.mem s.aw)).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 64 ∧ - 64 + 32 ≤ - (attesterInnerArrayAllocFreeWord - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx s.mem s.aw) - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx s.mem s.aw)).toNat ∧ - outerBase.toNat + 32 ≤ - (attesterInnerArrayAllocFreeWord - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx s.mem s.aw) - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx s.mem s.aw)).toNat := by - have hfree96 : - 64 + 32 ≤ (attesterMultiRevokePostCopyFreeWord s.mem s.aw).toNat := by - change 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat - have hbaseGe := hInv.baseGe - have hbase96 : 64 + 32 ≤ base.toNat + 32 := by omega - exact le_trans hbase96 hInv.freeGe - have hfreeSpare96 : - (attesterMultiRevokePostCopyFreeWord s.mem s.aw).toNat + 96 < - UInt256.size := by - simpa [attesterMultiRevokePostCopyFreeWord, - attesterMultiRevokeInnerArrayCopyFreeWord] using hInv.freeSpare - have hfree32 : - (attesterMultiRevokePostCopyFreeWord s.mem s.aw).toNat + 32 < - UInt256.size := by - omega - have hfree64 : - (attesterMultiRevokePostCopyFreeWord s.mem s.aw).toNat + 64 < - UInt256.size := by - omega - have hfree95 : - (attesterMultiRevokePostCopyFreeWord s.mem s.aw).toNat + 95 < - UInt256.size := by - omega - have hdataToNat : - (attesterMultiRevokePostCopyDataOffsetWord s.mem s.aw).toNat = - (attesterMultiRevokePostCopyFreeWord s.mem s.aw).toNat + 32 := by - unfold attesterMultiRevokePostCopyDataOffsetWord - exact uadd_lit32_toNat (attesterMultiRevokePostCopyFreeWord s.mem s.aw) hfree32 - have hdata96 : - 64 + 32 ≤ (attesterMultiRevokePostCopyDataOffsetWord s.mem s.aw).toNat := by - rw [hdataToNat] - omega - have hslotToNat : - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat = - outerBase.toNat + 32 + 32 * idx.toNat := by - exact attesterMultiRevokePostCopyOuterSlotWord_toNat (by omega) - have hslot96 : - 64 + 32 ≤ (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat := by - rw [hslotToNat] - have houter64 := hInv.outer64 - omega - have hslot63 : - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat + 63 < - UInt256.size := by - rw [hslotToNat] - omega - have houter63 : outerBase.toNat + 63 < UInt256.size := by - have hbase63 := hInv.base63 - have houterBeforeBase := hInv.outerBeforeBase - omega - have hawBounds := - attesterMultiRevokePostCopyOuterAw_bounds - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - hInv.awGe hInv.awMul hfree95 houter63 hslot63 - have hfreeToNat : - (attesterInnerArrayAllocFreeWord - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx s.mem s.aw) - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx s.mem s.aw)).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 64 := by - have h := - attesterMultiRevokePostCopyOuterMem_freeWord_toNat - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - hfree96 hdata96 hslot96 hawBounds.2 hawBounds.1 hfree64 - simpa [attesterMultiRevokePostCopyFreeWord, - attesterMultiRevokeInnerArrayCopyFreeWord] using h - constructor - · exact attesterMultiRevokePostCopyOuterMem_readOuter_from_copyInvAt - (I := I) (base := base) (len := len) (payload := payload) - (outerBase := outerBase) (schemaLen := schemaLen) - (schemaPayload := schemaPayload) (idx := idx) (s := s) - hInv (by omega) - · constructor - · exact hawBounds.1 - · constructor - · exact hawBounds.2 - · constructor - · exact hfreeToNat - · constructor - · rw [hfreeToNat] - have hfreeGe := hfree96 - change 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat at hfreeGe - omega - · rw [hfreeToNat] - have houterBeforeBase := hInv.outerBeforeBase - have hbaseBeforeFree := hInv.freeGe - omega - -theorem attesterMultiRevokePostCopyOuter_freeWordExact_from_copyInvAt - {I : ExecutionEnv} {base len payload outerBase schemaLen schemaPayload idx : UInt256} - {s : AttesterMultiRevokeInnerArrayCopyState} - (hInv : attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen 0 s) - (hslotBound : outerBase.toNat + 32 + 32 * idx.toNat + 63 < UInt256.size) : - (attesterInnerArrayAllocFreeWord - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx s.mem s.aw) - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx s.mem s.aw)).toNat = - base.toNat + 96 + 160 * len.toNat := by - have hfacts := - attesterMultiRevokePostCopyOuter_cursorFacts_from_copyInvAt - (I := I) (base := base) (len := len) (payload := payload) - (outerBase := outerBase) (schemaLen := schemaLen) - (schemaPayload := schemaPayload) (idx := idx) (s := s) - hInv hslotBound - rcases hfacts with ⟨_houter, _hawGe, _hawMul, hfreeToNat, _hfreeGe, _houterBefore⟩ - rw [hfreeToNat, hInv.freeExact] - omega - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevokePostCopyOuter_currentRequestReadLayout_from_copyInvAt - {I : ExecutionEnv} {callargs : Store} - {schemas schemaUids uids : List Value} {i : Nat} {schema : Value} - {base len payload outerBase schemaLen schemaPayload idx : UInt256} - {contentLo bound : Nat} - {s : AttesterMultiRevokeInnerArrayCopyState} - (v : AttesterImmutables) - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hSchemas : callargs.get? "schemas" = some (.array schemas)) - (hlookupSchema : lookupNth? schemas i = some schema) - (hlookupOuter : lookupNth? schemaUids i = some (.array uids)) - (hoff0 : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hiMax : i ≤ solcMaxU64) - (hidx : idx = UInt256.ofNat i) - (hschemaPayload : - schemaPayload = (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩) - (hlenToNat : len.toNat = uids.length) - (huidWords : - ∀ {j uid}, lookupNth? uids j = some uid → - ∃ uidWord, - attesterBytes32ValueWord? uid = some uidWord ∧ - uidWord = - calldataWord I.calldata - (attesterMultiRevokeInnerArrayCopyCalldataOffset payload - (UInt256.ofNat j)).toNat) - (hInv : attesterMultiRevokeInnerCopyReadInvAt I base len payload outerBase schemaLen 0 s) - (hslotBeforeBase : - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat + 32 ≤ base.toNat) - (hcontentLoBase : contentLo ≤ base.toNat) - (hbound : - base.toNat + 96 + 160 * len.toNat ≤ bound) - (hslotBound : outerBase.toNat + 32 + 32 * idx.toNat + 63 < UInt256.size) : - AttesterMultiRevokeRequestReadLayoutAtBounded schemas schemaUids - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx s.mem s.aw) - outerBase contentLo bound i := by - intro schema' uids' hschema' huids' - rw [hlookupSchema] at hschema' - cases hschema' - rw [hlookupOuter] at huids' - cases huids' - let finalMem := attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx - s.mem s.aw - let free := attesterMultiRevokePostCopyFreeWord s.mem s.aw - let dataOff := attesterMultiRevokePostCopyDataOffsetWord s.mem s.aw - let slot := attesterMultiRevokePostCopyOuterSlotWord outerBase idx - have hslotToNat : - slot.toNat = outerBase.toNat + 32 + 32 * idx.toNat := by - dsimp [slot] - exact attesterMultiRevokePostCopyOuterSlotWord_toNat (by omega) - have hfree32 : free.toNat + 32 < UInt256.size := by - have hspare : free.toNat + 96 < UInt256.size := by - simpa [free, attesterMultiRevokePostCopyFreeWord, - attesterMultiRevokeInnerArrayCopyFreeWord] using hInv.freeSpare - omega - have hdataToNat : dataOff.toNat = free.toNat + 32 := by - unfold dataOff attesterMultiRevokePostCopyDataOffsetWord - exact uadd_lit32_toNat free hfree32 - have hslotBelowFree : slot.toNat + 32 ≤ free.toNat := by - exact le_trans (by simpa [slot] using hslotBeforeBase) - (by - change base.toNat ≤ (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat - have h := hInv.freeGe - omega) - obtain ⟨schemaWord, hschemaWord, hschemaWordEq⟩ := - attesterDecode_multiRevoke_schema_word_at_payload - (v := v) (I := I) (callargs := callargs) (schemas := schemas) - (idx := i) (schema := schema) hdec hSchemas hlookupSchema hoff0 hiMax - have hschemaReadWord : - attesterMultiRevokePostCopySchemaWord I schemaPayload idx = schemaWord := by - rw [hschemaWordEq, hschemaPayload, hidx] - have hreqDataToNat : ((⟨32⟩ : UInt256) + free).toNat = dataOff.toNat := by - rfl - have hlenSize : uids.length < UInt256.size := by - rw [← hlenToNat] - exact len.val.isLt - have hlenWord : UInt256.ofNat uids.length = len := by - apply u256_inj - rw [ulit_toNat' uids.length hlenSize, hlenToNat] - have hfreeToNat : - free.toNat = base.toNat + 32 + 160 * len.toNat := by - dsimp [free, attesterMultiRevokePostCopyFreeWord, - attesterMultiRevokeInnerArrayCopyFreeWord] - rw [hInv.freeExact] - omega - have hbaseReqBound : base.toNat + 32 ≤ bound := by - have hlenNonneg : 0 ≤ len.toNat := Nat.zero_le _ - nlinarith - refine ⟨schemaWord, free, base, hschemaWord, ?_, ?_, ?_, ?_, ?_, ?_, ?_, - ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · dsimp [slot] - have hslot64Idx : - 64 + 32 ≤ (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat := by - change 64 + 32 ≤ slot.toNat - rw [hslotToNat] - exact le_trans hInv.outer64 (by omega) - simpa [hidx] using hslot64Idx - · dsimp [slot] - have hslotBoundIdx : - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat + 32 ≤ - bound := by - exact le_trans (by simpa [slot] using hslotBeforeBase) - (le_trans (Nat.le_add_right base.toNat 32) hbaseReqBound) - simpa [hidx] using hslotBoundIdx - · dsimp [slot] - rw [← hidx] - exact attesterMultiRevokePostCopyOuterMem_current_slot_size - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - · dsimp [slot, finalMem] - rw [← hidx] - exact attesterMultiRevokePostCopyOuterMem_read_current_slot - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - · rw [hfreeToNat] - exact le_trans hcontentLoBase (by omega) - · rw [hfreeToNat] - omega - · dsimp [finalMem] - exact attesterMultiRevokePostCopyOuterMem_current_schema_size - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - · rw [hreqDataToNat, hdataToNat, hfreeToNat] - exact le_trans hcontentLoBase (by omega) - · rw [hreqDataToNat, hdataToNat, hfreeToNat] - omega - · rw [hreqDataToNat] - dsimp [finalMem, dataOff] - exact attesterMultiRevokePostCopyOuterMem_current_data_size - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - · dsimp [finalMem] - rw [← hschemaReadWord] - exact attesterMultiRevokePostCopyOuterMem_read_current_schema - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - hdataToNat (Or.inr (by simpa [slot] using hslotBelowFree)) - · rw [hreqDataToNat] - dsimp [finalMem, dataOff] - exact attesterMultiRevokePostCopyOuterMem_read_current_data_ptr - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - (Or.inr (by - rw [hdataToNat] - exact le_trans (by simpa [slot] using hslotBelowFree) (by omega))) - · exact hcontentLoBase - · exact hbaseReqBound - · dsimp [finalMem] - exact attesterMultiRevokePostCopyOuterMem_size_ge - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - hInv.memSize - · constructor - · dsimp [finalMem] - have hreadLen : - finalMem.readWithPadding base.toNat 32 = UInt256.toByteArray len := by - dsimp [finalMem] - exact attesterMultiRevokePostCopyOuterMem_read_preserved_before_free - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - hInv.memSize hInv.read hInv.baseGe hInv.freeGe hdataToNat - (Or.inr (by simpa [slot] using hslotBeforeBase)) - simpa [hlenWord] using hreadLen - · intro j uid hlookupUid - have hjLtUids : j < uids.length := lookupNth?_some_length hlookupUid - have hjLtLen : j < len.toNat := by - rw [hlenToNat] - exact hjLtUids - obtain ⟨uidWord, huidWord, huidWordEq⟩ := - huidWords hlookupUid - have hcopyElem := hInv.layout (j := j) hjLtLen - dsimp only [AttesterMultiRevokeInnerCopyReadLayout] at hcopyElem - let copySlot := attesterMultiRevokeInnerArrayCopySlotWord base (UInt256.ofNat j) - let elemPtr := attesterMultiRevokeInnerCopyTuplePtr base len j - rcases hcopyElem with - ⟨hcopySlotMem, hcopyPtrMem, hcopyPtr32Mem, - hcopySlotRead, hcopyPtrRead, hcopyPtr32Read⟩ - have hjSize : j < UInt256.size := lt_trans hjLtLen len.val.isLt - have hjWordToNat : (UInt256.ofNat j).toNat = j := - ulit_toNat' j hjSize - have hcopySlotBound : base.toNat + 32 + 32 * j + 63 < UInt256.size := by - have hmul : 32 * j ≤ 32 * len.toNat := - Nat.mul_le_mul_left 32 (le_of_lt hjLtLen) - have hbaseSlot63 := hInv.baseSlot63 - omega - have hcopySlotToNat : copySlot.toNat = base.toNat + 32 + 32 * j := by - unfold copySlot - rw [attesterMultiRevokeInnerArrayCopySlotWord_toNat] - · rw [hjWordToNat] - · rw [hjWordToNat] - omega - have hcopyPtrToNat : - elemPtr.toNat = base.toNat + 32 + 96 * len.toNat + 64 * j := by - unfold elemPtr - exact attesterMultiRevokeInnerCopyTuplePtr_toNat (by - unfold attesterMultiRevokeInnerCopyTuplePtrNat - have hmul : 64 * j ≤ 64 * len.toNat := - Nat.mul_le_mul_left 64 (le_of_lt hjLtLen) - have hfreeSpare := hInv.freeSpare - rw [hInv.freeExact] at hfreeSpare - omega) - have hcopyPtr32ToNat : - ((⟨32⟩ : UInt256) + elemPtr).toNat = - base.toNat + 32 + 96 * len.toNat + 64 * j + 32 := by - rw [attesterMultiRevokeInnerCopyTuplePtr_add32_toNat] - · unfold attesterMultiRevokeInnerCopyTuplePtrNat - rfl - · unfold attesterMultiRevokeInnerCopyTuplePtrNat - have hmul : 64 * j ≤ 64 * len.toNat := - Nat.mul_le_mul_left 64 (le_of_lt hjLtLen) - have hfreeSpare := hInv.freeSpare - rw [hInv.freeExact] at hfreeSpare - omega - let elemSlot := (⟨32⟩ : UInt256) + - UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat j) + base - have hmulJToNat : - (UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat j)).toNat = 32 * j := by - rw [u256_mul_toNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide, hjWordToNat] - exact Nat.mod_eq_of_lt (by omega) - have hprefixToNat : - ((⟨32⟩ : UInt256) + - UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat j)).toNat = - 32 + 32 * j := by - rw [uadd_toNat, hmulJToNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - exact Nat.mod_eq_of_lt (by omega) - have helemSlotToNat : elemSlot.toNat = base.toNat + 32 + 32 * j := by - unfold elemSlot - rw [uadd_toNat, hprefixToNat] - rw [show 32 + 32 * j + base.toNat = base.toNat + 32 + 32 * j by omega] - exact Nat.mod_eq_of_lt (by omega) - have helemSlotEqNat : elemSlot.toNat = copySlot.toNat := by - rw [helemSlotToNat, hcopySlotToNat] - have hcopySlotBeforeFree : copySlot.toNat + 32 ≤ free.toNat := by - rw [hcopySlotToNat] - change base.toNat + 32 + 32 * j + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat - rw [hInv.freeExact] - have hmul : 32 * j ≤ 96 * len.toNat := by - have hmul32 : 32 * j ≤ 32 * len.toNat := - Nat.mul_le_mul_left 32 (le_of_lt hjLtLen) - nlinarith - omega - have hcopyPtrBeforeFree : elemPtr.toNat + 32 ≤ free.toNat := by - rw [hcopyPtrToNat] - change base.toNat + 32 + 96 * len.toNat + 64 * j + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat - rw [hInv.freeExact] - omega - have hcopyPtr32BeforeFree : - ((⟨32⟩ : UInt256) + elemPtr).toNat + 32 ≤ free.toNat := by - rw [hcopyPtr32ToNat] - change base.toNat + 32 + 96 * len.toNat + 64 * j + 32 + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat - rw [hInv.freeExact] - omega - have hcurrentSlotBelowCopySlot : slot.toNat + 32 ≤ copySlot.toNat := by - rw [hcopySlotToNat] - exact le_trans (by simpa [slot] using hslotBeforeBase) (by omega) - have hcurrentSlotBelowPtr : slot.toNat + 32 ≤ elemPtr.toNat := by - rw [hcopyPtrToNat] - exact le_trans (by simpa [slot] using hslotBeforeBase) (by omega) - have hcurrentSlotBelowPtr32 : slot.toNat + 32 ≤ ((⟨32⟩ : UInt256) + elemPtr).toNat := by - rw [hcopyPtr32ToNat] - exact le_trans (by simpa [slot] using hslotBeforeBase) (by omega) - refine ⟨uidWord, elemPtr, huidWord, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · rw [helemSlotToNat] - exact le_trans hcontentLoBase (by omega) - · rw [helemSlotToNat] - omega - · rw [helemSlotEqNat] - exact attesterMultiRevokePostCopyOuterMem_size_ge - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - hcopySlotMem - · rw [helemSlotEqNat] - exact attesterMultiRevokePostCopyOuterMem_read_preserved_before_free - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - hcopySlotMem hcopySlotRead - (by - rw [hcopySlotToNat] - have hbaseGe := hInv.baseGe - omega) - hcopySlotBeforeFree hdataToNat - (Or.inr (by simpa [slot] using hcurrentSlotBelowCopySlot)) - · rw [hcopyPtrToNat] - exact le_trans hcontentLoBase (by omega) - · rw [hcopyPtrToNat] - omega - · exact attesterMultiRevokePostCopyOuterMem_size_ge - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - hcopyPtrMem - · rw [hcopyPtr32ToNat] - exact le_trans hcontentLoBase (by omega) - · rw [hcopyPtr32ToNat] - omega - · exact attesterMultiRevokePostCopyOuterMem_size_ge - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - hcopyPtr32Mem - · have hreadPtr : - finalMem.readWithPadding elemPtr.toNat 32 = - UInt256.toByteArray - (calldataWord I.calldata - (attesterMultiRevokeInnerArrayCopyCalldataOffset payload - (UInt256.ofNat j)).toNat) := by - dsimp [finalMem] - exact attesterMultiRevokePostCopyOuterMem_read_preserved_before_free - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - hcopyPtrMem hcopyPtrRead - (by - rw [hcopyPtrToNat] - omega) - hcopyPtrBeforeFree hdataToNat - (Or.inr (by simpa [slot] using hcurrentSlotBelowPtr)) - have hwordEq : - calldataWord I.calldata - (attesterMultiRevokeInnerArrayCopyCalldataOffset payload - (UInt256.ofNat j)).toNat = - uidWord := by - exact huidWordEq.symm - simpa [hwordEq] using hreadPtr - · dsimp [finalMem] - exact attesterMultiRevokePostCopyOuterMem_read_preserved_before_free - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := s.mem) (aw := s.aw) - hcopyPtr32Mem hcopyPtr32Read - (by - rw [hcopyPtr32ToNat] - omega) - hcopyPtr32BeforeFree hdataToNat - (Or.inr (by simpa [slot] using hcurrentSlotBelowPtr32)) - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeOuterIterationToOuterLoopWithReadInvariantAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx outerBase schemaLen secondLen secondPayload schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hidxSchema : UInt256.lt idx schemaLen = ⟨1⟩) - (hidxSecond : UInt256.lt idx secondLen = ⟨1⟩) - (hoffsetOk : - UInt256.slt - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) secondPayload) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩) - (hlenOk : - UInt256.gt - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hpayloadOk : - UInt256.sgt - (attesterMultiRevokeInnerArrayPayloadWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) ⟨5⟩)) = ⟨0⟩) - (hlenNe : - attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx) ≠ ⟨0⟩) - (hawGe : 3 ≤ aw.toNat) - (hawMul : aw.toNat * 32 < UInt256.size) - (houterRead : mem.readWithPadding outerBase.toNat 32 = UInt256.toByteArray schemaLen) - (houterMemSize : outerBase.toNat + 32 ≤ mem.size) - (houter64 : 64 + 32 ≤ outerBase.toNat) - (hbaseGe : 64 + 32 ≤ (attesterInnerArrayAllocFreeWord mem aw).toNat) - (houterBeforeBase : - outerBase.toNat + 32 ≤ (attesterInnerArrayAllocFreeWord mem aw).toNat) - (hbaseSpare : - (attesterInnerArrayAllocFreeWord mem aw).toNat + 32 + - 160 * - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)).toNat + - 96 < UInt256.size) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ b' s' k' C', - b'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeInnerInitReadInvAt I - (attesterInnerArrayAllocFreeWord mem aw) - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - outerBase schemaLen 0 b' ∧ - s'.idx = - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) ∧ - attesterMultiRevokeInnerCopyReadInvAt I - (attesterInnerArrayAllocFreeWord mem aw) - (attesterMultiRevokeInnerArrayLengthWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - (attesterMultiRevokeInnerArrayPayloadWord I secondPayload - (attesterMultiRevokeInnerArrayHeadWord secondPayload idx)) - outerBase schemaLen 0 s' ∧ - AttesterReadPreservedBefore mem s'.mem - (attesterInnerArrayAllocFreeWord mem aw).toNat ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [attesterMultiRevokePostCopyNextIdx idx, outerBase, schemaLen, - secondLen, secondPayload, schemaLen, schemaPayload, ret, selector] - (attesterMultiRevokePostCopyOuterMem - (attesterInnerArrayAllocFreeWord mem aw) outerBase I schemaPayload idx s'.mem s'.aw) - (attesterMultiRevokePostCopyOuterAw - (attesterInnerArrayAllocFreeWord mem aw) outerBase I schemaPayload idx s'.mem s'.aw) - ByteArray.empty (cA, σ) k' C' := by - let head := attesterMultiRevokeInnerArrayHeadWord secondPayload idx - let innerLen := attesterMultiRevokeInnerArrayLengthWord I secondPayload head - let innerPayload := attesterMultiRevokeInnerArrayPayloadWord I secondPayload head - let base := attesterInnerArrayAllocFreeWord mem aw - let tail := - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - obtain ⟨k0, C0, rd475⟩ := - attesterX_multiRevokeOuterIterationToInnerInitAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k) (C := C) - hidxSchema hidxSecond hoffsetOk hlenOk hpayloadOk hlenNe hreach - have hlenNatNe : innerLen.toNat ≠ 0 := by - intro hzero - apply hlenNe - apply u256_inj - simpa [innerLen] using hzero - have hinit : - attesterMultiRevokeInnerInitReadInvAt I base innerLen outerBase schemaLen - (innerLen.toNat - 1) - { slot := ((⟨32⟩ : UInt256) + base), - remaining := innerLen, - mem := attesterInnerArrayAllocMem innerLen mem aw, - aw := attesterInnerArrayAllocAw innerLen mem aw } := by - exact attesterMultiRevokeInnerInitReadInvAt_init - (I := I) (base := base) (len := innerLen) - (outerBase := outerBase) (schemaLen := schemaLen) - (mem := mem) (aw := aw) - hlenNatNe hawGe hawMul (by simpa [base] using hbaseGe) - (by simpa [base, innerLen, head] using hbaseSpare) - houterRead houterMemSize houter64 - (by simpa [base] using houterBeforeBase) rfl - have hpresAlloc : - AttesterReadPreservedBefore mem (attesterInnerArrayAllocMem innerLen mem aw) - base.toNat := by - exact AttesterReadPreservedBefore_innerAlloc - (len := innerLen) (mem := mem) (aw := aw) (base := base) rfl - let InitInv : Nat → AttesterMultiRevokeInnerArrayInitState → Prop := - fun n b => - attesterMultiRevokeInnerInitReadInvAt I base innerLen outerBase schemaLen n b ∧ - AttesterReadPreservedBefore mem b.mem base.toNat - obtain ⟨b', k1, C1, hbrem, hInitFinalPair, rd518⟩ := - attesterX_multiRevokeInnerArrayInitLoopWithStateInvariantAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (slot := ((⟨32⟩ : UInt256) + base)) (base := base) - (len := innerLen) (payload := innerPayload) (tail := tail) - (mem := attesterInnerArrayAllocMem innerLen mem aw) - (aw := attesterInnerArrayAllocAw innerLen mem aw) - (k := k0) (C := C0) (by simp [tail]) - InitInv - (fun n b hInv => attesterMultiRevokeInnerInitReadInvAt_remaining hInv.1) - (fun n b hInv => attesterMultiRevokeInnerInitReadInvAt_bound hInv.1) - (fun n b hInv => - ⟨attesterMultiRevokeInnerInitReadInvAt_step hInv.1, - AttesterReadPreservedBefore_innerInitStep hInv.1 hInv.2⟩) - (by exact ⟨hinit, hpresAlloc⟩) - (by simpa [base, innerLen, innerPayload, head, tail] using rd475) - have hInitFinal : - attesterMultiRevokeInnerInitReadInvAt I base innerLen outerBase schemaLen 0 b' := - hInitFinalPair.1 - have hpresInitFinal : - AttesterReadPreservedBefore mem b'.mem base.toNat := - hInitFinalPair.2 - have hpresInitFinalMem : - AttesterReadPreservedBefore mem - (attesterMultiRevokeInnerArrayInitFinalMem b') base.toNat := - AttesterReadPreservedBefore_innerInitFinal hInitFinal hpresInitFinal - have hcopyInit : - attesterMultiRevokeInnerCopyReadInvAt I base innerLen innerPayload outerBase schemaLen - innerLen.toNat (attesterMultiRevokeInnerCopyInitState b') := - attesterMultiRevokeInnerCopyReadInvAt_init (payload := innerPayload) hInitFinal - have hpresCopyInit : - AttesterReadPreservedBefore mem - (attesterMultiRevokeInnerCopyInitState b').mem base.toNat := by - change AttesterReadPreservedBefore mem - (attesterMultiRevokeInnerArrayInitFinalMem b') base.toNat - exact hpresInitFinalMem - obtain ⟨s', k2, C2, hsidx, hCopy, hpresCopy, rd335⟩ := - attesterX_multiRevokeInnerCopyLoopToOuterLoopPreservedAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := base) (len := innerLen) (payload := innerPayload) - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := attesterMultiRevokeInnerArrayInitFinalMem b') - (aw := attesterMultiRevokeInnerArrayInitFinalAw b') - (k := k1) (C := C1) hidxSchema hcopyInit hpresCopyInit - (by - simpa [attesterMultiRevokeInnerCopyInitState, base, innerLen, innerPayload, - tail, attesterMultiRevokeInnerArrayInitExitStackAt] using rd518) - have hpresCopyFree : - AttesterReadPreservedBefore mem s'.mem - (attesterInnerArrayAllocFreeWord mem aw).toNat := by - change AttesterReadPreservedBefore mem s'.mem base.toNat - exact hpresCopy - exact ⟨b', s', k2, C2, hbrem, by simpa [base, innerLen] using hInitFinal, - by simpa [innerLen] using hsidx, by simpa [base, innerLen, innerPayload] using hCopy, - hpresCopyFree, by simpa [base, innerLen, innerPayload, head] using rd335⟩ - -set_option maxHeartbeats 1000000 in -theorem AttesterMultiRevokeOuterLoopInv.body_or_revert - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {callargs : Store} {schemas schemaUids : List Value} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hSchemas : callargs.get? "schemas" = some (.array schemas)) - (hSchemaUids : callargs.get? "schemaUids" = some (.array schemaUids)) - (hoff0 : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hoff1 : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hsizeSigned : I.calldata.size < 2 ^ 255) - (hschemasBound : schemas.length < 2 ^ 256) - (hschemasLenMax : schemas.length ≤ solcMaxU64) - (hlenEq : schemaUids.length = schemas.length) - (hschemaNorm : ∀ {idx schema}, lookupNth? schemas idx = some schema → - normalizeRawBoolWord? schema = .ok schema) - (huidssShape : ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid)) : - ∀ {fuel : Nat} {a : AttesterMultiRevokeOuterLoopCursor} {L : Store} - {evm : EVM.State}, - AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids (fuel + 1) a L evm → - ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a) a.mem a.aw ByteArray.empty a.acc k C → - (ExecBlock (config v) { contract := contract v, locals := L } evm - attesterMultiRevokeOuterSourceLoopBody .reverted ∧ - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I)) ∨ - ∃ a' L' evm' k' C', - (ExecBlock (config v) { contract := contract v, locals := L } evm - attesterMultiRevokeOuterSourceLoopBody - (.ok { contract := contract v, locals := L' } evm') ∨ - ExecBlock (config v) { contract := contract v, locals := L } evm - attesterMultiRevokeOuterSourceLoopBody - (.continue { contract := contract v, locals := L' } evm')) ∧ - AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids fuel a' L' evm' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a') a'.mem a'.aw ByteArray.empty a'.acc k' C' := by - intro fuel a L evm hInv k C hreach - rcases hInv with - ⟨i, hschemas, hschemaUids, hschemaLength, hrequests, hi, hvariant, hile, - hprocessed, hisize, hidx, hidxToNat, houterBase, hschemaLen, - hschemaLenToNat, hsecondLen, hsecondLenToNat, hsecondPayload, - hschemaPayload, hret, hselector, hacc, hawGe, hawMul, houterRead, - houterMemSize, houter64, hbaseGe, houterBeforeBase, - houterSlotsBeforeBase, hreadLayout, hfreeBudget⟩ - have hreachInit : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a) a.mem a.aw ByteArray.empty (cA, σ) k C := by - simpa [hacc] using hreach - have hltSchemas : i < schemas.length := by omega - have hiMax : i ≤ solcMaxU64 := by omega - have hltSchemaUids : i < schemaUids.length := by omega - obtain ⟨schema, hschemaLookup⟩ := - attesterLookupNth?_exists (xs := schemas) (i := i) hltSchemas - obtain ⟨schemaUidValue, hschemaUidLookupValue⟩ := - attesterLookupNth?_exists (xs := schemaUids) (i := i) hltSchemaUids - obtain ⟨uids, hschemaUidValue, huidsBound, huidsNorm⟩ := - huidssShape hschemaUidLookupValue - have hschemaUidLookup : lookupNth? schemaUids i = some (.array uids) := by - simpa [hschemaUidValue] using hschemaUidLookupValue - obtain ⟨hidxSecond0, hoffsetOk0, hlenOk0, hpayloadOk0, hlenToNat0, - hinnerLenMax, hlenZeroOf, hlenNeOf⟩ := - attesterMultiRevokeInnerArrayCurrentFacts_of_decode_at - (v := v) (I := I) (callargs := callargs) (schemaUids := schemaUids) - (inner := uids) (idx := i) hdec hSchemaUids hschemaUidLookup hoff1 hsizeSigned - have hidxSchema : UInt256.lt a.idx a.schemaLen = ⟨1⟩ := - AttesterMultiRevokeOuterLoopInv.cond_true - (cA := cA) (σ := σ) (I := I) (schemas := schemas) - (schemaUids := schemaUids) (fuel := fuel) (a := a) (L := L) - (evm := evm) - ⟨i, hschemas, hschemaUids, hschemaLength, hrequests, hi, hvariant, hile, - hprocessed, hisize, hidx, hidxToNat, houterBase, hschemaLen, - hschemaLenToNat, hsecondLen, hsecondLenToNat, hsecondPayload, - hschemaPayload, hret, hselector, hacc, hawGe, hawMul, houterRead, - houterMemSize, houter64, hbaseGe, houterBeforeBase, - houterSlotsBeforeBase, hreadLayout, hfreeBudget⟩ - have hidxSecond : UInt256.lt a.idx a.secondLen = ⟨1⟩ := by - simpa [hidx, hsecondLen] using hidxSecond0 - have hoffsetOk : - UInt256.slt - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx)) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) a.secondPayload) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩ := by - simpa [hidx, hsecondPayload] using hoffsetOk0 - have hlenOk : - UInt256.gt - (attesterMultiRevokeInnerArrayLengthWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩ := by - simpa [hidx, hsecondPayload] using hlenOk0 - have hpayloadOk : - UInt256.sgt - (attesterMultiRevokeInnerArrayPayloadWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx)) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx)) ⟨5⟩)) = - ⟨0⟩ := by - simpa [hidx, hsecondPayload] using hpayloadOk0 - cases uids with - | nil => - have hbodyRevert := - attesterMultiRevokeOuterSourceLoopBody_revert_emptyCurrent - (imm := v) (evm := evm) (locals := L) (schemaUids := schemaUids) - (i := i) hschemaUids hi hltSchemaUids (by simpa using hschemaUidLookup) - have hlenZero : - attesterMultiRevokeInnerArrayLengthWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx) = ⟨0⟩ := by - simpa [hidx, hsecondPayload] using hlenZeroOf (by simp) - exact .inl ⟨hbodyRevert, - attesterX_multiRevokeOuterIterationLengthZeroRevertsAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := a.idx) (outerBase := a.outerBase) (schemaLen := a.schemaLen) - (secondLen := a.secondLen) (secondPayload := a.secondPayload) - (schemaPayload := a.schemaPayload) (ret := a.ret) (selector := a.selector) - (mem := a.mem) (aw := a.aw) (k := k) (C := C) - hidxSchema hidxSecond hoffsetOk hlenOk hpayloadOk hlenZero - (by simpa [attesterMultiRevokeOuterLoopStack] using hreachInit)⟩ - | cons uid rest => - have huidsNe : (uid :: rest).length ≠ 0 := by simp - obtain ⟨L', hbodyOk, hsourceInv'⟩ := - attesterMultiRevokeOuterSourceLoop_step_current - (imm := v) (evm := evm) (schemas := schemas) (schemaUids := schemaUids) - hschemasBound hlenEq hschemaNorm fuel L - ⟨i, hschemas, hschemaUids, hschemaLength, hrequests, hi, hvariant, hile⟩ - (by - intro idx value hlookup hidxVar - have hidxEq : idx = i := by omega - subst idx - have hvalueEq : value = .array (uid :: rest) := by - have hs : some value = some (.array (uid :: rest)) := by - rw [← hlookup] - simpa [hschemaUidValue] using hschemaUidLookupValue - cases hs - rfl - exact ⟨uid :: rest, hvalueEq, huidsNe, huidsBound, huidsNorm⟩) - have hlenNe : - attesterMultiRevokeInnerArrayLengthWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx) ≠ ⟨0⟩ := by - simpa [hidx, hsecondPayload] using hlenNeOf huidsNe - have hbaseSpare : - (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat + 32 + - 160 * - (attesterMultiRevokeInnerArrayLengthWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx)).toNat + - 96 < UInt256.size := by - have hmul := Nat.mul_le_mul_left 160 hinnerLenMax - have hchunkLe : - 128 + 160 * (uid :: rest).length ≤ - attesterMultiRevokeOuterLoopBudgetChunk := by - unfold attesterMultiRevokeOuterLoopBudgetChunk - omega - have hbudgetStep : - 128 + 160 * (uid :: rest).length ≤ - attesterMultiRevokeOuterLoopBudgetChunk * (fuel + 1) := by - have hone : 1 ≤ fuel + 1 := by omega - have hmulFuel := - Nat.mul_le_mul_left attesterMultiRevokeOuterLoopBudgetChunk hone - omega - rw [show - (attesterMultiRevokeInnerArrayLengthWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx)).toNat = - (uid :: rest).length by simpa [hidx, hsecondPayload] using hlenToNat0] - omega - obtain ⟨b', s', k', C', _hbrem, _hInit, _hsidx, hCopy, hpresCopy, rd335⟩ := - attesterX_multiRevokeOuterIterationToOuterLoopWithReadInvariantAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := a.idx) (outerBase := a.outerBase) (schemaLen := a.schemaLen) - (secondLen := a.secondLen) (secondPayload := a.secondPayload) - (schemaPayload := a.schemaPayload) (ret := a.ret) (selector := a.selector) - (mem := a.mem) (aw := a.aw) (k := k) (C := C) - hidxSchema hidxSecond hoffsetOk hlenOk hpayloadOk hlenNe - hawGe hawMul houterRead houterMemSize houter64 hbaseGe houterBeforeBase - hbaseSpare - (by simpa [attesterMultiRevokeOuterLoopStack] using hreachInit) - let aNext : AttesterMultiRevokeOuterLoopCursor := - { a with - idx := attesterMultiRevokePostCopyNextIdx a.idx, - mem := attesterMultiRevokePostCopyOuterMem - (attesterInnerArrayAllocFreeWord a.mem a.aw) a.outerBase I a.schemaPayload - a.idx s'.mem s'.aw, - aw := attesterMultiRevokePostCopyOuterAw - (attesterInnerArrayAllocFreeWord a.mem a.aw) a.outerBase I a.schemaPayload - a.idx s'.mem s'.aw } - rcases hsourceInv' with - ⟨i', hschemas', hschemaUids', hschemaLength', hrequests', hi', - hvariant', hile'⟩ - have hi' : i' = i + 1 := by omega - subst i' - have hschemasSize : schemas.length < UInt256.size := by - rw [← hschemaLenToNat] - exact a.schemaLen.val.isLt - have hiSuccSize : i + 1 < UInt256.size := by - omega - have hnextIdx : - attesterMultiRevokePostCopyNextIdx a.idx = UInt256.ofNat (i + 1) := by - rw [attesterMultiRevokePostCopyNextIdx, hidx] - exact u256_one_add_ofNat i - have hnextIdxToNat : - (attesterMultiRevokePostCopyNextIdx a.idx).toNat = i + 1 := by - rw [hnextIdx] - exact ulit_toNat' (i + 1) hiSuccSize - have hslotBound : - a.outerBase.toNat + 32 + 32 * a.idx.toNat + 63 < UInt256.size := by - have hidxLeMax : a.idx.toNat ≤ solcMaxU64 := by - rw [hidxToNat] - omega - have hnextLeMax : - (attesterMultiRevokePostCopyNextIdx a.idx).toNat ≤ solcMaxU64 := by - rw [hnextIdxToNat] - omega - have hmul := Nat.mul_le_mul_left 32 hidxLeMax - have hmulNext := Nat.mul_le_mul_left 32 hnextLeMax - have houterToNat : a.outerBase.toNat = 128 := by - rw [houterBase] - rfl - rw [houterToNat] - norm_num [solcMaxU64, UInt256.size] at hmul hmulNext ⊢ - omega - have hpostFacts := - attesterMultiRevokePostCopyOuter_cursorFacts_from_copyInvAt - (I := I) (base := attesterInnerArrayAllocFreeWord a.mem a.aw) - (len := attesterMultiRevokeInnerArrayLengthWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx)) - (payload := attesterMultiRevokeInnerArrayPayloadWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx)) - (outerBase := a.outerBase) (schemaLen := a.schemaLen) - (schemaPayload := a.schemaPayload) (idx := a.idx) (s := s') - hCopy hslotBound - rcases hpostFacts with - ⟨houterPost, hawGePost, hawMulPost, _hfreeToNatPost, - hbaseGePost, houterBeforeBasePost⟩ - have hpostFreeExact := - attesterMultiRevokePostCopyOuter_freeWordExact_from_copyInvAt - (I := I) (base := attesterInnerArrayAllocFreeWord a.mem a.aw) - (len := attesterMultiRevokeInnerArrayLengthWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx)) - (payload := attesterMultiRevokeInnerArrayPayloadWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx)) - (outerBase := a.outerBase) (schemaLen := a.schemaLen) - (schemaPayload := a.schemaPayload) (idx := a.idx) (s := s') - hCopy hslotBound - have hcurrentSlotToNat : - (attesterMultiRevokePostCopyOuterSlotWord a.outerBase a.idx).toNat = - a.outerBase.toNat + 32 + 32 * a.idx.toNat := by - exact attesterMultiRevokePostCopyOuterSlotWord_toNat (by omega) - have hcurrentSlotBeforeBase : - (attesterMultiRevokePostCopyOuterSlotWord a.outerBase a.idx).toNat + 32 ≤ - (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat := by - rw [hcurrentSlotToNat, hidxToNat] - have hmul : 32 * (i + 1) ≤ 32 * schemas.length := - Nat.mul_le_mul_left 32 (by omega) - omega - have hcurrentRequestReadLayoutBounded : - AttesterMultiRevokeRequestReadLayoutAtBounded schemas schemaUids - aNext.mem a.outerBase - (a.outerBase.toNat + 32 + 32 * schemas.length) - (attesterInnerArrayAllocFreeWord aNext.mem aNext.aw).toNat i := by - dsimp [aNext] - exact - attesterMultiRevokePostCopyOuter_currentRequestReadLayout_from_copyInvAt - (I := I) (callargs := callargs) (schemas := schemas) - (schemaUids := schemaUids) (uids := uid :: rest) (i := i) - (schema := schema) - (base := attesterInnerArrayAllocFreeWord a.mem a.aw) - (len := - attesterMultiRevokeInnerArrayLengthWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx)) - (payload := - attesterMultiRevokeInnerArrayPayloadWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx)) - (outerBase := a.outerBase) (schemaLen := a.schemaLen) - (schemaPayload := a.schemaPayload) (idx := a.idx) (s := s') v - hdec hSchemas hschemaLookup hschemaUidLookup hoff0 hiMax hidx hschemaPayload - (by - simpa [hidx, hsecondPayload] using hlenToNat0) - (by - intro j uidVal hlookupUid - simpa [hidx, hsecondPayload] using - (attesterDecode_multiRevoke_uid_word_at_copy_payload - (v := v) (I := I) (callargs := callargs) - (schemaUids := schemaUids) (uids := uid :: rest) - (idx := i) (j := j) (uid := uidVal) - hdec hSchemaUids hschemaUidLookup hlookupUid hoff1 hsizeSigned)) - hCopy hcurrentSlotBeforeBase - houterSlotsBeforeBase - (by rw [hpostFreeExact]) - hslotBound - have hcurrentRequestReadLayout : - AttesterMultiRevokeRequestReadLayoutAt schemas schemaUids aNext.mem a.outerBase i := - AttesterMultiRevokeRequestReadLayoutAtBounded.to_readLayout - hcurrentRequestReadLayoutBounded - have hfreeBudgetNext : - (attesterInnerArrayAllocFreeWord aNext.mem aNext.aw).toNat + - attesterMultiRevokeEncoderOutputBudget schemas.length + 128 + - attesterMultiRevokeOuterLoopBudgetChunk * fuel < UInt256.size := by - dsimp [aNext] - rw [hpostFreeExact] - rw [show - (attesterMultiRevokeInnerArrayLengthWord I a.secondPayload - (attesterMultiRevokeInnerArrayHeadWord a.secondPayload a.idx)).toNat = - (uid :: rest).length by simpa [hidx, hsecondPayload] using hlenToNat0] - have hstep : - 96 + 160 * (uid :: rest).length + - attesterMultiRevokeEncoderOutputBudget schemas.length + 128 + - attesterMultiRevokeOuterLoopBudgetChunk * fuel ≤ - attesterMultiRevokeEncoderOutputBudget schemas.length + 128 + - attesterMultiRevokeOuterLoopBudgetChunk * (fuel + 1) := by - rw [Nat.mul_succ] - have hmulLen := Nat.mul_le_mul_left 160 hinnerLenMax - unfold attesterMultiRevokeOuterLoopBudgetChunk - omega - omega - have houterSlotsBeforeBaseNext : - aNext.outerBase.toNat + 32 + 32 * schemas.length ≤ - (attesterInnerArrayAllocFreeWord aNext.mem aNext.aw).toNat := by - dsimp [aNext] - rw [hpostFreeExact] - exact le_trans houterSlotsBeforeBase (by omega) - have hprocessedNext : - ∀ {idx value}, idx < i + 1 → lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length ≠ 0 ∧ - uids.length ≤ solcMaxU64 ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid) := by - intro idx value hidxLt hlookup - by_cases hlt : idx < i - · exact hprocessed hlt hlookup - · have hidxEq : idx = i := by omega - subst idx - have hvalueEq : value = .array (uid :: rest) := by - have hs : some value = some (.array (uid :: rest)) := by - rw [← hlookup] - simpa [hschemaUidValue] using hschemaUidLookupValue - cases hs - rfl - exact ⟨uid :: rest, hvalueEq, huidsNe, hinnerLenMax, huidsBound, huidsNorm⟩ - let currentSlot := attesterMultiRevokePostCopyOuterSlotWord a.outerBase a.idx - have hcontentLo64 : - 64 + 32 ≤ a.outerBase.toNat + 32 + 32 * schemas.length := by - omega - have hcurrentSlotBeforeContent : - currentSlot.toNat + 32 ≤ a.outerBase.toNat + 32 + 32 * schemas.length := by - dsimp [currentSlot] - rw [hcurrentSlotToNat, hidxToNat] - omega - have hboundOldLeNext : - (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat ≤ - (attesterInnerArrayAllocFreeWord aNext.mem aNext.aw).toNat := by - dsimp [aNext] - rw [hpostFreeExact] - omega - have hpostDataToNat : - (attesterMultiRevokePostCopyDataOffsetWord s'.mem s'.aw).toNat = - (attesterMultiRevokePostCopyFreeWord s'.mem s'.aw).toNat + 32 := by - have hfree32 : - (attesterMultiRevokePostCopyFreeWord s'.mem s'.aw).toNat + 32 < - UInt256.size := by - have hspare : - (attesterMultiRevokePostCopyFreeWord s'.mem s'.aw).toNat + 96 < - UInt256.size := by - simpa [attesterMultiRevokePostCopyFreeWord, - attesterMultiRevokeInnerArrayCopyFreeWord] using hCopy.freeSpare - omega - unfold attesterMultiRevokePostCopyDataOffsetWord - exact uadd_lit32_toNat (attesterMultiRevokePostCopyFreeWord s'.mem s'.aw) - hfree32 - have hpreserveToNext : - AttesterReadPreservedBeforeExcept a.mem aNext.mem - (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat currentSlot.toNat := by - intro read word hmem hread hread64 hbefore hdisj - rcases hpresCopy hmem hread hread64 hbefore with ⟨hmemCopy, hreadCopy⟩ - constructor - · dsimp [aNext] - exact attesterMultiRevokePostCopyOuterMem_size_ge - (I := I) (base := attesterInnerArrayAllocFreeWord a.mem a.aw) - (outerBase := a.outerBase) (schemaPayload := a.schemaPayload) - (idx := a.idx) (mem := s'.mem) (aw := s'.aw) hmemCopy - · dsimp [aNext] - exact attesterMultiRevokePostCopyOuterMem_read_preserved_before_free - (I := I) (base := attesterInnerArrayAllocFreeWord a.mem a.aw) - (outerBase := a.outerBase) (schemaPayload := a.schemaPayload) - (idx := a.idx) (mem := s'.mem) (aw := s'.aw) - hmemCopy hreadCopy hread64 - (by - have hfreeGe := hCopy.freeGe - change - (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord s'.mem s'.aw).toNat - at hfreeGe - simpa [attesterMultiRevokePostCopyFreeWord, - attesterMultiRevokeInnerArrayCopyFreeWord] using - (le_trans hbefore (by omega : (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord s'.mem s'.aw).toNat))) - hpostDataToNat - (by simpa [currentSlot] using hdisj) - have hreadLayoutNext : - AttesterMultiRevokeRequestsReadLayoutBounded schemas schemaUids (i + 1) - aNext.mem aNext.outerBase - (aNext.outerBase.toNat + 32 + 32 * schemas.length) - (attesterInnerArrayAllocFreeWord aNext.mem aNext.aw).toNat := by - intro idxOld hidxOld - by_cases hltOld : idxOld < i - · have hidxOldSize : idxOld < UInt256.size := by omega - have hidxOldToNat : (UInt256.ofNat idxOld).toNat = idxOld := - ulit_toNat' idxOld hidxOldSize - have hslotOldToNat : - (attesterMultiRevokePostCopyOuterSlotWord a.outerBase - (UInt256.ofNat idxOld)).toNat = - a.outerBase.toNat + 32 + 32 * idxOld := by - rw [attesterMultiRevokePostCopyOuterSlotWord_toNat] - · rw [hidxOldToNat] - · rw [hidxOldToNat] - have hidxOldMax : idxOld ≤ solcMaxU64 := by omega - have hmul : 32 * idxOld ≤ 32 * solcMaxU64 := - Nat.mul_le_mul_left 32 hidxOldMax - have houterToNat : a.outerBase.toNat = 128 := by - rw [houterBase] - rfl - rw [houterToNat] - norm_num [solcMaxU64, UInt256.size] at hmul ⊢ - omega - have hownSlotBefore : - (attesterMultiRevokePostCopyOuterSlotWord a.outerBase - (UInt256.ofNat idxOld)).toNat + 32 ≤ currentSlot.toNat := by - dsimp [currentSlot] - rw [hslotOldToNat, hcurrentSlotToNat, hidxToNat] - omega - have hOld : - AttesterMultiRevokeRequestReadLayoutAtBounded schemas schemaUids - a.mem a.outerBase - (a.outerBase.toNat + 32 + 32 * schemas.length) - (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat idxOld := - hreadLayout hltOld - have hpreserved : - AttesterMultiRevokeRequestReadLayoutAtBounded schemas schemaUids - aNext.mem a.outerBase - (a.outerBase.toNat + 32 + 32 * schemas.length) - (attesterInnerArrayAllocFreeWord aNext.mem aNext.aw).toNat idxOld := - AttesterMultiRevokeRequestReadLayoutAtBounded.preserve_except - (schemas := schemas) (schemaUids := schemaUids) - (mem := a.mem) (mem' := aNext.mem) (outerBase := a.outerBase) - (contentLo := a.outerBase.toNat + 32 + 32 * schemas.length) - (bound := (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat) - (bound' := (attesterInnerArrayAllocFreeWord aNext.mem aNext.aw).toNat) - (protectedSlot := currentSlot.toNat) (idx := idxOld) - hcontentLo64 hboundOldLeNext hownSlotBefore - hcurrentSlotBeforeContent hpreserveToNext hOld - simpa [aNext] using hpreserved - · have hidxEq : idxOld = i := by omega - subst idxOld - simpa [aNext] using hcurrentRequestReadLayoutBounded - exact .inr ⟨aNext, L', evm, k', C', .inl hbodyOk, - ⟨i + 1, hschemas', hschemaUids', hschemaLength', hrequests', hi', - hvariant', hile', hprocessedNext, hiSuccSize, - by simpa [aNext] using hnextIdx, - by simpa [aNext] using hnextIdxToNat, - by simpa [aNext] using houterBase, - by simpa [aNext] using hschemaLen, - by simpa [aNext] using hschemaLenToNat, - by simpa [aNext] using hsecondLen, - by simpa [aNext] using hsecondLenToNat, - by simpa [aNext] using hsecondPayload, - by simpa [aNext] using hschemaPayload, - by simpa [aNext] using hret, - by simpa [aNext] using hselector, - by simpa [aNext] using hacc, - by simpa [aNext] using hawGePost, - by simpa [aNext] using hawMulPost, - by simpa [aNext] using houterPost.1, - by simpa [aNext] using houterPost.2, - by simpa [aNext] using houter64, - by simpa [aNext] using hbaseGePost, - by simpa [aNext] using houterBeforeBasePost, - houterSlotsBeforeBaseNext, - hreadLayoutNext, - hfreeBudgetNext⟩, - by - simpa [aNext, attesterMultiRevokeOuterLoopStack, hacc] using rd335⟩ - -theorem attesterX_multiRevokeFirstInnerCopyToOuterLoopWithReadInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (hidxSchema : UInt256.lt (⟨0⟩ : UInt256) (attesterFirstArrayLengthWord I) = ⟨1⟩) - (hprogress : - ∃ (a' : AttesterMultiOuterArrayInitState), - ∃ (b' : AttesterMultiRevokeInnerArrayInitState), - ∃ (c' : AttesterMultiRevokeInnerArrayCopyState), - ∃ k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeInnerInitReadInv I a' 0 b' ∧ - c'.idx = attesterFirstInnerArrayLengthWord I ∧ - attesterMultiRevokeInnerCopyReadInv I a' b' 0 c' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨608⟩ : UInt256) - (attesterMultiRevokeInnerArrayCopyStack - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - c') - c'.mem c'.aw ByteArray.empty (cA, σ) k C) : - ∃ (a' : AttesterMultiOuterArrayInitState), - ∃ (b' : AttesterMultiRevokeInnerArrayInitState), - ∃ (c' : AttesterMultiRevokeInnerArrayCopyState), - ∃ k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeInnerInitReadInv I a' 0 b' ∧ - c'.idx = attesterFirstInnerArrayLengthWord I ∧ - attesterMultiRevokeInnerCopyReadInv I a' b' 0 c' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [attesterMultiRevokePostCopyNextIdx (⟨0⟩ : UInt256), ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiRevokePostCopyOuterMem - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ⟨128⟩ I ((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩) - (⟨0⟩ : UInt256) c'.mem c'.aw) - (attesterMultiRevokePostCopyOuterAw - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ⟨128⟩ I ((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩) - (⟨0⟩ : UInt256) c'.mem c'.aw) - ByteArray.empty (cA, σ) k C := by - obtain ⟨a', b', c', k0, C0, harem, hOuter, hbrem, hInit, hcidx, hCopy, rd0⟩ := - hprogress - let base := - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - let schemaPayload := (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩ - have hmloadOuter : - attesterMloadWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload (⟨0⟩ : UInt256) - c'.mem c'.aw) - (attesterMultiRevokePostCopyDataAw base I schemaPayload (⟨0⟩ : UInt256) - c'.mem c'.aw) - (⟨128⟩ : UInt256) = - attesterFirstArrayLengthWord I := by - exact attesterMultiRevokePostCopyDataMem_mloadOuter - (base := base) (outerBase := (⟨128⟩ : UInt256)) - (len := attesterFirstArrayLengthWord I) (schemaPayload := schemaPayload) - (idx := (⟨0⟩ : UInt256)) (mem := c'.mem) (aw := c'.aw) - (by simpa using hCopy.outerMemSize) - (by simpa using hCopy.outerRead) - (by simpa using hCopy.awMul) - (by decide) - (by simpa [base] using hCopy.base160) - (by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord c'.mem c'.aw).toNat - simpa [base] using hCopy.freeGe) - (by - change - (attesterMultiRevokeInnerArrayCopyFreeWord c'.mem c'.aw).toNat + 96 < - UInt256.size - have hspare := hCopy.freeSpare - simpa using hspare) - have hidxOuter : - UInt256.lt (⟨0⟩ : UInt256) - (attesterMloadWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload (⟨0⟩ : UInt256) - c'.mem c'.aw) - (attesterMultiRevokePostCopyDataAw base I schemaPayload (⟨0⟩ : UInt256) - c'.mem c'.aw) - (⟨128⟩ : UInt256)) = ⟨1⟩ := by - rw [hmloadOuter] - exact hidxSchema - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokePostInnerCopyToOuterLoop - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (innerIdx := c'.idx) (base := base) - (innerLen := attesterFirstInnerArrayLengthWord I) - (payload := attesterFirstInnerArrayStartWord I + ⟨32⟩) - (idx := (⟨0⟩ : UInt256)) (outerBase := (⟨128⟩ : UInt256)) - (schemaLen := attesterFirstArrayLengthWord I) - (secondLen := attesterSecondArrayLengthWord I) - (secondPayload := attesterSecondArrayPayloadStartWord I) - (schemaPayload := schemaPayload) (ret := ⟨97⟩) - (selector := solcSelectorWord I) (mem := c'.mem) (aw := c'.aw) - (k := k0) (C := C0) - hidxSchema hidxOuter - (by - simpa [base, schemaPayload, hcidx, - attesterMultiRevokeInnerArrayCopyStack] using rd0) - exact ⟨a', b', c', k1, C1, harem, hOuter, hbrem, hInit, hcidx, hCopy, by - simpa [base, schemaPayload] using rd1⟩ - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/MultiRevokeEVM.lean b/Benchmarks/EAS/Attester/MultiRevokeEVM.lean deleted file mode 100644 index 03fdbe6e..00000000 --- a/Benchmarks/EAS/Attester/MultiRevokeEVM.lean +++ /dev/null @@ -1,1593 +0,0 @@ -import Benchmarks.EAS.Attester.MultiRevokeMemory - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -set_option linter.unnecessarySimpa false - -abbrev attesterMultiRevokePostCopyFreeWord - (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMloadWord mem aw ⟨64⟩ - -abbrev attesterMultiRevokePostCopyAwAfterMload - (aw : UInt256) : UInt256 := - attesterMloadAw aw ⟨64⟩ - -abbrev attesterMultiRevokePostCopyFreeBumpWord - (mem : ByteArray) (aw : UInt256) : UInt256 := - (⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw - -abbrev attesterMultiRevokePostCopyFreeMem - (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray - (attesterMultiRevokePostCopyFreeBumpWord mem aw)).write 0 mem 64 32 - -abbrev attesterMultiRevokePostCopyFreeAw - (_mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiRevokePostCopyAwAfterMload aw).toNat 64 32) - -abbrev attesterMultiRevokePostCopySchemaCalldataOffset - (schemaPayload idx : UInt256) : UInt256 := - UInt256.mul (⟨32⟩ : UInt256) idx + schemaPayload - -abbrev attesterMultiRevokePostCopySchemaWord - (I : ExecutionEnv) (schemaPayload idx : UInt256) : UInt256 := - calldataWord I.calldata - (attesterMultiRevokePostCopySchemaCalldataOffset schemaPayload idx).toNat - -abbrev attesterMultiRevokePostCopySchemaMem - (I : ExecutionEnv) (schemaPayload idx : UInt256) (mem : ByteArray) (aw : UInt256) : - ByteArray := - (UInt256.toByteArray - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)).write 0 - (attesterMultiRevokePostCopyFreeMem mem aw) - (attesterMultiRevokePostCopyFreeWord mem aw).toNat 32 - -abbrev attesterMultiRevokePostCopySchemaAw - (_I : ExecutionEnv) (_schemaPayload _idx : UInt256) (mem : ByteArray) (aw : UInt256) : - UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiRevokePostCopyFreeAw mem aw).toNat - (attesterMultiRevokePostCopyFreeWord mem aw).toNat 32) - -abbrev attesterMultiRevokePostCopyDataOffsetWord - (mem : ByteArray) (aw : UInt256) : UInt256 := - (⟨32⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw - -abbrev attesterMultiRevokePostCopyDataMem - (base : UInt256) (I : ExecutionEnv) (schemaPayload idx : UInt256) - (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray base).write 0 - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat 32 - -abbrev attesterMultiRevokePostCopyDataAw - (_base : UInt256) (I : ExecutionEnv) (schemaPayload idx : UInt256) - (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M - (attesterMultiRevokePostCopySchemaAw I schemaPayload idx mem aw).toNat - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat 32) - -abbrev attesterMultiRevokePostCopyOuterArrayAwAfterMload - (outerBase : UInt256) (I : ExecutionEnv) (schemaPayload idx : UInt256) - (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMloadAw - (attesterMultiRevokePostCopyDataAw outerBase I schemaPayload idx mem aw) outerBase - -abbrev attesterMultiRevokePostCopyOuterSlotWord - (outerBase idx : UInt256) : UInt256 := - ((⟨32⟩ : UInt256) + UInt256.mul (⟨32⟩ : UInt256) idx) + outerBase - -abbrev attesterMultiRevokePostCopyOuterMem - (base outerBase : UInt256) (I : ExecutionEnv) (schemaPayload idx : UInt256) - (mem : ByteArray) (aw : UInt256) : ByteArray := - (UInt256.toByteArray (attesterMultiRevokePostCopyFreeWord mem aw)).write 0 - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat 32 - -abbrev attesterMultiRevokePostCopyOuterAw - (_base outerBase : UInt256) (I : ExecutionEnv) (schemaPayload idx : UInt256) - (mem : ByteArray) (aw : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M - (attesterMultiRevokePostCopyOuterArrayAwAfterMload outerBase I schemaPayload idx mem aw).toNat - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat 32) - -abbrev attesterMultiRevokePostCopyNextIdx (idx : UInt256) : UInt256 := - (⟨1⟩ : UInt256) + idx - -theorem attesterMultiRevokePostCopyOuterSlotWord_toNat - {outerBase idx : UInt256} - (hbound : outerBase.toNat + 32 + 32 * idx.toNat < UInt256.size) : - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat = - outerBase.toNat + 32 + 32 * idx.toNat := by - unfold attesterMultiRevokePostCopyOuterSlotWord - have hmul : - (UInt256.mul (⟨32⟩ : UInt256) idx).toNat = 32 * idx.toNat := by - rw [u256_mul_toNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - exact Nat.mod_eq_of_lt (by omega) - have hinner : - (((⟨32⟩ : UInt256) + UInt256.mul (⟨32⟩ : UInt256) idx).toNat) = - 32 + 32 * idx.toNat := by - rw [uadd_toNat, hmul] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - exact Nat.mod_eq_of_lt (by omega) - rw [uadd_toNat, hinner] - rw [show 32 + 32 * idx.toNat + outerBase.toNat = - outerBase.toNat + 32 + 32 * idx.toNat by omega] - exact Nat.mod_eq_of_lt hbound - -theorem attesterMultiRevokePostCopyDataMem_readOuter_and_size - {base outerBase len schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : outerBase.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding outerBase.toNat 32 = UInt256.toByteArray len) - (houter64 : 64 + 32 ≤ outerBase.toNat) - (hbase : outerBase.toNat + 32 ≤ base.toNat) - (hfree : base.toNat + 32 ≤ (attesterMultiRevokePostCopyFreeWord mem aw).toNat) - (hfree96 : - (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 96 < UInt256.size) : - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray len ∧ - outerBase.toNat + 32 ≤ - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).size := by - let free := attesterMultiRevokePostCopyFreeWord mem aw - let dataOff := attesterMultiRevokePostCopyDataOffsetWord mem aw - have hfreeGe : base.toNat + 32 ≤ free.toNat := by - simpa [free] using hfree - have hfree32 : free.toNat + 32 < UInt256.size := by - have hfree96' : free.toNat + 96 < UInt256.size := by - simpa [free] using hfree96 - omega - have hdataToNat : dataOff.toNat = free.toNat + 32 := by - unfold dataOff attesterMultiRevokePostCopyDataOffsetWord - exact uadd_lit32_toNat free hfree32 - have hread1 : - (attesterMultiRevokePostCopyFreeMem mem aw).readWithPadding outerBase.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokePostCopyFreeBumpWord mem aw)).readWithPadding - outerBase.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := mem) (base := outerBase.toNat) (writeOff := 64) - (len := len) (writeVal := attesterMultiRevokePostCopyFreeBumpWord mem aw) - hmem houter64 hread - have hmem1 : - outerBase.toNat + 32 ≤ (attesterMultiRevokePostCopyFreeMem mem aw).size := by - change outerBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokePostCopyFreeBumpWord mem aw)).size - exact le_trans hmem - (attesterWriteWord_size_ge_nat mem 64 - (attesterMultiRevokePostCopyFreeBumpWord mem aw)) - have hread2 : - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyFreeMem mem aw) - (attesterMultiRevokePostCopyFreeWord mem aw).toNat - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)).readWithPadding - outerBase.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopyFreeMem mem aw) - (base := outerBase.toNat) - (writeOff := (attesterMultiRevokePostCopyFreeWord mem aw).toNat) - (len := len) (writeVal := attesterMultiRevokePostCopySchemaWord I schemaPayload idx) - hmem1 (by simpa [free] using (by omega : outerBase.toNat + 32 ≤ free.toNat)) - hread1 - have hmem2 : - outerBase.toNat + 32 ≤ - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw).size := by - change outerBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyFreeMem mem aw) - (attesterMultiRevokePostCopyFreeWord mem aw).toNat - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)).size - exact le_trans hmem1 - (attesterWriteWord_size_ge_nat - (attesterMultiRevokePostCopyFreeMem mem aw) - (attesterMultiRevokePostCopyFreeWord mem aw).toNat - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)) - have hread3 : - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base).readWithPadding - outerBase.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (base := outerBase.toNat) - (writeOff := (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat) - (len := len) (writeVal := base) - hmem2 (by rw [hdataToNat]; omega) hread2 - have hmem3 : - outerBase.toNat + 32 ≤ - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).size := by - change outerBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base).size - exact le_trans hmem2 - (attesterWriteWord_size_ge_nat - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base) - exact ⟨hread3, hmem3⟩ - -theorem attesterMultiRevokePostCopyOuterMem_readOuter_and_size - {base outerBase len schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : outerBase.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding outerBase.toNat 32 = UInt256.toByteArray len) - (houter64 : 64 + 32 ≤ outerBase.toNat) - (hbase : outerBase.toNat + 32 ≤ base.toNat) - (hfree : base.toNat + 32 ≤ (attesterMultiRevokePostCopyFreeWord mem aw).toNat) - (hfree96 : - (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 96 < UInt256.size) - (hslotBound : outerBase.toNat + 32 + 32 * idx.toNat < UInt256.size) : - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray len ∧ - outerBase.toNat + 32 ≤ - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).size := by - obtain ⟨hreadData, hmemData⟩ := - attesterMultiRevokePostCopyDataMem_readOuter_and_size - (base := base) (outerBase := outerBase) (len := len) - (schemaPayload := schemaPayload) (idx := idx) (mem := mem) (aw := aw) - hmem hread houter64 hbase hfree hfree96 - have hslotToNat : - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat = - outerBase.toNat + 32 + 32 * idx.toNat := - attesterMultiRevokePostCopyOuterSlotWord_toNat hslotBound - have hreadOuter : - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)).readWithPadding - outerBase.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (base := outerBase.toNat) - (writeOff := (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat) - (len := len) (writeVal := attesterMultiRevokePostCopyFreeWord mem aw) - hmemData (by rw [hslotToNat]; omega) hreadData - have hmemOuter : - outerBase.toNat + 32 ≤ - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).size := by - change outerBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)).size - exact le_trans hmemData - (attesterWriteWord_size_ge_nat - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)) - exact ⟨hreadOuter, hmemOuter⟩ - -theorem attesterMultiRevokePostCopyDataMem_mloadOuter - {base outerBase len schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : outerBase.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding outerBase.toNat 32 = UInt256.toByteArray len) - (hawMul : aw.toNat * 32 < UInt256.size) - (houter64 : 64 + 32 ≤ outerBase.toNat) - (hbase : outerBase.toNat + 32 ≤ base.toNat) - (hfree : base.toNat + 32 ≤ (attesterMultiRevokePostCopyFreeWord mem aw).toNat) - (hfree96 : - (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 96 < UInt256.size) : - attesterMloadWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataAw base I schemaPayload idx mem aw) - outerBase = len := by - let free := attesterMultiRevokePostCopyFreeWord mem aw - let dataOff := attesterMultiRevokePostCopyDataOffsetWord mem aw - have hfreeGe : base.toNat + 32 ≤ free.toNat := by - simpa [free] using hfree - have hfree96' : free.toNat + 96 < UInt256.size := by - simpa [free] using hfree96 - have hfree32 : free.toNat + 32 < UInt256.size := by - omega - have hfree63 : free.toNat + 63 < UInt256.size := by - omega - have hdataToNat : dataOff.toNat = free.toNat + 32 := by - unfold dataOff attesterMultiRevokePostCopyDataOffsetWord - exact uadd_lit32_toNat free hfree32 - have hdata63 : dataOff.toNat + 63 < UInt256.size := by - rw [hdataToNat] - omega - have hread1 : - (attesterMultiRevokePostCopyFreeMem mem aw).readWithPadding outerBase.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokePostCopyFreeBumpWord mem aw)).readWithPadding - outerBase.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := mem) (base := outerBase.toNat) (writeOff := 64) - (len := len) (writeVal := attesterMultiRevokePostCopyFreeBumpWord mem aw) - hmem houter64 hread - have hmem1 : - outerBase.toNat + 32 ≤ (attesterMultiRevokePostCopyFreeMem mem aw).size := by - change outerBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokePostCopyFreeBumpWord mem aw)).size - exact le_trans hmem - (attesterWriteWord_size_ge_nat mem 64 - (attesterMultiRevokePostCopyFreeBumpWord mem aw)) - have hread2 : - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyFreeMem mem aw) - (attesterMultiRevokePostCopyFreeWord mem aw).toNat - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)).readWithPadding - outerBase.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopyFreeMem mem aw) - (base := outerBase.toNat) - (writeOff := (attesterMultiRevokePostCopyFreeWord mem aw).toNat) - (len := len) (writeVal := attesterMultiRevokePostCopySchemaWord I schemaPayload idx) - hmem1 (by simpa [free] using (by omega : outerBase.toNat + 32 ≤ free.toNat)) hread1 - have hmem2 : - outerBase.toNat + 32 ≤ - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw).size := by - change outerBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyFreeMem mem aw) - (attesterMultiRevokePostCopyFreeWord mem aw).toNat - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)).size - exact le_trans hmem1 - (attesterWriteWord_size_ge_nat - (attesterMultiRevokePostCopyFreeMem mem aw) - (attesterMultiRevokePostCopyFreeWord mem aw).toNat - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)) - have hread3 : - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).readWithPadding - outerBase.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base).readWithPadding - outerBase.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (base := outerBase.toNat) - (writeOff := (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat) - (len := len) (writeVal := base) - hmem2 (by rw [hdataToNat]; omega) hread2 - have hmem3 : - outerBase.toNat + 32 ≤ - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).size := by - change outerBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base).size - exact le_trans hmem2 - (attesterWriteWord_size_ge_nat - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base) - let aw1 := attesterMultiRevokePostCopyAwAfterMload aw - let aw2 := attesterMultiRevokePostCopyFreeAw mem aw - let aw3 := attesterMultiRevokePostCopySchemaAw I schemaPayload idx mem aw - let aw4 := attesterMultiRevokePostCopyDataAw base I schemaPayload idx mem aw - have hM1 : MachineState.M aw.toNat 64 32 < UInt256.size := - attesterMachineStateM32_lt hawMul (by norm_num [UInt256.size]) - have haw1ToNat : aw1.toNat = MachineState.M aw.toNat 64 32 := by - unfold aw1 attesterMultiRevokePostCopyAwAfterMload attesterMloadAw - rw [show (⟨64⟩ : UInt256).toNat = 64 by decide] - exact ulit_toNat' _ hM1 - have haw1Mul : aw1.toNat * 32 < UInt256.size := by - rw [haw1ToNat] - exact attesterMachineStateM32_mul32_lt hawMul (by norm_num [UInt256.size]) - have hM2 : MachineState.M aw1.toNat 64 32 < UInt256.size := - attesterMachineStateM32_lt haw1Mul (by norm_num [UInt256.size]) - have haw2ToNat : aw2.toNat = MachineState.M aw1.toNat 64 32 := by - unfold aw2 attesterMultiRevokePostCopyFreeAw - change (UInt256.ofNat (MachineState.M aw1.toNat 64 32)).toNat = - MachineState.M aw1.toNat 64 32 - exact ulit_toNat' _ hM2 - have haw2Mul : aw2.toNat * 32 < UInt256.size := by - rw [haw2ToNat] - exact attesterMachineStateM32_mul32_lt haw1Mul (by norm_num [UInt256.size]) - have hM3 : MachineState.M aw2.toNat free.toNat 32 < UInt256.size := - attesterMachineStateM32_lt haw2Mul hfree63 - have haw3ToNat : aw3.toNat = MachineState.M aw2.toNat free.toNat 32 := by - unfold aw3 attesterMultiRevokePostCopySchemaAw - change (UInt256.ofNat (MachineState.M aw2.toNat free.toNat 32)).toNat = - MachineState.M aw2.toNat free.toNat 32 - exact ulit_toNat' _ hM3 - have haw3Mul : aw3.toNat * 32 < UInt256.size := by - rw [haw3ToNat] - exact attesterMachineStateM32_mul32_lt haw2Mul hfree63 - have hM4 : MachineState.M aw3.toNat dataOff.toNat 32 < UInt256.size := - attesterMachineStateM32_lt haw3Mul hdata63 - have haw4ToNat : aw4.toNat = MachineState.M aw3.toNat dataOff.toNat 32 := by - unfold aw4 attesterMultiRevokePostCopyDataAw - change (UInt256.ofNat (MachineState.M aw3.toNat dataOff.toNat 32)).toNat = - MachineState.M aw3.toNat dataOff.toNat 32 - exact ulit_toNat' _ hM4 - have haw4Mul : aw4.toNat * 32 < UInt256.size := by - rw [haw4ToNat] - exact attesterMachineStateM32_mul32_lt haw3Mul hdata63 - have hdataCovered : dataOff.toNat + 32 ≤ aw4.toNat * 32 := by - have hcover := attesterMachineStateM_covers_word32 aw3.toNat dataOff.toNat - rw [haw4ToNat] - nlinarith - have houterCovered : outerBase.toNat + 32 ≤ aw4.toNat * 32 := by - exact le_trans (by rw [hdataToNat]; omega) hdataCovered - have haw : - ¬ outerBase ≥ - (attesterMultiRevokePostCopyDataAw base I schemaPayload idx mem aw) * - (⟨32⟩ : UInt256) := by - exact attesterMloadActiveWordsCovers - (base := outerBase) - (aw := attesterMultiRevokePostCopyDataAw base I schemaPayload idx mem aw) - (by simpa [aw4] using haw4Mul) - (by simpa [aw4] using houterCovered) - exact attesterMloadWord_of_readWithPadding hmem3 haw hread3 - -theorem attesterMultiRevokePostCopyOuterMem_read64 - {base outerBase schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hfree : 64 + 32 ≤ (attesterMultiRevokePostCopyFreeWord mem aw).toNat) - (hdata : 64 + 32 ≤ (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat) - (hslot : 64 + 32 ≤ (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat) : - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).readWithPadding - 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw) := by - have hread1 : - (attesterMultiRevokePostCopyFreeMem mem aw).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw) := by - change (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw)).readWithPadding - 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw) - exact attesterWriteWord_read_back_nat mem 64 - ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw) - have hmem1 : 64 + 32 ≤ (attesterMultiRevokePostCopyFreeMem mem aw).size := by - have hsize := attesterWriteWord_size_nat mem 64 - ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw) - change 64 + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw)).size - rw [hsize] - change 96 ≤ max mem.size (64 + 32) - exact Nat.le_max_right _ _ - have hread2 : - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw).readWithPadding - 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw) := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyFreeMem mem aw) - (attesterMultiRevokePostCopyFreeWord mem aw).toNat - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)).readWithPadding - 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopyFreeMem mem aw) - (base := 64) - (writeOff := (attesterMultiRevokePostCopyFreeWord mem aw).toNat) - (len := ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw)) - (writeVal := attesterMultiRevokePostCopySchemaWord I schemaPayload idx) - hmem1 hfree hread1 - have hmem2 : - 64 + 32 ≤ (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw).size := by - have hsize := attesterWriteWord_size_nat (attesterMultiRevokePostCopyFreeMem mem aw) - (attesterMultiRevokePostCopyFreeWord mem aw).toNat - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx) - change 64 + 32 ≤ - (Reasoning.Theory.writeWord (attesterMultiRevokePostCopyFreeMem mem aw) - (attesterMultiRevokePostCopyFreeWord mem aw).toNat - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)).size - rw [hsize] - exact le_trans hmem1 (Nat.le_max_left _ _) - have hread3 : - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).readWithPadding - 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw) := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base).readWithPadding - 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (base := 64) - (writeOff := (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat) - (len := ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw)) - (writeVal := base) - hmem2 hdata hread2 - have hmem3 : - 64 + 32 ≤ (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).size := by - have hsize := attesterWriteWord_size_nat - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base - change 64 + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base).size - rw [hsize] - exact le_trans hmem2 (Nat.le_max_left _ _) - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (base := 64) - (writeOff := (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat) - (len := ((⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw)) - (writeVal := attesterMultiRevokePostCopyFreeWord mem aw) - hmem3 hslot hread3 - -theorem attesterMultiRevokePostCopyOuterAw_bounds - {base outerBase schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hawGe : 3 ≤ aw.toNat) - (hawMul : aw.toNat * 32 < UInt256.size) - (hfree95 : (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 95 < UInt256.size) - (houter63 : outerBase.toNat + 63 < UInt256.size) - (hslot63 : (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat + 63 < - UInt256.size) : - 3 ≤ (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx mem aw).toNat ∧ - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx mem aw).toNat * - 32 < UInt256.size := by - let free := attesterMultiRevokePostCopyFreeWord mem aw - let dataOff := attesterMultiRevokePostCopyDataOffsetWord mem aw - let aw1 := attesterMultiRevokePostCopyAwAfterMload aw - let aw2 := attesterMultiRevokePostCopyFreeAw mem aw - let aw3 := attesterMultiRevokePostCopySchemaAw I schemaPayload idx mem aw - let aw4 := attesterMultiRevokePostCopyDataAw base I schemaPayload idx mem aw - let aw5 := attesterMultiRevokePostCopyOuterArrayAwAfterMload - outerBase I schemaPayload idx mem aw - let slot := attesterMultiRevokePostCopyOuterSlotWord outerBase idx - have hfree63 : free.toNat + 63 < UInt256.size := by - simpa [free] using (by - have h := hfree95 - omega) - have hfree32 : free.toNat + 32 < UInt256.size := by - simpa [free] using (by - have h := hfree95 - omega) - have hdataToNat : dataOff.toNat = free.toNat + 32 := by - unfold dataOff attesterMultiRevokePostCopyDataOffsetWord - exact uadd_lit32_toNat free hfree32 - have hdata63 : dataOff.toNat + 63 < UInt256.size := by - rw [hdataToNat] - simpa [free] using hfree95 - have hM1 : MachineState.M aw.toNat 64 32 < UInt256.size := - attesterMachineStateM32_lt hawMul (by norm_num [UInt256.size]) - have hM1Mul : MachineState.M aw.toNat 64 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt hawMul (by norm_num [UInt256.size]) - have haw1Ge : 3 ≤ aw1.toNat := by - unfold aw1 attesterMultiRevokePostCopyAwAfterMload attesterMloadAw - rw [show (⟨64⟩ : UInt256).toNat = 64 by decide] - rw [ulit_toNat' _ hM1] - exact le_trans hawGe (attesterMachineStateM_ge aw.toNat 64 32) - have haw1Mul : aw1.toNat * 32 < UInt256.size := by - unfold aw1 attesterMultiRevokePostCopyAwAfterMload attesterMloadAw - rw [show (⟨64⟩ : UInt256).toNat = 64 by decide] - rw [ulit_toNat' _ hM1] - exact hM1Mul - have hM2 : MachineState.M aw1.toNat 64 32 < UInt256.size := - attesterMachineStateM32_lt haw1Mul (by norm_num [UInt256.size]) - have hM2Mul : MachineState.M aw1.toNat 64 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt haw1Mul (by norm_num [UInt256.size]) - have haw2Ge : 3 ≤ aw2.toNat := by - unfold aw2 attesterMultiRevokePostCopyFreeAw - rw [ulit_toNat' _ hM2] - exact le_trans haw1Ge (attesterMachineStateM_ge aw1.toNat 64 32) - have haw2Mul : aw2.toNat * 32 < UInt256.size := by - unfold aw2 attesterMultiRevokePostCopyFreeAw - rw [ulit_toNat' _ hM2] - exact hM2Mul - have hM3 : MachineState.M aw2.toNat free.toNat 32 < UInt256.size := - attesterMachineStateM32_lt haw2Mul hfree63 - have hM3Mul : MachineState.M aw2.toNat free.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt haw2Mul hfree63 - have haw3Ge : 3 ≤ aw3.toNat := by - unfold aw3 attesterMultiRevokePostCopySchemaAw - rw [ulit_toNat' _ hM3] - exact le_trans haw2Ge - (attesterMachineStateM_ge - (attesterMultiRevokePostCopyFreeAw mem aw).toNat - (attesterMultiRevokePostCopyFreeWord mem aw).toNat 32) - have haw3Mul : aw3.toNat * 32 < UInt256.size := by - unfold aw3 attesterMultiRevokePostCopySchemaAw - rw [ulit_toNat' _ hM3] - exact hM3Mul - have hM4 : MachineState.M aw3.toNat dataOff.toNat 32 < UInt256.size := - attesterMachineStateM32_lt haw3Mul hdata63 - have hM4Mul : MachineState.M aw3.toNat dataOff.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt haw3Mul hdata63 - have haw4Ge : 3 ≤ aw4.toNat := by - unfold aw4 attesterMultiRevokePostCopyDataAw - rw [ulit_toNat' _ hM4] - exact le_trans haw3Ge - (attesterMachineStateM_ge - (attesterMultiRevokePostCopySchemaAw I schemaPayload idx mem aw).toNat - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat 32) - have haw4Mul : aw4.toNat * 32 < UInt256.size := by - unfold aw4 attesterMultiRevokePostCopyDataAw - rw [ulit_toNat' _ hM4] - exact hM4Mul - have hM5 : MachineState.M aw4.toNat outerBase.toNat 32 < UInt256.size := - attesterMachineStateM32_lt haw4Mul houter63 - have hM5Mul : MachineState.M aw4.toNat outerBase.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt haw4Mul houter63 - have haw5Ge : 3 ≤ aw5.toNat := by - unfold aw5 attesterMultiRevokePostCopyOuterArrayAwAfterMload attesterMloadAw - rw [ulit_toNat' _ hM5] - exact le_trans haw4Ge - (attesterMachineStateM_ge - (attesterMultiRevokePostCopyDataAw base I schemaPayload idx mem aw).toNat - outerBase.toNat 32) - have haw5Mul : aw5.toNat * 32 < UInt256.size := by - unfold aw5 attesterMultiRevokePostCopyOuterArrayAwAfterMload attesterMloadAw - rw [ulit_toNat' _ hM5] - exact hM5Mul - have hM6 : MachineState.M aw5.toNat slot.toNat 32 < UInt256.size := - attesterMachineStateM32_lt haw5Mul (by simpa [slot] using hslot63) - have hM6Mul : MachineState.M aw5.toNat slot.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt haw5Mul (by simpa [slot] using hslot63) - constructor - · unfold attesterMultiRevokePostCopyOuterAw - rw [ulit_toNat' _ hM6] - exact le_trans haw5Ge - (attesterMachineStateM_ge - (attesterMultiRevokePostCopyOuterArrayAwAfterMload - outerBase I schemaPayload idx mem aw).toNat - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat 32) - · unfold attesterMultiRevokePostCopyOuterAw - rw [ulit_toNat' _ hM6] - exact hM6Mul - -theorem attesterMultiRevokePostCopyOuterMem_mload64 - {base outerBase schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hfree : 64 + 32 ≤ (attesterMultiRevokePostCopyFreeWord mem aw).toNat) - (hdata : 64 + 32 ≤ (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat) - (hslot : 64 + 32 ≤ (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat) - (haw : - ¬ (⟨64⟩ : UInt256) ≥ - attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx mem aw * - (⟨32⟩ : UInt256)) : - attesterInnerArrayAllocFreeWord - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx mem aw) = - (⟨64⟩ : UInt256) + attesterMultiRevokePostCopyFreeWord mem aw := by - have hread := attesterMultiRevokePostCopyOuterMem_read64 - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := mem) (aw := aw) - hfree hdata hslot - have hmem : (⟨64⟩ : UInt256).toNat + 32 ≤ - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).size := by - have hsize := attesterWriteWord_size_nat - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw) - change (⟨64⟩ : UInt256).toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)).size - rw [hsize] - change 96 ≤ max - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).size - ((attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat + 32) - exact le_trans (by omega) (Nat.le_max_right _ _) - exact attesterMloadWord_of_readWithPadding hmem haw hread - -theorem attesterMultiRevokePostCopyOuterMem_freeWord_toNat - {base outerBase schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hfree : 64 + 32 ≤ (attesterMultiRevokePostCopyFreeWord mem aw).toNat) - (hdata : 64 + 32 ≤ (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat) - (hslot : 64 + 32 ≤ (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat) - (hawMul : - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx mem aw).toNat * - 32 < UInt256.size) - (hawGe : - 3 ≤ (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx mem aw).toNat) - (hfreeBound : (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 64 < UInt256.size) : - (attesterInnerArrayAllocFreeWord - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx mem aw)).toNat = - (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 64 := by - rw [attesterMultiRevokePostCopyOuterMem_mload64 - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := mem) (aw := aw) - hfree hdata hslot (attesterMload64ActiveWordsGe3 hawMul hawGe)] - exact attester_uadd_lit64_toNat (attesterMultiRevokePostCopyFreeWord mem aw) hfreeBound - -abbrev attesterMultiRevokeInnerArrayHeadWord - (payload idx : UInt256) : UInt256 := - payload + UInt256.mul (⟨32⟩ : UInt256) idx - -abbrev attesterMultiRevokeInnerArrayOffsetWord - (I : ExecutionEnv) (head : UInt256) : UInt256 := - calldataWord I.calldata head.toNat - -abbrev attesterMultiRevokeInnerArrayStartWord - (I : ExecutionEnv) (base head : UInt256) : UInt256 := - base + attesterMultiRevokeInnerArrayOffsetWord I head - -abbrev attesterMultiRevokeInnerArrayLengthWord - (I : ExecutionEnv) (base head : UInt256) : UInt256 := - calldataWord I.calldata - (attesterMultiRevokeInnerArrayStartWord I base head).toNat - -abbrev attesterMultiRevokeInnerArrayPayloadWord - (I : ExecutionEnv) (base head : UInt256) : UInt256 := - attesterMultiRevokeInnerArrayStartWord I base head + ⟨32⟩ - -private theorem attester_inner_start_add32_comm - (I : ExecutionEnv) (base head : UInt256) : - (⟨32⟩ : UInt256) + attesterMultiRevokeInnerArrayStartWord I base head = - attesterMultiRevokeInnerArrayStartWord I base head + ⟨32⟩ := by - exact u256_add_comm _ _ - -private theorem attester_pc363_after_inner_setup_at : - ((((((((((((⟨363⟩ : UInt256) + ⟨1⟩) + ⟨1⟩) + ⟨1⟩) + - UInt256.ofNat 2) + ⟨1⟩) + ⟨1⟩) + ⟨1⟩) + ⟨1⟩) + - UInt256.ofNat 3) + ⟨1⟩) + ⟨1⟩) + UInt256.ofNat 3 = - (⟨380⟩ : UInt256) := by - native_decide - -theorem attesterMultiRevokePostCopySchemaOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨638⟩ : UInt256) = true := by - let A := attesterBytecode.extract 0 722 - let B := (patchedRuntime v).extract 722 (patchedRuntime v).size - have hprefix : (patchedRuntime v).extract 0 722 = A := by - unfold A - rw [patchedRuntime_extract_preserved_len v 0 722 - (by simp [runtimeWrites, WindowDisjointFromWrites]) - (by norm_num) - (by norm_num) - (by norm_num)] - have hsplit : patchedRuntime v = A ++ B := by - unfold B - have h := ByteArray.extract_append_extract (a := patchedRuntime v) - (i := 0) (j := 722) (k := (patchedRuntime v).size) - rw [← hprefix] - have hsize : 722 ≤ (patchedRuntime v).size := by - rw [patchedRuntime_size v] - norm_num - have hmax : max 722 (patchedRuntime v).size = (patchedRuntime v).size := - Nat.max_eq_right hsize - have hmin : min 0 722 = 0 := by omega - simpa [hmin, hmax, ByteArray.extract_zero_size] using h.symm - rw [hsplit] - apply Reasoning.Theory.D_J_contains_append_left - unfold A - native_decide - -theorem attesterMultiRevokeOuterSourceLoopJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨335⟩ : UInt256) = true := by - let A := attesterBytecode.extract 0 722 - let B := (patchedRuntime v).extract 722 (patchedRuntime v).size - have hprefix : (patchedRuntime v).extract 0 722 = A := by - unfold A - rw [patchedRuntime_extract_preserved_len v 0 722 - (by simp [runtimeWrites, WindowDisjointFromWrites]) - (by norm_num) - (by norm_num) - (by norm_num)] - have hsplit : patchedRuntime v = A ++ B := by - unfold B - have h := ByteArray.extract_append_extract (a := patchedRuntime v) - (i := 0) (j := 722) (k := (patchedRuntime v).size) - rw [← hprefix] - have hsize : 722 ≤ (patchedRuntime v).size := by - rw [patchedRuntime_size v] - norm_num - have hmax : max 722 (patchedRuntime v).size = (patchedRuntime v).size := - Nat.max_eq_right hsize - have hmin : min 0 722 = 0 := by omega - simpa [hmin, hmax, ByteArray.extract_zero_size] using h.symm - rw [hsplit] - apply Reasoning.Theory.D_J_contains_append_left - unfold A - native_decide - -theorem attesterMultiRevokePostCopyOuterStoreOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨672⟩ : UInt256) = true := by - let A := attesterBytecode.extract 0 722 - let B := (patchedRuntime v).extract 722 (patchedRuntime v).size - have hprefix : (patchedRuntime v).extract 0 722 = A := by - unfold A - rw [patchedRuntime_extract_preserved_len v 0 722 - (by simp [runtimeWrites, WindowDisjointFromWrites]) - (by norm_num) - (by norm_num) - (by norm_num)] - have hsplit : patchedRuntime v = A ++ B := by - unfold B - have h := ByteArray.extract_append_extract (a := patchedRuntime v) - (i := 0) (j := 722) (k := (patchedRuntime v).size) - rw [← hprefix] - have hsize : 722 ≤ (patchedRuntime v).size := by - rw [patchedRuntime_size v] - norm_num - have hmax : max 722 (patchedRuntime v).size = (patchedRuntime v).size := - Nat.max_eq_right hsize - have hmin : min 0 722 = 0 := by omega - simpa [hmin, hmax, ByteArray.extract_zero_size] using h.symm - rw [hsplit] - apply Reasoning.Theory.D_J_contains_append_left - unfold A - native_decide - -theorem attesterMultiRevokeExternalCallEntryJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨698⟩ : UInt256) = true := by - let A := attesterBytecode.extract 0 722 - let B := (patchedRuntime v).extract 722 (patchedRuntime v).size - have hprefix : (patchedRuntime v).extract 0 722 = A := by - unfold A - rw [patchedRuntime_extract_preserved_len v 0 722 - (by simp [runtimeWrites, WindowDisjointFromWrites]) - (by norm_num) - (by norm_num) - (by norm_num)] - have hsplit : patchedRuntime v = A ++ B := by - unfold B - have h := ByteArray.extract_append_extract (a := patchedRuntime v) - (i := 0) (j := 722) (k := (patchedRuntime v).size) - rw [← hprefix] - have hsize : 722 ≤ (patchedRuntime v).size := by - rw [patchedRuntime_size v] - norm_num - have hmax : max 722 (patchedRuntime v).size = (patchedRuntime v).size := - Nat.max_eq_right hsize - have hmin : min 0 722 = 0 := by omega - simpa [hmin, hmax, ByteArray.extract_zero_size] using h.symm - rw [hsplit] - apply Reasoning.Theory.D_J_contains_append_left - unfold A - native_decide - -theorem attesterX_multiRevokeOuterSourceLoopExit - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx outerBase schemaLen secondLen secondPayload schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hge : UInt256.lt idx schemaLen = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, schemaPayload, - ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨698⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, schemaPayload, - ret, selector] - mem aw ByteArray.empty (cA, σ) k' C' := by - have hcond : UInt256.isZero (UInt256.lt idx schemaLen) ≠ ⟨0⟩ := by - rw [hge] - decide - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨335⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨336⟩, 0x82, .DUP3) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨337⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨338⟩, 0x10, .LT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨339⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨698⟩ (by attester_decode_at v, ⟨340⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨343⟩, 0x57, .JUMPI) - hcond (attesterMultiRevokeExternalCallEntryJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeOuterSourceLoopGuard - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx outerBase schemaLen secondLen secondPayload schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hlt : UInt256.lt idx schemaLen = ⟨1⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, schemaPayload, - ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨344⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, schemaPayload, - ret, selector] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨335⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨336⟩, 0x82, .DUP3) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨337⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨338⟩, 0x10, .LT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨339⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨698⟩ (by attester_decode_at v, ⟨340⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨343⟩, 0x57, .JUMPI) - (by rw [hlt]; decide) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeOuterSecondArrayAccessCheckAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx outerBase schemaLen secondLen secondPayload schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hltSecond : UInt256.lt idx secondLen = ⟨1⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨344⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, schemaPayload, - ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨355⟩ : UInt256) - [⟨363⟩, ⟨1⟩, idx, secondLen, secondPayload, ⟨0⟩, - UInt256.ofNat I.calldata.size, idx, outerBase, schemaLen, secondLen, - secondPayload, schemaLen, schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, by - simpa [hltSecond] using - (evm_run hreach with [ - raw calldatasize (by attester_decode_at v, ⟨344⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨345⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨346⟩, 0x86, .DUP7) (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨347⟩, 0x86, .DUP7) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨348⟩, 0x84, .DUP5) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨349⟩, 0x81, .DUP2) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨350⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨351⟩, 0x10, .LT) (by evm_ov), - raw push2 ⟨363⟩ (by attester_decode_at v, ⟨352⟩, 0x61, (.Push .PUSH2)) - (by evm_ov)])⟩ - -theorem attesterX_multiRevokeOuterSecondArrayAccessOkAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx outerBase schemaLen secondLen secondPayload schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hltSecond : UInt256.lt idx secondLen = ⟨1⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨344⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, schemaPayload, - ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨363⟩ : UInt256) - [idx, secondLen, secondPayload, ⟨0⟩, UInt256.ofNat I.calldata.size, - idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, - schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd0⟩ := - attesterX_multiRevokeOuterSecondArrayAccessCheckAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (outerBase := outerBase) (schemaLen := schemaLen) - (secondLen := secondLen) (secondPayload := secondPayload) - (schemaPayload := schemaPayload) (ret := ret) (selector := selector) - (mem := mem) (aw := aw) (k := k) (C := C) hltSecond hreach - exact ⟨_, _, evm_run rd0 with [ - raw jumpiT (by attester_decode_at v, ⟨355⟩, 0x57, .JUMPI) - (by decide) (attesterMultiRevokeOuterSourceElementOkJumpdest v) - (by evm_ov)]⟩ - -theorem attesterX_multiRevokeInnerArrayDecoderSetupAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx l p sz base len fp ret sel : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨363⟩ : UInt256) - [idx, l, p, ⟨0⟩, sz, idx, base, len, l, p, len, fp, ret, sel] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨380⟩ : UInt256) - [⟨2353⟩, p, attesterMultiRevokeInnerArrayHeadWord p idx, ⟨381⟩, - ⟨0⟩, sz, idx, base, len, l, p, len, fp, ret, sel] - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, by - simpa [attesterMultiRevokeInnerArrayHeadWord, attester_pc363_after_inner_setup_at] using - (evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨363⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨364⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨365⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨366⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mul (by attester_decode_at v, ⟨368⟩, 0x02, .MUL) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨369⟩, 0x81, .DUP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨370⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨371⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨381⟩ (by attester_decode_at v, ⟨372⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨375⟩, 0x91, .SWAP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨376⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨2353⟩ (by attester_decode_at v, ⟨377⟩, 0x61, (.Push .PUSH2)) (by evm_ov)])⟩ - -theorem attesterX_multiRevokeInnerArrayDecoderEntryAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx l p sz base len fp ret sel : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨363⟩ : UInt256) - [idx, l, p, ⟨0⟩, sz, idx, base, len, l, p, len, fp, ret, sel] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2353⟩ : UInt256) - [p, attesterMultiRevokeInnerArrayHeadWord p idx, ⟨381⟩, - ⟨0⟩, sz, idx, base, len, l, p, len, fp, ret, sel] - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd0⟩ := - attesterX_multiRevokeInnerArrayDecoderSetupAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (l := l) (p := p) (sz := sz) (base := base) - (len := len) (fp := fp) (ret := ret) (sel := sel) - (mem := mem) (aw := aw) (k := k) (C := C) hreach - exact ⟨_, _, evm_run rd0 with [ - raw jump (by attester_decode_at v, ⟨380⟩, 0x56, .JUMP) - (attesterInnerArrayDecoderJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeInnerArrayOffsetOkAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base head ret sz : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hslt : - UInt256.slt (attesterMultiRevokeInnerArrayOffsetWord I head) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) base) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2353⟩ : UInt256) - (base :: head :: ret :: ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2374⟩ : UInt256) - (attesterMultiRevokeInnerArrayOffsetWord I head :: ⟨0⟩ :: ⟨0⟩ :: - base :: head :: ret :: ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2353⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2354⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2355⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2356⟩, 0x83, .DUP4) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2357⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw push1 ⟨30⟩ (by attester_decode_at v, ⟨2358⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw not (by attester_decode_at v, ⟨2360⟩, 0x19, .NOT) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2361⟩, 0x84, .DUP5) (by evm_ov), - raw calldatasize (by attester_decode_at v, ⟨2362⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2363⟩, 0x03, .SUB) (by evm_ov), - raw add (by attester_decode_at v, ⟨2364⟩, 0x01, .ADD) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2365⟩, 0x81, .DUP2) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2366⟩, 0x12, .SLT) (by evm_ov), - raw push2 ⟨2374⟩ (by attester_decode_at v, ⟨2367⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2370⟩, 0x57, .JUMPI) - (by - change UInt256.slt (attesterMultiRevokeInnerArrayOffsetWord I head) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) base) - (UInt256.lnot (⟨30⟩ : UInt256))) ≠ ⟨0⟩ - rw [hslt] - decide) - (attesterInnerArrayOffsetOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeInnerArrayOffsetRevertsAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base head ret sz : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hslt : - UInt256.slt (attesterMultiRevokeInnerArrayOffsetWord I head) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) base) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2353⟩ : UInt256) - (base :: head :: ret :: ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - exact evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2353⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2354⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2355⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2356⟩, 0x83, .DUP4) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2357⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw push1 ⟨30⟩ (by attester_decode_at v, ⟨2358⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw not (by attester_decode_at v, ⟨2360⟩, 0x19, .NOT) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2361⟩, 0x84, .DUP5) (by evm_ov), - raw calldatasize (by attester_decode_at v, ⟨2362⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2363⟩, 0x03, .SUB) (by evm_ov), - raw add (by attester_decode_at v, ⟨2364⟩, 0x01, .ADD) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2365⟩, 0x81, .DUP2) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2366⟩, 0x12, .SLT) (by evm_ov), - raw push2 ⟨2374⟩ (by attester_decode_at v, ⟨2367⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2370⟩, 0x57, .JUMPI) - (by - change UInt256.slt (attesterMultiRevokeInnerArrayOffsetWord I head) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) base) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨0⟩ - rw [hslt]) - (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2371⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2372⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2373⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_multiRevokeInnerArrayLengthMaxOkAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base head ret sz : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hgt : - UInt256.gt (attesterMultiRevokeInnerArrayLengthWord I base head) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2374⟩ : UInt256) - (attesterMultiRevokeInnerArrayOffsetWord I head :: ⟨0⟩ :: ⟨0⟩ :: - base :: head :: ret :: ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2399⟩ : UInt256) - (attesterMultiRevokeInnerArrayStartWord I base head :: - attesterMultiRevokeInnerArrayLengthWord I base head :: ⟨0⟩ :: - base :: head :: ret :: ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2374⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2375⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2376⟩, 0x01, .ADD) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2377⟩, 0x80, .DUP1) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2378⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2379⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2380⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2381⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2383⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2385⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2387⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2388⟩, 0x03, .SUB) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2389⟩, 0x82, .DUP3) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2390⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2391⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2399⟩ (by attester_decode_at v, ⟨2392⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2395⟩, 0x57, .JUMPI) - (by - change UInt256.isZero - (UInt256.gt (attesterMultiRevokeInnerArrayLengthWord I base head) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) ≠ ⟨0⟩ - rw [hgt] - decide) - (attesterInnerArrayLengthOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeInnerArrayLengthMaxRevertsAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base head ret sz : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hgt : - UInt256.gt (attesterMultiRevokeInnerArrayLengthWord I base head) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨1⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2374⟩ : UInt256) - (attesterMultiRevokeInnerArrayOffsetWord I head :: ⟨0⟩ :: ⟨0⟩ :: - base :: head :: ret :: ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - exact evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2374⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2375⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2376⟩, 0x01, .ADD) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2377⟩, 0x80, .DUP1) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2378⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2379⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2380⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2381⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2383⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2385⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2387⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2388⟩, 0x03, .SUB) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2389⟩, 0x82, .DUP3) (by evm_ov), - raw gt (by attester_decode_at v, ⟨2390⟩, 0x11, .GT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2391⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2399⟩ (by attester_decode_at v, ⟨2392⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2395⟩, 0x57, .JUMPI) - (by - change UInt256.isZero - (UInt256.gt (attesterMultiRevokeInnerArrayLengthWord I base head) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩)) = ⟨0⟩ - rw [hgt] - decide) - (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2396⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2397⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2398⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeInnerArrayPayloadSetupAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base head ret sz : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2399⟩ : UInt256) - (attesterMultiRevokeInnerArrayStartWord I base head :: - attesterMultiRevokeInnerArrayLengthWord I base head :: ⟨0⟩ :: - base :: head :: ret :: ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2405⟩ : UInt256) - (attesterMultiRevokeInnerArrayLengthWord I base head :: - attesterMultiRevokeInnerArrayPayloadWord I base head :: - base :: head :: ret :: ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, by - simpa [attesterMultiRevokeInnerArrayPayloadWord, - attester_inner_start_add32_comm] using - (evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2399⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2400⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨2402⟩, 0x01, .ADD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2403⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2404⟩, 0x50, .POP) (by evm_ov)])⟩ - -theorem attesterX_multiRevokeInnerArrayPayloadGuardOkAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base head ret sz : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hsgt : - UInt256.sgt (attesterMultiRevokeInnerArrayPayloadWord I base head) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I base head) ⟨5⟩)) = ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2405⟩ : UInt256) - (attesterMultiRevokeInnerArrayLengthWord I base head :: - attesterMultiRevokeInnerArrayPayloadWord I base head :: - base :: head :: ret :: ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2102⟩ : UInt256) - (attesterMultiRevokeInnerArrayLengthWord I base head :: - attesterMultiRevokeInnerArrayPayloadWord I base head :: - base :: head :: ret :: ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw push1 ⟨5⟩ (by attester_decode_at v, ⟨2405⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2407⟩, 0x81, .DUP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2408⟩, 0x90, .SWAP1) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2409⟩, 0x1b, .SHL) (by evm_ov), - raw calldatasize (by attester_decode_at v, ⟨2410⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2411⟩, 0x03, .SUB) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2412⟩, 0x82, .DUP3) (by evm_ov), - raw sgt (by attester_decode_at v, ⟨2413⟩, 0x13, .SGT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2414⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2102⟩ (by attester_decode_at v, ⟨2415⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2418⟩, 0x57, .JUMPI) - (by - rw [hsgt] - decide) - (attesterDynamicArrayPayloadOkJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeInnerArrayPayloadGuardRevertsAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base head ret sz : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hsgt : - UInt256.sgt (attesterMultiRevokeInnerArrayPayloadWord I base head) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I base head) ⟨5⟩)) = ⟨1⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2405⟩ : UInt256) - (attesterMultiRevokeInnerArrayLengthWord I base head :: - attesterMultiRevokeInnerArrayPayloadWord I base head :: - base :: head :: ret :: ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - exact evm_run hreach with [ - raw push1 ⟨5⟩ (by attester_decode_at v, ⟨2405⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2407⟩, 0x81, .DUP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2408⟩, 0x90, .SWAP1) (by evm_ov), - raw shl (by attester_decode_at v, ⟨2409⟩, 0x1b, .SHL) (by evm_ov), - raw calldatasize (by attester_decode_at v, ⟨2410⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2411⟩, 0x03, .SUB) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2412⟩, 0x82, .DUP3) (by evm_ov), - raw sgt (by attester_decode_at v, ⟨2413⟩, 0x13, .SGT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2414⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2102⟩ (by attester_decode_at v, ⟨2415⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2418⟩, 0x57, .JUMPI) - (by - rw [hsgt] - decide) - (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2419⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2420⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2421⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_multiRevokeInnerArrayReturnAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base head ret sz : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hretJump : (D_J (patchedRuntime v) 0).contains ret = true) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2102⟩ : UInt256) - (attesterMultiRevokeInnerArrayLengthWord I base head :: - attesterMultiRevokeInnerArrayPayloadWord I base head :: - base :: head :: ret :: ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) ret - (attesterMultiRevokeInnerArrayLengthWord I base head :: - attesterMultiRevokeInnerArrayPayloadWord I base head :: - ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨2102⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2103⟩, 0x92, .SWAP3) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2104⟩, 0x50, .POP) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2105⟩, 0x92, .SWAP3) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2106⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2107⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨2108⟩, 0x56, .JUMP) - hretJump (by evm_ov)]⟩ - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeInnerArrayPayloadOkToReturnAt - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base head ret sz : UInt256} {tail : List UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (htail : tail.length ≤ 1000) - (hsgt : - UInt256.sgt (attesterMultiRevokeInnerArrayPayloadWord I base head) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft - (attesterMultiRevokeInnerArrayLengthWord I base head) ⟨5⟩)) = ⟨0⟩) - (hretJump : (D_J (patchedRuntime v) 0).contains ret = true) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2399⟩ : UInt256) - (attesterMultiRevokeInnerArrayStartWord I base head :: - attesterMultiRevokeInnerArrayLengthWord I base head :: ⟨0⟩ :: - base :: head :: ret :: ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) ret - (attesterMultiRevokeInnerArrayLengthWord I base head :: - attesterMultiRevokeInnerArrayPayloadWord I base head :: - ⟨0⟩ :: sz :: tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd2405⟩ := - attesterX_multiRevokeInnerArrayPayloadSetupAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := base) (head := head) (ret := ret) (sz := sz) - (tail := tail) (mem := mem) (aw := aw) (k := k) (C := C) - htail hreach - obtain ⟨k1, C1, rd2102⟩ := - attesterX_multiRevokeInnerArrayPayloadGuardOkAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := base) (head := head) (ret := ret) (sz := sz) - (tail := tail) (mem := mem) (aw := aw) (k := k0) (C := C0) - htail hsgt rd2405 - exact attesterX_multiRevokeInnerArrayReturnAt - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := base) (head := head) (ret := ret) (sz := sz) - (tail := tail) (mem := mem) (aw := aw) (k := k1) (C := C1) - htail hretJump rd2102 - -set_option maxHeartbeats 1500000 in -theorem attesterX_multiRevokePostInnerCopyToOuterLoop - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {innerIdx base innerLen payload idx outerBase schemaLen secondLen secondPayload - schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C} - (hidxSchema : UInt256.lt idx schemaLen = ⟨1⟩) - (hidxOuter : - UInt256.lt idx - (attesterMloadWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataAw base I schemaPayload idx mem aw) - outerBase) = ⟨1⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨608⟩ : UInt256) - [innerIdx, base, innerLen, innerLen, payload, idx, outerBase, schemaLen, - secondLen, secondPayload, schemaLen, schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [attesterMultiRevokePostCopyNextIdx idx, outerBase, schemaLen, - secondLen, secondPayload, schemaLen, schemaPayload, ret, selector] - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterMultiRevokePostCopyFreeWord mem aw - let aw1 := attesterMultiRevokePostCopyAwAfterMload aw - let bump := attesterMultiRevokePostCopyFreeBumpWord mem aw - let mem1 := attesterMultiRevokePostCopyFreeMem mem aw - let aw2 := attesterMultiRevokePostCopyFreeAw mem aw - let schemaOff := attesterMultiRevokePostCopySchemaCalldataOffset schemaPayload idx - let schema := attesterMultiRevokePostCopySchemaWord I schemaPayload idx - let mem2 := attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw - let aw3 := attesterMultiRevokePostCopySchemaAw I schemaPayload idx mem aw - let dataOff := attesterMultiRevokePostCopyDataOffsetWord mem aw - let mem3 := attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw - let aw4 := attesterMultiRevokePostCopyDataAw base I schemaPayload idx mem aw - let outerLen := attesterMloadWord mem3 aw4 outerBase - let aw5 := attesterMultiRevokePostCopyOuterArrayAwAfterMload - outerBase I schemaPayload idx mem aw - let slot := attesterMultiRevokePostCopyOuterSlotWord outerBase idx - let mem4 := attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw - let aw6 := attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx mem aw - have hcostMload64 : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - (⟨64⟩ : UInt256) :: base :: innerLen :: innerLen :: payload :: - idx :: outerBase :: schemaLen :: secondLen :: secondPayload :: - schemaLen :: schemaPayload :: ret :: selector :: [] → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreFree : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - (⟨64⟩ : UInt256) :: bump :: free :: base :: innerLen :: innerLen :: - payload :: idx :: outerBase :: schemaLen :: secondLen :: secondPayload :: - schemaLen :: schemaPayload :: ret :: selector :: [] → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSchema : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - free :: schema :: free :: free :: base :: innerLen :: innerLen :: - payload :: idx :: outerBase :: schemaLen :: secondLen :: secondPayload :: - schemaLen :: schemaPayload :: ret :: selector :: [] → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreData : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - dataOff :: base :: dataOff :: free :: base :: innerLen :: innerLen :: - payload :: idx :: outerBase :: schemaLen :: secondLen :: secondPayload :: - schemaLen :: schemaPayload :: ret :: selector :: [] → - memoryExpansionCost s .MSTORE = Cₘ aw4 - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostMloadOuter : - ∀ s : State, - s.machineState.activeWords = aw4 → - s.machineState.stack = - outerBase :: idx :: outerBase :: free :: base :: innerLen :: innerLen :: - payload :: idx :: outerBase :: schemaLen :: secondLen :: secondPayload :: - schemaLen :: schemaPayload :: ret :: selector :: [] → - memoryExpansionCost s .MLOAD = Cₘ aw5 - Cₘ aw4 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreOuter : - ∀ s : State, - s.machineState.activeWords = aw5 → - s.machineState.stack = - slot :: free :: free :: base :: innerLen :: innerLen :: payload :: - idx :: outerBase :: schemaLen :: secondLen :: secondPayload :: - schemaLen :: schemaPayload :: ret :: selector :: [] → - memoryExpansionCost s .MSTORE = Cₘ aw6 - Cₘ aw5 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - exact ⟨_, _, by - simpa [free, aw1, bump, mem1, aw2, schemaOff, schema, mem2, aw3, - dataOff, mem3, aw4, outerLen, aw5, slot, mem4, aw6, - attesterMultiRevokePostCopyNextIdx] using - evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨608⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨609⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨610⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨612⟩, 0x51, .MLOAD) - hcostMload64 (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨613⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨614⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨616⟩, 0x01, .ADD) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨617⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨619⟩, 0x52, .MSTORE) - hcostStoreFree (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨620⟩, 0x80, .DUP1) (by evm_ov), - raw dup13 (by attester_decode_at v, ⟨621⟩, 0x8c, .DUP13) (by evm_ov), - raw dup13 (by attester_decode_at v, ⟨622⟩, 0x8c, .DUP13) (by evm_ov), - raw dup9 (by attester_decode_at v, ⟨623⟩, 0x88, .DUP9) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨624⟩, 0x81, .DUP2) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨625⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨626⟩, 0x10, .LT) (by evm_ov), - raw push2 ⟨638⟩ (by attester_decode_at v, ⟨627⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨630⟩, 0x57, .JUMPI) - (by rw [hidxSchema]; decide) - (attesterMultiRevokePostCopySchemaOkJumpdest v) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨638⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨639⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨640⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨641⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mul (by attester_decode_at v, ⟨643⟩, 0x02, .MUL) (by evm_ov), - raw add (by attester_decode_at v, ⟨644⟩, 0x01, .ADD) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨645⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨646⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨647⟩, 0x52, .MSTORE) - hcostStoreSchema (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨648⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨650⟩, 0x01, .ADD) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨651⟩, 0x82, .DUP3) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨652⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw4 - Cₘ aw3) mem3 aw4 - (by attester_decode_at v, ⟨653⟩, 0x52, .MSTORE) - hcostStoreData (by rfl) (by rfl) (by evm_ov), - raw pop (by attester_decode_at v, ⟨654⟩, 0x50, .POP) (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨655⟩, 0x86, .DUP7) (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨656⟩, 0x86, .DUP7) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨657⟩, 0x81, .DUP2) (by evm_ov), - raw mload (Cₘ aw5 - Cₘ aw4) outerLen aw5 - (by attester_decode_at v, ⟨658⟩, 0x51, .MLOAD) - hcostMloadOuter (by rfl) (by rfl) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨659⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨660⟩, 0x10, .LT) (by evm_ov), - raw push2 ⟨672⟩ (by attester_decode_at v, ⟨661⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨664⟩, 0x57, .JUMPI) - (by rw [hidxOuter]; decide) - (attesterMultiRevokePostCopyOuterStoreOkJumpdest v) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨672⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨673⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mul (by attester_decode_at v, ⟨675⟩, 0x02, .MUL) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨676⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨678⟩, 0x01, .ADD) (by evm_ov), - raw add (by attester_decode_at v, ⟨679⟩, 0x01, .ADD) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨680⟩, 0x81, .DUP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨681⟩, 0x90, .SWAP1) (by evm_ov), - raw mstore (Cₘ aw6 - Cₘ aw5) mem4 aw6 - (by attester_decode_at v, ⟨682⟩, 0x52, .MSTORE) - hcostStoreOuter (by rfl) (by rfl) (by evm_ov), - raw pop (by attester_decode_at v, ⟨683⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨684⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨685⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨686⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨687⟩, 0x50, .POP) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨688⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨689⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨691⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨692⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨693⟩, 0x50, .POP) (by evm_ov), - raw push2 ⟨335⟩ (by attester_decode_at v, ⟨694⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨697⟩, 0x56, .JUMP) - (attesterMultiRevokeOuterSourceLoopJumpdest v) (by evm_ov)]⟩ - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/MultiRevokeEncoderABI.lean b/Benchmarks/EAS/Attester/MultiRevokeEncoderABI.lean deleted file mode 100644 index 2d3b8380..00000000 --- a/Benchmarks/EAS/Attester/MultiRevokeEncoderABI.lean +++ /dev/null @@ -1,1140 +0,0 @@ -import Benchmarks.EAS.Attester.MultiRevokeEncoderExact - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -def attesterWordBytesList (w : UInt256) : List UInt8 := - EVM.Word.toBytesBE w - -def attesterWordsBytesList : List UInt256 → List UInt8 - | [] => [] - | w :: rest => attesterWordBytesList w ++ attesterWordsBytesList rest - -theorem attesterNatBytes_eq_toBytesBE (n : Nat) : - ABI.natBytes n = EVM.Word.toBytesBE (UInt256.ofNat n) := rfl - -@[simp] theorem attesterWordsBytesList_nil : - attesterWordsBytesList [] = [] := rfl - -@[simp] theorem attesterWordsBytesList_cons (w : UInt256) (rest : List UInt256) : - attesterWordsBytesList (w :: rest) = - EVM.Word.toBytesBE w ++ attesterWordsBytesList rest := rfl - -theorem attesterWordsBytesList_append (xs ys : List UInt256) : - attesterWordsBytesList (xs ++ ys) = - attesterWordsBytesList xs ++ attesterWordsBytesList ys := by - induction xs with - | nil => - simp [attesterWordsBytesList] - | cons x xs ih => - simp [attesterWordBytesList, attesterWordsBytesList, ih, List.append_assoc] - -theorem attesterWordsBytesList_cons_toByteArray (w : UInt256) (rest : List UInt256) : - (attesterWordsBytesList (w :: rest)).toByteArray = - UInt256.toByteArray w ++ (attesterWordsBytesList rest).toByteArray := by - simp [attesterWordsBytesList, attesterWordBytesList, - word_toBytesBE_toByteArray_eq_toByteArray] - -theorem attesterWordsBytesList_length (words : List UInt256) : - (attesterWordsBytesList words).length = 32 * words.length := by - induction words with - | nil => - simp [attesterWordsBytesList] - | cons word rest ih => - have hwordLen : (attesterWordBytesList word).length = 32 := by - have h := word_toBytesBE_toByteArray_size word - rw [list_toByteArray_size] at h - simpa [attesterWordBytesList] using h - simp [attesterWordsBytesList, ih, hwordLen] - omega - -def AttesterWordsAt (mem : ByteArray) (base : Nat) (words : List UInt256) : Prop := - base + 32 * words.length ≤ mem.size ∧ - ∀ {idx word}, lookupNth? words idx = some word → - mem.readWithPadding (base + 32 * idx) 32 = UInt256.toByteArray word - -theorem AttesterWordsAt.tail - {mem : ByteArray} {base : Nat} {word : UInt256} {words : List UInt256} - (h : AttesterWordsAt mem base (word :: words)) : - AttesterWordsAt mem (base + 32) words := by - constructor - · have hb := h.1 - simp at hb - omega - · intro idx w hlookup - have htail := h.2 (idx := idx + 1) (word := w) (by - simpa [lookupNth?] using hlookup) - rw [show base + 32 + 32 * idx = base + 32 * (idx + 1) by omega] - exact htail - -theorem AttesterWordsAt.readWithPadding_eq - {mem : ByteArray} {base : Nat} : - ∀ words : List UInt256, - 32 * words.length < 2 ^ 64 → - AttesterWordsAt mem base words → - mem.readWithPadding base (32 * words.length) = - (attesterWordsBytesList words).toByteArray - | [], _hlen, _h => by - rw [show 32 * ([] : List UInt256).length = 0 by rfl] - rw [byteArray_readWithPadding_zero] - rfl - | word :: [], _hlen, h => by - have hhead := h.2 (idx := 0) (word := word) (by simp [lookupNth?]) - rw [show 32 * [word].length = 32 by norm_num] - rw [show base + 32 * 0 = base by omega] at hhead - rw [hhead] - rw [attesterWordsBytesList_cons_toByteArray word []] - simp [attesterWordsBytesList] - | word :: next :: rest, hlen, h => by - let words := next :: rest - have hhead := h.2 (idx := 0) (word := word) (by simp [lookupNth?]) - have htail : AttesterWordsAt mem (base + 32) words := - AttesterWordsAt.tail h - have htailLen : 32 * words.length < 2 ^ 64 := by - dsimp [words] - simp at hlen ⊢ - omega - have htailRead := - AttesterWordsAt.readWithPadding_eq (mem := mem) (base := base + 32) - words htailLen htail - have hlenSplit : 32 + 32 * words.length < 2 ^ 64 := by - rw [show 32 + 32 * words.length = 32 * (word :: words).length by - simp [words] - omega] - exact hlen - have hboundSplit : base + 32 + 32 * words.length ≤ mem.size := by - have hbound := h.1 - dsimp [words] at hbound ⊢ - omega - rw [show 32 * (word :: words).length = 32 + 32 * words.length by - simp [words] - omega] - rw [byteArray_readWithPadding_split mem base 32 (32 * words.length) - (by norm_num) - (by simp [words]) - (by norm_num) - htailLen - hlenSplit - hboundSplit] - rw [show base + 32 * 0 = base by omega] at hhead - rw [hhead, htailRead] - rw [attesterWordsBytesList_cons_toByteArray word words, - attesterWordsBytesList_cons_toByteArray next rest] - -theorem lookupNth?_append_cases {α : Type} : - ∀ {xs ys : List α} {idx : Nat} {value : α}, - lookupNth? (xs ++ ys) idx = some value → - (idx < xs.length ∧ lookupNth? xs idx = some value) ∨ - (xs.length ≤ idx ∧ lookupNth? ys (idx - xs.length) = some value) - | [], ys, idx, value, h => by - right - simpa using h - | x :: xs, ys, 0, value, h => by - left - constructor - · simp - · simpa [lookupNth?] using h - | x :: xs, ys, idx + 1, value, h => by - have htail : lookupNth? (xs ++ ys) idx = some value := by - simpa [lookupNth?] using h - rcases lookupNth?_append_cases htail with hleft | hright - · left - rcases hleft with ⟨hlt, hlookup⟩ - constructor - · simp - omega - · simpa [lookupNth?] using hlookup - · right - rcases hright with ⟨hle, hlookup⟩ - constructor - · simp - omega - · have hsub : idx + 1 - (x :: xs).length = idx - xs.length := by - simp - simpa [hsub] using hlookup - -theorem AttesterWordsAt.writeWord_preserved - {mem : ByteArray} {base off : Nat} {words : List UInt256} {write : UInt256} - (h : AttesterWordsAt mem base words) - (hdisj : off + 32 ≤ base ∨ base + 32 * words.length ≤ off) : - AttesterWordsAt (Reasoning.Theory.writeWord mem off write) base words := by - constructor - · exact le_trans h.1 (attesterWriteWord_size_ge_nat mem off write) - · intro idx word hlookup - have hidx : idx < words.length := lookupNth?_some_length hlookup - have hreadBound : base + 32 * idx + 32 ≤ mem.size := by - have hbound := h.1 - have hmul : 32 * (idx + 1) ≤ 32 * words.length := - Nat.mul_le_mul_left 32 (Nat.succ_le_of_lt hidx) - omega - have hpres : - (Reasoning.Theory.writeWord mem off write).readWithPadding - (base + 32 * idx) 32 = - mem.readWithPadding (base + 32 * idx) 32 := by - exact attesterWriteWord_read_preserved_len_nat mem off - (base + 32 * idx) 32 write - (by - rcases hdisj with hbefore | hafter - · exact Or.inr ⟨by omega, hreadBound⟩ - · exact Or.inl ⟨by omega, hreadBound⟩) - (by norm_num) (by norm_num) - rw [hpres] - exact h.2 hlookup - -theorem AttesterWordsAt.writeWord_append - {mem : ByteArray} {base : Nat} {words : List UInt256} {word : UInt256} - (h : AttesterWordsAt mem base words) : - AttesterWordsAt - (Reasoning.Theory.writeWord mem (base + 32 * words.length) word) - base (words ++ [word]) := by - constructor - · rw [attesterWriteWord_size_nat] - simp - omega - · intro idx readWord hlookup - have hidxTotal : idx < (words ++ [word]).length := - lookupNth?_some_length hlookup - rcases lookupNth?_append_cases hlookup with hleft | hright - · rcases hleft with ⟨_hlt, hlookupOld⟩ - have hpreserved : - AttesterWordsAt - (Reasoning.Theory.writeWord mem (base + 32 * words.length) word) - base words := - AttesterWordsAt.writeWord_preserved h (Or.inr (by rfl)) - exact hpreserved.2 hlookupOld - · rcases hright with ⟨hge, hlookupTail⟩ - cases hdelta : idx - words.length with - | zero => - have hreadWord : readWord = word := by - have htailEq : word = readWord := by - simpa [lookupNth?, hdelta] using hlookupTail - exact htailEq.symm - have hidx : idx = words.length := by - simp at hidxTotal - omega - rw [hidx, hreadWord] - exact attesterWriteWord_read_back_nat mem (base + 32 * words.length) word - | succ delta => - simp [lookupNth?, hdelta] at hlookupTail - -theorem AttesterWordsAt.append - {mem : ByteArray} {base : Nat} {xs ys : List UInt256} - (hxs : AttesterWordsAt mem base xs) - (hys : AttesterWordsAt mem (base + 32 * xs.length) ys) : - AttesterWordsAt mem base (xs ++ ys) := by - constructor - · have hx := hxs.1 - have hy := hys.1 - simp - omega - · intro idx word hlookup - rcases lookupNth?_append_cases hlookup with hleft | hright - · rcases hleft with ⟨_hlt, hlookupXs⟩ - exact hxs.2 hlookupXs - · rcases hright with ⟨_hge, hlookupYs⟩ - have hyRead := hys.2 hlookupYs - rw [show base + 32 * idx = - base + 32 * xs.length + 32 * (idx - xs.length) by - have hidx : idx < (xs ++ ys).length := lookupNth?_some_length hlookup - have hge : xs.length ≤ idx := _hge - simp at hidx - omega] - exact hyRead - -theorem attesterWriteWord_read_window_nat - (mem : ByteArray) (off start len : Nat) (word : UInt256) - (hwithin : start + len ≤ 32) (hpos : 0 < len) (hlen64 : len < 2 ^ 64) : - (Reasoning.Theory.writeWord mem off word).readWithPadding (off + start) len = - (UInt256.toByteArray word).extract start (start + len) := by - unfold Reasoning.Theory.writeWord - by_cases hle : off ≤ mem.size - · exact toByteArray_write_read_window_of_gap word mem off start len - hwithin hpos hlen64 (by - rw [Nat.sub_eq_zero_of_le hle] - exact lt_usize 0 (by norm_num)) - · have hge : mem.size ≤ off := by omega - rw [attesterToByteArray_write_eq_nat word mem off hge] - have hprefix : - (mem ++ ffi.ByteArray.zeroes (off - mem.size)).size = off := by - rw [ByteArray.size_append, ByteArray_zeroes_size] - omega - rw [readWithPadding_eq_extract' _ (off + start) len hpos hlen64 (by - rw [ByteArray.size_append, hprefix, toByteArray_size] - omega)] - rw [extract_append_right_window _ _ _ _ (by rw [hprefix]; omega), hprefix] - rw [show off + start - off = start by omega, - show off + start + len - off = start + len by omega] - -theorem attesterMultiRevokeSelectorWord_extract4 : - (UInt256.toByteArray attesterMultiRevokeSelectorWord).extract 0 4 = - multiRevokeSelector := by - native_decide - -theorem attesterBytes32ValueWord?_encodeABIValue - {value : Value} {w : UInt256} - (h : attesterBytes32ValueWord? value = some w) : - ABI.encodeABIValue? bytes32 value = some (EVM.Word.toBytesBE w) := by - cases value with - | fixedBytes n bytes => - dsimp [attesterBytes32ValueWord?] at h - by_cases hn : n = bytes32Width ∧ bytes.length = 32 - · simp [hn] at h - cases h - rcases hn with ⟨rfl, hlen⟩ - simp [ABI.encodeABIValue?, bytes32, bytes32Width, hlen, ABI.zeroBytes, - Nat.add_comm, toBytesBE_bytesToWord_of_length hlen] - · simp [hn] at h - | _ => - simp [attesterBytes32ValueWord?] at h - -theorem attesterEncodeABIValue_bytes32_eq_bind (value : Value) : - ABI.encodeABIValue? bytes32 value = - (attesterBytes32ValueWord? value).bind - (fun w => some (EVM.Word.toBytesBE w)) := by - cases value with - | fixedBytes n bytes => - by_cases hn : n = bytes32Width - · subst hn - by_cases hlen : bytes.length = 32 - · simp [ABI.encodeABIValue?, bytes32, bytes32Width, - attesterBytes32ValueWord?, hlen, ABI.zeroBytes, Nat.add_comm, - toBytesBE_bytesToWord_of_length hlen] - · simp [ABI.encodeABIValue?, bytes32, bytes32Width, - attesterBytes32ValueWord?, hlen] - · - by_cases hif : n = (31 : Fin 32) ∧ bytes.length = 32 - · exact False.elim (hn (by - simpa [bytes32Width] using hif.1)) - · simp [ABI.encodeABIValue?, bytes32, bytes32Width, - attesterBytes32ValueWord?, hif] - | _ => - simp [ABI.encodeABIValue?, ABI.encodeABIWord?, bytes32, - attesterBytes32ValueWord?] - -theorem attesterEncodeABIValue_uint256_zero : - ABI.encodeABIValue? uint256 (.int 0) = - some (EVM.Word.toBytesBE (⟨0⟩ : UInt256)) := by - have hpow : 0 < EVM.twoPow 256 := by norm_num [EVM.twoPow] - have hword : EVM.word 0 = (⟨0⟩ : UInt256) := rfl - simp [ABI.encodeABIValue?, ABI.encodeABIWord?, uint256, uint256Int, hpow, - hword] - -def attesterRevocationDataEncodedWords? : List Value → Option (List UInt256) - | [] => some [] - | uid :: rest => do - let uidWord <- attesterBytes32ValueWord? uid - let restWords <- attesterRevocationDataEncodedWords? rest - some (uidWord :: (⟨0⟩ : UInt256) :: restWords) - -theorem attesterRevocationDataEncodedWords?_length - {uids : List Value} {words : List UInt256} - (h : attesterRevocationDataEncodedWords? uids = some words) : - words.length = 2 * uids.length := by - induction uids generalizing words with - | nil => - simp [attesterRevocationDataEncodedWords?] at h - cases h - simp - | cons uid rest ih => - simp [attesterRevocationDataEncodedWords?] at h - cases hUid : attesterBytes32ValueWord? uid with - | none => - simp [hUid] at h - | some uidWord => - cases hRest : attesterRevocationDataEncodedWords? rest with - | none => - simp [hUid, hRest] at h - | some restWords => - simp [hUid, hRest] at h - cases h - have hlen := ih hRest - simp [hlen] - omega - -theorem attesterRevocationDataEncodedWords?_some_of_words - {uids : List Value} - (hwords : - ∀ {j uid}, lookupNth? uids j = some uid → - ∃ uidWord, attesterBytes32ValueWord? uid = some uidWord) : - ∃ words, - attesterRevocationDataEncodedWords? uids = some words ∧ - words.length = 2 * uids.length := by - induction uids with - | nil => - refine ⟨[], ?_, ?_⟩ - · simp [attesterRevocationDataEncodedWords?] - · simp - | cons uid rest ih => - obtain ⟨uidWord, hUidWord⟩ := - hwords (j := 0) (uid := uid) (by simp [lookupNth?]) - have hrestWords : - ∀ {j uid}, lookupNth? rest j = some uid → - ∃ uidWord, attesterBytes32ValueWord? uid = some uidWord := by - intro j uid hlookup - exact hwords (j := j + 1) (uid := uid) (by - simp [lookupNth?, hlookup]) - obtain ⟨restWords, hRest, hRestLen⟩ := ih hrestWords - refine ⟨uidWord :: (⟨0⟩ : UInt256) :: restWords, ?_, ?_⟩ - · simp [attesterRevocationDataEncodedWords?, hUidWord, hRest] - · simp [hRestLen] - omega - -theorem attesterRevocationDataValues_length (uids : List Value) : - (attesterRevocationDataValues uids).length = uids.length := by - induction uids with - | nil => simp [attesterRevocationDataValues] - | cons uid rest ih => simp [attesterRevocationDataValues, ih] - -theorem attesterEncodeABIValue_revocationDataValue (uid : Value) : - ABI.encodeABIValue? revocationRequestDataTy (attesterRevocationDataValue uid) = - (attesterBytes32ValueWord? uid).bind - (fun uidWord => - some (attesterWordsBytesList [uidWord, (⟨0⟩ : UInt256)])) := by - cases h : attesterBytes32ValueWord? uid with - | none => - simp [attesterRevocationDataValue, revocationRequestDataTy, - ABI.encodeABIValue?, ABI.encodeABIValues?, ABI.encodeABIValuesFrom?, - ABI.abiTupleHeadSize?, ABI.staticABIEncodedSize?, - ABI.staticABIEncodedSizeList?, ABI.isDynamicABIType, - attesterEncodeABIValue_bytes32_eq_bind, h] - | some uidWord => - have hUidEnc : ABI.encodeABIValue? bytes32 uid = - some (EVM.Word.toBytesBE uidWord) := - attesterBytes32ValueWord?_encodeABIValue h - have hUidEnc' : - ABI.encodeABIValue? (ABIType.elem (ElemType.bytes (31 : Fin 32))) uid = - some (EVM.Word.toBytesBE uidWord) := by - simpa [bytes32, bytes32Width] using hUidEnc - have hpow : 0 < EVM.twoPow 256 := by norm_num [EVM.twoPow] - have hword : EVM.word 0 = (⟨0⟩ : UInt256) := rfl - simp [attesterRevocationDataValue, revocationRequestDataTy, - ABI.encodeABIValue?, ABI.encodeABIValues?, ABI.encodeABIValuesFrom?, - ABI.abiTupleHeadSize?, ABI.staticABIEncodedSize?, - ABI.staticABIEncodedSizeList?, ABI.isDynamicABIType, - bytes32, bytes32Width, uint256, uint256Int] - rw [hUidEnc'] - simp [ABI.encodeABIWord?, hpow, hword, attesterWordsBytesList] - -theorem attesterEncodeABIStaticArrayElems_revocationDataValues : - ∀ uids : List Value, - ABI.encodeABIStaticArrayElems? revocationRequestDataTy - (attesterRevocationDataValues uids) = - (attesterRevocationDataEncodedWords? uids).bind - (fun words => some (attesterWordsBytesList words)) - | [] => by - simp [attesterRevocationDataValues, attesterRevocationDataEncodedWords?, - ABI.encodeABIStaticArrayElems?] - | uid :: rest => by - cases hUid : attesterBytes32ValueWord? uid with - | none => - simp [attesterRevocationDataValues, attesterRevocationDataEncodedWords?, - ABI.encodeABIStaticArrayElems?, - attesterEncodeABIValue_revocationDataValue, hUid] - | some uidWord => - cases hRest : attesterRevocationDataEncodedWords? rest with - | none => - simp [attesterRevocationDataValues, attesterRevocationDataEncodedWords?, - ABI.encodeABIStaticArrayElems?, - attesterEncodeABIValue_revocationDataValue, hUid, hRest, - attesterEncodeABIStaticArrayElems_revocationDataValues rest] - | some restWords => - simp [attesterRevocationDataValues, attesterRevocationDataEncodedWords?, - ABI.encodeABIStaticArrayElems?, - attesterEncodeABIValue_revocationDataValue, hUid, hRest, - attesterEncodeABIStaticArrayElems_revocationDataValues rest, - attesterWordsBytesList, List.append_assoc] - -def attesterMultiRevokeRequestEncodedWords? - (schema : Value) (uids : List Value) : Option (List UInt256) := do - let schemaWord <- attesterBytes32ValueWord? schema - let dataWords <- attesterRevocationDataEncodedWords? uids - some (schemaWord :: (⟨64⟩ : UInt256) :: UInt256.ofNat uids.length :: dataWords) - -theorem attesterMultiRevokeRequestEncodedWords?_length - {schema : Value} {uids : List Value} {words : List UInt256} - (h : attesterMultiRevokeRequestEncodedWords? schema uids = some words) : - words.length = 3 + 2 * uids.length := by - simp [attesterMultiRevokeRequestEncodedWords?] at h - cases hSchema : attesterBytes32ValueWord? schema with - | none => - simp [hSchema] at h - | some schemaWord => - cases hData : attesterRevocationDataEncodedWords? uids with - | none => - simp [hSchema, hData] at h - | some dataWords => - simp [hSchema, hData] at h - cases h - have hDataLen := - attesterRevocationDataEncodedWords?_length (uids := uids) - (words := dataWords) hData - simp [hDataLen] - omega - -theorem attesterMultiRevokeRequestEncodedWords?_some_of_words - {schema : Value} {uids : List Value} - (hschema : ∃ schemaWord, attesterBytes32ValueWord? schema = some schemaWord) - (huids : - ∀ {j uid}, lookupNth? uids j = some uid → - ∃ uidWord, attesterBytes32ValueWord? uid = some uidWord) : - ∃ words, - attesterMultiRevokeRequestEncodedWords? schema uids = some words ∧ - words.length = 3 + 2 * uids.length := by - rcases hschema with ⟨schemaWord, hschemaWord⟩ - obtain ⟨dataWords, hData, hDataLen⟩ := - attesterRevocationDataEncodedWords?_some_of_words huids - refine ⟨schemaWord :: (⟨64⟩ : UInt256) :: UInt256.ofNat uids.length :: dataWords, - ?_, ?_⟩ - · simp [attesterMultiRevokeRequestEncodedWords?, hschemaWord, hData] - · simp [hDataLen] - omega - -theorem attesterEncodeABIValue_revocationDataArray (uids : List Value) : - ABI.encodeABIValue? (.dynamicArray revocationRequestDataTy) - (.array (attesterRevocationDataValues uids)) = - (attesterRevocationDataEncodedWords? uids).bind - (fun words => - some (attesterWordsBytesList (UInt256.ofNat uids.length :: words))) := by - have hArray : - ABI.encodeABIValue? (.dynamicArray revocationRequestDataTy) - (.array (attesterRevocationDataValues uids)) = - (ABI.encodeABIStaticArrayElems? revocationRequestDataTy - (attesterRevocationDataValues uids)).bind - (fun encodedElems => - some (ABI.natBytes (attesterRevocationDataValues uids).length ++ - encodedElems)) := by - simp [ABI.encodeABIValue?, ABI.encodeABIArrayElems?, - ABI.isDynamicABIType, ABI.isDynamicABITypeList, revocationRequestDataTy, - bytes32, bytes32Width, uint256, uint256Int] - have hElems := - attesterEncodeABIStaticArrayElems_revocationDataValues uids - rw [hArray, hElems] - cases h : attesterRevocationDataEncodedWords? uids with - | none => - simp [h] - | some words => - simp [h, - attesterNatBytes_eq_toBytesBE, attesterRevocationDataValues_length, - attesterWordBytesList, attesterWordsBytesList] - -theorem attesterEncodeABIValue_multiRevokeRequestValue - (schema : Value) (uids : List Value) : - ABI.encodeABIValue? multiRevocationRequestTy - (attesterMultiRevokeRequestValue schema uids) = - (attesterMultiRevokeRequestEncodedWords? schema uids).bind - (fun words => some (attesterWordsBytesList words)) := by - cases hSchema : attesterBytes32ValueWord? schema with - | none => - simp [attesterMultiRevokeRequestValue, multiRevocationRequestTy, - ABI.encodeABIValue?, ABI.encodeABIValues?, ABI.encodeABIValuesFrom?, - ABI.abiTupleHeadSize?, ABI.staticABIEncodedSize?, - ABI.staticABIEncodedSizeList?, ABI.isDynamicABIType, - attesterEncodeABIValue_bytes32_eq_bind, - attesterMultiRevokeRequestEncodedWords?, hSchema] - | some schemaWord => - have hSchemaEnc : ABI.encodeABIValue? bytes32 schema = - some (EVM.Word.toBytesBE schemaWord) := - attesterBytes32ValueWord?_encodeABIValue hSchema - have hSchemaEnc' : - ABI.encodeABIValue? (ABIType.elem (ElemType.bytes (31 : Fin 32))) schema = - some (EVM.Word.toBytesBE schemaWord) := by - simpa [bytes32, bytes32Width] using hSchemaEnc - cases hData : attesterRevocationDataEncodedWords? uids with - | none => - simp [attesterMultiRevokeRequestValue, multiRevocationRequestTy, - ABI.encodeABIValue?, ABI.encodeABIValues?, ABI.encodeABIValuesFrom?, - ABI.abiTupleHeadSize?, ABI.staticABIEncodedSize?, - ABI.staticABIEncodedSizeList?, ABI.isDynamicABIType, - bytes32, bytes32Width, uint256, uint256Int, - attesterEncodeABIValue_revocationDataArray, - attesterMultiRevokeRequestEncodedWords?, hSchema, hData] - | some dataWords => - have h64 : UInt256.ofNat 64 = (⟨64⟩ : UInt256) := by native_decide - simp [attesterMultiRevokeRequestValue, multiRevocationRequestTy, - ABI.encodeABIValue?, ABI.encodeABIValues?, ABI.encodeABIValuesFrom?, - ABI.abiTupleHeadSize?, ABI.staticABIEncodedSize?, - ABI.staticABIEncodedSizeList?, ABI.isDynamicABIType, - bytes32, bytes32Width, uint256, uint256Int, - attesterEncodeABIValue_revocationDataArray, - attesterMultiRevokeRequestEncodedWords?, hSchema, hData] - rw [hSchemaEnc'] - simp [attesterNatBytes_eq_toBytesBE, h64, attesterWordsBytesList, - List.append_assoc] - -def attesterMultiRevokeRequestArrayElemsWordsFrom? - (headSize : Nat) : - List Value → List Value → List UInt256 → List UInt256 → Option (List UInt256) - | [], _, head, tail => some (head ++ tail) - | _ :: _, [], head, tail => some (head ++ tail) - | schema :: schemas, .array uids :: schemaUids, head, tail => do - let encoded <- attesterMultiRevokeRequestEncodedWords? schema uids - attesterMultiRevokeRequestArrayElemsWordsFrom? headSize schemas schemaUids - (head ++ [UInt256.ofNat (headSize + 32 * tail.length)]) - (tail ++ encoded) - | _ :: _, _ :: _, head, tail => some (head ++ tail) - -def attesterMultiRevokeRequestArrayElemsWords? - (schemas schemaUids : List Value) : Option (List UInt256) := - attesterMultiRevokeRequestArrayElemsWordsFrom? - ((attesterMultiRevokeRequestValues schemas schemaUids).length * 32) - schemas schemaUids [] [] - -theorem attesterMultiRevokeRequestArrayElemsWordsFrom?_some_of_words : - ∀ (schemas schemaUids : List Value) (headSize : Nat) - (head tail : List UInt256), - schemaUids.length = schemas.length → - (∀ {idx schema}, lookupNth? schemas idx = some schema → - ∃ schemaWord, attesterBytes32ValueWord? schema = some schemaWord) → - (∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - ∃ uidWord, attesterBytes32ValueWord? uid = some uidWord)) → - ∃ words, - attesterMultiRevokeRequestArrayElemsWordsFrom? - headSize schemas schemaUids head tail = some words - | [], [], headSize, head, tail, _hlen, _hschemas, _huidss => by - refine ⟨head ++ tail, ?_⟩ - simp [attesterMultiRevokeRequestArrayElemsWordsFrom?] - | [], _ :: _, headSize, head, tail, hlen, _hschemas, _huidss => by - simp at hlen - | _ :: _, [], headSize, head, tail, hlen, _hschemas, _huidss => by - simp at hlen - | schema :: schemas, value :: schemaUids, headSize, head, tail, hlen, - hschemas, huidss => by - obtain ⟨schemaWord, hschemaWord⟩ := - hschemas (idx := 0) (schema := schema) (by simp [lookupNth?]) - obtain ⟨uids, hvalue, huidsWords⟩ := - huidss (idx := 0) (value := value) (by simp [lookupNth?]) - subst value - have hlenTail : schemaUids.length = schemas.length := by - simp at hlen - exact hlen - have hschemasTail : - ∀ {idx schema}, lookupNth? schemas idx = some schema → - ∃ schemaWord, attesterBytes32ValueWord? schema = some schemaWord := by - intro idx schema hlookup - exact hschemas (idx := idx + 1) (schema := schema) (by - simp [lookupNth?, hlookup]) - have huidssTail : - ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - ∃ uidWord, attesterBytes32ValueWord? uid = some uidWord) := by - intro idx value hlookup - exact huidss (idx := idx + 1) (value := value) (by - simp [lookupNth?, hlookup]) - obtain ⟨encoded, hencoded, _hencodedLen⟩ := - attesterMultiRevokeRequestEncodedWords?_some_of_words - (schema := schema) (uids := uids) - ⟨schemaWord, hschemaWord⟩ huidsWords - obtain ⟨words, hwords⟩ := - attesterMultiRevokeRequestArrayElemsWordsFrom?_some_of_words - schemas schemaUids headSize - (head ++ [UInt256.ofNat (headSize + 32 * tail.length)]) - (tail ++ encoded) hlenTail hschemasTail huidssTail - refine ⟨words, ?_⟩ - simp [attesterMultiRevokeRequestArrayElemsWordsFrom?, hencoded, hwords] - -theorem attesterMultiRevokeRequestArrayElemsWords?_some_of_words - {schemas schemaUids : List Value} - (hlen : schemaUids.length = schemas.length) - (hschemas : - ∀ {idx schema}, lookupNth? schemas idx = some schema → - ∃ schemaWord, attesterBytes32ValueWord? schema = some schemaWord) - (huidss : - ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - ∃ uidWord, attesterBytes32ValueWord? uid = some uidWord)) : - ∃ words, - attesterMultiRevokeRequestArrayElemsWords? schemas schemaUids = some words := by - exact - attesterMultiRevokeRequestArrayElemsWordsFrom?_some_of_words - schemas schemaUids - ((attesterMultiRevokeRequestValues schemas schemaUids).length * 32) - [] [] hlen hschemas huidss - -theorem attesterMultiRevokeRequestArrayElemsWords?_some_of_memoryLayout - {schemas schemaUids : List Value} {mem : ByteArray} {aw outerBase : UInt256} - (hlen : schemaUids.length = schemas.length) - (huidssShape : - ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, value = .array uids) - (hlayout : - AttesterMultiRevokeRequestsMemoryLayout - schemas schemaUids schemas.length mem aw outerBase) : - ∃ words, - attesterMultiRevokeRequestArrayElemsWords? schemas schemaUids = some words := by - have hschemas : - ∀ {idx schema}, lookupNth? schemas idx = some schema → - ∃ schemaWord, attesterBytes32ValueWord? schema = some schemaWord := by - intro idx schema hschema - have hidxSchemas : idx < schemas.length := lookupNth?_some_length hschema - have hidxSchemaUids : idx < schemaUids.length := by omega - obtain ⟨value, hvalue⟩ := - attesterLookupNth?_exists (xs := schemaUids) (i := idx) hidxSchemaUids - rcases huidssShape hvalue with ⟨uids, hvalueArray⟩ - have huids : lookupNth? schemaUids idx = some (.array uids) := by - simpa [hvalueArray] using hvalue - rcases hlayout hidxSchemas hschema huids with - ⟨schemaWord, hschemaWord, _hschemaMload, _hlenMload, _huids⟩ - exact ⟨schemaWord, hschemaWord⟩ - have huidss : - ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - ∃ uidWord, attesterBytes32ValueWord? uid = some uidWord) := by - intro idx value hvalue - have hidxSchemaUids : idx < schemaUids.length := lookupNth?_some_length hvalue - have hidxSchemas : idx < schemas.length := by omega - obtain ⟨schema, hschema⟩ := - attesterLookupNth?_exists (xs := schemas) (i := idx) hidxSchemas - rcases huidssShape hvalue with ⟨uids, hvalueArray⟩ - have huids : lookupNth? schemaUids idx = some (.array uids) := by - simpa [hvalueArray] using hvalue - rcases hlayout hidxSchemas hschema huids with - ⟨_schemaWord, _hschemaWord, _hschemaMload, _hlenMload, huidsLayout⟩ - refine ⟨uids, hvalueArray, ?_⟩ - intro j uid huid - rcases huidsLayout huid with - ⟨uidWord, huidWord, _huidMload, _hextraMload⟩ - exact ⟨uidWord, huidWord⟩ - exact - attesterMultiRevokeRequestArrayElemsWords?_some_of_words - hlen hschemas huidss - -theorem attesterMultiRevokeRequestArrayElemsWords?_some_of_readLayoutBounded - {schemas schemaUids : List Value} {mem : ByteArray} - {outerBase : UInt256} {contentLo bound : Nat} - (hlen : schemaUids.length = schemas.length) - (huidssShape : - ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, value = .array uids) - (hlayout : - AttesterMultiRevokeRequestsReadLayoutBounded - schemas schemaUids schemas.length mem outerBase contentLo bound) : - ∃ words, - attesterMultiRevokeRequestArrayElemsWords? schemas schemaUids = some words := by - have hschemas : - ∀ {idx schema}, lookupNth? schemas idx = some schema → - ∃ schemaWord, attesterBytes32ValueWord? schema = some schemaWord := by - intro idx schema hschema - have hidxSchemas : idx < schemas.length := lookupNth?_some_length hschema - have hidxSchemaUids : idx < schemaUids.length := by omega - obtain ⟨value, hvalue⟩ := - attesterLookupNth?_exists (xs := schemaUids) (i := idx) hidxSchemaUids - rcases huidssShape hvalue with ⟨uids, hvalueArray⟩ - have huids : lookupNth? schemaUids idx = some (.array uids) := by - simpa [hvalueArray] using hvalue - rcases hlayout hidxSchemas hschema huids with - ⟨schemaWord, _reqPtr, _dataPtr, hschemaWord, _hslot64, _hslotBound, - _hslotMem, _hslotRead, _hreqLo, _hreqBound, _hreqMem, _hreq32Lo, - _hreq32Bound, _hreq32Mem, _hschemaRead, _hdataPtrRead, _hdataLo, - _hdataBound, _hdataMem, _hdataRead, _huidsRead⟩ - exact ⟨schemaWord, hschemaWord⟩ - have huidss : - ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - ∃ uidWord, attesterBytes32ValueWord? uid = some uidWord) := by - intro idx value hvalue - have hidxSchemaUids : idx < schemaUids.length := lookupNth?_some_length hvalue - have hidxSchemas : idx < schemas.length := by omega - obtain ⟨schema, hschema⟩ := - attesterLookupNth?_exists (xs := schemas) (i := idx) hidxSchemas - rcases huidssShape hvalue with ⟨uids, hvalueArray⟩ - have huids : lookupNth? schemaUids idx = some (.array uids) := by - simpa [hvalueArray] using hvalue - rcases hlayout hidxSchemas hschema huids with - ⟨_schemaWord, _reqPtr, _dataPtr, _hschemaWord, _hslot64, _hslotBound, - _hslotMem, _hslotRead, _hreqLo, _hreqBound, _hreqMem, _hreq32Lo, - _hreq32Bound, _hreq32Mem, _hschemaRead, _hdataPtrRead, _hdataLo, - _hdataBound, _hdataMem, _hdataRead, huidsRead⟩ - refine ⟨uids, hvalueArray, ?_⟩ - intro j uid huid - rcases huidsRead huid with - ⟨uidWord, _elemPtr, huidWord, _helemSlotLo, _helemSlotBound, - _helemSlotMem, _helemSlotRead, _helemPtrLo, _helemPtrBound, - _helemPtrMem, _helemPtr32Lo, _helemPtr32Bound, _helemPtr32Mem, - _helemRead, _helemExtraRead⟩ - exact ⟨uidWord, huidWord⟩ - exact - attesterMultiRevokeRequestArrayElemsWords?_some_of_words - hlen hschemas huidss - -theorem AttesterMultiRevokeRequestsReadLayoutBounded.to_memoryLayout - {schemas schemaUids : List Value} {i : Nat} - {mem : ByteArray} {aw outerBase : UInt256} {contentLo bound : Nat} - (hactive : - ∀ {off : UInt256}, off.toNat + 32 ≤ mem.size → - ¬ off ≥ aw * (⟨32⟩ : UInt256)) - (hread : - AttesterMultiRevokeRequestsReadLayoutBounded - schemas schemaUids i mem outerBase contentLo bound) : - AttesterMultiRevokeRequestsMemoryLayout schemas schemaUids i mem aw outerBase := by - intro idx hidx - exact - AttesterMultiRevokeRequestReadLayoutAt.to_mload hactive - (AttesterMultiRevokeRequestReadLayoutAtBounded.to_readLayout (hread hidx)) - -theorem AttesterReadPreservedBefore.trans - {mem₀ mem₁ mem₂ : ByteArray} {bound : Nat} - (h₀₁ : AttesterReadPreservedBefore mem₀ mem₁ bound) - (h₁₂ : AttesterReadPreservedBefore mem₁ mem₂ bound) : - AttesterReadPreservedBefore mem₀ mem₂ bound := by - intro read word hmem hread hread64 hbefore - have hmid := h₀₁ hmem hread hread64 hbefore - exact h₁₂ hmid.1 hmid.2 hread64 hbefore - -theorem AttesterReadPreservedBefore.writeWord_at_or_above - {mem : ByteArray} {off bound : Nat} {word : UInt256} - (hbound : bound ≤ off) : - AttesterReadPreservedBefore mem - (Reasoning.Theory.writeWord mem off word) bound := by - intro read w hmem hread _hread64 hbefore - constructor - · exact le_trans hmem (attesterWriteWord_size_ge_nat mem off word) - · rw [attesterWriteWord_read_preserved_len_nat mem off read 32 word - (Or.inl ⟨le_trans hbefore hbound, hmem⟩) (by norm_num) (by norm_num), - hread] - -theorem AttesterMultiRevokeRequestReadLayoutAtBounded.to_mload_bounded - {schemas schemaUids : List Value} {mem : ByteArray} - {aw outerBase : UInt256} {contentLo bound idx : Nat} - (hcontentLo64 : 64 + 32 ≤ contentLo) - (hactive : - ∀ {off : UInt256}, 64 + 32 ≤ off.toNat → off.toNat + 32 ≤ bound → - ¬ off ≥ aw * (⟨32⟩ : UInt256)) - (hread : - AttesterMultiRevokeRequestReadLayoutAtBounded - schemas schemaUids mem outerBase contentLo bound idx) : - AttesterMultiRevokeRequestMemoryLayoutAt schemas schemaUids mem aw outerBase idx := by - intro schema uids hschema huids - rcases hread hschema huids with - ⟨schemaWord, reqPtr, dataPtr, hschemaWord, hslot64, hslotBound, hslotMem, - hslotRead, hreqLo, hreqBound, hreqMem, hreq32Lo, hreq32Bound, hreq32Mem, - hschemaRead, hdataPtrRead, hdataLo, hdataBound, hdataMem, hdataRead, - huidsRead⟩ - let slot := attesterMultiRevokePostCopyOuterSlotWord outerBase (UInt256.ofNat idx) - have hreqMload : - attesterMultiRevokeRequestPtr mem aw outerBase idx = reqPtr := by - dsimp [attesterMultiRevokeRequestPtr, slot] at hslotMem hslotRead ⊢ - exact attesterMloadWord_of_readWithPadding hslotMem - (hactive (off := slot) hslot64 hslotBound) hslotRead - have hreq64 : 64 + 32 ≤ reqPtr.toNat := le_trans hcontentLo64 hreqLo - have hschemaMload : - attesterMloadWord mem aw - (attesterMultiRevokeRequestPtr mem aw outerBase idx) = - schemaWord := by - rw [hreqMload] - exact attesterMloadWord_of_readWithPadding hreqMem - (hactive (off := reqPtr) hreq64 hreqBound) hschemaRead - have hreq32_64 : 64 + 32 ≤ ((⟨32⟩ : UInt256) + reqPtr).toNat := - le_trans hcontentLo64 hreq32Lo - have hdataPtrMload : - attesterMultiRevokeRequestDataPtr mem aw outerBase idx = dataPtr := by - dsimp [attesterMultiRevokeRequestDataPtr] - rw [hreqMload] - exact attesterMloadWord_of_readWithPadding hreq32Mem - (hactive (off := (⟨32⟩ : UInt256) + reqPtr) hreq32_64 hreq32Bound) - hdataPtrRead - have hdata64 : 64 + 32 ≤ dataPtr.toNat := le_trans hcontentLo64 hdataLo - have hdataLenMload : - attesterMloadWord mem aw - (attesterMultiRevokeRequestDataPtr mem aw outerBase idx) = - UInt256.ofNat uids.length := by - rw [hdataPtrMload] - exact attesterMloadWord_of_readWithPadding hdataMem - (hactive (off := dataPtr) hdata64 hdataBound) hdataRead - refine ⟨schemaWord, hschemaWord, hschemaMload, hdataLenMload, ?_⟩ - intro j uid huid - rcases huidsRead huid with - ⟨uidWord, elemPtr, huidWord, helemSlotLo, helemSlotBound, helemSlotMem, - helemSlotRead, helemPtrLo, helemPtrBound, helemPtrMem, helemPtr32Lo, - helemPtr32Bound, helemPtr32Mem, helemRead, helemExtraRead⟩ - let elemSlot := (⟨32⟩ : UInt256) + - UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat j) + dataPtr - have helemSlot64 : 64 + 32 ≤ elemSlot.toNat := - le_trans hcontentLo64 helemSlotLo - have helemPtrMload : - attesterMultiRevokeRequestDataElemPtr mem aw outerBase idx j = elemPtr := by - dsimp [attesterMultiRevokeRequestDataElemPtr, elemSlot] - rw [hdataPtrMload] - exact attesterMloadWord_of_readWithPadding helemSlotMem - (hactive (off := elemSlot) helemSlot64 helemSlotBound) helemSlotRead - have helemPtr64 : 64 + 32 ≤ elemPtr.toNat := - le_trans hcontentLo64 helemPtrLo - have huidMload : - attesterMloadWord mem aw - (attesterMultiRevokeRequestDataElemPtr mem aw outerBase idx j) = - uidWord := by - rw [helemPtrMload] - exact attesterMloadWord_of_readWithPadding helemPtrMem - (hactive (off := elemPtr) helemPtr64 helemPtrBound) helemRead - have helemPtr32_64 : 64 + 32 ≤ ((⟨32⟩ : UInt256) + elemPtr).toNat := - le_trans hcontentLo64 helemPtr32Lo - have hextraMload : - attesterMloadWord mem aw - ((⟨32⟩ : UInt256) + - attesterMultiRevokeRequestDataElemPtr mem aw outerBase idx j) = - (⟨0⟩ : UInt256) := by - rw [helemPtrMload] - exact attesterMloadWord_of_readWithPadding helemPtr32Mem - (hactive (off := (⟨32⟩ : UInt256) + elemPtr) helemPtr32_64 - helemPtr32Bound) helemExtraRead - exact ⟨uidWord, huidWord, huidMload, hextraMload⟩ - -theorem AttesterMultiRevokeRequestsReadLayoutBounded.to_memoryLayout_bounded - {schemas schemaUids : List Value} {i : Nat} - {mem : ByteArray} {aw outerBase : UInt256} {contentLo bound : Nat} - (hcontentLo64 : 64 + 32 ≤ contentLo) - (hactive : - ∀ {off : UInt256}, 64 + 32 ≤ off.toNat → off.toNat + 32 ≤ bound → - ¬ off ≥ aw * (⟨32⟩ : UInt256)) - (hread : - AttesterMultiRevokeRequestsReadLayoutBounded - schemas schemaUids i mem outerBase contentLo bound) : - AttesterMultiRevokeRequestsMemoryLayout schemas schemaUids i mem aw outerBase := by - intro idx hidx - exact - AttesterMultiRevokeRequestReadLayoutAtBounded.to_mload_bounded - hcontentLo64 hactive (hread hidx) - -theorem AttesterMultiRevokeRequestReadLayoutAtBounded.preserve_before - {schemas schemaUids : List Value} - {mem mem' : ByteArray} {outerBase : UInt256} - {contentLo bound idx : Nat} - (hcontentLo64 : 64 + 32 ≤ contentLo) - (hpres : AttesterReadPreservedBefore mem mem' bound) - (h : - AttesterMultiRevokeRequestReadLayoutAtBounded - schemas schemaUids mem outerBase contentLo bound idx) : - AttesterMultiRevokeRequestReadLayoutAtBounded - schemas schemaUids mem' outerBase contentLo bound idx := by - intro schema uids hschema huids - rcases h hschema huids with - ⟨schemaWord, reqPtr, dataPtr, hschemaWord, hslot64, hslotBound, hslotMem, - hslotRead, hreqLo, hreqBound, hreqMem, hreq32Lo, hreq32Bound, hreq32Mem, - hschemaRead, hdataPtrRead, hdataLo, hdataBound, hdataMem, hdataRead, - huidsRead⟩ - have hslotPres := hpres hslotMem hslotRead hslot64 hslotBound - have hreq64 : 64 + 32 ≤ reqPtr.toNat := le_trans hcontentLo64 hreqLo - have hreqPres := hpres hreqMem hschemaRead hreq64 hreqBound - have hreq32_64 : 64 + 32 ≤ ((⟨32⟩ : UInt256) + reqPtr).toNat := - le_trans hcontentLo64 hreq32Lo - have hreq32Pres := hpres hreq32Mem hdataPtrRead hreq32_64 hreq32Bound - have hdata64 : 64 + 32 ≤ dataPtr.toNat := le_trans hcontentLo64 hdataLo - have hdataPres := hpres hdataMem hdataRead hdata64 hdataBound - refine ⟨schemaWord, reqPtr, dataPtr, hschemaWord, hslot64, hslotBound, - hslotPres.1, hslotPres.2, hreqLo, hreqBound, hreqPres.1, hreq32Lo, - hreq32Bound, hreq32Pres.1, hreqPres.2, hreq32Pres.2, hdataLo, - hdataBound, hdataPres.1, hdataPres.2, ?_⟩ - intro j uid huid - rcases huidsRead huid with - ⟨uidWord, elemPtr, huidWord, helemSlotLo, helemSlotBound, helemSlotMem, - helemSlotRead, helemPtrLo, helemPtrBound, helemPtrMem, helemPtr32Lo, - helemPtr32Bound, helemPtr32Mem, helemRead, helemExtraRead⟩ - let elemSlot := (⟨32⟩ : UInt256) + - UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat j) + dataPtr - have helemSlot64 : 64 + 32 ≤ elemSlot.toNat := - le_trans hcontentLo64 helemSlotLo - have helemSlotPres := - hpres helemSlotMem helemSlotRead helemSlot64 helemSlotBound - have helemPtr64 : 64 + 32 ≤ elemPtr.toNat := - le_trans hcontentLo64 helemPtrLo - have helemPtrPres := hpres helemPtrMem helemRead helemPtr64 helemPtrBound - have helemPtr32_64 : 64 + 32 ≤ ((⟨32⟩ : UInt256) + elemPtr).toNat := - le_trans hcontentLo64 helemPtr32Lo - have helemPtr32Pres := - hpres helemPtr32Mem helemExtraRead helemPtr32_64 helemPtr32Bound - exact ⟨uidWord, elemPtr, huidWord, helemSlotLo, helemSlotBound, - helemSlotPres.1, helemSlotPres.2, helemPtrLo, helemPtrBound, - helemPtrPres.1, helemPtr32Lo, helemPtr32Bound, helemPtr32Pres.1, - helemPtrPres.2, helemPtr32Pres.2⟩ - -theorem AttesterMultiRevokeRequestsReadLayoutBounded.preserve_before - {schemas schemaUids : List Value} {i : Nat} - {mem mem' : ByteArray} {outerBase : UInt256} {contentLo bound : Nat} - (hcontentLo64 : 64 + 32 ≤ contentLo) - (hpres : AttesterReadPreservedBefore mem mem' bound) - (h : - AttesterMultiRevokeRequestsReadLayoutBounded - schemas schemaUids i mem outerBase contentLo bound) : - AttesterMultiRevokeRequestsReadLayoutBounded - schemas schemaUids i mem' outerBase contentLo bound := by - intro idx hidx - exact - AttesterMultiRevokeRequestReadLayoutAtBounded.preserve_before - hcontentLo64 hpres (h hidx) - -set_option maxHeartbeats 1000000 in -theorem attesterEncodeABIDynamicArrayElemsFrom_multiRevokeRequestValues : - ∀ (schemas schemaUids : List Value) (headSize : Nat) - (head tail : List UInt256), - ABI.encodeABIDynamicArrayElemsFrom? multiRevocationRequestTy - (attesterMultiRevokeRequestValues schemas schemaUids) headSize - (attesterWordsBytesList head) (attesterWordsBytesList tail) = - (attesterMultiRevokeRequestArrayElemsWordsFrom? - headSize schemas schemaUids head tail).bind - (fun words => some (attesterWordsBytesList words)) - | [], [], headSize, head, tail => by - simp [attesterMultiRevokeRequestValues, - attesterMultiRevokeRequestArrayElemsWordsFrom?, - ABI.encodeABIDynamicArrayElemsFrom?, attesterWordsBytesList_append] - | [], _ :: _, headSize, head, tail => by - simp [attesterMultiRevokeRequestValues, - attesterMultiRevokeRequestArrayElemsWordsFrom?, - ABI.encodeABIDynamicArrayElemsFrom?, attesterWordsBytesList_append] - | _ :: _, [], headSize, head, tail => by - simp [attesterMultiRevokeRequestValues, - attesterMultiRevokeRequestArrayElemsWordsFrom?, - ABI.encodeABIDynamicArrayElemsFrom?, attesterWordsBytesList_append] - | schema :: schemas, value :: schemaUids, headSize, head, tail => by - cases value with - | array uids => - cases hReq : attesterMultiRevokeRequestEncodedWords? schema uids with - | none => - simp [attesterMultiRevokeRequestValues, - attesterMultiRevokeRequestArrayElemsWordsFrom?, - ABI.encodeABIDynamicArrayElemsFrom?, - attesterEncodeABIValue_multiRevokeRequestValue, hReq] - | some encoded => - have htailLen : - (attesterWordsBytesList tail).length = 32 * tail.length := - attesterWordsBytesList_length tail - have hOffset : - headSize + (attesterWordsBytesList tail).length = - headSize + 32 * tail.length := by - rw [htailLen] - simp [attesterMultiRevokeRequestValues, - attesterMultiRevokeRequestArrayElemsWordsFrom?, - ABI.encodeABIDynamicArrayElemsFrom?, - attesterEncodeABIValue_multiRevokeRequestValue, hReq, - hOffset, attesterNatBytes_eq_toBytesBE] - simpa [attesterWordBytesList, attesterWordsBytesList, - attesterWordsBytesList_append, List.append_assoc] using - attesterEncodeABIDynamicArrayElemsFrom_multiRevokeRequestValues - schemas schemaUids headSize - (head ++ [UInt256.ofNat (headSize + 32 * tail.length)]) - (tail ++ encoded) - | _ => - simp [attesterMultiRevokeRequestValues, - attesterMultiRevokeRequestArrayElemsWordsFrom?, - ABI.encodeABIDynamicArrayElemsFrom?, attesterWordsBytesList_append] - -theorem attesterEncodeABIArrayElems_multiRevokeRequestValues - (schemas schemaUids : List Value) : - ABI.encodeABIArrayElems? multiRevocationRequestTy - (attesterMultiRevokeRequestValues schemas schemaUids) = - (attesterMultiRevokeRequestArrayElemsWords? schemas schemaUids).bind - (fun words => some (attesterWordsBytesList words)) := by - have hdyn : - ABI.isDynamicABIType multiRevocationRequestTy = true := by - simp [multiRevocationRequestTy, revocationRequestDataTy, bytes32, - bytes32Width, uint256, uint256Int, ABI.isDynamicABIType, - ABI.isDynamicABITypeList] - rw [show - ABI.encodeABIArrayElems? multiRevocationRequestTy - (attesterMultiRevokeRequestValues schemas schemaUids) = - ABI.encodeABIDynamicArrayElemsFrom? multiRevocationRequestTy - (attesterMultiRevokeRequestValues schemas schemaUids) - ((attesterMultiRevokeRequestValues schemas schemaUids).length * 32) - [] [] by - simp [ABI.encodeABIArrayElems?, hdyn]] - simpa [attesterMultiRevokeRequestArrayElemsWords?] using - attesterEncodeABIDynamicArrayElemsFrom_multiRevokeRequestValues - schemas schemaUids - ((attesterMultiRevokeRequestValues schemas schemaUids).length * 32) [] [] - -theorem attesterEncodeABIValue_multiRevokeRequestArray - (schemas schemaUids : List Value) : - ABI.encodeABIValue? (.dynamicArray multiRevocationRequestTy) - (.array (attesterMultiRevokeRequestValues schemas schemaUids)) = - (attesterMultiRevokeRequestArrayElemsWords? schemas schemaUids).bind - (fun words => - some (attesterWordsBytesList - (UInt256.ofNat - (attesterMultiRevokeRequestValues schemas schemaUids).length :: - words))) := by - have hElems := attesterEncodeABIArrayElems_multiRevokeRequestValues schemas schemaUids - rw [show - ABI.encodeABIValue? (.dynamicArray multiRevocationRequestTy) - (.array (attesterMultiRevokeRequestValues schemas schemaUids)) = - (ABI.encodeABIArrayElems? multiRevocationRequestTy - (attesterMultiRevokeRequestValues schemas schemaUids)).bind - (fun encodedElems => - some (ABI.natBytes - (attesterMultiRevokeRequestValues schemas schemaUids).length ++ - encodedElems)) by - simp [ABI.encodeABIValue?]] - rw [hElems] - cases h : attesterMultiRevokeRequestArrayElemsWords? schemas schemaUids with - | none => - simp - | some words => - simp [attesterNatBytes_eq_toBytesBE, attesterWordBytesList, - attesterWordsBytesList] - -theorem attesterEncodeABIValues_multiRevokeRequestArray - (schemas schemaUids : List Value) : - ABI.encodeABIValues? [multiRevocationRequestArrayTy] - [.array (attesterMultiRevokeRequestValues schemas schemaUids)] = - (attesterMultiRevokeRequestArrayElemsWords? schemas schemaUids).bind - (fun words => - some (attesterWordsBytesList - [UInt256.ofNat 32, - UInt256.ofNat - (attesterMultiRevokeRequestValues schemas schemaUids).length] ++ - attesterWordsBytesList words)) := by - rw [show - ABI.encodeABIValues? [multiRevocationRequestArrayTy] - [.array (attesterMultiRevokeRequestValues schemas schemaUids)] = - (ABI.encodeABIArrayElems? multiRevocationRequestTy - (attesterMultiRevokeRequestValues schemas schemaUids)).bind - (fun encoded => - some (ABI.natBytes 32 ++ - (ABI.natBytes - (attesterMultiRevokeRequestValues schemas schemaUids).length ++ - encoded))) by - simpa [multiRevocationRequestArrayTy] using - (attesterEncodeABIValues_single_dynArray - (elemTy := multiRevocationRequestTy) - (vs := attesterMultiRevokeRequestValues schemas schemaUids))] - have hElems := attesterEncodeABIArrayElems_multiRevokeRequestValues schemas schemaUids - simp [multiRevocationRequestArrayTy] at hElems ⊢ - rw [hElems] - cases h : attesterMultiRevokeRequestArrayElemsWords? schemas schemaUids with - | none => - simp - | some words => - simp [attesterNatBytes_eq_toBytesBE, attesterWordBytesList, - attesterWordsBytesList, List.append_assoc] - -theorem attesterExternalABIEncode_multiRevokeRequestArray - (v : AttesterImmutables) (schemas schemaUids : List Value) : - (config v).externalABI.encode? "multiRevoke" - [.array (attesterMultiRevokeRequestValues schemas schemaUids)] = - (attesterMultiRevokeRequestArrayElemsWords? schemas schemaUids).bind - (fun words => - some (multiRevokeSelector ++ - (attesterWordsBytesList - [UInt256.ofNat 32, - UInt256.ofNat - (attesterMultiRevokeRequestValues schemas schemaUids).length] ++ - attesterWordsBytesList words).toByteArray)) := by - simp [config, attesterExternalABI, ABI.encodeCallWithSelector?] - rw [attesterEncodeABIValues_multiRevokeRequestArray] - cases h : attesterMultiRevokeRequestArrayElemsWords? schemas schemaUids with - | none => - simp [h] - | some words => - simp [h] - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/MultiRevokeEncoderExact.lean b/Benchmarks/EAS/Attester/MultiRevokeEncoderExact.lean deleted file mode 100644 index 5708f98e..00000000 --- a/Benchmarks/EAS/Attester/MultiRevokeEncoderExact.lean +++ /dev/null @@ -1,262 +0,0 @@ -import Benchmarks.EAS.Attester.MultiRevokePostLoop - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -def attesterMultiRevokeEncoderInnerIter : - Nat → AttesterMultiRevokeEncoderInnerState → AttesterMultiRevokeEncoderInnerState - | 0, s => s - | n + 1, s => attesterMultiRevokeEncoderInnerStepState - (attesterMultiRevokeEncoderInnerIter n s) - -def attesterMultiRevokeEncoderOuterStepState - (dst : UInt256) (s : AttesterMultiRevokeEncoderOuterState) : - AttesterMultiRevokeEncoderOuterState := - let inner0 := attesterMultiRevokeEncoderOuterInnerInitialState dst s - let innerDone := - attesterMultiRevokeEncoderInnerIter - (attesterMultiRevokeEncoderOuterInnerLen dst s).toNat inner0 - attesterMultiRevokeEncoderOuterBodyNextState s innerDone - -def attesterMultiRevokeEncoderOuterIter - (dst : UInt256) : - Nat → AttesterMultiRevokeEncoderOuterState → AttesterMultiRevokeEncoderOuterState - | 0, s => s - | n + 1, s => attesterMultiRevokeEncoderOuterStepState dst - (attesterMultiRevokeEncoderOuterIter dst n s) - -theorem attester_nat_sub_succ_add_one {m n : Nat} (hle : n + 1 ≤ m) : - m - n = m - (n + 1) + 1 := by - omega - -@[simp] theorem attesterMultiRevokeEncoderInnerIter_zero - (s : AttesterMultiRevokeEncoderInnerState) : - attesterMultiRevokeEncoderInnerIter 0 s = s := rfl - -@[simp] theorem attesterMultiRevokeEncoderInnerIter_succ - (n : Nat) (s : AttesterMultiRevokeEncoderInnerState) : - attesterMultiRevokeEncoderInnerIter (n + 1) s = - attesterMultiRevokeEncoderInnerStepState - (attesterMultiRevokeEncoderInnerIter n s) := rfl - -theorem attesterMultiRevokeEncoderInnerIter_idx_zero - (n : Nat) (s : AttesterMultiRevokeEncoderInnerState) - (hn : n < UInt256.size) - (hidx : s.innerIdx = (⟨0⟩ : UInt256)) : - (attesterMultiRevokeEncoderInnerIter n s).innerIdx = UInt256.ofNat n := by - induction n with - | zero => - change s.innerIdx = UInt256.ofNat 0 - rw [hidx] - simpa using (u256_ofNat_toNat (⟨0⟩ : UInt256)).symm - | succ n ih => - have hn' : n < UInt256.size := by omega - have hstep : - (attesterMultiRevokeEncoderInnerStepState - (attesterMultiRevokeEncoderInnerIter n s)).innerIdx = - (attesterMultiRevokeEncoderInnerIter n s).innerIdx + (⟨1⟩ : UInt256) := by - rfl - rw [attesterMultiRevokeEncoderInnerIter_succ, hstep, ih hn'] - exact attester_u256_ofNat_sub_succ_add_one - (m := n + 1) (n := 0) (by omega) (by omega) - -@[simp] theorem attesterMultiRevokeEncoderOuterIter_zero - (dst : UInt256) (s : AttesterMultiRevokeEncoderOuterState) : - attesterMultiRevokeEncoderOuterIter dst 0 s = s := rfl - -@[simp] theorem attesterMultiRevokeEncoderOuterIter_succ - (dst : UInt256) (n : Nat) (s : AttesterMultiRevokeEncoderOuterState) : - attesterMultiRevokeEncoderOuterIter dst (n + 1) s = - attesterMultiRevokeEncoderOuterStepState dst - (attesterMultiRevokeEncoderOuterIter dst n s) := rfl - -theorem attesterMultiRevokeEncoderOuterStepState_idx - (dst : UInt256) (s : AttesterMultiRevokeEncoderOuterState) : - (attesterMultiRevokeEncoderOuterStepState dst s).idx = - (⟨1⟩ : UInt256) + s.idx := by - rfl - -theorem attesterMultiRevokeEncoderOuterIter_idx_zero - (dst : UInt256) (n : Nat) (s : AttesterMultiRevokeEncoderOuterState) - (hn : n < UInt256.size) - (hidx : s.idx = (⟨0⟩ : UInt256)) : - (attesterMultiRevokeEncoderOuterIter dst n s).idx = UInt256.ofNat n := by - induction n with - | zero => - change s.idx = UInt256.ofNat 0 - rw [hidx] - simpa using (u256_ofNat_toNat (⟨0⟩ : UInt256)).symm - | succ n ih => - have hn' : n < UInt256.size := by omega - rw [attesterMultiRevokeEncoderOuterIter_succ, - attesterMultiRevokeEncoderOuterStepState_idx, ih hn'] - exact attester_u256_one_add_ofNat_sub_succ - (m := n + 1) (n := 0) (by omega) hn - -theorem attesterEncodeABIValues_single_dynArray - {elemTy : ABIType} {vs : List Value} : - ABI.encodeABIValues? [.dynamicArray elemTy] [.array vs] = - (ABI.encodeABIArrayElems? elemTy vs).bind - (fun encoded => - some (ABI.natBytes 32 ++ (ABI.natBytes vs.length ++ encoded))) := by - unfold ABI.encodeABIValues? - cases h : ABI.encodeABIArrayElems? elemTy vs with - | none => - simp [ABI.abiTupleHeadSize?, ABI.isDynamicABIType, - ABI.encodeABIValuesFrom?, ABI.encodeABIValue?, - h] - | some encoded => - simp [ABI.abiTupleHeadSize?, ABI.isDynamicABIType, - ABI.encodeABIValuesFrom?, ABI.encodeABIValue?, - h] - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeEncoderLoopToReturnExactState - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {idx srcHead len dstHead endPtr scratch dst src : UInt256} - {tail : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (htail : tail.length ≤ 1000) - (hinnerTail : tail.length + 9 ≤ 1000) - (hidx0 : idx = (⟨0⟩ : UInt256)) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) - (idx :: srcHead :: len :: dstHead :: endPtr :: scratch :: dst :: src :: - (⟨775⟩ : UInt256) :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ s' : AttesterMultiRevokeEncoderOuterState, ∃ k' C', - s' = - attesterMultiRevokeEncoderOuterIter dst len.toNat - { idx := idx, - srcHead := srcHead, - dstHead := dstHead, - endPtr := endPtr, - mem := mem, - aw := aw } ∧ - s'.idx = len ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨775⟩ : UInt256) - (s'.endPtr :: tail) - s'.mem s'.aw ByteArray.empty (cA, σ) k' C' := by - let s0 : AttesterMultiRevokeEncoderOuterState := - { idx := idx, - srcHead := srcHead, - dstHead := dstHead, - endPtr := endPtr, - mem := mem, - aw := aw } - let OuterInv : Nat → AttesterMultiRevokeEncoderOuterState → Prop := - fun n s => s = attesterMultiRevokeEncoderOuterIter dst (len.toNat - n) s0 ∧ - n ≤ len.toNat - have houterIdx : - ∀ n s, OuterInv n s → s.idx = UInt256.ofNat (len.toNat - n) := by - intro n s hInv - rw [hInv.1] - exact attesterMultiRevokeEncoderOuterIter_idx_zero dst (len.toNat - n) s0 - (lt_of_le_of_lt (Nat.sub_le _ _) len.val.isLt) - (by simpa [s0] using hidx0) - have houterLe : ∀ n s, OuterInv n s → n ≤ len.toNat := by - intro n s hInv - exact hInv.2 - have hbody : - ∀ n s, OuterInv (n + 1) s → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2469⟩ : UInt256) - (attesterMultiRevokeEncoderOuterStack len scratch dst src (⟨775⟩ : UInt256) - tail s) - s.mem s.aw ByteArray.empty (cA, σ) k C → - ∃ s' k' C', - OuterInv n s' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) - (attesterMultiRevokeEncoderOuterStack len scratch dst src (⟨775⟩ : UInt256) - tail s') - s'.mem s'.aw ByteArray.empty (cA, σ) k' C' := by - intro n s hInv k C rdBody - let innerLen := attesterMultiRevokeEncoderOuterInnerLen dst s - let inner0 := attesterMultiRevokeEncoderOuterInnerInitialState dst s - let InnerInv : Nat → AttesterMultiRevokeEncoderInnerState → Prop := - fun m inner => inner = attesterMultiRevokeEncoderInnerIter - (innerLen.toNat - m) inner0 ∧ m ≤ innerLen.toNat - have hinnerIdx : - ∀ m inner, InnerInv m inner → - inner.innerIdx = - UInt256.ofNat - ((attesterMultiRevokeEncoderOuterInnerLen dst s).toNat - m) := by - intro m inner h - rw [h.1] - simpa [innerLen] using - attesterMultiRevokeEncoderInnerIter_idx_zero - (innerLen.toNat - m) inner0 - (lt_of_le_of_lt (Nat.sub_le _ _) innerLen.val.isLt) - (by rfl) - have hinnerLe : - ∀ m inner, InnerInv m inner → - m ≤ (attesterMultiRevokeEncoderOuterInnerLen dst s).toNat := by - intro m inner h - simpa [innerLen] using h.2 - have hinnerStep : - ∀ m inner, InnerInv (m + 1) inner → - InnerInv m (attesterMultiRevokeEncoderInnerStepState inner) := by - intro m inner h - constructor - · rw [h.1, attester_nat_sub_succ_add_one h.2] - rfl - · omega - have hinnerInit : - InnerInv (attesterMultiRevokeEncoderOuterInnerLen dst s).toNat - (attesterMultiRevokeEncoderOuterInnerInitialState dst s) := by - constructor - · simp [innerLen, inner0] - · simp [innerLen] - have houterNext : - ∀ inner, InnerInv 0 inner → - OuterInv n (attesterMultiRevokeEncoderOuterBodyNextState s inner) := by - intro inner hinner - constructor - · rw [hinner.1] - change attesterMultiRevokeEncoderOuterStepState dst s = - attesterMultiRevokeEncoderOuterIter dst (len.toNat - n) s0 - rw [hInv.1, attester_nat_sub_succ_add_one hInv.2] - rfl - · omega - exact - attesterX_multiRevokeEncoderOuterLoopBodyWithStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (len := len) (scratch := scratch) (dst := dst) (src := src) - (ret := (⟨775⟩ : UInt256)) (tail := tail) (outer := s) - (k := k) (C := C) (n := n) - htail hinnerTail OuterInv InnerInv hinnerIdx hinnerLe hinnerStep - hinnerInit houterNext rdBody - have hInv0 : OuterInv len.toNat s0 := by - constructor - · simp [s0] - · omega - obtain ⟨s', k1, C1, hInvFinal, rd2592⟩ := - attesterX_multiRevokeEncoderOuterLoopWithStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (srcHead := srcHead) (len := len) (dstHead := dstHead) - (endPtr := endPtr) (scratch := scratch) (dst := dst) (src := src) - (ret := (⟨775⟩ : UInt256)) (tail := tail) (mem := mem) (aw := aw) - (k := k) (C := C) htail OuterInv houterIdx houterLe hbody hInv0 hidx0 rd - obtain ⟨k2, C2, rd775⟩ := - attesterX_multiRevokeEncoderOuterLoopExitToReturn - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := s'.idx) (srcHead := s'.srcHead) (len := len) - (dstHead := s'.dstHead) (endPtr := s'.endPtr) (scratch := scratch) - (dst := dst) (src := src) (tail := tail) (mem := s'.mem) (aw := s'.aw) - (k := k1) (C := C1) htail rd2592 - refine ⟨s', k2, C2, ?_, ?_, rd775⟩ - · simpa using hInvFinal.1 - · rw [hInvFinal.1] - have hidxIter := - attesterMultiRevokeEncoderOuterIter_idx_zero dst len.toNat s0 len.val.isLt - (by simpa [s0] using hidx0) - simpa [s0] using hidxIter.trans (u256_ofNat_toNat len) - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/MultiRevokeEncoderLayout.lean b/Benchmarks/EAS/Attester/MultiRevokeEncoderLayout.lean deleted file mode 100644 index a1e0ca30..00000000 --- a/Benchmarks/EAS/Attester/MultiRevokeEncoderLayout.lean +++ /dev/null @@ -1,1565 +0,0 @@ -import Benchmarks.EAS.Attester.MultiRevokeEVM -import Benchmarks.EAS.Attester.MultiSource - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -def attesterBytes32ValueWord? : Value → Option UInt256 - | .fixedBytes n bytes => - if n = bytes32Width ∧ bytes.length = 32 then - some (ABI.bytesToWord bytes) - else - none - | _ => none - -theorem attesterBytes32ValueWord?_of_toBytesBE (w : UInt256) : - attesterBytes32ValueWord? - (.fixedBytes bytes32Width (EVM.Word.toBytesBE w)) = some w := by - have hlen : (EVM.Word.toBytesBE w).length = 32 := by - simpa using word_toBytesBE_toByteArray_size w - simp [attesterBytes32ValueWord?, hlen, bytesToWord_toBytesBE] - -theorem attesterDecode_multiRevoke_schema_word (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} {schemas : List Value} - {idx : Nat} {schema : Value} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hSchemas : callargs.get? "schemas" = some (.array schemas)) - (hlookup : lookupNth? schemas idx = some schema) : - ∃ schemaWord, - attesterBytes32ValueWord? schema = some schemaWord ∧ - schemaWord = - calldataWord I.calldata - (4 + ((calldataWord I.calldata 4).toNat + 32 + 32 * idx)) := by - have hdec' : - decodeCalldata ["schemas", "schemaUids"] - [.dynamicArray bytes32, .dynamicArray (.dynamicArray bytes32)] I.calldata = - some callargs := by - simpa [decodeCalldataWithMode, config, multiRevokeTransition, transitionSignature, - bytes32Array, bytes32NestedArray] using hdec - obtain ⟨xs, endOffset, hfirst, hget⟩ := - attesterDecodeCalldata_twoDynamicArrays_first_decode - (cd := I.calldata) (callargs := callargs) - (name0 := "schemas") (name1 := "schemaUids") (elem1 := bytes32) - (by decide) hdec' - have hxs : xs = schemas := by - cases Option.some.inj (hget.symm.trans hSchemas) - rfl - have hlookupXs : lookupNth? xs idx = some schema := by - rw [hxs] - exact hlookup - obtain ⟨schemaWord, hshape⟩ := - decodeABIValue_dynamicArray_bytes32_lookup_shape - (bytes := I.calldata.toList.drop 4) (start := (calldataWord I.calldata 4).toNat) - (endOffset := endOffset) hfirst (lookupNth?_some_length hlookupXs) - have hread := - decodeABIValue_dynamicArray_bytes32_lookup_readNat - (bytes := I.calldata.toList.drop 4) (start := (calldataWord I.calldata 4).toNat) - (endOffset := endOffset) hfirst hshape - have hwordNat : - schemaWord.toNat = - (calldataWord I.calldata - (4 + ((calldataWord I.calldata 4).toNat + 32 + 32 * idx))).toNat := - readNat_drop4_at_some_eq_calldataWord (cd := I.calldata) hread - refine ⟨schemaWord, ?_, ?_⟩ - · rw [hlookupXs] at hshape - cases hshape - exact attesterBytes32ValueWord?_of_toBytesBE schemaWord - · exact u256_inj hwordNat - -theorem attesterDecode_multiRevoke_schema_word_at_payload (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} {schemas : List Value} - {idx : Nat} {schema : Value} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hSchemas : callargs.get? "schemas" = some (.array schemas)) - (hlookup : lookupNth? schemas idx = some schema) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hidxMax : idx ≤ solcMaxU64) : - ∃ schemaWord, - attesterBytes32ValueWord? schema = some schemaWord ∧ - schemaWord = - calldataWord I.calldata - (attesterMultiRevokePostCopySchemaCalldataOffset - ((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩) - (UInt256.ofNat idx)).toNat := by - obtain ⟨schemaWord, hschemaWord, hschemaEq⟩ := - attesterDecode_multiRevoke_schema_word - (v := v) (I := I) (callargs := callargs) (schemas := schemas) - (idx := idx) (schema := schema) hdec hSchemas hlookup - have hoffLe : (calldataWord I.calldata 4).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - have hidxSize : idx < UInt256.size := by - norm_num [solcMaxU64, UInt256.size] at hidxMax ⊢ - omega - have hidxWordToNat : (UInt256.ofNat idx).toNat = idx := - ulit_toNat' idx hidxSize - have hbase4ToNat : - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)).toNat = - 4 + (calldataWord I.calldata 4).toNat := by - change (((⟨4⟩ : UInt256) + calldataWord I.calldata 4).toNat = - 4 + (calldataWord I.calldata 4).toNat) - rw [uadd_toNat] - rw [show (⟨4⟩ : UInt256).toNat = 4 by decide] - exact Nat.mod_eq_of_lt (by - norm_num [solcMaxU64, UInt256.size] at hoffLe ⊢ - omega) - have hpayloadToNat : - (((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩ : UInt256)).toNat = - 4 + (calldataWord I.calldata 4).toNat + 32 := by - rw [uadd_toNat, hbase4ToNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - exact Nat.mod_eq_of_lt (by - norm_num [solcMaxU64, UInt256.size] at hoffLe ⊢ - omega) - have hmulToNat : - (UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat idx)).toNat = 32 * idx := by - rw [u256_mul_toNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide, hidxWordToNat] - exact Nat.mod_eq_of_lt (by - norm_num [solcMaxU64, UInt256.size] at hidxMax ⊢ - omega) - have hoffToNat : - (attesterMultiRevokePostCopySchemaCalldataOffset - ((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩) - (UInt256.ofNat idx)).toNat = - 4 + (calldataWord I.calldata 4).toNat + 32 + 32 * idx := by - unfold attesterMultiRevokePostCopySchemaCalldataOffset - rw [uadd_toNat, hmulToNat, hpayloadToNat] - rw [show 32 * idx + (4 + (calldataWord I.calldata 4).toNat + 32) = - 4 + (calldataWord I.calldata 4).toNat + 32 + 32 * idx by omega] - exact Nat.mod_eq_of_lt (by - norm_num [solcMaxU64, UInt256.size] at hoffLe hidxMax ⊢ - omega) - refine ⟨schemaWord, hschemaWord, ?_⟩ - rw [hschemaEq, hoffToNat] - rw [show - 4 + ((calldataWord I.calldata 4).toNat + 32 + 32 * idx) = - 4 + (calldataWord I.calldata 4).toNat + 32 + 32 * idx by omega] - -theorem attesterMultiRevokeInnerArrayCopyCalldataOffset_toNat - {payload : UInt256} {j : Nat} - (hj : j < UInt256.size) - (hbound : payload.toNat + 32 * j < UInt256.size) : - (attesterMultiRevokeInnerArrayCopyCalldataOffset payload (UInt256.ofNat j)).toNat = - payload.toNat + 32 * j := by - unfold attesterMultiRevokeInnerArrayCopyCalldataOffset - have hjToNat : (UInt256.ofNat j).toNat = j := - ulit_toNat' j hj - have hmul : - (UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat j)).toNat = 32 * j := by - rw [u256_mul_toNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide, hjToNat] - exact Nat.mod_eq_of_lt (by omega) - rw [uadd_toNat, hmul] - rw [show 32 * j + payload.toNat = payload.toNat + 32 * j by omega] - exact Nat.mod_eq_of_lt hbound - -theorem attesterDecode_multiRevoke_uid_word (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} {schemaUids uids : List Value} - {idx j : Nat} {uid : Value} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hSchemaUids : callargs.get? "schemaUids" = some (.array schemaUids)) - (hlookupOuter : lookupNth? schemaUids idx = some (.array uids)) - (hlookupUid : lookupNth? uids j = some uid) : - ∃ relativeOffset uidWord, - attesterBytes32ValueWord? uid = some uidWord ∧ - uidWord = - calldataWord I.calldata - (4 + ((calldataWord I.calldata 36).toNat + 32 + relativeOffset + 32 + - 32 * j)) := by - obtain ⟨_len, relativeOffset, innerEnd, _hlen, _hlenMax, _hidx, _hread, - hinner⟩ := - attesterDecode_multiRevoke_inner_decode_at - (v := v) (I := I) (callargs := callargs) (schemaUids := schemaUids) - (inner := uids) (idx := idx) hdec hSchemaUids hlookupOuter - obtain ⟨uidWord, hshape⟩ := - decodeABIValue_dynamicArray_bytes32_lookup_shape - (bytes := I.calldata.toList.drop 4) - (start := (calldataWord I.calldata 36).toNat + 32 + relativeOffset) - (endOffset := innerEnd) hinner (lookupNth?_some_length hlookupUid) - have hreadUid := - decodeABIValue_dynamicArray_bytes32_lookup_readNat - (bytes := I.calldata.toList.drop 4) - (start := (calldataWord I.calldata 36).toNat + 32 + relativeOffset) - (endOffset := innerEnd) hinner hshape - have hwordNat : - uidWord.toNat = - (calldataWord I.calldata - (4 + ((calldataWord I.calldata 36).toNat + 32 + relativeOffset + 32 + - 32 * j))).toNat := by - simpa [Nat.add_assoc] using - (readNat_drop4_at_some_eq_calldataWord (cd := I.calldata) hreadUid) - refine ⟨relativeOffset, uidWord, ?_, ?_⟩ - · rw [hlookupUid] at hshape - cases hshape - exact attesterBytes32ValueWord?_of_toBytesBE uidWord - · exact u256_inj hwordNat - -theorem attesterDecode_multiRevoke_uid_word_at_payload (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} {schemaUids uids : List Value} - {idx j : Nat} {uid : Value} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hSchemaUids : callargs.get? "schemaUids" = some (.array schemaUids)) - (hlookupOuter : lookupNth? schemaUids idx = some (.array uids)) - (hlookupUid : lookupNth? uids j = some uid) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hsizeSigned : I.calldata.size < 2 ^ 255) : - ∃ uidWord, - attesterBytes32ValueWord? uid = some uidWord ∧ - uidWord = - calldataWord I.calldata - ((attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat + - 32 * j) := by - obtain ⟨len, relativeOffset, innerEnd, hlenRead, hlenMax, hidx, hreadAt, - hinner⟩ := - attesterDecode_multiRevoke_inner_decode_at - (v := v) (I := I) (callargs := callargs) (schemaUids := schemaUids) - (inner := uids) (idx := idx) hdec hSchemaUids hlookupOuter - obtain ⟨uidWord, hshape⟩ := - decodeABIValue_dynamicArray_bytes32_lookup_shape - (bytes := I.calldata.toList.drop 4) - (start := (calldataWord I.calldata 36).toNat + 32 + relativeOffset) - (endOffset := innerEnd) hinner (lookupNth?_some_length hlookupUid) - have hreadUid := - decodeABIValue_dynamicArray_bytes32_lookup_readNat - (bytes := I.calldata.toList.drop 4) - (start := (calldataWord I.calldata 36).toNat + 32 + relativeOffset) - (endOffset := innerEnd) hinner hshape - have hsize : I.calldata.size < UInt256.size := lt_size_of_lt_sign hsizeSigned - have hdropLen : (I.calldata.toList.drop 4).length = I.calldata.size - 4 := by - rw [List.length_drop] - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [htlen] - have hreadUidSize := readNat?_some_length hreadUid - have hlenLeU64 : len ≤ solcMaxU64 := - Nat.le_of_not_gt (by simpa [solcMaxLen] using hlenMax) - have hidxSize : idx < UInt256.size := by - norm_num [solcMaxU64, UInt256.size] at hlenLeU64 ⊢ - omega - have hidxWordToNat : (UInt256.ofNat idx).toNat = idx := - ulit_toNat' idx hidxSize - have hoffLe : (calldataWord I.calldata 36).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - have hbaseToNat : - (attesterSecondArrayPayloadStartWord I).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 := - attesterSecondArrayPayloadStart_toNat (I := I) hoffMax - have hmulToNat : - (UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat idx)).toNat = - 32 * idx := by - rw [u256_mul_toNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide, hidxWordToNat] - exact Nat.mod_eq_of_lt (by - norm_num [solcMaxU64, UInt256.size] at hlenLeU64 ⊢ - omega) - have hheadToNat : - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx)).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 + 32 * idx := by - unfold attesterMultiRevokeInnerArrayHeadWord - rw [uadd_toNat, hbaseToNat, hmulToNat] - exact Nat.mod_eq_of_lt (by - norm_num [solcMaxU64, UInt256.size] at hoffLe hlenLeU64 ⊢ - omega) - have hoffWordToNat : - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat = - relativeOffset := by - unfold attesterMultiRevokeInnerArrayOffsetWord - rw [hheadToNat] - have hreadEq := - readNat_drop4_at_some_eq_calldataWord (cd := I.calldata) hreadAt - simpa [Nat.add_assoc] using hreadEq.symm - have hstartToNat : - (attesterMultiRevokeInnerArrayStartWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 + relativeOffset := by - unfold attesterMultiRevokeInnerArrayStartWord - rw [uadd_toNat, hbaseToNat, hoffWordToNat] - exact Nat.mod_eq_of_lt (by - rw [hdropLen] at hreadUidSize - omega) - have hpayloadToNat : - (attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 + relativeOffset + 32 := by - unfold attesterMultiRevokeInnerArrayPayloadWord - rw [uadd_toNat, hstartToNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide] - exact Nat.mod_eq_of_lt (by - rw [hdropLen] at hreadUidSize - omega) - have hwordNat : - uidWord.toNat = - (calldataWord I.calldata - ((attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat + - 32 * j)).toNat := by - rw [hpayloadToNat] - simpa [Nat.add_assoc] using - (readNat_drop4_at_some_eq_calldataWord (cd := I.calldata) hreadUid) - refine ⟨uidWord, ?_, ?_⟩ - · rw [hlookupUid] at hshape - cases hshape - exact attesterBytes32ValueWord?_of_toBytesBE uidWord - · exact u256_inj hwordNat - -theorem attesterDecode_multiRevoke_uid_word_at_copy_payload (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} {schemaUids uids : List Value} - {idx j : Nat} {uid : Value} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hSchemaUids : callargs.get? "schemaUids" = some (.array schemaUids)) - (hlookupOuter : lookupNth? schemaUids idx = some (.array uids)) - (hlookupUid : lookupNth? uids j = some uid) - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hsizeSigned : I.calldata.size < 2 ^ 255) : - ∃ uidWord, - attesterBytes32ValueWord? uid = some uidWord ∧ - uidWord = - calldataWord I.calldata - (attesterMultiRevokeInnerArrayCopyCalldataOffset - (attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) - (UInt256.ofNat j)).toNat := by - obtain ⟨uidWord, huidWord, huidPayloadEq⟩ := - attesterDecode_multiRevoke_uid_word_at_payload - (v := v) (I := I) (callargs := callargs) (schemaUids := schemaUids) - (uids := uids) (idx := idx) (j := j) (uid := uid) - hdec hSchemaUids hlookupOuter hlookupUid hoffMax hsizeSigned - obtain ⟨len, relativeOffset, innerEnd, hlenRead, hlenMax, hidx, hreadAt, - hinner⟩ := - attesterDecode_multiRevoke_inner_decode_at - (v := v) (I := I) (callargs := callargs) (schemaUids := schemaUids) - (inner := uids) (idx := idx) hdec hSchemaUids hlookupOuter - obtain ⟨uidWord', hshape⟩ := - decodeABIValue_dynamicArray_bytes32_lookup_shape - (bytes := I.calldata.toList.drop 4) - (start := (calldataWord I.calldata 36).toNat + 32 + relativeOffset) - (endOffset := innerEnd) hinner (lookupNth?_some_length hlookupUid) - have hreadUid := - decodeABIValue_dynamicArray_bytes32_lookup_readNat - (bytes := I.calldata.toList.drop 4) - (start := (calldataWord I.calldata 36).toNat + 32 + relativeOffset) - (endOffset := innerEnd) hinner hshape - have hsize : I.calldata.size < UInt256.size := lt_size_of_lt_sign hsizeSigned - have hdropLen : (I.calldata.toList.drop 4).length = I.calldata.size - 4 := by - rw [List.length_drop] - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [htlen] - have hreadUidSize := readNat?_some_length hreadUid - have hoffLe : (calldataWord I.calldata 36).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - have hlenLeU64 : len ≤ solcMaxU64 := - Nat.le_of_not_gt (by simpa [solcMaxLen] using hlenMax) - have hidxSize : idx < UInt256.size := by - norm_num [solcMaxU64, UInt256.size] at hlenLeU64 ⊢ - omega - have hidxWordToNat : (UInt256.ofNat idx).toNat = idx := - ulit_toNat' idx hidxSize - have hbaseToNat : - (attesterSecondArrayPayloadStartWord I).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 := - attesterSecondArrayPayloadStart_toNat (I := I) hoffMax - have hmulToNat : - (UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat idx)).toNat = - 32 * idx := by - rw [u256_mul_toNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide, hidxWordToNat] - exact Nat.mod_eq_of_lt (by - norm_num [solcMaxU64, UInt256.size] at hlenLeU64 ⊢ - omega) - have hheadToNat : - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx)).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 + 32 * idx := by - unfold attesterMultiRevokeInnerArrayHeadWord - rw [uadd_toNat, hbaseToNat, hmulToNat] - exact Nat.mod_eq_of_lt (by - norm_num [solcMaxU64, UInt256.size] at hoffLe hlenLeU64 ⊢ - omega) - have hoffWordToNat : - (attesterMultiRevokeInnerArrayOffsetWord I - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat = - relativeOffset := by - unfold attesterMultiRevokeInnerArrayOffsetWord - rw [hheadToNat] - have hreadEq := - readNat_drop4_at_some_eq_calldataWord (cd := I.calldata) hreadAt - simpa [Nat.add_assoc] using hreadEq.symm - have hstartToNat : - (attesterMultiRevokeInnerArrayStartWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 + relativeOffset := by - unfold attesterMultiRevokeInnerArrayStartWord - rw [uadd_toNat, hbaseToNat, hoffWordToNat] - exact Nat.mod_eq_of_lt (by - rw [hdropLen] at hreadUidSize - omega) - have hpayloadToNat : - (attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 + relativeOffset + 32 := by - unfold attesterMultiRevokeInnerArrayPayloadWord - rw [uadd_toNat, hstartToNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide] - exact Nat.mod_eq_of_lt (by - rw [hdropLen] at hreadUidSize - omega) - have hpayloadElemBound : - (attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat + - 32 * j < UInt256.size := by - rw [hpayloadToNat] - rw [hdropLen] at hreadUidSize - omega - have hjSize : j < UInt256.size := by - exact lt_of_le_of_lt (by - show j ≤ - (attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat + - 32 * j - omega) hpayloadElemBound - have hcopyOffsetToNat : - (attesterMultiRevokeInnerArrayCopyCalldataOffset - (attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) - (UInt256.ofNat j)).toNat = - (attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))).toNat + - 32 * j := - attesterMultiRevokeInnerArrayCopyCalldataOffset_toNat - (payload := - attesterMultiRevokeInnerArrayPayloadWord I - (attesterSecondArrayPayloadStartWord I) - (attesterMultiRevokeInnerArrayHeadWord - (attesterSecondArrayPayloadStartWord I) (UInt256.ofNat idx))) - (j := j) hjSize hpayloadElemBound - refine ⟨uidWord, huidWord, ?_⟩ - rw [huidPayloadEq, hcopyOffsetToNat] - -def attesterMultiRevokeRequestPtr - (mem : ByteArray) (aw outerBase : UInt256) (idx : Nat) : UInt256 := - attesterMloadWord mem aw - (attesterMultiRevokePostCopyOuterSlotWord outerBase (UInt256.ofNat idx)) - -def attesterMultiRevokeRequestDataPtr - (mem : ByteArray) (aw outerBase : UInt256) (idx : Nat) : UInt256 := - attesterMloadWord mem aw - ((⟨32⟩ : UInt256) + attesterMultiRevokeRequestPtr mem aw outerBase idx) - -def attesterMultiRevokeRequestDataElemPtr - (mem : ByteArray) (aw outerBase : UInt256) (idx j : Nat) : UInt256 := - attesterMloadWord mem aw - ((⟨32⟩ : UInt256) + - UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat j) + - attesterMultiRevokeRequestDataPtr mem aw outerBase idx) - -def attesterMultiRevokeInnerCopyTuplePtrNat - (base len : UInt256) (j : Nat) : Nat := - base.toNat + 32 + 96 * len.toNat + 64 * j - -def attesterMultiRevokeInnerCopyTuplePtr - (base len : UInt256) (j : Nat) : UInt256 := - UInt256.ofNat (attesterMultiRevokeInnerCopyTuplePtrNat base len j) - -theorem attesterMultiRevokeInnerCopyTuplePtr_toNat - {base len : UInt256} {j : Nat} - (hbound : attesterMultiRevokeInnerCopyTuplePtrNat base len j < UInt256.size) : - (attesterMultiRevokeInnerCopyTuplePtr base len j).toNat = - attesterMultiRevokeInnerCopyTuplePtrNat base len j := by - exact ulit_toNat' (attesterMultiRevokeInnerCopyTuplePtrNat base len j) hbound - -theorem attesterMultiRevokeInnerCopyTuplePtr_add32_toNat - {base len : UInt256} {j : Nat} - (hbound : attesterMultiRevokeInnerCopyTuplePtrNat base len j + 32 < UInt256.size) : - ((⟨32⟩ : UInt256) + attesterMultiRevokeInnerCopyTuplePtr base len j).toNat = - attesterMultiRevokeInnerCopyTuplePtrNat base len j + 32 := by - have hptrBound : attesterMultiRevokeInnerCopyTuplePtrNat base len j < UInt256.size := by - omega - rw [uadd_toNat] - rw [attesterMultiRevokeInnerCopyTuplePtr_toNat hptrBound] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - rw [show 32 + attesterMultiRevokeInnerCopyTuplePtrNat base len j = - attesterMultiRevokeInnerCopyTuplePtrNat base len j + 32 by omega] - exact Nat.mod_eq_of_lt hbound - -def AttesterMultiRevokeInnerCopyReadLayout - (I : ExecutionEnv) (base len payload : UInt256) (copied : Nat) - (mem : ByteArray) : Prop := - ∀ {j : Nat}, j < copied → - let slot := attesterMultiRevokeInnerArrayCopySlotWord base (UInt256.ofNat j) - let ptr := attesterMultiRevokeInnerCopyTuplePtr base len j - slot.toNat + 32 ≤ mem.size ∧ - ptr.toNat + 32 ≤ mem.size ∧ - ((⟨32⟩ : UInt256) + ptr).toNat + 32 ≤ mem.size ∧ - mem.readWithPadding slot.toNat 32 = UInt256.toByteArray ptr ∧ - mem.readWithPadding ptr.toNat 32 = - UInt256.toByteArray - (calldataWord I.calldata - (attesterMultiRevokeInnerArrayCopyCalldataOffset payload - (UInt256.ofNat j)).toNat) ∧ - mem.readWithPadding ((⟨32⟩ : UInt256) + ptr).toNat 32 = - UInt256.toByteArray (⟨0⟩ : UInt256) - -theorem AttesterMultiRevokeInnerCopyReadLayout_zero - (I : ExecutionEnv) (base len payload : UInt256) (mem : ByteArray) : - AttesterMultiRevokeInnerCopyReadLayout I base len payload 0 mem := by - intro j hlt - omega - -theorem AttesterMultiRevokeInnerCopyReadLayout_mono - {I : ExecutionEnv} {base len payload : UInt256} {i j : Nat} - {mem : ByteArray} - (hle : i ≤ j) - (h : AttesterMultiRevokeInnerCopyReadLayout I base len payload j mem) : - AttesterMultiRevokeInnerCopyReadLayout I base len payload i mem := by - intro idx hidx - exact h (by omega) - -set_option maxHeartbeats 1000000 in -theorem AttesterMultiRevokeInnerCopyReadLayout_step - {I : ExecutionEnv} {base len payload idx : UInt256} - {mem : ByteArray} {aw : UInt256} {n : Nat} - (hidx : idx = UInt256.ofNat (len.toNat - (n + 1))) - (hle : n + 1 ≤ len.toNat) - (hbaseGe : 64 + 32 ≤ base.toNat) - (hbaseSlot63 : base.toNat + 32 + 32 * len.toNat + 63 < UInt256.size) - (hfreeExact : - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat = - base.toNat + 32 + 96 * len.toNat + 64 * (len.toNat - (n + 1))) - (hfreeSpare : - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + - 64 * (n + 1) + 96 < UInt256.size) - (hLayout : - AttesterMultiRevokeInnerCopyReadLayout I base len payload - (len.toNat - (n + 1)) mem) : - AttesterMultiRevokeInnerCopyReadLayout I base len payload - (len.toNat - n) - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw) := by - classical - let oldCopied := len.toNat - (n + 1) - let free := attesterMultiRevokeInnerArrayCopyFreeWord mem aw - let zero := attesterMultiRevokeInnerArrayCopyZeroWord mem aw - let curSlot := attesterMultiRevokeInnerArrayCopySlotWord base idx - have hidxToNat : idx.toNat = oldCopied := by - rw [hidx] - exact ulit_toNat' oldCopied (by - unfold oldCopied - exact lt_of_le_of_lt (Nat.sub_le _ _) len.val.isLt) - have hcurSlotToNat : - curSlot.toNat = base.toNat + 32 + 32 * oldCopied := by - unfold curSlot - rw [attesterMultiRevokeInnerArrayCopySlotWord_toNat] - · rw [hidxToNat] - · rw [hidxToNat] - unfold oldCopied - have hmul : 32 * (len.toNat - (n + 1)) ≤ 32 * len.toNat := - Nat.mul_le_mul_left 32 (Nat.sub_le _ _) - omega - have hfree32 : free.toNat + 32 < UInt256.size := by - change (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + 32 < - UInt256.size - omega - have hzeroToNat : zero.toNat = free.toNat + 32 := by - unfold zero free - exact attesterMultiRevokeInnerArrayCopyZeroWord_toNat hfree32 - have hnewCopied : len.toNat - n = oldCopied + 1 := by - unfold oldCopied - omega - intro j hj - by_cases hOld : j < oldCopied - · have hOldLayout := hLayout (j := j) hOld - dsimp only [AttesterMultiRevokeInnerCopyReadLayout] at hOldLayout - let slot := attesterMultiRevokeInnerArrayCopySlotWord base (UInt256.ofNat j) - let ptr := attesterMultiRevokeInnerCopyTuplePtr base len j - have hjLtLen : j < len.toNat := by - exact lt_of_lt_of_le hOld (by - unfold oldCopied - exact Nat.sub_le _ _) - have hslotBound : - base.toNat + 32 + 32 * j + 63 < UInt256.size := by - have hjle : j ≤ len.toNat := le_of_lt hjLtLen - have hmul : 32 * j ≤ 32 * len.toNat := Nat.mul_le_mul_left 32 hjle - omega - have hslotToNat : slot.toNat = base.toNat + 32 + 32 * j := by - unfold slot - rw [attesterMultiRevokeInnerArrayCopySlotWord_toNat] - · rw [ulit_toNat' j (lt_trans hjLtLen len.val.isLt)] - · rw [ulit_toNat' j (lt_trans hjLtLen len.val.isLt)] - omega - have hptrToNat : - ptr.toNat = base.toNat + 32 + 96 * len.toNat + 64 * j := by - unfold ptr - exact attesterMultiRevokeInnerCopyTuplePtr_toNat (by - unfold attesterMultiRevokeInnerCopyTuplePtrNat - omega) - have hptr32ToNat : - ((⟨32⟩ : UInt256) + ptr).toNat = - base.toNat + 32 + 96 * len.toNat + 64 * j + 32 := by - rw [attesterMultiRevokeInnerCopyTuplePtr_add32_toNat] - · unfold attesterMultiRevokeInnerCopyTuplePtrNat - rfl - · unfold attesterMultiRevokeInnerCopyTuplePtrNat - omega - rcases hOldLayout with - ⟨hslotMem, hptrMem, hptr32Mem, hslotRead, hptrRead, hptr32Read⟩ - have hslotPreserve : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - slot.toNat 32 = - UInt256.toByteArray ptr := by - exact attesterMultiRevokeInnerArrayCopyStep_readWithPadding_at_nat_disj - (I := I) (readBase := slot) (base := base) (payload := payload) - (idx := idx) (len := ptr) (mem := mem) (aw := aw) - hslotMem hslotRead - (by rw [hslotToNat]; omega) - (by rw [hslotToNat, hfreeExact]; unfold oldCopied at hOld; omega) - (by rw [hslotToNat, hzeroToNat, hfreeExact]; unfold oldCopied at hOld; omega) - (by - rw [hslotToNat, hcurSlotToNat] - exact Or.inl (by unfold oldCopied at hOld; omega)) - have hptrPreserve : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - ptr.toNat 32 = - UInt256.toByteArray - (calldataWord I.calldata - (attesterMultiRevokeInnerArrayCopyCalldataOffset payload - (UInt256.ofNat j)).toNat) := by - exact attesterMultiRevokeInnerArrayCopyStep_readWithPadding_at_nat_disj - (I := I) (readBase := ptr) (base := base) (payload := payload) - (idx := idx) - (len := - calldataWord I.calldata - (attesterMultiRevokeInnerArrayCopyCalldataOffset payload - (UInt256.ofNat j)).toNat) - (mem := mem) (aw := aw) - hptrMem hptrRead - (by rw [hptrToNat]; omega) - (by rw [hptrToNat, hfreeExact]; unfold oldCopied at hOld; omega) - (by rw [hptrToNat, hzeroToNat, hfreeExact]; unfold oldCopied at hOld; omega) - (by - rw [hptrToNat, hcurSlotToNat] - exact Or.inr (by unfold oldCopied at hOld; omega)) - have hptr32Preserve : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - ((⟨32⟩ : UInt256) + ptr).toNat 32 = - UInt256.toByteArray (⟨0⟩ : UInt256) := by - exact attesterMultiRevokeInnerArrayCopyStep_readWithPadding_at_nat_disj - (I := I) (readBase := ((⟨32⟩ : UInt256) + ptr)) - (base := base) (payload := payload) (idx := idx) - (len := (⟨0⟩ : UInt256)) (mem := mem) (aw := aw) - hptr32Mem hptr32Read - (by rw [hptr32ToNat]; omega) - (by rw [hptr32ToNat, hfreeExact]; unfold oldCopied at hOld; omega) - (by rw [hptr32ToNat, hzeroToNat, hfreeExact]; unfold oldCopied at hOld; omega) - (by - rw [hptr32ToNat, hcurSlotToNat] - exact Or.inr (by unfold oldCopied at hOld; omega)) - exact - ⟨le_trans hslotMem attesterMultiRevokeInnerArrayCopyStep_size_ge, - le_trans hptrMem attesterMultiRevokeInnerArrayCopyStep_size_ge, - le_trans hptr32Mem attesterMultiRevokeInnerArrayCopyStep_size_ge, - hslotPreserve, hptrPreserve, hptr32Preserve⟩ - · have hjEq : j = oldCopied := by - rw [hnewCopied] at hj - omega - subst j - let slot := attesterMultiRevokeInnerArrayCopySlotWord base (UInt256.ofNat oldCopied) - let ptr := attesterMultiRevokeInnerCopyTuplePtr base len oldCopied - have hslotEq : slot = curSlot := by - unfold slot curSlot - rw [hidx] - have hptrToNat : ptr.toNat = free.toNat := by - unfold ptr free - rw [attesterMultiRevokeInnerCopyTuplePtr_toNat] - · rw [hfreeExact] - unfold attesterMultiRevokeInnerCopyTuplePtrNat oldCopied - rfl - · unfold attesterMultiRevokeInnerCopyTuplePtrNat oldCopied - omega - have hptrEq : ptr = free := by - apply u256_inj - exact hptrToNat - have hptr32ToNat : ((⟨32⟩ : UInt256) + ptr).toNat = zero.toNat := by - rw [attesterMultiRevokeInnerCopyTuplePtr_add32_toNat] - · have hptrNat : - attesterMultiRevokeInnerCopyTuplePtrNat base len oldCopied = free.toNat := by - unfold attesterMultiRevokeInnerCopyTuplePtrNat oldCopied free - rw [hfreeExact] - rw [hptrNat, hzeroToNat] - · unfold attesterMultiRevokeInnerCopyTuplePtrNat oldCopied - omega - have hslotBelowFree : curSlot.toNat + 32 ≤ free.toNat := by - rw [hcurSlotToNat, hfreeExact] - unfold oldCopied - have hleOld : len.toNat - (n + 1) ≤ len.toNat := Nat.sub_le _ _ - have hmul : 32 * (len.toNat - (n + 1)) ≤ 96 * len.toNat := by - have hmul32 : 32 * (len.toNat - (n + 1)) ≤ 32 * len.toNat := - Nat.mul_le_mul_left 32 hleOld - nlinarith - omega - have hslotBelowZero : curSlot.toNat + 32 ≤ zero.toNat := by - rw [hzeroToNat] - omega - have hstepSizeSlot : - slot.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).size := by - rw [hslotEq] - change curSlot.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - curSlot.toNat free).size - rw [attesterWriteWord_size_nat] - exact Nat.le_max_right _ _ - have hstepSizePtr : - ptr.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).size := by - rw [hptrToNat] - change free.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - curSlot.toNat free).size - rw [attesterWriteWord_size_nat] - apply le_trans _ (Nat.le_max_left _ _) - change free.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - zero.toNat (⟨0⟩ : UInt256)).size - exact le_trans - (by - change free.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - free.toNat (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)).size - rw [attesterWriteWord_size_nat] - exact Nat.le_max_right _ _) - (attesterWriteWord_size_ge_nat - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - zero.toNat (⟨0⟩ : UInt256)) - have hstepSizePtr32 : - ((⟨32⟩ : UInt256) + ptr).toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).size := by - rw [hptr32ToNat] - change zero.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - curSlot.toNat free).size - rw [attesterWriteWord_size_nat] - apply le_trans _ (Nat.le_max_left _ _) - change zero.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - zero.toNat (⟨0⟩ : UInt256)).size - rw [attesterWriteWord_size_nat] - exact Nat.le_max_right _ _ - have hslotRead : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - slot.toNat 32 = - UInt256.toByteArray ptr := by - rw [hslotEq, hptrEq] - exact attesterMultiRevokeInnerArrayCopyStep_read_current_slot - (I := I) (base := base) (payload := payload) (idx := idx) - (mem := mem) (aw := aw) - have hptrRead : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - ptr.toNat 32 = - UInt256.toByteArray - (calldataWord I.calldata - (attesterMultiRevokeInnerArrayCopyCalldataOffset payload - (UInt256.ofNat oldCopied)).toNat) := by - rw [hptrToNat] - have huid := - attesterMultiRevokeInnerArrayCopyStep_read_current_uid - (I := I) (base := base) (payload := payload) (idx := idx) - (mem := mem) (aw := aw) hzeroToNat (Or.inr hslotBelowFree) - have hidxEq : idx = UInt256.ofNat oldCopied := by - simpa [oldCopied] using hidx - simpa [attesterMultiRevokeInnerArrayCopyUidWord, hidxEq] using huid - have hptr32Read : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - ((⟨32⟩ : UInt256) + ptr).toNat 32 = - UInt256.toByteArray (⟨0⟩ : UInt256) := by - rw [hptr32ToNat] - exact attesterMultiRevokeInnerArrayCopyStep_read_current_zero - (I := I) (base := base) (payload := payload) (idx := idx) - (mem := mem) (aw := aw) (Or.inr hslotBelowZero) - exact - ⟨hstepSizeSlot, hstepSizePtr, hstepSizePtr32, - hslotRead, hptrRead, hptr32Read⟩ - -def AttesterMultiRevokeRequestMemoryLayoutAt - (schemas schemaUids : List Value) (mem : ByteArray) (aw outerBase : UInt256) - (idx : Nat) : Prop := - ∀ {schema uids}, - lookupNth? schemas idx = some schema → - lookupNth? schemaUids idx = some (.array uids) → - ∃ schemaWord, - attesterBytes32ValueWord? schema = some schemaWord ∧ - attesterMloadWord mem aw - (attesterMultiRevokeRequestPtr mem aw outerBase idx) = schemaWord ∧ - attesterMloadWord mem aw - (attesterMultiRevokeRequestDataPtr mem aw outerBase idx) = - UInt256.ofNat uids.length ∧ - ∀ {j uid}, - lookupNth? uids j = some uid → - ∃ uidWord, - attesterBytes32ValueWord? uid = some uidWord ∧ - attesterMloadWord mem aw - (attesterMultiRevokeRequestDataElemPtr mem aw outerBase idx j) = - uidWord ∧ - attesterMloadWord mem aw - ((⟨32⟩ : UInt256) + - attesterMultiRevokeRequestDataElemPtr mem aw outerBase idx j) = - (⟨0⟩ : UInt256) - -def AttesterMultiRevokeRequestsMemoryLayout - (schemas schemaUids : List Value) (i : Nat) - (mem : ByteArray) (aw outerBase : UInt256) : Prop := - ∀ {idx}, idx < i → - AttesterMultiRevokeRequestMemoryLayoutAt schemas schemaUids mem aw outerBase idx - -def AttesterMultiRevokeRequestReadLayoutAt - (schemas schemaUids : List Value) (mem : ByteArray) (outerBase : UInt256) - (idx : Nat) : Prop := - ∀ {schema uids}, - lookupNth? schemas idx = some schema → - lookupNth? schemaUids idx = some (.array uids) → - ∃ schemaWord reqPtr dataPtr, - attesterBytes32ValueWord? schema = some schemaWord ∧ - let slot := attesterMultiRevokePostCopyOuterSlotWord outerBase (UInt256.ofNat idx) - slot.toNat + 32 ≤ mem.size ∧ - mem.readWithPadding slot.toNat 32 = UInt256.toByteArray reqPtr ∧ - reqPtr.toNat + 32 ≤ mem.size ∧ - ((⟨32⟩ : UInt256) + reqPtr).toNat + 32 ≤ mem.size ∧ - mem.readWithPadding reqPtr.toNat 32 = UInt256.toByteArray schemaWord ∧ - mem.readWithPadding ((⟨32⟩ : UInt256) + reqPtr).toNat 32 = - UInt256.toByteArray dataPtr ∧ - dataPtr.toNat + 32 ≤ mem.size ∧ - mem.readWithPadding dataPtr.toNat 32 = - UInt256.toByteArray (UInt256.ofNat uids.length) ∧ - ∀ {j uid}, - lookupNth? uids j = some uid → - ∃ uidWord elemPtr, - attesterBytes32ValueWord? uid = some uidWord ∧ - let elemSlot := (⟨32⟩ : UInt256) + - UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat j) + dataPtr - elemSlot.toNat + 32 ≤ mem.size ∧ - mem.readWithPadding elemSlot.toNat 32 = UInt256.toByteArray elemPtr ∧ - elemPtr.toNat + 32 ≤ mem.size ∧ - ((⟨32⟩ : UInt256) + elemPtr).toNat + 32 ≤ mem.size ∧ - mem.readWithPadding elemPtr.toNat 32 = UInt256.toByteArray uidWord ∧ - mem.readWithPadding ((⟨32⟩ : UInt256) + elemPtr).toNat 32 = - UInt256.toByteArray (⟨0⟩ : UInt256) - -def AttesterMultiRevokeRequestsReadLayout - (schemas schemaUids : List Value) (i : Nat) - (mem : ByteArray) (outerBase : UInt256) : Prop := - ∀ {idx}, idx < i → - AttesterMultiRevokeRequestReadLayoutAt schemas schemaUids mem outerBase idx - -def AttesterMultiRevokeRequestReadLayoutAtBounded - (schemas schemaUids : List Value) (mem : ByteArray) (outerBase : UInt256) - (contentLo bound idx : Nat) : Prop := - ∀ {schema uids}, - lookupNth? schemas idx = some schema → - lookupNth? schemaUids idx = some (.array uids) → - ∃ schemaWord reqPtr dataPtr, - attesterBytes32ValueWord? schema = some schemaWord ∧ - let slot := attesterMultiRevokePostCopyOuterSlotWord outerBase (UInt256.ofNat idx) - 64 + 32 ≤ slot.toNat ∧ - slot.toNat + 32 ≤ bound ∧ - slot.toNat + 32 ≤ mem.size ∧ - mem.readWithPadding slot.toNat 32 = UInt256.toByteArray reqPtr ∧ - contentLo ≤ reqPtr.toNat ∧ - reqPtr.toNat + 32 ≤ bound ∧ - reqPtr.toNat + 32 ≤ mem.size ∧ - contentLo ≤ ((⟨32⟩ : UInt256) + reqPtr).toNat ∧ - ((⟨32⟩ : UInt256) + reqPtr).toNat + 32 ≤ bound ∧ - ((⟨32⟩ : UInt256) + reqPtr).toNat + 32 ≤ mem.size ∧ - mem.readWithPadding reqPtr.toNat 32 = UInt256.toByteArray schemaWord ∧ - mem.readWithPadding ((⟨32⟩ : UInt256) + reqPtr).toNat 32 = - UInt256.toByteArray dataPtr ∧ - contentLo ≤ dataPtr.toNat ∧ - dataPtr.toNat + 32 ≤ bound ∧ - dataPtr.toNat + 32 ≤ mem.size ∧ - mem.readWithPadding dataPtr.toNat 32 = - UInt256.toByteArray (UInt256.ofNat uids.length) ∧ - ∀ {j uid}, - lookupNth? uids j = some uid → - ∃ uidWord elemPtr, - attesterBytes32ValueWord? uid = some uidWord ∧ - let elemSlot := (⟨32⟩ : UInt256) + - UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat j) + dataPtr - contentLo ≤ elemSlot.toNat ∧ - elemSlot.toNat + 32 ≤ bound ∧ - elemSlot.toNat + 32 ≤ mem.size ∧ - mem.readWithPadding elemSlot.toNat 32 = UInt256.toByteArray elemPtr ∧ - contentLo ≤ elemPtr.toNat ∧ - elemPtr.toNat + 32 ≤ bound ∧ - elemPtr.toNat + 32 ≤ mem.size ∧ - contentLo ≤ ((⟨32⟩ : UInt256) + elemPtr).toNat ∧ - ((⟨32⟩ : UInt256) + elemPtr).toNat + 32 ≤ bound ∧ - ((⟨32⟩ : UInt256) + elemPtr).toNat + 32 ≤ mem.size ∧ - mem.readWithPadding elemPtr.toNat 32 = UInt256.toByteArray uidWord ∧ - mem.readWithPadding ((⟨32⟩ : UInt256) + elemPtr).toNat 32 = - UInt256.toByteArray (⟨0⟩ : UInt256) - -def AttesterMultiRevokeRequestsReadLayoutBounded - (schemas schemaUids : List Value) (i : Nat) - (mem : ByteArray) (outerBase : UInt256) (contentLo bound : Nat) : Prop := - ∀ {idx}, idx < i → - AttesterMultiRevokeRequestReadLayoutAtBounded - schemas schemaUids mem outerBase contentLo bound idx - -theorem AttesterMultiRevokeRequestReadLayoutAtBounded.to_readLayout - {schemas schemaUids : List Value} {mem : ByteArray} {outerBase : UInt256} - {contentLo bound idx : Nat} - (h : - AttesterMultiRevokeRequestReadLayoutAtBounded - schemas schemaUids mem outerBase contentLo bound idx) : - AttesterMultiRevokeRequestReadLayoutAt schemas schemaUids mem outerBase idx := by - intro schema uids hschema huids - rcases h hschema huids with - ⟨schemaWord, reqPtr, dataPtr, hschemaWord, hslot64, hslotBound, hslotMem, - hslotRead, hreqLo, hreqBound, hreqMem, hreq32Lo, hreq32Bound, hreq32Mem, - hschemaRead, hdataPtrRead, hdataLo, hdataBound, hdataMem, hdataRead, - huidsRead⟩ - refine ⟨schemaWord, reqPtr, dataPtr, hschemaWord, hslotMem, hslotRead, - hreqMem, hreq32Mem, hschemaRead, hdataPtrRead, hdataMem, hdataRead, ?_⟩ - intro j uid huid - rcases huidsRead huid with - ⟨uidWord, elemPtr, huidWord, helemSlotLo, helemSlotBound, helemSlotMem, - helemSlotRead, helemPtrLo, helemPtrBound, helemPtrMem, helemPtr32Lo, - helemPtr32Bound, helemPtr32Mem, helemRead, helemExtraRead⟩ - exact ⟨uidWord, elemPtr, huidWord, helemSlotMem, helemSlotRead, - helemPtrMem, helemPtr32Mem, helemRead, helemExtraRead⟩ - -theorem AttesterMultiRevokeRequestsReadLayoutBounded.to_readLayout - {schemas schemaUids : List Value} {i : Nat} - {mem : ByteArray} {outerBase : UInt256} {contentLo bound : Nat} - (h : - AttesterMultiRevokeRequestsReadLayoutBounded - schemas schemaUids i mem outerBase contentLo bound) : - AttesterMultiRevokeRequestsReadLayout schemas schemaUids i mem outerBase := by - intro idx hidx - exact AttesterMultiRevokeRequestReadLayoutAtBounded.to_readLayout (h hidx) - -theorem AttesterMultiRevokeRequestsReadLayout_zero - (schemas schemaUids : List Value) (mem : ByteArray) (outerBase : UInt256) : - AttesterMultiRevokeRequestsReadLayout schemas schemaUids 0 mem outerBase := by - intro idx hidx - omega - -theorem AttesterMultiRevokeRequestsReadLayoutBounded_zero - (schemas schemaUids : List Value) (mem : ByteArray) (outerBase : UInt256) - (contentLo bound : Nat) : - AttesterMultiRevokeRequestsReadLayoutBounded - schemas schemaUids 0 mem outerBase contentLo bound := by - intro idx hidx - omega - -theorem AttesterMultiRevokeRequestsReadLayout_mono - {schemas schemaUids : List Value} {i j : Nat} - {mem : ByteArray} {outerBase : UInt256} - (hle : i ≤ j) - (h : AttesterMultiRevokeRequestsReadLayout schemas schemaUids j mem outerBase) : - AttesterMultiRevokeRequestsReadLayout schemas schemaUids i mem outerBase := by - intro idx hidx - exact h (by omega) - -theorem AttesterMultiRevokeRequestsReadLayoutBounded_mono - {schemas schemaUids : List Value} {i j : Nat} - {mem : ByteArray} {outerBase : UInt256} {contentLo bound : Nat} - (hle : i ≤ j) - (h : - AttesterMultiRevokeRequestsReadLayoutBounded - schemas schemaUids j mem outerBase contentLo bound) : - AttesterMultiRevokeRequestsReadLayoutBounded - schemas schemaUids i mem outerBase contentLo bound := by - intro idx hidx - exact h (by omega) - -def AttesterReadPreservedBeforeExcept - (mem₀ mem₁ : ByteArray) (bound protectedSlot : Nat) : Prop := - ∀ {read : Nat} {word : UInt256}, - read + 32 ≤ mem₀.size → - mem₀.readWithPadding read 32 = UInt256.toByteArray word → - 64 + 32 ≤ read → - read + 32 ≤ bound → - (read + 32 ≤ protectedSlot ∨ protectedSlot + 32 ≤ read) → - read + 32 ≤ mem₁.size ∧ - mem₁.readWithPadding read 32 = UInt256.toByteArray word - -set_option maxHeartbeats 1000000 in -theorem AttesterMultiRevokeRequestReadLayoutAtBounded.preserve_except - {schemas schemaUids : List Value} - {mem mem' : ByteArray} {outerBase : UInt256} - {contentLo bound bound' protectedSlot idx : Nat} - (hcontentLo64 : 64 + 32 ≤ contentLo) - (hboundLe : bound ≤ bound') - (hownSlotDisj : - (attesterMultiRevokePostCopyOuterSlotWord outerBase (UInt256.ofNat idx)).toNat + 32 ≤ - protectedSlot) - (hcontentDisj : protectedSlot + 32 ≤ contentLo) - (hpres : AttesterReadPreservedBeforeExcept mem mem' bound protectedSlot) - (h : - AttesterMultiRevokeRequestReadLayoutAtBounded - schemas schemaUids mem outerBase contentLo bound idx) : - AttesterMultiRevokeRequestReadLayoutAtBounded - schemas schemaUids mem' outerBase contentLo bound' idx := by - intro schema uids hschema huids - rcases h hschema huids with - ⟨schemaWord, reqPtr, dataPtr, hschemaWord, hslot64, hslotBound, hslotMem, - hslotRead, hreqLo, hreqBound, hreqMem, hreq32Lo, hreq32Bound, hreq32Mem, - hschemaRead, hdataPtrRead, hdataLo, hdataBound, hdataMem, hdataRead, - huidsRead⟩ - let slot := attesterMultiRevokePostCopyOuterSlotWord outerBase (UInt256.ofNat idx) - have hslotPres := - hpres hslotMem hslotRead hslot64 hslotBound - (Or.inl (by simpa [slot] using hownSlotDisj)) - have hreq64 : 64 + 32 ≤ reqPtr.toNat := le_trans hcontentLo64 hreqLo - have hreqPres := - hpres hreqMem hschemaRead hreq64 hreqBound - (Or.inr (le_trans hcontentDisj hreqLo)) - have hreq32_64 : 64 + 32 ≤ ((⟨32⟩ : UInt256) + reqPtr).toNat := - le_trans hcontentLo64 hreq32Lo - have hreq32Pres := - hpres hreq32Mem hdataPtrRead hreq32_64 hreq32Bound - (Or.inr (le_trans hcontentDisj hreq32Lo)) - have hdata64 : 64 + 32 ≤ dataPtr.toNat := le_trans hcontentLo64 hdataLo - have hdataPres := - hpres hdataMem hdataRead hdata64 hdataBound - (Or.inr (le_trans hcontentDisj hdataLo)) - refine ⟨schemaWord, reqPtr, dataPtr, hschemaWord, hslot64, - le_trans hslotBound hboundLe, hslotPres.1, hslotPres.2, - hreqLo, le_trans hreqBound hboundLe, hreqPres.1, - hreq32Lo, le_trans hreq32Bound hboundLe, hreq32Pres.1, - hreqPres.2, hreq32Pres.2, - hdataLo, le_trans hdataBound hboundLe, hdataPres.1, hdataPres.2, ?_⟩ - intro j uid huid - rcases huidsRead huid with - ⟨uidWord, elemPtr, huidWord, helemSlotLo, helemSlotBound, helemSlotMem, - helemSlotRead, helemPtrLo, helemPtrBound, helemPtrMem, helemPtr32Lo, - helemPtr32Bound, helemPtr32Mem, helemRead, helemExtraRead⟩ - let elemSlot := (⟨32⟩ : UInt256) + - UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat j) + dataPtr - have helemSlot64 : 64 + 32 ≤ elemSlot.toNat := - le_trans hcontentLo64 helemSlotLo - have helemSlotPres := - hpres helemSlotMem helemSlotRead helemSlot64 helemSlotBound - (Or.inr (le_trans hcontentDisj helemSlotLo)) - have helemPtr64 : 64 + 32 ≤ elemPtr.toNat := - le_trans hcontentLo64 helemPtrLo - have helemPtrPres := - hpres helemPtrMem helemRead helemPtr64 helemPtrBound - (Or.inr (le_trans hcontentDisj helemPtrLo)) - have helemPtr32_64 : 64 + 32 ≤ ((⟨32⟩ : UInt256) + elemPtr).toNat := - le_trans hcontentLo64 helemPtr32Lo - have helemPtr32Pres := - hpres helemPtr32Mem helemExtraRead helemPtr32_64 helemPtr32Bound - (Or.inr (le_trans hcontentDisj helemPtr32Lo)) - exact ⟨uidWord, elemPtr, huidWord, helemSlotLo, - le_trans helemSlotBound hboundLe, helemSlotPres.1, helemSlotPres.2, - helemPtrLo, le_trans helemPtrBound hboundLe, helemPtrPres.1, - helemPtr32Lo, le_trans helemPtr32Bound hboundLe, helemPtr32Pres.1, - helemPtrPres.2, helemPtr32Pres.2⟩ - -theorem AttesterMultiRevokeRequestReadLayoutAt.to_mload - {schemas schemaUids : List Value} {mem : ByteArray} {aw outerBase : UInt256} - {idx : Nat} - (hactive : ∀ {off : UInt256}, off.toNat + 32 ≤ mem.size → ¬ off ≥ aw * (⟨32⟩ : UInt256)) - (hread : AttesterMultiRevokeRequestReadLayoutAt schemas schemaUids mem outerBase idx) : - AttesterMultiRevokeRequestMemoryLayoutAt schemas schemaUids mem aw outerBase idx := by - intro schema uids hschema huids - rcases hread hschema huids with - ⟨schemaWord, reqPtr, dataPtr, hschemaWord, hslotMem, hslotRead, - hreqMem, hreqDataMem, hschemaRead, hdataPtrRead, hdataMem, hdataRead, huidsRead⟩ - let slot := attesterMultiRevokePostCopyOuterSlotWord outerBase (UInt256.ofNat idx) - have hreqMload : - attesterMultiRevokeRequestPtr mem aw outerBase idx = reqPtr := by - dsimp [attesterMultiRevokeRequestPtr, slot] at hslotMem hslotRead ⊢ - exact attesterMloadWord_of_readWithPadding hslotMem (hactive hslotMem) hslotRead - have hschemaMload : - attesterMloadWord mem aw (attesterMultiRevokeRequestPtr mem aw outerBase idx) = - schemaWord := by - rw [hreqMload] - exact attesterMloadWord_of_readWithPadding hreqMem (hactive hreqMem) hschemaRead - have hdataPtrMload : - attesterMultiRevokeRequestDataPtr mem aw outerBase idx = dataPtr := by - dsimp [attesterMultiRevokeRequestDataPtr] - rw [hreqMload] - exact attesterMloadWord_of_readWithPadding hreqDataMem (hactive hreqDataMem) - hdataPtrRead - have hdataLenMload : - attesterMloadWord mem aw (attesterMultiRevokeRequestDataPtr mem aw outerBase idx) = - UInt256.ofNat uids.length := by - rw [hdataPtrMload] - exact attesterMloadWord_of_readWithPadding hdataMem (hactive hdataMem) hdataRead - refine ⟨schemaWord, hschemaWord, hschemaMload, hdataLenMload, ?_⟩ - intro j uid huid - rcases huidsRead huid with - ⟨uidWord, elemPtr, huidWord, helemSlotMem, helemSlotRead, - helemMem, helemExtraMem, helemRead, helemExtraRead⟩ - let elemSlot := (⟨32⟩ : UInt256) + - UInt256.mul (⟨32⟩ : UInt256) (UInt256.ofNat j) + dataPtr - have helemPtrMload : - attesterMultiRevokeRequestDataElemPtr mem aw outerBase idx j = elemPtr := by - dsimp [attesterMultiRevokeRequestDataElemPtr, elemSlot] - rw [hdataPtrMload] - exact attesterMloadWord_of_readWithPadding helemSlotMem (hactive helemSlotMem) - helemSlotRead - have huidMload : - attesterMloadWord mem aw - (attesterMultiRevokeRequestDataElemPtr mem aw outerBase idx j) = - uidWord := by - rw [helemPtrMload] - exact attesterMloadWord_of_readWithPadding helemMem (hactive helemMem) helemRead - have hextraMload : - attesterMloadWord mem aw - ((⟨32⟩ : UInt256) + - attesterMultiRevokeRequestDataElemPtr mem aw outerBase idx j) = - (⟨0⟩ : UInt256) := by - rw [helemPtrMload] - exact attesterMloadWord_of_readWithPadding helemExtraMem (hactive helemExtraMem) - helemExtraRead - exact ⟨uidWord, huidWord, huidMload, hextraMload⟩ - -theorem AttesterMultiRevokeRequestsMemoryLayout_zero - (schemas schemaUids : List Value) (mem : ByteArray) (aw outerBase : UInt256) : - AttesterMultiRevokeRequestsMemoryLayout schemas schemaUids 0 mem aw outerBase := by - intro idx hidx - omega - -theorem AttesterMultiRevokeRequestsMemoryLayout_mono - {schemas schemaUids : List Value} {i j : Nat} - {mem : ByteArray} {aw outerBase : UInt256} - (hle : i ≤ j) - (h : AttesterMultiRevokeRequestsMemoryLayout schemas schemaUids j mem aw outerBase) : - AttesterMultiRevokeRequestsMemoryLayout schemas schemaUids i mem aw outerBase := by - intro idx hidx - exact h (by omega) - -theorem attesterMultiRevokePostCopyOuterMem_read_current_slot - {I : ExecutionEnv} {base outerBase schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} : - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).readWithPadding - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat 32 = - UInt256.toByteArray (attesterMultiRevokePostCopyFreeWord mem aw) := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)).readWithPadding - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat 32 = - UInt256.toByteArray (attesterMultiRevokePostCopyFreeWord mem aw) - exact attesterWriteWord_read_back_nat - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw) - -theorem attesterMultiRevokePostCopyOuterMem_size_ge - {I : ExecutionEnv} {base outerBase schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} {n : Nat} - (hmem : n ≤ mem.size) : - n ≤ (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).size := by - change n ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)).size - apply le_trans _ (attesterWriteWord_size_ge_nat - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)) - change n ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base).size - apply le_trans _ (attesterWriteWord_size_ge_nat - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base) - change n ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyFreeMem mem aw) - (attesterMultiRevokePostCopyFreeWord mem aw).toNat - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)).size - apply le_trans _ (attesterWriteWord_size_ge_nat - (attesterMultiRevokePostCopyFreeMem mem aw) - (attesterMultiRevokePostCopyFreeWord mem aw).toNat - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)) - change n ≤ - (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokePostCopyFreeBumpWord mem aw)).size - exact le_trans hmem - (attesterWriteWord_size_ge_nat mem 64 - (attesterMultiRevokePostCopyFreeBumpWord mem aw)) - -theorem attesterMultiRevokePostCopyOuterMem_current_schema_size - {I : ExecutionEnv} {base outerBase schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} : - (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 32 ≤ - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).size := by - change (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)).size - apply le_trans _ (attesterWriteWord_size_ge_nat - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)) - change (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base).size - apply le_trans _ (attesterWriteWord_size_ge_nat - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base) - change (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyFreeMem mem aw) - (attesterMultiRevokePostCopyFreeWord mem aw).toNat - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)).size - rw [attesterWriteWord_size_nat] - exact Nat.le_max_right _ _ - -theorem attesterMultiRevokePostCopyOuterMem_current_data_size - {I : ExecutionEnv} {base outerBase schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} : - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat + 32 ≤ - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).size := by - change (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)).size - apply le_trans _ (attesterWriteWord_size_ge_nat - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)) - change (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat base).size - rw [attesterWriteWord_size_nat] - exact Nat.le_max_right _ _ - -theorem attesterMultiRevokePostCopyOuterMem_current_slot_size - {I : ExecutionEnv} {base outerBase schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} : - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat + 32 ≤ - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).size := by - change (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)).size - rw [attesterWriteWord_size_nat] - exact Nat.le_max_right _ _ - -theorem attesterMultiRevokePostCopyOuterMem_mload_current_slot - {I : ExecutionEnv} {base outerBase schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (haw : - ¬ attesterMultiRevokePostCopyOuterSlotWord outerBase idx ≥ - attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx mem aw * - (⟨32⟩ : UInt256)) : - attesterMloadWord - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterAw base outerBase I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx) = - attesterMultiRevokePostCopyFreeWord mem aw := by - have hmem : - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat + 32 ≤ - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).size := by - change (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)).size - rw [attesterWriteWord_size_nat - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat - (attesterMultiRevokePostCopyFreeWord mem aw)] - exact Nat.le_max_right _ _ - exact attesterMloadWord_of_readWithPadding hmem haw - (attesterMultiRevokePostCopyOuterMem_read_current_slot - (I := I) (base := base) (outerBase := outerBase) - (schemaPayload := schemaPayload) (idx := idx) (mem := mem) (aw := aw)) - -theorem attesterMultiRevokePostCopyOuterMem_read_current_schema - {I : ExecutionEnv} {base outerBase schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hdataToNat : - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat = - (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 32) - (hslotDisj : - (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 32 ≤ - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat ∨ - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat + 32 ≤ - (attesterMultiRevokePostCopyFreeWord mem aw).toNat) : - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).readWithPadding - (attesterMultiRevokePostCopyFreeWord mem aw).toNat 32 = - UInt256.toByteArray - (attesterMultiRevokePostCopySchemaWord I schemaPayload idx) := by - let free := attesterMultiRevokePostCopyFreeWord mem aw - let dataOff := attesterMultiRevokePostCopyDataOffsetWord mem aw - let slot := attesterMultiRevokePostCopyOuterSlotWord outerBase idx - let schemaWord := attesterMultiRevokePostCopySchemaWord I schemaPayload idx - have hreadSchema : - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw).readWithPadding - free.toNat 32 = - UInt256.toByteArray schemaWord := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyFreeMem mem aw) - free.toNat schemaWord).readWithPadding free.toNat 32 = - UInt256.toByteArray schemaWord - exact attesterWriteWord_read_back_nat - (attesterMultiRevokePostCopyFreeMem mem aw) free.toNat schemaWord - have hmemSchema : - free.toNat + 32 ≤ - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw).size := by - change free.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyFreeMem mem aw) - free.toNat schemaWord).size - rw [attesterWriteWord_size_nat - (attesterMultiRevokePostCopyFreeMem mem aw) free.toNat schemaWord] - exact Nat.le_max_right _ _ - have hreadData : - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).readWithPadding - free.toNat 32 = - UInt256.toByteArray schemaWord := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - dataOff.toNat base).readWithPadding free.toNat 32 = - UInt256.toByteArray schemaWord - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (base := free.toNat) (writeOff := dataOff.toNat) - (len := schemaWord) (writeVal := base) - hmemSchema (by rw [hdataToNat]) hreadSchema - have hmemData : - free.toNat + 32 ≤ - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).size := by - change free.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - dataOff.toNat base).size - rw [attesterWriteWord_size_nat - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - dataOff.toNat base] - exact le_trans hmemSchema (Nat.le_max_left _ _) - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - slot.toNat free).readWithPadding free.toNat 32 = - UInt256.toByteArray schemaWord - rcases hslotDisj with hslotAbove | hslotBelow - · exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (base := free.toNat) (writeOff := slot.toNat) - (len := schemaWord) (writeVal := free) - hmemData hslotAbove hreadData - · exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (base := free.toNat) (writeOff := slot.toNat) - (len := schemaWord) (writeVal := free) - hmemData hslotBelow hreadData - -theorem attesterMultiRevokePostCopyOuterMem_read_current_data_ptr - {I : ExecutionEnv} {base outerBase schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hslotDisj : - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat + 32 ≤ - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat ∨ - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat + 32 ≤ - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat) : - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).readWithPadding - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat 32 = - UInt256.toByteArray base := by - let dataOff := attesterMultiRevokePostCopyDataOffsetWord mem aw - let slot := attesterMultiRevokePostCopyOuterSlotWord outerBase idx - have hreadData : - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).readWithPadding - dataOff.toNat 32 = - UInt256.toByteArray base := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - dataOff.toNat base).readWithPadding dataOff.toNat 32 = - UInt256.toByteArray base - exact attesterWriteWord_read_back_nat - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) dataOff.toNat base - have hmemData : - dataOff.toNat + 32 ≤ - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).size := by - change dataOff.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - dataOff.toNat base).size - rw [attesterWriteWord_size_nat - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - dataOff.toNat base] - exact Nat.le_max_right _ _ - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - slot.toNat (attesterMultiRevokePostCopyFreeWord mem aw)).readWithPadding - dataOff.toNat 32 = - UInt256.toByteArray base - rcases hslotDisj with hslotAbove | hslotBelow - · exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (base := dataOff.toNat) (writeOff := slot.toNat) - (len := base) (writeVal := attesterMultiRevokePostCopyFreeWord mem aw) - hmemData hslotAbove hreadData - · exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (base := dataOff.toNat) (writeOff := slot.toNat) - (len := base) (writeVal := attesterMultiRevokePostCopyFreeWord mem aw) - hmemData hslotBelow hreadData - -theorem attesterMultiRevokePostCopyOuterMem_read_preserved_before_free - {I : ExecutionEnv} {base outerBase schemaPayload idx : UInt256} - {mem : ByteArray} {aw : UInt256} {read : Nat} {word : UInt256} - (hmem : read + 32 ≤ mem.size) - (hread : mem.readWithPadding read 32 = UInt256.toByteArray word) - (hread64 : 64 + 32 ≤ read) - (hbeforeFree : read + 32 ≤ (attesterMultiRevokePostCopyFreeWord mem aw).toNat) - (hdataToNat : - (attesterMultiRevokePostCopyDataOffsetWord mem aw).toNat = - (attesterMultiRevokePostCopyFreeWord mem aw).toNat + 32) - (hslotDisj : - read + 32 ≤ (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat ∨ - (attesterMultiRevokePostCopyOuterSlotWord outerBase idx).toNat + 32 ≤ read) : - (attesterMultiRevokePostCopyOuterMem base outerBase I schemaPayload idx mem aw).readWithPadding - read 32 = - UInt256.toByteArray word := by - let free := attesterMultiRevokePostCopyFreeWord mem aw - let dataOff := attesterMultiRevokePostCopyDataOffsetWord mem aw - let slot := attesterMultiRevokePostCopyOuterSlotWord outerBase idx - have hreadFree : - (attesterMultiRevokePostCopyFreeMem mem aw).readWithPadding read 32 = - UInt256.toByteArray word := by - change (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokePostCopyFreeBumpWord mem aw)).readWithPadding read 32 = - UInt256.toByteArray word - exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := mem) (base := read) (writeOff := 64) - (len := word) (writeVal := attesterMultiRevokePostCopyFreeBumpWord mem aw) - hmem hread64 hread - have hmemFree : - read + 32 ≤ (attesterMultiRevokePostCopyFreeMem mem aw).size := by - change read + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokePostCopyFreeBumpWord mem aw)).size - exact le_trans hmem - (attesterWriteWord_size_ge_nat mem 64 - (attesterMultiRevokePostCopyFreeBumpWord mem aw)) - have hreadSchema : - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw).readWithPadding - read 32 = - UInt256.toByteArray word := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyFreeMem mem aw) - free.toNat (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)).readWithPadding - read 32 = - UInt256.toByteArray word - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopyFreeMem mem aw) - (base := read) (writeOff := free.toNat) - (len := word) (writeVal := attesterMultiRevokePostCopySchemaWord I schemaPayload idx) - hmemFree hbeforeFree hreadFree - have hmemSchema : - read + 32 ≤ - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw).size := by - change read + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyFreeMem mem aw) - free.toNat (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)).size - exact le_trans hmemFree - (attesterWriteWord_size_ge_nat - (attesterMultiRevokePostCopyFreeMem mem aw) - free.toNat (attesterMultiRevokePostCopySchemaWord I schemaPayload idx)) - have hreadData : - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).readWithPadding - read 32 = - UInt256.toByteArray word := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - dataOff.toNat base).readWithPadding read 32 = - UInt256.toByteArray word - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - (base := read) (writeOff := dataOff.toNat) - (len := word) (writeVal := base) - hmemSchema (by rw [hdataToNat]; omega) hreadSchema - have hmemData : - read + 32 ≤ - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw).size := by - change read + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - dataOff.toNat base).size - exact le_trans hmemSchema - (attesterWriteWord_size_ge_nat - (attesterMultiRevokePostCopySchemaMem I schemaPayload idx mem aw) - dataOff.toNat base) - change (Reasoning.Theory.writeWord - (attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - slot.toNat (attesterMultiRevokePostCopyFreeWord mem aw)).readWithPadding read 32 = - UInt256.toByteArray word - rcases hslotDisj with hslotAbove | hslotBelow - · exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (base := read) (writeOff := slot.toNat) - (len := word) (writeVal := attesterMultiRevokePostCopyFreeWord mem aw) - hmemData hslotAbove hreadData - · exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := attesterMultiRevokePostCopyDataMem base I schemaPayload idx mem aw) - (base := read) (writeOff := slot.toNat) - (len := word) (writeVal := attesterMultiRevokePostCopyFreeWord mem aw) - hmemData hslotBelow hreadData - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/MultiRevokeLoopRun.lean b/Benchmarks/EAS/Attester/MultiRevokeLoopRun.lean deleted file mode 100644 index 802a4f66..00000000 --- a/Benchmarks/EAS/Attester/MultiRevokeLoopRun.lean +++ /dev/null @@ -1,598 +0,0 @@ -import Benchmarks.EAS.Attester.MultiRevokeContinuation - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevokeOuterInitFreeInv_to_outerLoopInv - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - {I : ExecutionEnv} {callargs : Store} {schemas schemaUids : List Value} - {evm : EVM.State} - {a : AttesterMultiOuterArrayInitState} - (hSchemas : callargs.get? "schemas" = some (.array schemas)) - (hSchemaUids : callargs.get? "schemaUids" = some (.array schemaUids)) - (hSchemasLen : - schemas.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hSchemaUidsLen : - schemaUids.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) - (hoff0 : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hoff1 : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hSchemasLenMax : schemas.length ≤ solcMaxU64) - (hOuter : attesterMultiRevokeOuterInitFreeInv I 0 a) : - let L1 := callargs.insert "schemaLength" (.int (Int.ofNat schemas.length)) - let L2 := L1.insert "multiRequests" - (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) - let L3 := L2.insert "i" (.int 0) - let cursor : AttesterMultiRevokeOuterLoopCursor := - { idx := ⟨0⟩, - outerBase := ⟨128⟩, - schemaLen := attesterFirstArrayLengthWord I, - secondLen := attesterSecondArrayLengthWord I, - secondPayload := attesterSecondArrayPayloadStartWord I, - schemaPayload := (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ret := ⟨97⟩, - selector := solcSelectorWord I, - mem := attesterMultiOuterArrayInitFinalMem a, - aw := attesterMultiOuterArrayInitFinalAw a, - acc := (cA, σ) } - AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids schemas.length cursor L3 evm := by - intro L1 L2 L3 cursor - rcases hOuter with - ⟨harem, habound, hale, hawGe, hawMul, hbaseGe, hbase160, hbaseBound, hbaseSpare, - hslotGe, hslot160, hslotBound, hslotSpare, hread128, hmem128, hfreeExact⟩ - let oldFree := attesterMultiOuterArrayInitFreeWord a.mem a.aw - have hlenWordToNat : - (attesterFirstArrayLengthWord I).toNat = schemas.length := by - rw [attesterFirstArrayLengthWord_toNat (I := I) hoff0] - exact hSchemasLen.symm - have hsecondWordToNat : - (attesterSecondArrayLengthWord I).toNat = schemaUids.length := by - rw [attesterSecondArrayLengthWord_toNat (I := I) hoff1] - exact hSchemaUidsLen.symm - have hlenPosWord : 0 < (attesterFirstArrayLengthWord I).toNat := by - rw [hlenWordToNat] - omega - have houterStepAw := - attesterMultiOuterArrayInitStepAw_bounds - (slot := a.slot) (mem := a.mem) (aw := a.aw) - hawGe hawMul - (by - have h : oldFree.toNat + 95 < UInt256.size := by - have hspare : oldFree.toNat + 64 + 160 + 160 * solcMaxU64 < UInt256.size := by - simpa [oldFree] using hbaseSpare - omega - exact h) - (by - have h : a.slot.toNat + 63 < UInt256.size := by - omega - exact h) - have holdFree32 : oldFree.toNat + 32 < UInt256.size := by - have h : oldFree.toNat + 64 < UInt256.size := by - simpa [oldFree] using hbaseBound - omega - have hoffsetToNat : - (attesterMultiOuterArrayInitOffsetWord a.mem a.aw).toNat = - oldFree.toNat + 32 := by - unfold oldFree attesterMultiOuterArrayInitOffsetWord - exact uadd_word_lit32_toNat - (attesterMultiOuterArrayInitFreeWord a.mem a.aw) holdFree32 - have hoffset160 : - 128 + 32 ≤ (attesterMultiOuterArrayInitOffsetWord a.mem a.aw).toNat := by - rw [hoffsetToNat] - have h : 128 + 32 ≤ oldFree.toNat := by - simpa [oldFree] using hbase160 - omega - have hfinalRead128 : - (attesterMultiOuterArrayInitFinalMem a).readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) := by - change - (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw).readWithPadding - 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) - simpa using - (attesterMultiOuterArrayInitStep_readWithPadding_nat - (base := (⟨128⟩ : UInt256)) (slot := a.slot) - (len := attesterFirstArrayLengthWord I) (mem := a.mem) (aw := a.aw) - (by simpa using hmem128) - (by simpa using hread128) - (by decide) - (by simpa using hbase160) - (by simpa using hoffset160) - (by simpa using hslot160)) - have hfinalMem128 : - 128 + 32 ≤ (attesterMultiOuterArrayInitFinalMem a).size := by - change 128 + 32 ≤ - (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw).size - exact le_trans hmem128 attesterMultiOuterArrayInitStep_size_ge - have hfinalFreeToNat : - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).toNat = - oldFree.toNat + 64 := by - change - (attesterMultiOuterArrayInitFreeWord - (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw) - (attesterMultiOuterArrayInitStepAw a.slot a.mem a.aw)).toNat = - oldFree.toNat + 64 - exact attesterMultiOuterArrayInitStep_freeWord_toNat - (slot := a.slot) (mem := a.mem) (aw := a.aw) - (by simpa [oldFree] using hbaseGe) - (by - rw [hoffsetToNat] - have h : 64 + 32 ≤ oldFree.toNat := by - simpa [oldFree] using hbaseGe - omega) - hslotGe houterStepAw.2 houterStepAw.1 - (by simpa [oldFree] using hbaseBound) - have hfreeBudget : - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).toNat + - attesterMultiRevokeEncoderOutputBudget schemas.length + 128 + - attesterMultiRevokeOuterLoopBudgetChunk * schemas.length < UInt256.size := by - rw [hfinalFreeToNat, hfreeExact] - rw [hlenWordToNat] - let n := schemas.length - have hnpos : 0 < n := by - dsimp [n] - omega - have hprefixLe : - 160 + 32 * n + 64 * (n - 1) + 64 + 128 ≤ 288 + 96 * n := by - have hsubEq : n - 1 + 1 = n := Nat.sub_add_cancel (by omega : 1 ≤ n) - have hmulSub : 64 * (n - 1) + 64 = 64 * n := by - nlinarith - nlinarith - have htotalLe : - 160 + 32 * n + 64 * (n - 1) + 64 + - attesterMultiRevokeEncoderOutputBudget n + 128 + - attesterMultiRevokeOuterLoopBudgetChunk * n ≤ - 356 + (96 + attesterMultiRevokeOuterLoopBudgetChunk + - attesterMultiRevokeOuterLoopBudgetChunk) * solcMaxU64 := by - have hmulLe : - (96 + attesterMultiRevokeOuterLoopBudgetChunk + - attesterMultiRevokeOuterLoopBudgetChunk) * n ≤ - (96 + attesterMultiRevokeOuterLoopBudgetChunk + - attesterMultiRevokeOuterLoopBudgetChunk) * solcMaxU64 := - Nat.mul_le_mul_left (96 + attesterMultiRevokeOuterLoopBudgetChunk + - attesterMultiRevokeOuterLoopBudgetChunk) - (by simpa [n] using hSchemasLenMax) - have hcombine : - 356 + 96 * n + attesterMultiRevokeOuterLoopBudgetChunk * n + - attesterMultiRevokeOuterLoopBudgetChunk * n = - 356 + (96 + attesterMultiRevokeOuterLoopBudgetChunk + - attesterMultiRevokeOuterLoopBudgetChunk) * n := by - ring - unfold attesterMultiRevokeEncoderOutputBudget - calc - 160 + 32 * n + 64 * (n - 1) + 64 + (4 + 64 + - attesterMultiRevokeOuterLoopBudgetChunk * n) + 128 + - attesterMultiRevokeOuterLoopBudgetChunk * n - ≤ 288 + 96 * n + 68 + - attesterMultiRevokeOuterLoopBudgetChunk * n + - attesterMultiRevokeOuterLoopBudgetChunk * n := by - omega - _ = 356 + (96 + attesterMultiRevokeOuterLoopBudgetChunk + - attesterMultiRevokeOuterLoopBudgetChunk) * n := by - calc - 288 + 96 * n + 68 + attesterMultiRevokeOuterLoopBudgetChunk * n + - attesterMultiRevokeOuterLoopBudgetChunk * n - = 356 + 96 * n + attesterMultiRevokeOuterLoopBudgetChunk * n + - attesterMultiRevokeOuterLoopBudgetChunk * n := by - omega - _ = 356 + (96 + attesterMultiRevokeOuterLoopBudgetChunk + - attesterMultiRevokeOuterLoopBudgetChunk) * n := by - rw [hcombine] - _ ≤ 356 + (96 + attesterMultiRevokeOuterLoopBudgetChunk + - attesterMultiRevokeOuterLoopBudgetChunk) * solcMaxU64 := by - omega - have hcap : - 356 + (96 + attesterMultiRevokeOuterLoopBudgetChunk + - attesterMultiRevokeOuterLoopBudgetChunk) * solcMaxU64 < - UInt256.size := by - native_decide - exact lt_of_le_of_lt (by simpa [n] using htotalLe) hcap - have hschemasL1 : L1.get? "schemas" = some (.array schemas) := by - simpa [L1] using - (attesterStoreGetInsertOfNe (locals := callargs) (name := "schemas") - (other := "schemaLength") (value := .int (Int.ofNat schemas.length)) - hSchemas (by decide)) - have hschemaUidsL1 : L1.get? "schemaUids" = some (.array schemaUids) := by - simpa [L1] using - (attesterStoreGetInsertOfNe (locals := callargs) (name := "schemaUids") - (other := "schemaLength") (value := .int (Int.ofNat schemas.length)) - hSchemaUids (by decide)) - have hschemaLengthL1 : L1.get? "schemaLength" = - some (.int (Int.ofNat schemas.length)) := by - simp [L1] - have hschemasL2 : L2.get? "schemas" = some (.array schemas) := by - simpa [L2] using - (attesterStoreGetInsertOfNe (locals := L1) (name := "schemas") - (other := "multiRequests") - (value := .array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) - hschemasL1 (by decide)) - have hschemaUidsL2 : L2.get? "schemaUids" = some (.array schemaUids) := by - simpa [L2] using - (attesterStoreGetInsertOfNe (locals := L1) (name := "schemaUids") - (other := "multiRequests") - (value := .array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) - hschemaUidsL1 (by decide)) - have hschemaLengthL2 : L2.get? "schemaLength" = - some (.int (Int.ofNat schemas.length)) := by - simpa [L2] using - (attesterStoreGetInsertOfNe (locals := L1) (name := "schemaLength") - (other := "multiRequests") - (value := .array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) - hschemaLengthL1 (by decide)) - have hrequestsL2 : - L2.get? "multiRequests" = - some (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) := by - simp [L2] - have hschemasL3 : L3.get? "schemas" = some (.array schemas) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "schemas") - (other := "i") (value := .int 0) hschemasL2 (by decide)) - have hschemaUidsL3 : L3.get? "schemaUids" = some (.array schemaUids) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "schemaUids") - (other := "i") (value := .int 0) hschemaUidsL2 (by decide)) - have hschemaLengthL3 : L3.get? "schemaLength" = - some (.int (Int.ofNat schemas.length)) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "schemaLength") - (other := "i") (value := .int 0) hschemaLengthL2 (by decide)) - have hrequestsL3 : - L3.get? "multiRequests" = - some (.array (attesterMultiRevokeRequestValuesPrefix 0 schemas schemaUids)) := by - have hraw : L3.get? "multiRequests" = - some (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "multiRequests") - (other := "i") (value := .int 0) hrequestsL2 (by decide)) - simpa [attesterMultiRevokeRequestValuesPrefix_zero] using hraw - have hiL3 : L3.get? "i" = some (.int 0) := by - simp [L3] - refine ⟨0, hschemasL3, hschemaUidsL3, hschemaLengthL3, hrequestsL3, ?_, - ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, - ?_, ?_, ?_, ?_, ?_⟩ - · simpa using hiL3 - · omega - · omega - · intro idx _value hlt _hlookup - omega - · change 0 < UInt256.size - norm_num [UInt256.size] - · change (⟨0⟩ : UInt256) = UInt256.ofNat 0 - native_decide - · simp [cursor] - · simp [cursor] - · simp [cursor] - · simpa [cursor] using hlenWordToNat - · simp [cursor] - · simpa [cursor] using hsecondWordToNat - · simp [cursor, attesterSecondArrayPayloadStartWord] - · simp [cursor] - · simp [cursor] - · simp [cursor] - · simp [cursor] - · simpa [cursor] using houterStepAw.1 - · simpa [cursor] using houterStepAw.2 - · simpa [cursor] using hfinalRead128 - · simpa [cursor] using hfinalMem128 - · change 64 + 32 ≤ (⟨128⟩ : UInt256).toNat - decide - · rw [hfinalFreeToNat] - have h : 64 + 32 ≤ oldFree.toNat := by - simpa [oldFree] using hbaseGe - omega - · constructor - · rw [hfinalFreeToNat] - change (⟨128⟩ : UInt256).toNat + 32 ≤ oldFree.toNat + 64 - have h : 64 + 32 ≤ oldFree.toNat := by - simpa [oldFree] using hbaseGe - have h128 : (⟨128⟩ : UInt256).toNat = 128 := by decide - rw [h128] - omega - · constructor - · have hfreeFinalLower : - 160 + 32 * schemas.length ≤ - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).toNat := by - rw [hfinalFreeToNat, hfreeExact, hlenWordToNat] - omega - have hcursorOuterBaseToNat : cursor.outerBase.toNat = 128 := by - change (⟨128⟩ : UInt256).toNat = 128 - decide - rw [hcursorOuterBaseToNat] - omega - · constructor - · intro idx hidx - omega - · simpa [cursor] using hfreeBudget - -theorem attesterX_multiRevokeOuterInitToLoopInv - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {callargs : Store} {schemas schemaUids : List Value} - (hSchemas : callargs.get? "schemas" = some (.array schemas)) - (hSchemaUids : callargs.get? "schemaUids" = some (.array schemaUids)) - (hSchemasLen : - schemas.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 4).toNat)).toNat) - (hSchemaUidsLen : - schemaUids.length = - (calldataWord I.calldata (4 + (calldataWord I.calldata 36).toNat)).toNat) - (hoff0 : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hoff1 : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hSchemasLenMax : schemas.length ≤ solcMaxU64) - (hprogress : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterArrayInitExitStack I ⟨128⟩ - (attesterFirstArrayLengthWord I) a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C) : - let L1 := callargs.insert "schemaLength" (.int (Int.ofNat schemas.length)) - let L2 := L1.insert "multiRequests" - (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault)) - let L3 := L2.insert "i" (.int 0) - ∃ cursor L k C, - L = L3 ∧ - AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids schemas.length cursor L - (initState cA gh bl σ σ₀ g A I) ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack cursor) cursor.mem cursor.aw ByteArray.empty - cursor.acc k C := by - intro L1 L2 L3 - rcases hprogress with ⟨a', k, C, _hrem, hOuter, rd⟩ - let cursor : AttesterMultiRevokeOuterLoopCursor := - { idx := ⟨0⟩, - outerBase := ⟨128⟩, - schemaLen := attesterFirstArrayLengthWord I, - secondLen := attesterSecondArrayLengthWord I, - secondPayload := attesterSecondArrayPayloadStartWord I, - schemaPayload := (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ret := ⟨97⟩, - selector := solcSelectorWord I, - mem := attesterMultiOuterArrayInitFinalMem a', - aw := attesterMultiOuterArrayInitFinalAw a', - acc := (cA, σ) } - have hInv : - AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids schemas.length cursor L3 - (initState cA gh bl σ σ₀ g A I) := by - simpa [cursor, L1, L2, L3] using - (attesterMultiRevokeOuterInitFreeInv_to_outerLoopInv - (cA := cA) (σ := σ) (I := I) (callargs := callargs) - (schemas := schemas) (schemaUids := schemaUids) (a := a') - hSchemas hSchemaUids hSchemasLen hSchemaUidsLen hoff0 hoff1 - hSchemasLenMax hOuter) - exact ⟨cursor, L3, k, C, rfl, hInv, by - simpa [cursor, attesterMultiRevokeOuterLoopStack, - attesterMultiRevokeOuterArrayInitExitStack] using rd⟩ - -set_option maxHeartbeats 1000000 in -theorem AttesterMultiRevokeOuterLoopInv.run_or_revert - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {callargs : Store} {schemas schemaUids : List Value} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hSchemas : callargs.get? "schemas" = some (.array schemas)) - (hSchemaUids : callargs.get? "schemaUids" = some (.array schemaUids)) - (hoff0 : ¬ solcMaxU64 < (calldataWord I.calldata 4).toNat) - (hoff1 : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hsizeSigned : I.calldata.size < 2 ^ 255) - (hschemasBound : schemas.length < 2 ^ 256) - (hschemasLenMax : schemas.length ≤ solcMaxU64) - (hlenEq : schemaUids.length = schemas.length) - (hschemaNorm : ∀ {idx schema}, lookupNth? schemas idx = some schema → - normalizeRawBoolWord? schema = .ok schema) - (huidssShape : ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid)) : - ∀ {fuel : Nat} {a : AttesterMultiRevokeOuterLoopCursor} {L : Store} - {evm : EVM.State}, - AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids fuel a L evm → - ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a) a.mem a.aw ByteArray.empty a.acc k C → - (∃ a' L' evm' k' C', - ExecStmt (config v) { contract := contract v, locals := L } evm - (.while attesterMultiRevokeOuterSourceLoopCond attesterMultiRevokeOuterSourceLoopBody) - (.ok { contract := contract v, locals := L' } evm') ∧ - AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids 0 a' L' evm' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨698⟩ : UInt256) - (attesterMultiRevokeOuterLoopStack a') a'.mem a'.aw ByteArray.empty a'.acc k' C') ∨ - (ExecStmt (config v) { contract := contract v, locals := L } evm - (.while attesterMultiRevokeOuterSourceLoopCond attesterMultiRevokeOuterSourceLoopBody) - .reverted ∧ - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I)) := by - intro fuel a L evm hInv k C rd - refine - (attesterMultiRevokeOuterLoop_from_headerBodyOutcome_or_revert - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids) - ?_ ?_ ?_ ?_) fuel a L evm hInv k C rd - · intro a L evm hInv - rcases hInv with - ⟨i, _hschemas, _hSchemaUids, hschemaLength, _hrequests, hi, hvariant, _hile, - _hprocessed, _hisize, _hidx, _hidxToNat, _houterBase, _hschemaLen, - _hschemaLenToNat, _hsecondLen, _hsecondLenToNat, _hsecondPayload, - _hschemaPayload, _hret, _hselector, _hacc, _hawGe, _hawMul, _houterRead, - _houterMemSize, _houter64, _hbaseGe, _houterBeforeBase, - _houterSlotsBeforeBase, _hreadLayout, _hfreeBudget⟩ - exact attesterMultiRevokeOuterSourceLoopCondFalse v evm hschemaLength hi (by omega) - · intro a L evm hInv k C rd - have hlt : - UInt256.lt a.idx a.schemaLen = ⟨0⟩ := - AttesterMultiRevokeOuterLoopInv.cond_false - (cA := cA) (σ := σ) (I := I) (schemas := schemas) - (schemaUids := schemaUids) (a := a) (L := L) (evm := evm) hInv - rcases hInv with - ⟨_i, _hschemas, _hSchemaUids, _hschemaLength, _hrequests, _hi, _hvariant, - _hile, _hprocessed, _hisize, _hidx, _hidxToNat, _houterBase, - _hschemaLen, _hschemaLenToNat, _hsecondLen, _hsecondLenToNat, - _hsecondPayload, _hschemaPayload, _hret, _hselector, hacc, _hawGe, - _hawMul, _houterRead, _houterMemSize, _houter64, _hbaseGe, - _houterBeforeBase, _houterSlotsBeforeBase, _hreadLayout, _hfreeBudget⟩ - obtain ⟨k', C', rd'⟩ := attesterX_multiRevokeOuterSourceLoopExit - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hlt - (by simpa [attesterMultiRevokeOuterLoopStack, hacc] using rd) - exact ⟨k', C', by simpa [attesterMultiRevokeOuterLoopStack, hacc] using rd'⟩ - · intro fuel a L evm hInv - rcases hInv with - ⟨i, _hschemas, _hSchemaUids, hschemaLength, _hrequests, hi, hvariant, _hile, - _hprocessed, _hisize, _hidx, _hidxToNat, _houterBase, _hschemaLen, - _hschemaLenToNat, _hsecondLen, _hsecondLenToNat, _hsecondPayload, - _hschemaPayload, _hret, _hselector, _hacc, _hawGe, _hawMul, _houterRead, - _houterMemSize, _houter64, _hbaseGe, _houterBeforeBase, - _houterSlotsBeforeBase, _hreadLayout, _hfreeBudget⟩ - exact attesterMultiRevokeOuterSourceLoopCondTrue v evm hschemaLength hi (by omega) - · intro fuel a L evm hInv k C rd - exact AttesterMultiRevokeOuterLoopInv.body_or_revert - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hdec hSchemas hSchemaUids hoff0 hoff1 hsizeSigned - hschemasBound hschemasLenMax hlenEq hschemaNorm huidssShape hInv k C rd - -theorem AttesterMultiRevokeOuterLoopInv.done_shape - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - {I : ExecutionEnv} {schemas schemaUids : List Value} - {a : AttesterMultiRevokeOuterLoopCursor} {L : Store} {evm : EVM.State} - (hInv : AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids 0 a L evm) : - L.get? "schemas" = some (.array schemas) ∧ - L.get? "schemaUids" = some (.array schemaUids) ∧ - L.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) ∧ - L.get? "multiRequests" = - some (.array (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) ∧ - L.get? "i" = some (.int (Int.ofNat schemas.length)) ∧ - a.idx = UInt256.ofNat schemas.length ∧ - a.idx.toNat = schemas.length ∧ - a.outerBase = (⟨128⟩ : UInt256) ∧ - a.schemaLen = attesterFirstArrayLengthWord I ∧ - a.schemaLen.toNat = schemas.length ∧ - a.secondLen = attesterSecondArrayLengthWord I ∧ - a.secondLen.toNat = schemaUids.length ∧ - a.secondPayload = attesterSecondArrayPayloadStartWord I ∧ - a.schemaPayload = (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩ ∧ - a.ret = (⟨97⟩ : UInt256) ∧ - a.selector = solcSelectorWord I ∧ - a.acc = (cA, σ) ∧ - 3 ≤ a.aw.toNat ∧ - a.aw.toNat * 32 < UInt256.size ∧ - a.mem.readWithPadding a.outerBase.toNat 32 = UInt256.toByteArray a.schemaLen ∧ - a.outerBase.toNat + 32 ≤ a.mem.size ∧ - 64 + 32 ≤ a.outerBase.toNat ∧ - 64 + 32 ≤ (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat ∧ - a.outerBase.toNat + 32 ≤ (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat ∧ - (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat + 128 < UInt256.size := by - rcases hInv with - ⟨i, hschemas, hschemaUids, hschemaLength, hrequests, hi, hvariant, _hile, - _hprocessed, _hisize, hidx, hidxToNat, houterBase, hschemaLen, - hschemaLenToNat, hsecondLen, hsecondLenToNat, hsecondPayload, - hschemaPayload, hret, hselector, hacc, hawGe, hawMul, houterRead, - houterMemSize, houter64, hbaseGe, houterBeforeBase, - _houterSlotsBeforeBase, _hreadLayout, hfreeBudget⟩ - have hidone : i = schemas.length := by omega - subst hidone - have hfreeLt : - (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat + 128 < UInt256.size := by - omega - exact - ⟨hschemas, hschemaUids, hschemaLength, hrequests, hi, hidx, hidxToNat, - houterBase, hschemaLen, hschemaLenToNat, hsecondLen, hsecondLenToNat, - hsecondPayload, hschemaPayload, hret, hselector, hacc, hawGe, hawMul, - houterRead, houterMemSize, houter64, hbaseGe, houterBeforeBase, hfreeLt⟩ - -theorem AttesterMultiRevokeOuterLoopInv.done_readLayout - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - {I : ExecutionEnv} {schemas schemaUids : List Value} - {a : AttesterMultiRevokeOuterLoopCursor} {L : Store} {evm : EVM.State} - (hInv : AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids 0 a L evm) : - AttesterMultiRevokeRequestsReadLayoutBounded schemas schemaUids schemas.length - a.mem a.outerBase - (a.outerBase.toNat + 32 + 32 * schemas.length) - (attesterInnerArrayAllocFreeWord a.mem a.aw).toNat := by - rcases hInv with - ⟨i, _hschemas, _hschemaUids, _hschemaLength, _hrequests, _hi, hvariant, - _hile, _hprocessed, _hisize, _hidx, hidxToNat, _houterBase, _hschemaLen, - _hschemaLenToNat, _hsecondLen, _hsecondLenToNat, _hsecondPayload, - _hschemaPayload, _hret, _hselector, _hacc, _hawGe, _hawMul, _houterRead, - _houterMemSize, _houter64, _hbaseGe, _houterBeforeBase, - _houterSlotsBeforeBase, hreadLayout, _hfreeBudget⟩ - have hidone : i = schemas.length := by omega - subst i - intro idx hidx - exact hreadLayout (by - rw [hidone] - omega) - -theorem AttesterMultiRevokeOuterLoopInv.done_uidss_ok - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - {I : ExecutionEnv} {schemas schemaUids : List Value} - {a : AttesterMultiRevokeOuterLoopCursor} {L : Store} {evm : EVM.State} - (hlenEq : schemaUids.length = schemas.length) - (hInv : AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids 0 a L evm) : - ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length ≠ 0 ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid) := by - rcases hInv with - ⟨i, _hschemas, _hschemaUids, _hschemaLength, _hrequests, _hi, hvariant, - _hile, hprocessed, _hisize, _hidx, _hidxToNat, _houterBase, _hschemaLen, - _hschemaLenToNat, _hsecondLen, _hsecondLenToNat, _hsecondPayload, - _hschemaPayload, _hret, _hselector, _hacc, _hawGe, _hawMul, _houterRead, - _houterMemSize, _houter64, _hbaseGe, _houterBeforeBase, - _houterSlotsBeforeBase, _hreadLayout, _hfreeBudget⟩ - have hidone : i = schemas.length := by omega - subst i - intro idx value hlookup - have hidxLtSchemaUids : idx < schemaUids.length := - lookupNth?_some_length hlookup - rcases hprocessed (by omega) hlookup with - ⟨uids, hvalue, hne, _hmax, hbound, hnorm⟩ - exact ⟨uids, hvalue, hne, hbound, hnorm⟩ - -theorem AttesterMultiRevokeOuterLoopInv.done_uidss_bounded - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - {I : ExecutionEnv} {schemas schemaUids : List Value} - {a : AttesterMultiRevokeOuterLoopCursor} {L : Store} {evm : EVM.State} - (hlenEq : schemaUids.length = schemas.length) - (hInv : AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids 0 a L evm) : - ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length ≠ 0 ∧ - uids.length ≤ solcMaxU64 ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid) := by - rcases hInv with - ⟨i, _hschemas, _hschemaUids, _hschemaLength, _hrequests, _hi, hvariant, - _hile, hprocessed, _hisize, _hidx, _hidxToNat, _houterBase, _hschemaLen, - _hschemaLenToNat, _hsecondLen, _hsecondLenToNat, _hsecondPayload, - _hschemaPayload, _hret, _hselector, _hacc, _hawGe, _hawMul, _houterRead, - _houterMemSize, _houter64, _hbaseGe, _houterBeforeBase, - _houterSlotsBeforeBase, _hreadLayout, _hfreeBudget⟩ - have hidone : i = schemas.length := by omega - subst i - intro idx value hlookup - have hidxLtSchemaUids : idx < schemaUids.length := - lookupNth?_some_length hlookup - exact hprocessed (by omega) hlookup - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/MultiRevokeMemory.lean b/Benchmarks/EAS/Attester/MultiRevokeMemory.lean deleted file mode 100644 index 4c8bc604..00000000 --- a/Benchmarks/EAS/Attester/MultiRevokeMemory.lean +++ /dev/null @@ -1,2365 +0,0 @@ -import Benchmarks.EAS.Attester.InnerArrayCopy - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -theorem attesterToByteArray_write_eq_nat (v : UInt256) (mem : ByteArray) (off : Nat) - (hoff : mem.size ≤ off) : - (UInt256.toByteArray v).write 0 mem off 32 = - mem ++ ffi.ByteArray.zeroes (off - mem.size) ++ UInt256.toByteArray v := by - have hsz : (UInt256.toByteArray v).data.size = 32 := UInt256.toByteArrayWithSizeProof v |>.2 - have hpz : (ffi.ByteArray.zeroes (off - mem.size)).data.size = off - mem.size := by - rw [show (ffi.ByteArray.zeroes (off - mem.size)).data.size = - (ffi.ByteArray.zeroes (off - mem.size)).size from rfl, ByteArray_zeroes_size] - apply ByteArray.ext - unfold ByteArray.write - rw [if_neg (by decide : ¬ ((32 : Nat) = 0)), - if_neg (show ¬ (0 ≥ (UInt256.toByteArray v).size) from by - rw [show (UInt256.toByteArray v).size = 32 from hsz]; omega)] - simp only [ByteArray.data_copySlice, ByteArray.data_append] - have hv : v.toByteArray.size = 32 := hsz - have hDsz : (mem.data ++ (ffi.ByteArray.zeroes (off - mem.size)).data).size = off := by - rw [Array.size_append, hpz] - show mem.size + (off - mem.size) = off - omega - rw [hv, show (min 32 (32 - 0) : Nat) = 32 from rfl, - show min mem.size (off + 32) - (off + 32) = 0 from by omega, - show (ffi.ByteArray.zeroes 0).data = (#[] : Array UInt8) from by - rw [zeroes_zero (n := 0) (by rfl)] - rfl] - rw [Array.append_empty] - rw [Array.extract_eq_self_of_le (by rw [hDsz]), - Array.extract_eq_self_of_le (show v.toByteArray.data.size ≤ 0 + (32 + 0) from by rw [hsz]), - Array.extract_eq_empty_of_le (by rw [hDsz]; omega), - Array.append_empty] - -theorem attesterWriteWord_size_nat (mem : ByteArray) (off : Nat) (word : UInt256) : - (Reasoning.Theory.writeWord mem off word).size = max mem.size (off + 32) := by - unfold Reasoning.Theory.writeWord - by_cases hoff : off ≤ mem.size - · rw [toByteArray_write32_size_of_le mem word off mem.size (max mem.size (off + 32)) - rfl hoff rfl] - · have hge : mem.size ≤ off := by omega - rw [attesterToByteArray_write_eq_nat word mem off hge] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray_zeroes_size, toByteArray_size] - rw [max_eq_right (by omega)] - omega - -theorem attesterWriteWord_size_ge_nat (mem : ByteArray) (off : Nat) (word : UInt256) : - mem.size ≤ (Reasoning.Theory.writeWord mem off word).size := by - rw [attesterWriteWord_size_nat] - exact Nat.le_max_left _ _ - -theorem attesterWriteWord_read_back_nat (mem : ByteArray) (off : Nat) (word : UInt256) : - (Reasoning.Theory.writeWord mem off word).readWithPadding off 32 = - UInt256.toByteArray word := by - unfold Reasoning.Theory.writeWord - by_cases hle : off ≤ mem.size - · rw [write32_read_back _ _ off (by rw [toByteArray_size]) hle] - rw [show 32 = (UInt256.toByteArray word).size by rw [toByteArray_size]] - exact byteArray_extract_self _ - · have hge : mem.size ≤ off := by omega - rw [attesterToByteArray_write_eq_nat word mem off hge] - rw [readWithPadding_eq_extract _ off (by - rw [ByteArray.size_append, ByteArray.size_append, ByteArray_zeroes_size, toByteArray_size] - omega)] - rw [extract_append_right_window - (mem ++ ffi.ByteArray.zeroes (off - mem.size)) - (UInt256.toByteArray word) off (off + 32) (by - rw [ByteArray.size_append, ByteArray_zeroes_size] - omega)] - rw [ByteArray.size_append, ByteArray_zeroes_size] - rw [show off - (mem.size + (off - mem.size)) = 0 by omega, - show off + 32 - (mem.size + (off - mem.size)) = 32 by omega] - rw [show (UInt256.toByteArray word).extract 0 32 = UInt256.toByteArray word from by - rw [show 32 = (UInt256.toByteArray word).size by rw [toByteArray_size]] - exact byteArray_extract_self _] - -theorem attesterWriteWord_read_below_len_nat (mem : ByteArray) (off : Nat) - (word : UInt256) (read len : Nat) - (hread : read + len ≤ mem.size) (hbelow : read + len ≤ off) - (hpos : 0 < len) (hlen64 : len < 2 ^ 64) : - (Reasoning.Theory.writeWord mem off word).readWithPadding read len = - mem.readWithPadding read len := by - unfold Reasoning.Theory.writeWord - by_cases hle : off ≤ mem.size - · exact write32_read_below_len _ _ off read len (by rw [toByteArray_size]) hle - hbelow hread hpos hlen64 - · have hge : mem.size ≤ off := by omega - rw [attesterToByteArray_write_eq_nat word mem off hge] - rw [readWithPadding_eq_extract' _ read len hpos hlen64 (by - rw [ByteArray.size_append, ByteArray.size_append, ByteArray_zeroes_size, toByteArray_size] - omega)] - rw [extract_append_left _ _ _ _ (by - rw [ByteArray.size_append, ByteArray_zeroes_size] - omega)] - rw [extract_append_left _ _ _ _ hread] - exact (readWithPadding_eq_extract' _ read len hpos hlen64 hread).symm - -theorem attesterWriteWord_read_preserved_len_nat (mem : ByteArray) (off read len : Nat) - (word : UInt256) - (hdisj : - (read + len ≤ off ∧ read + len ≤ mem.size) ∨ - (off + 32 ≤ read ∧ read + len ≤ mem.size)) - (hpos : 0 < len) (hlen64 : len < 2 ^ 64) : - (Reasoning.Theory.writeWord mem off word).readWithPadding read len = - mem.readWithPadding read len := by - rcases hdisj with hbelow | habove - · exact attesterWriteWord_read_below_len_nat mem off word read len - hbelow.2 hbelow.1 hpos hlen64 - · unfold Reasoning.Theory.writeWord - exact write32_read_above_len _ _ off read len (by rw [toByteArray_size]) - (by omega) habove.1 habove.2 hpos hlen64 - -theorem attesterReadWithPadding_writeWord_preserved_above_nat - {mem : ByteArray} {base writeOff : Nat} {len writeVal : UInt256} - (hmem : base + 32 ≤ mem.size) - (habove : base + 32 ≤ writeOff) - (hread : mem.readWithPadding base 32 = UInt256.toByteArray len) : - (Reasoning.Theory.writeWord mem writeOff writeVal).readWithPadding base 32 = - UInt256.toByteArray len := by - rw [attesterWriteWord_read_preserved_len_nat mem writeOff base 32 writeVal - (Or.inl ⟨habove, hmem⟩) (by norm_num) (by norm_num), hread] - -theorem attesterReadWithPadding_writeWord_preserved_below_nat - {mem : ByteArray} {base writeOff : Nat} {len writeVal : UInt256} - (hmem : base + 32 ≤ mem.size) - (hbelow : writeOff + 32 ≤ base) - (hread : mem.readWithPadding base 32 = UInt256.toByteArray len) : - (Reasoning.Theory.writeWord mem writeOff writeVal).readWithPadding base 32 = - UInt256.toByteArray len := by - rw [attesterWriteWord_read_preserved_len_nat mem writeOff base 32 writeVal - (Or.inr ⟨hbelow, hmem⟩) (by norm_num) (by norm_num), hread] - -theorem attesterMultiOuterArrayLenMem_read128 (I : ExecutionEnv) : - (attesterMultiOuterArrayLenMem I).readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) := by - unfold attesterMultiOuterArrayLenMem - change - (Reasoning.Theory.writeWord solcFreePtrMem 128 - (attesterFirstArrayLengthWord I)).readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) - exact attesterWriteWord_read_back_nat solcFreePtrMem 128 - (attesterFirstArrayLengthWord I) - -theorem attesterMultiOuterArrayAllocMem_read128 (I : ExecutionEnv) : - (attesterMultiOuterArrayAllocMem I).readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) := by - unfold attesterMultiOuterArrayAllocMem - change - (Reasoning.Theory.writeWord (attesterMultiOuterArrayLenMem I) 64 - (attesterMultiOuterArrayAllocEndWord I)).readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) - exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := attesterMultiOuterArrayLenMem I) - (base := 128) (writeOff := 64) - (len := attesterFirstArrayLengthWord I) - (writeVal := attesterMultiOuterArrayAllocEndWord I) - (by rw [attesterMultiOuterArrayLenMem_size I]) - (by norm_num) - (attesterMultiOuterArrayLenMem_read128 I) - -theorem attesterMultiOuterArrayAllocEndWord_toNat {I : ExecutionEnv} - (hlen : (attesterFirstArrayLengthWord I).toNat ≤ solcMaxU64) : - (attesterMultiOuterArrayAllocEndWord I).toNat = - 160 + 32 * (attesterFirstArrayLengthWord I).toNat := by - unfold attesterMultiOuterArrayAllocEndWord - have hmul : - (UInt256.mul (⟨32⟩ : UInt256) (attesterFirstArrayLengthWord I)).toNat = - 32 * (attesterFirstArrayLengthWord I).toNat := by - rw [u256_mul_toNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - exact Nat.mod_eq_of_lt (by - norm_num [solcMaxU64, UInt256.size] at hlen ⊢ - omega) - have hinner : - (((⟨32⟩ : UInt256) + - UInt256.mul (⟨32⟩ : UInt256) (attesterFirstArrayLengthWord I)).toNat) = - 32 + 32 * (attesterFirstArrayLengthWord I).toNat := by - rw [uadd_toNat, hmul] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - exact Nat.mod_eq_of_lt (by - norm_num [solcMaxU64, UInt256.size] at hlen ⊢ - omega) - rw [uadd_toNat, hinner] - rw [show (⟨128⟩ : UInt256).toNat = 128 by decide] - rw [show 128 + (32 + 32 * (attesterFirstArrayLengthWord I).toNat) = - 160 + 32 * (attesterFirstArrayLengthWord I).toNat by omega] - exact Nat.mod_eq_of_lt (by - have hbound : 32 * (attesterFirstArrayLengthWord I).toNat ≤ - 32 * solcMaxU64 := Nat.mul_le_mul_left 32 hlen - norm_num [solcMaxU64, UInt256.size] at hbound ⊢ - omega) - -theorem attesterInnerArrayAllocEndWord_toNat - {len free : UInt256} - (hfree : free.toNat + 32 + 32 * len.toNat < UInt256.size) : - (free + ((⟨32⟩ : UInt256) + UInt256.mul (⟨32⟩ : UInt256) len)).toNat = - free.toNat + 32 + 32 * len.toNat := by - have hmul : - (UInt256.mul (⟨32⟩ : UInt256) len).toNat = 32 * len.toNat := by - rw [u256_mul_toNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - exact Nat.mod_eq_of_lt (by omega) - have hinner : - (((⟨32⟩ : UInt256) + UInt256.mul (⟨32⟩ : UInt256) len).toNat) = - 32 + 32 * len.toNat := by - rw [uadd_toNat, hmul] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - exact Nat.mod_eq_of_lt (by omega) - rw [uadd_toNat, hinner] - rw [show free.toNat + (32 + 32 * len.toNat) = - free.toNat + 32 + 32 * len.toNat by omega] - exact Nat.mod_eq_of_lt hfree - -theorem attesterMultiRevokeInnerArrayCopySlotWord_toNat - {base idx : UInt256} - (hbound : base.toNat + 32 + 32 * idx.toNat < UInt256.size) : - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat = - base.toNat + 32 + 32 * idx.toNat := by - unfold attesterMultiRevokeInnerArrayCopySlotWord - have hmul : - (UInt256.mul (⟨32⟩ : UInt256) idx).toNat = 32 * idx.toNat := by - rw [u256_mul_toNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - exact Nat.mod_eq_of_lt (by omega) - have hadd : - (UInt256.mul (⟨32⟩ : UInt256) idx + base).toNat = - 32 * idx.toNat + base.toNat := by - rw [uadd_toNat, hmul] - exact Nat.mod_eq_of_lt (by omega) - rw [uadd_toNat, hadd] - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - rw [show 32 * idx.toNat + base.toNat + 32 = - base.toNat + 32 + 32 * idx.toNat by omega] - exact Nat.mod_eq_of_lt hbound - -theorem attesterMultiRevokeInnerArrayCopySlotWord_above_base - {base idx : UInt256} - (hbound : base.toNat + 32 + 32 * idx.toNat < UInt256.size) : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat := by - rw [attesterMultiRevokeInnerArrayCopySlotWord_toNat (base := base) (idx := idx) hbound] - omega - -theorem attesterMultiRevokeInnerArrayCopyZeroWord_toNat - {mem : ByteArray} {aw : UInt256} - (hfree32 : (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + 32 < - UInt256.size) : - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + 32 := by - unfold attesterMultiRevokeInnerArrayCopyZeroWord - exact uadd_lit32_toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw) hfree32 - -theorem attesterMloadActiveWordsCovers - {base aw : UInt256} - (hawMul : aw.toNat * 32 < UInt256.size) - (hcovered : base.toNat + 32 ≤ aw.toNat * 32) : - ¬ base ≥ aw * (⟨32⟩ : UInt256) := by - intro hge - have hmul : - (aw * (⟨32⟩ : UInt256)).toNat = aw.toNat * 32 := by - apply umul_toNat - rw [show (⟨32⟩ : UInt256).toNat = 32 by decide] - exact hawMul - have hle : aw.toNat * 32 ≤ base.toNat := by - change (aw * (⟨32⟩ : UInt256)).toNat ≤ base.toNat at hge - rwa [hmul] at hge - omega - -theorem attesterMachineStateM_covers_word32 (s f : Nat) : - f + 32 ≤ 32 * MachineState.M s f 32 := by - unfold MachineState.M - have hceil : f + 32 ≤ 32 * ((f + 32 + 31) / 32) := by - have hdiv : - (f + 32 + 31) / 32 ≤ (f + 32 + 31) / 32 := le_rfl - rw [Nat.div_le_iff_le_mul (by decide : 0 < 32)] at hdiv - omega - have hmax : (f + 32 + 31) / 32 ≤ max s ((f + 32 + 31) / 32) := - Nat.le_max_right _ _ - nlinarith - -theorem attesterMachineStateM_ge (s f l : Nat) : - s ≤ MachineState.M s f l := by - unfold MachineState.M - cases l <;> simp - -theorem attesterMachineStateM32_mul32_lt - {s f : Nat} - (hs : s * 32 < UInt256.size) - (hf : f + 63 < UInt256.size) : - MachineState.M s f 32 * 32 < UInt256.size := by - unfold MachineState.M - change max s ((f + 32 + 31) / 32) * 32 < UInt256.size - have hceil : ((f + 32 + 31) / 32) * 32 ≤ f + 32 + 31 := - Nat.div_mul_le_self _ _ - by_cases hle : s ≤ (f + 32 + 31) / 32 - · rw [max_eq_right hle] - omega - · rw [max_eq_left (by omega)] - exact hs - -theorem attesterMachineStateM32_lt - {s f : Nat} - (hs : s * 32 < UInt256.size) - (hf : f + 63 < UInt256.size) : - MachineState.M s f 32 < UInt256.size := by - have hmul := attesterMachineStateM32_mul32_lt (s := s) (f := f) hs hf - have hle : MachineState.M s f 32 ≤ MachineState.M s f 32 * 32 := by - nlinarith - omega - -theorem attesterMloadAw_ge - {aw off : UInt256} {n : Nat} - (hM : MachineState.M aw.toNat off.toNat 32 < UInt256.size) - (hawGe : n ≤ aw.toNat) : - n ≤ (attesterMloadAw aw off).toNat := by - unfold attesterMloadAw - rw [ulit_toNat' _ hM] - exact le_trans hawGe (attesterMachineStateM_ge aw.toNat off.toNat 32) - -theorem attesterMloadActiveWordsAfterM - {base : UInt256} {s : Nat} - (hM : MachineState.M s base.toNat 32 < UInt256.size) - (hMul : MachineState.M s base.toNat 32 * 32 < UInt256.size) : - ¬ base ≥ - UInt256.ofNat (MachineState.M s base.toNat 32) * (⟨32⟩ : UInt256) := by - apply attesterMloadActiveWordsCovers - · rw [ulit_toNat' _ hM] - exact hMul - · rw [ulit_toNat' _ hM] - simpa [Nat.mul_comm] using attesterMachineStateM_covers_word32 s base.toNat - -theorem attesterMload64ActiveWordsGe3 - {aw : UInt256} - (hawMul : aw.toNat * 32 < UInt256.size) - (hawGe : 3 ≤ aw.toNat) : - ¬ (⟨64⟩ : UInt256) ≥ aw * (⟨32⟩ : UInt256) := by - apply attesterMloadActiveWordsCovers - · exact hawMul - · rw [show (⟨64⟩ : UInt256).toNat = 64 by decide] - nlinarith - -theorem attester_uadd_lit64_toNat - (a : UInt256) (h : a.toNat + 64 < UInt256.size) : - (((⟨64⟩ : UInt256) + a).toNat = a.toNat + 64) := by - rw [uadd_toNat, show (⟨64⟩ : UInt256).toNat = 64 by decide] - rw [show 64 + a.toNat = a.toNat + 64 by omega] - exact Nat.mod_eq_of_lt h - -theorem attesterMultiOuterArrayInitStep_read64 - {slot : UInt256} {mem : ByteArray} {aw : UInt256} - (hfree : 64 + 32 ≤ (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (hoffset : 64 + 32 ≤ (attesterMultiOuterArrayInitOffsetWord mem aw).toNat) - (hslot : 64 + 32 ≤ slot.toNat) : - (attesterMultiOuterArrayInitStepMem slot mem aw).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) := by - have hread1 : - (attesterMultiOuterArrayInitFreeMem mem aw).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) := by - change (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)).readWithPadding - 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - exact attesterWriteWord_read_back_nat mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - have hmem1 : 64 + 32 ≤ (attesterMultiOuterArrayInitFreeMem mem aw).size := by - have hsize := attesterWriteWord_size_nat mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - change 64 + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)).size - rw [hsize] - change 96 ≤ max mem.size (64 + 32) - exact Nat.le_max_right _ _ - have hread2 : - (attesterMultiOuterArrayInitZeroMem mem aw).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) := by - change (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256)).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiOuterArrayInitFreeMem mem aw) - (base := 64) - (writeOff := (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (len := ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)) - (writeVal := (⟨0⟩ : UInt256)) - hmem1 hfree hread1 - have hmem2 : 64 + 32 ≤ (attesterMultiOuterArrayInitZeroMem mem aw).size := by - have hsize := attesterWriteWord_size_nat (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256) - change 64 + 32 ≤ - (Reasoning.Theory.writeWord (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256)).size - rw [hsize] - exact le_trans hmem1 (Nat.le_max_left _ _) - have hread3 : - (attesterMultiOuterArrayInitOffsetMem mem aw).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) := by - change (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiOuterArrayInitOffsetWord mem aw).toNat - (⟨96⟩ : UInt256)).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiOuterArrayInitZeroMem mem aw) - (base := 64) - (writeOff := (attesterMultiOuterArrayInitOffsetWord mem aw).toNat) - (len := ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)) - (writeVal := (⟨96⟩ : UInt256)) - hmem2 hoffset hread2 - have hmem3 : 64 + 32 ≤ (attesterMultiOuterArrayInitOffsetMem mem aw).size := by - have hsize := attesterWriteWord_size_nat (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiOuterArrayInitOffsetWord mem aw).toNat - (⟨96⟩ : UInt256) - change 64 + 32 ≤ - (Reasoning.Theory.writeWord (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiOuterArrayInitOffsetWord mem aw).toNat - (⟨96⟩ : UInt256)).size - rw [hsize] - exact le_trans hmem2 (Nat.le_max_left _ _) - change (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitOffsetMem mem aw) slot.toNat - (attesterMultiOuterArrayInitFreeWord mem aw)).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiOuterArrayInitOffsetMem mem aw) - (base := 64) (writeOff := slot.toNat) - (len := ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)) - (writeVal := attesterMultiOuterArrayInitFreeWord mem aw) - hmem3 hslot hread3 - -theorem attesterMultiOuterArrayInitStep_readWithPadding_nat - {base slot len : UInt256} {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (h64 : 64 + 32 ≤ base.toNat) - (hfree : base.toNat + 32 ≤ (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (hoffset : - base.toNat + 32 ≤ (attesterMultiOuterArrayInitOffsetWord mem aw).toNat) - (hslot : base.toNat + 32 ≤ slot.toNat) : - (attesterMultiOuterArrayInitStepMem slot mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - have hread1 : - (attesterMultiOuterArrayInitFreeMem mem aw).readWithPadding base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)).readWithPadding - base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := mem) (base := base.toNat) (writeOff := 64) - (len := len) - (writeVal := - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)) - hmem h64 hread - have hmem1 : - base.toNat + 32 ≤ (attesterMultiOuterArrayInitFreeMem mem aw).size := by - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)).size - exact le_trans hmem - (attesterWriteWord_size_ge_nat mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)) - have hread2 : - (attesterMultiOuterArrayInitZeroMem mem aw).readWithPadding base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256)).readWithPadding base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiOuterArrayInitFreeMem mem aw) - (base := base.toNat) - (writeOff := (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (len := len) (writeVal := (⟨0⟩ : UInt256)) - hmem1 hfree hread1 - have hmem2 : - base.toNat + 32 ≤ (attesterMultiOuterArrayInitZeroMem mem aw).size := by - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256)).size - exact le_trans hmem1 - (attesterWriteWord_size_ge_nat - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256)) - have hread3 : - (attesterMultiOuterArrayInitOffsetMem mem aw).readWithPadding base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiOuterArrayInitOffsetWord mem aw).toNat - (⟨96⟩ : UInt256)).readWithPadding base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiOuterArrayInitZeroMem mem aw) - (base := base.toNat) - (writeOff := (attesterMultiOuterArrayInitOffsetWord mem aw).toNat) - (len := len) (writeVal := (⟨96⟩ : UInt256)) - hmem2 hoffset hread2 - have hmem3 : - base.toNat + 32 ≤ (attesterMultiOuterArrayInitOffsetMem mem aw).size := by - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiOuterArrayInitOffsetWord mem aw).toNat - (⟨96⟩ : UInt256)).size - exact le_trans hmem2 - (attesterWriteWord_size_ge_nat - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiOuterArrayInitOffsetWord mem aw).toNat - (⟨96⟩ : UInt256)) - change (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitOffsetMem mem aw) slot.toNat - (attesterMultiOuterArrayInitFreeWord mem aw)).readWithPadding base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiOuterArrayInitOffsetMem mem aw) - (base := base.toNat) (writeOff := slot.toNat) (len := len) - (writeVal := attesterMultiOuterArrayInitFreeWord mem aw) - hmem3 hslot hread3 - -theorem attesterMultiOuterArrayInitStep_size_ge - {slot : UInt256} {mem : ByteArray} {aw : UInt256} : - mem.size ≤ (attesterMultiOuterArrayInitStepMem slot mem aw).size := by - apply le_trans (attesterWriteWord_size_ge_nat mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)) - apply le_trans (attesterWriteWord_size_ge_nat - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256)) - apply le_trans (attesterWriteWord_size_ge_nat - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiOuterArrayInitOffsetWord mem aw).toNat - (⟨96⟩ : UInt256)) - exact attesterWriteWord_size_ge_nat - (attesterMultiOuterArrayInitOffsetMem mem aw) slot.toNat - (attesterMultiOuterArrayInitFreeWord mem aw) - -theorem attesterMultiOuterArrayInitStep_mload64 - {slot : UInt256} {mem : ByteArray} {aw : UInt256} - (hfree : 64 + 32 ≤ (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (hoffset : 64 + 32 ≤ (attesterMultiOuterArrayInitOffsetWord mem aw).toNat) - (hslot : 64 + 32 ≤ slot.toNat) - (haw : - ¬ (⟨64⟩ : UInt256) ≥ - attesterMultiOuterArrayInitStepAw slot mem aw * (⟨32⟩ : UInt256)) : - attesterMultiOuterArrayInitFreeWord - (attesterMultiOuterArrayInitStepMem slot mem aw) - (attesterMultiOuterArrayInitStepAw slot mem aw) = - (⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw := by - have hread := attesterMultiOuterArrayInitStep_read64 - (slot := slot) (mem := mem) (aw := aw) - hfree hoffset hslot - have hmem : (⟨64⟩ : UInt256).toNat + 32 ≤ - (attesterMultiOuterArrayInitStepMem slot mem aw).size := by - have hsize4 := attesterWriteWord_size_nat (attesterMultiOuterArrayInitOffsetMem mem aw) - slot.toNat (attesterMultiOuterArrayInitFreeWord mem aw) - change (⟨64⟩ : UInt256).toNat + 32 ≤ - (Reasoning.Theory.writeWord (attesterMultiOuterArrayInitOffsetMem mem aw) - slot.toNat (attesterMultiOuterArrayInitFreeWord mem aw)).size - rw [hsize4] - change 96 ≤ max (attesterMultiOuterArrayInitOffsetMem mem aw).size (slot.toNat + 32) - exact le_trans (by omega) (Nat.le_max_right _ _) - exact attesterMloadWord_of_readWithPadding hmem haw hread - -theorem attesterMultiOuterArrayInitStep_freeWord_toNat - {slot : UInt256} {mem : ByteArray} {aw : UInt256} - (hfree : 64 + 32 ≤ (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (hoffset : 64 + 32 ≤ (attesterMultiOuterArrayInitOffsetWord mem aw).toNat) - (hslot : 64 + 32 ≤ slot.toNat) - (hawMul : - (attesterMultiOuterArrayInitStepAw slot mem aw).toNat * 32 < UInt256.size) - (hawGe : 3 ≤ (attesterMultiOuterArrayInitStepAw slot mem aw).toNat) - (hfreeBound : (attesterMultiOuterArrayInitFreeWord mem aw).toNat + 64 < UInt256.size) : - (attesterMultiOuterArrayInitFreeWord - (attesterMultiOuterArrayInitStepMem slot mem aw) - (attesterMultiOuterArrayInitStepAw slot mem aw)).toNat = - (attesterMultiOuterArrayInitFreeWord mem aw).toNat + 64 := by - rw [attesterMultiOuterArrayInitStep_mload64 - (slot := slot) (mem := mem) (aw := aw) - hfree hoffset hslot - (attesterMload64ActiveWordsGe3 hawMul hawGe)] - exact attester_uadd_lit64_toNat - (attesterMultiOuterArrayInitFreeWord mem aw) hfreeBound - -theorem attesterMultiOuterArrayInitStepAw_bounds - {slot : UInt256} {mem : ByteArray} {aw : UInt256} - (hawGe : 3 ≤ aw.toNat) - (hawMul : aw.toNat * 32 < UInt256.size) - (hfree95 : (attesterMultiOuterArrayInitFreeWord mem aw).toNat + 95 < UInt256.size) - (hslot63 : slot.toNat + 63 < UInt256.size) : - 3 ≤ (attesterMultiOuterArrayInitStepAw slot mem aw).toNat ∧ - (attesterMultiOuterArrayInitStepAw slot mem aw).toNat * 32 < UInt256.size := by - let aw1 := attesterMultiOuterArrayInitAwAfterMload aw - let aw2 := attesterMultiOuterArrayInitFreeAw aw - let aw3 := attesterMultiOuterArrayInitZeroAw mem aw - let aw4 := attesterMultiOuterArrayInitOffsetAw mem aw - let free := attesterMultiOuterArrayInitFreeWord mem aw - let offset := attesterMultiOuterArrayInitOffsetWord mem aw - have h64_63 : (⟨64⟩ : UInt256).toNat + 63 < UInt256.size := by decide - have hM1 : MachineState.M aw.toNat (⟨64⟩ : UInt256).toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw.toNat) (f := (⟨64⟩ : UInt256).toNat) - hawMul h64_63 - have hM1Mul : - MachineState.M aw.toNat (⟨64⟩ : UInt256).toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw.toNat) - (f := (⟨64⟩ : UInt256).toNat) hawMul h64_63 - have haw1Ge : 3 ≤ aw1.toNat := by - unfold aw1 attesterMultiOuterArrayInitAwAfterMload attesterMloadAw - rw [ulit_toNat' _ hM1] - exact le_trans hawGe - (attesterMachineStateM_ge aw.toNat (⟨64⟩ : UInt256).toNat 32) - have haw1Mul : aw1.toNat * 32 < UInt256.size := by - unfold aw1 attesterMultiOuterArrayInitAwAfterMload attesterMloadAw - rw [ulit_toNat' _ hM1] - exact hM1Mul - have hM2 : MachineState.M aw1.toNat 64 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw1.toNat) (f := 64) - haw1Mul (by norm_num [UInt256.size]) - have hM2Mul : - MachineState.M aw1.toNat 64 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw1.toNat) - (f := 64) haw1Mul (by norm_num [UInt256.size]) - have haw2Ge : 3 ≤ aw2.toNat := by - unfold aw2 attesterMultiOuterArrayInitFreeAw - rw [ulit_toNat' _ hM2] - exact le_trans haw1Ge - (attesterMachineStateM_ge aw1.toNat 64 32) - have haw2Mul : aw2.toNat * 32 < UInt256.size := by - unfold aw2 attesterMultiOuterArrayInitFreeAw - rw [ulit_toNat' _ hM2] - exact hM2Mul - have hfree63 : free.toNat + 63 < UInt256.size := by - unfold free - omega - have hM3 : MachineState.M aw2.toNat free.toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw2.toNat) (f := free.toNat) haw2Mul hfree63 - have hM3Mul : MachineState.M aw2.toNat free.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw2.toNat) (f := free.toNat) haw2Mul hfree63 - have haw3Ge : 3 ≤ aw3.toNat := by - unfold aw3 attesterMultiOuterArrayInitZeroAw - rw [ulit_toNat' _ hM3] - exact le_trans haw2Ge - (attesterMachineStateM_ge - (attesterMultiOuterArrayInitFreeAw aw).toNat - (attesterMultiOuterArrayInitFreeWord mem aw).toNat 32) - have haw3Mul : aw3.toNat * 32 < UInt256.size := by - unfold aw3 attesterMultiOuterArrayInitZeroAw - rw [ulit_toNat' _ hM3] - exact hM3Mul - have hfree32 : free.toNat + 32 < UInt256.size := by - unfold free - omega - have hoffToNat : offset.toNat = free.toNat + 32 := by - unfold offset attesterMultiOuterArrayInitOffsetWord free - exact uadd_word_lit32_toNat (attesterMultiOuterArrayInitFreeWord mem aw) hfree32 - have hoff63 : offset.toNat + 63 < UInt256.size := by - rw [hoffToNat] - omega - have hM4 : MachineState.M aw3.toNat offset.toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw3.toNat) (f := offset.toNat) haw3Mul hoff63 - have hM4Mul : MachineState.M aw3.toNat offset.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw3.toNat) (f := offset.toNat) haw3Mul hoff63 - have haw4Ge : 3 ≤ aw4.toNat := by - unfold aw4 attesterMultiOuterArrayInitOffsetAw - rw [ulit_toNat' _ hM4] - exact le_trans haw3Ge - (attesterMachineStateM_ge - (attesterMultiOuterArrayInitZeroAw mem aw).toNat - (attesterMultiOuterArrayInitOffsetWord mem aw).toNat 32) - have haw4Mul : aw4.toNat * 32 < UInt256.size := by - unfold aw4 attesterMultiOuterArrayInitOffsetAw - rw [ulit_toNat' _ hM4] - exact hM4Mul - have hM5 : MachineState.M aw4.toNat slot.toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw4.toNat) (f := slot.toNat) haw4Mul hslot63 - have hM5Mul : MachineState.M aw4.toNat slot.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw4.toNat) (f := slot.toNat) haw4Mul hslot63 - constructor - · unfold attesterMultiOuterArrayInitStepAw - rw [ulit_toNat' _ hM5] - exact le_trans haw4Ge - (attesterMachineStateM_ge - (attesterMultiOuterArrayInitOffsetAw mem aw).toNat slot.toNat 32) - · unfold attesterMultiOuterArrayInitStepAw - rw [ulit_toNat' _ hM5] - exact hM5Mul - -theorem attesterInnerArrayAllocMem_read64 - {len : UInt256} {mem : ByteArray} {aw : UInt256} : - (attesterInnerArrayAllocMem len mem aw).readWithPadding 64 32 = - UInt256.toByteArray (attesterInnerArrayAllocEndWord len mem aw) := by - change (Reasoning.Theory.writeWord (attesterInnerArrayAllocLenMem len mem aw) - 64 (attesterInnerArrayAllocEndWord len mem aw)).readWithPadding 64 32 = - UInt256.toByteArray (attesterInnerArrayAllocEndWord len mem aw) - exact attesterWriteWord_read_back_nat - (attesterInnerArrayAllocLenMem len mem aw) 64 - (attesterInnerArrayAllocEndWord len mem aw) - -theorem attesterInnerArrayAllocMem_mload64 - {len : UInt256} {mem : ByteArray} {aw : UInt256} - (haw : - ¬ (⟨64⟩ : UInt256) ≥ - attesterInnerArrayAllocAw len mem aw * (⟨32⟩ : UInt256)) : - attesterInnerArrayAllocFreeWord - (attesterInnerArrayAllocMem len mem aw) - (attesterInnerArrayAllocAw len mem aw) = - attesterInnerArrayAllocEndWord len mem aw := by - have hread := attesterInnerArrayAllocMem_read64 - (len := len) (mem := mem) (aw := aw) - have hmem : (⟨64⟩ : UInt256).toNat + 32 ≤ - (attesterInnerArrayAllocMem len mem aw).size := by - have hsize := attesterWriteWord_size_nat (attesterInnerArrayAllocLenMem len mem aw) - 64 (attesterInnerArrayAllocEndWord len mem aw) - change (⟨64⟩ : UInt256).toNat + 32 ≤ - (Reasoning.Theory.writeWord (attesterInnerArrayAllocLenMem len mem aw) - 64 (attesterInnerArrayAllocEndWord len mem aw)).size - rw [hsize] - change 96 ≤ max (attesterInnerArrayAllocLenMem len mem aw).size (64 + 32) - exact Nat.le_max_right _ _ - exact attesterMloadWord_of_readWithPadding hmem haw hread - -theorem attesterInnerArrayAllocMem_freeWord_toNat - {len : UInt256} {mem : ByteArray} {aw : UInt256} - (hawMul : (attesterInnerArrayAllocAw len mem aw).toNat * 32 < UInt256.size) - (hawGe : 3 ≤ (attesterInnerArrayAllocAw len mem aw).toNat) - (hbound : - (attesterInnerArrayAllocFreeWord mem aw).toNat + 32 + 32 * len.toNat < - UInt256.size) : - (attesterInnerArrayAllocFreeWord - (attesterInnerArrayAllocMem len mem aw) - (attesterInnerArrayAllocAw len mem aw)).toNat = - (attesterInnerArrayAllocFreeWord mem aw).toNat + 32 + 32 * len.toNat := by - rw [attesterInnerArrayAllocMem_mload64 - (len := len) (mem := mem) (aw := aw) - (attesterMload64ActiveWordsGe3 hawMul hawGe)] - exact attesterInnerArrayAllocEndWord_toNat hbound - -theorem attesterInnerArrayAllocAw_bounds - {len : UInt256} {mem : ByteArray} {aw : UInt256} - (hawGe : 3 ≤ aw.toNat) - (hawMul : aw.toNat * 32 < UInt256.size) - (hfree63 : (attesterInnerArrayAllocFreeWord mem aw).toNat + 63 < UInt256.size) : - 3 ≤ (attesterInnerArrayAllocAw len mem aw).toNat ∧ - (attesterInnerArrayAllocAw len mem aw).toNat * 32 < UInt256.size := by - let aw1 := attesterInnerArrayAllocAwAfterMload aw - let aw2 := attesterInnerArrayAllocLenAw len mem aw - have h64_63 : (⟨64⟩ : UInt256).toNat + 63 < UInt256.size := by decide - have hM1 : MachineState.M aw.toNat (⟨64⟩ : UInt256).toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw.toNat) (f := (⟨64⟩ : UInt256).toNat) - hawMul h64_63 - have hM1Mul : - MachineState.M aw.toNat (⟨64⟩ : UInt256).toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw.toNat) - (f := (⟨64⟩ : UInt256).toNat) hawMul h64_63 - have haw1Ge : 3 ≤ aw1.toNat := by - unfold aw1 attesterInnerArrayAllocAwAfterMload attesterMloadAw - rw [ulit_toNat' _ hM1] - exact le_trans hawGe - (attesterMachineStateM_ge aw.toNat (⟨64⟩ : UInt256).toNat 32) - have haw1Mul : aw1.toNat * 32 < UInt256.size := by - unfold aw1 attesterInnerArrayAllocAwAfterMload attesterMloadAw - rw [ulit_toNat' _ hM1] - exact hM1Mul - have hM2 : - MachineState.M aw1.toNat (attesterInnerArrayAllocFreeWord mem aw).toNat 32 < - UInt256.size := - attesterMachineStateM32_lt (s := aw1.toNat) - (f := (attesterInnerArrayAllocFreeWord mem aw).toNat) haw1Mul hfree63 - have hM2Mul : - MachineState.M aw1.toNat (attesterInnerArrayAllocFreeWord mem aw).toNat 32 * 32 < - UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw1.toNat) - (f := (attesterInnerArrayAllocFreeWord mem aw).toNat) haw1Mul hfree63 - have haw2Ge : 3 ≤ aw2.toNat := by - unfold aw2 attesterInnerArrayAllocLenAw - rw [ulit_toNat' _ hM2] - exact le_trans haw1Ge - (attesterMachineStateM_ge - (attesterInnerArrayAllocAwAfterMload aw).toNat - (attesterInnerArrayAllocFreeWord mem aw).toNat 32) - have haw2Mul : aw2.toNat * 32 < UInt256.size := by - unfold aw2 attesterInnerArrayAllocLenAw - rw [ulit_toNat' _ hM2] - exact hM2Mul - have hM3 : MachineState.M aw2.toNat 64 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw2.toNat) (f := 64) haw2Mul - (by norm_num [UInt256.size]) - have hM3Mul : MachineState.M aw2.toNat 64 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw2.toNat) (f := 64) haw2Mul - (by norm_num [UInt256.size]) - constructor - · unfold attesterInnerArrayAllocAw - rw [ulit_toNat' _ hM3] - exact le_trans haw2Ge - (attesterMachineStateM_ge - (attesterInnerArrayAllocLenAw len mem aw).toNat 64 32) - · unfold attesterInnerArrayAllocAw - rw [ulit_toNat' _ hM3] - exact hM3Mul - -theorem attesterInnerArrayAllocMem_base_size - {len : UInt256} {mem : ByteArray} {aw : UInt256} : - (attesterInnerArrayAllocFreeWord mem aw).toNat + 32 ≤ - (attesterInnerArrayAllocMem len mem aw).size := by - let base := attesterInnerArrayAllocFreeWord mem aw - have hmemLen : - base.toNat + 32 ≤ (attesterInnerArrayAllocLenMem len mem aw).size := by - have hsize := attesterWriteWord_size_nat mem base.toNat len - change base.toNat + 32 ≤ (Reasoning.Theory.writeWord mem base.toNat len).size - rw [hsize] - exact Nat.le_max_right _ _ - have hsize := attesterWriteWord_size_nat (attesterInnerArrayAllocLenMem len mem aw) - 64 (attesterInnerArrayAllocEndWord len mem aw) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord (attesterInnerArrayAllocLenMem len mem aw) - 64 (attesterInnerArrayAllocEndWord len mem aw)).size - rw [hsize] - exact le_trans hmemLen (Nat.le_max_left _ _) - -theorem attesterInnerArrayAllocMem_size_ge - {len : UInt256} {mem : ByteArray} {aw : UInt256} : - mem.size ≤ (attesterInnerArrayAllocMem len mem aw).size := by - apply le_trans (attesterWriteWord_size_ge_nat mem - (attesterInnerArrayAllocFreeWord mem aw).toNat len) - exact attesterWriteWord_size_ge_nat - (attesterInnerArrayAllocLenMem len mem aw) 64 - (attesterInnerArrayAllocEndWord len mem aw) - -theorem attesterInnerArrayAllocMem_readWithPadding_at_nat - {readBase len readLen : UInt256} {mem : ByteArray} {aw : UInt256} - (hmem : readBase.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding readBase.toNat 32 = UInt256.toByteArray readLen) - (h64 : 64 + 32 ≤ readBase.toNat) - (hbase : - readBase.toNat + 32 ≤ (attesterInnerArrayAllocFreeWord mem aw).toNat) : - (attesterInnerArrayAllocMem len mem aw).readWithPadding readBase.toNat 32 = - UInt256.toByteArray readLen := by - let base := attesterInnerArrayAllocFreeWord mem aw - have hreadLen : - (attesterInnerArrayAllocLenMem len mem aw).readWithPadding - readBase.toNat 32 = - UInt256.toByteArray readLen := by - change (Reasoning.Theory.writeWord mem base.toNat len).readWithPadding - readBase.toNat 32 = - UInt256.toByteArray readLen - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := mem) (base := readBase.toNat) (writeOff := base.toNat) - (len := readLen) (writeVal := len) - hmem hbase hread - have hmemLen : - readBase.toNat + 32 ≤ (attesterInnerArrayAllocLenMem len mem aw).size := by - change readBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord mem base.toNat len).size - exact le_trans hmem - (attesterWriteWord_size_ge_nat mem base.toNat len) - change (Reasoning.Theory.writeWord - (attesterInnerArrayAllocLenMem len mem aw) 64 - (attesterInnerArrayAllocEndWord len mem aw)).readWithPadding - readBase.toNat 32 = - UInt256.toByteArray readLen - exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := attesterInnerArrayAllocLenMem len mem aw) - (base := readBase.toNat) (writeOff := 64) (len := readLen) - (writeVal := attesterInnerArrayAllocEndWord len mem aw) - hmemLen h64 hreadLen - -theorem attesterInnerArrayAllocMem_readWithPadding_len_nat - {len : UInt256} {mem : ByteArray} {aw : UInt256} - (h64 : 64 + 32 ≤ (attesterInnerArrayAllocFreeWord mem aw).toNat) : - (attesterInnerArrayAllocMem len mem aw).readWithPadding - (attesterInnerArrayAllocFreeWord mem aw).toNat 32 = - UInt256.toByteArray len := by - let base := attesterInnerArrayAllocFreeWord mem aw - have hreadLen : - (attesterInnerArrayAllocLenMem len mem aw).readWithPadding base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord mem base.toNat len).readWithPadding - base.toNat 32 = UInt256.toByteArray len - exact attesterWriteWord_read_back_nat mem base.toNat len - have hmemLen : - base.toNat + 32 ≤ (attesterInnerArrayAllocLenMem len mem aw).size := by - have hsize := attesterWriteWord_size_nat mem base.toNat len - change base.toNat + 32 ≤ (Reasoning.Theory.writeWord mem base.toNat len).size - rw [hsize] - exact Nat.le_max_right _ _ - change (Reasoning.Theory.writeWord - (attesterInnerArrayAllocLenMem len mem aw) 64 - (attesterInnerArrayAllocEndWord len mem aw)).readWithPadding - base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := attesterInnerArrayAllocLenMem len mem aw) - (base := base.toNat) (writeOff := 64) (len := len) - (writeVal := attesterInnerArrayAllocEndWord len mem aw) - hmemLen h64 hreadLen - -theorem attesterInnerArrayAllocMem_mloadLen_nat - {len : UInt256} {mem : ByteArray} {aw : UInt256} - (h64 : 64 + 32 ≤ (attesterInnerArrayAllocFreeWord mem aw).toNat) - (haw : - ¬ attesterInnerArrayAllocFreeWord mem aw ≥ - attesterInnerArrayAllocAw len mem aw * (⟨32⟩ : UInt256)) : - attesterMloadWord - (attesterInnerArrayAllocMem len mem aw) - (attesterInnerArrayAllocAw len mem aw) - (attesterInnerArrayAllocFreeWord mem aw) = len := by - let base := attesterInnerArrayAllocFreeWord mem aw - have hread := - attesterInnerArrayAllocMem_readWithPadding_len_nat - (len := len) (mem := mem) (aw := aw) h64 - have hmemLen : - base.toNat + 32 ≤ (attesterInnerArrayAllocLenMem len mem aw).size := by - have hsize := attesterWriteWord_size_nat mem base.toNat len - change base.toNat + 32 ≤ (Reasoning.Theory.writeWord mem base.toNat len).size - rw [hsize] - exact Nat.le_max_right _ _ - have hmem : - base.toNat + 32 ≤ (attesterInnerArrayAllocMem len mem aw).size := by - have hsize := attesterWriteWord_size_nat (attesterInnerArrayAllocLenMem len mem aw) - 64 (attesterInnerArrayAllocEndWord len mem aw) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord (attesterInnerArrayAllocLenMem len mem aw) - 64 (attesterInnerArrayAllocEndWord len mem aw)).size - rw [hsize] - exact le_trans hmemLen (Nat.le_max_left _ _) - exact attesterMloadWord_of_readWithPadding hmem haw (by simpa [base] using hread) - -theorem attesterMultiRevokeInnerArrayInitStep_readWithPadding_nat - {base slot len : UInt256} {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (h64 : 64 + 32 ≤ base.toNat) - (hfree : - base.toNat + 32 ≤ (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (hsecond : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat) - (hslot : base.toNat + 32 ≤ slot.toNat) : - (attesterMultiRevokeInnerArrayInitStepMem slot mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - have hread1 : - (attesterMultiOuterArrayInitFreeMem mem aw).readWithPadding base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)).readWithPadding - base.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := mem) (base := base.toNat) (writeOff := 64) - (len := len) - (writeVal := - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)) - hmem h64 hread - have hmem1 : - base.toNat + 32 ≤ (attesterMultiOuterArrayInitFreeMem mem aw).size := by - have hsize := attesterWriteWord_size_nat mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)).size - rw [hsize] - exact le_trans hmem (Nat.le_max_left _ _) - have hread2 : - (attesterMultiOuterArrayInitZeroMem mem aw).readWithPadding base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256)).readWithPadding base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiOuterArrayInitFreeMem mem aw) - (base := base.toNat) - (writeOff := (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (len := len) (writeVal := (⟨0⟩ : UInt256)) - hmem1 hfree hread1 - have hmem2 : - base.toNat + 32 ≤ (attesterMultiOuterArrayInitZeroMem mem aw).size := by - have hsize := attesterWriteWord_size_nat - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256)).size - rw [hsize] - exact le_trans hmem1 (Nat.le_max_left _ _) - have hread3 : - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).readWithPadding base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiOuterArrayInitZeroMem mem aw) - (base := base.toNat) - (writeOff := (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat) - (len := len) (writeVal := (⟨0⟩ : UInt256)) - hmem2 hsecond hread2 - have hmem3 : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw).size := by - have hsize := attesterWriteWord_size_nat - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - (⟨0⟩ : UInt256) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).size - rw [hsize] - exact le_trans hmem2 (Nat.le_max_left _ _) - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw) - slot.toNat (attesterMultiOuterArrayInitFreeWord mem aw)).readWithPadding - base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw) - (base := base.toNat) (writeOff := slot.toNat) (len := len) - (writeVal := attesterMultiOuterArrayInitFreeWord mem aw) - hmem3 hslot hread3 - -theorem attesterMultiRevokeInnerArrayInitStep_read64 - {slot : UInt256} {mem : ByteArray} {aw : UInt256} - (hfree : 64 + 32 ≤ (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (hsecond : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat) - (hslot : 64 + 32 ≤ slot.toNat) : - (attesterMultiRevokeInnerArrayInitStepMem slot mem aw).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) := by - have hread1 : - (attesterMultiOuterArrayInitFreeMem mem aw).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) := by - change (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)).readWithPadding - 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - exact attesterWriteWord_read_back_nat mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - have hmem1 : 64 + 32 ≤ (attesterMultiOuterArrayInitFreeMem mem aw).size := by - have hsize := attesterWriteWord_size_nat mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - change 64 + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)).size - rw [hsize] - change 96 ≤ max mem.size (64 + 32) - exact Nat.le_max_right _ _ - have hread2 : - (attesterMultiOuterArrayInitZeroMem mem aw).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) := by - change (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256)).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiOuterArrayInitFreeMem mem aw) - (base := 64) - (writeOff := (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (len := ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)) - (writeVal := (⟨0⟩ : UInt256)) - hmem1 hfree hread1 - have hmem2 : 64 + 32 ≤ (attesterMultiOuterArrayInitZeroMem mem aw).size := by - have hsize := attesterWriteWord_size_nat (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256) - change 64 + 32 ≤ - (Reasoning.Theory.writeWord (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256)).size - rw [hsize] - exact le_trans hmem1 (Nat.le_max_left _ _) - have hread3 : - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) := by - change (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiOuterArrayInitZeroMem mem aw) - (base := 64) - (writeOff := (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat) - (len := ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)) - (writeVal := (⟨0⟩ : UInt256)) - hmem2 hsecond hread2 - have hmem3 : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw).size := by - have hsize := attesterWriteWord_size_nat (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - (⟨0⟩ : UInt256) - change 64 + 32 ≤ - (Reasoning.Theory.writeWord (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).size - rw [hsize] - exact le_trans hmem2 (Nat.le_max_left _ _) - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw) slot.toNat - (attesterMultiOuterArrayInitFreeWord mem aw)).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw) - (base := 64) (writeOff := slot.toNat) - (len := ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)) - (writeVal := attesterMultiOuterArrayInitFreeWord mem aw) - hmem3 hslot hread3 - -theorem attesterMultiRevokeInnerArrayInitStep_mload64 - {slot : UInt256} {mem : ByteArray} {aw : UInt256} - (hfree : 64 + 32 ≤ (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (hsecond : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat) - (hslot : 64 + 32 ≤ slot.toNat) - (haw : - ¬ (⟨64⟩ : UInt256) ≥ - attesterMultiRevokeInnerArrayInitStepAw slot mem aw * (⟨32⟩ : UInt256)) : - attesterMultiOuterArrayInitFreeWord - (attesterMultiRevokeInnerArrayInitStepMem slot mem aw) - (attesterMultiRevokeInnerArrayInitStepAw slot mem aw) = - (⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw := by - have hread := attesterMultiRevokeInnerArrayInitStep_read64 - (slot := slot) (mem := mem) (aw := aw) - hfree hsecond hslot - have hmem : (⟨64⟩ : UInt256).toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem slot mem aw).size := by - have hsize := attesterWriteWord_size_nat - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw) - slot.toNat (attesterMultiOuterArrayInitFreeWord mem aw) - change (⟨64⟩ : UInt256).toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw) - slot.toNat (attesterMultiOuterArrayInitFreeWord mem aw)).size - rw [hsize] - change 96 ≤ max (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw).size - (slot.toNat + 32) - exact le_trans (by omega) (Nat.le_max_right _ _) - exact attesterMloadWord_of_readWithPadding hmem haw hread - -theorem attesterMultiRevokeInnerArrayInitStep_freeWord_toNat - {slot : UInt256} {mem : ByteArray} {aw : UInt256} - (hfree : 64 + 32 ≤ (attesterMultiOuterArrayInitFreeWord mem aw).toNat) - (hsecond : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat) - (hslot : 64 + 32 ≤ slot.toNat) - (hawMul : - (attesterMultiRevokeInnerArrayInitStepAw slot mem aw).toNat * 32 < - UInt256.size) - (hawGe : 3 ≤ (attesterMultiRevokeInnerArrayInitStepAw slot mem aw).toNat) - (hfreeBound : (attesterMultiOuterArrayInitFreeWord mem aw).toNat + 64 < UInt256.size) : - (attesterMultiOuterArrayInitFreeWord - (attesterMultiRevokeInnerArrayInitStepMem slot mem aw) - (attesterMultiRevokeInnerArrayInitStepAw slot mem aw)).toNat = - (attesterMultiOuterArrayInitFreeWord mem aw).toNat + 64 := by - rw [attesterMultiRevokeInnerArrayInitStep_mload64 - (slot := slot) (mem := mem) (aw := aw) - hfree hsecond hslot - (attesterMload64ActiveWordsGe3 hawMul hawGe)] - exact attester_uadd_lit64_toNat - (attesterMultiOuterArrayInitFreeWord mem aw) hfreeBound - -theorem attesterMultiRevokeInnerArrayInitSecondZeroWord_toNat - {mem : ByteArray} {aw : UInt256} - (hfree32 : (attesterMultiOuterArrayInitFreeWord mem aw).toNat + 32 < UInt256.size) : - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat = - (attesterMultiOuterArrayInitFreeWord mem aw).toNat + 32 := by - unfold attesterMultiRevokeInnerArrayInitSecondZeroWord - exact uadd_word_lit32_toNat (attesterMultiOuterArrayInitFreeWord mem aw) hfree32 - -theorem attesterMultiRevokeInnerArrayInitStepAw_bounds - {slot : UInt256} {mem : ByteArray} {aw : UInt256} - (hawGe : 3 ≤ aw.toNat) - (hawMul : aw.toNat * 32 < UInt256.size) - (hfree63 : (attesterMultiOuterArrayInitFreeWord mem aw).toNat + 63 < UInt256.size) - (hsecond63 : (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat + 63 < - UInt256.size) - (hslot63 : slot.toNat + 63 < UInt256.size) : - 3 ≤ (attesterMultiRevokeInnerArrayInitStepAw slot mem aw).toNat ∧ - (attesterMultiRevokeInnerArrayInitStepAw slot mem aw).toNat * 32 < - UInt256.size := by - let aw1 := attesterMultiOuterArrayInitAwAfterMload aw - let aw2 := attesterMultiOuterArrayInitFreeAw aw - let aw3 := attesterMultiOuterArrayInitZeroAw mem aw - let aw4 := attesterMultiRevokeInnerArrayInitSecondZeroAw mem aw - have h64_63 : (⟨64⟩ : UInt256).toNat + 63 < UInt256.size := by decide - have hM1 : MachineState.M aw.toNat (⟨64⟩ : UInt256).toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw.toNat) (f := (⟨64⟩ : UInt256).toNat) - hawMul h64_63 - have hM1Mul : - MachineState.M aw.toNat (⟨64⟩ : UInt256).toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw.toNat) - (f := (⟨64⟩ : UInt256).toNat) hawMul h64_63 - have haw1Ge : 3 ≤ aw1.toNat := by - unfold aw1 attesterMultiOuterArrayInitAwAfterMload attesterMloadAw - rw [ulit_toNat' _ hM1] - exact le_trans hawGe - (attesterMachineStateM_ge aw.toNat (⟨64⟩ : UInt256).toNat 32) - have haw1Mul : aw1.toNat * 32 < UInt256.size := by - unfold aw1 attesterMultiOuterArrayInitAwAfterMload attesterMloadAw - rw [ulit_toNat' _ hM1] - exact hM1Mul - have hM2 : MachineState.M aw1.toNat 64 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw1.toNat) (f := 64) - haw1Mul (by norm_num [UInt256.size]) - have hM2Mul : - MachineState.M aw1.toNat 64 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw1.toNat) - (f := 64) haw1Mul (by norm_num [UInt256.size]) - have haw2Ge : 3 ≤ aw2.toNat := by - unfold aw2 attesterMultiOuterArrayInitFreeAw - rw [ulit_toNat' _ hM2] - exact le_trans haw1Ge - (attesterMachineStateM_ge aw1.toNat 64 32) - have haw2Mul : aw2.toNat * 32 < UInt256.size := by - unfold aw2 attesterMultiOuterArrayInitFreeAw - rw [ulit_toNat' _ hM2] - exact hM2Mul - have hM3 : MachineState.M aw2.toNat - (attesterMultiOuterArrayInitFreeWord mem aw).toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw2.toNat) - (f := (attesterMultiOuterArrayInitFreeWord mem aw).toNat) haw2Mul hfree63 - have hM3Mul : MachineState.M aw2.toNat - (attesterMultiOuterArrayInitFreeWord mem aw).toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw2.toNat) - (f := (attesterMultiOuterArrayInitFreeWord mem aw).toNat) haw2Mul hfree63 - have haw3Ge : 3 ≤ aw3.toNat := by - unfold aw3 attesterMultiOuterArrayInitZeroAw - rw [ulit_toNat' _ hM3] - exact le_trans haw2Ge - (attesterMachineStateM_ge - (attesterMultiOuterArrayInitFreeAw aw).toNat - (attesterMultiOuterArrayInitFreeWord mem aw).toNat 32) - have haw3Mul : aw3.toNat * 32 < UInt256.size := by - unfold aw3 attesterMultiOuterArrayInitZeroAw - rw [ulit_toNat' _ hM3] - exact hM3Mul - have hM4 : - MachineState.M aw3.toNat - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat 32 < - UInt256.size := - attesterMachineStateM32_lt (s := aw3.toNat) - (f := (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat) - haw3Mul hsecond63 - have hM4Mul : - MachineState.M aw3.toNat - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat 32 * 32 < - UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw3.toNat) - (f := (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat) - haw3Mul hsecond63 - have haw4Ge : 3 ≤ aw4.toNat := by - unfold aw4 attesterMultiRevokeInnerArrayInitSecondZeroAw - rw [ulit_toNat' _ hM4] - exact le_trans haw3Ge - (attesterMachineStateM_ge - (attesterMultiOuterArrayInitZeroAw mem aw).toNat - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat 32) - have haw4Mul : aw4.toNat * 32 < UInt256.size := by - unfold aw4 attesterMultiRevokeInnerArrayInitSecondZeroAw - rw [ulit_toNat' _ hM4] - exact hM4Mul - have hM5 : - MachineState.M aw4.toNat slot.toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw4.toNat) (f := slot.toNat) - haw4Mul hslot63 - have hM5Mul : - MachineState.M aw4.toNat slot.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw4.toNat) (f := slot.toNat) - haw4Mul hslot63 - constructor - · unfold attesterMultiRevokeInnerArrayInitStepAw - rw [ulit_toNat' _ hM5] - exact le_trans haw4Ge - (attesterMachineStateM_ge - (attesterMultiRevokeInnerArrayInitSecondZeroAw mem aw).toNat - slot.toNat 32) - · unfold attesterMultiRevokeInnerArrayInitStepAw - rw [ulit_toNat' _ hM5] - exact hM5Mul - -theorem attesterMultiRevokeInnerArrayInitStep_base_size - {base slot len : UInt256} {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem slot mem aw).size := by - have hsize1 := attesterWriteWord_size_nat mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw) - have hsize2 := attesterWriteWord_size_nat - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256) - have hsize3 := attesterWriteWord_size_nat - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - (⟨0⟩ : UInt256) - have hsize4 := attesterWriteWord_size_nat - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw) - slot.toNat (attesterMultiOuterArrayInitFreeWord mem aw) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw) - slot.toNat (attesterMultiOuterArrayInitFreeWord mem aw)).size - rw [hsize4] - change base.toNat + 32 ≤ max - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw).size (slot.toNat + 32) - apply le_trans _ (Nat.le_max_left _ _) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).size - rw [hsize3] - apply le_trans _ (Nat.le_max_left _ _) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256)).size - rw [hsize2] - apply le_trans _ (Nat.le_max_left _ _) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)).size - rw [hsize1] - exact le_trans hmem (Nat.le_max_left _ _) - -theorem attesterMultiRevokeInnerArrayInitStep_size_ge - {slot : UInt256} {mem : ByteArray} {aw : UInt256} : - mem.size ≤ (attesterMultiRevokeInnerArrayInitStepMem slot mem aw).size := by - apply le_trans (attesterWriteWord_size_ge_nat mem 64 - ((⟨64⟩ : UInt256) + attesterMultiOuterArrayInitFreeWord mem aw)) - apply le_trans (attesterWriteWord_size_ge_nat - (attesterMultiOuterArrayInitFreeMem mem aw) - (attesterMultiOuterArrayInitFreeWord mem aw).toNat - (⟨0⟩ : UInt256)) - apply le_trans (attesterWriteWord_size_ge_nat - (attesterMultiOuterArrayInitZeroMem mem aw) - (attesterMultiRevokeInnerArrayInitSecondZeroWord mem aw).toNat - (⟨0⟩ : UInt256)) - exact attesterWriteWord_size_ge_nat - (attesterMultiRevokeInnerArrayInitSecondZeroMem mem aw) slot.toNat - (attesterMultiOuterArrayInitFreeWord mem aw) - -theorem attesterMultiRevokeInnerArrayCopyStep_read64 - {I : ExecutionEnv} {base payload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hfree : 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) - (hslot : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat) : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw) := by - have hread1 : - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw) := by - change (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw)).readWithPadding - 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - exact attesterWriteWord_read_back_nat mem 64 - ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - have hmem1 : 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).size := by - have hsize := attesterWriteWord_size_nat mem 64 - ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - change 64 + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw)).size - rw [hsize] - change 96 ≤ max mem.size (64 + 32) - exact Nat.le_max_right _ _ - have hread2 : - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).readWithPadding - 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw) := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)).readWithPadding - 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (base := 64) - (writeOff := (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (len := ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw)) - (writeVal := attesterMultiRevokeInnerArrayCopyUidWord I payload idx) - hmem1 hfree hread1 - have hmem2 : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size := by - have hsize := attesterWriteWord_size_nat (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx) - change 64 + 32 ≤ - (Reasoning.Theory.writeWord (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)).size - rw [hsize] - exact le_trans hmem1 (Nat.le_max_left _ _) - have hread3 : - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).readWithPadding - 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw) := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (base := 64) - (writeOff := (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) - (len := ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw)) - (writeVal := (⟨0⟩ : UInt256)) - hmem2 hzero hread2 - have hmem3 : - 64 + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).size := by - have hsize := attesterWriteWord_size_nat - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256) - change 64 + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).size - rw [hsize] - exact le_trans hmem2 (Nat.le_max_left _ _) - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw)).readWithPadding 64 32 = - UInt256.toByteArray - ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (base := 64) - (writeOff := (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat) - (len := ((⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw)) - (writeVal := attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - hmem3 hslot hread3 - -theorem attesterMultiRevokeInnerArrayCopyZero_readWithPadding_nat - {I : ExecutionEnv} {base payload idx len : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (h64 : 64 + 32 ≤ base.toNat) - (huid : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) : - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - have hread1 : - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw)).readWithPadding - base.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := mem) (base := base.toNat) (writeOff := 64) - (len := len) (writeVal := attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw) - hmem h64 hread - have hmem1 : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).size := by - have hsize := attesterWriteWord_size_nat mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw)).size - rw [hsize] - exact le_trans hmem (Nat.le_max_left _ _) - have hread2 : - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)).readWithPadding - base.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (base := base.toNat) - (writeOff := (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (len := len) - (writeVal := attesterMultiRevokeInnerArrayCopyUidWord I payload idx) - hmem1 huid hread1 - have hmem2 : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size := by - have hsize := attesterWriteWord_size_nat (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)).size - rw [hsize] - exact le_trans hmem1 (Nat.le_max_left _ _) - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).readWithPadding base.toNat 32 = - UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (base := base.toNat) - (writeOff := (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) - (len := len) (writeVal := (⟨0⟩ : UInt256)) - hmem2 hzero hread2 - -theorem attesterMultiRevokeInnerArrayCopyZero_mloadLen_nat - {I : ExecutionEnv} {base payload idx len : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (haw : - ¬ base ≥ - attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw * (⟨32⟩ : UInt256)) - (h64 : 64 + 32 ≤ base.toNat) - (huid : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) : - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw) - base = len := by - have hreadZero := - attesterMultiRevokeInnerArrayCopyZero_readWithPadding_nat - (I := I) (base := base) (payload := payload) (idx := idx) - (len := len) (mem := mem) (aw := aw) - hmem hread h64 huid hzero - have hmem1 : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).size := by - have hsize := attesterWriteWord_size_nat mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw)).size - rw [hsize] - exact le_trans hmem (Nat.le_max_left _ _) - have hmem2 : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size := by - have hsize := attesterWriteWord_size_nat (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)).size - rw [hsize] - exact le_trans hmem1 (Nat.le_max_left _ _) - have hmemZero : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).size := by - have hsize := attesterWriteWord_size_nat - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).size - rw [hsize] - exact le_trans hmem2 (Nat.le_max_left _ _) - exact attesterMloadWord_of_readWithPadding hmemZero haw hreadZero - -theorem attesterMultiRevokeInnerArrayCopyStep_readWithPadding_nat - {I : ExecutionEnv} {base payload idx len : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (h64 : 64 + 32 ≤ base.toNat) - (huid : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) - (hslot : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat) : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - have hreadZero := - attesterMultiRevokeInnerArrayCopyZero_readWithPadding_nat - (I := I) (base := base) (payload := payload) (idx := idx) - (len := len) (mem := mem) (aw := aw) - hmem hread h64 huid hzero - have hmem1 : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).size := by - have hsize := attesterWriteWord_size_nat mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw)).size - rw [hsize] - exact le_trans hmem (Nat.le_max_left _ _) - have hmem2 : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size := by - have hsize := attesterWriteWord_size_nat (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)).size - rw [hsize] - exact le_trans hmem1 (Nat.le_max_left _ _) - have hmem3 : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).size := by - have hsize := attesterWriteWord_size_nat - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).size - rw [hsize] - exact le_trans hmem2 (Nat.le_max_left _ _) - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw)).readWithPadding - base.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (base := base.toNat) - (writeOff := (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat) - (len := len) - (writeVal := attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - hmem3 hslot hreadZero - -theorem attesterMultiRevokeInnerArrayCopyStep_readWithPadding_at_nat - {I : ExecutionEnv} {readBase base payload idx len : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : readBase.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding readBase.toNat 32 = UInt256.toByteArray len) - (h64 : 64 + 32 ≤ readBase.toNat) - (huid : - readBase.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : - readBase.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) - (hslot : - readBase.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat) : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - readBase.toNat 32 = - UInt256.toByteArray len := by - have hreadZero := - attesterMultiRevokeInnerArrayCopyZero_readWithPadding_nat - (I := I) (base := readBase) (payload := payload) (idx := idx) - (len := len) (mem := mem) (aw := aw) - hmem hread h64 huid hzero - have hmem1 : - readBase.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).size := by - change readBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw)).size - exact le_trans hmem - (attesterWriteWord_size_ge_nat mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw)) - have hmem2 : - readBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size := by - change readBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)).size - exact le_trans hmem1 - (attesterWriteWord_size_ge_nat - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)) - have hmem3 : - readBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).size := by - change readBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).size - exact le_trans hmem2 - (attesterWriteWord_size_ge_nat - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256)) - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw)).readWithPadding - readBase.toNat 32 = UInt256.toByteArray len - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (base := readBase.toNat) - (writeOff := (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat) - (len := len) - (writeVal := attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - hmem3 hslot hreadZero - -theorem attesterMultiRevokeInnerArrayCopyStep_readWithPadding_at_nat_disj - {I : ExecutionEnv} {readBase base payload idx len : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : readBase.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding readBase.toNat 32 = UInt256.toByteArray len) - (h64 : 64 + 32 ≤ readBase.toNat) - (huid : - readBase.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : - readBase.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) - (hslotDisj : - readBase.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat ∨ - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat + 32 ≤ readBase.toNat) : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - readBase.toNat 32 = - UInt256.toByteArray len := by - have hreadZero := - attesterMultiRevokeInnerArrayCopyZero_readWithPadding_nat - (I := I) (base := readBase) (payload := payload) (idx := idx) - (len := len) (mem := mem) (aw := aw) - hmem hread h64 huid hzero - have hmem1 : - readBase.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeMem mem aw).size := by - change readBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw)).size - exact le_trans hmem - (attesterWriteWord_size_ge_nat mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw)) - have hmem2 : - readBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size := by - change readBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)).size - exact le_trans hmem1 - (attesterWriteWord_size_ge_nat - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)) - have hmem3 : - readBase.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).size := by - change readBase.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).size - exact le_trans hmem2 - (attesterWriteWord_size_ge_nat - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256)) - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw)).readWithPadding - readBase.toNat 32 = UInt256.toByteArray len - rcases hslotDisj with hslotAbove | hslotBelow - · exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (base := readBase.toNat) - (writeOff := (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat) - (len := len) - (writeVal := attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - hmem3 hslotAbove hreadZero - · exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (base := readBase.toNat) - (writeOff := (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat) - (len := len) - (writeVal := attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - hmem3 hslotBelow hreadZero - -theorem attesterMultiRevokeInnerArrayCopyStep_read_current_slot - {I : ExecutionEnv} {base payload idx : UInt256} - {mem : ByteArray} {aw : UInt256} : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat 32 = - UInt256.toByteArray (attesterMultiRevokeInnerArrayCopyFreeWord mem aw) := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw)).readWithPadding - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat 32 = - UInt256.toByteArray (attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - exact attesterWriteWord_read_back_nat - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - -theorem attesterMultiRevokeInnerArrayCopyStep_read_current_uid - {I : ExecutionEnv} {base payload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hzeroToNat : - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + 32) - (hslotDisj : - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat ∨ - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat 32 = - UInt256.toByteArray (attesterMultiRevokeInnerArrayCopyUidWord I payload idx) := by - let free := attesterMultiRevokeInnerArrayCopyFreeWord mem aw - let zero := attesterMultiRevokeInnerArrayCopyZeroWord mem aw - let slot := attesterMultiRevokeInnerArrayCopySlotWord base idx - let uidWord := attesterMultiRevokeInnerArrayCopyUidWord I payload idx - have hreadUid : - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).readWithPadding - free.toNat 32 = - UInt256.toByteArray uidWord := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - free.toNat uidWord).readWithPadding free.toNat 32 = - UInt256.toByteArray uidWord - exact attesterWriteWord_read_back_nat - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) free.toNat uidWord - have hmemUid : - free.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw).size := by - change free.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - free.toNat uidWord).size - rw [attesterWriteWord_size_nat - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) free.toNat uidWord] - exact Nat.le_max_right _ _ - have hreadZero : - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).readWithPadding - free.toNat 32 = - UInt256.toByteArray uidWord := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - zero.toNat (⟨0⟩ : UInt256)).readWithPadding free.toNat 32 = - UInt256.toByteArray uidWord - exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (base := free.toNat) (writeOff := zero.toNat) - (len := uidWord) (writeVal := (⟨0⟩ : UInt256)) - hmemUid (by rw [hzeroToNat]) hreadUid - have hmemZero : - free.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).size := by - change free.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - zero.toNat (⟨0⟩ : UInt256)).size - exact le_trans hmemUid - (attesterWriteWord_size_ge_nat - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - zero.toNat (⟨0⟩ : UInt256)) - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - slot.toNat free).readWithPadding free.toNat 32 = - UInt256.toByteArray uidWord - rcases hslotDisj with hslotAbove | hslotBelow - · exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (base := free.toNat) (writeOff := slot.toNat) - (len := uidWord) (writeVal := free) - hmemZero hslotAbove hreadZero - · exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (base := free.toNat) (writeOff := slot.toNat) - (len := uidWord) (writeVal := free) - hmemZero hslotBelow hreadZero - -theorem attesterMultiRevokeInnerArrayCopyStep_read_current_zero - {I : ExecutionEnv} {base payload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hslotDisj : - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat ∨ - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).readWithPadding - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat 32 = - UInt256.toByteArray (⟨0⟩ : UInt256) := by - let zero := attesterMultiRevokeInnerArrayCopyZeroWord mem aw - let slot := attesterMultiRevokeInnerArrayCopySlotWord base idx - let free := attesterMultiRevokeInnerArrayCopyFreeWord mem aw - have hreadZero : - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).readWithPadding - zero.toNat 32 = - UInt256.toByteArray (⟨0⟩ : UInt256) := by - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - zero.toNat (⟨0⟩ : UInt256)).readWithPadding zero.toNat 32 = - UInt256.toByteArray (⟨0⟩ : UInt256) - exact attesterWriteWord_read_back_nat - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - zero.toNat (⟨0⟩ : UInt256) - have hmemZero : - zero.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).size := by - change zero.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - zero.toNat (⟨0⟩ : UInt256)).size - rw [attesterWriteWord_size_nat - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - zero.toNat (⟨0⟩ : UInt256)] - exact Nat.le_max_right _ _ - change (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - slot.toNat free).readWithPadding zero.toNat 32 = - UInt256.toByteArray (⟨0⟩ : UInt256) - rcases hslotDisj with hslotAbove | hslotBelow - · exact attesterReadWithPadding_writeWord_preserved_above_nat - (mem := attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (base := zero.toNat) (writeOff := slot.toNat) - (len := (⟨0⟩ : UInt256)) (writeVal := free) - hmemZero hslotAbove hreadZero - · exact attesterReadWithPadding_writeWord_preserved_below_nat - (mem := attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (base := zero.toNat) (writeOff := slot.toNat) - (len := (⟨0⟩ : UInt256)) (writeVal := free) - hmemZero hslotBelow hreadZero - -theorem attesterMultiRevokeInnerArrayCopyStep_base_size - {I : ExecutionEnv} {base payload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).size := by - have hsize1 := attesterWriteWord_size_nat mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw) - have hsize2 := attesterWriteWord_size_nat - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx) - have hsize3 := attesterWriteWord_size_nat - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256) - have hsize4 := attesterWriteWord_size_nat - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw)).size - rw [hsize4] - apply le_trans _ (Nat.le_max_left _ _) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256)).size - rw [hsize3] - apply le_trans _ (Nat.le_max_left _ _) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)).size - rw [hsize2] - apply le_trans _ (Nat.le_max_left _ _) - change base.toNat + 32 ≤ - (Reasoning.Theory.writeWord mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw)).size - rw [hsize1] - exact le_trans hmem (Nat.le_max_left _ _) - -theorem attesterMultiRevokeInnerArrayCopyStep_size_ge - {I : ExecutionEnv} {base payload idx : UInt256} - {mem : ByteArray} {aw : UInt256} : - mem.size ≤ (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).size := by - apply le_trans (attesterWriteWord_size_ge_nat mem 64 - (attesterMultiRevokeInnerArrayCopyFreeBumpWord mem aw)) - apply le_trans (attesterWriteWord_size_ge_nat - (attesterMultiRevokeInnerArrayCopyFreeMem mem aw) - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat - (attesterMultiRevokeInnerArrayCopyUidWord I payload idx)) - apply le_trans (attesterWriteWord_size_ge_nat - (attesterMultiRevokeInnerArrayCopyUidMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat - (⟨0⟩ : UInt256)) - exact attesterWriteWord_size_ge_nat - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - -theorem attesterMultiRevokeInnerArrayCopyStep_mload64 - {I : ExecutionEnv} {base payload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hfree : 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) - (hslot : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat) - (haw : - ¬ (⟨64⟩ : UInt256) ≥ - attesterMultiRevokeInnerArrayCopyStepAw I base payload idx mem aw * - (⟨32⟩ : UInt256)) : - attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload idx mem aw) = - (⟨64⟩ : UInt256) + attesterMultiRevokeInnerArrayCopyFreeWord mem aw := by - have hread := attesterMultiRevokeInnerArrayCopyStep_read64 - (I := I) (base := base) (payload := payload) (idx := idx) - (mem := mem) (aw := aw) - hfree hzero hslot - have hmem : (⟨64⟩ : UInt256).toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw).size := by - have hsize := attesterWriteWord_size_nat - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw) - change (⟨64⟩ : UInt256).toNat + 32 ≤ - (Reasoning.Theory.writeWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw)).size - rw [hsize] - change 96 ≤ max - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw).size - ((attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat + 32) - exact le_trans (by omega) (Nat.le_max_right _ _) - exact attesterMloadWord_of_readWithPadding hmem haw hread - -theorem attesterMultiRevokeInnerArrayCopyStepAw_bounds - {I : ExecutionEnv} {base payload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hawGe : 3 ≤ aw.toNat) - (hawMul : aw.toNat * 32 < UInt256.size) - (hbase63 : base.toNat + 63 < UInt256.size) - (hfree63 : (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + 63 < - UInt256.size) - (hzero63 : (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat + 63 < - UInt256.size) - (hslot63 : (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat + 63 < - UInt256.size) : - 3 ≤ (attesterMultiRevokeInnerArrayCopyStepAw I base payload idx mem aw).toNat ∧ - (attesterMultiRevokeInnerArrayCopyStepAw I base payload idx mem aw).toNat * 32 < - UInt256.size := by - let aw1 := attesterMultiRevokeInnerArrayCopyAwAfterMload aw - let aw2 := attesterMultiRevokeInnerArrayCopyFreeAw mem aw - let aw3 := attesterMultiRevokeInnerArrayCopyUidAw idx mem aw - let aw4 := attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw - let aw5 := attesterMloadAw aw4 base - let free := attesterMultiRevokeInnerArrayCopyFreeWord mem aw - let zero := attesterMultiRevokeInnerArrayCopyZeroWord mem aw - let slot := attesterMultiRevokeInnerArrayCopySlotWord base idx - have h64_63 : (⟨64⟩ : UInt256).toNat + 63 < UInt256.size := by decide - have hM1 : MachineState.M aw.toNat (⟨64⟩ : UInt256).toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw.toNat) (f := (⟨64⟩ : UInt256).toNat) - hawMul h64_63 - have hM1Mul : - MachineState.M aw.toNat (⟨64⟩ : UInt256).toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw.toNat) - (f := (⟨64⟩ : UInt256).toNat) hawMul h64_63 - have haw1Ge : 3 ≤ aw1.toNat := by - unfold aw1 attesterMultiRevokeInnerArrayCopyAwAfterMload attesterMloadAw - rw [ulit_toNat' _ hM1] - exact le_trans hawGe - (attesterMachineStateM_ge aw.toNat (⟨64⟩ : UInt256).toNat 32) - have haw1Mul : aw1.toNat * 32 < UInt256.size := by - unfold aw1 attesterMultiRevokeInnerArrayCopyAwAfterMload attesterMloadAw - rw [ulit_toNat' _ hM1] - exact hM1Mul - have hM2 : MachineState.M aw1.toNat 64 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw1.toNat) (f := 64) - haw1Mul (by norm_num [UInt256.size]) - have hM2Mul : MachineState.M aw1.toNat 64 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw1.toNat) (f := 64) - haw1Mul (by norm_num [UInt256.size]) - have haw2Ge : 3 ≤ aw2.toNat := by - unfold aw2 attesterMultiRevokeInnerArrayCopyFreeAw - rw [ulit_toNat' _ hM2] - exact le_trans haw1Ge - (attesterMachineStateM_ge aw1.toNat 64 32) - have haw2Mul : aw2.toNat * 32 < UInt256.size := by - unfold aw2 attesterMultiRevokeInnerArrayCopyFreeAw - rw [ulit_toNat' _ hM2] - exact hM2Mul - have hM3 : MachineState.M aw2.toNat free.toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw2.toNat) (f := free.toNat) - haw2Mul (by simpa [free] using hfree63) - have hM3Mul : MachineState.M aw2.toNat free.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw2.toNat) (f := free.toNat) - haw2Mul (by simpa [free] using hfree63) - have haw3Ge : 3 ≤ aw3.toNat := by - unfold aw3 attesterMultiRevokeInnerArrayCopyUidAw - rw [ulit_toNat' _ hM3] - exact le_trans haw2Ge - (attesterMachineStateM_ge - (attesterMultiRevokeInnerArrayCopyFreeAw mem aw).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat 32) - have haw3Mul : aw3.toNat * 32 < UInt256.size := by - unfold aw3 attesterMultiRevokeInnerArrayCopyUidAw - rw [ulit_toNat' _ hM3] - exact hM3Mul - have hM4 : MachineState.M aw3.toNat zero.toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw3.toNat) (f := zero.toNat) - haw3Mul (by simpa [zero] using hzero63) - have hM4Mul : MachineState.M aw3.toNat zero.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw3.toNat) (f := zero.toNat) - haw3Mul (by simpa [zero] using hzero63) - have haw4Ge : 3 ≤ aw4.toNat := by - unfold aw4 attesterMultiRevokeInnerArrayCopyZeroAw - rw [ulit_toNat' _ hM4] - exact le_trans haw3Ge - (attesterMachineStateM_ge - (attesterMultiRevokeInnerArrayCopyUidAw idx mem aw).toNat - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat 32) - have haw4Mul : aw4.toNat * 32 < UInt256.size := by - unfold aw4 attesterMultiRevokeInnerArrayCopyZeroAw - rw [ulit_toNat' _ hM4] - exact hM4Mul - have hM5 : MachineState.M aw4.toNat base.toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw4.toNat) (f := base.toNat) - haw4Mul hbase63 - have hM5Mul : MachineState.M aw4.toNat base.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw4.toNat) (f := base.toNat) - haw4Mul hbase63 - have haw5Ge : 3 ≤ aw5.toNat := by - unfold aw5 attesterMloadAw - rw [ulit_toNat' _ hM5] - exact le_trans haw4Ge - (attesterMachineStateM_ge aw4.toNat base.toNat 32) - have haw5Mul : aw5.toNat * 32 < UInt256.size := by - unfold aw5 attesterMloadAw - rw [ulit_toNat' _ hM5] - exact hM5Mul - have hM6 : MachineState.M aw5.toNat slot.toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw5.toNat) (f := slot.toNat) - haw5Mul (by simpa [slot] using hslot63) - have hM6Mul : MachineState.M aw5.toNat slot.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw5.toNat) (f := slot.toNat) - haw5Mul (by simpa [slot] using hslot63) - constructor - · unfold attesterMultiRevokeInnerArrayCopyStepAw - rw [ulit_toNat' _ hM6] - exact le_trans haw5Ge - (attesterMachineStateM_ge - (attesterMloadAw - (attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw) base).toNat - (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat 32) - · unfold attesterMultiRevokeInnerArrayCopyStepAw - rw [ulit_toNat' _ hM6] - exact hM6Mul - -theorem attesterMultiRevokeInnerArrayCopyStep_freeWord_toNat - {I : ExecutionEnv} {base payload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hfree : 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) - (hslot : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopySlotWord base idx).toNat) - (hawMul : - (attesterMultiRevokeInnerArrayCopyStepAw I base payload idx mem aw).toNat * 32 < - UInt256.size) - (hawGe : - 3 ≤ (attesterMultiRevokeInnerArrayCopyStepAw I base payload idx mem aw).toNat) - (hfreeBound : - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + 64 < UInt256.size) : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload idx mem aw)).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + 64 := by - rw [attesterMultiRevokeInnerArrayCopyStep_mload64 - (I := I) (base := base) (payload := payload) (idx := idx) - (mem := mem) (aw := aw) - hfree hzero hslot - (attesterMload64ActiveWordsGe3 hawMul hawGe)] - exact attester_uadd_lit64_toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw) hfreeBound - -theorem attesterMultiRevokeInnerArrayCopyZeroAw_covers_base - {I : ExecutionEnv} {base payload idx : UInt256} - {mem : ByteArray} {aw : UInt256} - (hawGe : 3 ≤ aw.toNat) - (hawMul : aw.toNat * 32 < UInt256.size) - (hfree63 : (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + 63 < - UInt256.size) - (hzero63 : (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat + 63 < - UInt256.size) - (hzeroGe : base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) : - ¬ base ≥ - attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw * - (⟨32⟩ : UInt256) := by - let aw1 := attesterMultiRevokeInnerArrayCopyAwAfterMload aw - let aw2 := attesterMultiRevokeInnerArrayCopyFreeAw mem aw - let aw3 := attesterMultiRevokeInnerArrayCopyUidAw idx mem aw - let aw4 := attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw - let free := attesterMultiRevokeInnerArrayCopyFreeWord mem aw - let zero := attesterMultiRevokeInnerArrayCopyZeroWord mem aw - have h64_63 : (⟨64⟩ : UInt256).toNat + 63 < UInt256.size := by decide - have hM1 : MachineState.M aw.toNat (⟨64⟩ : UInt256).toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw.toNat) (f := (⟨64⟩ : UInt256).toNat) - hawMul h64_63 - have hM1Mul : - MachineState.M aw.toNat (⟨64⟩ : UInt256).toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw.toNat) - (f := (⟨64⟩ : UInt256).toNat) hawMul h64_63 - have haw1Ge : 3 ≤ aw1.toNat := by - unfold aw1 attesterMultiRevokeInnerArrayCopyAwAfterMload attesterMloadAw - rw [ulit_toNat' _ hM1] - exact le_trans hawGe - (attesterMachineStateM_ge aw.toNat (⟨64⟩ : UInt256).toNat 32) - have haw1Mul : aw1.toNat * 32 < UInt256.size := by - unfold aw1 attesterMultiRevokeInnerArrayCopyAwAfterMload attesterMloadAw - rw [ulit_toNat' _ hM1] - exact hM1Mul - have hM2 : MachineState.M aw1.toNat 64 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw1.toNat) (f := 64) - haw1Mul (by norm_num [UInt256.size]) - have hM2Mul : MachineState.M aw1.toNat 64 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw1.toNat) (f := 64) - haw1Mul (by norm_num [UInt256.size]) - have haw2Ge : 3 ≤ aw2.toNat := by - unfold aw2 attesterMultiRevokeInnerArrayCopyFreeAw - rw [ulit_toNat' _ hM2] - exact le_trans haw1Ge - (attesterMachineStateM_ge aw1.toNat 64 32) - have haw2Mul : aw2.toNat * 32 < UInt256.size := by - unfold aw2 attesterMultiRevokeInnerArrayCopyFreeAw - rw [ulit_toNat' _ hM2] - exact hM2Mul - have hM3 : MachineState.M aw2.toNat free.toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw2.toNat) (f := free.toNat) - haw2Mul (by simpa [free] using hfree63) - have hM3Mul : MachineState.M aw2.toNat free.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw2.toNat) (f := free.toNat) - haw2Mul (by simpa [free] using hfree63) - have haw3Ge : 3 ≤ aw3.toNat := by - unfold aw3 attesterMultiRevokeInnerArrayCopyUidAw - rw [ulit_toNat' _ hM3] - exact le_trans haw2Ge - (attesterMachineStateM_ge - (attesterMultiRevokeInnerArrayCopyFreeAw mem aw).toNat - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat 32) - have haw3Mul : aw3.toNat * 32 < UInt256.size := by - unfold aw3 attesterMultiRevokeInnerArrayCopyUidAw - rw [ulit_toNat' _ hM3] - exact hM3Mul - have hM4 : MachineState.M aw3.toNat zero.toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := aw3.toNat) (f := zero.toNat) - haw3Mul (by simpa [zero] using hzero63) - have hM4Mul : MachineState.M aw3.toNat zero.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := aw3.toNat) (f := zero.toNat) - haw3Mul (by simpa [zero] using hzero63) - apply attesterMloadActiveWordsCovers - · unfold attesterMultiRevokeInnerArrayCopyZeroAw - rw [ulit_toNat' _ hM4] - exact hM4Mul - · unfold attesterMultiRevokeInnerArrayCopyZeroAw - rw [ulit_toNat' _ hM4] - have hcover := attesterMachineStateM_covers_word32 aw3.toNat zero.toNat - have hcovered : base.toNat + 32 ≤ 32 * MachineState.M aw3.toNat zero.toNat 32 := - le_trans hzeroGe (le_trans (Nat.le_add_right zero.toNat 32) hcover) - simpa [Nat.mul_comm] using hcovered - -theorem attesterMultiRevokeInnerArrayCopyZero_mloadLen_of_bounds_nat - {I : ExecutionEnv} {base payload idx len : UInt256} - {mem : ByteArray} {aw : UInt256} - (hmem : base.toNat + 32 ≤ mem.size) - (hread : mem.readWithPadding base.toNat 32 = UInt256.toByteArray len) - (hawGe : 3 ≤ aw.toNat) - (hawMul : aw.toNat * 32 < UInt256.size) - (hfree96 : - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + 96 < - UInt256.size) - (h64 : 64 + 32 ≤ base.toNat) - (hfree : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat) - (hzero : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat) : - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload idx mem aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload idx mem aw) - base = len := by - have hfree63 : - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + 63 < - UInt256.size := by - omega - have hfree32 : - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + 32 < - UInt256.size := by - omega - have hzeroToNat : - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord mem aw).toNat + 32 := - attesterMultiRevokeInnerArrayCopyZeroWord_toNat hfree32 - have hzero63 : - (attesterMultiRevokeInnerArrayCopyZeroWord mem aw).toNat + 63 < - UInt256.size := by - rw [hzeroToNat] - omega - exact attesterMultiRevokeInnerArrayCopyZero_mloadLen_nat - (I := I) (base := base) (payload := payload) (idx := idx) - (len := len) (mem := mem) (aw := aw) - hmem hread - (attesterMultiRevokeInnerArrayCopyZeroAw_covers_base - (I := I) (base := base) (payload := payload) (idx := idx) - (mem := mem) (aw := aw) - hawGe hawMul hfree63 hzero63 hzero) - h64 hfree hzero - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/MultiRevokePostCall.lean b/Benchmarks/EAS/Attester/MultiRevokePostCall.lean deleted file mode 100644 index 7783d10d..00000000 --- a/Benchmarks/EAS/Attester/MultiRevokePostCall.lean +++ /dev/null @@ -1,569 +0,0 @@ -import Benchmarks.EAS.Attester.MultiRevokeEVM -import Reasoning.ExternalCall - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -def attesterMultiRevokeEasWord (v : AttesterImmutables) : UInt256 := - EVM.Word.ofNat v.eas.toNat - -def attesterMultiRevokeTargetWord (v : AttesterImmutables) : UInt256 := - UInt256.land (attesterMultiRevokeEasWord v) solcAddrMask - -theorem attesterMultiRevokeEasWord_canonical (v : AttesterImmutables) : - (attesterMultiRevokeEasWord v).toNat < EVM.addressModulus := by - change (UInt256.ofNat v.eas.val).toNat < EVM.addressModulus - rw [UInt256.toNat_ofNat_of_lt] - · change v.eas.val < AccountAddress.size - exact v.eas.isLt - · exact lt_of_lt_of_le v.eas.isLt (by decide) - -theorem attesterMultiRevokeEasWord_clean (v : AttesterImmutables) : - UInt256.land solcAddrMask (attesterMultiRevokeEasWord v) = - attesterMultiRevokeEasWord v := - solcAddrMask_clean_left (attesterMultiRevokeEasWord_canonical v) - -theorem attesterMultiRevokeTargetWord_eq_easWord (v : AttesterImmutables) : - attesterMultiRevokeTargetWord v = attesterMultiRevokeEasWord v := by - unfold attesterMultiRevokeTargetWord - exact solcAddrMask_clean (attesterMultiRevokeEasWord_canonical v) - -theorem attesterMultiRevokeTarget_eq (v : AttesterImmutables) : - EVM.address v.eas = AccountAddress.ofUInt256 (attesterMultiRevokeTargetWord v) := by - rw [attesterMultiRevokeTargetWord_eq_easWord] - have hleft : EVM.address (v.eas : Nat) = v.eas := by - apply Fin.ext - simp [EVM.address, EVM.uintN] - exact Nat.mod_eq_of_lt v.eas.isLt - have hright : AccountAddress.ofUInt256 (attesterMultiRevokeEasWord v) = v.eas := by - change AccountAddress.ofUInt256 (UInt256.ofNat v.eas.val) = v.eas - exact accountAddress_roundtrip v.eas - rw [hleft, hright] - -def attesterMultiRevokeSelectorLow : UInt256 := - ⟨0x4cb7e9e5⟩ - -def attesterMultiRevokeSelectorWord : UInt256 := - UInt256.shiftLeft attesterMultiRevokeSelectorLow ⟨224⟩ - -abbrev attesterMultiRevokeCallFree (mem : ByteArray) (aw : UInt256) : UInt256 := - attesterMloadWord mem aw ⟨64⟩ - -abbrev attesterMultiRevokeCallAwAfterMload (aw : UInt256) : UInt256 := - attesterMloadAw aw ⟨64⟩ - -abbrev attesterMultiRevokeCallMemAfterSelector (mem : ByteArray) (aw : UInt256) : - ByteArray := - attesterMultiRevokeSelectorWord.toByteArray.write 0 mem - (attesterMultiRevokeCallFree mem aw).toNat 32 - -abbrev attesterMultiRevokeCallAwAfterSelector (mem : ByteArray) (aw : UInt256) : - UInt256 := - UInt256.ofNat (MachineState.M (attesterMultiRevokeCallAwAfterMload aw).toNat - (attesterMultiRevokeCallFree mem aw).toNat 32) - -theorem attesterX_multiRevokeLoopExitToEncoder - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {idx outerBase schemaLen secondLen secondPayload schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨698⟩ : UInt256) - [idx, outerBase, schemaLen, secondLen, secondPayload, schemaLen, schemaPayload, - ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2422⟩ : UInt256) - [⟨4⟩ + attesterMultiRevokeCallFree mem aw, outerBase, ⟨775⟩, - attesterMultiRevokeSelectorLow, attesterMultiRevokeTargetWord v, - outerBase, schemaLen, secondLen, secondPayload, schemaLen, schemaPayload, - ret, selector] - (attesterMultiRevokeCallMemAfterSelector mem aw) - (attesterMultiRevokeCallAwAfterSelector mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterMultiRevokeCallFree mem aw - let aw1 := attesterMultiRevokeCallAwAfterMload aw - let mem1 := attesterMultiRevokeCallMemAfterSelector mem aw - let aw2 := attesterMultiRevokeCallAwAfterSelector mem aw - have hcostMload64 : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - (⟨64⟩ : UInt256) :: outerBase :: schemaLen :: secondLen :: - secondPayload :: schemaLen :: schemaPayload :: ret :: selector :: [] → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostMstoreSelector : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - free :: attesterMultiRevokeSelectorWord :: free :: outerBase :: schemaLen :: - secondLen :: secondPayload :: schemaLen :: schemaPayload :: ret :: - selector :: [] → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have rd721 := evm_run rd with [ - raw jumpdest (by attester_decode_at v, ⟨698⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨699⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨700⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨702⟩, 0x51, .MLOAD) - hcostMload64 (by rfl) (by rfl) (by evm_ov), - raw push4 attesterMultiRevokeSelectorLow - (by attester_decode_at v, ⟨703⟩, 0x63, (.Push .PUSH4)) (by evm_ov), - raw push1 ⟨224⟩ - (by attester_decode_at v, ⟨708⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨710⟩, 0x1b, .SHL) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨711⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨712⟩, 0x52, .MSTORE) - hcostMstoreSelector (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨713⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨715⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw push1 ⟨160⟩ - (by attester_decode_at v, ⟨717⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨719⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨720⟩, 0x03, .SUB) (by evm_ov)] - have rd754 := rd721.pushConst (attesterMultiRevokeEasWord v) - (width := 32) (op := .PUSH32) (by decide) (attesterDecodeEasWord721 v) - (by evm_ov) - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, attesterMultiRevokeCallFree, - attesterMultiRevokeCallAwAfterMload, attesterMultiRevokeCallMemAfterSelector, - attesterMultiRevokeCallAwAfterSelector, attesterMultiRevokeSelectorLow, - attesterMultiRevokeSelectorWord, attesterMultiRevokeTargetWord] using - evm_run rd754 with [ - raw and (by attester_decode_at v, ⟨754⟩, 0x16, .AND) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨755⟩, 0x90, .SWAP1) (by evm_ov), - raw push4 attesterMultiRevokeSelectorLow - (by attester_decode_at v, ⟨756⟩, 0x63, (.Push .PUSH4)) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨761⟩, 0x90, .SWAP1) (by evm_ov), - raw push2 ⟨775⟩ - (by attester_decode_at v, ⟨762⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨765⟩, 0x90, .SWAP1) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨766⟩, 0x84, .DUP5) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨767⟩, 0x90, .SWAP1) (by evm_ov), - raw push1 ⟨4⟩ (by attester_decode_at v, ⟨768⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw add (by attester_decode_at v, ⟨770⟩, 0x01, .ADD) (by evm_ov), - raw push2 ⟨2422⟩ - (by attester_decode_at v, ⟨771⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨774⟩, 0x56, .JUMP) - (attesterMultiRevokeEncodeRequestsJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeEncoderReturnToExtcodesize - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {endPtr selectorLow target outerBase schemaLen secondLen secondPayload - schemaPayload ret selector : UInt256} - {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨775⟩ : UInt256) - [endPtr, selectorLow, target, outerBase, schemaLen, secondLen, secondPayload, - schemaLen, schemaPayload, ret, selector] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨787⟩ : UInt256) - [target, target, ⟨0⟩, attesterMultiRevokeCallFree mem aw, - UInt256.sub endPtr (attesterMultiRevokeCallFree mem aw), - attesterMultiRevokeCallFree mem aw, ⟨0⟩, endPtr, selectorLow, target, - outerBase, schemaLen, secondLen, secondPayload, schemaLen, schemaPayload, - ret, selector] - mem (attesterMultiRevokeCallAwAfterMload aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterMultiRevokeCallFree mem aw - let aw1 := attesterMultiRevokeCallAwAfterMload aw - have hcostMload64 : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - (⟨64⟩ : UInt256) :: ⟨0⟩ :: endPtr :: selectorLow :: target :: - outerBase :: schemaLen :: secondLen :: secondPayload :: schemaLen :: - schemaPayload :: ret :: selector :: [] → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - exact ⟨_, _, by - simpa [free, aw1, attesterMultiRevokeCallFree, - attesterMultiRevokeCallAwAfterMload] using - evm_run rd with [ - raw jumpdest (by attester_decode_at v, ⟨775⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨776⟩, 0x5f, .PUSH0) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨777⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨779⟩, 0x51, .MLOAD) - hcostMload64 (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨780⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨781⟩, 0x83, .DUP4) (by evm_ov), - raw sub (by attester_decode_at v, ⟨782⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨783⟩, 0x81, .DUP2) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨784⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup8 (by attester_decode_at v, ⟨785⟩, 0x87, .DUP8) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨786⟩, 0x80, .DUP1) (by evm_ov)]⟩ - -private theorem attesterMultiRevoke_extCodeSizeWord_ne_zero_lookup_code_pos - {σ : AccountMap} {target : UInt256} {addr : AccountAddress} - (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : - 0 < (UInt256.ofNat - ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by - subst addr - unfold Reasoning.Theory.extCodeSizeWord at hne - cases hacc : σ.find? (AccountAddress.ofUInt256 target) with - | none => - exfalso - exact hne (by simp [hacc, Option.option]) - | some acc => - have hwordNe : UInt256.ofNat acc.code.size ≠ (⟨0⟩ : UInt256) := by - intro hzero - exact hne (by simpa [hacc] using hzero) - have htoNatNe : (UInt256.ofNat acc.code.size).toNat ≠ 0 := by - intro hzeroNat - apply hwordNe - cases hword : UInt256.ofNat acc.code.size with - | mk val => - cases val using Fin.cases - · rfl - · simp [UInt256.toNat, hword] at hzeroNat - simpa [hacc] using Nat.pos_of_ne_zero htoNatNe - -private theorem attesterMultiRevoke_extCodeSizeWord_zero_lookup_code_zero - {σ : AccountMap} {target : UInt256} {addr : AccountAddress} - (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : - (UInt256.ofNat - ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by - subst addr - unfold Reasoning.Theory.extCodeSizeWord at hzero - cases hacc : σ.find? (AccountAddress.ofUInt256 target) with - | none => - simpa [hacc, Option.option] using - (show (UInt256.ofNat 0).toNat = 0 from by native_decide) - | some acc => - have hword := congrArg UInt256.toNat hzero - simpa [hacc] using hword - -theorem attesterMultiRevokeEvalExtCodeGuard_true (v : AttesterImmutables) - {evm : EVM.State} {locals : Store} {receiver : Expr} {target : AccountAddress} - (hreceiver : - evalExpr? (config v) { contract := contract v, locals := locals } evm receiver = - .ok (.address target)) - (hcode : - 0 < (UInt256.ofNat - ((evm.lookupAccount target).option 0 (fun acc => acc.code.size))).toNat) : - evalExpr? (config v) { contract := contract v, locals := locals } evm - (.binary .gt (.extCodeSize receiver) (.intLit 0)) = .ok (.bool true) := by - simp [evalExpr?, EvalResult.bind, bind, hreceiver, evalBinaryOp?, EVM.Word.ofNat, hcode] - -theorem attesterMultiRevokeEvalExtCodeGuard_false (v : AttesterImmutables) - {evm : EVM.State} {locals : Store} {receiver : Expr} {target : AccountAddress} - (hreceiver : - evalExpr? (config v) { contract := contract v, locals := locals } evm receiver = - .ok (.address target)) - (hcode : - (UInt256.ofNat - ((evm.lookupAccount target).option 0 (fun acc => acc.code.size))).toNat = 0) : - evalExpr? (config v) { contract := contract v, locals := locals } evm - (.binary .gt (.extCodeSize receiver) (.intLit 0)) = .ok (.bool false) := by - simp [evalExpr?, EvalResult.bind, bind, hreceiver, evalBinaryOp?, EVM.Word.ofNat, hcode] - -theorem attesterMultiRevokeCodeSize_ne_accountMapEquiv (v : AttesterImmutables) - {σ τ : AccountMap} - (hAccounts : accountMapEquiv σ τ) - (hne : - Reasoning.Theory.extCodeSizeWord σ (attesterMultiRevokeTargetWord v) ≠ - ⟨0⟩) : - Reasoning.Theory.extCodeSizeWord τ (attesterMultiRevokeTargetWord v) ≠ - ⟨0⟩ := by - intro hzero - apply hne - have hsame := - Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts - (attesterMultiRevokeTargetWord v) - rw [hsame] - exact hzero - -theorem attesterMultiRevokeCodeSize_zero_accountMapEquiv (v : AttesterImmutables) - {σ τ : AccountMap} - (hAccounts : accountMapEquiv σ τ) - (hzero : - Reasoning.Theory.extCodeSizeWord σ (attesterMultiRevokeTargetWord v) = - ⟨0⟩) : - Reasoning.Theory.extCodeSizeWord τ (attesterMultiRevokeTargetWord v) = - ⟨0⟩ := by - have hsame := - Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts - (attesterMultiRevokeTargetWord v) - rw [← hsame] - exact hzero - -theorem attesterMultiRevokeEasCode_pos_of_codeSize_ne - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hne : - Reasoning.Theory.extCodeSizeWord σ (attesterMultiRevokeTargetWord v) ≠ - ⟨0⟩) : - 0 < (UInt256.ofNat - (((initState cA gh bl σ σ₀ g A I).lookupAccount (EVM.address v.eas)).option 0 - (fun acc => acc.code.size))).toNat := by - simpa [initState, State.lookupAccount] using - attesterMultiRevoke_extCodeSizeWord_ne_zero_lookup_code_pos - (σ := σ) (target := attesterMultiRevokeTargetWord v) (addr := EVM.address v.eas) - (attesterMultiRevokeTarget_eq v) hne - -theorem attesterMultiRevokeEasCode_zero_of_codeSize_zero - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hzero : - Reasoning.Theory.extCodeSizeWord σ (attesterMultiRevokeTargetWord v) = - ⟨0⟩) : - (UInt256.ofNat - (((initState cA gh bl σ σ₀ g A I).lookupAccount (EVM.address v.eas)).option 0 - (fun acc => acc.code.size))).toNat = 0 := by - simpa [initState, State.lookupAccount] using - attesterMultiRevoke_extCodeSizeWord_zero_lookup_code_zero - (σ := σ) (target := attesterMultiRevokeTargetWord v) (addr := EVM.address v.eas) - (attesterMultiRevokeTarget_eq v) hzero - -theorem attesterX_multiRevokeCallAtExtcodesize {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {mem : ByteArray} {aw target inOff inSize outOff outSize : UInt256} - {rest : List UInt256} {args : List Value} {k C : ℕ} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨787⟩ : UInt256) - (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: outSize :: rest) - mem aw ByteArray.empty (cA, σ) k C) - (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) - (htgt : EVM.address v.eas = AccountAddress.ofUInt256 target) - (hcd : (config v).externalABI.encode? "multiRevoke" args = - some (mem.readWithPadding inOff.toNat inSize.toNat)) - (hperm : I.perm = true) (hdepth : I.depth.val < 1024) - (hov : rest.length + 9 ≤ 1024) : - ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) - (o : ByteArray) (A' : Substate) (k' C' : ℕ), - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨802⟩ : UInt256) - ((if z then ⟨1⟩ else ⟨0⟩) :: rest) - (o.write 0 mem outOff.toNat (min outSize (UInt256.ofNat o.size)).toNat) - (UInt256.ofNat (MachineState.M (MachineState.M aw.toNat inOff.toNat inSize.toNat) - outOff.toNat outSize.toNat)) - o (cA', σ') k' C' - ∧ typedCallViaEVM (config v) (initState cA gh bl σ σ₀ g A I) - (EVM.address v.eas) "multiRevoke" 0 args - (z, { initState cA gh bl σ σ₀ g A I with - accountMap := σ', substate := A', createdAccounts := cA' }, o) true - ∧ o.size < UInt256.size := by - obtain ⟨_, _, _, rd801⟩ := - RD.solcExtcodesizeGuardOkGas (pc := ⟨787⟩) (okPc := ⟨798⟩) - rd hcodeSize - (by attester_decode_at v, ⟨787⟩, 0x3b, .EXTCODESIZE) - (by attester_decode_at v, ⟨788⟩, 0x15, .ISZERO) - (by attester_decode_at v, ⟨789⟩, 0x80, .DUP1) - (by attester_decode_at v, ⟨790⟩, 0x15, .ISZERO) - (by attester_decode_at v, ⟨791⟩, 0x61, (.Push .PUSH2)) - (by attester_decode_at v, ⟨794⟩, 0x57, .JUMPI) - (attesterMultiRevokeExtcodesizeOkJumpdest v) - (by attester_decode_at v, ⟨798⟩, 0x5b, .JUMPDEST) - (by attester_decode_at v, ⟨799⟩, 0x50, .POP) - (by attester_decode_at v, ⟨800⟩, 0x5a, .GAS) - (by simp only [List.length_cons]; omega) - obtain ⟨cA', σ', z, o, A_in, callGas, k', C', hTheta, rd802raw, hosz⟩ := - rd801.call (by attester_decode_at v, ⟨801⟩, 0xf1, .CALL) hdepth - (by omega) - obtain ⟨g'', A', hΘ⟩ := hTheta - refine ⟨cA', σ', z, o, A', k', C', ?_, ?_, hosz⟩ - · simpa using rd802raw - · refine callCoincides (A_in := A_in) (g'' := g'') (callGas := callGas) - (callPerm := true) (targetWord := target) - (mem := mem) (inOff := inOff) (inSize := inSize) - (hdepth := fun h => absurd hdepth (by rw [show I.depth = (1024 : Fin 1025) from h]; decide)) - (htgt := htgt) (hcd := hcd) (hΘ := ?_) - simpa [initState, hperm] using hΘ - -theorem attesterX_multiRevokeNoCodeAtExtcodesize {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {mem : ByteArray} {aw target inOff inSize outOff outSize : UInt256} - {rest : List UInt256} {k C : ℕ} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨787⟩ : UInt256) - (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: outSize :: rest) - mem aw ByteArray.empty (cA, σ) k C) - (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) - (hov : rest.length + 9 ≤ 1024) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨k788, C788, rd788raw⟩ := RD.extcodesize rd - (by attester_decode_at v, ⟨787⟩, 0x3b, .EXTCODESIZE) - (by simp only [List.length_cons]; omega) - have rd788 : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨788⟩ : UInt256) - (Reasoning.Theory.extCodeSizeWord σ target :: target :: ⟨0⟩ :: - inOff :: inSize :: outOff :: outSize :: rest) - mem aw ByteArray.empty (cA, σ) k788 C788 := by - simpa using rd788raw - exact evm_run rd788 with [ - raw iszero (by attester_decode_at v, ⟨788⟩, 0x15, .ISZERO) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨789⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨790⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨798⟩ (by attester_decode_at v, ⟨791⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨794⟩, 0x57, .JUMPI) - (by rw [hcodeSize]; decide) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨795⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨796⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨797⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_multiRevokePostRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {k C : ℕ} {rest : List UInt256} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨802⟩ : UInt256) - (⟨0⟩ :: rest) mem aw rdata acc k C) - (hrdataSize : rdata.size < UInt256.size) - (hov : rest.length + 5 ≤ 1024) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have rd809 : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨809⟩ : UInt256) (UInt256.isZero ⟨0⟩ :: rest) mem aw rdata acc _ _ := - evm_run rd with [ - raw iszero (by attester_decode_at v, ⟨802⟩, 0x15, .ISZERO) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨803⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨804⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨816⟩ (by attester_decode_at v, ⟨805⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨808⟩, 0x57, .JUMPI) (by decide) - (by evm_ov)] - have rd810 := RD.returndatasize rd809 - (by attester_decode_at v, ⟨809⟩, 0x3d, .RETURNDATASIZE) - (by simp only [List.length_cons]; omega) - have rd811 := RD.push0 rd810 - (by attester_decode_at v, ⟨810⟩, 0x5f, .PUSH0) - (by simp only [List.length_cons]; omega) - have rd812 := RD.dup1 rd811 - (by attester_decode_at v, ⟨811⟩, 0x80, .DUP1) - (by simp only [List.length_cons]; omega) - have rd813 : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨813⟩ : UInt256) (UInt256.isZero ⟨0⟩ :: rest) - (rdata.write 0 mem 0 (UInt256.ofNat rdata.size).toNat) - (UInt256.ofNat (MachineState.M aw.toNat 0 (UInt256.ofNat rdata.size).toNat)) - rdata acc _ _ := - RD.returndatacopy - (Cₘ (UInt256.ofNat (MachineState.M aw.toNat 0 (UInt256.ofNat rdata.size).toNat)) - Cₘ aw) - (rdata.write 0 mem 0 (UInt256.ofNat rdata.size).toNat) - (UInt256.ofNat (MachineState.M aw.toNat 0 (UInt256.ofNat rdata.size).toNat)) - rd812 - (by attester_decode_at v, ⟨812⟩, 0x3e, .RETURNDATACOPY) - (by - rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, Nat.zero_add] - rw [show (UInt256.ofNat rdata.size).toNat = rdata.size from - ulit_toNat' rdata.size hrdataSize]) - (by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', hstks, haws, - List.getElem!_cons_zero, List.getElem!_cons_succ, - show (⟨0⟩ : UInt256).toNat = 0 from rfl]) - rfl rfl (by simp only [List.length_cons]; omega) - have rd814 := RD.returndatasize rd813 - (by attester_decode_at v, ⟨813⟩, 0x3d, .RETURNDATASIZE) - (by simp only [List.length_cons]; omega) - have rd815 := RD.push0 rd814 - (by attester_decode_at v, ⟨814⟩, 0x5f, .PUSH0) - (by simp only [List.length_cons]; omega) - exact RD.rev _ rd815 - (by attester_decode_at v, ⟨815⟩, 0xfd, .REVERT) - (fun s haws hstks => by rw [memExpRevertZeroOff s hstks, haws]) - (by simp only [List.length_cons]; omega) - -theorem attesterX_multiRevokeCallDepthLimitAtExtcodesize - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {mem : ByteArray} {aw target inOff inSize outOff outSize : UInt256} - {rest : List UInt256} {k C : ℕ} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨787⟩ : UInt256) - (target :: target :: ⟨0⟩ :: inOff :: inSize :: outOff :: outSize :: rest) - mem aw ByteArray.empty (cA, σ) k C) - (hcodeSize : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) - (hdepth : I.depth = 1024) - (hov : rest.length + 9 ≤ 1024) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, _, rd801⟩ := - RD.solcExtcodesizeGuardOkGas (pc := ⟨787⟩) (okPc := ⟨798⟩) - rd hcodeSize - (by attester_decode_at v, ⟨787⟩, 0x3b, .EXTCODESIZE) - (by attester_decode_at v, ⟨788⟩, 0x15, .ISZERO) - (by attester_decode_at v, ⟨789⟩, 0x80, .DUP1) - (by attester_decode_at v, ⟨790⟩, 0x15, .ISZERO) - (by attester_decode_at v, ⟨791⟩, 0x61, (.Push .PUSH2)) - (by attester_decode_at v, ⟨794⟩, 0x57, .JUMPI) - (attesterMultiRevokeExtcodesizeOkJumpdest v) - (by attester_decode_at v, ⟨798⟩, 0x5b, .JUMPDEST) - (by attester_decode_at v, ⟨799⟩, 0x50, .POP) - (by attester_decode_at v, ⟨800⟩, 0x5a, .GAS) - (by simp only [List.length_cons]; omega) - obtain ⟨k802, C802, rd802raw⟩ := - rd801.callDepthLimit (by attester_decode_at v, ⟨801⟩, 0xf1, .CALL) - hdepth (by omega) - have rd802 : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨802⟩ : UInt256) - (⟨0⟩ :: rest) - (ByteArray.empty.write 0 mem outOff.toNat - (min outSize (UInt256.ofNat ByteArray.empty.size)).toNat) - (UInt256.ofNat - (MachineState.M (MachineState.M aw.toNat inOff.toNat inSize.toNat) - outOff.toNat outSize.toNat)) - ByteArray.empty (cA, σ) k802 C802 := by - simpa using rd802raw - exact attesterX_multiRevokePostRevert (v := v) rd802 (by native_decide) (by omega) - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeSuccessStop {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem o : ByteArray} {aw : UInt256} {k C : ℕ} - {r0 r1 r2 r3 r4 r5 r6 r7 r8 selector : UInt256} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨802⟩ : UInt256) - [⟨1⟩, r0, r1, r2, r3, r4, r5, r6, r7, r8, ⟨97⟩, selector] - mem aw o acc k C) : - RDret (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) acc ByteArray.empty := by - obtain ⟨_, _, rd818⟩ := - RD.solcCallSuccessGuardOk (pc := ⟨802⟩) (okPc := ⟨816⟩) rd - (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) - (by attester_decode_at v, ⟨802⟩, 0x15, .ISZERO) - (by attester_decode_at v, ⟨803⟩, 0x80, .DUP1) - (by attester_decode_at v, ⟨804⟩, 0x15, .ISZERO) - (by attester_decode_at v, ⟨805⟩, 0x61, (.Push .PUSH2)) - (by attester_decode_at v, ⟨808⟩, 0x57, .JUMPI) - (attesterMultiRevokeCallOkJumpdest v) - (by attester_decode_at v, ⟨816⟩, 0x5b, .JUMPDEST) - (by attester_decode_at v, ⟨817⟩, 0x50, .POP) - (by simp) - have rd97 := evm_run rd818 with [ - raw pop (by attester_decode_at v, ⟨818⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨819⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨820⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨821⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨822⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨823⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨824⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨825⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨826⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨827⟩, 0x56, .JUMP) - (by simpa using attesterNoReturnDoneJumpdest v) (by evm_ov)] - have rd98 := evm_run rd97 with [ - raw jumpdest (by attester_decode_at v, ⟨97⟩, 0x5b, .JUMPDEST) (by evm_ov)] - exact RD.stop rd98 (by attester_decode_at v, ⟨98⟩, 0x00, .STOP) (by evm_ov) - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/MultiRevokePostLoop.lean b/Benchmarks/EAS/Attester/MultiRevokePostLoop.lean deleted file mode 100644 index 5e14439d..00000000 --- a/Benchmarks/EAS/Attester/MultiRevokePostLoop.lean +++ /dev/null @@ -1,1695 +0,0 @@ -import Benchmarks.EAS.Attester.MultiRevokeLoopRun -import Benchmarks.EAS.Attester.MultiRevokePostCall - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -abbrev attesterMultiRevokeEncoderOffsetMem - (mem : ByteArray) (dst : UInt256) : ByteArray := - (UInt256.toByteArray (⟨32⟩ : UInt256)).write 0 mem dst.toNat 32 - -abbrev attesterMultiRevokeEncoderAwAfterOffset - (aw dst : UInt256) : UInt256 := - UInt256.ofNat (MachineState.M aw.toNat dst.toNat 32) - -abbrev attesterMultiRevokeEncoderLengthMem - (mem : ByteArray) (dst len : UInt256) : ByteArray := - (UInt256.toByteArray len).write 0 - (attesterMultiRevokeEncoderOffsetMem mem dst) (dst + ⟨32⟩).toNat 32 - -abbrev attesterMultiRevokeEncoderAwAfterLoad - (aw dst src : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiRevokeEncoderAwAfterOffset aw dst).toNat - src.toNat 32) - -abbrev attesterMultiRevokeEncoderAwAfterLength - (aw dst src : UInt256) : UInt256 := - UInt256.ofNat - (MachineState.M (attesterMultiRevokeEncoderAwAfterLoad aw dst src).toNat - (dst + ⟨32⟩).toNat 32) - -abbrev attesterMultiRevokeEncoderOuterOffsetWord - (endPtr dst : UInt256) : UInt256 := - UInt256.lnot (⟨63⟩ : UInt256) + UInt256.sub endPtr dst - -abbrev attesterMultiRevokeEncoderOuterOffsetMem - (mem : ByteArray) (dstHead endPtr dst : UInt256) : ByteArray := - (UInt256.toByteArray - (attesterMultiRevokeEncoderOuterOffsetWord endPtr dst)).write 0 mem - dstHead.toNat 32 - -abbrev attesterMultiRevokeEncoderOuterOffsetAw - (aw dstHead : UInt256) : UInt256 := - UInt256.ofNat (MachineState.M aw.toNat dstHead.toNat 32) - -abbrev attesterMultiRevokeEncoderOuterSrcWord - (mem : ByteArray) (aw srcHead : UInt256) : UInt256 := - attesterMloadWord mem aw srcHead - -abbrev attesterMultiRevokeEncoderOuterSrcAw - (aw srcHead : UInt256) : UInt256 := - attesterMloadAw aw srcHead - -abbrev attesterMultiRevokeEncoderOuterSchemaWord - (mem : ByteArray) (aw srcWord : UInt256) : UInt256 := - attesterMloadWord mem aw srcWord - -abbrev attesterMultiRevokeEncoderOuterSchemaAw - (aw srcWord : UInt256) : UInt256 := - attesterMloadAw aw srcWord - -abbrev attesterMultiRevokeEncoderOuterSchemaMem - (mem : ByteArray) (endPtr schemaWord : UInt256) : ByteArray := - (UInt256.toByteArray schemaWord).write 0 mem endPtr.toNat 32 - -abbrev attesterMultiRevokeEncoderOuterSchemaStoreAw - (aw endPtr : UInt256) : UInt256 := - UInt256.ofNat (MachineState.M aw.toNat endPtr.toNat 32) - -abbrev attesterMultiRevokeEncoderOuterUidsPtrWord - (mem : ByteArray) (aw srcWord : UInt256) : UInt256 := - attesterMloadWord mem aw ((⟨32⟩ : UInt256) + srcWord) - -abbrev attesterMultiRevokeEncoderOuterUidsPtrAw - (aw srcWord : UInt256) : UInt256 := - attesterMloadAw aw ((⟨32⟩ : UInt256) + srcWord) - -abbrev attesterMultiRevokeEncoderOuterUidsOffsetMem - (mem : ByteArray) (endPtr : UInt256) : ByteArray := - (UInt256.toByteArray (⟨64⟩ : UInt256)).write 0 mem (endPtr + ⟨32⟩).toNat 32 - -abbrev attesterMultiRevokeEncoderOuterUidsOffsetAw - (aw endPtr : UInt256) : UInt256 := - UInt256.ofNat (MachineState.M aw.toNat (endPtr + ⟨32⟩).toNat 32) - -abbrev attesterMultiRevokeEncoderOuterUidsLenWord - (mem : ByteArray) (aw uidsPtr : UInt256) : UInt256 := - attesterMloadWord mem aw uidsPtr - -abbrev attesterMultiRevokeEncoderOuterUidsLenAw - (aw uidsPtr : UInt256) : UInt256 := - attesterMloadAw aw uidsPtr - -abbrev attesterMultiRevokeEncoderOuterUidsLenMem - (mem : ByteArray) (endPtr uidsLen : UInt256) : ByteArray := - (UInt256.toByteArray uidsLen).write 0 mem (endPtr + ⟨64⟩).toNat 32 - -abbrev attesterMultiRevokeEncoderOuterUidsLenStoreAw - (aw endPtr : UInt256) : UInt256 := - UInt256.ofNat (MachineState.M aw.toNat (endPtr + ⟨64⟩).toNat 32) - -abbrev attesterMultiRevokeEncoderInnerFirstWord - (mem : ByteArray) (aw uidPayload : UInt256) : UInt256 := - attesterMloadWord mem aw uidPayload - -abbrev attesterMultiRevokeEncoderInnerFirstAw - (aw uidPayload : UInt256) : UInt256 := - attesterMloadAw aw uidPayload - -abbrev attesterMultiRevokeEncoderInnerValueWord - (mem : ByteArray) (aw firstWord : UInt256) : UInt256 := - attesterMloadWord mem aw firstWord - -abbrev attesterMultiRevokeEncoderInnerValueAw - (aw firstWord : UInt256) : UInt256 := - attesterMloadAw aw firstWord - -abbrev attesterMultiRevokeEncoderInnerValueMem - (mem : ByteArray) (dstData valueWord : UInt256) : ByteArray := - (UInt256.toByteArray valueWord).write 0 mem dstData.toNat 32 - -abbrev attesterMultiRevokeEncoderInnerValueStoreAw - (aw dstData : UInt256) : UInt256 := - UInt256.ofNat (MachineState.M aw.toNat dstData.toNat 32) - -abbrev attesterMultiRevokeEncoderInnerExtraWord - (mem : ByteArray) (aw firstWord : UInt256) : UInt256 := - attesterMloadWord mem aw ((⟨32⟩ : UInt256) + firstWord) - -abbrev attesterMultiRevokeEncoderInnerExtraAw - (aw firstWord : UInt256) : UInt256 := - attesterMloadAw aw ((⟨32⟩ : UInt256) + firstWord) - -abbrev attesterMultiRevokeEncoderInnerExtraMem - (mem : ByteArray) (dstData extraWord : UInt256) : ByteArray := - (UInt256.toByteArray extraWord).write 0 mem (dstData + ⟨32⟩).toNat 32 - -abbrev attesterMultiRevokeEncoderInnerExtraStoreAw - (aw dstData : UInt256) : UInt256 := - UInt256.ofNat (MachineState.M aw.toNat (dstData + ⟨32⟩).toNat 32) - -theorem attesterX_multiRevokeDoneToEncoder - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {schemas schemaUids : List Value} - {a : AttesterMultiRevokeOuterLoopCursor} {L : Store} {evm : EVM.State} - {k C : ℕ} - (hInv : AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids 0 a L evm) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨698⟩ : UInt256) (attesterMultiRevokeOuterLoopStack a) - a.mem a.aw ByteArray.empty a.acc k C) : - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2422⟩ : UInt256) - [⟨4⟩ + attesterMultiRevokeCallFree a.mem a.aw, (⟨128⟩ : UInt256), - ⟨775⟩, attesterMultiRevokeSelectorLow, attesterMultiRevokeTargetWord v, - (⟨128⟩ : UInt256), attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiRevokeCallMemAfterSelector a.mem a.aw) - (attesterMultiRevokeCallAwAfterSelector a.mem a.aw) - ByteArray.empty (cA, σ) k' C' := by - have hshape := - AttesterMultiRevokeOuterLoopInv.done_shape - (cA := cA) (σ := σ) (I := I) - (schemas := schemas) (schemaUids := schemaUids) - (a := a) (L := L) (evm := evm) hInv - rcases hshape with - ⟨_hschemas, _hschemaUids, _hschemaLength, _hrequests, _hi, _hidx, - _hidxToNat, houterBase, hschemaLen, _hschemaLenToNat, hsecondLen, - _hsecondLenToNat, hsecondPayload, hschemaPayload, hret, hselector, hacc, - _hawGe, _hawMul, _houterRead, _houterMemSize, _houter64, _hbaseGe, - _houterBeforeBase, _hfreeLt⟩ - obtain ⟨k', C', rd2422⟩ := - attesterX_multiRevokeLoopExitToEncoder - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (by simpa [attesterMultiRevokeOuterLoopStack, hacc] using rd) - exact ⟨k', C', by - simpa [houterBase, hschemaLen, hsecondLen, hsecondPayload, hschemaPayload, - hret, hselector] using rd2422⟩ - -theorem attesterMultiRevokeEncoderPreambleLoad_fromDone - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - {I : ExecutionEnv} {schemas schemaUids : List Value} - {a : AttesterMultiRevokeOuterLoopCursor} {L : Store} {evm : EVM.State} - (hInv : AttesterMultiRevokeOuterLoopInv cA σ I schemas schemaUids 0 a L evm) : - attesterMloadWord - (attesterMultiRevokeEncoderOffsetMem - (attesterMultiRevokeCallMemAfterSelector a.mem a.aw) - ((⟨4⟩ : UInt256) + attesterMultiRevokeCallFree a.mem a.aw)) - (attesterMultiRevokeEncoderAwAfterOffset - (attesterMultiRevokeCallAwAfterSelector a.mem a.aw) - ((⟨4⟩ : UInt256) + attesterMultiRevokeCallFree a.mem a.aw)) - (⟨128⟩ : UInt256) = - attesterFirstArrayLengthWord I := by - let free := attesterMultiRevokeCallFree a.mem a.aw - let memSel := attesterMultiRevokeCallMemAfterSelector a.mem a.aw - let awLoad := attesterMultiRevokeCallAwAfterMload a.aw - let awSel := attesterMultiRevokeCallAwAfterSelector a.mem a.aw - let dst := (⟨4⟩ : UInt256) + free - let memOff := attesterMultiRevokeEncoderOffsetMem memSel dst - let awOff := attesterMultiRevokeEncoderAwAfterOffset awSel dst - have hshape := - AttesterMultiRevokeOuterLoopInv.done_shape - (cA := cA) (σ := σ) (I := I) - (schemas := schemas) (schemaUids := schemaUids) - (a := a) (L := L) (evm := evm) hInv - rcases hshape with - ⟨_hschemas, _hschemaUids, _hschemaLength, _hrequests, _hi, _hidx, - _hidxToNat, houterBase, hschemaLen, _hschemaLenToNat, _hsecondLen, - _hsecondLenToNat, _hsecondPayload, _hschemaPayload, _hret, _hselector, - _hacc, hawGe, hawMul, houterRead, houterMemSize, _houter64, _hbaseGe, - houterBeforeBase, hfree128⟩ - have hread0 : - a.mem.readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) := by - simpa [houterBase, hschemaLen] using houterRead - have hmem0 : 128 + 32 ≤ a.mem.size := by - simpa [houterBase] using houterMemSize - have hfreeAbove : 128 + 32 ≤ free.toNat := by - dsimp [free, attesterMultiRevokeCallFree] - simpa [houterBase] using houterBeforeBase - have hfree128Call : free.toNat + 128 < UInt256.size := by - simpa [free, attesterMultiRevokeCallFree, attesterInnerArrayAllocFreeWord] - using hfree128 - have hfree63 : free.toNat + 63 < UInt256.size := by - omega - have hfree4 : free.toNat + 4 < UInt256.size := by - omega - have hdstToNat : dst.toNat = free.toNat + 4 := by - dsimp [dst] - rw [uadd_toNat, show (⟨4⟩ : UInt256).toNat = 4 by decide] - rw [show 4 + free.toNat = free.toNat + 4 by omega, Nat.mod_eq_of_lt hfree4] - have hdst63 : dst.toNat + 63 < UInt256.size := by - rw [hdstToNat] - omega - have hreadSel : - memSel.readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) := by - dsimp [memSel, attesterMultiRevokeCallMemAfterSelector, free, - attesterMultiRevokeCallFree] - change - (Reasoning.Theory.writeWord a.mem (attesterMloadWord a.mem a.aw ⟨64⟩).toNat - attesterMultiRevokeSelectorWord).readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (base := 128) (writeOff := (attesterMloadWord a.mem a.aw ⟨64⟩).toNat) - (len := attesterFirstArrayLengthWord I) - hmem0 hfreeAbove hread0 - have hmemSel : 128 + 32 ≤ memSel.size := by - dsimp [memSel, attesterMultiRevokeCallMemAfterSelector, free, - attesterMultiRevokeCallFree] - change - 128 + 32 ≤ - (Reasoning.Theory.writeWord a.mem - (attesterMloadWord a.mem a.aw ⟨64⟩).toNat - attesterMultiRevokeSelectorWord).size - exact le_trans hmem0 - (attesterWriteWord_size_ge_nat a.mem - (attesterMloadWord a.mem a.aw ⟨64⟩).toNat - attesterMultiRevokeSelectorWord) - have hreadOff : - memOff.readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) := by - dsimp [memOff, attesterMultiRevokeEncoderOffsetMem] - change - (Reasoning.Theory.writeWord memSel dst.toNat (⟨32⟩ : UInt256)).readWithPadding - 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) - exact attesterReadWithPadding_writeWord_preserved_above_nat - (base := 128) (writeOff := dst.toNat) - (len := attesterFirstArrayLengthWord I) - hmemSel (by rw [hdstToNat]; omega) hreadSel - have hmemOff : (⟨128⟩ : UInt256).toNat + 32 ≤ memOff.size := by - change 128 + 32 ≤ memOff.size - dsimp [memOff, attesterMultiRevokeEncoderOffsetMem] - change - 128 + 32 ≤ - (Reasoning.Theory.writeWord memSel dst.toNat (⟨32⟩ : UInt256)).size - exact le_trans hmemSel - (attesterWriteWord_size_ge_nat memSel dst.toNat (⟨32⟩ : UInt256)) - have hM64 : MachineState.M a.aw.toNat (⟨64⟩ : UInt256).toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := a.aw.toNat) - (f := (⟨64⟩ : UInt256).toNat) hawMul (by decide) - have hM64Mul : - MachineState.M a.aw.toNat (⟨64⟩ : UInt256).toNat 32 * 32 < - UInt256.size := - attesterMachineStateM32_mul32_lt (s := a.aw.toNat) - (f := (⟨64⟩ : UInt256).toNat) hawMul (by decide) - have hawLoadMul : awLoad.toNat * 32 < UInt256.size := by - dsimp [awLoad, attesterMultiRevokeCallAwAfterMload, attesterMloadAw] - rw [ulit_toNat' _ hM64] - exact hM64Mul - have hMSel : MachineState.M awLoad.toNat free.toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := awLoad.toNat) (f := free.toNat) - hawLoadMul hfree63 - have hMSelMul : - MachineState.M awLoad.toNat free.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := awLoad.toNat) (f := free.toNat) - hawLoadMul hfree63 - have hawSelMul : awSel.toNat * 32 < UInt256.size := by - dsimp [awSel, attesterMultiRevokeCallAwAfterSelector, - attesterMultiRevokeCallFree, awLoad, free] - rw [ulit_toNat' _ hMSel] - exact hMSelMul - have hMOff : MachineState.M awSel.toNat dst.toNat 32 < UInt256.size := - attesterMachineStateM32_lt (s := awSel.toNat) (f := dst.toNat) - hawSelMul hdst63 - have hMOffMul : - MachineState.M awSel.toNat dst.toNat 32 * 32 < UInt256.size := - attesterMachineStateM32_mul32_lt (s := awSel.toNat) (f := dst.toNat) - hawSelMul hdst63 - have hawOffMul : awOff.toNat * 32 < UInt256.size := by - dsimp [awOff, attesterMultiRevokeEncoderAwAfterOffset] - rw [ulit_toNat' _ hMOff] - exact hMOffMul - have hcovered : (⟨128⟩ : UInt256).toNat + 32 ≤ awOff.toNat * 32 := by - dsimp [awOff, attesterMultiRevokeEncoderAwAfterOffset] - rw [ulit_toNat' _ hMOff] - change 128 + 32 ≤ MachineState.M awSel.toNat dst.toNat 32 * 32 - have hdstCover : - dst.toNat + 32 ≤ MachineState.M awSel.toNat dst.toNat 32 * 32 := by - simpa [Nat.mul_comm] using - (attesterMachineStateM_covers_word32 awSel.toNat dst.toNat) - have hdstLower : 128 + 32 ≤ dst.toNat + 32 := by - rw [hdstToNat] - omega - exact le_trans hdstLower hdstCover - have hawOff : - ¬ (⟨128⟩ : UInt256) ≥ awOff * (⟨32⟩ : UInt256) := - attesterMloadActiveWordsCovers hawOffMul hcovered - exact attesterMloadWord_of_readWithPadding hmemOff hawOff (by - change memOff.readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) - exact hreadOff) - -theorem attesterX_multiRevokeEncoderPreambleToOuterLoop - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {dst : UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (hload : - attesterMloadWord - (attesterMultiRevokeEncoderOffsetMem mem dst) - (attesterMultiRevokeEncoderAwAfterOffset aw dst) - (⟨128⟩ : UInt256) = - attesterFirstArrayLengthWord I) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2422⟩ : UInt256) - [dst, (⟨128⟩ : UInt256), ⟨775⟩, attesterMultiRevokeSelectorLow, - attesterMultiRevokeTargetWord v, (⟨128⟩ : UInt256), - attesterFirstArrayLengthWord I, attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) - [(⟨0⟩ : UInt256), (⟨128⟩ : UInt256) + ⟨32⟩, - attesterFirstArrayLengthWord I, dst + ⟨64⟩, - (dst + UInt256.shiftLeft (attesterFirstArrayLengthWord I) ⟨5⟩) + ⟨64⟩, - (⟨0⟩ : UInt256), dst, (⟨128⟩ : UInt256), ⟨775⟩, - attesterMultiRevokeSelectorLow, attesterMultiRevokeTargetWord v, - (⟨128⟩ : UInt256), attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiRevokeEncoderLengthMem mem dst (attesterFirstArrayLengthWord I)) - (attesterMultiRevokeEncoderAwAfterLength aw dst (⟨128⟩ : UInt256)) - ByteArray.empty (cA, σ) k' C' := by - let mem1 := attesterMultiRevokeEncoderOffsetMem mem dst - let aw1 := attesterMultiRevokeEncoderAwAfterOffset aw dst - let len := attesterFirstArrayLengthWord I - let aw2 := attesterMultiRevokeEncoderAwAfterLoad aw dst (⟨128⟩ : UInt256) - let mem2 := attesterMultiRevokeEncoderLengthMem mem dst len - let aw3 := attesterMultiRevokeEncoderAwAfterLength aw dst (⟨128⟩ : UInt256) - have hcostStoreOffset : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - dst :: (⟨32⟩ : UInt256) :: (dst + ⟨32⟩) :: (⟨0⟩ : UInt256) :: - dst :: (⟨128⟩ : UInt256) :: ⟨775⟩ :: - attesterMultiRevokeSelectorLow :: attesterMultiRevokeTargetWord v :: - (⟨128⟩ : UInt256) :: attesterFirstArrayLengthWord I :: - attesterSecondArrayLengthWord I :: attesterSecondArrayPayloadStartWord I :: - attesterFirstArrayLengthWord I :: - ((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩) :: - ⟨97⟩ :: solcSelectorWord I :: [] → - memoryExpansionCost s .MSTORE = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostLoadLen : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - (⟨128⟩ : UInt256) :: (dst + ⟨32⟩) :: (dst + ⟨32⟩) :: - (⟨0⟩ : UInt256) :: dst :: (⟨128⟩ : UInt256) :: ⟨775⟩ :: - attesterMultiRevokeSelectorLow :: attesterMultiRevokeTargetWord v :: - (⟨128⟩ : UInt256) :: attesterFirstArrayLengthWord I :: - attesterSecondArrayLengthWord I :: attesterSecondArrayPayloadStartWord I :: - attesterFirstArrayLengthWord I :: - ((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩) :: - ⟨97⟩ :: solcSelectorWord I :: [] → - memoryExpansionCost s .MLOAD = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreLen : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - (dst + ⟨32⟩) :: len :: len :: (dst + ⟨32⟩) :: - (dst + ⟨32⟩) :: (⟨0⟩ : UInt256) :: dst :: - (⟨128⟩ : UInt256) :: ⟨775⟩ :: attesterMultiRevokeSelectorLow :: - attesterMultiRevokeTargetWord v :: (⟨128⟩ : UInt256) :: - attesterFirstArrayLengthWord I :: attesterSecondArrayLengthWord I :: - attesterSecondArrayPayloadStartWord I :: attesterFirstArrayLengthWord I :: - ((UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩) :: - ⟨97⟩ :: solcSelectorWord I :: [] → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - exact ⟨_, _, by - simpa [mem1, aw1, len, aw2, mem2, aw3, - attesterMultiRevokeEncoderOffsetMem, - attesterMultiRevokeEncoderAwAfterOffset, - attesterMultiRevokeEncoderAwAfterLoad, - attesterMultiRevokeEncoderLengthMem, - attesterMultiRevokeEncoderAwAfterLength] using - evm_run rd with [ - raw jumpdest (by attester_decode_at v, ⟨2422⟩, 0x5b, .JUMPDEST) - (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2423⟩, 0x5f, .PUSH0) - (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2424⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2426⟩, 0x82, .DUP3) - (by evm_ov), - raw add (by attester_decode_at v, ⟨2427⟩, 0x01, .ADD) - (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2428⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2430⟩, 0x83, .DUP4) - (by evm_ov), - raw mstore (Cₘ aw1 - Cₘ aw) mem1 aw1 - (by attester_decode_at v, ⟨2431⟩, 0x52, .MSTORE) - hcostStoreOffset (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2432⟩, 0x80, .DUP1) - (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2433⟩, 0x84, .DUP5) - (by evm_ov), - raw mload (Cₘ aw2 - Cₘ aw1) len aw2 - (by attester_decode_at v, ⟨2434⟩, 0x51, .MLOAD) - hcostLoadLen - (by simpa [mem1, aw1, len] using hload) - (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2435⟩, 0x80, .DUP1) - (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2436⟩, 0x83, .DUP4) - (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨2437⟩, 0x52, .MSTORE) - hcostStoreLen (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2438⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2440⟩, 0x85, .DUP6) - (by evm_ov), - raw add (by attester_decode_at v, ⟨2441⟩, 0x01, .ADD) - (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2442⟩, 0x91, .SWAP2) - (by evm_ov), - raw pop (by attester_decode_at v, ⟨2443⟩, 0x50, .POP) - (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2444⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2446⟩, 0x81, .DUP2) - (by evm_ov), - raw push1 ⟨5⟩ (by attester_decode_at v, ⟨2447⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw shl (by attester_decode_at v, ⟨2449⟩, 0x1b, .SHL) - (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨2450⟩, 0x86, .DUP7) - (by evm_ov), - raw add (by attester_decode_at v, ⟨2451⟩, 0x01, .ADD) - (by evm_ov), - raw add (by attester_decode_at v, ⟨2452⟩, 0x01, .ADD) - (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2453⟩, 0x92, .SWAP3) - (by evm_ov), - raw pop (by attester_decode_at v, ⟨2454⟩, 0x50, .POP) - (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2455⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨2457⟩, 0x86, .DUP7) - (by evm_ov), - raw add (by attester_decode_at v, ⟨2458⟩, 0x01, .ADD) - (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2459⟩, 0x5f, .PUSH0) - (by evm_ov)]⟩ - -theorem attesterX_multiRevokeEncoderOuterLoopGuard - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {idx srcHead len dstHead endPtr scratch dst src ret : UInt256} - {tail : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (htail : tail.length ≤ 1000) - (hlt : UInt256.lt idx len = ⟨1⟩) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) - (idx :: srcHead :: len :: dstHead :: endPtr :: scratch :: dst :: src :: ret :: - tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2469⟩ : UInt256) - (idx :: srcHead :: len :: dstHead :: endPtr :: scratch :: dst :: src :: ret :: - tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run rd with [ - raw jumpdest (by attester_decode_at v, ⟨2460⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2461⟩, 0x82, .DUP3) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2462⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨2463⟩, 0x10, .LT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2464⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2592⟩ (by attester_decode_at v, ⟨2465⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2468⟩, 0x57, .JUMPI) - (by rw [hlt]; decide) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeEncoderOuterLoopToInnerLoop - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {idx srcHead len dstHead endPtr scratch dst src ret : UInt256} - {tail : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (htail : tail.length ≤ 1000) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2469⟩ : UInt256) - (idx :: srcHead :: len :: dstHead :: endPtr :: scratch :: dst :: src :: ret :: - tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - let mem1 := attesterMultiRevokeEncoderOuterOffsetMem mem dstHead endPtr dst - let aw1 := attesterMultiRevokeEncoderOuterOffsetAw aw dstHead - let srcWord := attesterMultiRevokeEncoderOuterSrcWord mem1 aw1 srcHead - let aw2 := attesterMultiRevokeEncoderOuterSrcAw aw1 srcHead - let schemaWord := attesterMultiRevokeEncoderOuterSchemaWord mem1 aw2 srcWord - let aw3 := attesterMultiRevokeEncoderOuterSchemaAw aw2 srcWord - let mem2 := attesterMultiRevokeEncoderOuterSchemaMem mem1 endPtr schemaWord - let aw4 := attesterMultiRevokeEncoderOuterSchemaStoreAw aw3 endPtr - let uidsPtr := attesterMultiRevokeEncoderOuterUidsPtrWord mem2 aw4 srcWord - let aw5 := attesterMultiRevokeEncoderOuterUidsPtrAw aw4 srcWord - let mem3 := attesterMultiRevokeEncoderOuterUidsOffsetMem mem2 endPtr - let aw6 := attesterMultiRevokeEncoderOuterUidsOffsetAw aw5 endPtr - let uidsLen := attesterMultiRevokeEncoderOuterUidsLenWord mem3 aw6 uidsPtr - let aw7 := attesterMultiRevokeEncoderOuterUidsLenAw aw6 uidsPtr - let mem4 := attesterMultiRevokeEncoderOuterUidsLenMem mem3 endPtr uidsLen - let aw8 := attesterMultiRevokeEncoderOuterUidsLenStoreAw aw7 endPtr - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2516⟩ : UInt256) - (uidsLen :: (endPtr + ⟨96⟩) :: (⟨0⟩ : UInt256) :: - ((⟨32⟩ : UInt256) + uidsPtr) :: idx :: srcHead :: len :: dstHead :: - endPtr :: scratch :: dst :: src :: ret :: tail) - mem4 aw8 ByteArray.empty (cA, σ) k' C' := by - let offsetWord := attesterMultiRevokeEncoderOuterOffsetWord endPtr dst - let mem1 := attesterMultiRevokeEncoderOuterOffsetMem mem dstHead endPtr dst - let aw1 := attesterMultiRevokeEncoderOuterOffsetAw aw dstHead - let srcWord := attesterMultiRevokeEncoderOuterSrcWord mem1 aw1 srcHead - let aw2 := attesterMultiRevokeEncoderOuterSrcAw aw1 srcHead - let schemaWord := attesterMultiRevokeEncoderOuterSchemaWord mem1 aw2 srcWord - let aw3 := attesterMultiRevokeEncoderOuterSchemaAw aw2 srcWord - let mem2 := attesterMultiRevokeEncoderOuterSchemaMem mem1 endPtr schemaWord - let aw4 := attesterMultiRevokeEncoderOuterSchemaStoreAw aw3 endPtr - let uidsPtr := attesterMultiRevokeEncoderOuterUidsPtrWord mem2 aw4 srcWord - let aw5 := attesterMultiRevokeEncoderOuterUidsPtrAw aw4 srcWord - let mem3 := attesterMultiRevokeEncoderOuterUidsOffsetMem mem2 endPtr - let aw6 := attesterMultiRevokeEncoderOuterUidsOffsetAw aw5 endPtr - let uidsLen := attesterMultiRevokeEncoderOuterUidsLenWord mem3 aw6 uidsPtr - let aw7 := attesterMultiRevokeEncoderOuterUidsLenAw aw6 uidsPtr - let mem4 := attesterMultiRevokeEncoderOuterUidsLenMem mem3 endPtr uidsLen - let aw8 := attesterMultiRevokeEncoderOuterUidsLenStoreAw aw7 endPtr - have hcostStoreOffset : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - dstHead :: offsetWord :: idx :: srcHead :: len :: dstHead :: endPtr :: - scratch :: dst :: src :: ret :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostLoadSrc : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - srcHead :: idx :: srcHead :: len :: dstHead :: endPtr :: scratch :: - dst :: src :: ret :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostLoadSchema : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - srcWord :: srcWord :: idx :: srcHead :: len :: dstHead :: endPtr :: - scratch :: dst :: src :: ret :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSchema : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - endPtr :: schemaWord :: srcWord :: idx :: srcHead :: len :: dstHead :: - endPtr :: scratch :: dst :: src :: ret :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw4 - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostLoadUidsPtr : - ∀ s : State, - s.machineState.activeWords = aw4 → - s.machineState.stack = - ((⟨32⟩ : UInt256) + srcWord) :: (⟨32⟩ : UInt256) :: idx :: - srcHead :: len :: dstHead :: endPtr :: scratch :: dst :: src :: - ret :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw5 - Cₘ aw4 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreUidsOffset : - ∀ s : State, - s.machineState.activeWords = aw5 → - s.machineState.stack = - (endPtr + ⟨32⟩) :: (⟨64⟩ : UInt256) :: (⟨64⟩ : UInt256) :: - uidsPtr :: (⟨32⟩ : UInt256) :: idx :: srcHead :: len :: dstHead :: - endPtr :: scratch :: dst :: src :: ret :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw6 - Cₘ aw5 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostLoadUidsLen : - ∀ s : State, - s.machineState.activeWords = aw6 → - s.machineState.stack = - uidsPtr :: (⟨64⟩ : UInt256) :: uidsPtr :: (⟨32⟩ : UInt256) :: - idx :: srcHead :: len :: dstHead :: endPtr :: scratch :: dst :: - src :: ret :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw7 - Cₘ aw6 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreUidsLen : - ∀ s : State, - s.machineState.activeWords = aw7 → - s.machineState.stack = - (endPtr + ⟨64⟩) :: uidsLen :: uidsLen :: uidsPtr :: - (⟨32⟩ : UInt256) :: idx :: srcHead :: len :: dstHead :: endPtr :: - scratch :: dst :: src :: ret :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw8 - Cₘ aw7 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - exact ⟨_, _, by - simpa [offsetWord, mem1, aw1, srcWord, aw2, schemaWord, aw3, mem2, aw4, - uidsPtr, aw5, mem3, aw6, uidsLen, aw7, mem4, aw8, - attesterMultiRevokeEncoderOuterOffsetWord, - attesterMultiRevokeEncoderOuterOffsetMem, - attesterMultiRevokeEncoderOuterOffsetAw, - attesterMultiRevokeEncoderOuterSrcWord, - attesterMultiRevokeEncoderOuterSrcAw, - attesterMultiRevokeEncoderOuterSchemaWord, - attesterMultiRevokeEncoderOuterSchemaAw, - attesterMultiRevokeEncoderOuterSchemaMem, - attesterMultiRevokeEncoderOuterSchemaStoreAw, - attesterMultiRevokeEncoderOuterUidsPtrWord, - attesterMultiRevokeEncoderOuterUidsPtrAw, - attesterMultiRevokeEncoderOuterUidsOffsetMem, - attesterMultiRevokeEncoderOuterUidsOffsetAw, - attesterMultiRevokeEncoderOuterUidsLenWord, - attesterMultiRevokeEncoderOuterUidsLenAw, - attesterMultiRevokeEncoderOuterUidsLenMem, - attesterMultiRevokeEncoderOuterUidsLenStoreAw] using - evm_run rd with [ - raw dup7 (by attester_decode_at v, ⟨2469⟩, 0x86, .DUP7) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2470⟩, 0x85, .DUP6) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2471⟩, 0x03, .SUB) (by evm_ov), - raw push1 ⟨63⟩ (by attester_decode_at v, ⟨2472⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw not (by attester_decode_at v, ⟨2474⟩, 0x19, .NOT) (by evm_ov), - raw add (by attester_decode_at v, ⟨2475⟩, 0x01, .ADD) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2476⟩, 0x84, .DUP5) (by evm_ov), - raw mstore (Cₘ aw1 - Cₘ aw) mem1 aw1 - (by attester_decode_at v, ⟨2477⟩, 0x52, .MSTORE) - hcostStoreOffset (by rfl) (by rfl) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2478⟩, 0x81, .DUP2) (by evm_ov), - raw mload (Cₘ aw2 - Cₘ aw1) srcWord aw2 - (by attester_decode_at v, ⟨2479⟩, 0x51, .MLOAD) - hcostLoadSrc (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2480⟩, 0x80, .DUP1) (by evm_ov), - raw mload (Cₘ aw3 - Cₘ aw2) schemaWord aw3 - (by attester_decode_at v, ⟨2481⟩, 0x51, .MLOAD) - hcostLoadSchema (by rfl) (by rfl) (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨2482⟩, 0x86, .DUP7) (by evm_ov), - raw mstore (Cₘ aw4 - Cₘ aw3) mem2 aw4 - (by attester_decode_at v, ⟨2483⟩, 0x52, .MSTORE) - hcostStoreSchema (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2484⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2486⟩, 0x90, .SWAP1) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2487⟩, 0x81, .DUP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨2488⟩, 0x01, .ADD) (by evm_ov), - raw mload (Cₘ aw5 - Cₘ aw4) uidsPtr aw5 - (by attester_decode_at v, ⟨2489⟩, 0x51, .MLOAD) - hcostLoadUidsPtr (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2490⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2492⟩, 0x82, .DUP3) (by evm_ov), - raw dup9 (by attester_decode_at v, ⟨2493⟩, 0x88, .DUP9) (by evm_ov), - raw add (by attester_decode_at v, ⟨2494⟩, 0x01, .ADD) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2495⟩, 0x81, .DUP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2496⟩, 0x90, .SWAP1) (by evm_ov), - raw mstore (Cₘ aw6 - Cₘ aw5) mem3 aw6 - (by attester_decode_at v, ⟨2497⟩, 0x52, .MSTORE) - hcostStoreUidsOffset (by rfl) (by rfl) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2498⟩, 0x81, .DUP2) (by evm_ov), - raw mload (Cₘ aw7 - Cₘ aw6) uidsLen aw7 - (by attester_decode_at v, ⟨2499⟩, 0x51, .MLOAD) - hcostLoadUidsLen (by rfl) (by rfl) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2500⟩, 0x90, .SWAP1) (by evm_ov), - raw dup9 (by attester_decode_at v, ⟨2501⟩, 0x88, .DUP9) (by evm_ov), - raw add (by attester_decode_at v, ⟨2502⟩, 0x01, .ADD) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2503⟩, 0x81, .DUP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2504⟩, 0x90, .SWAP1) (by evm_ov), - raw mstore (Cₘ aw8 - Cₘ aw7) mem4 aw8 - (by attester_decode_at v, ⟨2505⟩, 0x52, .MSTORE) - hcostStoreUidsLen (by rfl) (by rfl) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2506⟩, 0x91, .SWAP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨2507⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2508⟩, 0x90, .SWAP1) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2509⟩, 0x5f, .PUSH0) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2510⟩, 0x90, .SWAP1) (by evm_ov), - raw push1 ⟨96⟩ (by attester_decode_at v, ⟨2511⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup9 (by attester_decode_at v, ⟨2513⟩, 0x88, .DUP9) (by evm_ov), - raw add (by attester_decode_at v, ⟨2514⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2515⟩, 0x90, .SWAP1) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeEncoderInnerLoopGuard - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {innerLen dstData innerIdx uidPayload : UInt256} - {tail : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (htail : tail.length ≤ 1000) - (hlt : UInt256.lt innerIdx innerLen = ⟨1⟩) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2516⟩ : UInt256) - (innerLen :: dstData :: innerIdx :: uidPayload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2525⟩ : UInt256) - (innerLen :: dstData :: innerIdx :: uidPayload :: tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run rd with [ - raw jumpdest (by attester_decode_at v, ⟨2516⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2517⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2518⟩, 0x83, .DUP4) (by evm_ov), - raw lt (by attester_decode_at v, ⟨2519⟩, 0x10, .LT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2520⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2568⟩ (by attester_decode_at v, ⟨2521⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2524⟩, 0x57, .JUMPI) - (by rw [hlt]; decide) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeEncoderInnerLoopStepPrefix - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {innerLen dstData innerIdx uidPayload : UInt256} - {tail : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (htail : tail.length ≤ 1000) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2525⟩ : UInt256) - (innerLen :: dstData :: innerIdx :: uidPayload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - let firstWord := attesterMultiRevokeEncoderInnerFirstWord mem aw uidPayload - let aw1 := attesterMultiRevokeEncoderInnerFirstAw aw uidPayload - let valueWord := attesterMultiRevokeEncoderInnerValueWord mem aw1 firstWord - let aw2 := attesterMultiRevokeEncoderInnerValueAw aw1 firstWord - let mem1 := attesterMultiRevokeEncoderInnerValueMem mem dstData valueWord - let aw3 := attesterMultiRevokeEncoderInnerValueStoreAw aw2 dstData - let extraWord := attesterMultiRevokeEncoderInnerExtraWord mem1 aw3 firstWord - let aw4 := attesterMultiRevokeEncoderInnerExtraAw aw3 firstWord - let mem2 := attesterMultiRevokeEncoderInnerExtraMem mem1 dstData extraWord - let aw5 := attesterMultiRevokeEncoderInnerExtraStoreAw aw4 dstData - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2544⟩ : UInt256) - ((⟨2545⟩ : UInt256) :: innerLen :: dstData :: innerIdx :: - uidPayload :: tail) - mem2 aw5 ByteArray.empty (cA, σ) k' C' := by - let firstWord := attesterMultiRevokeEncoderInnerFirstWord mem aw uidPayload - let aw1 := attesterMultiRevokeEncoderInnerFirstAw aw uidPayload - let valueWord := attesterMultiRevokeEncoderInnerValueWord mem aw1 firstWord - let aw2 := attesterMultiRevokeEncoderInnerValueAw aw1 firstWord - let mem1 := attesterMultiRevokeEncoderInnerValueMem mem dstData valueWord - let aw3 := attesterMultiRevokeEncoderInnerValueStoreAw aw2 dstData - let extraWord := attesterMultiRevokeEncoderInnerExtraWord mem1 aw3 firstWord - let aw4 := attesterMultiRevokeEncoderInnerExtraAw aw3 firstWord - let mem2 := attesterMultiRevokeEncoderInnerExtraMem mem1 dstData extraWord - let aw5 := attesterMultiRevokeEncoderInnerExtraStoreAw aw4 dstData - have hcostLoadFirst : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - uidPayload :: dstData :: (⟨2545⟩ : UInt256) :: innerLen :: dstData :: - innerIdx :: uidPayload :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostLoadValue : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - firstWord :: firstWord :: dstData :: (⟨2545⟩ : UInt256) :: - innerLen :: dstData :: innerIdx :: uidPayload :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreValue : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - dstData :: valueWord :: firstWord :: dstData :: (⟨2545⟩ : UInt256) :: - innerLen :: dstData :: innerIdx :: uidPayload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostLoadExtra : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - ((⟨32⟩ : UInt256) + firstWord) :: (⟨32⟩ : UInt256) :: - dstData :: (⟨2545⟩ : UInt256) :: innerLen :: dstData :: - innerIdx :: uidPayload :: tail → - memoryExpansionCost s .MLOAD = Cₘ aw4 - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreExtra : - ∀ s : State, - s.machineState.activeWords = aw4 → - s.machineState.stack = - (dstData + ⟨32⟩) :: extraWord :: (⟨2545⟩ : UInt256) :: - innerLen :: dstData :: innerIdx :: uidPayload :: tail → - memoryExpansionCost s .MSTORE = Cₘ aw5 - Cₘ aw4 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - exact ⟨_, _, by - simpa [firstWord, aw1, valueWord, aw2, mem1, aw3, extraWord, aw4, mem2, aw5, - attesterMultiRevokeEncoderInnerFirstWord, - attesterMultiRevokeEncoderInnerFirstAw, - attesterMultiRevokeEncoderInnerValueWord, - attesterMultiRevokeEncoderInnerValueAw, - attesterMultiRevokeEncoderInnerValueMem, - attesterMultiRevokeEncoderInnerValueStoreAw, - attesterMultiRevokeEncoderInnerExtraWord, - attesterMultiRevokeEncoderInnerExtraAw, - attesterMultiRevokeEncoderInnerExtraMem, - attesterMultiRevokeEncoderInnerExtraStoreAw] using - evm_run rd with [ - raw push2 ⟨2545⟩ (by attester_decode_at v, ⟨2525⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2528⟩, 0x82, .DUP3) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2529⟩, 0x85, .DUP6) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) firstWord aw1 - (by attester_decode_at v, ⟨2530⟩, 0x51, .MLOAD) - hcostLoadFirst (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2531⟩, 0x80, .DUP1) (by evm_ov), - raw mload (Cₘ aw2 - Cₘ aw1) valueWord aw2 - (by attester_decode_at v, ⟨2532⟩, 0x51, .MLOAD) - hcostLoadValue (by rfl) (by rfl) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2533⟩, 0x82, .DUP3) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem1 aw3 - (by attester_decode_at v, ⟨2534⟩, 0x52, .MSTORE) - hcostStoreValue (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2535⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2537⟩, 0x90, .SWAP1) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2538⟩, 0x81, .DUP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨2539⟩, 0x01, .ADD) (by evm_ov), - raw mload (Cₘ aw4 - Cₘ aw3) extraWord aw4 - (by attester_decode_at v, ⟨2540⟩, 0x51, .MLOAD) - hcostLoadExtra (by rfl) (by rfl) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2541⟩, 0x91, .SWAP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨2542⟩, 0x01, .ADD) (by evm_ov), - raw mstore (Cₘ aw5 - Cₘ aw4) mem2 aw5 - (by attester_decode_at v, ⟨2543⟩, 0x52, .MSTORE) - hcostStoreExtra (by rfl) (by rfl) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeEncoderInnerLoopStep - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {innerLen dstData innerIdx uidPayload : UInt256} - {tail : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (htail : tail.length ≤ 1000) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2525⟩ : UInt256) - (innerLen :: dstData :: innerIdx :: uidPayload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - let firstWord := attesterMultiRevokeEncoderInnerFirstWord mem aw uidPayload - let aw1 := attesterMultiRevokeEncoderInnerFirstAw aw uidPayload - let valueWord := attesterMultiRevokeEncoderInnerValueWord mem aw1 firstWord - let aw2 := attesterMultiRevokeEncoderInnerValueAw aw1 firstWord - let mem1 := attesterMultiRevokeEncoderInnerValueMem mem dstData valueWord - let aw3 := attesterMultiRevokeEncoderInnerValueStoreAw aw2 dstData - let extraWord := attesterMultiRevokeEncoderInnerExtraWord mem1 aw3 firstWord - let aw4 := attesterMultiRevokeEncoderInnerExtraAw aw3 firstWord - let mem2 := attesterMultiRevokeEncoderInnerExtraMem mem1 dstData extraWord - let aw5 := attesterMultiRevokeEncoderInnerExtraStoreAw aw4 dstData - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2516⟩ : UInt256) - (innerLen :: (dstData + ⟨64⟩) :: (innerIdx + ⟨1⟩) :: - (uidPayload + ⟨32⟩) :: tail) - mem2 aw5 ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k1, C1, rd2544⟩ := - attesterX_multiRevokeEncoderInnerLoopStepPrefix - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v htail rd - exact ⟨_, _, by - simpa [u256_add_comm] using - evm_run rd2544 with [ - raw jump (by attester_decode_at v, ⟨2544⟩, 0x56, .JUMP) - (attesterMultiRevokeEncodeInnerReturnJumpdest v) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨2545⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2546⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2548⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨2549⟩, 0x01, .ADD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2550⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2551⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2552⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2554⟩, 0x84, .DUP5) (by evm_ov), - raw add (by attester_decode_at v, ⟨2555⟩, 0x01, .ADD) (by evm_ov), - raw swap4 (by attester_decode_at v, ⟨2556⟩, 0x93, .SWAP4) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2557⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2558⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2560⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨2561⟩, 0x01, .ADD) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2562⟩, 0x92, .SWAP3) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2563⟩, 0x50, .POP) (by evm_ov), - raw push2 ⟨2516⟩ (by attester_decode_at v, ⟨2564⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jump (by attester_decode_at v, ⟨2567⟩, 0x56, .JUMP) - (attesterMultiRevokeEncodeInnerLoopJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeEncoderInnerLoopExitGuard - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {innerLen dstData innerIdx uidPayload : UInt256} - {tail : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (htail : tail.length ≤ 1000) - (hlt : UInt256.lt innerIdx innerLen = ⟨0⟩) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2516⟩ : UInt256) - (innerLen :: dstData :: innerIdx :: uidPayload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2568⟩ : UInt256) - (innerLen :: dstData :: innerIdx :: uidPayload :: tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run rd with [ - raw jumpdest (by attester_decode_at v, ⟨2516⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2517⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2518⟩, 0x83, .DUP4) (by evm_ov), - raw lt (by attester_decode_at v, ⟨2519⟩, 0x10, .LT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2520⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2568⟩ (by attester_decode_at v, ⟨2521⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2524⟩, 0x57, .JUMPI) - (by rw [hlt]; decide) - (attesterMultiRevokeEncodeInnerExitJumpdest v) (by evm_ov)]⟩ - -structure AttesterMultiRevokeEncoderInnerState where - dstData : UInt256 - innerIdx : UInt256 - uidPayload : UInt256 - mem : ByteArray - aw : UInt256 - -def attesterMultiRevokeEncoderInnerStack - (innerLen : UInt256) (tail : List UInt256) - (s : AttesterMultiRevokeEncoderInnerState) : List UInt256 := - innerLen :: s.dstData :: s.innerIdx :: s.uidPayload :: tail - -def attesterMultiRevokeEncoderInnerStepState - (s : AttesterMultiRevokeEncoderInnerState) : - AttesterMultiRevokeEncoderInnerState := - let firstWord := attesterMultiRevokeEncoderInnerFirstWord s.mem s.aw s.uidPayload - let aw1 := attesterMultiRevokeEncoderInnerFirstAw s.aw s.uidPayload - let valueWord := attesterMultiRevokeEncoderInnerValueWord s.mem aw1 firstWord - let aw2 := attesterMultiRevokeEncoderInnerValueAw aw1 firstWord - let mem1 := attesterMultiRevokeEncoderInnerValueMem s.mem s.dstData valueWord - let aw3 := attesterMultiRevokeEncoderInnerValueStoreAw aw2 s.dstData - let extraWord := attesterMultiRevokeEncoderInnerExtraWord mem1 aw3 firstWord - let aw4 := attesterMultiRevokeEncoderInnerExtraAw aw3 firstWord - let mem2 := attesterMultiRevokeEncoderInnerExtraMem mem1 s.dstData extraWord - let aw5 := attesterMultiRevokeEncoderInnerExtraStoreAw aw4 s.dstData - { dstData := s.dstData + ⟨64⟩, - innerIdx := s.innerIdx + ⟨1⟩, - uidPayload := s.uidPayload + ⟨32⟩, - mem := mem2, - aw := aw5 } - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeEncoderInnerLoopWithStateInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {innerLen dstData uidPayload : UInt256} - {tail : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (htail : tail.length ≤ 1000) - (Inv : Nat → AttesterMultiRevokeEncoderInnerState → Prop) - (hidx : ∀ n s, Inv n s → s.innerIdx = UInt256.ofNat (innerLen.toNat - n)) - (hle : ∀ n s, Inv n s → n ≤ innerLen.toNat) - (hstep : - ∀ n s, Inv (n + 1) s → - Inv n (attesterMultiRevokeEncoderInnerStepState s)) - (hInv0 : - Inv innerLen.toNat - { dstData := dstData, - innerIdx := (⟨0⟩ : UInt256), - uidPayload := uidPayload, - mem := mem, - aw := aw }) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2516⟩ : UInt256) - (innerLen :: dstData :: (⟨0⟩ : UInt256) :: uidPayload :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ s' k' C', - Inv 0 s' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2568⟩ : UInt256) - (attesterMultiRevokeEncoderInnerStack innerLen tail s') - s'.mem s'.aw ByteArray.empty (cA, σ) k' C' := by - let stk := attesterMultiRevokeEncoderInnerStack innerLen tail - let memOf : AttesterMultiRevokeEncoderInnerState → ByteArray := fun s => s.mem - let awOf : AttesterMultiRevokeEncoderInnerState → UInt256 := fun s => s.aw - have hexit : - ∀ s, Inv 0 s → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2516⟩ : UInt256) (stk s) (memOf s) (awOf s) - ByteArray.empty (cA, σ) k C → - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2568⟩ : UInt256) (stk s) (memOf s) (awOf s) - ByteArray.empty (cA, σ) k' C' := by - intro s hInv k C rd - have hidxLen : s.innerIdx = innerLen := by - rw [hidx 0 s hInv] - simpa using (u256_ofNat_toNat innerLen) - have hlt : UInt256.lt s.innerIdx innerLen = (⟨0⟩ : UInt256) := by - rw [hidxLen] - exact ult_zero (a := innerLen) (b := innerLen) (by rfl) - exact attesterX_multiRevokeEncoderInnerLoopExitGuard - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (innerLen := innerLen) (dstData := s.dstData) (innerIdx := s.innerIdx) - (uidPayload := s.uidPayload) (tail := tail) (mem := s.mem) (aw := s.aw) - (k := k) (C := C) htail hlt - (by simpa [stk, memOf, awOf, attesterMultiRevokeEncoderInnerStack] using rd) - have hbody : - ∀ n s, Inv (n + 1) s → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2516⟩ : UInt256) (stk s) (memOf s) (awOf s) - ByteArray.empty (cA, σ) k C → - ∃ s' k' C', - Inv n s' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2516⟩ : UInt256) (stk s') (memOf s') (awOf s') - ByteArray.empty (cA, σ) k' C' := by - intro n s hInv k C rd - let s' := attesterMultiRevokeEncoderInnerStepState s - have hidxNat : s.innerIdx.toNat = innerLen.toNat - (n + 1) := by - rw [hidx (n + 1) s hInv] - exact ulit_toNat' (innerLen.toNat - (n + 1)) - (lt_of_le_of_lt (Nat.sub_le _ _) innerLen.val.isLt) - have hltNat : s.innerIdx.toNat < innerLen.toNat := by - have hnle : n + 1 ≤ innerLen.toNat := hle (n + 1) s hInv - omega - have hlt : UInt256.lt s.innerIdx innerLen = (⟨1⟩ : UInt256) := - ult_one hltNat - obtain ⟨k1, C1, rd2525⟩ := - attesterX_multiRevokeEncoderInnerLoopGuard - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (innerLen := innerLen) (dstData := s.dstData) (innerIdx := s.innerIdx) - (uidPayload := s.uidPayload) (tail := tail) (mem := s.mem) (aw := s.aw) - (k := k) (C := C) htail hlt - (by simpa [stk, memOf, awOf, attesterMultiRevokeEncoderInnerStack] using rd) - obtain ⟨k2, C2, rdNext⟩ := - attesterX_multiRevokeEncoderInnerLoopStep - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (innerLen := innerLen) (dstData := s.dstData) (innerIdx := s.innerIdx) - (uidPayload := s.uidPayload) (tail := tail) (mem := s.mem) (aw := s.aw) - (k := k1) (C := C1) htail rd2525 - refine ⟨s', k2, C2, hstep n s hInv, ?_⟩ - simpa [s', stk, memOf, awOf, attesterMultiRevokeEncoderInnerStack, - attesterMultiRevokeEncoderInnerStepState] using rdNext - let s0 : AttesterMultiRevokeEncoderInnerState := - { dstData := dstData, - innerIdx := (⟨0⟩ : UInt256), - uidPayload := uidPayload, - mem := mem, - aw := aw } - obtain ⟨s', k', C', hInvFinal, rdFinal⟩ := - RD.whileLoopCarryExit - (code := patchedRuntime v) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) - (rdata := ByteArray.empty) (acc := (cA, σ)) - (header := (⟨2516⟩ : UInt256)) (exit := (⟨2568⟩ : UInt256)) - Inv stk memOf awOf stk memOf awOf hexit hbody - innerLen.toNat s0 hInv0 k C - (by - simpa [s0, stk, memOf, awOf, attesterMultiRevokeEncoderInnerStack] - using rd) - exact ⟨s', k', C', hInvFinal, rdFinal⟩ - -theorem attesterX_multiRevokeEncoderInnerLoopExitToOuterLoop - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {innerLen dstData innerIdx uidPayload idx srcHead len dstHead endPtr - scratch dst src ret : UInt256} - {tail : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (htail : tail.length ≤ 1000) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2568⟩ : UInt256) - (innerLen :: dstData :: innerIdx :: uidPayload :: idx :: srcHead :: - len :: dstHead :: endPtr :: scratch :: dst :: src :: ret :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) - (((⟨1⟩ : UInt256) + idx) :: ((⟨32⟩ : UInt256) + srcHead) :: - len :: ((⟨32⟩ : UInt256) + dstHead) :: dstData :: scratch :: - dst :: src :: ret :: tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, by - simpa using - evm_run rd with [ - raw jumpdest (by attester_decode_at v, ⟨2568⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2569⟩, 0x50, .POP) (by evm_ov), - raw swap7 (by attester_decode_at v, ⟨2570⟩, 0x96, .SWAP7) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2571⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2572⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2573⟩, 0x50, .POP) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2574⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw swap4 (by attester_decode_at v, ⟨2576⟩, 0x93, .SWAP4) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨2577⟩, 0x84, .DUP5) (by evm_ov), - raw add (by attester_decode_at v, ⟨2578⟩, 0x01, .ADD) (by evm_ov), - raw swap4 (by attester_decode_at v, ⟨2579⟩, 0x93, .SWAP4) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2580⟩, 0x91, .SWAP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2581⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2582⟩, 0x91, .SWAP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨2583⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2584⟩, 0x90, .SWAP1) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨2585⟩, 0x60, (.Push .PUSH1)) - (by evm_ov), - raw add (by attester_decode_at v, ⟨2587⟩, 0x01, .ADD) (by evm_ov), - raw push2 ⟨2460⟩ (by attester_decode_at v, ⟨2588⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jump (by attester_decode_at v, ⟨2591⟩, 0x56, .JUMP) - (attesterMultiRevokeEncodeOuterLoopJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeEncoderOuterLoopExitGuard - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {idx srcHead len dstHead endPtr scratch dst src ret : UInt256} - {tail : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (htail : tail.length ≤ 1000) - (hlt : UInt256.lt idx len = ⟨0⟩) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) - (idx :: srcHead :: len :: dstHead :: endPtr :: scratch :: dst :: src :: ret :: - tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2592⟩ : UInt256) - (idx :: srcHead :: len :: dstHead :: endPtr :: scratch :: dst :: src :: ret :: - tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run rd with [ - raw jumpdest (by attester_decode_at v, ⟨2460⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨2461⟩, 0x82, .DUP3) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨2462⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨2463⟩, 0x10, .LT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2464⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2592⟩ (by attester_decode_at v, ⟨2465⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2468⟩, 0x57, .JUMPI) - (by rw [hlt]; decide) - (attesterMultiRevokeEncodeOuterExitJumpdest v) (by evm_ov)]⟩ - -structure AttesterMultiRevokeEncoderOuterState where - idx : UInt256 - srcHead : UInt256 - dstHead : UInt256 - endPtr : UInt256 - mem : ByteArray - aw : UInt256 - -def attesterMultiRevokeEncoderOuterStack - (len scratch dst src ret : UInt256) (tail : List UInt256) - (s : AttesterMultiRevokeEncoderOuterState) : List UInt256 := - s.idx :: s.srcHead :: len :: s.dstHead :: s.endPtr :: scratch :: dst :: src :: ret :: - tail - -def attesterMultiRevokeEncoderOuterInnerLen - (dst : UInt256) (s : AttesterMultiRevokeEncoderOuterState) : UInt256 := - let mem1 := attesterMultiRevokeEncoderOuterOffsetMem s.mem s.dstHead s.endPtr dst - let aw1 := attesterMultiRevokeEncoderOuterOffsetAw s.aw s.dstHead - let srcWord := attesterMultiRevokeEncoderOuterSrcWord mem1 aw1 s.srcHead - let aw2 := attesterMultiRevokeEncoderOuterSrcAw aw1 s.srcHead - let schemaWord := attesterMultiRevokeEncoderOuterSchemaWord mem1 aw2 srcWord - let aw3 := attesterMultiRevokeEncoderOuterSchemaAw aw2 srcWord - let mem2 := attesterMultiRevokeEncoderOuterSchemaMem mem1 s.endPtr schemaWord - let aw4 := attesterMultiRevokeEncoderOuterSchemaStoreAw aw3 s.endPtr - let uidsPtr := attesterMultiRevokeEncoderOuterUidsPtrWord mem2 aw4 srcWord - let aw5 := attesterMultiRevokeEncoderOuterUidsPtrAw aw4 srcWord - let mem3 := attesterMultiRevokeEncoderOuterUidsOffsetMem mem2 s.endPtr - let aw6 := attesterMultiRevokeEncoderOuterUidsOffsetAw aw5 s.endPtr - attesterMultiRevokeEncoderOuterUidsLenWord mem3 aw6 uidsPtr - -def attesterMultiRevokeEncoderOuterInnerInitialState - (dst : UInt256) (s : AttesterMultiRevokeEncoderOuterState) : - AttesterMultiRevokeEncoderInnerState := - let mem1 := attesterMultiRevokeEncoderOuterOffsetMem s.mem s.dstHead s.endPtr dst - let aw1 := attesterMultiRevokeEncoderOuterOffsetAw s.aw s.dstHead - let srcWord := attesterMultiRevokeEncoderOuterSrcWord mem1 aw1 s.srcHead - let aw2 := attesterMultiRevokeEncoderOuterSrcAw aw1 s.srcHead - let schemaWord := attesterMultiRevokeEncoderOuterSchemaWord mem1 aw2 srcWord - let aw3 := attesterMultiRevokeEncoderOuterSchemaAw aw2 srcWord - let mem2 := attesterMultiRevokeEncoderOuterSchemaMem mem1 s.endPtr schemaWord - let aw4 := attesterMultiRevokeEncoderOuterSchemaStoreAw aw3 s.endPtr - let uidsPtr := attesterMultiRevokeEncoderOuterUidsPtrWord mem2 aw4 srcWord - let aw5 := attesterMultiRevokeEncoderOuterUidsPtrAw aw4 srcWord - let mem3 := attesterMultiRevokeEncoderOuterUidsOffsetMem mem2 s.endPtr - let aw6 := attesterMultiRevokeEncoderOuterUidsOffsetAw aw5 s.endPtr - let uidsLen := attesterMultiRevokeEncoderOuterUidsLenWord mem3 aw6 uidsPtr - let aw7 := attesterMultiRevokeEncoderOuterUidsLenAw aw6 uidsPtr - let mem4 := attesterMultiRevokeEncoderOuterUidsLenMem mem3 s.endPtr uidsLen - let aw8 := attesterMultiRevokeEncoderOuterUidsLenStoreAw aw7 s.endPtr - { dstData := s.endPtr + ⟨96⟩, - innerIdx := (⟨0⟩ : UInt256), - uidPayload := (⟨32⟩ : UInt256) + uidsPtr, - mem := mem4, - aw := aw8 } - -def attesterMultiRevokeEncoderOuterBodyNextState - (s : AttesterMultiRevokeEncoderOuterState) - (inner : AttesterMultiRevokeEncoderInnerState) : - AttesterMultiRevokeEncoderOuterState := - { idx := (⟨1⟩ : UInt256) + s.idx, - srcHead := (⟨32⟩ : UInt256) + s.srcHead, - dstHead := (⟨32⟩ : UInt256) + s.dstHead, - endPtr := inner.dstData, - mem := inner.mem, - aw := inner.aw } - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeEncoderOuterLoopBodyWithStateInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {len scratch dst src ret : UInt256} - {tail : List UInt256} {outer : AttesterMultiRevokeEncoderOuterState} {k C n : ℕ} - (htail : tail.length ≤ 1000) - (hinnerTail : tail.length + 9 ≤ 1000) - (OuterInv : Nat → AttesterMultiRevokeEncoderOuterState → Prop) - (InnerInv : Nat → AttesterMultiRevokeEncoderInnerState → Prop) - (hinnerIdx : ∀ n inner, - InnerInv n inner → - inner.innerIdx = - UInt256.ofNat ((attesterMultiRevokeEncoderOuterInnerLen dst outer).toNat - n)) - (hinnerLe : ∀ n inner, - InnerInv n inner → - n ≤ (attesterMultiRevokeEncoderOuterInnerLen dst outer).toNat) - (hinnerStep : - ∀ n inner, InnerInv (n + 1) inner → - InnerInv n (attesterMultiRevokeEncoderInnerStepState inner)) - (hinnerInit : - InnerInv (attesterMultiRevokeEncoderOuterInnerLen dst outer).toNat - (attesterMultiRevokeEncoderOuterInnerInitialState dst outer)) - (houterNext : - ∀ inner, InnerInv 0 inner → - OuterInv n (attesterMultiRevokeEncoderOuterBodyNextState outer inner)) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2469⟩ : UInt256) - (attesterMultiRevokeEncoderOuterStack len scratch dst src ret tail outer) - outer.mem outer.aw ByteArray.empty (cA, σ) k C) : - ∃ s' k' C', - OuterInv n s' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) - (attesterMultiRevokeEncoderOuterStack len scratch dst src ret tail s') - s'.mem s'.aw ByteArray.empty (cA, σ) k' C' := by - let innerTail : List UInt256 := - outer.idx :: outer.srcHead :: len :: outer.dstHead :: outer.endPtr :: scratch :: dst :: src :: - ret :: tail - obtain ⟨k1, C1, rd2516⟩ := - attesterX_multiRevokeEncoderOuterLoopToInnerLoop - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := outer.idx) (srcHead := outer.srcHead) (len := len) - (dstHead := outer.dstHead) (endPtr := outer.endPtr) (scratch := scratch) - (dst := dst) (src := src) (ret := ret) (tail := tail) - (mem := outer.mem) (aw := outer.aw) (k := k) (C := C) htail - (by simpa [attesterMultiRevokeEncoderOuterStack] using rd) - obtain ⟨innerDone, k2, C2, hinnerDone, rd2568⟩ := - attesterX_multiRevokeEncoderInnerLoopWithStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (innerLen := attesterMultiRevokeEncoderOuterInnerLen dst outer) - (dstData := (attesterMultiRevokeEncoderOuterInnerInitialState dst outer).dstData) - (uidPayload := (attesterMultiRevokeEncoderOuterInnerInitialState dst outer).uidPayload) - (tail := innerTail) - (mem := (attesterMultiRevokeEncoderOuterInnerInitialState dst outer).mem) - (aw := (attesterMultiRevokeEncoderOuterInnerInitialState dst outer).aw) - (k := k1) (C := C1) hinnerTail InnerInv hinnerIdx hinnerLe hinnerStep - hinnerInit - (by - simpa [innerTail, attesterMultiRevokeEncoderOuterInnerLen, - attesterMultiRevokeEncoderOuterInnerInitialState] using rd2516) - obtain ⟨k3, C3, rd2460⟩ := - attesterX_multiRevokeEncoderInnerLoopExitToOuterLoop - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (innerLen := attesterMultiRevokeEncoderOuterInnerLen dst outer) - (dstData := innerDone.dstData) (innerIdx := innerDone.innerIdx) - (uidPayload := innerDone.uidPayload) - (idx := outer.idx) (srcHead := outer.srcHead) (len := len) - (dstHead := outer.dstHead) (endPtr := outer.endPtr) (scratch := scratch) - (dst := dst) (src := src) (ret := ret) (tail := tail) - (mem := innerDone.mem) (aw := innerDone.aw) - (k := k2) (C := C2) htail - (by simpa [innerTail] using rd2568) - refine ⟨attesterMultiRevokeEncoderOuterBodyNextState outer innerDone, k3, C3, - houterNext innerDone hinnerDone, ?_⟩ - simpa [attesterMultiRevokeEncoderOuterStack, - attesterMultiRevokeEncoderOuterBodyNextState] using rd2460 - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeEncoderOuterLoopWithStateInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {idx srcHead len dstHead endPtr scratch dst src ret : UInt256} - {tail : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (htail : tail.length ≤ 1000) - (Inv : Nat → AttesterMultiRevokeEncoderOuterState → Prop) - (hidx : ∀ n s, Inv n s → s.idx = UInt256.ofNat (len.toNat - n)) - (hle : ∀ n s, Inv n s → n ≤ len.toNat) - (hbody : - ∀ n s, Inv (n + 1) s → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2469⟩ : UInt256) - (attesterMultiRevokeEncoderOuterStack len scratch dst src ret tail s) - s.mem s.aw ByteArray.empty (cA, σ) k C → - ∃ s' k' C', - Inv n s' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) - (attesterMultiRevokeEncoderOuterStack len scratch dst src ret tail s') - s'.mem s'.aw ByteArray.empty (cA, σ) k' C') - (hInv0 : - Inv len.toNat - { idx := idx, - srcHead := srcHead, - dstHead := dstHead, - endPtr := endPtr, - mem := mem, - aw := aw }) - (hidx0 : idx = (⟨0⟩ : UInt256)) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) - (idx :: srcHead :: len :: dstHead :: endPtr :: scratch :: dst :: src :: ret :: - tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ s' k' C', - Inv 0 s' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2592⟩ : UInt256) - (attesterMultiRevokeEncoderOuterStack len scratch dst src ret tail s') - s'.mem s'.aw ByteArray.empty (cA, σ) k' C' := by - let stk := attesterMultiRevokeEncoderOuterStack len scratch dst src ret tail - let memOf : AttesterMultiRevokeEncoderOuterState → ByteArray := fun s => s.mem - let awOf : AttesterMultiRevokeEncoderOuterState → UInt256 := fun s => s.aw - have hexit : - ∀ s, Inv 0 s → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) (stk s) (memOf s) (awOf s) - ByteArray.empty (cA, σ) k C → - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2592⟩ : UInt256) (stk s) (memOf s) (awOf s) - ByteArray.empty (cA, σ) k' C' := by - intro s hInv k C rd - have hidxLen : s.idx = len := by - rw [hidx 0 s hInv] - simpa using (u256_ofNat_toNat len) - have hlt : UInt256.lt s.idx len = (⟨0⟩ : UInt256) := by - rw [hidxLen] - exact ult_zero (a := len) (b := len) (by rfl) - exact attesterX_multiRevokeEncoderOuterLoopExitGuard - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := s.idx) (srcHead := s.srcHead) (len := len) (dstHead := s.dstHead) - (endPtr := s.endPtr) (scratch := scratch) (dst := dst) (src := src) - (ret := ret) (tail := tail) (mem := s.mem) (aw := s.aw) - (k := k) (C := C) htail hlt - (by simpa [stk, memOf, awOf, attesterMultiRevokeEncoderOuterStack] using rd) - have hstep : - ∀ n s, Inv (n + 1) s → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) (stk s) (memOf s) (awOf s) - ByteArray.empty (cA, σ) k C → - ∃ s' k' C', - Inv n s' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) (stk s') (memOf s') (awOf s') - ByteArray.empty (cA, σ) k' C' := by - intro n s hInv k C rd - have hidxNat : s.idx.toNat = len.toNat - (n + 1) := by - rw [hidx (n + 1) s hInv] - exact ulit_toNat' (len.toNat - (n + 1)) - (lt_of_le_of_lt (Nat.sub_le _ _) len.val.isLt) - have hltNat : s.idx.toNat < len.toNat := by - have hnle : n + 1 ≤ len.toNat := hle (n + 1) s hInv - omega - have hlt : UInt256.lt s.idx len = (⟨1⟩ : UInt256) := - ult_one hltNat - obtain ⟨k1, C1, rd2469⟩ := - attesterX_multiRevokeEncoderOuterLoopGuard - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := s.idx) (srcHead := s.srcHead) (len := len) (dstHead := s.dstHead) - (endPtr := s.endPtr) (scratch := scratch) (dst := dst) (src := src) - (ret := ret) (tail := tail) (mem := s.mem) (aw := s.aw) - (k := k) (C := C) htail hlt - (by simpa [stk, memOf, awOf, attesterMultiRevokeEncoderOuterStack] using rd) - obtain ⟨s', k2, C2, hInv', rdNext⟩ := - hbody n s hInv k1 C1 - (by simpa [stk, attesterMultiRevokeEncoderOuterStack] using rd2469) - exact ⟨s', k2, C2, hInv', by - simpa [stk, memOf, awOf, attesterMultiRevokeEncoderOuterStack] using rdNext⟩ - let s0 : AttesterMultiRevokeEncoderOuterState := - { idx := idx, - srcHead := srcHead, - dstHead := dstHead, - endPtr := endPtr, - mem := mem, - aw := aw } - obtain ⟨s', k', C', hInvFinal, rdFinal⟩ := - RD.whileLoopCarryExit - (code := patchedRuntime v) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) - (rdata := ByteArray.empty) (acc := (cA, σ)) - (header := (⟨2460⟩ : UInt256)) (exit := (⟨2592⟩ : UInt256)) - Inv stk memOf awOf stk memOf awOf hexit hstep - len.toNat s0 hInv0 k C - (by - simpa [s0, stk, memOf, awOf, attesterMultiRevokeEncoderOuterStack, hidx0] - using rd) - exact ⟨s', k', C', hInvFinal, rdFinal⟩ - -theorem attesterX_multiRevokeEncoderOuterLoopExitToReturn - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {idx srcHead len dstHead endPtr scratch dst src : UInt256} - {tail : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (htail : tail.length ≤ 1000) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2592⟩ : UInt256) - (idx :: srcHead :: len :: dstHead :: endPtr :: scratch :: dst :: src :: - (⟨775⟩ : UInt256) :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨775⟩ : UInt256) - (endPtr :: tail) - mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, by - simpa using - evm_run rd with [ - raw jumpdest (by attester_decode_at v, ⟨2592⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2593⟩, 0x50, .POP) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2594⟩, 0x92, .SWAP3) (by evm_ov), - raw swap7 (by attester_decode_at v, ⟨2595⟩, 0x96, .SWAP7) (by evm_ov), - raw swap6 (by attester_decode_at v, ⟨2596⟩, 0x95, .SWAP6) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2597⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2598⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2599⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2600⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2601⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2602⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨2603⟩, 0x56, .JUMP) - (attesterMultiRevokeEncoderReturnJumpdest v) (by evm_ov)]⟩ - -theorem attester_u256_ofNat_sub_succ_add_one - {m n : Nat} (hle : n + 1 ≤ m) (hm : m < UInt256.size) : - (UInt256.ofNat (m - (n + 1)) + (⟨1⟩ : UInt256)) = - UInt256.ofNat (m - n) := by - apply u256_inj - rw [uadd_toNat] - rw [ulit_toNat' (m - (n + 1)) (by omega)] - rw [show (⟨1⟩ : UInt256).toNat = 1 by decide] - rw [Nat.mod_eq_of_lt (by omega)] - rw [ulit_toNat' (m - n) (by omega)] - omega - -theorem attester_u256_one_add_ofNat_sub_succ - {m n : Nat} (hle : n + 1 ≤ m) (hm : m < UInt256.size) : - ((⟨1⟩ : UInt256) + UInt256.ofNat (m - (n + 1))) = - UInt256.ofNat (m - n) := by - rw [u256_add_comm] - exact attester_u256_ofNat_sub_succ_add_one hle hm - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeEncoderLoopToReturn - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {idx srcHead len dstHead endPtr scratch dst src : UInt256} - {tail : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (htail : tail.length ≤ 1000) - (hinnerTail : tail.length + 9 ≤ 1000) - (hidx0 : idx = (⟨0⟩ : UInt256)) - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) - (idx :: srcHead :: len :: dstHead :: endPtr :: scratch :: dst :: src :: - (⟨775⟩ : UInt256) :: tail) - mem aw ByteArray.empty (cA, σ) k C) : - ∃ s' : AttesterMultiRevokeEncoderOuterState, ∃ k' C', - s'.idx = len ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨775⟩ : UInt256) - (s'.endPtr :: tail) - s'.mem s'.aw ByteArray.empty (cA, σ) k' C' := by - let OuterInv : Nat → AttesterMultiRevokeEncoderOuterState → Prop := - fun n s => s.idx = UInt256.ofNat (len.toNat - n) ∧ n ≤ len.toNat - have hidx : - ∀ n s, OuterInv n s → s.idx = UInt256.ofNat (len.toNat - n) := by - intro n s h - exact h.1 - have hle : ∀ n s, OuterInv n s → n ≤ len.toNat := by - intro n s h - exact h.2 - have hbody : - ∀ n s, OuterInv (n + 1) s → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2469⟩ : UInt256) - (attesterMultiRevokeEncoderOuterStack len scratch dst src (⟨775⟩ : UInt256) - tail s) - s.mem s.aw ByteArray.empty (cA, σ) k C → - ∃ s' k' C', - OuterInv n s' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2460⟩ : UInt256) - (attesterMultiRevokeEncoderOuterStack len scratch dst src (⟨775⟩ : UInt256) - tail s') - s'.mem s'.aw ByteArray.empty (cA, σ) k' C' := by - intro n s hInv k C rdBody - let innerLen := attesterMultiRevokeEncoderOuterInnerLen dst s - let InnerInv : Nat → AttesterMultiRevokeEncoderInnerState → Prop := - fun m inner => inner.innerIdx = UInt256.ofNat (innerLen.toNat - m) ∧ - m ≤ innerLen.toNat - have hinnerIdx : - ∀ m inner, InnerInv m inner → - inner.innerIdx = - UInt256.ofNat ((attesterMultiRevokeEncoderOuterInnerLen dst s).toNat - m) := by - intro m inner h - simpa [innerLen] using h.1 - have hinnerLe : - ∀ m inner, InnerInv m inner → - m ≤ (attesterMultiRevokeEncoderOuterInnerLen dst s).toNat := by - intro m inner h - simpa [innerLen] using h.2 - have hinnerStep : - ∀ m inner, InnerInv (m + 1) inner → - InnerInv m (attesterMultiRevokeEncoderInnerStepState inner) := by - intro m inner h - constructor - · change - (inner.innerIdx + (⟨1⟩ : UInt256)) = - UInt256.ofNat (innerLen.toNat - m) - rw [h.1] - exact attester_u256_ofNat_sub_succ_add_one h.2 innerLen.val.isLt - · omega - have hinnerInit : - InnerInv (attesterMultiRevokeEncoderOuterInnerLen dst s).toNat - (attesterMultiRevokeEncoderOuterInnerInitialState dst s) := by - constructor - · dsimp [attesterMultiRevokeEncoderOuterInnerInitialState] - rw [show - innerLen.toNat - (attesterMultiRevokeEncoderOuterInnerLen dst s).toNat = 0 by - simp [innerLen]] - simpa using (u256_ofNat_toNat (⟨0⟩ : UInt256)).symm - · simp [innerLen] - have houterNext : - ∀ inner, InnerInv 0 inner → - OuterInv n (attesterMultiRevokeEncoderOuterBodyNextState s inner) := by - intro inner _hinner - constructor - · change - ((⟨1⟩ : UInt256) + s.idx) = - UInt256.ofNat (len.toNat - n) - rw [hInv.1] - exact attester_u256_one_add_ofNat_sub_succ hInv.2 len.val.isLt - · omega - exact - attesterX_multiRevokeEncoderOuterLoopBodyWithStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (len := len) (scratch := scratch) (dst := dst) (src := src) - (ret := (⟨775⟩ : UInt256)) (tail := tail) (outer := s) - (k := k) (C := C) (n := n) - htail hinnerTail OuterInv InnerInv hinnerIdx hinnerLe hinnerStep - hinnerInit houterNext rdBody - have hInv0 : - OuterInv len.toNat - { idx := idx, - srcHead := srcHead, - dstHead := dstHead, - endPtr := endPtr, - mem := mem, - aw := aw } := by - constructor - · rw [hidx0] - change (⟨0⟩ : UInt256) = UInt256.ofNat (len.toNat - len.toNat) - rw [Nat.sub_self] - simpa using (u256_ofNat_toNat (⟨0⟩ : UInt256)).symm - · omega - obtain ⟨s', k1, C1, hInvFinal, rd2592⟩ := - attesterX_multiRevokeEncoderOuterLoopWithStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := idx) (srcHead := srcHead) (len := len) (dstHead := dstHead) - (endPtr := endPtr) (scratch := scratch) (dst := dst) (src := src) - (ret := (⟨775⟩ : UInt256)) (tail := tail) (mem := mem) (aw := aw) - (k := k) (C := C) htail OuterInv hidx hle hbody hInv0 hidx0 rd - obtain ⟨k2, C2, rd775⟩ := - attesterX_multiRevokeEncoderOuterLoopExitToReturn - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (idx := s'.idx) (srcHead := s'.srcHead) (len := len) - (dstHead := s'.dstHead) (endPtr := s'.endPtr) (scratch := scratch) - (dst := dst) (src := src) (tail := tail) (mem := s'.mem) (aw := s'.aw) - (k := k1) (C := C1) htail rd2592 - refine ⟨s', k2, C2, ?_, rd775⟩ - rw [hInvFinal.1] - simpa using (u256_ofNat_toNat len) - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/MultiRevokeProgress.lean b/Benchmarks/EAS/Attester/MultiRevokeProgress.lean deleted file mode 100644 index fb6b246e..00000000 --- a/Benchmarks/EAS/Attester/MultiRevokeProgress.lean +++ /dev/null @@ -1,2166 +0,0 @@ -import Benchmarks.EAS.Attester.MultiRevokeMemory - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -def attesterMultiRevokeOuterInitFreeInv - (I : ExecutionEnv) (n : Nat) (a : AttesterMultiOuterArrayInitState) : Prop := - a.remaining = UInt256.ofNat (n + 1) ∧ - n + 1 < UInt256.size ∧ - n + 1 ≤ (attesterFirstArrayLengthWord I).toNat ∧ - 3 ≤ a.aw.toNat ∧ - a.aw.toNat * 32 < UInt256.size ∧ - 64 + 32 ≤ (attesterMultiOuterArrayInitFreeWord a.mem a.aw).toNat ∧ - 128 + 32 ≤ (attesterMultiOuterArrayInitFreeWord a.mem a.aw).toNat ∧ - (attesterMultiOuterArrayInitFreeWord a.mem a.aw).toNat + 64 * (n + 1) < - UInt256.size ∧ - (attesterMultiOuterArrayInitFreeWord a.mem a.aw).toNat + 64 * (n + 1) + - 160 + 160 * solcMaxU64 < UInt256.size ∧ - 64 + 32 ≤ a.slot.toNat ∧ - 128 + 32 ≤ a.slot.toNat ∧ - a.slot.toNat + 32 * (n + 1) < UInt256.size ∧ - a.slot.toNat + 32 * (n + 1) + 32 < UInt256.size ∧ - a.mem.readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) ∧ - 128 + 32 ≤ a.mem.size ∧ - (attesterMultiOuterArrayInitFreeWord a.mem a.aw).toNat = - 160 + 32 * (attesterFirstArrayLengthWord I).toNat + - 64 * ((attesterFirstArrayLengthWord I).toNat - (n + 1)) - -theorem attesterMultiRevokeOuterInitFreeInv_remaining - {I : ExecutionEnv} {n : Nat} {a : AttesterMultiOuterArrayInitState} - (hInv : attesterMultiRevokeOuterInitFreeInv I n a) : - a.remaining = UInt256.ofNat (n + 1) := - hInv.1 - -theorem attesterMultiRevokeOuterInitFreeInv_bound - {I : ExecutionEnv} {n : Nat} {a : AttesterMultiOuterArrayInitState} - (hInv : attesterMultiRevokeOuterInitFreeInv I n a) : - n + 1 < UInt256.size := - hInv.2.1 - -theorem attesterMultiRevokeOuterInitFreeInv_init - {I : ExecutionEnv} - (hlenNe : (attesterFirstArrayLengthWord I).toNat ≠ 0) - (hlenMax : (attesterFirstArrayLengthWord I).toNat ≤ solcMaxU64) : - attesterMultiRevokeOuterInitFreeInv I - ((attesterFirstArrayLengthWord I).toNat - 1) - { slot := ((⟨32⟩ : UInt256) + ⟨128⟩), - remaining := attesterFirstArrayLengthWord I, - mem := attesterMultiOuterArrayAllocMem I, - aw := UInt256.ofNat 5 } := by - let len := attesterFirstArrayLengthWord I - have hsucc : len.toNat - 1 + 1 = len.toNat := by - unfold len - omega - have hfreeToNat : - (attesterMultiOuterArrayInitFreeWord - (attesterMultiOuterArrayAllocMem I) (UInt256.ofNat 5)).toNat = - 160 + 32 * len.toNat := by - unfold attesterMultiOuterArrayInitFreeWord len - rw [attesterMultiOuterArrayAllocMem_mload64 I] - rw [attesterMultiOuterArrayAllocEndWord_toNat (I := I) hlenMax] - have hslotToNat : (((⟨32⟩ : UInt256) + ⟨128⟩).toNat) = 160 := by - decide - have hbound96 : 96 * len.toNat ≤ 96 * solcMaxU64 := by - unfold len - exact Nat.mul_le_mul_left 96 hlenMax - have hbound32 : 32 * len.toNat ≤ 32 * solcMaxU64 := by - unfold len - exact Nat.mul_le_mul_left 32 hlenMax - refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simpa [len, hsucc] using (u256_ofNat_toNat len).symm - · rw [hsucc] - exact len.val.isLt - · rw [hsucc] - · change 3 ≤ (UInt256.ofNat 5).toNat - decide - · change (UInt256.ofNat 5).toNat * 32 < UInt256.size - decide - · rw [hfreeToNat] - omega - · rw [hfreeToNat] - omega - · rw [hfreeToNat, hsucc] - norm_num [solcMaxU64, UInt256.size] at hbound96 ⊢ - omega - · rw [hfreeToNat, hsucc] - norm_num [solcMaxU64, UInt256.size] at hbound96 ⊢ - omega - · rw [hslotToNat] - omega - · rw [hslotToNat] - · rw [hslotToNat, hsucc] - norm_num [solcMaxU64, UInt256.size] at hbound32 ⊢ - omega - · rw [hslotToNat, hsucc] - norm_num [solcMaxU64, UInt256.size] at hbound32 ⊢ - omega - · exact attesterMultiOuterArrayAllocMem_read128 I - · rw [attesterMultiOuterArrayAllocMem_size I] - · rw [hfreeToNat, hsucc] - unfold len - omega - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevokeOuterInitFreeInv_step - {I : ExecutionEnv} {n : Nat} {a : AttesterMultiOuterArrayInitState} - (hInv : attesterMultiRevokeOuterInitFreeInv I (n + 1) a) : - attesterMultiRevokeOuterInitFreeInv I n - (attesterMultiOuterArrayInitStepState a) := by - rcases hInv with - ⟨hrem, hbound, hleOld, hawGe, hawMul, hfreeGe, hfree160, hfreeBound, hfreeSpare, - hslotGe, hslot160, hslotBound, hslotSpare, hread128, hmem128, hfreeExact⟩ - have hfree95 : - (attesterMultiOuterArrayInitFreeWord a.mem a.aw).toNat + 95 < UInt256.size := by - have hpos : 2 ≤ (n + 1) + 1 := by omega - have hmul : 95 ≤ 64 * ((n + 1) + 1) := by nlinarith - omega - have hslot63 : a.slot.toNat + 63 < UInt256.size := by - have hpos : 2 ≤ (n + 1) + 1 := by omega - have hmul : 63 ≤ 32 * ((n + 1) + 1) := by nlinarith - omega - have hawStep := - attesterMultiOuterArrayInitStepAw_bounds - (slot := a.slot) (mem := a.mem) (aw := a.aw) - hawGe hawMul hfree95 hslot63 - have hfree32 : - (attesterMultiOuterArrayInitFreeWord a.mem a.aw).toNat + 32 < - UInt256.size := by - omega - have hoffsetToNat : - (attesterMultiOuterArrayInitOffsetWord a.mem a.aw).toNat = - (attesterMultiOuterArrayInitFreeWord a.mem a.aw).toNat + 32 := by - unfold attesterMultiOuterArrayInitOffsetWord - exact uadd_word_lit32_toNat - (attesterMultiOuterArrayInitFreeWord a.mem a.aw) hfree32 - have hoffsetGe : - 64 + 32 ≤ (attesterMultiOuterArrayInitOffsetWord a.mem a.aw).toNat := by - rw [hoffsetToNat] - omega - have hfree64 : - (attesterMultiOuterArrayInitFreeWord a.mem a.aw).toNat + 64 < - UInt256.size := by - omega - have hfreeStep : - (attesterMultiOuterArrayInitFreeWord - (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw) - (attesterMultiOuterArrayInitStepAw a.slot a.mem a.aw)).toNat = - (attesterMultiOuterArrayInitFreeWord a.mem a.aw).toNat + 64 := - attesterMultiOuterArrayInitStep_freeWord_toNat - (slot := a.slot) (mem := a.mem) (aw := a.aw) - hfreeGe hoffsetGe hslotGe hawStep.2 hawStep.1 hfree64 - have hslot32 : a.slot.toNat + 32 < UInt256.size := by - omega - have hslotStep : - (((⟨32⟩ : UInt256) + a.slot).toNat) = a.slot.toNat + 32 := - uadd_lit32_toNat a.slot hslot32 - have hoffset160 : - 128 + 32 ≤ (attesterMultiOuterArrayInitOffsetWord a.mem a.aw).toNat := by - rw [hoffsetToNat] - omega - have hread128Step : - (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw).readWithPadding - 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) := by - simpa using - (attesterMultiOuterArrayInitStep_readWithPadding_nat - (base := (⟨128⟩ : UInt256)) (slot := a.slot) - (len := attesterFirstArrayLengthWord I) (mem := a.mem) (aw := a.aw) - (by simpa using hmem128) - (by simpa using hread128) - (by decide) - (by simpa using hfree160) - (by simpa using hoffset160) - (by simpa using hslot160)) - have hmem128Step : - 128 + 32 ≤ (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw).size := - le_trans hmem128 attesterMultiOuterArrayInitStep_size_ge - refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · change UInt256.sub a.remaining (⟨1⟩ : UInt256) = UInt256.ofNat (n + 1) - rw [hrem] - simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using - attester_u256_ofNat_succ_sub_one (n := n + 1) hbound - · omega - · omega - · simpa [attesterMultiOuterArrayInitStepState] using hawStep.1 - · simpa [attesterMultiOuterArrayInitStepState] using hawStep.2 - · change 64 + 32 ≤ - (attesterMultiOuterArrayInitFreeWord - (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw) - (attesterMultiOuterArrayInitStepAw a.slot a.mem a.aw)).toNat - rw [hfreeStep] - omega - · change 128 + 32 ≤ - (attesterMultiOuterArrayInitFreeWord - (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw) - (attesterMultiOuterArrayInitStepAw a.slot a.mem a.aw)).toNat - rw [hfreeStep] - omega - · change - (attesterMultiOuterArrayInitFreeWord - (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw) - (attesterMultiOuterArrayInitStepAw a.slot a.mem a.aw)).toNat + - 64 * (n + 1) < - UInt256.size - rw [hfreeStep] - omega - · change - (attesterMultiOuterArrayInitFreeWord - (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw) - (attesterMultiOuterArrayInitStepAw a.slot a.mem a.aw)).toNat + - 64 * (n + 1) + 160 + 160 * solcMaxU64 < - UInt256.size - rw [hfreeStep] - omega - · change 64 + 32 ≤ (((⟨32⟩ : UInt256) + a.slot).toNat) - rw [hslotStep] - omega - · change 128 + 32 ≤ (((⟨32⟩ : UInt256) + a.slot).toNat) - rw [hslotStep] - omega - · change (((⟨32⟩ : UInt256) + a.slot).toNat) + 32 * (n + 1) < - UInt256.size - rw [hslotStep] - omega - · change (((⟨32⟩ : UInt256) + a.slot).toNat) + 32 * (n + 1) + 32 < - UInt256.size - rw [hslotStep] - omega - · simpa [attesterMultiOuterArrayInitStepState] using hread128Step - · simpa [attesterMultiOuterArrayInitStepState] using hmem128Step - · change - (attesterMultiOuterArrayInitFreeWord - (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw) - (attesterMultiOuterArrayInitStepAw a.slot a.mem a.aw)).toNat = - 160 + 32 * (attesterFirstArrayLengthWord I).toNat + - 64 * ((attesterFirstArrayLengthWord I).toNat - (n + 1)) - rw [hfreeStep, hfreeExact] - have hsub : - (attesterFirstArrayLengthWord I).toNat - (n + 1) = - (attesterFirstArrayLengthWord I).toNat - (n + 2) + 1 := by - omega - rw [hsub] - nlinarith - -theorem attesterX_multiRevokeOuterArrayInitProgressWithStateInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (hprogress : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨291⟩ : UInt256) - [((⟨32⟩ : UInt256) + ⟨128⟩), - attesterFirstArrayLengthWord I, ⟨128⟩, ⟨0⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayAllocMem I) (UInt256.ofNat 5) - ByteArray.empty (cA, σ) k C) - (Inv : Nat → AttesterMultiOuterArrayInitState → Prop) - (hremaining : - ∀ n a, Inv n a → a.remaining = UInt256.ofNat (n + 1)) - (hbound : ∀ n a, Inv n a → n + 1 < UInt256.size) - (hstep : - ∀ n a, Inv (n + 1) a → Inv n (attesterMultiOuterArrayInitStepState a)) - (hinit : - Inv ((attesterFirstArrayLengthWord I).toNat - 1) - { slot := ((⟨32⟩ : UInt256) + ⟨128⟩), - remaining := attesterFirstArrayLengthWord I, - mem := attesterMultiOuterArrayAllocMem I, - aw := UInt256.ofNat 5 }) : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv 0 a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterArrayInitExitStack I ⟨128⟩ - (attesterFirstArrayLengthWord I) a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C := by - obtain ⟨k0, C0, rd0⟩ := hprogress - exact attesterX_multiRevokeOuterArrayInitLoopWithStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (slot := ((⟨32⟩ : UInt256) + ⟨128⟩)) - (base := ⟨128⟩) - (len := attesterFirstArrayLengthWord I) - (mem := attesterMultiOuterArrayAllocMem I) - (aw := UInt256.ofNat 5) (k := k0) (C := C0) - Inv hremaining hbound hstep hinit rd0 - -theorem attesterX_multiRevokeOuterArrayInitProgressWithFreeInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (hlenNe : (attesterFirstArrayLengthWord I).toNat ≠ 0) - (hlenMax : (attesterFirstArrayLengthWord I).toNat ≤ solcMaxU64) - (hprogress : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨291⟩ : UInt256) - [((⟨32⟩ : UInt256) + ⟨128⟩), - attesterFirstArrayLengthWord I, ⟨128⟩, ⟨0⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayAllocMem I) (UInt256.ofNat 5) - ByteArray.empty (cA, σ) k C) : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterArrayInitExitStack I ⟨128⟩ - (attesterFirstArrayLengthWord I) a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C := by - exact attesterX_multiRevokeOuterArrayInitProgressWithStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - hprogress - (Inv := attesterMultiRevokeOuterInitFreeInv I) - (fun n a hInv => attesterMultiRevokeOuterInitFreeInv_remaining hInv) - (fun n a hInv => attesterMultiRevokeOuterInitFreeInv_bound hInv) - (fun n a hInv => attesterMultiRevokeOuterInitFreeInv_step hInv) - (attesterMultiRevokeOuterInitFreeInv_init - (I := I) hlenNe hlenMax) - -theorem attesterX_multiRevokeOuterSourceLoopFirstGuardWithInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (Inv : AttesterMultiOuterArrayInitState → Prop) - (hlenNe : (attesterFirstArrayLengthWord I).toNat ≠ 0) - (hprogress : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterArrayInitExitStack I ⟨128⟩ - (attesterFirstArrayLengthWord I) a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C) : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨344⟩ : UInt256) - (attesterMultiRevokeOuterArrayInitExitStack I ⟨128⟩ - (attesterFirstArrayLengthWord I) a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C := by - obtain ⟨a', k0, C0, hrem, hInv, rd0⟩ := hprogress - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokeOuterSourceLoopFirstGuard - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := ⟨128⟩) - (len := attesterFirstArrayLengthWord I) - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) hlenNe - (by - simpa [attesterMultiRevokeOuterArrayInitExitStack] using rd0) - exact ⟨a', k1, C1, hrem, hInv, by - simpa [attesterMultiRevokeOuterArrayInitExitStack] using rd1⟩ - -theorem attesterX_multiRevokeOuterSecondArrayAccessOkWithInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (Inv : AttesterMultiOuterArrayInitState → Prop) - (hsecondLenNe : (attesterSecondArrayLengthWord I).toNat ≠ 0) - (hprogress : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨344⟩ : UInt256) - (attesterMultiRevokeOuterArrayInitExitStack I ⟨128⟩ - (attesterFirstArrayLengthWord I) a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C) : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨363⟩ : UInt256) - [⟨0⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C := by - obtain ⟨a', k0, C0, hrem, hInv, rd0⟩ := hprogress - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokeOuterSecondArrayAccessOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := ⟨128⟩) - (len := attesterFirstArrayLengthWord I) - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) hsecondLenNe - (by - simpa [attesterMultiRevokeOuterArrayInitExitStack] using rd0) - exact ⟨a', k1, C1, hrem, hInv, rd1⟩ - -theorem attesterX_multiRevokeFirstInnerArrayDecoderEntryWithInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (Inv : AttesterMultiOuterArrayInitState → Prop) - (hprogress : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨363⟩ : UInt256) - [⟨0⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C) : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2353⟩ : UInt256) - [(UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C := by - obtain ⟨a', k0, C0, hrem, hInv, rd0⟩ := hprogress - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokeFirstInnerArrayDecoderEntryFromOuterSecond - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) rd0 - exact ⟨a', k1, C1, hrem, hInv, rd1⟩ - -theorem attesterX_multiRevokeFirstInnerArrayDecoderReturnWithInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (Inv : AttesterMultiOuterArrayInitState → Prop) - (hoffsetOk : - UInt256.slt (attesterFirstInnerArrayOffsetWord I) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩) - (hlenOk : - UInt256.gt (attesterFirstInnerArrayLengthWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hpayloadOk : - UInt256.sgt (attesterFirstInnerArrayStartWord I + ⟨32⟩) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft (attesterFirstInnerArrayLengthWord I) ⟨5⟩)) = ⟨0⟩) - (hprogress : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2353⟩ : UInt256) - [(UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨381⟩, ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C) : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨381⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C := by - obtain ⟨a', k0, C0, hrem, hInv, rd0⟩ := hprogress - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokeFirstInnerArrayOffsetOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hoffsetOk - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) - (by simpa [attesterSecondArrayPayloadStartWord] using rd0) - obtain ⟨k2, C2, rd2⟩ := - attesterX_multiRevokeFirstInnerArrayLengthMaxOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hlenOk - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k1) (C := C1) rd1 - obtain ⟨k3, C3, rd3⟩ := - attesterX_multiRevokeFirstInnerArrayPayloadOkToReturn - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hpayloadOk - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k2) (C := C2) rd2 - exact ⟨a', k3, C3, hrem, hInv, rd3⟩ - -theorem attesterX_multiRevokeFirstInnerArrayNonemptyProgressWithInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (Inv : AttesterMultiOuterArrayInitState → Prop) - (hlenNe : attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩) - (hlenOk : - UInt256.gt (attesterFirstInnerArrayLengthWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩) - (hprogress : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨381⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C) : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨445⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, ⟨0⟩, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C := by - obtain ⟨a', k0, C0, hrem, hInv, rd0⟩ := hprogress - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokeFirstInnerArrayNonemptyOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hlenNe - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) rd0 - obtain ⟨k2, C2, rd2⟩ := - attesterX_multiRevokeFirstInnerArrayLengthAllocMaxOk - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v hlenOk - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k1) (C := C1) rd1 - exact ⟨a', k2, C2, hrem, hInv, rd2⟩ - -theorem attesterX_multiRevokeFirstInnerArrayAllocProgressWithInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (Inv : AttesterMultiOuterArrayInitState → Prop) - (hlenNe : attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩) - (hprogress : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨445⟩ : UInt256) - [attesterFirstInnerArrayLengthWord I, ⟨0⟩, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayLengthWord I, - attesterFirstInnerArrayStartWord I + ⟨32⟩, - ⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k C) : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - Inv a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - (((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) :: - attesterFirstInnerArrayLengthWord I :: - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') :: - ⟨0⟩ :: - attesterFirstInnerArrayLengthWord I :: - attesterFirstInnerArrayLengthWord I :: - (attesterFirstInnerArrayStartWord I + ⟨32⟩) :: - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I]) - (attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ByteArray.empty (cA, σ) k C := by - obtain ⟨a', k0, C0, hrem, hInv, rd0⟩ := hprogress - obtain ⟨k1, C1, rd1⟩ := - attesterX_multiRevokeFirstInnerArrayAllocToInitLoop - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (len := attesterFirstInnerArrayLengthWord I) - (payload := attesterFirstInnerArrayStartWord I + ⟨32⟩) - (tail := [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I]) - (mem := attesterMultiOuterArrayInitFinalMem a') - (aw := attesterMultiOuterArrayInitFinalAw a') - (k := k0) (C := C0) - (by simp) hlenNe (by simpa using rd0) - exact ⟨a', k1, C1, hrem, hInv, rd1⟩ - -def attesterMultiRevokeInnerInitReadInv - (I : ExecutionEnv) (a : AttesterMultiOuterArrayInitState) - (n : Nat) (b : AttesterMultiRevokeInnerArrayInitState) : Prop := - let base := - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a) - let len := attesterFirstInnerArrayLengthWord I - attesterMultiRevokeOuterInitFreeInv I 0 a ∧ - b.remaining = UInt256.ofNat (n + 1) ∧ - n + 1 < UInt256.size ∧ - 3 ≤ b.aw.toNat ∧ - b.aw.toNat * 32 < UInt256.size ∧ - b.mem.readWithPadding base.toNat 32 = UInt256.toByteArray len ∧ - base.toNat + 32 ≤ b.mem.size ∧ - 64 + 32 ≤ base.toNat ∧ - base.toNat + 32 ≤ (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat ∧ - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + - 64 * (n + 1) < UInt256.size ∧ - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + - 64 * (n + 1) + 64 * len.toNat + 96 < UInt256.size ∧ - base.toNat + 32 ≤ b.slot.toNat ∧ - b.slot.toNat + 32 * (n + 1) + 63 < UInt256.size ∧ - base.toNat + 32 + 32 * len.toNat + 63 < UInt256.size ∧ - b.mem.readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) ∧ - 128 + 32 ≤ b.mem.size ∧ - 128 + 32 ≤ base.toNat - -theorem attesterMultiRevokeInnerInitReadInv_outer - {I : ExecutionEnv} {a : AttesterMultiOuterArrayInitState} - {n : Nat} {b : AttesterMultiRevokeInnerArrayInitState} - (hInv : attesterMultiRevokeInnerInitReadInv I a n b) : - attesterMultiRevokeOuterInitFreeInv I 0 a := - hInv.1 - -theorem attesterMultiRevokeInnerInitReadInv_remaining - {I : ExecutionEnv} {a : AttesterMultiOuterArrayInitState} - {n : Nat} {b : AttesterMultiRevokeInnerArrayInitState} - (hInv : attesterMultiRevokeInnerInitReadInv I a n b) : - b.remaining = UInt256.ofNat (n + 1) := - hInv.2.1 - -theorem attesterMultiRevokeInnerInitReadInv_bound - {I : ExecutionEnv} {a : AttesterMultiOuterArrayInitState} - {n : Nat} {b : AttesterMultiRevokeInnerArrayInitState} - (hInv : attesterMultiRevokeInnerInitReadInv I a n b) : - n + 1 < UInt256.size := - hInv.2.2.1 - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevokeInnerInitReadInv_init - {I : ExecutionEnv} {a : AttesterMultiOuterArrayInitState} - (hOuter : attesterMultiRevokeOuterInitFreeInv I 0 a) - (hlenNe : (attesterFirstInnerArrayLengthWord I).toNat ≠ 0) - (hlenMax : (attesterFirstInnerArrayLengthWord I).toNat ≤ solcMaxU64) : - attesterMultiRevokeInnerInitReadInv I a - ((attesterFirstInnerArrayLengthWord I).toNat - 1) - { slot := - ((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)), - remaining := attesterFirstInnerArrayLengthWord I, - mem := - attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a), - aw := - attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a) } := by - let base := - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a) - let len := attesterFirstInnerArrayLengthWord I - rcases hOuter with - ⟨harem, habound, hale, hawGe, hawMul, hbaseGe, hbase160, hbaseBound, hbaseSpare, - hslotGe, hslot160, hslotBound, hslotSpare, houterRead128, houterMem128, - _houterFreeExact⟩ - let oldFree := attesterMultiOuterArrayInitFreeWord a.mem a.aw - have holdFreeGe : 64 + 32 ≤ oldFree.toNat := by - simpa [oldFree] using hbaseGe - have holdFree160 : 128 + 32 ≤ oldFree.toNat := by - simpa [oldFree] using hbase160 - have holdFreeBound : oldFree.toNat + 64 < UInt256.size := by - simpa [oldFree] using hbaseBound - have holdFreeSpare : oldFree.toNat + 64 + 160 + 160 * solcMaxU64 < - UInt256.size := by - simpa [oldFree] using hbaseSpare - have houterFree95 : oldFree.toNat + 95 < UInt256.size := by - omega - have houterSlot63 : a.slot.toNat + 63 < UInt256.size := by - omega - have houterStepAw := - attesterMultiOuterArrayInitStepAw_bounds - (slot := a.slot) (mem := a.mem) (aw := a.aw) - hawGe hawMul houterFree95 houterSlot63 - have holdFree32 : oldFree.toNat + 32 < UInt256.size := by - omega - have hoffsetToNat : - (attesterMultiOuterArrayInitOffsetWord a.mem a.aw).toNat = - oldFree.toNat + 32 := by - unfold attesterMultiOuterArrayInitOffsetWord oldFree - exact uadd_word_lit32_toNat - (attesterMultiOuterArrayInitFreeWord a.mem a.aw) holdFree32 - have hoffsetGe : - 64 + 32 ≤ (attesterMultiOuterArrayInitOffsetWord a.mem a.aw).toNat := by - rw [hoffsetToNat] - omega - have hfinalFreeToNat : - (attesterMultiOuterArrayInitFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).toNat = - oldFree.toNat + 64 := by - change - (attesterMultiOuterArrayInitFreeWord - (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw) - (attesterMultiOuterArrayInitStepAw a.slot a.mem a.aw)).toNat = - oldFree.toNat + 64 - exact attesterMultiOuterArrayInitStep_freeWord_toNat - (slot := a.slot) (mem := a.mem) (aw := a.aw) - holdFreeGe hoffsetGe hslotGe - houterStepAw.2 houterStepAw.1 holdFreeBound - have hbase63 : base.toNat + 63 < UInt256.size := by - unfold base attesterInnerArrayAllocFreeWord - rw [hfinalFreeToNat] - omega - have hbaseFinalGe : 64 + 32 ≤ base.toNat := by - unfold base attesterInnerArrayAllocFreeWord - rw [hfinalFreeToNat] - omega - have hbaseFinal160 : 128 + 32 ≤ base.toNat := by - unfold base attesterInnerArrayAllocFreeWord - rw [hfinalFreeToNat] - omega - have hoffset160 : - 128 + 32 ≤ (attesterMultiOuterArrayInitOffsetWord a.mem a.aw).toNat := by - rw [hoffsetToNat] - omega - have houterFinalRead128 : - (attesterMultiOuterArrayInitFinalMem a).readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) := by - change - (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw).readWithPadding - 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) - simpa using - (attesterMultiOuterArrayInitStep_readWithPadding_nat - (base := (⟨128⟩ : UInt256)) (slot := a.slot) - (len := attesterFirstArrayLengthWord I) (mem := a.mem) (aw := a.aw) - (by simpa using houterMem128) - (by simpa using houterRead128) - (by decide) - (by simpa using hbase160) - (by simpa using hoffset160) - (by simpa using hslot160)) - have houterFinalMem128 : - 128 + 32 ≤ (attesterMultiOuterArrayInitFinalMem a).size := by - change 128 + 32 ≤ - (attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw).size - exact le_trans houterMem128 attesterMultiOuterArrayInitStep_size_ge - have hallocAw := - attesterInnerArrayAllocAw_bounds - (len := len) - (mem := attesterMultiOuterArrayInitFinalMem a) - (aw := attesterMultiOuterArrayInitFinalAw a) - (by - simpa [attesterMultiOuterArrayInitFinalAw] using houterStepAw.1) - (by - simpa [attesterMultiOuterArrayInitFinalAw] using houterStepAw.2) - hbase63 - have hallocBound : base.toNat + 32 + 32 * len.toNat < UInt256.size := by - unfold base len attesterInnerArrayAllocFreeWord - rw [hfinalFreeToNat] - have hmul : 32 * (attesterFirstInnerArrayLengthWord I).toNat ≤ - 160 * solcMaxU64 := by - have h32 : 32 * (attesterFirstInnerArrayLengthWord I).toNat ≤ - 32 * solcMaxU64 := Nat.mul_le_mul_left 32 hlenMax - nlinarith - norm_num [solcMaxU64, UInt256.size] at hmul holdFreeSpare ⊢ - omega - have hallocFreeToNat : - (attesterInnerArrayAllocFreeWord - (attesterInnerArrayAllocMem len - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)) - (attesterInnerArrayAllocAw len - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a))).toNat = - base.toNat + 32 + 32 * len.toNat := by - unfold base - exact attesterInnerArrayAllocMem_freeWord_toNat - (len := len) - (mem := attesterMultiOuterArrayInitFinalMem a) - (aw := attesterMultiOuterArrayInitFinalAw a) - hallocAw.2 hallocAw.1 hallocBound - have hslotToNat : - (((⟨32⟩ : UInt256) + base).toNat) = base.toNat + 32 := by - exact uadd_lit32_toNat base (by omega) - have hallocRead128 : - (attesterInnerArrayAllocMem len - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) := by - simpa using - (attesterInnerArrayAllocMem_readWithPadding_at_nat - (readBase := (⟨128⟩ : UInt256)) (len := len) - (readLen := attesterFirstArrayLengthWord I) - (mem := attesterMultiOuterArrayInitFinalMem a) - (aw := attesterMultiOuterArrayInitFinalAw a) - (by simpa using houterFinalMem128) - (by simpa using houterFinalRead128) - (by decide) - (by simpa [base] using hbaseFinal160)) - have hallocMem128 : - 128 + 32 ≤ - (attesterInnerArrayAllocMem len - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).size := - le_trans houterFinalMem128 attesterInnerArrayAllocMem_size_ge - have hlenSucc : len.toNat - 1 + 1 = len.toNat := by - unfold len - omega - unfold attesterMultiRevokeInnerInitReadInv - simp only - refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · exact ⟨harem, habound, hale, hawGe, hawMul, hbaseGe, hbase160, hbaseBound, hbaseSpare, - hslotGe, hslot160, hslotBound, hslotSpare, houterRead128, houterMem128, - _houterFreeExact⟩ - · simpa [len, hlenSucc] using (u256_ofNat_toNat len).symm - · rw [hlenSucc] - exact len.val.isLt - · simpa [len] using hallocAw.1 - · simpa [len] using hallocAw.2 - · exact attesterInnerArrayAllocMem_readWithPadding_len_nat - (len := len) - (mem := attesterMultiOuterArrayInitFinalMem a) - (aw := attesterMultiOuterArrayInitFinalAw a) - hbaseFinalGe - · exact attesterInnerArrayAllocMem_base_size - (len := len) - (mem := attesterMultiOuterArrayInitFinalMem a) - (aw := attesterMultiOuterArrayInitFinalAw a) - · exact hbaseFinalGe - · rw [hallocFreeToNat] - exact Nat.le_add_right _ _ - · change - (attesterInnerArrayAllocFreeWord - (attesterInnerArrayAllocMem len - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)) - (attesterInnerArrayAllocAw len - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a))).toNat + - 64 * (len.toNat - 1 + 1) < - UInt256.size - rw [hallocFreeToNat, hlenSucc] - unfold base len attesterInnerArrayAllocFreeWord - rw [hfinalFreeToNat] - have hmul : 96 * (attesterFirstInnerArrayLengthWord I).toNat ≤ - 160 * solcMaxU64 := by - have h96 : 96 * (attesterFirstInnerArrayLengthWord I).toNat ≤ - 96 * solcMaxU64 := Nat.mul_le_mul_left 96 hlenMax - exact le_trans h96 - (Nat.mul_le_mul_right solcMaxU64 (by norm_num : 96 ≤ 160)) - norm_num [solcMaxU64, UInt256.size] at hmul holdFreeSpare ⊢ - omega - · change - (attesterInnerArrayAllocFreeWord - (attesterInnerArrayAllocMem len - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)) - (attesterInnerArrayAllocAw len - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a))).toNat + - 64 * (len.toNat - 1 + 1) + 64 * len.toNat + 96 < - UInt256.size - rw [hallocFreeToNat, hlenSucc] - unfold base len attesterInnerArrayAllocFreeWord - rw [hfinalFreeToNat] - have hmul : 160 * (attesterFirstInnerArrayLengthWord I).toNat ≤ - 160 * solcMaxU64 := - Nat.mul_le_mul_left 160 hlenMax - norm_num [solcMaxU64, UInt256.size] at hmul holdFreeSpare ⊢ - omega - · rw [hslotToNat] - · change (((⟨32⟩ : UInt256) + base).toNat) + - 32 * (len.toNat - 1 + 1) + 63 < UInt256.size - rw [hslotToNat, hlenSucc] - unfold base len attesterInnerArrayAllocFreeWord - rw [hfinalFreeToNat] - have hmul : 32 * (attesterFirstInnerArrayLengthWord I).toNat ≤ - 160 * solcMaxU64 := by - have h32 : 32 * (attesterFirstInnerArrayLengthWord I).toNat ≤ - 32 * solcMaxU64 := Nat.mul_le_mul_left 32 hlenMax - exact le_trans h32 - (Nat.mul_le_mul_right solcMaxU64 (by norm_num : 32 ≤ 160)) - norm_num [solcMaxU64, UInt256.size] at hmul holdFreeSpare ⊢ - omega - · rw [hfinalFreeToNat] - have hmul : 32 * (attesterFirstInnerArrayLengthWord I).toNat ≤ - 160 * solcMaxU64 := by - have h32 : 32 * (attesterFirstInnerArrayLengthWord I).toNat ≤ - 32 * solcMaxU64 := Nat.mul_le_mul_left 32 hlenMax - exact le_trans h32 - (Nat.mul_le_mul_right solcMaxU64 (by norm_num : 32 ≤ 160)) - norm_num [solcMaxU64, UInt256.size] at hmul holdFreeSpare ⊢ - omega - · exact hallocRead128 - · exact hallocMem128 - · exact hbaseFinal160 - -theorem attesterMultiRevokeInnerInitReadInv_step - {I : ExecutionEnv} {a : AttesterMultiOuterArrayInitState} - {n : Nat} {b : AttesterMultiRevokeInnerArrayInitState} - (hInv : attesterMultiRevokeInnerInitReadInv I a (n + 1) b) : - attesterMultiRevokeInnerInitReadInv I a n - (attesterMultiRevokeInnerArrayInitStepState b) := by - let base := - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a) - let len := attesterFirstInnerArrayLengthWord I - rcases hInv with - ⟨hOuter, hrem, hbound, hawGe, hawMul, hread, hmem, hbaseGe, hfreeGe, - hfreeBound, hfreeSpare, hslotGe, hslotBound, hbaseSlot63, hread128, - hmem128, hbase160⟩ - have hfree63 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 63 < UInt256.size := by - have hmul : 63 ≤ 64 * ((n + 1) + 1) := by nlinarith - omega - have hfree32 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 32 < UInt256.size := by - omega - have hsecondToNat : - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat = - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 32 := - attesterMultiRevokeInnerArrayInitSecondZeroWord_toNat - (mem := b.mem) (aw := b.aw) hfree32 - have hsecondGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - rw [hsecondToNat] - exact le_trans hfreeGe (Nat.le_add_right _ _) - have hfree160 : - 128 + 32 ≤ (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat := by - omega - have hsecond160 : - 128 + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - rw [hsecondToNat] - omega - have hslot160 : 128 + 32 ≤ b.slot.toNat := by - omega - have hfree160 : - 128 + 32 ≤ (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat := by - omega - have hsecond160 : - 128 + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - rw [hsecondToNat] - omega - have hslot160 : 128 + 32 ≤ b.slot.toNat := by - omega - have hsecond63 : - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat + 63 < - UInt256.size := by - rw [hsecondToNat] - have hmul : 95 ≤ 64 * ((n + 1) + 1) := by nlinarith - omega - have hslot63 : b.slot.toNat + 63 < UInt256.size := by - have hmul : 63 ≤ 32 * ((n + 1) + 1) := by nlinarith - omega - have hawStep := - attesterMultiRevokeInnerArrayInitStepAw_bounds - (slot := b.slot) (mem := b.mem) (aw := b.aw) - hawGe hawMul hfree63 hsecond63 hslot63 - have hreadStep : - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := - attesterMultiRevokeInnerArrayInitStep_readWithPadding_nat - (base := base) (slot := b.slot) (len := len) (mem := b.mem) (aw := b.aw) - hmem hread hbaseGe hfreeGe hsecondGe hslotGe - have hmemStep : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).size := - attesterMultiRevokeInnerArrayInitStep_base_size - (base := base) (slot := b.slot) (len := len) (mem := b.mem) (aw := b.aw) - hmem - have hread128Step : - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).readWithPadding - 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) := by - simpa using - (attesterMultiRevokeInnerArrayInitStep_readWithPadding_nat - (base := (⟨128⟩ : UInt256)) (slot := b.slot) - (len := attesterFirstArrayLengthWord I) (mem := b.mem) (aw := b.aw) - (by simpa using hmem128) - (by simpa using hread128) - (by decide) - (by simpa using hfree160) - (by simpa using hsecond160) - (by simpa using hslot160)) - have hmem128Step : - 128 + 32 ≤ (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).size := - le_trans hmem128 attesterMultiRevokeInnerArrayInitStep_size_ge - have hfree96 : - 64 + 32 ≤ (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat := by - omega - have hsecond96 : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - omega - have hslot96 : 64 + 32 ≤ b.slot.toNat := by - omega - have hfree64 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 64 < - UInt256.size := by - omega - have hfreeStepToNat : - (attesterMultiOuterArrayInitFreeWord - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw) - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw)).toNat = - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 64 := - attesterMultiRevokeInnerArrayInitStep_freeWord_toNat - (slot := b.slot) (mem := b.mem) (aw := b.aw) - hfree96 hsecond96 hslot96 hawStep.2 hawStep.1 hfree64 - have hslot32 : b.slot.toNat + 32 < UInt256.size := by - omega - have hslotStepToNat : (((⟨32⟩ : UInt256) + b.slot).toNat) = - b.slot.toNat + 32 := - uadd_lit32_toNat b.slot hslot32 - unfold attesterMultiRevokeInnerInitReadInv - simp only - constructor - · exact hOuter - · constructor - · change UInt256.sub b.remaining (⟨1⟩ : UInt256) = UInt256.ofNat (n + 1) - rw [hrem] - simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using - attester_u256_ofNat_succ_sub_one (n := n + 1) hbound - · constructor - · omega - · constructor - · simpa [attesterMultiRevokeInnerArrayInitStepState] using hawStep.1 - · constructor - · simpa [attesterMultiRevokeInnerArrayInitStepState] using hawStep.2 - · constructor - · simpa [base, len, attesterMultiRevokeInnerArrayInitStepState] using hreadStep - · constructor - · simpa [base, attesterMultiRevokeInnerArrayInitStepState] using hmemStep - · constructor - · exact hbaseGe - · constructor - · change base.toNat + 32 ≤ - (attesterMultiOuterArrayInitFreeWord - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw) - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw)).toNat - rw [hfreeStepToNat] - omega - · constructor - · change - (attesterMultiOuterArrayInitFreeWord - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw) - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw)).toNat + - 64 * (n + 1) < - UInt256.size - rw [hfreeStepToNat] - omega - · constructor - · change - (attesterMultiOuterArrayInitFreeWord - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw) - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw)).toNat + - 64 * (n + 1) + 64 * len.toNat + 96 < - UInt256.size - rw [hfreeStepToNat] - have hfreeSpareLen : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + - 64 * ((n + 1) + 1) + 64 * len.toNat + 96 < - UInt256.size := by - simpa [len] using hfreeSpare - omega - · constructor - · change base.toNat + 32 ≤ (((⟨32⟩ : UInt256) + b.slot).toNat) - rw [hslotStepToNat] - exact le_trans hslotGe (Nat.le_add_right _ _) - · constructor - · change (((⟨32⟩ : UInt256) + b.slot).toNat) + - 32 * (n + 1) + 63 < - UInt256.size - rw [hslotStepToNat] - omega - · constructor - · exact hbaseSlot63 - · constructor - · simpa [attesterMultiRevokeInnerArrayInitStepState] - using hread128Step - · constructor - · simpa [attesterMultiRevokeInnerArrayInitStepState] - using hmem128Step - · exact hbase160 - -theorem attesterX_multiRevokeFirstInnerArrayInitProgressWithReadInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (hlenNe : attesterFirstInnerArrayLengthWord I ≠ ⟨0⟩) - (hlenMax : (attesterFirstInnerArrayLengthWord I).toNat ≤ solcMaxU64) - (hprogress : - ∃ a' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨475⟩ : UInt256) - (((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) :: - attesterFirstInnerArrayLengthWord I :: - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') :: - ⟨0⟩ :: - attesterFirstInnerArrayLengthWord I :: - attesterFirstInnerArrayLengthWord I :: - (attesterFirstInnerArrayStartWord I + ⟨32⟩) :: - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I]) - (attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - ByteArray.empty (cA, σ) k C) : - ∃ a' b' k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeInnerInitReadInv I a' 0 b' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (attesterMultiRevokeInnerArrayInitExitStack I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - b') - (attesterMultiRevokeInnerArrayInitFinalMem b') - (attesterMultiRevokeInnerArrayInitFinalAw b') - ByteArray.empty (cA, σ) k C := by - obtain ⟨a', k0, C0, hrem, hOuter, rd0⟩ := hprogress - have hlenNatNe : (attesterFirstInnerArrayLengthWord I).toNat ≠ 0 := by - intro hzero - apply hlenNe - apply u256_inj - simpa using hzero - obtain ⟨b', k1, C1, hbrem, hInv, rd1⟩ := - attesterX_multiRevokeInnerArrayInitLoopWithStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (Inv := attesterMultiRevokeInnerInitReadInv I a') - (slot := - ((⟨32⟩ : UInt256) + - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a'))) - (base := - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (len := attesterFirstInnerArrayLengthWord I) - (payload := attesterFirstInnerArrayStartWord I + ⟨32⟩) - (mem := - attesterInnerArrayAllocMem - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (aw := - attesterInnerArrayAllocAw - (attesterFirstInnerArrayLengthWord I) - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (k := k0) (C := C0) - (fun n b hInv => attesterMultiRevokeInnerInitReadInv_remaining hInv) - (fun n b hInv => attesterMultiRevokeInnerInitReadInv_bound hInv) - (fun n b hInv => attesterMultiRevokeInnerInitReadInv_step hInv) - (attesterMultiRevokeInnerInitReadInv_init - (I := I) (a := a') hOuter hlenNatNe hlenMax) - (by simpa using rd0) - exact ⟨a', b', k1, C1, hrem, hOuter, hbrem, hInv, rd1⟩ - -structure attesterMultiRevokeInnerCopyReadInv - (I : ExecutionEnv) (a : AttesterMultiOuterArrayInitState) - (b : AttesterMultiRevokeInnerArrayInitState) - (n : Nat) (s : AttesterMultiRevokeInnerArrayCopyState) : Prop where - init : attesterMultiRevokeInnerInitReadInv I a 0 b - idx : - s.idx = - UInt256.ofNat ((attesterFirstInnerArrayLengthWord I).toNat - n) - le : n ≤ (attesterFirstInnerArrayLengthWord I).toNat - awGe : 3 ≤ s.aw.toNat - awMul : s.aw.toNat * 32 < UInt256.size - read : - s.mem.readWithPadding - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).toNat 32 = - UInt256.toByteArray (attesterFirstInnerArrayLengthWord I) - memSize : - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).toNat + 32 ≤ s.mem.size - baseGe : - 64 + 32 ≤ - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).toNat - base63 : - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).toNat + 63 < UInt256.size - freeGe : - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat - freeSpare : - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + - 64 * n + 96 < UInt256.size - zeroGe : - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord s.mem s.aw).toNat - slotGe : - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)) s.idx).toNat - slot63 : - (attesterMultiRevokeInnerArrayCopySlotWord - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)) s.idx).toNat + 63 < - UInt256.size - outerRead : - s.mem.readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) - outerMemSize : 128 + 32 ≤ s.mem.size - base160 : - 128 + 32 ≤ - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)).toNat - -theorem attesterMultiRevokeInnerCopyReadInv_idx - {I : ExecutionEnv} {a : AttesterMultiOuterArrayInitState} - {b : AttesterMultiRevokeInnerArrayInitState} - {n : Nat} {s : AttesterMultiRevokeInnerArrayCopyState} - (hInv : attesterMultiRevokeInnerCopyReadInv I a b n s) : - s.idx = - UInt256.ofNat ((attesterFirstInnerArrayLengthWord I).toNat - n) := by - exact hInv.idx - -theorem attesterMultiRevokeInnerCopyReadInv_le - {I : ExecutionEnv} {a : AttesterMultiOuterArrayInitState} - {b : AttesterMultiRevokeInnerArrayInitState} - {n : Nat} {s : AttesterMultiRevokeInnerArrayCopyState} - (hInv : attesterMultiRevokeInnerCopyReadInv I a b n s) : - n ≤ (attesterFirstInnerArrayLengthWord I).toNat := by - exact hInv.le - -theorem attesterMultiRevokeInnerArrayCopyNextIdx_ofNat_progress - {len n : Nat} - (hle : n + 1 ≤ len) (hlen : len < UInt256.size) : - attesterMultiRevokeInnerArrayCopyNextIdx - (UInt256.ofNat (len - (n + 1))) = - UInt256.ofNat (len - n) := by - apply u256_inj - unfold attesterMultiRevokeInnerArrayCopyNextIdx - rw [uadd_toNat] - rw [show (⟨1⟩ : UInt256).toNat = 1 by decide] - rw [ulit_toNat' (len - (n + 1)) (by omega)] - rw [ulit_toNat' (len - n) (by omega)] - have hsum : 1 + (len - (n + 1)) = len - n := by omega - rw [hsum] - exact Nat.mod_eq_of_lt (by omega) - -def attesterMultiRevokeInnerCopyInitState - (b : AttesterMultiRevokeInnerArrayInitState) : - AttesterMultiRevokeInnerArrayCopyState := - { idx := (⟨0⟩ : UInt256), - mem := attesterMultiRevokeInnerArrayInitFinalMem b, - aw := attesterMultiRevokeInnerArrayInitFinalAw b } - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevokeInnerCopyReadInv_init - {I : ExecutionEnv} {a : AttesterMultiOuterArrayInitState} - {b : AttesterMultiRevokeInnerArrayInitState} - (hInv : attesterMultiRevokeInnerInitReadInv I a 0 b) : - attesterMultiRevokeInnerCopyReadInv I a b - (attesterFirstInnerArrayLengthWord I).toNat - (attesterMultiRevokeInnerCopyInitState b) := by - let base := - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a) - let len := attesterFirstInnerArrayLengthWord I - have hInvOrig := hInv - rcases hInv with - ⟨hOuter, hrem, hbound, hawGe, hawMul, hread, hmem, hbaseGe, hfreeGe, - hfreeBound, hfreeSpare, hslotGe, hslotBound, hbaseSlot63, hread128, - hmem128, hbase160⟩ - have hfree63 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 63 < - UInt256.size := by - omega - have hfree32 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 32 < - UInt256.size := by - omega - have hsecondToNat : - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat = - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 32 := - attesterMultiRevokeInnerArrayInitSecondZeroWord_toNat - (mem := b.mem) (aw := b.aw) hfree32 - have hsecondGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - rw [hsecondToNat] - exact le_trans hfreeGe (Nat.le_add_right _ _) - have hfree160 : - 128 + 32 ≤ (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat := by - omega - have hsecond160 : - 128 + 32 ≤ - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - rw [hsecondToNat] - omega - have hslot160 : 128 + 32 ≤ b.slot.toNat := by - omega - have hsecond63 : - (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat + 63 < - UInt256.size := by - rw [hsecondToNat] - omega - have hslot63 : b.slot.toNat + 63 < UInt256.size := by - omega - have hawStep := - attesterMultiRevokeInnerArrayInitStepAw_bounds - (slot := b.slot) (mem := b.mem) (aw := b.aw) - hawGe hawMul hfree63 hsecond63 hslot63 - have hreadStep : - (attesterMultiRevokeInnerArrayInitFinalMem b).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := by - change - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len - exact attesterMultiRevokeInnerArrayInitStep_readWithPadding_nat - (base := base) (slot := b.slot) (len := len) (mem := b.mem) (aw := b.aw) - hmem hread hbaseGe hfreeGe hsecondGe hslotGe - have hmemStep : - base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayInitFinalMem b).size := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).size - exact attesterMultiRevokeInnerArrayInitStep_base_size - (base := base) (slot := b.slot) (len := len) (mem := b.mem) (aw := b.aw) - hmem - have hread128Step : - (attesterMultiRevokeInnerArrayInitFinalMem b).readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) := by - change - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).readWithPadding - 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) - simpa using - (attesterMultiRevokeInnerArrayInitStep_readWithPadding_nat - (base := (⟨128⟩ : UInt256)) (slot := b.slot) - (len := attesterFirstArrayLengthWord I) (mem := b.mem) (aw := b.aw) - (by simpa using hmem128) - (by simpa using hread128) - (by decide) - (by simpa using hfree160) - (by simpa using hsecond160) - (by simpa using hslot160)) - have hmem128Step : - 128 + 32 ≤ (attesterMultiRevokeInnerArrayInitFinalMem b).size := by - change 128 + 32 ≤ - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw).size - exact le_trans hmem128 attesterMultiRevokeInnerArrayInitStep_size_ge - have hfree96 : - 64 + 32 ≤ (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat := by - omega - have hsecond96 : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayInitSecondZeroWord b.mem b.aw).toNat := by - omega - have hslot96 : 64 + 32 ≤ b.slot.toNat := by - omega - have hfree64 : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 64 < - UInt256.size := by - omega - have hfreeStepToNat : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat = - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 64 := by - change - (attesterMultiOuterArrayInitFreeWord - (attesterMultiRevokeInnerArrayInitStepMem b.slot b.mem b.aw) - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw)).toNat = - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + 64 - exact attesterMultiRevokeInnerArrayInitStep_freeWord_toNat - (slot := b.slot) (mem := b.mem) (aw := b.aw) - hfree96 hsecond96 hslot96 hawStep.2 hawStep.1 hfree64 - have hfreeFinalGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat := by - rw [hfreeStepToNat] - omega - have hfreeFinalSpare : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat + - 64 * len.toNat + 96 < UInt256.size := by - rw [hfreeStepToNat] - have hfreeSpareLen : - (attesterMultiOuterArrayInitFreeWord b.mem b.aw).toNat + - 64 * (0 + 1) + 64 * len.toNat + 96 < - UInt256.size := by - simpa [len] using hfreeSpare - omega - have hfreeFinal63 : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat + 63 < - UInt256.size := by - omega - have hfreeFinal32 : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat + 32 < - UInt256.size := by - omega - have hzeroToNat : - (attesterMultiRevokeInnerArrayCopyZeroWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat + 32 := - attesterMultiRevokeInnerArrayCopyZeroWord_toNat hfreeFinal32 - have hzeroGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat := by - rw [hzeroToNat] - exact le_trans hfreeFinalGe (Nat.le_add_right _ _) - have hzero63 : - (attesterMultiRevokeInnerArrayCopyZeroWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat + 63 < - UInt256.size := by - rw [hzeroToNat] - omega - have hbase63 : base.toNat + 63 < UInt256.size := by - omega - have hslot0Bound : - base.toNat + 32 + 32 * (⟨0⟩ : UInt256).toNat + 63 < UInt256.size := by - change base.toNat + 32 + 32 * 0 + 63 < UInt256.size - omega - have hslot0ToNat : - (attesterMultiRevokeInnerArrayCopySlotWord base (⟨0⟩ : UInt256)).toNat = - base.toNat + 32 + 32 * (⟨0⟩ : UInt256).toNat := - attesterMultiRevokeInnerArrayCopySlotWord_toNat (by omega) - have hslot0Ge : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base (⟨0⟩ : UInt256)).toNat := - attesterMultiRevokeInnerArrayCopySlotWord_above_base (by omega) - have hslot0_63 : - (attesterMultiRevokeInnerArrayCopySlotWord base (⟨0⟩ : UInt256)).toNat + 63 < - UInt256.size := by - rw [hslot0ToNat] - omega - have hidx0 : - (⟨0⟩ : UInt256) = UInt256.ofNat (len.toNat - len.toNat) := by - rw [show len.toNat - len.toNat = 0 by omega] - apply u256_inj - rfl - exact - { init := hInvOrig - idx := by simpa [len] using hidx0 - le := le_rfl - awGe := by - change 3 ≤ (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw).toNat - exact hawStep.1 - awMul := by - change - (attesterMultiRevokeInnerArrayInitStepAw b.slot b.mem b.aw).toNat * 32 < - UInt256.size - exact hawStep.2 - read := by - change - (attesterMultiRevokeInnerArrayInitFinalMem b).readWithPadding - base.toNat 32 = - UInt256.toByteArray len - exact hreadStep - memSize := by - change base.toNat + 32 ≤ (attesterMultiRevokeInnerArrayInitFinalMem b).size - exact hmemStep - baseGe := by - change 64 + 32 ≤ base.toNat - exact hbaseGe - base63 := by - change base.toNat + 63 < UInt256.size - exact hbase63 - freeGe := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat - exact hfreeFinalGe - freeSpare := by - change - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat + - 64 * len.toNat + 96 < - UInt256.size - exact hfreeFinalSpare - zeroGe := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord - (attesterMultiRevokeInnerArrayInitFinalMem b) - (attesterMultiRevokeInnerArrayInitFinalAw b)).toNat - exact hzeroGe - slotGe := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base (⟨0⟩ : UInt256)).toNat - exact hslot0Ge - slot63 := by - change - (attesterMultiRevokeInnerArrayCopySlotWord base (⟨0⟩ : UInt256)).toNat + 63 < - UInt256.size - exact hslot0_63 - outerRead := by - change (attesterMultiRevokeInnerArrayInitFinalMem b).readWithPadding 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) - exact hread128Step - outerMemSize := by - change 128 + 32 ≤ (attesterMultiRevokeInnerArrayInitFinalMem b).size - exact hmem128Step - base160 := by - change 128 + 32 ≤ base.toNat - exact hbase160 } - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevokeInnerCopyReadInv_step - {I : ExecutionEnv} {a : AttesterMultiOuterArrayInitState} - {b : AttesterMultiRevokeInnerArrayInitState} - {n : Nat} {s : AttesterMultiRevokeInnerArrayCopyState} - (hInv : attesterMultiRevokeInnerCopyReadInv I a b (n + 1) s) : - attesterMultiRevokeInnerCopyReadInv I a b n - (attesterMultiRevokeInnerArrayCopyStepState I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) s) := by - let base := - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a) - let len := attesterFirstInnerArrayLengthWord I - let payload := attesterFirstInnerArrayStartWord I + ⟨32⟩ - have hInit := hInv.init - rcases hInit with - ⟨_hOuter, _hrem, _hbound, _hawGeInit, _hawMulInit, _hreadInit, _hmemInit, - _hbaseGeInit, _hfreeGeInit, _hfreeBoundInit, _hfreeSpareInit, _hslotGeInit, - _hslotBoundInit, hbaseSlot63, _hread128Init, _hmem128Init, _hbase160Init⟩ - have hbaseGe' : 64 + 32 ≤ base.toNat := by - simpa [base] using hInv.baseGe - have hbase63' : base.toNat + 63 < UInt256.size := by - simpa [base] using hInv.base63 - have hfreeGe' : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat := by - simpa [base] using hInv.freeGe - have hzeroGe' : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord s.mem s.aw).toNat := by - simpa [base] using hInv.zeroGe - have hslotGe' : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base s.idx).toNat := by - simpa [base] using hInv.slotGe - have hslot63' : - (attesterMultiRevokeInnerArrayCopySlotWord base s.idx).toNat + 63 < - UInt256.size := by - simpa [base] using hInv.slot63 - have hbase160' : 128 + 32 ≤ base.toNat := by - simpa [base] using hInv.base160 - have hfree160' : - 128 + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat := by - omega - have hzero160' : - 128 + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord s.mem s.aw).toNat := by - omega - have hslot160' : - 128 + 32 ≤ (attesterMultiRevokeInnerArrayCopySlotWord base s.idx).toNat := by - omega - have hnextIdx : - attesterMultiRevokeInnerArrayCopyNextIdx s.idx = - UInt256.ofNat (len.toNat - n) := by - rw [hInv.idx] - exact attesterMultiRevokeInnerArrayCopyNextIdx_ofNat_progress - (len := len.toNat) (n := n) hInv.le len.val.isLt - have hnextIdxToNat : - (attesterMultiRevokeInnerArrayCopyNextIdx s.idx).toNat = len.toNat - n := by - rw [hnextIdx] - exact ulit_toNat' (len.toNat - n) - (lt_of_le_of_lt (Nat.sub_le _ _) len.val.isLt) - have hfree63 : - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 63 < - UInt256.size := by - have hspare := hInv.freeSpare - omega - have hfree32 : - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 32 < - UInt256.size := by - have hspare := hInv.freeSpare - omega - have hzeroToNat : - (attesterMultiRevokeInnerArrayCopyZeroWord s.mem s.aw).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 32 := - attesterMultiRevokeInnerArrayCopyZeroWord_toNat hfree32 - have hzero63 : - (attesterMultiRevokeInnerArrayCopyZeroWord s.mem s.aw).toNat + 63 < - UInt256.size := by - rw [hzeroToNat] - have hspare := hInv.freeSpare - omega - have hawStep := - attesterMultiRevokeInnerArrayCopyStepAw_bounds - (I := I) (base := base) (payload := payload) (idx := s.idx) - (mem := s.mem) (aw := s.aw) - hInv.awGe hInv.awMul hbase63' hfree63 hzero63 hslot63' - have hreadStep : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len := - attesterMultiRevokeInnerArrayCopyStep_readWithPadding_nat - (I := I) (base := base) (payload := payload) (idx := s.idx) - (len := len) (mem := s.mem) (aw := s.aw) - (by simpa [base] using hInv.memSize) - (by simpa [base, len] using hInv.read) - hbaseGe' hfreeGe' hzeroGe' hslotGe' - have hmemStep : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).size := - attesterMultiRevokeInnerArrayCopyStep_base_size - (I := I) (base := base) (payload := payload) (idx := s.idx) - (mem := s.mem) (aw := s.aw) hInv.memSize - have hread128Step : - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).readWithPadding - 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) := by - simpa using - (attesterMultiRevokeInnerArrayCopyStep_readWithPadding_at_nat - (I := I) (readBase := (⟨128⟩ : UInt256)) - (base := base) (payload := payload) (idx := s.idx) - (len := attesterFirstArrayLengthWord I) (mem := s.mem) (aw := s.aw) - (by simpa using hInv.outerMemSize) - (by simpa using hInv.outerRead) - (by decide) - (by simpa using hfree160') - (by simpa using hzero160') - (by simpa using hslot160')) - have hmem128Step : - 128 + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).size := - le_trans hInv.outerMemSize attesterMultiRevokeInnerArrayCopyStep_size_ge - have hfree96 : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat := by - have hbase96 : 64 + 32 ≤ base.toNat + 32 := by omega - exact le_trans hbase96 hfreeGe' - have hzero96 : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopyZeroWord s.mem s.aw).toNat := by - have hbase96 : 64 + 32 ≤ base.toNat + 32 := by omega - exact le_trans hbase96 hzeroGe' - have hslot96 : - 64 + 32 ≤ (attesterMultiRevokeInnerArrayCopySlotWord base s.idx).toNat := by - have hbase96 : 64 + 32 ≤ base.toNat + 32 := by omega - exact le_trans hbase96 hslotGe' - have hfree64 : - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 64 < - UInt256.size := by - omega - have hfreeStepToNat : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 64 := - attesterMultiRevokeInnerArrayCopyStep_freeWord_toNat - (I := I) (base := base) (payload := payload) (idx := s.idx) - (mem := s.mem) (aw := s.aw) - hfree96 hzero96 hslot96 hawStep.2 hawStep.1 hfree64 - have hfreeStepGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat := by - rw [hfreeStepToNat] - exact le_trans hfreeGe' (Nat.le_add_right _ _) - have hfreeStepSpare : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat + - 64 * n + 96 < UInt256.size := by - rw [hfreeStepToNat] - have hspare := hInv.freeSpare - omega - have hfreeStep32 : - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat + - 32 < UInt256.size := by - omega - have hzeroStepToNat : - (attesterMultiRevokeInnerArrayCopyZeroWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat = - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat + - 32 := - attesterMultiRevokeInnerArrayCopyZeroWord_toNat hfreeStep32 - have hzeroStepGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat := by - rw [hzeroStepToNat] - exact le_trans hfreeStepGe (Nat.le_add_right _ _) - have hslotNextBound : - base.toNat + 32 + - 32 * (attesterMultiRevokeInnerArrayCopyNextIdx s.idx).toNat + 63 < - UInt256.size := by - rw [hnextIdxToNat] - have hbaseSlot63' : - base.toNat + 32 + 32 * len.toNat + 63 < UInt256.size := by - simpa [base, len] using hbaseSlot63 - have hleLen : 32 * (len.toNat - n) ≤ 32 * len.toNat := - Nat.mul_le_mul_left 32 (Nat.sub_le _ _) - omega - have hslotNextToNat : - (attesterMultiRevokeInnerArrayCopySlotWord base - (attesterMultiRevokeInnerArrayCopyNextIdx s.idx)).toNat = - base.toNat + 32 + - 32 * (attesterMultiRevokeInnerArrayCopyNextIdx s.idx).toNat := - attesterMultiRevokeInnerArrayCopySlotWord_toNat (by omega) - have hslotNextGe : - base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base - (attesterMultiRevokeInnerArrayCopyNextIdx s.idx)).toNat := - attesterMultiRevokeInnerArrayCopySlotWord_above_base (by omega) - have hslotNext63 : - (attesterMultiRevokeInnerArrayCopySlotWord base - (attesterMultiRevokeInnerArrayCopyNextIdx s.idx)).toNat + 63 < - UInt256.size := by - rw [hslotNextToNat] - exact hslotNextBound - exact - { init := hInv.init - idx := by - change attesterMultiRevokeInnerArrayCopyNextIdx s.idx = - UInt256.ofNat ((attesterFirstInnerArrayLengthWord I).toNat - n) - simpa [len] using hnextIdx - le := by - have hle := hInv.le - omega - awGe := by - change 3 ≤ (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw).toNat - exact hawStep.1 - awMul := by - change - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw).toNat * - 32 < - UInt256.size - exact hawStep.2 - read := by - change - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).readWithPadding - base.toNat 32 = - UInt256.toByteArray len - exact hreadStep - memSize := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).size - exact hmemStep - baseGe := by - change 64 + 32 ≤ base.toNat - exact hInv.baseGe - base63 := by - change base.toNat + 63 < UInt256.size - exact hInv.base63 - freeGe := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat - exact hfreeStepGe - freeSpare := by - change - (attesterMultiRevokeInnerArrayCopyFreeWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat + - 64 * n + 96 < UInt256.size - exact hfreeStepSpare - zeroGe := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopyZeroWord - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyStepAw I base payload s.idx s.mem s.aw)).toNat - exact hzeroStepGe - slotGe := by - change base.toNat + 32 ≤ - (attesterMultiRevokeInnerArrayCopySlotWord base - (attesterMultiRevokeInnerArrayCopyNextIdx s.idx)).toNat - exact hslotNextGe - slot63 := by - change - (attesterMultiRevokeInnerArrayCopySlotWord base - (attesterMultiRevokeInnerArrayCopyNextIdx s.idx)).toNat + 63 < - UInt256.size - exact hslotNext63 - outerRead := by - change - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).readWithPadding - 128 32 = - UInt256.toByteArray (attesterFirstArrayLengthWord I) - exact hread128Step - outerMemSize := by - change 128 + 32 ≤ - (attesterMultiRevokeInnerArrayCopyStepMem I base payload s.idx s.mem s.aw).size - exact hmem128Step - base160 := by - change 128 + 32 ≤ base.toNat - exact hbase160' } - -theorem attesterX_multiRevokeFirstInnerArrayCopyProgressWithStateInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (hprogress : - ∃ (a' : AttesterMultiOuterArrayInitState), - ∃ (b' : AttesterMultiRevokeInnerArrayInitState), - ∃ k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (attesterMultiRevokeInnerArrayInitExitStack I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - b') - (attesterMultiRevokeInnerArrayInitFinalMem b') - (attesterMultiRevokeInnerArrayInitFinalAw b') - ByteArray.empty (cA, σ) k C) - (Inv : - AttesterMultiOuterArrayInitState → - AttesterMultiRevokeInnerArrayInitState → Nat → - AttesterMultiRevokeInnerArrayCopyState → Prop) - (hidx : - ∀ a b n s, Inv a b n s → - s.idx = - UInt256.ofNat ((attesterFirstInnerArrayLengthWord I).toNat - n)) - (hle : - ∀ a b n s, Inv a b n s → - n ≤ (attesterFirstInnerArrayLengthWord I).toNat) - (hload : - ∀ a b n s, Inv a b n s → - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I - (attesterFirstInnerArrayStartWord I + ⟨32⟩) s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I - (attesterFirstInnerArrayStartWord I + ⟨32⟩) s.idx s.mem s.aw) - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)) = - attesterFirstInnerArrayLengthWord I) - (hstep : - ∀ a b n s, Inv a b (n + 1) s → - Inv a b n - (attesterMultiRevokeInnerArrayCopyStepState I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a) - (attesterMultiOuterArrayInitFinalAw a)) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) s)) - (hinit : - ∀ a b, - a.remaining = (⟨1⟩ : UInt256) → - b.remaining = (⟨1⟩ : UInt256) → - Inv a b (attesterFirstInnerArrayLengthWord I).toNat - { idx := (⟨0⟩ : UInt256), - mem := attesterMultiRevokeInnerArrayInitFinalMem b, - aw := attesterMultiRevokeInnerArrayInitFinalAw b }) : - ∃ (a' : AttesterMultiOuterArrayInitState), - ∃ (b' : AttesterMultiRevokeInnerArrayInitState), - ∃ (c' : AttesterMultiRevokeInnerArrayCopyState), - ∃ k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - c'.idx = attesterFirstInnerArrayLengthWord I ∧ - Inv a' b' 0 c' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨608⟩ : UInt256) - (attesterMultiRevokeInnerArrayCopyStack - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - c') - c'.mem c'.aw ByteArray.empty (cA, σ) k C := by - obtain ⟨a', b', k0, C0, harem, hbrem, rd0⟩ := hprogress - obtain ⟨c', k1, C1, hcidx, hInv, rd1⟩ := - attesterX_multiRevokeInnerArrayCopyLoopWithStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (len := attesterFirstInnerArrayLengthWord I) - (payload := attesterFirstInnerArrayStartWord I + ⟨32⟩) - (tail := [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I]) - (mem := attesterMultiRevokeInnerArrayInitFinalMem b') - (aw := attesterMultiRevokeInnerArrayInitFinalAw b') - (k := k0) (C := C0) (by simp) - (Inv := Inv a' b') (hidx a' b') (hle a' b') (hload a' b') - (hstep a' b') (hinit a' b' harem hbrem) - (by simpa [attesterMultiRevokeInnerArrayInitExitStack] using rd0) - exact ⟨a', b', c', k1, C1, harem, hbrem, hcidx, hInv, rd1⟩ - -set_option maxHeartbeats 1000000 in -theorem attesterX_multiRevokeFirstInnerArrayCopyProgressWithReadStateInvariant - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - (hprogress : - ∃ (a' : AttesterMultiOuterArrayInitState), - ∃ (b' : AttesterMultiRevokeInnerArrayInitState), - ∃ k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeInnerInitReadInv I a' 0 b' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨518⟩ : UInt256) - (attesterMultiRevokeInnerArrayInitExitStack I - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - b') - (attesterMultiRevokeInnerArrayInitFinalMem b') - (attesterMultiRevokeInnerArrayInitFinalAw b') - ByteArray.empty (cA, σ) k C) : - ∃ (a' : AttesterMultiOuterArrayInitState), - ∃ (b' : AttesterMultiRevokeInnerArrayInitState), - ∃ (c' : AttesterMultiRevokeInnerArrayCopyState), - ∃ k C, - a'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeOuterInitFreeInv I 0 a' ∧ - b'.remaining = (⟨1⟩ : UInt256) ∧ - attesterMultiRevokeInnerInitReadInv I a' 0 b' ∧ - c'.idx = attesterFirstInnerArrayLengthWord I ∧ - attesterMultiRevokeInnerCopyReadInv I a' b' 0 c' ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨608⟩ : UInt256) - (attesterMultiRevokeInnerArrayCopyStack - (attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a')) - (attesterFirstInnerArrayLengthWord I) - (attesterFirstInnerArrayStartWord I + ⟨32⟩) - [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - c') - c'.mem c'.aw ByteArray.empty (cA, σ) k C := by - obtain ⟨a', b', k0, C0, harem, hOuter, hbrem, hInit, rd0⟩ := hprogress - let base := - attesterInnerArrayAllocFreeWord - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - let len := attesterFirstInnerArrayLengthWord I - let payload := attesterFirstInnerArrayStartWord I + ⟨32⟩ - have hload : - ∀ n s, attesterMultiRevokeInnerCopyReadInv I a' b' n s → - attesterMloadWord - (attesterMultiRevokeInnerArrayCopyZeroMem I payload s.idx s.mem s.aw) - (attesterMultiRevokeInnerArrayCopyZeroAw I payload s.idx s.mem s.aw) - base = len := by - intro n s hInv - have hfree96 : - (attesterMultiRevokeInnerArrayCopyFreeWord s.mem s.aw).toNat + 96 < - UInt256.size := by - have hspare := hInv.freeSpare - omega - exact attesterMultiRevokeInnerArrayCopyZero_mloadLen_of_bounds_nat - (I := I) (base := base) (payload := payload) (idx := s.idx) - (len := len) (mem := s.mem) (aw := s.aw) - (by simpa [base] using hInv.memSize) - (by simpa [base, len] using hInv.read) - hInv.awGe hInv.awMul hfree96 - (by simpa [base] using hInv.baseGe) - (by simpa [base] using hInv.freeGe) - (by simpa [base] using hInv.zeroGe) - obtain ⟨c', k1, C1, hcidx, hCopyInv, rd1⟩ := - attesterX_multiRevokeInnerArrayCopyLoopWithStateInvariant - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := base) - (len := len) - (payload := payload) - (tail := [⟨0⟩, ⟨128⟩, - attesterFirstArrayLengthWord I, - attesterSecondArrayLengthWord I, - attesterSecondArrayPayloadStartWord I, - attesterFirstArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I]) - (mem := attesterMultiRevokeInnerArrayInitFinalMem b') - (aw := attesterMultiRevokeInnerArrayInitFinalAw b') - (k := k0) (C := C0) (by simp) - (Inv := attesterMultiRevokeInnerCopyReadInv I a' b') - (fun n s hInv => attesterMultiRevokeInnerCopyReadInv_idx hInv) - (fun n s hInv => attesterMultiRevokeInnerCopyReadInv_le hInv) - hload - (fun n s hInv => attesterMultiRevokeInnerCopyReadInv_step hInv) - (attesterMultiRevokeInnerCopyReadInv_init hInit) - (by - simpa [base, len, payload, attesterMultiRevokeInnerArrayInitExitStack] - using rd0) - exact ⟨a', b', c', k1, C1, harem, hOuter, hbrem, hInit, hcidx, hCopyInv, rd1⟩ - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/MultiSource.lean b/Benchmarks/EAS/Attester/MultiSource.lean deleted file mode 100644 index b74f9544..00000000 --- a/Benchmarks/EAS/Attester/MultiSource.lean +++ /dev/null @@ -1,1411 +0,0 @@ -import Benchmarks.EAS.Attester.InnerArrayEVM - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -def attesterRevocationDataValue (uid : Value) : Value := - .tuple [uid, .int 0] - -def attesterRevocationDataValues : List Value → List Value - | [] => [] - | uid :: rest => attesterRevocationDataValue uid :: attesterRevocationDataValues rest - -def attesterRevocationDataDefault : Value := - attesterRevocationDataValue (.fixedBytes bytes32Width (List.replicate 32 0)) - -/-- Source-side shape of the inner `data` array after the first `n` entries have been filled. -/ -def attesterRevocationDataPrefix : Nat → List Value → List Value - | _, [] => [] - | 0, _ :: rest => - attesterRevocationDataDefault :: attesterRevocationDataPrefix 0 rest - | n + 1, uid :: rest => - attesterRevocationDataValue uid :: attesterRevocationDataPrefix n rest - -theorem attesterRevocationDataPrefix_length (n : Nat) (uids : List Value) : - (attesterRevocationDataPrefix n uids).length = uids.length := by - induction uids generalizing n with - | nil => - cases n <;> simp [attesterRevocationDataPrefix] - | cons _ rest ih => - cases n <;> simp [attesterRevocationDataPrefix, ih] - -theorem attesterRevocationDataPrefix_zero (uids : List Value) : - attesterRevocationDataPrefix 0 uids = - List.replicate uids.length attesterRevocationDataDefault := by - induction uids with - | nil => simp [attesterRevocationDataPrefix] - | cons _ rest ih => - change attesterRevocationDataDefault :: attesterRevocationDataPrefix 0 rest = - List.replicate (rest.length + 1) attesterRevocationDataDefault - rw [ih] - rw [show (rest.length + 1) = Nat.succ rest.length by omega] - rfl - -theorem attesterRevocationDataPrefix_all (uids : List Value) : - attesterRevocationDataPrefix uids.length uids = - attesterRevocationDataValues uids := by - induction uids with - | nil => simp [attesterRevocationDataPrefix, attesterRevocationDataValues] - | cons _ rest ih => simp [attesterRevocationDataPrefix, attesterRevocationDataValues, ih] - -theorem attesterRevocationDataPrefix_update : - ∀ {uids : List Value} {n : Nat}, n < uids.length → - ∃ uid, - lookupNth? uids n = some uid ∧ - updateNth? (attesterRevocationDataPrefix n uids) n - (attesterRevocationDataValue uid) = - some (attesterRevocationDataPrefix (n + 1) uids) - | [], _, h => by simp at h - | uid :: _, 0, _ => by - exact ⟨uid, rfl, by simp [attesterRevocationDataPrefix, updateNth?]⟩ - | _ :: rest, n + 1, h => by - have hlt : n < rest.length := by - simpa using Nat.succ_lt_succ_iff.mp h - obtain ⟨uid, hlookup, hupdate⟩ := - attesterRevocationDataPrefix_update (uids := rest) (n := n) hlt - refine ⟨uid, ?_, ?_⟩ - · simpa [lookupNth?] using hlookup - · simp [attesterRevocationDataPrefix, updateNth?, hupdate] - -def attesterMultiRevokeRequestValue (schema : Value) (uids : List Value) : Value := - .tuple [schema, .array (attesterRevocationDataValues uids)] - -def attesterMultiRevokeRequestDefault : Value := - .tuple [.fixedBytes bytes32Width (List.replicate 32 0), .array []] - -def attesterMultiRevokeRequestValues : List Value → List Value → List Value - | schema :: schemas, .array uids :: uidss => - attesterMultiRevokeRequestValue schema uids :: - attesterMultiRevokeRequestValues schemas uidss - | _, _ => [] - -/-- Source-side shape of `multiRequests` after the first `n` outer entries have been filled. -/ -def attesterMultiRevokeRequestValuesPrefix : Nat → List Value → List Value → List Value - | _, [], _ => [] - | 0, _ :: schemas, [] => - attesterMultiRevokeRequestDefault :: - attesterMultiRevokeRequestValuesPrefix 0 schemas [] - | 0, _ :: schemas, _ :: schemaUids => - attesterMultiRevokeRequestDefault :: - attesterMultiRevokeRequestValuesPrefix 0 schemas schemaUids - | n + 1, schema :: schemas, .array uids :: schemaUids => - attesterMultiRevokeRequestValue schema uids :: - attesterMultiRevokeRequestValuesPrefix n schemas schemaUids - | n + 1, _ :: schemas, _ :: schemaUids => - attesterMultiRevokeRequestDefault :: - attesterMultiRevokeRequestValuesPrefix n schemas schemaUids - | n + 1, _ :: schemas, [] => - attesterMultiRevokeRequestDefault :: - attesterMultiRevokeRequestValuesPrefix n schemas [] - -theorem attesterMultiRevokeRequestValuesPrefix_length - (n : Nat) (schemas schemaUids : List Value) : - (attesterMultiRevokeRequestValuesPrefix n schemas schemaUids).length = - schemas.length := by - induction schemas generalizing n schemaUids with - | nil => - cases n <;> cases schemaUids <;> - simp [attesterMultiRevokeRequestValuesPrefix] - | cons _ schemas ih => - cases n <;> cases schemaUids with - | nil => - simp [attesterMultiRevokeRequestValuesPrefix, ih] - | cons head tail => - cases head <;> - simp [attesterMultiRevokeRequestValuesPrefix, ih] - -theorem attesterMultiRevokeRequestValuesPrefix_zero - (schemas schemaUids : List Value) : - attesterMultiRevokeRequestValuesPrefix 0 schemas schemaUids = - List.replicate schemas.length attesterMultiRevokeRequestDefault := by - induction schemas generalizing schemaUids with - | nil => - cases schemaUids <;> simp [attesterMultiRevokeRequestValuesPrefix] - | cons _ schemas ih => - cases schemaUids <;> - change attesterMultiRevokeRequestDefault :: - attesterMultiRevokeRequestValuesPrefix 0 schemas _ = - List.replicate (schemas.length + 1) attesterMultiRevokeRequestDefault - all_goals - rw [ih] - rw [show schemas.length + 1 = Nat.succ schemas.length by omega] - rfl - -theorem attesterMultiRevokeRequestValuesPrefix_update : - ∀ {schemas schemaUids : List Value} {n : Nat} {schema : Value} {uids : List Value}, - lookupNth? schemas n = some schema → - lookupNth? schemaUids n = some (.array uids) → - updateNth? (attesterMultiRevokeRequestValuesPrefix n schemas schemaUids) - n (attesterMultiRevokeRequestValue schema uids) = - some (attesterMultiRevokeRequestValuesPrefix (n + 1) schemas schemaUids) - | [], _, _, _, _, hschema, _ => by simp [lookupNth?] at hschema - | _ :: _, [], 0, _, _, _, huids => by simp [lookupNth?] at huids - | _ :: _, _ :: _, 0, _, _, hschema, huids => by - simp [lookupNth?] at hschema huids - cases hschema - cases huids - simp [attesterMultiRevokeRequestValuesPrefix, updateNth?] - | _ :: schemas, head :: schemaUids, n + 1, schema, uids, hschema, huids => by - have hschemaTail : lookupNth? schemas n = some schema := by - simpa [lookupNth?] using hschema - have huidsTail : lookupNth? schemaUids n = some (.array uids) := by - simpa [lookupNth?] using huids - have htail := - attesterMultiRevokeRequestValuesPrefix_update - (schemas := schemas) (schemaUids := schemaUids) (n := n) - (schema := schema) (uids := uids) hschemaTail huidsTail - cases head <;> - simp [attesterMultiRevokeRequestValuesPrefix, updateNth?, htail] - | _ :: schemas, [], n + 1, _, _, _, huids => by - simp [lookupNth?] at huids - -theorem attesterMultiRevokeRequestValuesPrefix_all : - ∀ {schemas schemaUids : List Value}, - schemaUids.length = schemas.length → - (∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, value = .array uids) → - attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids = - attesterMultiRevokeRequestValues schemas schemaUids - | [], [], _hlen, _hshape => by - simp [attesterMultiRevokeRequestValuesPrefix, attesterMultiRevokeRequestValues] - | [], _ :: _, hlen, _hshape => by - simp at hlen - | _ :: _, [], hlen, _hshape => by - simp at hlen - | schema :: schemas, value :: schemaUids, hlen, hshape => by - have htailLen : schemaUids.length = schemas.length := by - simp at hlen - exact hlen - obtain ⟨uids, hvalue⟩ := hshape (idx := 0) (value := value) (by rfl) - subst value - have htailShape : - ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, value = .array uids := by - intro idx value hlookup - exact hshape (idx := idx + 1) (value := value) (by - simpa [lookupNth?] using hlookup) - simp [attesterMultiRevokeRequestValuesPrefix, attesterMultiRevokeRequestValues, - attesterMultiRevokeRequestValuesPrefix_all htailLen htailShape] - -def attesterMultiRevokeRequestsValue (schemas schemaUids : List Value) : Value := - .array (attesterMultiRevokeRequestValues schemas schemaUids) - -theorem attesterEvalAndTrue {cfg : Config} {solm : Frame} {evm : EVM.State} - {lhs rhs : Expr} - (hleft : evalExpr? cfg solm evm lhs = .ok (.bool true)) - (hright : evalExpr? cfg solm evm rhs = .ok (.bool true)) : - evalExpr? cfg solm evm (.binary .and lhs rhs) = .ok (.bool true) := by - simp [evalExpr?, hleft, hright, EvalResult.bind, bind, pure] - -theorem attesterEvalBinaryEq {cfg : Config} {solm : Frame} {evm : EVM.State} - {lhs rhs : Expr} {v₁ v₂ value : Value} - (hleft : evalExpr? cfg solm evm lhs = .ok v₁) - (hright : evalExpr? cfg solm evm rhs = .ok v₂) - (hop : evalBinaryOp? .eq v₁ v₂ = .ok value) : - evalExpr? cfg solm evm (.binary .eq lhs rhs) = .ok value := by - simp [evalExpr?, hleft, hright, hop, EvalResult.bind, bind] - -theorem attesterEvalBinaryLt {cfg : Config} {solm : Frame} {evm : EVM.State} - {lhs rhs : Expr} {v₁ v₂ value : Value} - (hleft : evalExpr? cfg solm evm lhs = .ok v₁) - (hright : evalExpr? cfg solm evm rhs = .ok v₂) - (hop : evalBinaryOp? .lt v₁ v₂ = .ok value) : - evalExpr? cfg solm evm (.binary .lt lhs rhs) = .ok value := by - simp [evalExpr?, hleft, hright, hop, EvalResult.bind, bind] - -theorem attesterEvalIndex {cfg : Config} {solm : Frame} {evm : EVM.State} - {base idx : Expr} {container key value : Value} - (hbase : evalExpr? cfg solm evm base = .ok container) - (hidx : evalExpr? cfg solm evm idx = .ok key) - (hindex : evalIndex? container key = .ok value) : - evalExpr? cfg solm evm (.index base idx) = .ok value := by - simp [evalExpr?, hbase, hidx, hindex, EvalResult.bind, bind] - -theorem attesterEvalRevocationData {cfg : Config} {solm : Frame} {evm : EVM.State} - {uidExpr : Expr} {uid : Value} - (huid : evalExpr? cfg solm evm uidExpr = .ok uid) : - evalExpr? cfg solm evm (revocationData uidExpr) = - .ok (attesterRevocationDataValue uid) := by - simp [revocationData, attesterRevocationDataValue, evalExpr?, huid, evalExprList?, - EvalResult.bind, bind, pure] - -theorem attesterEvalMultiRevokeRequest {cfg : Config} {solm : Frame} {evm : EVM.State} - {schemaExpr dataExpr : Expr} {schema : Value} {data : List Value} - (hschema : evalExpr? cfg solm evm schemaExpr = .ok schema) - (hdata : evalExpr? cfg solm evm dataExpr = .ok (.array data)) : - evalExpr? cfg solm evm (.tupleLit [schemaExpr, dataExpr]) = - .ok (.tuple [schema, .array data]) := by - simp [evalExpr?, evalExprList?, hschema, hdata, EvalResult.bind, bind, pure] - -theorem attesterEvalNewRevocationDataArray {cfg : Config} {solm : Frame} - {evm : EVM.State} {lenExpr : Expr} {n : Nat} - (hlen : evalExpr? cfg solm evm lenExpr = .ok (.int (Int.ofNat n))) : - evalExpr? cfg solm evm (.newArray revocationRequestDataSt lenExpr) = - .ok (.array (List.replicate n attesterRevocationDataDefault)) := by - simp [evalExpr?, hlen, revocationRequestDataSt, attesterRevocationDataDefault, - attesterRevocationDataValue, bytes32St, bytes32Width, uint256St, - defaultValue?, defaultValues?, EvalResult.bind, bind, pure] - -theorem attesterEvalNewMultiRevokeRequestArray {cfg : Config} {solm : Frame} - {evm : EVM.State} {lenExpr : Expr} {n : Nat} - (hlen : evalExpr? cfg solm evm lenExpr = .ok (.int (Int.ofNat n))) : - evalExpr? cfg solm evm (.newArray multiRevocationRequestSt lenExpr) = - .ok (.array (List.replicate n attesterMultiRevokeRequestDefault)) := by - simp [evalExpr?, hlen, multiRevocationRequestSt, attesterMultiRevokeRequestDefault, - revocationRequestDataSt, bytes32St, bytes32Width, uint256St, defaultValue?, - defaultValues?, EvalResult.bind, bind, pure] - -theorem attesterEvalUInt256NeZeroTrue {cfg : Config} {solm : Frame} {evm : EVM.State} - {expr : Expr} {n : Nat} - (hval : evalExpr? cfg solm evm expr = .ok (.int (Int.ofNat n))) - (hne : n ≠ 0) : - evalExpr? cfg solm evm (.binary .ne expr (.intLit 0)) = .ok (.bool true) := by - simp [evalExpr?, hval, evalBinaryOp?, hne, EvalResult.bind, bind, pure] - -theorem attesterEvalUInt256NeZeroFalse {cfg : Config} {solm : Frame} {evm : EVM.State} - {expr : Expr} {n : Nat} - (hval : evalExpr? cfg solm evm expr = .ok (.int (Int.ofNat n))) - (hzero : n = 0) : - evalExpr? cfg solm evm (.binary .ne expr (.intLit 0)) = .ok (.bool false) := by - subst n - simp [evalExpr?, hval, evalBinaryOp?, EvalResult.bind, bind, pure] - -theorem attesterEvalLocalArrayLength {cfg : Config} {solm : Frame} {evm : EVM.State} - {name : Ident} {xs : List Value} - (hget : solm.locals.get? name = some (.array xs)) : - evalExpr? cfg solm evm (lenLocal name) = .ok (.int (Int.ofNat xs.length)) := by - have hgetElem : solm.locals[name]? = some (.array xs) := by - simpa [Std.HashMap.get?_eq_getElem?] using hget - simp [lenLocal, localRef, evalExpr?, readLocalPath?, hgetElem, EvalResult.bind, bind, pure] - -theorem attesterAssignLocalVar {cfg : Config} {solm : Frame} {evm : EVM.State} - {name : Ident} {old value : Value} - (hget : solm.locals.get? name = some old) : - assignStorageRef? cfg solm evm .localVar (localRef name) value = - .ok ({ solm with locals := solm.locals.insert name value }, evm) := by - have hgetElem : solm.locals[name]? = some old := by - simpa [Std.HashMap.get?_eq_getElem?] using hget - simp [assignStorageRef?, localRef, hgetElem, updateLocalPath?, EvalResult.bind, bind, pure] - -theorem attesterExecAssignLocalVar {cfg : Config} {solm : Frame} {evm : EVM.State} - {name : Ident} {old value : Value} {expr : Expr} - (hrhs : evalExpr? cfg solm evm expr = .ok value) - (hget : solm.locals.get? name = some old) : - ExecStmt cfg solm evm (.assign .localVar (localRef name) expr) - (.ok { solm with locals := solm.locals.insert name value } evm) := - ExecStmt.assign hrhs (attesterAssignLocalVar hget) - -theorem attesterLookupNth?_exists {α : Type} : - ∀ {xs : List α} {i : Nat}, i < xs.length → ∃ value, lookupNth? xs i = some value - | [], _, h => by simp at h - | x :: _, 0, _ => ⟨x, rfl⟩ - | _ :: xs, i + 1, h => by - have hlt : i < xs.length := by - simpa using Nat.succ_lt_succ_iff.mp h - exact @attesterLookupNth?_exists α xs i hlt - -theorem attesterUpdateNth?_exists {α : Type} : - ∀ {xs : List α} {i : Nat}, i < xs.length → (value : α) → - ∃ xs', updateNth? xs i value = some xs' - | [], _, h, _ => by simp at h - | _ :: xs, 0, _, value => by - exact ⟨value :: xs, rfl⟩ - | x :: xs, i + 1, h, value => by - have hlt : i < xs.length := by - simpa using Nat.succ_lt_succ_iff.mp h - obtain ⟨xs', hupdate⟩ := @attesterUpdateNth?_exists α xs i hlt value - exact ⟨x :: xs', by simp [updateNth?, hupdate, bind, pure]⟩ - -theorem attesterAssignLocalArrayIndexOfUpdate {cfg : Config} {solm : Frame} - {evm : EVM.State} {name : Ident} {idxExpr : Expr} {xs xs' : List Value} - {i : Nat} {old value : Value} - (hidx : evalExpr? cfg solm evm idxExpr = .ok (.int (Int.ofNat i))) - (hget : solm.locals.get? name = some (.array xs)) - (hbounds : i < xs.length) - (hlookup : lookupNth? xs i = some old) - (hupdate : updateNth? xs i value = some xs') : - assignStorageRef? cfg solm evm .localVar (localIndex name idxExpr) value = - .ok ({ solm with locals := solm.locals.insert name (.array xs') }, evm) := by - have hgetElem : solm.locals[name]? = some (.array xs) := by - simpa [Std.HashMap.get?_eq_getElem?] using hget - have hcheck : 0 ≤ (i : Int) ∧ (i : Int) < (xs.length : Int) := by - constructor - · exact Int.natCast_nonneg i - · exact_mod_cast hbounds - have hnotNeg : ¬ (i : Int) < 0 := not_lt_of_ge (Int.natCast_nonneg i) - simp [assignStorageRef?, localIndex, hgetElem, updateLocalPath?, hidx, hcheck, - lookupIndex?, updateIndex?, intToNat?, hnotNeg, hlookup, hupdate, EvalResult.ofOption, - EvalResult.bind, bind, pure] - -theorem attesterExecAssignLocalArrayIndexOfUpdate {cfg : Config} {solm : Frame} - {evm : EVM.State} {name : Ident} {idxExpr rhs : Expr} {xs xs' : List Value} - {i : Nat} {old value : Value} - (hrhs : evalExpr? cfg solm evm rhs = .ok value) - (hidx : evalExpr? cfg solm evm idxExpr = .ok (.int (Int.ofNat i))) - (hget : solm.locals.get? name = some (.array xs)) - (hbounds : i < xs.length) - (hlookup : lookupNth? xs i = some old) - (hupdate : updateNth? xs i value = some xs') : - ExecStmt cfg solm evm (.assign .localVar (localIndex name idxExpr) rhs) - (.ok { solm with locals := solm.locals.insert name (.array xs') } evm) := - ExecStmt.assign hrhs - (attesterAssignLocalArrayIndexOfUpdate hidx hget hbounds hlookup hupdate) - -def attesterMultiRevokeInnerSourceLoopCond : Expr := - .binary .lt (.var "j") (.var "uidLength") - -def attesterMultiRevokeInnerSourceLoopBody : List Stmt := - [ arrSet "data" (.var "j") (revocationData (arrGet "uids" (.var "j"))), - .assign .localVar (localRef "j") (add256 (.var "j") (.intLit 1)) ] - -def attesterMultiRevokeInnerSourceLoopInv (uids : List Value) - (v : Nat) (locals : Store) : Prop := - ∃ j, - locals.get? "uids" = some (.array uids) ∧ - locals.get? "uidLength" = some (.int (Int.ofNat uids.length)) ∧ - locals.get? "data" = some (.array (attesterRevocationDataPrefix j uids)) ∧ - locals.get? "j" = some (.int (Int.ofNat j)) ∧ - j + v = uids.length ∧ - j ≤ uids.length - -theorem attesterEvalVarOfGet {cfg : Config} {C : ContractDecl} - {evm : EVM.State} {locals : Store} {name : Ident} {value : Value} - (hget : locals.get? name = some value) : - evalExpr? cfg { contract := C, locals := locals } evm (.var name) = .ok value := by - have hgetElem : locals[name]? = some value := by - simpa [Std.HashMap.get?_eq_getElem?] using hget - simp [evalExpr?, EvalResult.ofOption, hgetElem] - -theorem attesterStoreGetInsertSelf {locals : Store} {name : Ident} {value : Value} : - (locals.insert name value).get? name = some value := by - rw [Std.HashMap.get?_eq_getElem?] - simp - -theorem attesterStoreGetInsertOfNe {locals : Store} {name other : Ident} - {value old : Value} - (hget : locals.get? name = some old) - (hne : other ≠ name) : - (locals.insert other value).get? name = some old := by - have hgetElem : locals[name]? = some old := by - simpa [Std.HashMap.get?_eq_getElem?] using hget - rw [Std.HashMap.get?_eq_getElem?] - simp [Std.HashMap.getElem?_insert, hne, hgetElem] - -theorem attesterEvalUInt256AddOne {cfg : Config} {C : ContractDecl} - {evm : EVM.State} {locals : Store} {name : Ident} {i : Nat} - (hget : locals.get? name = some (.int (Int.ofNat i))) - (hbound : i + 1 < 2 ^ 256) : - evalExpr? cfg { contract := C, locals := locals } evm - (add256 (.var name) (.intLit 1)) = - .ok (.int (Int.ofNat (i + 1))) := by - have hgetElem : locals[name]? = some (.int (Int.ofNat i)) := by - simpa [Std.HashMap.get?_eq_getElem?] using hget - have hnotNeg : ¬ (Int.ofNat i + 1 : Int) < 0 := by - have hnonneg : (0 : Int) ≤ Int.ofNat i := Int.natCast_nonneg i - omega - have hadd : (Int.ofNat i + 1 : Int) = Int.ofNat (i + 1) := by - norm_num - have hltInt : (Int.ofNat i + 1 : Int) < (2 : Int) ^ (256 : Nat) := by - rw [hadd] - simpa using (Int.ofNat_lt.mpr hbound) - have hnotGe : ¬ (2 : Int) ^ (256 : Nat) ≤ (Int.ofNat i + 1 : Int) := - not_le_of_gt hltInt - have hrange : - 0 ≤ (Int.ofNat i + 1 : Int) ∧ - (Int.ofNat i + 1 : Int) < - 115792089237316195423570985008687907853269984665640564039457584007913129639936 := by - constructor - · exact le_of_not_gt hnotNeg - · simpa using hltInt - simp [add256, u256, uint256Int, evalExpr?, EvalResult.ofOption, hgetElem, - evalBinaryOp?, EvalResult.bind, bind, pure] - simpa using hrange - -theorem attesterMultiRevokeInnerSourceLoopCondTrue - (imm : AttesterImmutables) (evm : EVM.State) {locals : Store} - {uids : List Value} {j : Nat} - (hlen : locals.get? "uidLength" = some (.int (Int.ofNat uids.length))) - (hj : locals.get? "j" = some (.int (Int.ofNat j))) - (hlt : j < uids.length) : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - attesterMultiRevokeInnerSourceLoopCond = .ok (.bool true) := by - exact attesterEvalBinaryLt - (attesterEvalVarOfGet hj) - (attesterEvalVarOfGet hlen) - (by simp [evalBinaryOp?, hlt]) - -theorem attesterMultiRevokeInnerSourceLoopCondFalse - (imm : AttesterImmutables) (evm : EVM.State) {locals : Store} - {uids : List Value} {j : Nat} - (hlen : locals.get? "uidLength" = some (.int (Int.ofNat uids.length))) - (hj : locals.get? "j" = some (.int (Int.ofNat j))) - (hnot : ¬ j < uids.length) : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - attesterMultiRevokeInnerSourceLoopCond = .ok (.bool false) := by - exact attesterEvalBinaryLt - (attesterEvalVarOfGet hj) - (attesterEvalVarOfGet hlen) - (by simp [evalBinaryOp?, hnot]) - -theorem attesterMultiRevokeInnerSourceLoop_step - (imm : AttesterImmutables) (evm : EVM.State) {uids : List Value} - (hlenBound : uids.length < 2 ^ 256) - (hnorm : ∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid) : - ∀ n locals, attesterMultiRevokeInnerSourceLoopInv uids (n + 1) locals → - ∃ locals', - ExecBlock (config imm) { contract := contract imm, locals := locals } evm - attesterMultiRevokeInnerSourceLoopBody - (.ok { contract := contract imm, locals := locals' } evm) ∧ - attesterMultiRevokeInnerSourceLoopInv uids n locals' ∧ - ∃ j, - locals' = - (locals.insert "data" (.array (attesterRevocationDataPrefix (j + 1) uids))).insert - "j" (.int (Int.ofNat (j + 1))) := by - intro n locals hInv - rcases hInv with ⟨j, huids, hlen, hdata, hj, hvar, hle⟩ - have hlt : j < uids.length := by omega - obtain ⟨uid, huidLookup, hupdate⟩ := - attesterRevocationDataPrefix_update (uids := uids) (n := j) hlt - have hdataLen : - (attesterRevocationDataPrefix j uids).length = uids.length := - attesterRevocationDataPrefix_length j uids - obtain ⟨old, hdataLookup⟩ := - attesterLookupNth?_exists - (xs := attesterRevocationDataPrefix j uids) (i := j) - (by rw [hdataLen]; exact hlt) - let dataNext := attesterRevocationDataPrefix (j + 1) uids - have hidxEval : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - (.var "j") = .ok (.int (Int.ofNat j)) := - attesterEvalVarOfGet hj - have huidsEval : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - (.var "uids") = .ok (.array uids) := - attesterEvalVarOfGet huids - have hindex : - evalIndex? (.array uids) (.int (Int.ofNat j)) = .ok uid := by - simp [evalIndex?, hlt, huidLookup, hnorm huidLookup] - have hgetUid : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - (arrGet "uids" (.var "j")) = .ok uid := - attesterEvalIndex huidsEval hidxEval hindex - have hrhs : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - (revocationData (arrGet "uids" (.var "j"))) = - .ok (attesterRevocationDataValue uid) := - attesterEvalRevocationData hgetUid - let L1 := locals.insert "data" (.array dataNext) - have hstmtData : - ExecStmt (config imm) { contract := contract imm, locals := locals } evm - (arrSet "data" (.var "j") (revocationData (arrGet "uids" (.var "j")))) - (.ok { contract := contract imm, locals := L1 } evm) := by - simpa [arrSet, localIndex, dataNext, L1] using - attesterExecAssignLocalArrayIndexOfUpdate - (cfg := config imm) (solm := { contract := contract imm, locals := locals }) - (evm := evm) (name := "data") (idxExpr := .var "j") - (rhs := revocationData (arrGet "uids" (.var "j"))) - (xs := attesterRevocationDataPrefix j uids) (xs' := dataNext) - (i := j) (old := old) (value := attesterRevocationDataValue uid) - hrhs hidxEval hdata (by rw [hdataLen]; exact hlt) hdataLookup - (by simpa [dataNext] using hupdate) - have hjL1 : - L1.get? "j" = some (.int (Int.ofNat j)) := by - have hjElem : locals["j"]? = some (.int (Int.ofNat j)) := by - simpa [Std.HashMap.get?_eq_getElem?] using hj - rw [Std.HashMap.get?_eq_getElem?] - simp [L1, Std.HashMap.getElem?_insert, hjElem] - have hincEval : - evalExpr? (config imm) { contract := contract imm, locals := L1 } evm - (add256 (.var "j") (.intLit 1)) = - .ok (.int (Int.ofNat (j + 1))) := by - exact attesterEvalUInt256AddOne - (cfg := config imm) (C := contract imm) (evm := evm) - (locals := L1) (name := "j") (i := j) hjL1 (by omega) - let L2 := L1.insert "j" (.int (Int.ofNat (j + 1))) - have hstmtInc : - ExecStmt (config imm) { contract := contract imm, locals := L1 } evm - (.assign .localVar (localRef "j") (add256 (.var "j") (.intLit 1))) - (.ok { contract := contract imm, locals := L2 } evm) := by - simpa [localRef, L2] using - attesterExecAssignLocalVar - (cfg := config imm) (solm := { contract := contract imm, locals := L1 }) - (evm := evm) (name := "j") (old := .int (Int.ofNat j)) - (value := .int (Int.ofNat (j + 1))) - (expr := add256 (.var "j") (.intLit 1)) hincEval hjL1 - refine ⟨L2, ?_, ?_, j, rfl⟩ - · exact ExecBlock.consNormal hstmtData - (ExecBlock.consNormal hstmtInc ExecBlock.nil) - · refine ⟨j + 1, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · have huidsElem : locals["uids"]? = some (.array uids) := by - simpa [Std.HashMap.get?_eq_getElem?] using huids - rw [Std.HashMap.get?_eq_getElem?] - simp [L2, L1, Std.HashMap.getElem?_insert, huidsElem] - · have hlenElem : locals["uidLength"]? = - some (.int (Int.ofNat uids.length)) := by - simpa [Std.HashMap.get?_eq_getElem?] using hlen - rw [Std.HashMap.get?_eq_getElem?] - simp [L2, L1, Std.HashMap.getElem?_insert, hlenElem] - · rw [Std.HashMap.get?_eq_getElem?] - simp [L2, L1, Std.HashMap.getElem_insert, dataNext] - · rw [Std.HashMap.get?_eq_getElem?] - simp [L2] - · omega - · omega - -theorem attesterMultiRevokeInnerSourceLoop_from_inv - (imm : AttesterImmutables) (evm : EVM.State) {uids : List Value} - (hlenBound : uids.length < 2 ^ 256) - (hnorm : ∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid) : - ∀ n locals, attesterMultiRevokeInnerSourceLoopInv uids n locals → - ∃ locals', - ExecStmt (config imm) { contract := contract imm, locals := locals } evm - (.while attesterMultiRevokeInnerSourceLoopCond - attesterMultiRevokeInnerSourceLoopBody) - (.ok { contract := contract imm, locals := locals' } evm) ∧ - attesterMultiRevokeInnerSourceLoopInv uids 0 locals' := by - refine execWhile_var - (cfg := config imm) (C := contract imm) (evm := evm) - (cond := attesterMultiRevokeInnerSourceLoopCond) - (body := attesterMultiRevokeInnerSourceLoopBody) - (P := attesterMultiRevokeInnerSourceLoopInv uids) ?_ ?_ ?_ - · intro locals hInv - rcases hInv with ⟨j, _huids, hlen, _hdata, hj, hvar, _hle⟩ - exact attesterMultiRevokeInnerSourceLoopCondFalse imm evm hlen hj (by omega) - · intro n locals hInv - rcases hInv with ⟨j, _huids, hlen, _hdata, hj, hvar, _hle⟩ - exact attesterMultiRevokeInnerSourceLoopCondTrue imm evm hlen hj (by omega) - · intro n locals hInv - obtain ⟨locals', hbody, hInv', _⟩ := - attesterMultiRevokeInnerSourceLoop_step imm evm hlenBound hnorm - n locals hInv - exact ⟨locals', hbody, hInv'⟩ - -theorem attesterMultiRevokeInnerSourceLoop_from_inv_keep - (imm : AttesterImmutables) (evm : EVM.State) {uids : List Value} - {Keep : Store → Prop} - (hlenBound : uids.length < 2 ^ 256) - (hnorm : ∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid) - (hkeepData : ∀ {locals data}, Keep locals → - Keep (locals.insert "data" (.array data))) - (hkeepJ : ∀ {locals j}, Keep locals → - Keep (locals.insert "j" (.int (Int.ofNat j)))) : - ∀ n locals, attesterMultiRevokeInnerSourceLoopInv uids n locals → Keep locals → - ∃ locals', - ExecStmt (config imm) { contract := contract imm, locals := locals } evm - (.while attesterMultiRevokeInnerSourceLoopCond - attesterMultiRevokeInnerSourceLoopBody) - (.ok { contract := contract imm, locals := locals' } evm) ∧ - attesterMultiRevokeInnerSourceLoopInv uids 0 locals' ∧ - Keep locals' := by - intro n locals hBase hKeep - refine execWhile_var - (cfg := config imm) (C := contract imm) (evm := evm) - (cond := attesterMultiRevokeInnerSourceLoopCond) - (body := attesterMultiRevokeInnerSourceLoopBody) - (P := fun n locals => - attesterMultiRevokeInnerSourceLoopInv uids n locals ∧ Keep locals) ?_ ?_ ?_ - n locals ⟨hBase, hKeep⟩ - · intro locals hInv - rcases hInv.1 with ⟨j, _huids, hlen, _hdata, hj, hvar, _hle⟩ - exact attesterMultiRevokeInnerSourceLoopCondFalse imm evm hlen hj (by omega) - · intro n locals hInv - rcases hInv.1 with ⟨j, _huids, hlen, _hdata, hj, hvar, _hle⟩ - exact attesterMultiRevokeInnerSourceLoopCondTrue imm evm hlen hj (by omega) - · intro n locals hInv - obtain ⟨locals', hbody, hInv', j, hlocals'⟩ := - attesterMultiRevokeInnerSourceLoop_step imm evm hlenBound hnorm - n locals hInv.1 - refine ⟨locals', hbody, ?_⟩ - constructor - · exact hInv' - · rw [hlocals'] - exact hkeepJ (j := j + 1) - (hkeepData (data := attesterRevocationDataPrefix (j + 1) uids) hInv.2) - -theorem attesterMultiRevokeInnerSourceLoop - (imm : AttesterImmutables) (evm : EVM.State) {uids : List Value} - {locals : Store} - (hlenBound : uids.length < 2 ^ 256) - (hnorm : ∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid) - (huids : locals.get? "uids" = some (.array uids)) - (hlen : locals.get? "uidLength" = some (.int (Int.ofNat uids.length))) - (hdata : locals.get? "data" = - some (.array (List.replicate uids.length attesterRevocationDataDefault))) - (hj : locals.get? "j" = some (.int 0)) : - ∃ locals', - ExecStmt (config imm) { contract := contract imm, locals := locals } evm - (.while attesterMultiRevokeInnerSourceLoopCond - attesterMultiRevokeInnerSourceLoopBody) - (.ok { contract := contract imm, locals := locals' } evm) ∧ - locals'.get? "data" = some (.array (attesterRevocationDataValues uids)) ∧ - locals'.get? "j" = some (.int (Int.ofNat uids.length)) := by - have hdata0 : - locals.get? "data" = - some (.array (attesterRevocationDataPrefix 0 uids)) := by - simpa [attesterRevocationDataPrefix_zero] using hdata - have hinv : attesterMultiRevokeInnerSourceLoopInv uids uids.length locals := by - refine ⟨0, huids, hlen, hdata0, ?_, by simp, by simp⟩ - simpa using hj - obtain ⟨locals', hloop, hInvDone⟩ := - attesterMultiRevokeInnerSourceLoop_from_inv imm evm hlenBound hnorm - uids.length locals hinv - rcases hInvDone with ⟨j, _huids, _hlen, hdataDone, hjDone, hvar, _hle⟩ - have hjLen : j = uids.length := by omega - refine ⟨locals', hloop, ?_, ?_⟩ - · simpa [hjLen, attesterRevocationDataPrefix_all] using hdataDone - · simpa [hjLen] using hjDone - -def attesterMultiRevokeOuterSourceLoopCond : Expr := - .binary .lt (.var "i") (.var "schemaLength") - -def attesterMultiRevokeOuterSourceLoopBody : List Stmt := - [ .letDecl "uids" (some bytes32Array) (arrGet "schemaUids" (.var "i")), - .letDecl "uidLength" (some uint256) (lenLocal "uids"), - .require (.binary .ne (.var "uidLength") (.intLit 0)), - .letDecl "data" (some (.dynamicArray revocationRequestDataTy)) - (.newArray revocationRequestDataSt (.var "uidLength")), - .letDecl "j" (some uint256) (.intLit 0), - .while attesterMultiRevokeInnerSourceLoopCond - attesterMultiRevokeInnerSourceLoopBody, - arrSet "multiRequests" (.var "i") - (.tupleLit [arrGet "schemas" (.var "i"), .var "data"]), - .assign .localVar (localRef "i") (add256 (.var "i") (.intLit 1)) ] - -def attesterMultiRevokeOuterSourceLoopInv - (schemas schemaUids : List Value) (v : Nat) (locals : Store) : Prop := - ∃ i, - locals.get? "schemas" = some (.array schemas) ∧ - locals.get? "schemaUids" = some (.array schemaUids) ∧ - locals.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) ∧ - locals.get? "multiRequests" = - some (.array (attesterMultiRevokeRequestValuesPrefix i schemas schemaUids)) ∧ - locals.get? "i" = some (.int (Int.ofNat i)) ∧ - i + v = schemas.length ∧ - i ≤ schemas.length - -theorem attesterMultiRevokeOuterSourceLoopCondTrue - (imm : AttesterImmutables) (evm : EVM.State) {locals : Store} - {schemas : List Value} {i : Nat} - (hlen : locals.get? "schemaLength" = some (.int (Int.ofNat schemas.length))) - (hi : locals.get? "i" = some (.int (Int.ofNat i))) - (hlt : i < schemas.length) : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - attesterMultiRevokeOuterSourceLoopCond = .ok (.bool true) := by - exact attesterEvalBinaryLt - (attesterEvalVarOfGet hi) - (attesterEvalVarOfGet hlen) - (by simp [evalBinaryOp?, hlt]) - -theorem attesterMultiRevokeOuterSourceLoopCondFalse - (imm : AttesterImmutables) (evm : EVM.State) {locals : Store} - {schemas : List Value} {i : Nat} - (hlen : locals.get? "schemaLength" = some (.int (Int.ofNat schemas.length))) - (hi : locals.get? "i" = some (.int (Int.ofNat i))) - (hnot : ¬ i < schemas.length) : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - attesterMultiRevokeOuterSourceLoopCond = .ok (.bool false) := by - exact attesterEvalBinaryLt - (attesterEvalVarOfGet hi) - (attesterEvalVarOfGet hlen) - (by simp [evalBinaryOp?, hnot]) - -theorem attesterMultiRevokeOuterSourceLoopBody_revert_emptyCurrent - (imm : AttesterImmutables) (evm : EVM.State) {locals : Store} - {schemaUids : List Value} {i : Nat} - (hschemaUids : locals.get? "schemaUids" = some (.array schemaUids)) - (hi : locals.get? "i" = some (.int (Int.ofNat i))) - (hlt : i < schemaUids.length) - (hlookup : lookupNth? schemaUids i = some (.array [])) : - ExecBlock (config imm) { contract := contract imm, locals := locals } evm - attesterMultiRevokeOuterSourceLoopBody .reverted := by - have hschemaUidsEval : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - (.var "schemaUids") = .ok (.array schemaUids) := - attesterEvalVarOfGet hschemaUids - have hiEval : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - (.var "i") = .ok (.int (Int.ofNat i)) := - attesterEvalVarOfGet hi - have hindexUids : - evalIndex? (.array schemaUids) (.int (Int.ofNat i)) = .ok (.array []) := by - simp [evalIndex?, normalizeRawBoolWord?, hlt, hlookup] - have huidsExpr : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - (arrGet "schemaUids" (.var "i")) = .ok (.array []) := - attesterEvalIndex hschemaUidsEval hiEval hindexUids - let L1 := locals.insert "uids" (.array []) - have hstmtUids : - ExecStmt (config imm) { contract := contract imm, locals := locals } evm - (.letDecl "uids" (some bytes32Array) (arrGet "schemaUids" (.var "i"))) - (.ok { contract := contract imm, locals := L1 } evm) := by - simpa [L1] using ExecStmt.letDecl huidsExpr - have huidsL1 : L1.get? "uids" = some (.array []) := by - simp [L1] - have hlenExpr : - evalExpr? (config imm) { contract := contract imm, locals := L1 } evm - (lenLocal "uids") = .ok (.int 0) := by - simpa using attesterEvalLocalArrayLength - (cfg := config imm) (solm := { contract := contract imm, locals := L1 }) - (evm := evm) (name := "uids") (xs := []) huidsL1 - let L2 := L1.insert "uidLength" (.int 0) - have hstmtUidLength : - ExecStmt (config imm) { contract := contract imm, locals := L1 } evm - (.letDecl "uidLength" (some uint256) (lenLocal "uids")) - (.ok { contract := contract imm, locals := L2 } evm) := by - simpa [L2] using ExecStmt.letDecl hlenExpr - have hlenL2 : L2.get? "uidLength" = some (.int 0) := by - simp [L2] - have hrequireEval : - evalExpr? (config imm) { contract := contract imm, locals := L2 } evm - (.binary .ne (.var "uidLength") (.intLit 0)) = .ok (.bool false) := - attesterEvalUInt256NeZeroFalse (attesterEvalVarOfGet hlenL2) rfl - unfold attesterMultiRevokeOuterSourceLoopBody - exact ExecBlock.consNormal hstmtUids - (ExecBlock.consNormal hstmtUidLength - (ExecBlock.consRevert (ExecStmt.requireFalse hrequireEval))) - -set_option maxHeartbeats 1000000 in -theorem attesterMultiRevokeOuterSourceLoop_step_current - (imm : AttesterImmutables) (evm : EVM.State) - {schemas schemaUids : List Value} - (hschemasBound : schemas.length < 2 ^ 256) - (hlenEq : schemaUids.length = schemas.length) - (hschemaNorm : ∀ {idx schema}, lookupNth? schemas idx = some schema → - normalizeRawBoolWord? schema = .ok schema) : - ∀ n locals, attesterMultiRevokeOuterSourceLoopInv schemas schemaUids (n + 1) locals → - (∀ {idx value}, lookupNth? schemaUids idx = some value → - idx + (n + 1) = schemas.length → - ∃ uids, - value = .array uids ∧ - uids.length ≠ 0 ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid)) → - ∃ locals', - ExecBlock (config imm) { contract := contract imm, locals := locals } evm - attesterMultiRevokeOuterSourceLoopBody - (.ok { contract := contract imm, locals := locals' } evm) ∧ - attesterMultiRevokeOuterSourceLoopInv schemas schemaUids n locals' := by - intro n locals hInv huidssOkCurrent - rcases hInv with - ⟨i, hschemas, hschemaUids, hschemaLength, hrequests, hi, hvar, hle⟩ - have hlt : i < schemas.length := by omega - obtain ⟨schema, hschemaLookup⟩ := - attesterLookupNth?_exists (xs := schemas) (i := i) hlt - have hltSchemaUids : i < schemaUids.length := by omega - obtain ⟨schemaUidValue, hschemaUidLookupValue⟩ := - attesterLookupNth?_exists (xs := schemaUids) (i := i) hltSchemaUids - obtain ⟨uids, hschemaUidValue, huidsNe, huidsBound, huidsNorm⟩ := - huidssOkCurrent hschemaUidLookupValue hvar - have hschemaUidLookup : lookupNth? schemaUids i = some (.array uids) := by - simpa [hschemaUidValue] using hschemaUidLookupValue - have hschemaUidsEval : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - (.var "schemaUids") = .ok (.array schemaUids) := - attesterEvalVarOfGet hschemaUids - have hiEval : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - (.var "i") = .ok (.int (Int.ofNat i)) := - attesterEvalVarOfGet hi - have hindexUids : - evalIndex? (.array schemaUids) (.int (Int.ofNat i)) = .ok (.array uids) := by - simp [evalIndex?, normalizeRawBoolWord?, hltSchemaUids, hschemaUidLookup] - have huidsExpr : - evalExpr? (config imm) { contract := contract imm, locals := locals } evm - (arrGet "schemaUids" (.var "i")) = .ok (.array uids) := - attesterEvalIndex hschemaUidsEval hiEval hindexUids - let L1 := locals.insert "uids" (.array uids) - have hstmtUids : - ExecStmt (config imm) { contract := contract imm, locals := locals } evm - (.letDecl "uids" (some bytes32Array) (arrGet "schemaUids" (.var "i"))) - (.ok { contract := contract imm, locals := L1 } evm) := by - simpa [L1] using ExecStmt.letDecl huidsExpr - have huidsL1 : L1.get? "uids" = some (.array uids) := by - simp [L1] - have hlenExpr : - evalExpr? (config imm) { contract := contract imm, locals := L1 } evm - (lenLocal "uids") = .ok (.int (Int.ofNat uids.length)) := - attesterEvalLocalArrayLength huidsL1 - let L2 := L1.insert "uidLength" (.int (Int.ofNat uids.length)) - have hstmtUidLength : - ExecStmt (config imm) { contract := contract imm, locals := L1 } evm - (.letDecl "uidLength" (some uint256) (lenLocal "uids")) - (.ok { contract := contract imm, locals := L2 } evm) := by - simpa [L2] using ExecStmt.letDecl hlenExpr - have hlenL2 : L2.get? "uidLength" = some (.int (Int.ofNat uids.length)) := by - simp [L2] - have hrequireEval : - evalExpr? (config imm) { contract := contract imm, locals := L2 } evm - (.binary .ne (.var "uidLength") (.intLit 0)) = .ok (.bool true) := - attesterEvalUInt256NeZeroTrue (attesterEvalVarOfGet hlenL2) huidsNe - have hstmtRequire : - ExecStmt (config imm) { contract := contract imm, locals := L2 } evm - (.require (.binary .ne (.var "uidLength") (.intLit 0))) - (.ok { contract := contract imm, locals := L2 } evm) := - ExecStmt.requireTrue hrequireEval - have hnewData : - evalExpr? (config imm) { contract := contract imm, locals := L2 } evm - (.newArray revocationRequestDataSt (.var "uidLength")) = - .ok (.array (List.replicate uids.length attesterRevocationDataDefault)) := - attesterEvalNewRevocationDataArray (attesterEvalVarOfGet hlenL2) - let L3 := L2.insert "data" - (.array (List.replicate uids.length attesterRevocationDataDefault)) - have hstmtDataDecl : - ExecStmt (config imm) { contract := contract imm, locals := L2 } evm - (.letDecl "data" (some (.dynamicArray revocationRequestDataTy)) - (.newArray revocationRequestDataSt (.var "uidLength"))) - (.ok { contract := contract imm, locals := L3 } evm) := by - simpa [L3] using ExecStmt.letDecl hnewData - have hjExpr : - evalExpr? (config imm) { contract := contract imm, locals := L3 } evm - (.intLit 0) = .ok (.int 0) := by - simp [evalExpr?, pure] - let L4 := L3.insert "j" (.int 0) - have hstmtJDecl : - ExecStmt (config imm) { contract := contract imm, locals := L3 } evm - (.letDecl "j" (some uint256) (.intLit 0)) - (.ok { contract := contract imm, locals := L4 } evm) := by - simpa [L4] using ExecStmt.letDecl hjExpr - have huidsL4 : L4.get? "uids" = some (.array uids) := by - have huidsL2 : L2.get? "uids" = some (.array uids) := by - simpa [L2] using - (attesterStoreGetInsertOfNe (locals := L1) (name := "uids") - (other := "uidLength") (value := .int (Int.ofNat uids.length)) - huidsL1 (by decide)) - have huidsL3 : L3.get? "uids" = some (.array uids) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "uids") - (other := "data") - (value := .array (List.replicate uids.length attesterRevocationDataDefault)) - huidsL2 (by decide)) - simpa [L4] using - (attesterStoreGetInsertOfNe (locals := L3) (name := "uids") - (other := "j") (value := .int 0) huidsL3 (by decide)) - have hlenL4 : - L4.get? "uidLength" = some (.int (Int.ofNat uids.length)) := by - have hlenL3 : - L3.get? "uidLength" = some (.int (Int.ofNat uids.length)) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "uidLength") - (other := "data") - (value := .array (List.replicate uids.length attesterRevocationDataDefault)) - hlenL2 (by decide)) - simpa [L4] using - (attesterStoreGetInsertOfNe (locals := L3) (name := "uidLength") - (other := "j") (value := .int 0) hlenL3 (by decide)) - have hdataL4 : - L4.get? "data" = - some (.array (List.replicate uids.length attesterRevocationDataDefault)) := by - have hdataL3 : - L3.get? "data" = - some (.array (List.replicate uids.length attesterRevocationDataDefault)) := by - simp [L3] - simpa [L4] using - (attesterStoreGetInsertOfNe (locals := L3) (name := "data") - (other := "j") (value := .int 0) hdataL3 (by decide)) - have hjL4 : L4.get? "j" = some (.int 0) := by - simp [L4] - have hinnerInv : - attesterMultiRevokeInnerSourceLoopInv uids uids.length L4 := by - refine ⟨0, huidsL4, hlenL4, ?_, ?_, by simp, by simp⟩ - · simpa [attesterRevocationDataPrefix_zero] using hdataL4 - · simpa using hjL4 - let requestsPrefix := attesterMultiRevokeRequestValuesPrefix i schemas schemaUids - let Keep : Store → Prop := fun L => - L.get? "schemas" = some (.array schemas) ∧ - L.get? "schemaUids" = some (.array schemaUids) ∧ - L.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) ∧ - L.get? "multiRequests" = some (.array requestsPrefix) ∧ - L.get? "i" = some (.int (Int.ofNat i)) - have hKeepL4 : Keep L4 := by - dsimp [Keep, requestsPrefix] - have hschemasL1 : L1.get? "schemas" = some (.array schemas) := by - simpa [L1] using - (attesterStoreGetInsertOfNe (locals := locals) (name := "schemas") - (other := "uids") (value := .array uids) hschemas (by decide)) - have hschemasL2 : L2.get? "schemas" = some (.array schemas) := by - simpa [L2] using - (attesterStoreGetInsertOfNe (locals := L1) (name := "schemas") - (other := "uidLength") (value := .int (Int.ofNat uids.length)) - hschemasL1 (by decide)) - have hschemasL3 : L3.get? "schemas" = some (.array schemas) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "schemas") - (other := "data") - (value := .array (List.replicate uids.length attesterRevocationDataDefault)) - hschemasL2 (by decide)) - have hschemasL4 : L4.get? "schemas" = some (.array schemas) := by - simpa [L4] using - (attesterStoreGetInsertOfNe (locals := L3) (name := "schemas") - (other := "j") (value := .int 0) hschemasL3 (by decide)) - have hschemaUidsL1 : L1.get? "schemaUids" = some (.array schemaUids) := by - simpa [L1] using - (attesterStoreGetInsertOfNe (locals := locals) (name := "schemaUids") - (other := "uids") (value := .array uids) hschemaUids (by decide)) - have hschemaUidsL2 : L2.get? "schemaUids" = some (.array schemaUids) := by - simpa [L2] using - (attesterStoreGetInsertOfNe (locals := L1) (name := "schemaUids") - (other := "uidLength") (value := .int (Int.ofNat uids.length)) - hschemaUidsL1 (by decide)) - have hschemaUidsL3 : L3.get? "schemaUids" = some (.array schemaUids) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "schemaUids") - (other := "data") - (value := .array (List.replicate uids.length attesterRevocationDataDefault)) - hschemaUidsL2 (by decide)) - have hschemaUidsL4 : L4.get? "schemaUids" = some (.array schemaUids) := by - simpa [L4] using - (attesterStoreGetInsertOfNe (locals := L3) (name := "schemaUids") - (other := "j") (value := .int 0) hschemaUidsL3 (by decide)) - have hschemaLengthL1 : - L1.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) := by - simpa [L1] using - (attesterStoreGetInsertOfNe (locals := locals) (name := "schemaLength") - (other := "uids") (value := .array uids) hschemaLength (by decide)) - have hschemaLengthL2 : - L2.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) := by - simpa [L2] using - (attesterStoreGetInsertOfNe (locals := L1) (name := "schemaLength") - (other := "uidLength") (value := .int (Int.ofNat uids.length)) - hschemaLengthL1 (by decide)) - have hschemaLengthL3 : - L3.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "schemaLength") - (other := "data") - (value := .array (List.replicate uids.length attesterRevocationDataDefault)) - hschemaLengthL2 (by decide)) - have hschemaLengthL4 : - L4.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) := by - simpa [L4] using - (attesterStoreGetInsertOfNe (locals := L3) (name := "schemaLength") - (other := "j") (value := .int 0) hschemaLengthL3 (by decide)) - have hrequestsL1 : L1.get? "multiRequests" = some (.array requestsPrefix) := by - simpa [L1, requestsPrefix] using - (attesterStoreGetInsertOfNe (locals := locals) (name := "multiRequests") - (other := "uids") (value := .array uids) hrequests (by decide)) - have hrequestsL2 : L2.get? "multiRequests" = some (.array requestsPrefix) := by - simpa [L2] using - (attesterStoreGetInsertOfNe (locals := L1) (name := "multiRequests") - (other := "uidLength") (value := .int (Int.ofNat uids.length)) - hrequestsL1 (by decide)) - have hrequestsL3 : L3.get? "multiRequests" = some (.array requestsPrefix) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "multiRequests") - (other := "data") - (value := .array (List.replicate uids.length attesterRevocationDataDefault)) - hrequestsL2 (by decide)) - have hrequestsL4 : L4.get? "multiRequests" = some (.array requestsPrefix) := by - simpa [L4] using - (attesterStoreGetInsertOfNe (locals := L3) (name := "multiRequests") - (other := "j") (value := .int 0) hrequestsL3 (by decide)) - have hiL1 : L1.get? "i" = some (.int (Int.ofNat i)) := by - simpa [L1] using - (attesterStoreGetInsertOfNe (locals := locals) (name := "i") - (other := "uids") (value := .array uids) hi (by decide)) - have hiL2 : L2.get? "i" = some (.int (Int.ofNat i)) := by - simpa [L2] using - (attesterStoreGetInsertOfNe (locals := L1) (name := "i") - (other := "uidLength") (value := .int (Int.ofNat uids.length)) - hiL1 (by decide)) - have hiL3 : L3.get? "i" = some (.int (Int.ofNat i)) := by - simpa [L3] using - (attesterStoreGetInsertOfNe (locals := L2) (name := "i") - (other := "data") - (value := .array (List.replicate uids.length attesterRevocationDataDefault)) - hiL2 (by decide)) - have hiL4 : L4.get? "i" = some (.int (Int.ofNat i)) := by - simpa [L4] using - (attesterStoreGetInsertOfNe (locals := L3) (name := "i") - (other := "j") (value := .int 0) hiL3 (by decide)) - constructor - · exact hschemasL4 - constructor - · exact hschemaUidsL4 - constructor - · exact hschemaLengthL4 - constructor - · exact hrequestsL4 - · exact hiL4 - have hkeepData : ∀ {L data}, Keep L → Keep (L.insert "data" (.array data)) := by - intro L data hK - rcases hK with ⟨hs, hsu, hsl, hmr, hiK⟩ - exact ⟨attesterStoreGetInsertOfNe hs (by decide), - attesterStoreGetInsertOfNe hsu (by decide), - attesterStoreGetInsertOfNe hsl (by decide), - attesterStoreGetInsertOfNe hmr (by decide), - attesterStoreGetInsertOfNe hiK (by decide)⟩ - have hkeepJ : ∀ {L j}, Keep L → Keep (L.insert "j" (.int (Int.ofNat j))) := by - intro L j hK - rcases hK with ⟨hs, hsu, hsl, hmr, hiK⟩ - exact ⟨attesterStoreGetInsertOfNe hs (by decide), - attesterStoreGetInsertOfNe hsu (by decide), - attesterStoreGetInsertOfNe hsl (by decide), - attesterStoreGetInsertOfNe hmr (by decide), - attesterStoreGetInsertOfNe hiK (by decide)⟩ - obtain ⟨L5, hinnerLoop, hinnerDone, hKeepDone⟩ := - attesterMultiRevokeInnerSourceLoop_from_inv_keep - (imm := imm) (evm := evm) (uids := uids) (Keep := Keep) - huidsBound huidsNorm hkeepData hkeepJ uids.length L4 hinnerInv hKeepL4 - rcases hinnerDone with - ⟨jDone, _huidsDone, _hlenDone, hdataDone, _hjDone, hinnerVar, _hinnerLe⟩ - have hjDoneEq : jDone = uids.length := by omega - have hdataFinal : - L5.get? "data" = some (.array (attesterRevocationDataValues uids)) := by - simpa [hjDoneEq, attesterRevocationDataPrefix_all] using hdataDone - rcases hKeepDone with ⟨hschemas5, hschemaUids5, hschemaLength5, hrequests5, hi5⟩ - have hschemasEval5 : - evalExpr? (config imm) { contract := contract imm, locals := L5 } evm - (.var "schemas") = .ok (.array schemas) := - attesterEvalVarOfGet hschemas5 - have hiEval5 : - evalExpr? (config imm) { contract := contract imm, locals := L5 } evm - (.var "i") = .ok (.int (Int.ofNat i)) := - attesterEvalVarOfGet hi5 - have hindexSchema : - evalIndex? (.array schemas) (.int (Int.ofNat i)) = .ok schema := by - simp [evalIndex?, hlt, hschemaLookup, hschemaNorm hschemaLookup] - have hschemaExpr : - evalExpr? (config imm) { contract := contract imm, locals := L5 } evm - (arrGet "schemas" (.var "i")) = .ok schema := - attesterEvalIndex hschemasEval5 hiEval5 hindexSchema - have hdataExpr : - evalExpr? (config imm) { contract := contract imm, locals := L5 } evm - (.var "data") = .ok (.array (attesterRevocationDataValues uids)) := - attesterEvalVarOfGet hdataFinal - have hrequestExpr : - evalExpr? (config imm) { contract := contract imm, locals := L5 } evm - (.tupleLit [arrGet "schemas" (.var "i"), .var "data"]) = - .ok (attesterMultiRevokeRequestValue schema uids) := by - simpa [attesterMultiRevokeRequestValue] using - attesterEvalMultiRevokeRequest hschemaExpr hdataExpr - have hrequestsLen : - requestsPrefix.length = schemas.length := by - simp [requestsPrefix, attesterMultiRevokeRequestValuesPrefix_length] - obtain ⟨oldRequest, hrequestLookup⟩ := - attesterLookupNth?_exists (xs := requestsPrefix) (i := i) - (by rw [hrequestsLen]; exact hlt) - have hrequestUpdate : - updateNth? requestsPrefix i (attesterMultiRevokeRequestValue schema uids) = - some (attesterMultiRevokeRequestValuesPrefix (i + 1) schemas schemaUids) := by - simpa [requestsPrefix] using - attesterMultiRevokeRequestValuesPrefix_update - (schemas := schemas) (schemaUids := schemaUids) (n := i) - (schema := schema) (uids := uids) hschemaLookup hschemaUidLookup - let requestsNext := attesterMultiRevokeRequestValuesPrefix (i + 1) schemas schemaUids - let L6 := L5.insert "multiRequests" (.array requestsNext) - have hstmtSetRequest : - ExecStmt (config imm) { contract := contract imm, locals := L5 } evm - (arrSet "multiRequests" (.var "i") - (.tupleLit [arrGet "schemas" (.var "i"), .var "data"])) - (.ok { contract := contract imm, locals := L6 } evm) := by - simpa [arrSet, localIndex, requestsPrefix, requestsNext, L6] using - attesterExecAssignLocalArrayIndexOfUpdate - (cfg := config imm) (solm := { contract := contract imm, locals := L5 }) - (evm := evm) (name := "multiRequests") (idxExpr := .var "i") - (rhs := .tupleLit [arrGet "schemas" (.var "i"), .var "data"]) - (xs := requestsPrefix) (xs' := requestsNext) - (i := i) (old := oldRequest) - (value := attesterMultiRevokeRequestValue schema uids) - hrequestExpr hiEval5 hrequests5 (by rw [hrequestsLen]; exact hlt) - hrequestLookup (by simpa [requestsPrefix, requestsNext] using hrequestUpdate) - have hiL6 : L6.get? "i" = some (.int (Int.ofNat i)) := by - simpa [L6] using - (attesterStoreGetInsertOfNe (locals := L5) (name := "i") - (other := "multiRequests") (value := .array requestsNext) hi5 (by decide)) - have hincEval : - evalExpr? (config imm) { contract := contract imm, locals := L6 } evm - (add256 (.var "i") (.intLit 1)) = - .ok (.int (Int.ofNat (i + 1))) := by - exact attesterEvalUInt256AddOne - (cfg := config imm) (C := contract imm) (evm := evm) - (locals := L6) (name := "i") (i := i) hiL6 (by omega) - let L7 := L6.insert "i" (.int (Int.ofNat (i + 1))) - have hstmtInc : - ExecStmt (config imm) { contract := contract imm, locals := L6 } evm - (.assign .localVar (localRef "i") (add256 (.var "i") (.intLit 1))) - (.ok { contract := contract imm, locals := L7 } evm) := by - simpa [localRef, L7] using - attesterExecAssignLocalVar - (cfg := config imm) (solm := { contract := contract imm, locals := L6 }) - (evm := evm) (name := "i") (old := .int (Int.ofNat i)) - (value := .int (Int.ofNat (i + 1))) - (expr := add256 (.var "i") (.intLit 1)) hincEval hiL6 - refine ⟨L7, ?_, ?_⟩ - · exact ExecBlock.consNormal hstmtUids - (ExecBlock.consNormal hstmtUidLength - (ExecBlock.consNormal hstmtRequire - (ExecBlock.consNormal hstmtDataDecl - (ExecBlock.consNormal hstmtJDecl - (ExecBlock.consNormal hinnerLoop - (ExecBlock.consNormal hstmtSetRequest - (ExecBlock.consNormal hstmtInc ExecBlock.nil))))))) - · refine ⟨i + 1, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · have hs6 : L6.get? "schemas" = some (.array schemas) := by - simpa [L6] using - (attesterStoreGetInsertOfNe (locals := L5) (name := "schemas") - (other := "multiRequests") (value := .array requestsNext) hschemas5 - (by decide)) - simpa [L7] using - (attesterStoreGetInsertOfNe (locals := L6) (name := "schemas") - (other := "i") (value := .int (Int.ofNat (i + 1))) hs6 (by decide)) - · have hsu6 : L6.get? "schemaUids" = some (.array schemaUids) := by - simpa [L6] using - (attesterStoreGetInsertOfNe (locals := L5) (name := "schemaUids") - (other := "multiRequests") (value := .array requestsNext) hschemaUids5 - (by decide)) - simpa [L7] using - (attesterStoreGetInsertOfNe (locals := L6) (name := "schemaUids") - (other := "i") (value := .int (Int.ofNat (i + 1))) hsu6 (by decide)) - · have hsl6 : - L6.get? "schemaLength" = some (.int (Int.ofNat schemas.length)) := by - simpa [L6] using - (attesterStoreGetInsertOfNe (locals := L5) (name := "schemaLength") - (other := "multiRequests") (value := .array requestsNext) hschemaLength5 - (by decide)) - simpa [L7] using - (attesterStoreGetInsertOfNe (locals := L6) (name := "schemaLength") - (other := "i") (value := .int (Int.ofNat (i + 1))) hsl6 (by decide)) - · have hmr6 : - L6.get? "multiRequests" = some (.array requestsNext) := by - simp [L6] - simpa [requestsNext, L7] using - (attesterStoreGetInsertOfNe (locals := L6) (name := "multiRequests") - (other := "i") (value := .int (Int.ofNat (i + 1))) hmr6 - (by decide)) - · simp [L7] - · omega - · omega - -theorem attesterMultiRevokeOuterSourceLoop_step - (imm : AttesterImmutables) (evm : EVM.State) - {schemas schemaUids : List Value} - (hschemasBound : schemas.length < 2 ^ 256) - (hlenEq : schemaUids.length = schemas.length) - (hschemaNorm : ∀ {idx schema}, lookupNth? schemas idx = some schema → - normalizeRawBoolWord? schema = .ok schema) - (huidssOk : ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length ≠ 0 ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid)) : - ∀ n locals, attesterMultiRevokeOuterSourceLoopInv schemas schemaUids (n + 1) locals → - ∃ locals', - ExecBlock (config imm) { contract := contract imm, locals := locals } evm - attesterMultiRevokeOuterSourceLoopBody - (.ok { contract := contract imm, locals := locals' } evm) ∧ - attesterMultiRevokeOuterSourceLoopInv schemas schemaUids n locals' := by - intro n locals hInv - exact attesterMultiRevokeOuterSourceLoop_step_current - (imm := imm) (evm := evm) (schemas := schemas) (schemaUids := schemaUids) - hschemasBound hlenEq hschemaNorm n locals hInv - (by - intro idx value hlookup _hcurrent - exact huidssOk hlookup) - -theorem attesterMultiRevokeOuterSourceLoop_step_or_revert - (imm : AttesterImmutables) (evm : EVM.State) - {schemas schemaUids : List Value} - (hschemasBound : schemas.length < 2 ^ 256) - (hlenEq : schemaUids.length = schemas.length) - (hschemaNorm : ∀ {idx schema}, lookupNth? schemas idx = some schema → - normalizeRawBoolWord? schema = .ok schema) - (huidssShape : ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid)) : - ∀ n locals, attesterMultiRevokeOuterSourceLoopInv schemas schemaUids (n + 1) locals → - (ExecBlock (config imm) { contract := contract imm, locals := locals } evm - attesterMultiRevokeOuterSourceLoopBody .reverted) ∨ - ∃ locals', - ExecBlock (config imm) { contract := contract imm, locals := locals } evm - attesterMultiRevokeOuterSourceLoopBody - (.ok { contract := contract imm, locals := locals' } evm) ∧ - attesterMultiRevokeOuterSourceLoopInv schemas schemaUids n locals' := by - intro n locals hInv - have hInvOrig := hInv - rcases hInv with - ⟨i, _hschemas, hschemaUids, _hschemaLength, _hrequests, hi, hvar, _hle⟩ - have hlt : i < schemas.length := by omega - have hltSchemaUids : i < schemaUids.length := by omega - obtain ⟨schemaUidValue, hschemaUidLookupValue⟩ := - attesterLookupNth?_exists (xs := schemaUids) (i := i) hltSchemaUids - obtain ⟨uids, hschemaUidValue, huidsBound, huidsNorm⟩ := - huidssShape hschemaUidLookupValue - cases uids with - | nil => - have hlookupEmpty : lookupNth? schemaUids i = some (.array []) := by - simpa [hschemaUidValue] using hschemaUidLookupValue - exact .inl - (attesterMultiRevokeOuterSourceLoopBody_revert_emptyCurrent - (imm := imm) (evm := evm) (locals := locals) - (schemaUids := schemaUids) (i := i) hschemaUids hi hltSchemaUids hlookupEmpty) - | cons uid rest => - have huidsNe : (uid :: rest).length ≠ 0 := by simp - refine .inr ?_ - exact attesterMultiRevokeOuterSourceLoop_step_current - (imm := imm) (evm := evm) (schemas := schemas) (schemaUids := schemaUids) - hschemasBound hlenEq hschemaNorm n locals hInvOrig - (by - intro idx value hlookup hidxVar - have hidxEq : idx = i := by omega - subst idx - have hvalueEq : value = .array (uid :: rest) := by - have hs : some value = some (.array (uid :: rest)) := by - rw [← hlookup] - simpa [hschemaUidValue] using hschemaUidLookupValue - cases hs - rfl - exact ⟨uid :: rest, hvalueEq, huidsNe, huidsBound, huidsNorm⟩) - -theorem attesterMultiRevokeOuterSourceLoop_from_inv_or_revert - (imm : AttesterImmutables) (evm : EVM.State) - {schemas schemaUids : List Value} - (hschemasBound : schemas.length < 2 ^ 256) - (hlenEq : schemaUids.length = schemas.length) - (hschemaNorm : ∀ {idx schema}, lookupNth? schemas idx = some schema → - normalizeRawBoolWord? schema = .ok schema) - (huidssShape : ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid)) : - ∀ n locals, attesterMultiRevokeOuterSourceLoopInv schemas schemaUids n locals → - (∃ locals', - ExecStmt (config imm) { contract := contract imm, locals := locals } evm - (.while attesterMultiRevokeOuterSourceLoopCond - attesterMultiRevokeOuterSourceLoopBody) - (.ok { contract := contract imm, locals := locals' } evm) ∧ - attesterMultiRevokeOuterSourceLoopInv schemas schemaUids 0 locals') ∨ - ExecStmt (config imm) { contract := contract imm, locals := locals } evm - (.while attesterMultiRevokeOuterSourceLoopCond - attesterMultiRevokeOuterSourceLoopBody) - .reverted := by - intro n - induction n with - | zero => - intro locals hInv - rcases hInv with ⟨i, _hschemas, _hschemaUids, hlen, _hrequests, hi, hvar, _hle⟩ - exact .inl ⟨locals, - ExecStmt.whileFalse - (attesterMultiRevokeOuterSourceLoopCondFalse imm evm hlen hi (by omega)), - ⟨i, _hschemas, _hschemaUids, hlen, _hrequests, hi, hvar, _hle⟩⟩ - | succ n ih => - intro locals hInv - have hInvOrig := hInv - rcases hInv with ⟨i, _hschemas, _hschemaUids, hlen, _hrequests, hi, hvar, _hle⟩ - have hcond := - attesterMultiRevokeOuterSourceLoopCondTrue imm evm hlen hi (by omega) - rcases - attesterMultiRevokeOuterSourceLoop_step_or_revert - (imm := imm) (evm := evm) (schemas := schemas) (schemaUids := schemaUids) - hschemasBound hlenEq hschemaNorm huidssShape n locals hInvOrig - with hbodyRevert | hbodyOk - · exact .inr (ExecStmt.whileRevert hcond hbodyRevert) - · rcases hbodyOk with ⟨locals', hbody, hInv'⟩ - rcases ih locals' hInv' with hdone | hrev - · rcases hdone with ⟨locals'', hloop, hInvDone⟩ - exact .inl ⟨locals'', ExecStmt.whileTrue hcond hbody hloop, hInvDone⟩ - · exact .inr (ExecStmt.whileTrue hcond hbody hrev) - -theorem attesterMultiRevokeOuterSourceLoop_from_inv - (imm : AttesterImmutables) (evm : EVM.State) - {schemas schemaUids : List Value} - (hschemasBound : schemas.length < 2 ^ 256) - (hlenEq : schemaUids.length = schemas.length) - (hschemaNorm : ∀ {idx schema}, lookupNth? schemas idx = some schema → - normalizeRawBoolWord? schema = .ok schema) - (huidssOk : ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length ≠ 0 ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid)) : - ∀ n locals, attesterMultiRevokeOuterSourceLoopInv schemas schemaUids n locals → - ∃ locals', - ExecStmt (config imm) { contract := contract imm, locals := locals } evm - (.while attesterMultiRevokeOuterSourceLoopCond - attesterMultiRevokeOuterSourceLoopBody) - (.ok { contract := contract imm, locals := locals' } evm) ∧ - attesterMultiRevokeOuterSourceLoopInv schemas schemaUids 0 locals' := by - refine execWhile_var - (cfg := config imm) (C := contract imm) (evm := evm) - (cond := attesterMultiRevokeOuterSourceLoopCond) - (body := attesterMultiRevokeOuterSourceLoopBody) - (P := attesterMultiRevokeOuterSourceLoopInv schemas schemaUids) ?_ ?_ ?_ - · intro locals hInv - rcases hInv with ⟨i, _hschemas, _hschemaUids, hlen, _hrequests, hi, hvar, _hle⟩ - exact attesterMultiRevokeOuterSourceLoopCondFalse imm evm hlen hi (by omega) - · intro n locals hInv - rcases hInv with ⟨i, _hschemas, _hschemaUids, hlen, _hrequests, hi, hvar, _hle⟩ - exact attesterMultiRevokeOuterSourceLoopCondTrue imm evm hlen hi (by omega) - · intro n locals hInv - obtain ⟨locals', hbody, hInv'⟩ := - attesterMultiRevokeOuterSourceLoop_step - (imm := imm) (evm := evm) (schemas := schemas) (schemaUids := schemaUids) - hschemasBound hlenEq hschemaNorm huidssOk n locals hInv - exact ⟨locals', hbody, hInv'⟩ - -theorem attesterMultiRevokeOuterSourceLoop - (imm : AttesterImmutables) (evm : EVM.State) - {schemas schemaUids : List Value} {locals : Store} - (hschemasBound : schemas.length < 2 ^ 256) - (hlenEq : schemaUids.length = schemas.length) - (hschemaNorm : ∀ {idx schema}, lookupNth? schemas idx = some schema → - normalizeRawBoolWord? schema = .ok schema) - (huidssOk : ∀ {idx value}, lookupNth? schemaUids idx = some value → - ∃ uids, - value = .array uids ∧ - uids.length ≠ 0 ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid)) - (hschemas : locals.get? "schemas" = some (.array schemas)) - (hschemaUids : locals.get? "schemaUids" = some (.array schemaUids)) - (hschemaLength : locals.get? "schemaLength" = - some (.int (Int.ofNat schemas.length))) - (hrequests : locals.get? "multiRequests" = - some (.array (List.replicate schemas.length attesterMultiRevokeRequestDefault))) - (hi : locals.get? "i" = some (.int 0)) : - ∃ locals', - ExecStmt (config imm) { contract := contract imm, locals := locals } evm - (.while attesterMultiRevokeOuterSourceLoopCond - attesterMultiRevokeOuterSourceLoopBody) - (.ok { contract := contract imm, locals := locals' } evm) ∧ - locals'.get? "multiRequests" = - some (.array - (attesterMultiRevokeRequestValuesPrefix schemas.length schemas schemaUids)) ∧ - locals'.get? "i" = some (.int (Int.ofNat schemas.length)) := by - have hrequests0 : - locals.get? "multiRequests" = - some (.array (attesterMultiRevokeRequestValuesPrefix 0 schemas schemaUids)) := by - simpa [attesterMultiRevokeRequestValuesPrefix_zero] using hrequests - have hInv : - attesterMultiRevokeOuterSourceLoopInv schemas schemaUids schemas.length locals := by - refine ⟨0, hschemas, hschemaUids, hschemaLength, hrequests0, ?_, by simp, by simp⟩ - simpa using hi - obtain ⟨locals', hloop, hInvDone⟩ := - attesterMultiRevokeOuterSourceLoop_from_inv - (imm := imm) (evm := evm) (schemas := schemas) (schemaUids := schemaUids) - hschemasBound hlenEq hschemaNorm huidssOk schemas.length locals hInv - rcases hInvDone with - ⟨i, _hschemasDone, _hschemaUidsDone, _hschemaLengthDone, hrequestsDone, - hiDone, hvar, _hle⟩ - have hiLen : i = schemas.length := by omega - refine ⟨locals', hloop, ?_, ?_⟩ - · simpa [hiLen] using hrequestsDone - · simpa [hiLen] using hiDone - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/NestedArray.lean b/Benchmarks/EAS/Attester/NestedArray.lean deleted file mode 100644 index 7d00aeb8..00000000 --- a/Benchmarks/EAS/Attester/NestedArray.lean +++ /dev/null @@ -1,1046 +0,0 @@ -import Benchmarks.EAS.Attester.OuterArrayInit - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -/-! Helpers for the nested dynamic arrays used by `multiAttest` and `multiRevoke`. -/ - -abbrev attesterSecondArrayPayloadStartWord (I : ExecutionEnv) : UInt256 := - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩ - -abbrev attesterFirstInnerArrayOffsetWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata (attesterSecondArrayPayloadStartWord I).toNat - -abbrev attesterFirstInnerArrayStartWord (I : ExecutionEnv) : UInt256 := - attesterSecondArrayPayloadStartWord I + attesterFirstInnerArrayOffsetWord I - -abbrev attesterFirstInnerArrayLengthWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata (attesterFirstInnerArrayStartWord I).toNat - -abbrev attesterFirstInnerArrayPayloadStartWord (I : ExecutionEnv) : UInt256 := - attesterFirstInnerArrayStartWord I + ⟨32⟩ - -abbrev attesterFirstInnerArrayPayloadEndWord (I : ExecutionEnv) : UInt256 := - attesterFirstInnerArrayPayloadStartWord I + - UInt256.shiftLeft (attesterFirstInnerArrayLengthWord I) ⟨5⟩ - -theorem attesterSecondArrayPayloadStart_toNat {I : ExecutionEnv} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) : - (attesterSecondArrayPayloadStartWord I).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 := by - unfold attesterSecondArrayPayloadStartWord - rw [uadd_toNat] - rw [attesterSecondArrayStart_toNat (I := I) hoffMax] - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide] - exact Nat.mod_eq_of_lt (by - have hoffLe : (calldataWord I.calldata 36).toNat ≤ solcMaxU64 := - Nat.le_of_not_gt hoffMax - norm_num [solcMaxU64, UInt256.size] at hoffLe ⊢ - omega) - -theorem readNat_drop4_at_some_size {cd : ByteArray} {off n : Nat} - (hread : readNat? (cd.toList.drop 4) off = some n) : - 4 + off + 32 ≤ cd.size := by - unfold readNat? readWord? readBytes? at hread - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - by_cases hlen : 32 ≤ cd.toList.length - (4 + off) - · rw [htlen] at hlen - omega - · simp [hlen] at hread - -theorem readNat_drop4_at_some_eq_calldataWord {cd : ByteArray} {off n : Nat} - (hread : readNat? (cd.toList.drop 4) off = some n) : - n = (calldataWord cd (4 + off)).toNat := by - have hsize := readNat_drop4_at_some_size (cd := cd) (off := off) (n := n) hread - have hword := readNat_drop4_at_eq_calldataWord (cd := cd) (off := off) hsize - rw [hword] at hread - cases hread - rfl - -private theorem attester_slt_one_low {a b : UInt256} - (hlt : a.toNat < b.toNat) (hb : b.toNat < 2 ^ 255) : - UInt256.slt a b = ⟨1⟩ := by - unfold UInt256.slt UInt256.sltBool UInt256.fromBool Bool.toUInt256 - rw [if_neg (by omega : ¬ a.toNat ≥ 2 ^ 255), - if_neg (by omega : ¬ b.toNat ≥ 2 ^ 255)] - rw [decide_eq_true (show a < b by - show a.toNat < b.toNat - exact hlt)] - native_decide - -private theorem attester_sgt_zero_low {a b : UInt256} - (hle : a.toNat ≤ b.toNat) (hb : b.toNat < 2 ^ 255) : - UInt256.sgt a b = ⟨0⟩ := by - unfold UInt256.sgt UInt256.sgtBool UInt256.fromBool Bool.toUInt256 - rw [if_neg (by omega : ¬ a.toNat ≥ 2 ^ 255), - if_neg (by omega : ¬ b.toNat ≥ 2 ^ 255)] - rw [decide_eq_false (show ¬ a > b by - show ¬ a.toNat > b.toNat - omega)] - native_decide - -set_option maxHeartbeats 1000000 in -theorem attesterFirstInnerArrayGuardFacts_of_decode {I : ExecutionEnv} - {elem : ElemType} {relativeOffset : Nat} {inner : List Value} {innerEnd : Nat} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hreadFirst : readNat? (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32) = some relativeOffset) - (hinner : decodeABIValue? (.dynamicArray (.elem elem)) (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) = - some (.array inner, innerEnd)) - (hsizeSigned : I.calldata.size < 2 ^ 255) : - UInt256.slt (attesterFirstInnerArrayOffsetWord I) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩ ∧ - UInt256.gt (attesterFirstInnerArrayLengthWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩ ∧ - UInt256.sgt (attesterFirstInnerArrayStartWord I + ⟨32⟩) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft (attesterFirstInnerArrayLengthWord I) ⟨5⟩)) = ⟨0⟩ := by - obtain ⟨innerLen, hreadLen, hlenMax, hend, hendLe, _hlenValues⟩ := - decodeABIValue_dynamicArray_elem32_facts hinner - have hsize : I.calldata.size < UInt256.size := lt_size_of_lt_sign hsizeSigned - have hdropLen : (I.calldata.toList.drop 4).length = I.calldata.size - 4 := by - rw [List.length_drop] - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [htlen] - have hbaseToNat : - (attesterSecondArrayPayloadStartWord I).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 := - attesterSecondArrayPayloadStart_toNat (I := I) hoffMax - have hoffWordToNat : - (attesterFirstInnerArrayOffsetWord I).toNat = relativeOffset := by - unfold attesterFirstInnerArrayOffsetWord - rw [hbaseToNat] - have hreadEq := - readNat_drop4_at_some_eq_calldataWord (cd := I.calldata) hreadFirst - simpa [Nat.add_assoc] using hreadEq.symm - have hinnerLenReadSizeEarly := readNat?_some_length hreadLen - have hinnerHeadInCalldataEarly : - 4 + ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) + 32 ≤ - I.calldata.size := by - rw [hdropLen] at hinnerLenReadSizeEarly - omega - have hstartToNat : - (attesterFirstInnerArrayStartWord I).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 + relativeOffset := by - unfold attesterFirstInnerArrayStartWord - rw [uadd_toNat, hbaseToNat, hoffWordToNat] - exact Nat.mod_eq_of_lt (by - omega) - have hlenWordToNat : - (attesterFirstInnerArrayLengthWord I).toNat = innerLen := by - unfold attesterFirstInnerArrayLengthWord - rw [hstartToNat] - have hreadEq := - readNat_drop4_at_some_eq_calldataWord (cd := I.calldata) hreadLen - simpa [Nat.add_assoc] using hreadEq.symm - have hinnerLenWordOk : - UInt256.gt (attesterFirstInnerArrayLengthWord I) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - have hmaxToNat : - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = - solcMaxU64 := by - native_decide - rw [hlenWordToNat, hmaxToNat] - exact Nat.le_of_not_gt hlenMax - have hinnerHeadInCalldata : - 4 + ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) + 32 ≤ - I.calldata.size := hinnerHeadInCalldataEarly - have hpayloadInCalldata : - 4 + ((calldataWord I.calldata 36).toNat + 32 + relativeOffset + 32 + - 32 * innerLen) ≤ I.calldata.size := by - rw [hend] at hendLe - rw [hdropLen] at hendLe - omega - have hsubHeadToNat : - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)).toNat = - I.calldata.size - (4 + (calldataWord I.calldata 36).toNat + 32) := by - rw [usub_toNat] - · rw [ulit_toNat' I.calldata.size hsize, hbaseToNat] - · rw [ulit_toNat' I.calldata.size hsize, hbaseToNat] - omega - have hrhsOffsetToNat : - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)) - (UInt256.lnot (⟨30⟩ : UInt256))).toNat = - I.calldata.size - (4 + (calldataWord I.calldata 36).toNat + 32) - 31 := by - change ((UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I) + UInt256.lnot (⟨30⟩ : UInt256)).toNat = - I.calldata.size - (4 + (calldataWord I.calldata 36).toNat + 32) - 31) - rw [uadd_toNat, hsubHeadToNat] - have hlnot : (UInt256.lnot (⟨30⟩ : UInt256)).toNat = UInt256.size - 31 := by - native_decide - rw [hlnot] - have hsplit : - I.calldata.size - (4 + (calldataWord I.calldata 36).toNat + 32) + - (UInt256.size - 31) = - UInt256.size + - (I.calldata.size - (4 + (calldataWord I.calldata 36).toNat + 32) - 31) := by - omega - rw [hsplit, Nat.add_mod_left] - exact Nat.mod_eq_of_lt (by - have hleSub : - I.calldata.size - (4 + (calldataWord I.calldata 36).toNat + 32) - 31 ≤ - I.calldata.size := by - omega - exact lt_of_le_of_lt hleSub hsize) - have hoffsetGuard : - UInt256.slt (attesterFirstInnerArrayOffsetWord I) - (UInt256.add - (UInt256.sub (UInt256.ofNat I.calldata.size) - (attesterSecondArrayPayloadStartWord I)) - (UInt256.lnot (⟨30⟩ : UInt256))) = ⟨1⟩ := by - apply attester_slt_one_low - · rw [hoffWordToNat, hrhsOffsetToNat] - omega - · rw [hrhsOffsetToNat] - omega - have hinnerPayloadStartToNat : - (attesterFirstInnerArrayStartWord I + ⟨32⟩).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 + relativeOffset + 32 := by - rw [uadd_toNat, hstartToNat] - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide] - exact Nat.mod_eq_of_lt (by - omega) - have hshiftLenToNat : - (UInt256.shiftLeft (attesterFirstInnerArrayLengthWord I) ⟨5⟩).toNat = - 32 * innerLen := by - have hle : (attesterFirstInnerArrayLengthWord I).toNat ≤ solcMaxU64 := by - rw [hlenWordToNat] - exact Nat.le_of_not_gt hlenMax - simpa [hlenWordToNat] using - attesterShiftLeft5_toNat_of_le (attesterFirstInnerArrayLengthWord I) hle - have hsubPayloadToNat : - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft (attesterFirstInnerArrayLengthWord I) ⟨5⟩)).toNat = - I.calldata.size - 32 * innerLen := by - rw [usub_toNat] - · rw [ulit_toNat' I.calldata.size hsize, hshiftLenToNat] - · rw [ulit_toNat' I.calldata.size hsize, hshiftLenToNat] - omega - have hpayloadGuard : - UInt256.sgt (attesterFirstInnerArrayStartWord I + ⟨32⟩) - (UInt256.sub (UInt256.ofNat I.calldata.size) - (UInt256.shiftLeft (attesterFirstInnerArrayLengthWord I) ⟨5⟩)) = ⟨0⟩ := by - apply attester_sgt_zero_low - · rw [hinnerPayloadStartToNat, hsubPayloadToNat] - omega - · rw [hsubPayloadToNat] - omega - exact ⟨hoffsetGuard, hinnerLenWordOk, hpayloadGuard⟩ - -theorem attesterFirstInnerArrayLengthWord_toNat_of_decode {I : ExecutionEnv} - {elem : ElemType} {relativeOffset : Nat} {inner : List Value} {innerEnd : Nat} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hreadFirst : readNat? (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32) = some relativeOffset) - (hinner : decodeABIValue? (.dynamicArray (.elem elem)) (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) = - some (.array inner, innerEnd)) - (hsizeSigned : I.calldata.size < 2 ^ 255) : - (attesterFirstInnerArrayLengthWord I).toNat = inner.length := by - obtain ⟨innerLen, hreadLen, _hlenMax, _hend, _hendLe, hlenValues⟩ := - decodeABIValue_dynamicArray_elem32_facts hinner - have hsize : I.calldata.size < UInt256.size := lt_size_of_lt_sign hsizeSigned - have hdropLen : (I.calldata.toList.drop 4).length = I.calldata.size - 4 := by - rw [List.length_drop] - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [htlen] - have hbaseToNat : - (attesterSecondArrayPayloadStartWord I).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 := - attesterSecondArrayPayloadStart_toNat (I := I) hoffMax - have hoffWordToNat : - (attesterFirstInnerArrayOffsetWord I).toNat = relativeOffset := by - unfold attesterFirstInnerArrayOffsetWord - rw [hbaseToNat] - have hreadEq := - readNat_drop4_at_some_eq_calldataWord (cd := I.calldata) hreadFirst - simpa [Nat.add_assoc] using hreadEq.symm - have hinnerLenReadSize := readNat?_some_length hreadLen - have hinnerHeadInCalldata : - 4 + ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) + 32 ≤ - I.calldata.size := by - rw [hdropLen] at hinnerLenReadSize - omega - have hstartToNat : - (attesterFirstInnerArrayStartWord I).toNat = - 4 + (calldataWord I.calldata 36).toNat + 32 + relativeOffset := by - unfold attesterFirstInnerArrayStartWord - rw [uadd_toNat, hbaseToNat, hoffWordToNat] - exact Nat.mod_eq_of_lt (by - omega) - have hword : - (attesterFirstInnerArrayLengthWord I).toNat = innerLen := by - unfold attesterFirstInnerArrayLengthWord - rw [hstartToNat] - have hreadEq := - readNat_drop4_at_some_eq_calldataWord (cd := I.calldata) hreadLen - simpa [Nat.add_assoc] using hreadEq.symm - rw [hword, hlenValues] - -theorem attesterFirstInnerArrayLengthWord_le_solcMaxU64_of_decode {I : ExecutionEnv} - {elem : ElemType} {relativeOffset : Nat} {inner : List Value} {innerEnd : Nat} - (hoffMax : ¬ solcMaxU64 < (calldataWord I.calldata 36).toNat) - (hreadFirst : readNat? (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32) = some relativeOffset) - (hinner : decodeABIValue? (.dynamicArray (.elem elem)) (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) = - some (.array inner, innerEnd)) - (hsizeSigned : I.calldata.size < 2 ^ 255) : - (attesterFirstInnerArrayLengthWord I).toNat ≤ solcMaxU64 := by - obtain ⟨_innerLen, _hreadLen, hlenMax, _hend, _hendLe, hlenValues⟩ := - decodeABIValue_dynamicArray_elem32_facts hinner - rw [attesterFirstInnerArrayLengthWord_toNat_of_decode - (I := I) (elem := elem) hoffMax hreadFirst hinner hsizeSigned, hlenValues] - exact Nat.le_of_not_gt hlenMax - -theorem decodeABIArrayDynamicElems_first {ty : ABIType} {bytes : List UInt8} - {base n : Nat} {values : List Value} {endOffset : Nat} - (h : decodeABIArrayDynamicElems? ty (n + 1) bytes base = - some (values, endOffset)) : - ∃ relativeOffset value valueEnd valuesRest restEnd, - readNat? bytes base = some relativeOffset ∧ - decodeABIValue? ty bytes (base + relativeOffset) = some (value, valueEnd) ∧ - decodeABIArrayDynamicElemsFrom? ty n bytes base 32 ((n + 1) * 32) - (max (base + (n + 1) * 32) valueEnd) = - some (valuesRest, restEnd) ∧ - values = value :: valuesRest ∧ - endOffset = restEnd := by - unfold decodeABIArrayDynamicElems? at h - rw [decodeABIArrayDynamicElemsFrom?] at h - cases hread : readNat? bytes base with - | none => - simp [hread] at h - | some relativeOffset => - simp [hread] at h - cases hval : decodeABIValue? ty bytes (base + relativeOffset) with - | none => - simp [hval] at h - | some p => - rcases p with ⟨value, valueEnd⟩ - simp [hval] at h - cases hrest : - decodeABIArrayDynamicElemsFrom? ty n bytes base (0 + 32) ((n + 1) * 32) - (max (base + (n + 1) * 32) valueEnd) with - | none => - simp [hrest] at h - | some q => - rcases q with ⟨valuesRest, restEnd⟩ - simp [hrest] at h - rcases h with ⟨hvalues, hend⟩ - exact ⟨relativeOffset, value, valueEnd, valuesRest, restEnd, - by simpa using hread, hval, by simpa using hrest, - hvalues.symm, hend.symm⟩ - -theorem lookupNth?_some_length {α : Type} : - ∀ {xs : List α} {i : Nat} {value : α}, - lookupNth? xs i = some value → i < xs.length - | [], _, _, h => by simp [lookupNth?] at h - | _ :: _, 0, _, _ => by simp - | _ :: xs, i + 1, value, h => by - have htail : lookupNth? xs i = some value := by - simpa [lookupNth?] using h - have hlt := lookupNth?_some_length htail - simpa using Nat.succ_lt_succ hlt - -theorem decodeABIArrayDynamicElemsFrom_lookup {ty : ABIType} {n : Nat} - {bytes : List UInt8} {base headCursor headSize maxEnd : Nat} - {values : List Value} {endOffset i : Nat} {value : Value} - (h : decodeABIArrayDynamicElemsFrom? ty n bytes base headCursor headSize maxEnd = - some (values, endOffset)) - (hlookup : lookupNth? values i = some value) : - ∃ relativeOffset valueEnd, - readNat? bytes (base + headCursor + 32 * i) = some relativeOffset ∧ - decodeABIValue? ty bytes (base + relativeOffset) = some (value, valueEnd) := by - induction n generalizing headCursor maxEnd values endOffset i with - | zero => - simp [decodeABIArrayDynamicElemsFrom?] at h - rcases h with ⟨hvalues, _hend⟩ - cases hvalues - simp [lookupNth?] at hlookup - | succ n ih => - rw [decodeABIArrayDynamicElemsFrom?] at h - cases hread : readNat? bytes (base + headCursor) with - | none => - simp [hread] at h - | some relativeOffset => - simp [hread] at h - cases hval : decodeABIValue? ty bytes (base + relativeOffset) with - | none => - simp [hval] at h - | some p => - rcases p with ⟨headValue, valueEnd⟩ - simp [hval] at h - cases hrest : - decodeABIArrayDynamicElemsFrom? ty n bytes base (headCursor + 32) - headSize (max maxEnd valueEnd) with - | none => - simp [hrest] at h - | some q => - rcases q with ⟨valuesRest, restEnd⟩ - simp [hrest] at h - rcases h with ⟨hvalues, _hend⟩ - cases hvalues - cases i with - | zero => - simp [lookupNth?] at hlookup - cases hlookup - refine ⟨relativeOffset, valueEnd, ?_, hval⟩ - simpa using hread - | succ i => - have htail : lookupNth? valuesRest i = some value := by - simpa [lookupNth?] using hlookup - obtain ⟨tailOffset, tailEnd, htailRead, htailVal⟩ := - ih hrest htail - refine ⟨tailOffset, tailEnd, ?_, htailVal⟩ - simpa [Nat.mul_succ, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] - using htailRead - -theorem decodeABIArrayDynamicElems_lookup {ty : ABIType} {n : Nat} - {bytes : List UInt8} {base : Nat} - {values : List Value} {endOffset i : Nat} {value : Value} - (h : decodeABIArrayDynamicElems? ty n bytes base = some (values, endOffset)) - (hlookup : lookupNth? values i = some value) : - ∃ relativeOffset valueEnd, - readNat? bytes (base + 32 * i) = some relativeOffset ∧ - decodeABIValue? ty bytes (base + relativeOffset) = some (value, valueEnd) := by - unfold decodeABIArrayDynamicElems? at h - simpa [Nat.add_assoc] using - decodeABIArrayDynamicElemsFrom_lookup (ty := ty) (n := n) (bytes := bytes) - (base := base) (headCursor := 0) (headSize := n * 32) - (maxEnd := base + n * 32) h hlookup - -theorem decodeABIValue_nestedDynamicArray_lookup {elem : ABIType} - {bytes : List UInt8} {start : Nat} {values : List Value} {endOffset i : Nat} - {inner : List Value} - (hdec : decodeABIValue? (.dynamicArray (.dynamicArray elem)) bytes start = - some (.array values, endOffset)) - (hlookup : lookupNth? values i = some (.array inner)) : - ∃ len relativeOffset innerEnd, - readNat? bytes start = some len ∧ - ¬ solcMaxLen DecodeMode.modern < len ∧ - i < len ∧ - readNat? bytes (start + 32 + 32 * i) = some relativeOffset ∧ - decodeABIValue? (.dynamicArray elem) bytes (start + 32 + relativeOffset) = - some (.array inner, innerEnd) := by - unfold decodeABIValue? at hdec - cases hreadLen : readNat? bytes start with - | none => - simp [hreadLen] at hdec - | some len => - by_cases hlenMax : solcMaxU64 < len - · simp [hreadLen, hlenMax, solcMaxLen] at hdec - · simp [hreadLen, hlenMax, solcMaxLen, isDynamicABIType] at hdec - cases hvals : - decodeABIArrayDynamicElems? (.dynamicArray elem) len bytes (start + 32) with - | none => - simp [hvals] at hdec - | some p => - rcases p with ⟨values0, end0⟩ - simp [hvals] at hdec - rcases hdec with ⟨hvalues, _hend⟩ - cases hvalues - have hlookup0 : lookupNth? values i = some (.array inner) := hlookup - obtain ⟨relativeOffset, innerEnd, hread, hinner⟩ := - decodeABIArrayDynamicElems_lookup - (ty := .dynamicArray elem) (n := len) (bytes := bytes) - (base := start + 32) hvals hlookup0 - have hi : i < len := by - have hlt := lookupNth?_some_length hlookup0 - have hlen := decodeABIArrayDynamicElems_length hvals - omega - refine ⟨len, relativeOffset, innerEnd, (by simpa [hreadLen]), ?_, hi, ?_, - hinner⟩ - · simpa [solcMaxLen] using hlenMax - · simpa [Nat.add_assoc] using hread - -theorem decodeABIValue_nestedDynamicArray_lookup_shape {elem : ABIType} - {bytes : List UInt8} {start : Nat} {values : List Value} {endOffset i : Nat} - {value : Value} - (hdec : decodeABIValue? (.dynamicArray (.dynamicArray elem)) bytes start = - some (.array values, endOffset)) - (hlookup : lookupNth? values i = some value) : - ∃ len relativeOffset inner innerEnd, - value = .array inner ∧ - readNat? bytes start = some len ∧ - ¬ solcMaxLen DecodeMode.modern < len ∧ - i < len ∧ - readNat? bytes (start + 32 + 32 * i) = some relativeOffset ∧ - decodeABIValue? (.dynamicArray elem) bytes (start + 32 + relativeOffset) = - some (.array inner, innerEnd) := by - unfold decodeABIValue? at hdec - cases hreadLen : readNat? bytes start with - | none => - simp [hreadLen] at hdec - | some len => - by_cases hlenMax : solcMaxU64 < len - · simp [hreadLen, hlenMax, solcMaxLen] at hdec - · simp [hreadLen, hlenMax, solcMaxLen, isDynamicABIType] at hdec - cases hvals : - decodeABIArrayDynamicElems? (.dynamicArray elem) len bytes (start + 32) with - | none => - simp [hvals] at hdec - | some p => - rcases p with ⟨values0, end0⟩ - simp [hvals] at hdec - rcases hdec with ⟨hvalues, _hend⟩ - cases hvalues - have hlookup0 : lookupNth? values i = some value := hlookup - obtain ⟨relativeOffset, innerEnd, hread, hinnerValue⟩ := - decodeABIArrayDynamicElems_lookup - (ty := .dynamicArray elem) (n := len) (bytes := bytes) - (base := start + 32) hvals hlookup0 - obtain ⟨inner, hvalueArray⟩ := - decodeABIValue_dynamicArray_is_array hinnerValue - have hi : i < len := by - have hlt := lookupNth?_some_length hlookup0 - have hlen := decodeABIArrayDynamicElems_length hvals - omega - refine ⟨len, relativeOffset, inner, innerEnd, hvalueArray, (by simpa [hreadLen]), - ?_, hi, ?_, ?_⟩ - · simpa [solcMaxLen] using hlenMax - · simpa [Nat.add_assoc] using hread - · simpa [hvalueArray] using hinnerValue - -theorem decodeABIValue_nestedDynamicArray_first {elem : ABIType} - {bytes : List UInt8} {start : Nat} {values : List Value} {endOffset : Nat} - (hdec : decodeABIValue? (.dynamicArray (.dynamicArray elem)) bytes start = - some (.array values, endOffset)) - (hne : values.length ≠ 0) : - ∃ n relativeOffset inner innerEnd valuesRest restEnd, - readNat? bytes start = some (n + 1) ∧ - ¬ solcMaxLen DecodeMode.modern < n + 1 ∧ - readNat? bytes (start + 32) = some relativeOffset ∧ - decodeABIValue? (.dynamicArray elem) bytes (start + 32 + relativeOffset) = - some (.array inner, innerEnd) ∧ - decodeABIArrayDynamicElemsFrom? (.dynamicArray elem) n bytes (start + 32) 32 - ((n + 1) * 32) (max (start + 32 + (n + 1) * 32) innerEnd) = - some (valuesRest, restEnd) ∧ - values = .array inner :: valuesRest ∧ - endOffset = restEnd := by - unfold decodeABIValue? at hdec - cases hreadLen : readNat? bytes start with - | none => - simp [hreadLen] at hdec - | some len => - by_cases hlenMax : solcMaxU64 < len - · simp [hreadLen, hlenMax, solcMaxLen] at hdec - · simp [hreadLen, hlenMax, solcMaxLen, isDynamicABIType] at hdec - cases hvals : - decodeABIArrayDynamicElems? (.dynamicArray elem) len bytes (start + 32) with - | none => - simp [hvals] at hdec - | some p => - rcases p with ⟨values0, end0⟩ - simp [hvals] at hdec - rcases hdec with ⟨hvalues, hend⟩ - cases hvalues - cases hend - have hvaluesLen := decodeABIArrayDynamicElems_length hvals - cases len with - | zero => - simp at hvaluesLen - exfalso - exact hne (by rw [hvaluesLen]; simp) - | succ n => - obtain ⟨relativeOffset, value, valueEnd, valuesRest, restEnd, - hreadFirst, hvalue, hrest, hvalsShape, hrestEnd⟩ := - decodeABIArrayDynamicElems_first (ty := .dynamicArray elem) - (bytes := bytes) (base := start + 32) (n := n) - hvals - obtain ⟨inner, hinner⟩ := decodeABIValue_dynamicArray_is_array hvalue - subst hinner - exact ⟨n, relativeOffset, inner, valueEnd, valuesRest, restEnd, - rfl, by simpa [solcMaxLen] using hlenMax, - hreadFirst, hvalue, hrest, - hvalsShape, hrestEnd⟩ - -theorem attesterDecodeCalldata_twoDynamicArrays_first_decode {cd : ByteArray} - {callargs : Store} {name0 name1 : Ident} {elem1 : ABIType} - (hnames : name1 ≠ name0) - (hdec : decodeCalldata [name0, name1] [.dynamicArray bytes32, - .dynamicArray (.dynamicArray elem1)] cd = some callargs) : - ∃ xs endOffset, - decodeABIValue? (.dynamicArray bytes32) (cd.toList.drop 4) - (calldataWord cd 4).toNat = - some (.array xs, endOffset) ∧ - callargs.get? name0 = some (.array xs) := by - unfold decodeCalldata at hdec - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - simp [decodeCalldata.decodeArgs, abiTupleHeadSize?, isDynamicABIType, - bind, Option.bind] at hdec - rcases hdec with ⟨_hlen4, _hhuge, _hargHuge, _htotalHuge, hdec⟩ - by_cases hshort : cd.toList.length - 4 < 64 - · simp [hshort] at hdec - · simp [hshort] at hdec - have hsz68 : 68 ≤ cd.size := by - rw [htlen] at hshort - omega - cases hvals : - decodeABIValues? [.dynamicArray bytes32, .dynamicArray (.dynamicArray elem1)] - (List.drop 4 cd.toList) 0 0 64 64 with - | none => - simp [hvals] at hdec - | some p => - rcases p with ⟨values, endOffset⟩ - simp [hvals] at hdec - rw [decodeABIValues?] at hvals - simp [isDynamicABIType, bind, Option.bind] at hvals - cases hread0 : readNat? (List.drop 4 cd.toList) 0 with - | none => simp [hread0] at hvals - | some off0 => - by_cases hmax0 : solcMaxLen DecodeMode.modern < off0 - · simp [hread0] at hvals - have hle : off0 ≤ solcMaxU64 := hvals.1 - simp [solcMaxLen] at hmax0 - omega - · simp [hread0] at hvals - cases hv0 : decodeABIValue? (.dynamicArray bytes32) - (List.drop 4 cd.toList) off0 with - | none => simp [hv0] at hvals - | some p0 => - rcases p0 with ⟨v0, end0⟩ - obtain ⟨xs, hv0arr⟩ := decodeABIValue_dynamicArray_is_array hv0 - have hv0xs : - decodeABIValue? (.dynamicArray bytes32) (cd.toList.drop 4) off0 = - some (.array xs, end0) := by - simpa [hv0arr] using hv0 - simp [hv0] at hvals - cases hrest : - decodeABIValues? [.dynamicArray (.dynamicArray elem1)] - (List.drop 4 cd.toList) 0 32 64 (max 64 end0) with - | none => simp [hrest] at hvals - | some prest => - rcases prest with ⟨valuesRest, endRest⟩ - simp [hrest] at hvals - rw [decodeABIValues?] at hrest - simp [isDynamicABIType, bind, Option.bind] at hrest - cases hread1 : readNat? (List.drop 4 cd.toList) 32 with - | none => simp [hread1] at hrest - | some off1 => - by_cases hmax1 : solcMaxLen DecodeMode.modern < off1 - · simp [hread1] at hrest - have hle : off1 ≤ solcMaxU64 := hrest.1 - simp [solcMaxLen] at hmax1 - omega - · simp [hread1] at hrest - cases hv1 : - decodeABIValue? (.dynamicArray (.dynamicArray elem1)) - (List.drop 4 cd.toList) off1 with - | none => simp [hv1] at hrest - | some p1 => - rcases p1 with ⟨v1, end1⟩ - obtain ⟨ys, hv1arr⟩ := - decodeABIValue_dynamicArray_is_array hv1 - simp [hv1] at hrest - rcases hrest with ⟨_hoff1le, hrestEq⟩ - simp [decodeABIValues?] at hrestEq - rcases hrestEq with ⟨hvaluesRestEq, _hendRestEq⟩ - rcases hvals with ⟨_hoff0le, hvalsEq⟩ - rcases hvalsEq with ⟨hvaluesEq, _hendEq⟩ - cases hvaluesRestEq - rw [← hvaluesEq, hv0arr, hv1arr] at hdec - simp [decodeCalldata.insertValues] at hdec - cases hdec - have hreadOff0 := readNat_drop4_zero_eq_calldataWord - (cd := cd) (by omega : 36 ≤ cd.size) - rw [hread0] at hreadOff0 - cases hreadOff0 - refine ⟨xs, end0, ?_, ?_⟩ - · exact hv0xs - · rw [Std.HashMap.get?_eq_getElem?] - rw [Std.HashMap.getElem?_insert] - simp [hnames] - -theorem attesterDecodeCalldata_twoDynamicArrays_second_decode {cd : ByteArray} - {callargs : Store} {name0 name1 : Ident} {elem1 : ABIType} - (hdec : decodeCalldata [name0, name1] [.dynamicArray bytes32, - .dynamicArray (.dynamicArray elem1)] cd = some callargs) : - ∃ ys endOffset, - decodeABIValue? (.dynamicArray (.dynamicArray elem1)) (cd.toList.drop 4) - (calldataWord cd 36).toNat = - some (.array ys, endOffset) ∧ - callargs.get? name1 = some (.array ys) := by - unfold decodeCalldata at hdec - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - simp [decodeCalldata.decodeArgs, abiTupleHeadSize?, isDynamicABIType, - bind, Option.bind] at hdec - rcases hdec with ⟨_hlen4, _hhuge, _hargHuge, _htotalHuge, hdec⟩ - by_cases hshort : cd.toList.length - 4 < 64 - · simp [hshort] at hdec - · simp [hshort] at hdec - have hsz68 : 68 ≤ cd.size := by - rw [htlen] at hshort - omega - cases hvals : - decodeABIValues? [.dynamicArray bytes32, .dynamicArray (.dynamicArray elem1)] - (List.drop 4 cd.toList) 0 0 64 64 with - | none => - simp [hvals] at hdec - | some p => - rcases p with ⟨values, endOffset⟩ - simp [hvals] at hdec - rw [decodeABIValues?] at hvals - simp [isDynamicABIType, bind, Option.bind] at hvals - cases hread0 : readNat? (List.drop 4 cd.toList) 0 with - | none => simp [hread0] at hvals - | some off0 => - by_cases hmax0 : solcMaxLen DecodeMode.modern < off0 - · simp [hread0] at hvals - have hle : off0 ≤ solcMaxU64 := hvals.1 - simp [solcMaxLen] at hmax0 - omega - · simp [hread0] at hvals - cases hv0 : decodeABIValue? (.dynamicArray bytes32) - (List.drop 4 cd.toList) off0 with - | none => simp [hv0] at hvals - | some p0 => - rcases p0 with ⟨v0, end0⟩ - obtain ⟨xs, hv0arr⟩ := decodeABIValue_dynamicArray_is_array hv0 - simp [hv0] at hvals - cases hrest : - decodeABIValues? [.dynamicArray (.dynamicArray elem1)] - (List.drop 4 cd.toList) 0 32 64 (max 64 end0) with - | none => simp [hrest] at hvals - | some prest => - rcases prest with ⟨valuesRest, endRest⟩ - simp [hrest] at hvals - rw [decodeABIValues?] at hrest - simp [isDynamicABIType, bind, Option.bind] at hrest - cases hread1 : readNat? (List.drop 4 cd.toList) 32 with - | none => simp [hread1] at hrest - | some off1 => - by_cases hmax1 : solcMaxLen DecodeMode.modern < off1 - · simp [hread1] at hrest - have hle : off1 ≤ solcMaxU64 := hrest.1 - simp [solcMaxLen] at hmax1 - omega - · simp [hread1] at hrest - cases hv1 : - decodeABIValue? (.dynamicArray (.dynamicArray elem1)) - (List.drop 4 cd.toList) off1 with - | none => simp [hv1] at hrest - | some p1 => - rcases p1 with ⟨v1, end1⟩ - obtain ⟨ys, hv1arr⟩ := - decodeABIValue_dynamicArray_is_array hv1 - have hv1ys : - decodeABIValue? (.dynamicArray (.dynamicArray elem1)) - (cd.toList.drop 4) off1 = - some (.array ys, end1) := by - simpa [hv1arr] using hv1 - simp [hv1] at hrest - rcases hrest with ⟨_hoff1le, hrestEq⟩ - simp [decodeABIValues?] at hrestEq - rcases hrestEq with ⟨hvaluesRestEq, _hendRestEq⟩ - rcases hvals with ⟨_hoff0le, hvalsEq⟩ - rcases hvalsEq with ⟨hvaluesEq, _hendEq⟩ - cases hvaluesRestEq - rw [← hvaluesEq, hv0arr, hv1arr] at hdec - simp [decodeCalldata.insertValues] at hdec - cases hdec - have hreadOff1 := readNat_drop4_32_eq_calldataWord - (cd := cd) hsz68 - rw [hread1] at hreadOff1 - cases hreadOff1 - refine ⟨ys, end1, ?_, ?_⟩ - · exact hv1ys - · simp [Std.HashMap.get?_eq_getElem?] - -theorem attesterDecode_multiRevoke_first_inner_decode (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} {schemaUids : List Value} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hSchemaUids : callargs.get? "schemaUids" = some (.array schemaUids)) - (hne : schemaUids.length ≠ 0) : - ∃ n relativeOffset inner innerEnd valuesRest restEnd, - readNat? (I.calldata.toList.drop 4) (calldataWord I.calldata 36).toNat = - some (n + 1) ∧ - ¬ solcMaxLen DecodeMode.modern < n + 1 ∧ - readNat? (I.calldata.toList.drop 4) ((calldataWord I.calldata 36).toNat + 32) = - some relativeOffset ∧ - decodeABIValue? (.dynamicArray bytes32) (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) = - some (.array inner, innerEnd) ∧ - decodeABIArrayDynamicElemsFrom? (.dynamicArray bytes32) n - (I.calldata.toList.drop 4) ((calldataWord I.calldata 36).toNat + 32) 32 - ((n + 1) * 32) - (max ((calldataWord I.calldata 36).toNat + 32 + (n + 1) * 32) innerEnd) = - some (valuesRest, restEnd) ∧ - schemaUids = .array inner :: valuesRest ∧ - restEnd = restEnd := by - have hdec' : - decodeCalldata ["schemas", "schemaUids"] - [.dynamicArray bytes32, .dynamicArray (.dynamicArray bytes32)] I.calldata = - some callargs := by - simpa [decodeCalldataWithMode, config, multiRevokeTransition, transitionSignature, - bytes32Array, bytes32NestedArray] using hdec - obtain ⟨ys, endOffset, hsecond, hget⟩ := - attesterDecodeCalldata_twoDynamicArrays_second_decode - (cd := I.calldata) (callargs := callargs) - (name0 := "schemas") (name1 := "schemaUids") (elem1 := bytes32) hdec' - have hys : ys = schemaUids := by - cases Option.some.inj (hget.symm.trans hSchemaUids) - rfl - have hneYs : ys.length ≠ 0 := by - intro hzero - exact hne (by rw [← hys, hzero]) - obtain ⟨n, relativeOffset, inner, innerEnd, valuesRest, restEnd, - hlen, hlenMax, hreadFirst, hinner, hrest, hshape, _hend⟩ := - decodeABIValue_nestedDynamicArray_first (elem := bytes32) hsecond hneYs - refine ⟨n, relativeOffset, inner, innerEnd, valuesRest, restEnd, - hlen, hlenMax, ?_, ?_, ?_, ?_, rfl⟩ - · simpa [Nat.add_assoc] using hreadFirst - · simpa [Nat.add_assoc] using hinner - · simpa [Nat.add_assoc] using hrest - · rw [← hys, hshape] - -theorem attesterDecode_multiRevoke_inner_decode_at (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} {schemaUids inner : List Value} {idx : Nat} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hSchemaUids : callargs.get? "schemaUids" = some (.array schemaUids)) - (hlookup : lookupNth? schemaUids idx = some (.array inner)) : - ∃ len relativeOffset innerEnd, - readNat? (I.calldata.toList.drop 4) (calldataWord I.calldata 36).toNat = - some len ∧ - ¬ solcMaxLen DecodeMode.modern < len ∧ - idx < len ∧ - readNat? (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32 + 32 * idx) = - some relativeOffset ∧ - decodeABIValue? (.dynamicArray bytes32) (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) = - some (.array inner, innerEnd) := by - have hdec' : - decodeCalldata ["schemas", "schemaUids"] - [.dynamicArray bytes32, .dynamicArray (.dynamicArray bytes32)] I.calldata = - some callargs := by - simpa [decodeCalldataWithMode, config, multiRevokeTransition, transitionSignature, - bytes32Array, bytes32NestedArray] using hdec - obtain ⟨ys, endOffset, hsecond, hget⟩ := - attesterDecodeCalldata_twoDynamicArrays_second_decode - (cd := I.calldata) (callargs := callargs) - (name0 := "schemas") (name1 := "schemaUids") (elem1 := bytes32) hdec' - have hys : ys = schemaUids := by - cases Option.some.inj (hget.symm.trans hSchemaUids) - rfl - have hlookupYs : lookupNth? ys idx = some (.array inner) := by - rw [hys] - exact hlookup - obtain ⟨len, relativeOffset, innerEnd, hlen, hlenMax, hidx, hread, - hinner⟩ := - decodeABIValue_nestedDynamicArray_lookup (elem := bytes32) hsecond hlookupYs - refine ⟨len, relativeOffset, innerEnd, hlen, hlenMax, hidx, ?_, ?_⟩ - · simpa [Nat.add_assoc] using hread - · simpa [Nat.add_assoc] using hinner - -theorem attesterDecode_multiRevoke_schema_norm (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} {schemas : List Value} - {idx : Nat} {schema : Value} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hSchemas : callargs.get? "schemas" = some (.array schemas)) - (hlookup : lookupNth? schemas idx = some schema) : - normalizeRawBoolWord? schema = .ok schema := by - have hdec' : - decodeCalldata ["schemas", "schemaUids"] - [.dynamicArray bytes32, .dynamicArray (.dynamicArray bytes32)] I.calldata = - some callargs := by - simpa [decodeCalldataWithMode, config, multiRevokeTransition, transitionSignature, - bytes32Array, bytes32NestedArray] using hdec - obtain ⟨xs, endOffset, hfirst, hget⟩ := - attesterDecodeCalldata_twoDynamicArrays_first_decode - (cd := I.calldata) (callargs := callargs) - (name0 := "schemas") (name1 := "schemaUids") (elem1 := bytes32) - (by decide) hdec' - have hxs : xs = schemas := by - cases Option.some.inj (hget.symm.trans hSchemas) - rfl - have hlookupXs : lookupNth? xs idx = some schema := by - rw [hxs] - exact hlookup - obtain ⟨word, hshape⟩ := - decodeABIValue_dynamicArray_bytes32_lookup_shape - (bytes := I.calldata.toList.drop 4) (start := (calldataWord I.calldata 4).toNat) - (endOffset := endOffset) hfirst (lookupNth?_some_length hlookupXs) - rw [hlookupXs] at hshape - cases hshape - simp [normalizeRawBoolWord?] - -theorem attesterDecode_multiRevoke_schemaUids_shape (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} {schemaUids : List Value} - {idx : Nat} {value : Value} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiRevokeTransition v).params.map Param.name) - (transitionSignature (multiRevokeTransition v)).paramTypes I.calldata = - some callargs) - (hSchemaUids : callargs.get? "schemaUids" = some (.array schemaUids)) - (hlookup : lookupNth? schemaUids idx = some value) : - ∃ uids, - value = .array uids ∧ - uids.length < 2 ^ 256 ∧ - (∀ {j uid}, lookupNth? uids j = some uid → - normalizeRawBoolWord? uid = .ok uid) := by - have hdec' : - decodeCalldata ["schemas", "schemaUids"] - [.dynamicArray bytes32, .dynamicArray (.dynamicArray bytes32)] I.calldata = - some callargs := by - simpa [decodeCalldataWithMode, config, multiRevokeTransition, transitionSignature, - bytes32Array, bytes32NestedArray] using hdec - obtain ⟨ys, endOffset, hsecond, hget⟩ := - attesterDecodeCalldata_twoDynamicArrays_second_decode - (cd := I.calldata) (callargs := callargs) - (name0 := "schemas") (name1 := "schemaUids") (elem1 := bytes32) hdec' - have hys : ys = schemaUids := by - cases Option.some.inj (hget.symm.trans hSchemaUids) - rfl - have hlookupYs : lookupNth? ys idx = some value := by - rw [hys] - exact hlookup - obtain ⟨_len, _relativeOffset, inner, innerEnd, hvalue, _hlenRead, _hlenMax, _hidx, - _hread, hinner⟩ := - decodeABIValue_nestedDynamicArray_lookup_shape (elem := bytes32) hsecond hlookupYs - have hinner' : - decodeABIValue? (.dynamicArray abiBytes32) (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32 + _relativeOffset) = - some (.array inner, innerEnd) := by - simpa [bytes32, bytes32Width, abiBytes32, abiBytes32Width] using hinner - obtain ⟨innerLen, _hreadInnerLen, hinnerLenMax, _hend, _hendLe, hinnerLen⟩ := - decodeABIValue_dynamicArray_elem32_facts hinner' - have hinnerBound : inner.length < 2 ^ 256 := by - have hle : inner.length ≤ solcMaxU64 := by - rw [hinnerLen] - exact Nat.le_of_not_gt hinnerLenMax - norm_num [solcMaxU64] at hle ⊢ - omega - refine ⟨inner, hvalue, hinnerBound, ?_⟩ - intro j uid hlookupUid - obtain ⟨word, huidShape⟩ := - decodeABIValue_dynamicArray_bytes32_lookup_shape - (bytes := I.calldata.toList.drop 4) - (start := (calldataWord I.calldata 36).toNat + 32 + _relativeOffset) - (endOffset := innerEnd) hinner' - (lookupNth?_some_length hlookupUid) - rw [hlookupUid] at huidShape - cases huidShape - simp [normalizeRawBoolWord?] - -theorem attesterDecode_multiAttest_first_inner_decode (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} {schemaInputs : List Value} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = - some callargs) - (hSchemaInputs : callargs.get? "schemaInputs" = some (.array schemaInputs)) - (hne : schemaInputs.length ≠ 0) : - ∃ n relativeOffset inner innerEnd valuesRest restEnd, - readNat? (I.calldata.toList.drop 4) (calldataWord I.calldata 36).toNat = - some (n + 1) ∧ - ¬ solcMaxLen DecodeMode.modern < n + 1 ∧ - readNat? (I.calldata.toList.drop 4) ((calldataWord I.calldata 36).toNat + 32) = - some relativeOffset ∧ - decodeABIValue? (.dynamicArray uint256) (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) = - some (.array inner, innerEnd) ∧ - decodeABIArrayDynamicElemsFrom? (.dynamicArray uint256) n - (I.calldata.toList.drop 4) ((calldataWord I.calldata 36).toNat + 32) 32 - ((n + 1) * 32) - (max ((calldataWord I.calldata 36).toNat + 32 + (n + 1) * 32) innerEnd) = - some (valuesRest, restEnd) ∧ - schemaInputs = .array inner :: valuesRest ∧ - restEnd = restEnd := by - have hdec' : - decodeCalldata ["schemas", "schemaInputs"] - [.dynamicArray bytes32, .dynamicArray (.dynamicArray uint256)] I.calldata = - some callargs := by - simpa [decodeCalldataWithMode, config, multiAttestTransition, transitionSignature, - bytes32Array, uint256Array, uint256NestedArray] using hdec - obtain ⟨ys, endOffset, hsecond, hget⟩ := - attesterDecodeCalldata_twoDynamicArrays_second_decode - (cd := I.calldata) (callargs := callargs) - (name0 := "schemas") (name1 := "schemaInputs") (elem1 := uint256) hdec' - have hys : ys = schemaInputs := by - cases Option.some.inj (hget.symm.trans hSchemaInputs) - rfl - have hneYs : ys.length ≠ 0 := by - intro hzero - exact hne (by rw [← hys, hzero]) - obtain ⟨n, relativeOffset, inner, innerEnd, valuesRest, restEnd, - hlen, hlenMax, hreadFirst, hinner, hrest, hshape, _hend⟩ := - decodeABIValue_nestedDynamicArray_first (elem := uint256) hsecond hneYs - refine ⟨n, relativeOffset, inner, innerEnd, valuesRest, restEnd, - hlen, hlenMax, ?_, ?_, ?_, ?_, rfl⟩ - · simpa [Nat.add_assoc] using hreadFirst - · simpa [Nat.add_assoc] using hinner - · simpa [Nat.add_assoc] using hrest - · rw [← hys, hshape] - -theorem attesterDecode_multiAttest_inner_decode_at (v : AttesterImmutables) - {I : ExecutionEnv} {callargs : Store} {schemaInputs inner : List Value} {idx : Nat} - (hdec : decodeCalldataWithMode (config v).abiDecodeMode - ((multiAttestTransition v).params.map Param.name) - (transitionSignature (multiAttestTransition v)).paramTypes I.calldata = - some callargs) - (hSchemaInputs : callargs.get? "schemaInputs" = some (.array schemaInputs)) - (hlookup : lookupNth? schemaInputs idx = some (.array inner)) : - ∃ len relativeOffset innerEnd, - readNat? (I.calldata.toList.drop 4) (calldataWord I.calldata 36).toNat = - some len ∧ - ¬ solcMaxLen DecodeMode.modern < len ∧ - idx < len ∧ - readNat? (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32 + 32 * idx) = - some relativeOffset ∧ - decodeABIValue? (.dynamicArray uint256) (I.calldata.toList.drop 4) - ((calldataWord I.calldata 36).toNat + 32 + relativeOffset) = - some (.array inner, innerEnd) := by - have hdec' : - decodeCalldata ["schemas", "schemaInputs"] - [.dynamicArray bytes32, .dynamicArray (.dynamicArray uint256)] I.calldata = - some callargs := by - simpa [decodeCalldataWithMode, config, multiAttestTransition, transitionSignature, - bytes32Array, uint256Array, uint256NestedArray] using hdec - obtain ⟨ys, endOffset, hsecond, hget⟩ := - attesterDecodeCalldata_twoDynamicArrays_second_decode - (cd := I.calldata) (callargs := callargs) - (name0 := "schemas") (name1 := "schemaInputs") (elem1 := uint256) hdec' - have hys : ys = schemaInputs := by - cases Option.some.inj (hget.symm.trans hSchemaInputs) - rfl - have hlookupYs : lookupNth? ys idx = some (.array inner) := by - rw [hys] - exact hlookup - obtain ⟨len, relativeOffset, innerEnd, hlen, hlenMax, hidx, hread, - hinner⟩ := - decodeABIValue_nestedDynamicArray_lookup (elem := uint256) hsecond hlookupYs - refine ⟨len, relativeOffset, innerEnd, hlen, hlenMax, hidx, ?_, ?_⟩ - · simpa [Nat.add_assoc] using hread - · simpa [Nat.add_assoc] using hinner - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/OuterArrayInit.lean b/Benchmarks/EAS/Attester/OuterArrayInit.lean deleted file mode 100644 index c6fee135..00000000 --- a/Benchmarks/EAS/Attester/OuterArrayInit.lean +++ /dev/null @@ -1,1992 +0,0 @@ -import Benchmarks.EAS.Attester.DynamicArray - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -theorem attesterX_multiRevokeOuterArrayInitFinalIteration - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨291⟩ : UInt256) - [slot, (⟨1⟩ : UInt256), base, ⟨0⟩, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [⟨0⟩, base, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitStepMem slot mem aw) - (attesterMultiOuterArrayInitStepAw slot mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterMultiOuterArrayInitFreeWord mem aw - let aw1 := attesterMultiOuterArrayInitAwAfterMload aw - let mem1 := attesterMultiOuterArrayInitFreeMem mem aw - let aw2 := attesterMultiOuterArrayInitFreeAw aw - let mem2 := attesterMultiOuterArrayInitZeroMem mem aw - let aw3 := attesterMultiOuterArrayInitZeroAw mem aw - let off := attesterMultiOuterArrayInitOffsetWord mem aw - let mem3 := attesterMultiOuterArrayInitOffsetMem mem aw - let aw4 := attesterMultiOuterArrayInitOffsetAw mem aw - let mem4 := attesterMultiOuterArrayInitStepMem slot mem aw - let aw5 := attesterMultiOuterArrayInitStepAw slot mem aw - have hcostMload : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - [⟨64⟩, ⟨64⟩, slot, (⟨1⟩ : UInt256), base, ⟨0⟩, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStore64 : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - [⟨64⟩, ((⟨64⟩ : UInt256) + free), free, slot, (⟨1⟩ : UInt256), - base, ⟨0⟩, len, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - [free, (⟨0⟩ : UInt256), free, slot, (⟨1⟩ : UInt256), - base, ⟨0⟩, len, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreOff : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - [off, (⟨96⟩ : UInt256), free, slot, (⟨1⟩ : UInt256), - base, ⟨0⟩, len, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw4 - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSlot : - ∀ s : State, - s.machineState.activeWords = aw4 → - s.machineState.stack = - [slot, free, slot, (⟨1⟩ : UInt256), base, ⟨0⟩, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw5 - Cₘ aw4 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hrd314 : ∃ k314 C314, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨314⟩ : UInt256) - [slot, (⟨1⟩ : UInt256), base, ⟨0⟩, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem4 aw5 ByteArray.empty (cA, σ) k314 C314 := by - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, off, mem3, aw4, mem4, aw5] using - evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨291⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨292⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨294⟩, 0x80, .DUP1) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨295⟩, 0x51, .MLOAD) - hcostMload (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨296⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨297⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨298⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨299⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨300⟩, 0x91, .SWAP2) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨301⟩, 0x52, .MSTORE) - hcostStore64 (by rfl) (by rfl) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨302⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨303⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨304⟩, 0x52, .MSTORE) - hcostStoreZero (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨96⟩ (by attester_decode_at v, ⟨305⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨307⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨309⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨310⟩, 0x01, .ADD) (by evm_ov), - raw mstore (Cₘ aw4 - Cₘ aw3) mem3 aw4 - (by attester_decode_at v, ⟨311⟩, 0x52, .MSTORE) - hcostStoreOff (by rfl) (by rfl) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨312⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw5 - Cₘ aw4) mem4 aw5 - (by attester_decode_at v, ⟨313⟩, 0x52, .MSTORE) - hcostStoreSlot (by rfl) (by rfl) (by evm_ov)]⟩ - obtain ⟨_, _, rd314⟩ := hrd314 - have hrd328 : ∃ k328 C328, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨328⟩ : UInt256) - [((⟨32⟩ : UInt256) + slot), ⟨0⟩, base, ⟨0⟩, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem4 aw5 ByteArray.empty (cA, σ) k328 C328 := by - exact ⟨_, _, by - simpa using - evm_run rd314 with [ - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨314⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨316⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨317⟩, 0x90, .SWAP1) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨318⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨320⟩, 0x90, .SWAP1) (by evm_ov), - raw sub (by attester_decode_at v, ⟨321⟩, 0x03, .SUB) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨322⟩, 0x90, .SWAP1) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨323⟩, 0x81, .DUP2) (by evm_ov), - raw push2 ⟨291⟩ (by attester_decode_at v, ⟨324⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨327⟩, 0x57, .JUMPI) - (by native_decide) (by evm_ov)]⟩ - obtain ⟨_, _, rd328⟩ := hrd328 - have rd335 := evm_run rd328 with [ - raw swap1 (by attester_decode_at v, ⟨328⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨329⟩, 0x50, .POP) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨330⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨331⟩, 0x50, .POP) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨332⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨333⟩, 0x50, .POP) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨334⟩, 0x5f, .PUSH0) (by evm_ov)] - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, off, mem3, aw4, mem4, aw5] using rd335⟩ - -theorem attesterX_multiRevokeOuterArrayInitNonFinalIteration - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len remaining : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hnext : UInt256.sub remaining (⟨1⟩ : UInt256) ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨291⟩ : UInt256) - [slot, remaining, base, ⟨0⟩, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨291⟩ : UInt256) - [((⟨32⟩ : UInt256) + slot), UInt256.sub remaining ⟨1⟩, base, ⟨0⟩, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitStepMem slot mem aw) - (attesterMultiOuterArrayInitStepAw slot mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterMultiOuterArrayInitFreeWord mem aw - let aw1 := attesterMultiOuterArrayInitAwAfterMload aw - let mem1 := attesterMultiOuterArrayInitFreeMem mem aw - let aw2 := attesterMultiOuterArrayInitFreeAw aw - let mem2 := attesterMultiOuterArrayInitZeroMem mem aw - let aw3 := attesterMultiOuterArrayInitZeroAw mem aw - let off := attesterMultiOuterArrayInitOffsetWord mem aw - let mem3 := attesterMultiOuterArrayInitOffsetMem mem aw - let aw4 := attesterMultiOuterArrayInitOffsetAw mem aw - let mem4 := attesterMultiOuterArrayInitStepMem slot mem aw - let aw5 := attesterMultiOuterArrayInitStepAw slot mem aw - have hcostMload : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - [⟨64⟩, ⟨64⟩, slot, remaining, base, ⟨0⟩, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStore64 : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - [⟨64⟩, ((⟨64⟩ : UInt256) + free), free, slot, remaining, - base, ⟨0⟩, len, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - [free, (⟨0⟩ : UInt256), free, slot, remaining, - base, ⟨0⟩, len, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreOff : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - [off, (⟨96⟩ : UInt256), free, slot, remaining, - base, ⟨0⟩, len, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw4 - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSlot : - ∀ s : State, - s.machineState.activeWords = aw4 → - s.machineState.stack = - [slot, free, slot, remaining, base, ⟨0⟩, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw5 - Cₘ aw4 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hrd314 : ∃ k314 C314, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨314⟩ : UInt256) - [slot, remaining, base, ⟨0⟩, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem4 aw5 ByteArray.empty (cA, σ) k314 C314 := by - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, off, mem3, aw4, mem4, aw5] using - evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨291⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨292⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨294⟩, 0x80, .DUP1) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨295⟩, 0x51, .MLOAD) - hcostMload (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨296⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨297⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨298⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨299⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨300⟩, 0x91, .SWAP2) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨301⟩, 0x52, .MSTORE) - hcostStore64 (by rfl) (by rfl) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨302⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨303⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨304⟩, 0x52, .MSTORE) - hcostStoreZero (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨96⟩ (by attester_decode_at v, ⟨305⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨307⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨309⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨310⟩, 0x01, .ADD) (by evm_ov), - raw mstore (Cₘ aw4 - Cₘ aw3) mem3 aw4 - (by attester_decode_at v, ⟨311⟩, 0x52, .MSTORE) - hcostStoreOff (by rfl) (by rfl) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨312⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw5 - Cₘ aw4) mem4 aw5 - (by attester_decode_at v, ⟨313⟩, 0x52, .MSTORE) - hcostStoreSlot (by rfl) (by rfl) (by evm_ov)]⟩ - obtain ⟨_, _, rd314⟩ := hrd314 - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, off, mem3, aw4, mem4, aw5] using - evm_run rd314 with [ - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨314⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨316⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨317⟩, 0x90, .SWAP1) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨318⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨320⟩, 0x90, .SWAP1) (by evm_ov), - raw sub (by attester_decode_at v, ⟨321⟩, 0x03, .SUB) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨322⟩, 0x90, .SWAP1) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨323⟩, 0x81, .DUP2) (by evm_ov), - raw push2 ⟨291⟩ (by attester_decode_at v, ⟨324⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨327⟩, 0x57, .JUMPI) - (by simpa using hnext) - (attesterMultiRevokeOuterArrayInitLoopJumpdest v) (by evm_ov)]⟩ - -theorem attester_u256_ofNat_succ_sub_one {n : Nat} - (hn : n + 1 < UInt256.size) : - UInt256.sub (UInt256.ofNat (n + 1)) (⟨1⟩ : UInt256) = - UInt256.ofNat n := by - apply u256_inj - rw [usub_toNat] - · rw [ulit_toNat' (n + 1) hn] - rw [show (⟨1⟩ : UInt256).toNat = 1 by decide] - rw [ulit_toNat' n (by omega)] - omega - · rw [ulit_toNat' (n + 1) hn] - rw [show (⟨1⟩ : UInt256).toNat = 1 by decide] - omega - -theorem attester_u256_ofNat_pos_ne_zero {n : Nat} - (hpos : 0 < n) (hn : n < UInt256.size) : - UInt256.ofNat n ≠ (⟨0⟩ : UInt256) := by - intro hzero - have hnat := congrArg UInt256.toNat hzero - rw [ulit_toNat' n hn] at hnat - norm_num at hnat - omega - -structure AttesterMultiOuterArrayInitState where - slot : UInt256 - remaining : UInt256 - mem : ByteArray - aw : UInt256 - -abbrev attesterMultiRevokeOuterArrayInitStack - (I : ExecutionEnv) (base len : UInt256) - (a : AttesterMultiOuterArrayInitState) : List UInt256 := - [a.slot, a.remaining, base, ⟨0⟩, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - -abbrev attesterMultiRevokeOuterArrayInitExitStack - (I : ExecutionEnv) (base len : UInt256) - (_a : AttesterMultiOuterArrayInitState) : List UInt256 := - [⟨0⟩, base, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - -abbrev attesterMultiOuterArrayInitStepState - (a : AttesterMultiOuterArrayInitState) : AttesterMultiOuterArrayInitState := - { slot := (⟨32⟩ : UInt256) + a.slot, - remaining := UInt256.sub a.remaining ⟨1⟩, - mem := attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw, - aw := attesterMultiOuterArrayInitStepAw a.slot a.mem a.aw } - -abbrev attesterMultiOuterArrayInitFinalMem - (a : AttesterMultiOuterArrayInitState) : ByteArray := - attesterMultiOuterArrayInitStepMem a.slot a.mem a.aw - -abbrev attesterMultiOuterArrayInitFinalAw - (a : AttesterMultiOuterArrayInitState) : UInt256 := - attesterMultiOuterArrayInitStepAw a.slot a.mem a.aw - -theorem attesterX_multiRevokeOuterArrayInitLoop - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hlenNe : len.toNat ≠ 0) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨291⟩ : UInt256) - [slot, len, base, ⟨0⟩, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ a' k' C', - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - (attesterMultiRevokeOuterArrayInitExitStack I base len a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k' C' := by - let Inv : Nat → AttesterMultiOuterArrayInitState → Prop := - fun n a => a.remaining = UInt256.ofNat (n + 1) ∧ n + 1 < UInt256.size - let stk := attesterMultiRevokeOuterArrayInitStack I base len - let memOf : AttesterMultiOuterArrayInitState → ByteArray := fun a => a.mem - let awOf : AttesterMultiOuterArrayInitState → UInt256 := fun a => a.aw - let exitStk := attesterMultiRevokeOuterArrayInitExitStack I base len - let exitMem := attesterMultiOuterArrayInitFinalMem - let exitAw := attesterMultiOuterArrayInitFinalAw - have hexit : - ∀ a, Inv 0 a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨291⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨335⟩ : UInt256) (exitStk a) (exitMem a) (exitAw a) - ByteArray.empty (cA, σ) k' C' := by - intro a hInv k C rd - have hrem : a.remaining = (⟨1⟩ : UInt256) := by - simpa [Inv] using hInv.1 - exact attesterX_multiRevokeOuterArrayInitFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (mem := a.mem) (aw := a.aw) - (by - simpa [stk, memOf, awOf, hrem, attesterMultiRevokeOuterArrayInitStack] - using rd) - have hbody : - ∀ n a, Inv (n + 1) a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨291⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ a' k' C', - Inv n a' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨291⟩ : UInt256) (stk a') (memOf a') (awOf a') - ByteArray.empty (cA, σ) k' C' := by - intro n a hInv k C rd - let a' := attesterMultiOuterArrayInitStepState a - have hsub : - UInt256.sub a.remaining (⟨1⟩ : UInt256) = UInt256.ofNat (n + 1) := by - rw [hInv.1] - simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using - attester_u256_ofNat_succ_sub_one (n := n + 1) - (by simpa [Inv, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using hInv.2) - have hnext : UInt256.sub a.remaining (⟨1⟩ : UInt256) ≠ ⟨0⟩ := by - rw [hsub] - exact attester_u256_ofNat_pos_ne_zero - (n := n + 1) (by omega) (by - have hlt : n + 1 < UInt256.size := by - have := hInv.2 - omega - exact hlt) - obtain ⟨k', C', rd'⟩ := - attesterX_multiRevokeOuterArrayInitNonFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (remaining := a.remaining) (mem := a.mem) (aw := a.aw) hnext - (by - simpa [stk, memOf, awOf, attesterMultiRevokeOuterArrayInitStack] - using rd) - refine ⟨a', k', C', ?_, ?_⟩ - · constructor - · simpa [a', attesterMultiOuterArrayInitStepState] using hsub - · have := hInv.2 - omega - · simpa [a', stk, memOf, awOf, attesterMultiRevokeOuterArrayInitStack, - attesterMultiOuterArrayInitStepState] using rd' - let a0 : AttesterMultiOuterArrayInitState := - { slot := slot, remaining := len, mem := mem, aw := aw } - have hInv0 : Inv (len.toNat - 1) a0 := by - constructor - · have hsucc : (len.toNat - 1) + 1 = len.toNat := by omega - simpa [a0, hsucc] using (u256_ofNat_toNat len).symm - · have hsucc : (len.toNat - 1) + 1 = len.toNat := by omega - rw [hsucc] - exact len.val.isLt - obtain ⟨a', k', C', hInvFinal, rdFinal⟩ := - RD.whileLoopCarryExit - (code := patchedRuntime v) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) - (rdata := ByteArray.empty) (acc := (cA, σ)) - (header := (⟨291⟩ : UInt256)) (exit := (⟨335⟩ : UInt256)) - Inv stk memOf awOf exitStk exitMem exitAw hexit hbody - (len.toNat - 1) a0 hInv0 k C - (by - simpa [a0, stk, memOf, awOf, attesterMultiRevokeOuterArrayInitStack] - using hreach) - exact ⟨a', k', C', by simpa [Inv] using hInvFinal.1, rdFinal⟩ - - -theorem attesterX_multiAttestOuterArrayInitFinalIteration - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨929⟩ : UInt256) - [slot, (⟨1⟩ : UInt256), base, ⟨0⟩, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨973⟩ : UInt256) - [⟨0⟩, base, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitStepMem slot mem aw) - (attesterMultiOuterArrayInitStepAw slot mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterMultiOuterArrayInitFreeWord mem aw - let aw1 := attesterMultiOuterArrayInitAwAfterMload aw - let mem1 := attesterMultiOuterArrayInitFreeMem mem aw - let aw2 := attesterMultiOuterArrayInitFreeAw aw - let mem2 := attesterMultiOuterArrayInitZeroMem mem aw - let aw3 := attesterMultiOuterArrayInitZeroAw mem aw - let off := attesterMultiOuterArrayInitOffsetWord mem aw - let mem3 := attesterMultiOuterArrayInitOffsetMem mem aw - let aw4 := attesterMultiOuterArrayInitOffsetAw mem aw - let mem4 := attesterMultiOuterArrayInitStepMem slot mem aw - let aw5 := attesterMultiOuterArrayInitStepAw slot mem aw - have hcostMload : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - [⟨64⟩, ⟨64⟩, slot, (⟨1⟩ : UInt256), base, ⟨0⟩, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStore64 : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - [⟨64⟩, ((⟨64⟩ : UInt256) + free), free, slot, (⟨1⟩ : UInt256), - base, ⟨0⟩, len, ⟨96⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - [free, (⟨0⟩ : UInt256), free, slot, (⟨1⟩ : UInt256), - base, ⟨0⟩, len, ⟨96⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreOff : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - [off, (⟨96⟩ : UInt256), free, slot, (⟨1⟩ : UInt256), - base, ⟨0⟩, len, ⟨96⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw4 - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSlot : - ∀ s : State, - s.machineState.activeWords = aw4 → - s.machineState.stack = - [slot, free, slot, (⟨1⟩ : UInt256), base, ⟨0⟩, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw5 - Cₘ aw4 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hrd314 : ∃ k314 C314, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨952⟩ : UInt256) - [slot, (⟨1⟩ : UInt256), base, ⟨0⟩, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem4 aw5 ByteArray.empty (cA, σ) k314 C314 := by - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, off, mem3, aw4, mem4, aw5] using - evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨929⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨930⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨932⟩, 0x80, .DUP1) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨933⟩, 0x51, .MLOAD) - hcostMload (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨934⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨935⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨936⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨937⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨938⟩, 0x91, .SWAP2) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨939⟩, 0x52, .MSTORE) - hcostStore64 (by rfl) (by rfl) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨940⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨941⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨942⟩, 0x52, .MSTORE) - hcostStoreZero (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨96⟩ (by attester_decode_at v, ⟨943⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨945⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨947⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨948⟩, 0x01, .ADD) (by evm_ov), - raw mstore (Cₘ aw4 - Cₘ aw3) mem3 aw4 - (by attester_decode_at v, ⟨949⟩, 0x52, .MSTORE) - hcostStoreOff (by rfl) (by rfl) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨950⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw5 - Cₘ aw4) mem4 aw5 - (by attester_decode_at v, ⟨951⟩, 0x52, .MSTORE) - hcostStoreSlot (by rfl) (by rfl) (by evm_ov)]⟩ - obtain ⟨_, _, rd314⟩ := hrd314 - have hrd328 : ∃ k328 C328, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨966⟩ : UInt256) - [((⟨32⟩ : UInt256) + slot), ⟨0⟩, base, ⟨0⟩, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem4 aw5 ByteArray.empty (cA, σ) k328 C328 := by - exact ⟨_, _, by - simpa using - evm_run rd314 with [ - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨952⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨954⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨955⟩, 0x90, .SWAP1) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨956⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨958⟩, 0x90, .SWAP1) (by evm_ov), - raw sub (by attester_decode_at v, ⟨959⟩, 0x03, .SUB) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨960⟩, 0x90, .SWAP1) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨961⟩, 0x81, .DUP2) (by evm_ov), - raw push2 ⟨929⟩ (by attester_decode_at v, ⟨962⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨965⟩, 0x57, .JUMPI) - (by native_decide) (by evm_ov)]⟩ - obtain ⟨_, _, rd328⟩ := hrd328 - have rd335 := evm_run rd328 with [ - raw swap1 (by attester_decode_at v, ⟨966⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨967⟩, 0x50, .POP) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨968⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨969⟩, 0x50, .POP) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨970⟩, 0x90, .SWAP1) (by evm_ov), - raw pop (by attester_decode_at v, ⟨971⟩, 0x50, .POP) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨972⟩, 0x5f, .PUSH0) (by evm_ov)] - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, off, mem3, aw4, mem4, aw5] using rd335⟩ - -theorem attesterX_multiAttestOuterArrayInitNonFinalIteration - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len remaining : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hnext : UInt256.sub remaining (⟨1⟩ : UInt256) ≠ ⟨0⟩) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨929⟩ : UInt256) - [slot, remaining, base, ⟨0⟩, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨929⟩ : UInt256) - [((⟨32⟩ : UInt256) + slot), UInt256.sub remaining ⟨1⟩, base, ⟨0⟩, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - (attesterMultiOuterArrayInitStepMem slot mem aw) - (attesterMultiOuterArrayInitStepAw slot mem aw) - ByteArray.empty (cA, σ) k' C' := by - let free := attesterMultiOuterArrayInitFreeWord mem aw - let aw1 := attesterMultiOuterArrayInitAwAfterMload aw - let mem1 := attesterMultiOuterArrayInitFreeMem mem aw - let aw2 := attesterMultiOuterArrayInitFreeAw aw - let mem2 := attesterMultiOuterArrayInitZeroMem mem aw - let aw3 := attesterMultiOuterArrayInitZeroAw mem aw - let off := attesterMultiOuterArrayInitOffsetWord mem aw - let mem3 := attesterMultiOuterArrayInitOffsetMem mem aw - let aw4 := attesterMultiOuterArrayInitOffsetAw mem aw - let mem4 := attesterMultiOuterArrayInitStepMem slot mem aw - let aw5 := attesterMultiOuterArrayInitStepAw slot mem aw - have hcostMload : - ∀ s : State, - s.machineState.activeWords = aw → - s.machineState.stack = - [⟨64⟩, ⟨64⟩, slot, remaining, base, ⟨0⟩, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MLOAD = Cₘ aw1 - Cₘ aw := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStore64 : - ∀ s : State, - s.machineState.activeWords = aw1 → - s.machineState.stack = - [⟨64⟩, ((⟨64⟩ : UInt256) + free), free, slot, remaining, - base, ⟨0⟩, len, ⟨96⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw2 - Cₘ aw1 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreZero : - ∀ s : State, - s.machineState.activeWords = aw2 → - s.machineState.stack = - [free, (⟨0⟩ : UInt256), free, slot, remaining, - base, ⟨0⟩, len, ⟨96⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw3 - Cₘ aw2 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreOff : - ∀ s : State, - s.machineState.activeWords = aw3 → - s.machineState.stack = - [off, (⟨96⟩ : UInt256), free, slot, remaining, - base, ⟨0⟩, len, ⟨96⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw4 - Cₘ aw3 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hcostStoreSlot : - ∀ s : State, - s.machineState.activeWords = aw4 → - s.machineState.stack = - [slot, free, slot, remaining, base, ⟨0⟩, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] → - memoryExpansionCost s .MSTORE = Cₘ aw5 - Cₘ aw4 := by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstks, - List.getElem!_cons_zero] - rfl - have hrd314 : ∃ k314 C314, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨952⟩ : UInt256) - [slot, remaining, base, ⟨0⟩, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem4 aw5 ByteArray.empty (cA, σ) k314 C314 := by - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, off, mem3, aw4, mem4, aw5] using - evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨929⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨930⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨932⟩, 0x80, .DUP1) (by evm_ov), - raw mload (Cₘ aw1 - Cₘ aw) free aw1 - (by attester_decode_at v, ⟨933⟩, 0x51, .MLOAD) - hcostMload (by rfl) (by rfl) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨934⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨935⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨936⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨937⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨938⟩, 0x91, .SWAP2) (by evm_ov), - raw mstore (Cₘ aw2 - Cₘ aw1) mem1 aw2 - (by attester_decode_at v, ⟨939⟩, 0x52, .MSTORE) - hcostStore64 (by rfl) (by rfl) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨940⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨941⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw3 - Cₘ aw2) mem2 aw3 - (by attester_decode_at v, ⟨942⟩, 0x52, .MSTORE) - hcostStoreZero (by rfl) (by rfl) (by evm_ov), - raw push1 ⟨96⟩ (by attester_decode_at v, ⟨943⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨945⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨947⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨948⟩, 0x01, .ADD) (by evm_ov), - raw mstore (Cₘ aw4 - Cₘ aw3) mem3 aw4 - (by attester_decode_at v, ⟨949⟩, 0x52, .MSTORE) - hcostStoreOff (by rfl) (by rfl) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨950⟩, 0x81, .DUP2) (by evm_ov), - raw mstore (Cₘ aw5 - Cₘ aw4) mem4 aw5 - (by attester_decode_at v, ⟨951⟩, 0x52, .MSTORE) - hcostStoreSlot (by rfl) (by rfl) (by evm_ov)]⟩ - obtain ⟨_, _, rd314⟩ := hrd314 - exact ⟨_, _, by - simpa [free, aw1, mem1, aw2, mem2, aw3, off, mem3, aw4, mem4, aw5] using - evm_run rd314 with [ - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨952⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨954⟩, 0x01, .ADD) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨955⟩, 0x90, .SWAP1) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨956⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨958⟩, 0x90, .SWAP1) (by evm_ov), - raw sub (by attester_decode_at v, ⟨959⟩, 0x03, .SUB) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨960⟩, 0x90, .SWAP1) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨961⟩, 0x81, .DUP2) (by evm_ov), - raw push2 ⟨929⟩ (by attester_decode_at v, ⟨962⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨965⟩, 0x57, .JUMPI) - (by simpa using hnext) - (attesterMultiAttestOuterArrayInitLoopJumpdest v) (by evm_ov)]⟩ -abbrev attesterMultiAttestOuterArrayInitStack - (I : ExecutionEnv) (base len : UInt256) - (a : AttesterMultiOuterArrayInitState) : List UInt256 := - [a.slot, a.remaining, base, ⟨0⟩, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - -abbrev attesterMultiAttestOuterArrayInitExitStack - (I : ExecutionEnv) (base len : UInt256) - (_a : AttesterMultiOuterArrayInitState) : List UInt256 := - [⟨0⟩, base, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] -theorem attesterX_multiAttestOuterArrayInitLoop - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {slot base len : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hlenNe : len.toNat ≠ 0) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨929⟩ : UInt256) - [slot, len, base, ⟨0⟩, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ a' k' C', - a'.remaining = (⟨1⟩ : UInt256) ∧ - RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨973⟩ : UInt256) - (attesterMultiAttestOuterArrayInitExitStack I base len a') - (attesterMultiOuterArrayInitFinalMem a') - (attesterMultiOuterArrayInitFinalAw a') - ByteArray.empty (cA, σ) k' C' := by - let Inv : Nat → AttesterMultiOuterArrayInitState → Prop := - fun n a => a.remaining = UInt256.ofNat (n + 1) ∧ n + 1 < UInt256.size - let stk := attesterMultiAttestOuterArrayInitStack I base len - let memOf : AttesterMultiOuterArrayInitState → ByteArray := fun a => a.mem - let awOf : AttesterMultiOuterArrayInitState → UInt256 := fun a => a.aw - let exitStk := attesterMultiAttestOuterArrayInitExitStack I base len - let exitMem := attesterMultiOuterArrayInitFinalMem - let exitAw := attesterMultiOuterArrayInitFinalAw - have hexit : - ∀ a, Inv 0 a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨929⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ k' C', - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨973⟩ : UInt256) (exitStk a) (exitMem a) (exitAw a) - ByteArray.empty (cA, σ) k' C' := by - intro a hInv k C rd - have hrem : a.remaining = (⟨1⟩ : UInt256) := by - simpa [Inv] using hInv.1 - exact attesterX_multiAttestOuterArrayInitFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (mem := a.mem) (aw := a.aw) - (by - simpa [stk, memOf, awOf, hrem, attesterMultiAttestOuterArrayInitStack] - using rd) - have hbody : - ∀ n a, Inv (n + 1) a → ∀ k C, - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨929⟩ : UInt256) (stk a) (memOf a) (awOf a) - ByteArray.empty (cA, σ) k C → - ∃ a' k' C', - Inv n a' ∧ - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨929⟩ : UInt256) (stk a') (memOf a') (awOf a') - ByteArray.empty (cA, σ) k' C' := by - intro n a hInv k C rd - let a' := attesterMultiOuterArrayInitStepState a - have hsub : - UInt256.sub a.remaining (⟨1⟩ : UInt256) = UInt256.ofNat (n + 1) := by - rw [hInv.1] - simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using - attester_u256_ofNat_succ_sub_one (n := n + 1) - (by simpa [Inv, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using hInv.2) - have hnext : UInt256.sub a.remaining (⟨1⟩ : UInt256) ≠ ⟨0⟩ := by - rw [hsub] - exact attester_u256_ofNat_pos_ne_zero - (n := n + 1) (by omega) (by - have hlt : n + 1 < UInt256.size := by - have := hInv.2 - omega - exact hlt) - obtain ⟨k', C', rd'⟩ := - attesterX_multiAttestOuterArrayInitNonFinalIteration - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) v (slot := a.slot) (base := base) (len := len) - (remaining := a.remaining) (mem := a.mem) (aw := a.aw) hnext - (by - simpa [stk, memOf, awOf, attesterMultiAttestOuterArrayInitStack] - using rd) - refine ⟨a', k', C', ?_, ?_⟩ - · constructor - · simpa [a', attesterMultiOuterArrayInitStepState] using hsub - · have := hInv.2 - omega - · simpa [a', stk, memOf, awOf, attesterMultiAttestOuterArrayInitStack, - attesterMultiOuterArrayInitStepState] using rd' - let a0 : AttesterMultiOuterArrayInitState := - { slot := slot, remaining := len, mem := mem, aw := aw } - have hInv0 : Inv (len.toNat - 1) a0 := by - constructor - · have hsucc : (len.toNat - 1) + 1 = len.toNat := by omega - simpa [a0, hsucc] using (u256_ofNat_toNat len).symm - · have hsucc : (len.toNat - 1) + 1 = len.toNat := by omega - rw [hsucc] - exact len.val.isLt - obtain ⟨a', k', C', hInvFinal, rdFinal⟩ := - RD.whileLoopCarryExit - (code := patchedRuntime v) (ee := I) (g := g) - (s0 := initState cA gh bl σ σ₀ g A I) - (rdata := ByteArray.empty) (acc := (cA, σ)) - (header := (⟨929⟩ : UInt256)) (exit := (⟨973⟩ : UInt256)) - Inv stk memOf awOf exitStk exitMem exitAw hexit hbody - (len.toNat - 1) a0 hInv0 k C - (by - simpa [a0, stk, memOf, awOf, attesterMultiAttestOuterArrayInitStack] - using hreach) - exact ⟨a', k', C', by simpa [Inv] using hInvFinal.1, rdFinal⟩ - -theorem attesterX_multiRevokeOuterSourceLoopFirstGuard - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base len : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hlenNe : len.toNat ≠ 0) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨335⟩ : UInt256) - [⟨0⟩, base, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨344⟩ : UInt256) - [⟨0⟩, base, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - have hlt : UInt256.lt (⟨0⟩ : UInt256) len = ⟨1⟩ := by - apply ult_one - rw [show (⟨0⟩ : UInt256).toNat = 0 by decide] - omega - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨335⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨336⟩, 0x82, .DUP3) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨337⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨338⟩, 0x10, .LT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨339⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨698⟩ (by attester_decode_at v, ⟨340⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨343⟩, 0x57, .JUMPI) - (by rw [hlt]; decide) (by evm_ov)]⟩ - -theorem attesterX_multiAttestOuterSourceLoopFirstGuard - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base len : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hlenNe : len.toNat ≠ 0) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨973⟩ : UInt256) - [⟨0⟩, base, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨982⟩ : UInt256) - [⟨0⟩, base, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - have hlt : UInt256.lt (⟨0⟩ : UInt256) len = ⟨1⟩ := by - apply ult_one - rw [show (⟨0⟩ : UInt256).toNat = 0 by decide] - omega - exact ⟨_, _, evm_run hreach with [ - raw jumpdest (by attester_decode_at v, ⟨973⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨974⟩, 0x82, .DUP3) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨975⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨976⟩, 0x10, .LT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨977⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨1441⟩ (by attester_decode_at v, ⟨978⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨981⟩, 0x57, .JUMPI) - (by rw [hlt]; decide) (by evm_ov)]⟩ - -theorem attesterX_multiRevokeOuterSecondArrayAccessCheck - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base len : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hsecondLenNe : (attesterSecondArrayLengthWord I).toNat ≠ 0) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨344⟩ : UInt256) - [⟨0⟩, base, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨355⟩ : UInt256) - [⟨363⟩, ⟨1⟩, ⟨0⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, base, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - have hlt : - UInt256.lt (⟨0⟩ : UInt256) (attesterSecondArrayLengthWord I) = ⟨1⟩ := by - apply ult_one - rw [show (⟨0⟩ : UInt256).toNat = 0 by decide] - omega - exact ⟨_, _, by - simpa [hlt] using - (evm_run hreach with [ - raw calldatasize (by attester_decode_at v, ⟨344⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨345⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨346⟩, 0x86, .DUP7) (by evm_ov), - raw dup7 (by attester_decode_at v, ⟨347⟩, 0x86, .DUP7) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨348⟩, 0x84, .DUP5) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨349⟩, 0x81, .DUP2) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨350⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨351⟩, 0x10, .LT) (by evm_ov), - raw push2 ⟨363⟩ (by attester_decode_at v, ⟨352⟩, 0x61, (.Push .PUSH2)) - (by evm_ov)])⟩ - -theorem attesterMultiRevokeOuterSourceElementOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨363⟩ : UInt256) = true := by - let A := attesterBytecode.extract 0 722 - let B := (patchedRuntime v).extract 722 (patchedRuntime v).size - have hprefix : (patchedRuntime v).extract 0 722 = A := by - unfold A - rw [patchedRuntime_extract_preserved_len v 0 722 - (by simp [runtimeWrites, WindowDisjointFromWrites]) - (by norm_num) - (by norm_num) - (by norm_num)] - have hsplit : patchedRuntime v = A ++ B := by - unfold B - have h := ByteArray.extract_append_extract (a := patchedRuntime v) - (i := 0) (j := 722) (k := (patchedRuntime v).size) - rw [← hprefix] - have hsize : 722 ≤ (patchedRuntime v).size := by - rw [patchedRuntime_size v] - norm_num - have hmax : max 722 (patchedRuntime v).size = (patchedRuntime v).size := - Nat.max_eq_right hsize - have hmin : min 0 722 = 0 := by omega - simpa [hmin, hmax, ByteArray.extract_zero_size] using h.symm - rw [hsplit] - apply Reasoning.Theory.D_J_contains_append_left - unfold A - native_decide - -theorem attesterX_multiRevokeOuterSecondArrayAccessOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base len : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hsecondLenNe : (attesterSecondArrayLengthWord I).toNat ≠ 0) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨344⟩ : UInt256) - [⟨0⟩, base, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨363⟩ : UInt256) - [⟨0⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, base, len, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨97⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd0⟩ := - attesterX_multiRevokeOuterSecondArrayAccessCheck - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := base) (len := len) (mem := mem) (aw := aw) - (k := k) (C := C) hsecondLenNe hreach - exact ⟨_, _, evm_run rd0 with [ - raw jumpiT (by attester_decode_at v, ⟨355⟩, 0x57, .JUMPI) - (by decide) (attesterMultiRevokeOuterSourceElementOkJumpdest v) - (by evm_ov)]⟩ - -syntax "attester_dj_parse_at " term "," term : tactic -macro_rules - | `(tactic| attester_dj_parse_at $varg, $pc) => - `(tactic| - (rw [patchedRuntime_get?_preserved $varg ($pc : Nat) - (by norm_num [runtimeWrites, WindowDisjointFromWrites]) - (by norm_num)]; - native_decide)) - -syntax "attester_dj_step " term "," term "," term : tactic -macro_rules - | `(tactic| attester_dj_step $varg, $pc, $instr) => - `(tactic| - (rw [D_J_aux_eq_some (patchedRuntime $varg) $pc _ $instr - (by attester_dj_parse_at $varg, $pc)]; - simp [EVM.N, argOnNBytesOfInstr])) - -set_option maxRecDepth 20000 in -set_option maxHeartbeats 2000000 in -theorem attesterMultiAttestOuterSourceElementOkJumpdest (v : AttesterImmutables) : - (D_J (patchedRuntime v) 0).contains (⟨1001⟩ : UInt256) = true := by - unfold D_J - attester_dj_step v, 0, (.Push .PUSH1) - attester_dj_step v, 2, (.Push .PUSH1) - attester_dj_step v, 4, .MSTORE - attester_dj_step v, 5, .CALLVALUE - attester_dj_step v, 6, .DUP1 - attester_dj_step v, 7, .ISZERO - attester_dj_step v, 8, (.Push .PUSH2) - attester_dj_step v, 11, .JUMPI - attester_dj_step v, 12, (.Push .PUSH0) - attester_dj_step v, 13, .DUP1 - attester_dj_step v, 14, .REVERT - attester_dj_step v, 15, .JUMPDEST - attester_dj_step v, 16, .POP - attester_dj_step v, 17, (.Push .PUSH1) - attester_dj_step v, 19, .CALLDATASIZE - attester_dj_step v, 20, .LT - attester_dj_step v, 21, (.Push .PUSH2) - attester_dj_step v, 24, .JUMPI - attester_dj_step v, 25, (.Push .PUSH0) - attester_dj_step v, 26, .CALLDATALOAD - attester_dj_step v, 27, (.Push .PUSH1) - attester_dj_step v, 29, .SHR - attester_dj_step v, 30, .DUP1 - attester_dj_step v, 31, (.Push .PUSH4) - attester_dj_step v, 36, .EQ - attester_dj_step v, 37, (.Push .PUSH2) - attester_dj_step v, 40, .JUMPI - attester_dj_step v, 41, .DUP1 - attester_dj_step v, 42, (.Push .PUSH4) - attester_dj_step v, 47, .EQ - attester_dj_step v, 48, (.Push .PUSH2) - attester_dj_step v, 51, .JUMPI - attester_dj_step v, 52, .DUP1 - attester_dj_step v, 53, (.Push .PUSH4) - attester_dj_step v, 58, .EQ - attester_dj_step v, 59, (.Push .PUSH2) - attester_dj_step v, 62, .JUMPI - attester_dj_step v, 63, .DUP1 - attester_dj_step v, 64, (.Push .PUSH4) - attester_dj_step v, 69, .EQ - attester_dj_step v, 70, (.Push .PUSH2) - attester_dj_step v, 73, .JUMPI - attester_dj_step v, 74, .JUMPDEST - attester_dj_step v, 75, (.Push .PUSH0) - attester_dj_step v, 76, .DUP1 - attester_dj_step v, 77, .REVERT - attester_dj_step v, 78, .JUMPDEST - attester_dj_step v, 79, (.Push .PUSH2) - attester_dj_step v, 82, (.Push .PUSH2) - attester_dj_step v, 85, .CALLDATASIZE - attester_dj_step v, 86, (.Push .PUSH1) - attester_dj_step v, 88, (.Push .PUSH2) - attester_dj_step v, 91, .JUMP - attester_dj_step v, 92, .JUMPDEST - attester_dj_step v, 93, (.Push .PUSH2) - attester_dj_step v, 96, .JUMP - attester_dj_step v, 97, .JUMPDEST - attester_dj_step v, 98, .STOP - attester_dj_step v, 99, .JUMPDEST - attester_dj_step v, 100, (.Push .PUSH2) - attester_dj_step v, 103, (.Push .PUSH2) - attester_dj_step v, 106, .CALLDATASIZE - attester_dj_step v, 107, (.Push .PUSH1) - attester_dj_step v, 109, (.Push .PUSH2) - attester_dj_step v, 112, .JUMP - attester_dj_step v, 113, .JUMPDEST - attester_dj_step v, 114, (.Push .PUSH2) - attester_dj_step v, 117, .JUMP - attester_dj_step v, 118, .JUMPDEST - attester_dj_step v, 119, (.Push .PUSH1) - attester_dj_step v, 121, .MLOAD - attester_dj_step v, 122, (.Push .PUSH2) - attester_dj_step v, 125, .SWAP2 - attester_dj_step v, 126, .SWAP1 - attester_dj_step v, 127, (.Push .PUSH2) - attester_dj_step v, 130, .JUMP - attester_dj_step v, 131, .JUMPDEST - attester_dj_step v, 132, (.Push .PUSH1) - attester_dj_step v, 134, .MLOAD - attester_dj_step v, 135, .DUP1 - attester_dj_step v, 136, .SWAP2 - attester_dj_step v, 137, .SUB - attester_dj_step v, 138, .SWAP1 - attester_dj_step v, 139, .RETURN - attester_dj_step v, 140, .JUMPDEST - attester_dj_step v, 141, (.Push .PUSH2) - attester_dj_step v, 144, (.Push .PUSH2) - attester_dj_step v, 147, .CALLDATASIZE - attester_dj_step v, 148, (.Push .PUSH1) - attester_dj_step v, 150, (.Push .PUSH2) - attester_dj_step v, 153, .JUMP - attester_dj_step v, 154, .JUMPDEST - attester_dj_step v, 155, (.Push .PUSH2) - attester_dj_step v, 158, .JUMP - attester_dj_step v, 159, .JUMPDEST - attester_dj_step v, 160, (.Push .PUSH1) - attester_dj_step v, 162, .MLOAD - attester_dj_step v, 163, .SWAP1 - attester_dj_step v, 164, .DUP2 - attester_dj_step v, 165, .MSTORE - attester_dj_step v, 166, (.Push .PUSH1) - attester_dj_step v, 168, .ADD - attester_dj_step v, 169, (.Push .PUSH2) - attester_dj_step v, 172, .JUMP - attester_dj_step v, 173, .JUMPDEST - attester_dj_step v, 174, (.Push .PUSH2) - attester_dj_step v, 177, (.Push .PUSH2) - attester_dj_step v, 180, .CALLDATASIZE - attester_dj_step v, 181, (.Push .PUSH1) - attester_dj_step v, 183, (.Push .PUSH2) - attester_dj_step v, 186, .JUMP - attester_dj_step v, 187, .JUMPDEST - attester_dj_step v, 188, (.Push .PUSH2) - attester_dj_step v, 191, .JUMP - attester_dj_step v, 192, .JUMPDEST - attester_dj_step v, 193, .DUP3 - attester_dj_step v, 194, .DUP1 - attester_dj_step v, 195, .ISZERO - attester_dj_step v, 196, .DUP1 - attester_dj_step v, 197, (.Push .PUSH2) - attester_dj_step v, 200, .JUMPI - attester_dj_step v, 201, .POP - attester_dj_step v, 202, .DUP1 - attester_dj_step v, 203, .DUP3 - attester_dj_step v, 204, .EQ - attester_dj_step v, 205, .ISZERO - attester_dj_step v, 206, .JUMPDEST - attester_dj_step v, 207, .ISZERO - attester_dj_step v, 208, (.Push .PUSH2) - attester_dj_step v, 211, .JUMPI - attester_dj_step v, 212, (.Push .PUSH1) - attester_dj_step v, 214, .MLOAD - attester_dj_step v, 215, (.Push .PUSH4) - attester_dj_step v, 220, (.Push .PUSH1) - attester_dj_step v, 222, .SHL - attester_dj_step v, 223, .DUP2 - attester_dj_step v, 224, .MSTORE - attester_dj_step v, 225, (.Push .PUSH1) - attester_dj_step v, 227, .ADD - attester_dj_step v, 228, (.Push .PUSH1) - attester_dj_step v, 230, .MLOAD - attester_dj_step v, 231, .DUP1 - attester_dj_step v, 232, .SWAP2 - attester_dj_step v, 233, .SUB - attester_dj_step v, 234, .SWAP1 - attester_dj_step v, 235, .REVERT - attester_dj_step v, 236, .JUMPDEST - attester_dj_step v, 237, (.Push .PUSH0) - attester_dj_step v, 238, .DUP2 - attester_dj_step v, 239, (.Push .PUSH1) - attester_dj_step v, 241, (.Push .PUSH1) - attester_dj_step v, 243, (.Push .PUSH1) - attester_dj_step v, 245, .SHL - attester_dj_step v, 246, .SUB - attester_dj_step v, 247, .DUP2 - attester_dj_step v, 248, .GT - attester_dj_step v, 249, .ISZERO - attester_dj_step v, 250, (.Push .PUSH2) - attester_dj_step v, 253, .JUMPI - attester_dj_step v, 254, (.Push .PUSH2) - attester_dj_step v, 257, (.Push .PUSH2) - attester_dj_step v, 260, .JUMP - attester_dj_step v, 261, .JUMPDEST - attester_dj_step v, 262, (.Push .PUSH1) - attester_dj_step v, 264, .MLOAD - attester_dj_step v, 265, .SWAP1 - attester_dj_step v, 266, .DUP1 - attester_dj_step v, 267, .DUP3 - attester_dj_step v, 268, .MSTORE - attester_dj_step v, 269, .DUP1 - attester_dj_step v, 270, (.Push .PUSH1) - attester_dj_step v, 272, .MUL - attester_dj_step v, 273, (.Push .PUSH1) - attester_dj_step v, 275, .ADD - attester_dj_step v, 276, .DUP3 - attester_dj_step v, 277, .ADD - attester_dj_step v, 278, (.Push .PUSH1) - attester_dj_step v, 280, .MSTORE - attester_dj_step v, 281, .DUP1 - attester_dj_step v, 282, .ISZERO - attester_dj_step v, 283, (.Push .PUSH2) - attester_dj_step v, 286, .JUMPI - attester_dj_step v, 287, .DUP2 - attester_dj_step v, 288, (.Push .PUSH1) - attester_dj_step v, 290, .ADD - attester_dj_step v, 291, .JUMPDEST - attester_dj_step v, 292, (.Push .PUSH1) - attester_dj_step v, 294, .DUP1 - attester_dj_step v, 295, .MLOAD - attester_dj_step v, 296, .DUP1 - attester_dj_step v, 297, .DUP3 - attester_dj_step v, 298, .ADD - attester_dj_step v, 299, .SWAP1 - attester_dj_step v, 300, .SWAP2 - attester_dj_step v, 301, .MSTORE - attester_dj_step v, 302, (.Push .PUSH0) - attester_dj_step v, 303, .DUP2 - attester_dj_step v, 304, .MSTORE - attester_dj_step v, 305, (.Push .PUSH1) - attester_dj_step v, 307, (.Push .PUSH1) - attester_dj_step v, 309, .DUP3 - attester_dj_step v, 310, .ADD - attester_dj_step v, 311, .MSTORE - attester_dj_step v, 312, .DUP2 - attester_dj_step v, 313, .MSTORE - attester_dj_step v, 314, (.Push .PUSH1) - attester_dj_step v, 316, .ADD - attester_dj_step v, 317, .SWAP1 - attester_dj_step v, 318, (.Push .PUSH1) - attester_dj_step v, 320, .SWAP1 - attester_dj_step v, 321, .SUB - attester_dj_step v, 322, .SWAP1 - attester_dj_step v, 323, .DUP2 - attester_dj_step v, 324, (.Push .PUSH2) - attester_dj_step v, 327, .JUMPI - attester_dj_step v, 328, .SWAP1 - attester_dj_step v, 329, .POP - attester_dj_step v, 330, .JUMPDEST - attester_dj_step v, 331, .POP - attester_dj_step v, 332, .SWAP1 - attester_dj_step v, 333, .POP - attester_dj_step v, 334, (.Push .PUSH0) - attester_dj_step v, 335, .JUMPDEST - attester_dj_step v, 336, .DUP3 - attester_dj_step v, 337, .DUP2 - attester_dj_step v, 338, .LT - attester_dj_step v, 339, .ISZERO - attester_dj_step v, 340, (.Push .PUSH2) - attester_dj_step v, 343, .JUMPI - attester_dj_step v, 344, .CALLDATASIZE - attester_dj_step v, 345, (.Push .PUSH0) - attester_dj_step v, 346, .DUP7 - attester_dj_step v, 347, .DUP7 - attester_dj_step v, 348, .DUP5 - attester_dj_step v, 349, .DUP2 - attester_dj_step v, 350, .DUP2 - attester_dj_step v, 351, .LT - attester_dj_step v, 352, (.Push .PUSH2) - attester_dj_step v, 355, .JUMPI - attester_dj_step v, 356, (.Push .PUSH2) - attester_dj_step v, 359, (.Push .PUSH2) - attester_dj_step v, 362, .JUMP - attester_dj_step v, 363, .JUMPDEST - attester_dj_step v, 364, .SWAP1 - attester_dj_step v, 365, .POP - attester_dj_step v, 366, (.Push .PUSH1) - attester_dj_step v, 368, .MUL - attester_dj_step v, 369, .DUP2 - attester_dj_step v, 370, .ADD - attester_dj_step v, 371, .SWAP1 - attester_dj_step v, 372, (.Push .PUSH2) - attester_dj_step v, 375, .SWAP2 - attester_dj_step v, 376, .SWAP1 - attester_dj_step v, 377, (.Push .PUSH2) - attester_dj_step v, 380, .JUMP - attester_dj_step v, 381, .JUMPDEST - attester_dj_step v, 382, .SWAP1 - attester_dj_step v, 383, .SWAP3 - attester_dj_step v, 384, .POP - attester_dj_step v, 385, .SWAP1 - attester_dj_step v, 386, .POP - attester_dj_step v, 387, .DUP1 - attester_dj_step v, 388, (.Push .PUSH0) - attester_dj_step v, 389, .DUP2 - attester_dj_step v, 390, .SWAP1 - attester_dj_step v, 391, .SUB - attester_dj_step v, 392, (.Push .PUSH2) - attester_dj_step v, 395, .JUMPI - attester_dj_step v, 396, (.Push .PUSH1) - attester_dj_step v, 398, .MLOAD - attester_dj_step v, 399, (.Push .PUSH4) - attester_dj_step v, 404, (.Push .PUSH1) - attester_dj_step v, 406, .SHL - attester_dj_step v, 407, .DUP2 - attester_dj_step v, 408, .MSTORE - attester_dj_step v, 409, (.Push .PUSH1) - attester_dj_step v, 411, .ADD - attester_dj_step v, 412, (.Push .PUSH1) - attester_dj_step v, 414, .MLOAD - attester_dj_step v, 415, .DUP1 - attester_dj_step v, 416, .SWAP2 - attester_dj_step v, 417, .SUB - attester_dj_step v, 418, .SWAP1 - attester_dj_step v, 419, .REVERT - attester_dj_step v, 420, .JUMPDEST - attester_dj_step v, 421, (.Push .PUSH0) - attester_dj_step v, 422, .DUP2 - attester_dj_step v, 423, (.Push .PUSH1) - attester_dj_step v, 425, (.Push .PUSH1) - attester_dj_step v, 427, (.Push .PUSH1) - attester_dj_step v, 429, .SHL - attester_dj_step v, 430, .SUB - attester_dj_step v, 431, .DUP2 - attester_dj_step v, 432, .GT - attester_dj_step v, 433, .ISZERO - attester_dj_step v, 434, (.Push .PUSH2) - attester_dj_step v, 437, .JUMPI - attester_dj_step v, 438, (.Push .PUSH2) - attester_dj_step v, 441, (.Push .PUSH2) - attester_dj_step v, 444, .JUMP - attester_dj_step v, 445, .JUMPDEST - attester_dj_step v, 446, (.Push .PUSH1) - attester_dj_step v, 448, .MLOAD - attester_dj_step v, 449, .SWAP1 - attester_dj_step v, 450, .DUP1 - attester_dj_step v, 451, .DUP3 - attester_dj_step v, 452, .MSTORE - attester_dj_step v, 453, .DUP1 - attester_dj_step v, 454, (.Push .PUSH1) - attester_dj_step v, 456, .MUL - attester_dj_step v, 457, (.Push .PUSH1) - attester_dj_step v, 459, .ADD - attester_dj_step v, 460, .DUP3 - attester_dj_step v, 461, .ADD - attester_dj_step v, 462, (.Push .PUSH1) - attester_dj_step v, 464, .MSTORE - attester_dj_step v, 465, .DUP1 - attester_dj_step v, 466, .ISZERO - attester_dj_step v, 467, (.Push .PUSH2) - attester_dj_step v, 470, .JUMPI - attester_dj_step v, 471, .DUP2 - attester_dj_step v, 472, (.Push .PUSH1) - attester_dj_step v, 474, .ADD - attester_dj_step v, 475, .JUMPDEST - attester_dj_step v, 476, (.Push .PUSH1) - attester_dj_step v, 478, .DUP1 - attester_dj_step v, 479, .MLOAD - attester_dj_step v, 480, .DUP1 - attester_dj_step v, 481, .DUP3 - attester_dj_step v, 482, .ADD - attester_dj_step v, 483, .SWAP1 - attester_dj_step v, 484, .SWAP2 - attester_dj_step v, 485, .MSTORE - attester_dj_step v, 486, (.Push .PUSH0) - attester_dj_step v, 487, .DUP1 - attester_dj_step v, 488, .DUP3 - attester_dj_step v, 489, .MSTORE - attester_dj_step v, 490, (.Push .PUSH1) - attester_dj_step v, 492, .DUP3 - attester_dj_step v, 493, .ADD - attester_dj_step v, 494, .MSTORE - attester_dj_step v, 495, .DUP2 - attester_dj_step v, 496, .MSTORE - attester_dj_step v, 497, (.Push .PUSH1) - attester_dj_step v, 499, .ADD - attester_dj_step v, 500, .SWAP1 - attester_dj_step v, 501, (.Push .PUSH1) - attester_dj_step v, 503, .SWAP1 - attester_dj_step v, 504, .SUB - attester_dj_step v, 505, .SWAP1 - attester_dj_step v, 506, .DUP2 - attester_dj_step v, 507, (.Push .PUSH2) - attester_dj_step v, 510, .JUMPI - attester_dj_step v, 511, .SWAP1 - attester_dj_step v, 512, .POP - attester_dj_step v, 513, .JUMPDEST - attester_dj_step v, 514, .POP - attester_dj_step v, 515, .SWAP1 - attester_dj_step v, 516, .POP - attester_dj_step v, 517, (.Push .PUSH0) - attester_dj_step v, 518, .JUMPDEST - attester_dj_step v, 519, .DUP3 - attester_dj_step v, 520, .DUP2 - attester_dj_step v, 521, .LT - attester_dj_step v, 522, .ISZERO - attester_dj_step v, 523, (.Push .PUSH2) - attester_dj_step v, 526, .JUMPI - attester_dj_step v, 527, (.Push .PUSH1) - attester_dj_step v, 529, .MLOAD - attester_dj_step v, 530, .DUP1 - attester_dj_step v, 531, (.Push .PUSH1) - attester_dj_step v, 533, .ADD - attester_dj_step v, 534, (.Push .PUSH1) - attester_dj_step v, 536, .MSTORE - attester_dj_step v, 537, .DUP1 - attester_dj_step v, 538, .DUP7 - attester_dj_step v, 539, .DUP7 - attester_dj_step v, 540, .DUP5 - attester_dj_step v, 541, .DUP2 - attester_dj_step v, 542, .DUP2 - attester_dj_step v, 543, .LT - attester_dj_step v, 544, (.Push .PUSH2) - attester_dj_step v, 547, .JUMPI - attester_dj_step v, 548, (.Push .PUSH2) - attester_dj_step v, 551, (.Push .PUSH2) - attester_dj_step v, 554, .JUMP - attester_dj_step v, 555, .JUMPDEST - attester_dj_step v, 556, .SWAP1 - attester_dj_step v, 557, .POP - attester_dj_step v, 558, (.Push .PUSH1) - attester_dj_step v, 560, .MUL - attester_dj_step v, 561, .ADD - attester_dj_step v, 562, .CALLDATALOAD - attester_dj_step v, 563, .DUP2 - attester_dj_step v, 564, .MSTORE - attester_dj_step v, 565, (.Push .PUSH1) - attester_dj_step v, 567, .ADD - attester_dj_step v, 568, (.Push .PUSH0) - attester_dj_step v, 569, .DUP2 - attester_dj_step v, 570, .MSTORE - attester_dj_step v, 571, .POP - attester_dj_step v, 572, .DUP3 - attester_dj_step v, 573, .DUP3 - attester_dj_step v, 574, .DUP2 - attester_dj_step v, 575, .MLOAD - attester_dj_step v, 576, .DUP2 - attester_dj_step v, 577, .LT - attester_dj_step v, 578, (.Push .PUSH2) - attester_dj_step v, 581, .JUMPI - attester_dj_step v, 582, (.Push .PUSH2) - attester_dj_step v, 585, (.Push .PUSH2) - attester_dj_step v, 588, .JUMP - attester_dj_step v, 589, .JUMPDEST - attester_dj_step v, 590, (.Push .PUSH1) - attester_dj_step v, 592, .SWAP1 - attester_dj_step v, 593, .DUP2 - attester_dj_step v, 594, .MUL - attester_dj_step v, 595, .SWAP2 - attester_dj_step v, 596, .SWAP1 - attester_dj_step v, 597, .SWAP2 - attester_dj_step v, 598, .ADD - attester_dj_step v, 599, .ADD - attester_dj_step v, 600, .MSTORE - attester_dj_step v, 601, (.Push .PUSH1) - attester_dj_step v, 603, .ADD - attester_dj_step v, 604, (.Push .PUSH2) - attester_dj_step v, 607, .JUMP - attester_dj_step v, 608, .JUMPDEST - attester_dj_step v, 609, .POP - attester_dj_step v, 610, (.Push .PUSH1) - attester_dj_step v, 612, .MLOAD - attester_dj_step v, 613, .DUP1 - attester_dj_step v, 614, (.Push .PUSH1) - attester_dj_step v, 616, .ADD - attester_dj_step v, 617, (.Push .PUSH1) - attester_dj_step v, 619, .MSTORE - attester_dj_step v, 620, .DUP1 - attester_dj_step v, 621, .DUP13 - attester_dj_step v, 622, .DUP13 - attester_dj_step v, 623, .DUP9 - attester_dj_step v, 624, .DUP2 - attester_dj_step v, 625, .DUP2 - attester_dj_step v, 626, .LT - attester_dj_step v, 627, (.Push .PUSH2) - attester_dj_step v, 630, .JUMPI - attester_dj_step v, 631, (.Push .PUSH2) - attester_dj_step v, 634, (.Push .PUSH2) - attester_dj_step v, 637, .JUMP - attester_dj_step v, 638, .JUMPDEST - attester_dj_step v, 639, .SWAP1 - attester_dj_step v, 640, .POP - attester_dj_step v, 641, (.Push .PUSH1) - attester_dj_step v, 643, .MUL - attester_dj_step v, 644, .ADD - attester_dj_step v, 645, .CALLDATALOAD - attester_dj_step v, 646, .DUP2 - attester_dj_step v, 647, .MSTORE - attester_dj_step v, 648, (.Push .PUSH1) - attester_dj_step v, 650, .ADD - attester_dj_step v, 651, .DUP3 - attester_dj_step v, 652, .DUP2 - attester_dj_step v, 653, .MSTORE - attester_dj_step v, 654, .POP - attester_dj_step v, 655, .DUP7 - attester_dj_step v, 656, .DUP7 - attester_dj_step v, 657, .DUP2 - attester_dj_step v, 658, .MLOAD - attester_dj_step v, 659, .DUP2 - attester_dj_step v, 660, .LT - attester_dj_step v, 661, (.Push .PUSH2) - attester_dj_step v, 664, .JUMPI - attester_dj_step v, 665, (.Push .PUSH2) - attester_dj_step v, 668, (.Push .PUSH2) - attester_dj_step v, 671, .JUMP - attester_dj_step v, 672, .JUMPDEST - attester_dj_step v, 673, (.Push .PUSH1) - attester_dj_step v, 675, .MUL - attester_dj_step v, 676, (.Push .PUSH1) - attester_dj_step v, 678, .ADD - attester_dj_step v, 679, .ADD - attester_dj_step v, 680, .DUP2 - attester_dj_step v, 681, .SWAP1 - attester_dj_step v, 682, .MSTORE - attester_dj_step v, 683, .POP - attester_dj_step v, 684, .POP - attester_dj_step v, 685, .POP - attester_dj_step v, 686, .POP - attester_dj_step v, 687, .POP - attester_dj_step v, 688, .DUP1 - attester_dj_step v, 689, (.Push .PUSH1) - attester_dj_step v, 691, .ADD - attester_dj_step v, 692, .SWAP1 - attester_dj_step v, 693, .POP - attester_dj_step v, 694, (.Push .PUSH2) - attester_dj_step v, 697, .JUMP - attester_dj_step v, 698, .JUMPDEST - attester_dj_step v, 699, .POP - attester_dj_step v, 700, (.Push .PUSH1) - attester_dj_step v, 702, .MLOAD - attester_dj_step v, 703, (.Push .PUSH4) - attester_dj_step v, 708, (.Push .PUSH1) - attester_dj_step v, 710, .SHL - attester_dj_step v, 711, .DUP2 - attester_dj_step v, 712, .MSTORE - attester_dj_step v, 713, (.Push .PUSH1) - attester_dj_step v, 715, (.Push .PUSH1) - attester_dj_step v, 717, (.Push .PUSH1) - attester_dj_step v, 719, .SHL - attester_dj_step v, 720, .SUB - attester_dj_step v, 721, (.Push .PUSH32) - attester_dj_step v, 754, .AND - attester_dj_step v, 755, .SWAP1 - attester_dj_step v, 756, (.Push .PUSH4) - attester_dj_step v, 761, .SWAP1 - attester_dj_step v, 762, (.Push .PUSH2) - attester_dj_step v, 765, .SWAP1 - attester_dj_step v, 766, .DUP5 - attester_dj_step v, 767, .SWAP1 - attester_dj_step v, 768, (.Push .PUSH1) - attester_dj_step v, 770, .ADD - attester_dj_step v, 771, (.Push .PUSH2) - attester_dj_step v, 774, .JUMP - attester_dj_step v, 775, .JUMPDEST - attester_dj_step v, 776, (.Push .PUSH0) - attester_dj_step v, 777, (.Push .PUSH1) - attester_dj_step v, 779, .MLOAD - attester_dj_step v, 780, .DUP1 - attester_dj_step v, 781, .DUP4 - attester_dj_step v, 782, .SUB - attester_dj_step v, 783, .DUP2 - attester_dj_step v, 784, (.Push .PUSH0) - attester_dj_step v, 785, .DUP8 - attester_dj_step v, 786, .DUP1 - attester_dj_step v, 787, .EXTCODESIZE - attester_dj_step v, 788, .ISZERO - attester_dj_step v, 789, .DUP1 - attester_dj_step v, 790, .ISZERO - attester_dj_step v, 791, (.Push .PUSH2) - attester_dj_step v, 794, .JUMPI - attester_dj_step v, 795, (.Push .PUSH0) - attester_dj_step v, 796, .DUP1 - attester_dj_step v, 797, .REVERT - attester_dj_step v, 798, .JUMPDEST - attester_dj_step v, 799, .POP - attester_dj_step v, 800, .GAS - attester_dj_step v, 801, .CALL - attester_dj_step v, 802, .ISZERO - attester_dj_step v, 803, .DUP1 - attester_dj_step v, 804, .ISZERO - attester_dj_step v, 805, (.Push .PUSH2) - attester_dj_step v, 808, .JUMPI - attester_dj_step v, 809, .RETURNDATASIZE - attester_dj_step v, 810, (.Push .PUSH0) - attester_dj_step v, 811, .DUP1 - attester_dj_step v, 812, .RETURNDATACOPY - attester_dj_step v, 813, .RETURNDATASIZE - attester_dj_step v, 814, (.Push .PUSH0) - attester_dj_step v, 815, .REVERT - attester_dj_step v, 816, .JUMPDEST - attester_dj_step v, 817, .POP - attester_dj_step v, 818, .POP - attester_dj_step v, 819, .POP - attester_dj_step v, 820, .POP - attester_dj_step v, 821, .POP - attester_dj_step v, 822, .POP - attester_dj_step v, 823, .POP - attester_dj_step v, 824, .POP - attester_dj_step v, 825, .POP - attester_dj_step v, 826, .POP - attester_dj_step v, 827, .JUMP - attester_dj_step v, 828, .JUMPDEST - attester_dj_step v, 829, (.Push .PUSH1) - attester_dj_step v, 831, .DUP4 - attester_dj_step v, 832, .DUP1 - attester_dj_step v, 833, .ISZERO - attester_dj_step v, 834, .DUP1 - attester_dj_step v, 835, (.Push .PUSH2) - attester_dj_step v, 838, .JUMPI - attester_dj_step v, 839, .POP - attester_dj_step v, 840, .DUP1 - attester_dj_step v, 841, .DUP4 - attester_dj_step v, 842, .EQ - attester_dj_step v, 843, .ISZERO - attester_dj_step v, 844, .JUMPDEST - attester_dj_step v, 845, .ISZERO - attester_dj_step v, 846, (.Push .PUSH2) - attester_dj_step v, 849, .JUMPI - attester_dj_step v, 850, (.Push .PUSH1) - attester_dj_step v, 852, .MLOAD - attester_dj_step v, 853, (.Push .PUSH4) - attester_dj_step v, 858, (.Push .PUSH1) - attester_dj_step v, 860, .SHL - attester_dj_step v, 861, .DUP2 - attester_dj_step v, 862, .MSTORE - attester_dj_step v, 863, (.Push .PUSH1) - attester_dj_step v, 865, .ADD - attester_dj_step v, 866, (.Push .PUSH1) - attester_dj_step v, 868, .MLOAD - attester_dj_step v, 869, .DUP1 - attester_dj_step v, 870, .SWAP2 - attester_dj_step v, 871, .SUB - attester_dj_step v, 872, .SWAP1 - attester_dj_step v, 873, .REVERT - attester_dj_step v, 874, .JUMPDEST - attester_dj_step v, 875, (.Push .PUSH0) - attester_dj_step v, 876, .DUP2 - attester_dj_step v, 877, (.Push .PUSH1) - attester_dj_step v, 879, (.Push .PUSH1) - attester_dj_step v, 881, (.Push .PUSH1) - attester_dj_step v, 883, .SHL - attester_dj_step v, 884, .SUB - attester_dj_step v, 885, .DUP2 - attester_dj_step v, 886, .GT - attester_dj_step v, 887, .ISZERO - attester_dj_step v, 888, (.Push .PUSH2) - attester_dj_step v, 891, .JUMPI - attester_dj_step v, 892, (.Push .PUSH2) - attester_dj_step v, 895, (.Push .PUSH2) - attester_dj_step v, 898, .JUMP - attester_dj_step v, 899, .JUMPDEST - attester_dj_step v, 900, (.Push .PUSH1) - attester_dj_step v, 902, .MLOAD - attester_dj_step v, 903, .SWAP1 - attester_dj_step v, 904, .DUP1 - attester_dj_step v, 905, .DUP3 - attester_dj_step v, 906, .MSTORE - attester_dj_step v, 907, .DUP1 - attester_dj_step v, 908, (.Push .PUSH1) - attester_dj_step v, 910, .MUL - attester_dj_step v, 911, (.Push .PUSH1) - attester_dj_step v, 913, .ADD - attester_dj_step v, 914, .DUP3 - attester_dj_step v, 915, .ADD - attester_dj_step v, 916, (.Push .PUSH1) - attester_dj_step v, 918, .MSTORE - attester_dj_step v, 919, .DUP1 - attester_dj_step v, 920, .ISZERO - attester_dj_step v, 921, (.Push .PUSH2) - attester_dj_step v, 924, .JUMPI - attester_dj_step v, 925, .DUP2 - attester_dj_step v, 926, (.Push .PUSH1) - attester_dj_step v, 928, .ADD - attester_dj_step v, 929, .JUMPDEST - attester_dj_step v, 930, (.Push .PUSH1) - attester_dj_step v, 932, .DUP1 - attester_dj_step v, 933, .MLOAD - attester_dj_step v, 934, .DUP1 - attester_dj_step v, 935, .DUP3 - attester_dj_step v, 936, .ADD - attester_dj_step v, 937, .SWAP1 - attester_dj_step v, 938, .SWAP2 - attester_dj_step v, 939, .MSTORE - attester_dj_step v, 940, (.Push .PUSH0) - attester_dj_step v, 941, .DUP2 - attester_dj_step v, 942, .MSTORE - attester_dj_step v, 943, (.Push .PUSH1) - attester_dj_step v, 945, (.Push .PUSH1) - attester_dj_step v, 947, .DUP3 - attester_dj_step v, 948, .ADD - attester_dj_step v, 949, .MSTORE - attester_dj_step v, 950, .DUP2 - attester_dj_step v, 951, .MSTORE - attester_dj_step v, 952, (.Push .PUSH1) - attester_dj_step v, 954, .ADD - attester_dj_step v, 955, .SWAP1 - attester_dj_step v, 956, (.Push .PUSH1) - attester_dj_step v, 958, .SWAP1 - attester_dj_step v, 959, .SUB - attester_dj_step v, 960, .SWAP1 - attester_dj_step v, 961, .DUP2 - attester_dj_step v, 962, (.Push .PUSH2) - attester_dj_step v, 965, .JUMPI - attester_dj_step v, 966, .SWAP1 - attester_dj_step v, 967, .POP - attester_dj_step v, 968, .JUMPDEST - attester_dj_step v, 969, .POP - attester_dj_step v, 970, .SWAP1 - attester_dj_step v, 971, .POP - attester_dj_step v, 972, (.Push .PUSH0) - attester_dj_step v, 973, .JUMPDEST - attester_dj_step v, 974, .DUP3 - attester_dj_step v, 975, .DUP2 - attester_dj_step v, 976, .LT - attester_dj_step v, 977, .ISZERO - attester_dj_step v, 978, (.Push .PUSH2) - attester_dj_step v, 981, .JUMPI - attester_dj_step v, 982, .CALLDATASIZE - attester_dj_step v, 983, (.Push .PUSH0) - attester_dj_step v, 984, .DUP8 - attester_dj_step v, 985, .DUP8 - attester_dj_step v, 986, .DUP5 - attester_dj_step v, 987, .DUP2 - attester_dj_step v, 988, .DUP2 - attester_dj_step v, 989, .LT - attester_dj_step v, 990, (.Push .PUSH2) - attester_dj_step v, 993, .JUMPI - attester_dj_step v, 994, (.Push .PUSH2) - attester_dj_step v, 997, (.Push .PUSH2) - attester_dj_step v, 1000, .JUMP - attester_dj_step v, 1001, .JUMPDEST - rw [Reasoning.Theory.D_J_aux_acc (patchedRuntime v) 1002] - rw [Array.mem_append] - apply Or.inl - native_decide - -theorem attesterX_multiAttestOuterSecondArrayAccessCheck - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base len : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hsecondLenNe : (attesterSecondArrayLengthWord I).toNat ≠ 0) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨982⟩ : UInt256) - [⟨0⟩, base, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨993⟩ : UInt256) - [⟨1001⟩, ⟨1⟩, ⟨0⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, base, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - have hlt : - UInt256.lt (⟨0⟩ : UInt256) (attesterSecondArrayLengthWord I) = ⟨1⟩ := by - apply ult_one - rw [show (⟨0⟩ : UInt256).toNat = 0 by decide] - omega - exact ⟨_, _, by - simpa [hlt] using - (evm_run hreach with [ - raw calldatasize (by attester_decode_at v, ⟨982⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨983⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup8 (by attester_decode_at v, ⟨984⟩, 0x87, .DUP8) (by evm_ov), - raw dup8 (by attester_decode_at v, ⟨985⟩, 0x87, .DUP8) (by evm_ov), - raw dup5 (by attester_decode_at v, ⟨986⟩, 0x84, .DUP5) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨987⟩, 0x81, .DUP2) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨988⟩, 0x81, .DUP2) (by evm_ov), - raw lt (by attester_decode_at v, ⟨989⟩, 0x10, .LT) (by evm_ov), - raw push2 ⟨1001⟩ (by attester_decode_at v, ⟨990⟩, 0x61, (.Push .PUSH2)) - (by evm_ov)])⟩ - -theorem attesterX_multiAttestOuterSecondArrayAccessOk - {cA gh bl σ σ₀ A I} {g : Sat256} (v : AttesterImmutables) - {base len : UInt256} {mem : ByteArray} {aw : UInt256} {k C} - (hsecondLenNe : (attesterSecondArrayLengthWord I).toNat ≠ 0) - (hreach : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨982⟩ : UInt256) - [⟨0⟩, base, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1001⟩ : UInt256) - [⟨0⟩, attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - ⟨0⟩, UInt256.ofNat I.calldata.size, ⟨0⟩, base, len, ⟨96⟩, - attesterSecondArrayLengthWord I, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 36)) + ⟨32⟩, - len, - (UInt256.add ⟨4⟩ (calldataWord I.calldata 4)) + ⟨32⟩, - ⟨118⟩, solcSelectorWord I] - mem aw ByteArray.empty (cA, σ) k' C' := by - obtain ⟨k0, C0, rd0⟩ := - attesterX_multiAttestOuterSecondArrayAccessCheck - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) v - (base := base) (len := len) (mem := mem) (aw := aw) - (k := k) (C := C) hsecondLenNe hreach - exact ⟨_, _, evm_run rd0 with [ - raw jumpiT (by attester_decode_at v, ⟨993⟩, 0x57, .JUMPI) - (by decide) (attesterMultiAttestOuterSourceElementOkJumpdest v) - (by evm_ov)]⟩ - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/Revoke.lean b/Benchmarks/EAS/Attester/Revoke.lean deleted file mode 100644 index 7f1f6cde..00000000 --- a/Benchmarks/EAS/Attester/Revoke.lean +++ /dev/null @@ -1,1698 +0,0 @@ -import Benchmarks.EAS.Attester.Common -import Reasoning.ExternalCall - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.EAS.Attester.Immutables - -namespace Benchmarks.EAS.Attester - -/-! ## `revoke(bytes32,bytes32)` -/ - -def attesterRevokeSchemaBytes (I : ExecutionEnv) : List UInt8 := - (I.calldata.toList.drop 4).take 32 - -def attesterRevokeUidBytes (I : ExecutionEnv) : List UInt8 := - (I.calldata.toList.drop 36).take 32 - -def attesterRevokeSchemaWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -def attesterRevokeUidWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 36 - -def attesterRevokeStore (I : ExecutionEnv) : Store := - ((∅ : Store).insert "schema" (.fixedBytes bytes32Width (attesterRevokeSchemaBytes I))).insert - "uid" (.fixedBytes bytes32Width (attesterRevokeUidBytes I)) - -def attesterRevokeDataValue (I : ExecutionEnv) : Value := - .tuple [.fixedBytes bytes32Width (attesterRevokeUidBytes I), .int 0] - -def attesterRevokeRequestValue (I : ExecutionEnv) : Value := - .tuple [.fixedBytes bytes32Width (attesterRevokeSchemaBytes I), attesterRevokeDataValue I] - -def attesterRevokeArgVals (I : ExecutionEnv) : List Value := - [attesterRevokeRequestValue I] - -private theorem byteArray_toList_toByteArray (b : ByteArray) : - b.toList.toByteArray = b := by - apply ByteArray.ext - apply Array.toList_inj.mp - rw [byteArray_toList_eq] - simp - -def attesterRevokeExternalCalldata (I : ExecutionEnv) : ByteArray := - revokeSelector ++ - UInt256.toByteArray (attesterRevokeSchemaWord I) ++ - UInt256.toByteArray (attesterRevokeUidWord I) ++ - UInt256.toByteArray ⟨0⟩ - -private abbrev attesterRevokeWriteWord (mem : ByteArray) (off : Nat) - (w : UInt256) : ByteArray := - (UInt256.toByteArray w).write 0 mem off 32 - -def attesterRevokeEasWord (v : AttesterImmutables) : UInt256 := - EVM.Word.ofNat v.eas.toNat - -def attesterRevokeTargetWord (v : AttesterImmutables) : UInt256 := - UInt256.land solcAddrMask (attesterRevokeEasWord v) - -theorem attesterRevokeEasWord_canonical (v : AttesterImmutables) : - (attesterRevokeEasWord v).toNat < EVM.addressModulus := by - change (UInt256.ofNat v.eas.val).toNat < EVM.addressModulus - rw [UInt256.toNat_ofNat_of_lt] - · change v.eas.val < AccountAddress.size - exact v.eas.isLt - · exact lt_of_lt_of_le v.eas.isLt (by decide) - -theorem attesterRevokeEasWord_clean (v : AttesterImmutables) : - UInt256.land solcAddrMask (attesterRevokeEasWord v) = - attesterRevokeEasWord v := - solcAddrMask_clean_left (attesterRevokeEasWord_canonical v) - -theorem attesterRevokeTargetWord_eq_easWord (v : AttesterImmutables) : - attesterRevokeTargetWord v = attesterRevokeEasWord v := by - unfold attesterRevokeTargetWord - rw [attesterRevokeEasWord_clean] - -theorem attesterRevokeTarget_eq (v : AttesterImmutables) : - EVM.address v.eas = AccountAddress.ofUInt256 (attesterRevokeTargetWord v) := by - rw [attesterRevokeTargetWord_eq_easWord] - have hleft : EVM.address (v.eas : Nat) = v.eas := by - apply Fin.ext - simp [EVM.address, EVM.uintN] - exact Nat.mod_eq_of_lt v.eas.isLt - have hright : AccountAddress.ofUInt256 (attesterRevokeEasWord v) = v.eas := by - change AccountAddress.ofUInt256 (UInt256.ofNat v.eas.val) = v.eas - exact accountAddress_roundtrip v.eas - rw [hleft, hright] - -noncomputable def attesterRevokeMem192 : ByteArray := - writeCascade solcFreePtrMem [(64, (⟨192⟩ : UInt256))] - -noncomputable def attesterRevokeMemSchema (I : ExecutionEnv) : ByteArray := - writeCascade attesterRevokeMem192 [(128, attesterRevokeSchemaWord I)] - -noncomputable def attesterRevokeMem256 (I : ExecutionEnv) : ByteArray := - writeCascade (attesterRevokeMemSchema I) [(64, (⟨256⟩ : UInt256))] - -noncomputable def attesterRevokeMemUid (I : ExecutionEnv) : ByteArray := - writeCascade (attesterRevokeMem256 I) [(192, attesterRevokeUidWord I)] - -noncomputable def attesterRevokeMemValue (I : ExecutionEnv) : ByteArray := - writeCascade (attesterRevokeMemUid I) [(224, (⟨0⟩ : UInt256))] - -noncomputable def attesterRevokeMemDataOffset (I : ExecutionEnv) : ByteArray := - writeCascade (attesterRevokeMemValue I) [(160, (⟨192⟩ : UInt256))] - -def attesterRevokeSelectorWord : UInt256 := - UInt256.shiftLeft (⟨0x46926267⟩ : UInt256) ⟨224⟩ - -noncomputable def attesterRevokeCallMemSelector (I : ExecutionEnv) : ByteArray := - writeCascade (attesterRevokeMemDataOffset I) [(256, attesterRevokeSelectorWord)] - -noncomputable def attesterRevokeCallMemSchema (I : ExecutionEnv) : ByteArray := - writeCascade (attesterRevokeCallMemSelector I) [(260, attesterRevokeSchemaWord I)] - -noncomputable def attesterRevokeCallMemUid (I : ExecutionEnv) : ByteArray := - writeCascade (attesterRevokeCallMemSchema I) [(292, attesterRevokeUidWord I)] - -noncomputable def attesterRevokeCallMem (I : ExecutionEnv) : ByteArray := - writeCascade (attesterRevokeCallMemUid I) [(324, (⟨0⟩ : UInt256))] - -theorem attesterRevokeMem192_size : - attesterRevokeMem192.size = 96 := by - unfold attesterRevokeMem192 - exact writeCascade_size_of_base solcFreePtrMem [(64, (⟨192⟩ : UInt256))] - (base := 96) (out := 96) solcFreePtrMem_size - (by norm_num [WriteGapsOk, USize.size]) (by norm_num [writeCascadeSize]) - -theorem attesterRevokeMemSchema_size (I : ExecutionEnv) : - (attesterRevokeMemSchema I).size = 160 := by - unfold attesterRevokeMemSchema - exact writeCascade_size_of_base attesterRevokeMem192 [(128, attesterRevokeSchemaWord I)] - (base := 96) (out := 160) attesterRevokeMem192_size - (by - simp [WriteGapsOk] - exact lt_usize 32 (by norm_num)) - (by norm_num [writeCascadeSize]) - -theorem attesterRevokeMem256_size (I : ExecutionEnv) : - (attesterRevokeMem256 I).size = 160 := by - unfold attesterRevokeMem256 - exact writeCascade_size_of_base (attesterRevokeMemSchema I) [(64, (⟨256⟩ : UInt256))] - (base := 160) (out := 160) (attesterRevokeMemSchema_size I) - (by norm_num [WriteGapsOk, USize.size]) (by norm_num [writeCascadeSize]) - -theorem attesterRevokeMemUid_size (I : ExecutionEnv) : - (attesterRevokeMemUid I).size = 224 := by - unfold attesterRevokeMemUid - exact writeCascade_size_of_base (attesterRevokeMem256 I) [(192, attesterRevokeUidWord I)] - (base := 160) (out := 224) (attesterRevokeMem256_size I) - (by - simp [WriteGapsOk] - exact lt_usize 32 (by norm_num)) - (by norm_num [writeCascadeSize]) - -theorem attesterRevokeMemValue_size (I : ExecutionEnv) : - (attesterRevokeMemValue I).size = 256 := by - unfold attesterRevokeMemValue - exact writeCascade_size_of_base (attesterRevokeMemUid I) [(224, (⟨0⟩ : UInt256))] - (base := 224) (out := 256) (attesterRevokeMemUid_size I) - (by norm_num [WriteGapsOk, USize.size]) (by norm_num [writeCascadeSize]) - -theorem attesterRevokeMemDataOffset_size (I : ExecutionEnv) : - (attesterRevokeMemDataOffset I).size = 256 := by - unfold attesterRevokeMemDataOffset - exact writeCascade_size_of_base (attesterRevokeMemValue I) [(160, (⟨192⟩ : UInt256))] - (base := 256) (out := 256) (attesterRevokeMemValue_size I) - (by norm_num [WriteGapsOk, USize.size]) (by norm_num [writeCascadeSize]) - -theorem attesterRevokeCallMemSelector_size (I : ExecutionEnv) : - (attesterRevokeCallMemSelector I).size = 288 := by - unfold attesterRevokeCallMemSelector - exact writeCascade_size_of_base (attesterRevokeMemDataOffset I) - [(256, attesterRevokeSelectorWord)] (base := 256) (out := 288) - (attesterRevokeMemDataOffset_size I) - (by norm_num [WriteGapsOk, USize.size]) (by norm_num [writeCascadeSize]) - -theorem attesterRevokeCallMemSchema_size (I : ExecutionEnv) : - (attesterRevokeCallMemSchema I).size = 292 := by - unfold attesterRevokeCallMemSchema - exact writeCascade_size_of_base (attesterRevokeCallMemSelector I) - [(260, attesterRevokeSchemaWord I)] (base := 288) (out := 292) - (attesterRevokeCallMemSelector_size I) - (by norm_num [WriteGapsOk, USize.size]) (by norm_num [writeCascadeSize]) - -theorem attesterRevokeCallMemUid_size (I : ExecutionEnv) : - (attesterRevokeCallMemUid I).size = 324 := by - unfold attesterRevokeCallMemUid - exact writeCascade_size_of_base (attesterRevokeCallMemSchema I) - [(292, attesterRevokeUidWord I)] (base := 292) (out := 324) - (attesterRevokeCallMemSchema_size I) - (by norm_num [WriteGapsOk, USize.size]) (by norm_num [writeCascadeSize]) - -theorem attesterRevokeCallMem_size (I : ExecutionEnv) : - (attesterRevokeCallMem I).size = 356 := by - unfold attesterRevokeCallMem - exact writeCascade_size_of_base (attesterRevokeCallMemUid I) [(324, (⟨0⟩ : UInt256))] - (base := 324) (out := 356) (attesterRevokeCallMemUid_size I) - (by norm_num [WriteGapsOk, USize.size]) (by norm_num [writeCascadeSize]) - -theorem attesterRevokeMem192_read64 : - attesterRevokeMem192.readWithPadding 64 32 = UInt256.toByteArray ⟨192⟩ := by - unfold attesterRevokeMem192 - exact writeCascade_read_word_of_head_of_base solcFreePtrMem (base := 96) - (word := (⟨192⟩ : UInt256)) (rest := []) - (hbase := solcFreePtrMem_size) (hgap := by norm_num [USize.size]) - (hlater := by norm_num [WindowDisjointFromWrites, USize.size]) - -theorem attesterRevokeMem256_read64 (I : ExecutionEnv) : - (attesterRevokeMem256 I).readWithPadding 64 32 = UInt256.toByteArray ⟨256⟩ := by - unfold attesterRevokeMem256 - exact writeCascade_read_word_of_head_of_base (attesterRevokeMemSchema I) (base := 160) - (word := (⟨256⟩ : UInt256)) (rest := []) - (hbase := attesterRevokeMemSchema_size I) (hgap := by norm_num [USize.size]) - (hlater := by norm_num [WindowDisjointFromWrites, USize.size]) - -theorem attesterRevokeMemSchema_read128 (I : ExecutionEnv) : - (attesterRevokeMemSchema I).readWithPadding 128 32 = - UInt256.toByteArray (attesterRevokeSchemaWord I) := by - unfold attesterRevokeMemSchema - exact writeCascade_read_word_of_head_of_base attesterRevokeMem192 (base := 96) - (word := attesterRevokeSchemaWord I) (rest := []) - (hbase := attesterRevokeMem192_size) (hgap := by exact lt_usize 32 (by norm_num)) - (hlater := by norm_num [WindowDisjointFromWrites, USize.size]) - -theorem attesterRevokeMemSchema_read64 (I : ExecutionEnv) : - (attesterRevokeMemSchema I).readWithPadding 64 32 = UInt256.toByteArray ⟨192⟩ := by - unfold attesterRevokeMemSchema - rw [writeCascade_read_preserved_len attesterRevokeMem192 - [(128, attesterRevokeSchemaWord I)] 64 32 (by - rw [attesterRevokeMem192_size] - simp [WindowDisjointFromWrites] - exact lt_usize 32 (by norm_num)) (by norm_num) (by norm_num)] - exact attesterRevokeMem192_read64 - -theorem attesterRevokeMemDataOffset_read160 (I : ExecutionEnv) : - (attesterRevokeMemDataOffset I).readWithPadding 160 32 = UInt256.toByteArray ⟨192⟩ := by - unfold attesterRevokeMemDataOffset - exact writeCascade_read_word_of_head_of_base (attesterRevokeMemValue I) (base := 256) - (word := (⟨192⟩ : UInt256)) (rest := []) - (hbase := attesterRevokeMemValue_size I) (hgap := by norm_num [USize.size]) - (hlater := by norm_num [WindowDisjointFromWrites, USize.size]) - -theorem attesterRevokeMemUid_read192 (I : ExecutionEnv) : - (attesterRevokeMemUid I).readWithPadding 192 32 = - UInt256.toByteArray (attesterRevokeUidWord I) := by - unfold attesterRevokeMemUid - exact writeCascade_read_word_of_head_of_base (attesterRevokeMem256 I) (base := 160) - (word := attesterRevokeUidWord I) (rest := []) - (hbase := attesterRevokeMem256_size I) (hgap := by exact lt_usize 32 (by norm_num)) - (hlater := by norm_num [WindowDisjointFromWrites, USize.size]) - -theorem attesterRevokeMemValue_read224 (I : ExecutionEnv) : - (attesterRevokeMemValue I).readWithPadding 224 32 = UInt256.toByteArray ⟨0⟩ := by - unfold attesterRevokeMemValue - exact writeCascade_read_word_of_head_of_base (attesterRevokeMemUid I) (base := 224) - (word := (⟨0⟩ : UInt256)) (rest := []) - (hbase := attesterRevokeMemUid_size I) (hgap := by norm_num [USize.size]) - (hlater := by norm_num [WindowDisjointFromWrites, USize.size]) - -theorem attesterRevokeCallMem_read64 (I : ExecutionEnv) : - (attesterRevokeCallMem I).readWithPadding 64 32 = UInt256.toByteArray ⟨256⟩ := by - unfold attesterRevokeCallMem - rw [writeCascade_read_preserved_len (attesterRevokeCallMemUid I) - [(324, (⟨0⟩ : UInt256))] 64 32 (by - rw [attesterRevokeCallMemUid_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeCallMemUid - rw [writeCascade_read_preserved_len (attesterRevokeCallMemSchema I) - [(292, attesterRevokeUidWord I)] 64 32 (by - rw [attesterRevokeCallMemSchema_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeCallMemSchema - rw [writeCascade_read_preserved_len (attesterRevokeCallMemSelector I) - [(260, attesterRevokeSchemaWord I)] 64 32 (by - rw [attesterRevokeCallMemSelector_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeCallMemSelector - rw [writeCascade_read_preserved_len (attesterRevokeMemDataOffset I) - [(256, attesterRevokeSelectorWord)] 64 32 (by - rw [attesterRevokeMemDataOffset_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeMemDataOffset - rw [writeCascade_read_preserved_len (attesterRevokeMemValue I) - [(160, (⟨192⟩ : UInt256))] 64 32 (by - rw [attesterRevokeMemValue_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeMemValue - rw [writeCascade_read_preserved_len (attesterRevokeMemUid I) - [(224, (⟨0⟩ : UInt256))] 64 32 (by - rw [attesterRevokeMemUid_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeMemUid - rw [writeCascade_read_preserved_len (attesterRevokeMem256 I) - [(192, attesterRevokeUidWord I)] 64 32 (by - rw [attesterRevokeMem256_size I] - simp [WindowDisjointFromWrites] - exact lt_usize 32 (by norm_num)) (by norm_num) (by norm_num)] - exact attesterRevokeMem256_read64 I - -theorem attesterRevokeMemDataOffset_read64 (I : ExecutionEnv) : - (attesterRevokeMemDataOffset I).readWithPadding 64 32 = UInt256.toByteArray ⟨256⟩ := by - unfold attesterRevokeMemDataOffset - rw [writeCascade_read_preserved_len (attesterRevokeMemValue I) - [(160, (⟨192⟩ : UInt256))] 64 32 (by - rw [attesterRevokeMemValue_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeMemValue - rw [writeCascade_read_preserved_len (attesterRevokeMemUid I) - [(224, (⟨0⟩ : UInt256))] 64 32 (by - rw [attesterRevokeMemUid_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeMemUid - rw [writeCascade_read_preserved_len (attesterRevokeMem256 I) - [(192, attesterRevokeUidWord I)] 64 32 (by - rw [attesterRevokeMem256_size I] - simp [WindowDisjointFromWrites] - exact lt_usize 32 (by norm_num)) (by norm_num) (by norm_num)] - exact attesterRevokeMem256_read64 I - -theorem attesterRevokeMemDataOffset_read128 (I : ExecutionEnv) : - (attesterRevokeMemDataOffset I).readWithPadding 128 32 = - UInt256.toByteArray (attesterRevokeSchemaWord I) := by - unfold attesterRevokeMemDataOffset - rw [writeCascade_read_preserved_len (attesterRevokeMemValue I) - [(160, (⟨192⟩ : UInt256))] 128 32 (by - rw [attesterRevokeMemValue_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeMemValue - rw [writeCascade_read_preserved_len (attesterRevokeMemUid I) - [(224, (⟨0⟩ : UInt256))] 128 32 (by - rw [attesterRevokeMemUid_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeMemUid - rw [writeCascade_read_preserved_len (attesterRevokeMem256 I) - [(192, attesterRevokeUidWord I)] 128 32 (by - rw [attesterRevokeMem256_size I] - simp [WindowDisjointFromWrites] - exact lt_usize 32 (by norm_num)) (by norm_num) (by norm_num)] - unfold attesterRevokeMem256 - rw [writeCascade_read_preserved_len (attesterRevokeMemSchema I) - [(64, (⟨256⟩ : UInt256))] 128 32 (by - rw [attesterRevokeMemSchema_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - exact attesterRevokeMemSchema_read128 I - -theorem attesterRevokeMemDataOffset_read192 (I : ExecutionEnv) : - (attesterRevokeMemDataOffset I).readWithPadding 192 32 = - UInt256.toByteArray (attesterRevokeUidWord I) := by - unfold attesterRevokeMemDataOffset - rw [writeCascade_read_preserved_len (attesterRevokeMemValue I) - [(160, (⟨192⟩ : UInt256))] 192 32 (by - rw [attesterRevokeMemValue_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeMemValue - rw [writeCascade_read_preserved_len (attesterRevokeMemUid I) - [(224, (⟨0⟩ : UInt256))] 192 32 (by - rw [attesterRevokeMemUid_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - exact attesterRevokeMemUid_read192 I - -theorem attesterRevokeMemDataOffset_read224 (I : ExecutionEnv) : - (attesterRevokeMemDataOffset I).readWithPadding 224 32 = UInt256.toByteArray ⟨0⟩ := by - unfold attesterRevokeMemDataOffset - rw [writeCascade_read_preserved_len (attesterRevokeMemValue I) - [(160, (⟨192⟩ : UInt256))] 224 32 (by - rw [attesterRevokeMemValue_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - exact attesterRevokeMemValue_read224 I - -theorem attesterRevokeCallMemSelector_read128 (I : ExecutionEnv) : - (attesterRevokeCallMemSelector I).readWithPadding 128 32 = - UInt256.toByteArray (attesterRevokeSchemaWord I) := by - unfold attesterRevokeCallMemSelector - rw [writeCascade_read_preserved_len (attesterRevokeMemDataOffset I) - [(256, attesterRevokeSelectorWord)] 128 32 (by - rw [attesterRevokeMemDataOffset_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - exact attesterRevokeMemDataOffset_read128 I - -theorem attesterRevokeCallMemSchema_read160 (I : ExecutionEnv) : - (attesterRevokeCallMemSchema I).readWithPadding 160 32 = UInt256.toByteArray ⟨192⟩ := by - unfold attesterRevokeCallMemSchema - rw [writeCascade_read_preserved_len (attesterRevokeCallMemSelector I) - [(260, attesterRevokeSchemaWord I)] 160 32 (by - rw [attesterRevokeCallMemSelector_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeCallMemSelector - rw [writeCascade_read_preserved_len (attesterRevokeMemDataOffset I) - [(256, attesterRevokeSelectorWord)] 160 32 (by - rw [attesterRevokeMemDataOffset_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - exact attesterRevokeMemDataOffset_read160 I - -theorem attesterRevokeCallMemSchema_read192 (I : ExecutionEnv) : - (attesterRevokeCallMemSchema I).readWithPadding 192 32 = - UInt256.toByteArray (attesterRevokeUidWord I) := by - unfold attesterRevokeCallMemSchema - rw [writeCascade_read_preserved_len (attesterRevokeCallMemSelector I) - [(260, attesterRevokeSchemaWord I)] 192 32 (by - rw [attesterRevokeCallMemSelector_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeCallMemSelector - rw [writeCascade_read_preserved_len (attesterRevokeMemDataOffset I) - [(256, attesterRevokeSelectorWord)] 192 32 (by - rw [attesterRevokeMemDataOffset_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - exact attesterRevokeMemDataOffset_read192 I - -theorem attesterRevokeCallMemUid_read224 (I : ExecutionEnv) : - (attesterRevokeCallMemUid I).readWithPadding 224 32 = UInt256.toByteArray ⟨0⟩ := by - unfold attesterRevokeCallMemUid - rw [writeCascade_read_preserved_len (attesterRevokeCallMemSchema I) - [(292, attesterRevokeUidWord I)] 224 32 (by - rw [attesterRevokeCallMemSchema_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeCallMemSchema - rw [writeCascade_read_preserved_len (attesterRevokeCallMemSelector I) - [(260, attesterRevokeSchemaWord I)] 224 32 (by - rw [attesterRevokeCallMemSelector_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeCallMemSelector - rw [writeCascade_read_preserved_len (attesterRevokeMemDataOffset I) - [(256, attesterRevokeSelectorWord)] 224 32 (by - rw [attesterRevokeMemDataOffset_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - exact attesterRevokeMemDataOffset_read224 I - -theorem attesterRevokeSelectorWord_read0_4 : - (UInt256.toByteArray attesterRevokeSelectorWord).extract 0 4 = revokeSelector := by - native_decide - -theorem attesterRevokeCallMem_read256_4 (I : ExecutionEnv) : - (attesterRevokeCallMem I).readWithPadding 256 4 = revokeSelector := by - unfold attesterRevokeCallMem - rw [writeCascade_read_preserved_len (attesterRevokeCallMemUid I) - [(324, (⟨0⟩ : UInt256))] 256 4 (by - rw [attesterRevokeCallMemUid_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeCallMemUid - rw [writeCascade_read_preserved_len (attesterRevokeCallMemSchema I) - [(292, attesterRevokeUidWord I)] 256 4 (by - rw [attesterRevokeCallMemSchema_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeCallMemSchema - rw [writeCascade_read_preserved_len (attesterRevokeCallMemSelector I) - [(260, attesterRevokeSchemaWord I)] 256 4 (by - rw [attesterRevokeCallMemSelector_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeCallMemSelector - rw [writeCascade_read_window_of_head (attesterRevokeMemDataOffset I) - 256 0 4 attesterRevokeSelectorWord [] - (by rw [attesterRevokeMemDataOffset_size I]; norm_num [USize.size]) - (by rw [attesterRevokeMemDataOffset_size I]; norm_num [WindowDisjointFromWrites, USize.size]) - (by norm_num) (by norm_num) (by norm_num)] - exact attesterRevokeSelectorWord_read0_4 - -theorem attesterRevokeCallMem_read260 (I : ExecutionEnv) : - (attesterRevokeCallMem I).readWithPadding 260 32 = - UInt256.toByteArray (attesterRevokeSchemaWord I) := by - unfold attesterRevokeCallMem - rw [writeCascade_read_preserved_len (attesterRevokeCallMemUid I) - [(324, (⟨0⟩ : UInt256))] 260 32 (by - rw [attesterRevokeCallMemUid_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeCallMemUid - rw [writeCascade_read_preserved_len (attesterRevokeCallMemSchema I) - [(292, attesterRevokeUidWord I)] 260 32 (by - rw [attesterRevokeCallMemSchema_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeCallMemSchema - exact writeCascade_read_word_of_head_of_base (attesterRevokeCallMemSelector I) - (base := 288) (word := attesterRevokeSchemaWord I) - (rest := []) - (hbase := attesterRevokeCallMemSelector_size I) (hgap := by norm_num [USize.size]) - (hlater := by norm_num [WindowDisjointFromWrites, USize.size]) - -theorem attesterRevokeCallMem_read292 (I : ExecutionEnv) : - (attesterRevokeCallMem I).readWithPadding 292 32 = - UInt256.toByteArray (attesterRevokeUidWord I) := by - unfold attesterRevokeCallMem - rw [writeCascade_read_preserved_len (attesterRevokeCallMemUid I) - [(324, (⟨0⟩ : UInt256))] 292 32 (by - rw [attesterRevokeCallMemUid_size I] - norm_num [WindowDisjointFromWrites, USize.size]) (by norm_num) (by norm_num)] - unfold attesterRevokeCallMemUid - exact writeCascade_read_word_of_head_of_base (attesterRevokeCallMemSchema I) - (base := 292) (word := attesterRevokeUidWord I) - (rest := []) - (hbase := attesterRevokeCallMemSchema_size I) (hgap := by norm_num [USize.size]) - (hlater := by norm_num [WindowDisjointFromWrites, USize.size]) - -theorem attesterRevokeCallMem_read324 (I : ExecutionEnv) : - (attesterRevokeCallMem I).readWithPadding 324 32 = UInt256.toByteArray ⟨0⟩ := by - unfold attesterRevokeCallMem - exact writeCascade_read_word_of_head_of_base (attesterRevokeCallMemUid I) - (base := 324) (word := (⟨0⟩ : UInt256)) (rest := []) - (hbase := attesterRevokeCallMemUid_size I) (hgap := by norm_num [USize.size]) - (hlater := by norm_num [WindowDisjointFromWrites, USize.size]) - -theorem attesterRevokeCallMem_read256_100 (I : ExecutionEnv) : - (attesterRevokeCallMem I).readWithPadding 256 100 = - attesterRevokeExternalCalldata I := by - rw [byteArray_readWithPadding_split (attesterRevokeCallMem I) 256 4 96 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterRevokeCallMem_size I])] - rw [attesterRevokeCallMem_read256_4] - rw [byteArray_readWithPadding_split (attesterRevokeCallMem I) 260 32 64 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterRevokeCallMem_size I])] - rw [attesterRevokeCallMem_read260] - rw [byteArray_readWithPadding_split (attesterRevokeCallMem I) 292 32 32 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [attesterRevokeCallMem_size I])] - rw [attesterRevokeCallMem_read292, attesterRevokeCallMem_read324] - unfold attesterRevokeExternalCalldata - apply ByteArray.ext - simp [ByteArray.data_append, Array.append_assoc] - -theorem attesterDecodeABIValues_bytes32_bytes32_ok {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) - (hlen32 : ((bytes.drop 32).take 32).length = 32) : - decodeABIValues? [bytes32, bytes32] bytes 0 0 64 64 = - some ([.fixedBytes bytes32Width (bytes.take 32), - .fixedBytes bytes32Width ((bytes.drop 32).take 32)], 64) := by - have hge32 : 32 ≤ bytes.length - 32 := by - rw [List.length_take, List.length_drop] at hlen32 - omega - simp [decodeABIValues?, bytes32, bytes32Width, isDynamicABIType, - staticABIEncodedSize?, decodeABIValue?, readBytes?, zeroPadding?, hlen0] - rw [if_pos hge32] - simp [List.take_take] - -theorem attesterDecodeABIValues_bytes32_bytes32_none_short {bytes : List UInt8} - (hshort : bytes.length < 64) : - decodeABIValues? [bytes32, bytes32] bytes 0 0 64 64 = none := by - simp only [decodeABIValues?, bytes32, bytes32Width, isDynamicABIType, - Bool.false_eq_true, if_false, staticABIEncodedSize?, bind, Option.bind, Nat.zero_add] - by_cases h32 : bytes.length < 32 - · have htake0n : ¬ (bytes.take 32).length = 32 := by - rw [List.length_take] - omega - have hnot : ¬ 32 ≤ bytes.length := by omega - simp [decodeABIValue?, readBytes?, zeroPadding?, hnot, htake0n] - · have htake0 : (bytes.take 32).length = 32 := by - rw [List.length_take] - omega - have htake32n : ¬ ((bytes.drop 32).take 32).length = 32 := by - rw [List.length_take, List.length_drop] - omega - have hnot : ¬ 32 ≤ bytes.length - 32 := by - rw [List.length_take, List.length_drop] at htake32n - omega - simp [decodeABIValue?, readBytes?, zeroPadding?, htake0, hnot, htake32n] - -theorem attesterDecode_revoke_ok (v : AttesterImmutables) {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) : - decodeCalldataWithMode (config v).abiDecodeMode - ((revokeTransition v).params.map Param.name) - (transitionSignature (revokeTransition v)).paramTypes I.calldata = - some (attesterRevokeStore I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake4 : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have htake36 : ((I.calldata.toList.drop 36).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - show decodeCalldata ["schema", "uid"] [bytes32, bytes32] I.calldata = - some (attesterRevokeStore I) - unfold decodeCalldata - rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - rw [if_neg (by simp [bytes32, isDynamicABIType])] - rw [if_neg (by rintro ⟨_, hc⟩; rw [List.length_drop, htlen] at hc; omega)] - rw [if_neg (by simp [solcTotalSizeDynamicGuard])] - simp only [decodeCalldata.decodeArgs] - rw [show abiTupleHeadSize? [bytes32, bytes32] = some 64 by native_decide] - simp only [bind, Option.bind] - rw [attesterDecodeABIValues_bytes32_bytes32_ok (bytes := I.calldata.toList.drop 4) - (by simpa using htake4) - (by simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using htake36)] - rw [if_neg (by rw [List.length_drop, htlen]; omega : - ¬ (I.calldata.toList.drop 4).length < 64)] - simp [decodeCalldata.insertValues, attesterRevokeStore, attesterRevokeSchemaBytes, - attesterRevokeUidBytes] - -theorem attesterDecode_revoke_none_short (v : AttesterImmutables) {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 68) : - decodeCalldataWithMode (config v).abiDecodeMode - ((revokeTransition v).params.map Param.name) - (transitionSignature (revokeTransition v)).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - show decodeCalldata ["schema", "uid"] [bytes32, bytes32] I.calldata = none - unfold decodeCalldata - rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - rw [if_neg (by simp [bytes32, isDynamicABIType])] - rw [if_neg (by rintro ⟨_, hc⟩; rw [List.length_drop, htlen] at hc; omega)] - rw [if_neg (by simp [solcTotalSizeDynamicGuard])] - simp only [decodeCalldata.decodeArgs] - rw [show abiTupleHeadSize? [bytes32, bytes32] = some 64 by native_decide] - simp only [bind, Option.bind] - rw [attesterDecodeABIValues_bytes32_bytes32_none_short - (bytes := I.calldata.toList.drop 4) (by rw [List.length_drop, htlen]; omega)] - rw [if_pos (by rw [List.length_drop, htlen]; omega : - (I.calldata.toList.drop 4).length < 64)] - -theorem attesterDecode_revoke_none_huge (v : AttesterImmutables) {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - ((revokeTransition v).params.map Param.name) - (transitionSignature (revokeTransition v)).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - show decodeCalldata ["schema", "uid"] [bytes32, bytes32] I.calldata = none - unfold decodeCalldata - rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - rw [if_neg (by simp [bytes32, isDynamicABIType])] - rw [if_pos] - · exact ⟨rfl, by rw [List.length_drop, htlen]; omega⟩ - -theorem attesterRevokeSchemaBytes_eq_toBytesBE {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) : - attesterRevokeSchemaBytes I = EVM.Word.toBytesBE (attesterRevokeSchemaWord I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have hlen : (attesterRevokeSchemaBytes I).length = 32 := by - simp [attesterRevokeSchemaBytes, List.length_take, List.length_drop, htlen] - omega - have hword : ABI.bytesToWord (attesterRevokeSchemaBytes I) = - attesterRevokeSchemaWord I := by - simpa [attesterRevokeSchemaBytes, attesterRevokeSchemaWord, calldataWord, - show (⟨4⟩ : UInt256).toNat = 4 from by decide] - using decode_word_at_eq I.calldata 4 (by omega) (by norm_num) - rw [← hword] - exact (toBytesBE_bytesToWord_of_length hlen).symm - -theorem attesterRevokeUidBytes_eq_toBytesBE {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) : - attesterRevokeUidBytes I = EVM.Word.toBytesBE (attesterRevokeUidWord I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have hlen : (attesterRevokeUidBytes I).length = 32 := by - simp [attesterRevokeUidBytes, List.length_take, List.length_drop, htlen] - omega - have hword : ABI.bytesToWord (attesterRevokeUidBytes I) = - attesterRevokeUidWord I := by - simpa [attesterRevokeUidBytes, attesterRevokeUidWord, calldataWord, - show (⟨36⟩ : UInt256).toNat = 36 from by decide] - using decode_word_at_eq I.calldata 36 (by omega) (by norm_num) - rw [← hword] - exact (toBytesBE_bytesToWord_of_length hlen).symm - -theorem attesterEncodeRevoke_eq (v : AttesterImmutables) {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) : - (config v).externalABI.encode? "revoke" (attesterRevokeArgVals I) = - some (attesterRevokeExternalCalldata I) := by - have hschema := attesterRevokeSchemaBytes_eq_toBytesBE (I := I) hsz68 - have huid := attesterRevokeUidBytes_eq_toBytesBE (I := I) hsz68 - have hschemaLen : (EVM.Word.toBytesBE (attesterRevokeSchemaWord I)).length = 32 := by - simpa using word_toBytesBE_toByteArray_size (attesterRevokeSchemaWord I) - have huidLen : (EVM.Word.toBytesBE (attesterRevokeUidWord I)).length = 32 := by - simpa using word_toBytesBE_toByteArray_size (attesterRevokeUidWord I) - have hpow256 : 0 < EVM.twoPow 256 := by norm_num [EVM.twoPow] - have hzeroLen : (EVM.Word.ofNat 0).toBytesBE.length = 32 := by - simpa [list_toByteArray_size] using word_toBytesBE_toByteArray_size (EVM.Word.ofNat 0) - have hwordNat0 : EVM.Word.ofNat 0 = (⟨0⟩ : UInt256) := by native_decide - have hword0 : EVM.word 0 = (⟨0⟩ : UInt256) := rfl - simp [config, attesterExternalABI, ABI.encodeCallWithSelector?, ABI.encodeABIValues?, - ABI.encodeABIValuesFrom?, ABI.encodeABIValue?, ABI.encodeABIWord?, - ABI.encodeABIArrayElems?, ABI.encodeABIStaticArrayElems?, - ABI.encodeABIDynamicArrayElemsFrom?, ABI.abiTupleHeadSize?, - ABI.staticABIEncodedSize?, ABI.staticABIEncodedSizeList?, ABI.isDynamicABIType, - ABI.isDynamicABITypeList, attesterRevokeArgVals, attesterRevokeRequestValue, - attesterRevokeDataValue, attesterRevokeExternalCalldata, revocationRequestTy, - revocationRequestDataTy, bytes32, bytes32Width, uint256, uint256Int, revokeSelector, - selectorBytes, hschema, huid, hschemaLen, huidLen, hpow256, hzeroLen, ABI.natBytes, - ABI.padRightToWord, ABI.paddedSize, ABI.zeroBytes, - word_toBytesBE_toByteArray_eq_toByteArray, list_toByteArray_append] - apply ByteArray.ext - simp [ByteArray.data_append, ByteArray.append_assoc, byteArray_toList_toByteArray, - hwordNat0, hword0] - -theorem attesterEvalRevokeArgs (v : AttesterImmutables) (evm : EVM.State) - (I : ExecutionEnv) : - evalExprs? (config v) - { contract := contract v, locals := attesterRevokeStore I } evm - [revocationRequest (.var "schema") (.var "uid")] = - .ok (attesterRevokeArgVals I) := by - simp [attesterRevokeStore, attesterRevokeArgVals, attesterRevokeRequestValue, - attesterRevokeDataValue, revocationRequest, revocationData, evalExprs?, - evalExprList?, evalExpr?, EvalResult.bind, bind, pure, EvalResult.ofOption, - Std.HashMap.getElem_insert] - -theorem attesterDecode_revoke_return_ok (v : AttesterImmutables) (out : ByteArray) : - (config v).externalABI.decode? "revoke" out = some [] := by - simp [config, attesterExternalABI, decodeVoid?] - -theorem attesterRevokeBodySuccess (v : AttesterImmutables) - (evm evm' : EVM.State) (locals : Store) {argVals : List Value} - {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hguard : evalExpr? (config v) { contract := contract v, locals := locals } evm - (.binary .gt (.extCodeSize (easExpr v)) (.intLit 0)) = .ok (.bool true)) - (hargs : evalExprs? (config v) { contract := contract v, locals := locals } evm - [revocationRequest (.var "schema") (.var "uid")] = .ok argVals) - (hcall : typedCallViaEVM (config v) evm (EVM.address v.eas) "revoke" 0 argVals - (true, evm', out)) - (hdec : (config v).externalABI.decode? "revoke" out = some []) : - ExecTransitionBody (config v) (contract v) evm locals (revokeTransition v).body - (.returned - { contract := contract v, locals := locals.insert "_revoke" (collapseReturns []) } - evm' none) := by - exact ExecFuncBody.execBlockOK <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) <| - checkedExternalCallSuccess - (receiver := easExpr v) (retVar := "_revoke") (name := "revoke") - (sendVal := 0) (args := [revocationRequest (.var "schema") (.var "uid")]) - hguard - (attesterEvalEasExpr v { contract := contract v, locals := locals } evm) - hargs hcall hdec - -theorem attesterRevokeBodyCallFailure (v : AttesterImmutables) - (evm evm' : EVM.State) (locals : Store) {argVals : List Value} - {out : ByteArray} - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hguard : evalExpr? (config v) { contract := contract v, locals := locals } evm - (.binary .gt (.extCodeSize (easExpr v)) (.intLit 0)) = .ok (.bool true)) - (hargs : evalExprs? (config v) { contract := contract v, locals := locals } evm - [revocationRequest (.var "schema") (.var "uid")] = .ok argVals) - (hcall : typedCallViaEVM (config v) evm (EVM.address v.eas) "revoke" 0 argVals - (false, evm', out)) : - ExecTransitionBody (config v) (contract v) evm locals (revokeTransition v).body .reverted := by - exact ExecFuncBody.execBlockRevert <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) <| - checkedExternalCallFailure - (receiver := easExpr v) (retVar := "_revoke") (name := "revoke") - (sendVal := 0) (args := [revocationRequest (.var "schema") (.var "uid")]) - hguard - (attesterEvalEasExpr v { contract := contract v, locals := locals } evm) - hargs hcall - -theorem attesterRevokeBodyNoCode (v : AttesterImmutables) - (evm : EVM.State) (locals : Store) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hguard : evalExpr? (config v) { contract := contract v, locals := locals } evm - (.binary .gt (.extCodeSize (easExpr v)) (.intLit 0)) = .ok (.bool false)) : - ExecTransitionBody (config v) (contract v) evm locals (revokeTransition v).body .reverted := by - exact ExecFuncBody.execBlockRevert <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true hwv)) <| - checkedExternalCallNoCode - (receiver := easExpr v) (retVar := "_revoke") (name := "revoke") - (sendVal := 0) (args := [revocationRequest (.var "schema") (.var "uid")]) - hguard - -theorem attesterX_revokeWrapper {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = false) - (hrevoke : (attesterRevokeSelBytes == I.calldata.extract 0 4) = true) : - ∃ k C, RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨173⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C := by - have h0 := solcGuardPrologueRD (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (g := g) hcode - (by attester_decode) (by attester_decode) (by attester_decode) - (by attester_decode) (by attester_decode) (by attester_decode) - obtain ⟨_, _, h17⟩ := solcGuardCallvalueZero - (ctgt := (⟨15⟩ : UInt256)) (opC := .PUSH2) (wC := 2) - h0 hwv (by decide) (by attester_decode) - (by attester_decode) (by attester_decode) - (by attester_decode) (attesterGuardJumpdest v) - obtain ⟨k25, C25, h25raw⟩ := solcCalldataOk - (bodyPc := (⟨17⟩ : UInt256)) (selLoadTgt := attesterDispatchRevertPc) - (opR := .PUSH2) (wR := 2) - h17 hsz hsize (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) - have h25 : - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨25⟩ : UInt256) - [] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k25 C25 := by - simpa using h25raw - obtain ⟨k30, C30, h30raw⟩ := solcSelectorLoad h25 - (by attester_decode) (by attester_decode) (by attester_decode) (by attester_decode) (by simp) - have h30 : - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) attesterFirstArmPc - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k30 C30 := by - simpa [attesterFirstArmPc, solcSelectorWord] using h30raw - have heqMultiRevoke := attesterMultiRevokeEqZero I hsz hmultiRevoke - have heqMultiAttest := attesterMultiAttestEqZero I hsz hmultiAttest - have heqAttest := attesterAttestEqZero I hsz hattest - have heqRevoke := attesterRevokeEqNonzero I hsz hrevoke - exact ⟨_, _, h30 - |>.selectorArmNotTaken (selNat := (⟨0x13fde550⟩ : UInt256)) - (tgt := (⟨78⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqMultiRevoke (by simp) - |>.selectorArmNotTaken (selNat := (⟨0x54e1db35⟩ : UInt256)) - (tgt := (⟨99⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqMultiAttest (by simp) - |>.selectorArmNotTaken (selNat := (⟨0x72b9966d⟩ : UInt256)) - (tgt := (⟨140⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqAttest (by simp) - |>.selectorArmTaken (selNat := (⟨0xc2664610⟩ : UInt256)) - (tgt := (⟨173⟩ : UInt256)) (width := 2) (op := .PUSH2) - (by attester_decode) (by attester_decode) (by attester_decode) - (by decide) (by attester_decode) (by attester_decode) heqRevoke - (attesterRevokeWrapperJumpdest v) (by simp)⟩ - -theorem attesterX_revokeToDecoder {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨173⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2281⟩ : UInt256) - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨187⟩, ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd173⟩ := hreach - exact ⟨_, _, evm_run rd173 with [ - raw jumpdest (by attester_decode_at v, ⟨173⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push2 ⟨97⟩ (by attester_decode_at v, ⟨174⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw push2 ⟨187⟩ (by attester_decode_at v, ⟨177⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw calldatasize (by attester_decode_at v, ⟨180⟩, 0x36, .CALLDATASIZE) (by evm_ov), - raw push1 ⟨4⟩ (by attester_decode_at v, ⟨181⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push2 ⟨2281⟩ (by attester_decode_at v, ⟨183⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨186⟩, 0x56, .JUMP) - (attesterAttestDecoderJumpdest v) (by evm_ov)]⟩ - -theorem attesterX_revokeDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨1⟩) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨173⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2281⟩ := attesterX_revokeToDecoder (v := v) hreach - exact evm_run rd2281 with [ - raw jumpdest (by attester_decode_at v, ⟨2281⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2282⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2283⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2284⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2286⟩, 0x83, .DUP4) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2287⟩, 0x85, .DUP6) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2288⟩, 0x03, .SUB) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2289⟩, 0x12, .SLT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2290⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2298⟩ (by attester_decode_at v, ⟨2291⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2294⟩, 0x57, .JUMPI) (by rw [hslt]; decide) - (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2295⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2296⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2297⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_revokeDecodeShort {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hshort : I.calldata.size < 68) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = false) - (hrevoke : (attesterRevokeSelBytes == I.calldata.extract 0 4) = true) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨1⟩ := - solcDecodeLenCheckShort_4_64 hsz4 hshort hsize - exact attesterX_revokeDecodeRevert (v := v) hslt - (attesterX_revokeWrapper (g := g) v hcode hwv hsz4 hsize hmultiRevoke - hmultiAttest hattest hrevoke) - -theorem attesterX_revokeDecodeHuge {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = false) - (hrevoke : (attesterRevokeSelBytes == I.calldata.extract 0 4) = true) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨1⟩ := - solcDecodeLenCheckHuge_4_64 hbig hsize - exact attesterX_revokeDecodeRevert (v := v) hslt - (attesterX_revokeWrapper (g := g) v hcode hwv hsz4 hsize hmultiRevoke - hmultiAttest hattest hrevoke) - -theorem attesterX_revokeDecoded {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨173⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨1863⟩ : UInt256) - [attesterRevokeUidWord I, attesterRevokeSchemaWord I, ⟨97⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = - ⟨0⟩ := - solcDecodeLenCheckOk_4_64 hsz68 hsmall hsize - obtain ⟨_, _, rd2281⟩ := attesterX_revokeToDecoder (v := v) hreach - have rd187 := evm_run rd2281 with [ - raw jumpdest (by attester_decode_at v, ⟨2281⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2282⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2283⟩, 0x80, .DUP1) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨2284⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨2286⟩, 0x83, .DUP4) (by evm_ov), - raw dup6 (by attester_decode_at v, ⟨2287⟩, 0x85, .DUP6) (by evm_ov), - raw sub (by attester_decode_at v, ⟨2288⟩, 0x03, .SUB) (by evm_ov), - raw slt (by attester_decode_at v, ⟨2289⟩, 0x12, .SLT) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2290⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2298⟩ (by attester_decode_at v, ⟨2291⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jumpiT (by attester_decode_at v, ⟨2294⟩, 0x57, .JUMPI) - (by rw [hslt]; decide) (attesterAttestDecodeOkJumpdest v) (by evm_ov), - raw jumpdest (by attester_decode_at v, ⟨2298⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2299⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2300⟩, 0x50, .POP) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2301⟩, 0x80, .DUP1) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2302⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨2303⟩, 0x92, .SWAP3) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨2304⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨2306⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2307⟩, 0x91, .SWAP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨2308⟩, 0x01, .ADD) (by evm_ov), - raw calldataload (by attester_decode_at v, ⟨2309⟩, 0x35, .CALLDATALOAD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨2310⟩, 0x91, .SWAP2) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2311⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨2312⟩, 0x56, .JUMP) - (attesterRevokeDecodedJumpdest v) (by evm_ov)] - have rd1863 := evm_run rd187 with [ - raw jumpdest (by attester_decode_at v, ⟨187⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push2 ⟨1863⟩ (by attester_decode_at v, ⟨188⟩, 0x61, (.Push .PUSH2)) (by evm_ov), - raw jump (by attester_decode_at v, ⟨191⟩, 0x56, .JUMP) - (attesterRevokeBodyJumpdest v) (by evm_ov)] - exact ⟨_, _, by - simpa [attesterRevokeUidWord, attesterRevokeSchemaWord, calldataWord, - show (⟨4⟩ : UInt256).toNat = 4 from by decide, - show (⟨36⟩ : UInt256).toNat = 36 from by decide] using rd1863⟩ - -set_option maxHeartbeats 1000000 in -set_option maxRecDepth 10000 in -theorem attesterX_revokeToExtcodesize {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨173⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) : - ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2001⟩ : UInt256) - [attesterRevokeTargetWord v, attesterRevokeTargetWord v, ⟨0⟩, ⟨256⟩, ⟨100⟩, - ⟨256⟩, ⟨0⟩, ⟨356⟩, ⟨0x46926267⟩, attesterRevokeTargetWord v, - attesterRevokeUidWord I, attesterRevokeSchemaWord I, ⟨97⟩, solcSelectorWord I] - (attesterRevokeCallMem I) (UInt256.ofNat 12) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd1863⟩ := attesterX_revokeDecoded (v := v) hsz68 hsize hsmall hreach - have rd1938 := evm_run rd1863 with [ - raw jumpdest (by attester_decode_at v, ⟨1863⟩, 0x5b, .JUMPDEST) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1864⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1866⟩, 0x80, .DUP1) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) - (by attester_decode_at v, ⟨1867⟩, 0x51, .MLOAD) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1868⟩, 0x80, .DUP1) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1869⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨1870⟩, 0x01, .ADD) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1871⟩, 0x82, .DUP3) (by evm_ov), - raw mstore 0 attesterRevokeMem192 (UInt256.ofNat 3) - (by attester_decode_at v, ⟨1872⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1873⟩, 0x83, .DUP4) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1874⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 6 (attesterRevokeMemSchema I) (UInt256.ofNat 5) - (by attester_decode_at v, ⟨1875⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1876⟩, 0x81, .DUP2) (by evm_ov), - raw mload 0 ⟨192⟩ (UInt256.ofNat 5) - (by attester_decode_at v, ⟨1877⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterRevokeMemSchema_size I]; decide) (by decide) - (attesterRevokeMemSchema_read64 I)) - (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1878⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1879⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨1880⟩, 0x01, .ADD) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1881⟩, 0x83, .DUP4) (by evm_ov), - raw mstore 0 (attesterRevokeMem256 I) (UInt256.ofNat 5) - (by attester_decode_at v, ⟨1882⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1883⟩, 0x83, .DUP4) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1884⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 6 (attesterRevokeMemUid I) (UInt256.ofNat 7) - (by attester_decode_at v, ⟨1885⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨1886⟩, 0x5f, .PUSH0) (by evm_ov), - raw push1 ⟨32⟩ (by attester_decode_at v, ⟨1887⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1889⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1890⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨1891⟩, 0x01, .ADD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨1892⟩, 0x91, .SWAP2) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1893⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨1894⟩, 0x91, .SWAP2) (by evm_ov), - raw mstore 3 (attesterRevokeMemValue I) (UInt256.ofNat 8) - (by attester_decode_at v, ⟨1895⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1896⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1897⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨1898⟩, 0x01, .ADD) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨1899⟩, 0x91, .SWAP2) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1900⟩, 0x82, .DUP3) (by evm_ov), - raw mstore 0 (attesterRevokeMemDataOffset I) (UInt256.ofNat 8) - (by attester_decode_at v, ⟨1901⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw swap3 (by attester_decode_at v, ⟨1902⟩, 0x92, .SWAP3) (by evm_ov), - raw mload 0 ⟨256⟩ (UInt256.ofNat 8) - (by attester_decode_at v, ⟨1903⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterRevokeMemDataOffset_size I]; decide) (by decide) - (attesterRevokeMemDataOffset_read64 I)) - (by decide) (by evm_ov), - raw push4 ⟨0x46926267⟩ (by attester_decode_at v, ⟨1904⟩, 0x63, (.Push .PUSH4)) - (by evm_ov), - raw push1 ⟨224⟩ (by attester_decode_at v, ⟨1909⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨1911⟩, 0x1b, .SHL) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1912⟩, 0x81, .DUP2) (by evm_ov), - raw mstore 3 (attesterRevokeCallMemSelector I) (UInt256.ofNat 9) - (by attester_decode_at v, ⟨1913⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨1914⟩, 0x91, .SWAP2) (by evm_ov), - raw mload 0 (attesterRevokeSchemaWord I) (UInt256.ofNat 9) - (by attester_decode_at v, ⟨1915⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterRevokeCallMemSelector_size I]; decide) (by decide) - (attesterRevokeCallMemSelector_read128 I)) - (by decide) (by evm_ov), - raw push1 ⟨4⟩ (by attester_decode_at v, ⟨1916⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1918⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨1919⟩, 0x01, .ADD) (by evm_ov), - raw mstore 3 (attesterRevokeCallMemSchema I) (UInt256.ofNat 10) - (by attester_decode_at v, ⟨1920⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw mload 0 ⟨192⟩ (UInt256.ofNat 10) - (by attester_decode_at v, ⟨1921⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterRevokeCallMemSchema_size I]; decide) (by decide) - (attesterRevokeCallMemSchema_read160 I)) - (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1922⟩, 0x80, .DUP1) (by evm_ov), - raw mload 0 (attesterRevokeUidWord I) (UInt256.ofNat 10) - (by attester_decode_at v, ⟨1923⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterRevokeCallMemSchema_size I]; decide) (by decide) - (attesterRevokeCallMemSchema_read192 I)) - (by decide) (by evm_ov), - raw push1 ⟨36⟩ (by attester_decode_at v, ⟨1924⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1926⟩, 0x83, .DUP4) (by evm_ov), - raw add (by attester_decode_at v, ⟨1927⟩, 0x01, .ADD) (by evm_ov), - raw mstore 3 (attesterRevokeCallMemUid I) (UInt256.ofNat 11) - (by attester_decode_at v, ⟨1928⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1929⟩, 0x90, .SWAP1) (by evm_ov), - raw swap2 (by attester_decode_at v, ⟨1930⟩, 0x91, .SWAP2) (by evm_ov), - raw add (by attester_decode_at v, ⟨1931⟩, 0x01, .ADD) (by evm_ov), - raw mload 0 ⟨0⟩ (UInt256.ofNat 11) - (by attester_decode_at v, ⟨1932⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterRevokeCallMemUid_size I]; decide) (by decide) - (attesterRevokeCallMemUid_read224 I)) - (by decide) (by evm_ov), - raw push1 ⟨68⟩ (by attester_decode_at v, ⟨1933⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw dup3 (by attester_decode_at v, ⟨1935⟩, 0x82, .DUP3) (by evm_ov), - raw add (by attester_decode_at v, ⟨1936⟩, 0x01, .ADD) (by evm_ov), - raw mstore 3 (attesterRevokeCallMem I) (UInt256.ofNat 12) - (by attester_decode_at v, ⟨1937⟩, 0x52, .MSTORE) mem_cost - (by rfl) (by decide) (by evm_ov)] - have rd1971 := rd1938.pushConst (attesterRevokeEasWord v) (width := 32) (op := .PUSH32) - (by decide) (attesterDecodeEasWord1938 v) (by evm_ov) - have rd2001 := evm_run rd1971 with [ - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨1971⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨1⟩ (by attester_decode_at v, ⟨1973⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw push1 ⟨160⟩ (by attester_decode_at v, ⟨1975⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw shl (by attester_decode_at v, ⟨1977⟩, 0x1b, .SHL) (by evm_ov), - raw sub (by attester_decode_at v, ⟨1978⟩, 0x03, .SUB) (by evm_ov), - raw and (by attester_decode_at v, ⟨1979⟩, 0x16, .AND) (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1980⟩, 0x90, .SWAP1) (by evm_ov), - raw push4 ⟨0x46926267⟩ (by attester_decode_at v, ⟨1981⟩, 0x63, (.Push .PUSH4)) - (by evm_ov), - raw swap1 (by attester_decode_at v, ⟨1986⟩, 0x90, .SWAP1) (by evm_ov), - raw push1 ⟨100⟩ (by attester_decode_at v, ⟨1987⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw add (by attester_decode_at v, ⟨1989⟩, 0x01, .ADD) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨1990⟩, 0x5f, .PUSH0) (by evm_ov), - raw push1 ⟨64⟩ (by attester_decode_at v, ⟨1991⟩, 0x60, (.Push .PUSH1)) (by evm_ov), - raw mload 0 ⟨256⟩ (UInt256.ofNat 12) - (by attester_decode_at v, ⟨1993⟩, 0x51, .MLOAD) - mem_cost - (mloadWordValue_of_readWithPadding - (by rw [attesterRevokeCallMem_size I]; decide) (by decide) - (attesterRevokeCallMem_read64 I)) - (by decide) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨1994⟩, 0x80, .DUP1) (by evm_ov), - raw dup4 (by attester_decode_at v, ⟨1995⟩, 0x83, .DUP4) (by evm_ov), - raw sub (by attester_decode_at v, ⟨1996⟩, 0x03, .SUB) (by evm_ov), - raw dup2 (by attester_decode_at v, ⟨1997⟩, 0x81, .DUP2) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨1998⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup8 (by attester_decode_at v, ⟨1999⟩, 0x87, .DUP8) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2000⟩, 0x80, .DUP1) (by evm_ov)] - exact ⟨_, _, by - simpa [attesterRevokeTargetWord, attesterRevokeEasWord, - show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by decide, - show UInt256.land solcAddrMask (EVM.Word.ofNat v.eas.toNat) = - UInt256.land (EVM.Word.ofNat v.eas.toNat) solcAddrMask by - exact u256_land_comm solcAddrMask (EVM.Word.ofNat v.eas.toNat), - show UInt256.sub (⟨356⟩ : UInt256) ⟨256⟩ = (⟨100⟩ : UInt256) by decide] - using rd2001⟩ - -private theorem attester_extCodeSizeWord_ne_zero_lookup_code_pos - {σ : AccountMap} {target : UInt256} {addr : AccountAddress} - (haddr : addr = AccountAddress.ofUInt256 target) - (hne : Reasoning.Theory.extCodeSizeWord σ target ≠ ⟨0⟩) : - 0 < (UInt256.ofNat - ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat := by - subst addr - unfold Reasoning.Theory.extCodeSizeWord at hne - cases hacc : σ.find? (AccountAddress.ofUInt256 target) with - | none => - exfalso - exact hne (by simp [hacc, Option.option]) - | some acc => - have hwordNe : UInt256.ofNat acc.code.size ≠ (⟨0⟩ : UInt256) := by - intro hzero - exact hne (by simpa [hacc] using hzero) - have htoNatNe : (UInt256.ofNat acc.code.size).toNat ≠ 0 := by - intro hzeroNat - apply hwordNe - cases hword : UInt256.ofNat acc.code.size with - | mk val => - cases val using Fin.cases - · rfl - · simp [UInt256.toNat, hword] at hzeroNat - simpa [hacc] using Nat.pos_of_ne_zero htoNatNe - -private theorem attester_extCodeSizeWord_zero_lookup_code_zero - {σ : AccountMap} {target : UInt256} {addr : AccountAddress} - (haddr : addr = AccountAddress.ofUInt256 target) - (hzero : Reasoning.Theory.extCodeSizeWord σ target = ⟨0⟩) : - (UInt256.ofNat - ((σ.find? addr).option 0 (fun acc => acc.code.size))).toNat = 0 := by - subst addr - unfold Reasoning.Theory.extCodeSizeWord at hzero - cases hacc : σ.find? (AccountAddress.ofUInt256 target) with - | none => - simpa [hacc, Option.option] using - (show (UInt256.ofNat 0).toNat = 0 from by native_decide) - | some acc => - have hword := congrArg UInt256.toNat hzero - simpa [hacc] using hword - -theorem attesterEvalExtCodeGuard_true (v : AttesterImmutables) - {evm : EVM.State} {locals : Store} {receiver : Expr} {target : AccountAddress} - (hreceiver : - evalExpr? (config v) { contract := contract v, locals := locals } evm receiver = - .ok (.address target)) - (hcode : - 0 < (UInt256.ofNat - ((evm.lookupAccount target).option 0 (fun acc => acc.code.size))).toNat) : - evalExpr? (config v) { contract := contract v, locals := locals } evm - (.binary .gt (.extCodeSize receiver) (.intLit 0)) = .ok (.bool true) := by - simp [evalExpr?, EvalResult.bind, bind, hreceiver, evalBinaryOp?, EVM.Word.ofNat, hcode] - -theorem attesterEvalExtCodeGuard_false (v : AttesterImmutables) - {evm : EVM.State} {locals : Store} {receiver : Expr} {target : AccountAddress} - (hreceiver : - evalExpr? (config v) { contract := contract v, locals := locals } evm receiver = - .ok (.address target)) - (hcode : - (UInt256.ofNat - ((evm.lookupAccount target).option 0 (fun acc => acc.code.size))).toNat = 0) : - evalExpr? (config v) { contract := contract v, locals := locals } evm - (.binary .gt (.extCodeSize receiver) (.intLit 0)) = .ok (.bool false) := by - simp [evalExpr?, EvalResult.bind, bind, hreceiver, evalBinaryOp?, EVM.Word.ofNat, hcode] - -theorem attesterRevokeCodeSize_ne_accountMapEquiv (v : AttesterImmutables) - {σ τ : AccountMap} - (hAccounts : accountMapEquiv σ τ) - (hne : - Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) ≠ ⟨0⟩) : - Reasoning.Theory.extCodeSizeWord τ (attesterRevokeTargetWord v) ≠ ⟨0⟩ := by - intro hzero - apply hne - have hsame := - Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts - (attesterRevokeTargetWord v) - rw [hsame] - exact hzero - -theorem attesterRevokeCodeSize_zero_accountMapEquiv (v : AttesterImmutables) - {σ τ : AccountMap} - (hAccounts : accountMapEquiv σ τ) - (hzero : - Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) = ⟨0⟩) : - Reasoning.Theory.extCodeSizeWord τ (attesterRevokeTargetWord v) = ⟨0⟩ := by - have hsame := - Reasoning.Theory.extCodeSizeWord_accountMapEquiv hAccounts - (attesterRevokeTargetWord v) - rw [← hsame] - exact hzero - -theorem attesterRevokeEasCode_pos_of_codeSize_ne - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hne : - Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) ≠ ⟨0⟩) : - 0 < (UInt256.ofNat - (((initState cA gh bl σ σ₀ g A I).lookupAccount (EVM.address v.eas)).option 0 - (fun acc => acc.code.size))).toNat := by - simpa [initState, State.lookupAccount] using - attester_extCodeSizeWord_ne_zero_lookup_code_pos - (σ := σ) (target := attesterRevokeTargetWord v) (addr := EVM.address v.eas) - (attesterRevokeTarget_eq v) hne - -theorem attesterRevokeEasCode_zero_of_codeSize_zero - {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hzero : - Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) = ⟨0⟩) : - (UInt256.ofNat - (((initState cA gh bl σ σ₀ g A I).lookupAccount (EVM.address v.eas)).option 0 - (fun acc => acc.code.size))).toNat = 0 := by - simpa [initState, State.lookupAccount] using - attester_extCodeSizeWord_zero_lookup_code_zero - (σ := σ) (target := attesterRevokeTargetWord v) (addr := EVM.address v.eas) - (attesterRevokeTarget_eq v) hzero - -theorem attesterX_revokeNoCode {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsz68 : 68 ≤ I.calldata.size) (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = false) - (hrevoke : (attesterRevokeSelBytes == I.calldata.extract 0 4) = true) - (hcodeSize : - Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) = ⟨0⟩) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2001⟩ := - attesterX_revokeToExtcodesize (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) v hsz68 hsize hsmall - (attesterX_revokeWrapper (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) v hcode hwv hsz4 - hsize hmultiRevoke hmultiAttest hattest hrevoke) - obtain ⟨k2002, C2002, rd2002raw⟩ := RD.extcodesize rd2001 - (by attester_decode_at v, ⟨2001⟩, 0x3b, .EXTCODESIZE) (by simp) - have rd2002 : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2002⟩ : UInt256) - [Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v), - attesterRevokeTargetWord v, ⟨0⟩, ⟨256⟩, ⟨100⟩, ⟨256⟩, ⟨0⟩, - ⟨356⟩, ⟨0x46926267⟩, attesterRevokeTargetWord v, - attesterRevokeUidWord I, attesterRevokeSchemaWord I, ⟨97⟩, solcSelectorWord I] - (attesterRevokeCallMem I) (UInt256.ofNat 12) ByteArray.empty (cA, σ) - k2002 C2002 := by - simpa using rd2002raw - exact evm_run rd2002 with [ - raw iszero (by attester_decode_at v, ⟨2002⟩, 0x15, .ISZERO) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2003⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2004⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2012⟩ (by attester_decode_at v, ⟨2005⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2008⟩, 0x57, .JUMPI) - (by rw [hcodeSize]; decide) (by evm_ov), - raw push0 (by attester_decode_at v, ⟨2009⟩, 0x5f, .PUSH0) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2010⟩, 0x80, .DUP1) (by evm_ov), - raw rev 0 (by attester_decode_at v, ⟨2011⟩, 0xfd, .REVERT) - (fun s _ hstks => memExpRevert0 s hstks) (by evm_ov)] - -theorem attesterX_revokePostCall {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hreach : ∃ k C, RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨173⟩ : UInt256) - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) - (hcodeSize : - Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) ≠ ⟨0⟩) - (hperm : I.perm = true) (hdepth : I.depth.val < 1024) : - ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) (z : Bool) - (o : ByteArray) (A' : Substate) (k' C' : ℕ), - RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨2016⟩ : UInt256) - ((if z then ⟨1⟩ else ⟨0⟩) :: - ⟨356⟩ :: ⟨0x46926267⟩ :: attesterRevokeTargetWord v :: - attesterRevokeUidWord I :: attesterRevokeSchemaWord I :: ⟨97⟩ :: - solcSelectorWord I :: []) - (o.write 0 (attesterRevokeCallMem I) 256 - (min (⟨0⟩ : UInt256) (UInt256.ofNat o.size)).toNat) - ⟨12⟩ o (cA', σ') k' C' - ∧ typedCallViaEVM (config v) (initState cA gh bl σ σ₀ g A I) - (EVM.address v.eas) "revoke" 0 (attesterRevokeArgVals I) - (z, { initState cA gh bl σ σ₀ g A I with - accountMap := σ', substate := A', createdAccounts := cA' }, o) true - ∧ o.size < UInt256.size := by - obtain ⟨_, _, rd2001⟩ := - attesterX_revokeToExtcodesize (v := v) hsz68 hsize hsmall hreach - obtain ⟨_, _, _, rd2015⟩ := - RD.solcExtcodesizeGuardOkGas (pc := ⟨2001⟩) (okPc := ⟨2012⟩) - rd2001 hcodeSize - (by attester_decode_at v, ⟨2001⟩, 0x3b, .EXTCODESIZE) - (by attester_decode_at v, ⟨2002⟩, 0x15, .ISZERO) - (by attester_decode_at v, ⟨2003⟩, 0x80, .DUP1) - (by attester_decode_at v, ⟨2004⟩, 0x15, .ISZERO) - (by attester_decode_at v, ⟨2005⟩, 0x61, (.Push .PUSH2)) - (by attester_decode_at v, ⟨2008⟩, 0x57, .JUMPI) - (attesterRevokeExtcodesizeOkJumpdest v) - (by attester_decode_at v, ⟨2012⟩, 0x5b, .JUMPDEST) - (by attester_decode_at v, ⟨2013⟩, 0x50, .POP) - (by attester_decode_at v, ⟨2014⟩, 0x5a, .GAS) - (by norm_num) - obtain ⟨cA', σ', z, o, A_in, callGas, k', C', hTheta, rd2016raw, hosz⟩ := - rd2015.call (by attester_decode_at v, ⟨2015⟩, 0xf1, .CALL) hdepth - (by norm_num) - obtain ⟨g'', A', hΘ⟩ := hTheta - refine ⟨cA', σ', z, o, A', k', C', ?_, ?_, hosz⟩ - · have haw : - UInt256.ofNat (MachineState.M (MachineState.M (UInt256.ofNat 12).toNat - (⟨256⟩ : UInt256).toNat (⟨100⟩ : UInt256).toNat) - (⟨256⟩ : UInt256).toNat (⟨0⟩ : UInt256).toNat) = (⟨12⟩ : UInt256) := by - decide - have rd2016 : RD (patchedRuntime v) I g - (initState cA gh bl σ σ₀ g A I) (⟨2015⟩ + ⟨1⟩) - ((if z then ⟨1⟩ else ⟨0⟩) :: - ⟨356⟩ :: ⟨0x46926267⟩ :: attesterRevokeTargetWord v :: - attesterRevokeUidWord I :: attesterRevokeSchemaWord I :: ⟨97⟩ :: - solcSelectorWord I :: []) - (o.write 0 (attesterRevokeCallMem I) 256 - (min (⟨0⟩ : UInt256) (UInt256.ofNat o.size)).toNat) - ⟨12⟩ o (cA', σ') k' C' := - haw ▸ rd2016raw - simpa using rd2016 - · refine callCoincides (A_in := A_in) (g'' := g'') (callGas := callGas) - (callPerm := true) (targetWord := attesterRevokeTargetWord v) - (mem := attesterRevokeCallMem I) (inOff := ⟨256⟩) (inSize := ⟨100⟩) - (hdepth := fun h => absurd hdepth (by rw [show I.depth = (1024 : Fin 1025) from h]; decide)) - (htgt := attesterRevokeTarget_eq v) (hcd := ?_) (hΘ := ?_) - · rw [show (⟨256⟩ : UInt256).toNat = 256 by decide, - show (⟨100⟩ : UInt256).toNat = 100 by decide, - attesterRevokeCallMem_read256_100] - exact attesterEncodeRevoke_eq v hsz68 - · simpa [initState, hperm] using hΘ - -theorem attesterX_revokePostRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {k C : ℕ} {rest : List UInt256} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨2016⟩ : UInt256) - (⟨0⟩ :: rest) mem aw rdata acc k C) - (hrdataSize : rdata.size < UInt256.size) - (hov : rest.length + 5 ≤ 1024) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - have rd2023 : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2023⟩ : UInt256) (UInt256.isZero ⟨0⟩ :: rest) mem aw rdata acc _ _ := - evm_run rd with [ - raw iszero (by attester_decode_at v, ⟨2016⟩, 0x15, .ISZERO) (by evm_ov), - raw dup1 (by attester_decode_at v, ⟨2017⟩, 0x80, .DUP1) (by evm_ov), - raw iszero (by attester_decode_at v, ⟨2018⟩, 0x15, .ISZERO) (by evm_ov), - raw push2 ⟨2030⟩ (by attester_decode_at v, ⟨2019⟩, 0x61, (.Push .PUSH2)) - (by evm_ov), - raw jumpiNT (by attester_decode_at v, ⟨2022⟩, 0x57, .JUMPI) (by decide) - (by evm_ov)] - have rd2024 := RD.returndatasize rd2023 - (by attester_decode_at v, ⟨2023⟩, 0x3d, .RETURNDATASIZE) - (by simp only [List.length_cons]; omega) - have rd2025 := RD.push0 rd2024 - (by attester_decode_at v, ⟨2024⟩, 0x5f, .PUSH0) - (by simp only [List.length_cons]; omega) - have rd2026 := RD.dup1 rd2025 - (by attester_decode_at v, ⟨2025⟩, 0x80, .DUP1) - (by simp only [List.length_cons]; omega) - have rd2027 : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2027⟩ : UInt256) (UInt256.isZero ⟨0⟩ :: rest) - (rdata.write 0 mem 0 (UInt256.ofNat rdata.size).toNat) - (UInt256.ofNat (MachineState.M aw.toNat 0 (UInt256.ofNat rdata.size).toNat)) - rdata acc _ _ := - RD.returndatacopy - (Cₘ (UInt256.ofNat (MachineState.M aw.toNat 0 (UInt256.ofNat rdata.size).toNat)) - Cₘ aw) - (rdata.write 0 mem 0 (UInt256.ofNat rdata.size).toNat) - (UInt256.ofNat (MachineState.M aw.toNat 0 (UInt256.ofNat rdata.size).toNat)) - rd2026 - (by attester_decode_at v, ⟨2026⟩, 0x3e, .RETURNDATACOPY) - (by - rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, Nat.zero_add] - rw [show (UInt256.ofNat rdata.size).toNat = rdata.size from - ulit_toNat' rdata.size hrdataSize]) - (by - intro s haws hstks - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', hstks, haws, - List.getElem!_cons_zero, List.getElem!_cons_succ, - show (⟨0⟩ : UInt256).toNat = 0 from rfl]) - rfl rfl (by simp only [List.length_cons]; omega) - have rd2028 := RD.returndatasize rd2027 - (by attester_decode_at v, ⟨2027⟩, 0x3d, .RETURNDATASIZE) - (by simp only [List.length_cons]; omega) - have rd2029 := RD.push0 rd2028 - (by attester_decode_at v, ⟨2028⟩, 0x5f, .PUSH0) - (by simp only [List.length_cons]; omega) - exact RD.rev _ rd2029 - (by attester_decode_at v, ⟨2029⟩, 0xfd, .REVERT) - (fun s haws hstks => by rw [memExpRevertZeroOff s hstks, haws]) - (by simp only [List.length_cons]; omega) - -theorem attesterX_revokeSuccessStop {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {mem o : ByteArray} {k C : ℕ} - (rd : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) (⟨2016⟩ : UInt256) - [⟨1⟩, ⟨356⟩, ⟨0x46926267⟩, attesterRevokeTargetWord v, - attesterRevokeUidWord I, attesterRevokeSchemaWord I, ⟨97⟩, solcSelectorWord I] - mem ⟨12⟩ o acc k C) : - RDret (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) acc ByteArray.empty := by - obtain ⟨_, _, rd2032⟩ := - RD.solcCallSuccessGuardOk (pc := ⟨2016⟩) (okPc := ⟨2030⟩) rd - (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) - (by attester_decode_at v, ⟨2016⟩, 0x15, .ISZERO) - (by attester_decode_at v, ⟨2017⟩, 0x80, .DUP1) - (by attester_decode_at v, ⟨2018⟩, 0x15, .ISZERO) - (by attester_decode_at v, ⟨2019⟩, 0x61, (.Push .PUSH2)) - (by attester_decode_at v, ⟨2022⟩, 0x57, .JUMPI) - (attesterRevokeCallOkJumpdest v) - (by attester_decode_at v, ⟨2030⟩, 0x5b, .JUMPDEST) - (by attester_decode_at v, ⟨2031⟩, 0x50, .POP) - (by simp) - have rd97 := evm_run rd2032 with [ - raw pop (by attester_decode_at v, ⟨2032⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2033⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2034⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2035⟩, 0x50, .POP) (by evm_ov), - raw pop (by attester_decode_at v, ⟨2036⟩, 0x50, .POP) (by evm_ov), - raw jump (by attester_decode_at v, ⟨2037⟩, 0x56, .JUMP) - (attesterNoReturnDoneJumpdest v) (by evm_ov)] - have rd98 := evm_run rd97 with [ - raw jumpdest (by attester_decode_at v, ⟨97⟩, 0x5b, .JUMPDEST) (by evm_ov)] - exact RD.stop rd98 (by attester_decode_at v, ⟨98⟩, 0x00, .STOP) (by evm_ov) - -theorem attesterX_revokeCallDepthLimit {cA gh bl σ σ₀ A I} {g : Sat256} - (v : AttesterImmutables) - (hcode : I.code = patchedRuntime v) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsz68 : 68 ≤ I.calldata.size) (hsmall : I.calldata.size < 2 ^ 255 + 4) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = false) - (hrevoke : (attesterRevokeSelBytes == I.calldata.extract 0 4) = true) - (hcodeSize : - Reasoning.Theory.extCodeSizeWord σ (attesterRevokeTargetWord v) ≠ ⟨0⟩) - (hdepth : I.depth = 1024) : - RDrev (patchedRuntime v) g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, rd2001⟩ := - attesterX_revokeToExtcodesize (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) v hsz68 hsize hsmall - (attesterX_revokeWrapper (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) v hcode hwv hsz4 - hsize hmultiRevoke hmultiAttest hattest hrevoke) - obtain ⟨_, _, _, rd2015⟩ := - RD.solcExtcodesizeGuardOkGas (pc := ⟨2001⟩) (okPc := ⟨2012⟩) - rd2001 hcodeSize - (by attester_decode_at v, ⟨2001⟩, 0x3b, .EXTCODESIZE) - (by attester_decode_at v, ⟨2002⟩, 0x15, .ISZERO) - (by attester_decode_at v, ⟨2003⟩, 0x80, .DUP1) - (by attester_decode_at v, ⟨2004⟩, 0x15, .ISZERO) - (by attester_decode_at v, ⟨2005⟩, 0x61, (.Push .PUSH2)) - (by attester_decode_at v, ⟨2008⟩, 0x57, .JUMPI) - (attesterRevokeExtcodesizeOkJumpdest v) - (by attester_decode_at v, ⟨2012⟩, 0x5b, .JUMPDEST) - (by attester_decode_at v, ⟨2013⟩, 0x50, .POP) - (by attester_decode_at v, ⟨2014⟩, 0x5a, .GAS) - (by norm_num) - obtain ⟨k', C', rd2016raw⟩ := - rd2015.callDepthLimit (by attester_decode_at v, ⟨2015⟩, 0xf1, .CALL) hdepth - (by norm_num) - have haw : - UInt256.ofNat (MachineState.M (MachineState.M (UInt256.ofNat 12).toNat - (⟨256⟩ : UInt256).toNat (⟨100⟩ : UInt256).toNat) - (⟨256⟩ : UInt256).toNat (⟨0⟩ : UInt256).toNat) = (⟨12⟩ : UInt256) := by - decide - have rd2016 : RD (patchedRuntime v) I g (initState cA gh bl σ σ₀ g A I) - (⟨2016⟩ : UInt256) - [⟨0⟩, ⟨356⟩, ⟨0x46926267⟩, attesterRevokeTargetWord v, - attesterRevokeUidWord I, attesterRevokeSchemaWord I, ⟨97⟩, solcSelectorWord I] - (ByteArray.empty.write 0 (attesterRevokeCallMem I) 256 - (min (⟨0⟩ : UInt256) (UInt256.ofNat ByteArray.empty.size)).toNat) - ⟨12⟩ ByteArray.empty (cA, σ) k' C' := by - have rd := haw ▸ rd2016raw - simpa using rd - exact attesterX_revokePostRevert (v := v) rd2016 (by native_decide) (by simp) - -theorem attesterRevokeBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (v : AttesterImmutables) {code : ByteArray} - (hpatch : patchRuntime attesterBytecode (patches v) = some code) - (hcode : I.code = code) - (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) - (hwv : I.weiValue = ⟨0⟩) - (hmultiRevoke : (attesterMultiRevokeSelBytes == I.calldata.extract 0 4) = false) - (hmultiAttest : (attesterMultiAttestSelBytes == I.calldata.extract 0 4) = false) - (hattest : (attesterAttestSelBytes == I.calldata.extract 0 4) = false) - (hrevoke : (attesterRevokeSelBytes == I.calldata.extract 0 4) = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hpatched : code = patchedRuntime v := code_eq_patchedRuntime_of_patch hpatch - have hIcode : I.code = patchedRuntime v := hcode.trans hpatched - have hsz4 : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I attesterRevokeSelBytes attesterRevokeSelBytes_size hrevoke - have hd := attesterDispatch_revoke v hmultiRevoke hmultiAttest hattest hrevoke - by_cases hsz68 : 68 ≤ I.calldata.size - · by_cases hsmall : I.calldata.size < 2 ^ 255 + 4 - · let gS : Sat256 := Sat256.ofUInt256 g - let evmEvm : EVM.State := initState cA gh bl σ_evm σ₀ gS A I - let evmSolm : EVM.State := initState cA gh bl σ_solm σ₀ gS A I - have hdec := attesterDecode_revoke_ok v hsz68 hsmall - have hwvSolm : evmSolm.executionEnv.weiValue = ⟨0⟩ := by - simp [evmSolm, initState, hwv] - have hargsSolm : - evalExprs? (config v) - { contract := contract v, locals := attesterRevokeStore I } evmSolm - [revocationRequest (.var "schema") (.var "uid")] = - .ok (attesterRevokeArgVals I) := - attesterEvalRevokeArgs v evmSolm I - have hreach := - attesterX_revokeWrapper (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := gS) v hIcode hwv hsz4 hsize - hmultiRevoke hmultiAttest hattest hrevoke - by_cases hcodeSizeEvm : - Reasoning.Theory.extCodeSizeWord σ_evm (attesterRevokeTargetWord v) = ⟨0⟩ - · have hrdrev := - attesterX_revokeNoCode (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := gS) v hIcode hwv hsz4 hsize - hsz68 hsmall hmultiRevoke hmultiAttest hattest hrevoke hcodeSizeEvm - have hcodeSizeSolm : - Reasoning.Theory.extCodeSizeWord σ_solm (attesterRevokeTargetWord v) = - ⟨0⟩ := - attesterRevokeCodeSize_zero_accountMapEquiv v hAccounts hcodeSizeEvm - have hcodeSolmRaw := - attesterRevokeEasCode_zero_of_codeSize_zero - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := gS) v hcodeSizeSolm - have haddr : EVM.address v.eas = v.eas := by - apply Fin.ext - simp [EVM.address, EVM.uintN] - exact Nat.mod_eq_of_lt v.eas.isLt - have hcodeSolm : - (UInt256.ofNat - ((evmSolm.lookupAccount v.eas).option 0 (fun acc => acc.code.size))).toNat = - 0 := by - simpa [evmSolm, haddr] using hcodeSolmRaw - have hguard : - evalExpr? (config v) - { contract := contract v, locals := attesterRevokeStore I } evmSolm - (.binary .gt (.extCodeSize (easExpr v)) (.intLit 0)) = - .ok (.bool false) := - attesterEvalExtCodeGuard_false v - (attesterEvalEasExpr v - { contract := contract v, locals := attesterRevokeStore I } evmSolm) - hcodeSolm - have hbody := - attesterRevokeBodyNoCode v evmSolm (attesterRevokeStore I) hwvSolm hguard - exact hrdrev.reEquivExecutionRevert hIcode hd hdec hbody - · have hcodeSizeSolmNe : - Reasoning.Theory.extCodeSizeWord σ_solm (attesterRevokeTargetWord v) ≠ - ⟨0⟩ := - attesterRevokeCodeSize_ne_accountMapEquiv v hAccounts hcodeSizeEvm - have hcodeSolmRaw := - attesterRevokeEasCode_pos_of_codeSize_ne - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := gS) v hcodeSizeSolmNe - have haddr : EVM.address v.eas = v.eas := by - apply Fin.ext - simp [EVM.address, EVM.uintN] - exact Nat.mod_eq_of_lt v.eas.isLt - have hcodeSolm : - 0 < (UInt256.ofNat - ((evmSolm.lookupAccount v.eas).option 0 (fun acc => acc.code.size))).toNat := by - simpa [evmSolm, haddr] using hcodeSolmRaw - have hguard : - evalExpr? (config v) - { contract := contract v, locals := attesterRevokeStore I } evmSolm - (.binary .gt (.extCodeSize (easExpr v)) (.intLit 0)) = - .ok (.bool true) := - attesterEvalExtCodeGuard_true v - (attesterEvalEasExpr v - { contract := contract v, locals := attesterRevokeStore I } evmSolm) - hcodeSolm - by_cases hdepth : I.depth.val < 1024 - · obtain ⟨cA', σ', z, o, A', k', C', rd2016, hcallEvm, hosize⟩ := - attesterX_revokePostCall (cA := cA) (gh := gh) (bl := bl) - (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) (g := gS) v - hsz68 hsize hsmall hreach hcodeSizeEvm hperm hdepth - let evmPostEvm : EVM.State := - { evmEvm with accountMap := σ', substate := A', createdAccounts := cA' } - have hcallEvm' : - typedCallViaEVM (config v) evmEvm (EVM.address v.eas) "revoke" 0 - (attesterRevokeArgVals I) (z, evmPostEvm, o) true := by - simpa [evmEvm, evmPostEvm] using hcallEvm - obtain ⟨σSolmPost, ASolmPost, hcallSolm, hStateCall⟩ := - typedCallViaEVM_initState_EVMStateEquiv (hcall := hcallEvm') - (by simp [evmEvm, evmSolm, evmPostEvm, initState]) hAccounts - let evmPostSolm : EVM.State := - { evmSolm with - accountMap := σSolmPost, substate := ASolmPost, createdAccounts := cA' } - have hcallSolm' : - typedCallViaEVM (config v) evmSolm (EVM.address v.eas) "revoke" 0 - (attesterRevokeArgVals I) (z, evmPostSolm, o) true := by - simpa [evmPostSolm] using hcallSolm - have hStateCall' : EVMStateEquiv evmPostEvm evmPostSolm := by - simpa [evmPostSolm] using hStateCall - cases z - · simp only [Bool.false_eq_true, if_false] at rd2016 hcallSolm' - have hrdrev := attesterX_revokePostRevert (v := v) rd2016 hosize (by simp) - have hbody := - attesterRevokeBodyCallFailure v evmSolm evmPostSolm - (attesterRevokeStore I) hwvSolm hguard hargsSolm hcallSolm' - exact hrdrev.reEquivExecutionRevert hIcode hd hdec hbody - · simp only [Bool.true_eq_false, if_true] at rd2016 hcallSolm' - have hrdret := attesterX_revokeSuccessStop (v := v) rd2016 - have hretdec := attesterDecode_revoke_return_ok v o - have hbody := - attesterRevokeBodySuccess v evmSolm evmPostSolm - (attesterRevokeStore I) hwvSolm hguard hargsSolm hcallSolm' hretdec - have henc : returnEquiv ByteArray.empty none (revokeTransition v).returnType := by - rw [show (revokeTransition v).returnType = [] by rfl] - exact returnEquiv.fallthrough rfl (by rfl) (by native_decide) - exact hrdret.reEquivExecutionGenEVMStateEquiv hIcode hd hdec hbody - rfl (accountMapEquiv.refl σ') hStateCall' henc - · have hdepth1024 : I.depth = 1024 := by - apply Fin.ext - have hlt := I.depth.isLt - rw [not_lt] at hdepth - omega - have hrdrev := - attesterX_revokeCallDepthLimit (cA := cA) (gh := gh) (bl := bl) - (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) (g := gS) v hIcode - hwv hsz4 hsize hsz68 hsmall hmultiRevoke hmultiAttest hattest hrevoke - hcodeSizeEvm hdepth1024 - have hdepthInit : evmSolm.executionEnv.depth = 1024 := by - simpa [evmSolm, initState] using hdepth1024 - have hcallSolm : - typedCallViaEVM (config v) evmSolm (EVM.address v.eas) "revoke" 0 - (attesterRevokeArgVals I) - (false, - { evmSolm with - substate := (evmSolm.addAccessedAccount (EVM.address v.eas)).substate }, - ByteArray.empty) - true := - callNotMade_depthLimit - (cfg := config v) (evm := evmSolm) (tgt := EVM.address v.eas) - (name := "revoke") (args := attesterRevokeArgVals I) (callPerm := true) - (attesterEncodeRevoke_eq v hsz68) hdepthInit - have hbody := - attesterRevokeBodyCallFailure v evmSolm - ({ evmSolm with - substate := (evmSolm.addAccessedAccount (EVM.address v.eas)).substate }) - (attesterRevokeStore I) hwvSolm hguard hargsSolm hcallSolm - exact hrdrev.reEquivExecutionRevert hIcode hd hdec hbody - · have hbig : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - have hdec := attesterDecode_revoke_none_huge v hbig - exact (attesterX_revokeDecodeHuge (g := Sat256.ofUInt256 g) v hIcode hwv hsz4 - hsize hbig hmultiRevoke hmultiAttest hattest hrevoke) - |>.reEquivDecodingFailed hIcode hd hdec - · have hshort : I.calldata.size < 68 := by omega - have hdec := attesterDecode_revoke_none_short v hsz4 hshort - exact (attesterX_revokeDecodeShort (g := Sat256.ofUInt256 g) v hIcode hwv hsz4 - hsize hshort hmultiRevoke hmultiAttest hattest hrevoke) - |>.reEquivDecodingFailed hIcode hd hdec - -end Benchmarks.EAS.Attester diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/AbiDecode.lean b/Benchmarks/OpenZeppelinBench/TimelockController/AbiDecode.lean deleted file mode 100644 index 7f8f96db..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/AbiDecode.lean +++ /dev/null @@ -1,424 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.AbiEncode - -/-! -# OpenZeppelin TimelockController `hashOperation` calldata decode reconciliation - -Solm-side `decodeCalldataWithMode` facts for the 5-argument tuple -`(address, uint256, bytes, bytes32, bytes32)` of `hashOperation`. These mirror the modern solc -`abi_decode_tuple_t_address_t_uint256_t_bytes_calldata_ptr_t_bytes32_t_bytes32` external decoder -(runtime @4600) and its four revert branches (short head / dirty address / bytes-offset > 2^64 / -bytes length-or-payload OOB). - -Reusable `tlcAbiDec…` lemmas: the finite `decodeABIValues?` unfold for a head-`0xa0` tuple with a -single dynamic `bytes` member, with the offset/maxEnd bookkeeping done explicitly. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1600000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Decoded argument components (calldata args base = 4) -/ - -/-- Relative offset (from args base 4) of the dynamic `bytes` payload, `= cd[68]`. -/ -abbrev tlcHashOpArgOff (I : ExecutionEnv) : Nat := (calldataWord I.calldata 68).toNat - -/-- The dynamic `bytes` length word, `= cd[4 + off]`. -/ -abbrev tlcHashOpArgLen (I : ExecutionEnv) : Nat := - (calldataWord I.calldata (4 + tlcHashOpArgOff I)).toNat - -/-- The decoded `bytes data` payload (calldata slice `[4+off+32, +len)`). -/ -abbrev tlcHashOpData (I : ExecutionEnv) : ByteArray := - ⟨((I.calldata.toList.drop (4 + tlcHashOpArgOff I + 32)).take (tlcHashOpArgLen I)).toArray⟩ - -/-- The decoded `address target` (low 160 bits of `cd[4]`). -/ -abbrev tlcHashOpTarget (I : ExecutionEnv) : EVM.Address := - AccountAddress.ofNat (calldataWord I.calldata 4).toNat - -/-- The decoded `uint256 value` (`cd[36]`). -/ -abbrev tlcHashOpValue (I : ExecutionEnv) : Int := Int.ofNat (calldataWord I.calldata 36).toNat - -/-- The decoded `bytes32 predecessor` (`cd[100..132]`). -/ -abbrev tlcHashOpPred (I : ExecutionEnv) : List UInt8 := (I.calldata.toList.drop 100).take 32 - -/-- The decoded `bytes32 salt` (`cd[132..164]`). -/ -abbrev tlcHashOpSalt (I : ExecutionEnv) : List UInt8 := (I.calldata.toList.drop 132).take 32 - -/-- The decoded local store bound by `hashOperation(target, value, data, predecessor, salt)`. -/ -def tlcHashOpStore (I : ExecutionEnv) : Store := - ((((((∅ : Store).insert "target" (.address (tlcHashOpTarget I))).insert - "value" (.int (tlcHashOpValue I))).insert - "data" (.bytes (tlcHashOpData I))).insert - "predecessor" (.fixedBytes bytes32Width (tlcHashOpPred I))).insert - "salt" (.fixedBytes bytes32Width (tlcHashOpSalt I))) - -/-! ## The well-formedness conditions of a decodable `hashOperation` calldata -/ - -/-- The (execute-path) well-formedness conditions under which both the EVM external decoder - accepts and the Solm `decodeCalldata` succeeds. -/ -structure tlcHashOpWF (I : ExecutionEnv) : Prop where - head : 164 ≤ I.calldata.size - small : I.calldata.size < 2 ^ 255 - clean : (calldataWord I.calldata 4).toNat < EVM.addressModulus - offMax : tlcHashOpArgOff I ≤ solcMaxU64 - lenWord : 4 + tlcHashOpArgOff I + 32 ≤ I.calldata.size - lenMax : tlcHashOpArgLen I ≤ solcMaxU64 - payload : 4 + tlcHashOpArgOff I + 32 + tlcHashOpArgLen I ≤ I.calldata.size - -/-! ## Guard-dispatch helper -/ - -/-- Common calldata length that fits the `hashOperation` head (5 words after the 4-byte selector). -/ -private theorem tlc_enter {I : ExecutionEnv} (hhead : 164 ≤ I.calldata.size) - (hsmall : I.calldata.size < 2 ^ 255) : - decodeCalldataWithMode DecodeMode.modern ["target", "value", "data", "predecessor", "salt"] - [addr, uint256, bytesTy, bytes32, bytes32] I.calldata = - (match decodeABIValues? [addr, uint256, bytesTy, bytes32, bytes32] - (I.calldata.toList.drop 4) 0 0 160 160 DecodeMode.modern with - | some (values, _) => - decodeCalldata.insertValues ["target", "value", "data", "predecessor", "salt"] values ∅ - | none => none) := by - unfold decodeCalldataWithMode decodeCalldata - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - rw [if_neg (show ¬ I.calldata.toList.length < 4 from by rw [htlen]; omega)] - rw [if_neg (show ¬ ([addr, uint256, bytesTy, bytes32, bytes32].any isDynamicABIType = true ∧ - 2 ^ 255 ≤ I.calldata.toList.length) from by rintro ⟨_, hc⟩; rw [htlen] at hc; omega)] - rw [if_neg (show ¬ ([addr, uint256, bytesTy, bytes32, bytes32].isEmpty = false ∧ - 2 ^ 255 ≤ (I.calldata.toList.drop 4).length) from by - rintro ⟨_, hc⟩; rw [List.length_drop, htlen] at hc; omega)] - rw [if_neg (show ¬ (solcTotalSizeDynamicGuard [addr, uint256, bytesTy, bytes32, bytes32] = true ∧ - 2 ^ 255 ≤ I.calldata.toList.length) from by simp [solcTotalSizeDynamicGuard])] - simp only [decodeCalldata.decodeArgs] - rw [show abiTupleHeadSize? [addr, uint256, bytesTy, bytes32, bytes32] = some 160 from by - native_decide] - simp only [bind, Option.bind] - rw [if_neg (show ¬ (I.calldata.toList.drop 4).length < 160 from by - rw [List.length_drop, htlen]; omega)] - cases hd : decodeABIValues? [addr, uint256, bytesTy, bytes32, bytes32] - (I.calldata.toList.drop 4) 0 0 160 160 DecodeMode.modern with - | none => rfl - | some p => - obtain ⟨values, e⟩ := p - dsimp only - generalize decodeCalldata.insertValues ["target", "value", "data", "predecessor", "salt"] - values ∅ = s - cases s <;> rfl - -/-! ## Per-member decode helpers -/ - -/-- A `readNat?` at a 32-byte-aligned calldata slot equals the big-endian word there. -/ -private theorem tlc_readNat {I : ExecutionEnv} - (htlen : I.calldata.toList.length = I.calldata.size) (k : ℕ) - (hk : 4 + k + 32 ≤ I.calldata.size) : - readNat? (I.calldata.toList.drop 4) k = some (calldataWord I.calldata (4 + k)).toNat := by - unfold readNat? readWord? readBytes? - have hlk : (((I.calldata.toList.drop 4).drop k).take 32).length = 32 := by - rw [List.length_take, List.length_drop, List.length_drop, htlen]; omega - rw [if_pos hlk] - have hword : ABI.bytesToWord (((I.calldata.toList.drop 4).drop k).take 32) = - calldataWord I.calldata (4 + k) := by - have h := decode_word_at_eq_any I.calldata (4 + k) (by omega) - simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using h - simp only [Option.bind, bind, hword] - rfl - -/-- The `address target` member decodes cleanly to `tlcHashOpTarget`. -/ -private theorem tlc_addr_ok {I : ExecutionEnv} (hhead : 36 ≤ I.calldata.size) - (hclean : (calldataWord I.calldata 4).toNat < EVM.addressModulus) : - decodeABIValue? (.elem .address) (I.calldata.toList.drop 4) 0 = - some (.address (tlcHashOpTarget I), 32) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen0 : (((I.calldata.toList.drop 4).drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, List.length_drop, htlen]; omega - have hword4 : ABI.bytesToWord (((I.calldata.toList.drop 4).drop 0).take 32) = - calldataWord I.calldata 4 := by - rw [List.drop_zero]; exact decode_word_at_eq I.calldata 4 (by omega) (by norm_num) - rw [decodeABIValue_address_ok hlen0 (by rw [hword4]; exact hclean), hword4] - -/-- The `uint256 value` member always decodes to `tlcHashOpValue`. -/ -private theorem tlc_uint256_ok {I : ExecutionEnv} (hhead : 68 ≤ I.calldata.size) : - decodeABIValue? uint256 (I.calldata.toList.drop 4) 32 = - some (.int (tlcHashOpValue I), 64) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen32 : (((I.calldata.toList.drop 4).drop 32).take 32).length = 32 := by - rw [List.length_take, List.length_drop, List.length_drop, htlen]; omega - have hword36 : ABI.bytesToWord (((I.calldata.toList.drop 4).drop 32).take 32) = - calldataWord I.calldata 36 := by - have h := decode_word_at_eq I.calldata 36 (by omega) (by norm_num) - simpa [List.drop_drop, Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using h - rw [show uint256 = abiUInt256 from rfl, decodeABIValue_uint256_ok hlen32, hword36] - -/-! ## Solm decode outcomes - -`config.abiDecodeMode = .modern`, `hashOperationTransition.params.map Param.name = -["target","value","data","predecessor","salt"]`, and -`(transitionSignature hashOperationTransition).paramTypes = [addr, uint256, bytesTy, bytes32, bytes32]` -(all by `rfl`; use `show decodeCalldataWithMode DecodeMode.modern [...] [...] I.calldata = _`). -/ - -/-- Decode success on a well-formed `hashOperation` calldata. -/ -theorem tlcDecodeHashOperation_ok {I : ExecutionEnv} (hwf : tlcHashOpWF I) : - decodeCalldataWithMode config.abiDecodeMode (hashOperationTransition.params.map Param.name) - (transitionSignature hashOperationTransition).paramTypes I.calldata - = some (tlcHashOpStore I) := by - obtain ⟨hhead, hsmall, hclean, hoffMax, hlenWord, hlenMax, hpayload⟩ := hwf - show decodeCalldataWithMode DecodeMode.modern ["target", "value", "data", "predecessor", "salt"] - [addr, uint256, bytesTy, bytes32, bytes32] I.calldata = some (tlcHashOpStore I) - rw [tlc_enter hhead hsmall] - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have haddr := tlc_addr_ok (I := I) (by omega) hclean - have huint : decodeABIValue? (.elem (.int uint256Int)) (I.calldata.toList.drop 4) 32 = - some (.int (tlcHashOpValue I), 64) := tlc_uint256_ok (by omega) - have hoffRead : readNat? (I.calldata.toList.drop 4) 64 = some (tlcHashOpArgOff I) := by - have h := tlc_readNat htlen 64 (by omega); simpa using h - have hlenRead : readNat? (I.calldata.toList.drop 4) (tlcHashOpArgOff I) = some (tlcHashOpArgLen I) := - tlc_readNat htlen (tlcHashOpArgOff I) (by omega) - have hdrop : (I.calldata.toList.drop 4).drop (tlcHashOpArgOff I + 32) = - I.calldata.toList.drop (4 + tlcHashOpArgOff I + 32) := by - rw [List.drop_drop, show 4 + (tlcHashOpArgOff I + 32) = 4 + tlcHashOpArgOff I + 32 from by omega] - have hpayRead : readBytes? (I.calldata.toList.drop 4) (tlcHashOpArgOff I + 32) - (tlcHashOpArgLen I) = some ((I.calldata.toList.drop (4 + tlcHashOpArgOff I + 32)).take - (tlcHashOpArgLen I)) := by - simp only [readBytes?, hdrop] - rw [if_pos (show ((I.calldata.toList.drop (4 + tlcHashOpArgOff I + 32)).take - (tlcHashOpArgLen I)).length = tlcHashOpArgLen I from by - rw [List.length_take, List.length_drop, htlen]; omega)] - have hbytesval : decodeABIValue? ABIType.bytes (I.calldata.toList.drop 4) (tlcHashOpArgOff I) - = some (.bytes (tlcHashOpData I), - tlcHashOpArgOff I + 32 + paddedSize (tlcHashOpArgLen I)) := by - simp only [decodeABIValue?, hlenRead, bind, Option.bind, solcMaxLen_modern, - if_neg (not_lt.mpr hlenMax), hpayRead, tlcHashOpData] - have hbytes32pred : decodeABIValue? (.elem (.bytes bytes32Width)) (I.calldata.toList.drop 4) 96 = - some (.fixedBytes bytes32Width (tlcHashOpPred I), 128) := by - have hlen96 : (((I.calldata.toList.drop 4).drop 96).take 32).length = 32 := by - rw [List.length_take, List.length_drop, List.length_drop, htlen]; omega - have h := decodeABIValue_bytes32_ok (bytes := I.calldata.toList.drop 4) (start := 96) hlen96 - rw [show ((I.calldata.toList.drop 4).drop 96).take 32 = tlcHashOpPred I from by - unfold tlcHashOpPred; rw [List.drop_drop]] at h - exact h - have hbytes32salt : decodeABIValue? (.elem (.bytes bytes32Width)) (I.calldata.toList.drop 4) 128 = - some (.fixedBytes bytes32Width (tlcHashOpSalt I), 160) := by - have hlen128 : (((I.calldata.toList.drop 4).drop 128).take 32).length = 32 := by - rw [List.length_take, List.length_drop, List.length_drop, htlen]; omega - have h := decodeABIValue_bytes32_ok (bytes := I.calldata.toList.drop 4) (start := 128) hlen128 - rw [show ((I.calldata.toList.drop 4).drop 128).take 32 = tlcHashOpSalt I from by - unfold tlcHashOpSalt; rw [List.drop_drop]] at h - exact h - unfold decodeABIValues? - simp only [addr, isDynamicABIType, staticABIEncodedSize?, Bool.false_eq_true, if_false, bind, - Option.bind, Nat.add_zero, Nat.zero_add, reduceIte, haddr] - unfold decodeABIValues? - simp only [uint256, isDynamicABIType, staticABIEncodedSize?, Bool.false_eq_true, if_false, bind, - Option.bind, Nat.reduceAdd, reduceIte, huint] - unfold decodeABIValues? - simp only [bytesTy, isDynamicABIType, bind, Option.bind, Nat.reduceAdd, reduceIte, hoffRead, - solcMaxLen_modern, if_neg (not_lt.mpr hoffMax), Nat.zero_add, hbytesval] - unfold decodeABIValues? - simp only [bytes32, isDynamicABIType, staticABIEncodedSize?, Bool.false_eq_true, if_false, bind, - Option.bind, Nat.reduceAdd, reduceIte, hbytes32pred] - unfold decodeABIValues? - simp only [isDynamicABIType, staticABIEncodedSize?, Bool.false_eq_true, if_false, bind, - Option.bind, Nat.reduceAdd, reduceIte, hbytes32salt] - unfold decodeABIValues? - simp only [decodeCalldata.insertValues, tlcHashOpStore] - -/-- Decode failure: calldata too large (modern signed-size guard, `2^255 ≤ size`). -/ -theorem tlcDecodeHashOperation_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (hashOperationTransition.params.map Param.name) - (transitionSignature hashOperationTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode DecodeMode.modern ["target", "value", "data", "predecessor", "salt"] - [addr, uint256, bytesTy, bytes32, bytes32] I.calldata = none - unfold decodeCalldataWithMode decodeCalldata - by_cases hlt4 : I.calldata.toList.length < 4 - · rw [if_pos hlt4] - · rw [if_neg hlt4] - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - rw [if_pos (show [addr, uint256, bytesTy, bytes32, bytes32].any isDynamicABIType = true ∧ - 2 ^ 255 ≤ I.calldata.toList.length from ⟨by decide, by rw [htlen]; exact hbig⟩)] - -/-- Decode failure: the 5-word (`0xa0`) head is not fully present (`size < 164`). -/ -theorem tlcDecodeHashOperation_none_short {I : ExecutionEnv} - (hshort : I.calldata.size < 164) : - decodeCalldataWithMode config.abiDecodeMode (hashOperationTransition.params.map Param.name) - (transitionSignature hashOperationTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode DecodeMode.modern ["target", "value", "data", "predecessor", "salt"] - [addr, uint256, bytesTy, bytes32, bytes32] I.calldata = none - unfold decodeCalldataWithMode decodeCalldata - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - by_cases hlt4 : I.calldata.toList.length < 4 - · rw [if_pos hlt4] - · rw [if_neg hlt4] - rw [if_neg (show ¬ ([addr, uint256, bytesTy, bytes32, bytes32].any isDynamicABIType = true ∧ - 2 ^ 255 ≤ I.calldata.toList.length) from by rintro ⟨_, hc⟩; rw [htlen] at hc; omega)] - rw [if_neg (show ¬ ([addr, uint256, bytesTy, bytes32, bytes32].isEmpty = false ∧ - 2 ^ 255 ≤ (I.calldata.toList.drop 4).length) from by - rintro ⟨_, hc⟩; rw [List.length_drop, htlen] at hc; omega)] - rw [if_neg (show ¬ (solcTotalSizeDynamicGuard [addr, uint256, bytesTy, bytes32, bytes32] = true ∧ - 2 ^ 255 ≤ I.calldata.toList.length) from by simp [solcTotalSizeDynamicGuard])] - simp only [decodeCalldata.decodeArgs] - rw [show abiTupleHeadSize? [addr, uint256, bytesTy, bytes32, bytes32] = some 160 from by - native_decide] - simp only [bind, Option.bind] - rw [if_pos (show (I.calldata.toList.drop 4).length < 160 from by - rw [List.length_drop, htlen]; omega)] - -/-- Decode failure: dirty `address` (high 96 bits of `cd[4]` nonzero). -/ -theorem tlcDecodeHashOperation_none_dirtyAddr {I : ExecutionEnv} - (hhead : 164 ≤ I.calldata.size) (hsmall : I.calldata.size < 2 ^ 255) - (hdirty : EVM.addressModulus ≤ (calldataWord I.calldata 4).toNat) : - decodeCalldataWithMode config.abiDecodeMode (hashOperationTransition.params.map Param.name) - (transitionSignature hashOperationTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode DecodeMode.modern ["target", "value", "data", "predecessor", "salt"] - [addr, uint256, bytesTy, bytes32, bytes32] I.calldata = none - rw [tlc_enter hhead hsmall] - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen0 : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hword4 : ABI.bytesToWord ((I.calldata.toList.drop 4).take 32) = calldataWord I.calldata 4 := - decode_word_at_eq I.calldata 4 (by omega) (by norm_num) - have haddr : decodeABIValue? (.elem .address) (I.calldata.toList.drop 4) 0 = none := by - apply decodeABIValue_address_none_noncanon - · rw [List.drop_zero]; exact hlen0 - · rw [List.drop_zero, hword4]; exact not_lt.mpr hdirty - have hDAV : decodeABIValues? [addr, uint256, bytesTy, bytes32, bytes32] - (I.calldata.toList.drop 4) 0 0 160 160 DecodeMode.modern = none := by - simp only [decodeABIValues?, addr, isDynamicABIType, staticABIEncodedSize?, Bool.false_eq_true, - if_false, bind, Option.bind, Nat.add_zero, Nat.zero_add, haddr] - rw [hDAV] - -/-- Decode failure: the dynamic `bytes` offset exceeds `2^64-1`. -/ -theorem tlcDecodeHashOperation_none_offset {I : ExecutionEnv} - (hhead : 164 ≤ I.calldata.size) (hsmall : I.calldata.size < 2 ^ 255) - (hclean : (calldataWord I.calldata 4).toNat < EVM.addressModulus) - (hoff : solcMaxU64 < tlcHashOpArgOff I) : - decodeCalldataWithMode config.abiDecodeMode (hashOperationTransition.params.map Param.name) - (transitionSignature hashOperationTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode DecodeMode.modern ["target", "value", "data", "predecessor", "salt"] - [addr, uint256, bytesTy, bytes32, bytes32] I.calldata = none - rw [tlc_enter hhead hsmall] - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have haddr := tlc_addr_ok (I := I) (by omega) hclean - have huint : decodeABIValue? (.elem (.int uint256Int)) (I.calldata.toList.drop 4) 32 = - some (.int (tlcHashOpValue I), 64) := tlc_uint256_ok (by omega) - have hoffRead : readNat? (I.calldata.toList.drop 4) 64 = some (tlcHashOpArgOff I) := by - have h := tlc_readNat htlen 64 (by omega); simpa using h - have hDAV : decodeABIValues? [addr, uint256, bytesTy, bytes32, bytes32] - (I.calldata.toList.drop 4) 0 0 160 160 DecodeMode.modern = none := by - simp only [decodeABIValues?, addr, uint256, bytesTy, isDynamicABIType, staticABIEncodedSize?, - Bool.false_eq_true, if_false, bind, Option.bind, Nat.add_zero, Nat.zero_add, Nat.reduceAdd, - reduceIte, haddr, huint, hoffRead, solcMaxLen_modern, if_pos hoff] - rw [hDAV] - -/-- Decode failure: the `bytes` length word is not present (`size < 4 + off + 32`). -/ -theorem tlcDecodeHashOperation_none_lenWord {I : ExecutionEnv} - (hhead : 164 ≤ I.calldata.size) (hsmall : I.calldata.size < 2 ^ 255) - (hclean : (calldataWord I.calldata 4).toNat < EVM.addressModulus) - (hoffMax : tlcHashOpArgOff I ≤ solcMaxU64) - (hlenWord : I.calldata.size < 4 + tlcHashOpArgOff I + 32) : - decodeCalldataWithMode config.abiDecodeMode (hashOperationTransition.params.map Param.name) - (transitionSignature hashOperationTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode DecodeMode.modern ["target", "value", "data", "predecessor", "salt"] - [addr, uint256, bytesTy, bytes32, bytes32] I.calldata = none - rw [tlc_enter hhead hsmall] - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have haddr := tlc_addr_ok (I := I) (by omega) hclean - have huint : decodeABIValue? (.elem (.int uint256Int)) (I.calldata.toList.drop 4) 32 = - some (.int (tlcHashOpValue I), 64) := tlc_uint256_ok (by omega) - have hoffRead : readNat? (I.calldata.toList.drop 4) 64 = some (tlcHashOpArgOff I) := by - have h := tlc_readNat htlen 64 (by omega); simpa using h - have hlenRead : readNat? (I.calldata.toList.drop 4) (tlcHashOpArgOff I) = none := by - unfold readNat? readWord? readBytes? - rw [if_neg (show ¬ (((I.calldata.toList.drop 4).drop (tlcHashOpArgOff I)).take 32).length = 32 - from by rw [List.length_take, List.length_drop, List.length_drop, htlen]; omega)] - rfl - have hbytesval : decodeABIValue? ABIType.bytes (I.calldata.toList.drop 4) (tlcHashOpArgOff I) - = none := by - simp only [decodeABIValue?, hlenRead, bind, Option.bind] - have hDAV : decodeABIValues? [addr, uint256, bytesTy, bytes32, bytes32] - (I.calldata.toList.drop 4) 0 0 160 160 DecodeMode.modern = none := by - simp only [decodeABIValues?, addr, uint256, bytesTy, isDynamicABIType, staticABIEncodedSize?, - Bool.false_eq_true, if_false, bind, Option.bind, Nat.add_zero, Nat.zero_add, Nat.reduceAdd, - reduceIte, haddr, huint, hoffRead, solcMaxLen_modern, if_neg (not_lt.mpr hoffMax), hbytesval] - rw [hDAV] - -/-- Decode failure: the dynamic `bytes` length exceeds `2^64-1`. -/ -theorem tlcDecodeHashOperation_none_lenBig {I : ExecutionEnv} - (hhead : 164 ≤ I.calldata.size) (hsmall : I.calldata.size < 2 ^ 255) - (hclean : (calldataWord I.calldata 4).toNat < EVM.addressModulus) - (hoffMax : tlcHashOpArgOff I ≤ solcMaxU64) - (hlenWord : 4 + tlcHashOpArgOff I + 32 ≤ I.calldata.size) - (hlenBig : solcMaxU64 < tlcHashOpArgLen I) : - decodeCalldataWithMode config.abiDecodeMode (hashOperationTransition.params.map Param.name) - (transitionSignature hashOperationTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode DecodeMode.modern ["target", "value", "data", "predecessor", "salt"] - [addr, uint256, bytesTy, bytes32, bytes32] I.calldata = none - rw [tlc_enter hhead hsmall] - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have haddr := tlc_addr_ok (I := I) (by omega) hclean - have huint : decodeABIValue? (.elem (.int uint256Int)) (I.calldata.toList.drop 4) 32 = - some (.int (tlcHashOpValue I), 64) := tlc_uint256_ok (by omega) - have hoffRead : readNat? (I.calldata.toList.drop 4) 64 = some (tlcHashOpArgOff I) := by - have h := tlc_readNat htlen 64 (by omega); simpa using h - have hlenRead : readNat? (I.calldata.toList.drop 4) (tlcHashOpArgOff I) = some (tlcHashOpArgLen I) := - tlc_readNat htlen (tlcHashOpArgOff I) (by omega) - have hbytesval : decodeABIValue? ABIType.bytes (I.calldata.toList.drop 4) (tlcHashOpArgOff I) - = none := by - simp only [decodeABIValue?, hlenRead, bind, Option.bind, solcMaxLen_modern, if_pos hlenBig] - have hDAV : decodeABIValues? [addr, uint256, bytesTy, bytes32, bytes32] - (I.calldata.toList.drop 4) 0 0 160 160 DecodeMode.modern = none := by - simp only [decodeABIValues?, addr, uint256, bytesTy, isDynamicABIType, staticABIEncodedSize?, - Bool.false_eq_true, if_false, bind, Option.bind, Nat.add_zero, Nat.zero_add, Nat.reduceAdd, - reduceIte, haddr, huint, hoffRead, solcMaxLen_modern, if_neg (not_lt.mpr hoffMax), hbytesval] - rw [hDAV] - -/-- Decode failure: the `bytes` payload is not fully present (`size < 4 + off + 32 + len`). -/ -theorem tlcDecodeHashOperation_none_payload {I : ExecutionEnv} - (hhead : 164 ≤ I.calldata.size) (hsmall : I.calldata.size < 2 ^ 255) - (hclean : (calldataWord I.calldata 4).toNat < EVM.addressModulus) - (hoffMax : tlcHashOpArgOff I ≤ solcMaxU64) - (hlenWord : 4 + tlcHashOpArgOff I + 32 ≤ I.calldata.size) - (hlenMax : tlcHashOpArgLen I ≤ solcMaxU64) - (hpay : I.calldata.size < 4 + tlcHashOpArgOff I + 32 + tlcHashOpArgLen I) : - decodeCalldataWithMode config.abiDecodeMode (hashOperationTransition.params.map Param.name) - (transitionSignature hashOperationTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode DecodeMode.modern ["target", "value", "data", "predecessor", "salt"] - [addr, uint256, bytesTy, bytes32, bytes32] I.calldata = none - rw [tlc_enter hhead hsmall] - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have haddr := tlc_addr_ok (I := I) (by omega) hclean - have huint : decodeABIValue? (.elem (.int uint256Int)) (I.calldata.toList.drop 4) 32 = - some (.int (tlcHashOpValue I), 64) := tlc_uint256_ok (by omega) - have hoffRead : readNat? (I.calldata.toList.drop 4) 64 = some (tlcHashOpArgOff I) := by - have h := tlc_readNat htlen 64 (by omega); simpa using h - have hlenRead : readNat? (I.calldata.toList.drop 4) (tlcHashOpArgOff I) = some (tlcHashOpArgLen I) := - tlc_readNat htlen (tlcHashOpArgOff I) (by omega) - have hpayRead : readBytes? (I.calldata.toList.drop 4) (tlcHashOpArgOff I + 32) - (tlcHashOpArgLen I) = none := by - unfold readBytes? - rw [if_neg (show ¬ (((I.calldata.toList.drop 4).drop (tlcHashOpArgOff I + 32)).take - (tlcHashOpArgLen I)).length = tlcHashOpArgLen I from by - rw [List.length_take, List.length_drop, List.length_drop, htlen]; omega)] - have hbytesval : decodeABIValue? ABIType.bytes (I.calldata.toList.drop 4) (tlcHashOpArgOff I) - = none := by - simp only [decodeABIValue?, hlenRead, bind, Option.bind, solcMaxLen_modern, - if_neg (not_lt.mpr hlenMax), hpayRead] - have hDAV : decodeABIValues? [addr, uint256, bytesTy, bytes32, bytes32] - (I.calldata.toList.drop 4) 0 0 160 160 DecodeMode.modern = none := by - simp only [decodeABIValues?, addr, uint256, bytesTy, isDynamicABIType, staticABIEncodedSize?, - Bool.false_eq_true, if_false, bind, Option.bind, Nat.add_zero, Nat.zero_add, Nat.reduceAdd, - reduceIte, haddr, huint, hoffRead, solcMaxLen_modern, if_neg (not_lt.mpr hoffMax), hbytesval] - rw [hDAV] - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/AbiEncode.lean b/Benchmarks/OpenZeppelinBench/TimelockController/AbiEncode.lean deleted file mode 100644 index 1cc14747..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/AbiEncode.lean +++ /dev/null @@ -1,66 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Return -import Benchmarks.OpenZeppelinBench.TimelockController.Storage - -/-! -# OpenZeppelin TimelockController ABI-encode-in-memory reconciliation (for `hashOperation`) - -Reusable pieces connecting the EVM `abi_encode_tuple(address,uint256,bytes,bytes32,bytes32)` -encoder (runtime @5933) to the Solm spec `ABI.encodeReturnValues? [addr,uint256,bytes,bytes32,bytes32]`. - -LIBRARY CANDIDATEs: the `tlcAbiEnc…` lemmas below generalize to any solc tuple encoder with a single -dynamic `bytes` member and a `0xa0` head offset. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Pure ABI-encode characterization of the `hashOperation` tuple -/ - --- LIBRARY CANDIDATE: `Reasoning.ABI` — encode of `[addr,uint256,bytes,bytes32,bytes32]` (0xa0 head). -/-- `encodeReturnValues?` of the `hashOperation` argument tuple: the canonical - head `target ‖ value ‖ 0xa0 ‖ predecessor ‖ salt` followed by the tail `len ‖ padded data`. -/ -theorem tlcAbiEncHashOperation (a : EVM.Address) (i : Int) (hi : 0 ≤ i ∧ i < 2 ^ 256) - (ba : ByteArray) (pbs sbs : List UInt8) (hp : pbs.length = 32) (hs : sbs.length = 32) : - ABI.encodeReturnValues? [addr, uint256, bytesTy, bytes32, bytes32] - [.address a, .int i, .bytes ba, - .fixedBytes ⟨31, by decide⟩ pbs, .fixedBytes ⟨31, by decide⟩ sbs] - = some ⟨((EVM.word a).toBytesBE ++ (EVM.word i.toNat).toBytesBE - ++ ABI.natBytes 160 ++ pbs ++ sbs - ++ (ABI.natBytes ba.size ++ ABI.padRightToWord ba.toList)).toArray⟩ := by - have hlt : i < ↑(EVM.twoPow 256) := by - rw [show EVM.twoPow 256 = 2 ^ 256 from rfl]; exact_mod_cast hi.2 - simp [encodeReturnValues?, encodeABIValues?, encodeABIValuesFrom?, abiTupleHeadSize?, - encodeABIValue?, encodeABIWord?, isDynamicABIType, staticABIEncodedSize?, - addr, uint256, uint256Int, bytesTy, bytes32, bytes32Width, natBytes, zeroBytes, - hlt, hi.1, hp, hs, List.append_assoc] - -/-- The canonical `hashOperation` preimage bytes as a plain `List UInt8` - (`target ‖ value ‖ 0xa0 ‖ predecessor ‖ salt ‖ len ‖ padded data`). This is the exact byte - string the EVM encoder writes to `mem[0xa0 ..]` and hands to `KECCAK256`. -/ -def tlcAbiEncHashOperationBytes (a : EVM.Address) (n : Nat) (ba : ByteArray) - (pbs sbs : List UInt8) : List UInt8 := - (EVM.word a).toBytesBE ++ (EVM.word n).toBytesBE ++ ABI.natBytes 160 ++ pbs ++ sbs - ++ (ABI.natBytes ba.size ++ ABI.padRightToWord ba.toList) - --- LIBRARY CANDIDATE: the encoded byte length `= 5·32 (head) + 32 (len word) + roundUp₃₂(|data|)`. -/-- The canonical preimage length is `192 + paddedSize |data|`, i.e. the second (length) operand of - the `KECCAK256` opcode at runtime @2354 (`endPtr − 0xa0`). -/ -theorem tlcAbiEncHashOperationBytes_length (a : EVM.Address) (n : Nat) (ba : ByteArray) - (pbs sbs : List UInt8) (hp : pbs.length = 32) (hs : sbs.length = 32) : - (tlcAbiEncHashOperationBytes a n ba pbs sbs).length = 192 + ABI.paddedSize ba.size := by - have hw : ∀ w : EVM.Word, (EVM.Word.toBytesBE w).length = 32 := fun w => by - simpa using word_toBytesBE_toByteArray_size w - have hbalen : ba.toList.length = ba.size := by rw [byteArray_toList_eq, Array.length_toList]; rfl - have hpad : (ABI.padRightToWord ba.toList).length = ABI.paddedSize ba.size := by - unfold ABI.padRightToWord ABI.zeroBytes - rw [List.length_append, List.length_replicate, hbalen] - have : ba.size ≤ ABI.paddedSize ba.size := by unfold ABI.paddedSize; omega - omega - simp only [tlcAbiEncHashOperationBytes, List.length_append, hw, hp, hs, ABI.natBytes, hpad] - omega - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Body.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Body.lean deleted file mode 100644 index b473e972..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Body.lean +++ /dev/null @@ -1,140 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.AbiDecode - -/-! -# OpenZeppelin TimelockController `hashOperation` Solm body evaluation - -The Solm body of `hashOperation` is `nonpayable ++ [.return [keccak256(abi.encode(...))]]`. Under the -decoded store `tlcHashOpStore I`, the return expression `hashOperationExpr` evaluates to the -`bytes32` keccak of the canonical ABI encoding — the exact `ffi.KEC` of `tlcAbiEncHashOperationBytes`, -i.e. the same preimage the runtime encoder writes to `mem[0xa0..]` and hashes. - -Template: `Benchmarks/Dss/Dai/Permit.lean` `evalExpr_permitDigest` (770-834) — but that uses -`abiEncodePacked`; here the outer node is `.abiEncodeCall "__abi_encode_hashOperation"` which routes -through `config.externalABI.encode? = timelockExternalABI.encode? - = ABI.encodeReturnValues? [addr, uint256, bytesTy, bytes32, bytes32]` (see `Spec.lean:206`), -and that encode is exactly `tlcAbiEncHashOperation` (green, in `AbiEncode.lean`). --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1600000 - -namespace OpenZeppelinBench.TimelockController - -/-- The canonical `hashOperation` preimage as a `ByteArray` (what the runtime hashes at `mem[0xa0]` - and what the Solm `abi.encode` produces). -/ -abbrev tlcHashOpCanonBytes (I : ExecutionEnv) : ByteArray := - ⟨(tlcAbiEncHashOperationBytes (tlcHashOpTarget I) (tlcHashOpValue I).toNat - (tlcHashOpData I) (tlcHashOpPred I) (tlcHashOpSalt I)).toArray⟩ - -/-- The `bytes32` result of `hashOperation`: `keccak256` of the canonical ABI encoding. -/ -abbrev tlcHashOpKecList (I : ExecutionEnv) : List UInt8 := (ffi.KEC (tlcHashOpCanonBytes I)).toList - -/-- The Solm `hashOperation` body returns `keccak256(abi.encode(target,value,data,predecessor,salt))`. - Requires a well-formed calldata so the decoded `predecessor`/`salt` are full 32-byte words and the - `value` is in `uint256` range (all from `tlcHashOpWF`). -/ -theorem tlcHashOperationBodyReturns {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hwf : tlcHashOpWF I) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcHashOpStore I) - hashOperationTransition.body - (.returned { contract := contract, locals := tlcHashOpStore I } - (initState cA gh bl σ σ₀ g A I) - (some [.fixedBytes bytes32Width (tlcHashOpKecList I)])) := by - have hhead := hwf.head - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - -- Side conditions for `tlcAbiEncHashOperation`. - have hi0 : 0 ≤ tlcHashOpValue I := by unfold tlcHashOpValue; exact Int.natCast_nonneg _ - have hi1 : tlcHashOpValue I < 2 ^ 256 := by - have h : (calldataWord I.calldata 36).toNat < UInt256.size := - (calldataWord I.calldata 36).val.isLt - have hsz : UInt256.size = 2 ^ 256 := by norm_num [UInt256.size] - rw [hsz] at h; unfold tlcHashOpValue - show ((calldataWord I.calldata 36).toNat : ℤ) < 2 ^ 256 - exact_mod_cast h - have hp : (tlcHashOpPred I).length = 32 := by - unfold tlcHashOpPred; rw [List.length_take, List.length_drop, htlen]; omega - have hs : (tlcHashOpSalt I).length = 32 := by - unfold tlcHashOpSalt; rw [List.length_take, List.length_drop, htlen]; omega - -- Store lookups for the five decoded parameters. - have gT : (tlcHashOpStore I).get? "target" = some (.address (tlcHashOpTarget I)) := by - unfold tlcHashOpStore - rw [store_get_ne4 ((∅ : Store).insert "target" (.address (tlcHashOpTarget I))) - (.int (tlcHashOpValue I)) (.bytes (tlcHashOpData I)) - (.fixedBytes bytes32Width (tlcHashOpPred I)) (.fixedBytes bytes32Width (tlcHashOpSalt I)) - (by decide) (by decide) (by decide) (by decide)] - simp - have gV : (tlcHashOpStore I).get? "value" = some (.int (tlcHashOpValue I)) := by - unfold tlcHashOpStore - rw [store_get_ne3 (((∅ : Store).insert "target" (.address (tlcHashOpTarget I))).insert - "value" (.int (tlcHashOpValue I))) - (.bytes (tlcHashOpData I)) (.fixedBytes bytes32Width (tlcHashOpPred I)) - (.fixedBytes bytes32Width (tlcHashOpSalt I)) - (by decide) (by decide) (by decide)] - simp - have gD : (tlcHashOpStore I).get? "data" = some (.bytes (tlcHashOpData I)) := by - unfold tlcHashOpStore - rw [store_get_ne2 ((((∅ : Store).insert "target" (.address (tlcHashOpTarget I))).insert - "value" (.int (tlcHashOpValue I))).insert "data" (.bytes (tlcHashOpData I))) - (.fixedBytes bytes32Width (tlcHashOpPred I)) (.fixedBytes bytes32Width (tlcHashOpSalt I)) - (by decide) (by decide)] - simp - have gP : (tlcHashOpStore I).get? "predecessor" - = some (.fixedBytes bytes32Width (tlcHashOpPred I)) := by - unfold tlcHashOpStore - rw [store_get_ne (((((∅ : Store).insert "target" (.address (tlcHashOpTarget I))).insert - "value" (.int (tlcHashOpValue I))).insert "data" (.bytes (tlcHashOpData I))).insert - "predecessor" (.fixedBytes bytes32Width (tlcHashOpPred I))) - (.fixedBytes bytes32Width (tlcHashOpSalt I)) (by decide)] - simp - have gS : (tlcHashOpStore I).get? "salt" - = some (.fixedBytes bytes32Width (tlcHashOpSalt I)) := by - unfold tlcHashOpStore; simp - -- The five `.var` expressions evaluate to the decoded values. - have eT : evalExpr? config { contract := contract, locals := tlcHashOpStore I } - (initState cA gh bl σ σ₀ g A I) (.var "target") = .ok (.address (tlcHashOpTarget I)) := by - simp only [evalExpr?, gT, EvalResult.ofOption] - have eV : evalExpr? config { contract := contract, locals := tlcHashOpStore I } - (initState cA gh bl σ σ₀ g A I) (.var "value") = .ok (.int (tlcHashOpValue I)) := by - simp only [evalExpr?, gV, EvalResult.ofOption] - have eD : evalExpr? config { contract := contract, locals := tlcHashOpStore I } - (initState cA gh bl σ σ₀ g A I) (.var "data") = .ok (.bytes (tlcHashOpData I)) := by - simp only [evalExpr?, gD, EvalResult.ofOption] - have eP : evalExpr? config { contract := contract, locals := tlcHashOpStore I } - (initState cA gh bl σ σ₀ g A I) (.var "predecessor") - = .ok (.fixedBytes bytes32Width (tlcHashOpPred I)) := by - simp only [evalExpr?, gP, EvalResult.ofOption] - have eS : evalExpr? config { contract := contract, locals := tlcHashOpStore I } - (initState cA gh bl σ σ₀ g A I) (.var "salt") - = .ok (.fixedBytes bytes32Width (tlcHashOpSalt I)) := by - simp only [evalExpr?, gS, EvalResult.ofOption] - -- The argument list evaluates to the five decoded values. - have hlist : evalExprList? config { contract := contract, locals := tlcHashOpStore I } - (initState cA gh bl σ σ₀ g A I) - [.var "target", .var "value", .var "data", .var "predecessor", .var "salt"] - = .ok [.address (tlcHashOpTarget I), .int (tlcHashOpValue I), .bytes (tlcHashOpData I), - .fixedBytes bytes32Width (tlcHashOpPred I), .fixedBytes bytes32Width (tlcHashOpSalt I)] := by - simp only [evalExprList?, eT, eV, eD, eP, eS, EvalResult.bind, bind, pure] - -- The `abi.encode` call produces the canonical preimage bytes. - have henc : config.externalABI.encode? "__abi_encode_hashOperation" - [Value.address (tlcHashOpTarget I), .int (tlcHashOpValue I), .bytes (tlcHashOpData I), - .fixedBytes bytes32Width (tlcHashOpPred I), .fixedBytes bytes32Width (tlcHashOpSalt I)] - = some (tlcHashOpCanonBytes I) := - tlcAbiEncHashOperation (tlcHashOpTarget I) (tlcHashOpValue I) ⟨hi0, hi1⟩ - (tlcHashOpData I) (tlcHashOpPred I) (tlcHashOpSalt I) hp hs - -- The `abi.encode` call evaluates to the canonical preimage bytes. - have hcall : evalExpr? config { contract := contract, locals := tlcHashOpStore I } - (initState cA gh bl σ σ₀ g A I) - (.abiEncodeCall "__abi_encode_hashOperation" - [.var "target", .var "value", .var "data", .var "predecessor", .var "salt"]) - = .ok (.bytes (tlcHashOpCanonBytes I)) := by - rw [evalExpr?, hlist] - simp only [EvalResult.bind, bind, pure] - rw [henc]; rfl - -- Assemble: keccak256 of the encoded preimage. - refine nonpayableReturnExprBodyReturns (by simp only [initState]; exact hwv) ?_ - unfold hashOperationExpr - rw [evalExpr?, hcall]; rfl - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Cancel.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Cancel.lean deleted file mode 100644 index d2bd2f79..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Cancel.lean +++ /dev/null @@ -1,998 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.HasRole -import Benchmarks.OpenZeppelinBench.TimelockController.IsOperationPending -import Benchmarks.OpenZeppelinBench.TimelockController.GetOperationState -import Benchmarks.OpenZeppelinBench.TimelockController.GetTimestamp -import Benchmarks.OpenZeppelinBench.TimelockController.CancellerRole -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines -import Reasoning.MemCascade - -/-! -# OpenZeppelin TimelockController `cancel(bytes32)` refinement - -`cancel` (selector index 1, dispatch group G98 arm 1, body pc 1276) is the first function combining a -constant-role `onlyRole` guard, a mapping read, and a storage **delete**. It decodes one `bytes32 id` -via the shared word decoder `@4702`, enforces `onlyRole(CANCELLER_ROLE)` (the `_checkRole` helper -`@3461 → @3655 → @2762` — the same nested read `hasRole` uses, but with the constant role -`CANCELLER_ROLE` and account `msg.sender`), requires `isOperationPending(id)` (`_timestamps[id] > 1` -via the inlined `_getOperationState @2232` + range test `@2048`), then **deletes** `_timestamps[id]` -(`SSTORE 0` at the mapping slot `keccak(id ‖ 1)`) and emits a `Cancelled` `LOG2`. - -The delete `.delete (timestampRef id)` clears the `uint256` slot to `0` (`clearStorage?` on the -`.elem` leaf), coupling to the EVM `SSTORE 0` via `accountMapEquiv_sstoreAccountMap`. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## LOG2 stepping (absent from the shared library — only `LOG1/3/4` are provided there) - - Copied verbatim from the WETH9 `RD.log2`: pop `[offset, size, t1, t2]`, append a 2-topic log over - `mem[offset..offset+size]` (cost `memExp + Glog + Glogdata·size + 2·Glogtopic`, pc += 1). Requires - `ee.perm`; the `substate.logSeries` append is invisible to `RD`. -/ -def stLog2 (s : State) (a b c d : UInt256) (t : List UInt256) : State := - {s with - substate.logSeries := s.substate.logSeries.push - ⟨s.executionEnv.codeOwner, #[c, d], s.machineState.memory.readWithPadding a.toNat b.toNat⟩ - machineState.stack := t - machineState.activeWords := - UInt256.ofNat (MachineState.M s.machineState.activeWords.toNat a.toNat b.toNat) - machineState.gasAvailable := - (s.machineState.gasAvailable.subNat (memoryExpansionCost s .LOG2)).subNat - (GasConstants.Glog + GasConstants.Glogdata * b.toNat - + 2 * GasConstants.Glogtopic) - machineState.pc := s.machineState.pc + ⟨1⟩ - machineState.execLength := s.machineState.execLength + 1 } - -theorem log2_xstep {s : State} {code : ByteArray} {pcv a b c d : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.LOG2, .none)) (hperm : s.executionEnv.perm = true) - (hstk : s.machineState.stack = a :: b :: c :: d :: t) (hov : t.length ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat - < memoryExpansionCost s .LOG2 - + (GasConstants.Glog + GasConstants.Glogdata * b.toNat + 2 * GasConstants.Glogtopic) - then .error .OutOfGass else .ok (stLog2 s a b c d t, .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.LOG2, .none) := by - rw [hcode, hpc]; exact hdec - rw [← hcode, step_log2 s hd, hstk] - have hov' : ¬ ((a :: b :: c :: d :: t).length - 4 + 0 > 1024) := by - simp only [List.length_cons]; omega - have hpermF : (¬ s.executionEnv.perm = true) = False := eq_false (by simp [hperm]) - simp only [collapse_two_stage, if_neg hov', hpermF, if_false, stLog2] - -theorem RD.log2 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d : UInt256} {t : List UInt256} (mcost : ℕ) (awout : UInt256) - (h : RD code ee g s0 pc (a :: b :: c :: d :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.LOG2, .none)) (hperm : ee.perm = true) - (hmc : ∀ s : State, s.machineState.activeWords = aw → - s.machineState.stack = a :: b :: c :: d :: t → - memoryExpansionCost s .LOG2 = mcost) - (hawout : UInt256.ofNat (MachineState.M aw.toNat a.toNat b.toNat) = awout) - (hov : t.length ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) t mem awout rdata acc (k + 1) - (C + (mcost + (GasConstants.Glog + GasConstants.Glogdata * b.toNat - + 2 * GasConstants.Glogtopic))) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, hee, hworld⟩ - · exact Or.inl hoog - · have hmcS : memoryExpansionCost s .LOG2 = mcost := hmc s haw hstk - have hperms : s.executionEnv.perm = true := by rw [hee]; exact hperm - have st := log2_xstep hcode hpc hdec hperms hstk hov - rw [hmcS] at st - by_cases gg : g.toNat < C + (mcost - + (GasConstants.Glog + GasConstants.Glogdata * b.toNat + 2 * GasConstants.Glogtopic)) - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨stLog2 s a b c d t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, - (by have : 1 ≤ GasConstants.Glog := (by decide); omega), by omega, - ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [stLog2]; exact hcode - · simp only [stLog2]; rw [hpc] - · simp only [stLog2] - · simp only [stLog2, hmcS] - rw [hgas, Sat256.subNat_sub_add_of_sub_sub, Sat256.subNat_sub_add_of_sub_sub] - · simp only [stLog2]; exact hmem - · simp only [stLog2]; rw [haw, hawout] - · simp only [stLog2]; exact hrdata - · simp only [stLog2]; exact hacc - · simp only [stLog2]; exact hee - · simp only [stLog2]; exact hworld - -/-! ## Decoded argument, role slot, and stored words - -`cancel(bytes32 id)` binds the same one-`bytes32` local store as `getTimestamp` (`tlcGetTimestampStore`), -and its timestamp lives at the same mapping slot `keccak(id ‖ 1)`. The `onlyRole` guard reads the -nested slot `keccak(msg.sender ‖ keccak(CANCELLER_ROLE ‖ 0))`. -/ - -/-- `msg.sender` as an EVM word (what `CALLER` pushes). -/ -abbrev tlcCancelCallerWord (I : ExecutionEnv) : UInt256 := UInt256.ofNat I.source.val - -/-- The nested `_roles[CANCELLER_ROLE].hasRole[msg.sender]` slot as the runtime computes it. -/ -abbrev tlcCancelRoleSlot (I : ExecutionEnv) : UInt256 := - solcMappingSlot (solcMappingSlot ⟨0⟩ tlcCancellerRoleWord) - (UInt256.land solcAddrMask (tlcCancelCallerWord I)) - -/-- The stored `_roles[CANCELLER_ROLE].hasRole[msg.sender]` word. -/ -abbrev tlcCancelRoleWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (tlcCancelRoleSlot I) - -/-! ## EVM: reach the body and run the `bytes32` decoder -/ - -/-- Reach the `cancel` body pc 1276 (G98 arm 1). -/ -theorem tlcReachCancel {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 1)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1276⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0xc4d252f5⟩ := - solcSelectorWord_eq_of_beq I hsz 0xc4 0xd2 0x52 0xf5 ⟨0xc4d252f5⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG98Body 1 (by omega) ⟨1276⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j; rw [hsw]; native_decide) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Peel the non-payable guard, push the return/decode continuations `⟨476⟩`/`⟨1302⟩`, and run the - `bytes32` decoder prologue @4702 to the availability `JUMPI` @4714. -/ -theorem tlcCancelReachLenCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 1)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4714⟩ - [⟨4718⟩, UInt256.isZero (UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩), - ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1302⟩, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h1276⟩ := tlcReachCancel (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h1289⟩ := tlcGuardPeelOk (gt := ⟨1287⟩) h1276 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, h1289.push2 ⟨476⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨1302⟩ (by native_decide) (by evm_ov) - |>.calldatasize (by native_decide) (by evm_ov) - |>.push1 ⟨4⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4702⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.slt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨4718⟩ (by native_decide) (by evm_ov)⟩ - -/-- After the length check passes, finish the decoder (`CALLDATALOAD(4)`), jump back to the decode - continuation @1302, and enter the `cancel` body logic @2870 with `[id, ⟨476⟩, sel]`. -/ -theorem tlcCancelReach2870 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 1)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2870⟩ - [calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsz : 4 ≤ I.calldata.size := by omega - obtain ⟨_, _, h4714⟩ := tlcCancelReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact ⟨_, _, h4714.jumpiT (by native_decide) - (by rw [solcDecodeLenCheckOk_4_32 hsz36 hbig hsize]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨2870⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov)⟩ - -/-! ## EVM: the `onlyRole(CANCELLER_ROLE)` guard (@2870 → `_checkRole` @3461 → @3655 → @2762) - - The scratch memory the nested `hasRole` read leaves at @3665. -/ -noncomputable abbrev tlcCancelHasRoleMem (I : ExecutionEnv) : ByteArray := - twoWordHashMem (UInt256.land solcAddrMask (tlcCancelCallerWord I)) - (solcMappingSlot ⟨0⟩ tlcCancellerRoleWord) - (twoWordHashMem tlcCancellerRoleWord ⟨0⟩ solcFreePtrMem) - -/-- From the body @2870, push the constant role, dispatch `_checkRole(role) @3461 → @3655`, and reuse - `tlcHasRoleSlotLoad @2762` for the nested `_roles[role].hasRole[msg.sender]` read — reaching the - `if authorized` `JUMPI` @3665 with the masked stored byte on top. -/ -theorem tlcCancelReach3665 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2870⟩ - [calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3665⟩ - [UInt256.land ⟨255⟩ (tlcCancelRoleWord σ I), tlcCancelCallerWord I, tlcCancellerRoleWord, ⟨3471⟩, - tlcCancellerRoleWord, ⟨2912⟩, tlcCancellerRoleWord, calldataWord I.calldata 4, ⟨476⟩, - tlcSelWord I] - (tlcCancelHasRoleMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - have h2762 := h.jumpdest (by native_decide) (by evm_ov) - |>.pushConst tlcCancellerRoleWord (op := .PUSH32) (width := 32) (by decide) - (by native_decide) (by evm_ov) - |>.push2 ⟨2912⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.push2 ⟨3461⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨3471⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.caller (by native_decide) (by evm_ov) - |>.push2 ⟨3655⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨3665⟩ (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.push2 ⟨2762⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - exact tlcHasRoleSlotLoad h2762 (by jump_dest) (by simp) - -/-- `msg.sender` has the canceller role: continue past the `_checkRole` `JUMPI` @3665 through the - `_checkRole`/`onlyRole` return trampolines back to the body @2912. -/ -theorem tlcCancelReach2912 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2870⟩ - [calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hhas : ¬ UInt256.land ⟨255⟩ (tlcCancelRoleWord σ I) = ⟨0⟩) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2912⟩ - [tlcCancellerRoleWord, calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - (tlcCancelHasRoleMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - obtain ⟨_, _, h3665⟩ := tlcCancelReach3665 h - exact ⟨_, _, h3665.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨3712⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) hhas (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov)⟩ - -/-! ## EVM: the `isOperationPending` helper `@2048` used by `cancel` (@2912 → @2921) - - The `_getOperationState @2232` tail `@2059` — generic in the return address `ret` and the stack - tail `below`, unlike the fixed `IsOperationPending.tlcIsOperationPendingTail` (`ret = 509`, - `below = [sel]`). From `[state, 0, 0, key, ret] ++ below` it computes `state == 1 ∨ state == 2` - (the `DUP1;…;JUMPI` short-circuit) and returns to `ret` with `[boolOf state] ++ below`. -/ -theorem tlcCancelPendingTail {cA gh bl σ σ₀ A I} {g : Sat256} {R key ret : UInt256} - {below : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2059⟩ - (R :: ⟨0⟩ :: ⟨0⟩ :: key :: ret :: below) mem aw ByteArray.empty (cA, σ) k C) - (hbound : UInt256.isZero (UInt256.gt R ⟨3⟩) ≠ ⟨0⟩) - (hret : (D_J timelockControllerBenchBytecode 0).contains ret = true) - (hov : below.length + 8 ≤ 1024) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ret - (tlcIsOperationPendingBoolOf R :: below) mem aw ByteArray.empty (cA, σ) k' C' := by - by_cases heq1 : R = ⟨1⟩ - · have hc1 : UInt256.eq R ⟨1⟩ ≠ ⟨0⟩ := by rw [heq1]; decide - have hret' := h.jumpdest (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.push1 ⟨3⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.gt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨2081⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) hbound (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.eq (by native_decide) (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.push2 ⟨2110⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) hc1 (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap4 (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) hret (by evm_ov) - rw [show UInt256.eq R ⟨1⟩ = tlcIsOperationPendingBoolOf R from by - unfold tlcIsOperationPendingBoolOf; rw [if_pos heq1]] at hret' - exact ⟨_, _, hret'⟩ - · have hc0 : UInt256.eq R ⟨1⟩ = ⟨0⟩ := by - show UInt256.fromBool (decide (R = ⟨1⟩)) = ⟨0⟩ - rw [decide_eq_false heq1]; rfl - have hret' := h.jumpdest (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.push1 ⟨3⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.gt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨2081⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) hbound (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.eq (by native_decide) (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.push2 ⟨2110⟩ (by native_decide) (by evm_ov) - |>.jumpiNT (by native_decide) hc0 (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.push1 ⟨2⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.push1 ⟨3⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.gt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨2108⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) hbound (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.eq (by native_decide) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap4 (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) hret (by evm_ov) - rw [show UInt256.eq R ⟨2⟩ = tlcIsOperationPendingBoolOf R from by - unfold tlcIsOperationPendingBoolOf; rw [if_neg heq1]] at hret' - exact ⟨_, _, hret'⟩ - -/-- The scratch after the `_getOperationState` mapping keccak (over the `onlyRole` read's scratch). -/ -noncomputable abbrev tlcCancelPendingMem (I : ExecutionEnv) : ByteArray := - twoWordHashMem (calldataWord I.calldata 4) ⟨1⟩ (tlcCancelHasRoleMem I) - -theorem tlcCancelHasRoleMem_size (I : ExecutionEnv) : (tlcCancelHasRoleMem I).size = 96 := - twoWordHashMem_size_96 _ _ (twoWordHashMem_size_96 _ _ solcFreePtrMem_size) - -/-- From the body @2912 (canceller role confirmed), call the inlined `isOperationPending` helper - `@2048 → _getOperationState @2232`, resolve the four state leaves, and reach the `if pending` - `JUMPI` @2921 with the bool word `_timestamps[id] > 1` on top. -/ -theorem tlcCancelReach2921 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2912⟩ - [tlcCancellerRoleWord, calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - (tlcCancelHasRoleMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2921⟩ - [tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ I), tlcCancellerRoleWord, - calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - (tlcCancelPendingMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - have hmem96 := tlcCancelHasRoleMem_size I - have hkec := evm_run h with [ - jumpdest, push2 ⟨2921⟩, dup3, push2 ⟨2048⟩, jump (by jump_dest), - jumpdest, push0, push0, push2 ⟨2059⟩, dup4, push2 ⟨2232⟩, jump (by jump_dest), - jumpdest, push0, dup2, dup2, - raw mstore 0 (wordAt0Mem (calldataWord I.calldata 4) (tlcCancelHasRoleMem I)) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨32⟩, - raw mstore 0 (twoWordHashMem (calldataWord I.calldata 4) ⟨1⟩ (tlcCancelHasRoleMem I)) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨64⟩, dup2, - raw keccak256 0 (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) (UInt256.ofNat 3) - (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact twoWordHashMem_solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4) hmem96) - (by native_decide) (by evm_ov) ] - obtain ⟨_, _, hsl⟩ := hkec.sload (by native_decide) (by evm_ov) - by_cases ht0 : tlcGetTimestampWord σ I = ⟨0⟩ - · have hcond : UInt256.sub ⟨0⟩ (tlcGetTimestampWord σ I) = (⟨0⟩ : UInt256) := by - rw [ht0]; exact u256_sub_self ⟨0⟩ - have h2059 := evm_run hsl with [ - dup1, push0, sub, push2 ⟨2261⟩, jumpiNT hcond, - pop, push0, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h2921⟩ := tlcCancelPendingTail h2059 (by decide) (by jump_dest) (by simp) - have hb : tlcIsOperationPendingBoolOf (⟨0⟩ : UInt256) - = tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationPendingBoolWord - rw [if_neg (show ¬ 1 < (tlcGetTimestampWord σ I).toNat by rw [ht0]; decide)] - decide - rw [hb] at h2921; exact ⟨_, _, h2921⟩ - · have hcond0 : UInt256.sub ⟨0⟩ (tlcGetTimestampWord σ I) ≠ (⟨0⟩ : UInt256) := - u256_zero_sub_ne_zero ht0 - have h2269 := evm_run hsl with [ - dup1, push0, sub, push2 ⟨2261⟩, jumpiT hcond0 (by jump_dest), - jumpdest, push1 ⟨1⟩, dup2, sub, push2 ⟨2278⟩ ] - by_cases ht1 : tlcGetTimestampWord σ I = ⟨1⟩ - · have hcond1 : UInt256.sub (tlcGetTimestampWord σ I) ⟨1⟩ = (⟨0⟩ : UInt256) := by - rw [ht1]; exact u256_sub_self ⟨1⟩ - have h2059 := evm_run h2269 with [ - jumpiNT hcond1, - pop, push1 ⟨3⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h2921⟩ := tlcCancelPendingTail h2059 (by decide) (by jump_dest) (by simp) - have hb : tlcIsOperationPendingBoolOf (⟨3⟩ : UInt256) - = tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationPendingBoolWord - rw [if_neg (show ¬ 1 < (tlcGetTimestampWord σ I).toNat by rw [ht1]; decide)] - decide - rw [hb] at h2921; exact ⟨_, _, h2921⟩ - · have hne1 : (tlcGetTimestampWord σ I).toNat ≠ 1 := - fun hh => ht1 (by apply u256_inj; simpa using hh) - have hne0 : (tlcGetTimestampWord σ I).toNat ≠ 0 := - fun hh => ht0 (by apply u256_inj; simpa using hh) - have h2gt : 1 < (tlcGetTimestampWord σ I).toNat := by omega - have hcond1 : UInt256.sub (tlcGetTimestampWord σ I) ⟨1⟩ ≠ (⟨0⟩ : UInt256) := - u256_sub_ne_zero_of_ne ht1 - have h2286 := evm_run h2269 with [ - jumpiT hcond1 (by jump_dest), - jumpdest, timestamp, dup2, gt, iszero, push2 ⟨2295⟩ ] - by_cases htgt : UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp) = ⟨0⟩ - · have hcondr : UInt256.isZero - (UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp)) ≠ (⟨0⟩ : UInt256) := by - rw [htgt]; decide - have h2059 := evm_run h2286 with [ - jumpiT hcondr (by jump_dest), - jumpdest, pop, push1 ⟨2⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h2921⟩ := tlcCancelPendingTail h2059 (by decide) (by jump_dest) (by simp) - have hb : tlcIsOperationPendingBoolOf (⟨2⟩ : UInt256) - = tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationPendingBoolWord; rw [if_pos h2gt]; decide - rw [hb] at h2921; exact ⟨_, _, h2921⟩ - · have hcondw : UInt256.isZero - (UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp)) = (⟨0⟩ : UInt256) := - isZero_eq_zero_of_ne htgt - have h2059 := evm_run h2286 with [ - jumpiNT hcondw, - pop, push1 ⟨1⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h2921⟩ := tlcCancelPendingTail h2059 (by decide) (by jump_dest) (by simp) - have hb : tlcIsOperationPendingBoolOf (⟨1⟩ : UInt256) - = tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationPendingBoolWord; rw [if_pos h2gt]; decide - rw [hb] at h2921; exact ⟨_, _, h2921⟩ - -/-! ## EVM: the pending branch — delete `_timestamps[id]` + `Cancelled` LOG2 + STOP -/ - -/-- The `Cancelled(bytes32)` event topic (the `PUSH32` at pc 3002). -/ -abbrev tlcCancelledTopic : UInt256 := - ⟨0xbaa1eb22f2a492ba1a5fea61b8df4d27c6c8b5f3971e63bb58fa14ff72eedb70⟩ - -theorem tlcCancelHasRoleMem_read64 (I : ExecutionEnv) : - (tlcCancelHasRoleMem I).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := - twoWordHashMem_read64 _ _ (twoWordHashMem_size_96 _ _ solcFreePtrMem_size) - (twoWordHashMem_read64 _ _ solcFreePtrMem_size solcFreePtrMem_read64) - -theorem tlcCancelPendingMem_size (I : ExecutionEnv) : (tlcCancelPendingMem I).size = 96 := - twoWordHashMem_size_96 _ _ (tlcCancelHasRoleMem_size I) - -theorem tlcCancelPendingMem_read64 (I : ExecutionEnv) : - (tlcCancelPendingMem I).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := - twoWordHashMem_read64 _ _ (tlcCancelHasRoleMem_size I) (tlcCancelHasRoleMem_read64 I) - -/-- Canceller role held and operation pending: delete `_timestamps[id]` (`SSTORE 0` at the mapping - slot `keccak(id ‖ 1)`), emit `Cancelled(id)` (`LOG2`), and `STOP` — halting with the account map - carrying the single timestamp-slot clear. -/ -theorem tlcCancelX_pending {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2912⟩ - [tlcCancellerRoleWord, calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - (tlcCancelHasRoleMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hperm : I.perm = true) - (hpending : ¬ tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ I) = ⟨0⟩) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) - (cA, sstoreAccountMap I.codeOwner σ (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) ⟨0⟩) - ByteArray.empty := by - obtain ⟨_, _, h2921⟩ := tlcCancelReach2921 h - have hsstorepre := evm_run h2921 with [ - jumpdest, push2 ⟨2981⟩, jumpiT hpending (by jump_dest), - jumpdest, push0, dup3, dup2, - raw mstore 0 (wordAt0Mem (calldataWord I.calldata 4) (tlcCancelPendingMem I)) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨32⟩, - raw mstore 0 (twoWordHashMem (calldataWord I.calldata 4) ⟨1⟩ (tlcCancelPendingMem I)) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨64⟩, dup1, dup3, - raw keccak256 0 (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) (UInt256.ofNat 3) - (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact twoWordHashMem_solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4) - (tlcCancelPendingMem_size I)) - (by native_decide) (by evm_ov), - dup3, swap1 ] - obtain ⟨_, _, hss⟩ := hsstorepre.sstore hperm (by native_decide) (by evm_ov) - have h476 := hss.mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [twoWordHashMem_size_96 _ _ (tlcCancelPendingMem_size I)]; decide) - (by decide) - (twoWordHashMem_read64 _ _ (tlcCancelPendingMem_size I) (tlcCancelPendingMem_read64 I))) - (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.pushConst tlcCancelledTopic (op := .PUSH32) (width := 32) (by decide) (by native_decide) - (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - have hlog := RD.log2 0 (UInt256.ofNat 3) h476 (by native_decide) hperm mem_cost (by native_decide) - (by evm_ov) - have hstop := hlog.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - exact hstop.stop (by native_decide) (by evm_ov) - -/-! ## EVM revert paths - - A custom-error revert (`@…→ dispatcher @2157`) `MSTORE`s the selector + args into the free-memory - region `[0x80, …)` then `REVERT`s. `RD.rev` ignores the memory contents; only the dispatcher's - `MLOAD 0x40` (still the free pointer `0x80`, preserved because every write is at offset ≥ 0x80) and - the resulting stack matter. These two facts capture that free-pointer preservation for a - three-word error region, generic in the (irrelevant) stored words. -/ - -theorem tlcCancelErrMem_read64 {mem : ByteArray} (hsz : mem.size = 96) - (hr64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (u1 u2 u3 : UInt256) : - (writeWord (writeWord (writeWord mem 128 u1) 132 u2) 164 u3).readWithPadding 64 32 - = UInt256.toByteArray ⟨128⟩ := by - have hwin : WindowDisjointFromWrites 96 64 32 [(128, u1), (132, u2), (164, u3)] := - ⟨lt_usize _ (by norm_num), Or.inl ⟨by omega, by omega⟩, - lt_usize _ (by norm_num), Or.inl ⟨by omega, by omega⟩, - lt_usize _ (by norm_num), Or.inl ⟨by omega, by omega⟩, trivial⟩ - have h := writeCascade_read_preserved_of_base mem [(128, u1), (132, u2), (164, u3)] hsz hwin - exact h.trans hr64 - -theorem tlcCancelErrMem_size {mem : ByteArray} (hsz : mem.size = 96) (u1 u2 u3 : UInt256) : - 64 < (writeWord (writeWord (writeWord mem 128 u1) 132 u2) 164 u3).size := by - have hgaps : WriteGapsOk 96 [(128, u1), (132, u2), (164, u3)] := - ⟨lt_usize _ (by norm_num), lt_usize _ (by norm_num), lt_usize _ (by norm_num), trivial⟩ - have h : (writeWord (writeWord (writeWord mem 128 u1) 132 u2) 164 u3).size = 196 := by - show (writeCascade mem [(128, u1), (132, u2), (164, u3)]).size = 196 - exact writeCascade_size_of_base mem _ hsz hgaps rfl - omega - -/-- `msg.sender` lacks the canceller role: the `_checkRole` `JUMPI` @3665 falls through, building the - `AccessControlUnauthorizedAccount(sender, role)` custom error into memory and reverting via the - revert dispatcher @2157. -/ -theorem tlcCancelOnlyRoleRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2870⟩ - [calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hnhas : UInt256.land ⟨255⟩ (tlcCancelRoleWord σ I) = ⟨0⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h3665⟩ := tlcCancelReach3665 h - have hb96 := tlcCancelHasRoleMem_size I - have hbr64 := tlcCancelHasRoleMem_read64 I - have hrev := evm_run h3665 with [ - jumpdest, push2 ⟨3712⟩, jumpiNT hnhas, - push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [hb96]; decide) (by decide) hbr64) (by native_decide) (by evm_ov), - raw push4 ⟨0xe2517d3f⟩ (by native_decide) (by evm_ov), - push1 ⟨224⟩, shl, dup2, - raw mstore 6 (writeWord (tlcCancelHasRoleMem I) 128 (UInt256.shiftLeft ⟨0xe2517d3f⟩ ⟨224⟩)) - (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, - push1 ⟨4⟩, dup3, add, - raw mstore 3 (writeWord (writeWord (tlcCancelHasRoleMem I) 128 (UInt256.shiftLeft ⟨0xe2517d3f⟩ ⟨224⟩)) - 132 (UInt256.land (tlcCancelCallerWord I) (UInt256.sub (UInt256.shiftLeft ⟨1⟩ ⟨160⟩) ⟨1⟩))) - (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨36⟩, dup2, add, dup4, swap1, - raw mstore 3 (writeWord (writeWord (writeWord (tlcCancelHasRoleMem I) 128 - (UInt256.shiftLeft ⟨0xe2517d3f⟩ ⟨224⟩)) - 132 (UInt256.land (tlcCancelCallerWord I) (UInt256.sub (UInt256.shiftLeft ⟨1⟩ ⟨160⟩) ⟨1⟩))) - 164 tlcCancellerRoleWord) - (UInt256.ofNat 7) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨68⟩, add, push2 ⟨2157⟩, jump (by jump_dest), - jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 7) (by native_decide) mem_cost - (mloadFreePtrValue (tlcCancelErrMem_size hb96 _ _ _) (by decide) - (tlcCancelErrMem_read64 hb96 hbr64 _ _ _)) (by native_decide) (by evm_ov), - dup1, swap2, sub, swap1 ] - exact hrev.rev 0 (by native_decide) mem_cost (by evm_ov) - -/-- `_encodeStateBitmap(state) @4201`: from `[state, ret] ++ R` (with `state ≤ 3`), return to `ret` - with `[1 << (state & 0xff)] ++ R`. -/ -theorem tlcCancelEncodeBitmap {cA gh bl σ σ₀ A I} {g : Sat256} {state ret : UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4201⟩ - (state :: ret :: R) mem aw ByteArray.empty (cA, σ) k C) - (hb : UInt256.gt state ⟨3⟩ = ⟨0⟩) - (hret : (D_J timelockControllerBenchBytecode 0).contains ret = true) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ret - (UInt256.shiftLeft ⟨1⟩ (UInt256.land ⟨255⟩ state) :: R) mem aw ByteArray.empty (cA, σ) k' C' := by - refine ⟨_, _, h.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.push1 ⟨3⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.gt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨4220⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) (by rw [hb]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨255⟩ (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.and (by native_decide) (by evm_ov) - |>.shl (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) hret (by evm_ov)⟩ - -/-- The operation is not pending: the `if pending` `JUMPI` @2921 falls through, building the - `TimelockUnexpectedOperationState(id, bitmap)` custom error (two `_encodeStateBitmap` calls - combined by `OR`) into memory and reverting via the revert dispatcher @2157. -/ -theorem tlcCancelPendingRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2912⟩ - [tlcCancellerRoleWord, calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - (tlcCancelHasRoleMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hnpending : tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ I) = ⟨0⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h2921⟩ := tlcCancelReach2921 h - have hp96 := tlcCancelPendingMem_size I - have hpr64 := tlcCancelPendingMem_read64 I - -- Fall through the `if pending` JUMPI to @2926, call `_encodeStateBitmap(2) @4201`. - have h2926 := h2921.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨2981⟩ (by native_decide) (by evm_ov) - |>.jumpiNT (by native_decide) hnpending (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.push2 ⟨2936⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨2⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4201⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - obtain ⟨_, _, h2936⟩ := tlcCancelEncodeBitmap h2926 (by decide) (by jump_dest) (by simp) - -- @2936: call `_encodeStateBitmap(1) @4201`. - have h2946pre := h2936.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨2946⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4201⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - obtain ⟨_, _, h2946⟩ := tlcCancelEncodeBitmap h2946pre (by decide) (by jump_dest) (by simp) - -- @2946: encode the error (3 writes at 0x80/0x84/0xa4) and revert via @2157. - have hrev := evm_run h2946 with [ - jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [hp96]; decide) (by decide) hpr64) (by native_decide) (by evm_ov), - raw push4 ⟨0x5ead8eb5⟩ (by native_decide) (by evm_ov), - push1 ⟨224⟩, shl, dup2, - raw mstore 6 (writeWord (tlcCancelPendingMem I) 128 (UInt256.shiftLeft ⟨0x5ead8eb5⟩ ⟨224⟩)) - (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨4⟩, dup2, add, swap4, swap1, swap4, - raw mstore 3 (writeWord (writeWord (tlcCancelPendingMem I) 128 (UInt256.shiftLeft ⟨0x5ead8eb5⟩ ⟨224⟩)) - 132 (calldataWord I.calldata 4)) (UInt256.ofNat 6) (by native_decide) mem_cost (by rfl) - (by native_decide) (by evm_ov), - lor, push1 ⟨36⟩, dup3, add, - raw mstore 3 (writeWord (writeWord (writeWord (tlcCancelPendingMem I) 128 - (UInt256.shiftLeft ⟨0x5ead8eb5⟩ ⟨224⟩)) 132 (calldataWord I.calldata 4)) 164 - (UInt256.lor (UInt256.shiftLeft ⟨1⟩ (UInt256.land ⟨255⟩ ⟨1⟩)) - (UInt256.shiftLeft ⟨1⟩ (UInt256.land ⟨255⟩ ⟨2⟩)))) (UInt256.ofNat 7) (by native_decide) - mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨68⟩, add, push2 ⟨2157⟩, jump (by jump_dest), - jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 7) (by native_decide) mem_cost - (mloadFreePtrValue (tlcCancelErrMem_size hp96 _ _ _) (by decide) - (tlcCancelErrMem_read64 hp96 hpr64 _ _ _)) (by native_decide) (by evm_ov), - dup1, swap2, sub, swap1 ] - exact hrev.rev 0 (by native_decide) mem_cost (by evm_ov) - -/-! ## ABI decode (a single `bytes32`, exactly like `getTimestamp`) -/ - -theorem tlcDecodeCancel_ok {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) : - decodeCalldataWithMode config.abiDecodeMode (cancelTransition.params.map Param.name) - (transitionSignature cancelTransition).paramTypes I.calldata = some (tlcGetTimestampStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = _ - exact decodeCalldata_bytes32_ok hsz36 hbig - -theorem tlcDecodeCancel_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 36) : - decodeCalldataWithMode config.abiDecodeMode (cancelTransition.params.map Param.name) - (transitionSignature cancelTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_short hsz4 hshort - -theorem tlcDecodeCancel_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (cancelTransition.params.map Param.name) - (transitionSignature cancelTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_huge hbig - -/-- EVM decode revert (mis-sized calldata): the `bytes32` decoder's `SLT` availability check fails, - falling into its `PUSH0 PUSH0 REVERT` stub. -/ -theorem tlcCancelDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 1)) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4714⟩ := tlcCancelReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact h4714.jumpiNT (by native_decide) (by rw [hslt]; decide) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-! ## Solm body -/ - -/-- The evaluated `CANCELLER_ROLE` mapping key (as `evalExpr?` of the `bytes32` literal produces it). -/ -def tlcCancelRoleKey : KeyValue := .fixedBytes bytes32Width - [ 0xfd, 0x64, 0x3c, 0x72, 0x71, 0x0c, 0x63, 0xc0, - 0x18, 0x02, 0x59, 0xab, 0xa6, 0xb2, 0xd0, 0x54, - 0x51, 0xe3, 0x59, 0x1a, 0x24, 0xe5, 0x8b, 0x62, - 0x23, 0x93, 0x78, 0x08, 0x57, 0x26, 0xf7, 0x83 ] - -theorem tlcCancelRoleKey_word : keyValueToWord tlcCancelRoleKey = tlcCancellerRoleWord := by - native_decide - -theorem tlcCancelSourceCanon (I : ExecutionEnv) : - (UInt256.ofNat I.source.val).toNat < EVM.addressModulus := by - have hlt : (I.source.val : ℕ) < EVM.addressModulus := I.source.isLt - rw [ulit_toNat' _ (Nat.lt_of_lt_of_le hlt (by native_decide))] - exact hlt - -/-- The runtime nested role slot equals the spec `roleHasRoleSlot`. -/ -theorem tlcCancelRoleSlot_eq (I : ExecutionEnv) : - roleHasRoleSlot tlcCancelRoleKey (.address I.source) = tlcCancelRoleSlot I := by - unfold roleHasRoleSlot roleDataSlot mapSlot tlcCancelRoleSlot solcMappingSlot - rw [keyValueToWord_address, tlcCancelRoleKey_word, - solcAddrMask_clean_left (tlcCancelSourceCanon I)] - -theorem tlcCancelStore_get_roles (I : ExecutionEnv) : - (tlcGetTimestampStore I).get? "_roles" = none := by - simp [tlcGetTimestampStore] - -/-- `wordToElem .bool (word & 0xff)` is `true` exactly when the caller holds the role. -/ -theorem tlcCancelWordToElem_present {σ : AccountMap} {I : ExecutionEnv} - (hp : ¬ UInt256.land ⟨255⟩ (tlcCancelRoleWord σ I) = ⟨0⟩) : - Solm.wordToElem .bool (UInt256.land (tlcCancelRoleWord σ I) ⟨255⟩) = .bool true := by - have hz : UInt256.land (tlcCancelRoleWord σ I) ⟨255⟩ ≠ ⟨0⟩ := by rw [u256_land_comm]; exact hp - by_cases hval : (UInt256.land (tlcCancelRoleWord σ I) ⟨255⟩).val = 0 - · exact absurd (u256_inj (congrArg Fin.val hval)) hz - · simp [Solm.wordToElem, hval] - -theorem tlcCancelWordToElem_absent {σ : AccountMap} {I : ExecutionEnv} - (ha : UInt256.land ⟨255⟩ (tlcCancelRoleWord σ I) = ⟨0⟩) : - Solm.wordToElem .bool (UInt256.land (tlcCancelRoleWord σ I) ⟨255⟩) = .bool false := by - have hz : UInt256.land (tlcCancelRoleWord σ I) ⟨255⟩ = ⟨0⟩ := by rw [u256_land_comm]; exact ha - simp [Solm.wordToElem, hz] - -/-- The `onlyRole(CANCELLER_ROLE)` storage read: `_roles[CANCELLER_ROLE].hasRole[msg.sender]`. -/ -theorem tlcCancelHasRoleEval {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? config { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) (hasRoleExpr cancellerRole sender) - = .ok (Solm.wordToElem .bool (UInt256.land (tlcCancelRoleWord σ I) ⟨255⟩)) := by - have hstore : Solm.EVM.storageLoad (initState cA gh bl σ σ₀ g A I) - (initState cA gh bl σ σ₀ g A I).executionEnv.codeOwner (tlcCancelRoleSlot I) - = tlcCancelRoleWord σ I := - codeOwnerStorageWord_initState (tlcCancelRoleSlot I) - refine evalExpr_storage_scalar_value (cfg := config) - (solm := { contract := contract, locals := tlcGetTimestampStore I }) - (slot := roleHasRoleRef cancellerRole sender) - (er := ({ base := "_roles", steps := [.mindex tlcCancelRoleKey, .field "hasRole", - .mindex (.address I.source)] } : EvaledStorageRef)) - (t := .bool) - (loc := boolLoc (roleHasRoleSlot tlcCancelRoleKey (.address I.source))) - (value := Solm.wordToElem .bool (UInt256.land (tlcCancelRoleWord σ I) ⟨255⟩)) ?_ ?_ ?_ ?_ ?_ - · simp only [roleHasRoleRef]; exact tlcCancelStore_get_roles I - · simp [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, roleHasRoleRef, cancellerRole, - fixedBytes32, sender, envValue, tlcCancelRoleKey, bytes32Width, valueToKey?, initState, - EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?] - · simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, roleDataSt, boolSt] - · rfl - · rw [tlcCancelRoleSlot_eq] - show storageLocLoad (initState cA gh bl σ σ₀ g A I) (boolOffset0Loc (tlcCancelRoleSlot I)) = _ - rw [storageLocLoad_bool_offset0, hstore] - -/-- The `isOperationPending(id)` guard reads `_timestamps[id]` and compares `> 1`. -/ -theorem tlcCancelPendingEval {cA gh bl σ σ₀ A I} {g : Sat256} (hsz36 : 36 ≤ I.calldata.size) : - evalExpr? config { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) (isOperationPendingExpr (.var "id")) - = .ok (.bool ((Int.ofNat (tlcGetTimestampWord σ I).toNat : Int) > 1)) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hvk : valueToKey? (Value.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32)) - = some (tlcGetTimestampKey I) := by - simp [valueToKey?, tlcGetTimestampKey, abiBytes32Width, hlen] - have hslot : timestampSlot (tlcGetTimestampKey I) - = solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4) := by - unfold timestampSlot mapSlot solcMappingSlot - rw [tlcGetTimestampKey_eq I hsz36] - have hstore : evalExpr? config { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) (timestampExpr (.var "id")) - = .ok (.int (Int.ofNat (tlcGetTimestampWord σ I).toNat)) := by - unfold timestampExpr - rw [evalExpr_storage_scalar (cfg := config) - (solm := { contract := contract, locals := tlcGetTimestampStore I }) - (slot := timestampRef (.var "id")) - (er := ({ base := "_timestamps", steps := [.mindex (tlcGetTimestampKey I)] } : EvaledStorageRef)) - (t := .int uint256Int) (loc := uint256Loc (timestampSlot (tlcGetTimestampKey I))) - (hbase := by simp [timestampRef]) - (her := by - simp [evalStorageRef, evalStorageRefStep, timestampRef, tlcGetTimestampStore, - EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?, hvk]) - (hty := by - simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, tlcGetTimestampKey, uint256St]) - (hloc := by rfl)] - rw [hslot] - exact congrArg EvalResult.ok - (storageLocLoad_uint256 (initState cA gh bl σ σ₀ g A I) - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4))) - unfold isOperationPendingExpr doneTimestamp - simp only [evalExpr?, hstore, EvalResult.bind, bind, evalBinaryOp?, pure] - -/-- The `delete _timestamps[id]` statement clears the mapping slot to `0`. -/ -theorem tlcCancelDelete {cA gh bl σ σ₀ A I} {g : Sat256} (hsz36 : 36 ≤ I.calldata.size) : - deleteStorage? config { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) (timestampRef (.var "id")) - = .ok (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) - (initState cA gh bl σ σ₀ g A I).executionEnv.codeOwner - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) ⟨0⟩) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hvk : valueToKey? (Value.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32)) - = some (tlcGetTimestampKey I) := by - simp [valueToKey?, tlcGetTimestampKey, abiBytes32Width, hlen] - have hslot : timestampSlot (tlcGetTimestampKey I) - = solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4) := by - unfold timestampSlot mapSlot solcMappingSlot - rw [tlcGetTimestampKey_eq I hsz36] - have hlayout : config.storage.layout - { base := "_timestamps", steps := [.mindex (tlcGetTimestampKey I)] } - (initState cA gh bl σ σ₀ g A I) - = some (uint256Loc (timestampSlot (tlcGetTimestampKey I))) := rfl - unfold deleteStorage? - rw [resolveStorageRef?_ok (cfg := config) - (slot := timestampRef (.var "id")) - (er := ({ base := "_timestamps", steps := [.mindex (tlcGetTimestampKey I)] } : EvaledStorageRef)) - (ty := uint256St) - (hbase := by simp [timestampRef]) - (her := by - simp [evalStorageRef, evalStorageRefStep, timestampRef, tlcGetTimestampStore, - EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?, hvk]) - (hty := by - simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, tlcGetTimestampKey, uint256St])] - simp only [EvalResult.bind, bind, clearStorage?, uint256St, hlayout, hslot] - rw [show (0 : Int) = Int.ofNat (⟨0⟩ : UInt256).toNat from rfl] - exact congrArg (EvalResult.ofOption EvalError.storageError) - (storageLocStore_uint256 (initState cA gh bl σ σ₀ g A I) - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) ⟨0⟩) - -/-- Bridge: the EVM bool word is nonzero exactly when the timestamp exceeds `1` (pending). -/ -theorem tlcCancelPendingWord_pos {t : UInt256} (h : ¬ tlcIsOperationPendingBoolWord t = ⟨0⟩) : - 1 < t.toNat := by - by_contra hc - exact h (by unfold tlcIsOperationPendingBoolWord; rw [if_neg hc]) - -theorem tlcCancelPendingWord_zero {t : UInt256} (h : tlcIsOperationPendingBoolWord t = ⟨0⟩) : - ¬ 1 < t.toNat := by - intro hc - rw [show tlcIsOperationPendingBoolWord t = ⟨1⟩ from by - unfold tlcIsOperationPendingBoolWord; rw [if_pos hc]] at h - exact absurd h (by decide) - -/-- The Solm `isOperationPending(id)` guard is `true` when the timestamp exceeds `1`. -/ -theorem tlcCancelPendingEvalTrue {cA gh bl σ σ₀ A I} {g : Sat256} (hsz36 : 36 ≤ I.calldata.size) - (h : 1 < (tlcGetTimestampWord σ I).toNat) : - evalExpr? config { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) (isOperationPendingExpr (.var "id")) = .ok (.bool true) := by - rw [tlcCancelPendingEval hsz36] - exact congrArg (fun b => EvalResult.ok (Value.bool b)) - (decide_eq_true_eq.mpr (Int.ofNat_lt.mpr h)) - -theorem tlcCancelPendingEvalFalse {cA gh bl σ σ₀ A I} {g : Sat256} (hsz36 : 36 ≤ I.calldata.size) - (h : ¬ 1 < (tlcGetTimestampWord σ I).toNat) : - evalExpr? config { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) (isOperationPendingExpr (.var "id")) = .ok (.bool false) := by - rw [tlcCancelPendingEval hsz36] - exact congrArg (fun b => EvalResult.ok (Value.bool b)) - (decide_eq_false (fun hc => h (Int.ofNat_lt.mp hc))) - -/-- Happy path: `require`s pass, the `delete` clears `_timestamps[id]`, and the body falls through. -/ -theorem tlcCancelBodyPending {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hhas : ¬ UInt256.land ⟨255⟩ (tlcCancelRoleWord σ I) = ⟨0⟩) - (hpend : 1 < (tlcGetTimestampWord σ I).toNat) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcGetTimestampStore I) - cancelTransition.body - (.returned { contract := contract, locals := tlcGetTimestampStore I } - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) - (initState cA gh bl σ σ₀ g A I).executionEnv.codeOwner - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) ⟨0⟩) none) := by - refine ExecFuncBody.execBlockOK ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true - (by simp only [initState]; exact hwv))) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue ?_) ?_ - · rw [tlcCancelHasRoleEval, tlcCancelWordToElem_present hhas] - refine ExecBlock.consNormal (ExecStmt.requireTrue (tlcCancelPendingEvalTrue hsz36 hpend)) ?_ - exact ExecBlock.consNormal (ExecStmt.delete (tlcCancelDelete hsz36)) ExecBlock.nil - -/-- Caller lacks the role: the body reverts at the `onlyRole` `require`. -/ -theorem tlcCancelBodyRevertRole {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hnhas : UInt256.land ⟨255⟩ (tlcCancelRoleWord σ I) = ⟨0⟩) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcGetTimestampStore I) - cancelTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true - (by simp only [initState]; exact hwv))) ?_ - exact ExecBlock.consRevert (ExecStmt.requireFalse - (by rw [tlcCancelHasRoleEval, tlcCancelWordToElem_absent hnhas])) - -/-- Operation not pending: the body reverts at the `isOperationPending` `require`. -/ -theorem tlcCancelBodyRevertPending {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hhas : ¬ UInt256.land ⟨255⟩ (tlcCancelRoleWord σ I) = ⟨0⟩) - (hnpend : ¬ 1 < (tlcGetTimestampWord σ I).toNat) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcGetTimestampStore I) - cancelTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true - (by simp only [initState]; exact hwv))) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue ?_) ?_ - · rw [tlcCancelHasRoleEval, tlcCancelWordToElem_present hhas] - exact ExecBlock.consRevert (ExecStmt.requireFalse (tlcCancelPendingEvalFalse hsz36 hnpend)) - -/-! ## Refinement -/ - -/-- Refinement of `Cancel` (selector index 1). -/ -theorem tlcCancelBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 1)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 1) (by native_decide) hsel - have hroleword : tlcCancelRoleWord σ_evm I = tlcCancelRoleWord σ_solm I := by - simp only [tlcCancelRoleWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner (tlcCancelRoleSlot I) ⟨0⟩ - have htsword : tlcGetTimestampWord σ_evm I = tlcGetTimestampWord σ_solm I := by - simp only [tlcGetTimestampWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) ⟨0⟩ - have henc : returnEquiv ByteArray.empty none cancelTransition.returnType := by - simpa [cancelTransition] using - (returnEquiv.fallthrough (o := ByteArray.empty) (r := none) (t := []) - (dvs := []) rfl (by native_decide) (by native_decide)) - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz36 : 36 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · obtain ⟨_, _, h2870⟩ := tlcCancelReach2870 (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz36 hbig hsize hsel - by_cases hhas : UInt256.land ⟨255⟩ (tlcCancelRoleWord σ_evm I) = ⟨0⟩ - · -- caller lacks the role: both revert - exact tlcReEquivExecRev hcode (tlcCancelOnlyRoleRevert h2870 hhas) - (tlcSelectorDispatchCancel hsel) (tlcDecodeCancel_ok hsz36 hbig) - (tlcCancelBodyRevertRole (σ := σ_solm) hwv (by rw [← hroleword]; exact hhas)) - · -- caller has the role: reach the body @2912 - obtain ⟨_, _, h2912⟩ := tlcCancelReach2912 h2870 hhas - by_cases hpend : tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ_evm I) = ⟨0⟩ - · -- not pending: both revert - exact tlcReEquivExecRev hcode (tlcCancelPendingRevert h2912 hpend) - (tlcSelectorDispatchCancel hsel) (tlcDecodeCancel_ok hsz36 hbig) - (tlcCancelBodyRevertPending (σ := σ_solm) hwv hsz36 (by rw [← hroleword]; exact hhas) - (by rw [← htsword]; exact tlcCancelPendingWord_zero hpend)) - · -- pending: both delete `_timestamps[id]` - refine tlcReEquivExecGen hcode (tlcCancelX_pending h2912 _hperm hpend) - (tlcSelectorDispatchCancel hsel) (tlcDecodeCancel_ok hsz36 hbig) - (tlcCancelBodyPending (σ := σ_solm) hwv hsz36 (by rw [← hroleword]; exact hhas) - (by rw [← htsword]; exact tlcCancelPendingWord_pos hpend)) - (by simp [initState, storageStore_createdAccounts]) ?_ henc - simpa [initState, storageStore_accountMap] using - accountMapEquiv_sstoreAccountMap I.codeOwner - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) ⟨0⟩ hAccounts - · -- huge calldata: EVM reverts at the length check, Solm decode fails - have hhuge : 2 ^ 255 + 4 ≤ I.calldata.size := Nat.not_lt.mp hbig - exact tlcReEquivDecodeFailed hcode - (tlcCancelDecodeRevert (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckHuge_4_32 hhuge hsize)) - (tlcSelectorDispatchCancel hsel) (tlcDecodeCancel_none_huge hhuge) - · -- short calldata: EVM reverts at the length check, Solm decode fails - have hshort : I.calldata.size < 36 := by omega - exact tlcReEquivDecodeFailed hcode - (tlcCancelDecodeRevert (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckShort_4_32 hsz hshort hsize)) - (tlcSelectorDispatchCancel hsel) (tlcDecodeCancel_none_short hsz hshort) - · -- nonpayable guard: callvalue ≠ 0 - obtain ⟨_, _, h1276⟩ := tlcReachCancel (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨1287⟩) h1276 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchCancel hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/CancellerRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/CancellerRole.lean deleted file mode 100644 index b113943d..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/CancellerRole.lean +++ /dev/null @@ -1,102 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Return -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `CANCELLER_ROLE()` refinement - -`CANCELLER_ROLE` is a public non-payable `bytes32` constant getter (selector index 0, dispatch group -G147 arm 2, body pc 1151). It returns `keccak256("CANCELLER_ROLE")`. Copied from the -`PROPOSER_ROLE` template. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- `keccak256("CANCELLER_ROLE")` as an EVM word (the `PUSH32` constant at pc 1164). -/ -def tlcCancellerRoleWord : UInt256 := - ⟨0xfd643c72710c63c0180259aba6b2d05451e3591a24e58b62239378085726f783⟩ - -theorem tlcDecodeCancellerRole {I : ExecutionEnv} (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (cancellerRoleTransition.params.map Param.name) - (transitionSignature cancellerRoleTransition).paramTypes I.calldata = some ∅ := by - show decodeCalldataWithMode config.abiDecodeMode [] [] I.calldata = some (∅ : Store) - exact decodeCalldataWithMode_empty_ok hsz - -/-- Reach the `CANCELLER_ROLE` body pc 1151 (G147 arm 2). -/ -theorem tlcReachCancellerRole {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 0)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1151⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0xb08e51c0⟩ := - solcSelectorWord_eq_of_beq I hsz 0xb0 0x8e 0x51 0xc0 ⟨0xb08e51c0⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG147Body 2 (by omega) ⟨1151⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j <;> (rw [hsw]; native_decide)) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- EVM: with zero callvalue, `CANCELLER_ROLE()` returns the 32-byte role hash. -/ -theorem tlcCancellerRoleX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 0)) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray tlcCancellerRoleWord) := by - obtain ⟨_, _, h1151⟩ := tlcReachCancellerRole (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h1164⟩ := tlcGuardPeelOk (gt := ⟨1162⟩) h1151 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - have h581 := h1164.push2 ⟨581⟩ (by native_decide) (by simp) - |>.pushConst tlcCancellerRoleWord (op := .PUSH32) (width := 32) (by decide) - (by native_decide) (by simp) - |>.dup2 (by native_decide) (by simp) - |>.jump (by native_decide) (by jump_dest) (by simp) - exact tlcReturnWord h581 (by simp) - -/-- The Solm `CANCELLER_ROLE()` body returns the constant `bytes32`. -/ -theorem tlcCancellerRoleBodyReturns (evm : EVM.State) (locals : Store) - (h : evm.executionEnv.weiValue = ⟨0⟩) : - ExecTransitionBody config contract evm locals cancellerRoleTransition.body - (.returned { contract := contract, locals := locals } evm - (some [(.fixedBytes bytes32Width (EVM.Word.toBytesBE tlcCancellerRoleWord))])) := by - have hbody : cancellerRoleTransition.body = - [ Stmt.require (.binary .eq (.env .callvalue) (.intLit 0)), - Stmt.return [Expr.fixedBytesLit bytes32Width (EVM.Word.toBytesBE tlcCancellerRoleWord)] ] := by - native_decide - rw [hbody] - exact nonpayableFixedBytesLiteralBodyReturns (cfg := config) (contract := contract) - evm locals bytes32Width (EVM.Word.toBytesBE tlcCancellerRoleWord) h - -/-- Refinement of `CancellerRole` (selector index 0). -/ -theorem tlcCancellerRoleBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 0)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 0) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · exact tlcReEquivExecTransport hcode - (tlcCancellerRoleX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel) - (tlcSelectorDispatchCancellerRole hsel) (tlcDecodeCancellerRole hsz) - (tlcCancellerRoleBodyReturns (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) ∅ - (by simp only [initState]; exact hwv)) - rfl hAccounts - (returnEquiv_of_encode (bytes32ReturnEncoding tlcCancellerRoleWord)) - · obtain ⟨_, _, h1151⟩ := tlcReachCancellerRole (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨1162⟩) h1151 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchCancellerRole hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Constructor.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Constructor.lean deleted file mode 100644 index 288e7826..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Constructor.lean +++ /dev/null @@ -1,52 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.ConstructorEvm -import Benchmarks.OpenZeppelinBench.TimelockController.ConstructorSolm - -/-! -# OpenZeppelin TimelockController constructor correctness - -The optimized creation bytecode deploys the concrete payable wrapper with initial delay `1 days`, -`msg.sender` as admin/proposer/canceller, and `address(0)` as open executor. The proof assembles the -EVM creation trace (`tlcCtorInitcodeSuccess`) and the Solm constructor execution -(`tlcCtorSolmExecSuccess`) through the constructor-equivalence bridge, reconciling the two final -account maps with `tlcCtorFinalMap_reconcile`. The constructor is payable, so there is no -callvalue-revert path. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -namespace OpenZeppelinBench.TimelockController - -set_option maxRecDepth 2000000 - -set_option maxHeartbeats 1000000 in -theorem timelockControllerBenchConstructorCorrect : - constructorEquivalence config timelockControllerBenchCreationBytecode contract - timelockControllerBenchBytecode := by - refine constructorEquivalence.intro ?_ - intro cA gh bl σ_evm σ_solm σ₀ g A I args deployedInitcode hdeploy hcode hcalldata hperm hσ - have hdeployed := emptyCtorDeployment_eq_initcode tlc_selfDeployment_eq tlc_ctor_params_nil hdeploy - rw [hdeployed] at hcode - obtain rfl : args = [] := by - have := emptyCtorDeployment_args_length tlc_selfDeployment_eq tlc_ctor_params_nil hdeploy - rw [tlc_ctor_params_nil] at this - exact List.eq_nil_of_length_eq_zero this - have hrd := tlcCtorInitcodeSuccess (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hperm hcalldata - rcases hrd with hoog | ⟨s, hX, hacc⟩ - · exact constructorEquivalenceFor.outOfGas (Xi_error_of_X (g := g) (by - rw [← hcode] at hoog; simpa [Sat256.ofUInt256] using hoog)) - · have hsuccess := Xi_success_of_X (g := g) (by - rw [← hcode] at hX; simpa [Sat256.ofUInt256] using hX) - have hcA : s.createdAccounts = cA := congrArg Prod.fst hacc - have hσ' : s.accountMap = tlcCtorFinalMap I σ_evm := congrArg Prod.snd hacc - rw [hcA, hσ'] at hsuccess - obtain ⟨frame, S, hexec, hScA, hSmap⟩ := - tlcCtorSolmExecSuccess (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := g) - refine constructorEquivalenceFor.execution hsuccess hexec ?_ - refine ctorResultEquiv.success rfl rfl ?_ ?_ rfl - · exact hScA.symm - · rw [hSmap] - exact tlcCtorFinalMap_reconcile I hσ - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorDefs.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorDefs.lean deleted file mode 100644 index ddb96b88..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorDefs.lean +++ /dev/null @@ -1,142 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.GrantRole -import Benchmarks.OpenZeppelinBench.TimelockController.ProposerRole -import Benchmarks.OpenZeppelinBench.TimelockController.CancellerRole -import Benchmarks.OpenZeppelinBench.TimelockController.ExecutorRole -import Benchmarks.OpenZeppelinBench.TimelockController.DefaultAdminRole -import Reasoning.Initcode -import Reasoning.Constructor -import Solm.Equiv - -/-! -# OpenZeppelin TimelockController constructor — shared definitions - -The payable constructor grants five role bits, writes `_minDelay = 1 days` (slot 2), and deploys the -runtime. Because the initial storage is arbitrary (only `accountMapEquiv`-coupled), each `_grantRole` -call is a *conditional* nested-mapping bool write: `if (word & 0xff == 0) then set the low byte to 1`. -The `tlcCtorGrantMap` operator captures that single step uniformly on `AccountMap`s; both the EVM and -Solm sides reach a tower of these, so reconciliation just threads `accountMapEquiv` through it. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Creation-bytecode size and runtime window -/ - -theorem tlcCreation_size : timelockControllerBenchCreationBytecode.size = 7161 := by native_decide - -theorem tlcRuntime_size : timelockControllerBenchBytecode.size = 6509 := by native_decide - -/-- The runtime window `CODECOPY`'d + `RETURN`'d by the creation code (`PUSH2 6509 DUP1 PUSH2 652`: - offset `652`, length `6509`) is exactly the deployed runtime. -/ -theorem tlcCreation_runtime_window : - timelockControllerBenchCreationBytecode.extract 652 (652 + 6509) - = timelockControllerBenchBytecode := by native_decide - -/-! ## Deployment shape (empty constructor, payable) -/ - -theorem tlc_selfDeployment_eq : - config.selfDeployment = genSolidityConstructorDeployment contract.ctor.params := rfl - -theorem tlc_ctor_params_nil : contract.ctor.params = [] := rfl - -/-! ## Role / account words and the five nested-mapping slots -/ - -/-- Account word for `address(this)` (the `ADDRESS` opcode pushes `codeOwner.val`). -/ -abbrev tlcThisWord (I : ExecutionEnv) : UInt256 := UInt256.ofNat I.codeOwner.val - -/-- `_roles[role].hasRole[account]` slot as the constructor helper computes it (base slot 0). -/ -def tlcCtorSlot (role account : UInt256) : UInt256 := - solcMappingSlot (solcMappingSlot ⟨0⟩ role) account - -def tlcSlotAdminThis (I : ExecutionEnv) : UInt256 := - tlcCtorSlot tlcDefaultAdminRoleWord (tlcThisWord I) - -def tlcSlotAdminSender (I : ExecutionEnv) : UInt256 := - tlcCtorSlot tlcDefaultAdminRoleWord (solcSourceWord I) - -def tlcSlotPropSender (I : ExecutionEnv) : UInt256 := - tlcCtorSlot tlcProposerRoleWord (solcSourceWord I) - -def tlcSlotCancSender (I : ExecutionEnv) : UInt256 := - tlcCtorSlot tlcCancellerRoleWord (solcSourceWord I) - -def tlcSlotExecZero (I : ExecutionEnv) : UInt256 := - tlcCtorSlot tlcExecutorRoleWord ⟨0⟩ - -/-! ## The single-grant map operator and the final constructor map -/ - -/-- One `_grantRole(role, account)` write on the raw account map: if the low byte of the current slot - word is `0` (role absent), set it to `1`; otherwise leave the map unchanged. The stored value - `lor (land w ~0xff) 1` is the solc read-modify-write and equals the Solm `storageStore` of a bool - `true` at offset `0` (`storageLocStore_bool_true_offset0`). -/ -def tlcCtorGrantMap (cO : AccountAddress) (slot : UInt256) (σ : AccountMap) : AccountMap := - if UInt256.land ⟨255⟩ (σ.find? cO |>.option ⟨0⟩ (fun ac => ac.storage.findD slot ⟨0⟩)) = ⟨0⟩ then - sstoreAccountMap cO σ slot - (UInt256.lor - (UInt256.land (σ.find? cO |>.option ⟨0⟩ (fun ac => ac.storage.findD slot ⟨0⟩)) - (UInt256.lnot ⟨255⟩)) ⟨1⟩) - else σ - -/-- Grants 1-2 (admin→this, then admin→sender guarded by `sender ≠ 0`). -/ -def tlcCtorAdminMap (I : ExecutionEnv) (σ : AccountMap) : AccountMap := - if solcSourceWord I = ⟨0⟩ then - tlcCtorGrantMap I.codeOwner (tlcSlotAdminThis I) σ - else - tlcCtorGrantMap I.codeOwner (tlcSlotAdminSender I) - (tlcCtorGrantMap I.codeOwner (tlcSlotAdminThis I) σ) - -/-- The full constructor post-state map: five conditional grants then `_minDelay = 86400` (slot 2). -/ -def tlcCtorFinalMap (I : ExecutionEnv) (σ : AccountMap) : AccountMap := - sstoreAccountMap I.codeOwner - (tlcCtorGrantMap I.codeOwner (tlcSlotExecZero I) - (tlcCtorGrantMap I.codeOwner (tlcSlotCancSender I) - (tlcCtorGrantMap I.codeOwner (tlcSlotPropSender I) - (tlcCtorAdminMap I σ)))) - ⟨2⟩ ⟨86400⟩ - -/-! ## Reconciliation: `accountMapEquiv` is preserved by every step -/ - -theorem tlcCtorGrantMap_reconcile {σ_evm σ_solm : AccountMap} (cO : AccountAddress) (slot : UInt256) - (hAcc : accountMapEquiv σ_evm σ_solm) : - accountMapEquiv (tlcCtorGrantMap cO slot σ_evm) (tlcCtorGrantMap cO slot σ_solm) := by - have hword : (σ_evm.find? cO |>.option ⟨0⟩ (fun ac => ac.storage.findD slot ⟨0⟩)) = - (σ_solm.find? cO |>.option ⟨0⟩ (fun ac => ac.storage.findD slot ⟨0⟩)) := - accountMapEquiv_storage_findD hAcc cO slot ⟨0⟩ - unfold tlcCtorGrantMap - rw [hword] - split - · exact accountMapEquiv_sstoreAccountMap cO slot _ hAcc - · exact hAcc - -theorem tlcCtorAdminMap_reconcile {σ_evm σ_solm : AccountMap} (I : ExecutionEnv) - (hAcc : accountMapEquiv σ_evm σ_solm) : - accountMapEquiv (tlcCtorAdminMap I σ_evm) (tlcCtorAdminMap I σ_solm) := by - unfold tlcCtorAdminMap - split - · exact tlcCtorGrantMap_reconcile _ _ hAcc - · exact tlcCtorGrantMap_reconcile _ _ (tlcCtorGrantMap_reconcile _ _ hAcc) - -theorem tlcCtorFinalMap_reconcile {σ_evm σ_solm : AccountMap} (I : ExecutionEnv) - (hAcc : accountMapEquiv σ_evm σ_solm) : - accountMapEquiv (tlcCtorFinalMap I σ_evm) (tlcCtorFinalMap I σ_solm) := by - unfold tlcCtorFinalMap - exact accountMapEquiv_sstoreAccountMap _ _ _ - (tlcCtorGrantMap_reconcile _ _ - (tlcCtorGrantMap_reconcile _ _ - (tlcCtorGrantMap_reconcile _ _ - (tlcCtorAdminMap_reconcile I hAcc)))) - -/-! ## Spec-slot identity: `roleHasRoleSlot` in `solcMappingSlot` form -/ - -/-- The spec nested-mapping slot equals the solc keccak form used by the EVM helper. -/ -theorem roleHasRoleSlot_solcForm (roleKV accountKV : KeyValue) : - roleHasRoleSlot roleKV accountKV - = solcMappingSlot (solcMappingSlot ⟨0⟩ (keyValueToWord roleKV)) (keyValueToWord accountKV) := by - unfold roleHasRoleSlot roleDataSlot mapSlot solcMappingSlot - rfl - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorEvm.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorEvm.lean deleted file mode 100644 index 05e6d821..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorEvm.lean +++ /dev/null @@ -1,167 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.ConstructorDefs - -/-! -# OpenZeppelin TimelockController constructor — EVM creation-bytecode trace - -`tlcCtorInitcodeSuccess` : the payable creation bytecode halts returning the runtime, having applied -the five conditional `_grantRole` writes and `_minDelay = 86400` — i.e. the account map becomes -`tlcCtorFinalMap I σ`. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 4000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Section 0 — generic scratch-memory read lemmas - -The two subroutines (`_singleton @360`, `_grantRole @450`) write to the solc scratch region -`mem[0 .. 0x40]` before hashing; `twoWordHashMem key slot M` is exactly those two `MSTORE`s -(`key` at `mem[0]`, `slot` at `mem[0x20]`) over a base memory `M`. Unlike the runtime proofs, the -constructor's `M` is not exactly 96 bytes (the singletons grow it), so we re-derive the read-backs -for an arbitrary base of size `≥ 64`. -/ - -theorem tlcCtorEvmWordAt0_size {M : ByteArray} (key : UInt256) (hM : 32 ≤ M.size) : - (wordAt0Mem key M).size = M.size := by - unfold wordAt0Mem - rw [write32_eq _ _ _ (by rw [toByteArray_size]) (by omega), - ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, toByteArray_size] - omega - -theorem tlcCtorEvmScratch_size {M : ByteArray} (key slot : UInt256) (hM : 64 ≤ M.size) : - (twoWordHashMem key slot M).size = M.size := by - unfold twoWordHashMem wordAt32Mem - rw [write32_eq _ _ _ (by rw [toByteArray_size]) - (by rw [tlcCtorEvmWordAt0_size key (by omega)]; omega), - ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, tlcCtorEvmWordAt0_size key (by omega), - toByteArray_size] - omega - -/-- The `KECCAK256(0, 0x40)` preimage after the two scratch stores is `key ‖ slot`. -/ -theorem tlcCtorEvmScratch_read64 {M : ByteArray} (key slot : UInt256) (hM : 64 ≤ M.size) : - (twoWordHashMem key slot M).readWithPadding 0 64 = key.toByteArray ++ slot.toByteArray := by - have hw0 : 32 ≤ (wordAt0Mem key M).size := by rw [tlcCtorEvmWordAt0_size key (by omega)]; omega - rw [readWithPadding_eq_extract' _ 0 64 (by norm_num) (by norm_num) - (by rw [tlcCtorEvmScratch_size key slot hM]; omega)] - have hleft : (twoWordHashMem key slot M).extract 0 32 = key.toByteArray := by - rw [← readWithPadding_eq_extract _ 0 (by rw [tlcCtorEvmScratch_size key slot hM]; omega)] - unfold twoWordHashMem wordAt32Mem - rw [write32_read_below _ _ 32 0 (by rw [toByteArray_size]) hw0 (by omega)] - unfold wordAt0Mem - rw [write32_read_back _ _ 0 (by rw [toByteArray_size]) (by omega), toByteArray_extract_all] - have hright : (twoWordHashMem key slot M).extract 32 64 = slot.toByteArray := by - rw [← readWithPadding_eq_extract _ 32 (by rw [tlcCtorEvmScratch_size key slot hM]; omega)] - unfold twoWordHashMem wordAt32Mem - rw [write32_read_back _ _ 32 (by rw [toByteArray_size]) hw0, toByteArray_extract_all] - rw [show (twoWordHashMem key slot M).extract 0 64 = - (twoWordHashMem key slot M).extract 0 32 ++ (twoWordHashMem key slot M).extract 32 64 by - rw [ByteArray.extract_append_extract]; norm_num, hleft, hright] - -/-- The `KECCAK256` slot value produced by the scratch stores is `solcMappingSlot slot key`. -/ -theorem tlcCtorEvmScratch_keccak {M : ByteArray} (key slot : UInt256) (hM : 64 ≤ M.size) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((twoWordHashMem key slot M).readWithPadding 0 64))) = - solcMappingSlot slot key := by - rw [tlcCtorEvmScratch_read64 key slot hM] - unfold solcMappingSlot - exact mappingSlot_single key slot - -/-- Scratch stores at `mem[0..0x40]` do not disturb a 32-byte read at any offset `≥ 64`. -/ -theorem tlcCtorEvmScratch_read_above {M : ByteArray} (key slot : UInt256) (r : ℕ) - (hr : 64 ≤ r) (hin : r + 32 ≤ M.size) : - (twoWordHashMem key slot M).readWithPadding r 32 = M.readWithPadding r 32 := by - have hw0 : 32 ≤ (wordAt0Mem key M).size := by rw [tlcCtorEvmWordAt0_size key (by omega)]; omega - unfold twoWordHashMem wordAt32Mem - rw [write32_read_above _ _ 32 r (by rw [toByteArray_size]) hw0 (by omega) - (by rw [tlcCtorEvmWordAt0_size key (by omega)]; omega)] - unfold wordAt0Mem - rw [write32_read_above _ _ 0 r (by rw [toByteArray_size]) (by omega) (by omega) hin] - -/-! ## Section 0b — memory-cost / active-word helpers - -Every scratch/free-ptr memory access in `_grantRole` lands inside already-active memory (or has size -`0`), so its `memoryExpansionCost` is `0` and it leaves `activeWords` unchanged. These let the grant -combinator run over a *symbolic* `aw` (only a lower bound is needed). -/ - -theorem tlcCtorEvmM_within (aw : UInt256) (off len : ℕ) (h : off + len ≤ 32 * aw.toNat) : - MachineState.M aw.toNat off len = aw.toNat := by - unfold MachineState.M; split - · rfl - · rw [Nat.max_eq_left]; omega - -theorem tlcCtorEvmAwOut (aw : UInt256) (off len : ℕ) (h : off + len ≤ 32 * aw.toNat) : - UInt256.ofNat (MachineState.M aw.toNat off len) = aw := by - rw [tlcCtorEvmM_within aw off len h]; exact u256_ofNat_toNat aw - -theorem tlcCtorEvmM_len0 (aw : UInt256) (off : ℕ) : - MachineState.M aw.toNat off 0 = aw.toNat := rfl - -theorem tlcCtorEvmAwOut0 (aw : UInt256) (off : ℕ) : - UInt256.ofNat (MachineState.M aw.toNat off 0) = aw := by - rw [tlcCtorEvmM_len0]; exact u256_ofNat_toNat aw - -/-- Empty-source `CALLDATACOPY` (empty calldata) writing at or past the end of memory is a no-op. -/ -theorem tlcCtorEvmEmptyWrite_noop (base : ByteArray) (dest len : ℕ) (h : base.size ≤ dest) : - ByteArray.empty.write 0 base dest len = base := by - unfold ByteArray.write - by_cases hl : len = 0 - · simp only [hl, if_pos] - · rw [if_neg hl, if_pos (show (0:ℕ) ≥ ByteArray.empty.size by rw [ByteArray.size_empty])] - rw [show min len (base.size - dest) = 0 by omega, show min dest base.size = base.size by omega] - apply ByteArray.ext - have hb : base.data.size = base.size := rfl - rw [ByteArray.data_copySlice, Array.extract_eq_self_of_le (le_of_eq hb), - Array.extract_eq_empty_of_le - (by omega : min 0 (ffi.ByteArray.zeroes { toBitVec := (↑(0:ℕ)) }).data.size ≤ 0 + 0), - Array.extract_eq_empty_of_le - (by rw [hb]; omega : min base.data.size base.data.size ≤ - base.size + min 0 ((ffi.ByteArray.zeroes { toBitVec := (↑(0:ℕ)) }).data.size - 0)), - Array.append_empty, Array.append_empty] - -theorem tlcCtorEvmCost0_mstore {s : State} {aw a b : UInt256} {t : List UInt256} - (haws : s.machineState.activeWords = aw) (hstk : s.machineState.stack = a :: b :: t) - (h : a.toNat + 32 ≤ 32 * aw.toNat) : memoryExpansionCost s .MSTORE = 0 := by - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstk, List.getElem!_cons_zero] - rw [tlcCtorEvmAwOut aw a.toNat 32 h]; omega - -theorem tlcCtorEvmCost0_mload {s : State} {aw a : UInt256} {t : List UInt256} - (haws : s.machineState.activeWords = aw) (hstk : s.machineState.stack = a :: t) - (h : a.toNat + 32 ≤ 32 * aw.toNat) : memoryExpansionCost s .MLOAD = 0 := by - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstk, List.getElem!_cons_zero] - rw [tlcCtorEvmAwOut aw a.toNat 32 h]; omega - -theorem tlcCtorEvmCost0_keccak {s : State} {aw a b : UInt256} {t : List UInt256} - (haws : s.machineState.activeWords = aw) (hstk : s.machineState.stack = a :: b :: t) - (h : a.toNat + b.toNat ≤ 32 * aw.toNat) : memoryExpansionCost s .KECCAK256 = 0 := by - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstk, List.getElem!_cons_zero, - List.getElem!_cons_succ] - rw [tlcCtorEvmAwOut aw a.toNat b.toNat h]; omega - -theorem tlcCtorEvmCost0_log4 {s : State} {aw a c d e f : UInt256} {t : List UInt256} - (haws : s.machineState.activeWords = aw) - (hstk : s.machineState.stack = a :: ⟨0⟩ :: c :: d :: e :: f :: t) : - memoryExpansionCost s .LOG4 = 0 := by - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstk, List.getElem!_cons_zero, - List.getElem!_cons_succ] - rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, tlcCtorEvmAwOut0 aw a.toNat]; omega - -theorem tlcCtorEvmCost0_log1 {s : State} {aw a c : UInt256} {t : List UInt256} - (haws : s.machineState.activeWords = aw) - (hstk : s.machineState.stack = a :: ⟨0⟩ :: c :: t) : - memoryExpansionCost s .LOG1 = 0 := by - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ', haws, hstk, List.getElem!_cons_zero, - List.getElem!_cons_succ] - rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, tlcCtorEvmAwOut0 aw a.toNat]; omega - -theorem tlcCtorInitcodeSuccess {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchCreationBytecode) - (hperm : I.perm = true) (hcd : I.calldata = ByteArray.empty) : - RDret timelockControllerBenchCreationBytecode g (initState cA gh bl σ σ₀ g A I) - (cA, tlcCtorFinalMap I σ) timelockControllerBenchBytecode := by - sorry - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorSolm.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorSolm.lean deleted file mode 100644 index b2400963..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ConstructorSolm.lean +++ /dev/null @@ -1,405 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.ConstructorDefs - -/-! -# OpenZeppelin TimelockController constructor — Solm source execution - -`tlcCtorSolmExecSuccess` : the Solm constructor body (five `grantRoleIfMissing`, the `sender ≠ 0` -guarded admin grant, and `_minDelay = 86400`) runs to a returned state whose account map is -`tlcCtorFinalMap I σ` and whose created accounts are unchanged. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 4000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Infrastructure -/ - -/-- The local-free Solm frame threaded through the constructor body. -/ -abbrev tlcCtorSolmFrame : Frame := { contract := contract, locals := ∅ } - -/-- `storageLoad` at the code owner is the raw account-map slot word (matches `tlcCtorGrantMap`). -/ -theorem tlcCtorSolmStorageLoad (evm : EVM.State) (cO : AccountAddress) (slot : UInt256) : - Solm.EVM.storageLoad evm cO slot - = ((evm.accountMap.find? cO).option ⟨0⟩ (fun ac => ac.storage.findD slot ⟨0⟩)) := by - simp [Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage] - -/-- `wordToElem .bool (word & 0xff)` is `false` when the low byte is zero (role absent). -/ -theorem tlcCtorSolmWordToElemFalse (w : UInt256) (h : UInt256.land ⟨255⟩ w = ⟨0⟩) : - Solm.wordToElem .bool (UInt256.land w ⟨255⟩) = .bool false := by - have hz : UInt256.land w ⟨255⟩ = ⟨0⟩ := by rw [u256_land_comm]; exact h - simp [Solm.wordToElem, hz] - -/-- `wordToElem .bool (word & 0xff)` is `true` when the low byte is nonzero (role present). -/ -theorem tlcCtorSolmWordToElemTrue (w : UInt256) (h : ¬ UInt256.land ⟨255⟩ w = ⟨0⟩) : - Solm.wordToElem .bool (UInt256.land w ⟨255⟩) = .bool true := by - have hz : UInt256.land w ⟨255⟩ ≠ ⟨0⟩ := by rw [u256_land_comm]; exact h - by_cases hval : (UInt256.land w ⟨255⟩).val = 0 - · exact absurd (u256_inj (congrArg Fin.val hval)) hz - · simp [Solm.wordToElem, hval] - -/-- `_roles[role].hasRole[account]` storage-ref resolves to the evaled ref, given the key evals. -/ -theorem tlcCtorSolmEvalStorageRef (roleExpr accountExpr : Expr) (roleKV accKV : KeyValue) - (roleV accV : Value) (evm : EVM.State) - (hr : evalExpr? config tlcCtorSolmFrame evm roleExpr = .ok roleV) - (hrk : valueToKey? roleV = some roleKV) - (ha : evalExpr? config tlcCtorSolmFrame evm accountExpr = .ok accV) - (hak : valueToKey? accV = some accKV) : - evalStorageRef config tlcCtorSolmFrame evm (roleHasRoleRef roleExpr accountExpr) - = .ok { base := "_roles", - steps := [.mindex roleKV, .field "hasRole", .mindex accKV] } := by - simp [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, roleHasRoleRef, - EvalResult.bind, EvalResult.ofOption, bind, pure, hr, hrk, ha, hak] - -/-- The declared storage type of `_roles[role].hasRole[account]` is `bool`. -/ -theorem tlcCtorSolmType (roleKV accKV : KeyValue) : - storageTypeAt? contract.storage - { base := "_roles", steps := [.mindex roleKV, .field "hasRole", .mindex accKV] } - = some boolSt := by - simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, roleDataSt, boolSt] - -/-- The storage layout of `_roles[role].hasRole[account]` is `boolLoc (roleHasRoleSlot role account)`. -/ -theorem tlcCtorSolmLoc (roleKV accKV : KeyValue) : - config.storage.layout - { base := "_roles", steps := [.mindex roleKV, .field "hasRole", .mindex accKV] } - = fun _ => some (boolLoc (roleHasRoleSlot roleKV accKV)) := by - rfl - -/-! ## Per-expression evaluation (role literals, `this`, `caller`, `address(0)`) -/ - -/-- A `bytes32` role literal (given in `toBytesBE` form) evaluates to its `fixedBytes` value. -/ -theorem tlcCtorSolmRoleEval (roleExpr : Expr) (w : UInt256) (evm : EVM.State) - (hlit : roleExpr = .fixedBytesLit bytes32Width (EVM.Word.toBytesBE w)) : - evalExpr? config tlcCtorSolmFrame evm roleExpr - = .ok (.fixedBytes bytes32Width (EVM.Word.toBytesBE w)) := by - rw [hlit]; simp only [evalExpr?]; rfl - -theorem tlcCtorSolmRoleKey (w : UInt256) : - valueToKey? (Value.fixedBytes bytes32Width (EVM.Word.toBytesBE w)) - = some (.fixedBytes bytes32Width (EVM.Word.toBytesBE w)) := by - have hlen : (EVM.Word.toBytesBE w).length = 32 := by - simpa using word_toBytesBE_toByteArray_size w - simp [valueToKey?, bytes32Width, hlen] - -theorem tlcCtorSolmRoleWord (w : UInt256) : - keyValueToWord (.fixedBytes bytes32Width (EVM.Word.toBytesBE w)) = w := by - rw [show bytes32Width = (⟨31, by decide⟩ : Fin 32) from rfl] - exact keyValueToWord_fixedBytes32 w - -theorem tlcCtorSolmEvalThis (evm : EVM.State) (I : ExecutionEnv) (hI : evm.executionEnv = I) : - evalExpr? config tlcCtorSolmFrame evm thisAddr = .ok (.address I.codeOwner) := by - simp only [thisAddr, evalExpr?, envValue, hI]; rfl - -theorem tlcCtorSolmEvalSender (evm : EVM.State) (I : ExecutionEnv) (hI : evm.executionEnv = I) : - evalExpr? config tlcCtorSolmFrame evm sender = .ok (.address I.source) := by - simp only [sender, evalExpr?, envValue, hI]; rfl - -theorem tlcCtorSolmEvalZero (evm : EVM.State) : - evalExpr? config tlcCtorSolmFrame evm zeroAddr = .ok (.address (AccountAddress.ofNat 0)) := by - simp only [zeroAddr, evalExpr?, addrSt, castValue?, EvalResult.bind, EvalResult.ofOption, bind] - rfl - -theorem tlcCtorSolmAddrKey (a : AccountAddress) : - valueToKey? (Value.address a) = some (.address a) := rfl - -/-! ## `tlcCtorGrantMap` case characterisation -/ - -theorem tlcCtorSolmGrantMapPos (cO : AccountAddress) (slot : UInt256) (σ : AccountMap) - (h : UInt256.land ⟨255⟩ ((σ.find? cO).option ⟨0⟩ (fun ac => ac.storage.findD slot ⟨0⟩)) = ⟨0⟩) : - tlcCtorGrantMap cO slot σ = sstoreAccountMap cO σ slot - (UInt256.lor - (UInt256.land ((σ.find? cO).option ⟨0⟩ (fun ac => ac.storage.findD slot ⟨0⟩)) - (UInt256.lnot ⟨255⟩)) ⟨1⟩) := by - unfold tlcCtorGrantMap; rw [if_pos h] - -theorem tlcCtorSolmGrantMapNeg (cO : AccountAddress) (slot : UInt256) (σ : AccountMap) - (h : ¬ UInt256.land ⟨255⟩ ((σ.find? cO).option ⟨0⟩ (fun ac => ac.storage.findD slot ⟨0⟩)) = ⟨0⟩) : - tlcCtorGrantMap cO slot σ = σ := by - unfold tlcCtorGrantMap; rw [if_neg h] - -/-! ## Single `grantRoleIfMissing` step -/ - -theorem tlcCtorSolmGrantStep (roleExpr accountExpr : Expr) (er : EvaledStorageRef) - (slotW : UInt256) (evm : EVM.State) (cO : AccountAddress) - (hcO : evm.executionEnv.codeOwner = cO) - (her : evalStorageRef config tlcCtorSolmFrame evm (roleHasRoleRef roleExpr accountExpr) = .ok er) - (hty : storageTypeAt? contract.storage er = some boolSt) - (hloc : config.storage.layout er = fun _ => some (boolLoc slotW)) : - ∃ evm', ExecBlock config tlcCtorSolmFrame evm (grantRoleIfMissing roleExpr accountExpr) - (.ok tlcCtorSolmFrame evm') - ∧ evm'.accountMap = tlcCtorGrantMap cO slotW evm.accountMap - ∧ evm'.executionEnv = evm.executionEnv - ∧ evm'.createdAccounts = evm.createdAccounts := by - have hbase : tlcCtorSolmFrame.locals.get? "_roles" = none := by - simp - have hwload : Solm.EVM.storageLoad evm cO slotW - = (evm.accountMap.find? cO).option ⟨0⟩ (fun ac => ac.storage.findD slotW ⟨0⟩) := - tlcCtorSolmStorageLoad evm cO slotW - have hread : evalExpr? config tlcCtorSolmFrame evm (hasRoleExpr roleExpr accountExpr) - = .ok (Solm.wordToElem .bool (UInt256.land (Solm.EVM.storageLoad evm cO slotW) ⟨255⟩)) := by - refine evalExpr_storage_scalar_value (t := .bool) (loc := boolLoc slotW) hbase her hty hloc ?_ - show storageLocLoad evm (boolOffset0Loc slotW) - = Solm.wordToElem .bool (UInt256.land (Solm.EVM.storageLoad evm cO slotW) ⟨255⟩) - rw [storageLocLoad_bool_offset0, hcO] - by_cases hz : - UInt256.land ⟨255⟩ (Solm.EVM.storageLoad evm cO slotW) = ⟨0⟩ - · refine ⟨Solm.EVM.storageStore evm cO slotW - (UInt256.lor (UInt256.land (Solm.EVM.storageLoad evm cO slotW) (UInt256.lnot ⟨255⟩)) ⟨1⟩), - ?_, ?_, ?_, ?_⟩ - · have hguard : evalExpr? config tlcCtorSolmFrame evm - (.unary .not (hasRoleExpr roleExpr accountExpr)) = .ok (.bool true) := by - simp only [evalExpr?, EvalResult.bind, bind, hread, - tlcCtorSolmWordToElemFalse _ hz] - rfl - have hassign : assignStorageRef? config tlcCtorSolmFrame evm .storage - (roleHasRoleRef roleExpr accountExpr) (.bool true) - = .ok (tlcCtorSolmFrame, Solm.EVM.storageStore evm cO slotW - (UInt256.lor (UInt256.land (Solm.EVM.storageLoad evm cO slotW) - (UInt256.lnot ⟨255⟩)) ⟨1⟩)) := by - refine assignStorageRef_storage_scalar_value (ty := boolSt) (loc := boolLoc slotW) - hbase her hty hloc (by trivial) ?_ - show storageLocStore evm (boolOffset0Loc slotW) (.bool true) - = some (Solm.EVM.storageStore evm cO slotW - (UInt256.lor (UInt256.land (Solm.EVM.storageLoad evm cO slotW) - (UInt256.lnot ⟨255⟩)) ⟨1⟩)) - rw [storageLocStore_bool_true_offset0, hcO] - exact ExecBlock.consNormal - (ExecStmt.iteTrue hguard - (ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) hassign) ExecBlock.nil)) - ExecBlock.nil - · rw [storageStore_accountMap, hwload, - tlcCtorSolmGrantMapPos cO slotW evm.accountMap (by rw [← hwload]; exact hz)] - · rw [storageStore_executionEnv] - · rw [storageStore_createdAccounts] - · refine ⟨evm, ?_, ?_, rfl, rfl⟩ - · have hguard : evalExpr? config tlcCtorSolmFrame evm - (.unary .not (hasRoleExpr roleExpr accountExpr)) = .ok (.bool false) := by - simp only [evalExpr?, EvalResult.bind, bind, hread, - tlcCtorSolmWordToElemTrue _ hz] - rfl - exact ExecBlock.consNormal (ExecStmt.iteFalse hguard ExecBlock.nil) ExecBlock.nil - · rw [tlcCtorSolmGrantMapNeg cO slotW evm.accountMap (by rw [← hwload]; exact hz)] - -/-- The spec nested-mapping slot in `tlcCtorSlot` (solc) form, given the key words. -/ -theorem tlcCtorSolmSlotEq (roleKV accKV : KeyValue) (roleW accW : UInt256) - (hr : keyValueToWord roleKV = roleW) (ha : keyValueToWord accKV = accW) : - roleHasRoleSlot roleKV accKV = tlcCtorSlot roleW accW := by - rw [roleHasRoleSlot_solcForm, hr, ha]; rfl - -/-- A `grantRoleIfMissing` step, parameterised by the role/account key words. -/ -theorem tlcCtorSolmGrantByWords (roleExpr accountExpr : Expr) (roleKV accKV : KeyValue) - (roleV accV : Value) (roleW accW : UInt256) (evm : EVM.State) (I : ExecutionEnv) - (hI : evm.executionEnv = I) - (hr : evalExpr? config tlcCtorSolmFrame evm roleExpr = .ok roleV) - (hrk : valueToKey? roleV = some roleKV) (hrw : keyValueToWord roleKV = roleW) - (ha : evalExpr? config tlcCtorSolmFrame evm accountExpr = .ok accV) - (hak : valueToKey? accV = some accKV) (haw : keyValueToWord accKV = accW) : - ∃ evm', ExecBlock config tlcCtorSolmFrame evm (grantRoleIfMissing roleExpr accountExpr) - (.ok tlcCtorSolmFrame evm') - ∧ evm'.accountMap = tlcCtorGrantMap I.codeOwner (tlcCtorSlot roleW accW) evm.accountMap - ∧ evm'.executionEnv = evm.executionEnv - ∧ evm'.createdAccounts = evm.createdAccounts := by - apply tlcCtorSolmGrantStep roleExpr accountExpr - { base := "_roles", steps := [.mindex roleKV, .field "hasRole", .mindex accKV] } - (tlcCtorSlot roleW accW) evm I.codeOwner (by rw [hI]) - · exact tlcCtorSolmEvalStorageRef roleExpr accountExpr roleKV accKV roleV accV evm hr hrk ha hak - · exact tlcCtorSolmType roleKV accKV - · rw [tlcCtorSolmLoc, tlcCtorSolmSlotEq roleKV accKV roleW accW hrw haw] - -/-! ## The `sender ≠ 0` admin guard -/ - -theorem tlcCtorSolmSourceZero (I : ExecutionEnv) (h : solcSourceWord I = ⟨0⟩) : - I.source = AccountAddress.ofNat 0 := by - have hs := solcSource_ofNat I - rw [h] at hs - simpa using hs.symm - -theorem tlcCtorSolmSourceNeZero (I : ExecutionEnv) (h : ¬ solcSourceWord I = ⟨0⟩) : - I.source ≠ AccountAddress.ofNat 0 := by - intro hsrc - apply h - show UInt256.ofNat I.source.val = ⟨0⟩ - have : I.source.val = 0 := by rw [hsrc]; decide - rw [this]; decide - -theorem tlcCtorSolmGuardFalse (evm : EVM.State) (I : ExecutionEnv) (hI : evm.executionEnv = I) - (h : solcSourceWord I = ⟨0⟩) : - evalExpr? config tlcCtorSolmFrame evm (.binary .ne sender zeroAddr) = .ok (.bool false) := by - have hsrc : I.source = AccountAddress.ofNat 0 := tlcCtorSolmSourceZero I h - simp only [evalExpr?, EvalResult.bind, bind, tlcCtorSolmEvalSender evm I hI, - tlcCtorSolmEvalZero evm, evalBinaryOp?] - rw [hsrc] - simp - -theorem tlcCtorSolmGuardTrue (evm : EVM.State) (I : ExecutionEnv) (hI : evm.executionEnv = I) - (h : ¬ solcSourceWord I = ⟨0⟩) : - evalExpr? config tlcCtorSolmFrame evm (.binary .ne sender zeroAddr) = .ok (.bool true) := by - have hsrc : I.source ≠ AccountAddress.ofNat 0 := tlcCtorSolmSourceNeZero I h - simp only [evalExpr?, EvalResult.bind, bind, tlcCtorSolmEvalSender evm I hI, - tlcCtorSolmEvalZero evm, evalBinaryOp?] - have hbeq : (Value.address I.source == Value.address (AccountAddress.ofNat 0)) = false := by - simp only [beq_eq_false_iff_ne, ne_eq] - intro heq - exact hsrc (Value.address.inj heq) - rw [hbeq] - rfl - -/-! ## The five named grants -/ - -theorem tlcCtorSolmGrantAdminThis (evm : EVM.State) (I : ExecutionEnv) (hI : evm.executionEnv = I) : - ∃ evm', ExecBlock config tlcCtorSolmFrame evm (grantRoleIfMissing defaultAdminRole thisAddr) - (.ok tlcCtorSolmFrame evm') - ∧ evm'.accountMap = tlcCtorGrantMap I.codeOwner (tlcSlotAdminThis I) evm.accountMap - ∧ evm'.executionEnv = evm.executionEnv - ∧ evm'.createdAccounts = evm.createdAccounts := - tlcCtorSolmGrantByWords defaultAdminRole thisAddr _ _ _ _ tlcDefaultAdminRoleWord (tlcThisWord I) - evm I hI - (tlcCtorSolmRoleEval defaultAdminRole tlcDefaultAdminRoleWord evm (by native_decide)) - (tlcCtorSolmRoleKey tlcDefaultAdminRoleWord) (tlcCtorSolmRoleWord tlcDefaultAdminRoleWord) - (tlcCtorSolmEvalThis evm I hI) (tlcCtorSolmAddrKey I.codeOwner) - (by rw [keyValueToWord_address]) - -theorem tlcCtorSolmGrantAdminSender (evm : EVM.State) (I : ExecutionEnv) - (hI : evm.executionEnv = I) : - ∃ evm', ExecBlock config tlcCtorSolmFrame evm (grantRoleIfMissing defaultAdminRole sender) - (.ok tlcCtorSolmFrame evm') - ∧ evm'.accountMap = tlcCtorGrantMap I.codeOwner (tlcSlotAdminSender I) evm.accountMap - ∧ evm'.executionEnv = evm.executionEnv - ∧ evm'.createdAccounts = evm.createdAccounts := - tlcCtorSolmGrantByWords defaultAdminRole sender _ _ _ _ tlcDefaultAdminRoleWord (solcSourceWord I) - evm I hI - (tlcCtorSolmRoleEval defaultAdminRole tlcDefaultAdminRoleWord evm (by native_decide)) - (tlcCtorSolmRoleKey tlcDefaultAdminRoleWord) (tlcCtorSolmRoleWord tlcDefaultAdminRoleWord) - (tlcCtorSolmEvalSender evm I hI) (tlcCtorSolmAddrKey I.source) - (by rw [keyValueToWord_address]) - -theorem tlcCtorSolmGrantPropSender (evm : EVM.State) (I : ExecutionEnv) (hI : evm.executionEnv = I) : - ∃ evm', ExecBlock config tlcCtorSolmFrame evm (grantRoleIfMissing proposerRole sender) - (.ok tlcCtorSolmFrame evm') - ∧ evm'.accountMap = tlcCtorGrantMap I.codeOwner (tlcSlotPropSender I) evm.accountMap - ∧ evm'.executionEnv = evm.executionEnv - ∧ evm'.createdAccounts = evm.createdAccounts := - tlcCtorSolmGrantByWords proposerRole sender _ _ _ _ tlcProposerRoleWord (solcSourceWord I) - evm I hI - (tlcCtorSolmRoleEval proposerRole tlcProposerRoleWord evm (by native_decide)) - (tlcCtorSolmRoleKey tlcProposerRoleWord) (tlcCtorSolmRoleWord tlcProposerRoleWord) - (tlcCtorSolmEvalSender evm I hI) (tlcCtorSolmAddrKey I.source) - (by rw [keyValueToWord_address]) - -theorem tlcCtorSolmGrantCancSender (evm : EVM.State) (I : ExecutionEnv) (hI : evm.executionEnv = I) : - ∃ evm', ExecBlock config tlcCtorSolmFrame evm (grantRoleIfMissing cancellerRole sender) - (.ok tlcCtorSolmFrame evm') - ∧ evm'.accountMap = tlcCtorGrantMap I.codeOwner (tlcSlotCancSender I) evm.accountMap - ∧ evm'.executionEnv = evm.executionEnv - ∧ evm'.createdAccounts = evm.createdAccounts := - tlcCtorSolmGrantByWords cancellerRole sender _ _ _ _ tlcCancellerRoleWord (solcSourceWord I) - evm I hI - (tlcCtorSolmRoleEval cancellerRole tlcCancellerRoleWord evm (by native_decide)) - (tlcCtorSolmRoleKey tlcCancellerRoleWord) (tlcCtorSolmRoleWord tlcCancellerRoleWord) - (tlcCtorSolmEvalSender evm I hI) (tlcCtorSolmAddrKey I.source) - (by rw [keyValueToWord_address]) - -theorem tlcCtorSolmGrantExecZero (evm : EVM.State) (I : ExecutionEnv) (hI : evm.executionEnv = I) : - ∃ evm', ExecBlock config tlcCtorSolmFrame evm (grantRoleIfMissing executorRole zeroAddr) - (.ok tlcCtorSolmFrame evm') - ∧ evm'.accountMap = tlcCtorGrantMap I.codeOwner (tlcSlotExecZero I) evm.accountMap - ∧ evm'.executionEnv = evm.executionEnv - ∧ evm'.createdAccounts = evm.createdAccounts := - tlcCtorSolmGrantByWords executorRole zeroAddr _ _ _ _ tlcExecutorRoleWord ⟨0⟩ - evm I hI - (tlcCtorSolmRoleEval executorRole tlcExecutorRoleWord evm (by native_decide)) - (tlcCtorSolmRoleKey tlcExecutorRoleWord) (tlcCtorSolmRoleWord tlcExecutorRoleWord) - (tlcCtorSolmEvalZero evm) (tlcCtorSolmAddrKey (AccountAddress.ofNat 0)) - (by rw [keyValueToWord_address]; decide) - -/-! ## The `_minDelay = 86400` store -/ - -theorem tlcCtorSolmMinDelay (evm : EVM.State) (I : ExecutionEnv) (hI : evm.executionEnv = I) : - ∃ evm', ExecBlock config tlcCtorSolmFrame evm [ .assign .storage minDelayRef initialMinDelay ] - (.ok tlcCtorSolmFrame evm') - ∧ evm'.accountMap = sstoreAccountMap I.codeOwner evm.accountMap ⟨2⟩ ⟨86400⟩ - ∧ evm'.executionEnv = evm.executionEnv - ∧ evm'.createdAccounts = evm.createdAccounts := by - have hassign : assignStorageRef? config tlcCtorSolmFrame evm .storage minDelayRef (.int 86400) - = .ok (tlcCtorSolmFrame, Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨2⟩ ⟨86400⟩) := by - apply assignStorageRef_storage_scalar - (ty := uint256St) (loc := uint256Loc ⟨2⟩) (er := { base := "_minDelay", steps := [] }) - (hbase := by simp [minDelayRef]) - (her := by - simp [minDelayRef, evalStorageRef, evalStorageRefSteps, EvalResult.bind, pure, bind]) - (hty := by simp [storageTypeAt?, contract, storageDecls, uint256St]) - (hloc := by rfl) - show storageLocStore evm (uint256Loc ⟨2⟩) (.int (Int.ofNat (⟨86400⟩ : UInt256).toNat)) - = some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨2⟩ ⟨86400⟩) - exact storageLocStore_uint256 evm ⟨2⟩ ⟨86400⟩ - refine ⟨Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨2⟩ ⟨86400⟩, - ExecBlock.consNormal (ExecStmt.assign (by simp [evalExpr?, initialMinDelay, pure]) hassign) - ExecBlock.nil, ?_, ?_, ?_⟩ - · rw [storageStore_accountMap, hI] - · rw [storageStore_executionEnv] - · rw [storageStore_createdAccounts] - -/-! ## The admin block: grant `admin→this`, then the `sender ≠ 0` guarded `admin→sender` -/ - -theorem tlcCtorSolmAdminBlock (evm : EVM.State) (I : ExecutionEnv) (hI : evm.executionEnv = I) : - ∃ evm', ExecBlock config tlcCtorSolmFrame evm - (grantRoleIfMissing defaultAdminRole thisAddr ++ - [ .ite (.binary .ne sender zeroAddr) (grantRoleIfMissing defaultAdminRole sender) [] ]) - (.ok tlcCtorSolmFrame evm') - ∧ evm'.accountMap = tlcCtorAdminMap I evm.accountMap - ∧ evm'.executionEnv = evm.executionEnv - ∧ evm'.createdAccounts = evm.createdAccounts := by - obtain ⟨evm1, hB1, hmap1, henv1, hcre1⟩ := tlcCtorSolmGrantAdminThis evm I hI - by_cases hsrc : solcSourceWord I = ⟨0⟩ - · refine ⟨evm1, execBlock_append hB1 - (ExecBlock.consNormal - (ExecStmt.iteFalse (tlcCtorSolmGuardFalse evm1 I (henv1.trans hI) hsrc) ExecBlock.nil) - ExecBlock.nil), ?_, henv1, hcre1⟩ - rw [hmap1]; unfold tlcCtorAdminMap; rw [if_pos hsrc] - · obtain ⟨evm2, hB2, hmap2, henv2, hcre2⟩ := tlcCtorSolmGrantAdminSender evm1 I (henv1.trans hI) - refine ⟨evm2, execBlock_append hB1 - (ExecBlock.consNormal - (ExecStmt.iteTrue (tlcCtorSolmGuardTrue evm1 I (henv1.trans hI) hsrc) hB2) - ExecBlock.nil), ?_, henv2.trans henv1, hcre2.trans hcre1⟩ - rw [hmap2, hmap1]; unfold tlcCtorAdminMap; rw [if_neg hsrc] - -/-! ## The whole constructor body -/ - -theorem tlcCtorSolmBody (evm : EVM.State) (I : ExecutionEnv) (hI : evm.executionEnv = I) : - ∃ S, ExecBlock config tlcCtorSolmFrame evm constructorDecl.body (.ok tlcCtorSolmFrame S) - ∧ S.createdAccounts = evm.createdAccounts - ∧ S.accountMap = tlcCtorFinalMap I evm.accountMap := by - obtain ⟨evmA, hA, hmapA, henvA, hcreA⟩ := tlcCtorSolmAdminBlock evm I hI - obtain ⟨evmP, hP, hmapP, henvP, hcreP⟩ := - tlcCtorSolmGrantPropSender evmA I (henvA.trans hI) - obtain ⟨evmC, hC, hmapC, henvC, hcreC⟩ := - tlcCtorSolmGrantCancSender evmP I ((henvP.trans henvA).trans hI) - obtain ⟨evmE, hE, hmapE, henvE, hcreE⟩ := - tlcCtorSolmGrantExecZero evmC I (((henvC.trans henvP).trans henvA).trans hI) - obtain ⟨S, hM, hmapM, henvM, hcreM⟩ := - tlcCtorSolmMinDelay evmE I ((((henvE.trans henvC).trans henvP).trans henvA).trans hI) - refine ⟨S, - execBlock_append (execBlock_append (execBlock_append (execBlock_append hA hP) hC) hE) hM, - ?_, ?_⟩ - · rw [hcreM, hcreE, hcreC, hcreP, hcreA] - · rw [hmapM, hmapE, hmapC, hmapP, hmapA]; rfl - -theorem tlcCtorSolmExecSuccess {cA gh bl σ σ₀ A I} {g : UInt256} : - ∃ frame S, - solmCtorExec config contract [] cA gh bl σ σ₀ g A I (.returned frame S none) - ∧ S.createdAccounts = cA - ∧ S.accountMap = tlcCtorFinalMap I σ := by - obtain ⟨S, hbody, hcre, hmap⟩ := - tlcCtorSolmBody (initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) I (by rfl) - refine ⟨tlcCtorSolmFrame, S, ?_, ?_, ?_⟩ - · refine solmCtorExec.intro - (evmState := initState cA gh bl σ σ₀ (Sat256.ofUInt256 g) A I) - (argsStore := ∅) rfl rfl rfl ?_ - exact ExecFuncBody.execBlockOK hbody - · rw [hcre]; rfl - · rw [hmap]; rfl - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Correct.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Correct.lean deleted file mode 100644 index 45248570..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Correct.lean +++ /dev/null @@ -1,146 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.CancellerRole -import Benchmarks.OpenZeppelinBench.TimelockController.Cancel -import Benchmarks.OpenZeppelinBench.TimelockController.DefaultAdminRole -import Benchmarks.OpenZeppelinBench.TimelockController.ExecuteBatch -import Benchmarks.OpenZeppelinBench.TimelockController.Execute -import Benchmarks.OpenZeppelinBench.TimelockController.ExecutorRole -import Benchmarks.OpenZeppelinBench.TimelockController.GetMinDelay -import Benchmarks.OpenZeppelinBench.TimelockController.GetOperationState -import Benchmarks.OpenZeppelinBench.TimelockController.GetRoleAdmin -import Benchmarks.OpenZeppelinBench.TimelockController.GetTimestamp -import Benchmarks.OpenZeppelinBench.TimelockController.GrantRole -import Benchmarks.OpenZeppelinBench.TimelockController.HasRole -import Benchmarks.OpenZeppelinBench.TimelockController.HashOperationBatch -import Benchmarks.OpenZeppelinBench.TimelockController.HashOperation -import Benchmarks.OpenZeppelinBench.TimelockController.IsOperationDone -import Benchmarks.OpenZeppelinBench.TimelockController.IsOperationPending -import Benchmarks.OpenZeppelinBench.TimelockController.IsOperationReady -import Benchmarks.OpenZeppelinBench.TimelockController.IsOperation -import Benchmarks.OpenZeppelinBench.TimelockController.OnERC1155BatchReceived -import Benchmarks.OpenZeppelinBench.TimelockController.OnERC1155Received -import Benchmarks.OpenZeppelinBench.TimelockController.OnERC721Received -import Benchmarks.OpenZeppelinBench.TimelockController.ProposerRole -import Benchmarks.OpenZeppelinBench.TimelockController.RenounceRole -import Benchmarks.OpenZeppelinBench.TimelockController.RevokeRole -import Benchmarks.OpenZeppelinBench.TimelockController.ScheduleBatch -import Benchmarks.OpenZeppelinBench.TimelockController.Schedule -import Benchmarks.OpenZeppelinBench.TimelockController.SupportsInterface -import Benchmarks.OpenZeppelinBench.TimelockController.UpdateDelay -import Benchmarks.OpenZeppelinBench.TimelockController.Fallback -import Benchmarks.OpenZeppelinBench.TimelockController.Constructor -import Solm.Equiv - -/-! -# OpenZeppelin TimelockController benchmark correctness - -Thin top-level: the balanced depth-3 binary-search dispatcher routes each of the 28 selectors to -that function's `…BodyCore`; a non-matching selector (calldata ≥ 4) reverts (no fallback), and -calldata < 4 routes to the payable `receive` (empty calldata) or reverts (1–3 bytes). There is no -shared callvalue guard — each non-payable function guards its own callvalue. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace OpenZeppelinBench.TimelockController - -theorem timelockControllerBenchCorrect : - runtimeEquivalence config timelockControllerBenchBytecode contract := by - refine ⟨fun cA gh bl σ_evm σ_solm σ₀ g A I hcode hsize hperm hAccounts => ?_⟩ - by_cases hsz : 4 ≤ I.calldata.size - · by_cases h0 : selIs I (tlcSelBytes 0) - · exact tlcCancellerRoleBodyCore hcode hsize hperm h0 hAccounts - · by_cases h1 : selIs I (tlcSelBytes 1) - · exact tlcCancelBodyCore hcode hsize hperm h1 hAccounts - · by_cases h2 : selIs I (tlcSelBytes 2) - · exact tlcDefaultAdminRoleBodyCore hcode hsize hperm h2 hAccounts - · by_cases h3 : selIs I (tlcSelBytes 3) - · exact tlcExecuteBatchBodyCore hcode hsize hperm h3 hAccounts - · by_cases h4 : selIs I (tlcSelBytes 4) - · exact tlcExecuteBodyCore hcode hsize hperm h4 hAccounts - · by_cases h5 : selIs I (tlcSelBytes 5) - · exact tlcExecutorRoleBodyCore hcode hsize hperm h5 hAccounts - · by_cases h6 : selIs I (tlcSelBytes 6) - · exact tlcGetMinDelayBodyCore hcode hsize hperm h6 hAccounts - · by_cases h7 : selIs I (tlcSelBytes 7) - · exact tlcGetOperationStateBodyCore hcode hsize hperm h7 hAccounts - · by_cases h8 : selIs I (tlcSelBytes 8) - · exact tlcGetRoleAdminBodyCore hcode hsize hperm h8 hAccounts - · by_cases h9 : selIs I (tlcSelBytes 9) - · exact tlcGetTimestampBodyCore hcode hsize hperm h9 hAccounts - · by_cases h10 : selIs I (tlcSelBytes 10) - · exact tlcGrantRoleBodyCore hcode hsize hperm h10 hAccounts - · by_cases h11 : selIs I (tlcSelBytes 11) - · exact tlcHasRoleBodyCore hcode hsize hperm h11 hAccounts - · by_cases h12 : selIs I (tlcSelBytes 12) - · exact tlcHashOperationBatchBodyCore hcode hsize hperm h12 hAccounts - · by_cases h13 : selIs I (tlcSelBytes 13) - · exact tlcHashOperationBodyCore hcode hsize hperm h13 hAccounts - · by_cases h14 : selIs I (tlcSelBytes 14) - · exact tlcIsOperationDoneBodyCore hcode hsize hperm h14 hAccounts - · by_cases h15 : selIs I (tlcSelBytes 15) - · exact tlcIsOperationPendingBodyCore hcode hsize hperm h15 hAccounts - · by_cases h16 : selIs I (tlcSelBytes 16) - · exact tlcIsOperationReadyBodyCore hcode hsize hperm h16 hAccounts - · by_cases h17 : selIs I (tlcSelBytes 17) - · exact tlcIsOperationBodyCore hcode hsize hperm h17 hAccounts - · by_cases h18 : selIs I (tlcSelBytes 18) - · exact tlcOnERC1155BatchReceivedBodyCore hcode hsize hperm h18 hAccounts - · by_cases h19 : selIs I (tlcSelBytes 19) - · exact tlcOnERC1155ReceivedBodyCore hcode hsize hperm h19 hAccounts - · by_cases h20 : selIs I (tlcSelBytes 20) - · exact tlcOnERC721ReceivedBodyCore hcode hsize hperm h20 hAccounts - · by_cases h21 : selIs I (tlcSelBytes 21) - · exact tlcProposerRoleBodyCore hcode hsize hperm h21 hAccounts - · by_cases h22 : selIs I (tlcSelBytes 22) - · exact tlcRenounceRoleBodyCore hcode hsize hperm h22 hAccounts - · by_cases h23 : selIs I (tlcSelBytes 23) - · exact tlcRevokeRoleBodyCore hcode hsize hperm h23 hAccounts - · by_cases h24 : selIs I (tlcSelBytes 24) - · exact tlcScheduleBatchBodyCore hcode hsize hperm h24 hAccounts - · by_cases h25 : selIs I (tlcSelBytes 25) - · exact tlcScheduleBodyCore hcode hsize hperm h25 hAccounts - · by_cases h26 : selIs I (tlcSelBytes 26) - · exact tlcSupportsInterfaceBodyCore hcode hsize hperm h26 hAccounts - · by_cases h27 : selIs I (tlcSelBytes 27) - · exact tlcUpdateDelayBodyCore hcode hsize hperm h27 hAccounts - · refine tlcNoMatchBodyCore hcode hsize hperm hsz ?_ hAccounts - intro i hi - interval_cases i - · simpa [selIs] using h0 - · simpa [selIs] using h1 - · simpa [selIs] using h2 - · simpa [selIs] using h3 - · simpa [selIs] using h4 - · simpa [selIs] using h5 - · simpa [selIs] using h6 - · simpa [selIs] using h7 - · simpa [selIs] using h8 - · simpa [selIs] using h9 - · simpa [selIs] using h10 - · simpa [selIs] using h11 - · simpa [selIs] using h12 - · simpa [selIs] using h13 - · simpa [selIs] using h14 - · simpa [selIs] using h15 - · simpa [selIs] using h16 - · simpa [selIs] using h17 - · simpa [selIs] using h18 - · simpa [selIs] using h19 - · simpa [selIs] using h20 - · simpa [selIs] using h21 - · simpa [selIs] using h22 - · simpa [selIs] using h23 - · simpa [selIs] using h24 - · simpa [selIs] using h25 - · simpa [selIs] using h26 - · simpa [selIs] using h27 - · exact tlcShortBodyCore hcode hsize hperm (by omega) hAccounts - -theorem timelockControllerBenchContractCorrect : - contractEquivalence config timelockControllerBenchCreationBytecode - timelockControllerBenchBytecode contract := - contractEquivalence.intro timelockControllerBenchConstructorCorrect timelockControllerBenchCorrect - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/DefaultAdminRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/DefaultAdminRole.lean deleted file mode 100644 index 40441b08..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/DefaultAdminRole.lean +++ /dev/null @@ -1,103 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Return -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `DEFAULT_ADMIN_ROLE()` refinement - -`DEFAULT_ADMIN_ROLE` is a public non-payable `bytes32` constant getter (selector index 2, dispatch -group G147 arm 1, body pc 1132). It returns `bytes32(0)`, which the optimized runtime pushes with -`PUSH0` (not `PUSH32`). Copied from the `PROPOSER_ROLE` template. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 --- arm index 1 ⇒ `interval_cases j` yields a single goal, so the `<;>` combinator (kept for --- template parity) is flagged as an unnecessary seq-focus; the warning is purely cosmetic. -set_option linter.unnecessarySeqFocus false - -namespace OpenZeppelinBench.TimelockController - -/-- `DEFAULT_ADMIN_ROLE` is `bytes32(0)` (the `PUSH0` constant at pc 1145). -/ -def tlcDefaultAdminRoleWord : UInt256 := ⟨0⟩ - -theorem tlcDecodeDefaultAdminRole {I : ExecutionEnv} (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (defaultAdminRoleTransition.params.map Param.name) - (transitionSignature defaultAdminRoleTransition).paramTypes I.calldata = some ∅ := by - show decodeCalldataWithMode config.abiDecodeMode [] [] I.calldata = some (∅ : Store) - exact decodeCalldataWithMode_empty_ok hsz - -/-- Reach the `DEFAULT_ADMIN_ROLE` body pc 1132 (G147 arm 1). -/ -theorem tlcReachDefaultAdminRole {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 2)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1132⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0xa217fddf⟩ := - solcSelectorWord_eq_of_beq I hsz 0xa2 0x17 0xfd 0xdf ⟨0xa217fddf⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG147Body 1 (by omega) ⟨1132⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j <;> (rw [hsw]; native_decide)) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- EVM: with zero callvalue, `DEFAULT_ADMIN_ROLE()` returns the 32-byte zero constant. -/ -theorem tlcDefaultAdminRoleX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 2)) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray tlcDefaultAdminRoleWord) := by - obtain ⟨_, _, h1132⟩ := tlcReachDefaultAdminRole (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h1145⟩ := tlcGuardPeelOk (gt := ⟨1143⟩) h1132 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - have h581 := h1145.push2 ⟨581⟩ (by native_decide) (by simp) - |>.push0 (by native_decide) (by simp) - |>.dup2 (by native_decide) (by simp) - |>.jump (by native_decide) (by jump_dest) (by simp) - exact tlcReturnWord h581 (by simp) - -/-- The Solm `DEFAULT_ADMIN_ROLE()` body returns the constant `bytes32(0)`. -/ -theorem tlcDefaultAdminRoleBodyReturns (evm : EVM.State) (locals : Store) - (h : evm.executionEnv.weiValue = ⟨0⟩) : - ExecTransitionBody config contract evm locals defaultAdminRoleTransition.body - (.returned { contract := contract, locals := locals } evm - (some [(.fixedBytes bytes32Width (EVM.Word.toBytesBE tlcDefaultAdminRoleWord))])) := by - have hbody : defaultAdminRoleTransition.body = - [ Stmt.require (.binary .eq (.env .callvalue) (.intLit 0)), - Stmt.return [Expr.fixedBytesLit bytes32Width (EVM.Word.toBytesBE tlcDefaultAdminRoleWord)] ] := by - native_decide - rw [hbody] - exact nonpayableFixedBytesLiteralBodyReturns (cfg := config) (contract := contract) - evm locals bytes32Width (EVM.Word.toBytesBE tlcDefaultAdminRoleWord) h - -/-- Refinement of `DefaultAdminRole` (selector index 2). -/ -theorem tlcDefaultAdminRoleBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 2)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 2) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · exact tlcReEquivExecTransport hcode - (tlcDefaultAdminRoleX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel) - (tlcSelectorDispatchDefaultAdminRole hsel) (tlcDecodeDefaultAdminRole hsz) - (tlcDefaultAdminRoleBodyReturns (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) ∅ - (by simp only [initState]; exact hwv)) - rfl hAccounts - (returnEquiv_of_encode (bytes32ReturnEncoding tlcDefaultAdminRoleWord)) - · obtain ⟨_, _, h1132⟩ := tlcReachDefaultAdminRole (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨1143⟩) h1132 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchDefaultAdminRole hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Dispatch.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Dispatch.lean deleted file mode 100644 index 271a7530..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Dispatch.lean +++ /dev/null @@ -1,527 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController runtime dispatcher reach lemmas - -The dispatcher is solc 0.8.35's balanced depth-3 binary search over 28 selectors: a free-memory -pointer prologue, a `calldatasize < 4` guard that falls through to the payable receive / short-revert -handler (pc 434) rather than reverting inline, a selector load, and a tree of `GT` pivot splits whose -leaves are linear `EQ` arm groups. There is **no shared callvalue guard** — `receive` is payable, so -each non-payable function guards its own callvalue at its entry. - -Dispatch tree (anchor pcs read off the bytecode; each split is `DUP1; PUSH4 pivot; GT; PUSH2 lo; JUMPI`): - -``` -root@18 (0x8065657f hashOperation): sel.push1 ⟨128⟩ (by native_decide) (by decide) - |>.push1 ⟨64⟩ (by native_decide) (by decide) - |>.mstore 9 solcFreePtrMem (UInt256.ofNat 3) (by native_decide) - mem_cost (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; rfl) - (by decide) (by decide) - have h13 := h5 - |>.push1 ⟨4⟩ (by native_decide) (by simp only [List.length]; omega) - |>.calldatasize (by native_decide) (by simp only [List.length]; omega) - |>.lt (by native_decide) (by simp only [List.length]; omega) - |>.pushConst (⟨434⟩ : UInt256) (width := 2) (op := .PUSH2) (by native_decide) - (by native_decide) (by simp only [List.length]; omega) - |>.jumpiNT (by native_decide) (lt_four_eq_zero_of_ge hsz hsize) - (by simp only [List.length]; omega) - obtain ⟨k, C, h18⟩ := solcSelectorLoad h13 (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by simp only [List.length]; omega) - exact ⟨k, C, h18⟩ - -/-! ## Split / arm well-formedness -/ - -theorem tlcRootSplitWF : selectorSplitWellFormed timelockControllerBenchBytecode ⟨18⟩ := by - dsimp [selectorSplitWellFormed]; repeat' first | apply And.intro | native_decide - -theorem tlcN29SplitWF : selectorSplitWellFormed timelockControllerBenchBytecode ⟨29⟩ := by - dsimp [selectorSplitWellFormed]; repeat' first | apply And.intro | native_decide - -theorem tlcN40SplitWF : selectorSplitWellFormed timelockControllerBenchBytecode ⟨40⟩ := by - dsimp [selectorSplitWellFormed]; repeat' first | apply And.intro | native_decide - -theorem tlcN136SplitWF : selectorSplitWellFormed timelockControllerBenchBytecode ⟨136⟩ := by - dsimp [selectorSplitWellFormed]; repeat' first | apply And.intro | native_decide - -theorem tlcN232SplitWF : selectorSplitWellFormed timelockControllerBenchBytecode ⟨232⟩ := by - dsimp [selectorSplitWellFormed]; repeat' first | apply And.intro | native_decide - -theorem tlcN243SplitWF : selectorSplitWellFormed timelockControllerBenchBytecode ⟨243⟩ := by - dsimp [selectorSplitWellFormed]; repeat' first | apply And.intro | native_decide - -theorem tlcN339SplitWF : selectorSplitWellFormed timelockControllerBenchBytecode ⟨339⟩ := by - dsimp [selectorSplitWellFormed]; repeat' first | apply And.intro | native_decide - -theorem tlcG51ArmsWF : - ∀ j, j ≤ 3 → armWellFormed timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨51⟩ j) := by - intro j hj; interval_cases j <;> - (dsimp [armWellFormed]; repeat' first | apply And.intro | native_decide) - -theorem tlcG98ArmsWF : - ∀ j, j ≤ 2 → armWellFormed timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨99⟩ j) := by - intro j hj; interval_cases j <;> - (dsimp [armWellFormed]; repeat' first | apply And.intro | native_decide) - -theorem tlcG147ArmsWF : - ∀ j, j ≤ 3 → armWellFormed timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨147⟩ j) := by - intro j hj; interval_cases j <;> - (dsimp [armWellFormed]; repeat' first | apply And.intro | native_decide) - -theorem tlcG194ArmsWF : - ∀ j, j ≤ 2 → armWellFormed timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨195⟩ j) := by - intro j hj; interval_cases j <;> - (dsimp [armWellFormed]; repeat' first | apply And.intro | native_decide) - -theorem tlcG254ArmsWF : - ∀ j, j ≤ 3 → armWellFormed timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨254⟩ j) := by - intro j hj; interval_cases j <;> - (dsimp [armWellFormed]; repeat' first | apply And.intro | native_decide) - -theorem tlcG301ArmsWF : - ∀ j, j ≤ 2 → armWellFormed timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨302⟩ j) := by - intro j hj; interval_cases j <;> - (dsimp [armWellFormed]; repeat' first | apply And.intro | native_decide) - -theorem tlcG350ArmsWF : - ∀ j, j ≤ 3 → armWellFormed timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨350⟩ j) := by - intro j hj; interval_cases j <;> - (dsimp [armWellFormed]; repeat' first | apply And.intro | native_decide) - -theorem tlcG397ArmsWF : - ∀ j, j ≤ 2 → armWellFormed timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨398⟩ j) := by - intro j hj; interval_cases j <;> - (dsimp [armWellFormed]; repeat' first | apply And.intro | native_decide) - -/-! ## Internal-node reaches (parameterised over the split directions taken to get there) -/ - -/-- Root not taken (`sel ≥ 0x8065657f`): fall through to `N29`. -/ -theorem tlcReach29 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) = ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨29⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h18⟩ := tlcReachRootSplit (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize - exact ⟨_, _, by - simpa [selArmNextPc, armTgtWidth, selArmJumpiPc, selArmPushTgtPc, selArmEqPc, selArmPush4Pc] - using RD.selectorSplitNotTakenAuto h18 tlcRootSplitWF hroot (by simp)⟩ - -/-- Root taken (`sel < 0x8065657f`): jump 231, step jumpdest to `N232`. -/ -theorem tlcReach232 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) ≠ ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨232⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h18⟩ := tlcReachRootSplit (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize - have h231 := RD.selectorSplitTakenAuto h18 tlcRootSplitWF hroot (by jump_dest) (by simp) - exact ⟨_, _, h231.jumpdest (by native_decide) (by simp)⟩ - -/-- `N29` not taken (`sel ≥ 0xbc197c81`): fall through to `N40`. -/ -theorem tlcReach40 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) = ⟨0⟩) - (h29 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨29⟩) (tlcSelWord I) = ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨40⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h29r⟩ := tlcReach29 (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot - exact ⟨_, _, by - simpa [selArmNextPc, armTgtWidth, selArmJumpiPc, selArmPushTgtPc, selArmEqPc, selArmPush4Pc] - using RD.selectorSplitNotTakenAuto h29r tlcN29SplitWF h29 (by simp)⟩ - -/-- `N29` taken (`sel < 0xbc197c81`): jump 135, step jumpdest to `N136`. -/ -theorem tlcReach136 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) = ⟨0⟩) - (h29 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨29⟩) (tlcSelWord I) ≠ ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨136⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h29r⟩ := tlcReach29 (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot - have h135 := RD.selectorSplitTakenAuto h29r tlcN29SplitWF h29 (by jump_dest) (by simp) - exact ⟨_, _, h135.jumpdest (by native_decide) (by simp)⟩ - -/-- `N232` not taken (`sel ≥ 0x2ab0f529`): fall through to `N243`. -/ -theorem tlcReach243 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h232 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨232⟩) (tlcSelWord I) = ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨243⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h232r⟩ := tlcReach232 (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot - exact ⟨_, _, by - simpa [selArmNextPc, armTgtWidth, selArmJumpiPc, selArmPushTgtPc, selArmEqPc, selArmPush4Pc] - using RD.selectorSplitNotTakenAuto h232r tlcN232SplitWF h232 (by simp)⟩ - -/-- `N232` taken (`sel < 0x2ab0f529`): jump 338, step jumpdest to `N339`. -/ -theorem tlcReach339 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h232 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨232⟩) (tlcSelWord I) ≠ ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨339⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h232r⟩ := tlcReach232 (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot - have h338 := RD.selectorSplitTakenAuto h232r tlcN232SplitWF h232 (by jump_dest) (by simp) - exact ⟨_, _, h338.jumpdest (by native_decide) (by simp)⟩ - -/-! ## Leaf-group first-arm reaches -/ - -/-- `N40` not taken (`sel ≥ 0xd547741f`): fall through to arms `@51` (G51). -/ -theorem tlcReachG51First {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) = ⟨0⟩) - (h29 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨29⟩) (tlcSelWord I) = ⟨0⟩) - (h40 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨40⟩) (tlcSelWord I) = ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨51⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h40r⟩ := tlcReach40 (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h29 - exact ⟨_, _, by - simpa [selArmNextPc, armTgtWidth, selArmJumpiPc, selArmPushTgtPc, selArmEqPc, selArmPush4Pc] - using RD.selectorSplitNotTakenAuto h40r tlcN40SplitWF h40 (by simp)⟩ - -/-- `N40` taken (`sel < 0xd547741f`): jump 98, step jumpdest to arms `@99` (G98). -/ -theorem tlcReachG98First {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) = ⟨0⟩) - (h29 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨29⟩) (tlcSelWord I) = ⟨0⟩) - (h40 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨40⟩) (tlcSelWord I) ≠ ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨99⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h40r⟩ := tlcReach40 (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h29 - have h98 := RD.selectorSplitTakenAuto h40r tlcN40SplitWF h40 (by jump_dest) (by simp) - exact ⟨_, _, h98.jumpdest (by native_decide) (by simp)⟩ - -/-- `N136` not taken (`sel ≥ 0x91d14854`): fall through to arms `@147` (G147). -/ -theorem tlcReachG147First {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) = ⟨0⟩) - (h29 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨29⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h136 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨136⟩) (tlcSelWord I) = ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨147⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h136r⟩ := tlcReach136 (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h29 - exact ⟨_, _, by - simpa [selArmNextPc, armTgtWidth, selArmJumpiPc, selArmPushTgtPc, selArmEqPc, selArmPush4Pc] - using RD.selectorSplitNotTakenAuto h136r tlcN136SplitWF h136 (by simp)⟩ - -/-- `N136` taken (`sel < 0x91d14854`): jump 194, step jumpdest to arms `@195` (G194). -/ -theorem tlcReachG194First {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) = ⟨0⟩) - (h29 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨29⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h136 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨136⟩) (tlcSelWord I) ≠ ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨195⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h136r⟩ := tlcReach136 (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h29 - have h194 := RD.selectorSplitTakenAuto h136r tlcN136SplitWF h136 (by jump_dest) (by simp) - exact ⟨_, _, h194.jumpdest (by native_decide) (by simp)⟩ - -/-- `N243` not taken (`sel ≥ 0x36568abe`): fall through to arms `@254` (G254). -/ -theorem tlcReachG254First {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h232 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨232⟩) (tlcSelWord I) = ⟨0⟩) - (h243 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨243⟩) (tlcSelWord I) = ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨254⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h243r⟩ := tlcReach243 (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h232 - exact ⟨_, _, by - simpa [selArmNextPc, armTgtWidth, selArmJumpiPc, selArmPushTgtPc, selArmEqPc, selArmPush4Pc] - using RD.selectorSplitNotTakenAuto h243r tlcN243SplitWF h243 (by simp)⟩ - -/-- `N243` taken (`sel < 0x36568abe`): jump 301, step jumpdest to arms `@302` (G301). -/ -theorem tlcReachG301First {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h232 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨232⟩) (tlcSelWord I) = ⟨0⟩) - (h243 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨243⟩) (tlcSelWord I) ≠ ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨302⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h243r⟩ := tlcReach243 (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h232 - have h301 := RD.selectorSplitTakenAuto h243r tlcN243SplitWF h243 (by jump_dest) (by simp) - exact ⟨_, _, h301.jumpdest (by native_decide) (by simp)⟩ - -/-- `N339` not taken (`sel ≥ 0x134008d3`): fall through to arms `@350` (G350). -/ -theorem tlcReachG350First {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h232 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨232⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h339 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨339⟩) (tlcSelWord I) = ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨350⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h339r⟩ := tlcReach339 (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h232 - exact ⟨_, _, by - simpa [selArmNextPc, armTgtWidth, selArmJumpiPc, selArmPushTgtPc, selArmEqPc, selArmPush4Pc] - using RD.selectorSplitNotTakenAuto h339r tlcN339SplitWF h339 (by simp)⟩ - -/-- `N339` taken (`sel < 0x134008d3`): jump 397, step jumpdest to arms `@398` (G397). -/ -theorem tlcReachG397First {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h232 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨232⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h339 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨339⟩) (tlcSelWord I) ≠ ⟨0⟩) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨398⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h339r⟩ := tlcReach339 (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h232 - have h397 := RD.selectorSplitTakenAuto h339r tlcN339SplitWF h339 (by jump_dest) (by simp) - exact ⟨_, _, h397.jumpdest (by native_decide) (by simp)⟩ - -/-! ## Per-group body reaches (dispatcher fold to a matched arm's body pc) -/ - -theorem tlcReachG51Body {cA gh bl σ σ₀ A I} {g : Sat256} - (i : ℕ) (hi : i ≤ 3) (bodyPC : UInt256) - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) = ⟨0⟩) - (h29 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨29⟩) (tlcSelWord I) = ⟨0⟩) - (h40 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨40⟩) (tlcSelWord I) = ⟨0⟩) - (heq0 : ∀ j, j < i → - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨51⟩ j)) (tlcSelWord I) = ⟨0⟩) - (htake : UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨51⟩ i)) (tlcSelWord I) ≠ ⟨0⟩) - (hjd : (D_J timelockControllerBenchBytecode 0).contains bodyPC = true) - (hbody : armTgt timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨51⟩ i) = bodyPC) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) bodyPC - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, hfirst⟩ := tlcReachG51First (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h29 h40 - exact RD.dispatchTo bodyPC i hfirst - (fun j hj => tlcG51ArmsWF j (le_trans hj hi)) heq0 htake (by simpa [hbody] using hjd) hbody - (by simp) - -theorem tlcReachG98Body {cA gh bl σ σ₀ A I} {g : Sat256} - (i : ℕ) (hi : i ≤ 2) (bodyPC : UInt256) - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) = ⟨0⟩) - (h29 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨29⟩) (tlcSelWord I) = ⟨0⟩) - (h40 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨40⟩) (tlcSelWord I) ≠ ⟨0⟩) - (heq0 : ∀ j, j < i → - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨99⟩ j)) (tlcSelWord I) = ⟨0⟩) - (htake : UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨99⟩ i)) (tlcSelWord I) ≠ ⟨0⟩) - (hjd : (D_J timelockControllerBenchBytecode 0).contains bodyPC = true) - (hbody : armTgt timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨99⟩ i) = bodyPC) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) bodyPC - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, hfirst⟩ := tlcReachG98First (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h29 h40 - exact RD.dispatchTo bodyPC i hfirst - (fun j hj => tlcG98ArmsWF j (le_trans hj hi)) heq0 htake (by simpa [hbody] using hjd) hbody - (by simp) - -theorem tlcReachG147Body {cA gh bl σ σ₀ A I} {g : Sat256} - (i : ℕ) (hi : i ≤ 3) (bodyPC : UInt256) - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) = ⟨0⟩) - (h29 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨29⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h136 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨136⟩) (tlcSelWord I) = ⟨0⟩) - (heq0 : ∀ j, j < i → - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨147⟩ j)) (tlcSelWord I) = ⟨0⟩) - (htake : UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨147⟩ i)) (tlcSelWord I) ≠ ⟨0⟩) - (hjd : (D_J timelockControllerBenchBytecode 0).contains bodyPC = true) - (hbody : armTgt timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨147⟩ i) = bodyPC) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) bodyPC - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, hfirst⟩ := tlcReachG147First (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h29 h136 - exact RD.dispatchTo bodyPC i hfirst - (fun j hj => tlcG147ArmsWF j (le_trans hj hi)) heq0 htake (by simpa [hbody] using hjd) hbody - (by simp) - -theorem tlcReachG194Body {cA gh bl σ σ₀ A I} {g : Sat256} - (i : ℕ) (hi : i ≤ 2) (bodyPC : UInt256) - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) = ⟨0⟩) - (h29 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨29⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h136 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨136⟩) (tlcSelWord I) ≠ ⟨0⟩) - (heq0 : ∀ j, j < i → - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨195⟩ j)) (tlcSelWord I) = ⟨0⟩) - (htake : UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨195⟩ i)) (tlcSelWord I) ≠ ⟨0⟩) - (hjd : (D_J timelockControllerBenchBytecode 0).contains bodyPC = true) - (hbody : armTgt timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨195⟩ i) = bodyPC) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) bodyPC - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, hfirst⟩ := tlcReachG194First (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h29 h136 - exact RD.dispatchTo bodyPC i hfirst - (fun j hj => tlcG194ArmsWF j (le_trans hj hi)) heq0 htake (by simpa [hbody] using hjd) hbody - (by simp) - -theorem tlcReachG254Body {cA gh bl σ σ₀ A I} {g : Sat256} - (i : ℕ) (hi : i ≤ 3) (bodyPC : UInt256) - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h232 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨232⟩) (tlcSelWord I) = ⟨0⟩) - (h243 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨243⟩) (tlcSelWord I) = ⟨0⟩) - (heq0 : ∀ j, j < i → - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨254⟩ j)) (tlcSelWord I) = ⟨0⟩) - (htake : UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨254⟩ i)) (tlcSelWord I) ≠ ⟨0⟩) - (hjd : (D_J timelockControllerBenchBytecode 0).contains bodyPC = true) - (hbody : armTgt timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨254⟩ i) = bodyPC) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) bodyPC - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, hfirst⟩ := tlcReachG254First (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h232 h243 - exact RD.dispatchTo bodyPC i hfirst - (fun j hj => tlcG254ArmsWF j (le_trans hj hi)) heq0 htake (by simpa [hbody] using hjd) hbody - (by simp) - -theorem tlcReachG301Body {cA gh bl σ σ₀ A I} {g : Sat256} - (i : ℕ) (hi : i ≤ 2) (bodyPC : UInt256) - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h232 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨232⟩) (tlcSelWord I) = ⟨0⟩) - (h243 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨243⟩) (tlcSelWord I) ≠ ⟨0⟩) - (heq0 : ∀ j, j < i → - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨302⟩ j)) (tlcSelWord I) = ⟨0⟩) - (htake : UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨302⟩ i)) (tlcSelWord I) ≠ ⟨0⟩) - (hjd : (D_J timelockControllerBenchBytecode 0).contains bodyPC = true) - (hbody : armTgt timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨302⟩ i) = bodyPC) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) bodyPC - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, hfirst⟩ := tlcReachG301First (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h232 h243 - exact RD.dispatchTo bodyPC i hfirst - (fun j hj => tlcG301ArmsWF j (le_trans hj hi)) heq0 htake (by simpa [hbody] using hjd) hbody - (by simp) - -theorem tlcReachG350Body {cA gh bl σ σ₀ A I} {g : Sat256} - (i : ℕ) (hi : i ≤ 3) (bodyPC : UInt256) - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h232 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨232⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h339 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨339⟩) (tlcSelWord I) = ⟨0⟩) - (heq0 : ∀ j, j < i → - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨350⟩ j)) (tlcSelWord I) = ⟨0⟩) - (htake : UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨350⟩ i)) (tlcSelWord I) ≠ ⟨0⟩) - (hjd : (D_J timelockControllerBenchBytecode 0).contains bodyPC = true) - (hbody : armTgt timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨350⟩ i) = bodyPC) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) bodyPC - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, hfirst⟩ := tlcReachG350First (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h232 h339 - exact RD.dispatchTo bodyPC i hfirst - (fun j hj => tlcG350ArmsWF j (le_trans hj hi)) heq0 htake (by simpa [hbody] using hjd) hbody - (by simp) - -theorem tlcReachG397Body {cA gh bl σ σ₀ A I} {g : Sat256} - (i : ℕ) (hi : i ≤ 2) (bodyPC : UInt256) - (hcode : I.code = timelockControllerBenchBytecode) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h232 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨232⟩) (tlcSelWord I) ≠ ⟨0⟩) - (h339 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨339⟩) (tlcSelWord I) ≠ ⟨0⟩) - (heq0 : ∀ j, j < i → - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨398⟩ j)) (tlcSelWord I) = ⟨0⟩) - (htake : UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨398⟩ i)) (tlcSelWord I) ≠ ⟨0⟩) - (hjd : (D_J timelockControllerBenchBytecode 0).contains bodyPC = true) - (hbody : armTgt timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨398⟩ i) = bodyPC) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) bodyPC - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, hfirst⟩ := tlcReachG397First (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hroot h232 h339 - exact RD.dispatchTo bodyPC i hfirst - (fun j hj => tlcG397ArmsWF j (le_trans hj hi)) heq0 htake (by simpa [hbody] using hjd) hbody - (by simp) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/EvmExec.lean b/Benchmarks/OpenZeppelinBench/TimelockController/EvmExec.lean deleted file mode 100644 index dd4bfb09..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/EvmExec.lean +++ /dev/null @@ -1,194 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.EvmReach -import Benchmarks.OpenZeppelinBench.TimelockController.Body -import Benchmarks.OpenZeppelinBench.TimelockController.Return - -/-! -# OpenZeppelin TimelockController `hashOperation` EVM execute path (@988 → keccak → return) - -`tlcHashOperationX_ok`: on well-formed calldata with zero callvalue, the runtime decodes -`(address,uint256,bytes,bytes32,bytes32)`, re-`abi.encode`s the canonical tuple into `mem[0xa0..]`, -`KECCAK256`s `mem[0xa0, 192 + roundUp₃₂ len]`, and `RETURN`s the 32-byte hash — -`= keccak256(tlcHashOpCanonBytes I)`, the same preimage as the Solm side. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- The 32-byte `hashOperation` result as an EVM word: `keccak256` of the canonical ABI encoding. -/ -abbrev tlcHashOpKecWord (I : ExecutionEnv) : UInt256 := - UInt256.ofNat (fromByteArrayBigEndian (ffi.KEC (tlcHashOpCanonBytes I))) - -/-! ## Decoder trace (988 → 1015): decode `(address,uint256,bytes,bytes32,bytes32)` -/ - -/-- Decoder checkpoint 4600 → 4630: length availability check + address decode (subroutine 4356). -/ -private theorem tlcHashOpDecode4630 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (hsize : I.calldata.size < UInt256.size) (hwf : tlcHashOpWF I) - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4600⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4630⟩ - [calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, - ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - have hslt1 : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨160⟩ = ⟨0⟩ := by - have h := solcCalldataStaticLenCheckOk (sz := I.calldata.size) (words := 5) - (by have := hwf.head; omega) (by have := hwf.small; omega) hsize - simpa using h - have hmaskEq : UInt256.sub (UInt256.shiftLeft ⟨1⟩ ⟨160⟩) ⟨1⟩ = solcAddrMask := by native_decide - have hAddrCond : UInt256.eq (calldataWord I.calldata 4) - (UInt256.land (calldataWord I.calldata 4) - (UInt256.sub (UInt256.shiftLeft ⟨1⟩ ⟨160⟩) ⟨1⟩)) ≠ ⟨0⟩ := by - rw [hmaskEq, solcAddrCanon_eq hwf.clean]; decide - exact ⟨_, _, evm_run h with [ - jumpdest, push0, push0, push0, push0, push0, push0, push1 ⟨160⟩, dup8, dup10, sub, slt, iszero, - push2 ⟨4621⟩, jumpiT (by rw [hslt1]; decide) (by jump_dest), - jumpdest, push2 ⟨4630⟩, dup8, push2 ⟨4356⟩, jump (by jump_dest), - jumpdest, dup1, calldataload, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup2, and, dup2, eq, - push2 ⟨4378⟩, jumpiT hAddrCond (by jump_dest), - jumpdest, swap2, swap1, pop, jump (by jump_dest)]⟩ - -/-- Decoder checkpoint 4630 → 4664: decode value (@cd36) and bytes offset (@cd68), offset ≤ 2^64. -/ -private theorem tlcHashOpDecode4664 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (hwf : tlcHashOpWF I) - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4630⟩ - [calldataWord I.calldata 4, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, - ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4664⟩ - [calldataWord I.calldata 68, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, calldataWord I.calldata 36, - calldataWord I.calldata 4, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - have hu64 : UInt256.sub (UInt256.shiftLeft ⟨1⟩ ⟨64⟩) ⟨1⟩ = ⟨18446744073709551615⟩ := by native_decide - have hu64tn : (⟨18446744073709551615⟩ : UInt256).toNat = ABI.solcMaxU64 := rfl - have e68 : ((⟨4⟩ : UInt256) + ⟨64⟩).toNat = 68 := by native_decide - have hgtOff : UInt256.gt (calldataWord I.calldata 68) ⟨18446744073709551615⟩ = ⟨0⟩ := - ugt_zero (by rw [hu64tn]; exact hwf.offMax) - exact ⟨_, _, evm_run h with [ - jumpdest, swap6, pop, push1 ⟨32⟩, dup8, add, calldataload, swap5, pop, push1 ⟨64⟩, dup8, add, - calldataload, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, gt, iszero, push2 ⟨4663⟩, - jumpiT (by rw [hu64, e68, hgtOff]; decide) (by jump_dest), jumpdest]⟩ - -/-- Decoder checkpoint 4664 → 4676: decode the dynamic `bytes` (subroutine 4383): length-word - availability, `len ≤ 2^64`, payload availability. Length offset normalized via `s4`. -/ -private theorem tlcHashOpDecode4676 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (hsize : I.calldata.size < UInt256.size) (hwf : tlcHashOpWF I) - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4664⟩ - [calldataWord I.calldata 68, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, calldataWord I.calldata 36, - calldataWord I.calldata 4, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4676⟩ - [calldataWord I.calldata (4 + (calldataWord I.calldata 68).toNat), - ⟨4⟩ + calldataWord I.calldata 68 + ⟨32⟩, calldataWord I.calldata 68, - ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, calldataWord I.calldata 36, calldataWord I.calldata 4, ⟨4⟩, - UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - have hu64 : UInt256.sub (UInt256.shiftLeft ⟨1⟩ ⟨64⟩) ⟨1⟩ = ⟨18446744073709551615⟩ := by native_decide - have hu64tn : (⟨18446744073709551615⟩ : UInt256).toNat = ABI.solcMaxU64 := rfl - have hoffN : (calldataWord I.calldata 68).toNat ≤ 18446744073709551615 := hwf.offMax - have hlenWordN : 4 + (calldataWord I.calldata 68).toNat + 32 ≤ I.calldata.size := hwf.lenWord - have hpayN : 4 + (calldataWord I.calldata 68).toNat - + (calldataWord I.calldata (4 + (calldataWord I.calldata 68).toNat)).toNat + 32 - ≤ I.calldata.size := by - have h := hwf.payload; simp only [tlcHashOpArgOff, tlcHashOpArgLen] at h; omega - have s4 : ((⟨4⟩ : UInt256) + calldataWord I.calldata 68).toNat - = 4 + (calldataWord I.calldata 68).toNat := by - rw [uadd_toNat, show (⟨4⟩ : UInt256).toNat = 4 from rfl] - exact Nat.mod_eq_of_lt (by simp only [UInt256.size]; omega) - have hslt78 : UInt256.slt (⟨4⟩ + calldataWord I.calldata 68 + ⟨31⟩) - (UInt256.ofNat I.calldata.size) = ⟨1⟩ := by - apply slt_lit_one_low hwf.small - rw [uadd_toNat, s4, show (⟨31⟩ : UInt256).toNat = 31 from rfl, - Nat.mod_eq_of_lt (by simp only [UInt256.size]; omega)] - omega - have hgtLen : UInt256.gt (calldataWord I.calldata (4 + (calldataWord I.calldata 68).toNat)) - ⟨18446744073709551615⟩ = ⟨0⟩ := ugt_zero (by rw [hu64tn]; exact hwf.lenMax) - have sAll : ((⟨4⟩:UInt256) + calldataWord I.calldata 68 - + calldataWord I.calldata (4 + (calldataWord I.calldata 68).toNat) + ⟨32⟩).toNat - = 4 + (calldataWord I.calldata 68).toNat - + (calldataWord I.calldata (4 + (calldataWord I.calldata 68).toNat)).toNat + 32 := by - have hsz2 : I.calldata.size < UInt256.size := hsize - rw [uadd_toNat, uadd_toNat, s4, show (⟨32⟩:UInt256).toNat = 32 from rfl] - simp only [UInt256.size] at hsz2 ⊢; omega - have hgtPay : UInt256.gt (⟨4⟩ + calldataWord I.calldata 68 - + calldataWord I.calldata (4 + (calldataWord I.calldata 68).toNat) + ⟨32⟩) - (UInt256.ofNat I.calldata.size) = ⟨0⟩ := - ugt_zero (by rw [sAll, ulit_toNat' _ hsize]; exact hpayN) - have rd := evm_run h with [ - push2 ⟨4675⟩, dup10, dup3, dup11, add, push2 ⟨4383⟩, jump (by jump_dest), - jumpdest, push0, push0, dup4, push1 ⟨31⟩, dup5, add, slt, push2 ⟨4399⟩, - jumpiT (by rw [hslt78]; decide) (by jump_dest), - jumpdest, pop, dup2, calldataload, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, gt, iszero, - push2 ⟨4421⟩, jumpiT (by rw [hu64, s4, hgtLen]; decide) (by jump_dest), - jumpdest, push1 ⟨32⟩, dup4, add, swap2, pop, dup4, push1 ⟨32⟩, dup3, dup6, add, add, gt, iszero, - push2 ⟨4444⟩, jumpiT (by rw [s4, hgtPay]; decide) (by jump_dest), - jumpdest, swap3, pop, swap3, swap1, pop, jump (by jump_dest), jumpdest] - rw [s4] at rd - exact ⟨_, _, rd⟩ - -/-- Decoder checkpoint 4676 → 1015: final shuffle, load predecessor (@cd100) and salt (@cd132), - return to the body dispatcher. Offsets normalized to 100/132. -/ -private theorem tlcHashOpDecode1015 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4676⟩ - [calldataWord I.calldata (4 + (calldataWord I.calldata 68).toNat), - ⟨4⟩ + calldataWord I.calldata 68 + ⟨32⟩, calldataWord I.calldata 68, - ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, calldataWord I.calldata 36, calldataWord I.calldata 4, ⟨4⟩, - UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1015⟩ - [calldataWord I.calldata 132, calldataWord I.calldata 100, - calldataWord I.calldata (4 + (calldataWord I.calldata 68).toNat), - ⟨4⟩ + calldataWord I.calldata 68 + ⟨32⟩, calldataWord I.calldata 36, - calldataWord I.calldata 4, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - have e100 : ((⟨4⟩ : UInt256) + ⟨96⟩).toNat = 100 := by native_decide - have e132 : ((⟨4⟩ : UInt256) + ⟨128⟩).toNat = 132 := by native_decide - have rd := evm_run h with [ - swap8, swap11, swap7, swap10, pop, swap8, push1 ⟨96⟩, dup2, add, calldataload, - swap7, push1 ⟨128⟩, swap1, swap2, add, calldataload, swap6, pop, swap4, pop, pop, pop, pop, - jump (by jump_dest), jumpdest] - rw [e100, e132] at rd - exact ⟨_, _, rd⟩ - -/-! ## Hash driver + encoder (1015 → 5934 → encode → 2354 KECCAK256 → 581) -/ - -/-- Hash driver 1015 → 5934: build the encoder argument frame, load the free pointer `0x80`, - push encoder dest `0xa0` and return address `2332`. -/ -private theorem tlcHashOpDrive5934 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1015⟩ - [calldataWord I.calldata 132, calldataWord I.calldata 100, - calldataWord I.calldata (4 + (calldataWord I.calldata 68).toNat), - ⟨4⟩ + calldataWord I.calldata 68 + ⟨32⟩, calldataWord I.calldata 36, - calldataWord I.calldata 4, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨5934⟩ - [⟨32⟩ + ⟨128⟩, calldataWord I.calldata 132, calldataWord I.calldata 100, - calldataWord I.calldata (4 + (calldataWord I.calldata 68).toNat), - ⟨4⟩ + calldataWord I.calldata 68 + ⟨32⟩, calldataWord I.calldata 36, - calldataWord I.calldata 4, ⟨2332⟩, ⟨0⟩, calldataWord I.calldata 132, - calldataWord I.calldata 100, calldataWord I.calldata (4 + (calldataWord I.calldata 68).toNat), - ⟨4⟩ + calldataWord I.calldata 68 + ⟨32⟩, calldataWord I.calldata 36, - calldataWord I.calldata 4, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run h with [ - push2 ⟨2304⟩, jump (by jump_dest), jumpdest, push0, dup7, dup7, dup7, dup7, dup7, dup7, - push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost solcFreePtrMem_mload64 - (by decide) (by evm_ov), - push1 ⟨32⟩, add, push2 ⟨2332⟩, swap7, swap6, swap5, swap4, swap3, swap2, swap1, - push2 ⟨5933⟩, jump (by jump_dest), jumpdest]⟩ - -/-- EVM execute path: with zero callvalue and well-formed calldata, `hashOperation` returns - `keccak256(abi.encode(target,value,data,predecessor,salt))`. -/ -theorem tlcHashOperationX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 13)) - (hwf : tlcHashOpWF I) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (tlcHashOpKecWord I)) := by - sorry - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/EvmReach.lean b/Benchmarks/OpenZeppelinBench/TimelockController/EvmReach.lean deleted file mode 100644 index 20f56b89..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/EvmReach.lean +++ /dev/null @@ -1,49 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `hashOperation` EVM reach lemmas (shared) - -Reach the `hashOperation` body (pc 988, G194 arm 0) and set up the external 5-arg decoder call -(pc 4600). Shared by the execute-path (`EvmExec`) and revert-path (`EvmReverts`) proofs. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- Reach the `hashOperation` body pc 988 (G194 arm 0, selector `0x8065657f`). -/ -theorem tlcReachHashOperation {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 13)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨988⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x8065657f⟩ := - solcSelectorWord_eq_of_beq I hsz 0x80 0x65 0x65 0x7f ⟨0x8065657f⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG194Body 0 (by omega) ⟨988⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; omega) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Peel the non-payable guard and set up the decoder call: reach pc 4600 with the decoder's - argument stack `[4, size, 1014, 581, sel]` (offset, calldatasize, decoder-return, final-return). -/ -theorem tlcHashOpReachDecoder {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 13)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4600⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h988⟩ := tlcReachHashOperation (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h1001⟩ := tlcGuardPeelOk (gt := ⟨999⟩) h988 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, evm_run h1001 with [ - push2 ⟨581⟩, push2 ⟨1014⟩, calldatasize, push1 ⟨4⟩, push2 ⟨4600⟩, jump (by jump_dest)]⟩ - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/EvmReverts.lean b/Benchmarks/OpenZeppelinBench/TimelockController/EvmReverts.lean deleted file mode 100644 index 16566e80..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/EvmReverts.lean +++ /dev/null @@ -1,335 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.EvmReach -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.AbiDecode - -/-! -# OpenZeppelin TimelockController `hashOperation` EVM revert paths (malformed calldata) - -`tlcHashOperationDecodeFail`: when the calldata is not well-formed (`¬ tlcHashOpWF I`) and callvalue -is zero, the EVM external decoder reverts at one of its four checks (short head / dirty address / -bytes-offset > 2^64 / bytes length-or-payload OOB) and the Solm `decodeCalldata` returns `none` -(the `tlcDecodeHashOperation_none_*` lemmas), routed through `tlcReEquivDecodeFailed`. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Shared decoder reach-checkpoints (from pc 4600, the 5-arg external decoder) -/ - -/-- Pass the head-length check `SLT(size-4, 160)=0` @4617: reach pc 4621. -/ -private theorem tlcHashOpReach4621 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (rd : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4600⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hc1 : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨160⟩ = ⟨0⟩) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4621⟩ - [⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, - tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, evm_run rd with [ - jumpdest, push0, push0, push0, push0, push0, push0, push1 ⟨160⟩, dup8, dup10, sub, slt, - iszero, push2 ⟨4621⟩, jumpiT (by rw [hc1]; decide) (by jump_dest)]⟩ - -/-- Pass the head check and the address canonicalization subroutine (`EQ(w4, w4∧mask)=1` @4374, - clean address): reach pc 4630 with the decoded address word on top. -/ -private theorem tlcHashOpReach4630 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (rd : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4600⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hc1 : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨160⟩ = ⟨0⟩) - (hclean : (calldataWord I.calldata 4).toNat < EVM.addressModulus) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4630⟩ - [uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32), - ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, - tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - obtain ⟨_, _, h4621⟩ := tlcHashOpReach4621 rd hc1 - have hcleanEq : UInt256.eq (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - (UInt256.land (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) ≠ ⟨0⟩ := by - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide, - show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask from by decide, - solcAddrCanon_eq hclean] - decide - exact ⟨_, _, evm_run h4621 with [ - jumpdest, push2 ⟨4630⟩, dup8, push2 ⟨4356⟩, jump (by jump_dest), - jumpdest, dup1, calldataload, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup2, and, dup2, eq, - push2 ⟨4378⟩, jumpiT hcleanEq (by jump_dest), - jumpdest, swap2, swap1, pop, jump (by jump_dest)]⟩ - -/-- Pass the head + address + `bytes` offset checks (`GT(off, 2^64-1)=0` @4659, `off ≤ 2^64-1`): - reach pc 4663 with the offset word on top. -/ -private theorem tlcHashOpReach4663 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (rd : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4600⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hc1 : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨160⟩ = ⟨0⟩) - (hclean : (calldataWord I.calldata 4).toNat < EVM.addressModulus) - (hoffMax : tlcHashOpArgOff I ≤ solcMaxU64) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4663⟩ - [uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32), - ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, - uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨32⟩).toNat 32), - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32), - ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, - tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - obtain ⟨_, _, h4630⟩ := tlcHashOpReach4630 rd hc1 hclean - have hgt0 : UInt256.gt (uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - rw [show (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = solcMaxU64 from - by decide, - show ((⟨4⟩ : UInt256) + ⟨64⟩).toNat = 68 from by decide] - exact hoffMax - exact ⟨_, _, evm_run h4630 with [ - jumpdest, swap6, pop, push1 ⟨32⟩, dup8, add, calldataload, swap5, pop, push1 ⟨64⟩, dup8, add, - calldataload, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, gt, iszero, push2 ⟨4663⟩, - jumpiT (by rw [hgt0]; decide) (by jump_dest)]⟩ - -/-- Pass head + address + offset + the `bytes` length-word availability check - (`SLT(4+off+31, size)=1` @4395, `4+off+32 ≤ size < 2^255`): reach pc 4399, inside the - length-decoder subroutine, past the availability check. -/ -private theorem tlcHashOpReach4399 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (rd : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4600⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hc1 : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨160⟩ = ⟨0⟩) - (hclean : (calldataWord I.calldata 4).toNat < EVM.addressModulus) - (hoffMax : tlcHashOpArgOff I ≤ solcMaxU64) (hsmall : I.calldata.size < 2 ^ 255) - (hlenWord : 4 + tlcHashOpArgOff I + 32 ≤ I.calldata.size) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4399⟩ - [⟨0⟩, ⟨0⟩, - (⟨4⟩ : UInt256) + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32), - UInt256.ofNat I.calldata.size, ⟨4675⟩, - uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32), - ⟨0⟩, ⟨0⟩, ⟨0⟩, ⟨0⟩, - uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨32⟩).toNat 32), - uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32), - ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, - tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - obtain ⟨_, _, h4663⟩ := tlcHashOpReach4663 rd hc1 hclean hoffMax - have hw68 : (uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32)).toNat - = tlcHashOpArgOff I := by - rw [show ((⟨4⟩ : UInt256) + ⟨64⟩).toNat = 68 from by decide] - have hbound : ((⟨4⟩ : UInt256) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32) + ⟨31⟩).toNat - = 4 + tlcHashOpArgOff I + 31 := by - rw [uadd_toNat, uadd_toNat, hw68, show (⟨4⟩ : UInt256).toNat = 4 from by decide, - show (⟨31⟩ : UInt256).toNat = 31 from by decide] - have hmax : solcMaxU64 = 18446744073709551615 := by decide - have hleft : (4 + tlcHashOpArgOff I) % UInt256.size = 4 + tlcHashOpArgOff I := - Nat.mod_eq_of_lt (by rw [show UInt256.size = 2 ^ 256 from rfl]; omega) - rw [hleft] - exact Nat.mod_eq_of_lt (by rw [show UInt256.size = 2 ^ 256 from rfl]; omega) - have hslt1 : UInt256.slt ((⟨4⟩ : UInt256) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32) + ⟨31⟩) - (UInt256.ofNat I.calldata.size) = ⟨1⟩ := by - apply slt_lit_one_low hsmall - rw [hbound]; omega - exact ⟨_, _, evm_run h4663 with [ - jumpdest, push2 ⟨4675⟩, dup10, dup3, dup11, add, push2 ⟨4383⟩, jump (by jump_dest), - jumpdest, push0, push0, dup4, push1 ⟨31⟩, dup5, add, slt, push2 ⟨4399⟩, - jumpiT (by rw [hslt1]; decide) (by jump_dest)]⟩ - -/-! ## Per-case EVM reverts (each fails one decoder check via `jumpiNT` + the `PUSH0 PUSH0 REVERT`) -/ - -/-- Head-length check @4617 fails (`SLT(size-4,160)=1`): `size < 164` or `2^255+4 ≤ size`. -/ -private theorem tlcHashOpRevCheck1 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (rd : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4600⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hc1rev : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨160⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := - evm_run rd with [ - jumpdest, push0, push0, push0, push0, push0, push0, push1 ⟨160⟩, dup8, dup10, sub, slt, - iszero, push2 ⟨4621⟩, jumpiNT (by rw [hc1rev]; decide), - raw revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov)] - -/-- Address canonicalization check @4374 fails (`EQ(w4, w4∧mask)=0`): dirty address. -/ -private theorem tlcHashOpRevDirtyAddr {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (rd : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4600⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hc1 : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨160⟩ = ⟨0⟩) - (hdirty : EVM.addressModulus ≤ (calldataWord I.calldata 4).toNat) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4621⟩ := tlcHashOpReach4621 rd hc1 - have e4 : uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32) - = calldataWord I.calldata 4 := by rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - have hdirtyEq : UInt256.eq (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - (UInt256.land (uInt256OfByteArray (I.calldata.readBytes (⟨4⟩ : UInt256).toNat 32)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) = ⟨0⟩ := by - rw [e4, show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask from - by decide] - apply uInt256_eq_zero_of_ne - intro hone - exact absurd (solcAddrCanonical_of_clean hone) (by omega) - exact evm_run h4621 with [ - jumpdest, push2 ⟨4630⟩, dup8, push2 ⟨4356⟩, jump (by jump_dest), - jumpdest, dup1, calldataload, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup2, and, dup2, eq, - push2 ⟨4378⟩, jumpiNT (by rw [hdirtyEq]), - raw revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov)] - -/-- `bytes` offset check @4659 fails (`GT(off, 2^64-1)=1`): `off > 2^64-1`. -/ -private theorem tlcHashOpRevOffset {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (rd : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4600⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hc1 : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨160⟩ = ⟨0⟩) - (hclean : (calldataWord I.calldata 4).toNat < EVM.addressModulus) - (hoff : solcMaxU64 < tlcHashOpArgOff I) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4630⟩ := tlcHashOpReach4630 rd hc1 hclean - have hgt1 : UInt256.gt (uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨1⟩ := by - apply ugt_one - rw [show (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = solcMaxU64 from - by decide, - show ((⟨4⟩ : UInt256) + ⟨64⟩).toNat = 68 from by decide] - exact hoff - exact evm_run h4630 with [ - jumpdest, swap6, pop, push1 ⟨32⟩, dup8, add, calldataload, swap5, pop, push1 ⟨64⟩, dup8, add, - calldataload, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, gt, iszero, push2 ⟨4663⟩, - jumpiNT (by rw [hgt1]; decide), - raw revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov)] - -/-- `bytes` length-word availability check @4395 fails (`SLT(4+off+31, size)=0`, unavailable): - `size < 4 + off + 32` (with `off ≤ 2^64-1`, `size < 2^255`). -/ -private theorem tlcHashOpRevLenWord {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (rd : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4600⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hc1 : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨160⟩ = ⟨0⟩) - (hclean : (calldataWord I.calldata 4).toNat < EVM.addressModulus) - (hoffMax : tlcHashOpArgOff I ≤ solcMaxU64) (hsmall : I.calldata.size < 2 ^ 255) - (hlenWordRev : I.calldata.size < 4 + tlcHashOpArgOff I + 32) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4663⟩ := tlcHashOpReach4663 rd hc1 hclean hoffMax - have hw68 : (uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32)).toNat - = tlcHashOpArgOff I := by - rw [show ((⟨4⟩ : UInt256) + ⟨64⟩).toNat = 68 from by decide] - have hbound : ((⟨4⟩ : UInt256) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32) + ⟨31⟩).toNat - = 4 + tlcHashOpArgOff I + 31 := by - rw [uadd_toNat, uadd_toNat, hw68, show (⟨4⟩ : UInt256).toNat = 4 from by decide, - show (⟨31⟩ : UInt256).toNat = 31 from by decide] - have hmax : solcMaxU64 = 18446744073709551615 := by decide - have hleft : (4 + tlcHashOpArgOff I) % UInt256.size = 4 + tlcHashOpArgOff I := - Nat.mod_eq_of_lt (by rw [show UInt256.size = 2 ^ 256 from rfl]; omega) - rw [hleft] - exact Nat.mod_eq_of_lt (by rw [show UInt256.size = 2 ^ 256 from rfl]; omega) - have hmax : solcMaxU64 = 18446744073709551615 := by decide - have hsltRev : UInt256.slt ((⟨4⟩ : UInt256) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32) + ⟨31⟩) - (UInt256.ofNat I.calldata.size) = ⟨0⟩ := by - apply slt_lit_zero hsmall <;> rw [hbound] <;> omega - exact evm_run h4663 with [ - jumpdest, push2 ⟨4675⟩, dup10, dup3, dup11, add, push2 ⟨4383⟩, jump (by jump_dest), - jumpdest, push0, push0, dup4, push1 ⟨31⟩, dup5, add, slt, push2 ⟨4399⟩, jumpiNT hsltRev, - raw revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov)] - -/-- `bytes` length check @4417 fails (`GT(len, 2^64-1)=1`): `len > 2^64-1`. -/ -private theorem tlcHashOpRevLenBig {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (rd : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4600⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hc1 : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨160⟩ = ⟨0⟩) - (hclean : (calldataWord I.calldata 4).toNat < EVM.addressModulus) - (hoffMax : tlcHashOpArgOff I ≤ solcMaxU64) (hsmall : I.calldata.size < 2 ^ 255) - (hlenWord : 4 + tlcHashOpArgOff I + 32 ≤ I.calldata.size) - (hlenBig : solcMaxU64 < tlcHashOpArgLen I) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4399⟩ := tlcHashOpReach4399 rd hc1 hclean hoffMax hsmall hlenWord - have hw68 : (uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32)).toNat - = tlcHashOpArgOff I := by rw [show ((⟨4⟩ : UInt256) + ⟨64⟩).toNat = 68 from by decide] - have h4off : ((⟨4⟩ : UInt256) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32)).toNat - = 4 + tlcHashOpArgOff I := by - rw [uadd_toNat, hw68, show (⟨4⟩ : UInt256).toNat = 4 from by decide] - have hmax : solcMaxU64 = 18446744073709551615 := by decide - exact Nat.mod_eq_of_lt (by rw [show UInt256.size = 2 ^ 256 from rfl]; omega) - have hgtLen1 : UInt256.gt (uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32)).toNat 32)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨1⟩ := by - apply ugt_one - rw [show (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = solcMaxU64 from - by decide, h4off] - exact hlenBig - exact evm_run h4399 with [ - jumpdest, pop, dup2, calldataload, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, gt, - iszero, push2 ⟨4421⟩, jumpiNT (by rw [hgtLen1]; decide), - raw revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov)] - -/-- `bytes` payload availability check @4440 fails (`GT(4+off+32+len, size)=1`, payload OOB): - `size < 4 + off + 32 + len` (`len ≤ 2^64-1` so the length check @4417 passes). -/ -private theorem tlcHashOpRevPayload {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (rd : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4600⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1014⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hc1 : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨160⟩ = ⟨0⟩) - (hclean : (calldataWord I.calldata 4).toNat < EVM.addressModulus) - (hoffMax : tlcHashOpArgOff I ≤ solcMaxU64) (hsmall : I.calldata.size < 2 ^ 255) - (hlenWord : 4 + tlcHashOpArgOff I + 32 ≤ I.calldata.size) - (hlenMax : tlcHashOpArgLen I ≤ solcMaxU64) - (hpay : I.calldata.size < 4 + tlcHashOpArgOff I + 32 + tlcHashOpArgLen I) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4399⟩ := tlcHashOpReach4399 rd hc1 hclean hoffMax hsmall hlenWord - have hw68 : (uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32)).toNat - = tlcHashOpArgOff I := by rw [show ((⟨4⟩ : UInt256) + ⟨64⟩).toNat = 68 from by decide] - have h4off : ((⟨4⟩ : UInt256) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32)).toNat - = 4 + tlcHashOpArgOff I := by - rw [uadd_toNat, hw68, show (⟨4⟩ : UInt256).toNat = 4 from by decide] - have hmax : solcMaxU64 = 18446744073709551615 := by decide - exact Nat.mod_eq_of_lt (by rw [show UInt256.size = 2 ^ 256 from rfl]; omega) - have hgtLen0 : UInt256.gt (uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32)).toNat 32)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩) = ⟨0⟩ := by - apply ugt_zero - rw [show (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨64⟩) ⟨1⟩).toNat = solcMaxU64 from - by decide, h4off] - exact hlenMax - have hwlen : (uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32)).toNat 32)).toNat - = tlcHashOpArgLen I := by rw [h4off] - have hpayNat : ((⟨4⟩ : UInt256) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32)).toNat 32) - + ⟨32⟩).toNat = 4 + tlcHashOpArgOff I + tlcHashOpArgLen I + 32 := by - rw [uadd_toNat, uadd_toNat, hwlen, h4off, show (⟨32⟩ : UInt256).toNat = 32 from by decide] - have hmax : solcMaxU64 = 18446744073709551615 := by decide - have hinner : (4 + tlcHashOpArgOff I + tlcHashOpArgLen I) % UInt256.size - = 4 + tlcHashOpArgOff I + tlcHashOpArgLen I := - Nat.mod_eq_of_lt (by rw [show UInt256.size = 2 ^ 256 from rfl]; omega) - rw [hinner] - exact Nat.mod_eq_of_lt (by rw [show UInt256.size = 2 ^ 256 from rfl]; omega) - have hpayGt1 : UInt256.gt ((⟨4⟩ : UInt256) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) - + uInt256OfByteArray (I.calldata.readBytes ((⟨4⟩ : UInt256) + ⟨64⟩).toNat 32)).toNat 32) - + ⟨32⟩) (UInt256.ofNat I.calldata.size) = ⟨1⟩ := by - apply ugt_one - rw [hpayNat, ulit_toNat' I.calldata.size (by rw [show UInt256.size = 2 ^ 256 from rfl]; omega)] - omega - have h4421 := evm_run h4399 with [ - jumpdest, pop, dup2, calldataload, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨64⟩, shl, sub, dup2, gt, - iszero, push2 ⟨4421⟩, jumpiT (by rw [hgtLen0]; decide) (by jump_dest)] - exact evm_run h4421 with [ - jumpdest, push1 ⟨32⟩, dup4, add, swap2, pop, dup4, push1 ⟨32⟩, dup3, dup6, add, add, gt, - iszero, push2 ⟨4444⟩, jumpiNT (by rw [hpayGt1]; decide), - raw revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov)] - -/-- Not-well-formed calldata (with zero callvalue): the EVM external decoder reverts and the Solm - `decodeCalldata` returns `none`. -/ -theorem tlcHashOperationDecodeFail {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 13)) (hnwf : ¬ tlcHashOpWF I) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Execute.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Execute.lean deleted file mode 100644 index a9f6d2df..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Execute.lean +++ /dev/null @@ -1,19 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace OpenZeppelinBench.TimelockController - -/-- Refinement of `Execute` (selector index 4). -/ -theorem tlcExecuteBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 4)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ExecuteBatch.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ExecuteBatch.lean deleted file mode 100644 index 75a3610d..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ExecuteBatch.lean +++ /dev/null @@ -1,19 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace OpenZeppelinBench.TimelockController - -/-- Refinement of `ExecuteBatch` (selector index 3). -/ -theorem tlcExecuteBatchBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 3)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ExecutorRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ExecutorRole.lean deleted file mode 100644 index 9e33380e..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ExecutorRole.lean +++ /dev/null @@ -1,102 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Return -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `EXECUTOR_ROLE()` refinement - -`EXECUTOR_ROLE` is a public non-payable `bytes32` constant getter (selector index 5, dispatch group -G397 arm 2, body pc 530). It returns `keccak256("EXECUTOR_ROLE")`. Copied from the `PROPOSER_ROLE` -template. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- `keccak256("EXECUTOR_ROLE")` as an EVM word (the `PUSH32` constant at pc 543). -/ -def tlcExecutorRoleWord : UInt256 := - ⟨0xd8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e63⟩ - -theorem tlcDecodeExecutorRole {I : ExecutionEnv} (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (executorRoleTransition.params.map Param.name) - (transitionSignature executorRoleTransition).paramTypes I.calldata = some ∅ := by - show decodeCalldataWithMode config.abiDecodeMode [] [] I.calldata = some (∅ : Store) - exact decodeCalldataWithMode_empty_ok hsz - -/-- Reach the `EXECUTOR_ROLE` body pc 530 (G397 arm 2). -/ -theorem tlcReachExecutorRole {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 5)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨530⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x07bd0265⟩ := - solcSelectorWord_eq_of_beq I hsz 0x07 0xbd 0x02 0x65 ⟨0x07bd0265⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG397Body 2 (by omega) ⟨530⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j <;> (rw [hsw]; native_decide)) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- EVM: with zero callvalue, `EXECUTOR_ROLE()` returns the 32-byte role hash. -/ -theorem tlcExecutorRoleX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 5)) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray tlcExecutorRoleWord) := by - obtain ⟨_, _, h530⟩ := tlcReachExecutorRole (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h543⟩ := tlcGuardPeelOk (gt := ⟨541⟩) h530 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - have h581 := h543.push2 ⟨581⟩ (by native_decide) (by simp) - |>.pushConst tlcExecutorRoleWord (op := .PUSH32) (width := 32) (by decide) - (by native_decide) (by simp) - |>.dup2 (by native_decide) (by simp) - |>.jump (by native_decide) (by jump_dest) (by simp) - exact tlcReturnWord h581 (by simp) - -/-- The Solm `EXECUTOR_ROLE()` body returns the constant `bytes32`. -/ -theorem tlcExecutorRoleBodyReturns (evm : EVM.State) (locals : Store) - (h : evm.executionEnv.weiValue = ⟨0⟩) : - ExecTransitionBody config contract evm locals executorRoleTransition.body - (.returned { contract := contract, locals := locals } evm - (some [(.fixedBytes bytes32Width (EVM.Word.toBytesBE tlcExecutorRoleWord))])) := by - have hbody : executorRoleTransition.body = - [ Stmt.require (.binary .eq (.env .callvalue) (.intLit 0)), - Stmt.return [Expr.fixedBytesLit bytes32Width (EVM.Word.toBytesBE tlcExecutorRoleWord)] ] := by - native_decide - rw [hbody] - exact nonpayableFixedBytesLiteralBodyReturns (cfg := config) (contract := contract) - evm locals bytes32Width (EVM.Word.toBytesBE tlcExecutorRoleWord) h - -/-- Refinement of `ExecutorRole` (selector index 5). -/ -theorem tlcExecutorRoleBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 5)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 5) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · exact tlcReEquivExecTransport hcode - (tlcExecutorRoleX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel) - (tlcSelectorDispatchExecutorRole hsel) (tlcDecodeExecutorRole hsz) - (tlcExecutorRoleBodyReturns (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) ∅ - (by simp only [initState]; exact hwv)) - rfl hAccounts - (returnEquiv_of_encode (bytes32ReturnEncoding tlcExecutorRoleWord)) - · obtain ⟨_, _, h530⟩ := tlcReachExecutorRole (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨541⟩) h530 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchExecutorRole hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Fallback.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Fallback.lean deleted file mode 100644 index 8736a314..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Fallback.lean +++ /dev/null @@ -1,472 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController non-selector paths - -* `tlcNoMatchBodyCore` — calldata ≥ 4 but no selector matches: the EVM binary-search tree walks to a - leaf arm group, all arms miss, and it reverts (`PUSH0 PUSH0 REVERT`). Solm `dispatchMsg = none` - (no matching selector, calldata ≠ ∅ so no receive, no fallback) → `noDispatch`. -* `tlcShortBodyCore` — calldata < 4: empty calldata runs the payable `receive` (EVM `STOP` @440, - Solm `receive` empty body → both succeed, no state change); 1–3 bytes reverts (EVM @441, Solm - `dispatchMsg = none` → `noDispatch`). --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- Short calldata (`< 4` bytes): the prologue's `calldatasize < 4` guard jumps directly to the - receive / short-revert handler at pc 434 with an empty stack. -/ -theorem tlcReachFallback434 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hshort : I.calldata.size < 4) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨434⟩ [] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have h5 := (RD.initState (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hcode) - |>.push1 ⟨128⟩ (by native_decide) (by decide) - |>.push1 ⟨64⟩ (by native_decide) (by decide) - |>.mstore 9 solcFreePtrMem (UInt256.ofNat 3) (by native_decide) - mem_cost (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; rfl) - (by decide) (by decide) - have h434 := h5 - |>.push1 ⟨4⟩ (by native_decide) (by simp) - |>.calldatasize (by native_decide) (by simp) - |>.lt (by native_decide) (by simp) - |>.pushConst (⟨434⟩ : UInt256) (width := 2) (op := .PUSH2) (by native_decide) - (by native_decide) (by simp) - |>.jumpiT (by native_decide) (lt_four_ne_zero_of_lt hshort) (by jump_dest) (by simp) - exact ⟨_, _, h434⟩ - -/-- Empty calldata dispatches to the payable `receive`. -/ -theorem tlcReceiveDispatch {cd : ByteArray} (h0 : cd.size = 0) : - receiveDispatchMsg contract cd = some receiveTransition := by - simp only [receiveDispatchMsg, h0, if_pos, contract] - -theorem tlcSelDispatch_none_short {cd : ByteArray} (hshort : cd.size < 4) : - selectorDispatchMsg contract cd = none := by - rw [selectorDispatchMsg_eq_dispatchList contract cd] - exact dispatchList_none_short contract.transitions - (fun t _ => by rw [selectorOf, ByteArray.size_extract, keccak_size]; decide) hshort - -/-- Non-empty, `< 4`-byte calldata: no selector, no receive (nonempty), no fallback ⇒ no dispatch. -/ -theorem tlcDispatch_none_posShort {cd : ByteArray} (hpos : 0 < cd.size) (hshort : cd.size < 4) : - dispatchMsg contract cd = none := by - rw [dispatchMsg, tlcSelDispatch_none_short hshort] - simp only [receiveDispatchMsg, if_neg (show ¬ cd.size = 0 by omega)] - rfl - -/-! ## No-match dispatch: Solm side (`dispatchMsg = none`) -/ - -/-- No named selector matches (`calldata ≥ 4`): `selectorDispatchMsg` yields nothing. -/ -theorem tlcSelDispatch_none_nomatch {cd : ByteArray} - (hnm : ∀ i, i < 28 → (tlcSelBytes i == cd.extract 0 4) = false) : - selectorDispatchMsg contract cd = none := by - rw [selectorDispatchMsg_eq_dispatchList contract cd] - apply dispatchList_none_of_all_ne - intro t ht - simp only [contract] at ht - fin_cases ht - · rw [selectorOf, cancellerRoleSelectorBytes]; exact hnm 0 (by omega) - · rw [selectorOf, cancelSelectorBytes]; exact hnm 1 (by omega) - · rw [selectorOf, defaultAdminRoleSelectorBytes]; exact hnm 2 (by omega) - · rw [selectorOf, executeBatchSelectorBytes]; exact hnm 3 (by omega) - · rw [selectorOf, executeSelectorBytes]; exact hnm 4 (by omega) - · rw [selectorOf, executorRoleSelectorBytes]; exact hnm 5 (by omega) - · rw [selectorOf, getMinDelaySelectorBytes]; exact hnm 6 (by omega) - · rw [selectorOf, getOperationStateSelectorBytes]; exact hnm 7 (by omega) - · rw [selectorOf, getRoleAdminSelectorBytes]; exact hnm 8 (by omega) - · rw [selectorOf, getTimestampSelectorBytes]; exact hnm 9 (by omega) - · rw [selectorOf, grantRoleSelectorBytes]; exact hnm 10 (by omega) - · rw [selectorOf, hasRoleSelectorBytes]; exact hnm 11 (by omega) - · rw [selectorOf, hashOperationBatchSelectorBytes]; exact hnm 12 (by omega) - · rw [selectorOf, hashOperationSelectorBytes]; exact hnm 13 (by omega) - · rw [selectorOf, isOperationDoneSelectorBytes]; exact hnm 14 (by omega) - · rw [selectorOf, isOperationPendingSelectorBytes]; exact hnm 15 (by omega) - · rw [selectorOf, isOperationReadySelectorBytes]; exact hnm 16 (by omega) - · rw [selectorOf, isOperationSelectorBytes]; exact hnm 17 (by omega) - · rw [selectorOf, onERC1155BatchReceivedSelectorBytes]; exact hnm 18 (by omega) - · rw [selectorOf, onERC1155ReceivedSelectorBytes]; exact hnm 19 (by omega) - · rw [selectorOf, onERC721ReceivedSelectorBytes]; exact hnm 20 (by omega) - · rw [selectorOf, proposerRoleSelectorBytes]; exact hnm 21 (by omega) - · rw [selectorOf, renounceRoleSelectorBytes]; exact hnm 22 (by omega) - · rw [selectorOf, revokeRoleSelectorBytes]; exact hnm 23 (by omega) - · rw [selectorOf, scheduleBatchSelectorBytes]; exact hnm 24 (by omega) - · rw [selectorOf, scheduleSelectorBytes]; exact hnm 25 (by omega) - · rw [selectorOf, supportsInterfaceSelectorBytes]; exact hnm 26 (by omega) - · rw [selectorOf, updateDelaySelectorBytes]; exact hnm 27 (by omega) - -/-- No selector, non-empty (`≥ 4`-byte) calldata, no fallback ⇒ no dispatch. -/ -theorem tlcDispatch_none_nomatch {cd : ByteArray} (hsz : 4 ≤ cd.size) - (hnm : ∀ i, i < 28 → (tlcSelBytes i == cd.extract 0 4) = false) : - dispatchMsg contract cd = none := by - rw [dispatchMsg, tlcSelDispatch_none_nomatch hnm] - simp only [receiveDispatchMsg, if_neg (show ¬ cd.size = 0 by omega)] - rfl - -/-! ## No-match dispatch: EVM side (per-group arm selectors, decode facts, and reverts) - -Each leaf arm group ends in `PUSH0; PUSH0; REVERT` once all its arms miss. The arm selectors below -are in bytecode order; `tlcGArmEq` couples the EVM `EQ`-arm compare to a byte compare, and -`tlcGNoMatchRevert` scans a group's arms (all missing) and reverts. -/ - -def tlcG51SelBytes : ℕ → ByteArray - | 0 => ⟨#[0xd5, 0x47, 0x74, 0x1f]⟩ -- revokeRole - | 1 => ⟨#[0xe3, 0x83, 0x35, 0xe5]⟩ -- executeBatch - | 2 => ⟨#[0xf2, 0x3a, 0x6e, 0x61]⟩ -- onERC1155Received - | _ => ⟨#[0xf2, 0x7a, 0x0c, 0x92]⟩ -- getMinDelay - -def tlcG98SelBytes : ℕ → ByteArray - | 0 => ⟨#[0xbc, 0x19, 0x7c, 0x81]⟩ -- onERC1155BatchReceived - | 1 => ⟨#[0xc4, 0xd2, 0x52, 0xf5]⟩ -- cancel - | _ => ⟨#[0xd4, 0x5c, 0x44, 0x35]⟩ -- getTimestamp - -def tlcG147SelBytes : ℕ → ByteArray - | 0 => ⟨#[0x91, 0xd1, 0x48, 0x54]⟩ -- hasRole - | 1 => ⟨#[0xa2, 0x17, 0xfd, 0xdf]⟩ -- DEFAULT_ADMIN_ROLE - | 2 => ⟨#[0xb0, 0x8e, 0x51, 0xc0]⟩ -- CANCELLER_ROLE - | _ => ⟨#[0xb1, 0xc5, 0xf4, 0x27]⟩ -- hashOperationBatch - -def tlcG194SelBytes : ℕ → ByteArray - | 0 => ⟨#[0x80, 0x65, 0x65, 0x7f]⟩ -- hashOperation - | 1 => ⟨#[0x8f, 0x2a, 0x0b, 0xb0]⟩ -- scheduleBatch - | _ => ⟨#[0x8f, 0x61, 0xf4, 0xf5]⟩ -- PROPOSER_ROLE - -def tlcG254SelBytes : ℕ → ByteArray - | 0 => ⟨#[0x36, 0x56, 0x8a, 0xbe]⟩ -- renounceRole - | 1 => ⟨#[0x58, 0x4b, 0x15, 0x3e]⟩ -- isOperationPending - | 2 => ⟨#[0x64, 0xd6, 0x23, 0x53]⟩ -- updateDelay - | _ => ⟨#[0x79, 0x58, 0x00, 0x4c]⟩ -- getOperationState - -def tlcG301SelBytes : ℕ → ByteArray - | 0 => ⟨#[0x2a, 0xb0, 0xf5, 0x29]⟩ -- isOperationDone - | 1 => ⟨#[0x2f, 0x2f, 0xf1, 0x5d]⟩ -- grantRole - | _ => ⟨#[0x31, 0xd5, 0x07, 0x50]⟩ -- isOperation - -def tlcG350SelBytes : ℕ → ByteArray - | 0 => ⟨#[0x13, 0x40, 0x08, 0xd3]⟩ -- execute - | 1 => ⟨#[0x13, 0xbc, 0x9f, 0x20]⟩ -- isOperationReady - | 2 => ⟨#[0x15, 0x0b, 0x7a, 0x02]⟩ -- onERC721Received - | _ => ⟨#[0x24, 0x8a, 0x9c, 0xa3]⟩ -- getRoleAdmin - -def tlcG397SelBytes : ℕ → ByteArray - | 0 => ⟨#[0x01, 0xd5, 0x06, 0x2a]⟩ -- schedule - | 1 => ⟨#[0x01, 0xff, 0xc9, 0xa7]⟩ -- supportsInterface - | _ => ⟨#[0x07, 0xbd, 0x02, 0x65]⟩ -- EXECUTOR_ROLE - -theorem tlcG51ArmEq (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) (j : ℕ) (hj : j < 4) : - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨51⟩ j)) (tlcSelWord I) = - if (tlcG51SelBytes j == I.calldata.extract 0 4) then ⟨1⟩ else ⟨0⟩ := by - interval_cases j <;> exact evmSelectorDecode hsz _ _ _ _ _ (by native_decide) - -theorem tlcG98ArmEq (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) (j : ℕ) (hj : j < 3) : - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨99⟩ j)) (tlcSelWord I) = - if (tlcG98SelBytes j == I.calldata.extract 0 4) then ⟨1⟩ else ⟨0⟩ := by - interval_cases j <;> exact evmSelectorDecode hsz _ _ _ _ _ (by native_decide) - -theorem tlcG147ArmEq (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) (j : ℕ) (hj : j < 4) : - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨147⟩ j)) (tlcSelWord I) = - if (tlcG147SelBytes j == I.calldata.extract 0 4) then ⟨1⟩ else ⟨0⟩ := by - interval_cases j <;> exact evmSelectorDecode hsz _ _ _ _ _ (by native_decide) - -theorem tlcG194ArmEq (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) (j : ℕ) (hj : j < 3) : - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨195⟩ j)) (tlcSelWord I) = - if (tlcG194SelBytes j == I.calldata.extract 0 4) then ⟨1⟩ else ⟨0⟩ := by - interval_cases j <;> exact evmSelectorDecode hsz _ _ _ _ _ (by native_decide) - -theorem tlcG254ArmEq (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) (j : ℕ) (hj : j < 4) : - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨254⟩ j)) (tlcSelWord I) = - if (tlcG254SelBytes j == I.calldata.extract 0 4) then ⟨1⟩ else ⟨0⟩ := by - interval_cases j <;> exact evmSelectorDecode hsz _ _ _ _ _ (by native_decide) - -theorem tlcG301ArmEq (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) (j : ℕ) (hj : j < 3) : - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨302⟩ j)) (tlcSelWord I) = - if (tlcG301SelBytes j == I.calldata.extract 0 4) then ⟨1⟩ else ⟨0⟩ := by - interval_cases j <;> exact evmSelectorDecode hsz _ _ _ _ _ (by native_decide) - -theorem tlcG350ArmEq (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) (j : ℕ) (hj : j < 4) : - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨350⟩ j)) (tlcSelWord I) = - if (tlcG350SelBytes j == I.calldata.extract 0 4) then ⟨1⟩ else ⟨0⟩ := by - interval_cases j <;> exact evmSelectorDecode hsz _ _ _ _ _ (by native_decide) - -theorem tlcG397ArmEq (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) (j : ℕ) (hj : j < 3) : - UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨398⟩ j)) (tlcSelWord I) = - if (tlcG397SelBytes j == I.calldata.extract 0 4) then ⟨1⟩ else ⟨0⟩ := by - interval_cases j <;> exact evmSelectorDecode hsz _ _ _ _ _ (by native_decide) - -theorem tlcG51NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨51⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (heq0 : ∀ j, j < 4 → UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨51⟩ j)) (tlcSelWord I) = ⟨0⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hend := h - |>.selectorArmNotTakenAuto (tlcG51ArmsWF 0 (by omega)) (heq0 0 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG51ArmsWF 1 (by omega)) (heq0 1 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG51ArmsWF 2 (by omega)) (heq0 2 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG51ArmsWF 3 (by omega)) (heq0 3 (by omega)) (by simp) - exact hend.revertStub (by native_decide) (by native_decide) (by native_decide) (by simp) - -theorem tlcG98NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨99⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (heq0 : ∀ j, j < 3 → UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨99⟩ j)) (tlcSelWord I) = ⟨0⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hend := h - |>.selectorArmNotTakenAuto (tlcG98ArmsWF 0 (by omega)) (heq0 0 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG98ArmsWF 1 (by omega)) (heq0 1 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG98ArmsWF 2 (by omega)) (heq0 2 (by omega)) (by simp) - exact hend.revertStub (by native_decide) (by native_decide) (by native_decide) (by simp) - -theorem tlcG147NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨147⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (heq0 : ∀ j, j < 4 → UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨147⟩ j)) (tlcSelWord I) = ⟨0⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hend := h - |>.selectorArmNotTakenAuto (tlcG147ArmsWF 0 (by omega)) (heq0 0 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG147ArmsWF 1 (by omega)) (heq0 1 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG147ArmsWF 2 (by omega)) (heq0 2 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG147ArmsWF 3 (by omega)) (heq0 3 (by omega)) (by simp) - exact hend.revertStub (by native_decide) (by native_decide) (by native_decide) (by simp) - -theorem tlcG194NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨195⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (heq0 : ∀ j, j < 3 → UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨195⟩ j)) (tlcSelWord I) = ⟨0⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hend := h - |>.selectorArmNotTakenAuto (tlcG194ArmsWF 0 (by omega)) (heq0 0 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG194ArmsWF 1 (by omega)) (heq0 1 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG194ArmsWF 2 (by omega)) (heq0 2 (by omega)) (by simp) - exact hend.revertStub (by native_decide) (by native_decide) (by native_decide) (by simp) - -theorem tlcG254NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨254⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (heq0 : ∀ j, j < 4 → UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨254⟩ j)) (tlcSelWord I) = ⟨0⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hend := h - |>.selectorArmNotTakenAuto (tlcG254ArmsWF 0 (by omega)) (heq0 0 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG254ArmsWF 1 (by omega)) (heq0 1 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG254ArmsWF 2 (by omega)) (heq0 2 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG254ArmsWF 3 (by omega)) (heq0 3 (by omega)) (by simp) - exact hend.revertStub (by native_decide) (by native_decide) (by native_decide) (by simp) - -theorem tlcG301NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨302⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (heq0 : ∀ j, j < 3 → UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨302⟩ j)) (tlcSelWord I) = ⟨0⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hend := h - |>.selectorArmNotTakenAuto (tlcG301ArmsWF 0 (by omega)) (heq0 0 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG301ArmsWF 1 (by omega)) (heq0 1 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG301ArmsWF 2 (by omega)) (heq0 2 (by omega)) (by simp) - exact hend.revertStub (by native_decide) (by native_decide) (by native_decide) (by simp) - -theorem tlcG350NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨350⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (heq0 : ∀ j, j < 4 → UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨350⟩ j)) (tlcSelWord I) = ⟨0⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hend := h - |>.selectorArmNotTakenAuto (tlcG350ArmsWF 0 (by omega)) (heq0 0 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG350ArmsWF 1 (by omega)) (heq0 1 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG350ArmsWF 2 (by omega)) (heq0 2 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG350ArmsWF 3 (by omega)) (heq0 3 (by omega)) (by simp) - exact hend.revertStub (by native_decide) (by native_decide) (by native_decide) (by simp) - -theorem tlcG397NoMatchRevert {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨398⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (heq0 : ∀ j, j < 3 → UInt256.eq (armSelNat timelockControllerBenchBytecode - (nthArmPc timelockControllerBenchBytecode ⟨398⟩ j)) (tlcSelWord I) = ⟨0⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hend := h - |>.selectorArmNotTakenAuto (tlcG397ArmsWF 0 (by omega)) (heq0 0 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG397ArmsWF 1 (by omega)) (heq0 1 (by omega)) (by simp) - |>.selectorArmNotTakenAuto (tlcG397ArmsWF 2 (by omega)) (heq0 2 (by omega)) (by simp) - exact hend.revertStub (by native_decide) (by native_decide) (by native_decide) (by simp) - -theorem tlcNoMatchBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 28 → (tlcSelBytes i == I.calldata.extract 0 4) = false) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - refine RDrev.reEquivNoDispatch (g := Sat256.ofUInt256 g) hcode ?_ - (tlcDispatch_none_nomatch hsz hnm) - by_cases hroot : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨18⟩) (tlcSelWord I) = ⟨0⟩ - · by_cases h29 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨29⟩) (tlcSelWord I) = ⟨0⟩ - · by_cases h40 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨40⟩) (tlcSelWord I) = ⟨0⟩ - · -- G51: revokeRole, executeBatch, onERC1155Received, getMinDelay - obtain ⟨_, _, hfirst⟩ := tlcReachG51First (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hroot h29 h40 - refine tlcG51NoMatchRevert hfirst ?_ - intro j hj; interval_cases j - · rw [tlcG51ArmEq I hsz 0 (by omega), show (tlcG51SelBytes 0 == I.calldata.extract 0 4) - = false from by simpa [tlcG51SelBytes, tlcSelBytes] using hnm 23 (by omega)]; rfl - · rw [tlcG51ArmEq I hsz 1 (by omega), show (tlcG51SelBytes 1 == I.calldata.extract 0 4) - = false from by simpa [tlcG51SelBytes, tlcSelBytes] using hnm 3 (by omega)]; rfl - · rw [tlcG51ArmEq I hsz 2 (by omega), show (tlcG51SelBytes 2 == I.calldata.extract 0 4) - = false from by simpa [tlcG51SelBytes, tlcSelBytes] using hnm 19 (by omega)]; rfl - · rw [tlcG51ArmEq I hsz 3 (by omega), show (tlcG51SelBytes 3 == I.calldata.extract 0 4) - = false from by simpa [tlcG51SelBytes, tlcSelBytes] using hnm 6 (by omega)]; rfl - · -- G98: onERC1155BatchReceived, cancel, getTimestamp - obtain ⟨_, _, hfirst⟩ := tlcReachG98First (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hroot h29 h40 - refine tlcG98NoMatchRevert hfirst ?_ - intro j hj; interval_cases j - · rw [tlcG98ArmEq I hsz 0 (by omega), show (tlcG98SelBytes 0 == I.calldata.extract 0 4) - = false from by simpa [tlcG98SelBytes, tlcSelBytes] using hnm 18 (by omega)]; rfl - · rw [tlcG98ArmEq I hsz 1 (by omega), show (tlcG98SelBytes 1 == I.calldata.extract 0 4) - = false from by simpa [tlcG98SelBytes, tlcSelBytes] using hnm 1 (by omega)]; rfl - · rw [tlcG98ArmEq I hsz 2 (by omega), show (tlcG98SelBytes 2 == I.calldata.extract 0 4) - = false from by simpa [tlcG98SelBytes, tlcSelBytes] using hnm 9 (by omega)]; rfl - · by_cases h136 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨136⟩) (tlcSelWord I) = ⟨0⟩ - · -- G147: hasRole, DEFAULT_ADMIN_ROLE, CANCELLER_ROLE, hashOperationBatch - obtain ⟨_, _, hfirst⟩ := tlcReachG147First (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hroot h29 h136 - refine tlcG147NoMatchRevert hfirst ?_ - intro j hj; interval_cases j - · rw [tlcG147ArmEq I hsz 0 (by omega), show (tlcG147SelBytes 0 == I.calldata.extract 0 4) - = false from by simpa [tlcG147SelBytes, tlcSelBytes] using hnm 11 (by omega)]; rfl - · rw [tlcG147ArmEq I hsz 1 (by omega), show (tlcG147SelBytes 1 == I.calldata.extract 0 4) - = false from by simpa [tlcG147SelBytes, tlcSelBytes] using hnm 2 (by omega)]; rfl - · rw [tlcG147ArmEq I hsz 2 (by omega), show (tlcG147SelBytes 2 == I.calldata.extract 0 4) - = false from by simpa [tlcG147SelBytes, tlcSelBytes] using hnm 0 (by omega)]; rfl - · rw [tlcG147ArmEq I hsz 3 (by omega), show (tlcG147SelBytes 3 == I.calldata.extract 0 4) - = false from by simpa [tlcG147SelBytes, tlcSelBytes] using hnm 12 (by omega)]; rfl - · -- G194: hashOperation, scheduleBatch, PROPOSER_ROLE - obtain ⟨_, _, hfirst⟩ := tlcReachG194First (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hroot h29 h136 - refine tlcG194NoMatchRevert hfirst ?_ - intro j hj; interval_cases j - · rw [tlcG194ArmEq I hsz 0 (by omega), show (tlcG194SelBytes 0 == I.calldata.extract 0 4) - = false from by simpa [tlcG194SelBytes, tlcSelBytes] using hnm 13 (by omega)]; rfl - · rw [tlcG194ArmEq I hsz 1 (by omega), show (tlcG194SelBytes 1 == I.calldata.extract 0 4) - = false from by simpa [tlcG194SelBytes, tlcSelBytes] using hnm 24 (by omega)]; rfl - · rw [tlcG194ArmEq I hsz 2 (by omega), show (tlcG194SelBytes 2 == I.calldata.extract 0 4) - = false from by simpa [tlcG194SelBytes, tlcSelBytes] using hnm 21 (by omega)]; rfl - · by_cases h232 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨232⟩) (tlcSelWord I) = ⟨0⟩ - · by_cases h243 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨243⟩) (tlcSelWord I) = ⟨0⟩ - · -- G254: renounceRole, isOperationPending, updateDelay, getOperationState - obtain ⟨_, _, hfirst⟩ := tlcReachG254First (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hroot h232 h243 - refine tlcG254NoMatchRevert hfirst ?_ - intro j hj; interval_cases j - · rw [tlcG254ArmEq I hsz 0 (by omega), show (tlcG254SelBytes 0 == I.calldata.extract 0 4) - = false from by simpa [tlcG254SelBytes, tlcSelBytes] using hnm 22 (by omega)]; rfl - · rw [tlcG254ArmEq I hsz 1 (by omega), show (tlcG254SelBytes 1 == I.calldata.extract 0 4) - = false from by simpa [tlcG254SelBytes, tlcSelBytes] using hnm 15 (by omega)]; rfl - · rw [tlcG254ArmEq I hsz 2 (by omega), show (tlcG254SelBytes 2 == I.calldata.extract 0 4) - = false from by simpa [tlcG254SelBytes, tlcSelBytes] using hnm 27 (by omega)]; rfl - · rw [tlcG254ArmEq I hsz 3 (by omega), show (tlcG254SelBytes 3 == I.calldata.extract 0 4) - = false from by simpa [tlcG254SelBytes, tlcSelBytes] using hnm 7 (by omega)]; rfl - · -- G301: isOperationDone, grantRole, isOperation - obtain ⟨_, _, hfirst⟩ := tlcReachG301First (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hroot h232 h243 - refine tlcG301NoMatchRevert hfirst ?_ - intro j hj; interval_cases j - · rw [tlcG301ArmEq I hsz 0 (by omega), show (tlcG301SelBytes 0 == I.calldata.extract 0 4) - = false from by simpa [tlcG301SelBytes, tlcSelBytes] using hnm 14 (by omega)]; rfl - · rw [tlcG301ArmEq I hsz 1 (by omega), show (tlcG301SelBytes 1 == I.calldata.extract 0 4) - = false from by simpa [tlcG301SelBytes, tlcSelBytes] using hnm 10 (by omega)]; rfl - · rw [tlcG301ArmEq I hsz 2 (by omega), show (tlcG301SelBytes 2 == I.calldata.extract 0 4) - = false from by simpa [tlcG301SelBytes, tlcSelBytes] using hnm 17 (by omega)]; rfl - · by_cases h339 : UInt256.gt (armSelNat timelockControllerBenchBytecode ⟨339⟩) (tlcSelWord I) = ⟨0⟩ - · -- G350: execute, isOperationReady, onERC721Received, getRoleAdmin - obtain ⟨_, _, hfirst⟩ := tlcReachG350First (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hroot h232 h339 - refine tlcG350NoMatchRevert hfirst ?_ - intro j hj; interval_cases j - · rw [tlcG350ArmEq I hsz 0 (by omega), show (tlcG350SelBytes 0 == I.calldata.extract 0 4) - = false from by simpa [tlcG350SelBytes, tlcSelBytes] using hnm 4 (by omega)]; rfl - · rw [tlcG350ArmEq I hsz 1 (by omega), show (tlcG350SelBytes 1 == I.calldata.extract 0 4) - = false from by simpa [tlcG350SelBytes, tlcSelBytes] using hnm 16 (by omega)]; rfl - · rw [tlcG350ArmEq I hsz 2 (by omega), show (tlcG350SelBytes 2 == I.calldata.extract 0 4) - = false from by simpa [tlcG350SelBytes, tlcSelBytes] using hnm 20 (by omega)]; rfl - · rw [tlcG350ArmEq I hsz 3 (by omega), show (tlcG350SelBytes 3 == I.calldata.extract 0 4) - = false from by simpa [tlcG350SelBytes, tlcSelBytes] using hnm 8 (by omega)]; rfl - · -- G397: schedule, supportsInterface, EXECUTOR_ROLE - obtain ⟨_, _, hfirst⟩ := tlcReachG397First (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hroot h232 h339 - refine tlcG397NoMatchRevert hfirst ?_ - intro j hj; interval_cases j - · rw [tlcG397ArmEq I hsz 0 (by omega), show (tlcG397SelBytes 0 == I.calldata.extract 0 4) - = false from by simpa [tlcG397SelBytes, tlcSelBytes] using hnm 25 (by omega)]; rfl - · rw [tlcG397ArmEq I hsz 1 (by omega), show (tlcG397SelBytes 1 == I.calldata.extract 0 4) - = false from by simpa [tlcG397SelBytes, tlcSelBytes] using hnm 26 (by omega)]; rfl - · rw [tlcG397ArmEq I hsz 2 (by omega), show (tlcG397SelBytes 2 == I.calldata.extract 0 4) - = false from by simpa [tlcG397SelBytes, tlcSelBytes] using hnm 5 (by omega)]; rfl - -/-- Short/receive path (calldata < 4): reach @434, then `STOP` (size 0 → receive) or `REVERT` - (1–3 bytes → no-dispatch). Reach + dispatch helpers above are complete; the receive-execution / - no-dispatch framework glue is finished together with the constructor. -/ -theorem tlcShortBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hshort : I.calldata.size < 4) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - obtain ⟨k, C, h434⟩ := tlcReachFallback434 (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hshort - by_cases hsize0 : I.calldata.size = 0 - · -- Empty calldata: the JUMPI is not taken, `STOP` @440 runs the empty payable `receive`. - have hcond0 : UInt256.ofNat I.calldata.size = ⟨0⟩ := by rw [hsize0]; rfl - have hStop : RDret timelockControllerBenchBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) (cA, σ_evm) ByteArray.empty := - (h434.jumpdest (by native_decide) (by simp) - |>.calldatasize (by native_decide) (by simp) - |>.push2 ⟨441⟩ (by native_decide) (by simp) - |>.jumpiNT (by native_decide) hcond0 (by simp)).stop (by native_decide) (by simp) - rcases hStop with hoog | ⟨s, hX, hacc⟩ - · exact reEquiv_outOfGas (Xi_error_of_X (g := g) (by - rw [← hcode] at hoog - simpa [initState, Sat256.ofUInt256, Sat256.toUInt256] using hoog)) - · have hxi := Xi_success_of_X (g := g) (by - rw [← hcode] at hX - simpa [initState, Sat256.ofUInt256, Sat256.toUInt256] using hX) - have hcA : s.createdAccounts = cA := congrArg Prod.fst hacc - have hσ : s.accountMap = σ_evm := congrArg Prod.snd hacc - rw [hcA, hσ] at hxi - refine reEquiv_receiveExecution (tlcReceiveDispatch hsize0) rfl rfl - (ExecFuncBody.execBlockOK ExecBlock.nil) ?_ - rw [hxi] - exact execResultsEquiv.success rfl rfl rfl (by simpa [initState] using hAccounts) - (returnDataEquiv.abi (returnEquiv.fallthrough (dvs := []) rfl rfl (by native_decide))) - · -- 1–3 bytes: the JUMPI is taken, jumpdest @441 falls into `PUSH0 PUSH0 REVERT`; no dispatch. - have hcondNe : UInt256.ofNat I.calldata.size ≠ ⟨0⟩ := by - intro hz - have hz' : (UInt256.ofNat I.calldata.size).toNat = 0 := by rw [hz]; rfl - rw [UInt256.toNat_ofNat_of_lt hsize] at hz' - exact hsize0 hz' - have hRev : RDrev timelockControllerBenchBytecode (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := - (h434.jumpdest (by native_decide) (by simp) - |>.calldatasize (by native_decide) (by simp) - |>.push2 ⟨441⟩ (by native_decide) (by simp) - |>.jumpiT (by native_decide) hcondNe (by jump_dest) (by simp) - |>.jumpdest (by native_decide) (by simp)).revertStub - (by native_decide) (by native_decide) (by native_decide) (by simp) - exact RDrev.reEquivNoDispatch (g := Sat256.ofUInt256 g) hcode hRev - (tlcDispatch_none_posShort (Nat.pos_of_ne_zero hsize0) hshort) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/GetMinDelay.lean b/Benchmarks/OpenZeppelinBench/TimelockController/GetMinDelay.lean deleted file mode 100644 index 966a2e27..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/GetMinDelay.lean +++ /dev/null @@ -1,99 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Return -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch - -/-! -# OpenZeppelin TimelockController `getMinDelay()` refinement - -`getMinDelay` is a public non-payable `uint256` getter reading storage slot 2 (`_minDelay`). -Selector index 6, dispatch group G51 arm 3, body pc 1443. Template for fixed-slot word getters. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- The stored `_minDelay` value (storage slot 2). -/ -def tlcMinDelayWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := solcSlotWord σ I ⟨2⟩ - -theorem tlcDecodeGetMinDelay {I : ExecutionEnv} (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (getMinDelayTransition.params.map Param.name) - (transitionSignature getMinDelayTransition).paramTypes I.calldata = some ∅ := by - show decodeCalldataWithMode config.abiDecodeMode [] [] I.calldata = some (∅ : Store) - exact decodeCalldataWithMode_empty_ok hsz - -/-- Reach the `getMinDelay` body pc 1443 (G51 arm 3). -/ -theorem tlcReachGetMinDelay {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 6)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1443⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0xf27a0c92⟩ := - solcSelectorWord_eq_of_beq I hsz 0xf2 0x7a 0x0c 0x92 ⟨0xf27a0c92⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG51Body 3 (by omega) ⟨1443⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j <;> (rw [hsw]; native_decide)) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- EVM: with zero callvalue, `getMinDelay()` returns storage slot 2. -/ -theorem tlcGetMinDelayX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 6)) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (tlcMinDelayWord σ I)) := by - obtain ⟨_, _, h1443⟩ := tlcReachGetMinDelay (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h1456⟩ := tlcGuardPeelOk (gt := ⟨1454⟩) h1443 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - obtain ⟨_, _, h1459⟩ := (h1456.push1 ⟨2⟩ (by native_decide) (by simp)).sload (by native_decide) (by simp) - have h581 := h1459.push2 ⟨581⟩ (by native_decide) (by simp) - |>.jump (by native_decide) (by jump_dest) (by simp) - exact tlcReturnWord h581 (by simp) - -/-- The Solm `getMinDelay()` body returns the slot-2 word. -/ -theorem tlcGetMinDelayBodyReturns {cA gh bl σ σ₀ A I} {g : Sat256} - (h : I.weiValue = ⟨0⟩) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) ∅ - getMinDelayTransition.body - (.returned { contract := contract, locals := ∅ } (initState cA gh bl σ σ₀ g A I) - (some [(.int (Int.ofNat (tlcMinDelayWord σ I).toNat))])) := by - refine nonpayableReturnExprBodyReturns (by simp only [initState]; exact h) ?_ - rw [evalExpr_storage_scalar (cfg := config) (solm := { contract := contract, locals := ∅ }) - (slot := minDelayRef) (er := ({ base := "_minDelay", steps := [] } : EvaledStorageRef)) - (t := .int uint256Int) (loc := uint256Loc ⟨2⟩) - (hbase := by simp [minDelayRef]) - (her := by simp [evalStorageRef, minDelayRef, EvalResult.bind, EvalResult.ofOption, bind, pure]) - (hty := by simp [storageTypeAt?, contract, storageDecls, uint256St, uint256Int]) - (hloc := by rfl)] - exact congrArg EvalResult.ok (storageLocLoad_uint256 (initState cA gh bl σ σ₀ g A I) ⟨2⟩) - -/-- Refinement of `getMinDelay` (selector index 6). -/ -theorem tlcGetMinDelayBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 6)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 6) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · have hword : tlcMinDelayWord σ_evm I = tlcMinDelayWord σ_solm I := by - simp only [tlcMinDelayWord]; exact accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨2⟩ ⟨0⟩ - exact tlcReEquivExecTransport hcode - (tlcGetMinDelayX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel) - (tlcSelectorDispatchGetMinDelay hsel) (tlcDecodeGetMinDelay hsz) - (tlcGetMinDelayBodyReturns (g := Sat256.ofUInt256 g) hwv) (by rw [← hword]) hAccounts - (returnEquiv_of_encode (by simpa [uint256] using uint256ReturnEncoding (tlcMinDelayWord σ_evm I))) - · obtain ⟨_, _, h1443⟩ := tlcReachGetMinDelay (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨1454⟩) h1443 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchGetMinDelay hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/GetOperationState.lean b/Benchmarks/OpenZeppelinBench/TimelockController/GetOperationState.lean deleted file mode 100644 index 08233c00..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/GetOperationState.lean +++ /dev/null @@ -1,445 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.GetTimestamp -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `getOperationState(bytes32)` refinement - -`getOperationState` is a public non-payable `uint8` getter. The compiled body (pc 944, dispatch group -G254 arm 3) decodes one `bytes32 id`, then calls the inlined `_getOperationState` helper @2232 which -hashes the `_timestamps` mapping slot `keccak(id ‖ 1)`, `SLOAD`s the timestamp `t`, and returns the -4-way operation state (`0=Unset` if `t=0`, `3=Done` if `t=1`, `1=Waiting` if `t>block.timestamp`, -`2=Ready` otherwise), which the body ABI-encodes as a `uint8` (encoder @5061, dispatcher @521). - -Front half (guard peel, `bytes32` decoder @4702, slot-1 mapping keccak) and the `_getOperationState` -leaf traversal @2232 reuse `GetTimestamp`/`Storage`/`IsOperation` infrastructure; the `uint8` encoder -@5061→@521 stores the low-byte state word at the free pointer and `RETURN`s it, generalized over the -dirtied scratch memory (`twoWordHashMem …`) via `Storage.tlcRetMem*`. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- The `uint8` operation-state word `getOperationState` returns for a stored timestamp `t` and block - timestamp `ts`: `0` if `t=0`, `3` if `t=1`, `1` if `ts < t`, else `2`. -/ -def tlcGetOperationStateWord (t : UInt256) (ts : Nat) : UInt256 := - if t = ⟨0⟩ then ⟨0⟩ - else if t = ⟨1⟩ then ⟨3⟩ - else if (UInt256.ofNat ts).toNat < t.toNat then ⟨1⟩ - else ⟨2⟩ - -theorem tlcGetOperationStateWord_lt_4 (t : UInt256) (ts : Nat) : - (tlcGetOperationStateWord t ts).toNat < 4 := by - unfold tlcGetOperationStateWord; split_ifs <;> decide - -/-! ## Memory-generic `uint8` return encoder @5061 → @521 - - From @975 with `[state, sel]` over any free-pointer-preserving scratch memory (`size = 96`, - `mem[0x40] = 0x80`): the encoder @5061 stores the low-byte `state` word at the free pointer - (after the `state < 4` enum bounds check, always taken here), and the dispatcher @521 - `RETURN(0x80, 0x20)`s the 32-byte word. Reuses `Storage.tlcRetMem*`. -/ -theorem tlcGetOperationStateReturn {g : Sat256} {s0 : State} {ee : ExecutionEnv} - {k C : ℕ} {R : List UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {v : UInt256} {mem : ByteArray} - (h : RD timelockControllerBenchBytecode ee g s0 ⟨975⟩ (v :: R) mem - (UInt256.ofNat 3) rdata acc k C) - (hsize : mem.size = 96) - (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) - (hlt : UInt256.lt v ⟨4⟩ ≠ ⟨0⟩) - (hov : R.length + 8 ≤ 1024) : - RDret timelockControllerBenchBytecode g s0 acc (UInt256.toByteArray v) := by - exact evm_run h with [ - jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) - mem_cost (mloadFreePtrValue (by rw [hsize]; decide) (by decide) hread64) (by decide) (by evm_ov), - push2 ⟨521⟩, swap2, swap1, push2 ⟨5061⟩, jump (by jump_dest), - jumpdest, push1 ⟨32⟩, dup2, add, push1 ⟨4⟩, dup4, lt, push2 ⟨5093⟩, - jumpiT hlt (by jump_dest), - jumpdest, swap2, swap1, - raw mstore 6 (tlcRetMem mem v) (UInt256.ofNat 5) (by native_decide) - mem_cost (by rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide]; rfl) (by native_decide) - (by evm_ov), - swap1, jump (by jump_dest), - jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 5) (by native_decide) - mem_cost (tlcRetMem_mload64 hsize hread64 v) (by decide) (by evm_ov), - dup1, swap2, sub, swap1, - raw ret 0 (UInt256.toByteArray v) (by native_decide) mem_cost - (by rw [show (UInt256.sub ((⟨128⟩ : UInt256) + ⟨32⟩) ⟨128⟩).toNat = 32 from by decide] - exact tlcRetMem_read128 hsize v) - (by evm_ov) ] - -/-! ## EVM: reach the body and the decoder length check -/ - -/-- Reach the `getOperationState` body pc 944 (G254 arm 3). -/ -theorem tlcReachGetOperationState {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 7)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨944⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x7958004c⟩ := - solcSelectorWord_eq_of_beq I hsz 0x79 0x58 0x00 0x4c ⟨0x7958004c⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG254Body 3 (by omega) ⟨944⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j <;> (rw [hsw]; native_decide)) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Peel the non-payable guard, push the return/decode continuations `⟨975⟩`/`⟨970⟩`, and run the - `bytes32` decoder prologue @4702 to the availability `JUMPI` @4714. - Stack: `[⟨4718⟩, ISZERO(SLT(size-4, 32)), ⟨0⟩, ⟨4⟩, size, ⟨970⟩, ⟨975⟩, sel]`. -/ -theorem tlcGetOperationStateReachLenCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 7)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4714⟩ - [⟨4718⟩, UInt256.isZero (UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩), - ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨970⟩, ⟨975⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h944⟩ := tlcReachGetOperationState (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h957⟩ := tlcGuardPeelOk (gt := ⟨955⟩) h944 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, h957.push2 ⟨975⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨970⟩ (by native_decide) (by evm_ov) - |>.calldatasize (by native_decide) (by evm_ov) - |>.push1 ⟨4⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4702⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.slt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨4718⟩ (by native_decide) (by evm_ov)⟩ - -/-- After the length check passes, finish the decoder (`CALLDATALOAD(4)`), jump back to the decode - continuation @970, and enter the `_getOperationState` helper @2232 with `[id, ⟨975⟩, sel]`. -/ -theorem tlcGetOperationStateReachCompute {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 7)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2232⟩ - [calldataWord I.calldata 4, ⟨975⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsz : 4 ≤ I.calldata.size := by omega - obtain ⟨_, _, h4714⟩ := tlcGetOperationStateReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact ⟨_, _, h4714.jumpiT (by native_decide) - (by rw [solcDecodeLenCheckOk_4_32 hsz36 hbig hsize]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨2232⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov)⟩ - -/-! ## EVM: the `_getOperationState` helper @2232 and its four leaves - - From `[id, ⟨975⟩, sel]` at @2232, hash the slot `keccak(id ‖ 1)`, `SLOAD` the timestamp `t`, and - case-split the four state leaves — each returns to the encoder continuation @975 with the state - word `[state, sel]` on top. -/ -theorem tlcGetOperationStateCompute {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 7)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨975⟩ - [tlcGetOperationStateWord (tlcGetTimestampWord σ I) I.header.timestamp, tlcSelWord I] - (twoWordHashMem (calldataWord I.calldata 4) ⟨1⟩ solcFreePtrMem) - (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h2232⟩ := tlcGetOperationStateReachCompute (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz36 hbig hsize hsel - have hkec := evm_run h2232 with [ - jumpdest, push0, dup2, dup2, - raw mstore 0 (wordAt0Mem (calldataWord I.calldata 4) solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨32⟩, - raw mstore 0 (twoWordHashMem (calldataWord I.calldata 4) ⟨1⟩ solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨64⟩, dup2, - raw keccak256 0 (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) (UInt256.ofNat 3) - (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact tlcTwoWordKeccakSlot ⟨1⟩ (calldataWord I.calldata 4)) - (by native_decide) (by evm_ov) ] - obtain ⟨_, _, hsl⟩ := hkec.sload (by native_decide) (by evm_ov) - -- `hsl` is at @2247 with the loaded timestamp `t = tlcGetTimestampWord σ I` on top. - by_cases ht0 : tlcGetTimestampWord σ I = ⟨0⟩ - · -- Unset: `t = 0` ⇒ state 0. - have hcond : UInt256.sub ⟨0⟩ (tlcGetTimestampWord σ I) = (⟨0⟩ : UInt256) := by - rw [ht0]; exact u256_sub_self ⟨0⟩ - have h975 := evm_run hsl with [ - dup1, push0, sub, push2 ⟨2261⟩, jumpiNT hcond, - pop, push0, swap3, swap2, pop, pop, jump (by jump_dest) ] - exact ⟨_, _, by - rw [show tlcGetOperationStateWord (tlcGetTimestampWord σ I) I.header.timestamp = ⟨0⟩ from by - unfold tlcGetOperationStateWord; rw [if_pos ht0]] - exact h975⟩ - · -- `t ≠ 0`: pass the Unset `JUMPI` @2253, reach the Done check @2269. - have hcond0 : UInt256.sub ⟨0⟩ (tlcGetTimestampWord σ I) ≠ (⟨0⟩ : UInt256) := - u256_zero_sub_ne_zero ht0 - have h2269 := evm_run hsl with [ - dup1, push0, sub, push2 ⟨2261⟩, jumpiT hcond0 (by jump_dest), - jumpdest, push1 ⟨1⟩, dup2, sub, push2 ⟨2278⟩ ] - by_cases ht1 : tlcGetTimestampWord σ I = ⟨1⟩ - · -- Done: `t = 1` ⇒ state 3. - have hcond1 : UInt256.sub (tlcGetTimestampWord σ I) ⟨1⟩ = (⟨0⟩ : UInt256) := by - rw [ht1]; exact u256_sub_self ⟨1⟩ - have h975 := evm_run h2269 with [ - jumpiNT hcond1, - pop, push1 ⟨3⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - exact ⟨_, _, by - rw [show tlcGetOperationStateWord (tlcGetTimestampWord σ I) I.header.timestamp = ⟨3⟩ from by - unfold tlcGetOperationStateWord; rw [if_neg ht0, if_pos ht1]] - exact h975⟩ - · -- `t ≠ 1`: pass the Done `JUMPI` @2269, reach the timestamp check @2286. - have hcond1 : UInt256.sub (tlcGetTimestampWord σ I) ⟨1⟩ ≠ (⟨0⟩ : UInt256) := - u256_sub_ne_zero_of_ne ht1 - have h2286 := evm_run h2269 with [ - jumpiT hcond1 (by jump_dest), - jumpdest, timestamp, dup2, gt, iszero, push2 ⟨2295⟩ ] - by_cases htgt : UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp) = ⟨0⟩ - · -- Ready: `t ≤ block.timestamp` ⇒ state 2. - have hcondr : UInt256.isZero - (UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp)) - ≠ (⟨0⟩ : UInt256) := by - rw [htgt]; decide - have h975 := evm_run h2286 with [ - jumpiT hcondr (by jump_dest), - jumpdest, pop, push1 ⟨2⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - exact ⟨_, _, by - rw [show tlcGetOperationStateWord (tlcGetTimestampWord σ I) I.header.timestamp = ⟨2⟩ from by - unfold tlcGetOperationStateWord - rw [if_neg ht0, if_neg ht1, - if_neg (fun hc => by rw [ugt_one hc] at htgt; exact absurd htgt (by decide))]] - exact h975⟩ - · -- Waiting: `t > block.timestamp` ⇒ state 1. - have hcondw : UInt256.isZero - (UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp)) - = (⟨0⟩ : UInt256) := - isZero_eq_zero_of_ne htgt - have h975 := evm_run h2286 with [ - jumpiNT hcondw, - pop, push1 ⟨1⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - exact ⟨_, _, by - rw [show tlcGetOperationStateWord (tlcGetTimestampWord σ I) I.header.timestamp = ⟨1⟩ from by - unfold tlcGetOperationStateWord - rw [if_neg ht0, if_neg ht1, - if_pos (by by_contra hc; exact htgt (ugt_zero (Nat.le_of_not_lt hc)))]] - exact h975⟩ - -/-- EVM: with zero callvalue and well-sized calldata, `getOperationState(id)` returns the `uint8` - operation-state word. -/ -theorem tlcGetOperationStateX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 7)) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray - (tlcGetOperationStateWord (tlcGetTimestampWord σ I) I.header.timestamp)) := by - obtain ⟨_, _, h975⟩ := tlcGetOperationStateCompute (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz36 hbig hsize hsel - exact tlcGetOperationStateReturn h975 - (twoWordHashMem_size_96 _ _ solcFreePtrMem_size) - (twoWordHashMem_read64 _ _ solcFreePtrMem_size solcFreePtrMem_read64) - (by unfold tlcGetOperationStateWord; split_ifs <;> decide) (by evm_ov) - -/-- EVM revert path for a mis-sized calldata: the signed length check `SLT(size-4, 32) = 1` fails the - `JUMPI`, falling into the decoder's `PUSH0 PUSH0 REVERT` stub. -/ -theorem tlcGetOperationStateDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 7)) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4714⟩ := tlcGetOperationStateReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact h4714.jumpiNT (by native_decide) (by rw [hslt]; decide) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-! ## ABI decode (a single `bytes32`, exactly like `getTimestamp`) -/ - -theorem tlcDecodeGetOperationState_ok {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) : - decodeCalldataWithMode config.abiDecodeMode (getOperationStateTransition.params.map Param.name) - (transitionSignature getOperationStateTransition).paramTypes I.calldata - = some (tlcGetTimestampStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = _ - exact decodeCalldata_bytes32_ok hsz36 hbig - -theorem tlcDecodeGetOperationState_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 36) : - decodeCalldataWithMode config.abiDecodeMode (getOperationStateTransition.params.map Param.name) - (transitionSignature getOperationStateTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_short hsz4 hshort - -theorem tlcDecodeGetOperationState_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (getOperationStateTransition.params.map Param.name) - (transitionSignature getOperationStateTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_huge hbig - -/-! ## Solm body -/ - -/-- The Solm `getOperationState(id)` body returns the `uint8` operation state. -/ -theorem tlcGetOperationStateBodyReturns {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcGetTimestampStore I) - getOperationStateTransition.body - (.returned { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) - (some [(.int (Int.ofNat - (tlcGetOperationStateWord (tlcGetTimestampWord σ I) I.header.timestamp).toNat))])) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hvk : valueToKey? (Value.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32)) - = some (tlcGetTimestampKey I) := by - simp [valueToKey?, tlcGetTimestampKey, abiBytes32Width, hlen] - have hslot : timestampSlot (tlcGetTimestampKey I) - = solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4) := by - unfold timestampSlot mapSlot solcMappingSlot - rw [tlcGetTimestampKey_eq I hsz36] - have hstore : evalExpr? config { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) (timestampExpr (.var "id")) - = .ok (.int (Int.ofNat (tlcGetTimestampWord σ I).toNat)) := by - unfold timestampExpr - rw [evalExpr_storage_scalar (cfg := config) - (solm := { contract := contract, locals := tlcGetTimestampStore I }) - (slot := timestampRef (.var "id")) - (er := ({ base := "_timestamps", steps := [.mindex (tlcGetTimestampKey I)] } : EvaledStorageRef)) - (t := .int uint256Int) (loc := uint256Loc (timestampSlot (tlcGetTimestampKey I))) - (hbase := by simp [timestampRef]) - (her := by - simp [evalStorageRef, evalStorageRefStep, timestampRef, tlcGetTimestampStore, - EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?, hvk]) - (hty := by - simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, tlcGetTimestampKey, uint256St]) - (hloc := by rfl)] - rw [hslot] - exact congrArg EvalResult.ok - (storageLocLoad_uint256 (initState cA gh bl σ σ₀ g A I) - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4))) - have henv : evalExpr? config { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) (.env .timestamp) - = .ok (.int (Int.ofNat (UInt256.ofNat I.header.timestamp).toNat)) := by - simp only [evalExpr?, envValue, initState, pure] - have heqF : ∀ n : UInt256, tlcGetTimestampWord σ I ≠ n → - (Value.int (Int.ofNat (tlcGetTimestampWord σ I).toNat) == Value.int (Int.ofNat n.toNat)) = false := - fun n hn => by - simp only [beq_eq_false_iff_ne, ne_eq, Value.int.injEq] - intro hh; exact hn (u256_inj (Int.ofNat.inj hh)) - refine nonpayableReturnExprBodyReturns (by simp only [initState]; exact hwv) ?_ - unfold operationStateExpr doneTimestamp - by_cases h0 : tlcGetTimestampWord σ I = ⟨0⟩ - · rw [show tlcGetOperationStateWord (tlcGetTimestampWord σ I) I.header.timestamp = ⟨0⟩ from by - unfold tlcGetOperationStateWord; rw [if_pos h0]] - have he0 : (Value.int (Int.ofNat (tlcGetTimestampWord σ I).toNat) == Value.int 0) = true := by - rw [h0]; rfl - simp only [evalExpr?, hstore, EvalResult.bind, bind, pure, evalBinaryOp?, he0] - rfl - · by_cases h1 : tlcGetTimestampWord σ I = ⟨1⟩ - · rw [show tlcGetOperationStateWord (tlcGetTimestampWord σ I) I.header.timestamp = ⟨3⟩ from by - unfold tlcGetOperationStateWord; rw [if_neg h0, if_pos h1]] - have he0 : (Value.int (Int.ofNat (tlcGetTimestampWord σ I).toNat) == Value.int 0) = false := - heqF ⟨0⟩ h0 - have he1 : (Value.int (Int.ofNat (tlcGetTimestampWord σ I).toNat) == Value.int 1) = true := by - rw [h1]; rfl - simp only [evalExpr?, hstore, EvalResult.bind, bind, pure, evalBinaryOp?, he0, he1] - rfl - · have he0 : (Value.int (Int.ofNat (tlcGetTimestampWord σ I).toNat) == Value.int 0) = false := - heqF ⟨0⟩ h0 - have he1 : (Value.int (Int.ofNat (tlcGetTimestampWord σ I).toNat) == Value.int 1) = false := - heqF ⟨1⟩ h1 - by_cases htgt : (UInt256.ofNat I.header.timestamp).toNat < (tlcGetTimestampWord σ I).toNat - · rw [show tlcGetOperationStateWord (tlcGetTimestampWord σ I) I.header.timestamp = ⟨1⟩ from by - unfold tlcGetOperationStateWord; rw [if_neg h0, if_neg h1, if_pos htgt]] - have hg : decide (Int.ofNat (UInt256.ofNat I.header.timestamp).toNat - < Int.ofNat (tlcGetTimestampWord σ I).toNat) = true := - decide_eq_true_eq.mpr (Int.ofNat_lt.mpr htgt) - simp only [evalExpr?, hstore, henv, EvalResult.bind, bind, pure, evalBinaryOp?, he0, he1, - gt_iff_lt, hg] - rfl - · rw [show tlcGetOperationStateWord (tlcGetTimestampWord σ I) I.header.timestamp = ⟨2⟩ from by - unfold tlcGetOperationStateWord; rw [if_neg h0, if_neg h1, if_neg htgt]] - have hg : decide (Int.ofNat (UInt256.ofNat I.header.timestamp).toNat - < Int.ofNat (tlcGetTimestampWord σ I).toNat) = false := - decide_eq_false_iff_not.mpr (fun h => htgt (Int.ofNat_lt.mp h)) - simp only [evalExpr?, hstore, henv, EvalResult.bind, bind, pure, evalBinaryOp?, he0, he1, - gt_iff_lt, hg] - rfl - -/-- ABI-encoding the `uint8` operation-state result is the EVM's returned word. -/ -theorem tlcGetOperationStateUint8Encoding (t : UInt256) (ts : Nat) : - encodeReturnValue? uint8 (.int (Int.ofNat (tlcGetOperationStateWord t ts).toNat)) - = some (UInt256.toByteArray (tlcGetOperationStateWord t ts)) := by - simpa [uint8, uint8Int] using - uint8ReturnEncoding (tlcGetOperationStateWord t ts) - (Nat.lt_of_lt_of_le (tlcGetOperationStateWord_lt_4 t ts) (by decide)) - -/-! ## Refinement -/ - -/-- Refinement of `GetOperationState` (selector index 7). -/ -theorem tlcGetOperationStateBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 7)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 7) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz36 : 36 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · -- execute: `36 ≤ size < 2^255 + 4` - have hword : tlcGetTimestampWord σ_evm I = tlcGetTimestampWord σ_solm I := by - simp only [tlcGetTimestampWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) ⟨0⟩ - exact tlcReEquivExecTransport hcode - (tlcGetOperationStateX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz36 hbig hsize hsel) - (tlcSelectorDispatchGetOperationState hsel) - (tlcDecodeGetOperationState_ok hsz36 hbig) - (tlcGetOperationStateBodyReturns (g := Sat256.ofUInt256 g) hwv hsz36) - (by rw [← hword]) hAccounts - (returnEquiv_of_encode - (tlcGetOperationStateUint8Encoding (tlcGetTimestampWord σ_evm I) I.header.timestamp)) - · -- huge calldata: EVM reverts at the signed length check, Solm decode fails - have hhuge : 2 ^ 255 + 4 ≤ I.calldata.size := Nat.not_lt.mp hbig - have hrev := tlcGetOperationStateDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckHuge_4_32 hhuge hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchGetOperationState hsel) - (tlcDecodeGetOperationState_none_huge hhuge) - · -- short calldata: EVM reverts at the length check, Solm decode fails - have hshort : I.calldata.size < 36 := by omega - have hrev := tlcGetOperationStateDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckShort_4_32 hsz hshort hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchGetOperationState hsel) - (tlcDecodeGetOperationState_none_short hsz hshort) - · -- nonpayable guard: `callvalue ≠ 0` - obtain ⟨_, _, h944⟩ := tlcReachGetOperationState (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨955⟩) h944 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchGetOperationState hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/GetRoleAdmin.lean b/Benchmarks/OpenZeppelinBench/TimelockController/GetRoleAdmin.lean deleted file mode 100644 index b2b27d86..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/GetRoleAdmin.lean +++ /dev/null @@ -1,299 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Storage -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch - -/-! -# OpenZeppelin TimelockController `getRoleAdmin(bytes32)` refinement - -`getRoleAdmin` is a public non-payable `bytes32` getter over `_roles[role].adminRole`. In this -contract's layout `_roles` is a `mapping(bytes32 => RoleData)` at base slot `0`, and `.adminRole` is -field offset `1` of the struct, so the read slot is `keccak(role ‖ 0) + 1`. Selector index 8, -dispatch group G350 arm 3, body pc 712. The runtime peels its own non-payable guard, runs the modern -word-argument decoder (`@4702`, a signed `SLT(calldatasize - 4, 32)` availability check), hashes the -mapping slot `keccak(role ‖ 0)`, `ADD`s the field offset `1`, `SLOAD`s it, and returns the 32-byte -word. Template for arg-taking struct-field `bytes32` mapping getters (cf. `GetTimestamp`, the -base-slot-`1` `uint256` analogue). --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Decoded argument, storage word, and ABI decode -/ - -/-- The ABI-decoded `bytes32` role (the 32-byte calldata word at offset 4), as a mapping key value. -/ -abbrev tlcGetRoleAdminKey (I : ExecutionEnv) : KeyValue := - .fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32) - -/-- The decoded local store bound by `getRoleAdmin(bytes32 role)`. -/ -abbrev tlcGetRoleAdminStore (I : ExecutionEnv) : Store := - (∅ : Store).insert "role" (.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32)) - -/-- The stored `_roles[role].adminRole` value (mapping slot `keccak(role ‖ 0)`, struct offset `+1`). -/ -def tlcGetRoleAdminWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (roleAdminSlot (tlcGetRoleAdminKey I)) - -/-- The decoded `bytes32` key hashes to the same word the EVM `CALLDATALOAD(4)` loads. -/ -theorem tlcGetRoleAdminKey_eq (I : ExecutionEnv) (hsz36 : 36 ≤ I.calldata.size) : - keyValueToWord (tlcGetRoleAdminKey I) = calldataWord I.calldata 4 := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have key_eq : tlcGetRoleAdminKey I - = .fixedBytes ⟨31, by decide⟩ - (EVM.Word.toBytesBE (ABI.bytesToWord ((I.calldata.toList.drop 4).take 32))) := by - simp only [tlcGetRoleAdminKey] - rw [show abiBytes32Width = (⟨31, by decide⟩ : Fin 32) from rfl, - toBytesBE_bytesToWord_of_length hlen] - rw [key_eq, keyValueToWord_fixedBytes32, decode_word_at_eq_any I.calldata 4 (by omega)] - -theorem tlcDecodeGetRoleAdmin_ok {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) : - decodeCalldataWithMode config.abiDecodeMode (getRoleAdminTransition.params.map Param.name) - (transitionSignature getRoleAdminTransition).paramTypes I.calldata - = some (tlcGetRoleAdminStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["role"] [bytes32] I.calldata = _ - exact decodeCalldata_bytes32_ok hsz36 hbig - -theorem tlcDecodeGetRoleAdmin_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 36) : - decodeCalldataWithMode config.abiDecodeMode (getRoleAdminTransition.params.map Param.name) - (transitionSignature getRoleAdminTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_short hsz4 hshort - -theorem tlcDecodeGetRoleAdmin_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (getRoleAdminTransition.params.map Param.name) - (transitionSignature getRoleAdminTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_huge hbig - -/-! ## Slot arithmetic: `keccak(role ‖ 0) + 1` -/ - -/-- The EVM `ADD` of a `PUSH1 1` onto a slot word is the Solm layout's struct-field offset `+1`. -/ -theorem tlcOneAddEqAddSlot (s : UInt256) : (⟨1⟩ : UInt256) + s = addSlot s 1 := by - rw [u256_add_comm] - unfold addSlot - rw [← u256_ofNat_toNat s]; rfl - -/-! ## EVM: reach the body and the length check -/ - -/-- Reach the `getRoleAdmin` body pc 712 (G350 arm 3). -/ -theorem tlcReachGetRoleAdmin {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 8)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨712⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x248a9ca3⟩ := - solcSelectorWord_eq_of_beq I hsz 0x24 0x8a 0x9c 0xa3 ⟨0x248a9ca3⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG350Body 3 (by omega) ⟨712⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j <;> (rw [hsw]; native_decide)) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Peel the non-payable guard and run the decoder prologue to the `SLT` availability `JUMPI` @4714. - Stack: `[⟨4718⟩, ISZERO(SLT(size-4, 32)), ⟨0⟩, ⟨4⟩, size, ⟨738⟩, ⟨581⟩, sel]`. -/ -theorem tlcGetRoleAdminReachLenCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 8)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4714⟩ - [⟨4718⟩, UInt256.isZero (UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩), - ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨738⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h712⟩ := tlcReachGetRoleAdmin (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h725⟩ := tlcGuardPeelOk (gt := ⟨723⟩) h712 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, h725.push2 ⟨581⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨738⟩ (by native_decide) (by evm_ov) - |>.calldatasize (by native_decide) (by evm_ov) - |>.push1 ⟨4⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4702⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.slt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨4718⟩ (by native_decide) (by evm_ov)⟩ - -/-! ## Base-slot-0 struct-field mapping getter (@738 in the TimelockController runtime) - - Stack at entry `[key, ret, R]`; the routine writes `key‖0` into scratch, hashes, `ADD`s the - field offset `1`, loads the slot, and `JUMP`s to `ret` leaving `[slotWord, R]`. Memory becomes - `twoWordHashMem key ⟨0⟩ solcFreePtrMem`. The base-slot-`0`-plus-offset-`1` analogue of - `tlcMappingGetSlot1` (which is base slot `1` with no offset). -/ -theorem tlcGetRoleAdminGetSlot0Plus1 {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - {key ret : UInt256} {R : List UInt256} {rdata : ByteArray} {k C : ℕ} - (h : RD timelockControllerBenchBytecode ee g s0 ⟨738⟩ (key :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hret : (D_J timelockControllerBenchBytecode 0).contains ret = true) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD timelockControllerBenchBytecode ee g s0 ret - (solcSlotWord σ ee (⟨1⟩ + solcMappingSlot ⟨0⟩ key) :: R) - (twoWordHashMem key ⟨0⟩ solcFreePtrMem) (UInt256.ofNat 3) rdata (cA, σ) k' C' := by - have hk := h.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.mstore 0 (wordAt0Mem key solcFreePtrMem) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rfl) (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.mstore 0 (twoWordHashMem key ⟨0⟩ solcFreePtrMem) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rfl) (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.keccak256 0 (solcMappingSlot ⟨0⟩ key) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact tlcTwoWordKeccakSlot ⟨0⟩ key) - (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.add (by native_decide) (by evm_ov) - obtain ⟨_, _, hsl⟩ := hk.sload (by native_decide) (by evm_ov) - exact ⟨_, _, hsl.swap1 (by native_decide) (by evm_ov) |>.jump (by native_decide) hret (by evm_ov)⟩ - -/-- EVM: with zero callvalue and a well-sized calldata, `getRoleAdmin(role)` returns - `_roles[role].adminRole`. -/ -theorem tlcGetRoleAdminX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 8)) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (tlcGetRoleAdminWord σ I)) := by - have hsz : 4 ≤ I.calldata.size := by omega - obtain ⟨_, _, h4714⟩ := tlcGetRoleAdminReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - have h738 := h4714.jumpiT (by native_decide) - (by rw [solcDecodeLenCheckOk_4_32 hsz36 hbig hsize]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - obtain ⟨_, _, h581⟩ := tlcGetRoleAdminGetSlot0Plus1 h738 (by jump_dest) (by simp) - have hslot : (⟨1⟩ : UInt256) + solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4) - = roleAdminSlot (tlcGetRoleAdminKey I) := by - have hbaseslot : solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4) - = roleDataSlot (tlcGetRoleAdminKey I) := by - unfold roleDataSlot mapSlot solcMappingSlot - rw [tlcGetRoleAdminKey_eq I hsz36] - rw [hbaseslot] - exact tlcOneAddEqAddSlot (roleDataSlot (tlcGetRoleAdminKey I)) - have hval : solcSlotWord σ I (⟨1⟩ + solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - = tlcGetRoleAdminWord σ I := by - unfold tlcGetRoleAdminWord - rw [hslot] - rw [← hval] - exact tlcReturnWordFromMem h581 (twoWordHashMem_size_96 _ _ solcFreePtrMem_size) - (twoWordHashMem_read64 _ _ solcFreePtrMem_size solcFreePtrMem_read64) (by simp) - -/-- EVM revert path for a mis-sized calldata: the signed length check `SLT(size-4, 32) = 1` - fails the `JUMPI`, falling into the `PUSH0 PUSH0 REVERT` stub. -/ -theorem tlcGetRoleAdminDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 8)) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4714⟩ := tlcGetRoleAdminReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact h4714.jumpiNT (by native_decide) (by rw [hslt]; decide) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-! ## Solm body -/ - -/-- The Solm `getRoleAdmin(role)` body returns `_roles[role].adminRole`. -/ -theorem tlcGetRoleAdminBodyReturns {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcGetRoleAdminStore I) - getRoleAdminTransition.body - (.returned { contract := contract, locals := tlcGetRoleAdminStore I } - (initState cA gh bl σ σ₀ g A I) - (some [(.fixedBytes bytes32Width (EVM.Word.toBytesBE (tlcGetRoleAdminWord σ I)))])) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hvk : valueToKey? (Value.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32)) - = some (tlcGetRoleAdminKey I) := by - simp [valueToKey?, tlcGetRoleAdminKey, abiBytes32Width, hlen] - refine nonpayableReturnExprBodyReturns (by simp only [initState]; exact hwv) ?_ - rw [evalExpr_storage_scalar (cfg := config) - (solm := { contract := contract, locals := tlcGetRoleAdminStore I }) - (slot := roleAdminRef (.var "role")) - (er := ({ base := "_roles", steps := [.mindex (tlcGetRoleAdminKey I), .field "adminRole"] } : - EvaledStorageRef)) - (t := .bytes bytes32Width) (loc := bytes32Loc (roleAdminSlot (tlcGetRoleAdminKey I))) - (hbase := by simp [roleAdminRef]) - (her := by - simp [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, roleAdminRef, - tlcGetRoleAdminStore, EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?, hvk]) - (hty := by - simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, roleDataSt, - tlcGetRoleAdminKey, bytes32St]) - (hloc := by rfl)] - exact congrArg EvalResult.ok - (storageLocLoad_bytes32 (initState cA gh bl σ σ₀ g A I) (roleAdminSlot (tlcGetRoleAdminKey I))) - -/-! ## Refinement -/ - -theorem tlcGetRoleAdminBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 8)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 8) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz36 : 36 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · -- execute: `36 ≤ size < 2^255 + 4` - have hword : tlcGetRoleAdminWord σ_evm I = tlcGetRoleAdminWord σ_solm I := by - simp only [tlcGetRoleAdminWord, solcSlotWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner - (roleAdminSlot (tlcGetRoleAdminKey I)) ⟨0⟩ - exact tlcReEquivExecTransport hcode - (tlcGetRoleAdminX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz36 hbig hsize hsel) - (tlcSelectorDispatchGetRoleAdmin hsel) (tlcDecodeGetRoleAdmin_ok hsz36 hbig) - (tlcGetRoleAdminBodyReturns (g := Sat256.ofUInt256 g) hwv hsz36) (by rw [← hword]; rfl) - hAccounts - (returnEquiv_of_encode (bytes32ReturnEncoding (tlcGetRoleAdminWord σ_evm I))) - · -- huge calldata: `2^255 + 4 ≤ size`; EVM reverts at the signed length check, Solm decode fails - have hhuge : 2 ^ 255 + 4 ≤ I.calldata.size := Nat.not_lt.mp hbig - have hrev := tlcGetRoleAdminDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckHuge_4_32 hhuge hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchGetRoleAdmin hsel) - (tlcDecodeGetRoleAdmin_none_huge hhuge) - · -- short calldata: `size < 36`; EVM reverts at the length check, Solm decode fails - have hshort : I.calldata.size < 36 := by omega - have hrev := tlcGetRoleAdminDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckShort_4_32 hsz hshort hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchGetRoleAdmin hsel) - (tlcDecodeGetRoleAdmin_none_short hsz hshort) - · -- nonpayable guard: `callvalue ≠ 0` - obtain ⟨_, _, h712⟩ := tlcReachGetRoleAdmin (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨723⟩) h712 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchGetRoleAdmin hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/GetTimestamp.lean b/Benchmarks/OpenZeppelinBench/TimelockController/GetTimestamp.lean deleted file mode 100644 index 78b8be94..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/GetTimestamp.lean +++ /dev/null @@ -1,241 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Storage -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch - -/-! -# OpenZeppelin TimelockController `getTimestamp(bytes32)` refinement - -`getTimestamp` is a public non-payable `uint256` getter over the `_timestamps` mapping (base slot 1), -keyed by an ABI-decoded `bytes32` id. Selector index 9, dispatch group G98 arm 2, body pc 1307. -The runtime peels its own non-payable guard, runs the modern word-argument decoder (`@4702`, a signed -`SLT(calldatasize - 4, 32)` availability check), hashes the mapping slot `keccak(id ‖ 1)`, `SLOAD`s -it, and returns the 32-byte word. Template for arg-taking `uint256` mapping getters. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Decoded argument, storage word, and ABI decode -/ - -/-- The ABI-decoded `bytes32` id (the 32-byte calldata word at offset 4), as a mapping key value. -/ -abbrev tlcGetTimestampKey (I : ExecutionEnv) : KeyValue := - .fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32) - -/-- The decoded local store bound by `getTimestamp(bytes32 id)`. -/ -abbrev tlcGetTimestampStore (I : ExecutionEnv) : Store := - (∅ : Store).insert "id" (.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32)) - -/-- The stored `_timestamps[id]` value (mapping slot `keccak(id ‖ 1)`). -/ -def tlcGetTimestampWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) - -/-- The decoded `bytes32` key hashes to the same word the EVM `CALLDATALOAD(4)` loads. -/ -theorem tlcGetTimestampKey_eq (I : ExecutionEnv) (hsz36 : 36 ≤ I.calldata.size) : - keyValueToWord (tlcGetTimestampKey I) = calldataWord I.calldata 4 := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have key_eq : tlcGetTimestampKey I - = .fixedBytes ⟨31, by decide⟩ - (EVM.Word.toBytesBE (ABI.bytesToWord ((I.calldata.toList.drop 4).take 32))) := by - simp only [tlcGetTimestampKey] - rw [show abiBytes32Width = (⟨31, by decide⟩ : Fin 32) from rfl, - toBytesBE_bytesToWord_of_length hlen] - rw [key_eq, keyValueToWord_fixedBytes32, decode_word_at_eq_any I.calldata 4 (by omega)] - -theorem tlcDecodeGetTimestamp_ok {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) : - decodeCalldataWithMode config.abiDecodeMode (getTimestampTransition.params.map Param.name) - (transitionSignature getTimestampTransition).paramTypes I.calldata - = some (tlcGetTimestampStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = _ - exact decodeCalldata_bytes32_ok hsz36 hbig - -theorem tlcDecodeGetTimestamp_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 36) : - decodeCalldataWithMode config.abiDecodeMode (getTimestampTransition.params.map Param.name) - (transitionSignature getTimestampTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_short hsz4 hshort - -theorem tlcDecodeGetTimestamp_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (getTimestampTransition.params.map Param.name) - (transitionSignature getTimestampTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_huge hbig - -/-! ## EVM: reach the body and the length check -/ - -/-- Reach the `getTimestamp` body pc 1307 (G98 arm 2). -/ -theorem tlcReachGetTimestamp {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 9)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1307⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0xd45c4435⟩ := - solcSelectorWord_eq_of_beq I hsz 0xd4 0x5c 0x44 0x35 ⟨0xd45c4435⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG98Body 2 (by omega) ⟨1307⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j <;> (rw [hsw]; native_decide)) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Peel the non-payable guard and run the decoder prologue to the `SLT` availability `JUMPI` @4714. - Stack: `[⟨4718⟩, ISZERO(SLT(size-4, 32)), ⟨0⟩, ⟨4⟩, size, ⟨1333⟩, ⟨581⟩, sel]`. -/ -theorem tlcGetTimestampReachLenCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 9)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4714⟩ - [⟨4718⟩, UInt256.isZero (UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩), - ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1333⟩, ⟨581⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h1307⟩ := tlcReachGetTimestamp (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h1320⟩ := tlcGuardPeelOk (gt := ⟨1318⟩) h1307 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, h1320.push2 ⟨581⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨1333⟩ (by native_decide) (by evm_ov) - |>.calldatasize (by native_decide) (by evm_ov) - |>.push1 ⟨4⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4702⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.slt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨4718⟩ (by native_decide) (by evm_ov)⟩ - -/-- EVM: with zero callvalue and a well-sized calldata, `getTimestamp(id)` returns `_timestamps[id]`. -/ -theorem tlcGetTimestampX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 9)) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (tlcGetTimestampWord σ I)) := by - have hsz : 4 ≤ I.calldata.size := by omega - obtain ⟨_, _, h4714⟩ := tlcGetTimestampReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - have h1333 := h4714.jumpiT (by native_decide) - (by rw [solcDecodeLenCheckOk_4_32 hsz36 hbig hsize]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - obtain ⟨_, _, h581⟩ := tlcMappingGetSlot1 h1333 (by jump_dest) (by simp) - exact tlcReturnWordFromMem h581 (twoWordHashMem_size_96 _ _ solcFreePtrMem_size) - (twoWordHashMem_read64 _ _ solcFreePtrMem_size solcFreePtrMem_read64) (by simp) - -/-- EVM revert path for a mis-sized calldata: the signed length check `SLT(size-4, 32) = 1` - fails the `JUMPI`, falling into the `PUSH0 PUSH0 REVERT` stub. -/ -theorem tlcGetTimestampDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 9)) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4714⟩ := tlcGetTimestampReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact h4714.jumpiNT (by native_decide) (by rw [hslt]; decide) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-! ## Solm body -/ - -/-- The Solm `getTimestamp(id)` body returns `_timestamps[id]`. -/ -theorem tlcGetTimestampBodyReturns {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcGetTimestampStore I) - getTimestampTransition.body - (.returned { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) - (some [(.int (Int.ofNat (tlcGetTimestampWord σ I).toNat))])) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hvk : valueToKey? (Value.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32)) - = some (tlcGetTimestampKey I) := by - simp [valueToKey?, tlcGetTimestampKey, abiBytes32Width, hlen] - have hslot : timestampSlot (tlcGetTimestampKey I) - = solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4) := by - unfold timestampSlot mapSlot solcMappingSlot - rw [tlcGetTimestampKey_eq I hsz36] - refine nonpayableReturnExprBodyReturns (by simp only [initState]; exact hwv) ?_ - unfold timestampExpr - rw [evalExpr_storage_scalar (cfg := config) - (solm := { contract := contract, locals := tlcGetTimestampStore I }) - (slot := timestampRef (.var "id")) - (er := ({ base := "_timestamps", steps := [.mindex (tlcGetTimestampKey I)] } : EvaledStorageRef)) - (t := .int uint256Int) (loc := uint256Loc (timestampSlot (tlcGetTimestampKey I))) - (hbase := by simp [timestampRef]) - (her := by - simp [evalStorageRef, evalStorageRefStep, timestampRef, tlcGetTimestampStore, - EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?, hvk]) - (hty := by - simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, tlcGetTimestampKey, uint256St]) - (hloc := by rfl)] - rw [hslot] - exact congrArg EvalResult.ok - (storageLocLoad_uint256 (initState cA gh bl σ σ₀ g A I) - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4))) - -/-! ## Refinement -/ - -theorem tlcGetTimestampBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 9)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 9) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz36 : 36 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · -- execute: `36 ≤ size < 2^255 + 4` - have hword : tlcGetTimestampWord σ_evm I = tlcGetTimestampWord σ_solm I := by - simp only [tlcGetTimestampWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) ⟨0⟩ - exact tlcReEquivExecTransport hcode - (tlcGetTimestampX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz36 hbig hsize hsel) - (tlcSelectorDispatchGetTimestamp hsel) (tlcDecodeGetTimestamp_ok hsz36 hbig) - (tlcGetTimestampBodyReturns (g := Sat256.ofUInt256 g) hwv hsz36) (by rw [← hword]) hAccounts - (returnEquiv_of_encode - (by simpa [uint256] using uint256ReturnEncoding (tlcGetTimestampWord σ_evm I))) - · -- huge calldata: `2^255 + 4 ≤ size`; EVM reverts at the signed length check, Solm decode fails - have hhuge : 2 ^ 255 + 4 ≤ I.calldata.size := Nat.not_lt.mp hbig - have hrev := tlcGetTimestampDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckHuge_4_32 hhuge hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchGetTimestamp hsel) - (tlcDecodeGetTimestamp_none_huge hhuge) - · -- short calldata: `size < 36`; EVM reverts at the length check, Solm decode fails - have hshort : I.calldata.size < 36 := by omega - have hrev := tlcGetTimestampDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckShort_4_32 hsz hshort hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchGetTimestamp hsel) - (tlcDecodeGetTimestamp_none_short hsz hshort) - · -- nonpayable guard: `callvalue ≠ 0` - obtain ⟨_, _, h1307⟩ := tlcReachGetTimestamp (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨1318⟩) h1307 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchGetTimestamp hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/GrantRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/GrantRole.lean deleted file mode 100644 index 3d90960e..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/GrantRole.lean +++ /dev/null @@ -1,703 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.RevokeRole -import Benchmarks.OpenZeppelinBench.TimelockController.RenounceRole -import Benchmarks.OpenZeppelinBench.TimelockController.GetRoleAdmin -import Benchmarks.OpenZeppelinBench.TimelockController.HasRole -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `grantRole(bytes32,address)` refinement - -`grantRole` (selector index 10, dispatch group G301 arm 1, body pc 789) is `revokeRole` with the write -inverted: it decodes `(bytes32 role, address account)`, reads `_roles[role].adminRole`, enforces -`require(hasRole(adminRole, msg.sender))` (the SAME onlyRole helper `@3461→@3655→@2762`), then calls -the inlined `_grantRole @3953`: it SETS `_roles[role].hasRole[account]` (via `AND(~0xff); OR 1; SSTORE`) -and emits `RoleGranted`, but ONLY IF the role is currently ABSENT. - -The admin read, onlyRole nested-slot load, error-scratch, decoded store, and `letDecl`/onlyRole Solm -evaluations are identical to `revokeRole` and are imported from `RevokeRole.lean`. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## ABI decode (two-arg `(bytes32, address)`, shared decoder; produces `tlcHasRoleStore`) -/ - -theorem tlcDecodeGrantRole_ok {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (grantRoleTransition.params.map Param.name) - (transitionSignature grantRoleTransition).paramTypes I.calldata = some (tlcHasRoleStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "account"] [bytes32, addr] I.calldata = _ - exact decodeCalldata_bytes32_address_ok hsz68 hbig hcanon - -theorem tlcDecodeGrantRole_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 68) : - decodeCalldataWithMode config.abiDecodeMode (grantRoleTransition.params.map Param.name) - (transitionSignature grantRoleTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "account"] [bytes32, addr] I.calldata = none - exact decodeCalldata_bytes32_address_none_short hsz4 hshort - -theorem tlcDecodeGrantRole_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (grantRoleTransition.params.map Param.name) - (transitionSignature grantRoleTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "account"] [bytes32, addr] I.calldata = none - exact decodeCalldata_bytes32_address_none_huge hbig - -theorem tlcDecodeGrantRole_none_noncanon {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hnc : ¬ (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (grantRoleTransition.params.map Param.name) - (transitionSignature grantRoleTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "account"] [bytes32, addr] I.calldata = none - exact decodeCalldata_bytes32_address_none_noncanon hsz68 hbig hnc - -/-! ## EVM: reach the body @789 and run the shared two-arg decoder -/ - -/-- Reach the `grantRole` body pc 789 (G301 arm 1). -/ -theorem tlcReachGrantRole {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 10)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨789⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x2f2ff15d⟩ := - solcSelectorWord_eq_of_beq I hsz 0x2f 0x2f 0xf1 0x5d ⟨0x2f2ff15d⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG301Body 1 (by omega) ⟨789⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j; rw [hsw]; native_decide) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Peel the non-payable guard (gt @800), push continuations `[476, 815]`, and run the two-arg decoder - prologue to the `SLT` length-check `JUMPI` @5012. -/ -theorem tlcGrantRoleReachLenCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 10)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨5012⟩ - [⟨5016⟩, UInt256.isZero (UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩), - ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨815⟩, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h789⟩ := tlcReachGrantRole (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h802⟩ := tlcGuardPeelOk (gt := ⟨800⟩) h789 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, h802.push2 ⟨476⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨815⟩ (by native_decide) (by evm_ov) - |>.calldatasize (by native_decide) (by evm_ov) - |>.push1 ⟨4⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4999⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - |>.dup6 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.slt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨5016⟩ (by native_decide) (by evm_ov)⟩ - -/-- After the length check passes, run the decoder to the address canonicality `EQ`/`JUMPI` @4374. -/ -theorem tlcGrantRoleReachEqCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 10)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4374⟩ - [⟨4378⟩, - UInt256.eq (calldataWord I.calldata 36) - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)), - calldataWord I.calldata 36, ⟨36⟩, ⟨5032⟩, ⟨0⟩, calldataWord I.calldata 4, ⟨4⟩, - UInt256.ofNat I.calldata.size, ⟨815⟩, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = ⟨0⟩ := - solcDecodeLenCheckOk_4_64 hsz68 hbig hsize - obtain ⟨_, _, h5012⟩ := tlcGrantRoleReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv (by omega) hsize hsel - have hoff : (⟨4⟩ : UInt256) + ⟨32⟩ = ⟨36⟩ := by decide - have hafterAdd := h5012.jumpiT (by native_decide) (by rw [hslt]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.push2 ⟨5032⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.add (by native_decide) (by evm_ov) - rw [hoff] at hafterAdd - exact ⟨_, _, hafterAdd.push2 ⟨4356⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨160⟩ (by native_decide) (by evm_ov) - |>.shl (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.and (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.eq (by native_decide) (by evm_ov) - |>.push2 ⟨4378⟩ (by native_decide) (by evm_ov)⟩ - -/-- With a canonical account, finish the decoder and jump through `@815` into the body logic `@1914`, - leaving `[account, role, 476, sel]` over `solcFreePtrMem`. -/ -theorem tlcGrantRoleReach1914 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 10)) - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1914⟩ - [calldataWord I.calldata 36, calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by decide - obtain ⟨_, _, h4374⟩ := tlcGrantRoleReachEqCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv hsz68 hbig hsize hsel - exact ⟨_, _, h4374.jumpiT (by native_decide) - (by rw [hmask, solcAddrCanon_eq hcanon]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨1914⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov)⟩ - -/-! ## EVM: admin read + onlyRole nested-slot load, reaching @3665 (cont `1940`) -/ - -/-- From body-logic `@1914`, compute `adminRole`, dispatch through the onlyRole helpers, and run the - shared `@2762` load, reaching the onlyRole `JUMPI` @3665. Identical to `revokeRole` except the - onlyRole return continuation is `1940` (not `3066`). -/ -theorem tlcGrantRoleReachAdminBit {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1914⟩ - [calldataWord I.calldata 36, calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hsz36 : 36 ≤ I.calldata.size) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3665⟩ - [UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I), solcSourceWord I, - tlcRevokeRoleAdminWord σ I, ⟨3471⟩, tlcRevokeRoleAdminWord σ I, ⟨1940⟩, - tlcRevokeRoleAdminWord σ I, calldataWord I.calldata 36, calldataWord I.calldata 4, - ⟨476⟩, tlcSelWord I] - (tlcRevokeRoleOnlyMem σ I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - have hk := h.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.mstore 0 (wordAt0Mem (calldataWord I.calldata 4) solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.mstore 0 (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.keccak256 0 (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) (UInt256.ofNat 3) - (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact twoWordHashMem_solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4) solcFreePtrMem_size) - (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.add (by native_decide) (by evm_ov) - obtain ⟨_, _, hsl⟩ := hk.sload (by native_decide) (by evm_ov) - rw [tlcRevokeRoleAdminSlot_eq I hsz36] at hsl - have h2762 := hsl.push2 ⟨1940⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.push2 ⟨3461⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨3471⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.caller (by native_decide) (by evm_ov) - |>.push2 ⟨3655⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨3665⟩ (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.push2 ⟨2762⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - exact tlcRevokeRoleSlotLoadGen h2762 (tlcRevokeRoleMem1_size I) (by jump_dest) (by evm_ov) - -/-- `msg.sender` lacks `adminRole`: the onlyRole `JUMPI` is not taken and `@2157` `REVERT`s. Same - error scratch as `revokeRole` (the `1940` return continuation lives below the error's stack use). -/ -theorem tlcGrantRoleRevAdmin {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3665⟩ - [UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I), solcSourceWord I, - tlcRevokeRoleAdminWord σ I, ⟨3471⟩, tlcRevokeRoleAdminWord σ I, ⟨1940⟩, - tlcRevokeRoleAdminWord σ I, calldataWord I.calldata 36, calldataWord I.calldata 4, - ⟨476⟩, tlcSelWord I] - (tlcRevokeRoleOnlyMem σ I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hunauth : UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have h2165 := evm_run h with [ - jumpdest, - push2 ⟨3712⟩, - jumpiNT (by exact hunauth), - push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [tlcRevokeRoleOnlyMem_size]; decide) (by decide) - (tlcRevokeRoleOnlyMem_read64 σ I)) (by native_decide) (by evm_ov), - raw push4 ⟨0xe2517d3f⟩ (by native_decide) (by evm_ov), - push1 ⟨224⟩, shl, dup2, - raw mstore 6 (tlcRevokeRoleErr1 _ σ I) (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, - push1 ⟨4⟩, dup3, add, - raw mstore 3 (tlcRevokeRoleErr2 _ _ σ I) (UInt256.ofNat 6) (by native_decide) mem_cost - (by rw [show (⟨128⟩ + ⟨4⟩ : UInt256).toNat = 132 from by native_decide]) - (by native_decide) (by evm_ov), - push1 ⟨36⟩, dup2, add, dup4, swap1, - raw mstore 3 (tlcRevokeRoleErr3 _ _ _ σ I) (UInt256.ofNat 7) (by native_decide) mem_cost - (by rw [show (⟨128⟩ + ⟨36⟩ : UInt256).toNat = 164 from by native_decide]) - (by native_decide) (by evm_ov), - push1 ⟨68⟩, add, push2 ⟨2157⟩, jump (by jump_dest), - jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 7) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [tlcRevokeRoleErr3_size]; decide) (by decide) - (tlcRevokeRoleErr3_read64 _ _ _ σ I)) (by native_decide) (by evm_ov), - dup1, swap2, sub, swap1 ] - exact h2165.rev 0 (by native_decide) mem_cost (by evm_ov) - -/-- `msg.sender` has `adminRole`: dispatch to `_grantRole @3953` and run the shared `@2762` load for - `_roles[role].hasRole[account]`, reaching the `if present` `JUMPI` @3964 (no `ISZERO` — inverted - from `_revokeRole`). -/ -theorem tlcGrantRoleReach3964 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3665⟩ - [UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I), solcSourceWord I, - tlcRevokeRoleAdminWord σ I, ⟨3471⟩, tlcRevokeRoleAdminWord σ I, ⟨1940⟩, - tlcRevokeRoleAdminWord σ I, calldataWord I.calldata 36, calldataWord I.calldata 4, - ⟨476⟩, tlcSelWord I] - (tlcRevokeRoleOnlyMem σ I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hauth : ¬ UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3964⟩ - [UInt256.land ⟨255⟩ (tlcHasRoleWord σ I), ⟨0⟩, calldataWord I.calldata 36, - calldataWord I.calldata 4, ⟨1950⟩, tlcRevokeRoleAdminWord σ I, calldataWord I.calldata 36, - calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - (tlcRevokeRoleWriteMem σ I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - have h2762 := h.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨3712⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) (by exact hauth) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨1950⟩ (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - |>.push2 ⟨3953⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push2 ⟨3964⟩ (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - |>.push2 ⟨2762⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - exact tlcRevokeRoleSlotLoadGen h2762 (tlcRevokeRoleOnlyMem_size σ I) (by jump_dest) (by evm_ov) - -/-- Role present (`_roles[role].hasRole[account]` already `true`): `_grantRole` skips at `@4089`, - does no `SSTORE`/`LOG`, and `STOP`s with the account map unchanged. -/ -theorem tlcGrantRoleXSkip {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3665⟩ - [UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I), solcSourceWord I, - tlcRevokeRoleAdminWord σ I, ⟨3471⟩, tlcRevokeRoleAdminWord σ I, ⟨1940⟩, - tlcRevokeRoleAdminWord σ I, calldataWord I.calldata 36, calldataWord I.calldata 4, - ⟨476⟩, tlcSelWord I] - (tlcRevokeRoleOnlyMem σ I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hauth : ¬ UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) - (hpresent : ¬ UInt256.land ⟨255⟩ (tlcHasRoleWord σ I) = ⟨0⟩) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - ByteArray.empty := by - obtain ⟨_, _, h3964⟩ := tlcGrantRoleReach3964 h hauth - have h476 := evm_run h3964 with [ - jumpdest, - push2 ⟨4089⟩, - jumpiT (by exact hpresent) (by jump_dest), - jumpdest, - pop, push0, push2 ⟨1685⟩, - jump (by jump_dest), - jumpdest, - swap3, swap2, pop, pop, - jump (by jump_dest), - jumpdest, - pop, pop, pop, pop, - jump (by jump_dest), - jumpdest ] - exact h476.stop (by native_decide) (by evm_ov) - -/-- The `RoleGranted(bytes32,address,address)` event topic (the `PUSH32` at pc 4038). -/ -abbrev tlcGrantRoleGrantedTopic : UInt256 := - ⟨0x2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d⟩ - -/-- The `EVM.State` after `_roles[role].hasRole[account] = true` (set low byte via `OR 1`). -/ -abbrev tlcGrantRolePost (evm : EVM.State) (I : ExecutionEnv) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner (tlcHasRoleSlot I) - (UInt256.lor - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (tlcHasRoleSlot I)) - (UInt256.lnot ⟨255⟩)) ⟨1⟩) - -/-- Role absent (`_roles[role].hasRole[account]` currently `false`): `_grantRole` recomputes the - nested slot, `SSTORE`s `(word & ~0xff) | 1` (setting the bool to `true`), emits `RoleGranted` - `LOG4`, and `STOP`s — halting with the account map carrying the single nested-slot write. -/ -theorem tlcGrantRoleXWrite {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3665⟩ - [UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I), solcSourceWord I, - tlcRevokeRoleAdminWord σ I, ⟨3471⟩, tlcRevokeRoleAdminWord σ I, ⟨1940⟩, - tlcRevokeRoleAdminWord σ I, calldataWord I.calldata 36, calldataWord I.calldata 4, - ⟨476⟩, tlcSelWord I] - (tlcRevokeRoleOnlyMem σ I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hperm : I.perm = true) - (hauth : ¬ UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) - (habsent : UInt256.land ⟨255⟩ (tlcHasRoleWord σ I) = ⟨0⟩) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) - (cA, sstoreAccountMap I.codeOwner σ (tlcHasRoleSlot I) - (UInt256.lor ⟨1⟩ (UInt256.land (UInt256.lnot ⟨255⟩) (tlcHasRoleWord σ I)))) ByteArray.empty := by - obtain ⟨_, _, h3964⟩ := tlcGrantRoleReach3964 h hauth - have hM0 : (tlcRevokeRoleWriteMem σ I).size = 96 := - twoWordHashMem_size_96 _ _ (twoWordHashMem_size_96 _ _ (tlcRevokeRoleOnlyMem_size σ I)) - have hM2 : (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRevokeRoleWriteMem σ I)).size = 96 := - twoWordHashMem_size_96 _ _ hM0 - have hM4size : (twoWordHashMem - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) - (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRevokeRoleWriteMem σ I))).size = 96 := - twoWordHashMem_size_96 _ _ hM2 - have hM4read64 : (twoWordHashMem - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) - (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRevokeRoleWriteMem σ I))).readWithPadding - 64 32 = UInt256.toByteArray ⟨128⟩ := - twoWordHashMem_read64 _ _ hM2 (twoWordHashMem_read64 _ _ hM0 - (twoWordHashMem_read64 _ _ (twoWordHashMem_size_96 _ _ (tlcRevokeRoleOnlyMem_size σ I)) - (twoWordHashMem_read64 _ _ (tlcRevokeRoleOnlyMem_size σ I) (tlcRevokeRoleOnlyMem_read64 σ I)))) - have hkec := evm_run h3964 with [ - jumpdest, - push2 ⟨4089⟩, - jumpiNT (by exact habsent), - push0, dup4, dup2, - raw mstore 0 (wordAt0Mem (calldataWord I.calldata 4) (tlcRevokeRoleWriteMem σ I)) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨32⟩, dup2, dup2, - raw mstore 0 (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRevokeRoleWriteMem σ I)) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨64⟩, dup1, dup4, - raw keccak256 0 (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) (UInt256.ofNat 3) - (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact twoWordHashMem_solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4) hM0) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup7, and, dup5, - raw mstore 0 (wordAt0Mem - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRevokeRoleWriteMem σ I))) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - swap1, swap2, - raw mstore 0 (twoWordHashMem - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) - (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRevokeRoleWriteMem σ I))) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - swap1, - raw keccak256 0 (tlcHasRoleSlot I) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact (twoWordHashMem_solcMappingSlot (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) hM2).trans - (tlcRenounceRoleOuterSlot I)) - (by native_decide) (by evm_ov), - dup1 ] - obtain ⟨_, _, hsl⟩ := hkec.sload (by native_decide) (by evm_ov) - have hsstorepre := evm_run hsl with [ push1 ⟨255⟩, not, and, push1 ⟨1⟩, lor, swap1 ] - obtain ⟨_, _, hss⟩ := hsstorepre.sstore hperm (by native_decide) (by evm_ov) - have hlogpre := evm_run hss with [ - push2 ⟨4017⟩, - raw caller (by native_decide) (by evm_ov), - swap1, jump (by jump_dest), - jumpdest, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, and, dup3, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, and, dup5 ] - have hlog := (hlogpre.pushConst tlcGrantRoleGrantedTopic (width := 32) (op := .PUSH32) - (by decide) (by native_decide) (by evm_ov)).push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [hM4size]; decide) (by decide) hM4read64) (by native_decide) - (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [hM4size]; decide) (by decide) hM4read64) (by native_decide) - (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - have h476 := (hlog.log4 0 (UInt256.ofNat 3) (by native_decide) hperm mem_cost - (by native_decide) (by evm_ov)) |>.pop (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨1685⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - exact h476.stop (by native_decide) (by evm_ov) - -/-! ## EVM decode-revert paths -/ - -theorem tlcGrantRoleDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 10)) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h5012⟩ := tlcGrantRoleReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv hsz hsize hsel - exact h5012.jumpiNT (by native_decide) (by rw [hslt]; decide) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -theorem tlcGrantRoleNoncanonRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 10)) - (hnc : ¬ (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by decide - obtain ⟨_, _, h4374⟩ := tlcGrantRoleReachEqCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv hsz68 hbig hsize hsel - exact h4374.jumpiNT (by native_decide) (by rw [hmask]; exact tlcHasRoleNoncanon_eq hnc) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-! ## Solm body (`grantRoleIfMissing`: write `true` only if the role is currently absent) -/ - -/-- The `_roles[role].hasRole[account] = true` write collapses to a single bool `storageStore`. -/ -theorem tlcGrantRoleAssign {cA gh bl σ σ₀ A I} {g : Sat256} (hsz36 : 36 ≤ I.calldata.size) : - assignStorageRef? config { contract := contract, locals := tlcRevokeRoleStore' σ I } - (initState cA gh bl σ σ₀ g A I) .storage - (roleHasRoleRef (.var "role") (.var "account")) (.bool true) - = .ok ({ contract := contract, locals := tlcRevokeRoleStore' σ I }, - tlcGrantRolePost (initState cA gh bl σ σ₀ g A I) I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hslot : roleHasRoleSlot (tlcHasRoleRoleKey I) (tlcHasRoleAccountKey I) = tlcHasRoleSlot I := - tlcHasRoleSlot_eq I hsz36 - refine assignStorageRef_storage_scalar_value (cfg := config) - (solm := { contract := contract, locals := tlcRevokeRoleStore' σ I }) - (slot := roleHasRoleRef (.var "role") (.var "account")) - (er := ({ base := "_roles", steps := [.mindex (tlcHasRoleRoleKey I), .field "hasRole", - .mindex (tlcHasRoleAccountKey I)] } : EvaledStorageRef)) - (ty := boolSt) - (loc := boolLoc (roleHasRoleSlot (tlcHasRoleRoleKey I) (tlcHasRoleAccountKey I))) - (value := .bool true) ?_ ?_ ?_ ?_ (by trivial) ?_ - · simp only [roleHasRoleRef]; exact tlcRevokeRoleStore'_get_roles σ I - · simp [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, roleHasRoleRef, - tlcRevokeRoleStore'_index_role, tlcRevokeRoleStore'_index_account, tlcHasRoleAccountKey, - valueToKey?, hlen, abiBytes32Width, EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?] - · simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, roleDataSt, boolSt] - · rfl - · rw [hslot] - show storageLocStore (initState cA gh bl σ σ₀ g A I) (boolOffset0Loc (tlcHasRoleSlot I)) - (.bool true) = some (tlcGrantRolePost (initState cA gh bl σ σ₀ g A I) I) - rw [storageLocStore_bool_true_offset0] - -/-- The inverted guard `!hasRole(role, account)` is `true` when the role is absent. -/ -theorem tlcGrantRoleGuardEvalTrue {cA gh bl σ σ₀ A I} {g : Sat256} (hsz36 : 36 ≤ I.calldata.size) - (habs : UInt256.land ⟨255⟩ (tlcHasRoleWord σ I) = ⟨0⟩) : - evalExpr? config { contract := contract, locals := tlcRevokeRoleStore' σ I } - (initState cA gh bl σ σ₀ g A I) - (.unary .not (hasRoleExpr (.var "role") (.var "account"))) = .ok (.bool true) := by - simp only [evalExpr?, EvalResult.bind, bind, tlcRevokeRoleHasRoleEval hsz36, - tlcRevokeRoleWordToElem_absent habs] - rfl - -/-- The inverted guard `!hasRole(role, account)` is `false` when the role is present. -/ -theorem tlcGrantRoleGuardEvalFalse {cA gh bl σ σ₀ A I} {g : Sat256} (hsz36 : 36 ≤ I.calldata.size) - (hpres : ¬ UInt256.land ⟨255⟩ (tlcHasRoleWord σ I) = ⟨0⟩) : - evalExpr? config { contract := contract, locals := tlcRevokeRoleStore' σ I } - (initState cA gh bl σ σ₀ g A I) - (.unary .not (hasRoleExpr (.var "role") (.var "account"))) = .ok (.bool false) := by - simp only [evalExpr?, EvalResult.bind, bind, tlcRevokeRoleHasRoleEval hsz36, - tlcRevokeRoleWordToElem_present hpres] - rfl - -/-- Authorized + role absent: the body sets the bit (`.ite` then-branch writes `true`). -/ -theorem tlcGrantRoleBodyWrite {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hauth : ¬ UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) - (habs : UInt256.land ⟨255⟩ (tlcHasRoleWord σ I) = ⟨0⟩) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcHasRoleStore I) - grantRoleTransition.body - (.returned { contract := contract, locals := tlcRevokeRoleStore' σ I } - (tlcGrantRolePost (initState cA gh bl σ σ₀ g A I) I) none) := by - refine ExecFuncBody.execBlockOK ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true - (by simp only [initState]; exact hwv))) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (tlcRevokeRoleLetDeclEval hsz36)) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue - (by rw [tlcRevokeRoleOnlyRoleEval, tlcRevokeRoleAdminWordToElem_present hauth])) ?_ - refine ExecBlock.consNormal (ExecStmt.iteTrue (tlcGrantRoleGuardEvalTrue hsz36 habs) ?_) - ExecBlock.nil - exact ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) (tlcGrantRoleAssign hsz36)) - ExecBlock.nil - -/-- Authorized + role present: the body takes the empty `.ite` else-branch, state unchanged. -/ -theorem tlcGrantRoleBodySkip {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hauth : ¬ UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) - (hpres : ¬ UInt256.land ⟨255⟩ (tlcHasRoleWord σ I) = ⟨0⟩) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcHasRoleStore I) - grantRoleTransition.body - (.returned { contract := contract, locals := tlcRevokeRoleStore' σ I } - (initState cA gh bl σ σ₀ g A I) none) := by - refine ExecFuncBody.execBlockOK ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true - (by simp only [initState]; exact hwv))) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (tlcRevokeRoleLetDeclEval hsz36)) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue - (by rw [tlcRevokeRoleOnlyRoleEval, tlcRevokeRoleAdminWordToElem_present hauth])) ?_ - exact ExecBlock.consNormal (ExecStmt.iteFalse (tlcGrantRoleGuardEvalFalse hsz36 hpres) - ExecBlock.nil) ExecBlock.nil - -/-- Unauthorized: the body reverts at `require(hasRole(adminRole, msg.sender))`. -/ -theorem tlcGrantRoleBodyRevertAdmin {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hunauth : UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcHasRoleStore I) - grantRoleTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true - (by simp only [initState]; exact hwv))) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (tlcRevokeRoleLetDeclEval hsz36)) ?_ - exact ExecBlock.consRevert (ExecStmt.requireFalse - (by rw [tlcRevokeRoleOnlyRoleEval, tlcRevokeRoleAdminWordToElem_absent hunauth])) - -/-! ## Refinement -/ - -/-- Refinement of `GrantRole` (selector index 10). -/ -theorem tlcGrantRoleBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 10)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 10) (by native_decide) hsel - have hword : tlcHasRoleWord σ_evm I = tlcHasRoleWord σ_solm I := by - simp only [tlcHasRoleWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner (tlcHasRoleSlot I) ⟨0⟩ - have hadminword : tlcRevokeRoleAdminWord σ_evm I = tlcRevokeRoleAdminWord σ_solm I := by - simp only [tlcRevokeRoleAdminWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner (roleAdminSlot (tlcHasRoleRoleKey I)) ⟨0⟩ - have hadminslot : tlcRevokeRoleAdminSlot σ_evm I = tlcRevokeRoleAdminSlot σ_solm I := by - simp only [tlcRevokeRoleAdminSlot, hadminword] - have hadminhasrole : tlcRevokeRoleAdminHasRoleWord σ_evm I = tlcRevokeRoleAdminHasRoleWord σ_solm I := by - simp only [tlcRevokeRoleAdminHasRoleWord, hadminslot] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner (tlcRevokeRoleAdminSlot σ_solm I) ⟨0⟩ - have henc : returnEquiv ByteArray.empty none grantRoleTransition.returnType := by - simpa [grantRoleTransition] using - (returnEquiv.fallthrough (o := ByteArray.empty) (r := none) (t := []) - (dvs := []) rfl (by native_decide) (by native_decide)) - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz68 : 68 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · by_cases hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus - · obtain ⟨_, _, h1914⟩ := tlcGrantRoleReach1914 (cA := cA) (gh := gh) (bl := bl) - (σ := σ_evm) (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) - hcode hwv hsz68 hbig hsize hsel hcanon - obtain ⟨_, _, h3665⟩ := tlcGrantRoleReachAdminBit h1914 (by omega) - by_cases hauth : UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ_evm I) = ⟨0⟩ - · -- unauthorized: both revert - exact tlcReEquivExecRev hcode (tlcGrantRoleRevAdmin h3665 hauth) - (tlcSelectorDispatchGrantRole hsel) (tlcDecodeGrantRole_ok hsz68 hbig hcanon) - (tlcGrantRoleBodyRevertAdmin (σ := σ_solm) hwv (by omega) - (by rw [← hadminhasrole]; exact hauth)) - · by_cases hpres : UInt256.land ⟨255⟩ (tlcHasRoleWord σ_evm I) = ⟨0⟩ - · -- role absent: both SSTORE `true` - refine tlcReEquivExecGen hcode - (tlcGrantRoleXWrite h3665 _hperm hauth hpres) - (tlcSelectorDispatchGrantRole hsel) (tlcDecodeGrantRole_ok hsz68 hbig hcanon) - (tlcGrantRoleBodyWrite (σ := σ_solm) hwv (by omega) - (by rw [← hadminhasrole]; exact hauth) (by rw [← hword]; exact hpres)) - (by simp [tlcGrantRolePost, initState, storageStore_createdAccounts]) ?_ henc - have hval : UInt256.lor ⟨1⟩ (UInt256.land (UInt256.lnot ⟨255⟩) (tlcHasRoleWord σ_evm I)) - = UInt256.lor (UInt256.land (tlcHasRoleWord σ_solm I) (UInt256.lnot ⟨255⟩)) ⟨1⟩ := by - rw [u256_land_comm, hword, u256_lor_comm] - rw [hval] - simpa [tlcGrantRolePost, initState, storageStore_accountMap, - codeOwnerStorageWord_initState] using - accountMapEquiv_sstoreAccountMap I.codeOwner (tlcHasRoleSlot I) - (UInt256.lor (UInt256.land (tlcHasRoleWord σ_solm I) (UInt256.lnot ⟨255⟩)) ⟨1⟩) - hAccounts - · -- role present: no write on either side - exact tlcReEquivExecGen hcode - (tlcGrantRoleXSkip h3665 hauth hpres) - (tlcSelectorDispatchGrantRole hsel) (tlcDecodeGrantRole_ok hsz68 hbig hcanon) - (tlcGrantRoleBodySkip (σ := σ_solm) hwv (by omega) - (by rw [← hadminhasrole]; exact hauth) (by rw [← hword]; exact hpres)) - (by simp [initState]) - (by simpa [initState] using hAccounts) henc - · -- non-canonical account: EVM reverts at the address check, Solm decode fails - exact tlcReEquivDecodeFailed hcode - (tlcGrantRoleNoncanonRevert (g := Sat256.ofUInt256 g) hcode hwv hsz68 hbig hsize hsel - hcanon) - (tlcSelectorDispatchGrantRole hsel) (tlcDecodeGrantRole_none_noncanon hsz68 hbig hcanon) - · -- huge calldata - have hhuge : 2 ^ 255 + 4 ≤ I.calldata.size := Nat.not_lt.mp hbig - exact tlcReEquivDecodeFailed hcode - (tlcGrantRoleDecodeRevert (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckHuge_4_64 hhuge hsize)) - (tlcSelectorDispatchGrantRole hsel) (tlcDecodeGrantRole_none_huge hhuge) - · -- short calldata - have hshort : I.calldata.size < 68 := by omega - exact tlcReEquivDecodeFailed hcode - (tlcGrantRoleDecodeRevert (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckShort_4_64 hsz hshort hsize)) - (tlcSelectorDispatchGrantRole hsel) (tlcDecodeGrantRole_none_short hsz hshort) - · -- nonpayable guard: callvalue ≠ 0 - obtain ⟨_, _, h789⟩ := tlcReachGrantRole (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨800⟩) h789 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchGrantRole hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/HasRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/HasRole.lean deleted file mode 100644 index 81d0814d..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/HasRole.lean +++ /dev/null @@ -1,501 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Storage -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `hasRole(bytes32,address)` refinement - -`hasRole` is a public non-payable `bool` getter over the NESTED mapping `_roles[role].hasRole[account]` -(base slot 0): the slot is `keccak(account ‖ keccak(role ‖ 0))`. Selector index 11, dispatch group -G147 arm 0, body pc 1101. The runtime peels its non-payable guard, jumps to the out-of-line two-arg -decoder (`@4999`, a signed `SLT(size-4, 64)` length check + an address-canonicality `EQ` check in the -sub-decoder `@4356`), computes the nested slot with two `MSTORE+KECCAK256` rounds (`@2762`), `SLOAD`s -it, masks the low byte, and returns the `iszero(iszero(word & 0xff))`-normalized bool (`@509`). -Template for nested-mapping `bool` getters (grantRole/revokeRole read the same slot). --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Decoded arguments, storage slot, and stored word -/ - -/-- The ABI-decoded `bytes32` role key (the 32-byte calldata word at offset 4), as a mapping key. -/ -abbrev tlcHasRoleRoleKey (I : ExecutionEnv) : KeyValue := - .fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32) - -/-- The ABI-decoded `address` account key (the canonical word at offset 36), as a mapping key. -/ -abbrev tlcHasRoleAccountKey (I : ExecutionEnv) : KeyValue := - .address (AccountAddress.ofNat (calldataWord I.calldata 36).toNat) - -/-- The decoded local store bound by `hasRole(bytes32 role, address account)`. -/ -abbrev tlcHasRoleStore (I : ExecutionEnv) : Store := - ((∅ : Store).insert "role" (.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32))).insert - "account" (.address (AccountAddress.ofNat (calldataWord I.calldata 36).toNat)) - -/-- The nested-mapping slot `keccak(account ‖ keccak(role ‖ 0))` as the solc runtime computes it. -/ -def tlcHasRoleSlot (I : ExecutionEnv) : UInt256 := - solcMappingSlot (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (UInt256.land solcAddrMask (calldataWord I.calldata 36)) - -/-- The stored `_roles[role].hasRole[account]` word. -/ -abbrev tlcHasRoleWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (tlcHasRoleSlot I) - -/-- The decoded `bytes32` role key hashes to the same word `CALLDATALOAD(4)` loads. -/ -theorem tlcHasRoleRoleKey_eq (I : ExecutionEnv) (hsz36 : 36 ≤ I.calldata.size) : - keyValueToWord (tlcHasRoleRoleKey I) = calldataWord I.calldata 4 := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have key_eq : tlcHasRoleRoleKey I - = .fixedBytes ⟨31, by decide⟩ - (EVM.Word.toBytesBE (ABI.bytesToWord ((I.calldata.toList.drop 4).take 32))) := by - simp only [tlcHasRoleRoleKey] - rw [show abiBytes32Width = (⟨31, by decide⟩ : Fin 32) from rfl, - toBytesBE_bytesToWord_of_length hlen] - rw [key_eq, keyValueToWord_fixedBytes32, decode_word_at_eq_any I.calldata 4 (by omega)] - -/-- The spec `roleHasRoleSlot` equals the runtime nested keccak slot. -/ -theorem tlcHasRoleSlot_eq (I : ExecutionEnv) (hsz36 : 36 ≤ I.calldata.size) : - roleHasRoleSlot (tlcHasRoleRoleKey I) (tlcHasRoleAccountKey I) = tlcHasRoleSlot I := by - unfold tlcHasRoleSlot roleHasRoleSlot roleDataSlot mapSlot solcMappingSlot - rw [tlcHasRoleRoleKey_eq I hsz36, - keyValueToWord_address_ofNat_mask (calldataWord I.calldata 36)] - -/-- A non-canonical address word (solc's `EQ` returns `0`, forcing a revert). -/ -theorem tlcHasRoleNoncanon_eq {w : UInt256} (hnc : ¬ w.toNat < EVM.addressModulus) : - UInt256.eq w (UInt256.land w solcAddrMask) = ⟨0⟩ := by - have hne : ¬ (w = UInt256.land w solcAddrMask) := fun h => - hnc (h ▸ solcAddrMask_result_canonical w) - show UInt256.fromBool (decide (w = UInt256.land w solcAddrMask)) = ⟨0⟩ - rw [decide_eq_false hne]; rfl - -/-- Low-byte mask commutes: solc emits `AND(0xff, word)`, the spec uses `word & 0xff`. -/ -theorem tlcHasRoleLand255_comm (w : UInt256) : - UInt256.land ⟨255⟩ w = UInt256.land w ⟨255⟩ := by - apply u256_inj - rw [uland_toNat, uland_toNat] - exact nat_land_comm _ _ - -/-! ## ABI decode -/ - -theorem tlcDecodeHasRole_ok {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (hasRoleTransition.params.map Param.name) - (transitionSignature hasRoleTransition).paramTypes I.calldata = some (tlcHasRoleStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "account"] [bytes32, addr] I.calldata = _ - exact decodeCalldata_bytes32_address_ok hsz68 hbig hcanon - -theorem tlcDecodeHasRole_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 68) : - decodeCalldataWithMode config.abiDecodeMode (hasRoleTransition.params.map Param.name) - (transitionSignature hasRoleTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "account"] [bytes32, addr] I.calldata = none - exact decodeCalldata_bytes32_address_none_short hsz4 hshort - -theorem tlcDecodeHasRole_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (hasRoleTransition.params.map Param.name) - (transitionSignature hasRoleTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "account"] [bytes32, addr] I.calldata = none - exact decodeCalldata_bytes32_address_none_huge hbig - -theorem tlcDecodeHasRole_none_noncanon {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hnc : ¬ (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (hasRoleTransition.params.map Param.name) - (transitionSignature hasRoleTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "account"] [bytes32, addr] I.calldata = none - exact decodeCalldata_bytes32_address_none_noncanon hsz68 hbig hnc - -/-! ## EVM: reach the body and the out-of-line decoder length check -/ - -/-- Reach the `hasRole` body pc 1101 (G147 arm 0). -/ -theorem tlcReachHasRole {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 11)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1101⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x91d14854⟩ := - solcSelectorWord_eq_of_beq I hsz 0x91 0xd1 0x48 0x54 ⟨0x91d14854⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG147Body 0 (by omega) ⟨1101⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; exact absurd hj (Nat.not_lt_zero j)) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Peel the non-payable guard and run the two-arg decoder prologue to the `SLT` length-check `JUMPI` - @5012. Stack: `[⟨5016⟩, ISZERO(SLT(size-4, 64)), ⟨0⟩, ⟨0⟩, ⟨4⟩, size, ⟨1127⟩, ⟨509⟩, sel]`. -/ -theorem tlcHasRoleReachLenCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 11)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨5012⟩ - [⟨5016⟩, UInt256.isZero (UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩), - ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1127⟩, ⟨509⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h1101⟩ := tlcReachHasRole (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h1114⟩ := tlcGuardPeelOk (gt := ⟨1112⟩) h1101 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, h1114.push2 ⟨509⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨1127⟩ (by native_decide) (by evm_ov) - |>.calldatasize (by native_decide) (by evm_ov) - |>.push1 ⟨4⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4999⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - |>.dup6 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.slt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨5016⟩ (by native_decide) (by evm_ov)⟩ - -/-! ## Bool-return encoder @509 (memory-generic; normalizes `word & 0xff`) - - Store `iszero(iszero val)` at the free pointer, fall through the return dispatcher @521, - `RETURN(0x80, 0x20)`. A nested-mapping getter dirties the `[0,0x40)` scratch, so this runs over - any free-pointer-preserving 96-byte memory (unlike `SupportsInterface.tlcSuppIfaceReturnBool`, - which is fixed to `solcFreePtrMem`). -/ -theorem tlcHasRoleReturnBool {cA gh bl σ σ₀ A I} {g : Sat256} {val : UInt256} {R : List UInt256} - {mem : ByteArray} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨509⟩ - (val :: R) mem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hsize : mem.size = 96) - (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) - (hov : R.length + 5 ≤ 1024) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.isZero (UInt256.isZero val))) := by - set nv := UInt256.isZero (UInt256.isZero val) with hnv - have h521 := h.jumpdest (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [hsize]; decide) (by decide) hread64) (by decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.mstore 6 (tlcRetMem mem nv) (UInt256.ofNat 5) (by native_decide) mem_cost - (by rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide]; rfl) (by decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.add (by native_decide) (by evm_ov) - have hret := h521.jumpdest (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.mload 0 ⟨128⟩ (UInt256.ofNat 5) (by native_decide) mem_cost - (tlcRetMem_mload64 hsize hread64 nv) (by decide) (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - exact hret.ret 0 (UInt256.toByteArray nv) (by native_decide) mem_cost - (by rw [show ((⟨32⟩ + ⟨128⟩ : UInt256).sub ⟨128⟩).toNat = 32 from by decide, - show (⟨128⟩ : UInt256).toNat = 128 from by decide]; exact tlcRetMem_read128 hsize nv) - (by evm_ov) - -/-! ## Nested-mapping slot computation + `SLOAD` @2762 - - Entry stack `[account, role, cont, …R]` over `solcFreePtrMem`. Writes `role‖0`, hashes the inner - slot `keccak(role‖0)`, masks `account`, writes `account‖inner`, hashes the outer slot, `SLOAD`s - it, masks the low byte, and `JUMP`s to `cont` leaving `[account&0xff-loaded-word, …R]`. -/ -theorem tlcHasRoleSlotLoad {cA gh bl σ σ₀ A I} {g : Sat256} - {account role cont : UInt256} {R : List UInt256} {rdata : ByteArray} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2762⟩ - (account :: role :: cont :: R) solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hret : (D_J timelockControllerBenchBytecode 0).contains cont = true) - (hov : R.length + 12 ≤ 1024) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) cont - (UInt256.land ⟨255⟩ - (solcSlotWord σ I - (solcMappingSlot (solcMappingSlot ⟨0⟩ role) (UInt256.land solcAddrMask account))) :: R) - (twoWordHashMem (UInt256.land solcAddrMask account) (solcMappingSlot ⟨0⟩ role) - (twoWordHashMem role ⟨0⟩ solcFreePtrMem)) (UInt256.ofNat 3) rdata (cA, σ) k' C' := by - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by decide - have hkec := h.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.mstore 0 (wordAt0Mem role solcFreePtrMem) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rfl) (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.mstore 0 (twoWordHashMem role ⟨0⟩ solcFreePtrMem) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rfl) (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.keccak256 0 (solcMappingSlot ⟨0⟩ role) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact twoWordHashMem_solcMappingSlot ⟨0⟩ role solcFreePtrMem_size) - (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨160⟩ (by native_decide) (by evm_ov) - |>.shl (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.swap4 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.swap4 (by native_decide) (by evm_ov) - |>.and (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.mstore 0 - (wordAt0Mem (UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) account) - (twoWordHashMem role ⟨0⟩ solcFreePtrMem)) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rfl) (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.mstore 0 - (twoWordHashMem (UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) account) - (solcMappingSlot ⟨0⟩ role) (twoWordHashMem role ⟨0⟩ solcFreePtrMem)) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.keccak256 0 - (solcMappingSlot (solcMappingSlot ⟨0⟩ role) - (UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) account)) - (UInt256.ofNat 3) (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact twoWordHashMem_solcMappingSlot (solcMappingSlot ⟨0⟩ role) - (UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) account) - (twoWordHashMem_size_96 role ⟨0⟩ solcFreePtrMem_size)) - (by native_decide) (by evm_ov) - obtain ⟨_, _, hsl⟩ := hkec.sload (by native_decide) (by evm_ov) - have hfin := hsl.push1 ⟨255⟩ (by native_decide) (by evm_ov) - |>.and (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.jump (by native_decide) hret (by evm_ov) - exact ⟨_, _, by simpa only [hmask] using hfin⟩ - -/-! ## EVM: the full execute trace, reaching the address-canonicality check -/ - -/-- After the length check passes (`68 ≤ size < 2^255+4`), run the two-arg decoder to the address - sub-decoder's canonicality `EQ`/`JUMPI` @4374. Stack top is the check condition. -/ -theorem tlcHasRoleReachEqCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 11)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4374⟩ - [⟨4378⟩, - UInt256.eq (calldataWord I.calldata 36) - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)), - calldataWord I.calldata 36, ⟨36⟩, ⟨5032⟩, ⟨0⟩, calldataWord I.calldata 4, ⟨4⟩, - UInt256.ofNat I.calldata.size, ⟨1127⟩, ⟨509⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = ⟨0⟩ := - solcDecodeLenCheckOk_4_64 hsz68 hbig hsize - obtain ⟨_, _, h5012⟩ := tlcHasRoleReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv (by omega) hsize hsel - have hoff : (⟨4⟩ : UInt256) + ⟨32⟩ = ⟨36⟩ := by decide - have hafterAdd := h5012.jumpiT (by native_decide) (by rw [hslt]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.push2 ⟨5032⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.add (by native_decide) (by evm_ov) - rw [hoff] at hafterAdd - exact ⟨_, _, hafterAdd.push2 ⟨4356⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨160⟩ (by native_decide) (by evm_ov) - |>.shl (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.and (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.eq (by native_decide) (by evm_ov) - |>.push2 ⟨4378⟩ (by native_decide) (by evm_ov)⟩ - -/-- EVM: with zero callvalue, a well-sized calldata, and a canonical account, `hasRole` returns the - normalized `_roles[role].hasRole[account]` bool. -/ -theorem tlcHasRoleX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 11)) - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray - (UInt256.isZero (UInt256.isZero (UInt256.land (tlcHasRoleWord σ I) ⟨255⟩)))) := by - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by decide - obtain ⟨_, _, h4374⟩ := tlcHasRoleReachEqCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv hsz68 hbig hsize hsel - have h2762 := h4374.jumpiT (by native_decide) - (by rw [hmask, solcAddrCanon_eq hcanon]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨2762⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - obtain ⟨_, _, h509⟩ := tlcHasRoleSlotLoad h2762 (by jump_dest) (by evm_ov) - rw [tlcHasRoleLand255_comm] at h509 - exact tlcHasRoleReturnBool h509 - (twoWordHashMem_size_96 _ _ (twoWordHashMem_size_96 _ _ solcFreePtrMem_size)) - (twoWordHashMem_read64 _ _ (twoWordHashMem_size_96 _ _ solcFreePtrMem_size) - (twoWordHashMem_read64 _ _ solcFreePtrMem_size solcFreePtrMem_read64)) - (by evm_ov) - -/-- EVM revert path for a mis-sized calldata: the signed length check `SLT(size-4, 64) = 1` - fails the `JUMPI`, falling into the `PUSH0 PUSH0 REVERT` stub @5013. -/ -theorem tlcHasRoleDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 11)) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h5012⟩ := tlcHasRoleReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv hsz hsize hsel - exact h5012.jumpiNT (by native_decide) (by rw [hslt]; decide) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-- EVM revert path for a non-canonical address: the sub-decoder's `EQ` check fails the `JUMPI`, - falling into the `PUSH0 PUSH0 REVERT` stub @4375. -/ -theorem tlcHasRoleNoncanonRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 11)) - (hnc : ¬ (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by decide - obtain ⟨_, _, h4374⟩ := tlcHasRoleReachEqCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv hsz68 hbig hsize hsel - exact h4374.jumpiNT (by native_decide) (by rw [hmask]; exact tlcHasRoleNoncanon_eq hnc) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-! ## Solm body -/ - -theorem tlcHasRoleStore_get_roles (I : ExecutionEnv) : - (tlcHasRoleStore I).get? "_roles" = none := by - unfold tlcHasRoleStore - rw [store_get_ne2 _ _ _ (by native_decide) (by native_decide)] - simp - -theorem tlcHasRoleStore_index_role (I : ExecutionEnv) : - (tlcHasRoleStore I)["role"] = - Value.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32) := by - unfold tlcHasRoleStore - rw [Std.HashMap.getElem_insert]; simp - -/-- The Solm `hasRole(role, account)` body returns `_roles[role].hasRole[account]`. -/ -theorem tlcHasRoleBodyReturns {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcHasRoleStore I) - hasRoleTransition.body - (.returned { contract := contract, locals := tlcHasRoleStore I } (initState cA gh bl σ σ₀ g A I) - (some [Solm.wordToElem .bool (UInt256.land (tlcHasRoleWord σ I) ⟨255⟩)])) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hslot : roleHasRoleSlot (tlcHasRoleRoleKey I) (tlcHasRoleAccountKey I) = tlcHasRoleSlot I := - tlcHasRoleSlot_eq I hsz36 - have hstore : Solm.EVM.storageLoad (initState cA gh bl σ σ₀ g A I) - (initState cA gh bl σ σ₀ g A I).executionEnv.codeOwner (tlcHasRoleSlot I) = tlcHasRoleWord σ I := - codeOwnerStorageWord_initState (tlcHasRoleSlot I) - refine nonpayableReturnExprBodyReturns (by simp only [initState]; exact hwv) ?_ - refine evalExpr_storage_scalar_value (cfg := config) - (solm := { contract := contract, locals := tlcHasRoleStore I }) - (slot := roleHasRoleRef (.var "role") (.var "account")) - (er := ({ base := "_roles", steps := [.mindex (tlcHasRoleRoleKey I), .field "hasRole", - .mindex (tlcHasRoleAccountKey I)] } : EvaledStorageRef)) - (t := .bool) - (loc := boolLoc (roleHasRoleSlot (tlcHasRoleRoleKey I) (tlcHasRoleAccountKey I))) - (value := Solm.wordToElem .bool (UInt256.land (tlcHasRoleWord σ I) ⟨255⟩)) ?_ ?_ ?_ ?_ ?_ - · simp only [roleHasRoleRef]; exact tlcHasRoleStore_get_roles I - · simp [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, roleHasRoleRef, - tlcHasRoleStore_index_role, tlcHasRoleAccountKey, valueToKey?, - hlen, abiBytes32Width, EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?] - · simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, roleDataSt, boolSt] - · rfl - · rw [hslot] - show storageLocLoad (initState cA gh bl σ σ₀ g A I) (boolOffset0Loc (tlcHasRoleSlot I)) = _ - rw [storageLocLoad_bool_offset0, hstore] - -/-! ## Refinement -/ - -/-- Refinement of `HasRole` (selector index 11). -/ -theorem tlcHasRoleBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 11)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 11) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz68 : 68 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · by_cases hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus - · -- execute: canonical account - have hword : tlcHasRoleWord σ_evm I = tlcHasRoleWord σ_solm I := by - simp only [tlcHasRoleWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner (tlcHasRoleSlot I) ⟨0⟩ - have hbody : - ExecTransitionBody config contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) (tlcHasRoleStore I) - hasRoleTransition.body - (.returned { contract := contract, locals := tlcHasRoleStore I } - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (some [Solm.wordToElem .bool (UInt256.land (tlcHasRoleWord σ_solm I) ⟨255⟩)])) := - tlcHasRoleBodyReturns (g := Sat256.ofUInt256 g) hwv (by omega) - exact tlcReEquivExecTransport hcode - (tlcHasRoleX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz68 hbig hsize hsel hcanon) - (tlcSelectorDispatchHasRole hsel) (tlcDecodeHasRole_ok hsz68 hbig hcanon) hbody - (by rw [← hword]) hAccounts - (returnEquiv_of_encode (by - simpa [boolTy] using boolWordReturnEncoding (tlcHasRoleWord σ_evm I))) - · -- non-canonical account: EVM reverts at the address check, Solm decode fails - exact tlcReEquivDecodeFailed hcode - (tlcHasRoleNoncanonRevert (g := Sat256.ofUInt256 g) hcode hwv hsz68 hbig hsize hsel hcanon) - (tlcSelectorDispatchHasRole hsel) (tlcDecodeHasRole_none_noncanon hsz68 hbig hcanon) - · -- huge calldata: EVM reverts at the length check, Solm decode fails - have hhuge : 2 ^ 255 + 4 ≤ I.calldata.size := Nat.not_lt.mp hbig - exact tlcReEquivDecodeFailed hcode - (tlcHasRoleDecodeRevert (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckHuge_4_64 hhuge hsize)) - (tlcSelectorDispatchHasRole hsel) (tlcDecodeHasRole_none_huge hhuge) - · -- short calldata: EVM reverts at the length check, Solm decode fails - have hshort : I.calldata.size < 68 := by omega - exact tlcReEquivDecodeFailed hcode - (tlcHasRoleDecodeRevert (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckShort_4_64 hsz hshort hsize)) - (tlcSelectorDispatchHasRole hsel) (tlcDecodeHasRole_none_short hsz hshort) - · -- nonpayable guard: callvalue ≠ 0 - obtain ⟨_, _, h1101⟩ := tlcReachHasRole (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨1112⟩) h1101 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchHasRole hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/HashOperation.lean b/Benchmarks/OpenZeppelinBench/TimelockController/HashOperation.lean deleted file mode 100644 index b01a9f38..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/HashOperation.lean +++ /dev/null @@ -1,57 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.AbiEncode -import Benchmarks.OpenZeppelinBench.TimelockController.AbiDecode -import Benchmarks.OpenZeppelinBench.TimelockController.Body -import Benchmarks.OpenZeppelinBench.TimelockController.EvmReach -import Benchmarks.OpenZeppelinBench.TimelockController.EvmExec -import Benchmarks.OpenZeppelinBench.TimelockController.EvmReverts - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- KECCAK round-trip: the Solm `bytes32` result bytes equal the big-endian bytes of the EVM word. -/ -theorem tlcHashOp_kec_roundtrip (I : ExecutionEnv) : - tlcHashOpKecList I = EVM.Word.toBytesBE (tlcHashOpKecWord I) := by - show (ffi.KEC (tlcHashOpCanonBytes I)).toList - = EVM.Word.toBytesBE (UInt256.ofNat (fromByteArrayBigEndian (ffi.KEC (tlcHashOpCanonBytes I)))) - rw [← uInt256OfByteArray_eq, toBytesBE_uInt256OfByteArray_of_size (keccak_size _)] - -/-! ## Refinement (target) -/ - -/-- Refinement of `hashOperation` (selector index 13). The EVM decodes - `(address,uint256,bytes,bytes32,bytes32)`, ABI-re-encodes the canonical tuple, and returns its - `keccak256`; the Solm body returns the same `keccak256(abi.encode(...))`. Malformed calldata and - nonzero callvalue both revert on both sides. -/ -theorem tlcHashOperationBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 13)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 13) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hwf : tlcHashOpWF I - · -- well-formed: execute; both sides return `keccak256(canonical abi.encode)` - exact tlcReEquivExecTransport hcode - (tlcHashOperationX_ok (g := Sat256.ofUInt256 g) hcode hwv hsize hsel hwf) - (tlcSelectorDispatchHashOperation hsel) (tlcDecodeHashOperation_ok hwf) - (tlcHashOperationBodyReturns (g := Sat256.ofUInt256 g) hwv hwf) - (by rw [tlcHashOp_kec_roundtrip]) hAccounts - (returnEquiv_of_encode - (by simpa [bytes32] using bytes32ReturnEncoding (tlcHashOpKecWord I))) - · -- malformed calldata: EVM decoder reverts, Solm decode fails - exact tlcHashOperationDecodeFail hcode hwv hsz hsize hsel hwf hAccounts - · -- nonzero callvalue: EVM reverts at the per-function non-payable guard, Solm body reverts - obtain ⟨_, _, h988⟩ := tlcReachHashOperation (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨999⟩) h988 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchHashOperation hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/HashOperationBatch.lean b/Benchmarks/OpenZeppelinBench/TimelockController/HashOperationBatch.lean deleted file mode 100644 index bb243f5a..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/HashOperationBatch.lean +++ /dev/null @@ -1,19 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace OpenZeppelinBench.TimelockController - -/-- Refinement of `HashOperationBatch` (selector index 12). -/ -theorem tlcHashOperationBatchBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 12)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperation.lean b/Benchmarks/OpenZeppelinBench/TimelockController/IsOperation.lean deleted file mode 100644 index 31dd76c8..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperation.lean +++ /dev/null @@ -1,415 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.GetTimestamp -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `isOperation(bytes32)` refinement - -`isOperation` is a public non-payable `bool` getter. The compiled body (pc 820, dispatch group G301 -arm 2) is NOT a plain "load-and-compare": it decodes one `bytes32 id`, then calls the inlined -`_getOperationState` helper @2232 which hashes the `_timestamps` mapping slot `keccak(id ‖ 1)`, -`SLOAD`s the timestamp `t`, and returns the 4-way operation state -(`0=Unset` if `t=0`, `3=Done` if `t=1`, `1=Waiting` if `t>block.timestamp`, `2=Ready` otherwise), -after which the body returns the `bool` `state != Unset`. Since `state = 0 ⟺ t = 0`, this equals the -trusted spec's `_timestamps[id] != 0`. The proof therefore case-splits the EVM execution over the -four `_getOperationState` leaves and shows every leaf's `state != 0` word equals `t != 0`. - -Front half (guard peel, `bytes32` decoder @4702, slot-1 mapping keccak) reuses `GetTimestamp`/`Storage` -infrastructure; the bool return encoder @509 mirrors `SupportsInterface`, generalized over the dirtied -scratch memory (`twoWordHashMem …`) via `Storage.tlcRetMem*`. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- The 32-byte word `isOperation` returns for a stored timestamp `t`: `1` iff `t ≠ 0`. -/ -def tlcIsOperationBoolWord (t : UInt256) : UInt256 := if t = ⟨0⟩ then ⟨0⟩ else ⟨1⟩ - -/-! ## Memory-generic bool-return encoder @509 - - Structurally identical to `SupportsInterface.tlcSuppIfaceReturnBool`, but over any free-pointer - preserving scratch memory (`size = 96`, `mem[0x40] = 0x80`) — a mapping getter dirties `[0,0x40)`, - so the return runs over `twoWordHashMem …`, not `solcFreePtrMem`. Reuses `Storage.tlcRetMem*`. -/ -theorem tlcIsOperationReturnBool {g : Sat256} {s0 : State} {ee : ExecutionEnv} - {k C : ℕ} {R : List UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {val : UInt256} {mem : ByteArray} - (h : RD timelockControllerBenchBytecode ee g s0 ⟨509⟩ (val :: R) mem - (UInt256.ofNat 3) rdata acc k C) - (hsize : mem.size = 96) - (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) - (hnorm : UInt256.isZero (UInt256.isZero val) = val) - (hov : R.length + 8 ≤ 1024) : - RDret timelockControllerBenchBytecode g s0 acc (UInt256.toByteArray val) := by - exact evm_run h with [ - jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) - mem_cost (mloadFreePtrValue (by rw [hsize]; decide) (by decide) hread64) (by decide) (by evm_ov), - swap1, iszero, iszero, dup2, - raw mstore 6 (tlcRetMem mem val) (UInt256.ofNat 5) (by native_decide) - mem_cost (by rw [hnorm]; rfl) (by decide) (by evm_ov), - push1 ⟨32⟩, add, jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 5) (by native_decide) - mem_cost (tlcRetMem_mload64 hsize hread64 val) (by decide) (by evm_ov), - dup1, swap2, sub, swap1, - raw ret 0 (UInt256.toByteArray val) (by native_decide) mem_cost - (by rw [show (UInt256.sub ((⟨32⟩ : UInt256) + ⟨128⟩) ⟨128⟩).toNat = 32 from by decide] - exact tlcRetMem_read128 hsize val) - (by evm_ov) ] - -/-! ## EVM: reach the body and the decoder length check -/ - -/-- Reach the `isOperation` body pc 820 (G301 arm 2). -/ -theorem tlcReachIsOperation {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 17)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨820⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x31d50750⟩ := - solcSelectorWord_eq_of_beq I hsz 0x31 0xd5 0x07 0x50 ⟨0x31d50750⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG301Body 2 (by omega) ⟨820⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j <;> (rw [hsw]; native_decide)) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Peel the non-payable guard, push the return/decode continuations `⟨509⟩`/`⟨846⟩`, and run the - `bytes32` decoder prologue @4702 to the availability `JUMPI` @4714. - Stack: `[⟨4718⟩, ISZERO(SLT(size-4, 32)), ⟨0⟩, ⟨4⟩, size, ⟨846⟩, ⟨509⟩, sel]`. -/ -theorem tlcIsOperationReachLenCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 17)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4714⟩ - [⟨4718⟩, UInt256.isZero (UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩), - ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨846⟩, ⟨509⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h820⟩ := tlcReachIsOperation (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h833⟩ := tlcGuardPeelOk (gt := ⟨831⟩) h820 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, h833.push2 ⟨509⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨846⟩ (by native_decide) (by evm_ov) - |>.calldatasize (by native_decide) (by evm_ov) - |>.push1 ⟨4⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4702⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.slt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨4718⟩ (by native_decide) (by evm_ov)⟩ - -/-- After the length check passes, finish the decoder (`CALLDATALOAD(4)`), jump back to the decode - continuation @846, and enter the compute body @1956 with `[id, ⟨509⟩, sel]`. -/ -theorem tlcIsOperationReachCompute {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 17)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1956⟩ - [calldataWord I.calldata 4, ⟨509⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsz : 4 ≤ I.calldata.size := by omega - obtain ⟨_, _, h4714⟩ := tlcIsOperationReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact ⟨_, _, h4714.jumpiT (by native_decide) - (by rw [solcDecodeLenCheckOk_4_32 hsz36 hbig hsize]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨1956⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov)⟩ - -/-! ## EVM: the `_getOperationState` tail from @1967 to the bool-return encoder @509 - - Common to all four operation-state leaves: from `[state, 0, 0, id, ⟨509⟩, sel]` at @1967, the - enum range check (`state ≤ 3`, always taken) and `state != 0` (`EQ; ISZERO`) reach the encoder - @509 with `[iszero(eq state 0), sel]`. -/ -theorem tlcIsOperationTail {cA gh bl σ σ₀ A I} {g : Sat256} {R key : UInt256} - {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1967⟩ - [R, ⟨0⟩, ⟨0⟩, key, ⟨509⟩, tlcSelWord I] mem aw ByteArray.empty (cA, σ) k C) - (hbound : UInt256.isZero (UInt256.gt R ⟨3⟩) ≠ ⟨0⟩) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨509⟩ - [UInt256.isZero (UInt256.eq R ⟨0⟩), tlcSelWord I] mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, h.jumpdest (by native_decide) (by evm_ov) - |>.push1 ⟨3⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.gt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨1984⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) hbound (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.eq (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov)⟩ - -/-- The compute body: call `_getOperationState` @2232, resolve its four leaves, and reach the bool - encoder @509 with `[isOperation(id) as bool word, sel]`. `t := _timestamps[id]`. -/ -theorem tlcIsOperationCompute {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 17)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨509⟩ - [tlcIsOperationBoolWord (tlcGetTimestampWord σ I), tlcSelWord I] - (twoWordHashMem (calldataWord I.calldata 4) ⟨1⟩ solcFreePtrMem) - (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h1956⟩ := tlcIsOperationReachCompute (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz36 hbig hsize hsel - -- Set up the helper call and run the mapping keccak, up to the loaded slot value. - have hkec := evm_run h1956 with [ - jumpdest, push0, dup1, push2 ⟨1967⟩, dup4, push2 ⟨2232⟩, jump (by jump_dest), - jumpdest, push0, dup2, dup2, - raw mstore 0 (wordAt0Mem (calldataWord I.calldata 4) solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨32⟩, - raw mstore 0 (twoWordHashMem (calldataWord I.calldata 4) ⟨1⟩ solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨64⟩, dup2, - raw keccak256 0 (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) (UInt256.ofNat 3) - (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact tlcTwoWordKeccakSlot ⟨1⟩ (calldataWord I.calldata 4)) - (by native_decide) (by evm_ov) ] - obtain ⟨_, _, hsl⟩ := hkec.sload (by native_decide) (by evm_ov) - -- `hsl` is at @2247 with the loaded timestamp `t = tlcGetTimestampWord σ I` on top. - by_cases ht0 : tlcGetTimestampWord σ I = ⟨0⟩ - · -- Unset: `t = 0` ⇒ state 0. - have hcond : UInt256.sub ⟨0⟩ (tlcGetTimestampWord σ I) = (⟨0⟩ : UInt256) := by - rw [ht0]; exact u256_sub_self ⟨0⟩ - have h1967 := evm_run hsl with [ - dup1, push0, sub, push2 ⟨2261⟩, jumpiNT hcond, - pop, push0, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationTail h1967 (by decide) - have hb : UInt256.isZero (UInt256.eq (⟨0⟩ : UInt256) ⟨0⟩) - = tlcIsOperationBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationBoolWord; rw [if_pos ht0]; decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - · -- `t ≠ 0`: pass the Unset `JUMPI` @2253, reach the Done check @2269. - have hcond0 : UInt256.sub ⟨0⟩ (tlcGetTimestampWord σ I) ≠ (⟨0⟩ : UInt256) := - u256_zero_sub_ne_zero ht0 - have h2269 := evm_run hsl with [ - dup1, push0, sub, push2 ⟨2261⟩, jumpiT hcond0 (by jump_dest), - jumpdest, push1 ⟨1⟩, dup2, sub, push2 ⟨2278⟩ ] - by_cases ht1 : tlcGetTimestampWord σ I = ⟨1⟩ - · -- Done: `t = 1` ⇒ state 3. - have hcond1 : UInt256.sub (tlcGetTimestampWord σ I) ⟨1⟩ = (⟨0⟩ : UInt256) := by - rw [ht1]; exact u256_sub_self ⟨1⟩ - have h1967 := evm_run h2269 with [ - jumpiNT hcond1, - pop, push1 ⟨3⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationTail h1967 (by decide) - have hb : UInt256.isZero (UInt256.eq (⟨3⟩ : UInt256) ⟨0⟩) - = tlcIsOperationBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationBoolWord; rw [if_neg ht0]; decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - · -- `t ≠ 1`: pass the Done `JUMPI` @2269, reach the timestamp check @2286. - have hcond1 : UInt256.sub (tlcGetTimestampWord σ I) ⟨1⟩ ≠ (⟨0⟩ : UInt256) := - u256_sub_ne_zero_of_ne ht1 - have h2286 := evm_run h2269 with [ - jumpiT hcond1 (by jump_dest), - jumpdest, timestamp, dup2, gt, iszero, push2 ⟨2295⟩ ] - by_cases htgt : UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp) = ⟨0⟩ - · -- Ready: `t ≤ block.timestamp` ⇒ state 2. - have hcondr : UInt256.isZero - (UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp)) ≠ (⟨0⟩ : UInt256) := by - rw [htgt]; decide - have h1967 := evm_run h2286 with [ - jumpiT hcondr (by jump_dest), - jumpdest, pop, push1 ⟨2⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationTail h1967 (by decide) - have hb : UInt256.isZero (UInt256.eq (⟨2⟩ : UInt256) ⟨0⟩) - = tlcIsOperationBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationBoolWord; rw [if_neg ht0]; decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - · -- Waiting: `t > block.timestamp` ⇒ state 1. - have hcondw : UInt256.isZero - (UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp)) = (⟨0⟩ : UInt256) := - isZero_eq_zero_of_ne htgt - have h1967 := evm_run h2286 with [ - jumpiNT hcondw, - pop, push1 ⟨1⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationTail h1967 (by decide) - have hb : UInt256.isZero (UInt256.eq (⟨1⟩ : UInt256) ⟨0⟩) - = tlcIsOperationBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationBoolWord; rw [if_neg ht0]; decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - -/-- EVM: with zero callvalue and well-sized calldata, `isOperation(id)` returns the bool word - `_timestamps[id] != 0`. -/ -theorem tlcIsOperationX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 17)) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (tlcIsOperationBoolWord (tlcGetTimestampWord σ I))) := by - obtain ⟨_, _, h509⟩ := tlcIsOperationCompute (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz36 hbig hsize hsel - exact tlcIsOperationReturnBool h509 - (twoWordHashMem_size_96 _ _ solcFreePtrMem_size) - (twoWordHashMem_read64 _ _ solcFreePtrMem_size solcFreePtrMem_read64) - (by unfold tlcIsOperationBoolWord; split <;> decide) (by evm_ov) - -/-- EVM revert path for a mis-sized calldata: the signed length check `SLT(size-4, 32) = 1` fails the - `JUMPI`, falling into the decoder's `PUSH0 PUSH0 REVERT` stub. -/ -theorem tlcIsOperationDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 17)) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4714⟩ := tlcIsOperationReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact h4714.jumpiNT (by native_decide) (by rw [hslt]; decide) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-! ## ABI decode (a single `bytes32`, exactly like `getTimestamp`) -/ - -theorem tlcDecodeIsOperation_ok {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) : - decodeCalldataWithMode config.abiDecodeMode (isOperationTransition.params.map Param.name) - (transitionSignature isOperationTransition).paramTypes I.calldata - = some (tlcGetTimestampStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = _ - exact decodeCalldata_bytes32_ok hsz36 hbig - -theorem tlcDecodeIsOperation_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 36) : - decodeCalldataWithMode config.abiDecodeMode (isOperationTransition.params.map Param.name) - (transitionSignature isOperationTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_short hsz4 hshort - -theorem tlcDecodeIsOperation_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (isOperationTransition.params.map Param.name) - (transitionSignature isOperationTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_huge hbig - -/-! ## Solm body -/ - -/-- The Solm `isOperation(id)` body returns the bool `_timestamps[id] != 0`. -/ -theorem tlcIsOperationBodyReturns {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcGetTimestampStore I) - isOperationTransition.body - (.returned { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) - (some [(.bool (!((Int.ofNat (tlcGetTimestampWord σ I).toNat : Int) == 0)))])) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hvk : valueToKey? (Value.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32)) - = some (tlcGetTimestampKey I) := by - simp [valueToKey?, tlcGetTimestampKey, abiBytes32Width, hlen] - have hslot : timestampSlot (tlcGetTimestampKey I) - = solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4) := by - unfold timestampSlot mapSlot solcMappingSlot - rw [tlcGetTimestampKey_eq I hsz36] - have hstore : evalExpr? config { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) (timestampExpr (.var "id")) - = .ok (.int (Int.ofNat (tlcGetTimestampWord σ I).toNat)) := by - unfold timestampExpr - rw [evalExpr_storage_scalar (cfg := config) - (solm := { contract := contract, locals := tlcGetTimestampStore I }) - (slot := timestampRef (.var "id")) - (er := ({ base := "_timestamps", steps := [.mindex (tlcGetTimestampKey I)] } : EvaledStorageRef)) - (t := .int uint256Int) (loc := uint256Loc (timestampSlot (tlcGetTimestampKey I))) - (hbase := by simp [timestampRef]) - (her := by - simp [evalStorageRef, evalStorageRefStep, timestampRef, tlcGetTimestampStore, - EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?, hvk]) - (hty := by - simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, tlcGetTimestampKey, uint256St]) - (hloc := by rfl)] - rw [hslot] - exact congrArg EvalResult.ok - (storageLocLoad_uint256 (initState cA gh bl σ σ₀ g A I) - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4))) - refine nonpayableReturnExprBodyReturns (by simp only [initState]; exact hwv) ?_ - unfold isOperationExpr - simp only [evalExpr?, hstore, EvalResult.bind, bind, evalBinaryOp?, pure] - simp - -/-- ABI-encoding the `isOperation` result bool `_timestamps[id] != 0` is the EVM's returned word. -/ -theorem tlcIsOperationBoolEncoding (w : UInt256) : - encodeReturnValue? boolTy (.bool (!((Int.ofNat w.toNat : Int) == 0))) - = some (UInt256.toByteArray (tlcIsOperationBoolWord w)) := by - by_cases hz : w = ⟨0⟩ - · subst hz - have hb : (!((Int.ofNat (⟨0⟩ : UInt256).toNat : Int) == 0)) = false := by native_decide - rw [hb]; unfold tlcIsOperationBoolWord; rw [if_pos rfl] - simpa [boolTy] using boolFalseReturnEncoding - · have hne : w.toNat ≠ 0 := by intro hh; exact hz (by apply u256_inj; simpa using hh) - have hb : (!((Int.ofNat w.toNat : Int) == 0)) = true := by simpa using hne - rw [hb]; unfold tlcIsOperationBoolWord; rw [if_neg hz] - simpa [boolTy] using boolTrueReturnEncoding - -/-! ## Refinement -/ - -/-- Refinement of `IsOperation` (selector index 17). -/ -theorem tlcIsOperationBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 17)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 17) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz36 : 36 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · -- execute: `36 ≤ size < 2^255 + 4` - have hword : tlcGetTimestampWord σ_evm I = tlcGetTimestampWord σ_solm I := by - simp only [tlcGetTimestampWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) ⟨0⟩ - exact tlcReEquivExecTransport hcode - (tlcIsOperationX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz36 hbig hsize hsel) - (tlcSelectorDispatchIsOperation hsel) - (tlcDecodeIsOperation_ok hsz36 hbig) - (tlcIsOperationBodyReturns (g := Sat256.ofUInt256 g) hwv hsz36) (by rw [← hword]) hAccounts - (returnEquiv_of_encode (tlcIsOperationBoolEncoding (tlcGetTimestampWord σ_evm I))) - · -- huge calldata: EVM reverts at the signed length check, Solm decode fails - have hhuge : 2 ^ 255 + 4 ≤ I.calldata.size := Nat.not_lt.mp hbig - have hrev := tlcIsOperationDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckHuge_4_32 hhuge hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchIsOperation hsel) - (tlcDecodeIsOperation_none_huge hhuge) - · -- short calldata: EVM reverts at the length check, Solm decode fails - have hshort : I.calldata.size < 36 := by omega - have hrev := tlcIsOperationDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckShort_4_32 hsz hshort hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchIsOperation hsel) - (tlcDecodeIsOperation_none_short hsz hshort) - · -- nonpayable guard: `callvalue ≠ 0` - obtain ⟨_, _, h820⟩ := tlcReachIsOperation (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨831⟩) h820 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchIsOperation hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationDone.lean b/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationDone.lean deleted file mode 100644 index 234ea23e..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationDone.lean +++ /dev/null @@ -1,383 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.IsOperation -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `isOperationDone(bytes32)` refinement - -Near-copy of `isOperation`. Both decode one `bytes32 id`, call the SAME inlined `_getOperationState` -helper @2232 which hashes `keccak(id ‖ 1)`, `SLOAD`s the timestamp `t`, and returns the 4-way -operation state (`0=Unset` if `t=0`, `3=Done` if `t=1`, `1=Waiting` if `t>block.timestamp`, -`2=Ready` else). `isOperationDone` returns the `bool` `state == 3`, i.e. `_timestamps[id] == 1`. - -Differs from `isOperation` (imported, reused read-only) only in: (a) body pc 758 (G301 arm 0); -(b) the post-helper tail @1882 does `EQ` against the enum constant `3` (no `ISZERO`), yielding -`state == 3`; (c) the bool word `if t = 1 then 1 else 0`. The front half (guard peel, decoder, -mapping keccak) and the memory-generic bool-return encoder @509 (`tlcIsOperationReturnBool`) are -imported unchanged. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- The 32-byte word `isOperationDone` returns for a stored timestamp `t`: `1` iff `t = 1` (Done). -/ -def tlcIsOperationDoneBoolWord (t : UInt256) : UInt256 := if t = ⟨1⟩ then ⟨1⟩ else ⟨0⟩ - -/-! ## EVM: reach the body and the decoder length check -/ - -/-- Reach the `isOperationDone` body pc 758 (G301 arm 0). -/ -theorem tlcReachIsOperationDone {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 14)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨758⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x2ab0f529⟩ := - solcSelectorWord_eq_of_beq I hsz 0x2a 0xb0 0xf5 0x29 ⟨0x2ab0f529⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG301Body 0 (by omega) ⟨758⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; omega) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Peel the non-payable guard, push the return/decode continuations `⟨509⟩`/`⟨784⟩`, and run the - `bytes32` decoder prologue @4702 to the availability `JUMPI` @4714. -/ -theorem tlcIsOperationDoneReachLenCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 14)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4714⟩ - [⟨4718⟩, UInt256.isZero (UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩), - ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨784⟩, ⟨509⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h758⟩ := tlcReachIsOperationDone (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h771⟩ := tlcGuardPeelOk (gt := ⟨769⟩) h758 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, h771.push2 ⟨509⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨784⟩ (by native_decide) (by evm_ov) - |>.calldatasize (by native_decide) (by evm_ov) - |>.push1 ⟨4⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4702⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.slt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨4718⟩ (by native_decide) (by evm_ov)⟩ - -/-- After the length check passes, finish the decoder (`CALLDATALOAD(4)`), jump back to the decode - continuation @784, and enter the compute body @1906 with `[id, ⟨509⟩, sel]`. -/ -theorem tlcIsOperationDoneReachCompute {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 14)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1906⟩ - [calldataWord I.calldata 4, ⟨509⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsz : 4 ≤ I.calldata.size := by omega - obtain ⟨_, _, h4714⟩ := tlcIsOperationDoneReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact ⟨_, _, h4714.jumpiT (by native_decide) - (by rw [solcDecodeLenCheckOk_4_32 hsz36 hbig hsize]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨1906⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov)⟩ - -/-! ## EVM: the `_getOperationState` tail from @1882 to the bool-return encoder @509 - - From `[state, 3, 0, id, ⟨509⟩, sel]` at @1882, the enum range check (`state ≤ 3`, always taken) - and `state == 3` (`EQ`, no `ISZERO`) reach the encoder @509 with `[eq state 3, sel]`. -/ -theorem tlcIsOperationDoneTail {cA gh bl σ σ₀ A I} {g : Sat256} {R key : UInt256} - {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1882⟩ - [R, ⟨3⟩, ⟨0⟩, key, ⟨509⟩, tlcSelWord I] mem aw ByteArray.empty (cA, σ) k C) - (hbound : UInt256.isZero (UInt256.gt R ⟨3⟩) ≠ ⟨0⟩) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨509⟩ - [UInt256.eq R ⟨3⟩, tlcSelWord I] mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, h.jumpdest (by native_decide) (by evm_ov) - |>.push1 ⟨3⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.gt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨1899⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) hbound (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.eq (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov)⟩ - -/-- The compute body: run @1906/@1873 into `_getOperationState` @2232, resolve its four leaves, and - reach the bool encoder @509 with `[isOperationDone(id) as bool word, sel]`. `t := _timestamps[id]`. -/ -theorem tlcIsOperationDoneCompute {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 14)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨509⟩ - [tlcIsOperationDoneBoolWord (tlcGetTimestampWord σ I), tlcSelWord I] - (twoWordHashMem (calldataWord I.calldata 4) ⟨1⟩ solcFreePtrMem) - (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h1906⟩ := tlcIsOperationDoneReachCompute (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz36 hbig hsize hsel - -- Run @1906/@1873 into the helper call and the mapping keccak, up to the loaded slot value. - have hkec := evm_run h1906 with [ - jumpdest, push0, push1 ⟨3⟩, push2 ⟨1873⟩, jump (by jump_dest), - jumpdest, push2 ⟨1882⟩, dup4, push2 ⟨2232⟩, jump (by jump_dest), - jumpdest, push0, dup2, dup2, - raw mstore 0 (wordAt0Mem (calldataWord I.calldata 4) solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨32⟩, - raw mstore 0 (twoWordHashMem (calldataWord I.calldata 4) ⟨1⟩ solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨64⟩, dup2, - raw keccak256 0 (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) (UInt256.ofNat 3) - (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact tlcTwoWordKeccakSlot ⟨1⟩ (calldataWord I.calldata 4)) - (by native_decide) (by evm_ov) ] - obtain ⟨_, _, hsl⟩ := hkec.sload (by native_decide) (by evm_ov) - -- `hsl` is at @2247 with the loaded timestamp `t = tlcGetTimestampWord σ I` on top. - by_cases ht0 : tlcGetTimestampWord σ I = ⟨0⟩ - · -- Unset: `t = 0` ⇒ state 0. - have hcond : UInt256.sub ⟨0⟩ (tlcGetTimestampWord σ I) = (⟨0⟩ : UInt256) := by - rw [ht0]; exact u256_sub_self ⟨0⟩ - have ht1' : tlcGetTimestampWord σ I ≠ ⟨1⟩ := by rw [ht0]; decide - have h1882 := evm_run hsl with [ - dup1, push0, sub, push2 ⟨2261⟩, jumpiNT hcond, - pop, push0, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationDoneTail h1882 (by decide) - have hb : UInt256.eq (⟨0⟩ : UInt256) ⟨3⟩ - = tlcIsOperationDoneBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationDoneBoolWord; rw [if_neg ht1']; decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - · -- `t ≠ 0`: pass the Unset `JUMPI` @2253, reach the Done check @2269. - have hcond0 : UInt256.sub ⟨0⟩ (tlcGetTimestampWord σ I) ≠ (⟨0⟩ : UInt256) := - u256_zero_sub_ne_zero ht0 - have h2269 := evm_run hsl with [ - dup1, push0, sub, push2 ⟨2261⟩, jumpiT hcond0 (by jump_dest), - jumpdest, push1 ⟨1⟩, dup2, sub, push2 ⟨2278⟩ ] - by_cases ht1 : tlcGetTimestampWord σ I = ⟨1⟩ - · -- Done: `t = 1` ⇒ state 3. - have hcond1 : UInt256.sub (tlcGetTimestampWord σ I) ⟨1⟩ = (⟨0⟩ : UInt256) := by - rw [ht1]; exact u256_sub_self ⟨1⟩ - have h1882 := evm_run h2269 with [ - jumpiNT hcond1, - pop, push1 ⟨3⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationDoneTail h1882 (by decide) - have hb : UInt256.eq (⟨3⟩ : UInt256) ⟨3⟩ - = tlcIsOperationDoneBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationDoneBoolWord; rw [if_pos ht1]; decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - · -- `t ≠ 1`: pass the Done `JUMPI` @2269, reach the timestamp check @2286. - have hcond1 : UInt256.sub (tlcGetTimestampWord σ I) ⟨1⟩ ≠ (⟨0⟩ : UInt256) := - u256_sub_ne_zero_of_ne ht1 - have h2286 := evm_run h2269 with [ - jumpiT hcond1 (by jump_dest), - jumpdest, timestamp, dup2, gt, iszero, push2 ⟨2295⟩ ] - by_cases htgt : UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp) = ⟨0⟩ - · -- Ready: `t ≤ block.timestamp` ⇒ state 2. - have hcondr : UInt256.isZero - (UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp)) ≠ (⟨0⟩ : UInt256) := by - rw [htgt]; decide - have h1882 := evm_run h2286 with [ - jumpiT hcondr (by jump_dest), - jumpdest, pop, push1 ⟨2⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationDoneTail h1882 (by decide) - have hb : UInt256.eq (⟨2⟩ : UInt256) ⟨3⟩ - = tlcIsOperationDoneBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationDoneBoolWord; rw [if_neg ht1]; decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - · -- Waiting: `t > block.timestamp` ⇒ state 1. - have hcondw : UInt256.isZero - (UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp)) = (⟨0⟩ : UInt256) := - isZero_eq_zero_of_ne htgt - have h1882 := evm_run h2286 with [ - jumpiNT hcondw, - pop, push1 ⟨1⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationDoneTail h1882 (by decide) - have hb : UInt256.eq (⟨1⟩ : UInt256) ⟨3⟩ - = tlcIsOperationDoneBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationDoneBoolWord; rw [if_neg ht1]; decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - -/-- EVM: with zero callvalue and well-sized calldata, `isOperationDone(id)` returns the bool word - `_timestamps[id] == 1`. -/ -theorem tlcIsOperationDoneX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 14)) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (tlcIsOperationDoneBoolWord (tlcGetTimestampWord σ I))) := by - obtain ⟨_, _, h509⟩ := tlcIsOperationDoneCompute (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz36 hbig hsize hsel - exact tlcIsOperationReturnBool h509 - (twoWordHashMem_size_96 _ _ solcFreePtrMem_size) - (twoWordHashMem_read64 _ _ solcFreePtrMem_size solcFreePtrMem_read64) - (by unfold tlcIsOperationDoneBoolWord; split <;> decide) (by evm_ov) - -/-- EVM revert path for a mis-sized calldata: the signed length check fails the `JUMPI`, falling into - the decoder's `PUSH0 PUSH0 REVERT` stub. -/ -theorem tlcIsOperationDoneDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 14)) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4714⟩ := tlcIsOperationDoneReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact h4714.jumpiNT (by native_decide) (by rw [hslt]; decide) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-! ## ABI decode (a single `bytes32`, exactly like `getTimestamp`/`isOperation`) -/ - -theorem tlcDecodeIsOperationDone_ok {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) : - decodeCalldataWithMode config.abiDecodeMode (isOperationDoneTransition.params.map Param.name) - (transitionSignature isOperationDoneTransition).paramTypes I.calldata - = some (tlcGetTimestampStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = _ - exact decodeCalldata_bytes32_ok hsz36 hbig - -theorem tlcDecodeIsOperationDone_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 36) : - decodeCalldataWithMode config.abiDecodeMode (isOperationDoneTransition.params.map Param.name) - (transitionSignature isOperationDoneTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_short hsz4 hshort - -theorem tlcDecodeIsOperationDone_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (isOperationDoneTransition.params.map Param.name) - (transitionSignature isOperationDoneTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_huge hbig - -/-! ## Solm body -/ - -/-- The Solm `isOperationDone(id)` body returns the bool `_timestamps[id] == 1`. -/ -theorem tlcIsOperationDoneBodyReturns {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcGetTimestampStore I) - isOperationDoneTransition.body - (.returned { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) - (some [(.bool ((Int.ofNat (tlcGetTimestampWord σ I).toNat : Int) == 1))])) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hvk : valueToKey? (Value.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32)) - = some (tlcGetTimestampKey I) := by - simp [valueToKey?, tlcGetTimestampKey, abiBytes32Width, hlen] - have hslot : timestampSlot (tlcGetTimestampKey I) - = solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4) := by - unfold timestampSlot mapSlot solcMappingSlot - rw [tlcGetTimestampKey_eq I hsz36] - have hstore : evalExpr? config { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) (timestampExpr (.var "id")) - = .ok (.int (Int.ofNat (tlcGetTimestampWord σ I).toNat)) := by - unfold timestampExpr - rw [evalExpr_storage_scalar (cfg := config) - (solm := { contract := contract, locals := tlcGetTimestampStore I }) - (slot := timestampRef (.var "id")) - (er := ({ base := "_timestamps", steps := [.mindex (tlcGetTimestampKey I)] } : EvaledStorageRef)) - (t := .int uint256Int) (loc := uint256Loc (timestampSlot (tlcGetTimestampKey I))) - (hbase := by simp [timestampRef]) - (her := by - simp [evalStorageRef, evalStorageRefStep, timestampRef, tlcGetTimestampStore, - EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?, hvk]) - (hty := by - simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, tlcGetTimestampKey, uint256St]) - (hloc := by rfl)] - rw [hslot] - exact congrArg EvalResult.ok - (storageLocLoad_uint256 (initState cA gh bl σ σ₀ g A I) - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4))) - refine nonpayableReturnExprBodyReturns (by simp only [initState]; exact hwv) ?_ - unfold isOperationDoneExpr doneTimestamp - simp only [evalExpr?, hstore, EvalResult.bind, bind, evalBinaryOp?, pure] - simp - -/-- ABI-encoding the `isOperationDone` result bool `_timestamps[id] == 1` is the EVM's returned word. -/ -theorem tlcIsOperationDoneBoolEncoding (w : UInt256) : - encodeReturnValue? boolTy (.bool ((Int.ofNat w.toNat : Int) == 1)) - = some (UInt256.toByteArray (tlcIsOperationDoneBoolWord w)) := by - by_cases hz : w = ⟨1⟩ - · subst hz - have hb : ((Int.ofNat (⟨1⟩ : UInt256).toNat : Int) == 1) = true := by native_decide - rw [hb]; unfold tlcIsOperationDoneBoolWord; rw [if_pos rfl] - simpa [boolTy] using boolTrueReturnEncoding - · have hne : w.toNat ≠ 1 := by intro hh; exact hz (by apply u256_inj; simpa using hh) - have hb : ((Int.ofNat w.toNat : Int) == 1) = false := by - rw [beq_eq_false_iff_ne]; intro hh; exact hne (by simpa using hh) - rw [hb]; unfold tlcIsOperationDoneBoolWord; rw [if_neg hz] - simpa [boolTy] using boolFalseReturnEncoding - -/-! ## Refinement -/ - -/-- Refinement of `IsOperationDone` (selector index 14). -/ -theorem tlcIsOperationDoneBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 14)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 14) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz36 : 36 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · -- execute: `36 ≤ size < 2^255 + 4` - have hword : tlcGetTimestampWord σ_evm I = tlcGetTimestampWord σ_solm I := by - simp only [tlcGetTimestampWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) ⟨0⟩ - exact tlcReEquivExecTransport hcode - (tlcIsOperationDoneX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz36 hbig hsize hsel) - (tlcSelectorDispatchIsOperationDone hsel) - (tlcDecodeIsOperationDone_ok hsz36 hbig) - (tlcIsOperationDoneBodyReturns (g := Sat256.ofUInt256 g) hwv hsz36) (by rw [← hword]) - hAccounts - (returnEquiv_of_encode (tlcIsOperationDoneBoolEncoding (tlcGetTimestampWord σ_evm I))) - · -- huge calldata: EVM reverts at the signed length check, Solm decode fails - have hhuge : 2 ^ 255 + 4 ≤ I.calldata.size := Nat.not_lt.mp hbig - have hrev := tlcIsOperationDoneDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckHuge_4_32 hhuge hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchIsOperationDone hsel) - (tlcDecodeIsOperationDone_none_huge hhuge) - · -- short calldata: EVM reverts at the length check, Solm decode fails - have hshort : I.calldata.size < 36 := by omega - have hrev := tlcIsOperationDoneDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckShort_4_32 hsz hshort hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchIsOperationDone hsel) - (tlcDecodeIsOperationDone_none_short hsz hshort) - · -- nonpayable guard: `callvalue ≠ 0` - obtain ⟨_, _, h758⟩ := tlcReachIsOperationDone (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨769⟩) h758 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchIsOperationDone hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationPending.lean b/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationPending.lean deleted file mode 100644 index fe25431e..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationPending.lean +++ /dev/null @@ -1,452 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.IsOperation -import Benchmarks.OpenZeppelinBench.TimelockController.IsOperationDone -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `isOperationPending(bytes32)` refinement - -Near-copy of `isOperationDone`. Both decode one `bytes32 id`, call the SAME inlined -`_getOperationState` helper @2232 (the 4-way state: `0=Unset` if `t=0`, `3=Done` if `t=1`, -`1=Waiting` if `t>block.timestamp`, `2=Ready` else), then compare the state. `isOperationPending` -returns the `bool` `_timestamps[id] > 1`, i.e. `state ∈ {Waiting=1, Ready=2}`. - -Differs from `isOperationDone` (imported, reused read-only) in: (a) body pc 882 (G254 arm 1); -(b) the post-helper tail @2059 does the range test `state == 1 ∨ state == 2` (a `DUP1;…;JUMPI` -short-circuit) rather than a single `state == 3` `EQ`; (c) the bool word `if 1 < t then 1 else 0`. -The front half (guard peel, decoder, mapping keccak), the four helper leaves, and the memory-generic -bool-return encoder @509 (`tlcIsOperationReturnBool`) are imported unchanged. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- The 32-byte word `isOperationPending` returns for a stored timestamp `t`: `1` iff `1 < t` - (i.e. the operation state is `Waiting` or `Ready`). -/ -def tlcIsOperationPendingBoolWord (t : UInt256) : UInt256 := if 1 < t.toNat then ⟨1⟩ else ⟨0⟩ - -/-- The 32-byte word the tail @2059 leaves for a helper state `R`: `state == 1 ∨ state == 2`, encoded - by the `DUP1;…;JUMPI` short-circuit as `if R = 1 then (R == 1) else (R == 2)`. -/ -def tlcIsOperationPendingBoolOf (R : UInt256) : UInt256 := - if R = ⟨1⟩ then UInt256.eq R ⟨1⟩ else UInt256.eq R ⟨2⟩ - -/-! ## EVM: reach the body and the decoder length check -/ - -/-- Reach the `isOperationPending` body pc 882 (G254 arm 1). -/ -theorem tlcReachIsOperationPending {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 15)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨882⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x584b153e⟩ := - solcSelectorWord_eq_of_beq I hsz 0x58 0x4b 0x15 0x3e ⟨0x584b153e⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG254Body 1 (by omega) ⟨882⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j; rw [hsw]; native_decide) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Peel the non-payable guard, push the return/decode continuations `⟨509⟩`/`⟨908⟩`, and run the - `bytes32` decoder prologue @4702 to the availability `JUMPI` @4714. -/ -theorem tlcIsOperationPendingReachLenCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 15)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4714⟩ - [⟨4718⟩, UInt256.isZero (UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩), - ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨908⟩, ⟨509⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h882⟩ := tlcReachIsOperationPending (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h895⟩ := tlcGuardPeelOk (gt := ⟨893⟩) h882 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, h895.push2 ⟨509⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨908⟩ (by native_decide) (by evm_ov) - |>.calldatasize (by native_decide) (by evm_ov) - |>.push1 ⟨4⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4702⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.slt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨4718⟩ (by native_decide) (by evm_ov)⟩ - -/-- After the length check passes, finish the decoder, jump back to the decode continuation @908, - and enter the compute body @2048 with `[id, ⟨509⟩, sel]`. -/ -theorem tlcIsOperationPendingReachCompute {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 15)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2048⟩ - [calldataWord I.calldata 4, ⟨509⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsz : 4 ≤ I.calldata.size := by omega - obtain ⟨_, _, h4714⟩ := tlcIsOperationPendingReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact ⟨_, _, h4714.jumpiT (by native_decide) - (by rw [solcDecodeLenCheckOk_4_32 hsz36 hbig hsize]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨2048⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov)⟩ - -/-! ## EVM: the `isOperationPending` tail from @2059 to the bool-return encoder @509 - - From `[state, 0, 0, id, ⟨509⟩, sel]` at @2059, the enum range check (`state ≤ 3`, always taken) - computes `state == 1 ∨ state == 2` via a `DUP1;…;JUMPI` short-circuit, reaching @509 with - `[tlcIsOperationPendingBoolOf state, sel]`. -/ -theorem tlcIsOperationPendingTail {cA gh bl σ σ₀ A I} {g : Sat256} {R key : UInt256} - {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2059⟩ - [R, ⟨0⟩, ⟨0⟩, key, ⟨509⟩, tlcSelWord I] mem aw ByteArray.empty (cA, σ) k C) - (hbound : UInt256.isZero (UInt256.gt R ⟨3⟩) ≠ ⟨0⟩) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨509⟩ - [tlcIsOperationPendingBoolOf R, tlcSelWord I] mem aw ByteArray.empty (cA, σ) k' C' := by - by_cases heq1 : R = ⟨1⟩ - · -- state == 1: the `DUP1;…;JUMPI` short-circuits at @2110, answer `R == 1`. - have hc1 : UInt256.eq R ⟨1⟩ ≠ ⟨0⟩ := by rw [heq1]; decide - have h509 := h.jumpdest (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.push1 ⟨3⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.gt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨2081⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) hbound (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.eq (by native_decide) (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.push2 ⟨2110⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) hc1 (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap4 (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - rw [show UInt256.eq R ⟨1⟩ = tlcIsOperationPendingBoolOf R from by - unfold tlcIsOperationPendingBoolOf; rw [if_pos heq1]] at h509 - exact ⟨_, _, h509⟩ - · -- state ≠ 1: fall through, second range check, answer `R == 2`. - have hc0 : UInt256.eq R ⟨1⟩ = ⟨0⟩ := by - show UInt256.fromBool (decide (R = ⟨1⟩)) = ⟨0⟩ - rw [decide_eq_false heq1]; rfl - have h509 := h.jumpdest (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.push1 ⟨3⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.gt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨2081⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) hbound (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.eq (by native_decide) (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.push2 ⟨2110⟩ (by native_decide) (by evm_ov) - |>.jumpiNT (by native_decide) hc0 (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.push1 ⟨2⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.push1 ⟨3⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.gt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨2108⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) hbound (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.eq (by native_decide) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap4 (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - rw [show UInt256.eq R ⟨2⟩ = tlcIsOperationPendingBoolOf R from by - unfold tlcIsOperationPendingBoolOf; rw [if_neg heq1]] at h509 - exact ⟨_, _, h509⟩ - -/-- The compute body: call `_getOperationState` @2232, resolve its four leaves, and reach the bool - encoder @509 with `[isOperationPending(id) as bool word, sel]`. `t := _timestamps[id]`. -/ -theorem tlcIsOperationPendingCompute {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 15)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨509⟩ - [tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ I), tlcSelWord I] - (twoWordHashMem (calldataWord I.calldata 4) ⟨1⟩ solcFreePtrMem) - (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h2048⟩ := tlcIsOperationPendingReachCompute (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz36 hbig hsize hsel - -- Set up the helper call and run the mapping keccak, up to the loaded slot value. - have hkec := evm_run h2048 with [ - jumpdest, push0, push0, push2 ⟨2059⟩, dup4, push2 ⟨2232⟩, jump (by jump_dest), - jumpdest, push0, dup2, dup2, - raw mstore 0 (wordAt0Mem (calldataWord I.calldata 4) solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨32⟩, - raw mstore 0 (twoWordHashMem (calldataWord I.calldata 4) ⟨1⟩ solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨64⟩, dup2, - raw keccak256 0 (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) (UInt256.ofNat 3) - (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact tlcTwoWordKeccakSlot ⟨1⟩ (calldataWord I.calldata 4)) - (by native_decide) (by evm_ov) ] - obtain ⟨_, _, hsl⟩ := hkec.sload (by native_decide) (by evm_ov) - -- `hsl` is at @2247 with the loaded timestamp `t = tlcGetTimestampWord σ I` on top. - by_cases ht0 : tlcGetTimestampWord σ I = ⟨0⟩ - · -- Unset: `t = 0` ⇒ state 0. - have hcond : UInt256.sub ⟨0⟩ (tlcGetTimestampWord σ I) = (⟨0⟩ : UInt256) := by - rw [ht0]; exact u256_sub_self ⟨0⟩ - have h2059 := evm_run hsl with [ - dup1, push0, sub, push2 ⟨2261⟩, jumpiNT hcond, - pop, push0, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationPendingTail h2059 (by decide) - have hb : tlcIsOperationPendingBoolOf (⟨0⟩ : UInt256) - = tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationPendingBoolWord - rw [if_neg (show ¬ 1 < (tlcGetTimestampWord σ I).toNat by rw [ht0]; decide)] - decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - · -- `t ≠ 0`: pass the Unset `JUMPI` @2253, reach the Done check @2269. - have hne0 : (tlcGetTimestampWord σ I).toNat ≠ 0 := - fun hh => ht0 (by apply u256_inj; simpa using hh) - have hcond0 : UInt256.sub ⟨0⟩ (tlcGetTimestampWord σ I) ≠ (⟨0⟩ : UInt256) := - u256_zero_sub_ne_zero ht0 - have h2269 := evm_run hsl with [ - dup1, push0, sub, push2 ⟨2261⟩, jumpiT hcond0 (by jump_dest), - jumpdest, push1 ⟨1⟩, dup2, sub, push2 ⟨2278⟩ ] - by_cases ht1 : tlcGetTimestampWord σ I = ⟨1⟩ - · -- Done: `t = 1` ⇒ state 3. - have hcond1 : UInt256.sub (tlcGetTimestampWord σ I) ⟨1⟩ = (⟨0⟩ : UInt256) := by - rw [ht1]; exact u256_sub_self ⟨1⟩ - have h2059 := evm_run h2269 with [ - jumpiNT hcond1, - pop, push1 ⟨3⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationPendingTail h2059 (by decide) - have hb : tlcIsOperationPendingBoolOf (⟨3⟩ : UInt256) - = tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationPendingBoolWord - rw [if_neg (show ¬ 1 < (tlcGetTimestampWord σ I).toNat by rw [ht1]; decide)] - decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - · -- `t ≠ 1`: pass the Done `JUMPI` @2269, reach the timestamp check @2286. - have hne1 : (tlcGetTimestampWord σ I).toNat ≠ 1 := - fun hh => ht1 (by apply u256_inj; simpa using hh) - have h2gt : 1 < (tlcGetTimestampWord σ I).toNat := by omega - have hcond1 : UInt256.sub (tlcGetTimestampWord σ I) ⟨1⟩ ≠ (⟨0⟩ : UInt256) := - u256_sub_ne_zero_of_ne ht1 - have h2286 := evm_run h2269 with [ - jumpiT hcond1 (by jump_dest), - jumpdest, timestamp, dup2, gt, iszero, push2 ⟨2295⟩ ] - by_cases htgt : UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp) = ⟨0⟩ - · -- Ready: `t ≤ block.timestamp` ⇒ state 2. - have hcondr : UInt256.isZero - (UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp)) ≠ (⟨0⟩ : UInt256) := by - rw [htgt]; decide - have h2059 := evm_run h2286 with [ - jumpiT hcondr (by jump_dest), - jumpdest, pop, push1 ⟨2⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationPendingTail h2059 (by decide) - have hb : tlcIsOperationPendingBoolOf (⟨2⟩ : UInt256) - = tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationPendingBoolWord; rw [if_pos h2gt]; decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - · -- Waiting: `t > block.timestamp` ⇒ state 1. - have hcondw : UInt256.isZero - (UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp)) = (⟨0⟩ : UInt256) := - isZero_eq_zero_of_ne htgt - have h2059 := evm_run h2286 with [ - jumpiNT hcondw, - pop, push1 ⟨1⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationPendingTail h2059 (by decide) - have hb : tlcIsOperationPendingBoolOf (⟨1⟩ : UInt256) - = tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ I) := by - unfold tlcIsOperationPendingBoolWord; rw [if_pos h2gt]; decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - -/-- EVM: with zero callvalue and well-sized calldata, `isOperationPending(id)` returns the bool word - `_timestamps[id] > 1`. -/ -theorem tlcIsOperationPendingX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 15)) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (tlcIsOperationPendingBoolWord (tlcGetTimestampWord σ I))) := by - obtain ⟨_, _, h509⟩ := tlcIsOperationPendingCompute (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz36 hbig hsize hsel - exact tlcIsOperationReturnBool h509 - (twoWordHashMem_size_96 _ _ solcFreePtrMem_size) - (twoWordHashMem_read64 _ _ solcFreePtrMem_size solcFreePtrMem_read64) - (by unfold tlcIsOperationPendingBoolWord; split <;> decide) (by evm_ov) - -/-- EVM revert path for a mis-sized calldata: the signed length check fails the `JUMPI`, falling into - the decoder's `PUSH0 PUSH0 REVERT` stub. -/ -theorem tlcIsOperationPendingDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 15)) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4714⟩ := tlcIsOperationPendingReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact h4714.jumpiNT (by native_decide) (by rw [hslt]; decide) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-! ## ABI decode (a single `bytes32`, exactly like `isOperationDone`) -/ - -theorem tlcDecodeIsOperationPending_ok {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) : - decodeCalldataWithMode config.abiDecodeMode (isOperationPendingTransition.params.map Param.name) - (transitionSignature isOperationPendingTransition).paramTypes I.calldata - = some (tlcGetTimestampStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = _ - exact decodeCalldata_bytes32_ok hsz36 hbig - -theorem tlcDecodeIsOperationPending_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 36) : - decodeCalldataWithMode config.abiDecodeMode (isOperationPendingTransition.params.map Param.name) - (transitionSignature isOperationPendingTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_short hsz4 hshort - -theorem tlcDecodeIsOperationPending_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (isOperationPendingTransition.params.map Param.name) - (transitionSignature isOperationPendingTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_huge hbig - -/-! ## Solm body -/ - -/-- The Solm `isOperationPending(id)` body returns the bool `_timestamps[id] > 1`. -/ -theorem tlcIsOperationPendingBodyReturns {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcGetTimestampStore I) - isOperationPendingTransition.body - (.returned { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) - (some [(.bool ((Int.ofNat (tlcGetTimestampWord σ I).toNat : Int) > 1))])) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hvk : valueToKey? (Value.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32)) - = some (tlcGetTimestampKey I) := by - simp [valueToKey?, tlcGetTimestampKey, abiBytes32Width, hlen] - have hslot : timestampSlot (tlcGetTimestampKey I) - = solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4) := by - unfold timestampSlot mapSlot solcMappingSlot - rw [tlcGetTimestampKey_eq I hsz36] - have hstore : evalExpr? config { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) (timestampExpr (.var "id")) - = .ok (.int (Int.ofNat (tlcGetTimestampWord σ I).toNat)) := by - unfold timestampExpr - rw [evalExpr_storage_scalar (cfg := config) - (solm := { contract := contract, locals := tlcGetTimestampStore I }) - (slot := timestampRef (.var "id")) - (er := ({ base := "_timestamps", steps := [.mindex (tlcGetTimestampKey I)] } : EvaledStorageRef)) - (t := .int uint256Int) (loc := uint256Loc (timestampSlot (tlcGetTimestampKey I))) - (hbase := by simp [timestampRef]) - (her := by - simp [evalStorageRef, evalStorageRefStep, timestampRef, tlcGetTimestampStore, - EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?, hvk]) - (hty := by - simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, tlcGetTimestampKey, uint256St]) - (hloc := by rfl)] - rw [hslot] - exact congrArg EvalResult.ok - (storageLocLoad_uint256 (initState cA gh bl σ σ₀ g A I) - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4))) - refine nonpayableReturnExprBodyReturns (by simp only [initState]; exact hwv) ?_ - unfold isOperationPendingExpr doneTimestamp - simp only [evalExpr?, hstore, EvalResult.bind, bind, evalBinaryOp?, pure] - -/-- ABI-encoding the `isOperationPending` result bool `_timestamps[id] > 1` is the EVM's returned word. -/ -theorem tlcIsOperationPendingBoolEncoding (w : UInt256) : - encodeReturnValue? boolTy (.bool ((Int.ofNat w.toNat : Int) > 1)) - = some (UInt256.toByteArray (tlcIsOperationPendingBoolWord w)) := by - by_cases hlt : 1 < w.toNat - · have hd : decide ((Int.ofNat w.toNat : Int) > 1) = true := - decide_eq_true_eq.mpr (Int.ofNat_lt.mpr hlt) - simp only [hd]; unfold tlcIsOperationPendingBoolWord; rw [if_pos hlt] - simpa [boolTy] using boolTrueReturnEncoding - · have hd : decide ((Int.ofNat w.toNat : Int) > 1) = false := - decide_eq_false (fun hp => hlt (Int.ofNat_lt.mp hp)) - simp only [hd]; unfold tlcIsOperationPendingBoolWord; rw [if_neg hlt] - simpa [boolTy] using boolFalseReturnEncoding - -/-! ## Refinement -/ - -/-- Refinement of `IsOperationPending` (selector index 15). -/ -theorem tlcIsOperationPendingBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 15)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 15) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz36 : 36 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · -- execute: `36 ≤ size < 2^255 + 4` - have hword : tlcGetTimestampWord σ_evm I = tlcGetTimestampWord σ_solm I := by - simp only [tlcGetTimestampWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) ⟨0⟩ - exact tlcReEquivExecTransport hcode - (tlcIsOperationPendingX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz36 hbig hsize hsel) - (tlcSelectorDispatchIsOperationPending hsel) - (tlcDecodeIsOperationPending_ok hsz36 hbig) - (tlcIsOperationPendingBodyReturns (g := Sat256.ofUInt256 g) hwv hsz36) (by rw [← hword]) - hAccounts - (returnEquiv_of_encode (tlcIsOperationPendingBoolEncoding (tlcGetTimestampWord σ_evm I))) - · -- huge calldata: EVM reverts at the signed length check, Solm decode fails - have hhuge : 2 ^ 255 + 4 ≤ I.calldata.size := Nat.not_lt.mp hbig - have hrev := tlcIsOperationPendingDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckHuge_4_32 hhuge hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchIsOperationPending hsel) - (tlcDecodeIsOperationPending_none_huge hhuge) - · -- short calldata: EVM reverts at the length check, Solm decode fails - have hshort : I.calldata.size < 36 := by omega - have hrev := tlcIsOperationPendingDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckShort_4_32 hsz hshort hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchIsOperationPending hsel) - (tlcDecodeIsOperationPending_none_short hsz hshort) - · -- nonpayable guard: `callvalue ≠ 0` - obtain ⟨_, _, h882⟩ := tlcReachIsOperationPending (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨893⟩) h882 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchIsOperationPending hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationReady.lean b/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationReady.lean deleted file mode 100644 index 88531257..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/IsOperationReady.lean +++ /dev/null @@ -1,430 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.IsOperation -import Benchmarks.OpenZeppelinBench.TimelockController.IsOperationDone -import Benchmarks.OpenZeppelinBench.TimelockController.GetOperationState -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `isOperationReady(bytes32)` refinement - -Near-copy of `isOperationDone`. Both decode one `bytes32 id`, call the SAME inlined -`_getOperationState` helper @2232 (the 4-way state), then compare the state. `isOperationReady` -returns the `bool` `state == Ready(2)`, i.e. `1 < _timestamps[id] ∧ _timestamps[id] ≤ block.timestamp`. - -Differs from `isOperationDone` (imported, reused read-only) in: (a) body pc 614 (G350 arm 1); -(b) the compute body @1869 pushes the enum constant `2` (not `3`) but shares `isOperationDone`'s tail -JUMPDEST @1882, so the post-helper `EQ` tests `state == 2`; (c) the Solm side is the short-circuiting -`_timestamps[id] > 1 && _timestamps[id] <= block.timestamp`. The front half (guard peel, decoder, -mapping keccak), the four helper leaves, and the bool-return encoder @509 are imported unchanged. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- The 32-byte word `isOperationReady` returns for a stored timestamp `t` and block timestamp word - `tsW`: `1` iff `1 < t ∧ t ≤ tsW` (the operation state is `Ready`). -/ -def tlcIsOperationReadyBoolWord (t tsW : UInt256) : UInt256 := - if 1 < t.toNat ∧ t.toNat ≤ tsW.toNat then ⟨1⟩ else ⟨0⟩ - -/-! ## EVM: reach the body and the decoder length check -/ - -/-- Reach the `isOperationReady` body pc 614 (G350 arm 1). -/ -theorem tlcReachIsOperationReady {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 16)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨614⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x13bc9f20⟩ := - solcSelectorWord_eq_of_beq I hsz 0x13 0xbc 0x9f 0x20 ⟨0x13bc9f20⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG350Body 1 (by omega) ⟨614⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j; rw [hsw]; native_decide) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Peel the non-payable guard, push the return/decode continuations `⟨509⟩`/`⟨640⟩`, and run the - `bytes32` decoder prologue @4702 to the availability `JUMPI` @4714. -/ -theorem tlcIsOperationReadyReachLenCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 16)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4714⟩ - [⟨4718⟩, UInt256.isZero (UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩), - ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨640⟩, ⟨509⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h614⟩ := tlcReachIsOperationReady (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h627⟩ := tlcGuardPeelOk (gt := ⟨625⟩) h614 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, h627.push2 ⟨509⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨640⟩ (by native_decide) (by evm_ov) - |>.calldatasize (by native_decide) (by evm_ov) - |>.push1 ⟨4⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4702⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.slt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨4718⟩ (by native_decide) (by evm_ov)⟩ - -/-- After the length check passes, finish the decoder, jump back to the decode continuation @640, - and enter the compute body @1869 with `[id, ⟨509⟩, sel]`. -/ -theorem tlcIsOperationReadyReachCompute {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 16)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1869⟩ - [calldataWord I.calldata 4, ⟨509⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsz : 4 ≤ I.calldata.size := by omega - obtain ⟨_, _, h4714⟩ := tlcIsOperationReadyReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact ⟨_, _, h4714.jumpiT (by native_decide) - (by rw [solcDecodeLenCheckOk_4_32 hsz36 hbig hsize]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨1869⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov)⟩ - -/-! ## EVM: the `isOperationReady` tail from @1882 to the bool-return encoder @509 - - Shares `isOperationDone`'s tail JUMPDEST @1882: from `[state, 2, 0, id, ⟨509⟩, sel]`, the enum - range check (`state ≤ 3`, always taken) and `state == 2` (`EQ`) reach the encoder @509 with - `[eq state 2, sel]`. -/ -theorem tlcIsOperationReadyTail {cA gh bl σ σ₀ A I} {g : Sat256} {R key : UInt256} - {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1882⟩ - [R, ⟨2⟩, ⟨0⟩, key, ⟨509⟩, tlcSelWord I] mem aw ByteArray.empty (cA, σ) k C) - (hbound : UInt256.isZero (UInt256.gt R ⟨3⟩) ≠ ⟨0⟩) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨509⟩ - [UInt256.eq R ⟨2⟩, tlcSelWord I] mem aw ByteArray.empty (cA, σ) k' C' := by - exact ⟨_, _, h.jumpdest (by native_decide) (by evm_ov) - |>.push1 ⟨3⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.gt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨1899⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) hbound (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.eq (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov)⟩ - -/-- The compute body: call `_getOperationState` @2232, resolve its four leaves, and reach the bool - encoder @509 with `[isOperationReady(id) as bool word, sel]`. `t := _timestamps[id]`. -/ -theorem tlcIsOperationReadyCompute {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 16)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨509⟩ - [tlcIsOperationReadyBoolWord (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp), - tlcSelWord I] - (twoWordHashMem (calldataWord I.calldata 4) ⟨1⟩ solcFreePtrMem) - (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h1869⟩ := tlcIsOperationReadyReachCompute (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz36 hbig hsize hsel - -- Set up the helper call and run the mapping keccak, up to the loaded slot value. - have hkec := evm_run h1869 with [ - jumpdest, push0, push1 ⟨2⟩, jumpdest, push2 ⟨1882⟩, dup4, push2 ⟨2232⟩, jump (by jump_dest), - jumpdest, push0, dup2, dup2, - raw mstore 0 (wordAt0Mem (calldataWord I.calldata 4) solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨32⟩, - raw mstore 0 (twoWordHashMem (calldataWord I.calldata 4) ⟨1⟩ solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨64⟩, dup2, - raw keccak256 0 (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) (UInt256.ofNat 3) - (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact tlcTwoWordKeccakSlot ⟨1⟩ (calldataWord I.calldata 4)) - (by native_decide) (by evm_ov) ] - obtain ⟨_, _, hsl⟩ := hkec.sload (by native_decide) (by evm_ov) - -- `hsl` is at @2247 with the loaded timestamp `t = tlcGetTimestampWord σ I` on top. - by_cases ht0 : tlcGetTimestampWord σ I = ⟨0⟩ - · -- Unset: `t = 0` ⇒ state 0. - have hcond : UInt256.sub ⟨0⟩ (tlcGetTimestampWord σ I) = (⟨0⟩ : UInt256) := by - rw [ht0]; exact u256_sub_self ⟨0⟩ - have h1882 := evm_run hsl with [ - dup1, push0, sub, push2 ⟨2261⟩, jumpiNT hcond, - pop, push0, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationReadyTail h1882 (by decide) - have hb : UInt256.eq (⟨0⟩ : UInt256) ⟨2⟩ - = tlcIsOperationReadyBoolWord (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp) := by - unfold tlcIsOperationReadyBoolWord - rw [if_neg (fun h => absurd h.1 (show ¬ 1 < (tlcGetTimestampWord σ I).toNat by rw [ht0]; decide))] - decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - · -- `t ≠ 0`: pass the Unset `JUMPI` @2253, reach the Done check @2269. - have hne0 : (tlcGetTimestampWord σ I).toNat ≠ 0 := - fun hh => ht0 (by apply u256_inj; simpa using hh) - have hcond0 : UInt256.sub ⟨0⟩ (tlcGetTimestampWord σ I) ≠ (⟨0⟩ : UInt256) := - u256_zero_sub_ne_zero ht0 - have h2269 := evm_run hsl with [ - dup1, push0, sub, push2 ⟨2261⟩, jumpiT hcond0 (by jump_dest), - jumpdest, push1 ⟨1⟩, dup2, sub, push2 ⟨2278⟩ ] - by_cases ht1 : tlcGetTimestampWord σ I = ⟨1⟩ - · -- Done: `t = 1` ⇒ state 3. - have hcond1 : UInt256.sub (tlcGetTimestampWord σ I) ⟨1⟩ = (⟨0⟩ : UInt256) := by - rw [ht1]; exact u256_sub_self ⟨1⟩ - have h1882 := evm_run h2269 with [ - jumpiNT hcond1, - pop, push1 ⟨3⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationReadyTail h1882 (by decide) - have hb : UInt256.eq (⟨3⟩ : UInt256) ⟨2⟩ - = tlcIsOperationReadyBoolWord (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp) := by - unfold tlcIsOperationReadyBoolWord - rw [if_neg (fun h => absurd h.1 (show ¬ 1 < (tlcGetTimestampWord σ I).toNat by rw [ht1]; decide))] - decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - · -- `t ≠ 1`: pass the Done `JUMPI` @2269, reach the timestamp check @2286. - have hne1 : (tlcGetTimestampWord σ I).toNat ≠ 1 := - fun hh => ht1 (by apply u256_inj; simpa using hh) - have h2gt : 1 < (tlcGetTimestampWord σ I).toNat := by omega - have hcond1 : UInt256.sub (tlcGetTimestampWord σ I) ⟨1⟩ ≠ (⟨0⟩ : UInt256) := - u256_sub_ne_zero_of_ne ht1 - have h2286 := evm_run h2269 with [ - jumpiT hcond1 (by jump_dest), - jumpdest, timestamp, dup2, gt, iszero, push2 ⟨2295⟩ ] - by_cases htgt : UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp) = ⟨0⟩ - · -- Ready: `t ≤ block.timestamp` ⇒ state 2. - have hle : (tlcGetTimestampWord σ I).toNat ≤ (UInt256.ofNat I.header.timestamp).toNat := by - by_contra hh - rw [ugt_one (Nat.lt_of_not_le hh)] at htgt; exact absurd htgt (by decide) - have hcondr : UInt256.isZero - (UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp)) ≠ (⟨0⟩ : UInt256) := by - rw [htgt]; decide - have h1882 := evm_run h2286 with [ - jumpiT hcondr (by jump_dest), - jumpdest, pop, push1 ⟨2⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationReadyTail h1882 (by decide) - have hb : UInt256.eq (⟨2⟩ : UInt256) ⟨2⟩ - = tlcIsOperationReadyBoolWord (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp) := by - unfold tlcIsOperationReadyBoolWord; rw [if_pos ⟨h2gt, hle⟩]; decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - · -- Waiting: `t > block.timestamp` ⇒ state 1. - have hlt : ¬ (tlcGetTimestampWord σ I).toNat ≤ (UInt256.ofNat I.header.timestamp).toNat := - fun hle => htgt (ugt_zero hle) - have hcondw : UInt256.isZero - (UInt256.gt (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp)) = (⟨0⟩ : UInt256) := - isZero_eq_zero_of_ne htgt - have h1882 := evm_run h2286 with [ - jumpiNT hcondw, - pop, push1 ⟨1⟩, swap3, swap2, pop, pop, jump (by jump_dest) ] - obtain ⟨_, _, h509⟩ := tlcIsOperationReadyTail h1882 (by decide) - have hb : UInt256.eq (⟨1⟩ : UInt256) ⟨2⟩ - = tlcIsOperationReadyBoolWord (tlcGetTimestampWord σ I) (UInt256.ofNat I.header.timestamp) := by - unfold tlcIsOperationReadyBoolWord; rw [if_neg (fun h => hlt h.2)]; decide - rw [hb] at h509; exact ⟨_, _, h509⟩ - -/-- EVM: with zero callvalue and well-sized calldata, `isOperationReady(id)` returns the bool word - `1 < _timestamps[id] ∧ _timestamps[id] ≤ block.timestamp`. -/ -theorem tlcIsOperationReadyX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 16)) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (tlcIsOperationReadyBoolWord (tlcGetTimestampWord σ I) - (UInt256.ofNat I.header.timestamp))) := by - obtain ⟨_, _, h509⟩ := tlcIsOperationReadyCompute (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz36 hbig hsize hsel - exact tlcIsOperationReturnBool h509 - (twoWordHashMem_size_96 _ _ solcFreePtrMem_size) - (twoWordHashMem_read64 _ _ solcFreePtrMem_size solcFreePtrMem_read64) - (by unfold tlcIsOperationReadyBoolWord; split <;> decide) (by evm_ov) - -/-- EVM revert path for a mis-sized calldata: the signed length check fails the `JUMPI`, falling into - the decoder's `PUSH0 PUSH0 REVERT` stub. -/ -theorem tlcIsOperationReadyDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 16)) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4714⟩ := tlcIsOperationReadyReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hwv hsz hsize hsel - exact h4714.jumpiNT (by native_decide) (by rw [hslt]; decide) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-! ## ABI decode (a single `bytes32`, exactly like `isOperationDone`) -/ - -theorem tlcDecodeIsOperationReady_ok {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) : - decodeCalldataWithMode config.abiDecodeMode (isOperationReadyTransition.params.map Param.name) - (transitionSignature isOperationReadyTransition).paramTypes I.calldata - = some (tlcGetTimestampStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = _ - exact decodeCalldata_bytes32_ok hsz36 hbig - -theorem tlcDecodeIsOperationReady_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 36) : - decodeCalldataWithMode config.abiDecodeMode (isOperationReadyTransition.params.map Param.name) - (transitionSignature isOperationReadyTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_short hsz4 hshort - -theorem tlcDecodeIsOperationReady_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (isOperationReadyTransition.params.map Param.name) - (transitionSignature isOperationReadyTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["id"] [bytes32] I.calldata = none - exact decodeCalldata_bytes32_none_huge hbig - -/-! ## Solm body -/ - -/-- The Solm `isOperationReady(id)` body returns the short-circuiting bool - `_timestamps[id] > 1 && _timestamps[id] <= block.timestamp`. -/ -theorem tlcIsOperationReadyBodyReturns {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcGetTimestampStore I) - isOperationReadyTransition.body - (.returned { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) - (some [(.bool (decide (1 < (tlcGetTimestampWord σ I).toNat - ∧ (tlcGetTimestampWord σ I).toNat ≤ (UInt256.ofNat I.header.timestamp).toNat)))])) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hvk : valueToKey? (Value.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32)) - = some (tlcGetTimestampKey I) := by - simp [valueToKey?, tlcGetTimestampKey, abiBytes32Width, hlen] - have hslot : timestampSlot (tlcGetTimestampKey I) - = solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4) := by - unfold timestampSlot mapSlot solcMappingSlot - rw [tlcGetTimestampKey_eq I hsz36] - have hstore : evalExpr? config { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) (timestampExpr (.var "id")) - = .ok (.int (Int.ofNat (tlcGetTimestampWord σ I).toNat)) := by - unfold timestampExpr - rw [evalExpr_storage_scalar (cfg := config) - (solm := { contract := contract, locals := tlcGetTimestampStore I }) - (slot := timestampRef (.var "id")) - (er := ({ base := "_timestamps", steps := [.mindex (tlcGetTimestampKey I)] } : EvaledStorageRef)) - (t := .int uint256Int) (loc := uint256Loc (timestampSlot (tlcGetTimestampKey I))) - (hbase := by simp [timestampRef]) - (her := by - simp [evalStorageRef, evalStorageRefStep, timestampRef, tlcGetTimestampStore, - EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?, hvk]) - (hty := by - simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, tlcGetTimestampKey, uint256St]) - (hloc := by rfl)] - rw [hslot] - exact congrArg EvalResult.ok - (storageLocLoad_uint256 (initState cA gh bl σ σ₀ g A I) - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4))) - have henv : evalExpr? config { contract := contract, locals := tlcGetTimestampStore I } - (initState cA gh bl σ σ₀ g A I) (.env .timestamp) - = .ok (.int (Int.ofNat (UInt256.ofNat I.header.timestamp).toNat)) := by - simp only [evalExpr?, envValue, initState, pure] - refine nonpayableReturnExprBodyReturns (by simp only [initState]; exact hwv) ?_ - unfold isOperationReadyExpr isOperationPendingExpr doneTimestamp - by_cases hp : 1 < (tlcGetTimestampWord σ I).toNat - · by_cases hle : (tlcGetTimestampWord σ I).toNat ≤ (UInt256.ofNat I.header.timestamp).toNat - · have hpI : decide ((Int.ofNat (tlcGetTimestampWord σ I).toNat : Int) > 1) = true := - decide_eq_true_eq.mpr (Int.ofNat_lt.mpr hp) - have hleI : decide ((Int.ofNat (tlcGetTimestampWord σ I).toNat : Int) - ≤ Int.ofNat (UInt256.ofNat I.header.timestamp).toNat) = true := - decide_eq_true_eq.mpr (Int.ofNat_le.mpr hle) - have hr : decide (1 < (tlcGetTimestampWord σ I).toNat - ∧ (tlcGetTimestampWord σ I).toNat ≤ (UInt256.ofNat I.header.timestamp).toNat) = true := - decide_eq_true_eq.mpr ⟨hp, hle⟩ - simp only [evalExpr?, hstore, henv, EvalResult.bind, bind, pure, evalBinaryOp?, gt_iff_lt, - hpI, hleI, hr] - · have hpI : decide ((Int.ofNat (tlcGetTimestampWord σ I).toNat : Int) > 1) = true := - decide_eq_true_eq.mpr (Int.ofNat_lt.mpr hp) - have hleI : decide ((Int.ofNat (tlcGetTimestampWord σ I).toNat : Int) - ≤ Int.ofNat (UInt256.ofNat I.header.timestamp).toNat) = false := - decide_eq_false (fun hh => hle (Int.ofNat_le.mp hh)) - have hr : decide (1 < (tlcGetTimestampWord σ I).toNat - ∧ (tlcGetTimestampWord σ I).toNat ≤ (UInt256.ofNat I.header.timestamp).toNat) = false := - decide_eq_false (fun h => hle h.2) - simp only [evalExpr?, hstore, henv, EvalResult.bind, bind, pure, evalBinaryOp?, gt_iff_lt, - hpI, hleI, hr] - · have hpI : decide ((Int.ofNat (tlcGetTimestampWord σ I).toNat : Int) > 1) = false := - decide_eq_false (fun hh => hp (Int.ofNat_lt.mp hh)) - have hr : decide (1 < (tlcGetTimestampWord σ I).toNat - ∧ (tlcGetTimestampWord σ I).toNat ≤ (UInt256.ofNat I.header.timestamp).toNat) = false := - decide_eq_false (fun h => hp h.1) - simp only [evalExpr?, hstore, henv, EvalResult.bind, bind, pure, evalBinaryOp?, gt_iff_lt, - hpI, hr] - -/-- ABI-encoding the `isOperationReady` result is the EVM's returned word. -/ -theorem tlcIsOperationReadyBoolEncoding (t tsW : UInt256) : - encodeReturnValue? boolTy (.bool (decide (1 < t.toNat ∧ t.toNat ≤ tsW.toNat))) - = some (UInt256.toByteArray (tlcIsOperationReadyBoolWord t tsW)) := by - by_cases hc : 1 < t.toNat ∧ t.toNat ≤ tsW.toNat - · rw [decide_eq_true hc]; unfold tlcIsOperationReadyBoolWord; rw [if_pos hc] - simpa [boolTy] using boolTrueReturnEncoding - · rw [decide_eq_false hc]; unfold tlcIsOperationReadyBoolWord; rw [if_neg hc] - simpa [boolTy] using boolFalseReturnEncoding - -/-! ## Refinement -/ - -/-- Refinement of `IsOperationReady` (selector index 16). -/ -theorem tlcIsOperationReadyBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 16)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 16) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz36 : 36 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · -- execute: `36 ≤ size < 2^255 + 4` - have hword : tlcGetTimestampWord σ_evm I = tlcGetTimestampWord σ_solm I := by - simp only [tlcGetTimestampWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner - (solcMappingSlot ⟨1⟩ (calldataWord I.calldata 4)) ⟨0⟩ - exact tlcReEquivExecTransport hcode - (tlcIsOperationReadyX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz36 hbig hsize hsel) - (tlcSelectorDispatchIsOperationReady hsel) - (tlcDecodeIsOperationReady_ok hsz36 hbig) - (tlcIsOperationReadyBodyReturns (g := Sat256.ofUInt256 g) hwv hsz36) (by rw [← hword]) - hAccounts - (returnEquiv_of_encode (tlcIsOperationReadyBoolEncoding (tlcGetTimestampWord σ_evm I) - (UInt256.ofNat I.header.timestamp))) - · -- huge calldata: EVM reverts at the signed length check, Solm decode fails - have hhuge : 2 ^ 255 + 4 ≤ I.calldata.size := Nat.not_lt.mp hbig - have hrev := tlcIsOperationReadyDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckHuge_4_32 hhuge hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchIsOperationReady hsel) - (tlcDecodeIsOperationReady_none_huge hhuge) - · -- short calldata: EVM reverts at the length check, Solm decode fails - have hshort : I.calldata.size < 36 := by omega - have hrev := tlcIsOperationReadyDecodeRevert (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckShort_4_32 hsz hshort hsize) - exact tlcReEquivDecodeFailed hcode hrev (tlcSelectorDispatchIsOperationReady hsel) - (tlcDecodeIsOperationReady_none_short hsz hshort) - · -- nonpayable guard: `callvalue ≠ 0` - obtain ⟨_, _, h614⟩ := tlcReachIsOperationReady (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨625⟩) h614 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchIsOperationReady hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155BatchReceived.lean b/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155BatchReceived.lean deleted file mode 100644 index 2624eefb..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155BatchReceived.lean +++ /dev/null @@ -1,19 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace OpenZeppelinBench.TimelockController - -/-- Refinement of `OnERC1155BatchReceived` (selector index 18). -/ -theorem tlcOnERC1155BatchReceivedBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 18)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155Received.lean b/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155Received.lean deleted file mode 100644 index 329248f4..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/OnERC1155Received.lean +++ /dev/null @@ -1,19 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace OpenZeppelinBench.TimelockController - -/-- Refinement of `OnERC1155Received` (selector index 19). -/ -theorem tlcOnERC1155ReceivedBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 19)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/OnERC721Received.lean b/Benchmarks/OpenZeppelinBench/TimelockController/OnERC721Received.lean deleted file mode 100644 index 2cc651ab..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/OnERC721Received.lean +++ /dev/null @@ -1,19 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace OpenZeppelinBench.TimelockController - -/-- Refinement of `OnERC721Received` (selector index 20). -/ -theorem tlcOnERC721ReceivedBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 20)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ProposerRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ProposerRole.lean deleted file mode 100644 index 3917c2af..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ProposerRole.lean +++ /dev/null @@ -1,100 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Return -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch - -/-! -# OpenZeppelin TimelockController `PROPOSER_ROLE()` refinement - -`PROPOSER_ROLE` is a public non-payable `bytes32` constant getter (selector index 21, dispatch group -G194 arm 2, body pc 1050). It returns `keccak256("PROPOSER_ROLE")`. Template for the other three -role-constant getters. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- `keccak256("PROPOSER_ROLE")` as an EVM word (the `PUSH32` constant at pc 1066). -/ -def tlcProposerRoleWord : UInt256 := - ⟨0xb09aa5aeb3702cfd50b6b62bc4532604938f21248a27a1d5ca736082b6819cc1⟩ - -theorem tlcDecodeProposerRole {I : ExecutionEnv} (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (proposerRoleTransition.params.map Param.name) - (transitionSignature proposerRoleTransition).paramTypes I.calldata = some ∅ := by - show decodeCalldataWithMode config.abiDecodeMode [] [] I.calldata = some (∅ : Store) - exact decodeCalldataWithMode_empty_ok hsz - -/-- Reach the `PROPOSER_ROLE` body pc 1050 (G194 arm 2). -/ -theorem tlcReachProposerRole {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 21)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1050⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x8f61f4f5⟩ := - solcSelectorWord_eq_of_beq I hsz 0x8f 0x61 0xf4 0xf5 ⟨0x8f61f4f5⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG194Body 2 (by omega) ⟨1050⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j <;> (rw [hsw]; native_decide)) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- EVM: with zero callvalue, `PROPOSER_ROLE()` returns the 32-byte role hash. -/ -theorem tlcProposerRoleX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 21)) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray tlcProposerRoleWord) := by - obtain ⟨_, _, h1050⟩ := tlcReachProposerRole (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h1063⟩ := tlcGuardPeelOk (gt := ⟨1061⟩) h1050 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - have h581 := h1063.push2 ⟨581⟩ (by native_decide) (by simp) - |>.pushConst tlcProposerRoleWord (op := .PUSH32) (width := 32) (by decide) - (by native_decide) (by simp) - |>.dup2 (by native_decide) (by simp) - |>.jump (by native_decide) (by jump_dest) (by simp) - exact tlcReturnWord h581 (by simp) - -/-- The Solm `PROPOSER_ROLE()` body returns the constant `bytes32`. -/ -theorem tlcProposerRoleBodyReturns (evm : EVM.State) (locals : Store) - (h : evm.executionEnv.weiValue = ⟨0⟩) : - ExecTransitionBody config contract evm locals proposerRoleTransition.body - (.returned { contract := contract, locals := locals } evm - (some [(.fixedBytes bytes32Width (EVM.Word.toBytesBE tlcProposerRoleWord))])) := by - have hbody : proposerRoleTransition.body = - [ Stmt.require (.binary .eq (.env .callvalue) (.intLit 0)), - Stmt.return [Expr.fixedBytesLit bytes32Width (EVM.Word.toBytesBE tlcProposerRoleWord)] ] := by - native_decide - rw [hbody] - exact nonpayableFixedBytesLiteralBodyReturns (cfg := config) (contract := contract) - evm locals bytes32Width (EVM.Word.toBytesBE tlcProposerRoleWord) h - -/-- Refinement of `PROPOSER_ROLE` (selector index 21). -/ -theorem tlcProposerRoleBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 21)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 21) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · exact tlcReEquivExecTransport hcode - (tlcProposerRoleX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel) - (tlcSelectorDispatchProposerRole hsel) (tlcDecodeProposerRole hsz) - (tlcProposerRoleBodyReturns (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) ∅ - (by simp only [initState]; exact hwv)) - rfl hAccounts - (returnEquiv_of_encode (bytes32ReturnEncoding tlcProposerRoleWord)) - · obtain ⟨_, _, h1050⟩ := tlcReachProposerRole (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨1061⟩) h1050 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchProposerRole hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Receivers.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Receivers.lean deleted file mode 100644 index 12507cf7..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Receivers.lean +++ /dev/null @@ -1,226 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Return -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController — shared ERC-receiver routines - -The three ERC receivers (`onERC721Received`, `onERC1155Received`, `onERC1155BatchReceived`) each decode -their dynamic-typed calldata, ignore the decoded arguments, and `RETURN` a constant left-aligned -`bytes4` selector. The runtime shares one `bytes4` return encoder at pc 687 → pc 521: - -``` -687 MLOAD(0x40) -- P := free pointer (bumped past the decoded buffer) - PUSH1 1; PUSH1 1; PUSH1 0xe0; SHL; SUB; NOT -- top-4-byte mask ~((1<<224)-1) - AND; MSTORE(P) -- store (selVal & mask) at P - PUSH1 0x20; ADD; PUSH2 521; JUMP -521 MLOAD(0x40); DUP1; SWAP2; SUB; SWAP1; RETURN -- RETURN(P, 0x20) = mem[P .. P+0x20] -``` - -Because the decoder bumps the free pointer to `P = 0x80 + 0x20 + paddedLen` and leaves the active-word -count at exactly `(P + 0x20)/0x20`, the encoder's `MSTORE(P)` and `RETURN(P, 0x20)` touch only -already-active memory, so both have zero memory-expansion cost. `tlcRecvReturnBytes4` captures this -over an abstract `(mem, P, aw)`. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Left-aligned `bytes4` selector words (as `RETURN`ed by the shared encoder) -/ - -/-- `0x150b7a02 << 224` — the `onERC721Received` selector, left-aligned in a word. -/ -def tlcRecvErc721Word : UInt256 := - ⟨0x150b7a0200000000000000000000000000000000000000000000000000000000⟩ - -/-- `0xf23a6e61 << 224` — the `onERC1155Received` selector, left-aligned in a word. -/ -def tlcRecvErc1155Word : UInt256 := - ⟨0xf23a6e6100000000000000000000000000000000000000000000000000000000⟩ - -/-- `0xbc197c81 << 224` — the `onERC1155BatchReceived` selector, left-aligned in a word. -/ -def tlcRecvErc1155BatchWord : UInt256 := - ⟨0xbc197c8100000000000000000000000000000000000000000000000000000000⟩ - -/-- The top-4-byte keep mask the runtime materialises at pc 691..699 (`~((1<<224)-1)`). -/ -def tlcRecvBytes4Mask : UInt256 := - UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) ⟨1⟩) - -/-! ## `bytes4` ABI return encoding - -The Solm body returns `.fixedBytes bytes4Width <4 bytes>`; solc encodes that as the 4 bytes followed -by 28 zero bytes, i.e. exactly the 32 big-endian bytes of the left-aligned word. -/ - -theorem tlcRecvErc721ReturnEncoding : - encodeReturnValue? bytes4 (.fixedBytes bytes4Width [0x15, 0x0b, 0x7a, 0x02]) = - some (UInt256.toByteArray tlcRecvErc721Word) := by - refine scalarReturnEncoding (t := .bytes bytes4Width) (w := tlcRecvErc721Word) (by decide) ?_ ?_ - · native_decide - · native_decide - -theorem tlcRecvErc1155ReturnEncoding : - encodeReturnValue? bytes4 (.fixedBytes bytes4Width [0xf2, 0x3a, 0x6e, 0x61]) = - some (UInt256.toByteArray tlcRecvErc1155Word) := by - refine scalarReturnEncoding (t := .bytes bytes4Width) (w := tlcRecvErc1155Word) (by decide) ?_ ?_ - · native_decide - · native_decide - -theorem tlcRecvErc1155BatchReturnEncoding : - encodeReturnValue? bytes4 (.fixedBytes bytes4Width [0xbc, 0x19, 0x7c, 0x81]) = - some (UInt256.toByteArray tlcRecvErc1155BatchWord) := by - refine scalarReturnEncoding (t := .bytes bytes4Width) (w := tlcRecvErc1155BatchWord) (by decide) ?_ ?_ - · native_decide - · native_decide - -/-! ## Zero memory-expansion cost for an already-active 32-byte window -/ - -/-- `MachineState.M` fixed point: a 32-byte window ending at or before `aw*32` does not grow memory. -/ -theorem tlcRecvM_fixed {aw off : ℕ} (hle : off + 32 ≤ aw * 32) : - MachineState.M aw off 32 = aw := by - show max aw ((off + 32 + 31) / 32) = aw - rw [Nat.max_eq_left] - omega - -/-- `MSTORE` of a word into an already-active window costs nothing. -/ -theorem tlcRecvMstoreCost0 {s : State} {aw off val : UInt256} {t : List UInt256} - (haw : s.machineState.activeWords = aw) (hstk : s.machineState.stack = off :: val :: t) - (hle : off.toNat + 32 ≤ aw.toNat * 32) : - memoryExpansionCost s .MSTORE = 0 := by - refine mstoreCost_of_stack haw hstk ?_ - rw [tlcRecvM_fixed hle, u256_ofNat_toNat] - omega - -/-- `MLOAD` of an already-active window costs nothing. -/ -theorem tlcRecvMloadCost0 {s : State} {aw off : UInt256} {t : List UInt256} - (haw : s.machineState.activeWords = aw) (hstk : s.machineState.stack = off :: t) - (hle : off.toNat + 32 ≤ aw.toNat * 32) : - memoryExpansionCost s .MLOAD = 0 := by - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ'] - have htop : s.machineState.stack[0]! = off := by rw [hstk]; rfl - rw [htop, haw, tlcRecvM_fixed hle, u256_ofNat_toNat] - omega - -/-- `RETURN`ing an already-active 32-byte window costs nothing. -/ -theorem tlcRecvReturnCost0 {s : State} {aw off : UInt256} {t : List UInt256} - (haw : s.machineState.activeWords = aw) - (hstk : s.machineState.stack = off :: (⟨32⟩ : UInt256) :: t) - (hle : off.toNat + 32 ≤ aw.toNat * 32) : - memoryExpansionCost s .RETURN = 0 := by - simp only [memoryExpansionCost, memoryExpansionCost.μᵢ'] - have htop : s.machineState.stack[0]! = off := by rw [hstk]; rfl - have hnext : s.machineState.stack[1]! = (⟨32⟩ : UInt256) := by rw [hstk]; rfl - rw [htop, hnext, haw, show ((⟨32⟩ : UInt256).toNat) = 32 from by decide, - tlcRecvM_fixed hle, u256_ofNat_toNat] - omega - -/-- The active-word slot `aw*32` exceeds an in-range offset, so `MLOAD off` reads real memory. -/ -theorem tlcRecvNotGe {off aw : UInt256} (hawsz : aw.toNat * 32 < UInt256.size) - (hlt : off.toNat < aw.toNat * 32) : ¬ off ≥ aw * ⟨32⟩ := by - have hmul : (aw * ⟨32⟩).toNat = aw.toNat * 32 := by - rw [umul_toNat aw ⟨32⟩ (by rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide]; exact hawsz), - show (⟨32⟩ : UInt256).toNat = 32 from by decide] - intro hge - have h2 : (aw * ⟨32⟩).toNat ≤ off.toNat := hge - rw [hmul] at h2 - omega - -/-- `MachineState.M` fixed point, lifted to the word `activeWords`. -/ -theorem tlcRecvAwFixed {aw : UInt256} {off : ℕ} (hle : off + 32 ≤ aw.toNat * 32) : - UInt256.ofNat (MachineState.M aw.toNat off 32) = aw := by - rw [tlcRecvM_fixed hle, u256_ofNat_toNat] - -/-! ## Shared `bytes4` return encoder (pc 687 → pc 521) - - Runs over the memory the decoder left: free pointer `P` at `0x40`, buffer occupying `[0x80, P)`, - and active words at exactly `(P + 0x20)/0x20`. Stores the masked selector at `P` and - `RETURN(P, 0x20)`s it. All three memory touches (`MLOAD 0x40`, `MSTORE P`, `MLOAD 0x40`, - `RETURN P`) land in already-active memory, so they cost nothing. -/ -theorem tlcRecvReturnBytes4 {cA gh bl σ σ₀ A I} {g : Sat256} - {selVal P cont : UInt256} {R : List UInt256} {mem : ByteArray} {aw : UInt256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨687⟩ - (selVal :: cont :: R) mem aw ByteArray.empty (cA, σ) k C) - (hfree : mem.readWithPadding 64 32 = UInt256.toByteArray P) - (hmemsz : P.toNat ≤ mem.size) - (hPlo : 96 ≤ P.toNat) - (hawP : aw.toNat * 32 = P.toNat + 32) - (hPhi : P.toNat + 32 < UInt256.size) - (hov : R.length + 6 ≤ 1024) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land selVal tlcRecvBytes4Mask)) := by - have hawsz : aw.toNat * 32 < UInt256.size := by rw [hawP]; exact hPhi - have h64lt : (64 : ℕ) < aw.toNat * 32 := by omega - -- masked value stored at P - set val := UInt256.land selVal tlcRecvBytes4Mask with hval - set memout := (UInt256.toByteArray val).write 0 mem P.toNat 32 with hmemout - -- pc 687 .. 711: MLOAD 0x40, build mask, AND, MSTORE at P, jump to 521 - have h521 := h.jumpdest (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.mload 0 P aw (by native_decide) - (fun s hs1 hs2 => tlcRecvMloadCost0 hs1 hs2 - (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; omega)) - (mloadWordValue_of_readWithPadding - (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; omega) - (tlcRecvNotGe hawsz (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; omega)) - (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; exact hfree)) - (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; exact tlcRecvAwFixed (by omega)) - (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨224⟩ (by native_decide) (by evm_ov) - |>.shl (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.not (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.and (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.mstore 0 memout aw (by native_decide) - (fun s hs1 hs2 => tlcRecvMstoreCost0 hs1 hs2 (by omega)) - hmemout.symm - (by rw [tlcRecvAwFixed (by omega)]) - (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.add (by native_decide) (by evm_ov) - |>.push2 ⟨521⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - -- pc 521 .. 529: MLOAD 0x40 (still P), compute length 0x20, RETURN(P, 0x20) - have hmemoutsz : P.toNat + 32 ≤ memout.size := - toByteArray_write_size_ge_off_add32 val mem P.toNat (lt_usize _ (by omega)) - have hread64 : memout.readWithPadding 64 32 = UInt256.toByteArray P := by - rw [hmemout, write32_read_below (UInt256.toByteArray val) mem P.toNat 64 - (by rw [toByteArray_size]) hmemsz (by omega)] - exact hfree - have hreadP : memout.readWithPadding P.toNat 32 = UInt256.toByteArray val := by - rw [hmemout]; exact toByteArray_write32_read_back mem val P.toNat hmemsz - have hret := h521.jumpdest (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.mload 0 P aw (by native_decide) - (fun s hs1 hs2 => tlcRecvMloadCost0 hs1 hs2 - (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; omega)) - (mloadWordValue_of_readWithPadding - (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; omega) - (tlcRecvNotGe hawsz (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; omega)) - (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; exact hread64)) - (by rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide]; exact tlcRecvAwFixed (by omega)) - (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - have hlen32 : UInt256.sub (⟨32⟩ + P) P = ⟨32⟩ := by - apply u256_inj - have hadd : (⟨32⟩ + P).toNat = 32 + P.toNat := by - rw [uadd_toNat, show (⟨32⟩ : UInt256).toNat = 32 from by decide, Nat.mod_eq_of_lt (by omega)] - show (UInt256.sub (⟨32⟩ + P) P).toNat = (⟨32⟩ : UInt256).toNat - rw [usub_toNat (by rw [hadd]; omega), hadd, show (⟨32⟩ : UInt256).toNat = 32 from by decide] - omega - rw [hlen32] at hret - exact hret.ret 0 (UInt256.toByteArray val) (by native_decide) - (fun s hs1 hs2 => tlcRecvReturnCost0 hs1 hs2 (by omega)) - (by rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide]; exact hreadP) - (by evm_ov) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/RenounceRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/RenounceRole.lean deleted file mode 100644 index 7839a213..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/RenounceRole.lean +++ /dev/null @@ -1,785 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.HasRole -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `renounceRole(bytes32,address)` refinement - -`renounceRole` (selector index 22, dispatch group G254 arm 0, body pc 851) is the first -**nested-mapping storage-write** function proven for this contract. It decodes `(bytes32 role, -address callerConfirmation)` via the shared two-arg decoder `@4999` (the same one `hasRole` uses), -enforces `require(callerConfirmation == msg.sender)`, then calls the inlined `_revokeRole` helper -`@4096`: it computes the nested slot `keccak(account ‖ keccak(role ‖ 0))` (reusing -`tlcHasRoleSlotLoad @2762`), `SLOAD`s it, and — **only if the role is currently present** — clears the -low byte with `SLOAD; AND(NOT 0xff); SSTORE` and emits a `RoleRevoked` `LOG4`, otherwise it does -nothing. - -Template for the other nested-mapping mutations (`grantRole`/`revokeRole`): the conditional write is a -Solm `.ite` whose true branch `.assign .storage (roleHasRoleRef …) (.boolLit false)` couples to the -EVM `SSTORE` of `land word (lnot 0xff)` via `storageLocStore_bool_false_offset0`; the false branch is -a no-op matching the EVM jump-around at `@4089`. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Decoded arguments, source store, and post-state - -The role key / confirmation key / nested slot / stored word are all shared with `hasRole` -(`tlcHasRoleRoleKey`, `tlcHasRoleAccountKey`, `tlcHasRoleSlot`, `tlcHasRoleWord`): the same calldata -words hash to the same slot. Only the source-level local store differs (the second param is named -`callerConfirmation`, not `account`). -/ - -/-- The decoded local store bound by `renounceRole(bytes32 role, address callerConfirmation)`. -/ -abbrev tlcRenounceRoleStore (I : ExecutionEnv) : Store := - ((∅ : Store).insert "role" - (.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32))).insert - "callerConfirmation" (.address (AccountAddress.ofNat (calldataWord I.calldata 36).toNat)) - -/-- The nested-mapping slot `keccak(account ‖ keccak(role ‖ 0))` (= `tlcHasRoleSlot I`), as an - `abbrev` so it unfolds to the raw `solcMappingSlot` form produced by `tlcHasRoleSlotLoad`. -/ -abbrev tlcRenounceRoleSlot (I : ExecutionEnv) : UInt256 := - solcMappingSlot (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (UInt256.land solcAddrMask (calldataWord I.calldata 36)) - -/-- The stored `_roles[role].hasRole[callerConfirmation]` word. -/ -abbrev tlcRenounceRoleWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (tlcRenounceRoleSlot I) - -/-- Scratch memory after the `_revokeRole` slot computation: `account‖inner` staged over the - inner-slot preimage `role‖0` (the memory `tlcHasRoleSlotLoad` leaves at its exit). -/ -noncomputable abbrev tlcRenounceRoleKecMem (I : ExecutionEnv) : ByteArray := - twoWordHashMem (UInt256.land solcAddrMask (calldataWord I.calldata 36)) - (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ solcFreePtrMem) - -/-- The `EVM.State` after `_roles[role].hasRole[callerConfirmation] = false` (nested slot write); - stated exactly as `storageLocStore_bool_false_offset0` produces it. -/ -abbrev tlcRenounceRolePost (evm : EVM.State) (I : ExecutionEnv) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner (tlcRenounceRoleSlot I) - (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (tlcRenounceRoleSlot I)) - (UInt256.lnot ⟨255⟩)) - -/-- The runtime recomputes the outer slot with the mask on the right (`account & ((1<<160)-1)`); it - equals the spec/`tlcHasRoleSlotLoad` slot (mask on the left). -/ -theorem tlcRenounceRoleOuterSlot (I : ExecutionEnv) : - solcMappingSlot (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) - = tlcRenounceRoleSlot I := by - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by decide - rw [hmask, u256_land_comm] - -/-! ## ABI decode (two-arg `(bytes32, address)`, shared decoder) -/ - -theorem tlcDecodeRenounceRole_ok {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (renounceRoleTransition.params.map Param.name) - (transitionSignature renounceRoleTransition).paramTypes I.calldata - = some (tlcRenounceRoleStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "callerConfirmation"] [bytes32, addr] - I.calldata = _ - exact decodeCalldata_bytes32_address_ok hsz68 hbig hcanon - -theorem tlcDecodeRenounceRole_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 68) : - decodeCalldataWithMode config.abiDecodeMode (renounceRoleTransition.params.map Param.name) - (transitionSignature renounceRoleTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "callerConfirmation"] [bytes32, addr] - I.calldata = none - exact decodeCalldata_bytes32_address_none_short hsz4 hshort - -theorem tlcDecodeRenounceRole_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (renounceRoleTransition.params.map Param.name) - (transitionSignature renounceRoleTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "callerConfirmation"] [bytes32, addr] - I.calldata = none - exact decodeCalldata_bytes32_address_none_huge hbig - -theorem tlcDecodeRenounceRole_none_noncanon {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hnc : ¬ (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (renounceRoleTransition.params.map Param.name) - (transitionSignature renounceRoleTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "callerConfirmation"] [bytes32, addr] - I.calldata = none - exact decodeCalldata_bytes32_address_none_noncanon hsz68 hbig hnc - -/-! ## EVM: reach the body and run the shared two-arg decoder -/ - -/-- Reach the `renounceRole` body pc 851 (G254 arm 0). -/ -theorem tlcReachRenounceRole {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 22)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨851⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x36568abe⟩ := - solcSelectorWord_eq_of_beq I hsz 0x36 0x56 0x8a 0xbe ⟨0x36568abe⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG254Body 0 (by omega) ⟨851⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; exact absurd hj (Nat.not_lt_zero j)) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Peel the non-payable guard, push the two continuations `[476, 877]`, and run the two-arg decoder - prologue to the `SLT` length-check `JUMPI` @5012 (identical to `tlcHasRoleReachLenCheck` but with - the `renounceRole` return/decode continuations `476`/`877`). -/ -theorem tlcRenounceRoleReachLenCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 22)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨5012⟩ - [⟨5016⟩, UInt256.isZero (UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩), - ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨877⟩, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h851⟩ := tlcReachRenounceRole (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h864⟩ := tlcGuardPeelOk (gt := ⟨862⟩) h851 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, h864.push2 ⟨476⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨877⟩ (by native_decide) (by evm_ov) - |>.calldatasize (by native_decide) (by evm_ov) - |>.push1 ⟨4⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4999⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - |>.dup6 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.slt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨5016⟩ (by native_decide) (by evm_ov)⟩ - -/-- After the length check passes, run the two-arg decoder to the address sub-decoder's canonicality - `EQ`/`JUMPI` @4374 (identical to `tlcHasRoleReachEqCheck` with continuations `476`/`877`). -/ -theorem tlcRenounceRoleReachEqCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 22)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4374⟩ - [⟨4378⟩, - UInt256.eq (calldataWord I.calldata 36) - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)), - calldataWord I.calldata 36, ⟨36⟩, ⟨5032⟩, ⟨0⟩, calldataWord I.calldata 4, ⟨4⟩, - UInt256.ofNat I.calldata.size, ⟨877⟩, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = ⟨0⟩ := - solcDecodeLenCheckOk_4_64 hsz68 hbig hsize - obtain ⟨_, _, h5012⟩ := tlcRenounceRoleReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv (by omega) hsize hsel - have hoff : (⟨4⟩ : UInt256) + ⟨32⟩ = ⟨36⟩ := by decide - have hafterAdd := h5012.jumpiT (by native_decide) (by rw [hslt]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.push2 ⟨5032⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.add (by native_decide) (by evm_ov) - rw [hoff] at hafterAdd - exact ⟨_, _, hafterAdd.push2 ⟨4356⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨160⟩ (by native_decide) (by evm_ov) - |>.shl (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.and (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.eq (by native_decide) (by evm_ov) - |>.push2 ⟨4378⟩ (by native_decide) (by evm_ov)⟩ - -/-- With a canonical confirmation address, finish the decoder tail (@4374 `EQ` passes) and jump through - the decode continuation `@877` into the `renounceRole` body logic `@1992`, leaving - `[callerConfirmation, role, 476, sel]` on the stack over `solcFreePtrMem`. -/ -theorem tlcRenounceRoleReach1992 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 22)) - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1992⟩ - [calldataWord I.calldata 36, calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by decide - obtain ⟨_, _, h4374⟩ := tlcRenounceRoleReachEqCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv hsz68 hbig hsize hsel - exact ⟨_, _, h4374.jumpiT (by native_decide) - (by rw [hmask, solcAddrCanon_eq hcanon]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨1992⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov)⟩ - -/-! ## The `callerConfirmation == msg.sender` check (body @1992-2008) -/ - -/-- Masking a canonical confirmation address with the runtime `(1<<160)-1` mask is the identity. -/ -theorem tlcRenounceRoleMaskConf {I : ExecutionEnv} - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) - = calldataWord I.calldata 36 := by - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by decide - rw [hmask]; exact solcAddrMask_clean hcanon - -/-- `msg.sender` (as a word) equals the decoded confirmation word exactly when the confirmation - address decodes back to `msg.sender`. -/ -theorem tlcRenounceRoleSourceConf {I : ExecutionEnv} - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - (UInt256.ofNat I.source.val = calldataWord I.calldata 36) - ↔ AccountAddress.ofNat (calldataWord I.calldata 36).toNat = I.source := by - have hv : (AccountAddress.ofNat (calldataWord I.calldata 36).toNat).val - = (calldataWord I.calldata 36).toNat := by - unfold AccountAddress.ofNat - exact Nat.mod_eq_of_lt (by - rw [show AccountAddress.size = EVM.addressModulus from by decide]; exact hcanon) - constructor - · intro h - have hval : I.source.val = (calldataWord I.calldata 36).toNat := by - rw [← solcSourceWord_toNat I, solcSourceWord]; rw [h] - exact (Fin.ext (by rw [hv, hval])) - · intro h - rw [← h] - rw [show (AccountAddress.ofNat (calldataWord I.calldata 36).toNat).val - = (calldataWord I.calldata 36).toNat from hv] - exact u256_ofNat_toNat _ - -/-- Confirmation matches: the EVM `CALLER == callerConfirmation` `EQ` is `1`. -/ -theorem tlcRenounceRoleConfEqTrue {I : ExecutionEnv} - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) - (hconf : AccountAddress.ofNat (calldataWord I.calldata 36).toNat = I.source) : - UInt256.eq (UInt256.ofNat I.source.val) - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) = ⟨1⟩ := by - rw [tlcRenounceRoleMaskConf hcanon, (tlcRenounceRoleSourceConf hcanon).2 hconf] - exact uInt256_eq_self _ - -/-- Confirmation mismatches: the EVM `CALLER == callerConfirmation` `EQ` is `0`. -/ -theorem tlcRenounceRoleConfEqFalse {I : ExecutionEnv} - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) - (hnconf : ¬ AccountAddress.ofNat (calldataWord I.calldata 36).toNat = I.source) : - UInt256.eq (UInt256.ofNat I.source.val) - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) = ⟨0⟩ := by - rw [tlcRenounceRoleMaskConf hcanon] - apply uInt256_eq_zero_of_ne - intro hbad - exact hnconf ((tlcRenounceRoleSourceConf hcanon).1 (uInt256_eq_one_eq hbad)) - -/-- Confirmation-mismatch revert: build the `AccessControlBadConfirmation()` custom error and - `REVERT` (body @1992 → @2032). -/ -theorem tlcRenounceRoleRevConfirm {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1992⟩ - [calldataWord I.calldata 36, calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) - (hnconf : ¬ AccountAddress.ofNat (calldataWord I.calldata 36).toNat = I.source) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have h2032 := evm_run h with [ - jumpdest, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup2, and, - raw caller (by native_decide) (by evm_ov), - eq, push2 ⟨2033⟩, - jumpiNT (by exact tlcRenounceRoleConfEqFalse hcanon hnconf), - push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost solcFreePtrMem_mload64 - (by native_decide) (by evm_ov), - raw push4 ⟨0x334bd919⟩ (by native_decide) (by evm_ov), - push1 ⟨225⟩, shl, dup2, - raw mstore 6 (solcReturnMem (UInt256.shiftLeft ⟨0x334bd919⟩ ⟨225⟩)) (UInt256.ofNat 5) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨4⟩, add, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 5) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [solcReturnMem_size]; decide) (by decide) - (solcReturnMem_read64 _)) (by native_decide) (by evm_ov), - dup1, swap2, sub, swap1 ] - exact h2032.rev 0 (by native_decide) mem_cost (by evm_ov) - -/-! ## `_revokeRole` (body @1992 → @4096 → slot load @2762 → @4107) -/ - -/-- Confirmation matches: run the confirmation check, dispatch to `_revokeRole @4096`, and reuse - `tlcHasRoleSlotLoad @2762` for the nested-slot `SLOAD`, reaching the `if present` `ISZERO/JUMPI` - @4107 with the masked stored word on top and the recomputation scratch in memory. -/ -theorem tlcRenounceRoleReach4107 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1992⟩ - [calldataWord I.calldata 36, calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) - (hconf : AccountAddress.ofNat (calldataWord I.calldata 36).toNat = I.source) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4107⟩ - [UInt256.land ⟨255⟩ (tlcRenounceRoleWord σ I), ⟨0⟩, calldataWord I.calldata 36, - calldataWord I.calldata 4, ⟨2043⟩, calldataWord I.calldata 36, calldataWord I.calldata 4, - ⟨476⟩, tlcSelWord I] - (tlcRenounceRoleKecMem I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - have h2762 := evm_run h with [ - jumpdest, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup2, and, - raw caller (by native_decide) (by evm_ov), - eq, push2 ⟨2033⟩, - jumpiT (by rw [tlcRenounceRoleConfEqTrue hcanon hconf]; decide) (by jump_dest), - jumpdest, - push2 ⟨2043⟩, dup3, dup3, push2 ⟨4096⟩, - jump (by jump_dest), - jumpdest, - push0, push2 ⟨4107⟩, dup4, dup4, push2 ⟨2762⟩, - jump (by jump_dest) ] - exact tlcHasRoleSlotLoad h2762 (by jump_dest) (by evm_ov) - -/-- Role absent (`_roles[role].hasRole[account]` already `false`): `_revokeRole` takes the `@4089` - skip branch, does no `SSTORE`/`LOG`, and `STOP`s with the account map unchanged. -/ -theorem tlcRenounceRoleX_absent {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1992⟩ - [calldataWord I.calldata 36, calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) - (hconf : AccountAddress.ofNat (calldataWord I.calldata 36).toNat = I.source) - (habsent : UInt256.land ⟨255⟩ (tlcRenounceRoleWord σ I) = ⟨0⟩) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - ByteArray.empty := by - obtain ⟨_, _, h4107⟩ := tlcRenounceRoleReach4107 h hcanon hconf - have h476 := evm_run h4107 with [ - jumpdest, - iszero, push2 ⟨4089⟩, - jumpiT (by rw [habsent]; decide) (by jump_dest), - jumpdest, - pop, push0, push2 ⟨1685⟩, - jump (by jump_dest), - jumpdest, - swap3, swap2, pop, pop, - jump (by jump_dest), - jumpdest, - pop, pop, pop, - jump (by jump_dest), - jumpdest ] - exact h476.stop (by native_decide) (by evm_ov) - -/-- The `RoleRevoked(bytes32,address,address)` event topic (the `PUSH32` at pc 4158). -/ -abbrev tlcRenounceRoleRevokedTopic : UInt256 := - ⟨0xf6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b⟩ - -/-- Role present (`_roles[role].hasRole[account]` currently `true`): `_revokeRole` recomputes the - nested slot, `SSTORE`s `word & ~0xff` (clearing the bool to `false`), emits `RoleRevoked` `LOG4`, - and `STOP`s — halting with the account map carrying the single nested-slot write. -/ -theorem tlcRenounceRoleX_present {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1992⟩ - [calldataWord I.calldata 36, calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hperm : I.perm = true) - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) - (hconf : AccountAddress.ofNat (calldataWord I.calldata 36).toNat = I.source) - (hpresent : ¬ UInt256.land ⟨255⟩ (tlcRenounceRoleWord σ I) = ⟨0⟩) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) - (cA, sstoreAccountMap I.codeOwner σ (tlcRenounceRoleSlot I) - (UInt256.land (UInt256.lnot ⟨255⟩) (tlcRenounceRoleWord σ I))) ByteArray.empty := by - obtain ⟨_, _, h4107⟩ := tlcRenounceRoleReach4107 h hcanon hconf - have hM0 : (tlcRenounceRoleKecMem I).size = 96 := - twoWordHashMem_size_96 _ _ (twoWordHashMem_size_96 _ _ solcFreePtrMem_size) - have hM2 : (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRenounceRoleKecMem I)).size = 96 := - twoWordHashMem_size_96 _ _ hM0 - have hM4size : (twoWordHashMem - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) - (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRenounceRoleKecMem I))).size = 96 := - twoWordHashMem_size_96 _ _ hM2 - have hM4read64 : (twoWordHashMem - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) - (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRenounceRoleKecMem I))).readWithPadding - 64 32 = UInt256.toByteArray ⟨128⟩ := - twoWordHashMem_read64 _ _ hM2 (twoWordHashMem_read64 _ _ hM0 - (twoWordHashMem_read64 _ _ (twoWordHashMem_size_96 _ _ solcFreePtrMem_size) - (twoWordHashMem_read64 _ _ solcFreePtrMem_size solcFreePtrMem_read64))) - have hkec := evm_run h4107 with [ - jumpdest, - iszero, push2 ⟨4089⟩, - jumpiNT (by exact isZero_eq_zero_of_ne hpresent), - push0, dup4, dup2, - raw mstore 0 (wordAt0Mem (calldataWord I.calldata 4) (tlcRenounceRoleKecMem I)) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨32⟩, dup2, dup2, - raw mstore 0 (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRenounceRoleKecMem I)) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨64⟩, dup1, dup4, - raw keccak256 0 (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) (UInt256.ofNat 3) - (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact twoWordHashMem_solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4) hM0) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup7, and, dup1, dup6, - raw mstore 0 (wordAt0Mem - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRenounceRoleKecMem I))) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - swap3, - raw mstore 0 (twoWordHashMem - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) - (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRenounceRoleKecMem I))) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - dup1, dup4, - raw keccak256 0 (tlcRenounceRoleSlot I) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact (twoWordHashMem_solcMappingSlot (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) hM2).trans - (tlcRenounceRoleOuterSlot I)) - (by native_decide) (by evm_ov), - dup1 ] - obtain ⟨_, _, hsl⟩ := hkec.sload (by native_decide) (by evm_ov) - have hsstorepre := evm_run hsl with [ push1 ⟨255⟩, not, and, swap1 ] - obtain ⟨_, _, hss⟩ := hsstorepre.sstore hperm (by native_decide) (by evm_ov) - have hlogpre := evm_run hss with [ - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [hM4size]; decide) (by decide) hM4read64) - (by native_decide) (by evm_ov), - raw caller (by native_decide) (by evm_ov), - swap3, dup7, swap2 ] - have hlog := (hlogpre.pushConst tlcRenounceRoleRevokedTopic (width := 32) (op := .PUSH32) - (by decide) (by native_decide) (by evm_ov)).swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - have h476 := (hlog.log4 0 (UInt256.ofNat 3) (by native_decide) hperm mem_cost - (by native_decide) (by evm_ov)) |>.pop (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨1685⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - exact h476.stop (by native_decide) (by evm_ov) - -/-! ## EVM decode-revert paths (shared two-arg decoder) -/ - -/-- Mis-sized calldata: the signed length check fails the `JUMPI`, falling into the decoder's - `PUSH0 PUSH0 REVERT` stub @5013. -/ -theorem tlcRenounceRoleDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 22)) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h5012⟩ := tlcRenounceRoleReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv hsz hsize hsel - exact h5012.jumpiNT (by native_decide) (by rw [hslt]; decide) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-- Non-canonical confirmation address: the sub-decoder's canonicality `EQ` fails the `JUMPI`, - falling into the `PUSH0 PUSH0 REVERT` stub @4375. -/ -theorem tlcRenounceRoleNoncanonRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 22)) - (hnc : ¬ (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by decide - obtain ⟨_, _, h4374⟩ := tlcRenounceRoleReachEqCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv hsz68 hbig hsize hsel - exact h4374.jumpiNT (by native_decide) (by rw [hmask]; exact tlcHasRoleNoncanon_eq hnc) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-! ## Solm body -/ - -theorem tlcRenounceRoleStore_get_roles (I : ExecutionEnv) : - (tlcRenounceRoleStore I).get? "_roles" = none := by - unfold tlcRenounceRoleStore - rw [store_get_ne2 _ _ _ (by native_decide) (by native_decide)] - simp - -theorem tlcRenounceRoleStore_index_role (I : ExecutionEnv) : - (tlcRenounceRoleStore I)["role"] = - Value.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32) := by - unfold tlcRenounceRoleStore - rw [Std.HashMap.getElem_insert]; simp - -/-- `wordToElem .bool (word & 0xff)` is `true` exactly when the packed byte is nonzero. -/ -theorem tlcRenounceRoleWordToElem_present {σ : AccountMap} {I : ExecutionEnv} - (hpres : ¬ UInt256.land ⟨255⟩ (tlcRenounceRoleWord σ I) = ⟨0⟩) : - Solm.wordToElem .bool (UInt256.land (tlcRenounceRoleWord σ I) ⟨255⟩) = .bool true := by - have hz : UInt256.land (tlcRenounceRoleWord σ I) ⟨255⟩ ≠ ⟨0⟩ := by - rw [u256_land_comm]; exact hpres - by_cases hval : (UInt256.land (tlcRenounceRoleWord σ I) ⟨255⟩).val = 0 - · exact absurd (u256_inj (congrArg Fin.val hval)) hz - · simp [Solm.wordToElem, hval] - -/-- `wordToElem .bool (word & 0xff)` is `false` exactly when the packed byte is zero. -/ -theorem tlcRenounceRoleWordToElem_absent {σ : AccountMap} {I : ExecutionEnv} - (habs : UInt256.land ⟨255⟩ (tlcRenounceRoleWord σ I) = ⟨0⟩) : - Solm.wordToElem .bool (UInt256.land (tlcRenounceRoleWord σ I) ⟨255⟩) = .bool false := by - have hz : UInt256.land (tlcRenounceRoleWord σ I) ⟨255⟩ = ⟨0⟩ := by - rw [u256_land_comm]; exact habs - simp [Solm.wordToElem, hz] - -/-- The `callerConfirmation == msg.sender` guard evaluates to `true` when the decoded confirmation - address is `msg.sender`. -/ -theorem tlcRenounceRoleGuardEval (evm : EVM.State) (I : ExecutionEnv) - (hself : AccountAddress.ofNat (calldataWord I.calldata 36).toNat = evm.executionEnv.source) : - evalExpr? config { contract := contract, locals := tlcRenounceRoleStore I } evm - (.binary .eq (.var "callerConfirmation") sender) = .ok (.bool true) := by - have hcc : (tlcRenounceRoleStore I).get? "callerConfirmation" - = some (.address (AccountAddress.ofNat (calldataWord I.calldata 36).toNat)) := by - simp [tlcRenounceRoleStore] - simp only [sender, evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, hcc, envValue, - evalBinaryOp?, hself, beq_self_eq_true] - -/-- The `callerConfirmation == msg.sender` guard evaluates to `false` when it is not. -/ -theorem tlcRenounceRoleGuardEvalFalse (evm : EVM.State) (I : ExecutionEnv) - (hself : ¬ AccountAddress.ofNat (calldataWord I.calldata 36).toNat = evm.executionEnv.source) : - evalExpr? config { contract := contract, locals := tlcRenounceRoleStore I } evm - (.binary .eq (.var "callerConfirmation") sender) = .ok (.bool false) := by - have hcc : (tlcRenounceRoleStore I).get? "callerConfirmation" - = some (.address (AccountAddress.ofNat (calldataWord I.calldata 36).toNat)) := by - simp [tlcRenounceRoleStore] - simp only [sender, evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, hcc, envValue, - evalBinaryOp?] - rw [show ((Value.address (AccountAddress.ofNat (calldataWord I.calldata 36).toNat)) - == (Value.address evm.executionEnv.source)) = false from by - simp only [beq_eq_false_iff_ne, ne_eq, Value.address.injEq]; exact hself] - -/-- The `_roles[role].hasRole[callerConfirmation]` storage read (the `.ite` condition). -/ -theorem tlcRenounceRoleHasRoleEval {cA gh bl σ σ₀ A I} {g : Sat256} (hsz36 : 36 ≤ I.calldata.size) : - evalExpr? config { contract := contract, locals := tlcRenounceRoleStore I } - (initState cA gh bl σ σ₀ g A I) - (hasRoleExpr (.var "role") (.var "callerConfirmation")) - = .ok (Solm.wordToElem .bool (UInt256.land (tlcRenounceRoleWord σ I) ⟨255⟩)) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hslot : roleHasRoleSlot (tlcHasRoleRoleKey I) (tlcHasRoleAccountKey I) = tlcRenounceRoleSlot I := - tlcHasRoleSlot_eq I hsz36 - have hstore : Solm.EVM.storageLoad (initState cA gh bl σ σ₀ g A I) - (initState cA gh bl σ σ₀ g A I).executionEnv.codeOwner (tlcRenounceRoleSlot I) - = tlcRenounceRoleWord σ I := - codeOwnerStorageWord_initState (tlcRenounceRoleSlot I) - refine evalExpr_storage_scalar_value (cfg := config) - (solm := { contract := contract, locals := tlcRenounceRoleStore I }) - (slot := roleHasRoleRef (.var "role") (.var "callerConfirmation")) - (er := ({ base := "_roles", steps := [.mindex (tlcHasRoleRoleKey I), .field "hasRole", - .mindex (tlcHasRoleAccountKey I)] } : EvaledStorageRef)) - (t := .bool) - (loc := boolLoc (roleHasRoleSlot (tlcHasRoleRoleKey I) (tlcHasRoleAccountKey I))) - (value := Solm.wordToElem .bool (UInt256.land (tlcRenounceRoleWord σ I) ⟨255⟩)) ?_ ?_ ?_ ?_ ?_ - · simp only [roleHasRoleRef]; exact tlcRenounceRoleStore_get_roles I - · simp [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, roleHasRoleRef, - tlcRenounceRoleStore_index_role, tlcHasRoleAccountKey, valueToKey?, - hlen, abiBytes32Width, EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?] - · simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, roleDataSt, boolSt] - · rfl - · rw [hslot] - show storageLocLoad (initState cA gh bl σ σ₀ g A I) (boolOffset0Loc (tlcRenounceRoleSlot I)) = _ - rw [storageLocLoad_bool_offset0, hstore] - -/-- The `_roles[role].hasRole[callerConfirmation] = false` nested storage write collapses to a single - bool `storageStore` on the nested slot. -/ -theorem tlcRenounceRoleAssign {cA gh bl σ σ₀ A I} {g : Sat256} (hsz36 : 36 ≤ I.calldata.size) : - assignStorageRef? config { contract := contract, locals := tlcRenounceRoleStore I } - (initState cA gh bl σ σ₀ g A I) .storage - (roleHasRoleRef (.var "role") (.var "callerConfirmation")) (.bool false) - = .ok ({ contract := contract, locals := tlcRenounceRoleStore I }, - tlcRenounceRolePost (initState cA gh bl σ σ₀ g A I) I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hslot : roleHasRoleSlot (tlcHasRoleRoleKey I) (tlcHasRoleAccountKey I) = tlcRenounceRoleSlot I := - tlcHasRoleSlot_eq I hsz36 - have hstore : Solm.EVM.storageLoad (initState cA gh bl σ σ₀ g A I) - (initState cA gh bl σ σ₀ g A I).executionEnv.codeOwner (tlcRenounceRoleSlot I) - = tlcRenounceRoleWord σ I := - codeOwnerStorageWord_initState (tlcRenounceRoleSlot I) - refine assignStorageRef_storage_scalar_value (cfg := config) - (solm := { contract := contract, locals := tlcRenounceRoleStore I }) - (slot := roleHasRoleRef (.var "role") (.var "callerConfirmation")) - (er := ({ base := "_roles", steps := [.mindex (tlcHasRoleRoleKey I), .field "hasRole", - .mindex (tlcHasRoleAccountKey I)] } : EvaledStorageRef)) - (ty := boolSt) - (loc := boolLoc (roleHasRoleSlot (tlcHasRoleRoleKey I) (tlcHasRoleAccountKey I))) - (value := .bool false) ?_ ?_ ?_ ?_ (by trivial) ?_ - · simp only [roleHasRoleRef]; exact tlcRenounceRoleStore_get_roles I - · simp [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, roleHasRoleRef, - tlcRenounceRoleStore_index_role, tlcHasRoleAccountKey, valueToKey?, - hlen, abiBytes32Width, EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?] - · simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, roleDataSt, boolSt] - · rfl - · rw [hslot] - show storageLocStore (initState cA gh bl σ σ₀ g A I) (boolOffset0Loc (tlcRenounceRoleSlot I)) - (.bool false) = some (tlcRenounceRolePost (initState cA gh bl σ σ₀ g A I) I) - rw [storageLocStore_bool_false_offset0] - -/-- Happy path, role present: the body runs `require`s, takes the `.ite` `then` branch, and writes - `false`, falling through (`none`). -/ -theorem tlcRenounceRoleBodyPresent {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hself : AccountAddress.ofNat (calldataWord I.calldata 36).toNat = I.source) - (hpres : ¬ UInt256.land ⟨255⟩ (tlcRenounceRoleWord σ I) = ⟨0⟩) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcRenounceRoleStore I) - renounceRoleTransition.body - (.returned { contract := contract, locals := tlcRenounceRoleStore I } - (tlcRenounceRolePost (initState cA gh bl σ σ₀ g A I) I) none) := by - refine ExecFuncBody.execBlockOK ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true - (by simp only [initState]; exact hwv))) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (tlcRenounceRoleGuardEval _ I - (by simp only [initState]; exact hself))) ?_ - refine ExecBlock.consNormal (ExecStmt.iteTrue ?_ ?_) ExecBlock.nil - · rw [tlcRenounceRoleHasRoleEval hsz36, tlcRenounceRoleWordToElem_present hpres] - · exact ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) (tlcRenounceRoleAssign hsz36)) - ExecBlock.nil - -/-- Happy path, role absent: the body runs `require`s, takes the empty `.ite` `else` branch, and - falls through with the state unchanged (`none`). -/ -theorem tlcRenounceRoleBodyAbsent {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hself : AccountAddress.ofNat (calldataWord I.calldata 36).toNat = I.source) - (habs : UInt256.land ⟨255⟩ (tlcRenounceRoleWord σ I) = ⟨0⟩) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcRenounceRoleStore I) - renounceRoleTransition.body - (.returned { contract := contract, locals := tlcRenounceRoleStore I } - (initState cA gh bl σ σ₀ g A I) none) := by - refine ExecFuncBody.execBlockOK ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true - (by simp only [initState]; exact hwv))) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (tlcRenounceRoleGuardEval _ I - (by simp only [initState]; exact hself))) ?_ - refine ExecBlock.consNormal (ExecStmt.iteFalse ?_ ExecBlock.nil) ExecBlock.nil - rw [tlcRenounceRoleHasRoleEval hsz36, tlcRenounceRoleWordToElem_absent habs] - -/-- Confirmation mismatch: the body reverts at the `require(callerConfirmation == msg.sender)`. -/ -theorem tlcRenounceRoleBodyRevertConfirm {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hself : ¬ AccountAddress.ofNat (calldataWord I.calldata 36).toNat = I.source) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcRenounceRoleStore I) - renounceRoleTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true - (by simp only [initState]; exact hwv))) ?_ - exact ExecBlock.consRevert (ExecStmt.requireFalse (tlcRenounceRoleGuardEvalFalse _ I - (by simp only [initState]; exact hself))) - -/-- Refinement of `RenounceRole` (selector index 22). -/ -theorem tlcRenounceRoleBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 22)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 22) (by native_decide) hsel - have hword : tlcRenounceRoleWord σ_evm I = tlcRenounceRoleWord σ_solm I := by - simp only [tlcRenounceRoleWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner (tlcRenounceRoleSlot I) ⟨0⟩ - have henc : returnEquiv ByteArray.empty none renounceRoleTransition.returnType := by - simpa [renounceRoleTransition] using - (returnEquiv.fallthrough (o := ByteArray.empty) (r := none) (t := []) - (dvs := []) rfl (by native_decide) (by native_decide)) - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz68 : 68 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · by_cases hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus - · by_cases hconf : AccountAddress.ofNat (calldataWord I.calldata 36).toNat = I.source - · -- confirmation matches: both mutate (or no-op) the nested slot - obtain ⟨_, _, h1992⟩ := tlcRenounceRoleReach1992 (cA := cA) (gh := gh) (bl := bl) - (σ := σ_evm) (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) - hcode hwv hsz68 hbig hsize hsel hcanon - by_cases hpres : UInt256.land ⟨255⟩ (tlcRenounceRoleWord σ_evm I) = ⟨0⟩ - · -- role absent: no write on either side - exact tlcReEquivExecGen hcode - (tlcRenounceRoleX_absent h1992 hcanon hconf hpres) - (tlcSelectorDispatchRenounceRole hsel) (tlcDecodeRenounceRole_ok hsz68 hbig hcanon) - (tlcRenounceRoleBodyAbsent (σ := σ_solm) hwv - (by omega) hconf (by rw [← hword]; exact hpres)) - (by simp [initState]) - (by simpa [initState] using hAccounts) henc - · -- role present: both SSTORE `false` to the nested slot - refine tlcReEquivExecGen hcode - (tlcRenounceRoleX_present h1992 _hperm hcanon hconf hpres) - (tlcSelectorDispatchRenounceRole hsel) (tlcDecodeRenounceRole_ok hsz68 hbig hcanon) - (tlcRenounceRoleBodyPresent (σ := σ_solm) hwv - (by omega) hconf (by rw [← hword]; exact hpres)) - (by simp [tlcRenounceRolePost, initState, storageStore_createdAccounts]) ?_ henc - have hval : UInt256.land (UInt256.lnot ⟨255⟩) (tlcRenounceRoleWord σ_evm I) - = UInt256.land (tlcRenounceRoleWord σ_solm I) (UInt256.lnot ⟨255⟩) := by - rw [u256_land_comm, hword] - rw [hval] - simpa [tlcRenounceRolePost, initState, storageStore_accountMap, - codeOwnerStorageWord_initState] using - accountMapEquiv_sstoreAccountMap I.codeOwner (tlcRenounceRoleSlot I) - (UInt256.land (tlcRenounceRoleWord σ_solm I) (UInt256.lnot ⟨255⟩)) hAccounts - · -- confirmation mismatches: both revert - obtain ⟨_, _, h1992⟩ := tlcRenounceRoleReach1992 (cA := cA) (gh := gh) (bl := bl) - (σ := σ_evm) (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) - hcode hwv hsz68 hbig hsize hsel hcanon - exact tlcReEquivExecRev hcode (tlcRenounceRoleRevConfirm h1992 hcanon hconf) - (tlcSelectorDispatchRenounceRole hsel) (tlcDecodeRenounceRole_ok hsz68 hbig hcanon) - (tlcRenounceRoleBodyRevertConfirm (σ := σ_solm) hwv hconf) - · -- non-canonical confirmation: EVM reverts at the address check, Solm decode fails - exact tlcReEquivDecodeFailed hcode - (tlcRenounceRoleNoncanonRevert (g := Sat256.ofUInt256 g) hcode hwv hsz68 hbig hsize hsel - hcanon) - (tlcSelectorDispatchRenounceRole hsel) (tlcDecodeRenounceRole_none_noncanon hsz68 hbig - hcanon) - · -- huge calldata: EVM reverts at the length check, Solm decode fails - have hhuge : 2 ^ 255 + 4 ≤ I.calldata.size := Nat.not_lt.mp hbig - exact tlcReEquivDecodeFailed hcode - (tlcRenounceRoleDecodeRevert (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckHuge_4_64 hhuge hsize)) - (tlcSelectorDispatchRenounceRole hsel) (tlcDecodeRenounceRole_none_huge hhuge) - · -- short calldata: EVM reverts at the length check, Solm decode fails - have hshort : I.calldata.size < 68 := by omega - exact tlcReEquivDecodeFailed hcode - (tlcRenounceRoleDecodeRevert (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckShort_4_64 hsz hshort hsize)) - (tlcSelectorDispatchRenounceRole hsel) (tlcDecodeRenounceRole_none_short hsz hshort) - · -- nonpayable guard: callvalue ≠ 0 - obtain ⟨_, _, h851⟩ := tlcReachRenounceRole (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨862⟩) h851 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchRenounceRole hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Return.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Return.lean deleted file mode 100644 index 1e30a8ab..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Return.lean +++ /dev/null @@ -1,55 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch - -/-! -# OpenZeppelin TimelockController shared return routines - -`tlcReturnWord` is solc 0.8.35's split 32-byte return encoder (store `val` at the free pointer @581, -jump to the return dispatcher @521, `RETURN(0x80, 0x20)`). Shared by every `uint256` / `bytes32` -getter. (The library's single-block `RD.solcReturnWordFromMem` does not match this split shape.) - -LIBRARY CANDIDATE: `Reasoning.Solc` — split-encoder analogue of `RD.solcReturnWordFromMem`. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- Shared 32-byte return encoder: from pc 581 with `[val, cont, R]` and the free-pointer memory, - store `val` at 0x80 (@581), jump to the return dispatcher (@521), and `RETURN(0x80, 0x20)` the - 32 bytes of `val`. Used by every `uint256` / `bytes32` getter. -/ -theorem tlcReturnWord {cA gh bl σ σ₀ A I} {g : Sat256} {val cont : UInt256} {R : List UInt256} - {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨581⟩ - (val :: cont :: R) solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hov : R.length + 5 ≤ 1024) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray val) := by - have h521 := h.jumpdest (by native_decide) (by simp only [List.length_cons]; omega) - |>.push1 ⟨64⟩ (by native_decide) (by simp only [List.length_cons]; omega) - |>.mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost solcFreePtrMem_mload64 - (by decide) (by evm_ov) - |>.swap1 (by native_decide) (by simp only [List.length_cons]; omega) - |>.dup2 (by native_decide) (by simp only [List.length_cons]; omega) - |>.mstore 6 (solcReturnMem val) (UInt256.ofNat 5) (by native_decide) mem_cost - (by rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide]; rfl) (by decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by simp only [List.length_cons]; omega) - |>.add (by native_decide) (by simp only [List.length_cons]; omega) - |>.push2 ⟨521⟩ (by native_decide) (by simp only [List.length_cons]; omega) - |>.jump (by native_decide) (by jump_dest) (by simp only [List.length_cons]; omega) - have hret := h521.jumpdest (by native_decide) (by simp only [List.length_cons]; omega) - |>.push1 ⟨64⟩ (by native_decide) (by simp only [List.length_cons]; omega) - |>.mload 0 ⟨128⟩ (UInt256.ofNat 5) (by native_decide) mem_cost (solcReturnMem_mload64 val) - (by decide) (by evm_ov) - |>.dup1 (by native_decide) (by simp only [List.length_cons]; omega) - |>.swap2 (by native_decide) (by simp only [List.length_cons]; omega) - |>.sub (by native_decide) (by simp only [List.length_cons]; omega) - |>.swap1 (by native_decide) (by simp only [List.length_cons]; omega) - exact hret.ret 0 (UInt256.toByteArray val) (by native_decide) mem_cost - (by rw [show ((⟨32⟩ + ⟨128⟩ : UInt256).sub ⟨128⟩).toNat = 32 from by decide, - show (⟨128⟩ : UInt256).toNat = 128 from by decide]; exact solcReturnMem_read128 val) - (by simp only [List.length_cons]; omega) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/RevokeRole.lean b/Benchmarks/OpenZeppelinBench/TimelockController/RevokeRole.lean deleted file mode 100644 index 7cdeaaa2..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/RevokeRole.lean +++ /dev/null @@ -1,1033 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.RenounceRole -import Benchmarks.OpenZeppelinBench.TimelockController.GetRoleAdmin -import Benchmarks.OpenZeppelinBench.TimelockController.HasRole -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `revokeRole(bytes32,address)` refinement - -`revokeRole` (selector index 23, dispatch group G51 arm 0, body pc 1350) is `renounceRole` plus an -`onlyRole(getRoleAdmin(role))` admin check. It decodes `(bytes32 role, address account)` via the -shared two-arg decoder `@4999` (continuations `476`/`1376`, body-logic `@3040`), reads -`_roles[role].adminRole` (`keccak(role‖0)+1; SLOAD`), enforces `require(hasRole(adminRole, msg.sender))` -via the shared onlyRole helper `@3461→@3655→@2762`, then calls the inlined `_revokeRole @4096` (the -SAME helper `renounceRole` uses): it clears `_roles[role].hasRole[account]` only if currently present. - -The admin read dirties the keccak scratch, so the two `@2762` nested-slot loads (onlyRole and the -`_revokeRole` write) run over a *non-`solcFreePtrMem`* memory; `tlcRevokeRoleSlotLoadGen` is the -memory-generic form of `HasRole.tlcHasRoleSlotLoad` used for both. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Decoded data, slots, and stored words (shared with `hasRole`) -/ - -/-- The `_roles[role].adminRole` word (mapping slot `keccak(role ‖ 0)`, struct offset `+1`). -/ -abbrev tlcRevokeRoleAdminWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (roleAdminSlot (tlcHasRoleRoleKey I)) - -/-- The onlyRole nested slot `keccak(msg.sender ‖ keccak(adminRole ‖ 0))`. -/ -abbrev tlcRevokeRoleAdminSlot (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcMappingSlot (solcMappingSlot ⟨0⟩ (tlcRevokeRoleAdminWord σ I)) - (UInt256.land solcAddrMask (solcSourceWord I)) - -/-- The stored `_roles[adminRole].hasRole[msg.sender]` word (the onlyRole check reads its low byte). -/ -abbrev tlcRevokeRoleAdminHasRoleWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (tlcRevokeRoleAdminSlot σ I) - -/-- The runtime computes the admin slot as `1 + keccak(role ‖ 0)`; it equals `roleAdminSlot role`. -/ -theorem tlcRevokeRoleAdminSlot_eq (I : ExecutionEnv) (hsz36 : 36 ≤ I.calldata.size) : - (⟨1⟩ : UInt256) + solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4) - = roleAdminSlot (tlcHasRoleRoleKey I) := by - have hbaseslot : solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4) - = roleDataSlot (tlcHasRoleRoleKey I) := by - unfold roleDataSlot mapSlot solcMappingSlot - rw [tlcHasRoleRoleKey_eq I hsz36] - rw [hbaseslot] - exact tlcOneAddEqAddSlot (roleDataSlot (tlcHasRoleRoleKey I)) - -/-! ## ABI decode (two-arg `(bytes32, address)`, shared decoder; produces `tlcHasRoleStore`) -/ - -theorem tlcDecodeRevokeRole_ok {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (revokeRoleTransition.params.map Param.name) - (transitionSignature revokeRoleTransition).paramTypes I.calldata = some (tlcHasRoleStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "account"] [bytes32, addr] I.calldata = _ - exact decodeCalldata_bytes32_address_ok hsz68 hbig hcanon - -theorem tlcDecodeRevokeRole_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 68) : - decodeCalldataWithMode config.abiDecodeMode (revokeRoleTransition.params.map Param.name) - (transitionSignature revokeRoleTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "account"] [bytes32, addr] I.calldata = none - exact decodeCalldata_bytes32_address_none_short hsz4 hshort - -theorem tlcDecodeRevokeRole_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (revokeRoleTransition.params.map Param.name) - (transitionSignature revokeRoleTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "account"] [bytes32, addr] I.calldata = none - exact decodeCalldata_bytes32_address_none_huge hbig - -theorem tlcDecodeRevokeRole_none_noncanon {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hnc : ¬ (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - decodeCalldataWithMode config.abiDecodeMode (revokeRoleTransition.params.map Param.name) - (transitionSignature revokeRoleTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["role", "account"] [bytes32, addr] I.calldata = none - exact decodeCalldata_bytes32_address_none_noncanon hsz68 hbig hnc - -/-! ## Memory-generic nested-mapping slot load @2762 - - The `HasRole.tlcHasRoleSlotLoad` proof only reads memory in `[0,0x40)` (which it overwrites) via - `.size` facts, so it lifts verbatim to any 96-byte input `mem`. Needed because the admin read - leaves `twoWordHashMem …` (not `solcFreePtrMem`) before the two onlyRole/write `@2762` calls. -/ -theorem tlcRevokeRoleSlotLoadGen {cA gh bl σ σ₀ A I} {g : Sat256} - {account role cont : UInt256} {R : List UInt256} {mem rdata : ByteArray} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2762⟩ - (account :: role :: cont :: R) mem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hmem : mem.size = 96) - (hret : (D_J timelockControllerBenchBytecode 0).contains cont = true) - (hov : R.length + 12 ≤ 1024) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) cont - (UInt256.land ⟨255⟩ - (solcSlotWord σ I - (solcMappingSlot (solcMappingSlot ⟨0⟩ role) (UInt256.land solcAddrMask account))) :: R) - (twoWordHashMem (UInt256.land solcAddrMask account) (solcMappingSlot ⟨0⟩ role) - (twoWordHashMem role ⟨0⟩ mem)) (UInt256.ofNat 3) rdata (cA, σ) k' C' := by - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by decide - have hkec := h.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.mstore 0 (wordAt0Mem role mem) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rfl) (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.mstore 0 (twoWordHashMem role ⟨0⟩ mem) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rfl) (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.keccak256 0 (solcMappingSlot ⟨0⟩ role) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact twoWordHashMem_solcMappingSlot ⟨0⟩ role hmem) - (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨160⟩ (by native_decide) (by evm_ov) - |>.shl (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.swap4 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.swap4 (by native_decide) (by evm_ov) - |>.and (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.mstore 0 - (wordAt0Mem (UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) account) - (twoWordHashMem role ⟨0⟩ mem)) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rfl) (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.mstore 0 - (twoWordHashMem (UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) account) - (solcMappingSlot ⟨0⟩ role) (twoWordHashMem role ⟨0⟩ mem)) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.keccak256 0 - (solcMappingSlot (solcMappingSlot ⟨0⟩ role) - (UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) account)) - (UInt256.ofNat 3) (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact twoWordHashMem_solcMappingSlot (solcMappingSlot ⟨0⟩ role) - (UInt256.land (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) account) - (twoWordHashMem_size_96 role ⟨0⟩ hmem)) - (by native_decide) (by evm_ov) - obtain ⟨_, _, hsl⟩ := hkec.sload (by native_decide) (by evm_ov) - have hfin := hsl.push1 ⟨255⟩ (by native_decide) (by evm_ov) - |>.and (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.jump (by native_decide) hret (by evm_ov) - exact ⟨_, _, by simpa only [hmask] using hfin⟩ - -/-! ## EVM: reach the body @1350 and run the shared two-arg decoder -/ - -/-- Reach the `revokeRole` body pc 1350 (G51 arm 0). -/ -theorem tlcReachRevokeRole {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 23)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1350⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0xd547741f⟩ := - solcSelectorWord_eq_of_beq I hsz 0xd5 0x47 0x74 0x1f ⟨0xd547741f⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG51Body 0 (by omega) ⟨1350⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; exact absurd hj (Nat.not_lt_zero j)) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Peel the non-payable guard (gt @1361), push continuations `[476, 1376]`, and run the two-arg - decoder prologue to the `SLT` length-check `JUMPI` @5012. -/ -theorem tlcRevokeRoleReachLenCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 23)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨5012⟩ - [⟨5016⟩, UInt256.isZero (UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩), - ⟨0⟩, ⟨0⟩, ⟨4⟩, UInt256.ofNat I.calldata.size, ⟨1376⟩, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h1350⟩ := tlcReachRevokeRole (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz hsize hsel - obtain ⟨_, _, h1363⟩ := tlcGuardPeelOk (gt := ⟨1361⟩) h1350 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, h1363.push2 ⟨476⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨1376⟩ (by native_decide) (by evm_ov) - |>.calldatasize (by native_decide) (by evm_ov) - |>.push1 ⟨4⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨4999⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - |>.dup6 (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.slt (by native_decide) (by evm_ov) - |>.iszero (by native_decide) (by evm_ov) - |>.push2 ⟨5016⟩ (by native_decide) (by evm_ov)⟩ - -/-- After the length check passes, run the decoder to the address canonicality `EQ`/`JUMPI` @4374. -/ -theorem tlcRevokeRoleReachEqCheck {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 23)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4374⟩ - [⟨4378⟩, - UInt256.eq (calldataWord I.calldata 36) - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)), - calldataWord I.calldata 36, ⟨36⟩, ⟨5032⟩, ⟨0⟩, calldataWord I.calldata 4, ⟨4⟩, - UInt256.ofNat I.calldata.size, ⟨1376⟩, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = ⟨0⟩ := - solcDecodeLenCheckOk_4_64 hsz68 hbig hsize - obtain ⟨_, _, h5012⟩ := tlcRevokeRoleReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv (by omega) hsize hsel - have hoff : (⟨4⟩ : UInt256) + ⟨32⟩ = ⟨36⟩ := by decide - have hafterAdd := h5012.jumpiT (by native_decide) (by rw [hslt]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.push2 ⟨5032⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup5 (by native_decide) (by evm_ov) - |>.add (by native_decide) (by evm_ov) - rw [hoff] at hafterAdd - exact ⟨_, _, hafterAdd.push2 ⟨4356⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.calldataload (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨160⟩ (by native_decide) (by evm_ov) - |>.shl (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.and (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.eq (by native_decide) (by evm_ov) - |>.push2 ⟨4378⟩ (by native_decide) (by evm_ov)⟩ - -/-- With a canonical account, finish the decoder and jump through `@1376` into the body logic `@3040`, - leaving `[account, role, 476, sel]` over `solcFreePtrMem`. -/ -theorem tlcRevokeRoleReach3040 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 23)) - (hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3040⟩ - [calldataWord I.calldata 36, calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by decide - obtain ⟨_, _, h4374⟩ := tlcRevokeRoleReachEqCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv hsz68 hbig hsize hsel - exact ⟨_, _, h4374.jumpiT (by native_decide) - (by rw [hmask, solcAddrCanon_eq hcanon]; decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨3040⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov)⟩ - -/-! ## Memory chain across the admin read and the two nested-slot loads -/ - -/-- Memory after the admin `keccak(role‖0)` (before the onlyRole `@2762` load). -/ -noncomputable abbrev tlcRevokeRoleMem1 (I : ExecutionEnv) : ByteArray := - twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ solcFreePtrMem - -/-- Memory after the onlyRole `@2762` load (before the `_revokeRole @2762` write load). -/ -noncomputable abbrev tlcRevokeRoleOnlyMem (σ : AccountMap) (I : ExecutionEnv) : ByteArray := - twoWordHashMem (UInt256.land solcAddrMask (solcSourceWord I)) - (solcMappingSlot ⟨0⟩ (tlcRevokeRoleAdminWord σ I)) - (twoWordHashMem (tlcRevokeRoleAdminWord σ I) ⟨0⟩ (tlcRevokeRoleMem1 I)) - -theorem tlcRevokeRoleMem1_size (I : ExecutionEnv) : (tlcRevokeRoleMem1 I).size = 96 := - twoWordHashMem_size_96 _ _ solcFreePtrMem_size - -theorem tlcRevokeRoleMem1_read64 (I : ExecutionEnv) : - (tlcRevokeRoleMem1 I).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := - twoWordHashMem_read64 _ _ solcFreePtrMem_size solcFreePtrMem_read64 - -theorem tlcRevokeRoleOnlyMem_size (σ : AccountMap) (I : ExecutionEnv) : - (tlcRevokeRoleOnlyMem σ I).size = 96 := - twoWordHashMem_size_96 _ _ (twoWordHashMem_size_96 _ _ (tlcRevokeRoleMem1_size I)) - -theorem tlcRevokeRoleOnlyMem_read64 (σ : AccountMap) (I : ExecutionEnv) : - (tlcRevokeRoleOnlyMem σ I).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := - twoWordHashMem_read64 _ _ (twoWordHashMem_size_96 _ _ (tlcRevokeRoleMem1_size I)) - (twoWordHashMem_read64 _ _ (tlcRevokeRoleMem1_size I) (tlcRevokeRoleMem1_read64 I)) - -/-! ## EVM: admin read `_roles[role].adminRole` + onlyRole nested-slot load, reaching @3665 -/ - -/-- From body-logic `@3040`, compute `adminRole = _roles[role].adminRole` (`keccak(role‖0)+1; SLOAD`), - dispatch through the onlyRole helpers `@3461→@3655`, and run the shared `@2762` load for - `_roles[adminRole].hasRole[msg.sender]`, reaching the `if authorized` `JUMPI` @3665 with the - masked admin-hasRole bit on top. -/ -theorem tlcRevokeRoleReachAdminBit {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3040⟩ - [calldataWord I.calldata 36, calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hsz36 : 36 ≤ I.calldata.size) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3665⟩ - [UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I), solcSourceWord I, - tlcRevokeRoleAdminWord σ I, ⟨3471⟩, tlcRevokeRoleAdminWord σ I, ⟨3066⟩, - tlcRevokeRoleAdminWord σ I, calldataWord I.calldata 36, calldataWord I.calldata 4, - ⟨476⟩, tlcSelWord I] - (tlcRevokeRoleOnlyMem σ I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - have hk := h.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.mstore 0 (wordAt0Mem (calldataWord I.calldata 4) solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.mstore 0 (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ solcFreePtrMem) (UInt256.ofNat 3) - (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.keccak256 0 (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) (UInt256.ofNat 3) - (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact twoWordHashMem_solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4) solcFreePtrMem_size) - (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.add (by native_decide) (by evm_ov) - obtain ⟨_, _, hsl⟩ := hk.sload (by native_decide) (by evm_ov) - rw [tlcRevokeRoleAdminSlot_eq I hsz36] at hsl - have h2762 := hsl.push2 ⟨3066⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.push2 ⟨3461⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨3471⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.caller (by native_decide) (by evm_ov) - |>.push2 ⟨3655⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨3665⟩ (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.push2 ⟨2762⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - exact tlcRevokeRoleSlotLoadGen h2762 (tlcRevokeRoleMem1_size I) (by jump_dest) (by evm_ov) - -/-! ## EVM: onlyRole revert (`AccessControlUnauthorizedAccount`), @3665 → @2157 REVERT - - Error scratch: selector `@0x80`, masked `msg.sender` `@0x84`, `adminRole` `@0xa4` — writes at - 128/132/164 over the onlyRole memory (free pointer `@0x40` intact). -/ - -/-- Error scratch after the selector `MSTORE @0x80`. -/ -noncomputable abbrev tlcRevokeRoleErr1 (v : UInt256) (σ : AccountMap) (I : ExecutionEnv) : ByteArray := - (UInt256.toByteArray v).write 0 (tlcRevokeRoleOnlyMem σ I) 128 32 - -/-- Error scratch after the masked-sender `MSTORE @0x84`. -/ -noncomputable abbrev tlcRevokeRoleErr2 (v w : UInt256) (σ : AccountMap) (I : ExecutionEnv) : ByteArray := - (UInt256.toByteArray w).write 0 (tlcRevokeRoleErr1 v σ I) 132 32 - -/-- Error scratch after the `adminRole` `MSTORE @0xa4`. -/ -noncomputable abbrev tlcRevokeRoleErr3 (v w x : UInt256) (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - (UInt256.toByteArray x).write 0 (tlcRevokeRoleErr2 v w σ I) 164 32 - -theorem tlcRevokeRoleErr1_size (v : UInt256) (σ : AccountMap) (I : ExecutionEnv) : - (tlcRevokeRoleErr1 v σ I).size = 160 := by - unfold tlcRevokeRoleErr1 - rw [toByteArray_write_eq _ _ _ (by rw [tlcRevokeRoleOnlyMem_size]; omega) - (by rw [tlcRevokeRoleOnlyMem_size]; exact lt_usize _ (by norm_num)), - ByteArray.size_append, ByteArray.size_append, tlcRevokeRoleOnlyMem_size, ByteArray_zeroes_size, - show (USize.ofNat (128 - 96)).toNat = 32 from USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num)), - toByteArray_size] - -theorem tlcRevokeRoleErr2_size (v w : UInt256) (σ : AccountMap) (I : ExecutionEnv) : - (tlcRevokeRoleErr2 v w σ I).size = 164 := by - unfold tlcRevokeRoleErr2 - exact toByteArray_write32_size_of_le (tlcRevokeRoleErr1 v σ I) w 132 160 164 - (tlcRevokeRoleErr1_size v σ I) (by rw [tlcRevokeRoleErr1_size]; omega) (by decide) - -theorem tlcRevokeRoleErr3_size (v w x : UInt256) (σ : AccountMap) (I : ExecutionEnv) : - (tlcRevokeRoleErr3 v w x σ I).size = 196 := by - unfold tlcRevokeRoleErr3 - exact toByteArray_write32_size_of_le (tlcRevokeRoleErr2 v w σ I) x 164 164 196 - (tlcRevokeRoleErr2_size v w σ I) (by rw [tlcRevokeRoleErr2_size]) (by decide) - -theorem tlcRevokeRoleErr3_read64 (v w x : UInt256) (σ : AccountMap) (I : ExecutionEnv) : - (tlcRevokeRoleErr3 v w x σ I).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by - unfold tlcRevokeRoleErr3 - rw [write32_read_below _ _ 164 64 (by rw [toByteArray_size]) (by rw [tlcRevokeRoleErr2_size]) - (by omega)] - unfold tlcRevokeRoleErr2 - rw [write32_read_below _ _ 132 64 (by rw [toByteArray_size]) (by rw [tlcRevokeRoleErr1_size]; omega) - (by omega)] - unfold tlcRevokeRoleErr1 - rw [toByteArray_write_read_below_of_gap _ _ 128 64 (by rw [tlcRevokeRoleOnlyMem_size]) - (by omega) (by rw [tlcRevokeRoleOnlyMem_size]; exact lt_usize _ (by norm_num))] - exact tlcRevokeRoleOnlyMem_read64 σ I - -/-- `msg.sender` lacks `adminRole` (`land 0xff` of the admin-hasRole word is `0`): the onlyRole `JUMPI` - is not taken, the `AccessControlUnauthorizedAccount(sender, adminRole)` error is built, and `@2157` - `REVERT`s. -/ -theorem tlcRevokeRoleRevAdmin {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3665⟩ - [UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I), solcSourceWord I, - tlcRevokeRoleAdminWord σ I, ⟨3471⟩, tlcRevokeRoleAdminWord σ I, ⟨3066⟩, - tlcRevokeRoleAdminWord σ I, calldataWord I.calldata 36, calldataWord I.calldata 4, - ⟨476⟩, tlcSelWord I] - (tlcRevokeRoleOnlyMem σ I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hunauth : UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have h2165 := evm_run h with [ - jumpdest, - push2 ⟨3712⟩, - jumpiNT (by exact hunauth), - push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [tlcRevokeRoleOnlyMem_size]; decide) (by decide) - (tlcRevokeRoleOnlyMem_read64 σ I)) (by native_decide) (by evm_ov), - raw push4 ⟨0xe2517d3f⟩ (by native_decide) (by evm_ov), - push1 ⟨224⟩, shl, dup2, - raw mstore 6 (tlcRevokeRoleErr1 _ σ I) (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, - push1 ⟨4⟩, dup3, add, - raw mstore 3 (tlcRevokeRoleErr2 _ _ σ I) (UInt256.ofNat 6) (by native_decide) mem_cost - (by rw [show (⟨128⟩ + ⟨4⟩ : UInt256).toNat = 132 from by native_decide]) - (by native_decide) (by evm_ov), - push1 ⟨36⟩, dup2, add, dup4, swap1, - raw mstore 3 (tlcRevokeRoleErr3 _ _ _ σ I) (UInt256.ofNat 7) (by native_decide) mem_cost - (by rw [show (⟨128⟩ + ⟨36⟩ : UInt256).toNat = 164 from by native_decide]) - (by native_decide) (by evm_ov), - push1 ⟨68⟩, add, push2 ⟨2157⟩, jump (by jump_dest), - jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 7) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [tlcRevokeRoleErr3_size]; decide) (by decide) - (tlcRevokeRoleErr3_read64 _ _ _ σ I)) (by native_decide) (by evm_ov), - dup1, swap2, sub, swap1 ] - exact h2165.rev 0 (by native_decide) mem_cost (by evm_ov) - -/-! ## EVM: authorized path — `_revokeRole @4096` conditional clear of `_roles[role].hasRole[account]` -/ - -/-- Memory after the `_revokeRole @2762` write-slot load (`@4107`). -/ -noncomputable abbrev tlcRevokeRoleWriteMem (σ : AccountMap) (I : ExecutionEnv) : ByteArray := - twoWordHashMem (UInt256.land solcAddrMask (calldataWord I.calldata 36)) - (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRevokeRoleOnlyMem σ I)) - -/-- `msg.sender` has `adminRole`: take the onlyRole `JUMPI`, dispatch to `_revokeRole @4096`, and run - the shared `@2762` load for `_roles[role].hasRole[account]`, reaching the `if present` `ISZERO/JUMPI` - @4107 with the masked stored word on top. -/ -theorem tlcRevokeRoleReach4107 {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3665⟩ - [UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I), solcSourceWord I, - tlcRevokeRoleAdminWord σ I, ⟨3471⟩, tlcRevokeRoleAdminWord σ I, ⟨3066⟩, - tlcRevokeRoleAdminWord σ I, calldataWord I.calldata 36, calldataWord I.calldata 4, - ⟨476⟩, tlcSelWord I] - (tlcRevokeRoleOnlyMem σ I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hauth : ¬ UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4107⟩ - [UInt256.land ⟨255⟩ (tlcHasRoleWord σ I), ⟨0⟩, calldataWord I.calldata 36, - calldataWord I.calldata 4, ⟨1950⟩, tlcRevokeRoleAdminWord σ I, calldataWord I.calldata 36, - calldataWord I.calldata 4, ⟨476⟩, tlcSelWord I] - (tlcRevokeRoleWriteMem σ I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k' C' := by - have h2762 := h.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨3712⟩ (by native_decide) (by evm_ov) - |>.jumpiT (by native_decide) (by exact hauth) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push2 ⟨1950⟩ (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - |>.push2 ⟨4096⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.push2 ⟨4107⟩ (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - |>.push2 ⟨2762⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - exact tlcRevokeRoleSlotLoadGen h2762 (tlcRevokeRoleOnlyMem_size σ I) (by jump_dest) (by evm_ov) - -/-- Role absent (`_roles[role].hasRole[account]` already `false`): `_revokeRole` skips at `@4089`, - does no `SSTORE`/`LOG`, and `STOP`s with the account map unchanged. -/ -theorem tlcRevokeRoleXAbsent {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3665⟩ - [UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I), solcSourceWord I, - tlcRevokeRoleAdminWord σ I, ⟨3471⟩, tlcRevokeRoleAdminWord σ I, ⟨3066⟩, - tlcRevokeRoleAdminWord σ I, calldataWord I.calldata 36, calldataWord I.calldata 4, - ⟨476⟩, tlcSelWord I] - (tlcRevokeRoleOnlyMem σ I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hauth : ¬ UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) - (habsent : UInt256.land ⟨255⟩ (tlcHasRoleWord σ I) = ⟨0⟩) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - ByteArray.empty := by - obtain ⟨_, _, h4107⟩ := tlcRevokeRoleReach4107 h hauth - have h476 := evm_run h4107 with [ - jumpdest, - iszero, push2 ⟨4089⟩, - jumpiT (by rw [habsent]; decide) (by jump_dest), - jumpdest, - pop, push0, push2 ⟨1685⟩, - jump (by jump_dest), - jumpdest, - swap3, swap2, pop, pop, - jump (by jump_dest), - jumpdest, - pop, pop, pop, pop, - jump (by jump_dest), - jumpdest ] - exact h476.stop (by native_decide) (by evm_ov) - -/-- Role present (`_roles[role].hasRole[account]` currently `true`): `_revokeRole` recomputes the - nested slot, `SSTORE`s `word & ~0xff` (clearing the bool to `false`), emits `RoleRevoked` `LOG4`, - and `STOP`s — halting with the account map carrying the single nested-slot write. -/ -theorem tlcRevokeRoleXPresent {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨3665⟩ - [UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I), solcSourceWord I, - tlcRevokeRoleAdminWord σ I, ⟨3471⟩, tlcRevokeRoleAdminWord σ I, ⟨3066⟩, - tlcRevokeRoleAdminWord σ I, calldataWord I.calldata 36, calldataWord I.calldata 4, - ⟨476⟩, tlcSelWord I] - (tlcRevokeRoleOnlyMem σ I) (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hperm : I.perm = true) - (hauth : ¬ UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) - (hpresent : ¬ UInt256.land ⟨255⟩ (tlcHasRoleWord σ I) = ⟨0⟩) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) - (cA, sstoreAccountMap I.codeOwner σ (tlcHasRoleSlot I) - (UInt256.land (UInt256.lnot ⟨255⟩) (tlcHasRoleWord σ I))) ByteArray.empty := by - obtain ⟨_, _, h4107⟩ := tlcRevokeRoleReach4107 h hauth - have hM0 : (tlcRevokeRoleWriteMem σ I).size = 96 := - twoWordHashMem_size_96 _ _ (twoWordHashMem_size_96 _ _ (tlcRevokeRoleOnlyMem_size σ I)) - have hM2 : (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRevokeRoleWriteMem σ I)).size = 96 := - twoWordHashMem_size_96 _ _ hM0 - have hM4size : (twoWordHashMem - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) - (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRevokeRoleWriteMem σ I))).size = 96 := - twoWordHashMem_size_96 _ _ hM2 - have hM4read64 : (twoWordHashMem - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) - (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRevokeRoleWriteMem σ I))).readWithPadding - 64 32 = UInt256.toByteArray ⟨128⟩ := - twoWordHashMem_read64 _ _ hM2 (twoWordHashMem_read64 _ _ hM0 - (twoWordHashMem_read64 _ _ (twoWordHashMem_size_96 _ _ (tlcRevokeRoleOnlyMem_size σ I)) - (twoWordHashMem_read64 _ _ (tlcRevokeRoleOnlyMem_size σ I) (tlcRevokeRoleOnlyMem_read64 σ I)))) - have hkec := evm_run h4107 with [ - jumpdest, - iszero, push2 ⟨4089⟩, - jumpiNT (by exact isZero_eq_zero_of_ne hpresent), - push0, dup4, dup2, - raw mstore 0 (wordAt0Mem (calldataWord I.calldata 4) (tlcRevokeRoleWriteMem σ I)) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨32⟩, dup2, dup2, - raw mstore 0 (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRevokeRoleWriteMem σ I)) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - push1 ⟨64⟩, dup1, dup4, - raw keccak256 0 (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) (UInt256.ofNat 3) - (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact twoWordHashMem_solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4) hM0) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup7, and, dup1, dup6, - raw mstore 0 (wordAt0Mem - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRevokeRoleWriteMem σ I))) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - swap3, - raw mstore 0 (twoWordHashMem - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) - (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (twoWordHashMem (calldataWord I.calldata 4) ⟨0⟩ (tlcRevokeRoleWriteMem σ I))) - (UInt256.ofNat 3) (by native_decide) mem_cost (by rfl) (by native_decide) (by evm_ov), - dup1, dup4, - raw keccak256 0 (tlcHasRoleSlot I) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact (twoWordHashMem_solcMappingSlot (solcMappingSlot ⟨0⟩ (calldataWord I.calldata 4)) - (UInt256.land (calldataWord I.calldata 36) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩)) hM2).trans - (tlcRenounceRoleOuterSlot I)) - (by native_decide) (by evm_ov), - dup1 ] - obtain ⟨_, _, hsl⟩ := hkec.sload (by native_decide) (by evm_ov) - have hsstorepre := evm_run hsl with [ push1 ⟨255⟩, not, and, swap1 ] - obtain ⟨_, _, hss⟩ := hsstorepre.sstore hperm (by native_decide) (by evm_ov) - have hlogpre := evm_run hss with [ - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [hM4size]; decide) (by decide) hM4read64) - (by native_decide) (by evm_ov), - raw caller (by native_decide) (by evm_ov), - swap3, dup7, swap2 ] - have hlog := (hlogpre.pushConst tlcRenounceRoleRevokedTopic (width := 32) (op := .PUSH32) - (by decide) (by native_decide) (by evm_ov)).swap2 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - have h476 := (hlog.log4 0 (UInt256.ofNat 3) (by native_decide) hperm mem_cost - (by native_decide) (by evm_ov)) |>.pop (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push2 ⟨1685⟩ (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.swap3 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.pop (by native_decide) (by evm_ov) - |>.jump (by native_decide) (by jump_dest) (by evm_ov) - |>.jumpdest (by native_decide) (by evm_ov) - exact h476.stop (by native_decide) (by evm_ov) - -/-! ## EVM decode-revert paths (shared two-arg decoder) -/ - -/-- Mis-sized calldata: the signed length check fails, falling into the decoder's `PUSH0 PUSH0 REVERT` - stub @5013. -/ -theorem tlcRevokeRoleDecodeRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 23)) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h5012⟩ := tlcRevokeRoleReachLenCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv hsz hsize hsel - exact h5012.jumpiNT (by native_decide) (by rw [hslt]; decide) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-- Non-canonical account: the sub-decoder's canonicality `EQ` fails, falling into the `PUSH0 PUSH0 - REVERT` stub @4375. -/ -theorem tlcRevokeRoleNoncanonRevert {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz68 : 68 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 23)) - (hnc : ¬ (calldataWord I.calldata 36).toNat < EVM.addressModulus) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by decide - obtain ⟨_, _, h4374⟩ := tlcRevokeRoleReachEqCheck (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv hsz68 hbig hsize hsel - exact h4374.jumpiNT (by native_decide) (by rw [hmask]; exact tlcHasRoleNoncanon_eq hnc) (by evm_ov) - |>.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-! ## Solm body - -The body is `nonpayable ++ [letDecl "adminRole" …, require (hasRole adminRole sender)] ++ -revokeRoleIfPresent role account`. After the `letDecl` the local store gains `adminRole`. -/ - -/-- The local store after the `letDecl "adminRole" := _roles[role].adminRole` binding. -/ -abbrev tlcRevokeRoleStore' (σ : AccountMap) (I : ExecutionEnv) : Store := - (tlcHasRoleStore I).insert "adminRole" - (.fixedBytes bytes32Width (EVM.Word.toBytesBE (tlcRevokeRoleAdminWord σ I))) - -theorem tlcRevokeRoleStore'_get_roles (σ : AccountMap) (I : ExecutionEnv) : - (tlcRevokeRoleStore' σ I).get? "_roles" = none := by - unfold tlcRevokeRoleStore' tlcHasRoleStore - rw [store_get_ne3 _ _ _ _ (by native_decide) (by native_decide) (by native_decide)] - simp - -theorem tlcRevokeRoleStore'_index_role (σ : AccountMap) (I : ExecutionEnv) : - (tlcRevokeRoleStore' σ I)["role"] = - Value.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32) := by - unfold tlcRevokeRoleStore' tlcHasRoleStore - rw [Std.HashMap.getElem_insert]; simp [tlcHasRoleStore_index_role] - -theorem tlcRevokeRoleStore'_index_account (σ : AccountMap) (I : ExecutionEnv) : - (tlcRevokeRoleStore' σ I)["account"] = - Value.address (AccountAddress.ofNat (calldataWord I.calldata 36).toNat) := by - unfold tlcRevokeRoleStore' tlcHasRoleStore - rw [Std.HashMap.getElem_insert]; simp - -theorem tlcRevokeRoleStore'_index_adminRole (σ : AccountMap) (I : ExecutionEnv) : - (tlcRevokeRoleStore' σ I)["adminRole"] = - Value.fixedBytes bytes32Width (EVM.Word.toBytesBE (tlcRevokeRoleAdminWord σ I)) := by - unfold tlcRevokeRoleStore' tlcHasRoleStore - rw [Std.HashMap.getElem_insert]; simp - -/-- The Solm onlyRole nested slot `_roles[adminRole].hasRole[msg.sender]` equals the runtime slot. -/ -theorem tlcRevokeRoleOnlyRoleSlot_eq (σ : AccountMap) (I : ExecutionEnv) : - roleHasRoleSlot (.fixedBytes bytes32Width (EVM.Word.toBytesBE (tlcRevokeRoleAdminWord σ I))) - (.address I.source) - = tlcRevokeRoleAdminSlot σ I := by - unfold tlcRevokeRoleAdminSlot roleHasRoleSlot roleDataSlot mapSlot solcMappingSlot - rw [show bytes32Width = (⟨31, by decide⟩ : Fin 32) from rfl, - keyValueToWord_fixedBytes32 (tlcRevokeRoleAdminWord σ I), keyValueToWord_address, - solcAddrMask_clean_left (solcSourceWord_canonical I)] - -/-- The `letDecl "adminRole"` reads `_roles[role].adminRole` as a `bytes32`. -/ -theorem tlcRevokeRoleLetDeclEval {cA gh bl σ σ₀ A I} {g : Sat256} (hsz36 : 36 ≤ I.calldata.size) : - evalExpr? config { contract := contract, locals := tlcHasRoleStore I } - (initState cA gh bl σ σ₀ g A I) (.storage (roleAdminRef (.var "role"))) - = .ok (.fixedBytes bytes32Width (EVM.Word.toBytesBE (tlcRevokeRoleAdminWord σ I))) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hvk : valueToKey? (Value.fixedBytes abiBytes32Width ((I.calldata.toList.drop 4).take 32)) - = some (tlcHasRoleRoleKey I) := by - simp [valueToKey?, tlcHasRoleRoleKey, abiBytes32Width, hlen] - rw [evalExpr_storage_scalar (cfg := config) - (solm := { contract := contract, locals := tlcHasRoleStore I }) - (slot := roleAdminRef (.var "role")) - (er := ({ base := "_roles", steps := [.mindex (tlcHasRoleRoleKey I), .field "adminRole"] } : - EvaledStorageRef)) - (t := .bytes bytes32Width) (loc := bytes32Loc (roleAdminSlot (tlcHasRoleRoleKey I))) - (hbase := by simp only [roleAdminRef]; exact tlcHasRoleStore_get_roles I) - (her := by - simp [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, roleAdminRef, - tlcHasRoleStore_index_role, EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?, hvk]) - (hty := by - simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, roleDataSt, - tlcHasRoleRoleKey, bytes32St]) - (hloc := by rfl)] - exact congrArg EvalResult.ok - (storageLocLoad_bytes32 (initState cA gh bl σ σ₀ g A I) (roleAdminSlot (tlcHasRoleRoleKey I))) - -/-- The onlyRole guard `hasRole(adminRole, msg.sender)` reads `_roles[adminRole].hasRole[sender]`. -/ -theorem tlcRevokeRoleOnlyRoleEval {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? config { contract := contract, locals := tlcRevokeRoleStore' σ I } - (initState cA gh bl σ σ₀ g A I) (hasRoleExpr (.var "adminRole") sender) - = .ok (Solm.wordToElem .bool - (UInt256.land (tlcRevokeRoleAdminHasRoleWord σ I) ⟨255⟩)) := by - have hstore : Solm.EVM.storageLoad (initState cA gh bl σ σ₀ g A I) - (initState cA gh bl σ σ₀ g A I).executionEnv.codeOwner (tlcRevokeRoleAdminSlot σ I) - = tlcRevokeRoleAdminHasRoleWord σ I := - codeOwnerStorageWord_initState (tlcRevokeRoleAdminSlot σ I) - refine evalExpr_storage_scalar_value (cfg := config) - (solm := { contract := contract, locals := tlcRevokeRoleStore' σ I }) - (slot := roleHasRoleRef (.var "adminRole") sender) - (er := ({ base := "_roles", steps := [.mindex - (.fixedBytes bytes32Width (EVM.Word.toBytesBE (tlcRevokeRoleAdminWord σ I))), - .field "hasRole", .mindex (.address I.source)] } : EvaledStorageRef)) - (t := .bool) - (loc := boolLoc (roleHasRoleSlot - (.fixedBytes bytes32Width (EVM.Word.toBytesBE (tlcRevokeRoleAdminWord σ I))) - (.address I.source))) - (value := Solm.wordToElem .bool (UInt256.land (tlcRevokeRoleAdminHasRoleWord σ I) ⟨255⟩)) - ?_ ?_ ?_ ?_ ?_ - · simp only [roleHasRoleRef]; exact tlcRevokeRoleStore'_get_roles σ I - · have hadminlen : (EVM.Word.toBytesBE (tlcRevokeRoleAdminWord σ I)).length = 32 := by - simpa using word_toBytesBE_toByteArray_size (tlcRevokeRoleAdminWord σ I) - simp [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, roleHasRoleRef, sender, - valueToKey?, envValue, initState, - bytes32Width, hadminlen, EvalResult.bind, EvalResult.ofOption, - bind, pure, evalExpr?] - · simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, roleDataSt, boolSt] - · rfl - · rw [tlcRevokeRoleOnlyRoleSlot_eq σ I] - show storageLocLoad (initState cA gh bl σ σ₀ g A I) (boolOffset0Loc (tlcRevokeRoleAdminSlot σ I)) - = _ - rw [storageLocLoad_bool_offset0, hstore] - -/-- `wordToElem .bool (word & 0xff)` is `true` exactly when the packed byte is nonzero. -/ -theorem tlcRevokeRoleWordToElem_present {σ : AccountMap} {I : ExecutionEnv} - (hpres : ¬ UInt256.land ⟨255⟩ (tlcHasRoleWord σ I) = ⟨0⟩) : - Solm.wordToElem .bool (UInt256.land (tlcHasRoleWord σ I) ⟨255⟩) = .bool true := by - have hz : UInt256.land (tlcHasRoleWord σ I) ⟨255⟩ ≠ ⟨0⟩ := by - rw [u256_land_comm]; exact hpres - by_cases hval : (UInt256.land (tlcHasRoleWord σ I) ⟨255⟩).val = 0 - · exact absurd (u256_inj (congrArg Fin.val hval)) hz - · simp [Solm.wordToElem, hval] - -/-- `wordToElem .bool (word & 0xff)` is `false` exactly when the packed byte is zero. -/ -theorem tlcRevokeRoleWordToElem_absent {σ : AccountMap} {I : ExecutionEnv} - (habs : UInt256.land ⟨255⟩ (tlcHasRoleWord σ I) = ⟨0⟩) : - Solm.wordToElem .bool (UInt256.land (tlcHasRoleWord σ I) ⟨255⟩) = .bool false := by - have hz : UInt256.land (tlcHasRoleWord σ I) ⟨255⟩ = ⟨0⟩ := by - rw [u256_land_comm]; exact habs - simp [Solm.wordToElem, hz] - -/-- The `_roles[role].hasRole[account]` storage read (the `.ite` condition), in the extended store. -/ -theorem tlcRevokeRoleHasRoleEval {cA gh bl σ σ₀ A I} {g : Sat256} (hsz36 : 36 ≤ I.calldata.size) : - evalExpr? config { contract := contract, locals := tlcRevokeRoleStore' σ I } - (initState cA gh bl σ σ₀ g A I) - (hasRoleExpr (.var "role") (.var "account")) - = .ok (Solm.wordToElem .bool (UInt256.land (tlcHasRoleWord σ I) ⟨255⟩)) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hslot : roleHasRoleSlot (tlcHasRoleRoleKey I) (tlcHasRoleAccountKey I) = tlcHasRoleSlot I := - tlcHasRoleSlot_eq I hsz36 - have hstore : Solm.EVM.storageLoad (initState cA gh bl σ σ₀ g A I) - (initState cA gh bl σ σ₀ g A I).executionEnv.codeOwner (tlcHasRoleSlot I) = tlcHasRoleWord σ I := - codeOwnerStorageWord_initState (tlcHasRoleSlot I) - refine evalExpr_storage_scalar_value (cfg := config) - (solm := { contract := contract, locals := tlcRevokeRoleStore' σ I }) - (slot := roleHasRoleRef (.var "role") (.var "account")) - (er := ({ base := "_roles", steps := [.mindex (tlcHasRoleRoleKey I), .field "hasRole", - .mindex (tlcHasRoleAccountKey I)] } : EvaledStorageRef)) - (t := .bool) - (loc := boolLoc (roleHasRoleSlot (tlcHasRoleRoleKey I) (tlcHasRoleAccountKey I))) - (value := Solm.wordToElem .bool (UInt256.land (tlcHasRoleWord σ I) ⟨255⟩)) ?_ ?_ ?_ ?_ ?_ - · simp only [roleHasRoleRef]; exact tlcRevokeRoleStore'_get_roles σ I - · simp [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, roleHasRoleRef, - tlcRevokeRoleStore'_index_role, tlcRevokeRoleStore'_index_account, tlcHasRoleAccountKey, - valueToKey?, hlen, abiBytes32Width, EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?] - · simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, roleDataSt, boolSt] - · rfl - · rw [hslot] - show storageLocLoad (initState cA gh bl σ σ₀ g A I) (boolOffset0Loc (tlcHasRoleSlot I)) = _ - rw [storageLocLoad_bool_offset0, hstore] - -/-- The `_roles[role].hasRole[account] = false` write collapses to a single bool `storageStore`. -/ -theorem tlcRevokeRoleAssign {cA gh bl σ σ₀ A I} {g : Sat256} (hsz36 : 36 ≤ I.calldata.size) : - assignStorageRef? config { contract := contract, locals := tlcRevokeRoleStore' σ I } - (initState cA gh bl σ σ₀ g A I) .storage - (roleHasRoleRef (.var "role") (.var "account")) (.bool false) - = .ok ({ contract := contract, locals := tlcRevokeRoleStore' σ I }, - tlcRenounceRolePost (initState cA gh bl σ σ₀ g A I) I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hslot : roleHasRoleSlot (tlcHasRoleRoleKey I) (tlcHasRoleAccountKey I) = tlcRenounceRoleSlot I := - tlcHasRoleSlot_eq I hsz36 - refine assignStorageRef_storage_scalar_value (cfg := config) - (solm := { contract := contract, locals := tlcRevokeRoleStore' σ I }) - (slot := roleHasRoleRef (.var "role") (.var "account")) - (er := ({ base := "_roles", steps := [.mindex (tlcHasRoleRoleKey I), .field "hasRole", - .mindex (tlcHasRoleAccountKey I)] } : EvaledStorageRef)) - (ty := boolSt) - (loc := boolLoc (roleHasRoleSlot (tlcHasRoleRoleKey I) (tlcHasRoleAccountKey I))) - (value := .bool false) ?_ ?_ ?_ ?_ (by trivial) ?_ - · simp only [roleHasRoleRef]; exact tlcRevokeRoleStore'_get_roles σ I - · simp [evalStorageRef, evalStorageRefSteps, evalStorageRefStep, roleHasRoleRef, - tlcRevokeRoleStore'_index_role, tlcRevokeRoleStore'_index_account, tlcHasRoleAccountKey, - valueToKey?, hlen, abiBytes32Width, EvalResult.bind, EvalResult.ofOption, bind, pure, evalExpr?] - · simp [storageTypeAt?, storageTypeStep?, contract, storageDecls, roleDataSt, boolSt] - · rfl - · rw [hslot] - show storageLocStore (initState cA gh bl σ σ₀ g A I) (boolOffset0Loc (tlcRenounceRoleSlot I)) - (.bool false) = some (tlcRenounceRolePost (initState cA gh bl σ σ₀ g A I) I) - rw [storageLocStore_bool_false_offset0] - -/-- The onlyRole admin bit is nonzero → the guard evaluates `true`. -/ -theorem tlcRevokeRoleAdminWordToElem_present {σ : AccountMap} {I : ExecutionEnv} - (hauth : ¬ UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) : - Solm.wordToElem .bool (UInt256.land (tlcRevokeRoleAdminHasRoleWord σ I) ⟨255⟩) = .bool true := by - have hz : UInt256.land (tlcRevokeRoleAdminHasRoleWord σ I) ⟨255⟩ ≠ ⟨0⟩ := by - rw [u256_land_comm]; exact hauth - by_cases hval : (UInt256.land (tlcRevokeRoleAdminHasRoleWord σ I) ⟨255⟩).val = 0 - · exact absurd (u256_inj (congrArg Fin.val hval)) hz - · simp [Solm.wordToElem, hval] - -/-- The onlyRole admin bit is zero → the guard evaluates `false`. -/ -theorem tlcRevokeRoleAdminWordToElem_absent {σ : AccountMap} {I : ExecutionEnv} - (hunauth : UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) : - Solm.wordToElem .bool (UInt256.land (tlcRevokeRoleAdminHasRoleWord σ I) ⟨255⟩) = .bool false := by - have hz : UInt256.land (tlcRevokeRoleAdminHasRoleWord σ I) ⟨255⟩ = ⟨0⟩ := by - rw [u256_land_comm]; exact hunauth - simp [Solm.wordToElem, hz] - -/-- Authorized + role present: the body clears the bit (`.ite` then-branch writes `false`). -/ -theorem tlcRevokeRoleBodyPresent {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hauth : ¬ UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) - (hpres : ¬ UInt256.land ⟨255⟩ (tlcHasRoleWord σ I) = ⟨0⟩) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcHasRoleStore I) - revokeRoleTransition.body - (.returned { contract := contract, locals := tlcRevokeRoleStore' σ I } - (tlcRenounceRolePost (initState cA gh bl σ σ₀ g A I) I) none) := by - refine ExecFuncBody.execBlockOK ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true - (by simp only [initState]; exact hwv))) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (tlcRevokeRoleLetDeclEval hsz36)) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue - (by rw [tlcRevokeRoleOnlyRoleEval, tlcRevokeRoleAdminWordToElem_present hauth])) ?_ - refine ExecBlock.consNormal (ExecStmt.iteTrue ?_ ?_) ExecBlock.nil - · rw [tlcRevokeRoleHasRoleEval hsz36, tlcRevokeRoleWordToElem_present hpres] - · exact ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) (tlcRevokeRoleAssign hsz36)) - ExecBlock.nil - -/-- Authorized + role absent: the body takes the empty `.ite` else-branch, state unchanged. -/ -theorem tlcRevokeRoleBodyAbsent {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hauth : ¬ UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) - (habs : UInt256.land ⟨255⟩ (tlcHasRoleWord σ I) = ⟨0⟩) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcHasRoleStore I) - revokeRoleTransition.body - (.returned { contract := contract, locals := tlcRevokeRoleStore' σ I } - (initState cA gh bl σ σ₀ g A I) none) := by - refine ExecFuncBody.execBlockOK ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true - (by simp only [initState]; exact hwv))) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (tlcRevokeRoleLetDeclEval hsz36)) ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue - (by rw [tlcRevokeRoleOnlyRoleEval, tlcRevokeRoleAdminWordToElem_present hauth])) ?_ - refine ExecBlock.consNormal (ExecStmt.iteFalse ?_ ExecBlock.nil) ExecBlock.nil - rw [tlcRevokeRoleHasRoleEval hsz36, tlcRevokeRoleWordToElem_absent habs] - -/-- Unauthorized: the body reverts at `require(hasRole(adminRole, msg.sender))`. -/ -theorem tlcRevokeRoleBodyRevertAdmin {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) (hsz36 : 36 ≤ I.calldata.size) - (hunauth : UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ I) = ⟨0⟩) : - ExecTransitionBody config contract (initState cA gh bl σ σ₀ g A I) (tlcHasRoleStore I) - revokeRoleTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true - (by simp only [initState]; exact hwv))) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (tlcRevokeRoleLetDeclEval hsz36)) ?_ - exact ExecBlock.consRevert (ExecStmt.requireFalse - (by rw [tlcRevokeRoleOnlyRoleEval, tlcRevokeRoleAdminWordToElem_absent hunauth])) - -/-! ## Refinement -/ - -/-- Refinement of `RevokeRole` (selector index 23). -/ -theorem tlcRevokeRoleBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 23)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 23) (by native_decide) hsel - have hword : tlcHasRoleWord σ_evm I = tlcHasRoleWord σ_solm I := by - simp only [tlcHasRoleWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner (tlcHasRoleSlot I) ⟨0⟩ - have hadminword : tlcRevokeRoleAdminWord σ_evm I = tlcRevokeRoleAdminWord σ_solm I := by - simp only [tlcRevokeRoleAdminWord] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner (roleAdminSlot (tlcHasRoleRoleKey I)) ⟨0⟩ - have hadminslot : tlcRevokeRoleAdminSlot σ_evm I = tlcRevokeRoleAdminSlot σ_solm I := by - simp only [tlcRevokeRoleAdminSlot, hadminword] - have hadminhasrole : tlcRevokeRoleAdminHasRoleWord σ_evm I = tlcRevokeRoleAdminHasRoleWord σ_solm I := by - simp only [tlcRevokeRoleAdminHasRoleWord, hadminslot] - exact accountMapEquiv_storage_findD hAccounts I.codeOwner (tlcRevokeRoleAdminSlot σ_solm I) ⟨0⟩ - have henc : returnEquiv ByteArray.empty none revokeRoleTransition.returnType := by - simpa [revokeRoleTransition] using - (returnEquiv.fallthrough (o := ByteArray.empty) (r := none) (t := []) - (dvs := []) rfl (by native_decide) (by native_decide)) - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz68 : 68 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · by_cases hcanon : (calldataWord I.calldata 36).toNat < EVM.addressModulus - · -- decode succeeds; reach the onlyRole check - obtain ⟨_, _, h3040⟩ := tlcRevokeRoleReach3040 (cA := cA) (gh := gh) (bl := bl) - (σ := σ_evm) (σ₀ := σ₀) (A := A) (g := Sat256.ofUInt256 g) - hcode hwv hsz68 hbig hsize hsel hcanon - obtain ⟨_, _, h3665⟩ := tlcRevokeRoleReachAdminBit h3040 (by omega) - by_cases hauth : UInt256.land ⟨255⟩ (tlcRevokeRoleAdminHasRoleWord σ_evm I) = ⟨0⟩ - · -- unauthorized: both revert at the onlyRole check - exact tlcReEquivExecRev hcode (tlcRevokeRoleRevAdmin h3665 hauth) - (tlcSelectorDispatchRevokeRole hsel) (tlcDecodeRevokeRole_ok hsz68 hbig hcanon) - (tlcRevokeRoleBodyRevertAdmin (σ := σ_solm) hwv (by omega) - (by rw [← hadminhasrole]; exact hauth)) - · -- authorized: conditional clear - by_cases hpres : UInt256.land ⟨255⟩ (tlcHasRoleWord σ_evm I) = ⟨0⟩ - · -- role absent: no write on either side - exact tlcReEquivExecGen hcode - (tlcRevokeRoleXAbsent h3665 hauth hpres) - (tlcSelectorDispatchRevokeRole hsel) (tlcDecodeRevokeRole_ok hsz68 hbig hcanon) - (tlcRevokeRoleBodyAbsent (σ := σ_solm) hwv (by omega) - (by rw [← hadminhasrole]; exact hauth) (by rw [← hword]; exact hpres)) - (by simp [initState]) - (by simpa [initState] using hAccounts) henc - · -- role present: both SSTORE `false` - refine tlcReEquivExecGen hcode - (tlcRevokeRoleXPresent h3665 _hperm hauth hpres) - (tlcSelectorDispatchRevokeRole hsel) (tlcDecodeRevokeRole_ok hsz68 hbig hcanon) - (tlcRevokeRoleBodyPresent (σ := σ_solm) hwv (by omega) - (by rw [← hadminhasrole]; exact hauth) (by rw [← hword]; exact hpres)) - (by simp [tlcRenounceRolePost, initState, storageStore_createdAccounts]) ?_ henc - have hval : UInt256.land (UInt256.lnot ⟨255⟩) (tlcHasRoleWord σ_evm I) - = UInt256.land (tlcHasRoleWord σ_solm I) (UInt256.lnot ⟨255⟩) := by - rw [u256_land_comm, hword] - rw [hval] - simpa [tlcRenounceRolePost, initState, storageStore_accountMap, - codeOwnerStorageWord_initState] using - accountMapEquiv_sstoreAccountMap I.codeOwner (tlcHasRoleSlot I) - (UInt256.land (tlcHasRoleWord σ_solm I) (UInt256.lnot ⟨255⟩)) hAccounts - · -- non-canonical account: EVM reverts at the address check, Solm decode fails - exact tlcReEquivDecodeFailed hcode - (tlcRevokeRoleNoncanonRevert (g := Sat256.ofUInt256 g) hcode hwv hsz68 hbig hsize hsel - hcanon) - (tlcSelectorDispatchRevokeRole hsel) (tlcDecodeRevokeRole_none_noncanon hsz68 hbig hcanon) - · -- huge calldata: EVM reverts at the length check, Solm decode fails - have hhuge : 2 ^ 255 + 4 ≤ I.calldata.size := Nat.not_lt.mp hbig - exact tlcReEquivDecodeFailed hcode - (tlcRevokeRoleDecodeRevert (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckHuge_4_64 hhuge hsize)) - (tlcSelectorDispatchRevokeRole hsel) (tlcDecodeRevokeRole_none_huge hhuge) - · -- short calldata: EVM reverts at the length check, Solm decode fails - have hshort : I.calldata.size < 68 := by omega - exact tlcReEquivDecodeFailed hcode - (tlcRevokeRoleDecodeRevert (g := Sat256.ofUInt256 g) hcode hwv hsz hsize hsel - (solcDecodeLenCheckShort_4_64 hsz hshort hsize)) - (tlcSelectorDispatchRevokeRole hsel) (tlcDecodeRevokeRole_none_short hsz hshort) - · -- nonpayable guard: callvalue ≠ 0 - obtain ⟨_, _, h1350⟩ := tlcReachRevokeRole (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨1361⟩) h1350 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchRevokeRole hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Routines.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Routines.lean deleted file mode 100644 index f8aab9df..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Routines.lean +++ /dev/null @@ -1,218 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Common - -/-! -# OpenZeppelin TimelockController shared routine lemmas - -Contract-wide `RD` combinators and refinement bridges not covered directly by the library because -TimelockController (solc 0.8.35, payable `receive`) emits a **per-function** non-payable callvalue -guard rather than a shared-prologue one, and has `contract.receive = some …` (so the library -`reEquiv*` bridges, which require `receive = none`, do not apply on the selector-match path). - -The guard-peel lemmas are the per-function analogues of the library's `solcGuardCallvalueZero` / -`solcGuardCallvalueNonzeroRevert`. The `tlcReEquiv*` bridges consume a direct -`selectorDispatchMsg contract I.calldata = some t` fact, mirroring -`RDret.reEquivExecutionGenAccountMapEquiv` / `RDrev.reEquivExecutionRevert`. - -Adapted from the fully-proved sibling `Benchmarks/WETH9/Routines.lean` (same payable-dispatch shape). --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-- Non-payable callvalue guard, `callvalue == 0` branch: peel - `JUMPDEST; CALLVALUE; DUP1; ISZERO; PUSH2 gt; JUMPI; …; JUMPDEST gt; POP`, reaching `gt + 2` - with the selector word still on the stack. - LIBRARY CANDIDATE: `Reasoning.Solc` — per-function analogue of `solcGuardCallvalueZero`. -/ -theorem tlcGuardPeelOk {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {entry gt sel : UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (h : RD code ee g s0 entry [sel] mem aw rdata acc k C) - (hcv : ee.weiValue = ⟨0⟩) - (hd0 : decode code entry = some (.JUMPDEST, .none)) - (hd1 : decode code (entry + ⟨1⟩) = some (.CALLVALUE, .none)) - (hd2 : decode code (entry + ⟨1⟩ + ⟨1⟩) = some (.DUP1, .none)) - (hd3 : decode code (entry + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) = some (.ISZERO, .none)) - (hd4 : decode code (entry + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) = some (.Push .PUSH2, some (gt, 2))) - (hd7 : decode code (entry + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3) = some (.JUMPI, .none)) - (hgtjd : (D_J code 0).contains gt = true) - (hdgt : decode code gt = some (.JUMPDEST, .none)) - (hdpop : decode code (gt + ⟨1⟩) = some (.POP, .none)) : - ∃ k' C', RD code ee g s0 (gt + ⟨1⟩ + ⟨1⟩) [sel] mem aw rdata acc k' C' := by - have hcond : UInt256.isZero ee.weiValue ≠ ⟨0⟩ := by rw [hcv]; decide - exact ⟨_, _, h.jumpdest hd0 (by simp) - |>.callvalue hd1 (by simp) - |>.dup1 hd2 (by simp) - |>.iszero hd3 (by simp) - |>.pushConst gt (op := .PUSH2) (width := 2) (by simp) hd4 (by simp) - |>.jumpiT hd7 hcond hgtjd (by simp) - |>.jumpdest hdgt (by simp) - |>.pop hdpop (by simp)⟩ - -/-- Non-payable callvalue guard, `callvalue != 0` branch: the `JUMPI` is not taken and control falls - into the `PUSH0; PUSH0; REVERT` stub (solc ≥ 0.8.20 Shanghai emits `PUSH0 PUSH0` not `PUSH1 0 DUP1`). - LIBRARY CANDIDATE: `Reasoning.Solc` — per-function analogue of `solcGuardCallvalueNonzeroRevert`. -/ -theorem tlcGuardPeelRev {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {entry gt sel : UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (h : RD code ee g s0 entry [sel] mem aw rdata acc k C) - (hcv : ee.weiValue ≠ ⟨0⟩) - (hd0 : decode code entry = some (.JUMPDEST, .none)) - (hd1 : decode code (entry + ⟨1⟩) = some (.CALLVALUE, .none)) - (hd2 : decode code (entry + ⟨1⟩ + ⟨1⟩) = some (.DUP1, .none)) - (hd3 : decode code (entry + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) = some (.ISZERO, .none)) - (hd4 : decode code (entry + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) = some (.Push .PUSH2, some (gt, 2))) - (hd7 : decode code (entry + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3) = some (.JUMPI, .none)) - (hd8 : decode code (entry + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩) - = some (.PUSH0, .none)) - (hd9 : decode code (entry + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩ + ⟨1⟩) - = some (.PUSH0, .none)) - (hd10 : decode code (entry + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) - = some (.REVERT, .none)) : - RDrev code g s0 := by - have hcond : UInt256.isZero ee.weiValue = ⟨0⟩ := isZero_eq_zero_of_ne hcv - exact (h.jumpdest hd0 (by simp) - |>.callvalue hd1 (by simp) - |>.dup1 hd2 (by simp) - |>.iszero hd3 (by simp) - |>.pushConst gt (op := .PUSH2) (width := 2) (by simp) hd4 (by simp) - |>.jumpiNT hd7 hcond (by simp)).revertStub hd8 hd9 hd10 (by simp) - -/-! ## Connect lemmas taking a direct selector dispatch - -TimelockController has `contract.receive = some receiveTransition`, so the library `reEquiv*` -bridges — which require `contract.receive = none` to convert a `dispatchMsg` fact into a -`selectorDispatchMsg` one — do not apply on the selector-match path. When a named selector matches, -`selectorDispatchMsg contract I.calldata = some t` holds directly; these lemmas consume that, -mirroring `RDret.reEquivExecutionGenAccountMapEquiv` / `RDrev.reEquivExecutionRevert`. -/ - -/-- `RDret ⇒ execution` for a directly-matched selector (accounts up to `accountMapEquiv`). -/ -theorem tlcReEquivExecGen {cfg : Config} {t : TransitionDecl} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} - {o : ByteArray} {callargs cs retVal} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {evm'' : EVM.State} - (hcode : I.code = timelockControllerBenchBytecode) - (h : RDret timelockControllerBenchBytecode g (initState cA gh bl σ_evm σ₀ g A I) acc o) - (hsel : selectorDispatchMsg contract I.calldata = some t) - (hdec : decodeCalldataWithMode cfg.abiDecodeMode (t.params.map Param.name) - (transitionSignature t).paramTypes I.calldata = some callargs) - (hbody : ExecTransitionBody cfg contract - (initState cA gh bl σ_solm σ₀ g A I) callargs t.body - (.returned cs evm'' retVal)) - (hCreated : acc.1 = evm''.createdAccounts) - (hAccounts : accountMapEquiv acc.2 evm''.accountMap) - (henc : returnEquiv o retVal t.returnType) : - runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g.toUInt256 A I := by - rcases h with hoog | ⟨s, hX, hsacc⟩ - · exact reEquiv_outOfGas (Xi_error_of_X (g := g.toUInt256) (by - rw [← hcode] at hoog - simpa [initState, Sat256.ofUInt256, Sat256.toUInt256] using hoog)) - · have hxi := Xi_success_of_X (g := g.toUInt256) (by - rw [← hcode] at hX - simpa [initState, Sat256.ofUInt256, Sat256.toUInt256] using hX) - have hbody' : - ExecTransitionBody cfg contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g.toUInt256) A I) - callargs t.body (.returned cs evm'' retVal) := by - simpa [initState, Sat256.ofUInt256, Sat256.toUInt256] using hbody - refine runtimeEquivalenceFor.execution rfl - (solmExec.intro hsel rfl hdec rfl hbody') ?_ - rw [hxi] - have hcreated : s.createdAccounts = evm''.createdAccounts := - (congrArg Prod.fst hsacc).trans hCreated - have haccounts : accountMapEquiv s.accountMap evm''.accountMap := by - change accountMapEquiv (s.createdAccounts, s.accountMap).2 evm''.accountMap - rw [congrArg Prod.snd hsacc]; exact hAccounts - exact execResultsEquiv.success rfl rfl hcreated haccounts (.abi henc) - -/-- Getter form: the Solm body returns `rvSolm` (read from `σ_solm`) leaving state at `initState`, - the EVM output encodes `rvEvm` (read from `σ_evm`), coupled by `hval : rvSolm = rvEvm`. -/ -theorem tlcReEquivExecTransport {cfg : Config} {t : TransitionDecl} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} - {o : ByteArray} {callargs cs rvSolm rvEvm} - (hcode : I.code = timelockControllerBenchBytecode) - (h : RDret timelockControllerBenchBytecode g (initState cA gh bl σ_evm σ₀ g A I) (cA, σ_evm) o) - (hsel : selectorDispatchMsg contract I.calldata = some t) - (hdec : decodeCalldataWithMode cfg.abiDecodeMode (t.params.map Param.name) - (transitionSignature t).paramTypes I.calldata = some callargs) - (hbody : ExecTransitionBody cfg contract - (initState cA gh bl σ_solm σ₀ g A I) callargs t.body - (.returned cs (initState cA gh bl σ_solm σ₀ g A I) rvSolm)) - (hval : rvSolm = rvEvm) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (henc : returnEquiv o rvEvm t.returnType) : - runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g.toUInt256 A I := by - subst hval - exact tlcReEquivExecGen hcode h hsel hdec hbody (by simp [initState]) - (by simpa [initState] using hAccounts) henc - -/-- `RDrev ⇒ execution` (revert) for a directly-matched selector. -/ -theorem tlcReEquivExecRev {cfg : Config} {t : TransitionDecl} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} {callargs} - (hcode : I.code = timelockControllerBenchBytecode) - (h : RDrev timelockControllerBenchBytecode g (initState cA gh bl σ_evm σ₀ g A I)) - (hsel : selectorDispatchMsg contract I.calldata = some t) - (hdec : decodeCalldataWithMode cfg.abiDecodeMode (t.params.map Param.name) - (transitionSignature t).paramTypes I.calldata = some callargs) - (hbody : ExecTransitionBody cfg contract - (initState cA gh bl σ_solm σ₀ g A I) callargs t.body .reverted) : - runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g.toUInt256 A I := by - rcases h with hoog | ⟨g', o, hrev⟩ - · exact reEquiv_outOfGas (Xi_error_of_X (g := g.toUInt256) (by - rw [← hcode] at hoog - simpa [initState, Sat256.ofUInt256, Sat256.toUInt256] using hoog)) - · have hxi := Xi_revert_of_X (g := g.toUInt256) (by - rw [← hcode] at hrev - simpa [initState, Sat256.ofUInt256, Sat256.toUInt256] using hrev) - have hbody' : - ExecTransitionBody cfg contract - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g.toUInt256) A I) - callargs t.body .reverted := by - simpa [initState, Sat256.ofUInt256, Sat256.toUInt256] using hbody - refine runtimeEquivalenceFor.execution rfl - (solmExec.intro hsel rfl hdec rfl hbody') ?_ - rw [hxi]; exact execResultsEquiv.revert rfl rfl - -/-- `RDrev ⇒ decodingFailed` for a directly-matched selector whose ABI decode fails. -/ -theorem tlcReEquivDecodeFailed {cfg : Config} {t : TransitionDecl} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (h : RDrev timelockControllerBenchBytecode g (initState cA gh bl σ_evm σ₀ g A I)) - (hsel : selectorDispatchMsg contract I.calldata = some t) - (hdec : decodeCalldataWithMode cfg.abiDecodeMode (t.params.map Param.name) - (transitionSignature t).paramTypes I.calldata = none) : - runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g.toUInt256 A I := by - rcases h with hoog | ⟨g', o, hrev⟩ - · exact reEquiv_outOfGas (Xi_error_of_X (g := g.toUInt256) (by - rw [← hcode] at hoog - simpa [initState, Sat256.ofUInt256, Sat256.toUInt256] using hoog)) - · have hxi := Xi_revert_of_X (g := g.toUInt256) (by - rw [← hcode] at hrev - simpa [initState, Sat256.ofUInt256, Sat256.toUInt256] using hrev) - exact runtimeEquivalenceFor.decodingFailed hsel rfl hdec hxi - -/-- Non-payable function, `callvalue != 0` branch: the EVM reverts at the function's own callvalue - guard. On the Solm side the body reverts at its `require(msg.value == 0)` (when the calldata - decodes) or decoding fails first — both revert, matching the EVM revert. `hbodyRev` supplies the - Solm body revert for the decode-success case (typically `bodyReverts_nonPayable`). -/ -theorem tlcNonpayableRevert {cfg : Config} {t : TransitionDecl} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) - (h : RDrev timelockControllerBenchBytecode g (initState cA gh bl σ_evm σ₀ g A I)) - (hsel : selectorDispatchMsg contract I.calldata = some t) - (hbodyRev : ∀ callargs, - decodeCalldataWithMode cfg.abiDecodeMode (t.params.map Param.name) - (transitionSignature t).paramTypes I.calldata = some callargs → - ExecTransitionBody cfg contract (initState cA gh bl σ_solm σ₀ g A I) callargs t.body - .reverted) : - runtimeEquivalenceFor cfg contract cA gh bl σ_evm σ_solm σ₀ g.toUInt256 A I := by - by_cases hdec : decodeCalldataWithMode cfg.abiDecodeMode (t.params.map Param.name) - (transitionSignature t).paramTypes I.calldata = none - · exact tlcReEquivDecodeFailed hcode h hsel hdec - · obtain ⟨callargs, hca⟩ := Option.ne_none_iff_exists'.mp hdec - exact tlcReEquivExecRev hcode h hsel hca (hbodyRev callargs hca) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Schedule.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Schedule.lean deleted file mode 100644 index 0d88cbd9..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Schedule.lean +++ /dev/null @@ -1,19 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace OpenZeppelinBench.TimelockController - -/-- Refinement of `Schedule` (selector index 25). -/ -theorem tlcScheduleBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 25)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ScheduleBatch.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ScheduleBatch.lean deleted file mode 100644 index 8fe5e5c4..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ScheduleBatch.lean +++ /dev/null @@ -1,19 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 - -namespace OpenZeppelinBench.TimelockController - -/-- Refinement of `ScheduleBatch` (selector index 24). -/ -theorem tlcScheduleBatchBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 24)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/ScratchGrant.lean b/Benchmarks/OpenZeppelinBench/TimelockController/ScratchGrant.lean deleted file mode 100644 index 7af99bee..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/ScratchGrant.lean +++ /dev/null @@ -1,79 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.ConstructorEvm -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -set_option maxRecDepth 2000000 -set_option maxHeartbeats 4000000 -namespace OpenZeppelinBench.TimelockController - --- discover grant stack shapes. Entry @450: [account, role, retaddr, R...] -example {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - {M : ByteArray} {aw : UInt256} {account role retaddr : UInt256} {R : List UInt256} - (h : RD timelockControllerBenchCreationBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨450⟩ - (account :: role :: retaddr :: R) M aw ByteArray.empty (cA, σ) k C) - (haw : 96 ≤ 32 * aw.toNat) (hMsize : 256 ≤ M.size) (hR : R.length ≤ 900) - (hfp : M.readWithPadding 64 32 = (⟨256⟩ : UInt256).toByteArray) : - True := by - have e0 : (⟨0⟩ : UInt256).toNat = 0 := by native_decide - have e32 : (⟨32⟩ : UInt256).toNat = 32 := by native_decide - have e64 : (⟨64⟩ : UInt256).toNat = 64 := by native_decide - -- @450 JUMPDEST ; @451 PUSH0 ; @452 DUP3 ; @453 DUP2 ; @454 MSTORE (mem[0]=role) - have h1 := h.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.dup3 (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - have h2 := h1.mstore 0 (wordAt0Mem role M) aw (by native_decide) - (fun s ha hs => tlcCtorEvmCost0_mstore ha hs (by omega)) (by rfl) - (tlcCtorEvmAwOut aw (⟨0⟩ : UInt256).toNat 32 (by omega)) (by evm_ov) - -- @455 PUSH1 32 ; @457 DUP2 ; @458 DUP2 ; @459 MSTORE (mem[32]=0) - have h3 := h2.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - have h4 := h3.mstore 0 (twoWordHashMem role ⟨0⟩ M) aw (by native_decide) - (fun s ha hs => tlcCtorEvmCost0_mstore ha hs (by omega)) (by rfl) - (tlcCtorEvmAwOut aw (⟨32⟩ : UInt256).toNat 32 (by omega)) (by evm_ov) - -- @460 PUSH1 64 ; @462 DUP1 ; @463 DUP4 ; @464 KECCAK256 -> roleDataSlot = solcMappingSlot 0 role - have h5 := h4.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.dup1 (by native_decide) (by evm_ov) - |>.dup4 (by native_decide) (by evm_ov) - have h6 := h5.keccak256 0 (solcMappingSlot ⟨0⟩ role) aw (by native_decide) - (fun s ha hs => tlcCtorEvmCost0_keccak ha hs (by omega)) - (by rw [e0, e64]; exact tlcCtorEvmScratch_keccak role ⟨0⟩ (by omega)) - (tlcCtorEvmAwOut aw (⟨0⟩ : UInt256).toNat (⟨64⟩ : UInt256).toNat (by omega)) (by evm_ov) - -- @465-474: mask account. maskAcc = land account solcAddrMask - have h7 := h6.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨160⟩ (by native_decide) (by evm_ov) - |>.shl (by native_decide) (by evm_ov) - |>.sub (by native_decide) (by evm_ov) - |>.dup6 (by native_decide) (by evm_ov) - |>.and (by native_decide) (by evm_ov) - -- @475 DUP5 ; @476 MSTORE (mem[0]=maskAcc) - have h8 := h7.dup5 (by native_decide) (by evm_ov) - have h9 := h8.mstore 0 (wordAt0Mem (UInt256.land account (UInt256.sub (UInt256.shiftLeft ⟨1⟩ ⟨160⟩) ⟨1⟩)) - (twoWordHashMem role ⟨0⟩ M)) aw (by native_decide) - (fun s ha hs => tlcCtorEvmCost0_mstore ha hs (by omega)) (by rfl) - (tlcCtorEvmAwOut aw (⟨0⟩ : UInt256).toNat 32 (by omega)) (by evm_ov) - -- @477 SWAP1 ; @478 SWAP2 ; @479 MSTORE (mem[32]=roleDataSlot) - have h10 := h9.swap1 (by native_decide) (by evm_ov) - |>.swap2 (by native_decide) (by evm_ov) - have h11 := h10.mstore 0 (twoWordHashMem (UInt256.land account (UInt256.sub (UInt256.shiftLeft ⟨1⟩ ⟨160⟩) ⟨1⟩)) - (solcMappingSlot ⟨0⟩ role) (twoWordHashMem role ⟨0⟩ M)) aw (by native_decide) - (fun s ha hs => tlcCtorEvmCost0_mstore ha hs (by omega)) (by rfl) - (tlcCtorEvmAwOut aw (⟨32⟩ : UInt256).toNat 32 (by omega)) (by evm_ov) - -- @480 DUP2 ; @481 KECCAK256 -> finalSlot = solcMappingSlot roleDataSlot maskAcc - have h12 := h11.dup2 (by native_decide) (by evm_ov) - have h13 := h12.keccak256 0 - (solcMappingSlot (solcMappingSlot ⟨0⟩ role) - (UInt256.land account (UInt256.sub (UInt256.shiftLeft ⟨1⟩ ⟨160⟩) ⟨1⟩))) aw (by native_decide) - (fun s ha hs => tlcCtorEvmCost0_keccak ha hs (by omega)) - (by rw [e0, e64] - exact tlcCtorEvmScratch_keccak _ (solcMappingSlot ⟨0⟩ role) - (by rw [tlcCtorEvmScratch_size role ⟨0⟩ (by omega)]; omega)) - (tlcCtorEvmAwOut aw (⟨0⟩ : UInt256).toNat (⟨64⟩ : UInt256).toNat (by omega)) (by evm_ov) - -- @482 SLOAD ; @483 PUSH1 255 ; @485 AND ; @486 PUSH2 610 ; @489 JUMPI - obtain ⟨_, _, h14⟩ := h13.sload (by native_decide) (by evm_ov) - have h15 := h14.push1 ⟨255⟩ (by native_decide) (by evm_ov) - |>.and (by native_decide) (by evm_ov) - |>.push2 ⟨610⟩ (by native_decide) (by evm_ov) - sorry - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/SolmDispatch.lean b/Benchmarks/OpenZeppelinBench/TimelockController/SolmDispatch.lean deleted file mode 100644 index b4c4cc46..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/SolmDispatch.lean +++ /dev/null @@ -1,196 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Trusted - -/-! -# OpenZeppelin TimelockController Solm dispatch routing facts - -For each named selector, `selectorDispatchMsg contract I.calldata = some Transition`. These are -consumed by the per-function refinement bridges in `Routines.lean` (TimelockController has -`contract.receive = some …`, so the library `dispatchMsg`-based bridges do not apply and we route on -`selectorDispatchMsg` directly). --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -namespace OpenZeppelinBench.TimelockController - -attribute [local simp] - cancellerRoleSelectorBytes cancelSelectorBytes defaultAdminRoleSelectorBytes - executeBatchSelectorBytes executeSelectorBytes executorRoleSelectorBytes - getMinDelaySelectorBytes getOperationStateSelectorBytes getRoleAdminSelectorBytes - getTimestampSelectorBytes grantRoleSelectorBytes hasRoleSelectorBytes - hashOperationBatchSelectorBytes hashOperationSelectorBytes isOperationDoneSelectorBytes - isOperationPendingSelectorBytes isOperationReadySelectorBytes isOperationSelectorBytes - onERC1155BatchReceivedSelectorBytes onERC1155ReceivedSelectorBytes onERC721ReceivedSelectorBytes - proposerRoleSelectorBytes renounceRoleSelectorBytes revokeRoleSelectorBytes - scheduleBatchSelectorBytes scheduleSelectorBytes supportsInterfaceSelectorBytes - updateDelaySelectorBytes - -theorem tlcSelectorDispatchCancellerRole {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 0)) : - selectorDispatchMsg contract I.calldata = some cancellerRoleTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 0 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchCancel {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 1)) : - selectorDispatchMsg contract I.calldata = some cancelTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 1 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchDefaultAdminRole {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 2)) : - selectorDispatchMsg contract I.calldata = some defaultAdminRoleTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 2 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchExecuteBatch {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 3)) : - selectorDispatchMsg contract I.calldata = some executeBatchTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 3 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchExecute {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 4)) : - selectorDispatchMsg contract I.calldata = some executeTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 4 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchExecutorRole {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 5)) : - selectorDispatchMsg contract I.calldata = some executorRoleTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 5 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchGetMinDelay {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 6)) : - selectorDispatchMsg contract I.calldata = some getMinDelayTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 6 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchGetOperationState {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 7)) : - selectorDispatchMsg contract I.calldata = some getOperationStateTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 7 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchGetRoleAdmin {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 8)) : - selectorDispatchMsg contract I.calldata = some getRoleAdminTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 8 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchGetTimestamp {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 9)) : - selectorDispatchMsg contract I.calldata = some getTimestampTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 9 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchGrantRole {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 10)) : - selectorDispatchMsg contract I.calldata = some grantRoleTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 10 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchHasRole {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 11)) : - selectorDispatchMsg contract I.calldata = some hasRoleTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 11 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchHashOperationBatch {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 12)) : - selectorDispatchMsg contract I.calldata = some hashOperationBatchTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 12 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchHashOperation {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 13)) : - selectorDispatchMsg contract I.calldata = some hashOperationTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 13 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchIsOperationDone {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 14)) : - selectorDispatchMsg contract I.calldata = some isOperationDoneTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 14 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchIsOperationPending {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 15)) : - selectorDispatchMsg contract I.calldata = some isOperationPendingTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 15 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchIsOperationReady {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 16)) : - selectorDispatchMsg contract I.calldata = some isOperationReadyTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 16 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchIsOperation {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 17)) : - selectorDispatchMsg contract I.calldata = some isOperationTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 17 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchOnERC1155BatchReceived {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 18)) : - selectorDispatchMsg contract I.calldata = some onERC1155BatchReceivedTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 18 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchOnERC1155Received {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 19)) : - selectorDispatchMsg contract I.calldata = some onERC1155ReceivedTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 19 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchOnERC721Received {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 20)) : - selectorDispatchMsg contract I.calldata = some onERC721ReceivedTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 20 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchProposerRole {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 21)) : - selectorDispatchMsg contract I.calldata = some proposerRoleTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 21 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchRenounceRole {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 22)) : - selectorDispatchMsg contract I.calldata = some renounceRoleTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 22 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchRevokeRole {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 23)) : - selectorDispatchMsg contract I.calldata = some revokeRoleTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 23 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchScheduleBatch {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 24)) : - selectorDispatchMsg contract I.calldata = some scheduleBatchTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 24 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchSchedule {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 25)) : - selectorDispatchMsg contract I.calldata = some scheduleTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 25 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchSupportsInterface {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 26)) : - selectorDispatchMsg contract I.calldata = some supportsInterfaceTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 26 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -theorem tlcSelectorDispatchUpdateDelay {I : ExecutionEnv} (hsel : selIs I (tlcSelBytes 27)) : - selectorDispatchMsg contract I.calldata = some updateDelayTransition := by - have hcd : I.calldata.extract 0 4 = tlcSelBytes 27 := (byteArray_eq_of_beq hsel).symm - rw [selectorDispatchMsg_eq_dispatchList contract I.calldata] - simp [contract, dispatchList, selectorOf, hcd]; native_decide - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Storage.lean b/Benchmarks/OpenZeppelinBench/TimelockController/Storage.lean deleted file mode 100644 index 4e3ca540..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Storage.lean +++ /dev/null @@ -1,158 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Return - -/-! -# OpenZeppelin TimelockController shared mapping-getter routines - -Two reusable `RD` routines factored out of the `getTimestamp(bytes32)` refinement: - -* `tlcMappingGetSlot1` — the inline `mapping(bytes32 => uint256)` slot getter at base slot `1` - (PUSH0-based Shanghai scratch write `key‖1`, `KECCAK256`, `SLOAD`), generic over the mapping key - and the return continuation. The keccak preimage lives in `twoWordHashMem key ⟨1⟩ solcFreePtrMem`. -* `tlcReturnWordFromMem` — the split 32-byte return encoder of `Return.tlcReturnWord`, generalized to - any free-pointer-preserving scratch memory (`size = 96`, `mem[0x40] = 0x80`). A mapping getter - dirties the `[0,0x40)` scratch, so the return runs over `twoWordHashMem …`, not `solcFreePtrMem`. - -LIBRARY CANDIDATEs: `Reasoning.Solc` — `tlcMappingGetSlot1` generalizes the base-slot-`0` -`RD.solcZeroSlotMappingGetter` to base slot `1` with the modern PUSH0 write order; and -`tlcReturnWordFromMem` is the memory-generic form of the split return encoder. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Mapping-slot keccak identity for the modern (key-first) scratch layout -/ - -/-- The slot word an EVM `KECCAK256` over `twoWordHashMem key baseSlot solcFreePtrMem` (key at - `mem[0]`, `baseSlot` at `mem[0x20]`) pushes equals the Solm layout mapping slot for - `mapping[key]` at `baseSlot`. (Analogue of `solcMappingKeccakSlot`, whose scratch writes the - slot first; solc 0.8.35 writes the key first.) -/ -theorem tlcTwoWordKeccakSlot (baseSlot key : UInt256) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((twoWordHashMem key baseSlot solcFreePtrMem).readWithPadding 0 64))) - = solcMappingSlot baseSlot key := by - rw [twoWordHashMem_read0_64 key baseSlot solcFreePtrMem_size] - unfold solcMappingSlot - exact mappingSlot_single key baseSlot - -/-! ## Base-slot-1 mapping getter (@1333 in the TimelockController runtime) - - Stack at entry `[key, ret, R]`; the routine writes `key‖1` into scratch, hashes, loads the slot, - and `JUMP`s to `ret` leaving `[slotWord, R]`. Memory becomes `twoWordHashMem key ⟨1⟩ …`. -/ - --- LIBRARY CANDIDATE: `Reasoning.Solc` — base-slot-`1` PUSH0 mapping getter (key-first scratch write). -theorem tlcMappingGetSlot1 {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - {key ret : UInt256} {R : List UInt256} {rdata : ByteArray} {k C : ℕ} - (h : RD timelockControllerBenchBytecode ee g s0 ⟨1333⟩ (key :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hret : (D_J timelockControllerBenchBytecode 0).contains ret = true) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD timelockControllerBenchBytecode ee g s0 ret - (solcSlotWord σ ee (solcMappingSlot ⟨1⟩ key) :: R) - (twoWordHashMem key ⟨1⟩ solcFreePtrMem) (UInt256.ofNat 3) rdata (cA, σ) k' C' := by - have hk := h.jumpdest (by native_decide) (by evm_ov) - |>.push0 (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.dup2 (by native_decide) (by evm_ov) - |>.mstore 0 (wordAt0Mem key solcFreePtrMem) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rfl) (by native_decide) (by evm_ov) - |>.push1 ⟨1⟩ (by native_decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by evm_ov) - |>.mstore 0 (twoWordHashMem key ⟨1⟩ solcFreePtrMem) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rfl) (by native_decide) (by evm_ov) - |>.push1 ⟨64⟩ (by native_decide) (by evm_ov) - |>.swap1 (by native_decide) (by evm_ov) - |>.keccak256 0 (solcMappingSlot ⟨1⟩ key) (UInt256.ofNat 3) (by native_decide) mem_cost - (by rw [show (⟨0⟩ : UInt256).toNat = 0 from rfl, show (⟨64⟩ : UInt256).toNat = 64 from by decide] - exact tlcTwoWordKeccakSlot ⟨1⟩ key) - (by native_decide) (by evm_ov) - obtain ⟨_, _, hsl⟩ := hk.sload (by native_decide) (by evm_ov) - exact ⟨_, _, hsl.swap1 (by native_decide) (by evm_ov) |>.jump (by native_decide) hret (by evm_ov)⟩ - -/-! ## Memory-generic split 32-byte return encoder (from pc 581) - - `Return.tlcReturnWord` bakes in `solcFreePtrMem`; a mapping getter leaves the free pointer intact - at `mem[0x40]` but dirties the `[0,0x40)` scratch, so we need the return over any such memory. -/ - -/-- Memory after the return epilogue stores the 32-byte word `val` at the free pointer `0x80`. -/ -def tlcRetMem (mem : ByteArray) (val : UInt256) : ByteArray := - (UInt256.toByteArray val).write 0 mem 128 32 - -theorem tlcRetMem_eq {mem : ByteArray} (hsize : mem.size = 96) (val : UInt256) : - tlcRetMem mem val - = (mem ++ ffi.ByteArray.zeroes (USize.ofNat 32)) ++ UInt256.toByteArray val := by - rw [tlcRetMem, toByteArray_write_eq _ _ _ (by rw [hsize]; omega) - (by rw [hsize]; exact lt_usize _ (by norm_num))] - norm_num [hsize] - -theorem tlcRetMem_size {mem : ByteArray} (hsize : mem.size = 96) (val : UInt256) : - (tlcRetMem mem val).size = 160 := by - rw [tlcRetMem_eq hsize, ByteArray.size_append, ByteArray.size_append, hsize, - zeroes_ofNat_size _ (by norm_num), toByteArray_size] - -theorem tlcRetMem_read64 {mem : ByteArray} (hsize : mem.size = 96) - (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (val : UInt256) : - (tlcRetMem mem val).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by - rw [readWithPadding_eq_extract _ _ (by rw [tlcRetMem_size hsize]; omega), tlcRetMem_eq hsize, - extract_append_left _ _ _ _ - (by rw [ByteArray.size_append, hsize, zeroes_ofNat_size _ (by norm_num)]; omega), - extract_append_left _ _ _ _ (by rw [hsize]), - ← readWithPadding_eq_extract _ _ (by rw [hsize]), hread64] - -theorem tlcRetMem_read128 {mem : ByteArray} (hsize : mem.size = 96) (val : UInt256) : - (tlcRetMem mem val).readWithPadding 128 32 = UInt256.toByteArray val := by - have hpad : (mem ++ ffi.ByteArray.zeroes (USize.ofNat 32)).size = 128 := by - rw [ByteArray.size_append, hsize, zeroes_ofNat_size _ (by norm_num)] - rw [readWithPadding_eq_extract _ _ (by have := tlcRetMem_size hsize val; omega), tlcRetMem_eq hsize, - extract_append_right' _ _ _ _ (by omega) (by have := toByteArray_size val; omega)] - -theorem tlcRetMem_mload64 {mem : ByteArray} (hsize : mem.size = 96) - (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) (val : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (tlcRetMem mem val).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 5 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian ((tlcRetMem mem val).readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩ := - mloadFreePtrValue (by rw [tlcRetMem_size hsize]; decide) (by decide) - (tlcRetMem_read64 hsize hread64 val) - --- LIBRARY CANDIDATE: `Reasoning.Solc` — memory-generic split-encoder analogue of `tlcReturnWord`. -theorem tlcReturnWordFromMem {cA gh bl σ σ₀ A I} {g : Sat256} {val cont : UInt256} {R : List UInt256} - {mem : ByteArray} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨581⟩ - (val :: cont :: R) mem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hsize : mem.size = 96) - (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) - (hov : R.length + 5 ≤ 1024) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray val) := by - have h521 := h.jumpdest (by native_decide) (by simp only [List.length_cons]; omega) - |>.push1 ⟨64⟩ (by native_decide) (by simp only [List.length_cons]; omega) - |>.mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost - (mloadFreePtrValue (by rw [hsize]; decide) (by decide) hread64) (by decide) (by evm_ov) - |>.swap1 (by native_decide) (by simp only [List.length_cons]; omega) - |>.dup2 (by native_decide) (by simp only [List.length_cons]; omega) - |>.mstore 6 (tlcRetMem mem val) (UInt256.ofNat 5) (by native_decide) mem_cost - (by rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide]; rfl) (by decide) (by evm_ov) - |>.push1 ⟨32⟩ (by native_decide) (by simp only [List.length_cons]; omega) - |>.add (by native_decide) (by simp only [List.length_cons]; omega) - |>.push2 ⟨521⟩ (by native_decide) (by simp only [List.length_cons]; omega) - |>.jump (by native_decide) (by jump_dest) (by simp only [List.length_cons]; omega) - have hret := h521.jumpdest (by native_decide) (by simp only [List.length_cons]; omega) - |>.push1 ⟨64⟩ (by native_decide) (by simp only [List.length_cons]; omega) - |>.mload 0 ⟨128⟩ (UInt256.ofNat 5) (by native_decide) mem_cost - (tlcRetMem_mload64 hsize hread64 val) (by decide) (by evm_ov) - |>.dup1 (by native_decide) (by simp only [List.length_cons]; omega) - |>.swap2 (by native_decide) (by simp only [List.length_cons]; omega) - |>.sub (by native_decide) (by simp only [List.length_cons]; omega) - |>.swap1 (by native_decide) (by simp only [List.length_cons]; omega) - exact hret.ret 0 (UInt256.toByteArray val) (by native_decide) mem_cost - (by rw [show ((⟨32⟩ + ⟨128⟩ : UInt256).sub ⟨128⟩).toNat = 32 from by decide, - show (⟨128⟩ : UInt256).toNat = 128 from by decide]; exact tlcRetMem_read128 hsize val) - (by simp only [List.length_cons]; omega) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/SupportsInterface.lean b/Benchmarks/OpenZeppelinBench/TimelockController/SupportsInterface.lean deleted file mode 100644 index 4b55d95b..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/SupportsInterface.lean +++ /dev/null @@ -1,713 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Return -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `supportsInterface(bytes4)` refinement - -`supportsInterface` peels its non-payable callvalue guard, decodes a `bytes4 interfaceId` -(subroutine @4561: validates `calldata ≥ 36` and clean low-28-bytes, reverting otherwise), computes -`interfaceId == IERC1155Receiver || interfaceId == IAccessControl || interfaceId == IERC165` via a -short-circuit OR (subroutines @1675/@3619/@4235), and ABI-encodes the resulting `bool` (split -encoder @509/@521). Selector index 26, dispatch group G397 arm 1, body pc 478. - -The `bytes4` word/mask coupling lemmas below are adapted from the proven -`Examples/OpenZeppelinBench/AccessControl/SupportsInterface.lean` (identical decoder + comparison -codegen; only the constant set and the extra `IERC1155Receiver` arm differ). --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 2000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Decoded argument, mask, interface-id words, and Solm-side boolean -/ - -/-- The `bytes4 interfaceId` argument word (`CALLDATALOAD(4)`). -/ -abbrev tlcSuppIfaceWord (I : ExecutionEnv) : UInt256 := calldataWord I.calldata 4 - -/-- The 4 argument bytes of `bytes4 interfaceId` at calldata offset 4. -/ -abbrev tlcSuppIfaceBytes (I : ExecutionEnv) : List UInt8 := - ((I.calldata.toList.drop 4).take 32).take 4 - -/-- The decoded local store for `supportsInterface`. -/ -abbrev tlcSuppIfaceStore (I : ExecutionEnv) : Store := - (∅ : Store).insert "interfaceId" (.fixedBytes bytes4Width (tlcSuppIfaceBytes I)) - -/-- Solc's clean-bytes4 mask `0xffffffff…00 = ~((1 << 224) - 1)`. -/ -abbrev tlcSuppIfaceMask : UInt256 := - UInt256.lnot (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨224⟩) ⟨1⟩) - --- `IERC1155Receiver` id `0x4e2312e0`: solc builds it as `0x02711897 << 0xe5 = 0x4e2312e0 << 224`. -abbrev tlcIerc1155Word : UInt256 := UInt256.shiftLeft (⟨0x02711897⟩ : UInt256) ⟨0xe5⟩ -abbrev tlcIaccessControlWord : UInt256 := UInt256.shiftLeft (⟨0x7965db0b⟩ : UInt256) ⟨224⟩ -abbrev tlcIerc165Word : UInt256 := UInt256.shiftLeft (⟨0x01ffc9a7⟩ : UInt256) ⟨224⟩ - -/-- The Solm-side boolean: the 3-way interface-id disjunction (list-`BEq` form). -/ -abbrev tlcSuppIfaceResult (I : ExecutionEnv) : Bool := - (tlcSuppIfaceBytes I == [0x4e, 0x23, 0x12, 0xe0]) || - ((tlcSuppIfaceBytes I == [0x79, 0x65, 0xdb, 0x0b]) || - (tlcSuppIfaceBytes I == [0x01, 0xff, 0xc9, 0xa7])) - -abbrev tlcSuppIfaceResultWord (I : ExecutionEnv) : UInt256 := - if tlcSuppIfaceResult I then ⟨1⟩ else ⟨0⟩ - -/-! ## `bytes4` word / mask coupling (adapted from AccessControl; contract-agnostic). - LIBRARY CANDIDATE: these are pure calldata/word facts, reusable by any `supportsInterface`. -/ - -theorem tlcListUInt8_decide_eq_beq (xs ys : List UInt8) : - decide (xs = ys) = (xs == ys) := by - by_cases h : xs = ys - · subst ys; simp - · have hbeq : (xs == ys) = false := by - apply Bool.eq_false_iff.mpr; intro hb; exact h (eq_of_beq hb) - simp [h, hbeq] - -theorem tlcFixedBytes4_beq (xs ys : List UInt8) : - (Value.fixedBytes bytes4Width xs == Value.fixedBytes bytes4Width ys) = (xs == ys) := by - simp [BEq.beq, tlcListUInt8_decide_eq_beq] - -theorem tlcFromBytesBigEndian_append (a b : List UInt8) : - fromBytesBigEndian (a ++ b) = - fromBytesBigEndian a * 2 ^ (8 * b.length) + fromBytesBigEndian b := by - unfold fromBytesBigEndian Function.comp - rw [List.reverse_append, fromBytes'_append, List.length_reverse] - ring - -theorem tlcFromBytesBigEndian_bound (xs : List UInt8) : - fromBytesBigEndian xs < 2 ^ (8 * xs.length) := by - unfold fromBytesBigEndian Function.comp - have h := fromBytes'_le (bs := xs.reverse) - rwa [List.length_reverse] at h - -theorem tlcFromBytes'_zero_iff_all_zero (xs : List UInt8) : - fromBytes' xs = 0 ↔ xs.all (· == 0) = true := by - induction xs with - | nil => simp [fromBytes'] - | cons x xs ih => - constructor - · intro h - simp only [List.all_cons, Bool.and_eq_true] - unfold fromBytes' at h - have hxnat : x.toNat = 0 := (Nat.add_eq_zero_iff.mp h).1 - have htail : fromBytes' xs = 0 := by - have hprod : UInt8.size * fromBytes' xs = 0 := (Nat.add_eq_zero_iff.mp h).2 - have hsize : 0 < UInt8.size := by decide - omega - have hx : x = 0 := UInt8.toNat_inj.mp hxnat - exact ⟨by simp [hx], ih.mp htail⟩ - · intro h - simp only [List.all_cons, Bool.and_eq_true] at h - rcases h with ⟨hx, hxs⟩ - have hx0 : x = 0 := eq_of_beq hx - unfold fromBytes' - simp [hx0, ih.mpr hxs] - -theorem tlcFromBytesBigEndian_zero_iff_all_zero (xs : List UInt8) : - fromBytesBigEndian xs = 0 ↔ xs.all (· == 0) = true := by - unfold fromBytesBigEndian Function.comp - rw [tlcFromBytes'_zero_iff_all_zero]; simp - -theorem tlcBytesToWord_toNat_of_len (xs : List UInt8) (hlen : xs.length = 32) : - (ABI.bytesToWord xs).toNat = fromBytesBigEndian xs := by - unfold ABI.bytesToWord fromByteArrayBigEndian - rw [ulit_toNat'] - · simp [byteArray_toList_eq] - · change fromByteArrayBigEndian { data := xs.toArray } < UInt256.size - unfold fromByteArrayBigEndian - simp [byteArray_toList_eq] - rw [show UInt256.size = 2 ^ (8 * xs.length) by rw [hlen]; rfl] - exact tlcFromBytesBigEndian_bound xs - -theorem tlcSuppIfaceWord_toNat {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) : - (tlcSuppIfaceWord I).toNat = fromBytesBigEndian ((I.calldata.toList.drop 4).take 32) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen]; omega - have hword : ABI.bytesToWord ((I.calldata.toList.drop 4).take 32) = tlcSuppIfaceWord I := by - simpa [tlcSuppIfaceWord, calldataWord] using - decode_word_at_eq I.calldata 4 (by omega) (by norm_num) - rw [← hword] - exact tlcBytesToWord_toNat_of_len _ hlen - -theorem tlcSuppIfaceMask_toNat : tlcSuppIfaceMask.toNat = 2 ^ 256 - 2 ^ 224 := by decide - -theorem tlcSuppIfaceClean_of_mod_zero (w : UInt256) (hmod : w.toNat % 2 ^ 224 = 0) : - UInt256.land w tlcSuppIfaceMask = w := by - apply u256_inj - show Nat.land w.toNat tlcSuppIfaceMask.toNat % UInt256.size = w.toNat - rw [tlcSuppIfaceMask_toNat, natLandClearLow w.toNat 224 (by norm_num) w.val.isLt] - rw [show w.toNat / 2 ^ 224 * 2 ^ 224 = w.toNat by - have := Nat.div_add_mod w.toNat (2 ^ 224); omega] - exact Nat.mod_eq_of_lt w.val.isLt - -theorem tlcSuppIfaceModZero_of_padding {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) - (hpad : zeroPadding? ((I.calldata.toList.drop 4).take 32) 4 28 = some ()) : - (tlcSuppIfaceWord I).toNat % 2 ^ 224 = 0 := by - let xs := (I.calldata.toList.drop 4).take 32 - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hxsLen : xs.length = 32 := by - dsimp [xs]; rw [List.length_take, List.length_drop, htlen]; omega - have htailLen : (xs.drop 4).length = 28 := by rw [List.length_drop, hxsLen] - have htailTake : (xs.drop 4).take 28 = xs.drop 4 := - List.take_of_length_le (by rw [htailLen]) - have htailAll : (xs.drop 4).all (· == 0) = true := by - unfold zeroPadding? readBytes? at hpad - have hlen : ((xs.drop 4).take 28).length = 28 := by rw [htailTake, htailLen] - rw [if_pos hlen] at hpad - rw [htailTake] at hpad - by_cases hall : (xs.drop 4).all (· == 0) = true - · exact hall - · simp at hpad; simpa using hpad - have htailZero : fromBytesBigEndian (xs.drop 4) = 0 := - (tlcFromBytesBigEndian_zero_iff_all_zero (xs.drop 4)).mpr htailAll - have hword := tlcSuppIfaceWord_toNat (I := I) hsz36 - rw [hword] - change fromBytesBigEndian xs % 2 ^ 224 = 0 - rw [show xs = xs.take 4 ++ xs.drop 4 from (List.take_append_drop 4 xs).symm] - rw [tlcFromBytesBigEndian_append, htailLen, htailZero] - rw [show 8 * 28 = 224 by norm_num, Nat.add_zero] - exact Nat.mul_mod_left _ _ - -theorem tlcSuppIfaceEqOne_of_padding {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) - (hpad : zeroPadding? ((I.calldata.toList.drop 4).take 32) 4 28 = some ()) : - UInt256.eq (tlcSuppIfaceWord I) (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = ⟨1⟩ := by - have hclean : UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask = tlcSuppIfaceWord I := - tlcSuppIfaceClean_of_mod_zero _ (tlcSuppIfaceModZero_of_padding hsz36 hpad) - rw [hclean]; exact uInt256_eq_self _ - -theorem tlcSuppIfaceModNeZero_of_padding_none {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) - (hpad : zeroPadding? ((I.calldata.toList.drop 4).take 32) 4 28 = none) : - (tlcSuppIfaceWord I).toNat % 2 ^ 224 ≠ 0 := by - let xs := (I.calldata.toList.drop 4).take 32 - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hxsLen : xs.length = 32 := by - dsimp [xs]; rw [List.length_take, List.length_drop, htlen]; omega - have htailLen : (xs.drop 4).length = 28 := by rw [List.length_drop, hxsLen] - have htailTake : (xs.drop 4).take 28 = xs.drop 4 := - List.take_of_length_le (by rw [htailLen]) - have htailAllFalse : (xs.drop 4).all (· == 0) = false := by - unfold zeroPadding? readBytes? at hpad - have hlen : ((xs.drop 4).take 28).length = 28 := by rw [htailTake, htailLen] - rw [if_pos hlen] at hpad - rw [htailTake] at hpad - by_cases hall : (xs.drop 4).all (· == 0) = true - · simp at hpad - exfalso - rcases hpad with ⟨x, hxmem, hxne⟩ - have hallProp : ∀ x ∈ xs.drop 4, x = 0 := by simpa using hall - exact hxne (hallProp x hxmem) - · exact Bool.eq_false_iff.mpr hall - have htailNZ : fromBytesBigEndian (xs.drop 4) ≠ 0 := by - intro hz - have hall := (tlcFromBytesBigEndian_zero_iff_all_zero (xs.drop 4)).mp hz - rw [hall] at htailAllFalse; contradiction - have hword := tlcSuppIfaceWord_toNat (I := I) hsz36 - rw [hword] - change fromBytesBigEndian xs % 2 ^ 224 ≠ 0 - rw [show xs = xs.take 4 ++ xs.drop 4 from (List.take_append_drop 4 xs).symm] - rw [tlcFromBytesBigEndian_append, htailLen] - intro hmod - have htailMod : fromBytesBigEndian (xs.drop 4) % 2 ^ 224 = 0 := by - simpa [Nat.add_comm, Nat.add_left_comm, Nat.add_assoc] using hmod - have htailBound : fromBytesBigEndian (xs.drop 4) < 2 ^ 224 := by - have hb := tlcFromBytesBigEndian_bound (xs.drop 4) - rw [htailLen] at hb; simpa using hb - have htailZero : fromBytesBigEndian (xs.drop 4) = 0 := - Nat.eq_zero_of_le_zero (Nat.le_of_lt_succ (by omega)) - exact htailNZ htailZero - -theorem tlcSuppIfaceModZero_of_land_eq (w : UInt256) - (hclean : UInt256.land w tlcSuppIfaceMask = w) : w.toNat % 2 ^ 224 = 0 := by - have ht := congrArg UInt256.toNat hclean - change Nat.land w.toNat tlcSuppIfaceMask.toNat % UInt256.size = w.toNat at ht - rw [tlcSuppIfaceMask_toNat, natLandClearLow w.toNat 224 (by norm_num) w.val.isLt] at ht - have hsmall : w.toNat / 2 ^ 224 * 2 ^ 224 < UInt256.size := - lt_of_le_of_lt (by simpa [Nat.mul_comm] using Nat.mul_div_le w.toNat (2 ^ 224)) w.val.isLt - rw [Nat.mod_eq_of_lt hsmall] at ht - have hdiv := Nat.div_add_mod w.toNat (2 ^ 224) - omega - -theorem tlcSuppIfaceEqZero_of_padding_none {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) - (hpad : zeroPadding? ((I.calldata.toList.drop 4).take 32) 4 28 = none) : - UInt256.eq (tlcSuppIfaceWord I) (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = ⟨0⟩ := by - apply uInt256_eq_zero_of_ne - intro heq - have hword : tlcSuppIfaceWord I = UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask := - uInt256_eq_one_eq heq - exact (tlcSuppIfaceModNeZero_of_padding_none hsz36 hpad) - (tlcSuppIfaceModZero_of_land_eq _ hword.symm) - -theorem tlcSuppIfaceMaskedWord_toNat {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) : - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask).toNat = - fromBytesBigEndian (tlcSuppIfaceBytes I) * 2 ^ 224 := by - let xs := (I.calldata.toList.drop 4).take 32 - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - have hxsLen : xs.length = 32 := by - dsimp [xs]; rw [List.length_take, List.length_drop, htlen]; omega - have htailLen : (xs.drop 4).length = 28 := by rw [List.length_drop, hxsLen] - have hxsBound : fromBytesBigEndian xs < 2 ^ 256 := by - have hb := tlcFromBytesBigEndian_bound xs - rw [hxsLen] at hb; simpa using hb - have hword := tlcSuppIfaceWord_toNat (I := I) hsz36 - change Nat.land (tlcSuppIfaceWord I).toNat tlcSuppIfaceMask.toNat % UInt256.size = _ - rw [hword] - change Nat.land (fromBytesBigEndian xs) tlcSuppIfaceMask.toNat % UInt256.size = - fromBytesBigEndian (xs.take 4) * 2 ^ 224 - rw [tlcSuppIfaceMask_toNat, natLandClearLow (fromBytesBigEndian xs) 224 (by norm_num) hxsBound] - have hsplit : fromBytesBigEndian xs = - fromBytesBigEndian (xs.take 4) * 2 ^ 224 + fromBytesBigEndian (xs.drop 4) := by - calc - fromBytesBigEndian xs = fromBytesBigEndian (xs.take 4 ++ xs.drop 4) := - congrArg fromBytesBigEndian (List.take_append_drop 4 xs).symm - _ = fromBytesBigEndian (xs.take 4) * 2 ^ 224 + fromBytesBigEndian (xs.drop 4) := by - rw [tlcFromBytesBigEndian_append, htailLen] - rw [hsplit] - have htailBound : fromBytesBigEndian (xs.drop 4) < 2 ^ 224 := by - have hb := tlcFromBytesBigEndian_bound (xs.drop 4) - rw [htailLen] at hb; simpa using hb - have hdiv : (fromBytesBigEndian (xs.take 4) * 2 ^ 224 + fromBytesBigEndian (xs.drop 4)) / - 2 ^ 224 = fromBytesBigEndian (xs.take 4) := by omega - rw [hdiv] - have hheadBound : fromBytesBigEndian (xs.take 4) < 2 ^ 32 := by - have hb := tlcFromBytesBigEndian_bound (xs.take 4) - have hheadLen : (xs.take 4).length = 4 := by rw [List.length_take, hxsLen]; rfl - rw [hheadLen] at hb; simpa using hb - have hprodLt : fromBytesBigEndian (xs.take 4) * 2 ^ 224 < UInt256.size := by - have hlt : fromBytesBigEndian (xs.take 4) * 2 ^ 224 < 2 ^ 32 * 2 ^ 224 := - Nat.mul_lt_mul_of_pos_right hheadBound (by positivity) - simpa [UInt256.size, Nat.pow_add] using hlt - rw [Nat.mod_eq_of_lt hprodLt] - -theorem tlcSuppIfaceBytes_length {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) : - (tlcSuppIfaceBytes I).length = 4 := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList]; rfl - simp [tlcSuppIfaceBytes, List.length_take, List.length_drop, htlen]; omega - -theorem tlcIerc1155Word_toNat : - tlcIerc1155Word.toNat = fromBytesBigEndian [0x4e, 0x23, 0x12, 0xe0] * 2 ^ 224 := by decide - -theorem tlcIaccessControlWord_toNat : - tlcIaccessControlWord.toNat = fromBytesBigEndian [0x79, 0x65, 0xdb, 0x0b] * 2 ^ 224 := by decide - -theorem tlcIerc165Word_toNat : - tlcIerc165Word.toNat = fromBytesBigEndian [0x01, 0xff, 0xc9, 0xa7] * 2 ^ 224 := by decide - -/-- The generic "const-word vs masked-arg" comparison ↔ list equality. -/ -theorem tlcSuppIfaceEq_generic {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) - (cw : UInt256) (cb : List UInt8) (hcb : cb.length = 4) - (hcw : cw.toNat = fromBytesBigEndian cb * 2 ^ 224) : - UInt256.eq cw (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = - if (tlcSuppIfaceBytes I == cb) then ⟨1⟩ else ⟨0⟩ := by - by_cases h : tlcSuppIfaceBytes I = cb - · have hbeq : (tlcSuppIfaceBytes I == cb) = true := by rw [h]; simp - rw [hbeq] - have heq : cw = UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask := by - apply u256_inj - rw [hcw, tlcSuppIfaceMaskedWord_toNat hsz36, h] - rw [heq]; exact uInt256_eq_self _ - · have hbeq : (tlcSuppIfaceBytes I == cb) = false := by - apply Bool.eq_false_iff.mpr; intro hb; exact h (eq_of_beq hb) - rw [hbeq] - apply uInt256_eq_zero_of_ne - intro heq1 - have heq : cw = UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask := uInt256_eq_one_eq heq1 - have hn : fromBytesBigEndian (tlcSuppIfaceBytes I) = fromBytesBigEndian cb := by - have ht := congrArg UInt256.toNat heq - rw [hcw, tlcSuppIfaceMaskedWord_toNat hsz36] at ht - omega - exact h (fromBytesBigEndian_inj4 (tlcSuppIfaceBytes_length hsz36) hcb hn) - -theorem tlcSuppIfaceEq_ierc1155 {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) : - UInt256.eq tlcIerc1155Word (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = - if (tlcSuppIfaceBytes I == [0x4e, 0x23, 0x12, 0xe0]) then ⟨1⟩ else ⟨0⟩ := - tlcSuppIfaceEq_generic hsz36 _ _ rfl tlcIerc1155Word_toNat - -theorem tlcSuppIfaceEq_iaccessControl {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) : - UInt256.eq tlcIaccessControlWord (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = - if (tlcSuppIfaceBytes I == [0x79, 0x65, 0xdb, 0x0b]) then ⟨1⟩ else ⟨0⟩ := - tlcSuppIfaceEq_generic hsz36 _ _ rfl tlcIaccessControlWord_toNat - -theorem tlcSuppIfaceEq_ierc165 {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) : - UInt256.eq tlcIerc165Word (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = - if (tlcSuppIfaceBytes I == [0x01, 0xff, 0xc9, 0xa7]) then ⟨1⟩ else ⟨0⟩ := - tlcSuppIfaceEq_generic hsz36 _ _ rfl tlcIerc165Word_toNat - -theorem tlcSuppIfaceResultWord_norm (I : ExecutionEnv) : - UInt256.isZero (UInt256.isZero (tlcSuppIfaceResultWord I)) = tlcSuppIfaceResultWord I := by - by_cases h : tlcSuppIfaceResult I <;> simp [tlcSuppIfaceResultWord, h] <;> decide - -/-! ## Reach the body -/ - -/-- Reach the `supportsInterface` body pc 478 (G397 arm 1). -/ -theorem tlcReachSupportsInterface {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 26)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨478⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x01ffc9a7⟩ := - solcSelectorWord_eq_of_beq I hsz 0x01 0xff 0xc9 0xa7 ⟨0x01ffc9a7⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - refine tlcReachG397Body 1 (by omega) ⟨478⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j; rw [hsw]; native_decide) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-! ## ABI decode -/ - -theorem tlcDecodeSupportsInterface_ok {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hpad : zeroPadding? ((I.calldata.toList.drop 4).take 32) 4 28 = some ()) : - decodeCalldataWithMode config.abiDecodeMode (supportsInterfaceTransition.params.map Param.name) - (transitionSignature supportsInterfaceTransition).paramTypes I.calldata = - some (tlcSuppIfaceStore I) := by - show decodeCalldata ["interfaceId"] [bytes4] I.calldata = some (tlcSuppIfaceStore I) - simpa [tlcSuppIfaceStore, tlcSuppIfaceBytes, calldataBytes4Arg, bytes4, bytes4Width, - abiBytes4, abiBytes4Width] using - decodeCalldata_bytes4_ok (cd := I.calldata) (x := "interfaceId") hsz36 hbig hpad - -theorem tlcDecodeSupportsInterface_none_short {I : ExecutionEnv} - (hsz4 : 4 ≤ I.calldata.size) (hshort : I.calldata.size < 36) : - decodeCalldataWithMode config.abiDecodeMode (supportsInterfaceTransition.params.map Param.name) - (transitionSignature supportsInterfaceTransition).paramTypes I.calldata = none := by - show decodeCalldata ["interfaceId"] [bytes4] I.calldata = none - simpa [bytes4, bytes4Width, abiBytes4, abiBytes4Width] using - decodeCalldata_bytes4_none_short (cd := I.calldata) (x := "interfaceId") hsz4 hshort - -theorem tlcDecodeSupportsInterface_none_huge {I : ExecutionEnv} - (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (supportsInterfaceTransition.params.map Param.name) - (transitionSignature supportsInterfaceTransition).paramTypes I.calldata = none := by - show decodeCalldata ["interfaceId"] [bytes4] I.calldata = none - simpa [bytes4, bytes4Width, abiBytes4, abiBytes4Width] using - decodeCalldata_bytes4_none_huge (cd := I.calldata) (x := "interfaceId") hbig - -theorem tlcDecodeSupportsInterface_none_pad {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hbig : I.calldata.size < 2 ^ 255 + 4) - (hpad : zeroPadding? ((I.calldata.toList.drop 4).take 32) 4 28 = none) : - decodeCalldataWithMode config.abiDecodeMode (supportsInterfaceTransition.params.map Param.name) - (transitionSignature supportsInterfaceTransition).paramTypes I.calldata = none := by - show decodeCalldata ["interfaceId"] [bytes4] I.calldata = none - simpa [bytes4, bytes4Width, abiBytes4, abiBytes4Width] using - decodeCalldata_bytes4_none_pad (cd := I.calldata) (x := "interfaceId") hsz36 hbig hpad - -/-! ## Solm body -/ - -/-- The Solm `supportsInterface(bytes4)` body returns the 3-way disjunction boolean. -/ -theorem tlcSuppIfaceBodyReturns (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) : - ExecTransitionBody config contract evm (tlcSuppIfaceStore I) - supportsInterfaceTransition.body - (.returned { contract := contract, locals := tlcSuppIfaceStore I } evm - (some [(.bool (tlcSuppIfaceResult I))])) := by - refine nonpayableReturnExprBodyReturns hwv ?_ - have hvar : evalExpr? config { contract := contract, locals := tlcSuppIfaceStore I } evm - (.var "interfaceId") = .ok (.fixedBytes bytes4Width (tlcSuppIfaceBytes I)) := by - simp [evalExpr?, EvalResult.ofOption, tlcSuppIfaceStore] - have he : ∀ c : List UInt8, - evalExpr? config { contract := contract, locals := tlcSuppIfaceStore I } evm - (.binary .eq (.var "interfaceId") (fixedBytes4 c)) - = .ok (.bool (tlcSuppIfaceBytes I == c)) := by - intro c - simp only [evalExpr?, hvar, fixedBytes4, EvalResult.bind, bind, evalBinaryOp?, pure, - tlcFixedBytes4_beq] - have hor : ∀ (e1 e2 : Expr) (c1 c2 : Bool), - evalExpr? config { contract := contract, locals := tlcSuppIfaceStore I } evm e1 - = .ok (.bool c1) → - evalExpr? config { contract := contract, locals := tlcSuppIfaceStore I } evm e2 - = .ok (.bool c2) → - evalExpr? config { contract := contract, locals := tlcSuppIfaceStore I } evm - (.binary .or e1 e2) = .ok (.bool (c1 || c2)) := by - intro e1 e2 c1 c2 h1 h2 - simp only [evalExpr?, h1, EvalResult.bind, bind] - cases c1 with - | true => rfl - | false => rw [h2]; rfl - show evalExpr? config { contract := contract, locals := tlcSuppIfaceStore I } evm - (.binary .or (.binary .eq (.var "interfaceId") ierc1155ReceiverId) - (.binary .or (.binary .eq (.var "interfaceId") iaccessControlId) - (.binary .eq (.var "interfaceId") ierc165Id))) = .ok (.bool (tlcSuppIfaceResult I)) - exact hor _ _ _ _ (he [0x4e, 0x23, 0x12, 0xe0]) - (hor _ _ _ _ (he [0x79, 0x65, 0xdb, 0x0b]) (he [0x01, 0xff, 0xc9, 0xa7])) - -/-! ## EVM trace -/ - -/-- Peel the guard and jump into the `bytes4` decoder subroutine @4561, leaving the decoder's - arguments `[offset=4, calldatasize, retPC=504, contPC=509, sel]`. -/ -theorem tlcSuppIfaceReachDecoder {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 26)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨4561⟩ - [⟨4⟩, UInt256.ofNat I.calldata.size, ⟨504⟩, ⟨509⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h478⟩ := tlcReachSupportsInterface (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hcode hsz4 hsize hsel - obtain ⟨_, _, h491⟩ := tlcGuardPeelOk (gt := ⟨489⟩) h478 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by jump_dest) - (by native_decide) (by native_decide) - exact ⟨_, _, evm_run h491 with [ - push2 ⟨509⟩, push2 ⟨504⟩, calldatasize, push1 ⟨4⟩, push2 ⟨4561⟩, jump (by jump_dest)]⟩ - -/-- Split bool-return encoder @509 (store `iszero∘iszero val` at the free pointer, fall through the - return dispatcher @521, `RETURN(0x80, 0x20)`). Structurally identical to the proven - AccessControl `bool` encoder. LIBRARY CANDIDATE: split analogue of `RD.solcReturnBoolFromMem`. -/ -theorem tlcSuppIfaceReturnBool {g : Sat256} {s0 : State} {ee : ExecutionEnv} - {k C : ℕ} {R : List UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {val : UInt256} - (h : RD timelockControllerBenchBytecode ee g s0 ⟨509⟩ (val :: R) solcFreePtrMem - (UInt256.ofNat 3) rdata acc k C) - (hnorm : UInt256.isZero (UInt256.isZero val) = val) - (hov : R.length + 8 ≤ 1024) : - RDret timelockControllerBenchBytecode g s0 acc (UInt256.toByteArray val) := by - exact evm_run h with [ - jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by decide) - mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - swap1, iszero, iszero, dup2, - raw mstore 6 (solcReturnMem val) (UInt256.ofNat 5) (by decide) - mem_cost (by rw [hnorm]; rfl) (by decide) (by evm_ov), - push1 ⟨32⟩, add, jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 5) (by decide) - mem_cost (solcReturnMem_mload64 val) (by decide) (by evm_ov), - dup1, swap2, sub, swap1, - raw ret 0 (UInt256.toByteArray val) (by decide) mem_cost - (by rw [show (UInt256.sub ((⟨32⟩ : UInt256) + ⟨128⟩) ⟨128⟩).toNat = 32 from by decide] - exact solcReturnMem_read128 val) - (by evm_ov) ] - -/-- Reach the bool-computing subroutine @1675 with the decoded argument on the stack. -/ -theorem tlcSuppIfaceReach1675 {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hszhi : I.calldata.size < 2 ^ 255 + 4) (hsel : selIs I (tlcSelBytes 26)) - (hpad : zeroPadding? ((I.calldata.toList.drop 4).take 32) 4 28 = some ()) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1675⟩ - [tlcSuppIfaceWord I, ⟨509⟩, tlcSelWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨0⟩ := - solcDecodeLenCheckOk_4_32 hsz36 hszhi hsize - have hclean : UInt256.eq (tlcSuppIfaceWord I) - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = ⟨1⟩ := - tlcSuppIfaceEqOne_of_padding hsz36 hpad - obtain ⟨_, _, h4561⟩ := tlcSuppIfaceReachDecoder (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv (by omega) hsize hsel - exact ⟨_, _, evm_run h4561 with [ - jumpdest, push0, push1 ⟨32⟩, dup3, dup5, sub, slt, iszero, push2 ⟨4577⟩, - jumpiT (by rw [hslt]; decide) (by jump_dest), - jumpdest, dup2, calldataload, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨224⟩, shl, sub, - not, dup2, and, dup2, eq, push2 ⟨2110⟩, - jumpiT (by - change UInt256.eq (tlcSuppIfaceWord I) - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) ≠ ⟨0⟩ - rw [hclean]; decide) (by jump_dest), - jumpdest, swap4, swap3, pop, pop, pop, jump (by jump_dest), - jumpdest, push2 ⟨1675⟩, jump (by jump_dest)]⟩ - -/-- The bool computer (@1675 → @3619 → @4235 → epilogue @1685) reaches the return encoder @509 with - the ABI result word on the stack. -/ -theorem tlcSuppIfaceCompute {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} - (hsz36 : 36 ≤ I.calldata.size) - (hreach : ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨1675⟩ - [tlcSuppIfaceWord I, ⟨509⟩, sel] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨509⟩ - [tlcSuppIfaceResultWord I, sel] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd1675⟩ := hreach - by_cases h1155 : (tlcSuppIfaceBytes I == [0x4e, 0x23, 0x12, 0xe0]) = true - · -- IERC1155Receiver matches: `@3619` short-circuits to the epilogue. - have hresult : tlcSuppIfaceResultWord I = ⟨1⟩ := by - simp [tlcSuppIfaceResultWord, tlcSuppIfaceResult, h1155] - have hc1eq : UInt256.eq tlcIerc1155Word - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = ⟨1⟩ := by - simpa [h1155] using tlcSuppIfaceEq_ierc1155 hsz36 - have rd1685 := evm_run rd1675 with [ - jumpdest, push0, push2 ⟨1685⟩, dup3, push2 ⟨3619⟩, jump (by jump_dest), - jumpdest, push0, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨224⟩, shl, sub, not, dup3, and, - push4 ⟨0x02711897⟩, push1 ⟨0xe5⟩, shl, eq, dup1, push2 ⟨1685⟩, - jumpiT (by - change UInt256.eq tlcIerc1155Word - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) ≠ ⟨0⟩ - rw [hc1eq]; decide) (by jump_dest)] - exact ⟨_, _, by - simpa [hresult, hc1eq] using evm_run rd1685 with [ - jumpdest, swap3, swap2, pop, pop, jump (by jump_dest), - jumpdest, swap3, swap2, pop, pop, jump (by jump_dest)]⟩ - · have h1155f : (tlcSuppIfaceBytes I == [0x4e, 0x23, 0x12, 0xe0]) = false := by simpa using h1155 - have hc1z : UInt256.eq tlcIerc1155Word - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = ⟨0⟩ := by - simpa [h1155f] using tlcSuppIfaceEq_ierc1155 hsz36 - by_cases hac : (tlcSuppIfaceBytes I == [0x79, 0x65, 0xdb, 0x0b]) = true - · -- IAccessControl matches: `@4235` short-circuits to the epilogue. - have hresult : tlcSuppIfaceResultWord I = ⟨1⟩ := by - simp [tlcSuppIfaceResultWord, tlcSuppIfaceResult, h1155f, hac] - have hc2eq : UInt256.eq tlcIaccessControlWord - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = ⟨1⟩ := by - simpa [hac] using tlcSuppIfaceEq_iaccessControl hsz36 - have rd1685 := evm_run rd1675 with [ - jumpdest, push0, push2 ⟨1685⟩, dup3, push2 ⟨3619⟩, jump (by jump_dest), - jumpdest, push0, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨224⟩, shl, sub, not, dup3, and, - push4 ⟨0x02711897⟩, push1 ⟨0xe5⟩, shl, eq, dup1, push2 ⟨1685⟩, - jumpiNT (by - change UInt256.eq tlcIerc1155Word - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = ⟨0⟩ - rw [hc1z]), - pop, push2 ⟨1685⟩, dup3, push2 ⟨4235⟩, jump (by jump_dest), - jumpdest, push0, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨224⟩, shl, sub, not, dup3, and, - push4 ⟨0x7965db0b⟩, push1 ⟨224⟩, shl, eq, dup1, push2 ⟨1685⟩, - jumpiT (by - change UInt256.eq tlcIaccessControlWord - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) ≠ ⟨0⟩ - rw [hc2eq]; decide) (by jump_dest)] - exact ⟨_, _, by - simpa [hresult, hc2eq] using evm_run rd1685 with [ - jumpdest, swap3, swap2, pop, pop, jump (by jump_dest), - jumpdest, swap3, swap2, pop, pop, jump (by jump_dest), - jumpdest, swap3, swap2, pop, pop, jump (by jump_dest)]⟩ - · -- Neither IERC1155Receiver nor IAccessControl; result = IERC165 match (fall-through @4235). - have hacf : (tlcSuppIfaceBytes I == [0x79, 0x65, 0xdb, 0x0b]) = false := by simpa using hac - have hc2z : UInt256.eq tlcIaccessControlWord - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = ⟨0⟩ := by - simpa [hacf] using tlcSuppIfaceEq_iaccessControl hsz36 - have hc3 : UInt256.eq tlcIerc165Word - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = tlcSuppIfaceResultWord I := by - rw [tlcSuppIfaceEq_ierc165 hsz36] - simp [tlcSuppIfaceResultWord, tlcSuppIfaceResult, h1155f, hacf] - have hc3rev : UInt256.eq (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) - tlcIerc165Word = tlcSuppIfaceResultWord I := by rw [uInt256_eq_comm]; exact hc3 - have rd1685 := evm_run rd1675 with [ - jumpdest, push0, push2 ⟨1685⟩, dup3, push2 ⟨3619⟩, jump (by jump_dest), - jumpdest, push0, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨224⟩, shl, sub, not, dup3, and, - push4 ⟨0x02711897⟩, push1 ⟨0xe5⟩, shl, eq, dup1, push2 ⟨1685⟩, - jumpiNT (by - change UInt256.eq tlcIerc1155Word - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = ⟨0⟩ - rw [hc1z]), - pop, push2 ⟨1685⟩, dup3, push2 ⟨4235⟩, jump (by jump_dest), - jumpdest, push0, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨224⟩, shl, sub, not, dup3, and, - push4 ⟨0x7965db0b⟩, push1 ⟨224⟩, shl, eq, dup1, push2 ⟨1685⟩, - jumpiNT (by - change UInt256.eq tlcIaccessControlWord - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = ⟨0⟩ - rw [hc2z]), - pop, push4 ⟨0x01ffc9a7⟩, push1 ⟨224⟩, shl, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨224⟩, - shl, sub, not, dup4, and, eq, push2 ⟨1685⟩, jump (by jump_dest)] - exact ⟨_, _, by - simpa [hc3rev] using evm_run rd1685 with [ - jumpdest, swap3, swap2, pop, pop, jump (by jump_dest), - jumpdest, swap3, swap2, pop, pop, jump (by jump_dest), - jumpdest, swap3, swap2, pop, pop, jump (by jump_dest)]⟩ - -theorem tlcSuppIfaceX_ok {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hszhi : I.calldata.size < 2 ^ 255 + 4) (hsel : selIs I (tlcSelBytes 26)) - (hpad : zeroPadding? ((I.calldata.toList.drop 4).take 32) 4 28 = some ()) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (tlcSuppIfaceResultWord I)) := by - obtain ⟨_, _, rd509⟩ := tlcSuppIfaceCompute hsz36 - (tlcSuppIfaceReach1675 hcode hwv hsz36 hsize hszhi hsel hpad) - exact tlcSuppIfaceReturnBool rd509 (tlcSuppIfaceResultWord_norm I) (by evm_ov) - -/-- Decoder bounds-check failure (`calldata < 36` or `≥ 2^255+4`): the decoder reverts. -/ -theorem tlcSuppIfaceBoundsRev {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz4 : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : selIs I (tlcSelBytes 26)) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h4561⟩ := tlcSuppIfaceReachDecoder (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv hsz4 hsize hsel - exact evm_run h4561 with [ - jumpdest, push0, push1 ⟨32⟩, dup3, dup5, sub, slt, iszero, push2 ⟨4577⟩, - jumpiNT (by rw [hslt]; decide), - raw revertStub (by decide) (by decide) (by decide) (by evm_ov)] - -/-- Decoder clean-bytes4 check failure (nonzero low 28 bytes): the decoder reverts. -/ -theorem tlcSuppIfaceBadpadRev {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hwv : I.weiValue = ⟨0⟩) - (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hbig : I.calldata.size < 2 ^ 255 + 4) (hsel : selIs I (tlcSelBytes 26)) - (hpad : zeroPadding? ((I.calldata.toList.drop 4).take 32) 4 28 = none) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨0⟩ := - solcDecodeLenCheckOk_4_32 hsz36 hbig hsize - have hclean : UInt256.eq (tlcSuppIfaceWord I) - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = ⟨0⟩ := - tlcSuppIfaceEqZero_of_padding_none hsz36 hpad - obtain ⟨_, _, h4561⟩ := tlcSuppIfaceReachDecoder (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (g := g) hcode hwv (by omega) hsize hsel - exact evm_run h4561 with [ - jumpdest, push0, push1 ⟨32⟩, dup3, dup5, sub, slt, iszero, push2 ⟨4577⟩, - jumpiT (by rw [hslt]; decide) (by jump_dest), - jumpdest, dup2, calldataload, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨224⟩, shl, sub, - not, dup2, and, dup2, eq, push2 ⟨2110⟩, - jumpiNT (by - change UInt256.eq (tlcSuppIfaceWord I) - (UInt256.land (tlcSuppIfaceWord I) tlcSuppIfaceMask) = ⟨0⟩ - rw [hclean]), - raw revertStub (by decide) (by decide) (by decide) (by evm_ov)] - -/-! ## Refinement -/ - -/-- Refinement of `SupportsInterface` (selector index 26). -/ -theorem tlcSupportsInterfaceBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 26)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz4 : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 26) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hsz36 : 36 ≤ I.calldata.size - · by_cases hbig : I.calldata.size < 2 ^ 255 + 4 - · cases hpad : zeroPadding? ((I.calldata.toList.drop 4).take 32) 4 28 with - | none => - exact tlcReEquivDecodeFailed hcode - (tlcSuppIfaceBadpadRev (g := Sat256.ofUInt256 g) hcode hwv hsz36 hsize hbig hsel hpad) - (tlcSelectorDispatchSupportsInterface hsel) - (tlcDecodeSupportsInterface_none_pad hsz36 hbig hpad) - | some _ => - have hpadSome : zeroPadding? ((I.calldata.toList.drop 4).take 32) 4 28 = some () := by - simpa using hpad - exact tlcReEquivExecTransport hcode - (tlcSuppIfaceX_ok (g := Sat256.ofUInt256 g) hcode hwv hsz36 hsize hbig hsel hpadSome) - (tlcSelectorDispatchSupportsInterface hsel) - (tlcDecodeSupportsInterface_ok hsz36 hbig hpadSome) - (tlcSuppIfaceBodyReturns (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I - (by simp only [initState]; exact hwv)) - rfl hAccounts - (returnEquiv_of_encode (by - by_cases hr : tlcSuppIfaceResult I - · simpa [tlcSuppIfaceResultWord, hr] using boolTrueReturnEncoding - · simpa [boolTy, tlcSuppIfaceResultWord, hr] using boolFalseReturnEncoding)) - · have hbigge : 2 ^ 255 + 4 ≤ I.calldata.size := by omega - exact tlcReEquivDecodeFailed hcode - (tlcSuppIfaceBoundsRev (g := Sat256.ofUInt256 g) hcode hwv hsz4 hsize hsel - (solcDecodeLenCheckHuge_4_32 hbigge hsize)) - (tlcSelectorDispatchSupportsInterface hsel) - (tlcDecodeSupportsInterface_none_huge hbigge) - · have hshort : I.calldata.size < 36 := by omega - exact tlcReEquivDecodeFailed hcode - (tlcSuppIfaceBoundsRev (g := Sat256.ofUInt256 g) hcode hwv hsz4 hsize hsel - (solcDecodeLenCheckShort_4_32 hsz4 hshort hsize)) - (tlcSelectorDispatchSupportsInterface hsel) - (tlcDecodeSupportsInterface_none_short hsz4 hshort) - · obtain ⟨_, _, h478⟩ := tlcReachSupportsInterface (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz4 hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨489⟩) h478 hwv (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchSupportsInterface hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/UpdateDelay.lean b/Benchmarks/OpenZeppelinBench/TimelockController/UpdateDelay.lean deleted file mode 100644 index 4cf8079f..00000000 --- a/Benchmarks/OpenZeppelinBench/TimelockController/UpdateDelay.lean +++ /dev/null @@ -1,378 +0,0 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.SolmDispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Dispatch -import Benchmarks.OpenZeppelinBench.TimelockController.Routines - -/-! -# OpenZeppelin TimelockController `updateDelay(uint256)` refinement - -`updateDelay` (selector index 27, dispatch group G254 arm 2, body pc 913) is the first -**state-mutating** function proven for this contract. It peels its non-payable callvalue guard, -decodes a single `uint256` word (via the shared `@4702` decoder, inlined here to avoid colliding with -a shared `Storage.lean`), enforces `require(msg.sender == address(this))`, emits the `MinDelayChange` -event (`LOG1`, ignored by the spec), and `SSTORE`s the new delay to storage slot 2 (`_minDelay`), -returning nothing (`STOP`). - -Template for the other mutations: the EVM trace ends at `RD.stop` (empty return) with the account map -carrying a single `sstoreAccountMap`, coupled to the Solm `.assign .storage` body result by -`accountMapEquiv_sstoreAccountMap`; the void return is `returnEquiv.fallthrough`. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach - -set_option maxRecDepth 2000000 -set_option maxHeartbeats 1000000 - -namespace OpenZeppelinBench.TimelockController - -/-! ## Decoded value, source-level store, and post-state -/ - -/-- The decoded `newDelay` word (calldata bytes `[4, 36)`). -/ -abbrev tlcUpdateDelayWord (I : ExecutionEnv) : UInt256 := calldataWord I.calldata 4 - -/-- The source-level locals after decoding `updateDelay(uint256 newDelay)`. -/ -abbrev tlcUpdateDelayStore (I : ExecutionEnv) : Store := - (∅ : Store).insert "newDelay" (Value.int (Int.ofNat (tlcUpdateDelayWord I).toNat)) - -/-- The decoded `newDelay` as a Solm value. -/ -abbrev tlcUpdateDelayVal (I : ExecutionEnv) : Value := - Value.int (Int.ofNat (tlcUpdateDelayWord I).toNat) - -/-- The Solm EVM state after `_minDelay = newDelay` (storage slot 2). -/ -abbrev tlcUpdateDelayPost (evm : EVM.State) (I : ExecutionEnv) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨2⟩ (tlcUpdateDelayWord I) - -/-! ## ABI decode (modern mode, one `uint256` word) -/ - -theorem tlcUpdateDelayDecodeOk {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) (hhi : I.calldata.size < 2 ^ 255 + 4) : - decodeCalldataWithMode config.abiDecodeMode (updateDelayTransition.params.map Param.name) - (transitionSignature updateDelayTransition).paramTypes I.calldata - = some (tlcUpdateDelayStore I) := by - show decodeCalldataWithMode config.abiDecodeMode ["newDelay"] [uint256] I.calldata = _ - exact decodeCalldata_uint256_ok hsz36 hhi - -theorem tlcUpdateDelayDecodeShort {I : ExecutionEnv} (hshort : I.calldata.size < 36) : - decodeCalldataWithMode config.abiDecodeMode (updateDelayTransition.params.map Param.name) - (transitionSignature updateDelayTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["newDelay"] [uint256] I.calldata = none - exact decodeCalldata_uint256_none_short hshort - -theorem tlcUpdateDelayDecodeHuge {I : ExecutionEnv} (hbig : 2 ^ 255 + 4 ≤ I.calldata.size) : - decodeCalldataWithMode config.abiDecodeMode (updateDelayTransition.params.map Param.name) - (transitionSignature updateDelayTransition).paramTypes I.calldata = none := by - show decodeCalldataWithMode config.abiDecodeMode ["newDelay"] [uint256] I.calldata = none - exact decodeCalldata_uint256_none_huge hbig - -/-! ## Solm-side body -/ - -/-- `newDelay` reads back from the decoded store. -/ -theorem tlcUpdateDelayRhs (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? config { contract := contract, locals := tlcUpdateDelayStore I } evm (.var "newDelay") - = .ok (tlcUpdateDelayVal I) := by - simp only [evalExpr?, EvalResult.ofOption, tlcUpdateDelayStore, tlcUpdateDelayVal] - rw [show (((∅ : Store).insert "newDelay" - (Value.int (Int.ofNat (tlcUpdateDelayWord I).toNat))).get? "newDelay") - = some (Value.int (Int.ofNat (tlcUpdateDelayWord I).toNat)) from by simp] - -/-- The `_minDelay = newDelay` scalar storage write collapses to a single `storageStore` on slot 2. -/ -theorem tlcUpdateDelayAssign (evm : EVM.State) (I : ExecutionEnv) : - assignStorageRef? config { contract := contract, locals := tlcUpdateDelayStore I } evm - .storage minDelayRef (tlcUpdateDelayVal I) = - .ok ({ contract := contract, locals := tlcUpdateDelayStore I }, tlcUpdateDelayPost evm I) := by - apply assignStorageRef_storage_scalar - (er := ({ base := "_minDelay", steps := [] } : EvaledStorageRef)) - (ty := uint256St) (loc := uint256Loc ⟨2⟩) - (hbase := by simp [tlcUpdateDelayStore, minDelayRef]) - (her := by simp [evalStorageRef, minDelayRef, EvalResult.bind, bind, pure]) - (hty := by simp [storageTypeAt?, contract, storageDecls, uint256St, uint256Int]) - (hloc := by rfl) - simpa [tlcUpdateDelayVal, tlcUpdateDelayPost, uint256Loc, uint256Int] using - storageLocStore_uint256 evm ⟨2⟩ (tlcUpdateDelayWord I) - -/-- With `msg.sender == address(this)`, the body stores `newDelay` and falls through (`none`). -/ -theorem tlcUpdateDelayBodyReturns (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hself : evm.executionEnv.source = evm.executionEnv.codeOwner) : - ExecTransitionBody config contract evm (tlcUpdateDelayStore I) updateDelayTransition.body - (.returned { contract := contract, locals := tlcUpdateDelayStore I } - (tlcUpdateDelayPost evm I) none) := by - refine ExecFuncBody.execBlockOK ?_ - have hguard : evalExpr? config { contract := contract, locals := tlcUpdateDelayStore I } evm - (.binary .eq sender thisAddr) = .ok (.bool true) := by - simp only [sender, thisAddr, evalExpr?, EvalResult.bind, bind, pure, envValue, evalBinaryOp?, - hself, beq_self_eq_true] - exact nonpayableRequireAssignStorageBlock hwv hguard (tlcUpdateDelayRhs evm I) - (tlcUpdateDelayAssign evm I) - -/-- With `msg.sender ≠ address(this)`, the body reverts at the `require`. -/ -theorem tlcUpdateDelayBodyReverts (evm : EVM.State) (I : ExecutionEnv) - (hwv : evm.executionEnv.weiValue = ⟨0⟩) - (hself : evm.executionEnv.source ≠ evm.executionEnv.codeOwner) : - ExecTransitionBody config contract evm (tlcUpdateDelayStore I) updateDelayTransition.body - .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hguard : evalExpr? config { contract := contract, locals := tlcUpdateDelayStore I } evm - (.binary .eq sender thisAddr) = .ok (.bool false) := by - simp only [sender, thisAddr, evalExpr?, EvalResult.bind, bind, pure, envValue, evalBinaryOp?] - rw [show ((Value.address evm.executionEnv.source) == (Value.address evm.executionEnv.codeOwner)) - = false from by - simp only [beq_eq_false_iff_ne, ne_eq, Value.address.injEq]; exact hself] - exact nonpayableSecondRequireReverts hwv hguard - -/-! ## EVM-side scratch memory for the `MinDelayChange` LOG - -The event stores `oldDelay` at the free pointer `0x80` (giving `solcReturnMem oldDelay`) then the new -value `wd` at `0x80 + 0x20 = 0xa0`. The custom-error revert path (caller ≠ this) stores the error -selector at `0x80` (again `solcReturnMem …`) then the masked caller at `0x84`. Both keep the free -pointer word at `[0x40, 0x60)` intact, so `MLOAD 0x40` still reads `0x80`. -/ - -/-- Memory after `SSTORE`-side event build: `oldDelay@0x80`, `wd@0xa0` (active-words 6). -/ -abbrev tlcUpdateDelayLogMem (oldDelay wd : UInt256) : ByteArray := - (UInt256.toByteArray wd).write 0 (solcReturnMem oldDelay) 160 32 - -theorem tlcUpdateDelayLogMem_size (oldDelay wd : UInt256) : - (tlcUpdateDelayLogMem oldDelay wd).size = 192 := by - unfold tlcUpdateDelayLogMem - exact toByteArray_write32_size_of_le (solcReturnMem oldDelay) wd 160 160 192 - (solcReturnMem_size oldDelay) (by rw [solcReturnMem_size]) (by decide) - -theorem tlcUpdateDelayLogMem_read64 (oldDelay wd : UInt256) : - (tlcUpdateDelayLogMem oldDelay wd).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by - unfold tlcUpdateDelayLogMem - rw [write32_read_below _ _ 160 64 (by rw [toByteArray_size]) (by rw [solcReturnMem_size]) (by omega)] - exact solcReturnMem_read64 oldDelay - -theorem tlcUpdateDelayLogMem_mload64 (oldDelay wd : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (tlcUpdateDelayLogMem oldDelay wd).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 6 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat (fromByteArrayBigEndian - ((tlcUpdateDelayLogMem oldDelay wd).readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩ := - mloadFreePtrValue (by rw [tlcUpdateDelayLogMem_size]; decide) (by decide) - (tlcUpdateDelayLogMem_read64 oldDelay wd) - -/-- The `MinDelayChange(uint256,uint256)` event topic (the `PUSH32` at pc 2184). -/ -abbrev tlcUpdateDelayTopic : UInt256 := - ⟨0x11c24f4ead16507c69ac467fbd5e4eed5fb5c699626d2cc6d66421df253886d5⟩ - -/-- Memory after the custom-error build: error selector `v@0x80`, masked caller `w@0x84`. -/ -abbrev tlcUpdateDelayErrMem (v w : UInt256) : ByteArray := - (UInt256.toByteArray w).write 0 (solcReturnMem v) 132 32 - -theorem tlcUpdateDelayErrMem_mload64 (v w : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (tlcUpdateDelayErrMem v w).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 6 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat (fromByteArrayBigEndian - ((tlcUpdateDelayErrMem v w).readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩ := by - apply mloadFreePtrValue - · have : (tlcUpdateDelayErrMem v w).size = 164 := by - unfold tlcUpdateDelayErrMem - exact toByteArray_write32_size_of_le (solcReturnMem v) w 132 160 164 - (solcReturnMem_size v) (by rw [solcReturnMem_size]; omega) (by decide) - omega - · decide - · unfold tlcUpdateDelayErrMem - rw [write32_read_below _ _ 132 64 (by rw [toByteArray_size]) - (by rw [solcReturnMem_size]; omega) (by omega)] - exact solcReturnMem_read64 v - -/-! ## EVM trace : reach the body, decode the word, run to the caller check -/ - -/-- Reach the `updateDelay` body pc 913 (G254 arm 2). -/ -theorem tlcUpdateDelayReach {cA gh bl σ σ₀ A I} {g : Sat256} - (hcode : I.code = timelockControllerBenchBytecode) (hsz : 4 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) (hsel : selIs I (tlcSelBytes 27)) : - ∃ k C, RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨913⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hsw : tlcSelWord I = ⟨0x64d62353⟩ := - solcSelectorWord_eq_of_beq I hsz 0x64 0xd6 0x23 0x53 ⟨0x64d62353⟩ (by native_decide) - (by simpa [tlcSelBytes] using hsel) - exact tlcReachG254Body 2 (by omega) ⟨913⟩ hcode hsz hsize - (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) (by rw [hsw]; native_decide) - (by intro j hj; interval_cases j <;> (rw [hsw]; native_decide)) - (by rw [hsw]; native_decide) (by jump_dest) (by native_decide) - -/-- Decode detour `926 → 2117`: pass the `size ≥ 36` guard, `CALLDATALOAD` the word, jump to the - caller check with `[newDelay, 476, sel]` on the stack. -/ -theorem tlcUpdateDelayReachCaller {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨926⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hsz36 : 36 ≤ I.calldata.size) (hhi : I.calldata.size < 2 ^ 255 + 4) - (hsize : I.calldata.size < UInt256.size) : - ∃ k' C', RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2117⟩ - [tlcUpdateDelayWord I, ⟨476⟩, tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k' C' := by - have hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨0⟩ := - solcDecodeLenCheckOk_4_32 hsz36 hhi hsize - have h2117 := evm_run h with [ - push2 ⟨476⟩, push2 ⟨939⟩, calldatasize, push1 ⟨4⟩, push2 ⟨4702⟩, jump (by jump_dest), - jumpdest, push0, push1 ⟨32⟩, dup3, dup5, sub, slt, iszero, push2 ⟨4718⟩, - jumpiT (by rw [hslt]; decide) (by jump_dest), - jumpdest, pop, calldataload, swap2, swap1, pop, jump (by jump_dest), - jumpdest, push2 ⟨2117⟩, jump (by jump_dest) ] - exact ⟨_, _, by simpa [tlcUpdateDelayWord, calldataWord] using h2117⟩ - -/-! ## EVM trace : the store + LOG happy path, and the two revert paths -/ - -/-- Happy path (`msg.sender == address(this)`): emit the `MinDelayChange` `LOG1`, `SSTORE` slot 2, and - `STOP` — halting with the account map carrying a single `sstoreAccountMap` and an empty return. -/ -theorem tlcUpdateDelayX_ok {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2117⟩ - [tlcUpdateDelayWord I, ⟨476⟩, tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) - (hperm : I.perm = true) (hself : I.source = I.codeOwner) : - RDret timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) - (cA, sstoreAccountMap I.codeOwner σ ⟨2⟩ (tlcUpdateDelayWord I)) ByteArray.empty := by - have h2167 := evm_run h with [ - jumpdest, - raw caller (by native_decide) (by evm_ov), - raw address (by native_decide) (by evm_ov), - dup2, eq, push2 ⟨2166⟩, - jumpiT (by rw [hself, uInt256_eq_self]; decide) (by jump_dest), - jumpdest, push1 ⟨2⟩ ] - obtain ⟨_, _, h2169⟩ := h2167.sload (by native_decide) (by evm_ov) - have h2184 := evm_run h2169 with [ - push1 ⟨64⟩, dup1, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost solcFreePtrMem_mload64 - (by native_decide) (by evm_ov), - swap2, dup3, - raw mstore 6 (solcReturnMem _) (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) - (by native_decide) (by evm_ov), - push1 ⟨32⟩, dup3, add, dup5, swap1, - raw mstore 3 (tlcUpdateDelayLogMem _ (tlcUpdateDelayWord I)) (UInt256.ofNat 6) (by native_decide) - mem_cost (by rfl) (by native_decide) (by evm_ov) ] - have h2217 := h2184.pushConst tlcUpdateDelayTopic (width := 32) (op := .PUSH32) (by decide) - (by native_decide) (by evm_ov) - have h2226pre := evm_run h2217 with [ - swap2, add, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 6) (by native_decide) mem_cost - (tlcUpdateDelayLogMem_mload64 _ (tlcUpdateDelayWord I)) (by native_decide) (by evm_ov), - dup1, swap2, sub, swap1 ] - have h2227 := h2226pre.log1 0 (UInt256.ofNat 6) (by native_decide) hperm mem_cost - (by native_decide) (by evm_ov) - have h2230 := evm_run h2227 with [ pop, push1 ⟨2⟩ ] - obtain ⟨_, _, h2231⟩ := h2230.sstore hperm (by native_decide) (by evm_ov) - have h476 := h2231.jump (by native_decide) (by jump_dest) (by evm_ov) - exact h476.jumpdest (by native_decide) (by evm_ov) |>.stop (by native_decide) (by evm_ov) - -/-- Caller-check revert (`msg.sender ≠ address(this)`): build the `AccessControlUnauthorizedAccount`- - style custom error and `REVERT`. -/ -theorem tlcUpdateDelayRevCaller {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2117⟩ - [tlcUpdateDelayWord I, ⟨476⟩, tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, σ) k C) - (hself : I.source ≠ I.codeOwner) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have heq0 : UInt256.eq (UInt256.ofNat I.source.val) (UInt256.ofNat I.codeOwner.val) = ⟨0⟩ := by - apply uInt256_eq_zero_of_ne - intro hbad - refine hself (Fin.ext ?_) - have h1 : (UInt256.ofNat I.source.val).toNat = I.source.val := - ulit_toNat' _ (lt_of_lt_of_le I.source.isLt (by decide : AccountAddress.size ≤ UInt256.size)) - have h2 : (UInt256.ofNat I.codeOwner.val).toNat = I.codeOwner.val := - ulit_toNat' _ (lt_of_lt_of_le I.codeOwner.isLt (by decide : AccountAddress.size ≤ UInt256.size)) - rw [← h1, ← h2, uInt256_eq_one_eq hbad] - have h2165pre := evm_run h with [ - jumpdest, - raw caller (by native_decide) (by evm_ov), - raw address (by native_decide) (by evm_ov), - dup2, eq, push2 ⟨2166⟩, - jumpiNT (by exact heq0), - push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by native_decide) mem_cost solcFreePtrMem_mload64 - (by native_decide) (by evm_ov), - raw push4 ⟨0xe2850c59⟩ (by native_decide) (by evm_ov), - push1 ⟨224⟩, shl, dup2, - raw mstore 6 (solcReturnMem _) (UInt256.ofNat 5) (by native_decide) mem_cost (by rfl) - (by native_decide) (by evm_ov), - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup3, and, push1 ⟨4⟩, dup3, add, - raw mstore 3 (tlcUpdateDelayErrMem _ _) (UInt256.ofNat 6) (by native_decide) mem_cost - (by rw [show (⟨128⟩ + ⟨4⟩ : UInt256).toNat = 132 from by native_decide]) - (by native_decide) (by evm_ov), - push1 ⟨36⟩, add, jumpdest, push1 ⟨64⟩, - raw mload 0 ⟨128⟩ (UInt256.ofNat 6) (by native_decide) mem_cost - (tlcUpdateDelayErrMem_mload64 _ _) (by native_decide) (by evm_ov), - dup1, swap2, sub, swap1 ] - exact h2165pre.rev 0 (by native_decide) mem_cost (by evm_ov) - -/-- Decode-guard revert (`size < 36` or `size ≥ 2²⁵⁵+4`): the modern `SLT(cds-4, 32)` guard is `1`, - so `ISZERO` is `0`, the `JUMPI` falls through, and the `PUSH0 PUSH0 REVERT` stub fires. -/ -theorem tlcUpdateDelayRevDecode {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (h : RD timelockControllerBenchBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨926⟩ - [tlcSelWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hslt : UInt256.slt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩) : - RDrev timelockControllerBenchBytecode g (initState cA gh bl σ σ₀ g A I) := by - have h4715 := evm_run h with [ - push2 ⟨476⟩, push2 ⟨939⟩, calldatasize, push1 ⟨4⟩, push2 ⟨4702⟩, jump (by jump_dest), - jumpdest, push0, push1 ⟨32⟩, dup3, dup5, sub, slt, iszero, push2 ⟨4718⟩, - jumpiNT (by rw [hslt]; decide) ] - exact h4715.revertStub (by native_decide) (by native_decide) (by native_decide) (by evm_ov) - -/-! ## Refinement -/ - -/-- Refinement of `updateDelay` (selector index 27). -/ -theorem tlcUpdateDelayBodyCore {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - (hcode : I.code = timelockControllerBenchBytecode) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) (hsel : selIs I (tlcSelBytes 27)) - (hAccounts : accountMapEquiv σ_evm σ_solm) : - runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - have hsz : 4 ≤ I.calldata.size := - calldata_size_ge_of_selIs I (tlcSelBytes 27) (by native_decide) hsel - by_cases hwv : I.weiValue = ⟨0⟩ - · -- callvalue == 0 - by_cases hsz36 : 36 ≤ I.calldata.size - · by_cases hhi : I.calldata.size < 2 ^ 255 + 4 - · -- decode succeeds : 36 ≤ size < 2^255 + 4 - obtain ⟨_, _, h913⟩ := tlcUpdateDelayReach (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - obtain ⟨_, _, h926⟩ := tlcGuardPeelOk (gt := ⟨924⟩) h913 hwv - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) - obtain ⟨_, _, h2117⟩ := tlcUpdateDelayReachCaller h926 hsz36 hhi hsize - by_cases hself : I.source = I.codeOwner - · -- msg.sender == address(this) : both mutate slot 2 - exact tlcReEquivExecGen hcode - (tlcUpdateDelayX_ok h2117 _hperm hself) - (tlcSelectorDispatchUpdateDelay hsel) (tlcUpdateDelayDecodeOk hsz36 hhi) - (tlcUpdateDelayBodyReturns (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I - (by simp only [initState]; exact hwv) (by simp only [initState]; exact hself)) - (by simp [tlcUpdateDelayPost, initState, storageStore_createdAccounts]) - (by simpa [tlcUpdateDelayPost, initState, storageStore_accountMap] using - accountMapEquiv_sstoreAccountMap I.codeOwner ⟨2⟩ (tlcUpdateDelayWord I) hAccounts) - (by simpa [updateDelayTransition] using - (returnEquiv.fallthrough (o := ByteArray.empty) (r := none) (t := []) - (dvs := []) rfl (by native_decide) (by native_decide))) - · -- msg.sender ≠ address(this) : both revert - exact tlcReEquivExecRev hcode (tlcUpdateDelayRevCaller h2117 hself) - (tlcSelectorDispatchUpdateDelay hsel) (tlcUpdateDelayDecodeOk hsz36 hhi) - (tlcUpdateDelayBodyReverts (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) I - (by simp only [initState]; exact hwv) (by simp only [initState]; exact hself)) - · -- calldata too large : decode fails, EVM reverts at the SLT guard - obtain ⟨_, _, h913⟩ := tlcUpdateDelayReach (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - obtain ⟨_, _, h926⟩ := tlcGuardPeelOk (gt := ⟨924⟩) h913 hwv - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) - exact tlcReEquivDecodeFailed hcode - (tlcUpdateDelayRevDecode h926 (solcDecodeLenCheckHuge_4_32 (by omega) hsize)) - (tlcSelectorDispatchUpdateDelay hsel) (tlcUpdateDelayDecodeHuge (by omega)) - · -- calldata too short : decode fails, EVM reverts at the SLT guard - obtain ⟨_, _, h913⟩ := tlcUpdateDelayReach (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - obtain ⟨_, _, h926⟩ := tlcGuardPeelOk (gt := ⟨924⟩) h913 hwv - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by jump_dest) (by native_decide) (by native_decide) - exact tlcReEquivDecodeFailed hcode - (tlcUpdateDelayRevDecode h926 (solcDecodeLenCheckShort_4_32 hsz (by omega) hsize)) - (tlcSelectorDispatchUpdateDelay hsel) (tlcUpdateDelayDecodeShort (by omega)) - · -- callvalue ≠ 0 : nonpayable guard reverts on both sides - obtain ⟨_, _, h913⟩ := tlcUpdateDelayReach (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hcode hsz hsize hsel - have hrev := tlcGuardPeelRev (gt := ⟨924⟩) h913 hwv - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) (by native_decide) - exact tlcNonpayableRevert hcode hrev (tlcSelectorDispatchUpdateDelay hsel) - (fun callargs _ => bodyReverts_nonPayable (by simp only [initState]; exact hwv)) - -end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/README.md b/Benchmarks/README.md index 4df9f099..e06eeda4 100644 --- a/Benchmarks/README.md +++ b/Benchmarks/README.md @@ -1,269 +1,80 @@ -# Benchmark Status - -Last updated: 2026-07-06. - -This file tracks whether a benchmark is ready to give to a proving agent. "Completed" means the -proof task has been marked done. "Handed off" means the benchmark has been selected for agent proof -work and no current semantic blocker is recorded here. It does not mean the theorem is already -proved. - -Sizes are byte counts from checked-in `runtime.hex` and `creation.hex`. ABI surface counts are from -the checked-in `.abi.json` files. - -## Size and Readiness Table - -| Benchmark | solc | Runtime bytes | Creation bytes | ABI surface | Readiness level | Ready for proof | -| --- | --- | ---: | ---: | --- | --- | --- | -| `Dss/Dai` | 0.6.12 | 4011 | 4312 | 22 fn + ctor | Completed | Yes | -| `Dss/Vow` | 0.6.12 | 5150 | 5410 | 24 fn + ctor | Completed | Yes | -| `Dss/Vat` | 0.6.12 | 6965 | 7021 | 28 fn + ctor | Handed off | Yes | -| `Dss/Pot` | 0.6.12 | 2595 | 2746 | 17 fn + ctor | Completed | Yes | -| `Dss/Jug` | 0.6.12 | 2440 | 2560 | 12 fn + ctor | Completed | Yes | -| `Dss/Spot` | 0.6.12 | 2178 | 2320 | 12 fn + ctor | Completed | Yes | -| `Dss/LinearDecrease` | 0.6.12 | 1128 | 1217 | 6 fn + ctor | Completed | Yes | -| `Dss/StairstepExponentialDecrease` | 0.6.12 | 1433 | 1522 | 7 fn + ctor | Completed | Yes | -| `Dss/ExponentialDecrease` | 0.6.12 | 1321 | 1410 | 6 fn + ctor | Completed | Yes | -| `Dss/GemJoin` | 0.6.12 | 2022 | 2326 | 11 fn + ctor | Completed | Yes | -| `Dss/DaiJoin` | 0.6.12 | 1733 | 1876 | 9 fn + ctor | Completed | Yes | -| `Dss/Cat` | 0.6.12 | 3873 | 3999 | 16 fn + ctor | Handed off | No | -| `Dss/Clipper` | 0.6.12 | 9360 | 9707 | 29 fn + ctor | Handed off | No | -| `Dss/Cure` | 0.6.12 | 3875 | 3971 | 20 fn + ctor | Completed | Yes | -| `Dss/Dog` | 0.6.12 | 4745 | 4927 | 17 fn + ctor | Handed off | No | -| `Dss/End` | 0.6.12 | 10265 | 10359 | 32 fn + ctor | Handed off | Yes | -| `Dss/Flapper` | 0.6.12 | 5008 | 5216 | 20 fn + ctor | Completed | No | -| `Dss/Flipper` | 0.6.12 | 6386 | 6596 | 19 fn + ctor | Completed | Yes | -| `Dss/Flopper` | 0.6.12 | 4780 | 5000 | 20 fn + ctor | Completed | Yes | -| `WETH9` | 0.5.16 | 1763 | 2055 | 11 fn + fallback/receive | Completed | Yes | -| `EAS/Attester` | 0.8.26 | 3186 | 3371 | 4 fn + ctor | Handed off | Yes | -| `ERC721` | 0.8.35 | 1482 | 1510 | 7 fn + empty ctor | Ready for proof | Yes | -| `OpenZeppelinBench/VestingWallet` | 0.8.35 | 2277 | 2485 | 14 fn + ctor + receive | Ready for proof | Yes | -| `OpenZeppelinBench/TimelockController` | 0.8.35 | 6509 | 7161 | 28 fn + ctor + receive | Handed off | Yes | -| `CompoundIII/CometRewards` | 0.8.15 via-IR | 4063 | 4207 | 11 fn + ctor | Handed off | Yes | -| `Safe` | 0.8.35 | 11874 | 11907 | 31 fn + ctor + fallback/receive | Handed off | Yes | -| `UniswapV2Router02` | 0.6.6 | 21955 | 22346 | 24 fn + ctor + fallback/receive | Prep needed | No | -| `UniswapV3Pool` | 0.7.6 | 22142 | 22728 | 26 fn + ctor | Handed off | Yes | -| `CompoundIII/Comet` | 0.8.15 via-IR | 18655 | 21528 | 68 fn + ctor + fallback/receive | Prep needed | No | -| `Auction` | 0.8.23 | 6150 | 6179 | 20 fn + empty ctor | Handed off | Yes | -| `Klima` | 0.7.5 | 6975 | 7732 | 30 fn + ctor | Ready for proof | Yes | - -## Completed / ready for proof / handed off - -- `Dss/Dai`: completed. Target theorem: `Benchmarks.Dss.Dai.daiContractCorrect`. - Proof work has been marked done. - -- `Dss/Vow`: completed. Target theorem: `Benchmarks.Dss.Vow.vowContractCorrect`. - Proof work has been marked done. - -- `Dss/Vat`: handed off. Target theorem: - `Benchmarks.Dss.Vat.vatContractCorrect`. Fresh solc output exactly matches the checked-in Lean - creation/runtime byte arrays, and the solc storage layout matches the spec. The runtime has no - external call sites, contract creation, delegate calls, selfdestruct, or high-level-call - `EXTCODESIZE` guards to model. No semantic blocker is currently known; expected proof work is - arithmetic helper lemmas, storage-mapping layout lemmas, and the large state-update bodies. - -- `Dss/Pot`: completed. Target theorem: - `Benchmarks.Dss.Pot.potContractCorrect`. Fresh solc output exactly matches the checked-in Lean - creation/runtime byte arrays, and the solc storage layout matches the spec. The runtime has two - optimized external-call sites with two `EXTCODESIZE` guards; the spec now models those guards on - all three source-level `VatLike` calls (`drip`, `join`, `exit`, with `join`/`exit` sharing a - bytecode call path). Proof work has been marked done. - -- `Dss/Jug`: completed. Target theorem: - `Benchmarks.Dss.Jug.jugContractCorrect`. Fresh solc output exactly matches the checked-in Lean - creation/runtime byte arrays, and the solc storage layout matches the spec. The runtime has two - external-call sites with two `EXTCODESIZE` guards; the spec now models those guards on - `VatLike.ilks` and `VatLike.fold`. Proof work has been marked done. - -- `Dss/Spot`: completed. Target theorem: - `Benchmarks.Dss.Spot.spotContractCorrect`. Fresh solc output exactly matches the checked-in Lean - creation/runtime byte arrays, and the solc storage layout matches the spec. The runtime has two - external-call sites with two `EXTCODESIZE` guards; the spec now models those guards on - `PipLike.peek` and `VatLike.file`. The `Poke` event is omitted consistently with the framework's - substate/log abstraction. Proof work has been marked done. - -- `Dss/LinearDecrease`, `Dss/StairstepExponentialDecrease`, and `Dss/ExponentialDecrease`: - completed. Target theorems: - `Benchmarks.Dss.LinearDecrease.linearDecreaseContractCorrect`, - `Benchmarks.Dss.StairstepExponentialDecrease.stairstepExponentialDecreaseContractCorrect`, and - `Benchmarks.Dss.ExponentialDecrease.exponentialDecreaseContractCorrect`. Fresh solc output is - checked in for all three deployable contracts from `src/abaci.sol`; the specs model auth, - storage layout, `file`, public getters, checked arithmetic, and the source-level price functions - including the `rpow` loop for the exponential variants. Proof work has been marked done. - -- `Dss/GemJoin`: completed. Target theorem: - `Benchmarks.Dss.GemJoin.gemJoinContractCorrect`. Fresh solc output is checked in from - `src/join.sol`; the spec models auth, constructor initialization, public getters, cage, - join/exit flows, high-level external-call `EXTCODESIZE` guards, and typed external ABI hooks for - `VatLike` and `GemLike`. Proof work has been marked done. - -- `Dss/DaiJoin`: completed. Target theorem: - `Benchmarks.Dss.DaiJoin.daiJoinContractCorrect`. Fresh solc output is checked in from - `src/join.sol`; the spec models auth, constructor initialization, public getters, cage, - join/exit flows, high-level external-call `EXTCODESIZE` guards, and typed external ABI hooks for - `VatLike` and `DSTokenLike`. Proof work has been marked done. - -- `Dss/End`: ready for proof, not yet handed off. Target theorem: - `Benchmarks.Dss.End.endContractCorrect`. The solc storage layout matches the spec's 18 slots - (0–17, including the nested `out[ilk][usr]` mapping). A bytecode-level audit of the checked-in - 10265-byte runtime finds 36 high-level external-call sites — 29 `CALL` and 7 `STATICCALL` — each - preceded by an `EXTCODESIZE` guard (36 guards), with no delegatecall, contract creation, or - selfdestruct, and a binary-search dispatcher over exactly the 32 ABI selectors. The spec models - all 36 calls with code-size guards, the 7 `view` callees (`dai`, `par`, `spot.ilks`, `tell`, - `bids`, `sales`, `read`) as `perm := false` static calls and the 29 state-changing calls as - `perm := true`, all 32 dispatched functions (18 getters + 14 externals), the constructor, and the - settlement flow (`cage`/`cage(ilk)`/`snip`/`skip`/`skim`/`free`/`thaw`/`flow`/`pack`/`cash`), with - typed ABI hooks for `VatLike`/`CatLike`/`DogLike`/`SpotLike`/`CureLike`/`FlipLike`/`ClipLike`/ - `PipLike` (the four `ilks(bytes32)` callees share one selector with distinct return decodes). The - `int256(x) >= 0` overflow guards are modeled as `x < 2^255`. Events are omitted consistently with - the framework's log abstraction. No semantic blocker is currently known; expected proof work is - binary-search dispatcher routing, mapping/nested-mapping slot lemmas, checked arithmetic, and the - typed external-call return decodings. - -- `Dss/Cure`: completed. Target theorem: - `Benchmarks.Dss.Cure.cureContractCorrect`. Fresh solc output is checked in, the artifact hashes - match `Benchmarks/Dss/Cure/README.md`, and the solc storage layout matches the spec's 10 slots - (`wards`, `live`, dynamic `srcs`, `wait`, `when`, `pos`, `amt`, `loaded`, `lCount`, `say`). A - bytecode-level audit of the checked-in 3875-byte runtime finds one `STATICCALL` and one matching - `EXTCODESIZE` guard for `SourceLike.cure()`, with no `CALL`, `DELEGATECALL`, contract creation, - or selfdestruct. The spec models all 20 public/external functions, the constructor, auth/live - guards, `file("wait", data)`, source-list `lift`/`drop`, `cage`, `tell`, checked `_add`/`_sub`, - the unchecked `lCount++` wrap in `load`, and the guarded static `SourceLike.cure()` return - decoding. `Trusted.lean` records the 20 opaque Keccak selector facts needed for dispatcher proof - work plus proof-local names for the verified jump tables. Events are omitted consistently with the - framework's log abstraction. Proof work has been marked done. - -- `Dss/Cat`, `Dss/Clipper`, `Dss/Dog`, and `Dss/Flapper`: scaffolded, not ready for proof. Fresh - upstream sources, ABI/AST/storage-layout - artifacts, optimized creation/runtime bytecode, Lean `ByteArray`s, verified `JUMPDEST` sets, and - top-level theorem targets are checked in and compile. Their current `Spec.lean` files are - intentionally minimal entrypoints; they still need full source-body transcription before they - should be handed to a proof agent. - -- `Dss/Flipper` and `Dss/Flopper`: completed. Target theorems: - `Benchmarks.Dss.Flipper.flipperContractCorrect` and - `Benchmarks.Dss.Flopper.flopperContractCorrect`. Proof work has been marked done. - -- `WETH9`: completed. Target theorem: - `Benchmarks.WETH9.weth9ContractCorrect`. Fresh solc output exactly matches the checked-in Lean - creation/runtime byte arrays. The payable fallback is modeled as `deposit`, and `withdraw` is - modeled as a value-sending low-level call followed by `require(success)`, matching the single - runtime `CALL` site. No benchmark-local semantic blocker is currently known under Solm's current - message-call abstraction; exact 2300-gas stipend precision would be framework-level refinement, - not missing local scaffold work. Proof work has been marked done. - -- `EAS/Attester`: handed off. Target theorem: - `Benchmarks.EAS.Attester.attesterContractCorrect`. Fresh solc 0.8.26 output exactly matches the - checked-in Lean creation/runtime byte arrays, and the solc storage layout is empty because `_eas` - is immutable. The runtime template has four `_eas` immutable patch sites and four typed EAS - `CALL`s; the spec models the two no-return calls (`revoke`, `multiRevoke`) with their explicit - `EXTCODESIZE` guards, while `attest` and `multiAttest` rely on return decoding as the bytecode - does. No semantic blocker is currently known; expected proof work is immutable patching, dynamic - calldata arrays, tuple ABI encoding, loop bodies, and external-call return decoding. - -- `ERC721`: ready for proof, not yet handed off. Target theorem: - `ERC721.erc721ContractCorrect`. Fresh solc 0.8.35 output with `--metadata-hash none` exactly - matches the checked-in Lean creation/runtime byte arrays, and the solc storage layout matches the - four mapping slots in the spec. The source is intentionally the compact ERC721 core only - (`approve`, `balanceOf`, `getApproved`, `isApprovedForAll`, `ownerOf`, `setApprovalForAll`, - `transferFrom`); metadata, ERC165, and safe-transfer extensions are not in this benchmark source. - The spec models the `unchecked` balance decrement/increment with modulo-2^256 wrapping. No - benchmark-local semantic blocker is currently known; expected proof work is binary-search - dispatcher routing, mapping slot lemmas, authorization/revert paths, and unchecked arithmetic. - -- `OpenZeppelinBench/VestingWallet`: ready for proof, not yet handed off. Target theorem: - `OpenZeppelinBench.VestingWallet.vestingWalletBenchContractCorrect`. Fresh solc 0.8.35 output - with `--metadata-hash none` exactly matches the checked-in Lean creation/runtime byte arrays. A - benchmark-local OpenZeppelin source closure is checked in with only the 14 files needed by - `VestingWalletBench.sol`. The spec models the payable `receive`, concrete immutable values - (`start = 0`, `duration = 365 days`), checked arithmetic, `uint64(block.timestamp)` truncation, - ERC20 `balanceOf` as a static typed call, and `SafeERC20.safeTransfer` as a raw call with optional - bool return checking plus the empty-return `EXTCODESIZE` guard. No benchmark-local semantic - blocker is currently known; expected proof work is overloaded ABI dispatch, immutable creation - patching, checked arithmetic paths, receive/fallback routing, and external-call reasoning. - -- `OpenZeppelinBench/TimelockController`: handed off. Target theorem: - `OpenZeppelinBench.TimelockController.timelockControllerBenchContractCorrect`. Fresh solc 0.8.35 - output with optimizer runs 200, Shanghai EVM, and `--metadata-hash none` is checked in with the - emitted ABI and storage layout. A benchmark-local OpenZeppelin source closure is checked in with - the 14 files needed by `TimelockControllerBench.sol`. The spec models the constructor's concrete - role grants (`msg.sender` admin/proposer/canceller and `address(0)` executor), `_roles`, - `_timestamps`, `_minDelay`, operation-state predicates, standard `abi.encode(...)` operation-id - hashing through a benchmark-local ABI hook, batch length checks, payable execution/receive, - low-level target calls, the reentrancy-sensitive `_afterCall` readiness check, and ERC721/ERC1155 - receiver hooks. Events, custom-error payloads, and bubbled revert bytes are omitted consistently - with the framework's current log/revert-data abstraction; the event-only loop in `scheduleBatch` - is omitted for that reason. No benchmark-local semantic blocker is currently known; expected - proof work is dispatcher routing, nested-role mapping layout, dynamic ABI encoding for - operation ids, checked timestamp arithmetic, batch call loops, and low-level call reasoning. - -- `CompoundIII/CometRewards`: handed off. Target theorem: - `Benchmarks.CompoundIII.CometRewards.cometRewardsContractCorrect`. Fresh solc 0.8.15 via-IR - output exactly matches the checked-in Lean creation/runtime byte arrays and ABI; the solc storage - layout matches the spec, including packed `RewardConfig` fields. The runtime has six - `STATICCALL` sites, three `CALL` sites, and two `EXTCODESIZE` guards; the spec models the view - calls as `perm := false` and the two guarded `accrueAccount` calls with explicit code-size - checks. Events and custom-error payloads are omitted consistently with the framework's - substate/revert-data abstraction. No semantic blocker is currently known; expected proof work is - via-IR dispatch, packed storage writes, dynamic calldata arrays, `pow10`/overflow paths, and typed - external-call return decoding. - -- `Safe`: handed off. Target theorem: - `Benchmarks.Safe.safeContractCorrect`. Fresh solc 0.8.35 output with optimizer runs 200, - Shanghai EVM, and `--metadata-hash none` exactly matches the checked-in Lean creation/runtime byte - arrays. The solc storage layout matches the spec, including the singleton, owners/modules - mappings, nonce/threshold counters, approved-hash mappings, and fixed assembly slots for fallback - handler, guard, and module guard. The spec models receive/fallback behavior, modern ABI decoding, - checked arithmetic, high-level-call `EXTCODESIZE` guards where solc emits them, ecrecover's - zero-address empty-return behavior, module/guard calls, and Safe's storage-access helper via raw - EVM slots. Events and revert payloads are omitted consistently with the framework's current - abstraction. No benchmark-local semantic blocker is currently known; expected proof work is - dispatcher routing, storage-layout/raw-slot lemmas, signature-check paths, module/guard external - calls, checked arithmetic, and low-level call reasoning. - -- `Auction`: handed off. Target theorem: - `auctionContractCorrect`. Fresh solc 0.8.23 output with optimizer runs 200, Shanghai EVM, and - `--metadata-hash none` exactly matches the checked-in Lean creation/runtime byte arrays. The - benchmark-local source closure contains the Nouns interfaces, OpenZeppelin upgradeable v4.4.0 - bases, and OpenZeppelin contracts v4.9.6 interfaces needed to reproduce the artifacts. The solc - storage layout matches the spec, including OZ gap slots and packed `auction.settled` at slot 211 - offset 20. The spec models the OZ `initializer` top-level/nested flag behavior, checked - arithmetic, the `mint` try/catch with `Error(string)` ABI-payload validation, high-level-call - `EXTCODESIZE` guards on `deposit`, `burn`, and `transferFrom`, and the ignored-but-decoded WETH - `transfer` bool return. No benchmark-local semantic blocker is currently known; expected proof - work is binary-search dispatcher routing, OZ initializer/reentrancy modifier traces, try/catch - return/revert decoding, packed storage updates, checked arithmetic, and external-call reasoning. - -- `UniswapV3Pool`: handed off. Target theorem: - `Benchmarks.UniswapV3Pool.uniswapV3PoolContractCorrect`. Large stress benchmark with - constructor-set immutables and complex pool paths; proof work should expect substantial selector, - immutable-code, external-call, and body-trace engineering. - -- `Klima`: ready for proof, not yet handed off. Target theorem: - `Benchmarks.Klima.klimaContractCorrect`. Fresh solc 0.7.5 output with optimizer runs 200 and - `--metadata-hash none` exactly matches the checked-in Lean creation/runtime byte arrays, and the - solc storage layout matches the spec. There are no immutables, so the creation bytecode returns the - runtime verbatim (byte offset 757). The KlimaDAO `KlimaToken` is the full inherited ERC20 + - EIP-2612 permit + `Ownable`/`VaultOwned` + `TWAPOracleUpdater` contract. The spec models the - compact-string `_name`/`_symbol` storage (pre-0.8 total decode), the `EnumerableSet.AddressSet` - `_values`/`_indexes` slots with `push`/swap-and-pop `remove`, `SafeMath` checked arithmetic, the - `_beforeTokenTransfer` hook's `EXTCODESIZE`-guarded `twapOracle.updateTWAP` external call on every - balance-moving path, and the `ecrecover`/EIP-712 `permit`. Events are omitted consistently with the - framework's log abstraction. No benchmark-local semantic blocker is currently known; expected proof - work is binary-search dispatcher routing, mapping/dynamic-array slot lemmas, compact-string layout, - `SafeMath` checked arithmetic, the guarded external call on transfer/mint/burn, and the - precompile/ABI `permit` lemmas. - -## Scaffolded, not yet handed off - -- None currently. - -## Needs prep before handoff - -- `UniswapV2Router02`: not ready for unsupervised handoff. Large scaffold with immutables, payable - receive, dynamic arrays, loops, `CREATE2` address derivation, raw TransferHelper calls, and many - typed external calls. Needs a focused semantic audit before agent assignment. - -- `CompoundIII/Comet`: not ready for unsupervised handoff. A parameterized immutable-aware wrapper - exists, but the constructor spec still has placeholders for `numAssets`, asset-list creation, - constructor validation, and constructor external-call wiring. Several runtime protocol bodies - also remain source-level scaffolds or placeholders rather than proof-ready specs. +# Benchmarks + +Real-world contracts used to evaluate the framework at scale. The layout separates finished work +from prepared targets: + +- **This directory** holds benchmarks whose refinement proof is complete (top-level + `…ContractCorrect` theorem, no `sorry`), with one exception noted below. +- **`Scaffolds/`** holds benchmarks that are prepared for proving but not yet + proved: the Sol⁻ specification, the exact compiled bytecode, the verified + jump-destination table, and the top-level theorem statements (as `sorry` + stubs) are checked in and compile (`lake build Benchmarks.Scaffolds`), so a + proving agent can start immediately. NOte that the specification may need + further adjustments to match the bytecode exactly. + +Sizes are bytes of checked-in `runtime.hex`. + +## Completed + +| Benchmark | Upstream source | solc | Runtime bytes | Top-level theorem | +|---|---|---|---|---| +| `WETH9` | Canonical mainnet WETH | 0.5.16 | 1763 | `weth9ContractCorrect` | +| `Dss/Dai` | MakerDAO `makerdao/dss` | 0.6.12 | 4011 | `daiContractCorrect` | +| `Dss/Vat` | MakerDAO `makerdao/dss` | 0.6.12 | 6965 | `vatContractCorrect` | +| `Dss/Vow` | MakerDAO `makerdao/dss` | 0.6.12 | 5150 | `vowContractCorrect` | +| `Dss/Pot` | MakerDAO `makerdao/dss` | 0.6.12 | 2595 | `potContractCorrect` | +| `Dss/Jug` | MakerDAO `makerdao/dss` | 0.6.12 | 2440 | `jugContractCorrect` | +| `Dss/Spot` | MakerDAO `makerdao/dss` | 0.6.12 | 2178 | `spotContractCorrect` | +| `Dss/Cat` | MakerDAO `makerdao/dss` | 0.6.12 | 3873 | `catContractCorrect` | +| `Dss/Dog` | MakerDAO `makerdao/dss` | 0.6.12 | 4745 | `dogContractCorrect` | +| `Dss/Cure` | MakerDAO `makerdao/dss` | 0.6.12 | 3875 | `cureContractCorrect` | +| `Dss/End` | MakerDAO `makerdao/dss` | 0.6.12 | 10265 | `endContractCorrect` | +| `Dss/Flapper` | MakerDAO `makerdao/dss` | 0.6.12 | 5008 | `flapperContractCorrect` | +| `Dss/Flipper` | MakerDAO `makerdao/dss` | 0.6.12 | 6386 | `flipperContractCorrect` | +| `Dss/Flopper` | MakerDAO `makerdao/dss` | 0.6.12 | 4780 | `flopperContractCorrect` | +| `Dss/GemJoin` | MakerDAO `makerdao/dss` (`join.sol`) | 0.6.12 | 2022 | `gemJoinContractCorrect` | +| `Dss/DaiJoin` | MakerDAO `makerdao/dss` (`join.sol`) | 0.6.12 | 1733 | `daiJoinContractCorrect` | +| `Dss/LinearDecrease` | MakerDAO `makerdao/dss` (`abaci.sol`) | 0.6.12 | 1128 | `linearDecreaseContractCorrect` | +| `Dss/StairstepExponentialDecrease` | MakerDAO `makerdao/dss` (`abaci.sol`) | 0.6.12 | 1433 | `stairstepExponentialDecreaseContractCorrect` | +| `Dss/ExponentialDecrease` | MakerDAO `makerdao/dss` (`abaci.sol`) | 0.6.12 | 1321 | `exponentialDecreaseContractCorrect` | +| `Dss/Clipper` | MakerDAO `makerdao/dss` | 0.6.12 | 9360 | `clipperContractCorrect` — **in progress**| + +`Dss/Clipper` stays here rather than in `Scaffolds/` because it completes the Dss suite and its +proof is substantially under way. + +## Scaffolds + +| Benchmark | Upstream source | solc | Runtime bytes | +|---|---|---|---| +| `Scaffolds/Safe` | Safe (Gnosis Safe) | 0.8.35 | 11874 | +| `Scaffolds/Klima` | KlimaDAO `KlimaToken` | 0.7.5 | 6975 | +| `Scaffolds/Auction` | Nouns auction house | 0.8.23 | 6150 | +| `Scaffolds/ERC721` | Compact ERC721 core | 0.8.35 | 1482 | +| `Scaffolds/EAS/Attester` | Ethereum Attestation Service | 0.8.26 | 3186 | +| `Scaffolds/CometRewards` | Compound III | 0.8.15 via-IR | 4063 | +| `Scaffolds/Comet` | Compound III | 0.8.15 via-IR | 18655 | +| `Scaffolds/VestingWallet` | OpenZeppelin Contracts | 0.8.35 | 2277 | +| `Scaffolds/TimelockController` | OpenZeppelin Contracts | 0.8.35 | 6509 | +| `Scaffolds/UniswapV3Pool` | `Uniswap/v3-core` | 0.7.6 | 22142 | +| `Scaffolds/UniswapV2Router02` | `Uniswap/v2-periphery` | 0.6.6 | 21955 | + +`Scaffolds/CompoundIII/` and `Scaffolds/OpenZeppelinBench/` hold source closures shared by the +respective scaffolds. + +## File conventions + +Each benchmark directory contains: + +- `Spec.lean` — the Sol⁻ contract: storage layout, transitions, typed external-call hooks. +- `SpecSyntax.lean` — the same spec in Solidity-like surface syntax, proved equal to `Spec.lean`. +- `Bytecode.lean` — the compiled creation/runtime bytecode as Lean byte arrays with the verified + jump-destination table. +- `Trusted.lean` — the per-contract trusted base: the contract's 4-byte function selectors as + axioms (concrete keccak values cannot be computed inside Lean; `ffi.keccak256` is an opaque + extern function), plus occasional data-slot constants of the same kind. +- `Constructor.lean` / `Correct.lean` — constructor and runtime equivalence; `…ContractCorrect` + bundles both. In `Scaffolds/` these are `sorry` stubs. +- Artifacts: `runtime.hex`, `creation.hex`, `*.abi.json`, `*.storage.json`, `sources.sha256` + (pins the upstream sources), and `contracts/` (the exact source closure used to reproduce the + bytecode). Compiler version and flags are recorded per benchmark in its own `README.md` where + present. diff --git a/Benchmarks/Scaffolds.lean b/Benchmarks/Scaffolds.lean new file mode 100644 index 00000000..7d723129 --- /dev/null +++ b/Benchmarks/Scaffolds.lean @@ -0,0 +1,11 @@ +import Benchmarks.Scaffolds.Auction.Correct +import Benchmarks.Scaffolds.Comet.Correct +import Benchmarks.Scaffolds.CometRewards.Correct +import Benchmarks.Scaffolds.EAS.Attester.Correct +import Benchmarks.Scaffolds.ERC721.Correct +import Benchmarks.Scaffolds.Klima.Correct +import Benchmarks.Scaffolds.Safe.Correct +import Benchmarks.Scaffolds.TimelockController.Correct +import Benchmarks.Scaffolds.UniswapV2Router02.Correct +import Benchmarks.Scaffolds.UniswapV3Pool.Correct +import Benchmarks.Scaffolds.VestingWallet.Correct diff --git a/Benchmarks/Auction/Bytecode.lean b/Benchmarks/Scaffolds/Auction/Bytecode.lean similarity index 99% rename from Benchmarks/Auction/Bytecode.lean rename to Benchmarks/Scaffolds/Auction/Bytecode.lean index d8d4c2b9..54d9315e 100644 --- a/Benchmarks/Auction/Bytecode.lean +++ b/Benchmarks/Scaffolds/Auction/Bytecode.lean @@ -1,4 +1,4 @@ -import Benchmarks.Auction.Spec +import Benchmarks.Scaffolds.Auction.Spec import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Benchmarks/Auction/Constructor.lean b/Benchmarks/Scaffolds/Auction/Constructor.lean similarity index 91% rename from Benchmarks/Auction/Constructor.lean rename to Benchmarks/Scaffolds/Auction/Constructor.lean index 8d80b24e..943c643b 100644 --- a/Benchmarks/Auction/Constructor.lean +++ b/Benchmarks/Scaffolds/Auction/Constructor.lean @@ -1,4 +1,4 @@ -import Benchmarks.Auction.Bytecode +import Benchmarks.Scaffolds.Auction.Bytecode import Solm.Equiv /-! diff --git a/Benchmarks/Auction/Correct.lean b/Benchmarks/Scaffolds/Auction/Correct.lean similarity index 93% rename from Benchmarks/Auction/Correct.lean rename to Benchmarks/Scaffolds/Auction/Correct.lean index da0b2df6..46461a2c 100644 --- a/Benchmarks/Auction/Correct.lean +++ b/Benchmarks/Scaffolds/Auction/Correct.lean @@ -1,4 +1,4 @@ -import Benchmarks.Auction.Constructor +import Benchmarks.Scaffolds.Auction.Constructor import Solm.Equiv /-! diff --git a/Benchmarks/Auction/NounsAuctionHouse.abi.json b/Benchmarks/Scaffolds/Auction/NounsAuctionHouse.abi.json similarity index 100% rename from Benchmarks/Auction/NounsAuctionHouse.abi.json rename to Benchmarks/Scaffolds/Auction/NounsAuctionHouse.abi.json diff --git a/Benchmarks/Auction/NounsAuctionHouse.sol b/Benchmarks/Scaffolds/Auction/NounsAuctionHouse.sol similarity index 100% rename from Benchmarks/Auction/NounsAuctionHouse.sol rename to Benchmarks/Scaffolds/Auction/NounsAuctionHouse.sol diff --git a/Benchmarks/Auction/NounsAuctionHouse.storage.json b/Benchmarks/Scaffolds/Auction/NounsAuctionHouse.storage.json similarity index 100% rename from Benchmarks/Auction/NounsAuctionHouse.storage.json rename to Benchmarks/Scaffolds/Auction/NounsAuctionHouse.storage.json diff --git a/Benchmarks/Auction/Spec.lean b/Benchmarks/Scaffolds/Auction/Spec.lean similarity index 100% rename from Benchmarks/Auction/Spec.lean rename to Benchmarks/Scaffolds/Auction/Spec.lean diff --git a/Benchmarks/Auction/SpecSyntax.lean b/Benchmarks/Scaffolds/Auction/SpecSyntax.lean similarity index 99% rename from Benchmarks/Auction/SpecSyntax.lean rename to Benchmarks/Scaffolds/Auction/SpecSyntax.lean index cd32f5ba..0135ed68 100644 --- a/Benchmarks/Auction/SpecSyntax.lean +++ b/Benchmarks/Scaffolds/Auction/SpecSyntax.lean @@ -1,4 +1,4 @@ -import Benchmarks.Auction.Spec +import Benchmarks.Scaffolds.Auction.Spec import Solm.Notation /-! diff --git a/Benchmarks/Auction/creation.hex b/Benchmarks/Scaffolds/Auction/creation.hex similarity index 100% rename from Benchmarks/Auction/creation.hex rename to Benchmarks/Scaffolds/Auction/creation.hex diff --git a/Benchmarks/Auction/interfaces/INounsAuctionHouse.sol b/Benchmarks/Scaffolds/Auction/interfaces/INounsAuctionHouse.sol similarity index 100% rename from Benchmarks/Auction/interfaces/INounsAuctionHouse.sol rename to Benchmarks/Scaffolds/Auction/interfaces/INounsAuctionHouse.sol diff --git a/Benchmarks/Auction/interfaces/INounsDescriptorMinimal.sol b/Benchmarks/Scaffolds/Auction/interfaces/INounsDescriptorMinimal.sol similarity index 100% rename from Benchmarks/Auction/interfaces/INounsDescriptorMinimal.sol rename to Benchmarks/Scaffolds/Auction/interfaces/INounsDescriptorMinimal.sol diff --git a/Benchmarks/Auction/interfaces/INounsSeeder.sol b/Benchmarks/Scaffolds/Auction/interfaces/INounsSeeder.sol similarity index 100% rename from Benchmarks/Auction/interfaces/INounsSeeder.sol rename to Benchmarks/Scaffolds/Auction/interfaces/INounsSeeder.sol diff --git a/Benchmarks/Auction/interfaces/INounsToken.sol b/Benchmarks/Scaffolds/Auction/interfaces/INounsToken.sol similarity index 100% rename from Benchmarks/Auction/interfaces/INounsToken.sol rename to Benchmarks/Scaffolds/Auction/interfaces/INounsToken.sol diff --git a/Benchmarks/Auction/interfaces/IWETH.sol b/Benchmarks/Scaffolds/Auction/interfaces/IWETH.sol similarity index 100% rename from Benchmarks/Auction/interfaces/IWETH.sol rename to Benchmarks/Scaffolds/Auction/interfaces/IWETH.sol diff --git a/Benchmarks/Auction/runtime.hex b/Benchmarks/Scaffolds/Auction/runtime.hex similarity index 100% rename from Benchmarks/Auction/runtime.hex rename to Benchmarks/Scaffolds/Auction/runtime.hex diff --git a/Benchmarks/Auction/sources.sha256 b/Benchmarks/Scaffolds/Auction/sources.sha256 similarity index 100% rename from Benchmarks/Auction/sources.sha256 rename to Benchmarks/Scaffolds/Auction/sources.sha256 diff --git a/Benchmarks/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol b/Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol similarity index 100% rename from Benchmarks/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol rename to Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol diff --git a/Benchmarks/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol b/Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol similarity index 100% rename from Benchmarks/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol rename to Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol diff --git a/Benchmarks/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/security/PausableUpgradeable.sol b/Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/security/PausableUpgradeable.sol similarity index 100% rename from Benchmarks/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/security/PausableUpgradeable.sol rename to Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/security/PausableUpgradeable.sol diff --git a/Benchmarks/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/security/ReentrancyGuardUpgradeable.sol b/Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/security/ReentrancyGuardUpgradeable.sol similarity index 100% rename from Benchmarks/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/security/ReentrancyGuardUpgradeable.sol rename to Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/security/ReentrancyGuardUpgradeable.sol diff --git a/Benchmarks/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol b/Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol similarity index 100% rename from Benchmarks/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol rename to Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol diff --git a/Benchmarks/Auction/vendor/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol b/Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol similarity index 100% rename from Benchmarks/Auction/vendor/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol rename to Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol diff --git a/Benchmarks/Auction/vendor/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol b/Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol similarity index 100% rename from Benchmarks/Auction/vendor/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol rename to Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol diff --git a/Benchmarks/Auction/vendor/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol b/Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol similarity index 100% rename from Benchmarks/Auction/vendor/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol rename to Benchmarks/Scaffolds/Auction/vendor/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol diff --git a/Benchmarks/CompoundIII/Comet/Bytecode.lean b/Benchmarks/Scaffolds/Comet/Bytecode.lean similarity index 99% rename from Benchmarks/CompoundIII/Comet/Bytecode.lean rename to Benchmarks/Scaffolds/Comet/Bytecode.lean index 3a9f7474..eb766fe1 100644 --- a/Benchmarks/CompoundIII/Comet/Bytecode.lean +++ b/Benchmarks/Scaffolds/Comet/Bytecode.lean @@ -1,4 +1,4 @@ -import Benchmarks.CompoundIII.Comet.Spec +import Benchmarks.Scaffolds.Comet.Spec import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Benchmarks/CompoundIII/Comet/CometWithExtendedAssetList.abi.json b/Benchmarks/Scaffolds/Comet/CometWithExtendedAssetList.abi.json similarity index 100% rename from Benchmarks/CompoundIII/Comet/CometWithExtendedAssetList.abi.json rename to Benchmarks/Scaffolds/Comet/CometWithExtendedAssetList.abi.json diff --git a/Benchmarks/CompoundIII/Comet/CometWithExtendedAssetList.sol.ast.json b/Benchmarks/Scaffolds/Comet/CometWithExtendedAssetList.sol.ast.json similarity index 100% rename from Benchmarks/CompoundIII/Comet/CometWithExtendedAssetList.sol.ast.json rename to Benchmarks/Scaffolds/Comet/CometWithExtendedAssetList.sol.ast.json diff --git a/Benchmarks/CompoundIII/Comet/CometWithExtendedAssetList.storage.json b/Benchmarks/Scaffolds/Comet/CometWithExtendedAssetList.storage.json similarity index 100% rename from Benchmarks/CompoundIII/Comet/CometWithExtendedAssetList.storage.json rename to Benchmarks/Scaffolds/Comet/CometWithExtendedAssetList.storage.json diff --git a/Benchmarks/CompoundIII/Comet/Constructor.lean b/Benchmarks/Scaffolds/Comet/Constructor.lean similarity index 93% rename from Benchmarks/CompoundIII/Comet/Constructor.lean rename to Benchmarks/Scaffolds/Comet/Constructor.lean index 57b6da11..53bd5f2f 100644 --- a/Benchmarks/CompoundIII/Comet/Constructor.lean +++ b/Benchmarks/Scaffolds/Comet/Constructor.lean @@ -1,4 +1,4 @@ -import Benchmarks.CompoundIII.Comet.Bytecode +import Benchmarks.Scaffolds.Comet.Bytecode import Solm.Equiv /-! diff --git a/Benchmarks/CompoundIII/Comet/Correct.lean b/Benchmarks/Scaffolds/Comet/Correct.lean similarity index 96% rename from Benchmarks/CompoundIII/Comet/Correct.lean rename to Benchmarks/Scaffolds/Comet/Correct.lean index 73a1982b..5e9a8ecc 100644 --- a/Benchmarks/CompoundIII/Comet/Correct.lean +++ b/Benchmarks/Scaffolds/Comet/Correct.lean @@ -1,4 +1,4 @@ -import Benchmarks.CompoundIII.Comet.Constructor +import Benchmarks.Scaffolds.Comet.Constructor import Solm.Equiv /-! diff --git a/Benchmarks/CompoundIII/Comet/Immutables.lean b/Benchmarks/Scaffolds/Comet/Immutables.lean similarity index 100% rename from Benchmarks/CompoundIII/Comet/Immutables.lean rename to Benchmarks/Scaffolds/Comet/Immutables.lean diff --git a/Benchmarks/CompoundIII/Comet/README.md b/Benchmarks/Scaffolds/Comet/README.md similarity index 100% rename from Benchmarks/CompoundIII/Comet/README.md rename to Benchmarks/Scaffolds/Comet/README.md diff --git a/Benchmarks/CompoundIII/Comet/Spec.lean b/Benchmarks/Scaffolds/Comet/Spec.lean similarity index 99% rename from Benchmarks/CompoundIII/Comet/Spec.lean rename to Benchmarks/Scaffolds/Comet/Spec.lean index 831b1ed2..f82001d8 100644 --- a/Benchmarks/CompoundIII/Comet/Spec.lean +++ b/Benchmarks/Scaffolds/Comet/Spec.lean @@ -1,4 +1,4 @@ -import Benchmarks.CompoundIII.Comet.Immutables +import Benchmarks.Scaffolds.Comet.Immutables import Solm.Semantics import Solm.SolidityLayout diff --git a/Benchmarks/CompoundIII/Comet/SpecSyntax.lean b/Benchmarks/Scaffolds/Comet/SpecSyntax.lean similarity index 99% rename from Benchmarks/CompoundIII/Comet/SpecSyntax.lean rename to Benchmarks/Scaffolds/Comet/SpecSyntax.lean index 8be10c08..259bfbc0 100644 --- a/Benchmarks/CompoundIII/Comet/SpecSyntax.lean +++ b/Benchmarks/Scaffolds/Comet/SpecSyntax.lean @@ -1,4 +1,4 @@ -import Benchmarks.CompoundIII.Comet.Spec +import Benchmarks.Scaffolds.Comet.Spec import Solm.Notation /-! diff --git a/Benchmarks/CompoundIII/Comet/creation.hex b/Benchmarks/Scaffolds/Comet/creation.hex similarity index 100% rename from Benchmarks/CompoundIII/Comet/creation.hex rename to Benchmarks/Scaffolds/Comet/creation.hex diff --git a/Benchmarks/CompoundIII/Comet/runtime.hex b/Benchmarks/Scaffolds/Comet/runtime.hex similarity index 100% rename from Benchmarks/CompoundIII/Comet/runtime.hex rename to Benchmarks/Scaffolds/Comet/runtime.hex diff --git a/Benchmarks/CompoundIII/CometRewards/Bytecode.lean b/Benchmarks/Scaffolds/CometRewards/Bytecode.lean similarity index 99% rename from Benchmarks/CompoundIII/CometRewards/Bytecode.lean rename to Benchmarks/Scaffolds/CometRewards/Bytecode.lean index a7b2c6ef..29f6550c 100644 --- a/Benchmarks/CompoundIII/CometRewards/Bytecode.lean +++ b/Benchmarks/Scaffolds/CometRewards/Bytecode.lean @@ -1,4 +1,4 @@ -import Benchmarks.CompoundIII.CometRewards.Spec +import Benchmarks.Scaffolds.CometRewards.Spec import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Benchmarks/CompoundIII/CometRewards/CometRewards.abi.json b/Benchmarks/Scaffolds/CometRewards/CometRewards.abi.json similarity index 100% rename from Benchmarks/CompoundIII/CometRewards/CometRewards.abi.json rename to Benchmarks/Scaffolds/CometRewards/CometRewards.abi.json diff --git a/Benchmarks/CompoundIII/CometRewards/CometRewards.sol.ast.json b/Benchmarks/Scaffolds/CometRewards/CometRewards.sol.ast.json similarity index 100% rename from Benchmarks/CompoundIII/CometRewards/CometRewards.sol.ast.json rename to Benchmarks/Scaffolds/CometRewards/CometRewards.sol.ast.json diff --git a/Benchmarks/CompoundIII/CometRewards/CometRewards.storage.json b/Benchmarks/Scaffolds/CometRewards/CometRewards.storage.json similarity index 100% rename from Benchmarks/CompoundIII/CometRewards/CometRewards.storage.json rename to Benchmarks/Scaffolds/CometRewards/CometRewards.storage.json diff --git a/Benchmarks/Scaffolds/CometRewards/Constructor.lean b/Benchmarks/Scaffolds/CometRewards/Constructor.lean new file mode 100644 index 00000000..83a36ca6 --- /dev/null +++ b/Benchmarks/Scaffolds/CometRewards/Constructor.lean @@ -0,0 +1,19 @@ +import Benchmarks.Scaffolds.CometRewards.Bytecode +import Solm.Equiv + +/-! +# Compound III CometRewards constructor correctness stub + +The creation bytecode stores the deployer as `governor` and returns the runtime. The +constructor-equivalence proof is the benchmark target. +-/ + +open Solm ABI Ethereum Ethereum.EVM + +namespace Benchmarks.CompoundIII.CometRewards + +theorem cometRewardsConstructorCorrect : + constructorEquivalence config cometRewardsCreationBytecode contract cometRewardsBytecode := by + sorry + +end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/Scaffolds/CometRewards/Correct.lean b/Benchmarks/Scaffolds/CometRewards/Correct.lean new file mode 100644 index 00000000..eac7bdfb --- /dev/null +++ b/Benchmarks/Scaffolds/CometRewards/Correct.lean @@ -0,0 +1,23 @@ +import Benchmarks.Scaffolds.CometRewards.Constructor +import Solm.Equiv + +/-! +# Compound III CometRewards benchmark correctness stub + +Runtime equivalence of the via-IR CometRewards dispatcher against its spec. Proofs are the +benchmark target. +-/ + +open Solm ABI Ethereum Ethereum.EVM + +namespace Benchmarks.CompoundIII.CometRewards + +theorem cometRewardsCorrect : + runtimeEquivalence config cometRewardsBytecode contract := by + sorry + +theorem cometRewardsContractCorrect : + contractEquivalence config cometRewardsCreationBytecode cometRewardsBytecode contract := + contractEquivalence.intro cometRewardsConstructorCorrect cometRewardsCorrect + +end Benchmarks.CompoundIII.CometRewards diff --git a/Benchmarks/CompoundIII/CometRewards/README.md b/Benchmarks/Scaffolds/CometRewards/README.md similarity index 100% rename from Benchmarks/CompoundIII/CometRewards/README.md rename to Benchmarks/Scaffolds/CometRewards/README.md diff --git a/Benchmarks/CompoundIII/CometRewards/Spec.lean b/Benchmarks/Scaffolds/CometRewards/Spec.lean similarity index 100% rename from Benchmarks/CompoundIII/CometRewards/Spec.lean rename to Benchmarks/Scaffolds/CometRewards/Spec.lean diff --git a/Benchmarks/CompoundIII/CometRewards/SpecSyntax.lean b/Benchmarks/Scaffolds/CometRewards/SpecSyntax.lean similarity index 99% rename from Benchmarks/CompoundIII/CometRewards/SpecSyntax.lean rename to Benchmarks/Scaffolds/CometRewards/SpecSyntax.lean index 49530d6a..2e941a00 100644 --- a/Benchmarks/CompoundIII/CometRewards/SpecSyntax.lean +++ b/Benchmarks/Scaffolds/CometRewards/SpecSyntax.lean @@ -1,4 +1,4 @@ -import Benchmarks.CompoundIII.CometRewards.Spec +import Benchmarks.Scaffolds.CometRewards.Spec import Solm.Notation /-! diff --git a/Benchmarks/CompoundIII/CometRewards/Trusted.lean b/Benchmarks/Scaffolds/CometRewards/Trusted.lean similarity index 98% rename from Benchmarks/CompoundIII/CometRewards/Trusted.lean rename to Benchmarks/Scaffolds/CometRewards/Trusted.lean index 03198c02..af627fb0 100644 --- a/Benchmarks/CompoundIII/CometRewards/Trusted.lean +++ b/Benchmarks/Scaffolds/CometRewards/Trusted.lean @@ -1,4 +1,4 @@ -import Benchmarks.CompoundIII.CometRewards.Bytecode +import Benchmarks.Scaffolds.CometRewards.Bytecode import Solm.Semantics open Solm Ethereum Ethereum.EVM diff --git a/Benchmarks/CompoundIII/CometRewards/creation.hex b/Benchmarks/Scaffolds/CometRewards/creation.hex similarity index 100% rename from Benchmarks/CompoundIII/CometRewards/creation.hex rename to Benchmarks/Scaffolds/CometRewards/creation.hex diff --git a/Benchmarks/CompoundIII/CometRewards/runtime.hex b/Benchmarks/Scaffolds/CometRewards/runtime.hex similarity index 100% rename from Benchmarks/CompoundIII/CometRewards/runtime.hex rename to Benchmarks/Scaffolds/CometRewards/runtime.hex diff --git a/Benchmarks/CompoundIII/README.md b/Benchmarks/Scaffolds/CompoundIII/README.md similarity index 100% rename from Benchmarks/CompoundIII/README.md rename to Benchmarks/Scaffolds/CompoundIII/README.md diff --git a/Benchmarks/CompoundIII/contracts/CometConfiguration.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/CometConfiguration.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/CometConfiguration.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/CometConfiguration.sol diff --git a/Benchmarks/CompoundIII/contracts/CometCore.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/CometCore.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/CometCore.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/CometCore.sol diff --git a/Benchmarks/CompoundIII/contracts/CometExtInterface.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/CometExtInterface.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/CometExtInterface.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/CometExtInterface.sol diff --git a/Benchmarks/CompoundIII/contracts/CometInterface.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/CometInterface.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/CometInterface.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/CometInterface.sol diff --git a/Benchmarks/CompoundIII/contracts/CometMainInterface.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/CometMainInterface.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/CometMainInterface.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/CometMainInterface.sol diff --git a/Benchmarks/CompoundIII/contracts/CometMath.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/CometMath.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/CometMath.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/CometMath.sol diff --git a/Benchmarks/CompoundIII/contracts/CometRewards.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/CometRewards.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/CometRewards.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/CometRewards.sol diff --git a/Benchmarks/CompoundIII/contracts/CometStorage.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/CometStorage.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/CometStorage.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/CometStorage.sol diff --git a/Benchmarks/CompoundIII/contracts/CometWithExtendedAssetList.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/CometWithExtendedAssetList.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/CometWithExtendedAssetList.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/CometWithExtendedAssetList.sol diff --git a/Benchmarks/CompoundIII/contracts/interfaces/ERC20.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/interfaces/ERC20.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/interfaces/ERC20.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/interfaces/ERC20.sol diff --git a/Benchmarks/CompoundIII/contracts/interfaces/IAssetList.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/interfaces/IAssetList.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/interfaces/IAssetList.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/interfaces/IAssetList.sol diff --git a/Benchmarks/CompoundIII/contracts/interfaces/IAssetListFactory.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/interfaces/IAssetListFactory.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/interfaces/IAssetListFactory.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/interfaces/IAssetListFactory.sol diff --git a/Benchmarks/CompoundIII/contracts/interfaces/IAssetListFactoryHolder.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/interfaces/IAssetListFactoryHolder.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/interfaces/IAssetListFactoryHolder.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/interfaces/IAssetListFactoryHolder.sol diff --git a/Benchmarks/CompoundIII/contracts/interfaces/IERC20NonStandard.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/interfaces/IERC20NonStandard.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/interfaces/IERC20NonStandard.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/interfaces/IERC20NonStandard.sol diff --git a/Benchmarks/CompoundIII/contracts/interfaces/IPriceFeed.sol b/Benchmarks/Scaffolds/CompoundIII/contracts/interfaces/IPriceFeed.sol similarity index 100% rename from Benchmarks/CompoundIII/contracts/interfaces/IPriceFeed.sol rename to Benchmarks/Scaffolds/CompoundIII/contracts/interfaces/IPriceFeed.sol diff --git a/Benchmarks/CompoundIII/sources.sha256 b/Benchmarks/Scaffolds/CompoundIII/sources.sha256 similarity index 100% rename from Benchmarks/CompoundIII/sources.sha256 rename to Benchmarks/Scaffolds/CompoundIII/sources.sha256 diff --git a/Benchmarks/EAS/Attester/Attester.abi.json b/Benchmarks/Scaffolds/EAS/Attester/Attester.abi.json similarity index 100% rename from Benchmarks/EAS/Attester/Attester.abi.json rename to Benchmarks/Scaffolds/EAS/Attester/Attester.abi.json diff --git a/Benchmarks/EAS/Attester/Attester.sol.ast.json b/Benchmarks/Scaffolds/EAS/Attester/Attester.sol.ast.json similarity index 100% rename from Benchmarks/EAS/Attester/Attester.sol.ast.json rename to Benchmarks/Scaffolds/EAS/Attester/Attester.sol.ast.json diff --git a/Benchmarks/EAS/Attester/Attester.storage.json b/Benchmarks/Scaffolds/EAS/Attester/Attester.storage.json similarity index 100% rename from Benchmarks/EAS/Attester/Attester.storage.json rename to Benchmarks/Scaffolds/EAS/Attester/Attester.storage.json diff --git a/Benchmarks/EAS/Attester/Bytecode.lean b/Benchmarks/Scaffolds/EAS/Attester/Bytecode.lean similarity index 99% rename from Benchmarks/EAS/Attester/Bytecode.lean rename to Benchmarks/Scaffolds/EAS/Attester/Bytecode.lean index 6aa6d11e..30aad427 100644 --- a/Benchmarks/EAS/Attester/Bytecode.lean +++ b/Benchmarks/Scaffolds/EAS/Attester/Bytecode.lean @@ -1,4 +1,4 @@ -import Benchmarks.EAS.Attester.Spec +import Benchmarks.Scaffolds.EAS.Attester.Spec import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Benchmarks/Scaffolds/EAS/Attester/Constructor.lean b/Benchmarks/Scaffolds/EAS/Attester/Constructor.lean new file mode 100644 index 00000000..032e4939 --- /dev/null +++ b/Benchmarks/Scaffolds/EAS/Attester/Constructor.lean @@ -0,0 +1,20 @@ +import Benchmarks.Scaffolds.EAS.Attester.Bytecode +import Solm.Equiv + +/-! +# EAS Attester constructor correctness stub + +The creation bytecode deploys the runtime template with the immutable `_eas` patched in. The +constructor-equivalence proof is the benchmark target. +-/ + +open Solm ABI Ethereum Ethereum.EVM Benchmarks.EAS.Attester.Immutables + +namespace Benchmarks.EAS.Attester + +theorem attesterConstructorCorrect (v : AttesterImmutables) : + constructorEquivalenceWith (config v) attesterCreationBytecode (contract v) + (runtimeCodeOf attesterBytecode) := by + sorry + +end Benchmarks.EAS.Attester diff --git a/Benchmarks/Scaffolds/EAS/Attester/Correct.lean b/Benchmarks/Scaffolds/EAS/Attester/Correct.lean new file mode 100644 index 00000000..fdfb51aa --- /dev/null +++ b/Benchmarks/Scaffolds/EAS/Attester/Correct.lean @@ -0,0 +1,26 @@ +import Benchmarks.Scaffolds.EAS.Attester.Constructor +import Solm.Equiv + +/-! +# EAS Attester benchmark correctness stub + +For each immutable value `v`, the deployed runtime is the solc template patched with `_eas`, and +runtime equivalence is stated against `contract v`. Proofs are the benchmark target. +-/ + +open Solm ABI Ethereum Ethereum.EVM Benchmarks.EAS.Attester.Immutables + +namespace Benchmarks.EAS.Attester + +theorem attesterCorrect (v : AttesterImmutables) {code : ByteArray} + (hcode : patchRuntime attesterBytecode (patches v) = some code) : + runtimeEquivalence (config v) code (contract v) := by + sorry + +theorem attesterContractCorrect (v : AttesterImmutables) {code : ByteArray} + (hcode : patchRuntime attesterBytecode (patches v) = some code) : + contractEquivalenceWith (config v) attesterCreationBytecode code (contract v) + (runtimeCodeOf attesterBytecode) := + contractEquivalenceWith.intro (attesterConstructorCorrect v) (attesterCorrect v hcode) + +end Benchmarks.EAS.Attester diff --git a/Benchmarks/EAS/Attester/Immutables.lean b/Benchmarks/Scaffolds/EAS/Attester/Immutables.lean similarity index 100% rename from Benchmarks/EAS/Attester/Immutables.lean rename to Benchmarks/Scaffolds/EAS/Attester/Immutables.lean diff --git a/Benchmarks/EAS/Attester/README.md b/Benchmarks/Scaffolds/EAS/Attester/README.md similarity index 100% rename from Benchmarks/EAS/Attester/README.md rename to Benchmarks/Scaffolds/EAS/Attester/README.md diff --git a/Benchmarks/EAS/Attester/Spec.lean b/Benchmarks/Scaffolds/EAS/Attester/Spec.lean similarity index 99% rename from Benchmarks/EAS/Attester/Spec.lean rename to Benchmarks/Scaffolds/EAS/Attester/Spec.lean index 23f87c07..82f72ab5 100644 --- a/Benchmarks/EAS/Attester/Spec.lean +++ b/Benchmarks/Scaffolds/EAS/Attester/Spec.lean @@ -1,6 +1,6 @@ import Solm.Semantics import Solm.SolidityLayout -import Benchmarks.EAS.Attester.Immutables +import Benchmarks.Scaffolds.EAS.Attester.Immutables /-! # EAS Attester benchmark spec diff --git a/Benchmarks/EAS/Attester/SpecSyntax.lean b/Benchmarks/Scaffolds/EAS/Attester/SpecSyntax.lean similarity index 98% rename from Benchmarks/EAS/Attester/SpecSyntax.lean rename to Benchmarks/Scaffolds/EAS/Attester/SpecSyntax.lean index 0fef9ea5..82c46a46 100644 --- a/Benchmarks/EAS/Attester/SpecSyntax.lean +++ b/Benchmarks/Scaffolds/EAS/Attester/SpecSyntax.lean @@ -1,4 +1,4 @@ -import Benchmarks.EAS.Attester.Spec +import Benchmarks.Scaffolds.EAS.Attester.Spec import Solm.Notation /-! diff --git a/Benchmarks/EAS/Attester/Trusted.lean b/Benchmarks/Scaffolds/EAS/Attester/Trusted.lean similarity index 96% rename from Benchmarks/EAS/Attester/Trusted.lean rename to Benchmarks/Scaffolds/EAS/Attester/Trusted.lean index 5ba507de..0112a245 100644 --- a/Benchmarks/EAS/Attester/Trusted.lean +++ b/Benchmarks/Scaffolds/EAS/Attester/Trusted.lean @@ -1,4 +1,4 @@ -import Benchmarks.EAS.Attester.Bytecode +import Benchmarks.Scaffolds.EAS.Attester.Bytecode import Reasoning.Dispatch /-! diff --git a/Benchmarks/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/Common.sol b/Benchmarks/Scaffolds/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/Common.sol similarity index 100% rename from Benchmarks/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/Common.sol rename to Benchmarks/Scaffolds/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/Common.sol diff --git a/Benchmarks/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/IEAS.sol b/Benchmarks/Scaffolds/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/IEAS.sol similarity index 100% rename from Benchmarks/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/IEAS.sol rename to Benchmarks/Scaffolds/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/IEAS.sol diff --git a/Benchmarks/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/ISchemaRegistry.sol b/Benchmarks/Scaffolds/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/ISchemaRegistry.sol similarity index 100% rename from Benchmarks/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/ISchemaRegistry.sol rename to Benchmarks/Scaffolds/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/ISchemaRegistry.sol diff --git a/Benchmarks/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/ISemver.sol b/Benchmarks/Scaffolds/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/ISemver.sol similarity index 100% rename from Benchmarks/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/ISemver.sol rename to Benchmarks/Scaffolds/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/ISemver.sol diff --git a/Benchmarks/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/resolver/ISchemaResolver.sol b/Benchmarks/Scaffolds/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/resolver/ISchemaResolver.sol similarity index 100% rename from Benchmarks/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/resolver/ISchemaResolver.sol rename to Benchmarks/Scaffolds/EAS/Attester/contracts/@ethereum-attestation-service/eas-contracts/contracts/resolver/ISchemaResolver.sol diff --git a/Benchmarks/EAS/Attester/contracts/Attester.sol b/Benchmarks/Scaffolds/EAS/Attester/contracts/Attester.sol similarity index 100% rename from Benchmarks/EAS/Attester/contracts/Attester.sol rename to Benchmarks/Scaffolds/EAS/Attester/contracts/Attester.sol diff --git a/Benchmarks/EAS/Attester/creation.hex b/Benchmarks/Scaffolds/EAS/Attester/creation.hex similarity index 100% rename from Benchmarks/EAS/Attester/creation.hex rename to Benchmarks/Scaffolds/EAS/Attester/creation.hex diff --git a/Benchmarks/EAS/Attester/runtime.hex b/Benchmarks/Scaffolds/EAS/Attester/runtime.hex similarity index 100% rename from Benchmarks/EAS/Attester/runtime.hex rename to Benchmarks/Scaffolds/EAS/Attester/runtime.hex diff --git a/Benchmarks/EAS/Attester/sources.sha256 b/Benchmarks/Scaffolds/EAS/Attester/sources.sha256 similarity index 100% rename from Benchmarks/EAS/Attester/sources.sha256 rename to Benchmarks/Scaffolds/EAS/Attester/sources.sha256 diff --git a/Benchmarks/ERC721/Bytecode.lean b/Benchmarks/Scaffolds/ERC721/Bytecode.lean similarity index 99% rename from Benchmarks/ERC721/Bytecode.lean rename to Benchmarks/Scaffolds/ERC721/Bytecode.lean index 7e831100..2d80e0ca 100644 --- a/Benchmarks/ERC721/Bytecode.lean +++ b/Benchmarks/Scaffolds/ERC721/Bytecode.lean @@ -1,4 +1,4 @@ -import Benchmarks.ERC721.Spec +import Benchmarks.Scaffolds.ERC721.Spec import Solm.Semantics import Reasoning.JumpDest diff --git a/Benchmarks/ERC721/Constructor.lean b/Benchmarks/Scaffolds/ERC721/Constructor.lean similarity index 91% rename from Benchmarks/ERC721/Constructor.lean rename to Benchmarks/Scaffolds/ERC721/Constructor.lean index f25aa332..238a205b 100644 --- a/Benchmarks/ERC721/Constructor.lean +++ b/Benchmarks/Scaffolds/ERC721/Constructor.lean @@ -1,4 +1,4 @@ -import Benchmarks.ERC721.Bytecode +import Benchmarks.Scaffolds.ERC721.Bytecode import Solm.Equiv /-! diff --git a/Benchmarks/ERC721/Correct.lean b/Benchmarks/Scaffolds/ERC721/Correct.lean similarity index 98% rename from Benchmarks/ERC721/Correct.lean rename to Benchmarks/Scaffolds/ERC721/Correct.lean index 1e410d92..6fcd9768 100644 --- a/Benchmarks/ERC721/Correct.lean +++ b/Benchmarks/Scaffolds/ERC721/Correct.lean @@ -1,6 +1,6 @@ -import Benchmarks.ERC721.Bytecode -import Benchmarks.ERC721.Constructor -import Benchmarks.ERC721.Spec +import Benchmarks.Scaffolds.ERC721.Bytecode +import Benchmarks.Scaffolds.ERC721.Constructor +import Benchmarks.Scaffolds.ERC721.Spec import Reasoning.ABI import Reasoning.Stepping import Reasoning.Reach diff --git a/Benchmarks/ERC721/ERC721.abi.json b/Benchmarks/Scaffolds/ERC721/ERC721.abi.json similarity index 100% rename from Benchmarks/ERC721/ERC721.abi.json rename to Benchmarks/Scaffolds/ERC721/ERC721.abi.json diff --git a/Benchmarks/ERC721/ERC721.sol b/Benchmarks/Scaffolds/ERC721/ERC721.sol similarity index 100% rename from Benchmarks/ERC721/ERC721.sol rename to Benchmarks/Scaffolds/ERC721/ERC721.sol diff --git a/Benchmarks/ERC721/ERC721.storage.json b/Benchmarks/Scaffolds/ERC721/ERC721.storage.json similarity index 100% rename from Benchmarks/ERC721/ERC721.storage.json rename to Benchmarks/Scaffolds/ERC721/ERC721.storage.json diff --git a/Benchmarks/ERC721/Spec.lean b/Benchmarks/Scaffolds/ERC721/Spec.lean similarity index 100% rename from Benchmarks/ERC721/Spec.lean rename to Benchmarks/Scaffolds/ERC721/Spec.lean diff --git a/Benchmarks/ERC721/SpecSyntax.lean b/Benchmarks/Scaffolds/ERC721/SpecSyntax.lean similarity index 98% rename from Benchmarks/ERC721/SpecSyntax.lean rename to Benchmarks/Scaffolds/ERC721/SpecSyntax.lean index 00e5b2d4..e187858a 100644 --- a/Benchmarks/ERC721/SpecSyntax.lean +++ b/Benchmarks/Scaffolds/ERC721/SpecSyntax.lean @@ -1,4 +1,4 @@ -import Benchmarks.ERC721.Spec +import Benchmarks.Scaffolds.ERC721.Spec import Solm.Notation /-! diff --git a/Benchmarks/ERC721/creation.hex b/Benchmarks/Scaffolds/ERC721/creation.hex similarity index 100% rename from Benchmarks/ERC721/creation.hex rename to Benchmarks/Scaffolds/ERC721/creation.hex diff --git a/Benchmarks/ERC721/runtime.hex b/Benchmarks/Scaffolds/ERC721/runtime.hex similarity index 100% rename from Benchmarks/ERC721/runtime.hex rename to Benchmarks/Scaffolds/ERC721/runtime.hex diff --git a/Benchmarks/ERC721/sources.sha256 b/Benchmarks/Scaffolds/ERC721/sources.sha256 similarity index 100% rename from Benchmarks/ERC721/sources.sha256 rename to Benchmarks/Scaffolds/ERC721/sources.sha256 diff --git a/Benchmarks/Klima/Bytecode.lean b/Benchmarks/Scaffolds/Klima/Bytecode.lean similarity index 99% rename from Benchmarks/Klima/Bytecode.lean rename to Benchmarks/Scaffolds/Klima/Bytecode.lean index ba29e317..a03c3822 100644 --- a/Benchmarks/Klima/Bytecode.lean +++ b/Benchmarks/Scaffolds/Klima/Bytecode.lean @@ -1,4 +1,4 @@ -import Benchmarks.Klima.Spec +import Benchmarks.Scaffolds.Klima.Spec import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Benchmarks/Klima/Constructor.lean b/Benchmarks/Scaffolds/Klima/Constructor.lean similarity index 93% rename from Benchmarks/Klima/Constructor.lean rename to Benchmarks/Scaffolds/Klima/Constructor.lean index f2fc997a..07d63ddb 100644 --- a/Benchmarks/Klima/Constructor.lean +++ b/Benchmarks/Scaffolds/Klima/Constructor.lean @@ -1,4 +1,4 @@ -import Benchmarks.Klima.Bytecode +import Benchmarks.Scaffolds.Klima.Bytecode import Solm.Equiv /-! diff --git a/Benchmarks/Klima/Correct.lean b/Benchmarks/Scaffolds/Klima/Correct.lean similarity index 94% rename from Benchmarks/Klima/Correct.lean rename to Benchmarks/Scaffolds/Klima/Correct.lean index 9006b34a..f186911d 100644 --- a/Benchmarks/Klima/Correct.lean +++ b/Benchmarks/Scaffolds/Klima/Correct.lean @@ -1,4 +1,4 @@ -import Benchmarks.Klima.Constructor +import Benchmarks.Scaffolds.Klima.Constructor import Solm.Equiv /-! diff --git a/Benchmarks/Klima/KlimaToken.abi.json b/Benchmarks/Scaffolds/Klima/KlimaToken.abi.json similarity index 100% rename from Benchmarks/Klima/KlimaToken.abi.json rename to Benchmarks/Scaffolds/Klima/KlimaToken.abi.json diff --git a/Benchmarks/Klima/KlimaToken.storage.json b/Benchmarks/Scaffolds/Klima/KlimaToken.storage.json similarity index 100% rename from Benchmarks/Klima/KlimaToken.storage.json rename to Benchmarks/Scaffolds/Klima/KlimaToken.storage.json diff --git a/Benchmarks/Klima/README.md b/Benchmarks/Scaffolds/Klima/README.md similarity index 100% rename from Benchmarks/Klima/README.md rename to Benchmarks/Scaffolds/Klima/README.md diff --git a/Benchmarks/Klima/Spec.lean b/Benchmarks/Scaffolds/Klima/Spec.lean similarity index 99% rename from Benchmarks/Klima/Spec.lean rename to Benchmarks/Scaffolds/Klima/Spec.lean index 39c36ba7..22fedbd4 100644 --- a/Benchmarks/Klima/Spec.lean +++ b/Benchmarks/Scaffolds/Klima/Spec.lean @@ -1,6 +1,6 @@ import Solm.Semantics import Solm.SolidityLayout -import Benchmarks.Klima.StringLayout +import Benchmarks.Scaffolds.Klima.StringLayout /-! # KlimaDAO KlimaToken benchmark spec diff --git a/Benchmarks/Klima/SpecSyntax.lean b/Benchmarks/Scaffolds/Klima/SpecSyntax.lean similarity index 99% rename from Benchmarks/Klima/SpecSyntax.lean rename to Benchmarks/Scaffolds/Klima/SpecSyntax.lean index 03e5cc6b..9ed88452 100644 --- a/Benchmarks/Klima/SpecSyntax.lean +++ b/Benchmarks/Scaffolds/Klima/SpecSyntax.lean @@ -1,4 +1,4 @@ -import Benchmarks.Klima.Spec +import Benchmarks.Scaffolds.Klima.Spec import Solm.Notation /-! diff --git a/Benchmarks/Klima/StringLayout.lean b/Benchmarks/Scaffolds/Klima/StringLayout.lean similarity index 100% rename from Benchmarks/Klima/StringLayout.lean rename to Benchmarks/Scaffolds/Klima/StringLayout.lean diff --git a/Benchmarks/Klima/contracts/KlimaToken.sol b/Benchmarks/Scaffolds/Klima/contracts/KlimaToken.sol similarity index 100% rename from Benchmarks/Klima/contracts/KlimaToken.sol rename to Benchmarks/Scaffolds/Klima/contracts/KlimaToken.sol diff --git a/Benchmarks/Klima/creation.hex b/Benchmarks/Scaffolds/Klima/creation.hex similarity index 100% rename from Benchmarks/Klima/creation.hex rename to Benchmarks/Scaffolds/Klima/creation.hex diff --git a/Benchmarks/Klima/runtime.hex b/Benchmarks/Scaffolds/Klima/runtime.hex similarity index 100% rename from Benchmarks/Klima/runtime.hex rename to Benchmarks/Scaffolds/Klima/runtime.hex diff --git a/Benchmarks/Klima/sources.sha256 b/Benchmarks/Scaffolds/Klima/sources.sha256 similarity index 100% rename from Benchmarks/Klima/sources.sha256 rename to Benchmarks/Scaffolds/Klima/sources.sha256 diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/AccessControl.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/AccessControl.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/AccessControl.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/AccessControl.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/IAccessControl.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/IAccessControl.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/IAccessControl.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/IAccessControl.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/Ownable.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/Ownable.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/Ownable.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/access/Ownable.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/finance/VestingWallet.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/finance/VestingWallet.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/finance/VestingWallet.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/finance/VestingWallet.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/governance/TimelockController.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/governance/TimelockController.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/governance/TimelockController.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/governance/TimelockController.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC1363.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC1363.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC1363.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC1363.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC165.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC165.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC165.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC165.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC20.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC20.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC20.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC20.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC20Metadata.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC20Metadata.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC20Metadata.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/interfaces/IERC20Metadata.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC1155/IERC1155Receiver.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC1155/IERC1155Receiver.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC1155/IERC1155Receiver.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC1155/IERC1155Receiver.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC1155/utils/ERC1155Holder.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC1155/utils/ERC1155Holder.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC1155/utils/ERC1155Holder.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC1155/utils/ERC1155Holder.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC721/utils/ERC721Holder.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC721/utils/ERC721Holder.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC721/utils/ERC721Holder.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/token/ERC721/utils/ERC721Holder.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Address.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Address.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Address.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Address.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Context.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Context.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Context.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Context.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Errors.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Errors.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Errors.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/Errors.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/LowLevelCall.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/LowLevelCall.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/LowLevelCall.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/LowLevelCall.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol diff --git a/Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol b/Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol rename to Benchmarks/Scaffolds/OpenZeppelinBench/vendor/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol diff --git a/Benchmarks/Safe/Bytecode.lean b/Benchmarks/Scaffolds/Safe/Bytecode.lean similarity index 99% rename from Benchmarks/Safe/Bytecode.lean rename to Benchmarks/Scaffolds/Safe/Bytecode.lean index d6824ce5..a79a4964 100644 --- a/Benchmarks/Safe/Bytecode.lean +++ b/Benchmarks/Scaffolds/Safe/Bytecode.lean @@ -1,4 +1,4 @@ -import Benchmarks.Safe.Spec +import Benchmarks.Scaffolds.Safe.Spec import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Benchmarks/Safe/Constructor.lean b/Benchmarks/Scaffolds/Safe/Constructor.lean similarity index 91% rename from Benchmarks/Safe/Constructor.lean rename to Benchmarks/Scaffolds/Safe/Constructor.lean index a1e880e3..7efd4602 100644 --- a/Benchmarks/Safe/Constructor.lean +++ b/Benchmarks/Scaffolds/Safe/Constructor.lean @@ -1,4 +1,4 @@ -import Benchmarks.Safe.Bytecode +import Benchmarks.Scaffolds.Safe.Bytecode import Solm.Equiv /-! diff --git a/Benchmarks/Safe/Correct.lean b/Benchmarks/Scaffolds/Safe/Correct.lean similarity index 93% rename from Benchmarks/Safe/Correct.lean rename to Benchmarks/Scaffolds/Safe/Correct.lean index 0146e18d..e6d609a3 100644 --- a/Benchmarks/Safe/Correct.lean +++ b/Benchmarks/Scaffolds/Safe/Correct.lean @@ -1,4 +1,4 @@ -import Benchmarks.Safe.Constructor +import Benchmarks.Scaffolds.Safe.Constructor import Solm.Equiv /-! diff --git a/Benchmarks/Safe/README.md b/Benchmarks/Scaffolds/Safe/README.md similarity index 100% rename from Benchmarks/Safe/README.md rename to Benchmarks/Scaffolds/Safe/README.md diff --git a/Benchmarks/Safe/Safe.abi.json b/Benchmarks/Scaffolds/Safe/Safe.abi.json similarity index 100% rename from Benchmarks/Safe/Safe.abi.json rename to Benchmarks/Scaffolds/Safe/Safe.abi.json diff --git a/Benchmarks/Safe/Spec.lean b/Benchmarks/Scaffolds/Safe/Spec.lean similarity index 100% rename from Benchmarks/Safe/Spec.lean rename to Benchmarks/Scaffolds/Safe/Spec.lean diff --git a/Benchmarks/Safe/SpecSyntax.lean b/Benchmarks/Scaffolds/Safe/SpecSyntax.lean similarity index 99% rename from Benchmarks/Safe/SpecSyntax.lean rename to Benchmarks/Scaffolds/Safe/SpecSyntax.lean index edea5e9b..9d491f8f 100644 --- a/Benchmarks/Safe/SpecSyntax.lean +++ b/Benchmarks/Scaffolds/Safe/SpecSyntax.lean @@ -1,4 +1,4 @@ -import Benchmarks.Safe.Spec +import Benchmarks.Scaffolds.Safe.Spec import Solm.Notation /-! diff --git a/Benchmarks/Safe/contracts/Safe.sol b/Benchmarks/Scaffolds/Safe/contracts/Safe.sol similarity index 100% rename from Benchmarks/Safe/contracts/Safe.sol rename to Benchmarks/Scaffolds/Safe/contracts/Safe.sol diff --git a/Benchmarks/Safe/contracts/SafeL2.sol b/Benchmarks/Scaffolds/Safe/contracts/SafeL2.sol similarity index 100% rename from Benchmarks/Safe/contracts/SafeL2.sol rename to Benchmarks/Scaffolds/Safe/contracts/SafeL2.sol diff --git a/Benchmarks/Safe/contracts/accessors/SimulateTxAccessor.sol b/Benchmarks/Scaffolds/Safe/contracts/accessors/SimulateTxAccessor.sol similarity index 100% rename from Benchmarks/Safe/contracts/accessors/SimulateTxAccessor.sol rename to Benchmarks/Scaffolds/Safe/contracts/accessors/SimulateTxAccessor.sol diff --git a/Benchmarks/Safe/contracts/base/Executor.sol b/Benchmarks/Scaffolds/Safe/contracts/base/Executor.sol similarity index 100% rename from Benchmarks/Safe/contracts/base/Executor.sol rename to Benchmarks/Scaffolds/Safe/contracts/base/Executor.sol diff --git a/Benchmarks/Safe/contracts/base/FallbackManager.sol b/Benchmarks/Scaffolds/Safe/contracts/base/FallbackManager.sol similarity index 100% rename from Benchmarks/Safe/contracts/base/FallbackManager.sol rename to Benchmarks/Scaffolds/Safe/contracts/base/FallbackManager.sol diff --git a/Benchmarks/Safe/contracts/base/GuardManager.sol b/Benchmarks/Scaffolds/Safe/contracts/base/GuardManager.sol similarity index 100% rename from Benchmarks/Safe/contracts/base/GuardManager.sol rename to Benchmarks/Scaffolds/Safe/contracts/base/GuardManager.sol diff --git a/Benchmarks/Safe/contracts/base/ModuleManager.sol b/Benchmarks/Scaffolds/Safe/contracts/base/ModuleManager.sol similarity index 100% rename from Benchmarks/Safe/contracts/base/ModuleManager.sol rename to Benchmarks/Scaffolds/Safe/contracts/base/ModuleManager.sol diff --git a/Benchmarks/Safe/contracts/base/OwnerManager.sol b/Benchmarks/Scaffolds/Safe/contracts/base/OwnerManager.sol similarity index 100% rename from Benchmarks/Safe/contracts/base/OwnerManager.sol rename to Benchmarks/Scaffolds/Safe/contracts/base/OwnerManager.sol diff --git a/Benchmarks/Safe/contracts/common/EIP7702.sol b/Benchmarks/Scaffolds/Safe/contracts/common/EIP7702.sol similarity index 100% rename from Benchmarks/Safe/contracts/common/EIP7702.sol rename to Benchmarks/Scaffolds/Safe/contracts/common/EIP7702.sol diff --git a/Benchmarks/Safe/contracts/common/EIP7951.sol b/Benchmarks/Scaffolds/Safe/contracts/common/EIP7951.sol similarity index 100% rename from Benchmarks/Safe/contracts/common/EIP7951.sol rename to Benchmarks/Scaffolds/Safe/contracts/common/EIP7951.sol diff --git a/Benchmarks/Safe/contracts/common/ErrorMessage.sol b/Benchmarks/Scaffolds/Safe/contracts/common/ErrorMessage.sol similarity index 100% rename from Benchmarks/Safe/contracts/common/ErrorMessage.sol rename to Benchmarks/Scaffolds/Safe/contracts/common/ErrorMessage.sol diff --git a/Benchmarks/Safe/contracts/common/NativeCurrencyPaymentFallback.sol b/Benchmarks/Scaffolds/Safe/contracts/common/NativeCurrencyPaymentFallback.sol similarity index 100% rename from Benchmarks/Safe/contracts/common/NativeCurrencyPaymentFallback.sol rename to Benchmarks/Scaffolds/Safe/contracts/common/NativeCurrencyPaymentFallback.sol diff --git a/Benchmarks/Safe/contracts/common/SecuredSignatureValidator.sol b/Benchmarks/Scaffolds/Safe/contracts/common/SecuredSignatureValidator.sol similarity index 100% rename from Benchmarks/Safe/contracts/common/SecuredSignatureValidator.sol rename to Benchmarks/Scaffolds/Safe/contracts/common/SecuredSignatureValidator.sol diff --git a/Benchmarks/Safe/contracts/common/SecuredTokenTransfer.sol b/Benchmarks/Scaffolds/Safe/contracts/common/SecuredTokenTransfer.sol similarity index 100% rename from Benchmarks/Safe/contracts/common/SecuredTokenTransfer.sol rename to Benchmarks/Scaffolds/Safe/contracts/common/SecuredTokenTransfer.sol diff --git a/Benchmarks/Safe/contracts/common/SelfAuthorized.sol b/Benchmarks/Scaffolds/Safe/contracts/common/SelfAuthorized.sol similarity index 100% rename from Benchmarks/Safe/contracts/common/SelfAuthorized.sol rename to Benchmarks/Scaffolds/Safe/contracts/common/SelfAuthorized.sol diff --git a/Benchmarks/Safe/contracts/common/SignatureDecoder.sol b/Benchmarks/Scaffolds/Safe/contracts/common/SignatureDecoder.sol similarity index 100% rename from Benchmarks/Safe/contracts/common/SignatureDecoder.sol rename to Benchmarks/Scaffolds/Safe/contracts/common/SignatureDecoder.sol diff --git a/Benchmarks/Safe/contracts/common/Singleton.sol b/Benchmarks/Scaffolds/Safe/contracts/common/Singleton.sol similarity index 100% rename from Benchmarks/Safe/contracts/common/Singleton.sol rename to Benchmarks/Scaffolds/Safe/contracts/common/Singleton.sol diff --git a/Benchmarks/Safe/contracts/common/StorageAccessible.sol b/Benchmarks/Scaffolds/Safe/contracts/common/StorageAccessible.sol similarity index 100% rename from Benchmarks/Safe/contracts/common/StorageAccessible.sol rename to Benchmarks/Scaffolds/Safe/contracts/common/StorageAccessible.sol diff --git a/Benchmarks/Safe/contracts/examples/README.md b/Benchmarks/Scaffolds/Safe/contracts/examples/README.md similarity index 100% rename from Benchmarks/Safe/contracts/examples/README.md rename to Benchmarks/Scaffolds/Safe/contracts/examples/README.md diff --git a/Benchmarks/Safe/contracts/examples/guards/BaseGuard.sol b/Benchmarks/Scaffolds/Safe/contracts/examples/guards/BaseGuard.sol similarity index 100% rename from Benchmarks/Safe/contracts/examples/guards/BaseGuard.sol rename to Benchmarks/Scaffolds/Safe/contracts/examples/guards/BaseGuard.sol diff --git a/Benchmarks/Safe/contracts/examples/guards/DebugTransactionGuard.sol b/Benchmarks/Scaffolds/Safe/contracts/examples/guards/DebugTransactionGuard.sol similarity index 100% rename from Benchmarks/Safe/contracts/examples/guards/DebugTransactionGuard.sol rename to Benchmarks/Scaffolds/Safe/contracts/examples/guards/DebugTransactionGuard.sol diff --git a/Benchmarks/Safe/contracts/examples/guards/DelegateCallTransactionGuard.sol b/Benchmarks/Scaffolds/Safe/contracts/examples/guards/DelegateCallTransactionGuard.sol similarity index 100% rename from Benchmarks/Safe/contracts/examples/guards/DelegateCallTransactionGuard.sol rename to Benchmarks/Scaffolds/Safe/contracts/examples/guards/DelegateCallTransactionGuard.sol diff --git a/Benchmarks/Safe/contracts/examples/guards/OnlyOwnersGuard.sol b/Benchmarks/Scaffolds/Safe/contracts/examples/guards/OnlyOwnersGuard.sol similarity index 100% rename from Benchmarks/Safe/contracts/examples/guards/OnlyOwnersGuard.sol rename to Benchmarks/Scaffolds/Safe/contracts/examples/guards/OnlyOwnersGuard.sol diff --git a/Benchmarks/Safe/contracts/examples/guards/ReentrancyTransactionGuard.sol b/Benchmarks/Scaffolds/Safe/contracts/examples/guards/ReentrancyTransactionGuard.sol similarity index 100% rename from Benchmarks/Safe/contracts/examples/guards/ReentrancyTransactionGuard.sol rename to Benchmarks/Scaffolds/Safe/contracts/examples/guards/ReentrancyTransactionGuard.sol diff --git a/Benchmarks/Safe/contracts/examples/libraries/Migrate_1_3_0_to_1_2_0.sol b/Benchmarks/Scaffolds/Safe/contracts/examples/libraries/Migrate_1_3_0_to_1_2_0.sol similarity index 100% rename from Benchmarks/Safe/contracts/examples/libraries/Migrate_1_3_0_to_1_2_0.sol rename to Benchmarks/Scaffolds/Safe/contracts/examples/libraries/Migrate_1_3_0_to_1_2_0.sol diff --git a/Benchmarks/Safe/contracts/external/SafeMath.sol b/Benchmarks/Scaffolds/Safe/contracts/external/SafeMath.sol similarity index 100% rename from Benchmarks/Safe/contracts/external/SafeMath.sol rename to Benchmarks/Scaffolds/Safe/contracts/external/SafeMath.sol diff --git a/Benchmarks/Safe/contracts/handler/CompatibilityFallbackHandler.sol b/Benchmarks/Scaffolds/Safe/contracts/handler/CompatibilityFallbackHandler.sol similarity index 100% rename from Benchmarks/Safe/contracts/handler/CompatibilityFallbackHandler.sol rename to Benchmarks/Scaffolds/Safe/contracts/handler/CompatibilityFallbackHandler.sol diff --git a/Benchmarks/Safe/contracts/handler/ExtensibleFallbackHandler.sol b/Benchmarks/Scaffolds/Safe/contracts/handler/ExtensibleFallbackHandler.sol similarity index 100% rename from Benchmarks/Safe/contracts/handler/ExtensibleFallbackHandler.sol rename to Benchmarks/Scaffolds/Safe/contracts/handler/ExtensibleFallbackHandler.sol diff --git a/Benchmarks/Safe/contracts/handler/HandlerContext.sol b/Benchmarks/Scaffolds/Safe/contracts/handler/HandlerContext.sol similarity index 100% rename from Benchmarks/Safe/contracts/handler/HandlerContext.sol rename to Benchmarks/Scaffolds/Safe/contracts/handler/HandlerContext.sol diff --git a/Benchmarks/Safe/contracts/handler/TokenCallbackHandler.sol b/Benchmarks/Scaffolds/Safe/contracts/handler/TokenCallbackHandler.sol similarity index 100% rename from Benchmarks/Safe/contracts/handler/TokenCallbackHandler.sol rename to Benchmarks/Scaffolds/Safe/contracts/handler/TokenCallbackHandler.sol diff --git a/Benchmarks/Safe/contracts/handler/extensible/ERC165Handler.sol b/Benchmarks/Scaffolds/Safe/contracts/handler/extensible/ERC165Handler.sol similarity index 100% rename from Benchmarks/Safe/contracts/handler/extensible/ERC165Handler.sol rename to Benchmarks/Scaffolds/Safe/contracts/handler/extensible/ERC165Handler.sol diff --git a/Benchmarks/Safe/contracts/handler/extensible/ExtensibleBase.sol b/Benchmarks/Scaffolds/Safe/contracts/handler/extensible/ExtensibleBase.sol similarity index 100% rename from Benchmarks/Safe/contracts/handler/extensible/ExtensibleBase.sol rename to Benchmarks/Scaffolds/Safe/contracts/handler/extensible/ExtensibleBase.sol diff --git a/Benchmarks/Safe/contracts/handler/extensible/FallbackHandler.sol b/Benchmarks/Scaffolds/Safe/contracts/handler/extensible/FallbackHandler.sol similarity index 100% rename from Benchmarks/Safe/contracts/handler/extensible/FallbackHandler.sol rename to Benchmarks/Scaffolds/Safe/contracts/handler/extensible/FallbackHandler.sol diff --git a/Benchmarks/Safe/contracts/handler/extensible/MarshalLib.sol b/Benchmarks/Scaffolds/Safe/contracts/handler/extensible/MarshalLib.sol similarity index 100% rename from Benchmarks/Safe/contracts/handler/extensible/MarshalLib.sol rename to Benchmarks/Scaffolds/Safe/contracts/handler/extensible/MarshalLib.sol diff --git a/Benchmarks/Safe/contracts/handler/extensible/SignatureVerifierMuxer.sol b/Benchmarks/Scaffolds/Safe/contracts/handler/extensible/SignatureVerifierMuxer.sol similarity index 100% rename from Benchmarks/Safe/contracts/handler/extensible/SignatureVerifierMuxer.sol rename to Benchmarks/Scaffolds/Safe/contracts/handler/extensible/SignatureVerifierMuxer.sol diff --git a/Benchmarks/Safe/contracts/handler/extensible/TokenCallbacks.sol b/Benchmarks/Scaffolds/Safe/contracts/handler/extensible/TokenCallbacks.sol similarity index 100% rename from Benchmarks/Safe/contracts/handler/extensible/TokenCallbacks.sol rename to Benchmarks/Scaffolds/Safe/contracts/handler/extensible/TokenCallbacks.sol diff --git a/Benchmarks/Safe/contracts/interfaces/ERC1155TokenReceiver.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/ERC1155TokenReceiver.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/ERC1155TokenReceiver.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/ERC1155TokenReceiver.sol diff --git a/Benchmarks/Safe/contracts/interfaces/ERC721TokenReceiver.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/ERC721TokenReceiver.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/ERC721TokenReceiver.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/ERC721TokenReceiver.sol diff --git a/Benchmarks/Safe/contracts/interfaces/ERC777TokensRecipient.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/ERC777TokensRecipient.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/ERC777TokensRecipient.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/ERC777TokensRecipient.sol diff --git a/Benchmarks/Safe/contracts/interfaces/Enum.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/Enum.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/Enum.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/Enum.sol diff --git a/Benchmarks/Safe/contracts/interfaces/IERC165.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/IERC165.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/IERC165.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/IERC165.sol diff --git a/Benchmarks/Safe/contracts/interfaces/IFallbackManager.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/IFallbackManager.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/IFallbackManager.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/IFallbackManager.sol diff --git a/Benchmarks/Safe/contracts/interfaces/IGuardManager.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/IGuardManager.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/IGuardManager.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/IGuardManager.sol diff --git a/Benchmarks/Safe/contracts/interfaces/IModuleManager.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/IModuleManager.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/IModuleManager.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/IModuleManager.sol diff --git a/Benchmarks/Safe/contracts/interfaces/INativeCurrencyPaymentFallback.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/INativeCurrencyPaymentFallback.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/INativeCurrencyPaymentFallback.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/INativeCurrencyPaymentFallback.sol diff --git a/Benchmarks/Safe/contracts/interfaces/IOwnerManager.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/IOwnerManager.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/IOwnerManager.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/IOwnerManager.sol diff --git a/Benchmarks/Safe/contracts/interfaces/ISafe.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/ISafe.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/ISafe.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/ISafe.sol diff --git a/Benchmarks/Safe/contracts/interfaces/ISignatureValidator.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/ISignatureValidator.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/ISignatureValidator.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/ISignatureValidator.sol diff --git a/Benchmarks/Safe/contracts/interfaces/IStorageAccessible.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/IStorageAccessible.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/IStorageAccessible.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/IStorageAccessible.sol diff --git a/Benchmarks/Safe/contracts/interfaces/ViewStorageAccessible.sol b/Benchmarks/Scaffolds/Safe/contracts/interfaces/ViewStorageAccessible.sol similarity index 100% rename from Benchmarks/Safe/contracts/interfaces/ViewStorageAccessible.sol rename to Benchmarks/Scaffolds/Safe/contracts/interfaces/ViewStorageAccessible.sol diff --git a/Benchmarks/Safe/contracts/libraries/CreateCall.sol b/Benchmarks/Scaffolds/Safe/contracts/libraries/CreateCall.sol similarity index 100% rename from Benchmarks/Safe/contracts/libraries/CreateCall.sol rename to Benchmarks/Scaffolds/Safe/contracts/libraries/CreateCall.sol diff --git a/Benchmarks/Safe/contracts/libraries/MultiSend.sol b/Benchmarks/Scaffolds/Safe/contracts/libraries/MultiSend.sol similarity index 100% rename from Benchmarks/Safe/contracts/libraries/MultiSend.sol rename to Benchmarks/Scaffolds/Safe/contracts/libraries/MultiSend.sol diff --git a/Benchmarks/Safe/contracts/libraries/MultiSendCallOnly.sol b/Benchmarks/Scaffolds/Safe/contracts/libraries/MultiSendCallOnly.sol similarity index 100% rename from Benchmarks/Safe/contracts/libraries/MultiSendCallOnly.sol rename to Benchmarks/Scaffolds/Safe/contracts/libraries/MultiSendCallOnly.sol diff --git a/Benchmarks/Safe/contracts/libraries/SafeMigration.sol b/Benchmarks/Scaffolds/Safe/contracts/libraries/SafeMigration.sol similarity index 100% rename from Benchmarks/Safe/contracts/libraries/SafeMigration.sol rename to Benchmarks/Scaffolds/Safe/contracts/libraries/SafeMigration.sol diff --git a/Benchmarks/Safe/contracts/libraries/SafeStorage.sol b/Benchmarks/Scaffolds/Safe/contracts/libraries/SafeStorage.sol similarity index 100% rename from Benchmarks/Safe/contracts/libraries/SafeStorage.sol rename to Benchmarks/Scaffolds/Safe/contracts/libraries/SafeStorage.sol diff --git a/Benchmarks/Safe/contracts/libraries/SafeToL2Setup.sol b/Benchmarks/Scaffolds/Safe/contracts/libraries/SafeToL2Setup.sol similarity index 100% rename from Benchmarks/Safe/contracts/libraries/SafeToL2Setup.sol rename to Benchmarks/Scaffolds/Safe/contracts/libraries/SafeToL2Setup.sol diff --git a/Benchmarks/Safe/contracts/libraries/SignMessageLib.sol b/Benchmarks/Scaffolds/Safe/contracts/libraries/SignMessageLib.sol similarity index 100% rename from Benchmarks/Safe/contracts/libraries/SignMessageLib.sol rename to Benchmarks/Scaffolds/Safe/contracts/libraries/SignMessageLib.sol diff --git a/Benchmarks/Safe/contracts/proxies/SafeProxy.sol b/Benchmarks/Scaffolds/Safe/contracts/proxies/SafeProxy.sol similarity index 100% rename from Benchmarks/Safe/contracts/proxies/SafeProxy.sol rename to Benchmarks/Scaffolds/Safe/contracts/proxies/SafeProxy.sol diff --git a/Benchmarks/Safe/contracts/proxies/SafeProxyFactory.sol b/Benchmarks/Scaffolds/Safe/contracts/proxies/SafeProxyFactory.sol similarity index 100% rename from Benchmarks/Safe/contracts/proxies/SafeProxyFactory.sol rename to Benchmarks/Scaffolds/Safe/contracts/proxies/SafeProxyFactory.sol diff --git a/Benchmarks/Safe/contracts/test/DelegateCaller.sol b/Benchmarks/Scaffolds/Safe/contracts/test/DelegateCaller.sol similarity index 100% rename from Benchmarks/Safe/contracts/test/DelegateCaller.sol rename to Benchmarks/Scaffolds/Safe/contracts/test/DelegateCaller.sol diff --git a/Benchmarks/Safe/contracts/test/ERC1155Token.sol b/Benchmarks/Scaffolds/Safe/contracts/test/ERC1155Token.sol similarity index 100% rename from Benchmarks/Safe/contracts/test/ERC1155Token.sol rename to Benchmarks/Scaffolds/Safe/contracts/test/ERC1155Token.sol diff --git a/Benchmarks/Safe/contracts/test/ERC20Token.sol b/Benchmarks/Scaffolds/Safe/contracts/test/ERC20Token.sol similarity index 100% rename from Benchmarks/Safe/contracts/test/ERC20Token.sol rename to Benchmarks/Scaffolds/Safe/contracts/test/ERC20Token.sol diff --git a/Benchmarks/Safe/contracts/test/ERC721Token.sol b/Benchmarks/Scaffolds/Safe/contracts/test/ERC721Token.sol similarity index 100% rename from Benchmarks/Safe/contracts/test/ERC721Token.sol rename to Benchmarks/Scaffolds/Safe/contracts/test/ERC721Token.sol diff --git a/Benchmarks/Safe/contracts/test/Test4337ModuleAndHandler.sol b/Benchmarks/Scaffolds/Safe/contracts/test/Test4337ModuleAndHandler.sol similarity index 100% rename from Benchmarks/Safe/contracts/test/Test4337ModuleAndHandler.sol rename to Benchmarks/Scaffolds/Safe/contracts/test/Test4337ModuleAndHandler.sol diff --git a/Benchmarks/Safe/contracts/test/TestHandler.sol b/Benchmarks/Scaffolds/Safe/contracts/test/TestHandler.sol similarity index 100% rename from Benchmarks/Safe/contracts/test/TestHandler.sol rename to Benchmarks/Scaffolds/Safe/contracts/test/TestHandler.sol diff --git a/Benchmarks/Safe/contracts/test/TestImports.sol b/Benchmarks/Scaffolds/Safe/contracts/test/TestImports.sol similarity index 100% rename from Benchmarks/Safe/contracts/test/TestImports.sol rename to Benchmarks/Scaffolds/Safe/contracts/test/TestImports.sol diff --git a/Benchmarks/Safe/contracts/test/TestMarshalLib.sol b/Benchmarks/Scaffolds/Safe/contracts/test/TestMarshalLib.sol similarity index 100% rename from Benchmarks/Safe/contracts/test/TestMarshalLib.sol rename to Benchmarks/Scaffolds/Safe/contracts/test/TestMarshalLib.sol diff --git a/Benchmarks/Safe/contracts/test/TestNativeTokenReceiver.sol b/Benchmarks/Scaffolds/Safe/contracts/test/TestNativeTokenReceiver.sol similarity index 100% rename from Benchmarks/Safe/contracts/test/TestNativeTokenReceiver.sol rename to Benchmarks/Scaffolds/Safe/contracts/test/TestNativeTokenReceiver.sol diff --git a/Benchmarks/Safe/contracts/test/TestSafeSignatureVerifier.sol b/Benchmarks/Scaffolds/Safe/contracts/test/TestSafeSignatureVerifier.sol similarity index 100% rename from Benchmarks/Safe/contracts/test/TestSafeSignatureVerifier.sol rename to Benchmarks/Scaffolds/Safe/contracts/test/TestSafeSignatureVerifier.sol diff --git a/Benchmarks/Safe/creation.hex b/Benchmarks/Scaffolds/Safe/creation.hex similarity index 100% rename from Benchmarks/Safe/creation.hex rename to Benchmarks/Scaffolds/Safe/creation.hex diff --git a/Benchmarks/Safe/runtime.hex b/Benchmarks/Scaffolds/Safe/runtime.hex similarity index 100% rename from Benchmarks/Safe/runtime.hex rename to Benchmarks/Scaffolds/Safe/runtime.hex diff --git a/Benchmarks/Safe/sources.sha256 b/Benchmarks/Scaffolds/Safe/sources.sha256 similarity index 100% rename from Benchmarks/Safe/sources.sha256 rename to Benchmarks/Scaffolds/Safe/sources.sha256 diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Bytecode.lean b/Benchmarks/Scaffolds/TimelockController/Bytecode.lean similarity index 99% rename from Benchmarks/OpenZeppelinBench/TimelockController/Bytecode.lean rename to Benchmarks/Scaffolds/TimelockController/Bytecode.lean index f0c0e389..800b634f 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Bytecode.lean +++ b/Benchmarks/Scaffolds/TimelockController/Bytecode.lean @@ -1,4 +1,4 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Spec +import Benchmarks.Scaffolds.TimelockController.Spec import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Common.lean b/Benchmarks/Scaffolds/TimelockController/Common.lean similarity index 98% rename from Benchmarks/OpenZeppelinBench/TimelockController/Common.lean rename to Benchmarks/Scaffolds/TimelockController/Common.lean index b21edac9..76e622b1 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Common.lean +++ b/Benchmarks/Scaffolds/TimelockController/Common.lean @@ -1,4 +1,4 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Bytecode +import Benchmarks.Scaffolds.TimelockController.Bytecode import Reasoning.ABI import Reasoning.Stepping import Reasoning.Reach diff --git a/Benchmarks/Scaffolds/TimelockController/Constructor.lean b/Benchmarks/Scaffolds/TimelockController/Constructor.lean new file mode 100644 index 00000000..e4d98a4c --- /dev/null +++ b/Benchmarks/Scaffolds/TimelockController/Constructor.lean @@ -0,0 +1,21 @@ +import Benchmarks.Scaffolds.TimelockController.Bytecode +import Solm.Equiv + +/-! +# OpenZeppelin TimelockController constructor correctness stub + +The creation bytecode deploys the concrete payable wrapper with initial delay `1 days`, +`msg.sender` as admin/proposer/canceller, and `address(0)` as open executor. The +constructor-equivalence proof is the benchmark target. +-/ + +open Solm ABI Ethereum Ethereum.EVM + +namespace OpenZeppelinBench.TimelockController + +theorem timelockControllerBenchConstructorCorrect : + constructorEquivalence config timelockControllerBenchCreationBytecode contract + timelockControllerBenchBytecode := by + sorry + +end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/Scaffolds/TimelockController/Correct.lean b/Benchmarks/Scaffolds/TimelockController/Correct.lean new file mode 100644 index 00000000..8312382d --- /dev/null +++ b/Benchmarks/Scaffolds/TimelockController/Correct.lean @@ -0,0 +1,24 @@ +import Benchmarks.Scaffolds.TimelockController.Constructor +import Solm.Equiv + +/-! +# OpenZeppelin TimelockController benchmark correctness stub + +Runtime equivalence of the 28-selector binary-search dispatcher against its spec. Proofs are the +benchmark target. +-/ + +open Solm ABI Ethereum Ethereum.EVM + +namespace OpenZeppelinBench.TimelockController + +theorem timelockControllerBenchCorrect : + runtimeEquivalence config timelockControllerBenchBytecode contract := by + sorry + +theorem timelockControllerBenchContractCorrect : + contractEquivalence config timelockControllerBenchCreationBytecode + timelockControllerBenchBytecode contract := + contractEquivalence.intro timelockControllerBenchConstructorCorrect timelockControllerBenchCorrect + +end OpenZeppelinBench.TimelockController diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/README.md b/Benchmarks/Scaffolds/TimelockController/README.md similarity index 100% rename from Benchmarks/OpenZeppelinBench/TimelockController/README.md rename to Benchmarks/Scaffolds/TimelockController/README.md diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Spec.lean b/Benchmarks/Scaffolds/TimelockController/Spec.lean similarity index 100% rename from Benchmarks/OpenZeppelinBench/TimelockController/Spec.lean rename to Benchmarks/Scaffolds/TimelockController/Spec.lean diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/SpecSyntax.lean b/Benchmarks/Scaffolds/TimelockController/SpecSyntax.lean similarity index 99% rename from Benchmarks/OpenZeppelinBench/TimelockController/SpecSyntax.lean rename to Benchmarks/Scaffolds/TimelockController/SpecSyntax.lean index 9e7a0d80..a9e12c95 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/SpecSyntax.lean +++ b/Benchmarks/Scaffolds/TimelockController/SpecSyntax.lean @@ -1,4 +1,4 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Spec +import Benchmarks.Scaffolds.TimelockController.Spec import Solm.Notation /-! diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/TimelockControllerBench.abi.json b/Benchmarks/Scaffolds/TimelockController/TimelockControllerBench.abi.json similarity index 100% rename from Benchmarks/OpenZeppelinBench/TimelockController/TimelockControllerBench.abi.json rename to Benchmarks/Scaffolds/TimelockController/TimelockControllerBench.abi.json diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/TimelockControllerBench.sol b/Benchmarks/Scaffolds/TimelockController/TimelockControllerBench.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/TimelockController/TimelockControllerBench.sol rename to Benchmarks/Scaffolds/TimelockController/TimelockControllerBench.sol diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/TimelockControllerBench.storage.json b/Benchmarks/Scaffolds/TimelockController/TimelockControllerBench.storage.json similarity index 100% rename from Benchmarks/OpenZeppelinBench/TimelockController/TimelockControllerBench.storage.json rename to Benchmarks/Scaffolds/TimelockController/TimelockControllerBench.storage.json diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/Trusted.lean b/Benchmarks/Scaffolds/TimelockController/Trusted.lean similarity index 99% rename from Benchmarks/OpenZeppelinBench/TimelockController/Trusted.lean rename to Benchmarks/Scaffolds/TimelockController/Trusted.lean index dcd05273..deb765f3 100644 --- a/Benchmarks/OpenZeppelinBench/TimelockController/Trusted.lean +++ b/Benchmarks/Scaffolds/TimelockController/Trusted.lean @@ -1,4 +1,4 @@ -import Benchmarks.OpenZeppelinBench.TimelockController.Common +import Benchmarks.Scaffolds.TimelockController.Common /-! # OpenZeppelin TimelockController trusted selector facts diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/creation.hex b/Benchmarks/Scaffolds/TimelockController/creation.hex similarity index 100% rename from Benchmarks/OpenZeppelinBench/TimelockController/creation.hex rename to Benchmarks/Scaffolds/TimelockController/creation.hex diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/runtime.hex b/Benchmarks/Scaffolds/TimelockController/runtime.hex similarity index 100% rename from Benchmarks/OpenZeppelinBench/TimelockController/runtime.hex rename to Benchmarks/Scaffolds/TimelockController/runtime.hex diff --git a/Benchmarks/OpenZeppelinBench/TimelockController/sources.sha256 b/Benchmarks/Scaffolds/TimelockController/sources.sha256 similarity index 100% rename from Benchmarks/OpenZeppelinBench/TimelockController/sources.sha256 rename to Benchmarks/Scaffolds/TimelockController/sources.sha256 diff --git a/Benchmarks/UniswapV2Router02/@uniswap/lib/contracts/libraries/TransferHelper.sol b/Benchmarks/Scaffolds/UniswapV2Router02/@uniswap/lib/contracts/libraries/TransferHelper.sol similarity index 100% rename from Benchmarks/UniswapV2Router02/@uniswap/lib/contracts/libraries/TransferHelper.sol rename to Benchmarks/Scaffolds/UniswapV2Router02/@uniswap/lib/contracts/libraries/TransferHelper.sol diff --git a/Benchmarks/UniswapV2Router02/@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol b/Benchmarks/Scaffolds/UniswapV2Router02/@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol similarity index 100% rename from Benchmarks/UniswapV2Router02/@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol rename to Benchmarks/Scaffolds/UniswapV2Router02/@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol diff --git a/Benchmarks/UniswapV2Router02/@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol b/Benchmarks/Scaffolds/UniswapV2Router02/@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol similarity index 100% rename from Benchmarks/UniswapV2Router02/@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol rename to Benchmarks/Scaffolds/UniswapV2Router02/@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol diff --git a/Benchmarks/UniswapV2Router02/Bytecode.lean b/Benchmarks/Scaffolds/UniswapV2Router02/Bytecode.lean similarity index 99% rename from Benchmarks/UniswapV2Router02/Bytecode.lean rename to Benchmarks/Scaffolds/UniswapV2Router02/Bytecode.lean index f5867564..78ff59e3 100644 --- a/Benchmarks/UniswapV2Router02/Bytecode.lean +++ b/Benchmarks/Scaffolds/UniswapV2Router02/Bytecode.lean @@ -1,4 +1,4 @@ -import Benchmarks.UniswapV2Router02.Spec +import Benchmarks.Scaffolds.UniswapV2Router02.Spec import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Benchmarks/UniswapV2Router02/Constructor.lean b/Benchmarks/Scaffolds/UniswapV2Router02/Constructor.lean similarity index 93% rename from Benchmarks/UniswapV2Router02/Constructor.lean rename to Benchmarks/Scaffolds/UniswapV2Router02/Constructor.lean index aa4d8b8c..2a589560 100644 --- a/Benchmarks/UniswapV2Router02/Constructor.lean +++ b/Benchmarks/Scaffolds/UniswapV2Router02/Constructor.lean @@ -1,4 +1,4 @@ -import Benchmarks.UniswapV2Router02.Bytecode +import Benchmarks.Scaffolds.UniswapV2Router02.Bytecode import Solm.Equiv /-! diff --git a/Benchmarks/UniswapV2Router02/Correct.lean b/Benchmarks/Scaffolds/UniswapV2Router02/Correct.lean similarity index 95% rename from Benchmarks/UniswapV2Router02/Correct.lean rename to Benchmarks/Scaffolds/UniswapV2Router02/Correct.lean index 1c0855eb..0db13cf6 100644 --- a/Benchmarks/UniswapV2Router02/Correct.lean +++ b/Benchmarks/Scaffolds/UniswapV2Router02/Correct.lean @@ -1,4 +1,4 @@ -import Benchmarks.UniswapV2Router02.Constructor +import Benchmarks.Scaffolds.UniswapV2Router02.Constructor import Solm.Equiv /-! diff --git a/Benchmarks/UniswapV2Router02/Immutables.lean b/Benchmarks/Scaffolds/UniswapV2Router02/Immutables.lean similarity index 100% rename from Benchmarks/UniswapV2Router02/Immutables.lean rename to Benchmarks/Scaffolds/UniswapV2Router02/Immutables.lean diff --git a/Benchmarks/UniswapV2Router02/README.md b/Benchmarks/Scaffolds/UniswapV2Router02/README.md similarity index 100% rename from Benchmarks/UniswapV2Router02/README.md rename to Benchmarks/Scaffolds/UniswapV2Router02/README.md diff --git a/Benchmarks/UniswapV2Router02/Spec.lean b/Benchmarks/Scaffolds/UniswapV2Router02/Spec.lean similarity index 99% rename from Benchmarks/UniswapV2Router02/Spec.lean rename to Benchmarks/Scaffolds/UniswapV2Router02/Spec.lean index 1f6cdc8a..d0e13f17 100644 --- a/Benchmarks/UniswapV2Router02/Spec.lean +++ b/Benchmarks/Scaffolds/UniswapV2Router02/Spec.lean @@ -1,6 +1,6 @@ import Solm.Semantics import Solm.SolidityLayout -import Benchmarks.UniswapV2Router02.Immutables +import Benchmarks.Scaffolds.UniswapV2Router02.Immutables /-! # Uniswap V2 Router02 benchmark spec diff --git a/Benchmarks/UniswapV2Router02/SpecSyntax.lean b/Benchmarks/Scaffolds/UniswapV2Router02/SpecSyntax.lean similarity index 99% rename from Benchmarks/UniswapV2Router02/SpecSyntax.lean rename to Benchmarks/Scaffolds/UniswapV2Router02/SpecSyntax.lean index a375c37c..5ebef025 100644 --- a/Benchmarks/UniswapV2Router02/SpecSyntax.lean +++ b/Benchmarks/Scaffolds/UniswapV2Router02/SpecSyntax.lean @@ -1,4 +1,4 @@ -import Benchmarks.UniswapV2Router02.Spec +import Benchmarks.Scaffolds.UniswapV2Router02.Spec import Solm.Notation /-! diff --git a/Benchmarks/UniswapV2Router02/UniswapV2Router02.abi.json b/Benchmarks/Scaffolds/UniswapV2Router02/UniswapV2Router02.abi.json similarity index 100% rename from Benchmarks/UniswapV2Router02/UniswapV2Router02.abi.json rename to Benchmarks/Scaffolds/UniswapV2Router02/UniswapV2Router02.abi.json diff --git a/Benchmarks/UniswapV2Router02/UniswapV2Router02.sol.ast.json b/Benchmarks/Scaffolds/UniswapV2Router02/UniswapV2Router02.sol.ast.json similarity index 100% rename from Benchmarks/UniswapV2Router02/UniswapV2Router02.sol.ast.json rename to Benchmarks/Scaffolds/UniswapV2Router02/UniswapV2Router02.sol.ast.json diff --git a/Benchmarks/UniswapV2Router02/contracts/UniswapV2Router02.sol b/Benchmarks/Scaffolds/UniswapV2Router02/contracts/UniswapV2Router02.sol similarity index 100% rename from Benchmarks/UniswapV2Router02/contracts/UniswapV2Router02.sol rename to Benchmarks/Scaffolds/UniswapV2Router02/contracts/UniswapV2Router02.sol diff --git a/Benchmarks/UniswapV2Router02/contracts/interfaces/IERC20.sol b/Benchmarks/Scaffolds/UniswapV2Router02/contracts/interfaces/IERC20.sol similarity index 100% rename from Benchmarks/UniswapV2Router02/contracts/interfaces/IERC20.sol rename to Benchmarks/Scaffolds/UniswapV2Router02/contracts/interfaces/IERC20.sol diff --git a/Benchmarks/UniswapV2Router02/contracts/interfaces/IUniswapV2Router01.sol b/Benchmarks/Scaffolds/UniswapV2Router02/contracts/interfaces/IUniswapV2Router01.sol similarity index 100% rename from Benchmarks/UniswapV2Router02/contracts/interfaces/IUniswapV2Router01.sol rename to Benchmarks/Scaffolds/UniswapV2Router02/contracts/interfaces/IUniswapV2Router01.sol diff --git a/Benchmarks/UniswapV2Router02/contracts/interfaces/IUniswapV2Router02.sol b/Benchmarks/Scaffolds/UniswapV2Router02/contracts/interfaces/IUniswapV2Router02.sol similarity index 100% rename from Benchmarks/UniswapV2Router02/contracts/interfaces/IUniswapV2Router02.sol rename to Benchmarks/Scaffolds/UniswapV2Router02/contracts/interfaces/IUniswapV2Router02.sol diff --git a/Benchmarks/UniswapV2Router02/contracts/interfaces/IWETH.sol b/Benchmarks/Scaffolds/UniswapV2Router02/contracts/interfaces/IWETH.sol similarity index 100% rename from Benchmarks/UniswapV2Router02/contracts/interfaces/IWETH.sol rename to Benchmarks/Scaffolds/UniswapV2Router02/contracts/interfaces/IWETH.sol diff --git a/Benchmarks/UniswapV2Router02/contracts/libraries/SafeMath.sol b/Benchmarks/Scaffolds/UniswapV2Router02/contracts/libraries/SafeMath.sol similarity index 100% rename from Benchmarks/UniswapV2Router02/contracts/libraries/SafeMath.sol rename to Benchmarks/Scaffolds/UniswapV2Router02/contracts/libraries/SafeMath.sol diff --git a/Benchmarks/UniswapV2Router02/contracts/libraries/UniswapV2Library.sol b/Benchmarks/Scaffolds/UniswapV2Router02/contracts/libraries/UniswapV2Library.sol similarity index 100% rename from Benchmarks/UniswapV2Router02/contracts/libraries/UniswapV2Library.sol rename to Benchmarks/Scaffolds/UniswapV2Router02/contracts/libraries/UniswapV2Library.sol diff --git a/Benchmarks/UniswapV2Router02/creation.hex b/Benchmarks/Scaffolds/UniswapV2Router02/creation.hex similarity index 100% rename from Benchmarks/UniswapV2Router02/creation.hex rename to Benchmarks/Scaffolds/UniswapV2Router02/creation.hex diff --git a/Benchmarks/UniswapV2Router02/runtime.hex b/Benchmarks/Scaffolds/UniswapV2Router02/runtime.hex similarity index 100% rename from Benchmarks/UniswapV2Router02/runtime.hex rename to Benchmarks/Scaffolds/UniswapV2Router02/runtime.hex diff --git a/Benchmarks/UniswapV2Router02/sources.sha256 b/Benchmarks/Scaffolds/UniswapV2Router02/sources.sha256 similarity index 100% rename from Benchmarks/UniswapV2Router02/sources.sha256 rename to Benchmarks/Scaffolds/UniswapV2Router02/sources.sha256 diff --git a/Benchmarks/UniswapV3Pool/Bytecode.lean b/Benchmarks/Scaffolds/UniswapV3Pool/Bytecode.lean similarity index 99% rename from Benchmarks/UniswapV3Pool/Bytecode.lean rename to Benchmarks/Scaffolds/UniswapV3Pool/Bytecode.lean index 8655beba..8fd994ca 100644 --- a/Benchmarks/UniswapV3Pool/Bytecode.lean +++ b/Benchmarks/Scaffolds/UniswapV3Pool/Bytecode.lean @@ -1,4 +1,4 @@ -import Benchmarks.UniswapV3Pool.Spec +import Benchmarks.Scaffolds.UniswapV3Pool.Spec import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Benchmarks/UniswapV3Pool/Constructor.lean b/Benchmarks/Scaffolds/UniswapV3Pool/Constructor.lean similarity index 93% rename from Benchmarks/UniswapV3Pool/Constructor.lean rename to Benchmarks/Scaffolds/UniswapV3Pool/Constructor.lean index aed1aa95..74c51c07 100644 --- a/Benchmarks/UniswapV3Pool/Constructor.lean +++ b/Benchmarks/Scaffolds/UniswapV3Pool/Constructor.lean @@ -1,4 +1,4 @@ -import Benchmarks.UniswapV3Pool.Bytecode +import Benchmarks.Scaffolds.UniswapV3Pool.Bytecode import Solm.Equiv /-! diff --git a/Benchmarks/Scaffolds/UniswapV3Pool/Correct.lean b/Benchmarks/Scaffolds/UniswapV3Pool/Correct.lean new file mode 100644 index 00000000..38551558 --- /dev/null +++ b/Benchmarks/Scaffolds/UniswapV3Pool/Correct.lean @@ -0,0 +1,26 @@ +import Benchmarks.Scaffolds.UniswapV3Pool.Constructor +import Solm.Equiv + +/-! +# UniswapV3Pool benchmark correctness stub + +Parameterized over the pool's immutable values `v`: the deployed runtime is the template patched +with `v`, and runtime equivalence is stated against `contract v`. Proofs are the benchmark target. +-/ + +open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables + +namespace Benchmarks.UniswapV3Pool + +theorem uniswapV3PoolCorrect (v : PoolImmutables) {code : ByteArray} + (hcode : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : + runtimeEquivalence (config v) code (contract v) := by + sorry + +theorem uniswapV3PoolContractCorrect (v : PoolImmutables) {code : ByteArray} + (hcode : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : + contractEquivalenceWith (config v) uniswapV3PoolCreationBytecode code (contract v) + (runtimeCodeOf uniswapV3PoolBytecode) := + contractEquivalenceWith.intro (uniswapV3PoolConstructorCorrect v) (uniswapV3PoolCorrect v hcode) + +end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Immutables.lean b/Benchmarks/Scaffolds/UniswapV3Pool/Immutables.lean similarity index 100% rename from Benchmarks/UniswapV3Pool/Immutables.lean rename to Benchmarks/Scaffolds/UniswapV3Pool/Immutables.lean diff --git a/Benchmarks/UniswapV3Pool/README.md b/Benchmarks/Scaffolds/UniswapV3Pool/README.md similarity index 100% rename from Benchmarks/UniswapV3Pool/README.md rename to Benchmarks/Scaffolds/UniswapV3Pool/README.md diff --git a/Benchmarks/UniswapV3Pool/Spec.lean b/Benchmarks/Scaffolds/UniswapV3Pool/Spec.lean similarity index 99% rename from Benchmarks/UniswapV3Pool/Spec.lean rename to Benchmarks/Scaffolds/UniswapV3Pool/Spec.lean index 1bcd34da..b6510dcd 100644 --- a/Benchmarks/UniswapV3Pool/Spec.lean +++ b/Benchmarks/Scaffolds/UniswapV3Pool/Spec.lean @@ -1,6 +1,6 @@ import Solm.Semantics import Solm.SolidityLayout -import Benchmarks.UniswapV3Pool.Immutables +import Benchmarks.Scaffolds.UniswapV3Pool.Immutables /-! # UniswapV3Pool benchmark spec diff --git a/Benchmarks/UniswapV3Pool/SpecSyntax.lean b/Benchmarks/Scaffolds/UniswapV3Pool/SpecSyntax.lean similarity index 99% rename from Benchmarks/UniswapV3Pool/SpecSyntax.lean rename to Benchmarks/Scaffolds/UniswapV3Pool/SpecSyntax.lean index 111ee984..9428ea44 100644 --- a/Benchmarks/UniswapV3Pool/SpecSyntax.lean +++ b/Benchmarks/Scaffolds/UniswapV3Pool/SpecSyntax.lean @@ -1,4 +1,4 @@ -import Benchmarks.UniswapV3Pool.Spec +import Benchmarks.Scaffolds.UniswapV3Pool.Spec import Solm.Notation /-! diff --git a/Benchmarks/UniswapV3Pool/Trusted.lean b/Benchmarks/Scaffolds/UniswapV3Pool/Trusted.lean similarity index 98% rename from Benchmarks/UniswapV3Pool/Trusted.lean rename to Benchmarks/Scaffolds/UniswapV3Pool/Trusted.lean index fc266bce..9f76c593 100644 --- a/Benchmarks/UniswapV3Pool/Trusted.lean +++ b/Benchmarks/Scaffolds/UniswapV3Pool/Trusted.lean @@ -1,4 +1,4 @@ -import Benchmarks.UniswapV3Pool.Bytecode +import Benchmarks.Scaffolds.UniswapV3Pool.Bytecode import Solm.Semantics /-! diff --git a/Benchmarks/UniswapV3Pool/UniswapV3Pool.abi.json b/Benchmarks/Scaffolds/UniswapV3Pool/UniswapV3Pool.abi.json similarity index 100% rename from Benchmarks/UniswapV3Pool/UniswapV3Pool.abi.json rename to Benchmarks/Scaffolds/UniswapV3Pool/UniswapV3Pool.abi.json diff --git a/Benchmarks/UniswapV3Pool/contracts/NoDelegateCall.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/NoDelegateCall.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/NoDelegateCall.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/NoDelegateCall.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/UniswapV3Factory.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/UniswapV3Factory.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/UniswapV3Factory.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/UniswapV3Factory.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/UniswapV3Pool.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/UniswapV3Pool.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/UniswapV3Pool.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/UniswapV3Pool.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/UniswapV3PoolDeployer.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/UniswapV3PoolDeployer.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/UniswapV3PoolDeployer.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/UniswapV3PoolDeployer.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/IERC20Minimal.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/IERC20Minimal.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/IERC20Minimal.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/IERC20Minimal.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/IUniswapV3Factory.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/IUniswapV3Factory.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/IUniswapV3Factory.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/IUniswapV3Factory.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/IUniswapV3Pool.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/IUniswapV3Pool.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/IUniswapV3Pool.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/IUniswapV3Pool.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/IUniswapV3PoolDeployer.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/IUniswapV3PoolDeployer.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/IUniswapV3PoolDeployer.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/IUniswapV3PoolDeployer.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/LICENSE b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/LICENSE similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/LICENSE rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/LICENSE diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3FlashCallback.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3FlashCallback.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3FlashCallback.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3FlashCallback.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3MintCallback.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3MintCallback.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3MintCallback.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3MintCallback.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3SwapCallback.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3SwapCallback.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3SwapCallback.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/callback/IUniswapV3SwapCallback.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolActions.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolActions.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolActions.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolActions.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolDerivedState.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolDerivedState.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolDerivedState.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolDerivedState.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolEvents.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolEvents.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolEvents.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolEvents.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolState.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolState.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolState.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/interfaces/pool/IUniswapV3PoolState.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/BitMath.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/BitMath.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/BitMath.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/BitMath.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/FixedPoint128.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/FixedPoint128.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/FixedPoint128.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/FixedPoint128.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/FixedPoint96.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/FixedPoint96.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/FixedPoint96.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/FixedPoint96.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/FullMath.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/FullMath.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/FullMath.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/FullMath.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/LICENSE b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/LICENSE similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/LICENSE rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/LICENSE diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/LICENSE_MIT b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/LICENSE_MIT similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/LICENSE_MIT rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/LICENSE_MIT diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/LiquidityMath.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/LiquidityMath.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/LiquidityMath.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/LiquidityMath.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/LowGasSafeMath.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/LowGasSafeMath.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/LowGasSafeMath.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/LowGasSafeMath.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/Oracle.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/Oracle.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/Oracle.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/Oracle.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/Position.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/Position.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/Position.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/Position.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/SafeCast.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/SafeCast.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/SafeCast.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/SafeCast.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/SqrtPriceMath.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/SqrtPriceMath.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/SqrtPriceMath.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/SqrtPriceMath.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/SwapMath.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/SwapMath.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/SwapMath.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/SwapMath.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/Tick.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/Tick.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/Tick.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/Tick.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/TickBitmap.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/TickBitmap.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/TickBitmap.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/TickBitmap.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/TickMath.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/TickMath.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/TickMath.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/TickMath.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/TransferHelper.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/TransferHelper.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/TransferHelper.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/TransferHelper.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/libraries/UnsafeMath.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/UnsafeMath.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/libraries/UnsafeMath.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/libraries/UnsafeMath.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/BitMathEchidnaTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/BitMathEchidnaTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/BitMathEchidnaTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/BitMathEchidnaTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/BitMathTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/BitMathTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/BitMathTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/BitMathTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/FullMathEchidnaTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/FullMathEchidnaTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/FullMathEchidnaTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/FullMathEchidnaTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/FullMathTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/FullMathTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/FullMathTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/FullMathTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/LiquidityMathTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/LiquidityMathTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/LiquidityMathTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/LiquidityMathTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/LowGasSafeMathEchidnaTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/LowGasSafeMathEchidnaTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/LowGasSafeMathEchidnaTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/LowGasSafeMathEchidnaTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/MockTimeUniswapV3Pool.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/MockTimeUniswapV3Pool.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/MockTimeUniswapV3Pool.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/MockTimeUniswapV3Pool.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/MockTimeUniswapV3PoolDeployer.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/MockTimeUniswapV3PoolDeployer.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/MockTimeUniswapV3PoolDeployer.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/MockTimeUniswapV3PoolDeployer.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/NoDelegateCallTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/NoDelegateCallTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/NoDelegateCallTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/NoDelegateCallTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/OracleEchidnaTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/OracleEchidnaTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/OracleEchidnaTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/OracleEchidnaTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/OracleTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/OracleTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/OracleTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/OracleTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/SqrtPriceMathEchidnaTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/SqrtPriceMathEchidnaTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/SqrtPriceMathEchidnaTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/SqrtPriceMathEchidnaTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/SqrtPriceMathTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/SqrtPriceMathTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/SqrtPriceMathTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/SqrtPriceMathTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/SwapMathEchidnaTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/SwapMathEchidnaTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/SwapMathEchidnaTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/SwapMathEchidnaTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/SwapMathTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/SwapMathTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/SwapMathTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/SwapMathTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/TestERC20.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TestERC20.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/TestERC20.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TestERC20.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/TestUniswapV3Callee.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TestUniswapV3Callee.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/TestUniswapV3Callee.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TestUniswapV3Callee.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/TestUniswapV3ReentrantCallee.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TestUniswapV3ReentrantCallee.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/TestUniswapV3ReentrantCallee.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TestUniswapV3ReentrantCallee.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/TestUniswapV3Router.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TestUniswapV3Router.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/TestUniswapV3Router.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TestUniswapV3Router.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/TestUniswapV3SwapPay.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TestUniswapV3SwapPay.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/TestUniswapV3SwapPay.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TestUniswapV3SwapPay.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/TickBitmapEchidnaTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickBitmapEchidnaTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/TickBitmapEchidnaTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickBitmapEchidnaTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/TickBitmapTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickBitmapTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/TickBitmapTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickBitmapTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/TickEchidnaTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickEchidnaTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/TickEchidnaTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickEchidnaTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/TickMathEchidnaTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickMathEchidnaTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/TickMathEchidnaTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickMathEchidnaTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/TickMathTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickMathTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/TickMathTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickMathTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/TickOverflowSafetyEchidnaTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickOverflowSafetyEchidnaTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/TickOverflowSafetyEchidnaTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickOverflowSafetyEchidnaTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/TickTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/TickTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/TickTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/UniswapV3PoolSwapTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/UniswapV3PoolSwapTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/UniswapV3PoolSwapTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/UniswapV3PoolSwapTest.sol diff --git a/Benchmarks/UniswapV3Pool/contracts/test/UnsafeMathEchidnaTest.sol b/Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/UnsafeMathEchidnaTest.sol similarity index 100% rename from Benchmarks/UniswapV3Pool/contracts/test/UnsafeMathEchidnaTest.sol rename to Benchmarks/Scaffolds/UniswapV3Pool/contracts/test/UnsafeMathEchidnaTest.sol diff --git a/Benchmarks/UniswapV3Pool/creation.hex b/Benchmarks/Scaffolds/UniswapV3Pool/creation.hex similarity index 100% rename from Benchmarks/UniswapV3Pool/creation.hex rename to Benchmarks/Scaffolds/UniswapV3Pool/creation.hex diff --git a/Benchmarks/UniswapV3Pool/runtime.hex b/Benchmarks/Scaffolds/UniswapV3Pool/runtime.hex similarity index 100% rename from Benchmarks/UniswapV3Pool/runtime.hex rename to Benchmarks/Scaffolds/UniswapV3Pool/runtime.hex diff --git a/Benchmarks/UniswapV3Pool/sources.sha256 b/Benchmarks/Scaffolds/UniswapV3Pool/sources.sha256 similarity index 100% rename from Benchmarks/UniswapV3Pool/sources.sha256 rename to Benchmarks/Scaffolds/UniswapV3Pool/sources.sha256 diff --git a/Benchmarks/OpenZeppelinBench/VestingWallet/Bytecode.lean b/Benchmarks/Scaffolds/VestingWallet/Bytecode.lean similarity index 99% rename from Benchmarks/OpenZeppelinBench/VestingWallet/Bytecode.lean rename to Benchmarks/Scaffolds/VestingWallet/Bytecode.lean index 24f22e86..345c7682 100644 --- a/Benchmarks/OpenZeppelinBench/VestingWallet/Bytecode.lean +++ b/Benchmarks/Scaffolds/VestingWallet/Bytecode.lean @@ -1,4 +1,4 @@ -import Benchmarks.OpenZeppelinBench.VestingWallet.Spec +import Benchmarks.Scaffolds.VestingWallet.Spec import Ethereum.Semantics import Reasoning.JumpDest diff --git a/Benchmarks/OpenZeppelinBench/VestingWallet/Constructor.lean b/Benchmarks/Scaffolds/VestingWallet/Constructor.lean similarity index 90% rename from Benchmarks/OpenZeppelinBench/VestingWallet/Constructor.lean rename to Benchmarks/Scaffolds/VestingWallet/Constructor.lean index 4d6dd68a..0b3ad8ea 100644 --- a/Benchmarks/OpenZeppelinBench/VestingWallet/Constructor.lean +++ b/Benchmarks/Scaffolds/VestingWallet/Constructor.lean @@ -1,4 +1,4 @@ -import Benchmarks.OpenZeppelinBench.VestingWallet.Bytecode +import Benchmarks.Scaffolds.VestingWallet.Bytecode import Solm.Equiv /-! diff --git a/Benchmarks/OpenZeppelinBench/VestingWallet/Correct.lean b/Benchmarks/Scaffolds/VestingWallet/Correct.lean similarity index 92% rename from Benchmarks/OpenZeppelinBench/VestingWallet/Correct.lean rename to Benchmarks/Scaffolds/VestingWallet/Correct.lean index e75b2e4b..4c613204 100644 --- a/Benchmarks/OpenZeppelinBench/VestingWallet/Correct.lean +++ b/Benchmarks/Scaffolds/VestingWallet/Correct.lean @@ -1,4 +1,4 @@ -import Benchmarks.OpenZeppelinBench.VestingWallet.Constructor +import Benchmarks.Scaffolds.VestingWallet.Constructor import Solm.Equiv /-! diff --git a/Benchmarks/OpenZeppelinBench/VestingWallet/Spec.lean b/Benchmarks/Scaffolds/VestingWallet/Spec.lean similarity index 100% rename from Benchmarks/OpenZeppelinBench/VestingWallet/Spec.lean rename to Benchmarks/Scaffolds/VestingWallet/Spec.lean diff --git a/Benchmarks/OpenZeppelinBench/VestingWallet/SpecSyntax.lean b/Benchmarks/Scaffolds/VestingWallet/SpecSyntax.lean similarity index 98% rename from Benchmarks/OpenZeppelinBench/VestingWallet/SpecSyntax.lean rename to Benchmarks/Scaffolds/VestingWallet/SpecSyntax.lean index a0c80597..e1907687 100644 --- a/Benchmarks/OpenZeppelinBench/VestingWallet/SpecSyntax.lean +++ b/Benchmarks/Scaffolds/VestingWallet/SpecSyntax.lean @@ -1,4 +1,4 @@ -import Benchmarks.OpenZeppelinBench.VestingWallet.Spec +import Benchmarks.Scaffolds.VestingWallet.Spec import Solm.Notation /-! diff --git a/Benchmarks/OpenZeppelinBench/VestingWallet/VestingWalletBench.abi.json b/Benchmarks/Scaffolds/VestingWallet/VestingWalletBench.abi.json similarity index 100% rename from Benchmarks/OpenZeppelinBench/VestingWallet/VestingWalletBench.abi.json rename to Benchmarks/Scaffolds/VestingWallet/VestingWalletBench.abi.json diff --git a/Benchmarks/OpenZeppelinBench/VestingWallet/VestingWalletBench.sol b/Benchmarks/Scaffolds/VestingWallet/VestingWalletBench.sol similarity index 100% rename from Benchmarks/OpenZeppelinBench/VestingWallet/VestingWalletBench.sol rename to Benchmarks/Scaffolds/VestingWallet/VestingWalletBench.sol diff --git a/Benchmarks/OpenZeppelinBench/VestingWallet/VestingWalletBench.storage.json b/Benchmarks/Scaffolds/VestingWallet/VestingWalletBench.storage.json similarity index 100% rename from Benchmarks/OpenZeppelinBench/VestingWallet/VestingWalletBench.storage.json rename to Benchmarks/Scaffolds/VestingWallet/VestingWalletBench.storage.json diff --git a/Benchmarks/OpenZeppelinBench/VestingWallet/creation.hex b/Benchmarks/Scaffolds/VestingWallet/creation.hex similarity index 100% rename from Benchmarks/OpenZeppelinBench/VestingWallet/creation.hex rename to Benchmarks/Scaffolds/VestingWallet/creation.hex diff --git a/Benchmarks/OpenZeppelinBench/VestingWallet/runtime.hex b/Benchmarks/Scaffolds/VestingWallet/runtime.hex similarity index 100% rename from Benchmarks/OpenZeppelinBench/VestingWallet/runtime.hex rename to Benchmarks/Scaffolds/VestingWallet/runtime.hex diff --git a/Benchmarks/OpenZeppelinBench/VestingWallet/sources.sha256 b/Benchmarks/Scaffolds/VestingWallet/sources.sha256 similarity index 100% rename from Benchmarks/OpenZeppelinBench/VestingWallet/sources.sha256 rename to Benchmarks/Scaffolds/VestingWallet/sources.sha256 diff --git a/Benchmarks/UniswapV3Pool/Burn.lean b/Benchmarks/UniswapV3Pool/Burn.lean deleted file mode 100644 index 716cd4b8..00000000 --- a/Benchmarks/UniswapV3Pool/Burn.lean +++ /dev/null @@ -1,1970 +0,0 @@ -import Benchmarks.UniswapV3Pool.Locking -import Benchmarks.UniswapV3Pool.NoDelegateCall -import Benchmarks.UniswapV3Pool.TickSpacing -import Benchmarks.UniswapV3Pool.TicksInt128 -import Benchmarks.UniswapV3Pool.Uint128 - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev burnTickLowerWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -abbrev burnTickUpperWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 36 - -abbrev burnAmountWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 68 - -abbrev burnTickLowerCleanWord (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨2⟩ (burnTickLowerWord I) - -abbrev burnTickUpperCleanWord (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨2⟩ (burnTickUpperWord I) - -abbrev burnAmountCleanWord (I : ExecutionEnv) : UInt256 := - UInt256.land (burnAmountWord I) uint128Mask - -abbrev burnTickLowerValue (I : ExecutionEnv) : Value := - .int (tickSpacingSint24Value (burnTickLowerWord I)) - -abbrev burnTickUpperValue (I : ExecutionEnv) : Value := - .int (tickSpacingSint24Value (burnTickUpperWord I)) - -abbrev burnAmountValue (I : ExecutionEnv) : Value := - .int (Int.ofNat (UInt256.land (burnAmountWord I) uint128Mask).toNat) - -abbrev burnLiquidityDeltaValue (I : ExecutionEnv) : Value := - .int (0 - Int.ofNat (burnAmountCleanWord I).toNat) - -abbrev burnStore (I : ExecutionEnv) : Store := - ((∅ : Store).insert "tickLower" (burnTickLowerValue I)) - |>.insert "tickUpper" (burnTickUpperValue I) - |>.insert "amount" (burnAmountValue I) - -abbrev burnLiquidityDeltaFrame (v : PoolImmutables) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnStore I).insert "liquidityDelta" (burnLiquidityDeltaValue I) } - -abbrev burnUint8Mask : UInt256 := - UInt256.ofNat (2 ^ 8 - 1) - -abbrev burnUnlockedShift : UInt256 := - UInt256.shiftLeft ⟨1⟩ ⟨240⟩ - -abbrev burnUnlockedByte (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land burnUint8Mask (UInt256.div (solcSlotWord σ I ⟨0⟩) burnUnlockedShift) - -abbrev burnUnlockedClearMask : UInt256 := - UInt256.lnot (UInt256.shiftLeft burnUint8Mask ⟨240⟩) - -abbrev burnLockedSlotWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land burnUnlockedClearMask (solcSlotWord σ I ⟨0⟩) - -abbrev burnUnlockedLoc : StorageLoc := - slot0UnlockedLoc - -def burnModifyPositionMem0 : ByteArray := - (UInt256.toByteArray ((⟨128⟩ : UInt256) + ⟨128⟩)).write 0 solcFreePtrMem - (⟨64⟩ : UInt256).toNat 32 - -def burnModifyPositionMem1 (I : ExecutionEnv) : ByteArray := - (UInt256.toByteArray (UInt256.ofNat I.source.val)).write 0 burnModifyPositionMem0 - (⟨128⟩ : UInt256).toNat 32 - -def burnModifyPositionMem2 (I : ExecutionEnv) : ByteArray := - (UInt256.toByteArray (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))).write 0 - (burnModifyPositionMem1 I) ((⟨128⟩ : UInt256) + ⟨32⟩).toNat 32 - -def burnModifyPositionMem3 (I : ExecutionEnv) : ByteArray := - (UInt256.toByteArray (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))).write 0 - (burnModifyPositionMem2 I) ((⟨128⟩ : UInt256) + ⟨64⟩).toNat 32 - -def burnModifyPositionMem4 (I : ExecutionEnv) : ByteArray := - (UInt256.toByteArray - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))).write 0 - (burnModifyPositionMem3 I) (⟨224⟩ : UInt256).toNat 32 - -private theorem uint128Mask_decode (w : UInt256) : - (UInt256.land w uint128Mask).toNat = w.toNat % EVM.twoPow 128 := by - rw [u256_land_toNat, uint128Mask_toNat, nat_land_mask_eq_mod] - exact Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num [EVM.twoPow])) - (by norm_num [EVM.twoPow, UInt256.size])) - -theorem burnUnlockedByte_eq_slot0UnlockedRawWord (σ : AccountMap) (I : ExecutionEnv) : - burnUnlockedByte σ I = slot0UnlockedRawWord σ I := by - have hshift : burnUnlockedShift = slot0ShiftBytes 30 := by - native_decide - simp [burnUnlockedByte, slot0UnlockedRawWord, burnUnlockedShift, slot0ShiftBytes, - slot0SlotWord, burnUint8Mask, slot0Uint8Mask, hshift, u256_land_comm] - -theorem uniswapV3PoolBurnEvalUnlocked {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) { contract := contract v, locals := burnStore I } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "unlocked")) = - .ok (wordToElem .bool (burnUnlockedByte σ I)) := by - rw [evalExpr_storage_scalar - (t := .bool) - (slot := slot0F "unlocked") - (er := { base := "slot0", steps := [.field "unlocked"] }) - (loc := burnUnlockedLoc) - (hbase := by simp [slot0F, burnStore]) - (her := by - simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, boolSt]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, burnUnlockedLoc, - slot0UnlockedLoc, loc])] - simpa [burnUnlockedByte_eq_slot0UnlockedRawWord] using - slot0StorageLocLoad_unlocked (initState cA gh bl σ σ₀ g A I) - -theorem burnUnlockedByte_wordToElem_false {σ : AccountMap} {I : ExecutionEnv} - (hzero : burnUnlockedByte σ I = ⟨0⟩) : - wordToElem .bool (burnUnlockedByte σ I) = .bool false := by - simp [wordToElem, hzero] - -theorem burnUnlockedByte_wordToElem_true {σ : AccountMap} {I : ExecutionEnv} - (hnz : burnUnlockedByte σ I ≠ ⟨0⟩) : - wordToElem .bool (burnUnlockedByte σ I) = .bool true := by - have hbeq : ((burnUnlockedByte σ I).val == 0) = false := by - rw [beq_eq_false_iff_ne] - intro hval - apply hnz - apply u256_inj - simpa [UInt256.toNat] using hval - simp [wordToElem, hbeq] - -theorem burnUnlockedByte_transport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - burnUnlockedByte σ_solm I = burnUnlockedByte σ_evm I := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ (⟨0⟩ : UInt256) - dsimp [burnUnlockedByte, solcSlotWord] - rw [← hslot] - -theorem burnLockedSlotWord_transport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - burnLockedSlotWord σ_solm I = burnLockedSlotWord σ_evm I := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ (⟨0⟩ : UInt256) - dsimp [burnLockedSlotWord, solcSlotWord] - rw [← hslot] - -theorem uniswapV3PoolBurnSourceLockedReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hlocked : burnUnlockedByte σ I = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (burnStore I) - burnTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [burnTransition, nonpayable, lockPrefix, burnStore] using - (nonpayableSecondRequireReverts - (cfg := config v) - (solm := { contract := contract v, locals := burnStore I }) - (evm := initState cA gh bl σ σ₀ g A I) - (guard := .storage (slot0F "unlocked")) - (hwv := by simp [initState, hwv]) - (hguard := by - rw [uniswapV3PoolBurnEvalUnlocked] - exact congrArg EvalResult.ok (burnUnlockedByte_wordToElem_false hlocked))) - -theorem uniswapV3PoolBurnSourceLockPrefixExact {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : burnUnlockedByte σ I ≠ ⟨0⟩) : - ExecBlock (config v) { contract := contract v, locals := burnStore I } - (initState cA gh bl σ σ₀ g A I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false) ] - (.ok { contract := contract v, locals := burnStore I } - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I))) := by - refine nonpayableRequireAssignStorageBlock - (cfg := config v) (solm := { contract := contract v, locals := burnStore I }) - (evm := initState cA gh bl σ σ₀ g A I) - (evm' := Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - (guard := .storage (slot0F "unlocked")) (rhs := .boolLit false) - (ref := slot0F "unlocked") (value := .bool false) - (by simp [initState, hwv]) ?_ ?_ ?_ - · rw [uniswapV3PoolBurnEvalUnlocked] - exact congrArg EvalResult.ok (burnUnlockedByte_wordToElem_true hunlocked) - · simp [evalExpr?, pure] - · apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "unlocked"] }) - (ty := .elem .bool) - (loc := burnUnlockedLoc) - · simp [slot0F, burnStore] - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, boolSt] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, burnUnlockedLoc, - slot0UnlockedLoc, loc] - · trivial - · simpa [initState, burnLockedSlotWord, solcSlotWord, burnUnlockedLoc, slot0UnlockedLoc, - burnUnlockedClearMask, slot0UnlockedClearMask, u256_land_comm] using - storageLocStore_slot0Unlocked_false (initState cA gh bl σ σ₀ g A I) - -theorem assignStorageRef_burn_unlocked_true - {v : PoolImmutables} (evm : EVM.State) (L : Store) - (hbase : "slot0" ∉ L) : - assignStorageRef? (config v) - { contract := contract v, locals := L } - evm .storage (slot0F "unlocked") (.bool true) = - .ok ({ contract := contract v, locals := L }, slot0AfterUnlockState evm) := by - apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "unlocked"] }) - (ty := .elem .bool) - (loc := burnUnlockedLoc) - · simpa [slot0F] using hbase - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, boolSt] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, burnUnlockedLoc, - slot0UnlockedLoc, loc] - · trivial - · simpa [burnUnlockedLoc, slot0UnlockedLoc] using storageLocStore_slot0Unlocked_true evm - -theorem uniswapV3PoolBurnEvalLiquidityDeltaRevert {v : PoolImmutables} - {evm : EVM.State} {I : ExecutionEnv} - (hne : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) ≠ burnAmountCleanWord I) : - evalExpr? (config v) { contract := contract v, locals := burnStore I } evm - (subE (.intLit 0) (.inRange int128Int (.var "amount"))) = .revert := by - have hgeNat : EVM.twoPow 127 ≤ (burnAmountCleanWord I).toNat := - signextend_fifteen_ne_self_toNat_ge_twoPow127 hne - have hinRange : - evalExpr? (config v) { contract := contract v, locals := burnStore I } evm - (.inRange int128Int (.var "amount")) = .revert := by - simp [evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, burnStore, - burnAmountValue, int128Int] - simpa [EVM.twoPow, burnAmountCleanWord] using hgeNat - simp [subE, evalExpr?, EvalResult.bind, bind, hinRange] - -theorem uniswapV3PoolBurnEvalLiquidityDeltaOk {v : PoolImmutables} - {evm : EVM.State} {I : ExecutionEnv} - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) : - evalExpr? (config v) { contract := contract v, locals := burnStore I } evm - (subE (.intLit 0) (.inRange int128Int (.var "amount"))) = - .ok (burnLiquidityDeltaValue I) := by - have hltNat : (burnAmountCleanWord I).toNat < EVM.twoPow 127 := - signextend_fifteen_eq_self_toNat_lt_twoPow127 - (by simpa [burnAmountCleanWord] using uint128Mask_bound (burnAmountWord I)) - hcanon - have hinRange : - evalExpr? (config v) { contract := contract v, locals := burnStore I } evm - (.inRange int128Int (.var "amount")) = .ok (burnAmountValue I) := by - simp [evalExpr?, EvalResult.bind, EvalResult.ofOption, bind, pure, burnStore, - burnAmountValue, int128Int] - simpa [EVM.twoPow, burnAmountCleanWord] using hltNat - simp [subE, evalExpr?, EvalResult.bind, bind, evalBinaryOp?, burnLiquidityDeltaValue, - burnAmountValue, hinRange] - -theorem uniswapV3PoolBurnSourceThroughLiquidityDelta {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : burnUnlockedByte σ I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) : - ExecBlock (config v) { contract := contract v, locals := burnStore I } - (initState cA gh bl σ σ₀ g A I) - (nonpayable ++ lockPrefix ++ - [ .letDecl "liquidityDelta" (some int128) - (subE (.intLit 0) (.inRange int128Int (.var "amount"))) ]) - (.ok (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I))) := by - have hprefix := uniswapV3PoolBurnSourceLockPrefixExact (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hunlocked - have htail : - ExecBlock (config v) { contract := contract v, locals := burnStore I } - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - [ .letDecl "liquidityDelta" (some int128) - (subE (.intLit 0) (.inRange int128Int (.var "amount"))) ] - (.ok (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I))) := by - exact ExecBlock.consNormal - (ExecStmt.letDecl (uniswapV3PoolBurnEvalLiquidityDeltaOk - (v := v) (evm := Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) - I.codeOwner ⟨0⟩ (burnLockedSlotWord σ I)) (I := I) hcanon)) - ExecBlock.nil - simpa [nonpayable, lockPrefix] using execBlock_append hprefix htail - -theorem uniswapV3PoolBurnSourceLiquidityDeltaReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : burnUnlockedByte σ I ≠ ⟨0⟩) - (hne : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) ≠ burnAmountCleanWord I) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (burnStore I) - burnTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolBurnSourceLockPrefixExact (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hunlocked - have htail : - ∀ rest, - ExecBlock (config v) { contract := contract v, locals := burnStore I } - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - (.letDecl "liquidityDelta" (some int128) - (subE (.intLit 0) (.inRange int128Int (.var "amount"))) :: rest) - .reverted := by - intro rest - exact ExecBlock.consRevert - (ExecStmt.letDeclRevert (uniswapV3PoolBurnEvalLiquidityDeltaRevert - (v := v) (evm := Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) - I.codeOwner ⟨0⟩ (burnLockedSlotWord σ I)) (I := I) hne)) - simpa [burnTransition, nonpayable, lockPrefix] using execBlock_append hprefix (htail _) - -private def burnStSignextend (s : State) (res : UInt256) (t : List UInt256) : State := - { s with - machineState.stack := res :: t, - machineState.gasAvailable := s.machineState.gasAvailable.subNat 5 - machineState.pc := s.machineState.pc + ⟨1⟩ - machineState.execLength := s.machineState.execLength + 1 } - -private theorem burnSignextendXstep {code : ByteArray} {s : State} {pc a b : UInt256} - {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pc) - (hdec : decode code pc = some (.SIGNEXTEND, .none)) - (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : - Xstep (D_J code 0) s = - if s.machineState.gasAvailable.toNat < 5 then .error .OutOfGass - else .ok (burnStSignextend s (UInt256.signextend a b) t, .none) := by - have hdecS : decode s.executionEnv.code s.machineState.pc = some (.SIGNEXTEND, .none) := by - rw [hcode, hpc] - exact hdec - have hstep := step_signextend s hdecS - have hnoOverflow : ¬ 1024 ≤ t.length := by omega - simpa [hcode, hstk, GasConstants.Glow, burnStSignextend, hnoOverflow] using hstep - -theorem burnRDSignextend {code : ByteArray} {ee : ExecutionEnv} - {g : Sat256} {s0 : State} {pc : UInt256} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.SIGNEXTEND, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.signextend a b :: t) mem aw rdata acc - (k + 1) (C + 5) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, hee, - hworld⟩ - · exact Or.inl hoog - · have st := burnSignextendXstep hcode hpc hdec hstk hov - by_cases gg : g.toNat < C + 5 - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨burnStSignextend s (UInt256.signextend a b) t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, by omega, - by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [burnStSignextend]; exact hcode - · simp only [burnStSignextend]; rw [hpc] - · rfl - · simp only [burnStSignextend]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [burnStSignextend]; exact hmem - · simp only [burnStSignextend]; exact haw - · simp only [burnStSignextend]; exact hrdata - · simp only [burnStSignextend]; exact hacc - · exact hee - · exact hworld - -private theorem uniswapV3PoolPatchPreservesJumpDest9577 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨9577⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched9577 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨9577⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest9577 - -private theorem uniswapV3PoolPatchPreservesJumpDest9648 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨9648⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched9648 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨9648⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest9648 - -private theorem uniswapV3PoolPatchPreservesJumpDest9724 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨9724⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched9724 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨9724⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest9724 - -private theorem uniswapV3PoolPatchPreservesJumpDest11243 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11243⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched11243 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11243⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest11243 - -private theorem uniswapV3PoolPatchPreservesJumpDest16216 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16216⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched16216 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16216⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest16216 - -private theorem uniswapV3PoolPatchPreservesJumpDest16233 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16233⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched16233 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16233⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest16233 - -private theorem uniswapV3PoolPatchPreservesJumpDest16246 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16246⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched16246 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16246⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest16246 - -private theorem uniswapV3PoolBurnLockPatchDisjoint33 {v : PoolImmutables} - {pc : UInt256} - (hlo : 9577 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 10457) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -private theorem uniswapV3PoolBurnLockDecodeEqTemplate {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 9577 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 10457) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 10457 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolBurnLockPatchDisjoint33 (v := v) (pc := pc) hlo hhi) - -private theorem uniswapV3PoolBurnReturnShimPatchDisjoint1 {v : PoolImmutables} - {pc : UInt256} - (hlo : 11243 ≤ pc.toNat) (hhi : pc.toNat + 1 ≤ 11248) : - ∀ p ∈ patches v, pc.toNat + 1 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -private theorem uniswapV3PoolBurnSharedPatchDisjoint33 {v : PoolImmutables} - {pc : UInt256} - (hlo : 16216 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 16265) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -private theorem uniswapV3PoolBurnSharedDecodeEqTemplate {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 16216 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 16265) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 16265 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolBurnSharedPatchDisjoint33 (v := v) (pc := pc) hlo hhi) - -private theorem uniswapV3PoolBurnSharedTailPatchDisjoint33 {v : PoolImmutables} - {pc : UInt256} - (hlo : 16233 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 17313) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -private theorem uniswapV3PoolBurnSharedTailDecodeEqTemplate {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 16233 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 17313) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 17313 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolBurnSharedTailPatchDisjoint33 (v := v) (pc := pc) hlo hhi) - -private theorem uniswapV3PoolBurnReturnShimDecodeNoArg {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} {byte : UInt8} {op : Operation} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 11243 ≤ pc.toNat) (hhi : pc.toNat + 1 ≤ 11248) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some byte) - (hparse : (some byte >>= parseInstr) = some op) - (harg : argOnNBytesOfInstr op = 0) : - decode code pc = some (op, .none) := by - exact uniswapV3PoolDecodePatchedNoArg hpatch - (by - have hsize : 11248 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolBurnReturnShimPatchDisjoint1 (v := v) (pc := pc) hlo hhi) - hgetTemplate hparse harg - -private theorem uniswapV3PoolBurnLockedRevertTailWf {v : PoolImmutables} - {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcErrorStringRevertTailWf code ⟨9598⟩ ⟨3⟩ ⟨5001035⟩ ⟨232⟩ .PUSH3 3 := by - dsimp [solcErrorStringRevertTailWf] - repeat' constructor - all_goals - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - -private theorem decodeScalarWordWithMode_int24_ok {bytes : List UInt8} {start : Nat} - (hlen : ((bytes.drop start).take 32).length = 32) : - decodeScalarWordWithMode? DecodeMode.legacySolc05 int24 bytes start = - some - (.int (tickSpacingSint24Value (ABI.bytesToWord ((bytes.drop start).take 32))), - start + 32) := by - simp only [decodeScalarWordWithMode?] - unfold readWord? readBytes? int24 int24Int - rw [if_pos hlen] - simp only [bind, Option.bind] - unfold decodeABIWord? - simp only [OfNat.ofNat_ne_zero, ↓reduceIte] - rfl - -private theorem decodeScalarWordWithMode_uint128_ok {bytes : List UInt8} {start : Nat} - (hlen : ((bytes.drop start).take 32).length = 32) : - decodeScalarWordWithMode? DecodeMode.legacySolc05 uint128 bytes start = - some - (.int (Int.ofNat - (UInt256.land (ABI.bytesToWord ((bytes.drop start).take 32)) uint128Mask).toNat), - start + 32) := by - simp only [decodeScalarWordWithMode?] - unfold readWord? readBytes? uint128 uint128Int - rw [if_pos hlen] - simp only [bind, Option.bind] - unfold decodeABIWord? - simp only [OfNat.ofNat_ne_zero, ↓reduceIte] - rw [uint128Mask_decode] - rfl - -private theorem decodeScalarWordsWithMode_int24_int24_uint128_ok {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) - (hlen32 : ((bytes.drop 32).take 32).length = 32) - (hlen64 : ((bytes.drop 64).take 32).length = 32) : - decodeScalarWordsWithMode? DecodeMode.legacySolc05 [int24, int24, uint128] bytes 0 = - some - [ .int (tickSpacingSint24Value (ABI.bytesToWord (bytes.take 32))), - .int (tickSpacingSint24Value (ABI.bytesToWord ((bytes.drop 32).take 32))), - .int (Int.ofNat - (UInt256.land (ABI.bytesToWord ((bytes.drop 64).take 32)) uint128Mask).toNat) ] := by - simp only [decodeScalarWordsWithMode?] - rw [decodeScalarWordWithMode_int24_ok (bytes := bytes) (start := 0) - (by simpa using hlen0)] - simp only [List.drop_zero] - rw [decodeScalarWordWithMode_int24_ok (bytes := bytes) (start := 32) hlen32] - simp only [bind, Option.bind] - rw [decodeScalarWordWithMode_uint128_ok (bytes := bytes) (start := 64) hlen64] - -private theorem decodeScalarWordsWithMode_int24_int24_uint128_none_short {bytes : List UInt8} - (hshort : bytes.length < 96) : - decodeScalarWordsWithMode? DecodeMode.legacySolc05 [int24, int24, uint128] bytes 0 = - none := by - simp only [decodeScalarWordsWithMode?] - by_cases hlen0 : (bytes.take 32).length = 32 - · rw [decodeScalarWordWithMode_int24_ok (bytes := bytes) (start := 0) - (by simpa using hlen0)] - simp only [List.drop_zero] - by_cases hlen32 : ((bytes.drop 32).take 32).length = 32 - · rw [decodeScalarWordWithMode_int24_ok (bytes := bytes) (start := 32) hlen32] - simp only [bind, Option.bind] - have hlen64 : ¬ ((bytes.drop 64).take 32).length = 32 := by - rw [List.length_take, List.length_drop] - omega - unfold decodeScalarWordWithMode? readWord? readBytes? uint128 uint128Int - rw [if_neg hlen64] - simp only [bind, Option.bind] - · unfold decodeScalarWordWithMode? readWord? readBytes? int24 int24Int - rw [if_neg hlen32] - simp only [bind, Option.bind] - · unfold decodeScalarWordWithMode? readWord? readBytes? int24 int24Int - simp only [List.drop_zero] - rw [if_neg hlen0] - simp only [bind, Option.bind] - -theorem uniswapV3PoolBurnDecodeOk {v : PoolImmutables} {I : ExecutionEnv} - (hsz100 : 100 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - (burnTransition.params.map Param.name) - (transitionSignature burnTransition).paramTypes I.calldata = some (burnStore I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake4 : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have htake36 : (((I.calldata.toList.drop 4).drop 32).take 32).length = 32 := by - rw [List.length_take, List.length_drop, List.length_drop, htlen] - omega - have htake68 : (((I.calldata.toList.drop 4).drop 64).take 32).length = 32 := by - rw [List.length_take, List.length_drop, List.length_drop, htlen] - omega - have hword4 : ABI.bytesToWord ((I.calldata.toList.drop 4).take 32) = - calldataWord I.calldata 4 := - decode_word_at_eq I.calldata 4 (by omega) (by norm_num) - have hword36 : ABI.bytesToWord ((I.calldata.toList.drop 36).take 32) = - calldataWord I.calldata 36 := - decode_word_at_eq I.calldata 36 (by omega) (by norm_num) - have hword68 : ABI.bytesToWord ((I.calldata.toList.drop 68).take 32) = - calldataWord I.calldata 68 := - decode_word_at_eq I.calldata 68 (by omega) (by norm_num) - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := burnTransition.params.map Param.name) - (types := (transitionSignature burnTransition).paramTypes) (cd := I.calldata)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 [int24, int24, uint128] - (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["tickLower", "tickUpper", "amount"] values ∅ - | none => none) = some (burnStore I) - rw [decodeScalarWordsWithMode_int24_int24_uint128_ok - (bytes := I.calldata.toList.drop 4) htake4 htake36 htake68] - simp [decodeCalldata.insertValues, burnStore, burnTickLowerValue, burnTickUpperValue, - burnAmountValue, burnTickLowerWord, burnTickUpperWord, burnAmountWord] - rw [hword4, hword36, hword68] - · native_decide - -theorem uniswapV3PoolBurnDecodeShort {v : PoolImmutables} {I : ExecutionEnv} - (hshort : I.calldata.size < 100) : - decodeCalldataWithMode (config v).abiDecodeMode - (burnTransition.params.map Param.name) - (transitionSignature burnTransition).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := burnTransition.params.map Param.name) - (types := (transitionSignature burnTransition).paramTypes) (cd := I.calldata)] - · by_cases hsz4 : I.calldata.size < 4 - · rw [if_pos (by rw [htlen]; omega : I.calldata.toList.length < 4)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 - [int24, int24, uint128] (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["tickLower", "tickUpper", "amount"] values ∅ - | none => none) = none - rw [decodeScalarWordsWithMode_int24_int24_uint128_none_short - (bytes := I.calldata.toList.drop 4) (by rw [List.length_drop, htlen]; omega)] - · native_decide - -theorem uniswapV3PoolBurnReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 17 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1852⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 17 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0xa3 0x41 0x23 0xa7 - (uniswapV3PoolSelNat 17) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h43 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨43⟩) hpatch h32 hgt32 - have hgt43 : UInt256.gt (armSelNat code ⟨43⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h152 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨152⟩) hpatch h43 hgt43 - have hgt152 : UInt256.gt (armSelNat code ⟨152⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h163 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨163⟩) hpatch h152 hgt152 - have hmiss16 : (uniswapV3PoolSelBytes 16 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h174 := uniswapV3PoolSelectorArmMissToOf (i := 16) (next := ⟨174⟩) - hpatch hsz hmiss16 h163 - have h1852 := uniswapV3PoolSelectorArmHitTo (i := 17) (target := ⟨1852⟩) - hpatch hsz hsel h174 - exact ⟨_, _, h1852⟩ - -theorem uniswapV3PoolDispatch_burn {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 17 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some burnTransition := by - apply dispatchMsg_eq_some_of_split (hfallback := by rfl) (hreceive := by rfl) - (pre := []) - (ti := burnTransition) - (post := [collectTransition v, collectprotocolTransition v, factoryTransition v, - feeTransition v, feegrowthglobal0X128Transition, feegrowthglobal1X128Transition, - flashTransition v, increaseobservationcardinalitynextTransition v, initializeTransition, - liquidityTransition, maxliquiditypertickTransition v, mintTransition v, - observationsTransition, observeTransition v, positionsTransition, protocolfeesTransition, - setfeeprotocolTransition v, slot0Transition, snapshotcumulativesinsideTransition v, - swapTransition v, tickbitmapTransition, tickspacingTransition v, ticksTransition, - token0Transition v, token1Transition v]) - (by simp [contract, transitions]) - (by simp) - (by rw [selectorOf, burnSelectorBytes]; simpa [uniswapV3PoolSelBytes] using hsel) - -theorem uniswapV3PoolBurnEvmDecodeShort {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 17 == I.calldata.extract 0 4) = true) - (hshort : I.calldata.size < 100) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - have hreach := uniswapV3PoolBurnReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - have hlt : - UInt256.lt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨96⟩ = ⟨1⟩ := by - apply ult_one - rw [usub_ofNat_word_toNat (by - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega) hsize] - rw [show (⟨96⟩ : UInt256).toNat = 96 from by decide] - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega - exact RD.solcExternalStaticArgsShortReverts (need := ⟨96⟩) - (entry := ⟨1852⟩) (ret := ⟨621⟩) (decoded := ⟨1874⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - hlt - -theorem uniswapV3PoolBurnExternalLenOk {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsz100 : 100 ≤ I.calldata.size) - (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 17 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1874⟩ - (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩ :: ⟨4⟩ :: ⟨621⟩ :: - [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hreach := uniswapV3PoolBurnReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - have hlt : - UInt256.lt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨96⟩ = ⟨0⟩ := by - exact solcDecodeLenCheckOkUnsigned (by - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - rw [show (⟨96⟩ : UInt256).toNat = 96 from by decide] - omega) hsize - exact RD.solcExternalStaticArgsLenOk (need := ⟨96⟩) - (entry := ⟨1852⟩) (ret := ⟨621⟩) (decoded := ⟨1874⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - hlt - -theorem uniswapV3PoolBurnDecodedReachTickLower {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {de ret : UInt256} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨1874⟩ (de :: ⟨4⟩ :: ret :: R) mem aw rdata acc k C) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨1883⟩ - (burnTickLowerCleanWord ee :: ⟨2⟩ :: ⟨4⟩ :: ret :: R) - mem aw rdata acc k' C' := by - have rd1875 : RD code ee g s0 ⟨1875⟩ (de :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1) (C + 1) := by - simpa using h.jumpdest - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1876 : RD code ee g s0 ⟨1876⟩ (⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1) (C + 1 + 2) := by - simpa using rd1875.pop - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1877 : RD code ee g s0 ⟨1877⟩ (⟨4⟩ :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1) (C + 1 + 2 + 3) := by - simpa using rd1876.dup1 - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1878 : RD code ee g s0 ⟨1878⟩ (burnTickLowerWord ee :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3) := by - simpa [burnTickLowerWord, calldataWord, show (⟨4⟩ : UInt256).toNat = 4 from by decide] - using rd1877.calldataload - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1880 : RD code ee g s0 ⟨1880⟩ (⟨2⟩ :: burnTickLowerWord ee :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3 + 3) := by - simpa using rd1878.push1 ⟨2⟩ - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1881 : RD code ee g s0 ⟨1881⟩ (burnTickLowerWord ee :: ⟨2⟩ :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3 + 3 + 3) := by - simpa using rd1880.swap1 - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1882 : RD code ee g s0 ⟨1882⟩ - (⟨2⟩ :: burnTickLowerWord ee :: ⟨2⟩ :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 1 + 2 + 3 + 3 + 3 + 3 + 3) := by - simpa using rd1881.dup2 - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - exact ⟨_, _, by - simpa [burnTickLowerCleanWord] using - (burnRDSignextend rd1882 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by simp only [List.length_cons]; omega))⟩ - -theorem uniswapV3PoolBurnTickLowerReachTickUpper {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨1883⟩ - (burnTickLowerCleanWord ee :: ⟨2⟩ :: ⟨4⟩ :: ret :: R) mem aw rdata acc k C) - (hov : R.length + 6 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨1892⟩ - (burnTickUpperCleanWord ee :: ⟨4⟩ :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc k' C' := by - have rd1884 : RD code ee g s0 ⟨1884⟩ - (⟨4⟩ :: ⟨2⟩ :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1) (C + 3) := by - simpa using h.swap2 - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1886 : RD code ee g s0 ⟨1886⟩ - (⟨32⟩ :: ⟨4⟩ :: ⟨2⟩ :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1) (C + 3 + 3) := by - simpa using rd1884.push1 ⟨32⟩ - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1887 : RD code ee g s0 ⟨1887⟩ - (⟨4⟩ :: ⟨32⟩ :: ⟨4⟩ :: ⟨2⟩ :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1) (C + 3 + 3 + 3) := by - simpa using rd1886.dup2 - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1888 : RD code ee g s0 ⟨1888⟩ - (⟨36⟩ :: ⟨4⟩ :: ⟨2⟩ :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1) (C + 3 + 3 + 3 + 3) := by - simpa using rd1887.add - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1889 : RD code ee g s0 ⟨1889⟩ - (burnTickUpperWord ee :: ⟨4⟩ :: ⟨2⟩ :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1) (C + 3 + 3 + 3 + 3 + 3) := by - simpa [burnTickUpperWord, calldataWord, - show (⟨36⟩ : UInt256).toNat = 36 from by decide] using - rd1888.calldataload - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1890 : RD code ee g s0 ⟨1890⟩ - (⟨4⟩ :: burnTickUpperWord ee :: ⟨2⟩ :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1) - (C + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa using rd1889.swap1 - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1891 : RD code ee g s0 ⟨1891⟩ - (⟨2⟩ :: burnTickUpperWord ee :: ⟨4⟩ :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 3 + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa using rd1890.swap2 - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - exact ⟨_, _, by - simpa [burnTickUpperCleanWord] using - (burnRDSignextend rd1891 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by simp only [List.length_cons]; omega))⟩ - -theorem uniswapV3PoolBurnTickUpperReachModifyPosition {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨1892⟩ - (burnTickUpperCleanWord ee :: ⟨4⟩ :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc k C) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨9577⟩ - (burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - mem aw rdata acc k' C' := by - have hmask : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨1⟩ = uint128Mask := by - native_decide - have hamount : - UInt256.land uint128Mask (burnAmountWord ee) = burnAmountCleanWord ee := by - rw [burnAmountCleanWord, u256_land_comm] - have rd1893 : RD code ee g s0 ⟨1893⟩ - (⟨4⟩ :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1) (C + 3) := by - simpa using h.swap1 - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1895 : RD code ee g s0 ⟨1895⟩ - (⟨64⟩ :: ⟨4⟩ :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1) (C + 3 + 3) := by - simpa using rd1893.push1 ⟨64⟩ - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1896 : RD code ee g s0 ⟨1896⟩ - (⟨68⟩ :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1) (C + 3 + 3 + 3) := by - simpa using rd1895.add - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1897 : RD code ee g s0 ⟨1897⟩ - (burnAmountWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1) (C + 3 + 3 + 3 + 3) := by - simpa [burnAmountWord, calldataWord, - show (⟨68⟩ : UInt256).toNat = 68 from by decide] using - rd1896.calldataload - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1899 : RD code ee g s0 ⟨1899⟩ - (⟨1⟩ :: burnAmountWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1) (C + 3 + 3 + 3 + 3 + 3) := by - simpa using rd1897.push1 ⟨1⟩ - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1901 : RD code ee g s0 ⟨1901⟩ - (⟨1⟩ :: ⟨1⟩ :: burnAmountWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1) - (C + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa using rd1899.push1 ⟨1⟩ - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1903 : RD code ee g s0 ⟨1903⟩ - (⟨128⟩ :: ⟨1⟩ :: ⟨1⟩ :: burnAmountWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 3 + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa using rd1901.push1 ⟨128⟩ - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - have rd1904 : RD code ee g s0 ⟨1904⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: ⟨1⟩ :: burnAmountWord ee :: - burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa using rd1903.shl - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp only [List.length_cons]; omega) - have rd1905 : RD code ee g s0 ⟨1905⟩ - (uint128Mask :: burnAmountWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa [hmask] using rd1904.sub - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp only [List.length_cons]; omega) - have rd1906 : RD code ee g s0 ⟨1906⟩ - (burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa [hamount] using rd1905.and - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp only [List.length_cons]; omega) - have rd1909 := rd1906.push2 ⟨9577⟩ - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by evm_ov) - exact ⟨_, _, rd1909.jump - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched9577 hpatch) - (by evm_ov)⟩ - -theorem uniswapV3PoolBurnLockCheck {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {amount upper lower ret : UInt256} {R : List UInt256} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨9577⟩ (amount :: upper :: lower :: ret :: R) - mem aw rdata (cA, σ) k C) - (hov : R.length + 10 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨9597⟩ - (⟨9648⟩ :: burnUnlockedByte σ ee :: ⟨0⟩ :: ⟨0⟩ :: amount :: upper :: - lower :: ret :: R) - mem aw rdata (cA, σ) k' C' := by - have rd9578 := by - simpa using h.jumpdest - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9580 := by - simpa using rd9578.push1 ⟨0⟩ - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9581 := by - simpa using rd9580.dup1 - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - obtain ⟨_, _, rd9582₀⟩ := rd9581.sload - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9582 := by - simpa [solcSlotWord] using rd9582₀ - have rd9583 := by - simpa using rd9582.dup2 - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9584 := by - simpa using rd9583.swap1 - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9586 := by - simpa using rd9584.push1 ⟨1⟩ - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9588 := by - simpa using rd9586.push1 ⟨240⟩ - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9589 := by - simpa [burnUnlockedShift] using rd9588.shl - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons]; omega) - have rd9590 := by - simpa using rd9589.swap1 - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9591 := by - simpa using rd9590.div - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9593 := by - simpa [burnUint8Mask] using rd9591.push1 ⟨255⟩ - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9594 := by - simpa [burnUnlockedByte] using rd9593.and - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons]; omega) - exact ⟨_, _, by - simpa using rd9594.push2 ⟨9648⟩ - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)⟩ - -theorem uniswapV3PoolBurnLockEnterOk {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {amount upper lower ret : UInt256} {R : List UInt256} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨9577⟩ (amount :: upper :: lower :: ret :: R) - mem aw rdata (cA, σ) k C) - (hperm : ee.perm = true) - (hunlocked : burnUnlockedByte σ ee ≠ ⟨0⟩) - (hov : R.length + 10 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨9662⟩ - (⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: amount :: upper :: lower :: ret :: R) - mem aw rdata - (cA, sstoreAccountMap ee.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ ee)) k' C' := by - obtain ⟨_, _, rd9597⟩ := uniswapV3PoolBurnLockCheck hpatch h hov - have rd9648 := - rd9597.jumpiT - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - hunlocked - (uniswapV3PoolJumpDestPatched9648 hpatch) - (by evm_ov) - have rd9649 := by - simpa using rd9648.jumpdest - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9651 := by - simpa using rd9649.push1 ⟨0⟩ - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9652 := by - simpa using rd9651.dup1 - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - obtain ⟨_, _, rd9653₀⟩ := rd9652.sload - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9653 := by - simpa [solcSlotWord] using rd9653₀ - have rd9655 := by - simpa [burnUint8Mask] using rd9653.push1 ⟨255⟩ - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9657 := by - simpa using rd9655.push1 ⟨240⟩ - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9658 := by - simpa using rd9657.shl - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons]; omega) - have rd9659 := by - simpa [burnUnlockedClearMask] using rd9658.not - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - have rd9660 := by - simpa [burnLockedSlotWord] using rd9659.and - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons]; omega) - have rd9661 := by - simpa using rd9660.dup2 - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - simpa [burnLockedSlotWord, burnUnlockedClearMask, burnUint8Mask, solcSlotWord] using - rd9661.sstore hperm - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - (by evm_ov) - -theorem uniswapV3PoolBurnLockEnterLockedRevert {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {amount upper lower ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨9577⟩ (amount :: upper :: lower :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hlocked : burnUnlockedByte σ ee = ⟨0⟩) - (hov : R.length + 11 ≤ 1024) : - RDrev code g s0 := by - obtain ⟨_, _, rd9597⟩ := uniswapV3PoolBurnLockCheck hpatch h (by omega) - have rd9598 := rd9597.jumpiNT - (by rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)]; native_decide) - hlocked - (by evm_ov) - exact RD.solcErrorStringRevertTail - (pc := ⟨9598⟩) (len := ⟨3⟩) (rawWord := ⟨5001035⟩) (shift := ⟨232⟩) - (word := UInt256.shiftLeft ⟨5001035⟩ ⟨232⟩) (op := .PUSH3) (width := 3) - rd9598 - (uniswapV3PoolBurnLockedRevertTailWf hpatch) - (by native_decide) - rfl - solcFreePtrMem_size - solcFreePtrMem_read64 - (by simp only [List.length_cons]; omega) - -theorem uniswapV3PoolBurnAfterLockWriteOwner {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {amount upper lower ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨9662⟩ - (⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: amount :: upper :: lower :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hov : R.length + 12 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨9675⟩ - (⟨128⟩ :: ⟨64⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: amount :: upper :: lower :: ret :: R) - (burnModifyPositionMem1 ee) (UInt256.ofNat 5) rdata (cA, σ) k' C' := by - have hd9662 : decode code ⟨9662⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9664 : decode code ⟨9664⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9665 : decode code ⟨9665⟩ = some (.MLOAD, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9666 : decode code ⟨9666⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9668 : decode code ⟨9668⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9669 : decode code ⟨9669⟩ = some (.ADD, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9670 : decode code ⟨9670⟩ = some (.DUP3, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9671 : decode code ⟨9671⟩ = some (.MSTORE, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9672 : decode code ⟨9672⟩ = some (.CALLER, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9673 : decode code ⟨9673⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9674 : decode code ⟨9674⟩ = some (.MSTORE, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have rd9664 := by - simpa using h.push1 ⟨64⟩ hd9662 - (by simp only [List.length_cons]; omega) - have rd9665 := by - simpa using rd9664.dup1 hd9664 - (by simp only [List.length_cons]; omega) - have rd9666 := by - simpa using rd9665.mload 0 ⟨128⟩ (UInt256.ofNat 3) hd9665 - mem_cost - solcFreePtrMem_mload64 - (by native_decide) - (by simp only [List.length_cons]; omega) - have rd9668 := by - simpa using rd9666.push1 ⟨128⟩ hd9666 - (by simp only [List.length_cons]; omega) - have rd9669 := by - simpa using rd9668.dup2 hd9668 - (by simp only [List.length_cons]; omega) - have rd9670 := by - simpa using rd9669.add hd9669 - (by simp only [List.length_cons]; omega) - have rd9671 := by - simpa using rd9670.dup3 hd9670 - (by simp only [List.length_cons]; omega) - have rd9672 := by - simpa [burnModifyPositionMem0] using - rd9671.mstore 0 burnModifyPositionMem0 (UInt256.ofNat 3) - hd9671 - mem_cost - (by rfl) - (by native_decide) - (by simp only [List.length_cons]; omega) - have rd9673 := by - simpa using rd9672.caller hd9672 - (by simp only [List.length_cons]; omega) - have rd9674 := by - simpa using rd9673.dup2 hd9673 - (by simp only [List.length_cons]; omega) - exact ⟨_, _, by - simpa [burnModifyPositionMem1] using - rd9674.mstore 6 (burnModifyPositionMem1 ee) (UInt256.ofNat 5) - hd9674 - mem_cost - (by rfl) - (by native_decide) - (by simp only [List.length_cons]; omega)⟩ - -theorem uniswapV3PoolBurnAfterLockWriteTicks {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨9675⟩ - (⟨128⟩ :: ⟨64⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: burnAmountCleanWord ee :: - burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: ret :: R) - (burnModifyPositionMem1 ee) (UInt256.ofNat 5) rdata (cA, σ) k C) - (hov : R.length + 13 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨9695⟩ - (⟨128⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: burnAmountCleanWord ee :: - burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: ret :: R) - (burnModifyPositionMem3 ee) (UInt256.ofNat 7) rdata (cA, σ) k' C' := by - have hd9675 : decode code ⟨9675⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9677 : decode code ⟨9677⟩ = some (.DUP9, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9678 : decode code ⟨9678⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9679 : decode code ⟨9679⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9680 : decode code ⟨9680⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9682 : decode code ⟨9682⟩ = some (.DUP4, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9683 : decode code ⟨9683⟩ = some (.ADD, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9684 : decode code ⟨9684⟩ = some (.MSTORE, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9685 : decode code ⟨9685⟩ = some (.DUP8, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9686 : decode code ⟨9686⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9687 : decode code ⟨9687⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9688 : decode code ⟨9688⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9689 : decode code ⟨9689⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9690 : decode code ⟨9690⟩ = some (.ADD, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9691 : decode code ⟨9691⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9692 : decode code ⟨9692⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9693 : decode code ⟨9693⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9694 : decode code ⟨9694⟩ = some (.MSTORE, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have rd9677 := by - simpa using h.push1 ⟨2⟩ hd9675 - (by simp only [List.length_cons]; omega) - have rd9678 := by - simpa using rd9677.dup9 hd9677 - (by simp only [List.length_cons]; omega) - have rd9679 := by - simpa using rd9678.dup2 hd9678 - (by simp only [List.length_cons]; omega) - have rd9680 := by - simpa using burnRDSignextend rd9679 hd9679 - (by simp only [List.length_cons]; omega) - have rd9682 := by - simpa using rd9680.push1 ⟨32⟩ hd9680 - (by simp only [List.length_cons]; omega) - have rd9683 := by - simpa using rd9682.dup4 hd9682 - (by simp only [List.length_cons]; omega) - have rd9684 := by - simpa using rd9683.add hd9683 - (by simp only [List.length_cons]; omega) - have rd9685 := by - simpa [burnModifyPositionMem2] using - rd9684.mstore 3 (burnModifyPositionMem2 ee) (UInt256.ofNat 6) - hd9684 - mem_cost - (by rfl) - (by native_decide) - (by simp only [List.length_cons]; omega) - have rd9686 := by - simpa using rd9685.dup8 hd9685 - (by simp only [List.length_cons]; omega) - have rd9687 := by - simpa using rd9686.swap1 hd9686 - (by simp only [List.length_cons]; omega) - have rd9688 := by - simpa using burnRDSignextend rd9687 hd9687 - (by simp only [List.length_cons]; omega) - have rd9689 := by - simpa using rd9688.swap2 hd9688 - (by simp only [List.length_cons]; omega) - have rd9690 := by - simpa using rd9689.dup2 hd9689 - (by simp only [List.length_cons]; omega) - have rd9691 := by - simpa using rd9690.add hd9690 - (by simp only [List.length_cons]; omega) - have rd9692 := by - simpa using rd9691.swap2 hd9691 - (by simp only [List.length_cons]; omega) - have rd9693 := by - simpa using rd9692.swap1 hd9692 - (by simp only [List.length_cons]; omega) - have rd9694 := by - simpa using rd9693.swap2 hd9693 - (by simp only [List.length_cons]; omega) - exact ⟨_, _, by - simpa [burnModifyPositionMem3] using - rd9694.mstore 3 (burnModifyPositionMem3 ee) (UInt256.ofNat 7) - hd9694 - mem_cost - (by rfl) - (by native_decide) - (by simp only [List.length_cons]; omega)⟩ - -theorem uniswapV3PoolBurnPrepareLiquidityDelta {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨9695⟩ - (⟨128⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: burnAmountCleanWord ee :: - burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: ret :: R) - (burnModifyPositionMem3 ee) (UInt256.ofNat 7) rdata (cA, σ) k C) - (hov : R.length + 17 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨16216⟩ - (burnAmountCleanWord ee :: ⟨9724⟩ :: ⟨224⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: burnAmountCleanWord ee :: - burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: ret :: R) - (burnModifyPositionMem3 ee) (UInt256.ofNat 7) rdata (cA, σ) k' C' := by - have hmask : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨1⟩ = uint128Mask := by - native_decide - have hamount : - UInt256.land (burnAmountCleanWord ee) uint128Mask = burnAmountCleanWord ee := by - exact uint128Mask_clean (by - simpa [burnAmountCleanWord] using uint128Mask_bound (burnAmountWord ee)) - have hd9695 : decode code ⟨9695⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9696 : decode code ⟨9696⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9697 : decode code ⟨9697⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9698 : decode code ⟨9698⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9699 : decode code ⟨9699⟩ = some (.Push .PUSH2, some (⟨9737⟩, 2)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9702 : decode code ⟨9702⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9703 : decode code ⟨9703⟩ = some (.Push .PUSH1, some (⟨96⟩, 1)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9705 : decode code ⟨9705⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9706 : decode code ⟨9706⟩ = some (.ADD, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9707 : decode code ⟨9707⟩ = some (.Push .PUSH2, some (⟨9724⟩, 2)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9710 : decode code ⟨9710⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9712 : decode code ⟨9712⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9714 : decode code ⟨9714⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9716 : decode code ⟨9716⟩ = some (.SHL, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9717 : decode code ⟨9717⟩ = some (.SUB, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9718 : decode code ⟨9718⟩ = some (.DUP11, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9719 : decode code ⟨9719⟩ = some (.AND, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9720 : decode code ⟨9720⟩ = some (.Push .PUSH2, some (⟨16216⟩, 2)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9723 : decode code ⟨9723⟩ = some (.JUMP, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have rd9696 := by - simpa using h.dup2 hd9695 - (by simp only [List.length_cons]; omega) - have rd9697 := by - simpa using rd9696.swap1 hd9696 - (by simp only [List.length_cons]; omega) - have rd9698 := by - simpa using rd9697.dup2 hd9697 - (by simp only [List.length_cons]; omega) - have rd9699 := by - simpa using rd9698.swap1 hd9698 - (by simp only [List.length_cons]; omega) - have rd9702 := by - simpa using rd9699.push2 ⟨9737⟩ hd9699 - (by simp only [List.length_cons]; omega) - have rd9703 := by - simpa using rd9702.swap1 hd9702 - (by simp only [List.length_cons]; omega) - have rd9705 := by - simpa using rd9703.push1 ⟨96⟩ hd9703 - (by simp only [List.length_cons]; omega) - have rd9706 := by - simpa using rd9705.dup2 hd9705 - (by simp only [List.length_cons]; omega) - have rd9707 := by - simpa using rd9706.add hd9706 - (by simp only [List.length_cons]; omega) - have rd9710 := by - simpa using rd9707.push2 ⟨9724⟩ hd9707 - (by simp only [List.length_cons]; omega) - have rd9712 := by - simpa using rd9710.push1 ⟨1⟩ hd9710 - (by simp only [List.length_cons]; omega) - have rd9714 := by - simpa using rd9712.push1 ⟨1⟩ hd9712 - (by simp only [List.length_cons]; omega) - have rd9716 := by - simpa using rd9714.push1 ⟨128⟩ hd9714 - (by simp only [List.length_cons]; omega) - have rd9717 := by - simpa using rd9716.shl hd9716 - (by simp only [List.length_cons]; omega) - have rd9718 := by - simpa [hmask] using rd9717.sub hd9717 - (by simp only [List.length_cons]; omega) - have rd9719 := by - simpa using rd9718.dup11 hd9718 - (by simp only [List.length_cons]; omega) - have rd9720 := by - simpa [hamount] using rd9719.and hd9719 - (by simp only [List.length_cons]; omega) - have rd9723 := by - simpa using rd9720.push2 ⟨16216⟩ hd9720 - (by simp only [List.length_cons]; omega) - exact ⟨_, _, rd9723.jump hd9723 (uniswapV3PoolJumpDestPatched16216 hpatch) - (by simp only [List.length_cons]; omega)⟩ - -theorem uniswapV3PoolBurnLiquidityDeltaInt128Ok {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨16216⟩ - (burnAmountCleanWord ee :: ⟨9724⟩ :: ⟨224⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: burnAmountCleanWord ee :: - burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: ret :: R) - (burnModifyPositionMem3 ee) (UInt256.ofNat 7) rdata (cA, σ) k C) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord ee) = burnAmountCleanWord ee) - (hov : R.length + 18 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨9724⟩ - (burnAmountCleanWord ee :: ⟨224⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: burnAmountCleanWord ee :: - burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: ret :: R) - (burnModifyPositionMem3 ee) (UInt256.ofNat 7) rdata (cA, σ) k' C' := by - have hd16216 : decode code ⟨16216⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16217 : decode code ⟨16217⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16218 : decode code ⟨16218⟩ = some (.Push .PUSH1, some (⟨15⟩, 1)) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16220 : decode code ⟨16220⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16221 : decode code ⟨16221⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16222 : decode code ⟨16222⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16223 : decode code ⟨16223⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16224 : decode code ⟨16224⟩ = some (.EQ, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16225 : decode code ⟨16225⟩ = some (.Push .PUSH2, some (⟨11243⟩, 2)) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16228 : decode code ⟨16228⟩ = some (.JUMPI, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd11243 : decode code ⟨11243⟩ = some (.JUMPDEST, .none) := by - exact uniswapV3PoolBurnReturnShimDecodeNoArg (pc := ⟨11243⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd11244 : decode code ⟨11244⟩ = some (.SWAP2, .none) := by - exact uniswapV3PoolBurnReturnShimDecodeNoArg (pc := ⟨11244⟩) (byte := 0x91) - (op := .SWAP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd11245 : decode code ⟨11245⟩ = some (.SWAP1, .none) := by - exact uniswapV3PoolBurnReturnShimDecodeNoArg (pc := ⟨11245⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd11246 : decode code ⟨11246⟩ = some (.POP, .none) := by - exact uniswapV3PoolBurnReturnShimDecodeNoArg (pc := ⟨11246⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd11247 : decode code ⟨11247⟩ = some (.JUMP, .none) := by - exact uniswapV3PoolBurnReturnShimDecodeNoArg (pc := ⟨11247⟩) (byte := 0x56) - (op := .JUMP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hcond : - UInt256.eq (burnAmountCleanWord ee) - (UInt256.signextend ⟨15⟩ (burnAmountCleanWord ee)) ≠ ⟨0⟩ := by - have heq : - UInt256.eq (burnAmountCleanWord ee) - (UInt256.signextend ⟨15⟩ (burnAmountCleanWord ee)) = ⟨1⟩ := by - rw [hcanon, uInt256_eq_self] - rw [heq] - native_decide - have rd16217 := by - simpa using h.jumpdest hd16216 - (by simp only [List.length_cons]; omega) - have rd16218 := by - simpa using rd16217.dup1 hd16217 - (by simp only [List.length_cons]; omega) - have rd16220 := by - simpa using rd16218.push1 ⟨15⟩ hd16218 - (by simp only [List.length_cons]; omega) - have rd16221 := by - simpa using rd16220.dup2 hd16220 - (by simp only [List.length_cons]; omega) - have rd16222 := by - simpa using rd16221.swap1 hd16221 - (by simp only [List.length_cons]; omega) - have rd16223 := by - simpa using burnRDSignextend rd16222 hd16222 - (by simp only [List.length_cons]; omega) - have rd16224 := by - simpa using rd16223.dup2 hd16223 - (by simp only [List.length_cons]; omega) - have rd16225 := by - simpa using rd16224.eq hd16224 - (by simp only [List.length_cons]; omega) - have rd16228 := by - simpa using rd16225.push2 ⟨11243⟩ hd16225 - (by simp only [List.length_cons]; omega) - have rd11243 := rd16228.jumpiT hd16228 hcond - (uniswapV3PoolJumpDestPatched11243 hpatch) - (by simp only [List.length_cons]; omega) - have rd11244 := by - simpa using rd11243.jumpdest hd11243 - (by simp only [List.length_cons]; omega) - have rd11245 := by - simpa using rd11244.swap2 hd11244 - (by simp only [List.length_cons]; omega) - have rd11246 := by - simpa using rd11245.swap1 hd11245 - (by simp only [List.length_cons]; omega) - have rd11247 := by - simpa using rd11246.pop hd11246 - (by simp only [List.length_cons]; omega) - exact ⟨_, _, rd11247.jump hd11247 (uniswapV3PoolJumpDestPatched9724 hpatch) - (by simp only [List.length_cons]; omega)⟩ - -theorem uniswapV3PoolBurnWriteLiquidityDelta {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨9724⟩ - (burnAmountCleanWord ee :: ⟨224⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: burnAmountCleanWord ee :: - burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: ret :: R) - (burnModifyPositionMem3 ee) (UInt256.ofNat 7) rdata (cA, σ) k C) - (hov : R.length + 17 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨16233⟩ - (⟨128⟩ :: ⟨9737⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnModifyPositionMem4 ee) (UInt256.ofNat 8) rdata (cA, σ) k' C' := by - have hd9724 : decode code ⟨9724⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9725 : decode code ⟨9725⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9727 : decode code ⟨9727⟩ = some (.SUB, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9728 : decode code ⟨9728⟩ = some (.Push .PUSH1, some (⟨15⟩, 1)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9730 : decode code ⟨9730⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9731 : decode code ⟨9731⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9732 : decode code ⟨9732⟩ = some (.MSTORE, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9733 : decode code ⟨9733⟩ = some (.Push .PUSH2, some (⟨16233⟩, 2)) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd9736 : decode code ⟨9736⟩ = some (.JUMP, .none) := by - rw [uniswapV3PoolBurnLockDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have rd9725 := by - simpa using h.jumpdest hd9724 - (by simp only [List.length_cons]; omega) - have rd9727 := by - simpa using rd9725.push1 ⟨0⟩ hd9725 - (by simp only [List.length_cons]; omega) - have rd9728 := by - simpa using rd9727.sub hd9727 - (by simp only [List.length_cons]; omega) - have rd9730 := by - simpa using rd9728.push1 ⟨15⟩ hd9728 - (by simp only [List.length_cons]; omega) - have rd9731 := by - simpa using burnRDSignextend rd9730 hd9730 - (by simp only [List.length_cons]; omega) - have rd9732 := by - simpa using rd9731.swap1 hd9731 - (by simp only [List.length_cons]; omega) - have rd9733 := by - simpa [burnModifyPositionMem4] using - rd9732.mstore 3 (burnModifyPositionMem4 ee) (UInt256.ofNat 8) - hd9732 - mem_cost - (by rfl) - (by native_decide) - (by simp only [List.length_cons]; omega) - have rd9736 := by - simpa using rd9733.push2 ⟨16233⟩ hd9733 - (by simp only [List.length_cons]; omega) - exact ⟨_, _, rd9736.jump hd9736 (uniswapV3PoolJumpDestPatched16233 hpatch) - (by simp only [List.length_cons]; omega)⟩ - -theorem uniswapV3PoolBurnNoDelegateCallOk {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨16233⟩ - (⟨128⟩ :: ⟨9737⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnModifyPositionMem4 ee) (UInt256.ofNat 8) rdata (cA, σ) k C) - (hguard : uniswapV3PoolNoDelegateCallGuard v ee ≠ ⟨0⟩) - (hov : R.length + 19 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨16246⟩ - (⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnModifyPositionMem4 ee) (UInt256.ofNat 8) rdata (cA, σ) k' C' := by - have hd16233 : decode code ⟨16233⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16234 : decode code ⟨16234⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16236 : decode code ⟨16236⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16237 : decode code ⟨16237⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16239 : decode code ⟨16239⟩ = some (.Push .PUSH2, some (⟨16246⟩, 2)) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16242 : decode code ⟨16242⟩ = some (.Push .PUSH2, some (⟨11248⟩, 2)) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16245 : decode code ⟨16245⟩ = some (.JUMP, .none) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have rd16234 := by - simpa using h.jumpdest hd16233 - (by simp only [List.length_cons]; omega) - have rd16236 := by - simpa using rd16234.push1 ⟨0⟩ hd16234 - (by simp only [List.length_cons]; omega) - have rd16237 := by - simpa using rd16236.dup1 hd16236 - (by simp only [List.length_cons]; omega) - have rd16239 := by - simpa using rd16237.push1 ⟨0⟩ hd16237 - (by simp only [List.length_cons]; omega) - have rd16242 := by - simpa using rd16239.push2 ⟨16246⟩ hd16239 - (by simp only [List.length_cons]; omega) - have rd16245 := by - simpa using rd16242.push2 ⟨11248⟩ hd16242 - (by simp only [List.length_cons]; omega) - have rd11248 := rd16245.jump hd16245 (uniswapV3PoolJumpDestPatched11248 hpatch) - (by simp only [List.length_cons]; omega) - obtain ⟨_, _, hrd⟩ := - uniswapV3PoolNoDelegateCallReturnOk (v := v) (code := code) (ee := ee) (g := g) - (s0 := s0) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (mem := burnModifyPositionMem4 ee) (aw := UInt256.ofNat 8) (rdata := rdata) - (acc := (cA, σ)) hpatch rd11248 hguard - (uniswapV3PoolJumpDestPatched16246 hpatch) - (by simp only [List.length_cons]; omega) - exact ⟨_, _, by simpa using hrd⟩ - -theorem uniswapV3PoolBurnLiquidityDeltaInt128Revert {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨16216⟩ - (burnAmountCleanWord ee :: ⟨9724⟩ :: ⟨224⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: burnAmountCleanWord ee :: - burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: ret :: R) - (burnModifyPositionMem3 ee) (UInt256.ofNat 7) rdata (cA, σ) k C) - (hcheck : - UInt256.eq (burnAmountCleanWord ee) - (UInt256.signextend ⟨15⟩ (burnAmountCleanWord ee)) = ⟨0⟩) - (hov : R.length + 18 ≤ 1024) : - RDrev code g s0 := by - have hd16216 : decode code ⟨16216⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16217 : decode code ⟨16217⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16218 : decode code ⟨16218⟩ = some (.Push .PUSH1, some (⟨15⟩, 1)) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16220 : decode code ⟨16220⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16221 : decode code ⟨16221⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16222 : decode code ⟨16222⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16223 : decode code ⟨16223⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16224 : decode code ⟨16224⟩ = some (.EQ, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16225 : decode code ⟨16225⟩ = some (.Push .PUSH2, some (⟨11243⟩, 2)) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16228 : decode code ⟨16228⟩ = some (.JUMPI, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16229 : decode code ⟨16229⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16231 : decode code ⟨16231⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have hd16232 : decode code ⟨16232⟩ = some (.REVERT, .none) := by - rw [uniswapV3PoolBurnSharedDecodeEqTemplate hpatch (by native_decide) (by native_decide)] - native_decide - have rd16217 := by - simpa using h.jumpdest hd16216 - (by simp only [List.length_cons]; omega) - have rd16218 := by - simpa using rd16217.dup1 hd16217 - (by simp only [List.length_cons]; omega) - have rd16220 := by - simpa using rd16218.push1 ⟨15⟩ hd16218 - (by simp only [List.length_cons]; omega) - have rd16221 := by - simpa using rd16220.dup2 hd16220 - (by simp only [List.length_cons]; omega) - have rd16222 := by - simpa using rd16221.swap1 hd16221 - (by simp only [List.length_cons]; omega) - have rd16223 := by - simpa using burnRDSignextend rd16222 hd16222 - (by simp only [List.length_cons]; omega) - have rd16224 := by - simpa using rd16223.dup2 hd16223 - (by simp only [List.length_cons]; omega) - have rd16225 := by - simpa using rd16224.eq hd16224 - (by simp only [List.length_cons]; omega) - have rd16228 := by - simpa using rd16225.push2 ⟨11243⟩ hd16225 - (by simp only [List.length_cons]; omega) - have rd16229 := rd16228.jumpiNT hd16228 hcheck - (by simp only [List.length_cons]; omega) - have rd16231 := by - simpa using rd16229.push1 ⟨0⟩ hd16229 - (by simp only [List.length_cons]; omega) - have rd16232 := by - simpa using rd16231.dup1 hd16231 - (by simp only [List.length_cons]; omega) - exact rd16232.rev 0 hd16232 mem_cost - (by simp only [List.length_cons]; omega) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnAfterCheckTicks.lean b/Benchmarks/UniswapV3Pool/BurnAfterCheckTicks.lean deleted file mode 100644 index bee44251..00000000 --- a/Benchmarks/UniswapV3Pool/BurnAfterCheckTicks.lean +++ /dev/null @@ -1,1993 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnCheckTicks -import Benchmarks.UniswapV3Pool.InitializeGetTickLogCombine - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev burnSlot0SqrtPriceX96Value (σ : AccountMap) (I : ExecutionEnv) : Value := - .int (Int.ofNat (slot0SqrtPriceX96Word σ I).toNat) - -abbrev burnSlot0TickValue (σ : AccountMap) (I : ExecutionEnv) : Value := - wordToElem (.int int24Int) (slot0TickRawWord σ I) - -abbrev burnSlot0ObservationIndexValue (σ : AccountMap) (I : ExecutionEnv) : Value := - .int (Int.ofNat (slot0ObservationIndexWord σ I).toNat) - -abbrev burnSlot0ObservationCardinalityValue (σ : AccountMap) (I : ExecutionEnv) : - Value := - .int (Int.ofNat (slot0ObservationCardinalityWord σ I).toNat) - -abbrev burnSlot0ObservationCardinalityNextValue (σ : AccountMap) (I : ExecutionEnv) : - Value := - .int (Int.ofNat (slot0ObservationCardinalityNextWord σ I).toNat) - -abbrev burnModifyPositionAfterSlot0Frame - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (((((burnModifyPositionStore I) - |>.insert "_slot0sqrtPriceX96" (burnSlot0SqrtPriceX96Value σ I)) - |>.insert "_slot0tick" (burnSlot0TickValue σ I)) - |>.insert "_slot0observationIndex" (burnSlot0ObservationIndexValue σ I)) - |>.insert "_slot0observationCardinality" - (burnSlot0ObservationCardinalityValue σ I)) - |>.insert "_slot0observationCardinalityNext" - (burnSlot0ObservationCardinalityNextValue σ I) } - -abbrev burnPositionKeyPackedList (I : ExecutionEnv) : List UInt8 := - ((EVM.word I.source).toBytesBE.drop 12) ++ - ((EVM.wordOfInt (tickSpacingSint24Value (burnTickLowerWord I))).toBytesBE.drop 29) ++ - ((EVM.wordOfInt (tickSpacingSint24Value (burnTickUpperWord I))).toBytesBE.drop 29) - -abbrev burnPositionKeyPackedBytes (I : ExecutionEnv) : ByteArray := - ByteArray.mk (burnPositionKeyPackedList I).toArray - -abbrev burnPositionKeyValue (I : ExecutionEnv) : Value := - .fixedBytes ⟨31, by decide⟩ (ffi.KEC (burnPositionKeyPackedBytes I)).toList - -abbrev burnModifyPositionAfterPositionKeyFrame - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnModifyPositionAfterSlot0Frame v σ I).locals.insert "_positionKey" - (burnPositionKeyValue I) } - -abbrev burnFeeGrowthGlobal0Value (σ : AccountMap) (I : ExecutionEnv) : Value := - .int (Int.ofNat (solcSlotWord σ I ⟨1⟩).toNat) - -abbrev burnFeeGrowthGlobal1Value (σ : AccountMap) (I : ExecutionEnv) : Value := - .int (Int.ofNat (solcSlotWord σ I ⟨2⟩).toNat) - -abbrev burnModifyPositionAfterFeeGrowthGlobalsFrame - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := ((((burnModifyPositionAfterPositionKeyFrame v σ I).locals - |>.insert "_feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I)) - |>.insert "_feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I)) - |>.insert "flippedLower" (.bool false)) - |>.insert "flippedUpper" (.bool false) } - -def burnModifyPositionSlot0Prefix : List Stmt := - [ .letDecl "_slot0sqrtPriceX96" (some uint160) (.storage (slot0F "sqrtPriceX96")), - .letDecl "_slot0tick" (some int24) (.storage (slot0F "tick")), - .letDecl "_slot0observationIndex" (some uint16) - (.storage (slot0F "observationIndex")), - .letDecl "_slot0observationCardinality" (some uint16) - (.storage (slot0F "observationCardinality")), - .letDecl "_slot0observationCardinalityNext" (some uint16) - (.storage (slot0F "observationCardinalityNext")) ] - -def burnModifyPositionPositionKeyStep : List Stmt := - [ .letDecl "_positionKey" (some bytes32) - (positionKey (.var "owner") (.var "tickLower") (.var "tickUpper")) ] - -def burnModifyPositionFeeGrowthGlobalsStep : List Stmt := - [ .letDecl "_feeGrowthGlobal0X128" (some uint256) (.storage feeGrowthGlobal0X128Ref), - .letDecl "_feeGrowthGlobal1X128" (some uint256) (.storage feeGrowthGlobal1X128Ref), - .letDecl "flippedLower" (some boolTy) (.boolLit false), - .letDecl "flippedUpper" (some boolTy) (.boolLit false) ] - -theorem burnEvalSlot0SqrtPriceX96 {v : PoolImmutables} - {L : Store} {cA gh bl σ σ₀ A I} {g : Sat256} - (hbase : L.get? "slot0" = none) : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "sqrtPriceX96")) = - .ok (burnSlot0SqrtPriceX96Value σ I) := by - rw [evalExpr_storage_scalar - (t := .int uint160Int) - (slot := slot0F "sqrtPriceX96") - (er := { base := "slot0", steps := [.field "sqrtPriceX96"] }) - (loc := loc ⟨0⟩ ⟨0, by decide⟩ ⟨20, by decide⟩ (by decide) - (.int uint160Int)) - (hbase := by simpa [slot0F] using hbase) - (her := by simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - uint160St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [burnSlot0SqrtPriceX96Value, initState, slot0SqrtPriceX96Word, slot0SlotWord, - solcSlotWord] using - slot0StorageLocLoad_sqrtPriceX96 (initState cA gh bl σ σ₀ g A I) - -theorem burnEvalSlot0Tick {v : PoolImmutables} - {L : Store} {cA gh bl σ σ₀ A I} {g : Sat256} - (hbase : L.get? "slot0" = none) : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "tick")) = - .ok (burnSlot0TickValue σ I) := by - rw [evalExpr_storage_scalar - (t := .int int24Int) - (slot := slot0F "tick") - (er := { base := "slot0", steps := [.field "tick"] }) - (loc := loc ⟨0⟩ ⟨20, by decide⟩ ⟨3, by decide⟩ (by decide) - (.int int24Int)) - (hbase := by simpa [slot0F] using hbase) - (her := by simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, int24St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [burnSlot0TickValue, initState, slot0TickRawWord, slot0SlotWord, solcSlotWord] using - slot0StorageLocLoad_tick (initState cA gh bl σ σ₀ g A I) - -theorem burnEvalSlot0ObservationIndex {v : PoolImmutables} - {L : Store} {cA gh bl σ σ₀ A I} {g : Sat256} - (hbase : L.get? "slot0" = none) : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "observationIndex")) = - .ok (burnSlot0ObservationIndexValue σ I) := by - rw [evalExpr_storage_scalar - (t := .int uint16Int) - (slot := slot0F "observationIndex") - (er := { base := "slot0", steps := [.field "observationIndex"] }) - (loc := loc ⟨0⟩ ⟨23, by decide⟩ ⟨2, by decide⟩ (by decide) - (.int uint16Int)) - (hbase := by simpa [slot0F] using hbase) - (her := by simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - uint16St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [burnSlot0ObservationIndexValue, initState, slot0ObservationIndexWord, - slot0SlotWord, solcSlotWord] using - slot0StorageLocLoad_observationIndex (initState cA gh bl σ σ₀ g A I) - -theorem burnEvalSlot0ObservationCardinality {v : PoolImmutables} - {L : Store} {cA gh bl σ σ₀ A I} {g : Sat256} - (hbase : L.get? "slot0" = none) : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "observationCardinality")) = - .ok (burnSlot0ObservationCardinalityValue σ I) := by - rw [evalExpr_storage_scalar - (t := .int uint16Int) - (slot := slot0F "observationCardinality") - (er := { base := "slot0", steps := [.field "observationCardinality"] }) - (loc := loc ⟨0⟩ ⟨25, by decide⟩ ⟨2, by decide⟩ (by decide) - (.int uint16Int)) - (hbase := by simpa [slot0F] using hbase) - (her := by simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - uint16St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [burnSlot0ObservationCardinalityValue, initState, - slot0ObservationCardinalityWord, slot0SlotWord, solcSlotWord] using - slot0StorageLocLoad_observationCardinality (initState cA gh bl σ σ₀ g A I) - -theorem burnEvalSlot0ObservationCardinalityNext {v : PoolImmutables} - {L : Store} {cA gh bl σ σ₀ A I} {g : Sat256} - (hbase : L.get? "slot0" = none) : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) - (.storage (slot0F "observationCardinalityNext")) = - .ok (burnSlot0ObservationCardinalityNextValue σ I) := by - rw [evalExpr_storage_scalar - (t := .int uint16Int) - (slot := slot0F "observationCardinalityNext") - (er := { base := "slot0", steps := [.field "observationCardinalityNext"] }) - (loc := loc ⟨0⟩ ⟨27, by decide⟩ ⟨2, by decide⟩ (by decide) - (.int uint16Int)) - (hbase := by simpa [slot0F] using hbase) - (her := by simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - uint16St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [burnSlot0ObservationCardinalityNextValue, initState, - slot0ObservationCardinalityNextWord, slot0SlotWord, solcSlotWord] using - slot0StorageLocLoad_observationCardinalityNext (initState cA gh bl σ σ₀ g A I) - -theorem uniswapV3PoolModifyPositionSourceSlot0Loads {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - burnModifyPositionSlot0Prefix - (ExecResult.ok (burnModifyPositionAfterSlot0Frame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - refine ExecBlock.consNormal - (ExecStmt.letDecl (burnEvalSlot0SqrtPriceX96 (v := v) - (L := burnModifyPositionStore I) (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (by simp [burnModifyPositionStore]))) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl (burnEvalSlot0Tick (v := v) - (L := (burnModifyPositionStore I).insert "_slot0sqrtPriceX96" - (burnSlot0SqrtPriceX96Value σ I)) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) - (by simp [burnModifyPositionStore]))) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl (burnEvalSlot0ObservationIndex (v := v) - (L := ((burnModifyPositionStore I) - |>.insert "_slot0sqrtPriceX96" (burnSlot0SqrtPriceX96Value σ I)) - |>.insert "_slot0tick" (burnSlot0TickValue σ I)) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) - (by simp [burnModifyPositionStore]))) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl (burnEvalSlot0ObservationCardinality (v := v) - (L := (((burnModifyPositionStore I) - |>.insert "_slot0sqrtPriceX96" (burnSlot0SqrtPriceX96Value σ I)) - |>.insert "_slot0tick" (burnSlot0TickValue σ I)) - |>.insert "_slot0observationIndex" (burnSlot0ObservationIndexValue σ I)) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) - (by simp [burnModifyPositionStore]))) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl (burnEvalSlot0ObservationCardinalityNext (v := v) - (L := ((((burnModifyPositionStore I) - |>.insert "_slot0sqrtPriceX96" (burnSlot0SqrtPriceX96Value σ I)) - |>.insert "_slot0tick" (burnSlot0TickValue σ I)) - |>.insert "_slot0observationIndex" (burnSlot0ObservationIndexValue σ I)) - |>.insert "_slot0observationCardinality" - (burnSlot0ObservationCardinalityValue σ I)) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) - (by simp [burnModifyPositionStore]))) ?_ - exact ExecBlock.nil - -theorem uniswapV3PoolModifyPositionSourceThroughSlot0Loads {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - (noDelegateCall v ++ checkTicksBody (.var "tickLower") (.var "tickUpper") ++ - burnModifyPositionSlot0Prefix) - (ExecResult.ok (burnModifyPositionAfterSlot0Frame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := uniswapV3PoolModifyPositionSourceThroughUpperLe (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard htickLt hge hle - exact execBlock_append hprefix - (uniswapV3PoolModifyPositionSourceSlot0Loads (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g)) - -theorem burnModifyPositionStore_owner (I : ExecutionEnv) : - (burnModifyPositionStore I).get? "owner" = some (.address I.source) := by - rw [burnModifyPositionStore] - exact store_get_self - ((((∅ : Store).insert "liquidityDelta" (burnLiquidityDeltaValue I)) - |>.insert "tickUpper" (burnTickUpperValue I)) - |>.insert "tickLower" (burnTickLowerValue I)) - "owner" (.address I.source) - -theorem burnAfterSlot0Frame_owner {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterSlot0Frame v σ I).locals.get? "owner" = - some (.address I.source) := by - rw [burnModifyPositionAfterSlot0Frame] - rw [store_get_ne5 (burnModifyPositionStore I) - (k1 := "_slot0sqrtPriceX96") (k2 := "_slot0tick") - (k3 := "_slot0observationIndex") (k4 := "_slot0observationCardinality") - (k5 := "_slot0observationCardinalityNext") (a := "owner") - (burnSlot0SqrtPriceX96Value σ I) (burnSlot0TickValue σ I) - (burnSlot0ObservationIndexValue σ I) (burnSlot0ObservationCardinalityValue σ I) - (burnSlot0ObservationCardinalityNextValue σ I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide)] - exact burnModifyPositionStore_owner I - -theorem burnAfterSlot0Frame_tickLower {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterSlot0Frame v σ I).locals.get? "tickLower" = - some (burnTickLowerValue I) := by - rw [burnModifyPositionAfterSlot0Frame] - rw [store_get_ne5 (burnModifyPositionStore I) - (k1 := "_slot0sqrtPriceX96") (k2 := "_slot0tick") - (k3 := "_slot0observationIndex") (k4 := "_slot0observationCardinality") - (k5 := "_slot0observationCardinalityNext") (a := "tickLower") - (burnSlot0SqrtPriceX96Value σ I) (burnSlot0TickValue σ I) - (burnSlot0ObservationIndexValue σ I) (burnSlot0ObservationCardinalityValue σ I) - (burnSlot0ObservationCardinalityNextValue σ I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide)] - exact burnModifyPositionStore_tickLower I - -theorem burnAfterSlot0Frame_tickUpper {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterSlot0Frame v σ I).locals.get? "tickUpper" = - some (burnTickUpperValue I) := by - rw [burnModifyPositionAfterSlot0Frame] - rw [store_get_ne5 (burnModifyPositionStore I) - (k1 := "_slot0sqrtPriceX96") (k2 := "_slot0tick") - (k3 := "_slot0observationIndex") (k4 := "_slot0observationCardinality") - (k5 := "_slot0observationCardinalityNext") (a := "tickUpper") - (burnSlot0SqrtPriceX96Value σ I) (burnSlot0TickValue σ I) - (burnSlot0ObservationIndexValue σ I) (burnSlot0ObservationCardinalityValue σ I) - (burnSlot0ObservationCardinalityNextValue σ I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide)] - exact burnModifyPositionStore_tickUpper I - -theorem burnEvalOwnerAfterSlot0 {v : PoolImmutables} - {σ : AccountMap} {cA gh bl σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnModifyPositionAfterSlot0Frame v σ I) - (initState cA gh bl σ σ₀ g A I) (.var "owner") = .ok (.address I.source) := by - unfold evalExpr? - rw [burnAfterSlot0Frame_owner] - rfl - -theorem burnEvalTickLowerAfterSlot0 {v : PoolImmutables} - {σ : AccountMap} {cA gh bl σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnModifyPositionAfterSlot0Frame v σ I) - (initState cA gh bl σ σ₀ g A I) (.var "tickLower") = - .ok (burnTickLowerValue I) := by - unfold evalExpr? - rw [burnAfterSlot0Frame_tickLower] - rfl - -theorem burnEvalTickUpperAfterSlot0 {v : PoolImmutables} - {σ : AccountMap} {cA gh bl σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnModifyPositionAfterSlot0Frame v σ I) - (initState cA gh bl σ σ₀ g A I) (.var "tickUpper") = - .ok (burnTickUpperValue I) := by - unfold evalExpr? - rw [burnAfterSlot0Frame_tickUpper] - rfl - -theorem burnEncodePackedTickLower (I : ExecutionEnv) : - encodePackedValue? int24 (burnTickLowerValue I) = - some ((EVM.wordOfInt (tickSpacingSint24Value (burnTickLowerWord I))).toBytesBE.drop 29) := by - have hge : -↑(EVM.twoPow 23) ≤ tickSpacingSint24Value (burnTickLowerWord I) := by - simpa [EVM.twoPow] using tickSpacingSint24Value_ge (burnTickLowerWord I) - have hlt : tickSpacingSint24Value (burnTickLowerWord I) < ↑(EVM.twoPow 23) := by - simpa [EVM.twoPow] using tickSpacingSint24Value_lt (burnTickLowerWord I) - simp [encodePackedValue?, burnTickLowerValue, int24, int24Int, encodeABIWord?, hge, hlt] - -theorem burnEncodePackedTickUpper (I : ExecutionEnv) : - encodePackedValue? int24 (burnTickUpperValue I) = - some ((EVM.wordOfInt (tickSpacingSint24Value (burnTickUpperWord I))).toBytesBE.drop 29) := by - have hge : -↑(EVM.twoPow 23) ≤ tickSpacingSint24Value (burnTickUpperWord I) := by - simpa [EVM.twoPow] using tickSpacingSint24Value_ge (burnTickUpperWord I) - have hlt : tickSpacingSint24Value (burnTickUpperWord I) < ↑(EVM.twoPow 23) := by - simpa [EVM.twoPow] using tickSpacingSint24Value_lt (burnTickUpperWord I) - simp [encodePackedValue?, burnTickUpperValue, int24, int24Int, encodeABIWord?, hge, hlt] - -theorem burnEvalPackedArgsTickUpper {v : PoolImmutables} - {σ : AccountMap} {cA gh bl σ₀ A I} {g : Sat256} : - evalPackedArgs? (config v) (burnModifyPositionAfterSlot0Frame v σ I) - (initState cA gh bl σ σ₀ g A I) [(int24, .var "tickUpper")] = - .ok ((EVM.wordOfInt (tickSpacingSint24Value (burnTickUpperWord I))).toBytesBE.drop 29) := by - unfold evalPackedArgs? - rw [burnEvalTickUpperAfterSlot0] - simp only [EvalResult.bind, bind, pure, EvalResult.ofOption, burnEncodePackedTickUpper] - unfold evalPackedArgs? - simp only [List.append_nil] - -theorem burnEvalPackedArgsTicks {v : PoolImmutables} - {σ : AccountMap} {cA gh bl σ₀ A I} {g : Sat256} : - evalPackedArgs? (config v) (burnModifyPositionAfterSlot0Frame v σ I) - (initState cA gh bl σ σ₀ g A I) [(int24, .var "tickLower"), (int24, .var "tickUpper")] = - .ok (((EVM.wordOfInt (tickSpacingSint24Value (burnTickLowerWord I))).toBytesBE.drop 29) ++ - ((EVM.wordOfInt (tickSpacingSint24Value (burnTickUpperWord I))).toBytesBE.drop 29)) := by - unfold evalPackedArgs? - rw [burnEvalTickLowerAfterSlot0] - simp only [EvalResult.bind, bind, pure, EvalResult.ofOption, burnEncodePackedTickLower] - rw [burnEvalPackedArgsTickUpper] - -theorem burnEvalPackedPositionKeyArgs {v : PoolImmutables} - {σ : AccountMap} {cA gh bl σ₀ A I} {g : Sat256} : - evalPackedArgs? (config v) (burnModifyPositionAfterSlot0Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - [(addr, .var "owner"), (int24, .var "tickLower"), (int24, .var "tickUpper")] = - .ok (burnPositionKeyPackedList I) := by - unfold evalPackedArgs? - rw [burnEvalOwnerAfterSlot0] - simp only [EvalResult.bind, bind, pure, EvalResult.ofOption] - simp [addr, encodePackedValue?, burnPositionKeyPackedList] - rw [burnEvalPackedArgsTicks] - -theorem burnEvalAbiEncodePackedPositionKey {v : PoolImmutables} - {σ : AccountMap} {cA gh bl σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnModifyPositionAfterSlot0Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.abiEncodePacked [(addr, .var "owner"), (int24, .var "tickLower"), - (int24, .var "tickUpper")]) = - .ok (.bytes (burnPositionKeyPackedBytes I)) := by - unfold evalExpr? - rw [burnEvalPackedPositionKeyArgs] - rfl - -theorem burnEvalPositionKey {v : PoolImmutables} - {σ : AccountMap} {cA gh bl σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnModifyPositionAfterSlot0Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - (positionKey (.var "owner") (.var "tickLower") (.var "tickUpper")) = - .ok (burnPositionKeyValue I) := by - unfold positionKey - unfold evalExpr? - rw [burnEvalAbiEncodePackedPositionKey] - rfl - -theorem uniswapV3PoolModifyPositionSourcePositionKey {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - ExecBlock (config v) (burnModifyPositionAfterSlot0Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - burnModifyPositionPositionKeyStep - (ExecResult.ok (burnModifyPositionAfterPositionKeyFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - refine ExecBlock.consNormal (ExecStmt.letDecl (burnEvalPositionKey (v := v) - (σ := σ) (cA := cA) (gh := gh) (bl := bl) (σ₀ := σ₀) (A := A) - (I := I) (g := g))) ?_ - exact ExecBlock.nil - -theorem uniswapV3PoolModifyPositionSourceThroughPositionKey {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - (noDelegateCall v ++ checkTicksBody (.var "tickLower") (.var "tickUpper") ++ - burnModifyPositionSlot0Prefix ++ burnModifyPositionPositionKeyStep) - (ExecResult.ok (burnModifyPositionAfterPositionKeyFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := uniswapV3PoolModifyPositionSourceThroughSlot0Loads (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard htickLt hge hle - exact execBlock_append hprefix - (uniswapV3PoolModifyPositionSourcePositionKey (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g)) - -theorem burnEvalFeeGrowthGlobal0 {v : PoolImmutables} - {L : Store} {cA gh bl σ σ₀ A I} {g : Sat256} - (hbase : L.get? "feeGrowthGlobal0X128" = none) : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) (.storage feeGrowthGlobal0X128Ref) = - .ok (burnFeeGrowthGlobal0Value σ I) := by - apply evalExpr_storage_scalar_value - (er := { base := "feeGrowthGlobal0X128", steps := [] }) - (t := .int uint256Int) - (loc := loc ⟨1⟩ ⟨0, by decide⟩ ⟨32, by decide⟩ (by decide) - (.int uint256Int)) - · simpa [feeGrowthGlobal0X128Ref] using hbase - · simp [evalStorageRef, feeGrowthGlobal0X128Ref, pure, bind, EvalResult.bind] - · simp [contract, storageDecls, storageTypeAt?, uint256St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc] - · simpa [burnFeeGrowthGlobal0Value, initState, solcSlotWord, loc, uint256Loc] using - (storageLocLoad_uint256 (initState cA gh bl σ σ₀ g A I) ⟨1⟩) - -theorem burnEvalFeeGrowthGlobal1 {v : PoolImmutables} - {L : Store} {cA gh bl σ σ₀ A I} {g : Sat256} - (hbase : L.get? "feeGrowthGlobal1X128" = none) : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) (.storage feeGrowthGlobal1X128Ref) = - .ok (burnFeeGrowthGlobal1Value σ I) := by - apply evalExpr_storage_scalar_value - (er := { base := "feeGrowthGlobal1X128", steps := [] }) - (t := .int uint256Int) - (loc := loc ⟨2⟩ ⟨0, by decide⟩ ⟨32, by decide⟩ (by decide) - (.int uint256Int)) - · simpa [feeGrowthGlobal1X128Ref] using hbase - · simp [evalStorageRef, feeGrowthGlobal1X128Ref, pure, bind, EvalResult.bind] - · simp [contract, storageDecls, storageTypeAt?, uint256St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc] - · simpa [burnFeeGrowthGlobal1Value, initState, solcSlotWord, loc, uint256Loc] using - (storageLocLoad_uint256 (initState cA gh bl σ σ₀ g A I) ⟨2⟩) - -theorem uniswapV3PoolModifyPositionSourceFeeGrowthGlobals {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - ExecBlock (config v) (burnModifyPositionAfterPositionKeyFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - burnModifyPositionFeeGrowthGlobalsStep - (ExecResult.ok (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - refine ExecBlock.consNormal - (ExecStmt.letDecl (burnEvalFeeGrowthGlobal0 (v := v) - (L := (burnModifyPositionAfterPositionKeyFrame v σ I).locals) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) - (by - simp [burnModifyPositionStore]))) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl (burnEvalFeeGrowthGlobal1 (v := v) - (L := ((burnModifyPositionAfterPositionKeyFrame v σ I).locals - |>.insert "_feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I))) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) - (by - simp [burnModifyPositionStore]))) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (by - change evalExpr? _ _ _ (.boolLit false) = .ok (.bool false) - unfold evalExpr? - rfl)) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (by - change evalExpr? _ _ _ (.boolLit false) = .ok (.bool false) - unfold evalExpr? - rfl)) ?_ - exact ExecBlock.nil - -theorem uniswapV3PoolModifyPositionSourceThroughFeeGrowthGlobals {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - (noDelegateCall v ++ checkTicksBody (.var "tickLower") (.var "tickUpper") ++ - burnModifyPositionSlot0Prefix ++ burnModifyPositionPositionKeyStep ++ - burnModifyPositionFeeGrowthGlobalsStep) - (ExecResult.ok (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := uniswapV3PoolModifyPositionSourceThroughPositionKey (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard htickLt hge hle - exact execBlock_append hprefix - (uniswapV3PoolModifyPositionSourceFeeGrowthGlobals (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g)) - -noncomputable def burnModifyPositionSlot0Mem0 (I : ExecutionEnv) : ByteArray := - writeWord (burnModifyPositionMem4 I) 64 (UInt256.ofNat 480) - -noncomputable def burnModifyPositionSlot0Mem1 (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnModifyPositionSlot0Mem0 I) 256 (slot0SqrtPriceX96Word σ I) - -noncomputable def burnModifyPositionSlot0Mem2 (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnModifyPositionSlot0Mem1 σ I) 288 (slot0TickReturnWord σ I) - -noncomputable def burnModifyPositionSlot0Mem3 (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnModifyPositionSlot0Mem2 σ I) 320 (slot0ObservationIndexWord σ I) - -noncomputable def burnModifyPositionSlot0Mem4 (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnModifyPositionSlot0Mem3 σ I) 352 (slot0ObservationCardinalityWord σ I) - -noncomputable def burnModifyPositionSlot0Mem5 (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnModifyPositionSlot0Mem4 σ I) 384 - (slot0ObservationCardinalityNextWord σ I) - -noncomputable def burnModifyPositionSlot0Mem6 (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnModifyPositionSlot0Mem5 σ I) 416 (slot0FeeProtocolWord σ I) - -noncomputable def burnModifyPositionSlot0Mem (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnModifyPositionSlot0Mem6 σ I) 448 - (slot0BoolReturnWord (slot0UnlockedRawWord σ I)) - -private theorem burnModifyPositionMem0_size_forSlot0 : - burnModifyPositionMem0.size = 96 := by - unfold burnModifyPositionMem0 - change ((UInt256.toByteArray (⟨256⟩ : UInt256)).write 0 solcFreePtrMem 64 32).size = 96 - exact toByteArray_write32_size_of_le solcFreePtrMem (⟨256⟩ : UInt256) 64 96 96 - solcFreePtrMem_size (by rw [solcFreePtrMem_size]; omega) (by omega) - -private theorem burnModifyPositionMem1_size_forSlot0 (I : ExecutionEnv) : - (burnModifyPositionMem1 I).size = 160 := by - unfold burnModifyPositionMem1 - change (writeWord burnModifyPositionMem0 128 (UInt256.ofNat I.source.val)).size = 160 - rw [writeWord_size] - · rw [burnModifyPositionMem0_size_forSlot0] - omega - · rw [burnModifyPositionMem0_size_forSlot0] - native_decide - -private theorem burnModifyPositionMem2_size_forSlot0 (I : ExecutionEnv) : - (burnModifyPositionMem2 I).size = 192 := by - unfold burnModifyPositionMem2 - change (writeWord (burnModifyPositionMem1 I) 160 - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))).size = 192 - rw [writeWord_size] - · rw [burnModifyPositionMem1_size_forSlot0 I] - omega - · rw [burnModifyPositionMem1_size_forSlot0 I] - native_decide - -private theorem burnModifyPositionMem3_size_forSlot0 (I : ExecutionEnv) : - (burnModifyPositionMem3 I).size = 224 := by - unfold burnModifyPositionMem3 - change (writeWord (burnModifyPositionMem2 I) 192 - (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))).size = 224 - rw [writeWord_size] - · rw [burnModifyPositionMem2_size_forSlot0 I] - omega - · rw [burnModifyPositionMem2_size_forSlot0 I] - native_decide - -private theorem burnModifyPositionMem4_cascadeFromMem0_forSlot0 (I : ExecutionEnv) : - burnModifyPositionMem4 I = - writeCascade burnModifyPositionMem0 - [(128, UInt256.ofNat I.source.val), - (160, UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)), - (192, UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)), - (224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] := by - rfl - -private theorem burnModifyPositionMem4_cascadeFromMem1_forSlot0 (I : ExecutionEnv) : - burnModifyPositionMem4 I = - writeCascade (burnModifyPositionMem1 I) - [(160, UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)), - (192, UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)), - (224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] := by - rfl - -private theorem burnModifyPositionMem4_cascadeFromMem2_forSlot0 (I : ExecutionEnv) : - burnModifyPositionMem4 I = - writeCascade (burnModifyPositionMem2 I) - [(192, UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)), - (224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] := by - rfl - -private theorem burnModifyPositionMem4_cascadeFromMem3_forSlot0 (I : ExecutionEnv) : - burnModifyPositionMem4 I = - writeCascade (burnModifyPositionMem3 I) - [(224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] := by - rfl - -theorem burnModifyPositionMem4_read128 (I : ExecutionEnv) : - (burnModifyPositionMem4 I).readWithPadding 128 32 = - UInt256.toByteArray (UInt256.ofNat I.source.val) := by - rw [burnModifyPositionMem4_cascadeFromMem0_forSlot0] - exact writeCascade_read_word_of_head_of_base burnModifyPositionMem0 (base := 96) - (off := 128) (UInt256.ofNat I.source.val) - [(160, UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)), - (192, UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)), - (224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] - burnModifyPositionMem0_size_forSlot0 (by native_decide) - (by - simp [WindowDisjointFromWrites]) - -theorem burnModifyPositionMem4_read160 (I : ExecutionEnv) : - (burnModifyPositionMem4 I).readWithPadding 160 32 = - UInt256.toByteArray (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) := by - rw [burnModifyPositionMem4_cascadeFromMem1_forSlot0] - exact writeCascade_read_word_of_head_of_base (burnModifyPositionMem1 I) (base := 160) - (off := 160) (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - [(192, UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)), - (224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] - (burnModifyPositionMem1_size_forSlot0 I) (by native_decide) - (by - simp [WindowDisjointFromWrites]) - -theorem burnModifyPositionMem4_read192 (I : ExecutionEnv) : - (burnModifyPositionMem4 I).readWithPadding 192 32 = - UInt256.toByteArray (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) := by - rw [burnModifyPositionMem4_cascadeFromMem2_forSlot0] - exact writeCascade_read_word_of_head_of_base (burnModifyPositionMem2 I) (base := 192) - (off := 192) (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - [(224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] - (burnModifyPositionMem2_size_forSlot0 I) (by native_decide) - (by - simp [WindowDisjointFromWrites]) - -theorem burnModifyPositionMem4_read224 (I : ExecutionEnv) : - (burnModifyPositionMem4 I).readWithPadding 224 32 = - UInt256.toByteArray - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) := by - rw [burnModifyPositionMem4_cascadeFromMem3_forSlot0] - exact writeCascade_read_word_of_head_of_base (burnModifyPositionMem3 I) (base := 224) - (off := 224) - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) [] - (burnModifyPositionMem3_size_forSlot0 I) (by native_decide) - (by simp [WindowDisjointFromWrites]) - -private def burnModifyPositionSlot0Writes (σ : AccountMap) (I : ExecutionEnv) : - List (Nat × UInt256) := - [(64, UInt256.ofNat 480), - (256, slot0SqrtPriceX96Word σ I), - (288, slot0TickReturnWord σ I), - (320, slot0ObservationIndexWord σ I), - (352, slot0ObservationCardinalityWord σ I), - (384, slot0ObservationCardinalityNextWord σ I), - (416, slot0FeeProtocolWord σ I), - (448, slot0BoolReturnWord (slot0UnlockedRawWord σ I))] - -private theorem burnModifyPositionSlot0Mem_cascade (σ : AccountMap) (I : ExecutionEnv) : - burnModifyPositionSlot0Mem σ I = - writeCascade (burnModifyPositionMem4 I) (burnModifyPositionSlot0Writes σ I) := by - rfl - -theorem burnModifyPositionSlot0Mem_size (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionSlot0Mem σ I).size = 480 := by - rw [burnModifyPositionSlot0Mem_cascade] - exact writeCascade_size_of_base (burnModifyPositionMem4 I) - (burnModifyPositionSlot0Writes σ I) (burnModifyPositionMem4_size I) - (by - simp [burnModifyPositionSlot0Writes, WriteGapsOk]) - (by simp [burnModifyPositionSlot0Writes, writeCascadeSize]) - -private theorem burnModifyPositionSlot0Mem_readPreserved - (σ : AccountMap) (I : ExecutionEnv) {off : Nat} - (hdisj : - WindowDisjointFromWrites 256 off 32 (burnModifyPositionSlot0Writes σ I)) : - (burnModifyPositionSlot0Mem σ I).readWithPadding off 32 = - (burnModifyPositionMem4 I).readWithPadding off 32 := by - rw [burnModifyPositionSlot0Mem_cascade] - exact writeCascade_read_preserved_of_base (burnModifyPositionMem4 I) - (burnModifyPositionSlot0Writes σ I) (base := 256) (read := off) - (burnModifyPositionMem4_size I) hdisj - -theorem burnModifyPositionSlot0Mem_read128 (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionSlot0Mem σ I).readWithPadding 128 32 = - UInt256.toByteArray (UInt256.ofNat I.source.val) := by - rw [burnModifyPositionSlot0Mem_readPreserved σ I - (by - simp [burnModifyPositionSlot0Writes, WindowDisjointFromWrites])] - exact burnModifyPositionMem4_read128 I - -theorem burnModifyPositionSlot0Mem_read160 (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionSlot0Mem σ I).readWithPadding 160 32 = - UInt256.toByteArray (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) := by - rw [burnModifyPositionSlot0Mem_readPreserved σ I - (by - simp [burnModifyPositionSlot0Writes, WindowDisjointFromWrites])] - exact burnModifyPositionMem4_read160 I - -theorem burnModifyPositionSlot0Mem_read192 (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionSlot0Mem σ I).readWithPadding 192 32 = - UInt256.toByteArray (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) := by - rw [burnModifyPositionSlot0Mem_readPreserved σ I - (by - simp [burnModifyPositionSlot0Writes, WindowDisjointFromWrites])] - exact burnModifyPositionMem4_read192 I - -theorem burnModifyPositionSlot0Mem_read224 (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionSlot0Mem σ I).readWithPadding 224 32 = - UInt256.toByteArray - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) := by - rw [burnModifyPositionSlot0Mem_readPreserved σ I - (by - simp [burnModifyPositionSlot0Writes, WindowDisjointFromWrites])] - exact burnModifyPositionMem4_read224 I - -theorem burnModifyPositionSlot0Mem_mload128 (σ : AccountMap) (I : ExecutionEnv) : - (if (⟨128⟩ : UInt256).toNat ≥ (burnModifyPositionSlot0Mem σ I).size - ∨ (⟨128⟩ : UInt256) ≥ UInt256.ofNat 15 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnModifyPositionSlot0Mem σ I).readWithPadding (⟨128⟩ : UInt256).toNat 32))) = - UInt256.ofNat I.source.val := by - exact mloadWordValue_of_readWithPadding - (mem := burnModifyPositionSlot0Mem σ I) (aw := UInt256.ofNat 15) - (off := ⟨128⟩) (v := UInt256.ofNat I.source.val) - (by rw [burnModifyPositionSlot0Mem_size σ I]; native_decide) - (by native_decide) - (by - simpa [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - using burnModifyPositionSlot0Mem_read128 σ I) - -theorem burnModifyPositionSlot0Mem_mload160 (σ : AccountMap) (I : ExecutionEnv) : - (if (⟨160⟩ : UInt256).toNat ≥ (burnModifyPositionSlot0Mem σ I).size - ∨ (⟨160⟩ : UInt256) ≥ UInt256.ofNat 15 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnModifyPositionSlot0Mem σ I).readWithPadding (⟨160⟩ : UInt256).toNat 32))) = - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) := by - exact mloadWordValue_of_readWithPadding - (mem := burnModifyPositionSlot0Mem σ I) (aw := UInt256.ofNat 15) - (off := ⟨160⟩) - (v := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (by rw [burnModifyPositionSlot0Mem_size σ I]; native_decide) - (by native_decide) - (by - simpa [show (⟨160⟩ : UInt256).toNat = 160 from by decide] - using burnModifyPositionSlot0Mem_read160 σ I) - -theorem burnModifyPositionSlot0Mem_mload192 (σ : AccountMap) (I : ExecutionEnv) : - (if (⟨192⟩ : UInt256).toNat ≥ (burnModifyPositionSlot0Mem σ I).size - ∨ (⟨192⟩ : UInt256) ≥ UInt256.ofNat 15 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnModifyPositionSlot0Mem σ I).readWithPadding (⟨192⟩ : UInt256).toNat 32))) = - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) := by - exact mloadWordValue_of_readWithPadding - (mem := burnModifyPositionSlot0Mem σ I) (aw := UInt256.ofNat 15) - (off := ⟨192⟩) - (v := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (by rw [burnModifyPositionSlot0Mem_size σ I]; native_decide) - (by native_decide) - (by - simpa [show (⟨192⟩ : UInt256).toNat = 192 from by decide] - using burnModifyPositionSlot0Mem_read192 σ I) - -theorem burnModifyPositionSlot0Mem_mload224 (σ : AccountMap) (I : ExecutionEnv) : - (if (⟨224⟩ : UInt256).toNat ≥ (burnModifyPositionSlot0Mem σ I).size - ∨ (⟨224⟩ : UInt256) ≥ UInt256.ofNat 15 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnModifyPositionSlot0Mem σ I).readWithPadding (⟨224⟩ : UInt256).toNat 32))) = - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) := by - exact mloadWordValue_of_readWithPadding - (mem := burnModifyPositionSlot0Mem σ I) (aw := UInt256.ofNat 15) - (off := ⟨224⟩) - (v := UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (by rw [burnModifyPositionSlot0Mem_size σ I]; native_decide) - (by native_decide) - (by - simpa [show (⟨224⟩ : UInt256).toNat = 224 from by decide] - using burnModifyPositionSlot0Mem_read224 σ I) - -theorem burnModifyPositionSlot0Mem_read64 (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionSlot0Mem σ I).readWithPadding 64 32 = - UInt256.toByteArray (UInt256.ofNat 480) := by - rw [burnModifyPositionSlot0Mem_cascade] - exact writeCascade_read_word_of_head_of_base (burnModifyPositionMem4 I) - (base := 256) (off := 64) (UInt256.ofNat 480) - [(256, slot0SqrtPriceX96Word σ I), - (288, slot0TickReturnWord σ I), - (320, slot0ObservationIndexWord σ I), - (352, slot0ObservationCardinalityWord σ I), - (384, slot0ObservationCardinalityNextWord σ I), - (416, slot0FeeProtocolWord σ I), - (448, slot0BoolReturnWord (slot0UnlockedRawWord σ I))] - (burnModifyPositionMem4_size I) (by native_decide) - (by simp [WindowDisjointFromWrites]) - -theorem burnModifyPositionSlot0Mem_mload64 (σ : AccountMap) (I : ExecutionEnv) : - (if (⟨64⟩ : UInt256).toNat ≥ (burnModifyPositionSlot0Mem σ I).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 15 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnModifyPositionSlot0Mem σ I).readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - UInt256.ofNat 480 := by - exact mloadWordValue_of_readWithPadding - (mem := burnModifyPositionSlot0Mem σ I) (aw := UInt256.ofNat 15) - (off := ⟨64⟩) (v := UInt256.ofNat 480) - (by rw [burnModifyPositionSlot0Mem_size σ I]; native_decide) - (by native_decide) - (by - simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using burnModifyPositionSlot0Mem_read64 σ I) - -theorem twoWordHashMem_read0_of_size_ge {mem : ByteArray} (key slot : UInt256) - (hmem : 64 ≤ mem.size) : - (twoWordHashMem key slot mem).readWithPadding 0 32 = - UInt256.toByteArray key := by - have hword0Size : (wordAt0Mem key mem).size = mem.size := by - unfold wordAt0Mem - change (writeWord mem 0 key).size = mem.size - rw [writeWord_size] - · omega - · have hzero : 0 - mem.size = 0 := by omega - rw [hzero] - native_decide - unfold twoWordHashMem wordAt32Mem - rw [write32_read_below _ _ 32 0 (by rw [toByteArray_size]) - (by rw [hword0Size]; omega) (by omega)] - unfold wordAt0Mem - rw [write32_read_back _ _ _ (by rw [toByteArray_size]) (by omega)] - apply ByteArray.ext - rw [ByteArray.data_extract] - exact Array.extract_eq_self_of_le (by - change (UInt256.toByteArray key).size ≤ 32 - rw [toByteArray_size]) -theorem twoWordHashMem_read32_of_size_ge {mem : ByteArray} (key slot : UInt256) - (hmem : 64 ≤ mem.size) : - (twoWordHashMem key slot mem).readWithPadding 32 32 = - UInt256.toByteArray slot := by - have hword0Size : (wordAt0Mem key mem).size = mem.size := by - unfold wordAt0Mem - change (writeWord mem 0 key).size = mem.size - rw [writeWord_size] - · omega - · have hzero : 0 - mem.size = 0 := by omega - rw [hzero] - native_decide - unfold twoWordHashMem wordAt32Mem - rw [write32_read_back _ _ _ (by rw [toByteArray_size]) - (by rw [hword0Size]; omega)] - apply ByteArray.ext - rw [ByteArray.data_extract] - exact Array.extract_eq_self_of_le (by - change (UInt256.toByteArray slot).size ≤ 32 - rw [toByteArray_size]) -theorem twoWordHashMem_size_of_size_ge {mem : ByteArray} (key slot : UInt256) - (hmem : 64 ≤ mem.size) : - (twoWordHashMem key slot mem).size = mem.size := by - have hword0Size : (wordAt0Mem key mem).size = mem.size := by - unfold wordAt0Mem - change (writeWord mem 0 key).size = mem.size - rw [writeWord_size] - · omega - · have hzero : 0 - mem.size = 0 := by omega - rw [hzero] - native_decide - unfold twoWordHashMem wordAt32Mem - change (writeWord (wordAt0Mem key mem) 32 slot).size = mem.size - rw [writeWord_size] - · rw [hword0Size] - omega - · rw [hword0Size] - have hzero : 32 - mem.size = 0 := by omega - rw [hzero] - native_decide -theorem twoWordHashMem_read0_64_of_size_ge {mem : ByteArray} (key slot : UInt256) - (hmem : 64 ≤ mem.size) : - (twoWordHashMem key slot mem).readWithPadding 0 64 = - UInt256.toByteArray key ++ UInt256.toByteArray slot := by - have hsize := twoWordHashMem_size_of_size_ge (mem := mem) key slot hmem - rw [readWithPadding_eq_extract' _ 0 64 (by norm_num) (by norm_num) - (by rw [hsize]; omega)] - have hleft : - (twoWordHashMem key slot mem).extract 0 32 = UInt256.toByteArray key := by - rw [← readWithPadding_eq_extract _ 0 (by rw [hsize]; omega), - twoWordHashMem_read0_of_size_ge key slot hmem] - have hright : - (twoWordHashMem key slot mem).extract 32 64 = UInt256.toByteArray slot := by - rw [← readWithPadding_eq_extract _ 32 (by rw [hsize]; omega), - twoWordHashMem_read32_of_size_ge key slot hmem] - rw [show (twoWordHashMem key slot mem).extract 0 64 = - (twoWordHashMem key slot mem).extract 0 32 ++ - (twoWordHashMem key slot mem).extract 32 64 by - rw [ByteArray.extract_append_extract] - norm_num] - rw [hleft, hright] -theorem twoWordHashMem_solcMappingSlot_of_size_ge - (baseSlot key : UInt256) {mem : ByteArray} (hmem : 64 ≤ mem.size) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((twoWordHashMem key baseSlot mem).readWithPadding 0 64))) = - solcMappingSlot baseSlot key := by - rw [twoWordHashMem_read0_64_of_size_ge key baseSlot hmem] - unfold solcMappingSlot - exact mappingSlot_single key baseSlot -abbrev burnPositionKeyOwnerPackedWord (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.lnot (⟨79228162514264337593543950335⟩ : UInt256)) - (UInt256.shiftLeft (UInt256.ofNat I.source.val) ⟨96⟩) -abbrev burnPositionKeyLowerPackedWord (I : ExecutionEnv) : UInt256 := - UInt256.shiftLeft - (UInt256.signextend ⟨2⟩ - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) ⟨232⟩ -abbrev burnPositionKeyUpperPackedWord (I : ExecutionEnv) : UInt256 := - UInt256.shiftLeft - (UInt256.signextend ⟨2⟩ - (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))) ⟨232⟩ -abbrev burnPositionKeyPackedLengthWord : UInt256 := - (⟨26⟩ : UInt256) + UInt256.sub (UInt256.ofNat 480) (UInt256.ofNat 480) -abbrev burnPositionKeyNewFreePtrWord : UInt256 := - UInt256.ofNat 480 + (⟨58⟩ : UInt256) -theorem burnPositionKeyPackedLengthWord_eq : - burnPositionKeyPackedLengthWord = (⟨26⟩ : UInt256) := by - native_decide -theorem burnPositionKeyNewFreePtrWord_eq : - burnPositionKeyNewFreePtrWord = UInt256.ofNat 538 := by - native_decide -noncomputable def burnPositionKeyMem0 (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnModifyPositionSlot0Mem σ I) 512 (burnPositionKeyOwnerPackedWord I) -noncomputable def burnPositionKeyMem1 (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnPositionKeyMem0 σ I) 532 (burnPositionKeyLowerPackedWord I) -noncomputable def burnPositionKeyMem2 (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnPositionKeyMem1 σ I) 535 (burnPositionKeyUpperPackedWord I) -noncomputable def burnPositionKeyMem3 (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnPositionKeyMem2 σ I) 480 burnPositionKeyPackedLengthWord -noncomputable def burnPositionKeyPackedHashMem (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnPositionKeyMem3 σ I) 64 burnPositionKeyNewFreePtrWord -noncomputable abbrev burnPositionKeyHashWord (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((burnPositionKeyPackedHashMem σ I).readWithPadding 512 26))) -noncomputable abbrev burnPositionBaseSlotWord (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - solcMappingSlot ⟨7⟩ (burnPositionKeyHashWord σ I) -noncomputable abbrev burnPositionKeyMappingMem (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - twoWordHashMem (burnPositionKeyHashWord σ I) ⟨7⟩ - (burnPositionKeyPackedHashMem σ I) -private def burnPositionKeyPackedWrites (I : ExecutionEnv) : List (Nat × UInt256) := - [(512, burnPositionKeyOwnerPackedWord I), - (532, burnPositionKeyLowerPackedWord I), - (535, burnPositionKeyUpperPackedWord I)] -private theorem burnPositionKeyMem2_cascade (σ : AccountMap) (I : ExecutionEnv) : - burnPositionKeyMem2 σ I = - writeCascade (burnModifyPositionSlot0Mem σ I) - (burnPositionKeyPackedWrites I) := by - rfl - -theorem burnPositionKeyMem2_size (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMem2 σ I).size = 567 := by - rw [burnPositionKeyMem2_cascade] - exact writeCascade_size_of_base (burnModifyPositionSlot0Mem σ I) - (burnPositionKeyPackedWrites I) (burnModifyPositionSlot0Mem_size σ I) - (by - simp [burnPositionKeyPackedWrites, WriteGapsOk] - native_decide) - (by simp [burnPositionKeyPackedWrites, writeCascadeSize]) - -theorem burnPositionKeyMem2_read64 (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMem2 σ I).readWithPadding 64 32 = - UInt256.toByteArray (UInt256.ofNat 480) := by - rw [burnPositionKeyMem2_cascade] - rw [writeCascade_read_preserved_of_base (burnModifyPositionSlot0Mem σ I) - (burnPositionKeyPackedWrites I) (base := 480) (read := 64) - (burnModifyPositionSlot0Mem_size σ I) - (by - simp [burnPositionKeyPackedWrites, WindowDisjointFromWrites] - native_decide)] - exact burnModifyPositionSlot0Mem_read64 σ I - -theorem burnPositionKeyMem2_mload64 (σ : AccountMap) (I : ExecutionEnv) : - (if (⟨64⟩ : UInt256).toNat ≥ (burnPositionKeyMem2 σ I).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 18 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPositionKeyMem2 σ I).readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - UInt256.ofNat 480 := by - exact mloadWordValue_of_readWithPadding - (mem := burnPositionKeyMem2 σ I) (aw := UInt256.ofNat 18) - (off := ⟨64⟩) (v := UInt256.ofNat 480) - (by rw [burnPositionKeyMem2_size σ I]; native_decide) - (by native_decide) - (by - simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using burnPositionKeyMem2_read64 σ I) - -theorem burnPositionKeyMem3_size (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMem3 σ I).size = 567 := by - unfold burnPositionKeyMem3 - rw [writeWord_size] - · rw [burnPositionKeyMem2_size σ I] - omega - · rw [burnPositionKeyMem2_size σ I] - native_decide - -theorem burnPositionKeyPackedHashMem_size (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyPackedHashMem σ I).size = 567 := by - unfold burnPositionKeyPackedHashMem - rw [writeWord_size] - · rw [burnPositionKeyMem3_size σ I] - omega - · rw [burnPositionKeyMem3_size σ I] - native_decide - -theorem burnPositionKeyMem3_read480 (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMem3 σ I).readWithPadding 480 32 = - UInt256.toByteArray burnPositionKeyPackedLengthWord := by - unfold burnPositionKeyMem3 - exact writeWord_read_back (burnPositionKeyMem2 σ I) 480 - burnPositionKeyPackedLengthWord - (by rw [burnPositionKeyMem2_size σ I]; native_decide) - -theorem burnPositionKeyPackedHashMem_read480 (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyPackedHashMem σ I).readWithPadding 480 32 = - UInt256.toByteArray burnPositionKeyPackedLengthWord := by - unfold burnPositionKeyPackedHashMem - rw [writeWord_read_preserved (burnPositionKeyMem3 σ I) 64 480 - burnPositionKeyNewFreePtrWord - (by rw [burnPositionKeyMem3_size σ I]; native_decide) - (by rw [burnPositionKeyMem3_size σ I]; omega)] - exact burnPositionKeyMem3_read480 σ I - -theorem burnPositionKeyPackedHashMem_mload480 (σ : AccountMap) (I : ExecutionEnv) : - (if (⟨480⟩ : UInt256).toNat ≥ (burnPositionKeyPackedHashMem σ I).size - ∨ (⟨480⟩ : UInt256) ≥ UInt256.ofNat 18 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPositionKeyPackedHashMem σ I).readWithPadding - (⟨480⟩ : UInt256).toNat 32))) = - burnPositionKeyPackedLengthWord := by - exact mloadWordValue_of_readWithPadding - (mem := burnPositionKeyPackedHashMem σ I) (aw := UInt256.ofNat 18) - (off := ⟨480⟩) (v := burnPositionKeyPackedLengthWord) - (by rw [burnPositionKeyPackedHashMem_size σ I]; native_decide) - (by native_decide) - (by - simpa [show (⟨480⟩ : UInt256).toNat = 480 from by decide] - using burnPositionKeyPackedHashMem_read480 σ I) - -private theorem uniswapV3PoolBurnAfterCheckTicksPatchDisjoint33 {v : PoolImmutables} - {pc : UInt256} - (hlo : 16264 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19295) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -private theorem uniswapV3PoolBurnAfterCheckTicksDecodeEqTemplate {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 16264 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 19295 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolBurnAfterCheckTicksPatchDisjoint33 (v := v) (pc := pc) hlo hhi) - -private theorem uniswapV3PoolPatchPreservesJumpDest19151 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨19151⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched19151 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨19151⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest19151 - -private theorem uniswapV3PoolPatchPreservesJumpDest16867 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16867⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched16867 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16867⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest16867 - -private theorem uniswapV3PoolPatchPreservesJumpDest19166 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨19166⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched19166 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨19166⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest19166 - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnAfterCheckTicksSlot0Frame {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨16264⟩ - (⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnModifyPositionMem4 ee) (UInt256.ofNat 8) rdata (cA, σ) k C) - (hov : R.length + 35 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨16397⟩ - (⟨32⟩ :: slot0TickReturnWord σ ee :: ⟨96⟩ :: ⟨256⟩ :: ⟨64⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnModifyPositionSlot0Mem σ ee) (UInt256.ofNat 15) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 16264 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnAfterCheckTicksDecodeEqTemplate hpatch - hlo hhi - have hmask160 : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask := by - native_decide - have hmask16 : (⟨65535⟩ : UInt256) = slot0Uint16Mask := by - native_decide - have hmask8 : (⟨255⟩ : UInt256) = slot0Uint8Mask := by - native_decide - have hshift160 : - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩ = slot0ShiftBytes 20 := by - native_decide - have hshift184 : - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨184⟩ = slot0ShiftBytes 23 := by - native_decide - have hshift200 : - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨200⟩ = slot0ShiftBytes 25 := by - native_decide - have hshift216 : - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨216⟩ = slot0ShiftBytes 27 := by - native_decide - have hshift232 : - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩ = slot0ShiftBytes 29 := by - native_decide - have hshift240 : - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨240⟩ = slot0ShiftBytes 30 := by - native_decide - have rd16268 := evm_run h with [ - raw jumpdest (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨64⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov)] - have rd16269 := by - simpa [burnModifyPositionFreePtrLoad] using - rd16268.mload 0 (UInt256.ofNat 256) (UInt256.ofNat 8) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost - (by simpa [burnModifyPositionFreePtrLoad] using burnModifyPositionFreePtrLoad_eq ee) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16275 := evm_run rd16269 with [ - raw push1 ⟨224⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw mstore 0 (burnModifyPositionSlot0Mem0 ee) (UInt256.ofNat 8) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost rfl - (by native_decide) (by evm_ov)] - have rd16277 := evm_run rd16275 with [ - raw push1 ⟨0⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov)] - obtain ⟨k16278, C16278, rd16278Raw⟩ := rd16277.sload - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16278 := by - simpa [slot0SlotWord, solcSlotWord] using rd16278Raw - have rd16301 := evm_run rd16278 with [ - raw push1 ⟨1⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨160⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw shl (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw sub (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw and (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw mstore 3 (burnModifyPositionSlot0Mem1 σ ee) (UInt256.ofNat 9) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost - (by - rw [hmask160] - rfl) - (by native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨160⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw shl (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw div (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨2⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov)] - have rd16302 := RD.signextend rd16301 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16303 := evm_run rd16302 with [ - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov)] - have rd16304 := RD.signextend rd16303 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16305 := evm_run rd16304 with [ - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov)] - have rd16306 := RD.signextend rd16305 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16314 := evm_run rd16306 with [ - raw push1 ⟨32⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw mstore 3 (burnModifyPositionSlot0Mem2 σ ee) (UInt256.ofNat 10) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost - (by - unfold burnModifyPositionSlot0Mem2 slot0TickReturnWord slot0SlotWord solcSlotWord - rw [hshift160, slot0SignextendTwo_idempotent, slot0SignextendTwo_idempotent] - simp only [show (UInt256.ofNat 256 + (⟨32⟩ : UInt256)).toNat = 288 from by decide] - rfl) - (by native_decide) (by evm_ov)] - have rd16330 := evm_run rd16314 with [ - raw push2 ⟨65535⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨184⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw shl (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw div (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw and (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup6 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup8 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw mstore 3 (burnModifyPositionSlot0Mem3 σ ee) (UInt256.ofNat 11) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost - (by - unfold burnModifyPositionSlot0Mem3 slot0ObservationIndexWord slot0SlotWord solcSlotWord - rw [hmask16, hshift184, u256_land_comm slot0Uint16Mask] - simp only [show ((⟨64⟩ : UInt256) + UInt256.ofNat 256).toNat = 320 from by decide] - rfl) - (by native_decide) (by evm_ov)] - have rd16348 := evm_run rd16330 with [ - raw push1 ⟨1⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨200⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw shl (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw div (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw and (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨96⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup8 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw mstore 3 (burnModifyPositionSlot0Mem4 σ ee) (UInt256.ofNat 12) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost - (by - unfold burnModifyPositionSlot0Mem4 slot0ObservationCardinalityWord slot0SlotWord solcSlotWord - rw [hmask16, hshift200, u256_land_comm slot0Uint16Mask] - simp only [show (UInt256.ofNat 256 + (⟨96⟩ : UInt256)).toNat = 352 from by decide] - rfl) - (by native_decide) (by evm_ov)] - have rd16363 := evm_run rd16348 with [ - raw push1 ⟨1⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨216⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw shl (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup6 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw div (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw and (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨128⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup7 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw mstore 3 (burnModifyPositionSlot0Mem5 σ ee) (UInt256.ofNat 13) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost - (by - unfold burnModifyPositionSlot0Mem5 slot0ObservationCardinalityNextWord slot0SlotWord - solcSlotWord - rw [hmask16, hshift216, u256_land_comm slot0Uint16Mask] - simp only [show (UInt256.ofNat 256 + (⟨128⟩ : UInt256)).toNat = 384 from by decide] - rfl) - (by native_decide) (by evm_ov)] - have rd16379 := evm_run rd16363 with [ - raw push1 ⟨255⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨232⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw shl (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup6 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw div (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw and (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨160⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup8 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw mstore 3 (burnModifyPositionSlot0Mem6 σ ee) (UInt256.ofNat 14) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost - (by - unfold burnModifyPositionSlot0Mem6 slot0FeeProtocolWord slot0SlotWord solcSlotWord - rw [hmask8, hshift232, u256_land_comm slot0Uint8Mask] - simp only [show (UInt256.ofNat 256 + (⟨160⟩ : UInt256)).toNat = 416 from by decide] - rfl) - (by native_decide) (by evm_ov)] - have rd16397 := evm_run rd16379 with [ - raw push1 ⟨1⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨240⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw shl (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw swap5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw div (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw swap4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw and (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw iszero (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw iszero (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw push1 ⟨192⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw dup6 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw mstore 3 (burnModifyPositionSlot0Mem σ ee) (UInt256.ofNat 15) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost - (by - unfold burnModifyPositionSlot0Mem slot0UnlockedRawWord slot0BoolReturnWord slot0SlotWord - solcSlotWord - rw [hmask8, hshift240, u256_land_comm slot0Uint8Mask] - simp only [show (UInt256.ofNat 256 + (⟨192⟩ : UInt256)).toNat = 448 from by decide] - rfl) - (by native_decide) (by evm_ov)] - exact ⟨_, _, by - simpa [slot0TickReturnWord, slot0SlotWord, solcSlotWord, hshift160, - slot0SignextendTwo_idempotent] using rd16397⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnAfterCheckTicksEnterPositionKey {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨16397⟩ - (⟨32⟩ :: slot0TickReturnWord σ ee :: ⟨96⟩ :: ⟨256⟩ :: ⟨64⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnModifyPositionSlot0Mem σ ee) (UInt256.ofNat 15) rdata (cA, σ) k C) - (hov : R.length + 35 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨19151⟩ - (slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnModifyPositionSlot0Mem σ ee) (UInt256.ofNat 15) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 16264 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnAfterCheckTicksDecodeEqTemplate hpatch - hlo hhi - have rd16398 := evm_run h with [ - raw dup9 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd16399 := by - simpa using - rd16398.mload 0 (UInt256.ofNat ee.source.val) (UInt256.ofNat 15) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost (burnModifyPositionSlot0Mem_mload128 σ ee) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16402 := evm_run rd16399 with [ - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup10 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd16403 := by - simpa [show ((⟨128⟩ : UInt256) + ⟨32⟩) = (⟨160⟩ : UInt256) from by decide, - show ((⟨32⟩ : UInt256) + ⟨128⟩) = (⟨160⟩ : UInt256) from by decide] using - rd16402.mload 0 (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (UInt256.ofNat 15) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost (burnModifyPositionSlot0Mem_mload160 σ ee) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16406 := evm_run rd16403 with [ - raw swap5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup10 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd16407 := by - simpa [show ((⟨128⟩ : UInt256) + ⟨64⟩) = (⟨192⟩ : UInt256) from by decide, - show ((⟨64⟩ : UInt256) + ⟨128⟩) = (⟨192⟩ : UInt256) from by decide] using - rd16406.mload 0 (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (UInt256.ofNat 15) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost (burnModifyPositionSlot0Mem_mload192 σ ee) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16410 := evm_run rd16407 with [ - raw swap3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup10 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd16411 := by - simpa [show ((⟨128⟩ : UInt256) + ⟨96⟩) = (⟨224⟩ : UInt256) from by decide, - show ((⟨96⟩ : UInt256) + ⟨128⟩) = (⟨224⟩ : UInt256) from by decide] using - rd16410.mload 0 - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee))) - (UInt256.ofNat 15) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost (burnModifyPositionSlot0Mem_mload224 σ ee) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16427 := evm_run rd16411 with [ - raw swap4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push2 ⟨16428⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push2 ⟨19151⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - exact ⟨_, _, by - simpa using rd16427.jump - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched19151 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnAfterCheckTicksCallPositionKeyRoutine {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨19151⟩ - (slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnModifyPositionSlot0Mem σ ee) (UInt256.ofNat 15) rdata (cA, σ) k C) - (hov : R.length + 40 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨16867⟩ - (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨7⟩ :: ⟨19166⟩ :: ⟨0⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnModifyPositionSlot0Mem σ ee) (UInt256.ofNat 15) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 16264 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnAfterCheckTicksDecodeEqTemplate hpatch - hlo hhi - have rd19165 := evm_run h with [ - raw jumpdest (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨0⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push2 ⟨19166⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨7⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup8 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup8 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup8 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push2 ⟨16867⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - exact ⟨_, _, by - simpa using rd19165.jump - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched16867 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnAfterCheckTicksPositionKeyRoutine {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨16867⟩ - (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨7⟩ :: ⟨19166⟩ :: ⟨0⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnModifyPositionSlot0Mem σ ee) (UInt256.ofNat 15) rdata (cA, σ) k C) - (hov : R.length + 55 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨19166⟩ - (burnPositionBaseSlotWord σ ee :: ⟨0⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 16264 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnAfterCheckTicksDecodeEqTemplate hpatch - hlo hhi - have hd16878 : - decode code ⟨16878⟩ = - some (.Push .PUSH12, some (⟨79228162514264337593543950335⟩, 12)) := by - rw [hdec _ (by native_decide) (by native_decide)] - native_decide - have hpackedStart : - (⟨32⟩ : UInt256) + UInt256.ofNat 480 = ⟨512⟩ := by - native_decide - have hpackedStartRev : - UInt256.ofNat 480 + (⟨32⟩ : UInt256) = ⟨512⟩ := by - native_decide - have hnewFree : - UInt256.ofNat 480 + (⟨58⟩ : UInt256) = burnPositionKeyNewFreePtrWord := rfl - have hslot : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((burnPositionKeyMappingMem σ ee).readWithPadding 0 64))) = - burnPositionBaseSlotWord σ ee := by - exact twoWordHashMem_solcMappingSlot_of_size_ge ⟨7⟩ - (burnPositionKeyHashWord σ ee) - (by rw [burnPositionKeyPackedHashMem_size σ ee]; omega) - have rd16871 := evm_run h with [ - raw jumpdest (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨64⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd16872 := by - simpa using - rd16871.mload 0 (UInt256.ofNat 480) (UInt256.ofNat 15) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost (burnModifyPositionSlot0Mem_mload64 σ ee) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16878pre := evm_run rd16872 with [ - raw push1 ⟨96⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw shl (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd16891 := by - simpa using - rd16878pre.pushConst (⟨79228162514264337593543950335⟩ : UInt256) - (by native_decide : Operation.POp.PUSH12 ≠ .PUSH0) hd16878 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16901 := evm_run rd16891 with [ - raw not (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw and (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨32⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup7 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mstore 6 (burnPositionKeyMem0 σ ee) (UInt256.ofNat 17) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost - (by - unfold burnPositionKeyMem0 burnPositionKeyOwnerPackedWord - rw [hpackedStartRev] - rfl) - (by native_decide) (by evm_ov)] - have rd16906pre := evm_run rd16901 with [ - raw push1 ⟨2⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd16907pre := RD.signextend rd16906pre - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16916 := evm_run rd16907pre with [ - raw push1 ⟨232⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw shl (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨52⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup8 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mstore 3 (burnPositionKeyMem1 σ ee) (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost - (by - unfold burnPositionKeyMem1 burnPositionKeyLowerPackedWord - rfl) - (by native_decide) (by evm_ov)] - have rd16920pre := evm_run rd16916 with [ - raw swap3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd16921pre := RD.signextend rd16920pre - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16928 := evm_run rd16921pre with [ - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw shl (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨55⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mstore 0 (burnPositionKeyMem2 σ ee) (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost - (by - unfold burnPositionKeyMem2 burnPositionKeyUpperPackedWord - rfl) - (by native_decide) (by evm_ov)] - have rd16930pre := evm_run rd16928 with [ - raw dup1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd16930 := by - simpa using - rd16930pre.mload 0 (UInt256.ofNat 480) (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost (burnPositionKeyMem2_mload64 σ ee) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16938 := evm_run rd16930 with [ - raw dup1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨26⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mstore 0 (burnPositionKeyMem3 σ ee) (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost - (by - unfold burnPositionKeyMem3 burnPositionKeyPackedLengthWord - rfl) - (by native_decide) (by evm_ov)] - have rd16945 := evm_run rd16938 with [ - raw push1 ⟨58⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mstore 0 (burnPositionKeyPackedHashMem σ ee) (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost - (by - unfold burnPositionKeyPackedHashMem - rw [hnewFree] - rfl) - (by native_decide) (by evm_ov)] - have rd16947pre := evm_run rd16945 with [ - raw dup3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd16947 := by - simpa [burnPositionKeyPackedLengthWord_eq] using - rd16947pre.mload 0 burnPositionKeyPackedLengthWord (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost (burnPositionKeyPackedHashMem_mload480 σ ee) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16953 := evm_run rd16947 with [ - raw swap3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd16954 := by - simpa [hpackedStart, burnPositionKeyHashWord] using - rd16953.keccak256 0 (burnPositionKeyHashWord σ ee) - (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost rfl (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16959 := evm_run rd16954 with [ - raw push1 ⟨0⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mstore 0 - (wordAt0Mem (burnPositionKeyHashWord σ ee) (burnPositionKeyPackedHashMem σ ee)) - (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost rfl - (by native_decide) (by evm_ov)] - have rd16964pre := evm_run rd16959 with [ - raw swap3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mstore 0 (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) mem_cost - (by - unfold burnPositionKeyMappingMem twoWordHashMem - rfl) - (by native_decide) (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd16965 := by - simpa [burnPositionBaseSlotWord] using - rd16964pre.keccak256 0 (burnPositionBaseSlotWord σ ee) - (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost hslot (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16966 := evm_run rd16965 with [ - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - exact ⟨_, _, by - simpa using rd16966.jump - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched19166 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnAfterCheckTicksFeeGlobalsBranchTest {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨19166⟩ - (burnPositionBaseSlotWord σ ee :: ⟨0⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 55 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨19189⟩ - (⟨19492⟩ :: - UInt256.isZero - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)))) :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 16264 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnAfterCheckTicksDecodeEqTemplate hpatch - hlo hhi - have rd19167 := evm_run h with [ - raw jumpdest (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd19169 := evm_run rd19167 with [ - raw push1 ⟨1⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - obtain ⟨_, _, rd19170⟩ := rd19169.sload - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd19172 := evm_run rd19170 with [ - raw push1 ⟨2⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - obtain ⟨_, _, rd19173⟩ := rd19172.sload - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd19184pre := evm_run rd19173 with [ - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨0⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨15⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup8 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd19185 := RD.signextend rd19184pre - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd19189 := evm_run rd19185 with [ - raw iszero (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push2 ⟨19492⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - exact ⟨_, _, by simpa [solcSlotWord] using rd19189⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnAfterFeeGlobals.lean b/Benchmarks/UniswapV3Pool/BurnAfterFeeGlobals.lean deleted file mode 100644 index 8681b975..00000000 --- a/Benchmarks/UniswapV3Pool/BurnAfterFeeGlobals.lean +++ /dev/null @@ -1,1946 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnAfterCheckTicks - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def burnModifyPositionLiquidityDeltaUpdateStep (v : PoolImmutables) : List Stmt := - [ Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ .letDecl "time" (some uint32) blockTimestamp32, - .internalCall "observeSingle" - [ .var "time", .intLit 0, .storage (slot0F "tick"), - .storage (slot0F "observationIndex"), .storage liquidityRef, - .storage (slot0F "observationCardinality") ] - "observedForUpdate", - .internalCall "tickUpdate" - [ .var "tickLower", .var "_slot0tick", .var "liquidityDelta", - .var "_feeGrowthGlobal0X128", .var "_feeGrowthGlobal1X128", - tuple1 (.var "observedForUpdate"), tuple0 (.var "observedForUpdate"), - .var "time", .boolLit false, .intLit v.maxLiquidityPerTick ] - "flippedLowerCall", - .assign .localVar (varRef "flippedLower") (.var "flippedLowerCall"), - .internalCall "tickUpdate" - [ .var "tickUpper", .var "_slot0tick", .var "liquidityDelta", - .var "_feeGrowthGlobal0X128", .var "_feeGrowthGlobal1X128", - tuple1 (.var "observedForUpdate"), tuple0 (.var "observedForUpdate"), - .var "time", .boolLit true, .intLit v.maxLiquidityPerTick ] - "flippedUpperCall", - .assign .localVar (varRef "flippedUpper") (.var "flippedUpperCall"), - Stmt.ite (.var "flippedLower") - [ .internalCall "tickBitmapFlip" [.var "tickLower", .intLit v.tickSpacing] - "_flipLower" ] - [], - Stmt.ite (.var "flippedUpper") - [ .internalCall "tickBitmapFlip" [.var "tickUpper", .intLit v.tickSpacing] - "_flipUpper" ] - [] ] - [] ] - -theorem burnModifyPositionStore_liquidityDelta (I : ExecutionEnv) : - (burnModifyPositionStore I).get? "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnModifyPositionStore] - rw [store_get_ne3 ((∅ : Store).insert "liquidityDelta" (burnLiquidityDeltaValue I)) - (k1 := "tickUpper") (k2 := "tickLower") (k3 := "owner") - (a := "liquidityDelta") (burnTickUpperValue I) (burnTickLowerValue I) - (.address I.source) (by native_decide) (by native_decide) (by native_decide)] - exact store_get_self (∅ : Store) "liquidityDelta" (burnLiquidityDeltaValue I) - -theorem burnAfterSlot0Frame_liquidityDelta {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterSlot0Frame v σ I).locals.get? "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnModifyPositionAfterSlot0Frame] - rw [store_get_ne5 (burnModifyPositionStore I) - (k1 := "_slot0sqrtPriceX96") (k2 := "_slot0tick") - (k3 := "_slot0observationIndex") (k4 := "_slot0observationCardinality") - (k5 := "_slot0observationCardinalityNext") (a := "liquidityDelta") - (burnSlot0SqrtPriceX96Value σ I) (burnSlot0TickValue σ I) - (burnSlot0ObservationIndexValue σ I) (burnSlot0ObservationCardinalityValue σ I) - (burnSlot0ObservationCardinalityNextValue σ I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide)] - exact burnModifyPositionStore_liquidityDelta I - -theorem burnAfterPositionKeyFrame_liquidityDelta {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterPositionKeyFrame v σ I).locals.get? "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnModifyPositionAfterPositionKeyFrame] - rw [store_get_ne (burnModifyPositionAfterSlot0Frame v σ I).locals - (k := "_positionKey") (a := "liquidityDelta") (burnPositionKeyValue I) - (by native_decide)] - exact burnAfterSlot0Frame_liquidityDelta σ I - -theorem burnAfterFeeGrowthGlobalsFrame_liquidityDelta {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals.get? "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnModifyPositionAfterFeeGrowthGlobalsFrame] - rw [store_get_ne4 (burnModifyPositionAfterPositionKeyFrame v σ I).locals - (k1 := "_feeGrowthGlobal0X128") (k2 := "_feeGrowthGlobal1X128") - (k3 := "flippedLower") (k4 := "flippedUpper") (a := "liquidityDelta") - (burnFeeGrowthGlobal0Value σ I) (burnFeeGrowthGlobal1Value σ I) - (.bool false) (.bool false) - (by native_decide) (by native_decide) (by native_decide) (by native_decide)] - exact burnAfterPositionKeyFrame_liquidityDelta σ I - -theorem burnEvalLiquidityDeltaNeZeroFalse {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hzero : burnAmountCleanWord I = ⟨0⟩) : - evalExpr? (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (neE (.var "liquidityDelta") (.intLit 0)) = .ok (.bool false) := by - simp only [neE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnAfterFeeGrowthGlobalsFrame_liquidityDelta (v := v) σ I] - simp [EvalResult.ofOption, evalBinaryOp?, burnLiquidityDeltaValue, hzero] - -theorem burnEvalLiquidityDeltaNeZeroTrue {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) : - evalExpr? (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (neE (.var "liquidityDelta") (.intLit 0)) = .ok (.bool true) := by - simp only [neE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnAfterFeeGrowthGlobalsFrame_liquidityDelta (v := v) σ I] - simp [EvalResult.ofOption, evalBinaryOp?, burnLiquidityDeltaValue] - have hnat : (burnAmountCleanWord I).toNat ≠ 0 := by - intro h - exact hnonzero (uint256_toNat_eq_zero h) - omega - -theorem uniswapV3PoolModifyPositionSourceLiquidityDeltaZeroSkip {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hzero : burnAmountCleanWord I = ⟨0⟩) : - ExecBlock (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (burnModifyPositionLiquidityDeltaUpdateStep v) - (ExecResult.ok (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - refine ExecBlock.consNormal (ExecStmt.iteFalse ?_ ?_) ExecBlock.nil - · exact burnEvalLiquidityDeltaNeZeroFalse (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hzero - · exact ExecBlock.nil - -theorem uniswapV3PoolModifyPositionSourceThroughLiquidityDeltaZeroSkip - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hzero : burnAmountCleanWord I = ⟨0⟩) : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - (noDelegateCall v ++ checkTicksBody (.var "tickLower") (.var "tickUpper") ++ - burnModifyPositionSlot0Prefix ++ burnModifyPositionPositionKeyStep ++ - burnModifyPositionFeeGrowthGlobalsStep ++ - burnModifyPositionLiquidityDeltaUpdateStep v) - (ExecResult.ok (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := uniswapV3PoolModifyPositionSourceThroughFeeGrowthGlobals (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard htickLt hge hle - exact execBlock_append hprefix - (uniswapV3PoolModifyPositionSourceLiquidityDeltaZeroSkip (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hzero) - -abbrev burnTickLowerFeeGrowthCompareWord (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨2⟩ - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - -abbrev burnTickUpperFeeGrowthCompareWord (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨2⟩ - (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - -abbrev burnTickLowerFeeGrowthKey (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨2⟩ (burnTickLowerFeeGrowthCompareWord I) - -abbrev burnTickUpperFeeGrowthKey (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨2⟩ (burnTickUpperFeeGrowthCompareWord I) - -abbrev burnTickLowerFeeGrowthBaseSlot (I : ExecutionEnv) : UInt256 := - solcMappingSlot ⟨5⟩ (burnTickLowerFeeGrowthKey I) - -abbrev burnTickUpperFeeGrowthBaseSlot (I : ExecutionEnv) : UInt256 := - solcMappingSlot ⟨5⟩ (burnTickUpperFeeGrowthKey I) - -abbrev burnTickLowerFeeGrowthOutside0Slot (I : ExecutionEnv) : UInt256 := - (⟨1⟩ : UInt256) + burnTickLowerFeeGrowthBaseSlot I - -abbrev burnTickLowerFeeGrowthOutside1Slot (I : ExecutionEnv) : UInt256 := - (⟨2⟩ : UInt256) + burnTickLowerFeeGrowthBaseSlot I - -abbrev burnTickLowerFeeGrowthOutside0Word (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - solcSlotWord σ I (burnTickLowerFeeGrowthOutside0Slot I) - -abbrev burnTickLowerFeeGrowthOutside1Word (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - solcSlotWord σ I (burnTickLowerFeeGrowthOutside1Slot I) - -abbrev burnTickUpperFeeGrowthOutside0Slot (I : ExecutionEnv) : UInt256 := - (⟨1⟩ : UInt256) + burnTickUpperFeeGrowthBaseSlot I - -abbrev burnTickUpperFeeGrowthOutside1Slot (I : ExecutionEnv) : UInt256 := - (⟨2⟩ : UInt256) + burnTickUpperFeeGrowthBaseSlot I - -abbrev burnTickUpperFeeGrowthOutside0Word (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - solcSlotWord σ I (burnTickUpperFeeGrowthOutside0Slot I) - -abbrev burnTickUpperFeeGrowthOutside1Word (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - solcSlotWord σ I (burnTickUpperFeeGrowthOutside1Slot I) - -noncomputable abbrev burnTickLowerFeeGrowthMem (σ : AccountMap) - (I : ExecutionEnv) : ByteArray := - twoWordHashMem (burnTickLowerFeeGrowthKey I) ⟨5⟩ - (burnPositionKeyMappingMem σ I) - -noncomputable abbrev burnTickUpperFeeGrowthMem (σ : AccountMap) - (I : ExecutionEnv) : ByteArray := - wordAt0Mem (burnTickUpperFeeGrowthKey I) (burnTickLowerFeeGrowthMem σ I) - -theorem wordAt0Mem_size_of_size_ge {mem : ByteArray} (word : UInt256) - (hmem : 32 ≤ mem.size) : - (wordAt0Mem word mem).size = mem.size := by - unfold wordAt0Mem - rw [write32_eq _ _ _ (by rw [toByteArray_size]) (by omega), - ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, toByteArray_size] - omega - -theorem wordAt0Mem_twoWordHashMem_read0_64_of_size_ge - {mem : ByteArray} (key newKey slot : UInt256) (hmem : 64 ≤ mem.size) : - (wordAt0Mem newKey (twoWordHashMem key slot mem)).readWithPadding 0 64 = - UInt256.toByteArray newKey ++ UInt256.toByteArray slot := by - have hbaseSize : - (twoWordHashMem key slot mem).size = mem.size := - twoWordHashMem_size_of_size_ge key slot hmem - have hsize : - (wordAt0Mem newKey (twoWordHashMem key slot mem)).size = mem.size := by - rw [wordAt0Mem_size_of_size_ge] - · exact hbaseSize - · rw [hbaseSize] - omega - rw [readWithPadding_eq_extract' _ 0 64 (by norm_num) (by norm_num) - (by rw [hsize]; omega)] - have hleft : - (wordAt0Mem newKey (twoWordHashMem key slot mem)).extract 0 32 = - UInt256.toByteArray newKey := by - rw [← readWithPadding_eq_extract _ 0 (by rw [hsize]; omega), - wordAt0Mem_read0] - have hright : - (wordAt0Mem newKey (twoWordHashMem key slot mem)).extract 32 64 = - UInt256.toByteArray slot := by - rw [← readWithPadding_eq_extract _ 32 (by rw [hsize]; omega)] - unfold wordAt0Mem - rw [write32_read_above _ _ 0 32 (by rw [toByteArray_size]) - (by omega) (by omega) (by rw [hbaseSize]; omega)] - exact twoWordHashMem_read32_of_size_ge key slot hmem - rw [show (wordAt0Mem newKey (twoWordHashMem key slot mem)).extract 0 64 = - (wordAt0Mem newKey (twoWordHashMem key slot mem)).extract 0 32 ++ - (wordAt0Mem newKey (twoWordHashMem key slot mem)).extract 32 64 by - rw [ByteArray.extract_append_extract] - norm_num] - rw [hleft, hright] - -theorem wordAt0Mem_twoWordHashMem_solcMappingSlot_of_size_ge - (baseSlot key newKey : UInt256) {mem : ByteArray} (hmem : 64 ≤ mem.size) : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((wordAt0Mem newKey (twoWordHashMem key baseSlot mem)).readWithPadding - 0 64))) = - solcMappingSlot baseSlot newKey := by - rw [wordAt0Mem_twoWordHashMem_read0_64_of_size_ge key newKey baseSlot hmem] - unfold solcMappingSlot - exact mappingSlot_single newKey baseSlot - -theorem burnPositionKeyMappingMem_size (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMappingMem σ I).size = 567 := by - unfold burnPositionKeyMappingMem - rw [twoWordHashMem_size_of_size_ge] - · exact burnPositionKeyPackedHashMem_size σ I - · rw [burnPositionKeyPackedHashMem_size σ I] - omega - -theorem burnTickLowerFeeGrowthMem_size (σ : AccountMap) (I : ExecutionEnv) : - (burnTickLowerFeeGrowthMem σ I).size = 567 := by - unfold burnTickLowerFeeGrowthMem - rw [twoWordHashMem_size_of_size_ge] - · exact burnPositionKeyMappingMem_size σ I - · rw [burnPositionKeyMappingMem_size σ I] - omega - -theorem burnTickUpperFeeGrowthMem_size (σ : AccountMap) (I : ExecutionEnv) : - (burnTickUpperFeeGrowthMem σ I).size = 567 := by - unfold burnTickUpperFeeGrowthMem - rw [wordAt0Mem_size_of_size_ge] - · exact burnTickLowerFeeGrowthMem_size σ I - · rw [burnTickLowerFeeGrowthMem_size σ I] - omega - -theorem burnFeeGrowthInsideLowerSlt_eq (σ : AccountMap) (I : ExecutionEnv) : - UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ I)) - (burnTickLowerFeeGrowthCompareWord I) = - if tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickLowerWord I) then ⟨1⟩ else ⟨0⟩ := by - simp only [slot0TickReturnWord, burnTickLowerFeeGrowthCompareWord, - burnTickLowerCleanWord] - rw [signextend_two_tickSpacing_idempotent - (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 20))] - rw [signextend_two_tickSpacing_idempotent - (UInt256.signextend ⟨2⟩ (burnTickLowerWord I))] - rw [signextend_two_tickSpacing_idempotent (burnTickLowerWord I)] - rw [← slot0TickRawValue_wordOfInt - (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 20))] - rw [← wordOfInt_sint24Value_eq_signextend_two (burnTickLowerWord I)] - exact slt_wordOfInt_int24 _ _ (tickSpacingSint24Value_ge _) - (tickSpacingSint24Value_lt _) (tickSpacingSint24Value_ge _) - (tickSpacingSint24Value_lt _) - -theorem burnFeeGrowthInsideLowerSlt_ne_zero (σ : AccountMap) (I : ExecutionEnv) - (hlt : - tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickLowerWord I)) : - UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ I)) - (burnTickLowerFeeGrowthCompareWord I) ≠ ⟨0⟩ := by - rw [burnFeeGrowthInsideLowerSlt_eq σ I, if_pos hlt] - native_decide - -theorem burnFeeGrowthInsideLowerSlt_eq_zero (σ : AccountMap) (I : ExecutionEnv) - (hge : - ¬ tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickLowerWord I)) : - UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ I)) - (burnTickLowerFeeGrowthCompareWord I) = ⟨0⟩ := by - rw [burnFeeGrowthInsideLowerSlt_eq σ I, if_neg hge] - -theorem burnFeeGrowthInsideUpperSlt_eq (σ : AccountMap) (I : ExecutionEnv) : - UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ I)) - (burnTickUpperFeeGrowthCompareWord I) = - if tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickUpperWord I) then ⟨1⟩ else ⟨0⟩ := by - simp only [slot0TickReturnWord, burnTickUpperFeeGrowthCompareWord, - burnTickUpperCleanWord] - rw [signextend_two_tickSpacing_idempotent - (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 20))] - rw [signextend_two_tickSpacing_idempotent - (UInt256.signextend ⟨2⟩ (burnTickUpperWord I))] - rw [signextend_two_tickSpacing_idempotent (burnTickUpperWord I)] - rw [← slot0TickRawValue_wordOfInt - (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 20))] - rw [← wordOfInt_sint24Value_eq_signextend_two (burnTickUpperWord I)] - exact slt_wordOfInt_int24 _ _ (tickSpacingSint24Value_ge _) - (tickSpacingSint24Value_lt _) (tickSpacingSint24Value_ge _) - (tickSpacingSint24Value_lt _) - -theorem burnFeeGrowthInsideUpperSlt_ne_zero (σ : AccountMap) (I : ExecutionEnv) - (hlt : - tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickUpperWord I)) : - UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ I)) - (burnTickUpperFeeGrowthCompareWord I) ≠ ⟨0⟩ := by - rw [burnFeeGrowthInsideUpperSlt_eq σ I, if_pos hlt] - native_decide - -theorem burnFeeGrowthInsideUpperSlt_eq_zero (σ : AccountMap) (I : ExecutionEnv) - (hge : - ¬ tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickUpperWord I)) : - UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ I)) - (burnTickUpperFeeGrowthCompareWord I) = ⟨0⟩ := by - rw [burnFeeGrowthInsideUpperSlt_eq σ I, if_neg hge] - -private theorem uniswapV3PoolBurnAfterFeeGlobalsDecodeEqTemplate {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 16264 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 19295 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -private theorem uniswapV3PoolPatchPreservesJumpDest19492 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨19492⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched19492 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨19492⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest19492 - -private theorem uniswapV3PoolPatchPreservesJumpDest19510 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨19510⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched19510 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨19510⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest19510 - -theorem burnLiquidityDeltaZeroJumpCond (I : ExecutionEnv) - (hzero : burnAmountCleanWord I = ⟨0⟩) : - UInt256.isZero - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))) ≠ ⟨0⟩ := by - rw [hzero] - native_decide - -theorem signextend_fifteen_zero_sub_ne_zero_of_lt {w : UInt256} - (hnonzero : w ≠ ⟨0⟩) (hlt : w.toNat < EVM.twoPow 127) : - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ w) ≠ ⟨0⟩ := by - have htoNatNe : w.toNat ≠ 0 := by - intro h - exact hnonzero (uint256_toNat_eq_zero h) - have hpos : 0 < w.toNat := Nat.pos_of_ne_zero htoNatNe - have hsubNat : (UInt256.sub (⟨0⟩ : UInt256) w).toNat = UInt256.size - w.toNat := by - have hsub := usub_toNat_underflow (a := (⟨0⟩ : UInt256)) (b := w) hpos - simpa using hsub - have hposInt : (0 : Int) < (w.toNat : Int) := by exact_mod_cast hpos - have hneg : -(Int.ofNat w.toNat) < 0 := by - have : (0 : Int) < Int.ofNat w.toNat := by simpa using hposInt - omega - have habs : (-(Int.ofNat w.toNat)).natAbs = w.toNat := by - rw [Int.natAbs_neg] - simp - have hword : UInt256.sub (⟨0⟩ : UInt256) w = - EVM.wordOfInt (-(Int.ofNat w.toNat)) := by - apply u256_inj - rw [hsubNat] - have hltWord : (-(Int.ofNat w.toNat)).natAbs < EVM.wordModulus := by - rw [habs] - rw [show EVM.wordModulus = UInt256.size by native_decide] - exact w.val.isLt - rw [wordOfInt_neg_toNat_lt_wordModulus _ hneg hltWord] - rw [habs] - rw [hword] - rw [signextend_fifteen_wordOfInt_ticks] - · intro hwzero - have hto := congrArg UInt256.toNat hwzero - have hltWord : (-(Int.ofNat w.toNat)).natAbs < EVM.wordModulus := by - rw [habs] - rw [show EVM.wordModulus = UInt256.size by native_decide] - exact w.val.isLt - rw [wordOfInt_neg_toNat_lt_wordModulus _ hneg hltWord] at hto - rw [habs] at hto - change UInt256.size - w.toNat = 0 at hto - have hwlt : w.toNat < UInt256.size := w.val.isLt - omega - · norm_num [EVM.twoPow] at hlt ⊢ - omega - · norm_num [EVM.twoPow] at hlt ⊢ - omega - -theorem signextend_fifteen_zero_sub_slt_zero_of_lt {w : UInt256} - (hnonzero : w ≠ ⟨0⟩) (hlt : w.toNat < EVM.twoPow 127) : - UInt256.slt (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ w)) ⟨0⟩ = ⟨1⟩ := by - have htoNatNe : w.toNat ≠ 0 := by - intro h - exact hnonzero (uint256_toNat_eq_zero h) - have hpos : 0 < w.toNat := Nat.pos_of_ne_zero htoNatNe - have hsubNat : (UInt256.sub (⟨0⟩ : UInt256) w).toNat = UInt256.size - w.toNat := by - simpa using usub_toNat_underflow (a := (⟨0⟩ : UInt256)) (b := w) hpos - have hposInt : (0 : Int) < (w.toNat : Int) := by exact_mod_cast hpos - have hneg : -(Int.ofNat w.toNat) < 0 := by - have : (0 : Int) < Int.ofNat w.toNat := by simpa using hposInt - omega - have habs : (-(Int.ofNat w.toNat)).natAbs = w.toNat := by - rw [Int.natAbs_neg] - simp - have hword : UInt256.sub (⟨0⟩ : UInt256) w = - EVM.wordOfInt (-(Int.ofNat w.toNat)) := by - apply u256_inj - rw [hsubNat] - have hltWord : (-(Int.ofNat w.toNat)).natAbs < EVM.wordModulus := by - rw [habs, show EVM.wordModulus = UInt256.size by native_decide] - exact w.val.isLt - rw [wordOfInt_neg_toNat_lt_wordModulus _ hneg hltWord, habs] - rw [hword, signextend_fifteen_wordOfInt_ticks] - · apply slt_lit_one_high (m := 0) - · norm_num - · have hltWord : (-(Int.ofNat w.toNat)).natAbs < EVM.wordModulus := by - rw [habs, show EVM.wordModulus = UInt256.size by native_decide] - exact w.val.isLt - rw [wordOfInt_neg_toNat_lt_wordModulus _ hneg hltWord, habs] - norm_num [UInt256.size, EVM.twoPow] at hlt ⊢ - omega - · norm_num [EVM.twoPow] at hlt ⊢ - omega - · norm_num [EVM.twoPow] at hlt ⊢ - omega - -theorem burnLiquidityDeltaNonzeroJumpCond (I : ExecutionEnv) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) : - UInt256.isZero - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))) = ⟨0⟩ := by - rw [ticksSignextendFifteen_idempotent] - apply isZero_eq_zero_of_ne - exact signextend_fifteen_zero_sub_ne_zero_of_lt hnonzero - (signextend_fifteen_eq_self_toNat_lt_twoPow127 - (by simpa [burnAmountCleanWord] using uint128Mask_bound (burnAmountWord I)) - hcanon) - -theorem burnLiquidityDeltaNegativeSltJumpCond (I : ExecutionEnv) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) : - UInt256.isZero - (UInt256.slt - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))) - ⟨0⟩) = ⟨0⟩ := by - rw [ticksSignextendFifteen_idempotent] - rw [signextend_fifteen_zero_sub_slt_zero_of_lt hnonzero - (signextend_fifteen_eq_self_toNat_lt_twoPow127 - (by simpa [burnAmountCleanWord] using uint128Mask_bound (burnAmountWord I)) - hcanon)] - native_decide - -theorem uniswapV3PoolBurnAfterFeeGlobalsLiquidityDeltaZeroJump {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcond : - UInt256.isZero - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)))) ≠ ⟨0⟩) - (h : RD code ee g s0 ⟨19189⟩ - (⟨19492⟩ :: - UInt256.isZero - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)))) :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 55 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨19492⟩ - (⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec : decode code (⟨19189⟩ : UInt256) = - decode uniswapV3PoolBytecode (⟨19189⟩ : UInt256) := by - exact uniswapV3PoolBurnAfterFeeGlobalsDecodeEqTemplate hpatch - (by native_decide) (by native_decide) - exact ⟨_, _, h.jumpiT - (by rw [hdec]; native_decide) - hcond - (uniswapV3PoolJumpDestPatched19492 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnAfterFeeGlobalsLiquidityDeltaNonzeroFallthrough - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {ret : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcond : - UInt256.isZero - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)))) = ⟨0⟩) - (h : RD code ee g s0 ⟨19189⟩ - (⟨19492⟩ :: - UInt256.isZero - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)))) :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 55 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨19190⟩ - (⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec : decode code (⟨19189⟩ : UInt256) = - decode uniswapV3PoolBytecode (⟨19189⟩ : UInt256) := by - exact uniswapV3PoolBurnAfterFeeGlobalsDecodeEqTemplate hpatch - (by native_decide) (by native_decide) - exact ⟨_, _, h.jumpiNT - (by rw [hdec]; native_decide) - hcond - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -private theorem uniswapV3PoolBurnAfterFeeGlobalsCallDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 19492 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19559) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 19559 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -private theorem uniswapV3PoolPatchPreservesJumpDest21387 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨21387⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched21387 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨21387⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest21387 - -private theorem uniswapV3PoolPatchPreservesJumpDest21457 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨21457⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched21457 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨21457⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest21457 - -private theorem uniswapV3PoolPatchPreservesJumpDest21476 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨21476⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched21476 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨21476⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest21476 - -private theorem uniswapV3PoolPatchPreservesJumpDest21510 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨21510⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched21510 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨21510⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest21510 - -private theorem uniswapV3PoolPatchPreservesJumpDest21529 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨21529⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched21529 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨21529⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest21529 - -private theorem uniswapV3PoolPatchPreservesJumpDest21559 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨21559⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched21559 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨21559⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest21559 - -private theorem uniswapV3PoolBurnFeeGrowthInsideSetupDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 21387 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21591) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 21591 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -theorem uniswapV3PoolBurnAfterFeeGlobalsEnterFeeGrowthInside {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨19492⟩ - (⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 57 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21387⟩ - (solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 19492 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19559) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnAfterFeeGlobalsCallDecodeEqTemplate hpatch hlo hhi - have rd19503 := evm_run h with [ - raw jumpdest (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨0⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push2 ⟨19510⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨5⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup13 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup13 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd19504 := RD.dup12 rd19503 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd19509 := evm_run rd19504 with [ - raw dup11 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup11 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push2 ⟨21387⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - exact ⟨_, _, rd19509.jump - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched21387 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -set_option maxHeartbeats 3000000 in -theorem uniswapV3PoolBurnFeeGrowthInsideLowerBranchTest {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21387⟩ - (solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 80 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21440⟩ - (⟨21457⟩ :: - UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ ee)) - (burnTickLowerFeeGrowthCompareWord ee) :: - ⟨0⟩ :: ⟨0⟩ :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21387 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21591) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnFeeGrowthInsideSetupDecodeEqTemplate hpatch hlo hhi - have rd21392 := evm_run h with [ - raw jumpdest (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨2⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup6 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21393 := RD.signextend rd21392 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21395 := evm_run rd21393 with [ - raw dup1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21396 := RD.signextend rd21395 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21400 := evm_run rd21396 with [ - raw push1 ⟨0⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21401 := rd21400.mstore 0 - (wordAt0Mem (burnTickLowerFeeGrowthKey ee) (burnPositionKeyMappingMem σ ee)) - (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost - (by rfl) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21405 := evm_run rd21401 with [ - raw push1 ⟨32⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup10 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21406 := rd21405.mstore 0 - (burnTickLowerFeeGrowthMem σ ee) - (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost - (by rfl) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21410 := evm_run rd21406 with [ - raw push1 ⟨64⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have hLowerSlot : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((burnTickLowerFeeGrowthMem σ ee).readWithPadding 0 64))) = - burnTickLowerFeeGrowthBaseSlot ee := by - exact twoWordHashMem_solcMappingSlot_of_size_ge ⟨5⟩ - (burnTickLowerFeeGrowthKey ee) - (by rw [burnPositionKeyMappingMem_size σ ee]; omega) - have rd21411 := rd21410.keccak256 0 (burnTickLowerFeeGrowthBaseSlot ee) - (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost - (by simpa [show (⟨0⟩ : UInt256).toNat = 0 from by decide, - show (⟨64⟩ : UInt256).toNat = 64 from by decide] using hLowerSlot) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21413 := evm_run rd21411 with [ - raw dup9 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup6 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21414 := RD.signextend rd21413 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21415 := evm_run rd21414 with [ - raw dup6 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21416 := RD.signextend rd21415 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21417 := evm_run rd21416 with [ - raw dup4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21418 := rd21417.mstore 0 - (wordAt0Mem (burnTickUpperFeeGrowthKey ee) (burnTickLowerFeeGrowthMem σ ee)) - (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost - (by rfl) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21420 := evm_run rd21418 with [ - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have hUpperSlot : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((burnTickUpperFeeGrowthMem σ ee).readWithPadding 0 64))) = - burnTickUpperFeeGrowthBaseSlot ee := by - simpa [burnTickUpperFeeGrowthMem, burnTickLowerFeeGrowthMem, - burnTickUpperFeeGrowthBaseSlot] using - wordAt0Mem_twoWordHashMem_solcMappingSlot_of_size_ge ⟨5⟩ - (burnTickLowerFeeGrowthKey ee) (burnTickUpperFeeGrowthKey ee) - (by rw [burnPositionKeyMappingMem_size σ ee]; omega) - have rd21421 := rd21420.keccak256 0 (burnTickUpperFeeGrowthBaseSlot ee) - (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost - (by simpa [show (⟨0⟩ : UInt256).toNat = 0 from by decide, - show (⟨64⟩ : UInt256).toNat = 64 from by decide] using hUpperSlot) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21435 := evm_run rd21421 with [ - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup11 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21436 := RD.signextend rd21435 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21440 := evm_run rd21436 with [ - raw slt (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push2 ⟨21457⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - exact ⟨_, _, rd21440⟩ - -theorem uniswapV3PoolBurnFeeGrowthInsideLowerBelowJump {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcond : - UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ ee)) - (burnTickLowerFeeGrowthCompareWord ee) ≠ ⟨0⟩) - (h : RD code ee g s0 ⟨21440⟩ - (⟨21457⟩ :: - UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ ee)) - (burnTickLowerFeeGrowthCompareWord ee) :: - ⟨0⟩ :: ⟨0⟩ :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 80 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21457⟩ - (⟨0⟩ :: ⟨0⟩ :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec : decode code (⟨21440⟩ : UInt256) = - decode uniswapV3PoolBytecode (⟨21440⟩ : UInt256) := by - exact uniswapV3PoolBurnFeeGrowthInsideSetupDecodeEqTemplate hpatch - (by native_decide) (by native_decide) - exact ⟨_, _, h.jumpiT - (by rw [hdec]; native_decide) - hcond - (uniswapV3PoolJumpDestPatched21457 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnFeeGrowthInsideLowerNotBelowFallthrough {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hzero : - UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ ee)) - (burnTickLowerFeeGrowthCompareWord ee) = ⟨0⟩) - (h : RD code ee g s0 ⟨21440⟩ - (⟨21457⟩ :: - UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ ee)) - (burnTickLowerFeeGrowthCompareWord ee) :: - ⟨0⟩ :: ⟨0⟩ :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 80 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21441⟩ - (⟨0⟩ :: ⟨0⟩ :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec : decode code (⟨21440⟩ : UInt256) = - decode uniswapV3PoolBytecode (⟨21440⟩ : UInt256) := by - exact uniswapV3PoolBurnFeeGrowthInsideSetupDecodeEqTemplate hpatch - (by native_decide) (by native_decide) - exact ⟨_, _, h.jumpiNT - (by rw [hdec]; native_decide) - hzero - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnFeeGrowthInsideLowerBelowToJoin {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21457⟩ - (⟨0⟩ :: ⟨0⟩ :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 80 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21476⟩ - (UInt256.sub (solcSlotWord σ ee ⟨2⟩) - (burnTickLowerFeeGrowthOutside1Word σ ee) :: - UInt256.sub (solcSlotWord σ ee ⟨1⟩) - (burnTickLowerFeeGrowthOutside0Word σ ee) :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21387 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21591) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnFeeGrowthInsideSetupDecodeEqTemplate hpatch hlo hhi - have rd21462 := evm_run h with [ - raw jumpdest (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨1⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - obtain ⟨_, _, rd21463⟩ := rd21462.sload - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21467 := evm_run rd21463 with [ - raw dup9 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21471 := evm_run rd21467 with [ - raw dup4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨2⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - obtain ⟨_, _, rd21472⟩ := rd21471.sload - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21476 := evm_run rd21472 with [ - raw dup8 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - exact ⟨_, _, rd21476⟩ - -theorem uniswapV3PoolBurnFeeGrowthInsideLowerNotBelowToJoin {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21441⟩ - (⟨0⟩ :: ⟨0⟩ :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 80 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21476⟩ - (solcSlotWord σ ee (burnTickLowerFeeGrowthBaseSlot ee + ⟨2⟩) :: - solcSlotWord σ ee (burnTickLowerFeeGrowthBaseSlot ee + ⟨1⟩) :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21387 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21591) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnFeeGrowthInsideSetupDecodeEqTemplate hpatch hlo hhi - have rd21447 := evm_run h with [ - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨1⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - obtain ⟨_, _, rd21448⟩ := rd21447.sload - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21452 := evm_run rd21448 with [ - raw push1 ⟨2⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - obtain ⟨_, _, rd21453⟩ := rd21452.sload - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21456 := evm_run rd21453 with [ - raw push2 ⟨21476⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - exact ⟨_, _, rd21456.jump - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched21476 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnFeeGrowthInsideUpperBranchTest {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret below1 below0 : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21476⟩ - (below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 82 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21493⟩ - (⟨21510⟩ :: - UInt256.isZero - (UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ ee)) - (burnTickUpperFeeGrowthCompareWord ee)) :: - ⟨0⟩ :: ⟨0⟩ :: below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21387 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21591) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnFeeGrowthInsideSetupDecodeEqTemplate hpatch hlo hhi - have rd21480 := evm_run h with [ - raw jumpdest (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨0⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21481 := RD.dup12 rd21480 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21483 := evm_run rd21481 with [ - raw push1 ⟨2⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21484 := RD.signextend rd21483 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21485 := RD.dup12 rd21484 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21487 := evm_run rd21485 with [ - raw push1 ⟨2⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21488 := RD.signextend rd21487 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21493 := evm_run rd21488 with [ - raw slt (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw iszero (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push2 ⟨21510⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - exact ⟨_, _, rd21493⟩ - -theorem uniswapV3PoolBurnFeeGrowthInsideUpperNotInsideJump {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret below1 below0 : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcond : - UInt256.isZero - (UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ ee)) - (burnTickUpperFeeGrowthCompareWord ee)) ≠ ⟨0⟩) - (h : RD code ee g s0 ⟨21493⟩ - (⟨21510⟩ :: - UInt256.isZero - (UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ ee)) - (burnTickUpperFeeGrowthCompareWord ee)) :: - ⟨0⟩ :: ⟨0⟩ :: below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 82 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21510⟩ - (⟨0⟩ :: ⟨0⟩ :: below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec : decode code (⟨21493⟩ : UInt256) = - decode uniswapV3PoolBytecode (⟨21493⟩ : UInt256) := by - exact uniswapV3PoolBurnFeeGrowthInsideSetupDecodeEqTemplate hpatch - (by native_decide) (by native_decide) - exact ⟨_, _, h.jumpiT - (by rw [hdec]; native_decide) - hcond - (uniswapV3PoolJumpDestPatched21510 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnFeeGrowthInsideUpperInsideFallthrough {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret below1 below0 : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hzero : - UInt256.isZero - (UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ ee)) - (burnTickUpperFeeGrowthCompareWord ee)) = ⟨0⟩) - (h : RD code ee g s0 ⟨21493⟩ - (⟨21510⟩ :: - UInt256.isZero - (UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ ee)) - (burnTickUpperFeeGrowthCompareWord ee)) :: - ⟨0⟩ :: ⟨0⟩ :: below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 82 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21494⟩ - (⟨0⟩ :: ⟨0⟩ :: below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec : decode code (⟨21493⟩ : UInt256) = - decode uniswapV3PoolBytecode (⟨21493⟩ : UInt256) := by - exact uniswapV3PoolBurnFeeGrowthInsideSetupDecodeEqTemplate hpatch - (by native_decide) (by native_decide) - exact ⟨_, _, h.jumpiNT - (by rw [hdec]; native_decide) - hzero - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnFeeGrowthInsideUpperInsideToJoin {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret below1 below0 : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21494⟩ - (⟨0⟩ :: ⟨0⟩ :: below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 82 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21529⟩ - (solcSlotWord σ ee (burnTickUpperFeeGrowthBaseSlot ee + ⟨2⟩) :: - solcSlotWord σ ee (burnTickUpperFeeGrowthBaseSlot ee + ⟨1⟩) :: - below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21387 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21591) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnFeeGrowthInsideSetupDecodeEqTemplate hpatch hlo hhi - have rd21500 := evm_run h with [ - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨1⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - obtain ⟨_, _, rd21501⟩ := rd21500.sload - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21505 := evm_run rd21501 with [ - raw push1 ⟨2⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - obtain ⟨_, _, rd21506⟩ := rd21505.sload - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21509 := evm_run rd21506 with [ - raw push2 ⟨21529⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - exact ⟨_, _, rd21509.jump - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched21529 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnFeeGrowthInsideUpperNotInsideToJoin {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret below1 below0 : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21510⟩ - (⟨0⟩ :: ⟨0⟩ :: below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 82 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21529⟩ - (UInt256.sub (solcSlotWord σ ee ⟨2⟩) - (burnTickUpperFeeGrowthOutside1Word σ ee) :: - UInt256.sub (solcSlotWord σ ee ⟨1⟩) - (burnTickUpperFeeGrowthOutside0Word σ ee) :: - below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21387 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21591) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnFeeGrowthInsideSetupDecodeEqTemplate hpatch hlo hhi - have rd21515 := evm_run h with [ - raw jumpdest (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨1⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - obtain ⟨_, _, rd21516⟩ := rd21515.sload - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21520 := evm_run rd21516 with [ - raw dup11 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21524 := evm_run rd21520 with [ - raw dup5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨2⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - obtain ⟨_, _, rd21525⟩ := rd21524.sload - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21529 := evm_run rd21525 with [ - raw dup10 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - exact ⟨_, _, rd21529⟩ - -theorem uniswapV3PoolBurnFeeGrowthInsideJoinReturn {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret above1 above0 below1 below0 upperBase lowerBase z0 z1 fee1 fee0 tick upper lower marker : - UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains ret = true) - (h : RD code ee g s0 ⟨21529⟩ - (above1 :: above0 :: below1 :: below0 :: upperBase :: lowerBase :: z0 :: z1 :: - fee1 :: fee0 :: tick :: upper :: lower :: marker :: ret :: R) - mem aw rdata acc k C) - (hov : R.length + 15 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret - (UInt256.sub (UInt256.sub fee1 below1) above1 :: - UInt256.sub (UInt256.sub fee0 below0) above0 :: R) - mem aw rdata acc k' C' := by - have hdec (pc : UInt256) - (hlo : 21387 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21591) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnFeeGrowthInsideSetupDecodeEqTemplate hpatch hlo hhi - have rd21532 := evm_run h with [ - raw jumpdest (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21533 := RD.swap9 rd21532 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21538 := evm_run rd21533 with [ - raw sub (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap8 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap8 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21539 := RD.swap12 rd21538 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by omega) - have rd21547 := evm_run rd21539 with [ - raw swap7 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap6 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21548 := RD.swap9 rd21547 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21558 := evm_run rd21548 with [ - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap4 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap7 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - exact ⟨_, _, rd21558.jump - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - hdest - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnFeeGrowthInsideEnterPositionUpdate {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {inside1 inside0 z0 z1 z2 z3 fee1 fee0 posBase tick delta upper lower owner ret free : - UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨19510⟩ - (inside1 :: inside0 :: z0 :: z1 :: z2 :: z3 :: fee1 :: fee0 :: posBase :: - tick :: delta :: upper :: lower :: owner :: ret :: free :: R) - mem aw rdata acc k C) - (hov : R.length + 20 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21559⟩ - (inside1 :: inside0 :: delta :: posBase :: ⟨19527⟩ :: inside1 :: inside0 :: - z2 :: z3 :: fee1 :: fee0 :: posBase :: tick :: delta :: upper :: lower :: - owner :: ret :: free :: R) - mem aw rdata acc k' C' := by - have hdec (pc : UInt256) - (hlo : 19492 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19559) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnAfterFeeGlobalsCallDecodeEqTemplate hpatch hlo hhi - have rd19526 := evm_run h with [ - raw jumpdest (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push2 ⟨19527⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup8 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup11 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup5 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push2 ⟨21559⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - exact ⟨_, _, rd19526.jump - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched21559 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnAfterFeeGlobalsZeroToFeeGrowthInside {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hzero : burnAmountCleanWord ee = ⟨0⟩) - (h : RD code ee g s0 ⟨19189⟩ - (⟨19492⟩ :: - UInt256.isZero - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)))) :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 57 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21387⟩ - (solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - obtain ⟨_, _, hrdZero⟩ := - uniswapV3PoolBurnAfterFeeGlobalsLiquidityDeltaZeroJump (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (R := R) (rdata := rdata) - (cA := cA) (σ := σ) hpatch (burnLiquidityDeltaZeroJumpCond ee hzero) h - (by omega) - exact uniswapV3PoolBurnAfterFeeGlobalsEnterFeeGrowthInside (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (R := R) (rdata := rdata) - (cA := cA) (σ := σ) hpatch hrdZero hov - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnAfterFeeGrowthInside.lean b/Benchmarks/UniswapV3Pool/BurnAfterFeeGrowthInside.lean deleted file mode 100644 index 2ae5177d..00000000 --- a/Benchmarks/UniswapV3Pool/BurnAfterFeeGrowthInside.lean +++ /dev/null @@ -1,295 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnAfterFeeGlobals - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem burnFeeGrowthInsideUpperIsZero_eq_zero_of_lt (σ : AccountMap) - (I : ExecutionEnv) - (hlt : - tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickUpperWord I)) : - UInt256.isZero - (UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ I)) - (burnTickUpperFeeGrowthCompareWord I)) = ⟨0⟩ := by - exact isZero_eq_zero_of_ne (burnFeeGrowthInsideUpperSlt_ne_zero σ I hlt) - -theorem burnFeeGrowthInsideUpperIsZero_ne_zero_of_ge (σ : AccountMap) - (I : ExecutionEnv) - (hge : - ¬ tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickUpperWord I)) : - UInt256.isZero - (UInt256.slt (UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ I)) - (burnTickUpperFeeGrowthCompareWord I)) ≠ ⟨0⟩ := by - rw [burnFeeGrowthInsideUpperSlt_eq_zero σ I hge] - native_decide - -theorem uniswapV3PoolBurnFeeGrowthInsideLowerBelowToUpperJoin {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlt : - tickSpacingSint24Value (slot0TickRawWord σ ee) < - tickSpacingSint24Value (burnTickLowerWord ee)) - (h : RD code ee g s0 ⟨21387⟩ - (solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 80 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21476⟩ - (UInt256.sub (solcSlotWord σ ee ⟨2⟩) - (burnTickLowerFeeGrowthOutside1Word σ ee) :: - UInt256.sub (solcSlotWord σ ee ⟨1⟩) - (burnTickLowerFeeGrowthOutside0Word σ ee) :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - obtain ⟨_, _, hrdTest⟩ := - uniswapV3PoolBurnFeeGrowthInsideLowerBranchTest (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (R := R) (rdata := rdata) - (cA := cA) (σ := σ) hpatch h hov - obtain ⟨_, _, hrdJump⟩ := - uniswapV3PoolBurnFeeGrowthInsideLowerBelowJump (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (R := R) (rdata := rdata) - (cA := cA) (σ := σ) hpatch (burnFeeGrowthInsideLowerSlt_ne_zero σ ee hlt) - hrdTest hov - exact uniswapV3PoolBurnFeeGrowthInsideLowerBelowToJoin (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (R := R) (rdata := rdata) - (cA := cA) (σ := σ) hpatch hrdJump hov - -theorem uniswapV3PoolBurnFeeGrowthInsideLowerNotBelowToUpperJoin - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {ret : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hge : - ¬ tickSpacingSint24Value (slot0TickRawWord σ ee) < - tickSpacingSint24Value (burnTickLowerWord ee)) - (h : RD code ee g s0 ⟨21387⟩ - (solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 80 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21476⟩ - (solcSlotWord σ ee (burnTickLowerFeeGrowthBaseSlot ee + ⟨2⟩) :: - solcSlotWord σ ee (burnTickLowerFeeGrowthBaseSlot ee + ⟨1⟩) :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - obtain ⟨_, _, hrdTest⟩ := - uniswapV3PoolBurnFeeGrowthInsideLowerBranchTest (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (R := R) (rdata := rdata) - (cA := cA) (σ := σ) hpatch h hov - obtain ⟨_, _, hrdFallthrough⟩ := - uniswapV3PoolBurnFeeGrowthInsideLowerNotBelowFallthrough (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (R := R) (rdata := rdata) - (cA := cA) (σ := σ) hpatch (burnFeeGrowthInsideLowerSlt_eq_zero σ ee hge) - hrdTest hov - exact uniswapV3PoolBurnFeeGrowthInsideLowerNotBelowToJoin (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (R := R) (rdata := rdata) - (cA := cA) (σ := σ) hpatch hrdFallthrough hov - -theorem uniswapV3PoolBurnFeeGrowthInsideUpperInsideFromJoin {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret below1 below0 : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlt : - tickSpacingSint24Value (slot0TickRawWord σ ee) < - tickSpacingSint24Value (burnTickUpperWord ee)) - (h : RD code ee g s0 ⟨21476⟩ - (below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 82 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21529⟩ - (solcSlotWord σ ee (burnTickUpperFeeGrowthBaseSlot ee + ⟨2⟩) :: - solcSlotWord σ ee (burnTickUpperFeeGrowthBaseSlot ee + ⟨1⟩) :: - below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - obtain ⟨_, _, hrdTest⟩ := - uniswapV3PoolBurnFeeGrowthInsideUpperBranchTest (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (below1 := below1) - (below0 := below0) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch h hov - obtain ⟨_, _, hrdFallthrough⟩ := - uniswapV3PoolBurnFeeGrowthInsideUpperInsideFallthrough (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (below1 := below1) - (below0 := below0) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch (burnFeeGrowthInsideUpperIsZero_eq_zero_of_lt σ ee hlt) hrdTest hov - exact uniswapV3PoolBurnFeeGrowthInsideUpperInsideToJoin (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (below1 := below1) - (below0 := below0) (R := R) (rdata := rdata) (cA := cA) (σ := σ) hpatch - hrdFallthrough hov - -theorem uniswapV3PoolBurnFeeGrowthInsideUpperNotInsideFromJoin - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {ret below1 below0 : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hge : - ¬ tickSpacingSint24Value (slot0TickRawWord σ ee) < - tickSpacingSint24Value (burnTickUpperWord ee)) - (h : RD code ee g s0 ⟨21476⟩ - (below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 82 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21529⟩ - (UInt256.sub (solcSlotWord σ ee ⟨2⟩) - (burnTickUpperFeeGrowthOutside1Word σ ee) :: - UInt256.sub (solcSlotWord σ ee ⟨1⟩) - (burnTickUpperFeeGrowthOutside0Word σ ee) :: - below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot ee :: burnTickLowerFeeGrowthBaseSlot ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - obtain ⟨_, _, hrdTest⟩ := - uniswapV3PoolBurnFeeGrowthInsideUpperBranchTest (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (below1 := below1) - (below0 := below0) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch h hov - obtain ⟨_, _, hrdJump⟩ := - uniswapV3PoolBurnFeeGrowthInsideUpperNotInsideJump (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (below1 := below1) - (below0 := below0) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch (burnFeeGrowthInsideUpperIsZero_ne_zero_of_ge σ ee hge) hrdTest hov - exact uniswapV3PoolBurnFeeGrowthInsideUpperNotInsideToJoin (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (below1 := below1) - (below0 := below0) (R := R) (rdata := rdata) (cA := cA) (σ := σ) hpatch hrdJump hov - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnBody.lean b/Benchmarks/UniswapV3Pool/BurnBody.lean deleted file mode 100644 index 517fbecb..00000000 --- a/Benchmarks/UniswapV3Pool/BurnBody.lean +++ /dev/null @@ -1,2000 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnSourceSuccess -import Benchmarks.UniswapV3Pool.BurnPositionUpdateTokensOwedBridge -import Benchmarks.UniswapV3Pool.BurnZeroDeltaFinish -import Benchmarks.UniswapV3Pool.BurnZeroDeltaSlowToken0 -import Benchmarks.UniswapV3Pool.BurnLowerLiquidityAddDeltaRevert - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 17 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_burn (v := v) (cd := I.calldata) hsel - by_cases hsz100 : 100 ≤ I.calldata.size - · have hdecode := uniswapV3PoolBurnDecodeOk (v := v) (I := I) hsz100 - have hdecoded := uniswapV3PoolBurnExternalLenOk (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsz100 hsize hsel - obtain ⟨_, _, hrdDecoded⟩ := hdecoded - obtain ⟨_, _, hrdLower⟩ := - uniswapV3PoolBurnDecodedReachTickLower (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) hpatch (by - simpa using hrdDecoded) (by simp) - obtain ⟨_, _, hrdUpper⟩ := - uniswapV3PoolBurnTickLowerReachTickUpper (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) hpatch hrdLower (by simp) - obtain ⟨_, _, hrdModifyPosition⟩ := - uniswapV3PoolBurnTickUpperReachModifyPosition (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) hpatch hrdUpper (by simp) - by_cases hunlocked : burnUnlockedByte σ_evm I ≠ ⟨0⟩ - · obtain ⟨_, _, hrdAfterLock⟩ := - uniswapV3PoolBurnLockEnterOk (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (amount := burnAmountCleanWord I) (upper := burnTickUpperCleanWord I) - (lower := burnTickLowerCleanWord I) (ret := ⟨621⟩) - (R := [solcSelectorWord I]) (mem := solcFreePtrMem) - (aw := UInt256.ofNat 3) (rdata := ByteArray.empty) - (cA := cA) (σ := σ_evm) hpatch hrdModifyPosition _hperm hunlocked - (by simp only [List.length_cons, List.length_nil]; omega) - have hunlockedSolm : burnUnlockedByte σ_solm I ≠ ⟨0⟩ := by - rw [burnUnlockedByte_transport (σ_evm := σ_evm) (σ_solm := σ_solm) - hAccounts] - exact hunlocked - have hsourceLock := uniswapV3PoolBurnSourceLockPrefixExact (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm - have hlockedWord : - burnLockedSlotWord σ_solm I = burnLockedSlotWord σ_evm I := - burnLockedSlotWord_transport (σ_evm := σ_evm) (σ_solm := σ_solm) - hAccounts - let σLockedEvm := sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ (burnLockedSlotWord σ_evm I) - let σLockedSolm := sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I) - have hAccountsAfterLock : - accountMapEquiv σLockedEvm σLockedSolm := by - dsimp [σLockedEvm, σLockedSolm] - rw [hlockedWord] - exact accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ_evm I) hAccounts - obtain ⟨_, _, hrdOwnerFrame⟩ := - uniswapV3PoolBurnAfterLockWriteOwner (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (amount := burnAmountCleanWord I) (upper := burnTickUpperCleanWord I) - (lower := burnTickLowerCleanWord I) (ret := ⟨621⟩) - (R := [solcSelectorWord I]) (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hrdAfterLock - (by simp only [List.length_cons, List.length_nil]; omega) - obtain ⟨_, _, hrdTickFrame⟩ := - uniswapV3PoolBurnAfterLockWriteTicks (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (cA := cA) - (σ := σLockedEvm) - hpatch hrdOwnerFrame - (by simp only [List.length_cons, List.length_nil]; omega) - obtain ⟨_, _, hrdLiquidityDeltaPrep⟩ := - uniswapV3PoolBurnPrepareLiquidityDelta (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (cA := cA) - (σ := σLockedEvm) - hpatch hrdTickFrame - (by simp only [List.length_cons, List.length_nil]; omega) - by_cases hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I - · obtain ⟨_, _, hrdLiquidityDeltaClean⟩ := - uniswapV3PoolBurnLiquidityDeltaInt128Ok (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (cA := cA) - (σ := σLockedEvm) - hpatch hrdLiquidityDeltaPrep hcanon - (by simp only [List.length_cons, List.length_nil]; omega) - have hsourceLiquidityDelta := uniswapV3PoolBurnSourceThroughLiquidityDelta (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm hcanon - obtain ⟨_, _, hrdLiquidityDeltaWritten⟩ := - uniswapV3PoolBurnWriteLiquidityDelta (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (cA := cA) - (σ := σLockedEvm) - hpatch hrdLiquidityDeltaClean - (by simp only [List.length_cons, List.length_nil]; omega) - have hrdNoDelegateOfGuard : - uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩ → - ∃ k' C', RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨16246⟩ - (⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnModifyPositionMem4 I) (UInt256.ofNat 8) ByteArray.empty - (cA, - σLockedEvm) k' C' := by - intro hnoDelegate - exact uniswapV3PoolBurnNoDelegateCallOk (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (cA := cA) - (σ := σLockedEvm) - hpatch hrdLiquidityDeltaWritten hnoDelegate - (by simp only [List.length_cons, List.length_nil]; omega) - by_cases hnoDelegate : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩ - · obtain ⟨_, _, hrdNoDelegate⟩ := hrdNoDelegateOfGuard hnoDelegate - obtain ⟨_, _, hrdCheckTicks⟩ := - uniswapV3PoolBurnEnterCheckTicks (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (cA := cA) - (σ := σLockedEvm) - hpatch hrdNoDelegate - (by simp only [List.length_cons, List.length_nil]; omega) - have hsourceNoDelegate := uniswapV3PoolModifyPositionSourceNoDelegateOk (v := v) - (cA := cA) (gh := gh) (bl := bl) - (σ := σLockedSolm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hnoDelegate - obtain ⟨_, _, hrdCheckTicksWords⟩ : - ∃ k' C', RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨17313⟩ - (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: ⟨16264⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnModifyPositionMem4 I) (UInt256.ofNat 8) ByteArray.empty - (cA, - σLockedEvm) k' C' := by - exact ⟨_, _, by - simpa [burnModifyPositionTickUpperLoad_eq I, - burnModifyPositionTickLowerLoad_eq I] using hrdCheckTicks⟩ - have hrdCheckTicksLtOfGuard : - UInt256.slt - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ - (burnTickLowerCleanWord I))) - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ - (burnTickUpperCleanWord I))) ≠ ⟨0⟩ → - ∃ k' C', RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨17377⟩ - (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: ⟨16264⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnModifyPositionMem4 I) (UInt256.ofNat 8) ByteArray.empty - (cA, - σLockedEvm) k' C' := by - intro hlt - exact uniswapV3PoolBurnCheckTicksLtOk (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨16264⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (mem := burnModifyPositionMem4 I) (aw := UInt256.ofNat 8) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hrdCheckTicksWords hlt - (by simp only [List.length_cons, List.length_nil]; omega) - by_cases htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I) - · have hltGuard := burnTickLtSlt_ne_zero I htickLt - obtain ⟨_, _, hrdAfterTickLt⟩ := hrdCheckTicksLtOfGuard hltGuard - by_cases hLowerMin : - tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int) - · have hltMinGuard := burnTickLowerMinSlt_ne_zero I hLowerMin - have hrd := uniswapV3PoolBurnCheckTicksLowerRevert (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨16264⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (mem := burnModifyPositionMem4 I) (aw := UInt256.ofNat 8) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hrdAfterTickLt hltMinGuard rfl rfl - (by simp only [List.length_cons, List.length_nil]; omega) - have hbody := uniswapV3PoolBurnSourceLowerReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm hcanon - hnoDelegate htickLt hLowerMin - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hgeMinGuard := burnTickLowerMinSlt_eq_zero I hLowerMin - obtain ⟨_, _, hrdAfterLower⟩ := - uniswapV3PoolBurnCheckTicksLowerOk (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨16264⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (mem := burnModifyPositionMem4 I) (aw := UInt256.ofNat 8) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hrdAfterTickLt hgeMinGuard - (by simp only [List.length_cons, List.length_nil]; omega) - have hsourceLower := uniswapV3PoolModifyPositionSourceThroughLowerGe (v := v) - (cA := cA) (gh := gh) (bl := bl) - (σ := σLockedSolm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) - hnoDelegate htickLt hLowerMin - by_cases hUpperMax : - (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I) - · have hgtMaxGuard := burnTickUpperMaxSgt_ne_zero I hUpperMax - have hrd := uniswapV3PoolBurnCheckTicksUpperRevert (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨16264⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (mem := burnModifyPositionMem4 I) (aw := UInt256.ofNat 8) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hrdAfterLower hgtMaxGuard rfl rfl - (by simp only [List.length_cons, List.length_nil]; omega) - have hbody := uniswapV3PoolBurnSourceUpperReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm hcanon - hnoDelegate htickLt hLowerMin hUpperMax - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hleMaxGuard := burnTickUpperMaxSgt_eq_zero I hUpperMax - obtain ⟨_, _, hrdAfterUpper⟩ := - uniswapV3PoolBurnCheckTicksUpperOk (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨16264⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (mem := burnModifyPositionMem4 I) (aw := UInt256.ofNat 8) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hrdAfterLower hleMaxGuard - (by simp only [List.length_cons, List.length_nil]; omega) - have hsourcePositionKey := - uniswapV3PoolModifyPositionSourceThroughPositionKey (v := v) - (cA := cA) (gh := gh) (bl := bl) - (σ := σLockedSolm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) - hnoDelegate htickLt hLowerMin hUpperMax - have hsourceFeeGlobals := - uniswapV3PoolModifyPositionSourceThroughFeeGrowthGlobals (v := v) - (cA := cA) (gh := gh) (bl := bl) - (σ := σLockedSolm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) - hnoDelegate htickLt hLowerMin hUpperMax - obtain ⟨_, _, hrdAfterCheckTicks⟩ := - uniswapV3PoolBurnCheckTicksReturn (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨16264⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (mem := burnModifyPositionMem4 I) (aw := UInt256.ofNat 8) - (rdata := ByteArray.empty) - (acc := (cA, σLockedEvm)) - hpatch hrdAfterUpper (uniswapV3PoolJumpDestPatched16264 hpatch) - (by simp only [List.length_cons, List.length_nil]; omega) - obtain ⟨_, _, hrdSlot0Frame⟩ := - uniswapV3PoolBurnAfterCheckTicksSlot0Frame (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hrdAfterCheckTicks - (by simp only [List.length_cons, List.length_nil]; omega) - obtain ⟨_, _, hrdPositionKeyEntry⟩ := - uniswapV3PoolBurnAfterCheckTicksEnterPositionKey (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hrdSlot0Frame - (by simp only [List.length_cons, List.length_nil]; omega) - obtain ⟨_, _, hrdPositionKeyRoutine⟩ := - uniswapV3PoolBurnAfterCheckTicksCallPositionKeyRoutine (v := v) - (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hrdPositionKeyEntry - (by simp only [List.length_cons, List.length_nil]; omega) - obtain ⟨_, _, hrdPositionBaseSlot⟩ := - uniswapV3PoolBurnAfterCheckTicksPositionKeyRoutine (v := v) - (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hrdPositionKeyRoutine - (by simp only [List.length_cons, List.length_nil]; omega) - obtain ⟨_, _, hrdFeeGlobalsBranchTest⟩ := - uniswapV3PoolBurnAfterCheckTicksFeeGlobalsBranchTest (v := v) - (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hrdPositionBaseSlot - (by simp only [List.length_cons, List.length_nil]; omega) - have hsourceZeroBranch := fun hzero => - uniswapV3PoolModifyPositionSourceThroughLiquidityDeltaZeroSkip - (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ := σLockedSolm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) - hnoDelegate htickLt hLowerMin hUpperMax hzero - have hrdZeroBranch := fun hzero => - uniswapV3PoolBurnAfterFeeGlobalsLiquidityDeltaZeroJump (v := v) - (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch (burnLiquidityDeltaZeroJumpCond I hzero) - hrdFeeGlobalsBranchTest - (by simp only [List.length_cons, List.length_nil]; omega) - have hrdFeeGrowthInsideEntry := fun hzero => - uniswapV3PoolBurnAfterFeeGlobalsZeroToFeeGrowthInside (v := v) - (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hzero hrdFeeGlobalsBranchTest - (by simp only [List.length_cons, List.length_nil]; omega) - have hrdFeeGrowthInsideJoinOfZero : - burnAmountCleanWord I = ⟨0⟩ → - ∃ k' C' above1 above0 below1 below0, - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨21529⟩ - (above1 :: above0 :: below1 :: below0 :: - burnTickUpperFeeGrowthBaseSlot I :: - burnTickLowerFeeGrowthBaseSlot I :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord - (σLockedEvm) I ⟨2⟩ :: - solcSlotWord - (σLockedEvm) I ⟨1⟩ :: - slot0TickReturnWord - (σLockedEvm) I :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord - (σLockedEvm) I ⟨2⟩ :: - solcSlotWord - (σLockedEvm) I ⟨1⟩ :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - slot0TickReturnWord - (σLockedEvm) I :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnTickUpperFeeGrowthMem - (σLockedEvm) I) - (UInt256.ofNat 18) ByteArray.empty - (cA, - σLockedEvm) k' C' := by - intro hzero - obtain ⟨_, _, hrdEntry⟩ := hrdFeeGrowthInsideEntry hzero - by_cases hCurrentBelow : - tickSpacingSint24Value - (slot0TickRawWord - (σLockedEvm) I) < - tickSpacingSint24Value (burnTickLowerWord I) - · obtain ⟨_, _, hrdLower⟩ := - uniswapV3PoolBurnFeeGrowthInsideLowerBelowToUpperJoin - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hCurrentBelow hrdEntry - (by simp only [List.length_cons, List.length_nil]; omega) - have hCurrentUpper : - tickSpacingSint24Value - (slot0TickRawWord - (σLockedEvm) I) < - tickSpacingSint24Value (burnTickUpperWord I) := - lt_trans hCurrentBelow htickLt - obtain ⟨_, _, hrdUpper⟩ := - uniswapV3PoolBurnFeeGrowthInsideUpperInsideFromJoin - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hCurrentUpper hrdLower - (by simp only [List.length_cons, List.length_nil]; omega) - exact ⟨_, _, _, _, _, _, hrdUpper⟩ - · obtain ⟨_, _, hrdLower⟩ := - uniswapV3PoolBurnFeeGrowthInsideLowerNotBelowToUpperJoin - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hCurrentBelow hrdEntry - (by simp only [List.length_cons, List.length_nil]; omega) - by_cases hCurrentUpper : - tickSpacingSint24Value - (slot0TickRawWord - (σLockedEvm) I) < - tickSpacingSint24Value (burnTickUpperWord I) - · obtain ⟨_, _, hrdUpper⟩ := - uniswapV3PoolBurnFeeGrowthInsideUpperInsideFromJoin - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hCurrentUpper hrdLower - (by simp only [List.length_cons, List.length_nil]; omega) - exact ⟨_, _, _, _, _, _, hrdUpper⟩ - · obtain ⟨_, _, hrdUpper⟩ := - uniswapV3PoolBurnFeeGrowthInsideUpperNotInsideFromJoin - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hCurrentUpper hrdLower - (by simp only [List.length_cons, List.length_nil]; omega) - exact ⟨_, _, _, _, _, _, hrdUpper⟩ - have hrdFeeGrowthInsideReturnOfZero : - burnAmountCleanWord I = ⟨0⟩ → - ∃ k' C' feeGrowthInside1 feeGrowthInside0, - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨19510⟩ - (feeGrowthInside1 :: feeGrowthInside0 :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord - (σLockedEvm) I ⟨2⟩ :: - solcSlotWord - (σLockedEvm) I ⟨1⟩ :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - slot0TickReturnWord - (σLockedEvm) I :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnTickUpperFeeGrowthMem - (σLockedEvm) I) - (UInt256.ofNat 18) ByteArray.empty - (cA, - σLockedEvm) k' C' := by - intro hzero - obtain ⟨_, _, hrdEntry⟩ := hrdFeeGrowthInsideEntry hzero - obtain ⟨_, _, hrdReturn⟩ := - uniswapV3PoolBurnFeeGrowthInsideEntryReturnConcrete (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch htickLt hrdEntry - (by simp only [List.length_cons, List.length_nil]; omega) - exact ⟨_, _, _, _, hrdReturn⟩ - have hrdPositionUpdateEntryOfZero : - burnAmountCleanWord I = ⟨0⟩ → - ∃ k' C' feeGrowthInside1 feeGrowthInside0, - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨21559⟩ - (feeGrowthInside1 :: feeGrowthInside0 :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - ⟨19527⟩ :: - feeGrowthInside1 :: feeGrowthInside0 :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord - (σLockedEvm) I ⟨2⟩ :: - solcSlotWord - (σLockedEvm) I ⟨1⟩ :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - slot0TickReturnWord - (σLockedEvm) I :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnTickUpperFeeGrowthMem - (σLockedEvm) I) - (UInt256.ofNat 18) ByteArray.empty - (cA, - σLockedEvm) k' C' := by - intro hzero - obtain ⟨_, _, feeGrowthInside1, feeGrowthInside0, hrdReturn⟩ := - hrdFeeGrowthInsideReturnOfZero hzero - obtain ⟨_, _, hrdEntry⟩ := - uniswapV3PoolBurnFeeGrowthInsideEnterPositionUpdate - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (z0 := ⟨0⟩) (z1 := ⟨0⟩) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord - (σLockedEvm) I ⟨2⟩) - (fee0 := solcSlotWord - (σLockedEvm) I ⟨1⟩) - (posBase := burnPositionBaseSlotWord - (σLockedEvm) I) - (tick := slot0TickReturnWord - (σLockedEvm) I) - (delta := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (ret := ⟨16428⟩) - (free := ⟨256⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - hpatch hrdReturn - (by simp only [List.length_cons, List.length_nil]; omega) - exact ⟨_, _, _, _, hrdEntry⟩ - have hrdPositionUpdateSlot0OfZero : - burnAmountCleanWord I = ⟨0⟩ → - ∃ k' C' feeGrowthInside1 feeGrowthInside0, - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨21572⟩ - (solcSlotWord - (σLockedEvm) I - (burnPositionBaseSlotWord - (σLockedEvm) I) :: - burnPositionKeyNewFreePtrWord :: ⟨64⟩ :: - feeGrowthInside1 :: feeGrowthInside0 :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - ⟨19527⟩ :: - feeGrowthInside1 :: feeGrowthInside0 :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord - (σLockedEvm) I ⟨2⟩ :: - solcSlotWord - (σLockedEvm) I ⟨1⟩ :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - slot0TickReturnWord - (σLockedEvm) I :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnPositionUpdateMem0 - (σLockedEvm) I) - (UInt256.ofNat 18) ByteArray.empty - (cA, - σLockedEvm) k' C' := by - intro hzero - obtain ⟨_, _, feeGrowthInside1, feeGrowthInside0, hrdEntry⟩ := - hrdPositionUpdateEntryOfZero hzero - have hslot0Result := - (uniswapV3PoolBurnPositionUpdateLoadSlot0 - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (delta := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (posBase := burnPositionBaseSlotWord - (σLockedEvm) I) - (retPos := ⟨19527⟩) - (inside1' := feeGrowthInside1) (inside0' := feeGrowthInside0) - (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord - (σLockedEvm) I ⟨2⟩) - (fee0 := solcSlotWord - (σLockedEvm) I ⟨1⟩) - (posBase' := burnPositionBaseSlotWord - (σLockedEvm) I) - (tick := slot0TickReturnWord - (σLockedEvm) I) - (delta' := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (ret := ⟨16428⟩) - (free := ⟨256⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - hpatch hrdEntry - (by simp only [List.length_cons, List.length_nil]; omega)) - obtain ⟨_, _, hrdSlot0⟩ := hslot0Result - exact ⟨_, _, _, _, hrdSlot0⟩ - have hrdPositionUpdatePackedSlot0OfZero : - burnAmountCleanWord I = ⟨0⟩ → - ∃ k' C' feeGrowthInside1 feeGrowthInside0, - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨21585⟩ - (burnPositionUpdateSlot0Mask :: - burnPositionKeyNewFreePtrWord :: ⟨64⟩ :: - feeGrowthInside1 :: feeGrowthInside0 :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - ⟨19527⟩ :: - feeGrowthInside1 :: feeGrowthInside0 :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord - (σLockedEvm) I ⟨2⟩ :: - solcSlotWord - (σLockedEvm) I ⟨1⟩ :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - slot0TickReturnWord - (σLockedEvm) I :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnPositionUpdateMem1 - (σLockedEvm) I - (solcSlotWord - (σLockedEvm) I - (burnPositionBaseSlotWord - (σLockedEvm) I))) - (UInt256.ofNat 18) ByteArray.empty - (cA, - σLockedEvm) k' C' := by - intro hzero - obtain ⟨_, _, feeGrowthInside1, feeGrowthInside0, hrdSlot0⟩ := - hrdPositionUpdateSlot0OfZero hzero - have hpackedResult := - (uniswapV3PoolBurnPositionUpdateStoreSlot0Packed - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (pos0 := solcSlotWord - (σLockedEvm) I - (burnPositionBaseSlotWord - (σLockedEvm) I)) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (delta := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (posBase := burnPositionBaseSlotWord - (σLockedEvm) I) - (retPos := ⟨19527⟩) - (inside1' := feeGrowthInside1) (inside0' := feeGrowthInside0) - (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord - (σLockedEvm) I ⟨2⟩) - (fee0 := solcSlotWord - (σLockedEvm) I ⟨1⟩) - (posBase' := burnPositionBaseSlotWord - (σLockedEvm) I) - (tick := slot0TickReturnWord - (σLockedEvm) I) - (delta' := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (ret := ⟨16428⟩) - (free := ⟨256⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - hpatch hrdSlot0 - (by simp only [List.length_cons, List.length_nil]; omega)) - obtain ⟨_, _, hrdPacked⟩ := hpackedResult - exact ⟨_, _, _, _, hrdPacked⟩ - have hrdPositionUpdateFeeGrowthInside0LastOfZero : - burnAmountCleanWord I = ⟨0⟩ → - ∃ k' C' feeGrowthInside1 feeGrowthInside0, - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨21595⟩ - (burnPositionUpdateSlot0Mask :: - burnPositionKeyNewFreePtrWord :: ⟨64⟩ :: - feeGrowthInside1 :: feeGrowthInside0 :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - ⟨19527⟩ :: - feeGrowthInside1 :: feeGrowthInside0 :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord - (σLockedEvm) I ⟨2⟩ :: - solcSlotWord - (σLockedEvm) I ⟨1⟩ :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - slot0TickReturnWord - (σLockedEvm) I :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnPositionUpdateMem2 - (σLockedEvm) I - (solcSlotWord - (σLockedEvm) I - (burnPositionBaseSlotWord - (σLockedEvm) I)) - (burnPositionBaseSlotWord - (σLockedEvm) I)) - (UInt256.ofNat 19) ByteArray.empty - (cA, - σLockedEvm) k' C' := by - intro hzero - obtain ⟨_, _, feeGrowthInside1, feeGrowthInside0, hrdPacked⟩ := - hrdPositionUpdatePackedSlot0OfZero hzero - have hfeeGrowthInside0Result := - (uniswapV3PoolBurnPositionUpdateStoreFeeGrowthInside0Last - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (delta := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (posBase := burnPositionBaseSlotWord - (σLockedEvm) I) - (retPos := ⟨19527⟩) - (inside1' := feeGrowthInside1) (inside0' := feeGrowthInside0) - (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord - (σLockedEvm) I ⟨2⟩) - (fee0 := solcSlotWord - (σLockedEvm) I ⟨1⟩) - (posBase' := burnPositionBaseSlotWord - (σLockedEvm) I) - (tick := slot0TickReturnWord - (σLockedEvm) I) - (delta' := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (ret := ⟨16428⟩) - (free := ⟨256⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - hpatch hrdPacked - (by simp only [List.length_cons, List.length_nil]; omega)) - obtain ⟨_, _, hrdFeeGrowthInside0⟩ := hfeeGrowthInside0Result - exact ⟨_, _, _, _, hrdFeeGrowthInside0⟩ - have hrdPositionUpdateFeeGrowthInside1LastOfZero : - burnAmountCleanWord I = ⟨0⟩ → - ∃ k' C' feeGrowthInside1 feeGrowthInside0, - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨21607⟩ - (burnPositionKeyNewFreePtrWord :: - burnPositionUpdateSlot0Mask :: - feeGrowthInside1 :: feeGrowthInside0 :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - ⟨19527⟩ :: - feeGrowthInside1 :: feeGrowthInside0 :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord - (σLockedEvm) I ⟨2⟩ :: - solcSlotWord - (σLockedEvm) I ⟨1⟩ :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - slot0TickReturnWord - (σLockedEvm) I :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnPositionUpdateMem3 - (σLockedEvm) I - (solcSlotWord - (σLockedEvm) I - (burnPositionBaseSlotWord - (σLockedEvm) I)) - (burnPositionBaseSlotWord - (σLockedEvm) I)) - (UInt256.ofNat 20) ByteArray.empty - (cA, - σLockedEvm) k' C' := by - intro hzero - obtain ⟨_, _, feeGrowthInside1, feeGrowthInside0, hrdFeeGrowthInside0⟩ := - hrdPositionUpdateFeeGrowthInside0LastOfZero hzero - have hfeeGrowthInside1Result := - (uniswapV3PoolBurnPositionUpdateStoreFeeGrowthInside1Last - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (delta := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (posBase := burnPositionBaseSlotWord - (σLockedEvm) I) - (retPos := ⟨19527⟩) - (inside1' := feeGrowthInside1) (inside0' := feeGrowthInside0) - (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord - (σLockedEvm) I ⟨2⟩) - (fee0 := solcSlotWord - (σLockedEvm) I ⟨1⟩) - (posBase' := burnPositionBaseSlotWord - (σLockedEvm) I) - (tick := slot0TickReturnWord - (σLockedEvm) I) - (delta' := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (ret := ⟨16428⟩) - (free := ⟨256⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - hpatch hrdFeeGrowthInside0 - (by simp only [List.length_cons, List.length_nil]; omega)) - obtain ⟨_, _, hrdFeeGrowthInside1⟩ := hfeeGrowthInside1Result - exact ⟨_, _, _, _, hrdFeeGrowthInside1⟩ - have hrdPositionUpdateTokensOwed0OfZero : - burnAmountCleanWord I = ⟨0⟩ → - ∃ k' C' feeGrowthInside1 feeGrowthInside0, - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨21620⟩ - (solcSlotWord - (σLockedEvm) I - (burnPositionBaseSlotWord - (σLockedEvm) I + (⟨3⟩ : UInt256)) :: - burnPositionKeyNewFreePtrWord :: - burnPositionUpdateSlot0Mask :: - feeGrowthInside1 :: feeGrowthInside0 :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - ⟨19527⟩ :: - feeGrowthInside1 :: feeGrowthInside0 :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord - (σLockedEvm) I ⟨2⟩ :: - solcSlotWord - (σLockedEvm) I ⟨1⟩ :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - slot0TickReturnWord - (σLockedEvm) I :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnPositionUpdateMem4 - (σLockedEvm) I - (solcSlotWord - (σLockedEvm) I - (burnPositionBaseSlotWord - (σLockedEvm) I)) - (burnPositionBaseSlotWord - (σLockedEvm) I)) - (UInt256.ofNat 21) ByteArray.empty - (cA, - σLockedEvm) k' C' := by - intro hzero - obtain ⟨_, _, feeGrowthInside1, feeGrowthInside0, hrdFeeGrowthInside1⟩ := - hrdPositionUpdateFeeGrowthInside1LastOfZero hzero - have htokensOwed0Result := - (uniswapV3PoolBurnPositionUpdateStoreTokensOwed0 - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (delta := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (posBase := burnPositionBaseSlotWord - (σLockedEvm) I) - (retPos := ⟨19527⟩) - (inside1' := feeGrowthInside1) (inside0' := feeGrowthInside0) - (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord - (σLockedEvm) I ⟨2⟩) - (fee0 := solcSlotWord - (σLockedEvm) I ⟨1⟩) - (posBase' := burnPositionBaseSlotWord - (σLockedEvm) I) - (tick := slot0TickReturnWord - (σLockedEvm) I) - (delta' := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (ret := ⟨16428⟩) - (free := ⟨256⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - hpatch hrdFeeGrowthInside1 - (by simp only [List.length_cons, List.length_nil]; omega)) - obtain ⟨_, _, hrdTokensOwed0⟩ := htokensOwed0Result - exact ⟨_, _, _, _, hrdTokensOwed0⟩ - have hrdPositionUpdateTokensOwed1OfZero : - burnAmountCleanWord I = ⟨0⟩ → - ∃ k' C' feeGrowthInside1 feeGrowthInside0, - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨21635⟩ - (burnPositionKeyNewFreePtrWord :: - feeGrowthInside1 :: feeGrowthInside0 :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - ⟨19527⟩ :: - feeGrowthInside1 :: feeGrowthInside0 :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord - (σLockedEvm) I ⟨2⟩ :: - solcSlotWord - (σLockedEvm) I ⟨1⟩ :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - slot0TickReturnWord - (σLockedEvm) I :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnPositionUpdateMem5 - (σLockedEvm) I - (solcSlotWord - (σLockedEvm) I - (burnPositionBaseSlotWord - (σLockedEvm) I)) - (burnPositionBaseSlotWord - (σLockedEvm) I)) - (UInt256.ofNat 22) ByteArray.empty - (cA, - σLockedEvm) k' C' := by - intro hzero - obtain ⟨_, _, feeGrowthInside1, feeGrowthInside0, hrdTokensOwed0⟩ := - hrdPositionUpdateTokensOwed0OfZero hzero - have htokensOwed1Result := - (uniswapV3PoolBurnPositionUpdateStoreTokensOwed1 - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (delta := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (posBase := burnPositionBaseSlotWord - (σLockedEvm) I) - (retPos := ⟨19527⟩) - (inside1' := feeGrowthInside1) (inside0' := feeGrowthInside0) - (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord - (σLockedEvm) I ⟨2⟩) - (fee0 := solcSlotWord - (σLockedEvm) I ⟨1⟩) - (posBase' := burnPositionBaseSlotWord - (σLockedEvm) I) - (tick := slot0TickReturnWord - (σLockedEvm) I) - (delta' := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (ret := ⟨16428⟩) - (free := ⟨256⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - hpatch hrdTokensOwed0 - (by simp only [List.length_cons, List.length_nil]; omega)) - obtain ⟨_, _, hrdTokensOwed1⟩ := htokensOwed1Result - exact ⟨_, _, _, _, hrdTokensOwed1⟩ - have hrdPositionUpdateDeltaZeroFallthroughOfZero : - burnAmountCleanWord I = ⟨0⟩ → - ∃ k' C' feeGrowthInside1 feeGrowthInside0, - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨21646⟩ - (⟨0⟩ :: burnPositionKeyNewFreePtrWord :: - feeGrowthInside1 :: feeGrowthInside0 :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - ⟨19527⟩ :: - feeGrowthInside1 :: feeGrowthInside0 :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord - (σLockedEvm) I ⟨2⟩ :: - solcSlotWord - (σLockedEvm) I ⟨1⟩ :: - burnPositionBaseSlotWord - (σLockedEvm) I :: - slot0TickReturnWord - (σLockedEvm) I :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnPositionUpdateMem5 - (σLockedEvm) I - (solcSlotWord - (σLockedEvm) I - (burnPositionBaseSlotWord - (σLockedEvm) I)) - (burnPositionBaseSlotWord - (σLockedEvm) I)) - (UInt256.ofNat 22) ByteArray.empty - (cA, - σLockedEvm) k' C' := by - intro hzero - obtain ⟨_, _, feeGrowthInside1, feeGrowthInside0, hrdTokensOwed1⟩ := - hrdPositionUpdateTokensOwed1OfZero hzero - have hdelta : - UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) = ⟨0⟩ := by - rw [hzero] - native_decide - have hfallthroughResult := - (uniswapV3PoolBurnPositionUpdateLiquidityDeltaZeroFallthrough - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (delta := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (posBase := burnPositionBaseSlotWord - (σLockedEvm) I) - (retPos := ⟨19527⟩) - (inside1' := feeGrowthInside1) (inside0' := feeGrowthInside0) - (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord - (σLockedEvm) I ⟨2⟩) - (fee0 := solcSlotWord - (σLockedEvm) I ⟨1⟩) - (posBase' := burnPositionBaseSlotWord - (σLockedEvm) I) - (tick := slot0TickReturnWord - (σLockedEvm) I) - (delta' := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (ret := ⟨16428⟩) - (free := ⟨256⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - hpatch hdelta hrdTokensOwed1 - (by simp only [List.length_cons, List.length_nil]; omega)) - obtain ⟨_, _, hrdFallthrough⟩ := hfallthroughResult - exact ⟨_, _, _, _, hrdFallthrough⟩ - let lockedEvm : AccountMap := - σLockedEvm - let positionBase : UInt256 := burnPositionBaseSlotWord lockedEvm I - have hrdPositionUpdateLiquidityZeroFallthroughOfZero : - burnAmountCleanWord I = ⟨0⟩ → - burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase) = ⟨0⟩ → - ∃ k' C' feeGrowthInside1 feeGrowthInside0, - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨21661⟩ - (⟨0⟩ :: burnPositionKeyNewFreePtrWord :: - feeGrowthInside1 :: feeGrowthInside0 :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - positionBase :: ⟨19527⟩ :: - feeGrowthInside1 :: feeGrowthInside0 :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord lockedEvm I ⟨2⟩ :: - solcSlotWord lockedEvm I ⟨1⟩ :: - positionBase :: - slot0TickReturnWord lockedEvm I :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: - [solcSelectorWord I]) - (burnPositionUpdateMem5 lockedEvm I - (solcSlotWord lockedEvm I positionBase) positionBase) - (UInt256.ofNat 22) ByteArray.empty - (cA, lockedEvm) k' C' := by - intro hzero hliquidity - obtain ⟨_, _, feeGrowthInside1, feeGrowthInside0, hrdFallthrough⟩ := - hrdPositionUpdateDeltaZeroFallthroughOfZero hzero - obtain ⟨_, _, hrd21661⟩ := - (uniswapV3PoolBurnPositionUpdateLiquidityZeroFallthrough - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (delta := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (posBase := positionBase) (retPos := ⟨19527⟩) - (inside1' := feeGrowthInside1) (inside0' := feeGrowthInside0) - (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord lockedEvm I ⟨2⟩) - (fee0 := solcSlotWord lockedEvm I ⟨1⟩) - (posBase' := positionBase) - (tick := slot0TickReturnWord lockedEvm I) - (delta' := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (ret := ⟨16428⟩) - (free := ⟨256⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (σ := lockedEvm) - hpatch hliquidity - (by simpa [lockedEvm, positionBase] using hrdFallthrough) - (by simp only [List.length_cons, List.length_nil]; omega)) - exact ⟨_, _, feeGrowthInside1, feeGrowthInside0, hrd21661⟩ - have hrdPositionUpdateLiquidityZeroRevertOfZero : - burnAmountCleanWord I = ⟨0⟩ → - burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase) = ⟨0⟩ → - RDrev code (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) := by - intro hzero hliquidity - obtain ⟨_, _, feeGrowthInside1, feeGrowthInside0, hrd21661⟩ := - hrdPositionUpdateLiquidityZeroFallthroughOfZero hzero hliquidity - exact uniswapV3PoolBurnPositionUpdateNpRevertTail - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (pos0 := solcSlotWord lockedEvm I positionBase) - (posBase := positionBase) - (stk := ⟨0⟩ :: burnPositionKeyNewFreePtrWord :: - feeGrowthInside1 :: feeGrowthInside0 :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - positionBase :: ⟨19527⟩ :: - feeGrowthInside1 :: feeGrowthInside0 :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord lockedEvm I ⟨2⟩ :: - solcSlotWord lockedEvm I ⟨1⟩ :: - positionBase :: - slot0TickReturnWord lockedEvm I :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) (σ := lockedEvm) - hpatch - (by simpa using hrd21661) - (by simp only [List.length_cons, List.length_nil]; omega) - by_cases hzeroLiq : - burnAmountCleanWord I = ⟨0⟩ ∧ - burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase) = ⟨0⟩ - · rcases hzeroLiq with ⟨hzero, hliquidity⟩ - let lockedSolm : AccountMap := - σLockedSolm - have hAccountsLocked : accountMapEquiv lockedEvm lockedSolm := by - simpa [lockedEvm, lockedSolm] using hAccountsAfterLock - have hPositionBase : - positionBase = positionsBase (burnPositionKeyKey I) := by - simpa [positionBase] using - burnPositionBaseSlotWord_eq_positionsBase lockedEvm I - have hliqEvm : - burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I (positionsBase (burnPositionKeyKey I))) = - ⟨0⟩ := by - simpa [hPositionBase] using hliquidity - have hslotEq : - solcSlotWord lockedSolm I (positionsBase (burnPositionKeyKey I)) = - solcSlotWord lockedEvm I (positionsBase (burnPositionKeyKey I)) := by - have hslot := accountMapEquiv_storage_findD hAccountsLocked I.codeOwner - (positionsBase (burnPositionKeyKey I)) (⟨0⟩ : UInt256) - simpa [solcSlotWord] using hslot.symm - have hliqSolm : - burnPositionUpdateSlot0Packed - (solcSlotWord lockedSolm I (positionsBase (burnPositionKeyKey I))) = - ⟨0⟩ := by - rw [hslotEq] - exact hliqEvm - have hrd := hrdPositionUpdateLiquidityZeroRevertOfZero hzero hliquidity - have hbody := - uniswapV3PoolBurnSourcePositionUpdateLiquidityZeroReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm - hcanon hnoDelegate htickLt hLowerMin hUpperMax hzero - (by simpa [lockedSolm] using hliqSolm) - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · let positionUpdateR : List UInt256 := - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I] - by_cases hzero : burnAmountCleanWord I = ⟨0⟩ - · have hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase) ≠ ⟨0⟩ := by - intro hliqZero - exact hzeroLiq ⟨hzero, hliqZero⟩ - let feeGrowthInside1 := burnTickGetInside1Word lockedEvm I - let feeGrowthInside0 := burnTickGetInside0Word lockedEvm I - by_cases hprod0 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I - (positionBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase)) = ⟨0⟩ - · by_cases hprod1 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I - (positionBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase)) = ⟨0⟩ - · obtain ⟨_, _, hrdFeeGrowthEntry⟩ := hrdFeeGrowthInsideEntry hzero - obtain ⟨_, _, hrd21861⟩ := - uniswapV3PoolBurnZeroDeltaPositionUpdateToMulDivReturnConcrete - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) (σ := lockedEvm) - hpatch _hperm htickLt hzero - (by simpa [positionBase] using hliq) - (by simpa [feeGrowthInside0, positionBase] using hprod0) - (by simpa [feeGrowthInside1, positionBase] using hprod1) - (by simpa [lockedEvm, positionBase] using hrdFeeGrowthEntry) - (by simp only [List.length_singleton]; omega) - have hmload224 := burnPositionUpdateMem5_mload224 lockedEvm I - (solcSlotWord lockedEvm I positionBase) positionBase - have hdelta : - UInt256.slt - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))) - ⟨0⟩ = ⟨0⟩ := by - rw [hzero] - native_decide - have hdest9737 : - (D_J code 0).contains (⟨9737⟩ : UInt256) = true := by - have hpreserve : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode - uniswapV3PoolPatchOffsets (⟨9737⟩ : UInt256) 0 = - true := by - native_decide - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) hpreserve - have hrdSuccessCases := - uniswapV3PoolBurnZeroDeltaPositionUpdateToFinalReturnCases - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (tokensOwed1 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I - (positionBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft ⟨1⟩ ⟨128⟩)) - (tokensOwed0 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I - (positionBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft ⟨1⟩ ⟨128⟩)) - (liquidity := burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase)) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (delta := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (posBase := positionBase) - (inside1' := feeGrowthInside1) (inside0' := feeGrowthInside0) - (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord lockedEvm I ⟨2⟩) - (fee0 := solcSlotWord lockedEvm I ⟨1⟩) - (tick := slot0TickReturnWord lockedEvm I) - (delta' := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (free := ⟨256⟩) (r3 := ⟨0⟩) - (amount := burnAmountCleanWord I) (eventUpper := burnTickUpperCleanWord I) - (eventLower := burnTickLowerCleanWord I) (R := [solcSelectorWord I]) - (σmem := lockedEvm) (pos0 := solcSlotWord lockedEvm I positionBase) - (rdata := ByteArray.empty) (cA := cA) - (σ := sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner lockedEvm - (positionBase + (⟨1⟩ : UInt256)) feeGrowthInside0) - (positionBase + (⟨2⟩ : UInt256)) feeGrowthInside1) - hpatch hdest9737 _hperm hzero hmload224 - (by simpa [positionUpdateR] using hrd21861) hdelta - (by simp only [List.length_singleton]; omega) - let tokensOwed0 : UInt256 := - UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I - (positionBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft ⟨1⟩ ⟨128⟩) - let tokensOwed1 : UInt256 := - UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I - (positionBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft ⟨1⟩ ⟨128⟩) - have hlow0 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I - (positionBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 := by - rfl - have hlow1 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I - (positionBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 := by - rfl - exact - uniswapV3PoolBurnZeroDeltaPositionUpdateFinish - (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) - (lockedEvm := lockedEvm) (lockedSolm := σLockedSolm) - (A := A) (I := I) (g := g) - (tokensOwed0 := tokensOwed0) (tokensOwed1 := tokensOwed1) - (feeGrowthInside0 := feeGrowthInside0) - (feeGrowthInside1 := feeGrowthInside1) - (positionBase := positionBase) (code := code) - hcode hdispatch hdecode hwv hunlockedSolm hcanon hnoDelegate - htickLt hLowerMin hUpperMax hzero - (by simpa [lockedEvm] using hAccountsAfterLock) - (by rfl) (by rfl) (by rfl) - (by - simpa [positionBase] using - burnPositionBaseSlotWord_eq_positionsBase lockedEvm I) - (by simpa [positionBase] using hliq) - hlow0 hlow1 - (by - simpa [tokensOwed0, tokensOwed1, lockedEvm] - using hrdSuccessCases) - · obtain ⟨_, _, hrdFeeGrowthEntry⟩ := hrdFeeGrowthInsideEntry hzero - have hliqBound : - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase)).toNat < - 2 ^ (128 : Nat) := by - change - (UInt256.land burnPositionUpdateSlot0Mask - (solcSlotWord lockedEvm I positionBase)).toNat < - 2 ^ (128 : Nat) - rw [burnPositionUpdateSlot0Mask_eq_uint128Mask] - rw [u256_land_comm] - simpa [EVM.twoPow] using - uint128Mask_bound (solcSlotWord lockedEvm I positionBase) - have hden : - UInt256.gt (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I - (positionBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) ≠ ⟨0⟩ := by - exact uniswapV3PoolFullMathMulDivProd1DenGtQ128 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I - (positionBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase)) - hliqBound - obtain ⟨_, _, hrd21861⟩ := - uniswapV3PoolBurnZeroDeltaPositionUpdateToMulDivReturnConcreteSlowToken1 - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) (σ := lockedEvm) - hpatch _hperm htickLt hzero - (by simpa [positionBase] using hliq) - (by simpa [feeGrowthInside0, positionBase] using hprod0) - (by - intro hprod1Zero - exact hprod1 (by - simpa [feeGrowthInside1, positionBase] using hprod1Zero)) - (by simpa [feeGrowthInside1, positionBase] using hden) - (by simpa [lockedEvm, positionBase] using hrdFeeGrowthEntry) - (by simp only [List.length_singleton]; omega) - have hmload224 := burnPositionUpdateMem5_mload224 lockedEvm I - (solcSlotWord lockedEvm I positionBase) positionBase - have hdelta : - UInt256.slt - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))) - ⟨0⟩ = ⟨0⟩ := by - rw [hzero] - native_decide - have hdest9737 : - (D_J code 0).contains (⟨9737⟩ : UInt256) = true := by - have hpreserve : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode - uniswapV3PoolPatchOffsets (⟨9737⟩ : UInt256) 0 = - true := by - native_decide - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) hpreserve - let tokensOwed0 : UInt256 := - UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I - (positionBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft ⟨1⟩ ⟨128⟩) - let tokensOwed1 : UInt256 := - uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I - (positionBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I - (positionBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase)) - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I - (positionBase + (⟨2⟩ : UInt256)))) - have hrdSuccessCases := - uniswapV3PoolBurnZeroDeltaPositionUpdateToFinalReturnCases - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase)) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (delta := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (posBase := positionBase) - (inside1' := feeGrowthInside1) (inside0' := feeGrowthInside0) - (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord lockedEvm I ⟨2⟩) - (fee0 := solcSlotWord lockedEvm I ⟨1⟩) - (tick := slot0TickReturnWord lockedEvm I) - (delta' := UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (free := ⟨256⟩) (r3 := ⟨0⟩) - (amount := burnAmountCleanWord I) (eventUpper := burnTickUpperCleanWord I) - (eventLower := burnTickLowerCleanWord I) (R := [solcSelectorWord I]) - (σmem := lockedEvm) (pos0 := solcSlotWord lockedEvm I positionBase) - (rdata := ByteArray.empty) (cA := cA) - (σ := sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner lockedEvm - (positionBase + (⟨1⟩ : UInt256)) feeGrowthInside0) - (positionBase + (⟨2⟩ : UInt256)) feeGrowthInside1) - hpatch hdest9737 _hperm hzero hmload224 - (by simpa [positionUpdateR, tokensOwed0, tokensOwed1] using hrd21861) - hdelta - (by simp only [List.length_singleton]; omega) - have hlow0 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I - (positionBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 := by - rfl - have hlow1 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I - (positionBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 := by - simpa [tokensOwed1] using - (uniswapV3PoolFullMathMulDivSlowResult_low128_eq_prod0Div128 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I - (positionBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))).symm - exact - uniswapV3PoolBurnZeroDeltaPositionUpdateFinish - (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) - (lockedEvm := lockedEvm) (lockedSolm := σLockedSolm) - (A := A) (I := I) (g := g) - (tokensOwed0 := tokensOwed0) (tokensOwed1 := tokensOwed1) - (feeGrowthInside0 := feeGrowthInside0) - (feeGrowthInside1 := feeGrowthInside1) - (positionBase := positionBase) (code := code) - hcode hdispatch hdecode hwv hunlockedSolm hcanon hnoDelegate - htickLt hLowerMin hUpperMax hzero - (by simpa [lockedEvm] using hAccountsAfterLock) - (by rfl) (by rfl) (by rfl) - (by - simpa [positionBase] using - burnPositionBaseSlotWord_eq_positionsBase lockedEvm I) - (by simpa [positionBase] using hliq) - hlow0 hlow1 - (by - simpa [tokensOwed0, tokensOwed1, lockedEvm] - using hrdSuccessCases) - · obtain ⟨_, _, hrdFeeGrowthEntry⟩ := hrdFeeGrowthInsideEntry hzero - exact - uniswapV3PoolBurnZeroDeltaPositionUpdateSlowToken0Runtime - (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) - (lockedEvm := lockedEvm) (lockedSolm := σLockedSolm) - (A := A) (I := I) (g := g) (code := code) - hpatch hcode _hperm hdispatch hdecode hwv hunlockedSolm - hcanon hnoDelegate htickLt hLowerMin hUpperMax hzero - (by simpa [lockedEvm] using hAccountsAfterLock) - (by rfl) - (by simpa [positionBase] using hliq) - (by - intro hprod0Zero - exact hprod0 (by - simpa [feeGrowthInside0, positionBase] using hprod0Zero)) - (by simpa [lockedEvm, positionBase] using hrdFeeGrowthEntry) - · have hnonzeroCond : - UInt256.isZero - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))) = ⟨0⟩ := - burnLiquidityDeltaNonzeroJumpCond I hcanon hzero - obtain ⟨_, _, _hrdAfterTimestamp⟩ := - uniswapV3PoolBurnAfterFeeGlobalsNonzeroToTimestampReturn - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) (σ := σLockedEvm) - hpatch hnonzeroCond hrdFeeGlobalsBranchTest - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, _hrdSlot0Liquidity⟩ := - uniswapV3PoolBurnAfterFeeGlobalsNonzeroTimestampToSlot0LiquidityLoaded - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) (σ := σLockedEvm) - hpatch _hrdAfterTimestamp - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, _hrdObserveSingleEntry⟩ := - uniswapV3PoolBurnAfterFeeGlobalsNonzeroSlot0LiquidityToObserveSingleEntry - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) (σ := σLockedEvm) - hpatch _hrdSlot0Liquidity - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, _hrdObserveSingleZero⟩ := - uniswapV3PoolBurnObserveSingleSecondsAgoZeroFallthrough - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (memPtr := ⟨8⟩) (ret := ⟨19273⟩) - (R := - ⟨0⟩ :: ⟨0⟩ :: UInt256.ofNat I.header.timestamp :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σLockedEvm I ⟨2⟩ :: - solcSlotWord σLockedEvm I ⟨1⟩ :: - burnPositionBaseSlotWord σLockedEvm I :: - slot0TickReturnWord σLockedEvm I :: - UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (mem := burnPositionKeyMappingMem σLockedEvm I) - (aw := UInt256.ofNat 18) - (rdata := ByteArray.empty) (cA := cA) (σ := σLockedEvm) - hpatch _hrdObserveSingleEntry - (by simp only [List.length_cons, List.length_nil]; omega) - by_cases hobsBound : - (slot0ObservationIndexWord σLockedEvm I).toNat < 65535 - · have hidxLt16 : - (slot0ObservationIndexWord σLockedEvm I).toNat < EVM.twoPow 16 := by - simpa [slot0ObservationIndexWord] using - slot0Uint16Mask_bound - (UInt256.div (slot0SlotWord σLockedEvm I) (slot0ShiftBytes 23)) - have hmaskIndex : - UInt256.land (⟨65535⟩ : UInt256) - (slot0ObservationIndexWord σLockedEvm I) = - slot0ObservationIndexWord σLockedEvm I := by - rw [show (⟨65535⟩ : UInt256) = slot0Uint16Mask by native_decide] - exact slot0Uint16Mask_clean_left hidxLt16 - have hlt : - UInt256.lt - ((⟨65535⟩ : UInt256).land - (slot0ObservationIndexWord σLockedEvm I)) - ⟨65535⟩ = ⟨1⟩ := by - rw [hmaskIndex] - apply ult_one - rw [show (⟨65535⟩ : UInt256).toNat = 65535 by native_decide] - exact hobsBound - obtain ⟨_, _, _hrdObserveSingleInBounds⟩ := - uniswapV3PoolBurnObserveSingleIndexInBoundsJump - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - hpatch _hrdObserveSingleZero - (by - have hlt' : - UInt256.lt - ((⟨65535⟩ : UInt256).land - ((⟨65535⟩ : UInt256).land - ((solcSlotWord σLockedEvm I ⟨0⟩).div - ((⟨1⟩ : UInt256).shiftLeft ⟨184⟩)))) - ⟨65535⟩ = ⟨1⟩ := by - simpa [slot0ObservationIndexWord, slot0SlotWord, - slot0Uint16Mask, u256_land_comm] using hlt - rw [hlt'] - decide) - (by simp only [List.length_cons, List.length_nil]; omega) - obtain ⟨_, _, _hrdObserveSingleLoaded⟩ := - uniswapV3PoolBurnObserveSingleLoadObservation - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (σ := σLockedEvm) hpatch _hrdObserveSingleInBounds - (by simp only [List.length_cons, List.length_nil]; omega) - let obsWord := burnObserveSingleLoadedObsWord σLockedEvm I - have hobsWord : - obsWord = burnObserveSingleSlotWord σLockedEvm I := by - simpa [obsWord] using - burnObserveSingleLoadedObsWord_eq σLockedEvm I hidxLt16 - have hsourceObserveStepOfEq := fun (heq : UInt256.eq - (UInt256.land (UInt256.ofNat I.header.timestamp) - observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩) => - uniswapV3PoolModifyPositionSourceObserveSingleTimestampEqualStep - (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ := σLockedSolm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) - (by - rw [← burnObserveSingleObservationIndexWord_transport - hAccountsAfterLock] - exact hobsBound) - (burnObserveSingleSourceTimestampEqOfGuard - hAccountsAfterLock hobsWord heq) - have hrdLowerTickUpdateEntryOfEq := fun (heq : UInt256.eq - (UInt256.land (UInt256.ofNat I.header.timestamp) - observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩) => - uniswapV3PoolBurnObserveSingleTimestampEqualToLowerTickUpdate - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - (obsWord := obsWord) - (time := UInt256.ofNat I.header.timestamp) - (callerTime := UInt256.ofNat I.header.timestamp) - (rdata := ByteArray.empty) (cA := cA) (σ := σLockedEvm) - hpatch - (by simpa [obsWord, burnObserveSingleLoadedObsWord] - using _hrdObserveSingleLoaded) - heq - (by simp only [List.length_cons, List.length_nil]; omega) - have hrdLiquidityAddDeltaEntryOfEq := fun (heq : UInt256.eq - (UInt256.land (UInt256.ofNat I.header.timestamp) - observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩) => - Exists.elim (hrdLowerTickUpdateEntryOfEq heq) fun _ hk => - Exists.elim hk fun _ hrdLowerTickUpdateEntry => - uniswapV3PoolBurnTickUpdateLowerToLiquidityAddDelta - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (rdata := ByteArray.empty) (cA := cA) (σ := σLockedEvm) hpatch hrdLowerTickUpdateEntry - (by - rw [burnObserveSingleDecodedMem_size σLockedEvm I obsWord] - native_decide) - (by simp only [List.length_cons, List.length_nil]; omega) - exact uniswapV3PoolBurnLowerLiquidityAddDeltaBranch hpatch hcode hwv hdispatch hdecode hunlockedSolm hcanon hnoDelegate htickLt hLowerMin hUpperMax hzero hAccountsAfterLock hobsBound hobsWord hrdLiquidityAddDeltaEntryOfEq - · have hoobEvm : - 65535 ≤ (slot0ObservationIndexWord σLockedEvm I).toNat := - Nat.le_of_not_gt hobsBound - have hidxLt16 : - (slot0ObservationIndexWord σLockedEvm I).toNat < EVM.twoPow 16 := by - simpa [slot0ObservationIndexWord] using - slot0Uint16Mask_bound - (UInt256.div (slot0SlotWord σLockedEvm I) (slot0ShiftBytes 23)) - have hmaskIndex : - UInt256.land (⟨65535⟩ : UInt256) - (slot0ObservationIndexWord σLockedEvm I) = - slot0ObservationIndexWord σLockedEvm I := by - rw [show (⟨65535⟩ : UInt256) = slot0Uint16Mask by native_decide] - exact slot0Uint16Mask_clean_left hidxLt16 - have hlt : - UInt256.lt - ((⟨65535⟩ : UInt256).land - (slot0ObservationIndexWord σLockedEvm I)) - ⟨65535⟩ = ⟨0⟩ := by - rw [hmaskIndex] - apply ult_zero - rw [show (⟨65535⟩ : UInt256).toNat = 65535 by native_decide] - exact hoobEvm - have hinvalidOr := - uniswapV3PoolBurnObserveSingleIndexOobInvalid - (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ - (Sat256.ofUInt256 g) A I) - hpatch _hrdObserveSingleZero - (by - simpa [slot0ObservationIndexWord, slot0SlotWord, - slot0Uint16Mask, u256_land_comm] using hlt) - (by simp only [List.length_cons, List.length_nil]; omega) - have hidxEq : - slot0ObservationIndexWord σLockedEvm I = - slot0ObservationIndexWord σLockedSolm I := by - unfold slot0ObservationIndexWord slot0SlotWord - rw [solcSlotWord_eq_of_accountMapEquiv hAccountsAfterLock I ⟨0⟩] - have hoobSolm : - 65535 ≤ (slot0ObservationIndexWord σLockedSolm I).toNat := by - rw [← hidxEq] - exact hoobEvm - have hbody := uniswapV3PoolBurnSourceObserveSingleOobReverts - (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv hunlockedSolm hcanon - hnoDelegate htickLt hLowerMin hUpperMax hzero - (by simpa [σLockedSolm] using hoobSolm) - rcases hinvalidOr with hoog | hinvalid - · exact reEquiv_outOfGas (Xi_error_of_X (g := g) (by - rw [← hcode] at hoog - simpa [initState, Sat256.ofUInt256] using hoog)) - · have hxi : - Ξ cA gh bl σ_evm σ₀ g A I = - .error .InvalidInstruction := - Xi_error_of_X (g := g) (by - rw [← hcode] at hinvalid - simpa [initState, Sat256.ofUInt256] using hinvalid) - exact reEquiv_execution hdispatch hdecode hbody - (execResultsEquiv.invalidHalt hxi rfl) - · have hzero := burnTickLtSlt_eq_zero I htickLt - have hrd := uniswapV3PoolBurnCheckTicksLtRevert (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨16264⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (mem := burnModifyPositionMem4 I) (aw := UInt256.ofNat 8) - (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) - hpatch hrdCheckTicksWords hzero rfl rfl - (by simp only [List.length_cons, List.length_nil]; omega) - have hbody := uniswapV3PoolBurnSourceTickLtReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm hcanon - hnoDelegate htickLt - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hnoDelegateZero : uniswapV3PoolNoDelegateCallGuard v I = ⟨0⟩ := by - by_contra hne - exact hnoDelegate hne - have hrd := uniswapV3PoolBurnNoDelegateCallRevert (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (cA := cA) - (σ := σLockedEvm) - hpatch hrdLiquidityDeltaWritten hnoDelegateZero - (by simp only [List.length_cons, List.length_nil]; omega) - have hbody := uniswapV3PoolBurnSourceNoDelegateReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm hcanon hnoDelegateZero - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hcheck : - UInt256.eq (burnAmountCleanWord I) - (UInt256.signextend ⟨15⟩ (burnAmountCleanWord I)) = ⟨0⟩ := by - apply uInt256_eq_zero_of_ne - intro heqOne - exact hcanon (uInt256_eq_one_eq heqOne).symm - have hrd := uniswapV3PoolBurnLiquidityDeltaInt128Revert (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (cA := cA) - (σ := σLockedEvm) - hpatch hrdLiquidityDeltaPrep hcheck - (by simp only [List.length_cons, List.length_nil]; omega) - have hbody := uniswapV3PoolBurnSourceLiquidityDeltaReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm hcanon - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hlockedEvm : burnUnlockedByte σ_evm I = ⟨0⟩ := by - by_contra hne - exact hunlocked hne - have hlockedSolm : burnUnlockedByte σ_solm I = ⟨0⟩ := by - rw [burnUnlockedByte_transport (σ_evm := σ_evm) (σ_solm := σ_solm) - hAccounts] - exact hlockedEvm - have hbody := uniswapV3PoolBurnSourceLockedReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hwv hlockedSolm - have hrd := uniswapV3PoolBurnLockEnterLockedRevert (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (amount := burnAmountCleanWord I) (upper := burnTickUpperCleanWord I) - (lower := burnTickLowerCleanWord I) (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) (σ := σ_evm) - hpatch hrdModifyPosition hlockedEvm - (by simp only [List.length_cons, List.length_nil]; omega) - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hshort : I.calldata.size < 100 := by omega - have hdecode := uniswapV3PoolBurnDecodeShort (v := v) (I := I) hshort - have hrd := uniswapV3PoolBurnEvmDecodeShort (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hshort - exact hrd.reEquivDecodingFailed hcode hdispatch hdecode - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnCheckTicks.lean b/Benchmarks/UniswapV3Pool/BurnCheckTicks.lean deleted file mode 100644 index 1e81e5be..00000000 --- a/Benchmarks/UniswapV3Pool/BurnCheckTicks.lean +++ /dev/null @@ -1,1940 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnNoDelegate - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev burnModifyPositionMload (I : ExecutionEnv) (off : UInt256) : UInt256 := - if off.toNat ≥ (burnModifyPositionMem4 I).size ∨ off ≥ UInt256.ofNat 8 * ⟨32⟩ then - ⟨0⟩ - else - UInt256.ofNat - (fromByteArrayBigEndian ((burnModifyPositionMem4 I).readWithPadding off.toNat 32)) - -abbrev burnModifyPositionTickLowerLoad (I : ExecutionEnv) : UInt256 := - burnModifyPositionMload I ⟨160⟩ - -abbrev burnModifyPositionTickUpperLoad (I : ExecutionEnv) : UInt256 := - burnModifyPositionMload I ⟨192⟩ - -abbrev burnModifyPositionFreePtrLoad (I : ExecutionEnv) : UInt256 := - burnModifyPositionMload I ⟨64⟩ - -private theorem burnModifyPositionMem0_size : - burnModifyPositionMem0.size = 96 := by - unfold burnModifyPositionMem0 - change ((UInt256.toByteArray (⟨256⟩ : UInt256)).write 0 solcFreePtrMem 64 32).size = 96 - exact toByteArray_write32_size_of_le solcFreePtrMem (⟨256⟩ : UInt256) 64 96 96 - solcFreePtrMem_size (by rw [solcFreePtrMem_size]; omega) (by omega) - -private theorem burnModifyPositionMem0_read64 : - burnModifyPositionMem0.readWithPadding 64 32 = UInt256.toByteArray ⟨256⟩ := by - unfold burnModifyPositionMem0 - change ((UInt256.toByteArray (⟨256⟩ : UInt256)).write 0 solcFreePtrMem 64 32).readWithPadding 64 32 = - UInt256.toByteArray ⟨256⟩ - exact toByteArray_write_read_back_of_gap (⟨256⟩ : UInt256) solcFreePtrMem 64 - (by rw [solcFreePtrMem_size]; native_decide) - -private theorem burnModifyPositionMem4_cascadeFromMem0 (I : ExecutionEnv) : - burnModifyPositionMem4 I = - writeCascade burnModifyPositionMem0 - [(128, UInt256.ofNat I.source.val), - (160, UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)), - (192, UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)), - (224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] := by - rfl - -theorem burnModifyPositionMem4_size (I : ExecutionEnv) : - (burnModifyPositionMem4 I).size = 256 := by - rw [burnModifyPositionMem4_cascadeFromMem0] - exact writeCascade_size_of_base burnModifyPositionMem0 _ burnModifyPositionMem0_size - (by simp [WriteGapsOk]; native_decide) (by simp [writeCascadeSize]) - -theorem burnModifyPositionMem4_read64 (I : ExecutionEnv) : - (burnModifyPositionMem4 I).readWithPadding 64 32 = UInt256.toByteArray ⟨256⟩ := by - rw [burnModifyPositionMem4_cascadeFromMem0] - rw [writeCascade_read_preserved_of_base burnModifyPositionMem0 (base := 96)] - exact burnModifyPositionMem0_read64 - · exact burnModifyPositionMem0_size - · simp [WindowDisjointFromWrites] - native_decide - -theorem burnModifyPositionFreePtrLoad_eq (I : ExecutionEnv) : - burnModifyPositionFreePtrLoad I = ⟨256⟩ := by - unfold burnModifyPositionFreePtrLoad burnModifyPositionMload - exact mloadWordValue_of_readWithPadding - (mem := burnModifyPositionMem4 I) (aw := UInt256.ofNat 8) (off := ⟨64⟩) - (v := ⟨256⟩) (by rw [burnModifyPositionMem4_size I]; native_decide) - (by native_decide) (burnModifyPositionMem4_read64 I) - -private theorem writeCascade_size_ge_base - (mem : ByteArray) (writes : List (Nat × UInt256)) - (hok : WriteGapsOk mem.size writes) : - mem.size ≤ (writeCascade mem writes).size := by - induction writes generalizing mem with - | nil => simp [writeCascade] - | cons write rest ih => - rcases write with ⟨off, word⟩ - rcases hok with ⟨hgap, hrest⟩ - rw [writeCascade_cons] - have hsize : (writeWord mem off word).size = max mem.size (off + 32) := - writeWord_size mem off word hgap - have hrec : - (writeWord mem off word).size ≤ - (writeCascade (writeWord mem off word) rest).size := by - exact ih (writeWord mem off word) (by simpa [hsize] using hrest) - have hbase : mem.size ≤ (writeWord mem off word).size := by - rw [hsize] - exact Nat.le_max_left _ _ - exact le_trans hbase hrec - -private theorem burnModifyPositionMem4_cascadeFromMem1 (I : ExecutionEnv) : - burnModifyPositionMem4 I = - writeCascade (burnModifyPositionMem1 I) - [(160, UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)), - (192, UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)), - (224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] := by - rfl - -private theorem burnModifyPositionMem4_cascadeFromMem2 (I : ExecutionEnv) : - burnModifyPositionMem4 I = - writeCascade (burnModifyPositionMem2 I) - [(192, UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)), - (224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] := by - rfl - -private theorem burnModifyPositionLaterWritesLowerDisjoint (I : ExecutionEnv) : - WindowDisjointFromWrites - (max (burnModifyPositionMem1 I).size (160 + 32)) 160 32 - [(192, UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)), - (224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] := by - simp [WindowDisjointFromWrites] - -private theorem burnModifyPositionLaterWritesUpperDisjoint (I : ExecutionEnv) : - WindowDisjointFromWrites - (max (burnModifyPositionMem2 I).size (192 + 32)) 192 32 - [(224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] := by - simp [WindowDisjointFromWrites] - -private theorem burnModifyPositionLowerRestGapsOk (I : ExecutionEnv) : - WriteGapsOk - (writeWord (burnModifyPositionMem1 I) 160 - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))).size - [(192, UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)), - (224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] := by - have hsize : - (writeWord (burnModifyPositionMem1 I) 160 - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))).size = - max (burnModifyPositionMem1 I).size (160 + 32) := by - exact writeWord_size _ _ _ (lt_usize _ (by omega)) - simp [WriteGapsOk, hsize] - -private theorem burnModifyPositionUpperRestGapsOk (I : ExecutionEnv) : - WriteGapsOk - (writeWord (burnModifyPositionMem2 I) 192 - (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))).size - [(224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] := by - have hsize : - (writeWord (burnModifyPositionMem2 I) 192 - (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))).size = - max (burnModifyPositionMem2 I).size (192 + 32) := by - exact writeWord_size _ _ _ (lt_usize _ (by omega)) - simp [WriteGapsOk, hsize] - -theorem burnModifyPositionTickLowerLoad_eq (I : ExecutionEnv) : - burnModifyPositionTickLowerLoad I = - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) := by - unfold burnModifyPositionTickLowerLoad burnModifyPositionMload - rw [burnModifyPositionMem4_cascadeFromMem1] - exact writeCascade_mload_word_of_head (mem := burnModifyPositionMem1 I) (off := 160) - (offWord := (⟨160⟩ : UInt256)) (aw := UInt256.ofNat 8) - (word := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (rest := [(192, UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)), - (224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))]) - (lt_usize _ (by omega)) (burnModifyPositionLaterWritesLowerDisjoint I) (by decide) - (by - rw [writeCascade_cons] - have hsize : - (writeWord (burnModifyPositionMem1 I) 160 - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))).size = - max (burnModifyPositionMem1 I).size (160 + 32) := by - exact writeWord_size _ _ _ (lt_usize _ (by omega)) - have hhead : - 160 < (writeWord (burnModifyPositionMem1 I) 160 - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))).size := by - rw [hsize] - omega - have hge := writeCascade_size_ge_base - (writeWord (burnModifyPositionMem1 I) 160 - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) - [(192, UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)), - (224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] - (burnModifyPositionLowerRestGapsOk I) - exact lt_of_lt_of_le hhead hge) - (by native_decide) - -theorem burnModifyPositionTickUpperLoad_eq (I : ExecutionEnv) : - burnModifyPositionTickUpperLoad I = - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) := by - unfold burnModifyPositionTickUpperLoad burnModifyPositionMload - rw [burnModifyPositionMem4_cascadeFromMem2] - exact writeCascade_mload_word_of_head (mem := burnModifyPositionMem2 I) (off := 192) - (offWord := (⟨192⟩ : UInt256)) (aw := UInt256.ofNat 8) - (word := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (rest := [(224, UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))]) - (lt_usize _ (by omega)) (burnModifyPositionLaterWritesUpperDisjoint I) (by decide) - (by - rw [writeCascade_cons] - have hsize : - (writeWord (burnModifyPositionMem2 I) 192 - (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))).size = - max (burnModifyPositionMem2 I).size (192 + 32) := by - exact writeWord_size _ _ _ (lt_usize _ (by omega)) - have hhead : - 192 < (writeWord (burnModifyPositionMem2 I) 192 - (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))).size := by - rw [hsize] - omega - have hge := writeCascade_size_ge_base - (writeWord (burnModifyPositionMem2 I) 192 - (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))) - [(224, UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))] - (burnModifyPositionUpperRestGapsOk I) - exact lt_of_lt_of_le hhead hge) - (by native_decide) - -private theorem uniswapV3PoolPatchPreservesJumpDest17313 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨17313⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest16264 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16264⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched16264 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16264⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest16264 - -private theorem uniswapV3PoolPatchPreservesJumpDest17377 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨17377⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest17444 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨17444⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest17510 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨17510⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched17313 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨17313⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest17313 - -theorem uniswapV3PoolJumpDestPatched17377 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨17377⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest17377 - -theorem uniswapV3PoolJumpDestPatched17444 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨17444⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest17444 - -theorem uniswapV3PoolJumpDestPatched17510 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨17510⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest17510 - -private theorem uniswapV3PoolBurnCheckTicksPatchDisjoint33 {v : PoolImmutables} - {pc : UInt256} - (hlo : 16246 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19295) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -private theorem uniswapV3PoolBurnCheckTicksDecodeEqTemplate {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 16246 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 19295 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolBurnCheckTicksPatchDisjoint33 (v := v) (pc := pc) hlo hhi) - -theorem uniswapV3PoolBurnEnterCheckTicks {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨16246⟩ - (⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnModifyPositionMem4 ee) (UInt256.ofNat 8) rdata (cA, σ) k C) - (hov : R.length + 23 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨17313⟩ - (burnModifyPositionTickUpperLoad ee :: burnModifyPositionTickLowerLoad ee :: ⟨16264⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnModifyPositionMem4 ee) (UInt256.ofNat 8) rdata (cA, σ) k' C' := by - have hd16246 : decode code ⟨16246⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16247 : decode code ⟨16247⟩ = some (.Push .PUSH2, some (⟨16264⟩, 2)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16250 : decode code ⟨16250⟩ = some (.DUP5, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16251 : decode code ⟨16251⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16253 : decode code ⟨16253⟩ = some (.ADD, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16254 : decode code ⟨16254⟩ = some (.MLOAD, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16255 : decode code ⟨16255⟩ = some (.DUP6, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16256 : decode code ⟨16256⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16258 : decode code ⟨16258⟩ = some (.ADD, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16259 : decode code ⟨16259⟩ = some (.MLOAD, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16260 : decode code ⟨16260⟩ = some (.Push .PUSH2, some (⟨17313⟩, 2)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16263 : decode code ⟨16263⟩ = some (.JUMP, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have rd16247 := by - simpa using h.jumpdest hd16246 - (by simp only [List.length_cons]; omega) - have rd16250 := by - simpa using rd16247.push2 ⟨16264⟩ hd16247 - (by simp only [List.length_cons]; omega) - have rd16251 := by - simpa using rd16250.dup5 hd16250 - (by simp only [List.length_cons]; omega) - have rd16253 := by - simpa using rd16251.push1 ⟨32⟩ hd16251 - (by simp only [List.length_cons]; omega) - have rd16254 := by - simpa using rd16253.add hd16253 - (by simp only [List.length_cons]; omega) - have rd16255 := by - simpa [burnModifyPositionTickLowerLoad, burnModifyPositionMload] using - rd16254.mload 0 (burnModifyPositionTickLowerLoad ee) (UInt256.ofNat 8) - hd16254 - mem_cost - (by rfl) - (by native_decide) - (by simp only [List.length_cons]; omega) - have rd16256 := by - simpa using rd16255.dup6 hd16255 - (by simp only [List.length_cons]; omega) - have rd16258 := by - simpa using rd16256.push1 ⟨64⟩ hd16256 - (by simp only [List.length_cons]; omega) - have rd16259 := by - simpa using rd16258.add hd16258 - (by simp only [List.length_cons]; omega) - have rd16260 := by - simpa [burnModifyPositionTickUpperLoad, burnModifyPositionMload] using - rd16259.mload 0 (burnModifyPositionTickUpperLoad ee) (UInt256.ofNat 8) - hd16259 - mem_cost - (by rfl) - (by native_decide) - (by simp only [List.length_cons]; omega) - have rd16263 := by - simpa using rd16260.push2 ⟨17313⟩ hd16260 - (by simp only [List.length_cons]; omega) - exact ⟨_, _, rd16263.jump hd16263 (uniswapV3PoolJumpDestPatched17313 hpatch) - (by simp only [List.length_cons]; omega)⟩ - -theorem uniswapV3PoolBurnCheckTicksLtOk {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret lower upper : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨17313⟩ (upper :: lower :: ret :: R) - mem aw rdata (cA, σ) k C) - (hlt : UInt256.slt (UInt256.signextend ⟨2⟩ lower) - (UInt256.signextend ⟨2⟩ upper) ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨17377⟩ (upper :: lower :: ret :: R) - mem aw rdata (cA, σ) k' C' := by - have hd17313 : decode code ⟨17313⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17314 : decode code ⟨17314⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17315 : decode code ⟨17315⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17317 : decode code ⟨17317⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17318 : decode code ⟨17318⟩ = some (.DUP3, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17319 : decode code ⟨17319⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17321 : decode code ⟨17321⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17322 : decode code ⟨17322⟩ = some (.SLT, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17323 : decode code ⟨17323⟩ = some (.Push .PUSH2, some (⟨17377⟩, 2)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17326 : decode code ⟨17326⟩ = some (.JUMPI, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have rd17314 := by - simpa using h.jumpdest hd17313 - (by simp only [List.length_cons]; omega) - have rd17315 := by - simpa using rd17314.dup1 hd17314 - (by simp only [List.length_cons]; omega) - have rd17317 := by - simpa using rd17315.push1 ⟨2⟩ hd17315 - (by simp only [List.length_cons]; omega) - have rd17318 := by - simpa using burnRDSignextend rd17317 hd17317 - (by simp only [List.length_cons]; omega) - have rd17319 := by - simpa using rd17318.dup3 hd17318 - (by simp only [List.length_cons]; omega) - have rd17321 := by - simpa using rd17319.push1 ⟨2⟩ hd17319 - (by simp only [List.length_cons]; omega) - have rd17322 := by - simpa using burnRDSignextend rd17321 hd17321 - (by simp only [List.length_cons]; omega) - have rd17323 := by - simpa using rd17322.slt hd17322 - (by simp only [List.length_cons]; omega) - have rd17326 := by - simpa using rd17323.push2 ⟨17377⟩ hd17323 - (by simp only [List.length_cons]; omega) - exact ⟨_, _, rd17326.jumpiT hd17326 hlt - (uniswapV3PoolJumpDestPatched17377 hpatch) - (by simp only [List.length_cons]; omega)⟩ - -private theorem uniswapV3PoolBurnTluRevertTailWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcErrorStringRevertTailWf code ⟨17327⟩ ⟨3⟩ ⟨5524565⟩ ⟨232⟩ .PUSH3 3 := by - dsimp [solcErrorStringRevertTailWf] - repeat' constructor - all_goals - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - -def burnTluRevertWord : UInt256 := - UInt256.shiftLeft ⟨5524565⟩ ⟨232⟩ - -noncomputable def burnTluRevertMem0 (I : ExecutionEnv) : ByteArray := - (UInt256.toByteArray solcErrorStringSelector).write 0 (burnModifyPositionMem4 I) 256 32 - -noncomputable def burnTluRevertMem1 (I : ExecutionEnv) : ByteArray := - (UInt256.toByteArray (⟨32⟩ : UInt256)).write 0 (burnTluRevertMem0 I) 260 32 - -noncomputable def burnTluRevertMem2 (I : ExecutionEnv) : ByteArray := - (UInt256.toByteArray (⟨3⟩ : UInt256)).write 0 (burnTluRevertMem1 I) 292 32 - -noncomputable def burnTluRevertMem3 (I : ExecutionEnv) : ByteArray := - (UInt256.toByteArray burnTluRevertWord).write 0 (burnTluRevertMem2 I) 324 32 - -private theorem burnTluRevertMem0_size (I : ExecutionEnv) : - (burnTluRevertMem0 I).size = 288 := by - unfold burnTluRevertMem0 - exact toByteArray_write32_size_of_ge (burnModifyPositionMem4 I) - solcErrorStringSelector 256 256 288 (burnModifyPositionMem4_size I) - (by omega) (by native_decide) (by omega) - -private theorem burnTluRevertMem1_size (I : ExecutionEnv) : - (burnTluRevertMem1 I).size = 292 := by - unfold burnTluRevertMem1 - exact toByteArray_write32_size_of_le (burnTluRevertMem0 I) (⟨32⟩ : UInt256) - 260 288 292 (burnTluRevertMem0_size I) - (by rw [burnTluRevertMem0_size I]; omega) (by omega) - -private theorem burnTluRevertMem2_size (I : ExecutionEnv) : - (burnTluRevertMem2 I).size = 324 := by - unfold burnTluRevertMem2 - exact toByteArray_write32_size_of_le (burnTluRevertMem1 I) (⟨3⟩ : UInt256) - 292 292 324 (burnTluRevertMem1_size I) - (by rw [burnTluRevertMem1_size I]) (by omega) - -private theorem burnTluRevertMem3_size (I : ExecutionEnv) : - (burnTluRevertMem3 I).size = 356 := by - unfold burnTluRevertMem3 - exact toByteArray_write32_size_of_ge (burnTluRevertMem2 I) burnTluRevertWord - 324 324 356 (burnTluRevertMem2_size I) - (by omega) (by native_decide) (by omega) - -private theorem burnTluRevertMem3_read64 (I : ExecutionEnv) : - (burnTluRevertMem3 I).readWithPadding 64 32 = UInt256.toByteArray ⟨256⟩ := by - unfold burnTluRevertMem3 - rw [toByteArray_write_read_below_of_gap burnTluRevertWord _ 324 64 - (by rw [burnTluRevertMem2_size I]; omega) (by omega) - (by rw [burnTluRevertMem2_size I]; native_decide)] - unfold burnTluRevertMem2 - rw [toByteArray_write_read_below_of_gap (⟨3⟩ : UInt256) _ 292 64 - (by rw [burnTluRevertMem1_size I]; omega) (by omega) - (by rw [burnTluRevertMem1_size I]; native_decide)] - unfold burnTluRevertMem1 - rw [toByteArray_write_read_below_of_gap (⟨32⟩ : UInt256) _ 260 64 - (by rw [burnTluRevertMem0_size I]; omega) (by omega) - (by rw [burnTluRevertMem0_size I]; native_decide)] - unfold burnTluRevertMem0 - rw [toByteArray_write_read_below_of_gap solcErrorStringSelector _ 256 64 - (by rw [burnModifyPositionMem4_size I]; omega) (by omega) - (by rw [burnModifyPositionMem4_size I]; native_decide)] - exact burnModifyPositionMem4_read64 I - -private theorem burnTluRevertMem3_mload64 (I : ExecutionEnv) : - (if (⟨64⟩ : UInt256).toNat ≥ (burnTluRevertMem3 I).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 12 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnTluRevertMem3 I).readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨256⟩ := - mloadWordValue_of_readWithPadding (mem := burnTluRevertMem3 I) - (aw := UInt256.ofNat 12) (off := ⟨64⟩) (v := ⟨256⟩) - (by rw [burnTluRevertMem3_size I]; native_decide) - (by native_decide) (burnTluRevertMem3_read64 I) - -noncomputable def burnCheckTicksRevertMem3 (I : ExecutionEnv) (word : UInt256) : ByteArray := - (UInt256.toByteArray word).write 0 (burnTluRevertMem2 I) 324 32 - -private theorem burnCheckTicksRevertMem3_size (I : ExecutionEnv) (word : UInt256) : - (burnCheckTicksRevertMem3 I word).size = 356 := by - unfold burnCheckTicksRevertMem3 - exact toByteArray_write32_size_of_ge (burnTluRevertMem2 I) word - 324 324 356 (burnTluRevertMem2_size I) - (by omega) (by native_decide) (by omega) - -private theorem burnCheckTicksRevertMem3_read64 (I : ExecutionEnv) (word : UInt256) : - (burnCheckTicksRevertMem3 I word).readWithPadding 64 32 = - UInt256.toByteArray ⟨256⟩ := by - unfold burnCheckTicksRevertMem3 - rw [toByteArray_write_read_below_of_gap word _ 324 64 - (by rw [burnTluRevertMem2_size I]; omega) (by omega) - (by rw [burnTluRevertMem2_size I]; native_decide)] - unfold burnTluRevertMem2 - rw [toByteArray_write_read_below_of_gap (⟨3⟩ : UInt256) _ 292 64 - (by rw [burnTluRevertMem1_size I]; omega) (by omega) - (by rw [burnTluRevertMem1_size I]; native_decide)] - unfold burnTluRevertMem1 - rw [toByteArray_write_read_below_of_gap (⟨32⟩ : UInt256) _ 260 64 - (by rw [burnTluRevertMem0_size I]; omega) (by omega) - (by rw [burnTluRevertMem0_size I]; native_decide)] - unfold burnTluRevertMem0 - rw [toByteArray_write_read_below_of_gap solcErrorStringSelector _ 256 64 - (by rw [burnModifyPositionMem4_size I]; omega) (by omega) - (by rw [burnModifyPositionMem4_size I]; native_decide)] - exact burnModifyPositionMem4_read64 I - -private theorem burnCheckTicksRevertMem3_mload64 (I : ExecutionEnv) (word : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (burnCheckTicksRevertMem3 I word).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 12 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnCheckTicksRevertMem3 I word).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) - = ⟨256⟩ := - mloadWordValue_of_readWithPadding (mem := burnCheckTicksRevertMem3 I word) - (aw := UInt256.ofNat 12) (off := ⟨64⟩) (v := ⟨256⟩) - (by rw [burnCheckTicksRevertMem3_size I word]; native_decide) - (by native_decide) (burnCheckTicksRevertMem3_read64 I word) - -theorem uniswapV3PoolBurnCheckTicksRevertTail {code : ByteArray} - {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc rawWord shift word : UInt256} {op : Operation.POp} {width : ℕ} - {stk : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (h : RD code ee g s0 pc stk - (burnModifyPositionMem4 ee) (UInt256.ofNat 8) rdata (cA, σ) k C) - (hwf : solcErrorStringRevertTailWf code pc ⟨3⟩ rawWord shift op width) - (hpush : op ≠ .PUSH0) - (hword : UInt256.shiftLeft rawWord shift = word) - (hov : stk.length + 5 ≤ 1024) : - RDrev code g s0 := by - rcases hwf with - ⟨hd0, hd2, hd3, hd4, hd8, hd10, hd11, hd12, hd13, hd15, hd17, hd18, - hd19, hd20, hd22, hd24, hd25, hd26, hd27, hdRawOut, hdShl, hd68, - hdDup3, hdAdd, hdMstore3, hdSwap, hdMload, hdSwap2, hdDup2, hdSwap3, - hdSub, hd100, hdAdd2, hdSwap4, hdRev⟩ - have rdMload := evm_run h with [ - raw push1 ⟨64⟩ hd0 (by evm_ov), - raw dup1 hd2 (by evm_ov), - raw mload 0 ⟨256⟩ (UInt256.ofNat 8) hd3 - mem_cost - (by simpa [burnModifyPositionFreePtrLoad] using burnModifyPositionFreePtrLoad_eq ee) - (by decide) (by evm_ov)] - have rdSelectorRaw := rdMload.pushConst (⟨4594637⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) hd4 (by simp only [List.length_cons]; omega) - have rdPrefix := evm_run rdSelectorRaw with [ - raw push1 ⟨229⟩ hd8 (by evm_ov), - raw shl hd10 (by evm_ov), - raw dup2 hd11 (by evm_ov), - raw mstore 3 (burnTluRevertMem0 ee) (UInt256.ofNat 9) - hd12 mem_cost (by rfl) (by decide) (by evm_ov), - raw push1 ⟨32⟩ hd13 (by evm_ov), - raw push1 ⟨4⟩ hd15 (by evm_ov), - raw dup3 hd17 (by evm_ov), - raw add hd18 (by evm_ov), - raw mstore 3 (burnTluRevertMem1 ee) (UInt256.ofNat 10) - hd19 mem_cost (by rfl) (by decide) (by evm_ov), - raw push1 ⟨3⟩ hd20 (by evm_ov), - raw push1 ⟨36⟩ hd22 (by evm_ov), - raw dup3 hd24 (by evm_ov), - raw add hd25 (by evm_ov), - raw mstore 3 (burnTluRevertMem2 ee) - (UInt256.ofNat 11) hd26 mem_cost (by rfl) (by decide) (by evm_ov)] - have rdRaw := rdPrefix.pushConst rawWord (width := width) (op := op) - hpush hd27 (by simp only [List.length_cons]; omega) - have rdWord := evm_run rdRaw with [ - raw push1 shift hdRawOut (by evm_ov), - raw shl hdShl (by evm_ov)] - rw [hword] at rdWord - exact evm_run rdWord with [ - raw push1 ⟨68⟩ hd68 (by evm_ov), - raw dup3 hdDup3 (by evm_ov), - raw add hdAdd (by evm_ov), - raw mstore 3 (burnCheckTicksRevertMem3 ee word) - (UInt256.ofNat 12) hdMstore3 mem_cost - (by - simp [burnCheckTicksRevertMem3] - have hoff : ((⟨256⟩ : UInt256) + ⟨68⟩).toNat = 324 := by native_decide - rw [hoff]) - (by decide) (by evm_ov), - raw swap1 hdSwap (by evm_ov), - raw mload 0 ⟨256⟩ (UInt256.ofNat 12) hdMload - mem_cost - (burnCheckTicksRevertMem3_mload64 ee word) - (by decide) (by evm_ov), - raw swap1 hdSwap2 (by evm_ov), - raw dup2 hdDup2 (by evm_ov), - raw swap1 hdSwap3 (by evm_ov), - raw sub hdSub (by evm_ov), - raw push1 ⟨100⟩ hd100 (by evm_ov), - raw add hdAdd2 (by evm_ov), - raw swap1 hdSwap4 (by evm_ov), - raw rev 0 hdRev mem_cost (by evm_ov)] - -theorem uniswapV3PoolBurnTluRevertTail {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {stk : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨17327⟩ stk - (burnModifyPositionMem4 ee) (UInt256.ofNat 8) rdata (cA, σ) k C) - (hov : stk.length + 5 ≤ 1024) : - RDrev code g s0 := by - rcases uniswapV3PoolBurnTluRevertTailWf hpatch with - ⟨hd0, hd2, hd3, hd4, hd8, hd10, hd11, hd12, hd13, hd15, hd17, hd18, - hd19, hd20, hd22, hd24, hd25, hd26, hd27, hdRawOut, hdShl, hd68, - hdDup3, hdAdd, hdMstore3, hdSwap, hdMload, hdSwap2, hdDup2, hdSwap3, - hdSub, hd100, hdAdd2, hdSwap4, hdRev⟩ - have rdMload := evm_run h with [ - raw push1 ⟨64⟩ hd0 (by evm_ov), - raw dup1 hd2 (by evm_ov), - raw mload 0 ⟨256⟩ (UInt256.ofNat 8) hd3 - mem_cost - (by simpa [burnModifyPositionFreePtrLoad] using burnModifyPositionFreePtrLoad_eq ee) - (by decide) (by evm_ov)] - have rdSelectorRaw := rdMload.pushConst (⟨4594637⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) hd4 (by simp only [List.length_cons]; omega) - have rdPrefix := evm_run rdSelectorRaw with [ - raw push1 ⟨229⟩ hd8 (by evm_ov), - raw shl hd10 (by evm_ov), - raw dup2 hd11 (by evm_ov), - raw mstore 3 (burnTluRevertMem0 ee) (UInt256.ofNat 9) - hd12 mem_cost (by rfl) (by decide) (by evm_ov), - raw push1 ⟨32⟩ hd13 (by evm_ov), - raw push1 ⟨4⟩ hd15 (by evm_ov), - raw dup3 hd17 (by evm_ov), - raw add hd18 (by evm_ov), - raw mstore 3 (burnTluRevertMem1 ee) (UInt256.ofNat 10) - hd19 mem_cost (by rfl) (by decide) (by evm_ov), - raw push1 ⟨3⟩ hd20 (by evm_ov), - raw push1 ⟨36⟩ hd22 (by evm_ov), - raw dup3 hd24 (by evm_ov), - raw add hd25 (by evm_ov), - raw mstore 3 (burnTluRevertMem2 ee) - (UInt256.ofNat 11) hd26 mem_cost (by rfl) (by decide) (by evm_ov)] - have rdRaw := rdPrefix.pushConst (⟨5524565⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) hd27 - (by simp only [List.length_cons]; omega) - have rdWord := evm_run rdRaw with [ - raw push1 ⟨232⟩ hdRawOut (by evm_ov), - raw shl hdShl (by evm_ov)] - exact evm_run rdWord with [ - raw push1 ⟨68⟩ hd68 (by evm_ov), - raw dup3 hdDup3 (by evm_ov), - raw add hdAdd (by evm_ov), - raw mstore 3 (burnTluRevertMem3 ee) - (UInt256.ofNat 12) hdMstore3 mem_cost - (by - simp [burnTluRevertMem3, burnTluRevertWord] - have hoff : ((⟨256⟩ : UInt256) + ⟨68⟩).toNat = 324 := by native_decide - rw [hoff]) - (by decide) (by evm_ov), - raw swap1 hdSwap (by evm_ov), - raw mload 0 ⟨256⟩ (UInt256.ofNat 12) hdMload - mem_cost - (burnTluRevertMem3_mload64 ee) - (by decide) (by evm_ov), - raw swap1 hdSwap2 (by evm_ov), - raw dup2 hdDup2 (by evm_ov), - raw swap1 hdSwap3 (by evm_ov), - raw sub hdSub (by evm_ov), - raw push1 ⟨100⟩ hd100 (by evm_ov), - raw add hdAdd2 (by evm_ov), - raw swap1 hdSwap4 (by evm_ov), - raw rev 0 hdRev mem_cost (by evm_ov)] - -private theorem uniswapV3PoolBurnTlmRevertTailWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcErrorStringRevertTailWf code ⟨17394⟩ ⟨3⟩ ⟨5524557⟩ ⟨232⟩ .PUSH3 3 := by - dsimp [solcErrorStringRevertTailWf] - repeat' constructor - all_goals - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - -def burnTlmRevertWord : UInt256 := - UInt256.shiftLeft ⟨5524557⟩ ⟨232⟩ - -theorem uniswapV3PoolBurnTlmRevertTail {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {stk : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨17394⟩ stk - (burnModifyPositionMem4 ee) (UInt256.ofNat 8) rdata (cA, σ) k C) - (hov : stk.length + 5 ≤ 1024) : - RDrev code g s0 := by - exact uniswapV3PoolBurnCheckTicksRevertTail - (pc := ⟨17394⟩) (rawWord := ⟨5524557⟩) (shift := ⟨232⟩) - (word := burnTlmRevertWord) (op := .PUSH3) (width := 3) - h (uniswapV3PoolBurnTlmRevertTailWf hpatch) (by native_decide) rfl hov - -private theorem uniswapV3PoolBurnTumRevertTailWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcErrorStringRevertTailWf code ⟨17460⟩ ⟨3⟩ ⟨5526861⟩ ⟨232⟩ .PUSH3 3 := by - dsimp [solcErrorStringRevertTailWf] - repeat' constructor - all_goals - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - -def burnTumRevertWord : UInt256 := - UInt256.shiftLeft ⟨5526861⟩ ⟨232⟩ - -theorem uniswapV3PoolBurnTumRevertTail {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {stk : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨17460⟩ stk - (burnModifyPositionMem4 ee) (UInt256.ofNat 8) rdata (cA, σ) k C) - (hov : stk.length + 5 ≤ 1024) : - RDrev code g s0 := by - exact uniswapV3PoolBurnCheckTicksRevertTail - (pc := ⟨17460⟩) (rawWord := ⟨5526861⟩) (shift := ⟨232⟩) - (word := burnTumRevertWord) (op := .PUSH3) (width := 3) - h (uniswapV3PoolBurnTumRevertTailWf hpatch) (by native_decide) rfl hov - -theorem uniswapV3PoolBurnCheckTicksLtRevert {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret lower upper : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨17313⟩ (upper :: lower :: ret :: R) - mem aw rdata (cA, σ) k C) - (hzero : UInt256.slt (UInt256.signextend ⟨2⟩ lower) - (UInt256.signextend ⟨2⟩ upper) = ⟨0⟩) - (hmem : mem = burnModifyPositionMem4 ee) - (haw : aw = UInt256.ofNat 8) - (hov : R.length + 8 ≤ 1024) : - RDrev code g s0 := by - subst hmem - subst haw - have hd17313 : decode code ⟨17313⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17314 : decode code ⟨17314⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17315 : decode code ⟨17315⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17317 : decode code ⟨17317⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17318 : decode code ⟨17318⟩ = some (.DUP3, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17319 : decode code ⟨17319⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17321 : decode code ⟨17321⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17322 : decode code ⟨17322⟩ = some (.SLT, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17323 : decode code ⟨17323⟩ = some (.Push .PUSH2, some (⟨17377⟩, 2)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17326 : decode code ⟨17326⟩ = some (.JUMPI, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have rd17314 := by - simpa using h.jumpdest hd17313 - (by simp only [List.length_cons]; omega) - have rd17315 := by - simpa using rd17314.dup1 hd17314 - (by simp only [List.length_cons]; omega) - have rd17317 := by - simpa using rd17315.push1 ⟨2⟩ hd17315 - (by simp only [List.length_cons]; omega) - have rd17318 := by - simpa using burnRDSignextend rd17317 hd17317 - (by simp only [List.length_cons]; omega) - have rd17319 := by - simpa using rd17318.dup3 hd17318 - (by simp only [List.length_cons]; omega) - have rd17321 := by - simpa using rd17319.push1 ⟨2⟩ hd17319 - (by simp only [List.length_cons]; omega) - have rd17322 := by - simpa using burnRDSignextend rd17321 hd17321 - (by simp only [List.length_cons]; omega) - have rd17323 := by - simpa using rd17322.slt hd17322 - (by simp only [List.length_cons]; omega) - have rd17326 := by - simpa using rd17323.push2 ⟨17377⟩ hd17323 - (by simp only [List.length_cons]; omega) - have rd17327 := rd17326.jumpiNT hd17326 hzero - (by simp only [List.length_cons]; omega) - exact uniswapV3PoolBurnTluRevertTail (v := v) (code := code) (ee := ee) (g := g) - (s0 := s0) (stk := upper :: lower :: ret :: R) (rdata := rdata) - (cA := cA) (σ := σ) hpatch rd17327 - (by simp only [List.length_cons]; omega) - -theorem uniswapV3PoolModifyPositionSourceNoDelegateOk {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (noDelegateCall v) - (ExecResult.ok { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I)) := by - simpa [noDelegateCall, eqE] using - (ExecBlock.consNormal - (ExecStmt.requireTrue (uniswapV3PoolNoDelegateCallEvalTrue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (L := burnModifyPositionStore I) (g := g) hguard)) - ExecBlock.nil) - -theorem burnModifyPositionStore_tickLower (I : ExecutionEnv) : - (burnModifyPositionStore I).get? "tickLower" = some (burnTickLowerValue I) := by - rw [burnModifyPositionStore] - rw [store_get_ne - ((((∅ : Store).insert "liquidityDelta" (burnLiquidityDeltaValue I)) - |>.insert "tickUpper" (burnTickUpperValue I)) - |>.insert "tickLower" (burnTickLowerValue I)) - (k := "owner") (a := "tickLower") (.address I.source) (by native_decide)] - exact store_get_self - (((∅ : Store).insert "liquidityDelta" (burnLiquidityDeltaValue I)) - |>.insert "tickUpper" (burnTickUpperValue I)) - "tickLower" (burnTickLowerValue I) - -theorem burnModifyPositionStore_tickUpper (I : ExecutionEnv) : - (burnModifyPositionStore I).get? "tickUpper" = some (burnTickUpperValue I) := by - rw [burnModifyPositionStore] - rw [store_get_ne2 - (((∅ : Store).insert "liquidityDelta" (burnLiquidityDeltaValue I)) - |>.insert "tickUpper" (burnTickUpperValue I)) - (k1 := "tickLower") (k2 := "owner") (a := "tickUpper") - (burnTickLowerValue I) (.address I.source) (by native_decide) (by native_decide)] - exact store_get_self ((∅ : Store).insert "liquidityDelta" (burnLiquidityDeltaValue I)) - "tickUpper" (burnTickUpperValue I) - -theorem burnTickLtSlt_eq (I : ExecutionEnv) : - UInt256.slt - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))) = - if tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I) then ⟨1⟩ else ⟨0⟩ := by - simp only [burnTickLowerCleanWord, burnTickUpperCleanWord] - rw [signextend_two_tickSpacing_idempotent (UInt256.signextend ⟨2⟩ (burnTickLowerWord I))] - rw [signextend_two_tickSpacing_idempotent (UInt256.signextend ⟨2⟩ (burnTickUpperWord I))] - rw [signextend_two_tickSpacing_idempotent (burnTickLowerWord I)] - rw [signextend_two_tickSpacing_idempotent (burnTickUpperWord I)] - rw [← wordOfInt_sint24Value_eq_signextend_two (burnTickLowerWord I)] - rw [← wordOfInt_sint24Value_eq_signextend_two (burnTickUpperWord I)] - exact slt_wordOfInt_int24 _ _ (tickSpacingSint24Value_ge _) (tickSpacingSint24Value_lt _) - (tickSpacingSint24Value_ge _) (tickSpacingSint24Value_lt _) - -theorem burnTickLtSlt_ne_zero (I : ExecutionEnv) - (hlt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) : - UInt256.slt - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))) ≠ - ⟨0⟩ := by - rw [burnTickLtSlt_eq I, if_pos hlt] - native_decide - -theorem burnTickLtSlt_eq_zero (I : ExecutionEnv) - (hlt : - ¬ tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) : - UInt256.slt - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))) = - ⟨0⟩ := by - rw [burnTickLtSlt_eq I, if_neg hlt] - -def burnMinTickWord : UInt256 := - UInt256.lnot ⟨887271⟩ - -theorem burnMinTickWord_eq_wordOfInt : - burnMinTickWord = EVM.wordOfInt (-887272) := by - native_decide - -theorem burnTickLowerMinSlt_eq (I : ExecutionEnv) : - UInt256.slt - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) - burnMinTickWord = - if tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int) then - ⟨1⟩ - else - ⟨0⟩ := by - simp only [burnTickLowerCleanWord] - rw [signextend_two_tickSpacing_idempotent (UInt256.signextend ⟨2⟩ (burnTickLowerWord I))] - rw [signextend_two_tickSpacing_idempotent (burnTickLowerWord I)] - rw [← wordOfInt_sint24Value_eq_signextend_two (burnTickLowerWord I)] - rw [burnMinTickWord_eq_wordOfInt] - exact slt_wordOfInt_int24 _ _ (tickSpacingSint24Value_ge _) (tickSpacingSint24Value_lt _) - (by norm_num) (by norm_num) - -theorem burnTickLowerMinSlt_ne_zero (I : ExecutionEnv) - (hlt : tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) : - UInt256.slt - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) - burnMinTickWord ≠ ⟨0⟩ := by - rw [burnTickLowerMinSlt_eq I, if_pos hlt] - native_decide - -theorem burnTickLowerMinSlt_eq_zero (I : ExecutionEnv) - (hlt : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) : - UInt256.slt - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) - burnMinTickWord = ⟨0⟩ := by - rw [burnTickLowerMinSlt_eq I, if_neg hlt] - -def burnMaxTickWord : UInt256 := - ⟨887272⟩ - -theorem burnMaxTickWord_eq_wordOfInt : - burnMaxTickWord = EVM.wordOfInt (887272 : Int) := by - native_decide - -theorem burnTickUpperMaxSgt_eq (I : ExecutionEnv) : - UInt256.sgt - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))) - burnMaxTickWord = - if (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I) then - ⟨1⟩ - else - ⟨0⟩ := by - simp only [burnTickUpperCleanWord] - rw [sgt_eq_slt_swap] - rw [signextend_two_tickSpacing_idempotent (UInt256.signextend ⟨2⟩ (burnTickUpperWord I))] - rw [signextend_two_tickSpacing_idempotent (burnTickUpperWord I)] - rw [burnMaxTickWord_eq_wordOfInt] - rw [← wordOfInt_sint24Value_eq_signextend_two (burnTickUpperWord I)] - exact slt_wordOfInt_int24 _ _ (by norm_num) (by norm_num) - (tickSpacingSint24Value_ge _) (tickSpacingSint24Value_lt _) - -theorem burnTickUpperMaxSgt_ne_zero (I : ExecutionEnv) - (hlt : (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) : - UInt256.sgt - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))) - burnMaxTickWord ≠ ⟨0⟩ := by - rw [burnTickUpperMaxSgt_eq I, if_pos hlt] - native_decide - -theorem burnTickUpperMaxSgt_eq_zero (I : ExecutionEnv) - (hlt : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) : - UInt256.sgt - (UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I))) - burnMaxTickWord = ⟨0⟩ := by - rw [burnTickUpperMaxSgt_eq I, if_neg hlt] - -theorem uniswapV3PoolBurnCheckTicksLowerOk {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret lower upper : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨17377⟩ (upper :: lower :: ret :: R) - mem aw rdata (cA, σ) k C) - (hge : UInt256.slt (UInt256.signextend ⟨2⟩ lower) burnMinTickWord = ⟨0⟩) - (hov : R.length + 8 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨17444⟩ (upper :: lower :: ret :: R) - mem aw rdata (cA, σ) k' C' := by - have hd17377 : decode code ⟨17377⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17378 : decode code ⟨17378⟩ = some (.Push .PUSH3, some (⟨887271⟩, 3)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17382 : decode code ⟨17382⟩ = some (.NOT, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17383 : decode code ⟨17383⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17385 : decode code ⟨17385⟩ = some (.DUP4, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17386 : decode code ⟨17386⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17387 : decode code ⟨17387⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17388 : decode code ⟨17388⟩ = some (.SLT, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17389 : decode code ⟨17389⟩ = some (.ISZERO, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17390 : decode code ⟨17390⟩ = some (.Push .PUSH2, some (⟨17444⟩, 2)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17393 : decode code ⟨17393⟩ = some (.JUMPI, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have rd17378 := by - simpa using h.jumpdest hd17377 - (by simp only [List.length_cons]; omega) - have rd17382 := rd17378.pushConst (⟨887271⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) hd17378 - (by simp only [List.length_cons]; omega) - have rd17383 := by - simpa [burnMinTickWord] using rd17382.not hd17382 - (by simp only [List.length_cons]; omega) - have rd17385 := by - simpa using rd17383.push1 ⟨2⟩ hd17383 - (by simp only [List.length_cons]; omega) - have rd17386 := by - simpa using rd17385.dup4 hd17385 - (by simp only [List.length_cons]; omega) - have rd17387 := by - simpa using rd17386.swap1 hd17386 - (by simp only [List.length_cons]; omega) - have rd17388 := by - simpa using burnRDSignextend rd17387 hd17387 - (by simp only [List.length_cons]; omega) - have rd17389 := by - simpa [burnMinTickWord] using rd17388.slt hd17388 - (by simp only [List.length_cons]; omega) - have rd17390 := by - simpa using rd17389.iszero hd17389 - (by simp only [List.length_cons]; omega) - have rd17393 := by - simpa using rd17390.push2 ⟨17444⟩ hd17390 - (by simp only [List.length_cons]; omega) - have hcond : - UInt256.isZero (UInt256.slt (UInt256.signextend ⟨2⟩ lower) burnMinTickWord) ≠ - ⟨0⟩ := by - rw [hge] - native_decide - exact ⟨_, _, rd17393.jumpiT hd17393 hcond - (uniswapV3PoolJumpDestPatched17444 hpatch) - (by simp only [List.length_cons]; omega)⟩ - -theorem uniswapV3PoolBurnCheckTicksLowerRevert {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret lower upper : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨17377⟩ (upper :: lower :: ret :: R) - mem aw rdata (cA, σ) k C) - (hlt : UInt256.slt (UInt256.signextend ⟨2⟩ lower) burnMinTickWord ≠ ⟨0⟩) - (hmem : mem = burnModifyPositionMem4 ee) - (haw : aw = UInt256.ofNat 8) - (hov : R.length + 8 ≤ 1024) : - RDrev code g s0 := by - subst hmem - subst haw - have hd17377 : decode code ⟨17377⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17378 : decode code ⟨17378⟩ = some (.Push .PUSH3, some (⟨887271⟩, 3)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17382 : decode code ⟨17382⟩ = some (.NOT, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17383 : decode code ⟨17383⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17385 : decode code ⟨17385⟩ = some (.DUP4, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17386 : decode code ⟨17386⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17387 : decode code ⟨17387⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17388 : decode code ⟨17388⟩ = some (.SLT, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17389 : decode code ⟨17389⟩ = some (.ISZERO, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17390 : decode code ⟨17390⟩ = some (.Push .PUSH2, some (⟨17444⟩, 2)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17393 : decode code ⟨17393⟩ = some (.JUMPI, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have rd17378 := by - simpa using h.jumpdest hd17377 - (by simp only [List.length_cons]; omega) - have rd17382 := rd17378.pushConst (⟨887271⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) hd17378 - (by simp only [List.length_cons]; omega) - have rd17383 := by - simpa [burnMinTickWord] using rd17382.not hd17382 - (by simp only [List.length_cons]; omega) - have rd17385 := by - simpa using rd17383.push1 ⟨2⟩ hd17383 - (by simp only [List.length_cons]; omega) - have rd17386 := by - simpa using rd17385.dup4 hd17385 - (by simp only [List.length_cons]; omega) - have rd17387 := by - simpa using rd17386.swap1 hd17386 - (by simp only [List.length_cons]; omega) - have rd17388 := by - simpa using burnRDSignextend rd17387 hd17387 - (by simp only [List.length_cons]; omega) - have rd17389 := by - simpa [burnMinTickWord] using rd17388.slt hd17388 - (by simp only [List.length_cons]; omega) - have rd17390 := by - simpa using rd17389.iszero hd17389 - (by simp only [List.length_cons]; omega) - have rd17393 := by - simpa using rd17390.push2 ⟨17444⟩ hd17390 - (by simp only [List.length_cons]; omega) - have hcond : - UInt256.isZero (UInt256.slt (UInt256.signextend ⟨2⟩ lower) burnMinTickWord) = - ⟨0⟩ := - isZero_eq_zero_of_ne hlt - have rd17394 := rd17393.jumpiNT hd17393 hcond - (by simp only [List.length_cons]; omega) - exact uniswapV3PoolBurnTlmRevertTail (v := v) (code := code) (ee := ee) (g := g) - (s0 := s0) (stk := upper :: lower :: ret :: R) (rdata := rdata) - (cA := cA) (σ := σ) hpatch rd17394 - (by simp only [List.length_cons]; omega) - -theorem uniswapV3PoolBurnCheckTicksUpperOk {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret lower upper : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨17444⟩ (upper :: lower :: ret :: R) - mem aw rdata (cA, σ) k C) - (hle : UInt256.sgt (UInt256.signextend ⟨2⟩ upper) burnMaxTickWord = ⟨0⟩) - (hov : R.length + 8 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨17510⟩ (upper :: lower :: ret :: R) - mem aw rdata (cA, σ) k' C' := by - have hd17444 : decode code ⟨17444⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17445 : decode code ⟨17445⟩ = some (.Push .PUSH3, some (⟨887272⟩, 3)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17449 : decode code ⟨17449⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17451 : decode code ⟨17451⟩ = some (.DUP3, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17452 : decode code ⟨17452⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17453 : decode code ⟨17453⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17454 : decode code ⟨17454⟩ = some (.SGT, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17455 : decode code ⟨17455⟩ = some (.ISZERO, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17456 : decode code ⟨17456⟩ = some (.Push .PUSH2, some (⟨17510⟩, 2)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17459 : decode code ⟨17459⟩ = some (.JUMPI, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have rd17445 := by - simpa using h.jumpdest hd17444 - (by simp only [List.length_cons]; omega) - have rd17449 := rd17445.pushConst (⟨887272⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) hd17445 - (by simp only [List.length_cons]; omega) - have rd17451 := by - simpa [burnMaxTickWord] using rd17449.push1 ⟨2⟩ hd17449 - (by simp only [List.length_cons]; omega) - have rd17452 := by - simpa using rd17451.dup3 hd17451 - (by simp only [List.length_cons]; omega) - have rd17453 := by - simpa using rd17452.swap1 hd17452 - (by simp only [List.length_cons]; omega) - have rd17454 := by - simpa using burnRDSignextend rd17453 hd17453 - (by simp only [List.length_cons]; omega) - have rd17455 := by - simpa [burnMaxTickWord] using rd17454.sgt hd17454 - (by simp only [List.length_cons]; omega) - have rd17456 := by - simpa using rd17455.iszero hd17455 - (by simp only [List.length_cons]; omega) - have rd17459 := by - simpa using rd17456.push2 ⟨17510⟩ hd17456 - (by simp only [List.length_cons]; omega) - have hcond : - UInt256.isZero (UInt256.sgt (UInt256.signextend ⟨2⟩ upper) burnMaxTickWord) ≠ - ⟨0⟩ := by - rw [hle] - native_decide - exact ⟨_, _, rd17459.jumpiT hd17459 hcond - (uniswapV3PoolJumpDestPatched17510 hpatch) - (by simp only [List.length_cons]; omega)⟩ - -theorem uniswapV3PoolBurnCheckTicksReturn {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret lower upper : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨17510⟩ (upper :: lower :: ret :: R) - mem aw rdata acc k C) - (hjd : (D_J code 0).contains ret = true) - (hov : R.length + 3 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret R mem aw rdata acc k' C' := by - have hd17510 : decode code ⟨17510⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17511 : decode code ⟨17511⟩ = some (.POP, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17512 : decode code ⟨17512⟩ = some (.POP, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17513 : decode code ⟨17513⟩ = some (.JUMP, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have rd17511 := h.jumpdest hd17510 (by simp only [List.length_cons]; omega) - have rd17512 := rd17511.pop hd17511 (by simp only [List.length_cons]; omega) - have rd17513 := rd17512.pop hd17512 (by simp only [List.length_cons]; omega) - exact ⟨_, _, rd17513.jump hd17513 hjd (by omega)⟩ - -theorem uniswapV3PoolBurnCheckTicksUpperRevert {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret lower upper : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨17444⟩ (upper :: lower :: ret :: R) - mem aw rdata (cA, σ) k C) - (hgt : UInt256.sgt (UInt256.signextend ⟨2⟩ upper) burnMaxTickWord ≠ ⟨0⟩) - (hmem : mem = burnModifyPositionMem4 ee) - (haw : aw = UInt256.ofNat 8) - (hov : R.length + 8 ≤ 1024) : - RDrev code g s0 := by - subst hmem - subst haw - have hd17444 : decode code ⟨17444⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17445 : decode code ⟨17445⟩ = some (.Push .PUSH3, some (⟨887272⟩, 3)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17449 : decode code ⟨17449⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17451 : decode code ⟨17451⟩ = some (.DUP3, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17452 : decode code ⟨17452⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17453 : decode code ⟨17453⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17454 : decode code ⟨17454⟩ = some (.SGT, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17455 : decode code ⟨17455⟩ = some (.ISZERO, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17456 : decode code ⟨17456⟩ = some (.Push .PUSH2, some (⟨17510⟩, 2)) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd17459 : decode code ⟨17459⟩ = some (.JUMPI, .none) := by - rw [uniswapV3PoolBurnCheckTicksDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have rd17445 := by - simpa using h.jumpdest hd17444 - (by simp only [List.length_cons]; omega) - have rd17449 := rd17445.pushConst (⟨887272⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) hd17445 - (by simp only [List.length_cons]; omega) - have rd17451 := by - simpa [burnMaxTickWord] using rd17449.push1 ⟨2⟩ hd17449 - (by simp only [List.length_cons]; omega) - have rd17452 := by - simpa using rd17451.dup3 hd17451 - (by simp only [List.length_cons]; omega) - have rd17453 := by - simpa using rd17452.swap1 hd17452 - (by simp only [List.length_cons]; omega) - have rd17454 := by - simpa using burnRDSignextend rd17453 hd17453 - (by simp only [List.length_cons]; omega) - have rd17455 := by - simpa [burnMaxTickWord] using rd17454.sgt hd17454 - (by simp only [List.length_cons]; omega) - have rd17456 := by - simpa using rd17455.iszero hd17455 - (by simp only [List.length_cons]; omega) - have rd17459 := by - simpa using rd17456.push2 ⟨17510⟩ hd17456 - (by simp only [List.length_cons]; omega) - have hcond : - UInt256.isZero (UInt256.sgt (UInt256.signextend ⟨2⟩ upper) burnMaxTickWord) = - ⟨0⟩ := - isZero_eq_zero_of_ne hgt - have rd17460 := rd17459.jumpiNT hd17459 hcond - (by simp only [List.length_cons]; omega) - exact uniswapV3PoolBurnTumRevertTail (v := v) (code := code) (ee := ee) (g := g) - (s0 := s0) (stk := upper :: lower :: ret :: R) (rdata := rdata) - (cA := cA) (σ := σ) hpatch rd17460 - (by simp only [List.length_cons]; omega) - -theorem uniswapV3PoolModifyPositionEvalTickLtTrue {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hlt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) : - evalExpr? (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (ltE (.var "tickLower") (.var "tickUpper")) = - .ok (.bool true) := by - have hLower := burnModifyPositionStore_tickLower I - have hUpper := burnModifyPositionStore_tickUpper I - simp only [ltE, evalExpr?, EvalResult.bind, EvalResult.ofOption, bind] - rw [hLower, hUpper] - simp [evalBinaryOp?, hlt] - -theorem uniswapV3PoolModifyPositionEvalTickLtFalse {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hlt : - ¬ tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) : - evalExpr? (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (ltE (.var "tickLower") (.var "tickUpper")) = - .ok (.bool false) := by - have hLower := burnModifyPositionStore_tickLower I - have hUpper := burnModifyPositionStore_tickUpper I - simp only [ltE, evalExpr?, EvalResult.bind, EvalResult.ofOption, bind] - rw [hLower, hUpper] - simp [evalBinaryOp?, hlt] - -theorem uniswapV3PoolModifyPositionEvalLowerGeTrue {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) : - evalExpr? (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (geE (.var "tickLower") minTick) = - .ok (.bool true) := by - have hLower := burnModifyPositionStore_tickLower I - simp only [geE, minTick, evalExpr?, EvalResult.bind, EvalResult.ofOption, bind] - rw [hLower] - have hge' : tickSpacingSint24Value (burnTickLowerWord I) >= (-887272 : Int) := by - omega - simp [evalBinaryOp?, hge'] - -theorem uniswapV3PoolModifyPositionEvalLowerGeFalse {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hlt : tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) : - evalExpr? (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (geE (.var "tickLower") minTick) = - .ok (.bool false) := by - have hLower := burnModifyPositionStore_tickLower I - simp only [geE, minTick, evalExpr?, EvalResult.bind, EvalResult.ofOption, bind] - rw [hLower] - have hge' : ¬ tickSpacingSint24Value (burnTickLowerWord I) >= (-887272 : Int) := by - omega - simp [evalBinaryOp?, hge'] - -theorem uniswapV3PoolModifyPositionEvalUpperLeTrue {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) : - evalExpr? (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (leE (.var "tickUpper") maxTick) = - .ok (.bool true) := by - have hUpper := burnModifyPositionStore_tickUpper I - simp only [leE, maxTick, evalExpr?, EvalResult.bind, EvalResult.ofOption, bind] - rw [hUpper] - have hle' : tickSpacingSint24Value (burnTickUpperWord I) <= (887272 : Int) := by - omega - simp [evalBinaryOp?, hle'] - -theorem uniswapV3PoolModifyPositionEvalUpperLeFalse {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hgt : (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) : - evalExpr? (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (leE (.var "tickUpper") maxTick) = - .ok (.bool false) := by - have hUpper := burnModifyPositionStore_tickUpper I - simp only [leE, maxTick, evalExpr?, EvalResult.bind, EvalResult.ofOption, bind] - rw [hUpper] - have hle' : ¬ tickSpacingSint24Value (burnTickUpperWord I) <= (887272 : Int) := by - omega - simp [evalBinaryOp?, hle'] - -theorem uniswapV3PoolModifyPositionSourceThroughTickLt {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (hlt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - (noDelegateCall v ++ [Stmt.require (ltE (.var "tickLower") (.var "tickUpper"))]) - (ExecResult.ok { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := uniswapV3PoolModifyPositionSourceNoDelegateOk (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard - have htail : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - [Stmt.require (ltE (.var "tickLower") (.var "tickUpper"))] - (ExecResult.ok { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecBlock.consNormal - (ExecStmt.requireTrue (uniswapV3PoolModifyPositionEvalTickLtTrue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hlt)) - ExecBlock.nil - exact execBlock_append hprefix htail - -theorem uniswapV3PoolModifyPositionSourceThroughLowerGe {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - (noDelegateCall v ++ - [Stmt.require (ltE (.var "tickLower") (.var "tickUpper")), - Stmt.require (geE (.var "tickLower") minTick)]) - (ExecResult.ok { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := uniswapV3PoolModifyPositionSourceThroughTickLt (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard htickLt - have htail : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - [Stmt.require (geE (.var "tickLower") minTick)] - (ExecResult.ok { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecBlock.consNormal - (ExecStmt.requireTrue (uniswapV3PoolModifyPositionEvalLowerGeTrue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hge)) - ExecBlock.nil - simpa [List.append_assoc] using execBlock_append hprefix htail - -theorem uniswapV3PoolModifyPositionSourceThroughUpperLe {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - (noDelegateCall v ++ checkTicksBody (.var "tickLower") (.var "tickUpper")) - (ExecResult.ok { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := uniswapV3PoolModifyPositionSourceThroughLowerGe (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard htickLt hge - have htail : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - [Stmt.require (leE (.var "tickUpper") maxTick)] - (ExecResult.ok { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecBlock.consNormal - (ExecStmt.requireTrue (uniswapV3PoolModifyPositionEvalUpperLeTrue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hle)) - ExecBlock.nil - simpa [checkTicksBody, List.append_assoc] using execBlock_append hprefix htail - -theorem uniswapV3PoolModifyPositionSourceTickLtRevertsPrefix {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (hlt : - ¬ tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (rest : List Stmt) : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - (noDelegateCall v ++ checkTicksBody (.var "tickLower") (.var "tickUpper") ++ rest) - .reverted := by - have hprefix := uniswapV3PoolModifyPositionSourceNoDelegateOk (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard - have htail : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - (Stmt.require (ltE (.var "tickLower") (.var "tickUpper")) :: - Stmt.require (geE (.var "tickLower") minTick) :: - Stmt.require (leE (.var "tickUpper") maxTick) :: rest) - .reverted := by - exact ExecBlock.consRevert - (ExecStmt.requireFalse (uniswapV3PoolModifyPositionEvalTickLtFalse - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hlt)) - simpa [checkTicksBody, List.append_assoc] using execBlock_append hprefix htail - -theorem uniswapV3PoolModifyPositionSourceLowerRevertsPrefix {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hlt : tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (rest : List Stmt) : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - (noDelegateCall v ++ checkTicksBody (.var "tickLower") (.var "tickUpper") ++ rest) - .reverted := by - have hprefix := uniswapV3PoolModifyPositionSourceThroughTickLt (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard htickLt - have htail : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - (Stmt.require (geE (.var "tickLower") minTick) :: - Stmt.require (leE (.var "tickUpper") maxTick) :: rest) - .reverted := by - exact ExecBlock.consRevert - (ExecStmt.requireFalse (uniswapV3PoolModifyPositionEvalLowerGeFalse - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hlt)) - simpa [checkTicksBody, List.append_assoc] using execBlock_append hprefix htail - -theorem uniswapV3PoolModifyPositionSourceUpperRevertsPrefix {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hgt : (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (rest : List Stmt) : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - (noDelegateCall v ++ checkTicksBody (.var "tickLower") (.var "tickUpper") ++ rest) - .reverted := by - have hprefix := uniswapV3PoolModifyPositionSourceThroughLowerGe (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard htickLt hge - have htail : - ExecBlock (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) - (Stmt.require (leE (.var "tickUpper") maxTick) :: rest) - .reverted := by - exact ExecBlock.consRevert - (ExecStmt.requireFalse (uniswapV3PoolModifyPositionEvalUpperLeFalse - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hgt)) - simpa [checkTicksBody, List.append_assoc] using execBlock_append hprefix htail - -theorem uniswapV3PoolModifyPositionSourceTickLtReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (hlt : - ¬ tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) : - ExecFuncBody (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (modifyPositionFunction v).body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [modifyPositionFunction, noDelegateCall, checkTicksBody, List.append_assoc] using - uniswapV3PoolModifyPositionSourceTickLtRevertsPrefix (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard hlt - ((modifyPositionFunction v).body.drop - (noDelegateCall v ++ checkTicksBody (.var "tickLower") (.var "tickUpper")).length) - -theorem uniswapV3PoolModifyPositionSourceLowerReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hlt : tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) : - ExecFuncBody (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (modifyPositionFunction v).body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [modifyPositionFunction, noDelegateCall, checkTicksBody, List.append_assoc] using - uniswapV3PoolModifyPositionSourceLowerRevertsPrefix (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard htickLt hlt - ((modifyPositionFunction v).body.drop - (noDelegateCall v ++ checkTicksBody (.var "tickLower") (.var "tickUpper")).length) - -theorem uniswapV3PoolModifyPositionSourceUpperReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hgt : (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) : - ExecFuncBody (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (modifyPositionFunction v).body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [modifyPositionFunction, noDelegateCall, checkTicksBody, List.append_assoc] using - uniswapV3PoolModifyPositionSourceUpperRevertsPrefix (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard htickLt hge hgt - ((modifyPositionFunction v).body.drop - (noDelegateCall v ++ checkTicksBody (.var "tickLower") (.var "tickUpper")).length) - -theorem uniswapV3PoolBurnSourceTickLtReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : burnUnlockedByte σ I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (hlt : - ¬ tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (burnStore I) - burnTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolBurnSourceThroughLiquidityDelta (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hunlocked hcanon - have hlockState : - Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I) = - initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - σ₀ g A I := by - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have hstmt : - ExecStmt (config v) (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - (.internalCall "modifyPosition" - [.env .caller, .var "tickLower", .var "tickUpper", .var "liquidityDelta"] - "modified") - .reverted := by - rw [hlockState] - refine internalCallFunctionRevert (callee := modifyPositionFunction v) - (argVals := burnModifyPositionArgValues I) (locals := burnModifyPositionStore I) - ?_ ?_ ?_ ?_ - · have hLower := burnLiquidityDeltaFrame_tickLower (v := v) I - have hUpper := burnLiquidityDeltaFrame_tickUpper (v := v) I - have hDelta := burnLiquidityDeltaFrame_liquidityDelta (v := v) I - simp only [burnModifyPositionArgValues, evalExprs?, evalExpr?, envValue, initState, - EvalResult.bind, bind, pure] - rw [hLower, hUpper, hDelta] - rfl - · simpa [burnLiquidityDeltaFrame] using uniswapV3PoolLookupModifyPosition v - · rfl - · exact uniswapV3PoolModifyPositionSourceTickLtReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) - (σ := sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hguard hlt - simpa [burnTransition, nonpayable, lockPrefix] using - execBlock_append hprefix (ExecBlock.consRevert hstmt) - -theorem uniswapV3PoolBurnSourceLowerReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : burnUnlockedByte σ I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hlt : tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (burnStore I) - burnTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolBurnSourceThroughLiquidityDelta (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hunlocked hcanon - have hlockState : - Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I) = - initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - σ₀ g A I := by - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have hstmt : - ExecStmt (config v) (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - (.internalCall "modifyPosition" - [.env .caller, .var "tickLower", .var "tickUpper", .var "liquidityDelta"] - "modified") - .reverted := by - rw [hlockState] - refine internalCallFunctionRevert (callee := modifyPositionFunction v) - (argVals := burnModifyPositionArgValues I) (locals := burnModifyPositionStore I) - ?_ ?_ ?_ ?_ - · have hLower := burnLiquidityDeltaFrame_tickLower (v := v) I - have hUpper := burnLiquidityDeltaFrame_tickUpper (v := v) I - have hDelta := burnLiquidityDeltaFrame_liquidityDelta (v := v) I - simp only [burnModifyPositionArgValues, evalExprs?, evalExpr?, envValue, initState, - EvalResult.bind, bind, pure] - rw [hLower, hUpper, hDelta] - rfl - · simpa [burnLiquidityDeltaFrame] using uniswapV3PoolLookupModifyPosition v - · rfl - · exact uniswapV3PoolModifyPositionSourceLowerReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) - (σ := sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hguard htickLt hlt - simpa [burnTransition, nonpayable, lockPrefix] using - execBlock_append hprefix (ExecBlock.consRevert hstmt) - -theorem uniswapV3PoolBurnSourceUpperReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : burnUnlockedByte σ I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hgt : (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (burnStore I) - burnTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolBurnSourceThroughLiquidityDelta (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hunlocked hcanon - have hlockState : - Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I) = - initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - σ₀ g A I := by - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have hstmt : - ExecStmt (config v) (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - (.internalCall "modifyPosition" - [.env .caller, .var "tickLower", .var "tickUpper", .var "liquidityDelta"] - "modified") - .reverted := by - rw [hlockState] - refine internalCallFunctionRevert (callee := modifyPositionFunction v) - (argVals := burnModifyPositionArgValues I) (locals := burnModifyPositionStore I) - ?_ ?_ ?_ ?_ - · have hLower := burnLiquidityDeltaFrame_tickLower (v := v) I - have hUpper := burnLiquidityDeltaFrame_tickUpper (v := v) I - have hDelta := burnLiquidityDeltaFrame_liquidityDelta (v := v) I - simp only [burnModifyPositionArgValues, evalExprs?, evalExpr?, envValue, initState, - EvalResult.bind, bind, pure] - rw [hLower, hUpper, hDelta] - rfl - · simpa [burnLiquidityDeltaFrame] using uniswapV3PoolLookupModifyPosition v - · rfl - · exact uniswapV3PoolModifyPositionSourceUpperReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) - (σ := sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hguard htickLt hge hgt - simpa [burnTransition, nonpayable, lockPrefix] using - execBlock_append hprefix (ExecBlock.consRevert hstmt) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnFullMathSlow.lean b/Benchmarks/UniswapV3Pool/BurnFullMathSlow.lean deleted file mode 100644 index 1b7176bb..00000000 --- a/Benchmarks/UniswapV3Pool/BurnFullMathSlow.lean +++ /dev/null @@ -1,955 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdate - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Reasoning.Theory - -theorem xor_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.XOR, .none)) - (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : - Xstep (D_J code 0) s = - (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok (stBinop s (a.xor b) t, .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.XOR, .none) := by - rw [hcode, hpc] - exact hdec - rw [← hcode, step_xor s hd, hstk] - have hov' : ¬((a :: b :: t).length - 2 + 1 > 1024) := by - simp only [List.length_cons] - omega - simp only [if_neg hov', GasConstants.Gverylow, stBinop] - -end Reasoning.Theory - -namespace Reasoning.Reach - -open Reasoning.Theory - -theorem RD.xor {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.XOR, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.xor a b :: t) mem aw rdata acc (k + 1) - (C + 3) := - h.stepBinop (fun _ hc hp hs => xor_xstep hc hp hdec hs hov) - -end Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem uniswapV3PoolFullMathMulDivSlowPatchDisjoint33 {v : PoolImmutables} - {pc : UInt256} - (hlo : 13017 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13225) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -private theorem uniswapV3PoolFullMathMulDivSlowDecodeEqTemplate {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 13017 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13225) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 13225 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolFullMathMulDivSlowPatchDisjoint33 (v := v) (pc := pc) hlo hhi) - -private abbrev fullMathStackPush (x : UInt256) (s : List UInt256) : List UInt256 := - x :: s - -private abbrev fullMathStackPop : List UInt256 → List UInt256 - | [] => [] - | _ :: xs => xs - -private def fullMathStackGetD : List UInt256 → Nat → UInt256 - | [], _ => ⟨0⟩ - | x :: _, 0 => x - | _ :: xs, n + 1 => fullMathStackGetD xs n - -private def fullMathStackSetD : List UInt256 → Nat → UInt256 → List UInt256 - | [], _, _ => [] - | _ :: xs, 0, v => v :: xs - | x :: xs, n + 1, v => x :: fullMathStackSetD xs n v - -private abbrev fullMathStackDup (n : Nat) (s : List UInt256) : List UInt256 := - fullMathStackGetD s (n - 1) :: s - -private def fullMathStackSwap (n : Nat) (s : List UInt256) : List UInt256 := - match s with - | [] => [] - | x :: xs => fullMathStackGetD xs (n - 1) :: fullMathStackSetD xs (n - 1) x - -private abbrev fullMathStackBin (f : UInt256 → UInt256 → UInt256) - (s : List UInt256) : List UInt256 := - match s with - | a :: b :: t => f a b :: t - | _ => s - -private abbrev fullMathStackTri (f : UInt256 → UInt256 → UInt256 → UInt256) - (s : List UInt256) : List UInt256 := - match s with - | a :: b :: c :: t => f a b c :: t - | _ => s - -abbrev uniswapV3PoolFullMathMulDivSlowBodyStack - (prod1 prod0 den b a ret z : UInt256) (R : List UInt256) : List UInt256 := - let s := prod1 :: prod0 :: ⟨0⟩ :: den :: b :: a :: ret :: z :: R - let s := fullMathStackPush ⟨0⟩ s - let s := fullMathStackDup 5 s - let s := fullMathStackDup 7 s - let s := fullMathStackDup 9 s - let s := fullMathStackTri (fun x y m => x.mulMod y m) s - let s := fullMathStackPush ⟨0⟩ s - let s := fullMathStackDup 7 s - let s := fullMathStackDup 2 s - let s := fullMathStackBin UInt256.sub s - let s := fullMathStackDup 8 s - let s := fullMathStackBin UInt256.land s - let s := fullMathStackSwap 7 s - let s := fullMathStackDup 8 s - let s := fullMathStackSwap 1 s - let s := fullMathStackBin UInt256.div s - let s := fullMathStackSwap 7 s - let s := fullMathStackPush ⟨2⟩ s - let s := fullMathStackPush ⟨3⟩ s - let s := fullMathStackDup 10 s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackDup 2 s - let s := fullMathStackBin UInt256.xor s - let s := fullMathStackDup 1 s - let s := fullMathStackDup 11 s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackDup 3 s - let s := fullMathStackBin UInt256.sub s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackDup 1 s - let s := fullMathStackDup 11 s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackDup 3 s - let s := fullMathStackBin UInt256.sub s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackDup 1 s - let s := fullMathStackDup 11 s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackDup 3 s - let s := fullMathStackBin UInt256.sub s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackDup 1 s - let s := fullMathStackDup 11 s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackDup 3 s - let s := fullMathStackBin UInt256.sub s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackDup 1 s - let s := fullMathStackDup 11 s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackDup 3 s - let s := fullMathStackBin UInt256.sub s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackDup 1 s - let s := fullMathStackDup 11 s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackSwap 1 s - let s := fullMathStackSwap 2 s - let s := fullMathStackBin UInt256.sub s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackSwap 2 s - let s := fullMathStackDup 2 s - let s := fullMathStackSwap 1 s - let s := fullMathStackBin UInt256.sub s - let s := fullMathStackDup 2 s - let s := fullMathStackSwap 1 s - let s := fullMathStackBin UInt256.div s - let s := fullMathStackPush ⟨1⟩ s - let s := fullMathStackBin (fun x y => x + y) s - let s := fullMathStackDup 7 s - let s := fullMathStackDup 5 s - let s := fullMathStackBin UInt256.gt s - let s := fullMathStackSwap 1 s - let s := fullMathStackSwap 6 s - let s := fullMathStackBin UInt256.sub s - let s := fullMathStackSwap 5 s - let s := fullMathStackSwap 1 s - let s := fullMathStackSwap 5 s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackSwap 2 s - let s := fullMathStackSwap 1 s - let s := fullMathStackSwap 5 s - let s := fullMathStackBin UInt256.sub s - let s := fullMathStackSwap 3 s - let s := fullMathStackSwap 1 s - let s := fullMathStackSwap 3 s - let s := fullMathStackBin UInt256.div s - let s := fullMathStackSwap 2 s - let s := fullMathStackSwap 1 s - let s := fullMathStackSwap 2 s - let s := fullMathStackBin UInt256.lor s - let s := fullMathStackSwap 2 s - let s := fullMathStackSwap 1 s - let s := fullMathStackSwap 2 s - let s := fullMathStackBin UInt256.mul s - let s := fullMathStackSwap 2 s - let s := fullMathStackPop s - fullMathStackPop s - -abbrev uniswapV3PoolFullMathMulDivSlowJumpStack - (prod1 prod0 den b a ret z : UInt256) (R : List UInt256) : List UInt256 := - let s := uniswapV3PoolFullMathMulDivSlowBodyStack prod1 prod0 den b a ret z R - let s := fullMathStackSwap 4 s - let s := fullMathStackSwap 3 s - let s := fullMathStackPop s - let s := fullMathStackPop s - fullMathStackPop s - -abbrev uniswapV3PoolFullMathMulDivSlowReturnStack - (prod1 prod0 den b a ret z : UInt256) (R : List UInt256) : List UInt256 := - fullMathStackPop - (uniswapV3PoolFullMathMulDivSlowJumpStack prod1 prod0 den b a ret z R) - -abbrev uniswapV3PoolFullMathMulDivSlowResult - (prod1 prod0 den b a : UInt256) : UInt256 := - fullMathStackGetD - (uniswapV3PoolFullMathMulDivSlowReturnStack prod1 prod0 den b a ⟨0⟩ ⟨0⟩ []) - 0 - -private abbrev fullMathSlowTwos (den : UInt256) : UInt256 := - UInt256.land den (UInt256.sub ⟨0⟩ den) - -private abbrev fullMathSlowDenOdd (den : UInt256) : UInt256 := - UInt256.div den (fullMathSlowTwos den) - -private abbrev fullMathSlowInvStep (d inv : UInt256) : UInt256 := - UInt256.mul (UInt256.sub ⟨2⟩ (UInt256.mul d inv)) inv - -private abbrev fullMathSlowInv (den : UInt256) : UInt256 := - let d := fullMathSlowDenOdd den - let inv := UInt256.xor ⟨2⟩ (UInt256.mul d ⟨3⟩) - let inv := fullMathSlowInvStep d inv - let inv := fullMathSlowInvStep d inv - let inv := fullMathSlowInvStep d inv - let inv := fullMathSlowInvStep d inv - let inv := fullMathSlowInvStep d inv - fullMathSlowInvStep d inv - -private abbrev fullMathSlowResultExpr - (prod1 prod0 den b a : UInt256) : UInt256 := - let twos := fullMathSlowTwos den - let prod0' := UInt256.div (UInt256.sub prod0 (a.mulMod b den)) twos - let prod1' := UInt256.sub prod1 ((a.mulMod b den).gt prod0) - let high := UInt256.mul prod1' (⟨1⟩ + UInt256.div (UInt256.sub ⟨0⟩ twos) twos) - UInt256.mul (UInt256.lor prod0' high) (fullMathSlowInv den) - -private theorem uniswapV3PoolFullMathMulDivSlowResult_eq_expr - (prod1 prod0 den b a : UInt256) : - uniswapV3PoolFullMathMulDivSlowResult prod1 prod0 den b a = - fullMathSlowResultExpr prod1 prod0 den b a := by - simp [uniswapV3PoolFullMathMulDivSlowResult, - uniswapV3PoolFullMathMulDivSlowReturnStack, - uniswapV3PoolFullMathMulDivSlowJumpStack, - uniswapV3PoolFullMathMulDivSlowBodyStack, fullMathSlowResultExpr, - fullMathSlowInv, fullMathSlowInvStep, fullMathSlowDenOdd, fullMathSlowTwos, - fullMathStackPush, fullMathStackPop, fullMathStackBin, fullMathStackSwap, - fullMathStackGetD, fullMathStackSetD] - -private theorem u256_mul_one (x : UInt256) : UInt256.mul x ⟨1⟩ = x := by - apply u256_inj - rw [u256_mul_toNat] - rw [show ((⟨1⟩ : UInt256).toNat) = 1 by rfl] - rw [Nat.mul_one] - exact Nat.mod_eq_of_lt x.val.isLt - -private theorem fullMathSlowTwosQ128 : - fullMathSlowTwos (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) = - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ := by - native_decide - -private theorem fullMathSlowInvQ128 : - fullMathSlowInv (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) = ⟨1⟩ := by - native_decide - -private theorem fullMathSlowHighFactorQ128 : - (⟨1⟩ : UInt256) + - UInt256.div - (UInt256.sub ⟨0⟩ (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) = - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ := by - native_decide - -private theorem fullMathMulModQ128_toNat (a b : UInt256) : - (a.mulMod b (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)).toNat = - (a.toNat * b.toNat) % 2 ^ (128 : Nat) := by - unfold UInt256.mulMod - have hq : (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩).toNat = 2 ^ (128 : Nat) := by - native_decide - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩).eq0 = false by native_decide] - rw [hq] - rw [if_neg (by decide : ¬false = true)] - rw [UInt256.toNat_ofNat_of_lt] - · rfl - · exact lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ (128 : Nat))) - (by norm_num [UInt256.size]) - -private theorem nat_sub_mod_div_eq_div (x m : Nat) (hm : 0 < m) : - (x - x % m) / m = x / m := by - have hdecomp : x = x / m * m + x % m := by - rw [show x / m * m = m * (x / m) by exact Nat.mul_comm (x / m) m] - exact (Nat.div_add_mod x m).symm - conv_lhs => rw [hdecomp] - have hmod : (x / m * m + x % m) % m = x % m := by - rw [Nat.add_mod] - rw [show x / m * m % m = 0 by - rw [Nat.mul_comm] - exact Nat.mul_mod_right m (x / m)] - rw [Nat.mod_mod] - simp - rw [hmod] - rw [Nat.add_sub_cancel_right] - rw [Nat.mul_comm] - exact Nat.mul_div_right (x / m) hm - -private theorem fullMathProd0SubMulModQ128DivEq (a b : UInt256) : - UInt256.div - (UInt256.sub (uniswapV3PoolFullMathMulDivProd0 a b) - (a.mulMod b (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) = - UInt256.div (uniswapV3PoolFullMathMulDivProd0 a b) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) := by - apply u256_inj - rw [udiv_toNat, udiv_toNat] - have hq : (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩).toNat = 2 ^ (128 : Nat) := by - native_decide - rw [hq] - have hprod0 : - (uniswapV3PoolFullMathMulDivProd0 a b).toNat = - (a.toNat * b.toNat) % 2 ^ (256 : Nat) := by - rw [uniswapV3PoolFullMathMulDivProd0, u256_mul_toNat] - rw [show UInt256.size = 2 ^ (256 : Nat) by rfl] - rw [Nat.mul_comm] - have hrem : - (a.mulMod b (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)).toNat = - (uniswapV3PoolFullMathMulDivProd0 a b).toNat % 2 ^ (128 : Nat) := by - rw [fullMathMulModQ128_toNat, hprod0] - rw [← Nat.mod_mod_of_dvd (a := a.toNat * b.toNat) - (show 2 ^ (128 : Nat) ∣ 2 ^ (256 : Nat) by - exact Nat.pow_dvd_pow 2 (by omega))] - have hle : - (a.mulMod b (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)).toNat ≤ - (uniswapV3PoolFullMathMulDivProd0 a b).toNat := by - rw [hrem] - exact Nat.mod_le _ _ - rw [usub_toNat (a := uniswapV3PoolFullMathMulDivProd0 a b) - (b := a.mulMod b (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) hle] - rw [hrem] - exact nat_sub_mod_div_eq_div (uniswapV3PoolFullMathMulDivProd0 a b).toNat - (2 ^ (128 : Nat)) (by norm_num) - -private theorem low128_lor_mul_q128 (x y : UInt256) : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.lor x (UInt256.mul y (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩))) = - UInt256.land burnPositionUpdateSlot0Mask x := by - apply u256_inj - rw [burnPositionUpdateSlot0Mask_eq_uint128Mask] - rw [u256_land_toNat, u256_land_toNat] - have hmask : uint128Mask.toNat = 2 ^ 128 - 1 := uint128Mask_toNat - have hq : (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩).toNat = 2 ^ 128 := by - native_decide - have hmul : - (UInt256.mul y (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)).toNat = - y.toNat * 2 ^ 128 % 2 ^ 256 := by - rw [u256_mul_toNat, hq] - rfl - rw [u256_lor_toNat, hmask, hmul] - rw [show UInt256.size = 2 ^ 256 by rfl] - change Nat.land (2 ^ 128 - 1) - ((Nat.lor x.toNat (y.toNat * 2 ^ 128 % 2 ^ 256)) % 2 ^ 256) % 2 ^ 256 = - Nat.land (2 ^ 128 - 1) x.toNat % 2 ^ 256 - rw [nat_land_comm (2 ^ 128 - 1) - ((Nat.lor x.toNat (y.toNat * 2 ^ 128 % 2 ^ 256)) % 2 ^ 256)] - rw [nat_land_comm (2 ^ 128 - 1) x.toNat] - rw [show - Nat.land ((Nat.lor x.toNat (y.toNat * 2 ^ 128 % 2 ^ 256)) % 2 ^ 256) - (2 ^ 128 - 1) % 2 ^ 256 = - Nat.land (Nat.lor x.toNat (y.toNat * 2 ^ 128 % 2 ^ 256)) (2 ^ 128 - 1) by - rw [nat_land_mask_eq_mod, nat_land_mask_eq_mod] - rw [Nat.mod_mod_of_dvd _ (show 2 ^ (128 : Nat) ∣ 2 ^ (256 : Nat) by - exact Nat.pow_dvd_pow 2 (by omega))] - exact Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ (128 : Nat))) - (by norm_num : 2 ^ (128 : Nat) < 2 ^ (256 : Nat)))] - rw [show (Nat.land x.toNat (2 ^ 128 - 1)) % 2 ^ 256 = - Nat.land x.toNat (2 ^ 128 - 1) by - rw [nat_land_mask_eq_mod] - exact Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ (128 : Nat))) - (by norm_num : 2 ^ (128 : Nat) < 2 ^ (256 : Nat)))] - apply Nat.eq_of_testBit_eq - intro i - change ((Nat.lor x.toNat (y.toNat * 2 ^ 128 % 2 ^ 256)) &&& (2 ^ 128 - 1)).testBit i = - (x.toNat &&& (2 ^ 128 - 1)).testBit i - rw [Nat.testBit_and, Nat.testBit_and] - change (((x.toNat ||| (y.toNat * 2 ^ 128 % 2 ^ 256)).testBit i) && - (2 ^ 128 - 1).testBit i) = - (x.toNat.testBit i && (2 ^ 128 - 1).testBit i) - rw [Nat.testBit_or] - by_cases hi : i < 128 - · rw [Nat.testBit_two_pow_sub_one, decide_eq_true hi] - simp only [Bool.and_true] - have hshiftzero : (y.toNat * 2 ^ 128 % 2 ^ 256).testBit i = false := by - rw [Nat.testBit_mod_two_pow] - rw [Nat.testBit_mul_two_pow] - simp [hi] - rw [hshiftzero] - simp - · rw [Nat.testBit_two_pow_sub_one, decide_eq_false hi] - simp - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolFullMathMulDivProd1NonzeroReturnStack - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {prod1 prod0 den b a ret z : UInt256} {R : List UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13044⟩ - (prod1 :: prod1 :: prod0 :: ⟨0⟩ :: den :: b :: a :: ret :: z :: R) - mem aw rdata acc k C) - (hprod1 : prod1 ≠ ⟨0⟩) (hden : UInt256.gt den prod1 ≠ ⟨0⟩) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 30 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret - (uniswapV3PoolFullMathMulDivSlowReturnStack prod1 prod0 den b a ret z R) - mem aw rdata acc k' C' := by - have hdec (pc : UInt256) - (hlo : 13017 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13225) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolFullMathMulDivSlowDecodeEqTemplate hpatch hlo hhi - have rd13047 := evm_run h with [ - raw push2 ⟨13071⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd13071 := rd13047.jumpiT - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - hprod1 (uniswapV3PoolJumpDestPatched13071 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd13078 := evm_run rd13071 with [ - raw jumpdest - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup5 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw gt - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push2 ⟨13083⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd13083 := rd13078.jumpiT - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - hden (uniswapV3PoolJumpDestPatched13083 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd13186 := evm_run rd13083 with [ - raw jumpdest - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨0⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup5 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup7 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup9 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mulmod - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨0⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup7 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup2 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup8 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw and - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap7 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup8 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw div - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap7 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨2⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨3⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup10 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup2 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw xor - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup11 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup3 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup11 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup3 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup11 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup3 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup11 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup3 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup11 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup3 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup11 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup2 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup2 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw div - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨1⟩ - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw add - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup7 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup5 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw gt - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap6 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap5 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap5 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap5 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw sub - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap3 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap3 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw div - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw lor - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap1 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw mul - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap2 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd13192 := evm_run rd13186 with [ - raw jumpdest - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap4 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw swap3 - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw pop - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rdret := rd13192.jump - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - hret (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, by - simpa [uniswapV3PoolFullMathMulDivSlowReturnStack, - uniswapV3PoolFullMathMulDivSlowJumpStack, - uniswapV3PoolFullMathMulDivSlowBodyStack, fullMathStackPush, fullMathStackPop, - fullMathStackDup, fullMathStackBin, fullMathStackTri, fullMathStackSwap, - fullMathStackGetD, fullMathStackSetD] using rdret⟩ - -private theorem nat_mod_pred_eq_div_add_mod {P N : Nat} (hN : 1 < N) : - P % (N - 1) = (P / N + P % N) % (N - 1) := by - let q := P / N - let r := P % N - change P % (N - 1) = (q + r) % (N - 1) - have hdecomp : P = q * N + r := by - rw [show q * N = N * q by exact Nat.mul_comm q N] - exact (Nat.div_add_mod P N).symm - rw [hdecomp] - let m := N - 1 - have hm : N = m + 1 := by - dsimp [m] - omega - have hrew : q * N + r = (q + r) + (N - 1) * q := by - rw [hm] - change q * (m + 1) + r = (q + r) + m * q - ring - rw [hrew] - exact Nat.add_mul_mod_self_left (q + r) (N - 1) q - -private theorem fullMathMulModLnotZero_toNat (a b : UInt256) : - (a.mulMod b (UInt256.lnot (⟨0⟩ : UInt256))).toNat = - (a.toNat * b.toNat) % (UInt256.size - 1) := by - have hlnotNat : (UInt256.lnot (⟨0⟩ : UInt256)).toNat = UInt256.size - 1 := by - native_decide - unfold UInt256.mulMod - rw [hlnotNat] - rw [if_neg (by native_decide)] - rw [UInt256.toNat_ofNat_of_lt] - · rfl - · exact lt_trans (Nat.mod_lt _ (show 0 < UInt256.size - 1 by native_decide)) - (by native_decide) - -theorem uniswapV3PoolFullMathMulDivProd1_toNat (a b : UInt256) : - (uniswapV3PoolFullMathMulDivProd1 a b).toNat = - a.toNat * b.toNat / UInt256.size := by - set N : Nat := UInt256.size with hNdef - set P : Nat := a.toNat * b.toNat with hPdef - set q : Nat := P / N with hqdef - set r : Nat := P % N with hrdef - set mm : UInt256 := a.mulMod b (UInt256.lnot (⟨0⟩ : UInt256)) with hmmdef - set prod0 : UInt256 := uniswapV3PoolFullMathMulDivProd0 a b with hprod0def - have hNpos : 0 < N := by rw [hNdef]; native_decide - have hpredPos : 0 < N - 1 := by rw [hNdef]; native_decide - have hprod0_toNat : prod0.toNat = r := by - rw [hprod0def, hrdef, hPdef, hNdef] - rw [uniswapV3PoolFullMathMulDivProd0, u256_mul_toNat] - rw [Nat.mul_comm] - have hmm_toNat : mm.toNat = (q + r) % (N - 1) := by - rw [hmmdef, hqdef, hrdef, hPdef, hNdef] - rw [fullMathMulModLnotZero_toNat] - exact nat_mod_pred_eq_div_add_mod (P := a.toNat * b.toNat) (N := UInt256.size) - (by native_decide) - have ha_le : a.toNat ≤ N - 1 := by - rw [hNdef] - exact Nat.le_pred_of_lt a.val.isLt - have hb_le : b.toNat ≤ N - 1 := by - rw [hNdef] - exact Nat.le_pred_of_lt b.val.isLt - have hP_lt_mul_pred : P < N * (N - 1) := by - have hle : P ≤ (N - 1) * (N - 1) := by - rw [hPdef] - exact Nat.mul_le_mul ha_le hb_le - have hlt : (N - 1) * (N - 1) < N * (N - 1) := by - exact Nat.mul_lt_mul_of_pos_right (by omega) hpredPos - exact lt_of_le_of_lt hle hlt - have hq_lt_pred : q < N - 1 := by - rw [hqdef] - exact Nat.div_lt_of_lt_mul hP_lt_mul_pred - unfold uniswapV3PoolFullMathMulDivProd1 - rw [← hmmdef, ← hprod0def] - change (UInt256.sub (UInt256.sub mm prod0) (UInt256.lt mm prod0)).toNat = q - by_cases hsum : q + r < N - 1 - · have hmm_qr : mm.toNat = q + r := by - rw [hmm_toNat] - exact Nat.mod_eq_of_lt hsum - have hle0 : prod0.toNat ≤ mm.toNat := by - rw [hmm_qr, hprod0_toNat] - exact Nat.le_add_left r q - have hnotlt : UInt256.lt mm prod0 = ⟨0⟩ := ult_zero hle0 - rw [hnotlt] - have hsub1 : (UInt256.sub mm prod0).toNat = q := by - rw [usub_toNat (a := mm) (b := prod0) hle0] - rw [hmm_qr, hprod0_toNat] - exact Nat.add_sub_cancel_right q r - rw [usub_toNat (a := UInt256.sub mm prod0) (b := (⟨0⟩ : UInt256))] - · rw [hsub1] - rfl - · simp - · have hsum_ge : N - 1 ≤ q + r := by omega - have hsum_lt_two : q + r < (N - 1) + (N - 1) := by - have hr_lt : r < N := by - rw [hrdef] - exact Nat.mod_lt P hNpos - omega - have hmod_qr : (q + r) % (N - 1) = q + r - (N - 1) := by - have hsplit : q + r = (N - 1) + (q + r - (N - 1)) := by omega - calc - (q + r) % (N - 1) = - ((N - 1) + (q + r - (N - 1))) % (N - 1) := by - exact congrArg (fun x => x % (N - 1)) hsplit - _ = (q + r - (N - 1)) % (N - 1) := Nat.add_mod_left (N - 1) _ - _ = q + r - (N - 1) := Nat.mod_eq_of_lt (by omega) - have hmm_qr : mm.toNat = q + r - (N - 1) := by - rw [hmm_toNat, hmod_qr] - have hlt : mm.toNat < prod0.toNat := by - rw [hmm_qr, hprod0_toNat] - omega - have hltword : UInt256.lt mm prod0 = ⟨1⟩ := ult_one hlt - rw [hltword] - have hsub1 : (UInt256.sub mm prod0).toNat = q + 1 := by - rw [usub_toNat_underflow (a := mm) (b := prod0) hlt] - rw [← hNdef, hmm_qr, hprod0_toNat] - have hcancel : q + r - (N - 1) + (N - 1) = q + r := - Nat.sub_add_cancel hsum_ge - have hNsucc : N = (N - 1) + 1 := by omega - nth_rewrite 1 [hNsucc] - rw [show (N - 1 + 1) + (q + r - (N - 1)) = - (q + r - (N - 1)) + (N - 1) + 1 by omega] - rw [hcancel] - rw [show q + r + 1 = q + 1 + r by omega] - exact Nat.add_sub_cancel_right (q + 1) r - rw [usub_toNat (a := UInt256.sub mm prod0) (b := (⟨1⟩ : UInt256))] - · rw [hsub1] - rfl - · rw [hsub1] - exact Nat.succ_le_succ (Nat.zero_le q) - -theorem uniswapV3PoolFullMathMulDivProd1_lt_q128_of_b_lt_q128 - (a b : UInt256) (hb : b.toNat < 2 ^ (128 : Nat)) : - (uniswapV3PoolFullMathMulDivProd1 a b).toNat < 2 ^ (128 : Nat) := by - rw [uniswapV3PoolFullMathMulDivProd1_toNat] - have hmul : a.toNat * b.toNat < UInt256.size * 2 ^ (128 : Nat) := - Nat.mul_lt_mul_of_lt_of_le a.val.isLt (Nat.le_of_lt hb) (by native_decide) - exact Nat.div_lt_of_lt_mul hmul - -theorem uniswapV3PoolFullMathMulDivProd1DenGtQ128 - (a b : UInt256) (hb : b.toNat < 2 ^ (128 : Nat)) : - UInt256.gt (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (uniswapV3PoolFullMathMulDivProd1 a b) ≠ ⟨0⟩ := by - have hlt := uniswapV3PoolFullMathMulDivProd1_lt_q128_of_b_lt_q128 a b hb - have hq : (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩).toNat = 2 ^ (128 : Nat) := by - native_decide - rw [ugt_one] - · exact one_ne_zero_uint - · rw [hq] - exact hlt - -theorem uniswapV3PoolFullMathMulDivSlowResult_low128_eq_prod0Div128 - (a b : UInt256) : - UInt256.land burnPositionUpdateSlot0Mask - (uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 a b) - (uniswapV3PoolFullMathMulDivProd0 a b) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) b a) = - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div (uniswapV3PoolFullMathMulDivProd0 a b) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) := by - rw [uniswapV3PoolFullMathMulDivSlowResult_eq_expr] - simp only [fullMathSlowResultExpr] - rw [fullMathSlowTwosQ128, fullMathSlowInvQ128, fullMathSlowHighFactorQ128] - rw [u256_mul_one] - rw [low128_lor_mul_q128] - exact congrArg (fun w => UInt256.land burnPositionUpdateSlot0Mask w) - (fullMathProd0SubMulModQ128DivEq a b) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnLiquidityAddDelta.lean b/Benchmarks/UniswapV3Pool/BurnLiquidityAddDelta.lean deleted file mode 100644 index cbbd1f1d..00000000 --- a/Benchmarks/UniswapV3Pool/BurnLiquidityAddDelta.lean +++ /dev/null @@ -1,213 +0,0 @@ -import Benchmarks.UniswapV3Pool.Spec -import Reasoning.SolmBody - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory - -namespace Benchmarks.UniswapV3Pool - -abbrev liquidityAddDeltaArgValues (x y : Int) : List Value := - [.int x, .int y] - -abbrev liquidityAddDeltaStore (x y : Int) : Store := - ((∅ : Store).insert "y" (.int y)).insert "x" (.int x) - -abbrev liquidityAddDeltaFrame (v : PoolImmutables) (x y : Int) : Frame := - { contract := contract v, locals := liquidityAddDeltaStore x y } - -abbrev liquidityAddDeltaWrappedSub (x y : Int) : Int := - (x - (0 - y)) % (2 ^ (128 : Nat)) - -abbrev liquidityAddDeltaWrappedAdd (x y : Int) : Int := - (x + y) % (2 ^ (128 : Nat)) - -abbrev liquidityAddDeltaAfterZStore (x y z : Int) : Store := - (liquidityAddDeltaStore x y).insert "z" (.int z) - -abbrev liquidityAddDeltaAfterZFrame (v : PoolImmutables) (x y z : Int) : Frame := - { contract := contract v, locals := liquidityAddDeltaAfterZStore x y z } - -theorem liquidityAddDelta_bindParams (x y : Int) : - bindParams? liquidityAddDeltaFunction.params (liquidityAddDeltaArgValues x y) = - some (liquidityAddDeltaStore x y) := by - rfl - -theorem liquidityAddDeltaStore_x (x y : Int) : - (liquidityAddDeltaStore x y).get? "x" = some (.int x) := by - rw [liquidityAddDeltaStore] - exact store_get_self ((∅ : Store).insert "y" (.int y)) "x" (.int x) - -theorem liquidityAddDeltaStore_y (x y : Int) : - (liquidityAddDeltaStore x y).get? "y" = some (.int y) := by - rw [liquidityAddDeltaStore] - rw [store_get_ne ((∅ : Store).insert "y" (.int y)) - (k := "x") (a := "y") (.int x) (by native_decide)] - exact store_get_self (∅ : Store) "y" (.int y) - -theorem liquidityAddDeltaAfterZStore_x (x y z : Int) : - (liquidityAddDeltaAfterZStore x y z).get? "x" = some (.int x) := by - rw [liquidityAddDeltaAfterZStore] - rw [store_get_ne (liquidityAddDeltaStore x y) - (k := "z") (a := "x") (.int z) (by native_decide)] - exact liquidityAddDeltaStore_x x y - -theorem liquidityAddDeltaAfterZStore_z (x y z : Int) : - (liquidityAddDeltaAfterZStore x y z).get? "z" = some (.int z) := by - rw [liquidityAddDeltaAfterZStore] - exact store_get_self (liquidityAddDeltaStore x y) "z" (.int z) - -theorem liquidityAddDelta_evalYLtZeroTrue {v : PoolImmutables} {evm x y} - (hy : y < 0) : - evalExpr? (config v) (liquidityAddDeltaFrame v x y) evm - (ltE (.var "y") (.intLit 0)) = .ok (.bool true) := by - simp only [liquidityAddDeltaFrame, ltE, evalExpr?, EvalResult.bind, bind, pure] - rw [liquidityAddDeltaStore_y] - simp [EvalResult.ofOption, evalBinaryOp?, hy] - -theorem liquidityAddDelta_evalYLtZeroFalse {v : PoolImmutables} {evm x y} - (hy : ¬ y < 0) : - evalExpr? (config v) (liquidityAddDeltaFrame v x y) evm - (ltE (.var "y") (.intLit 0)) = .ok (.bool false) := by - simp only [liquidityAddDeltaFrame, ltE, evalExpr?, EvalResult.bind, bind, pure] - rw [liquidityAddDeltaStore_y] - simp [EvalResult.ofOption, evalBinaryOp?, hy] - -theorem liquidityAddDelta_evalSubZ {v : PoolImmutables} {evm x y} : - evalExpr? (config v) (liquidityAddDeltaFrame v x y) evm - (uint128Wrap (subE (.var "x") (subE (.intLit 0) (.var "y")))) = - .ok (.int (liquidityAddDeltaWrappedSub x y)) := by - simp only [liquidityAddDeltaFrame, uint128Wrap, modE, subE, uint128Modulus, - evalExpr?, EvalResult.bind, bind, pure] - rw [liquidityAddDeltaStore_x, liquidityAddDeltaStore_y] - norm_num [EvalResult.ofOption, evalBinaryOp?, liquidityAddDeltaWrappedSub] - -theorem liquidityAddDelta_evalAddZ {v : PoolImmutables} {evm x y} : - evalExpr? (config v) (liquidityAddDeltaFrame v x y) evm - (uint128Wrap (addE (.var "x") (.var "y"))) = - .ok (.int (liquidityAddDeltaWrappedAdd x y)) := by - simp only [liquidityAddDeltaFrame, uint128Wrap, modE, addE, uint128Modulus, - evalExpr?, EvalResult.bind, bind, pure] - rw [liquidityAddDeltaStore_x, liquidityAddDeltaStore_y] - norm_num [EvalResult.ofOption, evalBinaryOp?, liquidityAddDeltaWrappedAdd] - -theorem liquidityAddDelta_evalZLtXTrue {v : PoolImmutables} {evm x y z} - (hlt : z < x) : - evalExpr? (config v) (liquidityAddDeltaAfterZFrame v x y z) evm - (ltE (.var "z") (.var "x")) = .ok (.bool true) := by - simp only [liquidityAddDeltaAfterZFrame, ltE, evalExpr?, EvalResult.bind, bind] - rw [liquidityAddDeltaAfterZStore_z, liquidityAddDeltaAfterZStore_x] - simp [EvalResult.ofOption, evalBinaryOp?, hlt] - -theorem liquidityAddDelta_evalZLtXFalse {v : PoolImmutables} {evm x y z} - (hlt : ¬ z < x) : - evalExpr? (config v) (liquidityAddDeltaAfterZFrame v x y z) evm - (ltE (.var "z") (.var "x")) = .ok (.bool false) := by - simp only [liquidityAddDeltaAfterZFrame, ltE, evalExpr?, EvalResult.bind, bind] - rw [liquidityAddDeltaAfterZStore_z, liquidityAddDeltaAfterZStore_x] - simp [EvalResult.ofOption, evalBinaryOp?, hlt] - -theorem liquidityAddDelta_evalZGeXTrue {v : PoolImmutables} {evm x y z} - (hge : z >= x) : - evalExpr? (config v) (liquidityAddDeltaAfterZFrame v x y z) evm - (geE (.var "z") (.var "x")) = .ok (.bool true) := by - simp only [liquidityAddDeltaAfterZFrame, geE, evalExpr?, EvalResult.bind, bind] - rw [liquidityAddDeltaAfterZStore_z, liquidityAddDeltaAfterZStore_x] - simp [EvalResult.ofOption, evalBinaryOp?, hge] - -theorem liquidityAddDelta_evalZGeXFalse {v : PoolImmutables} {evm x y z} - (hge : ¬ z >= x) : - evalExpr? (config v) (liquidityAddDeltaAfterZFrame v x y z) evm - (geE (.var "z") (.var "x")) = .ok (.bool false) := by - simp only [liquidityAddDeltaAfterZFrame, geE, evalExpr?, EvalResult.bind, bind] - rw [liquidityAddDeltaAfterZStore_z, liquidityAddDeltaAfterZStore_x] - simp [EvalResult.ofOption, evalBinaryOp?, hge] - -theorem liquidityAddDelta_evalReturnZ {v : PoolImmutables} {evm x y z} : - evalExprs? (config v) (liquidityAddDeltaAfterZFrame v x y z) evm [.var "z"] = - .ok [.int z] := by - simp only [evalExprs?, evalExpr?, EvalResult.bind, bind, pure] - rw [liquidityAddDeltaAfterZStore_z] - rfl - -theorem uniswapV3PoolLiquidityAddDeltaSourceNegativeReturns - {v : PoolImmutables} {evm x y} - (hy : y < 0) (hreq : liquidityAddDeltaWrappedSub x y < x) : - ExecFuncBody (config v) (liquidityAddDeltaFrame v x y) evm - liquidityAddDeltaFunction.body - (.returned (liquidityAddDeltaAfterZFrame v x y (liquidityAddDeltaWrappedSub x y)) - evm (some [.int (liquidityAddDeltaWrappedSub x y)])) := by - refine ExecFuncBody.execBlockRet ?_ - simpa [liquidityAddDeltaFunction] using - (ExecBlock.consReturn - (ExecStmt.iteTrue (liquidityAddDelta_evalYLtZeroTrue (v := v) (evm := evm) hy) - (ExecBlock.consNormal - (ExecStmt.letDecl (liquidityAddDelta_evalSubZ (v := v) (evm := evm))) - (ExecBlock.consNormal - (ExecStmt.requireTrue (liquidityAddDelta_evalZLtXTrue - (v := v) (evm := evm) (y := y) hreq)) - (ExecBlock.consReturn - (ExecStmt.return (liquidityAddDelta_evalReturnZ - (v := v) (evm := evm) (x := x) (y := y)))))))) - -theorem uniswapV3PoolLiquidityAddDeltaSourceNegativeReverts - {v : PoolImmutables} {evm x y} - (hy : y < 0) (hreq : ¬ liquidityAddDeltaWrappedSub x y < x) : - ExecFuncBody (config v) (liquidityAddDeltaFrame v x y) evm - liquidityAddDeltaFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [liquidityAddDeltaFunction] using - (ExecBlock.consRevert - (ExecStmt.iteTrue (liquidityAddDelta_evalYLtZeroTrue (v := v) (evm := evm) hy) - (ExecBlock.consNormal - (ExecStmt.letDecl (liquidityAddDelta_evalSubZ (v := v) (evm := evm))) - (ExecBlock.consRevert - (ExecStmt.requireFalse (liquidityAddDelta_evalZLtXFalse - (v := v) (evm := evm) (y := y) hreq)))))) - -theorem uniswapV3PoolLiquidityAddDeltaSourceNonnegativeReturns - {v : PoolImmutables} {evm x y} - (hy : ¬ y < 0) (hreq : liquidityAddDeltaWrappedAdd x y >= x) : - ExecFuncBody (config v) (liquidityAddDeltaFrame v x y) evm - liquidityAddDeltaFunction.body - (.returned (liquidityAddDeltaAfterZFrame v x y (liquidityAddDeltaWrappedAdd x y)) - evm (some [.int (liquidityAddDeltaWrappedAdd x y)])) := by - refine ExecFuncBody.execBlockRet ?_ - simpa [liquidityAddDeltaFunction] using - (ExecBlock.consReturn - (ExecStmt.iteFalse (liquidityAddDelta_evalYLtZeroFalse (v := v) (evm := evm) hy) - (ExecBlock.consNormal - (ExecStmt.letDecl (liquidityAddDelta_evalAddZ (v := v) (evm := evm))) - (ExecBlock.consNormal - (ExecStmt.requireTrue (liquidityAddDelta_evalZGeXTrue - (v := v) (evm := evm) (y := y) hreq)) - (ExecBlock.consReturn - (ExecStmt.return (liquidityAddDelta_evalReturnZ - (v := v) (evm := evm) (x := x) (y := y)))))))) - -theorem uniswapV3PoolLiquidityAddDeltaSourceNonnegativeReverts - {v : PoolImmutables} {evm x y} - (hy : ¬ y < 0) (hreq : ¬ liquidityAddDeltaWrappedAdd x y >= x) : - ExecFuncBody (config v) (liquidityAddDeltaFrame v x y) evm - liquidityAddDeltaFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [liquidityAddDeltaFunction] using - (ExecBlock.consRevert - (ExecStmt.iteFalse (liquidityAddDelta_evalYLtZeroFalse (v := v) (evm := evm) hy) - (ExecBlock.consNormal - (ExecStmt.letDecl (liquidityAddDelta_evalAddZ (v := v) (evm := evm))) - (ExecBlock.consRevert - (ExecStmt.requireFalse (liquidityAddDelta_evalZGeXFalse - (v := v) (evm := evm) (y := y) hreq)))))) - -theorem uniswapV3PoolLookupLiquidityAddDelta (v : PoolImmutables) : - lookupCallable? (contract v) "liquidityAddDelta" = - some liquidityAddDeltaFunction.toCallable := by - simp [lookupCallable?, lookupFunction?, contract, functions, getSqrtRatioAtTickFunction, - getTickAtSqrtRatioFunction, oracleLteFunction, oracleTransformFunction, - getSurroundingObservationsFunction, observeSingleFunction, observeBodyFunction, - liquidityAddDeltaFunction, oracleWriteFunction, tickGetFeeGrowthInsideFunction, - tickUpdateFunction, tickClearFunction, tickBitmapFlipFunction, positionUpdateFunction, - getAmount0DeltaUnsignedFunction, getAmount1DeltaUnsignedFunction, - getAmount0DeltaSignedFunction, getAmount1DeltaSignedFunction, modifyPositionFunction] - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnLowerLiquidityAddDeltaRevert.lean b/Benchmarks/UniswapV3Pool/BurnLowerLiquidityAddDeltaRevert.lean deleted file mode 100644 index ec47916b..00000000 --- a/Benchmarks/UniswapV3Pool/BurnLowerLiquidityAddDeltaRevert.lean +++ /dev/null @@ -1,456 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnTickUpdateTrace - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev burnLowerLiquidityAddDeltaTickLower (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) - -abbrev burnLowerLiquidityAddDeltaTickUpper (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) - -abbrev burnLowerLiquidityAddDeltaY (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) - -abbrev burnLowerLiquidityAddDeltaX (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - burnTickUpdateLowerLiquidityGrossBeforeWordEvm σ I - (burnLowerLiquidityAddDeltaTickLower I) - -noncomputable abbrev burnLowerLiquidityAddDeltaTail (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) (obsWord : UInt256) : List UInt256 := - burnTickUpdateLowerBaseSlotWord (burnLowerLiquidityAddDeltaTickLower I) :: - ⟨0⟩ :: EVM.wordOfInt v.maxLiquidityPerTick :: ⟨0⟩ :: - UInt256.ofNat I.header.timestamp :: - burnObserveSingleDecodedTickWord obsWord :: - burnObserveSingleDecodedSecondsWord obsWord :: - solcSlotWord σ I ⟨2⟩ :: - solcSlotWord σ I ⟨1⟩ :: - burnLowerLiquidityAddDeltaY I :: - slot0TickReturnWord σ I :: - burnLowerLiquidityAddDeltaTickLower I :: - ⟨5⟩ :: ⟨19331⟩ :: - burnObserveSingleDecodedSecondsWord obsWord :: - burnObserveSingleDecodedTickWord obsWord :: - UInt256.ofNat I.header.timestamp :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ I ⟨2⟩ :: - solcSlotWord σ I ⟨1⟩ :: - burnPositionBaseSlotWord σ I :: - slot0TickReturnWord σ I :: - burnLowerLiquidityAddDeltaY I :: - burnLowerLiquidityAddDeltaTickUpper I :: - burnLowerLiquidityAddDeltaTickLower I :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I] - -noncomputable abbrev burnLowerLiquidityAddDeltaEntryStack (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) (obsWord : UInt256) : List UInt256 := - burnLowerLiquidityAddDeltaY I :: - burnLowerLiquidityAddDeltaX σ I :: - ⟨20838⟩ :: ⟨0⟩ :: - burnLowerLiquidityAddDeltaX σ I :: - burnLowerLiquidityAddDeltaTail v σ I obsWord - -noncomputable abbrev burnLowerLiquidityAddDeltaReturnStack (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) (obsWord : UInt256) : List UInt256 := - UInt256.sub (burnLowerLiquidityAddDeltaX σ I) - (UInt256.sub ⟨0⟩ (burnLowerLiquidityAddDeltaY I)) :: - ⟨0⟩ :: - burnLowerLiquidityAddDeltaX σ I :: - burnLowerLiquidityAddDeltaTail v σ I obsWord - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnLowerLiquidityAddDeltaRevertBranch - {v : PoolImmutables} {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - {code : ByteArray} {σLockedEvm : AccountMap} {obsWord : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hdispatch : dispatchMsg (contract v) I.calldata = some burnTransition) - (hdecode : - decodeCalldataWithMode (config v).abiDecodeMode - (List.map Param.name burnTransition.params) - (transitionSignature burnTransition).paramTypes I.calldata = some (burnStore I)) - (hunlockedSolm : burnUnlockedByte σ_solm I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hAccountsAfterLock : - accountMapEquiv σLockedEvm - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I))) - (hobsBound : (slot0ObservationIndexWord σLockedEvm I).toNat < 65535) - (hobsWord : obsWord = burnObserveSingleSlotWord σLockedEvm I) - (hrevert : - ∃ _heq : UInt256.eq - (UInt256.land (UInt256.ofNat I.header.timestamp) observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩, - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I < - burnTickUpdateLowerLiquidityGrossBeforeInt - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I) - (hrdEntryOfEq : - ∀ _heq : UInt256.eq - (UInt256.land (UInt256.ofNat I.header.timestamp) observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩, - ∃ k' C', - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨13807⟩ - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - burnTickUpdateLowerLiquidityGrossBeforeWordEvm σLockedEvm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) :: - ⟨20838⟩ :: ⟨0⟩ :: - burnTickUpdateLowerLiquidityGrossBeforeWordEvm σLockedEvm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) :: - burnTickUpdateLowerBaseSlotWord - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) :: - ⟨0⟩ :: EVM.wordOfInt v.maxLiquidityPerTick :: ⟨0⟩ :: - UInt256.ofNat I.header.timestamp :: - burnObserveSingleDecodedTickWord obsWord :: - burnObserveSingleDecodedSecondsWord obsWord :: - solcSlotWord σLockedEvm I ⟨2⟩ :: - solcSlotWord σLockedEvm I ⟨1⟩ :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - slot0TickReturnWord σLockedEvm I :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - ⟨5⟩ :: ⟨19331⟩ :: - burnObserveSingleDecodedSecondsWord obsWord :: - burnObserveSingleDecodedTickWord obsWord :: - UInt256.ofNat I.header.timestamp :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σLockedEvm I ⟨2⟩ :: - solcSlotWord σLockedEvm I ⟨1⟩ :: - burnPositionBaseSlotWord σLockedEvm I :: - slot0TickReturnWord σLockedEvm I :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnTickUpdateLowerHashMem - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (burnObserveSingleDecodedMem σLockedEvm I obsWord)) - (UInt256.ofNat 21) ByteArray.empty (cA, σLockedEvm) k' C') : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - rcases hrevert with ⟨heq, hdelta⟩ - have hboundSolm : - (slot0ObservationIndexWord - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I).toNat < - 65535 := by - rw [← burnObserveSingleObservationIndexWord_transport hAccountsAfterLock] - exact hobsBound - have hsame := - burnObserveSingleSourceTimestampEqOfGuard hAccountsAfterLock hobsWord heq - have hbody := uniswapV3PoolBurnSourceLowerLiquidityAddDeltaReverts - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) - hwv hunlockedSolm hcanon hguard htickLt hge hle hnonzero hboundSolm hsame hdelta - have hiff := burnTickUpdateLowerLiquidityAddDeltaEvmCheck_iff - (σ_evm := σLockedEvm) - (σ_solm := sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) - (I := I) hAccountsAfterLock hcanon hnonzero - have hevmReqNe : - ¬ UInt256.lt - (UInt256.land uint128Mask - (UInt256.sub - (burnTickUpdateLowerLiquidityGrossBeforeWordEvm σLockedEvm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) - (UInt256.sub ⟨0⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))))) - (UInt256.land uint128Mask - (burnTickUpdateLowerLiquidityGrossBeforeWordEvm σLockedEvm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)))) ≠ ⟨0⟩ := by - intro hreq - exact hdelta (hiff.mpr hreq) - have hevmReqEq : - UInt256.lt - (UInt256.land uint128Mask - (UInt256.sub - (burnTickUpdateLowerLiquidityGrossBeforeWordEvm σLockedEvm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) - (UInt256.sub ⟨0⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))))) - (UInt256.land uint128Mask - (burnTickUpdateLowerLiquidityGrossBeforeWordEvm σLockedEvm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)))) = ⟨0⟩ := by - by_contra hne - exact hevmReqNe hne - have hneg := burnLiquidityDeltaNegativeSltJumpCond I hcanon hnonzero - rcases hrdEntryOfEq heq with ⟨_, _, hrdEntry⟩ - have hrdRevert := uniswapV3PoolLiquidityAddDeltaNegativeRevert - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (obsWord := obsWord) - (tickLower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (rdata := ByteArray.empty) (cA := cA) (σ := σLockedEvm) - hpatch hrdEntry hneg hevmReqEq - (by simp only [List.length_cons, List.length_nil]; omega) - exact hrdRevert.reEquivExecutionRevert hcode hdispatch hdecode hbody - -theorem uniswapV3PoolBurnLowerLiquidityAddDeltaReturnRD - {v : PoolImmutables} {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - {code : ByteArray} {σLockedEvm : AccountMap} {obsWord : UInt256} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hAccountsAfterLock : - accountMapEquiv σLockedEvm - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I))) - (hdelta : - burnTickUpdateLowerLiquidityGrossAfterSubInt - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I < - burnTickUpdateLowerLiquidityGrossBeforeInt - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I) - (hrdEntry : - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨13807⟩ - (burnLowerLiquidityAddDeltaEntryStack v σLockedEvm I obsWord) - (burnTickUpdateLowerHashMem (burnLowerLiquidityAddDeltaTickLower I) - (burnObserveSingleDecodedMem σLockedEvm I obsWord)) - (UInt256.ofNat 21) ByteArray.empty (cA, σLockedEvm) k C) : - ∃ k' C', - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨20838⟩ - (burnLowerLiquidityAddDeltaReturnStack v σLockedEvm I obsWord) - (burnTickUpdateLowerHashMem (burnLowerLiquidityAddDeltaTickLower I) - (burnObserveSingleDecodedMem σLockedEvm I obsWord)) - (UInt256.ofNat 21) ByteArray.empty (cA, σLockedEvm) k' C' := by - have hiff := burnTickUpdateLowerLiquidityAddDeltaEvmCheck_iff - (σ_evm := σLockedEvm) - (σ_solm := sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) - (I := I) hAccountsAfterLock hcanon hnonzero - have hreq : - UInt256.lt - (UInt256.land uint128Mask - (UInt256.sub (burnLowerLiquidityAddDeltaX σLockedEvm I) - (UInt256.sub ⟨0⟩ (burnLowerLiquidityAddDeltaY I)))) - (UInt256.land uint128Mask (burnLowerLiquidityAddDeltaX σLockedEvm I)) ≠ - ⟨0⟩ := by - simpa [burnLowerLiquidityAddDeltaX, burnLowerLiquidityAddDeltaY, - burnLowerLiquidityAddDeltaTickLower] using hiff.mp hdelta - have hneg : - UInt256.isZero (UInt256.slt - (UInt256.signextend ⟨15⟩ (burnLowerLiquidityAddDeltaY I)) ⟨0⟩) = - ⟨0⟩ := by - simpa [burnLowerLiquidityAddDeltaY] using - burnLiquidityDeltaNegativeSltJumpCond I hcanon hnonzero - simpa [burnLowerLiquidityAddDeltaReturnStack] using - (uniswapV3PoolLiquidityAddDeltaNegativeReturn - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (y := burnLowerLiquidityAddDeltaY I) - (x := burnLowerLiquidityAddDeltaX σLockedEvm I) - (ret := ⟨20838⟩) (scratch := ⟨0⟩) - (xCopy := burnLowerLiquidityAddDeltaX σLockedEvm I) - (R := burnLowerLiquidityAddDeltaTail v σLockedEvm I obsWord) - (mem := burnTickUpdateLowerHashMem (burnLowerLiquidityAddDeltaTickLower I) - (burnObserveSingleDecodedMem σLockedEvm I obsWord)) - (aw := UInt256.ofNat 21) (rdata := ByteArray.empty) (cA := cA) - (σ := σLockedEvm) hpatch hrdEntry hneg hreq - (uniswapV3PoolBurnJumpDestPatched20838 hpatch) - (by simp [burnLowerLiquidityAddDeltaTail])) - -theorem uniswapV3PoolBurnLowerMaxLiquidityRevertBranch - {v : PoolImmutables} {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - {code : ByteArray} {σLockedEvm : AccountMap} {obsWord : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hdispatch : dispatchMsg (contract v) I.calldata = some burnTransition) - (hdecode : - decodeCalldataWithMode (config v).abiDecodeMode - (List.map Param.name burnTransition.params) - (transitionSignature burnTransition).paramTypes I.calldata = some (burnStore I)) - (hunlockedSolm : burnUnlockedByte σ_solm I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hAccountsAfterLock : - accountMapEquiv σLockedEvm - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I))) - (hobsBound : (slot0ObservationIndexWord σLockedEvm I).toNat < 65535) - (hobsWord : obsWord = burnObserveSingleSlotWord σLockedEvm I) - (hrevert : - ∃ _heq : UInt256.eq - (UInt256.land (UInt256.ofNat I.header.timestamp) observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩, - burnTickUpdateLowerLiquidityGrossAfterSubInt - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I < - burnTickUpdateLowerLiquidityGrossBeforeInt - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I ∧ - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I <= - v.maxLiquidityPerTick) - (hrdEntryOfEq : - ∀ _heq : UInt256.eq - (UInt256.land (UInt256.ofNat I.header.timestamp) observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩, - ∃ k' C', - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨13807⟩ - (burnLowerLiquidityAddDeltaEntryStack v σLockedEvm I obsWord) - (burnTickUpdateLowerHashMem (burnLowerLiquidityAddDeltaTickLower I) - (burnObserveSingleDecodedMem σLockedEvm I obsWord)) - (UInt256.ofNat 21) ByteArray.empty (cA, σLockedEvm) k' C') : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - rcases hrevert with ⟨heq, hdelta, hmax⟩ - have hboundSolm : - (slot0ObservationIndexWord - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I).toNat < - 65535 := by - rw [← burnObserveSingleObservationIndexWord_transport hAccountsAfterLock] - exact hobsBound - have hsame := - burnObserveSingleSourceTimestampEqOfGuard hAccountsAfterLock hobsWord heq - have hbody := uniswapV3PoolBurnSourceLowerMaxLiquidityReverts - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) - hwv hunlockedSolm hcanon hguard htickLt hge hle hnonzero hboundSolm hsame hdelta hmax - rcases hrdEntryOfEq heq with ⟨_, _, hrdEntry⟩ - rcases uniswapV3PoolBurnLowerLiquidityAddDeltaReturnRD - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) - (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (code := code) (σLockedEvm := σLockedEvm) (obsWord := obsWord) - hpatch hcanon hnonzero hAccountsAfterLock hdelta hrdEntry with - ⟨_, _, hrd20838⟩ - have hmaxEvm := burnTickUpdateLowerMaxLiquidityEvmCheck_of_source - (v := v) (σ_evm := σLockedEvm) - (σ_solm := sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) - (I := I) hAccountsAfterLock hcanon hnonzero hdelta hmax - have hrdRevert := uniswapV3PoolBurnLowerMaxLiquidityRevert - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (obsWord := obsWord) (tickLower := burnLowerLiquidityAddDeltaTickLower I) - (rdata := ByteArray.empty) (cA := cA) (σ := σLockedEvm) hpatch - (by - simpa [burnLowerLiquidityAddDeltaReturnStack, burnLowerLiquidityAddDeltaTail] - using hrd20838) - (by - simpa [burnLowerLiquidityAddDeltaX, burnLowerLiquidityAddDeltaY, - burnLowerLiquidityAddDeltaTickLower] using hmaxEvm) - (by simp [burnLowerLiquidityAddDeltaTail]) - exact hrdRevert.reEquivExecutionRevert hcode hdispatch hdecode hbody - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnLowerLiquidityAddDeltaBranch - {v : PoolImmutables} {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} - {code : ByteArray} {σLockedEvm : AccountMap} {obsWord : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hdispatch : dispatchMsg (contract v) I.calldata = some burnTransition) - (hdecode : - decodeCalldataWithMode (config v).abiDecodeMode - (List.map Param.name burnTransition.params) - (transitionSignature burnTransition).paramTypes I.calldata = some (burnStore I)) - (hunlockedSolm : burnUnlockedByte σ_solm I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hAccountsAfterLock : - accountMapEquiv σLockedEvm - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I))) - (hobsBound : (slot0ObservationIndexWord σLockedEvm I).toNat < 65535) - (hobsWord : obsWord = burnObserveSingleSlotWord σLockedEvm I) - (hrdEntryOfEq : - ∀ _heq : UInt256.eq - (UInt256.land (UInt256.ofNat I.header.timestamp) observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩, - ∃ k' C', - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨13807⟩ - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - burnTickUpdateLowerLiquidityGrossBeforeWordEvm σLockedEvm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) :: - ⟨20838⟩ :: ⟨0⟩ :: - burnTickUpdateLowerLiquidityGrossBeforeWordEvm σLockedEvm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) :: - burnTickUpdateLowerBaseSlotWord - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) :: - ⟨0⟩ :: EVM.wordOfInt v.maxLiquidityPerTick :: ⟨0⟩ :: - UInt256.ofNat I.header.timestamp :: - burnObserveSingleDecodedTickWord obsWord :: - burnObserveSingleDecodedSecondsWord obsWord :: - solcSlotWord σLockedEvm I ⟨2⟩ :: - solcSlotWord σLockedEvm I ⟨1⟩ :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - slot0TickReturnWord σLockedEvm I :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - ⟨5⟩ :: ⟨19331⟩ :: - burnObserveSingleDecodedSecondsWord obsWord :: - burnObserveSingleDecodedTickWord obsWord :: - UInt256.ofNat I.header.timestamp :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σLockedEvm I ⟨2⟩ :: - solcSlotWord σLockedEvm I ⟨1⟩ :: - burnPositionBaseSlotWord σLockedEvm I :: - slot0TickReturnWord σLockedEvm I :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnTickUpdateLowerHashMem - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (burnObserveSingleDecodedMem σLockedEvm I obsWord)) - (UInt256.ofNat 21) ByteArray.empty (cA, σLockedEvm) k' C') : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - by_cases hrevert : - ∃ heq : UInt256.eq - (UInt256.land (UInt256.ofNat I.header.timestamp) observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩, - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I < - burnTickUpdateLowerLiquidityGrossBeforeInt - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I - · exact uniswapV3PoolBurnLowerLiquidityAddDeltaRevertBranch - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) - (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (code := code) (σLockedEvm := σLockedEvm) (obsWord := obsWord) - hpatch hcode hwv hdispatch hdecode hunlockedSolm hcanon hguard htickLt hge hle - hnonzero hAccountsAfterLock hobsBound hobsWord hrevert hrdEntryOfEq - · by_cases hmaxRevert : - ∃ heq : UInt256.eq - (UInt256.land (UInt256.ofNat I.header.timestamp) observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩, - burnTickUpdateLowerLiquidityGrossAfterSubInt - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I < - burnTickUpdateLowerLiquidityGrossBeforeInt - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I ∧ - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) I <= - v.maxLiquidityPerTick - · exact uniswapV3PoolBurnLowerMaxLiquidityRevertBranch - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) - (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (code := code) (σLockedEvm := σLockedEvm) (obsWord := obsWord) - hpatch hcode hwv hdispatch hdecode hunlockedSolm hcanon hguard htickLt hge hle - hnonzero hAccountsAfterLock hobsBound hobsWord hmaxRevert hrdEntryOfEq - · sorry - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnNoDelegate.lean b/Benchmarks/UniswapV3Pool/BurnNoDelegate.lean deleted file mode 100644 index e449a969..00000000 --- a/Benchmarks/UniswapV3Pool/BurnNoDelegate.lean +++ /dev/null @@ -1,217 +0,0 @@ -import Benchmarks.UniswapV3Pool.Burn - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev burnModifyPositionArgValues (I : ExecutionEnv) : List Value := - [ .address I.source, burnTickLowerValue I, burnTickUpperValue I, burnLiquidityDeltaValue I ] - -abbrev burnModifyPositionStore (I : ExecutionEnv) : Store := - ((((∅ : Store).insert "liquidityDelta" (burnLiquidityDeltaValue I)) - |>.insert "tickUpper" (burnTickUpperValue I)) - |>.insert "tickLower" (burnTickLowerValue I)) - |>.insert "owner" (.address I.source) - -theorem burnLiquidityDeltaFrame_tickLower {v : PoolImmutables} (I : ExecutionEnv) : - (burnLiquidityDeltaFrame v I).locals.get? "tickLower" = some (burnTickLowerValue I) := by - rw [burnLiquidityDeltaFrame, burnStore] - rw [store_get_ne3 ((∅ : Store).insert "tickLower" (burnTickLowerValue I)) - (k1 := "tickUpper") (k2 := "amount") (k3 := "liquidityDelta") - (a := "tickLower") (burnTickUpperValue I) (burnAmountValue I) - (burnLiquidityDeltaValue I) (by native_decide) (by native_decide) - (by native_decide)] - exact store_get_self (∅ : Store) "tickLower" (burnTickLowerValue I) - -theorem burnLiquidityDeltaFrame_tickUpper {v : PoolImmutables} (I : ExecutionEnv) : - (burnLiquidityDeltaFrame v I).locals.get? "tickUpper" = some (burnTickUpperValue I) := by - rw [burnLiquidityDeltaFrame, burnStore] - rw [store_get_ne2 (((∅ : Store).insert "tickLower" (burnTickLowerValue I)) - |>.insert "tickUpper" (burnTickUpperValue I)) (k1 := "amount") (k2 := "liquidityDelta") - (a := "tickUpper") (burnAmountValue I) (burnLiquidityDeltaValue I) - (by native_decide) (by native_decide)] - exact store_get_self ((∅ : Store).insert "tickLower" (burnTickLowerValue I)) - "tickUpper" (burnTickUpperValue I) - -theorem burnLiquidityDeltaFrame_liquidityDelta {v : PoolImmutables} (I : ExecutionEnv) : - (burnLiquidityDeltaFrame v I).locals.get? "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnLiquidityDeltaFrame, burnStore] - exact store_get_self - (((∅ : Store).insert "tickLower" (burnTickLowerValue I)) - |>.insert "tickUpper" (burnTickUpperValue I) - |>.insert "amount" (burnAmountValue I)) - "liquidityDelta" (burnLiquidityDeltaValue I) - -theorem uniswapV3PoolLookupModifyPosition (v : PoolImmutables) : - lookupCallable? (contract v) "modifyPosition" = some (modifyPositionFunction v).toCallable := by - simp [lookupCallable?, lookupFunction?, contract, functions, getSqrtRatioAtTickFunction, - getTickAtSqrtRatioFunction, oracleLteFunction, oracleTransformFunction, - getSurroundingObservationsFunction, observeSingleFunction, observeBodyFunction, - liquidityAddDeltaFunction, oracleWriteFunction, tickGetFeeGrowthInsideFunction, - tickUpdateFunction, tickClearFunction, tickBitmapFlipFunction, positionUpdateFunction, - getAmount0DeltaUnsignedFunction, getAmount1DeltaUnsignedFunction, - getAmount0DeltaSignedFunction, getAmount1DeltaSignedFunction, modifyPositionFunction] - -private theorem uniswapV3PoolBurnSharedTailPatchDisjoint33 {v : PoolImmutables} - {pc : UInt256} - (hlo : 16233 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 17313) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -private theorem uniswapV3PoolBurnSharedTailDecodeEqTemplate {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 16233 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 17313) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 17313 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolBurnSharedTailPatchDisjoint33 (v := v) (pc := pc) hlo hhi) - -theorem uniswapV3PoolBurnNoDelegateCallRevert {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨16233⟩ - (⟨128⟩ :: ⟨9737⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnModifyPositionMem4 ee) (UInt256.ofNat 8) rdata (cA, σ) k C) - (hguard : uniswapV3PoolNoDelegateCallGuard v ee = ⟨0⟩) - (hov : R.length + 19 ≤ 1024) : - RDrev code g s0 := by - have hd16233 : decode code ⟨16233⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16234 : decode code ⟨16234⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16236 : decode code ⟨16236⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16237 : decode code ⟨16237⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16239 : decode code ⟨16239⟩ = some (.Push .PUSH2, some (⟨16246⟩, 2)) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16242 : decode code ⟨16242⟩ = some (.Push .PUSH2, some (⟨11248⟩, 2)) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have hd16245 : decode code ⟨16245⟩ = some (.JUMP, .none) := by - rw [uniswapV3PoolBurnSharedTailDecodeEqTemplate hpatch (by native_decide) - (by native_decide)] - native_decide - have rd16234 := by - simpa using h.jumpdest hd16233 - (by simp only [List.length_cons]; omega) - have rd16236 := by - simpa using rd16234.push1 ⟨0⟩ hd16234 - (by simp only [List.length_cons]; omega) - have rd16237 := by - simpa using rd16236.dup1 hd16236 - (by simp only [List.length_cons]; omega) - have rd16239 := by - simpa using rd16237.push1 ⟨0⟩ hd16237 - (by simp only [List.length_cons]; omega) - have rd16242 := by - simpa using rd16239.push2 ⟨16246⟩ hd16239 - (by simp only [List.length_cons]; omega) - have rd16245 := by - simpa using rd16242.push2 ⟨11248⟩ hd16242 - (by simp only [List.length_cons]; omega) - have rd11248 := rd16245.jump hd16245 (uniswapV3PoolJumpDestPatched11248 hpatch) - (by simp only [List.length_cons]; omega) - exact uniswapV3PoolNoDelegateCallReturnRevert (v := v) (code := code) (ee := ee) - (g := g) (s0 := s0) (ret := ⟨16246⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (mem := burnModifyPositionMem4 ee) (aw := UInt256.ofNat 8) (rdata := rdata) - (acc := (cA, σ)) hpatch rd11248 hguard - (by simp only [List.length_cons]; omega) - -theorem uniswapV3PoolModifyPositionSourceNoDelegateReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I = ⟨0⟩) : - ExecFuncBody (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (modifyPositionFunction v).body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [modifyPositionFunction, noDelegateCall] using - (ExecBlock.consRevert - (ExecStmt.requireFalse (uniswapV3PoolNoDelegateCallEvalFalse - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (L := burnModifyPositionStore I) (g := g) hguard))) - -theorem uniswapV3PoolBurnSourceNoDelegateReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : burnUnlockedByte σ I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hguard : uniswapV3PoolNoDelegateCallGuard v I = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (burnStore I) - burnTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolBurnSourceThroughLiquidityDelta (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hunlocked hcanon - have hlockState : - Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I) = - initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - σ₀ g A I := by - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have hstmt : - ExecStmt (config v) (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - (.internalCall "modifyPosition" - [.env .caller, .var "tickLower", .var "tickUpper", .var "liquidityDelta"] - "modified") - .reverted := by - rw [hlockState] - refine internalCallFunctionRevert (callee := modifyPositionFunction v) - (argVals := burnModifyPositionArgValues I) (locals := burnModifyPositionStore I) - ?_ ?_ ?_ ?_ - · have hLower := burnLiquidityDeltaFrame_tickLower (v := v) I - have hUpper := burnLiquidityDeltaFrame_tickUpper (v := v) I - have hDelta := burnLiquidityDeltaFrame_liquidityDelta (v := v) I - simp only [burnModifyPositionArgValues, evalExprs?, evalExpr?, envValue, initState, - EvalResult.bind, bind, pure] - rw [hLower, hUpper, hDelta] - rfl - · simpa [burnLiquidityDeltaFrame] using uniswapV3PoolLookupModifyPosition v - · rfl - · exact uniswapV3PoolModifyPositionSourceNoDelegateReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) - (σ := sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hguard - simpa [burnTransition, nonpayable, lockPrefix] using - execBlock_append hprefix (ExecBlock.consRevert hstmt) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnNonzeroDeltaStart.lean b/Benchmarks/UniswapV3Pool/BurnNonzeroDeltaStart.lean deleted file mode 100644 index bec6c848..00000000 --- a/Benchmarks/UniswapV3Pool/BurnNonzeroDeltaStart.lean +++ /dev/null @@ -1,1555 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdate - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev burnBlockTimestamp32Value (I : ExecutionEnv) : Value := - .int (Int.ofNat ((UInt256.ofNat I.header.timestamp).toNat % 2 ^ (32 : Nat))) - -abbrev burnModifyPositionAfterTimeFrame - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals.insert - "time" (burnBlockTimestamp32Value I) } - -theorem burnEvalBlockTimestamp32AfterFeeGlobals {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) blockTimestamp32 = - .ok (burnBlockTimestamp32Value I) := by - unfold blockTimestamp32 uint32Wrap modE uint32Modulus burnBlockTimestamp32Value - simp only [evalExpr?, envValue, initState, EvalResult.bind, bind, pure, evalBinaryOp?] - norm_num - -theorem uniswapV3PoolModifyPositionSourceLiquidityDeltaNonzeroTimeStep - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) : - ExecStmt (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [.letDecl "time" (some uint32) blockTimestamp32] []) - (ExecResult.ok (burnModifyPositionAfterTimeFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - refine ExecStmt.iteTrue ?_ ?_ - · exact burnEvalLiquidityDeltaNeZeroTrue (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hnonzero - · exact ExecBlock.consNormal - (ExecStmt.letDecl (burnEvalBlockTimestamp32AfterFeeGlobals (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g))) - ExecBlock.nil - -abbrev burnPoolLiquidityWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (solcSlotWord σ I ⟨4⟩) uint128Mask - -abbrev burnPoolLiquidityValue (σ : AccountMap) (I : ExecutionEnv) : Value := - .int (Int.ofNat (burnPoolLiquidityWord σ I).toNat) - -abbrev burnObserveSingleArgValues (σ : AccountMap) (I : ExecutionEnv) : List Value := - [ burnBlockTimestamp32Value I, .int 0, burnSlot0TickValue σ I, - burnSlot0ObservationIndexValue σ I, burnPoolLiquidityValue σ I, - burnSlot0ObservationCardinalityValue σ I ] - -abbrev burnObserveSingleStore (σ : AccountMap) (I : ExecutionEnv) : Store := - ((((((∅ : Store) - |>.insert "cardinality" (burnSlot0ObservationCardinalityValue σ I)) - |>.insert "liquidity" (burnPoolLiquidityValue σ I)) - |>.insert "index" (burnSlot0ObservationIndexValue σ I)) - |>.insert "tick" (burnSlot0TickValue σ I)) - |>.insert "secondsAgo" (.int 0)) - |>.insert "time" (burnBlockTimestamp32Value I) - -theorem burnObserveSingleStore_secondsAgo (σ : AccountMap) (I : ExecutionEnv) : - (burnObserveSingleStore σ I).get? "secondsAgo" = some (.int 0) := by - rw [burnObserveSingleStore] - rw [store_get_ne - (L := (((((∅ : Store).insert "cardinality" (burnSlot0ObservationCardinalityValue σ I)) - |>.insert "liquidity" (burnPoolLiquidityValue σ I)) - |>.insert "index" (burnSlot0ObservationIndexValue σ I)) - |>.insert "tick" (burnSlot0TickValue σ I)) - |>.insert "secondsAgo" (.int 0)) - (k := "time") (a := "secondsAgo") (burnBlockTimestamp32Value I) - (by native_decide)] - exact store_get_self - ((((∅ : Store).insert "cardinality" (burnSlot0ObservationCardinalityValue σ I)) - |>.insert "liquidity" (burnPoolLiquidityValue σ I)) - |>.insert "index" (burnSlot0ObservationIndexValue σ I) - |>.insert "tick" (burnSlot0TickValue σ I)) - "secondsAgo" (.int 0) - -theorem burnObserveSingleStore_index (σ : AccountMap) (I : ExecutionEnv) : - (burnObserveSingleStore σ I).get? "index" = - some (burnSlot0ObservationIndexValue σ I) := by - rw [burnObserveSingleStore] - rw [store_get_ne3 - (L := (((∅ : Store).insert "cardinality" (burnSlot0ObservationCardinalityValue σ I)) - |>.insert "liquidity" (burnPoolLiquidityValue σ I)) - |>.insert "index" (burnSlot0ObservationIndexValue σ I)) - (k1 := "tick") (k2 := "secondsAgo") (k3 := "time") (a := "index") - (burnSlot0TickValue σ I) (.int 0) (burnBlockTimestamp32Value I) - (by native_decide) (by native_decide) (by native_decide)] - exact store_get_self - (((∅ : Store).insert "cardinality" (burnSlot0ObservationCardinalityValue σ I)) - |>.insert "liquidity" (burnPoolLiquidityValue σ I)) - "index" (burnSlot0ObservationIndexValue σ I) - -theorem burnObserveSingleStore_observations (σ : AccountMap) (I : ExecutionEnv) : - (burnObserveSingleStore σ I).get? "observations" = none := by - rw [burnObserveSingleStore] - rw [store_get_ne5 - (L := ((∅ : Store).insert "cardinality" (burnSlot0ObservationCardinalityValue σ I))) - (k1 := "liquidity") (k2 := "index") (k3 := "tick") - (k4 := "secondsAgo") (k5 := "time") (a := "observations") - (burnPoolLiquidityValue σ I) (burnSlot0ObservationIndexValue σ I) - (burnSlot0TickValue σ I) (.int 0) (burnBlockTimestamp32Value I) - (by native_decide) (by native_decide) (by native_decide) - (by native_decide) (by native_decide)] - rw [store_get_ne (L := (∅ : Store)) (k := "cardinality") (a := "observations") - (burnSlot0ObservationCardinalityValue σ I) (by native_decide)] - simp - -theorem burnEvalLiquidity {v : PoolImmutables} - {L : Store} {cA gh bl σ σ₀ A I} {g : Sat256} - (hbase : L.get? "liquidity" = none) : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) (.storage liquidityRef) = - .ok (burnPoolLiquidityValue σ I) := by - apply evalExpr_storage_scalar_value - (er := { base := "liquidity", steps := [] }) - (t := .int uint128Int) - (loc := loc ⟨4⟩ ⟨0, by decide⟩ ⟨16, by decide⟩ (by decide) (.int uint128Int)) - · simpa [liquidityRef] using hbase - · simp [evalStorageRef, liquidityRef, pure, bind, EvalResult.bind] - · simp [contract, storageDecls, storageTypeAt?, uint128St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc] - · simpa [initState, burnPoolLiquidityValue, burnPoolLiquidityWord, solcSlotWord, loc] using - (storageLocLoad_uint_offset0 (initState cA gh bl σ σ₀ g A I) ⟨4⟩ - ⟨16, by decide⟩ ⟨128, by decide⟩ (hbound := by decide) (by decide)) - -theorem burnModifyPosition_evalObserveSingleArgs {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExprs? (config v) (burnModifyPositionAfterTimeFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .var "time", .intLit 0, .storage (slot0F "tick"), - .storage (slot0F "observationIndex"), .storage liquidityRef, - .storage (slot0F "observationCardinality") ] = - .ok (burnObserveSingleArgValues σ I) := by - have htime : - (burnModifyPositionAfterTimeFrame v σ I).locals.get? "time" = - some (burnBlockTimestamp32Value I) := by - simp - have hslot0 : (burnModifyPositionAfterTimeFrame v σ I).locals.get? "slot0" = none := by - simp [burnModifyPositionStore] - have hliq : (burnModifyPositionAfterTimeFrame v σ I).locals.get? "liquidity" = none := by - simp [burnModifyPositionStore] - have htick := burnEvalSlot0Tick (v := v) - (L := (burnModifyPositionAfterTimeFrame v σ I).locals) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) hslot0 - have hindex := burnEvalSlot0ObservationIndex (v := v) - (L := (burnModifyPositionAfterTimeFrame v σ I).locals) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) hslot0 - have hcard := burnEvalSlot0ObservationCardinality (v := v) - (L := (burnModifyPositionAfterTimeFrame v σ I).locals) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) hslot0 - have hliquidity := burnEvalLiquidity (v := v) - (L := (burnModifyPositionAfterTimeFrame v σ I).locals) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) hliq - simp [evalExprs?, evalExpr?, EvalResult.ofOption, EvalResult.bind, bind, pure, - htick, hindex, hliquidity, hcard, burnObserveSingleArgValues] - -theorem burnObserveSingle_bindParams (σ : AccountMap) (I : ExecutionEnv) : - bindParams? observeSingleFunction.params (burnObserveSingleArgValues σ I) = - some (burnObserveSingleStore σ I) := by - rfl - -theorem uniswapV3PoolLookupObserveSingle (v : PoolImmutables) : - lookupCallable? (contract v) "observeSingle" = some observeSingleFunction.toCallable := by - simp [lookupCallable?, lookupFunction?, contract, functions, getSqrtRatioAtTickFunction, - getTickAtSqrtRatioFunction, oracleLteFunction, oracleTransformFunction, - getSurroundingObservationsFunction, observeSingleFunction, observeBodyFunction, - liquidityAddDeltaFunction, oracleWriteFunction, tickGetFeeGrowthInsideFunction, - tickUpdateFunction, tickClearFunction, tickBitmapFlipFunction, positionUpdateFunction, - getAmount0DeltaUnsignedFunction, getAmount1DeltaUnsignedFunction, - getAmount0DeltaSignedFunction, getAmount1DeltaSignedFunction, modifyPositionFunction] - -theorem burnObserveSingleEvalSecondsAgoZero {v : PoolImmutables} {σ I evm} : - evalExpr? (config v) { contract := contract v, locals := burnObserveSingleStore σ I } evm - (eqE (.var "secondsAgo") (.intLit 0)) = .ok (.bool true) := by - unfold eqE - simp only [evalExpr?, EvalResult.bind, bind, pure] - rw [burnObserveSingleStore_secondsAgo] - rfl - -theorem burnObserveSingleEvalIndex {v : PoolImmutables} {σ I evm} : - evalExpr? (config v) { contract := contract v, locals := burnObserveSingleStore σ I } evm - (.var "index") = .ok (burnSlot0ObservationIndexValue σ I) := by - simp only [evalExpr?] - rw [burnObserveSingleStore_index] - rfl - -theorem burnObserveSingleEvalIndexLtBoundFalse {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hoob : 65535 ≤ (slot0ObservationIndexWord σ I).toNat) : - evalExpr? (config v) { contract := contract v, locals := burnObserveSingleStore σ I } - (initState cA gh bl σ σ₀ g A I) (ltE (.var "index") (.intLit 65535)) = - .ok (.bool false) := by - unfold ltE - simp only [evalExpr?, burnObserveSingleEvalIndex, EvalResult.bind, bind, pure, evalBinaryOp?] - have hnot : ¬ Int.ofNat (slot0ObservationIndexWord σ I).toNat < (65535 : Int) := by - intro hlt - have hltNat : (slot0ObservationIndexWord σ I).toNat < 65535 := by - exact Int.ofNat_lt.mp hlt - exact not_lt_of_ge hoob hltNat - rw [show decide (Int.ofNat (slot0ObservationIndexWord σ I).toNat < 65535) = false from - decide_eq_false hnot] - -theorem burnObserveSingleEvalIndexLtBoundTrue {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hbound : (slot0ObservationIndexWord σ I).toNat < 65535) : - evalExpr? (config v) { contract := contract v, locals := burnObserveSingleStore σ I } - (initState cA gh bl σ σ₀ g A I) (ltE (.var "index") (.intLit 65535)) = - .ok (.bool true) := by - unfold ltE - simp only [evalExpr?, burnObserveSingleEvalIndex, EvalResult.bind, bind, pure, evalBinaryOp?] - have hlt : Int.ofNat (slot0ObservationIndexWord σ I).toNat < (65535 : Int) := by - change ((slot0ObservationIndexWord σ I).toNat : Int) < (65535 : Int) - exact_mod_cast hbound - rw [show decide (Int.ofNat (slot0ObservationIndexWord σ I).toNat < 65535) = true from - decide_eq_true hlt] - -theorem uniswapV3PoolObserveSingleSourceIndexOobReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hoob : 65535 ≤ (slot0ObservationIndexWord σ I).toNat) : - ExecFuncBody (config v) - { contract := contract v, locals := burnObserveSingleStore σ I } - (initState cA gh bl σ σ₀ g A I) observeSingleFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [observeSingleFunction] using - (ExecBlock.consRevert - (ExecStmt.iteTrue (burnObserveSingleEvalSecondsAgoZero (v := v) (σ := σ) (I := I) - (evm := initState cA gh bl σ σ₀ g A I)) - (ExecBlock.consRevert - (ExecStmt.requireFalse (burnObserveSingleEvalIndexLtBoundFalse (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hoob))))) - -private def burnModifyPositionObserveSingleOobTail (_v : PoolImmutables) : List Stmt := - [ .internalCall "tickGetFeeGrowthInside" - [ .var "tickLower", .var "tickUpper", .var "_slot0tick", - .var "_feeGrowthGlobal0X128", .var "_feeGrowthGlobal1X128" ] - "feeGrowthInside", - .internalCall "positionUpdate" - [ .var "_positionKey", .var "liquidityDelta", tuple0 (.var "feeGrowthInside"), - tuple1 (.var "feeGrowthInside") ] - "_positionUpdated", - Stmt.ite (ltE (.var "liquidityDelta") (.intLit 0)) - [ Stmt.ite (.var "flippedLower") - [ .internalCall "tickClear" [.var "tickLower"] "_clearLower" ] - [], - Stmt.ite (.var "flippedUpper") - [ .internalCall "tickClear" [.var "tickUpper"] "_clearUpper" ] - [] ] - [], - .letDecl "amount0" (some int256) (.intLit 0), - .letDecl "amount1" (some int256) (.intLit 0), - Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ Stmt.ite (ltE (.var "_slot0tick") (.var "tickLower")) - [ .internalCall "getSqrtRatioAtTick" [.var "tickLower"] "sqrtRatioLowerBelow", - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] "sqrtRatioUpperBelow", - .internalCall "getAmount0DeltaSigned" - [ .var "sqrtRatioLowerBelow", .var "sqrtRatioUpperBelow", - .var "liquidityDelta" ] - "amount0Below", - .assign .localVar (varRef "amount0") (.var "amount0Below") ] - [ Stmt.ite (ltE (.var "_slot0tick") (.var "tickUpper")) - [ .letDecl "liquidityBefore" (some uint128) (.storage liquidityRef), - .internalCall "oracleWrite" - [ .var "_slot0observationIndex", blockTimestamp32, .var "_slot0tick", - .var "liquidityBefore", .var "_slot0observationCardinality", - .var "_slot0observationCardinalityNext" ] - "oracleUpdated", - .assign .storage (slot0F "observationIndex") (tuple0 (.var "oracleUpdated")), - .assign .storage (slot0F "observationCardinality") - (tuple1 (.var "oracleUpdated")), - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] - "sqrtRatioUpperInside", - .internalCall "getAmount0DeltaSigned" - [ .var "_slot0sqrtPriceX96", .var "sqrtRatioUpperInside", - .var "liquidityDelta" ] - "amount0Inside", - .assign .localVar (varRef "amount0") (.var "amount0Inside"), - .internalCall "getSqrtRatioAtTick" [.var "tickLower"] - "sqrtRatioLowerInside", - .internalCall "getAmount1DeltaSigned" - [ .var "sqrtRatioLowerInside", .var "_slot0sqrtPriceX96", - .var "liquidityDelta" ] - "amount1Inside", - .assign .localVar (varRef "amount1") (.var "amount1Inside"), - .internalCall "liquidityAddDelta" - [ .var "liquidityBefore", .var "liquidityDelta" ] - "liquidityAfter", - .assign .storage liquidityRef (.var "liquidityAfter") ] - [ .internalCall "getSqrtRatioAtTick" [.var "tickLower"] - "sqrtRatioLowerAbove", - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] - "sqrtRatioUpperAbove", - .internalCall "getAmount1DeltaSigned" - [ .var "sqrtRatioLowerAbove", .var "sqrtRatioUpperAbove", - .var "liquidityDelta" ] - "amount1Above", - .assign .localVar (varRef "amount1") (.var "amount1Above") ] ] ] - [], - .return [.var "_positionKey", .var "amount0", .var "amount1"] ] - -theorem uniswapV3PoolModifyPositionSourceObserveSingleOobReverts - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hoob : 65535 ≤ (slot0ObservationIndexWord σ I).toNat) : - ExecFuncBody (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (modifyPositionFunction v).body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolModifyPositionSourceThroughFeeGrowthGlobals (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard htickLt hge hle - have hstep : ExecBlock (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (burnModifyPositionLiquidityDeltaUpdateStep v) .reverted := by - refine ExecBlock.consRevert ?_ - refine ExecStmt.iteTrue ?_ ?_ - · exact burnEvalLiquidityDeltaNeZeroTrue (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hnonzero - · refine ExecBlock.consNormal - (solm' := burnModifyPositionAfterTimeFrame v σ I) - (evm' := initState cA gh bl σ σ₀ g A I) ?_ ?_ - · exact ExecStmt.letDecl (burnEvalBlockTimestamp32AfterFeeGlobals (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g)) - · refine ExecBlock.consRevert ?_ - refine internalCallFunctionRevert (callee := observeSingleFunction) - (argVals := burnObserveSingleArgValues σ I) - (locals := burnObserveSingleStore σ I) ?_ ?_ ?_ ?_ - · exact burnModifyPosition_evalObserveSingleArgs (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) - · simpa [burnModifyPositionAfterTimeFrame] using uniswapV3PoolLookupObserveSingle v - · exact burnObserveSingle_bindParams σ I - · simpa [burnModifyPositionAfterTimeFrame] using - uniswapV3PoolObserveSingleSourceIndexOobReverts (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) hoob - have hmid := execBlock_append hprefix hstep - have hfull := - execBlock_append_term (s2 := burnModifyPositionObserveSingleOobTail v) hmid (by - intro f e h - cases h) - simpa [modifyPositionFunction, burnModifyPositionSlot0Prefix, - burnModifyPositionPositionKeyStep, burnModifyPositionFeeGrowthGlobalsStep, - burnModifyPositionLiquidityDeltaUpdateStep, burnModifyPositionObserveSingleOobTail] - using hfull - -theorem uniswapV3PoolBurnSourceObserveSingleOobReverts - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : burnUnlockedByte σ I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hoob : - 65535 ≤ - (slot0ObservationIndexWord - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I).toNat) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (burnStore I) - burnTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolBurnSourceThroughLiquidityDelta (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hunlocked hcanon - have hlockState : - Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I) = - initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - σ₀ g A I := by - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have hstmt : - ExecStmt (config v) (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - (.internalCall "modifyPosition" - [.env .caller, .var "tickLower", .var "tickUpper", .var "liquidityDelta"] - "modified") - .reverted := by - rw [hlockState] - refine internalCallFunctionRevert (callee := modifyPositionFunction v) - (argVals := burnModifyPositionArgValues I) (locals := burnModifyPositionStore I) - ?_ ?_ ?_ ?_ - · have hLower := burnLiquidityDeltaFrame_tickLower (v := v) I - have hUpper := burnLiquidityDeltaFrame_tickUpper (v := v) I - have hDelta := burnLiquidityDeltaFrame_liquidityDelta (v := v) I - simp only [burnModifyPositionArgValues, evalExprs?, evalExpr?, envValue, initState, - EvalResult.bind, bind, pure] - rw [hLower, hUpper, hDelta] - rfl - · simpa [burnLiquidityDeltaFrame] using uniswapV3PoolLookupModifyPosition v - · rfl - · exact uniswapV3PoolModifyPositionSourceObserveSingleOobReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) - (σ := sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - (σ₀ := σ₀) (A := A) (I := I) (g := g) - hguard htickLt hge hle hnonzero hoob - simpa [burnTransition, nonpayable, lockPrefix] using - execBlock_append hprefix (ExecBlock.consRevert hstmt) - -private theorem uniswapV3PoolBurnNonzeroTimestampDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 11291 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega) - -private theorem uniswapV3PoolBurnNonzeroStartDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 19189 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 19295 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega) - -private theorem uniswapV3PoolBurnObserveSingleZeroDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 13193 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13241) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 13241 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega) - -private theorem uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 13208 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13274) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 13274 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega) - -private theorem uniswapV3PoolBurnNonzeroShortPatchDisjoint {v : PoolImmutables} - {pc : UInt256} {n : Nat} (hlo : 19189 ≤ pc.toNat) (hhi : pc.toNat + n ≤ 19295) : - ∀ p ∈ patches v, pc.toNat + n ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolBurnNonzeroDecodePatchedPush1 {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 2 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 2 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x60) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1)) = n) : - decode code pc = some (.Push .PUSH1, some (n, 1)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + 1) = - uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1) := by - unfold ByteArray.extract' - have hguard : - (decide (pc.toNat.succ < 2 ^ 64) && decide (pc.toNat.succ + 1 < 2 ^ 64)) = - true := by - rw [Bool.and_eq_true] - constructor <;> rw [decide_eq_true_eq] <;> omega - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq (start := pc.toNat.succ) (stop := pc.toNat.succ + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl hbefore - · exact Or.inr (by omega)) - hpatch - have hgetSome : code.get? pc.toNat = some 0x60 := by - rw [hget, hgetTemplate] - have hparse : (some (0x60 : UInt8) >>= parseInstr) = some (.Push .PUSH1) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH1, - some (uInt256OfByteArray (code.extract' pc.toNat.succ (pc.toNat.succ + 1)), 1)) = - some (Operation.Push Operation.POp.PUSH1, some (n, 1)) - rw [hextract, hval] - -private theorem uniswapV3PoolBurnNonzeroDecodePatchedPush2 {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 3 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 3 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x61) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 2)) = n) : - decode code pc = some (.Push .PUSH2, some (n, 2)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + 2) = - uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 2) := by - unfold ByteArray.extract' - have hguard : - (decide (pc.toNat.succ < 2 ^ 64) && decide (pc.toNat.succ + 2 < 2 ^ 64)) = - true := by - rw [Bool.and_eq_true] - constructor <;> rw [decide_eq_true_eq] <;> omega - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq (start := pc.toNat.succ) (stop := pc.toNat.succ + 2) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl hbefore - · exact Or.inr (by omega)) - hpatch - have hgetSome : code.get? pc.toNat = some 0x61 := by - rw [hget, hgetTemplate] - have hparse : (some (0x61 : UInt8) >>= parseInstr) = some (.Push .PUSH2) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH2, - some (uInt256OfByteArray (code.extract' pc.toNat.succ (pc.toNat.succ + 2)), 2)) = - some (Operation.Push Operation.POp.PUSH2, some (n, 2)) - rw [hextract, hval] - -private theorem uniswapV3PoolBurnNonzeroPatchPreservesJumpDest11303 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11303⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolBurnJumpDestPatched11303 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11303⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolBurnNonzeroPatchPreservesJumpDest11303 - -private theorem uniswapV3PoolBurnNonzeroPatchPreservesJumpDest19199 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨19199⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolBurnJumpDestPatched19199 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨19199⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolBurnNonzeroPatchPreservesJumpDest19199 - -private theorem uniswapV3PoolBurnNonzeroPatchPreservesJumpDest13193 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨13193⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolBurnJumpDestPatched13193 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨13193⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolBurnNonzeroPatchPreservesJumpDest13193 - -private theorem uniswapV3PoolBurnNonzeroPatchPreservesJumpDest13226 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨13226⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolBurnJumpDestPatched13226 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨13226⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolBurnNonzeroPatchPreservesJumpDest13226 - -theorem uniswapV3PoolBurnAfterFeeGlobalsNonzeroToTimestampReturn - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {ret : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcond : - UInt256.isZero - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)))) = ⟨0⟩) - (h : RD code ee g s0 ⟨19189⟩ - (⟨19492⟩ :: - UInt256.isZero - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)))) :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 58 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨19200⟩ - (UInt256.ofNat ee.header.timestamp :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - obtain ⟨_, _, h19190⟩ := - uniswapV3PoolBurnAfterFeeGlobalsLiquidityDeltaNonzeroFallthrough - hpatch hcond h (by - have hlen := hov - omega) - have hd19190 : decode code ⟨19190⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19192 : decode code ⟨19192⟩ = some (.Push .PUSH2, some (⟨19199⟩, 2)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19195 : decode code ⟨19195⟩ = some (.Push .PUSH2, some (⟨11303⟩, 2)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19198 : decode code ⟨19198⟩ = some (.JUMP, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19199 : decode code ⟨19199⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd11303 : decode code ⟨11303⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnNonzeroTimestampDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd11304 : decode code ⟨11304⟩ = some (.TIMESTAMP, .none) := by - rw [uniswapV3PoolBurnNonzeroTimestampDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd11305 : decode code ⟨11305⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnNonzeroTimestampDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd11306 : decode code ⟨11306⟩ = some (.JUMP, .none) := by - rw [uniswapV3PoolBurnNonzeroTimestampDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have h19198 := evm_run h19190 with [ - raw push1 ⟨0⟩ hd19190 (by evm_ov), - raw push2 ⟨19199⟩ hd19192 (by evm_ov), - raw push2 ⟨11303⟩ hd19195 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega)] - have h11303 := h19198.jump hd19198 (uniswapV3PoolBurnJumpDestPatched11303 hpatch) - (by evm_ov) - have h11306 := evm_run h11303 with [ - raw jumpdest hd11303 (by evm_ov), - raw timestamp hd11304 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw swap1 hd11305 (by evm_ov)] - have h19199 := h11306.jump hd11306 (uniswapV3PoolBurnJumpDestPatched19199 hpatch) - (by evm_ov) - exact ⟨_, _, evm_run h19199 with [ - raw jumpdest hd19199 (by evm_ov)]⟩ - -theorem uniswapV3PoolBurnAfterFeeGlobalsNonzeroTimestampToSlot0LiquidityLoaded - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {ret : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨19200⟩ - (UInt256.ofNat ee.header.timestamp :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 58 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨19214⟩ - (solcSlotWord σ ee ⟨0⟩ :: solcSlotWord σ ee ⟨4⟩ :: - ⟨0⟩ :: ⟨0⟩ :: UInt256.ofNat ee.header.timestamp :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hd19200 : decode code ⟨19200⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19202 : decode code ⟨19202⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19203 : decode code ⟨19203⟩ = some (.SLOAD, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19204 : decode code ⟨19204⟩ = some (.Push .PUSH1, some (⟨4⟩, 1)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19206 : decode code ⟨19206⟩ = some (.SLOAD, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19207 : decode code ⟨19207⟩ = some (.SWAP3, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19208 : decode code ⟨19208⟩ = some (.SWAP4, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19209 : decode code ⟨19209⟩ = some (.POP, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19210 : decode code ⟨19210⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19211 : decode code ⟨19211⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19212 : decode code ⟨19212⟩ = some (.DUP3, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19213 : decode code ⟨19213⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have h19203 := evm_run h with [ - raw push1 ⟨0⟩ hd19200 (by evm_ov), - raw dup1 hd19202 (by evm_ov)] - obtain ⟨_, _, h19204⟩ := h19203.sload hd19203 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h19206 := evm_run h19204 with [ - raw push1 ⟨4⟩ hd19204 (by evm_ov)] - obtain ⟨_, _, h19207⟩ := h19206.sload hd19206 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - exact ⟨_, _, evm_run h19207 with [ - raw swap3 hd19207 (by evm_ov), - raw swap4 hd19208 (by evm_ov), - raw pop hd19209 (by evm_ov), - raw swap1 hd19210 (by evm_ov), - raw swap2 hd19211 (by evm_ov), - raw dup3 hd19212 (by evm_ov), - raw swap2 hd19213 (by evm_ov)]⟩ - -theorem uniswapV3PoolBurnAfterFeeGlobalsNonzeroSlot0LiquidityToObserveSingleEntry - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {ret : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨19214⟩ - (solcSlotWord σ ee ⟨0⟩ :: solcSlotWord σ ee ⟨4⟩ :: - ⟨0⟩ :: ⟨0⟩ :: UInt256.ofNat ee.header.timestamp :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 64 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨13193⟩ - (((solcSlotWord σ ee ⟨0⟩).div ((⟨1⟩ : UInt256).shiftLeft ⟨200⟩)).land ⟨65535⟩ :: - (solcSlotWord σ ee ⟨4⟩).land (((⟨1⟩ : UInt256).shiftLeft ⟨128⟩).sub ⟨1⟩) :: - (⟨65535⟩ : UInt256).land - ((solcSlotWord σ ee ⟨0⟩).div ((⟨1⟩ : UInt256).shiftLeft ⟨184⟩)) :: - (⟨2⟩ : UInt256).signextend - ((solcSlotWord σ ee ⟨0⟩).div ((⟨1⟩ : UInt256).shiftLeft ⟨160⟩)) :: - ⟨0⟩ :: UInt256.ofNat ee.header.timestamp :: ⟨8⟩ :: ⟨19273⟩ :: - ⟨0⟩ :: ⟨0⟩ :: UInt256.ofNat ee.header.timestamp :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: burnTickLowerCleanWord ee :: - ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hd19214 : decode code ⟨19214⟩ = some (.Push .PUSH2, some (⟨19273⟩, 2)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19217 : decode code ⟨19217⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19218 : decode code ⟨19218⟩ = some (.Push .PUSH1, some (⟨8⟩, 1)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19220 : decode code ⟨19220⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19221 : decode code ⟨19221⟩ = some (.DUP7, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19222 : decode code ⟨19222⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19223 : decode code ⟨19223⟩ = some (.DUP6, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19224 : decode code ⟨19224⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19225 : decode code ⟨19225⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19227 : decode code ⟨19227⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19229 : decode code ⟨19229⟩ = some (.SHL, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19230 : decode code ⟨19230⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19231 : decode code ⟨19231⟩ = some (.DIV, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19232 : decode code ⟨19232⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19234 : decode code ⟨19234⟩ = some (.SIGNEXTEND, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19235 : decode code ⟨19235⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19236 : decode code ⟨19236⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19239 : decode code ⟨19239⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19241 : decode code ⟨19241⟩ = some (.Push .PUSH1, some (⟨184⟩, 1)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19243 : decode code ⟨19243⟩ = some (.SHL, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19244 : decode code ⟨19244⟩ = some (.DUP4, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19245 : decode code ⟨19245⟩ = some (.DIV, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19246 : decode code ⟨19246⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19247 : decode code ⟨19247⟩ = some (.AND, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19248 : decode code ⟨19248⟩ = some (.SWAP3, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19249 : decode code ⟨19249⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19251 : decode code ⟨19251⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19253 : decode code ⟨19253⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19255 : decode code ⟨19255⟩ = some (.SHL, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19256 : decode code ⟨19256⟩ = some (.SUB, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19257 : decode code ⟨19257⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19258 : decode code ⟨19258⟩ = some (.SWAP3, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19259 : decode code ⟨19259⟩ = some (.AND, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19260 : decode code ⟨19260⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19261 : decode code ⟨19261⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [uniswapV3PoolBurnNonzeroStartDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd19263 : decode code ⟨19263⟩ = some (.Push .PUSH1, some (⟨200⟩, 1)) := by - exact uniswapV3PoolBurnNonzeroDecodePatchedPush1 hpatch (by native_decide) - (uniswapV3PoolBurnNonzeroShortPatchDisjoint - (pc := ⟨19263⟩) (n := 2) (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd19265 : decode code ⟨19265⟩ = some (.SHL, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19265⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnNonzeroShortPatchDisjoint - (pc := ⟨19265⟩) (n := 1) (by native_decide) (by native_decide) - have hd19266 : decode code ⟨19266⟩ = some (.SWAP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19266⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnNonzeroShortPatchDisjoint - (pc := ⟨19266⟩) (n := 1) (by native_decide) (by native_decide) - have hd19267 : decode code ⟨19267⟩ = some (.DIV, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19267⟩) (byte := 0x04) - (op := .DIV) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnNonzeroShortPatchDisjoint - (pc := ⟨19267⟩) (n := 1) (by native_decide) (by native_decide) - have hd19268 : decode code ⟨19268⟩ = some (.AND, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19268⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnNonzeroShortPatchDisjoint - (pc := ⟨19268⟩) (n := 1) (by native_decide) (by native_decide) - have hd19269 : decode code ⟨19269⟩ = some (.Push .PUSH2, some (⟨13193⟩, 2)) := by - exact uniswapV3PoolBurnNonzeroDecodePatchedPush2 hpatch (by native_decide) - (uniswapV3PoolBurnNonzeroShortPatchDisjoint - (pc := ⟨19269⟩) (n := 3) (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd19272 : decode code ⟨19272⟩ = some (.JUMP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19272⟩) (byte := 0x56) - (op := .JUMP) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnNonzeroShortPatchDisjoint - (pc := ⟨19272⟩) (n := 1) (by native_decide) (by native_decide) - have h19234 := evm_run h with [ - raw push2 ⟨19273⟩ hd19214 (by evm_ov), - raw swap2 hd19217 (by evm_ov), - raw push1 ⟨8⟩ hd19218 (by evm_ov), - raw swap2 hd19220 (by evm_ov), - raw dup7 hd19221 (by evm_ov), - raw swap2 hd19222 (by evm_ov), - raw dup6 hd19223 (by evm_ov), - raw swap2 hd19224 (by evm_ov), - raw push1 ⟨1⟩ hd19225 (by evm_ov), - raw push1 ⟨160⟩ hd19227 (by evm_ov), - raw shl hd19229 (by evm_ov), - raw dup2 hd19230 (by evm_ov), - raw div hd19231 (by evm_ov), - raw push1 ⟨2⟩ hd19232 (by evm_ov)] - have h19235 := RD.signextend h19234 hd19234 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h19272 := evm_run h19235 with [ - raw swap2 hd19235 (by evm_ov), - raw push2 ⟨65535⟩ hd19236 (by evm_ov), - raw push1 ⟨1⟩ hd19239 (by evm_ov), - raw push1 ⟨184⟩ hd19241 (by evm_ov), - raw shl hd19243 (by evm_ov), - raw dup4 hd19244 (by evm_ov), - raw div hd19245 (by evm_ov), - raw dup2 hd19246 (by evm_ov), - raw and hd19247 (by evm_ov), - raw swap3 hd19248 (by evm_ov), - raw push1 ⟨1⟩ hd19249 (by evm_ov), - raw push1 ⟨1⟩ hd19251 (by evm_ov), - raw push1 ⟨128⟩ hd19253 (by evm_ov), - raw shl hd19255 (by evm_ov), - raw sub hd19256 (by evm_ov), - raw swap1 hd19257 (by evm_ov), - raw swap3 hd19258 (by evm_ov), - raw and hd19259 (by evm_ov), - raw swap2 hd19260 (by evm_ov), - raw push1 ⟨1⟩ hd19261 (by evm_ov), - raw push1 ⟨200⟩ hd19263 (by evm_ov), - raw shl hd19265 (by evm_ov), - raw swap1 hd19266 (by evm_ov), - raw div hd19267 (by evm_ov), - raw and hd19268 (by evm_ov), - raw push2 ⟨13193⟩ hd19269 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega)] - exact ⟨_, _, h19272.jump hd19272 (uniswapV3PoolBurnJumpDestPatched13193 hpatch) - (by evm_ov)⟩ - -theorem uniswapV3PoolBurnObserveSingleSecondsAgoZeroFallthrough - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cardinality liquidity index tick time memPtr ret : UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13193⟩ - (cardinality :: liquidity :: index :: tick :: ⟨0⟩ :: time :: memPtr :: ret :: R) - mem aw rdata (cA, σ) k C) - (hov : R.length + 12 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨13208⟩ - (⟨0⟩ :: ⟨0⟩ :: - cardinality :: liquidity :: index :: tick :: ⟨0⟩ :: time :: memPtr :: ret :: R) - mem aw rdata (cA, σ) k' C' := by - have hd13193 : decode code ⟨13193⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnObserveSingleZeroDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13194 : decode code ⟨13194⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [uniswapV3PoolBurnObserveSingleZeroDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13196 : decode code ⟨13196⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolBurnObserveSingleZeroDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13197 : - decode code ⟨13197⟩ = some (.Push .PUSH4, some (⟨4294967295⟩, 4)) := by - rw [uniswapV3PoolBurnObserveSingleZeroDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13202 : decode code ⟨13202⟩ = some (.DUP8, .none) := by - rw [uniswapV3PoolBurnObserveSingleZeroDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13203 : decode code ⟨13203⟩ = some (.AND, .none) := by - rw [uniswapV3PoolBurnObserveSingleZeroDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13204 : decode code ⟨13204⟩ = some (.Push .PUSH2, some (⟨13360⟩, 2)) := by - rw [uniswapV3PoolBurnObserveSingleZeroDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13207 : decode code ⟨13207⟩ = some (.JUMPI, .none) := by - rw [uniswapV3PoolBurnObserveSingleZeroDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have h13194 := h.jumpdest hd13193 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h13207 := evm_run h13194 with [ - raw push1 ⟨0⟩ hd13194 (by evm_ov), - raw dup1 hd13196 (by evm_ov), - raw push4 ⟨4294967295⟩ hd13197 (by evm_ov), - raw dup8 hd13202 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw and hd13203 (by evm_ov), - raw push2 ⟨13360⟩ hd13204 (by evm_ov)] - exact ⟨_, _, h13207.jumpiNT hd13207 (by native_decide) (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega)⟩ - -theorem burnRDInvalidError {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {pc : UInt256} {stk : List UInt256} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (h : RD code ee g s0 pc stk mem aw rdata acc k C) - (hdec : decode code pc = some (.INVALID, .none)) : - X (g.toNat + 1) (D_J code 0) s0 = .error .OutOfGass ∨ - X (g.toNat + 1) (D_J code 0) s0 = .error .InvalidInstruction := by - rcases RD.conclude h with hoog | ⟨k', C', s', hX, hcode, hpc, _hstk, _hgas, hk, hC, - _hmem, _haw, _hrdata, _hacc⟩ - · exact Or.inl hoog - · have hdec' : decode s'.executionEnv.code s'.machineState.pc = some (.INVALID, .none) := by - rw [hcode, hpc] - exact hdec - have hstep : Xstep (D_J code 0) s' = .error .InvalidInstruction := by - have hstep' := Ethereum.EVM.step_invalid s' hdec' - simpa [hcode] using hstep' - have hfuel : g.toNat + 1 - k' = (g.toNat + 1 - (k' + 1)) + 1 := by - omega - exact Or.inr (by - rw [hX, hfuel] - exact Ethereum.EVM.Xstep_X_X_except _ s' _ _ hstep) - -theorem uniswapV3PoolBurnObserveSingleIndexOobInvalid - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cardinality liquidity index tick time memPtr ret : UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13208⟩ - (⟨0⟩ :: ⟨0⟩ :: cardinality :: liquidity :: index :: tick :: ⟨0⟩ :: time :: - memPtr :: ret :: R) - mem aw rdata (cA, σ) k C) - (hlt : UInt256.lt ((⟨65535⟩ : UInt256).land index) ⟨65535⟩ = ⟨0⟩) - (hov : R.length + 15 ≤ 1024) : - X (g.toNat + 1) (D_J code 0) s0 = .error .OutOfGass ∨ - X (g.toNat + 1) (D_J code 0) s0 = .error .InvalidInstruction := by - have hd13208 : decode code ⟨13208⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13210 : decode code ⟨13210⟩ = some (.DUP10, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13211 : decode code ⟨13211⟩ = some (.DUP7, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13212 : decode code ⟨13212⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13215 : decode code ⟨13215⟩ = some (.AND, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13216 : decode code ⟨13216⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13219 : decode code ⟨13219⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13220 : decode code ⟨13220⟩ = some (.LT, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13221 : decode code ⟨13221⟩ = some (.Push .PUSH2, some (⟨13226⟩, 2)) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13224 : decode code ⟨13224⟩ = some (.JUMPI, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13225 : decode code ⟨13225⟩ = some (.INVALID, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have h13221 := evm_run h with [ - raw push1 ⟨0⟩ hd13208 (by evm_ov), - raw dup10 hd13210 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw dup7 hd13211 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw push2 ⟨65535⟩ hd13212 (by evm_ov), - raw and hd13215 (by evm_ov), - raw push2 ⟨65535⟩ hd13216 (by evm_ov), - raw dup2 hd13219 (by evm_ov), - raw lt hd13220 (by evm_ov)] - rw [hlt] at h13221 - have h13224 := evm_run h13221 with [ - raw push2 ⟨13226⟩ hd13221 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega)] - have h13225 := h13224.jumpiNT hd13224 (by native_decide) (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - exact burnRDInvalidError h13225 hd13225 - -theorem uniswapV3PoolBurnObserveSingleIndexInBoundsJump - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cardinality liquidity index tick time memPtr ret : UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13208⟩ - (⟨0⟩ :: ⟨0⟩ :: cardinality :: liquidity :: index :: tick :: ⟨0⟩ :: time :: - memPtr :: ret :: R) - mem aw rdata (cA, σ) k C) - (hlt : UInt256.lt ((⟨65535⟩ : UInt256).land index) ⟨65535⟩ ≠ ⟨0⟩) - (hov : R.length + 15 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨13226⟩ - (((⟨65535⟩ : UInt256).land index) :: memPtr :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - cardinality :: liquidity :: index :: tick :: ⟨0⟩ :: time :: memPtr :: ret :: R) - mem aw rdata (cA, σ) k' C' := by - have hd13208 : decode code ⟨13208⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13210 : decode code ⟨13210⟩ = some (.DUP10, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13211 : decode code ⟨13211⟩ = some (.DUP7, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13212 : decode code ⟨13212⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13215 : decode code ⟨13215⟩ = some (.AND, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13216 : decode code ⟨13216⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13219 : decode code ⟨13219⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13220 : decode code ⟨13220⟩ = some (.LT, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13221 : decode code ⟨13221⟩ = some (.Push .PUSH2, some (⟨13226⟩, 2)) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13224 : decode code ⟨13224⟩ = some (.JUMPI, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have h13221 := evm_run h with [ - raw push1 ⟨0⟩ hd13208 (by evm_ov), - raw dup10 hd13210 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw dup7 hd13211 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw push2 ⟨65535⟩ hd13212 (by evm_ov), - raw and hd13215 (by evm_ov), - raw push2 ⟨65535⟩ hd13216 (by evm_ov), - raw dup2 hd13219 (by evm_ov), - raw lt hd13220 (by evm_ov)] - have h13224 := evm_run h13221 with [ - raw push2 ⟨13226⟩ hd13221 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega)] - exact ⟨_, _, h13224.jumpiT hd13224 hlt - (uniswapV3PoolBurnJumpDestPatched13226 hpatch) (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega)⟩ - -noncomputable abbrev burnObserveSingleAllocMem (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnPositionKeyMappingMem σ I) 64 - (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)) - -theorem burnPositionKeyMappingMem_mload64 (σ : AccountMap) (I : ExecutionEnv) : - (if (⟨64⟩ : UInt256).toNat ≥ (burnPositionKeyMappingMem σ I).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 18 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPositionKeyMappingMem σ I).readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - burnPositionKeyNewFreePtrWord := by - exact mloadWordValue_of_readWithPadding - (mem := burnPositionKeyMappingMem σ I) (aw := UInt256.ofNat 18) - (off := ⟨64⟩) (v := burnPositionKeyNewFreePtrWord) - (by rw [burnPositionKeyMappingMem_size σ I]; native_decide) - (by native_decide) - (by - simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using burnPositionKeyMappingMem_read64 σ I) - -theorem uniswapV3PoolBurnObserveSingleLoadObservation - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {cardinality liquidity index tick time ret : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13226⟩ - (((⟨65535⟩ : UInt256).land index) :: ⟨8⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - cardinality :: liquidity :: index :: tick :: ⟨0⟩ :: time :: ⟨8⟩ :: ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 17 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨13242⟩ - (solcSlotWord σ ee (⟨8⟩ + ((⟨65535⟩ : UInt256).land index)) :: - burnPositionKeyNewFreePtrWord :: ⟨64⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - cardinality :: liquidity :: index :: tick :: ⟨0⟩ :: time :: ⟨8⟩ :: ret :: R) - (burnObserveSingleAllocMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hd13226 : decode code ⟨13226⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13227 : decode code ⟨13227⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13229 : decode code ⟨13229⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13230 : decode code ⟨13230⟩ = some (.MLOAD, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13231 : decode code ⟨13231⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13233 : decode code ⟨13233⟩ = some (.DUP2, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13234 : decode code ⟨13234⟩ = some (.ADD, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13235 : decode code ⟨13235⟩ = some (.DUP3, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13236 : decode code ⟨13236⟩ = some (.MSTORE, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13237 : decode code ⟨13237⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13238 : decode code ⟨13238⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13239 : decode code ⟨13239⟩ = some (.SWAP3, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13240 : decode code ⟨13240⟩ = some (.ADD, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have hd13241 : decode code ⟨13241⟩ = some (.SLOAD, .none) := by - rw [uniswapV3PoolBurnObserveSingleBoundDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - have h13230 := evm_run h with [ - raw jumpdest hd13226 (by evm_ov), - raw push1 ⟨64⟩ hd13227 (by evm_ov), - raw dup1 hd13229 (by evm_ov)] - have h13231 := by - simpa using - h13230.mload 0 burnPositionKeyNewFreePtrWord (UInt256.ofNat 18) - hd13230 mem_cost (burnPositionKeyMappingMem_mload64 σ ee) - (by native_decide) - (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h13237 := evm_run h13231 with [ - raw push1 ⟨128⟩ hd13231 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw dup2 hd13233 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw add hd13234 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw dup3 hd13235 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw mstore 0 (burnObserveSingleAllocMem σ ee) (UInt256.ofNat 18) - hd13236 mem_cost rfl (by native_decide) (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw swap2 hd13237 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw swap1 hd13238 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw swap3 hd13239 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw add hd13240 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega)] - obtain ⟨_, _, h13242⟩ := h13237.sload hd13241 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - exact ⟨_, _, by simpa [solcSlotWord, u256_add_comm] using h13242⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnObserveSingle.lean b/Benchmarks/UniswapV3Pool/BurnObserveSingle.lean deleted file mode 100644 index 6a791691..00000000 --- a/Benchmarks/UniswapV3Pool/BurnObserveSingle.lean +++ /dev/null @@ -1,1434 +0,0 @@ -import Benchmarks.UniswapV3Pool.Observations -import Benchmarks.UniswapV3Pool.BurnNonzeroDeltaStart - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem burnObserveSingleSolcSlotWord_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) (slot : UInt256) : - solcSlotWord σ I slot = solcSlotWord τ I slot := by - have hslot := accountMapEquiv_storage_findD h I.codeOwner slot (⟨0⟩ : UInt256) - simpa [solcSlotWord] using hslot - -abbrev burnObserveSingleObservationKey (σ : AccountMap) (I : ExecutionEnv) : KeyValue := - .int (Int.ofNat (slot0ObservationIndexWord σ I).toNat) - -abbrev burnObserveSingleObservationBaseSlot (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - observationBase (burnObserveSingleObservationKey σ I) - -theorem burnObserveSingleObservationBaseSlot_eq (σ : AccountMap) (I : ExecutionEnv) : - burnObserveSingleObservationBaseSlot σ I = - ⟨8⟩ + slot0ObservationIndexWord σ I := by - unfold burnObserveSingleObservationBaseSlot burnObserveSingleObservationKey observationBase - rw [keyValueToWord_uint256] - rw [u256_ofNat_toNat] - -theorem burnObserveSingleObservationIndexWord_transport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} (hAccounts : accountMapEquiv σ_evm σ_solm) : - slot0ObservationIndexWord σ_evm I = slot0ObservationIndexWord σ_solm I := by - unfold slot0ObservationIndexWord slot0SlotWord - rw [burnObserveSingleSolcSlotWord_eq_of_accountMapEquiv hAccounts I ⟨0⟩] - -theorem burnObserveSingleObservationBaseSlot_transport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} (hAccounts : accountMapEquiv σ_evm σ_solm) : - burnObserveSingleObservationBaseSlot σ_evm I = - burnObserveSingleObservationBaseSlot σ_solm I := by - rw [burnObserveSingleObservationBaseSlot_eq, burnObserveSingleObservationBaseSlot_eq, - burnObserveSingleObservationIndexWord_transport hAccounts] - -abbrev burnObserveSingleSlotWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (burnObserveSingleObservationBaseSlot σ I) - -theorem burnObserveSingleSlotWord_transport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} (hAccounts : accountMapEquiv σ_evm σ_solm) : - burnObserveSingleSlotWord σ_evm I = burnObserveSingleSlotWord σ_solm I := by - unfold burnObserveSingleSlotWord - rw [burnObserveSingleObservationBaseSlot_transport hAccounts] - rw [burnObserveSingleSolcSlotWord_eq_of_accountMapEquiv hAccounts I - (burnObserveSingleObservationBaseSlot σ_solm I)] - -theorem burnObserveSingleMaskedSlotWord_eq (σ : AccountMap) (I : ExecutionEnv) - (hidxLt16 : (slot0ObservationIndexWord σ I).toNat < EVM.twoPow 16) : - solcSlotWord σ I (⟨8⟩ + ((⟨65535⟩ : UInt256).land - (slot0ObservationIndexWord σ I))) = - burnObserveSingleSlotWord σ I := by - have hmask : - UInt256.land (⟨65535⟩ : UInt256) (slot0ObservationIndexWord σ I) = - slot0ObservationIndexWord σ I := by - rw [show (⟨65535⟩ : UInt256) = slot0Uint16Mask by native_decide] - exact slot0Uint16Mask_clean_left hidxLt16 - simp [burnObserveSingleSlotWord, burnObserveSingleObservationBaseSlot_eq, hmask] - -abbrev burnObserveSingleLoadedObsWord (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - solcSlotWord σ I (⟨8⟩ + ((⟨65535⟩ : UInt256).land - ((⟨65535⟩ : UInt256).land - ((solcSlotWord σ I ⟨0⟩).div ((⟨1⟩ : UInt256).shiftLeft ⟨184⟩))))) - -theorem burnObserveSingleLoadedObsWord_eq (σ : AccountMap) (I : ExecutionEnv) - (hidxLt16 : (slot0ObservationIndexWord σ I).toNat < EVM.twoPow 16) : - burnObserveSingleLoadedObsWord σ I = burnObserveSingleSlotWord σ I := by - unfold burnObserveSingleLoadedObsWord - rw [show ((⟨1⟩ : UInt256).shiftLeft ⟨184⟩) = slot0ShiftBytes 23 by - native_decide] - rw [show (⟨65535⟩ : UInt256).land - ((solcSlotWord σ I ⟨0⟩).div (slot0ShiftBytes 23)) = - slot0ObservationIndexWord σ I by - rw [show (⟨65535⟩ : UInt256) = slot0Uint16Mask by native_decide] - simp [slot0ObservationIndexWord, slot0SlotWord, u256_land_comm]] - have hmask : - UInt256.land (⟨65535⟩ : UInt256) (slot0ObservationIndexWord σ I) = - slot0ObservationIndexWord σ I := by - rw [show (⟨65535⟩ : UInt256) = slot0Uint16Mask by native_decide] - exact slot0Uint16Mask_clean_left hidxLt16 - simpa [hmask] using burnObserveSingleMaskedSlotWord_eq σ I hidxLt16 - -abbrev burnObserveSingleBlockTimestampWord (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - UInt256.land (burnObserveSingleSlotWord σ I) observationsUint32Mask - -theorem burnObserveSingleBlockTimestampWord_transport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} (hAccounts : accountMapEquiv σ_evm σ_solm) : - burnObserveSingleBlockTimestampWord σ_evm I = - burnObserveSingleBlockTimestampWord σ_solm I := by - unfold burnObserveSingleBlockTimestampWord - rw [burnObserveSingleSlotWord_transport hAccounts] - -abbrev burnObserveSingleTickRawWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.div (burnObserveSingleSlotWord σ I) (observationsShiftBytes 4) - -theorem burnObserveSingleTickRawWord_transport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} (hAccounts : accountMapEquiv σ_evm σ_solm) : - burnObserveSingleTickRawWord σ_evm I = burnObserveSingleTickRawWord σ_solm I := by - unfold burnObserveSingleTickRawWord - rw [burnObserveSingleSlotWord_transport hAccounts] - -abbrev burnObserveSingleTickStorageWord (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - UInt256.land (burnObserveSingleTickRawWord σ I) observationsUint56Mask - -theorem burnObserveSingleTickStorageWord_transport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} (hAccounts : accountMapEquiv σ_evm σ_solm) : - burnObserveSingleTickStorageWord σ_evm I = - burnObserveSingleTickStorageWord σ_solm I := by - unfold burnObserveSingleTickStorageWord - rw [burnObserveSingleTickRawWord_transport hAccounts] - -abbrev burnObserveSingleTickReturnWord (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - UInt256.signextend ⟨6⟩ (burnObserveSingleTickRawWord σ I) - -theorem burnObserveSingleTickReturnWord_transport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} (hAccounts : accountMapEquiv σ_evm σ_solm) : - burnObserveSingleTickReturnWord σ_evm I = - burnObserveSingleTickReturnWord σ_solm I := by - unfold burnObserveSingleTickReturnWord - rw [burnObserveSingleTickRawWord_transport hAccounts] - -abbrev burnObserveSingleSecondsPerLiquidityWord (σ : AccountMap) - (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.div (burnObserveSingleSlotWord σ I) (observationsShiftBytes 11)) - slot0Uint160Mask - -theorem burnObserveSingleSecondsPerLiquidityWord_transport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} (hAccounts : accountMapEquiv σ_evm σ_solm) : - burnObserveSingleSecondsPerLiquidityWord σ_evm I = - burnObserveSingleSecondsPerLiquidityWord σ_solm I := by - unfold burnObserveSingleSecondsPerLiquidityWord - rw [burnObserveSingleSlotWord_transport hAccounts] - -def burnObserveSingleLastEvaledRef (σ : AccountMap) (I : ExecutionEnv) : - EvaledStorageRef := - { base := "observations", steps := [.aindex (burnObserveSingleObservationKey σ I)] } - -def burnObserveSingleLastFieldEvaledRef (σ : AccountMap) (I : ExecutionEnv) - (field : Ident) : EvaledStorageRef := - { base := "observations", - steps := [.aindex (burnObserveSingleObservationKey σ I), .field field] } - -abbrev burnObserveSingleAfterLastFrame (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnObserveSingleStore σ I).insert "last" - (.storageRef (burnObserveSingleLastEvaledRef σ I) observationStructTy) } - -private theorem burnObserveSingleStorageTypeAtBase : - storageTypeAt? storageDecls { base := "observations", steps := [] } = - some (.array observationStructTy 65535) := by - rfl - -theorem burnObserveSingleArrayIndexInBounds_ok {v : PoolImmutables} (evm : EVM.State) - (σ : AccountMap) (I : ExecutionEnv) - (hbound : (slot0ObservationIndexWord σ I).toNat < 65535) : - arrayIndexInBounds? (config v) evm (contract v).storage "observations" [] - (burnObserveSingleObservationKey σ I) = .ok () := by - unfold arrayIndexInBounds? - rw [show (contract v).storage = storageDecls by rfl, burnObserveSingleStorageTypeAtBase] - change (if 0 ≤ Int.ofNat (slot0ObservationIndexWord σ I).toNat ∧ - Int.ofNat (slot0ObservationIndexWord σ I).toNat < (↑(65535 : Nat) : Int) then - EvalResult.ok () else EvalResult.revert) = EvalResult.ok () - have hin : 0 ≤ Int.ofNat (slot0ObservationIndexWord σ I).toNat ∧ - Int.ofNat (slot0ObservationIndexWord σ I).toNat < (↑(65535 : Nat) : Int) := by - constructor - · exact Int.natCast_nonneg _ - · change ((slot0ObservationIndexWord σ I).toNat : Int) < (65535 : Int) - exact_mod_cast hbound - rw [if_pos hin] - -theorem burnObserveSingleAfterLast_last (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnObserveSingleAfterLastFrame v σ I).locals.get? "last" = - some (.storageRef (burnObserveSingleLastEvaledRef σ I) observationStructTy) := by - rw [burnObserveSingleAfterLastFrame] - exact store_get_self (burnObserveSingleStore σ I) "last" - (.storageRef (burnObserveSingleLastEvaledRef σ I) observationStructTy) - -theorem burnObserveSingleStore_time (σ : AccountMap) (I : ExecutionEnv) : - (burnObserveSingleStore σ I).get? "time" = some (burnBlockTimestamp32Value I) := by - rw [burnObserveSingleStore] - exact store_get_self - ((((((∅ : Store).insert "cardinality" (burnSlot0ObservationCardinalityValue σ I)) - |>.insert "liquidity" (burnPoolLiquidityValue σ I)) - |>.insert "index" (burnSlot0ObservationIndexValue σ I)) - |>.insert "tick" (burnSlot0TickValue σ I)) - |>.insert "secondsAgo" (.int 0)) - "time" (burnBlockTimestamp32Value I) - -theorem burnObserveSingleAfterLast_time (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnObserveSingleAfterLastFrame v σ I).locals.get? "time" = - some (burnBlockTimestamp32Value I) := by - rw [burnObserveSingleAfterLastFrame] - rw [store_get_ne (burnObserveSingleStore σ I) (k := "last") (a := "time") - (.storageRef (burnObserveSingleLastEvaledRef σ I) observationStructTy) - (by native_decide)] - exact burnObserveSingleStore_time σ I - -theorem burnObserveSingleEvalTimeAfterLast {v : PoolImmutables} - {evm σ I} : - evalExpr? (config v) (burnObserveSingleAfterLastFrame v σ I) evm - (.var "time") = .ok (burnBlockTimestamp32Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [burnObserveSingleAfterLast_time (v := v) (σ := σ) (I := I)] - -theorem burnObservationStorageLocLoad_blockTimestamp (evm : EVM.State) (base : UInt256) : - storageLocLoad evm - (loc base ⟨0, by decide⟩ ⟨4, by decide⟩ - (by decide) (.int uint32Int)) = - .int (Int.ofNat (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner base) - observationsUint32Mask).toNat) := by - rw [← show UInt256.ofNat (2 ^ (8 * 4) - 1) = observationsUint32Mask by native_decide] - simpa [loc, uint32Int] using - storageLocLoad_uint_offset0 evm base (4 : Fin 33) ⟨32, by decide⟩ - (hbound := by decide) (by decide) - -theorem burnObserveSingleEvalLastBlockTimestamp {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnObserveSingleAfterLastFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.field (.var "last") "blockTimestamp") = - .ok (.int (Int.ofNat (burnObserveSingleBlockTimestampWord σ I).toNat)) := by - rw [evalExpr?] - have hlast : - evalExpr? (config v) (burnObserveSingleAfterLastFrame v σ I) - (initState cA gh bl σ σ₀ g A I) (.var "last") = - .ok (.storageRef (burnObserveSingleLastEvaledRef σ I) observationStructTy) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [burnObserveSingleAfterLast_last (v := v) (σ := σ) (I := I)] - rw [hlast] - simp only [EvalResult.ofOption, EvalResult.bind, bind] - change readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnObserveSingleLastFieldEvaledRef σ I "blockTimestamp") - (.elem (.int uint32Int)) = - .ok (.int (Int.ofNat (burnObserveSingleBlockTimestampWord σ I).toNat)) - rw [readStorage?] - simp only [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnObserveSingleLastFieldEvaledRef, burnObserveSingleObservationKey] - simpa [initState, burnObserveSingleBlockTimestampWord, burnObserveSingleSlotWord, - solcSlotWord] - using burnObservationStorageLocLoad_blockTimestamp (initState cA gh bl σ σ₀ g A I) - (burnObserveSingleObservationBaseSlot σ I) - -theorem burnObserveSingleEvalLastTimestampNeTimeFalse {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hsame : - .int (Int.ofNat (burnObserveSingleBlockTimestampWord σ I).toNat) = - burnBlockTimestamp32Value I) : - evalExpr? (config v) (burnObserveSingleAfterLastFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (neE (.field (.var "last") "blockTimestamp") (.var "time")) = - .ok (.bool false) := by - unfold neE - rw [evalExpr?] <;> try decide - rw [burnObserveSingleEvalLastBlockTimestamp (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g)] - rw [burnObserveSingleEvalTimeAfterLast (v := v) - (evm := initState cA gh bl σ σ₀ g A I) (σ := σ) (I := I)] - rw [hsame] - simp [EvalResult.bind, bind, evalBinaryOp?, burnBlockTimestamp32Value] - -theorem burnObservationStorageLocLoad_tickCumulative (evm : EVM.State) (base : UInt256) : - storageLocLoad evm - (loc base ⟨4, by decide⟩ ⟨7, by decide⟩ - (by decide) (.int int56Int)) = - wordToElem (.int int56Int) - (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner base) - (observationsShiftBytes 4)) - observationsUint56Mask) := by - rw [← show UInt256.ofNat (256 ^ (4 : Nat)) = observationsShiftBytes 4 by rfl] - rw [← show UInt256.ofNat (256 ^ (7 : Nat) - 1) = observationsUint56Mask by - native_decide] - simpa [loc, int56Int] using - storageLocLoad_sint_offset evm base (4 : Fin 32) (7 : Fin 33) - ⟨56, by decide⟩ (hbound := by decide) (by decide) (by decide) - -theorem burnObserveSingleEvalLastTickCumulative {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnObserveSingleAfterLastFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.field (.var "last") "tickCumulative") = - .ok (wordToElem (.int int56Int) (burnObserveSingleTickStorageWord σ I)) := by - rw [evalExpr?] - have hlast : - evalExpr? (config v) (burnObserveSingleAfterLastFrame v σ I) - (initState cA gh bl σ σ₀ g A I) (.var "last") = - .ok (.storageRef (burnObserveSingleLastEvaledRef σ I) observationStructTy) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [burnObserveSingleAfterLast_last (v := v) (σ := σ) (I := I)] - rw [hlast] - simp only [EvalResult.ofOption, EvalResult.bind, bind] - change readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnObserveSingleLastFieldEvaledRef σ I "tickCumulative") - (.elem (.int int56Int)) = - .ok (wordToElem (.int int56Int) (burnObserveSingleTickStorageWord σ I)) - rw [readStorage?] - simp only [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnObserveSingleLastFieldEvaledRef, burnObserveSingleObservationKey] - simpa [initState, burnObserveSingleTickStorageWord, burnObserveSingleTickRawWord, - burnObserveSingleSlotWord, solcSlotWord] - using burnObservationStorageLocLoad_tickCumulative (initState cA gh bl σ σ₀ g A I) - (burnObserveSingleObservationBaseSlot σ I) - -theorem burnObservationStorageLocLoad_secondsPerLiquidity (evm : EVM.State) - (base : UInt256) : - storageLocLoad evm - (loc base ⟨11, by decide⟩ ⟨20, by decide⟩ - (by decide) (.int uint160Int)) = - .int (Int.ofNat (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner base) - (observationsShiftBytes 11)) - slot0Uint160Mask).toNat) := by - rw [← show UInt256.ofNat (256 ^ (11 : Nat)) = observationsShiftBytes 11 by rfl] - rw [← show UInt256.ofNat (256 ^ (20 : Nat) - 1) = slot0Uint160Mask by native_decide] - simpa [loc, uint160Int] using - storageLocLoad_uint_offset evm base (11 : Fin 32) (20 : Fin 33) - ⟨160, by decide⟩ (hbound := by decide) (by decide) (by decide) - -theorem burnObserveSingleEvalLastSecondsPerLiquidity {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnObserveSingleAfterLastFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.field (.var "last") "secondsPerLiquidityCumulativeX128") = - .ok (.int (Int.ofNat (burnObserveSingleSecondsPerLiquidityWord σ I).toNat)) := by - rw [evalExpr?] - have hlast : - evalExpr? (config v) (burnObserveSingleAfterLastFrame v σ I) - (initState cA gh bl σ σ₀ g A I) (.var "last") = - .ok (.storageRef (burnObserveSingleLastEvaledRef σ I) observationStructTy) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [burnObserveSingleAfterLast_last (v := v) (σ := σ) (I := I)] - rw [hlast] - simp only [EvalResult.ofOption, EvalResult.bind, bind] - change readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnObserveSingleLastFieldEvaledRef σ I "secondsPerLiquidityCumulativeX128") - (.elem (.int uint160Int)) = - .ok (.int (Int.ofNat (burnObserveSingleSecondsPerLiquidityWord σ I).toNat)) - rw [readStorage?] - simp only [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnObserveSingleLastFieldEvaledRef, burnObserveSingleObservationKey] - simpa [initState, burnObserveSingleSecondsPerLiquidityWord, burnObserveSingleSlotWord, - solcSlotWord] - using burnObservationStorageLocLoad_secondsPerLiquidity - (initState cA gh bl σ σ₀ g A I) (burnObserveSingleObservationBaseSlot σ I) - -def burnObserveSingleRawLastFieldEvaledRef (σ : AccountMap) (I : ExecutionEnv) - (field : Ident) : EvaledStorageRef := - { base := "observationsRaw", - steps := [.mindex (burnObserveSingleObservationKey σ I), .field field] } - -theorem burnObserveSingleEvalStorageRef_observationsRaw {v : PoolImmutables} - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) (field : Ident) : - evalStorageRef (config v) { contract := contract v, locals := burnObserveSingleStore σ I } - evm (observationsRawF (.var "index") field) = - .ok (burnObserveSingleRawLastFieldEvaledRef σ I field) := by - simp [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, observationsRawF, - burnObserveSingleRawLastFieldEvaledRef, burnObserveSingleEvalIndex, - burnSlot0ObservationIndexValue, burnObserveSingleObservationKey, valueToKey?, - EvalResult.bind, EvalResult.ofOption, bind, pure] - -theorem burnObserveSingleEvalRawBlockTimestamp {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) { contract := contract v, locals := burnObserveSingleStore σ I } - (initState cA gh bl σ σ₀ g A I) - (.storage (observationsRawF (.var "index") "blockTimestamp")) = - .ok (.int (Int.ofNat (burnObserveSingleBlockTimestampWord σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := burnObserveSingleRawLastFieldEvaledRef σ I "blockTimestamp") - (t := .int uint32Int) - (loc := loc (burnObserveSingleObservationBaseSlot σ I) ⟨0, by decide⟩ - ⟨4, by decide⟩ (by decide) (.int uint32Int)) - · simp [burnObserveSingleStore, observationsRawF] - · exact burnObserveSingleEvalStorageRef_observationsRaw - (v := v) (initState cA gh bl σ σ₀ g A I) σ I "blockTimestamp" - · simp [burnObserveSingleRawLastFieldEvaledRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, observationStructTy, uint32St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnObserveSingleRawLastFieldEvaledRef, burnObserveSingleObservationKey, - burnObserveSingleObservationBaseSlot, loc] - · simpa [initState, burnObserveSingleBlockTimestampWord, burnObserveSingleSlotWord, - solcSlotWord] using - burnObservationStorageLocLoad_blockTimestamp (initState cA gh bl σ σ₀ g A I) - (burnObserveSingleObservationBaseSlot σ I) - -theorem burnObserveSingleEvalRawTimestampNeTimeFalse {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hsame : - .int (Int.ofNat (burnObserveSingleBlockTimestampWord σ I).toNat) = - burnBlockTimestamp32Value I) : - evalExpr? (config v) { contract := contract v, locals := burnObserveSingleStore σ I } - (initState cA gh bl σ σ₀ g A I) - (neE (.storage (observationsRawF (.var "index") "blockTimestamp")) (.var "time")) = - .ok (.bool false) := by - unfold neE - rw [evalExpr?] <;> try decide - rw [burnObserveSingleEvalRawBlockTimestamp (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g)] - have htime : - evalExpr? (config v) { contract := contract v, locals := burnObserveSingleStore σ I } - (initState cA gh bl σ σ₀ g A I) (.var "time") = - .ok (burnBlockTimestamp32Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [burnObserveSingleStore_time σ I] - rw [htime] - rw [hsame] - simp [EvalResult.bind, bind, evalBinaryOp?, burnBlockTimestamp32Value] - -theorem burnObserveSingleEvalRawTickCumulative {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) { contract := contract v, locals := burnObserveSingleStore σ I } - (initState cA gh bl σ σ₀ g A I) - (.storage (observationsRawF (.var "index") "tickCumulative")) = - .ok (wordToElem (.int int56Int) (burnObserveSingleTickStorageWord σ I)) := by - apply evalExpr_storage_scalar_value - (er := burnObserveSingleRawLastFieldEvaledRef σ I "tickCumulative") - (t := .int int56Int) - (loc := loc (burnObserveSingleObservationBaseSlot σ I) ⟨4, by decide⟩ - ⟨7, by decide⟩ (by decide) (.int int56Int)) - · simp [burnObserveSingleStore, observationsRawF] - · exact burnObserveSingleEvalStorageRef_observationsRaw - (v := v) (initState cA gh bl σ σ₀ g A I) σ I "tickCumulative" - · simp [burnObserveSingleRawLastFieldEvaledRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, observationStructTy, int56St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnObserveSingleRawLastFieldEvaledRef, burnObserveSingleObservationKey, - burnObserveSingleObservationBaseSlot, loc] - · simpa [initState, burnObserveSingleTickStorageWord, burnObserveSingleTickRawWord, - burnObserveSingleSlotWord, solcSlotWord] using - burnObservationStorageLocLoad_tickCumulative (initState cA gh bl σ σ₀ g A I) - (burnObserveSingleObservationBaseSlot σ I) - -theorem burnObserveSingleEvalRawSecondsPerLiquidity {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) { contract := contract v, locals := burnObserveSingleStore σ I } - (initState cA gh bl σ σ₀ g A I) - (.storage (observationsRawF (.var "index") - "secondsPerLiquidityCumulativeX128")) = - .ok (.int (Int.ofNat (burnObserveSingleSecondsPerLiquidityWord σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := burnObserveSingleRawLastFieldEvaledRef σ I - "secondsPerLiquidityCumulativeX128") - (t := .int uint160Int) - (loc := loc (burnObserveSingleObservationBaseSlot σ I) ⟨11, by decide⟩ - ⟨20, by decide⟩ (by decide) (.int uint160Int)) - · simp [burnObserveSingleStore, observationsRawF] - · exact burnObserveSingleEvalStorageRef_observationsRaw - (v := v) (initState cA gh bl σ σ₀ g A I) - σ I "secondsPerLiquidityCumulativeX128" - · simp [burnObserveSingleRawLastFieldEvaledRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, observationStructTy, uint160St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnObserveSingleRawLastFieldEvaledRef, burnObserveSingleObservationKey, - burnObserveSingleObservationBaseSlot, loc] - · simpa [initState, burnObserveSingleSecondsPerLiquidityWord, burnObserveSingleSlotWord, - solcSlotWord] using - burnObservationStorageLocLoad_secondsPerLiquidity - (initState cA gh bl σ σ₀ g A I) (burnObserveSingleObservationBaseSlot σ I) - -abbrev burnObserveSingleTimestampEqualReturnValues (σ : AccountMap) (I : ExecutionEnv) : - List Value := - [ wordToElem (.int int56Int) (burnObserveSingleTickStorageWord σ I), - .int (Int.ofNat (burnObserveSingleSecondsPerLiquidityWord σ I).toNat) ] - -theorem burnObserveSingleTimestampEqualReturnValues_transport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} (hAccounts : accountMapEquiv σ_evm σ_solm) : - burnObserveSingleTimestampEqualReturnValues σ_evm I = - burnObserveSingleTimestampEqualReturnValues σ_solm I := by - unfold burnObserveSingleTimestampEqualReturnValues - rw [burnObserveSingleTickStorageWord_transport hAccounts, - burnObserveSingleSecondsPerLiquidityWord_transport hAccounts] - -theorem uniswapV3PoolObserveSingleSourceTimestampEqualReturns {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hbound : (slot0ObservationIndexWord σ I).toNat < 65535) - (hsame : - .int (Int.ofNat (burnObserveSingleBlockTimestampWord σ I).toNat) = - burnBlockTimestamp32Value I) : - ExecFuncBody (config v) - { contract := contract v, locals := burnObserveSingleStore σ I } - (initState cA gh bl σ σ₀ g A I) observeSingleFunction.body - (.returned { contract := contract v, locals := burnObserveSingleStore σ I } - (initState cA gh bl σ σ₀ g A I) - (some (burnObserveSingleTimestampEqualReturnValues σ I))) := by - refine ExecFuncBody.execBlockRet ?_ - simpa [observeSingleFunction] using - (ExecBlock.consReturn - (ExecStmt.iteTrue - (burnObserveSingleEvalSecondsAgoZero (v := v) (σ := σ) (I := I) - (evm := initState cA gh bl σ σ₀ g A I)) - (ExecBlock.consNormal - (ExecStmt.requireTrue - (burnObserveSingleEvalIndexLtBoundTrue (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hbound)) - (ExecBlock.consReturn - (ExecStmt.iteFalse - (burnObserveSingleEvalRawTimestampNeTimeFalse (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hsame) - (ExecBlock.consReturn <| ExecStmt.return (by - have htick : - evalExpr? (config v) - { contract := contract v, locals := burnObserveSingleStore σ I } - (initState cA gh bl σ σ₀ g A I) - (.storage (observationsRawF (.var "index") "tickCumulative")) = - .ok (wordToElem (.int int56Int) - (burnObserveSingleTickStorageWord σ I)) := - burnObserveSingleEvalRawTickCumulative (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) - have hseconds : - evalExpr? (config v) - { contract := contract v, locals := burnObserveSingleStore σ I } - (initState cA gh bl σ σ₀ g A I) - (.storage (observationsRawF (.var "index") - "secondsPerLiquidityCumulativeX128")) = - .ok (.int - (Int.ofNat (burnObserveSingleSecondsPerLiquidityWord σ I).toNat)) := - burnObserveSingleEvalRawSecondsPerLiquidity (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) - change evalExprs? (config v) - { contract := contract v, locals := burnObserveSingleStore σ I } - (initState cA gh bl σ σ₀ g A I) - [ .storage (observationsRawF (.var "index") "tickCumulative"), - .storage (observationsRawF (.var "index") - "secondsPerLiquidityCumulativeX128") ] = - .ok [ wordToElem (.int int56Int) (burnObserveSingleTickStorageWord σ I), - .int (Int.ofNat (burnObserveSingleSecondsPerLiquidityWord σ I).toNat) ] - rw [evalExprs?] - rw [htick] - simp only [EvalResult.bind, bind, pure] - rw [evalExprs?] - rw [hseconds] - rfl))))))) - -abbrev burnModifyPositionAfterObserveSingleFrame (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnModifyPositionAfterTimeFrame v σ I).locals.insert "observedForUpdate" - (.tuple (burnObserveSingleTimestampEqualReturnValues σ I)) } - -theorem uniswapV3PoolModifyPositionSourceObserveSingleTimestampEqualStep - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hbound : (slot0ObservationIndexWord σ I).toNat < 65535) - (hsame : - .int (Int.ofNat (burnObserveSingleBlockTimestampWord σ I).toNat) = - burnBlockTimestamp32Value I) : - ExecStmt (config v) (burnModifyPositionAfterTimeFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.internalCall "observeSingle" - [ .var "time", .intLit 0, .storage (slot0F "tick"), - .storage (slot0F "observationIndex"), .storage liquidityRef, - .storage (slot0F "observationCardinality") ] - "observedForUpdate") - (.ok (burnModifyPositionAfterObserveSingleFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - have hstmt := internalCallFunctionReturn (callee := observeSingleFunction) - (retVar := "observedForUpdate") - (argVals := burnObserveSingleArgValues σ I) - (locals := burnObserveSingleStore σ I) - (calleeSolm := { contract := contract v, locals := burnObserveSingleStore σ I }) - (value := some (burnObserveSingleTimestampEqualReturnValues σ I)) - (burnModifyPosition_evalObserveSingleArgs (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g)) - (by - simpa [burnModifyPositionAfterTimeFrame] using uniswapV3PoolLookupObserveSingle v) - (burnObserveSingle_bindParams σ I) - (uniswapV3PoolObserveSingleSourceTimestampEqualReturns (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hbound hsame) - simpa [burnModifyPositionAfterObserveSingleFrame, resumeAfterInternalCall, - collapseReturns] using hstmt - -abbrev burnObserveSingleDecodedBlockWord (obsWord : UInt256) : UInt256 := - UInt256.land obsWord observationsUint32Mask - -private theorem uInt256_eq_word_eq_of_ne_zero {a b : UInt256} - (h : UInt256.eq a b ≠ ⟨0⟩) : - a = b := by - apply uInt256_eq_one_eq - by_contra hone - exact h (uInt256_eq_zero_of_ne hone) - -theorem burnObserveSingleBlockTimestampValue_eq_of_maskedTimestamp - (σ : AccountMap) (I : ExecutionEnv) - (hword : burnObserveSingleBlockTimestampWord σ I = - UInt256.land (UInt256.ofNat I.header.timestamp) observationsUint32Mask) : - .int (Int.ofNat (burnObserveSingleBlockTimestampWord σ I).toNat) = - burnBlockTimestamp32Value I := by - unfold burnBlockTimestamp32Value - rw [hword, u256_land_toNat, observationsUint32Mask_toNat, nat_land_mask_eq_mod] - rw [Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num)) (by norm_num [UInt256.size]))] - -theorem burnObserveSingleSourceTimestampEqOfGuard {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} {obsWord : UInt256} - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hobsWord : obsWord = burnObserveSingleSlotWord σ_evm I) - (heq : UInt256.eq - (UInt256.land (UInt256.ofNat I.header.timestamp) observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩) : - .int (Int.ofNat (burnObserveSingleBlockTimestampWord σ_solm I).toNat) = - burnBlockTimestamp32Value I := by - have hdecoded : - burnObserveSingleDecodedBlockWord obsWord = - burnObserveSingleBlockTimestampWord σ_evm I := by - rw [hobsWord] - have hmasked : - UInt256.land (UInt256.ofNat I.header.timestamp) observationsUint32Mask = - burnObserveSingleBlockTimestampWord σ_evm I := - (uInt256_eq_word_eq_of_ne_zero heq).trans hdecoded - apply burnObserveSingleBlockTimestampValue_eq_of_maskedTimestamp - rw [← burnObserveSingleBlockTimestampWord_transport hAccounts] - exact hmasked.symm - -abbrev burnObserveSingleDecodedTickRawWord (obsWord : UInt256) : UInt256 := - UInt256.div obsWord (observationsShiftBytes 4) - -abbrev burnObserveSingleDecodedTickWord (obsWord : UInt256) : UInt256 := - UInt256.signextend ⟨6⟩ (burnObserveSingleDecodedTickRawWord obsWord) - -abbrev burnObserveSingleDecodedSecondsWord (obsWord : UInt256) : UInt256 := - UInt256.land slot0Uint160Mask (UInt256.div obsWord (observationsShiftBytes 11)) - -abbrev burnObserveSingleDecodedInitializedWord (obsWord : UInt256) : UInt256 := - slot0BoolReturnWord - (UInt256.land slot0Uint8Mask (UInt256.div obsWord (observationsShiftBytes 31))) - -noncomputable abbrev burnObserveSingleDecodedMem1 (σ : AccountMap) (I : ExecutionEnv) - (obsWord : UInt256) : ByteArray := - writeWord (burnObserveSingleAllocMem σ I) burnPositionKeyNewFreePtrWord.toNat - (burnObserveSingleDecodedBlockWord obsWord) - -noncomputable abbrev burnObserveSingleDecodedMem2 (σ : AccountMap) (I : ExecutionEnv) - (obsWord : UInt256) : ByteArray := - writeWord (burnObserveSingleDecodedMem1 σ I obsWord) - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat - (burnObserveSingleDecodedTickWord obsWord) - -noncomputable abbrev burnObserveSingleDecodedMem3 (σ : AccountMap) (I : ExecutionEnv) - (obsWord : UInt256) : ByteArray := - writeWord (burnObserveSingleDecodedMem2 σ I obsWord) - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat - (burnObserveSingleDecodedSecondsWord obsWord) - -noncomputable abbrev burnObserveSingleDecodedMem (σ : AccountMap) (I : ExecutionEnv) - (obsWord : UInt256) : ByteArray := - writeWord (burnObserveSingleDecodedMem3 σ I obsWord) - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat - (burnObserveSingleDecodedInitializedWord obsWord) - -theorem burnObserveSingleAllocMem_size (σ : AccountMap) (I : ExecutionEnv) : - (burnObserveSingleAllocMem σ I).size = 567 := by - unfold burnObserveSingleAllocMem - rw [writeWord_size _ _ _ (by rw [burnPositionKeyMappingMem_size σ I]; native_decide)] - rw [burnPositionKeyMappingMem_size σ I] - native_decide - -theorem burnObserveSingleDecodedMem1_size (σ : AccountMap) (I : ExecutionEnv) - (obsWord : UInt256) : - (burnObserveSingleDecodedMem1 σ I obsWord).size = 570 := by - unfold burnObserveSingleDecodedMem1 - rw [writeWord_size _ _ _ (by rw [burnObserveSingleAllocMem_size σ I]; native_decide)] - rw [burnObserveSingleAllocMem_size σ I] - native_decide - -theorem burnObserveSingleDecodedMem2_size (σ : AccountMap) (I : ExecutionEnv) - (obsWord : UInt256) : - (burnObserveSingleDecodedMem2 σ I obsWord).size = 602 := by - unfold burnObserveSingleDecodedMem2 - rw [writeWord_size _ _ _ (by - rw [burnObserveSingleDecodedMem1_size σ I obsWord] - native_decide)] - rw [burnObserveSingleDecodedMem1_size σ I obsWord] - native_decide - -theorem burnObserveSingleDecodedMem3_size (σ : AccountMap) (I : ExecutionEnv) - (obsWord : UInt256) : - (burnObserveSingleDecodedMem3 σ I obsWord).size = 634 := by - unfold burnObserveSingleDecodedMem3 - rw [writeWord_size _ _ _ (by - rw [burnObserveSingleDecodedMem2_size σ I obsWord] - native_decide)] - rw [burnObserveSingleDecodedMem2_size σ I obsWord] - native_decide - -theorem burnObserveSingleDecodedMem_size (σ : AccountMap) (I : ExecutionEnv) - (obsWord : UInt256) : - (burnObserveSingleDecodedMem σ I obsWord).size = 666 := by - unfold burnObserveSingleDecodedMem - rw [writeWord_size _ _ _ (by - rw [burnObserveSingleDecodedMem3_size σ I obsWord] - native_decide)] - rw [burnObserveSingleDecodedMem3_size σ I obsWord] - native_decide - -theorem burnObserveSingleDecodedMem_readFreePtrPlus32 (σ : AccountMap) - (I : ExecutionEnv) (obsWord : UInt256) : - (burnObserveSingleDecodedMem σ I obsWord).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat 32 = - UInt256.toByteArray (burnObserveSingleDecodedTickWord obsWord) := by - unfold burnObserveSingleDecodedMem - rw [writeWord_read_preserved - (burnObserveSingleDecodedMem3 σ I obsWord) - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat - (burnObserveSingleDecodedInitializedWord obsWord) - (by rw [burnObserveSingleDecodedMem3_size σ I obsWord]; native_decide) - (by rw [burnObserveSingleDecodedMem3_size σ I obsWord]; native_decide)] - unfold burnObserveSingleDecodedMem3 - rw [writeWord_read_preserved - (burnObserveSingleDecodedMem2 σ I obsWord) - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat - (burnObserveSingleDecodedSecondsWord obsWord) - (by rw [burnObserveSingleDecodedMem2_size σ I obsWord]; native_decide) - (by rw [burnObserveSingleDecodedMem2_size σ I obsWord]; native_decide)] - unfold burnObserveSingleDecodedMem2 - exact writeWord_read_back (burnObserveSingleDecodedMem1 σ I obsWord) - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat - (burnObserveSingleDecodedTickWord obsWord) - (by rw [burnObserveSingleDecodedMem1_size σ I obsWord]; native_decide) - -theorem burnObserveSingleDecodedMem_mloadFreePtrPlus32 (σ : AccountMap) - (I : ExecutionEnv) (obsWord : UInt256) : - (if (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat ≥ - (burnObserveSingleDecodedMem σ I obsWord).size - ∨ (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)) ≥ - UInt256.ofNat 21 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnObserveSingleDecodedMem σ I obsWord).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat 32))) = - burnObserveSingleDecodedTickWord obsWord := by - exact mloadWordValue_of_readWithPadding - (mem := burnObserveSingleDecodedMem σ I obsWord) (aw := UInt256.ofNat 21) - (off := burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)) - (v := burnObserveSingleDecodedTickWord obsWord) - (by rw [burnObserveSingleDecodedMem_size σ I obsWord]; native_decide) - (by native_decide) - (burnObserveSingleDecodedMem_readFreePtrPlus32 σ I obsWord) - -theorem burnObserveSingleDecodedMem_readFreePtrPlus64 (σ : AccountMap) - (I : ExecutionEnv) (obsWord : UInt256) : - (burnObserveSingleDecodedMem σ I obsWord).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat 32 = - UInt256.toByteArray (burnObserveSingleDecodedSecondsWord obsWord) := by - unfold burnObserveSingleDecodedMem - rw [writeWord_read_preserved - (burnObserveSingleDecodedMem3 σ I obsWord) - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat - (burnObserveSingleDecodedInitializedWord obsWord) - (by rw [burnObserveSingleDecodedMem3_size σ I obsWord]; native_decide) - (by rw [burnObserveSingleDecodedMem3_size σ I obsWord]; native_decide)] - unfold burnObserveSingleDecodedMem3 - exact writeWord_read_back (burnObserveSingleDecodedMem2 σ I obsWord) - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat - (burnObserveSingleDecodedSecondsWord obsWord) - (by rw [burnObserveSingleDecodedMem2_size σ I obsWord]; native_decide) - -theorem burnObserveSingleDecodedMem_mloadFreePtrPlus64 (σ : AccountMap) - (I : ExecutionEnv) (obsWord : UInt256) : - (if (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat ≥ - (burnObserveSingleDecodedMem σ I obsWord).size - ∨ (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)) ≥ - UInt256.ofNat 21 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnObserveSingleDecodedMem σ I obsWord).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat 32))) = - burnObserveSingleDecodedSecondsWord obsWord := by - exact mloadWordValue_of_readWithPadding - (mem := burnObserveSingleDecodedMem σ I obsWord) (aw := UInt256.ofNat 21) - (off := burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)) - (v := burnObserveSingleDecodedSecondsWord obsWord) - (by rw [burnObserveSingleDecodedMem_size σ I obsWord]; native_decide) - (by native_decide) - (burnObserveSingleDecodedMem_readFreePtrPlus64 σ I obsWord) - -private theorem uniswapV3PoolBurnObserveSingleReturnDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 13242 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13628) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 13628 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega) - -private theorem uniswapV3PoolBurnObserveSinglePatchPreservesJumpDest13340 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨13340⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolBurnJumpDestPatched13340 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨13340⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolBurnObserveSinglePatchPreservesJumpDest13340 - -private theorem uniswapV3PoolBurnObserveSinglePatchPreservesJumpDest13584 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨13584⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolBurnJumpDestPatched13584 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨13584⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolBurnObserveSinglePatchPreservesJumpDest13584 - -private theorem uniswapV3PoolBurnObserveSinglePatchPreservesJumpDest19273 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨19273⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolBurnJumpDestPatched19273 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨19273⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolBurnObserveSinglePatchPreservesJumpDest19273 - -theorem uniswapV3PoolBurnObserveSingleTimestampEqualJump - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {obsWord cardinality liquidity index tick time ret : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13242⟩ - (obsWord :: burnPositionKeyNewFreePtrWord :: ⟨64⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - cardinality :: liquidity :: index :: tick :: ⟨0⟩ :: time :: ⟨8⟩ :: ret :: R) - (burnObserveSingleAllocMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (heq : UInt256.eq (UInt256.land time observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩) - (hov : R.length + 25 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨13340⟩ - (burnPositionKeyNewFreePtrWord :: ⟨0⟩ :: ⟨0⟩ :: cardinality :: liquidity :: - index :: tick :: ⟨0⟩ :: time :: ⟨8⟩ :: ret :: R) - (burnObserveSingleDecodedMem σ ee obsWord) (UInt256.ofNat 21) rdata (cA, σ) k' C' := by - have hdecode {pc : UInt256} (hlo : 13242 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 13628) : - decode code pc = decode uniswapV3PoolBytecode pc := - uniswapV3PoolBurnObserveSingleReturnDecodeEqTemplate hpatch hlo hhi - have hd13242 : decode code ⟨13242⟩ = - some (.Push .PUSH4, some (⟨4294967295⟩, 4)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13247 : decode code ⟨13247⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13248 : decode code ⟨13248⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13249 : decode code ⟨13249⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13250 : decode code ⟨13250⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13251 : decode code ⟨13251⟩ = some (.DUP5, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13252 : decode code ⟨13252⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13253 : decode code ⟨13253⟩ = - some (.Push .PUSH5, some (⟨4294967296⟩, 5)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13259 : decode code ⟨13259⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13260 : decode code ⟨13260⟩ = some (.DIV, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13261 : decode code ⟨13261⟩ = some (.Push .PUSH1, some (⟨6⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13263 : decode code ⟨13263⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13264 : decode code ⟨13264⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13265 : decode code ⟨13265⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13266 : decode code ⟨13266⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13267 : decode code ⟨13267⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13268 : decode code ⟨13268⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13269 : decode code ⟨13269⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13270 : decode code ⟨13270⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13272 : decode code ⟨13272⟩ = some (.DUP6, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13273 : decode code ⟨13273⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13274 : decode code ⟨13274⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13275 : decode code ⟨13275⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13277 : decode code ⟨13277⟩ = some (.Push .PUSH1, some (⟨88⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13279 : decode code ⟨13279⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13280 : decode code ⟨13280⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13281 : decode code ⟨13281⟩ = some (.DIV, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13282 : decode code ⟨13282⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13284 : decode code ⟨13284⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13286 : decode code ⟨13286⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13288 : decode code ⟨13288⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13289 : decode code ⟨13289⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13290 : decode code ⟨13290⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13291 : decode code ⟨13291⟩ = some (.SWAP5, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13292 : decode code ⟨13292⟩ = some (.DUP5, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13293 : decode code ⟨13293⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13294 : decode code ⟨13294⟩ = some (.SWAP5, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13295 : decode code ⟨13295⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13296 : decode code ⟨13296⟩ = some (.SWAP5, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13297 : decode code ⟨13297⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13298 : decode code ⟨13298⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13300 : decode code ⟨13300⟩ = some (.Push .PUSH1, some (⟨248⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13302 : decode code ⟨13302⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13303 : decode code ⟨13303⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13304 : decode code ⟨13304⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13305 : decode code ⟨13305⟩ = some (.DIV, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13306 : decode code ⟨13306⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13308 : decode code ⟨13308⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13309 : decode code ⟨13309⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13310 : decode code ⟨13310⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13311 : decode code ⟨13311⟩ = some (.Push .PUSH1, some (⟨96⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13313 : decode code ⟨13313⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13314 : decode code ⟨13314⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13315 : decode code ⟨13315⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13316 : decode code ⟨13316⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13317 : decode code ⟨13317⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13318 : decode code ⟨13318⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13319 : decode code ⟨13319⟩ = some (.DUP11, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13320 : decode code ⟨13320⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13321 : decode code ⟨13321⟩ = some (.EQ, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13322 : decode code ⟨13322⟩ = some (.Push .PUSH2, some (⟨13340⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13325 : decode code ⟨13325⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have h13252 := evm_run h with [ - raw push4 ⟨4294967295⟩ hd13242 (by evm_ov), - raw dup1 hd13247 (by evm_ov), - raw dup3 hd13248 (by evm_ov), - raw and hd13249 (by evm_ov), - raw dup1 hd13250 (by evm_ov), - raw dup5 hd13251 (by evm_ov)] - have h13253 := h13252.mstore 0 (burnObserveSingleDecodedMem1 σ ee obsWord) - (UInt256.ofNat 18) hd13252 mem_cost - (by - dsimp [burnObserveSingleDecodedMem1, burnObserveSingleDecodedBlockWord] - rw [show (⟨4294967295⟩ : UInt256) = observationsUint32Mask by native_decide] - rfl) - (by native_decide) - (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h13259 := by - simpa [burnObserveSingleDecodedBlockWord] using - h13253.pushConst ⟨4294967296⟩ - (by decide : Operation.POp.PUSH5 ≠ .PUSH0) hd13253 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h13265pre := evm_run h13259 with [ - raw dup4 hd13259 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw div hd13260 (by evm_ov), - raw push1 ⟨6⟩ hd13261 (by evm_ov), - raw swap1 hd13263 (by evm_ov), - raw dup2 hd13264 (by evm_ov)] - have h13266 := RD.signextend h13265pre hd13265 (by evm_ov) - have h13267pre := evm_run h13266 with [ - raw dup2 hd13266 (by evm_ov)] - have h13268 := RD.signextend h13267pre hd13267 (by evm_ov) - have h13269pre := evm_run h13268 with [ - raw swap1 hd13268 (by evm_ov)] - have h13270 := RD.signextend h13269pre hd13269 (by evm_ov) - have h13274pre := evm_run h13270 with [ - raw push1 ⟨32⟩ hd13270 (by evm_ov), - raw dup6 hd13272 (by evm_ov), - raw add hd13273 (by evm_ov)] - have h13275 := h13274pre.mstore 3 (burnObserveSingleDecodedMem2 σ ee obsWord) - (UInt256.ofNat 19) hd13274 mem_cost - (by - rw [show (⟨4294967296⟩ : UInt256) = observationsShiftBytes 4 by native_decide] - simp [burnObserveSingleDecodedMem2, burnObserveSingleDecodedMem1, - burnObserveSingleDecodedTickWord, burnObserveSingleDecodedTickRawWord, - burnObserveSingleDecodedBlockWord, observationsSignextendSix_idempotent, - Reasoning.Theory.writeWord, u256_add_comm]) - (by native_decide) - (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h13297pre := evm_run h13275 with [ - raw push1 ⟨1⟩ hd13275 (by evm_ov), - raw push1 ⟨88⟩ hd13277 (by evm_ov), - raw shl hd13279 (by evm_ov), - raw dup4 hd13280 (by evm_ov), - raw div hd13281 (by evm_ov), - raw push1 ⟨1⟩ hd13282 (by evm_ov), - raw push1 ⟨1⟩ hd13284 (by evm_ov), - raw push1 ⟨160⟩ hd13286 (by evm_ov), - raw shl hd13288 (by evm_ov), - raw sub hd13289 (by evm_ov), - raw and hd13290 (by evm_ov), - raw swap5 hd13291 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw dup5 hd13292 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw add hd13293 (by evm_ov), - raw swap5 hd13294 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw swap1 hd13295 (by evm_ov), - raw swap5 hd13296 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega)] - have h13298 := h13297pre.mstore 3 (burnObserveSingleDecodedMem3 σ ee obsWord) - (UInt256.ofNat 20) hd13297 mem_cost - (by - rw [ - show UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨88⟩ = observationsShiftBytes 11 by - native_decide, - show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask by - native_decide] - simp [burnObserveSingleDecodedMem3, burnObserveSingleDecodedMem2, - burnObserveSingleDecodedMem1, burnObserveSingleDecodedSecondsWord, - burnObserveSingleDecodedTickWord, burnObserveSingleDecodedTickRawWord, - burnObserveSingleDecodedBlockWord, Reasoning.Theory.writeWord, u256_add_comm]) - (by native_decide) - (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h13315pre := evm_run h13298 with [ - raw push1 ⟨1⟩ hd13298 (by evm_ov), - raw push1 ⟨248⟩ hd13300 (by evm_ov), - raw shl hd13302 (by evm_ov), - raw swap1 hd13303 (by evm_ov), - raw swap2 hd13304 (by evm_ov), - raw div hd13305 (by evm_ov), - raw push1 ⟨255⟩ hd13306 (by evm_ov), - raw and hd13308 (by evm_ov), - raw iszero hd13309 (by evm_ov), - raw iszero hd13310 (by evm_ov), - raw push1 ⟨96⟩ hd13311 (by evm_ov), - raw dup4 hd13313 (by evm_ov), - raw add hd13314 (by evm_ov)] - have h13316 := h13315pre.mstore 3 (burnObserveSingleDecodedMem σ ee obsWord) - (UInt256.ofNat 21) hd13315 mem_cost - (by - rw [show (⟨255⟩ : UInt256) = slot0Uint8Mask by native_decide, - show UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨248⟩ = observationsShiftBytes 31 by - native_decide] - simp [burnObserveSingleDecodedMem, burnObserveSingleDecodedMem3, - burnObserveSingleDecodedMem2, burnObserveSingleDecodedMem1, - burnObserveSingleDecodedInitializedWord, burnObserveSingleDecodedSecondsWord, - burnObserveSingleDecodedTickWord, burnObserveSingleDecodedTickRawWord, - burnObserveSingleDecodedBlockWord, slot0BoolReturnWord, Reasoning.Theory.writeWord, - u256_add_comm]) - (by native_decide) - (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h13322pre := evm_run h13316 with [ - raw swap1 hd13316 (by evm_ov), - raw swap3 hd13317 (by evm_ov), - raw pop hd13318 (by evm_ov), - raw dup11 hd13319 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw and hd13320 (by evm_ov), - raw eq hd13321 (by evm_ov)] - have h13325 := evm_run h13322pre with [ - raw push2 ⟨13340⟩ hd13322 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega)] - rw [show (⟨4294967295⟩ : UInt256) = observationsUint32Mask by native_decide] at h13325 - exact ⟨_, _, h13325.jumpiT hd13325 heq - (uniswapV3PoolBurnJumpDestPatched13340 hpatch) (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega)⟩ - -theorem uniswapV3PoolBurnObserveSingleTimestampEqualReturn - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {obsWord cardinality liquidity index tick time memPtr ret : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13340⟩ - (burnPositionKeyNewFreePtrWord :: ⟨0⟩ :: ⟨0⟩ :: cardinality :: liquidity :: - index :: tick :: ⟨0⟩ :: time :: memPtr :: ret :: R) - (burnObserveSingleDecodedMem σ ee obsWord) (UInt256.ofNat 21) rdata (cA, σ) k C) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 14 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret - (burnObserveSingleDecodedSecondsWord obsWord :: - burnObserveSingleDecodedTickWord obsWord :: R) - (burnObserveSingleDecodedMem σ ee obsWord) (UInt256.ofNat 21) rdata (cA, σ) k' C' := by - have hdecode {pc : UInt256} (hlo : 13242 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 13628) : - decode code pc = decode uniswapV3PoolBytecode pc := - uniswapV3PoolBurnObserveSingleReturnDecodeEqTemplate hpatch hlo hhi - have hd13340 : decode code ⟨13340⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13341 : decode code ⟨13341⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13342 : decode code ⟨13342⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13344 : decode code ⟨13344⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13345 : decode code ⟨13345⟩ = some (.MLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13346 : decode code ⟨13346⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13347 : decode code ⟨13347⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13349 : decode code ⟨13349⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13350 : decode code ⟨13350⟩ = some (.MLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13351 : decode code ⟨13351⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13352 : decode code ⟨13352⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13353 : decode code ⟨13353⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13354 : decode code ⟨13354⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13355 : decode code ⟨13355⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13356 : decode code ⟨13356⟩ = - some (.Push .PUSH2, some (⟨13584⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13359 : decode code ⟨13359⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13584 : decode code ⟨13584⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13585 : decode code ⟨13585⟩ = some (.SWAP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13586 : decode code ⟨13586⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13587 : decode code ⟨13587⟩ = some (.SWAP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13588 : decode code ⟨13588⟩ = some (.SWAP6, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13589 : decode code ⟨13589⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13590 : decode code ⟨13590⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13591 : decode code ⟨13591⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13592 : decode code ⟨13592⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13593 : decode code ⟨13593⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13594 : decode code ⟨13594⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13595 : decode code ⟨13595⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have h13345 := evm_run h with [ - raw jumpdest hd13340 (by evm_ov), - raw dup1 hd13341 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw push1 ⟨32⟩ hd13342 (by evm_ov), - raw add hd13344 (by evm_ov)] - have h13346 := by - simpa using - h13345.mload 0 (burnObserveSingleDecodedTickWord obsWord) - (UInt256.ofNat 21) hd13345 mem_cost - (burnObserveSingleDecodedMem_mloadFreePtrPlus32 σ ee obsWord) - (by native_decide) - (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h13350 := evm_run h13346 with [ - raw dup2 hd13346 (by evm_ov), - raw push1 ⟨64⟩ hd13347 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw add hd13349 (by evm_ov)] - have h13351 := by - simpa using - h13350.mload 0 (burnObserveSingleDecodedSecondsWord obsWord) - (UInt256.ofNat 21) hd13350 mem_cost - (burnObserveSingleDecodedMem_mloadFreePtrPlus64 σ ee obsWord) - (by native_decide) - (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h13359 := evm_run h13351 with [ - raw swap3 hd13351 (by evm_ov), - raw pop hd13352 (by evm_ov), - raw swap3 hd13353 (by evm_ov), - raw pop hd13354 (by evm_ov), - raw pop hd13355 (by evm_ov), - raw push2 ⟨13584⟩ hd13356 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega)] - have h13584 := h13359.jump hd13359 - (uniswapV3PoolBurnJumpDestPatched13584 hpatch) (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h13595 := evm_run h13584 with [ - raw jumpdest hd13584 (by evm_ov), - raw swap8 hd13585 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw pop hd13586 (by evm_ov), - raw swap8 hd13587 (by - have hlen := hov - omega), - raw swap6 hd13588 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega), - raw pop hd13589 (by evm_ov), - raw pop hd13590 (by evm_ov), - raw pop hd13591 (by evm_ov), - raw pop hd13592 (by evm_ov), - raw pop hd13593 (by evm_ov), - raw pop hd13594 (by evm_ov)] - exact ⟨_, _, h13595.jump hd13595 hret (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega)⟩ - -theorem uniswapV3PoolBurnObserveSingleTimestampEqualLoadedReturn - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {obsWord cardinality liquidity index tick time ret : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13242⟩ - (obsWord :: burnPositionKeyNewFreePtrWord :: ⟨64⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - cardinality :: liquidity :: index :: tick :: ⟨0⟩ :: time :: ⟨8⟩ :: ret :: R) - (burnObserveSingleAllocMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (heq : UInt256.eq (UInt256.land time observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 25 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret - (burnObserveSingleDecodedSecondsWord obsWord :: - burnObserveSingleDecodedTickWord obsWord :: R) - (burnObserveSingleDecodedMem σ ee obsWord) (UInt256.ofNat 21) rdata (cA, σ) k' C' := by - obtain ⟨_, _, hjump⟩ := - uniswapV3PoolBurnObserveSingleTimestampEqualJump - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (obsWord := obsWord) (cardinality := cardinality) (liquidity := liquidity) - (index := index) (tick := tick) (time := time) (ret := ret) (R := R) - (rdata := rdata) (cA := cA) (σ := σ) hpatch h heq hov - exact - uniswapV3PoolBurnObserveSingleTimestampEqualReturn - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (obsWord := obsWord) (cardinality := cardinality) (liquidity := liquidity) - (index := index) (tick := tick) (time := time) (memPtr := ⟨8⟩) (ret := ret) - (R := R) (rdata := rdata) (cA := cA) (σ := σ) hpatch hjump hret (by omega) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdate.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdate.lean deleted file mode 100644 index a8c2fb85..00000000 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdate.lean +++ /dev/null @@ -1,1875 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnAfterFeeGrowthInside - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Reasoning.Theory - -def stMulmod (s : State) (res : UInt256) (t : List UInt256) : State := - { s with machineState := { s.machineState with - pc := s.machineState.pc + ⟨1⟩, stack := res :: t, - execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat GasConstants.Gmid } } - -theorem mulmod_xstep {s : State} {code : ByteArray} {pcv a b c : UInt256} - {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.MULMOD, .none)) - (hstk : s.machineState.stack = a :: b :: c :: t) (hov : t.length + 1 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < GasConstants.Gmid then .error .OutOfGass - else .ok (stMulmod s (a.mulMod b c) t, .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.MULMOD, .none) := by - rw [hcode, hpc] - exact hdec - rw [← hcode, step_mulmod s hd, hstk] - have hov' : ¬ ((a :: b :: c :: t).length - 3 + 1 > 1024) := by - simp only [List.length_cons] - omega - simp only [if_neg hov', stMulmod] - -end Reasoning.Theory - -namespace Reasoning.Reach - -open Reasoning.Theory - -theorem RD.mulmod {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: c :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.MULMOD, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (a.mulMod b c :: t) mem aw rdata acc (k + 1) - (C + GasConstants.Gmid) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, - hacc, hee, hworld⟩ - · exact Or.inl hoog - · have st := mulmod_xstep hcode hpc hdec hstk hov - have hcostpos : 0 < GasConstants.Gmid := by native_decide - by_cases gg : g.toNat < C + GasConstants.Gmid - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨stMulmod s (a.mulMod b c) t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, - by omega, by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [stMulmod] - exact hcode - · simp only [stMulmod] - rw [hpc] - · rfl - · simp only [stMulmod] - rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [stMulmod] - exact hmem - · simp only [stMulmod] - exact haw - · simp only [stMulmod] - exact hrdata - · simp only [stMulmod] - exact hacc - · exact hee - · exact hworld - -end Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem wordAt0Mem_read64_of_size_ge {mem : ByteArray} (word : UInt256) - (hmem : 96 ≤ mem.size) : - (wordAt0Mem word mem).readWithPadding 64 32 = mem.readWithPadding 64 32 := by - unfold wordAt0Mem - rw [write32_read_above _ _ 0 64 (by rw [toByteArray_size]) (by omega) (by omega) - (by omega)] - -theorem twoWordHashMem_read64_of_size_ge {mem : ByteArray} (key slot : UInt256) - (hmem : 96 ≤ mem.size) : - (twoWordHashMem key slot mem).readWithPadding 64 32 = - mem.readWithPadding 64 32 := by - unfold twoWordHashMem wordAt32Mem - rw [write32_read_above _ _ 32 64 (by rw [toByteArray_size]) - (by - rw [wordAt0Mem_size_of_size_ge] - · omega - · omega) - (by omega) - (by - rw [wordAt0Mem_size_of_size_ge] - · omega - · omega)] - exact wordAt0Mem_read64_of_size_ge key hmem - -theorem burnPositionKeyPackedHashMem_read64 (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyPackedHashMem σ I).readWithPadding 64 32 = - UInt256.toByteArray burnPositionKeyNewFreePtrWord := by - unfold burnPositionKeyPackedHashMem - exact writeWord_read_back (burnPositionKeyMem3 σ I) 64 - burnPositionKeyNewFreePtrWord - (by rw [burnPositionKeyMem3_size σ I]; native_decide) - -theorem burnPositionKeyMappingMem_read64 (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMappingMem σ I).readWithPadding 64 32 = - UInt256.toByteArray burnPositionKeyNewFreePtrWord := by - unfold burnPositionKeyMappingMem - rw [twoWordHashMem_read64_of_size_ge] - · exact burnPositionKeyPackedHashMem_read64 σ I - · rw [burnPositionKeyPackedHashMem_size σ I] - omega - -theorem burnTickLowerFeeGrowthMem_read64 (σ : AccountMap) (I : ExecutionEnv) : - (burnTickLowerFeeGrowthMem σ I).readWithPadding 64 32 = - UInt256.toByteArray burnPositionKeyNewFreePtrWord := by - unfold burnTickLowerFeeGrowthMem - rw [twoWordHashMem_read64_of_size_ge] - · exact burnPositionKeyMappingMem_read64 σ I - · rw [burnPositionKeyMappingMem_size σ I] - omega - -theorem burnTickUpperFeeGrowthMem_read64 (σ : AccountMap) (I : ExecutionEnv) : - (burnTickUpperFeeGrowthMem σ I).readWithPadding 64 32 = - UInt256.toByteArray burnPositionKeyNewFreePtrWord := by - unfold burnTickUpperFeeGrowthMem - rw [wordAt0Mem_read64_of_size_ge] - · exact burnTickLowerFeeGrowthMem_read64 σ I - · rw [burnTickLowerFeeGrowthMem_size σ I] - omega - -theorem burnTickUpperFeeGrowthMem_mload64 (σ : AccountMap) (I : ExecutionEnv) : - (if (⟨64⟩ : UInt256).toNat ≥ (burnTickUpperFeeGrowthMem σ I).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 18 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnTickUpperFeeGrowthMem σ I).readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - burnPositionKeyNewFreePtrWord := by - exact mloadWordValue_of_readWithPadding - (mem := burnTickUpperFeeGrowthMem σ I) (aw := UInt256.ofNat 18) - (off := ⟨64⟩) (v := burnPositionKeyNewFreePtrWord) - (by rw [burnTickUpperFeeGrowthMem_size σ I]; native_decide) - (by native_decide) - (by - simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using burnTickUpperFeeGrowthMem_read64 σ I) - -noncomputable abbrev burnPositionUpdateMem0 (σ : AccountMap) (I : ExecutionEnv) : - ByteArray := - writeWord (burnTickUpperFeeGrowthMem σ I) 64 - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) - -abbrev burnPositionUpdateSlot0Mask : UInt256 := - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨1⟩ - -abbrev burnPositionUpdateSlot0Packed (pos0 : UInt256) : UInt256 := - UInt256.land burnPositionUpdateSlot0Mask pos0 - -noncomputable abbrev burnPositionUpdateMem1 (σ : AccountMap) (I : ExecutionEnv) - (pos0 : UInt256) : ByteArray := - writeWord (burnPositionUpdateMem0 σ I) burnPositionKeyNewFreePtrWord.toNat - (burnPositionUpdateSlot0Packed pos0) - -noncomputable abbrev burnPositionUpdateMem2 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : ByteArray := - writeWord (burnPositionUpdateMem1 σ I pos0) - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat - (solcSlotWord σ I (posBase + (⟨1⟩ : UInt256))) - -noncomputable abbrev burnPositionUpdateMem3 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : ByteArray := - writeWord (burnPositionUpdateMem2 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat - (solcSlotWord σ I (posBase + (⟨2⟩ : UInt256))) - -noncomputable abbrev burnPositionUpdateMem4 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : ByteArray := - writeWord (burnPositionUpdateMem3 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat - (UInt256.land burnPositionUpdateSlot0Mask - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - -abbrev burnPositionUpdateTokensOwed1Packed (pos3 : UInt256) : UInt256 := - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div pos3 (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - -noncomputable abbrev burnPositionUpdateMem5 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : ByteArray := - writeWord (burnPositionUpdateMem4 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)).toNat - (burnPositionUpdateTokensOwed1Packed - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - -theorem burnPositionUpdateMem0_size (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionUpdateMem0 σ I).size = 567 := by - unfold burnPositionUpdateMem0 - rw [writeWord_size _ _ _ - (by rw [burnTickUpperFeeGrowthMem_size σ I]; native_decide)] - rw [burnTickUpperFeeGrowthMem_size σ I] - native_decide - -theorem burnPositionUpdateMem1_size (σ : AccountMap) (I : ExecutionEnv) - (pos0 : UInt256) : - (burnPositionUpdateMem1 σ I pos0).size = 570 := by - unfold burnPositionUpdateMem1 - rw [writeWord_size _ _ _ (by rw [burnPositionUpdateMem0_size σ I]; native_decide)] - rw [burnPositionUpdateMem0_size σ I] - native_decide - -theorem burnPositionUpdateMem2_size (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateMem2 σ I pos0 posBase).size = 602 := by - unfold burnPositionUpdateMem2 - rw [writeWord_size _ _ _ - (by rw [burnPositionUpdateMem1_size σ I pos0]; native_decide)] - rw [burnPositionUpdateMem1_size σ I pos0] - native_decide - -theorem burnPositionUpdateMem3_size (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateMem3 σ I pos0 posBase).size = 634 := by - unfold burnPositionUpdateMem3 - rw [writeWord_size _ _ _ - (by rw [burnPositionUpdateMem2_size σ I pos0 posBase]; native_decide)] - rw [burnPositionUpdateMem2_size σ I pos0 posBase] - native_decide - -theorem burnPositionUpdateMem4_size (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateMem4 σ I pos0 posBase).size = 666 := by - unfold burnPositionUpdateMem4 - rw [writeWord_size _ _ _ - (by rw [burnPositionUpdateMem3_size σ I pos0 posBase]; native_decide)] - rw [burnPositionUpdateMem3_size σ I pos0 posBase] - native_decide - -theorem burnPositionUpdateMem5_size (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateMem5 σ I pos0 posBase).size = 698 := by - unfold burnPositionUpdateMem5 - rw [writeWord_size _ _ _ - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide)] - rw [burnPositionUpdateMem4_size σ I pos0 posBase] - native_decide - -theorem burnPositionUpdateMem5_readFreePtr (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding - burnPositionKeyNewFreePtrWord.toNat 32 = - UInt256.toByteArray (burnPositionUpdateSlot0Packed pos0) := by - unfold burnPositionUpdateMem5 - rw [writeWord_read_preserved - (burnPositionUpdateMem4 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)).toNat - burnPositionKeyNewFreePtrWord.toNat - (burnPositionUpdateTokensOwed1Packed - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem4 - rw [writeWord_read_preserved - (burnPositionUpdateMem3 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat - burnPositionKeyNewFreePtrWord.toNat - (UInt256.land burnPositionUpdateSlot0Mask - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem3_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem3_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem3 - rw [writeWord_read_preserved - (burnPositionUpdateMem2 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat - burnPositionKeyNewFreePtrWord.toNat - (solcSlotWord σ I (posBase + (⟨2⟩ : UInt256))) - (by rw [burnPositionUpdateMem2_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem2_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem2 - rw [writeWord_read_preserved - (burnPositionUpdateMem1 σ I pos0) - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat - burnPositionKeyNewFreePtrWord.toNat - (solcSlotWord σ I (posBase + (⟨1⟩ : UInt256))) - (by rw [burnPositionUpdateMem1_size σ I pos0]; native_decide) - (by rw [burnPositionUpdateMem1_size σ I pos0]; native_decide)] - unfold burnPositionUpdateMem1 - exact writeWord_read_back (burnPositionUpdateMem0 σ I) - burnPositionKeyNewFreePtrWord.toNat (burnPositionUpdateSlot0Packed pos0) - (by rw [burnPositionUpdateMem0_size σ I]; native_decide) - -theorem burnPositionUpdateMem5_mloadFreePtr (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (if burnPositionKeyNewFreePtrWord.toNat ≥ - (burnPositionUpdateMem5 σ I pos0 posBase).size - ∨ burnPositionKeyNewFreePtrWord ≥ UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding - burnPositionKeyNewFreePtrWord.toNat 32))) = - burnPositionUpdateSlot0Packed pos0 := by - exact mloadWordValue_of_readWithPadding - (mem := burnPositionUpdateMem5 σ I pos0 posBase) (aw := UInt256.ofNat 22) - (off := burnPositionKeyNewFreePtrWord) (v := burnPositionUpdateSlot0Packed pos0) - (by rw [burnPositionUpdateMem5_size σ I pos0 posBase]; native_decide) - (by native_decide) - (burnPositionUpdateMem5_readFreePtr σ I pos0 posBase) - -theorem burnPositionUpdateMem5_read64 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding 64 32 = - UInt256.toByteArray (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) := by - unfold burnPositionUpdateMem5 - rw [writeWord_read_preserved - (burnPositionUpdateMem4 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)).toNat - 64 - (burnPositionUpdateTokensOwed1Packed - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem4 - rw [writeWord_read_preserved - (burnPositionUpdateMem3 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat - 64 - (UInt256.land burnPositionUpdateSlot0Mask - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem3_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem3_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem3 - rw [writeWord_read_preserved - (burnPositionUpdateMem2 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat - 64 - (solcSlotWord σ I (posBase + (⟨2⟩ : UInt256))) - (by rw [burnPositionUpdateMem2_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem2_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem2 - rw [writeWord_read_preserved - (burnPositionUpdateMem1 σ I pos0) - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat - 64 - (solcSlotWord σ I (posBase + (⟨1⟩ : UInt256))) - (by rw [burnPositionUpdateMem1_size σ I pos0]; native_decide) - (by rw [burnPositionUpdateMem1_size σ I pos0]; native_decide)] - unfold burnPositionUpdateMem1 - rw [writeWord_read_preserved - (burnPositionUpdateMem0 σ I) - burnPositionKeyNewFreePtrWord.toNat - 64 - (burnPositionUpdateSlot0Packed pos0) - (by rw [burnPositionUpdateMem0_size σ I]; native_decide) - (by rw [burnPositionUpdateMem0_size σ I]; native_decide)] - unfold burnPositionUpdateMem0 - exact writeWord_read_back (burnTickUpperFeeGrowthMem σ I) 64 - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) - (by rw [burnTickUpperFeeGrowthMem_size σ I]; native_decide) - -theorem burnPositionUpdateMem5_mload64 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (burnPositionUpdateMem5 σ I pos0 posBase).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) := by - exact mloadWordValue_of_readWithPadding - (mem := burnPositionUpdateMem5 σ I pos0 posBase) (aw := UInt256.ofNat 22) - (off := ⟨64⟩) (v := burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) - (by rw [burnPositionUpdateMem5_size σ I pos0 posBase]; native_decide) - (by native_decide) - (by - simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using burnPositionUpdateMem5_read64 σ I pos0 posBase) - -theorem burnPositionUpdateMem5_readFreePtrPlus32 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat 32 = - UInt256.toByteArray (solcSlotWord σ I (posBase + (⟨1⟩ : UInt256))) := by - unfold burnPositionUpdateMem5 - rw [writeWord_read_preserved - (burnPositionUpdateMem4 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)).toNat - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat - (burnPositionUpdateTokensOwed1Packed - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem4 - rw [writeWord_read_preserved - (burnPositionUpdateMem3 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat - (UInt256.land burnPositionUpdateSlot0Mask - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem3_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem3_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem3 - rw [writeWord_read_preserved - (burnPositionUpdateMem2 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat - (solcSlotWord σ I (posBase + (⟨2⟩ : UInt256))) - (by rw [burnPositionUpdateMem2_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem2_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem2 - exact writeWord_read_back (burnPositionUpdateMem1 σ I pos0) - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat - (solcSlotWord σ I (posBase + (⟨1⟩ : UInt256))) - (by rw [burnPositionUpdateMem1_size σ I pos0]; native_decide) - -theorem burnPositionUpdateMem5_mloadFreePtrPlus32 (σ : AccountMap) - (I : ExecutionEnv) (pos0 posBase : UInt256) : - (if (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat ≥ - (burnPositionUpdateMem5 σ I pos0 posBase).size - ∨ (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)) ≥ - UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat 32))) = - solcSlotWord σ I (posBase + (⟨1⟩ : UInt256)) := by - exact mloadWordValue_of_readWithPadding - (mem := burnPositionUpdateMem5 σ I pos0 posBase) (aw := UInt256.ofNat 22) - (off := burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)) - (v := solcSlotWord σ I (posBase + (⟨1⟩ : UInt256))) - (by rw [burnPositionUpdateMem5_size σ I pos0 posBase]; native_decide) - (by native_decide) - (burnPositionUpdateMem5_readFreePtrPlus32 σ I pos0 posBase) - -theorem burnPositionUpdateMem5_readFreePtrPlus64 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat 32 = - UInt256.toByteArray (solcSlotWord σ I (posBase + (⟨2⟩ : UInt256))) := by - unfold burnPositionUpdateMem5 - rw [writeWord_read_preserved - (burnPositionUpdateMem4 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)).toNat - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat - (burnPositionUpdateTokensOwed1Packed - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem4 - rw [writeWord_read_preserved - (burnPositionUpdateMem3 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat - (UInt256.land burnPositionUpdateSlot0Mask - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem3_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem3_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem3 - exact writeWord_read_back (burnPositionUpdateMem2 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat - (solcSlotWord σ I (posBase + (⟨2⟩ : UInt256))) - (by rw [burnPositionUpdateMem2_size σ I pos0 posBase]; native_decide) - -theorem burnPositionUpdateMem5_mloadFreePtrPlus64 (σ : AccountMap) - (I : ExecutionEnv) (pos0 posBase : UInt256) : - (if (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat ≥ - (burnPositionUpdateMem5 σ I pos0 posBase).size - ∨ (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)) ≥ - UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat 32))) = - solcSlotWord σ I (posBase + (⟨2⟩ : UInt256)) := by - exact mloadWordValue_of_readWithPadding - (mem := burnPositionUpdateMem5 σ I pos0 posBase) (aw := UInt256.ofNat 22) - (off := burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)) - (v := solcSlotWord σ I (posBase + (⟨2⟩ : UInt256))) - (by rw [burnPositionUpdateMem5_size σ I pos0 posBase]; native_decide) - (by native_decide) - (burnPositionUpdateMem5_readFreePtrPlus64 σ I pos0 posBase) - -theorem burnPositionUpdateMem5_readFreePtrPlus96 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat 32 = - UInt256.toByteArray - (UInt256.land burnPositionUpdateSlot0Mask - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) := by - unfold burnPositionUpdateMem5 - rw [writeWord_read_preserved - (burnPositionUpdateMem4 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)).toNat - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat - (burnPositionUpdateTokensOwed1Packed - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem4 - exact writeWord_read_back (burnPositionUpdateMem3 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat - (UInt256.land burnPositionUpdateSlot0Mask - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem3_size σ I pos0 posBase]; native_decide) - -theorem burnPositionUpdateMem5_mloadFreePtrPlus96 (σ : AccountMap) - (I : ExecutionEnv) (pos0 posBase : UInt256) : - (if (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat ≥ - (burnPositionUpdateMem5 σ I pos0 posBase).size - ∨ (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)) ≥ - UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat 32))) = - UInt256.land burnPositionUpdateSlot0Mask - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256))) := by - exact mloadWordValue_of_readWithPadding - (mem := burnPositionUpdateMem5 σ I pos0 posBase) (aw := UInt256.ofNat 22) - (off := burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)) - (v := UInt256.land burnPositionUpdateSlot0Mask - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem5_size σ I pos0 posBase]; native_decide) - (by native_decide) - (burnPositionUpdateMem5_readFreePtrPlus96 σ I pos0 posBase) - -theorem burnPositionUpdateMem5_readFreePtrPlus128 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)).toNat 32 = - UInt256.toByteArray - (burnPositionUpdateTokensOwed1Packed - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) := by - unfold burnPositionUpdateMem5 - exact writeWord_read_back (burnPositionUpdateMem4 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)).toNat - (burnPositionUpdateTokensOwed1Packed - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide) - -theorem burnPositionUpdateMem5_mloadFreePtrPlus128 (σ : AccountMap) - (I : ExecutionEnv) (pos0 posBase : UInt256) : - (if (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)).toNat ≥ - (burnPositionUpdateMem5 σ I pos0 posBase).size - ∨ (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)) ≥ - UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)).toNat 32))) = - burnPositionUpdateTokensOwed1Packed - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256))) := by - exact mloadWordValue_of_readWithPadding - (mem := burnPositionUpdateMem5 σ I pos0 posBase) (aw := UInt256.ofNat 22) - (off := burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)) - (v := burnPositionUpdateTokensOwed1Packed - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem5_size σ I pos0 posBase]; native_decide) - (by native_decide) - (burnPositionUpdateMem5_readFreePtrPlus128 σ I pos0 posBase) - -theorem burnPositionUpdateSlot0Mask_eq_uint128Mask : - burnPositionUpdateSlot0Mask = uint128Mask := by - native_decide - -theorem burnPositionUpdateSlot0Packed_mask (pos0 : UInt256) : - UInt256.land burnPositionUpdateSlot0Mask (burnPositionUpdateSlot0Packed pos0) = - burnPositionUpdateSlot0Packed pos0 := by - have hmask : burnPositionUpdateSlot0Mask = uint128Mask := by native_decide - unfold burnPositionUpdateSlot0Packed - rw [hmask] - exact uint128Mask_clean_left - (by - rw [u256_land_comm] - exact uint128Mask_bound pos0) - -private theorem uniswapV3PoolBurnPositionUpdateDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 21559 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21801) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 21801 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -private theorem uniswapV3PoolPatchPreservesJumpDest21710 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨21710⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched21710 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨21710⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest21710 - -private theorem uniswapV3PoolPatchPreservesJumpDest21733 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨21733⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched21733 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨21733⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest21733 - -private theorem uniswapV3PoolPatchPreservesJumpDest13017 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨13017⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched13017 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨13017⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest13017 - -private theorem uniswapV3PoolPatchPreservesJumpDest13060 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨13060⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched13060 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨13060⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest13060 - -private theorem uniswapV3PoolPatchPreservesJumpDest13071 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨13071⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched13071 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨13071⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest13071 - -private theorem uniswapV3PoolPatchPreservesJumpDest13083 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨13083⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched13083 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨13083⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest13083 - -private theorem uniswapV3PoolPatchPreservesJumpDest13186 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨13186⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched13186 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨13186⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest13186 - -private theorem uniswapV3PoolFullMathMulDivPatchDisjoint33 {v : PoolImmutables} - {pc : UInt256} - (hlo : 13017 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13225) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -private theorem uniswapV3PoolFullMathMulDivDecodeEqTemplate {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 13017 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13225) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 13225 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolFullMathMulDivPatchDisjoint33 (v := v) (pc := pc) hlo hhi) - -abbrev uniswapV3PoolFullMathMulDivProd0 (a b : UInt256) : UInt256 := - UInt256.mul b a - -abbrev uniswapV3PoolFullMathMulDivProd1 (a b : UInt256) : UInt256 := - UInt256.sub - (UInt256.sub (a.mulMod b (UInt256.lnot (⟨0⟩ : UInt256))) - (uniswapV3PoolFullMathMulDivProd0 a b)) - (UInt256.lt (a.mulMod b (UInt256.lnot (⟨0⟩ : UInt256))) - (uniswapV3PoolFullMathMulDivProd0 a b)) - -theorem uniswapV3PoolFullMathMulDivStartProduct {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {den b a ret z : UInt256} {R : List UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13017⟩ (den :: b :: a :: ret :: z :: R) - mem aw rdata acc k C) - (hov : R.length + 20 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨13044⟩ - (uniswapV3PoolFullMathMulDivProd1 a b :: - uniswapV3PoolFullMathMulDivProd1 a b :: - uniswapV3PoolFullMathMulDivProd0 a b :: ⟨0⟩ :: den :: b :: a :: ret :: z :: R) - mem aw rdata acc k' C' := by - have hdec (pc : UInt256) - (hlo : 13017 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13225) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolFullMathMulDivDecodeEqTemplate hpatch hlo hhi - have hd13017 : decode code ⟨13017⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨13017⟩ (by native_decide) (by native_decide)] - native_decide - have hd13018 : - decode code ⟨13018⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨13018⟩ (by native_decide) (by native_decide)] - native_decide - have hd13020 : decode code ⟨13020⟩ = some (.DUP1, .none) := by - rw [hdec ⟨13020⟩ (by native_decide) (by native_decide)] - native_decide - have hd13021 : decode code ⟨13021⟩ = some (.DUP1, .none) := by - rw [hdec ⟨13021⟩ (by native_decide) (by native_decide)] - native_decide - have hd13022 : - decode code ⟨13022⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨13022⟩ (by native_decide) (by native_decide)] - native_decide - have hd13024 : decode code ⟨13024⟩ = some (.NOT, .none) := by - rw [hdec ⟨13024⟩ (by native_decide) (by native_decide)] - native_decide - have hd13025 : decode code ⟨13025⟩ = some (.DUP6, .none) := by - rw [hdec ⟨13025⟩ (by native_decide) (by native_decide)] - native_decide - have hd13026 : decode code ⟨13026⟩ = some (.DUP8, .none) := by - rw [hdec ⟨13026⟩ (by native_decide) (by native_decide)] - native_decide - have hd13027 : decode code ⟨13027⟩ = some (.MULMOD, .none) := by - rw [hdec ⟨13027⟩ (by native_decide) (by native_decide)] - native_decide - have hd13028 : decode code ⟨13028⟩ = some (.DUP7, .none) := by - rw [hdec ⟨13028⟩ (by native_decide) (by native_decide)] - native_decide - have hd13029 : decode code ⟨13029⟩ = some (.DUP7, .none) := by - rw [hdec ⟨13029⟩ (by native_decide) (by native_decide)] - native_decide - have hd13030 : decode code ⟨13030⟩ = some (.MUL, .none) := by - rw [hdec ⟨13030⟩ (by native_decide) (by native_decide)] - native_decide - have hd13031 : decode code ⟨13031⟩ = some (.SWAP3, .none) := by - rw [hdec ⟨13031⟩ (by native_decide) (by native_decide)] - native_decide - have hd13032 : decode code ⟨13032⟩ = some (.POP, .none) := by - rw [hdec ⟨13032⟩ (by native_decide) (by native_decide)] - native_decide - have hd13033 : decode code ⟨13033⟩ = some (.DUP3, .none) := by - rw [hdec ⟨13033⟩ (by native_decide) (by native_decide)] - native_decide - have hd13034 : decode code ⟨13034⟩ = some (.DUP2, .none) := by - rw [hdec ⟨13034⟩ (by native_decide) (by native_decide)] - native_decide - have hd13035 : decode code ⟨13035⟩ = some (.LT, .none) := by - rw [hdec ⟨13035⟩ (by native_decide) (by native_decide)] - native_decide - have hd13036 : decode code ⟨13036⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨13036⟩ (by native_decide) (by native_decide)] - native_decide - have hd13037 : decode code ⟨13037⟩ = some (.DUP4, .none) := by - rw [hdec ⟨13037⟩ (by native_decide) (by native_decide)] - native_decide - have hd13038 : decode code ⟨13038⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨13038⟩ (by native_decide) (by native_decide)] - native_decide - have hd13039 : decode code ⟨13039⟩ = some (.SUB, .none) := by - rw [hdec ⟨13039⟩ (by native_decide) (by native_decide)] - native_decide - have hd13040 : decode code ⟨13040⟩ = some (.SUB, .none) := by - rw [hdec ⟨13040⟩ (by native_decide) (by native_decide)] - native_decide - have hd13041 : decode code ⟨13041⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨13041⟩ (by native_decide) (by native_decide)] - native_decide - have hd13042 : decode code ⟨13042⟩ = some (.POP, .none) := by - rw [hdec ⟨13042⟩ (by native_decide) (by native_decide)] - native_decide - have hd13043 : decode code ⟨13043⟩ = some (.DUP1, .none) := by - rw [hdec ⟨13043⟩ (by native_decide) (by native_decide)] - native_decide - have rd13044 := evm_run h with [ - raw jumpdest hd13017 (by evm_ov), - raw push1 ⟨0⟩ hd13018 (by evm_ov), - raw dup1 hd13020 (by evm_ov), - raw dup1 hd13021 (by evm_ov), - raw push1 ⟨0⟩ hd13022 (by evm_ov), - raw not hd13024 (by evm_ov), - raw dup6 hd13025 (by evm_ov), - raw dup8 hd13026 (by evm_ov), - raw mulmod hd13027 (by evm_ov), - raw dup7 hd13028 (by evm_ov), - raw dup7 hd13029 (by evm_ov), - raw mul hd13030 (by evm_ov), - raw swap3 hd13031 (by evm_ov), - raw pop hd13032 (by evm_ov), - raw dup3 hd13033 (by evm_ov), - raw dup2 hd13034 (by evm_ov), - raw lt hd13035 (by evm_ov), - raw swap1 hd13036 (by evm_ov), - raw dup4 hd13037 (by evm_ov), - raw swap1 hd13038 (by evm_ov), - raw sub hd13039 (by evm_ov), - raw sub hd13040 (by evm_ov), - raw swap1 hd13041 (by evm_ov), - raw pop hd13042 (by evm_ov), - raw dup1 hd13043 (by evm_ov)] - exact ⟨_, _, by - simpa [uniswapV3PoolFullMathMulDivProd0, uniswapV3PoolFullMathMulDivProd1] using - rd13044⟩ - -theorem uniswapV3PoolFullMathMulDivProd1ZeroReturn {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {prod1 prod0 den b a ret z : UInt256} {R : List UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13044⟩ - (prod1 :: prod1 :: prod0 :: ⟨0⟩ :: den :: b :: a :: ret :: z :: R) - mem aw rdata acc k C) - (hprod1 : prod1 = ⟨0⟩) (hden : UInt256.gt den ⟨0⟩ ≠ ⟨0⟩) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 20 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret (UInt256.div prod0 den :: z :: R) - mem aw rdata acc k' C' := by - have hdec (pc : UInt256) - (hlo : 13017 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13225) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolFullMathMulDivDecodeEqTemplate hpatch hlo hhi - have hd13044 : - decode code ⟨13044⟩ = some (.Push .PUSH2, some (⟨13071⟩, 2)) := by - rw [hdec ⟨13044⟩ (by native_decide) (by native_decide)] - native_decide - have hd13047 : decode code ⟨13047⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨13047⟩ (by native_decide) (by native_decide)] - native_decide - have hd13048 : - decode code ⟨13048⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨13048⟩ (by native_decide) (by native_decide)] - native_decide - have hd13050 : decode code ⟨13050⟩ = some (.DUP5, .none) := by - rw [hdec ⟨13050⟩ (by native_decide) (by native_decide)] - native_decide - have hd13051 : decode code ⟨13051⟩ = some (.GT, .none) := by - rw [hdec ⟨13051⟩ (by native_decide) (by native_decide)] - native_decide - have hd13052 : - decode code ⟨13052⟩ = some (.Push .PUSH2, some (⟨13060⟩, 2)) := by - rw [hdec ⟨13052⟩ (by native_decide) (by native_decide)] - native_decide - have hd13055 : decode code ⟨13055⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨13055⟩ (by native_decide) (by native_decide)] - native_decide - have hd13060 : decode code ⟨13060⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨13060⟩ (by native_decide) (by native_decide)] - native_decide - have hd13061 : decode code ⟨13061⟩ = some (.POP, .none) := by - rw [hdec ⟨13061⟩ (by native_decide) (by native_decide)] - native_decide - have hd13062 : decode code ⟨13062⟩ = some (.DUP3, .none) := by - rw [hdec ⟨13062⟩ (by native_decide) (by native_decide)] - native_decide - have hd13063 : decode code ⟨13063⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨13063⟩ (by native_decide) (by native_decide)] - native_decide - have hd13064 : decode code ⟨13064⟩ = some (.DIV, .none) := by - rw [hdec ⟨13064⟩ (by native_decide) (by native_decide)] - native_decide - have hd13065 : decode code ⟨13065⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨13065⟩ (by native_decide) (by native_decide)] - native_decide - have hd13066 : decode code ⟨13066⟩ = some (.POP, .none) := by - rw [hdec ⟨13066⟩ (by native_decide) (by native_decide)] - native_decide - have hd13067 : - decode code ⟨13067⟩ = some (.Push .PUSH2, some (⟨13186⟩, 2)) := by - rw [hdec ⟨13067⟩ (by native_decide) (by native_decide)] - native_decide - have hd13070 : decode code ⟨13070⟩ = some (.JUMP, .none) := by - rw [hdec ⟨13070⟩ (by native_decide) (by native_decide)] - native_decide - have hd13186 : decode code ⟨13186⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨13186⟩ (by native_decide) (by native_decide)] - native_decide - have hd13187 : decode code ⟨13187⟩ = some (.SWAP4, .none) := by - rw [hdec ⟨13187⟩ (by native_decide) (by native_decide)] - native_decide - have hd13188 : decode code ⟨13188⟩ = some (.SWAP3, .none) := by - rw [hdec ⟨13188⟩ (by native_decide) (by native_decide)] - native_decide - have hd13189 : decode code ⟨13189⟩ = some (.POP, .none) := by - rw [hdec ⟨13189⟩ (by native_decide) (by native_decide)] - native_decide - have hd13190 : decode code ⟨13190⟩ = some (.POP, .none) := by - rw [hdec ⟨13190⟩ (by native_decide) (by native_decide)] - native_decide - have hd13191 : decode code ⟨13191⟩ = some (.POP, .none) := by - rw [hdec ⟨13191⟩ (by native_decide) (by native_decide)] - native_decide - have hd13192 : decode code ⟨13192⟩ = some (.JUMP, .none) := by - rw [hdec ⟨13192⟩ (by native_decide) (by native_decide)] - native_decide - have rd13047 := evm_run h with [ - raw push2 ⟨13071⟩ hd13044 (by evm_ov)] - have rd13048 := by - simpa [hprod1] using rd13047.jumpiNT hd13047 hprod1 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd13055 := evm_run rd13048 with [ - raw push1 ⟨0⟩ hd13048 (by evm_ov), - raw dup5 hd13050 (by evm_ov), - raw gt hd13051 (by evm_ov), - raw push2 ⟨13060⟩ hd13052 (by evm_ov)] - have rd13060 := rd13055.jumpiT hd13055 hden - (uniswapV3PoolJumpDestPatched13060 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd13070 := evm_run rd13060 with [ - raw jumpdest hd13060 (by evm_ov), - raw pop hd13061 (by evm_ov), - raw dup3 hd13062 (by evm_ov), - raw swap1 hd13063 (by evm_ov), - raw div hd13064 (by evm_ov), - raw swap1 hd13065 (by evm_ov), - raw pop hd13066 (by evm_ov), - raw push2 ⟨13186⟩ hd13067 (by evm_ov)] - have rd13186 := rd13070.jump hd13070 - (uniswapV3PoolJumpDestPatched13186 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd13192 := evm_run rd13186 with [ - raw jumpdest hd13186 (by evm_ov), - raw swap4 hd13187 (by evm_ov), - raw swap3 hd13188 (by evm_ov), - raw pop hd13189 (by evm_ov), - raw pop hd13190 (by evm_ov), - raw pop hd13191 (by evm_ov)] - exact ⟨_, _, rd13192.jump hd13192 hret - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnPositionUpdateLoadSlot0 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21559⟩ - (inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 23 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21572⟩ - (solcSlotWord σ ee posBase :: burnPositionKeyNewFreePtrWord :: ⟨64⟩ :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem0 σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21559 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21801) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateDecodeEqTemplate hpatch hlo hhi - have rd21563 := evm_run h with [ - raw jumpdest (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw push1 ⟨64⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup1 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - have rd21564 := by - simpa using - rd21563.mload 0 burnPositionKeyNewFreePtrWord (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost (burnTickUpperFeeGrowthMem_mload64 σ ee) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21569 := evm_run rd21564 with [ - raw push1 ⟨160⟩ (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup2 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega), - raw add (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov), - raw dup3 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega)] - have rd21570 := by - simpa [burnPositionUpdateMem0] using - rd21569.mstore 0 (burnPositionUpdateMem0 σ ee) (UInt256.ofNat 18) - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - mem_cost (by rfl) (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21571 := evm_run rd21570 with [ - raw dup6 (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by evm_ov)] - obtain ⟨_, _, rd21572⟩ := rd21571.sload - (by rw [hdec _ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, rd21572⟩ - -theorem uniswapV3PoolBurnPositionUpdateStoreSlot0Packed {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pos0 inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21572⟩ - (pos0 :: burnPositionKeyNewFreePtrWord :: ⟨64⟩ :: inside1 :: inside0 :: - delta :: posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: - fee0 :: posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem0 σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 30 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21585⟩ - (burnPositionUpdateSlot0Mask :: burnPositionKeyNewFreePtrWord :: ⟨64⟩ :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem1 σ ee pos0) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21559 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21801) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateDecodeEqTemplate hpatch hlo hhi - have hd21572 : - decode code ⟨21572⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21572⟩ (by native_decide) (by native_decide)] - native_decide - have hd21574 : - decode code ⟨21574⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21574⟩ (by native_decide) (by native_decide)] - native_decide - have hd21575 : - decode code ⟨21576⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21576⟩ (by native_decide) (by native_decide)] - native_decide - have hd21578 : decode code ⟨21578⟩ = some (.SHL, .none) := by - rw [hdec ⟨21578⟩ (by native_decide) (by native_decide)] - native_decide - have hd21579 : decode code ⟨21579⟩ = some (.SUB, .none) := by - rw [hdec ⟨21579⟩ (by native_decide) (by native_decide)] - native_decide - have hd21580 : decode code ⟨21580⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨21580⟩ (by native_decide) (by native_decide)] - native_decide - have hd21581 : decode code ⟨21581⟩ = some (.DUP2, .none) := by - rw [hdec ⟨21581⟩ (by native_decide) (by native_decide)] - native_decide - have hd21582 : decode code ⟨21582⟩ = some (.AND, .none) := by - rw [hdec ⟨21582⟩ (by native_decide) (by native_decide)] - native_decide - have hd21583 : decode code ⟨21583⟩ = some (.DUP3, .none) := by - rw [hdec ⟨21583⟩ (by native_decide) (by native_decide)] - native_decide - have hd21584 : decode code ⟨21584⟩ = some (.MSTORE, .none) := by - rw [hdec ⟨21584⟩ (by native_decide) (by native_decide)] - native_decide - have rd21584 := evm_run h with [ - raw push1 ⟨1⟩ hd21572 (by evm_ov), - raw push1 ⟨1⟩ hd21574 (by evm_ov), - raw push1 ⟨128⟩ hd21575 (by evm_ov), - raw shl hd21578 (by evm_ov), - raw sub hd21579 (by evm_ov), - raw swap1 hd21580 (by evm_ov), - raw dup2 hd21581 (by simp only [List.length_cons] at hov ⊢; omega), - raw and hd21582 (by evm_ov), - raw dup3 hd21583 (by simp only [List.length_cons] at hov ⊢; omega)] - have rd21585 := by - simpa [burnPositionUpdateMem1, burnPositionUpdateSlot0Packed, - burnPositionUpdateSlot0Mask] using - rd21584.mstore 0 (burnPositionUpdateMem1 σ ee pos0) (UInt256.ofNat 18) - hd21584 - mem_cost (by rfl) (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, rd21585⟩ - -theorem uniswapV3PoolBurnPositionUpdateStoreFeeGrowthInside0Last {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21585⟩ - (burnPositionUpdateSlot0Mask :: burnPositionKeyNewFreePtrWord :: ⟨64⟩ :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem1 σ ee (solcSlotWord σ ee posBase)) - (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 30 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21595⟩ - (burnPositionUpdateSlot0Mask :: burnPositionKeyNewFreePtrWord :: ⟨64⟩ :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem2 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 19) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21559 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21801) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateDecodeEqTemplate hpatch hlo hhi - have hd21585 : - decode code ⟨21585⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21585⟩ (by native_decide) (by native_decide)] - native_decide - have hd21587 : decode code ⟨21587⟩ = some (.DUP8, .none) := by - rw [hdec ⟨21587⟩ (by native_decide) (by native_decide)] - native_decide - have hd21588 : decode code ⟨21588⟩ = some (.ADD, .none) := by - rw [hdec ⟨21588⟩ (by native_decide) (by native_decide)] - native_decide - have hd21589 : decode code ⟨21589⟩ = some (.SLOAD, .none) := by - rw [hdec ⟨21589⟩ (by native_decide) (by native_decide)] - native_decide - have hd21590 : - decode code ⟨21590⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdec ⟨21590⟩ (by native_decide) (by native_decide)] - native_decide - have hd21592 : decode code ⟨21592⟩ = some (.DUP4, .none) := by - rw [hdec ⟨21592⟩ (by native_decide) (by native_decide)] - native_decide - have hd21593 : decode code ⟨21593⟩ = some (.ADD, .none) := by - rw [hdec ⟨21593⟩ (by native_decide) (by native_decide)] - native_decide - have hd21594 : decode code ⟨21594⟩ = some (.MSTORE, .none) := by - rw [hdec ⟨21594⟩ (by native_decide) (by native_decide)] - native_decide - have rd21589 := evm_run h with [ - raw push1 ⟨1⟩ hd21585 (by evm_ov), - raw dup8 hd21587 (by simp only [List.length_cons] at hov ⊢; omega), - raw add hd21588 (by evm_ov)] - obtain ⟨_, _, rd21590⟩ := rd21589.sload hd21589 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21594 := evm_run rd21590 with [ - raw push1 ⟨32⟩ hd21590 (by evm_ov), - raw dup4 hd21592 (by simp only [List.length_cons] at hov ⊢; omega), - raw add hd21593 (by evm_ov)] - have rd21595 := by - simpa [burnPositionUpdateMem2] using - rd21594.mstore 3 - (burnPositionUpdateMem2 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 19) hd21594 mem_cost (by rfl) (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, rd21595⟩ - -theorem uniswapV3PoolBurnPositionUpdateStoreFeeGrowthInside1Last {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21595⟩ - (burnPositionUpdateSlot0Mask :: burnPositionKeyNewFreePtrWord :: ⟨64⟩ :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem2 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 19) rdata (cA, σ) k C) - (hov : R.length + 30 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21607⟩ - (burnPositionKeyNewFreePtrWord :: burnPositionUpdateSlot0Mask :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem3 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 20) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21559 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21801) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateDecodeEqTemplate hpatch hlo hhi - have hd21595 : - decode code ⟨21595⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdec ⟨21595⟩ (by native_decide) (by native_decide)] - native_decide - have hd21597 : decode code ⟨21597⟩ = some (.DUP8, .none) := by - rw [hdec ⟨21597⟩ (by native_decide) (by native_decide)] - native_decide - have hd21598 : decode code ⟨21598⟩ = some (.ADD, .none) := by - rw [hdec ⟨21598⟩ (by native_decide) (by native_decide)] - native_decide - have hd21599 : decode code ⟨21599⟩ = some (.SLOAD, .none) := by - rw [hdec ⟨21599⟩ (by native_decide) (by native_decide)] - native_decide - have hd21600 : decode code ⟨21600⟩ = some (.SWAP3, .none) := by - rw [hdec ⟨21600⟩ (by native_decide) (by native_decide)] - native_decide - have hd21601 : decode code ⟨21601⟩ = some (.DUP3, .none) := by - rw [hdec ⟨21601⟩ (by native_decide) (by native_decide)] - native_decide - have hd21602 : decode code ⟨21602⟩ = some (.ADD, .none) := by - rw [hdec ⟨21602⟩ (by native_decide) (by native_decide)] - native_decide - have hd21603 : decode code ⟨21603⟩ = some (.SWAP3, .none) := by - rw [hdec ⟨21603⟩ (by native_decide) (by native_decide)] - native_decide - have hd21604 : decode code ⟨21604⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨21604⟩ (by native_decide) (by native_decide)] - native_decide - have hd21605 : decode code ⟨21605⟩ = some (.SWAP3, .none) := by - rw [hdec ⟨21605⟩ (by native_decide) (by native_decide)] - native_decide - have hd21606 : decode code ⟨21606⟩ = some (.MSTORE, .none) := by - rw [hdec ⟨21606⟩ (by native_decide) (by native_decide)] - native_decide - have rd21599 := evm_run h with [ - raw push1 ⟨2⟩ hd21595 (by evm_ov), - raw dup8 hd21597 (by simp only [List.length_cons] at hov ⊢; omega), - raw add hd21598 (by evm_ov)] - obtain ⟨_, _, rd21600⟩ := rd21599.sload hd21599 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21606 := evm_run rd21600 with [ - raw swap3 hd21600 (by simp only [List.length_cons] at hov ⊢; omega), - raw dup3 hd21601 (by simp only [List.length_cons] at hov ⊢; omega), - raw add hd21602 (by evm_ov), - raw swap3 hd21603 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap1 hd21604 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap3 hd21605 (by simp only [List.length_cons] at hov ⊢; omega)] - have rd21607 := by - simpa [burnPositionUpdateMem3] using - rd21606.mstore 3 - (burnPositionUpdateMem3 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 20) hd21606 mem_cost (by rfl) (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, rd21607⟩ - -theorem uniswapV3PoolBurnPositionUpdateStoreTokensOwed0 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21607⟩ - (burnPositionKeyNewFreePtrWord :: burnPositionUpdateSlot0Mask :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem3 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 20) rdata (cA, σ) k C) - (hov : R.length + 30 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21620⟩ - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256)) :: - burnPositionKeyNewFreePtrWord :: burnPositionUpdateSlot0Mask :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem4 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 21) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21559 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21801) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateDecodeEqTemplate hpatch hlo hhi - have hd21607 : - decode code ⟨21607⟩ = some (.Push .PUSH1, some (⟨3⟩, 1)) := by - rw [hdec ⟨21607⟩ (by native_decide) (by native_decide)] - native_decide - have hd21609 : decode code ⟨21609⟩ = some (.DUP7, .none) := by - rw [hdec ⟨21609⟩ (by native_decide) (by native_decide)] - native_decide - have hd21610 : decode code ⟨21610⟩ = some (.ADD, .none) := by - rw [hdec ⟨21610⟩ (by native_decide) (by native_decide)] - native_decide - have hd21611 : decode code ⟨21611⟩ = some (.SLOAD, .none) := by - rw [hdec ⟨21611⟩ (by native_decide) (by native_decide)] - native_decide - have hd21612 : decode code ⟨21612⟩ = some (.DUP1, .none) := by - rw [hdec ⟨21612⟩ (by native_decide) (by native_decide)] - native_decide - have hd21613 : decode code ⟨21613⟩ = some (.DUP4, .none) := by - rw [hdec ⟨21613⟩ (by native_decide) (by native_decide)] - native_decide - have hd21614 : decode code ⟨21614⟩ = some (.AND, .none) := by - rw [hdec ⟨21614⟩ (by native_decide) (by native_decide)] - native_decide - have hd21615 : - decode code ⟨21615⟩ = some (.Push .PUSH1, some (⟨96⟩, 1)) := by - rw [hdec ⟨21615⟩ (by native_decide) (by native_decide)] - native_decide - have hd21617 : decode code ⟨21617⟩ = some (.DUP4, .none) := by - rw [hdec ⟨21617⟩ (by native_decide) (by native_decide)] - native_decide - have hd21618 : decode code ⟨21618⟩ = some (.ADD, .none) := by - rw [hdec ⟨21618⟩ (by native_decide) (by native_decide)] - native_decide - have hd21619 : decode code ⟨21619⟩ = some (.MSTORE, .none) := by - rw [hdec ⟨21619⟩ (by native_decide) (by native_decide)] - native_decide - have rd21611 := evm_run h with [ - raw push1 ⟨3⟩ hd21607 (by evm_ov), - raw dup7 hd21609 (by simp only [List.length_cons] at hov ⊢; omega), - raw add hd21610 (by evm_ov)] - obtain ⟨_, _, rd21612⟩ := rd21611.sload hd21611 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21619 := evm_run rd21612 with [ - raw dup1 hd21612 (by simp only [List.length_cons] at hov ⊢; omega), - raw dup4 hd21613 (by simp only [List.length_cons] at hov ⊢; omega), - raw and hd21614 (by evm_ov), - raw push1 ⟨96⟩ hd21615 (by evm_ov), - raw dup4 hd21617 (by simp only [List.length_cons] at hov ⊢; omega), - raw add hd21618 (by evm_ov)] - have rd21620 := by - simpa [burnPositionUpdateMem4] using - rd21619.mstore 3 - (burnPositionUpdateMem4 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 21) hd21619 mem_cost (by rfl) (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, rd21620⟩ - -theorem uniswapV3PoolBurnPositionUpdateStoreTokensOwed1 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21620⟩ - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256)) :: - burnPositionKeyNewFreePtrWord :: burnPositionUpdateSlot0Mask :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem4 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 21) rdata (cA, σ) k C) - (hov : R.length + 30 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21635⟩ - (burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21559 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21801) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateDecodeEqTemplate hpatch hlo hhi - have hd21620 : - decode code ⟨21620⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21620⟩ (by native_decide) (by native_decide)] - native_decide - have hd21622 : - decode code ⟨21622⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21622⟩ (by native_decide) (by native_decide)] - native_decide - have hd21624 : decode code ⟨21624⟩ = some (.SHL, .none) := by - rw [hdec ⟨21624⟩ (by native_decide) (by native_decide)] - native_decide - have hd21625 : decode code ⟨21625⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨21625⟩ (by native_decide) (by native_decide)] - native_decide - have hd21626 : decode code ⟨21626⟩ = some (.DIV, .none) := by - rw [hdec ⟨21626⟩ (by native_decide) (by native_decide)] - native_decide - have hd21627 : decode code ⟨21627⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨21627⟩ (by native_decide) (by native_decide)] - native_decide - have hd21628 : decode code ⟨21628⟩ = some (.SWAP2, .none) := by - rw [hdec ⟨21628⟩ (by native_decide) (by native_decide)] - native_decide - have hd21629 : decode code ⟨21629⟩ = some (.AND, .none) := by - rw [hdec ⟨21629⟩ (by native_decide) (by native_decide)] - native_decide - have hd21630 : - decode code ⟨21630⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21630⟩ (by native_decide) (by native_decide)] - native_decide - have hd21632 : decode code ⟨21632⟩ = some (.DUP3, .none) := by - rw [hdec ⟨21632⟩ (by native_decide) (by native_decide)] - native_decide - have hd21633 : decode code ⟨21633⟩ = some (.ADD, .none) := by - rw [hdec ⟨21633⟩ (by native_decide) (by native_decide)] - native_decide - have hd21634 : decode code ⟨21634⟩ = some (.MSTORE, .none) := by - rw [hdec ⟨21634⟩ (by native_decide) (by native_decide)] - native_decide - have rd21634 := evm_run h with [ - raw push1 ⟨1⟩ hd21620 (by evm_ov), - raw push1 ⟨128⟩ hd21622 (by evm_ov), - raw shl hd21624 (by evm_ov), - raw swap1 hd21625 (by simp only [List.length_cons] at hov ⊢; omega), - raw div hd21626 (by evm_ov), - raw swap1 hd21627 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap2 hd21628 (by simp only [List.length_cons] at hov ⊢; omega), - raw and hd21629 (by evm_ov), - raw push1 ⟨128⟩ hd21630 (by evm_ov), - raw dup3 hd21632 (by simp only [List.length_cons] at hov ⊢; omega), - raw add hd21633 (by evm_ov)] - have rd21635 := by - simpa [burnPositionUpdateMem5, burnPositionUpdateTokensOwed1Packed] using - rd21634.mstore 3 - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) hd21634 mem_cost (by rfl) (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, rd21635⟩ - -theorem uniswapV3PoolBurnPositionUpdateLiquidityDeltaZeroFallthrough {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdelta : UInt256.signextend ⟨15⟩ delta = ⟨0⟩) - (h : RD code ee g s0 ⟨21635⟩ - (burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hov : R.length + 30 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21646⟩ - (⟨0⟩ :: burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: - posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: - posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21559 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21801) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateDecodeEqTemplate hpatch hlo hhi - have hd21635 : - decode code ⟨21635⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨21635⟩ (by native_decide) (by native_decide)] - native_decide - have hd21637 : - decode code ⟨21637⟩ = some (.Push .PUSH1, some (⟨15⟩, 1)) := by - rw [hdec ⟨21637⟩ (by native_decide) (by native_decide)] - native_decide - have hd21639 : decode code ⟨21639⟩ = some (.DUP6, .none) := by - rw [hdec ⟨21639⟩ (by native_decide) (by native_decide)] - native_decide - have hd21640 : decode code ⟨21640⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨21640⟩ (by native_decide) (by native_decide)] - native_decide - have hd21641 : decode code ⟨21641⟩ = some (.SIGNEXTEND, .none) := by - rw [hdec ⟨21641⟩ (by native_decide) (by native_decide)] - native_decide - have hd21642 : - decode code ⟨21642⟩ = some (.Push .PUSH2, some (⟨21718⟩, 2)) := by - rw [hdec ⟨21642⟩ (by native_decide) (by native_decide)] - native_decide - have hd21645 : decode code ⟨21645⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨21645⟩ (by native_decide) (by native_decide)] - native_decide - have rd21641 := evm_run h with [ - raw push1 ⟨0⟩ hd21635 (by evm_ov), - raw push1 ⟨15⟩ hd21637 (by evm_ov), - raw dup6 hd21639 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap1 hd21640 (by simp only [List.length_cons] at hov ⊢; omega)] - have rd21642 := by - simpa using burnRDSignextend rd21641 hd21641 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21645 := evm_run rd21642 with [ - raw push2 ⟨21718⟩ hd21642 (by evm_ov)] - have rd21646 := rd21645.jumpiNT hd21645 hdelta - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, rd21646⟩ - -theorem uniswapV3PoolBurnPositionUpdateLiquidityNonzeroJump {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hliquidity : burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) ≠ ⟨0⟩) - (h : RD code ee g s0 ⟨21646⟩ - (⟨0⟩ :: burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: - posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: - posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hov : R.length + 30 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21710⟩ - (⟨0⟩ :: burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: - posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: - posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21559 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21801) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateDecodeEqTemplate hpatch hlo hhi - have hd21646 : decode code ⟨21646⟩ = some (.DUP2, .none) := by - rw [hdec ⟨21646⟩ (by native_decide) (by native_decide)] - native_decide - have hd21647 : decode code ⟨21647⟩ = some (.MLOAD, .none) := by - rw [hdec ⟨21647⟩ (by native_decide) (by native_decide)] - native_decide - have hd21648 : - decode code ⟨21648⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21648⟩ (by native_decide) (by native_decide)] - native_decide - have hd21650 : - decode code ⟨21650⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21650⟩ (by native_decide) (by native_decide)] - native_decide - have hd21652 : - decode code ⟨21652⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21652⟩ (by native_decide) (by native_decide)] - native_decide - have hd21654 : decode code ⟨21654⟩ = some (.SHL, .none) := by - rw [hdec ⟨21654⟩ (by native_decide) (by native_decide)] - native_decide - have hd21655 : decode code ⟨21655⟩ = some (.SUB, .none) := by - rw [hdec ⟨21655⟩ (by native_decide) (by native_decide)] - native_decide - have hd21656 : decode code ⟨21656⟩ = some (.AND, .none) := by - rw [hdec ⟨21656⟩ (by native_decide) (by native_decide)] - native_decide - have hd21657 : - decode code ⟨21657⟩ = some (.Push .PUSH2, some (⟨21710⟩, 2)) := by - rw [hdec ⟨21657⟩ (by native_decide) (by native_decide)] - native_decide - have hd21660 : decode code ⟨21660⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨21660⟩ (by native_decide) (by native_decide)] - native_decide - have rd21647 := evm_run h with [ - raw dup2 hd21646 (by simp only [List.length_cons] at hov ⊢; omega)] - have rd21648 := by - simpa using - rd21647.mload 0 - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.ofNat 22) hd21647 mem_cost - (burnPositionUpdateMem5_mloadFreePtr σ ee (solcSlotWord σ ee posBase) posBase) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21660 := evm_run rd21648 with [ - raw push1 ⟨1⟩ hd21648 (by evm_ov), - raw push1 ⟨1⟩ hd21650 (by evm_ov), - raw push1 ⟨128⟩ hd21652 (by evm_ov), - raw shl hd21654 (by evm_ov), - raw sub hd21655 (by evm_ov), - raw and hd21656 (by evm_ov), - raw push2 ⟨21710⟩ hd21657 (by evm_ov)] - have hcond : - UInt256.land burnPositionUpdateSlot0Mask - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) ≠ ⟨0⟩ := by - rwa [burnPositionUpdateSlot0Packed_mask] - have rd21710 := by - simpa [burnPositionUpdateSlot0Mask] using - rd21660.jumpiT hd21660 hcond (uniswapV3PoolJumpDestPatched21710 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, rd21710⟩ - -theorem uniswapV3PoolBurnPositionUpdateLiquidityZeroFallthrough {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hliquidity : burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) = ⟨0⟩) - (h : RD code ee g s0 ⟨21646⟩ - (⟨0⟩ :: burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: - posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: - posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hov : R.length + 30 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21661⟩ - (⟨0⟩ :: burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: - posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: - posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21559 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21801) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateDecodeEqTemplate hpatch hlo hhi - have hd21646 : decode code ⟨21646⟩ = some (.DUP2, .none) := by - rw [hdec ⟨21646⟩ (by native_decide) (by native_decide)] - native_decide - have hd21647 : decode code ⟨21647⟩ = some (.MLOAD, .none) := by - rw [hdec ⟨21647⟩ (by native_decide) (by native_decide)] - native_decide - have hd21648 : - decode code ⟨21648⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21648⟩ (by native_decide) (by native_decide)] - native_decide - have hd21650 : - decode code ⟨21650⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21650⟩ (by native_decide) (by native_decide)] - native_decide - have hd21652 : - decode code ⟨21652⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21652⟩ (by native_decide) (by native_decide)] - native_decide - have hd21654 : decode code ⟨21654⟩ = some (.SHL, .none) := by - rw [hdec ⟨21654⟩ (by native_decide) (by native_decide)] - native_decide - have hd21655 : decode code ⟨21655⟩ = some (.SUB, .none) := by - rw [hdec ⟨21655⟩ (by native_decide) (by native_decide)] - native_decide - have hd21656 : decode code ⟨21656⟩ = some (.AND, .none) := by - rw [hdec ⟨21656⟩ (by native_decide) (by native_decide)] - native_decide - have hd21657 : - decode code ⟨21657⟩ = some (.Push .PUSH2, some (⟨21710⟩, 2)) := by - rw [hdec ⟨21657⟩ (by native_decide) (by native_decide)] - native_decide - have hd21660 : decode code ⟨21660⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨21660⟩ (by native_decide) (by native_decide)] - native_decide - have rd21647 := evm_run h with [ - raw dup2 hd21646 (by simp only [List.length_cons] at hov ⊢; omega)] - have rd21648 := by - simpa using - rd21647.mload 0 - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.ofNat 22) hd21647 mem_cost - (burnPositionUpdateMem5_mloadFreePtr σ ee (solcSlotWord σ ee posBase) posBase) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21660 := evm_run rd21648 with [ - raw push1 ⟨1⟩ hd21648 (by evm_ov), - raw push1 ⟨1⟩ hd21650 (by evm_ov), - raw push1 ⟨128⟩ hd21652 (by evm_ov), - raw shl hd21654 (by evm_ov), - raw sub hd21655 (by evm_ov), - raw and hd21656 (by evm_ov), - raw push2 ⟨21710⟩ hd21657 (by evm_ov)] - have hcond : - UInt256.land burnPositionUpdateSlot0Mask - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) = ⟨0⟩ := by - rw [burnPositionUpdateSlot0Packed_mask, hliquidity] - have rd21661 := by - simpa [burnPositionUpdateSlot0Mask] using - rd21660.jumpiNT hd21660 hcond - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, rd21661⟩ - -theorem uniswapV3PoolBurnPositionUpdateReloadLiquidity {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21710⟩ - (⟨0⟩ :: burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: - posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: - posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hov : R.length + 30 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21733⟩ - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21559 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21801) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateDecodeEqTemplate hpatch hlo hhi - have hd21710 : decode code ⟨21710⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨21710⟩ (by native_decide) (by native_decide)] - native_decide - have hd21711 : decode code ⟨21711⟩ = some (.POP, .none) := by - rw [hdec ⟨21711⟩ (by native_decide) (by native_decide)] - native_decide - have hd21712 : decode code ⟨21712⟩ = some (.DUP1, .none) := by - rw [hdec ⟨21712⟩ (by native_decide) (by native_decide)] - native_decide - have hd21713 : decode code ⟨21713⟩ = some (.MLOAD, .none) := by - rw [hdec ⟨21713⟩ (by native_decide) (by native_decide)] - native_decide - have hd21714 : - decode code ⟨21714⟩ = some (.Push .PUSH2, some (⟨21733⟩, 2)) := by - rw [hdec ⟨21714⟩ (by native_decide) (by native_decide)] - native_decide - have hd21717 : decode code ⟨21717⟩ = some (.JUMP, .none) := by - rw [hdec ⟨21717⟩ (by native_decide) (by native_decide)] - native_decide - have rd21713 := evm_run h with [ - raw jumpdest hd21710 (by evm_ov), - raw pop hd21711 (by simp only [List.length_cons] at hov ⊢; omega), - raw dup1 hd21712 (by simp only [List.length_cons] at hov ⊢; omega)] - have rd21714 := by - simpa using - rd21713.mload 0 - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.ofNat 22) hd21713 mem_cost - (burnPositionUpdateMem5_mloadFreePtr σ ee (solcSlotWord σ ee posBase) posBase) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21717 := evm_run rd21714 with [ - raw push2 ⟨21733⟩ hd21714 (by evm_ov)] - exact ⟨_, _, rd21717.jump hd21717 (uniswapV3PoolJumpDestPatched21733 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnPositionUpdateStartMulDiv0 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21733⟩ - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hov : R.length + 35 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))) :: - ⟨21769⟩ :: ⟨0⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21559 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21801) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateDecodeEqTemplate hpatch hlo hhi - have hd21733 : decode code ⟨21733⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨21733⟩ (by native_decide) (by native_decide)] - native_decide - have hd21734 : - decode code ⟨21734⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨21734⟩ (by native_decide) (by native_decide)] - native_decide - have hd21736 : - decode code ⟨21736⟩ = some (.Push .PUSH2, some (⟨21769⟩, 2)) := by - rw [hdec ⟨21736⟩ (by native_decide) (by native_decide)] - native_decide - have hd21739 : decode code ⟨21739⟩ = some (.DUP4, .none) := by - rw [hdec ⟨21739⟩ (by native_decide) (by native_decide)] - native_decide - have hd21740 : - decode code ⟨21740⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdec ⟨21740⟩ (by native_decide) (by native_decide)] - native_decide - have hd21742 : decode code ⟨21742⟩ = some (.ADD, .none) := by - rw [hdec ⟨21742⟩ (by native_decide) (by native_decide)] - native_decide - have hd21743 : decode code ⟨21743⟩ = some (.MLOAD, .none) := by - rw [hdec ⟨21743⟩ (by native_decide) (by native_decide)] - native_decide - have hd21744 : decode code ⟨21744⟩ = some (.DUP7, .none) := by - rw [hdec ⟨21744⟩ (by native_decide) (by native_decide)] - native_decide - have hd21745 : decode code ⟨21745⟩ = some (.SUB, .none) := by - rw [hdec ⟨21745⟩ (by native_decide) (by native_decide)] - native_decide - have hd21746 : decode code ⟨21746⟩ = some (.DUP5, .none) := by - rw [hdec ⟨21746⟩ (by native_decide) (by native_decide)] - native_decide - have hd21747 : - decode code ⟨21747⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨21747⟩ (by native_decide) (by native_decide)] - native_decide - have hd21749 : decode code ⟨21749⟩ = some (.ADD, .none) := by - rw [hdec ⟨21749⟩ (by native_decide) (by native_decide)] - native_decide - have hd21750 : decode code ⟨21750⟩ = some (.MLOAD, .none) := by - rw [hdec ⟨21750⟩ (by native_decide) (by native_decide)] - native_decide - have hd21751 : - decode code ⟨21751⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21751⟩ (by native_decide) (by native_decide)] - native_decide - have hd21753 : - decode code ⟨21753⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21753⟩ (by native_decide) (by native_decide)] - native_decide - have hd21755 : - decode code ⟨21755⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21755⟩ (by native_decide) (by native_decide)] - native_decide - have hd21757 : decode code ⟨21757⟩ = some (.SHL, .none) := by - rw [hdec ⟨21757⟩ (by native_decide) (by native_decide)] - native_decide - have hd21758 : decode code ⟨21758⟩ = some (.SUB, .none) := by - rw [hdec ⟨21758⟩ (by native_decide) (by native_decide)] - native_decide - have hd21759 : decode code ⟨21759⟩ = some (.AND, .none) := by - rw [hdec ⟨21759⟩ (by native_decide) (by native_decide)] - native_decide - have hd21760 : - decode code ⟨21760⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21760⟩ (by native_decide) (by native_decide)] - native_decide - have hd21762 : - decode code ⟨21762⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21762⟩ (by native_decide) (by native_decide)] - native_decide - have hd21764 : decode code ⟨21764⟩ = some (.SHL, .none) := by - rw [hdec ⟨21764⟩ (by native_decide) (by native_decide)] - native_decide - have hd21765 : - decode code ⟨21765⟩ = some (.Push .PUSH2, some (⟨13017⟩, 2)) := by - rw [hdec ⟨21765⟩ (by native_decide) (by native_decide)] - native_decide - have hd21768 : decode code ⟨21768⟩ = some (.JUMP, .none) := by - rw [hdec ⟨21768⟩ (by native_decide) (by native_decide)] - native_decide - have rd21743 := evm_run h with [ - raw jumpdest hd21733 (by evm_ov), - raw push1 ⟨0⟩ hd21734 (by evm_ov), - raw push2 ⟨21769⟩ hd21736 (by evm_ov), - raw dup4 hd21739 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨32⟩ hd21740 (by evm_ov), - raw add hd21742 (by evm_ov)] - have rd21744 := by - simpa using - rd21743.mload 0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))) - (UInt256.ofNat 22) hd21743 mem_cost - (burnPositionUpdateMem5_mloadFreePtrPlus32 σ ee (solcSlotWord σ ee posBase) - posBase) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21750 := evm_run rd21744 with [ - raw dup7 hd21744 (by simp only [List.length_cons] at hov ⊢; omega), - raw sub hd21745 (by evm_ov), - raw dup5 hd21746 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨0⟩ hd21747 (by evm_ov), - raw add hd21749 (by evm_ov)] - have rd21751 := by - simpa [show burnPositionKeyNewFreePtrWord + (⟨0⟩ : UInt256) = - burnPositionKeyNewFreePtrWord from by native_decide] using - rd21750.mload 0 - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.ofNat 22) hd21750 mem_cost - (burnPositionUpdateMem5_mloadFreePtr σ ee (solcSlotWord σ ee posBase) posBase) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21768 := evm_run rd21751 with [ - raw push1 ⟨1⟩ hd21751 (by evm_ov), - raw push1 ⟨1⟩ hd21753 (by evm_ov), - raw push1 ⟨128⟩ hd21755 (by evm_ov), - raw shl hd21757 (by evm_ov), - raw sub hd21758 (by evm_ov), - raw and hd21759 (by evm_ov), - raw push1 ⟨1⟩ hd21760 (by evm_ov), - raw push1 ⟨128⟩ hd21762 (by evm_ov), - raw shl hd21764 (by evm_ov), - raw push2 ⟨13017⟩ hd21765 (by evm_ov)] - have rd13017 := rd21768.jump hd21768 (uniswapV3PoolJumpDestPatched13017 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, by - simpa [burnPositionUpdateSlot0Mask, burnPositionUpdateSlot0Packed_mask] using rd13017⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateMemory.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateMemory.lean deleted file mode 100644 index 8fdafcbf..00000000 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateMemory.lean +++ /dev/null @@ -1,174 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdate - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem wordAt0Mem_read224_of_size_ge {mem : ByteArray} (word : UInt256) - (hmem : 256 ≤ mem.size) : - (wordAt0Mem word mem).readWithPadding 224 32 = mem.readWithPadding 224 32 := by - unfold wordAt0Mem - rw [write32_read_above _ _ 0 224 (by rw [toByteArray_size]) (by omega) (by omega) - (by omega)] - -theorem twoWordHashMem_read224_of_size_ge {mem : ByteArray} (key slot : UInt256) - (hmem : 256 ≤ mem.size) : - (twoWordHashMem key slot mem).readWithPadding 224 32 = - mem.readWithPadding 224 32 := by - unfold twoWordHashMem wordAt32Mem - rw [write32_read_above _ _ 32 224 (by rw [toByteArray_size]) - (by - rw [wordAt0Mem_size_of_size_ge] - · omega - · omega) - (by omega) - (by - rw [wordAt0Mem_size_of_size_ge] - · omega - · omega)] - exact wordAt0Mem_read224_of_size_ge key hmem - -private theorem burnPositionKeyMem2_read224_cascade - (σ : AccountMap) (I : ExecutionEnv) : - burnPositionKeyMem2 σ I = - writeCascade (burnModifyPositionSlot0Mem σ I) - [(512, burnPositionKeyOwnerPackedWord I), - (532, burnPositionKeyLowerPackedWord I), - (535, burnPositionKeyUpperPackedWord I)] := by - rfl - -theorem burnPositionKeyMem2_read224 (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMem2 σ I).readWithPadding 224 32 = - UInt256.toByteArray - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) := by - rw [burnPositionKeyMem2_read224_cascade] - rw [writeCascade_read_preserved_of_base (burnModifyPositionSlot0Mem σ I) - [(512, burnPositionKeyOwnerPackedWord I), - (532, burnPositionKeyLowerPackedWord I), - (535, burnPositionKeyUpperPackedWord I)] (base := 480) (read := 224) - (burnModifyPositionSlot0Mem_size σ I) - (by - simp [WindowDisjointFromWrites] - native_decide)] - exact burnModifyPositionSlot0Mem_read224 σ I - -theorem burnPositionKeyMem3_read224 (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMem3 σ I).readWithPadding 224 32 = - UInt256.toByteArray - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) := by - unfold burnPositionKeyMem3 - rw [writeWord_read_preserved (burnPositionKeyMem2 σ I) 480 224 - burnPositionKeyPackedLengthWord - (by rw [burnPositionKeyMem2_size σ I]; native_decide) - (by rw [burnPositionKeyMem2_size σ I]; omega)] - exact burnPositionKeyMem2_read224 σ I - -theorem burnPositionKeyPackedHashMem_read224 (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyPackedHashMem σ I).readWithPadding 224 32 = - UInt256.toByteArray - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) := by - unfold burnPositionKeyPackedHashMem - rw [writeWord_read_preserved (burnPositionKeyMem3 σ I) 64 224 - burnPositionKeyNewFreePtrWord - (by rw [burnPositionKeyMem3_size σ I]; native_decide) - (by rw [burnPositionKeyMem3_size σ I]; omega)] - exact burnPositionKeyMem3_read224 σ I - -theorem burnPositionKeyMappingMem_read224 (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMappingMem σ I).readWithPadding 224 32 = - UInt256.toByteArray - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) := by - unfold burnPositionKeyMappingMem - rw [twoWordHashMem_read224_of_size_ge] - · exact burnPositionKeyPackedHashMem_read224 σ I - · rw [burnPositionKeyPackedHashMem_size σ I] - omega - -theorem burnTickLowerFeeGrowthMem_read224 (σ : AccountMap) (I : ExecutionEnv) : - (burnTickLowerFeeGrowthMem σ I).readWithPadding 224 32 = - UInt256.toByteArray - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) := by - unfold burnTickLowerFeeGrowthMem - rw [twoWordHashMem_read224_of_size_ge] - · exact burnPositionKeyMappingMem_read224 σ I - · rw [burnPositionKeyMappingMem_size σ I] - omega - -theorem burnTickUpperFeeGrowthMem_read224 (σ : AccountMap) (I : ExecutionEnv) : - (burnTickUpperFeeGrowthMem σ I).readWithPadding 224 32 = - UInt256.toByteArray - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) := by - unfold burnTickUpperFeeGrowthMem - rw [wordAt0Mem_read224_of_size_ge] - · exact burnTickLowerFeeGrowthMem_read224 σ I - · rw [burnTickLowerFeeGrowthMem_size σ I] - omega - -theorem burnPositionUpdateMem5_read224 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding 224 32 = - UInt256.toByteArray - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) := by - unfold burnPositionUpdateMem5 - rw [writeWord_read_preserved - (burnPositionUpdateMem4 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)).toNat 224 - (burnPositionUpdateTokensOwed1Packed - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem4_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem4 - rw [writeWord_read_preserved - (burnPositionUpdateMem3 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat 224 - (UInt256.land burnPositionUpdateSlot0Mask - (solcSlotWord σ I (posBase + (⟨3⟩ : UInt256)))) - (by rw [burnPositionUpdateMem3_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem3_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem3 - rw [writeWord_read_preserved - (burnPositionUpdateMem2 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat 224 - (solcSlotWord σ I (posBase + (⟨2⟩ : UInt256))) - (by rw [burnPositionUpdateMem2_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem2_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateMem2 - rw [writeWord_read_preserved - (burnPositionUpdateMem1 σ I pos0) - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat 224 - (solcSlotWord σ I (posBase + (⟨1⟩ : UInt256))) - (by rw [burnPositionUpdateMem1_size σ I pos0]; native_decide) - (by rw [burnPositionUpdateMem1_size σ I pos0]; native_decide)] - unfold burnPositionUpdateMem1 - rw [writeWord_read_preserved (burnPositionUpdateMem0 σ I) - burnPositionKeyNewFreePtrWord.toNat 224 (burnPositionUpdateSlot0Packed pos0) - (by rw [burnPositionUpdateMem0_size σ I]; native_decide) - (by rw [burnPositionUpdateMem0_size σ I]; native_decide)] - unfold burnPositionUpdateMem0 - rw [writeWord_read_preserved (burnTickUpperFeeGrowthMem σ I) 64 224 - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) - (by rw [burnTickUpperFeeGrowthMem_size σ I]; native_decide) - (by rw [burnTickUpperFeeGrowthMem_size σ I]; native_decide)] - exact burnTickUpperFeeGrowthMem_read224 σ I - -theorem burnPositionUpdateMem5_mload224 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (if (⟨224⟩ : UInt256).toNat ≥ (burnPositionUpdateMem5 σ I pos0 posBase).size - ∨ (⟨224⟩ : UInt256) ≥ UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPositionUpdateMem5 σ I pos0 posBase).readWithPadding - (⟨224⟩ : UInt256).toNat 32))) = - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) := by - exact mloadWordValue_of_readWithPadding - (mem := burnPositionUpdateMem5 σ I pos0 posBase) (aw := UInt256.ofNat 22) - (off := ⟨224⟩) - (v := UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (by rw [burnPositionUpdateMem5_size σ I pos0 posBase]; native_decide) - (by native_decide) - (by - simpa [show (⟨224⟩ : UInt256).toNat = 224 from by decide] - using burnPositionUpdateMem5_read224 σ I pos0 posBase) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdatePostReturn.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdatePostReturn.lean deleted file mode 100644 index d72a410f..00000000 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdatePostReturn.lean +++ /dev/null @@ -1,1900 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdateMemory -import Benchmarks.UniswapV3Pool.BurnFullMathSlow - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem uniswapV3PoolBurnPositionUpdatePostReturnDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 21769 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21846) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 21846 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -private theorem uniswapV3PoolPatchPreservesJumpDest21769 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨21769⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest21807 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨21807⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest21846 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨21846⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest21892 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨21892⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest21954 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨21954⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest19527 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨19527⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest19573 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨19573⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest16428 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16428⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest16801 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16801⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest9737 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨9737⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched21769 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨21769⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest21769 - -theorem uniswapV3PoolJumpDestPatched21807 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨21807⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest21807 - -theorem uniswapV3PoolJumpDestPatched21846 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨21846⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest21846 - -theorem uniswapV3PoolJumpDestPatched21892 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨21892⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest21892 - -theorem uniswapV3PoolJumpDestPatched21954 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨21954⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest21954 - -theorem uniswapV3PoolJumpDestPatched19527 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨19527⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest19527 - -theorem uniswapV3PoolJumpDestPatched19573 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨19573⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest19573 - -theorem uniswapV3PoolJumpDestPatched16428 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16428⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest16428 - -theorem uniswapV3PoolJumpDestPatched16801 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16801⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest16801 - -theorem uniswapV3PoolJumpDestPatched9737 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨9737⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest9737 - -private theorem uniswapV3PoolBurnPositionUpdateSkipLiquidityDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 21807 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21986) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 21986 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -private theorem uniswapV3PoolBurnPositionUpdateReturnDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 21954 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21996) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 21996 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -private theorem uniswapV3PoolBurnModifyPositionPostPositionUpdateDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 19527 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19620) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 19620 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -private theorem uniswapV3PoolBurnModifyPositionReturnToCallerDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 16428 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 16841) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 16841 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -abbrev burnPositionUpdateTokensOwed0AddedSlot3 - (pos3 tokensOwed0 : UInt256) : UInt256 := - UInt256.lor - (UInt256.land burnPositionUpdateSlot0Mask - (tokensOwed0 + UInt256.land burnPositionUpdateSlot0Mask pos3)) - (UInt256.land pos3 (UInt256.lnot burnPositionUpdateSlot0Mask)) - -abbrev burnPositionUpdateTokensOwedAddedSlot3 - (pos3 tokensOwed0 tokensOwed1 : UInt256) : UInt256 := - UInt256.lor - (UInt256.mul - (UInt256.land burnPositionUpdateSlot0Mask - (tokensOwed1 + UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div (burnPositionUpdateTokensOwed0AddedSlot3 pos3 tokensOwed0) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (UInt256.land burnPositionUpdateSlot0Mask - (burnPositionUpdateTokensOwed0AddedSlot3 pos3 tokensOwed0)) - -theorem uniswapV3PoolBurnPositionUpdateStartMulDiv1 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed0 z liquidity inside1 inside0 delta posBase retPos inside1' inside0' - z2 z3 fee1 fee0 posBase' tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21769⟩ - (tokensOwed0 :: z :: liquidity :: burnPositionKeyNewFreePtrWord :: inside1 :: - inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: - fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: - free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hov : R.length + 40 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256))) :: - ⟨21807⟩ :: ⟨0⟩ :: tokensOwed0 :: liquidity :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21769 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21846) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdatePostReturnDecodeEqTemplate hpatch hlo hhi - have hd21769 : decode code ⟨21769⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨21769⟩ (by native_decide) (by native_decide)] - native_decide - have hd21770 : decode code ⟨21770⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨21770⟩ (by native_decide) (by native_decide)] - native_decide - have hd21771 : decode code ⟨21771⟩ = some (.POP, .none) := by - rw [hdec ⟨21771⟩ (by native_decide) (by native_decide)] - native_decide - have hd21772 : - decode code ⟨21772⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨21772⟩ (by native_decide) (by native_decide)] - native_decide - have hd21774 : - decode code ⟨21774⟩ = some (.Push .PUSH2, some (⟨21807⟩, 2)) := by - rw [hdec ⟨21774⟩ (by native_decide) (by native_decide)] - native_decide - have hd21777 : decode code ⟨21777⟩ = some (.DUP5, .none) := by - rw [hdec ⟨21777⟩ (by native_decide) (by native_decide)] - native_decide - have hd21778 : - decode code ⟨21778⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [hdec ⟨21778⟩ (by native_decide) (by native_decide)] - native_decide - have hd21780 : decode code ⟨21780⟩ = some (.ADD, .none) := by - rw [hdec ⟨21780⟩ (by native_decide) (by native_decide)] - native_decide - have hd21781 : decode code ⟨21781⟩ = some (.MLOAD, .none) := by - rw [hdec ⟨21781⟩ (by native_decide) (by native_decide)] - native_decide - have hd21782 : decode code ⟨21782⟩ = some (.DUP7, .none) := by - rw [hdec ⟨21782⟩ (by native_decide) (by native_decide)] - native_decide - have hd21783 : decode code ⟨21783⟩ = some (.SUB, .none) := by - rw [hdec ⟨21783⟩ (by native_decide) (by native_decide)] - native_decide - have hd21784 : decode code ⟨21784⟩ = some (.DUP6, .none) := by - rw [hdec ⟨21784⟩ (by native_decide) (by native_decide)] - native_decide - have hd21785 : - decode code ⟨21785⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨21785⟩ (by native_decide) (by native_decide)] - native_decide - have hd21787 : decode code ⟨21787⟩ = some (.ADD, .none) := by - rw [hdec ⟨21787⟩ (by native_decide) (by native_decide)] - native_decide - have hd21788 : decode code ⟨21788⟩ = some (.MLOAD, .none) := by - rw [hdec ⟨21788⟩ (by native_decide) (by native_decide)] - native_decide - have hd21789 : - decode code ⟨21789⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21789⟩ (by native_decide) (by native_decide)] - native_decide - have hd21791 : - decode code ⟨21791⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21791⟩ (by native_decide) (by native_decide)] - native_decide - have hd21793 : - decode code ⟨21793⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21793⟩ (by native_decide) (by native_decide)] - native_decide - have hd21795 : decode code ⟨21795⟩ = some (.SHL, .none) := by - rw [hdec ⟨21795⟩ (by native_decide) (by native_decide)] - native_decide - have hd21796 : decode code ⟨21796⟩ = some (.SUB, .none) := by - rw [hdec ⟨21796⟩ (by native_decide) (by native_decide)] - native_decide - have hd21797 : decode code ⟨21797⟩ = some (.AND, .none) := by - rw [hdec ⟨21797⟩ (by native_decide) (by native_decide)] - native_decide - have hd21798 : - decode code ⟨21798⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21798⟩ (by native_decide) (by native_decide)] - native_decide - have hd21800 : - decode code ⟨21800⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21800⟩ (by native_decide) (by native_decide)] - native_decide - have hd21802 : decode code ⟨21802⟩ = some (.SHL, .none) := by - rw [hdec ⟨21802⟩ (by native_decide) (by native_decide)] - native_decide - have hd21803 : - decode code ⟨21803⟩ = some (.Push .PUSH2, some (⟨13017⟩, 2)) := by - rw [hdec ⟨21803⟩ (by native_decide) (by native_decide)] - native_decide - have hd21806 : decode code ⟨21806⟩ = some (.JUMP, .none) := by - rw [hdec ⟨21806⟩ (by native_decide) (by native_decide)] - native_decide - have rd21781 := evm_run h with [ - raw jumpdest hd21769 (by evm_ov), - raw swap1 hd21770 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd21771 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨0⟩ hd21772 (by evm_ov), - raw push2 ⟨21807⟩ hd21774 (by evm_ov), - raw dup5 hd21777 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨64⟩ hd21778 (by evm_ov), - raw add hd21780 (by evm_ov)] - have rd21782 := by - simpa using - rd21781.mload 0 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256))) - (UInt256.ofNat 22) hd21781 mem_cost - (burnPositionUpdateMem5_mloadFreePtrPlus64 σ ee (solcSlotWord σ ee posBase) - posBase) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21788 := evm_run rd21782 with [ - raw dup7 hd21782 (by simp only [List.length_cons] at hov ⊢; omega), - raw sub hd21783 (by evm_ov), - raw dup6 hd21784 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨0⟩ hd21785 (by evm_ov), - raw add hd21787 (by evm_ov)] - have rd21789 := by - simpa [show burnPositionKeyNewFreePtrWord + (⟨0⟩ : UInt256) = - burnPositionKeyNewFreePtrWord from by native_decide] using - rd21788.mload 0 - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.ofNat 22) hd21788 mem_cost - (burnPositionUpdateMem5_mloadFreePtr σ ee (solcSlotWord σ ee posBase) posBase) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21806 := evm_run rd21789 with [ - raw push1 ⟨1⟩ hd21789 (by evm_ov), - raw push1 ⟨1⟩ hd21791 (by evm_ov), - raw push1 ⟨128⟩ hd21793 (by evm_ov), - raw shl hd21795 (by evm_ov), - raw sub hd21796 (by evm_ov), - raw and hd21797 (by evm_ov), - raw push1 ⟨1⟩ hd21798 (by evm_ov), - raw push1 ⟨128⟩ hd21800 (by evm_ov), - raw shl hd21802 (by evm_ov), - raw push2 ⟨13017⟩ hd21803 (by evm_ov)] - have rd13017 := rd21806.jump hd21806 (uniswapV3PoolJumpDestPatched13017 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, by - simpa [burnPositionUpdateSlot0Mask, burnPositionUpdateSlot0Packed_mask] using rd13017⟩ - -theorem uniswapV3PoolBurnPositionUpdateMulDiv0Prod1ZeroStartMulDiv1 - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))) :: - ⟨21769⟩ :: ⟨0⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hprod1 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) = ⟨0⟩) - (hov : R.length + 45 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256))) :: - ⟨21807⟩ :: ⟨0⟩ :: - UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - obtain ⟨_, _, hrd13044⟩ := - uniswapV3PoolFullMathMulDivStartProduct - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (mem := burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (aw := UInt256.ofNat 22) (rdata := rdata) (acc := (cA, σ)) - (den := UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (b := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (a := UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (ret := ⟨21769⟩) (z := ⟨0⟩) - (R := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - hpatch h (by simp only [List.length_cons] at hov ⊢; omega) - have hden : - UInt256.gt (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨0⟩ ≠ ⟨0⟩ := by - native_decide - obtain ⟨_, _, hrd21769⟩ := - uniswapV3PoolFullMathMulDivProd1ZeroReturn - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (mem := burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (aw := UInt256.ofNat 22) (rdata := rdata) (acc := (cA, σ)) - (prod1 := uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (prod0 := uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (den := UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (b := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (a := UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (ret := ⟨21769⟩) (z := ⟨0⟩) - (R := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - hpatch hrd13044 hprod1 hden (uniswapV3PoolJumpDestPatched21769 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - exact uniswapV3PoolBurnPositionUpdateStartMulDiv1 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed0 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (z := ⟨0⟩) - (liquidity := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrd21769 (by omega) - -theorem uniswapV3PoolBurnPositionUpdateDeltaZeroSkipLiquidityWrite {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 z tokensOwed0 liquidity inside1 inside0 delta posBase retPos inside1' - inside0' z2 z3 fee1 fee0 posBase' tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdelta : UInt256.signextend ⟨15⟩ delta = ⟨0⟩) - (h : RD code ee g s0 ⟨21807⟩ - (tokensOwed1 :: z :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hov : R.length + 35 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21846⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21807 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21900) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateSkipLiquidityDecodeEqTemplate hpatch hlo (by omega) - have hd21807 : decode code ⟨21807⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨21807⟩ (by native_decide) (by native_decide)] - native_decide - have hd21808 : decode code ⟨21808⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨21808⟩ (by native_decide) (by native_decide)] - native_decide - have hd21809 : decode code ⟨21809⟩ = some (.POP, .none) := by - rw [hdec ⟨21809⟩ (by native_decide) (by native_decide)] - native_decide - have hd21810 : decode code ⟨21810⟩ = some (.DUP7, .none) := by - rw [hdec ⟨21810⟩ (by native_decide) (by native_decide)] - native_decide - have hd21811 : - decode code ⟨21811⟩ = some (.Push .PUSH1, some (⟨15⟩, 1)) := by - rw [hdec ⟨21811⟩ (by native_decide) (by native_decide)] - native_decide - have hd21813 : decode code ⟨21813⟩ = some (.SIGNEXTEND, .none) := by - rw [hdec ⟨21813⟩ (by native_decide) (by native_decide)] - native_decide - have hd21814 : - decode code ⟨21814⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨21814⟩ (by native_decide) (by native_decide)] - native_decide - have hd21816 : decode code ⟨21816⟩ = some (.EQ, .none) := by - rw [hdec ⟨21816⟩ (by native_decide) (by native_decide)] - native_decide - have hd21817 : - decode code ⟨21817⟩ = some (.Push .PUSH2, some (⟨21846⟩, 2)) := by - rw [hdec ⟨21817⟩ (by native_decide) (by native_decide)] - native_decide - have hd21820 : decode code ⟨21820⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨21820⟩ (by native_decide) (by native_decide)] - native_decide - have rd21813 := evm_run h with [ - raw jumpdest hd21807 (by evm_ov), - raw swap1 hd21808 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd21809 (by simp only [List.length_cons] at hov ⊢; omega), - raw dup7 hd21810 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨15⟩ hd21811 (by evm_ov)] - have rd21814 := by - simpa using burnRDSignextend rd21813 hd21813 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21820 := evm_run rd21814 with [ - raw push1 ⟨0⟩ hd21814 (by evm_ov), - raw eq hd21816 (by evm_ov), - raw push2 ⟨21846⟩ hd21817 (by evm_ov)] - have rd21846 := rd21820.jumpiT hd21820 - (by rw [hdelta]; native_decide) - (uniswapV3PoolJumpDestPatched21846 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, rd21846⟩ - -theorem uniswapV3PoolBurnPositionUpdateMulDiv1Prod1ZeroSkipLiquidityWrite - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {tokensOwed0 liquidity inside1 inside0 delta posBase retPos inside1' inside0' - z2 z3 fee1 fee0 posBase' tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: liquidity :: - UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256))) :: - ⟨21807⟩ :: ⟨0⟩ :: tokensOwed0 :: liquidity :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hprod1 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - liquidity = ⟨0⟩) - (hdelta : UInt256.signextend ⟨15⟩ delta = ⟨0⟩) - (hov : R.length + 45 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21846⟩ - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - liquidity) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) :: - tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - obtain ⟨_, _, hrd13044⟩ := - uniswapV3PoolFullMathMulDivStartProduct - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (mem := burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (aw := UInt256.ofNat 22) (rdata := rdata) (acc := (cA, σ)) - (den := UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (b := liquidity) - (a := UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (ret := ⟨21807⟩) (z := ⟨0⟩) - (R := tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - hpatch h (by simp only [List.length_cons] at hov ⊢; omega) - have hden : - UInt256.gt (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨0⟩ ≠ ⟨0⟩ := by - native_decide - obtain ⟨_, _, hrd21807⟩ := - uniswapV3PoolFullMathMulDivProd1ZeroReturn - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (mem := burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (aw := UInt256.ofNat 22) (rdata := rdata) (acc := (cA, σ)) - (prod1 := uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - liquidity) - (prod0 := uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - liquidity) - (den := UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (b := liquidity) - (a := UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (ret := ⟨21807⟩) (z := ⟨0⟩) - (R := tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - hpatch hrd13044 hprod1 hden (uniswapV3PoolJumpDestPatched21807 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - exact uniswapV3PoolBurnPositionUpdateDeltaZeroSkipLiquidityWrite - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - liquidity) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (z := ⟨0⟩) (tokensOwed0 := tokensOwed0) (liquidity := liquidity) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hdelta hrd21807 (by omega) - -theorem uniswapV3PoolBurnPositionUpdateMulDivsProd1ZeroSkipLiquidityWrite - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))) :: - ⟨21769⟩ :: ⟨0⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hprod0 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) = ⟨0⟩) - (hprod1 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) = ⟨0⟩) - (hdelta : UInt256.signextend ⟨15⟩ delta = ⟨0⟩) - (hov : R.length + 45 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21846⟩ - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) :: - UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - obtain ⟨_, _, hrdSecond13017⟩ := - uniswapV3PoolBurnPositionUpdateMulDiv0Prod1ZeroStartMulDiv1 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch h hprod0 (by omega) - exact uniswapV3PoolBurnPositionUpdateMulDiv1Prod1ZeroSkipLiquidityWrite - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed0 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (liquidity := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdSecond13017 hprod1 hdelta (by omega) - -theorem uniswapV3PoolBurnPositionUpdateStoreFeeGrowthLastAfterSkip {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity inside1 inside0 delta posBase retPos inside1' - inside0' z2 z3 fee1 fee0 posBase' tick delta' upper lower owner ret : UInt256} - {free : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hperm : ee.perm = true) - (h : RD code ee g s0 ⟨21846⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hov : R.length + 35 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata - (cA, sstoreAccountMap ee.codeOwner - (sstoreAccountMap ee.codeOwner σ (posBase + (⟨1⟩ : UInt256)) inside0) - (posBase + (⟨2⟩ : UInt256)) inside1) k' C' := by - have hdec (pc : UInt256) - (hlo : 21807 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21900) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateSkipLiquidityDecodeEqTemplate hpatch hlo (by omega) - have hd21846 : decode code ⟨21846⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨21846⟩ (by native_decide) (by native_decide)] - native_decide - have hd21847 : - decode code ⟨21847⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21847⟩ (by native_decide) (by native_decide)] - native_decide - have hd21849 : decode code ⟨21849⟩ = some (.DUP9, .none) := by - rw [hdec ⟨21849⟩ (by native_decide) (by native_decide)] - native_decide - have hd21850 : decode code ⟨21850⟩ = some (.ADD, .none) := by - rw [hdec ⟨21850⟩ (by native_decide) (by native_decide)] - native_decide - have hd21851 : decode code ⟨21851⟩ = some (.DUP7, .none) := by - rw [hdec ⟨21851⟩ (by native_decide) (by native_decide)] - native_decide - have hd21852 : decode code ⟨21852⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨21852⟩ (by native_decide) (by native_decide)] - native_decide - have hd21853 : decode code ⟨21853⟩ = some (.SSTORE, .none) := by - rw [hdec ⟨21853⟩ (by native_decide) (by native_decide)] - native_decide - have hd21854 : - decode code ⟨21854⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdec ⟨21854⟩ (by native_decide) (by native_decide)] - native_decide - have hd21856 : decode code ⟨21856⟩ = some (.DUP9, .none) := by - rw [hdec ⟨21856⟩ (by native_decide) (by native_decide)] - native_decide - have hd21857 : decode code ⟨21857⟩ = some (.ADD, .none) := by - rw [hdec ⟨21857⟩ (by native_decide) (by native_decide)] - native_decide - have hd21858 : decode code ⟨21858⟩ = some (.DUP6, .none) := by - rw [hdec ⟨21858⟩ (by native_decide) (by native_decide)] - native_decide - have hd21859 : decode code ⟨21859⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨21859⟩ (by native_decide) (by native_decide)] - native_decide - have hd21860 : decode code ⟨21860⟩ = some (.SSTORE, .none) := by - rw [hdec ⟨21860⟩ (by native_decide) (by native_decide)] - native_decide - have rd21853 := evm_run h with [ - raw jumpdest hd21846 (by evm_ov), - raw push1 ⟨1⟩ hd21847 (by evm_ov), - raw dup9 hd21849 (by simp only [List.length_cons] at hov ⊢; omega), - raw add hd21850 (by evm_ov), - raw dup7 hd21851 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap1 hd21852 (by simp only [List.length_cons] at hov ⊢; omega)] - obtain ⟨_, _, rd21854⟩ := rd21853.sstore hperm hd21853 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21860 := evm_run rd21854 with [ - raw push1 ⟨2⟩ hd21854 (by evm_ov), - raw dup9 hd21856 (by simp only [List.length_cons] at hov ⊢; omega), - raw add hd21857 (by evm_ov), - raw dup6 hd21858 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap1 hd21859 (by simp only [List.length_cons] at hov ⊢; omega)] - obtain ⟨_, _, rd21861⟩ := rd21860.sstore hperm hd21860 - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, rd21861⟩ - -theorem uniswapV3PoolBurnPositionUpdateMulDivsProd1ZeroStoreFeeGrowthLast - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hperm : ee.perm = true) - (h : RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))) :: - ⟨21769⟩ :: ⟨0⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hprod0 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) = ⟨0⟩) - (hprod1 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) = ⟨0⟩) - (hdelta : UInt256.signextend ⟨15⟩ delta = ⟨0⟩) - (hov : R.length + 45 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21861⟩ - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) :: - UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata - (cA, sstoreAccountMap ee.codeOwner - (sstoreAccountMap ee.codeOwner σ (posBase + (⟨1⟩ : UInt256)) inside0) - (posBase + (⟨2⟩ : UInt256)) inside1) k' C' := by - obtain ⟨_, _, hrd21846⟩ := - uniswapV3PoolBurnPositionUpdateMulDivsProd1ZeroSkipLiquidityWrite - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch h hprod0 hprod1 hdelta hov - exact uniswapV3PoolBurnPositionUpdateStoreFeeGrowthLastAfterSkip - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (tokensOwed0 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (liquidity := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hperm hrd21846 (by omega) - -theorem uniswapV3PoolBurnPositionUpdateStoreTokensOwedSlot3 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity freePtr inside1 inside0 delta posBase retPos - inside1' inside0' z2 z3 fee1 fee0 posBase' tick delta' upper lower owner ret - free : UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hperm : ee.perm = true) - (h : RD code ee g s0 ⟨21898⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: freePtr :: inside1 :: inside0 :: - delta :: posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: - fee0 :: posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: - free :: R) - mem aw rdata (cA, σ) k C) - (hov : R.length + 35 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21954⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: freePtr :: inside1 :: inside0 :: - delta :: posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: - fee0 :: posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: - free :: R) - mem aw rdata - (cA, sstoreAccountMap ee.codeOwner σ (posBase + (⟨3⟩ : UInt256)) - (burnPositionUpdateTokensOwedAddedSlot3 - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256))) tokensOwed0 tokensOwed1)) - k' C' := by - have hdec (pc : UInt256) - (hlo : 21807 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21986) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateSkipLiquidityDecodeEqTemplate hpatch hlo hhi - have hd21898 : - decode code ⟨21898⟩ = some (.Push .PUSH1, some (⟨3⟩, 1)) := by - rw [hdec ⟨21898⟩ (by native_decide) (by native_decide)] - native_decide - have hd21900 : decode code ⟨21900⟩ = some (.DUP9, .none) := by - rw [hdec ⟨21900⟩ (by native_decide) (by native_decide)] - native_decide - have hd21901 : decode code ⟨21901⟩ = some (.ADD, .none) := by - rw [hdec ⟨21901⟩ (by native_decide) (by native_decide)] - native_decide - have hd21902 : decode code ⟨21902⟩ = some (.DUP1, .none) := by - rw [hdec ⟨21902⟩ (by native_decide) (by native_decide)] - native_decide - have hd21903 : decode code ⟨21903⟩ = some (.SLOAD, .none) := by - rw [hdec ⟨21903⟩ (by native_decide) (by native_decide)] - native_decide - have hd21904 : - decode code ⟨21904⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21904⟩ (by native_decide) (by native_decide)] - native_decide - have hd21906 : - decode code ⟨21906⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21906⟩ (by native_decide) (by native_decide)] - native_decide - have hd21908 : - decode code ⟨21908⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21908⟩ (by native_decide) (by native_decide)] - native_decide - have hd21910 : decode code ⟨21910⟩ = some (.SHL, .none) := by - rw [hdec ⟨21910⟩ (by native_decide) (by native_decide)] - native_decide - have hd21911 : decode code ⟨21911⟩ = some (.SUB, .none) := by - rw [hdec ⟨21911⟩ (by native_decide) (by native_decide)] - native_decide - have hd21912 : decode code ⟨21912⟩ = some (.NOT, .none) := by - rw [hdec ⟨21912⟩ (by native_decide) (by native_decide)] - native_decide - have hd21913 : decode code ⟨21913⟩ = some (.DUP2, .none) := by - rw [hdec ⟨21913⟩ (by native_decide) (by native_decide)] - native_decide - have hd21914 : decode code ⟨21914⟩ = some (.AND, .none) := by - rw [hdec ⟨21914⟩ (by native_decide) (by native_decide)] - native_decide - have hd21915 : - decode code ⟨21915⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21915⟩ (by native_decide) (by native_decide)] - native_decide - have hd21917 : - decode code ⟨21917⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21917⟩ (by native_decide) (by native_decide)] - native_decide - have hd21919 : - decode code ⟨21919⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21919⟩ (by native_decide) (by native_decide)] - native_decide - have hd21921 : decode code ⟨21921⟩ = some (.SHL, .none) := by - rw [hdec ⟨21921⟩ (by native_decide) (by native_decide)] - native_decide - have hd21922 : decode code ⟨21922⟩ = some (.SUB, .none) := by - rw [hdec ⟨21922⟩ (by native_decide) (by native_decide)] - native_decide - have hd21923 : decode code ⟨21923⟩ = some (.SWAP2, .none) := by - rw [hdec ⟨21923⟩ (by native_decide) (by native_decide)] - native_decide - have hd21924 : decode code ⟨21924⟩ = some (.DUP3, .none) := by - rw [hdec ⟨21924⟩ (by native_decide) (by native_decide)] - native_decide - have hd21925 : decode code ⟨21925⟩ = some (.AND, .none) := by - rw [hdec ⟨21925⟩ (by native_decide) (by native_decide)] - native_decide - have hd21926 : decode code ⟨21926⟩ = some (.DUP6, .none) := by - rw [hdec ⟨21926⟩ (by native_decide) (by native_decide)] - native_decide - have hd21927 : decode code ⟨21927⟩ = some (.ADD, .none) := by - rw [hdec ⟨21927⟩ (by native_decide) (by native_decide)] - native_decide - have hd21928 : decode code ⟨21928⟩ = some (.DUP3, .none) := by - rw [hdec ⟨21928⟩ (by native_decide) (by native_decide)] - native_decide - have hd21929 : decode code ⟨21929⟩ = some (.AND, .none) := by - rw [hdec ⟨21929⟩ (by native_decide) (by native_decide)] - native_decide - have hd21930 : decode code ⟨21930⟩ = some (.OR, .none) := by - rw [hdec ⟨21930⟩ (by native_decide) (by native_decide)] - native_decide - have hd21931 : decode code ⟨21931⟩ = some (.DUP1, .none) := by - rw [hdec ⟨21931⟩ (by native_decide) (by native_decide)] - native_decide - have hd21932 : decode code ⟨21932⟩ = some (.DUP3, .none) := by - rw [hdec ⟨21932⟩ (by native_decide) (by native_decide)] - native_decide - have hd21933 : decode code ⟨21933⟩ = some (.AND, .none) := by - rw [hdec ⟨21933⟩ (by native_decide) (by native_decide)] - native_decide - have hd21934 : - decode code ⟨21934⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21934⟩ (by native_decide) (by native_decide)] - native_decide - have hd21936 : - decode code ⟨21936⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21936⟩ (by native_decide) (by native_decide)] - native_decide - have hd21938 : decode code ⟨21938⟩ = some (.SHL, .none) := by - rw [hdec ⟨21938⟩ (by native_decide) (by native_decide)] - native_decide - have hd21939 : decode code ⟨21939⟩ = some (.SWAP2, .none) := by - rw [hdec ⟨21939⟩ (by native_decide) (by native_decide)] - native_decide - have hd21940 : decode code ⟨21940⟩ = some (.DUP3, .none) := by - rw [hdec ⟨21940⟩ (by native_decide) (by native_decide)] - native_decide - have hd21941 : decode code ⟨21941⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨21941⟩ (by native_decide) (by native_decide)] - native_decide - have hd21942 : decode code ⟨21942⟩ = some (.DIV, .none) := by - rw [hdec ⟨21942⟩ (by native_decide) (by native_decide)] - native_decide - have hd21943 : decode code ⟨21943⟩ = some (.DUP4, .none) := by - rw [hdec ⟨21943⟩ (by native_decide) (by native_decide)] - native_decide - have hd21944 : decode code ⟨21944⟩ = some (.AND, .none) := by - rw [hdec ⟨21944⟩ (by native_decide) (by native_decide)] - native_decide - have hd21945 : decode code ⟨21945⟩ = some (.DUP6, .none) := by - rw [hdec ⟨21945⟩ (by native_decide) (by native_decide)] - native_decide - have hd21946 : decode code ⟨21946⟩ = some (.ADD, .none) := by - rw [hdec ⟨21946⟩ (by native_decide) (by native_decide)] - native_decide - have hd21947 : decode code ⟨21947⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨21947⟩ (by native_decide) (by native_decide)] - native_decide - have hd21948 : decode code ⟨21948⟩ = some (.SWAP3, .none) := by - rw [hdec ⟨21948⟩ (by native_decide) (by native_decide)] - native_decide - have hd21949 : decode code ⟨21949⟩ = some (.AND, .none) := by - rw [hdec ⟨21949⟩ (by native_decide) (by native_decide)] - native_decide - have hd21950 : decode code ⟨21950⟩ = some (.MUL, .none) := by - rw [hdec ⟨21950⟩ (by native_decide) (by native_decide)] - native_decide - have hd21951 : decode code ⟨21951⟩ = some (.OR, .none) := by - rw [hdec ⟨21951⟩ (by native_decide) (by native_decide)] - native_decide - have hd21952 : decode code ⟨21952⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨21952⟩ (by native_decide) (by native_decide)] - native_decide - have hd21953 : decode code ⟨21953⟩ = some (.SSTORE, .none) := by - rw [hdec ⟨21953⟩ (by native_decide) (by native_decide)] - native_decide - have rd21903 := evm_run h with [ - raw push1 ⟨3⟩ hd21898 (by evm_ov), - raw dup9 hd21900 (by simp only [List.length_cons] at hov ⊢; omega), - raw add hd21901 (by evm_ov), - raw dup1 hd21902 (by simp only [List.length_cons] at hov ⊢; omega)] - obtain ⟨_, _, rd21904⟩ := rd21903.sload hd21903 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21953 := evm_run rd21904 with [ - raw push1 ⟨1⟩ hd21904 (by evm_ov), - raw push1 ⟨1⟩ hd21906 (by evm_ov), - raw push1 ⟨128⟩ hd21908 (by evm_ov), - raw shl hd21910 (by evm_ov), - raw sub hd21911 (by evm_ov), - raw not hd21912 (by evm_ov), - raw dup2 hd21913 (by simp only [List.length_cons] at hov ⊢; omega), - raw and hd21914 (by evm_ov), - raw push1 ⟨1⟩ hd21915 (by evm_ov), - raw push1 ⟨1⟩ hd21917 (by evm_ov), - raw push1 ⟨128⟩ hd21919 (by evm_ov), - raw shl hd21921 (by evm_ov), - raw sub hd21922 (by evm_ov), - raw swap2 hd21923 (by simp only [List.length_cons] at hov ⊢; omega), - raw dup3 hd21924 (by simp only [List.length_cons] at hov ⊢; omega), - raw and hd21925 (by evm_ov), - raw dup6 hd21926 (by simp only [List.length_cons] at hov ⊢; omega), - raw add hd21927 (by evm_ov), - raw dup3 hd21928 (by simp only [List.length_cons] at hov ⊢; omega), - raw and hd21929 (by evm_ov), - raw lor hd21930 (by evm_ov), - raw dup1 hd21931 (by simp only [List.length_cons] at hov ⊢; omega), - raw dup3 hd21932 (by simp only [List.length_cons] at hov ⊢; omega), - raw and hd21933 (by evm_ov), - raw push1 ⟨1⟩ hd21934 (by evm_ov), - raw push1 ⟨128⟩ hd21936 (by evm_ov), - raw shl hd21938 (by evm_ov), - raw swap2 hd21939 (by simp only [List.length_cons] at hov ⊢; omega), - raw dup3 hd21940 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap1 hd21941 (by simp only [List.length_cons] at hov ⊢; omega), - raw div hd21942 (by evm_ov), - raw dup4 hd21943 (by simp only [List.length_cons] at hov ⊢; omega), - raw and hd21944 (by evm_ov), - raw dup6 hd21945 (by simp only [List.length_cons] at hov ⊢; omega), - raw add hd21946 (by evm_ov), - raw swap1 hd21947 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap3 hd21948 (by simp only [List.length_cons] at hov ⊢; omega), - raw and hd21949 (by evm_ov), - raw mul hd21950 (by evm_ov), - raw lor hd21951 (by evm_ov), - raw swap1 hd21952 (by simp only [List.length_cons] at hov ⊢; omega)] - obtain ⟨_, _, rd21954⟩ := rd21953.sstore hperm hd21953 - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, by - simpa [burnPositionUpdateTokensOwedAddedSlot3, - burnPositionUpdateTokensOwed0AddedSlot3, burnPositionUpdateSlot0Mask] using rd21954⟩ - -theorem uniswapV3PoolBurnPositionUpdateTokensOwed0NonzeroStore {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity freePtr inside1 inside0 delta posBase retPos - inside1' inside0' z2 z3 fee1 fee0 posBase' tick delta' upper lower owner ret - free : UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hperm : ee.perm = true) - (h : RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: freePtr :: inside1 :: inside0 :: - delta :: posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: - fee0 :: posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: - free :: R) - mem aw rdata (cA, σ) k C) - (htokens0 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 ≠ ⟨0⟩) - (hov : R.length + 35 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21954⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: freePtr :: inside1 :: inside0 :: - delta :: posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: - fee0 :: posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: - free :: R) - mem aw rdata - (cA, sstoreAccountMap ee.codeOwner σ (posBase + (⟨3⟩ : UInt256)) - (burnPositionUpdateTokensOwedAddedSlot3 - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256))) tokensOwed0 tokensOwed1)) - k' C' := by - have hdec (pc : UInt256) - (hlo : 21807 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21930) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateSkipLiquidityDecodeEqTemplate hpatch hlo (by omega) - have hd21861 : - decode code ⟨21861⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21861⟩ (by native_decide) (by native_decide)] - native_decide - have hd21863 : - decode code ⟨21863⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21863⟩ (by native_decide) (by native_decide)] - native_decide - have hd21865 : - decode code ⟨21865⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21865⟩ (by native_decide) (by native_decide)] - native_decide - have hd21867 : decode code ⟨21867⟩ = some (.SHL, .none) := by - rw [hdec ⟨21867⟩ (by native_decide) (by native_decide)] - native_decide - have hd21868 : decode code ⟨21868⟩ = some (.SUB, .none) := by - rw [hdec ⟨21868⟩ (by native_decide) (by native_decide)] - native_decide - have hd21869 : decode code ⟨21869⟩ = some (.DUP3, .none) := by - rw [hdec ⟨21869⟩ (by native_decide) (by native_decide)] - native_decide - have hd21870 : decode code ⟨21870⟩ = some (.AND, .none) := by - rw [hdec ⟨21870⟩ (by native_decide) (by native_decide)] - native_decide - have hd21871 : decode code ⟨21871⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨21871⟩ (by native_decide) (by native_decide)] - native_decide - have hd21872 : decode code ⟨21872⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨21872⟩ (by native_decide) (by native_decide)] - native_decide - have hd21873 : decode code ⟨21873⟩ = some (.DUP1, .none) := by - rw [hdec ⟨21873⟩ (by native_decide) (by native_decide)] - native_decide - have hd21874 : - decode code ⟨21874⟩ = some (.Push .PUSH2, some (⟨21892⟩, 2)) := by - rw [hdec ⟨21874⟩ (by native_decide) (by native_decide)] - native_decide - have hd21877 : decode code ⟨21877⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨21877⟩ (by native_decide) (by native_decide)] - native_decide - have hd21892 : decode code ⟨21892⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨21892⟩ (by native_decide) (by native_decide)] - native_decide - have hd21893 : decode code ⟨21893⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨21893⟩ (by native_decide) (by native_decide)] - native_decide - have hd21894 : - decode code ⟨21894⟩ = some (.Push .PUSH2, some (⟨21954⟩, 2)) := by - rw [hdec ⟨21894⟩ (by native_decide) (by native_decide)] - native_decide - have hd21897 : decode code ⟨21897⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨21897⟩ (by native_decide) (by native_decide)] - native_decide - have rd21877 := evm_run h with [ - raw push1 ⟨1⟩ hd21861 (by evm_ov), - raw push1 ⟨1⟩ hd21863 (by evm_ov), - raw push1 ⟨128⟩ hd21865 (by evm_ov), - raw shl hd21867 (by evm_ov), - raw sub hd21868 (by evm_ov), - raw dup3 hd21869 (by simp only [List.length_cons] at hov ⊢; omega), - raw and hd21870 (by evm_ov), - raw iszero hd21871 (by evm_ov), - raw iszero hd21872 (by evm_ov), - raw dup1 hd21873 (by simp only [List.length_cons] at hov ⊢; omega), - raw push2 ⟨21892⟩ hd21874 (by evm_ov)] - have hcond0 : - UInt256.isZero - (UInt256.isZero (UInt256.land tokensOwed0 burnPositionUpdateSlot0Mask)) ≠ - ⟨0⟩ := by - rw [u256_land_comm tokensOwed0 burnPositionUpdateSlot0Mask] - rw [isZero_eq_zero_of_ne htokens0] - native_decide - have rd21892 := rd21877.jumpiT hd21877 hcond0 - (uniswapV3PoolJumpDestPatched21892 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21897 := evm_run rd21892 with [ - raw jumpdest hd21892 (by evm_ov), - raw iszero hd21893 (by evm_ov), - raw push2 ⟨21954⟩ hd21894 (by evm_ov)] - have hstore : - UInt256.isZero - (UInt256.isZero - (UInt256.isZero (UInt256.land tokensOwed0 burnPositionUpdateSlot0Mask))) = - ⟨0⟩ := by - rw [u256_land_comm tokensOwed0 burnPositionUpdateSlot0Mask] - rw [isZero_eq_zero_of_ne htokens0] - native_decide - have rd21898 := rd21897.jumpiNT hd21897 hstore - (by simp only [List.length_cons] at hov ⊢; omega) - exact uniswapV3PoolBurnPositionUpdateStoreTokensOwedSlot3 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (freePtr := freePtr) (inside1 := inside1) - (inside0 := inside0) (delta := delta) (posBase := posBase) (retPos := retPos) - (inside1' := inside1') (inside0' := inside0') (z2 := z2) (z3 := z3) - (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ret) (free := free) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (cA := cA) (σ := σ) hpatch hperm rd21898 hov - -theorem uniswapV3PoolBurnPositionUpdateTokensOwedZeroSkipStores {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity inside1 inside0 delta posBase retPos inside1' - inside0' z2 z3 fee1 fee0 posBase' tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (htokens0 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 = ⟨0⟩) - (htokens1 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 = ⟨0⟩) - (hov : R.length + 35 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21954⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 21807 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21930) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateSkipLiquidityDecodeEqTemplate hpatch hlo (by omega) - have hd21861 : - decode code ⟨21861⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21861⟩ (by native_decide) (by native_decide)] - native_decide - have hd21863 : - decode code ⟨21863⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21863⟩ (by native_decide) (by native_decide)] - native_decide - have hd21865 : - decode code ⟨21865⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21865⟩ (by native_decide) (by native_decide)] - native_decide - have hd21867 : decode code ⟨21867⟩ = some (.SHL, .none) := by - rw [hdec ⟨21867⟩ (by native_decide) (by native_decide)] - native_decide - have hd21868 : decode code ⟨21868⟩ = some (.SUB, .none) := by - rw [hdec ⟨21868⟩ (by native_decide) (by native_decide)] - native_decide - have hd21869 : decode code ⟨21869⟩ = some (.DUP3, .none) := by - rw [hdec ⟨21869⟩ (by native_decide) (by native_decide)] - native_decide - have hd21870 : decode code ⟨21870⟩ = some (.AND, .none) := by - rw [hdec ⟨21870⟩ (by native_decide) (by native_decide)] - native_decide - have hd21871 : decode code ⟨21871⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨21871⟩ (by native_decide) (by native_decide)] - native_decide - have hd21872 : decode code ⟨21872⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨21872⟩ (by native_decide) (by native_decide)] - native_decide - have hd21873 : decode code ⟨21873⟩ = some (.DUP1, .none) := by - rw [hdec ⟨21873⟩ (by native_decide) (by native_decide)] - native_decide - have hd21874 : - decode code ⟨21874⟩ = some (.Push .PUSH2, some (⟨21892⟩, 2)) := by - rw [hdec ⟨21874⟩ (by native_decide) (by native_decide)] - native_decide - have hd21877 : decode code ⟨21877⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨21877⟩ (by native_decide) (by native_decide)] - native_decide - have hd21878 : decode code ⟨21878⟩ = some (.POP, .none) := by - rw [hdec ⟨21878⟩ (by native_decide) (by native_decide)] - native_decide - have hd21879 : - decode code ⟨21879⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨21879⟩ (by native_decide) (by native_decide)] - native_decide - have hd21881 : decode code ⟨21881⟩ = some (.DUP2, .none) := by - rw [hdec ⟨21881⟩ (by native_decide) (by native_decide)] - native_decide - have hd21882 : - decode code ⟨21882⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21882⟩ (by native_decide) (by native_decide)] - native_decide - have hd21884 : - decode code ⟨21884⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21884⟩ (by native_decide) (by native_decide)] - native_decide - have hd21886 : - decode code ⟨21886⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21886⟩ (by native_decide) (by native_decide)] - native_decide - have hd21888 : decode code ⟨21888⟩ = some (.SHL, .none) := by - rw [hdec ⟨21888⟩ (by native_decide) (by native_decide)] - native_decide - have hd21889 : decode code ⟨21889⟩ = some (.SUB, .none) := by - rw [hdec ⟨21889⟩ (by native_decide) (by native_decide)] - native_decide - have hd21890 : decode code ⟨21890⟩ = some (.AND, .none) := by - rw [hdec ⟨21890⟩ (by native_decide) (by native_decide)] - native_decide - have hd21891 : decode code ⟨21891⟩ = some (.GT, .none) := by - rw [hdec ⟨21891⟩ (by native_decide) (by native_decide)] - native_decide - have hd21892 : decode code ⟨21892⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨21892⟩ (by native_decide) (by native_decide)] - native_decide - have hd21893 : decode code ⟨21893⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨21893⟩ (by native_decide) (by native_decide)] - native_decide - have hd21894 : - decode code ⟨21894⟩ = some (.Push .PUSH2, some (⟨21954⟩, 2)) := by - rw [hdec ⟨21894⟩ (by native_decide) (by native_decide)] - native_decide - have hd21897 : decode code ⟨21897⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨21897⟩ (by native_decide) (by native_decide)] - native_decide - have rd21877 := evm_run h with [ - raw push1 ⟨1⟩ hd21861 (by evm_ov), - raw push1 ⟨1⟩ hd21863 (by evm_ov), - raw push1 ⟨128⟩ hd21865 (by evm_ov), - raw shl hd21867 (by evm_ov), - raw sub hd21868 (by evm_ov), - raw dup3 hd21869 (by simp only [List.length_cons] at hov ⊢; omega), - raw and hd21870 (by evm_ov), - raw iszero hd21871 (by evm_ov), - raw iszero hd21872 (by evm_ov), - raw dup1 hd21873 (by simp only [List.length_cons] at hov ⊢; omega), - raw push2 ⟨21892⟩ hd21874 (by evm_ov)] - have hcond0 : - UInt256.isZero - (UInt256.isZero (UInt256.land tokensOwed0 burnPositionUpdateSlot0Mask)) = - ⟨0⟩ := by - rw [u256_land_comm tokensOwed0 burnPositionUpdateSlot0Mask] - rw [htokens0] - native_decide - have rd21878 := by - simpa [burnPositionUpdateSlot0Mask] using - rd21877.jumpiNT hd21877 hcond0 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21892 := evm_run rd21878 with [ - raw pop hd21878 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨0⟩ hd21879 (by evm_ov), - raw dup2 hd21881 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨1⟩ hd21882 (by evm_ov), - raw push1 ⟨1⟩ hd21884 (by evm_ov), - raw push1 ⟨128⟩ hd21886 (by evm_ov), - raw shl hd21888 (by evm_ov), - raw sub hd21889 (by evm_ov), - raw and hd21890 (by evm_ov), - raw gt hd21891 (by evm_ov), - raw jumpdest hd21892 (by evm_ov), - raw iszero hd21893 (by evm_ov), - raw push2 ⟨21954⟩ hd21894 (by evm_ov)] - have hcond1 : - UInt256.isZero - (UInt256.gt (UInt256.land burnPositionUpdateSlot0Mask tokensOwed1) ⟨0⟩) ≠ - ⟨0⟩ := by - rw [htokens1] - native_decide - exact ⟨_, _, by - simpa [burnPositionUpdateSlot0Mask] using - rd21892.jumpiT hd21897 hcond1 (uniswapV3PoolJumpDestPatched21954 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnPositionUpdatePostReturnJump {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity freePtr inside1 inside0 delta posBase retPos - inside1' inside0' z2 z3 fee1 fee0 posBase' tick delta' upper lower owner ret - free : UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains retPos = true) - (h : RD code ee g s0 ⟨21954⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: freePtr :: inside1 :: inside0 :: - delta :: posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: - fee0 :: posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: - free :: R) - mem aw rdata acc k C) - (hov : R.length + 35 ≤ 1024) : - ∃ k' C', RD code ee g s0 retPos - (inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: - delta' :: upper :: lower :: owner :: ret :: free :: R) - mem aw rdata acc k' C' := by - have hdec (pc : UInt256) - (hlo : 21954 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21996) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateReturnDecodeEqTemplate hpatch hlo hhi - have hd21954 : decode code ⟨21954⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨21954⟩ (by native_decide) (by native_decide)] - native_decide - have hd21955 : decode code ⟨21955⟩ = some (.POP, .none) := by - rw [hdec ⟨21955⟩ (by native_decide) (by native_decide)] - native_decide - have hd21956 : decode code ⟨21956⟩ = some (.POP, .none) := by - rw [hdec ⟨21956⟩ (by native_decide) (by native_decide)] - native_decide - have hd21957 : decode code ⟨21957⟩ = some (.POP, .none) := by - rw [hdec ⟨21957⟩ (by native_decide) (by native_decide)] - native_decide - have hd21958 : decode code ⟨21958⟩ = some (.POP, .none) := by - rw [hdec ⟨21958⟩ (by native_decide) (by native_decide)] - native_decide - have hd21959 : decode code ⟨21959⟩ = some (.POP, .none) := by - rw [hdec ⟨21959⟩ (by native_decide) (by native_decide)] - native_decide - have hd21960 : decode code ⟨21960⟩ = some (.POP, .none) := by - rw [hdec ⟨21960⟩ (by native_decide) (by native_decide)] - native_decide - have hd21961 : decode code ⟨21961⟩ = some (.POP, .none) := by - rw [hdec ⟨21961⟩ (by native_decide) (by native_decide)] - native_decide - have hd21962 : decode code ⟨21962⟩ = some (.POP, .none) := by - rw [hdec ⟨21962⟩ (by native_decide) (by native_decide)] - native_decide - have hd21963 : decode code ⟨21963⟩ = some (.JUMP, .none) := by - rw [hdec ⟨21963⟩ (by native_decide) (by native_decide)] - native_decide - have rd21963 := evm_run h with [ - raw jumpdest hd21954 (by evm_ov), - raw pop hd21955 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd21956 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd21957 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd21958 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd21959 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd21960 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd21961 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd21962 (by simp only [List.length_cons] at hov ⊢; omega)] - exact ⟨_, _, rd21963.jump hd21963 hdest - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnPositionUpdateTokensOwedZeroReturn {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity inside1 inside0 delta posBase retPos inside1' - inside0' z2 z3 fee1 fee0 posBase' tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains retPos = true) - (h : RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (htokens0 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 = ⟨0⟩) - (htokens1 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 = ⟨0⟩) - (hov : R.length + 35 ≤ 1024) : - ∃ k' C', RD code ee g s0 retPos - (inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: - delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - obtain ⟨_, _, hrd21954⟩ := - uniswapV3PoolBurnPositionUpdateTokensOwedZeroSkipStores - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (inside1 := inside1) (inside0 := inside0) - (delta := delta) (posBase := posBase) (retPos := retPos) - (inside1' := inside1') (inside0' := inside0') (z2 := z2) (z3 := z3) - (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ret) (free := free) (R := R) (rdata := rdata) (cA := cA) - (σ := σ) hpatch h htokens0 htokens1 hov - exact uniswapV3PoolBurnPositionUpdatePostReturnJump - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (freePtr := burnPositionKeyNewFreePtrWord) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) - (mem := burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (aw := UInt256.ofNat 22) (rdata := rdata) (acc := (cA, σ)) - hpatch hdest hrd21954 hov - -theorem uniswapV3PoolBurnModifyPositionAfterPositionUpdateZeroDeltaReturn - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {inside1 inside0 z2 z3 fee1 fee0 posBase tick delta upper lower owner ret free : - UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains ret = true) - (h : RD code ee g s0 ⟨19527⟩ - (inside1 :: inside0 :: z2 :: z3 :: fee1 :: fee0 :: posBase :: tick :: delta :: - upper :: lower :: owner :: ret :: free :: R) - mem aw rdata acc k C) - (hdelta : UInt256.slt (UInt256.signextend ⟨15⟩ delta) ⟨0⟩ = ⟨0⟩) - (hov : R.length + 17 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret (posBase :: free :: R) mem aw rdata acc k' C' := by - have hdec (pc : UInt256) - (hlo : 19527 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19620) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnModifyPositionPostPositionUpdateDecodeEqTemplate hpatch hlo hhi - have hd19527 : decode code ⟨19527⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨19527⟩ (by native_decide) (by native_decide)] - native_decide - have hd19528 : decode code ⟨19528⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨19528⟩ (by native_decide) (by native_decide)] - native_decide - have hd19530 : decode code ⟨19530⟩ = some (.DUP10, .none) := by - rw [hdec ⟨19530⟩ (by native_decide) (by native_decide)] - native_decide - have hd19531 : decode code ⟨19531⟩ = some (.Push .PUSH1, some (⟨15⟩, 1)) := by - rw [hdec ⟨19531⟩ (by native_decide) (by native_decide)] - native_decide - have hd19533 : decode code ⟨19533⟩ = some (.SIGNEXTEND, .none) := by - rw [hdec ⟨19533⟩ (by native_decide) (by native_decide)] - native_decide - have hd19534 : decode code ⟨19534⟩ = some (.SLT, .none) := by - rw [hdec ⟨19534⟩ (by native_decide) (by native_decide)] - native_decide - have hd19535 : decode code ⟨19535⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨19535⟩ (by native_decide) (by native_decide)] - native_decide - have hd19536 : decode code ⟨19536⟩ = some (.Push .PUSH2, some (⟨19573⟩, 2)) := by - rw [hdec ⟨19536⟩ (by native_decide) (by native_decide)] - native_decide - have hd19539 : decode code ⟨19539⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨19539⟩ (by native_decide) (by native_decide)] - native_decide - have hd19573 : decode code ⟨19573⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨19573⟩ (by native_decide) (by native_decide)] - native_decide - have hd19574 : decode code ⟨19574⟩ = some (.POP, .none) := by - rw [hdec ⟨19574⟩ (by native_decide) (by native_decide)] - native_decide - have hd19575 : decode code ⟨19575⟩ = some (.POP, .none) := by - rw [hdec ⟨19575⟩ (by native_decide) (by native_decide)] - native_decide - have hd19576 : decode code ⟨19576⟩ = some (.POP, .none) := by - rw [hdec ⟨19576⟩ (by native_decide) (by native_decide)] - native_decide - have hd19577 : decode code ⟨19577⟩ = some (.POP, .none) := by - rw [hdec ⟨19577⟩ (by native_decide) (by native_decide)] - native_decide - have hd19578 : decode code ⟨19578⟩ = some (.POP, .none) := by - rw [hdec ⟨19578⟩ (by native_decide) (by native_decide)] - native_decide - have hd19579 : decode code ⟨19579⟩ = some (.POP, .none) := by - rw [hdec ⟨19579⟩ (by native_decide) (by native_decide)] - native_decide - have hd19580 : decode code ⟨19580⟩ = some (.SWAP6, .none) := by - rw [hdec ⟨19580⟩ (by native_decide) (by native_decide)] - native_decide - have hd19581 : decode code ⟨19581⟩ = some (.SWAP5, .none) := by - rw [hdec ⟨19581⟩ (by native_decide) (by native_decide)] - native_decide - have hd19582 : decode code ⟨19582⟩ = some (.POP, .none) := by - rw [hdec ⟨19582⟩ (by native_decide) (by native_decide)] - native_decide - have hd19583 : decode code ⟨19583⟩ = some (.POP, .none) := by - rw [hdec ⟨19583⟩ (by native_decide) (by native_decide)] - native_decide - have hd19584 : decode code ⟨19584⟩ = some (.POP, .none) := by - rw [hdec ⟨19584⟩ (by native_decide) (by native_decide)] - native_decide - have hd19585 : decode code ⟨19585⟩ = some (.POP, .none) := by - rw [hdec ⟨19585⟩ (by native_decide) (by native_decide)] - native_decide - have hd19586 : decode code ⟨19586⟩ = some (.POP, .none) := by - rw [hdec ⟨19586⟩ (by native_decide) (by native_decide)] - native_decide - have hd19587 : decode code ⟨19587⟩ = some (.JUMP, .none) := by - rw [hdec ⟨19587⟩ (by native_decide) (by native_decide)] - native_decide - have rd19533 := evm_run h with [ - raw jumpdest hd19527 (by evm_ov), - raw push1 ⟨0⟩ hd19528 (by evm_ov), - raw dup10 hd19530 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨15⟩ hd19531 (by evm_ov)] - have rd19534 := by - simpa using burnRDSignextend rd19533 hd19533 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd19539 := evm_run rd19534 with [ - raw slt hd19534 (by evm_ov), - raw iszero hd19535 (by evm_ov), - raw push2 ⟨19573⟩ hd19536 (by evm_ov)] - have hcond : - UInt256.isZero (UInt256.slt (UInt256.signextend ⟨15⟩ delta) ⟨0⟩) ≠ ⟨0⟩ := by - rw [hdelta] - native_decide - have rd19573 := rd19539.jumpiT hd19539 hcond - (uniswapV3PoolJumpDestPatched19573 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd19587 := evm_run rd19573 with [ - raw jumpdest hd19573 (by evm_ov), - raw pop hd19574 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd19575 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd19576 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd19577 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd19578 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd19579 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap6 hd19580 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap5 hd19581 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd19582 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd19583 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd19584 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd19585 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd19586 (by simp only [List.length_cons] at hov ⊢; omega)] - exact ⟨_, _, rd19587.jump hd19587 hdest - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnPositionUpdateTokensOwedZeroZeroDeltaModifyPositionReturn - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity inside1 inside0 delta posBase inside1' inside0' - z2 z3 fee1 fee0 posBase' tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains ret = true) - (h : RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: ⟨19527⟩ :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (htokens0 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 = ⟨0⟩) - (htokens1 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 = ⟨0⟩) - (hdelta : UInt256.slt (UInt256.signextend ⟨15⟩ delta') ⟨0⟩ = ⟨0⟩) - (hov : R.length + 35 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret (posBase' :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - obtain ⟨_, _, hrd19527⟩ := - uniswapV3PoolBurnPositionUpdateTokensOwedZeroReturn - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (inside1 := inside1) (inside0 := inside0) - (delta := delta) (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1') (inside0' := inside0') (z2 := z2) (z3 := z3) - (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ret) (free := free) (R := R) (rdata := rdata) (cA := cA) - (σ := σ) hpatch (uniswapV3PoolJumpDestPatched19527 hpatch) h htokens0 htokens1 - hov - exact uniswapV3PoolBurnModifyPositionAfterPositionUpdateZeroDeltaReturn - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1') (inside0 := inside0') (z2 := z2) (z3 := z3) - (fee1 := fee1) (fee0 := fee0) (posBase := posBase') (tick := tick) - (delta := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ret) (free := free) (R := R) - (mem := burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (aw := UInt256.ofNat 22) (rdata := rdata) (acc := (cA, σ)) - hpatch hdest hrd19527 hdelta - (by omega) - -theorem uniswapV3PoolBurnModifyPositionReturnZeroAmountToCaller {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pos0 memPosBase posBase free r1 r2 r3 ret : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains ret = true) - (hzero : burnAmountCleanWord ee = ⟨0⟩) - (h : RD code ee g s0 ⟨16428⟩ - (posBase :: free :: r1 :: r2 :: r3 :: ⟨128⟩ :: ret :: R) - (burnPositionUpdateMem5 σ ee pos0 memPosBase) (UInt256.ofNat 22) rdata - (cA, σ) k C) - (hov : R.length + 12 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret (r1 :: r2 :: posBase :: R) - (burnPositionUpdateMem5 σ ee pos0 memPosBase) (UInt256.ofNat 22) rdata - (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 16428 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 16841) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnModifyPositionReturnToCallerDecodeEqTemplate hpatch hlo hhi - have hd16428 : decode code ⟨16428⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨16428⟩ (by native_decide) (by native_decide)] - native_decide - have hd16429 : decode code ⟨16429⟩ = some (.SWAP4, .none) := by - rw [hdec ⟨16429⟩ (by native_decide) (by native_decide)] - native_decide - have hd16430 : decode code ⟨16430⟩ = some (.POP, .none) := by - rw [hdec ⟨16430⟩ (by native_decide) (by native_decide)] - native_decide - have hd16431 : decode code ⟨16431⟩ = some (.DUP5, .none) := by - rw [hdec ⟨16431⟩ (by native_decide) (by native_decide)] - native_decide - have hd16432 : - decode code ⟨16432⟩ = some (.Push .PUSH1, some (⟨96⟩, 1)) := by - rw [hdec ⟨16432⟩ (by native_decide) (by native_decide)] - native_decide - have hd16434 : decode code ⟨16434⟩ = some (.ADD, .none) := by - rw [hdec ⟨16434⟩ (by native_decide) (by native_decide)] - native_decide - have hd16435 : decode code ⟨16435⟩ = some (.MLOAD, .none) := by - rw [hdec ⟨16435⟩ (by native_decide) (by native_decide)] - native_decide - have hd16436 : - decode code ⟨16436⟩ = some (.Push .PUSH1, some (⟨15⟩, 1)) := by - rw [hdec ⟨16436⟩ (by native_decide) (by native_decide)] - native_decide - have hd16438 : decode code ⟨16438⟩ = some (.SIGNEXTEND, .none) := by - rw [hdec ⟨16438⟩ (by native_decide) (by native_decide)] - native_decide - have hd16439 : - decode code ⟨16439⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨16439⟩ (by native_decide) (by native_decide)] - native_decide - have hd16441 : decode code ⟨16441⟩ = some (.EQ, .none) := by - rw [hdec ⟨16441⟩ (by native_decide) (by native_decide)] - native_decide - have hd16442 : - decode code ⟨16442⟩ = some (.Push .PUSH2, some (⟨16801⟩, 2)) := by - rw [hdec ⟨16442⟩ (by native_decide) (by native_decide)] - native_decide - have hd16445 : decode code ⟨16445⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨16445⟩ (by native_decide) (by native_decide)] - native_decide - have hd16801 : decode code ⟨16801⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨16801⟩ (by native_decide) (by native_decide)] - native_decide - have hd16802 : decode code ⟨16802⟩ = some (.POP, .none) := by - rw [hdec ⟨16802⟩ (by native_decide) (by native_decide)] - native_decide - have hd16803 : decode code ⟨16803⟩ = some (.SWAP2, .none) := by - rw [hdec ⟨16803⟩ (by native_decide) (by native_decide)] - native_decide - have hd16804 : decode code ⟨16804⟩ = some (.SWAP4, .none) := by - rw [hdec ⟨16804⟩ (by native_decide) (by native_decide)] - native_decide - have hd16805 : decode code ⟨16805⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨16805⟩ (by native_decide) (by native_decide)] - native_decide - have hd16806 : decode code ⟨16806⟩ = some (.SWAP3, .none) := by - rw [hdec ⟨16806⟩ (by native_decide) (by native_decide)] - native_decide - have hd16807 : decode code ⟨16807⟩ = some (.POP, .none) := by - rw [hdec ⟨16807⟩ (by native_decide) (by native_decide)] - native_decide - have hd16808 : decode code ⟨16808⟩ = some (.JUMP, .none) := by - rw [hdec ⟨16808⟩ (by native_decide) (by native_decide)] - native_decide - have rd16435 := evm_run h with [ - raw jumpdest hd16428 (by evm_ov), - raw swap4 hd16429 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd16430 (by simp only [List.length_cons] at hov ⊢; omega), - raw dup5 hd16431 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨96⟩ hd16432 (by evm_ov), - raw add hd16434 (by evm_ov)] - have rd16436 := by - simpa [show ((⟨128⟩ : UInt256) + ⟨96⟩) = (⟨224⟩ : UInt256) from by decide, - show ((⟨96⟩ : UInt256) + ⟨128⟩) = (⟨224⟩ : UInt256) from by decide] using - rd16435.mload 0 - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee))) - (UInt256.ofNat 22) hd16435 mem_cost - (burnPositionUpdateMem5_mload224 σ ee pos0 memPosBase) - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16438 := evm_run rd16436 with [ - raw push1 ⟨15⟩ hd16436 (by evm_ov)] - have rd16439 := by - simpa using burnRDSignextend rd16438 hd16438 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16445 := evm_run rd16439 with [ - raw push1 ⟨0⟩ hd16439 (by evm_ov), - raw eq hd16441 (by evm_ov), - raw push2 ⟨16801⟩ hd16442 (by evm_ov)] - have hcond : - UInt256.eq ⟨0⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)))) ≠ - ⟨0⟩ := by - rw [hzero] - native_decide - have rd16801 := rd16445.jumpiT hd16445 hcond - (uniswapV3PoolJumpDestPatched16801 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16808 := evm_run rd16801 with [ - raw jumpdest hd16801 (by evm_ov), - raw pop hd16802 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap2 hd16803 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap4 hd16804 (by omega), - raw swap1 hd16805 (by simp only [List.length_cons]; omega), - raw swap3 hd16806 (by simp only [List.length_cons]; omega), - raw pop hd16807 (by simp only [List.length_cons]; omega)] - exact ⟨_, _, rd16808.jump hd16808 hdest - (by simp only [List.length_cons]; omega)⟩ - -theorem uniswapV3PoolBurnPositionUpdateTokensOwedZeroZeroDeltaReturnToCaller - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity inside1 inside0 delta posBase inside1' inside0' - z2 z3 fee1 fee0 posBase' tick delta' upper lower owner free r1 r2 r3 callerRet : - UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains callerRet = true) - (hzero : burnAmountCleanWord ee = ⟨0⟩) - (h : RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: ⟨19527⟩ :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ⟨16428⟩ :: free :: r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (htokens0 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 = ⟨0⟩) - (htokens1 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 = ⟨0⟩) - (hdelta : UInt256.slt (UInt256.signextend ⟨15⟩ delta') ⟨0⟩ = ⟨0⟩) - (hov : R.length + 40 ≤ 1024) : - ∃ k' C', RD code ee g s0 callerRet (r1 :: r2 :: posBase' :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - obtain ⟨_, _, hrd16428⟩ := - uniswapV3PoolBurnPositionUpdateTokensOwedZeroZeroDeltaModifyPositionReturn - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (inside1 := inside1) (inside0 := inside0) - (delta := delta) (posBase := posBase) (inside1' := inside1') - (inside0' := inside0') (z2 := z2) (z3 := z3) (fee1 := fee1) (fee0 := fee0) - (posBase' := posBase') (tick := tick) (delta' := delta') (upper := upper) - (lower := lower) (owner := owner) (ret := ⟨16428⟩) (free := free) - (R := r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) (rdata := rdata) - (cA := cA) (σ := σ) hpatch (uniswapV3PoolJumpDestPatched16428 hpatch) - h htokens0 htokens1 hdelta - (by simp only [List.length_cons] at hov ⊢; omega) - exact uniswapV3PoolBurnModifyPositionReturnZeroAmountToCaller - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (pos0 := solcSlotWord σ ee posBase) (memPosBase := posBase) (posBase := posBase') - (free := free) (r1 := r1) (r2 := r2) (r3 := r3) (ret := callerRet) (R := R) - (rdata := rdata) (cA := cA) (σ := σ) hpatch hdest hzero hrd16428 - (by omega) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateRevert.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateRevert.lean deleted file mode 100644 index 8f814889..00000000 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateRevert.lean +++ /dev/null @@ -1,226 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdate - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev burnPositionUpdateRevertFreePtr : UInt256 := - burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) - -def burnPositionUpdateNpRevertWord : UInt256 := - UInt256.shiftLeft (⟨1253⟩ : UInt256) ⟨244⟩ - -noncomputable abbrev burnPositionUpdateNpRevertMem0 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : ByteArray := - writeWord (burnPositionUpdateMem5 σ I pos0 posBase) - burnPositionUpdateRevertFreePtr.toNat solcErrorStringSelector - -noncomputable abbrev burnPositionUpdateNpRevertMem1 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : ByteArray := - writeWord (burnPositionUpdateNpRevertMem0 σ I pos0 posBase) - (burnPositionUpdateRevertFreePtr + (⟨4⟩ : UInt256)).toNat (⟨32⟩ : UInt256) - -noncomputable abbrev burnPositionUpdateNpRevertMem2 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : ByteArray := - writeWord (burnPositionUpdateNpRevertMem1 σ I pos0 posBase) - (burnPositionUpdateRevertFreePtr + (⟨36⟩ : UInt256)).toNat (⟨2⟩ : UInt256) - -noncomputable abbrev burnPositionUpdateNpRevertMem3 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : ByteArray := - writeWord (burnPositionUpdateNpRevertMem2 σ I pos0 posBase) - (burnPositionUpdateRevertFreePtr + (⟨68⟩ : UInt256)).toNat - burnPositionUpdateNpRevertWord - -theorem burnPositionUpdateNpRevertMem0_size (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateNpRevertMem0 σ I pos0 posBase).size = 730 := by - unfold burnPositionUpdateNpRevertMem0 burnPositionUpdateRevertFreePtr - rw [writeWord_size _ _ _ - (by rw [burnPositionUpdateMem5_size σ I pos0 posBase]; native_decide)] - rw [burnPositionUpdateMem5_size σ I pos0 posBase] - native_decide - -theorem burnPositionUpdateNpRevertMem1_size (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateNpRevertMem1 σ I pos0 posBase).size = 734 := by - unfold burnPositionUpdateNpRevertMem1 burnPositionUpdateRevertFreePtr - rw [writeWord_size _ _ _ - (by rw [burnPositionUpdateNpRevertMem0_size σ I pos0 posBase]; native_decide)] - rw [burnPositionUpdateNpRevertMem0_size σ I pos0 posBase] - native_decide - -theorem burnPositionUpdateNpRevertMem2_size (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateNpRevertMem2 σ I pos0 posBase).size = 766 := by - unfold burnPositionUpdateNpRevertMem2 burnPositionUpdateRevertFreePtr - rw [writeWord_size _ _ _ - (by rw [burnPositionUpdateNpRevertMem1_size σ I pos0 posBase]; native_decide)] - rw [burnPositionUpdateNpRevertMem1_size σ I pos0 posBase] - native_decide - -theorem burnPositionUpdateNpRevertMem3_size (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateNpRevertMem3 σ I pos0 posBase).size = 798 := by - unfold burnPositionUpdateNpRevertMem3 burnPositionUpdateRevertFreePtr - rw [writeWord_size _ _ _ - (by rw [burnPositionUpdateNpRevertMem2_size σ I pos0 posBase]; native_decide)] - rw [burnPositionUpdateNpRevertMem2_size σ I pos0 posBase] - native_decide - -theorem burnPositionUpdateNpRevertMem3_read64 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (burnPositionUpdateNpRevertMem3 σ I pos0 posBase).readWithPadding 64 32 = - UInt256.toByteArray burnPositionUpdateRevertFreePtr := by - unfold burnPositionUpdateNpRevertMem3 - rw [writeWord_read_preserved - (burnPositionUpdateNpRevertMem2 σ I pos0 posBase) - (burnPositionUpdateRevertFreePtr + (⟨68⟩ : UInt256)).toNat - 64 burnPositionUpdateNpRevertWord - (by rw [burnPositionUpdateNpRevertMem2_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateNpRevertMem2_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateNpRevertMem2 - rw [writeWord_read_preserved - (burnPositionUpdateNpRevertMem1 σ I pos0 posBase) - (burnPositionUpdateRevertFreePtr + (⟨36⟩ : UInt256)).toNat - 64 (⟨2⟩ : UInt256) - (by rw [burnPositionUpdateNpRevertMem1_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateNpRevertMem1_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateNpRevertMem1 - rw [writeWord_read_preserved - (burnPositionUpdateNpRevertMem0 σ I pos0 posBase) - (burnPositionUpdateRevertFreePtr + (⟨4⟩ : UInt256)).toNat - 64 (⟨32⟩ : UInt256) - (by rw [burnPositionUpdateNpRevertMem0_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateNpRevertMem0_size σ I pos0 posBase]; native_decide)] - unfold burnPositionUpdateNpRevertMem0 - rw [writeWord_read_preserved - (burnPositionUpdateMem5 σ I pos0 posBase) - burnPositionUpdateRevertFreePtr.toNat - 64 solcErrorStringSelector - (by rw [burnPositionUpdateMem5_size σ I pos0 posBase]; native_decide) - (by rw [burnPositionUpdateMem5_size σ I pos0 posBase]; native_decide)] - simpa [burnPositionUpdateRevertFreePtr] using - burnPositionUpdateMem5_read64 σ I pos0 posBase - -theorem burnPositionUpdateNpRevertMem3_mload64 (σ : AccountMap) (I : ExecutionEnv) - (pos0 posBase : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (burnPositionUpdateNpRevertMem3 σ I pos0 posBase).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 25 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPositionUpdateNpRevertMem3 σ I pos0 posBase).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - burnPositionUpdateRevertFreePtr := by - exact mloadWordValue_of_readWithPadding - (mem := burnPositionUpdateNpRevertMem3 σ I pos0 posBase) (aw := UInt256.ofNat 25) - (off := ⟨64⟩) (v := burnPositionUpdateRevertFreePtr) - (by rw [burnPositionUpdateNpRevertMem3_size σ I pos0 posBase]; native_decide) - (by native_decide) - (by - simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using burnPositionUpdateNpRevertMem3_read64 σ I pos0 posBase) - -private theorem uniswapV3PoolBurnPositionUpdateRevertDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 21661 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21801) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 21801 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -private theorem uniswapV3PoolBurnPositionUpdateNpRevertTailWf - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcErrorStringRevertTailWf code ⟨21661⟩ ⟨2⟩ ⟨1253⟩ ⟨244⟩ .PUSH2 2 := by - dsimp [solcErrorStringRevertTailWf] - repeat' constructor - all_goals - rw [uniswapV3PoolBurnPositionUpdateRevertDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - -theorem uniswapV3PoolBurnPositionUpdateNpRevertTail {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pos0 posBase : UInt256} {stk : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21661⟩ stk - (burnPositionUpdateMem5 σ ee pos0 posBase) (UInt256.ofNat 22) - rdata (cA, σ) k C) - (hov : stk.length + 5 ≤ 1024) : - RDrev code g s0 := by - rcases uniswapV3PoolBurnPositionUpdateNpRevertTailWf hpatch with - ⟨hd0, hd2, hd3, hd4, hd8, hd10, hd11, hd12, hd13, hd15, hd17, hd18, - hd19, hd20, hd22, hd24, hd25, hd26, hd27, hdRawOut, hdShl, hd68, - hdDup3, hdAdd, hdMstore3, hdSwap, hdMload, hdSwap2, hdDup2, hdSwap3, - hdSub, hd100, hdAdd2, hdSwap4, hdRev⟩ - have rdMload := evm_run h with [ - raw push1 ⟨64⟩ hd0 (by evm_ov), - raw dup1 hd2 (by evm_ov), - raw mload 0 burnPositionUpdateRevertFreePtr (UInt256.ofNat 22) hd3 - mem_cost - (by - simpa [burnPositionUpdateRevertFreePtr] using - burnPositionUpdateMem5_mload64 σ ee pos0 posBase) - (by decide) (by evm_ov)] - have rdSelectorRaw := rdMload.pushConst (⟨4594637⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) hd4 - (by simp only [List.length_cons]; omega) - have rdPrefix := evm_run rdSelectorRaw with [ - raw push1 ⟨229⟩ hd8 (by evm_ov), - raw shl hd10 (by evm_ov), - raw dup2 hd11 (by evm_ov), - raw mstore 4 (burnPositionUpdateNpRevertMem0 σ ee pos0 posBase) - (UInt256.ofNat 23) hd12 mem_cost (by rfl) (by decide) (by evm_ov), - raw push1 ⟨32⟩ hd13 (by evm_ov), - raw push1 ⟨4⟩ hd15 (by evm_ov), - raw dup3 hd17 (by evm_ov), - raw add hd18 (by evm_ov), - raw mstore 0 (burnPositionUpdateNpRevertMem1 σ ee pos0 posBase) - (UInt256.ofNat 23) hd19 mem_cost (by rfl) (by decide) (by evm_ov), - raw push1 ⟨2⟩ hd20 (by evm_ov), - raw push1 ⟨36⟩ hd22 (by evm_ov), - raw dup3 hd24 (by evm_ov), - raw add hd25 (by evm_ov), - raw mstore 3 (burnPositionUpdateNpRevertMem2 σ ee pos0 posBase) - (UInt256.ofNat 24) hd26 mem_cost (by rfl) (by decide) (by evm_ov)] - have rdRaw := rdPrefix.pushConst (⟨1253⟩ : UInt256) - (width := 2) (op := .PUSH2) (by decide) hd27 - (by simp only [List.length_cons]; omega) - have rdWord := evm_run rdRaw with [ - raw push1 ⟨244⟩ hdRawOut (by evm_ov), - raw shl hdShl (by evm_ov)] - exact evm_run rdWord with [ - raw push1 ⟨68⟩ hd68 (by evm_ov), - raw dup3 hdDup3 (by evm_ov), - raw add hdAdd (by evm_ov), - raw mstore 3 (burnPositionUpdateNpRevertMem3 σ ee pos0 posBase) - (UInt256.ofNat 25) hdMstore3 mem_cost - (by rfl) - (by decide) (by evm_ov), - raw swap1 hdSwap (by evm_ov), - raw mload 0 burnPositionUpdateRevertFreePtr (UInt256.ofNat 25) hdMload - mem_cost - (burnPositionUpdateNpRevertMem3_mload64 σ ee pos0 posBase) - (by decide) (by evm_ov), - raw swap1 hdSwap2 (by evm_ov), - raw dup2 hdDup2 (by evm_ov), - raw swap1 hdSwap3 (by evm_ov), - raw sub hdSub (by evm_ov), - raw push1 ⟨100⟩ hd100 (by evm_ov), - raw add hdAdd2 (by evm_ov), - raw swap1 hdSwap4 (by evm_ov), - raw rev 0 hdRev mem_cost (by evm_ov)] - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateSlowPostReturn.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateSlowPostReturn.lean deleted file mode 100644 index 88c4a81a..00000000 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateSlowPostReturn.lean +++ /dev/null @@ -1,555 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdatePostReturn - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolBurnPositionUpdateMulDiv1Prod1NonzeroSkipLiquidityWrite - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {tokensOwed0 liquidity inside1 inside0 delta posBase retPos inside1' inside0' - z2 z3 fee1 fee0 posBase' tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: liquidity :: - UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256))) :: - ⟨21807⟩ :: ⟨0⟩ :: tokensOwed0 :: liquidity :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hprod1 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - liquidity ≠ ⟨0⟩) - (hden : - UInt256.gt (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - liquidity) ≠ ⟨0⟩) - (hdelta : UInt256.signextend ⟨15⟩ delta = ⟨0⟩) - (hov : R.length + 60 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21846⟩ - (uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - liquidity) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - liquidity) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - liquidity - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) :: - tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - let den := UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ - let a := UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256))) - let prod1 := uniswapV3PoolFullMathMulDivProd1 a liquidity - let prod0 := uniswapV3PoolFullMathMulDivProd0 a liquidity - obtain ⟨_, _, hrd13044⟩ := - uniswapV3PoolFullMathMulDivStartProduct - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (mem := burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (aw := UInt256.ofNat 22) (rdata := rdata) (acc := (cA, σ)) - (den := den) (b := liquidity) (a := a) (ret := ⟨21807⟩) (z := ⟨0⟩) - (R := tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - hpatch (by simpa [den, a] using h) (by simp only [List.length_cons] at hov ⊢; omega) - obtain ⟨_, _, hrd21807⟩ := - uniswapV3PoolFullMathMulDivProd1NonzeroReturnStack - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (mem := burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (aw := UInt256.ofNat 22) (rdata := rdata) (acc := (cA, σ)) - (prod1 := prod1) (prod0 := prod0) (den := den) (b := liquidity) (a := a) - (ret := ⟨21807⟩) (z := ⟨0⟩) - (R := tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - hpatch - (by simpa [prod1, prod0, den, a] using hrd13044) - (by simpa [prod1, a] using hprod1) - (by simpa [prod1, den, a] using hden) - (uniswapV3PoolJumpDestPatched21807 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - exact uniswapV3PoolBurnPositionUpdateDeltaZeroSkipLiquidityWrite - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := uniswapV3PoolFullMathMulDivSlowResult prod1 prod0 den liquidity a) - (z := ⟨0⟩) (tokensOwed0 := tokensOwed0) (liquidity := liquidity) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hdelta - (by - simpa [prod1, prod0, den, a, uniswapV3PoolFullMathMulDivSlowResult, - uniswapV3PoolFullMathMulDivSlowReturnStack, - uniswapV3PoolFullMathMulDivSlowJumpStack, - uniswapV3PoolFullMathMulDivSlowBodyStack] using hrd21807) - (by omega) - -theorem uniswapV3PoolBurnPositionUpdateMulDiv0Prod1NonzeroStartMulDiv1 - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))) :: - ⟨21769⟩ :: ⟨0⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hprod0 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) ≠ ⟨0⟩) - (hden0 : - UInt256.gt (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) ≠ ⟨0⟩) - (hov : R.length + 60 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256))) :: - ⟨21807⟩ :: ⟨0⟩ :: - uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - let den := UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ - let liquidity := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) - let a := UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))) - let prod1 := uniswapV3PoolFullMathMulDivProd1 a liquidity - let prod0 := uniswapV3PoolFullMathMulDivProd0 a liquidity - obtain ⟨_, _, hrd13044⟩ := - uniswapV3PoolFullMathMulDivStartProduct - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (mem := burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (aw := UInt256.ofNat 22) (rdata := rdata) (acc := (cA, σ)) - (den := den) (b := liquidity) (a := a) (ret := ⟨21769⟩) (z := ⟨0⟩) - (R := liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - hpatch (by simpa [den, liquidity, a] using h) - (by simp only [List.length_cons] at hov ⊢; omega) - obtain ⟨_, _, hrd21769⟩ := - uniswapV3PoolFullMathMulDivProd1NonzeroReturnStack - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (mem := burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (aw := UInt256.ofNat 22) (rdata := rdata) (acc := (cA, σ)) - (prod1 := prod1) (prod0 := prod0) (den := den) (b := liquidity) (a := a) - (ret := ⟨21769⟩) (z := ⟨0⟩) - (R := liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - hpatch - (by simpa [prod1, prod0, den, liquidity, a] using hrd13044) - (by simpa [prod1, liquidity, a] using hprod0) - (by simpa [prod1, den, liquidity, a] using hden0) - (uniswapV3PoolJumpDestPatched21769 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - exact uniswapV3PoolBurnPositionUpdateStartMulDiv1 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed0 := uniswapV3PoolFullMathMulDivSlowResult prod1 prod0 den liquidity a) - (z := ⟨0⟩) (liquidity := liquidity) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch - (by - simpa [prod1, prod0, den, liquidity, a, uniswapV3PoolFullMathMulDivSlowResult, - uniswapV3PoolFullMathMulDivSlowReturnStack, - uniswapV3PoolFullMathMulDivSlowJumpStack, - uniswapV3PoolFullMathMulDivSlowBodyStack] using hrd21769) - (by omega) - -theorem uniswapV3PoolBurnPositionUpdateMulDiv0Prod1NonzeroMulDiv1Prod1ZeroStoreFeeGrowthLast - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hperm : ee.perm = true) - (h : RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))) :: - ⟨21769⟩ :: ⟨0⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hprod0 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) ≠ ⟨0⟩) - (hden0 : - UInt256.gt (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) ≠ ⟨0⟩) - (hprod1 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) = ⟨0⟩) - (hdelta : UInt256.signextend ⟨15⟩ delta = ⟨0⟩) - (hov : R.length + 60 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21861⟩ - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) :: - uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata - (cA, sstoreAccountMap ee.codeOwner - (sstoreAccountMap ee.codeOwner σ (posBase + (⟨1⟩ : UInt256)) inside0) - (posBase + (⟨2⟩ : UInt256)) inside1) k' C' := by - obtain ⟨_, _, hrdSecond13017⟩ := - uniswapV3PoolBurnPositionUpdateMulDiv0Prod1NonzeroStartMulDiv1 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch h hprod0 hden0 (by omega) - obtain ⟨_, _, hrd21846⟩ := - uniswapV3PoolBurnPositionUpdateMulDiv1Prod1ZeroSkipLiquidityWrite - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed0 := uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))))) - (liquidity := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdSecond13017 hprod1 hdelta (by omega) - exact uniswapV3PoolBurnPositionUpdateStoreFeeGrowthLastAfterSkip - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (tokensOwed0 := uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))))) - (liquidity := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hperm hrd21846 (by omega) - -theorem uniswapV3PoolBurnPositionUpdateMulDiv0Prod1NonzeroMulDiv1Prod1NonzeroStoreFeeGrowthLast - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hperm : ee.perm = true) - (h : RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))) :: - ⟨21769⟩ :: ⟨0⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hprod0 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) ≠ ⟨0⟩) - (hden0 : - UInt256.gt (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) ≠ ⟨0⟩) - (hprod1 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) ≠ ⟨0⟩) - (hden1 : - UInt256.gt (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) ≠ ⟨0⟩) - (hdelta : UInt256.signextend ⟨15⟩ delta = ⟨0⟩) - (hov : R.length + 60 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21861⟩ - (uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) :: - uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata - (cA, sstoreAccountMap ee.codeOwner - (sstoreAccountMap ee.codeOwner σ (posBase + (⟨1⟩ : UInt256)) inside0) - (posBase + (⟨2⟩ : UInt256)) inside1) k' C' := by - obtain ⟨_, _, hrdSecond13017⟩ := - uniswapV3PoolBurnPositionUpdateMulDiv0Prod1NonzeroStartMulDiv1 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch h hprod0 hden0 (by omega) - obtain ⟨_, _, hrd21846⟩ := - uniswapV3PoolBurnPositionUpdateMulDiv1Prod1NonzeroSkipLiquidityWrite - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed0 := uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))))) - (liquidity := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdSecond13017 hprod1 hden1 hdelta (by omega) - exact uniswapV3PoolBurnPositionUpdateStoreFeeGrowthLastAfterSkip - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256))))) - (tokensOwed0 := uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))))) - (liquidity := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hperm hrd21846 (by omega) - -theorem uniswapV3PoolBurnPositionUpdateMulDiv0Prod1ZeroMulDiv1Prod1NonzeroStoreFeeGrowthLast - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {inside1 inside0 delta posBase retPos inside1' inside0' z2 z3 fee1 fee0 posBase' - tick delta' upper lower owner ret free : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hperm : ee.perm = true) - (h : RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256))) :: - ⟨21769⟩ :: ⟨0⟩ :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata (cA, σ) k C) - (hprod0 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) = ⟨0⟩) - (hprod1 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) ≠ ⟨0⟩) - (hden : - UInt256.gt (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) ≠ ⟨0⟩) - (hdelta : UInt256.signextend ⟨15⟩ delta = ⟨0⟩) - (hov : R.length + 60 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21861⟩ - (uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) :: - UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) :: - burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase) :: - burnPositionKeyNewFreePtrWord :: inside1 :: inside0 :: delta :: posBase :: - retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: fee0 :: posBase' :: - tick :: delta' :: upper :: lower :: owner :: ret :: free :: R) - (burnPositionUpdateMem5 σ ee (solcSlotWord σ ee posBase) posBase) - (UInt256.ofNat 22) rdata - (cA, sstoreAccountMap ee.codeOwner - (sstoreAccountMap ee.codeOwner σ (posBase + (⟨1⟩ : UInt256)) inside0) - (posBase + (⟨2⟩ : UInt256)) inside1) k' C' := by - obtain ⟨_, _, hrdSecond13017⟩ := - uniswapV3PoolBurnPositionUpdateMulDiv0Prod1ZeroStartMulDiv1 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch h hprod0 (by omega) - obtain ⟨_, _, hrd21846⟩ := - uniswapV3PoolBurnPositionUpdateMulDiv1Prod1NonzeroSkipLiquidityWrite - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed0 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (liquidity := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdSecond13017 hprod1 hden hdelta (by omega) - exact uniswapV3PoolBurnPositionUpdateStoreFeeGrowthLastAfterSkip - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (UInt256.sub inside1 (solcSlotWord σ ee (posBase + (⟨2⟩ : UInt256))))) - (tokensOwed0 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub inside0 (solcSlotWord σ ee (posBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (liquidity := burnPositionUpdateSlot0Packed (solcSlotWord σ ee posBase)) - (inside1 := inside1) (inside0 := inside0) (delta := delta) (posBase := posBase) - (retPos := retPos) (inside1' := inside1') (inside0' := inside0') (z2 := z2) - (z3 := z3) (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) (ret := ret) - (free := free) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hperm hrd21846 (by omega) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateSource.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateSource.lean deleted file mode 100644 index 3219e08e..00000000 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateSource.lean +++ /dev/null @@ -1,1831 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdateRevert - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem toBytesBE_eq_reverse_LE (w : UInt256) : - EVM.Word.toBytesBE w = (EVM.Word.toBytesLEWithSizeProof w).1.reverse := by - unfold EVM.Word.toBytesBE EVM.Word.toBytesLEWithSizeProof - simp [toBytesBigEndian, List.reverse_append] - -private theorem shiftLeft96_toNat_of_lt_160 (w : UInt256) - (hw : w.toNat < 2 ^ (160 : Nat)) : - (UInt256.shiftLeft w ⟨96⟩).toNat = w.toNat * 2 ^ (96 : Nat) := by - have hprod : w.toNat * 2 ^ (96 : Nat) < UInt256.size := by - change w.toNat * 2 ^ (96 : Nat) < 2 ^ (256 : Nat) - nlinarith [hw, - show (2 : Nat) ^ (256 : Nat) = 2 ^ (160 : Nat) * 2 ^ (96 : Nat) by - norm_num [← Nat.pow_add]] - unfold UInt256.shiftLeft - rw [if_neg (by decide : ¬ (⟨96⟩ : UInt256).val ≥ 256)] - unfold UInt256.toNat - rw [Fin.shiftLeft_val] - rw [show (⟨96⟩ : UInt256).val.val = 96 by decide] - rw [Nat.shiftLeft_eq] - exact Nat.mod_eq_of_lt hprod - -private theorem shiftLeft96_LE_drop12_eq_take20 (w : UInt256) - (hw : w.toNat < 2 ^ (160 : Nat)) : - (EVM.Word.toBytesLEWithSizeProof (UInt256.shiftLeft w ⟨96⟩)).1.drop 12 = - (EVM.Word.toBytesLEWithSizeProof w).1.take 20 := by - apply fromBytes'_inj_of_length - · rw [List.length_drop, - (EVM.Word.toBytesLEWithSizeProof (UInt256.shiftLeft w ⟨96⟩)).2, - List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - · rw [fromBytes'_drop_wordLE, fromBytes'_take_wordLE, shiftLeft96_toNat_of_lt_160 _ hw] - rw [show 256 ^ (12 : Nat) = 2 ^ (96 : Nat) by - norm_num [show (256 : Nat) = 2 ^ 8 by norm_num, ← Nat.pow_mul]] - rw [show 256 ^ (20 : Nat) = 2 ^ (160 : Nat) by norm_num] - rw [show w.toNat * 2 ^ (96 : Nat) = 2 ^ (96 : Nat) * w.toNat by ring] - rw [Nat.mul_div_right _ (by positivity : 0 < 2 ^ (96 : Nat))] - rw [Nat.mod_eq_of_lt hw] - -private theorem sourceWord_toNat_lt_160 (I : ExecutionEnv) : - (EVM.word I.source).toNat < 2 ^ (160 : Nat) := by - unfold EVM.word EVM.uintN UInt256.toNat - change (Fin.ofNat UInt256.size ↑I.source).val < 2 ^ (160 : Nat) - rw [Fin.val_ofNat] - rw [Nat.mod_eq_of_lt] - · exact I.source.2 - · exact lt_trans I.source.2 (by norm_num [UInt256.size, AccountAddress.size]) - -private theorem ownerPackedWord_eq_shift (I : ExecutionEnv) : - burnPositionKeyOwnerPackedWord I = UInt256.shiftLeft (EVM.word I.source) ⟨96⟩ := by - apply u256_inj - unfold burnPositionKeyOwnerPackedWord - rw [u256_land_toNat] - have hlnot : (UInt256.lnot (⟨79228162514264337593543950335⟩ : UInt256)).toNat = - 2 ^ (256 : Nat) - 2 ^ (96 : Nat) := by - native_decide - rw [hlnot] - have hsource : (UInt256.ofNat ↑I.source).toNat < 2 ^ (160 : Nat) := by - unfold UInt256.ofNat UInt256.toNat - change (Fin.ofNat UInt256.size ↑I.source).val < 2 ^ (160 : Nat) - rw [Fin.val_ofNat] - rw [Nat.mod_eq_of_lt] - · exact I.source.2 - · exact lt_trans I.source.2 (by norm_num [UInt256.size, AccountAddress.size]) - have hshift : (UInt256.shiftLeft (UInt256.ofNat ↑I.source) ⟨96⟩).toNat = - (UInt256.ofNat ↑I.source).toNat * 2 ^ (96 : Nat) := - shiftLeft96_toNat_of_lt_160 _ hsource - rw [hshift] - let x := (UInt256.ofNat ↑I.source).toNat * 2 ^ (96 : Nat) - have hcomm : (2 ^ (256 : Nat) - 2 ^ (96 : Nat)).land x = - x.land (2 ^ (256 : Nat) - 2 ^ (96 : Nat)) := - Nat.land_comm _ _ - change (2 ^ (256 : Nat) - 2 ^ (96 : Nat)).land x % UInt256.size = - (UInt256.shiftLeft (EVM.word ↑I.source) ⟨96⟩).toNat - rw [hcomm] - subst x - rw [natLandClearLow ((UInt256.ofNat ↑I.source).toNat * 2 ^ (96 : Nat)) 96 - (by norm_num)] - · rw [show (UInt256.ofNat ↑I.source).toNat * 2 ^ (96 : Nat) = - 2 ^ (96 : Nat) * (UInt256.ofNat ↑I.source).toNat by ring] - rw [Nat.mul_div_right _ (by positivity : 0 < 2 ^ (96 : Nat))] - rw [Nat.mod_eq_of_lt] - · change (UInt256.ofNat ↑I.source).toNat * 2 ^ (96 : Nat) = - (UInt256.shiftLeft (UInt256.ofNat ↑I.source) ⟨96⟩).toNat - rw [hshift] - · have hprod : (UInt256.ofNat ↑I.source).toNat * 2 ^ (96 : Nat) < UInt256.size := by - change (UInt256.ofNat ↑I.source).toNat * 2 ^ (96 : Nat) < 2 ^ (256 : Nat) - nlinarith [hsource, - show (2 : Nat) ^ (256 : Nat) = 2 ^ (160 : Nat) * 2 ^ (96 : Nat) by - norm_num [← Nat.pow_add]] - exact hprod - · have hprod : (UInt256.ofNat ↑I.source).toNat * 2 ^ (96 : Nat) < UInt256.size := by - change (UInt256.ofNat ↑I.source).toNat * 2 ^ (96 : Nat) < 2 ^ (256 : Nat) - nlinarith [hsource, - show (2 : Nat) ^ (256 : Nat) = 2 ^ (160 : Nat) * 2 ^ (96 : Nat) by - norm_num [← Nat.pow_add]] - exact hprod - -private theorem ownerPacked_toBytesBE_take20 (I : ExecutionEnv) : - (EVM.Word.toBytesBE (burnPositionKeyOwnerPackedWord I)).take 20 = - (EVM.word I.source).toBytesBE.drop 12 := by - rw [ownerPackedWord_eq_shift] - rw [toBytesBE_eq_reverse_LE, toBytesBE_eq_reverse_LE] - rw [List.take_reverse, List.drop_reverse] - rw [(EVM.Word.toBytesLEWithSizeProof (UInt256.shiftLeft (EVM.word ↑I.source) ⟨96⟩)).2] - rw [(EVM.Word.toBytesLEWithSizeProof (EVM.word ↑I.source)).2] - norm_num - exact shiftLeft96_LE_drop12_eq_take20 _ (sourceWord_toNat_lt_160 I) - -private theorem nat_mul_pow232_mod_pow256 (n : Nat) : - n * 2 ^ (232 : Nat) % 2 ^ (256 : Nat) = - (n % 2 ^ (24 : Nat)) * 2 ^ (232 : Nat) := by - have hdecomp : n = n / 2 ^ (24 : Nat) * 2 ^ (24 : Nat) + n % 2 ^ (24 : Nat) := by - rw [show n / 2 ^ (24 : Nat) * 2 ^ (24 : Nat) = - 2 ^ (24 : Nat) * (n / 2 ^ (24 : Nat)) by ring] - exact (Nat.div_add_mod n (2 ^ (24 : Nat))).symm - calc - n * 2 ^ (232 : Nat) % 2 ^ (256 : Nat) - = ((n / 2 ^ (24 : Nat) * 2 ^ (24 : Nat) + n % 2 ^ (24 : Nat)) * - 2 ^ (232 : Nat)) % 2 ^ (256 : Nat) := by - rw [← hdecomp] - _ = (n / 2 ^ (24 : Nat) * 2 ^ (256 : Nat) + - (n % 2 ^ (24 : Nat)) * 2 ^ (232 : Nat)) % 2 ^ (256 : Nat) := by - ring_nf - _ = ((n % 2 ^ (24 : Nat)) * 2 ^ (232 : Nat)) % 2 ^ (256 : Nat) := by - rw [show n / 2 ^ (24 : Nat) * 2 ^ (256 : Nat) + - (n % 2 ^ (24 : Nat)) * 2 ^ (232 : Nat) = - 2 ^ (256 : Nat) * (n / 2 ^ (24 : Nat)) + - (n % 2 ^ (24 : Nat)) * 2 ^ (232 : Nat) by ring] - rw [Nat.mul_add_mod_self_left] - _ = (n % 2 ^ (24 : Nat)) * 2 ^ (232 : Nat) := by - rw [Nat.mod_eq_of_lt] - have hmod : n % 2 ^ (24 : Nat) < 2 ^ (24 : Nat) := - Nat.mod_lt _ (by positivity) - nlinarith [ - show (2 : Nat) ^ (256 : Nat) = 2 ^ (24 : Nat) * 2 ^ (232 : Nat) by - norm_num [← Nat.pow_add]] - -private theorem shiftLeft232_toNat (w : UInt256) : - (UInt256.shiftLeft w ⟨232⟩).toNat = - (w.toNat % 2 ^ (24 : Nat)) * 2 ^ (232 : Nat) := by - unfold UInt256.shiftLeft - rw [if_neg (by decide : ¬ (⟨232⟩ : UInt256).val ≥ 256)] - unfold UInt256.toNat - rw [Fin.shiftLeft_val, Nat.shiftLeft_eq] - exact nat_mul_pow232_mod_pow256 w.val.val - -private theorem shiftLeft232_LE_drop29_eq_take3 (w : UInt256) : - (EVM.Word.toBytesLEWithSizeProof (UInt256.shiftLeft w ⟨232⟩)).1.drop 29 = - (EVM.Word.toBytesLEWithSizeProof w).1.take 3 := by - apply fromBytes'_inj_of_length - · rw [List.length_drop, - (EVM.Word.toBytesLEWithSizeProof (UInt256.shiftLeft w ⟨232⟩)).2, - List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - · rw [fromBytes'_drop_wordLE, fromBytes'_take_wordLE, shiftLeft232_toNat] - rw [show 256 ^ (29 : Nat) = 2 ^ (232 : Nat) by - norm_num [show (256 : Nat) = 2 ^ 8 by norm_num, ← Nat.pow_mul]] - rw [show 256 ^ (3 : Nat) = 2 ^ (24 : Nat) by norm_num] - rw [show w.toNat % 2 ^ (24 : Nat) * 2 ^ (232 : Nat) = - 2 ^ (232 : Nat) * (w.toNat % 2 ^ (24 : Nat)) by ring] - rw [Nat.mul_div_right _ (by positivity : 0 < 2 ^ (232 : Nat))] - -private theorem shiftLeft232_toBytesBE_take3 (w : UInt256) : - (EVM.Word.toBytesBE (UInt256.shiftLeft w ⟨232⟩)).take 3 = - (EVM.Word.toBytesBE w).drop 29 := by - rw [toBytesBE_eq_reverse_LE, toBytesBE_eq_reverse_LE] - rw [List.take_reverse, List.drop_reverse] - rw [(EVM.Word.toBytesLEWithSizeProof (UInt256.shiftLeft w ⟨232⟩)).2] - rw [(EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - exact shiftLeft232_LE_drop29_eq_take3 w - -private theorem lowerPacked_toBytesBE_take3 (I : ExecutionEnv) : - (EVM.Word.toBytesBE (burnPositionKeyLowerPackedWord I)).take 3 = - (EVM.wordOfInt (tickSpacingSint24Value (burnTickLowerWord I))).toBytesBE.drop 29 := by - unfold burnPositionKeyLowerPackedWord burnTickLowerCleanWord - rw [signextend_two_tickSpacing_idempotent (UInt256.signextend ⟨2⟩ (burnTickLowerWord I))] - rw [signextend_two_tickSpacing_idempotent (burnTickLowerWord I)] - rw [← wordOfInt_sint24Value_eq_signextend_two (burnTickLowerWord I)] - exact shiftLeft232_toBytesBE_take3 _ - -private theorem upperPacked_toBytesBE_take3 (I : ExecutionEnv) : - (EVM.Word.toBytesBE (burnPositionKeyUpperPackedWord I)).take 3 = - (EVM.wordOfInt (tickSpacingSint24Value (burnTickUpperWord I))).toBytesBE.drop 29 := by - unfold burnPositionKeyUpperPackedWord burnTickUpperCleanWord - rw [signextend_two_tickSpacing_idempotent (UInt256.signextend ⟨2⟩ (burnTickUpperWord I))] - rw [signextend_two_tickSpacing_idempotent (burnTickUpperWord I)] - rw [← wordOfInt_sint24Value_eq_signextend_two (burnTickUpperWord I)] - exact shiftLeft232_toBytesBE_take3 _ - -private theorem word_toByteArray_extract0_eq_take (word : UInt256) (n : Nat) : - (UInt256.toByteArray word).extract 0 n = - ByteArray.mk ((EVM.Word.toBytesBE word).take n).toArray := by - rw [toByteArray_eq_toBytesBE] - apply ByteArray.ext - apply Array.toList_inj.mp - rw [ByteArray.data_extract, Array.toList_extract] - rw [List.extract_eq_take_drop, List.drop_zero] - simp - -private theorem owner_toByteArray_extract0_20 (I : ExecutionEnv) : - (UInt256.toByteArray (burnPositionKeyOwnerPackedWord I)).extract 0 20 = - ByteArray.mk ((EVM.word I.source).toBytesBE.drop 12).toArray := by - rw [word_toByteArray_extract0_eq_take, ownerPacked_toBytesBE_take20] - -private theorem lower_toByteArray_extract0_3 (I : ExecutionEnv) : - (UInt256.toByteArray (burnPositionKeyLowerPackedWord I)).extract 0 3 = - ByteArray.mk - ((EVM.wordOfInt (tickSpacingSint24Value (burnTickLowerWord I))).toBytesBE.drop 29).toArray := by - rw [word_toByteArray_extract0_eq_take, lowerPacked_toBytesBE_take3] - -private theorem upper_toByteArray_extract0_3 (I : ExecutionEnv) : - (UInt256.toByteArray (burnPositionKeyUpperPackedWord I)).extract 0 3 = - ByteArray.mk - ((EVM.wordOfInt (tickSpacingSint24Value (burnTickUpperWord I))).toBytesBE.drop 29).toArray := by - rw [word_toByteArray_extract0_eq_take, upperPacked_toBytesBE_take3] - -private theorem burnPositionKeyMem0_size (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMem0 σ I).size = 544 := by - unfold burnPositionKeyMem0 - rw [writeWord_size] - · rw [burnModifyPositionSlot0Mem_size σ I] - native_decide - · rw [burnModifyPositionSlot0Mem_size σ I] - native_decide - -private theorem burnPositionKeyMem1_size (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMem1 σ I).size = 564 := by - unfold burnPositionKeyMem1 - rw [writeWord_size] - · rw [burnPositionKeyMem0_size σ I] - native_decide - · rw [burnPositionKeyMem0_size σ I] - native_decide - -private theorem burnPositionKeyMem2_read512_20 (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMem2 σ I).readWithPadding 512 20 = - (UInt256.toByteArray (burnPositionKeyOwnerPackedWord I)).extract 0 20 := by - unfold burnPositionKeyMem2 - rw [writeWord_read_preserved_len] - · unfold burnPositionKeyMem1 - rw [writeWord_read_preserved_len] - · unfold burnPositionKeyMem0 - simpa using writeWord_read_window (burnModifyPositionSlot0Mem σ I) 512 0 20 - (burnPositionKeyOwnerPackedWord I) (by norm_num) (by norm_num) (by norm_num) - (by rw [burnModifyPositionSlot0Mem_size σ I]; native_decide) - · rw [burnPositionKeyMem0_size σ I] - native_decide - · exact Or.inl ⟨by norm_num, by rw [burnPositionKeyMem0_size σ I]; omega⟩ - · norm_num - · norm_num - · rw [burnPositionKeyMem1_size σ I] - native_decide - · exact Or.inl ⟨by norm_num, by rw [burnPositionKeyMem1_size σ I]; omega⟩ - · norm_num - · norm_num - -private theorem burnPositionKeyMem2_read532_3 (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMem2 σ I).readWithPadding 532 3 = - (UInt256.toByteArray (burnPositionKeyLowerPackedWord I)).extract 0 3 := by - unfold burnPositionKeyMem2 - rw [writeWord_read_preserved_len] - · unfold burnPositionKeyMem1 - simpa using writeWord_read_window (burnPositionKeyMem0 σ I) 532 0 3 - (burnPositionKeyLowerPackedWord I) (by norm_num) (by norm_num) (by norm_num) - (by rw [burnPositionKeyMem0_size σ I]; native_decide) - · rw [burnPositionKeyMem1_size σ I] - native_decide - · exact Or.inl ⟨by norm_num, by rw [burnPositionKeyMem1_size σ I]; omega⟩ - · norm_num - · norm_num - -private theorem burnPositionKeyMem2_read535_3 (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyMem2 σ I).readWithPadding 535 3 = - (UInt256.toByteArray (burnPositionKeyUpperPackedWord I)).extract 0 3 := by - unfold burnPositionKeyMem2 - simpa using writeWord_read_window (burnPositionKeyMem1 σ I) 535 0 3 - (burnPositionKeyUpperPackedWord I) (by norm_num) (by norm_num) (by norm_num) - (by rw [burnPositionKeyMem1_size σ I]; native_decide) - -private theorem byteArray_mk_append (xs ys : List UInt8) : - ByteArray.mk xs.toArray ++ ByteArray.mk ys.toArray = - ByteArray.mk (xs ++ ys).toArray := by - apply ByteArray.ext - apply Array.toList_inj.mp - rw [ByteArray.data_append, Array.toList_append] - -private theorem byteArray_mk_append3 (xs ys zs : List UInt8) : - ByteArray.mk xs.toArray ++ (ByteArray.mk ys.toArray ++ ByteArray.mk zs.toArray) = - ByteArray.mk (xs ++ ys ++ zs).toArray := by - rw [byteArray_mk_append, byteArray_mk_append] - apply ByteArray.ext - apply Array.toList_inj.mp - simp [List.append_assoc] - -theorem burnPositionKeyPackedHashMem_read512_26 - (σ : AccountMap) (I : ExecutionEnv) : - (burnPositionKeyPackedHashMem σ I).readWithPadding 512 26 = - burnPositionKeyPackedBytes I := by - unfold burnPositionKeyPackedHashMem - rw [writeWord_read_preserved_len] - · unfold burnPositionKeyMem3 - rw [writeWord_read_preserved_len] - · rw [byteArray_readWithPadding_split _ 512 20 6] - · rw [byteArray_readWithPadding_split _ 532 3 3] - · rw [burnPositionKeyMem2_read512_20, burnPositionKeyMem2_read532_3, - burnPositionKeyMem2_read535_3] - rw [owner_toByteArray_extract0_20, lower_toByteArray_extract0_3, - upper_toByteArray_extract0_3] - unfold burnPositionKeyPackedBytes burnPositionKeyPackedList - rw [byteArray_mk_append3] - · norm_num - · norm_num - · norm_num - · norm_num - · norm_num - · rw [burnPositionKeyMem2_size σ I] - omega - · norm_num - · norm_num - · norm_num - · norm_num - · norm_num - · rw [burnPositionKeyMem2_size σ I] - omega - · rw [burnPositionKeyMem2_size σ I] - native_decide - · exact Or.inr ⟨by norm_num, by rw [burnPositionKeyMem2_size σ I]; omega⟩ - · norm_num - · norm_num - · rw [burnPositionKeyMem3_size σ I] - native_decide - · exact Or.inr ⟨by norm_num, by rw [burnPositionKeyMem3_size σ I]; omega⟩ - · norm_num - · norm_num - -theorem burnPositionKeyHashWord_eq (σ : AccountMap) (I : ExecutionEnv) : - burnPositionKeyHashWord σ I = - UInt256.ofNat (fromByteArrayBigEndian (ffi.KEC (burnPositionKeyPackedBytes I))) := by - unfold burnPositionKeyHashWord - rw [burnPositionKeyPackedHashMem_read512_26] - -theorem burnPositionKeyValue_keyValueToWord (I : ExecutionEnv) : - keyValueToWord - (KeyValue.fixedBytes bytes32Width (ffi.KEC (burnPositionKeyPackedBytes I)).toList) = - UInt256.ofNat (fromByteArrayBigEndian (ffi.KEC (burnPositionKeyPackedBytes I))) := by - have hkey := keyValueToWord_fixedBytes32 (uInt256OfByteArray - (ffi.KEC (burnPositionKeyPackedBytes I))) - rw [toBytesBE_keccak_uInt256OfByteArray (burnPositionKeyPackedBytes I)] at hkey - rw [uInt256OfByteArray_eq] at hkey - simpa [bytes32Width] using hkey - -theorem burnPositionBaseSlotWord_eq_positionsBase - (σ : AccountMap) (I : ExecutionEnv) : - burnPositionBaseSlotWord σ I = - positionsBase - (KeyValue.fixedBytes bytes32Width (ffi.KEC (burnPositionKeyPackedBytes I)).toList) := by - unfold burnPositionBaseSlotWord positionsBase mapSlot solcMappingSlot - rw [burnPositionKeyHashWord_eq σ I, burnPositionKeyValue_keyValueToWord I] - -abbrev burnPositionKeyKey (I : ExecutionEnv) : KeyValue := - .fixedBytes bytes32Width (ffi.KEC (burnPositionKeyPackedBytes I)).toList - -abbrev burnPositionUpdateArgValues (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : List Value := - [ burnPositionKeyValue I, - burnLiquidityDeltaValue I, - .int (Int.ofNat feeGrowthInside0X128.toNat), - .int (Int.ofNat feeGrowthInside1X128.toNat) ] - -abbrev burnPositionUpdateStore (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : Store := - ((((∅ : Store) - |>.insert "feeGrowthInside1X128" (.int (Int.ofNat feeGrowthInside1X128.toNat))) - |>.insert "feeGrowthInside0X128" (.int (Int.ofNat feeGrowthInside0X128.toNat))) - |>.insert "liquidityDelta" (burnLiquidityDeltaValue I)) - |>.insert "positionKey" (burnPositionKeyValue I) - -abbrev burnPositionUpdateFrame (v : PoolImmutables) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : Frame := - { contract := contract v, - locals := burnPositionUpdateStore I feeGrowthInside0X128 feeGrowthInside1X128 } - -def burnPositionUpdateEvaledBaseRef (I : ExecutionEnv) : EvaledStorageRef := - { base := "positions", steps := [.mindex (burnPositionKeyKey I)] } - -def burnPositionUpdateEvaledRef (I : ExecutionEnv) (field : Ident) : EvaledStorageRef := - { base := "positions", steps := [.mindex (burnPositionKeyKey I), .field field] } - -theorem burnPositionUpdate_bindParams (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - bindParams? positionUpdateFunction.params - (burnPositionUpdateArgValues I feeGrowthInside0X128 feeGrowthInside1X128) = - some (burnPositionUpdateStore I feeGrowthInside0X128 feeGrowthInside1X128) := by - rfl - -theorem burnPositionUpdateStore_positionKey (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - (burnPositionUpdateStore I feeGrowthInside0X128 feeGrowthInside1X128).get? - "positionKey" = - some (burnPositionKeyValue I) := by - rw [burnPositionUpdateStore] - exact store_get_self - ((((∅ : Store) - |>.insert "feeGrowthInside1X128" (.int (Int.ofNat feeGrowthInside1X128.toNat))) - |>.insert "feeGrowthInside0X128" (.int (Int.ofNat feeGrowthInside0X128.toNat))) - |>.insert "liquidityDelta" (burnLiquidityDeltaValue I)) - "positionKey" (burnPositionKeyValue I) - -theorem burnPositionUpdateStore_liquidityDelta (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - (burnPositionUpdateStore I feeGrowthInside0X128 feeGrowthInside1X128).get? - "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnPositionUpdateStore] - rw [store_get_ne - ((((∅ : Store) - |>.insert "feeGrowthInside1X128" (.int (Int.ofNat feeGrowthInside1X128.toNat))) - |>.insert "feeGrowthInside0X128" (.int (Int.ofNat feeGrowthInside0X128.toNat))) - |>.insert "liquidityDelta" (burnLiquidityDeltaValue I)) - (k := "positionKey") (a := "liquidityDelta") (burnPositionKeyValue I) - (by native_decide)] - exact store_get_self - (((∅ : Store) - |>.insert "feeGrowthInside1X128" (.int (Int.ofNat feeGrowthInside1X128.toNat))) - |>.insert "feeGrowthInside0X128" (.int (Int.ofNat feeGrowthInside0X128.toNat))) - "liquidityDelta" (burnLiquidityDeltaValue I) - -theorem burnPositionUpdateStore_positions (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - (burnPositionUpdateStore I feeGrowthInside0X128 feeGrowthInside1X128).get? - "positions" = none := by - rw [burnPositionUpdateStore] - rw [store_get_ne4 (∅ : Store) - (k1 := "feeGrowthInside1X128") (k2 := "feeGrowthInside0X128") - (k3 := "liquidityDelta") (k4 := "positionKey") (a := "positions") - (.int (Int.ofNat feeGrowthInside1X128.toNat)) - (.int (Int.ofNat feeGrowthInside0X128.toNat)) - (burnLiquidityDeltaValue I) (burnPositionKeyValue I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide)] - simp - -theorem burnPositionUpdate_evalStorageRef_positions {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - evalStorageRef (config v) - (burnPositionUpdateFrame v I feeGrowthInside0X128 feeGrowthInside1X128) evm - (positionsRef (.var "positionKey")) = - .ok (burnPositionUpdateEvaledBaseRef I) := by - have hlen : - (ffi.KEC (burnPositionKeyPackedBytes I)).toList.length = - bytes32Width.val + 1 := by - rw [byteArray_toList_eq, Array.length_toList] - change (ffi.KEC (burnPositionKeyPackedBytes I)).size = bytes32Width.val + 1 - rw [keccak_size] - simp [bytes32Width] - simp [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, positionsRef, - evalExpr?, burnPositionUpdateEvaledBaseRef, burnPositionUpdateFrame, - burnPositionKeyValue, burnPositionKeyKey, - valueToKey?, hlen, bytes32Width, EvalResult.bind, EvalResult.ofOption, bind, pure] - -theorem burnPositionUpdate_resolvePositionRef {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - resolveStorageRef? (config v) - (burnPositionUpdateFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) (positionsRef (.var "positionKey")) = - .ok (burnPositionUpdateEvaledBaseRef I, positionInfoStructTy) := by - rw [resolveStorageRef?] - change - (match - (burnPositionUpdateStore I feeGrowthInside0X128 feeGrowthInside1X128).get? - "positions" with - | some (.storageRef er ty) => - evalStorageRefFrom? (config v) - (burnPositionUpdateFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) er ty (positionsRef (.var "positionKey")).steps - | _ => - match - evalStorageRef (config v) - (burnPositionUpdateFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) (positionsRef (.var "positionKey")) with - | .ok er => do - let ty <- EvalResult.ofOption .storageError - (storageTypeAt? - (burnPositionUpdateFrame v I feeGrowthInside0X128 feeGrowthInside1X128).contract.storage - er) - pure (er, ty) - | .revert => .revert - | .error e => .error e) = - .ok (burnPositionUpdateEvaledBaseRef I, positionInfoStructTy) - rw [burnPositionUpdateStore_positions] - rw [burnPositionUpdate_evalStorageRef_positions (v := v) - (initState cA gh bl σ σ₀ g A I) I feeGrowthInside0X128 feeGrowthInside1X128] - simp [burnPositionUpdateEvaledBaseRef, burnPositionKeyKey, contract, storageDecls, - storageTypeAt?, storageTypeStep?, positionInfoStructTy, EvalResult.ofOption, - EvalResult.bind, bind, pure] - -theorem positionsStorageLocLoad_liquidity_at (evm : EVM.State) (base : UInt256) : - storageLocLoad evm - (loc base ⟨0, by decide⟩ ⟨16, by decide⟩ (by decide) - (.int uint128Int)) = - .int (Int.ofNat (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner base) - uint128Mask).toNat) := by - rw [← show UInt256.ofNat (2 ^ (8 * 16) - 1) = uint128Mask by native_decide] - simpa [loc, uint128Int] using - storageLocLoad_uint_offset0 evm base (16 : Fin 33) ⟨128, by decide⟩ - (hbound := by decide) (by decide) - -theorem burnPositionUpdate_sourceLiquidityLoad_zero - {cA gh bl σ σ₀ A I} {g : Sat256} - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) = ⟨0⟩) : - storageLocLoad (initState cA gh bl σ σ₀ g A I) - (loc (positionsBase (burnPositionKeyKey I)) ⟨0, by decide⟩ ⟨16, by decide⟩ - (by decide) (.int uint128Int)) = - .int 0 := by - have hmask : burnPositionUpdateSlot0Mask = uint128Mask := by native_decide - have hword : - UInt256.land (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) - uint128Mask = ⟨0⟩ := by - simpa [burnPositionUpdateSlot0Packed, hmask, u256_land_comm] using hliq - rw [positionsStorageLocLoad_liquidity_at] - simp [initState, Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage, - hword] - -theorem burnPositionUpdate_sourceLiquidityLoad - {cA gh bl σ σ₀ A I} {g : Sat256} : - storageLocLoad (initState cA gh bl σ σ₀ g A I) - (loc (positionsBase (burnPositionKeyKey I)) ⟨0, by decide⟩ ⟨16, by decide⟩ - (by decide) (.int uint128Int)) = - .int (Int.ofNat (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I)))).toNat) := by - have hmask : burnPositionUpdateSlot0Mask = uint128Mask := by native_decide - rw [positionsStorageLocLoad_liquidity_at] - simp [initState, Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage, - burnPositionUpdateSlot0Packed, hmask, u256_land_comm] - -theorem burnPositionUpdateStorageLocLoad_feeGrowthInside0Last - (evm : EVM.State) (base : UInt256) : - storageLocLoad evm - (loc (base + ⟨1⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int)) = - .int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (base + ⟨1⟩)).toNat) := by - simpa [loc, uint256Loc] using storageLocLoad_uint256 evm (base + ⟨1⟩) - -theorem burnPositionUpdateStorageLocLoad_feeGrowthInside1Last - (evm : EVM.State) (base : UInt256) : - storageLocLoad evm - (loc (base + ⟨2⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int)) = - .int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (base + ⟨2⟩)).toNat) := by - simpa [loc, uint256Loc] using storageLocLoad_uint256 evm (base + ⟨2⟩) - -abbrev burnPositionUpdateAfterPositionFrame (v : PoolImmutables) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : Frame := - { contract := contract v, - locals := - (burnPositionUpdateStore I feeGrowthInside0X128 feeGrowthInside1X128).insert - "position" (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) } - -theorem burnPositionUpdateAfterPosition_liquidityDelta (v : PoolImmutables) - (I : ExecutionEnv) (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - (burnPositionUpdateAfterPositionFrame v I feeGrowthInside0X128 feeGrowthInside1X128).locals.get? - "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnPositionUpdateAfterPositionFrame] - rw [store_get_ne - (burnPositionUpdateStore I feeGrowthInside0X128 feeGrowthInside1X128) - (k := "position") (a := "liquidityDelta") - (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) - (by native_decide)] - exact burnPositionUpdateStore_liquidityDelta I feeGrowthInside0X128 feeGrowthInside1X128 - -theorem burnPositionUpdateAfterPosition_position (v : PoolImmutables) - (I : ExecutionEnv) (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - (burnPositionUpdateAfterPositionFrame v I feeGrowthInside0X128 feeGrowthInside1X128).locals.get? - "position" = - some (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) := by - rw [burnPositionUpdateAfterPositionFrame] - exact store_get_self - (burnPositionUpdateStore I feeGrowthInside0X128 feeGrowthInside1X128) - "position" (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) - -theorem burnPositionUpdate_evalLiquidityDeltaEqZero {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hzero : burnAmountCleanWord I = ⟨0⟩) : - evalExpr? (config v) - (burnPositionUpdateAfterPositionFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (eqE (.var "liquidityDelta") (.intLit 0)) = .ok (.bool true) := by - simp only [eqE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPositionUpdateAfterPosition_liquidityDelta (v := v)] - simp [EvalResult.ofOption, burnLiquidityDeltaValue, hzero, evalBinaryOp?] - -theorem burnPositionUpdate_evalLiquidityDeltaEqZeroFalse {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) : - evalExpr? (config v) - (burnPositionUpdateAfterPositionFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (eqE (.var "liquidityDelta") (.intLit 0)) = .ok (.bool false) := by - simp only [eqE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPositionUpdateAfterPosition_liquidityDelta (v := v)] - simp [EvalResult.ofOption, burnLiquidityDeltaValue, evalBinaryOp?] - have hnat : (burnAmountCleanWord I).toNat ≠ 0 := by - intro h - exact hnonzero (uint256_toNat_eq_zero h) - omega - -theorem burnPositionUpdate_evalPositionLiquidityZero {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) = ⟨0⟩) : - evalExpr? (config v) - (burnPositionUpdateAfterPositionFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (.field (.var "position") "liquidity") = .ok (.int 0) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [burnPositionUpdateAfterPosition_position (v := v)] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? positionInfoStructTy (.field "liquidity") = some uint128St by - simp [storageTypeStep?, positionInfoStructTy, uint128St]] - change - readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnPositionUpdateEvaledRef I "liquidity") uint128St = - .ok (.int 0) - rw [show uint128St = .elem (.int uint128Int) by rfl] - rw [readStorage?_elem - (er := burnPositionUpdateEvaledRef I "liquidity") - (t := .int uint128Int) - (loc := loc (positionsBase (burnPositionKeyKey I)) ⟨0, by decide⟩ - ⟨16, by decide⟩ (by decide) (.int uint128Int))] - · exact congrArg EvalResult.ok (burnPositionUpdate_sourceLiquidityLoad_zero - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hliq) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, loc] - -theorem burnPositionUpdate_evalPositionLiquidityGtZeroFalse {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) = ⟨0⟩) : - evalExpr? (config v) - (burnPositionUpdateAfterPositionFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (gtE (.field (.var "position") "liquidity") (.intLit 0)) = - .ok (.bool false) := by - have hfield := burnPositionUpdate_evalPositionLiquidityZero - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 hliq - simp [gtE, evalExpr?, hfield, evalBinaryOp?, EvalResult.bind, bind, pure] - -theorem uniswapV3PoolPositionUpdateSourceLiquidityZeroReverts - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) = ⟨0⟩) : - ExecFuncBody (config v) - (burnPositionUpdateFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) positionUpdateFunction.body .reverted := by - change ExecFuncBody (config v) - (burnPositionUpdateFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "position" (positionsRef (.var "positionKey")), - Stmt.ite (eqE (.var "liquidityDelta") (.intLit 0)) - [ .require (gtE (.field (.var "position") "liquidity") (.intLit 0)), - .letDecl "liquidityNext" (some uint128) - (.field (.var "position") "liquidity") ] - [ .internalCall "liquidityAddDelta" - [.field (.var "position") "liquidity", .var "liquidityDelta"] - "liquidityNext" ], - .letDecl "tokensOwed0" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside0X128") - (.field (.var "position") "feeGrowthInside0LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)), - .letDecl "tokensOwed1" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside1X128") - (.field (.var "position") "feeGrowthInside1LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)), - Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ .assign .storage { base := "position", steps := [.field "liquidity"] } - (.var "liquidityNext") ] - [], - .assign .storage { base := "position", steps := [.field "feeGrowthInside0LastX128"] } - (.var "feeGrowthInside0X128"), - .assign .storage { base := "position", steps := [.field "feeGrowthInside1LastX128"] } - (.var "feeGrowthInside1X128"), - Stmt.ite (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) - [ .assign .storage { base := "position", steps := [.field "tokensOwed0"] } - (addE (.field (.var "position") "tokensOwed0") (.var "tokensOwed0")), - .assign .storage { base := "position", steps := [.field "tokensOwed1"] } - (addE (.field (.var "position") "tokensOwed1") (.var "tokensOwed1")) ] - [] ] .reverted - refine ExecFuncBody.execBlockRevert ?_ - refine ExecBlock.consNormal (ExecStmt.letStorage - (burnPositionUpdate_resolvePositionRef (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - feeGrowthInside0X128 feeGrowthInside1X128)) ?_ - refine ExecBlock.consRevert (ExecStmt.iteTrue - (burnPositionUpdate_evalLiquidityDeltaEqZero (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) feeGrowthInside0X128 feeGrowthInside1X128 hzero) ?_) - exact ExecBlock.consRevert (ExecStmt.requireFalse - (burnPositionUpdate_evalPositionLiquidityGtZeroFalse (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) feeGrowthInside0X128 feeGrowthInside1X128 hliq)) - -abbrev burnPositionUpdateValueArgValues (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : List Value := - [ burnPositionKeyValue I, - burnLiquidityDeltaValue I, - feeGrowthInside0X128, - feeGrowthInside1X128 ] - -abbrev burnPositionUpdateValueStore (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : Store := - ((((∅ : Store) - |>.insert "feeGrowthInside1X128" feeGrowthInside1X128) - |>.insert "feeGrowthInside0X128" feeGrowthInside0X128) - |>.insert "liquidityDelta" (burnLiquidityDeltaValue I)) - |>.insert "positionKey" (burnPositionKeyValue I) - -abbrev burnPositionUpdateValueFrame (v : PoolImmutables) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : Frame := - { contract := contract v, - locals := burnPositionUpdateValueStore I feeGrowthInside0X128 feeGrowthInside1X128 } - -theorem burnPositionUpdateValue_bindParams (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - bindParams? positionUpdateFunction.params - (burnPositionUpdateValueArgValues I feeGrowthInside0X128 feeGrowthInside1X128) = - some (burnPositionUpdateValueStore I feeGrowthInside0X128 feeGrowthInside1X128) := by - rfl - -theorem burnPositionUpdateValueStore_liquidityDelta (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - (burnPositionUpdateValueStore I feeGrowthInside0X128 feeGrowthInside1X128).get? - "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnPositionUpdateValueStore] - rw [store_get_ne - ((((∅ : Store) - |>.insert "feeGrowthInside1X128" feeGrowthInside1X128) - |>.insert "feeGrowthInside0X128" feeGrowthInside0X128) - |>.insert "liquidityDelta" (burnLiquidityDeltaValue I)) - (k := "positionKey") (a := "liquidityDelta") (burnPositionKeyValue I) - (by native_decide)] - exact store_get_self - (((∅ : Store) - |>.insert "feeGrowthInside1X128" feeGrowthInside1X128) - |>.insert "feeGrowthInside0X128" feeGrowthInside0X128) - "liquidityDelta" (burnLiquidityDeltaValue I) - -theorem burnPositionUpdateValueStore_feeGrowthInside0X128 (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - (burnPositionUpdateValueStore I feeGrowthInside0X128 feeGrowthInside1X128).get? - "feeGrowthInside0X128" = - some feeGrowthInside0X128 := by - rw [burnPositionUpdateValueStore] - rw [store_get_ne2 - (((∅ : Store).insert "feeGrowthInside1X128" feeGrowthInside1X128) - |>.insert "feeGrowthInside0X128" feeGrowthInside0X128) - (k1 := "liquidityDelta") (k2 := "positionKey") - (a := "feeGrowthInside0X128") (burnLiquidityDeltaValue I) (burnPositionKeyValue I) - (by native_decide) (by native_decide)] - exact store_get_self ((∅ : Store).insert "feeGrowthInside1X128" feeGrowthInside1X128) - "feeGrowthInside0X128" feeGrowthInside0X128 - -theorem burnPositionUpdateValueStore_feeGrowthInside1X128 (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - (burnPositionUpdateValueStore I feeGrowthInside0X128 feeGrowthInside1X128).get? - "feeGrowthInside1X128" = - some feeGrowthInside1X128 := by - rw [burnPositionUpdateValueStore] - rw [store_get_ne3 - ((∅ : Store).insert "feeGrowthInside1X128" feeGrowthInside1X128) - (k1 := "feeGrowthInside0X128") (k2 := "liquidityDelta") (k3 := "positionKey") - (a := "feeGrowthInside1X128") feeGrowthInside0X128 (burnLiquidityDeltaValue I) - (burnPositionKeyValue I) (by native_decide) (by native_decide) (by native_decide)] - exact store_get_self (∅ : Store) "feeGrowthInside1X128" feeGrowthInside1X128 - -theorem burnPositionUpdateValueStore_positions (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - (burnPositionUpdateValueStore I feeGrowthInside0X128 feeGrowthInside1X128).get? - "positions" = none := by - rw [burnPositionUpdateValueStore] - rw [store_get_ne4 (∅ : Store) - (k1 := "feeGrowthInside1X128") (k2 := "feeGrowthInside0X128") - (k3 := "liquidityDelta") (k4 := "positionKey") (a := "positions") - feeGrowthInside1X128 feeGrowthInside0X128 - (burnLiquidityDeltaValue I) (burnPositionKeyValue I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide)] - simp - -theorem burnPositionUpdateValue_evalStorageRef_positions {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - evalStorageRef (config v) - (burnPositionUpdateValueFrame v I feeGrowthInside0X128 feeGrowthInside1X128) evm - (positionsRef (.var "positionKey")) = - .ok (burnPositionUpdateEvaledBaseRef I) := by - have hlen : - (ffi.KEC (burnPositionKeyPackedBytes I)).toList.length = - bytes32Width.val + 1 := by - rw [byteArray_toList_eq, Array.length_toList] - change (ffi.KEC (burnPositionKeyPackedBytes I)).size = bytes32Width.val + 1 - rw [keccak_size] - simp [bytes32Width] - simp [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, positionsRef, - evalExpr?, burnPositionUpdateEvaledBaseRef, burnPositionUpdateValueFrame, - burnPositionKeyValue, burnPositionKeyKey, - valueToKey?, hlen, bytes32Width, EvalResult.bind, EvalResult.ofOption, bind, pure] - -theorem burnPositionUpdateValue_resolvePositionRef {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - resolveStorageRef? (config v) - (burnPositionUpdateValueFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) (positionsRef (.var "positionKey")) = - .ok (burnPositionUpdateEvaledBaseRef I, positionInfoStructTy) := by - rw [resolveStorageRef?] - change - (match - (burnPositionUpdateValueStore I feeGrowthInside0X128 feeGrowthInside1X128).get? - "positions" with - | some (.storageRef er ty) => - evalStorageRefFrom? (config v) - (burnPositionUpdateValueFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) er ty (positionsRef (.var "positionKey")).steps - | _ => - match - evalStorageRef (config v) - (burnPositionUpdateValueFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) (positionsRef (.var "positionKey")) with - | .ok er => do - let ty <- EvalResult.ofOption .storageError - (storageTypeAt? - (burnPositionUpdateValueFrame v I feeGrowthInside0X128 feeGrowthInside1X128).contract.storage - er) - pure (er, ty) - | .revert => .revert - | .error e => .error e) = - .ok (burnPositionUpdateEvaledBaseRef I, positionInfoStructTy) - rw [burnPositionUpdateValueStore_positions] - rw [burnPositionUpdateValue_evalStorageRef_positions (v := v) - (initState cA gh bl σ σ₀ g A I) I feeGrowthInside0X128 feeGrowthInside1X128] - simp [burnPositionUpdateEvaledBaseRef, burnPositionKeyKey, contract, storageDecls, - storageTypeAt?, storageTypeStep?, positionInfoStructTy, EvalResult.ofOption, - EvalResult.bind, bind, pure] - -abbrev burnPositionUpdateValueAfterPositionFrame (v : PoolImmutables) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : Frame := - { contract := contract v, - locals := - (burnPositionUpdateValueStore I feeGrowthInside0X128 feeGrowthInside1X128).insert - "position" (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) } - -theorem burnPositionUpdateValueAfterPosition_liquidityDelta (v : PoolImmutables) - (I : ExecutionEnv) (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - (burnPositionUpdateValueAfterPositionFrame v I feeGrowthInside0X128 - feeGrowthInside1X128).locals.get? "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnPositionUpdateValueAfterPositionFrame] - rw [store_get_ne - (burnPositionUpdateValueStore I feeGrowthInside0X128 feeGrowthInside1X128) - (k := "position") (a := "liquidityDelta") - (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) - (by native_decide)] - exact burnPositionUpdateValueStore_liquidityDelta I feeGrowthInside0X128 - feeGrowthInside1X128 - -theorem burnPositionUpdateValueAfterPosition_position (v : PoolImmutables) - (I : ExecutionEnv) (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - (burnPositionUpdateValueAfterPositionFrame v I feeGrowthInside0X128 - feeGrowthInside1X128).locals.get? "position" = - some (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) := by - rw [burnPositionUpdateValueAfterPositionFrame] - exact store_get_self - (burnPositionUpdateValueStore I feeGrowthInside0X128 feeGrowthInside1X128) - "position" (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) - -theorem burnPositionUpdateValue_evalLiquidityDeltaEqZero {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) - (hzero : burnAmountCleanWord I = ⟨0⟩) : - evalExpr? (config v) - (burnPositionUpdateValueAfterPositionFrame v I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (eqE (.var "liquidityDelta") (.intLit 0)) = .ok (.bool true) := by - simp only [eqE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPositionUpdateValueAfterPosition_liquidityDelta (v := v)] - simp [EvalResult.ofOption, burnLiquidityDeltaValue, hzero, evalBinaryOp?] - -theorem burnPositionUpdateValue_evalLiquidityDeltaEqZeroFalse {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) : - evalExpr? (config v) - (burnPositionUpdateValueAfterPositionFrame v I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (eqE (.var "liquidityDelta") (.intLit 0)) = .ok (.bool false) := by - simp only [eqE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPositionUpdateValueAfterPosition_liquidityDelta (v := v)] - simp [EvalResult.ofOption, burnLiquidityDeltaValue, evalBinaryOp?] - have hnat : (burnAmountCleanWord I).toNat ≠ 0 := by - intro h - exact hnonzero (uint256_toNat_eq_zero h) - omega - -theorem burnPositionUpdateValue_evalPositionLiquidityZero {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) = ⟨0⟩) : - evalExpr? (config v) - (burnPositionUpdateValueAfterPositionFrame v I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (.field (.var "position") "liquidity") = .ok (.int 0) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [burnPositionUpdateValueAfterPosition_position (v := v)] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? positionInfoStructTy (.field "liquidity") = some uint128St by - simp [storageTypeStep?, positionInfoStructTy, uint128St]] - change - readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnPositionUpdateEvaledRef I "liquidity") uint128St = - .ok (.int 0) - rw [show uint128St = .elem (.int uint128Int) by rfl] - rw [readStorage?_elem - (er := burnPositionUpdateEvaledRef I "liquidity") - (t := .int uint128Int) - (loc := loc (positionsBase (burnPositionKeyKey I)) ⟨0, by decide⟩ - ⟨16, by decide⟩ (by decide) (.int uint128Int))] - · exact congrArg EvalResult.ok (burnPositionUpdate_sourceLiquidityLoad_zero - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hliq) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, loc] - -theorem burnPositionUpdateValue_evalPositionLiquidityGtZeroFalse {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) = ⟨0⟩) : - evalExpr? (config v) - (burnPositionUpdateValueAfterPositionFrame v I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (gtE (.field (.var "position") "liquidity") (.intLit 0)) = - .ok (.bool false) := by - have hfield := burnPositionUpdateValue_evalPositionLiquidityZero - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 hliq - simp [gtE, evalExpr?, hfield, evalBinaryOp?, EvalResult.bind, bind, pure] - -abbrev burnPositionUpdateValueAfterLiquidityNextFrame (v : PoolImmutables) - (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : Frame := - { contract := contract v, - locals := (burnPositionUpdateValueAfterPositionFrame v I feeGrowthInside0X128 - feeGrowthInside1X128).locals.insert "liquidityNext" - (.int (Int.ofNat (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I)))).toNat)) } - -theorem burnPositionUpdateValue_evalPositionLiquidity {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - evalExpr? (config v) - (burnPositionUpdateValueAfterPositionFrame v I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (.field (.var "position") "liquidity") = - .ok (.int (Int.ofNat (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I)))).toNat)) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [burnPositionUpdateValueAfterPosition_position (v := v)] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? positionInfoStructTy (.field "liquidity") = some uint128St by - simp [storageTypeStep?, positionInfoStructTy, uint128St]] - change - readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnPositionUpdateEvaledRef I "liquidity") uint128St = - .ok (.int (Int.ofNat (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I)))).toNat)) - rw [show uint128St = .elem (.int uint128Int) by rfl] - rw [readStorage?_elem - (er := burnPositionUpdateEvaledRef I "liquidity") - (t := .int uint128Int) - (loc := loc (positionsBase (burnPositionKeyKey I)) ⟨0, by decide⟩ - ⟨16, by decide⟩ (by decide) (.int uint128Int))] - · exact congrArg EvalResult.ok (burnPositionUpdate_sourceLiquidityLoad - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g)) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, loc] - -theorem burnPositionUpdateValue_evalPositionLiquidityGtZeroTrue {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) : - evalExpr? (config v) - (burnPositionUpdateValueAfterPositionFrame v I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (gtE (.field (.var "position") "liquidity") (.intLit 0)) = - .ok (.bool true) := by - have hfield := burnPositionUpdateValue_evalPositionLiquidity - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - have hnat_ne : - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I)))).toNat ≠ 0 := by - intro hnat - exact hliq (uint256_toNat_eq_zero hnat) - have hposNat : - 0 < (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I)))).toNat := - Nat.pos_of_ne_zero hnat_ne - simp [gtE, evalExpr?, hfield, evalBinaryOp?, hposNat, EvalResult.bind, bind, pure] - -theorem uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroPrefixValue - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) : - ExecBlock (config v) - (burnPositionUpdateValueFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "position" (positionsRef (.var "positionKey")), - Stmt.ite (eqE (.var "liquidityDelta") (.intLit 0)) - [ .require (gtE (.field (.var "position") "liquidity") (.intLit 0)), - .letDecl "liquidityNext" (some uint128) - (.field (.var "position") "liquidity") ] - [ .internalCall "liquidityAddDelta" - [.field (.var "position") "liquidity", .var "liquidityDelta"] - "liquidityNext" ]] - (ExecResult.ok - (burnPositionUpdateValueAfterLiquidityNextFrame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I)) := by - refine ExecBlock.consNormal (ExecStmt.letStorage - (burnPositionUpdateValue_resolvePositionRef (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - feeGrowthInside0X128 feeGrowthInside1X128)) ?_ - refine ExecBlock.consNormal (ExecStmt.iteTrue - (burnPositionUpdateValue_evalLiquidityDeltaEqZero (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) feeGrowthInside0X128 feeGrowthInside1X128 hzero) ?_) ExecBlock.nil - refine ExecBlock.consNormal (ExecStmt.requireTrue - (burnPositionUpdateValue_evalPositionLiquidityGtZeroTrue (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 hliq)) ?_ - exact ExecBlock.consNormal (ExecStmt.letDecl - (burnPositionUpdateValue_evalPositionLiquidity (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128)) ExecBlock.nil - -theorem burnPositionUpdateValueAfterLiquidityNext_position (v : PoolImmutables) - (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - (burnPositionUpdateValueAfterLiquidityNextFrame v σ I feeGrowthInside0X128 - feeGrowthInside1X128).locals.get? "position" = - some (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) := by - rw [burnPositionUpdateValueAfterLiquidityNextFrame] - rw [store_get_ne (burnPositionUpdateValueAfterPositionFrame v I feeGrowthInside0X128 - feeGrowthInside1X128).locals (k := "liquidityNext") (a := "position") - (.int (Int.ofNat (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I)))).toNat)) - (by native_decide)] - exact burnPositionUpdateValueAfterPosition_position v I feeGrowthInside0X128 - feeGrowthInside1X128 - -theorem burnPositionUpdateValue_evalFeeGrowthInside0LastAfterLiquidityNext - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - evalExpr? (config v) - (burnPositionUpdateValueAfterLiquidityNextFrame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (.field (.var "position") "feeGrowthInside0LastX128") = - .ok (.int (Int.ofNat - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨1⟩)).toNat)) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [burnPositionUpdateValueAfterLiquidityNext_position (v := v) (σ := σ)] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? positionInfoStructTy (.field "feeGrowthInside0LastX128") = - some uint256St by simp [storageTypeStep?, positionInfoStructTy, uint256St]] - change - readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnPositionUpdateEvaledRef I "feeGrowthInside0LastX128") uint256St = - .ok (.int (Int.ofNat - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨1⟩)).toNat)) - rw [show uint256St = .elem (.int uint256Int) by rfl] - rw [readStorage?_elem - (er := burnPositionUpdateEvaledRef I "feeGrowthInside0LastX128") - (t := .int uint256Int) - (loc := loc (positionsBase (burnPositionKeyKey I) + ⟨1⟩) ⟨0, by decide⟩ - ⟨32, by decide⟩ (by decide) (.int uint256Int))] - · simpa [initState, solcSlotWord] using - burnPositionUpdateStorageLocLoad_feeGrowthInside0Last - (initState cA gh bl σ σ₀ g A I) (positionsBase (burnPositionKeyKey I)) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, loc] - -theorem burnPositionUpdateValue_evalFeeGrowthInside1LastAfterLiquidityNext - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - evalExpr? (config v) - (burnPositionUpdateValueAfterLiquidityNextFrame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (.field (.var "position") "feeGrowthInside1LastX128") = - .ok (.int (Int.ofNat - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩)).toNat)) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [burnPositionUpdateValueAfterLiquidityNext_position (v := v) (σ := σ)] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? positionInfoStructTy (.field "feeGrowthInside1LastX128") = - some uint256St by simp [storageTypeStep?, positionInfoStructTy, uint256St]] - change - readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnPositionUpdateEvaledRef I "feeGrowthInside1LastX128") uint256St = - .ok (.int (Int.ofNat - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩)).toNat)) - rw [show uint256St = .elem (.int uint256Int) by rfl] - rw [readStorage?_elem - (er := burnPositionUpdateEvaledRef I "feeGrowthInside1LastX128") - (t := .int uint256Int) - (loc := loc (positionsBase (burnPositionKeyKey I) + ⟨2⟩) ⟨0, by decide⟩ - ⟨32, by decide⟩ (by decide) (.int uint256Int))] - · simpa [initState, solcSlotWord] using - burnPositionUpdateStorageLocLoad_feeGrowthInside1Last - (initState cA gh bl σ σ₀ g A I) (positionsBase (burnPositionKeyKey I)) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, loc] - -theorem uniswapV3PoolPositionUpdateSourceLiquidityZeroRevertsValue - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) = ⟨0⟩) : - ExecFuncBody (config v) - (burnPositionUpdateValueFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) positionUpdateFunction.body .reverted := by - change ExecFuncBody (config v) - (burnPositionUpdateValueFrame v I feeGrowthInside0X128 feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "position" (positionsRef (.var "positionKey")), - Stmt.ite (eqE (.var "liquidityDelta") (.intLit 0)) - [ .require (gtE (.field (.var "position") "liquidity") (.intLit 0)), - .letDecl "liquidityNext" (some uint128) - (.field (.var "position") "liquidity") ] - [ .internalCall "liquidityAddDelta" - [.field (.var "position") "liquidity", .var "liquidityDelta"] - "liquidityNext" ], - .letDecl "tokensOwed0" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside0X128") - (.field (.var "position") "feeGrowthInside0LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)), - .letDecl "tokensOwed1" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside1X128") - (.field (.var "position") "feeGrowthInside1LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)), - Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ .assign .storage { base := "position", steps := [.field "liquidity"] } - (.var "liquidityNext") ] - [], - .assign .storage { base := "position", steps := [.field "feeGrowthInside0LastX128"] } - (.var "feeGrowthInside0X128"), - .assign .storage { base := "position", steps := [.field "feeGrowthInside1LastX128"] } - (.var "feeGrowthInside1X128"), - Stmt.ite (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) - [ .assign .storage { base := "position", steps := [.field "tokensOwed0"] } - (addE (.field (.var "position") "tokensOwed0") (.var "tokensOwed0")), - .assign .storage { base := "position", steps := [.field "tokensOwed1"] } - (addE (.field (.var "position") "tokensOwed1") (.var "tokensOwed1")) ] - [] ] .reverted - refine ExecFuncBody.execBlockRevert ?_ - refine ExecBlock.consNormal (ExecStmt.letStorage - (burnPositionUpdateValue_resolvePositionRef (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - feeGrowthInside0X128 feeGrowthInside1X128)) ?_ - refine ExecBlock.consRevert (ExecStmt.iteTrue - (burnPositionUpdateValue_evalLiquidityDeltaEqZero (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) feeGrowthInside0X128 feeGrowthInside1X128 hzero) ?_) - exact ExecBlock.consRevert (ExecStmt.requireFalse - (burnPositionUpdateValue_evalPositionLiquidityGtZeroFalse (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) feeGrowthInside0X128 feeGrowthInside1X128 hliq)) - -abbrev burnTickGetLowerKey (I : ExecutionEnv) : KeyValue := - .int (tickSpacingSint24Value (burnTickLowerWord I)) - -abbrev burnTickGetUpperKey (I : ExecutionEnv) : KeyValue := - .int (tickSpacingSint24Value (burnTickUpperWord I)) - -abbrev burnTickGetLowerBaseSlot (I : ExecutionEnv) : UInt256 := - ticksBase (burnTickGetLowerKey I) - -abbrev burnTickGetUpperBaseSlot (I : ExecutionEnv) : UInt256 := - ticksBase (burnTickGetUpperKey I) - -def burnTickGetLowerEvaledBaseRef (I : ExecutionEnv) : EvaledStorageRef := - { base := "ticks", steps := [.mindex (burnTickGetLowerKey I)] } - -def burnTickGetUpperEvaledBaseRef (I : ExecutionEnv) : EvaledStorageRef := - { base := "ticks", steps := [.mindex (burnTickGetUpperKey I)] } - -def burnTickGetLowerEvaledRef (I : ExecutionEnv) (field : Ident) : EvaledStorageRef := - { base := "ticks", steps := [.mindex (burnTickGetLowerKey I), .field field] } - -def burnTickGetUpperEvaledRef (I : ExecutionEnv) (field : Ident) : EvaledStorageRef := - { base := "ticks", steps := [.mindex (burnTickGetUpperKey I), .field field] } - -abbrev burnTickGetLowerFeeGrowthOutside0Word (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - solcSlotWord σ I (burnTickGetLowerBaseSlot I + ⟨1⟩) - -abbrev burnTickGetLowerFeeGrowthOutside1Word (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - solcSlotWord σ I (burnTickGetLowerBaseSlot I + ⟨2⟩) - -abbrev burnTickGetUpperFeeGrowthOutside0Word (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - solcSlotWord σ I (burnTickGetUpperBaseSlot I + ⟨1⟩) - -abbrev burnTickGetUpperFeeGrowthOutside1Word (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - solcSlotWord σ I (burnTickGetUpperBaseSlot I + ⟨2⟩) - -abbrev burnTickGetFeeGrowthInsideArgValues (σ : AccountMap) (I : ExecutionEnv) : - List Value := - [ burnTickLowerValue I, - burnTickUpperValue I, - burnSlot0TickValue σ I, - burnFeeGrowthGlobal0Value σ I, - burnFeeGrowthGlobal1Value σ I ] - -abbrev burnTickGetFeeGrowthInsideStore (σ : AccountMap) (I : ExecutionEnv) : Store := - (((((∅ : Store) - |>.insert "feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I)) - |>.insert "feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I)) - |>.insert "tickCurrent" (burnSlot0TickValue σ I)) - |>.insert "tickUpper" (burnTickUpperValue I)) - |>.insert "tickLower" (burnTickLowerValue I) - -abbrev burnTickGetFeeGrowthInsideFrame (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := burnTickGetFeeGrowthInsideStore σ I } - -theorem burnTickGetFeeGrowthInside_bindParams (σ : AccountMap) (I : ExecutionEnv) : - bindParams? tickGetFeeGrowthInsideFunction.params - (burnTickGetFeeGrowthInsideArgValues σ I) = - some (burnTickGetFeeGrowthInsideStore σ I) := by - rfl - -theorem burnTickGetStore_tickLower (σ : AccountMap) (I : ExecutionEnv) : - (burnTickGetFeeGrowthInsideStore σ I).get? "tickLower" = - some (burnTickLowerValue I) := by - rw [burnTickGetFeeGrowthInsideStore] - exact store_get_self - ((((∅ : Store) - |>.insert "feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I)) - |>.insert "feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I)) - |>.insert "tickCurrent" (burnSlot0TickValue σ I) - |>.insert "tickUpper" (burnTickUpperValue I)) - "tickLower" (burnTickLowerValue I) - -theorem burnTickGetStore_tickUpper (σ : AccountMap) (I : ExecutionEnv) : - (burnTickGetFeeGrowthInsideStore σ I).get? "tickUpper" = - some (burnTickUpperValue I) := by - rw [burnTickGetFeeGrowthInsideStore] - rw [store_get_ne - ((((∅ : Store) - |>.insert "feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I)) - |>.insert "feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I)) - |>.insert "tickCurrent" (burnSlot0TickValue σ I) - |>.insert "tickUpper" (burnTickUpperValue I)) - (k := "tickLower") (a := "tickUpper") (burnTickLowerValue I) - (by native_decide)] - exact store_get_self - (((∅ : Store) - |>.insert "feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I)) - |>.insert "feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I) - |>.insert "tickCurrent" (burnSlot0TickValue σ I)) - "tickUpper" (burnTickUpperValue I) - -theorem burnTickGet_evalStorageRef_lower {v : PoolImmutables} - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) : - evalStorageRef (config v) (burnTickGetFeeGrowthInsideFrame v σ I) evm - (ticksRef (.var "tickLower")) = - .ok (burnTickGetLowerEvaledBaseRef I) := by - simp only [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, ticksRef, - burnTickGetFeeGrowthInsideFrame, evalExpr?, EvalResult.bind, bind, pure] - rw [burnTickGetStore_tickLower] - simp [burnTickGetLowerEvaledBaseRef, burnTickGetLowerKey, burnTickLowerValue, - valueToKey?, EvalResult.ofOption] - -theorem burnTickGet_evalStorageRef_upper {v : PoolImmutables} - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) : - evalStorageRef (config v) (burnTickGetFeeGrowthInsideFrame v σ I) evm - (ticksRef (.var "tickUpper")) = - .ok (burnTickGetUpperEvaledBaseRef I) := by - simp only [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, ticksRef, - burnTickGetFeeGrowthInsideFrame, evalExpr?, EvalResult.bind, bind, pure] - rw [burnTickGetStore_tickUpper] - simp [burnTickGetUpperEvaledBaseRef, burnTickGetUpperKey, burnTickUpperValue, - valueToKey?, EvalResult.ofOption] - -theorem burnTickGetStore_ticks (σ : AccountMap) (I : ExecutionEnv) : - (burnTickGetFeeGrowthInsideStore σ I).get? "ticks" = none := by - rw [burnTickGetFeeGrowthInsideStore] - rw [store_get_ne5 (∅ : Store) - (k1 := "feeGrowthGlobal1X128") (k2 := "feeGrowthGlobal0X128") - (k3 := "tickCurrent") (k4 := "tickUpper") (k5 := "tickLower") (a := "ticks") - (burnFeeGrowthGlobal1Value σ I) (burnFeeGrowthGlobal0Value σ I) - (burnSlot0TickValue σ I) (burnTickUpperValue I) (burnTickLowerValue I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide)] - simp - -theorem burnTickGet_resolveLowerRef {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - resolveStorageRef? (config v) (burnTickGetFeeGrowthInsideFrame v σ I) - (initState cA gh bl σ σ₀ g A I) (ticksRef (.var "tickLower")) = - .ok (burnTickGetLowerEvaledBaseRef I, tickInfoStructTy) := by - apply resolveStorageRef?_ok - · exact burnTickGetStore_ticks σ I - · exact burnTickGet_evalStorageRef_lower (v := v) (initState cA gh bl σ σ₀ g A I) σ I - · simp [burnTickGetLowerEvaledBaseRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, tickInfoStructTy] - -theorem burnTickGet_resolveUpperRef {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - resolveStorageRef? (config v) (burnTickGetFeeGrowthInsideFrame v σ I) - (initState cA gh bl σ σ₀ g A I) (ticksRef (.var "tickUpper")) = - .ok (burnTickGetUpperEvaledBaseRef I, tickInfoStructTy) := by - apply resolveStorageRef?_ok - · exact burnTickGetStore_ticks σ I - · exact burnTickGet_evalStorageRef_upper (v := v) (initState cA gh bl σ σ₀ g A I) σ I - · simp [burnTickGetUpperEvaledBaseRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, tickInfoStructTy] - -abbrev burnWordSubInt (x y : Int) : Int := - (x - y) % (2 ^ 256 : Int) - -theorem evalExpr_wordSub_int {v : PoolImmutables} {frame : Frame} {evm : EVM.State} - {e₁ e₂ : Expr} {x y : Int} - (h₁ : evalExpr? (config v) frame evm e₁ = .ok (.int x)) - (h₂ : evalExpr? (config v) frame evm e₂ = .ok (.int y)) : - evalExpr? (config v) frame evm (wordSub e₁ e₂) = - .ok (.int (burnWordSubInt x y)) := by - simp only [wordSub, modE, subE, uint256Modulus, evalExpr?, EvalResult.bind, bind, pure] - rw [h₁, h₂] - simp [evalBinaryOp?, burnWordSubInt] - -theorem ticksStorageLocLoad_feeGrowthOutside0_at (evm : EVM.State) (base : UInt256) : - storageLocLoad evm - (loc (base + ⟨1⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int)) = - .int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (base + ⟨1⟩)).toNat) := by - simpa [loc, uint256Loc] using storageLocLoad_uint256 evm (base + ⟨1⟩) - -theorem ticksStorageLocLoad_feeGrowthOutside1_at (evm : EVM.State) (base : UInt256) : - storageLocLoad evm - (loc (base + ⟨2⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int)) = - .int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (base + ⟨2⟩)).toNat) := by - simpa [loc, uint256Loc] using storageLocLoad_uint256 evm (base + ⟨2⟩) - -abbrev burnTickGetLowerFeeGrowthOutside0Int (σ : AccountMap) (I : ExecutionEnv) : - Int := - Int.ofNat (burnTickGetLowerFeeGrowthOutside0Word σ I).toNat - -abbrev burnTickGetLowerFeeGrowthOutside1Int (σ : AccountMap) (I : ExecutionEnv) : - Int := - Int.ofNat (burnTickGetLowerFeeGrowthOutside1Word σ I).toNat - -abbrev burnTickGetUpperFeeGrowthOutside0Int (σ : AccountMap) (I : ExecutionEnv) : - Int := - Int.ofNat (burnTickGetUpperFeeGrowthOutside0Word σ I).toNat - -abbrev burnTickGetUpperFeeGrowthOutside1Int (σ : AccountMap) (I : ExecutionEnv) : - Int := - Int.ofNat (burnTickGetUpperFeeGrowthOutside1Word σ I).toNat - -abbrev burnTickGetFeeGrowthGlobal0Int (σ : AccountMap) (I : ExecutionEnv) : Int := - Int.ofNat (solcSlotWord σ I ⟨1⟩).toNat - -abbrev burnTickGetFeeGrowthGlobal1Int (σ : AccountMap) (I : ExecutionEnv) : Int := - Int.ofNat (solcSlotWord σ I ⟨2⟩).toNat - -abbrev burnTickGetBelow0Int (σ : AccountMap) (I : ExecutionEnv) : Int := - if tickSpacingSint24Value (slot0TickRawWord σ I) >= - tickSpacingSint24Value (burnTickLowerWord I) then - burnTickGetLowerFeeGrowthOutside0Int σ I - else - burnWordSubInt (burnTickGetFeeGrowthGlobal0Int σ I) - (burnTickGetLowerFeeGrowthOutside0Int σ I) - -abbrev burnTickGetBelow1Int (σ : AccountMap) (I : ExecutionEnv) : Int := - if tickSpacingSint24Value (slot0TickRawWord σ I) >= - tickSpacingSint24Value (burnTickLowerWord I) then - burnTickGetLowerFeeGrowthOutside1Int σ I - else - burnWordSubInt (burnTickGetFeeGrowthGlobal1Int σ I) - (burnTickGetLowerFeeGrowthOutside1Int σ I) - -abbrev burnTickGetAbove0Int (σ : AccountMap) (I : ExecutionEnv) : Int := - if tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickUpperWord I) then - burnTickGetUpperFeeGrowthOutside0Int σ I - else - burnWordSubInt (burnTickGetFeeGrowthGlobal0Int σ I) - (burnTickGetUpperFeeGrowthOutside0Int σ I) - -abbrev burnTickGetAbove1Int (σ : AccountMap) (I : ExecutionEnv) : Int := - if tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickUpperWord I) then - burnTickGetUpperFeeGrowthOutside1Int σ I - else - burnWordSubInt (burnTickGetFeeGrowthGlobal1Int σ I) - (burnTickGetUpperFeeGrowthOutside1Int σ I) - -abbrev burnTickGetInside0Int (σ : AccountMap) (I : ExecutionEnv) : Int := - burnWordSubInt - (burnWordSubInt (burnTickGetFeeGrowthGlobal0Int σ I) (burnTickGetBelow0Int σ I)) - (burnTickGetAbove0Int σ I) - -abbrev burnTickGetInside1Int (σ : AccountMap) (I : ExecutionEnv) : Int := - burnWordSubInt - (burnWordSubInt (burnTickGetFeeGrowthGlobal1Int σ I) (burnTickGetBelow1Int σ I)) - (burnTickGetAbove1Int σ I) - -abbrev burnTickGetBelow0Value (σ : AccountMap) (I : ExecutionEnv) : Value := - .int (burnTickGetBelow0Int σ I) - -abbrev burnTickGetBelow1Value (σ : AccountMap) (I : ExecutionEnv) : Value := - .int (burnTickGetBelow1Int σ I) - -abbrev burnTickGetAbove0Value (σ : AccountMap) (I : ExecutionEnv) : Value := - .int (burnTickGetAbove0Int σ I) - -abbrev burnTickGetAbove1Value (σ : AccountMap) (I : ExecutionEnv) : Value := - .int (burnTickGetAbove1Int σ I) - -abbrev burnTickGetInside0Value (σ : AccountMap) (I : ExecutionEnv) : Value := - .int (burnTickGetInside0Int σ I) - -abbrev burnTickGetInside1Value (σ : AccountMap) (I : ExecutionEnv) : Value := - .int (burnTickGetInside1Int σ I) - -abbrev burnTickGetAfterLowerFrame (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnTickGetFeeGrowthInsideStore σ I).insert "lower" - (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) } - -abbrev burnTickGetAfterUpperFrame (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnTickGetAfterLowerFrame v σ I).locals.insert "upper" - (.storageRef (burnTickGetUpperEvaledBaseRef I) tickInfoStructTy) } - -abbrev burnTickGetAfterBelow0Frame (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnTickGetAfterUpperFrame v σ I).locals.insert "feeGrowthBelow0X128" - (burnTickGetBelow0Value σ I) } - -abbrev burnTickGetAfterBelow1Frame (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnTickGetAfterBelow0Frame v σ I).locals.insert "feeGrowthBelow1X128" - (burnTickGetBelow1Value σ I) } - -abbrev burnTickGetAfterAbove0Frame (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnTickGetAfterBelow1Frame v σ I).locals.insert "feeGrowthAbove0X128" - (burnTickGetAbove0Value σ I) } - -abbrev burnTickGetAfterAbove1Frame (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnTickGetAfterAbove0Frame v σ I).locals.insert "feeGrowthAbove1X128" - (burnTickGetAbove1Value σ I) } - -theorem burnTickGetAfterLower_tickUpper (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterLowerFrame v σ I).locals.get? "tickUpper" = - some (burnTickUpperValue I) := by - rw [burnTickGetAfterLowerFrame] - rw [store_get_ne (burnTickGetFeeGrowthInsideStore σ I) - (k := "lower") (a := "tickUpper") - (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) - (by native_decide)] - exact burnTickGetStore_tickUpper σ I - -theorem burnTickGetAfterLower_ticks (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterLowerFrame v σ I).locals.get? "ticks" = none := by - rw [burnTickGetAfterLowerFrame] - rw [store_get_ne (burnTickGetFeeGrowthInsideStore σ I) - (k := "lower") (a := "ticks") - (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) - (by native_decide)] - exact burnTickGetStore_ticks σ I - -theorem burnTickGetAfterLower_evalStorageRef_upper {v : PoolImmutables} - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) : - evalStorageRef (config v) (burnTickGetAfterLowerFrame v σ I) evm - (ticksRef (.var "tickUpper")) = - .ok (burnTickGetUpperEvaledBaseRef I) := by - simp only [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, ticksRef, - burnTickGetAfterLowerFrame, evalExpr?, EvalResult.bind, bind, pure] - rw [burnTickGetAfterLower_tickUpper v σ I] - simp [burnTickGetUpperEvaledBaseRef, burnTickGetUpperKey, burnTickUpperValue, - valueToKey?, EvalResult.ofOption] - -theorem burnTickGetAfterLower_resolveUpperRef {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - resolveStorageRef? (config v) (burnTickGetAfterLowerFrame v σ I) - (initState cA gh bl σ σ₀ g A I) (ticksRef (.var "tickUpper")) = - .ok (burnTickGetUpperEvaledBaseRef I, tickInfoStructTy) := by - apply resolveStorageRef?_ok - · exact burnTickGetAfterLower_ticks v σ I - · exact burnTickGetAfterLower_evalStorageRef_upper (v := v) - (initState cA gh bl σ σ₀ g A I) σ I - · simp [burnTickGetUpperEvaledBaseRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, tickInfoStructTy] - -theorem burnTickGetAfterUpper_lower (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterUpperFrame v σ I).locals.get? "lower" = - some (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) := by - rw [burnTickGetAfterUpperFrame] - rw [store_get_ne (burnTickGetAfterLowerFrame v σ I).locals - (k := "upper") (a := "lower") - (.storageRef (burnTickGetUpperEvaledBaseRef I) tickInfoStructTy) - (by native_decide)] - rw [burnTickGetAfterLowerFrame] - exact store_get_self (burnTickGetFeeGrowthInsideStore σ I) - "lower" (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) - -theorem burnTickGetAfterUpper_upper (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterUpperFrame v σ I).locals.get? "upper" = - some (.storageRef (burnTickGetUpperEvaledBaseRef I) tickInfoStructTy) := by - rw [burnTickGetAfterUpperFrame] - exact store_get_self (burnTickGetAfterLowerFrame v σ I).locals - "upper" (.storageRef (burnTickGetUpperEvaledBaseRef I) tickInfoStructTy) - -theorem burnTickGetAfterUpper_tickLower (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterUpperFrame v σ I).locals.get? "tickLower" = - some (burnTickLowerValue I) := by - rw [burnTickGetAfterUpperFrame] - rw [store_get_ne (burnTickGetAfterLowerFrame v σ I).locals - (k := "upper") (a := "tickLower") - (.storageRef (burnTickGetUpperEvaledBaseRef I) tickInfoStructTy) - (by native_decide)] - rw [burnTickGetAfterLowerFrame] - rw [store_get_ne (burnTickGetFeeGrowthInsideStore σ I) - (k := "lower") (a := "tickLower") - (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) - (by native_decide)] - exact burnTickGetStore_tickLower σ I - -theorem burnTickGetAfterUpper_tickUpper (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterUpperFrame v σ I).locals.get? "tickUpper" = - some (burnTickUpperValue I) := by - rw [burnTickGetAfterUpperFrame] - rw [store_get_ne (burnTickGetAfterLowerFrame v σ I).locals - (k := "upper") (a := "tickUpper") - (.storageRef (burnTickGetUpperEvaledBaseRef I) tickInfoStructTy) - (by native_decide)] - exact burnTickGetAfterLower_tickUpper v σ I - -theorem burnTickGetAfterUpper_tickCurrent (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterUpperFrame v σ I).locals.get? "tickCurrent" = - some (burnSlot0TickValue σ I) := by - rw [burnTickGetAfterUpperFrame] - rw [store_get_ne (burnTickGetAfterLowerFrame v σ I).locals - (k := "upper") (a := "tickCurrent") - (.storageRef (burnTickGetUpperEvaledBaseRef I) tickInfoStructTy) - (by native_decide)] - rw [burnTickGetAfterLowerFrame] - rw [store_get_ne (burnTickGetFeeGrowthInsideStore σ I) - (k := "lower") (a := "tickCurrent") - (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) - (by native_decide)] - rw [burnTickGetFeeGrowthInsideStore] - rw [store_get_ne2 - (((∅ : Store) - |>.insert "feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I)) - |>.insert "feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I) - |>.insert "tickCurrent" (burnSlot0TickValue σ I)) - (k1 := "tickUpper") (k2 := "tickLower") (a := "tickCurrent") - (burnTickUpperValue I) (burnTickLowerValue I) - (by native_decide) (by native_decide)] - exact store_get_self - (((∅ : Store) - |>.insert "feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I)) - |>.insert "feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I)) - "tickCurrent" (burnSlot0TickValue σ I) - -theorem burnTickGet_evalCurrentGeLower {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnTickGetAfterUpperFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (geE (.var "tickCurrent") (.var "tickLower")) = - .ok (.bool (tickSpacingSint24Value (slot0TickRawWord σ I) >= - tickSpacingSint24Value (burnTickLowerWord I))) := by - simp only [geE, evalExpr?, EvalResult.bind, bind] - rw [burnTickGetAfterUpper_tickCurrent v σ I, burnTickGetAfterUpper_tickLower v σ I] - simp [EvalResult.ofOption, burnSlot0TickValue, burnTickLowerValue, wordToElem, int24Int, - tickSpacingSint24Value, evalBinaryOp?] - -theorem burnTickGet_evalCurrentLtUpper {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnTickGetAfterBelow1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - (ltE (.var "tickCurrent") (.var "tickUpper")) = - .ok (.bool (tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickUpperWord I))) := by - simp only [ltE, evalExpr?, EvalResult.bind, bind] - rw [show (burnTickGetAfterBelow1Frame v σ I).locals.get? "tickCurrent" = - some (burnSlot0TickValue σ I) by - rw [burnTickGetAfterBelow1Frame, burnTickGetAfterBelow0Frame] - rw [store_get_ne (burnTickGetAfterBelow0Frame v σ I).locals - (k := "feeGrowthBelow1X128") (a := "tickCurrent") (burnTickGetBelow1Value σ I) - (by native_decide)] - rw [store_get_ne (burnTickGetAfterUpperFrame v σ I).locals - (k := "feeGrowthBelow0X128") (a := "tickCurrent") (burnTickGetBelow0Value σ I) - (by native_decide)] - exact burnTickGetAfterUpper_tickCurrent v σ I] - rw [show (burnTickGetAfterBelow1Frame v σ I).locals.get? "tickUpper" = - some (burnTickUpperValue I) by - rw [burnTickGetAfterBelow1Frame, burnTickGetAfterBelow0Frame] - rw [store_get_ne (burnTickGetAfterBelow0Frame v σ I).locals - (k := "feeGrowthBelow1X128") (a := "tickUpper") (burnTickGetBelow1Value σ I) - (by native_decide)] - rw [store_get_ne (burnTickGetAfterUpperFrame v σ I).locals - (k := "feeGrowthBelow0X128") (a := "tickUpper") (burnTickGetBelow0Value σ I) - (by native_decide)] - exact burnTickGetAfterUpper_tickUpper v σ I] - simp [EvalResult.ofOption, burnSlot0TickValue, burnTickUpperValue, wordToElem, int24Int, - tickSpacingSint24Value, evalBinaryOp?] - -theorem burnTickGet_evalLowerFeeGrowthOutside0 {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} {frame : Frame} - (hlower : frame.locals.get? "lower" = - some (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy)) : - evalExpr? (config v) frame (initState cA gh bl σ σ₀ g A I) - (.field (.var "lower") "feeGrowthOutside0X128") = - .ok (.int (burnTickGetLowerFeeGrowthOutside0Int σ I)) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [hlower] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? tickInfoStructTy (.field "feeGrowthOutside0X128") = - some uint256St by simp [storageTypeStep?, tickInfoStructTy, uint256St]] - change - readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnTickGetLowerEvaledRef I "feeGrowthOutside0X128") uint256St = - .ok (.int (burnTickGetLowerFeeGrowthOutside0Int σ I)) - rw [show uint256St = .elem (.int uint256Int) by rfl] - rw [readStorage?_elem - (er := burnTickGetLowerEvaledRef I "feeGrowthOutside0X128") - (t := .int uint256Int) - (loc := loc (burnTickGetLowerBaseSlot I + ⟨1⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int))] - · simpa [initState, burnTickGetLowerFeeGrowthOutside0Int, - burnTickGetLowerFeeGrowthOutside0Word, burnTickGetLowerBaseSlot, solcSlotWord] using - ticksStorageLocLoad_feeGrowthOutside0_at (initState cA gh bl σ σ₀ g A I) - (burnTickGetLowerBaseSlot I) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnTickGetLowerEvaledRef, burnTickGetLowerKey, burnTickGetLowerBaseSlot, loc] - -theorem burnTickGet_evalLowerFeeGrowthOutside1 {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} {frame : Frame} - (hlower : frame.locals.get? "lower" = - some (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy)) : - evalExpr? (config v) frame (initState cA gh bl σ σ₀ g A I) - (.field (.var "lower") "feeGrowthOutside1X128") = - .ok (.int (burnTickGetLowerFeeGrowthOutside1Int σ I)) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [hlower] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? tickInfoStructTy (.field "feeGrowthOutside1X128") = - some uint256St by simp [storageTypeStep?, tickInfoStructTy, uint256St]] - change - readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnTickGetLowerEvaledRef I "feeGrowthOutside1X128") uint256St = - .ok (.int (burnTickGetLowerFeeGrowthOutside1Int σ I)) - rw [show uint256St = .elem (.int uint256Int) by rfl] - rw [readStorage?_elem - (er := burnTickGetLowerEvaledRef I "feeGrowthOutside1X128") - (t := .int uint256Int) - (loc := loc (burnTickGetLowerBaseSlot I + ⟨2⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int))] - · simpa [initState, burnTickGetLowerFeeGrowthOutside1Int, - burnTickGetLowerFeeGrowthOutside1Word, burnTickGetLowerBaseSlot, solcSlotWord] using - ticksStorageLocLoad_feeGrowthOutside1_at (initState cA gh bl σ σ₀ g A I) - (burnTickGetLowerBaseSlot I) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnTickGetLowerEvaledRef, burnTickGetLowerKey, burnTickGetLowerBaseSlot, loc] - -theorem burnTickGet_evalUpperFeeGrowthOutside0 {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} {frame : Frame} - (hupper : frame.locals.get? "upper" = - some (.storageRef (burnTickGetUpperEvaledBaseRef I) tickInfoStructTy)) : - evalExpr? (config v) frame (initState cA gh bl σ σ₀ g A I) - (.field (.var "upper") "feeGrowthOutside0X128") = - .ok (.int (burnTickGetUpperFeeGrowthOutside0Int σ I)) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [hupper] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? tickInfoStructTy (.field "feeGrowthOutside0X128") = - some uint256St by simp [storageTypeStep?, tickInfoStructTy, uint256St]] - change - readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnTickGetUpperEvaledRef I "feeGrowthOutside0X128") uint256St = - .ok (.int (burnTickGetUpperFeeGrowthOutside0Int σ I)) - rw [show uint256St = .elem (.int uint256Int) by rfl] - rw [readStorage?_elem - (er := burnTickGetUpperEvaledRef I "feeGrowthOutside0X128") - (t := .int uint256Int) - (loc := loc (burnTickGetUpperBaseSlot I + ⟨1⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int))] - · simpa [initState, burnTickGetUpperFeeGrowthOutside0Int, - burnTickGetUpperFeeGrowthOutside0Word, burnTickGetUpperBaseSlot, solcSlotWord] using - ticksStorageLocLoad_feeGrowthOutside0_at (initState cA gh bl σ σ₀ g A I) - (burnTickGetUpperBaseSlot I) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnTickGetUpperEvaledRef, burnTickGetUpperKey, burnTickGetUpperBaseSlot, loc] - -theorem burnTickGet_evalUpperFeeGrowthOutside1 {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} {frame : Frame} - (hupper : frame.locals.get? "upper" = - some (.storageRef (burnTickGetUpperEvaledBaseRef I) tickInfoStructTy)) : - evalExpr? (config v) frame (initState cA gh bl σ σ₀ g A I) - (.field (.var "upper") "feeGrowthOutside1X128") = - .ok (.int (burnTickGetUpperFeeGrowthOutside1Int σ I)) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [hupper] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? tickInfoStructTy (.field "feeGrowthOutside1X128") = - some uint256St by simp [storageTypeStep?, tickInfoStructTy, uint256St]] - change - readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnTickGetUpperEvaledRef I "feeGrowthOutside1X128") uint256St = - .ok (.int (burnTickGetUpperFeeGrowthOutside1Int σ I)) - rw [show uint256St = .elem (.int uint256Int) by rfl] - rw [readStorage?_elem - (er := burnTickGetUpperEvaledRef I "feeGrowthOutside1X128") - (t := .int uint256Int) - (loc := loc (burnTickGetUpperBaseSlot I + ⟨2⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int))] - · simpa [initState, burnTickGetUpperFeeGrowthOutside1Int, - burnTickGetUpperFeeGrowthOutside1Word, burnTickGetUpperBaseSlot, solcSlotWord] using - ticksStorageLocLoad_feeGrowthOutside1_at (initState cA gh bl σ σ₀ g A I) - (burnTickGetUpperBaseSlot I) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnTickGetUpperEvaledRef, burnTickGetUpperKey, burnTickGetUpperBaseSlot, loc] - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateSourceSuccess.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateSourceSuccess.lean deleted file mode 100644 index 6c7b17f1..00000000 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateSourceSuccess.lean +++ /dev/null @@ -1,1907 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdateSource - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev burnPositionUpdateSourceLiquidityInt (σ : AccountMap) (I : ExecutionEnv) : Int := - Int.ofNat (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I)))).toNat - -abbrev burnPositionUpdateSourceFeeGrowthInside0LastInt - (σ : AccountMap) (I : ExecutionEnv) : Int := - Int.ofNat (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨1⟩)).toNat - -abbrev burnPositionUpdateSourceFeeGrowthInside1LastInt - (σ : AccountMap) (I : ExecutionEnv) : Int := - Int.ofNat (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩)).toNat - -abbrev burnPositionUpdateSourceTokensOwed0Int - (σ : AccountMap) (I : ExecutionEnv) (feeGrowthInside0X128 : Int) : Int := - (((burnWordSubInt feeGrowthInside0X128 - (burnPositionUpdateSourceFeeGrowthInside0LastInt σ I)) * - burnPositionUpdateSourceLiquidityInt σ I) / ((2 : Int) ^ 128)) % ((2 : Int) ^ 128) - -abbrev burnPositionUpdateSourceTokensOwed1Int - (σ : AccountMap) (I : ExecutionEnv) (feeGrowthInside1X128 : Int) : Int := - (((burnWordSubInt feeGrowthInside1X128 - (burnPositionUpdateSourceFeeGrowthInside1LastInt σ I)) * - burnPositionUpdateSourceLiquidityInt σ I) / ((2 : Int) ^ 128)) % ((2 : Int) ^ 128) - -abbrev burnPositionUpdateSourceTokensOwedSlot (I : ExecutionEnv) : UInt256 := - positionsBase (burnPositionKeyKey I) + ⟨3⟩ - -abbrev burnPositionUpdateSourceStoredTokensOwed0Int - (evm : EVM.State) (I : ExecutionEnv) : Int := - Int.ofNat (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I)) - uint128Mask).toNat - -abbrev burnPositionUpdateSourceStoredTokensOwed1Int - (evm : EVM.State) (I : ExecutionEnv) : Int := - Int.ofNat (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I)) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) uint128Mask).toNat - -abbrev burnPositionUpdateSourceTokensOwed0WriteInt - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 : UInt256) : Int := - burnPositionUpdateSourceStoredTokensOwed0Int evm I + - burnPositionUpdateSourceTokensOwed0Int σ I (Int.ofNat feeGrowthInside0X128.toNat) - -abbrev burnPositionUpdateSourceTokensOwed1WriteInt - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside1X128 : UInt256) : Int := - burnPositionUpdateSourceStoredTokensOwed1Int evm I + - burnPositionUpdateSourceTokensOwed1Int σ I (Int.ofNat feeGrowthInside1X128.toNat) - -abbrev burnPositionUpdateSourceTokensOwed0StoreWord - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 : UInt256) : UInt256 := - UInt256.lor - (UInt256.land - (EVM.wordOfInt - (burnPositionUpdateSourceTokensOwed0WriteInt evm σ I feeGrowthInside0X128)) - uint128Mask) - (UInt256.land (UInt256.lnot uint128Mask) - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I))) - -abbrev burnPositionUpdateSourceTokensOwed1StoreWord - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside1X128 : UInt256) : UInt256 := - UInt256.lor - (UInt256.mul - (UInt256.land - (EVM.wordOfInt - (burnPositionUpdateSourceTokensOwed1WriteInt evm σ I feeGrowthInside1X128)) - uint128Mask) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I)) - uint128Mask) - -abbrev burnPositionUpdateSourceAfterTokensOwed0State - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 : UInt256) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateSourceTokensOwed0StoreWord evm σ I feeGrowthInside0X128) - -abbrev burnPositionUpdateSourceAfterTokensOwedState - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : EVM.State := - let evm1 := burnPositionUpdateSourceAfterTokensOwed0State evm σ I feeGrowthInside0X128 - Solm.EVM.storageStore evm1 evm1.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateSourceTokensOwed1StoreWord evm1 σ I feeGrowthInside1X128) - -theorem burnPositionUpdateValueAfterLiquidityNext_feeGrowthInside0X128 - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - (burnPositionUpdateValueAfterLiquidityNextFrame v σ I feeGrowthInside0X128 - feeGrowthInside1X128).locals.get? "feeGrowthInside0X128" = - some feeGrowthInside0X128 := by - rw [burnPositionUpdateValueAfterLiquidityNextFrame] - rw [store_get_ne (burnPositionUpdateValueAfterPositionFrame v I feeGrowthInside0X128 - feeGrowthInside1X128).locals (k := "liquidityNext") (a := "feeGrowthInside0X128") - (.int (Int.ofNat (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I)))).toNat)) - (by native_decide)] - rw [burnPositionUpdateValueAfterPositionFrame] - rw [store_get_ne (burnPositionUpdateValueStore I feeGrowthInside0X128 feeGrowthInside1X128) - (k := "position") (a := "feeGrowthInside0X128") - (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) - (by native_decide)] - exact burnPositionUpdateValueStore_feeGrowthInside0X128 I feeGrowthInside0X128 - feeGrowthInside1X128 - -theorem burnPositionUpdateValueAfterLiquidityNext_feeGrowthInside1X128 - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - (burnPositionUpdateValueAfterLiquidityNextFrame v σ I feeGrowthInside0X128 - feeGrowthInside1X128).locals.get? "feeGrowthInside1X128" = - some feeGrowthInside1X128 := by - rw [burnPositionUpdateValueAfterLiquidityNextFrame] - rw [store_get_ne (burnPositionUpdateValueAfterPositionFrame v I feeGrowthInside0X128 - feeGrowthInside1X128).locals (k := "liquidityNext") (a := "feeGrowthInside1X128") - (.int (Int.ofNat (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I)))).toNat)) - (by native_decide)] - rw [burnPositionUpdateValueAfterPositionFrame] - rw [store_get_ne (burnPositionUpdateValueStore I feeGrowthInside0X128 feeGrowthInside1X128) - (k := "position") (a := "feeGrowthInside1X128") - (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) - (by native_decide)] - exact burnPositionUpdateValueStore_feeGrowthInside1X128 I feeGrowthInside0X128 - feeGrowthInside1X128 - -theorem burnPositionUpdateValue_evalPositionLiquidityAfterLiquidityNext - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - evalExpr? (config v) - (burnPositionUpdateValueAfterLiquidityNextFrame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (.field (.var "position") "liquidity") = - .ok (.int (burnPositionUpdateSourceLiquidityInt σ I)) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [burnPositionUpdateValueAfterLiquidityNext_position (v := v) (σ := σ)] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? positionInfoStructTy (.field "liquidity") = some uint128St by - simp [storageTypeStep?, positionInfoStructTy, uint128St]] - change - readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnPositionUpdateEvaledRef I "liquidity") uint128St = - .ok (.int (burnPositionUpdateSourceLiquidityInt σ I)) - rw [show uint128St = .elem (.int uint128Int) by rfl] - rw [readStorage?_elem - (er := burnPositionUpdateEvaledRef I "liquidity") - (t := .int uint128Int) - (loc := loc (positionsBase (burnPositionKeyKey I)) ⟨0, by decide⟩ - ⟨16, by decide⟩ (by decide) (.int uint128Int))] - · exact congrArg EvalResult.ok (burnPositionUpdate_sourceLiquidityLoad - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g)) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, loc] - -theorem burnPositionUpdateValue_evalFeeGrowthInside0AfterLiquidityNext - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) : - evalExpr? (config v) - (burnPositionUpdateValueAfterLiquidityNextFrame v σ I (.int feeGrowthInside0X128) - (.int feeGrowthInside1X128)) - (initState cA gh bl σ σ₀ g A I) (.var "feeGrowthInside0X128") = - .ok (.int feeGrowthInside0X128) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [burnPositionUpdateValueAfterLiquidityNext_feeGrowthInside0X128 - (v := v) (σ := σ) (I := I)] - -theorem burnPositionUpdateValue_evalFeeGrowthInside1AfterLiquidityNext - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) : - evalExpr? (config v) - (burnPositionUpdateValueAfterLiquidityNextFrame v σ I (.int feeGrowthInside0X128) - (.int feeGrowthInside1X128)) - (initState cA gh bl σ σ₀ g A I) (.var "feeGrowthInside1X128") = - .ok (.int feeGrowthInside1X128) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [burnPositionUpdateValueAfterLiquidityNext_feeGrowthInside1X128 - (v := v) (σ := σ) (I := I)] - -theorem burnPositionUpdateValue_evalTokensOwed0AfterLiquidityNext - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) : - evalExpr? (config v) - (burnPositionUpdateValueAfterLiquidityNextFrame v σ I (.int feeGrowthInside0X128) - (.int feeGrowthInside1X128)) - (initState cA gh bl σ σ₀ g A I) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside0X128") - (.field (.var "position") "feeGrowthInside0LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)) = - .ok (.int (burnPositionUpdateSourceTokensOwed0Int σ I feeGrowthInside0X128)) := by - have hfee := - burnPositionUpdateValue_evalFeeGrowthInside0AfterLiquidityNext - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - have hlast := - burnPositionUpdateValue_evalFeeGrowthInside0LastAfterLiquidityNext - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (.int feeGrowthInside0X128) (.int feeGrowthInside1X128) - have hliq := - burnPositionUpdateValue_evalPositionLiquidityAfterLiquidityNext - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (.int feeGrowthInside0X128) (.int feeGrowthInside1X128) - simp [uint128Wrap, divE, mulE, wordSub, modE, subE, uint128Modulus, - fixedPoint128Q128, uint256Modulus, evalExpr?, EvalResult.bind, bind, pure, - hfee, hlast, hliq, evalBinaryOp?, - burnPositionUpdateSourceTokensOwed0Int, burnPositionUpdateSourceLiquidityInt, - burnPositionUpdateSourceFeeGrowthInside0LastInt, - burnWordSubInt] - -theorem burnPositionUpdateValue_evalTokensOwed1AfterLiquidityNext - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) : - evalExpr? (config v) - (burnPositionUpdateValueAfterLiquidityNextFrame v σ I (.int feeGrowthInside0X128) - (.int feeGrowthInside1X128)) - (initState cA gh bl σ σ₀ g A I) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside1X128") - (.field (.var "position") "feeGrowthInside1LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)) = - .ok (.int (burnPositionUpdateSourceTokensOwed1Int σ I feeGrowthInside1X128)) := by - have hfee := - burnPositionUpdateValue_evalFeeGrowthInside1AfterLiquidityNext - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - have hlast := - burnPositionUpdateValue_evalFeeGrowthInside1LastAfterLiquidityNext - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (.int feeGrowthInside0X128) (.int feeGrowthInside1X128) - have hliq := - burnPositionUpdateValue_evalPositionLiquidityAfterLiquidityNext - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (.int feeGrowthInside0X128) (.int feeGrowthInside1X128) - simp [uint128Wrap, divE, mulE, wordSub, modE, subE, uint128Modulus, - fixedPoint128Q128, uint256Modulus, evalExpr?, EvalResult.bind, bind, pure, - hfee, hlast, hliq, evalBinaryOp?, - burnPositionUpdateSourceTokensOwed1Int, burnPositionUpdateSourceLiquidityInt, - burnPositionUpdateSourceFeeGrowthInside1LastInt, - burnWordSubInt] - -abbrev burnPositionUpdateValueAfterTokensOwed0Frame - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) : Frame := - { contract := contract v, - locals := (burnPositionUpdateValueAfterLiquidityNextFrame v σ I - (.int feeGrowthInside0X128) (.int feeGrowthInside1X128)).locals.insert - "tokensOwed0" - (.int (burnPositionUpdateSourceTokensOwed0Int σ I feeGrowthInside0X128)) } - -abbrev burnPositionUpdateValueAfterTokensOwed1Frame - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) : Frame := - { contract := contract v, - locals := (burnPositionUpdateValueAfterTokensOwed0Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128).locals.insert "tokensOwed1" - (.int (burnPositionUpdateSourceTokensOwed1Int σ I feeGrowthInside1X128)) } - -theorem burnPositionUpdateValueAfterTokensOwed0_position - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) : - (burnPositionUpdateValueAfterTokensOwed0Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128).locals.get? "position" = - some (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) := by - rw [burnPositionUpdateValueAfterTokensOwed0Frame] - rw [store_get_ne (burnPositionUpdateValueAfterLiquidityNextFrame v σ I - (.int feeGrowthInside0X128) (.int feeGrowthInside1X128)).locals - (k := "tokensOwed0") (a := "position") - (.int (burnPositionUpdateSourceTokensOwed0Int σ I feeGrowthInside0X128)) - (by native_decide)] - exact burnPositionUpdateValueAfterLiquidityNext_position v σ I - (.int feeGrowthInside0X128) (.int feeGrowthInside1X128) - -theorem burnPositionUpdateValueAfterTokensOwed0_feeGrowthInside1X128 - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) : - (burnPositionUpdateValueAfterTokensOwed0Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128).locals.get? "feeGrowthInside1X128" = - some (.int feeGrowthInside1X128) := by - rw [burnPositionUpdateValueAfterTokensOwed0Frame] - rw [store_get_ne (burnPositionUpdateValueAfterLiquidityNextFrame v σ I - (.int feeGrowthInside0X128) (.int feeGrowthInside1X128)).locals - (k := "tokensOwed0") (a := "feeGrowthInside1X128") - (.int (burnPositionUpdateSourceTokensOwed0Int σ I feeGrowthInside0X128)) - (by native_decide)] - exact burnPositionUpdateValueAfterLiquidityNext_feeGrowthInside1X128 v σ I - (.int feeGrowthInside0X128) (.int feeGrowthInside1X128) - -theorem burnPositionUpdateValue_evalFeeGrowthInside1AfterTokensOwed0 - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed0Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) (.var "feeGrowthInside1X128") = - .ok (.int feeGrowthInside1X128) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [burnPositionUpdateValueAfterTokensOwed0_feeGrowthInside1X128 - (v := v) (σ := σ) (I := I)] - -theorem burnPositionUpdateValue_evalPositionLiquidityAfterTokensOwed0 - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed0Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (.field (.var "position") "liquidity") = - .ok (.int (burnPositionUpdateSourceLiquidityInt σ I)) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [burnPositionUpdateValueAfterTokensOwed0_position (v := v) (σ := σ)] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? positionInfoStructTy (.field "liquidity") = some uint128St by - simp [storageTypeStep?, positionInfoStructTy, uint128St]] - change - readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnPositionUpdateEvaledRef I "liquidity") uint128St = - .ok (.int (burnPositionUpdateSourceLiquidityInt σ I)) - rw [show uint128St = .elem (.int uint128Int) by rfl] - rw [readStorage?_elem - (er := burnPositionUpdateEvaledRef I "liquidity") - (t := .int uint128Int) - (loc := loc (positionsBase (burnPositionKeyKey I)) ⟨0, by decide⟩ - ⟨16, by decide⟩ (by decide) (.int uint128Int))] - · exact congrArg EvalResult.ok (burnPositionUpdate_sourceLiquidityLoad - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g)) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, loc] - -theorem burnPositionUpdateValue_evalFeeGrowthInside1LastAfterTokensOwed0 - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed0Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (.field (.var "position") "feeGrowthInside1LastX128") = - .ok (.int (burnPositionUpdateSourceFeeGrowthInside1LastInt σ I)) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [burnPositionUpdateValueAfterTokensOwed0_position (v := v) (σ := σ)] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? positionInfoStructTy (.field "feeGrowthInside1LastX128") = - some uint256St by simp [storageTypeStep?, positionInfoStructTy, uint256St]] - change - readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnPositionUpdateEvaledRef I "feeGrowthInside1LastX128") uint256St = - .ok (.int (burnPositionUpdateSourceFeeGrowthInside1LastInt σ I)) - rw [show uint256St = .elem (.int uint256Int) by rfl] - rw [readStorage?_elem - (er := burnPositionUpdateEvaledRef I "feeGrowthInside1LastX128") - (t := .int uint256Int) - (loc := loc (positionsBase (burnPositionKeyKey I) + ⟨2⟩) ⟨0, by decide⟩ - ⟨32, by decide⟩ (by decide) (.int uint256Int))] - · simpa [initState, solcSlotWord, burnPositionUpdateSourceFeeGrowthInside1LastInt] - using burnPositionUpdateStorageLocLoad_feeGrowthInside1Last - (initState cA gh bl σ σ₀ g A I) (positionsBase (burnPositionKeyKey I)) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, loc] - -theorem burnPositionUpdateValue_evalTokensOwed1AfterTokensOwed0 - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed0Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside1X128") - (.field (.var "position") "feeGrowthInside1LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)) = - .ok (.int (burnPositionUpdateSourceTokensOwed1Int σ I feeGrowthInside1X128)) := by - have hfee := - burnPositionUpdateValue_evalFeeGrowthInside1AfterTokensOwed0 - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - have hlast := - burnPositionUpdateValue_evalFeeGrowthInside1LastAfterTokensOwed0 - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - have hliq := - burnPositionUpdateValue_evalPositionLiquidityAfterTokensOwed0 - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - simp [uint128Wrap, divE, mulE, wordSub, modE, subE, uint128Modulus, - fixedPoint128Q128, uint256Modulus, evalExpr?, EvalResult.bind, bind, pure, - hfee, hlast, hliq, evalBinaryOp?, - burnPositionUpdateSourceTokensOwed1Int, burnPositionUpdateSourceLiquidityInt, - burnPositionUpdateSourceFeeGrowthInside1LastInt, - burnWordSubInt] - -theorem burnPositionUpdateValueAfterLiquidityNext_liquidityDelta - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Value) : - (burnPositionUpdateValueAfterLiquidityNextFrame v σ I feeGrowthInside0X128 - feeGrowthInside1X128).locals.get? "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnPositionUpdateValueAfterLiquidityNextFrame] - rw [store_get_ne (burnPositionUpdateValueAfterPositionFrame v I feeGrowthInside0X128 - feeGrowthInside1X128).locals (k := "liquidityNext") (a := "liquidityDelta") - (.int (Int.ofNat (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I)))).toNat)) - (by native_decide)] - exact burnPositionUpdateValueAfterPosition_liquidityDelta v I feeGrowthInside0X128 - feeGrowthInside1X128 - -theorem burnPositionUpdateValueAfterTokensOwed1_liquidityDelta - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) : - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128).locals.get? "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnPositionUpdateValueAfterTokensOwed1Frame] - rw [store_get_ne (burnPositionUpdateValueAfterTokensOwed0Frame v σ I - feeGrowthInside0X128 feeGrowthInside1X128).locals - (k := "tokensOwed1") (a := "liquidityDelta") - (.int (burnPositionUpdateSourceTokensOwed1Int σ I feeGrowthInside1X128)) - (by native_decide)] - rw [burnPositionUpdateValueAfterTokensOwed0Frame] - rw [store_get_ne (burnPositionUpdateValueAfterLiquidityNextFrame v σ I - (.int feeGrowthInside0X128) (.int feeGrowthInside1X128)).locals - (k := "tokensOwed0") (a := "liquidityDelta") - (.int (burnPositionUpdateSourceTokensOwed0Int σ I feeGrowthInside0X128)) - (by native_decide)] - exact burnPositionUpdateValueAfterLiquidityNext_liquidityDelta v σ I - (.int feeGrowthInside0X128) (.int feeGrowthInside1X128) - -theorem burnPositionUpdateValue_evalLiquidityDeltaNeZeroFalseAfterTokensOwed1 - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) - (hzero : burnAmountCleanWord I = ⟨0⟩) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - (neE (.var "liquidityDelta") (.intLit 0)) = .ok (.bool false) := by - simp only [neE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPositionUpdateValueAfterTokensOwed1_liquidityDelta (v := v) (σ := σ)] - simp [EvalResult.ofOption, burnLiquidityDeltaValue, hzero, evalBinaryOp?] - -theorem uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwed0PrefixValue - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) : - ExecBlock (config v) - (burnPositionUpdateValueFrame v I (.int feeGrowthInside0X128) - (.int feeGrowthInside1X128)) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "position" (positionsRef (.var "positionKey")), - Stmt.ite (eqE (.var "liquidityDelta") (.intLit 0)) - [ .require (gtE (.field (.var "position") "liquidity") (.intLit 0)), - .letDecl "liquidityNext" (some uint128) - (.field (.var "position") "liquidity") ] - [ .internalCall "liquidityAddDelta" - [.field (.var "position") "liquidity", .var "liquidityDelta"] - "liquidityNext" ], - .letDecl "tokensOwed0" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside0X128") - (.field (.var "position") "feeGrowthInside0LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)) ] - (ExecResult.ok - (burnPositionUpdateValueAfterTokensOwed0Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := - uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroPrefixValue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (.int feeGrowthInside0X128) (.int feeGrowthInside1X128) - hzero hliq - have htail : - ExecBlock (config v) - (burnPositionUpdateValueAfterLiquidityNextFrame v σ I - (.int feeGrowthInside0X128) (.int feeGrowthInside1X128)) - (initState cA gh bl σ σ₀ g A I) - [ .letDecl "tokensOwed0" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside0X128") - (.field (.var "position") "feeGrowthInside0LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)) ] - (ExecResult.ok - (burnPositionUpdateValueAfterTokensOwed0Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecBlock.consNormal - (ExecStmt.letDecl - (burnPositionUpdateValue_evalTokensOwed0AfterLiquidityNext - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128)) - ExecBlock.nil - simpa using execBlock_append hprefix htail - -theorem uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedPrefixValue - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) : - ExecBlock (config v) - (burnPositionUpdateValueFrame v I (.int feeGrowthInside0X128) - (.int feeGrowthInside1X128)) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "position" (positionsRef (.var "positionKey")), - Stmt.ite (eqE (.var "liquidityDelta") (.intLit 0)) - [ .require (gtE (.field (.var "position") "liquidity") (.intLit 0)), - .letDecl "liquidityNext" (some uint128) - (.field (.var "position") "liquidity") ] - [ .internalCall "liquidityAddDelta" - [.field (.var "position") "liquidity", .var "liquidityDelta"] - "liquidityNext" ], - .letDecl "tokensOwed0" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside0X128") - (.field (.var "position") "feeGrowthInside0LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)), - .letDecl "tokensOwed1" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside1X128") - (.field (.var "position") "feeGrowthInside1LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)) ] - (ExecResult.ok - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := - uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwed0PrefixValue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 hzero hliq - have htail : - ExecBlock (config v) - (burnPositionUpdateValueAfterTokensOwed0Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - [ .letDecl "tokensOwed1" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside1X128") - (.field (.var "position") "feeGrowthInside1LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)) ] - (ExecResult.ok - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecBlock.consNormal - (ExecStmt.letDecl - (burnPositionUpdateValue_evalTokensOwed1AfterTokensOwed0 - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128)) - ExecBlock.nil - simpa using execBlock_append hprefix htail - -theorem uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroLiquiditySkipPrefixValue - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : Int) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) : - ExecBlock (config v) - (burnPositionUpdateValueFrame v I (.int feeGrowthInside0X128) - (.int feeGrowthInside1X128)) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "position" (positionsRef (.var "positionKey")), - Stmt.ite (eqE (.var "liquidityDelta") (.intLit 0)) - [ .require (gtE (.field (.var "position") "liquidity") (.intLit 0)), - .letDecl "liquidityNext" (some uint128) - (.field (.var "position") "liquidity") ] - [ .internalCall "liquidityAddDelta" - [.field (.var "position") "liquidity", .var "liquidityDelta"] - "liquidityNext" ], - .letDecl "tokensOwed0" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside0X128") - (.field (.var "position") "feeGrowthInside0LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)), - .letDecl "tokensOwed1" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside1X128") - (.field (.var "position") "feeGrowthInside1LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)), - Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ .assign .storage { base := "position", steps := [.field "liquidity"] } - (.var "liquidityNext") ] - [] ] - (ExecResult.ok - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := - uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedPrefixValue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 hzero hliq - have htail : - ExecBlock (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I) - [ Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ .assign .storage { base := "position", steps := [.field "liquidity"] } - (.var "liquidityNext") ] - [] ] - (ExecResult.ok - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I feeGrowthInside0X128 - feeGrowthInside1X128) - (initState cA gh bl σ σ₀ g A I)) := by - refine ExecBlock.consNormal (ExecStmt.iteFalse - (burnPositionUpdateValue_evalLiquidityDeltaNeZeroFalseAfterTokensOwed1 - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 hzero) - ?_) ExecBlock.nil - exact ExecBlock.nil - simpa using execBlock_append hprefix htail - -theorem burnPositionUpdateValueAfterTokensOwed1_position - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)).locals.get? - "position" = - some (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) := by - rw [burnPositionUpdateValueAfterTokensOwed1Frame] - rw [store_get_ne (burnPositionUpdateValueAfterTokensOwed0Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)).locals - (k := "tokensOwed1") (a := "position") - (.int (burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat))) (by native_decide)] - exact burnPositionUpdateValueAfterTokensOwed0_position v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat) - -theorem burnPositionUpdateValueAfterTokensOwed1_feeGrowthInside0X128 - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)).locals.get? - "feeGrowthInside0X128" = - some (.int (Int.ofNat feeGrowthInside0X128.toNat)) := by - rw [burnPositionUpdateValueAfterTokensOwed1Frame] - rw [store_get_ne (burnPositionUpdateValueAfterTokensOwed0Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)).locals - (k := "tokensOwed1") (a := "feeGrowthInside0X128") - (.int (burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat))) (by native_decide)] - rw [burnPositionUpdateValueAfterTokensOwed0Frame] - rw [store_get_ne (burnPositionUpdateValueAfterLiquidityNextFrame v σ I - (.int (Int.ofNat feeGrowthInside0X128.toNat)) - (.int (Int.ofNat feeGrowthInside1X128.toNat))).locals - (k := "tokensOwed0") (a := "feeGrowthInside0X128") - (.int (burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat))) (by native_decide)] - rw [burnPositionUpdateValueAfterLiquidityNext_feeGrowthInside0X128] - -theorem burnPositionUpdateValueAfterTokensOwed1_feeGrowthInside1X128 - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)).locals.get? - "feeGrowthInside1X128" = - some (.int (Int.ofNat feeGrowthInside1X128.toNat)) := by - rw [burnPositionUpdateValueAfterTokensOwed1Frame] - rw [store_get_ne (burnPositionUpdateValueAfterTokensOwed0Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)).locals - (k := "tokensOwed1") (a := "feeGrowthInside1X128") - (.int (burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat))) (by native_decide)] - exact burnPositionUpdateValueAfterTokensOwed0_feeGrowthInside1X128 v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat) - -theorem burnPositionUpdateValue_evalFeeGrowthInside0AfterTokensOwed1 - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm (.var "feeGrowthInside0X128") = - .ok (.int (Int.ofNat feeGrowthInside0X128.toNat)) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [burnPositionUpdateValueAfterTokensOwed1_feeGrowthInside0X128 - (v := v) (σ := σ) (I := I)] - -theorem burnPositionUpdateValue_evalFeeGrowthInside1AfterTokensOwed1 - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm (.var "feeGrowthInside1X128") = - .ok (.int (Int.ofNat feeGrowthInside1X128.toNat)) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [burnPositionUpdateValueAfterTokensOwed1_feeGrowthInside1X128 - (v := v) (σ := σ) (I := I)] - -theorem burnPositionUpdateValue_resolveFeeGrowthInside0LastAfterTokensOwed1 - {v : PoolImmutables} {evm : EVM.State} {σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - resolveStorageRef? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm { base := "position", steps := [.field "feeGrowthInside0LastX128"] } = - .ok (burnPositionUpdateEvaledRef I "feeGrowthInside0LastX128", uint256St) := by - rw [resolveStorageRef?] - rw [burnPositionUpdateValueAfterTokensOwed1_position] - simp [evalStorageRefFrom?, evalStorageRefStep, EvalResult.bind, EvalResult.ofOption, bind, - pure, burnPositionUpdateEvaledRef, burnPositionUpdateEvaledBaseRef, uint256St, - storageTypeStep?, positionInfoStructTy] - -theorem burnPositionUpdateValue_resolveFeeGrowthInside1LastAfterTokensOwed1 - {v : PoolImmutables} {evm : EVM.State} {σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - resolveStorageRef? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm { base := "position", steps := [.field "feeGrowthInside1LastX128"] } = - .ok (burnPositionUpdateEvaledRef I "feeGrowthInside1LastX128", uint256St) := by - rw [resolveStorageRef?] - rw [burnPositionUpdateValueAfterTokensOwed1_position] - simp [evalStorageRefFrom?, evalStorageRefStep, EvalResult.bind, EvalResult.ofOption, bind, - pure, burnPositionUpdateEvaledRef, burnPositionUpdateEvaledBaseRef, uint256St, - storageTypeStep?, positionInfoStructTy] - -theorem burnPositionUpdateValue_assignFeeGrowthInside0LastAfterTokensOwed1 - {v : PoolImmutables} {evm : EVM.State} {σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - assignStorageRef? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm .storage { base := "position", steps := [.field "feeGrowthInside0LastX128"] } - (.int (Int.ofNat feeGrowthInside0X128.toNat)) = - .ok ((burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)), - Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) := by - rw [assignStorageRef?] - rw [burnPositionUpdateValue_resolveFeeGrowthInside0LastAfterTokensOwed1] - simp only [EvalResult.bind, bind, EvalResult.ofOption, pure] - rw [show (config v).storage.layout (burnPositionUpdateEvaledRef I - "feeGrowthInside0LastX128") = - fun _ => some (loc (positionsBase (burnPositionKeyKey I) + ⟨1⟩) ⟨0, by decide⟩ - ⟨32, by decide⟩ (by decide) (.int uint256Int)) by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, loc]] - simp only [EvalResult.bind, bind, EvalResult.ofOption, pure] - have hstore : - storageLocStore evm - (loc (positionsBase (burnPositionKeyKey I) + ⟨1⟩) ⟨0, by decide⟩ - ⟨32, by decide⟩ (by decide) (.int uint256Int)) - (.int (Int.ofNat feeGrowthInside0X128.toNat)) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) := by - simpa [loc, uint256Loc] using - storageLocStore_uint256 evm (positionsBase (burnPositionKeyKey I) + ⟨1⟩) - feeGrowthInside0X128 - rw [hstore] - -theorem burnPositionUpdateValue_assignFeeGrowthInside1LastAfterTokensOwed1 - {v : PoolImmutables} {evm : EVM.State} {σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - assignStorageRef? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm .storage { base := "position", steps := [.field "feeGrowthInside1LastX128"] } - (.int (Int.ofNat feeGrowthInside1X128.toNat)) = - .ok ((burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)), - Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨2⟩) feeGrowthInside1X128) := by - rw [assignStorageRef?] - rw [burnPositionUpdateValue_resolveFeeGrowthInside1LastAfterTokensOwed1] - simp only [EvalResult.bind, bind, EvalResult.ofOption, pure] - rw [show (config v).storage.layout (burnPositionUpdateEvaledRef I - "feeGrowthInside1LastX128") = - fun _ => some (loc (positionsBase (burnPositionKeyKey I) + ⟨2⟩) ⟨0, by decide⟩ - ⟨32, by decide⟩ (by decide) (.int uint256Int)) by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, loc]] - simp only [EvalResult.bind, bind, EvalResult.ofOption, pure] - have hstore : - storageLocStore evm - (loc (positionsBase (burnPositionKeyKey I) + ⟨2⟩) ⟨0, by decide⟩ - ⟨32, by decide⟩ (by decide) (.int uint256Int)) - (.int (Int.ofNat feeGrowthInside1X128.toNat)) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨2⟩) feeGrowthInside1X128) := by - simpa [loc, uint256Loc] using - storageLocStore_uint256 evm (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128 - rw [hstore] - -theorem uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroFeeGrowthLastTailValue - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - ExecBlock (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (initState cA gh bl σ σ₀ g A I) - [ .assign .storage { base := "position", steps := [.field "feeGrowthInside0LastX128"] } - (.var "feeGrowthInside0X128"), - .assign .storage { base := "position", steps := [.field "feeGrowthInside1LastX128"] } - (.var "feeGrowthInside1X128") ] - (ExecResult.ok - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128)) := by - let frame := burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat) - let evm0 := initState cA gh bl σ σ₀ g A I - let evm1 := Solm.EVM.storageStore evm0 evm0.executionEnv.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128 - let evm2 := Solm.EVM.storageStore evm1 evm1.executionEnv.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨2⟩) feeGrowthInside1X128 - have hassign0 : - assignStorageRef? (config v) frame evm0 .storage - { base := "position", steps := [.field "feeGrowthInside0LastX128"] } - (.int (Int.ofNat feeGrowthInside0X128.toNat)) = .ok (frame, evm1) := by - simpa [frame, evm0, evm1] using - burnPositionUpdateValue_assignFeeGrowthInside0LastAfterTokensOwed1 - (v := v) (evm := evm0) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128 - have hstep0 : - ExecStmt (config v) frame evm0 - (.assign .storage { base := "position", steps := [.field "feeGrowthInside0LastX128"] } - (.var "feeGrowthInside0X128")) (.ok frame evm1) := by - exact ExecStmt.assign - (burnPositionUpdateValue_evalFeeGrowthInside0AfterTokensOwed1 - (v := v) (evm := evm0) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128) - hassign0 - have hassign1 : - assignStorageRef? (config v) frame evm1 .storage - { base := "position", steps := [.field "feeGrowthInside1LastX128"] } - (.int (Int.ofNat feeGrowthInside1X128.toNat)) = .ok (frame, evm2) := by - simpa [frame, evm1, evm2] using - burnPositionUpdateValue_assignFeeGrowthInside1LastAfterTokensOwed1 - (v := v) (evm := evm1) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128 - have hstep1 : - ExecStmt (config v) frame evm1 - (.assign .storage { base := "position", steps := [.field "feeGrowthInside1LastX128"] } - (.var "feeGrowthInside1X128")) (.ok frame evm2) := by - exact ExecStmt.assign - (burnPositionUpdateValue_evalFeeGrowthInside1AfterTokensOwed1 - (v := v) (evm := evm1) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128) - hassign1 - simpa [frame, evm0, evm1, evm2, initState, storageStore_executionEnv] using - ExecBlock.consNormal hstep0 (ExecBlock.consNormal hstep1 ExecBlock.nil) - -theorem uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroFeeGrowthLastPrefixValue - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) : - ExecBlock (config v) - (burnPositionUpdateValueFrame v I (.int (Int.ofNat feeGrowthInside0X128.toNat)) - (.int (Int.ofNat feeGrowthInside1X128.toNat))) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "position" (positionsRef (.var "positionKey")), - Stmt.ite (eqE (.var "liquidityDelta") (.intLit 0)) - [ .require (gtE (.field (.var "position") "liquidity") (.intLit 0)), - .letDecl "liquidityNext" (some uint128) - (.field (.var "position") "liquidity") ] - [ .internalCall "liquidityAddDelta" - [.field (.var "position") "liquidity", .var "liquidityDelta"] - "liquidityNext" ], - .letDecl "tokensOwed0" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside0X128") - (.field (.var "position") "feeGrowthInside0LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)), - .letDecl "tokensOwed1" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside1X128") - (.field (.var "position") "feeGrowthInside1LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)), - Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ .assign .storage { base := "position", steps := [.field "liquidity"] } - (.var "liquidityNext") ] - [], - .assign .storage { base := "position", steps := [.field "feeGrowthInside0LastX128"] } - (.var "feeGrowthInside0X128"), - .assign .storage { base := "position", steps := [.field "feeGrowthInside1LastX128"] } - (.var "feeGrowthInside1X128") ] - (ExecResult.ok - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128)) := by - have hprefix := - uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroLiquiditySkipPrefixValue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (Int.ofNat feeGrowthInside0X128.toNat) - (Int.ofNat feeGrowthInside1X128.toNat) hzero hliq - have htail := - uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroFeeGrowthLastTailValue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - simpa using execBlock_append hprefix htail - -theorem burnPositionUpdateValueAfterTokensOwed1_tokensOwed0 - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)).locals.get? - "tokensOwed0" = - some (.int (burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat))) := by - rw [burnPositionUpdateValueAfterTokensOwed1Frame] - rw [store_get_ne (burnPositionUpdateValueAfterTokensOwed0Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)).locals - (k := "tokensOwed1") (a := "tokensOwed0") - (.int (burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat))) (by native_decide)] - rw [burnPositionUpdateValueAfterTokensOwed0Frame] - exact store_get_self (burnPositionUpdateValueAfterLiquidityNextFrame v σ I - (.int (Int.ofNat feeGrowthInside0X128.toNat)) - (.int (Int.ofNat feeGrowthInside1X128.toNat))).locals "tokensOwed0" - (.int (burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat))) - -theorem burnPositionUpdateValueAfterTokensOwed1_tokensOwed1 - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)).locals.get? - "tokensOwed1" = - some (.int (burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat))) := by - rw [burnPositionUpdateValueAfterTokensOwed1Frame] - exact store_get_self (burnPositionUpdateValueAfterTokensOwed0Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)).locals - "tokensOwed1" - (.int (burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat))) - -theorem burnPositionUpdateValue_evalTokensOwedGtFalseAfterTokensOwed1 - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (htokens0 : - burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat) = 0) - (htokens1 : - burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat) = 0) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm - (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) = .ok (.bool false) := by - have hgt0 : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm (gtE (.var "tokensOwed0") (.intLit 0)) = .ok (.bool false) := by - simp only [gtE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPositionUpdateValueAfterTokensOwed1_tokensOwed0 (v := v) (σ := σ) (I := I)] - rw [htokens0] - native_decide - have hgt1 : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm (gtE (.var "tokensOwed1") (.intLit 0)) = .ok (.bool false) := by - simp only [gtE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPositionUpdateValueAfterTokensOwed1_tokensOwed1 (v := v) (σ := σ) (I := I)] - rw [htokens1] - native_decide - simp only [orE, evalExpr?, EvalResult.bind, bind, pure] - rw [hgt0] - rw [hgt1] - -theorem burnPositionUpdateValue_evalTokensOwedGtTrueAfterTokensOwed1_left - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (htokens0 : - 0 < burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat)) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm - (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) = .ok (.bool true) := by - have hgt0 : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm (gtE (.var "tokensOwed0") (.intLit 0)) = .ok (.bool true) := by - simp only [gtE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPositionUpdateValueAfterTokensOwed1_tokensOwed0 (v := v) (σ := σ) (I := I)] - simp only [evalBinaryOp?] - exact congrArg (fun b => EvalResult.ok (Value.bool b)) (decide_eq_true htokens0) - simp only [orE, evalExpr?, EvalResult.bind, bind, pure] - rw [hgt0] - -theorem burnPositionUpdateValue_evalTokensOwedGtTrueAfterTokensOwed1_right - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (htokens0 : - burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat) = 0) - (htokens1 : - 0 < burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat)) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm - (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) = .ok (.bool true) := by - have hgt0 : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm (gtE (.var "tokensOwed0") (.intLit 0)) = .ok (.bool false) := by - simp only [gtE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPositionUpdateValueAfterTokensOwed1_tokensOwed0 (v := v) (σ := σ) (I := I)] - rw [htokens0] - native_decide - have hgt1 : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm (gtE (.var "tokensOwed1") (.intLit 0)) = .ok (.bool true) := by - simp only [gtE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPositionUpdateValueAfterTokensOwed1_tokensOwed1 (v := v) (σ := σ) (I := I)] - simp only [evalBinaryOp?] - exact congrArg (fun b => EvalResult.ok (Value.bool b)) (decide_eq_true htokens1) - simp only [orE, evalExpr?, EvalResult.bind, bind, pure] - rw [hgt0] - rw [hgt1] - -theorem burnPositionUpdateValue_resolveTokensOwed0AfterTokensOwed1 - {v : PoolImmutables} {evm : EVM.State} {σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - resolveStorageRef? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm { base := "position", steps := [.field "tokensOwed0"] } = - .ok (burnPositionUpdateEvaledRef I "tokensOwed0", uint128St) := by - rw [resolveStorageRef?] - rw [burnPositionUpdateValueAfterTokensOwed1_position] - simp [evalStorageRefFrom?, evalStorageRefStep, EvalResult.bind, EvalResult.ofOption, bind, - pure, burnPositionUpdateEvaledRef, burnPositionUpdateEvaledBaseRef, uint128St, - storageTypeStep?, positionInfoStructTy] - -theorem burnPositionUpdateValue_resolveTokensOwed1AfterTokensOwed1 - {v : PoolImmutables} {evm : EVM.State} {σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - resolveStorageRef? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm { base := "position", steps := [.field "tokensOwed1"] } = - .ok (burnPositionUpdateEvaledRef I "tokensOwed1", uint128St) := by - rw [resolveStorageRef?] - rw [burnPositionUpdateValueAfterTokensOwed1_position] - simp [evalStorageRefFrom?, evalStorageRefStep, EvalResult.bind, EvalResult.ofOption, bind, - pure, burnPositionUpdateEvaledRef, burnPositionUpdateEvaledBaseRef, uint128St, - storageTypeStep?, positionInfoStructTy] - -theorem burnPositionUpdateStorageLocLoad_tokensOwed0 - (evm : EVM.State) (base : UInt256) : - storageLocLoad evm - (loc (base + ⟨3⟩) ⟨0, by decide⟩ ⟨16, by decide⟩ (by decide) - (.int uint128Int)) = - .int (Int.ofNat (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (base + ⟨3⟩)) - uint128Mask).toNat) := by - rw [← show UInt256.ofNat (2 ^ (8 * 16) - 1) = uint128Mask by native_decide] - simpa [loc, uint128Int] using - storageLocLoad_uint_offset0 evm (base + ⟨3⟩) (16 : Fin 33) ⟨128, by decide⟩ - (hbound := by decide) (by decide) - -theorem burnPositionUpdateStorageLocLoad_tokensOwed1 - (evm : EVM.State) (base : UInt256) : - storageLocLoad evm - (loc (base + ⟨3⟩) ⟨16, by decide⟩ ⟨16, by decide⟩ (by decide) - (.int uint128Int)) = - .int (Int.ofNat (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (base + ⟨3⟩)) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) uint128Mask).toNat) := by - rw [← show UInt256.ofNat ((256 : Nat) ^ (16 : Nat)) = - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ by native_decide] - rw [← show UInt256.ofNat ((256 : Nat) ^ (16 : Nat) - 1) = uint128Mask by native_decide] - simpa [loc, uint128Int] using - storageLocLoad_uint_offset evm (base + ⟨3⟩) (16 : Fin 32) (16 : Fin 33) - ⟨128, by decide⟩ (by decide) (by decide) - -private theorem burnPositionUpdateLow128_insert_toNat (low old : UInt256) - (hlow : low.toNat < 2 ^ 128) : - (UInt256.lor low (UInt256.land (UInt256.lnot uint128Mask) old)).toNat = - low.toNat + old.toNat / 2 ^ 128 * 2 ^ 128 := by - rw [u256_lor_toNat] - have hclearMask : - UInt256.lnot uint128Mask = UInt256.ofNat ((2 : Nat) ^ 256 - 2 ^ 128) := by - native_decide - have hhigh : - (UInt256.land (UInt256.lnot uint128Mask) old).toNat = - old.toNat / 2 ^ 128 * 2 ^ 128 := by - rw [hclearMask] - exact u256_land_high_mask_toNat old 128 (by norm_num) - have hq : old.toNat / 2 ^ 128 < 2 ^ 128 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 128 * 2 ^ 128 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - simp [UInt256.size] - have hlorLt : - Nat.lor low.toNat ((UInt256.land (UInt256.lnot uint128Mask) old).toNat) < - UInt256.size := by - rw [hhigh] - rw [nat_lor_shift_add low.toNat (old.toNat / 2 ^ 128) 128 hlow] - have hqle : old.toNat / 2 ^ 128 ≤ 2 ^ 128 - 1 := Nat.le_pred_of_lt hq - have hprod : (old.toNat / 2 ^ 128) * 2 ^ 128 ≤ (2 ^ 128 - 1) * 2 ^ 128 := - Nat.mul_le_mul_right _ hqle - norm_num [UInt256.size, Nat.pow_add] at hprod ⊢ - omega - rw [Nat.mod_eq_of_lt hlorLt] - rw [hhigh] - exact nat_lor_shift_add low.toNat (old.toNat / 2 ^ 128) 128 hlow - -private theorem burnPositionUpdateHigh128_insert_toNat (low old : UInt256) - (hlow : low.toNat < 2 ^ 128) : - (UInt256.lor (UInt256.mul low (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (UInt256.land old uint128Mask)).toNat = - (UInt256.land old uint128Mask).toNat + low.toNat * 2 ^ 128 := by - rw [u256_lor_toNat, u256_mul_toNat] - have hshift : (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩).toNat = 2 ^ 128 := by - native_decide - rw [hshift] - have hprodLt : low.toNat * 2 ^ 128 < UInt256.size := by - have hlowle : low.toNat ≤ 2 ^ 128 - 1 := Nat.le_pred_of_lt hlow - have hprod : low.toNat * 2 ^ 128 ≤ (2 ^ 128 - 1) * 2 ^ 128 := - Nat.mul_le_mul_right _ hlowle - norm_num [UInt256.size, Nat.pow_add] at hprod ⊢ - omega - rw [Nat.mod_eq_of_lt hprodLt] - have hlowOldLt : (UInt256.land old uint128Mask).toNat < 2 ^ 128 := by - simpa using uint128Mask_bound old - have hlorLt : - Nat.lor (low.toNat * 2 ^ 128) (UInt256.land old uint128Mask).toNat < - UInt256.size := by - rw [nat_lor_comm] - rw [nat_lor_shift_add (UInt256.land old uint128Mask).toNat low.toNat 128 hlowOldLt] - have hlowOldLe : (UInt256.land old uint128Mask).toNat ≤ 2 ^ 128 - 1 := - Nat.le_pred_of_lt hlowOldLt - have hlowLe : low.toNat ≤ 2 ^ 128 - 1 := Nat.le_pred_of_lt hlow - have hprod : low.toNat * 2 ^ 128 ≤ (2 ^ 128 - 1) * 2 ^ 128 := - Nat.mul_le_mul_right _ hlowLe - have hmax : (2 ^ 128 - 1) + (2 ^ 128 - 1) * 2 ^ 128 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - rw [Nat.mod_eq_of_lt hlorLt] - rw [nat_lor_comm] - rw [nat_lor_shift_add (UInt256.land old uint128Mask).toNat low.toNat 128 hlowOldLt] - -theorem burnPositionUpdateStorageLocStore_tokensOwed0 - (evm : EVM.State) (slot : UInt256) (n : Int) : - storageLocStore evm - (loc slot ⟨0, by decide⟩ ⟨16, by decide⟩ (by decide) (.int uint128Int)) - (.int n) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner slot - (UInt256.lor - (UInt256.land (EVM.wordOfInt n) uint128Mask) - (UInt256.land (UInt256.lnot uint128Mask) - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)))) := by - unfold storageLocStore storageLocWriteWord loc - simp only [valueToWord, bind, Option.bind] - congr 2 - apply u256_inj - let old := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot - let low := UInt256.land (EVM.wordOfInt n) uint128Mask - show fromBytes' - (List.take 0 ↑(EVM.Word.toBytesLEWithSizeProof old) ++ - List.take 16 ↑(EVM.Word.toBytesLEWithSizeProof (EVM.wordOfInt n)) ++ - List.drop (0 + 16) ↑(EVM.Word.toBytesLEWithSizeProof old)) = - (UInt256.lor low (UInt256.land (UInt256.lnot uint128Mask) old)).toNat - rw [List.take_zero, List.nil_append] - rw [fromBytes'_append, fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [show 256 ^ (16 : Nat) = 2 ^ 128 by norm_num [Nat.pow_add]] - have hlen16 : - (List.take 16 (EVM.Word.toBytesLEWithSizeProof (EVM.wordOfInt n)).1).length = 16 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof (EVM.wordOfInt n)).2] - norm_num - rw [hlen16] - rw [show 2 ^ (8 * 16) = 2 ^ 128 by norm_num] - rw [burnPositionUpdateLow128_insert_toNat low old] - · dsimp [low] - rw [u256_land_toNat, uint128Mask_toNat, nat_land_mask_eq_mod] - rw [Nat.mod_eq_of_lt - (lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 128)) (by norm_num [UInt256.size]))] - ring_nf - · dsimp [low] - simpa using uint128Mask_bound (EVM.wordOfInt n) - -theorem burnPositionUpdateStorageLocStore_tokensOwed1 - (evm : EVM.State) (slot : UInt256) (n : Int) : - storageLocStore evm - (loc slot ⟨16, by decide⟩ ⟨16, by decide⟩ (by decide) (.int uint128Int)) - (.int n) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner slot - (UInt256.lor - (UInt256.mul (UInt256.land (EVM.wordOfInt n) uint128Mask) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (UInt256.land (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) - uint128Mask))) := by - unfold storageLocStore storageLocWriteWord loc - simp only [valueToWord, bind, Option.bind] - congr 2 - apply u256_inj - let old := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot - let low := UInt256.land (EVM.wordOfInt n) uint128Mask - show fromBytes' - (List.take 16 ↑(EVM.Word.toBytesLEWithSizeProof old) ++ - List.take 16 ↑(EVM.Word.toBytesLEWithSizeProof (EVM.wordOfInt n)) ++ - List.drop (16 + 16) ↑(EVM.Word.toBytesLEWithSizeProof old)) = - (UInt256.lor (UInt256.mul low (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (UInt256.land old uint128Mask)).toNat - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [show 256 ^ (16 : Nat) = 2 ^ 128 by norm_num [Nat.pow_add]] - rw [show 256 ^ (32 : Nat) = 2 ^ 256 by norm_num [Nat.pow_add]] - have hlen16old : - (List.take 16 (EVM.Word.toBytesLEWithSizeProof old).1).length = 16 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof old).2] - norm_num - have hlen16val : - (List.take 16 (EVM.Word.toBytesLEWithSizeProof (EVM.wordOfInt n)).1).length = 16 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof (EVM.wordOfInt n)).2] - norm_num - have hlen32 : - (List.take 16 (EVM.Word.toBytesLEWithSizeProof old).1 ++ - List.take 16 (EVM.Word.toBytesLEWithSizeProof (EVM.wordOfInt n)).1).length = 32 := by - rw [List.length_append, hlen16old, hlen16val] - rw [hlen16old, hlen32] - rw [show old.toNat / 2 ^ 256 = 0 by exact Nat.div_eq_of_lt old.val.isLt] - rw [show 2 ^ (8 * 16) = 2 ^ 128 by norm_num] - rw [burnPositionUpdateHigh128_insert_toNat low old] - rw [show (UInt256.land old uint128Mask).toNat = old.toNat % 2 ^ 128 by - rw [u256_land_toNat, uint128Mask_toNat, nat_land_mask_eq_mod] - exact Nat.mod_eq_of_lt - (lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 128)) (by norm_num [UInt256.size]))] - · dsimp [low] - rw [u256_land_toNat, uint128Mask_toNat, nat_land_mask_eq_mod] - rw [Nat.mod_eq_of_lt - (lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 128)) (by norm_num [UInt256.size]))] - ring_nf - · dsimp [low] - simpa using uint128Mask_bound (EVM.wordOfInt n) - -theorem burnPositionUpdateValue_evalPositionTokensOwed0AfterTokensOwed1 - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm (.field (.var "position") "tokensOwed0") = - .ok (.int (Int.ofNat (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨3⟩)) - uint128Mask).toNat)) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [burnPositionUpdateValueAfterTokensOwed1_position (v := v) (σ := σ)] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? positionInfoStructTy (.field "tokensOwed0") = some uint128St by - simp [storageTypeStep?, positionInfoStructTy, uint128St]] - change - readStorage? (config v) evm (burnPositionUpdateEvaledRef I "tokensOwed0") uint128St = - .ok (.int (Int.ofNat (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨3⟩)) - uint128Mask).toNat)) - rw [show uint128St = .elem (.int uint128Int) by rfl] - rw [readStorage?_elem - (er := burnPositionUpdateEvaledRef I "tokensOwed0") - (t := .int uint128Int) - (loc := loc (positionsBase (burnPositionKeyKey I) + ⟨3⟩) ⟨0, by decide⟩ - ⟨16, by decide⟩ (by decide) (.int uint128Int))] - · exact congrArg EvalResult.ok - (burnPositionUpdateStorageLocLoad_tokensOwed0 evm (positionsBase (burnPositionKeyKey I))) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, loc] - -theorem burnPositionUpdateValue_evalPositionTokensOwed1AfterTokensOwed1 - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm (.field (.var "position") "tokensOwed1") = - .ok (.int (Int.ofNat (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨3⟩)) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) uint128Mask).toNat)) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [burnPositionUpdateValueAfterTokensOwed1_position (v := v) (σ := σ)] - simp only [EvalResult.ofOption] - rw [show storageTypeStep? positionInfoStructTy (.field "tokensOwed1") = some uint128St by - simp [storageTypeStep?, positionInfoStructTy, uint128St]] - change - readStorage? (config v) evm (burnPositionUpdateEvaledRef I "tokensOwed1") uint128St = - .ok (.int (Int.ofNat (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨3⟩)) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) uint128Mask).toNat)) - rw [show uint128St = .elem (.int uint128Int) by rfl] - rw [readStorage?_elem - (er := burnPositionUpdateEvaledRef I "tokensOwed1") - (t := .int uint128Int) - (loc := loc (positionsBase (burnPositionKeyKey I) + ⟨3⟩) ⟨16, by decide⟩ - ⟨16, by decide⟩ (by decide) (.int uint128Int))] - · exact congrArg EvalResult.ok - (burnPositionUpdateStorageLocLoad_tokensOwed1 evm (positionsBase (burnPositionKeyKey I))) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, loc] - -theorem burnPositionUpdateValue_evalTokensOwed0AddAfterTokensOwed1 - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm (addE (.field (.var "position") "tokensOwed0") (.var "tokensOwed0")) = - .ok (.int (burnPositionUpdateSourceStoredTokensOwed0Int evm I + - burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat))) := by - let frame := burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat) - have hfield := - burnPositionUpdateValue_evalPositionTokensOwed0AfterTokensOwed1 - (v := v) (evm := evm) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128 - have hvar : - evalExpr? (config v) frame evm (.var "tokensOwed0") = - .ok (.int (burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat))) := by - simp only [frame, evalExpr?, EvalResult.ofOption] - rw [burnPositionUpdateValueAfterTokensOwed1_tokensOwed0 (v := v) (σ := σ) (I := I)] - unfold addE - rw [evalExpr?] - change - EvalResult.bind (evalExpr? (config v) frame evm - (.field (.var "position") "tokensOwed0")) (fun lhsValue => - EvalResult.bind (evalExpr? (config v) frame evm (.var "tokensOwed0")) - (fun rhsValue => evalBinaryOp? .add lhsValue rhsValue)) = - .ok (.int (burnPositionUpdateSourceStoredTokensOwed0Int evm I + - burnPositionUpdateSourceTokensOwed0Int σ I (Int.ofNat feeGrowthInside0X128.toNat))) - rw [hfield, hvar] - simp only [EvalResult.bind, evalBinaryOp?, - burnPositionUpdateSourceStoredTokensOwed0Int] - all_goals decide - -theorem burnPositionUpdateValue_evalTokensOwed1AddAfterTokensOwed1 - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm (addE (.field (.var "position") "tokensOwed1") (.var "tokensOwed1")) = - .ok (.int (burnPositionUpdateSourceStoredTokensOwed1Int evm I + - burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat))) := by - let frame := burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat) - have hfield := - burnPositionUpdateValue_evalPositionTokensOwed1AfterTokensOwed1 - (v := v) (evm := evm) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128 - have hvar : - evalExpr? (config v) frame evm (.var "tokensOwed1") = - .ok (.int (burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat))) := by - simp only [frame, evalExpr?, EvalResult.ofOption] - rw [burnPositionUpdateValueAfterTokensOwed1_tokensOwed1 (v := v) (σ := σ) (I := I)] - unfold addE - rw [evalExpr?] - change - EvalResult.bind (evalExpr? (config v) frame evm - (.field (.var "position") "tokensOwed1")) (fun lhsValue => - EvalResult.bind (evalExpr? (config v) frame evm (.var "tokensOwed1")) - (fun rhsValue => evalBinaryOp? .add lhsValue rhsValue)) = - .ok (.int (burnPositionUpdateSourceStoredTokensOwed1Int evm I + - burnPositionUpdateSourceTokensOwed1Int σ I (Int.ofNat feeGrowthInside1X128.toNat))) - rw [hfield, hvar] - simp only [EvalResult.bind, evalBinaryOp?, - burnPositionUpdateSourceStoredTokensOwed1Int] - all_goals decide - -theorem burnPositionUpdateValue_assignTokensOwed0AfterTokensOwed1 - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - assignStorageRef? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm .storage { base := "position", steps := [.field "tokensOwed0"] } - (.int (burnPositionUpdateSourceTokensOwed0WriteInt evm σ I feeGrowthInside0X128)) = - .ok ((burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)), - Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateSourceTokensOwed0StoreWord evm σ I feeGrowthInside0X128)) := by - rw [assignStorageRef?] - rw [burnPositionUpdateValue_resolveTokensOwed0AfterTokensOwed1] - simp only [EvalResult.bind, bind, EvalResult.ofOption, pure] - rw [show (config v).storage.layout (burnPositionUpdateEvaledRef I "tokensOwed0") = - fun _ => some (loc (burnPositionUpdateSourceTokensOwedSlot I) ⟨0, by decide⟩ - ⟨16, by decide⟩ (by decide) (.int uint128Int)) by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, burnPositionUpdateSourceTokensOwedSlot, - loc]] - simp only [EvalResult.bind, bind, EvalResult.ofOption, pure] - rw [burnPositionUpdateStorageLocStore_tokensOwed0 evm - (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateSourceTokensOwed0WriteInt evm σ I feeGrowthInside0X128)] - -theorem burnPositionUpdateValue_assignTokensOwed1AfterTokensOwed1 - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - assignStorageRef? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm .storage { base := "position", steps := [.field "tokensOwed1"] } - (.int (burnPositionUpdateSourceTokensOwed1WriteInt evm σ I feeGrowthInside1X128)) = - .ok ((burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)), - Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateSourceTokensOwed1StoreWord evm σ I feeGrowthInside1X128)) := by - rw [assignStorageRef?] - rw [burnPositionUpdateValue_resolveTokensOwed1AfterTokensOwed1] - simp only [EvalResult.bind, bind, EvalResult.ofOption, pure] - rw [show (config v).storage.layout (burnPositionUpdateEvaledRef I "tokensOwed1") = - fun _ => some (loc (burnPositionUpdateSourceTokensOwedSlot I) ⟨16, by decide⟩ - ⟨16, by decide⟩ (by decide) (.int uint128Int)) by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnPositionUpdateEvaledRef, burnPositionKeyKey, burnPositionUpdateSourceTokensOwedSlot, - loc]] - simp only [EvalResult.bind, bind, EvalResult.ofOption, pure] - rw [burnPositionUpdateStorageLocStore_tokensOwed1 evm - (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateSourceTokensOwed1WriteInt evm σ I feeGrowthInside1X128)] - -theorem burnPositionUpdateValue_assignTokensOwed0AfterTokensOwed1_some - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - ∃ evm', - assignStorageRef? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm .storage { base := "position", steps := [.field "tokensOwed0"] } - (.int (burnPositionUpdateSourceStoredTokensOwed0Int evm I + - burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat))) = - .ok ((burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)), - evm') := by - refine ⟨Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateSourceTokensOwed0StoreWord evm σ I feeGrowthInside0X128), ?_⟩ - simpa [burnPositionUpdateSourceTokensOwed0WriteInt] using - burnPositionUpdateValue_assignTokensOwed0AfterTokensOwed1 - (v := v) (evm := evm) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128 - -theorem burnPositionUpdateValue_assignTokensOwed1AfterTokensOwed1_some - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) : - ∃ evm', - assignStorageRef? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm .storage { base := "position", steps := [.field "tokensOwed1"] } - (.int (burnPositionUpdateSourceStoredTokensOwed1Int evm I + - burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat))) = - .ok ((burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)), - evm') := by - refine ⟨Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateSourceTokensOwed1StoreWord evm σ I feeGrowthInside1X128), ?_⟩ - simpa [burnPositionUpdateSourceTokensOwed1WriteInt] using - burnPositionUpdateValue_assignTokensOwed1AfterTokensOwed1 - (v := v) (evm := evm) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128 - -theorem uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedTrueTailValue - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hcond : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm - (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) = .ok (.bool true)) : - ExecBlock (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm - [ Stmt.ite (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) - [ .assign .storage { base := "position", steps := [.field "tokensOwed0"] } - (addE (.field (.var "position") "tokensOwed0") (.var "tokensOwed0")), - .assign .storage { base := "position", steps := [.field "tokensOwed1"] } - (addE (.field (.var "position") "tokensOwed1") (.var "tokensOwed1")) ] - [] ] - (ExecResult.ok - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (burnPositionUpdateSourceAfterTokensOwedState evm σ I - feeGrowthInside0X128 feeGrowthInside1X128)) := by - let frame := burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat) - let evm1 := burnPositionUpdateSourceAfterTokensOwed0State evm σ I feeGrowthInside0X128 - let evm2 := burnPositionUpdateSourceAfterTokensOwedState evm σ I - feeGrowthInside0X128 feeGrowthInside1X128 - have hstep0 : - ExecStmt (config v) frame evm - (.assign .storage { base := "position", steps := [.field "tokensOwed0"] } - (addE (.field (.var "position") "tokensOwed0") (.var "tokensOwed0"))) - (.ok frame evm1) := by - exact ExecStmt.assign - (by - simpa [frame] using - burnPositionUpdateValue_evalTokensOwed0AddAfterTokensOwed1 - (v := v) (evm := evm) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128) - (by - simpa [frame, evm1, burnPositionUpdateSourceAfterTokensOwed0State, - burnPositionUpdateSourceTokensOwed0WriteInt] using - burnPositionUpdateValue_assignTokensOwed0AfterTokensOwed1 - (v := v) (evm := evm) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128) - have hstep1 : - ExecStmt (config v) frame evm1 - (.assign .storage { base := "position", steps := [.field "tokensOwed1"] } - (addE (.field (.var "position") "tokensOwed1") (.var "tokensOwed1"))) - (.ok frame evm2) := by - exact ExecStmt.assign - (by - simpa [frame] using - burnPositionUpdateValue_evalTokensOwed1AddAfterTokensOwed1 - (v := v) (evm := evm1) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128) - (by - simpa [frame, evm2, burnPositionUpdateSourceAfterTokensOwedState, - burnPositionUpdateSourceTokensOwed1WriteInt] using - burnPositionUpdateValue_assignTokensOwed1AfterTokensOwed1 - (v := v) (evm := evm1) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128) - have hthen : - ExecBlock (config v) frame evm - [ .assign .storage { base := "position", steps := [.field "tokensOwed0"] } - (addE (.field (.var "position") "tokensOwed0") (.var "tokensOwed0")), - .assign .storage { base := "position", steps := [.field "tokensOwed1"] } - (addE (.field (.var "position") "tokensOwed1") (.var "tokensOwed1")) ] - (.ok frame evm2) := by - exact ExecBlock.consNormal hstep0 (ExecBlock.consNormal hstep1 ExecBlock.nil) - simpa [frame, evm2] using - ExecBlock.consNormal (ExecStmt.iteTrue (by simpa [frame] using hcond) hthen) ExecBlock.nil - -set_option maxHeartbeats 800000 in -theorem uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedTrueBlockValue - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) - (hcond : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128) - (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) = .ok (.bool true)) : - ExecBlock (config v) - (burnPositionUpdateValueFrame v I (.int (Int.ofNat feeGrowthInside0X128.toNat)) - (.int (Int.ofNat feeGrowthInside1X128.toNat))) - (initState cA gh bl σ σ₀ g A I) - ([ .letStorage "position" (positionsRef (.var "positionKey")), - Stmt.ite (eqE (.var "liquidityDelta") (.intLit 0)) - [ .require (gtE (.field (.var "position") "liquidity") (.intLit 0)), - .letDecl "liquidityNext" (some uint128) - (.field (.var "position") "liquidity") ] - [ .internalCall "liquidityAddDelta" - [.field (.var "position") "liquidity", .var "liquidityDelta"] - "liquidityNext" ], - .letDecl "tokensOwed0" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside0X128") - (.field (.var "position") "feeGrowthInside0LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)), - .letDecl "tokensOwed1" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside1X128") - (.field (.var "position") "feeGrowthInside1LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)), - Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ .assign .storage { base := "position", steps := [.field "liquidity"] } - (.var "liquidityNext") ] - [], - .assign .storage { base := "position", steps := [.field "feeGrowthInside0LastX128"] } - (.var "feeGrowthInside0X128"), - .assign .storage { base := "position", steps := [.field "feeGrowthInside1LastX128"] } - (.var "feeGrowthInside1X128") ] ++ - [ Stmt.ite (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) - [ .assign .storage { base := "position", steps := [.field "tokensOwed0"] } - (addE (.field (.var "position") "tokensOwed0") (.var "tokensOwed0")), - .assign .storage { base := "position", steps := [.field "tokensOwed1"] } - (addE (.field (.var "position") "tokensOwed1") (.var "tokensOwed1")) ] - [] ]) - (ExecResult.ok - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (burnPositionUpdateSourceAfterTokensOwedState - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128) - σ I feeGrowthInside0X128 feeGrowthInside1X128)) := by - let evmFee := - Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) feeGrowthInside1X128 - have hprefix := - uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroFeeGrowthLastPrefixValue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 hzero hliq - have hcondFee : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evmFee - (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) = .ok (.bool true) := by - simpa [evmFee] using hcond - have htail := - uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedTrueTailValue - (v := v) (evm := evmFee) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128 hcondFee - simpa [evmFee] using execBlock_append hprefix htail - -theorem burnPositionUpdateSourceAfterTokensOwedState_stateEquiv_of_final_word - {evm σ I} {feeGrowthInside0X128 feeGrowthInside1X128 finalWord : UInt256} - (hword : - burnPositionUpdateSourceTokensOwed1StoreWord - (burnPositionUpdateSourceAfterTokensOwed0State evm σ I feeGrowthInside0X128) - σ I feeGrowthInside1X128 = finalWord) : - EVMStateEquiv - (Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) finalWord) - (burnPositionUpdateSourceAfterTokensOwedState evm σ I - feeGrowthInside0X128 feeGrowthInside1X128) := by - refine ⟨?_, ?_, ?_⟩ - · simp [burnPositionUpdateSourceAfterTokensOwedState, - burnPositionUpdateSourceAfterTokensOwed0State, storageStore_executionEnv] - · simp [burnPositionUpdateSourceAfterTokensOwedState, - burnPositionUpdateSourceAfterTokensOwed0State, storageStore_createdAccounts] - · rw [← hword] - simp [burnPositionUpdateSourceAfterTokensOwedState, - burnPositionUpdateSourceAfterTokensOwed0State, storageStore_accountMap, - storageStore_executionEnv] - exact accountMapEquiv_sstoreAccountMap_self_update evm.accountMap - evm.executionEnv.codeOwner (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateSourceTokensOwed0StoreWord evm σ I feeGrowthInside0X128) - (burnPositionUpdateSourceTokensOwed1StoreWord - (Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateSourceTokensOwed0StoreWord evm σ I feeGrowthInside0X128)) - σ I feeGrowthInside1X128) - -theorem burnPositionUpdateTokensOwedState_stateEquiv_of_final_word - {evmEvm evmSolm : EVM.State} {σ I} - {feeGrowthInside0X128 feeGrowthInside1X128 finalWord : UInt256} - (hstate : EVMStateEquiv evmEvm evmSolm) - (hword : - burnPositionUpdateSourceTokensOwed1StoreWord - (burnPositionUpdateSourceAfterTokensOwed0State evmSolm σ I feeGrowthInside0X128) - σ I feeGrowthInside1X128 = finalWord) : - EVMStateEquiv - (Solm.EVM.storageStore evmEvm evmEvm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) finalWord) - (burnPositionUpdateSourceAfterTokensOwedState evmSolm σ I - feeGrowthInside0X128 feeGrowthInside1X128) := by - refine ⟨?_, ?_, ?_⟩ - · simp [burnPositionUpdateSourceAfterTokensOwedState, - burnPositionUpdateSourceAfterTokensOwed0State, storageStore_executionEnv] - exact hstate.executionEnv - · simp [burnPositionUpdateSourceAfterTokensOwedState, - burnPositionUpdateSourceAfterTokensOwed0State, storageStore_createdAccounts] - exact hstate.createdAccounts - · have hsingle : accountMapEquiv - (Solm.EVM.storageStore evmEvm evmEvm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) finalWord).accountMap - (Solm.EVM.storageStore evmSolm evmSolm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) finalWord).accountMap := by - rw [hstate.executionEnv] - exact storageStore_accountMapEquiv hstate.accountMap evmSolm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) finalWord - have hsource := - burnPositionUpdateSourceAfterTokensOwedState_stateEquiv_of_final_word - (evm := evmSolm) (σ := σ) (I := I) - (feeGrowthInside0X128 := feeGrowthInside0X128) - (feeGrowthInside1X128 := feeGrowthInside1X128) - (finalWord := finalWord) hword - exact accountMapEquiv.trans hsingle hsource.accountMap - -theorem uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedZeroTailValue - {v : PoolImmutables} {evm σ I} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (htokens0 : - burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat) = 0) - (htokens1 : - burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat) = 0) : - ExecBlock (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm - [ Stmt.ite (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) - [ .assign .storage { base := "position", steps := [.field "tokensOwed0"] } - (addE (.field (.var "position") "tokensOwed0") (.var "tokensOwed0")), - .assign .storage { base := "position", steps := [.field "tokensOwed1"] } - (addE (.field (.var "position") "tokensOwed1") (.var "tokensOwed1")) ] - [] ] - (ExecResult.ok - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evm) := by - refine ExecBlock.consNormal (ExecStmt.iteFalse ?_ ?_) ExecBlock.nil - · exact burnPositionUpdateValue_evalTokensOwedGtFalseAfterTokensOwed1 - (v := v) (evm := evm) (σ := σ) (I := I) - feeGrowthInside0X128 feeGrowthInside1X128 htokens0 htokens1 - · exact ExecBlock.nil - -theorem uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedZeroBlockValue - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) - (htokens0 : - burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat) = 0) - (htokens1 : - burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat) = 0) : - ExecBlock (config v) - (burnPositionUpdateValueFrame v I (.int (Int.ofNat feeGrowthInside0X128.toNat)) - (.int (Int.ofNat feeGrowthInside1X128.toNat))) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "position" (positionsRef (.var "positionKey")), - Stmt.ite (eqE (.var "liquidityDelta") (.intLit 0)) - [ .require (gtE (.field (.var "position") "liquidity") (.intLit 0)), - .letDecl "liquidityNext" (some uint128) - (.field (.var "position") "liquidity") ] - [ .internalCall "liquidityAddDelta" - [.field (.var "position") "liquidity", .var "liquidityDelta"] - "liquidityNext" ], - .letDecl "tokensOwed0" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside0X128") - (.field (.var "position") "feeGrowthInside0LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)), - .letDecl "tokensOwed1" (some uint128) - (uint128Wrap - (divE - (mulE - (wordSub (.var "feeGrowthInside1X128") - (.field (.var "position") "feeGrowthInside1LastX128")) - (.field (.var "position") "liquidity")) - fixedPoint128Q128)), - Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ .assign .storage { base := "position", steps := [.field "liquidity"] } - (.var "liquidityNext") ] - [], - .assign .storage { base := "position", steps := [.field "feeGrowthInside0LastX128"] } - (.var "feeGrowthInside0X128"), - .assign .storage { base := "position", steps := [.field "feeGrowthInside1LastX128"] } - (.var "feeGrowthInside1X128"), - Stmt.ite (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) - [ .assign .storage { base := "position", steps := [.field "tokensOwed0"] } - (addE (.field (.var "position") "tokensOwed0") (.var "tokensOwed0")), - .assign .storage { base := "position", steps := [.field "tokensOwed1"] } - (addE (.field (.var "position") "tokensOwed1") (.var "tokensOwed1")) ] - [] ] - (ExecResult.ok - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128)) := by - have hprefix := - uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroFeeGrowthLastPrefixValue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 hzero hliq - have htail := - uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedZeroTailValue - (v := v) - (evm := Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) feeGrowthInside1X128) - (σ := σ) (I := I) feeGrowthInside0X128 feeGrowthInside1X128 htokens0 htokens1 - simpa using execBlock_append hprefix htail - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedBridge.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedBridge.lean deleted file mode 100644 index 15a5a471..00000000 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedBridge.lean +++ /dev/null @@ -1,1207 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdateTokensOwedPacking -import Benchmarks.UniswapV3Pool.BurnPositionUpdateTokensOwedStore -import Benchmarks.UniswapV3Pool.BurnPositionUpdateSlowPostReturn - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev burnTickGetBelow0Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - if tickSpacingSint24Value (slot0TickRawWord σ I) >= - tickSpacingSint24Value (burnTickLowerWord I) then - burnTickGetLowerFeeGrowthOutside0Word σ I - else - UInt256.sub (solcSlotWord σ I ⟨1⟩) (burnTickGetLowerFeeGrowthOutside0Word σ I) - -abbrev burnTickGetBelow1Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - if tickSpacingSint24Value (slot0TickRawWord σ I) >= - tickSpacingSint24Value (burnTickLowerWord I) then - burnTickGetLowerFeeGrowthOutside1Word σ I - else - UInt256.sub (solcSlotWord σ I ⟨2⟩) (burnTickGetLowerFeeGrowthOutside1Word σ I) - -abbrev burnTickGetAbove0Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - if tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickUpperWord I) then - burnTickGetUpperFeeGrowthOutside0Word σ I - else - UInt256.sub (solcSlotWord σ I ⟨1⟩) (burnTickGetUpperFeeGrowthOutside0Word σ I) - -abbrev burnTickGetAbove1Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - if tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickUpperWord I) then - burnTickGetUpperFeeGrowthOutside1Word σ I - else - UInt256.sub (solcSlotWord σ I ⟨2⟩) (burnTickGetUpperFeeGrowthOutside1Word σ I) - -abbrev burnTickGetInside0Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.sub (UInt256.sub (solcSlotWord σ I ⟨1⟩) (burnTickGetBelow0Word σ I)) - (burnTickGetAbove0Word σ I) - -abbrev burnTickGetInside1Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.sub (UInt256.sub (solcSlotWord σ I ⟨2⟩) (burnTickGetBelow1Word σ I)) - (burnTickGetAbove1Word σ I) - -theorem solcSlotWord_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) (slot : UInt256) : - solcSlotWord σ I slot = solcSlotWord τ I slot := by - have hslot := accountMapEquiv_storage_findD h I.codeOwner slot (⟨0⟩ : UInt256) - simpa [solcSlotWord] using hslot - -theorem sstoreAccountMap_find?_same_exists - {σ : AccountMap} {addr : AccountAddress} {slot val : UInt256} - (h : ∃ acc, σ.find? addr = some acc) : - ∃ acc, (sstoreAccountMap addr σ slot val).find? addr = some acc := by - rcases h with ⟨acc, hacc⟩ - refine ⟨if val == default then {acc with storage := acc.storage.erase slot} - else {acc with storage := acc.storage.insert slot val}, ?_⟩ - simp only [sstoreAccountMap, hacc, Option.option] - rw [accountMap_find_insert_self] - -theorem storageStore_codeOwner_find?_exists - {evm : EVM.State} (h : ∃ acc, evm.accountMap.find? evm.executionEnv.codeOwner = some acc) - (slot val : UInt256) : - ∃ acc, - (Solm.EVM.storageStore evm evm.executionEnv.codeOwner slot val).accountMap.find? - (Solm.EVM.storageStore evm evm.executionEnv.codeOwner slot val).executionEnv.codeOwner = - some acc := by - simpa [storageStore_accountMap, storageStore_executionEnv] using - sstoreAccountMap_find?_same_exists (σ := evm.accountMap) - (addr := evm.executionEnv.codeOwner) (slot := slot) (val := val) h - -theorem accountMap_find?_codeOwner_exists_of_burnUnlockedByte_ne_zero - {σ : AccountMap} {I : ExecutionEnv} (h : burnUnlockedByte σ I ≠ ⟨0⟩) : - ∃ acc, σ.find? I.codeOwner = some acc := by - by_cases hmissing : σ.find? I.codeOwner = none - · exfalso - apply h - simp [burnUnlockedByte, solcSlotWord, hmissing, burnUint8Mask, burnUnlockedShift, - Option.option] - native_decide - · cases hfind : σ.find? I.codeOwner with - | none => exact False.elim (hmissing hfind) - | some acc => exact ⟨acc, rfl⟩ - -theorem slot0TickRawWord_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) : - slot0TickRawWord σ I = slot0TickRawWord τ I := by - rw [slot0TickRawWord, slot0SlotWord, solcSlotWord_eq_of_accountMapEquiv h I ⟨0⟩] - -theorem slot0TickReturnWord_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) : - slot0TickReturnWord σ I = slot0TickReturnWord τ I := by - rw [slot0TickReturnWord, slot0SlotWord, solcSlotWord_eq_of_accountMapEquiv h I ⟨0⟩] - -theorem burnTickGetLowerFeeGrowthOutside0Word_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) : - burnTickGetLowerFeeGrowthOutside0Word σ I = - burnTickGetLowerFeeGrowthOutside0Word τ I := by - rw [burnTickGetLowerFeeGrowthOutside0Word, - solcSlotWord_eq_of_accountMapEquiv h I (burnTickGetLowerBaseSlot I + ⟨1⟩)] - -theorem burnTickGetLowerFeeGrowthOutside1Word_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) : - burnTickGetLowerFeeGrowthOutside1Word σ I = - burnTickGetLowerFeeGrowthOutside1Word τ I := by - rw [burnTickGetLowerFeeGrowthOutside1Word, - solcSlotWord_eq_of_accountMapEquiv h I (burnTickGetLowerBaseSlot I + ⟨2⟩)] - -theorem burnTickGetUpperFeeGrowthOutside0Word_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) : - burnTickGetUpperFeeGrowthOutside0Word σ I = - burnTickGetUpperFeeGrowthOutside0Word τ I := by - rw [burnTickGetUpperFeeGrowthOutside0Word, - solcSlotWord_eq_of_accountMapEquiv h I (burnTickGetUpperBaseSlot I + ⟨1⟩)] - -theorem burnTickGetUpperFeeGrowthOutside1Word_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) : - burnTickGetUpperFeeGrowthOutside1Word σ I = - burnTickGetUpperFeeGrowthOutside1Word τ I := by - rw [burnTickGetUpperFeeGrowthOutside1Word, - solcSlotWord_eq_of_accountMapEquiv h I (burnTickGetUpperBaseSlot I + ⟨2⟩)] - -theorem burnTickGetBelow0Word_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) : - burnTickGetBelow0Word σ I = burnTickGetBelow0Word τ I := by - unfold burnTickGetBelow0Word - rw [slot0TickRawWord_eq_of_accountMapEquiv h I] - rw [burnTickGetLowerFeeGrowthOutside0Word_eq_of_accountMapEquiv h I] - rw [solcSlotWord_eq_of_accountMapEquiv h I ⟨1⟩] - -theorem burnTickGetBelow1Word_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) : - burnTickGetBelow1Word σ I = burnTickGetBelow1Word τ I := by - unfold burnTickGetBelow1Word - rw [slot0TickRawWord_eq_of_accountMapEquiv h I] - rw [burnTickGetLowerFeeGrowthOutside1Word_eq_of_accountMapEquiv h I] - rw [solcSlotWord_eq_of_accountMapEquiv h I ⟨2⟩] - -theorem burnTickGetAbove0Word_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) : - burnTickGetAbove0Word σ I = burnTickGetAbove0Word τ I := by - unfold burnTickGetAbove0Word - rw [slot0TickRawWord_eq_of_accountMapEquiv h I] - rw [burnTickGetUpperFeeGrowthOutside0Word_eq_of_accountMapEquiv h I] - rw [solcSlotWord_eq_of_accountMapEquiv h I ⟨1⟩] - -theorem burnTickGetAbove1Word_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) : - burnTickGetAbove1Word σ I = burnTickGetAbove1Word τ I := by - unfold burnTickGetAbove1Word - rw [slot0TickRawWord_eq_of_accountMapEquiv h I] - rw [burnTickGetUpperFeeGrowthOutside1Word_eq_of_accountMapEquiv h I] - rw [solcSlotWord_eq_of_accountMapEquiv h I ⟨2⟩] - -theorem burnTickGetInside0Word_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) : - burnTickGetInside0Word σ I = burnTickGetInside0Word τ I := by - rw [burnTickGetInside0Word, solcSlotWord_eq_of_accountMapEquiv h I ⟨1⟩, - burnTickGetBelow0Word_eq_of_accountMapEquiv h I, - burnTickGetAbove0Word_eq_of_accountMapEquiv h I] - -theorem burnTickGetInside1Word_eq_of_accountMapEquiv {σ τ : AccountMap} - (h : accountMapEquiv σ τ) (I : ExecutionEnv) : - burnTickGetInside1Word σ I = burnTickGetInside1Word τ I := by - rw [burnTickGetInside1Word, solcSlotWord_eq_of_accountMapEquiv h I ⟨2⟩, - burnTickGetBelow1Word_eq_of_accountMapEquiv h I, - burnTickGetAbove1Word_eq_of_accountMapEquiv h I] - -theorem burnPositionUpdateSourceTokensOwed0Int_eq_of_accountMapEquiv - {σ τ : AccountMap} (h : accountMapEquiv σ τ) (I : ExecutionEnv) - (feeGrowthInside0X128 : Int) : - burnPositionUpdateSourceTokensOwed0Int σ I feeGrowthInside0X128 = - burnPositionUpdateSourceTokensOwed0Int τ I feeGrowthInside0X128 := by - unfold burnPositionUpdateSourceTokensOwed0Int - rw [burnPositionUpdateSourceFeeGrowthInside0LastInt, - solcSlotWord_eq_of_accountMapEquiv h I - (positionsBase (burnPositionKeyKey I) + ⟨1⟩)] - rw [burnPositionUpdateSourceLiquidityInt, - solcSlotWord_eq_of_accountMapEquiv h I (positionsBase (burnPositionKeyKey I))] - -theorem burnPositionUpdateSourceTokensOwed1Int_eq_of_accountMapEquiv - {σ τ : AccountMap} (h : accountMapEquiv σ τ) (I : ExecutionEnv) - (feeGrowthInside1X128 : Int) : - burnPositionUpdateSourceTokensOwed1Int σ I feeGrowthInside1X128 = - burnPositionUpdateSourceTokensOwed1Int τ I feeGrowthInside1X128 := by - unfold burnPositionUpdateSourceTokensOwed1Int - rw [burnPositionUpdateSourceFeeGrowthInside1LastInt, - solcSlotWord_eq_of_accountMapEquiv h I - (positionsBase (burnPositionKeyKey I) + ⟨2⟩)] - rw [burnPositionUpdateSourceLiquidityInt, - solcSlotWord_eq_of_accountMapEquiv h I (positionsBase (burnPositionKeyKey I))] - -theorem burnTickGetBelow0Int_eq_word (σ : AccountMap) (I : ExecutionEnv) : - burnTickGetBelow0Int σ I = Int.ofNat (burnTickGetBelow0Word σ I).toNat := by - unfold burnTickGetBelow0Int burnTickGetBelow0Word - split - · rfl - · exact burnWordSubInt_ofNat_toNat_eq (solcSlotWord σ I ⟨1⟩) - (burnTickGetLowerFeeGrowthOutside0Word σ I) - -theorem burnTickGetBelow1Int_eq_word (σ : AccountMap) (I : ExecutionEnv) : - burnTickGetBelow1Int σ I = Int.ofNat (burnTickGetBelow1Word σ I).toNat := by - unfold burnTickGetBelow1Int burnTickGetBelow1Word - split - · rfl - · exact burnWordSubInt_ofNat_toNat_eq (solcSlotWord σ I ⟨2⟩) - (burnTickGetLowerFeeGrowthOutside1Word σ I) - -theorem burnTickGetAbove0Int_eq_word (σ : AccountMap) (I : ExecutionEnv) : - burnTickGetAbove0Int σ I = Int.ofNat (burnTickGetAbove0Word σ I).toNat := by - unfold burnTickGetAbove0Int burnTickGetAbove0Word - split - · rfl - · exact burnWordSubInt_ofNat_toNat_eq (solcSlotWord σ I ⟨1⟩) - (burnTickGetUpperFeeGrowthOutside0Word σ I) - -theorem burnTickGetAbove1Int_eq_word (σ : AccountMap) (I : ExecutionEnv) : - burnTickGetAbove1Int σ I = Int.ofNat (burnTickGetAbove1Word σ I).toNat := by - unfold burnTickGetAbove1Int burnTickGetAbove1Word - split - · rfl - · exact burnWordSubInt_ofNat_toNat_eq (solcSlotWord σ I ⟨2⟩) - (burnTickGetUpperFeeGrowthOutside1Word σ I) - -theorem burnTickGetInside0Value_eq_word (σ : AccountMap) (I : ExecutionEnv) : - burnTickGetInside0Value σ I = .int (Int.ofNat (burnTickGetInside0Word σ I).toNat) := by - simp only [burnTickGetInside0Value, burnTickGetInside0Int] - rw [burnTickGetBelow0Int_eq_word σ I, burnTickGetAbove0Int_eq_word σ I] - change - Value.int - (burnWordSubInt - (burnWordSubInt (Int.ofNat (solcSlotWord σ I ⟨1⟩).toNat) - (Int.ofNat (burnTickGetBelow0Word σ I).toNat)) - (Int.ofNat (burnTickGetAbove0Word σ I).toNat)) = - Value.int (Int.ofNat (burnTickGetInside0Word σ I).toNat) - rw [burnWordSubInt_ofNat_toNat_eq (solcSlotWord σ I ⟨1⟩) - (burnTickGetBelow0Word σ I)] - rw [burnWordSubInt_ofNat_toNat_eq - (UInt256.sub (solcSlotWord σ I ⟨1⟩) (burnTickGetBelow0Word σ I)) - (burnTickGetAbove0Word σ I)] - -theorem burnTickGetInside1Value_eq_word (σ : AccountMap) (I : ExecutionEnv) : - burnTickGetInside1Value σ I = .int (Int.ofNat (burnTickGetInside1Word σ I).toNat) := by - simp only [burnTickGetInside1Value, burnTickGetInside1Int] - rw [burnTickGetBelow1Int_eq_word σ I, burnTickGetAbove1Int_eq_word σ I] - change - Value.int - (burnWordSubInt - (burnWordSubInt (Int.ofNat (solcSlotWord σ I ⟨2⟩).toNat) - (Int.ofNat (burnTickGetBelow1Word σ I).toNat)) - (Int.ofNat (burnTickGetAbove1Word σ I).toNat)) = - Value.int (Int.ofNat (burnTickGetInside1Word σ I).toNat) - rw [burnWordSubInt_ofNat_toNat_eq (solcSlotWord σ I ⟨2⟩) - (burnTickGetBelow1Word σ I)] - rw [burnWordSubInt_ofNat_toNat_eq - (UInt256.sub (solcSlotWord σ I ⟨2⟩) (burnTickGetBelow1Word σ I)) - (burnTickGetAbove1Word σ I)] - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnFeeGrowthInsideEntryReturnConcrete {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord ee) < - tickSpacingSint24Value (burnTickUpperWord ee)) - (h : RD code ee g s0 ⟨21387⟩ - (solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 82 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨19510⟩ - (burnTickGetInside1Word σ ee :: burnTickGetInside0Word σ ee :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R) - (burnTickUpperFeeGrowthMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k' C' := by - let tail : List UInt256 := - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R - by_cases hCurrentBelow : - tickSpacingSint24Value (slot0TickRawWord σ ee) < - tickSpacingSint24Value (burnTickLowerWord ee) - · obtain ⟨_, _, hrdLower⟩ := - uniswapV3PoolBurnFeeGrowthInsideLowerBelowToUpperJoin - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (ret := ret) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hCurrentBelow h (by omega) - have hCurrentUpper : - tickSpacingSint24Value (slot0TickRawWord σ ee) < - tickSpacingSint24Value (burnTickUpperWord ee) := - lt_trans hCurrentBelow htickLt - obtain ⟨_, _, hrdUpper⟩ := - uniswapV3PoolBurnFeeGrowthInsideUpperInsideFromJoin - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (ret := ret) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hCurrentUpper hrdLower (by omega) - obtain ⟨_, _, hrdReturn⟩ := - uniswapV3PoolBurnFeeGrowthInsideJoinReturn (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ⟨19510⟩) - (rdata := rdata) (acc := (cA, σ)) hpatch - (uniswapV3PoolJumpDestPatched19510 hpatch) hrdUpper - (by simp only [List.length_cons] at hov ⊢; omega) - have hnotGeLower : - ¬ tickSpacingSint24Value (slot0TickRawWord σ ee) >= - tickSpacingSint24Value (burnTickLowerWord ee) := by - exact not_le_of_gt hCurrentBelow - exact ⟨_, _, by simpa [tail, burnTickGetInside1Word, burnTickGetInside0Word, - burnTickGetBelow1Word, burnTickGetBelow0Word, burnTickGetAbove1Word, - burnTickGetAbove0Word, hnotGeLower, hCurrentUpper, - burnTickGetLowerFeeGrowthOutside0Word, burnTickGetLowerFeeGrowthOutside1Word, - burnTickGetUpperFeeGrowthOutside0Word, burnTickGetUpperFeeGrowthOutside1Word, - burnTickGetLowerBaseSlot, burnTickGetUpperBaseSlot, burnTickGetLowerKey, - burnTickGetUpperKey, burnTickLowerFeeGrowthOutside0Word, - burnTickLowerFeeGrowthOutside1Word, burnTickUpperFeeGrowthOutside0Word, - burnTickUpperFeeGrowthOutside1Word, burnTickLowerFeeGrowthOutside0Slot, - burnTickLowerFeeGrowthOutside1Slot, burnTickUpperFeeGrowthOutside0Slot, - burnTickUpperFeeGrowthOutside1Slot, burnTickLowerFeeGrowthBaseSlot, - burnTickUpperFeeGrowthBaseSlot, burnTickLowerFeeGrowthKey, - burnTickUpperFeeGrowthKey, burnTickLowerFeeGrowthCompareWord, - burnTickUpperFeeGrowthCompareWord, ticksBase, mapSlot, solcMappingSlot, - keyValueToWord, wordOfInt_sint24Value_eq_signextend_two, - signextend_two_tickSpacing_idempotent, u256_add_comm] using hrdReturn⟩ - · obtain ⟨_, _, hrdLower⟩ := - uniswapV3PoolBurnFeeGrowthInsideLowerNotBelowToUpperJoin - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (ret := ret) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hCurrentBelow h (by omega) - have hgeLower : - tickSpacingSint24Value (slot0TickRawWord σ ee) >= - tickSpacingSint24Value (burnTickLowerWord ee) := by - exact le_of_not_gt hCurrentBelow - by_cases hCurrentUpper : - tickSpacingSint24Value (slot0TickRawWord σ ee) < - tickSpacingSint24Value (burnTickUpperWord ee) - · obtain ⟨_, _, hrdUpper⟩ := - uniswapV3PoolBurnFeeGrowthInsideUpperInsideFromJoin - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (ret := ret) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hCurrentUpper hrdLower (by omega) - obtain ⟨_, _, hrdReturn⟩ := - uniswapV3PoolBurnFeeGrowthInsideJoinReturn (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ⟨19510⟩) - (rdata := rdata) (acc := (cA, σ)) hpatch - (uniswapV3PoolJumpDestPatched19510 hpatch) hrdUpper - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, by simpa [tail, burnTickGetInside1Word, burnTickGetInside0Word, - burnTickGetBelow1Word, burnTickGetBelow0Word, burnTickGetAbove1Word, - burnTickGetAbove0Word, hgeLower, hCurrentUpper, - burnTickGetLowerFeeGrowthOutside0Word, burnTickGetLowerFeeGrowthOutside1Word, - burnTickGetUpperFeeGrowthOutside0Word, burnTickGetUpperFeeGrowthOutside1Word, - burnTickGetLowerBaseSlot, burnTickGetUpperBaseSlot, burnTickGetLowerKey, - burnTickGetUpperKey, burnTickLowerFeeGrowthOutside0Word, - burnTickLowerFeeGrowthOutside1Word, burnTickUpperFeeGrowthOutside0Word, - burnTickUpperFeeGrowthOutside1Word, burnTickLowerFeeGrowthOutside0Slot, - burnTickLowerFeeGrowthOutside1Slot, burnTickUpperFeeGrowthOutside0Slot, - burnTickUpperFeeGrowthOutside1Slot, burnTickLowerFeeGrowthBaseSlot, - burnTickUpperFeeGrowthBaseSlot, burnTickLowerFeeGrowthKey, - burnTickUpperFeeGrowthKey, burnTickLowerFeeGrowthCompareWord, - burnTickUpperFeeGrowthCompareWord, ticksBase, mapSlot, solcMappingSlot, - keyValueToWord, wordOfInt_sint24Value_eq_signextend_two, - signextend_two_tickSpacing_idempotent, u256_add_comm] using hrdReturn⟩ - · obtain ⟨_, _, hrdUpper⟩ := - uniswapV3PoolBurnFeeGrowthInsideUpperNotInsideFromJoin - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (ret := ret) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hCurrentUpper hrdLower (by omega) - obtain ⟨_, _, hrdReturn⟩ := - uniswapV3PoolBurnFeeGrowthInsideJoinReturn (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ⟨19510⟩) - (rdata := rdata) (acc := (cA, σ)) hpatch - (uniswapV3PoolJumpDestPatched19510 hpatch) hrdUpper - (by simp only [List.length_cons] at hov ⊢; omega) - exact ⟨_, _, by simpa [tail, burnTickGetInside1Word, burnTickGetInside0Word, - burnTickGetBelow1Word, burnTickGetBelow0Word, burnTickGetAbove1Word, - burnTickGetAbove0Word, hgeLower, hCurrentUpper, - burnTickGetLowerFeeGrowthOutside0Word, burnTickGetLowerFeeGrowthOutside1Word, - burnTickGetUpperFeeGrowthOutside0Word, burnTickGetUpperFeeGrowthOutside1Word, - burnTickGetLowerBaseSlot, burnTickGetUpperBaseSlot, burnTickGetLowerKey, - burnTickGetUpperKey, burnTickLowerFeeGrowthOutside0Word, - burnTickLowerFeeGrowthOutside1Word, burnTickUpperFeeGrowthOutside0Word, - burnTickUpperFeeGrowthOutside1Word, burnTickLowerFeeGrowthOutside0Slot, - burnTickLowerFeeGrowthOutside1Slot, burnTickUpperFeeGrowthOutside0Slot, - burnTickUpperFeeGrowthOutside1Slot, burnTickLowerFeeGrowthBaseSlot, - burnTickUpperFeeGrowthBaseSlot, burnTickLowerFeeGrowthKey, - burnTickUpperFeeGrowthKey, burnTickLowerFeeGrowthCompareWord, - burnTickUpperFeeGrowthCompareWord, ticksBase, mapSlot, solcMappingSlot, - keyValueToWord, wordOfInt_sint24Value_eq_signextend_two, - signextend_two_tickSpacing_idempotent, u256_add_comm] using hrdReturn⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnZeroDeltaPositionUpdateToMulDivReturnConcrete - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hperm : ee.perm = true) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord ee) < - tickSpacingSint24Value (burnTickUpperWord ee)) - (hzero : burnAmountCleanWord ee = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)) ≠ ⟨0⟩) - (hprod0 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub (burnTickGetInside0Word σ ee) - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee))) = ⟨0⟩) - (hprod1 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub (burnTickGetInside1Word σ ee) - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee))) = ⟨0⟩) - (h : RD code ee g s0 ⟨21387⟩ - (solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 82 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21861⟩ - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub (burnTickGetInside1Word σ ee) - (solcSlotWord σ ee - (burnPositionBaseSlotWord σ ee + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) :: - UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub (burnTickGetInside0Word σ ee) - (solcSlotWord σ ee - (burnPositionBaseSlotWord σ ee + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) :: - burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)) :: - burnPositionKeyNewFreePtrWord :: - burnTickGetInside1Word σ ee :: burnTickGetInside0Word σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - burnPositionBaseSlotWord σ ee :: ⟨19527⟩ :: - burnTickGetInside1Word σ ee :: burnTickGetInside0Word σ ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R) - (burnPositionUpdateMem5 σ ee - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)) - (burnPositionBaseSlotWord σ ee)) - (UInt256.ofNat 22) rdata - (cA, sstoreAccountMap ee.codeOwner - (sstoreAccountMap ee.codeOwner σ - (burnPositionBaseSlotWord σ ee + (⟨1⟩ : UInt256)) - (burnTickGetInside0Word σ ee)) - (burnPositionBaseSlotWord σ ee + (⟨2⟩ : UInt256)) - (burnTickGetInside1Word σ ee)) k' C' := by - let inside1 := burnTickGetInside1Word σ ee - let inside0 := burnTickGetInside0Word σ ee - let posBase := burnPositionBaseSlotWord σ ee - let delta := UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) - let postFreeR : List UInt256 := - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R - let tail : List UInt256 := - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - posBase :: slot0TickReturnWord σ ee :: - delta :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: postFreeR - obtain ⟨_, _, hrdReturn⟩ := - uniswapV3PoolBurnFeeGrowthInsideEntryReturnConcrete - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (ret := ret) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch htickLt h (by omega) - obtain ⟨_, _, hrdEntry⟩ := - uniswapV3PoolBurnFeeGrowthInsideEnterPositionUpdate - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) - (z0 := ⟨0⟩) (z1 := ⟨0⟩) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase := posBase) (tick := slot0TickReturnWord σ ee) - (delta := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) - hpatch - (by simpa [inside1, inside0, posBase, delta] using hrdReturn) - (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdSlot0⟩ := - uniswapV3PoolBurnPositionUpdateLoadSlot0 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdEntry (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdPacked⟩ := - uniswapV3PoolBurnPositionUpdateStoreSlot0Packed - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (pos0 := solcSlotWord σ ee posBase) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdSlot0 (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdFee0⟩ := - uniswapV3PoolBurnPositionUpdateStoreFeeGrowthInside0Last - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch (by simpa [inside1, inside0, posBase, delta] using hrdPacked) - (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdFee1⟩ := - uniswapV3PoolBurnPositionUpdateStoreFeeGrowthInside1Last - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdFee0 (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdTokens0⟩ := - uniswapV3PoolBurnPositionUpdateStoreTokensOwed0 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdFee1 (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdTokens1⟩ := - uniswapV3PoolBurnPositionUpdateStoreTokensOwed1 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdTokens0 (by simp [postFreeR] at hov ⊢; omega) - have hdelta : UInt256.signextend ⟨15⟩ delta = ⟨0⟩ := by - dsimp [delta] - rw [hzero] - native_decide - obtain ⟨_, _, hrdFallthrough⟩ := - uniswapV3PoolBurnPositionUpdateLiquidityDeltaZeroFallthrough - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hdelta hrdTokens1 (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdNonzero⟩ := - uniswapV3PoolBurnPositionUpdateLiquidityNonzeroJump - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hliq hrdFallthrough (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdReload⟩ := - uniswapV3PoolBurnPositionUpdateReloadLiquidity - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdNonzero (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrd13017⟩ := - uniswapV3PoolBurnPositionUpdateStartMulDiv0 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdReload (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrd21861⟩ := - uniswapV3PoolBurnPositionUpdateMulDivsProd1ZeroStoreFeeGrowthLast - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hperm hrd13017 - (by simpa [inside0, posBase] using hprod0) - (by simpa [inside1, posBase] using hprod1) - hdelta (by simp [postFreeR] at hov ⊢; omega) - exact ⟨_, _, by simpa [inside1, inside0, posBase, delta, postFreeR, tail] using hrd21861⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnZeroDeltaPositionUpdateToMulDivReturnConcreteSlowToken1 - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hperm : ee.perm = true) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord ee) < - tickSpacingSint24Value (burnTickUpperWord ee)) - (hzero : burnAmountCleanWord ee = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)) ≠ ⟨0⟩) - (hprod0 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub (burnTickGetInside0Word σ ee) - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee))) = ⟨0⟩) - (hprod1 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub (burnTickGetInside1Word σ ee) - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee))) ≠ ⟨0⟩) - (hden : - UInt256.gt (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub (burnTickGetInside1Word σ ee) - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)))) ≠ ⟨0⟩) - (h : RD code ee g s0 ⟨21387⟩ - (solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 82 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21861⟩ - (uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub (burnTickGetInside1Word σ ee) - (solcSlotWord σ ee - (burnPositionBaseSlotWord σ ee + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub (burnTickGetInside1Word σ ee) - (solcSlotWord σ ee - (burnPositionBaseSlotWord σ ee + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee))) - (UInt256.sub (burnTickGetInside1Word σ ee) - (solcSlotWord σ ee - (burnPositionBaseSlotWord σ ee + (⟨2⟩ : UInt256)))) :: - UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub (burnTickGetInside0Word σ ee) - (solcSlotWord σ ee - (burnPositionBaseSlotWord σ ee + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) :: - burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)) :: - burnPositionKeyNewFreePtrWord :: - burnTickGetInside1Word σ ee :: burnTickGetInside0Word σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - burnPositionBaseSlotWord σ ee :: ⟨19527⟩ :: - burnTickGetInside1Word σ ee :: burnTickGetInside0Word σ ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R) - (burnPositionUpdateMem5 σ ee - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)) - (burnPositionBaseSlotWord σ ee)) - (UInt256.ofNat 22) rdata - (cA, sstoreAccountMap ee.codeOwner - (sstoreAccountMap ee.codeOwner σ - (burnPositionBaseSlotWord σ ee + (⟨1⟩ : UInt256)) - (burnTickGetInside0Word σ ee)) - (burnPositionBaseSlotWord σ ee + (⟨2⟩ : UInt256)) - (burnTickGetInside1Word σ ee)) k' C' := by - let inside1 := burnTickGetInside1Word σ ee - let inside0 := burnTickGetInside0Word σ ee - let posBase := burnPositionBaseSlotWord σ ee - let delta := UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) - let postFreeR : List UInt256 := - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R - let tail : List UInt256 := - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - posBase :: slot0TickReturnWord σ ee :: - delta :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: postFreeR - obtain ⟨_, _, hrdReturn⟩ := - uniswapV3PoolBurnFeeGrowthInsideEntryReturnConcrete - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (ret := ret) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch htickLt h (by omega) - obtain ⟨_, _, hrdEntry⟩ := - uniswapV3PoolBurnFeeGrowthInsideEnterPositionUpdate - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) - (z0 := ⟨0⟩) (z1 := ⟨0⟩) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase := posBase) (tick := slot0TickReturnWord σ ee) - (delta := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) - hpatch - (by simpa [inside1, inside0, posBase, delta] using hrdReturn) - (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdSlot0⟩ := - uniswapV3PoolBurnPositionUpdateLoadSlot0 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdEntry (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdPacked⟩ := - uniswapV3PoolBurnPositionUpdateStoreSlot0Packed - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (pos0 := solcSlotWord σ ee posBase) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdSlot0 (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdFee0⟩ := - uniswapV3PoolBurnPositionUpdateStoreFeeGrowthInside0Last - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch (by simpa [inside1, inside0, posBase, delta] using hrdPacked) - (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdFee1⟩ := - uniswapV3PoolBurnPositionUpdateStoreFeeGrowthInside1Last - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdFee0 (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdTokens0⟩ := - uniswapV3PoolBurnPositionUpdateStoreTokensOwed0 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdFee1 (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdTokens1⟩ := - uniswapV3PoolBurnPositionUpdateStoreTokensOwed1 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdTokens0 (by simp [postFreeR] at hov ⊢; omega) - have hdelta : UInt256.signextend ⟨15⟩ delta = ⟨0⟩ := by - dsimp [delta] - rw [hzero] - native_decide - obtain ⟨_, _, hrdFallthrough⟩ := - uniswapV3PoolBurnPositionUpdateLiquidityDeltaZeroFallthrough - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hdelta hrdTokens1 (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdNonzero⟩ := - uniswapV3PoolBurnPositionUpdateLiquidityNonzeroJump - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hliq hrdFallthrough (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdReload⟩ := - uniswapV3PoolBurnPositionUpdateReloadLiquidity - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdNonzero (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrd13017⟩ := - uniswapV3PoolBurnPositionUpdateStartMulDiv0 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdReload (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrd21861⟩ := - uniswapV3PoolBurnPositionUpdateMulDiv0Prod1ZeroMulDiv1Prod1NonzeroStoreFeeGrowthLast - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hperm hrd13017 - (by simpa [inside0, posBase] using hprod0) - (by simpa [inside1, posBase] using hprod1) - (by simpa [inside1, posBase] using hden) - hdelta (by simp [postFreeR] at hov ⊢; omega) - exact ⟨_, _, by simpa [inside1, inside0, posBase, delta, postFreeR, tail] using hrd21861⟩ - -theorem burnPositionUpdateTokensOwedState_stateEquiv_of_addedSlot3 - {evmEvm evmSolm : EVM.State} {σ I} - {feeGrowthInside0X128 feeGrowthInside1X128 tokensOwed0 tokensOwed1 : UInt256} - (hstate : EVMStateEquiv evmEvm evmSolm) - (hword : - burnPositionUpdateSourceTokensOwed1StoreWord - (burnPositionUpdateSourceAfterTokensOwed0State evmSolm σ I feeGrowthInside0X128) - σ I feeGrowthInside1X128 = - burnPositionUpdateTokensOwedAddedSlot3 - (Solm.EVM.storageLoad evmEvm evmEvm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I)) - tokensOwed0 tokensOwed1) : - EVMStateEquiv - (Solm.EVM.storageStore evmEvm evmEvm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateTokensOwedAddedSlot3 - (Solm.EVM.storageLoad evmEvm evmEvm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I)) - tokensOwed0 tokensOwed1)) - (burnPositionUpdateSourceAfterTokensOwedState evmSolm σ I - feeGrowthInside0X128 feeGrowthInside1X128) := by - exact burnPositionUpdateTokensOwedState_stateEquiv_of_final_word hstate hword - -theorem burnPositionUpdateTokensOwedAccountMapEquiv_of_addedSlot3 - {evmEvm evmSolm : EVM.State} {σ I} - {feeGrowthInside0X128 feeGrowthInside1X128 tokensOwed0 tokensOwed1 : UInt256} - (hstate : EVMStateEquiv evmEvm evmSolm) - (hword : - burnPositionUpdateSourceTokensOwed1StoreWord - (burnPositionUpdateSourceAfterTokensOwed0State evmSolm σ I feeGrowthInside0X128) - σ I feeGrowthInside1X128 = - burnPositionUpdateTokensOwedAddedSlot3 - (Solm.EVM.storageLoad evmEvm evmEvm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I)) - tokensOwed0 tokensOwed1) : - accountMapEquiv - (sstoreAccountMap evmEvm.executionEnv.codeOwner evmEvm.accountMap - (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateTokensOwedAddedSlot3 - (Solm.EVM.storageLoad evmEvm evmEvm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I)) - tokensOwed0 tokensOwed1)) - (burnPositionUpdateSourceAfterTokensOwedState evmSolm σ I - feeGrowthInside0X128 feeGrowthInside1X128).accountMap := by - have hstate' := - burnPositionUpdateTokensOwedState_stateEquiv_of_addedSlot3 - (evmEvm := evmEvm) (evmSolm := evmSolm) (σ := σ) (I := I) - (feeGrowthInside0X128 := feeGrowthInside0X128) - (feeGrowthInside1X128 := feeGrowthInside1X128) - (tokensOwed0 := tokensOwed0) (tokensOwed1 := tokensOwed1) hstate hword - simpa [storageStore_accountMap] using hstate'.accountMap - -theorem uniswapV3PoolBurnPositionUpdateZeroDeltaReturnToCallerByTokensCases - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity inside1 inside0 delta posBase inside1' inside0' - z2 z3 fee1 fee0 posBase' tick delta' upper lower owner free r1 r2 r3 callerRet : - UInt256} - {R : List UInt256} {mem : ByteArray} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains callerRet = true) - (hperm : ee.perm = true) - (hzero : burnAmountCleanWord ee = ⟨0⟩) - (hmload224 : - (if (⟨224⟩ : UInt256).toNat ≥ mem.size - ∨ (⟨224⟩ : UInt256) ≥ UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (mem.readWithPadding (⟨224⟩ : UInt256).toNat 32))) = - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee))) - (h : RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: ⟨19527⟩ :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ⟨16428⟩ :: free :: r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) - mem (UInt256.ofNat 22) rdata (cA, σ) k C) - (hdelta : UInt256.slt (UInt256.signextend ⟨15⟩ delta') ⟨0⟩ = ⟨0⟩) - (hov : R.length + 40 ≤ 1024) : - (∃ k' C', RD code ee g s0 callerRet (r1 :: r2 :: posBase' :: R) - mem (UInt256.ofNat 22) rdata (cA, σ) k' C' ∧ - UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 = ⟨0⟩ ∧ - UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 = ⟨0⟩) ∨ - (∃ k' C', RD code ee g s0 callerRet (r1 :: r2 :: posBase' :: R) - mem (UInt256.ofNat 22) rdata - (cA, sstoreAccountMap ee.codeOwner σ (posBase + (⟨3⟩ : UInt256)) - (burnPositionUpdateTokensOwedAddedSlot3 - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256))) tokensOwed0 tokensOwed1)) - k' C' ∧ - (UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 ≠ ⟨0⟩ ∨ - UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 ≠ ⟨0⟩)) := by - by_cases htokens0 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 = ⟨0⟩ - · by_cases htokens1 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 = ⟨0⟩ - · obtain ⟨_, _, hrd⟩ := - uniswapV3PoolBurnPositionUpdateTokensOwedZeroZeroDeltaReturnToCallerGeneric - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (inside1 := inside1) (inside0 := inside0) - (delta := delta) (posBase := posBase) (inside1' := inside1') - (inside0' := inside0') (z2 := z2) (z3 := z3) (fee1 := fee1) - (fee0 := fee0) (posBase' := posBase') (tick := tick) (delta' := delta') - (upper := upper) (lower := lower) (owner := owner) (free := free) - (r1 := r1) (r2 := r2) (r3 := r3) (callerRet := callerRet) - (R := R) (mem := mem) (rdata := rdata) (acc := (cA, σ)) - hpatch hdest hzero hmload224 h htokens0 htokens1 hdelta hov - exact Or.inl ⟨_, _, hrd, htokens0, htokens1⟩ - · obtain ⟨_, _, hrd⟩ := - uniswapV3PoolBurnPositionUpdateTokensOwed1NonzeroZeroDeltaReturnToCaller - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (inside1 := inside1) (inside0 := inside0) - (delta := delta) (posBase := posBase) (inside1' := inside1') - (inside0' := inside0') (z2 := z2) (z3 := z3) (fee1 := fee1) - (fee0 := fee0) (posBase' := posBase') (tick := tick) (delta' := delta') - (upper := upper) (lower := lower) (owner := owner) (free := free) - (r1 := r1) (r2 := r2) (r3 := r3) (callerRet := callerRet) - (R := R) (mem := mem) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hdest hperm hzero hmload224 h htokens0 htokens1 hdelta hov - exact Or.inr ⟨_, _, hrd, Or.inr htokens1⟩ - · obtain ⟨_, _, hrd⟩ := - uniswapV3PoolBurnPositionUpdateTokensOwed0NonzeroZeroDeltaReturnToCaller - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (inside1 := inside1) (inside0 := inside0) - (delta := delta) (posBase := posBase) (inside1' := inside1') - (inside0' := inside0') (z2 := z2) (z3 := z3) (fee1 := fee1) - (fee0 := fee0) (posBase' := posBase') (tick := tick) (delta' := delta') - (upper := upper) (lower := lower) (owner := owner) (free := free) - (r1 := r1) (r2 := r2) (r3 := r3) (callerRet := callerRet) - (R := R) (mem := mem) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hdest hperm hzero hmload224 h htokens0 hdelta hov - exact Or.inr ⟨_, _, hrd, Or.inl htokens0⟩ - -theorem uniswapV3PoolBurnPositionUpdateZeroDeltaReturnToCallerByTokens - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity inside1 inside0 delta posBase inside1' inside0' - z2 z3 fee1 fee0 posBase' tick delta' upper lower owner free r1 r2 r3 callerRet : - UInt256} - {R : List UInt256} {mem : ByteArray} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains callerRet = true) - (hperm : ee.perm = true) - (hzero : burnAmountCleanWord ee = ⟨0⟩) - (hmload224 : - (if (⟨224⟩ : UInt256).toNat ≥ mem.size - ∨ (⟨224⟩ : UInt256) ≥ UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (mem.readWithPadding (⟨224⟩ : UInt256).toNat 32))) = - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee))) - (h : RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: ⟨19527⟩ :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ⟨16428⟩ :: free :: r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) - mem (UInt256.ofNat 22) rdata (cA, σ) k C) - (hdelta : UInt256.slt (UInt256.signextend ⟨15⟩ delta') ⟨0⟩ = ⟨0⟩) - (hov : R.length + 40 ≤ 1024) : - ∃ acc' k' C', RD code ee g s0 callerRet (r1 :: r2 :: posBase' :: R) - mem (UInt256.ofNat 22) rdata acc' k' C' := by - obtain hcases := - uniswapV3PoolBurnPositionUpdateZeroDeltaReturnToCallerByTokensCases - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (inside1 := inside1) (inside0 := inside0) - (delta := delta) (posBase := posBase) (inside1' := inside1') - (inside0' := inside0') (z2 := z2) (z3 := z3) (fee1 := fee1) - (fee0 := fee0) (posBase' := posBase') (tick := tick) (delta' := delta') - (upper := upper) (lower := lower) (owner := owner) (free := free) - (r1 := r1) (r2 := r2) (r3 := r3) (callerRet := callerRet) - (R := R) (mem := mem) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hdest hperm hzero hmload224 h hdelta hov - rcases hcases with hzeroTokens | hsomeTokens - · rcases hzeroTokens with ⟨k', C', hrd, _, _⟩ - exact ⟨(cA, σ), k', C', hrd⟩ - · rcases hsomeTokens with ⟨k', C', hrd, _⟩ - exact ⟨_, k', C', hrd⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedPacking.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedPacking.lean deleted file mode 100644 index 9aba845a..00000000 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedPacking.lean +++ /dev/null @@ -1,551 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdateSourceSuccess -import Benchmarks.UniswapV3Pool.BurnPositionUpdatePostReturn - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem burnWordSubInt_ofNat_toNat_eq (a b : UInt256) : - burnWordSubInt (Int.ofNat a.toNat) (Int.ofNat b.toNat) = - Int.ofNat (UInt256.sub a b).toNat := by - unfold burnWordSubInt - by_cases hle : b.toNat ≤ a.toNat - · rw [usub_toNat (a := a) (b := b) hle] - have hnonneg : 0 ≤ (a.toNat : Int) - (b.toNat : Int) := by omega - have hlt : (a.toNat : Int) - (b.toNat : Int) < (2 ^ 256 : Int) := by - have ha : a.toNat < UInt256.size := a.val.isLt - norm_num [UInt256.size] at ha ⊢ - omega - change ((a.toNat : Int) - (b.toNat : Int)) % (2 ^ 256 : Int) = - Int.ofNat (a.toNat - b.toNat) - rw [Int.emod_eq_of_lt hnonneg hlt] - norm_num - omega - · have hltab : a.toNat < b.toNat := Nat.lt_of_not_ge hle - rw [usub_toNat_underflow (a := a) (b := b) hltab] - have ha : a.toNat < UInt256.size := a.val.isLt - have hb : b.toNat < UInt256.size := b.val.isLt - have hwrappedNonneg : 0 ≤ (UInt256.size + a.toNat - b.toNat : Int) := by - norm_num [UInt256.size] at ha hb ⊢ - omega - have hwrappedLt : (UInt256.size + a.toNat - b.toNat : Int) < (2 ^ 256 : Int) := by - norm_num [UInt256.size] at ha hb ⊢ - omega - have hdiff : - (a.toNat : Int) - (b.toNat : Int) = - (UInt256.size + a.toNat - b.toNat : Int) + (-1 : Int) * (2 ^ 256 : Int) := by - norm_num [UInt256.size] at ha hb ⊢ - omega - change ((a.toNat : Int) - (b.toNat : Int)) % (2 ^ 256 : Int) = - Int.ofNat (UInt256.size + a.toNat - b.toNat) - rw [hdiff] - rw [Int.add_mul_emod_self_right] - rw [Int.emod_eq_of_lt hwrappedNonneg hwrappedLt] - norm_num [UInt256.size] at ha hb ⊢ - omega - -theorem burnFullMathProd0Div128Mask_toNat (a b : UInt256) : - (UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div (uniswapV3PoolFullMathMulDivProd0 a b) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩))).toNat = - (a.toNat * b.toNat / 2 ^ 128) % 2 ^ 128 := by - rw [burnPositionUpdateSlot0Mask_eq_uint128Mask] - rw [u256_land_toNat, uint128Mask_toNat] - rw [nat_land_comm] - rw [nat_land_mask_eq_mod] - rw [Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 128)) - (by norm_num [UInt256.size]))] - rw [udiv_toNat] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩).toNat = 2 ^ 128 by - native_decide] - rw [uniswapV3PoolFullMathMulDivProd0, u256_mul_toNat] - rw [show UInt256.size = 2 ^ 256 by rfl] - rw [show ((b.toNat * a.toNat % 2 ^ 256) / 2 ^ 128) % 2 ^ 128 = - (b.toNat * a.toNat / 2 ^ 128) % 2 ^ 128 by omega] - rw [Nat.mul_comm] - -theorem burnPositionUpdateSourceTokensOwed0Int_eq_maskedWord - (σ : AccountMap) (I : ExecutionEnv) (feeGrowthInside0X128 : UInt256) : - burnPositionUpdateSourceTokensOwed0Int σ I (Int.ofNat feeGrowthInside0X128.toNat) = - Int.ofNat - (UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨1⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩))).toNat := by - rw [burnFullMathProd0Div128Mask_toNat] - unfold burnPositionUpdateSourceTokensOwed0Int - rw [burnWordSubInt_ofNat_toNat_eq] - simp only [burnPositionUpdateSourceLiquidityInt] - norm_num - -theorem burnPositionUpdateSourceTokensOwed1Int_eq_maskedWord - (σ : AccountMap) (I : ExecutionEnv) (feeGrowthInside1X128 : UInt256) : - burnPositionUpdateSourceTokensOwed1Int σ I (Int.ofNat feeGrowthInside1X128.toNat) = - Int.ofNat - (UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩))).toNat := by - rw [burnFullMathProd0Div128Mask_toNat] - unfold burnPositionUpdateSourceTokensOwed1Int - rw [burnWordSubInt_ofNat_toNat_eq] - simp only [burnPositionUpdateSourceLiquidityInt] - norm_num - -theorem burnPositionUpdateSourceTokensOwed0Int_eq_zero_of_mask_eq_zero - {σ : AccountMap} {I : ExecutionEnv} {feeGrowthInside0X128 : UInt256} - (h : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨1⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = ⟨0⟩) : - burnPositionUpdateSourceTokensOwed0Int σ I (Int.ofNat feeGrowthInside0X128.toNat) = 0 := by - rw [burnPositionUpdateSourceTokensOwed0Int_eq_maskedWord] - rw [h] - rfl - -theorem burnPositionUpdateSourceTokensOwed1Int_eq_zero_of_mask_eq_zero - {σ : AccountMap} {I : ExecutionEnv} {feeGrowthInside1X128 : UInt256} - (h : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = ⟨0⟩) : - burnPositionUpdateSourceTokensOwed1Int σ I (Int.ofNat feeGrowthInside1X128.toNat) = 0 := by - rw [burnPositionUpdateSourceTokensOwed1Int_eq_maskedWord] - rw [h] - rfl - -theorem burnPositionUpdateSourceTokensOwed0Int_pos_of_mask_ne_zero - {σ : AccountMap} {I : ExecutionEnv} {feeGrowthInside0X128 : UInt256} - (h : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨1⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) ≠ ⟨0⟩) : - 0 < burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat) := by - rw [burnPositionUpdateSourceTokensOwed0Int_eq_maskedWord] - have hpos : 0 < - (UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨1⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩))).toNat := - Nat.pos_of_ne_zero (by - intro hzero - exact h (uint256_toNat_eq_zero hzero)) - exact (Nat.cast_pos (α := Int)).2 hpos - -theorem burnPositionUpdateSourceTokensOwed1Int_pos_of_mask_ne_zero - {σ : AccountMap} {I : ExecutionEnv} {feeGrowthInside1X128 : UInt256} - (h : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) ≠ ⟨0⟩) : - 0 < burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat) := by - rw [burnPositionUpdateSourceTokensOwed1Int_eq_maskedWord] - have hpos : 0 < - (UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩))).toNat := - Nat.pos_of_ne_zero (by - intro hzero - exact h (uint256_toNat_eq_zero hzero)) - exact (Nat.cast_pos (α := Int)).2 hpos - -theorem burnPositionUpdateSourceTokensOwed1Int_eq_zero_of_slow_mask_eq_zero - {σ : AccountMap} {I : ExecutionEnv} {feeGrowthInside1X128 : UInt256} - (h : - UInt256.land burnPositionUpdateSlot0Mask - (uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I)))) - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩)))) = - ⟨0⟩) : - burnPositionUpdateSourceTokensOwed1Int σ I (Int.ofNat feeGrowthInside1X128.toNat) = - 0 := by - let a := UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩)) - let b := burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) - exact burnPositionUpdateSourceTokensOwed1Int_eq_zero_of_mask_eq_zero - (σ := σ) (I := I) (feeGrowthInside1X128 := feeGrowthInside1X128) - (by - have hlow := uniswapV3PoolFullMathMulDivSlowResult_low128_eq_prod0Div128 a b - rw [← hlow] - simpa [a, b] using h) - -theorem burnPositionUpdateSourceTokensOwed1Int_pos_of_slow_mask_ne_zero - {σ : AccountMap} {I : ExecutionEnv} {feeGrowthInside1X128 : UInt256} - (h : - UInt256.land burnPositionUpdateSlot0Mask - (uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I)))) - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩)))) ≠ - ⟨0⟩) : - 0 < burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat) := by - let a := UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩)) - let b := burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) - exact burnPositionUpdateSourceTokensOwed1Int_pos_of_mask_ne_zero - (σ := σ) (I := I) (feeGrowthInside1X128 := feeGrowthInside1X128) - (by - have hlow := uniswapV3PoolFullMathMulDivSlowResult_low128_eq_prod0Div128 a b - intro hzero - exact h (by - rw [hlow] - simpa [a, b] using hzero)) - -private theorem burnPositionUpdateLandMaskAddLow_toNat (a b : UInt256) : - (UInt256.land uint128Mask (a + UInt256.land uint128Mask b)).toNat = - (a.toNat + b.toNat % 2 ^ 128) % 2 ^ 128 := by - rw [u256_land_comm] - rw [u256_land_toNat, uint128Mask_toNat, nat_land_mask_eq_mod] - rw [uadd_toNat] - have hlowB : (UInt256.land uint128Mask b).toNat = b.toNat % 2 ^ 128 := by - rw [u256_land_comm] - rw [u256_land_toNat, uint128Mask_toNat, nat_land_mask_eq_mod] - rw [Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 128)) - (by norm_num [UInt256.size]))] - rw [hlowB] - have hdiv : 2 ^ 128 ∣ UInt256.size := by - change 2 ^ 128 ∣ 2 ^ 256 - exact Nat.pow_dvd_pow 2 (by omega) - rw [Nat.mod_mod_of_dvd _ hdiv] - rw [Nat.add_mod] - rw [Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 128)) - (by norm_num [UInt256.size]))] - -private theorem burnPositionUpdateMaskedWordOfIntAdd_eq_landMaskAdd - (base token : UInt256) : - UInt256.land - (EVM.wordOfInt - (Int.ofNat (UInt256.land base uint128Mask).toNat + - Int.ofNat (UInt256.land burnPositionUpdateSlot0Mask token).toNat)) - uint128Mask = - UInt256.land burnPositionUpdateSlot0Mask - (token + UInt256.land burnPositionUpdateSlot0Mask base) := by - apply u256_inj - rw [burnPositionUpdateSlot0Mask_eq_uint128Mask] - rw [show EVM.wordOfInt - (Int.ofNat (UInt256.land base uint128Mask).toNat + - Int.ofNat (UInt256.land uint128Mask token).toNat) = - UInt256.ofNat ((UInt256.land base uint128Mask).toNat + - (UInt256.land uint128Mask token).toNat) by - rw [wordOfInt_nonneg _ (by - exact Int.add_nonneg (Int.natCast_nonneg _) (Int.natCast_nonneg _))] - rfl] - rw [u256_land_toNat, uint128Mask_toNat, nat_land_mask_eq_mod] - rw [ulit_toNat' _ (by - have h0 := uint128Mask_bound base - have h1 := uint128Mask_bound token - rw [u256_land_comm] at h1 - have h0le : (UInt256.land base uint128Mask).toNat ≤ 2 ^ 128 - 1 := - Nat.le_pred_of_lt h0 - have h1le : (UInt256.land uint128Mask token).toNat ≤ 2 ^ 128 - 1 := - Nat.le_pred_of_lt h1 - have hsum := Nat.add_le_add h0le h1le - have hmax : (2 ^ 128 - 1) + (2 ^ 128 - 1) < UInt256.size := by - norm_num [UInt256.size] - exact lt_of_le_of_lt hsum hmax)] - rw [Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 128)) - (by norm_num [UInt256.size]))] - rw [show (UInt256.land base uint128Mask).toNat = base.toNat % 2 ^ 128 by - rw [u256_land_toNat, uint128Mask_toNat, nat_land_mask_eq_mod] - rw [Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 128)) - (by norm_num [UInt256.size]))]] - rw [show (UInt256.land uint128Mask token).toNat = token.toNat % 2 ^ 128 by - rw [u256_land_comm] - rw [u256_land_toNat, uint128Mask_toNat, nat_land_mask_eq_mod] - rw [Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 128)) - (by norm_num [UInt256.size]))]] - rw [burnPositionUpdateLandMaskAddLow_toNat] - omega - -private theorem burnPositionUpdateSourceTokensOwed0StoreWord_eq_addedSlot3Low - (old token : UInt256) : - UInt256.lor - (UInt256.land - (EVM.wordOfInt - (Int.ofNat (UInt256.land old uint128Mask).toNat + - Int.ofNat (UInt256.land burnPositionUpdateSlot0Mask token).toNat)) - uint128Mask) - (UInt256.land (UInt256.lnot uint128Mask) old) = - burnPositionUpdateTokensOwed0AddedSlot3 old token := by - rw [burnPositionUpdateMaskedWordOfIntAdd_eq_landMaskAdd] - unfold burnPositionUpdateTokensOwed0AddedSlot3 - rw [burnPositionUpdateSlot0Mask_eq_uint128Mask] - rw [u256_land_comm old (UInt256.lnot uint128Mask)] - -private theorem burnPositionUpdateSourceTokensOwed1StoreWord_eq_addedSlot3High - (old token : UInt256) : - UInt256.lor - (UInt256.mul - (UInt256.land - (EVM.wordOfInt - (Int.ofNat (UInt256.land (UInt256.div old - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) uint128Mask).toNat + - Int.ofNat (UInt256.land burnPositionUpdateSlot0Mask token).toNat)) - uint128Mask) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (UInt256.land old uint128Mask) = - UInt256.lor - (UInt256.mul - (UInt256.land burnPositionUpdateSlot0Mask - (token + UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div old (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (UInt256.land burnPositionUpdateSlot0Mask old) := by - rw [burnPositionUpdateMaskedWordOfIntAdd_eq_landMaskAdd] - rw [burnPositionUpdateSlot0Mask_eq_uint128Mask] - rw [u256_land_comm uint128Mask old] - -set_option maxHeartbeats 1000000 in -theorem burnPositionUpdateSourceTokensOwedFinalStoreWord_eq_addedSlot3 - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hload : - Solm.EVM.storageLoad - (burnPositionUpdateSourceAfterTokensOwed0State evm σ I feeGrowthInside0X128) - (burnPositionUpdateSourceAfterTokensOwed0State evm σ I - feeGrowthInside0X128).executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) = - burnPositionUpdateSourceTokensOwed0StoreWord evm σ I feeGrowthInside0X128) : - burnPositionUpdateSourceTokensOwed1StoreWord - (burnPositionUpdateSourceAfterTokensOwed0State evm σ I feeGrowthInside0X128) - σ I feeGrowthInside1X128 = - burnPositionUpdateTokensOwedAddedSlot3 - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I)) - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨1⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) := by - let old := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) - let token0 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨1⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - let token1 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - have hword0 : - burnPositionUpdateSourceTokensOwed0StoreWord evm σ I feeGrowthInside0X128 = - burnPositionUpdateTokensOwed0AddedSlot3 old token0 := by - unfold burnPositionUpdateSourceTokensOwed0StoreWord - unfold burnPositionUpdateSourceTokensOwed0WriteInt - unfold burnPositionUpdateSourceStoredTokensOwed0Int - rw [burnPositionUpdateSourceTokensOwed0Int_eq_maskedWord] - simpa [old, token0] using - burnPositionUpdateSourceTokensOwed0StoreWord_eq_addedSlot3Low old token0 - unfold burnPositionUpdateSourceTokensOwed1StoreWord - unfold burnPositionUpdateSourceTokensOwed1WriteInt - unfold burnPositionUpdateSourceStoredTokensOwed1Int - rw [hload] - rw [hword0] - rw [burnPositionUpdateSourceTokensOwed1Int_eq_maskedWord] - simpa [old, token0, token1, burnPositionUpdateTokensOwedAddedSlot3] using - burnPositionUpdateSourceTokensOwed1StoreWord_eq_addedSlot3High - (burnPositionUpdateTokensOwed0AddedSlot3 old token0) token1 - -private theorem burnPositionUpdateLandMask_add_low_eq_of_low_eq - {a a' b : UInt256} - (h : - UInt256.land burnPositionUpdateSlot0Mask a = - UInt256.land burnPositionUpdateSlot0Mask a') : - UInt256.land burnPositionUpdateSlot0Mask - (a + UInt256.land burnPositionUpdateSlot0Mask b) = - UInt256.land burnPositionUpdateSlot0Mask - (a' + UInt256.land burnPositionUpdateSlot0Mask b) := by - apply u256_inj - rw [burnPositionUpdateSlot0Mask_eq_uint128Mask] at h ⊢ - rw [burnPositionUpdateLandMaskAddLow_toNat] - rw [burnPositionUpdateLandMaskAddLow_toNat] - have hmask (x : UInt256) : - (UInt256.land uint128Mask x).toNat = x.toNat % 2 ^ 128 := by - rw [u256_land_toNat, uint128Mask_toNat, nat_land_comm, nat_land_mask_eq_mod] - rw [Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 128)) - (by norm_num [UInt256.size]))] - have hlow := congrArg UInt256.toNat h - rw [hmask a, hmask a'] at hlow - rw [Nat.add_mod, Nat.add_mod] - rw [hlow] - simp [Nat.add_mod] - -theorem burnPositionUpdateTokensOwed0AddedSlot3_eq_of_low128 - {old token0 token0' : UInt256} - (h0 : - UInt256.land burnPositionUpdateSlot0Mask token0 = - UInt256.land burnPositionUpdateSlot0Mask token0') : - burnPositionUpdateTokensOwed0AddedSlot3 old token0 = - burnPositionUpdateTokensOwed0AddedSlot3 old token0' := by - unfold burnPositionUpdateTokensOwed0AddedSlot3 - rw [burnPositionUpdateLandMask_add_low_eq_of_low_eq h0] - -theorem burnPositionUpdateTokensOwedAddedSlot3_eq_of_low128 - {old token0 token0' token1 token1' : UInt256} - (h0 : - UInt256.land burnPositionUpdateSlot0Mask token0 = - UInt256.land burnPositionUpdateSlot0Mask token0') - (h1 : - UInt256.land burnPositionUpdateSlot0Mask token1 = - UInt256.land burnPositionUpdateSlot0Mask token1') : - burnPositionUpdateTokensOwedAddedSlot3 old token0 token1 = - burnPositionUpdateTokensOwedAddedSlot3 old token0' token1' := by - have h0word := burnPositionUpdateTokensOwed0AddedSlot3_eq_of_low128 - (old := old) h0 - unfold burnPositionUpdateTokensOwedAddedSlot3 - rw [h0word] - rw [burnPositionUpdateLandMask_add_low_eq_of_low_eq h1] - -theorem burnPositionUpdateSourceTokensOwedFinalStoreWord_eq_addedSlot3_of_low128 - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (feeGrowthInside0X128 feeGrowthInside1X128 tokensOwed0 tokensOwed1 : UInt256) - (hload : - Solm.EVM.storageLoad - (burnPositionUpdateSourceAfterTokensOwed0State evm σ I feeGrowthInside0X128) - (burnPositionUpdateSourceAfterTokensOwed0State evm σ I - feeGrowthInside0X128).executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) = - burnPositionUpdateSourceTokensOwed0StoreWord evm σ I feeGrowthInside0X128) - (h0 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨1⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed0) - (h1 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed1) : - burnPositionUpdateSourceTokensOwed1StoreWord - (burnPositionUpdateSourceAfterTokensOwed0State evm σ I feeGrowthInside0X128) - σ I feeGrowthInside1X128 = - burnPositionUpdateTokensOwedAddedSlot3 - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I)) - tokensOwed0 tokensOwed1 := by - let token0 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨1⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - let token1 := UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1X128 - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I) + ⟨2⟩))) - (burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - have hfast := - burnPositionUpdateSourceTokensOwedFinalStoreWord_eq_addedSlot3 - evm σ I feeGrowthInside0X128 feeGrowthInside1X128 hload - rw [hfast] - exact burnPositionUpdateTokensOwedAddedSlot3_eq_of_low128 - (old := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I)) - (token0 := token0) (token0' := tokensOwed0) - (token1 := token1) (token1' := tokensOwed1) - (by simpa [token0] using h0) (by simpa [token1] using h1) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedStore.lean b/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedStore.lean deleted file mode 100644 index 786d7fc2..00000000 --- a/Benchmarks/UniswapV3Pool/BurnPositionUpdateTokensOwedStore.lean +++ /dev/null @@ -1,786 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdatePostReturn - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem uniswapV3PoolBurnPositionUpdateTokensOwedStoreDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 21807 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21986) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 21986 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -theorem uniswapV3PoolBurnPositionUpdateTokensOwed1NonzeroStore {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity freePtr inside1 inside0 delta posBase retPos - inside1' inside0' z2 z3 fee1 fee0 posBase' tick delta' upper lower owner ret - free : UInt256} - {R : List UInt256} {mem : ByteArray} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hperm : ee.perm = true) - (h : RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: freePtr :: inside1 :: inside0 :: - delta :: posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: - fee0 :: posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: - free :: R) - mem aw rdata (cA, σ) k C) - (htokens0 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 = ⟨0⟩) - (htokens1 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 ≠ ⟨0⟩) - (hov : R.length + 35 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21954⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: freePtr :: inside1 :: inside0 :: - delta :: posBase :: retPos :: inside1' :: inside0' :: z2 :: z3 :: fee1 :: - fee0 :: posBase' :: tick :: delta' :: upper :: lower :: owner :: ret :: - free :: R) - mem aw rdata - (cA, sstoreAccountMap ee.codeOwner σ (posBase + (⟨3⟩ : UInt256)) - (burnPositionUpdateTokensOwedAddedSlot3 - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256))) tokensOwed0 tokensOwed1)) - k' C' := by - have hdec (pc : UInt256) - (hlo : 21807 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21930) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateTokensOwedStoreDecodeEqTemplate hpatch hlo - (by omega) - have hd21861 : - decode code ⟨21861⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21861⟩ (by native_decide) (by native_decide)] - native_decide - have hd21863 : - decode code ⟨21863⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21863⟩ (by native_decide) (by native_decide)] - native_decide - have hd21865 : - decode code ⟨21865⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21865⟩ (by native_decide) (by native_decide)] - native_decide - have hd21867 : decode code ⟨21867⟩ = some (.SHL, .none) := by - rw [hdec ⟨21867⟩ (by native_decide) (by native_decide)] - native_decide - have hd21868 : decode code ⟨21868⟩ = some (.SUB, .none) := by - rw [hdec ⟨21868⟩ (by native_decide) (by native_decide)] - native_decide - have hd21869 : decode code ⟨21869⟩ = some (.DUP3, .none) := by - rw [hdec ⟨21869⟩ (by native_decide) (by native_decide)] - native_decide - have hd21870 : decode code ⟨21870⟩ = some (.AND, .none) := by - rw [hdec ⟨21870⟩ (by native_decide) (by native_decide)] - native_decide - have hd21871 : decode code ⟨21871⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨21871⟩ (by native_decide) (by native_decide)] - native_decide - have hd21872 : decode code ⟨21872⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨21872⟩ (by native_decide) (by native_decide)] - native_decide - have hd21873 : decode code ⟨21873⟩ = some (.DUP1, .none) := by - rw [hdec ⟨21873⟩ (by native_decide) (by native_decide)] - native_decide - have hd21874 : - decode code ⟨21874⟩ = some (.Push .PUSH2, some (⟨21892⟩, 2)) := by - rw [hdec ⟨21874⟩ (by native_decide) (by native_decide)] - native_decide - have hd21877 : decode code ⟨21877⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨21877⟩ (by native_decide) (by native_decide)] - native_decide - have hd21878 : decode code ⟨21878⟩ = some (.POP, .none) := by - rw [hdec ⟨21878⟩ (by native_decide) (by native_decide)] - native_decide - have hd21879 : - decode code ⟨21879⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨21879⟩ (by native_decide) (by native_decide)] - native_decide - have hd21881 : decode code ⟨21881⟩ = some (.DUP2, .none) := by - rw [hdec ⟨21881⟩ (by native_decide) (by native_decide)] - native_decide - have hd21882 : - decode code ⟨21882⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21882⟩ (by native_decide) (by native_decide)] - native_decide - have hd21884 : - decode code ⟨21884⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21884⟩ (by native_decide) (by native_decide)] - native_decide - have hd21886 : - decode code ⟨21886⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21886⟩ (by native_decide) (by native_decide)] - native_decide - have hd21888 : decode code ⟨21888⟩ = some (.SHL, .none) := by - rw [hdec ⟨21888⟩ (by native_decide) (by native_decide)] - native_decide - have hd21889 : decode code ⟨21889⟩ = some (.SUB, .none) := by - rw [hdec ⟨21889⟩ (by native_decide) (by native_decide)] - native_decide - have hd21890 : decode code ⟨21890⟩ = some (.AND, .none) := by - rw [hdec ⟨21890⟩ (by native_decide) (by native_decide)] - native_decide - have hd21891 : decode code ⟨21891⟩ = some (.GT, .none) := by - rw [hdec ⟨21891⟩ (by native_decide) (by native_decide)] - native_decide - have hd21892 : decode code ⟨21892⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨21892⟩ (by native_decide) (by native_decide)] - native_decide - have hd21893 : decode code ⟨21893⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨21893⟩ (by native_decide) (by native_decide)] - native_decide - have hd21894 : - decode code ⟨21894⟩ = some (.Push .PUSH2, some (⟨21954⟩, 2)) := by - rw [hdec ⟨21894⟩ (by native_decide) (by native_decide)] - native_decide - have hd21897 : decode code ⟨21897⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨21897⟩ (by native_decide) (by native_decide)] - native_decide - have rd21877 := evm_run h with [ - raw push1 ⟨1⟩ hd21861 (by evm_ov), - raw push1 ⟨1⟩ hd21863 (by evm_ov), - raw push1 ⟨128⟩ hd21865 (by evm_ov), - raw shl hd21867 (by evm_ov), - raw sub hd21868 (by evm_ov), - raw dup3 hd21869 (by simp only [List.length_cons] at hov ⊢; omega), - raw and hd21870 (by evm_ov), - raw iszero hd21871 (by evm_ov), - raw iszero hd21872 (by evm_ov), - raw dup1 hd21873 (by simp only [List.length_cons] at hov ⊢; omega), - raw push2 ⟨21892⟩ hd21874 (by evm_ov)] - have hcond0 : - UInt256.isZero - (UInt256.isZero (UInt256.land tokensOwed0 burnPositionUpdateSlot0Mask)) = - ⟨0⟩ := by - rw [u256_land_comm tokensOwed0 burnPositionUpdateSlot0Mask] - rw [htokens0] - native_decide - have rd21878 := by - simpa [burnPositionUpdateSlot0Mask] using - rd21877.jumpiNT hd21877 hcond0 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21892 := evm_run rd21878 with [ - raw pop hd21878 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨0⟩ hd21879 (by evm_ov), - raw dup2 hd21881 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨1⟩ hd21882 (by evm_ov), - raw push1 ⟨1⟩ hd21884 (by evm_ov), - raw push1 ⟨128⟩ hd21886 (by evm_ov), - raw shl hd21888 (by evm_ov), - raw sub hd21889 (by evm_ov), - raw and hd21890 (by evm_ov), - raw gt hd21891 (by evm_ov), - raw jumpdest hd21892 (by evm_ov), - raw iszero hd21893 (by evm_ov), - raw push2 ⟨21954⟩ hd21894 (by evm_ov)] - have hgt1 : - UInt256.gt (UInt256.land burnPositionUpdateSlot0Mask tokensOwed1) ⟨0⟩ = ⟨1⟩ := by - apply ugt_one - have hpos : 0 < (UInt256.land burnPositionUpdateSlot0Mask tokensOwed1).toNat := by - apply Nat.pos_of_ne_zero - intro hz - exact htokens1 (uint256_toNat_eq_zero hz) - simpa using hpos - have hcond1 : - UInt256.isZero - (UInt256.gt (UInt256.land burnPositionUpdateSlot0Mask tokensOwed1) ⟨0⟩) = - ⟨0⟩ := by - rw [hgt1] - native_decide - have rd21898 := rd21892.jumpiNT hd21897 hcond1 - (by simp only [List.length_cons] at hov ⊢; omega) - exact uniswapV3PoolBurnPositionUpdateStoreTokensOwedSlot3 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (freePtr := freePtr) (inside1 := inside1) - (inside0 := inside0) (delta := delta) (posBase := posBase) (retPos := retPos) - (inside1' := inside1') (inside0' := inside0') (z2 := z2) (z3 := z3) - (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ret) (free := free) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (cA := cA) (σ := σ) hpatch hperm rd21898 hov - -private theorem uniswapV3PoolBurnModifyPositionReturnToCallerDecodeEqTemplateGeneric - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 16428 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 16841) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 16841 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -theorem uniswapV3PoolBurnModifyPositionReturnZeroAmountToCallerGeneric - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {posBase free r1 r2 r3 ret : UInt256} - {R : List UInt256} {mem : ByteArray} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains ret = true) - (hzero : burnAmountCleanWord ee = ⟨0⟩) - (hmload224 : - (if (⟨224⟩ : UInt256).toNat ≥ mem.size - ∨ (⟨224⟩ : UInt256) ≥ UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (mem.readWithPadding (⟨224⟩ : UInt256).toNat 32))) = - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee))) - (h : RD code ee g s0 ⟨16428⟩ - (posBase :: free :: r1 :: r2 :: r3 :: ⟨128⟩ :: ret :: R) - mem (UInt256.ofNat 22) rdata acc k C) - (hov : R.length + 12 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret (r1 :: r2 :: posBase :: R) - mem (UInt256.ofNat 22) rdata acc k' C' := by - have hdec (pc : UInt256) - (hlo : 16428 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 16841) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnModifyPositionReturnToCallerDecodeEqTemplateGeneric hpatch hlo hhi - have hd16428 : decode code ⟨16428⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨16428⟩ (by native_decide) (by native_decide)] - native_decide - have hd16429 : decode code ⟨16429⟩ = some (.SWAP4, .none) := by - rw [hdec ⟨16429⟩ (by native_decide) (by native_decide)] - native_decide - have hd16430 : decode code ⟨16430⟩ = some (.POP, .none) := by - rw [hdec ⟨16430⟩ (by native_decide) (by native_decide)] - native_decide - have hd16431 : decode code ⟨16431⟩ = some (.DUP5, .none) := by - rw [hdec ⟨16431⟩ (by native_decide) (by native_decide)] - native_decide - have hd16432 : - decode code ⟨16432⟩ = some (.Push .PUSH1, some (⟨96⟩, 1)) := by - rw [hdec ⟨16432⟩ (by native_decide) (by native_decide)] - native_decide - have hd16434 : decode code ⟨16434⟩ = some (.ADD, .none) := by - rw [hdec ⟨16434⟩ (by native_decide) (by native_decide)] - native_decide - have hd16435 : decode code ⟨16435⟩ = some (.MLOAD, .none) := by - rw [hdec ⟨16435⟩ (by native_decide) (by native_decide)] - native_decide - have hd16436 : - decode code ⟨16436⟩ = some (.Push .PUSH1, some (⟨15⟩, 1)) := by - rw [hdec ⟨16436⟩ (by native_decide) (by native_decide)] - native_decide - have hd16438 : decode code ⟨16438⟩ = some (.SIGNEXTEND, .none) := by - rw [hdec ⟨16438⟩ (by native_decide) (by native_decide)] - native_decide - have hd16439 : - decode code ⟨16439⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨16439⟩ (by native_decide) (by native_decide)] - native_decide - have hd16441 : decode code ⟨16441⟩ = some (.EQ, .none) := by - rw [hdec ⟨16441⟩ (by native_decide) (by native_decide)] - native_decide - have hd16442 : - decode code ⟨16442⟩ = some (.Push .PUSH2, some (⟨16801⟩, 2)) := by - rw [hdec ⟨16442⟩ (by native_decide) (by native_decide)] - native_decide - have hd16445 : decode code ⟨16445⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨16445⟩ (by native_decide) (by native_decide)] - native_decide - have hd16801 : decode code ⟨16801⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨16801⟩ (by native_decide) (by native_decide)] - native_decide - have hd16802 : decode code ⟨16802⟩ = some (.POP, .none) := by - rw [hdec ⟨16802⟩ (by native_decide) (by native_decide)] - native_decide - have hd16803 : decode code ⟨16803⟩ = some (.SWAP2, .none) := by - rw [hdec ⟨16803⟩ (by native_decide) (by native_decide)] - native_decide - have hd16804 : decode code ⟨16804⟩ = some (.SWAP4, .none) := by - rw [hdec ⟨16804⟩ (by native_decide) (by native_decide)] - native_decide - have hd16805 : decode code ⟨16805⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨16805⟩ (by native_decide) (by native_decide)] - native_decide - have hd16806 : decode code ⟨16806⟩ = some (.SWAP3, .none) := by - rw [hdec ⟨16806⟩ (by native_decide) (by native_decide)] - native_decide - have hd16807 : decode code ⟨16807⟩ = some (.POP, .none) := by - rw [hdec ⟨16807⟩ (by native_decide) (by native_decide)] - native_decide - have hd16808 : decode code ⟨16808⟩ = some (.JUMP, .none) := by - rw [hdec ⟨16808⟩ (by native_decide) (by native_decide)] - native_decide - have rd16435 := evm_run h with [ - raw jumpdest hd16428 (by evm_ov), - raw swap4 hd16429 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd16430 (by simp only [List.length_cons] at hov ⊢; omega), - raw dup5 hd16431 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨96⟩ hd16432 (by evm_ov), - raw add hd16434 (by evm_ov)] - have rd16436 := by - simpa [show ((⟨128⟩ : UInt256) + ⟨96⟩) = (⟨224⟩ : UInt256) from by decide, - show ((⟨96⟩ : UInt256) + ⟨128⟩) = (⟨224⟩ : UInt256) from by decide] using - rd16435.mload 0 - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee))) - (UInt256.ofNat 22) hd16435 mem_cost hmload224 - (by native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16438 := evm_run rd16436 with [ - raw push1 ⟨15⟩ hd16436 (by evm_ov)] - have rd16439 := by - simpa using burnRDSignextend rd16438 hd16438 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16445 := evm_run rd16439 with [ - raw push1 ⟨0⟩ hd16439 (by evm_ov), - raw eq hd16441 (by evm_ov), - raw push2 ⟨16801⟩ hd16442 (by evm_ov)] - have hcond : - UInt256.eq ⟨0⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)))) ≠ - ⟨0⟩ := by - rw [hzero] - native_decide - have rd16801 := rd16445.jumpiT hd16445 hcond - (uniswapV3PoolJumpDestPatched16801 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd16808 := evm_run rd16801 with [ - raw jumpdest hd16801 (by evm_ov), - raw pop hd16802 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap2 hd16803 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap4 hd16804 (by omega), - raw swap1 hd16805 (by simp only [List.length_cons]; omega), - raw swap3 hd16806 (by simp only [List.length_cons]; omega), - raw pop hd16807 (by simp only [List.length_cons]; omega)] - exact ⟨_, _, rd16808.jump hd16808 hdest - (by simp only [List.length_cons]; omega)⟩ - -theorem uniswapV3PoolBurnPositionUpdateTokensOwed0NonzeroZeroDeltaReturnToCaller - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity inside1 inside0 delta posBase inside1' inside0' - z2 z3 fee1 fee0 posBase' tick delta' upper lower owner free r1 r2 r3 callerRet : - UInt256} - {R : List UInt256} {mem : ByteArray} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains callerRet = true) - (hperm : ee.perm = true) - (hzero : burnAmountCleanWord ee = ⟨0⟩) - (hmload224 : - (if (⟨224⟩ : UInt256).toNat ≥ mem.size - ∨ (⟨224⟩ : UInt256) ≥ UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (mem.readWithPadding (⟨224⟩ : UInt256).toNat 32))) = - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee))) - (h : RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: ⟨19527⟩ :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ⟨16428⟩ :: free :: r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) - mem (UInt256.ofNat 22) rdata (cA, σ) k C) - (htokens0 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 ≠ ⟨0⟩) - (hdelta : UInt256.slt (UInt256.signextend ⟨15⟩ delta') ⟨0⟩ = ⟨0⟩) - (hov : R.length + 40 ≤ 1024) : - ∃ k' C', RD code ee g s0 callerRet (r1 :: r2 :: posBase' :: R) - mem (UInt256.ofNat 22) rdata - (cA, sstoreAccountMap ee.codeOwner σ (posBase + (⟨3⟩ : UInt256)) - (burnPositionUpdateTokensOwedAddedSlot3 - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256))) tokensOwed0 tokensOwed1)) - k' C' := by - obtain ⟨_, _, hrd21954⟩ := - uniswapV3PoolBurnPositionUpdateTokensOwed0NonzeroStore - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (freePtr := burnPositionKeyNewFreePtrWord) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) (inside1' := inside1') - (inside0' := inside0') (z2 := z2) (z3 := z3) (fee1 := fee1) - (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ⟨16428⟩) (free := free) - (R := r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) (mem := mem) - (aw := UInt256.ofNat 22) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hperm h htokens0 - (by simp only [List.length_cons] at hov ⊢; omega) - obtain ⟨_, _, hrd19527⟩ := - uniswapV3PoolBurnPositionUpdatePostReturnJump - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (freePtr := burnPositionKeyNewFreePtrWord) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) (inside1' := inside1') - (inside0' := inside0') (z2 := z2) (z3 := z3) (fee1 := fee1) - (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ⟨16428⟩) (free := free) - (R := r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) (mem := mem) - (aw := UInt256.ofNat 22) (rdata := rdata) - (acc := (cA, sstoreAccountMap ee.codeOwner σ (posBase + (⟨3⟩ : UInt256)) - (burnPositionUpdateTokensOwedAddedSlot3 - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256))) tokensOwed0 tokensOwed1))) - hpatch (uniswapV3PoolJumpDestPatched19527 hpatch) hrd21954 - (by simp only [List.length_cons] at hov ⊢; omega) - obtain ⟨_, _, hrd16428⟩ := - uniswapV3PoolBurnModifyPositionAfterPositionUpdateZeroDeltaReturn - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1') (inside0 := inside0') (z2 := z2) (z3 := z3) - (fee1 := fee1) (fee0 := fee0) (posBase := posBase') (tick := tick) - (delta := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ⟨16428⟩) (free := free) - (R := r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) (mem := mem) - (aw := UInt256.ofNat 22) (rdata := rdata) - (acc := (cA, sstoreAccountMap ee.codeOwner σ (posBase + (⟨3⟩ : UInt256)) - (burnPositionUpdateTokensOwedAddedSlot3 - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256))) tokensOwed0 tokensOwed1))) - hpatch (uniswapV3PoolJumpDestPatched16428 hpatch) hrd19527 hdelta - (by simp only [List.length_cons] at hov ⊢; omega) - exact uniswapV3PoolBurnModifyPositionReturnZeroAmountToCallerGeneric - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (posBase := posBase') (free := free) (r1 := r1) (r2 := r2) (r3 := r3) - (ret := callerRet) (R := R) (mem := mem) (rdata := rdata) - (acc := (cA, sstoreAccountMap ee.codeOwner σ (posBase + (⟨3⟩ : UInt256)) - (burnPositionUpdateTokensOwedAddedSlot3 - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256))) tokensOwed0 tokensOwed1))) - hpatch hdest hzero hmload224 hrd16428 - (by omega) - -theorem uniswapV3PoolBurnPositionUpdateTokensOwed1NonzeroZeroDeltaReturnToCaller - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity inside1 inside0 delta posBase inside1' inside0' - z2 z3 fee1 fee0 posBase' tick delta' upper lower owner free r1 r2 r3 callerRet : - UInt256} - {R : List UInt256} {mem : ByteArray} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains callerRet = true) - (hperm : ee.perm = true) - (hzero : burnAmountCleanWord ee = ⟨0⟩) - (hmload224 : - (if (⟨224⟩ : UInt256).toNat ≥ mem.size - ∨ (⟨224⟩ : UInt256) ≥ UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (mem.readWithPadding (⟨224⟩ : UInt256).toNat 32))) = - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee))) - (h : RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: ⟨19527⟩ :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ⟨16428⟩ :: free :: r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) - mem (UInt256.ofNat 22) rdata (cA, σ) k C) - (htokens0 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 = ⟨0⟩) - (htokens1 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 ≠ ⟨0⟩) - (hdelta : UInt256.slt (UInt256.signextend ⟨15⟩ delta') ⟨0⟩ = ⟨0⟩) - (hov : R.length + 40 ≤ 1024) : - ∃ k' C', RD code ee g s0 callerRet (r1 :: r2 :: posBase' :: R) - mem (UInt256.ofNat 22) rdata - (cA, sstoreAccountMap ee.codeOwner σ (posBase + (⟨3⟩ : UInt256)) - (burnPositionUpdateTokensOwedAddedSlot3 - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256))) tokensOwed0 tokensOwed1)) - k' C' := by - obtain ⟨_, _, hrd21954⟩ := - uniswapV3PoolBurnPositionUpdateTokensOwed1NonzeroStore - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (freePtr := burnPositionKeyNewFreePtrWord) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) (inside1' := inside1') - (inside0' := inside0') (z2 := z2) (z3 := z3) (fee1 := fee1) - (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ⟨16428⟩) (free := free) - (R := r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) (mem := mem) - (aw := UInt256.ofNat 22) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hperm h htokens0 htokens1 - (by simp only [List.length_cons] at hov ⊢; omega) - obtain ⟨_, _, hrd19527⟩ := - uniswapV3PoolBurnPositionUpdatePostReturnJump - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (freePtr := burnPositionKeyNewFreePtrWord) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) (inside1' := inside1') - (inside0' := inside0') (z2 := z2) (z3 := z3) (fee1 := fee1) - (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ⟨16428⟩) (free := free) - (R := r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) (mem := mem) - (aw := UInt256.ofNat 22) (rdata := rdata) - (acc := (cA, sstoreAccountMap ee.codeOwner σ (posBase + (⟨3⟩ : UInt256)) - (burnPositionUpdateTokensOwedAddedSlot3 - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256))) tokensOwed0 tokensOwed1))) - hpatch (uniswapV3PoolJumpDestPatched19527 hpatch) hrd21954 - (by simp only [List.length_cons] at hov ⊢; omega) - obtain ⟨_, _, hrd16428⟩ := - uniswapV3PoolBurnModifyPositionAfterPositionUpdateZeroDeltaReturn - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1') (inside0 := inside0') (z2 := z2) (z3 := z3) - (fee1 := fee1) (fee0 := fee0) (posBase := posBase') (tick := tick) - (delta := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ⟨16428⟩) (free := free) - (R := r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) (mem := mem) - (aw := UInt256.ofNat 22) (rdata := rdata) - (acc := (cA, sstoreAccountMap ee.codeOwner σ (posBase + (⟨3⟩ : UInt256)) - (burnPositionUpdateTokensOwedAddedSlot3 - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256))) tokensOwed0 tokensOwed1))) - hpatch (uniswapV3PoolJumpDestPatched16428 hpatch) hrd19527 hdelta - (by simp only [List.length_cons] at hov ⊢; omega) - exact uniswapV3PoolBurnModifyPositionReturnZeroAmountToCallerGeneric - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (posBase := posBase') (free := free) (r1 := r1) (r2 := r2) (r3 := r3) - (ret := callerRet) (R := R) (mem := mem) (rdata := rdata) - (acc := (cA, sstoreAccountMap ee.codeOwner σ (posBase + (⟨3⟩ : UInt256)) - (burnPositionUpdateTokensOwedAddedSlot3 - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256))) tokensOwed0 tokensOwed1))) - hpatch hdest hzero hmload224 hrd16428 - (by omega) - -theorem uniswapV3PoolBurnPositionUpdateTokensOwedZeroSkipStoresGeneric - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity inside1 inside0 delta posBase retPos inside1' - inside0' z2 z3 fee1 fee0 posBase' tick delta' upper lower owner ret free : - UInt256} - {R : List UInt256} {mem : ByteArray} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - mem (UInt256.ofNat 22) rdata acc k C) - (htokens0 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 = ⟨0⟩) - (htokens1 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 = ⟨0⟩) - (hov : R.length + 35 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨21954⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: retPos :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ret :: free :: R) - mem (UInt256.ofNat 22) rdata acc k' C' := by - have hdec (pc : UInt256) - (hlo : 21807 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21930) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPositionUpdateTokensOwedStoreDecodeEqTemplate hpatch hlo - (by omega) - have hd21861 : - decode code ⟨21861⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21861⟩ (by native_decide) (by native_decide)] - native_decide - have hd21863 : - decode code ⟨21863⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21863⟩ (by native_decide) (by native_decide)] - native_decide - have hd21865 : - decode code ⟨21865⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21865⟩ (by native_decide) (by native_decide)] - native_decide - have hd21867 : decode code ⟨21867⟩ = some (.SHL, .none) := by - rw [hdec ⟨21867⟩ (by native_decide) (by native_decide)] - native_decide - have hd21868 : decode code ⟨21868⟩ = some (.SUB, .none) := by - rw [hdec ⟨21868⟩ (by native_decide) (by native_decide)] - native_decide - have hd21869 : decode code ⟨21869⟩ = some (.DUP3, .none) := by - rw [hdec ⟨21869⟩ (by native_decide) (by native_decide)] - native_decide - have hd21870 : decode code ⟨21870⟩ = some (.AND, .none) := by - rw [hdec ⟨21870⟩ (by native_decide) (by native_decide)] - native_decide - have hd21871 : decode code ⟨21871⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨21871⟩ (by native_decide) (by native_decide)] - native_decide - have hd21872 : decode code ⟨21872⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨21872⟩ (by native_decide) (by native_decide)] - native_decide - have hd21873 : decode code ⟨21873⟩ = some (.DUP1, .none) := by - rw [hdec ⟨21873⟩ (by native_decide) (by native_decide)] - native_decide - have hd21874 : - decode code ⟨21874⟩ = some (.Push .PUSH2, some (⟨21892⟩, 2)) := by - rw [hdec ⟨21874⟩ (by native_decide) (by native_decide)] - native_decide - have hd21877 : decode code ⟨21877⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨21877⟩ (by native_decide) (by native_decide)] - native_decide - have hd21878 : decode code ⟨21878⟩ = some (.POP, .none) := by - rw [hdec ⟨21878⟩ (by native_decide) (by native_decide)] - native_decide - have hd21879 : - decode code ⟨21879⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨21879⟩ (by native_decide) (by native_decide)] - native_decide - have hd21881 : decode code ⟨21881⟩ = some (.DUP2, .none) := by - rw [hdec ⟨21881⟩ (by native_decide) (by native_decide)] - native_decide - have hd21882 : - decode code ⟨21882⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21882⟩ (by native_decide) (by native_decide)] - native_decide - have hd21884 : - decode code ⟨21884⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨21884⟩ (by native_decide) (by native_decide)] - native_decide - have hd21886 : - decode code ⟨21886⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨21886⟩ (by native_decide) (by native_decide)] - native_decide - have hd21888 : decode code ⟨21888⟩ = some (.SHL, .none) := by - rw [hdec ⟨21888⟩ (by native_decide) (by native_decide)] - native_decide - have hd21889 : decode code ⟨21889⟩ = some (.SUB, .none) := by - rw [hdec ⟨21889⟩ (by native_decide) (by native_decide)] - native_decide - have hd21890 : decode code ⟨21890⟩ = some (.AND, .none) := by - rw [hdec ⟨21890⟩ (by native_decide) (by native_decide)] - native_decide - have hd21891 : decode code ⟨21891⟩ = some (.GT, .none) := by - rw [hdec ⟨21891⟩ (by native_decide) (by native_decide)] - native_decide - have hd21892 : decode code ⟨21892⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨21892⟩ (by native_decide) (by native_decide)] - native_decide - have hd21893 : decode code ⟨21893⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨21893⟩ (by native_decide) (by native_decide)] - native_decide - have hd21894 : - decode code ⟨21894⟩ = some (.Push .PUSH2, some (⟨21954⟩, 2)) := by - rw [hdec ⟨21894⟩ (by native_decide) (by native_decide)] - native_decide - have hd21897 : decode code ⟨21897⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨21897⟩ (by native_decide) (by native_decide)] - native_decide - have rd21877 := evm_run h with [ - raw push1 ⟨1⟩ hd21861 (by evm_ov), - raw push1 ⟨1⟩ hd21863 (by evm_ov), - raw push1 ⟨128⟩ hd21865 (by evm_ov), - raw shl hd21867 (by evm_ov), - raw sub hd21868 (by evm_ov), - raw dup3 hd21869 (by simp only [List.length_cons] at hov ⊢; omega), - raw and hd21870 (by evm_ov), - raw iszero hd21871 (by evm_ov), - raw iszero hd21872 (by evm_ov), - raw dup1 hd21873 (by simp only [List.length_cons] at hov ⊢; omega), - raw push2 ⟨21892⟩ hd21874 (by evm_ov)] - have hcond0 : - UInt256.isZero - (UInt256.isZero (UInt256.land tokensOwed0 burnPositionUpdateSlot0Mask)) = - ⟨0⟩ := by - rw [u256_land_comm tokensOwed0 burnPositionUpdateSlot0Mask] - rw [htokens0] - native_decide - have rd21878 := by - simpa [burnPositionUpdateSlot0Mask] using - rd21877.jumpiNT hd21877 hcond0 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd21892 := evm_run rd21878 with [ - raw pop hd21878 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨0⟩ hd21879 (by evm_ov), - raw dup2 hd21881 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨1⟩ hd21882 (by evm_ov), - raw push1 ⟨1⟩ hd21884 (by evm_ov), - raw push1 ⟨128⟩ hd21886 (by evm_ov), - raw shl hd21888 (by evm_ov), - raw sub hd21889 (by evm_ov), - raw and hd21890 (by evm_ov), - raw gt hd21891 (by evm_ov), - raw jumpdest hd21892 (by evm_ov), - raw iszero hd21893 (by evm_ov), - raw push2 ⟨21954⟩ hd21894 (by evm_ov)] - have hcond1 : - UInt256.isZero - (UInt256.gt (UInt256.land burnPositionUpdateSlot0Mask tokensOwed1) ⟨0⟩) ≠ - ⟨0⟩ := by - rw [htokens1] - native_decide - exact ⟨_, _, by - simpa [burnPositionUpdateSlot0Mask] using - rd21892.jumpiT hd21897 hcond1 (uniswapV3PoolJumpDestPatched21954 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnPositionUpdateTokensOwedZeroZeroDeltaReturnToCallerGeneric - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity inside1 inside0 delta posBase inside1' inside0' - z2 z3 fee1 fee0 posBase' tick delta' upper lower owner free r1 r2 r3 callerRet : - UInt256} - {R : List UInt256} {mem : ByteArray} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains callerRet = true) - (hzero : burnAmountCleanWord ee = ⟨0⟩) - (hmload224 : - (if (⟨224⟩ : UInt256).toNat ≥ mem.size - ∨ (⟨224⟩ : UInt256) ≥ UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (mem.readWithPadding (⟨224⟩ : UInt256).toNat 32))) = - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee))) - (h : RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: ⟨19527⟩ :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase' :: tick :: delta' :: upper :: lower :: - owner :: ⟨16428⟩ :: free :: r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) - mem (UInt256.ofNat 22) rdata acc k C) - (htokens0 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 = ⟨0⟩) - (htokens1 : UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 = ⟨0⟩) - (hdelta : UInt256.slt (UInt256.signextend ⟨15⟩ delta') ⟨0⟩ = ⟨0⟩) - (hov : R.length + 40 ≤ 1024) : - ∃ k' C', RD code ee g s0 callerRet (r1 :: r2 :: posBase' :: R) - mem (UInt256.ofNat 22) rdata acc k' C' := by - obtain ⟨_, _, hrd21954⟩ := - uniswapV3PoolBurnPositionUpdateTokensOwedZeroSkipStoresGeneric - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (inside1 := inside1) (inside0 := inside0) - (delta := delta) (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1') (inside0' := inside0') (z2 := z2) (z3 := z3) - (fee1 := fee1) (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ⟨16428⟩) (free := free) - (R := r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) (mem := mem) - (rdata := rdata) (acc := acc) hpatch h htokens0 htokens1 - (by simp only [List.length_cons] at hov ⊢; omega) - obtain ⟨_, _, hrd19527⟩ := - uniswapV3PoolBurnPositionUpdatePostReturnJump - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (freePtr := burnPositionKeyNewFreePtrWord) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) (inside1' := inside1') - (inside0' := inside0') (z2 := z2) (z3 := z3) (fee1 := fee1) - (fee0 := fee0) (posBase' := posBase') (tick := tick) - (delta' := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ⟨16428⟩) (free := free) - (R := r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) (mem := mem) - (aw := UInt256.ofNat 22) (rdata := rdata) (acc := acc) - hpatch (uniswapV3PoolJumpDestPatched19527 hpatch) hrd21954 - (by simp only [List.length_cons] at hov ⊢; omega) - obtain ⟨_, _, hrd16428⟩ := - uniswapV3PoolBurnModifyPositionAfterPositionUpdateZeroDeltaReturn - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1') (inside0 := inside0') (z2 := z2) (z3 := z3) - (fee1 := fee1) (fee0 := fee0) (posBase := posBase') (tick := tick) - (delta := delta') (upper := upper) (lower := lower) (owner := owner) - (ret := ⟨16428⟩) (free := free) - (R := r1 :: r2 :: r3 :: ⟨128⟩ :: callerRet :: R) (mem := mem) - (aw := UInt256.ofNat 22) (rdata := rdata) (acc := acc) - hpatch (uniswapV3PoolJumpDestPatched16428 hpatch) hrd19527 hdelta - (by simp only [List.length_cons] at hov ⊢; omega) - exact uniswapV3PoolBurnModifyPositionReturnZeroAmountToCallerGeneric - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (posBase := posBase') (free := free) (r1 := r1) (r2 := r2) (r3 := r3) - (ret := callerRet) (R := R) (mem := mem) (rdata := rdata) (acc := acc) - hpatch hdest hzero hmload224 hrd16428 - (by omega) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnPostPositionUpdate.lean b/Benchmarks/UniswapV3Pool/BurnPostPositionUpdate.lean deleted file mode 100644 index 7bcfcfae..00000000 --- a/Benchmarks/UniswapV3Pool/BurnPostPositionUpdate.lean +++ /dev/null @@ -1,1147 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdateTokensOwedBridge - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem uniswapV3PoolBurnPostPositionUpdateDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 9737 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 9808) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 9808 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -private theorem uniswapV3PoolPatchPreservesJumpDest9833 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨9833⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched9833 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨9833⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest9833 - -private theorem uniswapV3PoolBurnEventDecodeEqTemplate - {v : PoolImmutables} {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 9833 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 9984) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 9984 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega) - -abbrev burnPostPositionUpdateEventTopic : UInt256 := - ⟨5529215719100538921338848767238990743315658914736670698561097943341164173356⟩ - -noncomputable def burnPostPositionUpdateEventMem0 - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - ByteArray := - writeWord (burnPositionUpdateMem5 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)).toNat - (UInt256.land amount burnPositionUpdateSlot0Mask) - -noncomputable def burnPostPositionUpdateEventMem1 - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - ByteArray := - writeWord (burnPostPositionUpdateEventMem0 σ I pos0 posBase amount) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) + (⟨32⟩ : UInt256)).toNat - ⟨0⟩ - -noncomputable def burnPostPositionUpdateEventMem - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - ByteArray := - writeWord (burnPostPositionUpdateEventMem1 σ I pos0 posBase amount) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) + (⟨64⟩ : UInt256)).toNat - ⟨0⟩ - -theorem burnPostPositionUpdateEventMem0_size - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - (burnPostPositionUpdateEventMem0 σ I pos0 posBase amount).size = 730 := by - unfold burnPostPositionUpdateEventMem0 - rw [writeWord_size _ _ _ (by - rw [burnPositionUpdateMem5_size σ I pos0 posBase] - native_decide)] - rw [burnPositionUpdateMem5_size σ I pos0 posBase] - native_decide - -theorem burnPostPositionUpdateEventMem1_size - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - (burnPostPositionUpdateEventMem1 σ I pos0 posBase amount).size = 762 := by - unfold burnPostPositionUpdateEventMem1 - rw [writeWord_size _ _ _ (by - rw [burnPostPositionUpdateEventMem0_size σ I pos0 posBase amount] - native_decide)] - rw [burnPostPositionUpdateEventMem0_size σ I pos0 posBase amount] - native_decide - -theorem burnPostPositionUpdateEventMem_size - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - (burnPostPositionUpdateEventMem σ I pos0 posBase amount).size = 794 := by - unfold burnPostPositionUpdateEventMem - rw [writeWord_size _ _ _ (by - rw [burnPostPositionUpdateEventMem1_size σ I pos0 posBase amount] - native_decide)] - rw [burnPostPositionUpdateEventMem1_size σ I pos0 posBase amount] - native_decide - -theorem burnPostPositionUpdateEventMem_read64 - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - (burnPostPositionUpdateEventMem σ I pos0 posBase amount).readWithPadding 64 32 = - UInt256.toByteArray (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) := by - unfold burnPostPositionUpdateEventMem - rw [writeWord_read_preserved - (burnPostPositionUpdateEventMem1 σ I pos0 posBase amount) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) + (⟨64⟩ : UInt256)).toNat - 64 (⟨0⟩ : UInt256) - (by - rw [burnPostPositionUpdateEventMem1_size σ I pos0 posBase amount] - native_decide) - (by - rw [burnPostPositionUpdateEventMem1_size σ I pos0 posBase amount] - native_decide)] - unfold burnPostPositionUpdateEventMem1 - rw [writeWord_read_preserved - (burnPostPositionUpdateEventMem0 σ I pos0 posBase amount) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) + (⟨32⟩ : UInt256)).toNat - 64 (⟨0⟩ : UInt256) - (by - rw [burnPostPositionUpdateEventMem0_size σ I pos0 posBase amount] - native_decide) - (by - rw [burnPostPositionUpdateEventMem0_size σ I pos0 posBase amount] - native_decide)] - unfold burnPostPositionUpdateEventMem0 - rw [writeWord_read_preserved - (burnPositionUpdateMem5 σ I pos0 posBase) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)).toNat - 64 (UInt256.land amount burnPositionUpdateSlot0Mask) - (by - rw [burnPositionUpdateMem5_size σ I pos0 posBase] - native_decide) - (by - rw [burnPositionUpdateMem5_size σ I pos0 posBase] - native_decide)] - exact burnPositionUpdateMem5_read64 σ I pos0 posBase - -theorem burnPostPositionUpdateEventMem_mload64 - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ - (burnPostPositionUpdateEventMem σ I pos0 posBase amount).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 25 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPostPositionUpdateEventMem σ I pos0 posBase amount).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) := by - exact mloadWordValue_of_readWithPadding - (by rw [burnPostPositionUpdateEventMem_size σ I pos0 posBase amount]; native_decide) - (by native_decide) - (by - simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using burnPostPositionUpdateEventMem_read64 σ I pos0 posBase amount) - -abbrev burnPostPositionUpdateUnlockedClearMask : UInt256 := - UInt256.lnot (UInt256.shiftLeft ⟨255⟩ ⟨240⟩) - -abbrev burnPostPositionUpdateUnlockedSlotWord (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - UInt256.lor - (UInt256.shiftLeft ⟨1⟩ ⟨240⟩) - (UInt256.land burnPostPositionUpdateUnlockedClearMask (codeOwnerStorageWord I σ ⟨0⟩)) - -noncomputable def burnPostPositionUpdateReturnMem0 - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - ByteArray := - writeWord (burnPostPositionUpdateEventMem σ I pos0 posBase amount) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)).toNat ⟨0⟩ - -noncomputable def burnPostPositionUpdateReturnMem - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - ByteArray := - writeWord (burnPostPositionUpdateReturnMem0 σ I pos0 posBase amount) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) + (⟨32⟩ : UInt256)).toNat ⟨0⟩ - -theorem burnPostPositionUpdateReturnMem0_size - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - (burnPostPositionUpdateReturnMem0 σ I pos0 posBase amount).size = 794 := by - unfold burnPostPositionUpdateReturnMem0 - rw [writeWord_size _ _ _ (by - rw [burnPostPositionUpdateEventMem_size σ I pos0 posBase amount] - native_decide)] - rw [burnPostPositionUpdateEventMem_size σ I pos0 posBase amount] - native_decide - -theorem burnPostPositionUpdateReturnMem_size - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - (burnPostPositionUpdateReturnMem σ I pos0 posBase amount).size = 794 := by - unfold burnPostPositionUpdateReturnMem - rw [writeWord_size _ _ _ (by - rw [burnPostPositionUpdateReturnMem0_size σ I pos0 posBase amount] - native_decide)] - rw [burnPostPositionUpdateReturnMem0_size σ I pos0 posBase amount] - native_decide - -theorem burnPostPositionUpdateReturnMem_read64 - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - (burnPostPositionUpdateReturnMem σ I pos0 posBase amount).readWithPadding 64 32 = - UInt256.toByteArray (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) := by - unfold burnPostPositionUpdateReturnMem - rw [writeWord_read_preserved - (burnPostPositionUpdateReturnMem0 σ I pos0 posBase amount) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) + (⟨32⟩ : UInt256)).toNat - 64 (⟨0⟩ : UInt256) - (by rw [burnPostPositionUpdateReturnMem0_size σ I pos0 posBase amount]; native_decide) - (by rw [burnPostPositionUpdateReturnMem0_size σ I pos0 posBase amount]; native_decide)] - unfold burnPostPositionUpdateReturnMem0 - rw [writeWord_read_preserved - (burnPostPositionUpdateEventMem σ I pos0 posBase amount) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)).toNat - 64 (⟨0⟩ : UInt256) - (by rw [burnPostPositionUpdateEventMem_size σ I pos0 posBase amount]; native_decide) - (by rw [burnPostPositionUpdateEventMem_size σ I pos0 posBase amount]; native_decide)] - exact burnPostPositionUpdateEventMem_read64 σ I pos0 posBase amount - -theorem burnPostPositionUpdateReturnMem_mload64 - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ - (burnPostPositionUpdateReturnMem σ I pos0 posBase amount).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 25 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPostPositionUpdateReturnMem σ I pos0 posBase amount).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) := by - exact mloadWordValue_of_readWithPadding - (mem := burnPostPositionUpdateReturnMem σ I pos0 posBase amount) - (aw := UInt256.ofNat 25) (off := ⟨64⟩) - (v := burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) - (by rw [burnPostPositionUpdateReturnMem_size σ I pos0 posBase amount]; native_decide) - (by native_decide) - (by - simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using burnPostPositionUpdateReturnMem_read64 σ I pos0 posBase amount) - -theorem burnPostPositionUpdateReturnMem_readFree - (σ : AccountMap) (I : ExecutionEnv) (pos0 posBase amount : UInt256) : - (burnPostPositionUpdateReturnMem σ I pos0 posBase amount).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)).toNat 64 = - UInt256.toByteArray (⟨0⟩ : UInt256) ++ UInt256.toByteArray (⟨0⟩ : UInt256) := by - have hsize := burnPostPositionUpdateReturnMem_size σ I pos0 posBase amount - have hleft : - (burnPostPositionUpdateReturnMem σ I pos0 posBase amount).readWithPadding - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)).toNat 32 = - UInt256.toByteArray (⟨0⟩ : UInt256) := by - unfold burnPostPositionUpdateReturnMem - rw [writeWord_read_preserved - (burnPostPositionUpdateReturnMem0 σ I pos0 posBase amount) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) + (⟨32⟩ : UInt256)).toNat - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)).toNat - (⟨0⟩ : UInt256) - (by rw [burnPostPositionUpdateReturnMem0_size σ I pos0 posBase amount]; native_decide) - (by rw [burnPostPositionUpdateReturnMem0_size σ I pos0 posBase amount]; native_decide)] - unfold burnPostPositionUpdateReturnMem0 - exact writeWord_read_back - (burnPostPositionUpdateEventMem σ I pos0 posBase amount) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)).toNat - (⟨0⟩ : UInt256) - (by rw [burnPostPositionUpdateEventMem_size σ I pos0 posBase amount]; native_decide) - have hright : - (burnPostPositionUpdateReturnMem σ I pos0 posBase amount).readWithPadding - ((burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)).toNat + 32) 32 = - UInt256.toByteArray (⟨0⟩ : UInt256) := by - unfold burnPostPositionUpdateReturnMem - simpa [show (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) + - (⟨32⟩ : UInt256)).toNat = - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)).toNat + 32 by - native_decide] using - writeWord_read_back - (burnPostPositionUpdateReturnMem0 σ I pos0 posBase amount) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) + (⟨32⟩ : UInt256)).toNat - (⟨0⟩ : UInt256) - (by rw [burnPostPositionUpdateReturnMem0_size σ I pos0 posBase amount]; native_decide) - rw [byteArray_readWithPadding_split - (burnPostPositionUpdateReturnMem σ I pos0 posBase amount) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)).toNat 32 32 - (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by rw [hsize]; native_decide)] - rw [hleft, hright] - -theorem uniswapV3PoolBurnPostPositionUpdateZeroAmountsToEvent {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {posBase amount upper lower ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨9737⟩ - (⟨0⟩ :: ⟨0⟩ :: posBase :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - amount :: upper :: lower :: ret :: R) - mem aw rdata acc k C) - (hov : R.length + 20 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨9833⟩ - (⟨0⟩ :: ⟨0⟩ :: posBase :: ⟨0⟩ :: ⟨0⟩ :: amount :: upper :: lower :: ret :: R) - mem aw rdata acc k' C' := by - have hdec (pc : UInt256) - (hlo : 9737 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 9808) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnPostPositionUpdateDecodeEqTemplate hpatch hlo hhi - have hd9737 : decode code ⟨9737⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨9737⟩ (by native_decide) (by native_decide)] - native_decide - have hd9738 : decode code ⟨9738⟩ = some (.SWAP3, .none) := by - rw [hdec ⟨9738⟩ (by native_decide) (by native_decide)] - native_decide - have hd9739 : decode code ⟨9739⟩ = some (.POP, .none) := by - rw [hdec ⟨9739⟩ (by native_decide) (by native_decide)] - native_decide - have hd9740 : decode code ⟨9740⟩ = some (.SWAP3, .none) := by - rw [hdec ⟨9740⟩ (by native_decide) (by native_decide)] - native_decide - have hd9741 : decode code ⟨9741⟩ = some (.POP, .none) := by - rw [hdec ⟨9741⟩ (by native_decide) (by native_decide)] - native_decide - have hd9742 : decode code ⟨9742⟩ = some (.SWAP3, .none) := by - rw [hdec ⟨9742⟩ (by native_decide) (by native_decide)] - native_decide - have hd9743 : decode code ⟨9743⟩ = some (.POP, .none) := by - rw [hdec ⟨9743⟩ (by native_decide) (by native_decide)] - native_decide - have hd9744 : decode code ⟨9744⟩ = some (.DUP2, .none) := by - rw [hdec ⟨9744⟩ (by native_decide) (by native_decide)] - native_decide - have hd9745 : decode code ⟨9745⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨9745⟩ (by native_decide) (by native_decide)] - native_decide - have hd9747 : decode code ⟨9747⟩ = some (.SUB, .none) := by - rw [hdec ⟨9747⟩ (by native_decide) (by native_decide)] - native_decide - have hd9748 : decode code ⟨9748⟩ = some (.SWAP5, .none) := by - rw [hdec ⟨9748⟩ (by native_decide) (by native_decide)] - native_decide - have hd9749 : decode code ⟨9749⟩ = some (.POP, .none) := by - rw [hdec ⟨9749⟩ (by native_decide) (by native_decide)] - native_decide - have hd9750 : decode code ⟨9750⟩ = some (.DUP1, .none) := by - rw [hdec ⟨9750⟩ (by native_decide) (by native_decide)] - native_decide - have hd9751 : decode code ⟨9751⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨9751⟩ (by native_decide) (by native_decide)] - native_decide - have hd9753 : decode code ⟨9753⟩ = some (.SUB, .none) := by - rw [hdec ⟨9753⟩ (by native_decide) (by native_decide)] - native_decide - have hd9754 : decode code ⟨9754⟩ = some (.SWAP4, .none) := by - rw [hdec ⟨9754⟩ (by native_decide) (by native_decide)] - native_decide - have hd9755 : decode code ⟨9755⟩ = some (.POP, .none) := by - rw [hdec ⟨9755⟩ (by native_decide) (by native_decide)] - native_decide - have hd9756 : decode code ⟨9756⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨9756⟩ (by native_decide) (by native_decide)] - native_decide - have hd9758 : decode code ⟨9758⟩ = some (.DUP6, .none) := by - rw [hdec ⟨9758⟩ (by native_decide) (by native_decide)] - native_decide - have hd9759 : decode code ⟨9759⟩ = some (.GT, .none) := by - rw [hdec ⟨9759⟩ (by native_decide) (by native_decide)] - native_decide - have hd9760 : decode code ⟨9760⟩ = some (.DUP1, .none) := by - rw [hdec ⟨9760⟩ (by native_decide) (by native_decide)] - native_decide - have hd9761 : decode code ⟨9761⟩ = some (.Push .PUSH2, some (⟨9770⟩, 2)) := by - rw [hdec ⟨9761⟩ (by native_decide) (by native_decide)] - native_decide - have hd9764 : decode code ⟨9764⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨9764⟩ (by native_decide) (by native_decide)] - native_decide - have hd9765 : decode code ⟨9765⟩ = some (.POP, .none) := by - rw [hdec ⟨9765⟩ (by native_decide) (by native_decide)] - native_decide - have hd9766 : decode code ⟨9766⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdec ⟨9766⟩ (by native_decide) (by native_decide)] - native_decide - have hd9768 : decode code ⟨9768⟩ = some (.DUP5, .none) := by - rw [hdec ⟨9768⟩ (by native_decide) (by native_decide)] - native_decide - have hd9769 : decode code ⟨9769⟩ = some (.GT, .none) := by - rw [hdec ⟨9769⟩ (by native_decide) (by native_decide)] - native_decide - have hd9770 : decode code ⟨9770⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨9770⟩ (by native_decide) (by native_decide)] - native_decide - have hd9771 : decode code ⟨9771⟩ = some (.ISZERO, .none) := by - rw [hdec ⟨9771⟩ (by native_decide) (by native_decide)] - native_decide - have hd9772 : decode code ⟨9772⟩ = some (.Push .PUSH2, some (⟨9833⟩, 2)) := by - rw [hdec ⟨9772⟩ (by native_decide) (by native_decide)] - native_decide - have hd9775 : decode code ⟨9775⟩ = some (.JUMPI, .none) := by - rw [hdec ⟨9775⟩ (by native_decide) (by native_decide)] - native_decide - have rd9764 := evm_run h with [ - raw jumpdest hd9737 (by evm_ov), - raw swap3 hd9738 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd9739 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap3 hd9740 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd9741 (by simp only [List.length_cons] at hov ⊢; omega), - raw swap3 hd9742 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd9743 (by simp only [List.length_cons] at hov ⊢; omega), - raw dup2 hd9744 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨0⟩ hd9745 (by evm_ov), - raw sub hd9747 (by evm_ov), - raw swap5 hd9748 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd9749 (by simp only [List.length_cons] at hov ⊢; omega), - raw dup1 hd9750 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨0⟩ hd9751 (by evm_ov), - raw sub hd9753 (by evm_ov), - raw swap4 hd9754 (by simp only [List.length_cons] at hov ⊢; omega), - raw pop hd9755 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨0⟩ hd9756 (by evm_ov), - raw dup6 hd9758 (by simp only [List.length_cons] at hov ⊢; omega), - raw gt hd9759 (by evm_ov), - raw dup1 hd9760 (by simp only [List.length_cons] at hov ⊢; omega), - raw push2 ⟨9770⟩ hd9761 (by evm_ov)] - have hcond0 : - UInt256.gt (UInt256.sub ⟨0⟩ ⟨0⟩) ⟨0⟩ = ⟨0⟩ := by - native_decide - have rd9765 := rd9764.jumpiNT hd9764 hcond0 - (by simp only [List.length_cons] at hov ⊢; omega) - have rd9775 := evm_run rd9765 with [ - raw pop hd9765 (by simp only [List.length_cons] at hov ⊢; omega), - raw push1 ⟨0⟩ hd9766 (by evm_ov), - raw dup5 hd9768 (by simp only [List.length_cons] at hov ⊢; omega), - raw gt hd9769 (by evm_ov), - raw jumpdest hd9770 (by evm_ov), - raw iszero hd9771 (by evm_ov), - raw push2 ⟨9833⟩ hd9772 (by evm_ov)] - have hcond1 : - UInt256.isZero (UInt256.gt (UInt256.sub ⟨0⟩ ⟨0⟩) ⟨0⟩) ≠ ⟨0⟩ := by - native_decide - exact ⟨_, _, rd9775.jumpiT hd9775 hcond1 (uniswapV3PoolJumpDestPatched9833 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnPostPositionUpdateEventLog {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {σ : AccountMap} {pos0 posBase amount upper lower ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨9833⟩ - (⟨0⟩ :: ⟨0⟩ :: posBase :: ⟨0⟩ :: ⟨0⟩ :: amount :: upper :: lower :: - ret :: R) - (burnPositionUpdateMem5 σ ee pos0 posBase) (UInt256.ofNat 22) rdata acc k C) - (hperm : ee.perm = true) - (hov : R.length + 24 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨9921⟩ - (⟨0⟩ :: ⟨0⟩ :: posBase :: ⟨0⟩ :: ⟨0⟩ :: amount :: upper :: lower :: - ret :: R) - (burnPostPositionUpdateEventMem σ ee pos0 posBase amount) (UInt256.ofNat 25) - rdata acc k' C' := by - have hdec (pc : UInt256) - (hlo : 9833 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 9984) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnEventDecodeEqTemplate hpatch hlo hhi - have hd9833 : decode code ⟨9833⟩ = some (.JUMPDEST, .none) := by - rw [hdec ⟨9833⟩ (by native_decide) (by native_decide)] - native_decide - have hd9834 : decode code ⟨9834⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [hdec ⟨9834⟩ (by native_decide) (by native_decide)] - native_decide - have hd9836 : decode code ⟨9836⟩ = some (.DUP1, .none) := by - rw [hdec ⟨9836⟩ (by native_decide) (by native_decide)] - native_decide - have hd9837 : decode code ⟨9837⟩ = some (.MLOAD, .none) := by - rw [hdec ⟨9837⟩ (by native_decide) (by native_decide)] - native_decide - have hd9838 : decode code ⟨9838⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨9838⟩ (by native_decide) (by native_decide)] - native_decide - have hd9840 : decode code ⟨9840⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdec ⟨9840⟩ (by native_decide) (by native_decide)] - native_decide - have hd9842 : decode code ⟨9842⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdec ⟨9842⟩ (by native_decide) (by native_decide)] - native_decide - have hd9844 : decode code ⟨9844⟩ = some (.SHL, .none) := by - rw [hdec ⟨9844⟩ (by native_decide) (by native_decide)] - native_decide - have hd9845 : decode code ⟨9845⟩ = some (.SUB, .none) := by - rw [hdec ⟨9845⟩ (by native_decide) (by native_decide)] - native_decide - have hd9846 : decode code ⟨9846⟩ = some (.DUP9, .none) := by - rw [hdec ⟨9846⟩ (by native_decide) (by native_decide)] - native_decide - have hd9847 : decode code ⟨9847⟩ = some (.AND, .none) := by - rw [hdec ⟨9847⟩ (by native_decide) (by native_decide)] - native_decide - have hd9848 : decode code ⟨9848⟩ = some (.DUP2, .none) := by - rw [hdec ⟨9848⟩ (by native_decide) (by native_decide)] - native_decide - have hd9849 : decode code ⟨9849⟩ = some (.MSTORE, .none) := by - rw [hdec ⟨9849⟩ (by native_decide) (by native_decide)] - native_decide - have hd9850 : decode code ⟨9850⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdec ⟨9850⟩ (by native_decide) (by native_decide)] - native_decide - have hd9852 : decode code ⟨9852⟩ = some (.DUP2, .none) := by - rw [hdec ⟨9852⟩ (by native_decide) (by native_decide)] - native_decide - have hd9853 : decode code ⟨9853⟩ = some (.ADD, .none) := by - rw [hdec ⟨9853⟩ (by native_decide) (by native_decide)] - native_decide - have hd9854 : decode code ⟨9854⟩ = some (.DUP8, .none) := by - rw [hdec ⟨9854⟩ (by native_decide) (by native_decide)] - native_decide - have hd9855 : decode code ⟨9855⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨9855⟩ (by native_decide) (by native_decide)] - native_decide - have hd9856 : decode code ⟨9856⟩ = some (.MSTORE, .none) := by - rw [hdec ⟨9856⟩ (by native_decide) (by native_decide)] - native_decide - have hd9857 : decode code ⟨9857⟩ = some (.DUP1, .none) := by - rw [hdec ⟨9857⟩ (by native_decide) (by native_decide)] - native_decide - have hd9858 : decode code ⟨9858⟩ = some (.DUP3, .none) := by - rw [hdec ⟨9858⟩ (by native_decide) (by native_decide)] - native_decide - have hd9859 : decode code ⟨9859⟩ = some (.ADD, .none) := by - rw [hdec ⟨9859⟩ (by native_decide) (by native_decide)] - native_decide - have hd9860 : decode code ⟨9860⟩ = some (.DUP7, .none) := by - rw [hdec ⟨9860⟩ (by native_decide) (by native_decide)] - native_decide - have hd9861 : decode code ⟨9861⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨9861⟩ (by native_decide) (by native_decide)] - native_decide - have hd9862 : decode code ⟨9862⟩ = some (.MSTORE, .none) := by - rw [hdec ⟨9862⟩ (by native_decide) (by native_decide)] - native_decide - have hd9863 : decode code ⟨9863⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨9863⟩ (by native_decide) (by native_decide)] - native_decide - have hd9864 : decode code ⟨9864⟩ = some (.MLOAD, .none) := by - rw [hdec ⟨9864⟩ (by native_decide) (by native_decide)] - native_decide - have hd9865 : decode code ⟨9865⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdec ⟨9865⟩ (by native_decide) (by native_decide)] - native_decide - have hd9867 : decode code ⟨9867⟩ = some (.DUP10, .none) := by - rw [hdec ⟨9867⟩ (by native_decide) (by native_decide)] - native_decide - have hd9868 : decode code ⟨9868⟩ = some (.DUP2, .none) := by - rw [hdec ⟨9868⟩ (by native_decide) (by native_decide)] - native_decide - have hd9869 : decode code ⟨9869⟩ = some (.SIGNEXTEND, .none) := by - rw [hdec ⟨9869⟩ (by native_decide) (by native_decide)] - native_decide - have hd9870 : decode code ⟨9870⟩ = some (.SWAP3, .none) := by - rw [hdec ⟨9870⟩ (by native_decide) (by native_decide)] - native_decide - have hd9871 : decode code ⟨9871⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨9871⟩ (by native_decide) (by native_decide)] - native_decide - have hd9872 : decode code ⟨9872⟩ = some (.DUP12, .none) := by - rw [hdec ⟨9872⟩ (by native_decide) (by native_decide)] - native_decide - have hd9873 : decode code ⟨9873⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨9873⟩ (by native_decide) (by native_decide)] - native_decide - have hd9874 : decode code ⟨9874⟩ = some (.SIGNEXTEND, .none) := by - rw [hdec ⟨9874⟩ (by native_decide) (by native_decide)] - native_decide - have hd9875 : decode code ⟨9875⟩ = some (.SWAP2, .none) := by - rw [hdec ⟨9875⟩ (by native_decide) (by native_decide)] - native_decide - have hd9876 : decode code ⟨9876⟩ = some (.CALLER, .none) := by - rw [hdec ⟨9876⟩ (by native_decide) (by native_decide)] - native_decide - have hd9877 : decode code ⟨9877⟩ = some (.SWAP2, .none) := by - rw [hdec ⟨9877⟩ (by native_decide) (by native_decide)] - native_decide - have hd9878 : - decode code ⟨9878⟩ = - some (.Push .PUSH32, some (burnPostPositionUpdateEventTopic, 32)) := by - rw [hdec ⟨9878⟩ (by native_decide) (by native_decide)] - native_decide - have hd9911 : decode code ⟨9911⟩ = some (.SWAP2, .none) := by - rw [hdec ⟨9911⟩ (by native_decide) (by native_decide)] - native_decide - have hd9912 : decode code ⟨9912⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨9912⟩ (by native_decide) (by native_decide)] - native_decide - have hd9913 : decode code ⟨9913⟩ = some (.DUP2, .none) := by - rw [hdec ⟨9913⟩ (by native_decide) (by native_decide)] - native_decide - have hd9914 : decode code ⟨9914⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨9914⟩ (by native_decide) (by native_decide)] - native_decide - have hd9915 : decode code ⟨9915⟩ = some (.SUB, .none) := by - rw [hdec ⟨9915⟩ (by native_decide) (by native_decide)] - native_decide - have hd9916 : decode code ⟨9916⟩ = some (.Push .PUSH1, some (⟨96⟩, 1)) := by - rw [hdec ⟨9916⟩ (by native_decide) (by native_decide)] - native_decide - have hd9918 : decode code ⟨9918⟩ = some (.ADD, .none) := by - rw [hdec ⟨9918⟩ (by native_decide) (by native_decide)] - native_decide - have hd9919 : decode code ⟨9919⟩ = some (.SWAP1, .none) := by - rw [hdec ⟨9919⟩ (by native_decide) (by native_decide)] - native_decide - have hd9920 : decode code ⟨9920⟩ = some (.LOG4, .none) := by - rw [hdec ⟨9920⟩ (by native_decide) (by native_decide)] - native_decide - have rd9837 := evm_run h with [ - raw jumpdest hd9833 (by evm_ov), - raw push1 ⟨64⟩ hd9834 (by evm_ov), - raw dup1 hd9836 (by evm_ov)] - have rd9838 := evm_run rd9837 with [ - raw mload 0 (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) - (UInt256.ofNat 22) hd9837 mem_cost - (burnPositionUpdateMem5_mload64 σ ee pos0 posBase) - (by native_decide) (by evm_ov)] - have rd9849 := evm_run rd9838 with [ - raw push1 ⟨1⟩ hd9838 (by evm_ov), - raw push1 ⟨1⟩ hd9840 (by evm_ov), - raw push1 ⟨128⟩ hd9842 (by evm_ov), - raw shl hd9844 (by evm_ov), - raw sub hd9845 (by evm_ov), - raw dup9 hd9846 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd9847 (by evm_ov), - raw dup2 hd9848 (by evm_ov), - raw mstore 4 (burnPostPositionUpdateEventMem0 σ ee pos0 posBase amount) - (UInt256.ofNat 23) hd9849 mem_cost rfl (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd9856 := evm_run rd9849 with [ - raw push1 ⟨32⟩ hd9850 (by evm_ov), - raw dup2 hd9852 (by evm_ov), - raw add hd9853 (by evm_ov), - raw dup8 hd9854 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap1 hd9855 (by evm_ov), - raw mstore 3 (burnPostPositionUpdateEventMem1 σ ee pos0 posBase amount) - (UInt256.ofNat 24) hd9856 mem_cost rfl (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd9862 := evm_run rd9856 with [ - raw dup1 hd9857 (by evm_ov), - raw dup3 hd9858 (by evm_ov), - raw add hd9859 (by evm_ov), - raw dup7 hd9860 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap1 hd9861 (by evm_ov), - raw mstore 3 (burnPostPositionUpdateEventMem σ ee pos0 posBase amount) - (UInt256.ofNat 25) hd9862 mem_cost rfl (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd9864 := evm_run rd9862 with [ - raw swap1 hd9863 (by evm_ov)] - have rd9865 := evm_run rd9864 with [ - raw mload 0 (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) - (UInt256.ofNat 25) hd9864 mem_cost - (burnPostPositionUpdateEventMem_mload64 σ ee pos0 posBase amount) - (by native_decide) (by evm_ov)] - have rd9869 := evm_run rd9865 with [ - raw push1 ⟨2⟩ hd9865 (by evm_ov), - raw dup10 hd9867 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup2 hd9868 (by evm_ov)] - have rd9870 := RD.signextend rd9869 hd9869 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd9872 := evm_run rd9870 with [ - raw swap3 hd9870 (by evm_ov), - raw swap1 hd9871 (by evm_ov)] - have rd9873 := RD.dup12 rd9872 hd9872 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd9874 := evm_run rd9873 with [ - raw swap1 hd9873 (by evm_ov)] - have rd9875 := RD.signextend rd9874 hd9874 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd9919 := evm_run rd9875 with [ - raw swap2 hd9875 (by evm_ov), - raw caller hd9876 (by evm_ov), - raw swap2 hd9877 (by evm_ov), - raw pushConst burnPostPositionUpdateEventTopic - (show Operation.POp.PUSH32 ≠ Operation.POp.PUSH0 by native_decide) - hd9878 (by evm_ov), - raw swap2 hd9911 (by evm_ov), - raw swap1 hd9912 (by evm_ov), - raw dup2 hd9913 (by evm_ov), - raw swap1 hd9914 (by evm_ov), - raw sub hd9915 (by evm_ov), - raw push1 ⟨96⟩ hd9916 (by evm_ov), - raw add hd9918 (by evm_ov)] - have rd9921 := evm_run rd9919 with [ - raw swap1 hd9919 (by evm_ov), - raw log4 0 (UInt256.ofNat 25) hd9920 hperm mem_cost - (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - exact ⟨_, _, by simpa [burnPositionUpdateSlot0Mask] using rd9921⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnPostPositionUpdateUnlockReturn {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {σmem σacc : AccountMap} {pos0 posBase amount upper lower : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨9921⟩ - (⟨0⟩ :: ⟨0⟩ :: posBase :: ⟨0⟩ :: ⟨0⟩ :: amount :: upper :: lower :: - ⟨621⟩ :: R) - (burnPostPositionUpdateEventMem σmem ee pos0 posBase amount) (UInt256.ofNat 25) - rdata (cA, σacc) k C) - (hperm : ee.perm = true) - (hov : R.length + 12 ≤ 1024) : - RDret code g s0 - (cA, sstoreAccountMap ee.codeOwner σacc ⟨0⟩ - (burnPostPositionUpdateUnlockedSlotWord σacc ee)) - (UInt256.toByteArray (⟨0⟩ : UInt256) ++ UInt256.toByteArray (⟨0⟩ : UInt256)) := by - have hdecEvent (pc : UInt256) - (hlo : 9833 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 9984) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnEventDecodeEqTemplate hpatch hlo hhi - have hd9921 : decode code ⟨9921⟩ = some (.POP, .none) := by - rw [hdecEvent ⟨9921⟩ (by native_decide) (by native_decide)] - native_decide - have hd9922 : decode code ⟨9922⟩ = some (.POP, .none) := by - rw [hdecEvent ⟨9922⟩ (by native_decide) (by native_decide)] - native_decide - have hd9923 : decode code ⟨9923⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecEvent ⟨9923⟩ (by native_decide) (by native_decide)] - native_decide - have hd9925 : decode code ⟨9925⟩ = some (.DUP1, .none) := by - rw [hdecEvent ⟨9925⟩ (by native_decide) (by native_decide)] - native_decide - have hd9926 : decode code ⟨9926⟩ = some (.SLOAD, .none) := by - rw [hdecEvent ⟨9926⟩ (by native_decide) (by native_decide)] - native_decide - have hd9927 : decode code ⟨9927⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - rw [hdecEvent ⟨9927⟩ (by native_decide) (by native_decide)] - native_decide - have hd9929 : decode code ⟨9929⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - rw [hdecEvent ⟨9929⟩ (by native_decide) (by native_decide)] - native_decide - have hd9931 : decode code ⟨9931⟩ = some (.SHL, .none) := by - rw [hdecEvent ⟨9931⟩ (by native_decide) (by native_decide)] - native_decide - have hd9932 : decode code ⟨9932⟩ = some (.NOT, .none) := by - rw [hdecEvent ⟨9932⟩ (by native_decide) (by native_decide)] - native_decide - have hd9933 : decode code ⟨9933⟩ = some (.AND, .none) := by - rw [hdecEvent ⟨9933⟩ (by native_decide) (by native_decide)] - native_decide - have hd9934 : decode code ⟨9934⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecEvent ⟨9934⟩ (by native_decide) (by native_decide)] - native_decide - have hd9936 : decode code ⟨9936⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - rw [hdecEvent ⟨9936⟩ (by native_decide) (by native_decide)] - native_decide - have hd9938 : decode code ⟨9938⟩ = some (.SHL, .none) := by - rw [hdecEvent ⟨9938⟩ (by native_decide) (by native_decide)] - native_decide - have hd9939 : decode code ⟨9939⟩ = some (.OR, .none) := by - rw [hdecEvent ⟨9939⟩ (by native_decide) (by native_decide)] - native_decide - have hd9940 : decode code ⟨9940⟩ = some (.SWAP1, .none) := by - rw [hdecEvent ⟨9940⟩ (by native_decide) (by native_decide)] - native_decide - have hd9941 : decode code ⟨9941⟩ = some (.SSTORE, .none) := by - rw [hdecEvent ⟨9941⟩ (by native_decide) (by native_decide)] - native_decide - have hd9942 : decode code ⟨9942⟩ = some (.POP, .none) := by - rw [hdecEvent ⟨9942⟩ (by native_decide) (by native_decide)] - native_decide - have hd9943 : decode code ⟨9943⟩ = some (.SWAP1, .none) := by - rw [hdecEvent ⟨9943⟩ (by native_decide) (by native_decide)] - native_decide - have hd9944 : decode code ⟨9944⟩ = some (.SWAP5, .none) := by - rw [hdecEvent ⟨9944⟩ (by native_decide) (by native_decide)] - native_decide - have hd9945 : decode code ⟨9945⟩ = some (.SWAP1, .none) := by - rw [hdecEvent ⟨9945⟩ (by native_decide) (by native_decide)] - native_decide - have hd9946 : decode code ⟨9946⟩ = some (.SWAP4, .none) := by - rw [hdecEvent ⟨9946⟩ (by native_decide) (by native_decide)] - native_decide - have hd9947 : decode code ⟨9947⟩ = some (.POP, .none) := by - rw [hdecEvent ⟨9947⟩ (by native_decide) (by native_decide)] - native_decide - have hd9948 : decode code ⟨9948⟩ = some (.SWAP2, .none) := by - rw [hdecEvent ⟨9948⟩ (by native_decide) (by native_decide)] - native_decide - have hd9949 : decode code ⟨9949⟩ = some (.POP, .none) := by - rw [hdecEvent ⟨9949⟩ (by native_decide) (by native_decide)] - native_decide - have hd9950 : decode code ⟨9950⟩ = some (.POP, .none) := by - rw [hdecEvent ⟨9950⟩ (by native_decide) (by native_decide)] - native_decide - have hd9951 : decode code ⟨9951⟩ = some (.JUMP, .none) := by - rw [hdecEvent ⟨9951⟩ (by native_decide) (by native_decide)] - native_decide - have hd621 : decode code ⟨621⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd622 : decode code ⟨622⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd624 : decode code ⟨624⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd625 : decode code ⟨625⟩ = some (.MLOAD, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd626 : decode code ⟨626⟩ = some (.SWAP3, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd627 : decode code ⟨627⟩ = some (.DUP4, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd628 : decode code ⟨628⟩ = some (.MSTORE, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd629 : decode code ⟨629⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd631 : decode code ⟨631⟩ = some (.DUP4, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd632 : decode code ⟨632⟩ = some (.ADD, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd633 : decode code ⟨633⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd634 : decode code ⟨634⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd635 : decode code ⟨635⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd636 : decode code ⟨636⟩ = some (.MSTORE, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd637 : decode code ⟨637⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd638 : decode code ⟨638⟩ = some (.MLOAD, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd639 : decode code ⟨639⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd640 : decode code ⟨640⟩ = some (.DUP3, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd641 : decode code ⟨641⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd642 : decode code ⟨642⟩ = some (.SUB, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd643 : decode code ⟨643⟩ = some (.ADD, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd644 : decode code ⟨644⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd645 : decode code ⟨645⟩ = some (.RETURN, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have rd9926 := evm_run h with [ - raw pop hd9921 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw pop hd9922 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨0⟩ hd9923 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd9925 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - obtain ⟨_, _, rd9927₀⟩ := rd9926.sload hd9926 (by evm_ov) - have rd9941 := evm_run rd9927₀ with [ - raw push1 ⟨255⟩ hd9927 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨240⟩ hd9929 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd9931 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw not hd9932 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd9933 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨1⟩ hd9934 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨240⟩ hd9936 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd9938 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw lor hd9939 (by evm_ov), - raw swap1 hd9940 (by evm_ov)] - obtain ⟨_, _, rd9942⟩ := rd9941.sstore hperm hd9941 (by evm_ov) - have rd9951 := evm_run rd9942 with [ - raw pop hd9942 (by evm_ov), - raw swap1 hd9943 (by evm_ov), - raw swap5 hd9944 (by - have h := hov - omega), - raw swap1 hd9945 (by evm_ov), - raw swap4 hd9946 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw pop hd9947 (by evm_ov), - raw swap2 hd9948 (by evm_ov), - raw pop hd9949 (by evm_ov), - raw pop hd9950 (by evm_ov)] - have rd621 := rd9951.jump hd9951 - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) (by evm_ov) - have rd628 := evm_run rd621 with [ - raw jumpdest hd621 (by evm_ov), - raw push1 ⟨64⟩ hd622 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd624 (by evm_ov), - raw mload 0 (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) - (UInt256.ofNat 25) hd625 mem_cost - (burnPostPositionUpdateEventMem_mload64 σmem ee pos0 posBase amount) - (by native_decide) (by evm_ov), - raw swap3 hd626 (by evm_ov), - raw dup4 hd627 (by evm_ov)] - have rd637 := evm_run rd628 with [ - raw mstore 0 (burnPostPositionUpdateReturnMem0 σmem ee pos0 posBase amount) - (UInt256.ofNat 25) hd628 mem_cost (by rfl) (by native_decide) (by evm_ov), - raw push1 ⟨32⟩ hd629 (by evm_ov), - raw dup4 hd631 (by evm_ov), - raw add hd632 (by evm_ov), - raw swap2 hd633 (by evm_ov), - raw swap1 hd634 (by evm_ov), - raw swap2 hd635 (by evm_ov), - raw mstore 0 (burnPostPositionUpdateReturnMem σmem ee pos0 posBase amount) - (UInt256.ofNat 25) hd636 mem_cost - (by - rw [show ((burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) + - (⟨32⟩ : UInt256)).toNat = - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256) + - (⟨32⟩ : UInt256)).toNat from by native_decide] - rfl) - (by native_decide) (by evm_ov)] - exact evm_run rd637 with [ - raw dup1 hd637 (by evm_ov), - raw mload 0 (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) - (UInt256.ofNat 25) hd638 mem_cost - (burnPostPositionUpdateReturnMem_mload64 σmem ee pos0 posBase amount) - (by native_decide) (by evm_ov), - raw swap2 hd639 (by evm_ov), - raw dup3 hd640 (by evm_ov), - raw swap1 hd641 (by evm_ov), - raw sub hd642 (by evm_ov), - raw add hd643 (by evm_ov), - raw swap1 hd644 (by evm_ov), - raw ret 0 - (UInt256.toByteArray (⟨0⟩ : UInt256) ++ UInt256.toByteArray (⟨0⟩ : UInt256)) - hd645 mem_cost - (by - rw [show (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)).toNat = - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)).toNat from rfl, - show (UInt256.sub - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) - (burnPositionKeyNewFreePtrWord + (⟨160⟩ : UInt256)) + - (⟨64⟩ : UInt256)).toNat = 64 - from by native_decide] - exact burnPostPositionUpdateReturnMem_readFree σmem ee pos0 posBase amount) - (by evm_ov)] - -abbrev burnPostPositionUpdateTokensOwedAccountMap - (ee : ExecutionEnv) (σ : AccountMap) - (posBase tokensOwed0 tokensOwed1 : UInt256) : AccountMap := - sstoreAccountMap ee.codeOwner σ (posBase + (⟨3⟩ : UInt256)) - (burnPositionUpdateTokensOwedAddedSlot3 - (solcSlotWord σ ee (posBase + (⟨3⟩ : UInt256))) tokensOwed0 tokensOwed1) - -theorem burnPostPositionUpdateUnlockedSlotWord_eq_slot0UnlockedTrueSlotWord - {evm : EVM.State} {σ : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ evm.accountMap) (hEnv : evm.executionEnv = I) : - burnPostPositionUpdateUnlockedSlotWord σ I = slot0UnlockedTrueSlotWord evm := by - simpa [burnPostPositionUpdateUnlockedSlotWord, burnPostPositionUpdateUnlockedClearMask, - slot0UnlockedClearMask] using - slot0UnlockedTrueSlotWord_eq_of_accountMapEquiv - (evm := evm) (σ := σ) (I := I) hAccounts hEnv - -theorem burnPostPositionUpdateFinalAccountMapEquiv - {evm : EVM.State} {σ : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ evm.accountMap) (hEnv : evm.executionEnv = I) : - accountMapEquiv - (sstoreAccountMap I.codeOwner σ ⟨0⟩ - (burnPostPositionUpdateUnlockedSlotWord σ I)) - (slot0AfterUnlockState evm).accountMap := by - have hword := burnPostPositionUpdateUnlockedSlotWord_eq_slot0UnlockedTrueSlotWord - (evm := evm) (σ := σ) (I := I) hAccounts hEnv - rw [hword] - simpa [slot0AfterUnlockState, storageStore_accountMap, hEnv] using - accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (slot0UnlockedTrueSlotWord evm) hAccounts - -theorem uniswapV3PoolBurnZeroDeltaPositionUpdateToFinalReturnCases - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tokensOwed1 tokensOwed0 liquidity inside1 inside0 delta posBase inside1' inside0' - z2 z3 fee1 fee0 tick delta' lower upper owner free r3 amount eventUpper eventLower : - UInt256} - {R : List UInt256} {σmem : AccountMap} {pos0 : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdest : (D_J code 0).contains ⟨9737⟩ = true) - (hperm : ee.perm = true) - (hzero : burnAmountCleanWord ee = ⟨0⟩) - (hmload224 : - (if (⟨224⟩ : UInt256).toNat ≥ - (burnPositionUpdateMem5 σmem ee pos0 posBase).size - ∨ (⟨224⟩ : UInt256) ≥ UInt256.ofNat 22 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnPositionUpdateMem5 σmem ee pos0 posBase).readWithPadding - (⟨224⟩ : UInt256).toNat 32))) = - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee))) - (h : RD code ee g s0 ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: liquidity :: burnPositionKeyNewFreePtrWord :: - inside1 :: inside0 :: delta :: posBase :: ⟨19527⟩ :: inside1' :: inside0' :: - z2 :: z3 :: fee1 :: fee0 :: posBase :: tick :: delta' :: upper :: lower :: - owner :: ⟨16428⟩ :: free :: ⟨0⟩ :: ⟨0⟩ :: r3 :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: amount :: eventUpper :: - eventLower :: ⟨621⟩ :: R) - (burnPositionUpdateMem5 σmem ee pos0 posBase) (UInt256.ofNat 22) rdata - (cA, σ) k C) - (hdelta : UInt256.slt (UInt256.signextend ⟨15⟩ delta') ⟨0⟩ = ⟨0⟩) - (hov : R.length + 49 ≤ 1024) : - (RDret code g s0 - (cA, sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (burnPostPositionUpdateUnlockedSlotWord σ ee)) - (UInt256.toByteArray (⟨0⟩ : UInt256) ++ UInt256.toByteArray (⟨0⟩ : UInt256)) ∧ - UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 = ⟨0⟩ ∧ - UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 = ⟨0⟩) ∨ - (RDret code g s0 - (cA, sstoreAccountMap ee.codeOwner - (burnPostPositionUpdateTokensOwedAccountMap ee σ posBase tokensOwed0 tokensOwed1) - ⟨0⟩ - (burnPostPositionUpdateUnlockedSlotWord - (burnPostPositionUpdateTokensOwedAccountMap ee σ posBase tokensOwed0 tokensOwed1) - ee)) - (UInt256.toByteArray (⟨0⟩ : UInt256) ++ UInt256.toByteArray (⟨0⟩ : UInt256)) ∧ - (UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 ≠ ⟨0⟩ ∨ - UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 ≠ ⟨0⟩)) := by - obtain hcases := - uniswapV3PoolBurnPositionUpdateZeroDeltaReturnToCallerByTokensCases - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := liquidity) (inside1 := inside1) (inside0 := inside0) - (delta := delta) (posBase := posBase) (inside1' := inside1') - (inside0' := inside0') (z2 := z2) (z3 := z3) (fee1 := fee1) - (fee0 := fee0) (posBase' := posBase) (tick := tick) (delta' := delta') - (upper := upper) (lower := lower) (owner := owner) (free := free) - (r1 := ⟨0⟩) (r2 := ⟨0⟩) (r3 := r3) (callerRet := ⟨9737⟩) - (R := ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: amount :: eventUpper :: - eventLower :: ⟨621⟩ :: R) - (mem := burnPositionUpdateMem5 σmem ee pos0 posBase) (rdata := rdata) - (cA := cA) (σ := σ) - hpatch hdest hperm hzero hmload224 h hdelta - (by simp only [List.length_cons]; omega) - rcases hcases with hzeroTokens | hsomeTokens - · rcases hzeroTokens with ⟨_, _, hrdRet, htokens0, htokens1⟩ - obtain ⟨_, _, hrdEvent⟩ := - uniswapV3PoolBurnPostPositionUpdateZeroAmountsToEvent - (v := v) hpatch hrdRet - (by omega) - obtain ⟨_, _, hrdLog⟩ := - uniswapV3PoolBurnPostPositionUpdateEventLog - (v := v) (σ := σmem) (pos0 := pos0) hpatch hrdEvent hperm - (by omega) - have hrdSuccess := - uniswapV3PoolBurnPostPositionUpdateUnlockReturn - (v := v) hpatch hrdLog hperm - (by omega) - exact Or.inl ⟨hrdSuccess, htokens0, htokens1⟩ - · rcases hsomeTokens with ⟨_, _, hrdRet, htokens⟩ - obtain ⟨_, _, hrdEvent⟩ := - uniswapV3PoolBurnPostPositionUpdateZeroAmountsToEvent - (v := v) hpatch hrdRet - (by omega) - obtain ⟨_, _, hrdLog⟩ := - uniswapV3PoolBurnPostPositionUpdateEventLog - (v := v) (σ := σmem) (pos0 := pos0) hpatch hrdEvent hperm - (by omega) - have hrdSuccess := - uniswapV3PoolBurnPostPositionUpdateUnlockReturn - (v := v) hpatch hrdLog hperm - (by omega) - exact Or.inr ⟨by - simpa [burnPostPositionUpdateTokensOwedAccountMap] using hrdSuccess, htokens⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnSourceSuccess.lean b/Benchmarks/UniswapV3Pool/BurnSourceSuccess.lean deleted file mode 100644 index c0a1885e..00000000 --- a/Benchmarks/UniswapV3Pool/BurnSourceSuccess.lean +++ /dev/null @@ -1,1214 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnTickGetFeeGrowthInsideSource -import Benchmarks.UniswapV3Pool.BurnPostPositionUpdate - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev burnModifyPositionAfterPositionUpdateFrame - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnModifyPositionAfterFeeGrowthInsideFrame v σ I).locals.insert - "_positionUpdated" .unit } - -abbrev burnModifyPositionAfterAmount0Frame - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnModifyPositionAfterPositionUpdateFrame v σ I).locals.insert - "amount0" (.int 0) } - -abbrev burnModifyPositionAfterAmount1Frame - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnModifyPositionAfterAmount0Frame v σ I).locals.insert - "amount1" (.int 0) } - -theorem burnAfterPositionUpdateFrame_liquidityDelta {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterPositionUpdateFrame v σ I).locals.get? "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnModifyPositionAfterPositionUpdateFrame] - rw [store_get_ne (burnModifyPositionAfterFeeGrowthInsideFrame v σ I).locals - (k := "_positionUpdated") (a := "liquidityDelta") .unit (by native_decide)] - exact burnAfterFeeGrowthInsideFrame_liquidityDelta σ I - -theorem burnAfterPositionUpdateFrame_positionKey {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterPositionUpdateFrame v σ I).locals.get? "_positionKey" = - some (burnPositionKeyValue I) := by - rw [burnModifyPositionAfterPositionUpdateFrame] - rw [store_get_ne (burnModifyPositionAfterFeeGrowthInsideFrame v σ I).locals - (k := "_positionUpdated") (a := "_positionKey") .unit (by native_decide)] - exact burnAfterFeeGrowthInsideFrame_positionKey σ I - -theorem burnAfterAmount0Frame_liquidityDelta {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterAmount0Frame v σ I).locals.get? "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnModifyPositionAfterAmount0Frame] - rw [store_get_ne (burnModifyPositionAfterPositionUpdateFrame v σ I).locals - (k := "amount0") (a := "liquidityDelta") (.int 0) (by native_decide)] - exact burnAfterPositionUpdateFrame_liquidityDelta σ I - -theorem burnAfterAmount1Frame_liquidityDelta {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterAmount1Frame v σ I).locals.get? "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnModifyPositionAfterAmount1Frame] - rw [store_get_ne (burnModifyPositionAfterAmount0Frame v σ I).locals - (k := "amount1") (a := "liquidityDelta") (.int 0) (by native_decide)] - exact burnAfterAmount0Frame_liquidityDelta σ I - -theorem burnAfterAmount1Frame_positionKey {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterAmount1Frame v σ I).locals.get? "_positionKey" = - some (burnPositionKeyValue I) := by - rw [burnModifyPositionAfterAmount1Frame, burnModifyPositionAfterAmount0Frame] - rw [store_get_ne (burnModifyPositionAfterAmount0Frame v σ I).locals - (k := "amount1") (a := "_positionKey") (.int 0) (by native_decide)] - rw [store_get_ne (burnModifyPositionAfterPositionUpdateFrame v σ I).locals - (k := "amount0") (a := "_positionKey") (.int 0) (by native_decide)] - exact burnAfterPositionUpdateFrame_positionKey σ I - -theorem burnAfterAmount1Frame_amount0 {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterAmount1Frame v σ I).locals.get? "amount0" = - some (.int 0) := by - rw [burnModifyPositionAfterAmount1Frame] - rw [store_get_ne (burnModifyPositionAfterAmount0Frame v σ I).locals - (k := "amount1") (a := "amount0") (.int 0) (by native_decide)] - rw [burnModifyPositionAfterAmount0Frame] - exact store_get_self (burnModifyPositionAfterPositionUpdateFrame v σ I).locals - "amount0" (.int 0) - -theorem burnAfterAmount1Frame_amount1 {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterAmount1Frame v σ I).locals.get? "amount1" = - some (.int 0) := by - rw [burnModifyPositionAfterAmount1Frame] - exact store_get_self (burnModifyPositionAfterAmount0Frame v σ I).locals "amount1" (.int 0) - -theorem burnModifyPosition_evalLiquidityDeltaLtZeroFalseAfterPositionUpdate - {v : PoolImmutables} {evm σ I} - (hzero : burnAmountCleanWord I = ⟨0⟩) : - evalExpr? (config v) (burnModifyPositionAfterPositionUpdateFrame v σ I) evm - (ltE (.var "liquidityDelta") (.intLit 0)) = .ok (.bool false) := by - simp only [ltE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnAfterPositionUpdateFrame_liquidityDelta (v := v) (σ := σ) (I := I)] - simp [EvalResult.ofOption, burnLiquidityDeltaValue, hzero, evalBinaryOp?] - -theorem burnModifyPosition_evalLiquidityDeltaNeZeroFalseAfterAmount1 - {v : PoolImmutables} {evm σ I} - (hzero : burnAmountCleanWord I = ⟨0⟩) : - evalExpr? (config v) (burnModifyPositionAfterAmount1Frame v σ I) evm - (neE (.var "liquidityDelta") (.intLit 0)) = .ok (.bool false) := by - simp only [neE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnAfterAmount1Frame_liquidityDelta (v := v) (σ := σ) (I := I)] - simp [EvalResult.ofOption, burnLiquidityDeltaValue, hzero, evalBinaryOp?] - -theorem burnModifyPosition_evalReturnValuesAfterAmount1 {v : PoolImmutables} - {evm σ I} : - evalExprs? (config v) (burnModifyPositionAfterAmount1Frame v σ I) evm - [.var "_positionKey", .var "amount0", .var "amount1"] = - .ok [burnPositionKeyValue I, .int 0, .int 0] := by - simp only [evalExprs?, evalExpr?, EvalResult.bind, bind, pure] - rw [burnAfterAmount1Frame_positionKey (v := v) (σ := σ) (I := I)] - rw [burnAfterAmount1Frame_amount0 (v := v) (σ := σ) (I := I)] - rw [burnAfterAmount1Frame_amount1 (v := v) (σ := σ) (I := I)] - rfl - -abbrev burnModifyPositionAfterPositionUpdateTail : List Stmt := - [ Stmt.ite (ltE (.var "liquidityDelta") (.intLit 0)) - [ Stmt.ite (.var "flippedLower") - [ .internalCall "tickClear" [.var "tickLower"] "_clearLower" ] - [], - Stmt.ite (.var "flippedUpper") - [ .internalCall "tickClear" [.var "tickUpper"] "_clearUpper" ] - [] ] - [], - .letDecl "amount0" (some int256) (.intLit 0), - .letDecl "amount1" (some int256) (.intLit 0), - Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ Stmt.ite (ltE (.var "_slot0tick") (.var "tickLower")) - [ .internalCall "getSqrtRatioAtTick" [.var "tickLower"] "sqrtRatioLowerBelow", - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] "sqrtRatioUpperBelow", - .internalCall "getAmount0DeltaSigned" - [ .var "sqrtRatioLowerBelow", .var "sqrtRatioUpperBelow", .var "liquidityDelta" ] - "amount0Below", - .assign .localVar (varRef "amount0") (.var "amount0Below") ] - [ Stmt.ite (ltE (.var "_slot0tick") (.var "tickUpper")) - [ .letDecl "liquidityBefore" (some uint128) (.storage liquidityRef), - .internalCall "oracleWrite" - [ .var "_slot0observationIndex", blockTimestamp32, .var "_slot0tick", - .var "liquidityBefore", .var "_slot0observationCardinality", - .var "_slot0observationCardinalityNext" ] - "oracleUpdated", - .assign .storage (slot0F "observationIndex") (tuple0 (.var "oracleUpdated")), - .assign .storage (slot0F "observationCardinality") - (tuple1 (.var "oracleUpdated")), - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] - "sqrtRatioUpperInside", - .internalCall "getAmount0DeltaSigned" - [ .var "_slot0sqrtPriceX96", .var "sqrtRatioUpperInside", - .var "liquidityDelta" ] - "amount0Inside", - .assign .localVar (varRef "amount0") (.var "amount0Inside"), - .internalCall "getSqrtRatioAtTick" [.var "tickLower"] - "sqrtRatioLowerInside", - .internalCall "getAmount1DeltaSigned" - [ .var "sqrtRatioLowerInside", .var "_slot0sqrtPriceX96", - .var "liquidityDelta" ] - "amount1Inside", - .assign .localVar (varRef "amount1") (.var "amount1Inside"), - .internalCall "liquidityAddDelta" - [ .var "liquidityBefore", .var "liquidityDelta" ] - "liquidityAfter", - .assign .storage liquidityRef (.var "liquidityAfter") ] - [ .internalCall "getSqrtRatioAtTick" [.var "tickLower"] - "sqrtRatioLowerAbove", - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] - "sqrtRatioUpperAbove", - .internalCall "getAmount1DeltaSigned" - [ .var "sqrtRatioLowerAbove", .var "sqrtRatioUpperAbove", - .var "liquidityDelta" ] - "amount1Above", - .assign .localVar (varRef "amount1") (.var "amount1Above") ] ] ] - [], - .return [.var "_positionKey", .var "amount0", .var "amount1"] ] - -theorem uniswapV3PoolModifyPositionSourceZeroDeltaAfterPositionUpdateTail - {v : PoolImmutables} {evm σ I} - (hzero : burnAmountCleanWord I = ⟨0⟩) : - ExecBlock (config v) (burnModifyPositionAfterPositionUpdateFrame v σ I) evm - [ Stmt.ite (ltE (.var "liquidityDelta") (.intLit 0)) - [ Stmt.ite (.var "flippedLower") - [ .internalCall "tickClear" [.var "tickLower"] "_clearLower" ] - [], - Stmt.ite (.var "flippedUpper") - [ .internalCall "tickClear" [.var "tickUpper"] "_clearUpper" ] - [] ] - [], - .letDecl "amount0" (some int256) (.intLit 0), - .letDecl "amount1" (some int256) (.intLit 0), - Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ Stmt.ite (ltE (.var "_slot0tick") (.var "tickLower")) - [ .internalCall "getSqrtRatioAtTick" [.var "tickLower"] "sqrtRatioLowerBelow", - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] "sqrtRatioUpperBelow", - .internalCall "getAmount0DeltaSigned" - [ .var "sqrtRatioLowerBelow", .var "sqrtRatioUpperBelow", - .var "liquidityDelta" ] - "amount0Below", - .assign .localVar (varRef "amount0") (.var "amount0Below") ] - [ Stmt.ite (ltE (.var "_slot0tick") (.var "tickUpper")) - [ .letDecl "liquidityBefore" (some uint128) (.storage liquidityRef), - .internalCall "oracleWrite" - [ .var "_slot0observationIndex", blockTimestamp32, .var "_slot0tick", - .var "liquidityBefore", .var "_slot0observationCardinality", - .var "_slot0observationCardinalityNext" ] - "oracleUpdated", - .assign .storage (slot0F "observationIndex") (tuple0 (.var "oracleUpdated")), - .assign .storage (slot0F "observationCardinality") - (tuple1 (.var "oracleUpdated")), - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] - "sqrtRatioUpperInside", - .internalCall "getAmount0DeltaSigned" - [ .var "_slot0sqrtPriceX96", .var "sqrtRatioUpperInside", - .var "liquidityDelta" ] - "amount0Inside", - .assign .localVar (varRef "amount0") (.var "amount0Inside"), - .internalCall "getSqrtRatioAtTick" [.var "tickLower"] - "sqrtRatioLowerInside", - .internalCall "getAmount1DeltaSigned" - [ .var "sqrtRatioLowerInside", .var "_slot0sqrtPriceX96", - .var "liquidityDelta" ] - "amount1Inside", - .assign .localVar (varRef "amount1") (.var "amount1Inside"), - .internalCall "liquidityAddDelta" - [ .var "liquidityBefore", .var "liquidityDelta" ] - "liquidityAfter", - .assign .storage liquidityRef (.var "liquidityAfter") ] - [ .internalCall "getSqrtRatioAtTick" [.var "tickLower"] - "sqrtRatioLowerAbove", - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] - "sqrtRatioUpperAbove", - .internalCall "getAmount1DeltaSigned" - [ .var "sqrtRatioLowerAbove", .var "sqrtRatioUpperAbove", - .var "liquidityDelta" ] - "amount1Above", - .assign .localVar (varRef "amount1") (.var "amount1Above") ] ] ] - [], - .return [.var "_positionKey", .var "amount0", .var "amount1"] ] - (.returned (burnModifyPositionAfterAmount1Frame v σ I) evm - (some [burnPositionKeyValue I, .int 0, .int 0])) := by - have hskipClears : - ExecStmt (config v) (burnModifyPositionAfterPositionUpdateFrame v σ I) evm - (Stmt.ite (ltE (.var "liquidityDelta") (.intLit 0)) - [ Stmt.ite (.var "flippedLower") - [ .internalCall "tickClear" [.var "tickLower"] "_clearLower" ] - [], - Stmt.ite (.var "flippedUpper") - [ .internalCall "tickClear" [.var "tickUpper"] "_clearUpper" ] - [] ] - []) - (.ok (burnModifyPositionAfterPositionUpdateFrame v σ I) evm) := by - refine ExecStmt.iteFalse - (burnModifyPosition_evalLiquidityDeltaLtZeroFalseAfterPositionUpdate - (v := v) (evm := evm) (σ := σ) (I := I) hzero) ?_ - exact ExecBlock.nil - have hamount0 : - ExecStmt (config v) (burnModifyPositionAfterPositionUpdateFrame v σ I) evm - (.letDecl "amount0" (some int256) (.intLit 0)) - (.ok (burnModifyPositionAfterAmount0Frame v σ I) evm) := by - refine ExecStmt.letDecl ?_ - simp [evalExpr?, pure] - have hamount1 : - ExecStmt (config v) (burnModifyPositionAfterAmount0Frame v σ I) evm - (.letDecl "amount1" (some int256) (.intLit 0)) - (.ok (burnModifyPositionAfterAmount1Frame v σ I) evm) := by - refine ExecStmt.letDecl ?_ - simp [evalExpr?, pure] - have hskipAmounts : - ExecStmt (config v) (burnModifyPositionAfterAmount1Frame v σ I) evm - (Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ Stmt.ite (ltE (.var "_slot0tick") (.var "tickLower")) - [ .internalCall "getSqrtRatioAtTick" [.var "tickLower"] "sqrtRatioLowerBelow", - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] "sqrtRatioUpperBelow", - .internalCall "getAmount0DeltaSigned" - [ .var "sqrtRatioLowerBelow", .var "sqrtRatioUpperBelow", - .var "liquidityDelta" ] - "amount0Below", - .assign .localVar (varRef "amount0") (.var "amount0Below") ] - [ Stmt.ite (ltE (.var "_slot0tick") (.var "tickUpper")) - [ .letDecl "liquidityBefore" (some uint128) (.storage liquidityRef), - .internalCall "oracleWrite" - [ .var "_slot0observationIndex", blockTimestamp32, .var "_slot0tick", - .var "liquidityBefore", .var "_slot0observationCardinality", - .var "_slot0observationCardinalityNext" ] - "oracleUpdated", - .assign .storage (slot0F "observationIndex") (tuple0 (.var "oracleUpdated")), - .assign .storage (slot0F "observationCardinality") - (tuple1 (.var "oracleUpdated")), - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] - "sqrtRatioUpperInside", - .internalCall "getAmount0DeltaSigned" - [ .var "_slot0sqrtPriceX96", .var "sqrtRatioUpperInside", - .var "liquidityDelta" ] - "amount0Inside", - .assign .localVar (varRef "amount0") (.var "amount0Inside"), - .internalCall "getSqrtRatioAtTick" [.var "tickLower"] - "sqrtRatioLowerInside", - .internalCall "getAmount1DeltaSigned" - [ .var "sqrtRatioLowerInside", .var "_slot0sqrtPriceX96", - .var "liquidityDelta" ] - "amount1Inside", - .assign .localVar (varRef "amount1") (.var "amount1Inside"), - .internalCall "liquidityAddDelta" - [ .var "liquidityBefore", .var "liquidityDelta" ] - "liquidityAfter", - .assign .storage liquidityRef (.var "liquidityAfter") ] - [ .internalCall "getSqrtRatioAtTick" [.var "tickLower"] - "sqrtRatioLowerAbove", - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] - "sqrtRatioUpperAbove", - .internalCall "getAmount1DeltaSigned" - [ .var "sqrtRatioLowerAbove", .var "sqrtRatioUpperAbove", - .var "liquidityDelta" ] - "amount1Above", - .assign .localVar (varRef "amount1") (.var "amount1Above") ] ] ] - []) - (.ok (burnModifyPositionAfterAmount1Frame v σ I) evm) := by - refine ExecStmt.iteFalse - (burnModifyPosition_evalLiquidityDeltaNeZeroFalseAfterAmount1 - (v := v) (evm := evm) (σ := σ) (I := I) hzero) ?_ - exact ExecBlock.nil - have hret : - ExecStmt (config v) (burnModifyPositionAfterAmount1Frame v σ I) evm - (.return [.var "_positionKey", .var "amount0", .var "amount1"]) - (.returned (burnModifyPositionAfterAmount1Frame v σ I) evm - (some [burnPositionKeyValue I, .int 0, .int 0])) := by - refine ExecStmt.return ?_ - exact burnModifyPosition_evalReturnValuesAfterAmount1 (v := v) (evm := evm) - (σ := σ) (I := I) - exact ExecBlock.consNormal hskipClears <| - ExecBlock.consNormal hamount0 <| - ExecBlock.consNormal hamount1 <| - ExecBlock.consNormal hskipAmounts <| - ExecBlock.consReturn hret - -theorem uniswapV3PoolModifyPositionSourceZeroDeltaAfterPositionUpdateTailNamed - {v : PoolImmutables} {evm σ I} - (hzero : burnAmountCleanWord I = ⟨0⟩) : - ExecBlock (config v) (burnModifyPositionAfterPositionUpdateFrame v σ I) evm - burnModifyPositionAfterPositionUpdateTail - (.returned (burnModifyPositionAfterAmount1Frame v σ I) evm - (some [burnPositionKeyValue I, .int 0, .int 0])) := by - simpa [burnModifyPositionAfterPositionUpdateTail] using - uniswapV3PoolModifyPositionSourceZeroDeltaAfterPositionUpdateTail - (v := v) (evm := evm) (σ := σ) (I := I) hzero - -theorem uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedZeroReturnsValue - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) - (htokens0 : - burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat) = 0) - (htokens1 : - burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat) = 0) : - ExecFuncBody (config v) - (burnPositionUpdateValueFrame v I (.int (Int.ofNat feeGrowthInside0X128.toNat)) - (.int (Int.ofNat feeGrowthInside1X128.toNat))) - (initState cA gh bl σ σ₀ g A I) positionUpdateFunction.body - (.returned - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128) - none) := by - refine ExecFuncBody.execBlockOK ?_ - simpa [positionUpdateFunction] using - uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedZeroBlockValue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - hzero hliq htokens0 htokens1 - -theorem uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedTrueReturnsValue - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) - (hcond : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128) - (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) = .ok (.bool true)) : - ExecFuncBody (config v) - (burnPositionUpdateValueFrame v I (.int (Int.ofNat feeGrowthInside0X128.toNat)) - (.int (Int.ofNat feeGrowthInside1X128.toNat))) - (initState cA gh bl σ σ₀ g A I) positionUpdateFunction.body - (.returned - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (burnPositionUpdateSourceAfterTokensOwedState - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128) - σ I feeGrowthInside0X128 feeGrowthInside1X128) - none) := by - refine ExecFuncBody.execBlockOK ?_ - simpa [positionUpdateFunction] using - uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedTrueBlockValue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - hzero hliq hcond - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolModifyPositionSourceZeroDeltaTailReturnsZeroTokens - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hinside0 : - burnTickGetInside0Value σ I = .int (Int.ofNat feeGrowthInside0X128.toNat)) - (hinside1 : - burnTickGetInside1Value σ I = .int (Int.ofNat feeGrowthInside1X128.toNat)) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) - (htokens0 : - burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat) = 0) - (htokens1 : - burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat) = 0) : - ExecBlock (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (burnModifyPositionAfterLiquidityDeltaTail v) - (.returned (burnModifyPositionAfterAmount1Frame v σ I) - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128) - (some [burnPositionKeyValue I, .int 0, .int 0])) := by - let evmFees := - Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128 - change ExecBlock (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - ([ .internalCall "tickGetFeeGrowthInside" - [ .var "tickLower", .var "tickUpper", .var "_slot0tick", - .var "_feeGrowthGlobal0X128", .var "_feeGrowthGlobal1X128" ] - "feeGrowthInside", - .internalCall "positionUpdate" - [ .var "_positionKey", .var "liquidityDelta", tuple0 (.var "feeGrowthInside"), - tuple1 (.var "feeGrowthInside") ] - "_positionUpdated" ] ++ burnModifyPositionAfterPositionUpdateTail) - (.returned (burnModifyPositionAfterAmount1Frame v σ I) evmFees - (some [burnPositionKeyValue I, .int 0, .int 0])) - refine ExecBlock.consNormal - (solm' := burnModifyPositionAfterFeeGrowthInsideFrame v σ I) - (evm' := initState cA gh bl σ σ₀ g A I) ?_ ?_ - · have hstmt := internalCallFunctionReturn (callee := tickGetFeeGrowthInsideFunction) - (retVar := "feeGrowthInside") - (argVals := burnTickGetFeeGrowthInsideArgValues σ I) - (locals := burnTickGetFeeGrowthInsideStore σ I) - (calleeSolm := burnTickGetAfterAbove1Frame v σ I) - (value := some [burnTickGetInside0Value σ I, burnTickGetInside1Value σ I]) - (burnModifyPosition_evalTickGetFeeGrowthInsideArgs (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g)) - (by - simpa [burnModifyPositionAfterFeeGrowthGlobalsFrame] using - uniswapV3PoolLookupTickGetFeeGrowthInside v) - (burnTickGetFeeGrowthInside_bindParams σ I) - (uniswapV3PoolTickGetFeeGrowthInsideSourceReturns (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g)) - simpa [burnModifyPositionAfterFeeGrowthInsideFrame, resumeAfterInternalCall, - collapseReturns] using hstmt - · refine ExecBlock.consNormal - (solm' := burnModifyPositionAfterPositionUpdateFrame v σ I) - (evm' := evmFees) ?_ ?_ - · have hbody := - uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedZeroReturnsValue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - hzero hliq htokens0 htokens1 - change ExecFuncBody (config v) - (burnPositionUpdateValueFrame v I (.int (Int.ofNat feeGrowthInside0X128.toNat)) - (.int (Int.ofNat feeGrowthInside1X128.toNat))) - (initState cA gh bl σ σ₀ g A I) positionUpdateFunction.body - (.returned - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evmFees none) at hbody - have hstmt := internalCallFunctionReturn (callee := positionUpdateFunction) - (retVar := "_positionUpdated") - (argVals := burnPositionUpdateValueArgValues I - (burnTickGetInside0Value σ I) (burnTickGetInside1Value σ I)) - (locals := burnPositionUpdateValueStore I - (burnTickGetInside0Value σ I) (burnTickGetInside1Value σ I)) - (calleeSolm := burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (value := none) - (burnModifyPosition_evalPositionUpdateArgsAfterFeeGrowthInside - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g)) - (by - simpa [burnModifyPositionAfterFeeGrowthInsideFrame] using - uniswapV3PoolLookupPositionUpdate v) - (by - simpa [hinside0, hinside1] using - burnPositionUpdateValue_bindParams I - (.int (Int.ofNat feeGrowthInside0X128.toNat)) - (.int (Int.ofNat feeGrowthInside1X128.toNat))) - (by - simpa [hinside0, hinside1, burnPositionUpdateValueFrame] using hbody) - simpa [burnModifyPositionAfterPositionUpdateFrame, resumeAfterInternalCall, - collapseReturns] using hstmt - · exact uniswapV3PoolModifyPositionSourceZeroDeltaAfterPositionUpdateTailNamed - (v := v) (evm := evmFees) (σ := σ) (I := I) hzero - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolModifyPositionSourceZeroDeltaReturnsZeroTokens - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hinside0 : - burnTickGetInside0Value σ I = .int (Int.ofNat feeGrowthInside0X128.toNat)) - (hinside1 : - burnTickGetInside1Value σ I = .int (Int.ofNat feeGrowthInside1X128.toNat)) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) - (htokens0 : - burnPositionUpdateSourceTokensOwed0Int σ I - (Int.ofNat feeGrowthInside0X128.toNat) = 0) - (htokens1 : - burnPositionUpdateSourceTokensOwed1Int σ I - (Int.ofNat feeGrowthInside1X128.toNat) = 0) : - ExecFuncBody (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (modifyPositionFunction v).body - (.returned (burnModifyPositionAfterAmount1Frame v σ I) - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128) - (some [burnPositionKeyValue I, .int 0, .int 0])) := by - refine ExecFuncBody.execBlockRet ?_ - have hprefix := uniswapV3PoolModifyPositionSourceThroughLiquidityDeltaZeroSkip - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hguard htickLt hge hle hzero - have htail := uniswapV3PoolModifyPositionSourceZeroDeltaTailReturnsZeroTokens - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - hinside0 hinside1 hzero hliq htokens0 htokens1 - simpa [modifyPositionFunction, burnModifyPositionSlot0Prefix, - burnModifyPositionPositionKeyStep, burnModifyPositionFeeGrowthGlobalsStep, - burnModifyPositionLiquidityDeltaUpdateStep, burnModifyPositionAfterLiquidityDeltaTail] - using execBlock_append hprefix htail - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolModifyPositionSourceZeroDeltaTailReturnsTokensOwed - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hinside0 : - burnTickGetInside0Value σ I = .int (Int.ofNat feeGrowthInside0X128.toNat)) - (hinside1 : - burnTickGetInside1Value σ I = .int (Int.ofNat feeGrowthInside1X128.toNat)) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) - (hcond : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128) - (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) = .ok (.bool true)) : - ExecBlock (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (burnModifyPositionAfterLiquidityDeltaTail v) - (.returned (burnModifyPositionAfterAmount1Frame v σ I) - (burnPositionUpdateSourceAfterTokensOwedState - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128) - σ I feeGrowthInside0X128 feeGrowthInside1X128) - (some [burnPositionKeyValue I, .int 0, .int 0])) := by - let evmFees := - Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) feeGrowthInside1X128 - let evmTokens := - burnPositionUpdateSourceAfterTokensOwedState evmFees σ I - feeGrowthInside0X128 feeGrowthInside1X128 - change ExecBlock (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - ([ .internalCall "tickGetFeeGrowthInside" - [ .var "tickLower", .var "tickUpper", .var "_slot0tick", - .var "_feeGrowthGlobal0X128", .var "_feeGrowthGlobal1X128" ] - "feeGrowthInside", - .internalCall "positionUpdate" - [ .var "_positionKey", .var "liquidityDelta", tuple0 (.var "feeGrowthInside"), - tuple1 (.var "feeGrowthInside") ] - "_positionUpdated" ] ++ burnModifyPositionAfterPositionUpdateTail) - (.returned (burnModifyPositionAfterAmount1Frame v σ I) evmTokens - (some [burnPositionKeyValue I, .int 0, .int 0])) - refine ExecBlock.consNormal - (solm' := burnModifyPositionAfterFeeGrowthInsideFrame v σ I) - (evm' := initState cA gh bl σ σ₀ g A I) ?_ ?_ - · have hstmt := internalCallFunctionReturn (callee := tickGetFeeGrowthInsideFunction) - (retVar := "feeGrowthInside") - (argVals := burnTickGetFeeGrowthInsideArgValues σ I) - (locals := burnTickGetFeeGrowthInsideStore σ I) - (calleeSolm := burnTickGetAfterAbove1Frame v σ I) - (value := some [burnTickGetInside0Value σ I, burnTickGetInside1Value σ I]) - (burnModifyPosition_evalTickGetFeeGrowthInsideArgs (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g)) - (by - simpa [burnModifyPositionAfterFeeGrowthGlobalsFrame] using - uniswapV3PoolLookupTickGetFeeGrowthInside v) - (burnTickGetFeeGrowthInside_bindParams σ I) - (uniswapV3PoolTickGetFeeGrowthInsideSourceReturns (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g)) - simpa [burnModifyPositionAfterFeeGrowthInsideFrame, resumeAfterInternalCall, - collapseReturns] using hstmt - · refine ExecBlock.consNormal - (solm' := burnModifyPositionAfterPositionUpdateFrame v σ I) - (evm' := evmTokens) ?_ ?_ - · have hbody := - uniswapV3PoolPositionUpdateSourceZeroDeltaLiquidityNonzeroTokensOwedTrueReturnsValue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - hzero hliq hcond - change ExecFuncBody (config v) - (burnPositionUpdateValueFrame v I (.int (Int.ofNat feeGrowthInside0X128.toNat)) - (.int (Int.ofNat feeGrowthInside1X128.toNat))) - (initState cA gh bl σ σ₀ g A I) positionUpdateFunction.body - (.returned - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - evmTokens none) at hbody - have hstmt := internalCallFunctionReturn (callee := positionUpdateFunction) - (retVar := "_positionUpdated") - (argVals := burnPositionUpdateValueArgValues I - (burnTickGetInside0Value σ I) (burnTickGetInside1Value σ I)) - (locals := burnPositionUpdateValueStore I - (burnTickGetInside0Value σ I) (burnTickGetInside1Value σ I)) - (calleeSolm := burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (value := none) - (burnModifyPosition_evalPositionUpdateArgsAfterFeeGrowthInside - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g)) - (by - simpa [burnModifyPositionAfterFeeGrowthInsideFrame] using - uniswapV3PoolLookupPositionUpdate v) - (by - simpa [hinside0, hinside1] using - burnPositionUpdateValue_bindParams I - (.int (Int.ofNat feeGrowthInside0X128.toNat)) - (.int (Int.ofNat feeGrowthInside1X128.toNat))) - (by - simpa [hinside0, hinside1, burnPositionUpdateValueFrame, evmTokens] using hbody) - simpa [burnModifyPositionAfterPositionUpdateFrame, resumeAfterInternalCall, - collapseReturns] using hstmt - · exact uniswapV3PoolModifyPositionSourceZeroDeltaAfterPositionUpdateTailNamed - (v := v) (evm := evmTokens) (σ := σ) (I := I) hzero - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolModifyPositionSourceZeroDeltaReturnsTokensOwed - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hinside0 : - burnTickGetInside0Value σ I = .int (Int.ofNat feeGrowthInside0X128.toNat)) - (hinside1 : - burnTickGetInside1Value σ I = .int (Int.ofNat feeGrowthInside1X128.toNat)) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) - (hcond : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v σ I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128) - (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) = .ok (.bool true)) : - ExecFuncBody (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (modifyPositionFunction v).body - (.returned (burnModifyPositionAfterAmount1Frame v σ I) - (burnPositionUpdateSourceAfterTokensOwedState - (Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128) - σ I feeGrowthInside0X128 feeGrowthInside1X128) - (some [burnPositionKeyValue I, .int 0, .int 0])) := by - refine ExecFuncBody.execBlockRet ?_ - have hprefix := uniswapV3PoolModifyPositionSourceThroughLiquidityDeltaZeroSkip - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hguard htickLt hge hle hzero - have htail := uniswapV3PoolModifyPositionSourceZeroDeltaTailReturnsTokensOwed - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - hinside0 hinside1 hzero hliq hcond - simpa [modifyPositionFunction, burnModifyPositionSlot0Prefix, - burnModifyPositionPositionKeyStep, burnModifyPositionFeeGrowthGlobalsStep, - burnModifyPositionLiquidityDeltaUpdateStep, burnModifyPositionAfterLiquidityDeltaTail] - using execBlock_append hprefix htail - -abbrev burnPublicAfterModifiedFrame - (v : PoolImmutables) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnLiquidityDeltaFrame v I).locals.insert "modified" - (.tuple [burnPositionKeyValue I, .int 0, .int 0]) } - -abbrev burnPublicAfterPositionFrame - (v : PoolImmutables) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnPublicAfterModifiedFrame v I).locals.insert "position" - (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) } - -abbrev burnPublicAfterAmount0Frame - (v : PoolImmutables) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnPublicAfterPositionFrame v I).locals.insert "amount0" (.int 0) } - -abbrev burnPublicAfterAmount1Frame - (v : PoolImmutables) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnPublicAfterAmount0Frame v I).locals.insert "amount1" (.int 0) } - -theorem burnPositionKeyValue_valueToKey (I : ExecutionEnv) : - valueToKey? (burnPositionKeyValue I) = - some (.fixedBytes bytes32Width (ffi.KEC (burnPositionKeyPackedBytes I)).toList) := by - have hlen : - (ffi.KEC (burnPositionKeyPackedBytes I)).toList.length = (31 : Nat) + 1 := by - rw [byteArray_toList_eq, Array.length_toList] - change (ffi.KEC (burnPositionKeyPackedBytes I)).size = (31 : Nat) + 1 - rw [keccak_size] - change valueToKey? (burnPositionKeyValue I) = - some (.fixedBytes (⟨31, by decide⟩ : Fin 32) - (ffi.KEC (burnPositionKeyPackedBytes I)).toList) - simp [valueToKey?, hlen] - -theorem burnPublicAfterModified_positions {v : PoolImmutables} (I : ExecutionEnv) : - (burnPublicAfterModifiedFrame v I).locals.get? "positions" = none := by - rw [burnPublicAfterModifiedFrame, burnLiquidityDeltaFrame, burnStore] - rw [store_get_ne5 (∅ : Store) - (k1 := "tickLower") (k2 := "tickUpper") (k3 := "amount") - (k4 := "liquidityDelta") (k5 := "modified") (a := "positions") - (burnTickLowerValue I) (burnTickUpperValue I) (burnAmountValue I) - (burnLiquidityDeltaValue I) (.tuple [burnPositionKeyValue I, .int 0, .int 0]) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide)] - simp - -set_option maxHeartbeats 1000000 in -theorem burnPublicAfterModified_evalStorageRef_positions {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - evalStorageRef (config v) (burnPublicAfterModifiedFrame v I) evm - (positionsRef (tuple0 (.var "modified"))) = - .ok (burnPositionUpdateEvaledBaseRef I) := by - have htuple : - tupleGetValue? (.tuple [burnPositionKeyValue I, .int 0, .int 0]) 0 = - .ok (burnPositionKeyValue I) := rfl - have hkey := burnPositionKeyValue_valueToKey I - simp [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, positionsRef, tuple0, - evalExpr?, burnPublicAfterModifiedFrame, burnPositionUpdateEvaledBaseRef, - burnPositionKeyKey, htuple, hkey, EvalResult.bind, EvalResult.ofOption, bind, pure] - -theorem burnPublicAfterModified_resolvePositionRef {v : PoolImmutables} - {evm I} : - resolveStorageRef? (config v) (burnPublicAfterModifiedFrame v I) evm - (positionsRef (tuple0 (.var "modified"))) = - .ok (burnPositionUpdateEvaledBaseRef I, positionInfoStructTy) := by - apply resolveStorageRef?_ok - · exact burnPublicAfterModified_positions (v := v) I - · exact burnPublicAfterModified_evalStorageRef_positions (v := v) evm I - · simp [burnPositionUpdateEvaledBaseRef, burnPositionKeyKey, contract, storageDecls, - storageTypeAt?, storageTypeStep?, positionInfoStructTy] - -theorem burnPublicAfterPosition_modified {v : PoolImmutables} (I : ExecutionEnv) : - (burnPublicAfterPositionFrame v I).locals.get? "modified" = - some (.tuple [burnPositionKeyValue I, .int 0, .int 0]) := by - rw [burnPublicAfterPositionFrame] - rw [store_get_ne (burnPublicAfterModifiedFrame v I).locals - (k := "position") (a := "modified") - (.storageRef (burnPositionUpdateEvaledBaseRef I) positionInfoStructTy) (by native_decide)] - rw [burnPublicAfterModifiedFrame] - exact store_get_self (burnLiquidityDeltaFrame v I).locals "modified" - (.tuple [burnPositionKeyValue I, .int 0, .int 0]) - -theorem burnPublicAfterAmount0_modified {v : PoolImmutables} (I : ExecutionEnv) : - (burnPublicAfterAmount0Frame v I).locals.get? "modified" = - some (.tuple [burnPositionKeyValue I, .int 0, .int 0]) := by - rw [burnPublicAfterAmount0Frame] - rw [store_get_ne (burnPublicAfterPositionFrame v I).locals - (k := "amount0") (a := "modified") (.int 0) (by native_decide)] - exact burnPublicAfterPosition_modified (v := v) I - -theorem burnPublicAfterPosition_evalModifiedTuple1 {v : PoolImmutables} {evm I} : - evalExpr? (config v) (burnPublicAfterPositionFrame v I) evm (tuple1 (.var "modified")) = - .ok (.int 0) := by - simp only [tuple1, evalExpr?, EvalResult.bind, bind] - rw [burnPublicAfterPosition_modified (v := v) I] - rfl - -theorem burnPublicAfterAmount0_evalModifiedTuple2 {v : PoolImmutables} {evm I} : - evalExpr? (config v) (burnPublicAfterAmount0Frame v I) evm (tuple2 (.var "modified")) = - .ok (.int 0) := by - simp only [tuple2, evalExpr?, EvalResult.bind, bind] - rw [burnPublicAfterAmount0_modified (v := v) I] - rfl - -theorem burnPublicAfterPosition_evalAmount0 {v : PoolImmutables} {evm I} : - evalExpr? (config v) (burnPublicAfterPositionFrame v I) evm - (uint256Wrap (subE (.intLit 0) (tuple1 (.var "modified")))) = .ok (.int 0) := by - simp only [uint256Wrap, modE, subE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPublicAfterPosition_evalModifiedTuple1 (v := v) (evm := evm) (I := I)] - simp [uint256Modulus, evalExpr?, evalBinaryOp?, pure] - -theorem burnPublicAfterAmount0_evalAmount1 {v : PoolImmutables} {evm I} : - evalExpr? (config v) (burnPublicAfterAmount0Frame v I) evm - (uint256Wrap (subE (.intLit 0) (tuple2 (.var "modified")))) = .ok (.int 0) := by - simp only [uint256Wrap, modE, subE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPublicAfterAmount0_evalModifiedTuple2 (v := v) (evm := evm) (I := I)] - simp [uint256Modulus, evalExpr?, evalBinaryOp?, pure] - -theorem burnPublicAfterAmount1_amount0 {v : PoolImmutables} (I : ExecutionEnv) : - (burnPublicAfterAmount1Frame v I).locals.get? "amount0" = some (.int 0) := by - rw [burnPublicAfterAmount1Frame] - rw [store_get_ne (burnPublicAfterAmount0Frame v I).locals - (k := "amount1") (a := "amount0") (.int 0) (by native_decide)] - rw [burnPublicAfterAmount0Frame] - exact store_get_self (burnPublicAfterPositionFrame v I).locals "amount0" (.int 0) - -theorem burnPublicAfterAmount1_amount1 {v : PoolImmutables} (I : ExecutionEnv) : - (burnPublicAfterAmount1Frame v I).locals.get? "amount1" = some (.int 0) := by - rw [burnPublicAfterAmount1Frame] - exact store_get_self (burnPublicAfterAmount0Frame v I).locals "amount1" (.int 0) - -theorem burnPublicAfterAmount1_evalAmountsPositiveFalse {v : PoolImmutables} {evm I} : - evalExpr? (config v) (burnPublicAfterAmount1Frame v I) evm - (orE (gtE (.var "amount0") (.intLit 0)) (gtE (.var "amount1") (.intLit 0))) = - .ok (.bool false) := by - simp only [orE, gtE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPublicAfterAmount1_amount0 (v := v) I] - rw [burnPublicAfterAmount1_amount1 (v := v) I] - simp [EvalResult.ofOption, evalBinaryOp?] - -theorem burnPublicAfterAmount1_evalReturnValues {v : PoolImmutables} {evm I} : - evalExprs? (config v) (burnPublicAfterAmount1Frame v I) evm - [.var "amount0", .var "amount1"] = .ok [.int 0, .int 0] := by - simp only [evalExprs?, evalExpr?, EvalResult.bind, bind, pure] - rw [burnPublicAfterAmount1_amount0 (v := v) I] - rw [burnPublicAfterAmount1_amount1 (v := v) I] - rfl - -theorem burnPublicAfterAmount1_noSlot0 {v : PoolImmutables} (I : ExecutionEnv) : - "slot0" ∉ (burnPublicAfterAmount1Frame v I).locals := by - rw [burnPublicAfterAmount1Frame, burnPublicAfterAmount0Frame, - burnPublicAfterPositionFrame, burnPublicAfterModifiedFrame, burnLiquidityDeltaFrame, burnStore] - simp - -theorem uniswapV3PoolBurnSourceAfterModifyPositionZeroTail - {v : PoolImmutables} {evm I} : - ExecBlock (config v) (burnPublicAfterModifiedFrame v I) evm - [ .letStorage "position" (positionsRef (tuple0 (.var "modified"))), - .letDecl "amount0" (some uint256) - (uint256Wrap (subE (.intLit 0) (tuple1 (.var "modified")))), - .letDecl "amount1" (some uint256) - (uint256Wrap (subE (.intLit 0) (tuple2 (.var "modified")))), - Stmt.ite (orE (gtE (.var "amount0") (.intLit 0)) - (gtE (.var "amount1") (.intLit 0))) - [ .assign .storage { base := "position", steps := [.field "tokensOwed0"] } - (addE (.field (.var "position") "tokensOwed0") (uint128Wrap (.var "amount0"))), - .assign .storage { base := "position", steps := [.field "tokensOwed1"] } - (addE (.field (.var "position") "tokensOwed1") (uint128Wrap (.var "amount1"))) ] - [], - .assign .storage (slot0F "unlocked") (.boolLit true), - .return [.var "amount0", .var "amount1"] ] - (.returned (burnPublicAfterAmount1Frame v I) (slot0AfterUnlockState evm) - (some [.int 0, .int 0])) := by - refine ExecBlock.consNormal - (ExecStmt.letStorage (burnPublicAfterModified_resolvePositionRef (v := v))) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl (burnPublicAfterPosition_evalAmount0 (v := v) (evm := evm) (I := I))) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl (burnPublicAfterAmount0_evalAmount1 (v := v) (evm := evm) (I := I))) ?_ - refine ExecBlock.consNormal - (ExecStmt.iteFalse - (burnPublicAfterAmount1_evalAmountsPositiveFalse (v := v) (evm := evm) (I := I)) - ExecBlock.nil) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) - (assignStorageRef_burn_unlocked_true (v := v) evm - (burnPublicAfterAmount1Frame v I).locals - (burnPublicAfterAmount1_noSlot0 (v := v) I))) ?_ - exact ExecBlock.consReturn - (ExecStmt.return (burnPublicAfterAmount1_evalReturnValues (v := v) - (evm := slot0AfterUnlockState evm) (I := I))) - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnSourceZeroDeltaReturnsZeroTokens - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : burnUnlockedByte σ I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hinside0 : - burnTickGetInside0Value - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I = - .int (Int.ofNat feeGrowthInside0X128.toNat)) - (hinside1 : - burnTickGetInside1Value - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I = - .int (Int.ofNat feeGrowthInside1X128.toNat)) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) - (htokens0 : - burnPositionUpdateSourceTokensOwed0Int - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I - (Int.ofNat feeGrowthInside0X128.toNat) = 0) - (htokens1 : - burnPositionUpdateSourceTokensOwed1Int - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I - (Int.ofNat feeGrowthInside1X128.toNat) = 0) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (burnStore I) burnTransition.body - (.returned (burnPublicAfterAmount1Frame v I) - (slot0AfterUnlockState - (Solm.EVM.storageStore - (Solm.EVM.storageStore - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) σ₀ g A I) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨1⟩) - feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128)) - (some [.int 0, .int 0])) := by - refine ExecFuncBody.execBlockRet ?_ - let lockedσ := sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I) - let evmFees := - Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl lockedσ σ₀ g A I) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) feeGrowthInside1X128 - have hprefix := uniswapV3PoolBurnSourceThroughLiquidityDelta (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hunlocked hcanon - have hlockState : - Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I) = - initState cA gh bl lockedσ σ₀ g A I := by - unfold lockedσ - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have hstmt : - ExecStmt (config v) (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - (.internalCall "modifyPosition" - [.env .caller, .var "tickLower", .var "tickUpper", .var "liquidityDelta"] - "modified") - (.ok (burnPublicAfterModifiedFrame v I) evmFees) := by - rw [hlockState] - have hbody := uniswapV3PoolModifyPositionSourceZeroDeltaReturnsZeroTokens - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := lockedσ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - (by simpa [lockedσ] using hinside0) (by simpa [lockedσ] using hinside1) - hguard htickLt hge hle hzero (by simpa [lockedσ] using hliq) - (by simpa [lockedσ] using htokens0) (by simpa [lockedσ] using htokens1) - refine internalCallFunctionReturn (callee := modifyPositionFunction v) - (retVar := "modified") - (argVals := burnModifyPositionArgValues I) (locals := burnModifyPositionStore I) - (calleeSolm := burnModifyPositionAfterAmount1Frame v lockedσ I) - (value := some [burnPositionKeyValue I, .int 0, .int 0]) ?_ ?_ ?_ ?_ - · have hLower := burnLiquidityDeltaFrame_tickLower (v := v) I - have hUpper := burnLiquidityDeltaFrame_tickUpper (v := v) I - have hDelta := burnLiquidityDeltaFrame_liquidityDelta (v := v) I - simp only [burnModifyPositionArgValues, evalExprs?, evalExpr?, envValue, initState, - EvalResult.bind, bind, pure] - rw [hLower, hUpper, hDelta] - rfl - · simpa [burnLiquidityDeltaFrame] using uniswapV3PoolLookupModifyPosition v - · rfl - · simpa [evmFees] using hbody - have htail : - ExecBlock (config v) (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - ([ .internalCall "modifyPosition" - [.env .caller, .var "tickLower", .var "tickUpper", .var "liquidityDelta"] - "modified" ] ++ - [ .letStorage "position" (positionsRef (tuple0 (.var "modified"))), - .letDecl "amount0" (some uint256) - (uint256Wrap (subE (.intLit 0) (tuple1 (.var "modified")))), - .letDecl "amount1" (some uint256) - (uint256Wrap (subE (.intLit 0) (tuple2 (.var "modified")))), - Stmt.ite (orE (gtE (.var "amount0") (.intLit 0)) - (gtE (.var "amount1") (.intLit 0))) - [ .assign .storage { base := "position", steps := [.field "tokensOwed0"] } - (addE (.field (.var "position") "tokensOwed0") - (uint128Wrap (.var "amount0"))), - .assign .storage { base := "position", steps := [.field "tokensOwed1"] } - (addE (.field (.var "position") "tokensOwed1") - (uint128Wrap (.var "amount1"))) ] - [], - .assign .storage (slot0F "unlocked") (.boolLit true), - .return [.var "amount0", .var "amount1"] ]) - (.returned (burnPublicAfterAmount1Frame v I) (slot0AfterUnlockState evmFees) - (some [.int 0, .int 0])) := by - refine ExecBlock.consNormal hstmt ?_ - exact uniswapV3PoolBurnSourceAfterModifyPositionZeroTail - (v := v) (evm := evmFees) (I := I) - simpa [burnTransition, nonpayable, lockPrefix, lockSuffix, evmFees, lockedσ] - using execBlock_append hprefix htail - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnSourceZeroDeltaReturnsTokensOwed - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (feeGrowthInside0X128 feeGrowthInside1X128 : UInt256) - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : burnUnlockedByte σ I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hinside0 : - burnTickGetInside0Value - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I = - .int (Int.ofNat feeGrowthInside0X128.toNat)) - (hinside1 : - burnTickGetInside1Value - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I = - .int (Int.ofNat feeGrowthInside1X128.toNat)) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩) - (hcond : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I - (Int.ofNat feeGrowthInside0X128.toNat) (Int.ofNat feeGrowthInside1X128.toNat)) - (Solm.EVM.storageStore - (Solm.EVM.storageStore - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) σ₀ g A I) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨1⟩) - feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128) - (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) = .ok (.bool true)) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (burnStore I) burnTransition.body - (.returned (burnPublicAfterAmount1Frame v I) - (slot0AfterUnlockState - (burnPositionUpdateSourceAfterTokensOwedState - (Solm.EVM.storageStore - (Solm.EVM.storageStore - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) σ₀ g A I) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨1⟩) - feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1X128) - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I - feeGrowthInside0X128 feeGrowthInside1X128)) - (some [.int 0, .int 0])) := by - refine ExecFuncBody.execBlockRet ?_ - let lockedσ := sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I) - let evmFees := - Solm.EVM.storageStore - (Solm.EVM.storageStore (initState cA gh bl lockedσ σ₀ g A I) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0X128) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) feeGrowthInside1X128 - let evmTokens := burnPositionUpdateSourceAfterTokensOwedState evmFees lockedσ I - feeGrowthInside0X128 feeGrowthInside1X128 - have hprefix := uniswapV3PoolBurnSourceThroughLiquidityDelta (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hunlocked hcanon - have hlockState : - Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I) = - initState cA gh bl lockedσ σ₀ g A I := by - unfold lockedσ - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have hstmt : - ExecStmt (config v) (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - (.internalCall "modifyPosition" - [.env .caller, .var "tickLower", .var "tickUpper", .var "liquidityDelta"] - "modified") - (.ok (burnPublicAfterModifiedFrame v I) evmTokens) := by - rw [hlockState] - have hbody := uniswapV3PoolModifyPositionSourceZeroDeltaReturnsTokensOwed - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := lockedσ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) feeGrowthInside0X128 feeGrowthInside1X128 - (by simpa [lockedσ] using hinside0) (by simpa [lockedσ] using hinside1) - hguard htickLt hge hle hzero (by simpa [lockedσ] using hliq) - (by simpa [lockedσ, evmFees] using hcond) - refine internalCallFunctionReturn (callee := modifyPositionFunction v) - (retVar := "modified") - (argVals := burnModifyPositionArgValues I) (locals := burnModifyPositionStore I) - (calleeSolm := burnModifyPositionAfterAmount1Frame v lockedσ I) - (value := some [burnPositionKeyValue I, .int 0, .int 0]) ?_ ?_ ?_ ?_ - · have hLower := burnLiquidityDeltaFrame_tickLower (v := v) I - have hUpper := burnLiquidityDeltaFrame_tickUpper (v := v) I - have hDelta := burnLiquidityDeltaFrame_liquidityDelta (v := v) I - simp only [burnModifyPositionArgValues, evalExprs?, evalExpr?, envValue, initState, - EvalResult.bind, bind, pure] - rw [hLower, hUpper, hDelta] - rfl - · simpa [burnLiquidityDeltaFrame] using uniswapV3PoolLookupModifyPosition v - · rfl - · simpa [evmTokens] using hbody - have htail : - ExecBlock (config v) (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - ([ .internalCall "modifyPosition" - [.env .caller, .var "tickLower", .var "tickUpper", .var "liquidityDelta"] - "modified" ] ++ - [ .letStorage "position" (positionsRef (tuple0 (.var "modified"))), - .letDecl "amount0" (some uint256) - (uint256Wrap (subE (.intLit 0) (tuple1 (.var "modified")))), - .letDecl "amount1" (some uint256) - (uint256Wrap (subE (.intLit 0) (tuple2 (.var "modified")))), - Stmt.ite (orE (gtE (.var "amount0") (.intLit 0)) - (gtE (.var "amount1") (.intLit 0))) - [ .assign .storage { base := "position", steps := [.field "tokensOwed0"] } - (addE (.field (.var "position") "tokensOwed0") - (uint128Wrap (.var "amount0"))), - .assign .storage { base := "position", steps := [.field "tokensOwed1"] } - (addE (.field (.var "position") "tokensOwed1") - (uint128Wrap (.var "amount1"))) ] - [], - .assign .storage (slot0F "unlocked") (.boolLit true), - .return [.var "amount0", .var "amount1"] ]) - (.returned (burnPublicAfterAmount1Frame v I) (slot0AfterUnlockState evmTokens) - (some [.int 0, .int 0])) := by - refine ExecBlock.consNormal hstmt ?_ - exact uniswapV3PoolBurnSourceAfterModifyPositionZeroTail - (v := v) (evm := evmTokens) (I := I) - simpa [burnTransition, nonpayable, lockPrefix, lockSuffix, evmFees, evmTokens, lockedσ] - using execBlock_append hprefix htail - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnTickGetFeeGrowthInsideSource.lean b/Benchmarks/UniswapV3Pool/BurnTickGetFeeGrowthInsideSource.lean deleted file mode 100644 index afe71879..00000000 --- a/Benchmarks/UniswapV3Pool/BurnTickGetFeeGrowthInsideSource.lean +++ /dev/null @@ -1,1097 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdateSourceSuccess - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem burnTickGet_evalCurrentGeLowerOf {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} {frame : Frame} - (hcurrent : frame.locals.get? "tickCurrent" = some (burnSlot0TickValue σ I)) - (hlower : frame.locals.get? "tickLower" = some (burnTickLowerValue I)) : - evalExpr? (config v) frame (initState cA gh bl σ σ₀ g A I) - (geE (.var "tickCurrent") (.var "tickLower")) = - .ok (.bool (tickSpacingSint24Value (slot0TickRawWord σ I) >= - tickSpacingSint24Value (burnTickLowerWord I))) := by - simp only [geE, evalExpr?, EvalResult.bind, bind] - rw [hcurrent, hlower] - simp [EvalResult.ofOption, burnSlot0TickValue, burnTickLowerValue, wordToElem, int24Int, - tickSpacingSint24Value, evalBinaryOp?] - -theorem burnTickGet_evalCurrentLtUpperOf {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} {frame : Frame} - (hcurrent : frame.locals.get? "tickCurrent" = some (burnSlot0TickValue σ I)) - (hupper : frame.locals.get? "tickUpper" = some (burnTickUpperValue I)) : - evalExpr? (config v) frame (initState cA gh bl σ σ₀ g A I) - (ltE (.var "tickCurrent") (.var "tickUpper")) = - .ok (.bool (tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickUpperWord I))) := by - simp only [ltE, evalExpr?, EvalResult.bind, bind] - rw [hcurrent, hupper] - simp [EvalResult.ofOption, burnSlot0TickValue, burnTickUpperValue, wordToElem, int24Int, - tickSpacingSint24Value, evalBinaryOp?] - -theorem burnTickGetAfterUpper_feeGrowthGlobal0 (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterUpperFrame v σ I).locals.get? "feeGrowthGlobal0X128" = - some (burnFeeGrowthGlobal0Value σ I) := by - rw [burnTickGetAfterUpperFrame, burnTickGetAfterLowerFrame] - rw [store_get_ne (burnTickGetAfterLowerFrame v σ I).locals - (k := "upper") (a := "feeGrowthGlobal0X128") - (.storageRef (burnTickGetUpperEvaledBaseRef I) tickInfoStructTy) - (by native_decide)] - rw [store_get_ne (burnTickGetFeeGrowthInsideStore σ I) - (k := "lower") (a := "feeGrowthGlobal0X128") - (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) - (by native_decide)] - rw [burnTickGetFeeGrowthInsideStore] - rw [store_get_ne3 ((∅ : Store) - |>.insert "feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I) - |>.insert "feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I)) - (k1 := "tickCurrent") (k2 := "tickUpper") (k3 := "tickLower") - (a := "feeGrowthGlobal0X128") - (burnSlot0TickValue σ I) (burnTickUpperValue I) (burnTickLowerValue I) - (by native_decide) (by native_decide) (by native_decide)] - exact store_get_self ((∅ : Store) - |>.insert "feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I)) - "feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I) - -theorem burnTickGetAfterUpper_feeGrowthGlobal1 (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterUpperFrame v σ I).locals.get? "feeGrowthGlobal1X128" = - some (burnFeeGrowthGlobal1Value σ I) := by - rw [burnTickGetAfterUpperFrame, burnTickGetAfterLowerFrame] - rw [store_get_ne (burnTickGetAfterLowerFrame v σ I).locals - (k := "upper") (a := "feeGrowthGlobal1X128") - (.storageRef (burnTickGetUpperEvaledBaseRef I) tickInfoStructTy) - (by native_decide)] - rw [store_get_ne (burnTickGetFeeGrowthInsideStore σ I) - (k := "lower") (a := "feeGrowthGlobal1X128") - (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) - (by native_decide)] - rw [burnTickGetFeeGrowthInsideStore] - rw [store_get_ne4 ((∅ : Store).insert "feeGrowthGlobal1X128" - (burnFeeGrowthGlobal1Value σ I)) - (k1 := "feeGrowthGlobal0X128") (k2 := "tickCurrent") - (k3 := "tickUpper") (k4 := "tickLower") (a := "feeGrowthGlobal1X128") - (burnFeeGrowthGlobal0Value σ I) (burnSlot0TickValue σ I) - (burnTickUpperValue I) (burnTickLowerValue I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide)] - exact store_get_self (∅ : Store) "feeGrowthGlobal1X128" - (burnFeeGrowthGlobal1Value σ I) - -theorem burnTickGetAfterBelow0_lower (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterBelow0Frame v σ I).locals.get? "lower" = - some (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) := by - rw [burnTickGetAfterBelow0Frame] - rw [store_get_ne (burnTickGetAfterUpperFrame v σ I).locals - (k := "feeGrowthBelow0X128") (a := "lower") (burnTickGetBelow0Value σ I) - (by native_decide)] - exact burnTickGetAfterUpper_lower v σ I - -theorem burnTickGetAfterBelow0_tickCurrent (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterBelow0Frame v σ I).locals.get? "tickCurrent" = - some (burnSlot0TickValue σ I) := by - rw [burnTickGetAfterBelow0Frame] - rw [store_get_ne (burnTickGetAfterUpperFrame v σ I).locals - (k := "feeGrowthBelow0X128") (a := "tickCurrent") (burnTickGetBelow0Value σ I) - (by native_decide)] - exact burnTickGetAfterUpper_tickCurrent v σ I - -theorem burnTickGetAfterBelow0_tickLower (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterBelow0Frame v σ I).locals.get? "tickLower" = - some (burnTickLowerValue I) := by - rw [burnTickGetAfterBelow0Frame] - rw [store_get_ne (burnTickGetAfterUpperFrame v σ I).locals - (k := "feeGrowthBelow0X128") (a := "tickLower") (burnTickGetBelow0Value σ I) - (by native_decide)] - exact burnTickGetAfterUpper_tickLower v σ I - -theorem burnTickGetAfterBelow0_feeGrowthGlobal1 (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterBelow0Frame v σ I).locals.get? "feeGrowthGlobal1X128" = - some (burnFeeGrowthGlobal1Value σ I) := by - rw [burnTickGetAfterBelow0Frame] - rw [store_get_ne (burnTickGetAfterUpperFrame v σ I).locals - (k := "feeGrowthBelow0X128") (a := "feeGrowthGlobal1X128") - (burnTickGetBelow0Value σ I) (by native_decide)] - exact burnTickGetAfterUpper_feeGrowthGlobal1 v σ I - -theorem burnTickGetAfterBelow1_upper (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterBelow1Frame v σ I).locals.get? "upper" = - some (.storageRef (burnTickGetUpperEvaledBaseRef I) tickInfoStructTy) := by - rw [burnTickGetAfterBelow1Frame, burnTickGetAfterBelow0Frame] - rw [store_get_ne (burnTickGetAfterBelow0Frame v σ I).locals - (k := "feeGrowthBelow1X128") (a := "upper") (burnTickGetBelow1Value σ I) - (by native_decide)] - rw [store_get_ne (burnTickGetAfterUpperFrame v σ I).locals - (k := "feeGrowthBelow0X128") (a := "upper") (burnTickGetBelow0Value σ I) - (by native_decide)] - exact burnTickGetAfterUpper_upper v σ I - -theorem burnTickGetAfterBelow1_tickCurrent (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterBelow1Frame v σ I).locals.get? "tickCurrent" = - some (burnSlot0TickValue σ I) := by - rw [burnTickGetAfterBelow1Frame] - rw [store_get_ne (burnTickGetAfterBelow0Frame v σ I).locals - (k := "feeGrowthBelow1X128") (a := "tickCurrent") (burnTickGetBelow1Value σ I) - (by native_decide)] - exact burnTickGetAfterBelow0_tickCurrent v σ I - -theorem burnTickGetAfterBelow1_tickUpper (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterBelow1Frame v σ I).locals.get? "tickUpper" = - some (burnTickUpperValue I) := by - rw [burnTickGetAfterBelow1Frame, burnTickGetAfterBelow0Frame] - rw [store_get_ne (burnTickGetAfterBelow0Frame v σ I).locals - (k := "feeGrowthBelow1X128") (a := "tickUpper") (burnTickGetBelow1Value σ I) - (by native_decide)] - rw [store_get_ne (burnTickGetAfterUpperFrame v σ I).locals - (k := "feeGrowthBelow0X128") (a := "tickUpper") (burnTickGetBelow0Value σ I) - (by native_decide)] - exact burnTickGetAfterUpper_tickUpper v σ I - -theorem burnTickGetAfterBelow1_feeGrowthGlobal0 (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterBelow1Frame v σ I).locals.get? "feeGrowthGlobal0X128" = - some (burnFeeGrowthGlobal0Value σ I) := by - rw [burnTickGetAfterBelow1Frame, burnTickGetAfterBelow0Frame] - rw [store_get_ne (burnTickGetAfterBelow0Frame v σ I).locals - (k := "feeGrowthBelow1X128") (a := "feeGrowthGlobal0X128") - (burnTickGetBelow1Value σ I) (by native_decide)] - rw [store_get_ne (burnTickGetAfterUpperFrame v σ I).locals - (k := "feeGrowthBelow0X128") (a := "feeGrowthGlobal0X128") - (burnTickGetBelow0Value σ I) (by native_decide)] - exact burnTickGetAfterUpper_feeGrowthGlobal0 v σ I - -theorem burnTickGetAfterAbove0_upper (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterAbove0Frame v σ I).locals.get? "upper" = - some (.storageRef (burnTickGetUpperEvaledBaseRef I) tickInfoStructTy) := by - rw [burnTickGetAfterAbove0Frame] - rw [store_get_ne (burnTickGetAfterBelow1Frame v σ I).locals - (k := "feeGrowthAbove0X128") (a := "upper") (burnTickGetAbove0Value σ I) - (by native_decide)] - exact burnTickGetAfterBelow1_upper v σ I - -theorem burnTickGetAfterAbove0_tickCurrent (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterAbove0Frame v σ I).locals.get? "tickCurrent" = - some (burnSlot0TickValue σ I) := by - rw [burnTickGetAfterAbove0Frame] - rw [store_get_ne (burnTickGetAfterBelow1Frame v σ I).locals - (k := "feeGrowthAbove0X128") (a := "tickCurrent") (burnTickGetAbove0Value σ I) - (by native_decide)] - exact burnTickGetAfterBelow1_tickCurrent v σ I - -theorem burnTickGetAfterAbove0_tickUpper (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterAbove0Frame v σ I).locals.get? "tickUpper" = - some (burnTickUpperValue I) := by - rw [burnTickGetAfterAbove0Frame] - rw [store_get_ne (burnTickGetAfterBelow1Frame v σ I).locals - (k := "feeGrowthAbove0X128") (a := "tickUpper") (burnTickGetAbove0Value σ I) - (by native_decide)] - exact burnTickGetAfterBelow1_tickUpper v σ I - -theorem burnTickGetAfterAbove0_feeGrowthGlobal1 (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterAbove0Frame v σ I).locals.get? "feeGrowthGlobal1X128" = - some (burnFeeGrowthGlobal1Value σ I) := by - rw [burnTickGetAfterAbove0Frame, burnTickGetAfterBelow1Frame, burnTickGetAfterBelow0Frame] - rw [store_get_ne (burnTickGetAfterBelow1Frame v σ I).locals - (k := "feeGrowthAbove0X128") (a := "feeGrowthGlobal1X128") - (burnTickGetAbove0Value σ I) (by native_decide)] - rw [store_get_ne (burnTickGetAfterBelow0Frame v σ I).locals - (k := "feeGrowthBelow1X128") (a := "feeGrowthGlobal1X128") - (burnTickGetBelow1Value σ I) (by native_decide)] - rw [store_get_ne (burnTickGetAfterUpperFrame v σ I).locals - (k := "feeGrowthBelow0X128") (a := "feeGrowthGlobal1X128") - (burnTickGetBelow0Value σ I) (by native_decide)] - exact burnTickGetAfterUpper_feeGrowthGlobal1 v σ I - -theorem burnTickGet_evalFeeGrowthBelow0 {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnTickGetAfterUpperFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.ite (geE (.var "tickCurrent") (.var "tickLower")) - (.field (.var "lower") "feeGrowthOutside0X128") - (wordSub (.var "feeGrowthGlobal0X128") - (.field (.var "lower") "feeGrowthOutside0X128"))) = - .ok (burnTickGetBelow0Value σ I) := by - rw [evalExpr?, burnTickGet_evalCurrentGeLower] - by_cases hge : tickSpacingSint24Value (slot0TickRawWord σ I) >= - tickSpacingSint24Value (burnTickLowerWord I) - · simp [hge] - simpa [burnTickGetBelow0Value, burnTickGetBelow0Int, hge] using - burnTickGet_evalLowerFeeGrowthOutside0 (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (frame := burnTickGetAfterUpperFrame v σ I) (burnTickGetAfterUpper_lower v σ I) - · simp [hge] - apply Eq.trans - · refine evalExpr_wordSub_int (v := v) (frame := burnTickGetAfterUpperFrame v σ I) - (evm := initState cA gh bl σ σ₀ g A I) - (x := burnTickGetFeeGrowthGlobal0Int σ I) - (y := burnTickGetLowerFeeGrowthOutside0Int σ I) ?_ ?_ - · simp only [evalExpr?] - rw [burnTickGetAfterUpper_feeGrowthGlobal0 v σ I] - simp [EvalResult.ofOption, burnFeeGrowthGlobal0Value, burnTickGetFeeGrowthGlobal0Int] - · exact burnTickGet_evalLowerFeeGrowthOutside0 (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (frame := burnTickGetAfterUpperFrame v σ I) (burnTickGetAfterUpper_lower v σ I) - · simp [burnTickGetBelow0Value, burnTickGetBelow0Int, hge, - burnTickGetFeeGrowthGlobal0Int, burnTickGetLowerFeeGrowthOutside0Int] - -theorem burnTickGet_evalFeeGrowthBelow1 {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnTickGetAfterBelow0Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.ite (geE (.var "tickCurrent") (.var "tickLower")) - (.field (.var "lower") "feeGrowthOutside1X128") - (wordSub (.var "feeGrowthGlobal1X128") - (.field (.var "lower") "feeGrowthOutside1X128"))) = - .ok (burnTickGetBelow1Value σ I) := by - rw [evalExpr?] - rw [burnTickGet_evalCurrentGeLowerOf - (frame := burnTickGetAfterBelow0Frame v σ I) - (burnTickGetAfterBelow0_tickCurrent v σ I) - (burnTickGetAfterBelow0_tickLower v σ I)] - by_cases hge : tickSpacingSint24Value (slot0TickRawWord σ I) >= - tickSpacingSint24Value (burnTickLowerWord I) - · simp [hge] - simpa [burnTickGetBelow1Value, burnTickGetBelow1Int, hge] using - burnTickGet_evalLowerFeeGrowthOutside1 (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (frame := burnTickGetAfterBelow0Frame v σ I) (burnTickGetAfterBelow0_lower v σ I) - · simp [hge] - apply Eq.trans - · refine evalExpr_wordSub_int (v := v) (frame := burnTickGetAfterBelow0Frame v σ I) - (evm := initState cA gh bl σ σ₀ g A I) - (x := burnTickGetFeeGrowthGlobal1Int σ I) - (y := burnTickGetLowerFeeGrowthOutside1Int σ I) ?_ ?_ - · simp only [evalExpr?] - rw [burnTickGetAfterBelow0_feeGrowthGlobal1 v σ I] - simp [EvalResult.ofOption, burnFeeGrowthGlobal1Value, burnTickGetFeeGrowthGlobal1Int] - · exact burnTickGet_evalLowerFeeGrowthOutside1 (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (frame := burnTickGetAfterBelow0Frame v σ I) (burnTickGetAfterBelow0_lower v σ I) - · simp [burnTickGetBelow1Value, burnTickGetBelow1Int, hge, - burnTickGetFeeGrowthGlobal1Int, burnTickGetLowerFeeGrowthOutside1Int] - -theorem burnTickGet_evalFeeGrowthAbove0 {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnTickGetAfterBelow1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.ite (ltE (.var "tickCurrent") (.var "tickUpper")) - (.field (.var "upper") "feeGrowthOutside0X128") - (wordSub (.var "feeGrowthGlobal0X128") - (.field (.var "upper") "feeGrowthOutside0X128"))) = - .ok (burnTickGetAbove0Value σ I) := by - rw [evalExpr?] - rw [burnTickGet_evalCurrentLtUpperOf - (frame := burnTickGetAfterBelow1Frame v σ I) - (burnTickGetAfterBelow1_tickCurrent v σ I) - (burnTickGetAfterBelow1_tickUpper v σ I)] - by_cases hlt : tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickUpperWord I) - · simp [hlt] - simpa [burnTickGetAbove0Value, burnTickGetAbove0Int, hlt] using - burnTickGet_evalUpperFeeGrowthOutside0 (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (frame := burnTickGetAfterBelow1Frame v σ I) (burnTickGetAfterBelow1_upper v σ I) - · simp [hlt] - apply Eq.trans - · refine evalExpr_wordSub_int (v := v) (frame := burnTickGetAfterBelow1Frame v σ I) - (evm := initState cA gh bl σ σ₀ g A I) - (x := burnTickGetFeeGrowthGlobal0Int σ I) - (y := burnTickGetUpperFeeGrowthOutside0Int σ I) ?_ ?_ - · simp only [evalExpr?] - rw [burnTickGetAfterBelow1_feeGrowthGlobal0 v σ I] - simp [EvalResult.ofOption, burnFeeGrowthGlobal0Value, burnTickGetFeeGrowthGlobal0Int] - · exact burnTickGet_evalUpperFeeGrowthOutside0 (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (frame := burnTickGetAfterBelow1Frame v σ I) (burnTickGetAfterBelow1_upper v σ I) - · simp [burnTickGetAbove0Value, burnTickGetAbove0Int, hlt, - burnTickGetFeeGrowthGlobal0Int, burnTickGetUpperFeeGrowthOutside0Int] - -theorem burnTickGet_evalFeeGrowthAbove1 {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnTickGetAfterAbove0Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.ite (ltE (.var "tickCurrent") (.var "tickUpper")) - (.field (.var "upper") "feeGrowthOutside1X128") - (wordSub (.var "feeGrowthGlobal1X128") - (.field (.var "upper") "feeGrowthOutside1X128"))) = - .ok (burnTickGetAbove1Value σ I) := by - rw [evalExpr?] - rw [burnTickGet_evalCurrentLtUpperOf - (frame := burnTickGetAfterAbove0Frame v σ I) - (burnTickGetAfterAbove0_tickCurrent v σ I) - (burnTickGetAfterAbove0_tickUpper v σ I)] - by_cases hlt : tickSpacingSint24Value (slot0TickRawWord σ I) < - tickSpacingSint24Value (burnTickUpperWord I) - · simp [hlt] - simpa [burnTickGetAbove1Value, burnTickGetAbove1Int, hlt] using - burnTickGet_evalUpperFeeGrowthOutside1 (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (frame := burnTickGetAfterAbove0Frame v σ I) (burnTickGetAfterAbove0_upper v σ I) - · simp [hlt] - apply Eq.trans - · refine evalExpr_wordSub_int (v := v) (frame := burnTickGetAfterAbove0Frame v σ I) - (evm := initState cA gh bl σ σ₀ g A I) - (x := burnTickGetFeeGrowthGlobal1Int σ I) - (y := burnTickGetUpperFeeGrowthOutside1Int σ I) ?_ ?_ - · simp only [evalExpr?] - rw [burnTickGetAfterAbove0_feeGrowthGlobal1 v σ I] - simp [EvalResult.ofOption, burnFeeGrowthGlobal1Value, burnTickGetFeeGrowthGlobal1Int] - · exact burnTickGet_evalUpperFeeGrowthOutside1 (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (frame := burnTickGetAfterAbove0Frame v σ I) (burnTickGetAfterAbove0_upper v σ I) - · simp [burnTickGetAbove1Value, burnTickGetAbove1Int, hlt, - burnTickGetFeeGrowthGlobal1Int, burnTickGetUpperFeeGrowthOutside1Int] - -theorem burnTickGetAfterAbove0_feeGrowthGlobal0 (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterAbove0Frame v σ I).locals.get? "feeGrowthGlobal0X128" = - some (burnFeeGrowthGlobal0Value σ I) := by - rw [burnTickGetAfterAbove0Frame] - rw [store_get_ne (burnTickGetAfterBelow1Frame v σ I).locals - (k := "feeGrowthAbove0X128") (a := "feeGrowthGlobal0X128") - (burnTickGetAbove0Value σ I) (by native_decide)] - exact burnTickGetAfterBelow1_feeGrowthGlobal0 v σ I - -theorem burnTickGetAfterAbove1_feeGrowthGlobal0 (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterAbove1Frame v σ I).locals.get? "feeGrowthGlobal0X128" = - some (burnFeeGrowthGlobal0Value σ I) := by - rw [burnTickGetAfterAbove1Frame] - rw [store_get_ne (burnTickGetAfterAbove0Frame v σ I).locals - (k := "feeGrowthAbove1X128") (a := "feeGrowthGlobal0X128") - (burnTickGetAbove1Value σ I) (by native_decide)] - exact burnTickGetAfterAbove0_feeGrowthGlobal0 v σ I - -theorem burnTickGetAfterAbove1_feeGrowthGlobal1 (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterAbove1Frame v σ I).locals.get? "feeGrowthGlobal1X128" = - some (burnFeeGrowthGlobal1Value σ I) := by - rw [burnTickGetAfterAbove1Frame] - rw [store_get_ne (burnTickGetAfterAbove0Frame v σ I).locals - (k := "feeGrowthAbove1X128") (a := "feeGrowthGlobal1X128") - (burnTickGetAbove1Value σ I) (by native_decide)] - exact burnTickGetAfterAbove0_feeGrowthGlobal1 v σ I - -theorem burnTickGetAfterAbove1_below0 (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterAbove1Frame v σ I).locals.get? "feeGrowthBelow0X128" = - some (burnTickGetBelow0Value σ I) := by - rw [burnTickGetAfterAbove1Frame, burnTickGetAfterAbove0Frame, - burnTickGetAfterBelow1Frame] - rw [store_get_ne (burnTickGetAfterAbove0Frame v σ I).locals - (k := "feeGrowthAbove1X128") (a := "feeGrowthBelow0X128") - (burnTickGetAbove1Value σ I) (by native_decide)] - rw [store_get_ne (burnTickGetAfterBelow1Frame v σ I).locals - (k := "feeGrowthAbove0X128") (a := "feeGrowthBelow0X128") - (burnTickGetAbove0Value σ I) (by native_decide)] - rw [store_get_ne (burnTickGetAfterBelow0Frame v σ I).locals - (k := "feeGrowthBelow1X128") (a := "feeGrowthBelow0X128") - (burnTickGetBelow1Value σ I) (by native_decide)] - rw [burnTickGetAfterBelow0Frame] - exact store_get_self (burnTickGetAfterUpperFrame v σ I).locals - "feeGrowthBelow0X128" (burnTickGetBelow0Value σ I) - -theorem burnTickGetAfterAbove1_below1 (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterAbove1Frame v σ I).locals.get? "feeGrowthBelow1X128" = - some (burnTickGetBelow1Value σ I) := by - rw [burnTickGetAfterAbove1Frame, burnTickGetAfterAbove0Frame] - rw [store_get_ne (burnTickGetAfterAbove0Frame v σ I).locals - (k := "feeGrowthAbove1X128") (a := "feeGrowthBelow1X128") - (burnTickGetAbove1Value σ I) (by native_decide)] - rw [store_get_ne (burnTickGetAfterBelow1Frame v σ I).locals - (k := "feeGrowthAbove0X128") (a := "feeGrowthBelow1X128") - (burnTickGetAbove0Value σ I) (by native_decide)] - rw [burnTickGetAfterBelow1Frame] - exact store_get_self (burnTickGetAfterBelow0Frame v σ I).locals - "feeGrowthBelow1X128" (burnTickGetBelow1Value σ I) - -theorem burnTickGetAfterAbove1_above0 (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterAbove1Frame v σ I).locals.get? "feeGrowthAbove0X128" = - some (burnTickGetAbove0Value σ I) := by - rw [burnTickGetAfterAbove1Frame] - rw [store_get_ne (burnTickGetAfterAbove0Frame v σ I).locals - (k := "feeGrowthAbove1X128") (a := "feeGrowthAbove0X128") - (burnTickGetAbove1Value σ I) (by native_decide)] - rw [burnTickGetAfterAbove0Frame] - exact store_get_self (burnTickGetAfterBelow1Frame v σ I).locals - "feeGrowthAbove0X128" (burnTickGetAbove0Value σ I) - -theorem burnTickGetAfterAbove1_above1 (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickGetAfterAbove1Frame v σ I).locals.get? "feeGrowthAbove1X128" = - some (burnTickGetAbove1Value σ I) := by - rw [burnTickGetAfterAbove1Frame] - exact store_get_self (burnTickGetAfterAbove0Frame v σ I).locals - "feeGrowthAbove1X128" (burnTickGetAbove1Value σ I) - -theorem burnTickGet_evalReturnValues {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExprs? (config v) (burnTickGetAfterAbove1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ wordSub (wordSub (.var "feeGrowthGlobal0X128") (.var "feeGrowthBelow0X128")) - (.var "feeGrowthAbove0X128"), - wordSub (wordSub (.var "feeGrowthGlobal1X128") (.var "feeGrowthBelow1X128")) - (.var "feeGrowthAbove1X128") ] = - .ok [burnTickGetInside0Value σ I, burnTickGetInside1Value σ I] := by - have hglobal0 : - evalExpr? (config v) (burnTickGetAfterAbove1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) (.var "feeGrowthGlobal0X128") = - .ok (.int (burnTickGetFeeGrowthGlobal0Int σ I)) := by - simp only [evalExpr?] - rw [burnTickGetAfterAbove1_feeGrowthGlobal0 v σ I] - simp [EvalResult.ofOption, burnFeeGrowthGlobal0Value, burnTickGetFeeGrowthGlobal0Int] - have hglobal1 : - evalExpr? (config v) (burnTickGetAfterAbove1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) (.var "feeGrowthGlobal1X128") = - .ok (.int (burnTickGetFeeGrowthGlobal1Int σ I)) := by - simp only [evalExpr?] - rw [burnTickGetAfterAbove1_feeGrowthGlobal1 v σ I] - simp [EvalResult.ofOption, burnFeeGrowthGlobal1Value, burnTickGetFeeGrowthGlobal1Int] - have hbelow0 : - evalExpr? (config v) (burnTickGetAfterAbove1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) (.var "feeGrowthBelow0X128") = - .ok (.int (burnTickGetBelow0Int σ I)) := by - simp only [evalExpr?] - rw [burnTickGetAfterAbove1_below0 v σ I] - simp [EvalResult.ofOption, burnTickGetBelow0Value] - have hbelow1 : - evalExpr? (config v) (burnTickGetAfterAbove1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) (.var "feeGrowthBelow1X128") = - .ok (.int (burnTickGetBelow1Int σ I)) := by - simp only [evalExpr?] - rw [burnTickGetAfterAbove1_below1 v σ I] - simp [EvalResult.ofOption, burnTickGetBelow1Value] - have habove0 : - evalExpr? (config v) (burnTickGetAfterAbove1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) (.var "feeGrowthAbove0X128") = - .ok (.int (burnTickGetAbove0Int σ I)) := by - simp only [evalExpr?] - rw [burnTickGetAfterAbove1_above0 v σ I] - simp [EvalResult.ofOption, burnTickGetAbove0Value] - have habove1 : - evalExpr? (config v) (burnTickGetAfterAbove1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) (.var "feeGrowthAbove1X128") = - .ok (.int (burnTickGetAbove1Int σ I)) := by - simp only [evalExpr?] - rw [burnTickGetAfterAbove1_above1 v σ I] - simp [EvalResult.ofOption, burnTickGetAbove1Value] - have hinner0 : - evalExpr? (config v) (burnTickGetAfterAbove1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - (wordSub (.var "feeGrowthGlobal0X128") (.var "feeGrowthBelow0X128")) = - .ok (.int - (burnWordSubInt (burnTickGetFeeGrowthGlobal0Int σ I) - (burnTickGetBelow0Int σ I))) := by - exact evalExpr_wordSub_int (v := v) (frame := burnTickGetAfterAbove1Frame v σ I) - (evm := initState cA gh bl σ σ₀ g A I) hglobal0 hbelow0 - have hinner1 : - evalExpr? (config v) (burnTickGetAfterAbove1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - (wordSub (.var "feeGrowthGlobal1X128") (.var "feeGrowthBelow1X128")) = - .ok (.int - (burnWordSubInt (burnTickGetFeeGrowthGlobal1Int σ I) - (burnTickGetBelow1Int σ I))) := by - exact evalExpr_wordSub_int (v := v) (frame := burnTickGetAfterAbove1Frame v σ I) - (evm := initState cA gh bl σ σ₀ g A I) hglobal1 hbelow1 - have hret0 : - evalExpr? (config v) (burnTickGetAfterAbove1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - (wordSub (wordSub (.var "feeGrowthGlobal0X128") (.var "feeGrowthBelow0X128")) - (.var "feeGrowthAbove0X128")) = - .ok (burnTickGetInside0Value σ I) := by - simpa [burnTickGetInside0Value, burnTickGetInside0Int] using - evalExpr_wordSub_int (v := v) (frame := burnTickGetAfterAbove1Frame v σ I) - (evm := initState cA gh bl σ σ₀ g A I) hinner0 habove0 - have hret1 : - evalExpr? (config v) (burnTickGetAfterAbove1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - (wordSub (wordSub (.var "feeGrowthGlobal1X128") (.var "feeGrowthBelow1X128")) - (.var "feeGrowthAbove1X128")) = - .ok (burnTickGetInside1Value σ I) := by - simpa [burnTickGetInside1Value, burnTickGetInside1Int] using - evalExpr_wordSub_int (v := v) (frame := burnTickGetAfterAbove1Frame v σ I) - (evm := initState cA gh bl σ σ₀ g A I) hinner1 habove1 - simp only [evalExprs?, hret0, hret1, EvalResult.bind, bind, pure] - -theorem uniswapV3PoolTickGetFeeGrowthInsideSourceReturns {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - ExecFuncBody (config v) (burnTickGetFeeGrowthInsideFrame v σ I) - (initState cA gh bl σ σ₀ g A I) tickGetFeeGrowthInsideFunction.body - (.returned (burnTickGetAfterAbove1Frame v σ I) - (initState cA gh bl σ σ₀ g A I) - (some [burnTickGetInside0Value σ I, burnTickGetInside1Value σ I])) := by - change ExecFuncBody (config v) (burnTickGetFeeGrowthInsideFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "lower" (ticksRef (.var "tickLower")), - .letStorage "upper" (ticksRef (.var "tickUpper")), - .letDecl "feeGrowthBelow0X128" (some uint256) - (.ite (geE (.var "tickCurrent") (.var "tickLower")) - (.field (.var "lower") "feeGrowthOutside0X128") - (wordSub (.var "feeGrowthGlobal0X128") - (.field (.var "lower") "feeGrowthOutside0X128"))), - .letDecl "feeGrowthBelow1X128" (some uint256) - (.ite (geE (.var "tickCurrent") (.var "tickLower")) - (.field (.var "lower") "feeGrowthOutside1X128") - (wordSub (.var "feeGrowthGlobal1X128") - (.field (.var "lower") "feeGrowthOutside1X128"))), - .letDecl "feeGrowthAbove0X128" (some uint256) - (.ite (ltE (.var "tickCurrent") (.var "tickUpper")) - (.field (.var "upper") "feeGrowthOutside0X128") - (wordSub (.var "feeGrowthGlobal0X128") - (.field (.var "upper") "feeGrowthOutside0X128"))), - .letDecl "feeGrowthAbove1X128" (some uint256) - (.ite (ltE (.var "tickCurrent") (.var "tickUpper")) - (.field (.var "upper") "feeGrowthOutside1X128") - (wordSub (.var "feeGrowthGlobal1X128") - (.field (.var "upper") "feeGrowthOutside1X128"))), - .return - [ wordSub (wordSub (.var "feeGrowthGlobal0X128") (.var "feeGrowthBelow0X128")) - (.var "feeGrowthAbove0X128"), - wordSub (wordSub (.var "feeGrowthGlobal1X128") (.var "feeGrowthBelow1X128")) - (.var "feeGrowthAbove1X128") ] ] _ - refine ExecFuncBody.execBlockRet ?_ - refine ExecBlock.consNormal (ExecStmt.letStorage (burnTickGet_resolveLowerRef - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g))) ?_ - refine ExecBlock.consNormal (ExecStmt.letStorage (burnTickGetAfterLower_resolveUpperRef - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g))) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (burnTickGet_evalFeeGrowthBelow0 - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g))) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (burnTickGet_evalFeeGrowthBelow1 - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g))) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (burnTickGet_evalFeeGrowthAbove0 - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g))) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (burnTickGet_evalFeeGrowthAbove1 - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g))) ?_ - exact ExecBlock.consReturn (ExecStmt.return (burnTickGet_evalReturnValues - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g))) - -def burnModifyPositionAfterLiquidityDeltaTail (_v : PoolImmutables) : List Stmt := - [ .internalCall "tickGetFeeGrowthInside" - [ .var "tickLower", .var "tickUpper", .var "_slot0tick", - .var "_feeGrowthGlobal0X128", .var "_feeGrowthGlobal1X128" ] - "feeGrowthInside", - .internalCall "positionUpdate" - [ .var "_positionKey", .var "liquidityDelta", tuple0 (.var "feeGrowthInside"), - tuple1 (.var "feeGrowthInside") ] - "_positionUpdated", - Stmt.ite (ltE (.var "liquidityDelta") (.intLit 0)) - [ Stmt.ite (.var "flippedLower") - [ .internalCall "tickClear" [.var "tickLower"] "_clearLower" ] - [], - Stmt.ite (.var "flippedUpper") - [ .internalCall "tickClear" [.var "tickUpper"] "_clearUpper" ] - [] ] - [], - .letDecl "amount0" (some int256) (.intLit 0), - .letDecl "amount1" (some int256) (.intLit 0), - Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ Stmt.ite (ltE (.var "_slot0tick") (.var "tickLower")) - [ .internalCall "getSqrtRatioAtTick" [.var "tickLower"] "sqrtRatioLowerBelow", - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] "sqrtRatioUpperBelow", - .internalCall "getAmount0DeltaSigned" - [ .var "sqrtRatioLowerBelow", .var "sqrtRatioUpperBelow", - .var "liquidityDelta" ] - "amount0Below", - .assign .localVar (varRef "amount0") (.var "amount0Below") ] - [ Stmt.ite (ltE (.var "_slot0tick") (.var "tickUpper")) - [ .letDecl "liquidityBefore" (some uint128) (.storage liquidityRef), - .internalCall "oracleWrite" - [ .var "_slot0observationIndex", blockTimestamp32, .var "_slot0tick", - .var "liquidityBefore", .var "_slot0observationCardinality", - .var "_slot0observationCardinalityNext" ] - "oracleUpdated", - .assign .storage (slot0F "observationIndex") (tuple0 (.var "oracleUpdated")), - .assign .storage (slot0F "observationCardinality") - (tuple1 (.var "oracleUpdated")), - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] - "sqrtRatioUpperInside", - .internalCall "getAmount0DeltaSigned" - [ .var "_slot0sqrtPriceX96", .var "sqrtRatioUpperInside", - .var "liquidityDelta" ] - "amount0Inside", - .assign .localVar (varRef "amount0") (.var "amount0Inside"), - .internalCall "getSqrtRatioAtTick" [.var "tickLower"] - "sqrtRatioLowerInside", - .internalCall "getAmount1DeltaSigned" - [ .var "sqrtRatioLowerInside", .var "_slot0sqrtPriceX96", - .var "liquidityDelta" ] - "amount1Inside", - .assign .localVar (varRef "amount1") (.var "amount1Inside"), - .internalCall "liquidityAddDelta" - [ .var "liquidityBefore", .var "liquidityDelta" ] - "liquidityAfter", - .assign .storage liquidityRef (.var "liquidityAfter") ] - [ .internalCall "getSqrtRatioAtTick" [.var "tickLower"] - "sqrtRatioLowerAbove", - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] - "sqrtRatioUpperAbove", - .internalCall "getAmount1DeltaSigned" - [ .var "sqrtRatioLowerAbove", .var "sqrtRatioUpperAbove", - .var "liquidityDelta" ] - "amount1Above", - .assign .localVar (varRef "amount1") (.var "amount1Above") ] ] ] - [], - .return [.var "_positionKey", .var "amount0", .var "amount1"] ] - -abbrev burnModifyPositionAfterFeeGrowthInsideFrame - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals.insert - "feeGrowthInside" (.tuple [burnTickGetInside0Value σ I, burnTickGetInside1Value σ I]) } - -theorem burnAfterSlot0Frame_slot0tick {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterSlot0Frame v σ I).locals.get? "_slot0tick" = - some (burnSlot0TickValue σ I) := by - rw [burnModifyPositionAfterSlot0Frame] - rw [store_get_ne3 - ((burnModifyPositionStore I).insert "_slot0sqrtPriceX96" - (burnSlot0SqrtPriceX96Value σ I) |>.insert "_slot0tick" (burnSlot0TickValue σ I)) - (k1 := "_slot0observationIndex") (k2 := "_slot0observationCardinality") - (k3 := "_slot0observationCardinalityNext") (a := "_slot0tick") - (burnSlot0ObservationIndexValue σ I) (burnSlot0ObservationCardinalityValue σ I) - (burnSlot0ObservationCardinalityNextValue σ I) - (by native_decide) (by native_decide) (by native_decide)] - exact store_get_self - ((burnModifyPositionStore I).insert "_slot0sqrtPriceX96" - (burnSlot0SqrtPriceX96Value σ I)) - "_slot0tick" (burnSlot0TickValue σ I) - -theorem burnAfterPositionKeyFrame_tickLower {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterPositionKeyFrame v σ I).locals.get? "tickLower" = - some (burnTickLowerValue I) := by - rw [burnModifyPositionAfterPositionKeyFrame] - rw [store_get_ne (burnModifyPositionAfterSlot0Frame v σ I).locals - (k := "_positionKey") (a := "tickLower") (burnPositionKeyValue I) - (by native_decide)] - exact burnAfterSlot0Frame_tickLower σ I - -theorem burnAfterPositionKeyFrame_tickUpper {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterPositionKeyFrame v σ I).locals.get? "tickUpper" = - some (burnTickUpperValue I) := by - rw [burnModifyPositionAfterPositionKeyFrame] - rw [store_get_ne (burnModifyPositionAfterSlot0Frame v σ I).locals - (k := "_positionKey") (a := "tickUpper") (burnPositionKeyValue I) - (by native_decide)] - exact burnAfterSlot0Frame_tickUpper σ I - -theorem burnAfterPositionKeyFrame_slot0tick {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterPositionKeyFrame v σ I).locals.get? "_slot0tick" = - some (burnSlot0TickValue σ I) := by - rw [burnModifyPositionAfterPositionKeyFrame] - rw [store_get_ne (burnModifyPositionAfterSlot0Frame v σ I).locals - (k := "_positionKey") (a := "_slot0tick") (burnPositionKeyValue I) - (by native_decide)] - exact burnAfterSlot0Frame_slot0tick σ I - -theorem burnAfterPositionKeyFrame_positionKey {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterPositionKeyFrame v σ I).locals.get? "_positionKey" = - some (burnPositionKeyValue I) := by - rw [burnModifyPositionAfterPositionKeyFrame] - exact store_get_self (burnModifyPositionAfterSlot0Frame v σ I).locals - "_positionKey" (burnPositionKeyValue I) - -theorem burnAfterFeeGrowthGlobalsFrame_tickLower {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals.get? "tickLower" = - some (burnTickLowerValue I) := by - rw [burnModifyPositionAfterFeeGrowthGlobalsFrame] - rw [store_get_ne4 (burnModifyPositionAfterPositionKeyFrame v σ I).locals - (k1 := "_feeGrowthGlobal0X128") (k2 := "_feeGrowthGlobal1X128") - (k3 := "flippedLower") (k4 := "flippedUpper") (a := "tickLower") - (burnFeeGrowthGlobal0Value σ I) (burnFeeGrowthGlobal1Value σ I) - (.bool false) (.bool false) - (by native_decide) (by native_decide) (by native_decide) (by native_decide)] - exact burnAfterPositionKeyFrame_tickLower σ I - -theorem burnAfterFeeGrowthGlobalsFrame_tickUpper {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals.get? "tickUpper" = - some (burnTickUpperValue I) := by - rw [burnModifyPositionAfterFeeGrowthGlobalsFrame] - rw [store_get_ne4 (burnModifyPositionAfterPositionKeyFrame v σ I).locals - (k1 := "_feeGrowthGlobal0X128") (k2 := "_feeGrowthGlobal1X128") - (k3 := "flippedLower") (k4 := "flippedUpper") (a := "tickUpper") - (burnFeeGrowthGlobal0Value σ I) (burnFeeGrowthGlobal1Value σ I) - (.bool false) (.bool false) - (by native_decide) (by native_decide) (by native_decide) (by native_decide)] - exact burnAfterPositionKeyFrame_tickUpper σ I - -theorem burnAfterFeeGrowthGlobalsFrame_slot0tick {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals.get? "_slot0tick" = - some (burnSlot0TickValue σ I) := by - rw [burnModifyPositionAfterFeeGrowthGlobalsFrame] - rw [store_get_ne4 (burnModifyPositionAfterPositionKeyFrame v σ I).locals - (k1 := "_feeGrowthGlobal0X128") (k2 := "_feeGrowthGlobal1X128") - (k3 := "flippedLower") (k4 := "flippedUpper") (a := "_slot0tick") - (burnFeeGrowthGlobal0Value σ I) (burnFeeGrowthGlobal1Value σ I) - (.bool false) (.bool false) - (by native_decide) (by native_decide) (by native_decide) (by native_decide)] - exact burnAfterPositionKeyFrame_slot0tick σ I - -theorem burnAfterFeeGrowthGlobalsFrame_positionKey {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals.get? "_positionKey" = - some (burnPositionKeyValue I) := by - rw [burnModifyPositionAfterFeeGrowthGlobalsFrame] - rw [store_get_ne4 (burnModifyPositionAfterPositionKeyFrame v σ I).locals - (k1 := "_feeGrowthGlobal0X128") (k2 := "_feeGrowthGlobal1X128") - (k3 := "flippedLower") (k4 := "flippedUpper") (a := "_positionKey") - (burnFeeGrowthGlobal0Value σ I) (burnFeeGrowthGlobal1Value σ I) - (.bool false) (.bool false) - (by native_decide) (by native_decide) (by native_decide) (by native_decide)] - exact burnAfterPositionKeyFrame_positionKey σ I - -theorem burnAfterFeeGrowthGlobalsFrame_feeGrowthGlobal0 {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals.get? - "_feeGrowthGlobal0X128" = some (burnFeeGrowthGlobal0Value σ I) := by - rw [burnModifyPositionAfterFeeGrowthGlobalsFrame] - rw [store_get_ne3 - ((burnModifyPositionAfterPositionKeyFrame v σ I).locals.insert - "_feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I)) - (k1 := "_feeGrowthGlobal1X128") (k2 := "flippedLower") (k3 := "flippedUpper") - (a := "_feeGrowthGlobal0X128") (burnFeeGrowthGlobal1Value σ I) - (.bool false) (.bool false) - (by native_decide) (by native_decide) (by native_decide)] - exact store_get_self (burnModifyPositionAfterPositionKeyFrame v σ I).locals - "_feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I) - -theorem burnAfterFeeGrowthGlobalsFrame_feeGrowthGlobal1 {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals.get? - "_feeGrowthGlobal1X128" = some (burnFeeGrowthGlobal1Value σ I) := by - rw [burnModifyPositionAfterFeeGrowthGlobalsFrame] - rw [store_get_ne2 - ((burnModifyPositionAfterPositionKeyFrame v σ I).locals.insert - "_feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I) - |>.insert "_feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I)) - (k1 := "flippedLower") (k2 := "flippedUpper") (a := "_feeGrowthGlobal1X128") - (.bool false) (.bool false) (by native_decide) (by native_decide)] - exact store_get_self - ((burnModifyPositionAfterPositionKeyFrame v σ I).locals.insert - "_feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I)) - "_feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I) - -theorem burnAfterFeeGrowthInsideFrame_positionKey {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterFeeGrowthInsideFrame v σ I).locals.get? "_positionKey" = - some (burnPositionKeyValue I) := by - rw [burnModifyPositionAfterFeeGrowthInsideFrame] - rw [store_get_ne (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals - (k := "feeGrowthInside") (a := "_positionKey") - (.tuple [burnTickGetInside0Value σ I, burnTickGetInside1Value σ I]) - (by native_decide)] - exact burnAfterFeeGrowthGlobalsFrame_positionKey σ I - -theorem burnAfterFeeGrowthInsideFrame_liquidityDelta {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterFeeGrowthInsideFrame v σ I).locals.get? "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnModifyPositionAfterFeeGrowthInsideFrame] - rw [store_get_ne (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals - (k := "feeGrowthInside") (a := "liquidityDelta") - (.tuple [burnTickGetInside0Value σ I, burnTickGetInside1Value σ I]) - (by native_decide)] - exact burnAfterFeeGrowthGlobalsFrame_liquidityDelta σ I - -theorem burnAfterFeeGrowthInsideFrame_feeGrowthInside {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterFeeGrowthInsideFrame v σ I).locals.get? "feeGrowthInside" = - some (.tuple [burnTickGetInside0Value σ I, burnTickGetInside1Value σ I]) := by - rw [burnModifyPositionAfterFeeGrowthInsideFrame] - exact store_get_self (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals - "feeGrowthInside" - (.tuple [burnTickGetInside0Value σ I, burnTickGetInside1Value σ I]) - -theorem burnModifyPosition_evalTickGetFeeGrowthInsideArgs {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExprs? (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .var "tickLower", .var "tickUpper", .var "_slot0tick", - .var "_feeGrowthGlobal0X128", .var "_feeGrowthGlobal1X128" ] = - .ok (burnTickGetFeeGrowthInsideArgValues σ I) := by - simp only [burnTickGetFeeGrowthInsideArgValues, evalExprs?, evalExpr?, - EvalResult.bind, bind, pure] - rw [burnAfterFeeGrowthGlobalsFrame_tickLower (v := v), - burnAfterFeeGrowthGlobalsFrame_tickUpper (v := v), - burnAfterFeeGrowthGlobalsFrame_slot0tick (v := v), - burnAfterFeeGrowthGlobalsFrame_feeGrowthGlobal0 (v := v), - burnAfterFeeGrowthGlobalsFrame_feeGrowthGlobal1 (v := v)] - rfl - -theorem burnModifyPosition_evalPositionUpdateArgsAfterFeeGrowthInside - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExprs? (config v) (burnModifyPositionAfterFeeGrowthInsideFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .var "_positionKey", .var "liquidityDelta", tuple0 (.var "feeGrowthInside"), - tuple1 (.var "feeGrowthInside") ] = - .ok (burnPositionUpdateValueArgValues I - (burnTickGetInside0Value σ I) (burnTickGetInside1Value σ I)) := by - simp only [burnPositionUpdateValueArgValues, evalExprs?, evalExpr?, tuple0, tuple1, - EvalResult.bind, bind, pure] - rw [burnAfterFeeGrowthInsideFrame_positionKey (v := v), - burnAfterFeeGrowthInsideFrame_liquidityDelta (v := v), - burnAfterFeeGrowthInsideFrame_feeGrowthInside (v := v)] - rfl - -theorem uniswapV3PoolLookupTickGetFeeGrowthInside (v : PoolImmutables) : - lookupCallable? (contract v) "tickGetFeeGrowthInside" = - some tickGetFeeGrowthInsideFunction.toCallable := by - simp [lookupCallable?, lookupFunction?, contract, functions, getSqrtRatioAtTickFunction, - getTickAtSqrtRatioFunction, oracleLteFunction, oracleTransformFunction, - getSurroundingObservationsFunction, observeSingleFunction, observeBodyFunction, - liquidityAddDeltaFunction, oracleWriteFunction, tickGetFeeGrowthInsideFunction, - tickUpdateFunction, tickClearFunction, tickBitmapFlipFunction, positionUpdateFunction, - getAmount0DeltaUnsignedFunction, getAmount1DeltaUnsignedFunction, - getAmount0DeltaSignedFunction, getAmount1DeltaSignedFunction, modifyPositionFunction] - -theorem uniswapV3PoolLookupPositionUpdate (v : PoolImmutables) : - lookupCallable? (contract v) "positionUpdate" = - some positionUpdateFunction.toCallable := by - simp [lookupCallable?, lookupFunction?, contract, functions, getSqrtRatioAtTickFunction, - getTickAtSqrtRatioFunction, oracleLteFunction, oracleTransformFunction, - getSurroundingObservationsFunction, observeSingleFunction, observeBodyFunction, - liquidityAddDeltaFunction, oracleWriteFunction, tickGetFeeGrowthInsideFunction, - tickUpdateFunction, tickClearFunction, tickBitmapFlipFunction, positionUpdateFunction, - getAmount0DeltaUnsignedFunction, getAmount1DeltaUnsignedFunction, - getAmount0DeltaSignedFunction, getAmount1DeltaSignedFunction, modifyPositionFunction] - -theorem uniswapV3PoolModifyPositionSourcePositionUpdateLiquidityZeroTailReverts - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) = ⟨0⟩) : - ExecBlock (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (burnModifyPositionAfterLiquidityDeltaTail v) - .reverted := by - change ExecBlock (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .internalCall "tickGetFeeGrowthInside" - [ .var "tickLower", .var "tickUpper", .var "_slot0tick", - .var "_feeGrowthGlobal0X128", .var "_feeGrowthGlobal1X128" ] - "feeGrowthInside", - .internalCall "positionUpdate" - [ .var "_positionKey", .var "liquidityDelta", tuple0 (.var "feeGrowthInside"), - tuple1 (.var "feeGrowthInside") ] - "_positionUpdated", - Stmt.ite (ltE (.var "liquidityDelta") (.intLit 0)) - [ Stmt.ite (.var "flippedLower") - [ .internalCall "tickClear" [.var "tickLower"] "_clearLower" ] - [], - Stmt.ite (.var "flippedUpper") - [ .internalCall "tickClear" [.var "tickUpper"] "_clearUpper" ] - [] ] - [], - .letDecl "amount0" (some int256) (.intLit 0), - .letDecl "amount1" (some int256) (.intLit 0), - Stmt.ite (neE (.var "liquidityDelta") (.intLit 0)) - [ Stmt.ite (ltE (.var "_slot0tick") (.var "tickLower")) - [ .internalCall "getSqrtRatioAtTick" [.var "tickLower"] "sqrtRatioLowerBelow", - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] "sqrtRatioUpperBelow", - .internalCall "getAmount0DeltaSigned" - [ .var "sqrtRatioLowerBelow", .var "sqrtRatioUpperBelow", - .var "liquidityDelta" ] - "amount0Below", - .assign .localVar (varRef "amount0") (.var "amount0Below") ] - [ Stmt.ite (ltE (.var "_slot0tick") (.var "tickUpper")) - [ .letDecl "liquidityBefore" (some uint128) (.storage liquidityRef), - .internalCall "oracleWrite" - [ .var "_slot0observationIndex", blockTimestamp32, .var "_slot0tick", - .var "liquidityBefore", .var "_slot0observationCardinality", - .var "_slot0observationCardinalityNext" ] - "oracleUpdated", - .assign .storage (slot0F "observationIndex") (tuple0 (.var "oracleUpdated")), - .assign .storage (slot0F "observationCardinality") - (tuple1 (.var "oracleUpdated")), - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] - "sqrtRatioUpperInside", - .internalCall "getAmount0DeltaSigned" - [ .var "_slot0sqrtPriceX96", .var "sqrtRatioUpperInside", - .var "liquidityDelta" ] - "amount0Inside", - .assign .localVar (varRef "amount0") (.var "amount0Inside"), - .internalCall "getSqrtRatioAtTick" [.var "tickLower"] - "sqrtRatioLowerInside", - .internalCall "getAmount1DeltaSigned" - [ .var "sqrtRatioLowerInside", .var "_slot0sqrtPriceX96", - .var "liquidityDelta" ] - "amount1Inside", - .assign .localVar (varRef "amount1") (.var "amount1Inside"), - .internalCall "liquidityAddDelta" - [ .var "liquidityBefore", .var "liquidityDelta" ] - "liquidityAfter", - .assign .storage liquidityRef (.var "liquidityAfter") ] - [ .internalCall "getSqrtRatioAtTick" [.var "tickLower"] - "sqrtRatioLowerAbove", - .internalCall "getSqrtRatioAtTick" [.var "tickUpper"] - "sqrtRatioUpperAbove", - .internalCall "getAmount1DeltaSigned" - [ .var "sqrtRatioLowerAbove", .var "sqrtRatioUpperAbove", - .var "liquidityDelta" ] - "amount1Above", - .assign .localVar (varRef "amount1") (.var "amount1Above") ] ] ] - [], - .return [.var "_positionKey", .var "amount0", .var "amount1"] ] - .reverted - refine ExecBlock.consNormal - (solm' := burnModifyPositionAfterFeeGrowthInsideFrame v σ I) - (evm' := initState cA gh bl σ σ₀ g A I) ?_ ?_ - · have hstmt := internalCallFunctionReturn (callee := tickGetFeeGrowthInsideFunction) - (retVar := "feeGrowthInside") - (argVals := burnTickGetFeeGrowthInsideArgValues σ I) - (locals := burnTickGetFeeGrowthInsideStore σ I) - (calleeSolm := burnTickGetAfterAbove1Frame v σ I) - (value := some [burnTickGetInside0Value σ I, burnTickGetInside1Value σ I]) - (burnModifyPosition_evalTickGetFeeGrowthInsideArgs (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g)) - (by - simpa [burnModifyPositionAfterFeeGrowthGlobalsFrame] using - uniswapV3PoolLookupTickGetFeeGrowthInside v) - (burnTickGetFeeGrowthInside_bindParams σ I) - (uniswapV3PoolTickGetFeeGrowthInsideSourceReturns (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g)) - simpa [burnModifyPositionAfterFeeGrowthInsideFrame, resumeAfterInternalCall, - collapseReturns] using hstmt - · refine ExecBlock.consRevert ?_ - refine internalCallFunctionRevert (callee := positionUpdateFunction) - (argVals := burnPositionUpdateValueArgValues I - (burnTickGetInside0Value σ I) (burnTickGetInside1Value σ I)) - (locals := burnPositionUpdateValueStore I - (burnTickGetInside0Value σ I) (burnTickGetInside1Value σ I)) - ?_ ?_ ?_ ?_ - · exact burnModifyPosition_evalPositionUpdateArgsAfterFeeGrowthInside - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) - · simpa [burnModifyPositionAfterFeeGrowthInsideFrame] using - uniswapV3PoolLookupPositionUpdate v - · exact burnPositionUpdateValue_bindParams I - (burnTickGetInside0Value σ I) (burnTickGetInside1Value σ I) - · simpa [burnPositionUpdateValueFrame, burnModifyPositionAfterFeeGrowthInsideFrame] using - uniswapV3PoolPositionUpdateSourceLiquidityZeroRevertsValue (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) - (burnTickGetInside0Value σ I) (burnTickGetInside1Value σ I) hzero hliq - -theorem uniswapV3PoolModifyPositionSourcePositionUpdateLiquidityZeroReverts - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ I (positionsBase (burnPositionKeyKey I))) = ⟨0⟩) : - ExecFuncBody (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (modifyPositionFunction v).body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolModifyPositionSourceThroughLiquidityDeltaZeroSkip - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hguard htickLt hge hle hzero - have htail := uniswapV3PoolModifyPositionSourcePositionUpdateLiquidityZeroTailReverts - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hzero hliq - simpa [modifyPositionFunction, burnModifyPositionSlot0Prefix, - burnModifyPositionPositionKeyStep, burnModifyPositionFeeGrowthGlobalsStep, - burnModifyPositionLiquidityDeltaUpdateStep, burnModifyPositionAfterLiquidityDeltaTail] - using execBlock_append hprefix htail - -theorem uniswapV3PoolBurnSourcePositionUpdateLiquidityZeroReverts - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : burnUnlockedByte σ I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - I (positionsBase (burnPositionKeyKey I))) = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (burnStore I) - burnTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolBurnSourceThroughLiquidityDelta (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hunlocked hcanon - have hlockState : - Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I) = - initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - σ₀ g A I := by - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have hstmt : - ExecStmt (config v) (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - (.internalCall "modifyPosition" - [.env .caller, .var "tickLower", .var "tickUpper", .var "liquidityDelta"] - "modified") - .reverted := by - rw [hlockState] - refine internalCallFunctionRevert (callee := modifyPositionFunction v) - (argVals := burnModifyPositionArgValues I) (locals := burnModifyPositionStore I) - ?_ ?_ ?_ ?_ - · have hLower := burnLiquidityDeltaFrame_tickLower (v := v) I - have hUpper := burnLiquidityDeltaFrame_tickUpper (v := v) I - have hDelta := burnLiquidityDeltaFrame_liquidityDelta (v := v) I - simp only [burnModifyPositionArgValues, evalExprs?, evalExpr?, envValue, initState, - EvalResult.bind, bind, pure] - rw [hLower, hUpper, hDelta] - rfl - · simpa [burnLiquidityDeltaFrame] using uniswapV3PoolLookupModifyPosition v - · rfl - · exact uniswapV3PoolModifyPositionSourcePositionUpdateLiquidityZeroReverts - (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ := sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hguard htickLt hge hle hzero - hliq - simpa [burnTransition, nonpayable, lockPrefix] using - execBlock_append hprefix (ExecBlock.consRevert hstmt) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnTickUpdateSource.lean b/Benchmarks/UniswapV3Pool/BurnTickUpdateSource.lean deleted file mode 100644 index 2b382775..00000000 --- a/Benchmarks/UniswapV3Pool/BurnTickUpdateSource.lean +++ /dev/null @@ -1,1150 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnTickUpdateStart -import Benchmarks.UniswapV3Pool.BurnLiquidityAddDelta - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev burnTickUpdateLowerInfoFrame (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnTickUpdateLowerStore v σ I).insert "info" - (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) } - -abbrev burnTickUpdateLowerLiquidityGrossBeforeWord (σ : AccountMap) - (I : ExecutionEnv) : UInt256 := - UInt256.land (solcSlotWord σ I (burnTickGetLowerBaseSlot I)) uint128Mask - -abbrev burnTickUpdateLowerLiquidityGrossBeforeValue (σ : AccountMap) - (I : ExecutionEnv) : Value := - .int (Int.ofNat (burnTickUpdateLowerLiquidityGrossBeforeWord σ I).toNat) - -abbrev burnTickUpdateLowerLiquidityGrossBeforeInt (σ : AccountMap) - (I : ExecutionEnv) : Int := - Int.ofNat (burnTickUpdateLowerLiquidityGrossBeforeWord σ I).toNat - -abbrev burnTickUpdateLowerLiquidityDeltaInt (I : ExecutionEnv) : Int := - 0 - Int.ofNat (burnAmountCleanWord I).toNat - -abbrev burnTickUpdateLowerLiquidityAddDeltaArgValues (σ : AccountMap) - (I : ExecutionEnv) : List Value := - liquidityAddDeltaArgValues - (burnTickUpdateLowerLiquidityGrossBeforeInt σ I) - (burnTickUpdateLowerLiquidityDeltaInt I) - -abbrev burnTickUpdateLowerAfterLiquidityGrossBeforeFrame - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnTickUpdateLowerInfoFrame v σ I).locals.insert - "liquidityGrossBefore" (burnTickUpdateLowerLiquidityGrossBeforeValue σ I) } - -abbrev burnTickUpdateLowerLiquidityGrossAfterSubInt (σ : AccountMap) - (I : ExecutionEnv) : Int := - liquidityAddDeltaWrappedSub - (burnTickUpdateLowerLiquidityGrossBeforeInt σ I) - (burnTickUpdateLowerLiquidityDeltaInt I) - -abbrev burnTickUpdateLowerAfterLiquidityGrossAfterFrame - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I).locals.insert - "liquidityGrossAfter" (.int (burnTickUpdateLowerLiquidityGrossAfterSubInt σ I)) } - -abbrev burnTickUpdateLowerFlippedBool (σ : AccountMap) (I : ExecutionEnv) : Bool := - decide ((burnTickUpdateLowerLiquidityGrossAfterSubInt σ I = 0) ≠ - (burnTickUpdateLowerLiquidityGrossBeforeInt σ I = 0)) - -abbrev burnTickUpdateLowerAfterFlippedFrame - (v : PoolImmutables) (σ : AccountMap) (I : ExecutionEnv) : Frame := - { contract := contract v, - locals := (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I).locals.insert - "flipped" (.bool (burnTickUpdateLowerFlippedBool σ I)) } - -theorem burnTickUpdateLowerStore_tick {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickUpdateLowerStore v σ I).get? "tick" = some (burnTickLowerValue I) := by - simp [burnTickUpdateLowerStore] - -theorem burnTickUpdateLowerStore_ticks {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickUpdateLowerStore v σ I).get? "ticks" = none := by - simp [burnTickUpdateLowerStore] - -theorem burnTickUpdateLowerStore_maxLiquidity {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnTickUpdateLowerStore v σ I).get? "maxLiquidity" = - some (.int v.maxLiquidityPerTick) := by - rw [burnTickUpdateLowerStore] - let L0 : Store := (∅ : Store).insert "maxLiquidity" (.int v.maxLiquidityPerTick) - let L1 : Store := (((((L0 - |>.insert "upper" (.bool false)) - |>.insert "time" (burnBlockTimestamp32Value I)) - |>.insert "tickCumulative" (wordToElem (.int int56Int) - (burnObserveSingleTickStorageWord σ I))) - |>.insert "secondsPerLiquidityCumulativeX128" - (.int (Int.ofNat (burnObserveSingleSecondsPerLiquidityWord σ I).toNat))) - |>.insert "feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I)) - change ((((L1.insert "feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I)) - |>.insert "liquidityDelta" (burnLiquidityDeltaValue I)) - |>.insert "tickCurrent" (burnSlot0TickValue σ I)) - |>.insert "tick" (burnTickLowerValue I)).get? "maxLiquidity" = - some (.int v.maxLiquidityPerTick) - rw [store_get_ne4 L1 (k1 := "feeGrowthGlobal0X128") (k2 := "liquidityDelta") - (k3 := "tickCurrent") (k4 := "tick") (a := "maxLiquidity") - (burnFeeGrowthGlobal0Value σ I) (burnLiquidityDeltaValue I) - (burnSlot0TickValue σ I) (burnTickLowerValue I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide)] - rw [store_get_ne5 L0 (k1 := "upper") (k2 := "time") (k3 := "tickCumulative") - (k4 := "secondsPerLiquidityCumulativeX128") (k5 := "feeGrowthGlobal1X128") - (a := "maxLiquidity") (.bool false) (burnBlockTimestamp32Value I) - (wordToElem (.int int56Int) (burnObserveSingleTickStorageWord σ I)) - (.int (Int.ofNat (burnObserveSingleSecondsPerLiquidityWord σ I).toNat)) - (burnFeeGrowthGlobal1Value σ I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - (by native_decide)] - rw [store_get_self (∅ : Store) "maxLiquidity" (.int v.maxLiquidityPerTick)] - -theorem burnTickUpdateLowerStore_liquidityDelta {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnTickUpdateLowerStore v σ I).get? "liquidityDelta" = - some (.int (burnTickUpdateLowerLiquidityDeltaInt I)) := by - rw [burnTickUpdateLowerStore] - let L0 : Store := - (((((((∅ : Store) - |>.insert "maxLiquidity" (.int v.maxLiquidityPerTick)) - |>.insert "upper" (.bool false)) - |>.insert "time" (burnBlockTimestamp32Value I)) - |>.insert "tickCumulative" (wordToElem (.int int56Int) - (burnObserveSingleTickStorageWord σ I))) - |>.insert "secondsPerLiquidityCumulativeX128" - (.int (Int.ofNat (burnObserveSingleSecondsPerLiquidityWord σ I).toNat))) - |>.insert "feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I)) - |>.insert "feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I) - change (((L0.insert "liquidityDelta" (burnLiquidityDeltaValue I)) - |>.insert "tickCurrent" (burnSlot0TickValue σ I)) - |>.insert "tick" (burnTickLowerValue I)).get? "liquidityDelta" = - some (.int (burnTickUpdateLowerLiquidityDeltaInt I)) - rw [store_get_ne2 (L0.insert "liquidityDelta" (burnLiquidityDeltaValue I)) - (k1 := "tickCurrent") (k2 := "tick") (a := "liquidityDelta") - (burnSlot0TickValue σ I) (burnTickLowerValue I) - (by native_decide) (by native_decide)] - rw [store_get_self L0 "liquidityDelta" (burnLiquidityDeltaValue I)] - -theorem burnTickUpdateLower_evalStorageRef_info {v : PoolImmutables} - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) : - evalStorageRef (config v) (burnTickUpdateLowerFrame v σ I) evm - (ticksRef (.var "tick")) = - .ok (burnTickGetLowerEvaledBaseRef I) := by - simp only [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, ticksRef, - burnTickUpdateLowerFrame, evalExpr?, EvalResult.bind, bind, pure] - rw [burnTickUpdateLowerStore_tick] - simp [burnTickGetLowerEvaledBaseRef, burnTickGetLowerKey, burnTickLowerValue, - valueToKey?, EvalResult.ofOption] - -theorem burnTickUpdateLower_resolveInfoRef {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - resolveStorageRef? (config v) (burnTickUpdateLowerFrame v σ I) - (initState cA gh bl σ σ₀ g A I) (ticksRef (.var "tick")) = - .ok (burnTickGetLowerEvaledBaseRef I, tickInfoStructTy) := by - apply resolveStorageRef?_ok - · exact burnTickUpdateLowerStore_ticks σ I - · exact burnTickUpdateLower_evalStorageRef_info (v := v) - (initState cA gh bl σ σ₀ g A I) σ I - · simp [burnTickGetLowerEvaledBaseRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, tickInfoStructTy] - -theorem burnTickUpdateLowerInfoFrame_info {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnTickUpdateLowerInfoFrame v σ I).locals.get? "info" = - some (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) := by - rw [burnTickUpdateLowerInfoFrame] - exact store_get_self (burnTickUpdateLowerStore v σ I) "info" - (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) - -theorem burnTickUpdateLowerInfoFrame_liquidityDelta {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnTickUpdateLowerInfoFrame v σ I).locals.get? "liquidityDelta" = - some (.int (burnTickUpdateLowerLiquidityDeltaInt I)) := by - rw [burnTickUpdateLowerInfoFrame] - rw [store_get_ne (burnTickUpdateLowerStore v σ I) - (k := "info") (a := "liquidityDelta") - (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) - (by native_decide)] - exact burnTickUpdateLowerStore_liquidityDelta σ I - -theorem burnTickUpdateLower_evalLiquidityGrossBefore {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnTickUpdateLowerInfoFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.field (.var "info") "liquidityGross") = - .ok (burnTickUpdateLowerLiquidityGrossBeforeValue σ I) := by - simp only [evalExpr?, EvalResult.bind, bind] - rw [burnTickUpdateLowerInfoFrame_info] - change readStorage? (config v) (initState cA gh bl σ σ₀ g A I) - (burnTickGetLowerEvaledRef I "liquidityGross") uint128St = - .ok (burnTickUpdateLowerLiquidityGrossBeforeValue σ I) - rw [show uint128St = .elem (.int uint128Int) by rfl] - rw [readStorage?_elem - (er := burnTickGetLowerEvaledRef I "liquidityGross") - (t := .int uint128Int) - (loc := loc (burnTickGetLowerBaseSlot I) ⟨0, by decide⟩ - ⟨16, by decide⟩ (by decide) (.int uint128Int))] - · simpa [initState, burnTickUpdateLowerLiquidityGrossBeforeValue, - burnTickUpdateLowerLiquidityGrossBeforeWord, solcSlotWord, loc] using - storageLocLoad_uint_offset0 (initState cA gh bl σ σ₀ g A I) - (burnTickGetLowerBaseSlot I) ⟨16, by decide⟩ ⟨128, by decide⟩ - (hbound := by decide) (by decide) - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - burnTickGetLowerEvaledRef, burnTickGetLowerBaseSlot, loc] - -theorem burnTickUpdateLowerAfterLiquidityGrossBeforeFrame_liquidityGrossBefore - {v : PoolImmutables} (σ : AccountMap) (I : ExecutionEnv) : - (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I).locals.get? - "liquidityGrossBefore" = - some (.int (burnTickUpdateLowerLiquidityGrossBeforeInt σ I)) := by - rw [burnTickUpdateLowerAfterLiquidityGrossBeforeFrame, - burnTickUpdateLowerLiquidityGrossBeforeValue, - burnTickUpdateLowerLiquidityGrossBeforeInt] - exact store_get_self (burnTickUpdateLowerInfoFrame v σ I).locals - "liquidityGrossBefore" - (.int (Int.ofNat (burnTickUpdateLowerLiquidityGrossBeforeWord σ I).toNat)) - -theorem burnTickUpdateLowerAfterLiquidityGrossBeforeFrame_liquidityDelta - {v : PoolImmutables} (σ : AccountMap) (I : ExecutionEnv) : - (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I).locals.get? - "liquidityDelta" = some (.int (burnTickUpdateLowerLiquidityDeltaInt I)) := by - rw [burnTickUpdateLowerAfterLiquidityGrossBeforeFrame] - rw [store_get_ne (burnTickUpdateLowerInfoFrame v σ I).locals - (k := "liquidityGrossBefore") (a := "liquidityDelta") - (burnTickUpdateLowerLiquidityGrossBeforeValue σ I) (by native_decide)] - exact burnTickUpdateLowerInfoFrame_liquidityDelta σ I - -theorem burnTickUpdateLowerAfterLiquidityGrossAfterFrame_liquidityGrossAfter - {v : PoolImmutables} (σ : AccountMap) (I : ExecutionEnv) : - (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I).locals.get? - "liquidityGrossAfter" = - some (.int (burnTickUpdateLowerLiquidityGrossAfterSubInt σ I)) := by - rw [burnTickUpdateLowerAfterLiquidityGrossAfterFrame] - exact store_get_self (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I).locals - "liquidityGrossAfter" (.int (burnTickUpdateLowerLiquidityGrossAfterSubInt σ I)) - -theorem burnTickUpdateLowerAfterLiquidityGrossAfterFrame_liquidityGrossBefore - {v : PoolImmutables} (σ : AccountMap) (I : ExecutionEnv) : - (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I).locals.get? - "liquidityGrossBefore" = - some (.int (burnTickUpdateLowerLiquidityGrossBeforeInt σ I)) := by - rw [burnTickUpdateLowerAfterLiquidityGrossAfterFrame] - rw [store_get_ne (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I).locals - (k := "liquidityGrossAfter") (a := "liquidityGrossBefore") - (.int (burnTickUpdateLowerLiquidityGrossAfterSubInt σ I)) (by native_decide)] - exact burnTickUpdateLowerAfterLiquidityGrossBeforeFrame_liquidityGrossBefore σ I - -theorem burnTickUpdateLowerAfterLiquidityGrossAfterFrame_maxLiquidity - {v : PoolImmutables} (σ : AccountMap) (I : ExecutionEnv) : - (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I).locals.get? - "maxLiquidity" = some (.int v.maxLiquidityPerTick) := by - rw [burnTickUpdateLowerAfterLiquidityGrossAfterFrame, - burnTickUpdateLowerAfterLiquidityGrossBeforeFrame, burnTickUpdateLowerInfoFrame] - rw [store_get_ne3 (burnTickUpdateLowerStore v σ I) - (k1 := "info") (k2 := "liquidityGrossBefore") (k3 := "liquidityGrossAfter") - (a := "maxLiquidity") - (.storageRef (burnTickGetLowerEvaledBaseRef I) tickInfoStructTy) - (burnTickUpdateLowerLiquidityGrossBeforeValue σ I) - (.int (burnTickUpdateLowerLiquidityGrossAfterSubInt σ I)) - (by native_decide) (by native_decide) (by native_decide)] - exact burnTickUpdateLowerStore_maxLiquidity σ I - -theorem burnTickUpdateLowerAfterFlippedFrame_flipped - {v : PoolImmutables} (σ : AccountMap) (I : ExecutionEnv) : - (burnTickUpdateLowerAfterFlippedFrame v σ I).locals.get? "flipped" = - some (.bool (burnTickUpdateLowerFlippedBool σ I)) := by - rw [burnTickUpdateLowerAfterFlippedFrame] - exact store_get_self (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I).locals - "flipped" (.bool (burnTickUpdateLowerFlippedBool σ I)) - -theorem burnTickUpdateLowerAfterFlippedFrame_liquidityGrossBefore - {v : PoolImmutables} (σ : AccountMap) (I : ExecutionEnv) : - (burnTickUpdateLowerAfterFlippedFrame v σ I).locals.get? "liquidityGrossBefore" = - some (.int (burnTickUpdateLowerLiquidityGrossBeforeInt σ I)) := by - rw [burnTickUpdateLowerAfterFlippedFrame] - rw [store_get_ne (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I).locals - (k := "flipped") (a := "liquidityGrossBefore") - (.bool (burnTickUpdateLowerFlippedBool σ I)) (by native_decide)] - exact burnTickUpdateLowerAfterLiquidityGrossAfterFrame_liquidityGrossBefore σ I - -theorem burnTickUpdateLower_evalLiquidityAddDeltaArgs - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExprs? (config v) (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [.var "liquidityGrossBefore", .var "liquidityDelta"] = - .ok (burnTickUpdateLowerLiquidityAddDeltaArgValues σ I) := by - simp only [burnTickUpdateLowerLiquidityAddDeltaArgValues, liquidityAddDeltaArgValues, - evalExprs?, evalExpr?, EvalResult.bind, bind, pure] - rw [burnTickUpdateLowerAfterLiquidityGrossBeforeFrame_liquidityGrossBefore, - burnTickUpdateLowerAfterLiquidityGrossBeforeFrame_liquidityDelta] - rfl - -theorem burnTickUpdateLowerLiquidityDeltaNegative (I : ExecutionEnv) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) : - burnTickUpdateLowerLiquidityDeltaInt I < 0 := by - have hnat : (burnAmountCleanWord I).toNat ≠ 0 := by - intro hzero - exact hnonzero (uint256_toNat_eq_zero hzero) - have hpos : 0 < (burnAmountCleanWord I).toNat := Nat.pos_of_ne_zero hnat - unfold burnTickUpdateLowerLiquidityDeltaInt - change 0 - ((burnAmountCleanWord I).toNat : Int) < 0 - have hposInt : (0 : Int) < ((burnAmountCleanWord I).toNat : Int) := by - omega - omega - -theorem burnTickUpdateLower_evalLiquidityGrossAfterLeMaxTrue - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hle : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ I <= v.maxLiquidityPerTick) : - evalExpr? (config v) (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (leE (.var "liquidityGrossAfter") (.var "maxLiquidity")) = .ok (.bool true) := by - simp only [leE, evalExpr?, EvalResult.bind, EvalResult.ofOption, bind] - rw [burnTickUpdateLowerAfterLiquidityGrossAfterFrame_liquidityGrossAfter, - burnTickUpdateLowerAfterLiquidityGrossAfterFrame_maxLiquidity] - simp [evalBinaryOp?, hle] - -theorem burnTickUpdateLower_evalLiquidityGrossAfterLeMaxFalse - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hle : - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt σ I <= v.maxLiquidityPerTick) : - evalExpr? (config v) (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (leE (.var "liquidityGrossAfter") (.var "maxLiquidity")) = .ok (.bool false) := by - simp only [leE, evalExpr?, EvalResult.bind, EvalResult.ofOption, bind] - rw [burnTickUpdateLowerAfterLiquidityGrossAfterFrame_liquidityGrossAfter, - burnTickUpdateLowerAfterLiquidityGrossAfterFrame_maxLiquidity] - simp [evalBinaryOp?, hle] - -theorem burnTickUpdateLower_evalFlipped - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (neE (eqE (.var "liquidityGrossAfter") (.intLit 0)) - (eqE (.var "liquidityGrossBefore") (.intLit 0))) = - .ok (.bool (burnTickUpdateLowerFlippedBool σ I)) := by - simp only [neE, eqE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnTickUpdateLowerAfterLiquidityGrossAfterFrame_liquidityGrossAfter, - burnTickUpdateLowerAfterLiquidityGrossAfterFrame_liquidityGrossBefore] - simp [EvalResult.ofOption, evalBinaryOp?, burnTickUpdateLowerFlippedBool] - -theorem burnTickUpdateLower_evalLiquidityGrossBeforeEqZeroTrue - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hzero : burnTickUpdateLowerLiquidityGrossBeforeInt σ I = 0) : - evalExpr? (config v) (burnTickUpdateLowerAfterFlippedFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (eqE (.var "liquidityGrossBefore") (.intLit 0)) = .ok (.bool true) := by - simp only [eqE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnTickUpdateLowerAfterFlippedFrame_liquidityGrossBefore] - have hnat : (burnTickUpdateLowerLiquidityGrossBeforeWord σ I).toNat = 0 := by - unfold burnTickUpdateLowerLiquidityGrossBeforeInt at hzero - exact Int.ofNat_eq_zero.mp hzero - simp [EvalResult.ofOption, evalBinaryOp?, hnat] - -theorem burnTickUpdateLower_evalLiquidityGrossBeforeEqZeroFalse - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hnonzero : burnTickUpdateLowerLiquidityGrossBeforeInt σ I ≠ 0) : - evalExpr? (config v) (burnTickUpdateLowerAfterFlippedFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (eqE (.var "liquidityGrossBefore") (.intLit 0)) = .ok (.bool false) := by - simp only [eqE, evalExpr?, EvalResult.bind, bind, pure] - rw [burnTickUpdateLowerAfterFlippedFrame_liquidityGrossBefore] - have hnat : (burnTickUpdateLowerLiquidityGrossBeforeWord σ I).toNat ≠ 0 := by - intro hz - apply hnonzero - unfold burnTickUpdateLowerLiquidityGrossBeforeInt - simp [hz] - simp [EvalResult.ofOption, evalBinaryOp?, hnat] - -theorem uniswapV3PoolTickUpdateLowerSourceInfoStep - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} : - ExecStmt (config v) (burnTickUpdateLowerFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.letStorage "info" (ticksRef (.var "tick"))) - (.ok (burnTickUpdateLowerInfoFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecStmt.letStorage (burnTickUpdateLower_resolveInfoRef - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g)) - -theorem uniswapV3PoolTickUpdateLowerSourceLiquidityGrossBeforeStep - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} : - ExecStmt (config v) (burnTickUpdateLowerInfoFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.letDecl "liquidityGrossBefore" (some uint128) - (.field (.var "info") "liquidityGross")) - (.ok (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecStmt.letDecl (burnTickUpdateLower_evalLiquidityGrossBefore - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g)) - -theorem uniswapV3PoolTickUpdateLowerSourcePrefix - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} : - ExecBlock (config v) (burnTickUpdateLowerFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "info" (ticksRef (.var "tick")), - .letDecl "liquidityGrossBefore" (some uint128) - (.field (.var "info") "liquidityGross") ] - (.ok (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecBlock.consNormal - (uniswapV3PoolTickUpdateLowerSourceInfoStep - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g)) - (ExecBlock.consNormal - (uniswapV3PoolTickUpdateLowerSourceLiquidityGrossBeforeStep - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g)) - ExecBlock.nil) - -theorem uniswapV3PoolTickUpdateLowerSourceLiquidityAddDeltaReturnStep - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hreq : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ I) : - ExecStmt (config v) (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.internalCall "liquidityAddDelta" - [.var "liquidityGrossBefore", .var "liquidityDelta"] "liquidityGrossAfter") - (.ok (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - let x := burnTickUpdateLowerLiquidityGrossBeforeInt σ I - let y := burnTickUpdateLowerLiquidityDeltaInt I - let z := burnTickUpdateLowerLiquidityGrossAfterSubInt σ I - have hbody : - ExecFuncBody (config v) - { (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I) with - locals := liquidityAddDeltaStore x y } - (initState cA gh bl σ σ₀ g A I) liquidityAddDeltaFunction.body - (.returned (liquidityAddDeltaAfterZFrame v x y z) - (initState cA gh bl σ σ₀ g A I) (some [.int z])) := by - have hy : y < 0 := by - simpa [y] using burnTickUpdateLowerLiquidityDeltaNegative I hnonzero - have hreq' : liquidityAddDeltaWrappedSub x y < x := by - simpa [x, y, z, burnTickUpdateLowerLiquidityGrossAfterSubInt] using hreq - simpa [liquidityAddDeltaFrame] using - uniswapV3PoolLiquidityAddDeltaSourceNegativeReturns - (v := v) (evm := initState cA gh bl σ σ₀ g A I) - (x := x) (y := y) hy hreq' - have hstmt := internalCallFunctionReturn (callee := liquidityAddDeltaFunction) - (retVar := "liquidityGrossAfter") - (argVals := burnTickUpdateLowerLiquidityAddDeltaArgValues σ I) - (locals := liquidityAddDeltaStore x y) - (calleeSolm := liquidityAddDeltaAfterZFrame v x y z) - (value := some [.int z]) - (burnTickUpdateLower_evalLiquidityAddDeltaArgs (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g)) - (uniswapV3PoolLookupLiquidityAddDelta v) - (by - change bindParams? liquidityAddDeltaFunction.params - (liquidityAddDeltaArgValues x y) = some (liquidityAddDeltaStore x y) - exact liquidityAddDelta_bindParams x y) - hbody - simpa [burnTickUpdateLowerAfterLiquidityGrossAfterFrame, resumeAfterInternalCall, - collapseReturns, x, y, z] using hstmt - -theorem uniswapV3PoolTickUpdateLowerSourceLiquidityAddDeltaRevertStep - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hreq : - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt σ I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ I) : - ExecStmt (config v) (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.internalCall "liquidityAddDelta" - [.var "liquidityGrossBefore", .var "liquidityDelta"] "liquidityGrossAfter") - .reverted := by - let x := burnTickUpdateLowerLiquidityGrossBeforeInt σ I - let y := burnTickUpdateLowerLiquidityDeltaInt I - have hbody : - ExecFuncBody (config v) - { (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I) with - locals := liquidityAddDeltaStore x y } - (initState cA gh bl σ σ₀ g A I) liquidityAddDeltaFunction.body - .reverted := by - have hy : y < 0 := by - simpa [y] using burnTickUpdateLowerLiquidityDeltaNegative I hnonzero - have hreq' : ¬ liquidityAddDeltaWrappedSub x y < x := by - simpa [x, y, burnTickUpdateLowerLiquidityGrossAfterSubInt] using hreq - simpa [liquidityAddDeltaFrame] using - uniswapV3PoolLiquidityAddDeltaSourceNegativeReverts - (v := v) (evm := initState cA gh bl σ σ₀ g A I) - (x := x) (y := y) hy hreq' - exact internalCallFunctionRevert (callee := liquidityAddDeltaFunction) - (argVals := burnTickUpdateLowerLiquidityAddDeltaArgValues σ I) - (locals := liquidityAddDeltaStore x y) - (burnTickUpdateLower_evalLiquidityAddDeltaArgs (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g)) - (uniswapV3PoolLookupLiquidityAddDelta v) - (by - change bindParams? liquidityAddDeltaFunction.params - (liquidityAddDeltaArgValues x y) = some (liquidityAddDeltaStore x y) - exact liquidityAddDelta_bindParams x y) - hbody - -theorem uniswapV3PoolTickUpdateLowerSourceThroughLiquidityAddDeltaReturnPrefix - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hreq : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ I) : - ExecBlock (config v) (burnTickUpdateLowerFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "info" (ticksRef (.var "tick")), - .letDecl "liquidityGrossBefore" (some uint128) - (.field (.var "info") "liquidityGross"), - .internalCall "liquidityAddDelta" - [.var "liquidityGrossBefore", .var "liquidityDelta"] "liquidityGrossAfter" ] - (.ok (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := uniswapV3PoolTickUpdateLowerSourcePrefix - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) - have htail : - ExecBlock (config v) (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .internalCall "liquidityAddDelta" - [.var "liquidityGrossBefore", .var "liquidityDelta"] "liquidityGrossAfter" ] - (.ok (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecBlock.consNormal - (uniswapV3PoolTickUpdateLowerSourceLiquidityAddDeltaReturnStep - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hnonzero hreq) - ExecBlock.nil - simpa using execBlock_append hprefix htail - -theorem uniswapV3PoolTickUpdateLowerSourceLiquidityAddDeltaRevertPrefix - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hreq : - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt σ I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ I) - (rest : List Stmt) : - ExecBlock (config v) (burnTickUpdateLowerFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.letStorage "info" (ticksRef (.var "tick")) :: - .letDecl "liquidityGrossBefore" (some uint128) - (.field (.var "info") "liquidityGross") :: - .internalCall "liquidityAddDelta" - [.var "liquidityGrossBefore", .var "liquidityDelta"] "liquidityGrossAfter" :: - rest) - .reverted := by - have hprefix := uniswapV3PoolTickUpdateLowerSourcePrefix - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) - have htail : - ExecBlock (config v) (burnTickUpdateLowerAfterLiquidityGrossBeforeFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.internalCall "liquidityAddDelta" - [.var "liquidityGrossBefore", .var "liquidityDelta"] "liquidityGrossAfter" :: - rest) - .reverted := by - exact ExecBlock.consRevert - (uniswapV3PoolTickUpdateLowerSourceLiquidityAddDeltaRevertStep - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hnonzero hreq) - simpa using execBlock_append hprefix htail - -theorem uniswapV3PoolTickUpdateLowerSourceMaxLiquidityStep - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hle : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ I <= v.maxLiquidityPerTick) : - ExecStmt (config v) (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.require (leE (.var "liquidityGrossAfter") (.var "maxLiquidity"))) - (.ok (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecStmt.requireTrue - (burnTickUpdateLower_evalLiquidityGrossAfterLeMaxTrue - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hle) - -theorem uniswapV3PoolTickUpdateLowerSourceMaxLiquidityRevertStep - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hle : - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt σ I <= v.maxLiquidityPerTick) : - ExecStmt (config v) (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.require (leE (.var "liquidityGrossAfter") (.var "maxLiquidity"))) - .reverted := by - exact ExecStmt.requireFalse - (burnTickUpdateLower_evalLiquidityGrossAfterLeMaxFalse - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hle) - -theorem uniswapV3PoolTickUpdateLowerSourceFlippedStep - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} : - ExecStmt (config v) (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.letDecl "flipped" (some boolTy) - (neE (eqE (.var "liquidityGrossAfter") (.intLit 0)) - (eqE (.var "liquidityGrossBefore") (.intLit 0)))) - (.ok (burnTickUpdateLowerAfterFlippedFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecStmt.letDecl - (burnTickUpdateLower_evalFlipped - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g)) - -theorem uniswapV3PoolTickUpdateLowerSourceLiquidityGrossBeforeNonzeroStep - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hbefore : burnTickUpdateLowerLiquidityGrossBeforeInt σ I ≠ 0) : - ExecStmt (config v) (burnTickUpdateLowerAfterFlippedFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (Stmt.ite (eqE (.var "liquidityGrossBefore") (.intLit 0)) - [ Stmt.ite (leE (.var "tick") (.var "tickCurrent")) - [ .assign .storage { base := "info", steps := [.field "feeGrowthOutside0X128"] } - (.var "feeGrowthGlobal0X128"), - .assign .storage { base := "info", steps := [.field "feeGrowthOutside1X128"] } - (.var "feeGrowthGlobal1X128"), - .assign .storage - { base := "info", steps := [.field "secondsPerLiquidityOutsideX128"] } - (.var "secondsPerLiquidityCumulativeX128"), - .assign .storage { base := "info", steps := [.field "tickCumulativeOutside"] } - (.var "tickCumulative"), - .assign .storage { base := "info", steps := [.field "secondsOutside"] } - (.var "time") ] - [], - .assign .storage { base := "info", steps := [.field "initialized"] } (.boolLit true) ] - []) - (.ok (burnTickUpdateLowerAfterFlippedFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecStmt.iteFalse - (burnTickUpdateLower_evalLiquidityGrossBeforeEqZeroFalse - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hbefore) - ExecBlock.nil - -theorem uniswapV3PoolTickUpdateLowerSourceThroughMaxLiquidity - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hdelta : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ I) - (hle : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ I <= v.maxLiquidityPerTick) : - ExecBlock (config v) (burnTickUpdateLowerFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "info" (ticksRef (.var "tick")), - .letDecl "liquidityGrossBefore" (some uint128) - (.field (.var "info") "liquidityGross"), - .internalCall "liquidityAddDelta" - [.var "liquidityGrossBefore", .var "liquidityDelta"] "liquidityGrossAfter", - .require (leE (.var "liquidityGrossAfter") (.var "maxLiquidity")) ] - (.ok (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := uniswapV3PoolTickUpdateLowerSourceThroughLiquidityAddDeltaReturnPrefix - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hnonzero hdelta - have htail : - ExecBlock (config v) (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .require (leE (.var "liquidityGrossAfter") (.var "maxLiquidity")) ] - (.ok (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecBlock.consNormal - (uniswapV3PoolTickUpdateLowerSourceMaxLiquidityStep - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hle) - ExecBlock.nil - simpa using execBlock_append hprefix htail - -theorem uniswapV3PoolTickUpdateLowerSourceThroughFlipped - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hdelta : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ I) - (hle : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ I <= v.maxLiquidityPerTick) : - ExecBlock (config v) (burnTickUpdateLowerFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "info" (ticksRef (.var "tick")), - .letDecl "liquidityGrossBefore" (some uint128) - (.field (.var "info") "liquidityGross"), - .internalCall "liquidityAddDelta" - [.var "liquidityGrossBefore", .var "liquidityDelta"] "liquidityGrossAfter", - .require (leE (.var "liquidityGrossAfter") (.var "maxLiquidity")), - .letDecl "flipped" (some boolTy) - (neE (eqE (.var "liquidityGrossAfter") (.intLit 0)) - (eqE (.var "liquidityGrossBefore") (.intLit 0))) ] - (.ok (burnTickUpdateLowerAfterFlippedFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := uniswapV3PoolTickUpdateLowerSourceThroughMaxLiquidity - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hnonzero hdelta hle - have htail : - ExecBlock (config v) (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .letDecl "flipped" (some boolTy) - (neE (eqE (.var "liquidityGrossAfter") (.intLit 0)) - (eqE (.var "liquidityGrossBefore") (.intLit 0))) ] - (.ok (burnTickUpdateLowerAfterFlippedFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecBlock.consNormal - (uniswapV3PoolTickUpdateLowerSourceFlippedStep - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g)) - ExecBlock.nil - simpa using execBlock_append hprefix htail - -theorem uniswapV3PoolTickUpdateLowerSourceThroughLiquidityGrossBeforeNonzero - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hdelta : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ I) - (hle : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ I <= v.maxLiquidityPerTick) - (hbefore : burnTickUpdateLowerLiquidityGrossBeforeInt σ I ≠ 0) : - ExecBlock (config v) (burnTickUpdateLowerFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .letStorage "info" (ticksRef (.var "tick")), - .letDecl "liquidityGrossBefore" (some uint128) - (.field (.var "info") "liquidityGross"), - .internalCall "liquidityAddDelta" - [.var "liquidityGrossBefore", .var "liquidityDelta"] "liquidityGrossAfter", - .require (leE (.var "liquidityGrossAfter") (.var "maxLiquidity")), - .letDecl "flipped" (some boolTy) - (neE (eqE (.var "liquidityGrossAfter") (.intLit 0)) - (eqE (.var "liquidityGrossBefore") (.intLit 0))), - Stmt.ite (eqE (.var "liquidityGrossBefore") (.intLit 0)) - [ Stmt.ite (leE (.var "tick") (.var "tickCurrent")) - [ .assign .storage { base := "info", steps := [.field "feeGrowthOutside0X128"] } - (.var "feeGrowthGlobal0X128"), - .assign .storage { base := "info", steps := [.field "feeGrowthOutside1X128"] } - (.var "feeGrowthGlobal1X128"), - .assign .storage - { base := "info", steps := [.field "secondsPerLiquidityOutsideX128"] } - (.var "secondsPerLiquidityCumulativeX128"), - .assign .storage { base := "info", steps := [.field "tickCumulativeOutside"] } - (.var "tickCumulative"), - .assign .storage { base := "info", steps := [.field "secondsOutside"] } - (.var "time") ] - [], - .assign .storage { base := "info", steps := [.field "initialized"] } (.boolLit true) ] - [] ] - (.ok (burnTickUpdateLowerAfterFlippedFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - have hprefix := uniswapV3PoolTickUpdateLowerSourceThroughFlipped - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hnonzero hdelta hle - have htail : - ExecBlock (config v) (burnTickUpdateLowerAfterFlippedFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ Stmt.ite (eqE (.var "liquidityGrossBefore") (.intLit 0)) - [ Stmt.ite (leE (.var "tick") (.var "tickCurrent")) - [ .assign .storage - { base := "info", steps := [.field "feeGrowthOutside0X128"] } - (.var "feeGrowthGlobal0X128"), - .assign .storage - { base := "info", steps := [.field "feeGrowthOutside1X128"] } - (.var "feeGrowthGlobal1X128"), - .assign .storage - { base := "info", steps := [.field "secondsPerLiquidityOutsideX128"] } - (.var "secondsPerLiquidityCumulativeX128"), - .assign .storage - { base := "info", steps := [.field "tickCumulativeOutside"] } - (.var "tickCumulative"), - .assign .storage { base := "info", steps := [.field "secondsOutside"] } - (.var "time") ] - [], - .assign .storage { base := "info", steps := [.field "initialized"] } - (.boolLit true) ] - [] ] - (.ok (burnTickUpdateLowerAfterFlippedFrame v σ I) - (initState cA gh bl σ σ₀ g A I)) := by - exact ExecBlock.consNormal - (uniswapV3PoolTickUpdateLowerSourceLiquidityGrossBeforeNonzeroStep - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hbefore) - ExecBlock.nil - simpa using execBlock_append hprefix htail - -theorem uniswapV3PoolTickUpdateLowerSourceMaxLiquidityRevertPrefix - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hdelta : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ I) - (hle : - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt σ I <= v.maxLiquidityPerTick) - (rest : List Stmt) : - ExecBlock (config v) (burnTickUpdateLowerFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.letStorage "info" (ticksRef (.var "tick")) :: - .letDecl "liquidityGrossBefore" (some uint128) - (.field (.var "info") "liquidityGross") :: - .internalCall "liquidityAddDelta" - [.var "liquidityGrossBefore", .var "liquidityDelta"] "liquidityGrossAfter" :: - .require (leE (.var "liquidityGrossAfter") (.var "maxLiquidity")) :: - rest) - .reverted := by - have hprefix := uniswapV3PoolTickUpdateLowerSourceThroughLiquidityAddDeltaReturnPrefix - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hnonzero hdelta - have htail : - ExecBlock (config v) (burnTickUpdateLowerAfterLiquidityGrossAfterFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (.require (leE (.var "liquidityGrossAfter") (.var "maxLiquidity")) :: rest) - .reverted := by - exact ExecBlock.consRevert - (uniswapV3PoolTickUpdateLowerSourceMaxLiquidityRevertStep - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hle) - simpa using execBlock_append hprefix htail - -theorem uniswapV3PoolModifyPositionSourceLowerLiquidityAddDeltaReverts - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hbound : (slot0ObservationIndexWord σ I).toNat < 65535) - (hsame : - .int (Int.ofNat (burnObserveSingleBlockTimestampWord σ I).toNat) = - burnBlockTimestamp32Value I) - (hreq : - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt σ I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ I) : - ExecFuncBody (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (modifyPositionFunction v).body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolModifyPositionSourceThroughFeeGrowthGlobals (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard htickLt hge hle - have htickBody : - ExecFuncBody (config v) (burnTickUpdateLowerFrame v σ I) - (initState cA gh bl σ σ₀ g A I) tickUpdateFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [tickUpdateFunction] using - uniswapV3PoolTickUpdateLowerSourceLiquidityAddDeltaRevertPrefix - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hnonzero hreq - [ .require (leE (.var "liquidityGrossAfter") (.var "maxLiquidity")), - .letDecl "flipped" (some boolTy) - (neE (eqE (.var "liquidityGrossAfter") (.intLit 0)) - (eqE (.var "liquidityGrossBefore") (.intLit 0))), - Stmt.ite (eqE (.var "liquidityGrossBefore") (.intLit 0)) - [ Stmt.ite (leE (.var "tick") (.var "tickCurrent")) - [ .assign .storage { base := "info", steps := [.field "feeGrowthOutside0X128"] } - (.var "feeGrowthGlobal0X128"), - .assign .storage { base := "info", steps := [.field "feeGrowthOutside1X128"] } - (.var "feeGrowthGlobal1X128"), - .assign .storage - { base := "info", steps := [.field "secondsPerLiquidityOutsideX128"] } - (.var "secondsPerLiquidityCumulativeX128"), - .assign .storage { base := "info", steps := [.field "tickCumulativeOutside"] } - (.var "tickCumulative"), - .assign .storage { base := "info", steps := [.field "secondsOutside"] } - (.var "time") ] - [], - .assign .storage { base := "info", steps := [.field "initialized"] } - (.boolLit true) ] - [], - .assign .storage { base := "info", steps := [.field "liquidityGross"] } - (.var "liquidityGrossAfter"), - .assign .storage { base := "info", steps := [.field "liquidityNet"] } - (.inRange int128Int - (.ite (.var "upper") - (subE (.field (.var "info") "liquidityNet") (.var "liquidityDelta")) - (addE (.field (.var "info") "liquidityNet") (.var "liquidityDelta")))), - .return [.var "flipped"] ] - have hstep : - ExecBlock (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (burnModifyPositionLiquidityDeltaUpdateStep v) .reverted := by - refine ExecBlock.consRevert ?_ - refine ExecStmt.iteTrue ?_ ?_ - · exact burnEvalLiquidityDeltaNeZeroTrue (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hnonzero - · refine ExecBlock.consNormal - (solm' := burnModifyPositionAfterTimeFrame v σ I) - (evm' := initState cA gh bl σ σ₀ g A I) ?_ ?_ - · exact ExecStmt.letDecl (burnEvalBlockTimestamp32AfterFeeGlobals (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g)) - · refine ExecBlock.consNormal - (uniswapV3PoolModifyPositionSourceObserveSingleTimestampEqualStep - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hbound hsame) ?_ - refine ExecBlock.consRevert ?_ - refine internalCallFunctionRevert (callee := tickUpdateFunction) - (argVals := burnTickUpdateLowerArgValues v σ I) - (locals := burnTickUpdateLowerStore v σ I) ?_ ?_ ?_ ?_ - · exact burnModifyPosition_evalLowerTickUpdateArgsAfterObserveSingle - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) - · simpa [burnModifyPositionAfterObserveSingleFrame] using - uniswapV3PoolLookupTickUpdate v - · exact burnTickUpdateLower_bindParams v σ I - · exact htickBody - have hmid := execBlock_append hprefix hstep - have hfull := execBlock_append_term (s2 := burnModifyPositionAfterLiquidityDeltaTail v) - hmid (by intro f e h; cases h) - simpa [modifyPositionFunction, burnModifyPositionSlot0Prefix, - burnModifyPositionPositionKeyStep, burnModifyPositionFeeGrowthGlobalsStep, - burnModifyPositionLiquidityDeltaUpdateStep, burnModifyPositionAfterLiquidityDeltaTail] - using hfull - -theorem uniswapV3PoolBurnSourceLowerLiquidityAddDeltaReverts - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : burnUnlockedByte σ I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hbound : - (slot0ObservationIndexWord - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I).toNat < 65535) - (hsame : - .int (Int.ofNat (burnObserveSingleBlockTimestampWord - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I).toNat) = - burnBlockTimestamp32Value I) - (hreq : - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I < - burnTickUpdateLowerLiquidityGrossBeforeInt - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (burnStore I) burnTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolBurnSourceThroughLiquidityDelta (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hunlocked hcanon - have hlockState : - Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I) = - initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - σ₀ g A I := by - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have hstmt : - ExecStmt (config v) (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - (.internalCall "modifyPosition" - [.env .caller, .var "tickLower", .var "tickUpper", .var "liquidityDelta"] - "modified") - .reverted := by - rw [hlockState] - refine internalCallFunctionRevert (callee := modifyPositionFunction v) - (argVals := burnModifyPositionArgValues I) (locals := burnModifyPositionStore I) - ?_ ?_ ?_ ?_ - · have hLower := burnLiquidityDeltaFrame_tickLower (v := v) I - have hUpper := burnLiquidityDeltaFrame_tickUpper (v := v) I - have hDelta := burnLiquidityDeltaFrame_liquidityDelta (v := v) I - simp only [burnModifyPositionArgValues, evalExprs?, evalExpr?, envValue, initState, - EvalResult.bind, bind, pure] - rw [hLower, hUpper, hDelta] - rfl - · simpa [burnLiquidityDeltaFrame] using uniswapV3PoolLookupModifyPosition v - · rfl - · exact uniswapV3PoolModifyPositionSourceLowerLiquidityAddDeltaReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) - (σ := sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - (σ₀ := σ₀) (A := A) (I := I) (g := g) - hguard htickLt hge hle hnonzero hbound hsame hreq - simpa [burnTransition, nonpayable, lockPrefix] using - execBlock_append hprefix (ExecBlock.consRevert hstmt) - -theorem uniswapV3PoolModifyPositionSourceLowerMaxLiquidityReverts - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hbound : (slot0ObservationIndexWord σ I).toNat < 65535) - (hsame : - .int (Int.ofNat (burnObserveSingleBlockTimestampWord σ I).toNat) = - burnBlockTimestamp32Value I) - (hdelta : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ I) - (hmax : - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt σ I <= v.maxLiquidityPerTick) : - ExecFuncBody (config v) { contract := contract v, locals := burnModifyPositionStore I } - (initState cA gh bl σ σ₀ g A I) (modifyPositionFunction v).body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolModifyPositionSourceThroughFeeGrowthGlobals (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hguard htickLt hge hle - have htickBody : - ExecFuncBody (config v) (burnTickUpdateLowerFrame v σ I) - (initState cA gh bl σ σ₀ g A I) tickUpdateFunction.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - simpa [tickUpdateFunction] using - uniswapV3PoolTickUpdateLowerSourceMaxLiquidityRevertPrefix - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hnonzero hdelta hmax - [ .letDecl "flipped" (some boolTy) - (neE (eqE (.var "liquidityGrossAfter") (.intLit 0)) - (eqE (.var "liquidityGrossBefore") (.intLit 0))), - Stmt.ite (eqE (.var "liquidityGrossBefore") (.intLit 0)) - [ Stmt.ite (leE (.var "tick") (.var "tickCurrent")) - [ .assign .storage { base := "info", steps := [.field "feeGrowthOutside0X128"] } - (.var "feeGrowthGlobal0X128"), - .assign .storage { base := "info", steps := [.field "feeGrowthOutside1X128"] } - (.var "feeGrowthGlobal1X128"), - .assign .storage - { base := "info", steps := [.field "secondsPerLiquidityOutsideX128"] } - (.var "secondsPerLiquidityCumulativeX128"), - .assign .storage { base := "info", steps := [.field "tickCumulativeOutside"] } - (.var "tickCumulative"), - .assign .storage { base := "info", steps := [.field "secondsOutside"] } - (.var "time") ] - [], - .assign .storage { base := "info", steps := [.field "initialized"] } - (.boolLit true) ] - [], - .assign .storage { base := "info", steps := [.field "liquidityGross"] } - (.var "liquidityGrossAfter"), - .assign .storage { base := "info", steps := [.field "liquidityNet"] } - (.inRange int128Int - (.ite (.var "upper") - (subE (.field (.var "info") "liquidityNet") (.var "liquidityDelta")) - (addE (.field (.var "info") "liquidityNet") (.var "liquidityDelta")))), - .return [.var "flipped"] ] - have hstep : - ExecBlock (config v) (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - (burnModifyPositionLiquidityDeltaUpdateStep v) .reverted := by - refine ExecBlock.consRevert ?_ - refine ExecStmt.iteTrue ?_ ?_ - · exact burnEvalLiquidityDeltaNeZeroTrue (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hnonzero - · refine ExecBlock.consNormal - (solm' := burnModifyPositionAfterTimeFrame v σ I) - (evm' := initState cA gh bl σ σ₀ g A I) ?_ ?_ - · exact ExecStmt.letDecl (burnEvalBlockTimestamp32AfterFeeGlobals (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g)) - · refine ExecBlock.consNormal - (uniswapV3PoolModifyPositionSourceObserveSingleTimestampEqualStep - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) hbound hsame) ?_ - refine ExecBlock.consRevert ?_ - refine internalCallFunctionRevert (callee := tickUpdateFunction) - (argVals := burnTickUpdateLowerArgValues v σ I) - (locals := burnTickUpdateLowerStore v σ I) ?_ ?_ ?_ ?_ - · exact burnModifyPosition_evalLowerTickUpdateArgsAfterObserveSingle - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (I := I) (g := g) - · simpa [burnModifyPositionAfterObserveSingleFrame] using - uniswapV3PoolLookupTickUpdate v - · exact burnTickUpdateLower_bindParams v σ I - · exact htickBody - have hmid := execBlock_append hprefix hstep - have hfull := execBlock_append_term (s2 := burnModifyPositionAfterLiquidityDeltaTail v) - hmid (by intro f e h; cases h) - simpa [modifyPositionFunction, burnModifyPositionSlot0Prefix, - burnModifyPositionPositionKeyStep, burnModifyPositionFeeGrowthGlobalsStep, - burnModifyPositionLiquidityDeltaUpdateStep, burnModifyPositionAfterLiquidityDeltaTail] - using hfull - -theorem uniswapV3PoolBurnSourceLowerMaxLiquidityReverts - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : burnUnlockedByte σ I ≠ ⟨0⟩) - (hcanon : - UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hge : ¬ tickSpacingSint24Value (burnTickLowerWord I) < (-887272 : Int)) - (hle : ¬ (887272 : Int) < tickSpacingSint24Value (burnTickUpperWord I)) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hbound : - (slot0ObservationIndexWord - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I).toNat < 65535) - (hsame : - .int (Int.ofNat (burnObserveSingleBlockTimestampWord - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I).toNat) = - burnBlockTimestamp32Value I) - (hdelta : - burnTickUpdateLowerLiquidityGrossAfterSubInt - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I < - burnTickUpdateLowerLiquidityGrossBeforeInt - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I) - (hmax : - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) I <= - v.maxLiquidityPerTick) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (burnStore I) burnTransition.body .reverted := by - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolBurnSourceThroughLiquidityDelta (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hwv hunlocked hcanon - have hlockState : - Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I) = - initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - σ₀ g A I := by - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have hstmt : - ExecStmt (config v) (burnLiquidityDeltaFrame v I) - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (burnLockedSlotWord σ I)) - (.internalCall "modifyPosition" - [.env .caller, .var "tickLower", .var "tickUpper", .var "liquidityDelta"] - "modified") - .reverted := by - rw [hlockState] - refine internalCallFunctionRevert (callee := modifyPositionFunction v) - (argVals := burnModifyPositionArgValues I) (locals := burnModifyPositionStore I) - ?_ ?_ ?_ ?_ - · have hLower := burnLiquidityDeltaFrame_tickLower (v := v) I - have hUpper := burnLiquidityDeltaFrame_tickUpper (v := v) I - have hDelta := burnLiquidityDeltaFrame_liquidityDelta (v := v) I - simp only [burnModifyPositionArgValues, evalExprs?, evalExpr?, envValue, initState, - EvalResult.bind, bind, pure] - rw [hLower, hUpper, hDelta] - rfl - · simpa [burnLiquidityDeltaFrame] using uniswapV3PoolLookupModifyPosition v - · rfl - · exact uniswapV3PoolModifyPositionSourceLowerMaxLiquidityReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) - (σ := sstoreAccountMap I.codeOwner σ ⟨0⟩ (burnLockedSlotWord σ I)) - (σ₀ := σ₀) (A := A) (I := I) (g := g) - hguard htickLt hge hle hnonzero hbound hsame hdelta hmax - simpa [burnTransition, nonpayable, lockPrefix] using - execBlock_append hprefix (ExecBlock.consRevert hstmt) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnTickUpdateStart.lean b/Benchmarks/UniswapV3Pool/BurnTickUpdateStart.lean deleted file mode 100644 index 84d9fc71..00000000 --- a/Benchmarks/UniswapV3Pool/BurnTickUpdateStart.lean +++ /dev/null @@ -1,581 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnObserveSingle -import Benchmarks.UniswapV3Pool.BurnTickGetFeeGrowthInsideSource -import Benchmarks.UniswapV3Pool.InitializeGetTickLog -import Benchmarks.UniswapV3Pool.SetFeeProtocolOwnerCall - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem uniswapV3PoolBurnPostObservePatchDisjoint {v : PoolImmutables} - {pc : UInt256} {n : Nat} (hlo : 19273 ≤ pc.toNat) - (hhi : pc.toNat + n ≤ 19350) - (havoid : pc.toNat + n ≤ 19295 ∨ 19327 ≤ pc.toNat) : - ∀ p ∈ patches v, pc.toNat + n ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolBurnPostObserveMaxLiquidityPatchWord19295 - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - code.extract 19295 19327 = - UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick) := by - let value := UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick) - let pre : List (Nat × ByteArray) := - [(8315, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (8829, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (10457, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (2258, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4853, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (6740, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (7822, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (9150, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (15650, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4551, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (6789, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (7924, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (9284, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (10529, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (15979, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (3311, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6603, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6658, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (10565, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (3072, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (10493, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19402, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19452, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (8174, value)] - let post : List (Nat × ByteArray) := - [(19350, value), (11259, UInt256.toByteArray (EVM.Word.ofNat v.original.toNat))] - have hpatch' : patchRuntime uniswapV3PoolBytecode (pre ++ (19295, value) :: post) = - some code := by - dsimp [pre, post, value] - simpa [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup, toByteArray_eq_toBytesBE] using hpatch - have hpost : ∀ p ∈ post, 19295 + 32 ≤ p.1 ∨ p.1 + 32 ≤ 19295 := by - intro p hp - dsimp [post] at hp - simp at hp - rcases hp with rfl | rfl - all_goals omega - have hsize : value.size = 32 := by - dsimp [value] - exact toByteArray_size _ - exact patchRuntime_extract_patch hsize hpost hpatch' - -private theorem uniswapV3PoolBurnPostObserveMaxLiquidityConstDecode19294 - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨19294⟩ = - some (.Push .PUSH32, some (EVM.wordOfInt v.maxLiquidityPerTick, 32)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have hget : code.get? ({ val := 19294 } : UInt256).toNat = - uniswapV3PoolBytecode.get? ({ val := 19294 } : UInt256).toNat := by - change code.get? 19294 = uniswapV3PoolBytecode.get? 19294 - apply get?_eq_of_extract_one - · rw [hsize] - native_decide - · native_decide - · exact patchRuntime_extract_eq (start := 19294) (stop := 19295) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by native_decide) - (fun p hp => by - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl - all_goals omega) hpatch - have hextract : code.extract' ({ val := 19294 } : UInt256).toNat.succ - (({ val := 19294 } : UInt256).toNat.succ + 32) = - UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick) := by - change code.extract' 19295 19327 = - UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick) - unfold ByteArray.extract' - have hguard : (decide (19295 < 2 ^ 64) && decide (19327 < 2 ^ 64)) = true := by - native_decide - rw [if_pos hguard] - exact uniswapV3PoolBurnPostObserveMaxLiquidityPatchWord19295 hpatch - have hgetSome : code.get? ({ val := 19294 } : UInt256).toNat = some 0x7f := by - rw [hget] - native_decide - have hparse : (some (0x7f : UInt8) >>= parseInstr) = some (.Push .PUSH32) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH32, - some (uInt256OfByteArray - (code.extract' ({ val := 19294 } : UInt256).toNat.succ - (({ val := 19294 } : UInt256).toNat.succ + 32)), 32)) = - some (Operation.Push Operation.POp.PUSH32, - some (EVM.wordOfInt v.maxLiquidityPerTick, 32)) - rw [hextract, uInt256OfByteArray_eq, fromByteArrayBigEndian_toByteArray, - u256_ofNat_toNat] - -private theorem uniswapV3PoolBurnPostObservePatchPreservesJumpDest20795 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨20795⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolBurnJumpDestPatched20795 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨20795⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolBurnPostObservePatchPreservesJumpDest20795 - -theorem uniswapV3PoolBurnPostObserveSingleToLowerTickUpdate - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {seconds tick z0 z1 time z2 z3 feeGrowthGlobal1 feeGrowthGlobal0 positionBase - slot0Tick liquidityDelta tickUpper tickLower source : UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨19273⟩ - (seconds :: tick :: z0 :: z1 :: time :: z2 :: z3 :: - feeGrowthGlobal1 :: feeGrowthGlobal0 :: positionBase :: slot0Tick :: - liquidityDelta :: tickUpper :: tickLower :: source :: R) - mem aw rdata (cA, σ) k C) - (hov : R.length + 43 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨20795⟩ - (EVM.wordOfInt v.maxLiquidityPerTick :: ⟨0⟩ :: time :: tick :: seconds :: - feeGrowthGlobal1 :: feeGrowthGlobal0 :: liquidityDelta :: slot0Tick :: - tickLower :: ⟨5⟩ :: ⟨19331⟩ :: seconds :: tick :: time :: z2 :: z3 :: - feeGrowthGlobal1 :: feeGrowthGlobal0 :: positionBase :: slot0Tick :: - liquidityDelta :: tickUpper :: tickLower :: source :: R) - mem aw rdata (cA, σ) k' C' := by - have hd19273 : decode code ⟨19273⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19273⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19273⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19274 : decode code ⟨19274⟩ = some (.SWAP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19274⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19274⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19275 : decode code ⟨19275⟩ = some (.SWAP3, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19275⟩) (byte := 0x92) - (op := .SWAP3) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19275⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19276 : decode code ⟨19276⟩ = some (.POP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19276⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19276⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19277 : decode code ⟨19277⟩ = some (.SWAP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19277⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19277⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19278 : decode code ⟨19278⟩ = some (.POP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19278⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19278⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19279 : decode code ⟨19279⟩ = - some (.Push .PUSH2, some (⟨19331⟩, 2)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush2 hpatch - (by native_decide) - (uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19279⟩) (n := 3) (by native_decide) (by native_decide) - (Or.inl (by native_decide))) - (by native_decide) (by native_decide) - have hd19282 : decode code ⟨19282⟩ = - some (.Push .PUSH1, some (⟨5⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 hpatch - (by native_decide) - (uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19282⟩) (n := 2) (by native_decide) (by native_decide) - (Or.inl (by native_decide))) - (by native_decide) (by native_decide) - have hd19284 : decode code ⟨19284⟩ = some (.DUP14, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19284⟩) (byte := 0x8d) - (op := .DUP14) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19284⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19285 : decode code ⟨19285⟩ = some (.DUP12, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19285⟩) (byte := 0x8b) - (op := .DUP12) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19285⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19286 : decode code ⟨19286⟩ = some (.DUP14, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19286⟩) (byte := 0x8d) - (op := .DUP14) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19286⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19287 : decode code ⟨19287⟩ = some (.DUP12, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19287⟩) (byte := 0x8b) - (op := .DUP12) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19287⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19288 : decode code ⟨19288⟩ = some (.DUP12, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19288⟩) (byte := 0x8b) - (op := .DUP12) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19288⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19289 : decode code ⟨19289⟩ = some (.DUP8, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19289⟩) (byte := 0x87) - (op := .DUP8) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19289⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19290 : decode code ⟨19290⟩ = some (.DUP10, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19290⟩) (byte := 0x89) - (op := .DUP10) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19290⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19291 : decode code ⟨19291⟩ = some (.DUP12, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19291⟩) (byte := 0x8b) - (op := .DUP12) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19291⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inl (by native_decide)) - have hd19292 : decode code ⟨19292⟩ = - some (.Push .PUSH1, some (⟨0⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 hpatch - (by native_decide) - (uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19292⟩) (n := 2) (by native_decide) (by native_decide) - (Or.inl (by native_decide))) - (by native_decide) (by native_decide) - have hd19294 := uniswapV3PoolBurnPostObserveMaxLiquidityConstDecode19294 hpatch - have hd19327 : decode code ⟨19327⟩ = - some (.Push .PUSH2, some (⟨20795⟩, 2)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush2 hpatch - (by native_decide) - (uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19327⟩) (n := 3) (by native_decide) (by native_decide) - (Or.inr (by native_decide))) - (by native_decide) (by native_decide) - have hd19330 : decode code ⟨19330⟩ = some (.JUMP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨19330⟩) (byte := 0x56) - (op := .JUMP) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - exact uniswapV3PoolBurnPostObservePatchDisjoint - (pc := ⟨19330⟩) (n := 1) (by native_decide) (by native_decide) - (Or.inr (by native_decide)) - have h19284 := evm_run h with [ - raw jumpdest hd19273 (by evm_ov), - raw swap1 hd19274 (by evm_ov), - raw swap3 hd19275 (by evm_ov), - raw pop hd19276 (by evm_ov), - raw swap1 hd19277 (by evm_ov), - raw pop hd19278 (by evm_ov), - raw push2 ⟨19331⟩ hd19279 (by evm_ov), - raw push1 ⟨5⟩ hd19282 (by evm_ov)] - have h19285 := by - simpa using h19284.dup14 hd19284 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h19286 := by - simpa using RD.dup12 h19285 hd19285 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h19287 := by - simpa using h19286.dup14 hd19286 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h19288 := by - simpa using RD.dup12 h19287 hd19287 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h19289 := by - simpa using RD.dup12 h19288 hd19288 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h19290 := by - simpa using h19289.dup8 hd19289 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h19291 := by - simpa using h19290.dup10 hd19290 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h19292 := by - simpa using RD.dup12 h19291 hd19291 (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h19294 := evm_run h19292 with [ - raw push1 ⟨0⟩ hd19292 (by evm_ov)] - have h19327 := by - simpa using - h19294.pushConst (EVM.wordOfInt v.maxLiquidityPerTick) - (by native_decide : Operation.POp.PUSH32 ≠ .PUSH0) hd19294 - (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - have h19330 := evm_run h19327 with [ - raw push2 ⟨20795⟩ hd19327 (by evm_ov)] - exact ⟨_, _, h19330.jump hd19330 (uniswapV3PoolBurnJumpDestPatched20795 hpatch) - (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega)⟩ - -theorem uniswapV3PoolBurnObserveSingleTimestampEqualToLowerTickUpdate - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {obsWord cardinality liquidity index currentTick time z0 z1 callerTime z2 z3 - feeGrowthGlobal1 feeGrowthGlobal0 positionBase slot0Tick liquidityDelta - tickUpper tickLower source : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13242⟩ - (obsWord :: burnPositionKeyNewFreePtrWord :: ⟨64⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - cardinality :: liquidity :: index :: currentTick :: ⟨0⟩ :: time :: ⟨8⟩ :: - ⟨19273⟩ :: z0 :: z1 :: callerTime :: z2 :: z3 :: feeGrowthGlobal1 :: - feeGrowthGlobal0 :: positionBase :: slot0Tick :: liquidityDelta :: tickUpper :: - tickLower :: source :: R) - (burnObserveSingleAllocMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (heq : UInt256.eq (UInt256.land time observationsUint32Mask) - (burnObserveSingleDecodedBlockWord obsWord) ≠ ⟨0⟩) - (hov : R.length + 55 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨20795⟩ - (EVM.wordOfInt v.maxLiquidityPerTick :: ⟨0⟩ :: callerTime :: - burnObserveSingleDecodedTickWord obsWord :: - burnObserveSingleDecodedSecondsWord obsWord :: feeGrowthGlobal1 :: - feeGrowthGlobal0 :: liquidityDelta :: slot0Tick :: tickLower :: ⟨5⟩ :: - ⟨19331⟩ :: burnObserveSingleDecodedSecondsWord obsWord :: - burnObserveSingleDecodedTickWord obsWord :: callerTime :: z2 :: z3 :: - feeGrowthGlobal1 :: feeGrowthGlobal0 :: positionBase :: slot0Tick :: - liquidityDelta :: tickUpper :: tickLower :: source :: R) - (burnObserveSingleDecodedMem σ ee obsWord) (UInt256.ofNat 21) rdata - (cA, σ) k' C' := by - obtain ⟨_, _, hret⟩ := - uniswapV3PoolBurnObserveSingleTimestampEqualLoadedReturn - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (obsWord := obsWord) (cardinality := cardinality) (liquidity := liquidity) - (index := index) (tick := currentTick) (time := time) (ret := ⟨19273⟩) - (R := z0 :: z1 :: callerTime :: z2 :: z3 :: feeGrowthGlobal1 :: - feeGrowthGlobal0 :: positionBase :: slot0Tick :: liquidityDelta :: tickUpper :: - tickLower :: source :: R) - (rdata := rdata) (cA := cA) (σ := σ) hpatch h heq - (uniswapV3PoolBurnJumpDestPatched19273 hpatch) - (by - have hlen := hov - simp only [List.length_cons] at hlen ⊢ - omega) - exact - uniswapV3PoolBurnPostObserveSingleToLowerTickUpdate - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (seconds := burnObserveSingleDecodedSecondsWord obsWord) - (tick := burnObserveSingleDecodedTickWord obsWord) (z0 := z0) (z1 := z1) - (time := callerTime) (z2 := z2) (z3 := z3) - (feeGrowthGlobal1 := feeGrowthGlobal1) (feeGrowthGlobal0 := feeGrowthGlobal0) - (positionBase := positionBase) (slot0Tick := slot0Tick) - (liquidityDelta := liquidityDelta) (tickUpper := tickUpper) - (tickLower := tickLower) (source := source) (R := R) - (mem := burnObserveSingleDecodedMem σ ee obsWord) (aw := UInt256.ofNat 21) - (rdata := rdata) (cA := cA) (σ := σ) hpatch hret (by - have hlen := hov - omega) - -abbrev burnTickUpdateLowerArgValues (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : List Value := - [ burnTickLowerValue I, - burnSlot0TickValue σ I, - burnLiquidityDeltaValue I, - burnFeeGrowthGlobal0Value σ I, - burnFeeGrowthGlobal1Value σ I, - .int (Int.ofNat (burnObserveSingleSecondsPerLiquidityWord σ I).toNat), - wordToElem (.int int56Int) (burnObserveSingleTickStorageWord σ I), - burnBlockTimestamp32Value I, - .bool false, - .int v.maxLiquidityPerTick ] - -abbrev burnTickUpdateLowerStore (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : Store := - ((((((((((∅ : Store) - |>.insert "maxLiquidity" (.int v.maxLiquidityPerTick)) - |>.insert "upper" (.bool false)) - |>.insert "time" (burnBlockTimestamp32Value I)) - |>.insert "tickCumulative" (wordToElem (.int int56Int) - (burnObserveSingleTickStorageWord σ I))) - |>.insert "secondsPerLiquidityCumulativeX128" - (.int (Int.ofNat (burnObserveSingleSecondsPerLiquidityWord σ I).toNat))) - |>.insert "feeGrowthGlobal1X128" (burnFeeGrowthGlobal1Value σ I)) - |>.insert "feeGrowthGlobal0X128" (burnFeeGrowthGlobal0Value σ I)) - |>.insert "liquidityDelta" (burnLiquidityDeltaValue I)) - |>.insert "tickCurrent" (burnSlot0TickValue σ I)) - |>.insert "tick" (burnTickLowerValue I) - -abbrev burnTickUpdateLowerFrame (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : Frame := - { contract := contract v, locals := burnTickUpdateLowerStore v σ I } - -theorem burnTickUpdateLower_bindParams (v : PoolImmutables) (σ : AccountMap) - (I : ExecutionEnv) : - bindParams? tickUpdateFunction.params (burnTickUpdateLowerArgValues v σ I) = - some (burnTickUpdateLowerStore v σ I) := by - rfl - -theorem burnAfterObserveSingleFrame_observedForUpdate {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterObserveSingleFrame v σ I).locals.get? "observedForUpdate" = - some (.tuple (burnObserveSingleTimestampEqualReturnValues σ I)) := by - rw [burnModifyPositionAfterObserveSingleFrame] - exact store_get_self (burnModifyPositionAfterTimeFrame v σ I).locals - "observedForUpdate" (.tuple (burnObserveSingleTimestampEqualReturnValues σ I)) - -theorem burnAfterObserveSingleFrame_time {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterObserveSingleFrame v σ I).locals.get? "time" = - some (burnBlockTimestamp32Value I) := by - rw [burnModifyPositionAfterObserveSingleFrame] - rw [store_get_ne (burnModifyPositionAfterTimeFrame v σ I).locals - (k := "observedForUpdate") (a := "time") - (.tuple (burnObserveSingleTimestampEqualReturnValues σ I)) (by native_decide)] - rw [burnModifyPositionAfterTimeFrame] - exact store_get_self (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals - "time" (burnBlockTimestamp32Value I) - -theorem burnAfterObserveSingleFrame_tickLower {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterObserveSingleFrame v σ I).locals.get? "tickLower" = - some (burnTickLowerValue I) := by - rw [burnModifyPositionAfterObserveSingleFrame] - rw [store_get_ne (burnModifyPositionAfterTimeFrame v σ I).locals - (k := "observedForUpdate") (a := "tickLower") - (.tuple (burnObserveSingleTimestampEqualReturnValues σ I)) (by native_decide)] - rw [burnModifyPositionAfterTimeFrame] - rw [store_get_ne (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals - (k := "time") (a := "tickLower") (burnBlockTimestamp32Value I) - (by native_decide)] - exact burnAfterFeeGrowthGlobalsFrame_tickLower σ I - -theorem burnAfterObserveSingleFrame_slot0tick {v : PoolImmutables} (σ : AccountMap) - (I : ExecutionEnv) : - (burnModifyPositionAfterObserveSingleFrame v σ I).locals.get? "_slot0tick" = - some (burnSlot0TickValue σ I) := by - rw [burnModifyPositionAfterObserveSingleFrame] - rw [store_get_ne (burnModifyPositionAfterTimeFrame v σ I).locals - (k := "observedForUpdate") (a := "_slot0tick") - (.tuple (burnObserveSingleTimestampEqualReturnValues σ I)) (by native_decide)] - rw [burnModifyPositionAfterTimeFrame] - rw [store_get_ne (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals - (k := "time") (a := "_slot0tick") (burnBlockTimestamp32Value I) - (by native_decide)] - exact burnAfterFeeGrowthGlobalsFrame_slot0tick σ I - -theorem burnAfterObserveSingleFrame_liquidityDelta {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterObserveSingleFrame v σ I).locals.get? "liquidityDelta" = - some (burnLiquidityDeltaValue I) := by - rw [burnModifyPositionAfterObserveSingleFrame] - rw [store_get_ne (burnModifyPositionAfterTimeFrame v σ I).locals - (k := "observedForUpdate") (a := "liquidityDelta") - (.tuple (burnObserveSingleTimestampEqualReturnValues σ I)) (by native_decide)] - rw [burnModifyPositionAfterTimeFrame] - rw [store_get_ne (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals - (k := "time") (a := "liquidityDelta") (burnBlockTimestamp32Value I) - (by native_decide)] - exact burnAfterFeeGrowthGlobalsFrame_liquidityDelta σ I - -theorem burnAfterObserveSingleFrame_feeGrowthGlobal0 {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterObserveSingleFrame v σ I).locals.get? - "_feeGrowthGlobal0X128" = some (burnFeeGrowthGlobal0Value σ I) := by - rw [burnModifyPositionAfterObserveSingleFrame] - rw [store_get_ne (burnModifyPositionAfterTimeFrame v σ I).locals - (k := "observedForUpdate") (a := "_feeGrowthGlobal0X128") - (.tuple (burnObserveSingleTimestampEqualReturnValues σ I)) (by native_decide)] - rw [burnModifyPositionAfterTimeFrame] - rw [store_get_ne (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals - (k := "time") (a := "_feeGrowthGlobal0X128") (burnBlockTimestamp32Value I) - (by native_decide)] - exact burnAfterFeeGrowthGlobalsFrame_feeGrowthGlobal0 σ I - -theorem burnAfterObserveSingleFrame_feeGrowthGlobal1 {v : PoolImmutables} - (σ : AccountMap) (I : ExecutionEnv) : - (burnModifyPositionAfterObserveSingleFrame v σ I).locals.get? - "_feeGrowthGlobal1X128" = some (burnFeeGrowthGlobal1Value σ I) := by - rw [burnModifyPositionAfterObserveSingleFrame] - rw [store_get_ne (burnModifyPositionAfterTimeFrame v σ I).locals - (k := "observedForUpdate") (a := "_feeGrowthGlobal1X128") - (.tuple (burnObserveSingleTimestampEqualReturnValues σ I)) (by native_decide)] - rw [burnModifyPositionAfterTimeFrame] - rw [store_get_ne (burnModifyPositionAfterFeeGrowthGlobalsFrame v σ I).locals - (k := "time") (a := "_feeGrowthGlobal1X128") (burnBlockTimestamp32Value I) - (by native_decide)] - exact burnAfterFeeGrowthGlobalsFrame_feeGrowthGlobal1 σ I - -theorem burnModifyPosition_evalLowerTickUpdateArgsAfterObserveSingle - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExprs? (config v) (burnModifyPositionAfterObserveSingleFrame v σ I) - (initState cA gh bl σ σ₀ g A I) - [ .var "tickLower", .var "_slot0tick", .var "liquidityDelta", - .var "_feeGrowthGlobal0X128", .var "_feeGrowthGlobal1X128", - tuple1 (.var "observedForUpdate"), tuple0 (.var "observedForUpdate"), - .var "time", .boolLit false, .intLit v.maxLiquidityPerTick ] = - .ok (burnTickUpdateLowerArgValues v σ I) := by - simp only [burnTickUpdateLowerArgValues, evalExprs?, evalExpr?, tuple0, tuple1, - EvalResult.bind, bind, pure] - rw [burnAfterObserveSingleFrame_tickLower (v := v), - burnAfterObserveSingleFrame_slot0tick (v := v), - burnAfterObserveSingleFrame_liquidityDelta (v := v), - burnAfterObserveSingleFrame_feeGrowthGlobal0 (v := v), - burnAfterObserveSingleFrame_feeGrowthGlobal1 (v := v), - burnAfterObserveSingleFrame_observedForUpdate (v := v), - burnAfterObserveSingleFrame_time (v := v)] - rfl - -theorem uniswapV3PoolLookupTickUpdate (v : PoolImmutables) : - lookupCallable? (contract v) "tickUpdate" = - some tickUpdateFunction.toCallable := by - simp [lookupCallable?, lookupFunction?, contract, functions, getSqrtRatioAtTickFunction, - getTickAtSqrtRatioFunction, oracleLteFunction, oracleTransformFunction, - getSurroundingObservationsFunction, observeSingleFunction, observeBodyFunction, - liquidityAddDeltaFunction, oracleWriteFunction, tickGetFeeGrowthInsideFunction, - tickUpdateFunction, tickClearFunction, tickBitmapFlipFunction, positionUpdateFunction, - getAmount0DeltaUnsignedFunction, getAmount1DeltaUnsignedFunction, - getAmount0DeltaSignedFunction, getAmount1DeltaSignedFunction, modifyPositionFunction] - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnTickUpdateTrace.lean b/Benchmarks/UniswapV3Pool/BurnTickUpdateTrace.lean deleted file mode 100644 index a048ab7b..00000000 --- a/Benchmarks/UniswapV3Pool/BurnTickUpdateTrace.lean +++ /dev/null @@ -1,1753 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnTickUpdateSource - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev burnTickUpdateLowerKeyWord (tickLower : UInt256) : UInt256 := - UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ tickLower) - -abbrev burnTickUpdateLowerBaseSlotWord (tickLower : UInt256) : UInt256 := - solcMappingSlot ⟨5⟩ (burnTickUpdateLowerKeyWord tickLower) - -abbrev burnTickUpdateLowerLoadedWord (σ : AccountMap) (ee : ExecutionEnv) - (tickLower : UInt256) : UInt256 := - solcSlotWord σ ee (burnTickUpdateLowerBaseSlotWord tickLower) - -abbrev burnTickUpdateLowerLiquidityGrossBeforeWordEvm (σ : AccountMap) - (ee : ExecutionEnv) (tickLower : UInt256) : UInt256 := - UInt256.land (burnTickUpdateLowerLoadedWord σ ee tickLower) uint128Mask - -noncomputable abbrev burnTickUpdateLowerHashMem - (tickLower : UInt256) (mem : ByteArray) : ByteArray := - twoWordHashMem (burnTickUpdateLowerKeyWord tickLower) ⟨5⟩ mem - -theorem burnTickUpdateLowerBaseSlotWord_eq_getLowerBaseSlot (I : ExecutionEnv) : - burnTickUpdateLowerBaseSlotWord (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) = - burnTickGetLowerBaseSlot I := by - simp [burnTickUpdateLowerBaseSlotWord, burnTickUpdateLowerKeyWord, - burnTickGetLowerBaseSlot, ticksBase, mapSlot, solcMappingSlot, - keyValueToWord, wordOfInt_sint24Value_eq_signextend_two, - signextend_two_tickSpacing_idempotent] - -theorem burnTickUpdateLowerLiquidityGrossBeforeWord_transport - {σ_evm σ_solm : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - burnTickUpdateLowerLiquidityGrossBeforeWord σ_solm I = - burnTickUpdateLowerLiquidityGrossBeforeWordEvm σ_evm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner - (burnTickGetLowerBaseSlot I) (⟨0⟩ : UInt256) - dsimp [burnTickUpdateLowerLiquidityGrossBeforeWord, - burnTickUpdateLowerLiquidityGrossBeforeWordEvm, burnTickUpdateLowerLoadedWord, - solcSlotWord] - rw [burnTickUpdateLowerBaseSlotWord_eq_getLowerBaseSlot] - rw [← hslot] - -theorem u256_zero_sub_zero_sub {w : UInt256} (hnonzero : w ≠ ⟨0⟩) : - UInt256.sub ⟨0⟩ (UInt256.sub ⟨0⟩ w) = w := by - apply u256_inj - have htoNatNe : w.toNat ≠ 0 := by - intro h - exact hnonzero (uint256_toNat_eq_zero h) - have hpos : 0 < w.toNat := Nat.pos_of_ne_zero htoNatNe - have hsub : (UInt256.sub (⟨0⟩ : UInt256) w).toNat = UInt256.size - w.toNat := by - simpa using usub_toNat_underflow (a := (⟨0⟩ : UInt256)) (b := w) hpos - have hsubPos : 0 < (UInt256.sub (⟨0⟩ : UInt256) w).toNat := by - rw [hsub] - have hwlt : w.toNat < UInt256.size := w.val.isLt - omega - have hsub2 := usub_toNat_underflow (a := (⟨0⟩ : UInt256)) - (b := UInt256.sub (⟨0⟩ : UInt256) w) hsubPos - rw [hsub2, hsub] - change UInt256.size - (UInt256.size - w.toNat) = w.toNat - have hwlt : w.toNat < UInt256.size := w.val.isLt - omega - -theorem signextend_fifteen_zero_sub_eq_of_lt {w : UInt256} - (hnonzero : w ≠ ⟨0⟩) (hlt : w.toNat < EVM.twoPow 127) : - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ w) = UInt256.sub ⟨0⟩ w := by - have htoNatNe : w.toNat ≠ 0 := by - intro h - exact hnonzero (uint256_toNat_eq_zero h) - have hpos : 0 < w.toNat := Nat.pos_of_ne_zero htoNatNe - have hsubNat : (UInt256.sub (⟨0⟩ : UInt256) w).toNat = UInt256.size - w.toNat := by - simpa using usub_toNat_underflow (a := (⟨0⟩ : UInt256)) (b := w) hpos - have hposInt : (0 : Int) < (w.toNat : Int) := by exact_mod_cast hpos - have hneg : -(Int.ofNat w.toNat) < 0 := by - have : (0 : Int) < Int.ofNat w.toNat := by simpa using hposInt - omega - have habs : (-(Int.ofNat w.toNat)).natAbs = w.toNat := by - rw [Int.natAbs_neg] - simp - have hword : UInt256.sub (⟨0⟩ : UInt256) w = - EVM.wordOfInt (-(Int.ofNat w.toNat)) := by - apply u256_inj - rw [hsubNat] - have hltWord : (-(Int.ofNat w.toNat)).natAbs < EVM.wordModulus := by - rw [habs] - rw [show EVM.wordModulus = UInt256.size by native_decide] - exact w.val.isLt - rw [wordOfInt_neg_toNat_lt_wordModulus _ hneg hltWord] - rw [habs] - rw [hword] - exact signextend_fifteen_wordOfInt_ticks (-(Int.ofNat w.toNat)) - (by - norm_num [EVM.twoPow] at hlt ⊢ - omega) - (by - norm_num [EVM.twoPow] at hlt ⊢ - omega) - -theorem u256_zero_sub_signextend_fifteen_zero_sub {w : UInt256} - (hnonzero : w ≠ ⟨0⟩) (hlt : w.toNat < EVM.twoPow 127) : - UInt256.sub ⟨0⟩ (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ w)) = w := by - rw [signextend_fifteen_zero_sub_eq_of_lt hnonzero hlt] - exact u256_zero_sub_zero_sub hnonzero - -theorem liquidityAddDeltaWrappedSub_lt_iff {x a : Nat} - (hx : x < 2 ^ (128 : Nat)) (ha0 : 0 < a) (ha : a < 2 ^ (128 : Nat)) : - liquidityAddDeltaWrappedSub (Int.ofNat x) (0 - Int.ofNat a) < Int.ofNat x ↔ - a ≤ x := by - unfold liquidityAddDeltaWrappedSub - have hsimp : - Int.ofNat x - (0 - (0 - Int.ofNat a)) = Int.ofNat x - Int.ofNat a := by - ring - rw [hsimp] - by_cases hle : a ≤ x - · have hleInt : Int.ofNat a ≤ Int.ofNat x := Int.ofNat_le.mpr hle - have hnonneg : 0 ≤ Int.ofNat x - Int.ofNat a := by omega - have hltm : Int.ofNat x - Int.ofNat a < (2 ^ (128 : Nat) : Int) := by - have hxInt : Int.ofNat x < (2 ^ (128 : Nat) : Int) := Int.ofNat_lt.mpr hx - have haNonneg : (0 : Int) ≤ Int.ofNat a := Int.natCast_nonneg a - omega - rw [Int.emod_eq_of_lt hnonneg hltm] - constructor - · intro _ - exact hle - · intro _ - have haPosInt : (0 : Int) < Int.ofNat a := Int.ofNat_lt.mpr ha0 - omega - · have hgt : x < a := Nat.lt_of_not_ge hle - let m : Int := (2 ^ (128 : Nat) : Int) - have hmodrewrite : (Int.ofNat x - Int.ofNat a) % m = - (Int.ofNat x - Int.ofNat a + 1 * m) % m := by - rw [Int.add_mul_emod_self_right] - rw [hmodrewrite] - have hnonneg : 0 ≤ Int.ofNat x - Int.ofNat a + 1 * m := by - dsimp [m] - have hxNonneg : (0 : Int) ≤ Int.ofNat x := Int.natCast_nonneg x - have haLtInt : Int.ofNat a < (2 ^ (128 : Nat) : Int) := Int.ofNat_lt.mpr ha - omega - have hltm : Int.ofNat x - Int.ofNat a + 1 * m < m := by - dsimp [m] - have hgtInt : Int.ofNat x < Int.ofNat a := Int.ofNat_lt.mpr hgt - omega - rw [Int.emod_eq_of_lt hnonneg hltm] - constructor - · intro hlt - dsimp [m] at hlt - have haLtInt : Int.ofNat a < (2 ^ (128 : Nat) : Int) := Int.ofNat_lt.mpr ha - omega - · intro hle' - exact False.elim (hle hle') - -theorem liquidityAddDeltaWrappedSub_eq_of_le {x a : Nat} - (hx : x < 2 ^ (128 : Nat)) (hle : a ≤ x) : - liquidityAddDeltaWrappedSub (Int.ofNat x) (0 - Int.ofNat a) = - Int.ofNat (x - a) := by - unfold liquidityAddDeltaWrappedSub - have hsimp : - Int.ofNat x - (0 - (0 - Int.ofNat a)) = Int.ofNat x - Int.ofNat a := by - ring - rw [hsimp] - have hnonneg : 0 ≤ Int.ofNat x - Int.ofNat a := by - exact sub_nonneg.mpr (Int.ofNat_le.mpr hle) - have hltm : Int.ofNat x - Int.ofNat a < (2 ^ (128 : Nat) : Int) := by - have hxInt : Int.ofNat x < (2 ^ (128 : Nat) : Int) := Int.ofNat_lt.mpr hx - have haNonneg : (0 : Int) ≤ Int.ofNat a := Int.natCast_nonneg a - omega - rw [Int.emod_eq_of_lt hnonneg hltm] - exact (Int.ofNat_sub hle).symm - -theorem uint128Mask_toNat_eq_mod (w : UInt256) : - (UInt256.land w uint128Mask).toNat = w.toNat % 2 ^ (128 : Nat) := by - rw [uland_toNat, uint128Mask_toNat] - change w.toNat.land (2 ^ (128 : Nat) - 1) = w.toNat % 2 ^ (128 : Nat) - exact nat_land_mask_eq_mod w.toNat 128 - -theorem uint128Mask_underflow_sub_toNat {x a : UInt256} - (hx : x.toNat < 2 ^ (128 : Nat)) (hgt : x.toNat < a.toNat) - (ha : a.toNat < 2 ^ (128 : Nat)) : - (UInt256.land (UInt256.sub x a) uint128Mask).toNat = - 2 ^ (128 : Nat) + x.toNat - a.toNat := by - have hsub := usub_toNat_underflow (a := x) (b := a) hgt - rw [uint128Mask_toNat_eq_mod, hsub] - have hremLt : 2 ^ (128 : Nat) + x.toNat - a.toNat < 2 ^ (128 : Nat) := by - omega - have hrewrite : UInt256.size + x.toNat - a.toNat = - (2 ^ (128 : Nat) - 1) * 2 ^ (128 : Nat) + - (2 ^ (128 : Nat) + x.toNat - a.toNat) := by - norm_num [UInt256.size] - omega - rw [hrewrite] - rw [Nat.mul_add_mod', Nat.mod_eq_of_lt hremLt] - -theorem evmUint128SubLtCheck_iff {x a : UInt256} - (hx : x.toNat < 2 ^ (128 : Nat)) (ha0 : 0 < a.toNat) - (ha : a.toNat < 2 ^ (128 : Nat)) : - UInt256.lt (UInt256.land uint128Mask (UInt256.sub x a)) - (UInt256.land uint128Mask x) ≠ ⟨0⟩ ↔ - a.toNat ≤ x.toNat := by - rw [u256_land_comm uint128Mask (UInt256.sub x a), - u256_land_comm uint128Mask x, uint128Mask_clean hx] - by_cases hle : a.toNat ≤ x.toNat - · have hsub := usub_toNat (a := x) (b := a) hle - have hsubLt128 : (UInt256.sub x a).toNat < 2 ^ (128 : Nat) := by - rw [hsub] - omega - rw [uint128Mask_clean hsubLt128] - have hltWords : (UInt256.sub x a).toNat < x.toNat := by - rw [hsub] - omega - rw [ult_one hltWords] - constructor - · intro _ - exact hle - · intro _ - native_decide - · have hgt : x.toNat < a.toNat := Nat.lt_of_not_ge hle - have hleft := uint128Mask_underflow_sub_toNat (x := x) (a := a) hx hgt ha - have hnotLt : x.toNat ≤ (UInt256.land (UInt256.sub x a) uint128Mask).toNat := by - rw [hleft] - omega - rw [ult_zero hnotLt] - constructor - · intro hneq - exact False.elim (hneq rfl) - · intro hle' - exact False.elim (hle hle') - -theorem burnTickUpdateLowerLiquidityAddDeltaEvmCheck_iff - {σ_evm σ_solm : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hcanon : UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) : - (burnTickUpdateLowerLiquidityGrossAfterSubInt σ_solm I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ_solm I) ↔ - UInt256.lt - (UInt256.land uint128Mask - (UInt256.sub - (burnTickUpdateLowerLiquidityGrossBeforeWordEvm σ_evm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) - (UInt256.sub ⟨0⟩ - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))))) - (UInt256.land uint128Mask - (burnTickUpdateLowerLiquidityGrossBeforeWordEvm σ_evm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)))) ≠ ⟨0⟩ := by - let amount := burnAmountCleanWord I - let x := burnTickUpdateLowerLiquidityGrossBeforeWordEvm σ_evm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - have hamountPos : 0 < amount.toNat := by - have htoNatNe : amount.toNat ≠ 0 := by - intro h - exact hnonzero (uint256_toNat_eq_zero h) - exact Nat.pos_of_ne_zero htoNatNe - have hamountLt128 : amount.toNat < 2 ^ (128 : Nat) := by - simpa [amount, burnAmountCleanWord, EVM.twoPow] using - uint128Mask_bound (burnAmountWord I) - have hamountLt127 : amount.toNat < EVM.twoPow 127 := - signextend_fifteen_eq_self_toNat_lt_twoPow127 - (by simpa [amount, burnAmountCleanWord] using uint128Mask_bound (burnAmountWord I)) - (by simpa [amount] using hcanon) - have hcancel : - UInt256.sub ⟨0⟩ (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ amount)) = - amount := - u256_zero_sub_signextend_fifteen_zero_sub (w := amount) hnonzero hamountLt127 - have hx : x.toNat < 2 ^ (128 : Nat) := by - simpa [x, EVM.twoPow] using - uint128Mask_bound (burnTickUpdateLowerLoadedWord σ_evm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) - have htransport := burnTickUpdateLowerLiquidityGrossBeforeWord_transport - (σ_evm := σ_evm) (σ_solm := σ_solm) (I := I) hAccounts - have hsource : - (burnTickUpdateLowerLiquidityGrossAfterSubInt σ_solm I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ_solm I) ↔ - amount.toNat ≤ x.toNat := by - simpa [burnTickUpdateLowerLiquidityGrossAfterSubInt, - burnTickUpdateLowerLiquidityGrossBeforeInt, burnTickUpdateLowerLiquidityDeltaInt, - amount, x, htransport] using - liquidityAddDeltaWrappedSub_lt_iff (x := x.toNat) (a := amount.toNat) - hx hamountPos hamountLt128 - have hevm : - UInt256.lt (UInt256.land uint128Mask (UInt256.sub x amount)) - (UInt256.land uint128Mask x) ≠ ⟨0⟩ ↔ - amount.toNat ≤ x.toNat := - evmUint128SubLtCheck_iff (x := x) (a := amount) hx hamountPos hamountLt128 - refine hsource.trans ?_ - simpa [x, amount, hcancel] using hevm.symm - -theorem burnTickUpdateLowerMaxLiquidityEvmCheck_of_source - {v : PoolImmutables} {σ_evm σ_solm : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hcanon : UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hnonzero : burnAmountCleanWord I ≠ ⟨0⟩) - (hdelta : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ_solm I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ_solm I) - (hmax : - ¬ burnTickUpdateLowerLiquidityGrossAfterSubInt σ_solm I <= v.maxLiquidityPerTick) : - UInt256.gt - (UInt256.land uint128Mask - (UInt256.sub - (burnTickUpdateLowerLiquidityGrossBeforeWordEvm σ_evm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) - (UInt256.sub ⟨0⟩ - (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))))) - (UInt256.land uint128Mask (EVM.wordOfInt v.maxLiquidityPerTick)) ≠ ⟨0⟩ := by - let amount := burnAmountCleanWord I - let x := burnTickUpdateLowerLiquidityGrossBeforeWordEvm σ_evm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - let z := UInt256.sub x - (UInt256.sub ⟨0⟩ (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ amount))) - have hamountPos : 0 < amount.toNat := by - have htoNatNe : amount.toNat ≠ 0 := by - intro h - exact hnonzero (uint256_toNat_eq_zero h) - exact Nat.pos_of_ne_zero htoNatNe - have hamountLt128 : amount.toNat < 2 ^ (128 : Nat) := by - simpa [amount, burnAmountCleanWord, EVM.twoPow] using - uint128Mask_bound (burnAmountWord I) - have hamountLt127 : amount.toNat < EVM.twoPow 127 := - signextend_fifteen_eq_self_toNat_lt_twoPow127 - (by simpa [amount, burnAmountCleanWord] using uint128Mask_bound (burnAmountWord I)) - (by simpa [amount] using hcanon) - have hcancel : - UInt256.sub ⟨0⟩ (UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ amount)) = - amount := - u256_zero_sub_signextend_fifteen_zero_sub (w := amount) hnonzero hamountLt127 - have hx : x.toNat < 2 ^ (128 : Nat) := by - simpa [x, EVM.twoPow] using - uint128Mask_bound (burnTickUpdateLowerLoadedWord σ_evm I - (UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I))) - have htransport := burnTickUpdateLowerLiquidityGrossBeforeWord_transport - (σ_evm := σ_evm) (σ_solm := σ_solm) (I := I) hAccounts - have hsource : - (burnTickUpdateLowerLiquidityGrossAfterSubInt σ_solm I < - burnTickUpdateLowerLiquidityGrossBeforeInt σ_solm I) ↔ - amount.toNat ≤ x.toNat := by - simpa [burnTickUpdateLowerLiquidityGrossAfterSubInt, - burnTickUpdateLowerLiquidityGrossBeforeInt, burnTickUpdateLowerLiquidityDeltaInt, - amount, x, htransport] using - liquidityAddDeltaWrappedSub_lt_iff (x := x.toNat) (a := amount.toNat) - hx hamountPos hamountLt128 - have hleAmount : amount.toNat ≤ x.toNat := hsource.mp hdelta - have hzToNat : z.toNat = x.toNat - amount.toNat := by - dsimp [z] - rw [hcancel] - exact usub_toNat (a := x) (b := amount) hleAmount - have hafterEq : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ_solm I = - Int.ofNat (x.toNat - amount.toNat) := by - simpa [burnTickUpdateLowerLiquidityGrossAfterSubInt, - burnTickUpdateLowerLiquidityGrossBeforeInt, burnTickUpdateLowerLiquidityDeltaInt, - amount, x, htransport] using - liquidityAddDeltaWrappedSub_eq_of_le (x := x.toNat) (a := amount.toNat) hx hleAmount - have hafterWord : - burnTickUpdateLowerLiquidityGrossAfterSubInt σ_solm I = Int.ofNat z.toNat := by - rw [hafterEq, hzToNat] - have hzLt128 : z.toNat < EVM.twoPow 128 := by - rw [hzToNat] - norm_num [EVM.twoPow] at hx ⊢ - omega - have hzClean : UInt256.land uint128Mask z = z := uint128Mask_clean_left hzLt128 - have hmaxWordNat : - (EVM.wordOfInt v.maxLiquidityPerTick).toNat = v.maxLiquidityPerTick.toNat := by - exact wordOfInt_nonneg_toNat_lt_wordModulus v.maxLiquidityPerTick - v.maxLiquidityPerTick_nonneg - (by - exact lt_trans v.maxLiquidityPerTick_lt - (by native_decide : (2 ^ (128 : Nat) : Int) < EVM.wordModulus)) - have hmaxWordLt128 : - (EVM.wordOfInt v.maxLiquidityPerTick).toNat < EVM.twoPow 128 := by - rw [hmaxWordNat] - exact (Int.toNat_lt v.maxLiquidityPerTick_nonneg).2 - (by simpa [EVM.twoPow] using v.maxLiquidityPerTick_lt) - have hmaxClean : - UInt256.land uint128Mask (EVM.wordOfInt v.maxLiquidityPerTick) = - EVM.wordOfInt v.maxLiquidityPerTick := - uint128Mask_clean_left hmaxWordLt128 - have hmaxLtAfter : - v.maxLiquidityPerTick < Int.ofNat z.toNat := by - have hmaxLt : - v.maxLiquidityPerTick < burnTickUpdateLowerLiquidityGrossAfterSubInt σ_solm I := by - omega - simpa [hafterWord] using hmaxLt - have hmaxNatLt : - (EVM.wordOfInt v.maxLiquidityPerTick).toNat < z.toNat := by - rw [hmaxWordNat] - exact (Int.toNat_lt v.maxLiquidityPerTick_nonneg).2 hmaxLtAfter - have hgt : - UInt256.gt z (EVM.wordOfInt v.maxLiquidityPerTick) = ⟨1⟩ := - ugt_one hmaxNatLt - have hgtNe : - UInt256.gt z (EVM.wordOfInt v.maxLiquidityPerTick) ≠ ⟨0⟩ := by - rw [hgt] - decide - simpa [z, x, amount, hzClean, hmaxClean] using hgtNe - -private theorem uniswapV3PoolBurnTickUpdatePatchDisjoint {v : PoolImmutables} - {pc : UInt256} {n : Nat} (hlo : 20795 ≤ pc.toNat) - (_hhi : pc.toNat + n ≤ 21285) : - ∀ p ∈ patches v, pc.toNat + n ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolBurnTickUpdateDecodeEqTemplate {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 20795 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21285) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 21285 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolBurnTickUpdatePatchDisjoint (v := v) (pc := pc) hlo hhi) - -private theorem uniswapV3PoolBurnTickUpdatePatchPreservesJumpDest13807 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨13807⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolBurnJumpDestPatched13807 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨13807⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolBurnTickUpdatePatchPreservesJumpDest13807 - -private theorem uniswapV3PoolBurnTickUpdatePatchPreservesJumpDest20838 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨20838⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolBurnJumpDestPatched20838 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨20838⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolBurnTickUpdatePatchPreservesJumpDest20838 - -theorem uniswapV3PoolBurnTickUpdateLowerToLiquidityAddDelta - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {maxLiquidity zero time tick seconds feeGrowthGlobal1 feeGrowthGlobal0 - liquidityDelta slot0Tick tickLower retPc z2 z3 positionBase tickUpper source : UInt256} - {R : List UInt256} {mem : ByteArray} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨20795⟩ - (maxLiquidity :: zero :: time :: tick :: seconds :: feeGrowthGlobal1 :: - feeGrowthGlobal0 :: liquidityDelta :: slot0Tick :: tickLower :: ⟨5⟩ :: - retPc :: seconds :: tick :: time :: z2 :: z3 :: feeGrowthGlobal1 :: - feeGrowthGlobal0 :: positionBase :: slot0Tick :: liquidityDelta :: - tickUpper :: tickLower :: source :: R) - mem (UInt256.ofNat 21) rdata (cA, σ) k C) - (hmem : 64 ≤ mem.size) - (hov : R.length + 55 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨13807⟩ - (liquidityDelta :: - burnTickUpdateLowerLiquidityGrossBeforeWordEvm σ ee tickLower :: - ⟨20838⟩ :: ⟨0⟩ :: - burnTickUpdateLowerLiquidityGrossBeforeWordEvm σ ee tickLower :: - burnTickUpdateLowerBaseSlotWord tickLower :: ⟨0⟩ :: maxLiquidity :: zero :: - time :: tick :: seconds :: feeGrowthGlobal1 :: feeGrowthGlobal0 :: - liquidityDelta :: slot0Tick :: tickLower :: ⟨5⟩ :: retPc :: seconds :: - tick :: time :: z2 :: z3 :: feeGrowthGlobal1 :: feeGrowthGlobal0 :: - positionBase :: slot0Tick :: liquidityDelta :: tickUpper :: tickLower :: source :: R) - (burnTickUpdateLowerHashMem tickLower mem) (UInt256.ofNat 21) rdata - (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 20795 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21285) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnTickUpdateDecodeEqTemplate hpatch hlo hhi - have rd20796 := by - simpa using h.jumpdest - (by rw [hdec ⟨20795⟩ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd20798 := evm_run rd20796 with [ - raw push1 ⟨2⟩ (by - change decode code ⟨20796⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) - rw [hdec ⟨20796⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw dup11 (by - change decode code ⟨20798⟩ = some (.DUP11, none) - rw [hdec ⟨20798⟩ (by native_decide) (by native_decide)] - native_decide) - (by simp only [List.length_cons] at hov ⊢; omega), - raw dup2 (by - change decode code ⟨20799⟩ = some (.DUP2, none) - rw [hdec ⟨20799⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov)] - have rd20801 := by - simpa using RD.signextend rd20798 - (by - change decode code ⟨20800⟩ = some (.SIGNEXTEND, none) - rw [hdec ⟨20800⟩ (by native_decide) (by native_decide)] - native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd20802 := evm_run rd20801 with [ - raw swap1 (by - change decode code ⟨20801⟩ = some (.SWAP1, none) - rw [hdec ⟨20801⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov)] - have rd20803 := by - simpa [burnTickUpdateLowerKeyWord] using RD.signextend rd20802 - (by - change decode code ⟨20802⟩ = some (.SIGNEXTEND, none) - rw [hdec ⟨20802⟩ (by native_decide) (by native_decide)] - native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd20807 := evm_run rd20803 with [ - raw push1 ⟨0⟩ (by - change decode code ⟨20803⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) - rw [hdec ⟨20803⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw swap1 (by - change decode code ⟨20805⟩ = some (.SWAP1, none) - rw [hdec ⟨20805⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw dup2 (by - change decode code ⟨20806⟩ = some (.DUP2, none) - rw [hdec ⟨20806⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov)] - have rd20808 := rd20807.mstore 0 - (wordAt0Mem (burnTickUpdateLowerKeyWord tickLower) mem) (UInt256.ofNat 21) - (by - change decode code ⟨20807⟩ = some (.MSTORE, none) - rw [hdec ⟨20807⟩ (by native_decide) (by native_decide)] - native_decide) - mem_cost (by rfl) (by native_decide) (by simp only [List.length_cons] at hov ⊢; omega) - have rd20812 := evm_run rd20808 with [ - raw push1 ⟨32⟩ (by - change decode code ⟨20808⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) - rw [hdec ⟨20808⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw dup13 (by - change decode code ⟨20810⟩ = some (.DUP13, none) - rw [hdec ⟨20810⟩ (by native_decide) (by native_decide)] - native_decide) - (by simp only [List.length_cons] at hov ⊢; omega), - raw swap1 (by - change decode code ⟨20811⟩ = some (.SWAP1, none) - rw [hdec ⟨20811⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov)] - have rd20813 := rd20812.mstore 0 (burnTickUpdateLowerHashMem tickLower mem) - (UInt256.ofNat 21) - (by - change decode code ⟨20812⟩ = some (.MSTORE, none) - rw [hdec ⟨20812⟩ (by native_decide) (by native_decide)] - native_decide) - mem_cost (by rfl) (by native_decide) (by simp only [List.length_cons] at hov ⊢; omega) - have hslot : - UInt256.ofNat (fromByteArrayBigEndian - (ffi.KEC ((burnTickUpdateLowerHashMem tickLower mem).readWithPadding 0 64))) = - burnTickUpdateLowerBaseSlotWord tickLower := by - exact twoWordHashMem_solcMappingSlot_of_size_ge ⟨5⟩ - (burnTickUpdateLowerKeyWord tickLower) hmem - have rd20817 := evm_run rd20813 with [ - raw push1 ⟨64⟩ (by - change decode code ⟨20813⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) - rw [hdec ⟨20813⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw dup2 (by - change decode code ⟨20815⟩ = some (.DUP2, none) - rw [hdec ⟨20815⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov)] - have rd20817Hash := rd20817.keccak256 0 (burnTickUpdateLowerBaseSlotWord tickLower) - (UInt256.ofNat 21) - (by - change decode code ⟨20816⟩ = some (.KECCAK256, none) - rw [hdec ⟨20816⟩ (by native_decide) (by native_decide)] - native_decide) - mem_cost hslot (by native_decide) (by simp only [List.length_cons] at hov ⊢; omega) - have rd20818 := evm_run rd20817Hash with [ - raw dup1 (by - change decode code ⟨20817⟩ = some (.DUP1, none) - rw [hdec ⟨20817⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov)] - obtain ⟨_, _, rd20819Raw⟩ := rd20818.sload - (by - change decode code ⟨20818⟩ = some (.SLOAD, none) - rw [hdec ⟨20818⟩ (by native_decide) (by native_decide)] - native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd20819 := by - simpa [burnTickUpdateLowerLoadedWord, solcSlotWord] using rd20819Raw - have rd20838 := evm_run rd20819 with [ - raw push1 ⟨1⟩ (by - change decode code ⟨20819⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨20819⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw push1 ⟨1⟩ (by - change decode code ⟨20821⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨20821⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw push1 ⟨128⟩ (by - change decode code ⟨20823⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) - rw [hdec ⟨20823⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw shl (by - change decode code ⟨20825⟩ = some (.SHL, none) - rw [hdec ⟨20825⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw sub (by - change decode code ⟨20826⟩ = some (.SUB, none) - rw [hdec ⟨20826⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw and (by - change decode code ⟨20827⟩ = some (.AND, none) - rw [hdec ⟨20827⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw dup3 (by - change decode code ⟨20828⟩ = some (.DUP3, none) - rw [hdec ⟨20828⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw push2 ⟨20838⟩ - (by - change decode code ⟨20829⟩ = some (.Push .PUSH2, some (⟨20838⟩, 2)) - rw [hdec ⟨20829⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw dup3 (by - change decode code ⟨20832⟩ = some (.DUP3, none) - rw [hdec ⟨20832⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw dup14 (by - change decode code ⟨20833⟩ = some (.DUP14, none) - rw [hdec ⟨20833⟩ (by native_decide) (by native_decide)] - native_decide) - (by simp only [List.length_cons] at hov ⊢; omega), - raw push2 ⟨13807⟩ - (by - change decode code ⟨20834⟩ = some (.Push .PUSH2, some (⟨13807⟩, 2)) - rw [hdec ⟨20834⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov)] - exact ⟨_, _, by - simpa [burnTickUpdateLowerLiquidityGrossBeforeWordEvm, burnTickUpdateLowerLoadedWord, - solcSlotWord, uint128Mask, u256_land_comm] using - rd20838.jump - (by - change decode code ⟨20837⟩ = some (.JUMP, none) - rw [hdec ⟨20837⟩ (by native_decide) (by native_decide)] - native_decide) - (uniswapV3PoolBurnJumpDestPatched13807 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -private theorem uniswapV3PoolLiquidityAddDeltaPatchDisjoint {v : PoolImmutables} - {pc : UInt256} {n : Nat} (hlo : 12989 ≤ pc.toNat) - (hhi : pc.toNat + n ≤ 13940) : - ∀ p ∈ patches v, pc.toNat + n ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolLiquidityAddDeltaDecodeEqTemplate {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 12989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13940) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch - (by - have hsize : 13940 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolLiquidityAddDeltaPatchDisjoint (v := v) (pc := pc) hlo hhi) - -private theorem uniswapV3PoolBurnPatchPreservesJumpDest13903 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨13903⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolBurnJumpDestPatched13903 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨13903⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolBurnPatchPreservesJumpDest13903 - -private theorem uniswapV3PoolBurnPatchPreservesJumpDest12989 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12989⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolBurnJumpDestPatched12989 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12989⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolBurnPatchPreservesJumpDest12989 - -abbrev burnTickUpdateLowerRevertFreePtr : UInt256 := - burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256) - -def burnTickUpdateLowerLiquidityAddDeltaRevertWord : UInt256 := - UInt256.shiftLeft (⟨19539⟩ : UInt256) ⟨240⟩ - -private theorem burnObserveSingleDecodedMem_read64 (σ : AccountMap) - (I : ExecutionEnv) (obsWord : UInt256) : - (burnObserveSingleDecodedMem σ I obsWord).readWithPadding 64 32 = - UInt256.toByteArray burnTickUpdateLowerRevertFreePtr := by - unfold burnObserveSingleDecodedMem - rw [writeWord_read_preserved - (burnObserveSingleDecodedMem3 σ I obsWord) - (burnPositionKeyNewFreePtrWord + (⟨96⟩ : UInt256)).toNat - 64 (burnObserveSingleDecodedInitializedWord obsWord) - (by rw [burnObserveSingleDecodedMem3_size σ I obsWord]; native_decide) - (by rw [burnObserveSingleDecodedMem3_size σ I obsWord]; native_decide)] - unfold burnObserveSingleDecodedMem3 - rw [writeWord_read_preserved - (burnObserveSingleDecodedMem2 σ I obsWord) - (burnPositionKeyNewFreePtrWord + (⟨64⟩ : UInt256)).toNat - 64 (burnObserveSingleDecodedSecondsWord obsWord) - (by rw [burnObserveSingleDecodedMem2_size σ I obsWord]; native_decide) - (by rw [burnObserveSingleDecodedMem2_size σ I obsWord]; native_decide)] - unfold burnObserveSingleDecodedMem2 - rw [writeWord_read_preserved - (burnObserveSingleDecodedMem1 σ I obsWord) - (burnPositionKeyNewFreePtrWord + (⟨32⟩ : UInt256)).toNat - 64 (burnObserveSingleDecodedTickWord obsWord) - (by rw [burnObserveSingleDecodedMem1_size σ I obsWord]; native_decide) - (by rw [burnObserveSingleDecodedMem1_size σ I obsWord]; native_decide)] - unfold burnObserveSingleDecodedMem1 - rw [writeWord_read_preserved - (burnObserveSingleAllocMem σ I) - burnPositionKeyNewFreePtrWord.toNat - 64 (burnObserveSingleDecodedBlockWord obsWord) - (by rw [burnObserveSingleAllocMem_size σ I]; native_decide) - (by rw [burnObserveSingleAllocMem_size σ I]; native_decide)] - unfold burnObserveSingleAllocMem - simpa [burnTickUpdateLowerRevertFreePtr] using - writeWord_read_back (burnPositionKeyMappingMem σ I) 64 - (burnPositionKeyNewFreePtrWord + (⟨128⟩ : UInt256)) - (by rw [burnPositionKeyMappingMem_size σ I]; native_decide) - -private theorem burnTickUpdateLowerHashMem_size (σ : AccountMap) (I : ExecutionEnv) - (obsWord tickLower : UInt256) : - (burnTickUpdateLowerHashMem tickLower (burnObserveSingleDecodedMem σ I obsWord)).size = - 666 := by - unfold burnTickUpdateLowerHashMem - rw [twoWordHashMem_size_of_size_ge] - · exact burnObserveSingleDecodedMem_size σ I obsWord - · rw [burnObserveSingleDecodedMem_size σ I obsWord] - omega - -private theorem burnTickUpdateLowerHashMem_read64 (σ : AccountMap) (I : ExecutionEnv) - (obsWord tickLower : UInt256) : - (burnTickUpdateLowerHashMem tickLower - (burnObserveSingleDecodedMem σ I obsWord)).readWithPadding 64 32 = - UInt256.toByteArray burnTickUpdateLowerRevertFreePtr := by - unfold burnTickUpdateLowerHashMem - rw [twoWordHashMem_read64_of_size_ge] - · exact burnObserveSingleDecodedMem_read64 σ I obsWord - · rw [burnObserveSingleDecodedMem_size σ I obsWord] - omega - -private theorem burnTickUpdateLowerHashMem_mload64 (σ : AccountMap) (I : ExecutionEnv) - (obsWord tickLower : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ - (burnTickUpdateLowerHashMem tickLower - (burnObserveSingleDecodedMem σ I obsWord)).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 21 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnTickUpdateLowerHashMem tickLower - (burnObserveSingleDecodedMem σ I obsWord)).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - burnTickUpdateLowerRevertFreePtr := by - exact mloadWordValue_of_readWithPadding - (mem := burnTickUpdateLowerHashMem tickLower (burnObserveSingleDecodedMem σ I obsWord)) - (aw := UInt256.ofNat 21) (off := ⟨64⟩) (v := burnTickUpdateLowerRevertFreePtr) - (by rw [burnTickUpdateLowerHashMem_size σ I obsWord tickLower]; native_decide) - (by native_decide) - (by - simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using burnTickUpdateLowerHashMem_read64 σ I obsWord tickLower) - -noncomputable abbrev burnTickUpdateLowerLiquidityAddDeltaRevertMem0 - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : ByteArray := - writeWord (burnTickUpdateLowerHashMem tickLower (burnObserveSingleDecodedMem σ I obsWord)) - burnTickUpdateLowerRevertFreePtr.toNat solcErrorStringSelector - -noncomputable abbrev burnTickUpdateLowerLiquidityAddDeltaRevertMem1 - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : ByteArray := - writeWord (burnTickUpdateLowerLiquidityAddDeltaRevertMem0 σ I obsWord tickLower) - (burnTickUpdateLowerRevertFreePtr + (⟨4⟩ : UInt256)).toNat (⟨32⟩ : UInt256) - -noncomputable abbrev burnTickUpdateLowerLiquidityAddDeltaRevertMem2 - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : ByteArray := - writeWord (burnTickUpdateLowerLiquidityAddDeltaRevertMem1 σ I obsWord tickLower) - (burnTickUpdateLowerRevertFreePtr + (⟨36⟩ : UInt256)).toNat (⟨2⟩ : UInt256) - -noncomputable abbrev burnTickUpdateLowerLiquidityAddDeltaRevertMem3 - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : ByteArray := - writeWord (burnTickUpdateLowerLiquidityAddDeltaRevertMem2 σ I obsWord tickLower) - (burnTickUpdateLowerRevertFreePtr + (⟨68⟩ : UInt256)).toNat - burnTickUpdateLowerLiquidityAddDeltaRevertWord - -private theorem burnTickUpdateLowerLiquidityAddDeltaRevertMem0_size - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : - (burnTickUpdateLowerLiquidityAddDeltaRevertMem0 σ I obsWord tickLower).size = 698 := by - unfold burnTickUpdateLowerLiquidityAddDeltaRevertMem0 burnTickUpdateLowerRevertFreePtr - rw [writeWord_size _ _ _ - (by rw [burnTickUpdateLowerHashMem_size σ I obsWord tickLower]; native_decide)] - rw [burnTickUpdateLowerHashMem_size σ I obsWord tickLower] - native_decide - -private theorem burnTickUpdateLowerLiquidityAddDeltaRevertMem1_size - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : - (burnTickUpdateLowerLiquidityAddDeltaRevertMem1 σ I obsWord tickLower).size = 702 := by - unfold burnTickUpdateLowerLiquidityAddDeltaRevertMem1 burnTickUpdateLowerRevertFreePtr - rw [writeWord_size _ _ _ - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem0_size σ I obsWord tickLower] - native_decide)] - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem0_size σ I obsWord tickLower] - native_decide - -private theorem burnTickUpdateLowerLiquidityAddDeltaRevertMem2_size - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : - (burnTickUpdateLowerLiquidityAddDeltaRevertMem2 σ I obsWord tickLower).size = 734 := by - unfold burnTickUpdateLowerLiquidityAddDeltaRevertMem2 burnTickUpdateLowerRevertFreePtr - rw [writeWord_size _ _ _ - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem1_size σ I obsWord tickLower] - native_decide)] - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem1_size σ I obsWord tickLower] - native_decide - -private theorem burnTickUpdateLowerLiquidityAddDeltaRevertMem3_size - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : - (burnTickUpdateLowerLiquidityAddDeltaRevertMem3 σ I obsWord tickLower).size = 766 := by - unfold burnTickUpdateLowerLiquidityAddDeltaRevertMem3 burnTickUpdateLowerRevertFreePtr - rw [writeWord_size _ _ _ - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem2_size σ I obsWord tickLower] - native_decide)] - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem2_size σ I obsWord tickLower] - native_decide - -private theorem burnTickUpdateLowerLiquidityAddDeltaRevertMem3_read64 - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : - (burnTickUpdateLowerLiquidityAddDeltaRevertMem3 σ I obsWord tickLower).readWithPadding - 64 32 = - UInt256.toByteArray burnTickUpdateLowerRevertFreePtr := by - unfold burnTickUpdateLowerLiquidityAddDeltaRevertMem3 - rw [writeWord_read_preserved - (burnTickUpdateLowerLiquidityAddDeltaRevertMem2 σ I obsWord tickLower) - (burnTickUpdateLowerRevertFreePtr + (⟨68⟩ : UInt256)).toNat - 64 burnTickUpdateLowerLiquidityAddDeltaRevertWord - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem2_size σ I obsWord tickLower] - native_decide) - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem2_size σ I obsWord tickLower] - native_decide)] - unfold burnTickUpdateLowerLiquidityAddDeltaRevertMem2 - rw [writeWord_read_preserved - (burnTickUpdateLowerLiquidityAddDeltaRevertMem1 σ I obsWord tickLower) - (burnTickUpdateLowerRevertFreePtr + (⟨36⟩ : UInt256)).toNat - 64 (⟨2⟩ : UInt256) - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem1_size σ I obsWord tickLower] - native_decide) - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem1_size σ I obsWord tickLower] - native_decide)] - unfold burnTickUpdateLowerLiquidityAddDeltaRevertMem1 - rw [writeWord_read_preserved - (burnTickUpdateLowerLiquidityAddDeltaRevertMem0 σ I obsWord tickLower) - (burnTickUpdateLowerRevertFreePtr + (⟨4⟩ : UInt256)).toNat - 64 (⟨32⟩ : UInt256) - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem0_size σ I obsWord tickLower] - native_decide) - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem0_size σ I obsWord tickLower] - native_decide)] - unfold burnTickUpdateLowerLiquidityAddDeltaRevertMem0 - rw [writeWord_read_preserved - (burnTickUpdateLowerHashMem tickLower (burnObserveSingleDecodedMem σ I obsWord)) - burnTickUpdateLowerRevertFreePtr.toNat - 64 solcErrorStringSelector - (by rw [burnTickUpdateLowerHashMem_size σ I obsWord tickLower]; native_decide) - (by rw [burnTickUpdateLowerHashMem_size σ I obsWord tickLower]; native_decide)] - exact burnTickUpdateLowerHashMem_read64 σ I obsWord tickLower - -private theorem burnTickUpdateLowerLiquidityAddDeltaRevertMem3_mload64 - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ - (burnTickUpdateLowerLiquidityAddDeltaRevertMem3 σ I obsWord tickLower).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 24 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnTickUpdateLowerLiquidityAddDeltaRevertMem3 σ I obsWord tickLower).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - burnTickUpdateLowerRevertFreePtr := by - exact mloadWordValue_of_readWithPadding - (mem := burnTickUpdateLowerLiquidityAddDeltaRevertMem3 σ I obsWord tickLower) - (aw := UInt256.ofNat 24) (off := ⟨64⟩) (v := burnTickUpdateLowerRevertFreePtr) - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem3_size σ I obsWord tickLower] - native_decide) - (by native_decide) - (by - simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using burnTickUpdateLowerLiquidityAddDeltaRevertMem3_read64 σ I obsWord tickLower) - -private theorem uniswapV3PoolLiquidityAddDeltaLsRevertTailWf - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcErrorStringRevertTailWf code ⟨13854⟩ ⟨2⟩ ⟨19539⟩ ⟨240⟩ .PUSH2 2 := by - dsimp [solcErrorStringRevertTailWf] - repeat' constructor - all_goals - rw [uniswapV3PoolLiquidityAddDeltaDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - -theorem uniswapV3PoolLiquidityAddDeltaLowerRevertTail - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {obsWord tickLower : UInt256} {stk : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13854⟩ stk - (burnTickUpdateLowerHashMem tickLower (burnObserveSingleDecodedMem σ ee obsWord)) - (UInt256.ofNat 21) rdata (cA, σ) k C) - (hov : stk.length + 5 ≤ 1024) : - RDrev code g s0 := by - rcases uniswapV3PoolLiquidityAddDeltaLsRevertTailWf hpatch with - ⟨hd0, hd2, hd3, hd4, hd8, hd10, hd11, hd12, hd13, hd15, hd17, hd18, - hd19, hd20, hd22, hd24, hd25, hd26, hd27, hdRawOut, hdShl, hd68, - hdDup3, hdAdd, hdMstore3, hdSwap, hdMload, hdSwap2, hdDup2, hdSwap3, - hdSub, hd100, hdAdd2, hdSwap4, hdRev⟩ - have rdMload := evm_run h with [ - raw push1 ⟨64⟩ hd0 (by evm_ov), - raw dup1 hd2 (by evm_ov), - raw mload 0 burnTickUpdateLowerRevertFreePtr (UInt256.ofNat 21) hd3 - mem_cost - (burnTickUpdateLowerHashMem_mload64 σ ee obsWord tickLower) - (by native_decide) (by evm_ov)] - have rdSelectorRaw := rdMload.pushConst (⟨4594637⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) hd4 - (by simp only [List.length_cons]; omega) - have rdPrefix := evm_run rdSelectorRaw with [ - raw push1 ⟨229⟩ hd8 (by evm_ov), - raw shl hd10 (by evm_ov), - raw dup2 hd11 (by evm_ov), - raw mstore 3 (burnTickUpdateLowerLiquidityAddDeltaRevertMem0 σ ee obsWord tickLower) - (UInt256.ofNat 22) hd12 mem_cost (by rfl) (by native_decide) (by evm_ov), - raw push1 ⟨32⟩ hd13 (by evm_ov), - raw push1 ⟨4⟩ hd15 (by evm_ov), - raw dup3 hd17 (by evm_ov), - raw add hd18 (by evm_ov), - raw mstore 0 (burnTickUpdateLowerLiquidityAddDeltaRevertMem1 σ ee obsWord tickLower) - (UInt256.ofNat 22) hd19 mem_cost (by rfl) (by native_decide) (by evm_ov), - raw push1 ⟨2⟩ hd20 (by evm_ov), - raw push1 ⟨36⟩ hd22 (by evm_ov), - raw dup3 hd24 (by evm_ov), - raw add hd25 (by evm_ov), - raw mstore 4 (burnTickUpdateLowerLiquidityAddDeltaRevertMem2 σ ee obsWord tickLower) - (UInt256.ofNat 23) hd26 mem_cost (by rfl) (by native_decide) (by evm_ov)] - have rdRaw := rdPrefix.pushConst (⟨19539⟩ : UInt256) - (width := 2) (op := .PUSH2) (by decide) hd27 - (by simp only [List.length_cons]; omega) - have rdWord := evm_run rdRaw with [ - raw push1 ⟨240⟩ hdRawOut (by evm_ov), - raw shl hdShl (by evm_ov)] - exact evm_run rdWord with [ - raw push1 ⟨68⟩ hd68 (by evm_ov), - raw dup3 hdDup3 (by evm_ov), - raw add hdAdd (by evm_ov), - raw mstore 3 (burnTickUpdateLowerLiquidityAddDeltaRevertMem3 σ ee obsWord tickLower) - (UInt256.ofNat 24) hdMstore3 mem_cost (by rfl) (by native_decide) (by evm_ov), - raw swap1 hdSwap (by evm_ov), - raw mload 0 burnTickUpdateLowerRevertFreePtr (UInt256.ofNat 24) hdMload - mem_cost - (burnTickUpdateLowerLiquidityAddDeltaRevertMem3_mload64 σ ee obsWord tickLower) - (by native_decide) (by evm_ov), - raw swap1 hdSwap2 (by evm_ov), - raw dup2 hdDup2 (by evm_ov), - raw swap1 hdSwap3 (by evm_ov), - raw sub hdSub (by evm_ov), - raw push1 ⟨100⟩ hd100 (by evm_ov), - raw add hdAdd2 (by evm_ov), - raw swap1 hdSwap4 (by evm_ov), - raw rev 0 hdRev mem_cost (by evm_ov)] - -def burnTickUpdateLowerMaxLiquidityRevertWord : UInt256 := - UInt256.shiftLeft (⟨19535⟩ : UInt256) ⟨240⟩ - -noncomputable abbrev burnTickUpdateLowerMaxLiquidityRevertMem3 - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : ByteArray := - writeWord (burnTickUpdateLowerLiquidityAddDeltaRevertMem2 σ I obsWord tickLower) - (burnTickUpdateLowerRevertFreePtr + (⟨68⟩ : UInt256)).toNat - burnTickUpdateLowerMaxLiquidityRevertWord - -private theorem burnTickUpdateLowerMaxLiquidityRevertMem3_size - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : - (burnTickUpdateLowerMaxLiquidityRevertMem3 σ I obsWord tickLower).size = 766 := by - unfold burnTickUpdateLowerMaxLiquidityRevertMem3 burnTickUpdateLowerRevertFreePtr - rw [writeWord_size _ _ _ - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem2_size σ I obsWord tickLower] - native_decide)] - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem2_size σ I obsWord tickLower] - native_decide - -private theorem burnTickUpdateLowerMaxLiquidityRevertMem3_read64 - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : - (burnTickUpdateLowerMaxLiquidityRevertMem3 σ I obsWord tickLower).readWithPadding - 64 32 = - UInt256.toByteArray burnTickUpdateLowerRevertFreePtr := by - unfold burnTickUpdateLowerMaxLiquidityRevertMem3 - rw [writeWord_read_preserved - (burnTickUpdateLowerLiquidityAddDeltaRevertMem2 σ I obsWord tickLower) - (burnTickUpdateLowerRevertFreePtr + (⟨68⟩ : UInt256)).toNat - 64 burnTickUpdateLowerMaxLiquidityRevertWord - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem2_size σ I obsWord tickLower] - native_decide) - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem2_size σ I obsWord tickLower] - native_decide)] - unfold burnTickUpdateLowerLiquidityAddDeltaRevertMem2 - rw [writeWord_read_preserved - (burnTickUpdateLowerLiquidityAddDeltaRevertMem1 σ I obsWord tickLower) - (burnTickUpdateLowerRevertFreePtr + (⟨36⟩ : UInt256)).toNat - 64 (⟨2⟩ : UInt256) - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem1_size σ I obsWord tickLower] - native_decide) - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem1_size σ I obsWord tickLower] - native_decide)] - unfold burnTickUpdateLowerLiquidityAddDeltaRevertMem1 - rw [writeWord_read_preserved - (burnTickUpdateLowerLiquidityAddDeltaRevertMem0 σ I obsWord tickLower) - (burnTickUpdateLowerRevertFreePtr + (⟨4⟩ : UInt256)).toNat - 64 (⟨32⟩ : UInt256) - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem0_size σ I obsWord tickLower] - native_decide) - (by - rw [burnTickUpdateLowerLiquidityAddDeltaRevertMem0_size σ I obsWord tickLower] - native_decide)] - unfold burnTickUpdateLowerLiquidityAddDeltaRevertMem0 - rw [writeWord_read_preserved - (burnTickUpdateLowerHashMem tickLower (burnObserveSingleDecodedMem σ I obsWord)) - burnTickUpdateLowerRevertFreePtr.toNat - 64 solcErrorStringSelector - (by rw [burnTickUpdateLowerHashMem_size σ I obsWord tickLower]; native_decide) - (by rw [burnTickUpdateLowerHashMem_size σ I obsWord tickLower]; native_decide)] - exact burnTickUpdateLowerHashMem_read64 σ I obsWord tickLower - -private theorem burnTickUpdateLowerMaxLiquidityRevertMem3_mload64 - (σ : AccountMap) (I : ExecutionEnv) (obsWord tickLower : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ - (burnTickUpdateLowerMaxLiquidityRevertMem3 σ I obsWord tickLower).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 24 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((burnTickUpdateLowerMaxLiquidityRevertMem3 σ I obsWord tickLower).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - burnTickUpdateLowerRevertFreePtr := by - exact mloadWordValue_of_readWithPadding - (mem := burnTickUpdateLowerMaxLiquidityRevertMem3 σ I obsWord tickLower) - (aw := UInt256.ofNat 24) (off := ⟨64⟩) (v := burnTickUpdateLowerRevertFreePtr) - (by - rw [burnTickUpdateLowerMaxLiquidityRevertMem3_size σ I obsWord tickLower] - native_decide) - (by native_decide) - (by - simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using burnTickUpdateLowerMaxLiquidityRevertMem3_read64 σ I obsWord tickLower) - -private theorem uniswapV3PoolBurnLowerMaxLiquidityRevertTailWf - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcErrorStringRevertTailWf code ⟨20867⟩ ⟨2⟩ ⟨19535⟩ ⟨240⟩ .PUSH2 2 := by - dsimp [solcErrorStringRevertTailWf] - repeat' constructor - all_goals - rw [uniswapV3PoolBurnTickUpdateDecodeEqTemplate hpatch - (by native_decide) (by native_decide)] - native_decide - -theorem uniswapV3PoolBurnLowerMaxLiquidityRevertTail - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {obsWord tickLower : UInt256} {stk : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨20867⟩ stk - (burnTickUpdateLowerHashMem tickLower (burnObserveSingleDecodedMem σ ee obsWord)) - (UInt256.ofNat 21) rdata (cA, σ) k C) - (hov : stk.length + 5 ≤ 1024) : - RDrev code g s0 := by - rcases uniswapV3PoolBurnLowerMaxLiquidityRevertTailWf hpatch with - ⟨hd0, hd2, hd3, hd4, hd8, hd10, hd11, hd12, hd13, hd15, hd17, hd18, - hd19, hd20, hd22, hd24, hd25, hd26, hd27, hdRawOut, hdShl, hd68, - hdDup3, hdAdd, hdMstore3, hdSwap, hdMload, hdSwap2, hdDup2, hdSwap3, - hdSub, hd100, hdAdd2, hdSwap4, hdRev⟩ - have rdMload := evm_run h with [ - raw push1 ⟨64⟩ hd0 (by evm_ov), - raw dup1 hd2 (by evm_ov), - raw mload 0 burnTickUpdateLowerRevertFreePtr (UInt256.ofNat 21) hd3 - mem_cost - (burnTickUpdateLowerHashMem_mload64 σ ee obsWord tickLower) - (by native_decide) (by evm_ov)] - have rdSelectorRaw := rdMload.pushConst (⟨4594637⟩ : UInt256) - (width := 3) (op := .PUSH3) (by decide) hd4 - (by simp only [List.length_cons]; omega) - have rdPrefix := evm_run rdSelectorRaw with [ - raw push1 ⟨229⟩ hd8 (by evm_ov), - raw shl hd10 (by evm_ov), - raw dup2 hd11 (by evm_ov), - raw mstore 3 (burnTickUpdateLowerLiquidityAddDeltaRevertMem0 σ ee obsWord tickLower) - (UInt256.ofNat 22) hd12 mem_cost (by rfl) (by native_decide) (by evm_ov), - raw push1 ⟨32⟩ hd13 (by evm_ov), - raw push1 ⟨4⟩ hd15 (by evm_ov), - raw dup3 hd17 (by evm_ov), - raw add hd18 (by evm_ov), - raw mstore 0 (burnTickUpdateLowerLiquidityAddDeltaRevertMem1 σ ee obsWord tickLower) - (UInt256.ofNat 22) hd19 mem_cost (by rfl) (by native_decide) (by evm_ov), - raw push1 ⟨2⟩ hd20 (by evm_ov), - raw push1 ⟨36⟩ hd22 (by evm_ov), - raw dup3 hd24 (by evm_ov), - raw add hd25 (by evm_ov), - raw mstore 4 (burnTickUpdateLowerLiquidityAddDeltaRevertMem2 σ ee obsWord tickLower) - (UInt256.ofNat 23) hd26 mem_cost (by rfl) (by native_decide) (by evm_ov)] - have rdRaw := rdPrefix.pushConst (⟨19535⟩ : UInt256) - (width := 2) (op := .PUSH2) (by decide) hd27 - (by simp only [List.length_cons]; omega) - have rdWord := evm_run rdRaw with [ - raw push1 ⟨240⟩ hdRawOut (by evm_ov), - raw shl hdShl (by evm_ov)] - exact evm_run rdWord with [ - raw push1 ⟨68⟩ hd68 (by evm_ov), - raw dup3 hdDup3 (by evm_ov), - raw add hdAdd (by evm_ov), - raw mstore 3 (burnTickUpdateLowerMaxLiquidityRevertMem3 σ ee obsWord tickLower) - (UInt256.ofNat 24) hdMstore3 mem_cost (by rfl) (by native_decide) (by evm_ov), - raw swap1 hdSwap (by evm_ov), - raw mload 0 burnTickUpdateLowerRevertFreePtr (UInt256.ofNat 24) hdMload - mem_cost - (burnTickUpdateLowerMaxLiquidityRevertMem3_mload64 σ ee obsWord tickLower) - (by native_decide) (by evm_ov), - raw swap1 hdSwap2 (by evm_ov), - raw dup2 hdDup2 (by evm_ov), - raw swap1 hdSwap3 (by evm_ov), - raw sub hdSub (by evm_ov), - raw push1 ⟨100⟩ hd100 (by evm_ov), - raw add hdAdd2 (by evm_ov), - raw swap1 hdSwap4 (by evm_ov), - raw rev 0 hdRev mem_cost (by evm_ov)] - -theorem uniswapV3PoolLiquidityAddDeltaNegativeRevert - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {y x ret scratch xCopy obsWord tickLower : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13807⟩ (y :: x :: ret :: scratch :: xCopy :: R) - (burnTickUpdateLowerHashMem tickLower (burnObserveSingleDecodedMem σ ee obsWord)) - (UInt256.ofNat 21) rdata (cA, σ) k C) - (hneg : - UInt256.isZero (UInt256.slt (UInt256.signextend ⟨15⟩ y) ⟨0⟩) = ⟨0⟩) - (hreq : - UInt256.lt - (UInt256.land uint128Mask (UInt256.sub x (UInt256.sub ⟨0⟩ y))) - (UInt256.land uint128Mask x) = ⟨0⟩) - (hov : R.length + 20 ≤ 1024) : - RDrev code g s0 := by - have hdec (pc : UInt256) - (hlo : 12989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13940) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolLiquidityAddDeltaDecodeEqTemplate hpatch hlo hhi - have rd13808 := by - simpa using h.jumpdest - (by rw [hdec ⟨13807⟩ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd13814 := evm_run rd13808 with [ - raw push1 ⟨0⟩ (by - change decode code ⟨13808⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) - rw [hdec ⟨13808⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw dup1 (by - change decode code ⟨13810⟩ = some (.DUP1, none) - rw [hdec ⟨13810⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw dup3 (by - change decode code ⟨13811⟩ = some (.DUP3, none) - rw [hdec ⟨13811⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨15⟩ (by - change decode code ⟨13812⟩ = some (.Push .PUSH1, some (⟨15⟩, 1)) - rw [hdec ⟨13812⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov)] - have rd13815 := by - simpa using RD.signextend rd13814 - (by - change decode code ⟨13814⟩ = some (.SIGNEXTEND, none) - rw [hdec ⟨13814⟩ (by native_decide) (by native_decide)] - native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd13820 := evm_run rd13815 with [ - raw slt (by - change decode code ⟨13815⟩ = some (.SLT, none) - rw [hdec ⟨13815⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw iszero (by - change decode code ⟨13816⟩ = some (.ISZERO, none) - rw [hdec ⟨13816⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push2 ⟨13908⟩ (by - change decode code ⟨13817⟩ = some (.Push .PUSH2, some (⟨13908⟩, 2)) - rw [hdec ⟨13817⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov)] - have rd13821 := by - simpa using rd13820.jumpiNT - (by - change decode code ⟨13820⟩ = some (.JUMPI, none) - rw [hdec ⟨13820⟩ (by native_decide) (by native_decide)] - native_decide) - hneg - (by simp only [List.length_cons] at hov ⊢; omega) - have rd13853 := evm_run rd13821 with [ - raw dup3 (by - change decode code ⟨13821⟩ = some (.DUP3, none) - rw [hdec ⟨13821⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - change decode code ⟨13822⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨13822⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - change decode code ⟨13824⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨13824⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨128⟩ (by - change decode code ⟨13826⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) - rw [hdec ⟨13826⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw shl (by - change decode code ⟨13828⟩ = some (.SHL, none) - rw [hdec ⟨13828⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - change decode code ⟨13829⟩ = some (.SUB, none) - rw [hdec ⟨13829⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw and (by - change decode code ⟨13830⟩ = some (.AND, none) - rw [hdec ⟨13830⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw dup3 (by - change decode code ⟨13831⟩ = some (.DUP3, none) - rw [hdec ⟨13831⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨0⟩ (by - change decode code ⟨13832⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) - rw [hdec ⟨13832⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - change decode code ⟨13834⟩ = some (.SUB, none) - rw [hdec ⟨13834⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw dup5 (by - change decode code ⟨13835⟩ = some (.DUP5, none) - rw [hdec ⟨13835⟩ (by native_decide) (by native_decide)] - native_decide) (by simp only [List.length_cons] at hov ⊢; omega), - raw sub (by - change decode code ⟨13836⟩ = some (.SUB, none) - rw [hdec ⟨13836⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw swap2 (by - change decode code ⟨13837⟩ = some (.SWAP2, none) - rw [hdec ⟨13837⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw pop (by - change decode code ⟨13838⟩ = some (.POP, none) - rw [hdec ⟨13838⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw dup2 (by - change decode code ⟨13839⟩ = some (.DUP2, none) - rw [hdec ⟨13839⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - change decode code ⟨13840⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨13840⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - change decode code ⟨13842⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨13842⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨128⟩ (by - change decode code ⟨13844⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) - rw [hdec ⟨13844⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw shl (by - change decode code ⟨13846⟩ = some (.SHL, none) - rw [hdec ⟨13846⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - change decode code ⟨13847⟩ = some (.SUB, none) - rw [hdec ⟨13847⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw and (by - change decode code ⟨13848⟩ = some (.AND, none) - rw [hdec ⟨13848⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw lt (by - change decode code ⟨13849⟩ = some (.LT, none) - rw [hdec ⟨13849⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push2 ⟨13903⟩ (by - change decode code ⟨13850⟩ = some (.Push .PUSH2, some (⟨13903⟩, 2)) - rw [hdec ⟨13850⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov)] - have hreq' : - UInt256.lt - (UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨128⟩).sub ⟨1⟩) - (UInt256.sub x (UInt256.sub ⟨0⟩ y))) - (UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨128⟩).sub ⟨1⟩) x) = - ⟨0⟩ := by - rw [show ((⟨1⟩ : UInt256).shiftLeft ⟨128⟩).sub ⟨1⟩ = uint128Mask by - native_decide] - exact hreq - have rd13854 := by - simpa [uint128Mask, u256_land_comm] using rd13853.jumpiNT - (by - change decode code ⟨13853⟩ = some (.JUMPI, none) - rw [hdec ⟨13853⟩ (by native_decide) (by native_decide)] - native_decide) - hreq' - (by simp only [List.length_cons] at hov ⊢; omega) - exact uniswapV3PoolLiquidityAddDeltaLowerRevertTail - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (obsWord := obsWord) (tickLower := tickLower) - (rdata := rdata) (cA := cA) (σ := σ) - hpatch rd13854 - (by simp only [List.length_cons] at hov ⊢; omega) - -theorem uniswapV3PoolLiquidityAddDeltaNegativeReturn - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {y x ret scratch xCopy : UInt256} {R : List UInt256} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13807⟩ (y :: x :: ret :: scratch :: xCopy :: R) - mem aw rdata (cA, σ) k C) - (hneg : - UInt256.isZero (UInt256.slt (UInt256.signextend ⟨15⟩ y) ⟨0⟩) = ⟨0⟩) - (hreq : - UInt256.lt - (UInt256.land uint128Mask (UInt256.sub x (UInt256.sub ⟨0⟩ y))) - (UInt256.land uint128Mask x) ≠ ⟨0⟩) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 20 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret - (UInt256.sub x (UInt256.sub ⟨0⟩ y) :: scratch :: xCopy :: R) - mem aw rdata (cA, σ) k' C' := by - have hdec (pc : UInt256) - (hlo : 12989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13940) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolLiquidityAddDeltaDecodeEqTemplate hpatch hlo hhi - have rd13808 := by - simpa using h.jumpdest - (by rw [hdec ⟨13807⟩ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd13814 := evm_run rd13808 with [ - raw push1 ⟨0⟩ (by - change decode code ⟨13808⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) - rw [hdec ⟨13808⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw dup1 (by - change decode code ⟨13810⟩ = some (.DUP1, none) - rw [hdec ⟨13810⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw dup3 (by - change decode code ⟨13811⟩ = some (.DUP3, none) - rw [hdec ⟨13811⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨15⟩ (by - change decode code ⟨13812⟩ = some (.Push .PUSH1, some (⟨15⟩, 1)) - rw [hdec ⟨13812⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov)] - have rd13815 := by - simpa using RD.signextend rd13814 - (by - change decode code ⟨13814⟩ = some (.SIGNEXTEND, none) - rw [hdec ⟨13814⟩ (by native_decide) (by native_decide)] - native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd13820 := evm_run rd13815 with [ - raw slt (by - change decode code ⟨13815⟩ = some (.SLT, none) - rw [hdec ⟨13815⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw iszero (by - change decode code ⟨13816⟩ = some (.ISZERO, none) - rw [hdec ⟨13816⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push2 ⟨13908⟩ (by - change decode code ⟨13817⟩ = some (.Push .PUSH2, some (⟨13908⟩, 2)) - rw [hdec ⟨13817⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov)] - have rd13821 := by - simpa using rd13820.jumpiNT - (by - change decode code ⟨13820⟩ = some (.JUMPI, none) - rw [hdec ⟨13820⟩ (by native_decide) (by native_decide)] - native_decide) - hneg - (by simp only [List.length_cons] at hov ⊢; omega) - have rd13853 := evm_run rd13821 with [ - raw dup3 (by - change decode code ⟨13821⟩ = some (.DUP3, none) - rw [hdec ⟨13821⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - change decode code ⟨13822⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨13822⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - change decode code ⟨13824⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨13824⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨128⟩ (by - change decode code ⟨13826⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) - rw [hdec ⟨13826⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw shl (by - change decode code ⟨13828⟩ = some (.SHL, none) - rw [hdec ⟨13828⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - change decode code ⟨13829⟩ = some (.SUB, none) - rw [hdec ⟨13829⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw and (by - change decode code ⟨13830⟩ = some (.AND, none) - rw [hdec ⟨13830⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw dup3 (by - change decode code ⟨13831⟩ = some (.DUP3, none) - rw [hdec ⟨13831⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨0⟩ (by - change decode code ⟨13832⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) - rw [hdec ⟨13832⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - change decode code ⟨13834⟩ = some (.SUB, none) - rw [hdec ⟨13834⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw dup5 (by - change decode code ⟨13835⟩ = some (.DUP5, none) - rw [hdec ⟨13835⟩ (by native_decide) (by native_decide)] - native_decide) (by simp only [List.length_cons] at hov ⊢; omega), - raw sub (by - change decode code ⟨13836⟩ = some (.SUB, none) - rw [hdec ⟨13836⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw swap2 (by - change decode code ⟨13837⟩ = some (.SWAP2, none) - rw [hdec ⟨13837⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw pop (by - change decode code ⟨13838⟩ = some (.POP, none) - rw [hdec ⟨13838⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw dup2 (by - change decode code ⟨13839⟩ = some (.DUP2, none) - rw [hdec ⟨13839⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - change decode code ⟨13840⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨13840⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - change decode code ⟨13842⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨13842⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨128⟩ (by - change decode code ⟨13844⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) - rw [hdec ⟨13844⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw shl (by - change decode code ⟨13846⟩ = some (.SHL, none) - rw [hdec ⟨13846⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - change decode code ⟨13847⟩ = some (.SUB, none) - rw [hdec ⟨13847⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw and (by - change decode code ⟨13848⟩ = some (.AND, none) - rw [hdec ⟨13848⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw lt (by - change decode code ⟨13849⟩ = some (.LT, none) - rw [hdec ⟨13849⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw push2 ⟨13903⟩ (by - change decode code ⟨13850⟩ = some (.Push .PUSH2, some (⟨13903⟩, 2)) - rw [hdec ⟨13850⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov)] - have hreq' : - UInt256.lt - (UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨128⟩).sub ⟨1⟩) - (UInt256.sub x (UInt256.sub ⟨0⟩ y))) - (UInt256.land (((⟨1⟩ : UInt256).shiftLeft ⟨128⟩).sub ⟨1⟩) x) ≠ - ⟨0⟩ := by - rw [show ((⟨1⟩ : UInt256).shiftLeft ⟨128⟩).sub ⟨1⟩ = uint128Mask by - native_decide] - exact hreq - have rd13903 := by - simpa [uint128Mask, u256_land_comm] using rd13853.jumpiT - (by - change decode code ⟨13853⟩ = some (.JUMPI, none) - rw [hdec ⟨13853⟩ (by native_decide) (by native_decide)] - native_decide) - hreq' - (uniswapV3PoolBurnJumpDestPatched13903 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd13904 := by - simpa using rd13903.jumpdest - (by - rw [hdec ⟨13903⟩ (by native_decide) (by native_decide)] - native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd13907 := evm_run rd13904 with [ - raw push2 ⟨12989⟩ (by - change decode code ⟨13904⟩ = some (.Push .PUSH2, some (⟨12989⟩, 2)) - rw [hdec ⟨13904⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov)] - have rd12989 := by - simpa using rd13907.jump - (by - change decode code ⟨13907⟩ = some (.JUMP, none) - rw [hdec ⟨13907⟩ (by native_decide) (by native_decide)] - native_decide) - (uniswapV3PoolBurnJumpDestPatched12989 hpatch) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd12990 := by - simpa using rd12989.jumpdest - (by - rw [hdec ⟨12989⟩ (by native_decide) (by native_decide)] - native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd12994 := evm_run rd12990 with [ - raw swap3 (by - change decode code ⟨12990⟩ = some (.SWAP3, none) - rw [hdec ⟨12990⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw swap2 (by - change decode code ⟨12991⟩ = some (.SWAP2, none) - rw [hdec ⟨12991⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw pop (by - change decode code ⟨12992⟩ = some (.POP, none) - rw [hdec ⟨12992⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov), - raw pop (by - change decode code ⟨12993⟩ = some (.POP, none) - rw [hdec ⟨12993⟩ (by native_decide) (by native_decide)] - native_decide) (by evm_ov)] - exact ⟨_, _, by - simpa using rd12994.jump - (by - change decode code ⟨12994⟩ = some (.JUMP, none) - rw [hdec ⟨12994⟩ (by native_decide) (by native_decide)] - native_decide) - hret - (by simp only [List.length_cons] at hov ⊢; omega)⟩ - -theorem uniswapV3PoolBurnLowerMaxLiquidityRevert - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} - {z scratch x base zero maxLiquidity obsWord tickLower : UInt256} {R : List UInt256} - {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨20838⟩ - (z :: scratch :: x :: base :: zero :: maxLiquidity :: R) - (burnTickUpdateLowerHashMem tickLower (burnObserveSingleDecodedMem σ ee obsWord)) - (UInt256.ofNat 21) rdata (cA, σ) k C) - (hmax : - UInt256.gt (UInt256.land uint128Mask z) - (UInt256.land uint128Mask maxLiquidity) ≠ ⟨0⟩) - (hov : R.length + 16 ≤ 1024) : - RDrev code g s0 := by - have hdec (pc : UInt256) - (hlo : 20795 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 21285) : - decode code pc = decode uniswapV3PoolBytecode pc := by - exact uniswapV3PoolBurnTickUpdateDecodeEqTemplate hpatch hlo hhi - have rd20839 := by - simpa using h.jumpdest - (by rw [hdec ⟨20838⟩ (by native_decide) (by native_decide)]; native_decide) - (by simp only [List.length_cons] at hov ⊢; omega) - have rd20866 := evm_run rd20839 with [ - raw swap1 (by - change decode code ⟨20839⟩ = some (.SWAP1, none) - rw [hdec ⟨20839⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw pop (by - change decode code ⟨20840⟩ = some (.POP, none) - rw [hdec ⟨20840⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw dup5 (by - change decode code ⟨20841⟩ = some (.DUP5, none) - rw [hdec ⟨20841⟩ (by native_decide) (by native_decide)] - native_decide) - (by omega), - raw push1 ⟨1⟩ (by - change decode code ⟨20842⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨20842⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw push1 ⟨1⟩ (by - change decode code ⟨20844⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨20844⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw push1 ⟨128⟩ (by - change decode code ⟨20846⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) - rw [hdec ⟨20846⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw shl (by - change decode code ⟨20848⟩ = some (.SHL, none) - rw [hdec ⟨20848⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw sub (by - change decode code ⟨20849⟩ = some (.SUB, none) - rw [hdec ⟨20849⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw and (by - change decode code ⟨20850⟩ = some (.AND, none) - rw [hdec ⟨20850⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw dup2 (by - change decode code ⟨20851⟩ = some (.DUP2, none) - rw [hdec ⟨20851⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw push1 ⟨1⟩ (by - change decode code ⟨20852⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨20852⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw push1 ⟨1⟩ (by - change decode code ⟨20854⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) - rw [hdec ⟨20854⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw push1 ⟨128⟩ (by - change decode code ⟨20856⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) - rw [hdec ⟨20856⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw shl (by - change decode code ⟨20858⟩ = some (.SHL, none) - rw [hdec ⟨20858⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw sub (by - change decode code ⟨20859⟩ = some (.SUB, none) - rw [hdec ⟨20859⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw and (by - change decode code ⟨20860⟩ = some (.AND, none) - rw [hdec ⟨20860⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw gt (by - change decode code ⟨20861⟩ = some (.GT, none) - rw [hdec ⟨20861⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw iszero (by - change decode code ⟨20862⟩ = some (.ISZERO, none) - rw [hdec ⟨20862⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov), - raw push2 ⟨20916⟩ - (by - change decode code ⟨20863⟩ = some (.Push .PUSH2, some (⟨20916⟩, 2)) - rw [hdec ⟨20863⟩ (by native_decide) (by native_decide)] - native_decide) - (by evm_ov)] - have hcond : - UInt256.isZero - (UInt256.gt (UInt256.land uint128Mask z) - (UInt256.land uint128Mask maxLiquidity)) = - ⟨0⟩ := - isZero_eq_zero_of_ne hmax - have rd20867 := by - simpa [uint128Mask, u256_land_comm] using rd20866.jumpiNT - (by - change decode code ⟨20866⟩ = some (.JUMPI, none) - rw [hdec ⟨20866⟩ (by native_decide) (by native_decide)] - native_decide) - hcond - (by simp only [List.length_cons] at hov ⊢; omega) - exact uniswapV3PoolBurnLowerMaxLiquidityRevertTail - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (obsWord := obsWord) (tickLower := tickLower) (rdata := rdata) - (cA := cA) (σ := σ) hpatch rd20867 - (by simp only [List.length_cons] at hov ⊢; omega) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnZeroDeltaFinish.lean b/Benchmarks/UniswapV3Pool/BurnZeroDeltaFinish.lean deleted file mode 100644 index 52eff89a..00000000 --- a/Benchmarks/UniswapV3Pool/BurnZeroDeltaFinish.lean +++ /dev/null @@ -1,621 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnSourceSuccess -import Benchmarks.UniswapV3Pool.BurnPositionUpdateTokensOwedBridge - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnZeroDeltaPositionUpdateFinish - {v : PoolImmutables} - {cA : Batteries.RBSet AccountAddress compare} {gh : BlockHeader} - {bl : ProcessedBlocks} {σ_evm σ_solm σ₀ lockedEvm lockedSolm : AccountMap} - {A : Substate} {I : ExecutionEnv} {g tokensOwed0 tokensOwed1 : UInt256} - {feeGrowthInside0 feeGrowthInside1 positionBase : UInt256} {code : ByteArray} - (hcode : I.code = code) - (hdispatch : dispatchMsg (contract v) I.calldata = some burnTransition) - (hdecode : - decodeCalldataWithMode (config v).abiDecodeMode - (List.map Param.name burnTransition.params) - (transitionSignature burnTransition).paramTypes I.calldata = - some (burnStore I)) - (hwv : I.weiValue = ⟨0⟩) - (hunlockedSolm : burnUnlockedByte σ_solm I ≠ ⟨0⟩) - (hcanon : UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hnoDelegate : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hLowerMin : ¬ tickSpacingSint24Value (burnTickLowerWord I) < -887272) - (hUpperMax : ¬ 887272 < tickSpacingSint24Value (burnTickUpperWord I)) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hAccountsLocked : accountMapEquiv lockedEvm lockedSolm) - (hlockedSolm : - lockedSolm = - sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) - (hfee0 : feeGrowthInside0 = burnTickGetInside0Word lockedEvm I) - (hfee1 : feeGrowthInside1 = burnTickGetInside1Word lockedEvm I) - (hPositionBase : positionBase = positionsBase (burnPositionKeyKey I)) - (hliq : - burnPositionUpdateSlot0Packed (solcSlotWord lockedEvm I positionBase) ≠ ⟨0⟩) - (hlow0 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed0) - (hlow1 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I (positionBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed1) - (hrdSuccessCases : - (RDret code (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (cA, sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner lockedEvm - (positionBase + (⟨1⟩ : UInt256)) feeGrowthInside0) - (positionBase + (⟨2⟩ : UInt256)) feeGrowthInside1) - ⟨0⟩ - (burnPostPositionUpdateUnlockedSlotWord - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner lockedEvm - (positionBase + (⟨1⟩ : UInt256)) feeGrowthInside0) - (positionBase + (⟨2⟩ : UInt256)) feeGrowthInside1) - I)) - (UInt256.toByteArray (⟨0⟩ : UInt256) ++ - UInt256.toByteArray (⟨0⟩ : UInt256)) ∧ - UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 = ⟨0⟩ ∧ - UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 = ⟨0⟩) ∨ - (RDret code (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (cA, sstoreAccountMap I.codeOwner - (burnPostPositionUpdateTokensOwedAccountMap I - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner lockedEvm - (positionBase + (⟨1⟩ : UInt256)) feeGrowthInside0) - (positionBase + (⟨2⟩ : UInt256)) feeGrowthInside1) - positionBase tokensOwed0 tokensOwed1) - ⟨0⟩ - (burnPostPositionUpdateUnlockedSlotWord - (burnPostPositionUpdateTokensOwedAccountMap I - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner lockedEvm - (positionBase + (⟨1⟩ : UInt256)) feeGrowthInside0) - (positionBase + (⟨2⟩ : UInt256)) feeGrowthInside1) - positionBase tokensOwed0 tokensOwed1) - I)) - (UInt256.toByteArray (⟨0⟩ : UInt256) ++ - UInt256.toByteArray (⟨0⟩ : UInt256)) ∧ - (UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 ≠ ⟨0⟩ ∨ - UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 ≠ ⟨0⟩))) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hinside0 : - burnTickGetInside0Value lockedSolm I = - .int (Int.ofNat feeGrowthInside0.toNat) := by - rw [burnTickGetInside0Value_eq_word] - rw [← burnTickGetInside0Word_eq_of_accountMapEquiv hAccountsLocked I] - rw [hfee0] - have hinside1 : - burnTickGetInside1Value lockedSolm I = - .int (Int.ofNat feeGrowthInside1.toNat) := by - rw [burnTickGetInside1Value_eq_word] - rw [← burnTickGetInside1Word_eq_of_accountMapEquiv hAccountsLocked I] - rw [hfee1] - have hliqSolm : - burnPositionUpdateSlot0Packed - (solcSlotWord lockedSolm I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩ := by - have hslot := solcSlotWord_eq_of_accountMapEquiv hAccountsLocked I - (positionsBase (burnPositionKeyKey I)) - have hliqEvm : - burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I (positionsBase (burnPositionKeyKey I))) ≠ ⟨0⟩ := by - simpa [hPositionBase] using hliq - intro hzeroSlot - exact hliqEvm (by rwa [hslot]) - rcases hrdSuccessCases with hzeroTokens | hsomeTokens - · rcases hzeroTokens with ⟨hrdRet, htokens0, htokens1⟩ - have htokens0Src : - burnPositionUpdateSourceTokensOwed0Int lockedSolm I - (Int.ofNat feeGrowthInside0.toNat) = 0 := by - rw [← burnPositionUpdateSourceTokensOwed0Int_eq_of_accountMapEquiv - hAccountsLocked I (Int.ofNat feeGrowthInside0.toNat)] - exact burnPositionUpdateSourceTokensOwed0Int_eq_zero_of_mask_eq_zero - (by simpa [hPositionBase] using hlow0.trans htokens0) - have htokens1Src : - burnPositionUpdateSourceTokensOwed1Int lockedSolm I - (Int.ofNat feeGrowthInside1.toNat) = 0 := by - rw [← burnPositionUpdateSourceTokensOwed1Int_eq_of_accountMapEquiv - hAccountsLocked I (Int.ofNat feeGrowthInside1.toNat)] - exact burnPositionUpdateSourceTokensOwed1Int_eq_zero_of_mask_eq_zero - (by simpa [hPositionBase] using hlow1.trans htokens1) - let evmFeesSolm := - Solm.EVM.storageStore - (Solm.EVM.storageStore - (initState cA gh bl lockedSolm σ₀ (Sat256.ofUInt256 g) A I) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨1⟩) - feeGrowthInside0) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1 - let evmFeesEvm : AccountMap := - sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner lockedEvm - (positionBase + (⟨1⟩ : UInt256)) feeGrowthInside0) - (positionBase + (⟨2⟩ : UInt256)) feeGrowthInside1 - have hbody := - uniswapV3PoolBurnSourceZeroDeltaReturnsZeroTokens (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) feeGrowthInside0 feeGrowthInside1 - hwv hunlockedSolm hcanon - (by simpa [hlockedSolm] using hinside0) - (by simpa [hlockedSolm] using hinside1) - hnoDelegate htickLt hLowerMin hUpperMax hzero - (by simpa [hlockedSolm] using hliqSolm) - (by simpa [hlockedSolm] using htokens0Src) - (by simpa [hlockedSolm] using htokens1Src) - have hfeesAccounts : accountMapEquiv evmFeesEvm evmFeesSolm.accountMap := by - have hstores := - accountMapEquiv_sstoreAccountMap I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1 - (accountMapEquiv_sstoreAccountMap I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) - feeGrowthInside0 hAccountsLocked) - simpa [evmFeesEvm, evmFeesSolm, storageStore_accountMap, initState, - hPositionBase] using hstores - have hfinalAccounts : - accountMapEquiv - (sstoreAccountMap I.codeOwner evmFeesEvm ⟨0⟩ - (burnPostPositionUpdateUnlockedSlotWord evmFeesEvm I)) - (slot0AfterUnlockState evmFeesSolm).accountMap := by - exact burnPostPositionUpdateFinalAccountMapEquiv - (evm := evmFeesSolm) (σ := evmFeesEvm) (I := I) - hfeesAccounts - (by simp [evmFeesSolm, storageStore_executionEnv, initState]) - exact hrdRet.reEquivExecutionGenAccountMapEquiv - hcode hdispatch hdecode hbody - (by - simp [slot0AfterUnlockState, - storageStore_createdAccounts, initState]) - (by simpa [evmFeesEvm, evmFeesSolm, hlockedSolm] using hfinalAccounts) - (by - rw [show burnTransition.returnType = [uint256, uint256] from rfl] - exact returnEquiv.returned rfl (by native_decide)) - · rcases hsomeTokens with ⟨hrdRet, htokens⟩ - let evmFeesSolm := - Solm.EVM.storageStore - (Solm.EVM.storageStore - (initState cA gh bl lockedSolm σ₀ (Sat256.ofUInt256 g) A I) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨1⟩) - feeGrowthInside0) - I.codeOwner (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1 - let evmFeesEvm : AccountMap := - sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner lockedEvm - (positionBase + (⟨1⟩ : UInt256)) feeGrowthInside0) - (positionBase + (⟨2⟩ : UInt256)) feeGrowthInside1 - have hcond : - evalExpr? (config v) - (burnPositionUpdateValueAfterTokensOwed1Frame v - lockedSolm I (Int.ofNat feeGrowthInside0.toNat) - (Int.ofNat feeGrowthInside1.toNat)) - evmFeesSolm - (orE (gtE (.var "tokensOwed0") (.intLit 0)) - (gtE (.var "tokensOwed1") (.intLit 0))) = - .ok (.bool true) := by - rcases htokens with htokens0 | htokens1 - · have hpos0 : - 0 < burnPositionUpdateSourceTokensOwed0Int lockedSolm I - (Int.ofNat feeGrowthInside0.toNat) := by - rw [← burnPositionUpdateSourceTokensOwed0Int_eq_of_accountMapEquiv - hAccountsLocked I (Int.ofNat feeGrowthInside0.toNat)] - exact burnPositionUpdateSourceTokensOwed0Int_pos_of_mask_ne_zero - (by - intro hfast0 - have hfast0' : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I - (positionBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = ⟨0⟩ := by - simpa [hPositionBase] using hfast0 - exact htokens0 (by rwa [← hlow0])) - exact - burnPositionUpdateValue_evalTokensOwedGtTrueAfterTokensOwed1_left - (v := v) (evm := evmFeesSolm) (σ := lockedSolm) (I := I) - feeGrowthInside0 feeGrowthInside1 hpos0 - · have hpos1 : - 0 < burnPositionUpdateSourceTokensOwed1Int lockedSolm I - (Int.ofNat feeGrowthInside1.toNat) := by - rw [← burnPositionUpdateSourceTokensOwed1Int_eq_of_accountMapEquiv - hAccountsLocked I (Int.ofNat feeGrowthInside1.toNat)] - exact burnPositionUpdateSourceTokensOwed1Int_pos_of_mask_ne_zero - (by - intro hfast1 - have hfast1' : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I - (positionBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = ⟨0⟩ := by - simpa [hPositionBase] using hfast1 - exact htokens1 (by rwa [← hlow1])) - by_cases hpos0 : - 0 < burnPositionUpdateSourceTokensOwed0Int lockedSolm I - (Int.ofNat feeGrowthInside0.toNat) - · exact - burnPositionUpdateValue_evalTokensOwedGtTrueAfterTokensOwed1_left - (v := v) (evm := evmFeesSolm) (σ := lockedSolm) (I := I) - feeGrowthInside0 feeGrowthInside1 hpos0 - · have hnonneg0 : - 0 ≤ burnPositionUpdateSourceTokensOwed0Int lockedSolm I - (Int.ofNat feeGrowthInside0.toNat) := by - rw [burnPositionUpdateSourceTokensOwed0Int_eq_maskedWord] - exact Int.natCast_nonneg _ - have hzero0 : - burnPositionUpdateSourceTokensOwed0Int lockedSolm I - (Int.ofNat feeGrowthInside0.toNat) = 0 := by - omega - exact - burnPositionUpdateValue_evalTokensOwedGtTrueAfterTokensOwed1_right - (v := v) (evm := evmFeesSolm) (σ := lockedSolm) (I := I) - feeGrowthInside0 feeGrowthInside1 hzero0 hpos1 - have hbody := - uniswapV3PoolBurnSourceZeroDeltaReturnsTokensOwed (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) - (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) feeGrowthInside0 feeGrowthInside1 - hwv hunlockedSolm hcanon - (by simpa [hlockedSolm] using hinside0) - (by simpa [hlockedSolm] using hinside1) - hnoDelegate htickLt hLowerMin hUpperMax hzero - (by simpa [hlockedSolm] using hliqSolm) - (by simpa [hlockedSolm, evmFeesSolm] using hcond) - have hfeesAccounts : accountMapEquiv evmFeesEvm evmFeesSolm.accountMap := by - have hstores := - accountMapEquiv_sstoreAccountMap I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨2⟩) - feeGrowthInside1 - (accountMapEquiv_sstoreAccountMap I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) - feeGrowthInside0 hAccountsLocked) - simpa [evmFeesEvm, evmFeesSolm, storageStore_accountMap, initState, - hPositionBase] using hstores - let evmFeesEvmState : EVM.State := { evmFeesSolm with - accountMap := evmFeesEvm } - have hfeesState : EVMStateEquiv evmFeesEvmState evmFeesSolm := by - refine ⟨?_, ?_, hfeesAccounts⟩ <;> simp [evmFeesEvmState] - have hownerSolm : - ∃ acc, σ_solm.find? I.codeOwner = some acc := - accountMap_find?_codeOwner_exists_of_burnUnlockedByte_ne_zero - hunlockedSolm - have hownerLocked : - ∃ acc, lockedSolm.find? I.codeOwner = some acc := by - simpa [hlockedSolm] using - sstoreAccountMap_find?_same_exists (σ := σ_solm) - (addr := I.codeOwner) (slot := ⟨0⟩) - (val := burnLockedSlotWord σ_solm I) hownerSolm - have hownerInit : - ∃ acc, - (initState cA gh bl lockedSolm σ₀ (Sat256.ofUInt256 g) A I).accountMap.find? - (initState cA gh bl lockedSolm σ₀ (Sat256.ofUInt256 g) A I).executionEnv.codeOwner = - some acc := by - simpa [initState] using hownerLocked - have hownerFee0 : - ∃ acc, - (Solm.EVM.storageStore - (initState cA gh bl lockedSolm σ₀ (Sat256.ofUInt256 g) A I) - I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) - feeGrowthInside0).accountMap.find? - (Solm.EVM.storageStore - (initState cA gh bl lockedSolm σ₀ (Sat256.ofUInt256 g) A I) - I.codeOwner - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) - feeGrowthInside0).executionEnv.codeOwner = - some acc := by - simpa [initState] using - storageStore_codeOwner_find?_exists hownerInit - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) feeGrowthInside0 - have hownerFees : - ∃ acc, - evmFeesSolm.accountMap.find? evmFeesSolm.executionEnv.codeOwner = - some acc := by - simpa [evmFeesSolm, storageStore_executionEnv] using - storageStore_codeOwner_find?_exists hownerFee0 - (positionsBase (burnPositionKeyKey I) + ⟨2⟩) feeGrowthInside1 - have hload0 : - Solm.EVM.storageLoad - (burnPositionUpdateSourceAfterTokensOwed0State evmFeesSolm - lockedSolm I feeGrowthInside0) - (burnPositionUpdateSourceAfterTokensOwed0State evmFeesSolm - lockedSolm I feeGrowthInside0).executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I) = - burnPositionUpdateSourceTokensOwed0StoreWord evmFeesSolm lockedSolm - I feeGrowthInside0 := by - rcases hownerFees with ⟨accFees, haccFees⟩ - unfold burnPositionUpdateSourceAfterTokensOwed0State - simpa [evmFeesSolm, storageStore_executionEnv] using - storageLoad_storageStore_same_present evmFeesSolm - evmFeesSolm.executionEnv.codeOwner - haccFees - (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateSourceTokensOwed0StoreWord evmFeesSolm lockedSolm - I feeGrowthInside0) - have hslotBaseSolm : - solcSlotWord lockedSolm I (positionsBase (burnPositionKeyKey I)) = - solcSlotWord lockedEvm I positionBase := by - rw [← solcSlotWord_eq_of_accountMapEquiv hAccountsLocked I - (positionsBase (burnPositionKeyKey I))] - rw [hPositionBase] - have hslot1Solm : - solcSlotWord lockedSolm I - (positionsBase (burnPositionKeyKey I) + ⟨1⟩) = - solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)) := by - rw [← solcSlotWord_eq_of_accountMapEquiv hAccountsLocked I - (positionsBase (burnPositionKeyKey I) + ⟨1⟩)] - rw [hPositionBase] - have hslot2Solm : - solcSlotWord lockedSolm I - (positionsBase (burnPositionKeyKey I) + ⟨2⟩) = - solcSlotWord lockedEvm I (positionBase + (⟨2⟩ : UInt256)) := by - rw [← solcSlotWord_eq_of_accountMapEquiv hAccountsLocked I - (positionsBase (burnPositionKeyKey I) + ⟨2⟩)] - rw [hPositionBase] - have hword := - burnPositionUpdateSourceTokensOwedFinalStoreWord_eq_addedSlot3_of_low128 - evmFeesSolm lockedSolm I feeGrowthInside0 feeGrowthInside1 - tokensOwed0 tokensOwed1 hload0 - (by simpa [hslotBaseSolm, hslot1Solm, hPositionBase] using hlow0) - (by simpa [hslotBaseSolm, hslot2Solm, hPositionBase] using hlow1) - have hloadFees := - EVMStateEquiv.storageLoad_codeOwner hfeesState - (burnPositionUpdateSourceTokensOwedSlot I) - have hwordForState : - burnPositionUpdateSourceTokensOwed1StoreWord - (burnPositionUpdateSourceAfterTokensOwed0State evmFeesSolm - lockedSolm I feeGrowthInside0) - lockedSolm I feeGrowthInside1 = - burnPositionUpdateTokensOwedAddedSlot3 - (Solm.EVM.storageLoad evmFeesEvmState - evmFeesEvmState.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I)) - tokensOwed0 tokensOwed1 := by - rw [hloadFees] - exact hword - have htokensAccountsSource := - burnPositionUpdateTokensOwedAccountMapEquiv_of_addedSlot3 - (evmEvm := evmFeesEvmState) (evmSolm := evmFeesSolm) - (σ := lockedSolm) (I := I) - (feeGrowthInside0X128 := feeGrowthInside0) - (feeGrowthInside1X128 := feeGrowthInside1) - (tokensOwed0 := tokensOwed0) (tokensOwed1 := tokensOwed1) - hfeesState hwordForState - let evmTokensSolm := - burnPositionUpdateSourceAfterTokensOwedState evmFeesSolm lockedSolm I - feeGrowthInside0 feeGrowthInside1 - let evmTokensEvm : AccountMap := - sstoreAccountMap evmFeesEvmState.executionEnv.codeOwner - evmFeesEvmState.accountMap - (burnPositionUpdateSourceTokensOwedSlot I) - (burnPositionUpdateTokensOwedAddedSlot3 - (Solm.EVM.storageLoad evmFeesEvmState - evmFeesEvmState.executionEnv.codeOwner - (burnPositionUpdateSourceTokensOwedSlot I)) - tokensOwed0 tokensOwed1) - have htokensAccounts : - accountMapEquiv evmTokensEvm evmTokensSolm.accountMap := by - simpa [evmTokensEvm, evmTokensSolm] using htokensAccountsSource - have htokensEvmPost : - evmTokensEvm = - burnPostPositionUpdateTokensOwedAccountMap I evmFeesEvm positionBase - tokensOwed0 tokensOwed1 := by - simp [evmTokensEvm, burnPostPositionUpdateTokensOwedAccountMap, - evmFeesEvmState, evmFeesSolm, burnPositionUpdateSourceTokensOwedSlot, - Solm.EVM.storageLoad, State.lookupAccount, solcSlotWord, - Account.lookupStorage, storageStore_executionEnv, initState, - hPositionBase] - have hfinalAccounts : - accountMapEquiv - (sstoreAccountMap I.codeOwner evmTokensEvm ⟨0⟩ - (burnPostPositionUpdateUnlockedSlotWord evmTokensEvm I)) - (slot0AfterUnlockState evmTokensSolm).accountMap := by - exact burnPostPositionUpdateFinalAccountMapEquiv - (evm := evmTokensSolm) (σ := evmTokensEvm) (I := I) - htokensAccounts - (by simp [evmTokensSolm, evmFeesSolm, - burnPositionUpdateSourceAfterTokensOwedState, - burnPositionUpdateSourceAfterTokensOwed0State, - storageStore_executionEnv, initState]) - have hfinalAccountsPost : - accountMapEquiv - (sstoreAccountMap I.codeOwner - (burnPostPositionUpdateTokensOwedAccountMap I evmFeesEvm - positionBase tokensOwed0 tokensOwed1) - ⟨0⟩ - (burnPostPositionUpdateUnlockedSlotWord - (burnPostPositionUpdateTokensOwedAccountMap I evmFeesEvm - positionBase tokensOwed0 tokensOwed1) - I)) - (slot0AfterUnlockState evmTokensSolm).accountMap := by - simpa [htokensEvmPost] using hfinalAccounts - exact hrdRet.reEquivExecutionGenAccountMapEquiv - hcode hdispatch hdecode hbody - (by - simp [slot0AfterUnlockState, - burnPositionUpdateSourceAfterTokensOwedState, - burnPositionUpdateSourceAfterTokensOwed0State, - storageStore_createdAccounts, initState]) - (by - simpa [burnPostPositionUpdateTokensOwedAccountMap, evmFeesEvm, - evmTokensSolm, evmFeesSolm, hlockedSolm] using hfinalAccountsPost) - (by - rw [show burnTransition.returnType = [uint256, uint256] from rfl] - exact returnEquiv.returned rfl (by native_decide)) - -theorem uniswapV3PoolBurnZeroDeltaMulDivReturnToRuntimeFinish - {v : PoolImmutables} - {cA : Batteries.RBSet AccountAddress compare} {gh : BlockHeader} - {bl : ProcessedBlocks} {σ_evm σ_solm σ₀ lockedEvm lockedSolm : AccountMap} - {A : Substate} {I : ExecutionEnv} {g tokensOwed0 tokensOwed1 : UInt256} - {feeGrowthInside0 feeGrowthInside1 positionBase : UInt256} {code : ByteArray} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) - (hperm : I.perm = true) - (hdispatch : dispatchMsg (contract v) I.calldata = some burnTransition) - (hdecode : - decodeCalldataWithMode (config v).abiDecodeMode - (List.map Param.name burnTransition.params) - (transitionSignature burnTransition).paramTypes I.calldata = - some (burnStore I)) - (hwv : I.weiValue = ⟨0⟩) - (hunlockedSolm : burnUnlockedByte σ_solm I ≠ ⟨0⟩) - (hcanon : UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hnoDelegate : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hLowerMin : ¬ tickSpacingSint24Value (burnTickLowerWord I) < -887272) - (hUpperMax : ¬ 887272 < tickSpacingSint24Value (burnTickUpperWord I)) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hAccountsLocked : accountMapEquiv lockedEvm lockedSolm) - (hlockedSolm : - lockedSolm = - sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) - (hfee0 : feeGrowthInside0 = burnTickGetInside0Word lockedEvm I) - (hfee1 : feeGrowthInside1 = burnTickGetInside1Word lockedEvm I) - (hPositionBase : positionBase = positionsBase (burnPositionKeyKey I)) - (hliq : - burnPositionUpdateSlot0Packed (solcSlotWord lockedEvm I positionBase) ≠ ⟨0⟩) - (hrd21861 : - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - ⟨21861⟩ - (tokensOwed1 :: tokensOwed0 :: - burnPositionUpdateSlot0Packed (solcSlotWord lockedEvm I positionBase) :: - burnPositionKeyNewFreePtrWord :: feeGrowthInside1 :: feeGrowthInside0 :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - positionBase :: ⟨19527⟩ :: feeGrowthInside1 :: feeGrowthInside0 :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord lockedEvm I ⟨2⟩ :: solcSlotWord lockedEvm I ⟨1⟩ :: - positionBase :: slot0TickReturnWord lockedEvm I :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnPositionUpdateMem5 lockedEvm I (solcSlotWord lockedEvm I positionBase) - positionBase) - (UInt256.ofNat 22) ByteArray.empty - (cA, sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner lockedEvm - (positionBase + (⟨1⟩ : UInt256)) feeGrowthInside0) - (positionBase + (⟨2⟩ : UInt256)) feeGrowthInside1) k C) - (hlow0 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed0) - (hlow1 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I (positionBase + (⟨2⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I positionBase))) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed1) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hmload224 := burnPositionUpdateMem5_mload224 lockedEvm I - (solcSlotWord lockedEvm I positionBase) positionBase - have hdelta : - UInt256.slt - (UInt256.signextend ⟨15⟩ - (UInt256.signextend ⟨15⟩ - (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)))) - ⟨0⟩ = ⟨0⟩ := by - rw [hzero] - native_decide - have hdest9737 : - (D_J code 0).contains (⟨9737⟩ : UInt256) = true := by - have hpreserve : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode - uniswapV3PoolPatchOffsets (⟨9737⟩ : UInt256) 0 = - true := by - native_decide - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) hpreserve - have hrdSuccessCases := - uniswapV3PoolBurnZeroDeltaPositionUpdateToFinalReturnCases - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (tokensOwed1 := tokensOwed1) (tokensOwed0 := tokensOwed0) - (liquidity := burnPositionUpdateSlot0Packed (solcSlotWord lockedEvm I positionBase)) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (delta := UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (posBase := positionBase) - (inside1' := feeGrowthInside1) (inside0' := feeGrowthInside0) - (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord lockedEvm I ⟨2⟩) - (fee0 := solcSlotWord lockedEvm I ⟨1⟩) - (tick := slot0TickReturnWord lockedEvm I) - (delta' := UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I))) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (free := ⟨256⟩) (r3 := ⟨0⟩) - (amount := burnAmountCleanWord I) (eventUpper := burnTickUpperCleanWord I) - (eventLower := burnTickLowerCleanWord I) (R := [solcSelectorWord I]) - (σmem := lockedEvm) (pos0 := solcSlotWord lockedEvm I positionBase) - (rdata := ByteArray.empty) (cA := cA) - (σ := sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner lockedEvm - (positionBase + (⟨1⟩ : UInt256)) feeGrowthInside0) - (positionBase + (⟨2⟩ : UInt256)) feeGrowthInside1) - hpatch hdest9737 hperm hzero hmload224 hrd21861 hdelta - (by simp only [List.length_singleton]; omega) - exact - uniswapV3PoolBurnZeroDeltaPositionUpdateFinish - (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) - (lockedEvm := lockedEvm) (lockedSolm := lockedSolm) - (A := A) (I := I) (g := g) - (tokensOwed0 := tokensOwed0) (tokensOwed1 := tokensOwed1) - (feeGrowthInside0 := feeGrowthInside0) (feeGrowthInside1 := feeGrowthInside1) - (positionBase := positionBase) (code := code) - hcode hdispatch hdecode hwv hunlockedSolm hcanon hnoDelegate - htickLt hLowerMin hUpperMax hzero hAccountsLocked hlockedSolm - hfee0 hfee1 hPositionBase (by simpa using hliq) hlow0 hlow1 - hrdSuccessCases - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnZeroDeltaMulDivStart.lean b/Benchmarks/UniswapV3Pool/BurnZeroDeltaMulDivStart.lean deleted file mode 100644 index 4d8e0b2f..00000000 --- a/Benchmarks/UniswapV3Pool/BurnZeroDeltaMulDivStart.lean +++ /dev/null @@ -1,247 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnPositionUpdateTokensOwedBridge - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnZeroDeltaPositionUpdateToMulDiv0StartConcrete - {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord ee) < - tickSpacingSint24Value (burnTickUpperWord ee)) - (hzero : burnAmountCleanWord ee = ⟨0⟩) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)) ≠ ⟨0⟩) - (h : RD code ee g s0 ⟨21387⟩ - (solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - slot0TickReturnWord σ ee :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R) - (burnPositionKeyMappingMem σ ee) (UInt256.ofNat 18) rdata (cA, σ) k C) - (hov : R.length + 82 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨13017⟩ - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ :: - burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)) :: - UInt256.sub (burnTickGetInside0Word σ ee) - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee + (⟨1⟩ : UInt256))) :: - ⟨21769⟩ :: ⟨0⟩ :: - burnPositionUpdateSlot0Packed - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)) :: - burnPositionKeyNewFreePtrWord :: - burnTickGetInside1Word σ ee :: burnTickGetInside0Word σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - burnPositionBaseSlotWord σ ee :: ⟨19527⟩ :: - burnTickGetInside1Word σ ee :: burnTickGetInside0Word σ ee :: - ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord σ ee ⟨2⟩ :: solcSlotWord σ ee ⟨1⟩ :: - burnPositionBaseSlotWord σ ee :: slot0TickReturnWord σ ee :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee) :: - UInt256.ofNat ee.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R) - (burnPositionUpdateMem5 σ ee - (solcSlotWord σ ee (burnPositionBaseSlotWord σ ee)) - (burnPositionBaseSlotWord σ ee)) - (UInt256.ofNat 22) rdata (cA, σ) k' C' := by - let inside1 := burnTickGetInside1Word σ ee - let inside0 := burnTickGetInside0Word σ ee - let posBase := burnPositionBaseSlotWord σ ee - let delta := UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord ee)) - let postFreeR : List UInt256 := - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord ee :: burnTickUpperCleanWord ee :: - burnTickLowerCleanWord ee :: ret :: R - obtain ⟨_, _, hrdReturn⟩ := - uniswapV3PoolBurnFeeGrowthInsideEntryReturnConcrete - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (ret := ret) (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch htickLt h (by omega) - obtain ⟨_, _, hrdEntry⟩ := - uniswapV3PoolBurnFeeGrowthInsideEnterPositionUpdate - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) - (z0 := ⟨0⟩) (z1 := ⟨0⟩) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase := posBase) (tick := slot0TickReturnWord σ ee) - (delta := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) - hpatch - (by simpa [inside1, inside0, posBase, delta] using hrdReturn) - (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdSlot0⟩ := - uniswapV3PoolBurnPositionUpdateLoadSlot0 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdEntry (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdPacked⟩ := - uniswapV3PoolBurnPositionUpdateStoreSlot0Packed - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (pos0 := solcSlotWord σ ee posBase) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdSlot0 (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdFee0⟩ := - uniswapV3PoolBurnPositionUpdateStoreFeeGrowthInside0Last - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch (by simpa [inside1, inside0, posBase, delta] using hrdPacked) - (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdFee1⟩ := - uniswapV3PoolBurnPositionUpdateStoreFeeGrowthInside1Last - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdFee0 (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdTokens0⟩ := - uniswapV3PoolBurnPositionUpdateStoreTokensOwed0 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdFee1 (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdTokens1⟩ := - uniswapV3PoolBurnPositionUpdateStoreTokensOwed1 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdTokens0 (by simp [postFreeR] at hov ⊢; omega) - have hdelta : UInt256.signextend ⟨15⟩ delta = ⟨0⟩ := by - dsimp [delta] - rw [hzero] - native_decide - obtain ⟨_, _, hrdFallthrough⟩ := - uniswapV3PoolBurnPositionUpdateLiquidityDeltaZeroFallthrough - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hdelta hrdTokens1 (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdNonzero⟩ := - uniswapV3PoolBurnPositionUpdateLiquidityNonzeroJump - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hliq hrdFallthrough (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrdReload⟩ := - uniswapV3PoolBurnPositionUpdateReloadLiquidity - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdNonzero (by simp [postFreeR] at hov ⊢; omega) - obtain ⟨_, _, hrd13017⟩ := - uniswapV3PoolBurnPositionUpdateStartMulDiv0 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (inside1 := inside1) (inside0 := inside0) (delta := delta) - (posBase := posBase) (retPos := ⟨19527⟩) - (inside1' := inside1) (inside0' := inside0) (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord σ ee ⟨2⟩) (fee0 := solcSlotWord σ ee ⟨1⟩) - (posBase' := posBase) (tick := slot0TickReturnWord σ ee) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord ee)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord ee)) - (owner := UInt256.ofNat ee.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := postFreeR) (rdata := rdata) (cA := cA) (σ := σ) - hpatch hrdReload (by simp [postFreeR] at hov ⊢; omega) - exact ⟨_, _, by simpa [inside1, inside0, posBase, delta, postFreeR] using hrd13017⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/BurnZeroDeltaSlowToken0.lean b/Benchmarks/UniswapV3Pool/BurnZeroDeltaSlowToken0.lean deleted file mode 100644 index f8120ed7..00000000 --- a/Benchmarks/UniswapV3Pool/BurnZeroDeltaSlowToken0.lean +++ /dev/null @@ -1,311 +0,0 @@ -import Benchmarks.UniswapV3Pool.BurnZeroDeltaMulDivStart -import Benchmarks.UniswapV3Pool.BurnZeroDeltaFinish -import Benchmarks.UniswapV3Pool.BurnPositionUpdateSlowPostReturn - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolBurnZeroDeltaPositionUpdateSlowToken0Runtime - {v : PoolImmutables} - {cA : Batteries.RBSet AccountAddress compare} {gh : BlockHeader} - {bl : ProcessedBlocks} {σ_evm σ_solm σ₀ lockedEvm lockedSolm : AccountMap} - {A : Substate} {I : ExecutionEnv} {g : UInt256} {code : ByteArray} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) - (hperm : I.perm = true) - (hdispatch : dispatchMsg (contract v) I.calldata = some burnTransition) - (hdecode : - decodeCalldataWithMode (config v).abiDecodeMode - (List.map Param.name burnTransition.params) - (transitionSignature burnTransition).paramTypes I.calldata = - some (burnStore I)) - (hwv : I.weiValue = ⟨0⟩) - (hunlockedSolm : burnUnlockedByte σ_solm I ≠ ⟨0⟩) - (hcanon : UInt256.signextend ⟨15⟩ (burnAmountCleanWord I) = burnAmountCleanWord I) - (hnoDelegate : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) - (htickLt : - tickSpacingSint24Value (burnTickLowerWord I) < - tickSpacingSint24Value (burnTickUpperWord I)) - (hLowerMin : ¬ tickSpacingSint24Value (burnTickLowerWord I) < -887272) - (hUpperMax : ¬ 887272 < tickSpacingSint24Value (burnTickUpperWord I)) - (hzero : burnAmountCleanWord I = ⟨0⟩) - (hAccountsLocked : accountMapEquiv lockedEvm lockedSolm) - (hlockedSolm : - lockedSolm = - sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ (burnLockedSlotWord σ_solm I)) - (hliq : - burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I (burnPositionBaseSlotWord lockedEvm I)) ≠ ⟨0⟩) - (hprod0 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub (burnTickGetInside0Word lockedEvm I) - (solcSlotWord lockedEvm I - (burnPositionBaseSlotWord lockedEvm I + (⟨1⟩ : UInt256)))) - (burnPositionUpdateSlot0Packed - (solcSlotWord lockedEvm I (burnPositionBaseSlotWord lockedEvm I))) ≠ ⟨0⟩) - (hrdFeeGrowthEntry : - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨21387⟩ - (solcSlotWord lockedEvm I ⟨2⟩ :: solcSlotWord lockedEvm I ⟨1⟩ :: - slot0TickReturnWord lockedEvm I :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - ⟨5⟩ :: ⟨19510⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - solcSlotWord lockedEvm I ⟨2⟩ :: solcSlotWord lockedEvm I ⟨1⟩ :: - burnPositionBaseSlotWord lockedEvm I :: slot0TickReturnWord lockedEvm I :: - UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) :: - UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I) :: - UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I) :: - UInt256.ofNat I.source.val :: ⟨16428⟩ :: ⟨256⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I]) - (burnPositionKeyMappingMem lockedEvm I) (UInt256.ofNat 18) ByteArray.empty - (cA, lockedEvm) k C) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - let positionBase := burnPositionBaseSlotWord lockedEvm I - let feeGrowthInside1 := burnTickGetInside1Word lockedEvm I - let feeGrowthInside0 := burnTickGetInside0Word lockedEvm I - let liquidity := burnPositionUpdateSlot0Packed (solcSlotWord lockedEvm I positionBase) - let delta := UInt256.signextend ⟨15⟩ (UInt256.sub ⟨0⟩ (burnAmountCleanWord I)) - let positionUpdateR : List UInt256 := - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨128⟩ :: ⟨9737⟩ :: - ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: ⟨0⟩ :: - burnAmountCleanWord I :: burnTickUpperCleanWord I :: - burnTickLowerCleanWord I :: ⟨621⟩ :: [solcSelectorWord I] - have hPositionBase : positionBase = positionsBase (burnPositionKeyKey I) := by - simpa [positionBase] using burnPositionBaseSlotWord_eq_positionsBase lockedEvm I - have hliqBound : liquidity.toNat < 2 ^ (128 : Nat) := by - dsimp [liquidity, positionBase] - change - (UInt256.land burnPositionUpdateSlot0Mask - (solcSlotWord lockedEvm I (burnPositionBaseSlotWord lockedEvm I))).toNat < - 2 ^ (128 : Nat) - rw [burnPositionUpdateSlot0Mask_eq_uint128Mask] - rw [u256_land_comm] - simpa [EVM.twoPow] using - uint128Mask_bound (solcSlotWord lockedEvm I (burnPositionBaseSlotWord lockedEvm I)) - have hden0 : - UInt256.gt (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - liquidity) ≠ ⟨0⟩ := by - exact uniswapV3PoolFullMathMulDivProd1DenGtQ128 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - liquidity hliqBound - obtain ⟨_, _, hrd13017⟩ := - uniswapV3PoolBurnZeroDeltaPositionUpdateToMulDiv0StartConcrete - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨621⟩) (R := [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) (σ := lockedEvm) - hpatch htickLt hzero - (by simpa [positionBase, liquidity] using hliq) - (by simpa [positionBase] using hrdFeeGrowthEntry) - (by simp only [List.length_singleton]; omega) - have hdelta : UInt256.signextend ⟨15⟩ delta = ⟨0⟩ := by - dsimp [delta] - rw [hzero] - native_decide - by_cases hprod1 : - uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I (positionBase + (⟨2⟩ : UInt256)))) - liquidity = ⟨0⟩ - · let tokensOwed0 : UInt256 := - uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - liquidity) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - liquidity) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) liquidity - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - let tokensOwed1 : UInt256 := - UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I (positionBase + (⟨2⟩ : UInt256)))) - liquidity) - (UInt256.shiftLeft ⟨1⟩ ⟨128⟩) - obtain ⟨_, _, hrd21861⟩ := - uniswapV3PoolBurnPositionUpdateMulDiv0Prod1NonzeroMulDiv1Prod1ZeroStoreFeeGrowthLast - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (delta := delta) (posBase := positionBase) (retPos := ⟨19527⟩) - (inside1' := feeGrowthInside1) (inside0' := feeGrowthInside0) - (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord lockedEvm I ⟨2⟩) - (fee0 := solcSlotWord lockedEvm I ⟨1⟩) - (posBase' := positionBase) (tick := slot0TickReturnWord lockedEvm I) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := positionUpdateR) (rdata := ByteArray.empty) (cA := cA) (σ := lockedEvm) - hpatch hperm - (by simpa [feeGrowthInside1, feeGrowthInside0, positionBase, liquidity, delta, - positionUpdateR] using hrd13017) - (by simpa [feeGrowthInside0, positionBase, liquidity] using hprod0) - (by simpa [feeGrowthInside0, positionBase, liquidity] using hden0) - (by simpa [feeGrowthInside1, positionBase, liquidity] using hprod1) - hdelta - (by simp [positionUpdateR]) - have hlow0 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - liquidity) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 := by - simpa [tokensOwed0] using - (uniswapV3PoolFullMathMulDivSlowResult_low128_eq_prod0Div128 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - liquidity).symm - have hlow1 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I (positionBase + (⟨2⟩ : UInt256)))) - liquidity) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 := by - rfl - exact - uniswapV3PoolBurnZeroDeltaMulDivReturnToRuntimeFinish - (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) - (lockedEvm := lockedEvm) (lockedSolm := lockedSolm) - (A := A) (I := I) (g := g) - (tokensOwed0 := tokensOwed0) (tokensOwed1 := tokensOwed1) - (feeGrowthInside0 := feeGrowthInside0) (feeGrowthInside1 := feeGrowthInside1) - (positionBase := positionBase) (code := code) - hpatch hcode hperm hdispatch hdecode hwv hunlockedSolm hcanon hnoDelegate - htickLt hLowerMin hUpperMax hzero hAccountsLocked hlockedSolm - (by rfl) (by rfl) hPositionBase (by simpa [liquidity] using hliq) - (by simpa [tokensOwed0, tokensOwed1, feeGrowthInside1, feeGrowthInside0, - positionBase, liquidity, delta, positionUpdateR] using hrd21861) - hlow0 hlow1 - · let tokensOwed0 : UInt256 := - uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - liquidity) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - liquidity) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) liquidity - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - let tokensOwed1 : UInt256 := - uniswapV3PoolFullMathMulDivSlowResult - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I (positionBase + (⟨2⟩ : UInt256)))) - liquidity) - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I (positionBase + (⟨2⟩ : UInt256)))) - liquidity) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) liquidity - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I (positionBase + (⟨2⟩ : UInt256)))) - have hden1 : - UInt256.gt (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) - (uniswapV3PoolFullMathMulDivProd1 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I (positionBase + (⟨2⟩ : UInt256)))) - liquidity) ≠ ⟨0⟩ := by - exact uniswapV3PoolFullMathMulDivProd1DenGtQ128 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I (positionBase + (⟨2⟩ : UInt256)))) - liquidity hliqBound - obtain ⟨_, _, hrd21861⟩ := - uniswapV3PoolBurnPositionUpdateMulDiv0Prod1NonzeroMulDiv1Prod1NonzeroStoreFeeGrowthLast - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (inside1 := feeGrowthInside1) (inside0 := feeGrowthInside0) - (delta := delta) (posBase := positionBase) (retPos := ⟨19527⟩) - (inside1' := feeGrowthInside1) (inside0' := feeGrowthInside0) - (z2 := ⟨0⟩) (z3 := ⟨0⟩) - (fee1 := solcSlotWord lockedEvm I ⟨2⟩) - (fee0 := solcSlotWord lockedEvm I ⟨1⟩) - (posBase' := positionBase) (tick := slot0TickReturnWord lockedEvm I) - (delta' := delta) - (upper := UInt256.signextend ⟨2⟩ (burnTickUpperCleanWord I)) - (lower := UInt256.signextend ⟨2⟩ (burnTickLowerCleanWord I)) - (owner := UInt256.ofNat I.source.val) (ret := ⟨16428⟩) (free := ⟨256⟩) - (R := positionUpdateR) (rdata := ByteArray.empty) (cA := cA) (σ := lockedEvm) - hpatch hperm - (by simpa [feeGrowthInside1, feeGrowthInside0, positionBase, liquidity, delta, - positionUpdateR] using hrd13017) - (by simpa [feeGrowthInside0, positionBase, liquidity] using hprod0) - (by simpa [feeGrowthInside0, positionBase, liquidity] using hden0) - (by simpa [feeGrowthInside1, positionBase, liquidity] using hprod1) - (by simpa [feeGrowthInside1, positionBase, liquidity] using hden1) - hdelta - (by simp [positionUpdateR]) - have hlow0 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - liquidity) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed0 := by - simpa [tokensOwed0] using - (uniswapV3PoolFullMathMulDivSlowResult_low128_eq_prod0Div128 - (UInt256.sub feeGrowthInside0 - (solcSlotWord lockedEvm I (positionBase + (⟨1⟩ : UInt256)))) - liquidity).symm - have hlow1 : - UInt256.land burnPositionUpdateSlot0Mask - (UInt256.div - (uniswapV3PoolFullMathMulDivProd0 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I (positionBase + (⟨2⟩ : UInt256)))) - liquidity) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) = - UInt256.land burnPositionUpdateSlot0Mask tokensOwed1 := by - simpa [tokensOwed1] using - (uniswapV3PoolFullMathMulDivSlowResult_low128_eq_prod0Div128 - (UInt256.sub feeGrowthInside1 - (solcSlotWord lockedEvm I (positionBase + (⟨2⟩ : UInt256)))) - liquidity).symm - exact - uniswapV3PoolBurnZeroDeltaMulDivReturnToRuntimeFinish - (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) - (lockedEvm := lockedEvm) (lockedSolm := lockedSolm) - (A := A) (I := I) (g := g) - (tokensOwed0 := tokensOwed0) (tokensOwed1 := tokensOwed1) - (feeGrowthInside0 := feeGrowthInside0) (feeGrowthInside1 := feeGrowthInside1) - (positionBase := positionBase) (code := code) - hpatch hcode hperm hdispatch hdecode hwv hunlockedSolm hcanon hnoDelegate - htickLt hLowerMin hUpperMax hzero hAccountsLocked hlockedSolm - (by rfl) (by rfl) hPositionBase (by simpa [liquidity] using hliq) - (by simpa [tokensOwed0, tokensOwed1, feeGrowthInside1, feeGrowthInside0, - positionBase, liquidity, delta, positionUpdateR] using hrd21861) - hlow0 hlow1 - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Collect.lean b/Benchmarks/UniswapV3Pool/Collect.lean deleted file mode 100644 index c8b05da8..00000000 --- a/Benchmarks/UniswapV3Pool/Collect.lean +++ /dev/null @@ -1,18 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolCollectBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 10 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/CollectProtocol.lean b/Benchmarks/UniswapV3Pool/CollectProtocol.lean deleted file mode 100644 index bc1536a9..00000000 --- a/Benchmarks/UniswapV3Pool/CollectProtocol.lean +++ /dev/null @@ -1,18 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolCollectProtocolBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 15 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Common.lean b/Benchmarks/UniswapV3Pool/Common.lean deleted file mode 100644 index bfe7bb8f..00000000 --- a/Benchmarks/UniswapV3Pool/Common.lean +++ /dev/null @@ -1,1998 +0,0 @@ -import Benchmarks.UniswapV3Pool.Trusted -import Reasoning.ABI -import Reasoning.Dispatch -import Reasoning.Initcode -import Reasoning.JumpDest -import Reasoning.Memory -import Reasoning.Reach -import Reasoning.Solc -import Reasoning.SolmBody -import Mathlib.Tactic.IntervalCases - -/-! -# UniswapV3Pool shared proof facts - -Contract-wide selector, dispatch, and revert facts used by the top-level runtime proof and the -per-function body proofs. --/ - -open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach -open Benchmarks.UniswapV3Pool.Immutables - -set_option maxRecDepth 2000000 - -namespace Benchmarks.UniswapV3Pool - -/-- The 4-byte function selector word the dispatcher computes from `calldata[0:32]`. -/ -abbrev uniswapV3PoolSelWord (I : ExecutionEnv) : UInt256 := - UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes 0 32)) ⟨224⟩ - -/-- The 4-byte selector of `I`'s calldata equals `sel`. -/ -abbrev selIs (I : ExecutionEnv) (sel : ByteArray) : Prop := - (sel == I.calldata.extract 0 4) = true - -/-- UniswapV3Pool selectors in increasing selector order, matching the deployed dispatcher tree. -/ -def uniswapV3PoolSelBytes : ℕ → ByteArray - | 0 => ⟨#[0x0d, 0xfe, 0x16, 0x81]⟩ -- token0() - | 1 => ⟨#[0x12, 0x8a, 0xcb, 0x08]⟩ -- swap(address,bool,int256,uint160,bytes) - | 2 => ⟨#[0x1a, 0x68, 0x65, 0x02]⟩ -- liquidity() - | 3 => ⟨#[0x1a, 0xd8, 0xb0, 0x3b]⟩ -- protocolFees() - | 4 => ⟨#[0x25, 0x2c, 0x09, 0xd7]⟩ -- observations(uint256) - | 5 => ⟨#[0x32, 0x14, 0x8f, 0x67]⟩ -- increaseObservationCardinalityNext(uint16) - | 6 => ⟨#[0x38, 0x50, 0xc7, 0xbd]⟩ -- slot0() - | 7 => ⟨#[0x3c, 0x8a, 0x7d, 0x8d]⟩ -- mint(address,int24,int24,uint128,bytes) - | 8 => ⟨#[0x46, 0x14, 0x13, 0x19]⟩ -- feeGrowthGlobal1X128() - | 9 => ⟨#[0x49, 0x0e, 0x6c, 0xbc]⟩ -- flash(address,uint256,uint256,bytes) - | 10 => ⟨#[0x4f, 0x1e, 0xb3, 0xd8]⟩ -- collect(address,int24,int24,uint128,uint128) - | 11 => ⟨#[0x51, 0x4e, 0xa4, 0xbf]⟩ -- positions(bytes32) - | 12 => ⟨#[0x53, 0x39, 0xc2, 0x96]⟩ -- tickBitmap(int16) - | 13 => ⟨#[0x70, 0xcf, 0x75, 0x4a]⟩ -- maxLiquidityPerTick() - | 14 => ⟨#[0x82, 0x06, 0xa4, 0xd1]⟩ -- setFeeProtocol(uint8,uint8) - | 15 => ⟨#[0x85, 0xb6, 0x67, 0x29]⟩ -- collectProtocol(address,uint128,uint128) - | 16 => ⟨#[0x88, 0x3b, 0xdb, 0xfd]⟩ -- observe(uint32[]) - | 17 => ⟨#[0xa3, 0x41, 0x23, 0xa7]⟩ -- burn(int24,int24,uint128) - | 18 => ⟨#[0xa3, 0x88, 0x07, 0xf2]⟩ -- snapshotCumulativesInside(int24,int24) - | 19 => ⟨#[0xc4, 0x5a, 0x01, 0x55]⟩ -- factory() - | 20 => ⟨#[0xd0, 0xc9, 0x3a, 0x7c]⟩ -- tickSpacing() - | 21 => ⟨#[0xd2, 0x12, 0x20, 0xa7]⟩ -- token1() - | 22 => ⟨#[0xdd, 0xca, 0x3f, 0x43]⟩ -- fee() - | 23 => ⟨#[0xf3, 0x05, 0x83, 0x99]⟩ -- feeGrowthGlobal0X128() - | 24 => ⟨#[0xf3, 0x0d, 0xba, 0x93]⟩ -- ticks(int24) - | _ => ⟨#[0xf6, 0x37, 0x73, 0x1d]⟩ -- initialize(uint160) - -/-- Numeric selector words in the same order as `uniswapV3PoolSelBytes`. -/ -def uniswapV3PoolSelNat : ℕ → UInt256 - | 0 => ⟨234755713⟩ - | 1 => ⟨311085832⟩ - | 2 => ⟨443049218⟩ - | 3 => ⟨450408507⟩ - | 4 => ⟨623643095⟩ - | 5 => ⟨840208231⟩ - | 6 => ⟨944818109⟩ - | 7 => ⟨1015709069⟩ - | 8 => ⟨1175720729⟩ - | 9 => ⟨1225682108⟩ - | 10 => ⟨1327412184⟩ - | 11 => ⟨1364108479⟩ - | 12 => ⟨1396294294⟩ - | 13 => ⟨1892644170⟩ - | 14 => ⟨2181473489⟩ - | 15 => ⟨2243323689⟩ - | 16 => ⟨2285624317⟩ - | 17 => ⟨2738955175⟩ - | 18 => ⟨2743601138⟩ - | 19 => ⟨3294232917⟩ - | 20 => ⟨3502848636⟩ - | 21 => ⟨3524403367⟩ - | 22 => ⟨3721019203⟩ - | 23 => ⟨4077224857⟩ - | 24 => ⟨4077763219⟩ - | _ => ⟨4130829085⟩ - -/-- EVM selector-word comparison agrees with comparing the calldata's first four bytes. -/ -theorem uniswapV3PoolSelectorEq (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) - (i : ℕ) (hi : i < 26) : - UInt256.eq (uniswapV3PoolSelNat i) (uniswapV3PoolSelWord I) = - if (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) then ⟨1⟩ else ⟨0⟩ := by - interval_cases i <;> - exact evmSelectorDecode hsz _ _ _ _ _ (by decide) - -theorem uniswapV3PoolSelectorEq_zero (I : ExecutionEnv) (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (i : ℕ) (hi : i < 26) : - UInt256.eq (uniswapV3PoolSelNat i) (uniswapV3PoolSelWord I) = ⟨0⟩ := by - rw [uniswapV3PoolSelectorEq I hsz i hi, hnm i hi] - rfl - -theorem byteArray_beq_false_of_ne_of_beq_true {a b x : ByteArray} - (hne : a ≠ b) (hbx : (b == x) = true) : - (a == x) = false := by - apply Bool.eq_false_of_not_eq_true - intro hax - have hax' : a = x := by - apply ByteArray.ext - exact LawfulBEq.eq_of_beq (show (a.data == x.data) = true from hax) - have hbx' : b = x := by - apply ByteArray.ext - exact LawfulBEq.eq_of_beq (show (b.data == x.data) = true from hbx) - apply hne - exact hax'.trans hbx'.symm - -theorem uniswapV3PoolSelectorMissOfHit (I : ExecutionEnv) {i j : ℕ} - (hne : uniswapV3PoolSelBytes i ≠ uniswapV3PoolSelBytes j) - (hhit : (uniswapV3PoolSelBytes j == I.calldata.extract 0 4) = true) : - (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false := - byteArray_beq_false_of_ne_of_beq_true hne hhit - -theorem uniswapV3PoolSelectorMissOfHitBytes {cd : ByteArray} {i j : ℕ} - (hne : uniswapV3PoolSelBytes i ≠ uniswapV3PoolSelBytes j) - (hhit : (uniswapV3PoolSelBytes j == cd.extract 0 4) = true) : - (uniswapV3PoolSelBytes i == cd.extract 0 4) = false := - byteArray_beq_false_of_ne_of_beq_true hne hhit - -theorem uniswapV3PoolSelectorMatchCases (I : ExecutionEnv) - (hnot : ¬ ∀ i, i < 26 → - (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - {P : Prop} - (h0 : (uniswapV3PoolSelBytes 0 == I.calldata.extract 0 4) = true → P) - (h1 : (uniswapV3PoolSelBytes 1 == I.calldata.extract 0 4) = true → P) - (h2 : (uniswapV3PoolSelBytes 2 == I.calldata.extract 0 4) = true → P) - (h3 : (uniswapV3PoolSelBytes 3 == I.calldata.extract 0 4) = true → P) - (h4 : (uniswapV3PoolSelBytes 4 == I.calldata.extract 0 4) = true → P) - (h5 : (uniswapV3PoolSelBytes 5 == I.calldata.extract 0 4) = true → P) - (h6 : (uniswapV3PoolSelBytes 6 == I.calldata.extract 0 4) = true → P) - (h7 : (uniswapV3PoolSelBytes 7 == I.calldata.extract 0 4) = true → P) - (h8 : (uniswapV3PoolSelBytes 8 == I.calldata.extract 0 4) = true → P) - (h9 : (uniswapV3PoolSelBytes 9 == I.calldata.extract 0 4) = true → P) - (h10 : (uniswapV3PoolSelBytes 10 == I.calldata.extract 0 4) = true → P) - (h11 : (uniswapV3PoolSelBytes 11 == I.calldata.extract 0 4) = true → P) - (h12 : (uniswapV3PoolSelBytes 12 == I.calldata.extract 0 4) = true → P) - (h13 : (uniswapV3PoolSelBytes 13 == I.calldata.extract 0 4) = true → P) - (h14 : (uniswapV3PoolSelBytes 14 == I.calldata.extract 0 4) = true → P) - (h15 : (uniswapV3PoolSelBytes 15 == I.calldata.extract 0 4) = true → P) - (h16 : (uniswapV3PoolSelBytes 16 == I.calldata.extract 0 4) = true → P) - (h17 : (uniswapV3PoolSelBytes 17 == I.calldata.extract 0 4) = true → P) - (h18 : (uniswapV3PoolSelBytes 18 == I.calldata.extract 0 4) = true → P) - (h19 : (uniswapV3PoolSelBytes 19 == I.calldata.extract 0 4) = true → P) - (h20 : (uniswapV3PoolSelBytes 20 == I.calldata.extract 0 4) = true → P) - (h21 : (uniswapV3PoolSelBytes 21 == I.calldata.extract 0 4) = true → P) - (h22 : (uniswapV3PoolSelBytes 22 == I.calldata.extract 0 4) = true → P) - (h23 : (uniswapV3PoolSelBytes 23 == I.calldata.extract 0 4) = true → P) - (h24 : (uniswapV3PoolSelBytes 24 == I.calldata.extract 0 4) = true → P) - (h25 : (uniswapV3PoolSelBytes 25 == I.calldata.extract 0 4) = true → P) : - P := by - by_cases h0m : (uniswapV3PoolSelBytes 0 == I.calldata.extract 0 4) = true - · exact h0 h0m - by_cases h1m : (uniswapV3PoolSelBytes 1 == I.calldata.extract 0 4) = true - · exact h1 h1m - by_cases h2m : (uniswapV3PoolSelBytes 2 == I.calldata.extract 0 4) = true - · exact h2 h2m - by_cases h3m : (uniswapV3PoolSelBytes 3 == I.calldata.extract 0 4) = true - · exact h3 h3m - by_cases h4m : (uniswapV3PoolSelBytes 4 == I.calldata.extract 0 4) = true - · exact h4 h4m - by_cases h5m : (uniswapV3PoolSelBytes 5 == I.calldata.extract 0 4) = true - · exact h5 h5m - by_cases h6m : (uniswapV3PoolSelBytes 6 == I.calldata.extract 0 4) = true - · exact h6 h6m - by_cases h7m : (uniswapV3PoolSelBytes 7 == I.calldata.extract 0 4) = true - · exact h7 h7m - by_cases h8m : (uniswapV3PoolSelBytes 8 == I.calldata.extract 0 4) = true - · exact h8 h8m - by_cases h9m : (uniswapV3PoolSelBytes 9 == I.calldata.extract 0 4) = true - · exact h9 h9m - by_cases h10m : (uniswapV3PoolSelBytes 10 == I.calldata.extract 0 4) = true - · exact h10 h10m - by_cases h11m : (uniswapV3PoolSelBytes 11 == I.calldata.extract 0 4) = true - · exact h11 h11m - by_cases h12m : (uniswapV3PoolSelBytes 12 == I.calldata.extract 0 4) = true - · exact h12 h12m - by_cases h13m : (uniswapV3PoolSelBytes 13 == I.calldata.extract 0 4) = true - · exact h13 h13m - by_cases h14m : (uniswapV3PoolSelBytes 14 == I.calldata.extract 0 4) = true - · exact h14 h14m - by_cases h15m : (uniswapV3PoolSelBytes 15 == I.calldata.extract 0 4) = true - · exact h15 h15m - by_cases h16m : (uniswapV3PoolSelBytes 16 == I.calldata.extract 0 4) = true - · exact h16 h16m - by_cases h17m : (uniswapV3PoolSelBytes 17 == I.calldata.extract 0 4) = true - · exact h17 h17m - by_cases h18m : (uniswapV3PoolSelBytes 18 == I.calldata.extract 0 4) = true - · exact h18 h18m - by_cases h19m : (uniswapV3PoolSelBytes 19 == I.calldata.extract 0 4) = true - · exact h19 h19m - by_cases h20m : (uniswapV3PoolSelBytes 20 == I.calldata.extract 0 4) = true - · exact h20 h20m - by_cases h21m : (uniswapV3PoolSelBytes 21 == I.calldata.extract 0 4) = true - · exact h21 h21m - by_cases h22m : (uniswapV3PoolSelBytes 22 == I.calldata.extract 0 4) = true - · exact h22 h22m - by_cases h23m : (uniswapV3PoolSelBytes 23 == I.calldata.extract 0 4) = true - · exact h23 h23m - by_cases h24m : (uniswapV3PoolSelBytes 24 == I.calldata.extract 0 4) = true - · exact h24 h24m - by_cases h25m : (uniswapV3PoolSelBytes 25 == I.calldata.extract 0 4) = true - · exact h25 h25m - exfalso - apply hnot - intro i hi - interval_cases i - · exact Bool.eq_false_of_not_eq_true h0m - · exact Bool.eq_false_of_not_eq_true h1m - · exact Bool.eq_false_of_not_eq_true h2m - · exact Bool.eq_false_of_not_eq_true h3m - · exact Bool.eq_false_of_not_eq_true h4m - · exact Bool.eq_false_of_not_eq_true h5m - · exact Bool.eq_false_of_not_eq_true h6m - · exact Bool.eq_false_of_not_eq_true h7m - · exact Bool.eq_false_of_not_eq_true h8m - · exact Bool.eq_false_of_not_eq_true h9m - · exact Bool.eq_false_of_not_eq_true h10m - · exact Bool.eq_false_of_not_eq_true h11m - · exact Bool.eq_false_of_not_eq_true h12m - · exact Bool.eq_false_of_not_eq_true h13m - · exact Bool.eq_false_of_not_eq_true h14m - · exact Bool.eq_false_of_not_eq_true h15m - · exact Bool.eq_false_of_not_eq_true h16m - · exact Bool.eq_false_of_not_eq_true h17m - · exact Bool.eq_false_of_not_eq_true h18m - · exact Bool.eq_false_of_not_eq_true h19m - · exact Bool.eq_false_of_not_eq_true h20m - · exact Bool.eq_false_of_not_eq_true h21m - · exact Bool.eq_false_of_not_eq_true h22m - · exact Bool.eq_false_of_not_eq_true h23m - · exact Bool.eq_false_of_not_eq_true h24m - · exact Bool.eq_false_of_not_eq_true h25m - -private theorem byteArray_prefix_suffix (b : ByteArray) (n : Nat) (hn : n ≤ b.size) : - b.extract 0 n ++ b.extract n b.size = b := by - rw [ByteArray.extract_append_extract] - rw [show min 0 n = 0 by omega, show max n b.size = b.size by omega] - exact byteArray_extract_self b - -private theorem spliceBytes?_eq_pref_append {pref rest value out : ByteArray} {offset : Nat} - (h : spliceBytes? (pref ++ rest) offset value = some out) (hoff : pref.size ≤ offset) : - ∃ rest', out = pref ++ rest' := by - unfold spliceBytes? at h - split at h - · cases h - refine ⟨rest.extract 0 (offset - pref.size) ++ value ++ - (pref ++ rest).extract (offset + value.size) (pref ++ rest).size, ?_⟩ - rw [extract_append_span] - · rw [byteArray_extract_self] - simp only [ByteArray.append_assoc] - · omega - · omega - · simp at h - -private theorem patchRuntime_eq_pref_append_aux (ps : List (Nat × ByteArray)) - {pref acc out : ByteArray} (hacc : ∃ rest, acc = pref ++ rest) - (hall : ∀ p ∈ ps, pref.size ≤ p.1) - (h : ps.foldlM (fun acc p => - if p.2.size = 32 then spliceBytes? acc p.1 p.2 else none) acc = some out) : - ∃ rest, out = pref ++ rest := by - induction ps generalizing acc with - | nil => - simp at h - cases h - exact hacc - | cons p ps ih => - simp only [List.foldlM_cons] at h - by_cases hsz : p.2.size = 32 - · rw [if_pos hsz] at h - rcases hacc with ⟨rest, rfl⟩ - cases hsp : spliceBytes? (pref ++ rest) p.1 p.2 with - | none => simp [hsp] at h - | some acc' => - simp [hsp] at h - exact ih (hacc := spliceBytes?_eq_pref_append hsp (hall p (by simp))) - (hall := fun q hq => hall q (by simp [hq])) h - · rw [if_neg hsz] at h - simp at h - -private theorem patchRuntime_eq_pref_append {template out : ByteArray} - {ps : List (Nat × ByteArray)} {n : Nat} (hn : n ≤ template.size) - (hall : ∀ p ∈ ps, n ≤ p.1) (h : patchRuntime template ps = some out) : - ∃ rest, out = template.extract 0 n ++ rest := by - unfold patchRuntime at h - refine patchRuntime_eq_pref_append_aux ps ?_ ?_ h - · exact ⟨template.extract n template.size, (byteArray_prefix_suffix template n hn).symm⟩ - · intro p hp - simpa [ByteArray.size_extract, hn] using hall p hp - -private theorem uniswapV3Pool_patches_ge_2258 (v : PoolImmutables) : - ∀ p ∈ patches v, 2258 ≤ p.1 := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> - norm_num - -/-- Patching immutables preserves the runtime prefix before the first immutable reference. -/ -theorem uniswapV3PoolPatchedPrefix2258 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - ∃ rest, code = uniswapV3PoolBytecode.extract 0 2258 ++ rest := by - exact patchRuntime_eq_pref_append (by native_decide) (uniswapV3Pool_patches_ge_2258 v) hpatch - -/-- Any instruction whose maximal decode window is before the first immutable patch is unchanged. -/ -theorem uniswapV3PoolDecodePatchedEqTemplate2258 {v : PoolImmutables} {code : ByteArray} - {pc : UInt256} (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 33 ≤ 2258) : - decode code pc = decode uniswapV3PoolBytecode pc := by - let pref := uniswapV3PoolBytecode.extract 0 2258 - let tail0 := uniswapV3PoolBytecode.extract 2258 uniswapV3PoolBytecode.size - obtain ⟨tail, htail⟩ := uniswapV3PoolPatchedPrefix2258 hpatch - have htemplate : uniswapV3PoolBytecode = pref ++ tail0 := by - dsimp [pref, tail0] - exact (byteArray_prefix_suffix uniswapV3PoolBytecode 2258 (by native_decide)).symm - have hprefSize : pref.size = 2258 := by - dsimp [pref] - rw [ByteArray.size_extract] - have hs : 2258 ≤ uniswapV3PoolBytecode.size := by native_decide - omega - rw [htail] - change decode (pref ++ tail) pc = decode uniswapV3PoolBytecode pc - rw [decode_append_left_window pref tail pc (by rw [hprefSize]; exact hwin) - (by rw [hprefSize]; norm_num)] - rw [htemplate] - rw [decode_append_left_window pref tail0 pc (by rw [hprefSize]; exact hwin) - (by rw [hprefSize]; norm_num)] - -private theorem spliceBytes?_extract_before {b val out : ByteArray} {offset start stop : Nat} - (h : spliceBytes? b offset val = some out) - (hbefore : stop ≤ offset) : - out.extract start stop = b.extract start stop := by - unfold spliceBytes? at h - split at h - · rename_i hb - cases h - rw [ByteArray.append_assoc] - rw [extract_append_left (b.extract 0 offset) (val ++ b.extract (offset + val.size) b.size) - start stop] - · rw [extract_extract_BA] - rw [show min (0 + stop) offset = stop by omega] - simp - · rw [ByteArray.size_extract] - omega - · simp at h - -private theorem spliceBytes?_extract_after {b val out : ByteArray} {offset start stop : Nat} - (h : spliceBytes? b offset val = some out) - (hafter : offset + val.size ≤ start) (hle : start ≤ stop) (hstop : stop ≤ b.size) : - out.extract start stop = b.extract start stop := by - unfold spliceBytes? at h - split at h - · rename_i hb - cases h - have hoff : offset ≤ b.size := by omega - rw [extract_append_right_window (b.extract 0 offset ++ val) - (b.extract (offset + val.size) b.size) start stop] - · rw [ByteArray.size_append, ByteArray.size_extract] - rw [show min offset b.size = offset by omega] - simp only [Nat.sub_zero] - rw [extract_extract_BA] - rw [show offset + val.size + (start - (offset + val.size)) = start by omega] - rw [show min (offset + val.size + (stop - (offset + val.size))) b.size = stop by omega] - · rw [ByteArray.size_append, ByteArray.size_extract] - rw [show min offset b.size = offset by omega] - omega - · simp at h - -private theorem spliceBytes?_extract_disjoint {b val out : ByteArray} {offset start stop : Nat} - (h : spliceBytes? b offset val = some out) - (hdisj : stop ≤ offset ∨ offset + val.size ≤ start) (hle : start ≤ stop) - (hstop : stop ≤ b.size) : - out.extract start stop = b.extract start stop := by - rcases hdisj with hbefore | hafter - · exact spliceBytes?_extract_before h hbefore - · exact spliceBytes?_extract_after h hafter hle hstop - -private theorem spliceBytes?_size_eq {b val out : ByteArray} {offset : Nat} - (h : spliceBytes? b offset val = some out) : - out.size = b.size := by - unfold spliceBytes? at h - split at h - · rename_i hb - cases h - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract] - omega - · simp at h - -private theorem patchRuntime_extract_eq_aux (ps : List (Nat × ByteArray)) - {template acc out : ByteArray} {start stop : Nat} - (hextract : acc.extract start stop = template.extract start stop) - (hsize : acc.size = template.size) - (hle : start ≤ stop) (hstop : stop ≤ template.size) - (hdisj : ∀ p ∈ ps, stop ≤ p.1 ∨ p.1 + 32 ≤ start) - (h : ps.foldlM (fun acc p => - if p.2.size = 32 then spliceBytes? acc p.1 p.2 else none) acc = some out) : - out.extract start stop = template.extract start stop ∧ out.size = template.size := by - induction ps generalizing acc with - | nil => - simp at h - cases h - exact ⟨hextract, hsize⟩ - | cons p ps ih => - simp only [List.foldlM_cons] at h - by_cases hszp : p.2.size = 32 - · rw [if_pos hszp] at h - cases hsp : spliceBytes? acc p.1 p.2 with - | none => simp [hsp] at h - | some acc' => - simp [hsp] at h - have hdisj' : stop ≤ p.1 ∨ p.1 + p.2.size ≤ start := by - simpa [hszp] using hdisj p (by simp) - have hacc' : acc'.extract start stop = template.extract start stop := by - rw [spliceBytes?_extract_disjoint hsp hdisj' hle (by rw [hsize]; exact hstop)] - exact hextract - have hsize' : acc'.size = template.size := by - rw [spliceBytes?_size_eq hsp, hsize] - exact ih hacc' hsize' - (fun q hq => hdisj q (List.mem_cons_of_mem p hq)) h - · rw [if_neg hszp] at h - simp at h - -theorem patchRuntime_extract_eq {template out : ByteArray} - {ps : List (Nat × ByteArray)} {start stop : Nat} - (hle : start ≤ stop) (hstop : stop ≤ template.size) - (hdisj : ∀ p ∈ ps, stop ≤ p.1 ∨ p.1 + 32 ≤ start) - (h : patchRuntime template ps = some out) : - out.extract start stop = template.extract start stop := by - unfold patchRuntime at h - exact (patchRuntime_extract_eq_aux ps (template := template) (acc := template) - (out := out) (start := start) (stop := stop) rfl rfl hle hstop hdisj h).1 - -private theorem spliceBytes?_extract_patch {b val out : ByteArray} {offset : Nat} - (h : spliceBytes? b offset val = some out) : - out.extract offset (offset + val.size) = val := by - unfold spliceBytes? at h - split at h - · rename_i hb - cases h - rw [ByteArray.append_assoc] - rw [extract_append_right_window (b.extract 0 offset) - (val ++ b.extract (offset + val.size) b.size) offset (offset + val.size)] - · rw [ByteArray.size_extract] - have hoff : offset ≤ b.size := by omega - rw [show min offset b.size = offset by omega] - rw [show offset - (offset - 0) = 0 by omega] - rw [show offset + val.size - (offset - 0) = val.size by omega] - rw [extract_append_left val (b.extract (offset + val.size) b.size) 0 val.size] - · exact byteArray_extract_self val - · omega - · rw [ByteArray.size_extract] - omega - · simp at h - -private theorem spliceBytes?_offset_add_size_le {b val out : ByteArray} {offset : Nat} - (h : spliceBytes? b offset val = some out) : - offset + val.size ≤ b.size := by - unfold spliceBytes? at h - split at h - · assumption - · simp at h - -private theorem patchRuntime_size_eq {template out : ByteArray} - {ps : List (Nat × ByteArray)} - (h : patchRuntime template ps = some out) : - out.size = template.size := by - unfold patchRuntime at h - exact (patchRuntime_extract_eq_aux ps (template := template) (acc := template) - (out := out) (start := 0) (stop := 0) rfl rfl (by omega) (by omega) - (fun p hp => Or.inl (by omega)) h).2 - -theorem patchRuntime_extract_patch {template out value : ByteArray} - {pre post : List (Nat × ByteArray)} {offset : Nat} - (hvalue : value.size = 32) - (hpost : ∀ p ∈ post, offset + 32 ≤ p.1 ∨ p.1 + 32 ≤ offset) - (h : patchRuntime template (pre ++ (offset, value) :: post) = some out) : - out.extract offset (offset + 32) = value := by - unfold patchRuntime at h - rw [List.foldlM_append] at h - cases hpre : List.foldlM - (fun acc p => if p.2.size = 32 then spliceBytes? acc p.1 p.2 else none) - template pre with - | none => simp [hpre] at h - | some accPre => - simp [hpre, hvalue] at h - cases hsp : spliceBytes? accPre offset value with - | none => simp [hsp] at h - | some accTarget => - simp [hsp] at h - have htarget : accTarget.extract offset (offset + 32) = value := by - simpa [hvalue] using spliceBytes?_extract_patch hsp - have htargetSize : offset + 32 ≤ accTarget.size := by - rw [spliceBytes?_size_eq hsp] - simpa [hvalue] using spliceBytes?_offset_add_size_le hsp - have htail := patchRuntime_extract_eq_aux post (template := accTarget) - (acc := accTarget) (out := out) (start := offset) (stop := offset + 32) - rfl rfl (by omega) htargetSize hpost h - exact htail.1.trans htarget - -private theorem patchRuntime_extract'_eq {template out : ByteArray} - {ps : List (Nat × ByteArray)} {start stop : Nat} - (hle : start ≤ stop) (hstop : stop ≤ template.size) - (hstart64 : start < 2 ^ 64) (hstop64 : stop < 2 ^ 64) - (hdisj : ∀ p ∈ ps, stop ≤ p.1 ∨ p.1 + 32 ≤ start) - (h : patchRuntime template ps = some out) : - out.extract' start stop = template.extract' start stop := by - unfold ByteArray.extract' - have hguard : (decide (start < 2 ^ 64) && decide (stop < 2 ^ 64)) = true := by - rw [decide_eq_true hstart64, decide_eq_true hstop64] - rfl - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq hle hstop hdisj h - -theorem get?_eq_of_extract_one {a b : ByteArray} {idx : Nat} - (ha : idx < a.size) (hb : idx < b.size) - (h : a.extract idx (idx + 1) = b.extract idx (idx + 1)) : - a.get? idx = b.get? idx := by - unfold ByteArray.get? - simp only [dif_pos ha, dif_pos hb] - have hdata := congrArg ByteArray.data h - have hlist := congrArg Array.toList hdata - rw [ByteArray.data_extract, ByteArray.data_extract, Array.toList_extract, - Array.toList_extract, List.extract_eq_take_drop, List.extract_eq_take_drop] at hlist - have hleft : (List.take (idx + 1 - idx) (List.drop idx a.data.toList))[0]? = - some (a.get idx ha) := by - simp [ByteArray.get] - have hright : (List.take (idx + 1 - idx) (List.drop idx b.data.toList))[0]? = - some (b.get idx hb) := by - simp [ByteArray.get] - have hget := congrArg (fun xs : List UInt8 => xs[0]?) hlist - change (List.take (idx + 1 - idx) (List.drop idx a.data.toList))[0]? = - (List.take (idx + 1 - idx) (List.drop idx b.data.toList))[0]? at hget - rw [hleft, hright] at hget - exact hget - -theorem uniswapV3PoolPatchedSize {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - code.size = uniswapV3PoolBytecode.size := - patchRuntime_size_eq hpatch - -theorem uniswapV3PoolToken0PatchWord {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - code.extract 2258 2290 = UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat) := by - let value := UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat) - let pre : List (Nat × ByteArray) := - [(8315, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (8829, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (10457, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat))] - let post : List (Nat × ByteArray) := - [(4853, value), (6740, value), (7822, value), (9150, value), (15650, value), - (4551, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (6789, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (7924, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (9284, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (10529, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (15979, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (3311, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6603, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6658, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (10565, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (3072, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (10493, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19402, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19452, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (8174, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19295, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19350, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (11259, UInt256.toByteArray (EVM.Word.ofNat v.original.toNat))] - have hpatch' : patchRuntime uniswapV3PoolBytecode (pre ++ (2258, value) :: post) = - some code := by - dsimp [pre, post, value] - simpa [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup, - toByteArray_eq_toBytesBE] using hpatch - have hpost : ∀ p ∈ post, 2258 + 32 ≤ p.1 ∨ p.1 + 32 ≤ 2258 := by - intro p hp - dsimp [post] at hp - simp at hp - rcases hp with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - have hsize : value.size = 32 := by - dsimp [value] - exact toByteArray_size _ - exact patchRuntime_extract_patch hsize hpost hpatch' - -theorem uniswapV3PoolToken0ConstDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨2257⟩ = - some (.Push .PUSH32, some (EVM.Word.ofNat v.token0.toNat, 32)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have hget : code.get? ({ val := 2257 } : UInt256).toNat = - uniswapV3PoolBytecode.get? ({ val := 2257 } : UInt256).toNat := by - change code.get? 2257 = uniswapV3PoolBytecode.get? 2257 - apply get?_eq_of_extract_one - · rw [hsize] - native_decide - · native_decide - · exact patchRuntime_extract_eq (start := 2257) (stop := 2258) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by native_decide) - (fun p hp => by - have hge := uniswapV3Pool_patches_ge_2258 v p hp - exact Or.inl (by omega)) hpatch - have hextract : code.extract' ({ val := 2257 } : UInt256).toNat.succ - (({ val := 2257 } : UInt256).toNat.succ + 32) = - UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat) := by - change code.extract' 2258 2290 = - UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat) - unfold ByteArray.extract' - have hguard : (decide (2258 < 2 ^ 64) && decide (2290 < 2 ^ 64)) = true := by - native_decide - rw [if_pos hguard] - exact uniswapV3PoolToken0PatchWord hpatch - have hgetSome : code.get? ({ val := 2257 } : UInt256).toNat = some 0x7f := by - rw [hget] - native_decide - have hparse : (some (0x7f : UInt8) >>= parseInstr) = some (.Push .PUSH32) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH32, - some (uInt256OfByteArray - (code.extract' ({ val := 2257 } : UInt256).toNat.succ - (({ val := 2257 } : UInt256).toNat.succ + 32)), 32)) = - some (Operation.Push Operation.POp.PUSH32, some (EVM.Word.ofNat v.token0.toNat, 32)) - rw [hextract, uInt256OfByteArray_eq, fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - -theorem uniswapV3PoolToken0GetterJumpdestDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨2256⟩ = some (.JUMPDEST, .none) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have hget : code.get? ({ val := 2256 } : UInt256).toNat = - uniswapV3PoolBytecode.get? ({ val := 2256 } : UInt256).toNat := by - change code.get? 2256 = uniswapV3PoolBytecode.get? 2256 - apply get?_eq_of_extract_one - · rw [hsize] - native_decide - · native_decide - · exact patchRuntime_extract_eq (start := 2256) (stop := 2257) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by native_decide) - (fun p hp => by - have hge := uniswapV3Pool_patches_ge_2258 v p hp - exact Or.inl (by omega)) hpatch - have hgetSome : code.get? ({ val := 2256 } : UInt256).toNat = some 0x5b := by - rw [hget] - native_decide - have hparse : (some (0x5b : UInt8) >>= parseInstr) = some .JUMPDEST := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.JUMPDEST, none) = some (Operation.JUMPDEST, none) - rfl - -theorem uniswapV3PoolToken1PatchWord {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - code.extract 10529 10561 = UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat) := by - let value0 := UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat) - let value1 := UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat) - let pre : List (Nat × ByteArray) := - [(8315, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (8829, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (10457, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (2258, value0), (4853, value0), (6740, value0), (7822, value0), - (9150, value0), (15650, value0), - (4551, value1), (6789, value1), (7924, value1), (9284, value1)] - let post : List (Nat × ByteArray) := - [(15979, value1), - (3311, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6603, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6658, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (10565, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (3072, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (10493, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19402, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19452, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (8174, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19295, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19350, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (11259, UInt256.toByteArray (EVM.Word.ofNat v.original.toNat))] - have hpatch' : patchRuntime uniswapV3PoolBytecode (pre ++ (10529, value1) :: post) = - some code := by - dsimp [pre, post, value0, value1] - simpa [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup, - toByteArray_eq_toBytesBE] using hpatch - have hpost : ∀ p ∈ post, 10529 + 32 ≤ p.1 ∨ p.1 + 32 ≤ 10529 := by - intro p hp - dsimp [post] at hp - simp at hp - rcases hp with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl - all_goals omega - have hsize : value1.size = 32 := by - dsimp [value1] - exact toByteArray_size _ - exact patchRuntime_extract_patch hsize hpost hpatch' - -theorem uniswapV3PoolToken1ConstDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10528⟩ = - some (.Push .PUSH32, some (EVM.Word.ofNat v.token1.toNat, 32)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have hget : code.get? ({ val := 10528 } : UInt256).toNat = - uniswapV3PoolBytecode.get? ({ val := 10528 } : UInt256).toNat := by - change code.get? 10528 = uniswapV3PoolBytecode.get? 10528 - apply get?_eq_of_extract_one - · rw [hsize] - native_decide - · native_decide - · exact patchRuntime_extract_eq (start := 10528) (stop := 10529) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by native_decide) - (fun p hp => by - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl - all_goals omega) hpatch - have hextract : code.extract' ({ val := 10528 } : UInt256).toNat.succ - (({ val := 10528 } : UInt256).toNat.succ + 32) = - UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat) := by - change code.extract' 10529 10561 = - UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat) - unfold ByteArray.extract' - have hguard : (decide (10529 < 2 ^ 64) && decide (10561 < 2 ^ 64)) = true := by - native_decide - rw [if_pos hguard] - exact uniswapV3PoolToken1PatchWord hpatch - have hgetSome : code.get? ({ val := 10528 } : UInt256).toNat = some 0x7f := by - rw [hget] - native_decide - have hparse : (some (0x7f : UInt8) >>= parseInstr) = some (.Push .PUSH32) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH32, - some (uInt256OfByteArray - (code.extract' ({ val := 10528 } : UInt256).toNat.succ - (({ val := 10528 } : UInt256).toNat.succ + 32)), 32)) = - some (Operation.Push Operation.POp.PUSH32, some (EVM.Word.ofNat v.token1.toNat, 32)) - rw [hextract, uInt256OfByteArray_eq, fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - -theorem uniswapV3PoolDecodePatchedNoArg {v : PoolImmutables} {code : ByteArray} - {pc : UInt256} {byte : UInt8} {op : Operation} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 1 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 1 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some byte) - (hparse : (some byte >>= parseInstr) = some op) - (harg : argOnNBytesOfInstr op = 0) : - decode code pc = some (op, .none) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) hwin hdisj hpatch - unfold decode - rw [hget, hgetTemplate, hparse] - simp [harg] - -theorem uniswapV3PoolToken1GetterJumpdestDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10527⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨10527⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 10528 ≤ p.1 ∨ p.1 + 32 ≤ 10527 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolToken1GetterDupDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10561⟩ = some (.DUP2, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨10561⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 10562 ≤ p.1 ∨ p.1 + 32 ≤ 10561 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolToken1GetterJumpDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10562⟩ = some (.JUMP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨10562⟩) (byte := 0x56) - (op := .JUMP) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 10563 ≤ p.1 ∨ p.1 + 32 ≤ 10562 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolReturnAddress443Wf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcReturnAddressFromMemWf code ⟨443⟩ := by - dsimp [solcReturnAddressFromMemWf] - refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, - ?_, ?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem accountAddressWord_toNat (a : AccountAddress) : - (EVM.Word.ofNat a.toNat).toNat = a.toNat := by - unfold EVM.Word.ofNat UInt256.ofNat UInt256.toNat - exact Nat.mod_eq_of_lt - (lt_of_lt_of_le a.isLt (show AccountAddress.size ≤ UInt256.size from by decide)) - -theorem uniswapV3PoolAddressValueTransport (a : AccountAddress) : - some [Value.address (AccountAddress.ofNat a.toNat)] = - some [Value.address (AccountAddress.ofNat - (UInt256.land (EVM.Word.ofNat a.toNat) solcAddrMask).toNat)] := by - have hword := accountAddressWord_toNat a - have hcanon : (EVM.Word.ofNat a.toNat).toNat < EVM.addressModulus := by - rw [hword] - change a.toNat < EVM.twoPow 160 - simp [EVM.twoPow, AccountAddress.size] - rw [solcAddrMask_clean hcanon, hword] - -theorem uniswapV3PoolAddrLitEval {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} (a : EVM.Address) : - evalExpr? (config v) { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) (addrLit a) = - .ok (Value.address (AccountAddress.ofNat a.toNat)) := by - dsimp [addrLit] - have hint : - evalExpr? (config v) { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) (.intLit (↑↑a)) = - .ok (.int (↑↑a)) := by - simp [evalExpr?, pure] - unfold evalExpr? - rw [hint] - change (if (↑↑a : Int) < 0 then EvalResult.error EvalError.typeError - else EvalResult.ok - (Value.address (AccountAddress.ofNat (Int.toNat (↑↑a : Int))))) = - EvalResult.ok (Value.address (AccountAddress.ofNat ↑a)) - rw [if_neg (by omega)] - simp - -/- LIBRARY CANDIDATE: composes `solcConstGetterWf` with `solcReturnAddressFromMemWf` - for immutable address getters. -/ -theorem RD.solcAddressConstGetterExternal {code : ByteArray} {cA gh bl σ σ₀ A I} - {g : Sat256} {sel entry routine returnPc val : UInt256} {width : Nat} - {op : Operation.POp} - (hreach : ∃ k C, RD code I g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) - entry [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hentry : solcGetterEntryWf code entry returnPc routine) - (hgetter : solcConstGetterWf code routine val width op) - (hroutine : (D_J code 0).contains routine = true) - (hret : (D_J code 0).contains returnPc = true) - (hreturn : solcReturnAddressFromMemWf code returnPc) : - RDret code g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land val solcAddrMask)) := by - obtain ⟨_, _, rdRoutine⟩ := RD.solcGetterThunk hreach hentry hroutine - obtain ⟨_, _, rdReturn⟩ := RD.solcConstGetter (val := val) (width := width) - (op := op) (R := [sel]) rdRoutine hgetter hret - (by simp only [List.length_singleton]; omega) - exact RD.solcReturnAddressFromMem rdReturn hreturn - solcFreePtrMem_mload64 - (by rfl) - (solcReturnMem_mload64 (UInt256.land val solcAddrMask)) - (solcReturnMem_read128 (UInt256.land val solcAddrMask)) - (by simp only [List.length_singleton]; omega) - -theorem uniswapV3PoolDecodePatchedEqTemplateDisjoint {v : PoolImmutables} {code : ByteArray} - {pc : UInt256} (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 33 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) : - decode code pc = decode uniswapV3PoolBytecode pc := by - have hsize := uniswapV3PoolPatchedSize hpatch - have hpc : pc.toNat < uniswapV3PoolBytecode.size := by omega - have hpcCode : pc.toNat < code.size := by rw [hsize]; exact hpc - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one hpcCode hpc - exact patchRuntime_extract_eq (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - unfold decode - rw [hget] - cases hbyte : uniswapV3PoolBytecode.get? pc.toNat with - | none => simp - | some b => - cases hinstr : parseInstr b with - | none => simp [hinstr] - | some instr => - by_cases harg : argOnNBytesOfInstr instr = 0 - · simp [hinstr, harg] - · simp [hinstr, harg] - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + argOnNBytesOfInstr instr) = - uniswapV3PoolBytecode.extract' pc.toNat.succ - (pc.toNat.succ + argOnNBytesOfInstr instr) := by - exact patchRuntime_extract'_eq - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (start := pc.toNat.succ) - (stop := pc.toNat.succ + argOnNBytesOfInstr instr) - (by omega) - (by - have := argOnNBytesOfInstr_le_32 instr - omega) - (by omega) - (by - have := argOnNBytesOfInstr_le_32 instr - omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by - have := argOnNBytesOfInstr_le_32 instr - omega) - · exact Or.inr (by omega)) - hpatch - rw [hextract] - -private theorem lt_size_of_get?_bind_parseInstr_some {c : ByteArray} {i : ℕ} - {instr : Operation} (h : c.get? i >>= parseInstr = some instr) : i < c.size := by - rcases hb : c.get? i with _ | b - · rw [hb] at h - simp at h - · rw [ByteArray.get?] at hb - split at hb - · assumption - · simp at hb - -set_option linter.unusedVariables false in -def D_J_auxPreservesTargetBool (template : ByteArray) (offsets : List Nat) - (target : UInt256) (i : Nat) : Bool := - offsets.all (fun offset => decide (i + 1 ≤ offset ∨ offset + 32 ≤ i)) && - match hget : template.get? i >>= parseInstr with - | none => false - | some instr => - if instr = .JUMPDEST ∧ UInt256.ofNat i = target then - true - else - D_J_auxPreservesTargetBool template offsets target (N i instr) -termination_by template.size - i -decreasing_by - have hN : i < N i instr := by - simp [N] - omega - have hi : i < template.size := - lt_size_of_get?_bind_parseInstr_some hget - omega - -private theorem patchRuntime_parse_eq_of_disjoint {template out : ByteArray} - {ps : List (Nat × ByteArray)} {i : Nat} - (hpatch : patchRuntime template ps = some out) - (hdisj : ∀ p ∈ ps, i + 1 ≤ p.1 ∨ p.1 + 32 ≤ i) : - out.get? i >>= parseInstr = template.get? i >>= parseInstr := by - by_cases hi : i < template.size - · have hsize := patchRuntime_size_eq hpatch - have hget : out.get? i = template.get? i := by - apply get?_eq_of_extract_one (by rw [hsize]; exact hi) hi - exact patchRuntime_extract_eq (by omega) (by omega) hdisj hpatch - rw [hget] - · have hsize := patchRuntime_size_eq hpatch - have hout : out.get? i = none := by - rw [ByteArray.get?, dif_neg] - rw [hsize] - omega - have htemplate : template.get? i = none := by - rw [ByteArray.get?, dif_neg] - omega - rw [hout, htemplate] - -private theorem D_J_aux_contains_push_target {code : ByteArray} {i : Nat} - {result : Array UInt256} : - (D_J_aux code (N i .JUMPDEST) (result.push (UInt256.ofNat i))).contains - (UInt256.ofNat i) = true := by - rw [D_J_aux_acc] - rw [Array.contains_iff_mem] - simp - -theorem D_J_aux_contains_of_patchRuntime_preservesTarget {template out : ByteArray} - {ps : List (Nat × ByteArray)} {offsets : List Nat} {target : UInt256} {i : Nat} - {result : Array UInt256} - (hpatch : patchRuntime template ps = some out) - (hoffsets : ∀ p ∈ ps, p.1 ∈ offsets) - (hscan : D_J_auxPreservesTargetBool template offsets target i = true) : - (D_J_aux out i result).contains target = true := by - rw [D_J_auxPreservesTargetBool] at hscan - cases htemplate : template.get? i >>= parseInstr with - | none => - rw [htemplate] at hscan - simp at hscan - | some instr => - rw [htemplate] at hscan - simp only [Bool.and_eq_true, List.all_eq_true, decide_eq_true_eq] at hscan - rcases hscan with ⟨hdisj, htail⟩ - have hpatchDisj : ∀ p ∈ ps, i + 1 ≤ p.1 ∨ p.1 + 32 ≤ i := by - intro p hp - exact hdisj p.1 (hoffsets p hp) - have hparse := patchRuntime_parse_eq_of_disjoint hpatch hpatchDisj - rw [D_J_aux_eq_some out i result instr (by rw [hparse, htemplate])] - by_cases htarget : instr = .JUMPDEST ∧ UInt256.ofNat i = target - · rw [if_pos htarget] at htail - rcases htarget with ⟨rfl, htarget⟩ - rw [← htarget] - exact D_J_aux_contains_push_target - · rw [if_neg htarget] at htail - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch hoffsets htail -termination_by template.size - i -decreasing_by - have hi := lt_size_of_get?_bind_parseInstr_some htemplate - simp [N] - omega - -def uniswapV3PoolPatchOffsets : List Nat := - [8315, 8829, 10457, 2258, 4853, 6740, 7822, 9150, 15650, 4551, 6789, 7924, 9284, - 10529, 15979, 3311, 6603, 6658, 10565, 3072, 10493, 19402, 19452, 8174, 19295, - 19350, 11259] - -theorem uniswapV3PoolPatchOffsetMem (v : PoolImmutables) : - ∀ p ∈ patches v, p.1 ∈ uniswapV3PoolPatchOffsets := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> - simp [uniswapV3PoolPatchOffsets] - -private theorem uniswapV3PoolPatchPreservesJumpDest5293 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨5293⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest6434 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨6434⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest10527 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨10527⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest10599 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨10599⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest10455 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨10455⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched5293 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨5293⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest5293 - -theorem uniswapV3PoolJumpDestPatched6434 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨6434⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest6434 - -theorem uniswapV3PoolJumpDestPatched10527 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10527⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest10527 - -theorem uniswapV3PoolJumpDestPatched10599 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10599⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest10599 - -theorem uniswapV3PoolJumpDestPatched10455 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10455⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest10455 - -theorem uniswapV3PoolJumpDestPatched2258 {v : PoolImmutables} {code : ByteArray} - {pc : UInt256} (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : (D_J (uniswapV3PoolBytecode.extract 0 2258) 0).contains pc = true) : - (D_J code 0).contains pc = true := by - obtain ⟨tail, htail⟩ := uniswapV3PoolPatchedPrefix2258 hpatch - rw [htail] - exact D_J_contains_append_left _ _ pc h - -theorem uniswapV3PoolReturn443JumpDest {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨443⟩ = true := - uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide) - -theorem uniswapV3PoolPushAtPatchedEqTemplate2258 {v : PoolImmutables} {code : ByteArray} - {pc : UInt256} (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 33 ≤ 2258) : - pushAt code pc = pushAt uniswapV3PoolBytecode pc := by - unfold pushAt - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hwin] - -theorem uniswapV3PoolArmSelNatPatchedEqTemplate2258 {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : (selArmPush4Pc pc).toNat + 33 ≤ 2258) : - armSelNat code pc = armSelNat uniswapV3PoolBytecode pc := by - unfold armSelNat - rw [uniswapV3PoolPushAtPatchedEqTemplate2258 hpatch hwin] - -theorem uniswapV3PoolArmTgtOpPatchedEqTemplate2258 {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : (selArmPushTgtPc pc).toNat + 33 ≤ 2258) : - armTgtOp code pc = armTgtOp uniswapV3PoolBytecode pc := by - unfold armTgtOp - rw [uniswapV3PoolPushAtPatchedEqTemplate2258 hpatch hwin] - -theorem uniswapV3PoolArmTgtPatchedEqTemplate2258 {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : (selArmPushTgtPc pc).toNat + 33 ≤ 2258) : - armTgt code pc = armTgt uniswapV3PoolBytecode pc := by - unfold armTgt - rw [uniswapV3PoolPushAtPatchedEqTemplate2258 hpatch hwin] - -theorem uniswapV3PoolArmTgtWidthPatchedEqTemplate2258 {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : (selArmPushTgtPc pc).toNat + 33 ≤ 2258) : - armTgtWidth code pc = armTgtWidth uniswapV3PoolBytecode pc := by - unfold armTgtWidth - rw [uniswapV3PoolPushAtPatchedEqTemplate2258 hpatch hwin] - -theorem uniswapV3PoolArmWellFormedPatched2258 {v : PoolImmutables} {code : ByteArray} - {pc : UInt256} (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hpc : pc.toNat + 33 ≤ 2258) - (hpush4 : (selArmPush4Pc pc).toNat + 33 ≤ 2258) - (heqPc : (selArmEqPc pc).toNat + 33 ≤ 2258) - (hpushT : (selArmPushTgtPc pc).toNat + 33 ≤ 2258) - (hjumpi : (selArmJumpiPc pc (armTgtWidth uniswapV3PoolBytecode pc)).toNat + 33 ≤ 2258) - (hwf : armWellFormed uniswapV3PoolBytecode pc) : - armWellFormed code pc := by - rcases hwf with ⟨hdup, hpush, heq, hop, htgt, hji⟩ - have hopEq := uniswapV3PoolArmTgtOpPatchedEqTemplate2258 hpatch hpushT - have htgtEq := uniswapV3PoolArmTgtPatchedEqTemplate2258 hpatch hpushT - have hwEq := uniswapV3PoolArmTgtWidthPatchedEqTemplate2258 hpatch hpushT - refine ⟨?_, ?_, ?_, ?_, ?_, ?_⟩ - · rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hpc] - exact hdup - · rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch hpush4] - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hpush4] - exact hpush - · rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch heqPc] - exact heq - · rw [hopEq] - exact hop - · rw [hopEq, htgtEq, hwEq] - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hpushT] - exact htgt - · rw [hwEq] - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hjumpi] - exact hji - -theorem uniswapV3PoolSelectorSplitWellFormedPatched2258 {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hpc : pc.toNat + 33 ≤ 2258) - (hpush4 : (selArmPush4Pc pc).toNat + 33 ≤ 2258) - (hgtPc : (selArmEqPc pc).toNat + 33 ≤ 2258) - (hpushT : (selArmPushTgtPc pc).toNat + 33 ≤ 2258) - (hjumpi : (selArmJumpiPc pc (armTgtWidth uniswapV3PoolBytecode pc)).toNat + 33 ≤ 2258) - (hwf : selectorSplitWellFormed uniswapV3PoolBytecode pc) : - selectorSplitWellFormed code pc := by - rcases hwf with ⟨hdup, hpush, hgt, hop, htgt, hji⟩ - have hopEq := uniswapV3PoolArmTgtOpPatchedEqTemplate2258 hpatch hpushT - have htgtEq := uniswapV3PoolArmTgtPatchedEqTemplate2258 hpatch hpushT - have hwEq := uniswapV3PoolArmTgtWidthPatchedEqTemplate2258 hpatch hpushT - refine ⟨?_, ?_, ?_, ?_, ?_, ?_⟩ - · rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hpc] - exact hdup - · rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch hpush4] - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hpush4] - exact hpush - · rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hgtPc] - exact hgt - · rw [hopEq] - exact hop - · rw [hopEq, htgtEq, hwEq] - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hpushT] - exact htgt - · rw [hwEq] - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hjumpi] - exact hji - -theorem uniswapV3PoolFallbackRevertFrom {code : ByteArray} {ee : ExecutionEnv} - {g : Sat256} {s0 : State} {pc : UInt256} {stk : List UInt256} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (h : RD code ee g s0 pc stk mem aw rdata acc k C) - (hpush : decode code pc = some (.Push .PUSH2, some (⟨430⟩, 2))) - (hjump : decode code (pc + UInt256.ofNat 3) = some (.JUMP, .none)) - (hjd : (D_J code 0).contains ⟨430⟩ = true) - (hjdDecode : decode code ⟨430⟩ = some (.JUMPDEST, .none)) - (hr0 : decode code ⟨431⟩ = some (.Push .PUSH1, some (⟨0⟩, 1))) - (hr1 : decode code ⟨433⟩ = some (.DUP1, .none)) - (hr2 : decode code ⟨434⟩ = some (.REVERT, .none)) - (hovPush : stk.length + 1 ≤ 1024) (hovRev : stk.length + 2 ≤ 1024) : - RDrev code g s0 := by - exact RD.solcPush1Dup1Revert0 - (h.pushConst ⟨430⟩ (width := 2) (op := .PUSH2) (by native_decide) hpush hovPush - |>.jump hjump hjd (by omega) - |>.jumpdest hjdDecode (by omega)) - hr0 hr1 hr2 hovRev - -theorem uniswapV3PoolSelectorArmMissTo {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {pc next : UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (i : ℕ) - (h : RD code I g s0 pc [solcSelectorWord I] mem aw rdata acc k C) - (hpc : pc.toNat + 33 ≤ 2258 := by native_decide) - (hpush4 : (selArmPush4Pc pc).toNat + 33 ≤ 2258 := by native_decide) - (heqPc : (selArmEqPc pc).toNat + 33 ≤ 2258 := by native_decide) - (hpushT : (selArmPushTgtPc pc).toNat + 33 ≤ 2258 := by native_decide) - (hjumpi : - (selArmJumpiPc pc (armTgtWidth uniswapV3PoolBytecode pc)).toNat + 33 ≤ 2258 := - by native_decide) - (hwf0 : armWellFormed uniswapV3PoolBytecode pc := by - exact ⟨by native_decide, by native_decide, by native_decide, by native_decide, - by native_decide, by native_decide⟩) - (hsel0 : armSelNat uniswapV3PoolBytecode pc = uniswapV3PoolSelNat i := by - native_decide) - (hi : i < 26 := by omega) - (hnext : selArmNextPc pc (armTgtWidth code pc) = next := by - rw [uniswapV3PoolArmTgtWidthPatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) : - RD code I g s0 next [solcSelectorWord I] mem aw rdata acc (k + 5) (C + 22) := by - have hwf : armWellFormed code pc := - uniswapV3PoolArmWellFormedPatched2258 hpatch hpc hpush4 heqPc hpushT hjumpi hwf0 - have heq0 : UInt256.eq (armSelNat code pc) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch hpush4, hsel0] - simpa [uniswapV3PoolSelWord, solcSelectorWord] using - uniswapV3PoolSelectorEq_zero I hsz hnm i hi - have h' := h.selectorArmNotTakenAuto hwf heq0 (by simp) - simpa [hnext] using h' - -theorem uniswapV3PoolSelectorArmMissToOf {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {pc next : UInt256} {i : ℕ} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hmiss : (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 pc [solcSelectorWord I] mem aw rdata acc k C) - (hpc : pc.toNat + 33 ≤ 2258 := by native_decide) - (hpush4 : (selArmPush4Pc pc).toNat + 33 ≤ 2258 := by native_decide) - (heqPc : (selArmEqPc pc).toNat + 33 ≤ 2258 := by native_decide) - (hpushT : (selArmPushTgtPc pc).toNat + 33 ≤ 2258 := by native_decide) - (hjumpi : - (selArmJumpiPc pc (armTgtWidth uniswapV3PoolBytecode pc)).toNat + 33 ≤ 2258 := - by native_decide) - (hwf0 : armWellFormed uniswapV3PoolBytecode pc := by - exact ⟨by native_decide, by native_decide, by native_decide, by native_decide, - by native_decide, by native_decide⟩) - (hsel0 : armSelNat uniswapV3PoolBytecode pc = uniswapV3PoolSelNat i := by - native_decide) - (hi : i < 26 := by omega) - (hnext : selArmNextPc pc (armTgtWidth code pc) = next := by - rw [uniswapV3PoolArmTgtWidthPatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) : - RD code I g s0 next [solcSelectorWord I] mem aw rdata acc (k + 5) (C + 22) := by - have hwf : armWellFormed code pc := - uniswapV3PoolArmWellFormedPatched2258 hpatch hpc hpush4 heqPc hpushT hjumpi hwf0 - have heq0 : UInt256.eq (armSelNat code pc) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch hpush4, hsel0] - simpa [uniswapV3PoolSelWord, solcSelectorWord] using by - rw [uniswapV3PoolSelectorEq I hsz i hi, hmiss] - simp - have h' := h.selectorArmNotTakenAuto hwf heq0 (by simp) - simpa [hnext] using h' - -theorem uniswapV3PoolSelectorArmHitTo {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {pc target : UInt256} {i : ℕ} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hhit : (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = true) - (h : RD code I g s0 pc [solcSelectorWord I] mem aw rdata acc k C) - (hpc : pc.toNat + 33 ≤ 2258 := by native_decide) - (hpush4 : (selArmPush4Pc pc).toNat + 33 ≤ 2258 := by native_decide) - (heqPc : (selArmEqPc pc).toNat + 33 ≤ 2258 := by native_decide) - (hpushT : (selArmPushTgtPc pc).toNat + 33 ≤ 2258 := by native_decide) - (hjumpi : - (selArmJumpiPc pc (armTgtWidth uniswapV3PoolBytecode pc)).toNat + 33 ≤ 2258 := - by native_decide) - (hwf0 : armWellFormed uniswapV3PoolBytecode pc := by - exact ⟨by native_decide, by native_decide, by native_decide, by native_decide, - by native_decide, by native_decide⟩) - (hsel0 : armSelNat uniswapV3PoolBytecode pc = uniswapV3PoolSelNat i := by - native_decide) - (hi : i < 26 := by omega) - (hjd0 : (D_J (uniswapV3PoolBytecode.extract 0 2258) 0).contains - (armTgt uniswapV3PoolBytecode pc) = true := by native_decide) - (hnext : armTgt code pc = target := by - rw [uniswapV3PoolArmTgtPatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) : - RD code I g s0 target [solcSelectorWord I] mem aw rdata acc (k + 5) (C + 22) := by - have hwf : armWellFormed code pc := - uniswapV3PoolArmWellFormedPatched2258 hpatch hpc hpush4 heqPc hpushT hjumpi hwf0 - have heq1 : UInt256.eq (armSelNat code pc) (solcSelectorWord I) = ⟨1⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch hpush4, hsel0] - simpa [uniswapV3PoolSelWord, solcSelectorWord] using by - rw [uniswapV3PoolSelectorEq I hsz i hi, hhit] - simp - have heqne : UInt256.eq (armSelNat code pc) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [heq1] - decide - have hjd : (D_J code 0).contains (armTgt code pc) = true := by - rw [uniswapV3PoolArmTgtPatchedEqTemplate2258 hpatch hpushT] - exact uniswapV3PoolJumpDestPatched2258 hpatch hjd0 - have h' := h.selectorArmTakenAuto hwf heqne hjd (by simp) - simpa [hnext] using h' - -theorem uniswapV3PoolSelectorSplitNotTakenTo {v : PoolImmutables} - {code : ByteArray} {I : ExecutionEnv} {g : Sat256} {s0 : State} - {pc next : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code I g s0 pc [solcSelectorWord I] mem aw rdata acc k C) - (hgt : UInt256.gt (armSelNat code pc) (solcSelectorWord I) = ⟨0⟩) - (hpc : pc.toNat + 33 ≤ 2258 := by native_decide) - (hpush4 : (selArmPush4Pc pc).toNat + 33 ≤ 2258 := by native_decide) - (hgtPc : (selArmEqPc pc).toNat + 33 ≤ 2258 := by native_decide) - (hpushT : (selArmPushTgtPc pc).toNat + 33 ≤ 2258 := by native_decide) - (hjumpi : - (selArmJumpiPc pc (armTgtWidth uniswapV3PoolBytecode pc)).toNat + 33 ≤ 2258 := - by native_decide) - (hwf0 : selectorSplitWellFormed uniswapV3PoolBytecode pc := by - exact ⟨by native_decide, by native_decide, by native_decide, by native_decide, - by native_decide, by native_decide⟩) - (hnext : selArmNextPc pc (armTgtWidth code pc) = next := by - rw [uniswapV3PoolArmTgtWidthPatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) : - RD code I g s0 next [solcSelectorWord I] mem aw rdata acc (k + 5) (C + 22) := by - have hwf : selectorSplitWellFormed code pc := - uniswapV3PoolSelectorSplitWellFormedPatched2258 hpatch hpc hpush4 hgtPc hpushT - hjumpi hwf0 - have h' := h.selectorSplitNotTakenAuto hwf hgt (by simp) - simpa [hnext] using h' - -theorem uniswapV3PoolSelectorSplitTakenTo {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {pc next : UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code I g s0 pc [solcSelectorWord I] mem aw rdata acc k C) - (hgt : UInt256.gt (armSelNat code pc) (solcSelectorWord I) ≠ ⟨0⟩) - (hpc : pc.toNat + 33 ≤ 2258 := by native_decide) - (hpush4 : (selArmPush4Pc pc).toNat + 33 ≤ 2258 := by native_decide) - (hgtPc : (selArmEqPc pc).toNat + 33 ≤ 2258 := by native_decide) - (hpushT : (selArmPushTgtPc pc).toNat + 33 ≤ 2258 := by native_decide) - (hjumpi : - (selArmJumpiPc pc (armTgtWidth uniswapV3PoolBytecode pc)).toNat + 33 ≤ 2258 := - by native_decide) - (hwf0 : selectorSplitWellFormed uniswapV3PoolBytecode pc := by - exact ⟨by native_decide, by native_decide, by native_decide, by native_decide, - by native_decide, by native_decide⟩) - (hjd0 : (D_J (uniswapV3PoolBytecode.extract 0 2258) 0).contains - (armTgt uniswapV3PoolBytecode pc) = true := by native_decide) - (hjdWin : (armTgt uniswapV3PoolBytecode pc).toNat + 33 ≤ 2258 := by native_decide) - (hjdDecode0 : decode uniswapV3PoolBytecode (armTgt uniswapV3PoolBytecode pc) = - some (.JUMPDEST, .none) := by native_decide) - (hnext : armTgt code pc + ⟨1⟩ = next := by - rw [uniswapV3PoolArmTgtPatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) : - RD code I g s0 next [solcSelectorWord I] mem aw rdata acc (k + 6) (C + 23) := by - have hwf : selectorSplitWellFormed code pc := - uniswapV3PoolSelectorSplitWellFormedPatched2258 hpatch hpc hpush4 hgtPc hpushT - hjumpi hwf0 - have hjd : (D_J code 0).contains (armTgt code pc) = true := by - rw [uniswapV3PoolArmTgtPatchedEqTemplate2258 hpatch hpushT] - exact uniswapV3PoolJumpDestPatched2258 hpatch hjd0 - have hjdDecode : decode code (armTgt code pc) = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolArmTgtPatchedEqTemplate2258 hpatch hpushT] - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hjdWin] - exact hjdDecode0 - have h' := h.selectorSplitTakenAuto hwf hgt hjd (by simp) - have h'' := h'.jumpdest hjdDecode (by simp) - simpa [hnext] using h'' - -theorem uniswapV3PoolFallbackTailFrom {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {pc : UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code I g s0 pc [solcSelectorWord I] mem aw rdata acc k C) - (hpushWin : pc.toNat + 33 ≤ 2258 := by native_decide) - (hjumpWin : (pc + UInt256.ofNat 3).toNat + 33 ≤ 2258 := by native_decide) - (hpush0 : decode uniswapV3PoolBytecode pc = - some (.Push .PUSH2, some (⟨430⟩, 2)) := by native_decide) - (hjump0 : decode uniswapV3PoolBytecode (pc + UInt256.ofNat 3) = - some (.JUMP, .none) := by native_decide) : - RDrev code g s0 := by - exact uniswapV3PoolFallbackRevertFrom h - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hpushWin]; exact hpush0) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hjumpWin]; exact hjump0) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp) - (by simp) - -theorem uniswapV3PoolFallbackJumpdestFrom {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code I g s0 ⟨430⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - exact RD.solcPush1Dup1Revert0 - (h.jumpdest - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp)) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp) - -theorem uniswapV3PoolNoMatch_65 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨65⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - have h76 := uniswapV3PoolSelectorArmMissTo (next := ⟨76⟩) hpatch hsz hnm 22 h - have h87 := uniswapV3PoolSelectorArmMissTo (next := ⟨87⟩) hpatch hsz hnm 23 h76 - have h98 := uniswapV3PoolSelectorArmMissTo (next := ⟨98⟩) hpatch hsz hnm 24 h87 - have h109 := uniswapV3PoolSelectorArmMissTo (next := ⟨109⟩) hpatch hsz hnm 25 h98 - exact uniswapV3PoolFallbackTailFrom hpatch h109 - -theorem uniswapV3PoolNoMatch_114 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨114⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - have h125 := uniswapV3PoolSelectorArmMissTo (next := ⟨125⟩) hpatch hsz hnm 19 h - have h136 := uniswapV3PoolSelectorArmMissTo (next := ⟨136⟩) hpatch hsz hnm 20 h125 - have h147 := uniswapV3PoolSelectorArmMissTo (next := ⟨147⟩) hpatch hsz hnm 21 h136 - exact uniswapV3PoolFallbackTailFrom hpatch h147 - -theorem uniswapV3PoolNoMatch_163 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨163⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - have h174 := uniswapV3PoolSelectorArmMissTo (next := ⟨174⟩) hpatch hsz hnm 16 h - have h185 := uniswapV3PoolSelectorArmMissTo (next := ⟨185⟩) hpatch hsz hnm 17 h174 - have h196 := uniswapV3PoolSelectorArmMissTo (next := ⟨196⟩) hpatch hsz hnm 18 h185 - exact uniswapV3PoolFallbackTailFrom hpatch h196 - -theorem uniswapV3PoolNoMatch_201 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨201⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - have h212 := uniswapV3PoolSelectorArmMissTo (next := ⟨212⟩) hpatch hsz hnm 13 h - have h223 := uniswapV3PoolSelectorArmMissTo (next := ⟨223⟩) hpatch hsz hnm 14 h212 - have h234 := uniswapV3PoolSelectorArmMissTo (next := ⟨234⟩) hpatch hsz hnm 15 h223 - exact uniswapV3PoolFallbackTailFrom hpatch h234 - -theorem uniswapV3PoolNoMatch_261 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨261⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - have h272 := uniswapV3PoolSelectorArmMissTo (next := ⟨272⟩) hpatch hsz hnm 9 h - have h283 := uniswapV3PoolSelectorArmMissTo (next := ⟨283⟩) hpatch hsz hnm 10 h272 - have h294 := uniswapV3PoolSelectorArmMissTo (next := ⟨294⟩) hpatch hsz hnm 11 h283 - have h305 := uniswapV3PoolSelectorArmMissTo (next := ⟨305⟩) hpatch hsz hnm 12 h294 - exact uniswapV3PoolFallbackTailFrom hpatch h305 - -theorem uniswapV3PoolNoMatch_310 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨310⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - have h321 := uniswapV3PoolSelectorArmMissTo (next := ⟨321⟩) hpatch hsz hnm 6 h - have h332 := uniswapV3PoolSelectorArmMissTo (next := ⟨332⟩) hpatch hsz hnm 7 h321 - have h343 := uniswapV3PoolSelectorArmMissTo (next := ⟨343⟩) hpatch hsz hnm 8 h332 - exact uniswapV3PoolFallbackTailFrom hpatch h343 - -theorem uniswapV3PoolNoMatch_359 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨359⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - have h370 := uniswapV3PoolSelectorArmMissTo (next := ⟨370⟩) hpatch hsz hnm 3 h - have h381 := uniswapV3PoolSelectorArmMissTo (next := ⟨381⟩) hpatch hsz hnm 4 h370 - have h392 := uniswapV3PoolSelectorArmMissTo (next := ⟨392⟩) hpatch hsz hnm 5 h381 - exact uniswapV3PoolFallbackTailFrom hpatch h392 - -theorem uniswapV3PoolNoMatch_397 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨397⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - have h408 := uniswapV3PoolSelectorArmMissTo (next := ⟨408⟩) hpatch hsz hnm 0 h - have h419 := uniswapV3PoolSelectorArmMissTo (next := ⟨419⟩) hpatch hsz hnm 1 h408 - have h430 := uniswapV3PoolSelectorArmMissTo (next := ⟨430⟩) hpatch hsz hnm 2 h419 - exact uniswapV3PoolFallbackJumpdestFrom hpatch h430 - -theorem uniswapV3PoolNoMatch_54 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨54⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - by_cases hgt : UInt256.gt (armSelNat code ⟨54⟩) (solcSelectorWord I) = ⟨0⟩ - · have h65 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨65⟩) hpatch h hgt - exact uniswapV3PoolNoMatch_65 hpatch hsz hnm h65 - · have h114 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨114⟩) hpatch h hgt - exact uniswapV3PoolNoMatch_114 hpatch hsz hnm h114 - -theorem uniswapV3PoolNoMatch_152 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨152⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - by_cases hgt : UInt256.gt (armSelNat code ⟨152⟩) (solcSelectorWord I) = ⟨0⟩ - · have h163 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨163⟩) hpatch h hgt - exact uniswapV3PoolNoMatch_163 hpatch hsz hnm h163 - · have h201 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨201⟩) hpatch h hgt - exact uniswapV3PoolNoMatch_201 hpatch hsz hnm h201 - -theorem uniswapV3PoolNoMatch_250 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨250⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - by_cases hgt : UInt256.gt (armSelNat code ⟨250⟩) (solcSelectorWord I) = ⟨0⟩ - · have h261 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨261⟩) hpatch h hgt - exact uniswapV3PoolNoMatch_261 hpatch hsz hnm h261 - · have h310 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨310⟩) hpatch h hgt - exact uniswapV3PoolNoMatch_310 hpatch hsz hnm h310 - -theorem uniswapV3PoolNoMatch_348 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨348⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - by_cases hgt : UInt256.gt (armSelNat code ⟨348⟩) (solcSelectorWord I) = ⟨0⟩ - · have h359 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨359⟩) hpatch h hgt - exact uniswapV3PoolNoMatch_359 hpatch hsz hnm h359 - · have h397 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨397⟩) hpatch h hgt - exact uniswapV3PoolNoMatch_397 hpatch hsz hnm h397 - -theorem uniswapV3PoolNoMatch_43 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨43⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - by_cases hgt : UInt256.gt (armSelNat code ⟨43⟩) (solcSelectorWord I) = ⟨0⟩ - · have h54 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨54⟩) hpatch h hgt - exact uniswapV3PoolNoMatch_54 hpatch hsz hnm h54 - · have h152 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨152⟩) hpatch h hgt - exact uniswapV3PoolNoMatch_152 hpatch hsz hnm h152 - -theorem uniswapV3PoolNoMatch_239 {v : PoolImmutables} {code : ByteArray} - {I : ExecutionEnv} {g : Sat256} {s0 : State} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hsz : 4 ≤ I.calldata.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) - (h : RD code I g s0 ⟨239⟩ [solcSelectorWord I] mem aw rdata acc k C) : - RDrev code g s0 := by - by_cases hgt : UInt256.gt (armSelNat code ⟨239⟩) (solcSelectorWord I) = ⟨0⟩ - · have h250 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨250⟩) hpatch h hgt - exact uniswapV3PoolNoMatch_250 hpatch hsz hnm h250 - · have h348 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨348⟩) hpatch h hgt - exact uniswapV3PoolNoMatch_348 hpatch hsz hnm h348 - -set_option maxHeartbeats 3000000 in -theorem uniswapV3PoolReachSelector32 {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨32⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact solcLegacyDispatchReachSelector - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) (bodyPc := ⟨18⟩) (loadPc := ⟨26⟩) (firstPc := ⟨32⟩) - (guardTgt := ⟨16⟩) (revertTgt := ⟨430⟩) (guardWidth := 2) (revertWidth := 2) - (guardOp := .PUSH2) (revertOp := .PUSH2) - hcode hwv hsz hsize - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (by native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by native_decide) - -set_option maxHeartbeats 3000000 in -theorem uniswapV3PoolX_noMatch {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - obtain ⟨_, _, h32⟩ := solcLegacyDispatchReachSelector - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) (bodyPc := ⟨18⟩) (loadPc := ⟨26⟩) (firstPc := ⟨32⟩) - (guardTgt := ⟨16⟩) (revertTgt := ⟨430⟩) (guardWidth := 2) (revertWidth := 2) - (guardOp := .PUSH2) (revertOp := .PUSH2) - hcode hwv hsz hsize - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (by native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by native_decide) - by_cases hgt : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) = ⟨0⟩ - · have h43 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨43⟩) hpatch h32 hgt - exact uniswapV3PoolNoMatch_43 hpatch hsz hnm h43 - · have h239 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨239⟩) hpatch h32 hgt - exact uniswapV3PoolNoMatch_239 hpatch hsz hnm h239 - -/-- Calldata shorter than a selector dispatches to no transition. -/ -theorem uniswapV3PoolDispatch_none_short (v : PoolImmutables) {cd : ByteArray} - (h : cd.size < 4) : - dispatchMsg (contract v) cd = none := by - rw [dispatchMsg_eq_dispatchList (contract v) cd (by rfl)] - change dispatchList - [ burnTransition, collectTransition v, collectprotocolTransition v, factoryTransition v, - feeTransition v, feegrowthglobal0X128Transition, feegrowthglobal1X128Transition, - flashTransition v, increaseobservationcardinalitynextTransition v, initializeTransition, - liquidityTransition, maxliquiditypertickTransition v, mintTransition v, - observationsTransition, observeTransition v, positionsTransition, protocolfeesTransition, - setfeeprotocolTransition v, slot0Transition, snapshotcumulativesinsideTransition v, - swapTransition v, tickbitmapTransition, tickspacingTransition v, ticksTransition, - token0Transition v, token1Transition v ] cd = none - exact dispatchList_none_short _ (by - intro t ht - simp at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes]; rfl - · rw [selectorOf, collectSelectorBytes v]; rfl - · rw [selectorOf, collectProtocolSelectorBytes v]; rfl - · rw [selectorOf, factorySelectorBytes v]; rfl - · rw [selectorOf, feeSelectorBytes v]; rfl - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes]; rfl - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes]; rfl - · rw [selectorOf, flashSelectorBytes v]; rfl - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v]; rfl - · rw [selectorOf, initializeSelectorBytes]; rfl - · rw [selectorOf, liquiditySelectorBytes]; rfl - · rw [selectorOf, maxLiquidityPerTickSelectorBytes v]; rfl - · rw [selectorOf, mintSelectorBytes v]; rfl - · rw [selectorOf, observationsSelectorBytes]; rfl - · rw [selectorOf, observeSelectorBytes v]; rfl - · rw [selectorOf, positionsSelectorBytes]; rfl - · rw [selectorOf, protocolFeesSelectorBytes]; rfl - · rw [selectorOf, setFeeProtocolSelectorBytes v]; rfl - · rw [selectorOf, slot0SelectorBytes]; rfl - · rw [selectorOf, snapshotCumulativesInsideSelectorBytes v]; rfl - · rw [selectorOf, swapSelectorBytes v]; rfl - · rw [selectorOf, tickBitmapSelectorBytes]; rfl - · rw [selectorOf, tickSpacingSelectorBytes v]; rfl - · rw [selectorOf, ticksSelectorBytes]; rfl - · rw [selectorOf, token0SelectorBytes v]; rfl - · rw [selectorOf, token1SelectorBytes v]; rfl) h - -/-- If none of the public selectors match, dispatch yields no transition. -/ -theorem uniswapV3PoolDispatch_none_nomatch (v : PoolImmutables) {cd : ByteArray} - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == cd.extract 0 4) = false) : - dispatchMsg (contract v) cd = none := by - apply dispatchMsg_none_of_all_ne (hfallback := by rfl) - intro t ht - simp [contract, transitions] at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes]; simpa [uniswapV3PoolSelBytes] using hnm 17 (by omega) - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hnm 10 (by omega) - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hnm 15 (by omega) - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hnm 19 (by omega) - · rw [selectorOf, feeSelectorBytes v]; simpa [uniswapV3PoolSelBytes] using hnm 22 (by omega) - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using hnm 23 (by omega) - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using hnm 8 (by omega) - · rw [selectorOf, flashSelectorBytes v]; simpa [uniswapV3PoolSelBytes] using hnm 9 (by omega) - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hnm 5 (by omega) - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using hnm 25 (by omega) - · rw [selectorOf, liquiditySelectorBytes] - simpa [uniswapV3PoolSelBytes] using hnm 2 (by omega) - · rw [selectorOf, maxLiquidityPerTickSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hnm 13 (by omega) - · rw [selectorOf, mintSelectorBytes v]; simpa [uniswapV3PoolSelBytes] using hnm 7 (by omega) - · rw [selectorOf, observationsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using hnm 4 (by omega) - · rw [selectorOf, observeSelectorBytes v]; simpa [uniswapV3PoolSelBytes] using hnm 16 (by omega) - · rw [selectorOf, positionsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using hnm 11 (by omega) - · rw [selectorOf, protocolFeesSelectorBytes] - simpa [uniswapV3PoolSelBytes] using hnm 3 (by omega) - · rw [selectorOf, setFeeProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hnm 14 (by omega) - · rw [selectorOf, slot0SelectorBytes]; simpa [uniswapV3PoolSelBytes] using hnm 6 (by omega) - · rw [selectorOf, snapshotCumulativesInsideSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hnm 18 (by omega) - · rw [selectorOf, swapSelectorBytes v]; simpa [uniswapV3PoolSelBytes] using hnm 1 (by omega) - · rw [selectorOf, tickBitmapSelectorBytes] - simpa [uniswapV3PoolSelBytes] using hnm 12 (by omega) - · rw [selectorOf, tickSpacingSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hnm 20 (by omega) - · rw [selectorOf, ticksSelectorBytes]; simpa [uniswapV3PoolSelBytes] using hnm 24 (by omega) - · rw [selectorOf, token0SelectorBytes v]; simpa [uniswapV3PoolSelBytes] using hnm 0 (by omega) - · rw [selectorOf, token1SelectorBytes v]; simpa [uniswapV3PoolSelBytes] using hnm 21 (by omega) - -theorem uniswapV3PoolNoDispatch {v : PoolImmutables} {cA gh bl σ_evm σ_solm σ₀ A I} - {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hnm : ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl - σ_evm σ_solm σ₀ g A I := by - exact (uniswapV3PoolX_noMatch (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hnm) - |>.reEquivNoDispatch hcode (uniswapV3PoolDispatch_none_nomatch v hnm) - -theorem uniswapV3PoolBodyReverts_nonPayable (v : PoolImmutables) - (t : TransitionDecl) (ht : t ∈ (contract v).transitions) - (evm : EVM.State) (locals : Store) (h : evm.executionEnv.weiValue ≠ ⟨0⟩) : - ExecTransitionBody (config v) (contract v) evm locals t.body .reverted := by - simp [contract, transitions] at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> - exact bodyReverts_nonPayable h - -set_option maxHeartbeats 2000000 in -theorem uniswapV3PoolX_callvalue_ne {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue ≠ ⟨0⟩) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - have h0 := solcGuardPrologueRD (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (g := g) hcode - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - exact RD.solcPush1Dup1Revert0 - (h0.pushConst (solcGuardTgt uniswapV3PoolBytecode) - (width := solcGuardTgtWidth uniswapV3PoolBytecode) - (op := solcGuardTgtOp uniswapV3PoolBytecode) - (by native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp only [List.length]; omega) - |>.jumpiNT - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (isZero_eq_zero_of_ne hwv) - (by simp only [List.length]; omega)) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp only [List.length]; omega) - -set_option maxHeartbeats 2000000 in -theorem uniswapV3PoolX_short {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) (hsz : I.calldata.size < 4) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - have h0 := solcGuardPrologueRD (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) - (A := A) (g := g) hcode - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - obtain ⟨_, _, h1⟩ := solcGuardCallvalueZero - (ctgt := solcGuardTgt uniswapV3PoolBytecode) - (opC := solcGuardTgtOp uniswapV3PoolBytecode) - (wC := solcGuardTgtWidth uniswapV3PoolBytecode) h0 hwv - (by native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - exact RD.solcPush1Dup1Revert0 - (h1.push1 ⟨4⟩ - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp only [List.length]; omega) - |>.calldatasize - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp only [List.length]; omega) - |>.lt - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp only [List.length]; omega) - |>.pushConst (solcCalldataRevertTgt uniswapV3PoolBytecode) - (width := solcCalldataRevertTgtWidth uniswapV3PoolBytecode) - (op := solcCalldataRevertTgtOp uniswapV3PoolBytecode) - (by native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp only [List.length]; omega) - |>.jumpiT - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (lt_four_ne_zero_of_lt hsz) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (by simp only [List.length]; omega) - |>.jumpdest - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp only [List.length]; omega)) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by simp only [List.length]; omega) - -theorem uniswapV3PoolShortRevert {v : PoolImmutables} {cA gh bl σ_evm σ_solm σ₀ A I} - {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) - (_hsize : I.calldata.size < UInt256.size) (_hperm : I.perm = true) - (hwv : I.weiValue = ⟨0⟩) (hsz : I.calldata.size < 4) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl - σ_evm σ_solm σ₀ g A I := by - exact (uniswapV3PoolX_short (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz) - |>.reEquivNoDispatch hcode (uniswapV3PoolDispatch_none_short v hsz) - -theorem uniswapV3PoolNonPayable {v : PoolImmutables} {cA gh bl σ_evm σ_solm σ₀ A I} - {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue ≠ ⟨0⟩) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl - σ_evm σ_solm σ₀ g A I := by - exact (uniswapV3PoolX_callvalue_ne (g := Sat256.ofUInt256 g) hpatch hcode hwv) - |>.reEquivElim hcode - fun _ _ hrev => by - by_cases hdisp : dispatchMsg (contract v) I.calldata = none - · exact reEquiv_noDispatch hdisp hrev - · obtain ⟨t, ht⟩ := Option.ne_none_iff_exists'.mp hdisp - have htmem : t ∈ (contract v).transitions := by - rw [dispatchMsg_eq_dispatchList (contract v) I.calldata (by rfl)] at ht - exact dispatchList_some_mem ht - by_cases hdec : decodeCalldataWithMode (config v).abiDecodeMode (t.params.map Param.name) - (transitionSignature t).paramTypes I.calldata = none - · exact reEquiv_decodingFailed ht hdec hrev - · obtain ⟨callargs, hca⟩ := Option.ne_none_iff_exists'.mp hdec - exact reEquiv_execution ht hca - (uniswapV3PoolBodyReverts_nonPayable v t htmem - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) callargs - (by simp only [initState]; exact hwv)) - (by rw [hrev]; exact execResultsEquiv.revert rfl rfl) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Correct.lean b/Benchmarks/UniswapV3Pool/Correct.lean deleted file mode 100644 index 904a936d..00000000 --- a/Benchmarks/UniswapV3Pool/Correct.lean +++ /dev/null @@ -1,177 +0,0 @@ -import Benchmarks.UniswapV3Pool.Constructor -import Benchmarks.UniswapV3Pool.Functions -import Solm.Equiv - -/-! -# UniswapV3Pool benchmark correctness stub - -Parameterized over the pool's immutable values `v`. For each `v`, the deployed runtime is the -template patched with `v` (`patchRuntime uniswapV3PoolBytecode (patches v) = some code`), and runtime -equivalence is stated against `contract v` (whose immutable getters return `v`'s values). The -whole-contract bundle pairs this with the parameterized constructor target. All proofs are targets. --/ - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolCorrect (v : PoolImmutables) {code : ByteArray} - (hcode : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - runtimeEquivalence (config v) code (contract v) := by - constructor - intro cA gh bl σ_evm σ_solm σ₀ g A I hIcode hsize hperm haccounts - by_cases hwv : I.weiValue = ⟨0⟩ - · by_cases hshort : I.calldata.size < 4 - · exact uniswapV3PoolShortRevert (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := g) (hpatch := hcode) (hcode := hIcode) (_hsize := hsize) - (_hperm := hperm) (hwv := hwv) (hsz := hshort) - · have hsz : 4 ≤ I.calldata.size := by omega - by_cases hnm : - ∀ i, i < 26 → (uniswapV3PoolSelBytes i == I.calldata.extract 0 4) = false - · exact uniswapV3PoolNoDispatch (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) (hsz := hsz) - (hsize := hsize) (_hperm := hperm) (hnm := hnm) - · exact uniswapV3PoolSelectorMatchCases I hnm - (fun hsel => uniswapV3PoolToken0BodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolSwapBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolLiquidityBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolProtocolFeesBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolObservationsBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolIncreaseObservationCardinalityNextBodyCore (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) - (σ₀ := σ₀) (A := A) (I := I) (g := g) (hpatch := hcode) - (hcode := hIcode) (hwv := hwv) (hsz := hsz) (hsize := hsize) - (_hperm := hperm) (hAccounts := haccounts) (hsel := hsel)) - (fun hsel => uniswapV3PoolSlot0BodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolMintBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolFeeGrowthGlobal1X128BodyCore (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) - (hwv := hwv) (hsz := hsz) (hsize := hsize) (_hperm := hperm) - (hAccounts := haccounts) (hsel := hsel)) - (fun hsel => uniswapV3PoolFlashBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolCollectBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolPositionsBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolTickBitmapBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolMaxLiquidityPerTickBodyCore (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) - (hwv := hwv) (hsz := hsz) (hsize := hsize) (_hperm := hperm) - (hAccounts := haccounts) (hsel := hsel)) - (fun hsel => uniswapV3PoolSetFeeProtocolBodyCore (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) - (hwv := hwv) (hsz := hsz) (hsize := hsize) (_hperm := hperm) - (hAccounts := haccounts) (hsel := hsel)) - (fun hsel => uniswapV3PoolCollectProtocolBodyCore (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) - (hwv := hwv) (hsz := hsz) (hsize := hsize) (_hperm := hperm) - (hAccounts := haccounts) (hsel := hsel)) - (fun hsel => uniswapV3PoolObserveBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolBurnBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolSnapshotCumulativesInsideBodyCore (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) - (σ₀ := σ₀) (A := A) (I := I) (g := g) (hpatch := hcode) - (hcode := hIcode) (hwv := hwv) (hsz := hsz) (hsize := hsize) - (_hperm := hperm) (hAccounts := haccounts) (hsel := hsel)) - (fun hsel => uniswapV3PoolFactoryBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolTickSpacingBodyCore (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) - (hwv := hwv) (hsz := hsz) (hsize := hsize) (_hperm := hperm) - (hAccounts := haccounts) (hsel := hsel)) - (fun hsel => uniswapV3PoolToken1BodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolFeeBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolFeeGrowthGlobal0X128BodyCore (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) - (hwv := hwv) (hsz := hsz) (hsize := hsize) (_hperm := hperm) - (hAccounts := haccounts) (hsel := hsel)) - (fun hsel => uniswapV3PoolTicksBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - (fun hsel => uniswapV3PoolInitializeBodyCore (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := g) (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - (hsz := hsz) (hsize := hsize) (_hperm := hperm) (hAccounts := haccounts) - (hsel := hsel)) - · exact uniswapV3PoolNonPayable (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ_evm := σ_evm) (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (hpatch := hcode) (hcode := hIcode) (hwv := hwv) - -theorem uniswapV3PoolContractCorrect (v : PoolImmutables) {code : ByteArray} - (hcode : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - contractEquivalenceWith (config v) uniswapV3PoolCreationBytecode code (contract v) - (runtimeCodeOf uniswapV3PoolBytecode) := - contractEquivalenceWith.intro (uniswapV3PoolConstructorCorrect v) (uniswapV3PoolCorrect v hcode) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Factory.lean b/Benchmarks/UniswapV3Pool/Factory.lean deleted file mode 100644 index ff7a6ac9..00000000 --- a/Benchmarks/UniswapV3Pool/Factory.lean +++ /dev/null @@ -1,177 +0,0 @@ -import Benchmarks.UniswapV3Pool.ImmutableGetters - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolFactoryReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 19 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨2001⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 19 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0xc4 0x5a 0x01 0x55 - (uniswapV3PoolSelNat 19) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h43 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨43⟩) hpatch h32 hgt32 - have hgt43 : UInt256.gt (armSelNat code ⟨43⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h54 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨54⟩) hpatch h43 hgt43 - have hgt54 : UInt256.gt (armSelNat code ⟨54⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h114 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨114⟩) hpatch h54 hgt54 - have h2001 := uniswapV3PoolSelectorArmHitTo (i := 19) (target := ⟨2001⟩) - hpatch hsz hsel h114 - exact ⟨_, _, h2001⟩ - -theorem uniswapV3PoolFactoryDecode {v : PoolImmutables} {I : ExecutionEnv} - (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode ((factoryTransition v).params.map Param.name) - (transitionSignature (factoryTransition v)).paramTypes I.calldata = some (∅ : Store) := by - simpa [config, factoryTransition, transitionSignature] using - decodeCalldataWithMode_empty_ok (mode := DecodeMode.legacySolc05) (cd := I.calldata) hsz - -theorem uniswapV3PoolDispatch_factory {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 19 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some (factoryTransition v) := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v]) - (post := [feeTransition v, feegrowthglobal0X128Transition, feegrowthglobal1X128Transition, - flashTransition v, increaseobservationcardinalitynextTransition v, initializeTransition, - liquidityTransition, maxliquiditypertickTransition v, mintTransition v, observationsTransition, - observeTransition v, positionsTransition, protocolfeesTransition, setfeeprotocolTransition v, - slot0Transition, snapshotcumulativesinsideTransition v, swapTransition v, tickbitmapTransition, - tickspacingTransition v, ticksTransition, token0Transition v, token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 19) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 19) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 19) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hsel - -theorem uniswapV3PoolFactoryEntryWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcGetterEntryWf code ⟨2001⟩ ⟨443⟩ ⟨10455⟩ := by - dsimp [solcGetterEntryWf] - refine ⟨?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolFactoryGetterWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcConstGetterWf code ⟨10455⟩ (EVM.Word.ofNat v.factory.toNat) 32 .PUSH32 := by - dsimp [solcConstGetterWf] - refine ⟨?_, ?_, ?_, ?_, ?_⟩ - · exact uniswapV3PoolFactoryGetterJumpdestDecode hpatch - · native_decide - · exact uniswapV3PoolFactoryConstDecode hpatch - · exact uniswapV3PoolFactoryGetterDupDecode hpatch - · exact uniswapV3PoolFactoryGetterJumpDecode hpatch - -theorem uniswapV3PoolFactoryReturnWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcReturnAddressFromMemWf code ⟨443⟩ := - uniswapV3PoolReturnAddress443Wf hpatch - -theorem uniswapV3PoolFactoryRoutineJumpDest {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10455⟩ = true := - uniswapV3PoolJumpDestPatched10455 hpatch - -theorem uniswapV3PoolFactoryReturnJumpDest {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨443⟩ = true := - uniswapV3PoolReturn443JumpDest hpatch - -theorem uniswapV3PoolFactoryEvm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 19 == I.calldata.extract 0 4) = true) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land (EVM.Word.ofNat v.factory.toNat) solcAddrMask)) := by - have hreach := uniswapV3PoolFactoryReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - exact RD.solcAddressConstGetterExternal - (sel := solcSelectorWord I) (entry := ⟨2001⟩) (routine := ⟨10455⟩) - (returnPc := ⟨443⟩) (val := EVM.Word.ofNat v.factory.toNat) (width := 32) - (op := .PUSH32) hreach - (uniswapV3PoolFactoryEntryWf hpatch) - (uniswapV3PoolFactoryGetterWf hpatch) - (uniswapV3PoolFactoryRoutineJumpDest hpatch) - (uniswapV3PoolFactoryReturnJumpDest hpatch) - (uniswapV3PoolFactoryReturnWf hpatch) - -theorem uniswapV3PoolFactorySourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) (factoryTransition v).body - (.returned { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) - (some [Value.address (AccountAddress.ofNat v.factory.toNat)])) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [addrLit v.factory] ] _ - apply nonpayableReturnExprBodyReturns - · simp [initState, hwv] - · exact uniswapV3PoolAddrLitEval (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) v.factory - -theorem uniswapV3PoolFactoryValueTransport {v : PoolImmutables} : - some [Value.address (AccountAddress.ofNat v.factory.toNat)] = - some [Value.address (AccountAddress.ofNat - (UInt256.land (EVM.Word.ofNat v.factory.toNat) solcAddrMask).toNat)] := - uniswapV3PoolAddressValueTransport v.factory - -theorem uniswapV3PoolFactoryBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 19 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_factory (v := v) (cd := I.calldata) hsel - have hdecode := uniswapV3PoolFactoryDecode (v := v) (I := I) hsz - have hbody := uniswapV3PoolFactorySourceBody (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hrd := uniswapV3PoolFactoryEvm (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel - exact hrd.reEquivExecutionTransport hcode hdispatch hdecode hbody - (uniswapV3PoolFactoryValueTransport (v := v)) hAccounts - (returnEquiv_of_encode - (solcAddressReturnEncoding rfl (EVM.Word.ofNat v.factory.toNat))) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Fee.lean b/Benchmarks/UniswapV3Pool/Fee.lean deleted file mode 100644 index e3cddd0e..00000000 --- a/Benchmarks/UniswapV3Pool/Fee.lean +++ /dev/null @@ -1,483 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def uint24Mask : UInt256 := UInt256.ofNat (2 ^ 24 - 1) - -theorem uint24Mask_toNat : - uint24Mask.toNat = 2 ^ 24 - 1 := by - exact ulit_toNat' _ (by norm_num [UInt256.size]) - -theorem uint24Mask_bound (w : UInt256) : - (UInt256.land w uint24Mask).toNat < EVM.twoPow 24 := by - rw [uland_toNat] - rw [uint24Mask_toNat] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [EVM.twoPow]) - -theorem uint24Mask_clean {w : UInt256} (hcanon : w.toNat < EVM.twoPow 24) : - UInt256.land w uint24Mask = w := by - apply u256_inj - show Nat.land w.toNat uint24Mask.toNat % EVM.twoPow 256 = w.toNat - rw [uint24Mask_toNat, nat_land_mask_eq_mod] - rw [show EVM.twoPow 24 = 2 ^ 24 from rfl] at hcanon - rw [Nat.mod_eq_of_lt hcanon] - exact Nat.mod_eq_of_lt w.val.isLt - -theorem uint24ReturnEncodingInt (i : Int) (h0 : 0 ≤ i) (hlt : i < 2 ^ 24) : - encodeReturnValue? uint24 (.int i) = some (UInt256.toByteArray (EVM.wordOfInt i)) := by - have hword : EVM.wordOfInt i = EVM.word i.toNat := wordOfInt_nonneg i h0 - have hltWord : i < ↑(EVM.twoPow 24) := by - simpa [EVM.twoPow] using hlt - refine scalarReturnEncoding (t := (.int (.uint ⟨24, by decide⟩))) - (w := EVM.wordOfInt i) rfl ?_ ?_ - · simp only [abiTupleHeadSize?, staticABIEncodedSize?, isDynamicABIType, bind, Option.bind] - decide - · simp [encodeABIValue?, encodeABIWord?, hword, h0, hltWord] - -theorem uint24MaskCleanOfInt (i : Int) (h0 : 0 ≤ i) (hlt : i < 2 ^ 24) : - UInt256.land (EVM.wordOfInt i) uint24Mask = EVM.wordOfInt i := by - apply uint24Mask_clean - rw [wordOfInt_nonneg i h0] - have hltNat : i.toNat < EVM.twoPow 24 := by - exact (Int.toNat_lt h0).2 (by simpa [EVM.twoPow] using hlt) - unfold EVM.word EVM.uintN UInt256.toNat - simp only - rw [Nat.mod_eq_of_lt] - · exact hltNat - · have : EVM.twoPow 24 < EVM.twoPow 256 := by - norm_num [EVM.twoPow] - omega - -private theorem uniswapV3PoolPatchPreservesJumpDest10563 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨10563⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched10563 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10563⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest10563 - -theorem uniswapV3PoolFeeReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 22 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨2048⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 22 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0xdd 0xca 0x3f 0x43 - (uniswapV3PoolSelNat 22) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h43 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨43⟩) hpatch h32 hgt32 - have hgt43 : UInt256.gt (armSelNat code ⟨43⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h54 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨54⟩) hpatch h43 hgt43 - have hgt54 : UInt256.gt (armSelNat code ⟨54⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h65 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨65⟩) hpatch h54 hgt54 - have h2048 := uniswapV3PoolSelectorArmHitTo (i := 22) (target := ⟨2048⟩) - hpatch hsz hsel h65 - exact ⟨_, _, h2048⟩ - -theorem uniswapV3PoolFeeDecode {v : PoolImmutables} {I : ExecutionEnv} - (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode ((feeTransition v).params.map Param.name) - (transitionSignature (feeTransition v)).paramTypes I.calldata = some (∅ : Store) := by - simpa [config, feeTransition, transitionSignature] using - decodeCalldataWithMode_empty_ok (mode := DecodeMode.legacySolc05) (cd := I.calldata) hsz - -theorem uniswapV3PoolDispatch_fee {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 22 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some (feeTransition v) := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, factoryTransition v]) - (post := [feegrowthglobal0X128Transition, feegrowthglobal1X128Transition, flashTransition v, - increaseobservationcardinalitynextTransition v, initializeTransition, liquidityTransition, - maxliquiditypertickTransition v, mintTransition v, observationsTransition, observeTransition v, - positionsTransition, protocolfeesTransition, setfeeprotocolTransition v, slot0Transition, - snapshotcumulativesinsideTransition v, swapTransition v, tickbitmapTransition, - tickspacingTransition v, ticksTransition, token0Transition v, token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 22) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 22) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 22) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 22) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hsel - -theorem uniswapV3PoolFeePatchWord {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - code.extract 10565 10597 = UInt256.toByteArray (EVM.wordOfInt v.fee) := by - let value := UInt256.toByteArray (EVM.wordOfInt v.fee) - let pre : List (Nat × ByteArray) := - [(8315, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (8829, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (10457, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (2258, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4853, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (6740, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (7822, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (9150, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (15650, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4551, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (6789, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (7924, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (9284, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (10529, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (15979, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (3311, value), (6603, value), (6658, value)] - let post : List (Nat × ByteArray) := - [(3072, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (10493, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19402, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19452, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (8174, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19295, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19350, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (11259, UInt256.toByteArray (EVM.Word.ofNat v.original.toNat))] - have hpatch' : patchRuntime uniswapV3PoolBytecode (pre ++ (10565, value) :: post) = - some code := by - dsimp [pre, post, value] - simpa [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup, - toByteArray_eq_toBytesBE] using hpatch - have hpost : ∀ p ∈ post, 10565 + 32 ≤ p.1 ∨ p.1 + 32 ≤ 10565 := by - intro p hp - dsimp [post] at hp - simp at hp - rcases hp with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - have hsize : value.size = 32 := by - dsimp [value] - exact toByteArray_size _ - exact patchRuntime_extract_patch hsize hpost hpatch' - -theorem uniswapV3PoolFeeConstDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10564⟩ = some (.Push .PUSH32, some (EVM.wordOfInt v.fee, 32)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have hget : code.get? ({ val := 10564 } : UInt256).toNat = - uniswapV3PoolBytecode.get? ({ val := 10564 } : UInt256).toNat := by - change code.get? 10564 = uniswapV3PoolBytecode.get? 10564 - apply get?_eq_of_extract_one - · rw [hsize] - native_decide - · native_decide - · exact patchRuntime_extract_eq (start := 10564) (stop := 10565) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by native_decide) - (fun p hp => by - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl - all_goals omega) hpatch - have hextract : code.extract' ({ val := 10564 } : UInt256).toNat.succ - (({ val := 10564 } : UInt256).toNat.succ + 32) = - UInt256.toByteArray (EVM.wordOfInt v.fee) := by - change code.extract' 10565 10597 = UInt256.toByteArray (EVM.wordOfInt v.fee) - unfold ByteArray.extract' - have hguard : (decide (10565 < 2 ^ 64) && decide (10597 < 2 ^ 64)) = true := by - native_decide - rw [if_pos hguard] - exact uniswapV3PoolFeePatchWord hpatch - have hgetSome : code.get? ({ val := 10564 } : UInt256).toNat = some 0x7f := by - rw [hget] - native_decide - have hparse : (some (0x7f : UInt8) >>= parseInstr) = some (.Push .PUSH32) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH32, - some (uInt256OfByteArray - (code.extract' ({ val := 10564 } : UInt256).toNat.succ - (({ val := 10564 } : UInt256).toNat.succ + 32)), 32)) = - some (Operation.Push Operation.POp.PUSH32, some (EVM.wordOfInt v.fee, 32)) - rw [hextract, uInt256OfByteArray_eq, fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - -theorem uniswapV3PoolFeeGetterJumpdestDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10563⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨10563⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 10564 ≤ p.1 ∨ p.1 + 32 ≤ 10563 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolFeeGetterDupDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10597⟩ = some (.DUP2, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨10597⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 10598 ≤ p.1 ∨ p.1 + 32 ≤ 10597 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolFeeGetterJumpDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10598⟩ = some (.JUMP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨10598⟩) (byte := 0x56) - (op := .JUMP) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 10599 ≤ p.1 ∨ p.1 + 32 ≤ 10598 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolFeeEntryWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcGetterEntryWf code ⟨2048⟩ ⟨2056⟩ ⟨10563⟩ := by - dsimp [solcGetterEntryWf] - refine ⟨?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolFeeGetterWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcConstGetterWf code ⟨10563⟩ (EVM.wordOfInt v.fee) 32 .PUSH32 := by - dsimp [solcConstGetterWf] - refine ⟨?_, ?_, ?_, ?_, ?_⟩ - · exact uniswapV3PoolFeeGetterJumpdestDecode hpatch - · native_decide - · exact uniswapV3PoolFeeConstDecode hpatch - · exact uniswapV3PoolFeeGetterDupDecode hpatch - · exact uniswapV3PoolFeeGetterJumpDecode hpatch - -@[reducible] def solcReturnUint24FromMemWf (code : ByteArray) (pc : UInt256) : Prop := - let p1 := pc + ⟨1⟩ - let p3 := p1 + UInt256.ofNat 2 - let p4 := p3 + ⟨1⟩ - let p5 := p4 + ⟨1⟩ - let p9 := p5 + UInt256.ofNat 4 - let p10 := p9 + ⟨1⟩ - let p11 := p10 + ⟨1⟩ - let p12 := p11 + ⟨1⟩ - let p13 := p12 + ⟨1⟩ - let p14 := p13 + ⟨1⟩ - let p15 := p14 + ⟨1⟩ - let p16 := p15 + ⟨1⟩ - let p17 := p16 + ⟨1⟩ - let p18 := p17 + ⟨1⟩ - let p19 := p18 + ⟨1⟩ - let p21 := p19 + UInt256.ofNat 2 - let p22 := p21 + ⟨1⟩ - let p23 := p22 + ⟨1⟩ - decode code pc = some (.JUMPDEST, .none) - ∧ decode code p1 = some (.Push .PUSH1, some (⟨64⟩, 1)) - ∧ decode code p3 = some (.DUP1, .none) - ∧ decode code p4 = some (.MLOAD, .none) - ∧ decode code p5 = some (.Push .PUSH3, some (uint24Mask, 3)) - ∧ decode code p9 = some (.SWAP1, .none) - ∧ decode code p10 = some (.SWAP3, .none) - ∧ decode code p11 = some (.AND, .none) - ∧ decode code p12 = some (.DUP3, .none) - ∧ decode code p13 = some (.MSTORE, .none) - ∧ decode code p14 = some (.MLOAD, .none) - ∧ decode code p15 = some (.SWAP1, .none) - ∧ decode code p16 = some (.DUP2, .none) - ∧ decode code p17 = some (.SWAP1, .none) - ∧ decode code p18 = some (.SUB, .none) - ∧ decode code p19 = some (.Push .PUSH1, some (⟨32⟩, 1)) - ∧ decode code p21 = some (.ADD, .none) - ∧ decode code p22 = some (.SWAP1, .none) - ∧ decode code p23 = some (.RETURN, .none) - -theorem RD.solcReturnUint24FromMem {code : ByteArray} {g : Sat256} {s0 : State} - {ee : ExecutionEnv} {k C : ℕ} {pc val ret : UInt256} {R : List UInt256} - {mem memout rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - (h : RD code ee g s0 pc (val :: ret :: R) mem (UInt256.ofNat 3) rdata acc k C) - (hwf : solcReturnUint24FromMemWf code pc) - (hmload64 : - (if (⟨64⟩ : UInt256).toNat ≥ mem.size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 3 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (mem.readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩) - (hmemout : - (UInt256.toByteArray (UInt256.land val uint24Mask)).write 0 mem 128 32 = memout) - (hmemoutLoad64 : - (if (⟨64⟩ : UInt256).toNat ≥ memout.size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 5 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (memout.readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩) - (hread128 : - memout.readWithPadding 128 32 = UInt256.toByteArray (UInt256.land val uint24Mask)) - (hov : R.length + 9 ≤ 1024) : - RDret code g s0 acc (UInt256.toByteArray (UInt256.land val uint24Mask)) := by - rcases hwf with - ⟨hd0, hd1, hd3, hd4, hd5, hd9, hd10, hd11, hd12, hd13, hd14, hd15, hd16, - hd17, hd18, hd19, hd21, hd22, hd23⟩ - exact evm_run h with [ - raw jumpdest hd0 (by evm_ov), - raw push1 ⟨64⟩ hd1 (by evm_ov), - raw dup1 hd3 (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) hd4 mem_cost hmload64 (by decide) (by evm_ov), - raw pushConst uint24Mask (by native_decide) hd5 (by evm_ov), - raw swap1 hd9 (by evm_ov), - raw swap3 hd10 (by evm_ov), - raw and hd11 (by evm_ov), - raw dup3 hd12 (by evm_ov), - raw mstore 6 memout (UInt256.ofNat 5) hd13 mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - exact hmemout) - (by decide) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 5) hd14 mem_cost hmemoutLoad64 (by decide) - (by evm_ov), - raw swap1 hd15 (by evm_ov), - raw dup2 hd16 (by evm_ov), - raw swap1 hd17 (by evm_ov), - raw sub hd18 (by evm_ov), - raw push1 ⟨32⟩ hd19 (by evm_ov), - raw add hd21 (by evm_ov), - raw swap1 hd22 (by evm_ov), - raw ret 0 (UInt256.toByteArray (UInt256.land val uint24Mask)) hd23 mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - show ((⟨32⟩ : UInt256) + UInt256.sub (⟨128⟩ : UInt256) ⟨128⟩).toNat = 32 - from by decide] - exact hread128) - (by evm_ov)] - -theorem RD.solcUint24ConstGetterExternal {code : ByteArray} {cA gh bl σ σ₀ A I} - {g : Sat256} {sel entry routine returnPc val : UInt256} {width : Nat} - {op : Operation.POp} - (hreach : ∃ k C, RD code I g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) - entry [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hentry : solcGetterEntryWf code entry returnPc routine) - (hgetter : solcConstGetterWf code routine val width op) - (hroutine : (D_J code 0).contains routine = true) - (hret : (D_J code 0).contains returnPc = true) - (hreturn : solcReturnUint24FromMemWf code returnPc) : - RDret code g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land val uint24Mask)) := by - obtain ⟨_, _, rdRoutine⟩ := RD.solcGetterThunk hreach hentry hroutine - obtain ⟨_, _, rdReturn⟩ := RD.solcConstGetter (val := val) (width := width) - (op := op) (R := [sel]) rdRoutine hgetter hret - (by simp only [List.length_singleton]; omega) - exact RD.solcReturnUint24FromMem rdReturn hreturn - solcFreePtrMem_mload64 - (by rfl) - (solcReturnMem_mload64 (UInt256.land val uint24Mask)) - (solcReturnMem_read128 (UInt256.land val uint24Mask)) - (by simp only [List.length_singleton]; omega) - -theorem uniswapV3PoolFeeReturnWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcReturnUint24FromMemWf code ⟨2056⟩ := by - dsimp [solcReturnUint24FromMemWf] - refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolFeeReturnJumpDest {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨2056⟩ = true := - uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide) - -theorem uniswapV3PoolFeeEvm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 22 == I.calldata.extract 0 4) = true) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land (EVM.wordOfInt v.fee) uint24Mask)) := by - have hreach := uniswapV3PoolFeeReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - exact RD.solcUint24ConstGetterExternal - (sel := solcSelectorWord I) (entry := ⟨2048⟩) (routine := ⟨10563⟩) - (returnPc := ⟨2056⟩) (val := EVM.wordOfInt v.fee) (width := 32) - (op := .PUSH32) hreach - (uniswapV3PoolFeeEntryWf hpatch) - (uniswapV3PoolFeeGetterWf hpatch) - (uniswapV3PoolJumpDestPatched10563 hpatch) - (uniswapV3PoolFeeReturnJumpDest hpatch) - (uniswapV3PoolFeeReturnWf hpatch) - -theorem uniswapV3PoolFeeSourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) (feeTransition v).body - (.returned { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) - (some [Value.int v.fee])) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [.intLit v.fee] ] _ - exact nonpayableIntLiteralBodyReturns (initState cA gh bl σ σ₀ g A I) - (∅ : Store) v.fee hwv - -theorem uniswapV3PoolFeeBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 22 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_fee (v := v) (cd := I.calldata) hsel - have hdecode := uniswapV3PoolFeeDecode (v := v) (I := I) hsz - have hbody := uniswapV3PoolFeeSourceBody (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hrd := uniswapV3PoolFeeEvm (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel - have hmask := uint24MaskCleanOfInt v.fee v.fee_nonneg v.fee_lt - exact hrd.reEquivExecution hcode hdispatch hdecode hbody hAccounts - (returnEquiv_of_encode (by - simpa [hmask] using uint24ReturnEncodingInt v.fee v.fee_nonneg v.fee_lt)) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/FeeGrowthGlobal0X128.lean b/Benchmarks/UniswapV3Pool/FeeGrowthGlobal0X128.lean deleted file mode 100644 index 04abb0e7..00000000 --- a/Benchmarks/UniswapV3Pool/FeeGrowthGlobal0X128.lean +++ /dev/null @@ -1,218 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolFeeGrowthGlobal0X128ReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 23 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨2080⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 23 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0xf3 0x05 0x83 0x99 - (uniswapV3PoolSelNat 23) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h43 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨43⟩) hpatch h32 hgt32 - have hgt43 : UInt256.gt (armSelNat code ⟨43⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h54 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨54⟩) hpatch h43 hgt43 - have hgt54 : UInt256.gt (armSelNat code ⟨54⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h65 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨65⟩) hpatch h54 hgt54 - have hmiss22 : (uniswapV3PoolSelBytes 22 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h76 := uniswapV3PoolSelectorArmMissToOf (i := 22) (next := ⟨76⟩) - hpatch hsz hmiss22 h65 - have h2080 := uniswapV3PoolSelectorArmHitTo (i := 23) (target := ⟨2080⟩) - hpatch hsz hsel h76 - exact ⟨_, _, h2080⟩ - -theorem uniswapV3PoolFeeGrowthGlobal0X128Decode {v : PoolImmutables} {I : ExecutionEnv} - (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - (feegrowthglobal0X128Transition.params.map Param.name) - (transitionSignature feegrowthglobal0X128Transition).paramTypes I.calldata = - some (∅ : Store) := by - simpa [config, feegrowthglobal0X128Transition, transitionSignature] using - decodeCalldataWithMode_empty_ok (mode := DecodeMode.legacySolc05) (cd := I.calldata) hsz - -theorem uniswapV3PoolDispatch_feeGrowthGlobal0X128 {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 23 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some feegrowthglobal0X128Transition := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, - factoryTransition v, feeTransition v]) - (post := [feegrowthglobal1X128Transition, flashTransition v, - increaseobservationcardinalitynextTransition v, initializeTransition, liquidityTransition, - maxliquiditypertickTransition v, mintTransition v, observationsTransition, - observeTransition v, positionsTransition, protocolfeesTransition, setfeeprotocolTransition v, - slot0Transition, snapshotcumulativesinsideTransition v, swapTransition v, - tickbitmapTransition, tickspacingTransition v, ticksTransition, token0Transition v, - token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 23) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 23) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 23) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 23) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 23) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using hsel - -private theorem uniswapV3PoolFeeGrowthGlobal0X128PatchDisjoint {v : PoolImmutables} - {pc : UInt256} (hlo : 10599 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 11259) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> - omega - -theorem uniswapV3PoolFeeGrowthGlobal0X128EntryWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcGetterEntryWf code ⟨2080⟩ ⟨1118⟩ ⟨10599⟩ := by - dsimp [solcGetterEntryWf] - refine ⟨?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolFeeGrowthGlobal0X128GetterWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcWordSlotGetterWf code ⟨10599⟩ ⟨1⟩ := by - dsimp [solcWordSlotGetterWf] - refine ⟨?_, ?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolFeeGrowthGlobal0X128PatchDisjoint - (by native_decide) (by native_decide))] - native_decide - -theorem uniswapV3PoolFeeGrowthGlobal0X128ReturnWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcReturnWordFromMemWf code ⟨1118⟩ := by - dsimp [solcReturnWordFromMemWf] - refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolFeeGrowthGlobal0X128RoutineJumpDest {v : PoolImmutables} - {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10599⟩ = true := - uniswapV3PoolJumpDestPatched10599 hpatch - -theorem uniswapV3PoolFeeGrowthGlobal0X128ReturnJumpDest {v : PoolImmutables} - {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨1118⟩ = true := - uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide) - -theorem uniswapV3PoolFeeGrowthGlobal0X128Evm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 23 == I.calldata.extract 0 4) = true) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (solcSlotWord σ I ⟨1⟩)) := by - have hreach := uniswapV3PoolFeeGrowthGlobal0X128ReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - exact RD.solcWordGetterExternal (slot := ⟨1⟩) hreach - (uniswapV3PoolFeeGrowthGlobal0X128EntryWf hpatch) - (uniswapV3PoolFeeGrowthGlobal0X128GetterWf hpatch) - (uniswapV3PoolFeeGrowthGlobal0X128RoutineJumpDest hpatch) - (uniswapV3PoolFeeGrowthGlobal0X128ReturnJumpDest hpatch) - (uniswapV3PoolFeeGrowthGlobal0X128ReturnWf hpatch) - -theorem uniswapV3PoolFeeGrowthGlobal0X128SourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) feegrowthglobal0X128Transition.body - (.returned { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) - (some [Value.int (Int.ofNat (solcSlotWord σ I ⟨1⟩).toNat)])) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [.storage feeGrowthGlobal0X128Ref] ] _ - apply nonpayableReturnExprBodyReturns - · simp [initState, hwv] - · apply evalExpr_storage_scalar_value - (er := { base := "feeGrowthGlobal0X128", steps := [] }) - (t := .int uint256Int) - (loc := loc ⟨1⟩ ⟨0, by decide⟩ ⟨32, by decide⟩ (by decide) (.int uint256Int)) - · simp [feeGrowthGlobal0X128Ref] - · simp [evalStorageRef, feeGrowthGlobal0X128Ref, pure, bind, EvalResult.bind] - · simp [contract, storageDecls, storageTypeAt?, uint256St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc] - · simpa [initState, solcSlotWord, loc, uint256Loc] using - (storageLocLoad_uint256 (initState cA gh bl σ σ₀ g A I) ⟨1⟩) - -theorem uniswapV3PoolFeeGrowthGlobal0X128ValueTransport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - some [Value.int (Int.ofNat (solcSlotWord σ_solm I ⟨1⟩).toNat)] = - some [Value.int (Int.ofNat (solcSlotWord σ_evm I ⟨1⟩).toNat)] := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨1⟩ (⟨0⟩ : UInt256) - dsimp [solcSlotWord] - rw [← hslot] - -theorem uniswapV3PoolFeeGrowthGlobal0X128BodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 23 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_feeGrowthGlobal0X128 (v := v) (cd := I.calldata) hsel - have hdecode := uniswapV3PoolFeeGrowthGlobal0X128Decode (v := v) (I := I) hsz - have hbody := uniswapV3PoolFeeGrowthGlobal0X128SourceBody (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hvalue := uniswapV3PoolFeeGrowthGlobal0X128ValueTransport (σ_evm := σ_evm) - (σ_solm := σ_solm) (I := I) hAccounts - have hrd := uniswapV3PoolFeeGrowthGlobal0X128Evm (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel - exact hrd.reEquivExecutionTransport hcode hdispatch hdecode hbody hvalue hAccounts - (returnEquiv_of_encode (uint256ReturnEncoding (solcSlotWord σ_evm I ⟨1⟩))) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/FeeGrowthGlobal1X128.lean b/Benchmarks/UniswapV3Pool/FeeGrowthGlobal1X128.lean deleted file mode 100644 index 02c1b511..00000000 --- a/Benchmarks/UniswapV3Pool/FeeGrowthGlobal1X128.lean +++ /dev/null @@ -1,225 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolFeeGrowthGlobal1X128ReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 8 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1110⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 8 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0x46 0x14 0x13 0x19 - (uniswapV3PoolSelNat 8) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h239 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨239⟩) hpatch h32 hgt32 - have hgt239 : UInt256.gt (armSelNat code ⟨239⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h250 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨250⟩) hpatch h239 hgt239 - have hgt250 : UInt256.gt (armSelNat code ⟨250⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h310 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨310⟩) hpatch h250 hgt250 - have hmiss6 : (uniswapV3PoolSelBytes 6 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h321 := uniswapV3PoolSelectorArmMissToOf (i := 6) (next := ⟨321⟩) - hpatch hsz hmiss6 h310 - have hmiss7 : (uniswapV3PoolSelBytes 7 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h332 := uniswapV3PoolSelectorArmMissToOf (i := 7) (next := ⟨332⟩) - hpatch hsz hmiss7 h321 - have h1110 := uniswapV3PoolSelectorArmHitTo (i := 8) (target := ⟨1110⟩) - hpatch hsz hsel h332 - exact ⟨_, _, h1110⟩ - -theorem uniswapV3PoolFeeGrowthGlobal1X128Decode {v : PoolImmutables} {I : ExecutionEnv} - (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - (feegrowthglobal1X128Transition.params.map Param.name) - (transitionSignature feegrowthglobal1X128Transition).paramTypes I.calldata = - some (∅ : Store) := by - simpa [config, feegrowthglobal1X128Transition, transitionSignature] using - decodeCalldataWithMode_empty_ok (mode := DecodeMode.legacySolc05) (cd := I.calldata) hsz - -theorem uniswapV3PoolDispatch_feeGrowthGlobal1X128 {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 8 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some feegrowthglobal1X128Transition := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, - factoryTransition v, feeTransition v, feegrowthglobal0X128Transition]) - (post := [flashTransition v, increaseobservationcardinalitynextTransition v, - initializeTransition, liquidityTransition, maxliquiditypertickTransition v, mintTransition v, - observationsTransition, observeTransition v, positionsTransition, protocolfeesTransition, - setfeeprotocolTransition v, slot0Transition, snapshotcumulativesinsideTransition v, - swapTransition v, tickbitmapTransition, tickspacingTransition v, ticksTransition, - token0Transition v, token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 8) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 8) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 8) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 8) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 8) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 8) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using hsel - -private theorem uniswapV3PoolFeeGrowthGlobal1X128PatchDisjoint {v : PoolImmutables} - {pc : UInt256} (hlo : 6434 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 6603) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> - omega - -theorem uniswapV3PoolFeeGrowthGlobal1X128EntryWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcGetterEntryWf code ⟨1110⟩ ⟨1118⟩ ⟨6434⟩ := by - dsimp [solcGetterEntryWf] - refine ⟨?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolFeeGrowthGlobal1X128GetterWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcWordSlotGetterWf code ⟨6434⟩ ⟨2⟩ := by - dsimp [solcWordSlotGetterWf] - refine ⟨?_, ?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolFeeGrowthGlobal1X128PatchDisjoint - (by native_decide) (by native_decide))] - native_decide - -theorem uniswapV3PoolFeeGrowthGlobal1X128ReturnWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcReturnWordFromMemWf code ⟨1118⟩ := by - dsimp [solcReturnWordFromMemWf] - refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolFeeGrowthGlobal1X128RoutineJumpDest {v : PoolImmutables} - {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨6434⟩ = true := - uniswapV3PoolJumpDestPatched6434 hpatch - -theorem uniswapV3PoolFeeGrowthGlobal1X128ReturnJumpDest {v : PoolImmutables} - {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨1118⟩ = true := - uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide) - -theorem uniswapV3PoolFeeGrowthGlobal1X128Evm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 8 == I.calldata.extract 0 4) = true) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (solcSlotWord σ I ⟨2⟩)) := by - have hreach := uniswapV3PoolFeeGrowthGlobal1X128ReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - exact RD.solcWordGetterExternal (slot := ⟨2⟩) hreach - (uniswapV3PoolFeeGrowthGlobal1X128EntryWf hpatch) - (uniswapV3PoolFeeGrowthGlobal1X128GetterWf hpatch) - (uniswapV3PoolFeeGrowthGlobal1X128RoutineJumpDest hpatch) - (uniswapV3PoolFeeGrowthGlobal1X128ReturnJumpDest hpatch) - (uniswapV3PoolFeeGrowthGlobal1X128ReturnWf hpatch) - -theorem uniswapV3PoolFeeGrowthGlobal1X128SourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) feegrowthglobal1X128Transition.body - (.returned { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) - (some [Value.int (Int.ofNat (solcSlotWord σ I ⟨2⟩).toNat)])) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [.storage feeGrowthGlobal1X128Ref] ] _ - apply nonpayableReturnExprBodyReturns - · simp [initState, hwv] - · apply evalExpr_storage_scalar_value - (er := { base := "feeGrowthGlobal1X128", steps := [] }) - (t := .int uint256Int) - (loc := loc ⟨2⟩ ⟨0, by decide⟩ ⟨32, by decide⟩ (by decide) (.int uint256Int)) - · simp [feeGrowthGlobal1X128Ref] - · simp [evalStorageRef, feeGrowthGlobal1X128Ref, pure, bind, EvalResult.bind] - · simp [contract, storageDecls, storageTypeAt?, uint256St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc] - · simpa [initState, solcSlotWord, loc, uint256Loc] using - (storageLocLoad_uint256 (initState cA gh bl σ σ₀ g A I) ⟨2⟩) - -theorem uniswapV3PoolFeeGrowthGlobal1X128ValueTransport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - some [Value.int (Int.ofNat (solcSlotWord σ_solm I ⟨2⟩).toNat)] = - some [Value.int (Int.ofNat (solcSlotWord σ_evm I ⟨2⟩).toNat)] := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨2⟩ (⟨0⟩ : UInt256) - dsimp [solcSlotWord] - rw [← hslot] - -theorem uniswapV3PoolFeeGrowthGlobal1X128BodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 8 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_feeGrowthGlobal1X128 (v := v) (cd := I.calldata) hsel - have hdecode := uniswapV3PoolFeeGrowthGlobal1X128Decode (v := v) (I := I) hsz - have hbody := uniswapV3PoolFeeGrowthGlobal1X128SourceBody (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hvalue := uniswapV3PoolFeeGrowthGlobal1X128ValueTransport (σ_evm := σ_evm) - (σ_solm := σ_solm) (I := I) hAccounts - have hrd := uniswapV3PoolFeeGrowthGlobal1X128Evm (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel - exact hrd.reEquivExecutionTransport hcode hdispatch hdecode hbody hvalue hAccounts - (returnEquiv_of_encode (uint256ReturnEncoding (solcSlotWord σ_evm I ⟨2⟩))) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Flash.lean b/Benchmarks/UniswapV3Pool/Flash.lean deleted file mode 100644 index 56c2f2e4..00000000 --- a/Benchmarks/UniswapV3Pool/Flash.lean +++ /dev/null @@ -1,18 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolFlashBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 9 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Functions.lean b/Benchmarks/UniswapV3Pool/Functions.lean deleted file mode 100644 index e476c567..00000000 --- a/Benchmarks/UniswapV3Pool/Functions.lean +++ /dev/null @@ -1,26 +0,0 @@ -import Benchmarks.UniswapV3Pool.Token0 -import Benchmarks.UniswapV3Pool.Swap -import Benchmarks.UniswapV3Pool.Liquidity -import Benchmarks.UniswapV3Pool.ProtocolFees -import Benchmarks.UniswapV3Pool.Observations -import Benchmarks.UniswapV3Pool.IncreaseObservationCardinalityNext -import Benchmarks.UniswapV3Pool.Slot0 -import Benchmarks.UniswapV3Pool.Mint -import Benchmarks.UniswapV3Pool.FeeGrowthGlobal1X128 -import Benchmarks.UniswapV3Pool.Flash -import Benchmarks.UniswapV3Pool.Collect -import Benchmarks.UniswapV3Pool.Positions -import Benchmarks.UniswapV3Pool.TickBitmap -import Benchmarks.UniswapV3Pool.MaxLiquidityPerTick -import Benchmarks.UniswapV3Pool.SetFeeProtocol -import Benchmarks.UniswapV3Pool.CollectProtocol -import Benchmarks.UniswapV3Pool.Observe -import Benchmarks.UniswapV3Pool.BurnBody -import Benchmarks.UniswapV3Pool.SnapshotCumulativesInside -import Benchmarks.UniswapV3Pool.Factory -import Benchmarks.UniswapV3Pool.TickSpacing -import Benchmarks.UniswapV3Pool.Token1 -import Benchmarks.UniswapV3Pool.Fee -import Benchmarks.UniswapV3Pool.FeeGrowthGlobal0X128 -import Benchmarks.UniswapV3Pool.Ticks -import Benchmarks.UniswapV3Pool.Initialize diff --git a/Benchmarks/UniswapV3Pool/ImmutableGetters.lean b/Benchmarks/UniswapV3Pool/ImmutableGetters.lean deleted file mode 100644 index 62e0ec22..00000000 --- a/Benchmarks/UniswapV3Pool/ImmutableGetters.lean +++ /dev/null @@ -1,244 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolFactoryPatchWord8315 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - code.extract 8315 8347 = UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat) := by - let value := UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat) - let post : List (Nat × ByteArray) := - [(8829, value), (10457, value), - (2258, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4853, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (6740, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (7822, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (9150, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (15650, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4551, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (6789, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (7924, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (9284, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (10529, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (15979, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (3311, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6603, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6658, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (10565, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (3072, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (10493, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19402, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19452, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (8174, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19295, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19350, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (11259, UInt256.toByteArray (EVM.Word.ofNat v.original.toNat))] - have hpatch' : patchRuntime uniswapV3PoolBytecode ((8315, value) :: post) = - some code := by - dsimp [post, value] - simpa [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup, - toByteArray_eq_toBytesBE] using hpatch - have hpost : ∀ p ∈ post, 8315 + 32 ≤ p.1 ∨ p.1 + 32 ≤ 8315 := by - intro p hp - dsimp [post] at hp - simp at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl - all_goals omega - have hsize : value.size = 32 := by - dsimp [value] - exact toByteArray_size _ - simpa using - (patchRuntime_extract_patch (template := uniswapV3PoolBytecode) (out := code) - (value := value) (pre := []) (post := post) (offset := 8315) hsize hpost hpatch') - -theorem uniswapV3PoolFactoryConstDecode8314 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨8314⟩ = - some (.Push .PUSH32, some (EVM.Word.ofNat v.factory.toNat, 32)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have hget : code.get? ({ val := 8314 } : UInt256).toNat = - uniswapV3PoolBytecode.get? ({ val := 8314 } : UInt256).toNat := by - change code.get? 8314 = uniswapV3PoolBytecode.get? 8314 - apply get?_eq_of_extract_one - · rw [hsize] - native_decide - · native_decide - · exact patchRuntime_extract_eq (start := 8314) (stop := 8315) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by native_decide) - (fun p hp => by - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl - all_goals omega) hpatch - have hextract : code.extract' ({ val := 8314 } : UInt256).toNat.succ - (({ val := 8314 } : UInt256).toNat.succ + 32) = - UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat) := by - change code.extract' 8315 8347 = - UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat) - unfold ByteArray.extract' - have hguard : (decide (8315 < 2 ^ 64) && decide (8347 < 2 ^ 64)) = true := by - native_decide - rw [if_pos hguard] - exact uniswapV3PoolFactoryPatchWord8315 hpatch - have hgetSome : code.get? ({ val := 8314 } : UInt256).toNat = some 0x7f := by - rw [hget] - native_decide - have hparse : (some (0x7f : UInt8) >>= parseInstr) = some (.Push .PUSH32) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH32, - some (uInt256OfByteArray - (code.extract' ({ val := 8314 } : UInt256).toNat.succ - (({ val := 8314 } : UInt256).toNat.succ + 32)), 32)) = - some (Operation.Push Operation.POp.PUSH32, some (EVM.Word.ofNat v.factory.toNat, 32)) - rw [hextract, uInt256OfByteArray_eq, fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - -theorem uniswapV3PoolFactoryPatchWord {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - code.extract 10457 10489 = UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat) := by - let value := UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat) - let pre : List (Nat × ByteArray) := - [(8315, value), (8829, value)] - let post : List (Nat × ByteArray) := - [(2258, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4853, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (6740, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (7822, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (9150, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (15650, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4551, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (6789, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (7924, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (9284, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (10529, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (15979, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (3311, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6603, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6658, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (10565, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (3072, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (10493, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19402, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19452, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (8174, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19295, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19350, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (11259, UInt256.toByteArray (EVM.Word.ofNat v.original.toNat))] - have hpatch' : patchRuntime uniswapV3PoolBytecode (pre ++ (10457, value) :: post) = - some code := by - dsimp [pre, post, value] - simpa [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup, - toByteArray_eq_toBytesBE] using hpatch - have hpost : ∀ p ∈ post, 10457 + 32 ≤ p.1 ∨ p.1 + 32 ≤ 10457 := by - intro p hp - dsimp [post] at hp - simp at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - have hsize : value.size = 32 := by - dsimp [value] - exact toByteArray_size _ - exact patchRuntime_extract_patch hsize hpost hpatch' - -theorem uniswapV3PoolFactoryConstDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10456⟩ = - some (.Push .PUSH32, some (EVM.Word.ofNat v.factory.toNat, 32)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have hget : code.get? ({ val := 10456 } : UInt256).toNat = - uniswapV3PoolBytecode.get? ({ val := 10456 } : UInt256).toNat := by - change code.get? 10456 = uniswapV3PoolBytecode.get? 10456 - apply get?_eq_of_extract_one - · rw [hsize] - native_decide - · native_decide - · exact patchRuntime_extract_eq (start := 10456) (stop := 10457) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by native_decide) - (fun p hp => by - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl - all_goals omega) hpatch - have hextract : code.extract' ({ val := 10456 } : UInt256).toNat.succ - (({ val := 10456 } : UInt256).toNat.succ + 32) = - UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat) := by - change code.extract' 10457 10489 = - UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat) - unfold ByteArray.extract' - have hguard : (decide (10457 < 2 ^ 64) && decide (10489 < 2 ^ 64)) = true := by - native_decide - rw [if_pos hguard] - exact uniswapV3PoolFactoryPatchWord hpatch - have hgetSome : code.get? ({ val := 10456 } : UInt256).toNat = some 0x7f := by - rw [hget] - native_decide - have hparse : (some (0x7f : UInt8) >>= parseInstr) = some (.Push .PUSH32) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH32, - some (uInt256OfByteArray - (code.extract' ({ val := 10456 } : UInt256).toNat.succ - (({ val := 10456 } : UInt256).toNat.succ + 32)), 32)) = - some (Operation.Push Operation.POp.PUSH32, some (EVM.Word.ofNat v.factory.toNat, 32)) - rw [hextract, uInt256OfByteArray_eq, fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - -theorem uniswapV3PoolFactoryGetterJumpdestDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10455⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨10455⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 10456 ≤ p.1 ∨ p.1 + 32 ≤ 10455 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolFactoryGetterDupDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10489⟩ = some (.DUP2, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨10489⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 10490 ≤ p.1 ∨ p.1 + 32 ≤ 10489 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolFactoryGetterJumpDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10490⟩ = some (.JUMP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨10490⟩) (byte := 0x56) - (op := .JUMP) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 10491 ≤ p.1 ∨ p.1 + 32 ≤ 10490 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNext.lean b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNext.lean deleted file mode 100644 index ec499bc5..00000000 --- a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNext.lean +++ /dev/null @@ -1,1995 +0,0 @@ -import Benchmarks.UniswapV3Pool.IncreaseObservationCardinalityNextGrowLoop - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem uniswapV3PoolPatchPreservesJumpDest5404 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨5404⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched5404 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨5404⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest5404 - -private theorem uniswapV3PoolPatchPreservesJumpDest5472 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨5472⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest16053 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16053⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest5521 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨5521⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest5630 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨5630⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextPatchPreservesJumpDest857 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨857⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest13186 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨13186⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest16115 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16115⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched5472 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨5472⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest5472 - -theorem uniswapV3PoolJumpDestPatched16053 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16053⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest16053 - -theorem uniswapV3PoolJumpDestPatched5521 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨5521⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest5521 - -theorem uniswapV3PoolJumpDestPatched5630 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨5630⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest5630 - -theorem uniswapV3PoolIncreaseObservationCardinalityNextJumpDestPatched857 - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨857⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolIncreaseObservationCardinalityNextPatchPreservesJumpDest857 - -theorem uniswapV3PoolJumpDestPatched13186 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨13186⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest13186 - -theorem uniswapV3PoolJumpDestPatched16115 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16115⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest16115 - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextPatchDisjoint - {v : PoolImmutables} {pc : UInt256} (hlo : 5404 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 6603) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl <;> - omega - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchDisjoint - {v : PoolImmutables} {pc : UInt256} (hlo : 16053 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 19295) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl <;> - omega - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextMidPatchDisjoint - {v : PoolImmutables} {pc : UInt256} (hlo : 11291 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 15650) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl <;> - omega - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextLockEnterOk - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5404⟩ R mem aw rdata (cA, σ) k C) - (hperm : ee.perm = true) - (hunlocked : increaseObservationCardinalityNextUnlockedByte σ ee ≠ ⟨0⟩) - (hov : R.length + 4 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨5486⟩ R mem aw rdata - (cA, sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ ee)) k' C' := by - have hdecode {pc : UInt256} (hlo : 5404 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 6603) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 6603 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextPatchDisjoint hlo hhi)] - have hd5404 : decode code ⟨5404⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5405 : decode code ⟨5405⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5407 : decode code ⟨5407⟩ = some (.SLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5408 : decode code ⟨5408⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5410 : decode code ⟨5410⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5412 : decode code ⟨5412⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5413 : decode code ⟨5413⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5414 : decode code ⟨5414⟩ = some (.DIV, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5415 : decode code ⟨5415⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5417 : decode code ⟨5417⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5418 : decode code ⟨5418⟩ = some (.Push .PUSH2, some (⟨5472⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5421 : decode code ⟨5421⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5472 : decode code ⟨5472⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5473 : decode code ⟨5473⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5475 : decode code ⟨5475⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5476 : decode code ⟨5476⟩ = some (.SLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5477 : decode code ⟨5477⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5479 : decode code ⟨5479⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5481 : decode code ⟨5481⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5482 : decode code ⟨5482⟩ = some (.NOT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5483 : decode code ⟨5483⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5484 : decode code ⟨5484⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5485 : decode code ⟨5485⟩ = some (.SSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd5405 : RD code ee g s0 ⟨5405⟩ R mem aw rdata (cA, σ) (k + 1) (C + 1) := by - simpa using h.jumpdest hd5404 (by evm_ov) - have rd5407 : RD code ee g s0 ⟨5407⟩ (⟨0⟩ :: R) mem aw rdata (cA, σ) - (k + 1 + 1) (C + 1 + 3) := by - simpa using rd5405.push1 ⟨0⟩ hd5405 (by evm_ov) - obtain ⟨_, _, rd5408₀⟩ := rd5407.sload hd5407 (by evm_ov) - have rd5408 := by - simpa [solcSlotWord] using rd5408₀ - have rd5410 := by - simpa using rd5408.push1 ⟨1⟩ hd5408 (by evm_ov) - have rd5412 := by - simpa using rd5410.push1 ⟨240⟩ hd5410 (by evm_ov) - have rd5413 := by - simpa [increaseObservationCardinalityNextUnlockedShift] using - rd5412.shl hd5412 (by evm_ov) - have rd5414 := by - simpa using rd5413.swap1 hd5413 (by evm_ov) - have rd5415 := by - simpa using rd5414.div hd5414 (by evm_ov) - have rd5417 := by - simpa [increaseObservationCardinalityNextUint8Mask] using - rd5415.push1 ⟨255⟩ hd5415 (by evm_ov) - have rd5418 := by - simpa [increaseObservationCardinalityNextUnlockedByte] using rd5417.and hd5417 - (by evm_ov) - have rd5421 := by - simpa using rd5418.push2 ⟨5472⟩ hd5418 (by evm_ov) - have rd5472 := rd5421.jumpiT hd5421 hunlocked - (uniswapV3PoolJumpDestPatched5472 hpatch) (by evm_ov) - have rd5473 := by - simpa using rd5472.jumpdest hd5472 (by evm_ov) - have rd5475 := by - simpa using rd5473.push1 ⟨0⟩ hd5473 (by evm_ov) - have rd5476 := by - simpa using rd5475.dup1 hd5475 (by evm_ov) - obtain ⟨_, _, rd5477₀⟩ := rd5476.sload hd5476 (by evm_ov) - have rd5477 := by - simpa [solcSlotWord] using rd5477₀ - have rd5479 := by - simpa [increaseObservationCardinalityNextUint8Mask] using - rd5477.push1 ⟨255⟩ hd5477 (by evm_ov) - have rd5481 := by - simpa using rd5479.push1 ⟨240⟩ hd5479 (by evm_ov) - have rd5482 := by - simpa using rd5481.shl hd5481 (by evm_ov) - have rd5483 := by - simpa [increaseObservationCardinalityNextUnlockedClearMask] using rd5482.not - hd5482 (by evm_ov) - have rd5484 := by - simpa [increaseObservationCardinalityNextLockedSlotWord] using rd5483.and hd5483 - (by evm_ov) - have rd5485 := by - simpa using rd5484.swap1 hd5484 (by evm_ov) - exact rd5485.sstore hperm hd5485 (by - omega) - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextLockedRevertTailWf - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcErrorStringRevertTailWf code ⟨5422⟩ ⟨3⟩ ⟨5001035⟩ ⟨232⟩ .PUSH3 3 := by - have hdecode {pc : UInt256} (hlo : 5404 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 6603) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 6603 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextPatchDisjoint hlo hhi)] - dsimp [solcErrorStringRevertTailWf] - repeat' constructor - all_goals - rw [hdecode (by native_decide) (by native_decide)] - native_decide - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextLockEnterLockedRevert - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5404⟩ R solcFreePtrMem (UInt256.ofNat 3) rdata - (cA, σ) k C) - (hlocked : increaseObservationCardinalityNextUnlockedByte σ ee = ⟨0⟩) - (hov : R.length + 6 ≤ 1024) : - RDrev code g s0 := by - have hdecode {pc : UInt256} (hlo : 5404 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 6603) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 6603 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextPatchDisjoint hlo hhi)] - have hd5404 : decode code ⟨5404⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5405 : decode code ⟨5405⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5407 : decode code ⟨5407⟩ = some (.SLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5408 : decode code ⟨5408⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5410 : decode code ⟨5410⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5412 : decode code ⟨5412⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5413 : decode code ⟨5413⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5414 : decode code ⟨5414⟩ = some (.DIV, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5415 : decode code ⟨5415⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5417 : decode code ⟨5417⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5418 : decode code ⟨5418⟩ = some (.Push .PUSH2, some (⟨5472⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5421 : decode code ⟨5421⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd5405 : RD code ee g s0 ⟨5405⟩ R solcFreePtrMem (UInt256.ofNat 3) rdata - (cA, σ) (k + 1) (C + 1) := by - simpa using h.jumpdest hd5404 (by evm_ov) - have rd5407 : RD code ee g s0 ⟨5407⟩ (⟨0⟩ :: R) solcFreePtrMem - (UInt256.ofNat 3) rdata (cA, σ) (k + 1 + 1) (C + 1 + 3) := by - simpa using rd5405.push1 ⟨0⟩ hd5405 (by evm_ov) - obtain ⟨_, _, rd5408₀⟩ := rd5407.sload hd5407 (by evm_ov) - have rd5408 := by - simpa [solcSlotWord] using rd5408₀ - have rd5410 := by - simpa using rd5408.push1 ⟨1⟩ hd5408 (by evm_ov) - have rd5412 := by - simpa using rd5410.push1 ⟨240⟩ hd5410 (by evm_ov) - have rd5413 := by - simpa [increaseObservationCardinalityNextUnlockedShift] using - rd5412.shl hd5412 (by evm_ov) - have rd5414 := by - simpa using rd5413.swap1 hd5413 (by evm_ov) - have rd5415 := by - simpa using rd5414.div hd5414 (by evm_ov) - have rd5417 := by - simpa [increaseObservationCardinalityNextUint8Mask] using - rd5415.push1 ⟨255⟩ hd5415 (by evm_ov) - have rd5418 := by - simpa [increaseObservationCardinalityNextUnlockedByte] using rd5417.and hd5417 - (by evm_ov) - have rd5421 := by - simpa using rd5418.push2 ⟨5472⟩ hd5418 (by evm_ov) - have rd5422 := rd5421.jumpiNT hd5421 hlocked (by evm_ov) - exact RD.solcErrorStringRevertTail - (pc := ⟨5422⟩) (len := ⟨3⟩) (rawWord := ⟨5001035⟩) (shift := ⟨232⟩) - (word := UInt256.shiftLeft ⟨5001035⟩ ⟨232⟩) (op := .PUSH3) (width := 3) - rd5422 - (uniswapV3PoolIncreaseObservationCardinalityNextLockedRevertTailWf hpatch) - (by native_decide) - rfl - solcFreePtrMem_size - solcFreePtrMem_read64 - (by omega) - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextOldZeroRevertTailWf - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcErrorStringRevertTailWf code ⟨16067⟩ ⟨1⟩ ⟨73⟩ ⟨248⟩ .PUSH1 1 := by - have hdecode {pc : UInt256} (hlo : 16053 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 19295 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchDisjoint hlo hhi)] - dsimp [solcErrorStringRevertTailWf] - repeat' constructor - all_goals - rw [hdecode (by native_decide) (by native_decide)] - native_decide - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextAfterNoDelegateOldZeroRevert - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5493⟩ - (increaseObservationCardinalityNextArgWord ee :: ⟨857⟩ :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hzero : increaseObservationCardinalityNextOldWord σ ee = ⟨0⟩) - (hov : R.length + 14 ≤ 1024) : - RDrev code g s0 := by - have hdecodeBody {pc : UInt256} (hlo : 5404 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 6603) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 6603 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextPatchDisjoint hlo hhi)] - have hdecodeGrow {pc : UInt256} (hlo : 16053 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 19295 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchDisjoint hlo hhi)] - have hd5493 : decode code ⟨5493⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5494 : decode code ⟨5494⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5496 : decode code ⟨5496⟩ = some (.DUP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5497 : decode code ⟨5497⟩ = some (.SLOAD, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5498 : decode code ⟨5498⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5500 : decode code ⟨5500⟩ = some (.Push .PUSH1, some (⟨216⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5502 : decode code ⟨5502⟩ = some (.SHL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5503 : decode code ⟨5503⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5504 : decode code ⟨5504⟩ = some (.DIV, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5505 : decode code ⟨5505⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5508 : decode code ⟨5508⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5509 : decode code ⟨5509⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5510 : decode code ⟨5510⟩ = some (.Push .PUSH2, some (⟨5521⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5513 : decode code ⟨5513⟩ = some (.Push .PUSH1, some (⟨8⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5515 : decode code ⟨5515⟩ = some (.DUP4, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5516 : decode code ⟨5516⟩ = some (.DUP6, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5517 : decode code ⟨5517⟩ = some (.Push .PUSH2, some (⟨16053⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5520 : decode code ⟨5520⟩ = some (.JUMP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd16053 : decode code ⟨16053⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)] - native_decide - have hd16054 : decode code ⟨16054⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)] - native_decide - have hd16056 : decode code ⟨16056⟩ = some (.DUP1, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)] - native_decide - have hd16057 : decode code ⟨16057⟩ = some (.DUP4, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)] - native_decide - have hd16058 : decode code ⟨16058⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)] - native_decide - have hd16061 : decode code ⟨16061⟩ = some (.AND, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)] - native_decide - have hd16062 : decode code ⟨16062⟩ = some (.GT, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)] - native_decide - have hd16063 : decode code ⟨16063⟩ = some (.Push .PUSH2, some (⟨16115⟩, 2)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)] - native_decide - have hd16066 : decode code ⟨16066⟩ = some (.JUMPI, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)] - native_decide - have hshift : - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨216⟩ = slot0ShiftBytes 27 := by - native_decide - have hmask : increaseObservationCardinalityNextUint16Mask = slot0Uint16Mask := by - native_decide - have holdCleanL : - UInt256.land slot0Uint16Mask (increaseObservationCardinalityNextOldWord σ ee) = - increaseObservationCardinalityNextOldWord σ ee := by - exact slot0Uint16Mask_clean_left - (slot0Uint16Mask_bound (UInt256.div (slot0SlotWord σ ee) (slot0ShiftBytes 27))) - have holdCleanR : - UInt256.land (increaseObservationCardinalityNextOldWord σ ee) slot0Uint16Mask = - increaseObservationCardinalityNextOldWord σ ee := by - rw [u256_land_comm, holdCleanL] - have holdInner : - UInt256.land slot0Uint16Mask - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27)) = - increaseObservationCardinalityNextOldWord σ ee := by - rw [increaseObservationCardinalityNextOldWord, slot0ObservationCardinalityNextWord, - slot0SlotWord, u256_land_comm] - have hmaskedOldZero : - UInt256.land slot0Uint16Mask - (UInt256.land slot0Uint16Mask - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27))) = - ⟨0⟩ := by - rw [holdInner, holdCleanL, hzero] - have hgtMaskedOldZero : - UInt256.gt - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27)))) - ⟨0⟩ = - ⟨0⟩ := by - have hraw : - UInt256.land (⟨65535⟩ : UInt256) - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27))) = - ⟨0⟩ := by - simpa [slot0Uint16Mask] using hmaskedOldZero - rw [hraw] - native_decide - have rd5494 := by - simpa using h.jumpdest hd5493 (by evm_ov) - have rd5496 := by - simpa using rd5494.push1 ⟨0⟩ hd5494 (by evm_ov) - have rd5497 := by - simpa using rd5496.dup1 hd5496 (by evm_ov) - obtain ⟨_, _, rd5498₀⟩ := rd5497.sload hd5497 (by evm_ov) - have rd5498 := by - simpa [solcSlotWord] using rd5498₀ - have rd5500 := by - simpa using rd5498.push1 ⟨1⟩ hd5498 (by evm_ov) - have rd5502 := by - simpa using rd5500.push1 ⟨216⟩ hd5500 (by evm_ov) - have rd5503 := by - simpa using rd5502.shl hd5502 (by evm_ov) - have rd5504 := by - simpa using rd5503.swap1 hd5503 (by evm_ov) - have rd5505 := by - simpa [hshift] using rd5504.div hd5504 (by evm_ov) - have rd5508 := by - simpa [increaseObservationCardinalityNextUint16Mask, hmask, - increaseObservationCardinalityNextOldWord, slot0ObservationCardinalityNextWord, - slot0SlotWord, solcSlotWord] using rd5505.push2 ⟨65535⟩ hd5505 (by evm_ov) - have rd5509 := by - simpa [increaseObservationCardinalityNextOldWord, slot0ObservationCardinalityNextWord, - slot0SlotWord, solcSlotWord, hmask] using rd5508.and hd5508 (by - simp only [List.length_cons] - omega) - have rd5510 := by - simpa using rd5509.swap1 hd5509 (by evm_ov) - have rd5513 := by - simpa using rd5510.push2 ⟨5521⟩ hd5510 (by - simp only [List.length_cons] - omega) - have rd5515 := by - simpa using rd5513.push1 ⟨8⟩ hd5513 (by - simp only [List.length_cons] - omega) - have rd5516 := by - simpa using rd5515.dup4 hd5515 (by - simp only [List.length_cons] - omega) - have rd5517 := by - simpa using rd5516.dup6 hd5516 (by - simp only [List.length_cons] - omega) - have rd5520 := by - simpa using rd5517.push2 ⟨16053⟩ hd5517 (by - simp only [List.length_cons] - omega) - have rd16053 := rd5520.jump hd5520 (uniswapV3PoolJumpDestPatched16053 hpatch) - (by simp only [List.length_cons]; omega) - have rd16054 := by - simpa using rd16053.jumpdest hd16053 (by - simp only [List.length_cons] - omega) - have rd16056 := by - simpa using rd16054.push1 ⟨0⟩ hd16054 (by - simp only [List.length_cons] - omega) - have rd16057 := by - simpa using rd16056.dup1 hd16056 (by - simp only [List.length_cons] - omega) - have rd16058 := by - simpa using rd16057.dup4 hd16057 (by - simp only [List.length_cons] - omega) - have rd16061 := by - simpa [hmask, holdCleanL, holdCleanR] using rd16058.push2 ⟨65535⟩ hd16058 (by - simp only [List.length_cons] - omega) - have rd16062 := by - simpa [hmask, holdCleanL, holdCleanR] using rd16061.and hd16061 (by - simp only [List.length_cons] - omega) - have rd16063 := by - simpa [hmask, solcSlotWord, hmaskedOldZero] using rd16062.gt hd16062 (by - simp only [List.length_cons] - omega) - have rd16066 := by - simpa using rd16063.push2 ⟨16115⟩ hd16063 (by - simp only [List.length_cons] - omega) - have rd16067 := rd16066.jumpiNT hd16066 (by - simpa [solcSlotWord] using hgtMaskedOldZero) - (by simp only [List.length_cons]; omega) - exact RD.solcErrorStringRevertTail - (pc := ⟨16067⟩) (len := ⟨1⟩) (rawWord := ⟨73⟩) (shift := ⟨248⟩) - (word := UInt256.shiftLeft ⟨73⟩ ⟨248⟩) (op := .PUSH1) (width := 1) - rd16067 - (uniswapV3PoolIncreaseObservationCardinalityNextOldZeroRevertTailWf hpatch) - (by native_decide) - rfl - solcFreePtrMem_size - solcFreePtrMem_read64 - (by simp only [List.length_cons]; omega) - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextAfterNoDelegateNoGrowReturn - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5493⟩ - (increaseObservationCardinalityNextArgWord ee :: ⟨857⟩ :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (holdNonzero : increaseObservationCardinalityNextOldWord σ ee ≠ ⟨0⟩) - (hnewLe : UInt256.gt (increaseObservationCardinalityNextArgWord ee) - (increaseObservationCardinalityNextOldWord σ ee) = ⟨0⟩) - (hov : R.length + 14 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨5521⟩ - (increaseObservationCardinalityNextOldWord σ ee :: ⟨0⟩ :: - increaseObservationCardinalityNextOldWord σ ee :: - increaseObservationCardinalityNextArgWord ee :: ⟨857⟩ :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k' C' := by - have hdecodeBody {pc : UInt256} (hlo : 5404 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 6603) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 6603 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextPatchDisjoint hlo hhi)] - have hdecodeGrow {pc : UInt256} (hlo : 16053 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 19295 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchDisjoint hlo hhi)] - have hdecodeMid {pc : UInt256} (hlo : 11291 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextMidPatchDisjoint hlo hhi)] - have hd5493 : decode code ⟨5493⟩ = some (.JUMPDEST, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5494 : decode code ⟨5494⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5496 : decode code ⟨5496⟩ = some (.DUP1, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5497 : decode code ⟨5497⟩ = some (.SLOAD, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5498 : decode code ⟨5498⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5500 : decode code ⟨5500⟩ = some (.Push .PUSH1, some (⟨216⟩, 1)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5502 : decode code ⟨5502⟩ = some (.SHL, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5503 : decode code ⟨5503⟩ = some (.SWAP1, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5504 : decode code ⟨5504⟩ = some (.DIV, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5505 : decode code ⟨5505⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5508 : decode code ⟨5508⟩ = some (.AND, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5509 : decode code ⟨5509⟩ = some (.SWAP1, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5510 : decode code ⟨5510⟩ = some (.Push .PUSH2, some (⟨5521⟩, 2)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5513 : decode code ⟨5513⟩ = some (.Push .PUSH1, some (⟨8⟩, 1)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5515 : decode code ⟨5515⟩ = some (.DUP4, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5516 : decode code ⟨5516⟩ = some (.DUP6, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5517 : decode code ⟨5517⟩ = some (.Push .PUSH2, some (⟨16053⟩, 2)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5520 : decode code ⟨5520⟩ = some (.JUMP, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd16053 : decode code ⟨16053⟩ = some (.JUMPDEST, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16054 : decode code ⟨16054⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16056 : decode code ⟨16056⟩ = some (.DUP1, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16057 : decode code ⟨16057⟩ = some (.DUP4, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16058 : decode code ⟨16058⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16061 : decode code ⟨16061⟩ = some (.AND, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16062 : decode code ⟨16062⟩ = some (.GT, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16063 : decode code ⟨16063⟩ = some (.Push .PUSH2, some (⟨16115⟩, 2)) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16066 : decode code ⟨16066⟩ = some (.JUMPI, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16115 : decode code ⟨16115⟩ = some (.JUMPDEST, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16116 : decode code ⟨16116⟩ = some (.DUP3, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16117 : decode code ⟨16117⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16120 : decode code ⟨16120⟩ = some (.AND, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16121 : decode code ⟨16121⟩ = some (.DUP3, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16122 : decode code ⟨16122⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16125 : decode code ⟨16125⟩ = some (.AND, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16126 : decode code ⟨16126⟩ = some (.GT, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16127 : decode code ⟨16127⟩ = some (.Push .PUSH2, some (⟨16137⟩, 2)) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16130 : decode code ⟨16130⟩ = some (.JUMPI, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16131 : decode code ⟨16131⟩ = some (.POP, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16132 : decode code ⟨16132⟩ = some (.DUP2, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16133 : decode code ⟨16133⟩ = some (.Push .PUSH2, some (⟨13186⟩, 2)) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16136 : decode code ⟨16136⟩ = some (.JUMP, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd13186 : decode code ⟨13186⟩ = some (.JUMPDEST, .none) := by rw [hdecodeMid (by native_decide) (by native_decide)]; native_decide - have hd13187 : decode code ⟨13187⟩ = some (.SWAP4, .none) := by rw [hdecodeMid (by native_decide) (by native_decide)]; native_decide - have hd13188 : decode code ⟨13188⟩ = some (.SWAP3, .none) := by rw [hdecodeMid (by native_decide) (by native_decide)]; native_decide - have hd13189 : decode code ⟨13189⟩ = some (.POP, .none) := by rw [hdecodeMid (by native_decide) (by native_decide)]; native_decide - have hd13190 : decode code ⟨13190⟩ = some (.POP, .none) := by rw [hdecodeMid (by native_decide) (by native_decide)]; native_decide - have hd13191 : decode code ⟨13191⟩ = some (.POP, .none) := by rw [hdecodeMid (by native_decide) (by native_decide)]; native_decide - have hd13192 : decode code ⟨13192⟩ = some (.JUMP, .none) := by rw [hdecodeMid (by native_decide) (by native_decide)]; native_decide - have hshift : - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨216⟩ = slot0ShiftBytes 27 := by - native_decide - have hmask : increaseObservationCardinalityNextUint16Mask = slot0Uint16Mask := by - native_decide - have holdCleanL : - UInt256.land slot0Uint16Mask (increaseObservationCardinalityNextOldWord σ ee) = - increaseObservationCardinalityNextOldWord σ ee := by - exact slot0Uint16Mask_clean_left - (slot0Uint16Mask_bound (UInt256.div (slot0SlotWord σ ee) (slot0ShiftBytes 27))) - have holdCleanR : - UInt256.land (increaseObservationCardinalityNextOldWord σ ee) slot0Uint16Mask = - increaseObservationCardinalityNextOldWord σ ee := by - rw [u256_land_comm, holdCleanL] - have hnewCanon : - (increaseObservationCardinalityNextArgWord ee).toNat < EVM.twoPow 16 := by - simpa [increaseObservationCardinalityNextArgWord, hmask] using - slot0Uint16Mask_bound (calldataWord ee.calldata 4) - have hnewCleanL : - UInt256.land slot0Uint16Mask (increaseObservationCardinalityNextArgWord ee) = - increaseObservationCardinalityNextArgWord ee := by - exact slot0Uint16Mask_clean_left hnewCanon - have hnewCleanR : - UInt256.land (increaseObservationCardinalityNextArgWord ee) slot0Uint16Mask = - increaseObservationCardinalityNextArgWord ee := by - rw [u256_land_comm, hnewCleanL] - have holdInner : - UInt256.land slot0Uint16Mask - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27)) = - increaseObservationCardinalityNextOldWord σ ee := by - rw [increaseObservationCardinalityNextOldWord, slot0ObservationCardinalityNextWord, - slot0SlotWord, u256_land_comm] - have hmaskedOld : - UInt256.land slot0Uint16Mask - (UInt256.land slot0Uint16Mask - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27))) = - increaseObservationCardinalityNextOldWord σ ee := by - rw [holdInner, holdCleanL] - have holdRaw : - UInt256.land (⟨65535⟩ : UInt256) - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27)) = - increaseObservationCardinalityNextOldWord σ ee := by - simpa [slot0Uint16Mask] using holdInner - have hgtMaskedOldZero : - UInt256.gt - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27)))) - ⟨0⟩ ≠ - ⟨0⟩ := by - have hraw : - UInt256.land (⟨65535⟩ : UInt256) - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27))) = - increaseObservationCardinalityNextOldWord σ ee := by - simpa [slot0Uint16Mask] using hmaskedOld - have holdPos : 0 < (increaseObservationCardinalityNextOldWord σ ee).toNat := by - exact Nat.pos_of_ne_zero (by - intro hz - apply holdNonzero - apply u256_inj - simpa using hz) - have hgtOne : - UInt256.gt (increaseObservationCardinalityNextOldWord σ ee) ⟨0⟩ = ⟨1⟩ := by - exact ugt_one (by simpa using holdPos) - rw [hraw, hgtOne] - native_decide - have hnewLeRaw : - UInt256.gt - (UInt256.land (⟨65535⟩ : UInt256) (increaseObservationCardinalityNextArgWord ee)) - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27)))) = - ⟨0⟩ := by - have hrawOld : - UInt256.land (⟨65535⟩ : UInt256) - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27))) = - increaseObservationCardinalityNextOldWord σ ee := by - simpa [slot0Uint16Mask] using hmaskedOld - have hrawNew : - UInt256.land (⟨65535⟩ : UInt256) (increaseObservationCardinalityNextArgWord ee) = - increaseObservationCardinalityNextArgWord ee := by - simpa [slot0Uint16Mask] using hnewCleanL - rw [hrawNew, hrawOld] - exact hnewLe - have rd5494 := by - simpa using h.jumpdest hd5493 (by evm_ov) - have rd5496 := by - simpa using rd5494.push1 ⟨0⟩ hd5494 (by evm_ov) - have rd5497 := by - simpa using rd5496.dup1 hd5496 (by evm_ov) - obtain ⟨_, _, rd5498₀⟩ := rd5497.sload hd5497 (by evm_ov) - have rd5498 := by - simpa [solcSlotWord] using rd5498₀ - have rd5500 := by - simpa using rd5498.push1 ⟨1⟩ hd5498 (by evm_ov) - have rd5502 := by - simpa using rd5500.push1 ⟨216⟩ hd5500 (by evm_ov) - have rd5503 := by - simpa using rd5502.shl hd5502 (by evm_ov) - have rd5504 := by - simpa using rd5503.swap1 hd5503 (by evm_ov) - have rd5505 := by - simpa [hshift] using rd5504.div hd5504 (by evm_ov) - have rd5508 := by - simpa [increaseObservationCardinalityNextUint16Mask, hmask, - increaseObservationCardinalityNextOldWord, slot0ObservationCardinalityNextWord, - slot0SlotWord, solcSlotWord] using rd5505.push2 ⟨65535⟩ hd5505 (by evm_ov) - have rd5509 := by - simpa [increaseObservationCardinalityNextOldWord, slot0ObservationCardinalityNextWord, - slot0SlotWord, solcSlotWord, hmask] using rd5508.and hd5508 (by - simp only [List.length_cons] - omega) - have rd5510 := by - simpa using rd5509.swap1 hd5509 (by evm_ov) - have rd5513 := by - simpa using rd5510.push2 ⟨5521⟩ hd5510 (by - simp only [List.length_cons] - omega) - have rd5515 := by - simpa using rd5513.push1 ⟨8⟩ hd5513 (by - simp only [List.length_cons] - omega) - have rd5516 := by - simpa using rd5515.dup4 hd5515 (by - simp only [List.length_cons] - omega) - have rd5517 := by - simpa using rd5516.dup6 hd5516 (by - simp only [List.length_cons] - omega) - have rd5520 := by - simpa using rd5517.push2 ⟨16053⟩ hd5517 (by - simp only [List.length_cons] - omega) - have rd16053 := rd5520.jump hd5520 (uniswapV3PoolJumpDestPatched16053 hpatch) - (by simp only [List.length_cons]; omega) - have rd16054 := by - simpa using rd16053.jumpdest hd16053 (by - simp only [List.length_cons] - omega) - have rd16056 := by - simpa using rd16054.push1 ⟨0⟩ hd16054 (by - simp only [List.length_cons] - omega) - have rd16057 := by - simpa using rd16056.dup1 hd16056 (by - simp only [List.length_cons] - omega) - have rd16058 := by - simpa using rd16057.dup4 hd16057 (by - simp only [List.length_cons] - omega) - have rd16061 := by - simpa [hmask, holdCleanL, holdCleanR] using rd16058.push2 ⟨65535⟩ hd16058 (by - simp only [List.length_cons] - omega) - have rd16062 := by - simpa [hmask, holdCleanL, holdCleanR] using rd16061.and hd16061 (by - simp only [List.length_cons] - omega) - have rd16063 := by - simpa [hmask, solcSlotWord, hmaskedOld] using rd16062.gt hd16062 (by - simp only [List.length_cons] - omega) - have rd16066 := by - simpa using rd16063.push2 ⟨16115⟩ hd16063 (by - simp only [List.length_cons] - omega) - have rd16115 := rd16066.jumpiT hd16066 (by - simpa [solcSlotWord] using hgtMaskedOldZero) - (uniswapV3PoolJumpDestPatched16115 hpatch) - (by simp only [List.length_cons]; omega) - have rd16116 := by - simpa using rd16115.jumpdest hd16115 (by - simp only [List.length_cons] - omega) - have rd16117 := by - simpa using rd16116.dup3 hd16116 (by - simp only [List.length_cons] - omega) - have rd16120 := by - simpa using rd16117.push2 ⟨65535⟩ hd16117 (by - simp only [List.length_cons] - omega) - have rd16121 := by - simpa [hmask, holdCleanL, holdCleanR] using rd16120.and hd16120 (by - simp only [List.length_cons] - omega) - have rd16122 := by - simpa using rd16121.dup3 hd16121 (by - simp only [List.length_cons] - omega) - have rd16125 := by - simpa using rd16122.push2 ⟨65535⟩ hd16122 (by - simp only [List.length_cons] - omega) - have rd16126 := by - simpa [hmask, hnewCleanL, hnewCleanR] using rd16125.and hd16125 (by - simp only [List.length_cons] - omega) - have rd16127 := by - simpa using rd16126.gt hd16126 (by - simp only [List.length_cons] - omega) - have rd16130 := by - simpa using rd16127.push2 ⟨16137⟩ hd16127 (by - simp only [List.length_cons] - omega) - have rd16131 := rd16130.jumpiNT hd16130 hnewLeRaw (by - simp only [List.length_cons] - omega) - have rd16132 := by - simpa using rd16131.pop hd16131 (by - simp only [List.length_cons] - omega) - have rd16133 := by - simpa using rd16132.dup2 hd16132 (by - simp only [List.length_cons] - omega) - have rd16136 := by - simpa using rd16133.push2 ⟨13186⟩ hd16133 (by - simp only [List.length_cons] - omega) - have rd13186 := rd16136.jump hd16136 (uniswapV3PoolJumpDestPatched13186 hpatch) - (by simp only [List.length_cons]; omega) - have rd13187 := by - simpa using rd13186.jumpdest hd13186 (by - simp only [List.length_cons] - omega) - have rd13188 := by - simpa using rd13187.swap4 hd13187 (by - simp only [List.length_cons] - omega) - have rd13189 := by - simpa using rd13188.swap3 hd13188 (by - simp only [List.length_cons] - omega) - have rd13190 := by - simpa using rd13189.pop hd13189 (by - simp only [List.length_cons] - omega) - have rd13191 := by - simpa using rd13190.pop hd13190 (by - simp only [List.length_cons] - omega) - have rd13192 := by - simpa using rd13191.pop hd13191 (by - simp only [List.length_cons] - omega) - have rd5521 := rd13192.jump hd13192 (uniswapV3PoolJumpDestPatched5521 hpatch) - (by simp only [List.length_cons]; omega) - exact ⟨_, _, by - simpa [solcSlotWord, holdRaw] using rd5521⟩ - -set_option maxHeartbeats 1000000 in -private theorem uniswapV3PoolIncreaseObservationCardinalityNextNoGrowTailReturn - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5521⟩ - (increaseObservationCardinalityNextOldWord σ ee :: ⟨0⟩ :: - increaseObservationCardinalityNextOldWord σ ee :: - increaseObservationCardinalityNextArgWord ee :: ⟨857⟩ :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hperm : ee.perm = true) - (hov : R.length + 12 ≤ 1024) : - RDret code g s0 - (cA, sstoreAccountMap ee.codeOwner - (sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord σ ee)) - ⟨0⟩ - (increaseObservationCardinalityNextEvmUnlockedTrueSlotWord - (sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord σ ee)) ee)) - ByteArray.empty := by - have hdecodeBody {pc : UInt256} (hlo : 5404 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 6603) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 6603 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextPatchDisjoint hlo hhi)] - have hd5521 : decode code ⟨5521⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5522 : decode code ⟨5522⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5524 : decode code ⟨5524⟩ = some (.DUP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5525 : decode code ⟨5525⟩ = some (.SLOAD, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5526 : decode code ⟨5526⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5529 : decode code ⟨5529⟩ = some (.DUP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5530 : decode code ⟨5530⟩ = some (.DUP5, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5531 : decode code ⟨5531⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5532 : decode code ⟨5532⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5534 : decode code ⟨5534⟩ = some (.Push .PUSH1, some (⟨216⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5536 : decode code ⟨5536⟩ = some (.SHL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5537 : decode code ⟨5537⟩ = some (.DUP2, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5538 : decode code ⟨5538⟩ = some (.MUL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5539 : decode code ⟨5539⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5542 : decode code ⟨5542⟩ = some (.Push .PUSH1, some (⟨216⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5544 : decode code ⟨5544⟩ = some (.SHL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5545 : decode code ⟨5545⟩ = some (.NOT, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5546 : decode code ⟨5546⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5547 : decode code ⟨5547⟩ = some (.SWAP4, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5548 : decode code ⟨5548⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5549 : decode code ⟨5549⟩ = some (.SWAP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5550 : decode code ⟨5550⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5551 : decode code ⟨5551⟩ = some (.SWAP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5552 : decode code ⟨5552⟩ = some (.OR, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5553 : decode code ⟨5553⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5554 : decode code ⟨5554⟩ = some (.SWAP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5555 : decode code ⟨5555⟩ = some (.SSTORE, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5556 : decode code ⟨5556⟩ = some (.SWAP2, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5557 : decode code ⟨5557⟩ = some (.SWAP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5558 : decode code ⟨5558⟩ = some (.POP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5559 : decode code ⟨5559⟩ = some (.DUP4, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5560 : decode code ⟨5560⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5561 : decode code ⟨5561⟩ = some (.EQ, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5562 : decode code ⟨5562⟩ = some (.Push .PUSH2, some (⟨5630⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5565 : decode code ⟨5565⟩ = some (.JUMPI, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5630 : decode code ⟨5630⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5631 : decode code ⟨5631⟩ = some (.POP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5632 : decode code ⟨5632⟩ = some (.POP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5633 : decode code ⟨5633⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5635 : decode code ⟨5635⟩ = some (.DUP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5636 : decode code ⟨5636⟩ = some (.SLOAD, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5637 : decode code ⟨5637⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5639 : decode code ⟨5639⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5641 : decode code ⟨5641⟩ = some (.SHL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5642 : decode code ⟨5642⟩ = some (.NOT, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5643 : decode code ⟨5643⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5644 : decode code ⟨5644⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5646 : decode code ⟨5646⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5648 : decode code ⟨5648⟩ = some (.SHL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5649 : decode code ⟨5649⟩ = some (.OR, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5650 : decode code ⟨5650⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5651 : decode code ⟨5651⟩ = some (.SSTORE, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5652 : decode code ⟨5652⟩ = some (.POP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5653 : decode code ⟨5653⟩ = some (.JUMP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd857 : decode code ⟨857⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd858 : decode code ⟨858⟩ = some (.STOP, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have rd5525 := evm_run h with [ - raw jumpdest hd5521 (by evm_ov), - raw push1 ⟨0⟩ hd5522 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd5524 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - obtain ⟨_, _, rd5526₀⟩ := rd5525.sload hd5525 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd5555 := evm_run rd5526₀ with [ - raw push2 ⟨65535⟩ hd5526 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd5529 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup5 hd5530 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5531 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨1⟩ hd5532 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨216⟩ hd5534 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd5536 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup2 hd5537 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw mul hd5538 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push2 ⟨65535⟩ hd5539 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨216⟩ hd5542 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd5544 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw not hd5545 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap1 hd5546 (by evm_ov), - raw swap4 hd5547 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5548 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap3 hd5549 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap1 hd5550 (by evm_ov), - raw swap3 hd5551 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw lor hd5552 (by evm_ov), - raw swap1 hd5553 (by evm_ov), - raw swap3 hd5554 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - obtain ⟨_, _, rd5556₀⟩ := rd5555.sstore hperm hd5555 (by evm_ov) - have rd5556 := by - simpa [increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord, - codeOwnerStorageWord] using rd5556₀ - have rd5565 := evm_run rd5556 with [ - raw swap2 hd5556 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap3 hd5557 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw pop hd5558 (by evm_ov), - raw dup4 hd5559 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5560 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw eq hd5561 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push2 ⟨5630⟩ hd5562 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd5630 := rd5565.jumpiT hd5565 (by - rw [u256_eq_refl] - exact one_ne_zero_uint) - (uniswapV3PoolJumpDestPatched5630 hpatch) - (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd5636 := evm_run rd5630 with [ - raw jumpdest hd5630 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw pop hd5631 (by evm_ov), - raw pop hd5632 (by evm_ov), - raw push1 ⟨0⟩ hd5633 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd5635 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - obtain ⟨_, _, rd5637₀⟩ := rd5636.sload hd5636 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd5651 := evm_run rd5637₀ with [ - raw push1 ⟨255⟩ hd5637 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨240⟩ hd5639 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd5641 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw not hd5642 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5643 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨1⟩ hd5644 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨240⟩ hd5646 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd5648 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw lor hd5649 (by evm_ov), - raw swap1 hd5650 (by evm_ov)] - obtain ⟨_, _, rd5652₀⟩ := rd5651.sstore hperm hd5651 (by evm_ov) - have rd5652 := by - simpa [increaseObservationCardinalityNextEvmUnlockedTrueSlotWord, - slot0UnlockedClearMask, codeOwnerStorageWord] using rd5652₀ - have rd5653 := evm_run rd5652 with [ - raw pop hd5652 (by evm_ov)] - have rd857 := rd5653.jump hd5653 - (uniswapV3PoolIncreaseObservationCardinalityNextJumpDestPatched857 hpatch) - (by evm_ov) - have rd858 := rd857.jumpdest hd857 (by evm_ov) - have hpc858 : (⟨857⟩ : UInt256) + ⟨1⟩ = ⟨858⟩ := by - native_decide - obtain ⟨_, _, rd858'⟩ : ∃ k' C', RD code ee g s0 ⟨858⟩ R solcFreePtrMem - (UInt256.ofNat 3) rdata - (cA, sstoreAccountMap ee.codeOwner - (sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord σ ee)) - ⟨0⟩ - (increaseObservationCardinalityNextEvmUnlockedTrueSlotWord - (sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord σ ee)) ee)) - k' C' := by - exact ⟨_, _, by - simpa [increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord, - increaseObservationCardinalityNextEvmUnlockedTrueSlotWord, slot0UnlockedClearMask, - codeOwnerStorageWord, hpc858] using rd858⟩ - exact rd858'.stop hd858 (by - have h := hov - omega) - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextDecodedReachRoutine - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {de ret : UInt256} {R : List UInt256} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨846⟩ (de :: ⟨4⟩ :: ret :: R) mem aw rdata acc k C) - (hov : R.length + 3 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨5404⟩ - (increaseObservationCardinalityNextArgWord ee :: ret :: R) mem aw rdata acc k' C' := by - have harg : - UInt256.land increaseObservationCardinalityNextUint16Mask (calldataWord ee.calldata 4) = - increaseObservationCardinalityNextArgWord ee := by - rw [increaseObservationCardinalityNextArgWord, u256_land_comm] - have rd847 : RD code ee g s0 ⟨847⟩ (de :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1) (C + 1) := by - simpa using h.jumpdest - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd848 : RD code ee g s0 ⟨848⟩ (⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1) (C + 1 + 2) := by - simpa using rd847.pop - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd849 : RD code ee g s0 ⟨849⟩ (calldataWord ee.calldata 4 :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1) (C + 1 + 2 + 3) := by - simpa [calldataWord, show (⟨4⟩ : UInt256).toNat = 4 from by decide] using - (rd848.calldataload - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov)) - have rd852 : RD code ee g s0 ⟨852⟩ - (increaseObservationCardinalityNextUint16Mask :: calldataWord ee.calldata 4 :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3) := by - simpa [increaseObservationCardinalityNextUint16Mask] using rd849.push2 ⟨65535⟩ - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd853 : RD code ee g s0 ⟨853⟩ - (increaseObservationCardinalityNextArgWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3 + 3) := by - simpa [harg] using rd852.and - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by - simp only [List.length_cons] - omega) - have rd856 : RD code ee g s0 ⟨856⟩ - (⟨5404⟩ :: increaseObservationCardinalityNextArgWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3 + 3 + 3) := by - simpa using rd853.push2 ⟨5404⟩ - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - exact ⟨_, _, rd856.jump - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (uniswapV3PoolJumpDestPatched5404 hpatch) - (by evm_ov)⟩ - -set_option maxHeartbeats 3000000 in -private theorem uniswapV3PoolIncreaseObservationCardinalityNextExternalLenOk - {v : PoolImmutables} {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hreach : ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨824⟩ - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨846⟩ - (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩ :: ⟨4⟩ :: ⟨857⟩ :: - [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact RD.solcExternalStaticArgsLenOk (need := ⟨32⟩) - (entry := ⟨824⟩) (ret := ⟨857⟩) (decoded := ⟨846⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (solcDecodeLenCheckOkUnsigned (by simpa using hsz36) hsize) - -theorem uniswapV3PoolIncreaseObservationCardinalityNextEvmDecodeShort - {v : PoolImmutables} {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 5 == I.calldata.extract 0 4) = true) - (hshort : I.calldata.size < 36) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - have hreach := uniswapV3PoolIncreaseObservationCardinalityNextReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - have hlt : - UInt256.lt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩ := by - apply ult_one - rw [usub_ofNat_word_toNat (by - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega) hsize] - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide] - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega - exact RD.solcExternalStaticArgsShortReverts (need := ⟨32⟩) - (entry := ⟨824⟩) (ret := ⟨857⟩) (decoded := ⟨846⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - hlt - -theorem uniswapV3PoolIncreaseObservationCardinalityNextBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 5 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := - uniswapV3PoolDispatch_increaseObservationCardinalityNext (v := v) (cd := I.calldata) hsel - by_cases hsz36 : 36 ≤ I.calldata.size - · have hdecode := - uniswapV3PoolIncreaseObservationCardinalityNextDecodeOk (v := v) (I := I) hsz36 - have hreach := uniswapV3PoolIncreaseObservationCardinalityNextReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz - hsize hsel - obtain ⟨_, _, hdecoded⟩ := - uniswapV3PoolIncreaseObservationCardinalityNextExternalLenOk - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hpatch hreach - hsz36 hsize - obtain ⟨_, _, hbodyEntry⟩ := - uniswapV3PoolIncreaseObservationCardinalityNextDecodedReachRoutine - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (de := UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) (ret := ⟨857⟩) - (R := [solcSelectorWord I]) (mem := solcFreePtrMem) (aw := UInt256.ofNat 3) - (rdata := ByteArray.empty) (acc := (cA, σ_evm)) hpatch hdecoded - (by simp only [List.length_singleton]; omega) - by_cases hunlocked : increaseObservationCardinalityNextUnlockedByte σ_evm I ≠ ⟨0⟩ - · have hlockProgress : - ∃ k C, RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨5486⟩ - (increaseObservationCardinalityNextArgWord I :: ⟨857⟩ :: [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) k C := - uniswapV3PoolIncreaseObservationCardinalityNextLockEnterOk - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := increaseObservationCardinalityNextArgWord I :: ⟨857⟩ :: [solcSelectorWord I]) - (mem := solcFreePtrMem) (aw := UInt256.ofNat 3) (rdata := ByteArray.empty) - (cA := cA) (σ := σ_evm) hpatch hbodyEntry _hperm hunlocked - (by norm_num) - have hunlockedSolm : - increaseObservationCardinalityNextUnlockedByte σ_solm I ≠ ⟨0⟩ := by - rw [increaseObservationCardinalityNextUnlockedByte_transport - (σ_evm := σ_evm) (σ_solm := σ_solm) hAccounts] - exact hunlocked - have hsourceLock := - uniswapV3PoolIncreaseObservationCardinalityNextSourceLockPrefixExact (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm - have hlockedWord : - increaseObservationCardinalityNextLockedSlotWord σ_solm I = - increaseObservationCardinalityNextLockedSlotWord σ_evm I := - increaseObservationCardinalityNextLockedSlotWord_transport (σ_evm := σ_evm) - (σ_solm := σ_solm) hAccounts - have hAccountsAfterLock : - accountMapEquiv - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) := by - rw [hlockedWord] - exact accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I) hAccounts - have hsourceLockState : - Solm.EVM.storageStore (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - I.codeOwner ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I) = - initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I := by - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ_solm.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have hsourceLockInit : - ExecBlock (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false) ] - (.ok { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I)) := by - simpa [hsourceLockState] using hsourceLock - obtain ⟨kLock, CLock, hrdAfterLock⟩ := hlockProgress - by_cases hnoDelegate : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩ - · obtain ⟨kNoDelegate, CNoDelegate, hrdNoDelegate⟩ := - uniswapV3PoolNoDelegateCallOk (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := increaseObservationCardinalityNextArgWord I :: ⟨857⟩ :: [solcSelectorWord I]) - (mem := solcFreePtrMem) (aw := UInt256.ofNat 3) (rdata := ByteArray.empty) - (acc := (cA, sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I))) - hpatch hrdAfterLock hnoDelegate (by norm_num) - have hsourceNoDelegate : - ExecBlock (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I) - [ .require (.binary .eq (.env .this) (addrLit v.original)) ] - (.ok { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I)) := by - exact ExecBlock.consNormal - (ExecStmt.requireTrue (uniswapV3PoolNoDelegateCallEvalTrue - (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ := sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - (σ₀ := σ₀) (A := A) (I := I) - (L := increaseObservationCardinalityNextStore I) - (g := Sat256.ofUInt256 g) hnoDelegate)) - ExecBlock.nil - by_cases holdZeroEvm : - increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) I = ⟨0⟩ - · have hrd := - uniswapV3PoolIncreaseObservationCardinalityNextAfterNoDelegateOldZeroRevert - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [solcSelectorWord I]) (rdata := ByteArray.empty) (cA := cA) - (σ := sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) - hpatch hrdNoDelegate holdZeroEvm (by norm_num) - have holdZeroSolm : - increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) I = ⟨0⟩ := by - rw [increaseObservationCardinalityNextOldWord_transport hAccountsAfterLock] - exact holdZeroEvm - have hsourceOldZero : - ExecBlock (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I) - [ .letDecl "observationCardinalityNextOld" (some uint16) - (.storage (slot0F "observationCardinalityNext")), - .letDecl "observationCardinalityNextNew" (some uint16) - (.var "observationCardinalityNext"), - .require (gtE (.var "observationCardinalityNextOld") (.intLit 0)), - Stmt.ite (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) - [ .assign .localVar (varRef "observationCardinalityNextNew") - (.var "observationCardinalityNextOld") ] - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") - (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ], - .assign .storage (slot0F "observationCardinalityNext") - (.var "observationCardinalityNextNew"), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted := by - exact uniswapV3PoolIncreaseObservationCardinalityNextSourceOldZeroReverts - (v := v) - (evm := initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I) - (I := I) - (by simp [initState]) - (by simpa [initState] using holdZeroSolm) - have hsourceFail : - ExecBlock (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I) - [ .require (.binary .eq (.env .this) (addrLit v.original)), - .letDecl "observationCardinalityNextOld" (some uint16) - (.storage (slot0F "observationCardinalityNext")), - .letDecl "observationCardinalityNextNew" (some uint16) - (.var "observationCardinalityNext"), - .require (gtE (.var "observationCardinalityNextOld") (.intLit 0)), - Stmt.ite (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) - [ .assign .localVar (varRef "observationCardinalityNextNew") - (.var "observationCardinalityNextOld") ] - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") - (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ], - .assign .storage (slot0F "observationCardinalityNext") - (.var "observationCardinalityNextNew"), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted := by - simpa using execBlock_append hsourceNoDelegate hsourceOldZero - have hbody : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (increaseObservationCardinalityNextStore I) - (increaseobservationcardinalitynextTransition v).body .reverted := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (increaseObservationCardinalityNextStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .eq (.env .this) (addrLit v.original)), - .letDecl "observationCardinalityNextOld" (some uint16) - (.storage (slot0F "observationCardinalityNext")), - .letDecl "observationCardinalityNextNew" (some uint16) - (.var "observationCardinalityNext"), - .require (gtE (.var "observationCardinalityNextOld") (.intLit 0)), - Stmt.ite (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) - [ .assign .localVar (varRef "observationCardinalityNextNew") - (.var "observationCardinalityNextOld") ] - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") - (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ], - .assign .storage (slot0F "observationCardinalityNext") - (.var "observationCardinalityNextNew"), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted - exact ExecFuncBody.execBlockRevert <| by - simpa using execBlock_append hsourceLockInit hsourceFail - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have holdNonzeroEvm : - increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) I ≠ ⟨0⟩ := - holdZeroEvm - have holdNonzeroSolm : - increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) I ≠ ⟨0⟩ := by - rw [increaseObservationCardinalityNextOldWord_transport hAccountsAfterLock] - exact holdNonzeroEvm - have hnoGrowPrefix : - UInt256.gt (increaseObservationCardinalityNextArgWord I) - (increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) I) = ⟨0⟩ → - ∃ k C, RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨5521⟩ - (increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) I :: - ⟨0⟩ :: - increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) I :: - increaseObservationCardinalityNextArgWord I :: ⟨857⟩ :: [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) k C := by - intro hnewLeEvm - exact uniswapV3PoolIncreaseObservationCardinalityNextAfterNoDelegateNoGrowReturn - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [solcSelectorWord I]) (rdata := ByteArray.empty) (cA := cA) - (σ := sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) - hpatch hrdNoDelegate holdNonzeroEvm hnewLeEvm (by norm_num) - have hnewLeSolm : - ∀ hnewLeEvm : - UInt256.gt (increaseObservationCardinalityNextArgWord I) - (increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) I) = ⟨0⟩, - UInt256.gt (increaseObservationCardinalityNextArgWord I) - (increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) I) = ⟨0⟩ := by - intro hnewLeEvm - rw [increaseObservationCardinalityNextOldWord_transport hAccountsAfterLock] - exact hnewLeEvm - have hsourceNoGrowReturns : - ∀ hnewLeEvm : - UInt256.gt (increaseObservationCardinalityNextArgWord I) - (increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) I) = ⟨0⟩, - ExecBlock (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I) - [ .letDecl "observationCardinalityNextOld" (some uint16) - (.storage (slot0F "observationCardinalityNext")), - .letDecl "observationCardinalityNextNew" (some uint16) - (.var "observationCardinalityNext"), - .require (gtE (.var "observationCardinalityNextOld") (.intLit 0)), - Stmt.ite (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) - [ .assign .localVar (varRef "observationCardinalityNextNew") - (.var "observationCardinalityNextOld") ] - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") - (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ], - .assign .storage (slot0F "observationCardinalityNext") - (.var "observationCardinalityNextNew"), - .assign .storage (slot0F "unlocked") (.boolLit true) ] - (.ok - { contract := contract v, - locals := increaseObservationCardinalityNextStoreWithOldNewNoGrow - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) I } - (slot0AfterUnlockState - (increaseObservationCardinalityNextAfterNoGrowObsNextState - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I) I))) := by - intro hnewLeEvm - exact uniswapV3PoolIncreaseObservationCardinalityNextSourceNoGrowReturns - (v := v) - (evm := initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I) - (I := I) - (by simp [initState]) - (by simpa [initState] using holdNonzeroSolm) - (by simpa [initState] using hnewLeSolm hnewLeEvm) - by_cases hnewLeEvm : - UInt256.gt (increaseObservationCardinalityNextArgWord I) - (increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) I) = ⟨0⟩ - · obtain ⟨_, _, hrd5521⟩ := hnoGrowPrefix hnewLeEvm - have hrdRet := - uniswapV3PoolIncreaseObservationCardinalityNextNoGrowTailReturn - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [solcSelectorWord I]) (rdata := ByteArray.empty) (cA := cA) - (σ := sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) - hpatch hrd5521 _hperm (by norm_num) - have hsourceSuccess := - execBlock_append hsourceNoDelegate (hsourceNoGrowReturns hnewLeEvm) - have hbody : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (increaseObservationCardinalityNextStore I) - (increaseobservationcardinalitynextTransition v).body - (.returned - { contract := contract v, - locals := increaseObservationCardinalityNextStoreWithOldNewNoGrow - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) I } - (slot0AfterUnlockState - (increaseObservationCardinalityNextAfterNoGrowObsNextState - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I) I)) - none) - := by - refine ExecFuncBody.execBlockOK ?_ - simpa [increaseobservationcardinalitynextTransition] using - execBlock_append hsourceLockInit hsourceSuccess - exact hrdRet.reEquivExecutionGenAccountMapEquiv hcode hdispatch hdecode hbody - (by - simp [slot0AfterUnlockState, - increaseObservationCardinalityNextAfterNoGrowObsNextState, - storageStore_createdAccounts, initState]) - (by - exact increaseObservationCardinalityNextFinalNoGrowAccountMapEquiv - (evmOwner := initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I) - (σOwnerEvm := sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) - (I := I) - (by simpa [initState] using hAccountsAfterLock) - (by simp [initState])) - (by - rw [show (increaseobservationcardinalitynextTransition v).returnType = [] - from rfl] - exact returnEquiv.fallthrough rfl rfl (by native_decide)) - · exact uniswapV3PoolIncreaseObservationCardinalityNextGrowBranch - (v := v) (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) - (σ_solm := σ_solm) (σ₀ := σ₀) (A := A) (I := I) (g := g) - (code := code) hpatch hcode hdispatch hdecode hsourceLockInit - hsourceNoDelegate hrdNoDelegate hAccountsAfterLock holdNonzeroEvm - holdNonzeroSolm hnewLeEvm _hperm - · have hnoDelegateZero : uniswapV3PoolNoDelegateCallGuard v I = ⟨0⟩ := by - by_contra hne - exact hnoDelegate hne - have hrd := - uniswapV3PoolNoDelegateCallRevert (v := v) (code := code) (ee := I) - (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := increaseObservationCardinalityNextArgWord I :: ⟨857⟩ :: [solcSelectorWord I]) - (mem := solcFreePtrMem) (aw := UInt256.ofNat 3) (rdata := ByteArray.empty) - (acc := (cA, sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I))) - hpatch hrdAfterLock hnoDelegateZero (by norm_num) - have hsourceFail : - ExecBlock (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I) - [ .require (.binary .eq (.env .this) (addrLit v.original)), - .letDecl "observationCardinalityNextOld" (some uint16) - (.storage (slot0F "observationCardinalityNext")), - .letDecl "observationCardinalityNextNew" (some uint16) - (.var "observationCardinalityNext"), - .require (gtE (.var "observationCardinalityNextOld") (.intLit 0)), - Stmt.ite (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) - [ .assign .localVar (varRef "observationCardinalityNextNew") - (.var "observationCardinalityNextOld") ] - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ], - .assign .storage (slot0F "observationCardinalityNext") - (.var "observationCardinalityNextNew"), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted := by - exact ExecBlock.consRevert - (ExecStmt.requireFalse (uniswapV3PoolNoDelegateCallEvalFalse - (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ := sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - (σ₀ := σ₀) (A := A) (I := I) - (L := increaseObservationCardinalityNextStore I) - (g := Sat256.ofUInt256 g) hnoDelegateZero)) - have hbody : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (increaseObservationCardinalityNextStore I) - (increaseobservationcardinalitynextTransition v).body .reverted := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (increaseObservationCardinalityNextStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .eq (.env .this) (addrLit v.original)), - .letDecl "observationCardinalityNextOld" (some uint16) - (.storage (slot0F "observationCardinalityNext")), - .letDecl "observationCardinalityNextNew" (some uint16) - (.var "observationCardinalityNext"), - .require (gtE (.var "observationCardinalityNextOld") (.intLit 0)), - Stmt.ite (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) - [ .assign .localVar (varRef "observationCardinalityNextNew") - (.var "observationCardinalityNextOld") ] - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ], - .assign .storage (slot0F "observationCardinalityNext") - (.var "observationCardinalityNextNew"), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted - exact ExecFuncBody.execBlockRevert <| by - simpa using execBlock_append hsourceLockInit hsourceFail - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hlockedEvm : increaseObservationCardinalityNextUnlockedByte σ_evm I = ⟨0⟩ := by - by_contra hne - exact hunlocked hne - have hlockedSolm : - increaseObservationCardinalityNextUnlockedByte σ_solm I = ⟨0⟩ := by - rw [increaseObservationCardinalityNextUnlockedByte_transport - (σ_evm := σ_evm) (σ_solm := σ_solm) hAccounts] - exact hlockedEvm - have hbody := - uniswapV3PoolIncreaseObservationCardinalityNextSourceLockedReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hwv hlockedSolm - have hrd := - uniswapV3PoolIncreaseObservationCardinalityNextLockEnterLockedRevert - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := increaseObservationCardinalityNextArgWord I :: ⟨857⟩ :: [solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) (σ := σ_evm) hpatch hbodyEntry - hlockedEvm (by norm_num) - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hshort : I.calldata.size < 36 := by omega - have hdecode := - uniswapV3PoolIncreaseObservationCardinalityNextDecodeShort (v := v) (I := I) hshort - have hrd := uniswapV3PoolIncreaseObservationCardinalityNextEvmDecodeShort - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz - hsize hsel hshort - exact hrd.reEquivDecodingFailed hcode hdispatch hdecode - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextBase.lean b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextBase.lean deleted file mode 100644 index 622eaa61..00000000 --- a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextBase.lean +++ /dev/null @@ -1,1298 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common -import Benchmarks.UniswapV3Pool.Locking -import Benchmarks.UniswapV3Pool.NoDelegateCall - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev increaseObservationCardinalityNextUint16Mask : UInt256 := UInt256.ofNat (2 ^ 16 - 1) - -abbrev increaseObservationCardinalityNextUint8Mask : UInt256 := UInt256.ofNat (2 ^ 8 - 1) - -abbrev increaseObservationCardinalityNextUnlockedShift : UInt256 := - UInt256.shiftLeft ⟨1⟩ ⟨240⟩ - -abbrev increaseObservationCardinalityNextUnlockedByte (σ : AccountMap) - (I : ExecutionEnv) : UInt256 := - UInt256.land increaseObservationCardinalityNextUint8Mask - (UInt256.div (solcSlotWord σ I ⟨0⟩) increaseObservationCardinalityNextUnlockedShift) - -abbrev increaseObservationCardinalityNextUnlockedClearMask : UInt256 := - UInt256.lnot (UInt256.shiftLeft increaseObservationCardinalityNextUint8Mask ⟨240⟩) - -abbrev increaseObservationCardinalityNextLockedSlotWord (σ : AccountMap) - (I : ExecutionEnv) : UInt256 := - UInt256.land increaseObservationCardinalityNextUnlockedClearMask (solcSlotWord σ I ⟨0⟩) - -abbrev increaseObservationCardinalityNextArgWord (I : ExecutionEnv) : UInt256 := - UInt256.land (calldataWord I.calldata 4) increaseObservationCardinalityNextUint16Mask - -abbrev increaseObservationCardinalityNextArgValue (I : ExecutionEnv) : Value := - .int (Int.ofNat (increaseObservationCardinalityNextArgWord I).toNat) - -abbrev increaseObservationCardinalityNextOldWord (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - slot0ObservationCardinalityNextWord σ I - -abbrev increaseObservationCardinalityNextOldValue (σ : AccountMap) (I : ExecutionEnv) : - Value := - .int (Int.ofNat (increaseObservationCardinalityNextOldWord σ I).toNat) - -abbrev increaseObservationCardinalityNextStore (I : ExecutionEnv) : Store := - (∅ : Store).insert "observationCardinalityNext" - (increaseObservationCardinalityNextArgValue I) - -abbrev increaseObservationCardinalityNextStoreWithOld (σ : AccountMap) - (I : ExecutionEnv) : Store := - (increaseObservationCardinalityNextStore I).insert "observationCardinalityNextOld" - (increaseObservationCardinalityNextOldValue σ I) - -abbrev increaseObservationCardinalityNextStoreWithOldNew (σ : AccountMap) - (I : ExecutionEnv) : Store := - (increaseObservationCardinalityNextStoreWithOld σ I).insert - "observationCardinalityNextNew" (increaseObservationCardinalityNextArgValue I) - -abbrev increaseObservationCardinalityNextStoreWithOldNewNoGrow (σ : AccountMap) - (I : ExecutionEnv) : Store := - (increaseObservationCardinalityNextStoreWithOldNew σ I).insert - "observationCardinalityNextNew" (increaseObservationCardinalityNextOldValue σ I) - -abbrev increaseObservationCardinalityNextUnlockedLoc : StorageLoc := - loc ⟨0⟩ ⟨30, by decide⟩ ⟨1, by decide⟩ (by decide) .bool - -abbrev increaseObservationCardinalityNextObservationCardinalityNextLoc : StorageLoc := - loc ⟨0⟩ ⟨27, by decide⟩ ⟨2, by decide⟩ (by decide) (.int uint16Int) - -abbrev increaseObservationCardinalityNextNoGrowSlotWord (evm : EVM.State) - (I : ExecutionEnv) : UInt256 := - UInt256.ofNat - (fromBytes' - ((List.take 27 - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).1 ++ - List.take 2 - (EVM.Word.toBytesLEWithSizeProof - (increaseObservationCardinalityNextOldWord evm.accountMap I)).1) ++ - List.drop (27 + 2) - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).1)) - -abbrev increaseObservationCardinalityNextAfterNoGrowObsNextState (evm : EVM.State) - (I : ExecutionEnv) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (increaseObservationCardinalityNextNoGrowSlotWord evm I) - -abbrev increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord - (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.lor - (UInt256.land - (codeOwnerStorageWord I σ ⟨0⟩) - (UInt256.lnot (UInt256.shiftLeft (⟨65535⟩ : UInt256) ⟨216⟩))) - (UInt256.mul - (UInt256.land (increaseObservationCardinalityNextOldWord σ I) (⟨65535⟩ : UInt256)) - (UInt256.shiftLeft ⟨1⟩ ⟨216⟩)) - -abbrev increaseObservationCardinalityNextEvmUnlockedTrueSlotWord - (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.lor - (UInt256.shiftLeft ⟨1⟩ ⟨240⟩) - (UInt256.land slot0UnlockedClearMask (codeOwnerStorageWord I σ ⟨0⟩)) - -theorem increaseObservationCardinalityNextUint16Mask_toNat : - increaseObservationCardinalityNextUint16Mask.toNat = 2 ^ 16 - 1 := by - exact ulit_toNat' _ (by norm_num [UInt256.size]) - -theorem increaseObservationCardinalityNextUint16Mask_decode (w : UInt256) : - (UInt256.land w increaseObservationCardinalityNextUint16Mask).toNat = - w.toNat % EVM.twoPow 16 := by - rw [u256_land_toNat, increaseObservationCardinalityNextUint16Mask_toNat, - nat_land_mask_eq_mod] - exact Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num [EVM.twoPow])) - (by norm_num [EVM.twoPow, UInt256.size])) - -theorem decodeScalarWordWithMode_uint16_ok {bytes : List UInt8} {start : Nat} - (hlen : ((bytes.drop start).take 32).length = 32) : - decodeScalarWordWithMode? DecodeMode.legacySolc05 uint16 bytes start = - some - (.int (Int.ofNat - (UInt256.land (ABI.bytesToWord ((bytes.drop start).take 32)) - increaseObservationCardinalityNextUint16Mask).toNat), - start + 32) := by - simp only [decodeScalarWordWithMode?] - unfold readWord? readBytes? uint16 uint16Int - rw [if_pos hlen] - simp only [bind, Option.bind] - unfold decodeABIWord? - simp only [OfNat.ofNat_ne_zero, ↓reduceIte] - rw [increaseObservationCardinalityNextUint16Mask_decode] - rfl - -theorem decodeScalarWordsWithMode_uint16_ok {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) : - decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint16] bytes 0 = - some - [ .int (Int.ofNat - (UInt256.land (ABI.bytesToWord (bytes.take 32)) - increaseObservationCardinalityNextUint16Mask).toNat) ] := by - simp only [decodeScalarWordsWithMode?] - rw [decodeScalarWordWithMode_uint16_ok (bytes := bytes) (start := 0) (by simpa using hlen0)] - simp only [List.drop_zero, bind, Option.bind] - -theorem decodeScalarWordsWithMode_uint16_none_short {bytes : List UInt8} - (hshort : bytes.length < 32) : - decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint16] bytes 0 = none := by - simp only [decodeScalarWordsWithMode?] - have htake0n : ¬ (bytes.take 32).length = 32 := by - rw [List.length_take] - omega - unfold decodeScalarWordWithMode? readWord? readBytes? uint16 uint16Int - simp only [List.drop_zero] - rw [if_neg htake0n] - simp only [Option.bind, bind] - -theorem increaseObservationCardinalityNextUnlockedByte_eq_slot0UnlockedRawWord - (σ : AccountMap) (I : ExecutionEnv) : - increaseObservationCardinalityNextUnlockedByte σ I = slot0UnlockedRawWord σ I := by - have hshift : increaseObservationCardinalityNextUnlockedShift = slot0ShiftBytes 30 := by - native_decide - simp [increaseObservationCardinalityNextUnlockedByte, slot0UnlockedRawWord, - increaseObservationCardinalityNextUnlockedShift, slot0ShiftBytes, slot0SlotWord, - increaseObservationCardinalityNextUint8Mask, slot0Uint8Mask, hshift, u256_land_comm] - -theorem uniswapV3PoolIncreaseObservationCardinalityNextEvalUnlocked {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "unlocked")) = - .ok (wordToElem .bool (increaseObservationCardinalityNextUnlockedByte σ I)) := by - rw [evalExpr_storage_scalar - (t := .bool) - (slot := slot0F "unlocked") - (er := { base := "slot0", steps := [.field "unlocked"] }) - (loc := increaseObservationCardinalityNextUnlockedLoc) - (hbase := by simp [slot0F, increaseObservationCardinalityNextStore]) - (her := by - simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, boolSt]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - increaseObservationCardinalityNextUnlockedLoc, loc])] - simpa [increaseObservationCardinalityNextUnlockedByte_eq_slot0UnlockedRawWord] using - slot0StorageLocLoad_unlocked (initState cA gh bl σ σ₀ g A I) - -theorem increaseObservationCardinalityNextUnlockedByte_wordToElem_false - {σ : AccountMap} {I : ExecutionEnv} - (hzero : increaseObservationCardinalityNextUnlockedByte σ I = ⟨0⟩) : - wordToElem .bool (increaseObservationCardinalityNextUnlockedByte σ I) = .bool false := by - simp [wordToElem, hzero] - -theorem increaseObservationCardinalityNextUnlockedByte_wordToElem_true - {σ : AccountMap} {I : ExecutionEnv} - (hnz : increaseObservationCardinalityNextUnlockedByte σ I ≠ ⟨0⟩) : - wordToElem .bool (increaseObservationCardinalityNextUnlockedByte σ I) = .bool true := by - have hbeq : ((increaseObservationCardinalityNextUnlockedByte σ I).val == 0) = false := by - rw [beq_eq_false_iff_ne] - intro hval - apply hnz - apply u256_inj - simpa [UInt256.toNat] using hval - simp [wordToElem, hbeq] - -theorem increaseObservationCardinalityNextUnlockedByte_transport - {σ_evm σ_solm : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - increaseObservationCardinalityNextUnlockedByte σ_solm I = - increaseObservationCardinalityNextUnlockedByte σ_evm I := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ (⟨0⟩ : UInt256) - dsimp [increaseObservationCardinalityNextUnlockedByte, solcSlotWord] - rw [← hslot] - -theorem increaseObservationCardinalityNextLockedSlotWord_transport - {σ_evm σ_solm : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - increaseObservationCardinalityNextLockedSlotWord σ_solm I = - increaseObservationCardinalityNextLockedSlotWord σ_evm I := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ (⟨0⟩ : UInt256) - dsimp [increaseObservationCardinalityNextLockedSlotWord, solcSlotWord] - rw [← hslot] - -theorem increaseObservationCardinalityNextOldWord_transport - {σ_evm σ_solm : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - increaseObservationCardinalityNextOldWord σ_solm I = - increaseObservationCardinalityNextOldWord σ_evm I := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ (⟨0⟩ : UInt256) - dsimp [increaseObservationCardinalityNextOldWord, slot0ObservationCardinalityNextWord, - slot0SlotWord, solcSlotWord] - rw [← hslot] - -theorem increaseObservationCardinalityNextStorageLoad_codeOwner_eq - {evm : EVM.State} {σ : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ evm.accountMap) (hEnv : evm.executionEnv = I) : - Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ = - codeOwnerStorageWord I σ ⟨0⟩ := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ (⟨0⟩ : UInt256) - simpa [Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage, - codeOwnerStorageWord, hEnv] using hslot.symm - -theorem increaseObservationCardinalityNextNoGrowClearMask_toNat : - (UInt256.lnot (UInt256.shiftLeft (⟨65535⟩ : UInt256) ⟨216⟩)).toNat = - 2 ^ 256 - 2 ^ 232 + (2 ^ 216 - 1) := by - native_decide - -theorem natLandClearObservationCardinalityNextBytes (n : Nat) (hn : n < 2 ^ 256) : - Nat.land n (2 ^ 256 - 2 ^ 232 + (2 ^ 216 - 1)) = - n % 2 ^ 216 + (n / 2 ^ 232) * 2 ^ 232 := by - apply Nat.eq_of_testBit_eq - intro i - change (n &&& (2 ^ 256 - 2 ^ 232 + (2 ^ 216 - 1))).testBit i = - (n % 2 ^ 216 + n / 2 ^ 232 * 2 ^ 232).testBit i - rw [Nat.testBit_and] - rw [show n % 2 ^ 216 + (n / 2 ^ 232) * 2 ^ 232 = - 2 ^ 232 * (n / 2 ^ 232) + n % 2 ^ 216 by ring] - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 232) - (b_lt := lt_trans (Nat.mod_lt _ (show 0 < 2 ^ 216 by norm_num)) - (by norm_num : 2 ^ 216 < 2 ^ 232))] - rw [show 2 ^ 256 - 2 ^ 232 + (2 ^ 216 - 1) = - 2 ^ 232 * (2 ^ 24 - 1) + (2 ^ 216 - 1) by norm_num [Nat.pow_add]] - have hmaskLow : 2 ^ 216 - 1 < 2 ^ 232 := by norm_num - rw [Nat.testBit_two_pow_mul_add (a := 2 ^ 24 - 1) (b_lt := hmaskLow)] - by_cases hi232 : i < 232 - · simp [hi232] - change (n.testBit i && (2 ^ 216 - 1).testBit i) = (n % 2 ^ 216).testBit i - by_cases hi216 : i < 216 - · have hmask : (2 ^ 216 - 1).testBit i = true := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_true hi216 - have hmod : (n % 2 ^ 216).testBit i = n.testBit i := by - rw [Nat.testBit_mod_two_pow] - simp [hi216] - rw [hmask, hmod] - simp - · have hmask : (2 ^ 216 - 1).testBit i = false := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_false hi216 - have hmod : (n % 2 ^ 216).testBit i = false := by - rw [Nat.testBit_mod_two_pow] - simp [hi216] - rw [hmask, hmod] - simp - · have h232le : 232 ≤ i := Nat.le_of_not_gt hi232 - simp [hi232] - change (n.testBit i && (2 ^ 24 - 1).testBit (i - 232)) = - (n / 2 ^ 232).testBit (i - 232) - by_cases hi256 : i < 256 - · have hsub24 : i - 232 < 24 := by omega - have hdiv := divPow_testBit n 232 i h232le - have hmask : (2 ^ 24 - 1).testBit (i - 232) = true := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_true hsub24 - rw [hdiv, hmask] - simp - · have hsub24 : ¬ i - 232 < 24 := by omega - have hnbit : n.testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hn (Nat.pow_le_pow_right (by norm_num) (by omega : 256 ≤ i))) - have hdivfalse : (n / 2 ^ 232).testBit (i - 232) = false := by - rw [divPow_testBit n 232 i h232le, hnbit] - have hmask : (2 ^ 24 - 1).testBit (i - 232) = false := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_false hsub24 - rw [hmask, hdivfalse] - simp - -private theorem nat_lor_packed_uint16_byte216 (n field : Nat) - (hfield : field < 2 ^ 16) : - Nat.lor (n % 2 ^ 216 + n / 2 ^ 232 * 2 ^ 232) (field * 2 ^ 216) = - n % 2 ^ 216 + field * 2 ^ 216 + n / 2 ^ 232 * 2 ^ 232 := by - apply Nat.eq_of_testBit_eq - intro i - change ((n % 2 ^ 216 + n / 2 ^ 232 * 2 ^ 232) ||| (field * 2 ^ 216)).testBit i = - (n % 2 ^ 216 + field * 2 ^ 216 + n / 2 ^ 232 * 2 ^ 232).testBit i - rw [Nat.testBit_or] - rw [show n % 2 ^ 216 + n / 2 ^ 232 * 2 ^ 232 = - 2 ^ 232 * (n / 2 ^ 232) + n % 2 ^ 216 by ring] - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 232) - (b_lt := lt_trans (Nat.mod_lt _ (show 0 < 2 ^ 216 by norm_num)) - (by norm_num : 2 ^ 216 < 2 ^ 232))] - rw [show n % 2 ^ 216 + field * 2 ^ 216 + n / 2 ^ 232 * 2 ^ 232 = - 2 ^ 232 * (n / 2 ^ 232) + (2 ^ 216 * field + n % 2 ^ 216) by ring] - have hmid : 2 ^ 216 * field + n % 2 ^ 216 < 2 ^ 232 := by - have hlow : n % 2 ^ 216 ≤ 2 ^ 216 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (show 0 < 2 ^ 216 by norm_num)) - have hfieldle : field ≤ 2 ^ 16 - 1 := Nat.le_pred_of_lt hfield - have hmax : 2 ^ 216 * (2 ^ 16 - 1) + (2 ^ 216 - 1) < 2 ^ 232 := by - norm_num [Nat.pow_add] - nlinarith - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 232) (b_lt := hmid)] - rw [Nat.testBit_two_pow_mul_add (a := field) - (b_lt := Nat.mod_lt _ (show 0 < 2 ^ 216 by norm_num))] - rw [show field * 2 ^ 216 = 2 ^ 216 * field + 0 by ring] - rw [Nat.testBit_two_pow_mul_add (a := field) (b_lt := show 0 < 2 ^ 216 by norm_num)] - by_cases hi216 : i < 216 - · simp [hi216] - · have h216le : 216 ≤ i := Nat.le_of_not_gt hi216 - have hlowfalse : (n % 2 ^ 216).testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le (Nat.mod_lt _ (show 0 < 2 ^ 216 by norm_num)) - (Nat.pow_le_pow_right (by norm_num) h216le)) - by_cases hi232 : i < 232 - · simp [hi216, hi232] - intro hlowtrue - have hlowfalse' : - (n % 105312291668557186697918027683670432318895095400549111254310977536).testBit i = - false := by - simpa using hlowfalse - rw [hlowfalse'] at hlowtrue - cases hlowtrue - · have hfieldfalse : field.testBit (i - 216) = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hfield (Nat.pow_le_pow_right (by norm_num) (by omega))) - simp [hi216, hi232] - intro hfieldtrue - rw [hfieldfalse] at hfieldtrue - cases hfieldtrue - -private theorem nat_lor_packed_byte240 (n byte : Nat) (hbyte : byte < 2 ^ 8) : - Nat.lor (n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248) (byte * 2 ^ 240) = - n % 2 ^ 240 + byte * 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248 := by - apply Nat.eq_of_testBit_eq - intro i - change ((n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248) ||| (byte * 2 ^ 240)).testBit i = - (n % 2 ^ 240 + byte * 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248).testBit i - rw [Nat.testBit_or] - rw [show n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248 = - 2 ^ 248 * (n / 2 ^ 248) + n % 2 ^ 240 by ring] - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 248) - (b_lt := lt_trans (Nat.mod_lt _ (show 0 < 2 ^ 240 by norm_num)) - (by norm_num : 2 ^ 240 < 2 ^ 248))] - rw [show n % 2 ^ 240 + byte * 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248 = - 2 ^ 248 * (n / 2 ^ 248) + (2 ^ 240 * byte + n % 2 ^ 240) by ring] - have hmid : 2 ^ 240 * byte + n % 2 ^ 240 < 2 ^ 248 := by - have hlow : n % 2 ^ 240 ≤ 2 ^ 240 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (show 0 < 2 ^ 240 by norm_num)) - have hbytele : byte ≤ 2 ^ 8 - 1 := Nat.le_pred_of_lt hbyte - have hmax : 2 ^ 240 * (2 ^ 8 - 1) + (2 ^ 240 - 1) < 2 ^ 248 := by - norm_num [Nat.pow_add] - nlinarith - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 248) (b_lt := hmid)] - rw [Nat.testBit_two_pow_mul_add (a := byte) - (b_lt := Nat.mod_lt _ (show 0 < 2 ^ 240 by norm_num))] - rw [show byte * 2 ^ 240 = 2 ^ 240 * byte + 0 by ring] - rw [Nat.testBit_two_pow_mul_add (a := byte) (b_lt := show 0 < 2 ^ 240 by norm_num)] - by_cases hi240 : i < 240 - · simp [hi240] - · have h240le : 240 ≤ i := Nat.le_of_not_gt hi240 - have hlowfalse : (n % 2 ^ 240).testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le (Nat.mod_lt _ (show 0 < 2 ^ 240 by norm_num)) - (Nat.pow_le_pow_right (by norm_num) h240le)) - by_cases hi248 : i < 248 - · simp [hi240, hi248] - intro hlowtrue - have hlowfalse' : - (n % 1766847064778384329583297500742918515827483896875618958121606201292619776).testBit i = - false := by - simpa using hlowfalse - rw [hlowfalse'] at hlowtrue - cases hlowtrue - · have hbytefalse : byte.testBit (i - 240) = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hbyte (Nat.pow_le_pow_right (by norm_num) (by omega))) - simp [hi240, hi248] - intro hbytetrue - rw [hbytefalse] at hbytetrue - cases hbytetrue - -private theorem nat_lor_packed_true_byte240 (n : Nat) : - Nat.lor (n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248) (2 ^ 240) = - n % 2 ^ 240 + 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248 := by - simpa using nat_lor_packed_byte240 n 1 (by norm_num : 1 < 2 ^ 8) - -theorem increaseObservationCardinalityNextNoGrowSlotWord_nat_lt - (evm : EVM.State) (I : ExecutionEnv) : - fromBytes' - ((List.take 27 - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).1 ++ - List.take 2 - (EVM.Word.toBytesLEWithSizeProof - (increaseObservationCardinalityNextOldWord evm.accountMap I)).1) ++ - List.drop (27 + 2) - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).1) < - UInt256.size := by - let bs := - ((List.take 27 - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).1 ++ - List.take 2 - (EVM.Word.toBytesLEWithSizeProof - (increaseObservationCardinalityNextOldWord evm.accountMap I)).1) ++ - List.drop (27 + 2) - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).1) - have hlen : bs.length = 32 := by - simp [bs, List.length_take, List.length_drop, - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).2, - (EVM.Word.toBytesLEWithSizeProof - (increaseObservationCardinalityNextOldWord evm.accountMap I)).2] - apply lt_of_lt_of_le (b := 2 ^ (8 * bs.length)) - · simpa [bs] using (EVM.fromBytes'_le (bs := bs)) - · rw [hlen] - norm_num [UInt256.size] - -theorem increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord_eq - {evm : EVM.State} {σ : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ evm.accountMap) (hEnv : evm.executionEnv = I) : - increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord σ I = - increaseObservationCardinalityNextNoGrowSlotWord evm I := by - have hload := increaseObservationCardinalityNextStorageLoad_codeOwner_eq - (evm := evm) (σ := σ) (I := I) hAccounts hEnv - have holdEq : - increaseObservationCardinalityNextOldWord evm.accountMap I = - increaseObservationCardinalityNextOldWord σ I := by - exact increaseObservationCardinalityNextOldWord_transport - (σ_evm := σ) (σ_solm := evm.accountMap) hAccounts - have holdLt : - (increaseObservationCardinalityNextOldWord σ I).toNat < 2 ^ 16 := by - simpa [increaseObservationCardinalityNextOldWord] using - slot0Uint16Mask_bound (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 27)) - have hclearLt : - (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 216 + - (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 232 * 2 ^ 232 < - UInt256.size := by - rw [← natLandClearObservationCardinalityNextBytes - (codeOwnerStorageWord I σ ⟨0⟩).toNat (codeOwnerStorageWord I σ ⟨0⟩).val.isLt] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [UInt256.size]) - have hpackedLt : - (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 216 + - (increaseObservationCardinalityNextOldWord σ I).toNat * 2 ^ 216 + - (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 232 * 2 ^ 232 < - UInt256.size := by - have hlow : (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 216 ≤ 2 ^ 216 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (show 0 < 2 ^ 216 by norm_num)) - have holdLe : - (increaseObservationCardinalityNextOldWord σ I).toNat ≤ 2 ^ 16 - 1 := - Nat.le_pred_of_lt holdLt - have hhighLt : (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 232 < 2 ^ 24 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 232 * 2 ^ 24 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change (codeOwnerStorageWord I σ ⟨0⟩).val.val < UInt256.size - exact (codeOwnerStorageWord I σ ⟨0⟩).val.isLt - have hhighLe : (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 232 ≤ 2 ^ 24 - 1 := - Nat.le_pred_of_lt hhighLt - have hmax : - (2 ^ 216 - 1) + (2 ^ 16 - 1) * 2 ^ 216 + - (2 ^ 24 - 1) * 2 ^ 232 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - nlinarith - have hmulLt : - (increaseObservationCardinalityNextOldWord σ I).toNat * 2 ^ 216 < UInt256.size := by - exact lt_of_lt_of_le - (Nat.mul_lt_mul_of_pos_right holdLt (by norm_num : 0 < 2 ^ 216)) - (by norm_num [UInt256.size]) - have hmulMod : - (increaseObservationCardinalityNextOldWord σ I).toNat * 2 ^ 216 % UInt256.size = - (increaseObservationCardinalityNextOldWord σ I).toNat * 2 ^ 216 := - Nat.mod_eq_of_lt hmulLt - have hsourceWordLt : - fromBytes' - ((List.take 27 - (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).1 ++ - List.take 2 - (EVM.Word.toBytesLEWithSizeProof - (increaseObservationCardinalityNextOldWord σ I)).1) ++ - List.drop (27 + 2) - (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).1) < - UInt256.size := by - let bs := - ((List.take 27 - (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).1 ++ - List.take 2 - (EVM.Word.toBytesLEWithSizeProof - (increaseObservationCardinalityNextOldWord σ I)).1) ++ - List.drop (27 + 2) - (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).1) - have hlen : bs.length = 32 := by - simp [bs, List.length_take, List.length_drop, - (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).2, - (EVM.Word.toBytesLEWithSizeProof - (increaseObservationCardinalityNextOldWord σ I)).2] - apply lt_of_lt_of_le (b := 2 ^ (8 * bs.length)) - · simpa [bs] using (EVM.fromBytes'_le (bs := bs)) - · rw [hlen] - norm_num [UInt256.size] - apply u256_inj - rw [increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord, - increaseObservationCardinalityNextNoGrowSlotWord] - rw [hload, holdEq] - rw [u256_lor_toNat, u256_land_toNat, u256_mul_toNat] - rw [increaseObservationCardinalityNextNoGrowClearMask_toNat] - rw [natLandClearObservationCardinalityNextBytes] - rw [Nat.mod_eq_of_lt hclearLt] - rw [u256_land_toNat] - rw [show (⟨65535⟩ : UInt256).toNat = 2 ^ 16 - 1 by native_decide] - rw [nat_land_mask_eq_mod] - rw [Nat.mod_eq_of_lt holdLt] - rw [Nat.mod_eq_of_lt (lt_trans holdLt (by norm_num [UInt256.size]))] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨216⟩).toNat = 2 ^ 216 by - native_decide] - rw [hmulMod] - rw [nat_lor_packed_uint16_byte216 _ _ holdLt] - rw [Nat.mod_eq_of_lt hpackedLt] - rw [ulit_toNat' _ hsourceWordLt] - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - have hlen27 : - (List.take 27 (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).1).length = - 27 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof - (codeOwnerStorageWord I σ ⟨0⟩)).2] - norm_num - have hlen29 : - (List.take 27 (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).1 ++ - List.take 2 - (EVM.Word.toBytesLEWithSizeProof - (increaseObservationCardinalityNextOldWord σ I)).1).length = - 29 := by - rw [List.length_append, hlen27, List.length_take, - (EVM.Word.toBytesLEWithSizeProof - (increaseObservationCardinalityNextOldWord σ I)).2] - norm_num - rw [hlen27, hlen29] - rw [show 256 ^ (27 : Nat) = 2 ^ 216 by norm_num [Nat.pow_add]] - rw [show 256 ^ (29 : Nat) = 2 ^ 232 by norm_num [Nat.pow_add]] - rw [show 256 ^ (2 : Nat) = 2 ^ 16 by norm_num] - rw [Nat.mod_eq_of_lt holdLt] - ring - exact (codeOwnerStorageWord I σ ⟨0⟩).val.isLt - -theorem increaseObservationCardinalityNextEvmUnlockedTrueSlotWord_eq - {evm : EVM.State} {σ : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ evm.accountMap) (hEnv : evm.executionEnv = I) : - increaseObservationCardinalityNextEvmUnlockedTrueSlotWord σ I = - slot0UnlockedTrueSlotWord evm := by - have hload := increaseObservationCardinalityNextStorageLoad_codeOwner_eq - (evm := evm) (σ := σ) (I := I) hAccounts hEnv - have hclearLt : - (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 240 + - (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 248 * 2 ^ 248 < - UInt256.size := by - rw [← natLandClearSlot0UnlockedByte - (codeOwnerStorageWord I σ ⟨0⟩).toNat (codeOwnerStorageWord I σ ⟨0⟩).val.isLt] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [UInt256.size]) - have htrueLt : - (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 240 + 2 ^ 240 + - (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 248 * 2 ^ 248 < - UInt256.size := by - let w := codeOwnerStorageWord I σ ⟨0⟩ - have hlow : w.toNat % 2 ^ 240 ≤ 2 ^ 240 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 248 < 2 ^ 8 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 248 * 2 ^ 8 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 248 ≤ 2 ^ 8 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 240 - 1) + 2 ^ 240 + (2 ^ 8 - 1) * 2 ^ 248 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - dsimp [w] at hlow hhigh - omega - apply u256_inj - rw [increaseObservationCardinalityNextEvmUnlockedTrueSlotWord, slot0UnlockedTrueSlotWord] - rw [hload] - rw [u256_lor_toNat, u256_land_toNat] - rw [slot0UnlockedClearMask_toNat] - rw [nat_land_comm] - rw [natLandClearSlot0UnlockedByte] - rw [Nat.mod_eq_of_lt hclearLt] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨240⟩).toNat = 2 ^ 240 by - native_decide] - rw [nat_lor_comm] - rw [nat_lor_packed_true_byte240] - rw [Nat.mod_eq_of_lt htrueLt] - exact (ulit_toNat' _ htrueLt).symm - exact (codeOwnerStorageWord I σ ⟨0⟩).val.isLt - -theorem increaseObservationCardinalityNextFinalNoGrowAccountMapEquiv - {evmOwner : EVM.State} {σOwnerEvm : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σOwnerEvm evmOwner.accountMap) - (hEnv : evmOwner.executionEnv = I) : - accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner σOwnerEvm ⟨0⟩ - (increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord σOwnerEvm I)) - ⟨0⟩ - (increaseObservationCardinalityNextEvmUnlockedTrueSlotWord - (sstoreAccountMap I.codeOwner σOwnerEvm ⟨0⟩ - (increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord σOwnerEvm I)) I)) - (slot0AfterUnlockState - (increaseObservationCardinalityNextAfterNoGrowObsNextState evmOwner I)).accountMap := by - have hfirstWord := increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord_eq - (evm := evmOwner) (σ := σOwnerEvm) (I := I) hAccounts hEnv - have hFirstAccounts : - accountMapEquiv - (sstoreAccountMap I.codeOwner σOwnerEvm ⟨0⟩ - (increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord σOwnerEvm I)) - (increaseObservationCardinalityNextAfterNoGrowObsNextState evmOwner I).accountMap := by - rw [hfirstWord] - simpa [increaseObservationCardinalityNextAfterNoGrowObsNextState, - storageStore_accountMap, hEnv] using - accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (increaseObservationCardinalityNextNoGrowSlotWord evmOwner I) hAccounts - have hFirstEnv : - (increaseObservationCardinalityNextAfterNoGrowObsNextState evmOwner I).executionEnv = I := by - simp [increaseObservationCardinalityNextAfterNoGrowObsNextState, - storageStore_executionEnv, hEnv] - have hsecondWord := increaseObservationCardinalityNextEvmUnlockedTrueSlotWord_eq - (evm := increaseObservationCardinalityNextAfterNoGrowObsNextState evmOwner I) - (σ := sstoreAccountMap I.codeOwner σOwnerEvm ⟨0⟩ - (increaseObservationCardinalityNextEvmNoGrowObsNextSlotWord σOwnerEvm I)) - (I := I) hFirstAccounts hFirstEnv - rw [hsecondWord] - simpa [slot0AfterUnlockState, storageStore_accountMap, hFirstEnv] using - accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (slot0UnlockedTrueSlotWord - (increaseObservationCardinalityNextAfterNoGrowObsNextState evmOwner I)) - hFirstAccounts - -theorem increaseObservationCardinalityNextStoreWithOldNew_old - (σ : AccountMap) (I : ExecutionEnv) : - (increaseObservationCardinalityNextStoreWithOldNew σ I).get? - "observationCardinalityNextOld" = - some (increaseObservationCardinalityNextOldValue σ I) := by - rw [increaseObservationCardinalityNextStoreWithOldNew] - rw [store_get_ne (increaseObservationCardinalityNextStoreWithOld σ I) - (increaseObservationCardinalityNextArgValue I) (by decide)] - rw [increaseObservationCardinalityNextStoreWithOld, store_get_self] - -theorem increaseObservationCardinalityNextStoreWithOld_param - (σ : AccountMap) (I : ExecutionEnv) : - (increaseObservationCardinalityNextStoreWithOld σ I).get? - "observationCardinalityNext" = - some (increaseObservationCardinalityNextArgValue I) := by - rw [increaseObservationCardinalityNextStoreWithOld] - rw [store_get_ne (increaseObservationCardinalityNextStore I) - (increaseObservationCardinalityNextOldValue σ I) (by decide)] - rw [increaseObservationCardinalityNextStore, store_get_self] - -theorem increaseObservationCardinalityNextStoreWithOldNew_new - (σ : AccountMap) (I : ExecutionEnv) : - (increaseObservationCardinalityNextStoreWithOldNew σ I).get? - "observationCardinalityNextNew" = - some (increaseObservationCardinalityNextArgValue I) := by - rw [increaseObservationCardinalityNextStoreWithOldNew, store_get_self] - -theorem increaseObservationCardinalityNextStoreWithOldNewNoGrow_new - (σ : AccountMap) (I : ExecutionEnv) : - (increaseObservationCardinalityNextStoreWithOldNewNoGrow σ I).get? - "observationCardinalityNextNew" = - some (increaseObservationCardinalityNextOldValue σ I) := by - rw [increaseObservationCardinalityNextStoreWithOldNewNoGrow, store_get_self] - -theorem evalExpr_increaseObservationCardinalityNext_oldStorage {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) - (howner : evm.executionEnv.codeOwner = I.codeOwner) : - evalExpr? (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } - evm (.storage (slot0F "observationCardinalityNext")) = - .ok (increaseObservationCardinalityNextOldValue evm.accountMap I) := by - rw [evalExpr_storage_scalar - (t := .int uint16Int) - (slot := slot0F "observationCardinalityNext") - (er := { base := "slot0", steps := [.field "observationCardinalityNext"] }) - (loc := increaseObservationCardinalityNextObservationCardinalityNextLoc) - (hbase := by simp [slot0F, increaseObservationCardinalityNextStore]) - (her := by - simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - uint16St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - increaseObservationCardinalityNextObservationCardinalityNextLoc, loc])] - simpa [increaseObservationCardinalityNextOldValue, increaseObservationCardinalityNextOldWord, - slot0ObservationCardinalityNextWord, slot0SlotWord, solcSlotWord, howner] using - slot0StorageLocLoad_observationCardinalityNext evm - -theorem evalExpr_increaseObservationCardinalityNext_param_withOld {v : PoolImmutables} - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStoreWithOld σ I } - evm (.var "observationCardinalityNext") = - .ok (increaseObservationCardinalityNextArgValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [increaseObservationCardinalityNextStoreWithOld_param] - -theorem evalExpr_increaseObservationCardinalityNext_old_withOldNew - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStoreWithOldNew σ I } - evm (.var "observationCardinalityNextOld") = - .ok (increaseObservationCardinalityNextOldValue σ I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [increaseObservationCardinalityNextStoreWithOldNew_old] - -theorem evalExpr_increaseObservationCardinalityNext_new_withOldNew - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStoreWithOldNew σ I } - evm (.var "observationCardinalityNextNew") = - .ok (increaseObservationCardinalityNextArgValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [increaseObservationCardinalityNextStoreWithOldNew_new] - -theorem evalExpr_increaseObservationCardinalityNext_new_withOldNewNoGrow - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, - locals := increaseObservationCardinalityNextStoreWithOldNewNoGrow σ I } - evm (.var "observationCardinalityNextNew") = - .ok (increaseObservationCardinalityNextOldValue σ I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [increaseObservationCardinalityNextStoreWithOldNewNoGrow_new] - -theorem assignStorageRef_increaseObservationCardinalityNext_noGrowLocal - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) : - assignStorageRef? (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStoreWithOldNew σ I } - evm .localVar (varRef "observationCardinalityNextNew") - (increaseObservationCardinalityNextOldValue σ I) = - .ok - ({ contract := contract v, - locals := increaseObservationCardinalityNextStoreWithOldNewNoGrow σ I }, - evm) := by - simp [assignStorageRef?, varRef, updateLocalPath?, EvalResult.bind, bind, pure, - increaseObservationCardinalityNextStoreWithOldNewNoGrow] - -theorem assignStorageRef_increaseObservationCardinalityNext_unlocked_true - {v : PoolImmutables} (evm : EVM.State) (L : Store) - (hbase : "slot0" ∉ L) : - assignStorageRef? (config v) - { contract := contract v, locals := L } - evm .storage (slot0F "unlocked") (.bool true) = - .ok ({ contract := contract v, locals := L }, slot0AfterUnlockState evm) := by - apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "unlocked"] }) - (ty := .elem .bool) - (loc := increaseObservationCardinalityNextUnlockedLoc) - · simpa [slot0F] using hbase - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, boolSt] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - increaseObservationCardinalityNextUnlockedLoc, loc] - · trivial - · simpa [increaseObservationCardinalityNextUnlockedLoc, slot0UnlockedLoc] using - storageLocStore_slot0Unlocked_true evm - -theorem storageLocStore_increaseObservationCardinalityNext_noGrowObsNext - (evm : EVM.State) (I : ExecutionEnv) : - storageLocStore evm increaseObservationCardinalityNextObservationCardinalityNextLoc - (increaseObservationCardinalityNextOldValue evm.accountMap I) = - some (increaseObservationCardinalityNextAfterNoGrowObsNextState evm I) := by - unfold storageLocStore storageLocWriteWord - increaseObservationCardinalityNextObservationCardinalityNextLoc loc - increaseObservationCardinalityNextAfterNoGrowObsNextState - increaseObservationCardinalityNextNoGrowSlotWord - increaseObservationCardinalityNextOldValue - simp only [valueToWord, bind, Option.bind] - rw [show EVM.wordOfInt (Int.ofNat (increaseObservationCardinalityNextOldWord evm.accountMap I).toNat) = - increaseObservationCardinalityNextOldWord evm.accountMap I by - exact wordOfInt_ofNat_toNat _] - apply congrArg some - apply congrArg (fun w : UInt256 => - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ w) - apply u256_inj - rw [ulit_toNat'] - · rfl - · let bs := - ((List.take 27 - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).1 ++ - List.take 2 - (EVM.Word.toBytesLEWithSizeProof - (increaseObservationCardinalityNextOldWord evm.accountMap I)).1) ++ - List.drop (27 + 2) - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).1) - have hlen : bs.length = 32 := by - simp [bs, List.length_take, List.length_drop, - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).2, - (EVM.Word.toBytesLEWithSizeProof - (increaseObservationCardinalityNextOldWord evm.accountMap I)).2] - apply lt_of_lt_of_le (b := 2 ^ (8 * bs.length)) - · simpa [bs] using (EVM.fromBytes'_le (bs := bs)) - · rw [hlen] - norm_num [UInt256.size] - -theorem assignStorageRef_increaseObservationCardinalityNext_noGrowObsNext - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) : - assignStorageRef? (config v) - { contract := contract v, - locals := increaseObservationCardinalityNextStoreWithOldNewNoGrow evm.accountMap I } - evm .storage (slot0F "observationCardinalityNext") - (increaseObservationCardinalityNextOldValue evm.accountMap I) = - .ok - ({ contract := contract v, - locals := increaseObservationCardinalityNextStoreWithOldNewNoGrow evm.accountMap I }, - increaseObservationCardinalityNextAfterNoGrowObsNextState evm I) := by - apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "observationCardinalityNext"] }) - (ty := .elem (.int uint16Int)) - (loc := increaseObservationCardinalityNextObservationCardinalityNextLoc) - · simp [slot0F, increaseObservationCardinalityNextStoreWithOldNewNoGrow, - increaseObservationCardinalityNextStoreWithOldNew, - increaseObservationCardinalityNextStoreWithOld, - increaseObservationCardinalityNextStore] - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, uint16St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - increaseObservationCardinalityNextObservationCardinalityNextLoc, loc] - · trivial - · exact storageLocStore_increaseObservationCardinalityNext_noGrowObsNext evm I - -theorem evalExpr_increaseObservationCardinalityNext_oldGtZero_false {v : PoolImmutables} - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (hzero : increaseObservationCardinalityNextOldWord σ I = ⟨0⟩) : - evalExpr? (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStoreWithOldNew σ I } - evm (gtE (.var "observationCardinalityNextOld") (.intLit 0)) = - .ok (.bool false) := by - simp only [gtE, evalExpr?, evalExpr_increaseObservationCardinalityNext_old_withOldNew, - EvalResult.bind, bind, pure, evalBinaryOp?] - simp [hzero] - -theorem evalExpr_increaseObservationCardinalityNext_oldGtZero_true {v : PoolImmutables} - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (hnz : increaseObservationCardinalityNextOldWord σ I ≠ ⟨0⟩) : - evalExpr? (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStoreWithOldNew σ I } - evm (gtE (.var "observationCardinalityNextOld") (.intLit 0)) = - .ok (.bool true) := by - simp only [gtE, evalExpr?, evalExpr_increaseObservationCardinalityNext_old_withOldNew, - EvalResult.bind, bind, pure, evalBinaryOp?] - have hpos : 0 < (increaseObservationCardinalityNextOldWord σ I).toNat := by - exact Nat.pos_of_ne_zero (by - intro hz - apply hnz - apply u256_inj - simpa using hz) - simpa [increaseObservationCardinalityNextOldValue] using hpos - -theorem evalExpr_increaseObservationCardinalityNext_newLeOld_true {v : PoolImmutables} - (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (hnewLe : UInt256.gt (increaseObservationCardinalityNextArgWord I) - (increaseObservationCardinalityNextOldWord σ I) = ⟨0⟩) : - evalExpr? (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStoreWithOldNew σ I } - evm (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) = - .ok (.bool true) := by - simp only [leE, evalExpr?, evalExpr_increaseObservationCardinalityNext_new_withOldNew, - evalExpr_increaseObservationCardinalityNext_old_withOldNew, EvalResult.bind, bind, - evalBinaryOp?] - have hleNat : - (increaseObservationCardinalityNextArgWord I).toNat ≤ - (increaseObservationCardinalityNextOldWord σ I).toNat := by - by_contra hnot - have hlt : - (increaseObservationCardinalityNextOldWord σ I).toNat < - (increaseObservationCardinalityNextArgWord I).toNat := by - omega - have hgt : UInt256.gt (increaseObservationCardinalityNextArgWord I) - (increaseObservationCardinalityNextOldWord σ I) = ⟨1⟩ := by - exact ugt_one hlt - rw [hgt] at hnewLe - exact (by native_decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) hnewLe - simpa [increaseObservationCardinalityNextArgValue, - increaseObservationCardinalityNextOldValue] using hleNat - -theorem uniswapV3PoolIncreaseObservationCardinalityNextSourceNoGrowPrefix - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} - (howner : evm.executionEnv.codeOwner = I.codeOwner) - (holdNonzero : increaseObservationCardinalityNextOldWord evm.accountMap I ≠ ⟨0⟩) - (hnewLe : UInt256.gt (increaseObservationCardinalityNextArgWord I) - (increaseObservationCardinalityNextOldWord evm.accountMap I) = ⟨0⟩) : - ExecBlock (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } evm - [ .letDecl "observationCardinalityNextOld" (some uint16) - (.storage (slot0F "observationCardinalityNext")), - .letDecl "observationCardinalityNextNew" (some uint16) - (.var "observationCardinalityNext"), - .require (gtE (.var "observationCardinalityNextOld") (.intLit 0)), - Stmt.ite (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) - [ .assign .localVar (varRef "observationCardinalityNextNew") - (.var "observationCardinalityNextOld") ] - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ] ] - (.ok - { contract := contract v, - locals := increaseObservationCardinalityNextStoreWithOldNewNoGrow evm.accountMap I } - evm) := by - refine ExecBlock.consNormal - (ExecStmt.letDecl - (evalExpr_increaseObservationCardinalityNext_oldStorage (v := v) evm I howner)) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl - (evalExpr_increaseObservationCardinalityNext_param_withOld - (v := v) evm evm.accountMap I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_increaseObservationCardinalityNext_oldGtZero_true - (v := v) evm evm.accountMap I holdNonzero)) ?_ - refine ExecBlock.consNormal - (ExecStmt.iteTrue - (evalExpr_increaseObservationCardinalityNext_newLeOld_true - (v := v) evm evm.accountMap I hnewLe) ?_) ExecBlock.nil - exact ExecBlock.consNormal - (ExecStmt.assign - (evalExpr_increaseObservationCardinalityNext_old_withOldNew - (v := v) evm evm.accountMap I) - (assignStorageRef_increaseObservationCardinalityNext_noGrowLocal - (v := v) evm evm.accountMap I)) - ExecBlock.nil - -theorem uniswapV3PoolIncreaseObservationCardinalityNextSourceNoGrowReturns - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} - (howner : evm.executionEnv.codeOwner = I.codeOwner) - (holdNonzero : increaseObservationCardinalityNextOldWord evm.accountMap I ≠ ⟨0⟩) - (hnewLe : UInt256.gt (increaseObservationCardinalityNextArgWord I) - (increaseObservationCardinalityNextOldWord evm.accountMap I) = ⟨0⟩) : - ExecBlock (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } evm - [ .letDecl "observationCardinalityNextOld" (some uint16) - (.storage (slot0F "observationCardinalityNext")), - .letDecl "observationCardinalityNextNew" (some uint16) - (.var "observationCardinalityNext"), - .require (gtE (.var "observationCardinalityNextOld") (.intLit 0)), - Stmt.ite (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) - [ .assign .localVar (varRef "observationCardinalityNextNew") - (.var "observationCardinalityNextOld") ] - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ], - .assign .storage (slot0F "observationCardinalityNext") - (.var "observationCardinalityNextNew"), - .assign .storage (slot0F "unlocked") (.boolLit true) ] - (.ok - { contract := contract v, - locals := increaseObservationCardinalityNextStoreWithOldNewNoGrow evm.accountMap I } - (slot0AfterUnlockState - (increaseObservationCardinalityNextAfterNoGrowObsNextState evm I))) := by - have hprefix := - uniswapV3PoolIncreaseObservationCardinalityNextSourceNoGrowPrefix - (v := v) (evm := evm) (I := I) howner holdNonzero hnewLe - have htail : - ExecBlock (config v) - { contract := contract v, - locals := increaseObservationCardinalityNextStoreWithOldNewNoGrow evm.accountMap I } - evm - [ .assign .storage (slot0F "observationCardinalityNext") - (.var "observationCardinalityNextNew"), - .assign .storage (slot0F "unlocked") (.boolLit true) ] - (.ok - { contract := contract v, - locals := increaseObservationCardinalityNextStoreWithOldNewNoGrow evm.accountMap I } - (slot0AfterUnlockState - (increaseObservationCardinalityNextAfterNoGrowObsNextState evm I))) := by - refine ExecBlock.consNormal - (ExecStmt.assign - (evalExpr_increaseObservationCardinalityNext_new_withOldNewNoGrow - (v := v) evm evm.accountMap I) - (assignStorageRef_increaseObservationCardinalityNext_noGrowObsNext - (v := v) evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) - (assignStorageRef_increaseObservationCardinalityNext_unlocked_true - (v := v) (increaseObservationCardinalityNextAfterNoGrowObsNextState evm I) - (increaseObservationCardinalityNextStoreWithOldNewNoGrow evm.accountMap I) - (by - simp [increaseObservationCardinalityNextStoreWithOldNewNoGrow, - increaseObservationCardinalityNextStoreWithOldNew, - increaseObservationCardinalityNextStoreWithOld, - increaseObservationCardinalityNextStore]))) - ExecBlock.nil - simpa using execBlock_append hprefix htail - -theorem uniswapV3PoolIncreaseObservationCardinalityNextSourceOldZeroReverts - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} - (howner : evm.executionEnv.codeOwner = I.codeOwner) - (hzero : increaseObservationCardinalityNextOldWord evm.accountMap I = ⟨0⟩) : - ExecBlock (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } evm - [ .letDecl "observationCardinalityNextOld" (some uint16) - (.storage (slot0F "observationCardinalityNext")), - .letDecl "observationCardinalityNextNew" (some uint16) - (.var "observationCardinalityNext"), - .require (gtE (.var "observationCardinalityNextOld") (.intLit 0)), - Stmt.ite (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) - [ .assign .localVar (varRef "observationCardinalityNextNew") - (.var "observationCardinalityNextOld") ] - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ], - .assign .storage (slot0F "observationCardinalityNext") - (.var "observationCardinalityNextNew"), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted := by - refine ExecBlock.consNormal - (ExecStmt.letDecl - (evalExpr_increaseObservationCardinalityNext_oldStorage (v := v) evm I howner)) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl - (evalExpr_increaseObservationCardinalityNext_param_withOld - (v := v) evm evm.accountMap I)) ?_ - exact ExecBlock.consRevert - (ExecStmt.requireFalse - (evalExpr_increaseObservationCardinalityNext_oldGtZero_false - (v := v) evm evm.accountMap I hzero)) - -theorem uniswapV3PoolIncreaseObservationCardinalityNextSourceLockedReverts - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hlocked : increaseObservationCardinalityNextUnlockedByte σ I = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (increaseObservationCardinalityNextStore I) - (increaseobservationcardinalitynextTransition v).body .reverted := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (increaseObservationCardinalityNextStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .eq (.env .this) (addrLit v.original)), - .letDecl "observationCardinalityNextOld" (some uint16) - (.storage (slot0F "observationCardinalityNext")), - .letDecl "observationCardinalityNextNew" (some uint16) - (.var "observationCardinalityNext"), - .require (gtE (.var "observationCardinalityNextOld") (.intLit 0)), - Stmt.ite (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) - [ .assign .localVar (varRef "observationCardinalityNextNew") - (.var "observationCardinalityNextOld") ] - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ], - .assign .storage (slot0F "observationCardinalityNext") - (.var "observationCardinalityNextNew"), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted - exact ExecFuncBody.execBlockRevert <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true (by - simp [initState, hwv]))) <| - ExecBlock.consRevert (ExecStmt.requireFalse (by - rw [uniswapV3PoolIncreaseObservationCardinalityNextEvalUnlocked] - exact congrArg EvalResult.ok - (increaseObservationCardinalityNextUnlockedByte_wordToElem_false hlocked))) - -theorem uniswapV3PoolIncreaseObservationCardinalityNextSourceLockPrefixExact - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : increaseObservationCardinalityNextUnlockedByte σ I ≠ ⟨0⟩) : - ExecBlock (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl σ σ₀ g A I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false) ] - (.ok { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ I))) := by - refine nonpayableRequireAssignStorageBlock - (cfg := config v) - (solm := { contract := contract v, locals := increaseObservationCardinalityNextStore I }) - (evm := initState cA gh bl σ σ₀ g A I) - (evm' := Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ I)) - (guard := .storage (slot0F "unlocked")) (rhs := .boolLit false) - (ref := slot0F "unlocked") (value := .bool false) - (by simp [initState, hwv]) ?_ ?_ ?_ - · rw [uniswapV3PoolIncreaseObservationCardinalityNextEvalUnlocked] - exact congrArg EvalResult.ok - (increaseObservationCardinalityNextUnlockedByte_wordToElem_true hunlocked) - · simp [evalExpr?, pure] - · apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "unlocked"] }) - (ty := .elem .bool) - (loc := increaseObservationCardinalityNextUnlockedLoc) - · simp [slot0F, increaseObservationCardinalityNextStore] - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, boolSt] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - increaseObservationCardinalityNextUnlockedLoc, loc] - · trivial - · simpa [initState, increaseObservationCardinalityNextLockedSlotWord, solcSlotWord, - increaseObservationCardinalityNextUnlockedLoc, slot0UnlockedLoc, - increaseObservationCardinalityNextUnlockedClearMask, slot0UnlockedClearMask, - u256_land_comm] using - storageLocStore_slot0Unlocked_false (initState cA gh bl σ σ₀ g A I) - -theorem uniswapV3PoolIncreaseObservationCardinalityNextDecodeOk {v : PoolImmutables} - {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - ((increaseobservationcardinalitynextTransition v).params.map Param.name) - (transitionSignature (increaseobservationcardinalitynextTransition v)).paramTypes - I.calldata = some (increaseObservationCardinalityNextStore I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake4 : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have hword4 : ABI.bytesToWord ((I.calldata.toList.drop 4).take 32) = - calldataWord I.calldata 4 := - decode_word_at_eq I.calldata 4 (by omega) (by norm_num) - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := (increaseobservationcardinalitynextTransition v).params.map Param.name) - (types := (transitionSignature (increaseobservationcardinalitynextTransition v)).paramTypes) - (cd := I.calldata)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint16] - (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["observationCardinalityNext"] values ∅ - | none => none) = some (increaseObservationCardinalityNextStore I) - rw [decodeScalarWordsWithMode_uint16_ok (bytes := I.calldata.toList.drop 4) htake4] - simp [decodeCalldata.insertValues, increaseObservationCardinalityNextStore, - increaseObservationCardinalityNextArgValue, increaseObservationCardinalityNextArgWord] - rw [hword4] - · simp [increaseobservationcardinalitynextTransition, transitionSignature, - isABIScalarWordType, uint16] - -theorem uniswapV3PoolIncreaseObservationCardinalityNextDecodeShort {v : PoolImmutables} - {I : ExecutionEnv} (hshort : I.calldata.size < 36) : - decodeCalldataWithMode (config v).abiDecodeMode - ((increaseobservationcardinalitynextTransition v).params.map Param.name) - (transitionSignature (increaseobservationcardinalitynextTransition v)).paramTypes - I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := (increaseobservationcardinalitynextTransition v).params.map Param.name) - (types := (transitionSignature (increaseobservationcardinalitynextTransition v)).paramTypes) - (cd := I.calldata)] - · by_cases hsz4 : I.calldata.size < 4 - · rw [if_pos (by rw [htlen]; omega : I.calldata.toList.length < 4)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint16] - (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["observationCardinalityNext"] values ∅ - | none => none) = none - rw [decodeScalarWordsWithMode_uint16_none_short - (bytes := I.calldata.toList.drop 4) (by rw [List.length_drop, htlen]; omega)] - · simp [increaseobservationcardinalitynextTransition, transitionSignature, - isABIScalarWordType, uint16] - -theorem uniswapV3PoolDispatch_increaseObservationCardinalityNext {v : PoolImmutables} - {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 5 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some (increaseobservationcardinalitynextTransition v) := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, - factoryTransition v, feeTransition v, feegrowthglobal0X128Transition, - feegrowthglobal1X128Transition, flashTransition v]) - (post := [initializeTransition, liquidityTransition, maxliquiditypertickTransition v, - mintTransition v, observationsTransition, observeTransition v, positionsTransition, - protocolfeesTransition, setfeeprotocolTransition v, slot0Transition, - snapshotcumulativesinsideTransition v, swapTransition v, tickbitmapTransition, - tickspacingTransition v, ticksTransition, token0Transition v, token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 5) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 5) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 5) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 5) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 5) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 5) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 5) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 5) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hsel - -theorem uniswapV3PoolIncreaseObservationCardinalityNextReachEntry {v : PoolImmutables} - {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 5 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨824⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 5 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0x32 0x14 0x8f 0x67 - (uniswapV3PoolSelNat 5) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h239 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨239⟩) hpatch h32 hgt32 - have hgt239 : UInt256.gt (armSelNat code ⟨239⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h348 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨348⟩) hpatch h239 hgt239 - have hgt348 : UInt256.gt (armSelNat code ⟨348⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h359 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨359⟩) hpatch h348 hgt348 - have hmiss3 : (uniswapV3PoolSelBytes 3 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h370 := uniswapV3PoolSelectorArmMissToOf (i := 3) (next := ⟨370⟩) - hpatch hsz hmiss3 h359 - have hmiss4 : (uniswapV3PoolSelBytes 4 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h381 := uniswapV3PoolSelectorArmMissToOf (i := 4) (next := ⟨381⟩) - hpatch hsz hmiss4 h370 - have h824 := uniswapV3PoolSelectorArmHitTo (i := 5) (target := ⟨824⟩) - hpatch hsz hsel h381 - exact ⟨_, _, h824⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrow.lean b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrow.lean deleted file mode 100644 index 51fa3f29..00000000 --- a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrow.lean +++ /dev/null @@ -1,1697 +0,0 @@ -import Benchmarks.UniswapV3Pool.IncreaseObservationCardinalityNextBase - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest16053 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16053⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest16115 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16115⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest16137 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16137⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest16139 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16139⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest16207 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16207⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest5521 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨5521⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest5630 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨5630⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest857 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨857⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched16053 - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16053⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest16053 - -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched16115 - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16115⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest16115 - -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched16137 - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16137⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest16137 - -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched16139 - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16139⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest16139 - -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched16207 - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨16207⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest16207 - -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched5521 - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨5521⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest5521 - -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched5630 - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨5630⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest5630 - -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched857 - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨857⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchPreservesJumpDest857 - -abbrev increaseObservationCardinalityNextEvmObsNextSlotWord - (σ : AccountMap) (I : ExecutionEnv) (obsNext : UInt256) : UInt256 := - UInt256.lor - (UInt256.land - (codeOwnerStorageWord I σ ⟨0⟩) - (UInt256.lnot (UInt256.shiftLeft (⟨65535⟩ : UInt256) ⟨216⟩))) - (UInt256.mul - (UInt256.land obsNext (⟨65535⟩ : UInt256)) - (UInt256.shiftLeft ⟨1⟩ ⟨216⟩)) - -abbrev increaseObservationCardinalityNextGrowObservationSlot (i : UInt256) : UInt256 := - UInt256.land (⟨65535⟩ : UInt256) i + ⟨8⟩ - -abbrev increaseObservationCardinalityNextGrowObservationWord - (σ : AccountMap) (I : ExecutionEnv) (i : UInt256) : UInt256 := - UInt256.lor - (UInt256.land (⟨4294967295⟩ : UInt256) (⟨1⟩ : UInt256)) - (UInt256.land - (UInt256.lnot (⟨4294967295⟩ : UInt256)) - (codeOwnerStorageWord I σ (increaseObservationCardinalityNextGrowObservationSlot i))) - -abbrev increaseObservationCardinalityNextEventTopic : UInt256 := - ⟨77928370965229736361680894451701302466328135445772690950750693029892640871002⟩ - -def increaseObservationCardinalityNextEventMem0 (old : UInt256) : ByteArray := - (UInt256.toByteArray (UInt256.land old (⟨65535⟩ : UInt256))).write 0 solcFreePtrMem 128 32 - -def increaseObservationCardinalityNextEventMem (old obsNext : UInt256) : ByteArray := - (UInt256.toByteArray (UInt256.land obsNext (⟨65535⟩ : UInt256))).write 0 - (increaseObservationCardinalityNextEventMem0 old) 160 32 - -theorem increaseObservationCardinalityNextEventMem0_size (old : UInt256) : - (increaseObservationCardinalityNextEventMem0 old).size = 160 := by - unfold increaseObservationCardinalityNextEventMem0 - rw [toByteArray_write_eq _ _ _ (by rw [solcFreePtrMem_size]; omega) - (by rw [solcFreePtrMem_size]; exact lt_usize _ (by norm_num)), - ByteArray.size_append, ByteArray.size_append, solcFreePtrMem_size, ByteArray_zeroes_size, - show (USize.ofNat (128 - 96)).toNat = 32 from by - exact USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num)), - toByteArray_size] - -theorem increaseObservationCardinalityNextEventMem_size (old obsNext : UInt256) : - (increaseObservationCardinalityNextEventMem old obsNext).size = 192 := by - unfold increaseObservationCardinalityNextEventMem - rw [toByteArray_write_eq _ _ _ (by rw [increaseObservationCardinalityNextEventMem0_size]) - (by rw [increaseObservationCardinalityNextEventMem0_size]; exact lt_usize _ (by norm_num)), - ByteArray.size_append, ByteArray.size_append, increaseObservationCardinalityNextEventMem0_size, - ByteArray_zeroes_size, - show (USize.ofNat (160 - 160)).toNat = 0 from by - exact USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num)), - toByteArray_size] - -theorem increaseObservationCardinalityNextEventMem_read64 (old obsNext : UInt256) : - (increaseObservationCardinalityNextEventMem old obsNext).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - unfold increaseObservationCardinalityNextEventMem - rw [write32_read_below _ _ 160 64 (by rw [toByteArray_size]) - (by rw [increaseObservationCardinalityNextEventMem0_size]) (by omega)] - unfold increaseObservationCardinalityNextEventMem0 - rw [toByteArray_write_read_below_of_gap _ _ 128 64 - (by rw [solcFreePtrMem_size]) (by omega) - (by rw [solcFreePtrMem_size]; exact lt_usize _ (by norm_num))] - exact solcFreePtrMem_read64 - -theorem increaseObservationCardinalityNextEventMem_mload64 (old obsNext : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (increaseObservationCardinalityNextEventMem old obsNext).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 6 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((increaseObservationCardinalityNextEventMem old obsNext).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨128⟩ := - mloadFreePtrValue (by rw [increaseObservationCardinalityNextEventMem_size]; decide) - (by decide) (increaseObservationCardinalityNextEventMem_read64 old obsNext) - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowBodyPatchDisjoint - {v : PoolImmutables} {pc : UInt256} (hlo : 5404 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 6603) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl <;> - omega - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchDisjoint - {v : PoolImmutables} {pc : UInt256} (hlo : 16053 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 19295) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl <;> - omega - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowPrefix - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5493⟩ - (increaseObservationCardinalityNextArgWord ee :: ⟨857⟩ :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (holdNonzero : increaseObservationCardinalityNextOldWord σ ee ≠ ⟨0⟩) - (hnewGt : UInt256.gt (increaseObservationCardinalityNextArgWord ee) - (increaseObservationCardinalityNextOldWord σ ee) ≠ ⟨0⟩) - (hov : R.length + 14 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨16137⟩ - (⟨0⟩ :: increaseObservationCardinalityNextArgWord ee :: - increaseObservationCardinalityNextOldWord σ ee :: ⟨8⟩ :: ⟨5521⟩ :: ⟨0⟩ :: - increaseObservationCardinalityNextOldWord σ ee :: - increaseObservationCardinalityNextArgWord ee :: ⟨857⟩ :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k' C' := by - have hdecodeBody {pc : UInt256} (hlo : 5404 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 6603) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 6603 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowBodyPatchDisjoint hlo hhi)] - have hdecodeGrow {pc : UInt256} (hlo : 16053 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 19295 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchDisjoint hlo hhi)] - have hd5493 : decode code ⟨5493⟩ = some (.JUMPDEST, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5494 : decode code ⟨5494⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5496 : decode code ⟨5496⟩ = some (.DUP1, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5497 : decode code ⟨5497⟩ = some (.SLOAD, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5498 : decode code ⟨5498⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5500 : decode code ⟨5500⟩ = some (.Push .PUSH1, some (⟨216⟩, 1)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5502 : decode code ⟨5502⟩ = some (.SHL, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5503 : decode code ⟨5503⟩ = some (.SWAP1, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5504 : decode code ⟨5504⟩ = some (.DIV, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5505 : decode code ⟨5505⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5508 : decode code ⟨5508⟩ = some (.AND, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5509 : decode code ⟨5509⟩ = some (.SWAP1, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5510 : decode code ⟨5510⟩ = some (.Push .PUSH2, some (⟨5521⟩, 2)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5513 : decode code ⟨5513⟩ = some (.Push .PUSH1, some (⟨8⟩, 1)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5515 : decode code ⟨5515⟩ = some (.DUP4, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5516 : decode code ⟨5516⟩ = some (.DUP6, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5517 : decode code ⟨5517⟩ = some (.Push .PUSH2, some (⟨16053⟩, 2)) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5520 : decode code ⟨5520⟩ = some (.JUMP, .none) := by rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd16053 : decode code ⟨16053⟩ = some (.JUMPDEST, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16054 : decode code ⟨16054⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16056 : decode code ⟨16056⟩ = some (.DUP1, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16057 : decode code ⟨16057⟩ = some (.DUP4, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16058 : decode code ⟨16058⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16061 : decode code ⟨16061⟩ = some (.AND, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16062 : decode code ⟨16062⟩ = some (.GT, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16063 : decode code ⟨16063⟩ = some (.Push .PUSH2, some (⟨16115⟩, 2)) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16066 : decode code ⟨16066⟩ = some (.JUMPI, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16115 : decode code ⟨16115⟩ = some (.JUMPDEST, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16116 : decode code ⟨16116⟩ = some (.DUP3, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16117 : decode code ⟨16117⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16120 : decode code ⟨16120⟩ = some (.AND, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16121 : decode code ⟨16121⟩ = some (.DUP3, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16122 : decode code ⟨16122⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16125 : decode code ⟨16125⟩ = some (.AND, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16126 : decode code ⟨16126⟩ = some (.GT, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16127 : decode code ⟨16127⟩ = some (.Push .PUSH2, some (⟨16137⟩, 2)) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16130 : decode code ⟨16130⟩ = some (.JUMPI, .none) := by rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hshift : - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨216⟩ = slot0ShiftBytes 27 := by - native_decide - have hmask : increaseObservationCardinalityNextUint16Mask = slot0Uint16Mask := by - native_decide - have holdCleanL : - UInt256.land slot0Uint16Mask (increaseObservationCardinalityNextOldWord σ ee) = - increaseObservationCardinalityNextOldWord σ ee := by - exact slot0Uint16Mask_clean_left - (slot0Uint16Mask_bound (UInt256.div (slot0SlotWord σ ee) (slot0ShiftBytes 27))) - have holdCleanR : - UInt256.land (increaseObservationCardinalityNextOldWord σ ee) slot0Uint16Mask = - increaseObservationCardinalityNextOldWord σ ee := by - rw [u256_land_comm, holdCleanL] - have hnewCanon : - (increaseObservationCardinalityNextArgWord ee).toNat < EVM.twoPow 16 := by - simpa [increaseObservationCardinalityNextArgWord, hmask] using - slot0Uint16Mask_bound (calldataWord ee.calldata 4) - have hnewCleanL : - UInt256.land slot0Uint16Mask (increaseObservationCardinalityNextArgWord ee) = - increaseObservationCardinalityNextArgWord ee := by - exact slot0Uint16Mask_clean_left hnewCanon - have hnewCleanR : - UInt256.land (increaseObservationCardinalityNextArgWord ee) slot0Uint16Mask = - increaseObservationCardinalityNextArgWord ee := by - rw [u256_land_comm, hnewCleanL] - have holdInner : - UInt256.land slot0Uint16Mask - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27)) = - increaseObservationCardinalityNextOldWord σ ee := by - rw [increaseObservationCardinalityNextOldWord, slot0ObservationCardinalityNextWord, - slot0SlotWord, u256_land_comm] - have hmaskedOld : - UInt256.land slot0Uint16Mask - (UInt256.land slot0Uint16Mask - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27))) = - increaseObservationCardinalityNextOldWord σ ee := by - rw [holdInner, holdCleanL] - have holdRaw : - UInt256.land (⟨65535⟩ : UInt256) - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27)) = - increaseObservationCardinalityNextOldWord σ ee := by - simpa [slot0Uint16Mask] using holdInner - have hgtMaskedOldZero : - UInt256.gt - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27)))) - ⟨0⟩ ≠ - ⟨0⟩ := by - have hraw : - UInt256.land (⟨65535⟩ : UInt256) - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27))) = - increaseObservationCardinalityNextOldWord σ ee := by - simpa [slot0Uint16Mask] using hmaskedOld - have holdPos : 0 < (increaseObservationCardinalityNextOldWord σ ee).toNat := by - exact Nat.pos_of_ne_zero (by - intro hz - apply holdNonzero - apply u256_inj - simpa using hz) - have hgtOne : - UInt256.gt (increaseObservationCardinalityNextOldWord σ ee) ⟨0⟩ = ⟨1⟩ := by - exact ugt_one (by simpa using holdPos) - rw [hraw, hgtOne] - native_decide - have hnewGtRaw : - UInt256.gt - (UInt256.land (⟨65535⟩ : UInt256) (increaseObservationCardinalityNextArgWord ee)) - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27)))) ≠ - ⟨0⟩ := by - have hrawOld : - UInt256.land (⟨65535⟩ : UInt256) - (UInt256.land (⟨65535⟩ : UInt256) - (UInt256.div (solcSlotWord σ ee ⟨0⟩) (slot0ShiftBytes 27))) = - increaseObservationCardinalityNextOldWord σ ee := by - simpa [slot0Uint16Mask] using hmaskedOld - have hrawNew : - UInt256.land (⟨65535⟩ : UInt256) (increaseObservationCardinalityNextArgWord ee) = - increaseObservationCardinalityNextArgWord ee := by - simpa [slot0Uint16Mask] using hnewCleanL - rw [hrawNew, hrawOld] - exact hnewGt - have rd5494 := by - simpa using h.jumpdest hd5493 (by evm_ov) - have rd5496 := by - simpa using rd5494.push1 ⟨0⟩ hd5494 (by evm_ov) - have rd5497 := by - simpa using rd5496.dup1 hd5496 (by evm_ov) - obtain ⟨_, _, rd5498₀⟩ := rd5497.sload hd5497 (by evm_ov) - have rd5498 := by - simpa [solcSlotWord] using rd5498₀ - have rd5500 := by - simpa using rd5498.push1 ⟨1⟩ hd5498 (by evm_ov) - have rd5502 := by - simpa using rd5500.push1 ⟨216⟩ hd5500 (by evm_ov) - have rd5503 := by - simpa using rd5502.shl hd5502 (by evm_ov) - have rd5504 := by - simpa using rd5503.swap1 hd5503 (by evm_ov) - have rd5505 := by - simpa [hshift] using rd5504.div hd5504 (by evm_ov) - have rd5508 := by - simpa [increaseObservationCardinalityNextUint16Mask, hmask, - increaseObservationCardinalityNextOldWord, slot0ObservationCardinalityNextWord, - slot0SlotWord, solcSlotWord] using rd5505.push2 ⟨65535⟩ hd5505 (by evm_ov) - have rd5509 := by - simpa [increaseObservationCardinalityNextOldWord, slot0ObservationCardinalityNextWord, - slot0SlotWord, solcSlotWord, hmask] using rd5508.and hd5508 (by - simp only [List.length_cons] - omega) - have rd5510 := by - simpa using rd5509.swap1 hd5509 (by evm_ov) - have rd5513 := by - simpa using rd5510.push2 ⟨5521⟩ hd5510 (by - simp only [List.length_cons] - omega) - have rd5515 := by - simpa using rd5513.push1 ⟨8⟩ hd5513 (by - simp only [List.length_cons] - omega) - have rd5516 := by - simpa using rd5515.dup4 hd5515 (by - simp only [List.length_cons] - omega) - have rd5517 := by - simpa using rd5516.dup6 hd5516 (by - simp only [List.length_cons] - omega) - have rd5520 := by - simpa using rd5517.push2 ⟨16053⟩ hd5517 (by - simp only [List.length_cons] - omega) - have rd16053 := rd5520.jump hd5520 - (uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched16053 hpatch) - (by simp only [List.length_cons]; omega) - have rd16054 := by - simpa using rd16053.jumpdest hd16053 (by - simp only [List.length_cons] - omega) - have rd16056 := by - simpa using rd16054.push1 ⟨0⟩ hd16054 (by - simp only [List.length_cons] - omega) - have rd16057 := by - simpa using rd16056.dup1 hd16056 (by - simp only [List.length_cons] - omega) - have rd16058 := by - simpa using rd16057.dup4 hd16057 (by - simp only [List.length_cons] - omega) - have rd16061 := by - simpa [hmask, holdCleanL, holdCleanR] using rd16058.push2 ⟨65535⟩ hd16058 (by - simp only [List.length_cons] - omega) - have rd16062 := by - simpa [hmask, holdCleanL, holdCleanR] using rd16061.and hd16061 (by - simp only [List.length_cons] - omega) - have rd16063 := by - simpa [hmask, solcSlotWord, hmaskedOld] using rd16062.gt hd16062 (by - simp only [List.length_cons] - omega) - have rd16066 := by - simpa using rd16063.push2 ⟨16115⟩ hd16063 (by - simp only [List.length_cons] - omega) - have rd16115 := rd16066.jumpiT hd16066 (by - simpa [solcSlotWord] using hgtMaskedOldZero) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched16115 hpatch) - (by simp only [List.length_cons]; omega) - have rd16116 := by - simpa using rd16115.jumpdest hd16115 (by - simp only [List.length_cons] - omega) - have rd16117 := by - simpa using rd16116.dup3 hd16116 (by - simp only [List.length_cons] - omega) - have rd16120 := by - simpa using rd16117.push2 ⟨65535⟩ hd16117 (by - simp only [List.length_cons] - omega) - have rd16121 := by - simpa [hmask, holdCleanL, holdCleanR] using rd16120.and hd16120 (by - simp only [List.length_cons] - omega) - have rd16122 := by - simpa using rd16121.dup3 hd16121 (by - simp only [List.length_cons] - omega) - have rd16125 := by - simpa using rd16122.push2 ⟨65535⟩ hd16122 (by - simp only [List.length_cons] - omega) - have rd16126 := by - simpa [hmask, hnewCleanL, hnewCleanR] using rd16125.and hd16125 (by - simp only [List.length_cons] - omega) - have rd16127 := by - simpa using rd16126.gt hd16126 (by - simp only [List.length_cons] - omega) - have rd16130 := by - simpa using rd16127.push2 ⟨16137⟩ hd16127 (by - simp only [List.length_cons] - omega) - have rd16137 := rd16130.jumpiT hd16130 hnewGtRaw - (uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched16137 hpatch) - (by simp only [List.length_cons]; omega) - exact ⟨_, _, by - simpa [solcSlotWord, holdRaw] using rd16137⟩ - -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowEnterLoopHeader - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {obsNext old arg ret : UInt256} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨16137⟩ - (⟨0⟩ :: obsNext :: old :: ⟨8⟩ :: ⟨5521⟩ :: ⟨0⟩ :: old :: arg :: ret :: R) - mem aw rdata acc k C) - (hov : R.length + 10 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨16139⟩ - (old :: ⟨0⟩ :: obsNext :: old :: ⟨8⟩ :: ⟨5521⟩ :: ⟨0⟩ :: old :: arg :: ret :: R) - mem aw rdata acc k' C' := by - have hdecodeGrow {pc : UInt256} (hlo : 16053 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 19295 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchDisjoint hlo hhi)] - have hd16137 : decode code ⟨16137⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16138 : decode code ⟨16138⟩ = some (.DUP3, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have rd16138 := by - simpa using h.jumpdest hd16137 (by - simp only [List.length_cons] - omega) - have rd16139 := by - simpa using rd16138.dup3 hd16138 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd16139⟩ - -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowLoopExitToTail - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {i obsNext old arg ret : UInt256} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨16139⟩ - (i :: ⟨0⟩ :: obsNext :: old :: ⟨8⟩ :: ⟨5521⟩ :: ⟨0⟩ :: old :: arg :: ret :: R) - mem aw rdata acc k C) - (hdone : UInt256.isZero - (UInt256.lt - (UInt256.land (⟨65535⟩ : UInt256) i) - (UInt256.land (⟨65535⟩ : UInt256) obsNext)) ≠ ⟨0⟩) - (hov : R.length + 14 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨5521⟩ - (obsNext :: ⟨0⟩ :: old :: arg :: ret :: R) mem aw rdata acc k' C' := by - have hdecodeGrow {pc : UInt256} (hlo : 16053 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 19295 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchDisjoint hlo hhi)] - have hd16139 : decode code ⟨16139⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16140 : decode code ⟨16140⟩ = some (.DUP3, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16141 : decode code ⟨16141⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16144 : decode code ⟨16144⟩ = some (.AND, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16145 : decode code ⟨16145⟩ = some (.DUP2, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16146 : decode code ⟨16146⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16149 : decode code ⟨16149⟩ = some (.AND, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16150 : decode code ⟨16150⟩ = some (.LT, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16151 : decode code ⟨16151⟩ = some (.ISZERO, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16152 : decode code ⟨16152⟩ = some (.Push .PUSH2, some (⟨16207⟩, 2)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16155 : decode code ⟨16155⟩ = some (.JUMPI, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16207 : decode code ⟨16207⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16208 : decode code ⟨16208⟩ = some (.POP, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16209 : decode code ⟨16209⟩ = some (.SWAP1, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16210 : decode code ⟨16210⟩ = some (.SWAP4, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16211 : decode code ⟨16211⟩ = some (.SWAP3, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16212 : decode code ⟨16212⟩ = some (.POP, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16213 : decode code ⟨16213⟩ = some (.POP, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16214 : decode code ⟨16214⟩ = some (.POP, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16215 : decode code ⟨16215⟩ = some (.JUMP, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have rd16140 := by - simpa using h.jumpdest hd16139 (by - simp only [List.length_cons] - omega) - have rd16141 := by - simpa using rd16140.dup3 hd16140 (by - simp only [List.length_cons] - omega) - have rd16144 := by - simpa using rd16141.push2 ⟨65535⟩ hd16141 (by - simp only [List.length_cons] - omega) - have rd16145 := by - simpa using rd16144.and hd16144 (by - simp only [List.length_cons] - omega) - have rd16146 := by - simpa using rd16145.dup2 hd16145 (by - simp only [List.length_cons] - omega) - have rd16149 := by - simpa using rd16146.push2 ⟨65535⟩ hd16146 (by - simp only [List.length_cons] - omega) - have rd16150 := by - simpa using rd16149.and hd16149 (by - simp only [List.length_cons] - omega) - have rd16151 := by - simpa using rd16150.lt hd16150 (by - simp only [List.length_cons] - omega) - have rd16152 := by - simpa using rd16151.iszero hd16151 (by - simp only [List.length_cons] - omega) - have rd16155 := by - simpa using rd16152.push2 ⟨16207⟩ hd16152 (by - simp only [List.length_cons] - omega) - have rd16207 := rd16155.jumpiT hd16155 hdone - (uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched16207 hpatch) - (by simp only [List.length_cons]; omega) - have rd16208 := by - simpa using rd16207.jumpdest hd16207 (by - simp only [List.length_cons] - omega) - have rd16209 := by - simpa using rd16208.pop hd16208 (by - simp only [List.length_cons] - omega) - have rd16210 := by - simpa using rd16209.swap1 hd16209 (by - simp only [List.length_cons] - omega) - have rd16211 := by - simpa using rd16210.swap4 hd16210 (by - simp only [List.length_cons] - omega) - have rd16212 := by - simpa using rd16211.swap3 hd16211 (by - simp only [List.length_cons] - omega) - have rd16213 := by - simpa using rd16212.pop hd16212 (by - simp only [List.length_cons] - omega) - have rd16214 := by - simpa using rd16213.pop hd16213 (by - simp only [List.length_cons] - omega) - have rd16215 := by - simpa using rd16214.pop hd16214 (by - simp only [List.length_cons] - omega) - have rd5521 := rd16215.jump hd16215 - (uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched5521 hpatch) - (by simp only [List.length_cons]; omega) - exact ⟨_, _, by - simpa using rd5521⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowLoopBodyStep - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} - {σ : AccountMap} {i obsNext old arg ret : UInt256} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨16139⟩ - (i :: ⟨0⟩ :: obsNext :: old :: ⟨8⟩ :: ⟨5521⟩ :: ⟨0⟩ :: old :: arg :: ret :: R) - mem aw rdata (cA, σ) k C) - (hloop : UInt256.isZero - (UInt256.lt - (UInt256.land (⟨65535⟩ : UInt256) i) - (UInt256.land (⟨65535⟩ : UInt256) obsNext)) = ⟨0⟩) - (hincOk : UInt256.lt (UInt256.land (⟨65535⟩ : UInt256) i) - (⟨65535⟩ : UInt256) ≠ ⟨0⟩) - (hperm : ee.perm = true) - (hov : R.length + 15 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨16139⟩ - (((⟨1⟩ : UInt256) + i) :: ⟨0⟩ :: obsNext :: old :: ⟨8⟩ :: ⟨5521⟩ :: - ⟨0⟩ :: old :: arg :: ret :: R) - mem aw rdata - (cA, sstoreAccountMap ee.codeOwner σ - (increaseObservationCardinalityNextGrowObservationSlot i) - (increaseObservationCardinalityNextGrowObservationWord σ ee i)) k' C' := by - have hdecodeGrow {pc : UInt256} (hlo : 16053 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 19295 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowPatchDisjoint hlo hhi)] - have hd16139 : decode code ⟨16139⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16140 : decode code ⟨16140⟩ = some (.DUP3, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16141 : decode code ⟨16141⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16144 : decode code ⟨16144⟩ = some (.AND, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16145 : decode code ⟨16145⟩ = some (.DUP2, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16146 : decode code ⟨16146⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16149 : decode code ⟨16149⟩ = some (.AND, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16150 : decode code ⟨16150⟩ = some (.LT, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16151 : decode code ⟨16151⟩ = some (.ISZERO, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16152 : decode code ⟨16152⟩ = some (.Push .PUSH2, some (⟨16207⟩, 2)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16155 : decode code ⟨16155⟩ = some (.JUMPI, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16156 : decode code ⟨16156⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16158 : decode code ⟨16158⟩ = some (.DUP6, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16159 : decode code ⟨16159⟩ = some (.DUP3, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16160 : decode code ⟨16160⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16163 : decode code ⟨16163⟩ = some (.AND, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16164 : decode code ⟨16164⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16167 : decode code ⟨16167⟩ = some (.DUP2, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16168 : decode code ⟨16168⟩ = some (.LT, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16169 : decode code ⟨16169⟩ = some (.Push .PUSH2, some (⟨16174⟩, 2)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16172 : decode code ⟨16172⟩ = some (.JUMPI, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16174 : decode code ⟨16174⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16175 : decode code ⟨16175⟩ = some (.ADD, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16176 : decode code ⟨16176⟩ = some (.DUP1, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16177 : decode code ⟨16177⟩ = some (.SLOAD, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16178 : decode code ⟨16178⟩ = some (.Push .PUSH4, some (⟨4294967295⟩, 4)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16183 : decode code ⟨16183⟩ = some (.NOT, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16184 : decode code ⟨16184⟩ = some (.AND, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16185 : decode code ⟨16185⟩ = some (.Push .PUSH4, some (⟨4294967295⟩, 4)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16190 : decode code ⟨16190⟩ = some (.SWAP3, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16191 : decode code ⟨16191⟩ = some (.SWAP1, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16192 : decode code ⟨16192⟩ = some (.SWAP3, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16193 : decode code ⟨16193⟩ = some (.AND, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16194 : decode code ⟨16194⟩ = some (.SWAP2, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16195 : decode code ⟨16195⟩ = some (.SWAP1, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16196 : decode code ⟨16196⟩ = some (.SWAP2, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16197 : decode code ⟨16197⟩ = some (.OR, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16198 : decode code ⟨16198⟩ = some (.SWAP1, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16199 : decode code ⟨16199⟩ = some (.SSTORE, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16200 : decode code ⟨16200⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16202 : decode code ⟨16202⟩ = some (.ADD, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16203 : decode code ⟨16203⟩ = some (.Push .PUSH2, some (⟨16139⟩, 2)) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have hd16206 : decode code ⟨16206⟩ = some (.JUMP, .none) := by - rw [hdecodeGrow (by native_decide) (by native_decide)]; native_decide - have rd16140 := by - simpa using h.jumpdest hd16139 (by - simp only [List.length_cons] - omega) - have rd16141 := by - simpa using rd16140.dup3 hd16140 (by - simp only [List.length_cons] - omega) - have rd16144 := by - simpa using rd16141.push2 ⟨65535⟩ hd16141 (by - simp only [List.length_cons] - omega) - have rd16145 := by - simpa using rd16144.and hd16144 (by - simp only [List.length_cons] - omega) - have rd16146 := by - simpa using rd16145.dup2 hd16145 (by - simp only [List.length_cons] - omega) - have rd16149 := by - simpa using rd16146.push2 ⟨65535⟩ hd16146 (by - simp only [List.length_cons] - omega) - have rd16150 := by - simpa using rd16149.and hd16149 (by - simp only [List.length_cons] - omega) - have rd16151 := by - simpa using rd16150.lt hd16150 (by - simp only [List.length_cons] - omega) - have rd16152 := by - simpa using rd16151.iszero hd16151 (by - simp only [List.length_cons] - omega) - have rd16155 := by - simpa using rd16152.push2 ⟨16207⟩ hd16152 (by - simp only [List.length_cons] - omega) - have rd16156 := rd16155.jumpiNT hd16155 hloop (by - simp only [List.length_cons] - omega) - have rd16158 := by - simpa using rd16156.push1 ⟨1⟩ hd16156 (by - simp only [List.length_cons] - omega) - have rd16159 := by - simpa using rd16158.dup6 hd16158 (by - simp only [List.length_cons] - omega) - have rd16160 := by - simpa using rd16159.dup3 hd16159 (by - simp only [List.length_cons] - omega) - have rd16163 := by - simpa using rd16160.push2 ⟨65535⟩ hd16160 (by - simp only [List.length_cons] - omega) - have rd16164 := by - simpa using rd16163.and hd16163 (by - simp only [List.length_cons] - omega) - have rd16167 := by - simpa using rd16164.push2 ⟨65535⟩ hd16164 (by - simp only [List.length_cons] - omega) - have rd16168 := by - simpa using rd16167.dup2 hd16167 (by - simp only [List.length_cons] - omega) - have rd16169 := by - simpa using rd16168.lt hd16168 (by - simp only [List.length_cons] - omega) - have rd16172 := by - simpa using rd16169.push2 ⟨16174⟩ hd16169 (by - simp only [List.length_cons] - omega) - have rd16174 := rd16172.jumpiT hd16172 hincOk - (by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - (by native_decide : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨16174⟩ 0 = true)) - (by simp only [List.length_cons]; omega) - have rd16175 := by - simpa using rd16174.jumpdest hd16174 (by - simp only [List.length_cons] - omega) - have rd16176 := by - simpa [increaseObservationCardinalityNextGrowObservationSlot] using - rd16175.add hd16175 (by - simp only [List.length_cons] - omega) - have rd16177 := by - simpa using rd16176.dup1 hd16176 (by - simp only [List.length_cons] - omega) - obtain ⟨_, _, rd16178₀⟩ := rd16177.sload hd16177 (by - simp only [List.length_cons] - omega) - have rd16178 := by - simpa [increaseObservationCardinalityNextGrowObservationSlot, codeOwnerStorageWord] - using rd16178₀ - have rd16183 := by - simpa using rd16178.pushConst ⟨4294967295⟩ - (by native_decide : Operation.POp.PUSH4 ≠ .PUSH0) hd16178 (by - simp only [List.length_cons] - omega) - have rd16184 := by - simpa using rd16183.not hd16183 (by - simp only [List.length_cons] - omega) - have rd16185 := by - simpa using rd16184.and hd16184 (by - simp only [List.length_cons] - omega) - have rd16190 := by - simpa using rd16185.pushConst ⟨4294967295⟩ - (by native_decide : Operation.POp.PUSH4 ≠ .PUSH0) hd16185 (by - simp only [List.length_cons] - omega) - have rd16191 := by - simpa using rd16190.swap3 hd16190 (by - simp only [List.length_cons] - omega) - have rd16192 := by - simpa using rd16191.swap1 hd16191 (by - simp only [List.length_cons] - omega) - have rd16193 := by - simpa using rd16192.swap3 hd16192 (by - simp only [List.length_cons] - omega) - have rd16194 := by - simpa using rd16193.and hd16193 (by - simp only [List.length_cons] - omega) - have rd16195 := by - simpa using rd16194.swap2 hd16194 (by - simp only [List.length_cons] - omega) - have rd16196 := by - simpa using rd16195.swap1 hd16195 (by - simp only [List.length_cons] - omega) - have rd16197 := by - simpa using rd16196.swap2 hd16196 (by - simp only [List.length_cons] - omega) - have rd16198 := by - simpa [increaseObservationCardinalityNextGrowObservationWord] using - rd16197.lor hd16197 (by - simp only [List.length_cons] - omega) - have rd16199 := by - simpa using rd16198.swap1 hd16198 (by - simp only [List.length_cons] - omega) - obtain ⟨_, _, rd16200₀⟩ := rd16199.sstore hperm hd16199 (by - simp only [List.length_cons] - omega) - have rd16200 := by - simpa [increaseObservationCardinalityNextGrowObservationSlot, - increaseObservationCardinalityNextGrowObservationWord, codeOwnerStorageWord] - using rd16200₀ - have rd16202 := by - simpa using rd16200.push1 ⟨1⟩ hd16200 (by - simp only [List.length_cons] - omega) - have rd16203 := by - simpa using rd16202.add hd16202 (by - simp only [List.length_cons] - omega) - have rd16206 := by - simpa using rd16203.push2 ⟨16139⟩ hd16203 (by - simp only [List.length_cons] - omega) - have rd16139 := rd16206.jump hd16206 - (uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched16139 hpatch) - (by simp only [List.length_cons]; omega) - exact ⟨_, _, by - simpa [increaseObservationCardinalityNextGrowObservationSlot, - increaseObservationCardinalityNextGrowObservationWord, codeOwnerStorageWord] - using rd16139⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolIncreaseObservationCardinalityNextTailReturn - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {rdata : ByteArray} {obsNext : UInt256} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5521⟩ - (obsNext :: ⟨0⟩ :: increaseObservationCardinalityNextOldWord σ ee :: - increaseObservationCardinalityNextArgWord ee :: ⟨857⟩ :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hperm : ee.perm = true) - (heqObsNext : - UInt256.land (increaseObservationCardinalityNextOldWord σ ee) (⟨65535⟩ : UInt256) = - UInt256.land obsNext (⟨65535⟩ : UInt256)) - (hov : R.length + 12 ≤ 1024) : - RDret code g s0 - (cA, sstoreAccountMap ee.codeOwner - (sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmObsNextSlotWord σ ee obsNext)) - ⟨0⟩ - (increaseObservationCardinalityNextEvmUnlockedTrueSlotWord - (sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmObsNextSlotWord σ ee obsNext)) ee)) - ByteArray.empty := by - have hdecodeBody {pc : UInt256} (hlo : 5404 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 6603) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 6603 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowBodyPatchDisjoint hlo hhi)] - have hd5521 : decode code ⟨5521⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5522 : decode code ⟨5522⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5524 : decode code ⟨5524⟩ = some (.DUP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5525 : decode code ⟨5525⟩ = some (.SLOAD, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5526 : decode code ⟨5526⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5529 : decode code ⟨5529⟩ = some (.DUP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5530 : decode code ⟨5530⟩ = some (.DUP5, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5531 : decode code ⟨5531⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5532 : decode code ⟨5532⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5534 : decode code ⟨5534⟩ = some (.Push .PUSH1, some (⟨216⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5536 : decode code ⟨5536⟩ = some (.SHL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5537 : decode code ⟨5537⟩ = some (.DUP2, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5538 : decode code ⟨5538⟩ = some (.MUL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5539 : decode code ⟨5539⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5542 : decode code ⟨5542⟩ = some (.Push .PUSH1, some (⟨216⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5544 : decode code ⟨5544⟩ = some (.SHL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5545 : decode code ⟨5545⟩ = some (.NOT, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5546 : decode code ⟨5546⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5547 : decode code ⟨5547⟩ = some (.SWAP4, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5548 : decode code ⟨5548⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5549 : decode code ⟨5549⟩ = some (.SWAP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5550 : decode code ⟨5550⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5551 : decode code ⟨5551⟩ = some (.SWAP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5552 : decode code ⟨5552⟩ = some (.OR, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5553 : decode code ⟨5553⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5554 : decode code ⟨5554⟩ = some (.SWAP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5555 : decode code ⟨5555⟩ = some (.SSTORE, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5556 : decode code ⟨5556⟩ = some (.SWAP2, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5557 : decode code ⟨5557⟩ = some (.SWAP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5558 : decode code ⟨5558⟩ = some (.POP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5559 : decode code ⟨5559⟩ = some (.DUP4, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5560 : decode code ⟨5560⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5561 : decode code ⟨5561⟩ = some (.EQ, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5562 : decode code ⟨5562⟩ = some (.Push .PUSH2, some (⟨5630⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5565 : decode code ⟨5565⟩ = some (.JUMPI, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5630 : decode code ⟨5630⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5631 : decode code ⟨5631⟩ = some (.POP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5632 : decode code ⟨5632⟩ = some (.POP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5633 : decode code ⟨5633⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5635 : decode code ⟨5635⟩ = some (.DUP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5636 : decode code ⟨5636⟩ = some (.SLOAD, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5637 : decode code ⟨5637⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5639 : decode code ⟨5639⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5641 : decode code ⟨5641⟩ = some (.SHL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5642 : decode code ⟨5642⟩ = some (.NOT, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5643 : decode code ⟨5643⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5644 : decode code ⟨5644⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5646 : decode code ⟨5646⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5648 : decode code ⟨5648⟩ = some (.SHL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5649 : decode code ⟨5649⟩ = some (.OR, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5650 : decode code ⟨5650⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5651 : decode code ⟨5651⟩ = some (.SSTORE, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5652 : decode code ⟨5652⟩ = some (.POP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5653 : decode code ⟨5653⟩ = some (.JUMP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd857 : decode code ⟨857⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd858 : decode code ⟨858⟩ = some (.STOP, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have rd5525 := evm_run h with [ - raw jumpdest hd5521 (by evm_ov), - raw push1 ⟨0⟩ hd5522 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd5524 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - obtain ⟨_, _, rd5526₀⟩ := rd5525.sload hd5525 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd5555 := evm_run rd5526₀ with [ - raw push2 ⟨65535⟩ hd5526 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd5529 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup5 hd5530 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5531 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨1⟩ hd5532 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨216⟩ hd5534 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd5536 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup2 hd5537 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw mul hd5538 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push2 ⟨65535⟩ hd5539 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨216⟩ hd5542 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd5544 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw not hd5545 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap1 hd5546 (by evm_ov), - raw swap4 hd5547 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5548 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap3 hd5549 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap1 hd5550 (by evm_ov), - raw swap3 hd5551 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw lor hd5552 (by evm_ov), - raw swap1 hd5553 (by evm_ov), - raw swap3 hd5554 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - obtain ⟨_, _, rd5556₀⟩ := rd5555.sstore hperm hd5555 (by evm_ov) - have rd5556 := by - simpa [increaseObservationCardinalityNextEvmObsNextSlotWord, - codeOwnerStorageWord] using rd5556₀ - have rd5565 := evm_run rd5556 with [ - raw swap2 hd5556 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap3 hd5557 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw pop hd5558 (by evm_ov), - raw dup4 hd5559 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5560 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw eq hd5561 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push2 ⟨5630⟩ hd5562 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd5630 := rd5565.jumpiT hd5565 (by - rw [heqObsNext, u256_eq_refl] - exact one_ne_zero_uint) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched5630 hpatch) - (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd5636 := evm_run rd5630 with [ - raw jumpdest hd5630 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw pop hd5631 (by evm_ov), - raw pop hd5632 (by evm_ov), - raw push1 ⟨0⟩ hd5633 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd5635 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - obtain ⟨_, _, rd5637₀⟩ := rd5636.sload hd5636 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd5651 := evm_run rd5637₀ with [ - raw push1 ⟨255⟩ hd5637 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨240⟩ hd5639 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd5641 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw not hd5642 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5643 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨1⟩ hd5644 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨240⟩ hd5646 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd5648 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw lor hd5649 (by evm_ov), - raw swap1 hd5650 (by evm_ov)] - obtain ⟨_, _, rd5652₀⟩ := rd5651.sstore hperm hd5651 (by evm_ov) - have rd5652 := by - simpa [increaseObservationCardinalityNextEvmUnlockedTrueSlotWord, - slot0UnlockedClearMask, codeOwnerStorageWord] using rd5652₀ - have rd5653 := evm_run rd5652 with [ - raw pop hd5652 (by evm_ov)] - have rd857 := rd5653.jump hd5653 - (uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched857 hpatch) - (by evm_ov) - have rd858 := rd857.jumpdest hd857 (by evm_ov) - have hpc858 : (⟨857⟩ : UInt256) + ⟨1⟩ = ⟨858⟩ := by - native_decide - obtain ⟨_, _, rd858'⟩ : ∃ k' C', RD code ee g s0 ⟨858⟩ R solcFreePtrMem - (UInt256.ofNat 3) rdata - (cA, sstoreAccountMap ee.codeOwner - (sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmObsNextSlotWord σ ee obsNext)) - ⟨0⟩ - (increaseObservationCardinalityNextEvmUnlockedTrueSlotWord - (sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmObsNextSlotWord σ ee obsNext)) ee)) - k' C' := by - exact ⟨_, _, by - simpa [increaseObservationCardinalityNextEvmObsNextSlotWord, - increaseObservationCardinalityNextEvmUnlockedTrueSlotWord, slot0UnlockedClearMask, - codeOwnerStorageWord, hpc858] using rd858⟩ - exact rd858'.stop hd858 (by - have h := hov - omega) - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolIncreaseObservationCardinalityNextUnlockReturnFrom5630 - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {obsNext old arg : UInt256} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5630⟩ - (obsNext :: old :: arg :: ⟨857⟩ :: R) - mem aw rdata (cA, σ) k C) - (hperm : ee.perm = true) - (hov : R.length + 6 ≤ 1024) : - RDret code g s0 - (cA, sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmUnlockedTrueSlotWord σ ee)) - ByteArray.empty := by - have hdecodeBody {pc : UInt256} (hlo : 5404 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 6603) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 6603 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowBodyPatchDisjoint hlo hhi)] - have hd5630 : decode code ⟨5630⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5631 : decode code ⟨5631⟩ = some (.POP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5632 : decode code ⟨5632⟩ = some (.POP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5633 : decode code ⟨5633⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5635 : decode code ⟨5635⟩ = some (.DUP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5636 : decode code ⟨5636⟩ = some (.SLOAD, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5637 : decode code ⟨5637⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5639 : decode code ⟨5639⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5641 : decode code ⟨5641⟩ = some (.SHL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5642 : decode code ⟨5642⟩ = some (.NOT, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5643 : decode code ⟨5643⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5644 : decode code ⟨5644⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5646 : decode code ⟨5646⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5648 : decode code ⟨5648⟩ = some (.SHL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5649 : decode code ⟨5649⟩ = some (.OR, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5650 : decode code ⟨5650⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5651 : decode code ⟨5651⟩ = some (.SSTORE, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5652 : decode code ⟨5652⟩ = some (.POP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5653 : decode code ⟨5653⟩ = some (.JUMP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd857 : decode code ⟨857⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd858 : decode code ⟨858⟩ = some (.STOP, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have rd5636 := evm_run h with [ - raw jumpdest hd5630 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw pop hd5631 (by evm_ov), - raw pop hd5632 (by evm_ov), - raw push1 ⟨0⟩ hd5633 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd5635 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - obtain ⟨_, _, rd5637₀⟩ := rd5636.sload hd5636 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd5651 := evm_run rd5637₀ with [ - raw push1 ⟨255⟩ hd5637 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨240⟩ hd5639 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd5641 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw not hd5642 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5643 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨1⟩ hd5644 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨240⟩ hd5646 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd5648 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw lor hd5649 (by evm_ov), - raw swap1 hd5650 (by evm_ov)] - obtain ⟨_, _, rd5652₀⟩ := rd5651.sstore hperm hd5651 (by evm_ov) - have rd5652 := by - simpa [increaseObservationCardinalityNextEvmUnlockedTrueSlotWord, - slot0UnlockedClearMask, codeOwnerStorageWord] using rd5652₀ - have rd5653 := evm_run rd5652 with [ - raw pop hd5652 (by evm_ov)] - have rd857 := rd5653.jump hd5653 - (uniswapV3PoolIncreaseObservationCardinalityNextGrowJumpDestPatched857 hpatch) - (by evm_ov) - have rd858 := rd857.jumpdest hd857 (by evm_ov) - have hpc858 : (⟨857⟩ : UInt256) + ⟨1⟩ = ⟨858⟩ := by - native_decide - obtain ⟨_, _, rd858'⟩ : ∃ k' C', RD code ee g s0 ⟨858⟩ R mem aw rdata - (cA, sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmUnlockedTrueSlotWord σ ee)) - k' C' := by - exact ⟨_, _, by - simpa [increaseObservationCardinalityNextEvmUnlockedTrueSlotWord, - slot0UnlockedClearMask, codeOwnerStorageWord, hpc858] using rd858⟩ - exact rd858'.stop hd858 (by - have h := hov - omega) - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowEventTailReturn - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {rdata : ByteArray} {obsNext old arg : UInt256} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5565⟩ - (⟨5630⟩ :: UInt256.eq (UInt256.land old (⟨65535⟩ : UInt256)) - (UInt256.land obsNext (⟨65535⟩ : UInt256)) :: - obsNext :: old :: arg :: ⟨857⟩ :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hperm : ee.perm = true) - (hchanged : - UInt256.land old (⟨65535⟩ : UInt256) ≠ - UInt256.land obsNext (⟨65535⟩ : UInt256)) - (hov : R.length + 12 ≤ 1024) : - RDret code g s0 - (cA, sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmUnlockedTrueSlotWord σ ee)) - ByteArray.empty := by - have hdecodeBody {pc : UInt256} (hlo : 5404 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 6603) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 6603 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowBodyPatchDisjoint hlo hhi)] - have hd5565 : decode code ⟨5565⟩ = some (.JUMPI, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5566 : decode code ⟨5566⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5568 : decode code ⟨5568⟩ = some (.DUP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5569 : decode code ⟨5569⟩ = some (.MLOAD, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5570 : decode code ⟨5570⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5573 : decode code ⟨5573⟩ = some (.DUP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5574 : decode code ⟨5574⟩ = some (.DUP6, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5575 : decode code ⟨5575⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5576 : decode code ⟨5576⟩ = some (.DUP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5577 : decode code ⟨5577⟩ = some (.MSTORE, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5578 : decode code ⟨5578⟩ = some (.DUP4, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5579 : decode code ⟨5579⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5580 : decode code ⟨5580⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5582 : decode code ⟨5582⟩ = some (.DUP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5583 : decode code ⟨5583⟩ = some (.ADD, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5584 : decode code ⟨5584⟩ = some (.MSTORE, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5585 : decode code ⟨5585⟩ = some (.DUP2, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5586 : decode code ⟨5586⟩ = some (.MLOAD, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5587 : - decode code ⟨5587⟩ = - some (.Push .PUSH32, some (increaseObservationCardinalityNextEventTopic, 32)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd5620 : decode code ⟨5620⟩ = some (.SWAP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5621 : decode code ⟨5621⟩ = some (.SWAP2, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5622 : decode code ⟨5622⟩ = some (.DUP2, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5623 : decode code ⟨5623⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5624 : decode code ⟨5624⟩ = some (.SUB, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5625 : decode code ⟨5625⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5626 : decode code ⟨5626⟩ = some (.SWAP2, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5627 : decode code ⟨5627⟩ = some (.ADD, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5628 : decode code ⟨5628⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5629 : decode code ⟨5629⟩ = some (.LOG1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have heqZero : - UInt256.eq (UInt256.land old (⟨65535⟩ : UInt256)) - (UInt256.land obsNext (⟨65535⟩ : UInt256)) = ⟨0⟩ := - u256_eq_of_ne hchanged - have rd5566 := h.jumpiNT hd5565 heqZero (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd5569 := evm_run rd5566 with [ - raw push1 ⟨64⟩ hd5566 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd5568 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd5570 := rd5569.mload 0 ⟨128⟩ (UInt256.ofNat 3) hd5569 mem_cost - solcFreePtrMem_mload64 (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd5577 := evm_run rd5570 with [ - raw push2 ⟨65535⟩ hd5570 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd5573 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup6 hd5574 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5575 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup3 hd5576 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd5578 := rd5577.mstore 6 (increaseObservationCardinalityNextEventMem0 old) - (UInt256.ofNat 5) hd5577 mem_cost rfl (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd5584 := evm_run rd5578 with [ - raw dup4 hd5578 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5579 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨32⟩ hd5580 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup3 hd5582 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw add hd5583 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd5585 := rd5584.mstore 3 - (increaseObservationCardinalityNextEventMem old obsNext) (UInt256.ofNat 6) - hd5584 mem_cost - (by - unfold increaseObservationCardinalityNextEventMem - rw [show (((⟨128⟩ : UInt256) + ⟨32⟩).toNat) = 160 by native_decide]) - (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd5586 := evm_run rd5585 with [ - raw dup2 hd5585 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd5587 := rd5586.mload 0 ⟨128⟩ (UInt256.ofNat 6) hd5586 mem_cost - (increaseObservationCardinalityNextEventMem_mload64 old obsNext) - (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd5629 := evm_run rd5587 with [ - raw pushConst increaseObservationCardinalityNextEventTopic - (show Operation.POp.PUSH32 ≠ .PUSH0 by native_decide) hd5587 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap3 hd5620 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap2 hd5621 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup2 hd5622 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap1 hd5623 (by evm_ov), - raw sub hd5624 (by evm_ov), - raw swap1 hd5625 (by evm_ov), - raw swap2 hd5626 (by evm_ov), - raw add hd5627 (by evm_ov), - raw swap1 hd5628 (by evm_ov)] - have rd5630 := rd5629.log1 0 (UInt256.ofNat 6) hd5629 hperm mem_cost - (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - exact uniswapV3PoolIncreaseObservationCardinalityNextUnlockReturnFrom5630 - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (R := R) (rdata := rdata) (obsNext := obsNext) (old := old) (arg := arg) - (cA := cA) (σ := σ) hpatch rd5630 hperm (by - have h := hov - omega) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowLoop.lean b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowLoop.lean deleted file mode 100644 index 99ec1564..00000000 --- a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowLoop.lean +++ /dev/null @@ -1,1615 +0,0 @@ -import Benchmarks.UniswapV3Pool.IncreaseObservationCardinalityNextGrowTail - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem execWhile_var_state {cfg : Config} {C : ContractDecl} - {cond : Expr} {body : List Stmt} (P : ℕ → Solm.Store → EVM.State → Prop) - (hfalse : ∀ L evm, P 0 L evm → - evalExpr? cfg { contract := C, locals := L } evm cond = .ok (.bool false)) - (htrue : ∀ v L evm, P (v + 1) L evm → - evalExpr? cfg { contract := C, locals := L } evm cond = .ok (.bool true)) - (hstep : ∀ v L evm, P (v + 1) L evm → - ∃ L' evm', ExecBlock cfg { contract := C, locals := L } evm body - (.ok { contract := C, locals := L' } evm') ∧ P v L' evm') : - ∀ v L evm, P v L evm → ∃ L' evm', - ExecStmt cfg { contract := C, locals := L } evm (.while cond body) - (.ok { contract := C, locals := L' } evm') ∧ P 0 L' evm' := by - intro v - induction v with - | zero => - intro L evm hP - exact ⟨L, evm, ExecStmt.whileFalse (hfalse L evm hP), hP⟩ - | succ v ih => - intro L evm hP - obtain ⟨L1, evm1, hbody, hP1⟩ := hstep v L evm hP - obtain ⟨L', evm', hwhile, hP'⟩ := ih L1 evm1 hP1 - exact ⟨L', evm', ExecStmt.whileTrue (htrue v L evm hP) hbody hwhile, hP'⟩ - -abbrev increaseObservationCardinalityNextGrowStoreWithI - (σ : AccountMap) (I : ExecutionEnv) (i : UInt256) : Store := - (increaseObservationCardinalityNextStoreWithOldNew σ I).insert "i" - (.int (Int.ofNat i.toNat)) - -abbrev increaseObservationCardinalityNextGrowObservationLoc (i : UInt256) : StorageLoc := - loc (increaseObservationCardinalityNextGrowObservationSlot i) ⟨0, by decide⟩ - ⟨4, by decide⟩ (by decide) (.int uint32Int) - -abbrev increaseObservationCardinalityNextGrowObservationState - (evm : EVM.State) (i : UInt256) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner - (increaseObservationCardinalityNextGrowObservationSlot i) - (increaseObservationCardinalityNextGrowObservationWord evm.accountMap evm.executionEnv i) - -theorem evalExpr_increaseObservationCardinalityNext_i_withGrowStore - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) : - evalExpr? (config v) - { contract := contract v, - locals := increaseObservationCardinalityNextGrowStoreWithI σ I i } - evm (.var "i") = - .ok (.int (Int.ofNat i.toNat)) := by - rw [evalExpr?] - rw [increaseObservationCardinalityNextGrowStoreWithI, store_get_self] - rfl - -theorem evalExpr_increaseObservationCardinalityNext_new_withGrowStore - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) : - evalExpr? (config v) - { contract := contract v, - locals := increaseObservationCardinalityNextGrowStoreWithI σ I i } - evm (.var "observationCardinalityNextNew") = - .ok (increaseObservationCardinalityNextArgValue I) := by - rw [evalExpr?] - rw [increaseObservationCardinalityNextGrowStoreWithI] - rw [store_get_ne (increaseObservationCardinalityNextStoreWithOldNew σ I) - (.int (Int.ofNat i.toNat)) (by decide)] - rw [increaseObservationCardinalityNextStoreWithOldNew_new] - rfl - -theorem evalExpr_increaseObservationCardinalityNext_loopCond_true - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (hlt : i.toNat < (increaseObservationCardinalityNextArgWord I).toNat) : - evalExpr? (config v) - { contract := contract v, - locals := increaseObservationCardinalityNextGrowStoreWithI σ I i } - evm (ltE (.var "i") (.var "observationCardinalityNextNew")) = - .ok (.bool true) := by - simp only [ltE, evalExpr?, evalExpr_increaseObservationCardinalityNext_i_withGrowStore, - evalExpr_increaseObservationCardinalityNext_new_withGrowStore, EvalResult.bind, bind, - evalBinaryOp?] - simp [hlt] - -theorem evalExpr_increaseObservationCardinalityNext_loopCond_false - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (hle : (increaseObservationCardinalityNextArgWord I).toNat ≤ i.toNat) : - evalExpr? (config v) - { contract := contract v, - locals := increaseObservationCardinalityNextGrowStoreWithI σ I i } - evm (ltE (.var "i") (.var "observationCardinalityNextNew")) = - .ok (.bool false) := by - simp only [ltE, evalExpr?, evalExpr_increaseObservationCardinalityNext_i_withGrowStore, - evalExpr_increaseObservationCardinalityNext_new_withGrowStore, EvalResult.bind, bind, - evalBinaryOp?] - simp [not_lt.mpr hle] - -theorem evalExpr_increaseObservationCardinalityNext_one {v : PoolImmutables} - (solm : Frame) (evm : EVM.State) : - evalExpr? (config v) solm evm (.intLit 1) = .ok (.int 1) := by - simp only [evalExpr?, pure] - -theorem evalExpr_increaseObservationCardinalityNext_i_add_one_withGrowStore - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) : - evalExpr? (config v) - { contract := contract v, - locals := increaseObservationCardinalityNextGrowStoreWithI σ I i } - evm (addE (.var "i") (.intLit 1)) = - .ok (.int (Int.ofNat (i.toNat + 1))) := by - have hcast : Int.ofNat i.toNat + 1 = Int.ofNat (i.toNat + 1) := by - simp only [Int.ofNat_eq_natCast] - exact - ((Nat.cast_add i.toNat 1 : - ((i.toNat + 1 : Nat) : Int) = (i.toNat : Int) + (1 : Int)).symm) - simp only [addE, evalExpr?, evalExpr_increaseObservationCardinalityNext_i_withGrowStore, - EvalResult.bind, bind, pure, evalBinaryOp?] - rw [hcast] - -theorem assignStorageRef_increaseObservationCardinalityNext_i_next - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) : - assignStorageRef? (config v) - { contract := contract v, - locals := increaseObservationCardinalityNextGrowStoreWithI σ I i } - evm .localVar (varRef "i") (.int (Int.ofNat (i.toNat + 1))) = - .ok - ({ contract := contract v, - locals := (increaseObservationCardinalityNextGrowStoreWithI σ I i).insert "i" - (.int (Int.ofNat (i.toNat + 1))) }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [increaseObservationCardinalityNextGrowStoreWithI, store_get_self] - simp [updateLocalPath?, pure, bind, EvalResult.bind] - -theorem natLorShift32One (q : Nat) : Nat.lor 1 (q * 2 ^ 32) = 1 + q * 2 ^ 32 := by - rw [nat_lor_shift_add 1 q 32 (by norm_num)] - -theorem increaseObservationCardinalityNextGrowObservationWord_toNat - (old : UInt256) : - (UInt256.lor - (UInt256.land (⟨4294967295⟩ : UInt256) (⟨1⟩ : UInt256)) - (UInt256.land (UInt256.lnot (⟨4294967295⟩ : UInt256)) old)).toNat = - 1 + (old.toNat / 2 ^ 32) * 2 ^ 32 := by - have hlow : - (UInt256.land (⟨4294967295⟩ : UInt256) (⟨1⟩ : UInt256)).toNat = 1 := by - native_decide - have hmask : - UInt256.lnot (⟨4294967295⟩ : UInt256) = - UInt256.ofNat ((2 : Nat) ^ 256 - 2 ^ 32) := by - native_decide - have hhigh : - (UInt256.land (UInt256.lnot (⟨4294967295⟩ : UInt256)) old).toNat = - (old.toNat / 2 ^ 32) * 2 ^ 32 := by - rw [hmask] - exact u256_land_high_mask_toNat old 32 (by norm_num) - rw [u256_lor_toNat, hlow, hhigh, natLorShift32One] - rw [Nat.mod_eq_of_lt] - have hq : old.toNat / 2 ^ 32 < 2 ^ 224 := by - norm_num [UInt256.size] at old ⊢ - exact Nat.div_lt_of_lt_mul old.val.isLt - have hmul : old.toNat / 2 ^ 32 * 2 ^ 32 ≤ (2 ^ 224 - 1) * 2 ^ 32 := by - exact Nat.mul_le_mul_right _ (Nat.le_pred_of_lt hq) - norm_num [UInt256.size, Nat.pow_add] at hmul ⊢ - omega - -theorem storageLocStore_increaseObservationCardinalityNext_growObservation - (evm : EVM.State) (i : UInt256) : - storageLocStore evm (increaseObservationCardinalityNextGrowObservationLoc i) (.int 1) = - some (increaseObservationCardinalityNextGrowObservationState evm i) := by - unfold storageLocStore storageLocWriteWord - increaseObservationCardinalityNextGrowObservationLoc - increaseObservationCardinalityNextGrowObservationState - increaseObservationCardinalityNextGrowObservationWord loc - simp only [valueToWord, bind, Option.bind] - rw [show EVM.wordOfInt 1 = (⟨1⟩ : UInt256) by native_decide] - congr 2 - apply u256_inj - show fromBytes' - (List.take (0 : Fin 32).val _ ++ List.take (4 : Fin 33).val _ - ++ List.drop ((0 : Fin 32).val + (4 : Fin 33).val) _) = - (UInt256.lor - (UInt256.land (⟨4294967295⟩ : UInt256) (⟨1⟩ : UInt256)) - (UInt256.land (UInt256.lnot (⟨4294967295⟩ : UInt256)) - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (UInt256.land (⟨65535⟩ : UInt256) i + ⟨8⟩)))).toNat - rw [show (0 : Fin 32).val = 0 from rfl, show (4 : Fin 33).val = 4 from rfl, - List.take_zero, List.nil_append] - rw [show List.take 4 (EVM.Word.toBytesLEWithSizeProof (⟨1⟩ : UInt256)).1 = - [1, 0, 0, 0] by native_decide] - rw [fromBytes'_append, fromBytes'_drop_wordLE] - simp [fromBytes'] - rw [increaseObservationCardinalityNextGrowObservationWord_toNat] - ring_nf - -theorem increaseObservationCardinalityNextGrowObservationSlot_eq_observationBase - (i : UInt256) (hlt : i.toNat < 65535) : - increaseObservationCardinalityNextGrowObservationSlot i = - observationBase (.int (Int.ofNat i.toNat)) := by - have hclean : - UInt256.land (⟨65535⟩ : UInt256) i = i := by - simpa [slot0Uint16Mask] using - slot0Uint16Mask_clean_left (w := i) (by - simpa [EVM.twoPow] using (by omega : i.toNat < 65536)) - unfold increaseObservationCardinalityNextGrowObservationSlot observationBase - rw [keyValueToWord_uint256, hclean, u256_ofNat_toNat] - exact u256_add_comm i ⟨8⟩ - -abbrev increaseObservationCardinalityNextGrowObservationEvaledRef (i : UInt256) : - EvaledStorageRef := - { base := "observationsRaw", - steps := [.mindex (.int (Int.ofNat i.toNat)), .field "blockTimestamp"] } - -theorem evalStorageRef_increaseObservationCardinalityNext_growObservation - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) : - evalStorageRef (config v) - { contract := contract v, - locals := increaseObservationCardinalityNextGrowStoreWithI σ I i } - evm (observationsRawF (.var "i") "blockTimestamp") = - .ok (increaseObservationCardinalityNextGrowObservationEvaledRef i) := by - simp [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, observationsRawF, - increaseObservationCardinalityNextGrowObservationEvaledRef, - evalExpr_increaseObservationCardinalityNext_i_withGrowStore, - valueToKey?, EvalResult.bind, EvalResult.ofOption, bind, pure] - -theorem assignStorageRef_increaseObservationCardinalityNext_growObservation - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (hlt : i.toNat < 65535) : - assignStorageRef? (config v) - { contract := contract v, - locals := increaseObservationCardinalityNextGrowStoreWithI σ I i } - evm .storage (observationsRawF (.var "i") "blockTimestamp") (.int 1) = - .ok - ({ contract := contract v, - locals := increaseObservationCardinalityNextGrowStoreWithI σ I i }, - increaseObservationCardinalityNextGrowObservationState evm i) := by - apply assignStorageRef_storage_scalar_value - (er := increaseObservationCardinalityNextGrowObservationEvaledRef i) - (ty := .elem (.int uint32Int)) - (loc := increaseObservationCardinalityNextGrowObservationLoc i) - · simp [observationsRawF, increaseObservationCardinalityNextGrowStoreWithI, - increaseObservationCardinalityNextStoreWithOldNew, - increaseObservationCardinalityNextStoreWithOld, increaseObservationCardinalityNextStore] - · exact evalStorageRef_increaseObservationCardinalityNext_growObservation (v := v) evm σ I i - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, observationStructTy, uint32St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - increaseObservationCardinalityNextGrowObservationEvaledRef, - increaseObservationCardinalityNextGrowObservationLoc, loc] - exact (increaseObservationCardinalityNextGrowObservationSlot_eq_observationBase i hlt).symm - · trivial - · exact storageLocStore_increaseObservationCardinalityNext_growObservation evm i - -theorem execBlock_increaseObservationCardinalityNext_growLoopBody - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (hlt : i.toNat < 65535) : - ExecBlock (config v) - { contract := contract v, - locals := increaseObservationCardinalityNextGrowStoreWithI σ I i } - evm - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] - (.ok - { contract := contract v, - locals := (increaseObservationCardinalityNextGrowStoreWithI σ I i).insert "i" - (.int (Int.ofNat (i.toNat + 1))) } - (increaseObservationCardinalityNextGrowObservationState evm i)) := by - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_increaseObservationCardinalityNext_one _ _) - (assignStorageRef_increaseObservationCardinalityNext_growObservation - (v := v) evm σ I i hlt)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign - (evalExpr_increaseObservationCardinalityNext_i_add_one_withGrowStore - (v := v) (increaseObservationCardinalityNextGrowObservationState evm i) σ I i) - (assignStorageRef_increaseObservationCardinalityNext_i_next - (v := v) (increaseObservationCardinalityNextGrowObservationState evm i) σ I i)) - ExecBlock.nil - -structure increaseObservationCardinalityNextGrowLocals - (σ : AccountMap) (I : ExecutionEnv) (i : UInt256) (L : Store) : Prop where - i_get : L.get? "i" = some (.int (Int.ofNat i.toNat)) - new_get : L.get? "observationCardinalityNextNew" = - some (increaseObservationCardinalityNextArgValue I) - observationsRaw_get : L.get? "observationsRaw" = none - slot0_get : L.get? "slot0" = none - -theorem increaseObservationCardinalityNextGrowLocals_initial - (σ : AccountMap) (I : ExecutionEnv) (i : UInt256) : - increaseObservationCardinalityNextGrowLocals σ I i - (increaseObservationCardinalityNextGrowStoreWithI σ I i) := by - constructor - · rw [increaseObservationCardinalityNextGrowStoreWithI, store_get_self] - · rw [increaseObservationCardinalityNextGrowStoreWithI] - rw [store_get_ne (increaseObservationCardinalityNextStoreWithOldNew σ I) - (.int (Int.ofNat i.toNat)) (by decide)] - exact increaseObservationCardinalityNextStoreWithOldNew_new σ I - · simp [increaseObservationCardinalityNextGrowStoreWithI, - increaseObservationCardinalityNextStoreWithOldNew, - increaseObservationCardinalityNextStoreWithOld, - increaseObservationCardinalityNextStore] - · simp [increaseObservationCardinalityNextGrowStoreWithI, - increaseObservationCardinalityNextStoreWithOldNew, - increaseObservationCardinalityNextStoreWithOld, - increaseObservationCardinalityNextStore] - -theorem increaseObservationCardinalityNextGrowLocals_insert_next - {σ : AccountMap} {I : ExecutionEnv} {i : UInt256} {L : Store} - (hL : increaseObservationCardinalityNextGrowLocals σ I i L) - (hlt : i.toNat < 65535) : - increaseObservationCardinalityNextGrowLocals σ I (UInt256.ofNat (i.toNat + 1)) - (L.insert "i" (.int (Int.ofNat (i.toNat + 1)))) := by - have htoNat : (UInt256.ofNat (i.toNat + 1)).toNat = i.toNat + 1 := by - exact ulit_toNat' (i.toNat + 1) (by - norm_num [UInt256.size] - omega) - constructor - · rw [store_get_self, htoNat] - · rw [store_get_ne L (.int (Int.ofNat (i.toNat + 1))) (by decide)] - exact hL.new_get - · rw [store_get_ne L (.int (Int.ofNat (i.toNat + 1))) (by decide)] - exact hL.observationsRaw_get - · rw [store_get_ne L (.int (Int.ofNat (i.toNat + 1))) (by decide)] - exact hL.slot0_get - -theorem evalExpr_increaseObservationCardinalityNext_i_withGrowLocals - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (L : Store) - (hL : increaseObservationCardinalityNextGrowLocals σ I i L) : - evalExpr? (config v) { contract := contract v, locals := L } evm (.var "i") = - .ok (.int (Int.ofNat i.toNat)) := by - rw [evalExpr?] - rw [hL.i_get] - rfl - -theorem evalExpr_increaseObservationCardinalityNext_new_withGrowLocals - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (L : Store) - (hL : increaseObservationCardinalityNextGrowLocals σ I i L) : - evalExpr? (config v) { contract := contract v, locals := L } evm - (.var "observationCardinalityNextNew") = - .ok (increaseObservationCardinalityNextArgValue I) := by - rw [evalExpr?] - rw [hL.new_get] - rfl - -theorem evalExpr_increaseObservationCardinalityNext_loopCond_true_withGrowLocals - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (L : Store) - (hL : increaseObservationCardinalityNextGrowLocals σ I i L) - (hlt : i.toNat < (increaseObservationCardinalityNextArgWord I).toNat) : - evalExpr? (config v) { contract := contract v, locals := L } evm - (ltE (.var "i") (.var "observationCardinalityNextNew")) = - .ok (.bool true) := by - simp only [ltE, evalExpr?, - evalExpr_increaseObservationCardinalityNext_i_withGrowLocals - (v := v) evm σ I i L hL, - evalExpr_increaseObservationCardinalityNext_new_withGrowLocals - (v := v) evm σ I i L hL, - EvalResult.bind, bind, evalBinaryOp?] - simp [hlt] - -theorem evalExpr_increaseObservationCardinalityNext_loopCond_false_withGrowLocals - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (L : Store) - (hL : increaseObservationCardinalityNextGrowLocals σ I i L) - (hle : (increaseObservationCardinalityNextArgWord I).toNat ≤ i.toNat) : - evalExpr? (config v) { contract := contract v, locals := L } evm - (ltE (.var "i") (.var "observationCardinalityNextNew")) = - .ok (.bool false) := by - simp only [ltE, evalExpr?, - evalExpr_increaseObservationCardinalityNext_i_withGrowLocals - (v := v) evm σ I i L hL, - evalExpr_increaseObservationCardinalityNext_new_withGrowLocals - (v := v) evm σ I i L hL, - EvalResult.bind, bind, evalBinaryOp?] - simp [not_lt.mpr hle] - -theorem evalExpr_increaseObservationCardinalityNext_i_add_one_withGrowLocals - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (L : Store) - (hL : increaseObservationCardinalityNextGrowLocals σ I i L) : - evalExpr? (config v) { contract := contract v, locals := L } evm - (addE (.var "i") (.intLit 1)) = - .ok (.int (Int.ofNat (i.toNat + 1))) := by - have hcast : Int.ofNat i.toNat + 1 = Int.ofNat (i.toNat + 1) := by - simp only [Int.ofNat_eq_natCast] - exact - ((Nat.cast_add i.toNat 1 : - ((i.toNat + 1 : Nat) : Int) = (i.toNat : Int) + (1 : Int)).symm) - simp only [addE, evalExpr?, - evalExpr_increaseObservationCardinalityNext_i_withGrowLocals - (v := v) evm σ I i L hL, - EvalResult.bind, bind, pure, evalBinaryOp?] - rw [hcast] - -theorem evalStorageRef_increaseObservationCardinalityNext_growObservation_withGrowLocals - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (L : Store) - (hL : increaseObservationCardinalityNextGrowLocals σ I i L) : - evalStorageRef (config v) { contract := contract v, locals := L } evm - (observationsRawF (.var "i") "blockTimestamp") = - .ok (increaseObservationCardinalityNextGrowObservationEvaledRef i) := by - simp [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, observationsRawF, - increaseObservationCardinalityNextGrowObservationEvaledRef, - evalExpr_increaseObservationCardinalityNext_i_withGrowLocals - (v := v) evm σ I i L hL, - valueToKey?, EvalResult.bind, EvalResult.ofOption, bind, pure] - -theorem assignStorageRef_increaseObservationCardinalityNext_growObservation_withGrowLocals - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (L : Store) - (hL : increaseObservationCardinalityNextGrowLocals σ I i L) (hlt : i.toNat < 65535) : - assignStorageRef? (config v) { contract := contract v, locals := L } evm .storage - (observationsRawF (.var "i") "blockTimestamp") (.int 1) = - .ok - ({ contract := contract v, locals := L }, - increaseObservationCardinalityNextGrowObservationState evm i) := by - apply assignStorageRef_storage_scalar_value - (er := increaseObservationCardinalityNextGrowObservationEvaledRef i) - (ty := .elem (.int uint32Int)) - (loc := increaseObservationCardinalityNextGrowObservationLoc i) - · exact hL.observationsRaw_get - · exact evalStorageRef_increaseObservationCardinalityNext_growObservation_withGrowLocals - (v := v) evm σ I i L hL - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, observationStructTy, uint32St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - increaseObservationCardinalityNextGrowObservationEvaledRef, - increaseObservationCardinalityNextGrowObservationLoc, loc] - exact (increaseObservationCardinalityNextGrowObservationSlot_eq_observationBase i hlt).symm - · trivial - · exact storageLocStore_increaseObservationCardinalityNext_growObservation evm i - -theorem assignStorageRef_increaseObservationCardinalityNext_i_next_withGrowLocals - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (L : Store) - (hL : increaseObservationCardinalityNextGrowLocals σ I i L) : - assignStorageRef? (config v) { contract := contract v, locals := L } evm .localVar - (varRef "i") (.int (Int.ofNat (i.toNat + 1))) = - .ok - ({ contract := contract v, - locals := L.insert "i" (.int (Int.ofNat (i.toNat + 1))) }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [hL.i_get] - simp [updateLocalPath?, pure, bind, EvalResult.bind] - -theorem execBlock_increaseObservationCardinalityNext_growLoopBody_withGrowLocals - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (L : Store) - (hL : increaseObservationCardinalityNextGrowLocals σ I i L) (hlt : i.toNat < 65535) : - ExecBlock (config v) { contract := contract v, locals := L } evm - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] - (.ok - { contract := contract v, - locals := L.insert "i" (.int (Int.ofNat (i.toNat + 1))) } - (increaseObservationCardinalityNextGrowObservationState evm i)) := by - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_increaseObservationCardinalityNext_one _ _) - (assignStorageRef_increaseObservationCardinalityNext_growObservation_withGrowLocals - (v := v) evm σ I i L hL hlt)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign - (evalExpr_increaseObservationCardinalityNext_i_add_one_withGrowLocals - (v := v) (increaseObservationCardinalityNextGrowObservationState evm i) σ I i L hL) - (assignStorageRef_increaseObservationCardinalityNext_i_next_withGrowLocals - (v := v) (increaseObservationCardinalityNextGrowObservationState evm i) σ I i L hL)) - ExecBlock.nil - -def increaseObservationCardinalityNextGrowLoopSourceState : - Nat → EVM.State → UInt256 → EVM.State - | 0, evm, _ => evm - | n + 1, evm, i => - increaseObservationCardinalityNextGrowLoopSourceState n - (increaseObservationCardinalityNextGrowObservationState evm i) - (UInt256.ofNat (i.toNat + 1)) - -theorem execStmt_increaseObservationCardinalityNext_growLoopAux - {v : PoolImmutables} (σ : AccountMap) (I : ExecutionEnv) : - ∀ (n : Nat) (evm : EVM.State) (i : UInt256) (L : Store), - increaseObservationCardinalityNextGrowLocals σ I i L → - i.toNat ≤ (increaseObservationCardinalityNextArgWord I).toNat → - n = (increaseObservationCardinalityNextArgWord I).toNat - i.toNat → - (increaseObservationCardinalityNextArgWord I).toNat ≤ 65535 → - ∃ L', - ExecStmt (config v) { contract := contract v, locals := L } evm - (.while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ]) - (.ok { contract := contract v, locals := L' } - (increaseObservationCardinalityNextGrowLoopSourceState n evm i)) ∧ - increaseObservationCardinalityNextGrowLocals σ I - (increaseObservationCardinalityNextArgWord I) L' := by - intro n - induction n with - | zero => - intro evm i L hL hle hn _hnewBound - have hge : (increaseObservationCardinalityNextArgWord I).toNat ≤ i.toNat := by - omega - have hiNat : i.toNat = (increaseObservationCardinalityNextArgWord I).toNat := by - omega - have hi : i = increaseObservationCardinalityNextArgWord I := by - exact u256_inj hiNat - subst i - refine ⟨L, ?_, hL⟩ - simpa [increaseObservationCardinalityNextGrowLoopSourceState] using - ExecStmt.whileFalse - (evalExpr_increaseObservationCardinalityNext_loopCond_false_withGrowLocals - (v := v) evm σ I (increaseObservationCardinalityNextArgWord I) L hL - (by omega)) - | succ n ih => - intro evm i L hL hle hn hnewBound - have hlt : i.toNat < (increaseObservationCardinalityNextArgWord I).toNat := by - omega - have hiBound : i.toNat < 65535 := by - omega - let i' : UInt256 := UInt256.ofNat (i.toNat + 1) - have hbody := - execBlock_increaseObservationCardinalityNext_growLoopBody_withGrowLocals - (v := v) evm σ I i L hL hiBound - have hLnext : - increaseObservationCardinalityNextGrowLocals σ I i' - (L.insert "i" (.int (Int.ofNat (i.toNat + 1)))) := by - dsimp [i'] - exact increaseObservationCardinalityNextGrowLocals_insert_next hL hiBound - have hi'toNat : i'.toNat = i.toNat + 1 := by - dsimp [i'] - exact ulit_toNat' (i.toNat + 1) (by - norm_num [UInt256.size] - omega) - have hleNext : i'.toNat ≤ (increaseObservationCardinalityNextArgWord I).toNat := by - rw [hi'toNat] - omega - have hnNext : n = (increaseObservationCardinalityNextArgWord I).toNat - i'.toNat := by - rw [hi'toNat] - omega - obtain ⟨L', hwhile, hL'⟩ := - ih (increaseObservationCardinalityNextGrowObservationState evm i) i' - (L.insert "i" (.int (Int.ofNat (i.toNat + 1)))) hLnext hleNext hnNext hnewBound - refine ⟨L', ?_, hL'⟩ - exact ExecStmt.whileTrue - (evalExpr_increaseObservationCardinalityNext_loopCond_true_withGrowLocals - (v := v) evm σ I i L hL hlt) - hbody - (by - simpa [increaseObservationCardinalityNextGrowLoopSourceState, i'] using hwhile) - -theorem execStmt_increaseObservationCardinalityNext_growLoop - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (i : UInt256) (L : Store) - (hL : increaseObservationCardinalityNextGrowLocals σ I i L) - (hle : i.toNat ≤ (increaseObservationCardinalityNextArgWord I).toNat) - (hnewBound : (increaseObservationCardinalityNextArgWord I).toNat ≤ 65535) : - ∃ L', - ExecStmt (config v) { contract := contract v, locals := L } evm - (.while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ]) - (.ok { contract := contract v, locals := L' } - (increaseObservationCardinalityNextGrowLoopSourceState - ((increaseObservationCardinalityNextArgWord I).toNat - i.toNat) evm i)) ∧ - increaseObservationCardinalityNextGrowLocals σ I - (increaseObservationCardinalityNextArgWord I) L' := by - exact execStmt_increaseObservationCardinalityNext_growLoopAux (v := v) σ I - ((increaseObservationCardinalityNextArgWord I).toNat - i.toNat) evm i L - hL hle rfl hnewBound - -abbrev increaseObservationCardinalityNextObsNextSlotWord - (evm : EVM.State) (obsNext : UInt256) : UInt256 := - UInt256.ofNat - (fromBytes' - ((List.take 27 - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).1 ++ - List.take 2 (EVM.Word.toBytesLEWithSizeProof obsNext).1) ++ - List.drop (27 + 2) - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).1)) - -abbrev increaseObservationCardinalityNextAfterObsNextState - (evm : EVM.State) (obsNext : UInt256) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (increaseObservationCardinalityNextObsNextSlotWord evm obsNext) - -theorem storageLocStore_increaseObservationCardinalityNext_obsNext - (evm : EVM.State) (obsNext : UInt256) : - storageLocStore evm increaseObservationCardinalityNextObservationCardinalityNextLoc - (.int (Int.ofNat obsNext.toNat)) = - some (increaseObservationCardinalityNextAfterObsNextState evm obsNext) := by - unfold storageLocStore storageLocWriteWord - increaseObservationCardinalityNextObservationCardinalityNextLoc loc - increaseObservationCardinalityNextAfterObsNextState - increaseObservationCardinalityNextObsNextSlotWord - simp only [valueToWord, bind, Option.bind] - rw [show EVM.wordOfInt (Int.ofNat obsNext.toNat) = obsNext by - exact wordOfInt_ofNat_toNat _] - apply congrArg some - apply congrArg (fun w : UInt256 => - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ w) - apply u256_inj - rw [ulit_toNat'] - · rfl - · let bs := - ((List.take 27 - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).1 ++ - List.take 2 (EVM.Word.toBytesLEWithSizeProof obsNext).1) ++ - List.drop (27 + 2) - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).1) - have hlen : bs.length = 32 := by - simp [bs, List.length_take, List.length_drop, - (EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩)).2, - (EVM.Word.toBytesLEWithSizeProof obsNext).2] - apply lt_of_lt_of_le (b := 2 ^ (8 * bs.length)) - · simpa [bs] using (EVM.fromBytes'_le (bs := bs)) - · rw [hlen] - norm_num [UInt256.size] - -theorem assignStorageRef_increaseObservationCardinalityNext_obsNext_withGrowLocals - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (L : Store) - (hL : increaseObservationCardinalityNextGrowLocals σ I - (increaseObservationCardinalityNextArgWord I) L) : - assignStorageRef? (config v) { contract := contract v, locals := L } evm .storage - (slot0F "observationCardinalityNext") - (increaseObservationCardinalityNextArgValue I) = - .ok - ({ contract := contract v, locals := L }, - increaseObservationCardinalityNextAfterObsNextState evm - (increaseObservationCardinalityNextArgWord I)) := by - apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "observationCardinalityNext"] }) - (ty := .elem (.int uint16Int)) - (loc := increaseObservationCardinalityNextObservationCardinalityNextLoc) - · exact hL.slot0_get - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, uint16St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - increaseObservationCardinalityNextObservationCardinalityNextLoc, loc] - · trivial - · exact storageLocStore_increaseObservationCardinalityNext_obsNext evm - (increaseObservationCardinalityNextArgWord I) - -theorem increaseObservationCardinalityNextArgWord_lt_twoPow16 (I : ExecutionEnv) : - (increaseObservationCardinalityNextArgWord I).toNat < EVM.twoPow 16 := by - have hmask : increaseObservationCardinalityNextUint16Mask = slot0Uint16Mask := by - native_decide - simpa [increaseObservationCardinalityNextArgWord, hmask] using - slot0Uint16Mask_bound (calldataWord I.calldata 4) - -theorem increaseObservationCardinalityNextArgWord_le_65535 (I : ExecutionEnv) : - (increaseObservationCardinalityNextArgWord I).toNat ≤ 65535 := by - have hlt := increaseObservationCardinalityNextArgWord_lt_twoPow16 I - norm_num [EVM.twoPow] at hlt ⊢ - omega - -theorem evalExpr_increaseObservationCardinalityNext_newLeOld_false - {v : PoolImmutables} (evm : EVM.State) (σ : AccountMap) (I : ExecutionEnv) - (hnewGt : (increaseObservationCardinalityNextOldWord σ I).toNat < - (increaseObservationCardinalityNextArgWord I).toNat) : - evalExpr? (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStoreWithOldNew σ I } - evm (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) = - .ok (.bool false) := by - simp only [leE, evalExpr?, evalExpr_increaseObservationCardinalityNext_new_withOldNew, - evalExpr_increaseObservationCardinalityNext_old_withOldNew, EvalResult.bind, bind, - evalBinaryOp?] - simp [not_le.mpr hnewGt] - -theorem uniswapV3PoolIncreaseObservationCardinalityNextSourceGrowPrefix - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} - (howner : evm.executionEnv.codeOwner = I.codeOwner) - (holdNonzero : increaseObservationCardinalityNextOldWord evm.accountMap I ≠ ⟨0⟩) - (hnewGt : (increaseObservationCardinalityNextOldWord evm.accountMap I).toNat < - (increaseObservationCardinalityNextArgWord I).toNat) : - ∃ L', - ExecBlock (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } evm - [ .letDecl "observationCardinalityNextOld" (some uint16) - (.storage (slot0F "observationCardinalityNext")), - .letDecl "observationCardinalityNextNew" (some uint16) - (.var "observationCardinalityNext"), - .require (gtE (.var "observationCardinalityNextOld") (.intLit 0)), - Stmt.ite (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) - [ .assign .localVar (varRef "observationCardinalityNextNew") - (.var "observationCardinalityNextOld") ] - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") - (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ] ] - (.ok { contract := contract v, locals := L' } - (increaseObservationCardinalityNextGrowLoopSourceState - ((increaseObservationCardinalityNextArgWord I).toNat - - (increaseObservationCardinalityNextOldWord evm.accountMap I).toNat) - evm (increaseObservationCardinalityNextOldWord evm.accountMap I))) ∧ - increaseObservationCardinalityNextGrowLocals evm.accountMap I - (increaseObservationCardinalityNextArgWord I) L' := by - have hbranch : - ∃ L', - ExecBlock (config v) - { contract := contract v, - locals := increaseObservationCardinalityNextStoreWithOldNew evm.accountMap I } - evm - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ] - (.ok { contract := contract v, locals := L' } - (increaseObservationCardinalityNextGrowLoopSourceState - ((increaseObservationCardinalityNextArgWord I).toNat - - (increaseObservationCardinalityNextOldWord evm.accountMap I).toNat) - evm (increaseObservationCardinalityNextOldWord evm.accountMap I))) ∧ - increaseObservationCardinalityNextGrowLocals evm.accountMap I - (increaseObservationCardinalityNextArgWord I) L' := by - have hinit := - increaseObservationCardinalityNextGrowLocals_initial evm.accountMap I - (increaseObservationCardinalityNextOldWord evm.accountMap I) - obtain ⟨L', hwhile, hL'⟩ := - execStmt_increaseObservationCardinalityNext_growLoop - (v := v) evm evm.accountMap I - (increaseObservationCardinalityNextOldWord evm.accountMap I) - (increaseObservationCardinalityNextGrowStoreWithI evm.accountMap I - (increaseObservationCardinalityNextOldWord evm.accountMap I)) - hinit (by omega) (increaseObservationCardinalityNextArgWord_le_65535 I) - exact ⟨L', - ExecBlock.consNormal - (ExecStmt.letDecl - (evalExpr_increaseObservationCardinalityNext_old_withOldNew - (v := v) evm evm.accountMap I)) - (ExecBlock.consNormal hwhile ExecBlock.nil), - hL'⟩ - obtain ⟨L', helse, hL'⟩ := hbranch - refine ⟨L', ?_, hL'⟩ - refine ExecBlock.consNormal - (ExecStmt.letDecl - (evalExpr_increaseObservationCardinalityNext_oldStorage (v := v) evm I howner)) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl - (evalExpr_increaseObservationCardinalityNext_param_withOld - (v := v) evm evm.accountMap I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_increaseObservationCardinalityNext_oldGtZero_true - (v := v) evm evm.accountMap I holdNonzero)) ?_ - exact ExecBlock.consNormal - (ExecStmt.iteFalse - (evalExpr_increaseObservationCardinalityNext_newLeOld_false - (v := v) evm evm.accountMap I hnewGt) - helse) - ExecBlock.nil - -theorem uniswapV3PoolIncreaseObservationCardinalityNextSourceGrowReturns - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} - (howner : evm.executionEnv.codeOwner = I.codeOwner) - (holdNonzero : increaseObservationCardinalityNextOldWord evm.accountMap I ≠ ⟨0⟩) - (hnewGt : (increaseObservationCardinalityNextOldWord evm.accountMap I).toNat < - (increaseObservationCardinalityNextArgWord I).toNat) : - ∃ L', - ExecBlock (config v) - { contract := contract v, locals := increaseObservationCardinalityNextStore I } evm - [ .letDecl "observationCardinalityNextOld" (some uint16) - (.storage (slot0F "observationCardinalityNext")), - .letDecl "observationCardinalityNextNew" (some uint16) - (.var "observationCardinalityNext"), - .require (gtE (.var "observationCardinalityNextOld") (.intLit 0)), - Stmt.ite (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) - [ .assign .localVar (varRef "observationCardinalityNextNew") - (.var "observationCardinalityNextOld") ] - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") - (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ], - .assign .storage (slot0F "observationCardinalityNext") - (.var "observationCardinalityNextNew"), - .assign .storage (slot0F "unlocked") (.boolLit true) ] - (.ok { contract := contract v, locals := L' } - (slot0AfterUnlockState - (increaseObservationCardinalityNextAfterObsNextState - (increaseObservationCardinalityNextGrowLoopSourceState - ((increaseObservationCardinalityNextArgWord I).toNat - - (increaseObservationCardinalityNextOldWord evm.accountMap I).toNat) - evm (increaseObservationCardinalityNextOldWord evm.accountMap I)) - (increaseObservationCardinalityNextArgWord I)))) := by - obtain ⟨Lloop, hprefix, hLloop⟩ := - uniswapV3PoolIncreaseObservationCardinalityNextSourceGrowPrefix - (v := v) (evm := evm) (I := I) howner holdNonzero hnewGt - let evmLoop := - increaseObservationCardinalityNextGrowLoopSourceState - ((increaseObservationCardinalityNextArgWord I).toNat - - (increaseObservationCardinalityNextOldWord evm.accountMap I).toNat) - evm (increaseObservationCardinalityNextOldWord evm.accountMap I) - have htail : - ExecBlock (config v) { contract := contract v, locals := Lloop } evmLoop - [ .assign .storage (slot0F "observationCardinalityNext") - (.var "observationCardinalityNextNew"), - .assign .storage (slot0F "unlocked") (.boolLit true) ] - (.ok { contract := contract v, locals := Lloop } - (slot0AfterUnlockState - (increaseObservationCardinalityNextAfterObsNextState evmLoop - (increaseObservationCardinalityNextArgWord I)))) := by - refine ExecBlock.consNormal - (ExecStmt.assign - (evalExpr_increaseObservationCardinalityNext_new_withGrowLocals - (v := v) evmLoop evm.accountMap I - (increaseObservationCardinalityNextArgWord I) Lloop hLloop) - (assignStorageRef_increaseObservationCardinalityNext_obsNext_withGrowLocals - (v := v) evmLoop evm.accountMap I Lloop hLloop)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) - (assignStorageRef_increaseObservationCardinalityNext_unlocked_true - (v := v) - (increaseObservationCardinalityNextAfterObsNextState evmLoop - (increaseObservationCardinalityNextArgWord I)) - Lloop - (by - simpa [Std.HashMap.get?_eq_getElem?] using hLloop.slot0_get))) - ExecBlock.nil - refine ⟨Lloop, ?_⟩ - simpa [evmLoop] using execBlock_append hprefix htail - -theorem increaseObservationCardinalityNextGrow_i_add_one - (i : UInt256) (hlt : i.toNat < 65535) : - UInt256.ofNat (i.toNat + 1) = (⟨1⟩ : UInt256) + i := by - apply u256_inj - rw [uadd_toNat] - have hleft : (UInt256.ofNat (i.toNat + 1)).toNat = i.toNat + 1 := by - exact ulit_toNat' (i.toNat + 1) (by - norm_num [UInt256.size] - omega) - rw [hleft] - rw [show (⟨1⟩ : UInt256).toNat = 1 by rfl] - rw [Nat.mod_eq_of_lt] - · omega - · norm_num [UInt256.size] - omega - -def increaseObservationCardinalityNextGrowLoopAccountMap - (I : ExecutionEnv) : Nat → AccountMap → UInt256 → AccountMap - | 0, σ, _ => σ - | n + 1, σ, i => - increaseObservationCardinalityNextGrowLoopAccountMap I n - (sstoreAccountMap I.codeOwner σ - (increaseObservationCardinalityNextGrowObservationSlot i) - (increaseObservationCardinalityNextGrowObservationWord σ I i)) - (UInt256.ofNat (i.toNat + 1)) - -theorem increaseObservationCardinalityNext_uint16Mask_clean - (w : UInt256) (h : w.toNat < 65536) : - UInt256.land (⟨65535⟩ : UInt256) w = w := by - have hmask : (⟨65535⟩ : UInt256) = slot0Uint16Mask := by - native_decide - rw [hmask] - exact slot0Uint16Mask_clean_left (by - simpa [EVM.twoPow] using h) - -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowLoopRunAux - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} - {obsNext old arg ret : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hperm : ee.perm = true) (hov : R.length + 15 ≤ 1024) : - ∀ (n : Nat) (σ : AccountMap) (i : UInt256) (k C : ℕ), - RD code ee g s0 ⟨16139⟩ - (i :: ⟨0⟩ :: obsNext :: old :: ⟨8⟩ :: ⟨5521⟩ :: ⟨0⟩ :: old :: arg :: ret :: R) - mem aw rdata (cA, σ) k C → - i.toNat ≤ obsNext.toNat → - n = obsNext.toNat - i.toNat → - obsNext.toNat ≤ 65535 → - ∃ k' C', RD code ee g s0 ⟨5521⟩ - (obsNext :: ⟨0⟩ :: old :: arg :: ret :: R) mem aw rdata - (cA, increaseObservationCardinalityNextGrowLoopAccountMap ee n σ i) k' C' := by - intro n - induction n with - | zero => - intro σ i k C hrd hle hn _hobsBound - have hge : obsNext.toNat ≤ i.toNat := by - omega - have hiNat : i.toNat = obsNext.toNat := by - omega - have hi : i = obsNext := by - exact u256_inj hiNat - subst i - have hdone : - UInt256.isZero - (UInt256.lt - (UInt256.land (⟨65535⟩ : UInt256) obsNext) - (UInt256.land (⟨65535⟩ : UInt256) obsNext)) ≠ ⟨0⟩ := by - rw [show UInt256.lt - (UInt256.land (⟨65535⟩ : UInt256) obsNext) - (UInt256.land (⟨65535⟩ : UInt256) obsNext) = ⟨0⟩ by - exact ult_zero (by rfl)] - native_decide - obtain ⟨k', C', hrdTail⟩ := - uniswapV3PoolIncreaseObservationCardinalityNextGrowLoopExitToTail - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (R := R) (mem := mem) (aw := aw) (rdata := rdata) - (acc := (cA, σ)) (i := obsNext) (obsNext := obsNext) - (old := old) (arg := arg) (ret := ret) - hpatch hrd hdone (by omega) - exact ⟨k', C', by - simpa [increaseObservationCardinalityNextGrowLoopAccountMap] using hrdTail⟩ - | succ n ih => - intro σ i k C hrd hle hn hobsBound - have hlt : i.toNat < obsNext.toNat := by - omega - have hiBound : i.toNat < 65535 := by - omega - have hiClean : - UInt256.land (⟨65535⟩ : UInt256) i = i := - increaseObservationCardinalityNext_uint16Mask_clean i (by omega) - have hobsClean : - UInt256.land (⟨65535⟩ : UInt256) obsNext = obsNext := - increaseObservationCardinalityNext_uint16Mask_clean obsNext (by omega) - have hloop : - UInt256.isZero - (UInt256.lt - (UInt256.land (⟨65535⟩ : UInt256) i) - (UInt256.land (⟨65535⟩ : UInt256) obsNext)) = ⟨0⟩ := by - rw [hiClean, hobsClean, ult_one hlt] - native_decide - have hincOk : - UInt256.lt (UInt256.land (⟨65535⟩ : UInt256) i) - (⟨65535⟩ : UInt256) ≠ ⟨0⟩ := by - rw [hiClean, ult_one (by - rw [show (⟨65535⟩ : UInt256).toNat = 65535 by native_decide] - exact hiBound)] - native_decide - obtain ⟨k1, C1, hrd1⟩ := - uniswapV3PoolIncreaseObservationCardinalityNextGrowLoopBodyStep - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (R := R) (mem := mem) (aw := aw) (rdata := rdata) (cA := cA) - (σ := σ) (i := i) (obsNext := obsNext) (old := old) (arg := arg) - (ret := ret) hpatch hrd hloop hincOk hperm hov - let σ1 := - sstoreAccountMap ee.codeOwner σ - (increaseObservationCardinalityNextGrowObservationSlot i) - (increaseObservationCardinalityNextGrowObservationWord σ ee i) - let i' : UInt256 := UInt256.ofNat (i.toNat + 1) - have hi'toNat : i'.toNat = i.toNat + 1 := by - dsimp [i'] - exact ulit_toNat' (i.toNat + 1) (by - norm_num [UInt256.size] - omega) - have hleNext : i'.toNat ≤ obsNext.toNat := by - rw [hi'toNat] - omega - have hnNext : n = obsNext.toNat - i'.toNat := by - rw [hi'toNat] - omega - have hrd1' : RD code ee g s0 ⟨16139⟩ - (i' :: ⟨0⟩ :: obsNext :: old :: ⟨8⟩ :: ⟨5521⟩ :: - ⟨0⟩ :: old :: arg :: ret :: R) - mem aw rdata (cA, σ1) k1 C1 := by - have hnext := increaseObservationCardinalityNextGrow_i_add_one i hiBound - simpa [σ1, i', hnext] using hrd1 - obtain ⟨k', C', hrdTail⟩ := - ih σ1 i' k1 C1 hrd1' hleNext hnNext hobsBound - exact ⟨k', C', by - simpa [increaseObservationCardinalityNextGrowLoopAccountMap, σ1, i'] using hrdTail⟩ - -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowLoopRun - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} - {σ : AccountMap} {i obsNext old arg ret : UInt256} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨16139⟩ - (i :: ⟨0⟩ :: obsNext :: old :: ⟨8⟩ :: ⟨5521⟩ :: ⟨0⟩ :: old :: arg :: ret :: R) - mem aw rdata (cA, σ) k C) - (hle : i.toNat ≤ obsNext.toNat) - (hobsBound : obsNext.toNat ≤ 65535) - (hperm : ee.perm = true) (hov : R.length + 15 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨5521⟩ - (obsNext :: ⟨0⟩ :: old :: arg :: ret :: R) mem aw rdata - (cA, increaseObservationCardinalityNextGrowLoopAccountMap ee - (obsNext.toNat - i.toNat) σ i) k' C' := by - exact uniswapV3PoolIncreaseObservationCardinalityNextGrowLoopRunAux - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) (R := R) - (mem := mem) (aw := aw) (rdata := rdata) (cA := cA) (obsNext := obsNext) - (old := old) (arg := arg) (ret := ret) hpatch hperm hov - (obsNext.toNat - i.toNat) σ i k C h hle rfl hobsBound - -theorem increaseObservationCardinalityNextGrowObservationWord_equiv - {σ τ : AccountMap} {I : ExecutionEnv} (i : UInt256) - (hστ : accountMapEquiv σ τ) : - increaseObservationCardinalityNextGrowObservationWord σ I i = - increaseObservationCardinalityNextGrowObservationWord τ I i := by - unfold increaseObservationCardinalityNextGrowObservationWord codeOwnerStorageWord - rw [accountMapEquiv_storage_findD hστ I.codeOwner - (increaseObservationCardinalityNextGrowObservationSlot i) ⟨0⟩] - -theorem increaseObservationCardinalityNextGrowLoopAccountMap_equiv - {σ τ : AccountMap} {I : ExecutionEnv} (n : Nat) (i : UInt256) - (hστ : accountMapEquiv σ τ) : - accountMapEquiv - (increaseObservationCardinalityNextGrowLoopAccountMap I n σ i) - (increaseObservationCardinalityNextGrowLoopAccountMap I n τ i) := by - induction n generalizing σ τ i with - | zero => - simpa [increaseObservationCardinalityNextGrowLoopAccountMap] using hστ - | succ n ih => - have hword := increaseObservationCardinalityNextGrowObservationWord_equiv - (I := I) i hστ - have hstep : - accountMapEquiv - (sstoreAccountMap I.codeOwner σ - (increaseObservationCardinalityNextGrowObservationSlot i) - (increaseObservationCardinalityNextGrowObservationWord σ I i)) - (sstoreAccountMap I.codeOwner τ - (increaseObservationCardinalityNextGrowObservationSlot i) - (increaseObservationCardinalityNextGrowObservationWord τ I i)) := by - simpa [hword] using - accountMapEquiv_sstoreAccountMap I.codeOwner - (increaseObservationCardinalityNextGrowObservationSlot i) - (increaseObservationCardinalityNextGrowObservationWord σ I i) hστ - exact ih (UInt256.ofNat (i.toNat + 1)) hstep - -theorem increaseObservationCardinalityNextGrowObservationSlot_ne_zero - (i : UInt256) (hlt : i.toNat < 65535) : - increaseObservationCardinalityNextGrowObservationSlot i ≠ ⟨0⟩ := by - have hclean : - UInt256.land (⟨65535⟩ : UInt256) i = i := - increaseObservationCardinalityNext_uint16Mask_clean i (by omega) - have hslotNat : - (increaseObservationCardinalityNextGrowObservationSlot i).toNat = i.toNat + 8 := by - unfold increaseObservationCardinalityNextGrowObservationSlot - rw [hclean, uadd_toNat] - rw [show (⟨8⟩ : UInt256).toNat = 8 by rfl] - rw [Nat.mod_eq_of_lt (by - norm_num [UInt256.size] - omega - )] - intro hzero - have hnat := congrArg UInt256.toNat hzero - rw [hslotNat] at hnat - norm_num at hnat - -theorem increaseObservationCardinalityNextOldWord_sstore_growObservation - (σ : AccountMap) (I : ExecutionEnv) (i val : UInt256) (hlt : i.toNat < 65535) : - increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ - (increaseObservationCardinalityNextGrowObservationSlot i) val) I = - increaseObservationCardinalityNextOldWord σ I := by - have hslot : - solcSlotWord - (sstoreAccountMap I.codeOwner σ - (increaseObservationCardinalityNextGrowObservationSlot i) val) - I ⟨0⟩ = - solcSlotWord σ I ⟨0⟩ := by - simpa [solcSlotWord] using - sstoreAccountMap_storage_findD_ne σ I.codeOwner ⟨0⟩ - (increaseObservationCardinalityNextGrowObservationSlot i) val - (Ne.symm (increaseObservationCardinalityNextGrowObservationSlot_ne_zero i hlt)) - simp [increaseObservationCardinalityNextOldWord, slot0ObservationCardinalityNextWord, - slot0SlotWord, hslot] - -theorem increaseObservationCardinalityNextGrowLoopAccountMap_oldWord - (I : ExecutionEnv) : - ∀ (n : Nat) (σ : AccountMap) (i : UInt256), - i.toNat + n ≤ 65535 → - increaseObservationCardinalityNextOldWord - (increaseObservationCardinalityNextGrowLoopAccountMap I n σ i) I = - increaseObservationCardinalityNextOldWord σ I := by - intro n - induction n with - | zero => - intro σ i _hbound - simp [increaseObservationCardinalityNextGrowLoopAccountMap] - | succ n ih => - intro σ i hbound - have hiBound : i.toNat < 65535 := by omega - let σ1 := - sstoreAccountMap I.codeOwner σ - (increaseObservationCardinalityNextGrowObservationSlot i) - (increaseObservationCardinalityNextGrowObservationWord σ I i) - let i' : UInt256 := UInt256.ofNat (i.toNat + 1) - have hi'toNat : i'.toNat = i.toNat + 1 := by - dsimp [i'] - exact ulit_toNat' (i.toNat + 1) (by - norm_num [UInt256.size] - omega) - have hnextBound : i'.toNat + n ≤ 65535 := by - rw [hi'toNat] - omega - have hrec := ih σ1 i' hnextBound - have hwrite := - increaseObservationCardinalityNextOldWord_sstore_growObservation σ I i - (increaseObservationCardinalityNextGrowObservationWord σ I i) hiBound - simpa [increaseObservationCardinalityNextGrowLoopAccountMap, σ1, i'] using - hrec.trans hwrite - -theorem increaseObservationCardinalityNextGrowLoopSourceState_executionEnv - (n : Nat) (evm : EVM.State) (i : UInt256) : - (increaseObservationCardinalityNextGrowLoopSourceState n evm i).executionEnv = - evm.executionEnv := by - induction n generalizing evm i with - | zero => - simp [increaseObservationCardinalityNextGrowLoopSourceState] - | succ n ih => - simp [increaseObservationCardinalityNextGrowLoopSourceState, ih, - increaseObservationCardinalityNextGrowObservationState, storageStore_executionEnv] - -theorem increaseObservationCardinalityNextGrowLoopSourceState_createdAccounts - (n : Nat) (evm : EVM.State) (i : UInt256) : - (increaseObservationCardinalityNextGrowLoopSourceState n evm i).createdAccounts = - evm.createdAccounts := by - induction n generalizing evm i with - | zero => - simp [increaseObservationCardinalityNextGrowLoopSourceState] - | succ n ih => - simp [increaseObservationCardinalityNextGrowLoopSourceState, ih, - increaseObservationCardinalityNextGrowObservationState, storageStore_createdAccounts] - -theorem increaseObservationCardinalityNextGrowLoopSourceState_accountMap - (n : Nat) (evm : EVM.State) (I : ExecutionEnv) (i : UInt256) - (hEnv : evm.executionEnv = I) : - (increaseObservationCardinalityNextGrowLoopSourceState n evm i).accountMap = - increaseObservationCardinalityNextGrowLoopAccountMap I n evm.accountMap i := by - induction n generalizing evm i with - | zero => - simp [increaseObservationCardinalityNextGrowLoopSourceState, - increaseObservationCardinalityNextGrowLoopAccountMap] - | succ n ih => - have hEnv' : - (increaseObservationCardinalityNextGrowObservationState evm i).executionEnv = I := by - simp [increaseObservationCardinalityNextGrowObservationState, storageStore_executionEnv, - hEnv] - rw [increaseObservationCardinalityNextGrowLoopSourceState] - rw [ih (increaseObservationCardinalityNextGrowObservationState evm i) - (UInt256.ofNat (i.toNat + 1)) hEnv'] - simp [increaseObservationCardinalityNextGrowLoopAccountMap, - increaseObservationCardinalityNextGrowObservationState, storageStore_accountMap, hEnv] - -theorem natLorPackedUint16Byte216 (n field : Nat) (hfield : field < 2 ^ 16) : - Nat.lor (n % 2 ^ 216 + n / 2 ^ 232 * 2 ^ 232) (field * 2 ^ 216) = - n % 2 ^ 216 + field * 2 ^ 216 + n / 2 ^ 232 * 2 ^ 232 := by - apply Nat.eq_of_testBit_eq - intro i - change ((n % 2 ^ 216 + n / 2 ^ 232 * 2 ^ 232) ||| (field * 2 ^ 216)).testBit i = - (n % 2 ^ 216 + field * 2 ^ 216 + n / 2 ^ 232 * 2 ^ 232).testBit i - rw [Nat.testBit_or] - rw [show n % 2 ^ 216 + n / 2 ^ 232 * 2 ^ 232 = - 2 ^ 232 * (n / 2 ^ 232) + n % 2 ^ 216 by ring] - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 232) - (b_lt := lt_trans (Nat.mod_lt _ (show 0 < 2 ^ 216 by norm_num)) - (by norm_num : 2 ^ 216 < 2 ^ 232))] - rw [show n % 2 ^ 216 + field * 2 ^ 216 + n / 2 ^ 232 * 2 ^ 232 = - 2 ^ 232 * (n / 2 ^ 232) + (2 ^ 216 * field + n % 2 ^ 216) by ring] - have hmid : 2 ^ 216 * field + n % 2 ^ 216 < 2 ^ 232 := by - have hlow : n % 2 ^ 216 ≤ 2 ^ 216 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (show 0 < 2 ^ 216 by norm_num)) - have hfieldle : field ≤ 2 ^ 16 - 1 := Nat.le_pred_of_lt hfield - have hmax : 2 ^ 216 * (2 ^ 16 - 1) + (2 ^ 216 - 1) < 2 ^ 232 := by - norm_num [Nat.pow_add] - nlinarith - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 232) (b_lt := hmid)] - rw [Nat.testBit_two_pow_mul_add (a := field) - (b_lt := Nat.mod_lt _ (show 0 < 2 ^ 216 by norm_num))] - rw [show field * 2 ^ 216 = 2 ^ 216 * field + 0 by ring] - rw [Nat.testBit_two_pow_mul_add (a := field) (b_lt := show 0 < 2 ^ 216 by norm_num)] - by_cases hi216 : i < 216 - · simp [hi216] - · have h216le : 216 ≤ i := Nat.le_of_not_gt hi216 - have hlowfalse : (n % 2 ^ 216).testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le (Nat.mod_lt _ (show 0 < 2 ^ 216 by norm_num)) - (Nat.pow_le_pow_right (by norm_num) h216le)) - by_cases hi232 : i < 232 - · simp [hi216, hi232] - intro hlowtrue - have hlowfalse' : - (n % 105312291668557186697918027683670432318895095400549111254310977536).testBit i = - false := by - simpa using hlowfalse - rw [hlowfalse'] at hlowtrue - cases hlowtrue - · have hfieldfalse : field.testBit (i - 216) = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hfield (Nat.pow_le_pow_right (by norm_num) (by omega))) - simp [hi216, hi232] - intro hfieldtrue - rw [hfieldfalse] at hfieldtrue - cases hfieldtrue - -theorem increaseObservationCardinalityNextEvmObsNextSlotWord_eq - {evm : EVM.State} {σ : AccountMap} {I : ExecutionEnv} {obsNext : UInt256} - (hAccounts : accountMapEquiv σ evm.accountMap) (hEnv : evm.executionEnv = I) - (hobsLt : obsNext.toNat < 2 ^ 16) : - increaseObservationCardinalityNextEvmObsNextSlotWord σ I obsNext = - increaseObservationCardinalityNextObsNextSlotWord evm obsNext := by - have hload := increaseObservationCardinalityNextStorageLoad_codeOwner_eq - (evm := evm) (σ := σ) (I := I) hAccounts hEnv - have hclearLt : - (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 216 + - (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 232 * 2 ^ 232 < - UInt256.size := by - rw [← natLandClearObservationCardinalityNextBytes - (codeOwnerStorageWord I σ ⟨0⟩).toNat (codeOwnerStorageWord I σ ⟨0⟩).val.isLt] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [UInt256.size]) - have hpackedLt : - (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 216 + - obsNext.toNat * 2 ^ 216 + - (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 232 * 2 ^ 232 < - UInt256.size := by - have hlow : (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 216 ≤ 2 ^ 216 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (show 0 < 2 ^ 216 by norm_num)) - have hobsLe : obsNext.toNat ≤ 2 ^ 16 - 1 := Nat.le_pred_of_lt hobsLt - have hhighLt : (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 232 < 2 ^ 24 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 232 * 2 ^ 24 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change (codeOwnerStorageWord I σ ⟨0⟩).val.val < UInt256.size - exact (codeOwnerStorageWord I σ ⟨0⟩).val.isLt - have hhighLe : (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 232 ≤ 2 ^ 24 - 1 := - Nat.le_pred_of_lt hhighLt - have hmax : - (2 ^ 216 - 1) + (2 ^ 16 - 1) * 2 ^ 216 + - (2 ^ 24 - 1) * 2 ^ 232 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - nlinarith - have hmulLt : obsNext.toNat * 2 ^ 216 < UInt256.size := by - exact lt_of_lt_of_le - (Nat.mul_lt_mul_of_pos_right hobsLt (by norm_num : 0 < 2 ^ 216)) - (by norm_num [UInt256.size]) - have hmulMod : obsNext.toNat * 2 ^ 216 % UInt256.size = - obsNext.toNat * 2 ^ 216 := - Nat.mod_eq_of_lt hmulLt - have hsourceWordLt : - fromBytes' - ((List.take 27 - (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).1 ++ - List.take 2 (EVM.Word.toBytesLEWithSizeProof obsNext).1) ++ - List.drop (27 + 2) - (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).1) < - UInt256.size := by - let bs := - ((List.take 27 - (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).1 ++ - List.take 2 (EVM.Word.toBytesLEWithSizeProof obsNext).1) ++ - List.drop (27 + 2) - (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).1) - have hlen : bs.length = 32 := by - simp [bs, List.length_take, List.length_drop, - (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).2, - (EVM.Word.toBytesLEWithSizeProof obsNext).2] - apply lt_of_lt_of_le (b := 2 ^ (8 * bs.length)) - · simpa [bs] using (EVM.fromBytes'_le (bs := bs)) - · rw [hlen] - norm_num [UInt256.size] - apply u256_inj - rw [increaseObservationCardinalityNextEvmObsNextSlotWord, - increaseObservationCardinalityNextObsNextSlotWord] - rw [hload] - rw [u256_lor_toNat, u256_land_toNat, u256_mul_toNat] - rw [increaseObservationCardinalityNextNoGrowClearMask_toNat] - rw [natLandClearObservationCardinalityNextBytes] - rw [Nat.mod_eq_of_lt hclearLt] - rw [u256_land_toNat] - rw [show (⟨65535⟩ : UInt256).toNat = 2 ^ 16 - 1 by native_decide] - rw [nat_land_mask_eq_mod] - rw [Nat.mod_eq_of_lt hobsLt] - rw [Nat.mod_eq_of_lt (lt_trans hobsLt (by norm_num [UInt256.size]))] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨216⟩).toNat = 2 ^ 216 by - native_decide] - rw [hmulMod] - rw [natLorPackedUint16Byte216 _ _ hobsLt] - rw [Nat.mod_eq_of_lt hpackedLt] - rw [ulit_toNat' _ hsourceWordLt] - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - have hlen27 : - (List.take 27 (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).1).length = - 27 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof - (codeOwnerStorageWord I σ ⟨0⟩)).2] - norm_num - have hlen29 : - (List.take 27 (EVM.Word.toBytesLEWithSizeProof (codeOwnerStorageWord I σ ⟨0⟩)).1 ++ - List.take 2 (EVM.Word.toBytesLEWithSizeProof obsNext).1).length = - 29 := by - rw [List.length_append, hlen27, List.length_take, - (EVM.Word.toBytesLEWithSizeProof obsNext).2] - norm_num - rw [hlen27, hlen29] - rw [show 256 ^ (27 : Nat) = 2 ^ 216 by norm_num [Nat.pow_add]] - rw [show 256 ^ (29 : Nat) = 2 ^ 232 by norm_num [Nat.pow_add]] - rw [show 256 ^ (2 : Nat) = 2 ^ 16 by norm_num] - rw [Nat.mod_eq_of_lt hobsLt] - ring - exact (codeOwnerStorageWord I σ ⟨0⟩).val.isLt - -theorem increaseObservationCardinalityNextFinalGrowAccountMapEquiv - {evmOwner : EVM.State} {σOwnerEvm : AccountMap} {I : ExecutionEnv} - {old obsNext : UInt256} (n : Nat) - (hAccounts : accountMapEquiv σOwnerEvm evmOwner.accountMap) - (hEnv : evmOwner.executionEnv = I) - (hobsLt : obsNext.toNat < 2 ^ 16) : - accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (increaseObservationCardinalityNextGrowLoopAccountMap I n σOwnerEvm old) - ⟨0⟩ - (increaseObservationCardinalityNextEvmObsNextSlotWord - (increaseObservationCardinalityNextGrowLoopAccountMap I n σOwnerEvm old) - I obsNext)) - ⟨0⟩ - (increaseObservationCardinalityNextEvmUnlockedTrueSlotWord - (sstoreAccountMap I.codeOwner - (increaseObservationCardinalityNextGrowLoopAccountMap I n σOwnerEvm old) - ⟨0⟩ - (increaseObservationCardinalityNextEvmObsNextSlotWord - (increaseObservationCardinalityNextGrowLoopAccountMap I n σOwnerEvm old) - I obsNext)) I)) - (slot0AfterUnlockState - (increaseObservationCardinalityNextAfterObsNextState - (increaseObservationCardinalityNextGrowLoopSourceState n evmOwner old) - obsNext)).accountMap := by - have hLoopSourceMap := - increaseObservationCardinalityNextGrowLoopSourceState_accountMap - n evmOwner I old hEnv - have hLoopAccounts : - accountMapEquiv - (increaseObservationCardinalityNextGrowLoopAccountMap I n σOwnerEvm old) - (increaseObservationCardinalityNextGrowLoopSourceState n evmOwner old).accountMap := by - simpa [hLoopSourceMap] using - increaseObservationCardinalityNextGrowLoopAccountMap_equiv - (I := I) n old hAccounts - have hLoopEnv : - (increaseObservationCardinalityNextGrowLoopSourceState n evmOwner old).executionEnv = I := by - rw [increaseObservationCardinalityNextGrowLoopSourceState_executionEnv] - exact hEnv - have hfirstWord := increaseObservationCardinalityNextEvmObsNextSlotWord_eq - (evm := increaseObservationCardinalityNextGrowLoopSourceState n evmOwner old) - (σ := increaseObservationCardinalityNextGrowLoopAccountMap I n σOwnerEvm old) - (I := I) (obsNext := obsNext) hLoopAccounts hLoopEnv hobsLt - have hFirstAccounts : - accountMapEquiv - (sstoreAccountMap I.codeOwner - (increaseObservationCardinalityNextGrowLoopAccountMap I n σOwnerEvm old) - ⟨0⟩ - (increaseObservationCardinalityNextEvmObsNextSlotWord - (increaseObservationCardinalityNextGrowLoopAccountMap I n σOwnerEvm old) - I obsNext)) - (increaseObservationCardinalityNextAfterObsNextState - (increaseObservationCardinalityNextGrowLoopSourceState n evmOwner old) - obsNext).accountMap := by - rw [hfirstWord] - simpa [increaseObservationCardinalityNextAfterObsNextState, storageStore_accountMap, - hLoopEnv] using - accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (increaseObservationCardinalityNextObsNextSlotWord - (increaseObservationCardinalityNextGrowLoopSourceState n evmOwner old) - obsNext) hLoopAccounts - have hFirstEnv : - (increaseObservationCardinalityNextAfterObsNextState - (increaseObservationCardinalityNextGrowLoopSourceState n evmOwner old) - obsNext).executionEnv = I := by - simp [increaseObservationCardinalityNextAfterObsNextState, storageStore_executionEnv, - hLoopEnv] - have hsecondWord := increaseObservationCardinalityNextEvmUnlockedTrueSlotWord_eq - (evm := increaseObservationCardinalityNextAfterObsNextState - (increaseObservationCardinalityNextGrowLoopSourceState n evmOwner old) obsNext) - (σ := sstoreAccountMap I.codeOwner - (increaseObservationCardinalityNextGrowLoopAccountMap I n σOwnerEvm old) - ⟨0⟩ - (increaseObservationCardinalityNextEvmObsNextSlotWord - (increaseObservationCardinalityNextGrowLoopAccountMap I n σOwnerEvm old) - I obsNext)) - (I := I) hFirstAccounts hFirstEnv - rw [hsecondWord] - simpa [slot0AfterUnlockState, storageStore_accountMap, hFirstEnv] using - accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (slot0UnlockedTrueSlotWord - (increaseObservationCardinalityNextAfterObsNextState - (increaseObservationCardinalityNextGrowLoopSourceState n evmOwner old) obsNext)) - hFirstAccounts - -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowBranch - {v : PoolImmutables} {cA : Batteries.RBSet AccountAddress compare} - {gh : BlockHeader} {bl : ProcessedBlocks} {σ_evm σ_solm σ₀ : AccountMap} - {A : Substate} {I : ExecutionEnv} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) - (hdispatch : dispatchMsg (contract v) I.calldata = - some (increaseobservationcardinalitynextTransition v)) - (hdecode : - decodeCalldataWithMode (config v).abiDecodeMode - (List.map Param.name (increaseobservationcardinalitynextTransition v).params) - (transitionSignature (increaseobservationcardinalitynextTransition v)).paramTypes - I.calldata = - some (increaseObservationCardinalityNextStore I)) - (hsourceLockInit : - ExecBlock (config v) { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false) ] - (.ok { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I))) - (hsourceNoDelegate : - ExecBlock (config v) { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I) - [ .require (.binary .eq (.env .this) (addrLit v.original)) ] - (.ok { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) - σ₀ (Sat256.ofUInt256 g) A I))) - {kNoDelegate CNoDelegate : Nat} - (hrdNoDelegate : - RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨5493⟩ - [increaseObservationCardinalityNextArgWord I, ⟨857⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) kNoDelegate CNoDelegate) - (hAccountsAfterLock : - accountMapEquiv - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I))) - (holdNonzeroEvm : - increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) I ≠ ⟨0⟩) - (holdNonzeroSolm : - increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I)) I ≠ ⟨0⟩) - (hnewLeEvm : - ¬ UInt256.gt (increaseObservationCardinalityNextArgWord I) - (increaseObservationCardinalityNextOldWord - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I)) I) = ⟨0⟩) - (hperm : I.perm = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - let σe := sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_evm I) - let σs := sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (increaseObservationCardinalityNextLockedSlotWord σ_solm I) - let old := increaseObservationCardinalityNextOldWord σe I - let obsNext := increaseObservationCardinalityNextArgWord I - have hnewGtNat : old.toNat < obsNext.toNat := by - by_contra hnot - have hle : obsNext.toNat ≤ old.toNat := by omega - exact hnewLeEvm (by simpa [old, obsNext, σe] using ugt_zero hle) - have holdEq : - increaseObservationCardinalityNextOldWord σs I = old := by - simpa [old, σe, σs] using - increaseObservationCardinalityNextOldWord_transport hAccountsAfterLock - have hnewGtSolm : - (increaseObservationCardinalityNextOldWord σs I).toNat < obsNext.toNat := by - simpa [holdEq] using hnewGtNat - obtain ⟨_, _, hrd16137⟩ := - uniswapV3PoolIncreaseObservationCardinalityNextGrowPrefix - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [solcSelectorWord I]) (rdata := ByteArray.empty) (cA := cA) - (σ := σe) hpatch (by simpa [σe] using hrdNoDelegate) - (by simpa [old, obsNext, σe] using holdNonzeroEvm) - (by simpa [old, obsNext, σe] using hnewLeEvm) (by norm_num) - obtain ⟨_, _, hrd16139⟩ := - uniswapV3PoolIncreaseObservationCardinalityNextGrowEnterLoopHeader - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [solcSelectorWord I]) (mem := solcFreePtrMem) (aw := UInt256.ofNat 3) - (rdata := ByteArray.empty) (acc := (cA, σe)) (obsNext := obsNext) - (old := old) (arg := obsNext) (ret := ⟨857⟩) - hpatch hrd16137 (by norm_num) - obtain ⟨k5521, C5521, hrd5521₀⟩ := - uniswapV3PoolIncreaseObservationCardinalityNextGrowLoopRun - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [solcSelectorWord I]) (mem := solcFreePtrMem) (aw := UInt256.ofNat 3) - (rdata := ByteArray.empty) (cA := cA) (σ := σe) (i := old) - (obsNext := obsNext) (old := old) (arg := obsNext) (ret := ⟨857⟩) - hpatch hrd16139 (by omega) (increaseObservationCardinalityNextArgWord_le_65535 I) - hperm (by norm_num) - have holdLoop : - increaseObservationCardinalityNextOldWord - (increaseObservationCardinalityNextGrowLoopAccountMap I - (obsNext.toNat - old.toNat) σe old) I = old := by - have hobsLe : obsNext.toNat ≤ 65535 := by - simpa [obsNext] using increaseObservationCardinalityNextArgWord_le_65535 I - exact increaseObservationCardinalityNextGrowLoopAccountMap_oldWord I - (obsNext.toNat - old.toNat) σe old (by omega) - have hrd5521 : RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨5521⟩ - [obsNext, ⟨0⟩, - increaseObservationCardinalityNextOldWord - (increaseObservationCardinalityNextGrowLoopAccountMap I - (obsNext.toNat - old.toNat) σe old) I, - increaseObservationCardinalityNextArgWord I, ⟨857⟩, solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, increaseObservationCardinalityNextGrowLoopAccountMap I - (obsNext.toNat - old.toNat) σe old) k5521 C5521 := by - simpa [holdLoop, obsNext] using hrd5521₀ - have hchanged : - UInt256.land - (increaseObservationCardinalityNextOldWord - (increaseObservationCardinalityNextGrowLoopAccountMap I - (obsNext.toNat - old.toNat) σe old) I) - (⟨65535⟩ : UInt256) ≠ - UInt256.land obsNext (⟨65535⟩ : UInt256) := by - have holdBound : old.toNat < 65536 := by - simpa [old, σe, increaseObservationCardinalityNextOldWord] using - slot0Uint16Mask_bound (UInt256.div (slot0SlotWord σe I) (slot0ShiftBytes 27)) - have holdClean : UInt256.land old (⟨65535⟩ : UInt256) = old := by - rw [u256_land_comm] - exact increaseObservationCardinalityNext_uint16Mask_clean old holdBound - have hnewClean : UInt256.land obsNext (⟨65535⟩ : UInt256) = obsNext := by - rw [u256_land_comm] - exact increaseObservationCardinalityNext_uint16Mask_clean obsNext - (by have h := increaseObservationCardinalityNextArgWord_lt_twoPow16 I - simpa [obsNext, EVM.twoPow] using h) - rw [holdLoop, holdClean, hnewClean] - intro heq - have hnat := congrArg UInt256.toNat heq - omega - have hrdRet := - uniswapV3PoolIncreaseObservationCardinalityNextGrowChangedTailReturn - (v := v) (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [solcSelectorWord I]) (rdata := ByteArray.empty) (obsNext := obsNext) - (cA := cA) (σ := increaseObservationCardinalityNextGrowLoopAccountMap I - (obsNext.toNat - old.toNat) σe old) - hpatch hrd5521 hperm hchanged (by norm_num) - obtain ⟨Lgrow, hsourceGrow₀⟩ := - uniswapV3PoolIncreaseObservationCardinalityNextSourceGrowReturns - (v := v) - (evm := initState cA gh bl σs σ₀ (Sat256.ofUInt256 g) A I) - (I := I) (by simp [initState]) (by simpa [σs] using holdNonzeroSolm) - (by simpa [σs, obsNext] using hnewGtSolm) - have hsourceGrow : - ExecBlock (config v) { contract := contract v, locals := increaseObservationCardinalityNextStore I } - (initState cA gh bl σs σ₀ (Sat256.ofUInt256 g) A I) - [ .letDecl "observationCardinalityNextOld" (some uint16) - (.storage (slot0F "observationCardinalityNext")), - .letDecl "observationCardinalityNextNew" (some uint16) - (.var "observationCardinalityNext"), - .require (gtE (.var "observationCardinalityNextOld") (.intLit 0)), - Stmt.ite (leE (.var "observationCardinalityNextNew") - (.var "observationCardinalityNextOld")) - [ .assign .localVar (varRef "observationCardinalityNextNew") - (.var "observationCardinalityNextOld") ] - [ .letDecl "i" (some uint16) (.var "observationCardinalityNextOld"), - .while (ltE (.var "i") (.var "observationCardinalityNextNew")) - [ .assign .storage (observationsRawF (.var "i") "blockTimestamp") (.intLit 1), - .assign .localVar (varRef "i") (addE (.var "i") (.intLit 1)) ] ], - .assign .storage (slot0F "observationCardinalityNext") - (.var "observationCardinalityNextNew"), - .assign .storage (slot0F "unlocked") (.boolLit true) ] - (.ok { contract := contract v, locals := Lgrow } - (slot0AfterUnlockState - (increaseObservationCardinalityNextAfterObsNextState - (increaseObservationCardinalityNextGrowLoopSourceState - (obsNext.toNat - old.toNat) - (initState cA gh bl σs σ₀ (Sat256.ofUInt256 g) A I) old) - obsNext))) := by - simpa [initState, σs, old, obsNext, holdEq] using hsourceGrow₀ - have hsourceSuccess := execBlock_append hsourceNoDelegate hsourceGrow - have hbody : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (increaseObservationCardinalityNextStore I) - (increaseobservationcardinalitynextTransition v).body - (.returned { contract := contract v, locals := Lgrow } - (slot0AfterUnlockState - (increaseObservationCardinalityNextAfterObsNextState - (increaseObservationCardinalityNextGrowLoopSourceState - (obsNext.toNat - old.toNat) - (initState cA gh bl σs σ₀ (Sat256.ofUInt256 g) A I) old) - obsNext)) - none) := by - refine ExecFuncBody.execBlockOK ?_ - simpa [increaseobservationcardinalitynextTransition, σs] using - execBlock_append hsourceLockInit hsourceSuccess - exact hrdRet.reEquivExecutionGenAccountMapEquiv hcode hdispatch hdecode hbody - (by - simp [slot0AfterUnlockState, increaseObservationCardinalityNextAfterObsNextState, - increaseObservationCardinalityNextGrowLoopSourceState_createdAccounts, - storageStore_createdAccounts, initState]) - (by - exact increaseObservationCardinalityNextFinalGrowAccountMapEquiv - (evmOwner := initState cA gh bl σs σ₀ (Sat256.ofUInt256 g) A I) - (σOwnerEvm := σe) (I := I) (old := old) (obsNext := obsNext) - (obsNext.toNat - old.toNat) (by simpa [σe, σs, initState] using hAccountsAfterLock) - (by simp [initState]) (by - have h := increaseObservationCardinalityNextArgWord_lt_twoPow16 I - simpa [obsNext, EVM.twoPow] using h)) - (by - rw [show (increaseobservationcardinalitynextTransition v).returnType = [] from rfl] - exact returnEquiv.fallthrough rfl rfl (by native_decide)) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowTail.lean b/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowTail.lean deleted file mode 100644 index 7f56f1d2..00000000 --- a/Benchmarks/UniswapV3Pool/IncreaseObservationCardinalityNextGrowTail.lean +++ /dev/null @@ -1,251 +0,0 @@ -import Benchmarks.UniswapV3Pool.IncreaseObservationCardinalityNextGrow - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowTailPatchDisjoint - {v : PoolImmutables} {pc : UInt256} (hlo : 5404 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 6603) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl <;> - omega - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolIncreaseObservationCardinalityNextGrowChangedTailReturn - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {rdata : ByteArray} {obsNext : UInt256} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5521⟩ - (obsNext :: ⟨0⟩ :: increaseObservationCardinalityNextOldWord σ ee :: - increaseObservationCardinalityNextArgWord ee :: ⟨857⟩ :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hperm : ee.perm = true) - (hchanged : - UInt256.land (increaseObservationCardinalityNextOldWord σ ee) (⟨65535⟩ : UInt256) ≠ - UInt256.land obsNext (⟨65535⟩ : UInt256)) - (hov : R.length + 12 ≤ 1024) : - RDret code g s0 - (cA, sstoreAccountMap ee.codeOwner - (sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmObsNextSlotWord σ ee obsNext)) - ⟨0⟩ - (increaseObservationCardinalityNextEvmUnlockedTrueSlotWord - (sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmObsNextSlotWord σ ee obsNext)) ee)) - ByteArray.empty := by - have hdecodeBody {pc : UInt256} (hlo : 5404 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 6603) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 6603 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolIncreaseObservationCardinalityNextGrowTailPatchDisjoint hlo hhi)] - have hd5521 : decode code ⟨5521⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5522 : decode code ⟨5522⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5524 : decode code ⟨5524⟩ = some (.DUP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5525 : decode code ⟨5525⟩ = some (.SLOAD, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5526 : decode code ⟨5526⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5529 : decode code ⟨5529⟩ = some (.DUP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5530 : decode code ⟨5530⟩ = some (.DUP5, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5531 : decode code ⟨5531⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5532 : decode code ⟨5532⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5534 : decode code ⟨5534⟩ = some (.Push .PUSH1, some (⟨216⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5536 : decode code ⟨5536⟩ = some (.SHL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5537 : decode code ⟨5537⟩ = some (.DUP2, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5538 : decode code ⟨5538⟩ = some (.MUL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5539 : decode code ⟨5539⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5542 : decode code ⟨5542⟩ = some (.Push .PUSH1, some (⟨216⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5544 : decode code ⟨5544⟩ = some (.SHL, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5545 : decode code ⟨5545⟩ = some (.NOT, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5546 : decode code ⟨5546⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5547 : decode code ⟨5547⟩ = some (.SWAP4, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5548 : decode code ⟨5548⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5549 : decode code ⟨5549⟩ = some (.SWAP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5550 : decode code ⟨5550⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5551 : decode code ⟨5551⟩ = some (.SWAP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5552 : decode code ⟨5552⟩ = some (.OR, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5553 : decode code ⟨5553⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5554 : decode code ⟨5554⟩ = some (.SWAP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5555 : decode code ⟨5555⟩ = some (.SSTORE, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5556 : decode code ⟨5556⟩ = some (.SWAP2, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5557 : decode code ⟨5557⟩ = some (.SWAP3, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5558 : decode code ⟨5558⟩ = some (.POP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5559 : decode code ⟨5559⟩ = some (.DUP4, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5560 : decode code ⟨5560⟩ = some (.AND, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5561 : decode code ⟨5561⟩ = some (.EQ, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5562 : decode code ⟨5562⟩ = some (.Push .PUSH2, some (⟨5630⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have hd5565 : decode code ⟨5565⟩ = some (.JUMPI, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)]; native_decide - have rd5525 := evm_run h with [ - raw jumpdest hd5521 (by evm_ov), - raw push1 ⟨0⟩ hd5522 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd5524 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - obtain ⟨_, _, rd5526₀⟩ := rd5525.sload hd5525 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd5555 := evm_run rd5526₀ with [ - raw push2 ⟨65535⟩ hd5526 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd5529 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup5 hd5530 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5531 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨1⟩ hd5532 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨216⟩ hd5534 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd5536 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup2 hd5537 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw mul hd5538 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push2 ⟨65535⟩ hd5539 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨216⟩ hd5542 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd5544 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw not hd5545 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap1 hd5546 (by evm_ov), - raw swap4 hd5547 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5548 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap3 hd5549 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap1 hd5550 (by evm_ov), - raw swap3 hd5551 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw lor hd5552 (by evm_ov), - raw swap1 hd5553 (by evm_ov), - raw swap3 hd5554 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - obtain ⟨_, _, rd5556₀⟩ := rd5555.sstore hperm hd5555 (by evm_ov) - have rd5556 := by - simpa [increaseObservationCardinalityNextEvmObsNextSlotWord, - codeOwnerStorageWord] using rd5556₀ - have rd5565 := evm_run rd5556 with [ - raw swap2 hd5556 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap3 hd5557 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw pop hd5558 (by evm_ov), - raw dup4 hd5559 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd5560 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw eq hd5561 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push2 ⟨5630⟩ hd5562 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - exact uniswapV3PoolIncreaseObservationCardinalityNextGrowEventTailReturn - (v := v) (code := code) (ee := ee) (g := g) (s0 := s0) - (R := R) (rdata := rdata) (obsNext := obsNext) - (old := increaseObservationCardinalityNextOldWord σ ee) - (arg := increaseObservationCardinalityNextArgWord ee) (cA := cA) - (σ := sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (increaseObservationCardinalityNextEvmObsNextSlotWord σ ee obsNext)) - hpatch rd5565 hperm hchanged hov - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Initialize.lean b/Benchmarks/UniswapV3Pool/Initialize.lean deleted file mode 100644 index 21ae24a3..00000000 --- a/Benchmarks/UniswapV3Pool/Initialize.lean +++ /dev/null @@ -1,494 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatioSourceBridge -import Benchmarks.UniswapV3Pool.InitializeSourceStorageEquiv - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolInitializeBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 25 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_initialize (v := v) (cd := I.calldata) hsel - by_cases hsz36 : 36 ≤ I.calldata.size - · have hdecode := uniswapV3PoolInitializeDecodeOk (v := v) (I := I) hsz36 - by_cases hnz : slot0SqrtPriceX96Word σ_evm I ≠ ⟨0⟩ - · have hnzSolm : slot0SqrtPriceX96Word σ_solm I ≠ ⟨0⟩ := by - rw [slot0SqrtPriceX96Word_transport (σ_evm := σ_evm) (σ_solm := σ_solm) - hAccounts] - exact hnz - have hbody := uniswapV3PoolInitializeSourceAlreadyInitializedReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hwv hnzSolm - have hrd := uniswapV3PoolInitializeEvmAlreadyInitialized (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hsz36 hnz - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hzeroEvm : slot0SqrtPriceX96Word σ_evm I = ⟨0⟩ := by - by_contra hne - exact hnz hne - have hzeroSolm : slot0SqrtPriceX96Word σ_solm I = ⟨0⟩ := by - rw [slot0SqrtPriceX96Word_transport (σ_evm := σ_evm) (σ_solm := σ_solm) - hAccounts] - exact hzeroEvm - have hsourceGuard := uniswapV3PoolInitializeEvalSqrtPriceX96EqZeroTrue (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hzeroSolm - have hreachEntry := uniswapV3PoolInitializeReachEntry (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel - obtain ⟨_, _, hlenOk⟩ := - uniswapV3PoolInitializeExternalLenOk (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hpatch hreachEntry hsz36 hsize - obtain ⟨_, _, hbodyEntry⟩ := - uniswapV3PoolInitializeDecodedReachRoutine (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (mem := solcFreePtrMem) - (aw := UInt256.ofNat 3) (rdata := ByteArray.empty) (acc := (cA, σ_evm)) - hpatch hlenOk (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hgetTickEntry⟩ := - uniswapV3PoolInitializeReachGetTickAtSqrtRatio (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (mem := solcFreePtrMem) - (aw := UInt256.ofNat 3) (rdata := ByteArray.empty) (acc := (cA, σ_evm)) - hpatch hbodyEntry hzeroEvm (by simp only [List.length_singleton]; omega) - by_cases hlo : (initializeArgWord I).toNat < 4295128739 - · have hbody := uniswapV3PoolInitializeSourceGetTickLowReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hwv hzeroSolm hlo - have hrd := uniswapV3PoolGetTickAtSqrtRatioLowerRevert (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hgetTickEntry hlo - (by simp only [List.length_singleton]; omega) - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hloOk : 4295128739 ≤ (initializeArgWord I).toNat := Nat.not_lt.mp hlo - by_cases hhi : - 1461446703485210103287273052203988822378723970342 ≤ - (initializeArgWord I).toNat - · have hbody := uniswapV3PoolInitializeSourceGetTickHighReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hwv hzeroSolm hhi - have hrd := uniswapV3PoolGetTickAtSqrtRatioUpperRevert (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hgetTickEntry hloOk hhi - (by simp only [List.length_singleton]; omega) - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hhiOk : - (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342 := - Nat.lt_of_not_ge hhi - have hsourceRange := uniswapV3PoolGetTickAtSqrtRatioEvalRangeTrue (v := v) - (evm := initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (I := I) hloOk hhiOk - obtain ⟨_, _, hrangeOk⟩ := - uniswapV3PoolGetTickAtSqrtRatioRangeOk (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hgetTickEntry hloOk hhiOk - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hmsb7⟩ := - uniswapV3PoolGetTickAtSqrtRatioMsbStep7 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hrangeOk - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hmsb6⟩ := - uniswapV3PoolGetTickAtSqrtRatioMsbStep6 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hmsb7 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hmsb5⟩ := - uniswapV3PoolGetTickAtSqrtRatioMsbStep5 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hmsb6 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hmsb4⟩ := - uniswapV3PoolGetTickAtSqrtRatioMsbStep4 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hmsb5 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hmsb3⟩ := - uniswapV3PoolGetTickAtSqrtRatioMsbStep3 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hmsb4 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hmsb2⟩ := - uniswapV3PoolGetTickAtSqrtRatioMsbStep2 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hmsb3 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hmsb1⟩ := - uniswapV3PoolGetTickAtSqrtRatioMsbStep1 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hmsb2 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hmsb⟩ := - uniswapV3PoolGetTickAtSqrtRatioMsbCombine (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hmsb1 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hnormR⟩ := - uniswapV3PoolGetTickAtSqrtRatioNormalizeR (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hmsb - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog63⟩ := - uniswapV3PoolGetTickAtSqrtRatioLogStep63 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hnormR - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog62⟩ := - uniswapV3PoolGetTickAtSqrtRatioLogStep62 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog63 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog61⟩ := - uniswapV3PoolGetTickAtSqrtRatioLogStep61 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog62 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog60⟩ := - uniswapV3PoolGetTickAtSqrtRatioLogStep60 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog61 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog59⟩ := - uniswapV3PoolGetTickAtSqrtRatioLogStep59 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog60 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog58⟩ := - uniswapV3PoolGetTickAtSqrtRatioLogStep58 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog59 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog57⟩ := - uniswapV3PoolGetTickAtSqrtRatioLogStep57 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog58 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog56⟩ := - uniswapV3PoolGetTickAtSqrtRatioLogStep56 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog57 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog55⟩ := - uniswapV3PoolGetTickAtSqrtRatioLogStep55 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog56 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog54⟩ := - uniswapV3PoolGetTickAtSqrtRatioLogStep54 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog55 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog53⟩ := - uniswapV3PoolGetTickAtSqrtRatioLogStep53 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog54 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog52⟩ := - uniswapV3PoolGetTickAtSqrtRatioLogStep52 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog53 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog51⟩ := - uniswapV3PoolGetTickAtSqrtRatioLogStep51 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog52 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog2_57⟩ := - uniswapV3PoolGetTickAtSqrtRatioLog2Bits63To57 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog51 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, hlog2_50⟩ := - uniswapV3PoolGetTickAtSqrtRatioLog2Bits56To50 (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog2_57 - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, htickSetup⟩ := - uniswapV3PoolGetTickAtSqrtRatioTickEstimateSetup (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch hlog2_50 - (by simp only [List.length_singleton]; omega) - have htickEstimateIfSqrtOk : - getSqrtRatioAbsTickInRangeWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) ≠ ⟨0⟩ → - getSqrtRatioAfterAllBitsWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) - (getSqrtRatioInitialBranchWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I))) ≠ ⟨0⟩ → - ∃ k' C', RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨10793⟩ - (getTickEstimatedWord I :: ⟨0⟩ :: initializeArgWord I :: ⟨857⟩ :: - [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ_evm) k' C' := by - intro hok hratio - exact uniswapV3PoolGetTickAtSqrtRatioReturnTickEstimate (v := v) - (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, σ_evm)) hpatch htickSetup hok hratio - (by simp only [List.length_singleton]; omega) - have hobsEntryIfSqrtOk : - getSqrtRatioAbsTickInRangeWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) ≠ ⟨0⟩ → - getSqrtRatioAfterAllBitsWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) - (getSqrtRatioInitialBranchWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I))) ≠ ⟨0⟩ → - ∃ k' C', RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨17514⟩ - (UInt256.ofNat I.header.timestamp :: ⟨8⟩ :: ⟨10817⟩ :: ⟨0⟩ :: - ⟨0⟩ :: getTickEstimatedWord I :: initializeArgWord I :: ⟨857⟩ :: - [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ_evm) k' C' := by - intro hok hratio - obtain ⟨_, _, htickDone⟩ := htickEstimateIfSqrtOk hok hratio - exact uniswapV3PoolInitializeReachObservationStore (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (tick := getTickEstimatedWord I) (sqrt := initializeArgWord I) (ret := ⟨857⟩) - (R := [solcSelectorWord I]) (mem := solcFreePtrMem) (aw := UInt256.ofNat 3) - (rdata := ByteArray.empty) (acc := (cA, σ_evm)) hpatch htickDone - (by simp only [List.length_singleton]; omega) - have hobsStoreIfSqrtOk : - getSqrtRatioAbsTickInRangeWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) ≠ ⟨0⟩ → - getSqrtRatioAfterAllBitsWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) - (getSqrtRatioInitialBranchWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I))) ≠ ⟨0⟩ → - ∃ k' C', RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨10817⟩ - (⟨1⟩ :: ⟨1⟩ :: ⟨0⟩ :: ⟨0⟩ :: getTickEstimatedWord I :: - initializeArgWord I :: ⟨857⟩ :: [solcSelectorWord I]) - (initializeObservationStoreMem I) (UInt256.ofNat 8) ByteArray.empty - (cA, sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ - (initializeObservationSstoreWord σ_evm I)) - k' C' := by - intro hok hratio - obtain ⟨_, _, hobsEntry⟩ := hobsEntryIfSqrtOk hok hratio - exact uniswapV3PoolInitializeObservationStore (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (tick := getTickEstimatedWord I) (sqrt := initializeArgWord I) (ret := ⟨857⟩) - (R := [solcSelectorWord I]) (rdata := ByteArray.empty) (cA := cA) - (σ := σ_evm) hpatch hobsEntry _hperm - (by simp only [List.length_singleton]; omega) - have hslot0EventSetupIfSqrtOk : - getSqrtRatioAbsTickInRangeWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) ≠ ⟨0⟩ → - getSqrtRatioAfterAllBitsWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) - (getSqrtRatioInitialBranchWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I))) ≠ ⟨0⟩ → - ∃ k' C', RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨10904⟩ - (⟨0⟩ :: initializeSlot0ObservationCardinalityEventWord :: ⟨0⟩ :: - ⟨32⟩ :: initializeSlot0TickEventWord (getTickEstimatedWord I) :: - ⟨2⟩ :: initializeSlot0SqrtEventWord (initializeArgWord I) :: - initializeSlot0ObservationCardinalityNextEventWord :: ⟨64⟩ :: - ⟨1⟩ :: ⟨1⟩ :: ⟨0⟩ :: ⟨0⟩ :: getTickEstimatedWord I :: - initializeArgWord I :: ⟨857⟩ :: [solcSelectorWord I]) - (initializeSlot0EventMem I (initializeArgWord I) (getTickEstimatedWord I)) - (UInt256.ofNat 15) ByteArray.empty - (cA, sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ - (initializeObservationSstoreWord σ_evm I)) - k' C' := by - intro hok hratio - obtain ⟨_, _, hobsStore⟩ := hobsStoreIfSqrtOk hok hratio - exact uniswapV3PoolInitializeSlot0EventSetup (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (tick := getTickEstimatedWord I) (sqrt := initializeArgWord I) (ret := ⟨857⟩) - (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (acc := (cA, sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ - (initializeObservationSstoreWord σ_evm I))) - hpatch hobsStore (by simp only [List.length_singleton]; omega) - have hslot0StoreIfSqrtOk : - getSqrtRatioAbsTickInRangeWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) ≠ ⟨0⟩ → - getSqrtRatioAfterAllBitsWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) - (getSqrtRatioInitialBranchWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I))) ≠ ⟨0⟩ → - ∃ k' C', RD code I (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) ⟨11075⟩ - (⟨32⟩ :: initializeSlot0SqrtEventWord (initializeArgWord I) :: - initializeSlot0TickEventWord (getTickEstimatedWord I) :: ⟨64⟩ :: - ⟨1⟩ :: ⟨1⟩ :: ⟨0⟩ :: ⟨0⟩ :: getTickEstimatedWord I :: - initializeArgWord I :: ⟨857⟩ :: [solcSelectorWord I]) - (initializeSlot0EventMem I (initializeArgWord I) (getTickEstimatedWord I)) - (UInt256.ofNat 15) ByteArray.empty - (cA, sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ - (initializeObservationSstoreWord σ_evm I)) - ⟨0⟩ - (initializeSlot0SstoreWord - (sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ - (initializeObservationSstoreWord σ_evm I)) - I (initializeArgWord I) (getTickEstimatedWord I))) - k' C' := by - intro hok hratio - obtain ⟨_, _, hslot0EventSetup⟩ := hslot0EventSetupIfSqrtOk hok hratio - exact uniswapV3PoolInitializeSlot0Store (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (tick := getTickEstimatedWord I) (sqrt := initializeArgWord I) (ret := ⟨857⟩) - (R := [solcSelectorWord I]) (rdata := ByteArray.empty) (cA := cA) - (σ := sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ - (initializeObservationSstoreWord σ_evm I)) - hpatch hslot0EventSetup _hperm - (by simp only [List.length_singleton]; omega) - have hrdSuccessIfSqrtOk : - getSqrtRatioAbsTickInRangeWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) ≠ ⟨0⟩ → - getSqrtRatioAfterAllBitsWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) - (getSqrtRatioInitialBranchWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I))) ≠ ⟨0⟩ → - RDret code (Sat256.ofUInt256 g) - (initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (cA, sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ - (initializeObservationSstoreWord σ_evm I)) - ⟨0⟩ - (initializeSlot0SstoreWord - (sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ - (initializeObservationSstoreWord σ_evm I)) - I (initializeArgWord I) (getTickEstimatedWord I))) - ByteArray.empty := by - intro hok hratio - obtain ⟨_, _, hslot0Store⟩ := hslot0StoreIfSqrtOk hok hratio - exact uniswapV3PoolInitializeSlot0LogAndReturn (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (tick := getTickEstimatedWord I) (sqrt := initializeArgWord I) - (R := [solcSelectorWord I]) (rdata := ByteArray.empty) (cA := cA) - (σ := sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ - (initializeObservationSstoreWord σ_evm I)) - ⟨0⟩ - (initializeSlot0SstoreWord - (sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ - (initializeObservationSstoreWord σ_evm I)) - I (initializeArgWord I) (getTickEstimatedWord I))) - hpatch hslot0Store _hperm - (by simp only [List.length_singleton]; omega) - have hsqrtRange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272 := by - exact getSqrtRatioSourceTickHiAbsTickInt_le_maxTick I hloOk hhiOk - have hsqrtDen : getSqrtRatioSourceTickHiAfterBit524288Int I ≠ 0 := by - exact getSqrtRatioSourceTickHiAfterBit524288Int_ne_zero I - have hsqrtRet : - getSqrtRatioSourceReturnValueOf (getSqrtRatioSourceTickHiFinalRatioInt I) = - getTickSourceSqrtRatioAtTickHiValue I := by - exact getSqrtRatioSourceTickHiReturnValue_eq_word I hloOk hhiOk - have hcallee := - uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBodyOfReturnEq - (v := v) - (evm := initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) - (I := I) - hsqrtRange hsqrtDen hsqrtRet - have hfinalTick : getTickSourceFinalValue I = initializeTickValue I := by - exact getTickSourceFinalValue_eq_initializeTickValue I hloOk hhiOk - have hbody := - uniswapV3PoolInitializeSourceSuccessBodyOfSqrtRatioAtTickHi - (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) - hwv hzeroSolm hloOk hhiOk hcallee hfinalTick - have hok : - getSqrtRatioAbsTickInRangeWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) ≠ ⟨0⟩ := by - exact getSqrtRatioAbsTickInRangeWord_tickHi_ne_zero I hloOk hhiOk - (getTickHiWord_eq_source_of_bounds I hloOk hhiOk) - have hratioOk : - getSqrtRatioAfterAllBitsWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) - (getSqrtRatioInitialBranchWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I))) ≠ ⟨0⟩ := by - exact getSqrtRatioAfterAllBitsWord_tickHi_ne_zero I - have hrd := hrdSuccessIfSqrtOk hok hratioOk - exact hrd.reEquivExecutionGenAccountMapEquiv hcode hdispatch hdecode hbody - (by - simp [initializeSourceAfterStorageTailState_createdAccounts, initState]) - (by - exact Benchmarks.UniswapV3Pool.initializeSourceAfterStorageTailState_accountMapEquiv - (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) hAccounts) - (by - rw [show initializeTransition.returnType = [] from rfl] - exact returnEquiv.fallthrough rfl rfl (by native_decide)) - · have hshort : I.calldata.size < 36 := by omega - have hdecode := uniswapV3PoolInitializeDecodeShort (v := v) (I := I) hshort - have hrd := uniswapV3PoolInitializeEvmDecodeShort (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hshort - exact hrd.reEquivDecodingFailed hcode hdispatch hdecode - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeBase.lean b/Benchmarks/UniswapV3Pool/InitializeBase.lean deleted file mode 100644 index a50232dd..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeBase.lean +++ /dev/null @@ -1,1755 +0,0 @@ -import Benchmarks.UniswapV3Pool.SetFeeProtocolOwnerCall -import Benchmarks.UniswapV3Pool.Slot0 - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev initializeUint160Mask : UInt256 := UInt256.ofNat (2 ^ 160 - 1) - -abbrev initializeArgWord (I : ExecutionEnv) : UInt256 := - UInt256.land (calldataWord I.calldata 4) initializeUint160Mask - -abbrev initializeArgValue (I : ExecutionEnv) : Value := - .int (Int.ofNat (initializeArgWord I).toNat) - -abbrev initializeStore (I : ExecutionEnv) : Store := - (∅ : Store).insert "sqrtPriceX96" (initializeArgValue I) - -theorem initializeUint160Mask_toNat : - initializeUint160Mask.toNat = 2 ^ 160 - 1 := by - exact ulit_toNat' _ (by norm_num [UInt256.size]) - -theorem initializeUint160Mask_decode (w : UInt256) : - (UInt256.land w initializeUint160Mask).toNat = w.toNat % EVM.twoPow 160 := by - rw [u256_land_toNat, initializeUint160Mask_toNat, nat_land_mask_eq_mod] - exact Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num [EVM.twoPow])) - (by norm_num [EVM.twoPow, UInt256.size])) - -theorem decodeScalarWordWithMode_uint160_ok {bytes : List UInt8} {start : Nat} - (hlen : ((bytes.drop start).take 32).length = 32) : - decodeScalarWordWithMode? DecodeMode.legacySolc05 uint160 bytes start = - some - (.int (Int.ofNat - (UInt256.land (ABI.bytesToWord ((bytes.drop start).take 32)) - initializeUint160Mask).toNat), - start + 32) := by - simp only [decodeScalarWordWithMode?] - unfold readWord? readBytes? uint160 uint160Int - rw [if_pos hlen] - simp only [bind, Option.bind] - unfold decodeABIWord? - simp only [OfNat.ofNat_ne_zero, ↓reduceIte] - rw [initializeUint160Mask_decode] - rfl - -theorem decodeScalarWordsWithMode_uint160_ok {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) : - decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint160] bytes 0 = - some - [ .int (Int.ofNat - (UInt256.land (ABI.bytesToWord (bytes.take 32)) - initializeUint160Mask).toNat) ] := by - simp only [decodeScalarWordsWithMode?] - rw [decodeScalarWordWithMode_uint160_ok (bytes := bytes) (start := 0) (by simpa using hlen0)] - simp only [List.drop_zero, bind, Option.bind] - -theorem decodeScalarWordsWithMode_uint160_none_short {bytes : List UInt8} - (hshort : bytes.length < 32) : - decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint160] bytes 0 = none := by - simp only [decodeScalarWordsWithMode?] - have htake0n : ¬ (bytes.take 32).length = 32 := by - rw [List.length_take] - omega - unfold decodeScalarWordWithMode? readWord? readBytes? uint160 uint160Int - simp only [List.drop_zero] - rw [if_neg htake0n] - simp only [Option.bind, bind] - -theorem uniswapV3PoolInitializeDecodeOk {v : PoolImmutables} {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - (initializeTransition.params.map Param.name) - (transitionSignature initializeTransition).paramTypes I.calldata = - some (initializeStore I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake4 : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have hword4 : ABI.bytesToWord ((I.calldata.toList.drop 4).take 32) = - calldataWord I.calldata 4 := - decode_word_at_eq I.calldata 4 (by omega) (by norm_num) - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := initializeTransition.params.map Param.name) - (types := (transitionSignature initializeTransition).paramTypes) - (cd := I.calldata)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint160] - (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["sqrtPriceX96"] values ∅ - | none => none) = some (initializeStore I) - rw [decodeScalarWordsWithMode_uint160_ok (bytes := I.calldata.toList.drop 4) htake4] - simp [decodeCalldata.insertValues, initializeStore, initializeArgValue, initializeArgWord] - rw [hword4] - · simp [initializeTransition, transitionSignature, isABIScalarWordType, uint160] - -theorem uniswapV3PoolInitializeDecodeShort {v : PoolImmutables} {I : ExecutionEnv} - (hshort : I.calldata.size < 36) : - decodeCalldataWithMode (config v).abiDecodeMode - (initializeTransition.params.map Param.name) - (transitionSignature initializeTransition).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := initializeTransition.params.map Param.name) - (types := (transitionSignature initializeTransition).paramTypes) - (cd := I.calldata)] - · by_cases hsz4 : I.calldata.size < 4 - · rw [if_pos (by rw [htlen]; omega : I.calldata.toList.length < 4)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint160] - (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["sqrtPriceX96"] values ∅ - | none => none) = none - rw [decodeScalarWordsWithMode_uint160_none_short - (bytes := I.calldata.toList.drop 4) (by rw [List.length_drop, htlen]; omega)] - · simp [initializeTransition, transitionSignature, isABIScalarWordType, uint160] - -theorem uniswapV3PoolInitializePatchDisjointBeforeFirst {v : PoolImmutables} - {pc : UInt256} {n : Nat} (hhi : pc.toNat + n ≤ 2258) : - ∀ p ∈ patches v, pc.toNat + n ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -theorem uniswapV3PoolInitializeDecodeNoArg {v : PoolImmutables} {code : ByteArray} - {pc : UInt256} {byte : UInt8} {op : Operation} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hhi : pc.toNat + 1 ≤ 2258) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some byte) - (hparse : (some byte >>= parseInstr) = some op) - (harg : argOnNBytesOfInstr op = 0) : - decode code pc = some (op, .none) := by - refine uniswapV3PoolDecodePatchedNoArg hpatch ?_ ?_ hgetTemplate hparse harg - · have hsize : 2258 ≤ uniswapV3PoolBytecode.size := by native_decide - omega - · exact uniswapV3PoolInitializePatchDisjointBeforeFirst (v := v) (n := 1) hhi - -theorem uniswapV3PoolInitializeDecodePush1 {v : PoolImmutables} {code : ByteArray} - {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hhi : pc.toNat + 2 ≤ 2258) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x60) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1)) = n) : - decode code pc = some (.Push .PUSH1, some (n, 1)) := by - refine uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 hpatch ?_ ?_ - hgetTemplate hval - · have hsize : 2258 ≤ uniswapV3PoolBytecode.size := by native_decide - omega - · exact uniswapV3PoolInitializePatchDisjointBeforeFirst (v := v) (n := 2) hhi - -theorem uniswapV3PoolInitializeDecodePush2 {v : PoolImmutables} {code : ByteArray} - {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hhi : pc.toNat + 3 ≤ 2258) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x61) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 2)) = n) : - decode code pc = some (.Push .PUSH2, some (n, 2)) := by - refine uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush2 hpatch ?_ ?_ - hgetTemplate hval - · have hsize : 2258 ≤ uniswapV3PoolBytecode.size := by native_decide - omega - · exact uniswapV3PoolInitializePatchDisjointBeforeFirst (v := v) (n := 3) hhi - -theorem uniswapV3PoolInitializePatchDisjointBody {v : PoolImmutables} - {pc : UInt256} {n : Nat} (hlo : 10597 ≤ pc.toNat) (hhi : pc.toNat + n ≤ 11259) : - ∀ p ∈ patches v, pc.toNat + n ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -theorem uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio {v : PoolImmutables} - {pc : UInt256} {n : Nat} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + n ≤ 15650) : - ∀ p ∈ patches v, pc.toNat + n ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest10715 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨10715⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest10782 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨10782⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest13989 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨13989⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest14049 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨14049⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest14102 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨14102⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched10715 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10715⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest10715 - -theorem uniswapV3PoolJumpDestPatched10782 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10782⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest10782 - -theorem uniswapV3PoolJumpDestPatched13989 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨13989⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest13989 - -theorem uniswapV3PoolJumpDestPatched14049 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨14049⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest14049 - -theorem uniswapV3PoolJumpDestPatched14102 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨14102⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest14102 - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolDispatch_initialize {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 25 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some initializeTransition := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, - factoryTransition v, feeTransition v, feegrowthglobal0X128Transition, - feegrowthglobal1X128Transition, flashTransition v, - increaseobservationcardinalitynextTransition v]) - (post := [liquidityTransition, maxliquiditypertickTransition v, - mintTransition v, observationsTransition, observeTransition v, positionsTransition, - protocolfeesTransition, setfeeprotocolTransition v, slot0Transition, - snapshotcumulativesinsideTransition v, swapTransition v, tickbitmapTransition, - tickspacingTransition v, ticksTransition, token0Transition v, token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 25) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 25) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 25) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 25) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 25) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 25) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 25) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 25) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 5) (j := 25) - (by native_decide) hsel - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using hsel - -theorem uniswapV3PoolInitializeReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 25 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨2218⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 25 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0xf6 0x37 0x73 0x1d - (uniswapV3PoolSelNat 25) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h43 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨43⟩) hpatch h32 hgt32 - have hgt43 : UInt256.gt (armSelNat code ⟨43⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h54 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨54⟩) hpatch h43 hgt43 - have hgt54 : UInt256.gt (armSelNat code ⟨54⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h65 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨65⟩) hpatch h54 hgt54 - have hmiss22 : (uniswapV3PoolSelBytes 22 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h76 := uniswapV3PoolSelectorArmMissToOf (i := 22) (next := ⟨76⟩) - hpatch hsz hmiss22 h65 - have hmiss23 : (uniswapV3PoolSelBytes 23 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h87 := uniswapV3PoolSelectorArmMissToOf (i := 23) (next := ⟨87⟩) - hpatch hsz hmiss23 h76 - have hmiss24 : (uniswapV3PoolSelBytes 24 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h98 := uniswapV3PoolSelectorArmMissToOf (i := 24) (next := ⟨98⟩) - hpatch hsz hmiss24 h87 - have h2218 := uniswapV3PoolSelectorArmHitTo (i := 25) (target := ⟨2218⟩) - hpatch hsz hsel h98 - exact ⟨_, _, h2218⟩ - -theorem uniswapV3PoolInitializeEvmDecodeShort {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 25 == I.calldata.extract 0 4) = true) - (hshort : I.calldata.size < 36) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - have hreach := uniswapV3PoolInitializeReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - have hlt : - UInt256.lt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩ := by - apply ult_one - rw [usub_ofNat_word_toNat (by - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega) hsize] - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide] - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega - exact RD.solcExternalStaticArgsShortReverts (need := ⟨32⟩) - (entry := ⟨2218⟩) (ret := ⟨857⟩) (decoded := ⟨2240⟩) hreach - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2218⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - exact uniswapV3PoolInitializeDecodePush2 (pc := ⟨2219⟩) (n := ⟨857⟩) - hpatch (by native_decide) (by native_decide) (by native_decide)) - (by - exact uniswapV3PoolInitializeDecodePush1 (pc := ⟨2222⟩) (n := ⟨4⟩) - hpatch (by native_decide) (by native_decide) (by native_decide)) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2224⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2225⟩) (byte := 0x36) - (op := .CALLDATASIZE) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2226⟩) (byte := 0x03) - (op := .SUB) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - exact uniswapV3PoolInitializeDecodePush1 (pc := ⟨2227⟩) (n := ⟨32⟩) - hpatch (by native_decide) (by native_decide) (by native_decide)) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2229⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2230⟩) (byte := 0x10) - (op := .LT) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2231⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - exact uniswapV3PoolInitializeDecodePush2 (pc := ⟨2232⟩) (n := ⟨2240⟩) - hpatch (by native_decide) (by native_decide) (by native_decide)) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2235⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - exact uniswapV3PoolInitializeDecodePush1 (pc := ⟨2236⟩) (n := ⟨0⟩) - hpatch (by native_decide) (by native_decide) (by native_decide)) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2238⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2239⟩) (byte := 0xfd) - (op := .REVERT) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - hlt - -set_option maxHeartbeats 3000000 in -theorem uniswapV3PoolInitializeExternalLenOk {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hreach : ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨2218⟩ - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨2240⟩ - (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩ :: ⟨4⟩ :: ⟨857⟩ :: - [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact RD.solcExternalStaticArgsLenOk (need := ⟨32⟩) - (entry := ⟨2218⟩) (ret := ⟨857⟩) (decoded := ⟨2240⟩) hreach - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2218⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - exact uniswapV3PoolInitializeDecodePush2 (pc := ⟨2219⟩) (n := ⟨857⟩) - hpatch (by native_decide) (by native_decide) (by native_decide)) - (by - exact uniswapV3PoolInitializeDecodePush1 (pc := ⟨2222⟩) (n := ⟨4⟩) - hpatch (by native_decide) (by native_decide) (by native_decide)) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2224⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2225⟩) (byte := 0x36) - (op := .CALLDATASIZE) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2226⟩) (byte := 0x03) - (op := .SUB) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - exact uniswapV3PoolInitializeDecodePush1 (pc := ⟨2227⟩) (n := ⟨32⟩) - hpatch (by native_decide) (by native_decide) (by native_decide)) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2229⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2230⟩) (byte := 0x10) - (op := .LT) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2231⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - exact uniswapV3PoolInitializeDecodePush2 (pc := ⟨2232⟩) (n := ⟨2240⟩) - hpatch (by native_decide) (by native_decide) (by native_decide)) - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2235⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (solcDecodeLenCheckOkUnsigned (by simpa using hsz36) hsize) - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolInitializeDecodedReachRoutine {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {de ret : UInt256} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨2240⟩ (de :: ⟨4⟩ :: ret :: R) mem aw rdata acc k C) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨10715⟩ (initializeArgWord ee :: ret :: R) - mem aw rdata acc k' C' := by - have harg : - UInt256.land initializeUint160Mask (calldataWord ee.calldata 4) = - initializeArgWord ee := by - rw [initializeArgWord, u256_land_comm] - have rd2241 : RD code ee g s0 ⟨2241⟩ (de :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1) (C + 1) := by - simpa using h.jumpdest - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2240⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by evm_ov) - have rd2242 : RD code ee g s0 ⟨2242⟩ (⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1) (C + 1 + 2) := by - simpa using rd2241.pop - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2241⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by evm_ov) - have rd2243 : RD code ee g s0 ⟨2243⟩ (calldataWord ee.calldata 4 :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1) (C + 1 + 2 + 3) := by - simpa [calldataWord, show (⟨4⟩ : UInt256).toNat = 4 from by decide] using - (rd2242.calldataload - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2242⟩) (byte := 0x35) - (op := .CALLDATALOAD) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by evm_ov)) - have rd2245 : RD code ee g s0 ⟨2245⟩ - (⟨1⟩ :: calldataWord ee.calldata 4 :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3) := by - simpa using rd2243.push1 ⟨1⟩ - (uniswapV3PoolInitializeDecodePush1 (pc := ⟨2243⟩) (n := ⟨1⟩) - hpatch (by native_decide) (by native_decide) (by native_decide)) - (by evm_ov) - have rd2247 : RD code ee g s0 ⟨2247⟩ - (⟨1⟩ :: ⟨1⟩ :: calldataWord ee.calldata 4 :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3 + 3) := by - simpa using rd2245.push1 ⟨1⟩ - (uniswapV3PoolInitializeDecodePush1 (pc := ⟨2245⟩) (n := ⟨1⟩) - hpatch (by native_decide) (by native_decide) (by native_decide)) - (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd2249 : RD code ee g s0 ⟨2249⟩ - (⟨160⟩ :: ⟨1⟩ :: ⟨1⟩ :: calldataWord ee.calldata 4 :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1) - (C + 1 + 2 + 3 + 3 + 3 + 3) := by - simpa using rd2247.push1 ⟨160⟩ - (uniswapV3PoolInitializeDecodePush1 (pc := ⟨2247⟩) (n := ⟨160⟩) - hpatch (by native_decide) (by native_decide) (by native_decide)) - (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd2250 := by - simpa using rd2249.shl - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2249⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd2251 := by - simpa [initializeUint160Mask] using rd2250.sub - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2250⟩) (byte := 0x03) - (op := .SUB) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by evm_ov) - have rd2252 : RD code ee g s0 ⟨2252⟩ (initializeArgWord ee :: ret :: R) - mem aw rdata acc - (k + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 1 + 2 + 3 + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa [harg, initializeUint160Mask, u256_land_comm, - show (⟨2249⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ : UInt256) = ⟨2252⟩ by native_decide] using rd2251.and - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2251⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (by - simp only [List.length_cons] - omega) - have rd2255 := by - simpa using rd2252.push2 ⟨10715⟩ - (uniswapV3PoolInitializeDecodePush2 (pc := ⟨2252⟩) (n := ⟨10715⟩) - hpatch (by native_decide) (by native_decide) (by native_decide)) - (by evm_ov) - exact ⟨_, _, rd2255.jump - (by - refine uniswapV3PoolInitializeDecodeNoArg (pc := ⟨2255⟩) (byte := 0x56) - (op := .JUMP) hpatch (by native_decide) ?_ ?_ ?_ - all_goals native_decide) - (uniswapV3PoolJumpDestPatched10715 hpatch) - (by evm_ov)⟩ - -private theorem uniswapV3PoolInitializeAlreadyInitializedRevertTailWf - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcErrorStringRevertTailWf code ⟨10733⟩ ⟨2⟩ ⟨16713⟩ ⟨240⟩ .PUSH2 2 := by - have hdecode {pc : UInt256} (hlo : 10597 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 11259) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 11259 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointBody hlo hhi)] - dsimp [solcErrorStringRevertTailWf] - repeat' constructor - all_goals - rw [hdecode (by native_decide) (by native_decide)] - native_decide - -theorem uniswapV3PoolInitializeAlreadyInitializedRevert {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨10715⟩ (initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hnz : slot0SqrtPriceX96Word σ ee ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - RDrev code g s0 := by - have hdecode {pc : UInt256} (hlo : 10597 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 11259) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 11259 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointBody hlo hhi)] - have hd10715 : decode code ⟨10715⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10716 : decode code ⟨10716⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10718 : decode code ⟨10718⟩ = some (.SLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10719 : decode code ⟨10719⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10721 : decode code ⟨10721⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10723 : decode code ⟨10723⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10725 : decode code ⟨10725⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10726 : decode code ⟨10726⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10727 : decode code ⟨10727⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10728 : decode code ⟨10728⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10729 : decode code ⟨10729⟩ = some (.Push .PUSH2, some (⟨10782⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10732 : decode code ⟨10732⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd10716 := by - simpa using h.jumpdest hd10715 (by evm_ov) - have rd10718 := by - simpa using rd10716.push1 ⟨0⟩ hd10716 (by evm_ov) - obtain ⟨_, _, rd10719₀⟩ := rd10718.sload hd10718 (by evm_ov) - have rd10719 := by - simpa [slot0SlotWord, solcSlotWord] using rd10719₀ - have rd10721 := by - simpa using rd10719.push1 ⟨1⟩ hd10719 (by evm_ov) - have rd10723 := by - simpa using rd10721.push1 ⟨1⟩ hd10721 (by evm_ov) - have rd10725 := by - simpa using rd10723.push1 ⟨160⟩ hd10723 (by evm_ov) - have rd10726 := by - simpa using rd10725.shl hd10725 (by evm_ov) - have rd10727 := by - simpa [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask by native_decide] using rd10726.sub hd10726 (by evm_ov) - have rd10728 := by - simpa [slot0SqrtPriceX96Word, u256_land_comm] using rd10727.and hd10727 - (by evm_ov) - have rd10729 := by - simpa using rd10728.iszero hd10728 (by evm_ov) - have rd10732 := by - simpa using rd10729.push2 ⟨10782⟩ hd10729 (by evm_ov) - have hnzGuard := by - simpa [slot0SqrtPriceX96Word, slot0SlotWord, solcSlotWord, u256_land_comm] using hnz - have rd10733 := rd10732.jumpiNT hd10732 (isZero_eq_zero_of_ne hnzGuard) (by evm_ov) - exact RD.solcErrorStringRevertTail - (pc := ⟨10733⟩) (len := ⟨2⟩) (rawWord := ⟨16713⟩) (shift := ⟨240⟩) - (word := UInt256.shiftLeft ⟨16713⟩ ⟨240⟩) (op := .PUSH2) (width := 2) - rd10733 - (uniswapV3PoolInitializeAlreadyInitializedRevertTailWf hpatch) - (by native_decide) - rfl - solcFreePtrMem_size - solcFreePtrMem_read64 - (by simp only [List.length_cons]; omega) - -theorem uniswapV3PoolInitializeReachGetTickAtSqrtRatio {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨10715⟩ (initializeArgWord ee :: ret :: R) - mem aw rdata acc k C) - (hzero : slot0SqrtPriceX96Word acc.2 ee = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨13989⟩ - (initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 10597 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 11259) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 11259 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointBody hlo hhi)] - have hd10715 : decode code ⟨10715⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10716 : decode code ⟨10716⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10718 : decode code ⟨10718⟩ = some (.SLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10719 : decode code ⟨10719⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10721 : decode code ⟨10721⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10723 : decode code ⟨10723⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10725 : decode code ⟨10725⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10726 : decode code ⟨10726⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10727 : decode code ⟨10727⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10728 : decode code ⟨10728⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10729 : decode code ⟨10729⟩ = some (.Push .PUSH2, some (⟨10782⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10732 : decode code ⟨10732⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10782 : decode code ⟨10782⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10783 : decode code ⟨10783⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10785 : decode code ⟨10785⟩ = some (.Push .PUSH2, some (⟨10793⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10788 : decode code ⟨10788⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10789 : decode code ⟨10789⟩ = some (.Push .PUSH2, some (⟨13989⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10792 : decode code ⟨10792⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd10716 := by - simpa using h.jumpdest hd10715 (by evm_ov) - have rd10718 := by - simpa using rd10716.push1 ⟨0⟩ hd10716 (by evm_ov) - obtain ⟨_, _, rd10719₀⟩ := rd10718.sload hd10718 (by evm_ov) - have rd10719 := by - simpa [slot0SlotWord, solcSlotWord] using rd10719₀ - have rd10721 := by - simpa using rd10719.push1 ⟨1⟩ hd10719 (by evm_ov) - have rd10723 := by - simpa using rd10721.push1 ⟨1⟩ hd10721 (by evm_ov) - have rd10725 := by - simpa using rd10723.push1 ⟨160⟩ hd10723 (by evm_ov) - have rd10726 := by - simpa using rd10725.shl hd10725 (by evm_ov) - have rd10727 := by - simpa [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask by native_decide] using rd10726.sub hd10726 (by evm_ov) - have rd10728 := by - simpa [slot0SqrtPriceX96Word, u256_land_comm] using rd10727.and hd10727 - (by evm_ov) - have rd10729 := by - simpa using rd10728.iszero hd10728 (by evm_ov) - have rd10732 := by - simpa using rd10729.push2 ⟨10782⟩ hd10729 (by evm_ov) - have hzeroGuard := by - simpa [slot0SqrtPriceX96Word, slot0SlotWord, solcSlotWord, u256_land_comm] using hzero - have rd10782 := rd10732.jumpiT hd10732 (by - rw [hzeroGuard] - native_decide) - (uniswapV3PoolJumpDestPatched10782 hpatch) (by evm_ov) - have rd10783 := by - simpa using rd10782.jumpdest hd10782 (by evm_ov) - have rd10785 := by - simpa using rd10783.push1 ⟨0⟩ hd10783 (by evm_ov) - have rd10788 := by - simpa using rd10785.push2 ⟨10793⟩ hd10785 (by evm_ov) - have rd10789 := by - simpa using rd10788.dup3 hd10788 (by simp only [List.length_cons]; omega) - have rd10792 := by - simpa using rd10789.push2 ⟨13989⟩ hd10789 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd10792.jump hd10792 (uniswapV3PoolJumpDestPatched13989 hpatch) - (by simp only [List.length_cons]; omega)⟩ - -private theorem uniswapV3PoolGetTickAtSqrtRatioRRevertTailWf - {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcErrorStringRevertTailWf code ⟨14054⟩ ⟨1⟩ ⟨41⟩ ⟨249⟩ .PUSH1 1 := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - dsimp [solcErrorStringRevertTailWf] - repeat' constructor - all_goals - rw [hdecode (by native_decide) (by native_decide)] - native_decide - -theorem uniswapV3PoolGetTickAtSqrtRatioLowerRevert {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13989⟩ - (initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hlo : (initializeArgWord ee).toNat < 4295128739) - (hov : R.length + 12 ≤ 1024) : - RDrev code g s0 := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd13989 : decode code ⟨13989⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13990 : decode code ⟨13990⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13992 : decode code ⟨13992⟩ = - some (.Push .PUSH5, some (⟨4295128739⟩, 5)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13998 : decode code ⟨13998⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14000 : decode code ⟨14000⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14002 : decode code ⟨14002⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14004 : decode code ⟨14004⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14005 : decode code ⟨14005⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14006 : decode code ⟨14006⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14007 : decode code ⟨14007⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14008 : decode code ⟨14008⟩ = some (.LT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14009 : decode code ⟨14009⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14010 : decode code ⟨14010⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14011 : decode code ⟨14011⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14012 : decode code ⟨14012⟩ = some (.Push .PUSH2, some (⟨14049⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14015 : decode code ⟨14015⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14049 : decode code ⟨14049⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14050 : decode code ⟨14050⟩ = some (.Push .PUSH2, some (⟨14102⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14053 : decode code ⟨14053⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hargClean : UInt256.land (initializeArgWord ee) slot0Uint160Mask = - initializeArgWord ee := by - apply slot0Uint160Mask_clean - rw [initializeArgWord, show initializeUint160Mask = slot0Uint160Mask by native_decide] - exact slot0Uint160Mask_bound (calldataWord ee.calldata 4) - have hlt : UInt256.lt (initializeArgWord ee) ⟨4295128739⟩ = ⟨1⟩ := by - apply ult_one - rw [show (⟨4295128739⟩ : UInt256).toNat = 4295128739 from by decide] - exact hlo - have rd13990 := by - simpa using h.jumpdest hd13989 (by evm_ov) - have rd13992 := by - simpa using rd13990.push1 ⟨0⟩ hd13990 (by evm_ov) - have rd13998 := by - simpa using rd13992.pushConst (⟨4295128739⟩ : UInt256) - (by native_decide : Operation.POp.PUSH5 ≠ .PUSH0) hd13992 (by evm_ov) - have rd14000 := by - simpa using rd13998.push1 ⟨1⟩ hd13998 (by evm_ov) - have rd14002 := by - simpa using rd14000.push1 ⟨1⟩ hd14000 (by - simp only [List.length_cons] - omega) - have rd14004 := by - simpa using rd14002.push1 ⟨160⟩ hd14002 (by - simp only [List.length_cons] - omega) - have rd14005 := by - simpa using rd14004.shl hd14004 (by - simp only [List.length_cons] - omega) - have rd14006 := by - simpa [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask by native_decide] using rd14005.sub hd14005 (by evm_ov) - have rd14007 := by - simpa using rd14006.dup4 hd14006 (by - simp only [List.length_cons] - omega) - have rd14008 := by - simpa [hargClean, u256_land_comm] using rd14007.and hd14007 (by - simp only [List.length_cons] - omega) - have rd14009 := by - simpa [hlt] using rd14008.lt hd14008 (by evm_ov) - have rd14010 := by - simpa using rd14009.dup1 hd14009 (by - simp only [List.length_cons] - omega) - have rd14011 := by - simpa using rd14010.iszero hd14010 (by evm_ov) - have rd14012 := by - simpa using rd14011.swap1 hd14011 (by - simp only [List.length_cons] - omega) - have rd14015 := by - simpa using rd14012.push2 ⟨14049⟩ hd14012 (by - simp only [List.length_cons] - omega) - have rd14049 := rd14015.jumpiT hd14015 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) - (uniswapV3PoolJumpDestPatched14049 hpatch) (by - simp only [List.length_cons] - omega) - have rd14050 := by - simpa using rd14049.jumpdest hd14049 (by - simp only [List.length_cons] - omega) - have rd14053 := by - simpa using rd14050.push2 ⟨14102⟩ hd14050 (by - simp only [List.length_cons] - omega) - have rd14054 := by - simpa [show (⟨14049⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩ : UInt256) = ⟨14054⟩ - by native_decide] using - rd14053.jumpiNT hd14053 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) - (by simp only [List.length_cons]; omega) - exact RD.solcErrorStringRevertTail - (pc := ⟨14054⟩) (len := ⟨1⟩) (rawWord := ⟨41⟩) (shift := ⟨249⟩) - (word := UInt256.shiftLeft ⟨41⟩ ⟨249⟩) (op := .PUSH1) (width := 1) - rd14054 - (uniswapV3PoolGetTickAtSqrtRatioRRevertTailWf hpatch) - (by native_decide) - rfl - solcFreePtrMem_size - solcFreePtrMem_read64 - (by simp only [List.length_cons]; omega) - -theorem uniswapV3PoolGetTickAtSqrtRatioUpperRevert {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13989⟩ - (initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hlo : 4295128739 ≤ (initializeArgWord ee).toNat) - (hhi : 1461446703485210103287273052203988822378723970342 ≤ - (initializeArgWord ee).toNat) - (hov : R.length + 12 ≤ 1024) : - RDrev code g s0 := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd13989 : decode code ⟨13989⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13990 : decode code ⟨13990⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13992 : decode code ⟨13992⟩ = - some (.Push .PUSH5, some (⟨4295128739⟩, 5)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13998 : decode code ⟨13998⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14000 : decode code ⟨14000⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14002 : decode code ⟨14002⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14004 : decode code ⟨14004⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14005 : decode code ⟨14005⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14006 : decode code ⟨14006⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14007 : decode code ⟨14007⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14008 : decode code ⟨14008⟩ = some (.LT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14009 : decode code ⟨14009⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14010 : decode code ⟨14010⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14011 : decode code ⟨14011⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14012 : decode code ⟨14012⟩ = some (.Push .PUSH2, some (⟨14049⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14015 : decode code ⟨14015⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14016 : decode code ⟨14016⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14017 : decode code ⟨14017⟩ = some (.Push .PUSH20, - some (⟨1461446703485210103287273052203988822378723970342⟩, 20)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14038 : decode code ⟨14038⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14040 : decode code ⟨14040⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14042 : decode code ⟨14042⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14044 : decode code ⟨14044⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14045 : decode code ⟨14045⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14046 : decode code ⟨14046⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14047 : decode code ⟨14047⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14048 : decode code ⟨14048⟩ = some (.LT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14049 : decode code ⟨14049⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14050 : decode code ⟨14050⟩ = some (.Push .PUSH2, some (⟨14102⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14053 : decode code ⟨14053⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hargClean : UInt256.land (initializeArgWord ee) slot0Uint160Mask = - initializeArgWord ee := by - apply slot0Uint160Mask_clean - rw [initializeArgWord, show initializeUint160Mask = slot0Uint160Mask by native_decide] - exact slot0Uint160Mask_bound (calldataWord ee.calldata 4) - have hltLow : UInt256.lt (initializeArgWord ee) ⟨4295128739⟩ = ⟨0⟩ := by - apply ult_zero - rw [show (⟨4295128739⟩ : UInt256).toNat = 4295128739 from by decide] - exact hlo - have hltHigh : UInt256.lt (initializeArgWord ee) - ⟨1461446703485210103287273052203988822378723970342⟩ = ⟨0⟩ := by - apply ult_zero - rw [show (⟨1461446703485210103287273052203988822378723970342⟩ : UInt256).toNat = - 1461446703485210103287273052203988822378723970342 from by decide] - exact hhi - have rd13990 := by - simpa using h.jumpdest hd13989 (by evm_ov) - have rd13992 := by - simpa using rd13990.push1 ⟨0⟩ hd13990 (by evm_ov) - have rd13998 := by - simpa using rd13992.pushConst (⟨4295128739⟩ : UInt256) - (by native_decide : Operation.POp.PUSH5 ≠ .PUSH0) hd13992 (by evm_ov) - have rd14000 := by - simpa using rd13998.push1 ⟨1⟩ hd13998 (by evm_ov) - have rd14002 := by - simpa using rd14000.push1 ⟨1⟩ hd14000 (by - simp only [List.length_cons] - omega) - have rd14004 := by - simpa using rd14002.push1 ⟨160⟩ hd14002 (by - simp only [List.length_cons] - omega) - have rd14005 := by - simpa using rd14004.shl hd14004 (by - simp only [List.length_cons] - omega) - have rd14006 := by - simpa [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask by native_decide] using rd14005.sub hd14005 (by evm_ov) - have rd14007 := by - simpa using rd14006.dup4 hd14006 (by - simp only [List.length_cons] - omega) - have rd14008 := by - simpa [hargClean, u256_land_comm] using rd14007.and hd14007 (by - simp only [List.length_cons] - omega) - have rd14009 := by - simpa [hltLow] using rd14008.lt hd14008 (by evm_ov) - have rd14010 := by - simpa using rd14009.dup1 hd14009 (by - simp only [List.length_cons] - omega) - have rd14011 := by - simpa using rd14010.iszero hd14010 (by evm_ov) - have rd14012 := by - simpa using rd14011.swap1 hd14011 (by - simp only [List.length_cons] - omega) - have rd14015 := by - simpa using rd14012.push2 ⟨14049⟩ hd14012 (by - simp only [List.length_cons] - omega) - have rd14016 := by - simpa [show (⟨14012⟩ + UInt256.ofNat 3 + ⟨1⟩ : UInt256) = ⟨14016⟩ - by native_decide] using - rd14015.jumpiNT hd14015 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) - (by simp only [List.length_cons]; omega) - have rd14017 := by - simpa using rd14016.pop hd14016 (by evm_ov) - have rd14038 := by - simpa using rd14017.pushConst - (⟨1461446703485210103287273052203988822378723970342⟩ : UInt256) - (by native_decide : Operation.POp.PUSH20 ≠ .PUSH0) hd14017 (by evm_ov) - have rd14040 := by - simpa using rd14038.push1 ⟨1⟩ hd14038 (by evm_ov) - have rd14042 := by - simpa using rd14040.push1 ⟨1⟩ hd14040 (by - simp only [List.length_cons] - omega) - have rd14044 := by - simpa using rd14042.push1 ⟨160⟩ hd14042 (by - simp only [List.length_cons] - omega) - have rd14045 := by - simpa using rd14044.shl hd14044 (by - simp only [List.length_cons] - omega) - have rd14046 := by - simpa [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask by native_decide] using rd14045.sub hd14045 (by evm_ov) - have rd14047 := by - simpa using rd14046.dup4 hd14046 (by - simp only [List.length_cons] - omega) - have rd14048 := by - simpa [hargClean, u256_land_comm] using rd14047.and hd14047 (by - simp only [List.length_cons] - omega) - have rd14049 := by - simpa [hltHigh] using rd14048.lt hd14048 (by evm_ov) - have rd14050 := by - simpa using rd14049.jumpdest hd14049 (by - simp only [List.length_cons] - omega) - have rd14053 := by - simpa using rd14050.push2 ⟨14102⟩ hd14050 (by - simp only [List.length_cons] - omega) - have rd14054 := by - simpa [show (⟨14049⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩ : UInt256) = ⟨14054⟩ - by native_decide] using - rd14053.jumpiNT hd14053 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) - (by simp only [List.length_cons]; omega) - exact RD.solcErrorStringRevertTail - (pc := ⟨14054⟩) (len := ⟨1⟩) (rawWord := ⟨41⟩) (shift := ⟨249⟩) - (word := UInt256.shiftLeft ⟨41⟩ ⟨249⟩) (op := .PUSH1) (width := 1) - rd14054 - (uniswapV3PoolGetTickAtSqrtRatioRRevertTailWf hpatch) - (by native_decide) - rfl - solcFreePtrMem_size - solcFreePtrMem_read64 - (by simp only [List.length_cons]; omega) - -theorem uniswapV3PoolGetTickAtSqrtRatioRangeOk {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨13989⟩ - (initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hlo : 4295128739 ≤ (initializeArgWord ee).toNat) - (hhi : (initializeArgWord ee).toNat < - 1461446703485210103287273052203988822378723970342) - (hov : R.length + 12 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14102⟩ - (⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd13989 : decode code ⟨13989⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13990 : decode code ⟨13990⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13992 : decode code ⟨13992⟩ = - some (.Push .PUSH5, some (⟨4295128739⟩, 5)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd13998 : decode code ⟨13998⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14000 : decode code ⟨14000⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14002 : decode code ⟨14002⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14004 : decode code ⟨14004⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14005 : decode code ⟨14005⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14006 : decode code ⟨14006⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14007 : decode code ⟨14007⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14008 : decode code ⟨14008⟩ = some (.LT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14009 : decode code ⟨14009⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14010 : decode code ⟨14010⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14011 : decode code ⟨14011⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14012 : decode code ⟨14012⟩ = some (.Push .PUSH2, some (⟨14049⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14015 : decode code ⟨14015⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14016 : decode code ⟨14016⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14017 : decode code ⟨14017⟩ = some (.Push .PUSH20, - some (⟨1461446703485210103287273052203988822378723970342⟩, 20)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14038 : decode code ⟨14038⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14040 : decode code ⟨14040⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14042 : decode code ⟨14042⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14044 : decode code ⟨14044⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14045 : decode code ⟨14045⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14046 : decode code ⟨14046⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14047 : decode code ⟨14047⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14048 : decode code ⟨14048⟩ = some (.LT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14049 : decode code ⟨14049⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14050 : decode code ⟨14050⟩ = some (.Push .PUSH2, some (⟨14102⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14053 : decode code ⟨14053⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hargClean : UInt256.land (initializeArgWord ee) slot0Uint160Mask = - initializeArgWord ee := by - apply slot0Uint160Mask_clean - rw [initializeArgWord, show initializeUint160Mask = slot0Uint160Mask by native_decide] - exact slot0Uint160Mask_bound (calldataWord ee.calldata 4) - have hltLow : UInt256.lt (initializeArgWord ee) ⟨4295128739⟩ = ⟨0⟩ := by - apply ult_zero - rw [show (⟨4295128739⟩ : UInt256).toNat = 4295128739 from by decide] - exact hlo - have hltHigh : UInt256.lt (initializeArgWord ee) - ⟨1461446703485210103287273052203988822378723970342⟩ = ⟨1⟩ := by - apply ult_one - rw [show (⟨1461446703485210103287273052203988822378723970342⟩ : UInt256).toNat = - 1461446703485210103287273052203988822378723970342 from by decide] - exact hhi - have rd13990 := by - simpa using h.jumpdest hd13989 (by evm_ov) - have rd13992 := by - simpa using rd13990.push1 ⟨0⟩ hd13990 (by evm_ov) - have rd13998 := by - simpa using rd13992.pushConst (⟨4295128739⟩ : UInt256) - (by native_decide : Operation.POp.PUSH5 ≠ .PUSH0) hd13992 (by evm_ov) - have rd14000 := by - simpa using rd13998.push1 ⟨1⟩ hd13998 (by evm_ov) - have rd14002 := by - simpa using rd14000.push1 ⟨1⟩ hd14000 (by - simp only [List.length_cons] - omega) - have rd14004 := by - simpa using rd14002.push1 ⟨160⟩ hd14002 (by - simp only [List.length_cons] - omega) - have rd14005 := by - simpa using rd14004.shl hd14004 (by - simp only [List.length_cons] - omega) - have rd14006 := by - simpa [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask by native_decide] using rd14005.sub hd14005 (by evm_ov) - have rd14007 := by - simpa using rd14006.dup4 hd14006 (by - simp only [List.length_cons] - omega) - have rd14008 := by - simpa [hargClean, u256_land_comm] using rd14007.and hd14007 (by - simp only [List.length_cons] - omega) - have rd14009 := by - simpa [hltLow] using rd14008.lt hd14008 (by evm_ov) - have rd14010 := by - simpa using rd14009.dup1 hd14009 (by - simp only [List.length_cons] - omega) - have rd14011 := by - simpa using rd14010.iszero hd14010 (by evm_ov) - have rd14012 := by - simpa using rd14011.swap1 hd14011 (by - simp only [List.length_cons] - omega) - have rd14015 := by - simpa using rd14012.push2 ⟨14049⟩ hd14012 (by - simp only [List.length_cons] - omega) - have rd14016 := by - simpa [show (⟨14012⟩ + UInt256.ofNat 3 + ⟨1⟩ : UInt256) = ⟨14016⟩ - by native_decide] using - rd14015.jumpiNT hd14015 (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) - (by simp only [List.length_cons]; omega) - have rd14017 := by - simpa using rd14016.pop hd14016 (by evm_ov) - have rd14038 := by - simpa using rd14017.pushConst - (⟨1461446703485210103287273052203988822378723970342⟩ : UInt256) - (by native_decide : Operation.POp.PUSH20 ≠ .PUSH0) hd14017 (by evm_ov) - have rd14040 := by - simpa using rd14038.push1 ⟨1⟩ hd14038 (by evm_ov) - have rd14042 := by - simpa using rd14040.push1 ⟨1⟩ hd14040 (by - simp only [List.length_cons] - omega) - have rd14044 := by - simpa using rd14042.push1 ⟨160⟩ hd14042 (by - simp only [List.length_cons] - omega) - have rd14045 := by - simpa using rd14044.shl hd14044 (by - simp only [List.length_cons] - omega) - have rd14046 := by - simpa [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask by native_decide] using rd14045.sub hd14045 (by evm_ov) - have rd14047 := by - simpa using rd14046.dup4 hd14046 (by - simp only [List.length_cons] - omega) - have rd14048 := by - simpa [hargClean, u256_land_comm] using rd14047.and hd14047 (by - simp only [List.length_cons] - omega) - have rd14049 := by - simpa [hltHigh] using rd14048.lt hd14048 (by evm_ov) - have rd14050 := by - simpa using rd14049.jumpdest hd14049 (by - simp only [List.length_cons] - omega) - have rd14053 := by - simpa using rd14050.push2 ⟨14102⟩ hd14050 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14053.jumpiT hd14053 (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) - (uniswapV3PoolJumpDestPatched14102 hpatch) (by simp only [List.length_cons]; omega)⟩ - -theorem uniswapV3PoolInitializeEvmAlreadyInitialized {v : PoolImmutables} - {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 25 == I.calldata.extract 0 4) = true) - (hsz36 : 36 ≤ I.calldata.size) - (hnz : slot0SqrtPriceX96Word σ I ≠ ⟨0⟩) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - have hreach := uniswapV3PoolInitializeReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - obtain ⟨_, _, hdecoded⟩ := - uniswapV3PoolInitializeExternalLenOk (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) - (I := I) (g := g) hpatch hreach hsz36 hsize - obtain ⟨_, _, hbody⟩ := - uniswapV3PoolInitializeDecodedReachRoutine (v := v) (code := code) - (ee := I) (g := g) (s0 := initState cA gh bl σ σ₀ g A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (mem := solcFreePtrMem) - (aw := UInt256.ofNat 3) (rdata := ByteArray.empty) (acc := (cA, σ)) - hpatch hdecoded (by simp only [List.length_singleton]; omega) - exact uniswapV3PoolInitializeAlreadyInitializedRevert (v := v) (code := code) - (ee := I) (g := g) (s0 := initState cA gh bl σ σ₀ g A I) - (ret := ⟨857⟩) (R := [solcSelectorWord I]) (rdata := ByteArray.empty) - (cA := cA) (σ := σ) hpatch hbody hnz (by simp only [List.length_singleton]; omega) - -theorem uniswapV3PoolInitializeEvalSqrtPriceX96 {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) { contract := contract v, locals := initializeStore I } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "sqrtPriceX96")) = - .ok (.int (Int.ofNat (slot0SqrtPriceX96Word σ I).toNat)) := by - rw [evalExpr_storage_scalar - (t := .int uint160Int) - (slot := slot0F "sqrtPriceX96") - (er := { base := "slot0", steps := [.field "sqrtPriceX96"] }) - (loc := loc ⟨0⟩ ⟨0, by decide⟩ ⟨20, by decide⟩ (by decide) (.int uint160Int)) - (hbase := by simp [slot0F, initializeStore]) - (her := by - simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, uint160St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [slot0SqrtPriceX96Word, slot0SlotWord] using - slot0StorageLocLoad_sqrtPriceX96 (initState cA gh bl σ σ₀ g A I) - -theorem uniswapV3PoolInitializeEvalSqrtPriceX96EqZeroFalse {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hnz : slot0SqrtPriceX96Word σ I ≠ ⟨0⟩) : - evalExpr? (config v) { contract := contract v, locals := initializeStore I } - (initState cA gh bl σ σ₀ g A I) - (eqE (.storage (slot0F "sqrtPriceX96")) (.intLit 0)) = .ok (.bool false) := by - unfold eqE - simp only [evalExpr?, uniswapV3PoolInitializeEvalSqrtPriceX96, EvalResult.bind, bind, - pure, evalBinaryOp?] - have hnat : ¬ (slot0SqrtPriceX96Word σ I).toNat = 0 := by - intro h - apply hnz - apply u256_inj - simpa [UInt256.toNat] using h - simp [hnat] - -theorem uniswapV3PoolInitializeEvalSqrtPriceX96EqZeroTrue {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hzero : slot0SqrtPriceX96Word σ I = ⟨0⟩) : - evalExpr? (config v) { contract := contract v, locals := initializeStore I } - (initState cA gh bl σ σ₀ g A I) - (eqE (.storage (slot0F "sqrtPriceX96")) (.intLit 0)) = .ok (.bool true) := by - unfold eqE - simp only [evalExpr?, uniswapV3PoolInitializeEvalSqrtPriceX96, EvalResult.bind, bind, - pure, evalBinaryOp?] - have hnat : (slot0SqrtPriceX96Word σ I).toNat = 0 := by - rw [hzero] - rfl - simp [hnat] - -theorem uniswapV3PoolInitializeEvalSqrtPriceVar {v : PoolImmutables} - {evm I} : - evalExpr? (config v) { contract := contract v, locals := initializeStore I } - evm (.var "sqrtPriceX96") = .ok (initializeArgValue I) := by - simp [evalExpr?, initializeStore, EvalResult.ofOption] - -theorem uniswapV3PoolGetTickAtSqrtRatioEvalRangeFalseLow {v : PoolImmutables} - {evm I} (hlo : (initializeArgWord I).toNat < 4295128739) : - evalExpr? (config v) { contract := contract v, locals := initializeStore I } evm - (andE (geE (.var "sqrtPriceX96") minSqrtRatio) - (ltE (.var "sqrtPriceX96") maxSqrtRatio)) = .ok (.bool false) := by - unfold andE geE minSqrtRatio - simp only [evalExpr?, uniswapV3PoolInitializeEvalSqrtPriceVar, initializeArgValue, - EvalResult.bind, bind, pure, evalBinaryOp?] - have hnot : ¬ Int.ofNat (initializeArgWord I).toNat ≥ (4295128739 : Int) := by - change ¬ ((initializeArgWord I).toNat : Int) ≥ (4295128739 : Int) - omega - rw [show decide (Int.ofNat (initializeArgWord I).toNat ≥ (4295128739 : Int)) = false - from decide_eq_false hnot] - -theorem uniswapV3PoolGetTickAtSqrtRatioEvalRangeFalseHigh {v : PoolImmutables} - {evm I} - (hhi : 1461446703485210103287273052203988822378723970342 ≤ - (initializeArgWord I).toNat) : - evalExpr? (config v) { contract := contract v, locals := initializeStore I } evm - (andE (geE (.var "sqrtPriceX96") minSqrtRatio) - (ltE (.var "sqrtPriceX96") maxSqrtRatio)) = .ok (.bool false) := by - unfold andE geE ltE minSqrtRatio maxSqrtRatio - simp only [evalExpr?, uniswapV3PoolInitializeEvalSqrtPriceVar, initializeArgValue, - EvalResult.bind, bind, pure, evalBinaryOp?] - have hge : Int.ofNat (initializeArgWord I).toNat ≥ (4295128739 : Int) := by - change ((initializeArgWord I).toNat : Int) ≥ (4295128739 : Int) - omega - have hnot : ¬ Int.ofNat (initializeArgWord I).toNat < - (1461446703485210103287273052203988822378723970342 : Int) := by - change ¬ ((initializeArgWord I).toNat : Int) < - (1461446703485210103287273052203988822378723970342 : Int) - omega - rw [show decide (Int.ofNat (initializeArgWord I).toNat ≥ (4295128739 : Int)) = true - from decide_eq_true hge] - rw [show decide (Int.ofNat (initializeArgWord I).toNat < - (1461446703485210103287273052203988822378723970342 : Int)) = false - from decide_eq_false hnot] - -theorem uniswapV3PoolGetTickAtSqrtRatioEvalRangeTrue {v : PoolImmutables} - {evm I} (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - evalExpr? (config v) { contract := contract v, locals := initializeStore I } evm - (andE (geE (.var "sqrtPriceX96") minSqrtRatio) - (ltE (.var "sqrtPriceX96") maxSqrtRatio)) = .ok (.bool true) := by - unfold andE geE ltE minSqrtRatio maxSqrtRatio - simp only [evalExpr?, uniswapV3PoolInitializeEvalSqrtPriceVar, initializeArgValue, - EvalResult.bind, bind, pure, evalBinaryOp?] - have hge : Int.ofNat (initializeArgWord I).toNat ≥ (4295128739 : Int) := by - change ((initializeArgWord I).toNat : Int) ≥ (4295128739 : Int) - omega - have hlt : Int.ofNat (initializeArgWord I).toNat < - (1461446703485210103287273052203988822378723970342 : Int) := by - change ((initializeArgWord I).toNat : Int) < - (1461446703485210103287273052203988822378723970342 : Int) - omega - rw [show decide (Int.ofNat (initializeArgWord I).toNat ≥ (4295128739 : Int)) = true - from decide_eq_true hge] - rw [show decide (Int.ofNat (initializeArgWord I).toNat < - (1461446703485210103287273052203988822378723970342 : Int)) = true - from decide_eq_true hlt] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceRevertsLow {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hlo : (initializeArgWord I).toNat < 4295128739) : - ExecFuncBody (config v) { contract := contract v, locals := initializeStore I } - (initState cA gh bl σ σ₀ g A I) getTickAtSqrtRatioFunction.body .reverted := by - dsimp [getTickAtSqrtRatioFunction] - exact ExecFuncBody.execBlockRevert <| - ExecBlock.consRevert (ExecStmt.requireFalse - (uniswapV3PoolGetTickAtSqrtRatioEvalRangeFalseLow (v := v) hlo)) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceRevertsHigh {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hhi : 1461446703485210103287273052203988822378723970342 ≤ - (initializeArgWord I).toNat) : - ExecFuncBody (config v) { contract := contract v, locals := initializeStore I } - (initState cA gh bl σ σ₀ g A I) getTickAtSqrtRatioFunction.body .reverted := by - dsimp [getTickAtSqrtRatioFunction] - exact ExecFuncBody.execBlockRevert <| - ExecBlock.consRevert (ExecStmt.requireFalse - (uniswapV3PoolGetTickAtSqrtRatioEvalRangeFalseHigh (v := v) hhi)) - -theorem slot0SqrtPriceX96Word_transport {σ_evm σ_solm : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - slot0SqrtPriceX96Word σ_solm I = slot0SqrtPriceX96Word σ_evm I := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ (⟨0⟩ : UInt256) - dsimp [slot0SqrtPriceX96Word, slot0SlotWord, solcSlotWord] - rw [← hslot] - -theorem uniswapV3PoolInitializeSourceAlreadyInitializedReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hnz : slot0SqrtPriceX96Word σ I ≠ ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (initializeStore I) - initializeTransition.body .reverted := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (initializeStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (eqE (.storage (slot0F "sqrtPriceX96")) (.intLit 0)), - .internalCall "getTickAtSqrtRatio" [.var "sqrtPriceX96"] "tick", - .letDecl "time" (some uint32) (modE (.env .timestamp) uint32Modulus), - .assign .storage (observationsF (.intLit 0) "blockTimestamp") (.var "time"), - .assign .storage (observationsF (.intLit 0) "tickCumulative") (.intLit 0), - .assign .storage (observationsF (.intLit 0) "secondsPerLiquidityCumulativeX128") - (.intLit 0), - .assign .storage (observationsF (.intLit 0) "initialized") (.boolLit true), - .assign .storage (slot0F "sqrtPriceX96") (.var "sqrtPriceX96"), - .assign .storage (slot0F "tick") (.var "tick"), - .assign .storage (slot0F "observationIndex") (.intLit 0), - .assign .storage (slot0F "observationCardinality") (.intLit 1), - .assign .storage (slot0F "observationCardinalityNext") (.intLit 1), - .assign .storage (slot0F "feeProtocol") (.intLit 0), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted - exact ExecFuncBody.execBlockRevert <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true (by - simp [initState, hwv]))) <| - ExecBlock.consRevert (ExecStmt.requireFalse - (uniswapV3PoolInitializeEvalSqrtPriceX96EqZeroFalse (v := v) hnz)) - -theorem uniswapV3PoolInitializeSourceGetTickLowReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hzero : slot0SqrtPriceX96Word σ I = ⟨0⟩) - (hlo : (initializeArgWord I).toNat < 4295128739) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (initializeStore I) - initializeTransition.body .reverted := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (initializeStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (eqE (.storage (slot0F "sqrtPriceX96")) (.intLit 0)), - .internalCall "getTickAtSqrtRatio" [.var "sqrtPriceX96"] "tick", - .letDecl "time" (some uint32) (modE (.env .timestamp) uint32Modulus), - .assign .storage (observationsF (.intLit 0) "blockTimestamp") (.var "time"), - .assign .storage (observationsF (.intLit 0) "tickCumulative") (.intLit 0), - .assign .storage (observationsF (.intLit 0) "secondsPerLiquidityCumulativeX128") - (.intLit 0), - .assign .storage (observationsF (.intLit 0) "initialized") (.boolLit true), - .assign .storage (slot0F "sqrtPriceX96") (.var "sqrtPriceX96"), - .assign .storage (slot0F "tick") (.var "tick"), - .assign .storage (slot0F "observationIndex") (.intLit 0), - .assign .storage (slot0F "observationCardinality") (.intLit 1), - .assign .storage (slot0F "observationCardinalityNext") (.intLit 1), - .assign .storage (slot0F "feeProtocol") (.intLit 0), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted - refine ExecFuncBody.execBlockRevert <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true (by - simp [initState, hwv]))) <| - ExecBlock.consNormal (ExecStmt.requireTrue - (uniswapV3PoolInitializeEvalSqrtPriceX96EqZeroTrue (v := v) hzero)) <| - ExecBlock.consRevert ?_ - refine internalCallFunctionRevert (callee := getTickAtSqrtRatioFunction) - (argVals := [initializeArgValue I]) (locals := initializeStore I) ?_ ?_ ?_ ?_ - · simp [evalExprs?, uniswapV3PoolInitializeEvalSqrtPriceVar, EvalResult.bind, bind, pure] - · simp [lookupCallable?, lookupFunction?, contract, functions, getSqrtRatioAtTickFunction, - getTickAtSqrtRatioFunction] - · rfl - · exact uniswapV3PoolGetTickAtSqrtRatioSourceRevertsLow (v := v) hlo - -theorem uniswapV3PoolInitializeSourceGetTickHighReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hzero : slot0SqrtPriceX96Word σ I = ⟨0⟩) - (hhi : 1461446703485210103287273052203988822378723970342 ≤ - (initializeArgWord I).toNat) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (initializeStore I) - initializeTransition.body .reverted := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (initializeStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (eqE (.storage (slot0F "sqrtPriceX96")) (.intLit 0)), - .internalCall "getTickAtSqrtRatio" [.var "sqrtPriceX96"] "tick", - .letDecl "time" (some uint32) (modE (.env .timestamp) uint32Modulus), - .assign .storage (observationsF (.intLit 0) "blockTimestamp") (.var "time"), - .assign .storage (observationsF (.intLit 0) "tickCumulative") (.intLit 0), - .assign .storage (observationsF (.intLit 0) "secondsPerLiquidityCumulativeX128") - (.intLit 0), - .assign .storage (observationsF (.intLit 0) "initialized") (.boolLit true), - .assign .storage (slot0F "sqrtPriceX96") (.var "sqrtPriceX96"), - .assign .storage (slot0F "tick") (.var "tick"), - .assign .storage (slot0F "observationIndex") (.intLit 0), - .assign .storage (slot0F "observationCardinality") (.intLit 1), - .assign .storage (slot0F "observationCardinalityNext") (.intLit 1), - .assign .storage (slot0F "feeProtocol") (.intLit 0), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted - refine ExecFuncBody.execBlockRevert <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true (by - simp [initState, hwv]))) <| - ExecBlock.consNormal (ExecStmt.requireTrue - (uniswapV3PoolInitializeEvalSqrtPriceX96EqZeroTrue (v := v) hzero)) <| - ExecBlock.consRevert ?_ - refine internalCallFunctionRevert (callee := getTickAtSqrtRatioFunction) - (argVals := [initializeArgValue I]) (locals := initializeStore I) ?_ ?_ ?_ ?_ - · simp [evalExprs?, uniswapV3PoolInitializeEvalSqrtPriceVar, EvalResult.bind, bind, pure] - · simp [lookupCallable?, lookupFunction?, contract, functions, getSqrtRatioAtTickFunction, - getTickAtSqrtRatioFunction] - · rfl - · exact uniswapV3PoolGetTickAtSqrtRatioSourceRevertsHigh (v := v) hhi - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTick.lean b/Benchmarks/UniswapV3Pool/InitializeGetTick.lean deleted file mode 100644 index 8a6278c2..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeGetTick.lean +++ /dev/null @@ -1,1430 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeBase - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev getTickRatioMask : UInt256 := - ⟨6277101735386680763835789423207666416102355444459739545600⟩ - -abbrev getTickRatioWord (ee : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.shiftLeft (initializeArgWord ee) ⟨32⟩) getTickRatioMask - -abbrev getTickMsbThreshold7 : UInt256 := - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨1⟩ - -abbrev getTickMsbF7Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftLeft (UInt256.gt (getTickRatioWord ee) getTickMsbThreshold7) ⟨7⟩ - -abbrev getTickRAfterMsb7Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickRatioWord ee) (getTickMsbF7Word ee) - -abbrev getTickMsbThreshold6 : UInt256 := ⟨18446744073709551615⟩ - -abbrev getTickMsbF6Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftLeft (UInt256.gt (getTickRAfterMsb7Word ee) getTickMsbThreshold6) ⟨6⟩ - -abbrev getTickRAfterMsb6Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickRAfterMsb7Word ee) (getTickMsbF6Word ee) - -abbrev getTickMsbThreshold5 : UInt256 := ⟨4294967295⟩ - -abbrev getTickMsbF5Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftLeft (UInt256.gt (getTickRAfterMsb6Word ee) getTickMsbThreshold5) ⟨5⟩ - -abbrev getTickRAfterMsb5Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickRAfterMsb6Word ee) (getTickMsbF5Word ee) - -abbrev getTickMsbThreshold4 : UInt256 := ⟨65535⟩ - -abbrev getTickMsbF4Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftLeft (UInt256.gt (getTickRAfterMsb5Word ee) getTickMsbThreshold4) ⟨4⟩ - -abbrev getTickRAfterMsb4Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickRAfterMsb5Word ee) (getTickMsbF4Word ee) - -abbrev getTickMsbThreshold3 : UInt256 := ⟨255⟩ - -abbrev getTickMsbF3Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftLeft (UInt256.gt (getTickRAfterMsb4Word ee) getTickMsbThreshold3) ⟨3⟩ - -abbrev getTickRAfterMsb3Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickRAfterMsb4Word ee) (getTickMsbF3Word ee) - -abbrev getTickMsbThreshold2 : UInt256 := ⟨15⟩ - -abbrev getTickMsbF2Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftLeft (UInt256.gt (getTickRAfterMsb3Word ee) getTickMsbThreshold2) ⟨2⟩ - -abbrev getTickRAfterMsb2Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickRAfterMsb3Word ee) (getTickMsbF2Word ee) - -abbrev getTickMsbThreshold1 : UInt256 := ⟨3⟩ - -abbrev getTickMsbF1Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftLeft (UInt256.gt (getTickRAfterMsb2Word ee) getTickMsbThreshold1) ⟨1⟩ - -abbrev getTickRAfterMsb1Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickRAfterMsb2Word ee) (getTickMsbF1Word ee) - -abbrev getTickMsbF0Word (ee : ExecutionEnv) : UInt256 := - UInt256.gt (getTickRAfterMsb1Word ee) ⟨1⟩ - -abbrev getTickMsbF67Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickMsbF6Word ee) (getTickMsbF7Word ee) - -abbrev getTickMsbF567Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickMsbF5Word ee) (getTickMsbF67Word ee) - -abbrev getTickMsbF4567Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickMsbF4Word ee) (getTickMsbF567Word ee) - -abbrev getTickMsbF34567Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickMsbF4567Word ee) (getTickMsbF3Word ee) - -abbrev getTickMsbF234567Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickMsbF2Word ee) (getTickMsbF34567Word ee) - -abbrev getTickMsbF1234567Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickMsbF234567Word ee) (getTickMsbF1Word ee) - -abbrev getTickMsbWord (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickMsbF1234567Word ee) (getTickMsbF0Word ee) - -abbrev getTickRNormalizedHighWord (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickRatioWord ee) (UInt256.sub (getTickMsbWord ee) ⟨127⟩) - -abbrev getTickRNormalizedLowWord (ee : ExecutionEnv) : UInt256 := - UInt256.shiftLeft (getTickRatioWord ee) (UInt256.sub ⟨127⟩ (getTickMsbWord ee)) - -abbrev getTickRNormalizedWord (ee : ExecutionEnv) : UInt256 := - if UInt256.lt (getTickMsbWord ee) ⟨128⟩ = ⟨0⟩ then - getTickRNormalizedHighWord ee - else - getTickRNormalizedLowWord ee - -abbrev getTickLogRSquared63Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickRNormalizedWord ee) (getTickRNormalizedWord ee) - -abbrev getTickLogRShifted63Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared63Word ee) ⟨127⟩ - -abbrev getTickLogF63Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared63Word ee) ⟨255⟩ - -abbrev getTickLogRAfter63Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRShifted63Word ee) (getTickLogF63Word ee) - -abbrev getTickLogRSquared62Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLogRAfter63Word ee) (getTickLogRAfter63Word ee) - -abbrev getTickLogRShifted62Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared62Word ee) ⟨127⟩ - -abbrev getTickLogF62Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared62Word ee) ⟨255⟩ - -abbrev getTickLogRAfter62Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRShifted62Word ee) (getTickLogF62Word ee) - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest14263 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨14263⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest14273 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨14273⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched14263 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨14263⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest14263 - -theorem uniswapV3PoolJumpDestPatched14273 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨14273⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest14273 - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioMsbStep7 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14102⟩ - (⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 15 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14150⟩ - (getTickRAfterMsb7Word ee :: getTickMsbF7Word ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14102 : decode code ⟨14102⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14103 : decode code ⟨14103⟩ = - some (.Push .PUSH24, some (getTickRatioMask, 24)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14128 : decode code ⟨14128⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14130 : decode code ⟨14130⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14131 : decode code ⟨14131⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14132 : decode code ⟨14132⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14133 : decode code ⟨14133⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14134 : decode code ⟨14134⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14136 : decode code ⟨14136⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14138 : decode code ⟨14138⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14140 : decode code ⟨14140⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14141 : decode code ⟨14141⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14142 : decode code ⟨14142⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14143 : decode code ⟨14143⟩ = some (.GT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14144 : decode code ⟨14144⟩ = some (.Push .PUSH1, some (⟨7⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14146 : decode code ⟨14146⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14147 : decode code ⟨14147⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14148 : decode code ⟨14148⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14149 : decode code ⟨14149⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14103 := by - simpa using h.jumpdest hd14102 (by - simp only [List.length_cons] - omega) - have rd14128 := by - simpa using rd14103.pushConst getTickRatioMask - (by native_decide : Operation.POp.PUSH24 ≠ .PUSH0) hd14103 (by - simp only [List.length_cons] - omega) - have rd14130 := by - simpa using rd14128.push1 ⟨32⟩ hd14128 (by - simp only [List.length_cons] - omega) - have rd14131 := by - simpa using rd14130.dup4 hd14130 (by - simp only [List.length_cons] - omega) - have rd14132 := by - simpa using rd14131.swap1 hd14131 (by - simp only [List.length_cons] - omega) - have rd14133 := by - simpa using rd14132.shl hd14132 (by - simp only [List.length_cons] - omega) - have rd14134 := by - simpa [getTickRatioWord] using rd14133.and hd14133 (by - simp only [List.length_cons] - omega) - have rd14136 := by - simpa using rd14134.push1 ⟨1⟩ hd14134 (by - simp only [List.length_cons] - omega) - have rd14138 := by - simpa using rd14136.push1 ⟨1⟩ hd14136 (by - simp only [List.length_cons] - omega) - have rd14140 := by - simpa using rd14138.push1 ⟨128⟩ hd14138 (by - simp only [List.length_cons] - omega) - have rd14141 := by - simpa using rd14140.shl hd14140 (by - simp only [List.length_cons] - omega) - have rd14142 := by - simpa [getTickMsbThreshold7] using rd14141.sub hd14141 (by - simp only [List.length_cons] - omega) - have rd14143 := by - simpa using rd14142.dup2 hd14142 (by - simp only [List.length_cons] - omega) - have rd14144 := by - simpa using rd14143.gt hd14143 (by - simp only [List.length_cons] - omega) - have rd14146 := by - simpa using rd14144.push1 ⟨7⟩ hd14144 (by - simp only [List.length_cons] - omega) - have rd14147 := by - simpa [getTickMsbF7Word] using rd14146.shl hd14146 (by - simp only [List.length_cons] - omega) - have rd14148 := by - simpa using rd14147.dup2 hd14147 (by - simp only [List.length_cons] - omega) - have rd14149 := by - simpa using rd14148.dup2 hd14148 (by - simp only [List.length_cons] - omega) - have rd14150 := by - simpa [getTickRAfterMsb7Word] using rd14149.shr hd14149 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14150⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioMsbStep6 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14150⟩ - (getTickRAfterMsb7Word ee :: getTickMsbF7Word ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 15 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14167⟩ - (getTickRAfterMsb6Word ee :: getTickMsbF6Word ee :: getTickMsbF7Word ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14150 : decode code ⟨14150⟩ = - some (.Push .PUSH8, some (getTickMsbThreshold6, 8)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14159 : decode code ⟨14159⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14160 : decode code ⟨14160⟩ = some (.GT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14161 : decode code ⟨14161⟩ = some (.Push .PUSH1, some (⟨6⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14163 : decode code ⟨14163⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14164 : decode code ⟨14164⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14165 : decode code ⟨14165⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14166 : decode code ⟨14166⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14159 := by - simpa using h.pushConst getTickMsbThreshold6 - (by native_decide : Operation.POp.PUSH8 ≠ .PUSH0) hd14150 (by - simp only [List.length_cons] - omega) - have rd14160 := by - simpa using rd14159.dup2 hd14159 (by - simp only [List.length_cons] - omega) - have rd14161 := by - simpa using rd14160.gt hd14160 (by - simp only [List.length_cons] - omega) - have rd14163 := by - simpa using rd14161.push1 ⟨6⟩ hd14161 (by - simp only [List.length_cons] - omega) - have rd14164 := by - simpa [getTickMsbF6Word] using rd14163.shl hd14163 (by - simp only [List.length_cons] - omega) - have rd14165 := by - simpa using rd14164.swap1 hd14164 (by - simp only [List.length_cons] - omega) - have rd14166 := by - simpa using rd14165.dup2 hd14165 (by - simp only [List.length_cons] - omega) - have rd14167 := by - simpa [getTickRAfterMsb6Word] using rd14166.shr hd14166 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14167⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioMsbStep5 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14167⟩ - (getTickRAfterMsb6Word ee :: getTickMsbF6Word ee :: getTickMsbF7Word ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 15 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14180⟩ - (getTickRAfterMsb5Word ee :: getTickMsbF5Word ee :: getTickMsbF6Word ee :: - getTickMsbF7Word ee :: getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: - ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14167 : decode code ⟨14167⟩ = - some (.Push .PUSH4, some (getTickMsbThreshold5, 4)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14172 : decode code ⟨14172⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14173 : decode code ⟨14173⟩ = some (.GT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14174 : decode code ⟨14174⟩ = some (.Push .PUSH1, some (⟨5⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14176 : decode code ⟨14176⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14177 : decode code ⟨14177⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14178 : decode code ⟨14178⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14179 : decode code ⟨14179⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14172 := by - simpa using h.pushConst getTickMsbThreshold5 - (by native_decide : Operation.POp.PUSH4 ≠ .PUSH0) hd14167 (by - simp only [List.length_cons] - omega) - have rd14173 := by - simpa using rd14172.dup2 hd14172 (by - simp only [List.length_cons] - omega) - have rd14174 := by - simpa using rd14173.gt hd14173 (by - simp only [List.length_cons] - omega) - have rd14176 := by - simpa using rd14174.push1 ⟨5⟩ hd14174 (by - simp only [List.length_cons] - omega) - have rd14177 := by - simpa [getTickMsbF5Word] using rd14176.shl hd14176 (by - simp only [List.length_cons] - omega) - have rd14178 := by - simpa using rd14177.swap1 hd14177 (by - simp only [List.length_cons] - omega) - have rd14179 := by - simpa using rd14178.dup2 hd14178 (by - simp only [List.length_cons] - omega) - have rd14180 := by - simpa [getTickRAfterMsb5Word] using rd14179.shr hd14179 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14180⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioMsbStep4 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14180⟩ - (getTickRAfterMsb5Word ee :: getTickMsbF5Word ee :: getTickMsbF6Word ee :: - getTickMsbF7Word ee :: getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: - ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 15 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14191⟩ - (getTickRAfterMsb4Word ee :: getTickMsbF4Word ee :: getTickMsbF5Word ee :: - getTickMsbF6Word ee :: getTickMsbF7Word ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: - ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14180 : decode code ⟨14180⟩ = - some (.Push .PUSH2, some (getTickMsbThreshold4, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14183 : decode code ⟨14183⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14184 : decode code ⟨14184⟩ = some (.GT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14185 : decode code ⟨14185⟩ = some (.Push .PUSH1, some (⟨4⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14187 : decode code ⟨14187⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14188 : decode code ⟨14188⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14189 : decode code ⟨14189⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14190 : decode code ⟨14190⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14183 := by - simpa using h.push2 getTickMsbThreshold4 hd14180 (by - simp only [List.length_cons] - omega) - have rd14184 := by - simpa using rd14183.dup2 hd14183 (by - simp only [List.length_cons] - omega) - have rd14185 := by - simpa using rd14184.gt hd14184 (by - simp only [List.length_cons] - omega) - have rd14187 := by - simpa using rd14185.push1 ⟨4⟩ hd14185 (by - simp only [List.length_cons] - omega) - have rd14188 := by - simpa [getTickMsbF4Word] using rd14187.shl hd14187 (by - simp only [List.length_cons] - omega) - have rd14189 := by - simpa using rd14188.swap1 hd14188 (by - simp only [List.length_cons] - omega) - have rd14190 := by - simpa using rd14189.dup2 hd14189 (by - simp only [List.length_cons] - omega) - have rd14191 := by - simpa [getTickRAfterMsb4Word] using rd14190.shr hd14190 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14191⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioMsbStep3 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14191⟩ - (getTickRAfterMsb4Word ee :: getTickMsbF4Word ee :: getTickMsbF5Word ee :: - getTickMsbF6Word ee :: getTickMsbF7Word ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: - ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 15 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14203⟩ - (getTickRAfterMsb3Word ee :: ⟨3⟩ :: getTickMsbF3Word ee :: getTickMsbF4Word ee :: - getTickMsbF5Word ee :: getTickMsbF6Word ee :: getTickMsbF7Word ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14191 : decode code ⟨14191⟩ = - some (.Push .PUSH1, some (getTickMsbThreshold3, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14193 : decode code ⟨14193⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14194 : decode code ⟨14194⟩ = some (.GT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14195 : decode code ⟨14195⟩ = some (.Push .PUSH1, some (⟨3⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14197 : decode code ⟨14197⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14198 : decode code ⟨14198⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14199 : decode code ⟨14199⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14200 : decode code ⟨14200⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14201 : decode code ⟨14201⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14202 : decode code ⟨14202⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14193 := by - simpa using h.push1 getTickMsbThreshold3 hd14191 (by - simp only [List.length_cons] - omega) - have rd14194 := by - simpa using rd14193.dup2 hd14193 (by - simp only [List.length_cons] - omega) - have rd14195 := by - simpa using rd14194.gt hd14194 (by - simp only [List.length_cons] - omega) - have rd14197 := by - simpa using rd14195.push1 ⟨3⟩ hd14195 (by - simp only [List.length_cons] - omega) - have rd14198 := by - simpa using rd14197.swap1 hd14197 (by - simp only [List.length_cons] - omega) - have rd14199 := by - simpa using rd14198.dup2 hd14198 (by - simp only [List.length_cons] - omega) - have rd14200 := by - simpa [getTickMsbF3Word] using rd14199.shl hd14199 (by - simp only [List.length_cons] - omega) - have rd14201 := by - simpa using rd14200.swap2 hd14200 (by - simp only [List.length_cons] - omega) - have rd14202 := by - simpa using rd14201.dup3 hd14201 (by - simp only [List.length_cons] - omega) - have rd14203 := by - simpa [getTickRAfterMsb3Word] using rd14202.shr hd14202 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14203⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioMsbStep2 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14203⟩ - (getTickRAfterMsb3Word ee :: ⟨3⟩ :: getTickMsbF3Word ee :: getTickMsbF4Word ee :: - getTickMsbF5Word ee :: getTickMsbF6Word ee :: getTickMsbF7Word ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 17 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14213⟩ - (getTickRAfterMsb2Word ee :: getTickMsbF2Word ee :: ⟨3⟩ :: - getTickMsbF3Word ee :: getTickMsbF4Word ee :: getTickMsbF5Word ee :: - getTickMsbF6Word ee :: getTickMsbF7Word ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: - ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14203 : decode code ⟨14203⟩ = - some (.Push .PUSH1, some (getTickMsbThreshold2, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14205 : decode code ⟨14205⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14206 : decode code ⟨14206⟩ = some (.GT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14207 : decode code ⟨14207⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14209 : decode code ⟨14209⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14210 : decode code ⟨14210⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14211 : decode code ⟨14211⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14212 : decode code ⟨14212⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14205 := by - simpa using h.push1 getTickMsbThreshold2 hd14203 (by - simp only [List.length_cons] - omega) - have rd14206 := by - simpa using rd14205.dup2 hd14205 (by - simp only [List.length_cons] - omega) - have rd14207 := by - simpa using rd14206.gt hd14206 (by - simp only [List.length_cons] - omega) - have rd14209 := by - simpa using rd14207.push1 ⟨2⟩ hd14207 (by - simp only [List.length_cons] - omega) - have rd14210 := by - simpa [getTickMsbF2Word] using rd14209.shl hd14209 (by - simp only [List.length_cons] - omega) - have rd14211 := by - simpa using rd14210.swap1 hd14210 (by - simp only [List.length_cons] - omega) - have rd14212 := by - simpa using rd14211.dup2 hd14211 (by - simp only [List.length_cons] - omega) - have rd14213 := by - simpa [getTickRAfterMsb2Word] using rd14212.shr hd14212 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14213⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioMsbStep1 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14213⟩ - (getTickRAfterMsb2Word ee :: getTickMsbF2Word ee :: ⟨3⟩ :: - getTickMsbF3Word ee :: getTickMsbF4Word ee :: getTickMsbF5Word ee :: - getTickMsbF6Word ee :: getTickMsbF7Word ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: - ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 17 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14224⟩ - (getTickRAfterMsb1Word ee :: ⟨1⟩ :: getTickMsbF2Word ee :: - getTickMsbF1Word ee :: getTickMsbF3Word ee :: getTickMsbF4Word ee :: - getTickMsbF5Word ee :: getTickMsbF6Word ee :: getTickMsbF7Word ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14213 : decode code ⟨14213⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14214 : decode code ⟨14214⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14215 : decode code ⟨14215⟩ = some (.GT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14216 : decode code ⟨14216⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14218 : decode code ⟨14218⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14219 : decode code ⟨14219⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14220 : decode code ⟨14220⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14221 : decode code ⟨14221⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14222 : decode code ⟨14222⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14223 : decode code ⟨14223⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14214 := by - simpa using h.swap2 hd14213 (by - simp only [List.length_cons] - omega) - have rd14215 := by - simpa using rd14214.dup3 hd14214 (by - simp only [List.length_cons] - omega) - have rd14216 := by - simpa using rd14215.gt hd14215 (by - simp only [List.length_cons] - omega) - have rd14218 := by - simpa using rd14216.push1 ⟨1⟩ hd14216 (by - simp only [List.length_cons] - omega) - have rd14219 := by - simpa using rd14218.swap1 hd14218 (by - simp only [List.length_cons] - omega) - have rd14220 := by - simpa using rd14219.dup2 hd14219 (by - simp only [List.length_cons] - omega) - have rd14221 := by - simpa [getTickMsbF1Word] using rd14220.shl hd14220 (by - simp only [List.length_cons] - omega) - have rd14222 := by - simpa using rd14221.swap3 hd14221 (by - simp only [List.length_cons] - omega) - have rd14223 := by - simpa using rd14222.dup4 hd14222 (by - simp only [List.length_cons] - omega) - have rd14224 := by - simpa [getTickRAfterMsb1Word] using rd14223.shr hd14223 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14224⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioMsbCombine {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14224⟩ - (getTickRAfterMsb1Word ee :: ⟨1⟩ :: getTickMsbF2Word ee :: - getTickMsbF1Word ee :: getTickMsbF3Word ee :: getTickMsbF4Word ee :: - getTickMsbF5Word ee :: getTickMsbF6Word ee :: getTickMsbF7Word ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 17 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14242⟩ - (getTickMsbWord ee :: getTickRAfterMsb1Word ee :: getTickRatioWord ee :: ⟨0⟩ :: - initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14224 : decode code ⟨14224⟩ = some (.SWAP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14225 : decode code ⟨14225⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14226 : decode code ⟨14226⟩ = some (.DUP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14227 : decode code ⟨14227⟩ = some (.GT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14228 : decode code ⟨14228⟩ = some (.SWAP7, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14229 : decode code ⟨14229⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14230 : decode code ⟨14230⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14231 : decode code ⟨14231⟩ = some (.SWAP5, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14232 : decode code ⟨14232⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14233 : decode code ⟨14233⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14234 : decode code ⟨14234⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14235 : decode code ⟨14235⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14236 : decode code ⟨14236⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14237 : decode code ⟨14237⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14238 : decode code ⟨14238⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14239 : decode code ⟨14239⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14240 : decode code ⟨14240⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14241 : decode code ⟨14241⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14225 := by - simpa using h.swap8 hd14224 (by - simp only [List.length_cons] - omega) - have rd14226 := by - simpa using rd14225.swap1 hd14225 (by - simp only [List.length_cons] - omega) - have rd14227 := by - simpa using rd14226.dup9 hd14226 (by - simp only [List.length_cons] - omega) - have rd14228 := by - simpa [getTickMsbF0Word] using rd14227.gt hd14227 (by - simp only [List.length_cons] - omega) - have rd14229 := by - simpa using rd14228.swap7 hd14228 (by - simp only [List.length_cons] - omega) - have rd14230 := by - simpa [getTickMsbF67Word] using rd14229.lor hd14229 (by - simp only [List.length_cons] - omega) - have rd14231 := by - simpa using rd14230.swap1 hd14230 (by - simp only [List.length_cons] - omega) - have rd14232 := by - simpa using rd14231.swap5 hd14231 (by - simp only [List.length_cons] - omega) - have rd14233 := by - simpa [getTickMsbF567Word] using rd14232.lor hd14232 (by - simp only [List.length_cons] - omega) - have rd14234 := by - simpa using rd14233.swap1 hd14233 (by - simp only [List.length_cons] - omega) - have rd14235 := by - simpa using rd14234.swap3 hd14234 (by - simp only [List.length_cons] - omega) - have rd14236 := by - simpa [getTickMsbF4567Word] using rd14235.lor hd14235 (by - simp only [List.length_cons] - omega) - have rd14237 := by - simpa [getTickMsbF34567Word] using rd14236.lor hd14236 (by - simp only [List.length_cons] - omega) - have rd14238 := by - simpa using rd14237.swap1 hd14237 (by - simp only [List.length_cons] - omega) - have rd14239 := by - simpa using rd14238.swap2 hd14238 (by - simp only [List.length_cons] - omega) - have rd14240 := by - simpa [getTickMsbF234567Word] using rd14239.lor hd14239 (by - simp only [List.length_cons] - omega) - have rd14241 := by - simpa [getTickMsbF1234567Word] using rd14240.lor hd14240 (by - simp only [List.length_cons] - omega) - have rd14242 := by - simpa [getTickMsbWord] using rd14241.lor hd14241 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14242⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioNormalizeR {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14242⟩ - (getTickMsbWord ee :: getTickRAfterMsb1Word ee :: getTickRatioWord ee :: ⟨0⟩ :: - initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 14 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14273⟩ - (getTickMsbWord ee :: getTickRNormalizedWord ee :: getTickRatioWord ee :: ⟨0⟩ :: - initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14242 : decode code ⟨14242⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14244 : decode code ⟨14244⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14245 : decode code ⟨14245⟩ = some (.LT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14246 : decode code ⟨14246⟩ = some (.Push .PUSH2, some (⟨14263⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14249 : decode code ⟨14249⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14250 : decode code ⟨14250⟩ = some (.Push .PUSH1, some (⟨127⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14252 : decode code ⟨14252⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14253 : decode code ⟨14253⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14254 : decode code ⟨14254⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14255 : decode code ⟨14255⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14256 : decode code ⟨14256⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14257 : decode code ⟨14257⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14258 : decode code ⟨14258⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14259 : decode code ⟨14259⟩ = some (.Push .PUSH2, some (⟨14273⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14262 : decode code ⟨14262⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14263 : decode code ⟨14263⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14264 : decode code ⟨14264⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14265 : decode code ⟨14265⟩ = some (.Push .PUSH1, some (⟨127⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14267 : decode code ⟨14267⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14268 : decode code ⟨14268⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14269 : decode code ⟨14269⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14270 : decode code ⟨14270⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14271 : decode code ⟨14271⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14272 : decode code ⟨14272⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14244 := by - simpa using h.push1 ⟨128⟩ hd14242 (by - simp only [List.length_cons] - omega) - have rd14245 := by - simpa using rd14244.dup2 hd14244 (by - simp only [List.length_cons] - omega) - have rd14246 := by - simpa using rd14245.lt hd14245 (by - simp only [List.length_cons] - omega) - have rd14249 := by - simpa using rd14246.push2 ⟨14263⟩ hd14246 (by - simp only [List.length_cons] - omega) - by_cases hltZero : UInt256.lt (getTickMsbWord ee) ⟨128⟩ = ⟨0⟩ - · have rd14250 := by - simpa [show (⟨14246⟩ + UInt256.ofNat 3 + ⟨1⟩ : UInt256) = ⟨14250⟩ - by native_decide] using - rd14249.jumpiNT hd14249 hltZero (by - simp only [List.length_cons] - omega) - have rd14252 := by - simpa using rd14250.push1 ⟨127⟩ hd14250 (by - simp only [List.length_cons] - omega) - have rd14253 := by - simpa using rd14252.dup2 hd14252 (by - simp only [List.length_cons] - omega) - have rd14254 := by - simpa using rd14253.sub hd14253 (by - simp only [List.length_cons] - omega) - have rd14255 := by - simpa using rd14254.dup4 hd14254 (by - simp only [List.length_cons] - omega) - have rd14256 := by - simpa using rd14255.swap1 hd14255 (by - simp only [List.length_cons] - omega) - have rd14257 := by - simpa [getTickRNormalizedHighWord] using rd14256.shr hd14256 (by - simp only [List.length_cons] - omega) - have rd14258 := by - simpa using rd14257.swap2 hd14257 (by - simp only [List.length_cons] - omega) - have rd14259 := by - simpa using rd14258.pop hd14258 (by - simp only [List.length_cons] - omega) - have rd14262 := by - simpa using rd14259.push2 ⟨14273⟩ hd14259 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by - simpa [getTickRNormalizedWord, hltZero] using - rd14262.jump hd14262 (uniswapV3PoolJumpDestPatched14273 hpatch) (by - simp only [List.length_cons] - omega)⟩ - · have rd14263 := rd14249.jumpiT hd14249 hltZero - (uniswapV3PoolJumpDestPatched14263 hpatch) (by - simp only [List.length_cons] - omega) - have rd14264 := by - simpa using rd14263.jumpdest hd14263 (by - simp only [List.length_cons] - omega) - have rd14265 := by - simpa using rd14264.dup1 hd14264 (by - simp only [List.length_cons] - omega) - have rd14267 := by - simpa using rd14265.push1 ⟨127⟩ hd14265 (by - simp only [List.length_cons] - omega) - have rd14268 := by - simpa using rd14267.sub hd14267 (by - simp only [List.length_cons] - omega) - have rd14269 := by - simpa using rd14268.dup4 hd14268 (by - simp only [List.length_cons] - omega) - have rd14270 := by - simpa using rd14269.swap1 hd14269 (by - simp only [List.length_cons] - omega) - have rd14271 := by - simpa [getTickRNormalizedLowWord] using rd14270.shl hd14270 (by - simp only [List.length_cons] - omega) - have rd14272 := by - simpa using rd14271.swap2 hd14271 (by - simp only [List.length_cons] - omega) - have rd14273 := by - simpa using rd14272.pop hd14272 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by - simpa [getTickRNormalizedWord, hltZero] using rd14273⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLogStep63 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14273⟩ - (getTickMsbWord ee :: getTickRNormalizedWord ee :: getTickRatioWord ee :: ⟨0⟩ :: - initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 16 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14291⟩ - (getTickLogRAfter63Word ee :: ⟨255⟩ :: ⟨127⟩ :: getTickLogRSquared63Word ee :: - getTickMsbWord ee :: getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: - ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14273 : decode code ⟨14273⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14274 : decode code ⟨14274⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14275 : decode code ⟨14275⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14276 : decode code ⟨14276⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14277 : decode code ⟨14277⟩ = some (.Push .PUSH1, some (⟨127⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14279 : decode code ⟨14279⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14280 : decode code ⟨14280⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14281 : decode code ⟨14281⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14282 : decode code ⟨14282⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14284 : decode code ⟨14284⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14285 : decode code ⟨14285⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14286 : decode code ⟨14286⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14287 : decode code ⟨14287⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14288 : decode code ⟨14288⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14289 : decode code ⟨14289⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14290 : decode code ⟨14290⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14274 := by - simpa using h.jumpdest hd14273 (by - simp only [List.length_cons] - omega) - have rd14275 := by - simpa using rd14274.swap1 hd14274 (by - simp only [List.length_cons] - omega) - have rd14276 := by - simpa using rd14275.dup1 hd14275 (by - simp only [List.length_cons] - omega) - have rd14277 := by - simpa [getTickLogRSquared63Word] using rd14276.mul hd14276 (by - simp only [List.length_cons] - omega) - have rd14279 := by - simpa using rd14277.push1 ⟨127⟩ hd14277 (by - simp only [List.length_cons] - omega) - have rd14280 := by - simpa using rd14279.dup2 hd14279 (by - simp only [List.length_cons] - omega) - have rd14281 := by - simpa using rd14280.dup2 hd14280 (by - simp only [List.length_cons] - omega) - have rd14282 := by - simpa [getTickLogRShifted63Word] using rd14281.shr hd14281 (by - simp only [List.length_cons] - omega) - have rd14284 := by - simpa using rd14282.push1 ⟨255⟩ hd14282 (by - simp only [List.length_cons] - omega) - have rd14285 := by - simpa using rd14284.dup4 hd14284 (by - simp only [List.length_cons] - omega) - have rd14286 := by - simpa using rd14285.dup2 hd14285 (by - simp only [List.length_cons] - omega) - have rd14287 := by - simpa [getTickLogF63Word] using rd14286.shr hd14286 (by - simp only [List.length_cons] - omega) - have rd14288 := by - simpa using rd14287.swap2 hd14287 (by - simp only [List.length_cons] - omega) - have rd14289 := by - simpa using rd14288.swap1 hd14288 (by - simp only [List.length_cons] - omega) - have rd14290 := by - simpa using rd14289.swap2 hd14289 (by - simp only [List.length_cons] - omega) - have rd14291 := by - simpa [getTickLogRAfter63Word] using rd14290.shr hd14290 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14291⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLogStep62 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14291⟩ - (getTickLogRAfter63Word ee :: ⟨255⟩ :: ⟨127⟩ :: getTickLogRSquared63Word ee :: - getTickMsbWord ee :: getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: - ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 17 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14300⟩ - (getTickLogRAfter62Word ee :: getTickLogRSquared62Word ee :: ⟨255⟩ :: - ⟨127⟩ :: getTickLogRSquared63Word ee :: getTickMsbWord ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14291 : decode code ⟨14291⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14292 : decode code ⟨14292⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14293 : decode code ⟨14293⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14294 : decode code ⟨14294⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14295 : decode code ⟨14295⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14296 : decode code ⟨14296⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14297 : decode code ⟨14297⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14298 : decode code ⟨14298⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14299 : decode code ⟨14299⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14292 := by - simpa using h.dup1 hd14291 (by - simp only [List.length_cons] - omega) - have rd14293 := by - simpa [getTickLogRSquared62Word] using rd14292.mul hd14292 (by - simp only [List.length_cons] - omega) - have rd14294 := by - simpa using rd14293.dup1 hd14293 (by - simp only [List.length_cons] - omega) - have rd14295 := by - simpa using rd14294.dup4 hd14294 (by - simp only [List.length_cons] - omega) - have rd14296 := by - simpa [getTickLogRShifted62Word] using rd14295.shr hd14295 (by - simp only [List.length_cons] - omega) - have rd14297 := by - simpa using rd14296.dup2 hd14296 (by - simp only [List.length_cons] - omega) - have rd14298 := by - simpa using rd14297.dup4 hd14297 (by - simp only [List.length_cons] - omega) - have rd14299 := by - simpa [getTickLogF62Word] using rd14298.shr hd14298 (by - simp only [List.length_cons] - omega) - have rd14300 := by - simpa [getTickLogRAfter62Word] using rd14299.shr hd14299 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14300⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickLog.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickLog.lean deleted file mode 100644 index 19ffed63..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickLog.lean +++ /dev/null @@ -1,1309 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTick - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev getTickLogRSquared61Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLogRAfter62Word ee) (getTickLogRAfter62Word ee) - -abbrev getTickLogRShifted61Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared61Word ee) ⟨127⟩ - -abbrev getTickLogF61Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared61Word ee) ⟨255⟩ - -abbrev getTickLogRAfter61Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRShifted61Word ee) (getTickLogF61Word ee) - -abbrev getTickLogRSquared60Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLogRAfter61Word ee) (getTickLogRAfter61Word ee) - -abbrev getTickLogRShifted60Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared60Word ee) ⟨127⟩ - -abbrev getTickLogF60Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared60Word ee) ⟨255⟩ - -abbrev getTickLogRAfter60Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRShifted60Word ee) (getTickLogF60Word ee) - -def getTickLogRSquared59Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLogRAfter60Word ee) (getTickLogRAfter60Word ee) - -def getTickLogRShifted59Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared59Word ee) ⟨127⟩ - -def getTickLogF59Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared59Word ee) ⟨255⟩ - -def getTickLogRAfter59Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRShifted59Word ee) (getTickLogF59Word ee) - -def getTickLogRSquared58Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLogRAfter59Word ee) (getTickLogRAfter59Word ee) - -def getTickLogRShifted58Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared58Word ee) ⟨127⟩ - -def getTickLogF58Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared58Word ee) ⟨255⟩ - -def getTickLogRAfter58Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRShifted58Word ee) (getTickLogF58Word ee) - -def getTickLogRSquared57Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLogRAfter58Word ee) (getTickLogRAfter58Word ee) - -def getTickLogRShifted57Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared57Word ee) ⟨127⟩ - -def getTickLogF57Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared57Word ee) ⟨255⟩ - -def getTickLogRAfter57Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRShifted57Word ee) (getTickLogF57Word ee) - -def getTickLogRSquared56Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLogRAfter57Word ee) (getTickLogRAfter57Word ee) - -def getTickLogRShifted56Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared56Word ee) ⟨127⟩ - -def getTickLogF56Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared56Word ee) ⟨255⟩ - -def getTickLogRAfter56Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRShifted56Word ee) (getTickLogF56Word ee) - -def getTickLogRSquared55Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLogRAfter56Word ee) (getTickLogRAfter56Word ee) - -def getTickLogRShifted55Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared55Word ee) ⟨127⟩ - -def getTickLogF55Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared55Word ee) ⟨255⟩ - -def getTickLogRAfter55Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRShifted55Word ee) (getTickLogF55Word ee) - -def getTickLogRSquared54Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLogRAfter55Word ee) (getTickLogRAfter55Word ee) - -def getTickLogRShifted54Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared54Word ee) ⟨127⟩ - -def getTickLogF54Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared54Word ee) ⟨255⟩ - -def getTickLogRAfter54Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRShifted54Word ee) (getTickLogF54Word ee) - -def getTickLogRSquared53Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLogRAfter54Word ee) (getTickLogRAfter54Word ee) - -def getTickLogRShifted53Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared53Word ee) ⟨127⟩ - -def getTickLogF53Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared53Word ee) ⟨255⟩ - -def getTickLogRAfter53Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRShifted53Word ee) (getTickLogF53Word ee) - -def getTickLogRSquared52Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLogRAfter53Word ee) (getTickLogRAfter53Word ee) - -def getTickLogRShifted52Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared52Word ee) ⟨127⟩ - -def getTickLogF52Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared52Word ee) ⟨255⟩ - -def getTickLogRAfter52Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRShifted52Word ee) (getTickLogF52Word ee) - -def getTickLogRSquared51Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLogRAfter52Word ee) (getTickLogRAfter52Word ee) - -def getTickLogRShifted51Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared51Word ee) ⟨127⟩ - -def getTickLogF51Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared51Word ee) ⟨255⟩ - -def getTickLogRAfter51Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRShifted51Word ee) (getTickLogF51Word ee) - --- LIBRARY CANDIDATE: fills the missing `Reasoning.Theory` wrapper for EVM `DUP12`. -theorem dup12_xstep {s : State} {code : ByteArray} - {pcv a b c d e f gg hh ii jj kk ll : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.DUP12, .none)) - (hstk : s.machineState.stack = - a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t) - (hov : t.length + 13 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok - (stSwap s - (ll :: a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t), - .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.DUP12, .none) := by - rw [hcode, hpc]; exact hdec - rw [← hcode, step_dup12 s hd, hstk] - have hov' : - ¬ ((a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: - t).length - 12 + 13 > 1024) := by - simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Gverylow, stSwap] - --- LIBRARY CANDIDATE: companion `RD` combinator for the missing `DUP12` wrapper. -theorem RD.dup12 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d e f gg hh ii jj kk ll : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc - (a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t) - mem aw rdata acc k C) - (hdec : decode code pc = some (.DUP12, .none)) (hov : t.length + 13 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) - (ll :: a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: t) - mem aw rdata acc (k + 1) (C + 3) := - h.stepSwap (fun _ hc hp hs => dup12_xstep hc hp hdec hs hov) - --- LIBRARY CANDIDATE: fills the missing `Reasoning.Theory` wrapper for EVM `SWAP13`. -theorem swap13_xstep {s : State} {code : ByteArray} - {pcv a b c d e f gg hh ii jj kk ll mm nn : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.SWAP13, .none)) - (hstk : s.machineState.stack = - a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: nn :: t) - (hov : t.length + 14 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok - (stSwap s - (nn :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: - a :: t), - .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.SWAP13, .none) := by - rw [hcode, hpc]; exact hdec - rw [← hcode, step_swap13 s hd, hstk] - have hov' : - ¬ ((a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: - nn :: t).length - 14 + 14 > 1024) := by - simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Gverylow, stSwap] - --- LIBRARY CANDIDATE: companion `RD` combinator for the missing `SWAP13` wrapper. -theorem RD.swap13 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d e f gg hh ii jj kk ll mm nn : UInt256} {t : List UInt256} - (rd : RD code ee g s0 pc - (a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: nn :: t) - mem aw rdata acc k C) - (hdec : decode code pc = some (.SWAP13, .none)) (hov : t.length + 14 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) - (nn :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: a :: t) - mem aw rdata acc (k + 1) (C + 3) := - rd.stepSwap (fun _ hc hp hs => swap13_xstep hc hp hdec hs hov) - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLogStep61 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14300⟩ - (getTickLogRAfter62Word ee :: getTickLogRSquared62Word ee :: ⟨255⟩ :: - ⟨127⟩ :: getTickLogRSquared63Word ee :: getTickMsbWord ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 18 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14309⟩ - (getTickLogRAfter61Word ee :: getTickLogRSquared61Word ee :: - getTickLogRSquared62Word ee :: ⟨255⟩ :: ⟨127⟩ :: - getTickLogRSquared63Word ee :: getTickMsbWord ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14300 : decode code ⟨14300⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14301 : decode code ⟨14301⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14302 : decode code ⟨14302⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14303 : decode code ⟨14303⟩ = some (.DUP5, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14304 : decode code ⟨14304⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14305 : decode code ⟨14305⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14306 : decode code ⟨14306⟩ = some (.DUP5, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14307 : decode code ⟨14307⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14308 : decode code ⟨14308⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14301 := by - simpa using h.dup1 hd14300 (by - simp only [List.length_cons] - omega) - have rd14302 := by - simpa [getTickLogRSquared61Word] using rd14301.mul hd14301 (by - simp only [List.length_cons] - omega) - have rd14303 := by - simpa using rd14302.dup1 hd14302 (by - simp only [List.length_cons] - omega) - have rd14304 := by - simpa using rd14303.dup5 hd14303 (by - simp only [List.length_cons] - omega) - have rd14305 := by - simpa [getTickLogRShifted61Word] using rd14304.shr hd14304 (by - simp only [List.length_cons] - omega) - have rd14306 := by - simpa using rd14305.dup2 hd14305 (by - simp only [List.length_cons] - omega) - have rd14307 := by - simpa using rd14306.dup5 hd14306 (by - simp only [List.length_cons] - omega) - have rd14308 := by - simpa [getTickLogF61Word] using rd14307.shr hd14307 (by - simp only [List.length_cons] - omega) - have rd14309 := by - simpa [getTickLogRAfter61Word] using rd14308.shr hd14308 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14309⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLogStep60 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14309⟩ - (getTickLogRAfter61Word ee :: getTickLogRSquared61Word ee :: - getTickLogRSquared62Word ee :: ⟨255⟩ :: ⟨127⟩ :: - getTickLogRSquared63Word ee :: getTickMsbWord ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 19 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14318⟩ - (getTickLogRAfter60Word ee :: getTickLogRSquared60Word ee :: - getTickLogRSquared61Word ee :: getTickLogRSquared62Word ee :: - ⟨255⟩ :: ⟨127⟩ :: getTickLogRSquared63Word ee :: getTickMsbWord ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14309 : decode code ⟨14309⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14310 : decode code ⟨14310⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14311 : decode code ⟨14311⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14312 : decode code ⟨14312⟩ = some (.DUP6, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14313 : decode code ⟨14313⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14314 : decode code ⟨14314⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14315 : decode code ⟨14315⟩ = some (.DUP6, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14316 : decode code ⟨14316⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14317 : decode code ⟨14317⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14310 := by - simpa using h.dup1 hd14309 (by - simp only [List.length_cons] - omega) - have rd14311 := by - simpa [getTickLogRSquared60Word] using rd14310.mul hd14310 (by - simp only [List.length_cons] - omega) - have rd14312 := by - simpa using rd14311.dup1 hd14311 (by - simp only [List.length_cons] - omega) - have rd14313 := by - simpa using rd14312.dup6 hd14312 (by - simp only [List.length_cons] - omega) - have rd14314 := by - simpa [getTickLogRShifted60Word] using rd14313.shr hd14313 (by - simp only [List.length_cons] - omega) - have rd14315 := by - simpa using rd14314.dup2 hd14314 (by - simp only [List.length_cons] - omega) - have rd14316 := by - simpa using rd14315.dup6 hd14315 (by - simp only [List.length_cons] - omega) - have rd14317 := by - simpa [getTickLogF60Word] using rd14316.shr hd14316 (by - simp only [List.length_cons] - omega) - have rd14318 := by - simpa [getTickLogRAfter60Word] using rd14317.shr hd14317 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14318⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLogStep59 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14318⟩ - (getTickLogRAfter60Word ee :: getTickLogRSquared60Word ee :: - getTickLogRSquared61Word ee :: getTickLogRSquared62Word ee :: - ⟨255⟩ :: ⟨127⟩ :: getTickLogRSquared63Word ee :: getTickMsbWord ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 20 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14327⟩ - (getTickLogRAfter59Word ee :: getTickLogRSquared59Word ee :: - getTickLogRSquared60Word ee :: getTickLogRSquared61Word ee :: - getTickLogRSquared62Word ee :: ⟨255⟩ :: ⟨127⟩ :: - getTickLogRSquared63Word ee :: getTickMsbWord ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14318 : decode code ⟨14318⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14319 : decode code ⟨14319⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14320 : decode code ⟨14320⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14321 : decode code ⟨14321⟩ = some (.DUP7, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14322 : decode code ⟨14322⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14323 : decode code ⟨14323⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14324 : decode code ⟨14324⟩ = some (.DUP7, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14325 : decode code ⟨14325⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14326 : decode code ⟨14326⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14319 := by - simpa using h.dup1 hd14318 (by - simp only [List.length_cons] - omega) - have rd14320 := by - simpa [getTickLogRSquared59Word] using rd14319.mul hd14319 (by - simp only [List.length_cons] - omega) - have rd14321 := by - simpa using rd14320.dup1 hd14320 (by - simp only [List.length_cons] - omega) - have rd14322 := by - simpa using rd14321.dup7 hd14321 (by - simp only [List.length_cons] - omega) - have rd14323 := by - simpa [getTickLogRShifted59Word] using rd14322.shr hd14322 (by - simp only [List.length_cons] - omega) - have rd14324 := by - simpa using rd14323.dup2 hd14323 (by - simp only [List.length_cons] - omega) - have rd14325 := by - simpa using rd14324.dup7 hd14324 (by - simp only [List.length_cons] - omega) - have rd14326 := by - simpa [getTickLogF59Word] using rd14325.shr hd14325 (by - simp only [List.length_cons] - omega) - have rd14327 := by - simpa [getTickLogRAfter59Word] using rd14326.shr hd14326 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14327⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLogStep58 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14327⟩ - (getTickLogRAfter59Word ee :: getTickLogRSquared59Word ee :: - getTickLogRSquared60Word ee :: getTickLogRSquared61Word ee :: - getTickLogRSquared62Word ee :: ⟨255⟩ :: ⟨127⟩ :: - getTickLogRSquared63Word ee :: getTickMsbWord ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 21 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14336⟩ - (getTickLogRAfter58Word ee :: getTickLogRSquared58Word ee :: - getTickLogRSquared59Word ee :: getTickLogRSquared60Word ee :: - getTickLogRSquared61Word ee :: getTickLogRSquared62Word ee :: - ⟨255⟩ :: ⟨127⟩ :: getTickLogRSquared63Word ee :: getTickMsbWord ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: - ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14327 : decode code ⟨14327⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14328 : decode code ⟨14328⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14329 : decode code ⟨14329⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14330 : decode code ⟨14330⟩ = some (.DUP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14331 : decode code ⟨14331⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14332 : decode code ⟨14332⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14333 : decode code ⟨14333⟩ = some (.DUP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14334 : decode code ⟨14334⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14335 : decode code ⟨14335⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14328 := by - simpa using h.dup1 hd14327 (by - simp only [List.length_cons] - omega) - have rd14329 := by - simpa [getTickLogRSquared58Word] using rd14328.mul hd14328 (by - simp only [List.length_cons] - omega) - have rd14330 := by - simpa using rd14329.dup1 hd14329 (by - simp only [List.length_cons] - omega) - have rd14331 := by - simpa using rd14330.dup8 hd14330 (by - simp only [List.length_cons] - omega) - have rd14332 := by - simpa [getTickLogRShifted58Word] using rd14331.shr hd14331 (by - simp only [List.length_cons] - omega) - have rd14333 := by - simpa using rd14332.dup2 hd14332 (by - simp only [List.length_cons] - omega) - have rd14334 := by - simpa using rd14333.dup8 hd14333 (by - simp only [List.length_cons] - omega) - have rd14335 := by - simpa [getTickLogF58Word] using rd14334.shr hd14334 (by - simp only [List.length_cons] - omega) - have rd14336 := by - simpa [getTickLogRAfter58Word] using rd14335.shr hd14335 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14336⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLogStep57 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14336⟩ - (getTickLogRAfter58Word ee :: getTickLogRSquared58Word ee :: - getTickLogRSquared59Word ee :: getTickLogRSquared60Word ee :: - getTickLogRSquared61Word ee :: getTickLogRSquared62Word ee :: - ⟨255⟩ :: ⟨127⟩ :: getTickLogRSquared63Word ee :: getTickMsbWord ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: - ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 22 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14345⟩ - (getTickLogRAfter57Word ee :: getTickLogRSquared57Word ee :: - getTickLogRSquared58Word ee :: getTickLogRSquared59Word ee :: - getTickLogRSquared60Word ee :: getTickLogRSquared61Word ee :: - getTickLogRSquared62Word ee :: ⟨255⟩ :: ⟨127⟩ :: - getTickLogRSquared63Word ee :: getTickMsbWord ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14336 : decode code ⟨14336⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14337 : decode code ⟨14337⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14338 : decode code ⟨14338⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14339 : decode code ⟨14339⟩ = some (.DUP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14340 : decode code ⟨14340⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14341 : decode code ⟨14341⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14342 : decode code ⟨14342⟩ = some (.DUP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14343 : decode code ⟨14343⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14344 : decode code ⟨14344⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14337 := by - simpa using h.dup1 hd14336 (by - simp only [List.length_cons] - omega) - have rd14338 := by - simpa [getTickLogRSquared57Word] using rd14337.mul hd14337 (by - simp only [List.length_cons] - omega) - have rd14339 := by - simpa using rd14338.dup1 hd14338 (by - simp only [List.length_cons] - omega) - have rd14340 := by - simpa using rd14339.dup9 hd14339 (by - simp only [List.length_cons] - omega) - have rd14341 := by - simpa [getTickLogRShifted57Word] using rd14340.shr hd14340 (by - simp only [List.length_cons] - omega) - have rd14342 := by - simpa using rd14341.dup2 hd14341 (by - simp only [List.length_cons] - omega) - have rd14343 := by - simpa using rd14342.dup9 hd14342 (by - simp only [List.length_cons] - omega) - have rd14344 := by - simpa [getTickLogF57Word] using rd14343.shr hd14343 (by - simp only [List.length_cons] - omega) - have rd14345 := by - simpa [getTickLogRAfter57Word] using rd14344.shr hd14344 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14345⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLogStep56 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14345⟩ - (getTickLogRAfter57Word ee :: getTickLogRSquared57Word ee :: - getTickLogRSquared58Word ee :: getTickLogRSquared59Word ee :: - getTickLogRSquared60Word ee :: getTickLogRSquared61Word ee :: - getTickLogRSquared62Word ee :: ⟨255⟩ :: ⟨127⟩ :: - getTickLogRSquared63Word ee :: getTickMsbWord ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 23 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14354⟩ - (getTickLogRAfter56Word ee :: getTickLogRSquared56Word ee :: - getTickLogRSquared57Word ee :: getTickLogRSquared58Word ee :: - getTickLogRSquared59Word ee :: getTickLogRSquared60Word ee :: - getTickLogRSquared61Word ee :: getTickLogRSquared62Word ee :: - ⟨255⟩ :: ⟨127⟩ :: getTickLogRSquared63Word ee :: getTickMsbWord ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: - ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14345 : decode code ⟨14345⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14346 : decode code ⟨14346⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14347 : decode code ⟨14347⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14348 : decode code ⟨14348⟩ = some (.DUP10, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14349 : decode code ⟨14349⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14350 : decode code ⟨14350⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14351 : decode code ⟨14351⟩ = some (.DUP10, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14352 : decode code ⟨14352⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14353 : decode code ⟨14353⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14346 := by - simpa using h.dup1 hd14345 (by - simp only [List.length_cons] - omega) - have rd14347 := by - simpa [getTickLogRSquared56Word] using rd14346.mul hd14346 (by - simp only [List.length_cons] - omega) - have rd14348 := by - simpa using rd14347.dup1 hd14347 (by - simp only [List.length_cons] - omega) - have rd14349 := by - simpa using rd14348.dup10 hd14348 (by - simp only [List.length_cons] - omega) - have rd14350 := by - simpa [getTickLogRShifted56Word] using rd14349.shr hd14349 (by - simp only [List.length_cons] - omega) - have rd14351 := by - simpa using rd14350.dup2 hd14350 (by - simp only [List.length_cons] - omega) - have rd14352 := by - simpa using rd14351.dup10 hd14351 (by - simp only [List.length_cons] - omega) - have rd14353 := by - simpa [getTickLogF56Word] using rd14352.shr hd14352 (by - simp only [List.length_cons] - omega) - have rd14354 := by - simpa [getTickLogRAfter56Word] using rd14353.shr hd14353 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14354⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLogStep55 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14354⟩ - (getTickLogRAfter56Word ee :: getTickLogRSquared56Word ee :: - getTickLogRSquared57Word ee :: getTickLogRSquared58Word ee :: - getTickLogRSquared59Word ee :: getTickLogRSquared60Word ee :: - getTickLogRSquared61Word ee :: getTickLogRSquared62Word ee :: - ⟨255⟩ :: ⟨127⟩ :: getTickLogRSquared63Word ee :: getTickMsbWord ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: - ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 24 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14363⟩ - (getTickLogRAfter55Word ee :: getTickLogRSquared55Word ee :: - getTickLogRSquared56Word ee :: getTickLogRSquared57Word ee :: - getTickLogRSquared58Word ee :: getTickLogRSquared59Word ee :: - getTickLogRSquared60Word ee :: getTickLogRSquared61Word ee :: - getTickLogRSquared62Word ee :: ⟨255⟩ :: ⟨127⟩ :: - getTickLogRSquared63Word ee :: getTickMsbWord ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14354 : decode code ⟨14354⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14355 : decode code ⟨14355⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14356 : decode code ⟨14356⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14357 : decode code ⟨14357⟩ = some (.DUP11, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14358 : decode code ⟨14358⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14359 : decode code ⟨14359⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14360 : decode code ⟨14360⟩ = some (.DUP11, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14361 : decode code ⟨14361⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14362 : decode code ⟨14362⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14355 := by - simpa using h.dup1 hd14354 (by - simp only [List.length_cons] - omega) - have rd14356 := by - simpa [getTickLogRSquared55Word] using rd14355.mul hd14355 (by - simp only [List.length_cons] - omega) - have rd14357 := by - simpa using rd14356.dup1 hd14356 (by - simp only [List.length_cons] - omega) - have rd14358 := by - simpa using rd14357.dup11 hd14357 (by - simp only [List.length_cons] - omega) - have rd14359 := by - simpa [getTickLogRShifted55Word] using rd14358.shr hd14358 (by - simp only [List.length_cons] - omega) - have rd14360 := by - simpa using rd14359.dup2 hd14359 (by - simp only [List.length_cons] - omega) - have rd14361 := by - simpa using rd14360.dup11 hd14360 (by - simp only [List.length_cons] - omega) - have rd14362 := by - simpa [getTickLogF55Word] using rd14361.shr hd14361 (by - simp only [List.length_cons] - omega) - have rd14363 := by - simpa [getTickLogRAfter55Word] using rd14362.shr hd14362 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14363⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLogStep54 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14363⟩ - (getTickLogRAfter55Word ee :: getTickLogRSquared55Word ee :: - getTickLogRSquared56Word ee :: getTickLogRSquared57Word ee :: - getTickLogRSquared58Word ee :: getTickLogRSquared59Word ee :: - getTickLogRSquared60Word ee :: getTickLogRSquared61Word ee :: - getTickLogRSquared62Word ee :: ⟨255⟩ :: ⟨127⟩ :: - getTickLogRSquared63Word ee :: getTickMsbWord ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 25 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14372⟩ - (getTickLogRAfter54Word ee :: getTickLogRSquared54Word ee :: - getTickLogRSquared55Word ee :: getTickLogRSquared56Word ee :: - getTickLogRSquared57Word ee :: getTickLogRSquared58Word ee :: - getTickLogRSquared59Word ee :: getTickLogRSquared60Word ee :: - getTickLogRSquared61Word ee :: getTickLogRSquared62Word ee :: - ⟨255⟩ :: ⟨127⟩ :: getTickLogRSquared63Word ee :: getTickMsbWord ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: - ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14363 : decode code ⟨14363⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14364 : decode code ⟨14364⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14365 : decode code ⟨14365⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14366 : decode code ⟨14366⟩ = some (.DUP12, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14367 : decode code ⟨14367⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14368 : decode code ⟨14368⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14369 : decode code ⟨14369⟩ = some (.DUP12, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14370 : decode code ⟨14370⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14371 : decode code ⟨14371⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14364 := by - simpa using h.dup1 hd14363 (by - simp only [List.length_cons] - omega) - have rd14365 := by - simpa [getTickLogRSquared54Word] using rd14364.mul hd14364 (by - simp only [List.length_cons] - omega) - have rd14366 := by - simpa using rd14365.dup1 hd14365 (by - simp only [List.length_cons] - omega) - have rd14367 := by - simpa using RD.dup12 rd14366 hd14366 (by - simp only [List.length_cons] - omega) - have rd14368 := by - simpa [getTickLogRShifted54Word] using rd14367.shr hd14367 (by - simp only [List.length_cons] - omega) - have rd14369 := by - simpa using rd14368.dup2 hd14368 (by - simp only [List.length_cons] - omega) - have rd14370 := by - simpa using RD.dup12 rd14369 hd14369 (by - simp only [List.length_cons] - omega) - have rd14371 := by - simpa [getTickLogF54Word] using rd14370.shr hd14370 (by - simp only [List.length_cons] - omega) - have rd14372 := by - simpa [getTickLogRAfter54Word] using rd14371.shr hd14371 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14372⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLogStep53 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14372⟩ - (getTickLogRAfter54Word ee :: getTickLogRSquared54Word ee :: - getTickLogRSquared55Word ee :: getTickLogRSquared56Word ee :: - getTickLogRSquared57Word ee :: getTickLogRSquared58Word ee :: - getTickLogRSquared59Word ee :: getTickLogRSquared60Word ee :: - getTickLogRSquared61Word ee :: getTickLogRSquared62Word ee :: - ⟨255⟩ :: ⟨127⟩ :: getTickLogRSquared63Word ee :: getTickMsbWord ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: - ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 26 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14381⟩ - (getTickLogRAfter53Word ee :: getTickLogRSquared53Word ee :: - getTickLogRSquared54Word ee :: getTickLogRSquared55Word ee :: - getTickLogRSquared56Word ee :: getTickLogRSquared57Word ee :: - getTickLogRSquared58Word ee :: getTickLogRSquared59Word ee :: - getTickLogRSquared60Word ee :: getTickLogRSquared61Word ee :: - getTickLogRSquared62Word ee :: ⟨255⟩ :: ⟨127⟩ :: - getTickLogRSquared63Word ee :: getTickMsbWord ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14372 : decode code ⟨14372⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14373 : decode code ⟨14373⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14374 : decode code ⟨14374⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14375 : decode code ⟨14375⟩ = some (.DUP13, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14376 : decode code ⟨14376⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14377 : decode code ⟨14377⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14378 : decode code ⟨14378⟩ = some (.DUP13, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14379 : decode code ⟨14379⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14380 : decode code ⟨14380⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14373 := by - simpa using h.dup1 hd14372 (by - simp only [List.length_cons] - omega) - have rd14374 := by - simpa [getTickLogRSquared53Word] using rd14373.mul hd14373 (by - simp only [List.length_cons] - omega) - have rd14375 := by - simpa using rd14374.dup1 hd14374 (by - simp only [List.length_cons] - omega) - have rd14376 := by - simpa using rd14375.dup13 hd14375 (by - simp only [List.length_cons] - omega) - have rd14377 := by - simpa [getTickLogRShifted53Word] using rd14376.shr hd14376 (by - simp only [List.length_cons] - omega) - have rd14378 := by - simpa using rd14377.dup2 hd14377 (by - simp only [List.length_cons] - omega) - have rd14379 := by - simpa using rd14378.dup13 hd14378 (by - simp only [List.length_cons] - omega) - have rd14380 := by - simpa [getTickLogF53Word] using rd14379.shr hd14379 (by - simp only [List.length_cons] - omega) - have rd14381 := by - simpa [getTickLogRAfter53Word] using rd14380.shr hd14380 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14381⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLogStep52 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14381⟩ - (getTickLogRAfter53Word ee :: getTickLogRSquared53Word ee :: - getTickLogRSquared54Word ee :: getTickLogRSquared55Word ee :: - getTickLogRSquared56Word ee :: getTickLogRSquared57Word ee :: - getTickLogRSquared58Word ee :: getTickLogRSquared59Word ee :: - getTickLogRSquared60Word ee :: getTickLogRSquared61Word ee :: - getTickLogRSquared62Word ee :: ⟨255⟩ :: ⟨127⟩ :: - getTickLogRSquared63Word ee :: getTickMsbWord ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 27 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14390⟩ - (getTickLogRAfter52Word ee :: getTickLogRSquared52Word ee :: - getTickLogRSquared53Word ee :: getTickLogRSquared54Word ee :: - getTickLogRSquared55Word ee :: getTickLogRSquared56Word ee :: - getTickLogRSquared57Word ee :: getTickLogRSquared58Word ee :: - getTickLogRSquared59Word ee :: getTickLogRSquared60Word ee :: - getTickLogRSquared61Word ee :: getTickLogRSquared62Word ee :: - ⟨255⟩ :: ⟨127⟩ :: getTickLogRSquared63Word ee :: getTickMsbWord ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: - ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14381 : decode code ⟨14381⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14382 : decode code ⟨14382⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14383 : decode code ⟨14383⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14384 : decode code ⟨14384⟩ = some (.DUP14, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14385 : decode code ⟨14385⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14386 : decode code ⟨14386⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14387 : decode code ⟨14387⟩ = some (.DUP14, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14388 : decode code ⟨14388⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14389 : decode code ⟨14389⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14382 := by - simpa using h.dup1 hd14381 (by - simp only [List.length_cons] - omega) - have rd14383 := by - simpa [getTickLogRSquared52Word] using rd14382.mul hd14382 (by - simp only [List.length_cons] - omega) - have rd14384 := by - simpa using rd14383.dup1 hd14383 (by - simp only [List.length_cons] - omega) - have rd14385 := by - simpa using rd14384.dup14 hd14384 (by - simp only [List.length_cons] - omega) - have rd14386 := by - simpa [getTickLogRShifted52Word] using rd14385.shr hd14385 (by - simp only [List.length_cons] - omega) - have rd14387 := by - simpa using rd14386.dup2 hd14386 (by - simp only [List.length_cons] - omega) - have rd14388 := by - simpa using rd14387.dup14 hd14387 (by - simp only [List.length_cons] - omega) - have rd14389 := by - simpa [getTickLogF52Word] using rd14388.shr hd14388 (by - simp only [List.length_cons] - omega) - have rd14390 := by - simpa [getTickLogRAfter52Word] using rd14389.shr hd14389 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14390⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLogStep51 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14390⟩ - (getTickLogRAfter52Word ee :: getTickLogRSquared52Word ee :: - getTickLogRSquared53Word ee :: getTickLogRSquared54Word ee :: - getTickLogRSquared55Word ee :: getTickLogRSquared56Word ee :: - getTickLogRSquared57Word ee :: getTickLogRSquared58Word ee :: - getTickLogRSquared59Word ee :: getTickLogRSquared60Word ee :: - getTickLogRSquared61Word ee :: getTickLogRSquared62Word ee :: - ⟨255⟩ :: ⟨127⟩ :: getTickLogRSquared63Word ee :: getTickMsbWord ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: - ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 28 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14403⟩ - (getTickLogRAfter51Word ee :: getTickLogRSquared52Word ee :: - getTickLogRSquared53Word ee :: getTickLogRSquared54Word ee :: - getTickLogRSquared55Word ee :: getTickLogRSquared56Word ee :: - getTickLogRSquared57Word ee :: getTickLogRSquared58Word ee :: - getTickLogRSquared59Word ee :: getTickLogRSquared60Word ee :: - getTickLogRSquared61Word ee :: getTickLogRSquared62Word ee :: - getTickLogRSquared51Word ee :: ⟨127⟩ :: getTickLogRSquared63Word ee :: - getTickMsbWord ee :: getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: - ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14390 : decode code ⟨14390⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14391 : decode code ⟨14391⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14392 : decode code ⟨14392⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14393 : decode code ⟨14393⟩ = some (.DUP15, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14394 : decode code ⟨14394⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14395 : decode code ⟨14395⟩ = some (.SWAP13, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14396 : decode code ⟨14396⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14397 : decode code ⟨14397⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14398 : decode code ⟨14398⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14399 : decode code ⟨14399⟩ = some (.SWAP13, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14400 : decode code ⟨14400⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14401 : decode code ⟨14401⟩ = some (.SWAP13, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14402 : decode code ⟨14402⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14391 := by - simpa using h.dup1 hd14390 (by - simp only [List.length_cons] - omega) - have rd14392 := by - simpa [getTickLogRSquared51Word] using rd14391.mul hd14391 (by - simp only [List.length_cons] - omega) - have rd14393 := by - simpa using rd14392.dup1 hd14392 (by - simp only [List.length_cons] - omega) - have rd14394 := by - simpa using rd14393.dup15 hd14393 (by - simp only [List.length_cons] - omega) - have rd14395 := by - simpa [getTickLogRShifted51Word] using rd14394.shr hd14394 (by - simp only [List.length_cons] - omega) - have rd14396 := by - simpa using RD.swap13 rd14395 hd14395 (by - simp only [List.length_cons] - omega) - have rd14397 := by - simpa using rd14396.dup2 hd14396 (by - simp only [List.length_cons] - omega) - have rd14398 := by - simpa using rd14397.swap1 hd14397 (by - simp only [List.length_cons] - omega) - have rd14399 := by - simpa [getTickLogF51Word] using rd14398.shr hd14398 (by - simp only [List.length_cons] - omega) - have rd14400 := by - simpa using RD.swap13 rd14399 hd14399 (by - simp only [List.length_cons] - omega) - have rd14401 := by - simpa using rd14400.swap1 hd14400 (by - simp only [List.length_cons] - omega) - have rd14402 := by - simpa using RD.swap13 rd14401 hd14401 (by - simp only [List.length_cons] - omega) - have rd14403 := by - simpa [getTickLogRAfter51Word] using rd14402.shr hd14402 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14403⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickLog2Bridge.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickLog2Bridge.lean deleted file mode 100644 index 39a42b5c..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickLog2Bridge.lean +++ /dev/null @@ -1,131 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTickWordBridge - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem getTickLog2LowAfter50Nat_lt_twoPow64 (I : ExecutionEnv) : - getTickLog2BitsAfter50Nat I * 2 ^ (50 : Nat) < 2 ^ (64 : Nat) := by - have hb := getTickLog2BitsAfter50Nat_lt_twoPow14 I - norm_num at hb ⊢ - omega - -theorem getTickLog2After50Word_eq_source_of_msb_bounds (I : ExecutionEnv) - (hloMsb : 64 ≤ getTickSourceMsbAfter0Nat I) - (hhiMsb : getTickSourceMsbAfter0Nat I ≤ 191) : - getTickLog2After50Word I = EVM.wordOfInt (getTickSourceLog2After50Int I) := by - apply u256_inj - have hbaseWord := getTickLog2BaseWord_eq_source_of_msb_bounds I hloMsb hhiMsb - have hlowLt := getTickLog2LowAfter50Nat_lt_twoPow64 I - have hlowIntLt : - (getTickLog2BitsAfter50Nat I : Int) * (2 ^ (50 : Nat) : Int) < - (2 ^ (64 : Nat) : Int) := by - exact_mod_cast hlowLt - rw [getTickSourceLog2After50Int_eq_base_add_bits I] - by_cases hge128 : 128 ≤ getTickSourceMsbAfter0Nat I - · let q := getTickSourceMsbAfter0Nat I - 128 - have hq : q < 2 ^ (192 : Nat) := by - dsimp [q] - omega - have hbaseToNat : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat) := by - rw [hbaseWord] - unfold getTickSourceLog2BaseInt - have hbaseNonneg : - 0 ≤ ((getTickSourceMsbAfter0Nat I : Int) - 128) * - (2 ^ (64 : Nat) : Int) := by - norm_num - omega - have hbaseLt : - ((getTickSourceMsbAfter0Nat I : Int) - 128) * - (2 ^ (64 : Nat) : Int) < EVM.wordModulus := by - norm_num [EVM.wordModulus, EVM.twoPow] at hhiMsb ⊢ - omega - rw [wordOfInt_nonneg_toNat_lt_wordModulus _ hbaseNonneg hbaseLt] - dsimp [q] - omega - rw [getTickLog2After50Word_toNat_of_base I q hbaseToNat hq] - have hsrcNonneg : - 0 ≤ getTickSourceLog2BaseInt I + - (getTickLog2BitsAfter50Nat I : Int) * (2 ^ (50 : Nat) : Int) := by - unfold getTickSourceLog2BaseInt - norm_num - omega - have hsrcLt : - getTickSourceLog2BaseInt I + - (getTickLog2BitsAfter50Nat I : Int) * (2 ^ (50 : Nat) : Int) < - EVM.wordModulus := by - unfold getTickSourceLog2BaseInt - norm_num [EVM.wordModulus, EVM.twoPow] at hhiMsb hlowIntLt ⊢ - omega - rw [wordOfInt_nonneg_toNat_lt_wordModulus _ hsrcNonneg hsrcLt] - dsimp [q] - unfold getTickSourceLog2BaseInt - norm_num - omega - · have hlt128 : getTickSourceMsbAfter0Nat I < 128 := Nat.lt_of_not_ge hge128 - let d := 128 - getTickSourceMsbAfter0Nat I - let q := 2 ^ (192 : Nat) - d - have hdPos : 0 < d := by - dsimp [d] - omega - have hdLe : d ≤ 64 := by - dsimp [d] - omega - have hq : q < 2 ^ (192 : Nat) := by - dsimp [q] - omega - have hbaseToNat : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat) := by - rw [hbaseWord] - unfold getTickSourceLog2BaseInt - have hbaseNeg : - ((getTickSourceMsbAfter0Nat I : Int) - 128) * - (2 ^ (64 : Nat) : Int) < 0 := by - norm_num - omega - have hbaseAbs : - (((getTickSourceMsbAfter0Nat I : Int) - 128) * - (2 ^ (64 : Nat) : Int)).natAbs = - d * 2 ^ (64 : Nat) := by - dsimp [d] - omega - have hbaseAbsLt : - (((getTickSourceMsbAfter0Nat I : Int) - 128) * - (2 ^ (64 : Nat) : Int)).natAbs < EVM.wordModulus := by - rw [hbaseAbs] - exact lt_of_le_of_lt (Nat.mul_le_mul_right _ hdLe) (by native_decide) - rw [wordOfInt_neg_toNat_lt_wordModulus _ hbaseNeg hbaseAbsLt] - rw [hbaseAbs] - dsimp [q, d] - norm_num [UInt256.size, EVM.wordModulus, EVM.twoPow] - omega - rw [getTickLog2After50Word_toNat_of_base I q hbaseToNat hq] - have hsrcNeg : - getTickSourceLog2BaseInt I + - (getTickLog2BitsAfter50Nat I : Int) * (2 ^ (50 : Nat) : Int) < 0 := by - unfold getTickSourceLog2BaseInt - dsimp [d] - norm_num at hlowIntLt ⊢ - omega - have hsrcAbs : - (getTickSourceLog2BaseInt I + - (getTickLog2BitsAfter50Nat I : Int) * (2 ^ (50 : Nat) : Int)).natAbs = - d * 2 ^ (64 : Nat) - getTickLog2BitsAfter50Nat I * 2 ^ (50 : Nat) := by - unfold getTickSourceLog2BaseInt - dsimp [d] - norm_num at hlowIntLt ⊢ - omega - have hsrcAbsLt : - (getTickSourceLog2BaseInt I + - (getTickLog2BitsAfter50Nat I : Int) * (2 ^ (50 : Nat) : Int)).natAbs < - EVM.wordModulus := by - rw [hsrcAbs] - exact lt_of_le_of_lt (Nat.sub_le _ _) (lt_of_le_of_lt - (Nat.mul_le_mul_right _ hdLe) (by native_decide)) - rw [wordOfInt_neg_toNat_lt_wordModulus _ hsrcNeg hsrcAbsLt] - rw [hsrcAbs] - dsimp [q, d] - norm_num [UInt256.size, EVM.wordModulus, EVM.twoPow] at hlowLt ⊢ - omega - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickLogCombine.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickLogCombine.lean deleted file mode 100644 index 5b84451c..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickLogCombine.lean +++ /dev/null @@ -1,1754 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTickLog - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def getTickLogRSquared50Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLogRAfter51Word ee) (getTickLogRAfter51Word ee) - -def getTickLogRShifted50Word (ee : ExecutionEnv) : UInt256 := - UInt256.shiftRight (getTickLogRSquared50Word ee) ⟨127⟩ - -def getTickLog2BaseWord (ee : ExecutionEnv) : UInt256 := - UInt256.shiftLeft (getTickMsbWord ee + UInt256.lnot ⟨127⟩) ⟨64⟩ - -def getTickLog2Bit63Mask : UInt256 := ⟨9223372036854775808⟩ - -def getTickLog2Bit62Mask : UInt256 := ⟨4611686018427387904⟩ - -def getTickLog2Bit61Mask : UInt256 := ⟨2305843009213693952⟩ - -def getTickLog2Bit60Mask : UInt256 := ⟨1152921504606846976⟩ - -def getTickLog2Bit59Mask : UInt256 := ⟨576460752303423488⟩ - -def getTickLog2Bit58Mask : UInt256 := ⟨288230376151711744⟩ - -def getTickLog2Bit57Mask : UInt256 := ⟨144115188075855872⟩ - -def getTickLog2Bit56Mask : UInt256 := ⟨72057594037927936⟩ - -def getTickLog2Bit55Mask : UInt256 := ⟨36028797018963968⟩ - -def getTickLog2Bit54Mask : UInt256 := ⟨18014398509481984⟩ - -def getTickLog2Bit53Mask : UInt256 := ⟨9007199254740992⟩ - -def getTickLog2Bit52Mask : UInt256 := ⟨4503599627370496⟩ - -def getTickLog2Bit51Mask : UInt256 := ⟨2251799813685248⟩ - -def getTickLog2Bit50Mask : UInt256 := ⟨1125899906842624⟩ - -def getTickLog2Bit63Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit63Mask - (UInt256.shiftRight (getTickLogRSquared63Word ee) ⟨192⟩) - -def getTickLog2After63Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit63Word ee) (getTickLog2BaseWord ee) - -def getTickLog2Bit62Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit62Mask - (UInt256.shiftRight (getTickLogRSquared62Word ee) ⟨193⟩) - -def getTickLog2After62Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit62Word ee) (getTickLog2After63Word ee) - -def getTickLog2Bit61Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit61Mask - (UInt256.shiftRight (getTickLogRSquared61Word ee) ⟨194⟩) - -def getTickLog2After61Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit61Word ee) (getTickLog2After62Word ee) - -def getTickLog2Bit60Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit60Mask - (UInt256.shiftRight (getTickLogRSquared60Word ee) ⟨195⟩) - -def getTickLog2After60Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit60Word ee) (getTickLog2After61Word ee) - -def getTickLog2Bit59Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit59Mask - (UInt256.shiftRight (getTickLogRSquared59Word ee) ⟨196⟩) - -def getTickLog2After59Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit59Word ee) (getTickLog2After60Word ee) - -def getTickLog2Bit58Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit58Mask - (UInt256.shiftRight (getTickLogRSquared58Word ee) ⟨197⟩) - -def getTickLog2After58Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit58Word ee) (getTickLog2After59Word ee) - -def getTickLog2Bit57Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit57Mask - (UInt256.shiftRight (getTickLogRSquared57Word ee) ⟨198⟩) - -def getTickLog2After57Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit57Word ee) (getTickLog2After58Word ee) - -def getTickLog2Bit56Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit56Mask - (UInt256.shiftRight (getTickLogRSquared56Word ee) ⟨199⟩) - -def getTickLog2After56Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit56Word ee) (getTickLog2After57Word ee) - -def getTickLog2Bit55Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit55Mask - (UInt256.shiftRight (getTickLogRSquared55Word ee) ⟨200⟩) - -def getTickLog2After55Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit55Word ee) (getTickLog2After56Word ee) - -def getTickLog2Bit54Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit54Mask - (UInt256.shiftRight (getTickLogRSquared54Word ee) ⟨201⟩) - -def getTickLog2After54Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit54Word ee) (getTickLog2After55Word ee) - -def getTickLog2Bit53Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit53Mask - (UInt256.shiftRight (getTickLogRSquared53Word ee) ⟨202⟩) - -def getTickLog2After53Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit53Word ee) (getTickLog2After54Word ee) - -def getTickLog2Bit52Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit52Mask - (UInt256.shiftRight (getTickLogRSquared52Word ee) ⟨203⟩) - -def getTickLog2After52Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit52Word ee) (getTickLog2After53Word ee) - -def getTickLog2Bit51Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit51Mask - (UInt256.shiftRight (getTickLogRSquared51Word ee) ⟨204⟩) - -def getTickLog2After51Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit51Word ee) (getTickLog2After52Word ee) - -def getTickLog2Bit50Word (ee : ExecutionEnv) : UInt256 := - UInt256.land getTickLog2Bit50Mask - (UInt256.shiftRight (getTickLogRSquared50Word ee) ⟨205⟩) - -def getTickLog2After50Word (ee : ExecutionEnv) : UInt256 := - UInt256.lor (getTickLog2Bit50Word ee) (getTickLog2After51Word ee) - -def getTickLogSqrt10001Multiplier : UInt256 := ⟨255738958999603826347141⟩ - -def getTickLowOffsetWord : UInt256 := ⟨3402992956809132418596140100660247209⟩ - -def getTickHiOffsetWord : UInt256 := ⟨291339464771989622907027621153398088495⟩ - -def getTickLogSqrt10001Word (ee : ExecutionEnv) : UInt256 := - UInt256.mul (getTickLog2After50Word ee) getTickLogSqrt10001Multiplier - -def getTickLowBiasedWord (ee : ExecutionEnv) : UInt256 := - getTickLogSqrt10001Word ee + UInt256.lnot getTickLowOffsetWord - -def getTickLowWord (ee : ExecutionEnv) : UInt256 := - UInt256.sar ⟨128⟩ (getTickLowBiasedWord ee) - -def getTickHiBiasedWord (ee : ExecutionEnv) : UInt256 := - getTickLogSqrt10001Word ee + getTickHiOffsetWord - -def getTickHiWord (ee : ExecutionEnv) : UInt256 := - UInt256.sar ⟨128⟩ (getTickHiBiasedWord ee) - -def getTickHiInt24Word (ee : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨2⟩ (getTickHiWord ee) - -def getTickLowInt24Word (ee : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨2⟩ (getTickLowWord ee) - -def getTickLowEqHiWord (ee : ExecutionEnv) : UInt256 := - UInt256.eq (getTickLowInt24Word ee) (getTickHiInt24Word ee) - --- LIBRARY CANDIDATE: fills the missing `Reasoning.Theory` wrapper for EVM `DUP16`. -theorem dup16_xstep {s : State} {code : ByteArray} - {pcv a b c d e f gg hh ii jj kk ll mm nn oo pp : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.DUP16, .none)) - (hstk : s.machineState.stack = - a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: nn :: - oo :: pp :: t) - (hov : t.length + 17 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok - (stSwap s - (pp :: a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: - mm :: nn :: oo :: pp :: t), - .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.DUP16, .none) := by - rw [hcode, hpc]; exact hdec - rw [← hcode, step_dup16 s hd, hstk] - have hov' : - ¬ ((a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: - nn :: oo :: pp :: t).length - 16 + 17 > 1024) := by - simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Gverylow, stSwap] - --- LIBRARY CANDIDATE: companion `RD` combinator for the missing `DUP16` wrapper. -theorem RD.dup16 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d e f gg hh ii jj kk ll mm nn oo pp : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc - (a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: nn :: - oo :: pp :: t) - mem aw rdata acc k C) - (hdec : decode code pc = some (.DUP16, .none)) (hov : t.length + 17 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) - (pp :: a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: - nn :: oo :: pp :: t) - mem aw rdata acc (k + 1) (C + 3) := - h.stepSwap (fun _ hc hp hs => dup16_xstep hc hp hdec hs hov) - --- LIBRARY CANDIDATE: fills the missing `Reasoning.Theory` wrapper for EVM `SWAP15`. -theorem swap15_xstep {s : State} {code : ByteArray} - {pcv a b c d e f gg hh ii jj kk ll mm nn oo pp : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.SWAP15, .none)) - (hstk : s.machineState.stack = - a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: nn :: - oo :: pp :: t) - (hov : t.length + 16 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok - (stSwap s - (pp :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: - nn :: oo :: a :: t), - .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.SWAP15, .none) := by - rw [hcode, hpc]; exact hdec - rw [← hcode, step_swap15 s hd, hstk] - have hov' : - ¬ ((a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: - nn :: oo :: pp :: t).length - 16 + 16 > 1024) := by - simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Gverylow, stSwap] - --- LIBRARY CANDIDATE: companion `RD` combinator for the missing `SWAP15` wrapper. -theorem RD.swap15 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d e f gg hh ii jj kk ll mm nn oo pp : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc - (a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: nn :: - oo :: pp :: t) - mem aw rdata acc k C) - (hdec : decode code pc = some (.SWAP15, .none)) (hov : t.length + 16 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) - (pp :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: nn :: - oo :: a :: t) - mem aw rdata acc (k + 1) (C + 3) := - h.stepSwap (fun _ hc hp hs => swap15_xstep hc hp hdec hs hov) - --- LIBRARY CANDIDATE: fills the missing `Reasoning.Theory` wrapper for EVM `SWAP14`. -theorem swap14_xstep {s : State} {code : ByteArray} - {pcv a b c d e f gg hh ii jj kk ll mm nn oo : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.SWAP14, .none)) - (hstk : s.machineState.stack = - a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: nn :: - oo :: t) - (hov : t.length + 15 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok - (stSwap s - (oo :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: - nn :: a :: t), - .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.SWAP14, .none) := by - rw [hcode, hpc]; exact hdec - rw [← hcode, step_swap14 s hd, hstk] - have hov' : - ¬ ((a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: - nn :: oo :: t).length - 15 + 15 > 1024) := by - simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Gverylow, stSwap] - --- LIBRARY CANDIDATE: companion `RD` combinator for the missing `SWAP14` wrapper. -theorem RD.swap14 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d e f gg hh ii jj kk ll mm nn oo : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc - (a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: nn :: - oo :: t) - mem aw rdata acc k C) - (hdec : decode code pc = some (.SWAP14, .none)) (hov : t.length + 15 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) - (oo :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: nn :: - a :: t) - mem aw rdata acc (k + 1) (C + 3) := - h.stepSwap (fun _ hc hp hs => swap14_xstep hc hp hdec hs hov) - --- LIBRARY CANDIDATE: fills the missing `Reasoning.Theory` wrapper for EVM `SWAP12`. -theorem swap12_xstep {s : State} {code : ByteArray} - {pcv a b c d e f gg hh ii jj kk ll mm : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.SWAP12, .none)) - (hstk : s.machineState.stack = - a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: t) - (hov : t.length + 13 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok - (stSwap s - (mm :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: - a :: t), - .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.SWAP12, .none) := by - rw [hcode, hpc]; exact hdec - rw [← hcode, step_swap12 s hd, hstk] - have hov' : - ¬ ((a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: - mm :: t).length - 13 + 13 > 1024) := by - simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Gverylow, stSwap] - --- LIBRARY CANDIDATE: companion `RD` combinator for the missing `SWAP12` wrapper. -theorem RD.swap12 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d e f gg hh ii jj kk ll mm : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc - (a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: mm :: t) - mem aw rdata acc k C) - (hdec : decode code pc = some (.SWAP12, .none)) (hov : t.length + 13 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) - (mm :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: kk :: ll :: a :: t) - mem aw rdata acc (k + 1) (C + 3) := - h.stepSwap (fun _ hc hp hs => swap12_xstep hc hp hdec hs hov) - --- LIBRARY CANDIDATE: fills the missing `Reasoning.Theory` wrapper for EVM `SWAP9`. -theorem swap9_xstep {s : State} {code : ByteArray} - {pcv a b c d e f gg hh ii jj : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.SWAP9, .none)) - (hstk : s.machineState.stack = a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: t) - (hov : t.length + 10 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok (stSwap s (jj :: b :: c :: d :: e :: f :: gg :: hh :: ii :: a :: t), - .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.SWAP9, .none) := by - rw [hcode, hpc]; exact hdec - rw [← hcode, step_swap9 s hd, hstk] - have hov' : - ¬ ((a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: t).length - 10 + 10 > - 1024) := by - simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Gverylow, stSwap] - --- LIBRARY CANDIDATE: companion `RD` combinator for the missing `SWAP9` wrapper. -theorem RD.swap9 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d e f gg hh ii jj : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: t) - mem aw rdata acc k C) - (hdec : decode code pc = some (.SWAP9, .none)) (hov : t.length + 10 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) - (jj :: b :: c :: d :: e :: f :: gg :: hh :: ii :: a :: t) - mem aw rdata acc (k + 1) (C + 3) := - h.stepSwap (fun _ hc hp hs => swap9_xstep hc hp hdec hs hov) - --- LIBRARY CANDIDATE: fills the missing `Reasoning.Theory` wrapper for EVM `SAR`. -theorem sar_xstep {s : State} {code : ByteArray} {pcv a b : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.SAR, .none)) - (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok (stBinop s (UInt256.sar a b) t, .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.SAR, .none) := by - rw [hcode, hpc]; exact hdec - rw [← hcode, step_sar s hd, hstk] - have hov' : ¬ ((a :: b :: t).length - 2 + 1 > 1024) := by - simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Gverylow, stBinop] - --- LIBRARY CANDIDATE: companion `RD` combinator for the missing `SAR` wrapper. -theorem RD.sar {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.SAR, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.sar a b :: t) mem aw rdata acc - (k + 1) (C + 3) := - h.stepBinop (fun _ hc hp hs => sar_xstep hc hp hdec hs hov) - --- LIBRARY CANDIDATE: state update helper for the missing EVM `SIGNEXTEND` wrapper. -def stSignextend (s : State) (res : UInt256) (t : List UInt256) : State := - { s with machineState := { s.machineState with - pc := s.machineState.pc + ⟨1⟩, - stack := res :: t, - execLength := s.machineState.execLength + 1, - gasAvailable := s.machineState.gasAvailable.subNat 5 } } - --- LIBRARY CANDIDATE: fills the missing `Reasoning.Theory` wrapper for EVM `SIGNEXTEND`. -theorem signextend_xstep {s : State} {code : ByteArray} - {pcv a b : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.SIGNEXTEND, .none)) - (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 5 then .error .OutOfGass - else .ok (stSignextend s (UInt256.signextend a b) t, .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.SIGNEXTEND, .none) := by - rw [hcode, hpc]; exact hdec - rw [← hcode, step_signextend s hd, hstk] - have hov' : ¬ ((a :: b :: t).length - 2 + 1 > 1024) := by - simp only [List.length_cons]; omega - simp only [if_neg hov', GasConstants.Glow, stSignextend] - --- LIBRARY CANDIDATE: companion `RD` combinator for the missing `SIGNEXTEND` wrapper. -theorem RD.signextend {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {pc : UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.SIGNEXTEND, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.signextend a b :: t) mem aw rdata acc - (k + 1) (C + 5) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, - hee, hworld⟩ - · exact Or.inl hoog - · have st := signextend_xstep hcode hpc hdec hstk hov - by_cases gg : g.toNat < C + 5 - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨stSignextend s (UInt256.signextend a b) t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, by omega, - by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [stSignextend]; exact hcode - · simp only [stSignextend]; rw [hpc] - · rfl - · simp only [stSignextend]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [stSignextend]; exact hmem - · simp only [stSignextend]; exact haw - · simp only [stSignextend]; exact hrdata - · simp only [stSignextend]; exact hacc - · exact hee - · exact hworld - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLog2Bits63To57 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14403⟩ - (getTickLogRAfter51Word ee :: getTickLogRSquared52Word ee :: - getTickLogRSquared53Word ee :: getTickLogRSquared54Word ee :: - getTickLogRSquared55Word ee :: getTickLogRSquared56Word ee :: - getTickLogRSquared57Word ee :: getTickLogRSquared58Word ee :: - getTickLogRSquared59Word ee :: getTickLogRSquared60Word ee :: - getTickLogRSquared61Word ee :: getTickLogRSquared62Word ee :: - getTickLogRSquared51Word ee :: ⟨127⟩ :: getTickLogRSquared63Word ee :: - getTickMsbWord ee :: getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: - ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 28 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14553⟩ - (getTickLog2After57Word ee :: getTickLogRSquared56Word ee :: - getTickLogRSquared55Word ee :: getTickLogRSquared54Word ee :: - getTickLogRSquared53Word ee :: getTickLogRSquared52Word ee :: - getTickLogRSquared51Word ee :: getTickLogRSquared50Word ee :: - getTickMsbWord ee :: getTickLogRShifted50Word ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: - ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14403 : decode code ⟨14403⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14404 : decode code ⟨14404⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14405 : decode code ⟨14405⟩ = some (.SWAP13, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14406 : decode code ⟨14406⟩ = some (.DUP14, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14407 : decode code ⟨14407⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14408 : decode code ⟨14408⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14409 : decode code ⟨14409⟩ = some (.SWAP15, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14410 : decode code ⟨14410⟩ = some (.SWAP14, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14411 : decode code ⟨14411⟩ = some (.Push .PUSH1, some (⟨127⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14413 : decode code ⟨14413⟩ = some (.NOT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14414 : decode code ⟨14414⟩ = some (.DUP16, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14415 : decode code ⟨14415⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14416 : decode code ⟨14416⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14418 : decode code ⟨14418⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14419 : decode code ⟨14419⟩ = some (.Push .PUSH1, some (⟨192⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14421 : decode code ⟨14421⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14422 : decode code ⟨14422⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14423 : decode code ⟨14423⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14424 : decode code ⟨14424⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14425 : - decode code ⟨14425⟩ = some (.Push .PUSH8, some (getTickLog2Bit63Mask, 8)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14434 : decode code ⟨14434⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14435 : decode code ⟨14435⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14436 : decode code ⟨14436⟩ = some (.Push .PUSH1, some (⟨193⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14438 : decode code ⟨14438⟩ = some (.SWAP12, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14439 : decode code ⟨14439⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14440 : decode code ⟨14440⟩ = some (.SWAP12, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14441 : decode code ⟨14441⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14442 : - decode code ⟨14442⟩ = some (.Push .PUSH8, some (getTickLog2Bit62Mask, 8)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14451 : decode code ⟨14451⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14452 : decode code ⟨14452⟩ = some (.SWAP11, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14453 : decode code ⟨14453⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14454 : decode code ⟨14454⟩ = some (.SWAP11, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14455 : decode code ⟨14455⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14456 : decode code ⟨14456⟩ = some (.Push .PUSH1, some (⟨194⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14458 : decode code ⟨14458⟩ = some (.SWAP10, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14459 : decode code ⟨14459⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14460 : decode code ⟨14460⟩ = some (.SWAP10, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14461 : decode code ⟨14461⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14462 : - decode code ⟨14462⟩ = some (.Push .PUSH8, some (getTickLog2Bit61Mask, 8)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14471 : decode code ⟨14471⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14472 : decode code ⟨14472⟩ = some (.SWAP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14473 : decode code ⟨14473⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14474 : decode code ⟨14474⟩ = some (.SWAP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14475 : decode code ⟨14475⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14476 : decode code ⟨14476⟩ = some (.Push .PUSH1, some (⟨195⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14478 : decode code ⟨14478⟩ = some (.SWAP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14479 : decode code ⟨14479⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14480 : decode code ⟨14480⟩ = some (.SWAP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14481 : decode code ⟨14481⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14482 : - decode code ⟨14482⟩ = some (.Push .PUSH8, some (getTickLog2Bit60Mask, 8)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14491 : decode code ⟨14491⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14492 : decode code ⟨14492⟩ = some (.SWAP7, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14493 : decode code ⟨14493⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14494 : decode code ⟨14494⟩ = some (.SWAP7, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14495 : decode code ⟨14495⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14496 : decode code ⟨14496⟩ = some (.Push .PUSH1, some (⟨196⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14498 : decode code ⟨14498⟩ = some (.SWAP6, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14499 : decode code ⟨14499⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14500 : decode code ⟨14500⟩ = some (.SWAP6, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14501 : decode code ⟨14501⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14502 : - decode code ⟨14502⟩ = some (.Push .PUSH8, some (getTickLog2Bit59Mask, 8)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14511 : decode code ⟨14511⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14512 : decode code ⟨14512⟩ = some (.SWAP5, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14513 : decode code ⟨14513⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14514 : decode code ⟨14514⟩ = some (.SWAP5, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14515 : decode code ⟨14515⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14516 : decode code ⟨14516⟩ = some (.Push .PUSH1, some (⟨197⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14518 : decode code ⟨14518⟩ = some (.SWAP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14519 : decode code ⟨14519⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14520 : decode code ⟨14520⟩ = some (.SWAP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14521 : decode code ⟨14521⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14522 : - decode code ⟨14522⟩ = some (.Push .PUSH8, some (getTickLog2Bit58Mask, 8)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14531 : decode code ⟨14531⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14532 : decode code ⟨14532⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14533 : decode code ⟨14533⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14534 : decode code ⟨14534⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14535 : decode code ⟨14535⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14536 : decode code ⟨14536⟩ = some (.Push .PUSH1, some (⟨198⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14538 : decode code ⟨14538⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14539 : decode code ⟨14539⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14540 : decode code ⟨14540⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14541 : decode code ⟨14541⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14542 : - decode code ⟨14542⟩ = some (.Push .PUSH8, some (getTickLog2Bit57Mask, 8)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14551 : decode code ⟨14551⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14552 : decode code ⟨14552⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14404 := by - simpa using h.dup1 hd14403 (by - simp only [List.length_cons] - omega) - have rd14405 := by - simpa [getTickLogRSquared50Word] using rd14404.mul hd14404 (by - simp only [List.length_cons] - omega) - have rd14406 := by - simpa using RD.swap13 rd14405 hd14405 (by - simp only [List.length_cons] - omega) - have rd14407 := by - simpa using rd14406.dup14 hd14406 (by - simp only [List.length_cons] - omega) - have rd14408 := by - simpa using rd14407.swap1 hd14407 (by - simp only [List.length_cons] - omega) - have rd14409 := by - simpa [getTickLogRShifted50Word] using rd14408.shr hd14408 (by - simp only [List.length_cons] - omega) - have rd14410 := by - simpa using RD.swap15 rd14409 hd14409 (by - simp only [List.length_cons] - omega) - have rd14411 := by - simpa using RD.swap14 rd14410 hd14410 (by - simp only [List.length_cons] - omega) - have rd14413 := by - simpa using rd14411.push1 ⟨127⟩ hd14411 (by - simp only [List.length_cons] - omega) - have rd14414 := by - simpa using rd14413.not hd14413 (by - simp only [List.length_cons] - omega) - have rd14415 := by - simpa using RD.dup16 rd14414 hd14414 (by - simp only [List.length_cons] - omega) - have rd14416 := by - simpa using rd14415.add hd14415 (by - simp only [List.length_cons] - omega) - have rd14418 := by - simpa using rd14416.push1 ⟨64⟩ hd14416 (by - simp only [List.length_cons] - omega) - have rd14419 := by - simpa [getTickLog2BaseWord] using rd14418.shl hd14418 (by - simp only [List.length_cons] - omega) - have rd14421 := by - simpa using rd14419.push1 ⟨192⟩ hd14419 (by - simp only [List.length_cons] - omega) - have rd14422 := by - simpa using rd14421.swap2 hd14421 (by - simp only [List.length_cons] - omega) - have rd14423 := by - simpa using rd14422.swap1 hd14422 (by - simp only [List.length_cons] - omega) - have rd14424 := by - simpa using rd14423.swap2 hd14423 (by - simp only [List.length_cons] - omega) - have rd14425 := by - simpa using rd14424.shr hd14424 (by - simp only [List.length_cons] - omega) - have rd14434 := by - simpa using rd14425.pushConst getTickLog2Bit63Mask - (by native_decide : Operation.POp.PUSH8 ≠ .PUSH0) hd14425 (by - simp only [List.length_cons] - omega) - have rd14435 := by - simpa [getTickLog2Bit63Word] using rd14434.and hd14434 (by - simp only [List.length_cons] - omega) - have rd14436 := by - simpa [getTickLog2After63Word] using rd14435.lor hd14435 (by - simp only [List.length_cons] - omega) - have rd14438 := by - simpa using rd14436.push1 ⟨193⟩ hd14436 (by - simp only [List.length_cons] - omega) - have rd14439 := by - simpa using RD.swap12 rd14438 hd14438 (by - simp only [List.length_cons] - omega) - have rd14440 := by - simpa using rd14439.swap1 hd14439 (by - simp only [List.length_cons] - omega) - have rd14441 := by - simpa using RD.swap12 rd14440 hd14440 (by - simp only [List.length_cons] - omega) - have rd14442 := by - simpa using rd14441.shr hd14441 (by - simp only [List.length_cons] - omega) - have rd14451 := by - simpa using rd14442.pushConst getTickLog2Bit62Mask - (by native_decide : Operation.POp.PUSH8 ≠ .PUSH0) hd14442 (by - simp only [List.length_cons] - omega) - have rd14452 := by - simpa [getTickLog2Bit62Word] using rd14451.and hd14451 (by - simp only [List.length_cons] - omega) - have rd14453 := by - simpa using rd14452.swap11 hd14452 (by - simp only [List.length_cons] - omega) - have rd14454 := by - simpa using rd14453.swap1 hd14453 (by - simp only [List.length_cons] - omega) - have rd14455 := by - simpa using rd14454.swap11 hd14454 (by - simp only [List.length_cons] - omega) - have rd14456 := by - simpa [getTickLog2After62Word] using rd14455.lor hd14455 (by - simp only [List.length_cons] - omega) - have rd14458 := by - simpa using rd14456.push1 ⟨194⟩ hd14456 (by - simp only [List.length_cons] - omega) - have rd14459 := by - simpa using rd14458.swap10 hd14458 (by - simp only [List.length_cons] - omega) - have rd14460 := by - simpa using rd14459.swap1 hd14459 (by - simp only [List.length_cons] - omega) - have rd14461 := by - simpa using rd14460.swap10 hd14460 (by - simp only [List.length_cons] - omega) - have rd14462 := by - simpa using rd14461.shr hd14461 (by - simp only [List.length_cons] - omega) - have rd14471 := by - simpa using rd14462.pushConst getTickLog2Bit61Mask - (by native_decide : Operation.POp.PUSH8 ≠ .PUSH0) hd14462 (by - simp only [List.length_cons] - omega) - have rd14472 := by - simpa [getTickLog2Bit61Word] using rd14471.and hd14471 (by - simp only [List.length_cons] - omega) - have rd14473 := by - simpa using RD.swap9 rd14472 hd14472 (by - simp only [List.length_cons] - omega) - have rd14474 := by - simpa using rd14473.swap1 hd14473 (by - simp only [List.length_cons] - omega) - have rd14475 := by - simpa using RD.swap9 rd14474 hd14474 (by - simp only [List.length_cons] - omega) - have rd14476 := by - simpa [getTickLog2After61Word] using rd14475.lor hd14475 (by - simp only [List.length_cons] - omega) - have rd14478 := by - simpa using rd14476.push1 ⟨195⟩ hd14476 (by - simp only [List.length_cons] - omega) - have rd14479 := by - simpa using rd14478.swap8 hd14478 (by - simp only [List.length_cons] - omega) - have rd14480 := by - simpa using rd14479.swap1 hd14479 (by - simp only [List.length_cons] - omega) - have rd14481 := by - simpa using rd14480.swap8 hd14480 (by - simp only [List.length_cons] - omega) - have rd14482 := by - simpa using rd14481.shr hd14481 (by - simp only [List.length_cons] - omega) - have rd14491 := by - simpa using rd14482.pushConst getTickLog2Bit60Mask - (by native_decide : Operation.POp.PUSH8 ≠ .PUSH0) hd14482 (by - simp only [List.length_cons] - omega) - have rd14492 := by - simpa [getTickLog2Bit60Word] using rd14491.and hd14491 (by - simp only [List.length_cons] - omega) - have rd14493 := by - simpa using rd14492.swap7 hd14492 (by - simp only [List.length_cons] - omega) - have rd14494 := by - simpa using rd14493.swap1 hd14493 (by - simp only [List.length_cons] - omega) - have rd14495 := by - simpa using rd14494.swap7 hd14494 (by - simp only [List.length_cons] - omega) - have rd14496 := by - simpa [getTickLog2After60Word] using rd14495.lor hd14495 (by - simp only [List.length_cons] - omega) - have rd14498 := by - simpa using rd14496.push1 ⟨196⟩ hd14496 (by - simp only [List.length_cons] - omega) - have rd14499 := by - simpa using rd14498.swap6 hd14498 (by - simp only [List.length_cons] - omega) - have rd14500 := by - simpa using rd14499.swap1 hd14499 (by - simp only [List.length_cons] - omega) - have rd14501 := by - simpa using rd14500.swap6 hd14500 (by - simp only [List.length_cons] - omega) - have rd14502 := by - simpa using rd14501.shr hd14501 (by - simp only [List.length_cons] - omega) - have rd14511 := by - simpa using rd14502.pushConst getTickLog2Bit59Mask - (by native_decide : Operation.POp.PUSH8 ≠ .PUSH0) hd14502 (by - simp only [List.length_cons] - omega) - have rd14512 := by - simpa [getTickLog2Bit59Word] using rd14511.and hd14511 (by - simp only [List.length_cons] - omega) - have rd14513 := by - simpa using rd14512.swap5 hd14512 (by - simp only [List.length_cons] - omega) - have rd14514 := by - simpa using rd14513.swap1 hd14513 (by - simp only [List.length_cons] - omega) - have rd14515 := by - simpa using rd14514.swap5 hd14514 (by - simp only [List.length_cons] - omega) - have rd14516 := by - simpa [getTickLog2After59Word] using rd14515.lor hd14515 (by - simp only [List.length_cons] - omega) - have rd14518 := by - simpa using rd14516.push1 ⟨197⟩ hd14516 (by - simp only [List.length_cons] - omega) - have rd14519 := by - simpa using rd14518.swap4 hd14518 (by - simp only [List.length_cons] - omega) - have rd14520 := by - simpa using rd14519.swap1 hd14519 (by - simp only [List.length_cons] - omega) - have rd14521 := by - simpa using rd14520.swap4 hd14520 (by - simp only [List.length_cons] - omega) - have rd14522 := by - simpa using rd14521.shr hd14521 (by - simp only [List.length_cons] - omega) - have rd14531 := by - simpa using rd14522.pushConst getTickLog2Bit58Mask - (by native_decide : Operation.POp.PUSH8 ≠ .PUSH0) hd14522 (by - simp only [List.length_cons] - omega) - have rd14532 := by - simpa [getTickLog2Bit58Word] using rd14531.and hd14531 (by - simp only [List.length_cons] - omega) - have rd14533 := by - simpa using rd14532.swap3 hd14532 (by - simp only [List.length_cons] - omega) - have rd14534 := by - simpa using rd14533.swap1 hd14533 (by - simp only [List.length_cons] - omega) - have rd14535 := by - simpa using rd14534.swap3 hd14534 (by - simp only [List.length_cons] - omega) - have rd14536 := by - simpa [getTickLog2After58Word] using rd14535.lor hd14535 (by - simp only [List.length_cons] - omega) - have rd14538 := by - simpa using rd14536.push1 ⟨198⟩ hd14536 (by - simp only [List.length_cons] - omega) - have rd14539 := by - simpa using rd14538.swap2 hd14538 (by - simp only [List.length_cons] - omega) - have rd14540 := by - simpa using rd14539.swap1 hd14539 (by - simp only [List.length_cons] - omega) - have rd14541 := by - simpa using rd14540.swap2 hd14540 (by - simp only [List.length_cons] - omega) - have rd14542 := by - simpa using rd14541.shr hd14541 (by - simp only [List.length_cons] - omega) - have rd14551 := by - simpa using rd14542.pushConst getTickLog2Bit57Mask - (by native_decide : Operation.POp.PUSH8 ≠ .PUSH0) hd14542 (by - simp only [List.length_cons] - omega) - have rd14552 := by - simpa [getTickLog2Bit57Word] using rd14551.and hd14551 (by - simp only [List.length_cons] - omega) - have rd14553 := by - simpa [getTickLog2After57Word] using rd14552.lor hd14552 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14553⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioLog2Bits56To50 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14553⟩ - (getTickLog2After57Word ee :: getTickLogRSquared56Word ee :: - getTickLogRSquared55Word ee :: getTickLogRSquared54Word ee :: - getTickLogRSquared53Word ee :: getTickLogRSquared52Word ee :: - getTickLogRSquared51Word ee :: getTickLogRSquared50Word ee :: - getTickMsbWord ee :: getTickLogRShifted50Word ee :: getTickRatioWord ee :: - ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: - ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 23 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14666⟩ - (getTickLog2After50Word ee :: getTickMsbWord ee :: getTickLogRShifted50Word ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14553 : decode code ⟨14553⟩ = some (.Push .PUSH1, some (⟨199⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14555 : decode code ⟨14555⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14556 : decode code ⟨14556⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14557 : decode code ⟨14557⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14558 : decode code ⟨14558⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14559 : - decode code ⟨14559⟩ = some (.Push .PUSH8, some (getTickLog2Bit56Mask, 8)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14568 : decode code ⟨14568⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14569 : decode code ⟨14569⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14570 : decode code ⟨14570⟩ = some (.Push .PUSH1, some (⟨200⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14572 : decode code ⟨14572⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14573 : decode code ⟨14573⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14574 : decode code ⟨14574⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14575 : decode code ⟨14575⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14576 : - decode code ⟨14576⟩ = some (.Push .PUSH7, some (getTickLog2Bit55Mask, 7)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14584 : decode code ⟨14584⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14585 : decode code ⟨14585⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14586 : decode code ⟨14586⟩ = some (.Push .PUSH1, some (⟨201⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14588 : decode code ⟨14588⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14589 : decode code ⟨14589⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14590 : decode code ⟨14590⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14591 : decode code ⟨14591⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14592 : - decode code ⟨14592⟩ = some (.Push .PUSH7, some (getTickLog2Bit54Mask, 7)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14600 : decode code ⟨14600⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14601 : decode code ⟨14601⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14602 : decode code ⟨14602⟩ = some (.Push .PUSH1, some (⟨202⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14604 : decode code ⟨14604⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14605 : decode code ⟨14605⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14606 : decode code ⟨14606⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14607 : decode code ⟨14607⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14608 : - decode code ⟨14608⟩ = some (.Push .PUSH7, some (getTickLog2Bit53Mask, 7)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14616 : decode code ⟨14616⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14617 : decode code ⟨14617⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14618 : decode code ⟨14618⟩ = some (.Push .PUSH1, some (⟨203⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14620 : decode code ⟨14620⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14621 : decode code ⟨14621⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14622 : decode code ⟨14622⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14623 : decode code ⟨14623⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14624 : - decode code ⟨14624⟩ = some (.Push .PUSH7, some (getTickLog2Bit52Mask, 7)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14632 : decode code ⟨14632⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14633 : decode code ⟨14633⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14634 : decode code ⟨14634⟩ = some (.Push .PUSH1, some (⟨204⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14636 : decode code ⟨14636⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14637 : decode code ⟨14637⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14638 : decode code ⟨14638⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14639 : decode code ⟨14639⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14640 : - decode code ⟨14640⟩ = some (.Push .PUSH7, some (getTickLog2Bit51Mask, 7)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14648 : decode code ⟨14648⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14649 : decode code ⟨14649⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14650 : decode code ⟨14650⟩ = some (.Push .PUSH1, some (⟨205⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14652 : decode code ⟨14652⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14653 : decode code ⟨14653⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14654 : decode code ⟨14654⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14655 : decode code ⟨14655⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14656 : - decode code ⟨14656⟩ = some (.Push .PUSH7, some (getTickLog2Bit50Mask, 7)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14664 : decode code ⟨14664⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14665 : decode code ⟨14665⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14555 := by - simpa using h.push1 ⟨199⟩ hd14553 (by - simp only [List.length_cons] - omega) - have rd14556 := by - simpa using rd14555.swap2 hd14555 (by - simp only [List.length_cons] - omega) - have rd14557 := by - simpa using rd14556.swap1 hd14556 (by - simp only [List.length_cons] - omega) - have rd14558 := by - simpa using rd14557.swap2 hd14557 (by - simp only [List.length_cons] - omega) - have rd14559 := by - simpa using rd14558.shr hd14558 (by - simp only [List.length_cons] - omega) - have rd14568 := by - simpa using rd14559.pushConst getTickLog2Bit56Mask - (by native_decide : Operation.POp.PUSH8 ≠ .PUSH0) hd14559 (by - simp only [List.length_cons] - omega) - have rd14569 := by - simpa [getTickLog2Bit56Word] using rd14568.and hd14568 (by - simp only [List.length_cons] - omega) - have rd14570 := by - simpa [getTickLog2After56Word] using rd14569.lor hd14569 (by - simp only [List.length_cons] - omega) - have rd14572 := by - simpa using rd14570.push1 ⟨200⟩ hd14570 (by - simp only [List.length_cons] - omega) - have rd14573 := by - simpa using rd14572.swap2 hd14572 (by - simp only [List.length_cons] - omega) - have rd14574 := by - simpa using rd14573.swap1 hd14573 (by - simp only [List.length_cons] - omega) - have rd14575 := by - simpa using rd14574.swap2 hd14574 (by - simp only [List.length_cons] - omega) - have rd14576 := by - simpa using rd14575.shr hd14575 (by - simp only [List.length_cons] - omega) - have rd14584 := by - simpa using rd14576.pushConst getTickLog2Bit55Mask - (by native_decide : Operation.POp.PUSH7 ≠ .PUSH0) hd14576 (by - simp only [List.length_cons] - omega) - have rd14585 := by - simpa [getTickLog2Bit55Word] using rd14584.and hd14584 (by - simp only [List.length_cons] - omega) - have rd14586 := by - simpa [getTickLog2After55Word] using rd14585.lor hd14585 (by - simp only [List.length_cons] - omega) - have rd14588 := by - simpa using rd14586.push1 ⟨201⟩ hd14586 (by - simp only [List.length_cons] - omega) - have rd14589 := by - simpa using rd14588.swap2 hd14588 (by - simp only [List.length_cons] - omega) - have rd14590 := by - simpa using rd14589.swap1 hd14589 (by - simp only [List.length_cons] - omega) - have rd14591 := by - simpa using rd14590.swap2 hd14590 (by - simp only [List.length_cons] - omega) - have rd14592 := by - simpa using rd14591.shr hd14591 (by - simp only [List.length_cons] - omega) - have rd14600 := by - simpa using rd14592.pushConst getTickLog2Bit54Mask - (by native_decide : Operation.POp.PUSH7 ≠ .PUSH0) hd14592 (by - simp only [List.length_cons] - omega) - have rd14601 := by - simpa [getTickLog2Bit54Word] using rd14600.and hd14600 (by - simp only [List.length_cons] - omega) - have rd14602 := by - simpa [getTickLog2After54Word] using rd14601.lor hd14601 (by - simp only [List.length_cons] - omega) - have rd14604 := by - simpa using rd14602.push1 ⟨202⟩ hd14602 (by - simp only [List.length_cons] - omega) - have rd14605 := by - simpa using rd14604.swap2 hd14604 (by - simp only [List.length_cons] - omega) - have rd14606 := by - simpa using rd14605.swap1 hd14605 (by - simp only [List.length_cons] - omega) - have rd14607 := by - simpa using rd14606.swap2 hd14606 (by - simp only [List.length_cons] - omega) - have rd14608 := by - simpa using rd14607.shr hd14607 (by - simp only [List.length_cons] - omega) - have rd14616 := by - simpa using rd14608.pushConst getTickLog2Bit53Mask - (by native_decide : Operation.POp.PUSH7 ≠ .PUSH0) hd14608 (by - simp only [List.length_cons] - omega) - have rd14617 := by - simpa [getTickLog2Bit53Word] using rd14616.and hd14616 (by - simp only [List.length_cons] - omega) - have rd14618 := by - simpa [getTickLog2After53Word] using rd14617.lor hd14617 (by - simp only [List.length_cons] - omega) - have rd14620 := by - simpa using rd14618.push1 ⟨203⟩ hd14618 (by - simp only [List.length_cons] - omega) - have rd14621 := by - simpa using rd14620.swap2 hd14620 (by - simp only [List.length_cons] - omega) - have rd14622 := by - simpa using rd14621.swap1 hd14621 (by - simp only [List.length_cons] - omega) - have rd14623 := by - simpa using rd14622.swap2 hd14622 (by - simp only [List.length_cons] - omega) - have rd14624 := by - simpa using rd14623.shr hd14623 (by - simp only [List.length_cons] - omega) - have rd14632 := by - simpa using rd14624.pushConst getTickLog2Bit52Mask - (by native_decide : Operation.POp.PUSH7 ≠ .PUSH0) hd14624 (by - simp only [List.length_cons] - omega) - have rd14633 := by - simpa [getTickLog2Bit52Word] using rd14632.and hd14632 (by - simp only [List.length_cons] - omega) - have rd14634 := by - simpa [getTickLog2After52Word] using rd14633.lor hd14633 (by - simp only [List.length_cons] - omega) - have rd14636 := by - simpa using rd14634.push1 ⟨204⟩ hd14634 (by - simp only [List.length_cons] - omega) - have rd14637 := by - simpa using rd14636.swap2 hd14636 (by - simp only [List.length_cons] - omega) - have rd14638 := by - simpa using rd14637.swap1 hd14637 (by - simp only [List.length_cons] - omega) - have rd14639 := by - simpa using rd14638.swap2 hd14638 (by - simp only [List.length_cons] - omega) - have rd14640 := by - simpa using rd14639.shr hd14639 (by - simp only [List.length_cons] - omega) - have rd14648 := by - simpa using rd14640.pushConst getTickLog2Bit51Mask - (by native_decide : Operation.POp.PUSH7 ≠ .PUSH0) hd14640 (by - simp only [List.length_cons] - omega) - have rd14649 := by - simpa [getTickLog2Bit51Word] using rd14648.and hd14648 (by - simp only [List.length_cons] - omega) - have rd14650 := by - simpa [getTickLog2After51Word] using rd14649.lor hd14649 (by - simp only [List.length_cons] - omega) - have rd14652 := by - simpa using rd14650.push1 ⟨205⟩ hd14650 (by - simp only [List.length_cons] - omega) - have rd14653 := by - simpa using rd14652.swap2 hd14652 (by - simp only [List.length_cons] - omega) - have rd14654 := by - simpa using rd14653.swap1 hd14653 (by - simp only [List.length_cons] - omega) - have rd14655 := by - simpa using rd14654.swap2 hd14654 (by - simp only [List.length_cons] - omega) - have rd14656 := by - simpa using rd14655.shr hd14655 (by - simp only [List.length_cons] - omega) - have rd14664 := by - simpa using rd14656.pushConst getTickLog2Bit50Mask - (by native_decide : Operation.POp.PUSH7 ≠ .PUSH0) hd14656 (by - simp only [List.length_cons] - omega) - have rd14665 := by - simpa [getTickLog2Bit50Word] using rd14664.and hd14664 (by - simp only [List.length_cons] - omega) - have rd14666 := by - simpa [getTickLog2After50Word] using rd14665.lor hd14665 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14666⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioTickEstimateSetup {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14666⟩ - (getTickLog2After50Word ee :: getTickMsbWord ee :: getTickLogRShifted50Word ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: - initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 20 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨14739⟩ - (⟨14786⟩ :: getTickLowEqHiWord ee :: getTickHiWord ee :: getTickLowWord ee :: - getTickLogSqrt10001Word ee :: getTickLog2After50Word ee :: getTickMsbWord ee :: - getTickLogRShifted50Word ee :: getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: - ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14666 : - decode code ⟨14666⟩ = - some (.Push .PUSH10, some (getTickLogSqrt10001Multiplier, 10)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14677 : decode code ⟨14677⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14678 : decode code ⟨14678⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14679 : - decode code ⟨14679⟩ = some (.Push .PUSH16, some (getTickLowOffsetWord, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14696 : decode code ⟨14696⟩ = some (.NOT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14697 : decode code ⟨14697⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14698 : decode code ⟨14698⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14699 : decode code ⟨14699⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14701 : decode code ⟨14701⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14702 : decode code ⟨14702⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14703 : decode code ⟨14703⟩ = some (.SAR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14704 : decode code ⟨14704⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14705 : - decode code ⟨14705⟩ = some (.Push .PUSH16, some (getTickHiOffsetWord, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14722 : decode code ⟨14722⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14723 : decode code ⟨14723⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14724 : decode code ⟨14724⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14725 : decode code ⟨14725⟩ = some (.SAR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14726 : decode code ⟨14726⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14728 : decode code ⟨14728⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14729 : decode code ⟨14729⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14730 : decode code ⟨14730⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14731 : decode code ⟨14731⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14732 : decode code ⟨14732⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14733 : decode code ⟨14733⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14734 : decode code ⟨14734⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14735 : decode code ⟨14735⟩ = some (.EQ, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14736 : decode code ⟨14736⟩ = some (.Push .PUSH2, some (⟨14786⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14677 := by - simpa using h.pushConst getTickLogSqrt10001Multiplier - (by native_decide : Operation.POp.PUSH10 ≠ .PUSH0) hd14666 (by - simp only [List.length_cons] - omega) - have rd14678 := by - simpa using rd14677.dup2 hd14677 (by - simp only [List.length_cons] - omega) - have rd14679 := by - simpa [getTickLogSqrt10001Word] using rd14678.mul hd14678 (by - simp only [List.length_cons] - omega) - have rd14696 := by - simpa using rd14679.pushConst getTickLowOffsetWord - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd14679 (by - simp only [List.length_cons] - omega) - have rd14697 := by - simpa using rd14696.not hd14696 (by - simp only [List.length_cons] - omega) - have rd14698 := by - simpa using rd14697.dup2 hd14697 (by - simp only [List.length_cons] - omega) - have rd14699 := by - simpa [getTickLowBiasedWord] using rd14698.add hd14698 (by - simp only [List.length_cons] - omega) - have rd14701 := by - simpa using rd14699.push1 ⟨128⟩ hd14699 (by - simp only [List.length_cons] - omega) - have rd14702 := by - simpa using rd14701.swap1 hd14701 (by - simp only [List.length_cons] - omega) - have rd14703 := by - simpa using rd14702.dup2 hd14702 (by - simp only [List.length_cons] - omega) - have rd14704 := by - simpa [getTickLowWord] using RD.sar rd14703 hd14703 (by - simp only [List.length_cons] - omega) - have rd14705 := by - simpa using rd14704.swap1 hd14704 (by - simp only [List.length_cons] - omega) - have rd14722 := by - simpa using rd14705.pushConst getTickHiOffsetWord - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd14705 (by - simp only [List.length_cons] - omega) - have rd14723 := by - simpa using rd14722.dup4 hd14722 (by - simp only [List.length_cons] - omega) - have rd14724 := by - simpa [getTickHiBiasedWord] using rd14723.add hd14723 (by - simp only [List.length_cons] - omega) - have rd14725 := by - simpa using rd14724.swap1 hd14724 (by - simp only [List.length_cons] - omega) - have rd14726 := by - simpa [getTickHiWord] using RD.sar rd14725 hd14725 (by - simp only [List.length_cons] - omega) - have rd14728 := by - simpa using rd14726.push1 ⟨2⟩ hd14726 (by - simp only [List.length_cons] - omega) - have rd14729 := by - simpa using rd14728.dup2 hd14728 (by - simp only [List.length_cons] - omega) - have rd14730 := by - simpa using rd14729.dup2 hd14729 (by - simp only [List.length_cons] - omega) - have rd14731 := by - simpa [getTickHiInt24Word] using RD.signextend rd14730 hd14730 (by - simp only [List.length_cons] - omega) - have rd14732 := by - simpa using rd14731.swap1 hd14731 (by - simp only [List.length_cons] - omega) - have rd14733 := by - simpa using rd14732.dup4 hd14732 (by - simp only [List.length_cons] - omega) - have rd14734 := by - simpa using rd14733.swap1 hd14733 (by - simp only [List.length_cons] - omega) - have rd14735 := by - simpa [getTickLowInt24Word] using RD.signextend rd14734 hd14734 (by - simp only [List.length_cons] - omega) - have rd14736 := by - simpa [getTickLowEqHiWord] using rd14735.eq hd14735 (by - simp only [List.length_cons] - omega) - have rd14739 := by - simpa using rd14736.push2 ⟨14786⟩ hd14736 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd14739⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickReturn.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickReturn.lean deleted file mode 100644 index aa7ff2fd..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickReturn.lean +++ /dev/null @@ -1,295 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTickLogCombine - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest10793 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨10793⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest14786 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨14786⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest14788 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨14788⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched10793 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10793⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest10793 - -theorem uniswapV3PoolJumpDestPatched14786 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨14786⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest14786 - -theorem uniswapV3PoolJumpDestPatched14788 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨14788⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest14788 - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioReturnCleanup {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tick a b c d e f gg ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14788⟩ - (tick :: a :: b :: c :: d :: e :: f :: gg :: ⟨0⟩ :: initializeArgWord ee :: - ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 18 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨10793⟩ - (tick :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14788 : decode code ⟨14788⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14789 : decode code ⟨14789⟩ = some (.SWAP10, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14790 : decode code ⟨14790⟩ = some (.SWAP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14791 : decode code ⟨14791⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14792 : decode code ⟨14792⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14793 : decode code ⟨14793⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14794 : decode code ⟨14794⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14795 : decode code ⟨14795⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14796 : decode code ⟨14796⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14797 : decode code ⟨14797⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14798 : decode code ⟨14798⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14799 : decode code ⟨14799⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14800 : decode code ⟨14800⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14789 := by - simpa using h.jumpdest hd14788 (by - simp only [List.length_cons] - omega) - have rd14790 := by - simpa using rd14789.swap10 hd14789 (by - simp only [List.length_cons] - omega) - have rd14791 := by - simpa using RD.swap9 rd14790 hd14790 (by - simp only [List.length_cons] - omega) - have rd14792 := by - simpa using rd14791.pop hd14791 (by - simp only [List.length_cons] - omega) - have rd14793 := by - simpa using rd14792.pop hd14792 (by - simp only [List.length_cons] - omega) - have rd14794 := by - simpa using rd14793.pop hd14793 (by - simp only [List.length_cons] - omega) - have rd14795 := by - simpa using rd14794.pop hd14794 (by - simp only [List.length_cons] - omega) - have rd14796 := by - simpa using rd14795.pop hd14795 (by - simp only [List.length_cons] - omega) - have rd14797 := by - simpa using rd14796.pop hd14796 (by - simp only [List.length_cons] - omega) - have rd14798 := by - simpa using rd14797.pop hd14797 (by - simp only [List.length_cons] - omega) - have rd14799 := by - simpa using rd14798.pop hd14798 (by - simp only [List.length_cons] - omega) - have rd14800 := by - simpa using rd14799.pop hd14799 (by - simp only [List.length_cons] - omega) - have rd10793 := rd14800.jump hd14800 (uniswapV3PoolJumpDestPatched10793 hpatch) (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd10793⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioReturnTickLowEq {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14739⟩ - (⟨14786⟩ :: getTickLowEqHiWord ee :: getTickHiWord ee :: getTickLowWord ee :: - getTickLogSqrt10001Word ee :: getTickLog2After50Word ee :: getTickMsbWord ee :: - getTickLogRShifted50Word ee :: getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: - ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (heq : getTickLowEqHiWord ee ≠ ⟨0⟩) - (hov : R.length + 18 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨10793⟩ - (getTickLowWord ee :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14739 : decode code ⟨14739⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14786 : decode code ⟨14786⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14787 : decode code ⟨14787⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14788 : decode code ⟨14788⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14789 : decode code ⟨14789⟩ = some (.SWAP10, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14790 : decode code ⟨14790⟩ = some (.SWAP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14791 : decode code ⟨14791⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14792 : decode code ⟨14792⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14793 : decode code ⟨14793⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14794 : decode code ⟨14794⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14795 : decode code ⟨14795⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14796 : decode code ⟨14796⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14797 : decode code ⟨14797⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14798 : decode code ⟨14798⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14799 : decode code ⟨14799⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14800 : decode code ⟨14800⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14786 := h.jumpiT hd14739 heq (uniswapV3PoolJumpDestPatched14786 hpatch) (by - simp only [List.length_cons] - omega) - have rd14787 := by - simpa using rd14786.jumpdest hd14786 (by - simp only [List.length_cons] - omega) - have rd14788 := by - simpa using rd14787.dup2 hd14787 (by - simp only [List.length_cons] - omega) - have rd14789 := by - simpa using rd14788.jumpdest hd14788 (by - simp only [List.length_cons] - omega) - have rd14790 := by - simpa using rd14789.swap10 hd14789 (by - simp only [List.length_cons] - omega) - have rd14791 := by - simpa using RD.swap9 rd14790 hd14790 (by - simp only [List.length_cons] - omega) - have rd14792 := by - simpa using rd14791.pop hd14791 (by - simp only [List.length_cons] - omega) - have rd14793 := by - simpa using rd14792.pop hd14792 (by - simp only [List.length_cons] - omega) - have rd14794 := by - simpa using rd14793.pop hd14793 (by - simp only [List.length_cons] - omega) - have rd14795 := by - simpa using rd14794.pop hd14794 (by - simp only [List.length_cons] - omega) - have rd14796 := by - simpa using rd14795.pop hd14795 (by - simp only [List.length_cons] - omega) - have rd14797 := by - simpa using rd14796.pop hd14796 (by - simp only [List.length_cons] - omega) - have rd14798 := by - simpa using rd14797.pop hd14797 (by - simp only [List.length_cons] - omega) - have rd14799 := by - simpa using rd14798.pop hd14798 (by - simp only [List.length_cons] - omega) - have rd14800 := by - simpa using rd14799.pop hd14799 (by - simp only [List.length_cons] - omega) - have rd10793 := rd14800.jump hd14800 (uniswapV3PoolJumpDestPatched10793 hpatch) (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd10793⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatio.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatio.lean deleted file mode 100644 index 0fc07ac2..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatio.lean +++ /dev/null @@ -1,1068 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTickReturn - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def getSqrtRatioTickInt24Word (tick : UInt256) : UInt256 := - UInt256.signextend ⟨2⟩ tick - -def getSqrtRatioTickNegWord (tick : UInt256) : UInt256 := - UInt256.slt (getSqrtRatioTickInt24Word tick) ⟨0⟩ - -def getSqrtRatioAbsTickNegWord (tick : UInt256) : UInt256 := - UInt256.sub ⟨0⟩ (getSqrtRatioTickInt24Word tick) - -def getSqrtRatioMaxTickWord : UInt256 := ⟨887272⟩ - -def getSqrtRatioAbsTickInRangeWord (absTick : UInt256) : UInt256 := - UInt256.isZero (UInt256.gt absTick getSqrtRatioMaxTickWord) - -def getSqrtRatioBit1Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨1⟩ - -def getSqrtRatioInitialEvenWord : UInt256 := - UInt256.shiftLeft ⟨1⟩ ⟨128⟩ - -def getSqrtRatioInitialOddWord : UInt256 := - ⟨340265354078544963557816517032075149313⟩ - -def getSqrtRatioUint136Mask : UInt256 := - ⟨87112285931760246646623899502532662132735⟩ - -def getSqrtRatioRatioMaskedWord (ratio : UInt256) : UInt256 := - UInt256.land getSqrtRatioUint136Mask ratio - -def getSqrtRatioBit2Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨2⟩ - -def getSqrtRatioFactor2Word : UInt256 := - ⟨340248342086729790484326174814286782778⟩ - -def getSqrtRatioAfterBit2Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor2Word - (getSqrtRatioRatioMaskedWord ratio)) ⟨128⟩ - -theorem uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick {v : PoolImmutables} - {pc : UInt256} {n : Nat} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + n ≤ 13989) : - ∀ p ∈ patches v, pc.toNat + n ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11629 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11629⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11652 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11652⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11660 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11660⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11722 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11722⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11742 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11742⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11760 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11760⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11812 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11812⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched11629 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11629⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11629 - -theorem uniswapV3PoolJumpDestPatched11652 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11652⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11652 - -theorem uniswapV3PoolJumpDestPatched11660 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11660⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11660 - -theorem uniswapV3PoolJumpDestPatched11722 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11722⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11722 - -theorem uniswapV3PoolJumpDestPatched11742 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11742⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11742 - -theorem uniswapV3PoolJumpDestPatched11760 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11760⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11760 - -theorem uniswapV3PoolJumpDestPatched11812 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11812⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11812 - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioSqrtRatioCallSetup {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14739⟩ - (⟨14786⟩ :: getTickLowEqHiWord ee :: getTickHiWord ee :: getTickLowWord ee :: - getTickLogSqrt10001Word ee :: getTickLog2After50Word ee :: getTickMsbWord ee :: - getTickLogRShifted50Word ee :: getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: - ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (heq : getTickLowEqHiWord ee = ⟨0⟩) - (hov : R.length + 18 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11629⟩ - (getTickHiWord ee :: ⟨14758⟩ :: initializeArgWord ee :: - getTickHiWord ee :: getTickLowWord ee :: getTickLogSqrt10001Word ee :: - getTickLog2After50Word ee :: getTickMsbWord ee :: getTickLogRShifted50Word ee :: - getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: ⟨10793⟩ :: - ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14739 : decode code ⟨14739⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14740 : decode code ⟨14740⟩ = some (.DUP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14741 : decode code ⟨14741⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14743 : decode code ⟨14743⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14745 : decode code ⟨14745⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14747 : decode code ⟨14747⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14748 : decode code ⟨14748⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14749 : decode code ⟨14749⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14750 : decode code ⟨14750⟩ = some (.Push .PUSH2, some (⟨14758⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14753 : decode code ⟨14753⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14754 : decode code ⟨14754⟩ = some (.Push .PUSH2, some (⟨11629⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14757 : decode code ⟨14757⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hargClean : UInt256.land (initializeArgWord ee) slot0Uint160Mask = - initializeArgWord ee := by - apply slot0Uint160Mask_clean - rw [initializeArgWord, show initializeUint160Mask = slot0Uint160Mask by native_decide] - exact slot0Uint160Mask_bound (calldataWord ee.calldata 4) - have hargCleanR : UInt256.land slot0Uint160Mask (initializeArgWord ee) = - initializeArgWord ee := by - rw [u256_land_comm] - exact hargClean - have rd14740 := h.jumpiNT hd14739 heq (by - simp only [List.length_cons] - omega) - have rd14741 := by - simpa using RD.dup9 rd14740 hd14740 (by - simp only [List.length_cons] - omega) - have rd14743 := by - simpa using rd14741.push1 ⟨1⟩ hd14741 (by - simp only [List.length_cons] - omega) - have rd14745 := by - simpa using rd14743.push1 ⟨1⟩ hd14743 (by - simp only [List.length_cons] - omega) - have rd14747 := by - simpa using rd14745.push1 ⟨160⟩ hd14745 (by - simp only [List.length_cons] - omega) - have rd14748 := by - simpa using rd14747.shl hd14747 (by - simp only [List.length_cons] - omega) - have rd14749 := by - simpa [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask by native_decide] using rd14748.sub hd14748 (by - simp only [List.length_cons] - omega) - have rd14750 := by - simpa [hargCleanR] using rd14749.and hd14749 (by - simp only [List.length_cons] - omega) - have rd14753 := by - simpa using rd14750.push2 ⟨14758⟩ hd14750 (by - simp only [List.length_cons] - omega) - have rd14754 := by - simpa using rd14753.dup3 hd14753 (by - simp only [List.length_cons] - omega) - have rd14757 := by - simpa using rd14754.push2 ⟨11629⟩ hd14754 (by - simp only [List.length_cons] - omega) - have rd11629 := rd14757.jump hd14757 (uniswapV3PoolJumpDestPatched11629 hpatch) (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd11629⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickAbsTickNonNeg {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11629⟩ (tick :: ret :: R) mem aw rdata acc k C) - (hnonneg : getSqrtRatioTickNegWord tick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11663⟩ - (getSqrtRatioTickInt24Word tick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11629 : decode code ⟨11629⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11630 : decode code ⟨11630⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11632 : decode code ⟨11632⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11633 : decode code ⟨11633⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11635 : decode code ⟨11635⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11636 : decode code ⟨11636⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11638 : decode code ⟨11638⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11639 : decode code ⟨11639⟩ = some (.SLT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11640 : decode code ⟨11640⟩ = some (.Push .PUSH2, some (⟨11652⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11643 : decode code ⟨11643⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11644 : decode code ⟨11644⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11645 : decode code ⟨11645⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11647 : decode code ⟨11647⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11648 : decode code ⟨11648⟩ = some (.Push .PUSH2, some (⟨11660⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11651 : decode code ⟨11651⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11660 : decode code ⟨11660⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11661 : decode code ⟨11661⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11662 : decode code ⟨11662⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd11630 := by - simpa using h.jumpdest hd11629 (by - simp only [List.length_cons] - omega) - have rd11632 := by - simpa using rd11630.push1 ⟨0⟩ hd11630 (by - simp only [List.length_cons] - omega) - have rd11633 := by - simpa using rd11632.dup1 hd11632 (by - simp only [List.length_cons] - omega) - have rd11635 := by - simpa using rd11633.push1 ⟨0⟩ hd11633 (by - simp only [List.length_cons] - omega) - have rd11636 := by - simpa using rd11635.dup4 hd11635 (by - simp only [List.length_cons] - omega) - have rd11638 := by - simpa using rd11636.push1 ⟨2⟩ hd11636 (by - simp only [List.length_cons] - omega) - have rd11639 := by - simpa [getSqrtRatioTickInt24Word] using RD.signextend rd11638 hd11638 (by - simp only [List.length_cons] - omega) - have rd11640 := by - simpa [getSqrtRatioTickNegWord] using rd11639.slt hd11639 (by - simp only [List.length_cons] - omega) - have rd11643 := by - simpa using rd11640.push2 ⟨11652⟩ hd11640 (by - simp only [List.length_cons] - omega) - have rd11644 := rd11643.jumpiNT hd11643 hnonneg (by - simp only [List.length_cons] - omega) - have rd11645 := by - simpa using rd11644.dup3 hd11644 (by - simp only [List.length_cons] - omega) - have rd11647 := by - simpa using rd11645.push1 ⟨2⟩ hd11645 (by - simp only [List.length_cons] - omega) - have rd11648 := by - simpa [getSqrtRatioTickInt24Word] using RD.signextend rd11647 hd11647 (by - simp only [List.length_cons] - omega) - have rd11651 := by - simpa using rd11648.push2 ⟨11660⟩ hd11648 (by - simp only [List.length_cons] - omega) - have rd11660 := rd11651.jump hd11651 (uniswapV3PoolJumpDestPatched11660 hpatch) (by - simp only [List.length_cons] - omega) - have rd11661 := by - simpa using rd11660.jumpdest hd11660 (by - simp only [List.length_cons] - omega) - have rd11662 := by - simpa using rd11661.swap1 hd11661 (by - simp only [List.length_cons] - omega) - have rd11663 := by - simpa using rd11662.pop hd11662 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd11663⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickAbsTickNeg {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11629⟩ (tick :: ret :: R) mem aw rdata acc k C) - (hneg : getSqrtRatioTickNegWord tick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11663⟩ - (getSqrtRatioAbsTickNegWord tick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11629 : decode code ⟨11629⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11630 : decode code ⟨11630⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11632 : decode code ⟨11632⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11633 : decode code ⟨11633⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11635 : decode code ⟨11635⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11636 : decode code ⟨11636⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11638 : decode code ⟨11638⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11639 : decode code ⟨11639⟩ = some (.SLT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11640 : decode code ⟨11640⟩ = some (.Push .PUSH2, some (⟨11652⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11643 : decode code ⟨11643⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11652 : decode code ⟨11652⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11653 : decode code ⟨11653⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11654 : decode code ⟨11654⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11656 : decode code ⟨11656⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11657 : decode code ⟨11657⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11659 : decode code ⟨11659⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11660 : decode code ⟨11660⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11661 : decode code ⟨11661⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11662 : decode code ⟨11662⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd11630 := by - simpa using h.jumpdest hd11629 (by - simp only [List.length_cons] - omega) - have rd11632 := by - simpa using rd11630.push1 ⟨0⟩ hd11630 (by - simp only [List.length_cons] - omega) - have rd11633 := by - simpa using rd11632.dup1 hd11632 (by - simp only [List.length_cons] - omega) - have rd11635 := by - simpa using rd11633.push1 ⟨0⟩ hd11633 (by - simp only [List.length_cons] - omega) - have rd11636 := by - simpa using rd11635.dup4 hd11635 (by - simp only [List.length_cons] - omega) - have rd11638 := by - simpa using rd11636.push1 ⟨2⟩ hd11636 (by - simp only [List.length_cons] - omega) - have rd11639 := by - simpa [getSqrtRatioTickInt24Word] using RD.signextend rd11638 hd11638 (by - simp only [List.length_cons] - omega) - have rd11640 := by - simpa [getSqrtRatioTickNegWord] using rd11639.slt hd11639 (by - simp only [List.length_cons] - omega) - have rd11643 := by - simpa using rd11640.push2 ⟨11652⟩ hd11640 (by - simp only [List.length_cons] - omega) - have rd11652 := rd11643.jumpiT hd11643 hneg (uniswapV3PoolJumpDestPatched11652 hpatch) (by - simp only [List.length_cons] - omega) - have rd11653 := by - simpa using rd11652.jumpdest hd11652 (by - simp only [List.length_cons] - omega) - have rd11654 := by - simpa using rd11653.dup3 hd11653 (by - simp only [List.length_cons] - omega) - have rd11656 := by - simpa using rd11654.push1 ⟨2⟩ hd11654 (by - simp only [List.length_cons] - omega) - have rd11657 := by - simpa [getSqrtRatioTickInt24Word] using RD.signextend rd11656 hd11656 (by - simp only [List.length_cons] - omega) - have rd11659 := by - simpa using rd11657.push1 ⟨0⟩ hd11657 (by - simp only [List.length_cons] - omega) - have rd11660 := by - simpa [getSqrtRatioAbsTickNegWord] using rd11659.sub hd11659 (by - simp only [List.length_cons] - omega) - have rd11661 := by - simpa using rd11660.jumpdest hd11660 (by - simp only [List.length_cons] - omega) - have rd11662 := by - simpa using rd11661.swap1 hd11661 (by - simp only [List.length_cons] - omega) - have rd11663 := by - simpa using rd11662.pop hd11662 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd11663⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickRangeOk {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11663⟩ (absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hok : getSqrtRatioAbsTickInRangeWord absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11722⟩ (absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11663 : decode code ⟨11663⟩ = some (.Push .PUSH3, some (⟨887272⟩, 3)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11667 : decode code ⟨11667⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11668 : decode code ⟨11668⟩ = some (.GT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11669 : decode code ⟨11669⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11670 : decode code ⟨11670⟩ = some (.Push .PUSH2, some (⟨11722⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11673 : decode code ⟨11673⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd11667 := by - simpa [getSqrtRatioMaxTickWord] using - h.pushConst (⟨887272⟩ : UInt256) (by native_decide : Operation.POp.PUSH3 ≠ .PUSH0) - hd11663 (by - simp only [List.length_cons] - omega) - have rd11668 := by - simpa using rd11667.dup2 hd11667 (by - simp only [List.length_cons] - omega) - have rd11669 := by - simpa [getSqrtRatioMaxTickWord] using rd11668.gt hd11668 (by - simp only [List.length_cons] - omega) - have rd11670 := by - simpa [getSqrtRatioAbsTickInRangeWord] using rd11669.iszero hd11669 (by - simp only [List.length_cons] - omega) - have rd11673 := by - simpa using rd11670.push2 ⟨11722⟩ hd11670 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd11673.jumpiT hd11673 hok (uniswapV3PoolJumpDestPatched11722 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickRatioInitEven {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11722⟩ (absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit1Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11760⟩ - (getSqrtRatioInitialEvenWord :: ⟨0⟩ :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11722 : decode code ⟨11722⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11723 : decode code ⟨11723⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11725 : decode code ⟨11725⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11727 : decode code ⟨11727⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11728 : decode code ⟨11728⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11729 : decode code ⟨11729⟩ = some (.Push .PUSH2, some (⟨11742⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11732 : decode code ⟨11732⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11733 : decode code ⟨11733⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11735 : decode code ⟨11735⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11737 : decode code ⟨11737⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11738 : decode code ⟨11738⟩ = some (.Push .PUSH2, some (⟨11760⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11741 : decode code ⟨11741⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd11723 := by - simpa using h.jumpdest hd11722 (by - simp only [List.length_cons] - omega) - have rd11725 := by - simpa using rd11723.push1 ⟨0⟩ hd11723 (by - simp only [List.length_cons] - omega) - have rd11727 := by - simpa using rd11725.push1 ⟨1⟩ hd11725 (by - simp only [List.length_cons] - omega) - have rd11728 := by - simpa using rd11727.dup3 hd11727 (by - simp only [List.length_cons] - omega) - have rd11729 := by - simpa [getSqrtRatioBit1Word] using rd11728.and hd11728 (by - simp only [List.length_cons] - omega) - have rd11732 := by - simpa using rd11729.push2 ⟨11742⟩ hd11729 (by - simp only [List.length_cons] - omega) - have rd11733 := rd11732.jumpiNT hd11732 hbit (by - simp only [List.length_cons] - omega) - have rd11735 := by - simpa using rd11733.push1 ⟨1⟩ hd11733 (by - simp only [List.length_cons] - omega) - have rd11737 := by - simpa using rd11735.push1 ⟨128⟩ hd11735 (by - simp only [List.length_cons] - omega) - have rd11738 := by - simpa [getSqrtRatioInitialEvenWord] using rd11737.shl hd11737 (by - simp only [List.length_cons] - omega) - have rd11741 := by - simpa using rd11738.push2 ⟨11760⟩ hd11738 (by - simp only [List.length_cons] - omega) - have rd11760 := rd11741.jump hd11741 (uniswapV3PoolJumpDestPatched11760 hpatch) (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd11760⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickRatioInitOdd {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11722⟩ (absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit1Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11760⟩ - (getSqrtRatioInitialOddWord :: ⟨0⟩ :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11722 : decode code ⟨11722⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11723 : decode code ⟨11723⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11725 : decode code ⟨11725⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11727 : decode code ⟨11727⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11728 : decode code ⟨11728⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11729 : decode code ⟨11729⟩ = some (.Push .PUSH2, some (⟨11742⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11732 : decode code ⟨11732⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11742 : decode code ⟨11742⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11743 : - decode code ⟨11743⟩ = - some (.Push .PUSH16, some (⟨340265354078544963557816517032075149313⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd11723 := by - simpa using h.jumpdest hd11722 (by - simp only [List.length_cons] - omega) - have rd11725 := by - simpa using rd11723.push1 ⟨0⟩ hd11723 (by - simp only [List.length_cons] - omega) - have rd11727 := by - simpa using rd11725.push1 ⟨1⟩ hd11725 (by - simp only [List.length_cons] - omega) - have rd11728 := by - simpa using rd11727.dup3 hd11727 (by - simp only [List.length_cons] - omega) - have rd11729 := by - simpa [getSqrtRatioBit1Word] using rd11728.and hd11728 (by - simp only [List.length_cons] - omega) - have rd11732 := by - simpa using rd11729.push2 ⟨11742⟩ hd11729 (by - simp only [List.length_cons] - omega) - have rd11742 := rd11732.jumpiT hd11732 hbit (uniswapV3PoolJumpDestPatched11742 hpatch) (by - simp only [List.length_cons] - omega) - have rd11743 := by - simpa using rd11742.jumpdest hd11742 (by - simp only [List.length_cons] - omega) - have rd11760 := by - simpa [getSqrtRatioInitialOddWord] using - rd11743.pushConst (⟨340265354078544963557816517032075149313⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd11743 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd11760⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit2Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11760⟩ (ratio :: ⟨0⟩ :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit2Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11812⟩ - (getSqrtRatioRatioMaskedWord ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11760 : decode code ⟨11760⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11761 : - decode code ⟨11761⟩ = - some (.Push .PUSH17, some (⟨87112285931760246646623899502532662132735⟩, 17)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11779 : decode code ⟨11779⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11780 : decode code ⟨11780⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11781 : decode code ⟨11781⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11782 : decode code ⟨11782⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11784 : decode code ⟨11784⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11785 : decode code ⟨11785⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11786 : decode code ⟨11786⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11787 : decode code ⟨11787⟩ = some (.Push .PUSH2, some (⟨11812⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11790 : decode code ⟨11790⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit2Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd11761 := by - simpa using h.jumpdest hd11760 (by - simp only [List.length_cons] - omega) - have rd11779 := by - simpa [getSqrtRatioUint136Mask] using - rd11761.pushConst (⟨87112285931760246646623899502532662132735⟩ : UInt256) - (by native_decide : Operation.POp.PUSH17 ≠ .PUSH0) hd11761 (by - simp only [List.length_cons] - omega) - have rd11780 := by - simpa [getSqrtRatioRatioMaskedWord, getSqrtRatioUint136Mask] using - rd11779.and hd11779 (by - simp only [List.length_cons] - omega) - have rd11781 := by - simpa using rd11780.swap1 hd11780 (by - simp only [List.length_cons] - omega) - have rd11782 := by - simpa using rd11781.pop hd11781 (by - simp only [List.length_cons] - omega) - have rd11784 := by - simpa using rd11782.push1 ⟨2⟩ hd11782 (by - simp only [List.length_cons] - omega) - have rd11785 := by - simpa using rd11784.dup3 hd11784 (by - simp only [List.length_cons] - omega) - have rd11786 := by - simpa [getSqrtRatioBit2Word] using rd11785.and hd11785 (by - simp only [List.length_cons] - omega) - have rd11787 := by - simpa using rd11786.iszero hd11786 (by - simp only [List.length_cons] - omega) - have rd11790 := by - simpa using rd11787.push2 ⟨11812⟩ hd11787 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd11790.jumpiT hd11790 hcond (uniswapV3PoolJumpDestPatched11812 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit2Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11760⟩ (ratio :: ⟨0⟩ :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit2Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11812⟩ - (getSqrtRatioAfterBit2Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11760 : decode code ⟨11760⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11761 : - decode code ⟨11761⟩ = - some (.Push .PUSH17, some (⟨87112285931760246646623899502532662132735⟩, 17)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11779 : decode code ⟨11779⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11780 : decode code ⟨11780⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11781 : decode code ⟨11781⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11782 : decode code ⟨11782⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11784 : decode code ⟨11784⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11785 : decode code ⟨11785⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11786 : decode code ⟨11786⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11787 : decode code ⟨11787⟩ = some (.Push .PUSH2, some (⟨11812⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11790 : decode code ⟨11790⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11791 : - decode code ⟨11791⟩ = - some (.Push .PUSH16, some (⟨340248342086729790484326174814286782778⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11808 : decode code ⟨11808⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11809 : decode code ⟨11809⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11811 : decode code ⟨11811⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit2Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd11761 := by - simpa using h.jumpdest hd11760 (by - simp only [List.length_cons] - omega) - have rd11779 := by - simpa [getSqrtRatioUint136Mask] using - rd11761.pushConst (⟨87112285931760246646623899502532662132735⟩ : UInt256) - (by native_decide : Operation.POp.PUSH17 ≠ .PUSH0) hd11761 (by - simp only [List.length_cons] - omega) - have rd11780 := by - simpa [getSqrtRatioRatioMaskedWord, getSqrtRatioUint136Mask] using - rd11779.and hd11779 (by - simp only [List.length_cons] - omega) - have rd11781 := by - simpa using rd11780.swap1 hd11780 (by - simp only [List.length_cons] - omega) - have rd11782 := by - simpa using rd11781.pop hd11781 (by - simp only [List.length_cons] - omega) - have rd11784 := by - simpa using rd11782.push1 ⟨2⟩ hd11782 (by - simp only [List.length_cons] - omega) - have rd11785 := by - simpa using rd11784.dup3 hd11784 (by - simp only [List.length_cons] - omega) - have rd11786 := by - simpa [getSqrtRatioBit2Word] using rd11785.and hd11785 (by - simp only [List.length_cons] - omega) - have rd11787 := by - simpa using rd11786.iszero hd11786 (by - simp only [List.length_cons] - omega) - have rd11790 := by - simpa using rd11787.push2 ⟨11812⟩ hd11787 (by - simp only [List.length_cons] - omega) - have rd11791 := rd11790.jumpiNT hd11790 hcond (by - simp only [List.length_cons] - omega) - have rd11808 := by - simpa [getSqrtRatioFactor2Word] using - rd11791.pushConst (⟨340248342086729790484326174814286782778⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd11791 (by - simp only [List.length_cons] - omega) - have rd11809 := by - simpa using rd11808.mul hd11808 (by - simp only [List.length_cons] - omega) - have rd11811 := by - simpa using rd11809.push1 ⟨128⟩ hd11809 (by - simp only [List.length_cons] - omega) - have rd11812 := by - simpa [getSqrtRatioAfterBit2Word, getSqrtRatioFactor2Word] using rd11811.shr hd11811 - (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd11812⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBits.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBits.lean deleted file mode 100644 index 3b3f7df2..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBits.lean +++ /dev/null @@ -1,1799 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatio - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def getSqrtRatioBit4Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨4⟩ - -def getSqrtRatioFactor4Word : UInt256 := - ⟨340214320654664324051920982716015181260⟩ - -def getSqrtRatioAfterBit4Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor4Word ratio) ⟨128⟩ - -def getSqrtRatioBit8Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨8⟩ - -def getSqrtRatioFactor8Word : UInt256 := - ⟨340146287995602323631171512101879684304⟩ - -def getSqrtRatioAfterBit8Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor8Word ratio) ⟨128⟩ - -def getSqrtRatioBit16Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨16⟩ - -def getSqrtRatioFactor16Word : UInt256 := - ⟨340010263488231146823593991679159461444⟩ - -def getSqrtRatioAfterBit16Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor16Word ratio) ⟨128⟩ - -def getSqrtRatioBit32Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨32⟩ - -def getSqrtRatioFactor32Word : UInt256 := - ⟨339738377640345403697157401104375502016⟩ - -def getSqrtRatioAfterBit32Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor32Word ratio) ⟨128⟩ - -def getSqrtRatioBit64Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨64⟩ - -def getSqrtRatioFactor64Word : UInt256 := - ⟨339195258003219555707034227454543997025⟩ - -def getSqrtRatioAfterBit64Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor64Word ratio) ⟨128⟩ - -def getSqrtRatioBit128Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨128⟩ - -def getSqrtRatioFactor128Word : UInt256 := - ⟨338111622100601834656805679988414885971⟩ - -def getSqrtRatioAfterBit128Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor128Word ratio) ⟨128⟩ - -def getSqrtRatioBit256Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨256⟩ - -def getSqrtRatioFactor256Word : UInt256 := - ⟨335954724994790223023589805789778977700⟩ - -def getSqrtRatioAfterBit256Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor256Word ratio) ⟨128⟩ - -def getSqrtRatioBit512Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨512⟩ - -def getSqrtRatioFactor512Word : UInt256 := - ⟨331682121138379247127172139078559817300⟩ - -def getSqrtRatioAfterBit512Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor512Word ratio) ⟨128⟩ - -def getSqrtRatioBit1024Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨1024⟩ - -def getSqrtRatioFactor1024Word : UInt256 := - ⟨323299236684853023288211250268160618739⟩ - -def getSqrtRatioAfterBit1024Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor1024Word ratio) ⟨128⟩ - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11843 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11843⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11874 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11874⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11905 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11905⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11936 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11936⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11967 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11967⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11998 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11998⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12030 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12030⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12062 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12062⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12094 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12094⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched11843 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11843⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11843 - -theorem uniswapV3PoolJumpDestPatched11874 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11874⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11874 - -theorem uniswapV3PoolJumpDestPatched11905 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11905⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11905 - -theorem uniswapV3PoolJumpDestPatched11936 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11936⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11936 - -theorem uniswapV3PoolJumpDestPatched11967 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11967⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11967 - -theorem uniswapV3PoolJumpDestPatched11998 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11998⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11998 - -theorem uniswapV3PoolJumpDestPatched12030 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12030⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12030 - -theorem uniswapV3PoolJumpDestPatched12062 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12062⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12062 - -theorem uniswapV3PoolJumpDestPatched12094 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12094⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12094 - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit4Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11812⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit4Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11843⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11812 : decode code ⟨11812⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11813 : decode code ⟨11813⟩ = some (.Push .PUSH1, some (⟨4⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11815 : decode code ⟨11815⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11816 : decode code ⟨11816⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11817 : decode code ⟨11817⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11818 : decode code ⟨11818⟩ = some (.Push .PUSH2, some (⟨11843⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11821 : decode code ⟨11821⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit4Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd11813 := by - simpa using h.jumpdest hd11812 (by - simp only [List.length_cons] - omega) - have rd11815 := by - simpa using rd11813.push1 ⟨4⟩ hd11813 (by - simp only [List.length_cons] - omega) - have rd11816 := by - simpa using rd11815.dup3 hd11815 (by - simp only [List.length_cons] - omega) - have rd11817 := by - simpa [getSqrtRatioBit4Word] using rd11816.and hd11816 (by - simp only [List.length_cons] - omega) - have rd11818 := by - simpa using rd11817.iszero hd11817 (by - simp only [List.length_cons] - omega) - have rd11821 := by - simpa using rd11818.push2 ⟨11843⟩ hd11818 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd11821.jumpiT hd11821 hcond (uniswapV3PoolJumpDestPatched11843 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit4Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11812⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit4Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11843⟩ - (getSqrtRatioAfterBit4Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11812 : decode code ⟨11812⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11813 : decode code ⟨11813⟩ = some (.Push .PUSH1, some (⟨4⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11815 : decode code ⟨11815⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11816 : decode code ⟨11816⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11817 : decode code ⟨11817⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11818 : decode code ⟨11818⟩ = some (.Push .PUSH2, some (⟨11843⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11821 : decode code ⟨11821⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11822 : - decode code ⟨11822⟩ = - some (.Push .PUSH16, some (⟨340214320654664324051920982716015181260⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11839 : decode code ⟨11839⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11840 : decode code ⟨11840⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11842 : decode code ⟨11842⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit4Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd11813 := by - simpa using h.jumpdest hd11812 (by - simp only [List.length_cons] - omega) - have rd11815 := by - simpa using rd11813.push1 ⟨4⟩ hd11813 (by - simp only [List.length_cons] - omega) - have rd11816 := by - simpa using rd11815.dup3 hd11815 (by - simp only [List.length_cons] - omega) - have rd11817 := by - simpa [getSqrtRatioBit4Word] using rd11816.and hd11816 (by - simp only [List.length_cons] - omega) - have rd11818 := by - simpa using rd11817.iszero hd11817 (by - simp only [List.length_cons] - omega) - have rd11821 := by - simpa using rd11818.push2 ⟨11843⟩ hd11818 (by - simp only [List.length_cons] - omega) - have rd11822 := rd11821.jumpiNT hd11821 hcond (by - simp only [List.length_cons] - omega) - have rd11839 := by - simpa [getSqrtRatioFactor4Word] using - rd11822.pushConst (⟨340214320654664324051920982716015181260⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd11822 (by - simp only [List.length_cons] - omega) - have rd11840 := by - simpa using rd11839.mul hd11839 (by - simp only [List.length_cons] - omega) - have rd11842 := by - simpa using rd11840.push1 ⟨128⟩ hd11840 (by - simp only [List.length_cons] - omega) - have rd11843 := by - simpa [getSqrtRatioAfterBit4Word, getSqrtRatioFactor4Word] using rd11842.shr hd11842 - (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd11843⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit8Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11843⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit8Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11874⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11843 : decode code ⟨11843⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11844 : decode code ⟨11844⟩ = some (.Push .PUSH1, some (⟨8⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11846 : decode code ⟨11846⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11847 : decode code ⟨11847⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11848 : decode code ⟨11848⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11849 : decode code ⟨11849⟩ = some (.Push .PUSH2, some (⟨11874⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11852 : decode code ⟨11852⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit8Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd11844 := by - simpa using h.jumpdest hd11843 (by - simp only [List.length_cons] - omega) - have rd11846 := by - simpa using rd11844.push1 ⟨8⟩ hd11844 (by - simp only [List.length_cons] - omega) - have rd11847 := by - simpa using rd11846.dup3 hd11846 (by - simp only [List.length_cons] - omega) - have rd11848 := by - simpa [getSqrtRatioBit8Word] using rd11847.and hd11847 (by - simp only [List.length_cons] - omega) - have rd11849 := by - simpa using rd11848.iszero hd11848 (by - simp only [List.length_cons] - omega) - have rd11852 := by - simpa using rd11849.push2 ⟨11874⟩ hd11849 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd11852.jumpiT hd11852 hcond (uniswapV3PoolJumpDestPatched11874 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit8Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11843⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit8Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11874⟩ - (getSqrtRatioAfterBit8Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11843 : decode code ⟨11843⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11844 : decode code ⟨11844⟩ = some (.Push .PUSH1, some (⟨8⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11846 : decode code ⟨11846⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11847 : decode code ⟨11847⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11848 : decode code ⟨11848⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11849 : decode code ⟨11849⟩ = some (.Push .PUSH2, some (⟨11874⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11852 : decode code ⟨11852⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11853 : - decode code ⟨11853⟩ = - some (.Push .PUSH16, some (⟨340146287995602323631171512101879684304⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11870 : decode code ⟨11870⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11871 : decode code ⟨11871⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11873 : decode code ⟨11873⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit8Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd11844 := by - simpa using h.jumpdest hd11843 (by - simp only [List.length_cons] - omega) - have rd11846 := by - simpa using rd11844.push1 ⟨8⟩ hd11844 (by - simp only [List.length_cons] - omega) - have rd11847 := by - simpa using rd11846.dup3 hd11846 (by - simp only [List.length_cons] - omega) - have rd11848 := by - simpa [getSqrtRatioBit8Word] using rd11847.and hd11847 (by - simp only [List.length_cons] - omega) - have rd11849 := by - simpa using rd11848.iszero hd11848 (by - simp only [List.length_cons] - omega) - have rd11852 := by - simpa using rd11849.push2 ⟨11874⟩ hd11849 (by - simp only [List.length_cons] - omega) - have rd11853 := rd11852.jumpiNT hd11852 hcond (by - simp only [List.length_cons] - omega) - have rd11870 := by - simpa [getSqrtRatioFactor8Word] using - rd11853.pushConst (⟨340146287995602323631171512101879684304⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd11853 (by - simp only [List.length_cons] - omega) - have rd11871 := by - simpa using rd11870.mul hd11870 (by - simp only [List.length_cons] - omega) - have rd11873 := by - simpa using rd11871.push1 ⟨128⟩ hd11871 (by - simp only [List.length_cons] - omega) - have rd11874 := by - simpa [getSqrtRatioAfterBit8Word, getSqrtRatioFactor8Word] using rd11873.shr hd11873 - (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd11874⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit16Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11874⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit16Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11905⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11874 : decode code ⟨11874⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11875 : decode code ⟨11875⟩ = some (.Push .PUSH1, some (⟨16⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11877 : decode code ⟨11877⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11878 : decode code ⟨11878⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11879 : decode code ⟨11879⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11880 : decode code ⟨11880⟩ = some (.Push .PUSH2, some (⟨11905⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11883 : decode code ⟨11883⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit16Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd11875 := by - simpa using h.jumpdest hd11874 (by - simp only [List.length_cons] - omega) - have rd11877 := by - simpa using rd11875.push1 ⟨16⟩ hd11875 (by - simp only [List.length_cons] - omega) - have rd11878 := by - simpa using rd11877.dup3 hd11877 (by - simp only [List.length_cons] - omega) - have rd11879 := by - simpa [getSqrtRatioBit16Word] using rd11878.and hd11878 (by - simp only [List.length_cons] - omega) - have rd11880 := by - simpa using rd11879.iszero hd11879 (by - simp only [List.length_cons] - omega) - have rd11883 := by - simpa using rd11880.push2 ⟨11905⟩ hd11880 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd11883.jumpiT hd11883 hcond (uniswapV3PoolJumpDestPatched11905 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit16Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11874⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit16Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11905⟩ - (getSqrtRatioAfterBit16Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11874 : decode code ⟨11874⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11875 : decode code ⟨11875⟩ = some (.Push .PUSH1, some (⟨16⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11877 : decode code ⟨11877⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11878 : decode code ⟨11878⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11879 : decode code ⟨11879⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11880 : decode code ⟨11880⟩ = some (.Push .PUSH2, some (⟨11905⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11883 : decode code ⟨11883⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11884 : - decode code ⟨11884⟩ = - some (.Push .PUSH16, some (⟨340010263488231146823593991679159461444⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11901 : decode code ⟨11901⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11902 : decode code ⟨11902⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11904 : decode code ⟨11904⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit16Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd11875 := by - simpa using h.jumpdest hd11874 (by - simp only [List.length_cons] - omega) - have rd11877 := by - simpa using rd11875.push1 ⟨16⟩ hd11875 (by - simp only [List.length_cons] - omega) - have rd11878 := by - simpa using rd11877.dup3 hd11877 (by - simp only [List.length_cons] - omega) - have rd11879 := by - simpa [getSqrtRatioBit16Word] using rd11878.and hd11878 (by - simp only [List.length_cons] - omega) - have rd11880 := by - simpa using rd11879.iszero hd11879 (by - simp only [List.length_cons] - omega) - have rd11883 := by - simpa using rd11880.push2 ⟨11905⟩ hd11880 (by - simp only [List.length_cons] - omega) - have rd11884 := rd11883.jumpiNT hd11883 hcond (by - simp only [List.length_cons] - omega) - have rd11901 := by - simpa [getSqrtRatioFactor16Word] using - rd11884.pushConst (⟨340010263488231146823593991679159461444⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd11884 (by - simp only [List.length_cons] - omega) - have rd11902 := by - simpa using rd11901.mul hd11901 (by - simp only [List.length_cons] - omega) - have rd11904 := by - simpa using rd11902.push1 ⟨128⟩ hd11902 (by - simp only [List.length_cons] - omega) - have rd11905 := by - simpa [getSqrtRatioAfterBit16Word, getSqrtRatioFactor16Word] using - rd11904.shr hd11904 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd11905⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit32Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11905⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit32Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11936⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11905 : decode code ⟨11905⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11906 : decode code ⟨11906⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11908 : decode code ⟨11908⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11909 : decode code ⟨11909⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11910 : decode code ⟨11910⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11911 : decode code ⟨11911⟩ = some (.Push .PUSH2, some (⟨11936⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11914 : decode code ⟨11914⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit32Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd11906 := by - simpa using h.jumpdest hd11905 (by - simp only [List.length_cons] - omega) - have rd11908 := by - simpa using rd11906.push1 ⟨32⟩ hd11906 (by - simp only [List.length_cons] - omega) - have rd11909 := by - simpa using rd11908.dup3 hd11908 (by - simp only [List.length_cons] - omega) - have rd11910 := by - simpa [getSqrtRatioBit32Word] using rd11909.and hd11909 (by - simp only [List.length_cons] - omega) - have rd11911 := by - simpa using rd11910.iszero hd11910 (by - simp only [List.length_cons] - omega) - have rd11914 := by - simpa using rd11911.push2 ⟨11936⟩ hd11911 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd11914.jumpiT hd11914 hcond (uniswapV3PoolJumpDestPatched11936 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit32Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11905⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit32Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11936⟩ - (getSqrtRatioAfterBit32Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11905 : decode code ⟨11905⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11906 : decode code ⟨11906⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11908 : decode code ⟨11908⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11909 : decode code ⟨11909⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11910 : decode code ⟨11910⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11911 : decode code ⟨11911⟩ = some (.Push .PUSH2, some (⟨11936⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11914 : decode code ⟨11914⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11915 : - decode code ⟨11915⟩ = - some (.Push .PUSH16, some (⟨339738377640345403697157401104375502016⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11932 : decode code ⟨11932⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11933 : decode code ⟨11933⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11935 : decode code ⟨11935⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit32Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd11906 := by - simpa using h.jumpdest hd11905 (by - simp only [List.length_cons] - omega) - have rd11908 := by - simpa using rd11906.push1 ⟨32⟩ hd11906 (by - simp only [List.length_cons] - omega) - have rd11909 := by - simpa using rd11908.dup3 hd11908 (by - simp only [List.length_cons] - omega) - have rd11910 := by - simpa [getSqrtRatioBit32Word] using rd11909.and hd11909 (by - simp only [List.length_cons] - omega) - have rd11911 := by - simpa using rd11910.iszero hd11910 (by - simp only [List.length_cons] - omega) - have rd11914 := by - simpa using rd11911.push2 ⟨11936⟩ hd11911 (by - simp only [List.length_cons] - omega) - have rd11915 := rd11914.jumpiNT hd11914 hcond (by - simp only [List.length_cons] - omega) - have rd11932 := by - simpa [getSqrtRatioFactor32Word] using - rd11915.pushConst (⟨339738377640345403697157401104375502016⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd11915 (by - simp only [List.length_cons] - omega) - have rd11933 := by - simpa using rd11932.mul hd11932 (by - simp only [List.length_cons] - omega) - have rd11935 := by - simpa using rd11933.push1 ⟨128⟩ hd11933 (by - simp only [List.length_cons] - omega) - have rd11936 := by - simpa [getSqrtRatioAfterBit32Word, getSqrtRatioFactor32Word] using - rd11935.shr hd11935 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd11936⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit64Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11936⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit64Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11967⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11936 : decode code ⟨11936⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11937 : decode code ⟨11937⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11939 : decode code ⟨11939⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11940 : decode code ⟨11940⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11941 : decode code ⟨11941⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11942 : decode code ⟨11942⟩ = some (.Push .PUSH2, some (⟨11967⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11945 : decode code ⟨11945⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit64Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd11937 := by - simpa using h.jumpdest hd11936 (by - simp only [List.length_cons] - omega) - have rd11939 := by - simpa using rd11937.push1 ⟨64⟩ hd11937 (by - simp only [List.length_cons] - omega) - have rd11940 := by - simpa using rd11939.dup3 hd11939 (by - simp only [List.length_cons] - omega) - have rd11941 := by - simpa [getSqrtRatioBit64Word] using rd11940.and hd11940 (by - simp only [List.length_cons] - omega) - have rd11942 := by - simpa using rd11941.iszero hd11941 (by - simp only [List.length_cons] - omega) - have rd11945 := by - simpa using rd11942.push2 ⟨11967⟩ hd11942 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd11945.jumpiT hd11945 hcond (uniswapV3PoolJumpDestPatched11967 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit64Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11936⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit64Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11967⟩ - (getSqrtRatioAfterBit64Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11936 : decode code ⟨11936⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11937 : decode code ⟨11937⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11939 : decode code ⟨11939⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11940 : decode code ⟨11940⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11941 : decode code ⟨11941⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11942 : decode code ⟨11942⟩ = some (.Push .PUSH2, some (⟨11967⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11945 : decode code ⟨11945⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11946 : - decode code ⟨11946⟩ = - some (.Push .PUSH16, some (⟨339195258003219555707034227454543997025⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11963 : decode code ⟨11963⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11964 : decode code ⟨11964⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11966 : decode code ⟨11966⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit64Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd11937 := by - simpa using h.jumpdest hd11936 (by - simp only [List.length_cons] - omega) - have rd11939 := by - simpa using rd11937.push1 ⟨64⟩ hd11937 (by - simp only [List.length_cons] - omega) - have rd11940 := by - simpa using rd11939.dup3 hd11939 (by - simp only [List.length_cons] - omega) - have rd11941 := by - simpa [getSqrtRatioBit64Word] using rd11940.and hd11940 (by - simp only [List.length_cons] - omega) - have rd11942 := by - simpa using rd11941.iszero hd11941 (by - simp only [List.length_cons] - omega) - have rd11945 := by - simpa using rd11942.push2 ⟨11967⟩ hd11942 (by - simp only [List.length_cons] - omega) - have rd11946 := rd11945.jumpiNT hd11945 hcond (by - simp only [List.length_cons] - omega) - have rd11963 := by - simpa [getSqrtRatioFactor64Word] using - rd11946.pushConst (⟨339195258003219555707034227454543997025⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd11946 (by - simp only [List.length_cons] - omega) - have rd11964 := by - simpa using rd11963.mul hd11963 (by - simp only [List.length_cons] - omega) - have rd11966 := by - simpa using rd11964.push1 ⟨128⟩ hd11964 (by - simp only [List.length_cons] - omega) - have rd11967 := by - simpa [getSqrtRatioAfterBit64Word, getSqrtRatioFactor64Word] using - rd11966.shr hd11966 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd11967⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit128Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11967⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit128Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11998⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11967 : decode code ⟨11967⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11968 : decode code ⟨11968⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11970 : decode code ⟨11970⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11971 : decode code ⟨11971⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11972 : decode code ⟨11972⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11973 : decode code ⟨11973⟩ = some (.Push .PUSH2, some (⟨11998⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11976 : decode code ⟨11976⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit128Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd11968 := by - simpa using h.jumpdest hd11967 (by - simp only [List.length_cons] - omega) - have rd11970 := by - simpa using rd11968.push1 ⟨128⟩ hd11968 (by - simp only [List.length_cons] - omega) - have rd11971 := by - simpa using rd11970.dup3 hd11970 (by - simp only [List.length_cons] - omega) - have rd11972 := by - simpa [getSqrtRatioBit128Word] using rd11971.and hd11971 (by - simp only [List.length_cons] - omega) - have rd11973 := by - simpa using rd11972.iszero hd11972 (by - simp only [List.length_cons] - omega) - have rd11976 := by - simpa using rd11973.push2 ⟨11998⟩ hd11973 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd11976.jumpiT hd11976 hcond (uniswapV3PoolJumpDestPatched11998 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit128Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11967⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit128Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11998⟩ - (getSqrtRatioAfterBit128Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11967 : decode code ⟨11967⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11968 : decode code ⟨11968⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11970 : decode code ⟨11970⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11971 : decode code ⟨11971⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11972 : decode code ⟨11972⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11973 : decode code ⟨11973⟩ = some (.Push .PUSH2, some (⟨11998⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11976 : decode code ⟨11976⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11977 : - decode code ⟨11977⟩ = - some (.Push .PUSH16, some (⟨338111622100601834656805679988414885971⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11994 : decode code ⟨11994⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11995 : decode code ⟨11995⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11997 : decode code ⟨11997⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit128Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd11968 := by - simpa using h.jumpdest hd11967 (by - simp only [List.length_cons] - omega) - have rd11970 := by - simpa using rd11968.push1 ⟨128⟩ hd11968 (by - simp only [List.length_cons] - omega) - have rd11971 := by - simpa using rd11970.dup3 hd11970 (by - simp only [List.length_cons] - omega) - have rd11972 := by - simpa [getSqrtRatioBit128Word] using rd11971.and hd11971 (by - simp only [List.length_cons] - omega) - have rd11973 := by - simpa using rd11972.iszero hd11972 (by - simp only [List.length_cons] - omega) - have rd11976 := by - simpa using rd11973.push2 ⟨11998⟩ hd11973 (by - simp only [List.length_cons] - omega) - have rd11977 := rd11976.jumpiNT hd11976 hcond (by - simp only [List.length_cons] - omega) - have rd11994 := by - simpa [getSqrtRatioFactor128Word] using - rd11977.pushConst (⟨338111622100601834656805679988414885971⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd11977 (by - simp only [List.length_cons] - omega) - have rd11995 := by - simpa using rd11994.mul hd11994 (by - simp only [List.length_cons] - omega) - have rd11997 := by - simpa using rd11995.push1 ⟨128⟩ hd11995 (by - simp only [List.length_cons] - omega) - have rd11998 := by - simpa [getSqrtRatioAfterBit128Word, getSqrtRatioFactor128Word] using - rd11997.shr hd11997 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd11998⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit256Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11998⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit256Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12030⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11998 : decode code ⟨11998⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11999 : decode code ⟨11999⟩ = some (.Push .PUSH2, some (⟨256⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12002 : decode code ⟨12002⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12003 : decode code ⟨12003⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12004 : decode code ⟨12004⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12005 : decode code ⟨12005⟩ = some (.Push .PUSH2, some (⟨12030⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12008 : decode code ⟨12008⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit256Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd11999 := by - simpa using h.jumpdest hd11998 (by - simp only [List.length_cons] - omega) - have rd12002 := by - simpa using rd11999.push2 ⟨256⟩ hd11999 (by - simp only [List.length_cons] - omega) - have rd12003 := by - simpa using rd12002.dup3 hd12002 (by - simp only [List.length_cons] - omega) - have rd12004 := by - simpa [getSqrtRatioBit256Word] using rd12003.and hd12003 (by - simp only [List.length_cons] - omega) - have rd12005 := by - simpa using rd12004.iszero hd12004 (by - simp only [List.length_cons] - omega) - have rd12008 := by - simpa using rd12005.push2 ⟨12030⟩ hd12005 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12008.jumpiT hd12008 hcond (uniswapV3PoolJumpDestPatched12030 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit256Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11998⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit256Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12030⟩ - (getSqrtRatioAfterBit256Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd11998 : decode code ⟨11998⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd11999 : decode code ⟨11999⟩ = some (.Push .PUSH2, some (⟨256⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12002 : decode code ⟨12002⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12003 : decode code ⟨12003⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12004 : decode code ⟨12004⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12005 : decode code ⟨12005⟩ = some (.Push .PUSH2, some (⟨12030⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12008 : decode code ⟨12008⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12009 : - decode code ⟨12009⟩ = - some (.Push .PUSH16, some (⟨335954724994790223023589805789778977700⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12026 : decode code ⟨12026⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12027 : decode code ⟨12027⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12029 : decode code ⟨12029⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit256Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd11999 := by - simpa using h.jumpdest hd11998 (by - simp only [List.length_cons] - omega) - have rd12002 := by - simpa using rd11999.push2 ⟨256⟩ hd11999 (by - simp only [List.length_cons] - omega) - have rd12003 := by - simpa using rd12002.dup3 hd12002 (by - simp only [List.length_cons] - omega) - have rd12004 := by - simpa [getSqrtRatioBit256Word] using rd12003.and hd12003 (by - simp only [List.length_cons] - omega) - have rd12005 := by - simpa using rd12004.iszero hd12004 (by - simp only [List.length_cons] - omega) - have rd12008 := by - simpa using rd12005.push2 ⟨12030⟩ hd12005 (by - simp only [List.length_cons] - omega) - have rd12009 := rd12008.jumpiNT hd12008 hcond (by - simp only [List.length_cons] - omega) - have rd12026 := by - simpa [getSqrtRatioFactor256Word] using - rd12009.pushConst (⟨335954724994790223023589805789778977700⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd12009 (by - simp only [List.length_cons] - omega) - have rd12027 := by - simpa using rd12026.mul hd12026 (by - simp only [List.length_cons] - omega) - have rd12029 := by - simpa using rd12027.push1 ⟨128⟩ hd12027 (by - simp only [List.length_cons] - omega) - have rd12030 := by - simpa [getSqrtRatioAfterBit256Word, getSqrtRatioFactor256Word] using - rd12029.shr hd12029 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd12030⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit512Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12030⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit512Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12062⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12030 : decode code ⟨12030⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12031 : decode code ⟨12031⟩ = some (.Push .PUSH2, some (⟨512⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12034 : decode code ⟨12034⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12035 : decode code ⟨12035⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12036 : decode code ⟨12036⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12037 : decode code ⟨12037⟩ = some (.Push .PUSH2, some (⟨12062⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12040 : decode code ⟨12040⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit512Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd12031 := by - simpa using h.jumpdest hd12030 (by - simp only [List.length_cons] - omega) - have rd12034 := by - simpa using rd12031.push2 ⟨512⟩ hd12031 (by - simp only [List.length_cons] - omega) - have rd12035 := by - simpa using rd12034.dup3 hd12034 (by - simp only [List.length_cons] - omega) - have rd12036 := by - simpa [getSqrtRatioBit512Word] using rd12035.and hd12035 (by - simp only [List.length_cons] - omega) - have rd12037 := by - simpa using rd12036.iszero hd12036 (by - simp only [List.length_cons] - omega) - have rd12040 := by - simpa using rd12037.push2 ⟨12062⟩ hd12037 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12040.jumpiT hd12040 hcond (uniswapV3PoolJumpDestPatched12062 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit512Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12030⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit512Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12062⟩ - (getSqrtRatioAfterBit512Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12030 : decode code ⟨12030⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12031 : decode code ⟨12031⟩ = some (.Push .PUSH2, some (⟨512⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12034 : decode code ⟨12034⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12035 : decode code ⟨12035⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12036 : decode code ⟨12036⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12037 : decode code ⟨12037⟩ = some (.Push .PUSH2, some (⟨12062⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12040 : decode code ⟨12040⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12041 : - decode code ⟨12041⟩ = - some (.Push .PUSH16, some (⟨331682121138379247127172139078559817300⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12058 : decode code ⟨12058⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12059 : decode code ⟨12059⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12061 : decode code ⟨12061⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit512Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd12031 := by - simpa using h.jumpdest hd12030 (by - simp only [List.length_cons] - omega) - have rd12034 := by - simpa using rd12031.push2 ⟨512⟩ hd12031 (by - simp only [List.length_cons] - omega) - have rd12035 := by - simpa using rd12034.dup3 hd12034 (by - simp only [List.length_cons] - omega) - have rd12036 := by - simpa [getSqrtRatioBit512Word] using rd12035.and hd12035 (by - simp only [List.length_cons] - omega) - have rd12037 := by - simpa using rd12036.iszero hd12036 (by - simp only [List.length_cons] - omega) - have rd12040 := by - simpa using rd12037.push2 ⟨12062⟩ hd12037 (by - simp only [List.length_cons] - omega) - have rd12041 := rd12040.jumpiNT hd12040 hcond (by - simp only [List.length_cons] - omega) - have rd12058 := by - simpa [getSqrtRatioFactor512Word] using - rd12041.pushConst (⟨331682121138379247127172139078559817300⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd12041 (by - simp only [List.length_cons] - omega) - have rd12059 := by - simpa using rd12058.mul hd12058 (by - simp only [List.length_cons] - omega) - have rd12061 := by - simpa using rd12059.push1 ⟨128⟩ hd12059 (by - simp only [List.length_cons] - omega) - have rd12062 := by - simpa [getSqrtRatioAfterBit512Word, getSqrtRatioFactor512Word] using - rd12061.shr hd12061 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd12062⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit1024Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12062⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit1024Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12094⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12062 : decode code ⟨12062⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12063 : decode code ⟨12063⟩ = some (.Push .PUSH2, some (⟨1024⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12066 : decode code ⟨12066⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12067 : decode code ⟨12067⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12068 : decode code ⟨12068⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12069 : decode code ⟨12069⟩ = some (.Push .PUSH2, some (⟨12094⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12072 : decode code ⟨12072⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit1024Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd12063 := by - simpa using h.jumpdest hd12062 (by - simp only [List.length_cons] - omega) - have rd12066 := by - simpa using rd12063.push2 ⟨1024⟩ hd12063 (by - simp only [List.length_cons] - omega) - have rd12067 := by - simpa using rd12066.dup3 hd12066 (by - simp only [List.length_cons] - omega) - have rd12068 := by - simpa [getSqrtRatioBit1024Word] using rd12067.and hd12067 (by - simp only [List.length_cons] - omega) - have rd12069 := by - simpa using rd12068.iszero hd12068 (by - simp only [List.length_cons] - omega) - have rd12072 := by - simpa using rd12069.push2 ⟨12094⟩ hd12069 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12072.jumpiT hd12072 hcond (uniswapV3PoolJumpDestPatched12094 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit1024Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12062⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit1024Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12094⟩ - (getSqrtRatioAfterBit1024Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12062 : decode code ⟨12062⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12063 : decode code ⟨12063⟩ = some (.Push .PUSH2, some (⟨1024⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12066 : decode code ⟨12066⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12067 : decode code ⟨12067⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12068 : decode code ⟨12068⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12069 : decode code ⟨12069⟩ = some (.Push .PUSH2, some (⟨12094⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12072 : decode code ⟨12072⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12073 : - decode code ⟨12073⟩ = - some (.Push .PUSH16, some (⟨323299236684853023288211250268160618739⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12090 : decode code ⟨12090⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12091 : decode code ⟨12091⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12093 : decode code ⟨12093⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit1024Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd12063 := by - simpa using h.jumpdest hd12062 (by - simp only [List.length_cons] - omega) - have rd12066 := by - simpa using rd12063.push2 ⟨1024⟩ hd12063 (by - simp only [List.length_cons] - omega) - have rd12067 := by - simpa using rd12066.dup3 hd12066 (by - simp only [List.length_cons] - omega) - have rd12068 := by - simpa [getSqrtRatioBit1024Word] using rd12067.and hd12067 (by - simp only [List.length_cons] - omega) - have rd12069 := by - simpa using rd12068.iszero hd12068 (by - simp only [List.length_cons] - omega) - have rd12072 := by - simpa using rd12069.push2 ⟨12094⟩ hd12069 (by - simp only [List.length_cons] - omega) - have rd12073 := rd12072.jumpiNT hd12072 hcond (by - simp only [List.length_cons] - omega) - have rd12090 := by - simpa [getSqrtRatioFactor1024Word] using - rd12073.pushConst (⟨323299236684853023288211250268160618739⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd12073 (by - simp only [List.length_cons] - omega) - have rd12091 := by - simpa using rd12090.mul hd12090 (by - simp only [List.length_cons] - omega) - have rd12093 := by - simpa using rd12091.push1 ⟨128⟩ hd12091 (by - simp only [List.length_cons] - omega) - have rd12094 := by - simpa [getSqrtRatioAfterBit1024Word, getSqrtRatioFactor1024Word] using - rd12093.shr hd12093 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd12094⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBitsHigh.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBitsHigh.lean deleted file mode 100644 index 5d2e401f..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioBitsHigh.lean +++ /dev/null @@ -1,1815 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatioBits - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def getSqrtRatioBit2048Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨2048⟩ - -def getSqrtRatioFactor2048Word : UInt256 := - ⟨307163716377032989948697243942600083929⟩ - -def getSqrtRatioAfterBit2048Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor2048Word ratio) ⟨128⟩ - -def getSqrtRatioBit4096Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨4096⟩ - -def getSqrtRatioFactor4096Word : UInt256 := - ⟨277268403626896220162999269216087595045⟩ - -def getSqrtRatioAfterBit4096Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor4096Word ratio) ⟨128⟩ - -def getSqrtRatioBit8192Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨8192⟩ - -def getSqrtRatioFactor8192Word : UInt256 := - ⟨225923453940442621947126027127485391333⟩ - -def getSqrtRatioAfterBit8192Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor8192Word ratio) ⟨128⟩ - -def getSqrtRatioBit16384Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨16384⟩ - -def getSqrtRatioFactor16384Word : UInt256 := - ⟨149997214084966997727330242082538205943⟩ - -def getSqrtRatioAfterBit16384Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor16384Word ratio) ⟨128⟩ - -def getSqrtRatioBit32768Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨32768⟩ - -def getSqrtRatioFactor32768Word : UInt256 := - ⟨66119101136024775622716233608466517926⟩ - -def getSqrtRatioAfterBit32768Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor32768Word ratio) ⟨128⟩ - -def getSqrtRatioBit65536Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨65536⟩ - -def getSqrtRatioFactor65536Word : UInt256 := - ⟨12847376061809297530290974190478138313⟩ - -def getSqrtRatioAfterBit65536Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor65536Word ratio) ⟨128⟩ - -def getSqrtRatioBit131072Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨131072⟩ - -def getSqrtRatioFactor131072Word : UInt256 := - ⟨485053260817066172746253684029974020⟩ - -def getSqrtRatioAfterBit131072Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor131072Word ratio) ⟨128⟩ - -def getSqrtRatioBit262144Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨262144⟩ - -def getSqrtRatioFactor262144Word : UInt256 := - ⟨691415978906521570653435304214168⟩ - -def getSqrtRatioAfterBit262144Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor262144Word ratio) ⟨128⟩ - -def getSqrtRatioBit524288Word (absTick : UInt256) : UInt256 := - UInt256.land absTick ⟨524288⟩ - -def getSqrtRatioFactor524288Word : UInt256 := - ⟨1404880482679654955896180642⟩ - -def getSqrtRatioAfterBit524288Word (ratio : UInt256) : UInt256 := - UInt256.shiftRight (UInt256.mul getSqrtRatioFactor524288Word ratio) ⟨128⟩ - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12126 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12126⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12158 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12158⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12190 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12190⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12222 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12222⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12254 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12254⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12287 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12287⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12319 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12319⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12350 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12350⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12379 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12379⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched12126 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12126⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12126 - -theorem uniswapV3PoolJumpDestPatched12158 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12158⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12158 - -theorem uniswapV3PoolJumpDestPatched12190 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12190⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12190 - -theorem uniswapV3PoolJumpDestPatched12222 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12222⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12222 - -theorem uniswapV3PoolJumpDestPatched12254 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12254⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12254 - -theorem uniswapV3PoolJumpDestPatched12287 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12287⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12287 - -theorem uniswapV3PoolJumpDestPatched12319 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12319⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12319 - -theorem uniswapV3PoolJumpDestPatched12350 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12350⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12350 - -theorem uniswapV3PoolJumpDestPatched12379 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12379⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12379 - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit2048Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12094⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit2048Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12126⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12094 : decode code ⟨12094⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12095 : decode code ⟨12095⟩ = some (.Push .PUSH2, some (⟨2048⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12098 : decode code ⟨12098⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12099 : decode code ⟨12099⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12100 : decode code ⟨12100⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12101 : decode code ⟨12101⟩ = some (.Push .PUSH2, some (⟨12126⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12104 : decode code ⟨12104⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit2048Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd12095 := by - simpa using h.jumpdest hd12094 (by - simp only [List.length_cons] - omega) - have rd12098 := by - simpa using rd12095.push2 ⟨2048⟩ hd12095 (by - simp only [List.length_cons] - omega) - have rd12099 := by - simpa using rd12098.dup3 hd12098 (by - simp only [List.length_cons] - omega) - have rd12100 := by - simpa [getSqrtRatioBit2048Word] using rd12099.and hd12099 (by - simp only [List.length_cons] - omega) - have rd12101 := by - simpa using rd12100.iszero hd12100 (by - simp only [List.length_cons] - omega) - have rd12104 := by - simpa using rd12101.push2 ⟨12126⟩ hd12101 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12104.jumpiT hd12104 hcond (uniswapV3PoolJumpDestPatched12126 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit2048Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12094⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit2048Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12126⟩ - (getSqrtRatioAfterBit2048Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12094 : decode code ⟨12094⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12095 : decode code ⟨12095⟩ = some (.Push .PUSH2, some (⟨2048⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12098 : decode code ⟨12098⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12099 : decode code ⟨12099⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12100 : decode code ⟨12100⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12101 : decode code ⟨12101⟩ = some (.Push .PUSH2, some (⟨12126⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12104 : decode code ⟨12104⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12105 : - decode code ⟨12105⟩ = - some (.Push .PUSH16, some (⟨307163716377032989948697243942600083929⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12122 : decode code ⟨12122⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12123 : decode code ⟨12123⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12125 : decode code ⟨12125⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit2048Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd12095 := by - simpa using h.jumpdest hd12094 (by - simp only [List.length_cons] - omega) - have rd12098 := by - simpa using rd12095.push2 ⟨2048⟩ hd12095 (by - simp only [List.length_cons] - omega) - have rd12099 := by - simpa using rd12098.dup3 hd12098 (by - simp only [List.length_cons] - omega) - have rd12100 := by - simpa [getSqrtRatioBit2048Word] using rd12099.and hd12099 (by - simp only [List.length_cons] - omega) - have rd12101 := by - simpa using rd12100.iszero hd12100 (by - simp only [List.length_cons] - omega) - have rd12104 := by - simpa using rd12101.push2 ⟨12126⟩ hd12101 (by - simp only [List.length_cons] - omega) - have rd12105 := rd12104.jumpiNT hd12104 hcond (by - simp only [List.length_cons] - omega) - have rd12122 := by - simpa [getSqrtRatioFactor2048Word] using - rd12105.pushConst (⟨307163716377032989948697243942600083929⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd12105 (by - simp only [List.length_cons] - omega) - have rd12123 := by - simpa using rd12122.mul hd12122 (by - simp only [List.length_cons] - omega) - have rd12125 := by - simpa using rd12123.push1 ⟨128⟩ hd12123 (by - simp only [List.length_cons] - omega) - have rd12126 := by - simpa [getSqrtRatioAfterBit2048Word, getSqrtRatioFactor2048Word] using - rd12125.shr hd12125 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd12126⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit4096Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12126⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit4096Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12158⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12126 : decode code ⟨12126⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12127 : decode code ⟨12127⟩ = some (.Push .PUSH2, some (⟨4096⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12130 : decode code ⟨12130⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12131 : decode code ⟨12131⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12132 : decode code ⟨12132⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12133 : decode code ⟨12133⟩ = some (.Push .PUSH2, some (⟨12158⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12136 : decode code ⟨12136⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit4096Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd12127 := by - simpa using h.jumpdest hd12126 (by - simp only [List.length_cons] - omega) - have rd12130 := by - simpa using rd12127.push2 ⟨4096⟩ hd12127 (by - simp only [List.length_cons] - omega) - have rd12131 := by - simpa using rd12130.dup3 hd12130 (by - simp only [List.length_cons] - omega) - have rd12132 := by - simpa [getSqrtRatioBit4096Word] using rd12131.and hd12131 (by - simp only [List.length_cons] - omega) - have rd12133 := by - simpa using rd12132.iszero hd12132 (by - simp only [List.length_cons] - omega) - have rd12136 := by - simpa using rd12133.push2 ⟨12158⟩ hd12133 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12136.jumpiT hd12136 hcond (uniswapV3PoolJumpDestPatched12158 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit4096Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12126⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit4096Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12158⟩ - (getSqrtRatioAfterBit4096Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12126 : decode code ⟨12126⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12127 : decode code ⟨12127⟩ = some (.Push .PUSH2, some (⟨4096⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12130 : decode code ⟨12130⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12131 : decode code ⟨12131⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12132 : decode code ⟨12132⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12133 : decode code ⟨12133⟩ = some (.Push .PUSH2, some (⟨12158⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12136 : decode code ⟨12136⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12137 : - decode code ⟨12137⟩ = - some (.Push .PUSH16, some (⟨277268403626896220162999269216087595045⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12154 : decode code ⟨12154⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12155 : decode code ⟨12155⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12157 : decode code ⟨12157⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit4096Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd12127 := by - simpa using h.jumpdest hd12126 (by - simp only [List.length_cons] - omega) - have rd12130 := by - simpa using rd12127.push2 ⟨4096⟩ hd12127 (by - simp only [List.length_cons] - omega) - have rd12131 := by - simpa using rd12130.dup3 hd12130 (by - simp only [List.length_cons] - omega) - have rd12132 := by - simpa [getSqrtRatioBit4096Word] using rd12131.and hd12131 (by - simp only [List.length_cons] - omega) - have rd12133 := by - simpa using rd12132.iszero hd12132 (by - simp only [List.length_cons] - omega) - have rd12136 := by - simpa using rd12133.push2 ⟨12158⟩ hd12133 (by - simp only [List.length_cons] - omega) - have rd12137 := rd12136.jumpiNT hd12136 hcond (by - simp only [List.length_cons] - omega) - have rd12154 := by - simpa [getSqrtRatioFactor4096Word] using - rd12137.pushConst (⟨277268403626896220162999269216087595045⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd12137 (by - simp only [List.length_cons] - omega) - have rd12155 := by - simpa using rd12154.mul hd12154 (by - simp only [List.length_cons] - omega) - have rd12157 := by - simpa using rd12155.push1 ⟨128⟩ hd12155 (by - simp only [List.length_cons] - omega) - have rd12158 := by - simpa [getSqrtRatioAfterBit4096Word, getSqrtRatioFactor4096Word] using - rd12157.shr hd12157 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd12158⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit8192Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12158⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit8192Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12190⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12158 : decode code ⟨12158⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12159 : decode code ⟨12159⟩ = some (.Push .PUSH2, some (⟨8192⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12162 : decode code ⟨12162⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12163 : decode code ⟨12163⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12164 : decode code ⟨12164⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12165 : decode code ⟨12165⟩ = some (.Push .PUSH2, some (⟨12190⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12168 : decode code ⟨12168⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit8192Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd12159 := by - simpa using h.jumpdest hd12158 (by - simp only [List.length_cons] - omega) - have rd12162 := by - simpa using rd12159.push2 ⟨8192⟩ hd12159 (by - simp only [List.length_cons] - omega) - have rd12163 := by - simpa using rd12162.dup3 hd12162 (by - simp only [List.length_cons] - omega) - have rd12164 := by - simpa [getSqrtRatioBit8192Word] using rd12163.and hd12163 (by - simp only [List.length_cons] - omega) - have rd12165 := by - simpa using rd12164.iszero hd12164 (by - simp only [List.length_cons] - omega) - have rd12168 := by - simpa using rd12165.push2 ⟨12190⟩ hd12165 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12168.jumpiT hd12168 hcond (uniswapV3PoolJumpDestPatched12190 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit8192Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12158⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit8192Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12190⟩ - (getSqrtRatioAfterBit8192Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12158 : decode code ⟨12158⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12159 : decode code ⟨12159⟩ = some (.Push .PUSH2, some (⟨8192⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12162 : decode code ⟨12162⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12163 : decode code ⟨12163⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12164 : decode code ⟨12164⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12165 : decode code ⟨12165⟩ = some (.Push .PUSH2, some (⟨12190⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12168 : decode code ⟨12168⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12169 : - decode code ⟨12169⟩ = - some (.Push .PUSH16, some (⟨225923453940442621947126027127485391333⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12186 : decode code ⟨12186⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12187 : decode code ⟨12187⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12189 : decode code ⟨12189⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit8192Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd12159 := by - simpa using h.jumpdest hd12158 (by - simp only [List.length_cons] - omega) - have rd12162 := by - simpa using rd12159.push2 ⟨8192⟩ hd12159 (by - simp only [List.length_cons] - omega) - have rd12163 := by - simpa using rd12162.dup3 hd12162 (by - simp only [List.length_cons] - omega) - have rd12164 := by - simpa [getSqrtRatioBit8192Word] using rd12163.and hd12163 (by - simp only [List.length_cons] - omega) - have rd12165 := by - simpa using rd12164.iszero hd12164 (by - simp only [List.length_cons] - omega) - have rd12168 := by - simpa using rd12165.push2 ⟨12190⟩ hd12165 (by - simp only [List.length_cons] - omega) - have rd12169 := rd12168.jumpiNT hd12168 hcond (by - simp only [List.length_cons] - omega) - have rd12186 := by - simpa [getSqrtRatioFactor8192Word] using - rd12169.pushConst (⟨225923453940442621947126027127485391333⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd12169 (by - simp only [List.length_cons] - omega) - have rd12187 := by - simpa using rd12186.mul hd12186 (by - simp only [List.length_cons] - omega) - have rd12189 := by - simpa using rd12187.push1 ⟨128⟩ hd12187 (by - simp only [List.length_cons] - omega) - have rd12190 := by - simpa [getSqrtRatioAfterBit8192Word, getSqrtRatioFactor8192Word] using - rd12189.shr hd12189 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd12190⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit16384Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12190⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit16384Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12222⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12190 : decode code ⟨12190⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12191 : decode code ⟨12191⟩ = some (.Push .PUSH2, some (⟨16384⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12194 : decode code ⟨12194⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12195 : decode code ⟨12195⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12196 : decode code ⟨12196⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12197 : decode code ⟨12197⟩ = some (.Push .PUSH2, some (⟨12222⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12200 : decode code ⟨12200⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit16384Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd12191 := by - simpa using h.jumpdest hd12190 (by - simp only [List.length_cons] - omega) - have rd12194 := by - simpa using rd12191.push2 ⟨16384⟩ hd12191 (by - simp only [List.length_cons] - omega) - have rd12195 := by - simpa using rd12194.dup3 hd12194 (by - simp only [List.length_cons] - omega) - have rd12196 := by - simpa [getSqrtRatioBit16384Word] using rd12195.and hd12195 (by - simp only [List.length_cons] - omega) - have rd12197 := by - simpa using rd12196.iszero hd12196 (by - simp only [List.length_cons] - omega) - have rd12200 := by - simpa using rd12197.push2 ⟨12222⟩ hd12197 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12200.jumpiT hd12200 hcond (uniswapV3PoolJumpDestPatched12222 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit16384Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12190⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit16384Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12222⟩ - (getSqrtRatioAfterBit16384Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12190 : decode code ⟨12190⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12191 : decode code ⟨12191⟩ = some (.Push .PUSH2, some (⟨16384⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12194 : decode code ⟨12194⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12195 : decode code ⟨12195⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12196 : decode code ⟨12196⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12197 : decode code ⟨12197⟩ = some (.Push .PUSH2, some (⟨12222⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12200 : decode code ⟨12200⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12201 : - decode code ⟨12201⟩ = - some (.Push .PUSH16, some (⟨149997214084966997727330242082538205943⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12218 : decode code ⟨12218⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12219 : decode code ⟨12219⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12221 : decode code ⟨12221⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit16384Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd12191 := by - simpa using h.jumpdest hd12190 (by - simp only [List.length_cons] - omega) - have rd12194 := by - simpa using rd12191.push2 ⟨16384⟩ hd12191 (by - simp only [List.length_cons] - omega) - have rd12195 := by - simpa using rd12194.dup3 hd12194 (by - simp only [List.length_cons] - omega) - have rd12196 := by - simpa [getSqrtRatioBit16384Word] using rd12195.and hd12195 (by - simp only [List.length_cons] - omega) - have rd12197 := by - simpa using rd12196.iszero hd12196 (by - simp only [List.length_cons] - omega) - have rd12200 := by - simpa using rd12197.push2 ⟨12222⟩ hd12197 (by - simp only [List.length_cons] - omega) - have rd12201 := rd12200.jumpiNT hd12200 hcond (by - simp only [List.length_cons] - omega) - have rd12218 := by - simpa [getSqrtRatioFactor16384Word] using - rd12201.pushConst (⟨149997214084966997727330242082538205943⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd12201 (by - simp only [List.length_cons] - omega) - have rd12219 := by - simpa using rd12218.mul hd12218 (by - simp only [List.length_cons] - omega) - have rd12221 := by - simpa using rd12219.push1 ⟨128⟩ hd12219 (by - simp only [List.length_cons] - omega) - have rd12222 := by - simpa [getSqrtRatioAfterBit16384Word, getSqrtRatioFactor16384Word] using - rd12221.shr hd12221 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd12222⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit32768Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12222⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit32768Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12254⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12222 : decode code ⟨12222⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12223 : decode code ⟨12223⟩ = some (.Push .PUSH2, some (⟨32768⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12226 : decode code ⟨12226⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12227 : decode code ⟨12227⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12228 : decode code ⟨12228⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12229 : decode code ⟨12229⟩ = some (.Push .PUSH2, some (⟨12254⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12232 : decode code ⟨12232⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit32768Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd12223 := by - simpa using h.jumpdest hd12222 (by - simp only [List.length_cons] - omega) - have rd12226 := by - simpa using rd12223.push2 ⟨32768⟩ hd12223 (by - simp only [List.length_cons] - omega) - have rd12227 := by - simpa using rd12226.dup3 hd12226 (by - simp only [List.length_cons] - omega) - have rd12228 := by - simpa [getSqrtRatioBit32768Word] using rd12227.and hd12227 (by - simp only [List.length_cons] - omega) - have rd12229 := by - simpa using rd12228.iszero hd12228 (by - simp only [List.length_cons] - omega) - have rd12232 := by - simpa using rd12229.push2 ⟨12254⟩ hd12229 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12232.jumpiT hd12232 hcond (uniswapV3PoolJumpDestPatched12254 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit32768Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12222⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit32768Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12254⟩ - (getSqrtRatioAfterBit32768Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12222 : decode code ⟨12222⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12223 : decode code ⟨12223⟩ = some (.Push .PUSH2, some (⟨32768⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12226 : decode code ⟨12226⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12227 : decode code ⟨12227⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12228 : decode code ⟨12228⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12229 : decode code ⟨12229⟩ = some (.Push .PUSH2, some (⟨12254⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12232 : decode code ⟨12232⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12233 : - decode code ⟨12233⟩ = - some (.Push .PUSH16, some (⟨66119101136024775622716233608466517926⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12250 : decode code ⟨12250⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12251 : decode code ⟨12251⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12253 : decode code ⟨12253⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit32768Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd12223 := by - simpa using h.jumpdest hd12222 (by - simp only [List.length_cons] - omega) - have rd12226 := by - simpa using rd12223.push2 ⟨32768⟩ hd12223 (by - simp only [List.length_cons] - omega) - have rd12227 := by - simpa using rd12226.dup3 hd12226 (by - simp only [List.length_cons] - omega) - have rd12228 := by - simpa [getSqrtRatioBit32768Word] using rd12227.and hd12227 (by - simp only [List.length_cons] - omega) - have rd12229 := by - simpa using rd12228.iszero hd12228 (by - simp only [List.length_cons] - omega) - have rd12232 := by - simpa using rd12229.push2 ⟨12254⟩ hd12229 (by - simp only [List.length_cons] - omega) - have rd12233 := rd12232.jumpiNT hd12232 hcond (by - simp only [List.length_cons] - omega) - have rd12250 := by - simpa [getSqrtRatioFactor32768Word] using - rd12233.pushConst (⟨66119101136024775622716233608466517926⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd12233 (by - simp only [List.length_cons] - omega) - have rd12251 := by - simpa using rd12250.mul hd12250 (by - simp only [List.length_cons] - omega) - have rd12253 := by - simpa using rd12251.push1 ⟨128⟩ hd12251 (by - simp only [List.length_cons] - omega) - have rd12254 := by - simpa [getSqrtRatioAfterBit32768Word, getSqrtRatioFactor32768Word] using - rd12253.shr hd12253 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd12254⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit65536Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12254⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit65536Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12287⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12254 : decode code ⟨12254⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12255 : decode code ⟨12255⟩ = some (.Push .PUSH3, some (⟨65536⟩, 3)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12259 : decode code ⟨12259⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12260 : decode code ⟨12260⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12261 : decode code ⟨12261⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12262 : decode code ⟨12262⟩ = some (.Push .PUSH2, some (⟨12287⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12265 : decode code ⟨12265⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit65536Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd12255 := by - simpa using h.jumpdest hd12254 (by - simp only [List.length_cons] - omega) - have rd12259 := by - simpa using - rd12255.pushConst (⟨65536⟩ : UInt256) - (by native_decide : Operation.POp.PUSH3 ≠ .PUSH0) hd12255 (by - simp only [List.length_cons] - omega) - have rd12260 := by - simpa using rd12259.dup3 hd12259 (by - simp only [List.length_cons] - omega) - have rd12261 := by - simpa [getSqrtRatioBit65536Word] using rd12260.and hd12260 (by - simp only [List.length_cons] - omega) - have rd12262 := by - simpa using rd12261.iszero hd12261 (by - simp only [List.length_cons] - omega) - have rd12265 := by - simpa using rd12262.push2 ⟨12287⟩ hd12262 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12265.jumpiT hd12265 hcond (uniswapV3PoolJumpDestPatched12287 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit65536Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12254⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit65536Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12287⟩ - (getSqrtRatioAfterBit65536Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12254 : decode code ⟨12254⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12255 : decode code ⟨12255⟩ = some (.Push .PUSH3, some (⟨65536⟩, 3)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12259 : decode code ⟨12259⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12260 : decode code ⟨12260⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12261 : decode code ⟨12261⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12262 : decode code ⟨12262⟩ = some (.Push .PUSH2, some (⟨12287⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12265 : decode code ⟨12265⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12266 : - decode code ⟨12266⟩ = - some (.Push .PUSH16, some (⟨12847376061809297530290974190478138313⟩, 16)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12283 : decode code ⟨12283⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12284 : decode code ⟨12284⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12286 : decode code ⟨12286⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit65536Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd12255 := by - simpa using h.jumpdest hd12254 (by - simp only [List.length_cons] - omega) - have rd12259 := by - simpa using - rd12255.pushConst (⟨65536⟩ : UInt256) - (by native_decide : Operation.POp.PUSH3 ≠ .PUSH0) hd12255 (by - simp only [List.length_cons] - omega) - have rd12260 := by - simpa using rd12259.dup3 hd12259 (by - simp only [List.length_cons] - omega) - have rd12261 := by - simpa [getSqrtRatioBit65536Word] using rd12260.and hd12260 (by - simp only [List.length_cons] - omega) - have rd12262 := by - simpa using rd12261.iszero hd12261 (by - simp only [List.length_cons] - omega) - have rd12265 := by - simpa using rd12262.push2 ⟨12287⟩ hd12262 (by - simp only [List.length_cons] - omega) - have rd12266 := rd12265.jumpiNT hd12265 hcond (by - simp only [List.length_cons] - omega) - have rd12283 := by - simpa [getSqrtRatioFactor65536Word] using - rd12266.pushConst (⟨12847376061809297530290974190478138313⟩ : UInt256) - (by native_decide : Operation.POp.PUSH16 ≠ .PUSH0) hd12266 (by - simp only [List.length_cons] - omega) - have rd12284 := by - simpa using rd12283.mul hd12283 (by - simp only [List.length_cons] - omega) - have rd12286 := by - simpa using rd12284.push1 ⟨128⟩ hd12284 (by - simp only [List.length_cons] - omega) - have rd12287 := by - simpa [getSqrtRatioAfterBit65536Word, getSqrtRatioFactor65536Word] using - rd12286.shr hd12286 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd12287⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit131072Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12287⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit131072Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12319⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12287 : decode code ⟨12287⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12288 : decode code ⟨12288⟩ = some (.Push .PUSH3, some (⟨131072⟩, 3)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12292 : decode code ⟨12292⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12293 : decode code ⟨12293⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12294 : decode code ⟨12294⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12295 : decode code ⟨12295⟩ = some (.Push .PUSH2, some (⟨12319⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12298 : decode code ⟨12298⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit131072Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd12288 := by - simpa using h.jumpdest hd12287 (by - simp only [List.length_cons] - omega) - have rd12292 := by - simpa using - rd12288.pushConst (⟨131072⟩ : UInt256) - (by native_decide : Operation.POp.PUSH3 ≠ .PUSH0) hd12288 (by - simp only [List.length_cons] - omega) - have rd12293 := by - simpa using rd12292.dup3 hd12292 (by - simp only [List.length_cons] - omega) - have rd12294 := by - simpa [getSqrtRatioBit131072Word] using rd12293.and hd12293 (by - simp only [List.length_cons] - omega) - have rd12295 := by - simpa using rd12294.iszero hd12294 (by - simp only [List.length_cons] - omega) - have rd12298 := by - simpa using rd12295.push2 ⟨12319⟩ hd12295 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12298.jumpiT hd12298 hcond (uniswapV3PoolJumpDestPatched12319 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit131072Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12287⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit131072Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12319⟩ - (getSqrtRatioAfterBit131072Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12287 : decode code ⟨12287⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12288 : decode code ⟨12288⟩ = some (.Push .PUSH3, some (⟨131072⟩, 3)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12292 : decode code ⟨12292⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12293 : decode code ⟨12293⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12294 : decode code ⟨12294⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12295 : decode code ⟨12295⟩ = some (.Push .PUSH2, some (⟨12319⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12298 : decode code ⟨12298⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12299 : - decode code ⟨12299⟩ = - some (.Push .PUSH15, some (⟨485053260817066172746253684029974020⟩, 15)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12315 : decode code ⟨12315⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12316 : decode code ⟨12316⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12318 : decode code ⟨12318⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit131072Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd12288 := by - simpa using h.jumpdest hd12287 (by - simp only [List.length_cons] - omega) - have rd12292 := by - simpa using - rd12288.pushConst (⟨131072⟩ : UInt256) - (by native_decide : Operation.POp.PUSH3 ≠ .PUSH0) hd12288 (by - simp only [List.length_cons] - omega) - have rd12293 := by - simpa using rd12292.dup3 hd12292 (by - simp only [List.length_cons] - omega) - have rd12294 := by - simpa [getSqrtRatioBit131072Word] using rd12293.and hd12293 (by - simp only [List.length_cons] - omega) - have rd12295 := by - simpa using rd12294.iszero hd12294 (by - simp only [List.length_cons] - omega) - have rd12298 := by - simpa using rd12295.push2 ⟨12319⟩ hd12295 (by - simp only [List.length_cons] - omega) - have rd12299 := rd12298.jumpiNT hd12298 hcond (by - simp only [List.length_cons] - omega) - have rd12315 := by - simpa [getSqrtRatioFactor131072Word] using - rd12299.pushConst (⟨485053260817066172746253684029974020⟩ : UInt256) - (by native_decide : Operation.POp.PUSH15 ≠ .PUSH0) hd12299 (by - simp only [List.length_cons] - omega) - have rd12316 := by - simpa using rd12315.mul hd12315 (by - simp only [List.length_cons] - omega) - have rd12318 := by - simpa using rd12316.push1 ⟨128⟩ hd12316 (by - simp only [List.length_cons] - omega) - have rd12319 := by - simpa [getSqrtRatioAfterBit131072Word, getSqrtRatioFactor131072Word] using - rd12318.shr hd12318 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd12319⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit262144Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12319⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit262144Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12350⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12319 : decode code ⟨12319⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12320 : decode code ⟨12320⟩ = some (.Push .PUSH3, some (⟨262144⟩, 3)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12324 : decode code ⟨12324⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12325 : decode code ⟨12325⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12326 : decode code ⟨12326⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12327 : decode code ⟨12327⟩ = some (.Push .PUSH2, some (⟨12350⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12330 : decode code ⟨12330⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit262144Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd12320 := by - simpa using h.jumpdest hd12319 (by - simp only [List.length_cons] - omega) - have rd12324 := by - simpa using - rd12320.pushConst (⟨262144⟩ : UInt256) - (by native_decide : Operation.POp.PUSH3 ≠ .PUSH0) hd12320 (by - simp only [List.length_cons] - omega) - have rd12325 := by - simpa using rd12324.dup3 hd12324 (by - simp only [List.length_cons] - omega) - have rd12326 := by - simpa [getSqrtRatioBit262144Word] using rd12325.and hd12325 (by - simp only [List.length_cons] - omega) - have rd12327 := by - simpa using rd12326.iszero hd12326 (by - simp only [List.length_cons] - omega) - have rd12330 := by - simpa using rd12327.push2 ⟨12350⟩ hd12327 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12330.jumpiT hd12330 hcond (uniswapV3PoolJumpDestPatched12350 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit262144Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12319⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit262144Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12350⟩ - (getSqrtRatioAfterBit262144Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12319 : decode code ⟨12319⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12320 : decode code ⟨12320⟩ = some (.Push .PUSH3, some (⟨262144⟩, 3)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12324 : decode code ⟨12324⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12325 : decode code ⟨12325⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12326 : decode code ⟨12326⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12327 : decode code ⟨12327⟩ = some (.Push .PUSH2, some (⟨12350⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12330 : decode code ⟨12330⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12331 : - decode code ⟨12331⟩ = - some (.Push .PUSH14, some (⟨691415978906521570653435304214168⟩, 14)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12346 : decode code ⟨12346⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12347 : decode code ⟨12347⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12349 : decode code ⟨12349⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit262144Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd12320 := by - simpa using h.jumpdest hd12319 (by - simp only [List.length_cons] - omega) - have rd12324 := by - simpa using - rd12320.pushConst (⟨262144⟩ : UInt256) - (by native_decide : Operation.POp.PUSH3 ≠ .PUSH0) hd12320 (by - simp only [List.length_cons] - omega) - have rd12325 := by - simpa using rd12324.dup3 hd12324 (by - simp only [List.length_cons] - omega) - have rd12326 := by - simpa [getSqrtRatioBit262144Word] using rd12325.and hd12325 (by - simp only [List.length_cons] - omega) - have rd12327 := by - simpa using rd12326.iszero hd12326 (by - simp only [List.length_cons] - omega) - have rd12330 := by - simpa using rd12327.push2 ⟨12350⟩ hd12327 (by - simp only [List.length_cons] - omega) - have rd12331 := rd12330.jumpiNT hd12330 hcond (by - simp only [List.length_cons] - omega) - have rd12346 := by - simpa [getSqrtRatioFactor262144Word] using - rd12331.pushConst (⟨691415978906521570653435304214168⟩ : UInt256) - (by native_decide : Operation.POp.PUSH14 ≠ .PUSH0) hd12331 (by - simp only [List.length_cons] - omega) - have rd12347 := by - simpa using rd12346.mul hd12346 (by - simp only [List.length_cons] - omega) - have rd12349 := by - simpa using rd12347.push1 ⟨128⟩ hd12347 (by - simp only [List.length_cons] - omega) - have rd12350 := by - simpa [getSqrtRatioAfterBit262144Word, getSqrtRatioFactor262144Word] using - rd12349.shr hd12349 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd12350⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit524288Zero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12350⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit524288Word absTick = ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12379⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12350 : decode code ⟨12350⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12351 : decode code ⟨12351⟩ = some (.Push .PUSH3, some (⟨524288⟩, 3)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12355 : decode code ⟨12355⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12356 : decode code ⟨12356⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12357 : decode code ⟨12357⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12358 : decode code ⟨12358⟩ = some (.Push .PUSH2, some (⟨12379⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12361 : decode code ⟨12361⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit524288Word absTick) ≠ ⟨0⟩ := by - rw [hbit] - native_decide - have rd12351 := by - simpa using h.jumpdest hd12350 (by - simp only [List.length_cons] - omega) - have rd12355 := by - simpa using - rd12351.pushConst (⟨524288⟩ : UInt256) - (by native_decide : Operation.POp.PUSH3 ≠ .PUSH0) hd12351 (by - simp only [List.length_cons] - omega) - have rd12356 := by - simpa using rd12355.dup3 hd12355 (by - simp only [List.length_cons] - omega) - have rd12357 := by - simpa [getSqrtRatioBit524288Word] using rd12356.and hd12356 (by - simp only [List.length_cons] - omega) - have rd12358 := by - simpa using rd12357.iszero hd12357 (by - simp only [List.length_cons] - omega) - have rd12361 := by - simpa using rd12358.push2 ⟨12379⟩ hd12358 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12361.jumpiT hd12361 hcond (uniswapV3PoolJumpDestPatched12379 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickBit524288Set {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12350⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hbit : getSqrtRatioBit524288Word absTick ≠ ⟨0⟩) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12379⟩ - (getSqrtRatioAfterBit524288Word ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12350 : decode code ⟨12350⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12351 : decode code ⟨12351⟩ = some (.Push .PUSH3, some (⟨524288⟩, 3)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12355 : decode code ⟨12355⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12356 : decode code ⟨12356⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12357 : decode code ⟨12357⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12358 : decode code ⟨12358⟩ = some (.Push .PUSH2, some (⟨12379⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12361 : decode code ⟨12361⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12362 : - decode code ⟨12362⟩ = - some (.Push .PUSH12, some (⟨1404880482679654955896180642⟩, 12)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12375 : decode code ⟨12375⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12376 : decode code ⟨12376⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12378 : decode code ⟨12378⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioBit524288Word absTick) = ⟨0⟩ := - isZero_eq_zero_of_ne hbit - have rd12351 := by - simpa using h.jumpdest hd12350 (by - simp only [List.length_cons] - omega) - have rd12355 := by - simpa using - rd12351.pushConst (⟨524288⟩ : UInt256) - (by native_decide : Operation.POp.PUSH3 ≠ .PUSH0) hd12351 (by - simp only [List.length_cons] - omega) - have rd12356 := by - simpa using rd12355.dup3 hd12355 (by - simp only [List.length_cons] - omega) - have rd12357 := by - simpa [getSqrtRatioBit524288Word] using rd12356.and hd12356 (by - simp only [List.length_cons] - omega) - have rd12358 := by - simpa using rd12357.iszero hd12357 (by - simp only [List.length_cons] - omega) - have rd12361 := by - simpa using rd12358.push2 ⟨12379⟩ hd12358 (by - simp only [List.length_cons] - omega) - have rd12362 := rd12361.jumpiNT hd12361 hcond (by - simp only [List.length_cons] - omega) - have rd12375 := by - simpa [getSqrtRatioFactor524288Word] using - rd12362.pushConst (⟨1404880482679654955896180642⟩ : UInt256) - (by native_decide : Operation.POp.PUSH12 ≠ .PUSH0) hd12362 (by - simp only [List.length_cons] - omega) - have rd12376 := by - simpa using rd12375.mul hd12375 (by - simp only [List.length_cons] - omega) - have rd12378 := by - simpa using rd12376.push1 ⟨128⟩ hd12376 (by - simp only [List.length_cons] - omega) - have rd12379 := by - simpa [getSqrtRatioAfterBit524288Word, getSqrtRatioFactor524288Word] using - rd12378.shr hd12378 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd12379⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioFull.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioFull.lean deleted file mode 100644 index 267912d4..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioFull.lean +++ /dev/null @@ -1,721 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatioReturn - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def getSqrtRatioAfterBit2BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit2Word absTick = ⟨0⟩ then getSqrtRatioRatioMaskedWord ratio - else getSqrtRatioAfterBit2Word ratio - -def getSqrtRatioAfterBit4BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit4Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit4Word ratio - -def getSqrtRatioAfterBit8BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit8Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit8Word ratio - -def getSqrtRatioAfterBit16BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit16Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit16Word ratio - -def getSqrtRatioAfterBit32BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit32Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit32Word ratio - -def getSqrtRatioAfterBit64BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit64Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit64Word ratio - -def getSqrtRatioAfterBit128BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit128Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit128Word ratio - -def getSqrtRatioAfterBit256BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit256Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit256Word ratio - -def getSqrtRatioAfterBit512BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit512Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit512Word ratio - -def getSqrtRatioAfterBit1024BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit1024Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit1024Word ratio - -def getSqrtRatioAfterLowBitsWord (absTick ratio : UInt256) : UInt256 := - let r4 := getSqrtRatioAfterBit4BranchWord absTick ratio - let r8 := getSqrtRatioAfterBit8BranchWord absTick r4 - let r16 := getSqrtRatioAfterBit16BranchWord absTick r8 - let r32 := getSqrtRatioAfterBit32BranchWord absTick r16 - let r64 := getSqrtRatioAfterBit64BranchWord absTick r32 - let r128 := getSqrtRatioAfterBit128BranchWord absTick r64 - let r256 := getSqrtRatioAfterBit256BranchWord absTick r128 - let r512 := getSqrtRatioAfterBit512BranchWord absTick r256 - getSqrtRatioAfterBit1024BranchWord absTick r512 - -def getSqrtRatioAfterAllBitsWord (absTick ratio : UInt256) : UInt256 := - let r2 := getSqrtRatioAfterBit2BranchWord absTick ratio - let r1024 := getSqrtRatioAfterLowBitsWord absTick r2 - getSqrtRatioAfterHighBitsWord absTick r1024 - -def getSqrtRatioAbsTickBranchWord (tick : UInt256) : UInt256 := - if getSqrtRatioTickNegWord tick = ⟨0⟩ then getSqrtRatioTickInt24Word tick - else getSqrtRatioAbsTickNegWord tick - -def getSqrtRatioInitialBranchWord (absTick : UInt256) : UInt256 := - if getSqrtRatioBit1Word absTick = ⟨0⟩ then getSqrtRatioInitialEvenWord - else getSqrtRatioInitialOddWord - -def getSqrtRatioAtTickResultWord (tick : UInt256) : UInt256 := - let absTick := getSqrtRatioAbsTickBranchWord tick - let ratio := getSqrtRatioInitialBranchWord absTick - getSqrtRatioTailReturnWord tick (getSqrtRatioAfterAllBitsWord absTick ratio) - -def getTickHiSqrtRatioCleanWord (sqrtRatio : UInt256) : UInt256 := - UInt256.land slot0Uint160Mask sqrtRatio - -def getTickHiSqrtRatioGtInputWord (ee : ExecutionEnv) (sqrtRatio : UInt256) : UInt256 := - UInt256.gt (getTickHiSqrtRatioCleanWord sqrtRatio) (initializeArgWord ee) - -def getTickAfterHiSqrtRatioWord (ee : ExecutionEnv) (sqrtRatio : UInt256) : UInt256 := - if getTickHiSqrtRatioGtInputWord ee sqrtRatio = ⟨0⟩ then getTickHiWord ee - else getTickLowWord ee - -def getTickHiSqrtRatioWord (ee : ExecutionEnv) : UInt256 := - getSqrtRatioAtTickResultWord (getTickHiWord ee) - -def getTickEstimatedWord (ee : ExecutionEnv) : UInt256 := - if getTickLowEqHiWord ee = ⟨0⟩ then getTickAfterHiSqrtRatioWord ee (getTickHiSqrtRatioWord ee) - else getTickLowWord ee - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest14779 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨14779⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest14781 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨14781⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched14779 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨14779⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest14779 - -theorem uniswapV3PoolJumpDestPatched14781 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨14781⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest14781 - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickLowBits {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11812⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12094⟩ - (getSqrtRatioAfterLowBitsWord absTick ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - let r4 := getSqrtRatioAfterBit4BranchWord absTick ratio - have h4 : ∃ k' C', RD code ee g s0 ⟨11843⟩ - (r4 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit4Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit4Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h hbit hov - exact ⟨_, _, by simpa [r4, getSqrtRatioAfterBit4BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit4Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h hbit hov - exact ⟨_, _, by simpa [r4, getSqrtRatioAfterBit4BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h4⟩ := h4 - let r8 := getSqrtRatioAfterBit8BranchWord absTick r4 - have h8 : ∃ k' C', RD code ee g s0 ⟨11874⟩ - (r8 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit8Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit8Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r4) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h4 hbit hov - exact ⟨_, _, by simpa [r8, getSqrtRatioAfterBit8BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit8Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r4) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h4 hbit hov - exact ⟨_, _, by simpa [r8, getSqrtRatioAfterBit8BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h8⟩ := h8 - let r16 := getSqrtRatioAfterBit16BranchWord absTick r8 - have h16 : ∃ k' C', RD code ee g s0 ⟨11905⟩ - (r16 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit16Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit16Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r8) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h8 hbit hov - exact ⟨_, _, by simpa [r16, getSqrtRatioAfterBit16BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit16Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r8) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h8 hbit hov - exact ⟨_, _, by simpa [r16, getSqrtRatioAfterBit16BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h16⟩ := h16 - let r32 := getSqrtRatioAfterBit32BranchWord absTick r16 - have h32 : ∃ k' C', RD code ee g s0 ⟨11936⟩ - (r32 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit32Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit32Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r16) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h16 hbit hov - exact ⟨_, _, by simpa [r32, getSqrtRatioAfterBit32BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit32Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r16) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h16 hbit hov - exact ⟨_, _, by simpa [r32, getSqrtRatioAfterBit32BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h32⟩ := h32 - let r64 := getSqrtRatioAfterBit64BranchWord absTick r32 - have h64 : ∃ k' C', RD code ee g s0 ⟨11967⟩ - (r64 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit64Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit64Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r32) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h32 hbit hov - exact ⟨_, _, by simpa [r64, getSqrtRatioAfterBit64BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit64Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r32) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h32 hbit hov - exact ⟨_, _, by simpa [r64, getSqrtRatioAfterBit64BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h64⟩ := h64 - let r128 := getSqrtRatioAfterBit128BranchWord absTick r64 - have h128 : ∃ k' C', RD code ee g s0 ⟨11998⟩ - (r128 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit128Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit128Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r64) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h64 hbit hov - exact ⟨_, _, by simpa [r128, getSqrtRatioAfterBit128BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit128Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r64) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h64 hbit hov - exact ⟨_, _, by simpa [r128, getSqrtRatioAfterBit128BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h128⟩ := h128 - let r256 := getSqrtRatioAfterBit256BranchWord absTick r128 - have h256 : ∃ k' C', RD code ee g s0 ⟨12030⟩ - (r256 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit256Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit256Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r128) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h128 hbit hov - exact ⟨_, _, by simpa [r256, getSqrtRatioAfterBit256BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit256Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r128) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h128 hbit hov - exact ⟨_, _, by simpa [r256, getSqrtRatioAfterBit256BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h256⟩ := h256 - let r512 := getSqrtRatioAfterBit512BranchWord absTick r256 - have h512 : ∃ k' C', RD code ee g s0 ⟨12062⟩ - (r512 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit512Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit512Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r256) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h256 hbit hov - exact ⟨_, _, by simpa [r512, getSqrtRatioAfterBit512BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit512Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r256) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h256 hbit hov - exact ⟨_, _, by simpa [r512, getSqrtRatioAfterBit512BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h512⟩ := h512 - let r1024 := getSqrtRatioAfterBit1024BranchWord absTick r512 - have h1024 : ∃ k' C', RD code ee g s0 ⟨12094⟩ - (r1024 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit1024Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit1024Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r512) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h512 hbit hov - exact ⟨_, _, by simpa [r1024, getSqrtRatioAfterBit1024BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit1024Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r512) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h512 hbit hov - exact ⟨_, _, by simpa [r1024, getSqrtRatioAfterBit1024BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h1024⟩ := h1024 - exact ⟨_, _, by - simpa [getSqrtRatioAfterLowBitsWord, r4, r8, r16, r32, r64, r128, r256, r512, - r1024] using h1024⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickAllBits {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11760⟩ (ratio :: ⟨0⟩ :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12379⟩ - (getSqrtRatioAfterAllBitsWord absTick ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - let r2 := getSqrtRatioAfterBit2BranchWord absTick ratio - have h2 : ∃ k' C', RD code ee g s0 ⟨11812⟩ - (r2 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit2Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit2Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h hbit hov - exact ⟨_, _, by simpa [r2, getSqrtRatioAfterBit2BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit2Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h hbit hov - exact ⟨_, _, by simpa [r2, getSqrtRatioAfterBit2BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h2⟩ := h2 - obtain ⟨_, _, hlow⟩ := - uniswapV3PoolGetSqrtRatioAtTickLowBits (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r2) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h2 hov - obtain ⟨_, _, hhigh⟩ := - uniswapV3PoolGetSqrtRatioAtTickHighBits (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := getSqrtRatioAfterLowBitsWord absTick r2) - (absTick := absTick) (tick := tick) (ret := ret) (R := R) (mem := mem) - (aw := aw) (rdata := rdata) (acc := acc) hpatch hlow hov - exact ⟨_, _, by - simpa [getSqrtRatioAfterAllBitsWord, r2] using hhigh⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioReturnAfterHiSqrt {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {sqrtRatio ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14758⟩ - (sqrtRatio :: initializeArgWord ee :: getTickHiWord ee :: getTickLowWord ee :: - getTickLogSqrt10001Word ee :: getTickLog2After50Word ee :: getTickMsbWord ee :: - getTickLogRShifted50Word ee :: getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: - ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 18 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨10793⟩ - (getTickAfterHiSqrtRatioWord ee sqrtRatio :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 13989 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetTickAtSqrtRatio hlo hhi)] - have hd14758 : decode code ⟨14758⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14759 : decode code ⟨14759⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14761 : decode code ⟨14761⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14763 : decode code ⟨14763⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14765 : decode code ⟨14765⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14766 : decode code ⟨14766⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14767 : decode code ⟨14767⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14768 : decode code ⟨14768⟩ = some (.GT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14769 : decode code ⟨14769⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14770 : decode code ⟨14770⟩ = some (.Push .PUSH2, some (⟨14779⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14773 : decode code ⟨14773⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14774 : decode code ⟨14774⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14775 : decode code ⟨14775⟩ = some (.Push .PUSH2, some (⟨14781⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14778 : decode code ⟨14778⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14779 : decode code ⟨14779⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14780 : decode code ⟨14780⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14781 : decode code ⟨14781⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14782 : decode code ⟨14782⟩ = some (.Push .PUSH2, some (⟨14788⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd14785 : decode code ⟨14785⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd14759 := by - simpa using h.jumpdest hd14758 (by - simp only [List.length_cons] - omega) - have rd14761 := by - simpa using rd14759.push1 ⟨1⟩ hd14759 (by - simp only [List.length_cons] - omega) - have rd14763 := by - simpa using rd14761.push1 ⟨1⟩ hd14761 (by - simp only [List.length_cons] - omega) - have rd14765 := by - simpa using rd14763.push1 ⟨160⟩ hd14763 (by - simp only [List.length_cons] - omega) - have rd14766 := by - simpa using rd14765.shl hd14765 (by - simp only [List.length_cons] - omega) - have rd14767 := by - simpa [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask by native_decide] using rd14766.sub hd14766 (by - simp only [List.length_cons] - omega) - have rd14768 := by - simpa [getTickHiSqrtRatioCleanWord] using rd14767.and hd14767 (by - simp only [List.length_cons] - omega) - have rd14769 := by - simpa [getTickHiSqrtRatioGtInputWord] using rd14768.gt hd14768 (by - simp only [List.length_cons] - omega) - have rd14770 := by - simpa using rd14769.iszero hd14769 (by - simp only [List.length_cons] - omega) - have rd14773 := by - simpa using rd14770.push2 ⟨14779⟩ hd14770 (by - simp only [List.length_cons] - omega) - by_cases hgt : getTickHiSqrtRatioGtInputWord ee sqrtRatio = ⟨0⟩ - · have hcond : UInt256.isZero (getTickHiSqrtRatioGtInputWord ee sqrtRatio) ≠ ⟨0⟩ := by - rw [hgt] - native_decide - have rd14779 := rd14773.jumpiT hd14773 hcond - (uniswapV3PoolJumpDestPatched14779 hpatch) (by - simp only [List.length_cons] - omega) - have rd14780 := by - simpa using rd14779.jumpdest hd14779 (by - simp only [List.length_cons] - omega) - have rd14781 := by - simpa using rd14780.dup1 hd14780 (by - simp only [List.length_cons] - omega) - have rd14782 := by - simpa using rd14781.jumpdest hd14781 (by - simp only [List.length_cons] - omega) - have rd14785 := by - simpa using rd14782.push2 ⟨14788⟩ hd14782 (by - simp only [List.length_cons] - omega) - have rd14788 := rd14785.jump hd14785 (uniswapV3PoolJumpDestPatched14788 hpatch) (by - simp only [List.length_cons] - omega) - obtain ⟨_, _, hdone⟩ := - uniswapV3PoolGetTickAtSqrtRatioReturnCleanup (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (tick := getTickHiWord ee) - (a := getTickHiWord ee) (b := getTickLowWord ee) - (c := getTickLogSqrt10001Word ee) (d := getTickLog2After50Word ee) - (e := getTickMsbWord ee) (f := getTickLogRShifted50Word ee) - (gg := getTickRatioWord ee) (ret := ret) (R := R) (rdata := rdata) - (acc := acc) hpatch rd14788 hov - exact ⟨_, _, by simpa [getTickAfterHiSqrtRatioWord, hgt] using hdone⟩ - · have hcond : UInt256.isZero (getTickHiSqrtRatioGtInputWord ee sqrtRatio) = ⟨0⟩ := - isZero_eq_zero_of_ne hgt - have rd14774 := rd14773.jumpiNT hd14773 hcond (by - simp only [List.length_cons] - omega) - have rd14775 := by - simpa using rd14774.dup2 hd14774 (by - simp only [List.length_cons] - omega) - have rd14778 := by - simpa using rd14775.push2 ⟨14781⟩ hd14775 (by - simp only [List.length_cons] - omega) - have rd14781 := rd14778.jump hd14778 (uniswapV3PoolJumpDestPatched14781 hpatch) (by - simp only [List.length_cons] - omega) - have rd14782 := by - simpa using rd14781.jumpdest hd14781 (by - simp only [List.length_cons] - omega) - have rd14785 := by - simpa using rd14782.push2 ⟨14788⟩ hd14782 (by - simp only [List.length_cons] - omega) - have rd14788 := rd14785.jump hd14785 (uniswapV3PoolJumpDestPatched14788 hpatch) (by - simp only [List.length_cons] - omega) - obtain ⟨_, _, hdone⟩ := - uniswapV3PoolGetTickAtSqrtRatioReturnCleanup (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (tick := getTickLowWord ee) - (a := getTickHiWord ee) (b := getTickLowWord ee) - (c := getTickLogSqrt10001Word ee) (d := getTickLog2After50Word ee) - (e := getTickMsbWord ee) (f := getTickLogRShifted50Word ee) - (gg := getTickRatioWord ee) (ret := ret) (R := R) (rdata := rdata) - (acc := acc) hpatch rd14788 hov - exact ⟨_, _, by simpa [getTickAfterHiSqrtRatioWord, hgt] using hdone⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickReturn {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11629⟩ (tick :: ret :: R) mem aw rdata acc k C) - (hok : getSqrtRatioAbsTickInRangeWord (getSqrtRatioAbsTickBranchWord tick) ≠ ⟨0⟩) - (hratio : - getSqrtRatioAfterAllBitsWord (getSqrtRatioAbsTickBranchWord tick) - (getSqrtRatioInitialBranchWord (getSqrtRatioAbsTickBranchWord tick)) ≠ ⟨0⟩) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 9 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret (getSqrtRatioAtTickResultWord tick :: R) - mem aw rdata acc k' C' := by - by_cases hneg : getSqrtRatioTickNegWord tick = ⟨0⟩ - · obtain ⟨_, _, habs⟩ := - uniswapV3PoolGetSqrtRatioAtTickAbsTickNonNeg (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (tick := tick) (ret := ret) (R := R) - (mem := mem) (aw := aw) (rdata := rdata) (acc := acc) hpatch h hneg - (by omega) - let absTick := getSqrtRatioTickInt24Word tick - obtain ⟨_, _, hrange⟩ := - uniswapV3PoolGetSqrtRatioAtTickRangeOk (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (absTick := absTick) (tick := tick) - (ret := ret) (R := R) (mem := mem) (aw := aw) (rdata := rdata) - (acc := acc) hpatch (by simpa [absTick] using habs) (by - simpa [absTick, getSqrtRatioAbsTickBranchWord, hneg] using hok) (by omega) - by_cases hbit : getSqrtRatioBit1Word absTick = ⟨0⟩ - · obtain ⟨_, _, hinit⟩ := - uniswapV3PoolGetSqrtRatioAtTickRatioInitEven (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (absTick := absTick) (tick := tick) - (ret := ret) (R := R) (mem := mem) (aw := aw) (rdata := rdata) - (acc := acc) hpatch hrange hbit (by omega) - let ratio := getSqrtRatioInitialEvenWord - obtain ⟨_, _, hall⟩ := - uniswapV3PoolGetSqrtRatioAtTickAllBits (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch (by simpa [ratio] using hinit) (by omega) - have hratio' : getSqrtRatioAfterAllBitsWord absTick ratio ≠ ⟨0⟩ := by - simpa [absTick, ratio, getSqrtRatioAbsTickBranchWord, - getSqrtRatioInitialBranchWord, hneg, hbit] using hratio - obtain ⟨_, _, hdone⟩ := - uniswapV3PoolGetSqrtRatioAtTickReturnTail (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) - (ratio := getSqrtRatioAfterAllBitsWord absTick ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch hall hratio' hret hov - exact ⟨_, _, by - simpa [getSqrtRatioAtTickResultWord, getSqrtRatioAbsTickBranchWord, - getSqrtRatioInitialBranchWord, absTick, ratio, hneg, hbit] using hdone⟩ - · obtain ⟨_, _, hinit⟩ := - uniswapV3PoolGetSqrtRatioAtTickRatioInitOdd (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (absTick := absTick) (tick := tick) - (ret := ret) (R := R) (mem := mem) (aw := aw) (rdata := rdata) - (acc := acc) hpatch hrange hbit (by omega) - let ratio := getSqrtRatioInitialOddWord - obtain ⟨_, _, hall⟩ := - uniswapV3PoolGetSqrtRatioAtTickAllBits (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch (by simpa [ratio] using hinit) (by omega) - have hratio' : getSqrtRatioAfterAllBitsWord absTick ratio ≠ ⟨0⟩ := by - simpa [absTick, ratio, getSqrtRatioAbsTickBranchWord, - getSqrtRatioInitialBranchWord, hneg, hbit] using hratio - obtain ⟨_, _, hdone⟩ := - uniswapV3PoolGetSqrtRatioAtTickReturnTail (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) - (ratio := getSqrtRatioAfterAllBitsWord absTick ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch hall hratio' hret hov - exact ⟨_, _, by - simpa [getSqrtRatioAtTickResultWord, getSqrtRatioAbsTickBranchWord, - getSqrtRatioInitialBranchWord, absTick, ratio, hneg, hbit] using hdone⟩ - · obtain ⟨_, _, habs⟩ := - uniswapV3PoolGetSqrtRatioAtTickAbsTickNeg (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (tick := tick) (ret := ret) (R := R) - (mem := mem) (aw := aw) (rdata := rdata) (acc := acc) hpatch h hneg - (by omega) - let absTick := getSqrtRatioAbsTickNegWord tick - obtain ⟨_, _, hrange⟩ := - uniswapV3PoolGetSqrtRatioAtTickRangeOk (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (absTick := absTick) (tick := tick) - (ret := ret) (R := R) (mem := mem) (aw := aw) (rdata := rdata) - (acc := acc) hpatch (by simpa [absTick] using habs) (by - simpa [absTick, getSqrtRatioAbsTickBranchWord, hneg] using hok) (by omega) - by_cases hbit : getSqrtRatioBit1Word absTick = ⟨0⟩ - · obtain ⟨_, _, hinit⟩ := - uniswapV3PoolGetSqrtRatioAtTickRatioInitEven (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (absTick := absTick) (tick := tick) - (ret := ret) (R := R) (mem := mem) (aw := aw) (rdata := rdata) - (acc := acc) hpatch hrange hbit (by omega) - let ratio := getSqrtRatioInitialEvenWord - obtain ⟨_, _, hall⟩ := - uniswapV3PoolGetSqrtRatioAtTickAllBits (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch (by simpa [ratio] using hinit) (by omega) - have hratio' : getSqrtRatioAfterAllBitsWord absTick ratio ≠ ⟨0⟩ := by - simpa [absTick, ratio, getSqrtRatioAbsTickBranchWord, - getSqrtRatioInitialBranchWord, hneg, hbit] using hratio - obtain ⟨_, _, hdone⟩ := - uniswapV3PoolGetSqrtRatioAtTickReturnTail (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) - (ratio := getSqrtRatioAfterAllBitsWord absTick ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch hall hratio' hret hov - exact ⟨_, _, by - simpa [getSqrtRatioAtTickResultWord, getSqrtRatioAbsTickBranchWord, - getSqrtRatioInitialBranchWord, absTick, ratio, hneg, hbit] using hdone⟩ - · obtain ⟨_, _, hinit⟩ := - uniswapV3PoolGetSqrtRatioAtTickRatioInitOdd (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (absTick := absTick) (tick := tick) - (ret := ret) (R := R) (mem := mem) (aw := aw) (rdata := rdata) - (acc := acc) hpatch hrange hbit (by omega) - let ratio := getSqrtRatioInitialOddWord - obtain ⟨_, _, hall⟩ := - uniswapV3PoolGetSqrtRatioAtTickAllBits (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch (by simpa [ratio] using hinit) (by omega) - have hratio' : getSqrtRatioAfterAllBitsWord absTick ratio ≠ ⟨0⟩ := by - simpa [absTick, ratio, getSqrtRatioAbsTickBranchWord, - getSqrtRatioInitialBranchWord, hneg, hbit] using hratio - obtain ⟨_, _, hdone⟩ := - uniswapV3PoolGetSqrtRatioAtTickReturnTail (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) - (ratio := getSqrtRatioAfterAllBitsWord absTick ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch hall hratio' hret hov - exact ⟨_, _, by - simpa [getSqrtRatioAtTickResultWord, getSqrtRatioAbsTickBranchWord, - getSqrtRatioInitialBranchWord, absTick, ratio, hneg, hbit] using hdone⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetTickAtSqrtRatioReturnTickEstimate {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ret : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨14739⟩ - (⟨14786⟩ :: getTickLowEqHiWord ee :: getTickHiWord ee :: getTickLowWord ee :: - getTickLogSqrt10001Word ee :: getTickLog2After50Word ee :: getTickMsbWord ee :: - getTickLogRShifted50Word ee :: getTickRatioWord ee :: ⟨0⟩ :: initializeArgWord ee :: - ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hok : - getSqrtRatioAbsTickInRangeWord (getSqrtRatioAbsTickBranchWord (getTickHiWord ee)) ≠ - ⟨0⟩) - (hratio : - getSqrtRatioAfterAllBitsWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord ee)) - (getSqrtRatioInitialBranchWord (getSqrtRatioAbsTickBranchWord (getTickHiWord ee))) ≠ - ⟨0⟩) - (hov : R.length + 23 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨10793⟩ - (getTickEstimatedWord ee :: ⟨0⟩ :: initializeArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k' C' := by - by_cases heq : getTickLowEqHiWord ee = ⟨0⟩ - · obtain ⟨_, _, hsqrtEntry⟩ := - uniswapV3PoolGetTickAtSqrtRatioSqrtRatioCallSetup (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (R := R) (rdata := rdata) - (acc := acc) hpatch h heq (by omega) - let tail := - initializeArgWord ee :: getTickHiWord ee :: getTickLowWord ee :: - getTickLogSqrt10001Word ee :: getTickLog2After50Word ee :: getTickMsbWord ee :: - getTickLogRShifted50Word ee :: getTickRatioWord ee :: ⟨0⟩ :: - initializeArgWord ee :: ⟨10793⟩ :: ⟨0⟩ :: initializeArgWord ee :: ret :: R - obtain ⟨_, _, hsqrtDone⟩ := - uniswapV3PoolGetSqrtRatioAtTickReturn (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (tick := getTickHiWord ee) (ret := ⟨14758⟩) - (R := tail) (mem := solcFreePtrMem) (aw := UInt256.ofNat 3) (rdata := rdata) - (acc := acc) hpatch (by simpa [tail] using hsqrtEntry) hok hratio - (uniswapV3PoolJumpDestPatched14758 hpatch) (by - simp only [tail, List.length_cons] - omega) - obtain ⟨_, _, hdone⟩ := - uniswapV3PoolGetTickAtSqrtRatioReturnAfterHiSqrt (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (sqrtRatio := getTickHiSqrtRatioWord ee) - (ret := ret) (R := R) (rdata := rdata) (acc := acc) hpatch - (by simpa [tail, getTickHiSqrtRatioWord] using hsqrtDone) (by omega) - exact ⟨_, _, by simpa [getTickEstimatedWord, getTickHiSqrtRatioWord, heq] using hdone⟩ - · obtain ⟨_, _, hdone⟩ := - uniswapV3PoolGetTickAtSqrtRatioReturnTickLowEq (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ret := ret) (R := R) (rdata := rdata) - (acc := acc) hpatch h heq (by omega) - exact ⟨_, _, by simpa [getTickEstimatedWord, heq] using hdone⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioNonzero.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioNonzero.lean deleted file mode 100644 index c41ab61a..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioNonzero.lean +++ /dev/null @@ -1,1767 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTickLog2Bridge -import Benchmarks.UniswapV3Pool.InitializeSourceGetSqrtRatioHighBits -import Benchmarks.UniswapV3Pool.InitializeSourceStorageEquiv -import Benchmarks.UniswapV3Pool.TickSpacing - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem u256_mul_shiftRight128_toNat_of_factor_lt_q128 - (factor ratio : UInt256) - (hfactor : factor.toNat < 2 ^ (128 : Nat)) - (hratio : ratio.toNat ≤ 2 ^ (128 : Nat)) : - (UInt256.shiftRight (UInt256.mul factor ratio) ⟨128⟩).toNat = - factor.toNat * ratio.toNat / 2 ^ (128 : Nat) := by - unfold UInt256.shiftRight UInt256.mul - simp only [UInt256.toNat] - rw [if_neg] - · rw [Fin.shiftRight_val] - rw [Fin.val_mul] - rw [Nat.mod_eq_of_lt] - · rw [Nat.shiftRight_eq_div_pow] - norm_num [UInt256.size] - · have hmul : - factor.val.val * ratio.val.val < 2 ^ (128 : Nat) * 2 ^ (128 : Nat) := by - exact Nat.mul_lt_mul_of_lt_of_le hfactor hratio (Nat.zero_lt_of_lt hfactor) - have hpow : 2 ^ (128 : Nat) * 2 ^ (128 : Nat) = UInt256.size := by - norm_num [UInt256.size] - omega - · decide - -private theorem sqrtRatioStepWord_lb - (factor ratio : UInt256) (factorNat lbIn lbOut : Nat) - (hfactorNat : factor.toNat = factorNat) - (hfactorLt : factorNat < 2 ^ (128 : Nat)) - (hratioLo : lbIn ≤ ratio.toNat) - (hratioHi : ratio.toNat ≤ 2 ^ (128 : Nat)) - (hlb : lbOut ≤ factorNat * lbIn / 2 ^ (128 : Nat)) : - lbOut ≤ (UInt256.shiftRight (UInt256.mul factor ratio) ⟨128⟩).toNat := by - rw [u256_mul_shiftRight128_toNat_of_factor_lt_q128] - · rw [hfactorNat] - exact le_trans hlb (Nat.div_le_div_right (Nat.mul_le_mul_left factorNat hratioLo)) - · rw [hfactorNat] - exact hfactorLt - · exact hratioHi - -private theorem sqrtRatioStepWord_le_q128 - (factor ratio : UInt256) (factorNat : Nat) - (hfactorNat : factor.toNat = factorNat) - (hfactorLt : factorNat < 2 ^ (128 : Nat)) - (hratioHi : ratio.toNat ≤ 2 ^ (128 : Nat)) : - (UInt256.shiftRight (UInt256.mul factor ratio) ⟨128⟩).toNat ≤ 2 ^ (128 : Nat) := by - rw [u256_mul_shiftRight128_toNat_of_factor_lt_q128] - · rw [hfactorNat] - apply Nat.div_le_of_le_mul - exact Nat.mul_le_mul (Nat.le_of_lt hfactorLt) hratioHi - · rw [hfactorNat] - exact hfactorLt - · exact hratioHi - -private theorem getSqrtRatioInitialMaskedBranchWord_lb (absTick : UInt256) : - 340265354078544963557816517032075149313 ≤ - (getSqrtRatioRatioMaskedWord (getSqrtRatioInitialBranchWord absTick)).toNat := by - unfold getSqrtRatioRatioMaskedWord getSqrtRatioInitialBranchWord - by_cases h : getSqrtRatioBit1Word absTick = ⟨0⟩ - · simp [h, getSqrtRatioInitialEvenWord, getSqrtRatioUint136Mask] - native_decide - · simp [h, getSqrtRatioInitialOddWord, getSqrtRatioUint136Mask] - native_decide - -private theorem getSqrtRatioInitialMaskedBranchWord_le_q128 (absTick : UInt256) : - (getSqrtRatioRatioMaskedWord (getSqrtRatioInitialBranchWord absTick)).toNat ≤ - 2 ^ (128 : Nat) := by - unfold getSqrtRatioRatioMaskedWord getSqrtRatioInitialBranchWord - by_cases h : getSqrtRatioBit1Word absTick = ⟨0⟩ - · simp [h, getSqrtRatioInitialEvenWord, getSqrtRatioUint136Mask] - native_decide - · simp [h, getSqrtRatioInitialOddWord, getSqrtRatioUint136Mask] - native_decide - -private theorem sourceSqrtRatioStepInt_lb - (absTick ratio mask constant : Int) (constantNat lbIn lbOut : Nat) - (hconstantNat : constant.toNat = constantNat) - (hconstant0 : 0 ≤ constant) - (hratioLo : (lbIn : Int) ≤ ratio) - (hlbKeep : lbOut ≤ lbIn) - (hlbMul : lbOut ≤ constantNat * lbIn / 2 ^ (128 : Nat)) : - (lbOut : Int) ≤ - getSqrtRatioSourceTickRatioStepRatioInt absTick ratio mask constant := by - unfold getSqrtRatioSourceTickRatioStepRatioInt - by_cases h : getSqrtRatioSourceTickRatioStepBitInt absTick mask = 0 - · rw [if_pos h] - exact le_trans (by exact_mod_cast hlbKeep) hratioLo - · rw [if_neg h] - have hratio0 : 0 ≤ ratio := le_trans (by norm_num : (0 : Int) ≤ lbIn) hratioLo - have hratioNat : lbIn ≤ ratio.toNat := by - have htmp := Int.toNat_le_toNat hratioLo - simpa using htmp - have hprod : (ratio * constant).toNat = ratio.toNat * constantNat := by - rw [Int.toNat_mul hratio0 hconstant0, hconstantNat] - have hNat : lbOut ≤ (ratio * constant).toNat / 2 ^ (128 : Nat) := by - rw [hprod, Nat.mul_comm] - exact le_trans hlbMul - (Nat.div_le_div_right (Nat.mul_le_mul_left constantNat hratioNat)) - exact_mod_cast hNat - -private theorem getTickSourceRatioNat_ge_min_shift (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) : - 4295128739 * 2 ^ (32 : Nat) ≤ getTickSourceRatioNat I := by - unfold getTickSourceRatioNat - rw [Nat.mod_eq_of_lt] - · exact Nat.mul_le_mul_right _ hlo - · have harg := initializeArgWord_toNat_lt_twoPow160 I - have hmul := Nat.mul_lt_mul_of_pos_right harg (by norm_num : 0 < 2 ^ (32 : Nat)) - rw [← Nat.pow_add] at hmul - norm_num at hmul ⊢ - exact lt_trans hmul (by norm_num [EVM.wordModulus, EVM.twoPow]) - -private theorem getTickSourceRatioNat_lt_max_shift (I : ExecutionEnv) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - getTickSourceRatioNat I < - 1461446703485210103287273052203988822378723970342 * 2 ^ (32 : Nat) := by - unfold getTickSourceRatioNat - rw [Nat.mod_eq_of_lt] - · exact Nat.mul_lt_mul_of_pos_right hhi (by norm_num : 0 < 2 ^ (32 : Nat)) - · have harg := initializeArgWord_toNat_lt_twoPow160 I - have hmul := Nat.mul_lt_mul_of_pos_right harg (by norm_num : 0 < 2 ^ (32 : Nat)) - rw [← Nat.pow_add] at hmul - norm_num at hmul ⊢ - exact lt_trans hmul (by norm_num [EVM.wordModulus, EVM.twoPow]) - -private theorem getTickSourceMsbAfter0Nat_le_191 (I : ExecutionEnv) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - getTickSourceMsbAfter0Nat I ≤ 191 := by - have hratioMax := getTickSourceRatioNat_lt_max_shift I hhi - have hratioLt192 : getTickSourceRatioNat I < 2 ^ (192 : Nat) := by - exact lt_trans hratioMax (by native_decide) - unfold getTickSourceMsbAfter0Nat getTickSourceMsbAfter1Nat getTickSourceMsbAfter2Nat - getTickSourceMsbAfter3Nat getTickSourceMsbAfter4Nat getTickSourceMsbAfter5Nat - getTickSourceMsbAfter6Nat - by_cases h7 : getTickSourceRatioGt7 I - · have hf7 : getTickSourceMsbF7Nat I = 128 := by simp [getTickSourceMsbF7Nat, h7] - have hr7lt : getTickSourceRAfterMsb7Nat I < 2 ^ (64 : Nat) := by - unfold getTickSourceRAfterMsb7Nat - rw [hf7] - rw [Nat.div_lt_iff_lt_mul (by norm_num : 0 < 2 ^ (128 : Nat))] - rw [← Nat.pow_add] - norm_num - exact hratioLt192 - have hf6 : getTickSourceMsbF6Nat I = 0 := by - unfold getTickSourceMsbF6Nat getTickSourceRAfterMsb7Gt6 - rw [show decide (getTickSourceRAfterMsb7Nat I > 0xFFFFFFFFFFFFFFFF) = false by - apply decide_eq_false - norm_num at hr7lt ⊢ - omega] - simp - have h5 := getTickSourceMsbF5Nat_le_32 I - have h4 := getTickSourceMsbF4Nat_le_16 I - have h3 := getTickSourceMsbF3Nat_le_8 I - have h2 := getTickSourceMsbF2Nat_le_4 I - have h1 := getTickSourceMsbF1Nat_le_2 I - have h0 := getTickSourceMsbF0Nat_le_1 I - omega - · have hf7 : getTickSourceMsbF7Nat I = 0 := by simp [getTickSourceMsbF7Nat, h7] - have h6 := getTickSourceMsbF6Nat_le_64 I - have h5 := getTickSourceMsbF5Nat_le_32 I - have h4 := getTickSourceMsbF4Nat_le_16 I - have h3 := getTickSourceMsbF3Nat_le_8 I - have h2 := getTickSourceMsbF2Nat_le_4 I - have h1 := getTickSourceMsbF1Nat_le_2 I - have h0 := getTickSourceMsbF0Nat_le_1 I - omega - -private theorem getTickSourceMsbAfter0Nat_ge_64 (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) : - 64 ≤ getTickSourceMsbAfter0Nat I := by - have hratioMin := getTickSourceRatioNat_ge_min_shift I hlo - have hratioGt64 : 2 ^ (64 : Nat) - 1 < getTickSourceRatioNat I := by - exact lt_of_lt_of_le (by native_decide) hratioMin - unfold getTickSourceMsbAfter0Nat getTickSourceMsbAfter1Nat getTickSourceMsbAfter2Nat - getTickSourceMsbAfter3Nat getTickSourceMsbAfter4Nat getTickSourceMsbAfter5Nat - getTickSourceMsbAfter6Nat - by_cases h7 : getTickSourceRatioGt7 I - · have hf7 : getTickSourceMsbF7Nat I = 128 := by simp [getTickSourceMsbF7Nat, h7] - omega - · have hf7 : getTickSourceMsbF7Nat I = 0 := by simp [getTickSourceMsbF7Nat, h7] - have hr7 : getTickSourceRAfterMsb7Nat I = getTickSourceRatioNat I := by - unfold getTickSourceRAfterMsb7Nat - rw [hf7] - simp - have hf6 : getTickSourceMsbF6Nat I = 64 := by - unfold getTickSourceMsbF6Nat getTickSourceRAfterMsb7Gt6 - rw [hr7] - rw [show decide (getTickSourceRatioNat I > 0xFFFFFFFFFFFFFFFF) = true by - apply decide_eq_true - norm_num at hratioGt64 ⊢ - omega] - simp - omega - -private theorem getTickSourceLog2After50Int_lower (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) : - -((64 : Int) * 2 ^ (64 : Nat)) ≤ getTickSourceLog2After50Int I := by - have hmsb := getTickSourceMsbAfter0Nat_ge_64 I hlo - have hf63 : 0 ≤ (getTickSourceLogF63Nat I : Int) * (2 ^ (63 : Nat) : Int) := by - positivity - unfold getTickSourceLog2After50Int getTickSourceLog2AfterStep - getTickSourceLog2After51Int getTickSourceLog2After52Int getTickSourceLog2After53Int - getTickSourceLog2After54Int getTickSourceLog2After55Int getTickSourceLog2After56Int - getTickSourceLog2After57Int getTickSourceLog2After58Int getTickSourceLog2After59Int - getTickSourceLog2After60Int getTickSourceLog2After61Int getTickSourceLog2After62Int - getTickSourceLog2After63Int getTickSourceLog2BaseInt getTickSourceLogStepLog2AfterInt - unfold getTickSourceLog2AfterStep getTickSourceLogStepLog2AfterInt - omega - -private theorem getTickSourceLog2After50Int_upper (I : ExecutionEnv) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - getTickSourceLog2After50Int I ≤ (64 : Int) * 2 ^ (64 : Nat) - 2 ^ (50 : Nat) := by - have hmsb := getTickSourceMsbAfter0Nat_le_191 I hhi - have hf63 := getTickSourceLogF63Nat_le_1 I - have hf62 := getTickSourceLogF62Nat_le_1 I - have hf61 := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter62Nat I) - (getTickSourceLogRAfter62Nat_mul_self_lt_wordModulus I) - have hf60 := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter61Nat I) - (getTickSourceLogRAfter61Nat_mul_self_lt_wordModulus I) - have hf59 := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter60Nat I) - (getTickSourceLogRAfter60Nat_mul_self_lt_wordModulus I) - have hf58 := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter59Nat I) - (getTickSourceLogRAfter59Nat_mul_self_lt_wordModulus I) - have hf57 := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter58Nat I) - (getTickSourceLogRAfter58Nat_mul_self_lt_wordModulus I) - have hf56 := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter57Nat I) - (getTickSourceLogRAfter57Nat_mul_self_lt_wordModulus I) - have hf55 := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter56Nat I) - (getTickSourceLogRAfter56Nat_mul_self_lt_wordModulus I) - have hf54 := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter55Nat I) - (getTickSourceLogRAfter55Nat_mul_self_lt_wordModulus I) - have hf53 := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter54Nat I) - (getTickSourceLogRAfter54Nat_mul_self_lt_wordModulus I) - have hf52 := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter53Nat I) - (getTickSourceLogRAfter53Nat_mul_self_lt_wordModulus I) - have hf51 := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter52Nat I) - (getTickSourceLogRAfter52Nat_mul_self_lt_wordModulus I) - have hf50 := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter51Nat I) - (getTickSourceLogRAfter51Nat_mul_self_lt_wordModulus I) - unfold getTickSourceLog2After50Int getTickSourceLog2AfterStep - getTickSourceLog2After51Int getTickSourceLog2After52Int getTickSourceLog2After53Int - getTickSourceLog2After54Int getTickSourceLog2After55Int getTickSourceLog2After56Int - getTickSourceLog2After57Int getTickSourceLog2After58Int getTickSourceLog2After59Int - getTickSourceLog2After60Int getTickSourceLog2After61Int getTickSourceLog2After62Int - getTickSourceLog2After63Int getTickSourceLog2BaseInt getTickSourceLogStepLog2AfterInt - unfold getTickSourceLog2AfterStep getTickSourceLogStepLog2AfterInt at * - norm_num at * - omega - -theorem getSqrtRatioSourceTickHiAbsTickInt_le_maxTick (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272 := by - have hlo2 := getTickSourceLog2After50Int_lower I hlo - have hhi2 := getTickSourceLog2After50Int_upper I hhi - unfold getSqrtRatioSourceTickHiAbsTickInt getTickSourceTickHiInt - unfold getTickSourceLogSqrt10001Int getTickSourceTickHiOffsetInt - getTickSourceFixedPoint128Int getTickSourceLogSqrt10001MultiplierInt - omega - -theorem getTickSourceTickHiInt_int24_bounds (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - -(2 ^ 23 : Int) ≤ getTickSourceTickHiInt I ∧ getTickSourceTickHiInt I < 2 ^ 23 := by - have habs := getSqrtRatioSourceTickHiAbsTickInt_le_maxTick I hlo hhi - unfold getSqrtRatioSourceTickHiAbsTickInt at habs - by_cases hneg : getTickSourceTickHiInt I < 0 - · rw [if_pos hneg] at habs - constructor <;> omega - · rw [if_neg hneg] at habs - constructor <;> omega - -theorem getTickSourceTickLowInt_int24_bounds (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - -(2 ^ 23 : Int) ≤ getTickSourceTickLowInt I ∧ getTickSourceTickLowInt I < 2 ^ 23 := by - have hlo2 := getTickSourceLog2After50Int_lower I hlo - have hhi2 := getTickSourceLog2After50Int_upper I hhi - unfold getTickSourceTickLowInt getTickSourceLogSqrt10001Int - unfold getTickSourceTickLowOffsetInt getTickSourceFixedPoint128Int - getTickSourceLogSqrt10001MultiplierInt - omega - -theorem getTickSourceTickHiNumerator_int256_bounds (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - -(2 ^ 255 : Int) ≤ getTickSourceLogSqrt10001Int I + getTickSourceTickHiOffsetInt ∧ - getTickSourceLogSqrt10001Int I + getTickSourceTickHiOffsetInt < 2 ^ 255 := by - have hlo2 := getTickSourceLog2After50Int_lower I hlo - have hhi2 := getTickSourceLog2After50Int_upper I hhi - unfold getTickSourceLogSqrt10001Int getTickSourceLogSqrt10001MultiplierInt - getTickSourceTickHiOffsetInt - omega - -theorem getTickSourceTickLowNumerator_int256_bounds (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - -(2 ^ 255 : Int) ≤ getTickSourceLogSqrt10001Int I - getTickSourceTickLowOffsetInt ∧ - getTickSourceLogSqrt10001Int I - getTickSourceTickLowOffsetInt < 2 ^ 255 := by - have hlo2 := getTickSourceLog2After50Int_lower I hlo - have hhi2 := getTickSourceLog2After50Int_upper I hhi - unfold getTickSourceLogSqrt10001Int getTickSourceLogSqrt10001MultiplierInt - getTickSourceTickLowOffsetInt - omega - -private theorem getTickSourceLogSqrt10001Int_int256_bounds (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - -(2 ^ 255 : Int) ≤ getTickSourceLogSqrt10001Int I ∧ - getTickSourceLogSqrt10001Int I < 2 ^ 255 := by - have hlo2 := getTickSourceLog2After50Int_lower I hlo - have hhi2 := getTickSourceLog2After50Int_upper I hhi - unfold getTickSourceLogSqrt10001Int getTickSourceLogSqrt10001MultiplierInt - constructor <;> omega - -private theorem nat_sub_mul_mod_eq_sub_mul {S n c : Nat} - (hprod : n * c < S) (hprodPos : 0 < n * c) (hc : 0 < c) : - ((S - n) * c) % S = S - n * c := by - have hprodLe : n * c ≤ S := le_of_lt hprod - have hcSucc : c = (c - 1) + 1 := by omega - rw [Nat.sub_mul] - have hdecomp : S * c - n * c = (S - n * c) + S * (c - 1) := by - calc - S * c - n * c = S * ((c - 1) + 1) - n * c := by rw [← hcSucc] - _ = (S * (c - 1) + S * 1) - n * c := by rw [Nat.mul_add] - _ = (S * (c - 1) + S) - n * c := by rw [Nat.mul_one] - _ = S + S * (c - 1) - n * c := by rw [Nat.add_comm] - _ = S - n * c + S * (c - 1) := by rw [Nat.sub_add_comm hprodLe] - _ = (S - n * c) + S * (c - 1) := rfl - rw [hdecomp, Nat.add_mul_mod_self_left] - exact Nat.mod_eq_of_lt (Nat.sub_lt (Nat.zero_lt_of_lt hprod) hprodPos) - -private theorem int_natAbs_mul_nat_of_neg {x : Int} {c : Nat} (hx : x < 0) (hc : 0 < c) : - (x * (c : Int)).natAbs = x.natAbs * c := by - apply (Nat.cast_inj (R := Int)).mp - have hxAbs : (x.natAbs : Int) = -x := Int.ofNat_natAbs_of_nonpos (by omega) - have hprodNeg : x * (c : Int) < 0 := by - have hcInt : (0 : Int) < c := by exact_mod_cast hc - exact mul_neg_of_neg_of_pos hx hcInt - have hprodAbs : ((x * (c : Int)).natAbs : Int) = -(x * (c : Int)) := - Int.ofNat_natAbs_of_nonpos (by omega) - rw [hprodAbs, Nat.cast_mul, hxAbs] - norm_num - -private theorem getTickSourceLog2After50Int_natAbs_lt_wordModulus_of_lower (I : ExecutionEnv) - (hlo2 : -((64 : Int) * 2 ^ (64 : Nat)) ≤ getTickSourceLog2After50Int I) - (hneg : getTickSourceLog2After50Int I < 0) : - (getTickSourceLog2After50Int I).natAbs < EVM.wordModulus := by - have habs : ((getTickSourceLog2After50Int I).natAbs : Int) = - -getTickSourceLog2After50Int I := Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [EVM.wordModulus, EVM.twoPow] at hlo2 ⊢ - omega - -private theorem getTickSourceLog2After50Int_mul_const_natAbs_lt_wordModulus_of_lower - (I : ExecutionEnv) - (hlo2 : -((64 : Int) * 2 ^ (64 : Nat)) ≤ getTickSourceLog2After50Int I) - (hneg : getTickSourceLog2After50Int I < 0) : - (getTickSourceLog2After50Int I * (255738958999603826347141 : Int)).natAbs < - EVM.wordModulus := by - change (getTickSourceLog2After50Int I * ((255738958999603826347141 : Nat) : Int)).natAbs < - EVM.wordModulus - rw [int_natAbs_mul_nat_of_neg - (x := getTickSourceLog2After50Int I) (c := 255738958999603826347141) hneg - (by norm_num)] - have habs : ((getTickSourceLog2After50Int I).natAbs : Int) = - -getTickSourceLog2After50Int I := Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [EVM.wordModulus, EVM.twoPow] at hlo2 ⊢ - omega - -private theorem getTickLogSqrt10001Word_eq_source_of_log2_bounds_nonneg (I : ExecutionEnv) - (hlog2 : getTickLog2After50Word I = EVM.wordOfInt (getTickSourceLog2After50Int I)) - (hhi2 : getTickSourceLog2After50Int I ≤ - (64 : Int) * 2 ^ (64 : Nat) - 2 ^ (50 : Nat)) - (hnonneg : 0 ≤ getTickSourceLog2After50Int I) : - getTickLogSqrt10001Word I = EVM.wordOfInt (getTickSourceLogSqrt10001Int I) := by - apply u256_inj - unfold getTickLogSqrt10001Word getTickSourceLogSqrt10001Int - getTickSourceLogSqrt10001MultiplierInt - rw [hlog2] - rw [u256_mul_toNat] - have hconst : getTickLogSqrt10001Multiplier.toNat = 255738958999603826347141 := by - native_decide - rw [hconst] - have hlog2Lt : getTickSourceLog2After50Int I < EVM.wordModulus := by - norm_num [EVM.wordModulus, EVM.twoPow] at hhi2 ⊢ - omega - have hprod0 : 0 ≤ getTickSourceLog2After50Int I * - (255738958999603826347141 : Int) := by - exact mul_nonneg hnonneg (by norm_num) - have hprodLt : - getTickSourceLog2After50Int I * (255738958999603826347141 : Int) < - EVM.wordModulus := by - norm_num [EVM.wordModulus, EVM.twoPow] at hhi2 ⊢ - omega - rw [wordOfInt_nonneg_toNat_lt_wordModulus _ hnonneg hlog2Lt] - rw [wordOfInt_nonneg_toNat_lt_wordModulus _ hprod0 hprodLt] - have hprodNatLt : - (getTickSourceLog2After50Int I).toNat * 255738958999603826347141 < - UInt256.size := by - have hto : ((getTickSourceLog2After50Int I).toNat : Int) = - getTickSourceLog2After50Int I := Int.toNat_of_nonneg hnonneg - norm_num [UInt256.size] at hprodLt ⊢ - omega - rw [Nat.mod_eq_of_lt hprodNatLt] - have hto : ((getTickSourceLog2After50Int I).toNat : Int) = - getTickSourceLog2After50Int I := Int.toNat_of_nonneg hnonneg - omega - -private theorem getTickLogSqrt10001Word_eq_source_of_log2_bounds_neg (I : ExecutionEnv) - (hlog2 : getTickLog2After50Word I = EVM.wordOfInt (getTickSourceLog2After50Int I)) - (hlo2 : -((64 : Int) * 2 ^ (64 : Nat)) ≤ getTickSourceLog2After50Int I) - (hneg : getTickSourceLog2After50Int I < 0) : - getTickLogSqrt10001Word I = EVM.wordOfInt (getTickSourceLogSqrt10001Int I) := by - apply u256_inj - unfold getTickLogSqrt10001Word getTickSourceLogSqrt10001Int - getTickSourceLogSqrt10001MultiplierInt - rw [hlog2] - rw [u256_mul_toNat] - have hconst : getTickLogSqrt10001Multiplier.toNat = 255738958999603826347141 := by - native_decide - rw [hconst] - have hlog2AbsLt : (getTickSourceLog2After50Int I).natAbs < EVM.wordModulus := - getTickSourceLog2After50Int_natAbs_lt_wordModulus_of_lower I hlo2 hneg - have hprodNeg : - getTickSourceLog2After50Int I * (255738958999603826347141 : Int) < 0 := by - exact mul_neg_of_neg_of_pos hneg (by norm_num) - have hprodAbs : - (getTickSourceLog2After50Int I * - (255738958999603826347141 : Int)).natAbs = - (getTickSourceLog2After50Int I).natAbs * 255738958999603826347141 := - int_natAbs_mul_nat_of_neg hneg (by norm_num) - have hprodAbsLt : - (getTickSourceLog2After50Int I * - (255738958999603826347141 : Int)).natAbs < EVM.wordModulus := - getTickSourceLog2After50Int_mul_const_natAbs_lt_wordModulus_of_lower I hlo2 hneg - rw [wordOfInt_neg_toNat_lt_wordModulus _ hneg hlog2AbsLt] - rw [wordOfInt_neg_toNat_lt_wordModulus _ hprodNeg hprodAbsLt] - rw [hprodAbs] - have hprodLtSize : - (getTickSourceLog2After50Int I).natAbs * 255738958999603826347141 < - UInt256.size := by - rw [← hprodAbs] - simpa [EVM.wordModulus, EVM.twoPow, UInt256.size] using hprodAbsLt - have hmod : - (UInt256.size - (getTickSourceLog2After50Int I).natAbs) * - 255738958999603826347141 % UInt256.size = - UInt256.size - - (getTickSourceLog2After50Int I).natAbs * 255738958999603826347141 := by - have hprodPos : - 0 < (getTickSourceLog2After50Int I).natAbs * 255738958999603826347141 := by - exact Nat.mul_pos (Int.natAbs_pos.mpr (ne_of_lt hneg)) (by norm_num) - exact nat_sub_mul_mod_eq_sub_mul hprodLtSize hprodPos (by norm_num) - exact hmod - -private theorem getTickLogSqrt10001Word_eq_source_of_log2_bounds (I : ExecutionEnv) - (hlog2 : getTickLog2After50Word I = EVM.wordOfInt (getTickSourceLog2After50Int I)) - (hlo2 : -((64 : Int) * 2 ^ (64 : Nat)) ≤ getTickSourceLog2After50Int I) - (hhi2 : getTickSourceLog2After50Int I ≤ - (64 : Int) * 2 ^ (64 : Nat) - 2 ^ (50 : Nat)) : - getTickLogSqrt10001Word I = EVM.wordOfInt (getTickSourceLogSqrt10001Int I) := by - by_cases hnonneg : 0 ≤ getTickSourceLog2After50Int I - · exact getTickLogSqrt10001Word_eq_source_of_log2_bounds_nonneg I hlog2 hhi2 hnonneg - · have hneg : getTickSourceLog2After50Int I < 0 := by omega - exact getTickLogSqrt10001Word_eq_source_of_log2_bounds_neg I hlog2 hlo2 hneg - -private theorem getTickLogSqrt10001Word_eq_source_of_bounds (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - getTickLogSqrt10001Word I = EVM.wordOfInt (getTickSourceLogSqrt10001Int I) := by - have hloMsb := getTickSourceMsbAfter0Nat_ge_64 I hlo - have hhiMsb := getTickSourceMsbAfter0Nat_le_191 I hhi - exact getTickLogSqrt10001Word_eq_source_of_log2_bounds I - (getTickLog2After50Word_eq_source_of_msb_bounds I hloMsb hhiMsb) - (getTickSourceLog2After50Int_lower I hlo) - (getTickSourceLog2After50Int_upper I hhi) - -set_option maxRecDepth 2000000 in -set_option maxHeartbeats 1000000 in -private theorem getTickHiBiasedWord_eq_source_of_log (I : ExecutionEnv) - (hlog : getTickLogSqrt10001Word I = EVM.wordOfInt (getTickSourceLogSqrt10001Int I)) - (hlogGe : -(2 ^ 255 : Int) ≤ getTickSourceLogSqrt10001Int I) - (hlogLt : getTickSourceLogSqrt10001Int I < 2 ^ 255) - (hsumGe : - -(2 ^ 255 : Int) ≤ getTickSourceLogSqrt10001Int I + getTickSourceTickHiOffsetInt) - (hsumLt : getTickSourceLogSqrt10001Int I + getTickSourceTickHiOffsetInt < 2 ^ 255) : - getTickHiBiasedWord I = - EVM.wordOfInt (getTickSourceLogSqrt10001Int I + getTickSourceTickHiOffsetInt) := by - apply u256_inj - unfold getTickHiBiasedWord getTickSourceTickHiOffsetInt - rw [hlog, uadd_toNat] - have hoff : getTickHiOffsetWord.toNat = 291339464771989622907027621153398088495 := by - native_decide - rw [hoff] - let l := getTickSourceLogSqrt10001Int I - change ((EVM.wordOfInt l).toNat + 291339464771989622907027621153398088495) % - UInt256.size = - (EVM.wordOfInt (l + 291339464771989622907027621153398088495)).toNat - have hlogAbsLt : l.natAbs < EVM.wordModulus := by - by_cases hneg : l < 0 - · have habs : (l.natAbs : Int) = -l := Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [l, EVM.wordModulus, EVM.twoPow] at hlogGe ⊢ - omega - · have hnonneg : 0 ≤ l := by omega - have habs : (l.natAbs : Int) = l := Int.natAbs_of_nonneg hnonneg - have hlt : (l.natAbs : Int) < EVM.wordModulus := by - rw [habs] - exact lt_trans hlogLt (by norm_num [EVM.wordModulus, EVM.twoPow]) - exact_mod_cast hlt - have hsumAbsLt : (l + 291339464771989622907027621153398088495).natAbs < - EVM.wordModulus := by - by_cases hneg : l + 291339464771989622907027621153398088495 < 0 - · have habs : - ((l + 291339464771989622907027621153398088495).natAbs : Int) = - -(l + 291339464771989622907027621153398088495) := - Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [l, EVM.wordModulus, EVM.twoPow] at hsumGe ⊢ - omega - · have hnonneg : 0 ≤ l + 291339464771989622907027621153398088495 := by omega - have habs : - ((l + 291339464771989622907027621153398088495).natAbs : Int) = - l + 291339464771989622907027621153398088495 := - Int.natAbs_of_nonneg hnonneg - have hlt : - ((l + 291339464771989622907027621153398088495).natAbs : Int) < - EVM.wordModulus := by - rw [habs] - exact lt_trans (by simpa [l, getTickSourceTickHiOffsetInt] using hsumLt) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - exact_mod_cast hlt - by_cases hlogNonneg : 0 ≤ l - · have hlogLtWord : l < EVM.wordModulus := - lt_trans hlogLt (by norm_num [EVM.wordModulus, EVM.twoPow]) - rw [wordOfInt_nonneg_toNat_lt_wordModulus l hlogNonneg hlogLtWord] - have hsumNonneg : 0 ≤ l + 291339464771989622907027621153398088495 := by omega - have hsumLtWord : l + 291339464771989622907027621153398088495 < - EVM.wordModulus := - lt_trans (by simpa [l, getTickSourceTickHiOffsetInt] using hsumLt) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - rw [wordOfInt_nonneg_toNat_lt_wordModulus _ hsumNonneg hsumLtWord] - have hsumNatLt : l.toNat + 291339464771989622907027621153398088495 < - UInt256.size := by - have hlto : (l.toNat : Int) = l := Int.toNat_of_nonneg hlogNonneg - norm_num [UInt256.size] at hsumLtWord ⊢ - omega - rw [Nat.mod_eq_of_lt hsumNatLt] - have hlto : (l.toNat : Int) = l := Int.toNat_of_nonneg hlogNonneg - omega - · have hlogNeg : l < 0 := by omega - rw [wordOfInt_neg_toNat_lt_wordModulus l hlogNeg hlogAbsLt] - by_cases hsumNonneg : 0 ≤ l + 291339464771989622907027621153398088495 - · have hsumLtWord : l + 291339464771989622907027621153398088495 < - EVM.wordModulus := - lt_trans (by simpa [l, getTickSourceTickHiOffsetInt] using hsumLt) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - rw [wordOfInt_nonneg_toNat_lt_wordModulus _ hsumNonneg hsumLtWord] - have habs : (l.natAbs : Int) = -l := Int.ofNat_natAbs_of_nonpos (by omega) - have hwrap : - UInt256.size ≤ - UInt256.size - l.natAbs + 291339464771989622907027621153398088495 := by - norm_num [UInt256.size] at habs hsumNonneg ⊢ - omega - have hsumLt2 : - UInt256.size - l.natAbs + 291339464771989622907027621153398088495 < - 2 * UInt256.size := by - have habsLtSize : l.natAbs < UInt256.size := by - simpa [EVM.wordModulus, EVM.twoPow, UInt256.size] using hlogAbsLt - norm_num [UInt256.size] - omega - have hmod : - (UInt256.size - l.natAbs + 291339464771989622907027621153398088495) % - UInt256.size = - UInt256.size - l.natAbs + 291339464771989622907027621153398088495 - - UInt256.size := by - rw [Nat.mod_eq_sub_mod hwrap] - rw [Nat.mod_eq_of_lt] - omega - rw [hmod] - have hto : ((l + 291339464771989622907027621153398088495).toNat : Int) = - l + 291339464771989622907027621153398088495 := - Int.toNat_of_nonneg hsumNonneg - have hlogAbsLe : l.natAbs ≤ UInt256.size := by - exact le_of_lt - (by simpa [EVM.wordModulus, EVM.twoPow, UInt256.size] using hlogAbsLt) - apply (Nat.cast_inj (R := Int)).mp - rw [Nat.cast_sub hwrap] - rw [Nat.cast_add] - rw [Nat.cast_sub hlogAbsLe] - rw [hto] - rw [habs] - norm_num [UInt256.size] - ring - · have hsumNeg : l + 291339464771989622907027621153398088495 < 0 := by omega - rw [wordOfInt_neg_toNat_lt_wordModulus _ hsumNeg hsumAbsLt] - have habsLog : (l.natAbs : Int) = -l := Int.ofNat_natAbs_of_nonpos (by omega) - have habsSum : - ((l + 291339464771989622907027621153398088495).natAbs : Int) = - -(l + 291339464771989622907027621153398088495) := - Int.ofNat_natAbs_of_nonpos (by omega) - have hltNoWrap : - UInt256.size - l.natAbs + 291339464771989622907027621153398088495 < - UInt256.size := by - norm_num [UInt256.size] at habsLog hsumNeg ⊢ - omega - rw [Nat.mod_eq_of_lt hltNoWrap] - have hlogAbsLe : l.natAbs ≤ UInt256.size := by - exact le_of_lt - (by simpa [EVM.wordModulus, EVM.twoPow, UInt256.size] using hlogAbsLt) - have hsumAbsLe : - (l + 291339464771989622907027621153398088495).natAbs ≤ UInt256.size := - le_of_lt (by simpa [EVM.wordModulus, EVM.twoPow, UInt256.size] using hsumAbsLt) - apply (Nat.cast_inj (R := Int)).mp - rw [Nat.cast_add] - rw [Nat.cast_sub hlogAbsLe] - rw [Nat.cast_sub hsumAbsLe] - rw [habsLog] - rw [habsSum] - norm_num [UInt256.size] - ring - -set_option maxRecDepth 2000000 in -set_option maxHeartbeats 1000000 in -private theorem getTickLowBiasedWord_eq_source_of_log (I : ExecutionEnv) - (hlog : getTickLogSqrt10001Word I = EVM.wordOfInt (getTickSourceLogSqrt10001Int I)) - (hlogGe : -(2 ^ 255 : Int) ≤ getTickSourceLogSqrt10001Int I) - (hlogLt : getTickSourceLogSqrt10001Int I < 2 ^ 255) - (hdiffGe : - -(2 ^ 255 : Int) ≤ getTickSourceLogSqrt10001Int I - getTickSourceTickLowOffsetInt) - (hdiffLt : getTickSourceLogSqrt10001Int I - getTickSourceTickLowOffsetInt < 2 ^ 255) : - getTickLowBiasedWord I = - EVM.wordOfInt (getTickSourceLogSqrt10001Int I - getTickSourceTickLowOffsetInt) := by - apply u256_inj - unfold getTickLowBiasedWord getTickSourceTickLowOffsetInt - rw [hlog, uadd_toNat] - have hoff : (UInt256.lnot getTickLowOffsetWord).toNat = - UInt256.size - 3402992956809132418596140100660247210 := by - native_decide - rw [hoff] - let l := getTickSourceLogSqrt10001Int I - let off : Nat := 3402992956809132418596140100660247210 - change ((EVM.wordOfInt l).toNat + (UInt256.size - off)) % UInt256.size = - (EVM.wordOfInt (l - (off : Int))).toNat - have hlogAbsLt : l.natAbs < EVM.wordModulus := by - by_cases hneg : l < 0 - · have habs : (l.natAbs : Int) = -l := Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [l, EVM.wordModulus, EVM.twoPow] at hlogGe ⊢ - omega - · have hnonneg : 0 ≤ l := by omega - have habs : (l.natAbs : Int) = l := Int.natAbs_of_nonneg hnonneg - have hlt : (l.natAbs : Int) < EVM.wordModulus := by - rw [habs] - exact lt_trans hlogLt (by norm_num [EVM.wordModulus, EVM.twoPow]) - exact_mod_cast hlt - have hdiffAbsLt : (l - (off : Int)).natAbs < EVM.wordModulus := by - by_cases hneg : l - (off : Int) < 0 - · have habs : ((l - (off : Int)).natAbs : Int) = -(l - (off : Int)) := - Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [l, off, EVM.wordModulus, EVM.twoPow] at hdiffGe ⊢ - omega - · have hnonneg : 0 ≤ l - (off : Int) := by omega - have habs : ((l - (off : Int)).natAbs : Int) = l - (off : Int) := - Int.natAbs_of_nonneg hnonneg - have hlt : ((l - (off : Int)).natAbs : Int) < EVM.wordModulus := by - rw [habs] - exact lt_trans (by simpa [l, off, getTickSourceTickLowOffsetInt] using hdiffLt) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - exact_mod_cast hlt - by_cases hlogNonneg : 0 ≤ l - · have hlogLtWord : l < EVM.wordModulus := - lt_trans hlogLt (by norm_num [EVM.wordModulus, EVM.twoPow]) - rw [wordOfInt_nonneg_toNat_lt_wordModulus l hlogNonneg hlogLtWord] - by_cases hdiffNonneg : 0 ≤ l - (off : Int) - · have hdiffLtWord : l - (off : Int) < EVM.wordModulus := - lt_trans (by simpa [l, off, getTickSourceTickLowOffsetInt] using hdiffLt) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - rw [wordOfInt_nonneg_toNat_lt_wordModulus _ hdiffNonneg hdiffLtWord] - have hwrap : UInt256.size ≤ l.toNat + (UInt256.size - off) := by - have hlto : (l.toNat : Int) = l := Int.toNat_of_nonneg hlogNonneg - norm_num [off, UInt256.size] at hdiffNonneg hlto ⊢ - omega - have hlt2 : l.toNat + (UInt256.size - off) < 2 * UInt256.size := by - have hlogNatLt : l.toNat < UInt256.size := by - exact (Int.toNat_lt hlogNonneg).2 - (by simpa [EVM.wordModulus, EVM.twoPow, UInt256.size] using hlogLtWord) - norm_num [off] - omega - rw [Nat.mod_eq_sub_mod hwrap] - rw [Nat.mod_eq_of_lt] - · - have hlto : (l.toNat : Int) = l := Int.toNat_of_nonneg hlogNonneg - have hto : ((l - (off : Int)).toNat : Int) = l - (off : Int) := - Int.toNat_of_nonneg hdiffNonneg - apply (Nat.cast_inj (R := Int)).mp - rw [Nat.cast_sub hwrap] - rw [Nat.cast_add] - rw [hlto] - rw [hto] - norm_num [off, UInt256.size] - ring - · omega - · have hdiffNeg : l - (off : Int) < 0 := by omega - rw [wordOfInt_neg_toNat_lt_wordModulus _ hdiffNeg hdiffAbsLt] - have hltNoWrap : l.toNat + (UInt256.size - off) < UInt256.size := by - have hlto : (l.toNat : Int) = l := Int.toNat_of_nonneg hlogNonneg - norm_num [off, UInt256.size] at hdiffNeg hlto ⊢ - omega - rw [Nat.mod_eq_of_lt hltNoWrap] - have hlto : (l.toNat : Int) = l := Int.toNat_of_nonneg hlogNonneg - have habsDiff : (((l - (off : Int)).natAbs) : Int) = -(l - (off : Int)) := - Int.ofNat_natAbs_of_nonpos (by omega) - have hdiffAbsLe : (l - (off : Int)).natAbs ≤ UInt256.size := by - exact le_of_lt - (by simpa [EVM.wordModulus, EVM.twoPow, UInt256.size] using hdiffAbsLt) - apply (Nat.cast_inj (R := Int)).mp - rw [Nat.cast_add] - rw [hlto] - rw [Nat.cast_sub hdiffAbsLe] - rw [habsDiff] - norm_num [off, UInt256.size] - ring - · have hlogNeg : l < 0 := by omega - rw [wordOfInt_neg_toNat_lt_wordModulus l hlogNeg hlogAbsLt] - have hdiffNeg : l - (off : Int) < 0 := by omega - rw [wordOfInt_neg_toNat_lt_wordModulus _ hdiffNeg hdiffAbsLt] - have habsLog : (l.natAbs : Int) = -l := Int.ofNat_natAbs_of_nonpos (by omega) - have habsDiff : (((l - (off : Int)).natAbs) : Int) = -(l - (off : Int)) := - Int.ofNat_natAbs_of_nonpos (by omega) - have hwrap : UInt256.size ≤ UInt256.size - l.natAbs + (UInt256.size - off) := by - norm_num [off, UInt256.size] - omega - have hlt2 : UInt256.size - l.natAbs + (UInt256.size - off) < 2 * UInt256.size := by - have hdiffAbsLtSize : (l - (off : Int)).natAbs < UInt256.size := by - simpa [EVM.wordModulus, EVM.twoPow, UInt256.size] using hdiffAbsLt - have hsumEq : - UInt256.size - l.natAbs + (UInt256.size - off) = - 2 * UInt256.size - (l - (off : Int)).natAbs := by - have hlogAbsLe : l.natAbs ≤ UInt256.size := by - exact le_of_lt - (by simpa [EVM.wordModulus, EVM.twoPow, UInt256.size] using hlogAbsLt) - have hdiffAbsLe2 : (l - (off : Int)).natAbs ≤ 2 * UInt256.size := by - omega - apply (Nat.cast_inj (R := Int)).mp - rw [Nat.cast_add] - rw [Nat.cast_sub hlogAbsLe] - rw [Nat.cast_sub hdiffAbsLe2] - rw [habsLog] - rw [habsDiff] - norm_num [off, UInt256.size] - ring - rw [hsumEq] - exact Nat.sub_lt (by norm_num [UInt256.size]) (Int.natAbs_pos.mpr (ne_of_lt hdiffNeg)) - rw [Nat.mod_eq_sub_mod hwrap] - rw [Nat.mod_eq_of_lt] - · - have hlogAbsLe : l.natAbs ≤ UInt256.size := by - exact le_of_lt - (by simpa [EVM.wordModulus, EVM.twoPow, UInt256.size] using hlogAbsLt) - have hdiffAbsLe : (l - (off : Int)).natAbs ≤ UInt256.size := by - exact le_of_lt - (by simpa [EVM.wordModulus, EVM.twoPow, UInt256.size] using hdiffAbsLt) - apply (Nat.cast_inj (R := Int)).mp - rw [Nat.cast_sub hwrap] - rw [Nat.cast_add] - rw [Nat.cast_sub hlogAbsLe] - rw [Nat.cast_sub hdiffAbsLe] - rw [habsLog] - rw [habsDiff] - norm_num [off, UInt256.size] - ring - · omega - -private theorem getTickHiWord_eq_source_of_biased (I : ExecutionEnv) - (hbiased : getTickHiBiasedWord I = - EVM.wordOfInt (getTickSourceLogSqrt10001Int I + getTickSourceTickHiOffsetInt)) - (hge : -(2 ^ 255 : Int) ≤ getTickSourceLogSqrt10001Int I + getTickSourceTickHiOffsetInt) - (hlt : getTickSourceLogSqrt10001Int I + getTickSourceTickHiOffsetInt < 2 ^ 255) : - getTickHiWord I = EVM.wordOfInt (getTickSourceTickHiInt I) := by - unfold getTickHiWord - rw [hbiased] - unfold getTickSourceTickHiInt getTickSourceFixedPoint128Int - exact sar128_wordOfInt - (getTickSourceLogSqrt10001Int I + getTickSourceTickHiOffsetInt) hge hlt - -private theorem getTickLowWord_eq_source_of_biased (I : ExecutionEnv) - (hbiased : getTickLowBiasedWord I = - EVM.wordOfInt (getTickSourceLogSqrt10001Int I - getTickSourceTickLowOffsetInt)) - (hge : -(2 ^ 255 : Int) ≤ getTickSourceLogSqrt10001Int I - getTickSourceTickLowOffsetInt) - (hlt : getTickSourceLogSqrt10001Int I - getTickSourceTickLowOffsetInt < 2 ^ 255) : - getTickLowWord I = EVM.wordOfInt (getTickSourceTickLowInt I) := by - unfold getTickLowWord - rw [hbiased] - unfold getTickSourceTickLowInt getTickSourceFixedPoint128Int - exact sar128_wordOfInt - (getTickSourceLogSqrt10001Int I - getTickSourceTickLowOffsetInt) hge hlt - -theorem getTickHiWord_eq_source_of_bounds (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - getTickHiWord I = EVM.wordOfInt (getTickSourceTickHiInt I) := by - have hlog := getTickLogSqrt10001Word_eq_source_of_bounds I hlo hhi - have hlogBounds := getTickSourceLogSqrt10001Int_int256_bounds I hlo hhi - have hnumBounds := getTickSourceTickHiNumerator_int256_bounds I hlo hhi - exact getTickHiWord_eq_source_of_biased I - (getTickHiBiasedWord_eq_source_of_log I hlog hlogBounds.1 hlogBounds.2 - hnumBounds.1 hnumBounds.2) - hnumBounds.1 hnumBounds.2 - -theorem getTickLowWord_eq_source_of_bounds (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - getTickLowWord I = EVM.wordOfInt (getTickSourceTickLowInt I) := by - have hlog := getTickLogSqrt10001Word_eq_source_of_bounds I hlo hhi - have hlogBounds := getTickSourceLogSqrt10001Int_int256_bounds I hlo hhi - have hnumBounds := getTickSourceTickLowNumerator_int256_bounds I hlo hhi - exact getTickLowWord_eq_source_of_biased I - (getTickLowBiasedWord_eq_source_of_log I hlog hlogBounds.1 hlogBounds.2 - hnumBounds.1 hnumBounds.2) - hnumBounds.1 hnumBounds.2 - -theorem getTickSourceTickLowValue_eq_wordToElem_of_word (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) - (hword : getTickLowWord I = EVM.wordOfInt (getTickSourceTickLowInt I)) : - getTickSourceTickLowValue I = wordToElem (.int int24Int) (getTickLowWord I) := by - rw [hword] - unfold getTickSourceTickLowValue - have hb := getTickSourceTickLowInt_int24_bounds I hlo hhi - exact (wordToElem_int24_wordOfInt (getTickSourceTickLowInt I) hb.1 hb.2).symm - -theorem getTickSourceTickHiValue_eq_wordToElem_of_word (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) - (hword : getTickHiWord I = EVM.wordOfInt (getTickSourceTickHiInt I)) : - getTickSourceTickHiValue I = wordToElem (.int int24Int) (getTickHiWord I) := by - rw [hword] - unfold getTickSourceTickHiValue - have hb := getTickSourceTickHiInt_int24_bounds I hlo hhi - exact (wordToElem_int24_wordOfInt (getTickSourceTickHiInt I) hb.1 hb.2).symm - -theorem getTickLowEqHiWord_eq_one_of_source_eq (I : ExecutionEnv) - (hlowWord : getTickLowWord I = EVM.wordOfInt (getTickSourceTickLowInt I)) - (hhiWord : getTickHiWord I = EVM.wordOfInt (getTickSourceTickHiInt I)) - (heq : getTickSourceTickLowInt I = getTickSourceTickHiInt I) : - getTickLowEqHiWord I = ⟨1⟩ := by - have hwordEq : getTickLowInt24Word I = getTickHiInt24Word I := by - unfold getTickLowInt24Word getTickHiInt24Word - rw [hlowWord, hhiWord, heq] - unfold getTickLowEqHiWord - rw [hwordEq] - exact u256_eq_refl _ - -theorem getTickLowEqHiWord_eq_zero_of_source_ne (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) - (hlowWord : getTickLowWord I = EVM.wordOfInt (getTickSourceTickLowInt I)) - (hhiWord : getTickHiWord I = EVM.wordOfInt (getTickSourceTickHiInt I)) - (hne : getTickSourceTickLowInt I ≠ getTickSourceTickHiInt I) : - getTickLowEqHiWord I = ⟨0⟩ := by - have hlowBounds := getTickSourceTickLowInt_int24_bounds I hlo hhi - have hhiBounds := getTickSourceTickHiInt_int24_bounds I hlo hhi - have hwordNe : getTickLowInt24Word I ≠ getTickHiInt24Word I := by - intro hwordEq - have hlowSign : - getTickLowInt24Word I = EVM.wordOfInt (getTickSourceTickLowInt I) := by - unfold getTickLowInt24Word - rw [hlowWord] - exact signextend_two_wordOfInt_tickSpacing (getTickSourceTickLowInt I) - hlowBounds.1 hlowBounds.2 - have hhiSign : - getTickHiInt24Word I = EVM.wordOfInt (getTickSourceTickHiInt I) := by - unfold getTickHiInt24Word - rw [hhiWord] - exact signextend_two_wordOfInt_tickSpacing (getTickSourceTickHiInt I) - hhiBounds.1 hhiBounds.2 - have hwordOfIntEq : - EVM.wordOfInt (getTickSourceTickLowInt I) = - EVM.wordOfInt (getTickSourceTickHiInt I) := by - rw [← hlowSign, ← hhiSign] - exact hwordEq - exact hne (wordOfInt_int24_inj hlowBounds.1 hlowBounds.2 hhiBounds.1 hhiBounds.2 - hwordOfIntEq) - unfold getTickLowEqHiWord - exact u256_eq_of_ne hwordNe - -theorem getSqrtRatioAbsTickBranchWord_tickHi_eq_source_abs (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) - (hhiWord : getTickHiWord I = EVM.wordOfInt (getTickSourceTickHiInt I)) : - getSqrtRatioAbsTickBranchWord (getTickHiWord I) = - EVM.wordOfInt (getSqrtRatioSourceTickHiAbsTickInt I) := by - have hb := getTickSourceTickHiInt_int24_bounds I hlo hhi - unfold getSqrtRatioAbsTickBranchWord getSqrtRatioTickNegWord getSqrtRatioTickInt24Word - getSqrtRatioAbsTickNegWord - rw [hhiWord] - rw [signextend_two_wordOfInt_tickSpacing (getTickSourceTickHiInt I) hb.1 hb.2] - rw [slt_wordOfInt_int24_zero (getTickSourceTickHiInt I) hb.1 hb.2] - unfold getSqrtRatioSourceTickHiAbsTickInt - by_cases hneg : getTickSourceTickHiInt I < 0 - · simp only [hneg, ↓reduceIte] - rw [if_neg (by native_decide : ¬ ((⟨1⟩ : UInt256) = ⟨0⟩))] - unfold getSqrtRatioTickInt24Word - rw [signextend_two_wordOfInt_tickSpacing (getTickSourceTickHiInt I) hb.1 hb.2] - rw [show 0 - getTickSourceTickHiInt I = -getTickSourceTickHiInt I by omega] - exact zero_sub_wordOfInt_int24_neg (getTickSourceTickHiInt I) hneg hb.1 - · simp only [hneg, ↓reduceIte] - -theorem getSqrtRatioAbsTickBranchWord_tickHi_toNat_le_max (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) - (hhiWord : getTickHiWord I = EVM.wordOfInt (getTickSourceTickHiInt I)) : - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)).toNat ≤ getSqrtRatioMaxTickWord.toNat := by - have hb := getTickSourceTickHiInt_int24_bounds I hlo hhi - have hrange := getSqrtRatioSourceTickHiAbsTickInt_le_maxTick I hlo hhi - unfold getSqrtRatioAbsTickBranchWord getSqrtRatioTickNegWord getSqrtRatioTickInt24Word - getSqrtRatioAbsTickNegWord - rw [hhiWord] - rw [signextend_two_wordOfInt_tickSpacing (getTickSourceTickHiInt I) hb.1 hb.2] - rw [slt_wordOfInt_int24_zero (getTickSourceTickHiInt I) hb.1 hb.2] - by_cases hneg : getTickSourceTickHiInt I < 0 - · simp only [hneg, ↓reduceIte] - rw [if_neg (by native_decide : ¬ ((⟨1⟩ : UInt256) = ⟨0⟩))] - unfold getSqrtRatioTickInt24Word - rw [signextend_two_wordOfInt_tickSpacing (getTickSourceTickHiInt I) hb.1 hb.2] - rw [zero_sub_wordOfInt_int24_neg_toNat (getTickSourceTickHiInt I) hneg hb.1] - rw [show getSqrtRatioMaxTickWord.toNat = 887272 by native_decide] - have hrange' : -getTickSourceTickHiInt I ≤ 887272 := by - unfold getSqrtRatioSourceTickHiAbsTickInt at hrange - rw [if_pos hneg] at hrange - omega - exact Int.toNat_le_toNat hrange' - · simp only [hneg, ↓reduceIte] - have hnonneg : 0 ≤ getTickSourceTickHiInt I := by omega - have hrange' : getTickSourceTickHiInt I ≤ 887272 := by - unfold getSqrtRatioSourceTickHiAbsTickInt at hrange - rw [if_neg hneg] at hrange - exact hrange - rw [wordOfInt_nonneg_toNat_lt_wordModulus (getTickSourceTickHiInt I) hnonneg] - · rw [show getSqrtRatioMaxTickWord.toNat = 887272 by native_decide] - exact Int.toNat_le_toNat hrange' - · exact lt_of_le_of_lt hrange' (by norm_num [EVM.wordModulus, EVM.twoPow]) - -theorem getSqrtRatioAbsTickInRangeWord_tickHi_ne_zero (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) - (hhiWord : getTickHiWord I = EVM.wordOfInt (getTickSourceTickHiInt I)) : - getSqrtRatioAbsTickInRangeWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) ≠ ⟨0⟩ := by - unfold getSqrtRatioAbsTickInRangeWord - have hgt0 : - UInt256.gt (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) - getSqrtRatioMaxTickWord = ⟨0⟩ := by - exact ugt_zero (getSqrtRatioAbsTickBranchWord_tickHi_toNat_le_max I hlo hhi hhiWord) - rw [hgt0] - rw [show UInt256.isZero (⟨0⟩ : UInt256) = ⟨1⟩ from by decide] - intro h - cases h - -private theorem getSqrtRatioSourceTickHiInitialRatioInt_lb (I : ExecutionEnv) : - (340265354078544963557816517032075149313 : Int) ≤ - getSqrtRatioSourceTickHiInitialRatioInt I := by - unfold getSqrtRatioSourceTickHiInitialRatioInt - by_cases h : getSqrtRatioSourceTickHiBit1Int I = 0 - · simp [h] - · simp [h] - -theorem getSqrtRatioSourceTickHiAfterBit524288Int_ne_zero (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit524288Int I ≠ 0 := by - have hr0lo := getSqrtRatioSourceTickHiInitialRatioInt_lb I - have hr2lo : (340231330945450418515964920540021147198 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit2Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit2Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiInitialRatioInt I) - 2 - getSqrtRatioSourceFactor2Int - 340248342086729790484326174814286782778 - 340265354078544963557816517032075149313 - 340231330945450418515964920540021147198 - (by native_decide) - (by native_decide) - hr0lo - (by native_decide) - (by native_decide) - have hr4lo : (340163294884840501567246455576441303173 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit4Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit4Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2Int I) - 4 - getSqrtRatioSourceFactor4Int - 340214320654664324051920982716015181260 - 340231330945450418515964920540021147198 - 340163294884840501567246455576441303173 - (by native_decide) - (by native_decide) - hr2lo - (by native_decide) - (by native_decide) - have hr8lo : (340027263576413978334042125129128142263 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit8Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit8Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4Int I) - 8 - getSqrtRatioSourceFactor8Int - 340146287995602323631171512101879684304 - 340163294884840501567246455576441303173 - 340027263576413978334042125129128142263 - (by native_decide) - (by native_decide) - hr4lo - (by native_decide) - (by native_decide) - have hr16lo : (339755364134575681238502878529008278326 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit16Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit16Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8Int I) - 16 - getSqrtRatioSourceFactor16Int - 340010263488231146823593991679159461444 - 340027263576413978334042125129128142263 - 339755364134575681238502878529008278326 - (by native_decide) - (by native_decide) - hr8lo - (by native_decide) - (by native_decide) - have hr32lo : (339212217342146842559531600927033253847 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit32Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit32Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16Int I) - 32 - getSqrtRatioSourceFactor32Int - 339738377640345403697157401104375502016 - 339755364134575681238502878529008278326 - 339212217342146842559531600927033253847 - (by native_decide) - (by native_decide) - hr16lo - (by native_decide) - (by native_decide) - have hr64lo : (338128527259088467778511436198880488164 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit64Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit64Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32Int I) - 64 - getSqrtRatioSourceFactor64Int - 339195258003219555707034227454543997025 - 339212217342146842559531600927033253847 - 338128527259088467778511436198880488164 - (by native_decide) - (by native_decide) - hr32lo - (by native_decide) - (by native_decide) - have hr128lo : (335971522311117552149334092109581418674 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit128Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit128Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit64Int I) - 128 - getSqrtRatioSourceFactor128Int - 338111622100601834656805679988414885971 - 338128527259088467778511436198880488164 - 335971522311117552149334092109581418674 - (by native_decide) - (by native_decide) - hr64lo - (by native_decide) - (by native_decide) - have hr256lo : (331698704829854243503582989311158516586 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit256Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit256Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit128Int I) - 256 - getSqrtRatioSourceFactor256Int - 335954724994790223023589805789778977700 - 335971522311117552149334092109581418674 - 331698704829854243503582989311158516586 - (by native_decide) - (by native_decide) - hr128lo - (by native_decide) - (by native_decide) - have hr512lo : (323315401242583425022802937239550140918 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit512Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit512Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit256Int I) - 512 - getSqrtRatioSourceFactor512Int - 331682121138379247127172139078559817300 - 331698704829854243503582989311158516586 - 323315401242583425022802937239550140918 - (by native_decide) - (by native_decide) - hr256lo - (by native_decide) - (by native_decide) - have hr1024lo : (307179074178916392659402722612948179612 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit1024Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit1024Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit512Int I) - 1024 - getSqrtRatioSourceFactor1024Int - 323299236684853023288211250268160618739 - 323315401242583425022802937239550140918 - 307179074178916392659402722612948179612 - (by native_decide) - (by native_decide) - hr512lo - (by native_decide) - (by native_decide) - have hr2048lo : (277282266700509388632609933215391170106 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit2048Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit2048Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit1024Int I) - 2048 - getSqrtRatioSourceFactor2048Int - 307163716377032989948697243942600083929 - 307179074178916392659402722612948179612 - 277282266700509388632609933215391170106 - (by native_decide) - (by native_decide) - hr1024lo - (by native_decide) - (by native_decide) - have hr4096lo : (225934749830749445986089663015556949343 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit4096Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit4096Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2048Int I) - 4096 - getSqrtRatioSourceFactor4096Int - 277268403626896220162999269216087595045 - 277282266700509388632609933215391170106 - 225934749830749445986089663015556949343 - (by native_decide) - (by native_decide) - hr2048lo - (by native_decide) - (by native_decide) - have hr8192lo : (150004713758184102711002566140788444796 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit8192Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit8192Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4096Int I) - 8192 - getSqrtRatioSourceFactor8192Int - 225923453940442621947126027127485391333 - 225934749830749445986089663015556949343 - 150004713758184102711002566140788444796 - (by native_decide) - (by native_decide) - hr4096lo - (by native_decide) - (by native_decide) - have hr16384lo : (66122407008436832627027740713496573148 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit16384Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit16384Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8192Int I) - 16384 - getSqrtRatioSourceFactor16384Int - 149997214084966997727330242082538205943 - 150004713758184102711002566140788444796 - 66122407008436832627027740713496573148 - (by native_decide) - (by native_decide) - hr8192lo - (by native_decide) - (by native_decide) - have hr32768lo : (12848018414553970828728179856918040433 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit32768Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit32768Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16384Int I) - 32768 - getSqrtRatioSourceFactor32768Int - 66119101136024775622716233608466517926 - 66122407008436832627027740713496573148 - 12848018414553970828728179856918040433 - (by native_decide) - (by native_decide) - hr16384lo - (by native_decide) - (by native_decide) - have hr65536lo : (485077512873820763967752669154895175 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit65536Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit65536Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32768Int I) - 65536 - getSqrtRatioSourceFactor65536Int - 12847376061809297530290974190478138313 - 12848018414553970828728179856918040433 - 485077512873820763967752669154895175 - (by native_decide) - (by native_decide) - hr32768lo - (by native_decide) - (by native_decide) - have hr131072lo : (691450548841240133896843047535567 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit131072Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit131072Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit65536Int I) - 131072 - getSqrtRatioSourceFactor131072Int - 485053260817066172746253684029974020 - 485077512873820763967752669154895175 - 691450548841240133896843047535567 - (by native_decide) - (by native_decide) - hr65536lo - (by native_decide) - (by native_decide) - have hr262144lo : (1404950724947776134837143967 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit262144Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit262144Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit131072Int I) - 262144 - getSqrtRatioSourceFactor262144Int - 691415978906521570653435304214168 - 691450548841240133896843047535567 - 1404950724947776134837143967 - (by native_decide) - (by native_decide) - hr131072lo - (by native_decide) - (by native_decide) - have hr524288lo : (5800441176149320 : Int) ≤ - getSqrtRatioSourceTickHiAfterBit524288Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit524288Int] using - sourceSqrtRatioStepInt_lb - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit262144Int I) - 524288 - getSqrtRatioSourceFactor524288Int - 1404880482679654955896180642 - 1404950724947776134837143967 - 5800441176149320 - (by native_decide) - (by native_decide) - hr262144lo - (by native_decide) - (by native_decide) - exact ne_of_gt (lt_of_lt_of_le (by norm_num) hr524288lo) - -theorem getSqrtRatioAfterAllBitsWord_tickHi_ne_zero (I : ExecutionEnv) : - getSqrtRatioAfterAllBitsWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) - (getSqrtRatioInitialBranchWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I))) ≠ ⟨0⟩ := by - let absTick := getSqrtRatioAbsTickBranchWord (getTickHiWord I) - let r0 := getSqrtRatioInitialBranchWord absTick - let r0m := getSqrtRatioRatioMaskedWord r0 - have hr0mlo : 340265354078544963557816517032075149313 ≤ r0m.toNat := by - dsimp [r0m, r0] - exact getSqrtRatioInitialMaskedBranchWord_lb absTick - have hr0mhi : r0m.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r0m, r0] - exact getSqrtRatioInitialMaskedBranchWord_le_q128 absTick - let r2 := getSqrtRatioAfterBit2BranchWord absTick r0 - have hr2lo : 340231330945450418515964920540021147198 ≤ r2.toNat := by - dsimp [r2] - unfold getSqrtRatioAfterBit2BranchWord - by_cases h : getSqrtRatioBit2Word absTick = ⟨0⟩ - · simpa [h, r0m, r0] using - (le_trans (by native_decide : - 340231330945450418515964920540021147198 ≤ - 340265354078544963557816517032075149313) hr0mlo) - · simpa [h, getSqrtRatioAfterBit2Word, r0m, r0] using - sqrtRatioStepWord_lb getSqrtRatioFactor2Word r0m - 340248342086729790484326174814286782778 - 340265354078544963557816517032075149313 - 340231330945450418515964920540021147198 - (by native_decide) (by native_decide) hr0mlo hr0mhi (by native_decide) - have hr2hi : r2.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r2] - unfold getSqrtRatioAfterBit2BranchWord - by_cases h : getSqrtRatioBit2Word absTick = ⟨0⟩ - · simpa [h, r0m, r0] using hr0mhi - · simpa [h, getSqrtRatioAfterBit2Word, r0m, r0] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor2Word r0m - 340248342086729790484326174814286782778 - (by native_decide) (by native_decide) hr0mhi - let r4 := getSqrtRatioAfterBit4BranchWord absTick r2 - have hr4lo : 340163294884840501567246455576441303173 ≤ r4.toNat := by - dsimp [r4] - unfold getSqrtRatioAfterBit4BranchWord - by_cases h : getSqrtRatioBit4Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 340163294884840501567246455576441303173 ≤ - 340231330945450418515964920540021147198) hr2lo) - · simpa [h, getSqrtRatioAfterBit4Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor4Word r2 - 340214320654664324051920982716015181260 - 340231330945450418515964920540021147198 - 340163294884840501567246455576441303173 - (by native_decide) (by native_decide) hr2lo hr2hi (by native_decide) - have hr4hi : r4.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r4] - unfold getSqrtRatioAfterBit4BranchWord - by_cases h : getSqrtRatioBit4Word absTick = ⟨0⟩ - · simpa [h] using hr2hi - · simpa [h, getSqrtRatioAfterBit4Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor4Word r2 - 340214320654664324051920982716015181260 - (by native_decide) (by native_decide) hr2hi - let r8 := getSqrtRatioAfterBit8BranchWord absTick r4 - have hr8lo : 340027263576413978334042125129128142263 ≤ r8.toNat := by - dsimp [r8] - unfold getSqrtRatioAfterBit8BranchWord - by_cases h : getSqrtRatioBit8Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 340027263576413978334042125129128142263 ≤ - 340163294884840501567246455576441303173) hr4lo) - · simpa [h, getSqrtRatioAfterBit8Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor8Word r4 - 340146287995602323631171512101879684304 - 340163294884840501567246455576441303173 - 340027263576413978334042125129128142263 - (by native_decide) (by native_decide) hr4lo hr4hi (by native_decide) - have hr8hi : r8.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r8] - unfold getSqrtRatioAfterBit8BranchWord - by_cases h : getSqrtRatioBit8Word absTick = ⟨0⟩ - · simpa [h] using hr4hi - · simpa [h, getSqrtRatioAfterBit8Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor8Word r4 - 340146287995602323631171512101879684304 - (by native_decide) (by native_decide) hr4hi - let r16 := getSqrtRatioAfterBit16BranchWord absTick r8 - have hr16lo : 339755364134575681238502878529008278326 ≤ r16.toNat := by - dsimp [r16] - unfold getSqrtRatioAfterBit16BranchWord - by_cases h : getSqrtRatioBit16Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 339755364134575681238502878529008278326 ≤ - 340027263576413978334042125129128142263) hr8lo) - · simpa [h, getSqrtRatioAfterBit16Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor16Word r8 - 340010263488231146823593991679159461444 - 340027263576413978334042125129128142263 - 339755364134575681238502878529008278326 - (by native_decide) (by native_decide) hr8lo hr8hi (by native_decide) - have hr16hi : r16.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r16] - unfold getSqrtRatioAfterBit16BranchWord - by_cases h : getSqrtRatioBit16Word absTick = ⟨0⟩ - · simpa [h] using hr8hi - · simpa [h, getSqrtRatioAfterBit16Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor16Word r8 - 340010263488231146823593991679159461444 - (by native_decide) (by native_decide) hr8hi - let r32 := getSqrtRatioAfterBit32BranchWord absTick r16 - have hr32lo : 339212217342146842559531600927033253847 ≤ r32.toNat := by - dsimp [r32] - unfold getSqrtRatioAfterBit32BranchWord - by_cases h : getSqrtRatioBit32Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 339212217342146842559531600927033253847 ≤ - 339755364134575681238502878529008278326) hr16lo) - · simpa [h, getSqrtRatioAfterBit32Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor32Word r16 - 339738377640345403697157401104375502016 - 339755364134575681238502878529008278326 - 339212217342146842559531600927033253847 - (by native_decide) (by native_decide) hr16lo hr16hi (by native_decide) - have hr32hi : r32.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r32] - unfold getSqrtRatioAfterBit32BranchWord - by_cases h : getSqrtRatioBit32Word absTick = ⟨0⟩ - · simpa [h] using hr16hi - · simpa [h, getSqrtRatioAfterBit32Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor32Word r16 - 339738377640345403697157401104375502016 - (by native_decide) (by native_decide) hr16hi - let r64 := getSqrtRatioAfterBit64BranchWord absTick r32 - have hr64lo : 338128527259088467778511436198880488164 ≤ r64.toNat := by - dsimp [r64] - unfold getSqrtRatioAfterBit64BranchWord - by_cases h : getSqrtRatioBit64Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 338128527259088467778511436198880488164 ≤ - 339212217342146842559531600927033253847) hr32lo) - · simpa [h, getSqrtRatioAfterBit64Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor64Word r32 - 339195258003219555707034227454543997025 - 339212217342146842559531600927033253847 - 338128527259088467778511436198880488164 - (by native_decide) (by native_decide) hr32lo hr32hi (by native_decide) - have hr64hi : r64.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r64] - unfold getSqrtRatioAfterBit64BranchWord - by_cases h : getSqrtRatioBit64Word absTick = ⟨0⟩ - · simpa [h] using hr32hi - · simpa [h, getSqrtRatioAfterBit64Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor64Word r32 - 339195258003219555707034227454543997025 - (by native_decide) (by native_decide) hr32hi - let r128 := getSqrtRatioAfterBit128BranchWord absTick r64 - have hr128lo : 335971522311117552149334092109581418674 ≤ r128.toNat := by - dsimp [r128] - unfold getSqrtRatioAfterBit128BranchWord - by_cases h : getSqrtRatioBit128Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 335971522311117552149334092109581418674 ≤ - 338128527259088467778511436198880488164) hr64lo) - · simpa [h, getSqrtRatioAfterBit128Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor128Word r64 - 338111622100601834656805679988414885971 - 338128527259088467778511436198880488164 - 335971522311117552149334092109581418674 - (by native_decide) (by native_decide) hr64lo hr64hi (by native_decide) - have hr128hi : r128.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r128] - unfold getSqrtRatioAfterBit128BranchWord - by_cases h : getSqrtRatioBit128Word absTick = ⟨0⟩ - · simpa [h] using hr64hi - · simpa [h, getSqrtRatioAfterBit128Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor128Word r64 - 338111622100601834656805679988414885971 - (by native_decide) (by native_decide) hr64hi - let r256 := getSqrtRatioAfterBit256BranchWord absTick r128 - have hr256lo : 331698704829854243503582989311158516586 ≤ r256.toNat := by - dsimp [r256] - unfold getSqrtRatioAfterBit256BranchWord - by_cases h : getSqrtRatioBit256Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 331698704829854243503582989311158516586 ≤ - 335971522311117552149334092109581418674) hr128lo) - · simpa [h, getSqrtRatioAfterBit256Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor256Word r128 - 335954724994790223023589805789778977700 - 335971522311117552149334092109581418674 - 331698704829854243503582989311158516586 - (by native_decide) (by native_decide) hr128lo hr128hi (by native_decide) - have hr256hi : r256.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r256] - unfold getSqrtRatioAfterBit256BranchWord - by_cases h : getSqrtRatioBit256Word absTick = ⟨0⟩ - · simpa [h] using hr128hi - · simpa [h, getSqrtRatioAfterBit256Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor256Word r128 - 335954724994790223023589805789778977700 - (by native_decide) (by native_decide) hr128hi - let r512 := getSqrtRatioAfterBit512BranchWord absTick r256 - have hr512lo : 323315401242583425022802937239550140918 ≤ r512.toNat := by - dsimp [r512] - unfold getSqrtRatioAfterBit512BranchWord - by_cases h : getSqrtRatioBit512Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 323315401242583425022802937239550140918 ≤ - 331698704829854243503582989311158516586) hr256lo) - · simpa [h, getSqrtRatioAfterBit512Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor512Word r256 - 331682121138379247127172139078559817300 - 331698704829854243503582989311158516586 - 323315401242583425022802937239550140918 - (by native_decide) (by native_decide) hr256lo hr256hi (by native_decide) - have hr512hi : r512.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r512] - unfold getSqrtRatioAfterBit512BranchWord - by_cases h : getSqrtRatioBit512Word absTick = ⟨0⟩ - · simpa [h] using hr256hi - · simpa [h, getSqrtRatioAfterBit512Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor512Word r256 - 331682121138379247127172139078559817300 - (by native_decide) (by native_decide) hr256hi - let r1024 := getSqrtRatioAfterBit1024BranchWord absTick r512 - have hr1024lo : 307179074178916392659402722612948179612 ≤ r1024.toNat := by - dsimp [r1024] - unfold getSqrtRatioAfterBit1024BranchWord - by_cases h : getSqrtRatioBit1024Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 307179074178916392659402722612948179612 ≤ - 323315401242583425022802937239550140918) hr512lo) - · simpa [h, getSqrtRatioAfterBit1024Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor1024Word r512 - 323299236684853023288211250268160618739 - 323315401242583425022802937239550140918 - 307179074178916392659402722612948179612 - (by native_decide) (by native_decide) hr512lo hr512hi (by native_decide) - have hr1024hi : r1024.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r1024] - unfold getSqrtRatioAfterBit1024BranchWord - by_cases h : getSqrtRatioBit1024Word absTick = ⟨0⟩ - · simpa [h] using hr512hi - · simpa [h, getSqrtRatioAfterBit1024Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor1024Word r512 - 323299236684853023288211250268160618739 - (by native_decide) (by native_decide) hr512hi - let r2048 := getSqrtRatioAfterBit2048BranchWord absTick r1024 - have hr2048lo : 277282266700509388632609933215391170106 ≤ r2048.toNat := by - dsimp [r2048] - unfold getSqrtRatioAfterBit2048BranchWord - by_cases h : getSqrtRatioBit2048Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 277282266700509388632609933215391170106 ≤ - 307179074178916392659402722612948179612) hr1024lo) - · simpa [h, getSqrtRatioAfterBit2048Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor2048Word r1024 - 307163716377032989948697243942600083929 - 307179074178916392659402722612948179612 - 277282266700509388632609933215391170106 - (by native_decide) (by native_decide) hr1024lo hr1024hi (by native_decide) - have hr2048hi : r2048.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r2048] - unfold getSqrtRatioAfterBit2048BranchWord - by_cases h : getSqrtRatioBit2048Word absTick = ⟨0⟩ - · simpa [h] using hr1024hi - · simpa [h, getSqrtRatioAfterBit2048Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor2048Word r1024 - 307163716377032989948697243942600083929 - (by native_decide) (by native_decide) hr1024hi - let r4096 := getSqrtRatioAfterBit4096BranchWord absTick r2048 - have hr4096lo : 225934749830749445986089663015556949343 ≤ r4096.toNat := by - dsimp [r4096] - unfold getSqrtRatioAfterBit4096BranchWord - by_cases h : getSqrtRatioBit4096Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 225934749830749445986089663015556949343 ≤ - 277282266700509388632609933215391170106) hr2048lo) - · simpa [h, getSqrtRatioAfterBit4096Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor4096Word r2048 - 277268403626896220162999269216087595045 - 277282266700509388632609933215391170106 - 225934749830749445986089663015556949343 - (by native_decide) (by native_decide) hr2048lo hr2048hi (by native_decide) - have hr4096hi : r4096.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r4096] - unfold getSqrtRatioAfterBit4096BranchWord - by_cases h : getSqrtRatioBit4096Word absTick = ⟨0⟩ - · simpa [h] using hr2048hi - · simpa [h, getSqrtRatioAfterBit4096Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor4096Word r2048 - 277268403626896220162999269216087595045 - (by native_decide) (by native_decide) hr2048hi - let r8192 := getSqrtRatioAfterBit8192BranchWord absTick r4096 - have hr8192lo : 150004713758184102711002566140788444796 ≤ r8192.toNat := by - dsimp [r8192] - unfold getSqrtRatioAfterBit8192BranchWord - by_cases h : getSqrtRatioBit8192Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 150004713758184102711002566140788444796 ≤ - 225934749830749445986089663015556949343) hr4096lo) - · simpa [h, getSqrtRatioAfterBit8192Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor8192Word r4096 - 225923453940442621947126027127485391333 - 225934749830749445986089663015556949343 - 150004713758184102711002566140788444796 - (by native_decide) (by native_decide) hr4096lo hr4096hi (by native_decide) - have hr8192hi : r8192.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r8192] - unfold getSqrtRatioAfterBit8192BranchWord - by_cases h : getSqrtRatioBit8192Word absTick = ⟨0⟩ - · simpa [h] using hr4096hi - · simpa [h, getSqrtRatioAfterBit8192Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor8192Word r4096 - 225923453940442621947126027127485391333 - (by native_decide) (by native_decide) hr4096hi - let r16384 := getSqrtRatioAfterBit16384BranchWord absTick r8192 - have hr16384lo : 66122407008436832627027740713496573148 ≤ r16384.toNat := by - dsimp [r16384] - unfold getSqrtRatioAfterBit16384BranchWord - by_cases h : getSqrtRatioBit16384Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 66122407008436832627027740713496573148 ≤ - 150004713758184102711002566140788444796) hr8192lo) - · simpa [h, getSqrtRatioAfterBit16384Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor16384Word r8192 - 149997214084966997727330242082538205943 - 150004713758184102711002566140788444796 - 66122407008436832627027740713496573148 - (by native_decide) (by native_decide) hr8192lo hr8192hi (by native_decide) - have hr16384hi : r16384.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r16384] - unfold getSqrtRatioAfterBit16384BranchWord - by_cases h : getSqrtRatioBit16384Word absTick = ⟨0⟩ - · simpa [h] using hr8192hi - · simpa [h, getSqrtRatioAfterBit16384Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor16384Word r8192 - 149997214084966997727330242082538205943 - (by native_decide) (by native_decide) hr8192hi - let r32768 := getSqrtRatioAfterBit32768BranchWord absTick r16384 - have hr32768lo : 12848018414553970828728179856918040433 ≤ r32768.toNat := by - dsimp [r32768] - unfold getSqrtRatioAfterBit32768BranchWord - by_cases h : getSqrtRatioBit32768Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 12848018414553970828728179856918040433 ≤ - 66122407008436832627027740713496573148) hr16384lo) - · simpa [h, getSqrtRatioAfterBit32768Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor32768Word r16384 - 66119101136024775622716233608466517926 - 66122407008436832627027740713496573148 - 12848018414553970828728179856918040433 - (by native_decide) (by native_decide) hr16384lo hr16384hi (by native_decide) - have hr32768hi : r32768.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r32768] - unfold getSqrtRatioAfterBit32768BranchWord - by_cases h : getSqrtRatioBit32768Word absTick = ⟨0⟩ - · simpa [h] using hr16384hi - · simpa [h, getSqrtRatioAfterBit32768Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor32768Word r16384 - 66119101136024775622716233608466517926 - (by native_decide) (by native_decide) hr16384hi - let r65536 := getSqrtRatioAfterBit65536BranchWord absTick r32768 - have hr65536lo : 485077512873820763967752669154895175 ≤ r65536.toNat := by - dsimp [r65536] - unfold getSqrtRatioAfterBit65536BranchWord - by_cases h : getSqrtRatioBit65536Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 485077512873820763967752669154895175 ≤ - 12848018414553970828728179856918040433) hr32768lo) - · simpa [h, getSqrtRatioAfterBit65536Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor65536Word r32768 - 12847376061809297530290974190478138313 - 12848018414553970828728179856918040433 - 485077512873820763967752669154895175 - (by native_decide) (by native_decide) hr32768lo hr32768hi (by native_decide) - have hr65536hi : r65536.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r65536] - unfold getSqrtRatioAfterBit65536BranchWord - by_cases h : getSqrtRatioBit65536Word absTick = ⟨0⟩ - · simpa [h] using hr32768hi - · simpa [h, getSqrtRatioAfterBit65536Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor65536Word r32768 - 12847376061809297530290974190478138313 - (by native_decide) (by native_decide) hr32768hi - let r131072 := getSqrtRatioAfterBit131072BranchWord absTick r65536 - have hr131072lo : 691450548841240133896843047535567 ≤ r131072.toNat := by - dsimp [r131072] - unfold getSqrtRatioAfterBit131072BranchWord - by_cases h : getSqrtRatioBit131072Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 691450548841240133896843047535567 ≤ - 485077512873820763967752669154895175) hr65536lo) - · simpa [h, getSqrtRatioAfterBit131072Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor131072Word r65536 - 485053260817066172746253684029974020 - 485077512873820763967752669154895175 - 691450548841240133896843047535567 - (by native_decide) (by native_decide) hr65536lo hr65536hi (by native_decide) - have hr131072hi : r131072.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r131072] - unfold getSqrtRatioAfterBit131072BranchWord - by_cases h : getSqrtRatioBit131072Word absTick = ⟨0⟩ - · simpa [h] using hr65536hi - · simpa [h, getSqrtRatioAfterBit131072Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor131072Word r65536 - 485053260817066172746253684029974020 - (by native_decide) (by native_decide) hr65536hi - let r262144 := getSqrtRatioAfterBit262144BranchWord absTick r131072 - have hr262144lo : 1404950724947776134837143967 ≤ r262144.toNat := by - dsimp [r262144] - unfold getSqrtRatioAfterBit262144BranchWord - by_cases h : getSqrtRatioBit262144Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 1404950724947776134837143967 ≤ - 691450548841240133896843047535567) hr131072lo) - · simpa [h, getSqrtRatioAfterBit262144Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor262144Word r131072 - 691415978906521570653435304214168 - 691450548841240133896843047535567 - 1404950724947776134837143967 - (by native_decide) (by native_decide) hr131072lo hr131072hi (by native_decide) - have hr262144hi : r262144.toNat ≤ 2 ^ (128 : Nat) := by - dsimp [r262144] - unfold getSqrtRatioAfterBit262144BranchWord - by_cases h : getSqrtRatioBit262144Word absTick = ⟨0⟩ - · simpa [h] using hr131072hi - · simpa [h, getSqrtRatioAfterBit262144Word] using - sqrtRatioStepWord_le_q128 getSqrtRatioFactor262144Word r131072 - 691415978906521570653435304214168 - (by native_decide) (by native_decide) hr131072hi - let r524288 := getSqrtRatioAfterBit524288BranchWord absTick r262144 - have hr524288lo : 5800441176149320 ≤ r524288.toNat := by - dsimp [r524288] - unfold getSqrtRatioAfterBit524288BranchWord - by_cases h : getSqrtRatioBit524288Word absTick = ⟨0⟩ - · simpa [h] using - (le_trans (by native_decide : - 5800441176149320 ≤ 1404950724947776134837143967) hr262144lo) - · simpa [h, getSqrtRatioAfterBit524288Word] using - sqrtRatioStepWord_lb getSqrtRatioFactor524288Word r262144 - 1404880482679654955896180642 - 1404950724947776134837143967 - 5800441176149320 - (by native_decide) (by native_decide) hr262144lo hr262144hi (by native_decide) - change r524288 ≠ ⟨0⟩ - intro hzero - have hz : r524288.toNat = 0 := by - simpa using congrArg UInt256.toNat hzero - have hpos : 0 < r524288.toNat := - lt_of_lt_of_le (by native_decide : 0 < 5800441176149320) hr524288lo - omega - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioReturn.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioReturn.lean deleted file mode 100644 index 8a3b3bd2..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioReturn.lean +++ /dev/null @@ -1,1100 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatioBitsHigh - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def getSqrtRatioTickPosWord (tick : UInt256) : UInt256 := - UInt256.sgt (getSqrtRatioTickInt24Word tick) ⟨0⟩ - -def getSqrtRatioMaxUintWord : UInt256 := - UInt256.lnot (⟨0⟩ : UInt256) - -def getSqrtRatioInvertedWord (ratio : UInt256) : UInt256 := - UInt256.div getSqrtRatioMaxUintWord ratio - -def getSqrtRatioRoundBaseWord : UInt256 := - ⟨4294967296⟩ - -def getSqrtRatioRemainderWord (ratio : UInt256) : UInt256 := - UInt256.mod ratio getSqrtRatioRoundBaseWord - -def getSqrtRatioRoundUpFlagWord (ratio : UInt256) : UInt256 := - UInt256.isZero (UInt256.isZero (getSqrtRatioRemainderWord ratio)) - -def getSqrtRatioReturnAddWord (ratio : UInt256) : UInt256 := - UInt256.land ⟨255⟩ (getSqrtRatioRoundUpFlagWord ratio) - -def getSqrtRatioReturnWord (ratio : UInt256) : UInt256 := - UInt256.shiftRight ratio ⟨32⟩ + getSqrtRatioReturnAddWord ratio - -def getSqrtRatioFinalRatioWord (tick ratio : UInt256) : UInt256 := - if getSqrtRatioTickPosWord tick = ⟨0⟩ then ratio else getSqrtRatioInvertedWord ratio - -def getSqrtRatioTailReturnWord (tick ratio : UInt256) : UInt256 := - getSqrtRatioReturnWord (getSqrtRatioFinalRatioWord tick ratio) - -def getSqrtRatioAfterBit2048BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit2048Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit2048Word ratio - -def getSqrtRatioAfterBit4096BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit4096Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit4096Word ratio - -def getSqrtRatioAfterBit8192BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit8192Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit8192Word ratio - -def getSqrtRatioAfterBit16384BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit16384Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit16384Word ratio - -def getSqrtRatioAfterBit32768BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit32768Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit32768Word ratio - -def getSqrtRatioAfterBit65536BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit65536Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit65536Word ratio - -def getSqrtRatioAfterBit131072BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit131072Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit131072Word ratio - -def getSqrtRatioAfterBit262144BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit262144Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit262144Word ratio - -def getSqrtRatioAfterBit524288BranchWord (absTick ratio : UInt256) : UInt256 := - if getSqrtRatioBit524288Word absTick = ⟨0⟩ then ratio - else getSqrtRatioAfterBit524288Word ratio - -def getSqrtRatioAfterHighBitsWord (absTick ratio : UInt256) : UInt256 := - let r2048 := getSqrtRatioAfterBit2048BranchWord absTick ratio - let r4096 := getSqrtRatioAfterBit4096BranchWord absTick r2048 - let r8192 := getSqrtRatioAfterBit8192BranchWord absTick r4096 - let r16384 := getSqrtRatioAfterBit16384BranchWord absTick r8192 - let r32768 := getSqrtRatioAfterBit32768BranchWord absTick r16384 - let r65536 := getSqrtRatioAfterBit65536BranchWord absTick r32768 - let r131072 := getSqrtRatioAfterBit131072BranchWord absTick r65536 - let r262144 := getSqrtRatioAfterBit262144BranchWord absTick r131072 - getSqrtRatioAfterBit524288BranchWord absTick r262144 - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12402 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12402⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12406 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12406⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12426 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12426⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest12429 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨12429⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest14758 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨14758⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched12402 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12402⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12402 - -theorem uniswapV3PoolJumpDestPatched12406 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12406⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12406 - -theorem uniswapV3PoolJumpDestPatched12426 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12426⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12426 - -theorem uniswapV3PoolJumpDestPatched12429 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨12429⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest12429 - -theorem uniswapV3PoolJumpDestPatched14758 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨14758⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest14758 - --- LIBRARY CANDIDATE: fills the missing generic `RD` wrapper for EVM `MOD`. -private theorem getSqrtRatioModXstep {s : State} {code : ByteArray} - {pcv a b : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.MOD, .none)) - (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 5 then .error .OutOfGass - else .ok (stBinop5 s (UInt256.mod a b) t, .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.MOD, .none) := by - rw [hcode, hpc] - exact hdec - rw [← hcode, step_mod s hd, hstk] - have hov' : ¬ ((a :: b :: t).length - 2 + 1 > 1024) := by - simp only [List.length_cons] - omega - simp only [if_neg hov', GasConstants.Glow, stBinop5] - --- LIBRARY CANDIDATE: fills the missing generic `RD` wrapper for EVM `MOD`. -private theorem getSqrtRatioRDMod {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {pc : UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} {a b : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.MOD, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.mod a b :: t) mem aw rdata acc - (k + 1) (C + 5) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, - hee, hworld⟩ - · exact Or.inl hoog - · have st := getSqrtRatioModXstep hcode hpc hdec hstk hov - by_cases gg : g.toNat < C + 5 - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨stBinop5 s (UInt256.mod a b) t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, - by omega, by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [stBinop5]; exact hcode - · simp only [stBinop5]; rw [hpc] - · rfl - · simp only [stBinop5]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [stBinop5]; exact hmem - · simp only [stBinop5]; exact haw - · simp only [stBinop5]; exact hrdata - · simp only [stBinop5]; exact hacc - · exact hee - · exact hworld - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickHighBits {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12094⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hov : R.length + 7 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12379⟩ - (getSqrtRatioAfterHighBitsWord absTick ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - let r2048 := getSqrtRatioAfterBit2048BranchWord absTick ratio - have h2048 : ∃ k' C', RD code ee g s0 ⟨12126⟩ - (r2048 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit2048Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit2048Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h hbit hov - exact ⟨_, _, by - simpa [r2048, getSqrtRatioAfterBit2048BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit2048Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h hbit hov - exact ⟨_, _, by - simpa [r2048, getSqrtRatioAfterBit2048BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h2048⟩ := h2048 - let r4096 := getSqrtRatioAfterBit4096BranchWord absTick r2048 - have h4096 : ∃ k' C', RD code ee g s0 ⟨12158⟩ - (r4096 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit4096Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit4096Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r2048) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h2048 hbit hov - exact ⟨_, _, by - simpa [r4096, getSqrtRatioAfterBit4096BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit4096Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r2048) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h2048 hbit hov - exact ⟨_, _, by - simpa [r4096, getSqrtRatioAfterBit4096BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h4096⟩ := h4096 - let r8192 := getSqrtRatioAfterBit8192BranchWord absTick r4096 - have h8192 : ∃ k' C', RD code ee g s0 ⟨12190⟩ - (r8192 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit8192Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit8192Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r4096) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h4096 hbit hov - exact ⟨_, _, by - simpa [r8192, getSqrtRatioAfterBit8192BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit8192Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r4096) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h4096 hbit hov - exact ⟨_, _, by - simpa [r8192, getSqrtRatioAfterBit8192BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h8192⟩ := h8192 - let r16384 := getSqrtRatioAfterBit16384BranchWord absTick r8192 - have h16384 : ∃ k' C', RD code ee g s0 ⟨12222⟩ - (r16384 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit16384Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit16384Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r8192) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h8192 hbit hov - exact ⟨_, _, by - simpa [r16384, getSqrtRatioAfterBit16384BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit16384Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r8192) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h8192 hbit hov - exact ⟨_, _, by - simpa [r16384, getSqrtRatioAfterBit16384BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h16384⟩ := h16384 - let r32768 := getSqrtRatioAfterBit32768BranchWord absTick r16384 - have h32768 : ∃ k' C', RD code ee g s0 ⟨12254⟩ - (r32768 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit32768Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit32768Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r16384) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h16384 hbit hov - exact ⟨_, _, by - simpa [r32768, getSqrtRatioAfterBit32768BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit32768Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r16384) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h16384 hbit hov - exact ⟨_, _, by - simpa [r32768, getSqrtRatioAfterBit32768BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h32768⟩ := h32768 - let r65536 := getSqrtRatioAfterBit65536BranchWord absTick r32768 - have h65536 : ∃ k' C', RD code ee g s0 ⟨12287⟩ - (r65536 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit65536Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit65536Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r32768) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h32768 hbit hov - exact ⟨_, _, by - simpa [r65536, getSqrtRatioAfterBit65536BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit65536Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r32768) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h32768 hbit hov - exact ⟨_, _, by - simpa [r65536, getSqrtRatioAfterBit65536BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h65536⟩ := h65536 - let r131072 := getSqrtRatioAfterBit131072BranchWord absTick r65536 - have h131072 : ∃ k' C', RD code ee g s0 ⟨12319⟩ - (r131072 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit131072Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit131072Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r65536) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h65536 hbit hov - exact ⟨_, _, by - simpa [r131072, getSqrtRatioAfterBit131072BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit131072Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r65536) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h65536 hbit hov - exact ⟨_, _, by - simpa [r131072, getSqrtRatioAfterBit131072BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h131072⟩ := h131072 - let r262144 := getSqrtRatioAfterBit262144BranchWord absTick r131072 - have h262144 : ∃ k' C', RD code ee g s0 ⟨12350⟩ - (r262144 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit262144Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit262144Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r131072) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h131072 hbit hov - exact ⟨_, _, by - simpa [r262144, getSqrtRatioAfterBit262144BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit262144Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r131072) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h131072 hbit hov - exact ⟨_, _, by - simpa [r262144, getSqrtRatioAfterBit262144BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h262144⟩ := h262144 - let r524288 := getSqrtRatioAfterBit524288BranchWord absTick r262144 - have h524288 : ∃ k' C', RD code ee g s0 ⟨12379⟩ - (r524288 :: absTick :: ⟨0⟩ :: tick :: ret :: R) mem aw rdata acc k' C' := by - by_cases hbit : getSqrtRatioBit524288Word absTick = ⟨0⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit524288Zero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r262144) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h262144 hbit hov - exact ⟨_, _, by - simpa [r524288, getSqrtRatioAfterBit524288BranchWord, hbit] using hnext⟩ - · obtain ⟨_, _, hnext⟩ := - uniswapV3PoolGetSqrtRatioAtTickBit524288Set (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := r262144) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch h262144 hbit hov - exact ⟨_, _, by - simpa [r524288, getSqrtRatioAfterBit524288BranchWord, hbit] using hnext⟩ - obtain ⟨_, _, h524288⟩ := h524288 - exact ⟨_, _, by - simpa [getSqrtRatioAfterHighBitsWord, r2048, r4096, r8192, r16384, r32768, - r65536, r131072, r262144, r524288] using h524288⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickTickNonPos {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12379⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hpos : getSqrtRatioTickPosWord tick = ⟨0⟩) - (hov : R.length + 8 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12406⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12379 : decode code ⟨12379⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12380 : decode code ⟨12380⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12382 : decode code ⟨12382⟩ = some (.DUP5, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12383 : decode code ⟨12383⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12385 : decode code ⟨12385⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12386 : decode code ⟨12386⟩ = some (.SGT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12387 : decode code ⟨12387⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12388 : decode code ⟨12388⟩ = some (.Push .PUSH2, some (⟨12406⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12391 : decode code ⟨12391⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioTickPosWord tick) ≠ ⟨0⟩ := by - rw [hpos] - native_decide - have rd12380 := by - simpa using h.jumpdest hd12379 (by - simp only [List.length_cons] - omega) - have rd12382 := by - simpa using rd12380.push1 ⟨0⟩ hd12380 (by - simp only [List.length_cons] - omega) - have rd12383 := by - simpa using RD.dup5 rd12382 hd12382 (by - simp only [List.length_cons] - omega) - have rd12385 := by - simpa using rd12383.push1 ⟨2⟩ hd12383 (by - simp only [List.length_cons] - omega) - have rd12386 := by - simpa [getSqrtRatioTickInt24Word] using RD.signextend rd12385 hd12385 (by - simp only [List.length_cons] - omega) - have rd12387 := by - simpa [getSqrtRatioTickPosWord] using rd12386.sgt hd12386 (by - simp only [List.length_cons] - omega) - have rd12388 := by - simpa using rd12387.iszero hd12387 (by - simp only [List.length_cons] - omega) - have rd12391 := by - simpa using rd12388.push2 ⟨12406⟩ hd12388 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12391.jumpiT hd12391 hcond - (uniswapV3PoolJumpDestPatched12406 hpatch) (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickTickPos {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12379⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hpos : getSqrtRatioTickPosWord tick ≠ ⟨0⟩) - (hratio : ratio ≠ ⟨0⟩) - (hov : R.length + 9 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨12406⟩ - (getSqrtRatioInvertedWord ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12379 : decode code ⟨12379⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12380 : decode code ⟨12380⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12382 : decode code ⟨12382⟩ = some (.DUP5, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12383 : decode code ⟨12383⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12385 : decode code ⟨12385⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12386 : decode code ⟨12386⟩ = some (.SGT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12387 : decode code ⟨12387⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12388 : decode code ⟨12388⟩ = some (.Push .PUSH2, some (⟨12406⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12391 : decode code ⟨12391⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12392 : decode code ⟨12392⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12393 : decode code ⟨12393⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12395 : decode code ⟨12395⟩ = some (.NOT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12396 : decode code ⟨12396⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12397 : decode code ⟨12397⟩ = some (.Push .PUSH2, some (⟨12402⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12400 : decode code ⟨12400⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12402 : decode code ⟨12402⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12403 : decode code ⟨12403⟩ = some (.DIV, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12404 : decode code ⟨12404⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12405 : decode code ⟨12405⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hskip : UInt256.isZero (getSqrtRatioTickPosWord tick) = ⟨0⟩ := - isZero_eq_zero_of_ne hpos - have rd12380 := by - simpa using h.jumpdest hd12379 (by - simp only [List.length_cons] - omega) - have rd12382 := by - simpa using rd12380.push1 ⟨0⟩ hd12380 (by - simp only [List.length_cons] - omega) - have rd12383 := by - simpa using RD.dup5 rd12382 hd12382 (by - simp only [List.length_cons] - omega) - have rd12385 := by - simpa using rd12383.push1 ⟨2⟩ hd12383 (by - simp only [List.length_cons] - omega) - have rd12386 := by - simpa [getSqrtRatioTickInt24Word] using RD.signextend rd12385 hd12385 (by - simp only [List.length_cons] - omega) - have rd12387 := by - simpa [getSqrtRatioTickPosWord] using rd12386.sgt hd12386 (by - simp only [List.length_cons] - omega) - have rd12388 := by - simpa using rd12387.iszero hd12387 (by - simp only [List.length_cons] - omega) - have rd12391 := by - simpa using rd12388.push2 ⟨12406⟩ hd12388 (by - simp only [List.length_cons] - omega) - have rd12392 := rd12391.jumpiNT hd12391 hskip (by - simp only [List.length_cons] - omega) - have rd12393 := by - simpa using rd12392.dup1 hd12392 (by - simp only [List.length_cons] - omega) - have rd12395 := by - simpa using rd12393.push1 ⟨0⟩ hd12393 (by - simp only [List.length_cons] - omega) - have rd12396 := by - simpa [getSqrtRatioMaxUintWord] using rd12395.not hd12395 (by - simp only [List.length_cons] - omega) - have rd12397 := by - simpa using rd12396.dup2 hd12396 (by - simp only [List.length_cons] - omega) - have rd12400 := by - simpa using rd12397.push2 ⟨12402⟩ hd12397 (by - simp only [List.length_cons] - omega) - have rd12402 := rd12400.jumpiT hd12400 hratio - (uniswapV3PoolJumpDestPatched12402 hpatch) (by - simp only [List.length_cons] - omega) - have rd12403 := by - simpa using rd12402.jumpdest hd12402 (by - simp only [List.length_cons] - omega) - have rd12404 := by - simpa [getSqrtRatioInvertedWord, getSqrtRatioMaxUintWord] using - rd12403.div hd12403 (by - simp only [List.length_cons] - omega) - have rd12405 := by - simpa using rd12404.swap1 hd12404 (by - simp only [List.length_cons] - omega) - have rd12406 := by - simpa using rd12405.pop hd12405 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, by simpa using rd12406⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickReturnRemainderZero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12406⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hrem : getSqrtRatioRemainderWord ratio = ⟨0⟩) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 8 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret (getSqrtRatioReturnWord ratio :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12406 : decode code ⟨12406⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12407 : decode code ⟨12407⟩ = some (.Push .PUSH5, some (⟨4294967296⟩, 5)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12413 : decode code ⟨12413⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12414 : decode code ⟨12414⟩ = some (.MOD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12415 : decode code ⟨12415⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12416 : decode code ⟨12416⟩ = some (.Push .PUSH2, some (⟨12426⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12419 : decode code ⟨12419⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12426 : decode code ⟨12426⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12427 : decode code ⟨12427⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12429 : decode code ⟨12429⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12430 : decode code ⟨12430⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12432 : decode code ⟨12432⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12433 : decode code ⟨12433⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12435 : decode code ⟨12435⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12436 : decode code ⟨12436⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12437 : decode code ⟨12437⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12438 : decode code ⟨12438⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12439 : decode code ⟨12439⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12440 : decode code ⟨12440⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12441 : decode code ⟨12441⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12442 : decode code ⟨12442⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12443 : decode code ⟨12443⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12444 : decode code ⟨12444⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12445 : decode code ⟨12445⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12446 : decode code ⟨12446⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hcond : UInt256.isZero (getSqrtRatioRemainderWord ratio) ≠ ⟨0⟩ := by - rw [hrem] - native_decide - have hround : - UInt256.land (⟨255⟩ : UInt256) ⟨0⟩ = getSqrtRatioReturnAddWord ratio := by - rw [getSqrtRatioReturnAddWord, getSqrtRatioRoundUpFlagWord, hrem] - native_decide - have rd12407 := by - simpa using h.jumpdest hd12406 (by - simp only [List.length_cons] - omega) - have rd12413 := by - simpa [getSqrtRatioRoundBaseWord] using - rd12407.pushConst (⟨4294967296⟩ : UInt256) - (by native_decide : Operation.POp.PUSH5 ≠ .PUSH0) hd12407 (by - simp only [List.length_cons] - omega) - have rd12414 := by - simpa using rd12413.dup2 hd12413 (by - simp only [List.length_cons] - omega) - have rd12415 := by - simpa [getSqrtRatioRemainderWord, getSqrtRatioRoundBaseWord] using - getSqrtRatioRDMod rd12414 hd12414 (by - simp only [List.length_cons] - omega) - have rd12416 := by - simpa using rd12415.iszero hd12415 (by - simp only [List.length_cons] - omega) - have rd12419 := by - simpa using rd12416.push2 ⟨12426⟩ hd12416 (by - simp only [List.length_cons] - omega) - have rd12426 := rd12419.jumpiT hd12419 hcond - (uniswapV3PoolJumpDestPatched12426 hpatch) (by - simp only [List.length_cons] - omega) - have rd12427 := by - simpa using rd12426.jumpdest hd12426 (by - simp only [List.length_cons] - omega) - have rd12429 := by - simpa using rd12427.push1 ⟨0⟩ hd12427 (by - simp only [List.length_cons] - omega) - have rd12430 := by - simpa using rd12429.jumpdest hd12429 (by - simp only [List.length_cons] - omega) - have rd12432 := by - simpa using rd12430.push1 ⟨255⟩ hd12430 (by - simp only [List.length_cons] - omega) - have rd12433 := by - simpa [hround] using rd12432.and hd12432 (by - simp only [List.length_cons] - omega) - have rd12435 := by - simpa using rd12433.push1 ⟨32⟩ hd12433 (by - simp only [List.length_cons] - omega) - have rd12436 := by - simpa using RD.dup3 rd12435 hd12435 (by - simp only [List.length_cons] - omega) - have rd12437 := by - simpa using rd12436.swap1 hd12436 (by - simp only [List.length_cons] - omega) - have rd12438 := by - simpa using rd12437.shr hd12437 (by - simp only [List.length_cons] - omega) - have rd12439 := by - simpa [getSqrtRatioReturnWord] using rd12438.add hd12438 (by - simp only [List.length_cons] - omega) - have rd12440 := by - simpa using RD.swap3 rd12439 hd12439 (by - simp only [List.length_cons] - omega) - have rd12441 := by - simpa using rd12440.pop hd12440 (by - simp only [List.length_cons] - omega) - have rd12442 := by - simpa using rd12441.pop hd12441 (by - simp only [List.length_cons] - omega) - have rd12443 := by - simpa using rd12442.pop hd12442 (by - simp only [List.length_cons] - omega) - have rd12444 := by - simpa using RD.swap2 rd12443 hd12443 (by - omega) - have rd12445 := by - simpa using rd12444.swap1 hd12444 (by - simp only [List.length_cons] - omega) - have rd12446 := by - simpa using rd12445.pop hd12445 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12446.jump hd12446 hret (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickReturnRemainderNonzero {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12406⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hrem : getSqrtRatioRemainderWord ratio ≠ ⟨0⟩) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 8 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret (getSqrtRatioReturnWord ratio :: R) - mem aw rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 11629 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 13989) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 13989 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointGetSqrtRatioAtTick hlo hhi)] - have hd12406 : decode code ⟨12406⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12407 : decode code ⟨12407⟩ = some (.Push .PUSH5, some (⟨4294967296⟩, 5)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12413 : decode code ⟨12413⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12414 : decode code ⟨12414⟩ = some (.MOD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12415 : decode code ⟨12415⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12416 : decode code ⟨12416⟩ = some (.Push .PUSH2, some (⟨12426⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12419 : decode code ⟨12419⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12420 : decode code ⟨12420⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12422 : decode code ⟨12422⟩ = some (.Push .PUSH2, some (⟨12429⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12425 : decode code ⟨12425⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12429 : decode code ⟨12429⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12430 : decode code ⟨12430⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12432 : decode code ⟨12432⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12433 : decode code ⟨12433⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12435 : decode code ⟨12435⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12436 : decode code ⟨12436⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12437 : decode code ⟨12437⟩ = some (.SHR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12438 : decode code ⟨12438⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12439 : decode code ⟨12439⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12440 : decode code ⟨12440⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12441 : decode code ⟨12441⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12442 : decode code ⟨12442⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12443 : decode code ⟨12443⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12444 : decode code ⟨12444⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12445 : decode code ⟨12445⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd12446 : decode code ⟨12446⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hskip : UInt256.isZero (getSqrtRatioRemainderWord ratio) = ⟨0⟩ := - isZero_eq_zero_of_ne hrem - have hround : - UInt256.land (⟨255⟩ : UInt256) ⟨1⟩ = getSqrtRatioReturnAddWord ratio := by - rw [getSqrtRatioReturnAddWord, getSqrtRatioRoundUpFlagWord, hskip] - native_decide - have rd12407 := by - simpa using h.jumpdest hd12406 (by - simp only [List.length_cons] - omega) - have rd12413 := by - simpa [getSqrtRatioRoundBaseWord] using - rd12407.pushConst (⟨4294967296⟩ : UInt256) - (by native_decide : Operation.POp.PUSH5 ≠ .PUSH0) hd12407 (by - simp only [List.length_cons] - omega) - have rd12414 := by - simpa using rd12413.dup2 hd12413 (by - simp only [List.length_cons] - omega) - have rd12415 := by - simpa [getSqrtRatioRemainderWord, getSqrtRatioRoundBaseWord] using - getSqrtRatioRDMod rd12414 hd12414 (by - simp only [List.length_cons] - omega) - have rd12416 := by - simpa using rd12415.iszero hd12415 (by - simp only [List.length_cons] - omega) - have rd12419 := by - simpa using rd12416.push2 ⟨12426⟩ hd12416 (by - simp only [List.length_cons] - omega) - have rd12420 := rd12419.jumpiNT hd12419 hskip (by - simp only [List.length_cons] - omega) - have rd12422 := by - simpa using rd12420.push1 ⟨1⟩ hd12420 (by - simp only [List.length_cons] - omega) - have rd12425 := by - simpa using rd12422.push2 ⟨12429⟩ hd12422 (by - simp only [List.length_cons] - omega) - have rd12429 := rd12425.jump hd12425 - (uniswapV3PoolJumpDestPatched12429 hpatch) (by - simp only [List.length_cons] - omega) - have rd12430 := by - simpa using rd12429.jumpdest hd12429 (by - simp only [List.length_cons] - omega) - have rd12432 := by - simpa using rd12430.push1 ⟨255⟩ hd12430 (by - simp only [List.length_cons] - omega) - have rd12433 := by - simpa [hround] using rd12432.and hd12432 (by - simp only [List.length_cons] - omega) - have rd12435 := by - simpa using rd12433.push1 ⟨32⟩ hd12433 (by - simp only [List.length_cons] - omega) - have rd12436 := by - simpa using RD.dup3 rd12435 hd12435 (by - simp only [List.length_cons] - omega) - have rd12437 := by - simpa using rd12436.swap1 hd12436 (by - simp only [List.length_cons] - omega) - have rd12438 := by - simpa using rd12437.shr hd12437 (by - simp only [List.length_cons] - omega) - have rd12439 := by - simpa [getSqrtRatioReturnWord] using rd12438.add hd12438 (by - simp only [List.length_cons] - omega) - have rd12440 := by - simpa using RD.swap3 rd12439 hd12439 (by - simp only [List.length_cons] - omega) - have rd12441 := by - simpa using rd12440.pop hd12440 (by - simp only [List.length_cons] - omega) - have rd12442 := by - simpa using rd12441.pop hd12441 (by - simp only [List.length_cons] - omega) - have rd12443 := by - simpa using rd12442.pop hd12442 (by - simp only [List.length_cons] - omega) - have rd12444 := by - simpa using RD.swap2 rd12443 hd12443 (by - omega) - have rd12445 := by - simpa using rd12444.swap1 hd12444 (by - simp only [List.length_cons] - omega) - have rd12446 := by - simpa using rd12445.pop hd12445 (by - simp only [List.length_cons] - omega) - exact ⟨_, _, rd12446.jump hd12446 hret (by - simp only [List.length_cons] - omega)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolGetSqrtRatioAtTickReturnTail {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {ratio absTick tick ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨12379⟩ (ratio :: absTick :: ⟨0⟩ :: tick :: ret :: R) - mem aw rdata acc k C) - (hratio : ratio ≠ ⟨0⟩) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 9 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret (getSqrtRatioTailReturnWord tick ratio :: R) - mem aw rdata acc k' C' := by - by_cases hpos : getSqrtRatioTickPosWord tick = ⟨0⟩ - · obtain ⟨_, _, htail⟩ := - uniswapV3PoolGetSqrtRatioAtTickTickNonPos (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) (rdata := rdata) - (acc := acc) hpatch h hpos (by omega) - by_cases hrem : getSqrtRatioRemainderWord ratio = ⟨0⟩ - · obtain ⟨_, _, hdone⟩ := - uniswapV3PoolGetSqrtRatioAtTickReturnRemainderZero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch htail hrem hret (by omega) - exact ⟨_, _, by - simpa [getSqrtRatioTailReturnWord, getSqrtRatioFinalRatioWord, hpos] using hdone⟩ - · obtain ⟨_, _, hdone⟩ := - uniswapV3PoolGetSqrtRatioAtTickReturnRemainderNonzero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) - (rdata := rdata) (acc := acc) hpatch htail hrem hret (by omega) - exact ⟨_, _, by - simpa [getSqrtRatioTailReturnWord, getSqrtRatioFinalRatioWord, hpos] using hdone⟩ - · obtain ⟨_, _, htail⟩ := - uniswapV3PoolGetSqrtRatioAtTickTickPos (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := ratio) (absTick := absTick) - (tick := tick) (ret := ret) (R := R) (mem := mem) (aw := aw) (rdata := rdata) - (acc := acc) hpatch h hpos hratio hov - by_cases hrem : getSqrtRatioRemainderWord (getSqrtRatioInvertedWord ratio) = ⟨0⟩ - · obtain ⟨_, _, hdone⟩ := - uniswapV3PoolGetSqrtRatioAtTickReturnRemainderZero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := getSqrtRatioInvertedWord ratio) - (absTick := absTick) (tick := tick) (ret := ret) (R := R) (mem := mem) - (aw := aw) (rdata := rdata) (acc := acc) hpatch htail hrem hret (by omega) - exact ⟨_, _, by - simpa [getSqrtRatioTailReturnWord, getSqrtRatioFinalRatioWord, hpos] using hdone⟩ - · obtain ⟨_, _, hdone⟩ := - uniswapV3PoolGetSqrtRatioAtTickReturnRemainderNonzero (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (ratio := getSqrtRatioInvertedWord ratio) - (absTick := absTick) (tick := tick) (ret := ret) (R := R) (mem := mem) - (aw := aw) (rdata := rdata) (acc := acc) hpatch htail hrem hret (by omega) - exact ⟨_, _, by - simpa [getSqrtRatioTailReturnWord, getSqrtRatioFinalRatioWord, hpos] using hdone⟩ - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioSourceBridge.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioSourceBridge.lean deleted file mode 100644 index 0b4c20ea..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickSqrtRatioSourceBridge.lean +++ /dev/null @@ -1,986 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatioNonzero - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem sqrtRatioBitWord_eq_zero_iff_source - (absW : UInt256) (abs : Int) (mask : Nat) (wmask : UInt256) - (habsW : absW = EVM.wordOfInt abs) - (habs0 : 0 ≤ abs) (habsLt : abs < (EVM.wordModulus : Int)) - (hmaskLt : mask < EVM.wordModulus) (hwmask : wmask.toNat = mask) : - (UInt256.land absW wmask = ⟨0⟩) ↔ - getSqrtRatioSourceTickRatioStepBitInt abs (mask : Int) = 0 := by - unfold getSqrtRatioSourceTickRatioStepBitInt - have hto : (UInt256.land absW wmask).toNat = Nat.land abs.toNat mask := by - rw [habsW, u256_land_toNat, wordOfInt_nonneg_toNat_lt_wordModulus _ habs0 habsLt, - hwmask] - have hlandLt : Nat.land abs.toNat mask < UInt256.size := by - exact lt_of_le_of_lt (nat_land_le_right _ _) (by simpa [EVM.wordModulus] using hmaskLt) - exact Nat.mod_eq_of_lt hlandLt - constructor - · intro hzero - have hz := congrArg UInt256.toNat hzero - simpa [hto] using hz - · intro hzero - have hzeroNat : Nat.land abs.toNat mask = 0 := by - simpa using hzero - apply u256_inj - rw [hto, hzeroNat] - rfl - -private theorem sqrtRatioRatioMaskedWord_clean (ratio : UInt256) - (hratio : ratio.toNat ≤ 2 ^ (128 : Nat)) : - getSqrtRatioRatioMaskedWord ratio = ratio := by - apply u256_inj - unfold getSqrtRatioRatioMaskedWord getSqrtRatioUint136Mask - rw [uland_toNat] - rw [show (⟨87112285931760246646623899502532662132735⟩ : UInt256).toNat = - 2 ^ (136 : Nat) - 1 by native_decide] - change Nat.land (2 ^ (136 : Nat) - 1) ratio.toNat = ratio.toNat - rw [nat_land_comm] - rw [nat_land_mask_eq_mod] - have hlt136 : ratio.toNat < 2 ^ (136 : Nat) := by - exact lt_of_le_of_lt hratio (by norm_num) - rw [Nat.mod_eq_of_lt hlt136] - -private theorem sqrtRatioMulShiftWord_eq_source - (ratioW factorW : UInt256) (ratio : Int) (constant : Nat) - (hratioW : ratioW = EVM.wordOfInt ratio) - (hratio0 : 0 ≤ ratio) (hratioLe : ratio ≤ (2 ^ (128 : Nat) : Int)) - (hfactorNat : factorW.toNat = constant) - (hfactorLt : constant < 2 ^ (128 : Nat)) : - UInt256.shiftRight (UInt256.mul factorW ratioW) ⟨128⟩ = - EVM.wordOfInt (((ratio * (constant : Int)).toNat / 2 ^ (128 : Nat) : Nat) : Int) := by - apply u256_inj - have hratioLtWord : ratio < (EVM.wordModulus : Int) := by - norm_num [EVM.wordModulus, EVM.twoPow] at hratioLe ⊢ - omega - have hratioNat : ratioW.toNat = ratio.toNat := by - rw [hratioW, wordOfInt_nonneg_toNat_lt_wordModulus _ hratio0 hratioLtWord] - have hratioNatLe : ratio.toNat ≤ 2 ^ (128 : Nat) := by - simpa using Int.toNat_le_toNat hratioLe - have hratioWLe : ratioW.toNat ≤ 2 ^ (128 : Nat) := by - rw [hratioNat] - exact hratioNatLe - rw [u256_mul_shiftRight128_toNat_of_factor_lt_q128 factorW ratioW] - · rw [hfactorNat, hratioNat, Nat.mul_comm] - have hprodNat : (ratio * (constant : Int)).toNat = ratio.toNat * constant := by - rw [Int.toNat_mul hratio0 (by exact_mod_cast Nat.zero_le constant)] - simp - rw [← hprodNat] - have hquot0 : 0 ≤ (((ratio * (constant : Int)).toNat / 2 ^ (128 : Nat) : Nat) : Int) := by - exact_mod_cast Nat.zero_le _ - have hprodLt : ratio.toNat * constant < EVM.wordModulus := by - have hconstLe : constant ≤ 2 ^ (128 : Nat) - 1 := by omega - have hmulLe : ratio.toNat * constant ≤ 2 ^ (128 : Nat) * - (2 ^ (128 : Nat) - 1) := by - exact Nat.mul_le_mul hratioNatLe hconstLe - norm_num [EVM.wordModulus, EVM.twoPow] at hmulLe ⊢ - omega - have hquotLt : (((ratio * (constant : Int)).toNat / 2 ^ (128 : Nat) : Nat) : Int) < - (EVM.wordModulus : Int) := by - have hle : (ratio * (constant : Int)).toNat / 2 ^ (128 : Nat) ≤ - ratio.toNat * constant := by - rw [hprodNat] - exact Nat.div_le_self _ _ - exact_mod_cast lt_of_le_of_lt hle hprodLt - rw [wordOfInt_nonneg_toNat_lt_wordModulus _ hquot0 hquotLt] - rw [Int.toNat_natCast] - · rw [hfactorNat] - exact hfactorLt - · exact hratioWLe - -private theorem sqrtRatioStepBranchWord_eq_source - (absW ratioW factorW wmask : UInt256) (abs ratio : Int) (mask constant : Nat) - (habsW : absW = EVM.wordOfInt abs) - (habs0 : 0 ≤ abs) (habsLt : abs < (EVM.wordModulus : Int)) - (hratioW : ratioW = EVM.wordOfInt ratio) - (hratio0 : 0 ≤ ratio) (hratioLe : ratio ≤ (2 ^ (128 : Nat) : Int)) - (hmaskLt : mask < EVM.wordModulus) (hwmask : wmask.toNat = mask) - (hfactorNat : factorW.toNat = constant) - (hfactorLt : constant < 2 ^ (128 : Nat)) : - (if UInt256.land absW wmask = ⟨0⟩ then ratioW - else UInt256.shiftRight (UInt256.mul factorW ratioW) ⟨128⟩) = - EVM.wordOfInt (getSqrtRatioSourceTickRatioStepRatioInt abs ratio - (mask : Int) (constant : Int)) := by - have hbit := sqrtRatioBitWord_eq_zero_iff_source absW abs mask wmask habsW habs0 habsLt - hmaskLt hwmask - by_cases hsrc : getSqrtRatioSourceTickRatioStepBitInt abs (mask : Int) = 0 - · rw [if_pos (hbit.mpr hsrc)] - unfold getSqrtRatioSourceTickRatioStepRatioInt - rw [if_pos hsrc] - exact hratioW - · rw [if_neg (fun hzero => hsrc (hbit.mp hzero))] - unfold getSqrtRatioSourceTickRatioStepRatioInt - rw [if_neg hsrc] - exact sqrtRatioMulShiftWord_eq_source ratioW factorW ratio constant hratioW hratio0 hratioLe - hfactorNat hfactorLt - -private theorem getSqrtRatioInitialBranchWord_tickHi_eq_source (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) - (hhiWord : getTickHiWord I = EVM.wordOfInt (getTickSourceTickHiInt I)) : - getSqrtRatioInitialBranchWord (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) = - EVM.wordOfInt (getSqrtRatioSourceTickHiInitialRatioInt I) := by - let absW := getSqrtRatioAbsTickBranchWord (getTickHiWord I) - let abs := getSqrtRatioSourceTickHiAbsTickInt I - have habsW : absW = EVM.wordOfInt abs := by - dsimp [absW, abs] - exact getSqrtRatioAbsTickBranchWord_tickHi_eq_source_abs I hlo hhi hhiWord - have habs0 : 0 ≤ abs := by - dsimp [abs] - exact getSqrtRatioSourceTickHiAbsTickInt_nonneg I - have habsLt : abs < (EVM.wordModulus : Int) := by - dsimp [abs] - exact getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I - (getSqrtRatioSourceTickHiAbsTickInt_le_maxTick I hlo hhi) - have hbit := sqrtRatioBitWord_eq_zero_iff_source absW abs 1 (⟨1⟩ : UInt256) - habsW habs0 habsLt (by norm_num [EVM.wordModulus, EVM.twoPow]) (by native_decide) - unfold getSqrtRatioInitialBranchWord getSqrtRatioBit1Word - getSqrtRatioSourceTickHiInitialRatioInt getSqrtRatioSourceTickHiBit1Int - by_cases hsrc : getSqrtRatioSourceTickRatioStepBitInt abs (1 : Int) = 0 - · rw [if_pos (hbit.mpr hsrc)] - have hsrcI : getSqrtRatioSourceTickHiBit1Int I = 0 := by - simpa [abs, getSqrtRatioSourceTickHiBit1Int, - getSqrtRatioSourceTickRatioStepBitInt] using hsrc - have hsrcRaw : - ((getSqrtRatioSourceTickHiAbsTickInt I).toNat.land 1 : Int) = 0 := by - simpa [getSqrtRatioSourceTickHiBit1Int] using hsrcI - rw [if_pos hsrcRaw] - native_decide - · rw [if_neg (fun hzero => hsrc (hbit.mp hzero))] - have hsrcI : getSqrtRatioSourceTickHiBit1Int I ≠ 0 := by - intro hzero - exact hsrc (by - simpa [abs, getSqrtRatioSourceTickHiBit1Int, - getSqrtRatioSourceTickRatioStepBitInt] using hzero) - have hsrcRaw : - ((getSqrtRatioSourceTickHiAbsTickInt I).toNat.land 1 : Int) ≠ 0 := by - intro hzero - exact hsrcI (by simpa [getSqrtRatioSourceTickHiBit1Int] using hzero) - rw [if_neg hsrcRaw] - native_decide - -private theorem getSqrtRatioInitialBranchWord_le_q128 (absTick : UInt256) : - (getSqrtRatioInitialBranchWord absTick).toNat ≤ 2 ^ (128 : Nat) := by - unfold getSqrtRatioInitialBranchWord - by_cases h : getSqrtRatioBit1Word absTick = ⟨0⟩ - · simp [h, getSqrtRatioInitialEvenWord] - native_decide - · simp [h, getSqrtRatioInitialOddWord] - native_decide - -private theorem getSqrtRatioAfterAllBitsWord_tickHi_eq_source (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) - (hhiWord : getTickHiWord I = EVM.wordOfInt (getTickSourceTickHiInt I)) : - getSqrtRatioAfterAllBitsWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I)) - (getSqrtRatioInitialBranchWord - (getSqrtRatioAbsTickBranchWord (getTickHiWord I))) = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit524288Int I) := by - let absW := getSqrtRatioAbsTickBranchWord (getTickHiWord I) - let r0 := getSqrtRatioInitialBranchWord absW - let r2 := getSqrtRatioAfterBit2BranchWord absW r0 - let r4 := getSqrtRatioAfterBit4BranchWord absW r2 - let r8 := getSqrtRatioAfterBit8BranchWord absW r4 - let r16 := getSqrtRatioAfterBit16BranchWord absW r8 - let r32 := getSqrtRatioAfterBit32BranchWord absW r16 - let r64 := getSqrtRatioAfterBit64BranchWord absW r32 - let r128 := getSqrtRatioAfterBit128BranchWord absW r64 - let r256 := getSqrtRatioAfterBit256BranchWord absW r128 - let r512 := getSqrtRatioAfterBit512BranchWord absW r256 - let r1024 := getSqrtRatioAfterBit1024BranchWord absW r512 - let r2048 := getSqrtRatioAfterBit2048BranchWord absW r1024 - let r4096 := getSqrtRatioAfterBit4096BranchWord absW r2048 - let r8192 := getSqrtRatioAfterBit8192BranchWord absW r4096 - let r16384 := getSqrtRatioAfterBit16384BranchWord absW r8192 - let r32768 := getSqrtRatioAfterBit32768BranchWord absW r16384 - let r65536 := getSqrtRatioAfterBit65536BranchWord absW r32768 - let r131072 := getSqrtRatioAfterBit131072BranchWord absW r65536 - let r262144 := getSqrtRatioAfterBit262144BranchWord absW r131072 - let r524288 := getSqrtRatioAfterBit524288BranchWord absW r262144 - have habsW : absW = EVM.wordOfInt (getSqrtRatioSourceTickHiAbsTickInt I) := by - dsimp [absW] - exact getSqrtRatioAbsTickBranchWord_tickHi_eq_source_abs I hlo hhi hhiWord - have habs0 : 0 ≤ getSqrtRatioSourceTickHiAbsTickInt I := - getSqrtRatioSourceTickHiAbsTickInt_nonneg I - have habsLt : getSqrtRatioSourceTickHiAbsTickInt I < (EVM.wordModulus : Int) := - getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I - (getSqrtRatioSourceTickHiAbsTickInt_le_maxTick I hlo hhi) - have hstage (ratioW factorW wmask : UInt256) (ratio : Int) (mask constant : Nat) - (hratioW : ratioW = EVM.wordOfInt ratio) - (hratio0 : 0 ≤ ratio) (hratioLe : ratio ≤ (2 ^ (128 : Nat) : Int)) - (hmaskLt : mask < EVM.wordModulus) (hwmask : wmask.toNat = mask) - (hfactorNat : factorW.toNat = constant) (hfactorLt : constant < 2 ^ (128 : Nat)) : - (if UInt256.land absW wmask = ⟨0⟩ then ratioW - else UInt256.shiftRight (UInt256.mul factorW ratioW) ⟨128⟩) = - EVM.wordOfInt (getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) ratio (mask : Int) (constant : Int)) := - sqrtRatioStepBranchWord_eq_source absW ratioW factorW wmask - (getSqrtRatioSourceTickHiAbsTickInt I) ratio mask constant - habsW habs0 habsLt hratioW hratio0 hratioLe - hmaskLt hwmask hfactorNat hfactorLt - have hr0 : r0 = EVM.wordOfInt (getSqrtRatioSourceTickHiInitialRatioInt I) := by - dsimp [r0, absW] - exact getSqrtRatioInitialBranchWord_tickHi_eq_source I hlo hhi hhiWord - have hr0m : getSqrtRatioRatioMaskedWord r0 = - EVM.wordOfInt (getSqrtRatioSourceTickHiInitialRatioInt I) := by - rw [sqrtRatioRatioMaskedWord_clean r0 (getSqrtRatioInitialBranchWord_le_q128 absW), hr0] - have hr2 : r2 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit2Int I) := by - simpa [r2, getSqrtRatioAfterBit2BranchWord, getSqrtRatioAfterBit2Word, - getSqrtRatioBit2Word, getSqrtRatioFactor2Word, getSqrtRatioSourceTickHiAfterBit2Int, - getSqrtRatioSourceFactor2Int] using - hstage (getSqrtRatioRatioMaskedWord r0) getSqrtRatioFactor2Word (⟨2⟩ : UInt256) - (getSqrtRatioSourceTickHiInitialRatioInt I) 2 - 340248342086729790484326174814286782778 - hr0m (getSqrtRatioSourceTickHiInitialRatioInt_nonneg I) - (getSqrtRatioSourceTickHiInitialRatioInt_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr4 : r4 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit4Int I) := by - simpa [r4, getSqrtRatioAfterBit4BranchWord, getSqrtRatioAfterBit4Word, - getSqrtRatioBit4Word, getSqrtRatioFactor4Word, getSqrtRatioSourceTickHiAfterBit4Int, - getSqrtRatioSourceFactor4Int] using - hstage r2 getSqrtRatioFactor4Word - (⟨4⟩ : UInt256) (getSqrtRatioSourceTickHiAfterBit2Int I) 4 - 340214320654664324051920982716015181260 - hr2 (getSqrtRatioSourceTickHiAfterBit2Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit2Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr8 : r8 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit8Int I) := by - simpa [r8, getSqrtRatioAfterBit8BranchWord, getSqrtRatioAfterBit8Word, - getSqrtRatioBit8Word, getSqrtRatioFactor8Word, getSqrtRatioSourceTickHiAfterBit8Int, - getSqrtRatioSourceFactor8Int] using - hstage r4 getSqrtRatioFactor8Word (⟨8⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit4Int I) 8 - 340146287995602323631171512101879684304 - hr4 (getSqrtRatioSourceTickHiAfterBit4Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit4Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr16 : r16 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit16Int I) := by - simpa [r16, getSqrtRatioAfterBit16BranchWord, getSqrtRatioAfterBit16Word, - getSqrtRatioBit16Word, getSqrtRatioFactor16Word, - getSqrtRatioSourceTickHiAfterBit16Int, getSqrtRatioSourceFactor16Int] using - hstage r8 getSqrtRatioFactor16Word (⟨16⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit8Int I) 16 - 340010263488231146823593991679159461444 - hr8 (getSqrtRatioSourceTickHiAfterBit8Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit8Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr32 : r32 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit32Int I) := by - simpa [r32, getSqrtRatioAfterBit32BranchWord, getSqrtRatioAfterBit32Word, - getSqrtRatioBit32Word, getSqrtRatioFactor32Word, - getSqrtRatioSourceTickHiAfterBit32Int, getSqrtRatioSourceFactor32Int] using - hstage r16 getSqrtRatioFactor32Word (⟨32⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit16Int I) 32 - 339738377640345403697157401104375502016 - hr16 (getSqrtRatioSourceTickHiAfterBit16Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit16Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr64 : r64 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit64Int I) := by - simpa [r64, getSqrtRatioAfterBit64BranchWord, getSqrtRatioAfterBit64Word, - getSqrtRatioBit64Word, getSqrtRatioFactor64Word, - getSqrtRatioSourceTickHiAfterBit64Int, getSqrtRatioSourceFactor64Int] using - hstage r32 getSqrtRatioFactor64Word (⟨64⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit32Int I) 64 - 339195258003219555707034227454543997025 - hr32 (getSqrtRatioSourceTickHiAfterBit32Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit32Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr128 : r128 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit128Int I) := by - simpa [r128, getSqrtRatioAfterBit128BranchWord, getSqrtRatioAfterBit128Word, - getSqrtRatioBit128Word, getSqrtRatioFactor128Word, - getSqrtRatioSourceTickHiAfterBit128Int, getSqrtRatioSourceFactor128Int] using - hstage r64 getSqrtRatioFactor128Word (⟨128⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit64Int I) 128 - 338111622100601834656805679988414885971 - hr64 (getSqrtRatioSourceTickHiAfterBit64Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit64Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr256 : r256 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit256Int I) := by - simpa [r256, getSqrtRatioAfterBit256BranchWord, getSqrtRatioAfterBit256Word, - getSqrtRatioBit256Word, getSqrtRatioFactor256Word, - getSqrtRatioSourceTickHiAfterBit256Int, getSqrtRatioSourceFactor256Int] using - hstage r128 getSqrtRatioFactor256Word (⟨256⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit128Int I) 256 - 335954724994790223023589805789778977700 - hr128 (getSqrtRatioSourceTickHiAfterBit128Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit128Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr512 : r512 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit512Int I) := by - simpa [r512, getSqrtRatioAfterBit512BranchWord, getSqrtRatioAfterBit512Word, - getSqrtRatioBit512Word, getSqrtRatioFactor512Word, - getSqrtRatioSourceTickHiAfterBit512Int, getSqrtRatioSourceFactor512Int] using - hstage r256 getSqrtRatioFactor512Word (⟨512⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit256Int I) 512 - 331682121138379247127172139078559817300 - hr256 (getSqrtRatioSourceTickHiAfterBit256Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit256Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr1024 : r1024 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit1024Int I) := by - simpa [r1024, getSqrtRatioAfterBit1024BranchWord, getSqrtRatioAfterBit1024Word, - getSqrtRatioBit1024Word, getSqrtRatioFactor1024Word, - getSqrtRatioSourceTickHiAfterBit1024Int, getSqrtRatioSourceFactor1024Int] using - hstage r512 getSqrtRatioFactor1024Word (⟨1024⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit512Int I) 1024 - 323299236684853023288211250268160618739 - hr512 (getSqrtRatioSourceTickHiAfterBit512Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit512Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr2048 : r2048 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit2048Int I) := by - simpa [r2048, getSqrtRatioAfterBit2048BranchWord, getSqrtRatioAfterBit2048Word, - getSqrtRatioBit2048Word, getSqrtRatioFactor2048Word, - getSqrtRatioSourceTickHiAfterBit2048Int, getSqrtRatioSourceFactor2048Int] using - hstage r1024 getSqrtRatioFactor2048Word (⟨2048⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit1024Int I) 2048 - 307163716377032989948697243942600083929 - hr1024 (getSqrtRatioSourceTickHiAfterBit1024Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit1024Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr4096 : r4096 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit4096Int I) := by - simpa [r4096, getSqrtRatioAfterBit4096BranchWord, getSqrtRatioAfterBit4096Word, - getSqrtRatioBit4096Word, getSqrtRatioFactor4096Word, - getSqrtRatioSourceTickHiAfterBit4096Int, getSqrtRatioSourceFactor4096Int] using - hstage r2048 getSqrtRatioFactor4096Word (⟨4096⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit2048Int I) 4096 - 277268403626896220162999269216087595045 - hr2048 (getSqrtRatioSourceTickHiAfterBit2048Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit2048Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr8192 : r8192 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit8192Int I) := by - simpa [r8192, getSqrtRatioAfterBit8192BranchWord, getSqrtRatioAfterBit8192Word, - getSqrtRatioBit8192Word, getSqrtRatioFactor8192Word, - getSqrtRatioSourceTickHiAfterBit8192Int, getSqrtRatioSourceFactor8192Int] using - hstage r4096 getSqrtRatioFactor8192Word (⟨8192⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit4096Int I) 8192 - 225923453940442621947126027127485391333 - hr4096 (getSqrtRatioSourceTickHiAfterBit4096Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit4096Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr16384 : r16384 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit16384Int I) := by - simpa [r16384, getSqrtRatioAfterBit16384BranchWord, getSqrtRatioAfterBit16384Word, - getSqrtRatioBit16384Word, getSqrtRatioFactor16384Word, - getSqrtRatioSourceTickHiAfterBit16384Int, getSqrtRatioSourceFactor16384Int] using - hstage r8192 getSqrtRatioFactor16384Word (⟨16384⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit8192Int I) 16384 - 149997214084966997727330242082538205943 - hr8192 (getSqrtRatioSourceTickHiAfterBit8192Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit8192Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr32768 : r32768 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit32768Int I) := by - simpa [r32768, getSqrtRatioAfterBit32768BranchWord, getSqrtRatioAfterBit32768Word, - getSqrtRatioBit32768Word, getSqrtRatioFactor32768Word, - getSqrtRatioSourceTickHiAfterBit32768Int, getSqrtRatioSourceFactor32768Int] using - hstage r16384 getSqrtRatioFactor32768Word (⟨32768⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit16384Int I) 32768 - 66119101136024775622716233608466517926 - hr16384 (getSqrtRatioSourceTickHiAfterBit16384Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit16384Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr65536 : r65536 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit65536Int I) := by - simpa [r65536, getSqrtRatioAfterBit65536BranchWord, getSqrtRatioAfterBit65536Word, - getSqrtRatioBit65536Word, getSqrtRatioFactor65536Word, - getSqrtRatioSourceTickHiAfterBit65536Int, getSqrtRatioSourceFactor65536Int] using - hstage r32768 getSqrtRatioFactor65536Word (⟨65536⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit32768Int I) 65536 - 12847376061809297530290974190478138313 - hr32768 (getSqrtRatioSourceTickHiAfterBit32768Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit32768Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr131072 : r131072 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit131072Int I) := by - simpa [r131072, getSqrtRatioAfterBit131072BranchWord, getSqrtRatioAfterBit131072Word, - getSqrtRatioBit131072Word, getSqrtRatioFactor131072Word, - getSqrtRatioSourceTickHiAfterBit131072Int, getSqrtRatioSourceFactor131072Int] using - hstage r65536 getSqrtRatioFactor131072Word (⟨131072⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit65536Int I) 131072 - 485053260817066172746253684029974020 - hr65536 (getSqrtRatioSourceTickHiAfterBit65536Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit65536Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr262144 : r262144 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit262144Int I) := by - simpa [r262144, getSqrtRatioAfterBit262144BranchWord, getSqrtRatioAfterBit262144Word, - getSqrtRatioBit262144Word, getSqrtRatioFactor262144Word, - getSqrtRatioSourceTickHiAfterBit262144Int, getSqrtRatioSourceFactor262144Int] using - hstage r131072 getSqrtRatioFactor262144Word (⟨262144⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit131072Int I) 262144 - 691415978906521570653435304214168 - hr131072 (getSqrtRatioSourceTickHiAfterBit131072Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit131072Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - have hr524288 : r524288 = - EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit524288Int I) := by - simpa [r524288, getSqrtRatioAfterBit524288BranchWord, getSqrtRatioAfterBit524288Word, - getSqrtRatioBit524288Word, getSqrtRatioFactor524288Word, - getSqrtRatioSourceTickHiAfterBit524288Int, getSqrtRatioSourceFactor524288Int] using - hstage r262144 getSqrtRatioFactor524288Word (⟨524288⟩ : UInt256) - (getSqrtRatioSourceTickHiAfterBit262144Int I) 524288 - 1404880482679654955896180642 - hr262144 (getSqrtRatioSourceTickHiAfterBit262144Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit262144Int_le_q128 I) - (by native_decide) (by native_decide) (by native_decide) (by native_decide) - simpa [getSqrtRatioAfterAllBitsWord, getSqrtRatioAfterLowBitsWord, - getSqrtRatioAfterHighBitsWord, absW, r0, r2, r4, r8, r16, r32, r64, r128, r256, - r512, r1024, r2048, r4096, r8192, r16384, r32768, r65536, r131072, r262144, - r524288] using hr524288 - -private theorem sgt_wordOfInt_int24_zero (i : Int) - (hge : -(2 ^ 23 : Int) ≤ i) (hlt : i < 2 ^ 23) : - UInt256.sgt (EVM.wordOfInt i) ⟨0⟩ = if 0 < i then ⟨1⟩ else ⟨0⟩ := by - by_cases hpos : 0 < i - · rw [if_pos hpos] - have h0 : 0 ≤ i := by omega - rw [wordOfInt_nonneg i h0] - apply sgt_lit_one (m := 0) - · norm_num - · unfold EVM.word EVM.uintN UInt256.toNat - simp only - rw [Nat.mod_eq_of_lt] - · omega - · exact lt_trans ((Int.toNat_lt h0).2 hlt) (by norm_num [EVM.twoPow]) - · unfold EVM.word EVM.uintN UInt256.toNat - simp only - rw [Nat.mod_eq_of_lt] - · exact lt_trans ((Int.toNat_lt h0).2 hlt) (by norm_num) - · exact lt_trans ((Int.toNat_lt h0).2 hlt) (by norm_num [EVM.twoPow]) - · rw [if_neg hpos] - by_cases hneg : i < 0 - · have hto := wordOfInt_neg_toNat_lt_wordModulus i hneg (by - have hle : i.natAbs ≤ EVM.twoPow 23 := by - have habs : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [EVM.twoPow] at hge ⊢ - omega - exact lt_of_le_of_lt hle (by native_decide : EVM.twoPow 23 < EVM.wordModulus)) - unfold UInt256.sgt UInt256.sgtBool UInt256.fromBool Bool.toUInt256 - rw [hto] - have hhigh : UInt256.size - i.natAbs ≥ 2 ^ (255 : Nat) := by - have hle : i.natAbs ≤ 2 ^ 23 := by - have habs : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - norm_num at hge ⊢ - omega - have hposAbs : 0 < i.natAbs := Int.natAbs_pos.mpr (by omega) - norm_num [UInt256.size] at hle ⊢ - omega - rw [if_pos hhigh] - change (if (if false then decide (EVM.wordOfInt i > (⟨0⟩ : UInt256)) else false) = true - then UInt256.ofNat 1 else UInt256.ofNat 0) = (⟨0⟩ : UInt256) - rfl - · have hi0 : i = 0 := by omega - rw [hi0] - native_decide - -private theorem maxUint_div_toNat_eq (ratio : Int) - (hratio0 : 0 ≤ ratio) (hden : ratio ≠ 0) : - (EVM.wordModulus - 1) / ratio.toNat = - ((2 ^ (256 : Nat) - 1 : Int) / ratio).toNat := by - have hratioPos : 0 < ratio := lt_of_le_of_ne hratio0 (Ne.symm hden) - apply Int.ofNat.inj - change (((EVM.wordModulus - 1) / ratio.toNat : Nat) : Int) = - (((2 ^ (256 : Nat) - 1 : Int) / ratio).toNat : Int) - rw [Int.natCast_ediv] - have hdivNonneg : 0 ≤ ((2 ^ (256 : Nat) - 1 : Int) / ratio) := by - exact Int.ediv_nonneg (by norm_num) (by omega) - rw [Int.toNat_of_nonneg hdivNonneg] - norm_num [EVM.wordModulus, EVM.twoPow] - rw [max_eq_left hratio0] - -private theorem int_toNat_div_pow32_eq (ratio : Int) (hratio0 : 0 ≤ ratio) : - ratio.toNat / 2 ^ (32 : Nat) = (ratio / (2 ^ (32 : Nat) : Int)).toNat := by - apply Int.ofNat.inj - change ((ratio.toNat / 2 ^ (32 : Nat) : Nat) : Int) = - ((ratio / (2 ^ (32 : Nat) : Int)).toNat : Int) - rw [Int.natCast_ediv] - have hdivNonneg : 0 ≤ ratio / (2 ^ (32 : Nat) : Int) := by - exact Int.ediv_nonneg hratio0 (by norm_num) - rw [Int.toNat_of_nonneg hdivNonneg] - rw [Int.toNat_of_nonneg hratio0] - norm_num - -private theorem getSqrtRatioFinalRatioWord_tickHi_eq_source - (I : ExecutionEnv) (ratioW : UInt256) (ratio : Int) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) - (hhiWord : getTickHiWord I = EVM.wordOfInt (getTickSourceTickHiInt I)) - (hratioW : ratioW = EVM.wordOfInt ratio) - (hratio0 : 0 ≤ ratio) (hratioLe : ratio ≤ (2 ^ (128 : Nat) : Int)) - (hden : ratio ≠ 0) : - getSqrtRatioFinalRatioWord (getTickHiWord I) ratioW = - EVM.wordOfInt (getSqrtRatioSourceFinalRatioIntOf (getTickSourceTickHiInt I) ratio) := by - have hb := getTickSourceTickHiInt_int24_bounds I hlo hhi - have htickPos : getSqrtRatioTickPosWord (getTickHiWord I) = - if 0 < getTickSourceTickHiInt I then ⟨1⟩ else ⟨0⟩ := by - unfold getSqrtRatioTickPosWord getSqrtRatioTickInt24Word - rw [hhiWord] - rw [signextend_two_wordOfInt_tickSpacing (getTickSourceTickHiInt I) hb.1 hb.2] - exact sgt_wordOfInt_int24_zero (getTickSourceTickHiInt I) hb.1 hb.2 - have hratioLtWord : ratio < (EVM.wordModulus : Int) := by - norm_num [EVM.wordModulus, EVM.twoPow] at hratioLe ⊢ - omega - by_cases hpos : 0 < getTickSourceTickHiInt I - · unfold getSqrtRatioFinalRatioWord - rw [htickPos, if_pos hpos] - rw [if_neg (by native_decide : (⟨1⟩ : UInt256) ≠ (⟨0⟩ : UInt256))] - unfold getSqrtRatioInvertedWord getSqrtRatioMaxUintWord - apply u256_inj - rw [udiv_toNat] - have hratioNat : ratioW.toNat = ratio.toNat := by - rw [hratioW, wordOfInt_nonneg_toNat_lt_wordModulus _ hratio0 hratioLtWord] - rw [hratioNat] - rw [show (UInt256.lnot (⟨0⟩ : UInt256)).toNat = EVM.wordModulus - 1 by - native_decide] - have hfinal0 : 0 ≤ getSqrtRatioSourceFinalRatioIntOf (getTickSourceTickHiInt I) ratio := - getSqrtRatioSourceFinalRatioIntOf_nonneg _ _ hratio0 - have hfinalLt : getSqrtRatioSourceFinalRatioIntOf (getTickSourceTickHiInt I) ratio < - (EVM.wordModulus : Int) := - getSqrtRatioSourceFinalRatioIntOf_lt_wordModulus _ _ hratioLtWord - rw [wordOfInt_nonneg_toNat_lt_wordModulus _ hfinal0 hfinalLt] - unfold getSqrtRatioSourceFinalRatioIntOf - rw [if_pos hpos] - exact maxUint_div_toNat_eq ratio hratio0 hden - · unfold getSqrtRatioFinalRatioWord - rw [htickPos, if_neg hpos] - rw [if_pos (by native_decide : (⟨0⟩ : UInt256) = (⟨0⟩ : UInt256))] - unfold getSqrtRatioSourceFinalRatioIntOf - rw [if_neg hpos] - exact hratioW - -private theorem getSqrtRatioReturnAddWord_toNat_zero - (ratioW : UInt256) (n : Nat) (hn : ratioW.toNat = n) - (hrem : n % 2 ^ (32 : Nat) = 0) : - (getSqrtRatioReturnAddWord ratioW).toNat = 0 := by - have hremToNat : (getSqrtRatioRemainderWord ratioW).toNat = n % 2 ^ (32 : Nat) := by - unfold getSqrtRatioRemainderWord getSqrtRatioRoundBaseWord UInt256.mod - rw [show ((⟨4294967296⟩ : UInt256).val == 0) = false by native_decide] - change ratioW.toNat % 4294967296 = n % 2 ^ (32 : Nat) - rw [hn] - norm_num - have hremWord : getSqrtRatioRemainderWord ratioW = ⟨0⟩ := by - apply u256_inj - rw [hremToNat, hrem] - rfl - unfold getSqrtRatioReturnAddWord getSqrtRatioRoundUpFlagWord - rw [hremWord] - native_decide - -private theorem getSqrtRatioReturnAddWord_toNat_one - (ratioW : UInt256) (n : Nat) (hn : ratioW.toNat = n) - (hrem : n % 2 ^ (32 : Nat) ≠ 0) : - (getSqrtRatioReturnAddWord ratioW).toNat = 1 := by - have hremToNat : (getSqrtRatioRemainderWord ratioW).toNat = n % 2 ^ (32 : Nat) := by - unfold getSqrtRatioRemainderWord getSqrtRatioRoundBaseWord UInt256.mod - rw [show ((⟨4294967296⟩ : UInt256).val == 0) = false by native_decide] - change ratioW.toNat % 4294967296 = n % 2 ^ (32 : Nat) - rw [hn] - norm_num - have hremWord : getSqrtRatioRemainderWord ratioW ≠ ⟨0⟩ := by - intro hzero - have hz := congrArg UInt256.toNat hzero - rw [hremToNat] at hz - exact hrem hz - unfold getSqrtRatioReturnAddWord getSqrtRatioRoundUpFlagWord - by_cases hz : getSqrtRatioRemainderWord ratioW = ⟨0⟩ - · exact False.elim (hremWord hz) - · have hisZero : UInt256.isZero (getSqrtRatioRemainderWord ratioW) = ⟨0⟩ := by - unfold UInt256.isZero UInt256.eq0 UInt256.fromBool Bool.toUInt256 - simp [hz] - rfl - rw [hisZero] - native_decide - -private theorem getSqrtRatioReturnWord_eq_source - (ratioW : UInt256) (ratio : Int) - (hratioW : ratioW = EVM.wordOfInt ratio) - (hratio0 : 0 ≤ ratio) (hratioLt : ratio < (EVM.wordModulus : Int)) : - getSqrtRatioReturnWord ratioW = EVM.wordOfInt (getSqrtRatioSourceReturnIntOf ratio) := by - apply u256_inj - have hratioNat : ratioW.toNat = ratio.toNat := by - rw [hratioW, wordOfInt_nonneg_toNat_lt_wordModulus _ hratio0 hratioLt] - unfold getSqrtRatioReturnWord getSqrtRatioSourceReturnIntOf - rw [uadd_toNat] - unfold UInt256.shiftRight - rw [if_neg (by decide : ¬ (⟨32⟩ : UInt256).val ≥ 256)] - unfold UInt256.toNat - rw [Fin.shiftRight_val, Nat.shiftRight_eq_div_pow] - change (ratioW.toNat / 2 ^ (32 : Nat) + (getSqrtRatioReturnAddWord ratioW).toNat) % - UInt256.size = - (EVM.wordOfInt - (↑(ratio.toNat / 2 ^ (32 : Nat)) + - if (Value.int (ratio % (2 ^ (32 : Nat) : Int)) == Value.int 0) = true then 0 - else 1)).toNat - rw [hratioNat] - have hsumLt0 : ratio.toNat / 2 ^ (32 : Nat) + 1 < EVM.wordModulus := by - have hratioNatLt : ratio.toNat < EVM.wordModulus := (Int.toNat_lt hratio0).2 hratioLt - have hratioLt256 : ratio.toNat < 2 ^ (256 : Nat) := by - simpa [EVM.wordModulus, EVM.twoPow] using hratioNatLt - have hdivLt : ratio.toNat / 2 ^ (32 : Nat) < 2 ^ (224 : Nat) := by - rw [Nat.div_lt_iff_lt_mul (by norm_num : 0 < 2 ^ (32 : Nat))] - simpa [Nat.pow_add] using hratioLt256 - exact lt_trans (Nat.succ_lt_succ hdivLt) (by norm_num [EVM.wordModulus, EVM.twoPow]) - by_cases hrem : ratio.toNat % 2 ^ (32 : Nat) = 0 - · have hmodInt : ratio % (2 ^ (32 : Nat) : Int) = 0 := by - have hto : (ratio % (2 ^ (32 : Nat) : Int)).toNat = 0 := by - rw [Int.toNat_emod hratio0 (by norm_num : 0 ≤ (2 ^ (32 : Nat) : Int))] - exact hrem - have hnonneg : 0 ≤ ratio % (2 ^ (32 : Nat) : Int) := - Int.emod_nonneg ratio (by norm_num) - omega - have hadd := getSqrtRatioReturnAddWord_toNat_zero ratioW ratio.toNat hratioNat hrem - have hbeq : (Value.int (ratio % (2 ^ (32 : Nat) : Int)) == Value.int 0) = true := by - rw [hmodInt] - native_decide - rw [hadd, hbeq] - simp only [if_true, add_zero] - have hbaseLt : ratio.toNat / 2 ^ (32 : Nat) < EVM.wordModulus := by - exact lt_of_le_of_lt (Nat.div_le_self _ _) ((Int.toNat_lt hratio0).2 hratioLt) - rw [Nat.mod_eq_of_lt] - · rw [wordOfInt_nonneg_toNat_lt_wordModulus _ - (by positivity : 0 ≤ ((ratio.toNat / 2 ^ (32 : Nat) : Nat) : Int)) - (by exact_mod_cast hbaseLt)] - rw [Int.toNat_natCast] - · simpa [UInt256.size, EVM.wordModulus] using hbaseLt - · have hmodIntNe : ratio % (2 ^ (32 : Nat) : Int) ≠ 0 := by - intro hmod - apply hrem - have hto := congrArg Int.toNat hmod - rw [Int.toNat_emod hratio0 (by norm_num : 0 ≤ (2 ^ (32 : Nat) : Int))] at hto - simpa using hto - have hadd := getSqrtRatioReturnAddWord_toNat_one ratioW ratio.toNat hratioNat hrem - have hbeq : (Value.int (ratio % (2 ^ (32 : Nat) : Int)) == Value.int 0) = false := by - cases h : (Value.int (ratio % (2 ^ (32 : Nat) : Int)) == Value.int 0) <;> simp_all - rw [hadd, hbeq] - simp only [Bool.false_eq_true, if_false] - rw [Nat.mod_eq_of_lt] - · rw [wordOfInt_nonneg_toNat_lt_wordModulus _ - (by positivity : 0 ≤ ((ratio.toNat / 2 ^ (32 : Nat) : Nat) + 1 : Int)) - (by exact_mod_cast hsumLt0)] - norm_num - rw [max_eq_left hratio0] - change ratio.toNat / 2 ^ (32 : Nat) + 1 = - (ratio / (2 ^ (32 : Nat) : Int) + 1).toNat - have hdivNonneg : 0 ≤ ratio / (2 ^ (32 : Nat) : Int) := by - exact Int.ediv_nonneg hratio0 (by norm_num) - rw [Int.toNat_add hdivNonneg (by norm_num : 0 ≤ (1 : Int))] - rw [int_toNat_div_pow32_eq ratio hratio0] - norm_num - · simpa [UInt256.size, EVM.wordModulus] using hsumLt0 - -private theorem getSqrtRatioSourceReturnIntOf_nonneg (ratio : Int) : - 0 ≤ getSqrtRatioSourceReturnIntOf ratio := by - unfold getSqrtRatioSourceReturnIntOf - split <;> positivity - -private theorem getSqrtRatioSourceReturnIntOf_lt_wordModulus (ratio : Int) - (hratio0 : 0 ≤ ratio) (hratioLt : ratio < (EVM.wordModulus : Int)) : - getSqrtRatioSourceReturnIntOf ratio < (EVM.wordModulus : Int) := by - unfold getSqrtRatioSourceReturnIntOf - have hratioNatLt : ratio.toNat < EVM.wordModulus := (Int.toNat_lt hratio0).2 hratioLt - have hle : ratio.toNat / 2 ^ (32 : Nat) ≤ ratio.toNat := Nat.div_le_self _ _ - split <;> norm_num [EVM.wordModulus, EVM.twoPow] at * <;> omega - -private def sqrtRatioStepIntByNat (abs : Nat) (ratio : Int) (mask constant : Int) : Int := - if ((Nat.land abs mask.toNat : Nat) : Int) = 0 then ratio - else ((ratio * constant).toNat / 2 ^ (128 : Nat) : Nat) - -private def sqrtRatioAfterAllIntByNat (abs : Nat) : Int := - let r0 := - if ((Nat.land abs 1 : Nat) : Int) = 0 then (2 ^ (128 : Nat) : Int) - else (340265354078544963557816517032075149313 : Int) - let r2 := sqrtRatioStepIntByNat abs r0 2 340248342086729790484326174814286782778 - let r4 := sqrtRatioStepIntByNat abs r2 4 340214320654664324051920982716015181260 - let r8 := sqrtRatioStepIntByNat abs r4 8 340146287995602323631171512101879684304 - let r16 := sqrtRatioStepIntByNat abs r8 16 340010263488231146823593991679159461444 - let r32 := sqrtRatioStepIntByNat abs r16 32 339738377640345403697157401104375502016 - let r64 := sqrtRatioStepIntByNat abs r32 64 339195258003219555707034227454543997025 - let r128 := sqrtRatioStepIntByNat abs r64 128 338111622100601834656805679988414885971 - let r256 := sqrtRatioStepIntByNat abs r128 256 335954724994790223023589805789778977700 - let r512 := sqrtRatioStepIntByNat abs r256 512 331682121138379247127172139078559817300 - let r1024 := sqrtRatioStepIntByNat abs r512 1024 323299236684853023288211250268160618739 - let r2048 := sqrtRatioStepIntByNat abs r1024 2048 307163716377032989948697243942600083929 - let r4096 := sqrtRatioStepIntByNat abs r2048 4096 277268403626896220162999269216087595045 - let r8192 := sqrtRatioStepIntByNat abs r4096 8192 225923453940442621947126027127485391333 - let r16384 := sqrtRatioStepIntByNat abs r8192 16384 149997214084966997727330242082538205943 - let r32768 := sqrtRatioStepIntByNat abs r16384 32768 66119101136024775622716233608466517926 - let r65536 := sqrtRatioStepIntByNat abs r32768 65536 12847376061809297530290974190478138313 - let r131072 := sqrtRatioStepIntByNat abs r65536 131072 485053260817066172746253684029974020 - let r262144 := sqrtRatioStepIntByNat abs r131072 262144 691415978906521570653435304214168 - let r524288 := sqrtRatioStepIntByNat abs r262144 524288 1404880482679654955896180642 - r524288 - -private theorem getSqrtRatioSourceTickHiAfterBit524288Int_eq_reflected (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit524288Int I = - sqrtRatioAfterAllIntByNat (getSqrtRatioSourceTickHiAbsTickInt I).toNat := by - unfold getSqrtRatioSourceTickHiAfterBit524288Int getSqrtRatioSourceTickHiAfterBit262144Int - getSqrtRatioSourceTickHiAfterBit131072Int getSqrtRatioSourceTickHiAfterBit65536Int - getSqrtRatioSourceTickHiAfterBit32768Int getSqrtRatioSourceTickHiAfterBit16384Int - getSqrtRatioSourceTickHiAfterBit8192Int getSqrtRatioSourceTickHiAfterBit4096Int - getSqrtRatioSourceTickHiAfterBit2048Int getSqrtRatioSourceTickHiAfterBit1024Int - getSqrtRatioSourceTickHiAfterBit512Int getSqrtRatioSourceTickHiAfterBit256Int - getSqrtRatioSourceTickHiAfterBit128Int getSqrtRatioSourceTickHiAfterBit64Int - getSqrtRatioSourceTickHiAfterBit32Int getSqrtRatioSourceTickHiAfterBit16Int - getSqrtRatioSourceTickHiAfterBit8Int getSqrtRatioSourceTickHiAfterBit4Int - getSqrtRatioSourceTickHiAfterBit2Int getSqrtRatioSourceTickHiInitialRatioInt - getSqrtRatioSourceTickHiBit1Int getSqrtRatioSourceTickRatioStepRatioInt - getSqrtRatioSourceTickRatioStepBitInt sqrtRatioAfterAllIntByNat sqrtRatioStepIntByNat - getSqrtRatioSourceFactor2Int getSqrtRatioSourceFactor4Int getSqrtRatioSourceFactor8Int - getSqrtRatioSourceFactor16Int getSqrtRatioSourceFactor32Int getSqrtRatioSourceFactor64Int - getSqrtRatioSourceFactor128Int getSqrtRatioSourceFactor256Int getSqrtRatioSourceFactor512Int - getSqrtRatioSourceFactor1024Int getSqrtRatioSourceFactor2048Int - getSqrtRatioSourceFactor4096Int getSqrtRatioSourceFactor8192Int - getSqrtRatioSourceFactor16384Int getSqrtRatioSourceFactor32768Int - getSqrtRatioSourceFactor65536Int getSqrtRatioSourceFactor131072Int - getSqrtRatioSourceFactor262144Int getSqrtRatioSourceFactor524288Int - rfl - -private theorem sqrtRatioAfterAllIntByNat_range_lower : - ((List.range 887273).all fun n => - 2 ^ (64 : Nat) < (sqrtRatioAfterAllIntByNat n).toNat) = true := by - native_decide - -private theorem sqrtRatioAfterAllIntByNat_lower_of_le_max (n : Nat) (hn : n ≤ 887272) : - 2 ^ (64 : Nat) < (sqrtRatioAfterAllIntByNat n).toNat := by - have hnmem : n ∈ List.range 887273 := by - rw [List.mem_range] - omega - have hdecide := List.all_eq_true.mp sqrtRatioAfterAllIntByNat_range_lower n hnmem - exact of_decide_eq_true hdecide - -private theorem getSqrtRatioSourceTickHiAfterBit524288Int_gt_q64 (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - (2 ^ (64 : Nat) : Int) < getSqrtRatioSourceTickHiAfterBit524288Int I := by - rw [getSqrtRatioSourceTickHiAfterBit524288Int_eq_reflected I] - have hnatLe : (getSqrtRatioSourceTickHiAbsTickInt I).toNat ≤ 887272 := by - exact Int.toNat_le_toNat (getSqrtRatioSourceTickHiAbsTickInt_le_maxTick I hlo hhi) - exact Int.lt_toNat.mp (sqrtRatioAfterAllIntByNat_lower_of_le_max _ hnatLe) - -private theorem getSqrtRatioSourceFinalRatioIntOf_lt_return_bound - (tick ratio : Int) (hratioLe : ratio ≤ (2 ^ (128 : Nat) : Int)) - (hratioGt : (2 ^ (64 : Nat) : Int) < ratio) : - getSqrtRatioSourceFinalRatioIntOf tick ratio < - (((2 ^ (160 : Nat) - 1) * 2 ^ (32 : Nat) : Nat) : Int) := by - unfold getSqrtRatioSourceFinalRatioIntOf - by_cases hpos : 0 < tick - · rw [if_pos hpos] - let bound : Int := (((2 ^ (160 : Nat) - 1) * 2 ^ (32 : Nat) : Nat) : Int) - have hdenPos : 0 < ratio := lt_trans (by norm_num) hratioGt - have hdenGe : ((2 ^ (64 : Nat) + 1 : Nat) : Int) ≤ ratio := by - omega - have hbase : (2 ^ (256 : Nat) - 1 : Int) < - bound * ((2 ^ (64 : Nat) + 1 : Nat) : Int) := by - native_decide - have hmulLe : bound * ((2 ^ (64 : Nat) + 1 : Nat) : Int) ≤ bound * ratio := by - exact Int.mul_le_mul_of_nonneg_left hdenGe (by dsimp [bound]; norm_num) - exact Int.ediv_lt_of_lt_mul hdenPos (lt_of_lt_of_le hbase hmulLe) - · rw [if_neg hpos] - exact lt_of_le_of_lt hratioLe (by native_decide) - -private theorem getSqrtRatioSourceTickHiFinalRatioInt_lt_return_bound (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - getSqrtRatioSourceTickHiFinalRatioInt I < - (((2 ^ (160 : Nat) - 1) * 2 ^ (32 : Nat) : Nat) : Int) := by - unfold getSqrtRatioSourceTickHiFinalRatioInt - exact getSqrtRatioSourceFinalRatioIntOf_lt_return_bound - (getTickSourceTickHiInt I) - (getSqrtRatioSourceTickHiAfterBit524288Int I) - (getSqrtRatioSourceTickHiAfterBit524288Int_le_q128 I) - (getSqrtRatioSourceTickHiAfterBit524288Int_gt_q64 I hlo hhi) - -private theorem getSqrtRatioSourceReturnIntOf_lt_twoPow160_of_ratio_lt_return_bound - (ratio : Int) (hratio0 : 0 ≤ ratio) - (hratioLt : - ratio < (((2 ^ (160 : Nat) - 1) * 2 ^ (32 : Nat) : Nat) : Int)) : - getSqrtRatioSourceReturnIntOf ratio < (2 ^ (160 : Nat) : Int) := by - unfold getSqrtRatioSourceReturnIntOf - have hratioNatLt : ratio.toNat < (2 ^ (160 : Nat) - 1) * 2 ^ (32 : Nat) := by - exact (Int.toNat_lt hratio0).2 hratioLt - have hdivLtPred : ratio.toNat / 2 ^ (32 : Nat) < 2 ^ (160 : Nat) - 1 := by - rw [Nat.div_lt_iff_lt_mul (by norm_num : 0 < 2 ^ (32 : Nat))] - simpa using hratioNatLt - by_cases hbeq : (Value.int (ratio % (2 ^ (32 : Nat) : Int)) == Value.int 0) = true - · rw [if_pos hbeq] - have hdivLt : ratio.toNat / 2 ^ (32 : Nat) < 2 ^ (160 : Nat) := by - omega - exact_mod_cast hdivLt - · rw [if_neg hbeq] - have hsuccLt : ratio.toNat / 2 ^ (32 : Nat) + 1 < 2 ^ (160 : Nat) := by - omega - exact_mod_cast hsuccLt - -theorem getSqrtRatioSourceTickHiReturnValue_eq_word (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - getSqrtRatioSourceReturnValueOf (getSqrtRatioSourceTickHiFinalRatioInt I) = - getTickSourceSqrtRatioAtTickHiValue I := by - have hhiWord := getTickHiWord_eq_source_of_bounds I hlo hhi - let absW := getSqrtRatioAbsTickBranchWord (getTickHiWord I) - let r0 := getSqrtRatioInitialBranchWord absW - let rAll := getSqrtRatioAfterAllBitsWord absW r0 - have hAll : rAll = EVM.wordOfInt (getSqrtRatioSourceTickHiAfterBit524288Int I) := by - dsimp [rAll, r0, absW] - exact getSqrtRatioAfterAllBitsWord_tickHi_eq_source I hlo hhi hhiWord - have hFinal : getSqrtRatioFinalRatioWord (getTickHiWord I) rAll = - EVM.wordOfInt (getSqrtRatioSourceTickHiFinalRatioInt I) := by - simpa [getSqrtRatioSourceTickHiFinalRatioInt] using - getSqrtRatioFinalRatioWord_tickHi_eq_source I rAll - (getSqrtRatioSourceTickHiAfterBit524288Int I) hlo hhi hhiWord hAll - (getSqrtRatioSourceTickHiAfterBit524288Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit524288Int_le_q128 I) - (getSqrtRatioSourceTickHiAfterBit524288Int_ne_zero I) - have hfinal0 : 0 ≤ getSqrtRatioSourceTickHiFinalRatioInt I := by - unfold getSqrtRatioSourceTickHiFinalRatioInt - exact getSqrtRatioSourceFinalRatioIntOf_nonneg _ _ - (getSqrtRatioSourceTickHiAfterBit524288Int_nonneg I) - have hratioLt : getSqrtRatioSourceTickHiAfterBit524288Int I < (EVM.wordModulus : Int) := by - exact lt_of_le_of_lt (getSqrtRatioSourceTickHiAfterBit524288Int_le_q128 I) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - have hfinalLt : getSqrtRatioSourceTickHiFinalRatioInt I < (EVM.wordModulus : Int) := by - unfold getSqrtRatioSourceTickHiFinalRatioInt - exact getSqrtRatioSourceFinalRatioIntOf_lt_wordModulus _ _ hratioLt - have hReturn := getSqrtRatioReturnWord_eq_source - (getSqrtRatioFinalRatioWord (getTickHiWord I) rAll) - (getSqrtRatioSourceTickHiFinalRatioInt I) hFinal hfinal0 hfinalLt - have hReturnNat := congrArg UInt256.toNat hReturn - rw [wordOfInt_nonneg_toNat_lt_wordModulus _ - (getSqrtRatioSourceReturnIntOf_nonneg (getSqrtRatioSourceTickHiFinalRatioInt I)) - (getSqrtRatioSourceReturnIntOf_lt_wordModulus (getSqrtRatioSourceTickHiFinalRatioInt I) - hfinal0 hfinalLt)] at hReturnNat - unfold getSqrtRatioSourceReturnValueOf getTickSourceSqrtRatioAtTickHiValue - unfold getTickHiSqrtRatioWord getSqrtRatioAtTickResultWord getSqrtRatioTailReturnWord - dsimp [absW, r0, rAll] at hReturnNat - rw [hReturnNat] - apply congrArg Value.int - exact (Int.toNat_of_nonneg - (getSqrtRatioSourceReturnIntOf_nonneg (getSqrtRatioSourceTickHiFinalRatioInt I))).symm - -private theorem getTickHiSqrtRatioWord_toNat_lt_twoPow160 (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - (getTickHiSqrtRatioWord I).toNat < 2 ^ (160 : Nat) := by - have hret := getSqrtRatioSourceTickHiReturnValue_eq_word I hlo hhi - have hretInt : - getSqrtRatioSourceReturnIntOf (getSqrtRatioSourceTickHiFinalRatioInt I) = - Int.ofNat (getTickHiSqrtRatioWord I).toNat := by - unfold getSqrtRatioSourceReturnValueOf getTickSourceSqrtRatioAtTickHiValue at hret - exact Value.int.inj hret - have hfinal0 : 0 ≤ getSqrtRatioSourceTickHiFinalRatioInt I := by - unfold getSqrtRatioSourceTickHiFinalRatioInt - exact getSqrtRatioSourceFinalRatioIntOf_nonneg _ _ - (getSqrtRatioSourceTickHiAfterBit524288Int_nonneg I) - have hretLt : - getSqrtRatioSourceReturnIntOf (getSqrtRatioSourceTickHiFinalRatioInt I) < - (2 ^ (160 : Nat) : Int) := by - exact getSqrtRatioSourceReturnIntOf_lt_twoPow160_of_ratio_lt_return_bound - (getSqrtRatioSourceTickHiFinalRatioInt I) hfinal0 - (getSqrtRatioSourceTickHiFinalRatioInt_lt_return_bound I hlo hhi) - rw [hretInt] at hretLt - exact Int.ofNat_lt.mp hretLt - -private theorem getTickHiSqrtRatioCleanWord_eq_self (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - getTickHiSqrtRatioCleanWord (getTickHiSqrtRatioWord I) = getTickHiSqrtRatioWord I := by - unfold getTickHiSqrtRatioCleanWord - rw [u256_land_comm] - exact slot0Uint160Mask_clean (getTickHiSqrtRatioWord_toNat_lt_twoPow160 I hlo hhi) - -theorem getTickSourceFinalValue_eq_initializeTickValue (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - getTickSourceFinalValue I = initializeTickValue I := by - have hlowWord := getTickLowWord_eq_source_of_bounds I hlo hhi - have hhiWord := getTickHiWord_eq_source_of_bounds I hlo hhi - have hlowValue := getTickSourceTickLowValue_eq_wordToElem_of_word I hlo hhi hlowWord - have hhiValue := getTickSourceTickHiValue_eq_wordToElem_of_word I hlo hhi hhiWord - have hclean := getTickHiSqrtRatioCleanWord_eq_self I hlo hhi - by_cases heq : getTickSourceTickLowInt I = getTickSourceTickHiInt I - · have hsourceEq : getTickSourceTickLowValue I = getTickSourceTickHiValue I := by - unfold getTickSourceTickLowValue getTickSourceTickHiValue - rw [heq] - have hsourceBeq : - (getTickSourceTickLowValue I == getTickSourceTickHiValue I) = true := by - simp [hsourceEq] - have hwordEq := getTickLowEqHiWord_eq_one_of_source_eq I hlowWord hhiWord heq - have hinit : initializeTickValue I = wordToElem (.int int24Int) (getTickLowWord I) := by - unfold initializeTickValue getTickEstimatedWord - rw [hwordEq] - rw [if_neg (by native_decide : ¬ ((⟨1⟩ : UInt256) = (⟨0⟩ : UInt256)))] - unfold getTickSourceFinalValue - rw [hsourceBeq, hinit] - exact hlowValue - · have hsourceBeq : - (getTickSourceTickLowValue I == getTickSourceTickHiValue I) = false := by - unfold getTickSourceTickLowValue getTickSourceTickHiValue - cases h : (Value.int (getTickSourceTickLowInt I) == - Value.int (getTickSourceTickHiInt I)) <;> simp_all - have hwordEq := getTickLowEqHiWord_eq_zero_of_source_ne I hlo hhi hlowWord hhiWord heq - unfold getTickSourceFinalValue - rw [hsourceBeq] - by_cases hle : - Int.ofNat (getTickHiSqrtRatioWord I).toNat ≤ - Int.ofNat (initializeArgWord I).toNat - · rw [if_pos hle] - have hgt0 : - UInt256.gt (getTickHiSqrtRatioCleanWord (getTickHiSqrtRatioWord I)) - (initializeArgWord I) = ⟨0⟩ := by - rw [hclean] - exact ugt_zero (Int.ofNat_le.mp hle) - have hinit : initializeTickValue I = wordToElem (.int int24Int) (getTickHiWord I) := by - unfold initializeTickValue getTickEstimatedWord getTickAfterHiSqrtRatioWord - getTickHiSqrtRatioGtInputWord - rw [hwordEq] - rw [if_pos (by native_decide : (⟨0⟩ : UInt256) = (⟨0⟩ : UInt256))] - rw [hgt0] - rw [if_pos (by native_decide : (⟨0⟩ : UInt256) = (⟨0⟩ : UInt256))] - rw [hinit] - exact hhiValue - · rw [if_neg hle] - have hgt1 : - UInt256.gt (getTickHiSqrtRatioCleanWord (getTickHiSqrtRatioWord I)) - (initializeArgWord I) = ⟨1⟩ := by - rw [hclean] - exact ugt_one (by - have hnotNat : - ¬ (getTickHiSqrtRatioWord I).toNat ≤ (initializeArgWord I).toNat := by - intro hnat - exact hle (Int.ofNat_le.mpr hnat) - omega) - have hinit : initializeTickValue I = wordToElem (.int int24Int) (getTickLowWord I) := by - unfold initializeTickValue getTickEstimatedWord getTickAfterHiSqrtRatioWord - getTickHiSqrtRatioGtInputWord - rw [hwordEq] - rw [if_pos (by native_decide : (⟨0⟩ : UInt256) = (⟨0⟩ : UInt256))] - rw [hgt1] - rw [if_neg (by native_decide : ¬ ((⟨1⟩ : UInt256) = (⟨0⟩ : UInt256)))] - rw [hinit] - exact hlowValue - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeGetTickWordBridge.lean b/Benchmarks/UniswapV3Pool/InitializeGetTickWordBridge.lean deleted file mode 100644 index 123aee2e..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeGetTickWordBridge.lean +++ /dev/null @@ -1,1839 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTickLogCombine -import Benchmarks.UniswapV3Pool.InitializeSourceGetTickPostLog -import Benchmarks.UniswapV3Pool.TickSpacing - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem nat_land_shifted_uint160_mask (n : Nat) (hn : n < 2 ^ (160 : Nat)) : - Nat.land (n * 2 ^ (32 : Nat)) ((2 ^ (160 : Nat) - 1) * 2 ^ (32 : Nat)) = - n * 2 ^ (32 : Nat) := by - rw [show n * 2 ^ (32 : Nat) = n <<< 32 by rw [Nat.shiftLeft_eq]] - rw [show (2 ^ (160 : Nat) - 1) * 2 ^ (32 : Nat) = - (2 ^ (160 : Nat) - 1) <<< 32 by rw [Nat.shiftLeft_eq]] - apply Nat.eq_of_testBit_eq - intro i - change (((n <<< 32) &&& ((2 ^ (160 : Nat) - 1) <<< 32)).testBit i) = - (n <<< 32).testBit i - rw [Nat.testBit_and, testBit_shiftLeft, testBit_shiftLeft] - by_cases hi32 : i < 32 - · simp [hi32] - · rw [if_neg hi32, if_neg hi32] - by_cases hi160 : i - 32 < 160 - · have hmask : (2 ^ (160 : Nat) - 1).testBit (i - 32) = true := by - rw [Nat.testBit_two_pow_sub_one, decide_eq_true hi160] - rw [hmask, Bool.and_true] - · have hmask : (2 ^ (160 : Nat) - 1).testBit (i - 32) = false := by - rw [Nat.testBit_two_pow_sub_one, decide_eq_false hi160] - have hnbit : n.testBit (i - 32) = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hn (Nat.pow_le_pow_right (by norm_num) (by omega))) - rw [hmask, hnbit] - rfl - -theorem getTickRatioWord_toNat_eq_source (I : ExecutionEnv) : - (getTickRatioWord I).toNat = getTickSourceRatioNat I := by - unfold getTickRatioWord getTickSourceRatioNat getTickRatioMask - rw [u256_land_toNat] - have hshift : - (UInt256.shiftLeft (initializeArgWord I) ⟨32⟩).toNat = - (initializeArgWord I).toNat * 2 ^ (32 : Nat) := by - unfold UInt256.shiftLeft - rw [if_neg (by decide : ¬ (⟨32⟩ : UInt256).val ≥ 256)] - unfold UInt256.toNat - rw [Fin.shiftLeft_val] - change ((initializeArgWord I).toNat <<< 32) % UInt256.size = - (initializeArgWord I).toNat * 2 ^ (32 : Nat) - rw [Nat.shiftLeft_eq] - rw [Nat.mod_eq_of_lt] - have harg := initializeArgWord_toNat_lt_twoPow160 I - have hmul := Nat.mul_lt_mul_of_pos_right harg (by norm_num : 0 < 2 ^ (32 : Nat)) - rw [← Nat.pow_add] at hmul - norm_num [UInt256.size] at hmul ⊢ - exact lt_trans hmul (by norm_num [UInt256.size]) - rw [hshift] - rw [show (⟨6277101735386680763835789423207666416102355444459739545600⟩ : - UInt256).toNat = (2 ^ (160 : Nat) - 1) * 2 ^ (32 : Nat) by native_decide] - rw [nat_land_shifted_uint160_mask] - rw [show EVM.wordModulus = UInt256.size by native_decide] - exact initializeArgWord_toNat_lt_twoPow160 I - -private theorem shiftRight_toNat_of_lt_256 (w s : UInt256) (hs : s.toNat < 256) : - (UInt256.shiftRight w s).toNat = w.toNat / 2 ^ s.toNat := by - unfold UInt256.shiftRight - rw [if_neg] - · unfold UInt256.toNat - rw [Fin.shiftRight_val, Nat.shiftRight_eq_div_pow] - · exact not_le_of_gt hs - -private theorem shiftLeft_toNat_of_lt_256 (w s : UInt256) (hs : s.toNat < 256) : - (UInt256.shiftLeft w s).toNat = w.toNat * 2 ^ s.toNat % UInt256.size := by - unfold UInt256.shiftLeft - rw [if_neg] - · unfold UInt256.toNat - rw [Fin.shiftLeft_val, Nat.shiftLeft_eq] - · exact not_le_of_gt hs - -theorem getTickMsbF7Word_toNat_eq_source (I : ExecutionEnv) : - (getTickMsbF7Word I).toNat = getTickSourceMsbF7Nat I := by - unfold getTickMsbF7Word getTickSourceMsbF7Nat getTickSourceRatioGt7 - have hthreshold : - getTickMsbThreshold7.toNat = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF := by - native_decide - by_cases hgt : getTickSourceRatioNat I > 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - · have hgtWord : UInt256.gt (getTickRatioWord I) getTickMsbThreshold7 = ⟨1⟩ := by - exact ugt_one (by - rw [getTickRatioWord_toNat_eq_source I, hthreshold] - exact hgt) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨7⟩).toNat = 128 by native_decide] - rw [decide_eq_true hgt] - norm_num - · have hgtWord : UInt256.gt (getTickRatioWord I) getTickMsbThreshold7 = ⟨0⟩ := by - exact ugt_zero (by - rw [getTickRatioWord_toNat_eq_source I, hthreshold] - omega) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨0⟩ : UInt256) ⟨7⟩).toNat = 0 by native_decide] - rw [decide_eq_false hgt] - norm_num - -theorem getTickRAfterMsb7Word_toNat_eq_source (I : ExecutionEnv) : - (getTickRAfterMsb7Word I).toNat = getTickSourceRAfterMsb7Nat I := by - unfold getTickRAfterMsb7Word getTickSourceRAfterMsb7Nat - rw [shiftRight_toNat_of_lt_256] - · rw [getTickRatioWord_toNat_eq_source I, getTickMsbF7Word_toNat_eq_source I] - · rw [getTickMsbF7Word_toNat_eq_source I] - unfold getTickSourceMsbF7Nat - split <;> norm_num - -theorem getTickMsbF6Word_toNat_eq_source (I : ExecutionEnv) : - (getTickMsbF6Word I).toNat = getTickSourceMsbF6Nat I := by - unfold getTickMsbF6Word getTickSourceMsbF6Nat getTickSourceRAfterMsb7Gt6 - have hthreshold : getTickMsbThreshold6.toNat = 0xFFFFFFFFFFFFFFFF := by - native_decide - by_cases hgt : getTickSourceRAfterMsb7Nat I > 0xFFFFFFFFFFFFFFFF - · have hgtWord : UInt256.gt (getTickRAfterMsb7Word I) getTickMsbThreshold6 = ⟨1⟩ := by - exact ugt_one (by - rw [getTickRAfterMsb7Word_toNat_eq_source I, hthreshold] - exact hgt) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨6⟩).toNat = 64 by native_decide] - rw [decide_eq_true hgt] - norm_num - · have hgtWord : UInt256.gt (getTickRAfterMsb7Word I) getTickMsbThreshold6 = ⟨0⟩ := by - exact ugt_zero (by - rw [getTickRAfterMsb7Word_toNat_eq_source I, hthreshold] - omega) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨0⟩ : UInt256) ⟨6⟩).toNat = 0 by native_decide] - rw [decide_eq_false hgt] - norm_num - -theorem getTickRAfterMsb6Word_toNat_eq_source (I : ExecutionEnv) : - (getTickRAfterMsb6Word I).toNat = getTickSourceRAfterMsb6Nat I := by - unfold getTickRAfterMsb6Word getTickSourceRAfterMsb6Nat - rw [shiftRight_toNat_of_lt_256] - · rw [getTickRAfterMsb7Word_toNat_eq_source I, getTickMsbF6Word_toNat_eq_source I] - · rw [getTickMsbF6Word_toNat_eq_source I] - unfold getTickSourceMsbF6Nat - split <;> norm_num - -theorem getTickMsbF5Word_toNat_eq_source (I : ExecutionEnv) : - (getTickMsbF5Word I).toNat = getTickSourceMsbF5Nat I := by - unfold getTickMsbF5Word getTickSourceMsbF5Nat getTickSourceRAfterMsb6Gt5 - have hthreshold : getTickMsbThreshold5.toNat = 0xFFFFFFFF := by - native_decide - by_cases hgt : getTickSourceRAfterMsb6Nat I > 0xFFFFFFFF - · have hgtWord : UInt256.gt (getTickRAfterMsb6Word I) getTickMsbThreshold5 = ⟨1⟩ := by - exact ugt_one (by - rw [getTickRAfterMsb6Word_toNat_eq_source I, hthreshold] - exact hgt) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨5⟩).toNat = 32 by native_decide] - rw [decide_eq_true hgt] - norm_num - · have hgtWord : UInt256.gt (getTickRAfterMsb6Word I) getTickMsbThreshold5 = ⟨0⟩ := by - exact ugt_zero (by - rw [getTickRAfterMsb6Word_toNat_eq_source I, hthreshold] - omega) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨0⟩ : UInt256) ⟨5⟩).toNat = 0 by native_decide] - rw [decide_eq_false hgt] - norm_num - -theorem getTickRAfterMsb5Word_toNat_eq_source (I : ExecutionEnv) : - (getTickRAfterMsb5Word I).toNat = getTickSourceRAfterMsb5Nat I := by - unfold getTickRAfterMsb5Word getTickSourceRAfterMsb5Nat - rw [shiftRight_toNat_of_lt_256] - · rw [getTickRAfterMsb6Word_toNat_eq_source I, getTickMsbF5Word_toNat_eq_source I] - · rw [getTickMsbF5Word_toNat_eq_source I] - unfold getTickSourceMsbF5Nat - split <;> norm_num - -theorem getTickMsbF4Word_toNat_eq_source (I : ExecutionEnv) : - (getTickMsbF4Word I).toNat = getTickSourceMsbF4Nat I := by - unfold getTickMsbF4Word getTickSourceMsbF4Nat getTickSourceRAfterMsb5Gt4 - have hthreshold : getTickMsbThreshold4.toNat = 0xFFFF := by - native_decide - by_cases hgt : getTickSourceRAfterMsb5Nat I > 0xFFFF - · have hgtWord : UInt256.gt (getTickRAfterMsb5Word I) getTickMsbThreshold4 = ⟨1⟩ := by - exact ugt_one (by - rw [getTickRAfterMsb5Word_toNat_eq_source I, hthreshold] - exact hgt) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨4⟩).toNat = 16 by native_decide] - rw [decide_eq_true hgt] - norm_num - · have hgtWord : UInt256.gt (getTickRAfterMsb5Word I) getTickMsbThreshold4 = ⟨0⟩ := by - exact ugt_zero (by - rw [getTickRAfterMsb5Word_toNat_eq_source I, hthreshold] - omega) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨0⟩ : UInt256) ⟨4⟩).toNat = 0 by native_decide] - rw [decide_eq_false hgt] - norm_num - -theorem getTickRAfterMsb4Word_toNat_eq_source (I : ExecutionEnv) : - (getTickRAfterMsb4Word I).toNat = getTickSourceRAfterMsb4Nat I := by - unfold getTickRAfterMsb4Word getTickSourceRAfterMsb4Nat - rw [shiftRight_toNat_of_lt_256] - · rw [getTickRAfterMsb5Word_toNat_eq_source I, getTickMsbF4Word_toNat_eq_source I] - · rw [getTickMsbF4Word_toNat_eq_source I] - unfold getTickSourceMsbF4Nat - split <;> norm_num - -theorem getTickMsbF3Word_toNat_eq_source (I : ExecutionEnv) : - (getTickMsbF3Word I).toNat = getTickSourceMsbF3Nat I := by - unfold getTickMsbF3Word getTickSourceMsbF3Nat getTickSourceRAfterMsb4Gt3 - have hthreshold : getTickMsbThreshold3.toNat = 0xFF := by - native_decide - by_cases hgt : getTickSourceRAfterMsb4Nat I > 0xFF - · have hgtWord : UInt256.gt (getTickRAfterMsb4Word I) getTickMsbThreshold3 = ⟨1⟩ := by - exact ugt_one (by - rw [getTickRAfterMsb4Word_toNat_eq_source I, hthreshold] - exact hgt) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨3⟩).toNat = 8 by native_decide] - rw [decide_eq_true hgt] - norm_num - · have hgtWord : UInt256.gt (getTickRAfterMsb4Word I) getTickMsbThreshold3 = ⟨0⟩ := by - exact ugt_zero (by - rw [getTickRAfterMsb4Word_toNat_eq_source I, hthreshold] - omega) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨0⟩ : UInt256) ⟨3⟩).toNat = 0 by native_decide] - rw [decide_eq_false hgt] - norm_num - -theorem getTickRAfterMsb3Word_toNat_eq_source (I : ExecutionEnv) : - (getTickRAfterMsb3Word I).toNat = getTickSourceRAfterMsb3Nat I := by - unfold getTickRAfterMsb3Word getTickSourceRAfterMsb3Nat - rw [shiftRight_toNat_of_lt_256] - · rw [getTickRAfterMsb4Word_toNat_eq_source I, getTickMsbF3Word_toNat_eq_source I] - · rw [getTickMsbF3Word_toNat_eq_source I] - unfold getTickSourceMsbF3Nat - split <;> norm_num - -theorem getTickMsbF2Word_toNat_eq_source (I : ExecutionEnv) : - (getTickMsbF2Word I).toNat = getTickSourceMsbF2Nat I := by - unfold getTickMsbF2Word getTickSourceMsbF2Nat getTickSourceRAfterMsb3Gt2 - have hthreshold : getTickMsbThreshold2.toNat = 0xF := by - native_decide - by_cases hgt : getTickSourceRAfterMsb3Nat I > 0xF - · have hgtWord : UInt256.gt (getTickRAfterMsb3Word I) getTickMsbThreshold2 = ⟨1⟩ := by - exact ugt_one (by - rw [getTickRAfterMsb3Word_toNat_eq_source I, hthreshold] - exact hgt) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨2⟩).toNat = 4 by native_decide] - rw [decide_eq_true hgt] - norm_num - · have hgtWord : UInt256.gt (getTickRAfterMsb3Word I) getTickMsbThreshold2 = ⟨0⟩ := by - exact ugt_zero (by - rw [getTickRAfterMsb3Word_toNat_eq_source I, hthreshold] - omega) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨0⟩ : UInt256) ⟨2⟩).toNat = 0 by native_decide] - rw [decide_eq_false hgt] - norm_num - -theorem getTickRAfterMsb2Word_toNat_eq_source (I : ExecutionEnv) : - (getTickRAfterMsb2Word I).toNat = getTickSourceRAfterMsb2Nat I := by - unfold getTickRAfterMsb2Word getTickSourceRAfterMsb2Nat - rw [shiftRight_toNat_of_lt_256] - · rw [getTickRAfterMsb3Word_toNat_eq_source I, getTickMsbF2Word_toNat_eq_source I] - · rw [getTickMsbF2Word_toNat_eq_source I] - unfold getTickSourceMsbF2Nat - split <;> norm_num - -theorem getTickMsbF1Word_toNat_eq_source (I : ExecutionEnv) : - (getTickMsbF1Word I).toNat = getTickSourceMsbF1Nat I := by - unfold getTickMsbF1Word getTickSourceMsbF1Nat getTickSourceRAfterMsb2Gt1 - have hthreshold : getTickMsbThreshold1.toNat = 0x3 := by - native_decide - by_cases hgt : getTickSourceRAfterMsb2Nat I > 0x3 - · have hgtWord : UInt256.gt (getTickRAfterMsb2Word I) getTickMsbThreshold1 = ⟨1⟩ := by - exact ugt_one (by - rw [getTickRAfterMsb2Word_toNat_eq_source I, hthreshold] - exact hgt) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨1⟩).toNat = 2 by native_decide] - rw [decide_eq_true hgt] - norm_num - · have hgtWord : UInt256.gt (getTickRAfterMsb2Word I) getTickMsbThreshold1 = ⟨0⟩ := by - exact ugt_zero (by - rw [getTickRAfterMsb2Word_toNat_eq_source I, hthreshold] - omega) - rw [hgtWord] - rw [show (UInt256.shiftLeft (⟨0⟩ : UInt256) ⟨1⟩).toNat = 0 by native_decide] - rw [decide_eq_false hgt] - norm_num - -theorem getTickRAfterMsb1Word_toNat_eq_source (I : ExecutionEnv) : - (getTickRAfterMsb1Word I).toNat = getTickSourceRAfterMsb1Nat I := by - unfold getTickRAfterMsb1Word getTickSourceRAfterMsb1Nat - rw [shiftRight_toNat_of_lt_256] - · rw [getTickRAfterMsb2Word_toNat_eq_source I, getTickMsbF1Word_toNat_eq_source I] - · rw [getTickMsbF1Word_toNat_eq_source I] - unfold getTickSourceMsbF1Nat - split <;> norm_num - -theorem getTickMsbF0Word_toNat_eq_source (I : ExecutionEnv) : - (getTickMsbF0Word I).toNat = getTickSourceMsbF0Nat I := by - unfold getTickMsbF0Word getTickSourceMsbF0Nat getTickSourceRAfterMsb1Gt0 - by_cases hgt : getTickSourceRAfterMsb1Nat I > 1 - · have hgtWord : UInt256.gt (getTickRAfterMsb1Word I) ⟨1⟩ = ⟨1⟩ := by - exact ugt_one (by - rw [getTickRAfterMsb1Word_toNat_eq_source I] - change 1 < getTickSourceRAfterMsb1Nat I - exact hgt) - rw [hgtWord, decide_eq_true hgt] - rfl - · have hgtWord : UInt256.gt (getTickRAfterMsb1Word I) ⟨1⟩ = ⟨0⟩ := by - exact ugt_zero (by - rw [getTickRAfterMsb1Word_toNat_eq_source I] - change getTickSourceRAfterMsb1Nat I ≤ 1 - omega) - rw [hgtWord, decide_eq_false hgt] - norm_num - -private theorem getTickMsbWord_bits_toNat - (b0 b1 b2 b3 b4 b5 b6 b7 : Bool) : - (UInt256.lor - (UInt256.lor - (UInt256.lor - (if b2 then (⟨4⟩ : UInt256) else ⟨0⟩) - (UInt256.lor - (UInt256.lor - (if b4 then (⟨16⟩ : UInt256) else ⟨0⟩) - (UInt256.lor - (if b5 then (⟨32⟩ : UInt256) else ⟨0⟩) - (UInt256.lor - (if b6 then (⟨64⟩ : UInt256) else ⟨0⟩) - (if b7 then (⟨128⟩ : UInt256) else ⟨0⟩)))) - (if b3 then (⟨8⟩ : UInt256) else ⟨0⟩))) - (if b1 then (⟨2⟩ : UInt256) else ⟨0⟩)) - (if b0 then (⟨1⟩ : UInt256) else ⟨0⟩)).toNat = - (if b7 then 128 else 0) + - ((if b6 then 64 else 0) + - ((if b5 then 32 else 0) + - ((if b4 then 16 else 0) + - ((if b3 then 8 else 0) + - ((if b2 then 4 else 0) + - ((if b1 then 2 else 0) + if b0 then 1 else 0)))))) := by - native_decide +revert - -theorem getTickMsbWord_toNat_eq_source (I : ExecutionEnv) : - (getTickMsbWord I).toNat = getTickSourceMsbAfter0Nat I := by - have hf7 : - getTickMsbF7Word I = - if getTickSourceRatioGt7 I then (⟨128⟩ : UInt256) else ⟨0⟩ := by - apply u256_inj - rw [getTickMsbF7Word_toNat_eq_source I] - unfold getTickSourceMsbF7Nat - by_cases h : getTickSourceRatioGt7 I <;> (simp [h]; try native_decide) - have hf6 : - getTickMsbF6Word I = - if getTickSourceRAfterMsb7Gt6 I then (⟨64⟩ : UInt256) else ⟨0⟩ := by - apply u256_inj - rw [getTickMsbF6Word_toNat_eq_source I] - unfold getTickSourceMsbF6Nat - by_cases h : getTickSourceRAfterMsb7Gt6 I <;> (simp [h]; try native_decide) - have hf5 : - getTickMsbF5Word I = - if getTickSourceRAfterMsb6Gt5 I then (⟨32⟩ : UInt256) else ⟨0⟩ := by - apply u256_inj - rw [getTickMsbF5Word_toNat_eq_source I] - unfold getTickSourceMsbF5Nat - by_cases h : getTickSourceRAfterMsb6Gt5 I <;> (simp [h]; try native_decide) - have hf4 : - getTickMsbF4Word I = - if getTickSourceRAfterMsb5Gt4 I then (⟨16⟩ : UInt256) else ⟨0⟩ := by - apply u256_inj - rw [getTickMsbF4Word_toNat_eq_source I] - unfold getTickSourceMsbF4Nat - by_cases h : getTickSourceRAfterMsb5Gt4 I <;> (simp [h]; try native_decide) - have hf3 : - getTickMsbF3Word I = - if getTickSourceRAfterMsb4Gt3 I then (⟨8⟩ : UInt256) else ⟨0⟩ := by - apply u256_inj - rw [getTickMsbF3Word_toNat_eq_source I] - unfold getTickSourceMsbF3Nat - by_cases h : getTickSourceRAfterMsb4Gt3 I <;> (simp [h]; try native_decide) - have hf2 : - getTickMsbF2Word I = - if getTickSourceRAfterMsb3Gt2 I then (⟨4⟩ : UInt256) else ⟨0⟩ := by - apply u256_inj - rw [getTickMsbF2Word_toNat_eq_source I] - unfold getTickSourceMsbF2Nat - by_cases h : getTickSourceRAfterMsb3Gt2 I <;> (simp [h]; try native_decide) - have hf1 : - getTickMsbF1Word I = - if getTickSourceRAfterMsb2Gt1 I then (⟨2⟩ : UInt256) else ⟨0⟩ := by - apply u256_inj - rw [getTickMsbF1Word_toNat_eq_source I] - unfold getTickSourceMsbF1Nat - by_cases h : getTickSourceRAfterMsb2Gt1 I <;> (simp [h]; try native_decide) - have hf0 : - getTickMsbF0Word I = - if getTickSourceRAfterMsb1Gt0 I then (⟨1⟩ : UInt256) else ⟨0⟩ := by - apply u256_inj - rw [getTickMsbF0Word_toNat_eq_source I] - unfold getTickSourceMsbF0Nat - by_cases h : getTickSourceRAfterMsb1Gt0 I <;> (simp [h]; try native_decide) - unfold getTickMsbWord getTickMsbF1234567Word getTickMsbF234567Word - getTickMsbF34567Word getTickMsbF4567Word getTickMsbF567Word getTickMsbF67Word - rw [hf7, hf6, hf5, hf4, hf3, hf2, hf1, hf0] - simpa [getTickSourceMsbAfter0Nat, getTickSourceMsbAfter1Nat, - getTickSourceMsbAfter2Nat, getTickSourceMsbAfter3Nat, getTickSourceMsbAfter4Nat, - getTickSourceMsbAfter5Nat, getTickSourceMsbAfter6Nat, getTickSourceMsbF0Nat, - getTickSourceMsbF1Nat, getTickSourceMsbF2Nat, getTickSourceMsbF3Nat, - getTickSourceMsbF4Nat, getTickSourceMsbF5Nat, getTickSourceMsbF6Nat, - getTickSourceMsbF7Nat, Nat.add_assoc] using - getTickMsbWord_bits_toNat - (getTickSourceRAfterMsb1Gt0 I) - (getTickSourceRAfterMsb2Gt1 I) - (getTickSourceRAfterMsb3Gt2 I) - (getTickSourceRAfterMsb4Gt3 I) - (getTickSourceRAfterMsb5Gt4 I) - (getTickSourceRAfterMsb6Gt5 I) - (getTickSourceRAfterMsb7Gt6 I) - (getTickSourceRatioGt7 I) - -theorem getTickRNormalizedWord_toNat_eq_source (I : ExecutionEnv) : - (getTickRNormalizedWord I).toNat = getTickSourceRNormalizedNat I := by - have hmsb := getTickMsbWord_toNat_eq_source I - have hmsbLe := getTickSourceMsbAfter0Nat_le_255 I - unfold getTickRNormalizedWord getTickSourceRNormalizedNat - by_cases hge : 128 ≤ getTickSourceMsbAfter0Nat I - · have hltWord : UInt256.lt (getTickMsbWord I) ⟨128⟩ = ⟨0⟩ := by - apply ult_zero - rw [hmsb] - change 128 ≤ getTickSourceMsbAfter0Nat I - exact hge - have hsource : getTickSourceMsbGe128 I = true := by - unfold getTickSourceMsbGe128 - exact decide_eq_true hge - simp only [hltWord, hsource, ↓reduceIte] - unfold getTickRNormalizedHighWord getTickSourceRNormalizedHighNat - have hsub : (UInt256.sub (getTickMsbWord I) ⟨127⟩).toNat = - getTickSourceMsbAfter0Nat I - 127 := by - rw [usub_toNat] - · rw [hmsb] - change getTickSourceMsbAfter0Nat I - 127 = getTickSourceMsbAfter0Nat I - 127 - rfl - · rw [hmsb] - change 127 ≤ getTickSourceMsbAfter0Nat I - omega - rw [shiftRight_toNat_of_lt_256] - · rw [getTickRatioWord_toNat_eq_source I, hsub] - · rw [hsub] - omega - · have hltNat : getTickSourceMsbAfter0Nat I < 128 := Nat.lt_of_not_ge hge - have hltWord : UInt256.lt (getTickMsbWord I) ⟨128⟩ = ⟨1⟩ := by - apply ult_one - rw [hmsb] - change getTickSourceMsbAfter0Nat I < 128 - exact hltNat - have hsource : getTickSourceMsbGe128 I = false := by - unfold getTickSourceMsbGe128 - exact decide_eq_false hge - rw [hltWord, hsource] - rw [if_neg (by native_decide : ¬ ((⟨1⟩ : UInt256) = ⟨0⟩))] - rw [if_neg (by decide : ¬ (false = true))] - unfold getTickRNormalizedLowWord getTickSourceRNormalizedLowNat - have hsub : (UInt256.sub ⟨127⟩ (getTickMsbWord I)).toNat = - 127 - getTickSourceMsbAfter0Nat I := by - rw [usub_toNat] - · rw [hmsb] - change 127 - getTickSourceMsbAfter0Nat I = 127 - getTickSourceMsbAfter0Nat I - rfl - · rw [hmsb] - change getTickSourceMsbAfter0Nat I ≤ 127 - omega - rw [shiftLeft_toNat_of_lt_256] - · rw [getTickRatioWord_toNat_eq_source I, hsub] - rw [show EVM.wordModulus = UInt256.size by native_decide] - · rw [hsub] - omega - -theorem getTickLogRSquared63Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared63Word I).toNat = - getTickSourceRNormalizedNat I * getTickSourceRNormalizedNat I := by - unfold getTickLogRSquared63Word - rw [u256_mul_toNat] - rw [getTickRNormalizedWord_toNat_eq_source I] - rw [Nat.mod_eq_of_lt] - simpa [EVM.wordModulus] using getTickSourceRNormalizedNat_mul_self_lt_wordModulus I - -theorem getTickLogRShifted63Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRShifted63Word I).toNat = getTickSourceLogRShifted63Nat I := by - unfold getTickLogRShifted63Word getTickSourceLogRShifted63Nat - rw [shiftRight_toNat_of_lt_256] - · rw [getTickLogRSquared63Word_toNat_eq_source I] - change getTickSourceRNormalizedNat I * getTickSourceRNormalizedNat I / 2 ^ (127 : Nat) = - getTickSourceRNormalizedNat I * getTickSourceRNormalizedNat I / 2 ^ (127 : Nat) - rfl - · native_decide - -theorem getTickLogF63Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogF63Word I).toNat = getTickSourceLogF63Nat I := by - unfold getTickLogF63Word getTickSourceLogF63Nat getTickSourceLogRShifted63Nat - rw [shiftRight_toNat_of_lt_256] - · rw [getTickLogRSquared63Word_toNat_eq_source I] - change getTickSourceRNormalizedNat I * getTickSourceRNormalizedNat I / 2 ^ (255 : Nat) = - getTickSourceRNormalizedNat I * getTickSourceRNormalizedNat I / 2 ^ (127 : Nat) / - 2 ^ (128 : Nat) - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - · native_decide - -theorem getTickLogRAfter63Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRAfter63Word I).toNat = getTickSourceLogRAfter63Nat I := by - unfold getTickLogRAfter63Word getTickSourceLogRAfter63Nat - rw [shiftRight_toNat_of_lt_256] - · rw [getTickLogRShifted63Word_toNat_eq_source I, getTickLogF63Word_toNat_eq_source I] - · rw [getTickLogF63Word_toNat_eq_source I] - have hle := getTickSourceLogF63Nat_le_1 I - omega - -private theorem getTickLogStepRShiftedWord_toNat_eq_source (r : UInt256) (rn : Nat) - (hr : r.toNat = rn) (hmul : rn * rn < EVM.wordModulus) : - (UInt256.shiftRight (UInt256.mul r r) ⟨127⟩).toNat = - getTickSourceLogStepRShiftedNat rn := by - unfold getTickSourceLogStepRShiftedNat - rw [shiftRight_toNat_of_lt_256] - · rw [u256_mul_toNat, hr] - rw [Nat.mod_eq_of_lt] - · change rn * rn / 2 ^ (127 : Nat) = rn * rn / 2 ^ (127 : Nat) - rfl - · simpa [EVM.wordModulus] using hmul - · native_decide - -private theorem getTickLogStepFWord_toNat_eq_source (r : UInt256) (rn : Nat) - (hr : r.toNat = rn) (hmul : rn * rn < EVM.wordModulus) : - (UInt256.shiftRight (UInt256.mul r r) ⟨255⟩).toNat = - getTickSourceLogStepFNat rn := by - unfold getTickSourceLogStepFNat getTickSourceLogStepRShiftedNat - rw [shiftRight_toNat_of_lt_256] - · rw [u256_mul_toNat, hr] - rw [Nat.mod_eq_of_lt] - · change rn * rn / 2 ^ (255 : Nat) = rn * rn / 2 ^ (127 : Nat) / - 2 ^ (128 : Nat) - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - · simpa [EVM.wordModulus] using hmul - · native_decide - -private theorem getTickLogStepRAfterWord_toNat_eq_source (r : UInt256) (rn : Nat) - (hr : r.toNat = rn) (hmul : rn * rn < EVM.wordModulus) : - (UInt256.shiftRight - (UInt256.shiftRight (UInt256.mul r r) ⟨127⟩) - (UInt256.shiftRight (UInt256.mul r r) ⟨255⟩)).toNat = - getTickSourceLogStepRAfterNat rn := by - unfold getTickSourceLogStepRAfterNat - rw [shiftRight_toNat_of_lt_256] - · rw [getTickLogStepRShiftedWord_toNat_eq_source r rn hr hmul, - getTickLogStepFWord_toNat_eq_source r rn hr hmul] - · rw [getTickLogStepFWord_toNat_eq_source r rn hr hmul] - have hle := getTickSourceLogStepFNat_le_1 rn hmul - omega - -theorem getTickLogRSquared62Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared62Word I).toNat = - getTickSourceLogRAfter63Nat I * getTickSourceLogRAfter63Nat I := by - unfold getTickLogRSquared62Word - rw [u256_mul_toNat, getTickLogRAfter63Word_toNat_eq_source I] - rw [Nat.mod_eq_of_lt] - simpa [EVM.wordModulus] using getTickSourceLogRAfter63Nat_mul_self_lt_wordModulus I - -theorem getTickLogRShifted62Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRShifted62Word I).toNat = getTickSourceLogRShifted62Nat I := by - unfold getTickLogRShifted62Word getTickLogRSquared62Word getTickSourceLogRShifted62Nat - exact getTickLogStepRShiftedWord_toNat_eq_source - (getTickLogRAfter63Word I) - (getTickSourceLogRAfter63Nat I) - (getTickLogRAfter63Word_toNat_eq_source I) - (getTickSourceLogRAfter63Nat_mul_self_lt_wordModulus I) - -theorem getTickLogF62Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogF62Word I).toNat = getTickSourceLogF62Nat I := by - unfold getTickLogF62Word getTickLogRSquared62Word getTickSourceLogF62Nat - exact getTickLogStepFWord_toNat_eq_source - (getTickLogRAfter63Word I) - (getTickSourceLogRAfter63Nat I) - (getTickLogRAfter63Word_toNat_eq_source I) - (getTickSourceLogRAfter63Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRAfter62Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRAfter62Word I).toNat = getTickSourceLogRAfter62Nat I := by - unfold getTickLogRAfter62Word getTickLogRShifted62Word getTickLogF62Word - getTickLogRSquared62Word getTickSourceLogRAfter62Nat - exact getTickLogStepRAfterWord_toNat_eq_source - (getTickLogRAfter63Word I) - (getTickSourceLogRAfter63Nat I) - (getTickLogRAfter63Word_toNat_eq_source I) - (getTickSourceLogRAfter63Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRShifted61Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRShifted61Word I).toNat = getTickSourceLogRShifted61Nat I := by - unfold getTickLogRShifted61Word getTickLogRSquared61Word getTickSourceLogRShifted61Nat - exact getTickLogStepRShiftedWord_toNat_eq_source - (getTickLogRAfter62Word I) - (getTickSourceLogRAfter62Nat I) - (getTickLogRAfter62Word_toNat_eq_source I) - (getTickSourceLogRAfter62Nat_mul_self_lt_wordModulus I) - -theorem getTickLogF61Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogF61Word I).toNat = getTickSourceLogF61Nat I := by - unfold getTickLogF61Word getTickLogRSquared61Word getTickSourceLogF61Nat - exact getTickLogStepFWord_toNat_eq_source - (getTickLogRAfter62Word I) - (getTickSourceLogRAfter62Nat I) - (getTickLogRAfter62Word_toNat_eq_source I) - (getTickSourceLogRAfter62Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRAfter61Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRAfter61Word I).toNat = getTickSourceLogRAfter61Nat I := by - unfold getTickLogRAfter61Word getTickLogRShifted61Word getTickLogF61Word - getTickLogRSquared61Word getTickSourceLogRAfter61Nat - exact getTickLogStepRAfterWord_toNat_eq_source - (getTickLogRAfter62Word I) - (getTickSourceLogRAfter62Nat I) - (getTickLogRAfter62Word_toNat_eq_source I) - (getTickSourceLogRAfter62Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRShifted60Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRShifted60Word I).toNat = getTickSourceLogRShifted60Nat I := by - unfold getTickLogRShifted60Word getTickLogRSquared60Word getTickSourceLogRShifted60Nat - exact getTickLogStepRShiftedWord_toNat_eq_source - (getTickLogRAfter61Word I) - (getTickSourceLogRAfter61Nat I) - (getTickLogRAfter61Word_toNat_eq_source I) - (getTickSourceLogRAfter61Nat_mul_self_lt_wordModulus I) - -theorem getTickLogF60Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogF60Word I).toNat = getTickSourceLogF60Nat I := by - unfold getTickLogF60Word getTickLogRSquared60Word getTickSourceLogF60Nat - exact getTickLogStepFWord_toNat_eq_source - (getTickLogRAfter61Word I) - (getTickSourceLogRAfter61Nat I) - (getTickLogRAfter61Word_toNat_eq_source I) - (getTickSourceLogRAfter61Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRAfter60Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRAfter60Word I).toNat = getTickSourceLogRAfter60Nat I := by - unfold getTickLogRAfter60Word getTickLogRShifted60Word getTickLogF60Word - getTickLogRSquared60Word getTickSourceLogRAfter60Nat - exact getTickLogStepRAfterWord_toNat_eq_source - (getTickLogRAfter61Word I) - (getTickSourceLogRAfter61Nat I) - (getTickLogRAfter61Word_toNat_eq_source I) - (getTickSourceLogRAfter61Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRAfter59Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRAfter59Word I).toNat = getTickSourceLogRAfter59Nat I := by - unfold getTickLogRAfter59Word getTickLogRShifted59Word getTickLogF59Word - getTickLogRSquared59Word getTickSourceLogRAfter59Nat getTickSourceLogRAfterStep - exact getTickLogStepRAfterWord_toNat_eq_source - (getTickLogRAfter60Word I) - (getTickSourceLogRAfter60Nat I) - (getTickLogRAfter60Word_toNat_eq_source I) - (getTickSourceLogRAfter60Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRAfter58Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRAfter58Word I).toNat = getTickSourceLogRAfter58Nat I := by - unfold getTickLogRAfter58Word getTickLogRShifted58Word getTickLogF58Word - getTickLogRSquared58Word getTickSourceLogRAfter58Nat getTickSourceLogRAfterStep - exact getTickLogStepRAfterWord_toNat_eq_source - (getTickLogRAfter59Word I) - (getTickSourceLogRAfter59Nat I) - (getTickLogRAfter59Word_toNat_eq_source I) - (getTickSourceLogRAfter59Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRAfter57Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRAfter57Word I).toNat = getTickSourceLogRAfter57Nat I := by - unfold getTickLogRAfter57Word getTickLogRShifted57Word getTickLogF57Word - getTickLogRSquared57Word getTickSourceLogRAfter57Nat getTickSourceLogRAfterStep - exact getTickLogStepRAfterWord_toNat_eq_source - (getTickLogRAfter58Word I) - (getTickSourceLogRAfter58Nat I) - (getTickLogRAfter58Word_toNat_eq_source I) - (getTickSourceLogRAfter58Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRAfter56Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRAfter56Word I).toNat = getTickSourceLogRAfter56Nat I := by - unfold getTickLogRAfter56Word getTickLogRShifted56Word getTickLogF56Word - getTickLogRSquared56Word getTickSourceLogRAfter56Nat getTickSourceLogRAfterStep - exact getTickLogStepRAfterWord_toNat_eq_source - (getTickLogRAfter57Word I) - (getTickSourceLogRAfter57Nat I) - (getTickLogRAfter57Word_toNat_eq_source I) - (getTickSourceLogRAfter57Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRAfter55Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRAfter55Word I).toNat = getTickSourceLogRAfter55Nat I := by - unfold getTickLogRAfter55Word getTickLogRShifted55Word getTickLogF55Word - getTickLogRSquared55Word getTickSourceLogRAfter55Nat getTickSourceLogRAfterStep - exact getTickLogStepRAfterWord_toNat_eq_source - (getTickLogRAfter56Word I) - (getTickSourceLogRAfter56Nat I) - (getTickLogRAfter56Word_toNat_eq_source I) - (getTickSourceLogRAfter56Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRAfter54Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRAfter54Word I).toNat = getTickSourceLogRAfter54Nat I := by - unfold getTickLogRAfter54Word getTickLogRShifted54Word getTickLogF54Word - getTickLogRSquared54Word getTickSourceLogRAfter54Nat getTickSourceLogRAfterStep - exact getTickLogStepRAfterWord_toNat_eq_source - (getTickLogRAfter55Word I) - (getTickSourceLogRAfter55Nat I) - (getTickLogRAfter55Word_toNat_eq_source I) - (getTickSourceLogRAfter55Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRAfter53Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRAfter53Word I).toNat = getTickSourceLogRAfter53Nat I := by - unfold getTickLogRAfter53Word getTickLogRShifted53Word getTickLogF53Word - getTickLogRSquared53Word getTickSourceLogRAfter53Nat getTickSourceLogRAfterStep - exact getTickLogStepRAfterWord_toNat_eq_source - (getTickLogRAfter54Word I) - (getTickSourceLogRAfter54Nat I) - (getTickLogRAfter54Word_toNat_eq_source I) - (getTickSourceLogRAfter54Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRAfter52Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRAfter52Word I).toNat = getTickSourceLogRAfter52Nat I := by - unfold getTickLogRAfter52Word getTickLogRShifted52Word getTickLogF52Word - getTickLogRSquared52Word getTickSourceLogRAfter52Nat getTickSourceLogRAfterStep - exact getTickLogStepRAfterWord_toNat_eq_source - (getTickLogRAfter53Word I) - (getTickSourceLogRAfter53Nat I) - (getTickLogRAfter53Word_toNat_eq_source I) - (getTickSourceLogRAfter53Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRAfter51Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRAfter51Word I).toNat = getTickSourceLogRAfter51Nat I := by - unfold getTickLogRAfter51Word getTickLogRShifted51Word getTickLogF51Word - getTickLogRSquared51Word getTickSourceLogRAfter51Nat getTickSourceLogRAfterStep - exact getTickLogStepRAfterWord_toNat_eq_source - (getTickLogRAfter52Word I) - (getTickSourceLogRAfter52Nat I) - (getTickLogRAfter52Word_toNat_eq_source I) - (getTickSourceLogRAfter52Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRShifted50Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRShifted50Word I).toNat = getTickSourceLogRShifted50Nat I := by - unfold getTickLogRShifted50Word getTickLogRSquared50Word getTickSourceLogRShifted50Nat - exact getTickLogStepRShiftedWord_toNat_eq_source - (getTickLogRAfter51Word I) - (getTickSourceLogRAfter51Nat I) - (getTickLogRAfter51Word_toNat_eq_source I) - (getTickSourceLogRAfter51Nat_mul_self_lt_wordModulus I) - -private theorem getTickLogRSquaredWord_toNat_eq_source (r : UInt256) (rn : Nat) - (hr : r.toNat = rn) (hmul : rn * rn < EVM.wordModulus) : - (UInt256.mul r r).toNat = rn * rn := by - rw [u256_mul_toNat, hr, Nat.mod_eq_of_lt] - simpa [EVM.wordModulus] using hmul - -theorem getTickLogRSquared61Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared61Word I).toNat = - getTickSourceLogRAfter62Nat I * getTickSourceLogRAfter62Nat I := by - unfold getTickLogRSquared61Word - exact getTickLogRSquaredWord_toNat_eq_source - (getTickLogRAfter62Word I) - (getTickSourceLogRAfter62Nat I) - (getTickLogRAfter62Word_toNat_eq_source I) - (getTickSourceLogRAfter62Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRSquared60Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared60Word I).toNat = - getTickSourceLogRAfter61Nat I * getTickSourceLogRAfter61Nat I := by - unfold getTickLogRSquared60Word - exact getTickLogRSquaredWord_toNat_eq_source - (getTickLogRAfter61Word I) - (getTickSourceLogRAfter61Nat I) - (getTickLogRAfter61Word_toNat_eq_source I) - (getTickSourceLogRAfter61Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRSquared59Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared59Word I).toNat = - getTickSourceLogRAfter60Nat I * getTickSourceLogRAfter60Nat I := by - unfold getTickLogRSquared59Word - exact getTickLogRSquaredWord_toNat_eq_source - (getTickLogRAfter60Word I) - (getTickSourceLogRAfter60Nat I) - (getTickLogRAfter60Word_toNat_eq_source I) - (getTickSourceLogRAfter60Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRSquared58Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared58Word I).toNat = - getTickSourceLogRAfter59Nat I * getTickSourceLogRAfter59Nat I := by - unfold getTickLogRSquared58Word - exact getTickLogRSquaredWord_toNat_eq_source - (getTickLogRAfter59Word I) - (getTickSourceLogRAfter59Nat I) - (getTickLogRAfter59Word_toNat_eq_source I) - (getTickSourceLogRAfter59Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRSquared57Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared57Word I).toNat = - getTickSourceLogRAfter58Nat I * getTickSourceLogRAfter58Nat I := by - unfold getTickLogRSquared57Word - exact getTickLogRSquaredWord_toNat_eq_source - (getTickLogRAfter58Word I) - (getTickSourceLogRAfter58Nat I) - (getTickLogRAfter58Word_toNat_eq_source I) - (getTickSourceLogRAfter58Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRSquared56Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared56Word I).toNat = - getTickSourceLogRAfter57Nat I * getTickSourceLogRAfter57Nat I := by - unfold getTickLogRSquared56Word - exact getTickLogRSquaredWord_toNat_eq_source - (getTickLogRAfter57Word I) - (getTickSourceLogRAfter57Nat I) - (getTickLogRAfter57Word_toNat_eq_source I) - (getTickSourceLogRAfter57Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRSquared55Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared55Word I).toNat = - getTickSourceLogRAfter56Nat I * getTickSourceLogRAfter56Nat I := by - unfold getTickLogRSquared55Word - exact getTickLogRSquaredWord_toNat_eq_source - (getTickLogRAfter56Word I) - (getTickSourceLogRAfter56Nat I) - (getTickLogRAfter56Word_toNat_eq_source I) - (getTickSourceLogRAfter56Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRSquared54Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared54Word I).toNat = - getTickSourceLogRAfter55Nat I * getTickSourceLogRAfter55Nat I := by - unfold getTickLogRSquared54Word - exact getTickLogRSquaredWord_toNat_eq_source - (getTickLogRAfter55Word I) - (getTickSourceLogRAfter55Nat I) - (getTickLogRAfter55Word_toNat_eq_source I) - (getTickSourceLogRAfter55Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRSquared53Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared53Word I).toNat = - getTickSourceLogRAfter54Nat I * getTickSourceLogRAfter54Nat I := by - unfold getTickLogRSquared53Word - exact getTickLogRSquaredWord_toNat_eq_source - (getTickLogRAfter54Word I) - (getTickSourceLogRAfter54Nat I) - (getTickLogRAfter54Word_toNat_eq_source I) - (getTickSourceLogRAfter54Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRSquared52Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared52Word I).toNat = - getTickSourceLogRAfter53Nat I * getTickSourceLogRAfter53Nat I := by - unfold getTickLogRSquared52Word - exact getTickLogRSquaredWord_toNat_eq_source - (getTickLogRAfter53Word I) - (getTickSourceLogRAfter53Nat I) - (getTickLogRAfter53Word_toNat_eq_source I) - (getTickSourceLogRAfter53Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRSquared51Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared51Word I).toNat = - getTickSourceLogRAfter52Nat I * getTickSourceLogRAfter52Nat I := by - unfold getTickLogRSquared51Word - exact getTickLogRSquaredWord_toNat_eq_source - (getTickLogRAfter52Word I) - (getTickSourceLogRAfter52Nat I) - (getTickLogRAfter52Word_toNat_eq_source I) - (getTickSourceLogRAfter52Nat_mul_self_lt_wordModulus I) - -theorem getTickLogRSquared50Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLogRSquared50Word I).toNat = - getTickSourceLogRAfter51Nat I * getTickSourceLogRAfter51Nat I := by - unfold getTickLogRSquared50Word - exact getTickLogRSquaredWord_toNat_eq_source - (getTickLogRAfter51Word I) - (getTickSourceLogRAfter51Nat I) - (getTickLogRAfter51Word_toNat_eq_source I) - (getTickSourceLogRAfter51Nat_mul_self_lt_wordModulus I) - -private theorem nat_div_twoPow255_eq_testBit (n : Nat) (hn : n < 2 ^ (256 : Nat)) : - n / 2 ^ (255 : Nat) = (n.testBit 255).toNat := by - by_cases hlt : n < 2 ^ (255 : Nat) - · have hbit : n.testBit 255 = false := Nat.testBit_lt_two_pow hlt - have hdiv : n / 2 ^ (255 : Nat) = 0 := Nat.div_eq_of_lt hlt - rw [hdiv, hbit] - simp - · have hge : 2 ^ (255 : Nat) ≤ n := Nat.le_of_not_gt hlt - have hdiv : n / 2 ^ (255 : Nat) = 1 := by - apply Nat.div_eq_of_lt_le (k := 1) - · simpa using hge - · simpa using hn - have hbit : n.testBit 255 = true := by - have hbit0 : (n / 2 ^ (255 : Nat)).testBit 0 = true := by - rw [hdiv] - decide - rw [Nat.testBit_div_two_pow] at hbit0 - simpa using hbit0 - rw [hdiv, hbit] - simp - -private theorem nat_land_shifted_log_bit (n bit : Nat) - (hbit : bit ≤ 255) (hn : n < 2 ^ (256 : Nat)) : - Nat.land (n / 2 ^ (255 - bit)) (2 ^ bit) = - (n / 2 ^ (255 : Nat)) * 2 ^ bit := by - change (n / 2 ^ (255 - bit) &&& 2 ^ bit) = - (n / 2 ^ (255 : Nat)) * 2 ^ bit - rw [Nat.and_two_pow] - rw [Nat.testBit_div_two_pow] - rw [show bit + (255 - bit) = 255 by omega] - rw [nat_div_twoPow255_eq_testBit n hn] - -private theorem getTickLog2BitWord_toNat_of_rsq (mask rsq shift : UInt256) - (rn bit shiftNat : Nat) - (hmask : mask.toNat = 2 ^ bit) - (hrsq : rsq.toNat = rn) - (hshift : shift.toNat = shiftNat) - (hshiftNat : shiftNat = 255 - bit) - (hbit : bit ≤ 255) - (hrn : rn < EVM.wordModulus) : - (UInt256.land mask (UInt256.shiftRight rsq shift)).toNat = - (rn / 2 ^ (255 : Nat)) * 2 ^ bit := by - rw [u256_land_toNat] - rw [shiftRight_toNat_of_lt_256] - · rw [hmask, hrsq, hshift, hshiftNat] - rw [nat_land_comm] - rw [Nat.mod_eq_of_lt] - · exact nat_land_shifted_log_bit rn bit hbit (by - simpa [EVM.wordModulus, EVM.twoPow] using hrn) - · exact lt_of_le_of_lt (nat_land_le_right _ _) (by - have hpow : 2 ^ bit ≤ 2 ^ (255 : Nat) := - Nat.pow_le_pow_right (by norm_num) hbit - exact lt_of_le_of_lt hpow (by norm_num [UInt256.size])) - · rw [hshift, hshiftNat] - omega - -theorem getTickLog2Bit63Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit63Word I).toNat = getTickSourceLogF63Nat I * 2 ^ (63 : Nat) := by - unfold getTickLog2Bit63Word getTickSourceLogF63Nat getTickSourceLogRShifted63Nat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit63Mask (getTickLogRSquared63Word I) ⟨192⟩ - (getTickSourceRNormalizedNat I * getTickSourceRNormalizedNat I) 63 192 - (by native_decide) - (getTickLogRSquared63Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceRNormalizedNat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2Bit62Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit62Word I).toNat = getTickSourceLogF62Nat I * 2 ^ (62 : Nat) := by - unfold getTickLog2Bit62Word getTickSourceLogF62Nat getTickSourceLogRShifted62Nat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit62Mask (getTickLogRSquared62Word I) ⟨193⟩ - (getTickSourceLogRAfter63Nat I * getTickSourceLogRAfter63Nat I) 62 193 - (by native_decide) - (getTickLogRSquared62Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceLogRAfter63Nat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2Bit61Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit61Word I).toNat = getTickSourceLogF61Nat I * 2 ^ (61 : Nat) := by - unfold getTickLog2Bit61Word getTickSourceLogF61Nat getTickSourceLogStepFNat - getTickSourceLogStepRShiftedNat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit61Mask (getTickLogRSquared61Word I) ⟨194⟩ - (getTickSourceLogRAfter62Nat I * getTickSourceLogRAfter62Nat I) 61 194 - (by native_decide) - (getTickLogRSquared61Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceLogRAfter62Nat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2Bit60Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit60Word I).toNat = getTickSourceLogF60Nat I * 2 ^ (60 : Nat) := by - unfold getTickLog2Bit60Word getTickSourceLogF60Nat getTickSourceLogStepFNat - getTickSourceLogStepRShiftedNat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit60Mask (getTickLogRSquared60Word I) ⟨195⟩ - (getTickSourceLogRAfter61Nat I * getTickSourceLogRAfter61Nat I) 60 195 - (by native_decide) - (getTickLogRSquared60Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceLogRAfter61Nat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2Bit59Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit59Word I).toNat = - getTickSourceLogStepFNat (getTickSourceLogRAfter60Nat I) * 2 ^ (59 : Nat) := by - unfold getTickLog2Bit59Word getTickSourceLogStepFNat getTickSourceLogStepRShiftedNat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit59Mask (getTickLogRSquared59Word I) ⟨196⟩ - (getTickSourceLogRAfter60Nat I * getTickSourceLogRAfter60Nat I) 59 196 - (by native_decide) - (getTickLogRSquared59Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceLogRAfter60Nat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2Bit58Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit58Word I).toNat = - getTickSourceLogStepFNat (getTickSourceLogRAfter59Nat I) * 2 ^ (58 : Nat) := by - unfold getTickLog2Bit58Word getTickSourceLogStepFNat getTickSourceLogStepRShiftedNat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit58Mask (getTickLogRSquared58Word I) ⟨197⟩ - (getTickSourceLogRAfter59Nat I * getTickSourceLogRAfter59Nat I) 58 197 - (by native_decide) - (getTickLogRSquared58Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceLogRAfter59Nat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2Bit57Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit57Word I).toNat = - getTickSourceLogStepFNat (getTickSourceLogRAfter58Nat I) * 2 ^ (57 : Nat) := by - unfold getTickLog2Bit57Word getTickSourceLogStepFNat getTickSourceLogStepRShiftedNat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit57Mask (getTickLogRSquared57Word I) ⟨198⟩ - (getTickSourceLogRAfter58Nat I * getTickSourceLogRAfter58Nat I) 57 198 - (by native_decide) - (getTickLogRSquared57Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceLogRAfter58Nat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2Bit56Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit56Word I).toNat = - getTickSourceLogStepFNat (getTickSourceLogRAfter57Nat I) * 2 ^ (56 : Nat) := by - unfold getTickLog2Bit56Word getTickSourceLogStepFNat getTickSourceLogStepRShiftedNat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit56Mask (getTickLogRSquared56Word I) ⟨199⟩ - (getTickSourceLogRAfter57Nat I * getTickSourceLogRAfter57Nat I) 56 199 - (by native_decide) - (getTickLogRSquared56Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceLogRAfter57Nat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2Bit55Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit55Word I).toNat = - getTickSourceLogStepFNat (getTickSourceLogRAfter56Nat I) * 2 ^ (55 : Nat) := by - unfold getTickLog2Bit55Word getTickSourceLogStepFNat getTickSourceLogStepRShiftedNat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit55Mask (getTickLogRSquared55Word I) ⟨200⟩ - (getTickSourceLogRAfter56Nat I * getTickSourceLogRAfter56Nat I) 55 200 - (by native_decide) - (getTickLogRSquared55Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceLogRAfter56Nat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2Bit54Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit54Word I).toNat = - getTickSourceLogStepFNat (getTickSourceLogRAfter55Nat I) * 2 ^ (54 : Nat) := by - unfold getTickLog2Bit54Word getTickSourceLogStepFNat getTickSourceLogStepRShiftedNat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit54Mask (getTickLogRSquared54Word I) ⟨201⟩ - (getTickSourceLogRAfter55Nat I * getTickSourceLogRAfter55Nat I) 54 201 - (by native_decide) - (getTickLogRSquared54Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceLogRAfter55Nat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2Bit53Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit53Word I).toNat = - getTickSourceLogStepFNat (getTickSourceLogRAfter54Nat I) * 2 ^ (53 : Nat) := by - unfold getTickLog2Bit53Word getTickSourceLogStepFNat getTickSourceLogStepRShiftedNat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit53Mask (getTickLogRSquared53Word I) ⟨202⟩ - (getTickSourceLogRAfter54Nat I * getTickSourceLogRAfter54Nat I) 53 202 - (by native_decide) - (getTickLogRSquared53Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceLogRAfter54Nat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2Bit52Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit52Word I).toNat = - getTickSourceLogStepFNat (getTickSourceLogRAfter53Nat I) * 2 ^ (52 : Nat) := by - unfold getTickLog2Bit52Word getTickSourceLogStepFNat getTickSourceLogStepRShiftedNat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit52Mask (getTickLogRSquared52Word I) ⟨203⟩ - (getTickSourceLogRAfter53Nat I * getTickSourceLogRAfter53Nat I) 52 203 - (by native_decide) - (getTickLogRSquared52Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceLogRAfter53Nat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2Bit51Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit51Word I).toNat = - getTickSourceLogStepFNat (getTickSourceLogRAfter52Nat I) * 2 ^ (51 : Nat) := by - unfold getTickLog2Bit51Word getTickSourceLogStepFNat getTickSourceLogStepRShiftedNat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit51Mask (getTickLogRSquared51Word I) ⟨204⟩ - (getTickSourceLogRAfter52Nat I * getTickSourceLogRAfter52Nat I) 51 204 - (by native_decide) - (getTickLogRSquared51Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceLogRAfter52Nat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2Bit50Word_toNat_eq_source (I : ExecutionEnv) : - (getTickLog2Bit50Word I).toNat = getTickSourceLogF50Nat I * 2 ^ (50 : Nat) := by - unfold getTickLog2Bit50Word getTickSourceLogF50Nat getTickSourceLogStepFNat - getTickSourceLogStepRShiftedNat - rw [getTickLog2BitWord_toNat_of_rsq - getTickLog2Bit50Mask (getTickLogRSquared50Word I) ⟨205⟩ - (getTickSourceLogRAfter51Nat I * getTickSourceLogRAfter51Nat I) 50 205 - (by native_decide) - (getTickLogRSquared50Word_toNat_eq_source I) - (by native_decide) (by norm_num) (by norm_num) - (getTickSourceLogRAfter51Nat_mul_self_lt_wordModulus I)] - rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] - -theorem getTickLog2BaseWord_eq_source_of_msb_bounds (I : ExecutionEnv) - (hloMsb : 64 ≤ getTickSourceMsbAfter0Nat I) - (hhiMsb : getTickSourceMsbAfter0Nat I ≤ 191) : - getTickLog2BaseWord I = EVM.wordOfInt (getTickSourceLog2BaseInt I) := by - apply u256_inj - unfold getTickLog2BaseWord getTickSourceLog2BaseInt - rw [shiftLeft_toNat_of_lt_256] - · rw [uadd_toNat, getTickMsbWord_toNat_eq_source I] - have hlnot : (UInt256.lnot (⟨127⟩ : UInt256)).toNat = UInt256.size - 128 := by - native_decide - rw [hlnot] - by_cases hge128 : 128 ≤ getTickSourceMsbAfter0Nat I - · have hbaseMod : - (getTickSourceMsbAfter0Nat I + (UInt256.size - 128)) % UInt256.size = - getTickSourceMsbAfter0Nat I - 128 := by - have hsum : - getTickSourceMsbAfter0Nat I + (UInt256.size - 128) = - UInt256.size + (getTickSourceMsbAfter0Nat I - 128) := by - norm_num [UInt256.size] - omega - rw [hsum, Nat.add_mod_left] - rw [Nat.mod_eq_of_lt] - omega - rw [hbaseMod] - have hmulLt : (getTickSourceMsbAfter0Nat I - 128) * 2 ^ (64 : Nat) < - UInt256.size := by - have hdiff : getTickSourceMsbAfter0Nat I - 128 ≤ 63 := by omega - exact lt_of_le_of_lt (Nat.mul_le_mul_right _ hdiff) (by native_decide) - change (getTickSourceMsbAfter0Nat I - 128) * 2 ^ (64 : Nat) % UInt256.size = - (EVM.wordOfInt - (((getTickSourceMsbAfter0Nat I : Int) - 128) * (2 ^ (64 : Nat) : Int))).toNat - rw [Nat.mod_eq_of_lt hmulLt] - have hsrcNonneg : - 0 ≤ ((getTickSourceMsbAfter0Nat I : Int) - 128) * (2 ^ (64 : Nat) : Int) := by - norm_num - omega - have hsrcLt : - ((getTickSourceMsbAfter0Nat I : Int) - 128) * (2 ^ (64 : Nat) : Int) < - EVM.wordModulus := by - norm_num [EVM.wordModulus, EVM.twoPow, UInt256.size] at hhiMsb ⊢ - omega - rw [wordOfInt_nonneg_toNat_lt_wordModulus _ hsrcNonneg hsrcLt] - have htoNat : - (((getTickSourceMsbAfter0Nat I : Int) - 128) * - (2 ^ (64 : Nat) : Int)).toNat = - (getTickSourceMsbAfter0Nat I - 128) * 2 ^ (64 : Nat) := by - norm_num - omega - rw [htoNat] - · have hlt128 : getTickSourceMsbAfter0Nat I < 128 := Nat.lt_of_not_ge hge128 - let d := 128 - getTickSourceMsbAfter0Nat I - have hdPos : 0 < d := by - dsimp [d] - omega - have hdLe : d ≤ 64 := by - dsimp [d] - omega - have hbaseMod : - (getTickSourceMsbAfter0Nat I + (UInt256.size - 128)) % UInt256.size = - UInt256.size - d := by - have hsum : - getTickSourceMsbAfter0Nat I + (UInt256.size - 128) = UInt256.size - d := by - dsimp [d] - norm_num [UInt256.size] - omega - rw [hsum] - rw [Nat.mod_eq_of_lt] - · exact Nat.sub_lt (by native_decide : 0 < UInt256.size) hdPos - rw [hbaseMod] - have hdMulPos : 0 < d * 2 ^ (64 : Nat) := Nat.mul_pos hdPos (by norm_num) - have hdMulLe : d * 2 ^ (64 : Nat) ≤ UInt256.size := by - exact le_trans (Nat.mul_le_mul_right _ hdLe) (by native_decide) - have hshiftMod : - ((UInt256.size - d) * 2 ^ (64 : Nat)) % UInt256.size = - UInt256.size - d * 2 ^ (64 : Nat) := by - have hdecomp : - (UInt256.size - d) * 2 ^ (64 : Nat) = - (UInt256.size - d * 2 ^ (64 : Nat)) + - UInt256.size * (2 ^ (64 : Nat) - 1) := by - norm_num [UInt256.size] at hdLe ⊢ - omega - rw [hdecomp, Nat.add_mul_mod_self_left] - rw [Nat.mod_eq_of_lt] - omega - change (UInt256.size - d) * 2 ^ (64 : Nat) % UInt256.size = - (EVM.wordOfInt - (((getTickSourceMsbAfter0Nat I : Int) - 128) * (2 ^ (64 : Nat) : Int))).toNat - rw [hshiftMod] - have hsrcNeg : - ((getTickSourceMsbAfter0Nat I : Int) - 128) * (2 ^ (64 : Nat) : Int) < 0 := by - norm_num - omega - have hsrcAbs : - (((getTickSourceMsbAfter0Nat I : Int) - 128) * - (2 ^ (64 : Nat) : Int)).natAbs = - d * 2 ^ (64 : Nat) := by - dsimp [d] - omega - have hsrcAbsLt : - (((getTickSourceMsbAfter0Nat I : Int) - 128) * - (2 ^ (64 : Nat) : Int)).natAbs < EVM.wordModulus := by - rw [hsrcAbs] - exact lt_of_le_of_lt (Nat.mul_le_mul_right _ hdLe) (by native_decide) - rw [wordOfInt_neg_toNat_lt_wordModulus _ hsrcNeg hsrcAbsLt] - rw [hsrcAbs] - · native_decide - -private theorem nat_lor_zero_left (n : Nat) : Nat.lor 0 n = n := by - apply Nat.eq_of_testBit_eq - intro i - change (0 ||| n).testBit i = n.testBit i - rw [Nat.testBit_or] - simp - -private theorem nat_lor_bit_low_add (low coeff bit : Nat) - (hlowMod : low % 2 ^ (bit + 1) = 0) - (hcoeff : coeff ≤ 1) : - Nat.lor (coeff * 2 ^ bit) low = low + coeff * 2 ^ bit := by - rcases Nat.eq_zero_or_pos coeff with hcoeff0 | hcoeffPos - · subst coeff - rw [Nat.zero_mul, nat_lor_zero_left] - omega - · have hcoeff1 : coeff = 1 := by omega - subst coeff - have hlowEq : low = low / 2 ^ (bit + 1) * 2 ^ (bit + 1) := by - have h := Nat.div_add_mod low (2 ^ (bit + 1)) - rw [hlowMod, add_zero] at h - rw [Nat.mul_comm] at h - exact h.symm - rw [hlowEq] - rw [nat_lor_shift_add] - · ring - · rw [one_mul] - exact Nat.pow_lt_pow_right (by norm_num : 1 < 2) (Nat.lt_succ_self bit) - -private theorem nat_lor_bit_low_high_add (q low coeff bit : Nat) - (hlow64 : low < 2 ^ (64 : Nat)) - (hlowMod : low % 2 ^ (bit + 1) = 0) - (hcoeff : coeff ≤ 1) - (hnewLow : low + coeff * 2 ^ bit < 2 ^ (64 : Nat)) : - Nat.lor (coeff * 2 ^ bit) (low + q * 2 ^ (64 : Nat)) = - low + coeff * 2 ^ bit + q * 2 ^ (64 : Nat) := by - have hprev : low + q * 2 ^ (64 : Nat) = Nat.lor low (q * 2 ^ (64 : Nat)) := by - rw [nat_lor_shift_add low q 64 hlow64] - rw [hprev] - calc - Nat.lor (coeff * 2 ^ bit) (Nat.lor low (q * 2 ^ (64 : Nat))) = - Nat.lor (Nat.lor (coeff * 2 ^ bit) low) (q * 2 ^ (64 : Nat)) := by - exact (Nat.lor_assoc (coeff * 2 ^ bit) low (q * 2 ^ (64 : Nat))).symm - _ = Nat.lor (low + coeff * 2 ^ bit) (q * 2 ^ (64 : Nat)) := by - rw [nat_lor_bit_low_add low coeff bit hlowMod hcoeff] - _ = low + coeff * 2 ^ bit + q * 2 ^ (64 : Nat) := by - rw [nat_lor_shift_add (low + coeff * 2 ^ bit) q 64 hnewLow] - -private theorem getTickLog2AfterStepWord_toNat_of_prev - (bitWord prev : UInt256) (q bits coeff bit : Nat) - (hbitWord : bitWord.toNat = coeff * 2 ^ bit) - (hprev : prev.toNat = bits * 2 ^ (bit + 1) + q * 2 ^ (64 : Nat)) - (hbitsLow : bits * 2 ^ (bit + 1) < 2 ^ (64 : Nat)) - (hcoeff : coeff ≤ 1) - (hnewLow : (bits * 2 + coeff) * 2 ^ bit < 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (UInt256.lor bitWord prev).toNat = - (bits * 2 + coeff) * 2 ^ bit + q * 2 ^ (64 : Nat) := by - rw [u256_lor_toNat, hbitWord, hprev] - have hlowMod : bits * 2 ^ (bit + 1) % 2 ^ (bit + 1) = 0 := by - exact Nat.mul_mod_left bits (2 ^ (bit + 1)) - have hnewLow' : bits * 2 ^ (bit + 1) + coeff * 2 ^ bit < 2 ^ (64 : Nat) := by - rw [show bits * 2 ^ (bit + 1) + coeff * 2 ^ bit = - (bits * 2 + coeff) * 2 ^ bit by - rw [Nat.pow_succ] - ring] - exact hnewLow - rw [nat_lor_bit_low_high_add q (bits * 2 ^ (bit + 1)) coeff bit hbitsLow - hlowMod hcoeff hnewLow'] - rw [show bits * 2 ^ (bit + 1) + coeff * 2 ^ bit = - (bits * 2 + coeff) * 2 ^ bit by - rw [Nat.pow_succ] - ring] - rw [Nat.mod_eq_of_lt] - have hltQ : q + 1 ≤ 2 ^ (192 : Nat) := Nat.succ_le_iff.mpr hq - calc - (bits * 2 + coeff) * 2 ^ bit + q * 2 ^ (64 : Nat) - < 2 ^ (64 : Nat) + q * 2 ^ (64 : Nat) := by omega - _ = (q + 1) * 2 ^ (64 : Nat) := by ring - _ ≤ 2 ^ (192 : Nat) * 2 ^ (64 : Nat) := by - exact Nat.mul_le_mul_right _ hltQ - _ = UInt256.size := by native_decide - -private def getTickLog2BitsAfter63Nat (I : ExecutionEnv) : Nat := - getTickSourceLogF63Nat I - -private def getTickLog2BitsAfter62Nat (I : ExecutionEnv) : Nat := - getTickLog2BitsAfter63Nat I * 2 + getTickSourceLogF62Nat I - -private def getTickLog2BitsAfter61Nat (I : ExecutionEnv) : Nat := - getTickLog2BitsAfter62Nat I * 2 + getTickSourceLogF61Nat I - -private def getTickLog2BitsAfter60Nat (I : ExecutionEnv) : Nat := - getTickLog2BitsAfter61Nat I * 2 + getTickSourceLogF60Nat I - -private def getTickLog2BitsAfter59Nat (I : ExecutionEnv) : Nat := - getTickLog2BitsAfter60Nat I * 2 + getTickSourceLogStepFNat (getTickSourceLogRAfter60Nat I) - -private def getTickLog2BitsAfter58Nat (I : ExecutionEnv) : Nat := - getTickLog2BitsAfter59Nat I * 2 + getTickSourceLogStepFNat (getTickSourceLogRAfter59Nat I) - -private def getTickLog2BitsAfter57Nat (I : ExecutionEnv) : Nat := - getTickLog2BitsAfter58Nat I * 2 + getTickSourceLogStepFNat (getTickSourceLogRAfter58Nat I) - -private def getTickLog2BitsAfter56Nat (I : ExecutionEnv) : Nat := - getTickLog2BitsAfter57Nat I * 2 + getTickSourceLogStepFNat (getTickSourceLogRAfter57Nat I) - -private def getTickLog2BitsAfter55Nat (I : ExecutionEnv) : Nat := - getTickLog2BitsAfter56Nat I * 2 + getTickSourceLogStepFNat (getTickSourceLogRAfter56Nat I) - -private def getTickLog2BitsAfter54Nat (I : ExecutionEnv) : Nat := - getTickLog2BitsAfter55Nat I * 2 + getTickSourceLogStepFNat (getTickSourceLogRAfter55Nat I) - -private def getTickLog2BitsAfter53Nat (I : ExecutionEnv) : Nat := - getTickLog2BitsAfter54Nat I * 2 + getTickSourceLogStepFNat (getTickSourceLogRAfter54Nat I) - -private def getTickLog2BitsAfter52Nat (I : ExecutionEnv) : Nat := - getTickLog2BitsAfter53Nat I * 2 + getTickSourceLogStepFNat (getTickSourceLogRAfter53Nat I) - -private def getTickLog2BitsAfter51Nat (I : ExecutionEnv) : Nat := - getTickLog2BitsAfter52Nat I * 2 + getTickSourceLogStepFNat (getTickSourceLogRAfter52Nat I) - -def getTickLog2BitsAfter50Nat (I : ExecutionEnv) : Nat := - getTickLog2BitsAfter51Nat I * 2 + getTickSourceLogF50Nat I - -private theorem getTickLog2BitsAfter63Nat_lt_twoPow1 (I : ExecutionEnv) : - getTickLog2BitsAfter63Nat I < 2 ^ (1 : Nat) := by - unfold getTickLog2BitsAfter63Nat - have hf := getTickSourceLogF63Nat_le_1 I - omega - -private theorem getTickLog2BitsAfter62Nat_lt_twoPow2 (I : ExecutionEnv) : - getTickLog2BitsAfter62Nat I < 2 ^ (2 : Nat) := by - unfold getTickLog2BitsAfter62Nat - have hb := getTickLog2BitsAfter63Nat_lt_twoPow1 I - have hf := getTickSourceLogF62Nat_le_1 I - norm_num at hb hf ⊢ - omega - -private theorem getTickLog2BitsAfter61Nat_lt_twoPow3 (I : ExecutionEnv) : - getTickLog2BitsAfter61Nat I < 2 ^ (3 : Nat) := by - unfold getTickLog2BitsAfter61Nat - have hb := getTickLog2BitsAfter62Nat_lt_twoPow2 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter62Nat I) - (getTickSourceLogRAfter62Nat_mul_self_lt_wordModulus I) - have hf61 : getTickSourceLogF61Nat I ≤ 1 := by - simpa [getTickSourceLogF61Nat] using hf - norm_num at hb hf61 ⊢ - omega - -private theorem getTickLog2BitsAfter60Nat_lt_twoPow4 (I : ExecutionEnv) : - getTickLog2BitsAfter60Nat I < 2 ^ (4 : Nat) := by - unfold getTickLog2BitsAfter60Nat - have hb := getTickLog2BitsAfter61Nat_lt_twoPow3 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter61Nat I) - (getTickSourceLogRAfter61Nat_mul_self_lt_wordModulus I) - have hf60 : getTickSourceLogF60Nat I ≤ 1 := by - simpa [getTickSourceLogF60Nat] using hf - norm_num at hb hf60 ⊢ - omega - -private theorem getTickLog2BitsAfter59Nat_lt_twoPow5 (I : ExecutionEnv) : - getTickLog2BitsAfter59Nat I < 2 ^ (5 : Nat) := by - unfold getTickLog2BitsAfter59Nat - have hb := getTickLog2BitsAfter60Nat_lt_twoPow4 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter60Nat I) - (getTickSourceLogRAfter60Nat_mul_self_lt_wordModulus I) - norm_num at hb hf ⊢ - omega - -private theorem getTickLog2BitsAfter58Nat_lt_twoPow6 (I : ExecutionEnv) : - getTickLog2BitsAfter58Nat I < 2 ^ (6 : Nat) := by - unfold getTickLog2BitsAfter58Nat - have hb := getTickLog2BitsAfter59Nat_lt_twoPow5 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter59Nat I) - (getTickSourceLogRAfter59Nat_mul_self_lt_wordModulus I) - norm_num at hb hf ⊢ - omega - -private theorem getTickLog2BitsAfter57Nat_lt_twoPow7 (I : ExecutionEnv) : - getTickLog2BitsAfter57Nat I < 2 ^ (7 : Nat) := by - unfold getTickLog2BitsAfter57Nat - have hb := getTickLog2BitsAfter58Nat_lt_twoPow6 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter58Nat I) - (getTickSourceLogRAfter58Nat_mul_self_lt_wordModulus I) - norm_num at hb hf ⊢ - omega - -private theorem getTickLog2BitsAfter56Nat_lt_twoPow8 (I : ExecutionEnv) : - getTickLog2BitsAfter56Nat I < 2 ^ (8 : Nat) := by - unfold getTickLog2BitsAfter56Nat - have hb := getTickLog2BitsAfter57Nat_lt_twoPow7 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter57Nat I) - (getTickSourceLogRAfter57Nat_mul_self_lt_wordModulus I) - norm_num at hb hf ⊢ - omega - -private theorem getTickLog2BitsAfter55Nat_lt_twoPow9 (I : ExecutionEnv) : - getTickLog2BitsAfter55Nat I < 2 ^ (9 : Nat) := by - unfold getTickLog2BitsAfter55Nat - have hb := getTickLog2BitsAfter56Nat_lt_twoPow8 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter56Nat I) - (getTickSourceLogRAfter56Nat_mul_self_lt_wordModulus I) - norm_num at hb hf ⊢ - omega - -private theorem getTickLog2BitsAfter54Nat_lt_twoPow10 (I : ExecutionEnv) : - getTickLog2BitsAfter54Nat I < 2 ^ (10 : Nat) := by - unfold getTickLog2BitsAfter54Nat - have hb := getTickLog2BitsAfter55Nat_lt_twoPow9 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter55Nat I) - (getTickSourceLogRAfter55Nat_mul_self_lt_wordModulus I) - norm_num at hb hf ⊢ - omega - -private theorem getTickLog2BitsAfter53Nat_lt_twoPow11 (I : ExecutionEnv) : - getTickLog2BitsAfter53Nat I < 2 ^ (11 : Nat) := by - unfold getTickLog2BitsAfter53Nat - have hb := getTickLog2BitsAfter54Nat_lt_twoPow10 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter54Nat I) - (getTickSourceLogRAfter54Nat_mul_self_lt_wordModulus I) - norm_num at hb hf ⊢ - omega - -private theorem getTickLog2BitsAfter52Nat_lt_twoPow12 (I : ExecutionEnv) : - getTickLog2BitsAfter52Nat I < 2 ^ (12 : Nat) := by - unfold getTickLog2BitsAfter52Nat - have hb := getTickLog2BitsAfter53Nat_lt_twoPow11 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter53Nat I) - (getTickSourceLogRAfter53Nat_mul_self_lt_wordModulus I) - norm_num at hb hf ⊢ - omega - -private theorem getTickLog2BitsAfter51Nat_lt_twoPow13 (I : ExecutionEnv) : - getTickLog2BitsAfter51Nat I < 2 ^ (13 : Nat) := by - unfold getTickLog2BitsAfter51Nat - have hb := getTickLog2BitsAfter52Nat_lt_twoPow12 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter52Nat I) - (getTickSourceLogRAfter52Nat_mul_self_lt_wordModulus I) - norm_num at hb hf ⊢ - omega - -theorem getTickLog2BitsAfter50Nat_lt_twoPow14 (I : ExecutionEnv) : - getTickLog2BitsAfter50Nat I < 2 ^ (14 : Nat) := by - unfold getTickLog2BitsAfter50Nat - have hb := getTickLog2BitsAfter51Nat_lt_twoPow13 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter51Nat I) - (getTickSourceLogRAfter51Nat_mul_self_lt_wordModulus I) - have hf50 : getTickSourceLogF50Nat I ≤ 1 := by - simpa [getTickSourceLogF50Nat] using hf - norm_num at hb hf50 ⊢ - omega - -private theorem getTickLog2After63Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After63Word I).toNat = - getTickLog2BitsAfter63Nat I * 2 ^ (63 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After63Word - have hf := getTickSourceLogF63Nat_le_1 I - simpa [getTickLog2BitsAfter63Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit63Word I) (getTickLog2BaseWord I) q 0 (getTickSourceLogF63Nat I) 63 - (getTickLog2Bit63Word_toNat_eq_source I) - (by simpa using hbase) - (by norm_num) - hf - (by - norm_num at hf ⊢ - omega) - hq - -private theorem getTickLog2After62Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After62Word I).toNat = - getTickLog2BitsAfter62Nat I * 2 ^ (62 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After62Word - have hb := getTickLog2BitsAfter63Nat_lt_twoPow1 I - have hf := getTickSourceLogF62Nat_le_1 I - simpa [getTickLog2BitsAfter62Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit62Word I) (getTickLog2After63Word I) q - (getTickLog2BitsAfter63Nat I) (getTickSourceLogF62Nat I) 62 - (getTickLog2Bit62Word_toNat_eq_source I) - (getTickLog2After63Word_toNat_of_base I q hbase hq) - (by - norm_num at hb ⊢ - omega) - hf - (by - norm_num at hb hf ⊢ - omega) - hq - -private theorem getTickLog2After61Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After61Word I).toNat = - getTickLog2BitsAfter61Nat I * 2 ^ (61 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After61Word - have hb := getTickLog2BitsAfter62Nat_lt_twoPow2 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter62Nat I) - (getTickSourceLogRAfter62Nat_mul_self_lt_wordModulus I) - have hf61 : getTickSourceLogF61Nat I ≤ 1 := by - simpa [getTickSourceLogF61Nat] using hf - simpa [getTickLog2BitsAfter61Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit61Word I) (getTickLog2After62Word I) q - (getTickLog2BitsAfter62Nat I) (getTickSourceLogF61Nat I) 61 - (getTickLog2Bit61Word_toNat_eq_source I) - (getTickLog2After62Word_toNat_of_base I q hbase hq) - (by - norm_num at hb ⊢ - omega) - hf61 - (by - norm_num at hb hf61 ⊢ - omega) - hq - -private theorem getTickLog2After60Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After60Word I).toNat = - getTickLog2BitsAfter60Nat I * 2 ^ (60 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After60Word - have hb := getTickLog2BitsAfter61Nat_lt_twoPow3 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter61Nat I) - (getTickSourceLogRAfter61Nat_mul_self_lt_wordModulus I) - have hf60 : getTickSourceLogF60Nat I ≤ 1 := by - simpa [getTickSourceLogF60Nat] using hf - simpa [getTickLog2BitsAfter60Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit60Word I) (getTickLog2After61Word I) q - (getTickLog2BitsAfter61Nat I) (getTickSourceLogF60Nat I) 60 - (getTickLog2Bit60Word_toNat_eq_source I) - (getTickLog2After61Word_toNat_of_base I q hbase hq) - (by - norm_num at hb ⊢ - omega) - hf60 - (by - norm_num at hb hf60 ⊢ - omega) - hq - -private theorem getTickLog2After59Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After59Word I).toNat = - getTickLog2BitsAfter59Nat I * 2 ^ (59 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After59Word - have hb := getTickLog2BitsAfter60Nat_lt_twoPow4 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter60Nat I) - (getTickSourceLogRAfter60Nat_mul_self_lt_wordModulus I) - simpa [getTickLog2BitsAfter59Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit59Word I) (getTickLog2After60Word I) q - (getTickLog2BitsAfter60Nat I) - (getTickSourceLogStepFNat (getTickSourceLogRAfter60Nat I)) 59 - (getTickLog2Bit59Word_toNat_eq_source I) - (getTickLog2After60Word_toNat_of_base I q hbase hq) - (by - norm_num at hb ⊢ - omega) - hf - (by - norm_num at hb hf ⊢ - omega) - hq - -private theorem getTickLog2After58Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After58Word I).toNat = - getTickLog2BitsAfter58Nat I * 2 ^ (58 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After58Word - have hb := getTickLog2BitsAfter59Nat_lt_twoPow5 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter59Nat I) - (getTickSourceLogRAfter59Nat_mul_self_lt_wordModulus I) - simpa [getTickLog2BitsAfter58Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit58Word I) (getTickLog2After59Word I) q - (getTickLog2BitsAfter59Nat I) - (getTickSourceLogStepFNat (getTickSourceLogRAfter59Nat I)) 58 - (getTickLog2Bit58Word_toNat_eq_source I) - (getTickLog2After59Word_toNat_of_base I q hbase hq) - (by - norm_num at hb ⊢ - omega) - hf - (by - norm_num at hb hf ⊢ - omega) - hq - -private theorem getTickLog2After57Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After57Word I).toNat = - getTickLog2BitsAfter57Nat I * 2 ^ (57 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After57Word - have hb := getTickLog2BitsAfter58Nat_lt_twoPow6 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter58Nat I) - (getTickSourceLogRAfter58Nat_mul_self_lt_wordModulus I) - simpa [getTickLog2BitsAfter57Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit57Word I) (getTickLog2After58Word I) q - (getTickLog2BitsAfter58Nat I) - (getTickSourceLogStepFNat (getTickSourceLogRAfter58Nat I)) 57 - (getTickLog2Bit57Word_toNat_eq_source I) - (getTickLog2After58Word_toNat_of_base I q hbase hq) - (by - norm_num at hb ⊢ - omega) - hf - (by - norm_num at hb hf ⊢ - omega) - hq - -private theorem getTickLog2After56Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After56Word I).toNat = - getTickLog2BitsAfter56Nat I * 2 ^ (56 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After56Word - have hb := getTickLog2BitsAfter57Nat_lt_twoPow7 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter57Nat I) - (getTickSourceLogRAfter57Nat_mul_self_lt_wordModulus I) - simpa [getTickLog2BitsAfter56Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit56Word I) (getTickLog2After57Word I) q - (getTickLog2BitsAfter57Nat I) - (getTickSourceLogStepFNat (getTickSourceLogRAfter57Nat I)) 56 - (getTickLog2Bit56Word_toNat_eq_source I) - (getTickLog2After57Word_toNat_of_base I q hbase hq) - (by - norm_num at hb ⊢ - omega) - hf - (by - norm_num at hb hf ⊢ - omega) - hq - -private theorem getTickLog2After55Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After55Word I).toNat = - getTickLog2BitsAfter55Nat I * 2 ^ (55 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After55Word - have hb := getTickLog2BitsAfter56Nat_lt_twoPow8 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter56Nat I) - (getTickSourceLogRAfter56Nat_mul_self_lt_wordModulus I) - simpa [getTickLog2BitsAfter55Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit55Word I) (getTickLog2After56Word I) q - (getTickLog2BitsAfter56Nat I) - (getTickSourceLogStepFNat (getTickSourceLogRAfter56Nat I)) 55 - (getTickLog2Bit55Word_toNat_eq_source I) - (getTickLog2After56Word_toNat_of_base I q hbase hq) - (by - norm_num at hb ⊢ - omega) - hf - (by - norm_num at hb hf ⊢ - omega) - hq - -private theorem getTickLog2After54Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After54Word I).toNat = - getTickLog2BitsAfter54Nat I * 2 ^ (54 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After54Word - have hb := getTickLog2BitsAfter55Nat_lt_twoPow9 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter55Nat I) - (getTickSourceLogRAfter55Nat_mul_self_lt_wordModulus I) - simpa [getTickLog2BitsAfter54Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit54Word I) (getTickLog2After55Word I) q - (getTickLog2BitsAfter55Nat I) - (getTickSourceLogStepFNat (getTickSourceLogRAfter55Nat I)) 54 - (getTickLog2Bit54Word_toNat_eq_source I) - (getTickLog2After55Word_toNat_of_base I q hbase hq) - (by - norm_num at hb ⊢ - omega) - hf - (by - norm_num at hb hf ⊢ - omega) - hq - -private theorem getTickLog2After53Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After53Word I).toNat = - getTickLog2BitsAfter53Nat I * 2 ^ (53 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After53Word - have hb := getTickLog2BitsAfter54Nat_lt_twoPow10 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter54Nat I) - (getTickSourceLogRAfter54Nat_mul_self_lt_wordModulus I) - simpa [getTickLog2BitsAfter53Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit53Word I) (getTickLog2After54Word I) q - (getTickLog2BitsAfter54Nat I) - (getTickSourceLogStepFNat (getTickSourceLogRAfter54Nat I)) 53 - (getTickLog2Bit53Word_toNat_eq_source I) - (getTickLog2After54Word_toNat_of_base I q hbase hq) - (by - norm_num at hb ⊢ - omega) - hf - (by - norm_num at hb hf ⊢ - omega) - hq - -private theorem getTickLog2After52Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After52Word I).toNat = - getTickLog2BitsAfter52Nat I * 2 ^ (52 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After52Word - have hb := getTickLog2BitsAfter53Nat_lt_twoPow11 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter53Nat I) - (getTickSourceLogRAfter53Nat_mul_self_lt_wordModulus I) - simpa [getTickLog2BitsAfter52Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit52Word I) (getTickLog2After53Word I) q - (getTickLog2BitsAfter53Nat I) - (getTickSourceLogStepFNat (getTickSourceLogRAfter53Nat I)) 52 - (getTickLog2Bit52Word_toNat_eq_source I) - (getTickLog2After53Word_toNat_of_base I q hbase hq) - (by - norm_num at hb ⊢ - omega) - hf - (by - norm_num at hb hf ⊢ - omega) - hq - -private theorem getTickLog2After51Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After51Word I).toNat = - getTickLog2BitsAfter51Nat I * 2 ^ (51 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After51Word - have hb := getTickLog2BitsAfter52Nat_lt_twoPow12 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter52Nat I) - (getTickSourceLogRAfter52Nat_mul_self_lt_wordModulus I) - simpa [getTickLog2BitsAfter51Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit51Word I) (getTickLog2After52Word I) q - (getTickLog2BitsAfter52Nat I) - (getTickSourceLogStepFNat (getTickSourceLogRAfter52Nat I)) 51 - (getTickLog2Bit51Word_toNat_eq_source I) - (getTickLog2After52Word_toNat_of_base I q hbase hq) - (by - norm_num at hb ⊢ - omega) - hf - (by - norm_num at hb hf ⊢ - omega) - hq - -theorem getTickLog2After50Word_toNat_of_base (I : ExecutionEnv) (q : Nat) - (hbase : (getTickLog2BaseWord I).toNat = q * 2 ^ (64 : Nat)) - (hq : q < 2 ^ (192 : Nat)) : - (getTickLog2After50Word I).toNat = - getTickLog2BitsAfter50Nat I * 2 ^ (50 : Nat) + q * 2 ^ (64 : Nat) := by - unfold getTickLog2After50Word - have hb := getTickLog2BitsAfter51Nat_lt_twoPow13 I - have hf := getTickSourceLogStepFNat_le_1 (getTickSourceLogRAfter51Nat I) - (getTickSourceLogRAfter51Nat_mul_self_lt_wordModulus I) - have hf50 : getTickSourceLogF50Nat I ≤ 1 := by - simpa [getTickSourceLogF50Nat] using hf - simpa [getTickLog2BitsAfter50Nat] using - getTickLog2AfterStepWord_toNat_of_prev - (getTickLog2Bit50Word I) (getTickLog2After51Word I) q - (getTickLog2BitsAfter51Nat I) (getTickSourceLogF50Nat I) 50 - (getTickLog2Bit50Word_toNat_eq_source I) - (getTickLog2After51Word_toNat_of_base I q hbase hq) - (by - norm_num at hb ⊢ - omega) - hf50 - (by - norm_num at hb hf50 ⊢ - omega) - hq - -theorem getTickSourceLog2After50Int_eq_base_add_bits (I : ExecutionEnv) : - getTickSourceLog2After50Int I = - getTickSourceLog2BaseInt I + - (getTickLog2BitsAfter50Nat I : Int) * (2 ^ (50 : Nat) : Int) := by - unfold getTickSourceLog2After50Int getTickSourceLog2After51Int - getTickSourceLog2After52Int getTickSourceLog2After53Int getTickSourceLog2After54Int - getTickSourceLog2After55Int getTickSourceLog2After56Int getTickSourceLog2After57Int - getTickSourceLog2After58Int getTickSourceLog2After59Int getTickSourceLog2After60Int - getTickSourceLog2After61Int getTickSourceLog2After62Int getTickSourceLog2After63Int - getTickSourceLog2AfterStep getTickSourceLogStepLog2AfterInt - getTickLog2BitsAfter50Nat getTickLog2BitsAfter51Nat getTickLog2BitsAfter52Nat - getTickLog2BitsAfter53Nat getTickLog2BitsAfter54Nat getTickLog2BitsAfter55Nat - getTickLog2BitsAfter56Nat getTickLog2BitsAfter57Nat getTickLog2BitsAfter58Nat - getTickLog2BitsAfter59Nat getTickLog2BitsAfter60Nat getTickLog2BitsAfter61Nat - getTickLog2BitsAfter62Nat getTickLog2BitsAfter63Nat getTickSourceLogF61Nat - getTickSourceLogF60Nat getTickSourceLogF50Nat - norm_num [Nat.cast_add, Nat.cast_mul] - ring_nf - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatio.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatio.lean deleted file mode 100644 index c5bc172d..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatio.lean +++ /dev/null @@ -1,838 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeSourceGetTickPostLog - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem getTickStoreForSqrtRatioAtTickHiCall_tick (I : ExecutionEnv) : - (getTickStoreForSqrtRatioAtTickHiCall I).get? "tick" = - some (getTickSourceTickHiValue I) := by - rw [getTickStoreForSqrtRatioAtTickHiCall, store_get_self] - -theorem evalExpr_getSqrtRatio_tickVar_forTickHi {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - evm (.var "tick") = .ok (getTickSourceTickHiValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreForSqrtRatioAtTickHiCall_tick] - -def getSqrtRatioSourceTickHiAbsTickInt (I : ExecutionEnv) : Int := - if getTickSourceTickHiInt I < 0 then 0 - getTickSourceTickHiInt I - else getTickSourceTickHiInt I - -def getSqrtRatioSourceTickHiAbsTickValue (I : ExecutionEnv) : Value := - .int (getSqrtRatioSourceTickHiAbsTickInt I) - -def getSqrtRatioStoreAfterTickHiAbsTick (I : ExecutionEnv) : Store := - (getTickStoreForSqrtRatioAtTickHiCall I).insert "absTick" - (getSqrtRatioSourceTickHiAbsTickValue I) - -theorem getSqrtRatioStoreAfterTickHiAbsTick_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiAbsTick I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - rw [getSqrtRatioStoreAfterTickHiAbsTick, store_get_self] - -theorem getSqrtRatioStoreAfterTickHiAbsTick_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiAbsTick I).get? "tick" = - some (getTickSourceTickHiValue I) := by - rw [getSqrtRatioStoreAfterTickHiAbsTick] - rw [store_get_ne (getTickStoreForSqrtRatioAtTickHiCall I) (k := "absTick") - (a := "tick") (getSqrtRatioSourceTickHiAbsTickValue I) (by decide)] - exact getTickStoreForSqrtRatioAtTickHiCall_tick I - -theorem evalExpr_getSqrtRatio_absTick_forTickHi {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - evm - (.ite (ltE (.var "tick") (.intLit 0)) - (subE (.intLit 0) (.var "tick")) - (.var "tick")) = .ok (getSqrtRatioSourceTickHiAbsTickValue I) := by - unfold getSqrtRatioSourceTickHiAbsTickValue getSqrtRatioSourceTickHiAbsTickInt ltE subE - by_cases hneg : getTickSourceTickHiInt I < 0 - · simp [evalExpr?, evalExpr_getSqrtRatio_tickVar_forTickHi, EvalResult.bind, bind, - pure, evalBinaryOp?, getTickSourceTickHiValue, hneg] - · simp [evalExpr?, evalExpr_getSqrtRatio_tickVar_forTickHi, EvalResult.bind, bind, - pure, evalBinaryOp?, getTickSourceTickHiValue, hneg] - -theorem evalExpr_getSqrtRatio_absTickVar_forTickHi {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiAbsTick I } - evm (.var "absTick") = .ok (getSqrtRatioSourceTickHiAbsTickValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getSqrtRatioStoreAfterTickHiAbsTick_absTick] - -theorem evalExpr_getSqrtRatio_absTickLeMax_forTickHi {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - evalExpr? (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiAbsTick I } - evm (leE (.var "absTick") maxTick) = .ok (.bool true) := by - unfold leE maxTick - simp [evalExpr?, evalExpr_getSqrtRatio_absTickVar_forTickHi, EvalResult.bind, bind, - pure, evalBinaryOp?, getSqrtRatioSourceTickHiAbsTickValue, hrange] - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiAbsTickPrefix - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - [ .letDecl "absTick" (some uint256) - (.ite (ltE (.var "tick") (.intLit 0)) - (subE (.intLit 0) (.var "tick")) - (.var "tick")), - .require (leE (.var "absTick") maxTick) ] - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiAbsTick I } evm) := by - refine ExecBlock.consNormal - (ExecStmt.letDecl (evalExpr_getSqrtRatio_absTick_forTickHi evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.requireTrue (evalExpr_getSqrtRatio_absTickLeMax_forTickHi evm I hrange)) - ExecBlock.nil - -def getSqrtRatioSourceTickHiBit1Int (I : ExecutionEnv) : Int := - Nat.land (getSqrtRatioSourceTickHiAbsTickInt I).toNat 1 - -def getSqrtRatioSourceTickHiInitialRatioInt (I : ExecutionEnv) : Int := - if getSqrtRatioSourceTickHiBit1Int I = 0 then 2 ^ (128 : Nat) - else 340265354078544963557816517032075149313 - -def getSqrtRatioSourceTickHiInitialRatioValue (I : ExecutionEnv) : Value := - .int (getSqrtRatioSourceTickHiInitialRatioInt I) - -def getSqrtRatioStoreAfterTickHiInitialRatio (I : ExecutionEnv) : Store := - (getSqrtRatioStoreAfterTickHiAbsTick I).insert "ratio" - (getSqrtRatioSourceTickHiInitialRatioValue I) - -theorem getSqrtRatioSourceTickHiAbsTickInt_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAbsTickInt I := by - unfold getSqrtRatioSourceTickHiAbsTickInt - by_cases h : getTickSourceTickHiInt I < 0 <;> omega - -theorem getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus - (I : ExecutionEnv) (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - getSqrtRatioSourceTickHiAbsTickInt I < (EVM.wordModulus : Int) := by - norm_num [EVM.wordModulus, EVM.twoPow] - omega - -theorem evalExpr_getSqrtRatio_absTickBit1_forTickHi {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - evalExpr? (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiAbsTick I } - evm (bitAndE (.var "absTick") (.intLit 1)) = - .ok (.int (getSqrtRatioSourceTickHiBit1Int I)) := by - unfold bitAndE getSqrtRatioSourceTickHiBit1Int - have hnonneg := getSqrtRatioSourceTickHiAbsTickInt_nonneg I - have hlt := getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange - have hone : 1 < EVM.wordModulus := by norm_num [EVM.wordModulus, EVM.twoPow] - simp [evalExpr?, evalExpr_getSqrtRatio_absTickVar_forTickHi, EvalResult.bind, bind, - pure, evalBinaryOp?, getSqrtRatioSourceTickHiAbsTickValue, hnonneg, hlt, hone] - -theorem evalExpr_getSqrtRatio_initialRatio_forTickHi {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - evalExpr? (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiAbsTick I } - evm - (.ite (neE (bitAndE (.var "absTick") (.intLit 0x1)) (.intLit 0)) - (.intLit 0xfffcb933bd6fad37aa2d162d1a594001) - fixedPoint128Q128) = - .ok (getSqrtRatioSourceTickHiInitialRatioValue I) := by - unfold getSqrtRatioSourceTickHiInitialRatioValue getSqrtRatioSourceTickHiInitialRatioInt - neE fixedPoint128Q128 - by_cases hzero : getSqrtRatioSourceTickHiBit1Int I = 0 - · simp [evalExpr?, evalExpr_getSqrtRatio_absTickBit1_forTickHi evm I hrange, - EvalResult.bind, bind, pure, evalBinaryOp?, hzero] - · have hbeq : - (Value.int (getSqrtRatioSourceTickHiBit1Int I) == Value.int 0) = false := by - cases h : (Value.int (getSqrtRatioSourceTickHiBit1Int I) == Value.int 0) <;> - simp_all - simp [evalExpr?, evalExpr_getSqrtRatio_absTickBit1_forTickHi evm I hrange, - EvalResult.bind, bind, pure, evalBinaryOp?, hzero, hbeq] - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiInitialRatioPrefix - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - [ .letDecl "absTick" (some uint256) - (.ite (ltE (.var "tick") (.intLit 0)) - (subE (.intLit 0) (.var "tick")) - (.var "tick")), - .require (leE (.var "absTick") maxTick), - .letDecl "ratio" (some uint256) - (.ite (neE (bitAndE (.var "absTick") (.intLit 0x1)) (.intLit 0)) - (.intLit 0xfffcb933bd6fad37aa2d162d1a594001) - fixedPoint128Q128) ] - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiInitialRatio I } - evm) := by - refine execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiAbsTickPrefix evm I hrange) ?_ - exact ExecBlock.consNormal - (ExecStmt.letDecl (evalExpr_getSqrtRatio_initialRatio_forTickHi evm I hrange)) - ExecBlock.nil - -def getSqrtRatioSourceTickRatioStepBitInt (absTick mask : Int) : Int := - Nat.land absTick.toNat mask.toNat - -def getSqrtRatioSourceTickRatioStepRatioInt - (absTick ratio mask constant : Int) : Int := - if getSqrtRatioSourceTickRatioStepBitInt absTick mask = 0 then ratio - else ((ratio * constant).toNat / 2 ^ (128 : Nat) : Nat) - -theorem getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (absTick ratio mask constant : Int) - (hratio0 : 0 ≤ ratio) : - 0 ≤ getSqrtRatioSourceTickRatioStepRatioInt absTick ratio mask constant := by - unfold getSqrtRatioSourceTickRatioStepRatioInt - by_cases h : getSqrtRatioSourceTickRatioStepBitInt absTick mask = 0 - · simp [h, hratio0] - · simp [h] - exact Int.ediv_nonneg (le_max_right _ _) (by norm_num) - -theorem getSqrtRatioSourceTickRatioStepRatioInt_le_input - (absTick ratio mask constant : Int) - (hratio0 : 0 ≤ ratio) (hconst0 : 0 ≤ constant) - (hconstLe : constant ≤ 2 ^ (128 : Nat)) : - getSqrtRatioSourceTickRatioStepRatioInt absTick ratio mask constant ≤ ratio := by - unfold getSqrtRatioSourceTickRatioStepRatioInt - by_cases h : getSqrtRatioSourceTickRatioStepBitInt absTick mask = 0 - · simp [h] - · simp [h] - apply Int.ediv_le_of_le_mul - · norm_num - · have hprod0 : 0 ≤ ratio * constant := mul_nonneg hratio0 hconst0 - rw [max_eq_left hprod0] - exact mul_le_mul_of_nonneg_left hconstLe hratio0 - -theorem getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (absTick ratio mask constant : Int) - (hratio0 : 0 ≤ ratio) (hratioLe : ratio ≤ 2 ^ (128 : Nat)) - (hconst0 : 0 ≤ constant) (hconstLe : constant ≤ 2 ^ (128 : Nat)) : - getSqrtRatioSourceTickRatioStepRatioInt absTick ratio mask constant ≤ - 2 ^ (128 : Nat) := by - exact le_trans - (getSqrtRatioSourceTickRatioStepRatioInt_le_input absTick ratio mask constant - hratio0 hconst0 hconstLe) - hratioLe - -theorem getSqrtRatioSourceRatio_mul_lt_wordModulus - (ratio constant : Int) - (hratioLe : ratio ≤ 2 ^ (128 : Nat)) - (hconst0 : 0 ≤ constant) (hconstLt : constant < 2 ^ (128 : Nat)) : - ratio * constant < (EVM.wordModulus : Int) := by - have hconstLe : constant ≤ (2 ^ (128 : Nat) : Int) - 1 := by omega - have hmulLe : - ratio * constant ≤ (2 ^ (128 : Nat) : Int) * - ((2 ^ (128 : Nat) : Int) - 1) := by - exact mul_le_mul hratioLe hconstLe hconst0 (by positivity) - have hcap : - (2 ^ (128 : Nat) : Int) * ((2 ^ (128 : Nat) : Int) - 1) < - (EVM.wordModulus : Int) := by - norm_num [EVM.wordModulus, EVM.twoPow] - omega - -def getSqrtRatioSourceTickRatioStepStoreAfter - (S : Store) (absTick ratio mask constant : Int) : Store := - if getSqrtRatioSourceTickRatioStepBitInt absTick mask = 0 then S - else - S.insert "ratio" - (.int (getSqrtRatioSourceTickRatioStepRatioInt absTick ratio mask constant)) - -theorem evalExpr_getSqrtRatio_absTickVar - {v : PoolImmutables} (evm : EVM.State) (S : Store) (absTick : Int) - (habs : S.get? "absTick" = some (.int absTick)) : - evalExpr? (config v) { contract := contract v, locals := S } evm (.var "absTick") = - .ok (.int absTick) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [habs] - -theorem evalExpr_getSqrtRatio_ratioVar - {v : PoolImmutables} (evm : EVM.State) (S : Store) (ratio : Int) - (hratio : S.get? "ratio" = some (.int ratio)) : - evalExpr? (config v) { contract := contract v, locals := S } evm (.var "ratio") = - .ok (.int ratio) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hratio] - -theorem evalExpr_getSqrtRatio_var_of_get - {v : PoolImmutables} (evm : EVM.State) (S : Store) (key : Ident) (value : Value) - (hget : S.get? key = some value) : - evalExpr? (config v) { contract := contract v, locals := S } evm (.var key) = - .ok value := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hget] - -theorem evalExpr_getSqrtRatio_tickRatioStepBit - {v : PoolImmutables} (evm : EVM.State) (S : Store) (absTick mask : Int) - (habs : S.get? "absTick" = some (.int absTick)) - (habs0 : 0 ≤ absTick) (habsLt : absTick < (EVM.wordModulus : Int)) - (hmask0 : 0 ≤ mask) (hmaskLt : mask < (EVM.wordModulus : Int)) : - evalExpr? (config v) { contract := contract v, locals := S } evm - (bitAndE (.var "absTick") (.intLit mask)) = - .ok (.int (getSqrtRatioSourceTickRatioStepBitInt absTick mask)) := by - unfold bitAndE getSqrtRatioSourceTickRatioStepBitInt - simp [evalExpr?, evalExpr_getSqrtRatio_absTickVar (v := v) evm S absTick habs, - EvalResult.bind, bind, pure, evalBinaryOp?, habs0, habsLt, hmask0, hmaskLt] - -theorem evalExpr_getSqrtRatio_tickRatioStepCond - {v : PoolImmutables} (evm : EVM.State) (S : Store) (absTick mask : Int) - (habs : S.get? "absTick" = some (.int absTick)) - (habs0 : 0 ≤ absTick) (habsLt : absTick < (EVM.wordModulus : Int)) - (hmask0 : 0 ≤ mask) (hmaskLt : mask < (EVM.wordModulus : Int)) : - evalExpr? (config v) { contract := contract v, locals := S } evm - (neE (bitAndE (.var "absTick") (.intLit mask)) (.intLit 0)) = - .ok (.bool (!(Value.int (getSqrtRatioSourceTickRatioStepBitInt absTick mask) == - Value.int 0))) := by - unfold neE - simp [evalExpr?, - evalExpr_getSqrtRatio_tickRatioStepBit (v := v) evm S absTick mask habs - habs0 habsLt hmask0 hmaskLt, - EvalResult.bind, bind, pure, evalBinaryOp?] - -theorem evalExpr_getSqrtRatio_tickRatioStepAssign - {v : PoolImmutables} (evm : EVM.State) (S : Store) (ratio constant : Int) - (hratio : S.get? "ratio" = some (.int ratio)) - (hmul0 : 0 ≤ ratio * constant) - (hmulLt : ratio * constant < (EVM.wordModulus : Int)) : - evalExpr? (config v) { contract := contract v, locals := S } evm - (shrE (mulE (.var "ratio") (.intLit constant)) shift128) = - .ok (.int ((ratio * constant).toNat / 2 ^ (128 : Nat) : Nat)) := by - unfold shrE mulE shift128 - simp only [evalExpr?, evalExpr_getSqrtRatio_ratioVar (v := v) evm S ratio hratio, - EvalResult.bind, bind, pure] - change evalBinaryOp? .shr (.int (ratio * constant)) (.int 128) = - .ok (.int ((ratio * constant).toNat / 2 ^ (128 : Nat) : Nat)) - rw [evalBinaryOp_int_shr_ok] - · rfl - · exact hmul0 - · exact hmulLt - · norm_num - · norm_num - -set_option maxRecDepth 4096 in -theorem getSqrtRatioSourceTickRatioStepExec - {v : PoolImmutables} (evm : EVM.State) - (S : Store) (absTick ratio mask constant : Int) - (habs : S.get? "absTick" = some (.int absTick)) - (hratio : S.get? "ratio" = some (.int ratio)) - (habs0 : 0 ≤ absTick) (habsLt : absTick < (EVM.wordModulus : Int)) - (hmask0 : 0 ≤ mask) (hmaskLt : mask < (EVM.wordModulus : Int)) - (hmul0 : 0 ≤ ratio * constant) - (hmulLt : ratio * constant < (EVM.wordModulus : Int)) : - ExecBlock (config v) { contract := contract v, locals := S } evm - (tickRatioStep mask constant) - (.ok - { contract := contract v, - locals := getSqrtRatioSourceTickRatioStepStoreAfter S absTick ratio mask constant } - evm) := by - unfold tickRatioStep - by_cases hzero : getSqrtRatioSourceTickRatioStepBitInt absTick mask = 0 - · refine ExecBlock.consNormal (ExecStmt.iteFalse ?_ ?_) ExecBlock.nil - · have hcond := - evalExpr_getSqrtRatio_tickRatioStepCond (v := v) evm S absTick mask habs - habs0 habsLt hmask0 hmaskLt - rw [hcond] - simp [hzero] - · simpa [getSqrtRatioSourceTickRatioStepStoreAfter, hzero] using - (ExecBlock.nil : - ExecBlock (config v) { contract := contract v, locals := S } evm [] - (.ok { contract := contract v, locals := S } evm)) - · refine ExecBlock.consNormal (ExecStmt.iteTrue ?_ ?_) ExecBlock.nil - · have hcond := - evalExpr_getSqrtRatio_tickRatioStepCond (v := v) evm S absTick mask habs - habs0 habsLt hmask0 hmaskLt - rw [hcond] - have hbeq : - (Value.int (getSqrtRatioSourceTickRatioStepBitInt absTick mask) == - Value.int 0) = false := by - cases h : (Value.int (getSqrtRatioSourceTickRatioStepBitInt absTick mask) == - Value.int 0) <;> simp_all - simp [hbeq] - · refine ExecBlock.consNormal - (ExecStmt.assign - (evalExpr_getSqrtRatio_tickRatioStepAssign (v := v) evm S ratio constant - hratio hmul0 hmulLt) ?_) - ExecBlock.nil - unfold assignStorageRef? - simp only [varRef] - rw [hratio] - simp [updateLocalPath?, getSqrtRatioSourceTickRatioStepStoreAfter, - getSqrtRatioSourceTickRatioStepRatioInt, hzero, EvalResult.bind, bind, pure] - -theorem getSqrtRatioSourceTickRatioStepExecOfBounded - {v : PoolImmutables} (evm : EVM.State) - (S : Store) (absTick ratio mask constant : Int) - (habs : S.get? "absTick" = some (.int absTick)) - (hratio : S.get? "ratio" = some (.int ratio)) - (habs0 : 0 ≤ absTick) (habsLt : absTick < (EVM.wordModulus : Int)) - (hmask0 : 0 ≤ mask) (hmaskLt : mask < (EVM.wordModulus : Int)) - (hratio0 : 0 ≤ ratio) (hratioLe : ratio ≤ 2 ^ (128 : Nat)) - (hconst0 : 0 ≤ constant) (hconstLt : constant < 2 ^ (128 : Nat)) : - ExecBlock (config v) { contract := contract v, locals := S } evm - (tickRatioStep mask constant) - (.ok - { contract := contract v, - locals := getSqrtRatioSourceTickRatioStepStoreAfter S absTick ratio mask constant } - evm) := by - exact getSqrtRatioSourceTickRatioStepExec (v := v) evm S absTick ratio mask constant - habs hratio habs0 habsLt hmask0 hmaskLt - (mul_nonneg hratio0 hconst0) - (getSqrtRatioSourceRatio_mul_lt_wordModulus ratio constant hratioLe hconst0 hconstLt) - -theorem getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (S : Store) (absTick ratio mask constant : Int) - (habs : S.get? "absTick" = some (.int absTick)) : - (getSqrtRatioSourceTickRatioStepStoreAfter S absTick ratio mask constant).get? - "absTick" = - some (.int absTick) := by - unfold getSqrtRatioSourceTickRatioStepStoreAfter - by_cases hzero : getSqrtRatioSourceTickRatioStepBitInt absTick mask = 0 - · rw [if_pos hzero] - exact habs - · rw [if_neg hzero] - rw [store_get_ne S (k := "ratio") (a := "absTick") - (.int (getSqrtRatioSourceTickRatioStepRatioInt absTick ratio mask constant)) - (by decide)] - exact habs - -theorem getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (S : Store) (absTick ratio mask constant : Int) - (hratio : S.get? "ratio" = some (.int ratio)) : - (getSqrtRatioSourceTickRatioStepStoreAfter S absTick ratio mask constant).get? "ratio" = - some (.int (getSqrtRatioSourceTickRatioStepRatioInt absTick ratio mask constant)) := by - unfold getSqrtRatioSourceTickRatioStepStoreAfter - by_cases hzero : getSqrtRatioSourceTickRatioStepBitInt absTick mask = 0 - · rw [if_pos hzero] - simpa [getSqrtRatioSourceTickRatioStepRatioInt, hzero] using hratio - · rw [if_neg hzero] - rw [store_get_self] - -theorem getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (S : Store) (absTick ratio mask constant : Int) (key : Ident) - (hkey : ("ratio" == key) = false) : - (getSqrtRatioSourceTickRatioStepStoreAfter S absTick ratio mask constant).get? key = - S.get? key := by - unfold getSqrtRatioSourceTickRatioStepStoreAfter - by_cases hzero : getSqrtRatioSourceTickRatioStepBitInt absTick mask = 0 - · rw [if_pos hzero] - · rw [if_neg hzero] - rw [store_get_ne S (k := "ratio") (a := key) - (.int (getSqrtRatioSourceTickRatioStepRatioInt absTick ratio mask constant)) - hkey] - -theorem getSqrtRatioStoreAfterTickHiInitialRatio_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiInitialRatio I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - rw [getSqrtRatioStoreAfterTickHiInitialRatio] - rw [store_get_ne (getSqrtRatioStoreAfterTickHiAbsTick I) (k := "ratio") - (a := "absTick") (getSqrtRatioSourceTickHiInitialRatioValue I) (by decide)] - exact getSqrtRatioStoreAfterTickHiAbsTick_absTick I - -theorem getSqrtRatioStoreAfterTickHiInitialRatio_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiInitialRatio I).get? "ratio" = - some (getSqrtRatioSourceTickHiInitialRatioValue I) := by - rw [getSqrtRatioStoreAfterTickHiInitialRatio, store_get_self] - -theorem getSqrtRatioStoreAfterTickHiInitialRatio_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiInitialRatio I).get? "tick" = - some (getTickSourceTickHiValue I) := by - rw [getSqrtRatioStoreAfterTickHiInitialRatio] - rw [store_get_ne (getSqrtRatioStoreAfterTickHiAbsTick I) (k := "ratio") - (a := "tick") (getSqrtRatioSourceTickHiInitialRatioValue I) (by decide)] - exact getSqrtRatioStoreAfterTickHiAbsTick_tick I - -def getSqrtRatioSourceFactor2Int : Int := - 340248342086729790484326174814286782778 - -def getSqrtRatioSourceTickHiAfterBit2Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiInitialRatioInt I) - 2 - getSqrtRatioSourceFactor2Int - -def getSqrtRatioStoreAfterTickHiBit2 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiInitialRatio I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiInitialRatioInt I) - 2 - getSqrtRatioSourceFactor2Int - -theorem getSqrtRatioSourceTickHiInitialRatioInt_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiInitialRatioInt I := by - unfold getSqrtRatioSourceTickHiInitialRatioInt - by_cases h : getSqrtRatioSourceTickHiBit1Int I = 0 <;> simp [h] - -theorem getSqrtRatioSourceTickHiInitialRatioInt_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiInitialRatioInt I ≤ 2 ^ (128 : Nat) := by - unfold getSqrtRatioSourceTickHiInitialRatioInt - by_cases h : getSqrtRatioSourceTickHiBit1Int I = 0 <;> simp [h] - -theorem getSqrtRatioSourceTickHiAfterBit2Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit2Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit2Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiInitialRatioInt I) - 2 - getSqrtRatioSourceFactor2Int - (getSqrtRatioSourceTickHiInitialRatioInt_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit2Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit2Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit2Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiInitialRatioInt I) - 2 - getSqrtRatioSourceFactor2Int - (getSqrtRatioSourceTickHiInitialRatioInt_nonneg I) - (getSqrtRatioSourceTickHiInitialRatioInt_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor2Int]) - (by norm_num [getSqrtRatioSourceFactor2Int]) - -theorem getSqrtRatioSourceTickHiInitialRatio_mul_factor2_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiInitialRatioInt I * getSqrtRatioSourceFactor2Int := by - have h0 := getSqrtRatioSourceTickHiInitialRatioInt_nonneg I - unfold getSqrtRatioSourceFactor2Int - positivity - -theorem getSqrtRatioSourceTickHiInitialRatio_mul_factor2_lt_wordModulus - (I : ExecutionEnv) : - getSqrtRatioSourceTickHiInitialRatioInt I * getSqrtRatioSourceFactor2Int < - (EVM.wordModulus : Int) := by - unfold getSqrtRatioSourceTickHiInitialRatioInt getSqrtRatioSourceFactor2Int - by_cases h : getSqrtRatioSourceTickHiBit1Int I = 0 - · simp [h, EVM.wordModulus, EVM.twoPow] - · simp [h, EVM.wordModulus, EVM.twoPow] - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit2 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiInitialRatio I } evm - (tickRatioStep 0x2 0xfff97272373d413259a46990580e213a) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit2 I } evm) := by - exact getSqrtRatioSourceTickRatioStepExec (v := v) evm - (getSqrtRatioStoreAfterTickHiInitialRatio I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiInitialRatioInt I) - 2 - getSqrtRatioSourceFactor2Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiInitialRatio_absTick I) - (by - simpa [getSqrtRatioSourceTickHiInitialRatioValue] using - getSqrtRatioStoreAfterTickHiInitialRatio_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiInitialRatio_mul_factor2_nonneg I) - (getSqrtRatioSourceTickHiInitialRatio_mul_factor2_lt_wordModulus I) - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit2 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - ([ .letDecl "absTick" (some uint256) - (.ite (ltE (.var "tick") (.intLit 0)) - (subE (.intLit 0) (.var "tick")) - (.var "tick")), - .require (leE (.var "absTick") maxTick), - .letDecl "ratio" (some uint256) - (.ite (neE (bitAndE (.var "absTick") (.intLit 0x1)) (.intLit 0)) - (.intLit 0xfffcb933bd6fad37aa2d162d1a594001) - fixedPoint128Q128) ] ++ - tickRatioStep 0x2 0xfff97272373d413259a46990580e213a) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit2 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiInitialRatioPrefix evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit2 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit2_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit2 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit2, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiInitialRatio I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiInitialRatioInt I) - 2 - getSqrtRatioSourceFactor2Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiInitialRatio_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit2_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit2 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit2Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit2, getSqrtRatioSourceTickHiAfterBit2Int, - getSqrtRatioSourceTickHiInitialRatioValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiInitialRatio I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiInitialRatioInt I) - 2 - getSqrtRatioSourceFactor2Int - (by - simpa [getSqrtRatioSourceTickHiInitialRatioValue] using - getSqrtRatioStoreAfterTickHiInitialRatio_ratio I) - -theorem getSqrtRatioStoreAfterTickHiBit2_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit2 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit2] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiInitialRatio I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiInitialRatioInt I) - 2 - getSqrtRatioSourceFactor2Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiInitialRatio_tick I) - -def getSqrtRatioSourceFactor4Int : Int := - 340214320654664324051920982716015181260 - -def getSqrtRatioSourceTickHiAfterBit4Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2Int I) - 4 - getSqrtRatioSourceFactor4Int - -def getSqrtRatioStoreAfterTickHiBit4 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit2 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2Int I) - 4 - getSqrtRatioSourceFactor4Int - -theorem getSqrtRatioSourceTickHiAfterBit4Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit4Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit4Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2Int I) - 4 - getSqrtRatioSourceFactor4Int - (getSqrtRatioSourceTickHiAfterBit2Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit4Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit4Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit4Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2Int I) - 4 - getSqrtRatioSourceFactor4Int - (getSqrtRatioSourceTickHiAfterBit2Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit2Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor4Int]) - (by norm_num [getSqrtRatioSourceFactor4Int]) - -theorem getSqrtRatioSourceTickHiAfterBit2_mul_factor4_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit2Int I * getSqrtRatioSourceFactor4Int := by - unfold getSqrtRatioSourceTickHiAfterBit2Int getSqrtRatioSourceTickRatioStepRatioInt - getSqrtRatioSourceFactor2Int getSqrtRatioSourceFactor4Int - by_cases h2 : - getSqrtRatioSourceTickRatioStepBitInt (getSqrtRatioSourceTickHiAbsTickInt I) 2 = 0 - · simp [h2] - exact getSqrtRatioSourceTickHiInitialRatioInt_nonneg I - · simp [h2] - exact Int.ediv_nonneg (le_max_right _ _) (by norm_num) - -theorem getSqrtRatioSourceTickHiAfterBit2_mul_factor4_lt_wordModulus - (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit2Int I * getSqrtRatioSourceFactor4Int < - (EVM.wordModulus : Int) := by - unfold getSqrtRatioSourceTickHiAfterBit2Int getSqrtRatioSourceTickRatioStepRatioInt - getSqrtRatioSourceFactor2Int getSqrtRatioSourceFactor4Int - getSqrtRatioSourceTickHiInitialRatioInt - by_cases h2 : - getSqrtRatioSourceTickRatioStepBitInt (getSqrtRatioSourceTickHiAbsTickInt I) 2 = 0 - · by_cases h1 : getSqrtRatioSourceTickHiBit1Int I = 0 - · simp [h2, h1, EVM.wordModulus, EVM.twoPow] - · simp [h2, h1, EVM.wordModulus, EVM.twoPow] - · by_cases h1 : getSqrtRatioSourceTickHiBit1Int I = 0 - · simp [h2, h1, EVM.wordModulus, EVM.twoPow] - · simp [h2, h1, EVM.wordModulus, EVM.twoPow] - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit4 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit2 I } evm - (tickRatioStep 0x4 0xfff2e50f5f656932ef12357cf3c7fdcc) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit4 I } evm) := by - exact getSqrtRatioSourceTickRatioStepExec (v := v) evm - (getSqrtRatioStoreAfterTickHiBit2 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2Int I) - 4 - getSqrtRatioSourceFactor4Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit2_absTick I) - (getSqrtRatioStoreAfterTickHiBit2_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit2_mul_factor4_nonneg I) - (getSqrtRatioSourceTickHiAfterBit2_mul_factor4_lt_wordModulus I) - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit4 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - (([ .letDecl "absTick" (some uint256) - (.ite (ltE (.var "tick") (.intLit 0)) - (subE (.intLit 0) (.var "tick")) - (.var "tick")), - .require (leE (.var "absTick") maxTick), - .letDecl "ratio" (some uint256) - (.ite (neE (bitAndE (.var "absTick") (.intLit 0x1)) (.intLit 0)) - (.intLit 0xfffcb933bd6fad37aa2d162d1a594001) - fixedPoint128Q128) ] ++ - tickRatioStep 0x2 0xfff97272373d413259a46990580e213a) ++ - tickRatioStep 0x4 0xfff2e50f5f656932ef12357cf3c7fdcc) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit4 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit2 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit4 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit4_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit4 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit4, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit2 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2Int I) - 4 - getSqrtRatioSourceFactor4Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit2_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit4_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit4 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit4Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit4, getSqrtRatioSourceTickHiAfterBit4Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit2 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2Int I) - 4 - getSqrtRatioSourceFactor4Int - (getSqrtRatioStoreAfterTickHiBit2_ratio I) - -theorem getSqrtRatioStoreAfterTickHiBit4_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit4 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit4] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit2 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2Int I) - 4 - getSqrtRatioSourceFactor4Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit2_tick I) - -def getSqrtRatioSourceFactor8Int : Int := - 340146287995602323631171512101879684304 - -def getSqrtRatioSourceTickHiAfterBit8Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4Int I) - 8 - getSqrtRatioSourceFactor8Int - -def getSqrtRatioStoreAfterTickHiBit8 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit4 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4Int I) - 8 - getSqrtRatioSourceFactor8Int - -theorem getSqrtRatioSourceTickHiAfterBit4_mul_factor8_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit4Int I * getSqrtRatioSourceFactor8Int := by - exact mul_nonneg - (getSqrtRatioSourceTickHiAfterBit4Int_nonneg I) - (by norm_num [getSqrtRatioSourceFactor8Int]) - -theorem getSqrtRatioSourceTickHiAfterBit4_mul_factor8_lt_wordModulus - (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit4Int I * getSqrtRatioSourceFactor8Int < - (EVM.wordModulus : Int) := by - exact getSqrtRatioSourceRatio_mul_lt_wordModulus - (getSqrtRatioSourceTickHiAfterBit4Int I) - getSqrtRatioSourceFactor8Int - (getSqrtRatioSourceTickHiAfterBit4Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor8Int]) - (by norm_num [getSqrtRatioSourceFactor8Int]) - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit8 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit4 I } evm - (tickRatioStep 0x8 0xffe5caca7e10e4e61c3624eaa0941cd0) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit8 I } evm) := by - exact getSqrtRatioSourceTickRatioStepExec (v := v) evm - (getSqrtRatioStoreAfterTickHiBit4 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4Int I) - 8 - getSqrtRatioSourceFactor8Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit4_absTick I) - (getSqrtRatioStoreAfterTickHiBit4_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit4_mul_factor8_nonneg I) - (getSqrtRatioSourceTickHiAfterBit4_mul_factor8_lt_wordModulus I) - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit8 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - ((([ .letDecl "absTick" (some uint256) - (.ite (ltE (.var "tick") (.intLit 0)) - (subE (.intLit 0) (.var "tick")) - (.var "tick")), - .require (leE (.var "absTick") maxTick), - .letDecl "ratio" (some uint256) - (.ite (neE (bitAndE (.var "absTick") (.intLit 0x1)) (.intLit 0)) - (.intLit 0xfffcb933bd6fad37aa2d162d1a594001) - fixedPoint128Q128) ] ++ - tickRatioStep 0x2 0xfff97272373d413259a46990580e213a) ++ - tickRatioStep 0x4 0xfff2e50f5f656932ef12357cf3c7fdcc) ++ - tickRatioStep 0x8 0xffe5caca7e10e4e61c3624eaa0941cd0) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit8 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit4 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit8 evm I hrange) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioHighBits.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioHighBits.lean deleted file mode 100644 index 62531f05..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioHighBits.lean +++ /dev/null @@ -1,1493 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeSourceGetSqrtRatioLowBits - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem getSqrtRatioStoreAfterTickHiBit1024_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit1024 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit1024, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit512 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit512Int I) - 1024 - getSqrtRatioSourceFactor1024Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit512_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit1024_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit1024 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit1024Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit1024, getSqrtRatioSourceTickHiAfterBit1024Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit512 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit512Int I) - 1024 - getSqrtRatioSourceFactor1024Int - (getSqrtRatioStoreAfterTickHiBit512_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit1024Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit1024Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit1024Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit512Int I) - 1024 - getSqrtRatioSourceFactor1024Int - (getSqrtRatioSourceTickHiAfterBit512Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit1024Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit1024Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit1024Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit512Int I) - 1024 - getSqrtRatioSourceFactor1024Int - (getSqrtRatioSourceTickHiAfterBit512Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit512Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor1024Int]) - (by norm_num [getSqrtRatioSourceFactor1024Int]) - -def getSqrtRatioSourceFactor2048Int : Int := - 307163716377032989948697243942600083929 - -def getSqrtRatioSourceTickHiAfterBit2048Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit1024Int I) - 2048 - getSqrtRatioSourceFactor2048Int - -def getSqrtRatioStoreAfterTickHiBit2048 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit1024 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit1024Int I) - 2048 - getSqrtRatioSourceFactor2048Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit2048 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit1024 I } evm - (tickRatioStep 0x800 0xe7159475a2c29b7443b29c7fa6e889d9) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit2048 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit1024 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit1024Int I) - 2048 - getSqrtRatioSourceFactor2048Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit1024_absTick I) - (getSqrtRatioStoreAfterTickHiBit1024_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit1024Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit1024Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor2048Int]) - (by norm_num [getSqrtRatioSourceFactor2048Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit2048 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit1024 ++ - tickRatioStep 0x800 0xe7159475a2c29b7443b29c7fa6e889d9 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit2048 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit2048 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit2048 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit1024 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit2048 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit2048_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit2048 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit2048, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit1024 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit1024Int I) - 2048 - getSqrtRatioSourceFactor2048Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit1024_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit2048_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit2048 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit2048Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit2048, getSqrtRatioSourceTickHiAfterBit2048Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit1024 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit1024Int I) - 2048 - getSqrtRatioSourceFactor2048Int - (getSqrtRatioStoreAfterTickHiBit1024_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit2048Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit2048Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit2048Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit1024Int I) - 2048 - getSqrtRatioSourceFactor2048Int - (getSqrtRatioSourceTickHiAfterBit1024Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit2048Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit2048Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit2048Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit1024Int I) - 2048 - getSqrtRatioSourceFactor2048Int - (getSqrtRatioSourceTickHiAfterBit1024Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit1024Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor2048Int]) - (by norm_num [getSqrtRatioSourceFactor2048Int]) - -def getSqrtRatioSourceFactor4096Int : Int := - 277268403626896220162999269216087595045 - -def getSqrtRatioSourceTickHiAfterBit4096Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2048Int I) - 4096 - getSqrtRatioSourceFactor4096Int - -def getSqrtRatioStoreAfterTickHiBit4096 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit2048 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2048Int I) - 4096 - getSqrtRatioSourceFactor4096Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit4096 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit2048 I } evm - (tickRatioStep 0x1000 0xd097f3bdfd2022b8845ad8f792aa5825) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit4096 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit2048 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2048Int I) - 4096 - getSqrtRatioSourceFactor4096Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit2048_absTick I) - (getSqrtRatioStoreAfterTickHiBit2048_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit2048Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit2048Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor4096Int]) - (by norm_num [getSqrtRatioSourceFactor4096Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit4096 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit2048 ++ - tickRatioStep 0x1000 0xd097f3bdfd2022b8845ad8f792aa5825 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit4096 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit4096 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit4096 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit2048 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit4096 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit4096_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit4096 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit4096, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit2048 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2048Int I) - 4096 - getSqrtRatioSourceFactor4096Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit2048_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit4096_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit4096 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit4096Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit4096, getSqrtRatioSourceTickHiAfterBit4096Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit2048 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2048Int I) - 4096 - getSqrtRatioSourceFactor4096Int - (getSqrtRatioStoreAfterTickHiBit2048_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit4096Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit4096Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit4096Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2048Int I) - 4096 - getSqrtRatioSourceFactor4096Int - (getSqrtRatioSourceTickHiAfterBit2048Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit4096Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit4096Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit4096Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2048Int I) - 4096 - getSqrtRatioSourceFactor4096Int - (getSqrtRatioSourceTickHiAfterBit2048Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit2048Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor4096Int]) - (by norm_num [getSqrtRatioSourceFactor4096Int]) - -def getSqrtRatioSourceFactor8192Int : Int := - 225923453940442621947126027127485391333 - -def getSqrtRatioSourceTickHiAfterBit8192Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4096Int I) - 8192 - getSqrtRatioSourceFactor8192Int - -def getSqrtRatioStoreAfterTickHiBit8192 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit4096 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4096Int I) - 8192 - getSqrtRatioSourceFactor8192Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit8192 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit4096 I } evm - (tickRatioStep 0x2000 0xa9f746462d870fdf8a65dc1f90e061e5) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit8192 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit4096 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4096Int I) - 8192 - getSqrtRatioSourceFactor8192Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit4096_absTick I) - (getSqrtRatioStoreAfterTickHiBit4096_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit4096Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit4096Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor8192Int]) - (by norm_num [getSqrtRatioSourceFactor8192Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit8192 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit4096 ++ - tickRatioStep 0x2000 0xa9f746462d870fdf8a65dc1f90e061e5 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit8192 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit8192 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit8192 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit4096 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit8192 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit8192_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit8192 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit8192, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit4096 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4096Int I) - 8192 - getSqrtRatioSourceFactor8192Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit4096_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit8192_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit8192 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit8192Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit8192, getSqrtRatioSourceTickHiAfterBit8192Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit4096 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4096Int I) - 8192 - getSqrtRatioSourceFactor8192Int - (getSqrtRatioStoreAfterTickHiBit4096_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit8192Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit8192Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit8192Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4096Int I) - 8192 - getSqrtRatioSourceFactor8192Int - (getSqrtRatioSourceTickHiAfterBit4096Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit8192Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit8192Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit8192Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4096Int I) - 8192 - getSqrtRatioSourceFactor8192Int - (getSqrtRatioSourceTickHiAfterBit4096Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit4096Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor8192Int]) - (by norm_num [getSqrtRatioSourceFactor8192Int]) - -def getSqrtRatioSourceFactor16384Int : Int := - 149997214084966997727330242082538205943 - -def getSqrtRatioSourceTickHiAfterBit16384Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8192Int I) - 16384 - getSqrtRatioSourceFactor16384Int - -def getSqrtRatioStoreAfterTickHiBit16384 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit8192 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8192Int I) - 16384 - getSqrtRatioSourceFactor16384Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit16384 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit8192 I } evm - (tickRatioStep 0x4000 0x70d869a156d2a1b890bb3df62baf32f7) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit16384 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit8192 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8192Int I) - 16384 - getSqrtRatioSourceFactor16384Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit8192_absTick I) - (getSqrtRatioStoreAfterTickHiBit8192_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit8192Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit8192Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor16384Int]) - (by norm_num [getSqrtRatioSourceFactor16384Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit16384 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit8192 ++ - tickRatioStep 0x4000 0x70d869a156d2a1b890bb3df62baf32f7 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit16384 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit16384 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit16384 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit8192 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit16384 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit16384_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit16384 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit16384, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit8192 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8192Int I) - 16384 - getSqrtRatioSourceFactor16384Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit8192_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit16384_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit16384 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit16384Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit16384, getSqrtRatioSourceTickHiAfterBit16384Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit8192 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8192Int I) - 16384 - getSqrtRatioSourceFactor16384Int - (getSqrtRatioStoreAfterTickHiBit8192_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit16384Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit16384Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit16384Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8192Int I) - 16384 - getSqrtRatioSourceFactor16384Int - (getSqrtRatioSourceTickHiAfterBit8192Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit16384Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit16384Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit16384Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8192Int I) - 16384 - getSqrtRatioSourceFactor16384Int - (getSqrtRatioSourceTickHiAfterBit8192Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit8192Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor16384Int]) - (by norm_num [getSqrtRatioSourceFactor16384Int]) - -def getSqrtRatioSourceFactor32768Int : Int := - 66119101136024775622716233608466517926 - -def getSqrtRatioSourceTickHiAfterBit32768Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16384Int I) - 32768 - getSqrtRatioSourceFactor32768Int - -def getSqrtRatioStoreAfterTickHiBit32768 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit16384 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16384Int I) - 32768 - getSqrtRatioSourceFactor32768Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit32768 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit16384 I } evm - (tickRatioStep 0x8000 0x31be135f97d08fd981231505542fcfa6) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit32768 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit16384 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16384Int I) - 32768 - getSqrtRatioSourceFactor32768Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit16384_absTick I) - (getSqrtRatioStoreAfterTickHiBit16384_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit16384Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit16384Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor32768Int]) - (by norm_num [getSqrtRatioSourceFactor32768Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit32768 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit16384 ++ - tickRatioStep 0x8000 0x31be135f97d08fd981231505542fcfa6 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit32768 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit32768 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit32768 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit16384 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit32768 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit32768_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit32768 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit32768, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit16384 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16384Int I) - 32768 - getSqrtRatioSourceFactor32768Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit16384_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit32768_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit32768 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit32768Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit32768, getSqrtRatioSourceTickHiAfterBit32768Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit16384 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16384Int I) - 32768 - getSqrtRatioSourceFactor32768Int - (getSqrtRatioStoreAfterTickHiBit16384_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit32768Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit32768Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit32768Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16384Int I) - 32768 - getSqrtRatioSourceFactor32768Int - (getSqrtRatioSourceTickHiAfterBit16384Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit32768Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit32768Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit32768Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16384Int I) - 32768 - getSqrtRatioSourceFactor32768Int - (getSqrtRatioSourceTickHiAfterBit16384Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit16384Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor32768Int]) - (by norm_num [getSqrtRatioSourceFactor32768Int]) - -def getSqrtRatioSourceFactor65536Int : Int := - 12847376061809297530290974190478138313 - -def getSqrtRatioSourceTickHiAfterBit65536Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32768Int I) - 65536 - getSqrtRatioSourceFactor65536Int - -def getSqrtRatioStoreAfterTickHiBit65536 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit32768 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32768Int I) - 65536 - getSqrtRatioSourceFactor65536Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit65536 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit32768 I } evm - (tickRatioStep 0x10000 0x9aa508b5b7a84e1c677de54f3e99bc9) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit65536 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit32768 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32768Int I) - 65536 - getSqrtRatioSourceFactor65536Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit32768_absTick I) - (getSqrtRatioStoreAfterTickHiBit32768_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit32768Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit32768Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor65536Int]) - (by norm_num [getSqrtRatioSourceFactor65536Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit65536 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit32768 ++ - tickRatioStep 0x10000 0x9aa508b5b7a84e1c677de54f3e99bc9 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit65536 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit65536 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit65536 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit32768 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit65536 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit65536_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit65536 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit65536, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit32768 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32768Int I) - 65536 - getSqrtRatioSourceFactor65536Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit32768_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit65536_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit65536 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit65536Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit65536, getSqrtRatioSourceTickHiAfterBit65536Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit32768 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32768Int I) - 65536 - getSqrtRatioSourceFactor65536Int - (getSqrtRatioStoreAfterTickHiBit32768_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit65536Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit65536Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit65536Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32768Int I) - 65536 - getSqrtRatioSourceFactor65536Int - (getSqrtRatioSourceTickHiAfterBit32768Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit65536Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit65536Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit65536Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32768Int I) - 65536 - getSqrtRatioSourceFactor65536Int - (getSqrtRatioSourceTickHiAfterBit32768Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit32768Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor65536Int]) - (by norm_num [getSqrtRatioSourceFactor65536Int]) - -def getSqrtRatioSourceFactor131072Int : Int := - 485053260817066172746253684029974020 - -def getSqrtRatioSourceTickHiAfterBit131072Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit65536Int I) - 131072 - getSqrtRatioSourceFactor131072Int - -def getSqrtRatioStoreAfterTickHiBit131072 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit65536 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit65536Int I) - 131072 - getSqrtRatioSourceFactor131072Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit131072 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit65536 I } evm - (tickRatioStep 0x20000 0x5d6af8dedb81196699c329225ee604) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit131072 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit65536 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit65536Int I) - 131072 - getSqrtRatioSourceFactor131072Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit65536_absTick I) - (getSqrtRatioStoreAfterTickHiBit65536_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit65536Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit65536Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor131072Int]) - (by norm_num [getSqrtRatioSourceFactor131072Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit131072 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit65536 ++ - tickRatioStep 0x20000 0x5d6af8dedb81196699c329225ee604 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit131072 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit131072 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit131072 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit65536 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit131072 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit131072_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit131072 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit131072, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit65536 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit65536Int I) - 131072 - getSqrtRatioSourceFactor131072Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit65536_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit131072_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit131072 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit131072Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit131072, getSqrtRatioSourceTickHiAfterBit131072Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit65536 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit65536Int I) - 131072 - getSqrtRatioSourceFactor131072Int - (getSqrtRatioStoreAfterTickHiBit65536_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit131072Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit131072Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit131072Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit65536Int I) - 131072 - getSqrtRatioSourceFactor131072Int - (getSqrtRatioSourceTickHiAfterBit65536Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit131072Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit131072Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit131072Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit65536Int I) - 131072 - getSqrtRatioSourceFactor131072Int - (getSqrtRatioSourceTickHiAfterBit65536Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit65536Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor131072Int]) - (by norm_num [getSqrtRatioSourceFactor131072Int]) - -def getSqrtRatioSourceFactor262144Int : Int := - 691415978906521570653435304214168 - -def getSqrtRatioSourceTickHiAfterBit262144Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit131072Int I) - 262144 - getSqrtRatioSourceFactor262144Int - -def getSqrtRatioStoreAfterTickHiBit262144 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit131072 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit131072Int I) - 262144 - getSqrtRatioSourceFactor262144Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit262144 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit131072 I } evm - (tickRatioStep 0x40000 0x2216e584f5fa1ea926041bedfe98) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit262144 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit131072 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit131072Int I) - 262144 - getSqrtRatioSourceFactor262144Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit131072_absTick I) - (getSqrtRatioStoreAfterTickHiBit131072_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit131072Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit131072Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor262144Int]) - (by norm_num [getSqrtRatioSourceFactor262144Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit262144 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit131072 ++ - tickRatioStep 0x40000 0x2216e584f5fa1ea926041bedfe98 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit262144 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit262144 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit262144 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit131072 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit262144 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit262144_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit262144 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit262144, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit131072 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit131072Int I) - 262144 - getSqrtRatioSourceFactor262144Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit131072_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit262144_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit262144 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit262144Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit262144, getSqrtRatioSourceTickHiAfterBit262144Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit131072 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit131072Int I) - 262144 - getSqrtRatioSourceFactor262144Int - (getSqrtRatioStoreAfterTickHiBit131072_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit262144Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit262144Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit262144Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit131072Int I) - 262144 - getSqrtRatioSourceFactor262144Int - (getSqrtRatioSourceTickHiAfterBit131072Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit262144Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit262144Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit262144Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit131072Int I) - 262144 - getSqrtRatioSourceFactor262144Int - (getSqrtRatioSourceTickHiAfterBit131072Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit131072Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor262144Int]) - (by norm_num [getSqrtRatioSourceFactor262144Int]) - -def getSqrtRatioSourceFactor524288Int : Int := - 1404880482679654955896180642 - -def getSqrtRatioSourceTickHiAfterBit524288Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit262144Int I) - 524288 - getSqrtRatioSourceFactor524288Int - -def getSqrtRatioStoreAfterTickHiBit524288 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit262144 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit262144Int I) - 524288 - getSqrtRatioSourceFactor524288Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit524288 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit262144 I } evm - (tickRatioStep 0x80000 0x48a170391f7dc42444e8fa2) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit524288 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit262144 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit262144Int I) - 524288 - getSqrtRatioSourceFactor524288Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit262144_absTick I) - (getSqrtRatioStoreAfterTickHiBit262144_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit262144Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit262144Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor524288Int]) - (by norm_num [getSqrtRatioSourceFactor524288Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit524288 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit262144 ++ - tickRatioStep 0x80000 0x48a170391f7dc42444e8fa2 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit524288 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit524288 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit524288 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit262144 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit524288 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit2048_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit2048 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit2048] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit1024 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit1024Int I) - 2048 - getSqrtRatioSourceFactor2048Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit1024_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit4096_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit4096 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit4096] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit2048 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit2048Int I) - 4096 - getSqrtRatioSourceFactor4096Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit2048_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit8192_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit8192 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit8192] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit4096 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4096Int I) - 8192 - getSqrtRatioSourceFactor8192Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit4096_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit16384_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit16384 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit16384] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit8192 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8192Int I) - 16384 - getSqrtRatioSourceFactor16384Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit8192_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit32768_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit32768 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit32768] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit16384 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16384Int I) - 32768 - getSqrtRatioSourceFactor32768Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit16384_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit65536_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit65536 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit65536] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit32768 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32768Int I) - 65536 - getSqrtRatioSourceFactor65536Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit32768_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit131072_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit131072 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit131072] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit65536 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit65536Int I) - 131072 - getSqrtRatioSourceFactor131072Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit65536_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit262144_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit262144 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit262144] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit131072 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit131072Int I) - 262144 - getSqrtRatioSourceFactor262144Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit131072_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit524288_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit524288 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit524288] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit262144 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit262144Int I) - 524288 - getSqrtRatioSourceFactor524288Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit262144_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit524288_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit524288 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit524288Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit524288, getSqrtRatioSourceTickHiAfterBit524288Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit262144 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit262144Int I) - 524288 - getSqrtRatioSourceFactor524288Int - (getSqrtRatioStoreAfterTickHiBit262144_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit524288Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit524288Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit524288Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit262144Int I) - 524288 - getSqrtRatioSourceFactor524288Int - (getSqrtRatioSourceTickHiAfterBit262144Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit524288Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit524288Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit524288Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit262144Int I) - 524288 - getSqrtRatioSourceFactor524288Int - (getSqrtRatioSourceTickHiAfterBit262144Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit262144Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor524288Int]) - (by norm_num [getSqrtRatioSourceFactor524288Int]) - -def getSqrtRatioSourceFinalRatioIntOf (tick ratio : Int) : Int := - if 0 < tick then (2 ^ (256 : Nat) - 1) / ratio else ratio - -def getSqrtRatioSourceFinalRatioStoreOf (S : Store) (tick ratio : Int) : Store := - if 0 < tick then S.insert "ratio" (.int (getSqrtRatioSourceFinalRatioIntOf tick ratio)) - else S - -def getSqrtRatioSourceReturnExpr : Expr := - addE (shrE (.var "ratio") shift32) - (.ite (eqE (modE (.var "ratio") uint32Modulus) (.intLit 0)) - (.intLit 0) (.intLit 1)) - -def getSqrtRatioSourceReturnIntOf (ratio : Int) : Int := - ((ratio.toNat / 2 ^ (32 : Nat) : Nat) : Int) + - if Value.int (ratio % (2 ^ (32 : Nat) : Int)) == Value.int 0 then 0 else 1 - -def getSqrtRatioSourceReturnValueOf (ratio : Int) : Value := - .int (getSqrtRatioSourceReturnIntOf ratio) - -def getSqrtRatioSourceTailBlock : List Stmt := - [ Stmt.ite (gtE (.var "tick") (.intLit 0)) - [ .assign .localVar (varRef "ratio") (divE uint256MaxExpr (.var "ratio")) ] - [], - .return [getSqrtRatioSourceReturnExpr] ] - -def getSqrtRatioSourceTickHiFinalRatioInt (I : ExecutionEnv) : Int := - getSqrtRatioSourceFinalRatioIntOf - (getTickSourceTickHiInt I) - (getSqrtRatioSourceTickHiAfterBit524288Int I) - -def getSqrtRatioStoreAfterTickHiFinalRatio (I : ExecutionEnv) : Store := - getSqrtRatioSourceFinalRatioStoreOf - (getSqrtRatioStoreAfterTickHiBit524288 I) - (getTickSourceTickHiInt I) - (getSqrtRatioSourceTickHiAfterBit524288Int I) - -theorem getSqrtRatioSourceFinalRatioStoreOf_ratio - (S : Store) (tick ratio : Int) - (hratio : S.get? "ratio" = some (.int ratio)) : - (getSqrtRatioSourceFinalRatioStoreOf S tick ratio).get? "ratio" = - some (.int (getSqrtRatioSourceFinalRatioIntOf tick ratio)) := by - unfold getSqrtRatioSourceFinalRatioStoreOf - by_cases hpos : 0 < tick - · rw [if_pos hpos, store_get_self] - · rw [if_neg hpos] - simpa [getSqrtRatioSourceFinalRatioIntOf, hpos] using hratio - -theorem getSqrtRatioSourceFinalRatioStoreOf_tick - (S : Store) (tick ratio : Int) (value : Value) - (htick : S.get? "tick" = some value) : - (getSqrtRatioSourceFinalRatioStoreOf S tick ratio).get? "tick" = some value := by - unfold getSqrtRatioSourceFinalRatioStoreOf - by_cases hpos : 0 < tick - · rw [if_pos hpos] - rw [store_get_ne S (k := "ratio") (a := "tick") - (.int (getSqrtRatioSourceFinalRatioIntOf tick ratio)) (by decide)] - exact htick - · rw [if_neg hpos] - exact htick - -theorem getSqrtRatioStoreAfterTickHiFinalRatio_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiFinalRatio I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiFinalRatioInt I)) := by - simpa [getSqrtRatioStoreAfterTickHiFinalRatio, getSqrtRatioSourceTickHiFinalRatioInt] using - getSqrtRatioSourceFinalRatioStoreOf_ratio - (getSqrtRatioStoreAfterTickHiBit524288 I) - (getTickSourceTickHiInt I) - (getSqrtRatioSourceTickHiAfterBit524288Int I) - (getSqrtRatioStoreAfterTickHiBit524288_ratio I) - -theorem getSqrtRatioStoreAfterTickHiFinalRatio_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiFinalRatio I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiFinalRatio] using - getSqrtRatioSourceFinalRatioStoreOf_tick - (getSqrtRatioStoreAfterTickHiBit524288 I) - (getTickSourceTickHiInt I) - (getSqrtRatioSourceTickHiAfterBit524288Int I) - (getTickSourceTickHiValue I) - (getSqrtRatioStoreAfterTickHiBit524288_tick I) - -theorem evalExpr_getSqrtRatio_tickPosCond - {v : PoolImmutables} (evm : EVM.State) (S : Store) (tick : Int) - (htick : S.get? "tick" = some (.int tick)) : - evalExpr? (config v) { contract := contract v, locals := S } evm - (gtE (.var "tick") (.intLit 0)) = .ok (.bool (0 < tick)) := by - unfold gtE - have hvar := - evalExpr_getSqrtRatio_var_of_get (v := v) evm S "tick" (.int tick) htick - simp only [evalExpr?, hvar, EvalResult.bind, bind, pure, evalBinaryOp?] - -theorem evalExpr_getSqrtRatio_finalRatioAssign - {v : PoolImmutables} (evm : EVM.State) (S : Store) (tick ratio : Int) - (hratio : S.get? "ratio" = some (.int ratio)) - (hden : ratio ≠ 0) (hpos : 0 < tick) : - evalExpr? (config v) { contract := contract v, locals := S } evm - (divE uint256MaxExpr (.var "ratio")) = - .ok (.int (getSqrtRatioSourceFinalRatioIntOf tick ratio)) := by - unfold divE uint256MaxExpr getSqrtRatioSourceFinalRatioIntOf - have hvar := - evalExpr_getSqrtRatio_var_of_get (v := v) evm S "ratio" (.int ratio) hratio - simp only [evalExpr?, hvar, EvalResult.bind, bind, pure, evalBinaryOp?] - simp [hpos, hden] - -theorem getSqrtRatioSourceFinalRatioIntOf_nonneg (tick ratio : Int) - (hratio0 : 0 ≤ ratio) : - 0 ≤ getSqrtRatioSourceFinalRatioIntOf tick ratio := by - unfold getSqrtRatioSourceFinalRatioIntOf - by_cases hpos : 0 < tick - · rw [if_pos hpos] - exact Int.ediv_nonneg (by norm_num) hratio0 - · rw [if_neg hpos] - exact hratio0 - -theorem getSqrtRatioSourceFinalRatioIntOf_lt_wordModulus (tick ratio : Int) - (hratioLt : ratio < (EVM.wordModulus : Int)) : - getSqrtRatioSourceFinalRatioIntOf tick ratio < (EVM.wordModulus : Int) := by - unfold getSqrtRatioSourceFinalRatioIntOf - by_cases hpos : 0 < tick - · rw [if_pos hpos] - exact lt_of_le_of_lt - (Int.ediv_le_self ratio (by norm_num : 0 ≤ (2 ^ (256 : Nat) - 1 : Int))) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - · rw [if_neg hpos] - exact hratioLt - -theorem evalExpr_getSqrtRatio_returnExpr - {v : PoolImmutables} (evm : EVM.State) (S : Store) (ratio : Int) - (hratio : S.get? "ratio" = some (.int ratio)) - (hratio0 : 0 ≤ ratio) (hratioLt : ratio < (EVM.wordModulus : Int)) : - evalExpr? (config v) { contract := contract v, locals := S } evm - getSqrtRatioSourceReturnExpr = .ok (getSqrtRatioSourceReturnValueOf ratio) := by - unfold getSqrtRatioSourceReturnExpr getSqrtRatioSourceReturnValueOf - getSqrtRatioSourceReturnIntOf addE shrE eqE modE shift32 uint32Modulus - have hvar := - evalExpr_getSqrtRatio_var_of_get (v := v) evm S "ratio" (.int ratio) hratio - have hshr : - evalBinaryOp? .shr (.int ratio) (.int 32) = - .ok (.int (ratio.toNat / 2 ^ (32 : Nat))) := by - simpa using evalBinaryOp_int_shr_ok (x := ratio) (s := 32) hratio0 hratioLt - (by norm_num) (by norm_num) - by_cases hbeq : - (Value.int (ratio % (2 ^ (32 : Nat) : Int)) == Value.int 0) = true - · norm_num at hbeq - have hmod : ratio % (4294967296 : Int) = 0 := - Int.emod_eq_zero_of_dvd hbeq - have hbeqValue : - (Value.int (ratio % (4294967296 : Int)) == Value.int 0) = true := by - simp [hmod] - simp only [evalExpr?, hvar, EvalResult.bind, bind, pure] - rw [hshr] - simp [evalBinaryOp?, hmod, hratio0] - · have hbeqFalse : - (Value.int (ratio % (2 ^ (32 : Nat) : Int)) == Value.int 0) = false := by - cases h : (Value.int (ratio % (2 ^ (32 : Nat) : Int)) == Value.int 0) <;> - simp_all - norm_num at hbeqFalse - have hmodNe : ratio % (4294967296 : Int) ≠ 0 := by - intro hmod - exact hbeqFalse (Int.dvd_of_emod_eq_zero hmod) - have hbeqValue : - (Value.int (ratio % (4294967296 : Int)) == Value.int 0) = false := by - cases h : (Value.int (ratio % (4294967296 : Int)) == Value.int 0) <;> - simp_all - simp only [evalExpr?, hvar, EvalResult.bind, bind, pure] - rw [hshr] - simp [evalBinaryOp?, hbeqValue, hratio0] - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceFinalRatioOf - {v : PoolImmutables} (evm : EVM.State) (S : Store) (tick ratio : Int) - (htick : S.get? "tick" = some (.int tick)) - (hratio : S.get? "ratio" = some (.int ratio)) - (hden : ratio ≠ 0) : - ExecBlock (config v) { contract := contract v, locals := S } evm - [ Stmt.ite (gtE (.var "tick") (.intLit 0)) - [ .assign .localVar (varRef "ratio") (divE uint256MaxExpr (.var "ratio")) ] - [] ] - (.ok - { contract := contract v, - locals := getSqrtRatioSourceFinalRatioStoreOf S tick ratio } - evm) := by - by_cases hpos : 0 < tick - · refine ExecBlock.consNormal (ExecStmt.iteTrue ?_ ?_) ExecBlock.nil - · rw [evalExpr_getSqrtRatio_tickPosCond (v := v) evm S tick htick] - simp [hpos] - · refine ExecBlock.consNormal - (ExecStmt.assign - (evalExpr_getSqrtRatio_finalRatioAssign (v := v) evm S tick ratio hratio hden hpos) - ?_) - ExecBlock.nil - unfold assignStorageRef? - simp only [varRef] - rw [hratio] - simp [updateLocalPath?, getSqrtRatioSourceFinalRatioStoreOf, - getSqrtRatioSourceFinalRatioIntOf, hpos, EvalResult.bind, bind, pure] - · refine ExecBlock.consNormal (ExecStmt.iteFalse ?_ ?_) ExecBlock.nil - · rw [evalExpr_getSqrtRatio_tickPosCond (v := v) evm S tick htick] - simp [hpos] - · simpa [getSqrtRatioSourceFinalRatioStoreOf, hpos] using - (ExecBlock.nil : - ExecBlock (config v) { contract := contract v, locals := S } evm [] - (.ok { contract := contract v, locals := S } evm)) - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTailOf - {v : PoolImmutables} (evm : EVM.State) (S : Store) (tick ratio : Int) - (htick : S.get? "tick" = some (.int tick)) - (hratio : S.get? "ratio" = some (.int ratio)) - (hratio0 : 0 ≤ ratio) (hratioLt : ratio < (EVM.wordModulus : Int)) - (hden : ratio ≠ 0) : - ExecBlock (config v) { contract := contract v, locals := S } evm - getSqrtRatioSourceTailBlock - (.returned - { contract := contract v, - locals := getSqrtRatioSourceFinalRatioStoreOf S tick ratio } - evm (some [getSqrtRatioSourceReturnValueOf - (getSqrtRatioSourceFinalRatioIntOf tick ratio)])) := by - unfold getSqrtRatioSourceTailBlock - have hfinal := - uniswapV3PoolGetSqrtRatioAtTickSourceFinalRatioOf (v := v) evm S tick ratio - htick hratio hden - have hratioFinal := - getSqrtRatioSourceFinalRatioStoreOf_ratio S tick ratio hratio - have hfinal0 : - 0 ≤ getSqrtRatioSourceFinalRatioIntOf tick ratio := - getSqrtRatioSourceFinalRatioIntOf_nonneg tick ratio hratio0 - have hfinalLt : - getSqrtRatioSourceFinalRatioIntOf tick ratio < (EVM.wordModulus : Int) := - getSqrtRatioSourceFinalRatioIntOf_lt_wordModulus tick ratio hratioLt - have hret := - evalExpr_getSqrtRatio_returnExpr (v := v) evm - (getSqrtRatioSourceFinalRatioStoreOf S tick ratio) - (getSqrtRatioSourceFinalRatioIntOf tick ratio) - hratioFinal hfinal0 hfinalLt - exact execBlock_append hfinal - (ExecBlock.consReturn (ExecStmt.return (evalExprs?_singleton hret))) - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiTail - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hden : getSqrtRatioSourceTickHiAfterBit524288Int I ≠ 0) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit524288 I } evm - getSqrtRatioSourceTailBlock - (.returned { contract := contract v, locals := getSqrtRatioStoreAfterTickHiFinalRatio I } - evm (some [getSqrtRatioSourceReturnValueOf - (getSqrtRatioSourceTickHiFinalRatioInt I)])) := by - have htick : - (getSqrtRatioStoreAfterTickHiBit524288 I).get? "tick" = - some (.int (getTickSourceTickHiInt I)) := by - simpa [getTickSourceTickHiValue] using getSqrtRatioStoreAfterTickHiBit524288_tick I - have hratio := - getSqrtRatioStoreAfterTickHiBit524288_ratio I - have hratioLt : - getSqrtRatioSourceTickHiAfterBit524288Int I < (EVM.wordModulus : Int) := by - exact lt_of_le_of_lt - (getSqrtRatioSourceTickHiAfterBit524288Int_le_q128 I) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - simpa [getSqrtRatioStoreAfterTickHiFinalRatio, getSqrtRatioSourceTickHiFinalRatioInt] - using - uniswapV3PoolGetSqrtRatioAtTickSourceTailOf (v := v) evm - (getSqrtRatioStoreAfterTickHiBit524288 I) - (getTickSourceTickHiInt I) - (getSqrtRatioSourceTickHiAfterBit524288Int I) - htick hratio - (getSqrtRatioSourceTickHiAfterBit524288Int_nonneg I) - hratioLt - hden - -theorem getSqrtRatioAtTickFunction_body_eq_tickHiSourceBlocks : - getSqrtRatioAtTickFunction.body = - getSqrtRatioSourceTickHiPrefixThroughBit524288 ++ getSqrtRatioSourceTailBlock := by - rfl - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBodyOfReturnEq - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) - (hden : getSqrtRatioSourceTickHiAfterBit524288Int I ≠ 0) - (hret : - getSqrtRatioSourceReturnValueOf (getSqrtRatioSourceTickHiFinalRatioInt I) = - getTickSourceSqrtRatioAtTickHiValue I) : - ExecFuncBody (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - evm getSqrtRatioAtTickFunction.body - (.returned { contract := contract v, locals := getSqrtRatioStoreAfterTickHiFinalRatio I } - evm (some [getTickSourceSqrtRatioAtTickHiValue I])) := by - refine ExecFuncBody.execBlockRet ?_ - rw [getSqrtRatioAtTickFunction_body_eq_tickHiSourceBlocks] - have hprefix := - uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit524288 (v := v) evm I hrange - have htail := - uniswapV3PoolGetSqrtRatioAtTickSourceTickHiTail (v := v) evm I hden - simpa [hret] using execBlock_append hprefix htail - -set_option maxRecDepth 20000 in -theorem evalExpr_getSqrtRatio_tickVar_afterBit524288 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit524288 I } - evm (.var "tick") = .ok (getTickSourceTickHiValue I) := by - exact evalExpr_getSqrtRatio_var_of_get evm - (getSqrtRatioStoreAfterTickHiBit524288 I) - "tick" - (getTickSourceTickHiValue I) - (getSqrtRatioStoreAfterTickHiBit524288_tick I) - -set_option maxRecDepth 20000 in -theorem evalExpr_getSqrtRatio_tickPosCond_afterBit524288 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit524288 I } - evm (gtE (.var "tick") (.intLit 0)) = - .ok (.bool (0 < getTickSourceTickHiInt I)) := by - unfold gtE - simp only [evalExpr?, evalExpr_getSqrtRatio_tickVar_afterBit524288, EvalResult.bind, - bind, pure, evalBinaryOp?] - simp [getTickSourceTickHiValue] - -set_option maxRecDepth 20000 in -theorem evalExpr_getSqrtRatio_ratioVar_afterBit524288 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit524288 I } - evm (.var "ratio") = .ok (.int (getSqrtRatioSourceTickHiAfterBit524288Int I)) := by - exact evalExpr_getSqrtRatio_var_of_get evm - (getSqrtRatioStoreAfterTickHiBit524288 I) - "ratio" - (.int (getSqrtRatioSourceTickHiAfterBit524288Int I)) - (getSqrtRatioStoreAfterTickHiBit524288_ratio I) - -set_option maxRecDepth 20000 in -theorem evalExpr_getSqrtRatio_finalRatioAssign_afterBit524288 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hden : getSqrtRatioSourceTickHiAfterBit524288Int I ≠ 0) - (hpos : 0 < getTickSourceTickHiInt I) : - evalExpr? (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit524288 I } - evm (divE uint256MaxExpr (.var "ratio")) = - .ok (.int (getSqrtRatioSourceTickHiFinalRatioInt I)) := by - unfold divE uint256MaxExpr getSqrtRatioSourceTickHiFinalRatioInt - getSqrtRatioSourceFinalRatioIntOf - simp only [evalExpr?, evalExpr_getSqrtRatio_ratioVar_afterBit524288, EvalResult.bind, - bind, pure, evalBinaryOp?] - simp [hpos, hden] - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioLowBits.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioLowBits.lean deleted file mode 100644 index f4d4e3fb..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetSqrtRatioLowBits.lean +++ /dev/null @@ -1,911 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeSourceGetSqrtRatio - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def getSqrtRatioSourceTickHiInitialRatioPrefixBlock : List Stmt := - [ .letDecl "absTick" (some uint256) - (.ite (ltE (.var "tick") (.intLit 0)) - (subE (.intLit 0) (.var "tick")) - (.var "tick")), - .require (leE (.var "absTick") maxTick), - .letDecl "ratio" (some uint256) - (.ite (neE (bitAndE (.var "absTick") (.intLit 0x1)) (.intLit 0)) - (.intLit 0xfffcb933bd6fad37aa2d162d1a594001) - fixedPoint128Q128) ] - -def getSqrtRatioSourceTickHiPrefixThroughBit8 : List Stmt := - (((getSqrtRatioSourceTickHiInitialRatioPrefixBlock ++ - tickRatioStep 0x2 0xfff97272373d413259a46990580e213a) ++ - tickRatioStep 0x4 0xfff2e50f5f656932ef12357cf3c7fdcc) ++ - tickRatioStep 0x8 0xffe5caca7e10e4e61c3624eaa0941cd0) - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit8Block - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit8 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit8 I } - evm) := by - simpa [getSqrtRatioSourceTickHiPrefixThroughBit8, - getSqrtRatioSourceTickHiInitialRatioPrefixBlock] using - uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit8 evm I hrange - -theorem getSqrtRatioStoreAfterTickHiBit8_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit8 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit8, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit4 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4Int I) - 8 - getSqrtRatioSourceFactor8Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit4_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit8_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit8 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit8Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit8, getSqrtRatioSourceTickHiAfterBit8Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit4 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4Int I) - 8 - getSqrtRatioSourceFactor8Int - (getSqrtRatioStoreAfterTickHiBit4_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit8Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit8Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit8Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4Int I) - 8 - getSqrtRatioSourceFactor8Int - (getSqrtRatioSourceTickHiAfterBit4Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit8Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit8Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit8Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4Int I) - 8 - getSqrtRatioSourceFactor8Int - (getSqrtRatioSourceTickHiAfterBit4Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit4Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor8Int]) - (by norm_num [getSqrtRatioSourceFactor8Int]) - -def getSqrtRatioSourceFactor16Int : Int := - 340010263488231146823593991679159461444 - -def getSqrtRatioSourceTickHiAfterBit16Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8Int I) - 16 - getSqrtRatioSourceFactor16Int - -def getSqrtRatioStoreAfterTickHiBit16 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit8 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8Int I) - 16 - getSqrtRatioSourceFactor16Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit16 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit8 I } evm - (tickRatioStep 0x10 0xffcb9843d60f6159c9db58835c926644) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit16 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit8 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8Int I) - 16 - getSqrtRatioSourceFactor16Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit8_absTick I) - (getSqrtRatioStoreAfterTickHiBit8_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit8Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit8Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor16Int]) - (by norm_num [getSqrtRatioSourceFactor16Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit16 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit8 ++ - tickRatioStep 0x10 0xffcb9843d60f6159c9db58835c926644 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit16 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit16 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit16 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit8Block evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit16 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit16_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit16 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit16, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit8 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8Int I) - 16 - getSqrtRatioSourceFactor16Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit8_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit16_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit16 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit16Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit16, getSqrtRatioSourceTickHiAfterBit16Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit8 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8Int I) - 16 - getSqrtRatioSourceFactor16Int - (getSqrtRatioStoreAfterTickHiBit8_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit16Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit16Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit16Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8Int I) - 16 - getSqrtRatioSourceFactor16Int - (getSqrtRatioSourceTickHiAfterBit8Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit16Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit16Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit16Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8Int I) - 16 - getSqrtRatioSourceFactor16Int - (getSqrtRatioSourceTickHiAfterBit8Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit8Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor16Int]) - (by norm_num [getSqrtRatioSourceFactor16Int]) - -def getSqrtRatioSourceFactor32Int : Int := - 339738377640345403697157401104375502016 - -def getSqrtRatioSourceTickHiAfterBit32Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16Int I) - 32 - getSqrtRatioSourceFactor32Int - -def getSqrtRatioStoreAfterTickHiBit32 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit16 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16Int I) - 32 - getSqrtRatioSourceFactor32Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit32 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit16 I } evm - (tickRatioStep 0x20 0xff973b41fa98c081472e6896dfb254c0) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit32 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit16 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16Int I) - 32 - getSqrtRatioSourceFactor32Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit16_absTick I) - (getSqrtRatioStoreAfterTickHiBit16_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit16Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit16Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor32Int]) - (by norm_num [getSqrtRatioSourceFactor32Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit32 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit16 ++ - tickRatioStep 0x20 0xff973b41fa98c081472e6896dfb254c0 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit32 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit32 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit32 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit16 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit32 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit32_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit32 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit32, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit16 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16Int I) - 32 - getSqrtRatioSourceFactor32Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit16_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit32_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit32 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit32Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit32, getSqrtRatioSourceTickHiAfterBit32Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit16 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16Int I) - 32 - getSqrtRatioSourceFactor32Int - (getSqrtRatioStoreAfterTickHiBit16_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit32Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit32Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit32Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16Int I) - 32 - getSqrtRatioSourceFactor32Int - (getSqrtRatioSourceTickHiAfterBit16Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit32Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit32Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit32Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16Int I) - 32 - getSqrtRatioSourceFactor32Int - (getSqrtRatioSourceTickHiAfterBit16Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit16Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor32Int]) - (by norm_num [getSqrtRatioSourceFactor32Int]) - -def getSqrtRatioSourceFactor64Int : Int := - 339195258003219555707034227454543997025 - -def getSqrtRatioSourceTickHiAfterBit64Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32Int I) - 64 - getSqrtRatioSourceFactor64Int - -def getSqrtRatioStoreAfterTickHiBit64 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit32 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32Int I) - 64 - getSqrtRatioSourceFactor64Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit64 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit32 I } evm - (tickRatioStep 0x40 0xff2ea16466c96a3843ec78b326b52861) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit64 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit32 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32Int I) - 64 - getSqrtRatioSourceFactor64Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit32_absTick I) - (getSqrtRatioStoreAfterTickHiBit32_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit32Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit32Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor64Int]) - (by norm_num [getSqrtRatioSourceFactor64Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit64 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit32 ++ - tickRatioStep 0x40 0xff2ea16466c96a3843ec78b326b52861 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit64 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit64 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit64 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit32 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit64 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit64_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit64 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit64, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit32 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32Int I) - 64 - getSqrtRatioSourceFactor64Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit32_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit64_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit64 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit64Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit64, getSqrtRatioSourceTickHiAfterBit64Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit32 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32Int I) - 64 - getSqrtRatioSourceFactor64Int - (getSqrtRatioStoreAfterTickHiBit32_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit64Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit64Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit64Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32Int I) - 64 - getSqrtRatioSourceFactor64Int - (getSqrtRatioSourceTickHiAfterBit32Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit64Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit64Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit64Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32Int I) - 64 - getSqrtRatioSourceFactor64Int - (getSqrtRatioSourceTickHiAfterBit32Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit32Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor64Int]) - (by norm_num [getSqrtRatioSourceFactor64Int]) - -def getSqrtRatioSourceFactor128Int : Int := - 338111622100601834656805679988414885971 - -def getSqrtRatioSourceTickHiAfterBit128Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit64Int I) - 128 - getSqrtRatioSourceFactor128Int - -def getSqrtRatioStoreAfterTickHiBit128 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit64 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit64Int I) - 128 - getSqrtRatioSourceFactor128Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit128 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit64 I } evm - (tickRatioStep 0x80 0xfe5dee046a99a2a811c461f1969c3053) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit128 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit64 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit64Int I) - 128 - getSqrtRatioSourceFactor128Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit64_absTick I) - (getSqrtRatioStoreAfterTickHiBit64_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit64Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit64Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor128Int]) - (by norm_num [getSqrtRatioSourceFactor128Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit128 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit64 ++ - tickRatioStep 0x80 0xfe5dee046a99a2a811c461f1969c3053 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit128 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit128 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit128 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit64 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit128 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit128_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit128 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit128, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit64 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit64Int I) - 128 - getSqrtRatioSourceFactor128Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit64_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit128_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit128 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit128Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit128, getSqrtRatioSourceTickHiAfterBit128Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit64 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit64Int I) - 128 - getSqrtRatioSourceFactor128Int - (getSqrtRatioStoreAfterTickHiBit64_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit128Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit128Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit128Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit64Int I) - 128 - getSqrtRatioSourceFactor128Int - (getSqrtRatioSourceTickHiAfterBit64Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit128Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit128Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit128Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit64Int I) - 128 - getSqrtRatioSourceFactor128Int - (getSqrtRatioSourceTickHiAfterBit64Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit64Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor128Int]) - (by norm_num [getSqrtRatioSourceFactor128Int]) - -def getSqrtRatioSourceFactor256Int : Int := - 335954724994790223023589805789778977700 - -def getSqrtRatioSourceTickHiAfterBit256Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit128Int I) - 256 - getSqrtRatioSourceFactor256Int - -def getSqrtRatioStoreAfterTickHiBit256 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit128 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit128Int I) - 256 - getSqrtRatioSourceFactor256Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit256 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit128 I } evm - (tickRatioStep 0x100 0xfcbe86c7900a88aedcffc83b479aa3a4) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit256 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit128 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit128Int I) - 256 - getSqrtRatioSourceFactor256Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit128_absTick I) - (getSqrtRatioStoreAfterTickHiBit128_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit128Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit128Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor256Int]) - (by norm_num [getSqrtRatioSourceFactor256Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit256 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit128 ++ - tickRatioStep 0x100 0xfcbe86c7900a88aedcffc83b479aa3a4 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit256 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit256 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit256 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit128 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit256 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit256_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit256 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit256, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit128 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit128Int I) - 256 - getSqrtRatioSourceFactor256Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit128_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit256_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit256 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit256Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit256, getSqrtRatioSourceTickHiAfterBit256Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit128 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit128Int I) - 256 - getSqrtRatioSourceFactor256Int - (getSqrtRatioStoreAfterTickHiBit128_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit256Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit256Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit256Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit128Int I) - 256 - getSqrtRatioSourceFactor256Int - (getSqrtRatioSourceTickHiAfterBit128Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit256Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit256Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit256Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit128Int I) - 256 - getSqrtRatioSourceFactor256Int - (getSqrtRatioSourceTickHiAfterBit128Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit128Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor256Int]) - (by norm_num [getSqrtRatioSourceFactor256Int]) - -def getSqrtRatioSourceFactor512Int : Int := - 331682121138379247127172139078559817300 - -def getSqrtRatioSourceTickHiAfterBit512Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit256Int I) - 512 - getSqrtRatioSourceFactor512Int - -def getSqrtRatioStoreAfterTickHiBit512 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit256 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit256Int I) - 512 - getSqrtRatioSourceFactor512Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit512 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit256 I } evm - (tickRatioStep 0x200 0xf987a7253ac413176f2b074cf7815e54) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit512 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit256 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit256Int I) - 512 - getSqrtRatioSourceFactor512Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit256_absTick I) - (getSqrtRatioStoreAfterTickHiBit256_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit256Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit256Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor512Int]) - (by norm_num [getSqrtRatioSourceFactor512Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit512 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit256 ++ - tickRatioStep 0x200 0xf987a7253ac413176f2b074cf7815e54 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit512 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit512 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit512 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit256 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit512 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit512_absTick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit512 I).get? "absTick" = - some (getSqrtRatioSourceTickHiAbsTickValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit512, getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioSourceTickRatioStepStoreAfter_absTick - (getSqrtRatioStoreAfterTickHiBit256 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit256Int I) - 512 - getSqrtRatioSourceFactor512Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit256_absTick I) - -theorem getSqrtRatioStoreAfterTickHiBit512_ratio (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit512 I).get? "ratio" = - some (.int (getSqrtRatioSourceTickHiAfterBit512Int I)) := by - simpa [getSqrtRatioStoreAfterTickHiBit512, getSqrtRatioSourceTickHiAfterBit512Int] using - getSqrtRatioSourceTickRatioStepStoreAfter_ratio - (getSqrtRatioStoreAfterTickHiBit256 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit256Int I) - 512 - getSqrtRatioSourceFactor512Int - (getSqrtRatioStoreAfterTickHiBit256_ratio I) - -theorem getSqrtRatioSourceTickHiAfterBit512Int_nonneg (I : ExecutionEnv) : - 0 ≤ getSqrtRatioSourceTickHiAfterBit512Int I := by - simpa [getSqrtRatioSourceTickHiAfterBit512Int] using - getSqrtRatioSourceTickRatioStepRatioInt_nonneg - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit256Int I) - 512 - getSqrtRatioSourceFactor512Int - (getSqrtRatioSourceTickHiAfterBit256Int_nonneg I) - -theorem getSqrtRatioSourceTickHiAfterBit512Int_le_q128 (I : ExecutionEnv) : - getSqrtRatioSourceTickHiAfterBit512Int I ≤ 2 ^ (128 : Nat) := by - simpa [getSqrtRatioSourceTickHiAfterBit512Int] using - getSqrtRatioSourceTickRatioStepRatioInt_le_q128 - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit256Int I) - 512 - getSqrtRatioSourceFactor512Int - (getSqrtRatioSourceTickHiAfterBit256Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit256Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor512Int]) - (by norm_num [getSqrtRatioSourceFactor512Int]) - -def getSqrtRatioSourceFactor1024Int : Int := - 323299236684853023288211250268160618739 - -def getSqrtRatioSourceTickHiAfterBit1024Int (I : ExecutionEnv) : Int := - getSqrtRatioSourceTickRatioStepRatioInt - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit512Int I) - 1024 - getSqrtRatioSourceFactor1024Int - -def getSqrtRatioStoreAfterTickHiBit1024 (I : ExecutionEnv) : Store := - getSqrtRatioSourceTickRatioStepStoreAfter - (getSqrtRatioStoreAfterTickHiBit512 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit512Int I) - 1024 - getSqrtRatioSourceFactor1024Int - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit1024 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit512 I } evm - (tickRatioStep 0x400 0xf3392b0822b70005940c7a398e4b70f3) - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit1024 I } - evm) := by - exact getSqrtRatioSourceTickRatioStepExecOfBounded (v := v) evm - (getSqrtRatioStoreAfterTickHiBit512 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit512Int I) - 1024 - getSqrtRatioSourceFactor1024Int - (by - simpa [getSqrtRatioSourceTickHiAbsTickValue] using - getSqrtRatioStoreAfterTickHiBit512_absTick I) - (getSqrtRatioStoreAfterTickHiBit512_ratio I) - (getSqrtRatioSourceTickHiAbsTickInt_nonneg I) - (getSqrtRatioSourceTickHiAbsTickInt_lt_wordModulus I hrange) - (by norm_num) - (by norm_num [EVM.wordModulus, EVM.twoPow]) - (getSqrtRatioSourceTickHiAfterBit512Int_nonneg I) - (getSqrtRatioSourceTickHiAfterBit512Int_le_q128 I) - (by norm_num [getSqrtRatioSourceFactor1024Int]) - (by norm_num [getSqrtRatioSourceFactor1024Int]) - -def getSqrtRatioSourceTickHiPrefixThroughBit1024 : List Stmt := - getSqrtRatioSourceTickHiPrefixThroughBit512 ++ - tickRatioStep 0x400 0xf3392b0822b70005940c7a398e4b70f3 - -theorem uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit1024 - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hrange : getSqrtRatioSourceTickHiAbsTickInt I ≤ 887272) : - ExecBlock (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } evm - getSqrtRatioSourceTickHiPrefixThroughBit1024 - (.ok { contract := contract v, locals := getSqrtRatioStoreAfterTickHiBit1024 I } - evm) := by - exact execBlock_append - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiThroughBit512 evm I hrange) - (uniswapV3PoolGetSqrtRatioAtTickSourceTickHiBit1024 evm I hrange) - -theorem getSqrtRatioStoreAfterTickHiBit8_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit8 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit8] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit4 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit4Int I) - 8 - getSqrtRatioSourceFactor8Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit4_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit16_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit16 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit16] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit8 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit8Int I) - 16 - getSqrtRatioSourceFactor16Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit8_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit32_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit32 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit32] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit16 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit16Int I) - 32 - getSqrtRatioSourceFactor32Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit16_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit64_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit64 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit64] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit32 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit32Int I) - 64 - getSqrtRatioSourceFactor64Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit32_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit128_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit128 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit128] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit64 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit64Int I) - 128 - getSqrtRatioSourceFactor128Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit64_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit256_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit256 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit256] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit128 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit128Int I) - 256 - getSqrtRatioSourceFactor256Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit128_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit512_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit512 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit512] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit256 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit256Int I) - 512 - getSqrtRatioSourceFactor512Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit256_tick I) - -theorem getSqrtRatioStoreAfterTickHiBit1024_tick (I : ExecutionEnv) : - (getSqrtRatioStoreAfterTickHiBit1024 I).get? "tick" = - some (getTickSourceTickHiValue I) := by - simpa [getSqrtRatioStoreAfterTickHiBit1024] using - getSqrtRatioSourceTickRatioStepStoreAfter_preserve_of_ne - (getSqrtRatioStoreAfterTickHiBit512 I) - (getSqrtRatioSourceTickHiAbsTickInt I) - (getSqrtRatioSourceTickHiAfterBit512Int I) - 1024 - getSqrtRatioSourceFactor1024Int - "tick" - (by decide) |>.trans (getSqrtRatioStoreAfterTickHiBit512_tick I) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLog.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLog.lean deleted file mode 100644 index 0f3ae40c..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLog.lean +++ /dev/null @@ -1,599 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeSourceGetTickMsb - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem initializeArgWord_toNat_lt_twoPow160 (I : ExecutionEnv) : - (initializeArgWord I).toNat < 2 ^ (160 : Nat) := by - unfold initializeArgWord - rw [initializeUint160Mask_decode] - exact Nat.mod_lt _ (by norm_num [EVM.twoPow]) - -theorem getTickSourceRatioNat_lt_twoPow192 (I : ExecutionEnv) : - getTickSourceRatioNat I < 2 ^ (192 : Nat) := by - unfold getTickSourceRatioNat - rw [Nat.mod_eq_of_lt] - · have harg := initializeArgWord_toNat_lt_twoPow160 I - have hmul := Nat.mul_lt_mul_of_pos_right harg (by norm_num : 0 < 2 ^ (32 : Nat)) - rw [← Nat.pow_add] at hmul - norm_num at hmul - exact hmul - · have harg := initializeArgWord_toNat_lt_twoPow160 I - have hmul := Nat.mul_lt_mul_of_pos_right harg (by norm_num : 0 < 2 ^ (32 : Nat)) - rw [← Nat.pow_add] at hmul - norm_num at hmul ⊢ - exact lt_trans hmul (by norm_num [EVM.wordModulus, EVM.twoPow]) - -theorem getTickSourceRAfterMsb7Nat_le_threshold7 (I : ExecutionEnv) : - getTickSourceRAfterMsb7Nat I ≤ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF := by - unfold getTickSourceRAfterMsb7Nat getTickSourceMsbF7Nat getTickSourceRatioGt7 - by_cases h : getTickSourceRatioNat I > 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - · rw [show decide (getTickSourceRatioNat I > 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) = - true by exact decide_eq_true h] - norm_num - rw [Nat.div_le_iff_le_mul (by norm_num)] - have hratio := getTickSourceRatioNat_lt_twoPow192 I - norm_num at hratio ⊢ - omega - · rw [show decide (getTickSourceRatioNat I > 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) = - false by exact decide_eq_false h] - norm_num - omega - -theorem getTickSourceRAfterMsb6Nat_le_threshold6 (I : ExecutionEnv) : - getTickSourceRAfterMsb6Nat I ≤ 0xFFFFFFFFFFFFFFFF := by - unfold getTickSourceRAfterMsb6Nat getTickSourceMsbF6Nat getTickSourceRAfterMsb7Gt6 - by_cases h : getTickSourceRAfterMsb7Nat I > 0xFFFFFFFFFFFFFFFF - · rw [show decide (getTickSourceRAfterMsb7Nat I > 0xFFFFFFFFFFFFFFFF) = - true by exact decide_eq_true h] - norm_num - rw [Nat.div_le_iff_le_mul (by norm_num)] - have hprev := getTickSourceRAfterMsb7Nat_le_threshold7 I - norm_num at hprev ⊢ - omega - · rw [show decide (getTickSourceRAfterMsb7Nat I > 0xFFFFFFFFFFFFFFFF) = - false by exact decide_eq_false h] - norm_num - omega - -theorem getTickSourceRAfterMsb5Nat_le_threshold5 (I : ExecutionEnv) : - getTickSourceRAfterMsb5Nat I ≤ 0xFFFFFFFF := by - unfold getTickSourceRAfterMsb5Nat getTickSourceMsbF5Nat getTickSourceRAfterMsb6Gt5 - by_cases h : getTickSourceRAfterMsb6Nat I > 0xFFFFFFFF - · rw [show decide (getTickSourceRAfterMsb6Nat I > 0xFFFFFFFF) = - true by exact decide_eq_true h] - norm_num - rw [Nat.div_le_iff_le_mul (by norm_num)] - have hprev := getTickSourceRAfterMsb6Nat_le_threshold6 I - norm_num at hprev ⊢ - omega - · rw [show decide (getTickSourceRAfterMsb6Nat I > 0xFFFFFFFF) = - false by exact decide_eq_false h] - norm_num - omega - -theorem getTickSourceRAfterMsb4Nat_le_threshold3 (I : ExecutionEnv) : - getTickSourceRAfterMsb4Nat I ≤ 0xFFFF := by - unfold getTickSourceRAfterMsb4Nat getTickSourceMsbF4Nat getTickSourceRAfterMsb5Gt4 - by_cases h : getTickSourceRAfterMsb5Nat I > 0xFFFF - · rw [show decide (getTickSourceRAfterMsb5Nat I > 0xFFFF) = - true by exact decide_eq_true h] - norm_num - rw [Nat.div_le_iff_le_mul (by norm_num)] - have hprev := getTickSourceRAfterMsb5Nat_le_threshold5 I - norm_num at hprev ⊢ - omega - · rw [show decide (getTickSourceRAfterMsb5Nat I > 0xFFFF) = - false by exact decide_eq_false h] - norm_num - omega - -theorem getTickSourceRAfterMsb3Nat_le_threshold2 (I : ExecutionEnv) : - getTickSourceRAfterMsb3Nat I ≤ 0xFF := by - unfold getTickSourceRAfterMsb3Nat getTickSourceMsbF3Nat getTickSourceRAfterMsb4Gt3 - by_cases h : getTickSourceRAfterMsb4Nat I > 0xFF - · rw [show decide (getTickSourceRAfterMsb4Nat I > 0xFF) = - true by exact decide_eq_true h] - norm_num - rw [Nat.div_le_iff_le_mul (by norm_num)] - have hprev := getTickSourceRAfterMsb4Nat_le_threshold3 I - norm_num at hprev ⊢ - omega - · rw [show decide (getTickSourceRAfterMsb4Nat I > 0xFF) = - false by exact decide_eq_false h] - norm_num - omega - -theorem getTickSourceRAfterMsb2Nat_le_threshold1 (I : ExecutionEnv) : - getTickSourceRAfterMsb2Nat I ≤ 0xF := by - unfold getTickSourceRAfterMsb2Nat getTickSourceMsbF2Nat getTickSourceRAfterMsb3Gt2 - by_cases h : getTickSourceRAfterMsb3Nat I > 0xF - · rw [show decide (getTickSourceRAfterMsb3Nat I > 0xF) = - true by exact decide_eq_true h] - norm_num - rw [Nat.div_le_iff_le_mul (by norm_num)] - have hprev := getTickSourceRAfterMsb3Nat_le_threshold2 I - norm_num at hprev ⊢ - omega - · rw [show decide (getTickSourceRAfterMsb3Nat I > 0xF) = - false by exact decide_eq_false h] - norm_num - omega - -theorem getTickSourceRAfterMsb1Nat_le_3 (I : ExecutionEnv) : - getTickSourceRAfterMsb1Nat I ≤ 3 := by - unfold getTickSourceRAfterMsb1Nat getTickSourceMsbF1Nat getTickSourceRAfterMsb2Gt1 - by_cases h : getTickSourceRAfterMsb2Nat I > 0x3 - · rw [show decide (getTickSourceRAfterMsb2Nat I > 0x3) = - true by exact decide_eq_true h] - norm_num - rw [Nat.div_le_iff_le_mul (by norm_num)] - have hprev := getTickSourceRAfterMsb2Nat_le_threshold1 I - norm_num at hprev ⊢ - omega - · rw [show decide (getTickSourceRAfterMsb2Nat I > 0x3) = - false by exact decide_eq_false h] - norm_num - omega - -theorem getTickSourceRAfterMsb6Nat_eq_ratio_div_msbAfter6 (I : ExecutionEnv) : - getTickSourceRAfterMsb6Nat I = - getTickSourceRatioNat I / 2 ^ getTickSourceMsbAfter6Nat I := by - unfold getTickSourceRAfterMsb6Nat getTickSourceRAfterMsb7Nat getTickSourceMsbAfter6Nat - rw [Nat.div_div_eq_div_mul] - rw [← Nat.pow_add] - -theorem getTickSourceRAfterMsb5Nat_eq_ratio_div_msbAfter5 (I : ExecutionEnv) : - getTickSourceRAfterMsb5Nat I = - getTickSourceRatioNat I / 2 ^ getTickSourceMsbAfter5Nat I := by - unfold getTickSourceRAfterMsb5Nat getTickSourceMsbAfter5Nat - rw [getTickSourceRAfterMsb6Nat_eq_ratio_div_msbAfter6] - rw [Nat.div_div_eq_div_mul] - rw [← Nat.pow_add] - -theorem getTickSourceRAfterMsb4Nat_eq_ratio_div_msbAfter4 (I : ExecutionEnv) : - getTickSourceRAfterMsb4Nat I = - getTickSourceRatioNat I / 2 ^ getTickSourceMsbAfter4Nat I := by - unfold getTickSourceRAfterMsb4Nat getTickSourceMsbAfter4Nat - rw [getTickSourceRAfterMsb5Nat_eq_ratio_div_msbAfter5] - rw [Nat.div_div_eq_div_mul] - rw [← Nat.pow_add] - -theorem getTickSourceRAfterMsb3Nat_eq_ratio_div_msbAfter3 (I : ExecutionEnv) : - getTickSourceRAfterMsb3Nat I = - getTickSourceRatioNat I / 2 ^ getTickSourceMsbAfter3Nat I := by - unfold getTickSourceRAfterMsb3Nat getTickSourceMsbAfter3Nat - rw [getTickSourceRAfterMsb4Nat_eq_ratio_div_msbAfter4] - rw [Nat.div_div_eq_div_mul] - rw [← Nat.pow_add] - -theorem getTickSourceRAfterMsb2Nat_eq_ratio_div_msbAfter2 (I : ExecutionEnv) : - getTickSourceRAfterMsb2Nat I = - getTickSourceRatioNat I / 2 ^ getTickSourceMsbAfter2Nat I := by - unfold getTickSourceRAfterMsb2Nat getTickSourceMsbAfter2Nat - rw [getTickSourceRAfterMsb3Nat_eq_ratio_div_msbAfter3] - rw [Nat.div_div_eq_div_mul] - rw [← Nat.pow_add] - -theorem getTickSourceRAfterMsb1Nat_eq_ratio_div_msbAfter1 (I : ExecutionEnv) : - getTickSourceRAfterMsb1Nat I = - getTickSourceRatioNat I / 2 ^ getTickSourceMsbAfter1Nat I := by - unfold getTickSourceRAfterMsb1Nat getTickSourceMsbAfter1Nat - rw [getTickSourceRAfterMsb2Nat_eq_ratio_div_msbAfter2] - rw [Nat.div_div_eq_div_mul] - rw [← Nat.pow_add] - -theorem getTickSourceRAfterMsb1Nat_lt_twoPow_f0_succ (I : ExecutionEnv) : - getTickSourceRAfterMsb1Nat I < 2 ^ (getTickSourceMsbF0Nat I + 1) := by - unfold getTickSourceMsbF0Nat getTickSourceRAfterMsb1Gt0 - by_cases h : getTickSourceRAfterMsb1Nat I > 1 - · rw [show decide (getTickSourceRAfterMsb1Nat I > 1) = true by exact decide_eq_true h] - have hle := getTickSourceRAfterMsb1Nat_le_3 I - norm_num - omega - · rw [show decide (getTickSourceRAfterMsb1Nat I > 1) = false by exact decide_eq_false h] - norm_num - omega - -theorem getTickSourceRatioNat_lt_twoPow_msbAfter0_succ (I : ExecutionEnv) : - getTickSourceRatioNat I < 2 ^ (getTickSourceMsbAfter0Nat I + 1) := by - have hdiv := getTickSourceRAfterMsb1Nat_lt_twoPow_f0_succ I - rw [getTickSourceRAfterMsb1Nat_eq_ratio_div_msbAfter1] at hdiv - have hk : 0 < 2 ^ getTickSourceMsbAfter1Nat I := Nat.pow_pos (by norm_num) - have hratio := (Nat.div_lt_iff_lt_mul hk).mp hdiv - rw [← Nat.pow_add] at hratio - have hexp : - getTickSourceMsbF0Nat I + 1 + getTickSourceMsbAfter1Nat I = - getTickSourceMsbAfter1Nat I + getTickSourceMsbF0Nat I + 1 := by - omega - rw [hexp] at hratio - simpa [getTickSourceMsbAfter0Nat] using hratio - -theorem getTickSourceRNormalizedHighNat_lt_twoPow128 (I : ExecutionEnv) - (hge : getTickSourceMsbGe128 I = true) : - getTickSourceRNormalizedHighNat I < 2 ^ (128 : Nat) := by - have hNat : 128 ≤ getTickSourceMsbAfter0Nat I := by - unfold getTickSourceMsbGe128 at hge - exact of_decide_eq_true hge - unfold getTickSourceRNormalizedHighNat - rw [Nat.div_lt_iff_lt_mul (by - exact Nat.pow_pos (by norm_num : 0 < 2))] - rw [← Nat.pow_add] - have hexp : 128 + (getTickSourceMsbAfter0Nat I - 127) = - getTickSourceMsbAfter0Nat I + 1 := by - omega - rw [hexp] - exact getTickSourceRatioNat_lt_twoPow_msbAfter0_succ I - -theorem getTickSourceRNormalizedLowNat_lt_twoPow128 (I : ExecutionEnv) - (hge : getTickSourceMsbGe128 I = false) : - getTickSourceRNormalizedLowNat I < 2 ^ (128 : Nat) := by - have hNat : getTickSourceMsbAfter0Nat I < 128 := by - unfold getTickSourceMsbGe128 at hge - exact Nat.lt_of_not_ge (of_decide_eq_false hge) - unfold getTickSourceRNormalizedLowNat - have hratio := getTickSourceRatioNat_lt_twoPow_msbAfter0_succ I - have hmul := Nat.mul_lt_mul_of_pos_right hratio - (k := 2 ^ (127 - getTickSourceMsbAfter0Nat I)) - (Nat.pow_pos (by norm_num : 0 < 2)) - rw [← Nat.pow_add] at hmul - have hexp : getTickSourceMsbAfter0Nat I + 1 + (127 - getTickSourceMsbAfter0Nat I) = - 128 := by - omega - rw [hexp] at hmul - rw [Nat.mod_eq_of_lt] - · exact hmul - · exact lt_trans hmul (by norm_num [EVM.wordModulus, EVM.twoPow]) - -theorem getTickSourceRNormalizedNat_lt_twoPow128 (I : ExecutionEnv) : - getTickSourceRNormalizedNat I < 2 ^ (128 : Nat) := by - unfold getTickSourceRNormalizedNat - by_cases hge : getTickSourceMsbGe128 I = true - · rw [if_pos hge] - exact getTickSourceRNormalizedHighNat_lt_twoPow128 I hge - · have hfalse : getTickSourceMsbGe128 I = false := Bool.eq_false_iff.mpr hge - rw [if_neg hge] - exact getTickSourceRNormalizedLowNat_lt_twoPow128 I hfalse - -theorem getTickSourceRNormalizedNat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceRNormalizedNat I * getTickSourceRNormalizedNat I < EVM.wordModulus := by - have hr := getTickSourceRNormalizedNat_lt_twoPow128 I - have hrle : getTickSourceRNormalizedNat I ≤ 2 ^ (128 : Nat) - 1 := - Nat.le_pred_of_lt hr - have hmul := Nat.mul_le_mul hrle hrle - exact Nat.lt_of_le_of_lt hmul (by norm_num [EVM.wordModulus, EVM.twoPow]) - -theorem intOfNat_toNat_div_pow_127_cast (n : Nat) : - ((Int.ofNat n).toNat / 2 ^ Int.toNat (127 : Int) : Int) = - (n / 2 ^ (127 : Nat) : Nat) := by - rfl - -def getTickSourceLogRShifted63Nat (I : ExecutionEnv) : Nat := - getTickSourceRNormalizedNat I * getTickSourceRNormalizedNat I / 2 ^ (127 : Nat) - -def getTickSourceLogRShifted63Value (I : ExecutionEnv) : Value := - .int (getTickSourceLogRShifted63Nat I) - -def getTickStoreAfterLogRShifted63 (I : ExecutionEnv) : Store := - (getTickStoreAfterLog2BaseLet I).insert "r" (getTickSourceLogRShifted63Value I) - -def getTickSourceLogF63Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRShifted63Nat I / 2 ^ (128 : Nat) - -def getTickSourceLogF63Value (I : ExecutionEnv) : Value := - .int (getTickSourceLogF63Nat I) - -def getTickStoreAfterLogF63Let (I : ExecutionEnv) : Store := - (getTickStoreAfterLogRShifted63 I).insert "f" (getTickSourceLogF63Value I) - -def getTickSourceLog2After63Int (I : ExecutionEnv) : Int := - getTickSourceLog2BaseInt I + (getTickSourceLogF63Nat I : Int) * (2 ^ (63 : Nat) : Int) - -def getTickSourceLog2After63Value (I : ExecutionEnv) : Value := - .int (getTickSourceLog2After63Int I) - -def getTickStoreAfterLog2Step63 (I : ExecutionEnv) : Store := - (getTickStoreAfterLogF63Let I).insert "log_2" (getTickSourceLog2After63Value I) - -def getTickSourceLogRAfter63Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRShifted63Nat I / 2 ^ getTickSourceLogF63Nat I - -def getTickSourceLogRAfter63Value (I : ExecutionEnv) : Value := - .int (getTickSourceLogRAfter63Nat I) - -def getTickStoreAfterLogStep63 (I : ExecutionEnv) : Store := - (getTickStoreAfterLog2Step63 I).insert "r" (getTickSourceLogRAfter63Value I) - -theorem getTickSourceLogRShifted63Nat_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRShifted63Nat I < EVM.wordModulus := by - unfold getTickSourceLogRShifted63Nat - exact lt_of_le_of_lt (Nat.div_le_self _ _) (getTickSourceRNormalizedNat_mul_self_lt_wordModulus I) - -theorem getTickSourceLogRShifted63Nat_lt_twoPow129 (I : ExecutionEnv) : - getTickSourceLogRShifted63Nat I < 2 ^ (129 : Nat) := by - unfold getTickSourceLogRShifted63Nat - rw [Nat.div_lt_iff_lt_mul (by norm_num : 0 < 2 ^ (127 : Nat))] - rw [← Nat.pow_add] - norm_num - exact getTickSourceRNormalizedNat_mul_self_lt_wordModulus I - -theorem getTickSourceLogF63Nat_le_1 (I : ExecutionEnv) : - getTickSourceLogF63Nat I ≤ 1 := by - unfold getTickSourceLogF63Nat - have hshifted := getTickSourceLogRShifted63Nat_lt_twoPow129 I - have hf : getTickSourceLogRShifted63Nat I / 2 ^ (128 : Nat) < 2 := by - rw [Nat.div_lt_iff_lt_mul (by norm_num : 0 < 2 ^ (128 : Nat))] - norm_num - exact hshifted - omega - -theorem getTickStoreAfterNormalizeR_r (I : ExecutionEnv) : - (getTickStoreAfterNormalizeR I).get? "r" = - some (getTickSourceRNormalizedValue I) := by - rw [getTickStoreAfterNormalizeR, store_get_self] - -theorem getTickStoreAfterLog2BaseLet_r (I : ExecutionEnv) : - (getTickStoreAfterLog2BaseLet I).get? "r" = - some (getTickSourceRNormalizedValue I) := by - rw [getTickStoreAfterLog2BaseLet] - rw [store_get_ne (getTickStoreAfterNormalizeR I) (k := "log_2") (a := "r") - (getTickSourceLog2BaseValue I) (by decide)] - exact getTickStoreAfterNormalizeR_r I - -theorem getTickStoreAfterLog2BaseLet_log2 (I : ExecutionEnv) : - (getTickStoreAfterLog2BaseLet I).get? "log_2" = - some (getTickSourceLog2BaseValue I) := by - rw [getTickStoreAfterLog2BaseLet, store_get_self] - -theorem evalExpr_getTick_rVar_afterLog2Base {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLog2BaseLet I } - evm (.var "r") = .ok (getTickSourceRNormalizedValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLog2BaseLet_r] - -theorem evalExpr_getTick_log2Var_afterLog2Base {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLog2BaseLet I } - evm (.var "log_2") = .ok (getTickSourceLog2BaseValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLog2BaseLet_log2] - -theorem evalExpr_getTick_log_r_mul_r_63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLog2BaseLet I } - evm (mulE (.var "r") (.var "r")) = - .ok (.int (Int.ofNat (getTickSourceRNormalizedNat I * getTickSourceRNormalizedNat I))) := by - unfold mulE - simp only [evalExpr?, evalExpr_getTick_rVar_afterLog2Base, EvalResult.bind, bind, - evalBinaryOp?, getTickSourceRNormalizedValue] - rw [← Int.natCast_mul] - rfl - -theorem evalExpr_getTick_log_r_shifted_63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLog2BaseLet I } - evm (shrE (mulE (.var "r") (.var "r")) (.intLit 127)) = - .ok (getTickSourceLogRShifted63Value I) := by - unfold shrE - simp only [evalExpr?, evalExpr_getTick_log_r_mul_r_63, EvalResult.bind, bind, pure] - rw [evalBinaryOp_int_shr_ok] - · rw [getTickSourceLogRShifted63Value, getTickSourceLogRShifted63Nat] - rw [intOfNat_toNat_div_pow_127_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceRNormalizedNat_mul_self_lt_wordModulus I) - · norm_num - · norm_num - -theorem assignStorageRef_getTick_r_shifted63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterLog2BaseLet I } - evm .localVar (varRef "r") (getTickSourceLogRShifted63Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterLogRShifted63 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterLog2BaseLet_r] - simp [getTickStoreAfterLogRShifted63, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem getTickStoreAfterLogRShifted63_r (I : ExecutionEnv) : - (getTickStoreAfterLogRShifted63 I).get? "r" = - some (getTickSourceLogRShifted63Value I) := by - rw [getTickStoreAfterLogRShifted63, store_get_self] - -theorem getTickStoreAfterLogRShifted63_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogRShifted63 I).get? "log_2" = - some (getTickSourceLog2BaseValue I) := by - rw [getTickStoreAfterLogRShifted63] - rw [store_get_ne (getTickStoreAfterLog2BaseLet I) (k := "r") (a := "log_2") - (getTickSourceLogRShifted63Value I) (by decide)] - exact getTickStoreAfterLog2BaseLet_log2 I - -theorem evalExpr_getTick_rVar_afterLogRShifted63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogRShifted63 I } - evm (.var "r") = .ok (getTickSourceLogRShifted63Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogRShifted63_r] - -theorem evalExpr_getTick_log_f63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogRShifted63 I } - evm (shrE (.var "r") shift128) = .ok (getTickSourceLogF63Value I) := by - unfold shrE shift128 - simp only [evalExpr?, evalExpr_getTick_rVar_afterLogRShifted63, EvalResult.bind, bind, pure] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceLogRShifted63Nat I))) - (.int (Int.ofNat 128)) = .ok (getTickSourceLogF63Value I) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceLogF63Value getTickSourceLogF63Nat - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceLogRShifted63Nat_lt_wordModulus I) - · norm_num - · norm_num - -theorem getTickStoreAfterLogF63Let_r (I : ExecutionEnv) : - (getTickStoreAfterLogF63Let I).get? "r" = - some (getTickSourceLogRShifted63Value I) := by - rw [getTickStoreAfterLogF63Let] - rw [store_get_ne (getTickStoreAfterLogRShifted63 I) (k := "f") (a := "r") - (getTickSourceLogF63Value I) (by decide)] - exact getTickStoreAfterLogRShifted63_r I - -theorem getTickStoreAfterLogF63Let_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogF63Let I).get? "log_2" = - some (getTickSourceLog2BaseValue I) := by - rw [getTickStoreAfterLogF63Let] - rw [store_get_ne (getTickStoreAfterLogRShifted63 I) (k := "f") (a := "log_2") - (getTickSourceLogF63Value I) (by decide)] - exact getTickStoreAfterLogRShifted63_log2 I - -theorem getTickStoreAfterLogF63Let_f (I : ExecutionEnv) : - (getTickStoreAfterLogF63Let I).get? "f" = some (getTickSourceLogF63Value I) := by - rw [getTickStoreAfterLogF63Let, store_get_self] - -theorem evalExpr_getTick_log2Var_afterLogF63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogF63Let I } - evm (.var "log_2") = .ok (getTickSourceLog2BaseValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogF63Let_log2] - -theorem evalExpr_getTick_fVar_afterLogF63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogF63Let I } - evm (.var "f") = .ok (getTickSourceLogF63Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogF63Let_f] - -theorem evalExpr_getTick_log2_add_f63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogF63Let I } - evm (addE (.var "log_2") (mulE (.var "f") (.intLit (2 ^ (63 : Nat))))) = - .ok (getTickSourceLog2After63Value I) := by - unfold addE mulE getTickSourceLog2After63Value getTickSourceLog2After63Int - simp only [evalExpr?, evalExpr_getTick_log2Var_afterLogF63, evalExpr_getTick_fVar_afterLogF63, - EvalResult.bind, bind, evalBinaryOp?, getTickSourceLogF63Value, - getTickSourceLog2BaseValue] - -theorem assignStorageRef_getTick_log2_after63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterLogF63Let I } - evm .localVar (varRef "log_2") (getTickSourceLog2After63Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterLog2Step63 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterLogF63Let_log2] - simp [getTickStoreAfterLog2Step63, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem getTickStoreAfterLog2Step63_r (I : ExecutionEnv) : - (getTickStoreAfterLog2Step63 I).get? "r" = - some (getTickSourceLogRShifted63Value I) := by - rw [getTickStoreAfterLog2Step63] - rw [store_get_ne (getTickStoreAfterLogF63Let I) (k := "log_2") (a := "r") - (getTickSourceLog2After63Value I) (by decide)] - exact getTickStoreAfterLogF63Let_r I - -theorem getTickStoreAfterLog2Step63_f (I : ExecutionEnv) : - (getTickStoreAfterLog2Step63 I).get? "f" = some (getTickSourceLogF63Value I) := by - rw [getTickStoreAfterLog2Step63] - rw [store_get_ne (getTickStoreAfterLogF63Let I) (k := "log_2") (a := "f") - (getTickSourceLog2After63Value I) (by decide)] - exact getTickStoreAfterLogF63Let_f I - -theorem evalExpr_getTick_rVar_afterLog2Step63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLog2Step63 I } - evm (.var "r") = .ok (getTickSourceLogRShifted63Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLog2Step63_r] - -theorem evalExpr_getTick_fVar_afterLog2Step63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLog2Step63 I } - evm (.var "f") = .ok (getTickSourceLogF63Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLog2Step63_f] - -theorem evalExpr_getTick_log_r_after63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLog2Step63 I } - evm (shrE (.var "r") (.var "f")) = .ok (getTickSourceLogRAfter63Value I) := by - unfold shrE - simp only [evalExpr?, evalExpr_getTick_rVar_afterLog2Step63, - evalExpr_getTick_fVar_afterLog2Step63, EvalResult.bind, bind] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceLogRShifted63Nat I))) - (.int (Int.ofNat (getTickSourceLogF63Nat I))) = - .ok (getTickSourceLogRAfter63Value I) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceLogRAfter63Value getTickSourceLogRAfter63Nat - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceLogRShifted63Nat_lt_wordModulus I) - · exact Int.natCast_nonneg _ - · have hle := getTickSourceLogF63Nat_le_1 I - have hlt : getTickSourceLogF63Nat I < 256 := by omega - exact Int.ofNat_lt.mpr hlt - -theorem assignStorageRef_getTick_r_afterLog63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterLog2Step63 I } - evm .localVar (varRef "r") (getTickSourceLogRAfter63Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterLogStep63 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterLog2Step63_r] - simp [getTickStoreAfterLogStep63, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep63 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLog2BaseLet I } - evm (logStep 63 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep63 I } evm) := by - change ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLog2BaseLet I } - evm - [ .assign .localVar (varRef "r") (shrE (mulE (.var "r") (.var "r")) (.intLit 127)), - .letDecl "f" (some uint256) (shrE (.var "r") shift128), - .assign .localVar (varRef "log_2") - (addE (.var "log_2") (mulE (.var "f") (.intLit (2 ^ (63 : Nat))))), - .assign .localVar (varRef "r") (shrE (.var "r") (.var "f")) ] - (.ok { contract := contract v, locals := getTickStoreAfterLogStep63 I } evm) - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_log_r_shifted_63 evm I) - (assignStorageRef_getTick_r_shifted63 evm I)) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_log_f63 evm I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_log2_add_f63 evm I) - (assignStorageRef_getTick_log2_after63 evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_log_r_after63 evm I) - (assignStorageRef_getTick_r_afterLog63 evm I)) - ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceThroughLogStep63 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - ((msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF ++ - msbStep 4 0xFFFF ++ - msbStep 3 0xFF ++ - msbStep 2 0xF ++ - msbStep 1 0x3 ++ - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0x1)) (.intLit 1) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - Stmt.ite (geE (.var "msb") (.intLit 128)) - [ .assign .localVar (varRef "r") - (shrE (.var "ratio") (subE (.var "msb") (.intLit 127))) ] - [ .assign .localVar (varRef "r") - (shlE (.var "ratio") (subE (.intLit 127) (.var "msb"))) ], - .letDecl "log_2" (some int256) - (mulE (subE (.var "msb") (.intLit 128)) (.intLit (2 ^ (64 : Nat)))) ]) ++ - logStep 63 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep63 I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceThroughLog2Base evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep63 evm I) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogRemaining.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogRemaining.lean deleted file mode 100644 index c01a3f1b..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogRemaining.lean +++ /dev/null @@ -1,649 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeSourceGetTickLogStep60 - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def getTickSourceLog2AfterStep (log2 : Int) (r bit : Nat) : Int := - getTickSourceLogStepLog2AfterInt log2 r bit - -def getTickSourceLogRAfterStep (r : Nat) : Nat := - getTickSourceLogStepRAfterNat r - -def getTickStoreAfterLogStep (S : Store) (log2 : Int) (r bit : Nat) : Store := - getTickSourceLogStepStoreAfter S log2 r bit - -theorem getTickStoreAfterLogStep_r (S : Store) (log2 : Int) (r bit : Nat) : - (getTickStoreAfterLogStep S log2 r bit).get? "r" = - some (Value.int (Int.ofNat (getTickSourceLogRAfterStep r))) := by - simpa [getTickStoreAfterLogStep, getTickSourceLogRAfterStep, - getTickSourceLogStepRAfterValue] - using getTickSourceLogStepStoreAfter_r S log2 r bit - -theorem getTickStoreAfterLogStep_log2 (S : Store) (log2 : Int) (r bit : Nat) : - (getTickStoreAfterLogStep S log2 r bit).get? "log_2" = - some (Value.int (getTickSourceLog2AfterStep log2 r bit)) := by - simpa [getTickStoreAfterLogStep, getTickSourceLog2AfterStep, - getTickSourceLogStepLog2AfterValue] - using getTickSourceLogStepStoreAfter_log2 S log2 r bit - -def getTickSourceLog2After59Int (I : ExecutionEnv) : Int := - getTickSourceLog2AfterStep (getTickSourceLog2After60Int I) (getTickSourceLogRAfter60Nat I) 59 - -def getTickSourceLogRAfter59Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRAfterStep (getTickSourceLogRAfter60Nat I) - -def getTickStoreAfterLogStep59 (I : ExecutionEnv) : Store := - getTickStoreAfterLogStep (getTickStoreAfterLogStep60 I) - (getTickSourceLog2After60Int I) (getTickSourceLogRAfter60Nat I) 59 - -theorem getTickSourceLogRAfter59Nat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRAfter59Nat I * getTickSourceLogRAfter59Nat I < EVM.wordModulus := by - unfold getTickSourceLogRAfter59Nat getTickSourceLogRAfterStep - exact getTickSourceLogStepRAfterNat_mul_self_lt_wordModulus - (getTickSourceLogRAfter60Nat I) - (getTickSourceLogRAfter60Nat_mul_self_lt_wordModulus I) - -theorem getTickStoreAfterLogStep60_r (I : ExecutionEnv) : - (getTickStoreAfterLogStep60 I).get? "r" = - some (Value.int (Int.ofNat (getTickSourceLogRAfter60Nat I))) := by - simpa [getTickStoreAfterLogStep60, getTickSourceLogRAfter60Nat, - getTickSourceLogStepRAfterValue] - using getTickSourceLogStepStoreAfter_r (getTickStoreAfterLogStep61 I) - (getTickSourceLog2After61Int I) (getTickSourceLogRAfter61Nat I) 60 - -theorem getTickStoreAfterLogStep60_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep60 I).get? "log_2" = - some (Value.int (getTickSourceLog2After60Int I)) := by - simpa [getTickStoreAfterLogStep60, getTickSourceLog2After60Int, - getTickSourceLogStepLog2AfterValue] - using getTickSourceLogStepStoreAfter_log2 (getTickStoreAfterLogStep61 I) - (getTickSourceLog2After61Int I) (getTickSourceLogRAfter61Nat I) 60 - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep59 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep60 I } - evm (logStep 59 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep59 I } evm) := by - exact getTickSourceLogStepExec evm (getTickStoreAfterLogStep60 I) - (getTickSourceLog2After60Int I) (getTickSourceLogRAfter60Nat I) 59 - (getTickStoreAfterLogStep60_r I) - (getTickStoreAfterLogStep60_log2 I) - (getTickSourceLogRAfter60Nat_mul_self_lt_wordModulus I) - -def getTickSourceLog2After58Int (I : ExecutionEnv) : Int := - getTickSourceLog2AfterStep (getTickSourceLog2After59Int I) (getTickSourceLogRAfter59Nat I) 58 - -def getTickSourceLogRAfter58Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRAfterStep (getTickSourceLogRAfter59Nat I) - -def getTickStoreAfterLogStep58 (I : ExecutionEnv) : Store := - getTickStoreAfterLogStep (getTickStoreAfterLogStep59 I) - (getTickSourceLog2After59Int I) (getTickSourceLogRAfter59Nat I) 58 - -theorem getTickSourceLogRAfter58Nat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRAfter58Nat I * getTickSourceLogRAfter58Nat I < EVM.wordModulus := by - unfold getTickSourceLogRAfter58Nat getTickSourceLogRAfterStep - exact getTickSourceLogStepRAfterNat_mul_self_lt_wordModulus - (getTickSourceLogRAfter59Nat I) - (getTickSourceLogRAfter59Nat_mul_self_lt_wordModulus I) - -theorem getTickStoreAfterLogStep59_r (I : ExecutionEnv) : - (getTickStoreAfterLogStep59 I).get? "r" = - some (Value.int (Int.ofNat (getTickSourceLogRAfter59Nat I))) := by - simpa [getTickStoreAfterLogStep59, getTickSourceLogRAfter59Nat] - using getTickStoreAfterLogStep_r (getTickStoreAfterLogStep60 I) - (getTickSourceLog2After60Int I) (getTickSourceLogRAfter60Nat I) 59 - -theorem getTickStoreAfterLogStep59_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep59 I).get? "log_2" = - some (Value.int (getTickSourceLog2After59Int I)) := by - simpa [getTickStoreAfterLogStep59, getTickSourceLog2After59Int] - using getTickStoreAfterLogStep_log2 (getTickStoreAfterLogStep60 I) - (getTickSourceLog2After60Int I) (getTickSourceLogRAfter60Nat I) 59 - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep58 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep59 I } - evm (logStep 58 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep58 I } evm) := by - exact getTickSourceLogStepExec evm (getTickStoreAfterLogStep59 I) - (getTickSourceLog2After59Int I) (getTickSourceLogRAfter59Nat I) 58 - (getTickStoreAfterLogStep59_r I) - (getTickStoreAfterLogStep59_log2 I) - (getTickSourceLogRAfter59Nat_mul_self_lt_wordModulus I) - -def getTickSourceLog2After57Int (I : ExecutionEnv) : Int := - getTickSourceLog2AfterStep (getTickSourceLog2After58Int I) (getTickSourceLogRAfter58Nat I) 57 - -def getTickSourceLogRAfter57Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRAfterStep (getTickSourceLogRAfter58Nat I) - -def getTickStoreAfterLogStep57 (I : ExecutionEnv) : Store := - getTickStoreAfterLogStep (getTickStoreAfterLogStep58 I) - (getTickSourceLog2After58Int I) (getTickSourceLogRAfter58Nat I) 57 - -theorem getTickSourceLogRAfter57Nat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRAfter57Nat I * getTickSourceLogRAfter57Nat I < EVM.wordModulus := by - unfold getTickSourceLogRAfter57Nat getTickSourceLogRAfterStep - exact getTickSourceLogStepRAfterNat_mul_self_lt_wordModulus - (getTickSourceLogRAfter58Nat I) - (getTickSourceLogRAfter58Nat_mul_self_lt_wordModulus I) - -theorem getTickStoreAfterLogStep58_r (I : ExecutionEnv) : - (getTickStoreAfterLogStep58 I).get? "r" = - some (Value.int (Int.ofNat (getTickSourceLogRAfter58Nat I))) := by - simpa [getTickStoreAfterLogStep58, getTickSourceLogRAfter58Nat] - using getTickStoreAfterLogStep_r (getTickStoreAfterLogStep59 I) - (getTickSourceLog2After59Int I) (getTickSourceLogRAfter59Nat I) 58 - -theorem getTickStoreAfterLogStep58_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep58 I).get? "log_2" = - some (Value.int (getTickSourceLog2After58Int I)) := by - simpa [getTickStoreAfterLogStep58, getTickSourceLog2After58Int] - using getTickStoreAfterLogStep_log2 (getTickStoreAfterLogStep59 I) - (getTickSourceLog2After59Int I) (getTickSourceLogRAfter59Nat I) 58 - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep57 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep58 I } - evm (logStep 57 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep57 I } evm) := by - exact getTickSourceLogStepExec evm (getTickStoreAfterLogStep58 I) - (getTickSourceLog2After58Int I) (getTickSourceLogRAfter58Nat I) 57 - (getTickStoreAfterLogStep58_r I) - (getTickStoreAfterLogStep58_log2 I) - (getTickSourceLogRAfter58Nat_mul_self_lt_wordModulus I) - -def getTickSourceLog2After56Int (I : ExecutionEnv) : Int := - getTickSourceLog2AfterStep (getTickSourceLog2After57Int I) (getTickSourceLogRAfter57Nat I) 56 - -def getTickSourceLogRAfter56Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRAfterStep (getTickSourceLogRAfter57Nat I) - -def getTickStoreAfterLogStep56 (I : ExecutionEnv) : Store := - getTickStoreAfterLogStep (getTickStoreAfterLogStep57 I) - (getTickSourceLog2After57Int I) (getTickSourceLogRAfter57Nat I) 56 - -theorem getTickSourceLogRAfter56Nat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRAfter56Nat I * getTickSourceLogRAfter56Nat I < EVM.wordModulus := by - unfold getTickSourceLogRAfter56Nat getTickSourceLogRAfterStep - exact getTickSourceLogStepRAfterNat_mul_self_lt_wordModulus - (getTickSourceLogRAfter57Nat I) - (getTickSourceLogRAfter57Nat_mul_self_lt_wordModulus I) - -theorem getTickStoreAfterLogStep57_r (I : ExecutionEnv) : - (getTickStoreAfterLogStep57 I).get? "r" = - some (Value.int (Int.ofNat (getTickSourceLogRAfter57Nat I))) := by - simpa [getTickStoreAfterLogStep57, getTickSourceLogRAfter57Nat] - using getTickStoreAfterLogStep_r (getTickStoreAfterLogStep58 I) - (getTickSourceLog2After58Int I) (getTickSourceLogRAfter58Nat I) 57 - -theorem getTickStoreAfterLogStep57_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep57 I).get? "log_2" = - some (Value.int (getTickSourceLog2After57Int I)) := by - simpa [getTickStoreAfterLogStep57, getTickSourceLog2After57Int] - using getTickStoreAfterLogStep_log2 (getTickStoreAfterLogStep58 I) - (getTickSourceLog2After58Int I) (getTickSourceLogRAfter58Nat I) 57 - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep56 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep57 I } - evm (logStep 56 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep56 I } evm) := by - exact getTickSourceLogStepExec evm (getTickStoreAfterLogStep57 I) - (getTickSourceLog2After57Int I) (getTickSourceLogRAfter57Nat I) 56 - (getTickStoreAfterLogStep57_r I) - (getTickStoreAfterLogStep57_log2 I) - (getTickSourceLogRAfter57Nat_mul_self_lt_wordModulus I) - -def getTickSourceLog2After55Int (I : ExecutionEnv) : Int := - getTickSourceLog2AfterStep (getTickSourceLog2After56Int I) (getTickSourceLogRAfter56Nat I) 55 - -def getTickSourceLogRAfter55Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRAfterStep (getTickSourceLogRAfter56Nat I) - -def getTickStoreAfterLogStep55 (I : ExecutionEnv) : Store := - getTickStoreAfterLogStep (getTickStoreAfterLogStep56 I) - (getTickSourceLog2After56Int I) (getTickSourceLogRAfter56Nat I) 55 - -theorem getTickSourceLogRAfter55Nat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRAfter55Nat I * getTickSourceLogRAfter55Nat I < EVM.wordModulus := by - unfold getTickSourceLogRAfter55Nat getTickSourceLogRAfterStep - exact getTickSourceLogStepRAfterNat_mul_self_lt_wordModulus - (getTickSourceLogRAfter56Nat I) - (getTickSourceLogRAfter56Nat_mul_self_lt_wordModulus I) - -theorem getTickStoreAfterLogStep56_r (I : ExecutionEnv) : - (getTickStoreAfterLogStep56 I).get? "r" = - some (Value.int (Int.ofNat (getTickSourceLogRAfter56Nat I))) := by - simpa [getTickStoreAfterLogStep56, getTickSourceLogRAfter56Nat] - using getTickStoreAfterLogStep_r (getTickStoreAfterLogStep57 I) - (getTickSourceLog2After57Int I) (getTickSourceLogRAfter57Nat I) 56 - -theorem getTickStoreAfterLogStep56_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep56 I).get? "log_2" = - some (Value.int (getTickSourceLog2After56Int I)) := by - simpa [getTickStoreAfterLogStep56, getTickSourceLog2After56Int] - using getTickStoreAfterLogStep_log2 (getTickStoreAfterLogStep57 I) - (getTickSourceLog2After57Int I) (getTickSourceLogRAfter57Nat I) 56 - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep55 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep56 I } - evm (logStep 55 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep55 I } evm) := by - exact getTickSourceLogStepExec evm (getTickStoreAfterLogStep56 I) - (getTickSourceLog2After56Int I) (getTickSourceLogRAfter56Nat I) 55 - (getTickStoreAfterLogStep56_r I) - (getTickStoreAfterLogStep56_log2 I) - (getTickSourceLogRAfter56Nat_mul_self_lt_wordModulus I) - -def getTickSourceLog2After54Int (I : ExecutionEnv) : Int := - getTickSourceLog2AfterStep (getTickSourceLog2After55Int I) (getTickSourceLogRAfter55Nat I) 54 - -def getTickSourceLogRAfter54Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRAfterStep (getTickSourceLogRAfter55Nat I) - -def getTickStoreAfterLogStep54 (I : ExecutionEnv) : Store := - getTickStoreAfterLogStep (getTickStoreAfterLogStep55 I) - (getTickSourceLog2After55Int I) (getTickSourceLogRAfter55Nat I) 54 - -theorem getTickSourceLogRAfter54Nat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRAfter54Nat I * getTickSourceLogRAfter54Nat I < EVM.wordModulus := by - unfold getTickSourceLogRAfter54Nat getTickSourceLogRAfterStep - exact getTickSourceLogStepRAfterNat_mul_self_lt_wordModulus - (getTickSourceLogRAfter55Nat I) - (getTickSourceLogRAfter55Nat_mul_self_lt_wordModulus I) - -theorem getTickStoreAfterLogStep55_r (I : ExecutionEnv) : - (getTickStoreAfterLogStep55 I).get? "r" = - some (Value.int (Int.ofNat (getTickSourceLogRAfter55Nat I))) := by - simpa [getTickStoreAfterLogStep55, getTickSourceLogRAfter55Nat] - using getTickStoreAfterLogStep_r (getTickStoreAfterLogStep56 I) - (getTickSourceLog2After56Int I) (getTickSourceLogRAfter56Nat I) 55 - -theorem getTickStoreAfterLogStep55_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep55 I).get? "log_2" = - some (Value.int (getTickSourceLog2After55Int I)) := by - simpa [getTickStoreAfterLogStep55, getTickSourceLog2After55Int] - using getTickStoreAfterLogStep_log2 (getTickStoreAfterLogStep56 I) - (getTickSourceLog2After56Int I) (getTickSourceLogRAfter56Nat I) 55 - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep54 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep55 I } - evm (logStep 54 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep54 I } evm) := by - exact getTickSourceLogStepExec evm (getTickStoreAfterLogStep55 I) - (getTickSourceLog2After55Int I) (getTickSourceLogRAfter55Nat I) 54 - (getTickStoreAfterLogStep55_r I) - (getTickStoreAfterLogStep55_log2 I) - (getTickSourceLogRAfter55Nat_mul_self_lt_wordModulus I) - -def getTickSourceLog2After53Int (I : ExecutionEnv) : Int := - getTickSourceLog2AfterStep (getTickSourceLog2After54Int I) (getTickSourceLogRAfter54Nat I) 53 - -def getTickSourceLogRAfter53Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRAfterStep (getTickSourceLogRAfter54Nat I) - -def getTickStoreAfterLogStep53 (I : ExecutionEnv) : Store := - getTickStoreAfterLogStep (getTickStoreAfterLogStep54 I) - (getTickSourceLog2After54Int I) (getTickSourceLogRAfter54Nat I) 53 - -theorem getTickSourceLogRAfter53Nat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRAfter53Nat I * getTickSourceLogRAfter53Nat I < EVM.wordModulus := by - unfold getTickSourceLogRAfter53Nat getTickSourceLogRAfterStep - exact getTickSourceLogStepRAfterNat_mul_self_lt_wordModulus - (getTickSourceLogRAfter54Nat I) - (getTickSourceLogRAfter54Nat_mul_self_lt_wordModulus I) - -theorem getTickStoreAfterLogStep54_r (I : ExecutionEnv) : - (getTickStoreAfterLogStep54 I).get? "r" = - some (Value.int (Int.ofNat (getTickSourceLogRAfter54Nat I))) := by - simpa [getTickStoreAfterLogStep54, getTickSourceLogRAfter54Nat] - using getTickStoreAfterLogStep_r (getTickStoreAfterLogStep55 I) - (getTickSourceLog2After55Int I) (getTickSourceLogRAfter55Nat I) 54 - -theorem getTickStoreAfterLogStep54_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep54 I).get? "log_2" = - some (Value.int (getTickSourceLog2After54Int I)) := by - simpa [getTickStoreAfterLogStep54, getTickSourceLog2After54Int] - using getTickStoreAfterLogStep_log2 (getTickStoreAfterLogStep55 I) - (getTickSourceLog2After55Int I) (getTickSourceLogRAfter55Nat I) 54 - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep53 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep54 I } - evm (logStep 53 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep53 I } evm) := by - exact getTickSourceLogStepExec evm (getTickStoreAfterLogStep54 I) - (getTickSourceLog2After54Int I) (getTickSourceLogRAfter54Nat I) 53 - (getTickStoreAfterLogStep54_r I) - (getTickStoreAfterLogStep54_log2 I) - (getTickSourceLogRAfter54Nat_mul_self_lt_wordModulus I) - -def getTickSourceLog2After52Int (I : ExecutionEnv) : Int := - getTickSourceLog2AfterStep (getTickSourceLog2After53Int I) (getTickSourceLogRAfter53Nat I) 52 - -def getTickSourceLogRAfter52Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRAfterStep (getTickSourceLogRAfter53Nat I) - -def getTickStoreAfterLogStep52 (I : ExecutionEnv) : Store := - getTickStoreAfterLogStep (getTickStoreAfterLogStep53 I) - (getTickSourceLog2After53Int I) (getTickSourceLogRAfter53Nat I) 52 - -theorem getTickSourceLogRAfter52Nat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRAfter52Nat I * getTickSourceLogRAfter52Nat I < EVM.wordModulus := by - unfold getTickSourceLogRAfter52Nat getTickSourceLogRAfterStep - exact getTickSourceLogStepRAfterNat_mul_self_lt_wordModulus - (getTickSourceLogRAfter53Nat I) - (getTickSourceLogRAfter53Nat_mul_self_lt_wordModulus I) - -theorem getTickStoreAfterLogStep53_r (I : ExecutionEnv) : - (getTickStoreAfterLogStep53 I).get? "r" = - some (Value.int (Int.ofNat (getTickSourceLogRAfter53Nat I))) := by - simpa [getTickStoreAfterLogStep53, getTickSourceLogRAfter53Nat] - using getTickStoreAfterLogStep_r (getTickStoreAfterLogStep54 I) - (getTickSourceLog2After54Int I) (getTickSourceLogRAfter54Nat I) 53 - -theorem getTickStoreAfterLogStep53_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep53 I).get? "log_2" = - some (Value.int (getTickSourceLog2After53Int I)) := by - simpa [getTickStoreAfterLogStep53, getTickSourceLog2After53Int] - using getTickStoreAfterLogStep_log2 (getTickStoreAfterLogStep54 I) - (getTickSourceLog2After54Int I) (getTickSourceLogRAfter54Nat I) 53 - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep52 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep53 I } - evm (logStep 52 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep52 I } evm) := by - exact getTickSourceLogStepExec evm (getTickStoreAfterLogStep53 I) - (getTickSourceLog2After53Int I) (getTickSourceLogRAfter53Nat I) 52 - (getTickStoreAfterLogStep53_r I) - (getTickStoreAfterLogStep53_log2 I) - (getTickSourceLogRAfter53Nat_mul_self_lt_wordModulus I) - -def getTickSourceLog2After51Int (I : ExecutionEnv) : Int := - getTickSourceLog2AfterStep (getTickSourceLog2After52Int I) (getTickSourceLogRAfter52Nat I) 51 - -def getTickSourceLogRAfter51Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRAfterStep (getTickSourceLogRAfter52Nat I) - -def getTickStoreAfterLogStep51 (I : ExecutionEnv) : Store := - getTickStoreAfterLogStep (getTickStoreAfterLogStep52 I) - (getTickSourceLog2After52Int I) (getTickSourceLogRAfter52Nat I) 51 - -theorem getTickSourceLogRAfter51Nat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRAfter51Nat I * getTickSourceLogRAfter51Nat I < EVM.wordModulus := by - unfold getTickSourceLogRAfter51Nat getTickSourceLogRAfterStep - exact getTickSourceLogStepRAfterNat_mul_self_lt_wordModulus - (getTickSourceLogRAfter52Nat I) - (getTickSourceLogRAfter52Nat_mul_self_lt_wordModulus I) - -theorem getTickStoreAfterLogStep52_r (I : ExecutionEnv) : - (getTickStoreAfterLogStep52 I).get? "r" = - some (Value.int (Int.ofNat (getTickSourceLogRAfter52Nat I))) := by - simpa [getTickStoreAfterLogStep52, getTickSourceLogRAfter52Nat] - using getTickStoreAfterLogStep_r (getTickStoreAfterLogStep53 I) - (getTickSourceLog2After53Int I) (getTickSourceLogRAfter53Nat I) 52 - -theorem getTickStoreAfterLogStep52_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep52 I).get? "log_2" = - some (Value.int (getTickSourceLog2After52Int I)) := by - simpa [getTickStoreAfterLogStep52, getTickSourceLog2After52Int] - using getTickStoreAfterLogStep_log2 (getTickStoreAfterLogStep53 I) - (getTickSourceLog2After53Int I) (getTickSourceLogRAfter53Nat I) 52 - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep51 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep52 I } - evm (logStep 51 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep51 I } evm) := by - exact getTickSourceLogStepExec evm (getTickStoreAfterLogStep52 I) - (getTickSourceLog2After52Int I) (getTickSourceLogRAfter52Nat I) 51 - (getTickStoreAfterLogStep52_r I) - (getTickStoreAfterLogStep52_log2 I) - (getTickSourceLogRAfter52Nat_mul_self_lt_wordModulus I) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogSteps59To51 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep60 I } evm - (logStep 59 true ++ - (logStep 58 true ++ - (logStep 57 true ++ - (logStep 56 true ++ - (logStep 55 true ++ - (logStep 54 true ++ - (logStep 53 true ++ - (logStep 52 true ++ - logStep 51 true)))))))) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep51 I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep59 evm I) - (execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep58 evm I) - (execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep57 evm I) - (execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep56 evm I) - (execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep55 evm I) - (execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep54 evm I) - (execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep53 evm I) - (execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep52 evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep51 evm I)))))))) - -def getTickSourceLogRShifted50Nat (I : ExecutionEnv) : Nat := - getTickSourceLogStepRShiftedNat (getTickSourceLogRAfter51Nat I) - -def getTickSourceLogRShifted50Value (I : ExecutionEnv) : Value := - .int (getTickSourceLogRShifted50Nat I) - -def getTickStoreAfterLogRShifted50 (I : ExecutionEnv) : Store := - getTickSourceLogStepStoreAfterRShifted (getTickStoreAfterLogStep51 I) - (getTickSourceLogRAfter51Nat I) - -def getTickSourceLogF50Nat (I : ExecutionEnv) : Nat := - getTickSourceLogStepFNat (getTickSourceLogRAfter51Nat I) - -def getTickSourceLogF50Value (I : ExecutionEnv) : Value := - .int (getTickSourceLogF50Nat I) - -def getTickStoreAfterLogF50Let (I : ExecutionEnv) : Store := - getTickSourceLogStepStoreAfterFLet (getTickStoreAfterLogStep51 I) - (getTickSourceLogRAfter51Nat I) - -def getTickSourceLog2After50Int (I : ExecutionEnv) : Int := - getTickSourceLog2AfterStep (getTickSourceLog2After51Int I) (getTickSourceLogRAfter51Nat I) 50 - -def getTickSourceLog2After50Value (I : ExecutionEnv) : Value := - .int (getTickSourceLog2After50Int I) - -def getTickStoreAfterLogStep50 (I : ExecutionEnv) : Store := - getTickSourceLogStepStoreAfterLog2 (getTickStoreAfterLogStep51 I) - (getTickSourceLog2After51Int I) (getTickSourceLogRAfter51Nat I) 50 - -theorem getTickSourceLogRShifted50Nat_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRShifted50Nat I < EVM.wordModulus := by - unfold getTickSourceLogRShifted50Nat - exact getTickSourceLogStepRShiftedNat_lt_wordModulus (getTickSourceLogRAfter51Nat I) - (getTickSourceLogRAfter51Nat_mul_self_lt_wordModulus I) - -theorem getTickStoreAfterLogStep51_r (I : ExecutionEnv) : - (getTickStoreAfterLogStep51 I).get? "r" = - some (Value.int (Int.ofNat (getTickSourceLogRAfter51Nat I))) := by - simpa [getTickStoreAfterLogStep51, getTickSourceLogRAfter51Nat] - using getTickStoreAfterLogStep_r (getTickStoreAfterLogStep52 I) - (getTickSourceLog2After52Int I) (getTickSourceLogRAfter52Nat I) 51 - -theorem getTickStoreAfterLogStep51_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep51 I).get? "log_2" = - some (Value.int (getTickSourceLog2After51Int I)) := by - simpa [getTickStoreAfterLogStep51, getTickSourceLog2After51Int] - using getTickStoreAfterLogStep_log2 (getTickStoreAfterLogStep52 I) - (getTickSourceLog2After52Int I) (getTickSourceLogRAfter52Nat I) 51 - -theorem getTickStoreAfterLogRShifted50_r (I : ExecutionEnv) : - (getTickStoreAfterLogRShifted50 I).get? "r" = - some (getTickSourceLogRShifted50Value I) := by - rw [getTickStoreAfterLogRShifted50, getTickSourceLogStepStoreAfterRShifted, - store_get_self] - rfl - -theorem getTickStoreAfterLogRShifted50_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogRShifted50 I).get? "log_2" = - some (Value.int (getTickSourceLog2After51Int I)) := by - rw [getTickStoreAfterLogRShifted50, getTickSourceLogStepStoreAfterRShifted] - rw [store_get_ne (getTickStoreAfterLogStep51 I) (k := "r") (a := "log_2") - (getTickSourceLogStepRShiftedValue (getTickSourceLogRAfter51Nat I)) (by decide)] - exact getTickStoreAfterLogStep51_log2 I - -theorem getTickStoreAfterLogF50Let_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogF50Let I).get? "log_2" = - some (Value.int (getTickSourceLog2After51Int I)) := by - rw [getTickStoreAfterLogF50Let, getTickSourceLogStepStoreAfterFLet] - rw [store_get_ne - (getTickSourceLogStepStoreAfterRShifted (getTickStoreAfterLogStep51 I) - (getTickSourceLogRAfter51Nat I)) - (k := "f") (a := "log_2") - (getTickSourceLogStepFValue (getTickSourceLogRAfter51Nat I)) (by decide)] - simpa [getTickStoreAfterLogRShifted50] using getTickStoreAfterLogRShifted50_log2 I - -theorem getTickStoreAfterLogF50Let_f (I : ExecutionEnv) : - (getTickStoreAfterLogF50Let I).get? "f" = some (getTickSourceLogF50Value I) := by - rw [getTickStoreAfterLogF50Let, getTickSourceLogStepStoreAfterFLet, store_get_self] - rfl - -theorem evalExpr_getTick_log2Var_afterLogF50 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogF50Let I } - evm (.var "log_2") = .ok (Value.int (getTickSourceLog2After51Int I)) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogF50Let_log2] - -theorem evalExpr_getTick_fVar_afterLogF50 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogF50Let I } - evm (.var "f") = .ok (getTickSourceLogF50Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogF50Let_f] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep50 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep51 I } - evm (logStep 50 false) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep50 I } evm) := by - have evalR : evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterLogStep51 I } evm (.var "r") = - .ok (Value.int (Int.ofNat (getTickSourceLogRAfter51Nat I))) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogStep51_r] - have evalMul : evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterLogStep51 I } evm - (mulE (.var "r") (.var "r")) = - .ok (Value.int (Int.ofNat - (getTickSourceLogRAfter51Nat I * getTickSourceLogRAfter51Nat I))) := by - unfold mulE - simp only [evalExpr?, evalR, EvalResult.bind, bind, evalBinaryOp?] - change EvalResult.ok - (Value.int ((getTickSourceLogRAfter51Nat I : Int) * - (getTickSourceLogRAfter51Nat I : Int))) = - EvalResult.ok - (Value.int (((getTickSourceLogRAfter51Nat I * - getTickSourceLogRAfter51Nat I : Nat) : Int))) - rw [← Int.natCast_mul] - have evalRShifted : evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterLogStep51 I } evm - (shrE (mulE (.var "r") (.var "r")) (.intLit 127)) = - .ok (getTickSourceLogRShifted50Value I) := by - unfold shrE - simp only [evalExpr?, evalMul, EvalResult.bind, bind, pure] - rw [evalBinaryOp_int_shr_ok] - · rw [getTickSourceLogRShifted50Value, getTickSourceLogRShifted50Nat, - getTickSourceLogStepRShiftedNat] - rw [intOfNat_toNat_div_pow_127_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceLogRAfter51Nat_mul_self_lt_wordModulus I) - · norm_num - · norm_num - have assignRShifted : - assignStorageRef? (config v) - { contract := contract v, locals := getTickStoreAfterLogStep51 I } - evm .localVar (varRef "r") (getTickSourceLogRShifted50Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterLogRShifted50 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterLogStep51_r] - simp [getTickStoreAfterLogRShifted50, getTickSourceLogStepStoreAfterRShifted, - getTickSourceLogRShifted50Value, getTickSourceLogRShifted50Nat, - getTickSourceLogStepRShiftedValue, updateLocalPath?, pure, bind, EvalResult.bind] - have evalRShiftedVar : evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterLogRShifted50 I } - evm (.var "r") = .ok (getTickSourceLogRShifted50Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogRShifted50_r] - have evalF : evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterLogRShifted50 I } - evm (shrE (.var "r") shift128) = .ok (getTickSourceLogF50Value I) := by - unfold shrE shift128 - simp only [evalExpr?, evalRShiftedVar, EvalResult.bind, bind, pure] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceLogRShifted50Nat I))) - (.int (Int.ofNat 128)) = .ok (getTickSourceLogF50Value I) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceLogF50Value getTickSourceLogF50Nat - rw [getTickSourceLogRShifted50Nat] - rw [getTickSourceLogStepFNat] - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceLogRShifted50Nat_lt_wordModulus I) - · norm_num - · norm_num - have evalLog2Add : evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterLogF50Let I } - evm (addE (.var "log_2") (mulE (.var "f") (.intLit (2 ^ (50 : Nat))))) = - .ok (getTickSourceLog2After50Value I) := by - unfold addE mulE getTickSourceLog2After50Value getTickSourceLog2After50Int - getTickSourceLog2AfterStep - simp only [evalExpr?, evalExpr_getTick_log2Var_afterLogF50, - evalExpr_getTick_fVar_afterLogF50, EvalResult.bind, bind, evalBinaryOp?, - getTickSourceLogF50Value, getTickSourceLogF50Nat, - getTickSourceLogStepLog2AfterInt] - have assignLog2 : - assignStorageRef? (config v) - { contract := contract v, locals := getTickStoreAfterLogF50Let I } - evm .localVar (varRef "log_2") (getTickSourceLog2After50Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterLogStep50 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterLogF50Let_log2] - simp [getTickStoreAfterLogStep50, getTickSourceLogStepStoreAfterLog2, - getTickStoreAfterLogF50Let, getTickSourceLogStepStoreAfterFLet, - getTickSourceLog2After50Value, getTickSourceLog2After50Int, - getTickSourceLog2AfterStep, getTickSourceLogStepLog2AfterValue, - updateLocalPath?, pure, bind, EvalResult.bind] - change ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep51 I } evm - [ .assign .localVar (varRef "r") (shrE (mulE (.var "r") (.var "r")) (.intLit 127)), - .letDecl "f" (some uint256) (shrE (.var "r") shift128), - .assign .localVar (varRef "log_2") - (addE (.var "log_2") (mulE (.var "f") (.intLit (2 ^ (50 : Nat))))) ] - (.ok { contract := contract v, locals := getTickStoreAfterLogStep50 I } evm) - refine ExecBlock.consNormal (ExecStmt.assign evalRShifted assignRShifted) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl evalF) ?_ - exact ExecBlock.consNormal (ExecStmt.assign evalLog2Add assignLog2) ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogSteps59To50 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep60 I } evm - ((logStep 59 true ++ - (logStep 58 true ++ - (logStep 57 true ++ - (logStep 56 true ++ - (logStep 55 true ++ - (logStep 54 true ++ - (logStep 53 true ++ - (logStep 52 true ++ - logStep 51 true)))))))) ++ - logStep 50 false) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep50 I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceLogSteps59To51 evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep50 evm I) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep60.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep60.lean deleted file mode 100644 index d516e953..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep60.lean +++ /dev/null @@ -1,94 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeSourceGetTickLogStep61 - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def getTickSourceLogRShifted60Nat (I : ExecutionEnv) : Nat := - getTickSourceLogStepRShiftedNat (getTickSourceLogRAfter61Nat I) - -def getTickSourceLogF60Nat (I : ExecutionEnv) : Nat := - getTickSourceLogStepFNat (getTickSourceLogRAfter61Nat I) - -def getTickSourceLog2After60Int (I : ExecutionEnv) : Int := - getTickSourceLogStepLog2AfterInt (getTickSourceLog2After61Int I) - (getTickSourceLogRAfter61Nat I) 60 - -def getTickSourceLogRAfter60Nat (I : ExecutionEnv) : Nat := - getTickSourceLogStepRAfterNat (getTickSourceLogRAfter61Nat I) - -def getTickStoreAfterLogStep60 (I : ExecutionEnv) : Store := - getTickSourceLogStepStoreAfter (getTickStoreAfterLogStep61 I) - (getTickSourceLog2After61Int I) (getTickSourceLogRAfter61Nat I) 60 - -theorem getTickSourceLogRAfter60Nat_lt_twoPow128 (I : ExecutionEnv) : - getTickSourceLogRAfter60Nat I < 2 ^ (128 : Nat) := by - unfold getTickSourceLogRAfter60Nat - exact getTickSourceLogStepRAfterNat_lt_twoPow128 - (getTickSourceLogRAfter61Nat I) - (getTickSourceLogRAfter61Nat_mul_self_lt_wordModulus I) - -theorem getTickSourceLogRAfter60Nat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRAfter60Nat I * getTickSourceLogRAfter60Nat I < EVM.wordModulus := by - unfold getTickSourceLogRAfter60Nat - exact getTickSourceLogStepRAfterNat_mul_self_lt_wordModulus - (getTickSourceLogRAfter61Nat I) - (getTickSourceLogRAfter61Nat_mul_self_lt_wordModulus I) - -theorem getTickStoreAfterLogStep61_r (I : ExecutionEnv) : - (getTickStoreAfterLogStep61 I).get? "r" = - some (Value.int (Int.ofNat (getTickSourceLogRAfter61Nat I))) := by - simpa [getTickStoreAfterLogStep61, getTickSourceLogRAfter61Nat, - getTickSourceLogStepRAfterValue] - using getTickSourceLogStepStoreAfter_r (getTickStoreAfterLogStep62 I) - (getTickSourceLog2After62Int I) (getTickSourceLogRAfter62Nat I) 61 - -theorem getTickStoreAfterLogStep61_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep61 I).get? "log_2" = - some (Value.int (getTickSourceLog2After61Int I)) := by - simpa [getTickStoreAfterLogStep61, getTickSourceLog2After61Int, - getTickSourceLogStepLog2AfterValue] - using getTickSourceLogStepStoreAfter_log2 (getTickStoreAfterLogStep62 I) - (getTickSourceLog2After62Int I) (getTickSourceLogRAfter62Nat I) 61 - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep60 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep61 I } - evm (logStep 60 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep60 I } evm) := by - exact getTickSourceLogStepExec evm (getTickStoreAfterLogStep61 I) - (getTickSourceLog2After61Int I) (getTickSourceLogRAfter61Nat I) 60 - (getTickStoreAfterLogStep61_r I) - (getTickStoreAfterLogStep61_log2 I) - (getTickSourceLogRAfter61Nat_mul_self_lt_wordModulus I) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceThroughLogStep60 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - (((((msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF ++ - msbStep 4 0xFFFF ++ - msbStep 3 0xFF ++ - msbStep 2 0xF ++ - msbStep 1 0x3 ++ - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0x1)) (.intLit 1) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - Stmt.ite (geE (.var "msb") (.intLit 128)) - [ .assign .localVar (varRef "r") - (shrE (.var "ratio") (subE (.var "msb") (.intLit 127))) ] - [ .assign .localVar (varRef "r") - (shlE (.var "ratio") (subE (.intLit 127) (.var "msb"))) ], - .letDecl "log_2" (some int256) - (mulE (subE (.var "msb") (.intLit 128)) (.intLit (2 ^ (64 : Nat)))) ]) ++ - logStep 63 true) ++ - logStep 62 true) ++ - logStep 61 true) ++ - logStep 60 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep60 I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceThroughLogStep61 evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep60 evm I) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep61.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep61.lean deleted file mode 100644 index 05833482..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep61.lean +++ /dev/null @@ -1,362 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeSourceGetTickLogStep62 - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def getTickSourceLogStepRShiftedNat (r : Nat) : Nat := - r * r / 2 ^ (127 : Nat) - -def getTickSourceLogStepRShiftedValue (r : Nat) : Value := - .int (getTickSourceLogStepRShiftedNat r) - -def getTickSourceLogStepStoreAfterRShifted (S : Store) (r : Nat) : Store := - S.insert "r" (getTickSourceLogStepRShiftedValue r) - -def getTickSourceLogStepFNat (r : Nat) : Nat := - getTickSourceLogStepRShiftedNat r / 2 ^ (128 : Nat) - -def getTickSourceLogStepFValue (r : Nat) : Value := - .int (getTickSourceLogStepFNat r) - -def getTickSourceLogStepStoreAfterFLet (S : Store) (r : Nat) : Store := - (getTickSourceLogStepStoreAfterRShifted S r).insert "f" (getTickSourceLogStepFValue r) - -def getTickSourceLogStepLog2AfterInt (log2 : Int) (r bit : Nat) : Int := - log2 + (getTickSourceLogStepFNat r : Int) * (2 ^ bit : Int) - -def getTickSourceLogStepLog2AfterValue (log2 : Int) (r bit : Nat) : Value := - .int (getTickSourceLogStepLog2AfterInt log2 r bit) - -def getTickSourceLogStepStoreAfterLog2 (S : Store) (log2 : Int) (r bit : Nat) : Store := - (getTickSourceLogStepStoreAfterFLet S r).insert "log_2" - (getTickSourceLogStepLog2AfterValue log2 r bit) - -def getTickSourceLogStepRAfterNat (r : Nat) : Nat := - getTickSourceLogStepRShiftedNat r / 2 ^ getTickSourceLogStepFNat r - -def getTickSourceLogStepRAfterValue (r : Nat) : Value := - .int (getTickSourceLogStepRAfterNat r) - -def getTickSourceLogStepStoreAfter (S : Store) (log2 : Int) (r bit : Nat) : Store := - (getTickSourceLogStepStoreAfterLog2 S log2 r bit).insert "r" - (getTickSourceLogStepRAfterValue r) - -theorem getTickSourceLogStepRShiftedNat_lt_wordModulus (r : Nat) - (hr : r * r < EVM.wordModulus) : - getTickSourceLogStepRShiftedNat r < EVM.wordModulus := by - unfold getTickSourceLogStepRShiftedNat - exact lt_of_le_of_lt (Nat.div_le_self _ _) hr - -theorem getTickSourceLogStepRShiftedNat_lt_twoPow129 (r : Nat) - (hr : r * r < EVM.wordModulus) : - getTickSourceLogStepRShiftedNat r < 2 ^ (129 : Nat) := by - unfold getTickSourceLogStepRShiftedNat - rw [Nat.div_lt_iff_lt_mul (by norm_num : 0 < 2 ^ (127 : Nat))] - rw [← Nat.pow_add] - norm_num - exact hr - -theorem getTickSourceLogStepFNat_le_1 (r : Nat) (hr : r * r < EVM.wordModulus) : - getTickSourceLogStepFNat r ≤ 1 := by - unfold getTickSourceLogStepFNat - have hshifted := getTickSourceLogStepRShiftedNat_lt_twoPow129 r hr - have hf : getTickSourceLogStepRShiftedNat r / 2 ^ (128 : Nat) < 2 := by - rw [Nat.div_lt_iff_lt_mul (by norm_num : 0 < 2 ^ (128 : Nat))] - norm_num - exact hshifted - omega - -theorem getTickSourceLogStepRAfterNat_lt_twoPow128 (r : Nat) - (hr : r * r < EVM.wordModulus) : - getTickSourceLogStepRAfterNat r < 2 ^ (128 : Nat) := by - unfold getTickSourceLogStepRAfterNat getTickSourceLogStepFNat - exact sourceLogStepNextNat_lt_twoPow128 - (getTickSourceLogStepRShiftedNat r) - (getTickSourceLogStepRShiftedNat_lt_twoPow129 r hr) - -theorem getTickSourceLogStepRAfterNat_mul_self_lt_wordModulus (r : Nat) - (hr : r * r < EVM.wordModulus) : - getTickSourceLogStepRAfterNat r * getTickSourceLogStepRAfterNat r < EVM.wordModulus := by - have hrlt := getTickSourceLogStepRAfterNat_lt_twoPow128 r hr - have hrle : getTickSourceLogStepRAfterNat r ≤ 2 ^ (128 : Nat) - 1 := - Nat.le_pred_of_lt hrlt - have hmul := Nat.mul_le_mul hrle hrle - exact Nat.lt_of_le_of_lt hmul (by norm_num [EVM.wordModulus, EVM.twoPow]) - -theorem getTickSourceLogStepStoreAfter_r (S : Store) (log2 : Int) (r bit : Nat) : - (getTickSourceLogStepStoreAfter S log2 r bit).get? "r" = - some (getTickSourceLogStepRAfterValue r) := by - rw [getTickSourceLogStepStoreAfter, store_get_self] - -theorem getTickSourceLogStepStoreAfter_log2 (S : Store) (log2 : Int) (r bit : Nat) : - (getTickSourceLogStepStoreAfter S log2 r bit).get? "log_2" = - some (getTickSourceLogStepLog2AfterValue log2 r bit) := by - rw [getTickSourceLogStepStoreAfter] - rw [store_get_ne (getTickSourceLogStepStoreAfterLog2 S log2 r bit) (k := "r") - (a := "log_2") (getTickSourceLogStepRAfterValue r) (by decide)] - rw [getTickSourceLogStepStoreAfterLog2, store_get_self] - -theorem getTickSourceLogStepExec {v : PoolImmutables} (evm : EVM.State) - (S : Store) (log2 : Int) (r bit : Nat) - (hrget : S.get? "r" = some (Value.int (Int.ofNat r))) - (hlog2get : S.get? "log_2" = some (Value.int log2)) - (hrmul : r * r < EVM.wordModulus) : - ExecBlock (config v) { contract := contract v, locals := S } evm (logStep bit true) - (.ok { contract := contract v, locals := getTickSourceLogStepStoreAfter S log2 r bit } - evm) := by - have evalR : evalExpr? (config v) { contract := contract v, locals := S } evm - (.var "r") = .ok (.int (Int.ofNat r)) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hrget] - have evalLog2 : evalExpr? (config v) { contract := contract v, locals := S } evm - (.var "log_2") = .ok (.int log2) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hlog2get] - have evalMul : evalExpr? (config v) { contract := contract v, locals := S } evm - (mulE (.var "r") (.var "r")) = .ok (.int (Int.ofNat (r * r))) := by - unfold mulE - simp only [evalExpr?, evalR, EvalResult.bind, bind, evalBinaryOp?] - change EvalResult.ok (Value.int ((r : Int) * (r : Int))) = - EvalResult.ok (Value.int ((r * r : Nat) : Int)) - rw [← Int.natCast_mul] - have evalRShifted : evalExpr? (config v) { contract := contract v, locals := S } evm - (shrE (mulE (.var "r") (.var "r")) (.intLit 127)) = - .ok (getTickSourceLogStepRShiftedValue r) := by - unfold shrE - simp only [evalExpr?, evalMul, EvalResult.bind, bind, pure] - rw [evalBinaryOp_int_shr_ok] - · rw [getTickSourceLogStepRShiftedValue, getTickSourceLogStepRShiftedNat] - rw [intOfNat_toNat_div_pow_127_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr hrmul - · norm_num - · norm_num - have assignRShifted : - assignStorageRef? (config v) { contract := contract v, locals := S } - evm .localVar (varRef "r") (getTickSourceLogStepRShiftedValue r) = - .ok ({ contract := contract v, locals := getTickSourceLogStepStoreAfterRShifted S r }, - evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [hrget] - simp [getTickSourceLogStepStoreAfterRShifted, updateLocalPath?, pure, bind, - EvalResult.bind] - have hShiftedR : (getTickSourceLogStepStoreAfterRShifted S r).get? "r" = - some (getTickSourceLogStepRShiftedValue r) := by - rw [getTickSourceLogStepStoreAfterRShifted, store_get_self] - have hShiftedLog2 : (getTickSourceLogStepStoreAfterRShifted S r).get? "log_2" = - some (Value.int log2) := by - rw [getTickSourceLogStepStoreAfterRShifted] - rw [store_get_ne S (k := "r") (a := "log_2") - (getTickSourceLogStepRShiftedValue r) (by decide)] - exact hlog2get - have evalRShiftedVar : evalExpr? (config v) - { contract := contract v, locals := getTickSourceLogStepStoreAfterRShifted S r } - evm (.var "r") = .ok (getTickSourceLogStepRShiftedValue r) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hShiftedR] - have evalF : evalExpr? (config v) - { contract := contract v, locals := getTickSourceLogStepStoreAfterRShifted S r } - evm (shrE (.var "r") shift128) = .ok (getTickSourceLogStepFValue r) := by - unfold shrE shift128 - simp only [evalExpr?, evalRShiftedVar, EvalResult.bind, bind, pure] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceLogStepRShiftedNat r))) - (.int (Int.ofNat 128)) = .ok (getTickSourceLogStepFValue r) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceLogStepFValue getTickSourceLogStepFNat - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceLogStepRShiftedNat_lt_wordModulus r hrmul) - · norm_num - · norm_num - have hAfterFLog2 : (getTickSourceLogStepStoreAfterFLet S r).get? "log_2" = - some (Value.int log2) := by - rw [getTickSourceLogStepStoreAfterFLet] - rw [store_get_ne (getTickSourceLogStepStoreAfterRShifted S r) (k := "f") - (a := "log_2") (getTickSourceLogStepFValue r) (by decide)] - exact hShiftedLog2 - have hAfterFR : (getTickSourceLogStepStoreAfterFLet S r).get? "r" = - some (getTickSourceLogStepRShiftedValue r) := by - rw [getTickSourceLogStepStoreAfterFLet] - rw [store_get_ne (getTickSourceLogStepStoreAfterRShifted S r) (k := "f") - (a := "r") (getTickSourceLogStepFValue r) (by decide)] - exact hShiftedR - have hAfterFF : (getTickSourceLogStepStoreAfterFLet S r).get? "f" = - some (getTickSourceLogStepFValue r) := by - rw [getTickSourceLogStepStoreAfterFLet, store_get_self] - have evalLog2AfterF : evalExpr? (config v) - { contract := contract v, locals := getTickSourceLogStepStoreAfterFLet S r } - evm (.var "log_2") = .ok (.int log2) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hAfterFLog2] - have evalFAfterF : evalExpr? (config v) - { contract := contract v, locals := getTickSourceLogStepStoreAfterFLet S r } - evm (.var "f") = .ok (getTickSourceLogStepFValue r) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hAfterFF] - have evalLog2Add : evalExpr? (config v) - { contract := contract v, locals := getTickSourceLogStepStoreAfterFLet S r } - evm (addE (.var "log_2") (mulE (.var "f") (.intLit (2 ^ bit)))) = - .ok (getTickSourceLogStepLog2AfterValue log2 r bit) := by - unfold addE mulE getTickSourceLogStepLog2AfterValue getTickSourceLogStepLog2AfterInt - simp only [evalExpr?, evalLog2AfterF, evalFAfterF, EvalResult.bind, bind, - evalBinaryOp?, getTickSourceLogStepFValue] - have assignLog2 : assignStorageRef? (config v) - { contract := contract v, locals := getTickSourceLogStepStoreAfterFLet S r } - evm .localVar (varRef "log_2") (getTickSourceLogStepLog2AfterValue log2 r bit) = - .ok ({ contract := contract v, locals := getTickSourceLogStepStoreAfterLog2 S log2 r bit }, - evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [hAfterFLog2] - simp [getTickSourceLogStepStoreAfterLog2, updateLocalPath?, pure, bind, - EvalResult.bind] - have hAfterLog2R : (getTickSourceLogStepStoreAfterLog2 S log2 r bit).get? "r" = - some (getTickSourceLogStepRShiftedValue r) := by - rw [getTickSourceLogStepStoreAfterLog2] - rw [store_get_ne (getTickSourceLogStepStoreAfterFLet S r) (k := "log_2") - (a := "r") (getTickSourceLogStepLog2AfterValue log2 r bit) (by decide)] - exact hAfterFR - have hAfterLog2F : (getTickSourceLogStepStoreAfterLog2 S log2 r bit).get? "f" = - some (getTickSourceLogStepFValue r) := by - rw [getTickSourceLogStepStoreAfterLog2] - rw [store_get_ne (getTickSourceLogStepStoreAfterFLet S r) (k := "log_2") - (a := "f") (getTickSourceLogStepLog2AfterValue log2 r bit) (by decide)] - exact hAfterFF - have evalRAfterLog2 : evalExpr? (config v) - { contract := contract v, locals := getTickSourceLogStepStoreAfterLog2 S log2 r bit } - evm (.var "r") = .ok (getTickSourceLogStepRShiftedValue r) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hAfterLog2R] - have evalFAfterLog2 : evalExpr? (config v) - { contract := contract v, locals := getTickSourceLogStepStoreAfterLog2 S log2 r bit } - evm (.var "f") = .ok (getTickSourceLogStepFValue r) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hAfterLog2F] - have evalRAfter : evalExpr? (config v) - { contract := contract v, locals := getTickSourceLogStepStoreAfterLog2 S log2 r bit } - evm (shrE (.var "r") (.var "f")) = .ok (getTickSourceLogStepRAfterValue r) := by - unfold shrE - simp only [evalExpr?, evalRAfterLog2, evalFAfterLog2, EvalResult.bind, bind] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceLogStepRShiftedNat r))) - (.int (Int.ofNat (getTickSourceLogStepFNat r))) = - .ok (getTickSourceLogStepRAfterValue r) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceLogStepRAfterValue getTickSourceLogStepRAfterNat - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceLogStepRShiftedNat_lt_wordModulus r hrmul) - · exact Int.natCast_nonneg _ - · have hle := getTickSourceLogStepFNat_le_1 r hrmul - have hlt : getTickSourceLogStepFNat r < 256 := by omega - exact Int.ofNat_lt.mpr hlt - have assignRAfter : assignStorageRef? (config v) - { contract := contract v, locals := getTickSourceLogStepStoreAfterLog2 S log2 r bit } - evm .localVar (varRef "r") (getTickSourceLogStepRAfterValue r) = - .ok ({ contract := contract v, locals := getTickSourceLogStepStoreAfter S log2 r bit }, - evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [hAfterLog2R] - simp [getTickSourceLogStepStoreAfter, updateLocalPath?, pure, bind, EvalResult.bind] - change ExecBlock (config v) { contract := contract v, locals := S } evm - [ .assign .localVar (varRef "r") (shrE (mulE (.var "r") (.var "r")) (.intLit 127)), - .letDecl "f" (some uint256) (shrE (.var "r") shift128), - .assign .localVar (varRef "log_2") - (addE (.var "log_2") (mulE (.var "f") (.intLit (2 ^ bit)))), - .assign .localVar (varRef "r") (shrE (.var "r") (.var "f")) ] - (.ok { contract := contract v, locals := getTickSourceLogStepStoreAfter S log2 r bit } evm) - refine ExecBlock.consNormal (ExecStmt.assign evalRShifted assignRShifted) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl evalF) ?_ - refine ExecBlock.consNormal (ExecStmt.assign evalLog2Add assignLog2) ?_ - exact ExecBlock.consNormal (ExecStmt.assign evalRAfter assignRAfter) ExecBlock.nil - -def getTickSourceLogRShifted61Nat (I : ExecutionEnv) : Nat := - getTickSourceLogStepRShiftedNat (getTickSourceLogRAfter62Nat I) - -def getTickSourceLogF61Nat (I : ExecutionEnv) : Nat := - getTickSourceLogStepFNat (getTickSourceLogRAfter62Nat I) - -def getTickSourceLog2After61Int (I : ExecutionEnv) : Int := - getTickSourceLogStepLog2AfterInt (getTickSourceLog2After62Int I) - (getTickSourceLogRAfter62Nat I) 61 - -def getTickSourceLogRAfter61Nat (I : ExecutionEnv) : Nat := - getTickSourceLogStepRAfterNat (getTickSourceLogRAfter62Nat I) - -def getTickStoreAfterLogStep61 (I : ExecutionEnv) : Store := - getTickSourceLogStepStoreAfter (getTickStoreAfterLogStep62 I) - (getTickSourceLog2After62Int I) (getTickSourceLogRAfter62Nat I) 61 - -theorem getTickSourceLogRAfter61Nat_lt_twoPow128 (I : ExecutionEnv) : - getTickSourceLogRAfter61Nat I < 2 ^ (128 : Nat) := by - unfold getTickSourceLogRAfter61Nat - exact getTickSourceLogStepRAfterNat_lt_twoPow128 - (getTickSourceLogRAfter62Nat I) - (getTickSourceLogRAfter62Nat_mul_self_lt_wordModulus I) - -theorem getTickSourceLogRAfter61Nat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRAfter61Nat I * getTickSourceLogRAfter61Nat I < EVM.wordModulus := by - unfold getTickSourceLogRAfter61Nat - exact getTickSourceLogStepRAfterNat_mul_self_lt_wordModulus - (getTickSourceLogRAfter62Nat I) - (getTickSourceLogRAfter62Nat_mul_self_lt_wordModulus I) - -theorem getTickStoreAfterLog2Step62_log2 (I : ExecutionEnv) : - (getTickStoreAfterLog2Step62 I).get? "log_2" = - some (getTickSourceLog2After62Value I) := by - rw [getTickStoreAfterLog2Step62, store_get_self] - -theorem getTickStoreAfterLogStep62_r (I : ExecutionEnv) : - (getTickStoreAfterLogStep62 I).get? "r" = some (getTickSourceLogRAfter62Value I) := by - rw [getTickStoreAfterLogStep62, store_get_self] - -theorem getTickStoreAfterLogStep62_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep62 I).get? "log_2" = - some (getTickSourceLog2After62Value I) := by - rw [getTickStoreAfterLogStep62] - rw [store_get_ne (getTickStoreAfterLog2Step62 I) (k := "r") (a := "log_2") - (getTickSourceLogRAfter62Value I) (by decide)] - exact getTickStoreAfterLog2Step62_log2 I - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep61 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep62 I } - evm (logStep 61 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep61 I } evm) := by - exact getTickSourceLogStepExec evm (getTickStoreAfterLogStep62 I) - (getTickSourceLog2After62Int I) (getTickSourceLogRAfter62Nat I) 61 - (by simpa [getTickSourceLogRAfter62Value] using getTickStoreAfterLogStep62_r I) - (by simpa [getTickSourceLog2After62Value] using getTickStoreAfterLogStep62_log2 I) - (getTickSourceLogRAfter62Nat_mul_self_lt_wordModulus I) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceThroughLogStep61 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - ((((msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF ++ - msbStep 4 0xFFFF ++ - msbStep 3 0xFF ++ - msbStep 2 0xF ++ - msbStep 1 0x3 ++ - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0x1)) (.intLit 1) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - Stmt.ite (geE (.var "msb") (.intLit 128)) - [ .assign .localVar (varRef "r") - (shrE (.var "ratio") (subE (.var "msb") (.intLit 127))) ] - [ .assign .localVar (varRef "r") - (shlE (.var "ratio") (subE (.intLit 127) (.var "msb"))) ], - .letDecl "log_2" (some int256) - (mulE (subE (.var "msb") (.intLit 128)) (.intLit (2 ^ (64 : Nat)))) ]) ++ - logStep 63 true) ++ - logStep 62 true) ++ - logStep 61 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep61 I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceThroughLogStep62 evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep61 evm I) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep62.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep62.lean deleted file mode 100644 index 8505b044..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickLogStep62.lean +++ /dev/null @@ -1,382 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeSourceGetTickLog - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem sourceLogStepNextNat_lt_twoPow128 (s : Nat) (hs : s < 2 ^ (129 : Nat)) : - s / 2 ^ (s / 2 ^ (128 : Nat)) < 2 ^ (128 : Nat) := by - have hf_lt : s / 2 ^ (128 : Nat) < 2 := by - rw [Nat.div_lt_iff_lt_mul (by norm_num : 0 < 2 ^ (128 : Nat))] - norm_num - exact hs - have hf_le : s / 2 ^ (128 : Nat) ≤ 1 := by omega - by_cases hf0 : s / 2 ^ (128 : Nat) = 0 - · have hs_lt : s < 2 ^ (128 : Nat) := by - have hzero := Nat.div_eq_zero_iff.mp hf0 - omega - rw [hf0] - simpa using hs_lt - · have hf1 : s / 2 ^ (128 : Nat) = 1 := by omega - rw [hf1] - rw [Nat.div_lt_iff_lt_mul (by norm_num : 0 < 2 ^ (1 : Nat))] - norm_num - exact hs - -theorem getTickSourceLogRAfter63Nat_lt_twoPow128 (I : ExecutionEnv) : - getTickSourceLogRAfter63Nat I < 2 ^ (128 : Nat) := by - unfold getTickSourceLogRAfter63Nat getTickSourceLogF63Nat - exact sourceLogStepNextNat_lt_twoPow128 - (getTickSourceLogRShifted63Nat I) (getTickSourceLogRShifted63Nat_lt_twoPow129 I) - -theorem getTickSourceLogRAfter63Nat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRAfter63Nat I * getTickSourceLogRAfter63Nat I < EVM.wordModulus := by - have hr := getTickSourceLogRAfter63Nat_lt_twoPow128 I - have hrle : getTickSourceLogRAfter63Nat I ≤ 2 ^ (128 : Nat) - 1 := - Nat.le_pred_of_lt hr - have hmul := Nat.mul_le_mul hrle hrle - exact Nat.lt_of_le_of_lt hmul (by norm_num [EVM.wordModulus, EVM.twoPow]) - -def getTickSourceLogRShifted62Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRAfter63Nat I * getTickSourceLogRAfter63Nat I / 2 ^ (127 : Nat) - -def getTickSourceLogRShifted62Value (I : ExecutionEnv) : Value := - .int (getTickSourceLogRShifted62Nat I) - -def getTickStoreAfterLogRShifted62 (I : ExecutionEnv) : Store := - (getTickStoreAfterLogStep63 I).insert "r" (getTickSourceLogRShifted62Value I) - -def getTickSourceLogF62Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRShifted62Nat I / 2 ^ (128 : Nat) - -def getTickSourceLogF62Value (I : ExecutionEnv) : Value := - .int (getTickSourceLogF62Nat I) - -def getTickStoreAfterLogF62Let (I : ExecutionEnv) : Store := - (getTickStoreAfterLogRShifted62 I).insert "f" (getTickSourceLogF62Value I) - -def getTickSourceLog2After62Int (I : ExecutionEnv) : Int := - getTickSourceLog2After63Int I + (getTickSourceLogF62Nat I : Int) * (2 ^ (62 : Nat) : Int) - -def getTickSourceLog2After62Value (I : ExecutionEnv) : Value := - .int (getTickSourceLog2After62Int I) - -def getTickStoreAfterLog2Step62 (I : ExecutionEnv) : Store := - (getTickStoreAfterLogF62Let I).insert "log_2" (getTickSourceLog2After62Value I) - -def getTickSourceLogRAfter62Nat (I : ExecutionEnv) : Nat := - getTickSourceLogRShifted62Nat I / 2 ^ getTickSourceLogF62Nat I - -def getTickSourceLogRAfter62Value (I : ExecutionEnv) : Value := - .int (getTickSourceLogRAfter62Nat I) - -def getTickStoreAfterLogStep62 (I : ExecutionEnv) : Store := - (getTickStoreAfterLog2Step62 I).insert "r" (getTickSourceLogRAfter62Value I) - -theorem getTickSourceLogRShifted62Nat_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRShifted62Nat I < EVM.wordModulus := by - unfold getTickSourceLogRShifted62Nat - exact lt_of_le_of_lt (Nat.div_le_self _ _) - (getTickSourceLogRAfter63Nat_mul_self_lt_wordModulus I) - -theorem getTickSourceLogRShifted62Nat_lt_twoPow129 (I : ExecutionEnv) : - getTickSourceLogRShifted62Nat I < 2 ^ (129 : Nat) := by - unfold getTickSourceLogRShifted62Nat - rw [Nat.div_lt_iff_lt_mul (by norm_num : 0 < 2 ^ (127 : Nat))] - rw [← Nat.pow_add] - norm_num - exact getTickSourceLogRAfter63Nat_mul_self_lt_wordModulus I - -theorem getTickSourceLogF62Nat_le_1 (I : ExecutionEnv) : - getTickSourceLogF62Nat I ≤ 1 := by - unfold getTickSourceLogF62Nat - have hshifted := getTickSourceLogRShifted62Nat_lt_twoPow129 I - have hf : getTickSourceLogRShifted62Nat I / 2 ^ (128 : Nat) < 2 := by - rw [Nat.div_lt_iff_lt_mul (by norm_num : 0 < 2 ^ (128 : Nat))] - norm_num - exact hshifted - omega - -theorem getTickSourceLogRAfter62Nat_lt_twoPow128 (I : ExecutionEnv) : - getTickSourceLogRAfter62Nat I < 2 ^ (128 : Nat) := by - unfold getTickSourceLogRAfter62Nat getTickSourceLogF62Nat - exact sourceLogStepNextNat_lt_twoPow128 - (getTickSourceLogRShifted62Nat I) (getTickSourceLogRShifted62Nat_lt_twoPow129 I) - -theorem getTickSourceLogRAfter62Nat_mul_self_lt_wordModulus (I : ExecutionEnv) : - getTickSourceLogRAfter62Nat I * getTickSourceLogRAfter62Nat I < EVM.wordModulus := by - have hr := getTickSourceLogRAfter62Nat_lt_twoPow128 I - have hrle : getTickSourceLogRAfter62Nat I ≤ 2 ^ (128 : Nat) - 1 := - Nat.le_pred_of_lt hr - have hmul := Nat.mul_le_mul hrle hrle - exact Nat.lt_of_le_of_lt hmul (by norm_num [EVM.wordModulus, EVM.twoPow]) - -theorem getTickStoreAfterLog2Step63_log2 (I : ExecutionEnv) : - (getTickStoreAfterLog2Step63 I).get? "log_2" = - some (getTickSourceLog2After63Value I) := by - rw [getTickStoreAfterLog2Step63, store_get_self] - -theorem getTickStoreAfterLogStep63_r (I : ExecutionEnv) : - (getTickStoreAfterLogStep63 I).get? "r" = some (getTickSourceLogRAfter63Value I) := by - rw [getTickStoreAfterLogStep63, store_get_self] - -theorem getTickStoreAfterLogStep63_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep63 I).get? "log_2" = - some (getTickSourceLog2After63Value I) := by - rw [getTickStoreAfterLogStep63] - rw [store_get_ne (getTickStoreAfterLog2Step63 I) (k := "r") (a := "log_2") - (getTickSourceLogRAfter63Value I) (by decide)] - exact getTickStoreAfterLog2Step63_log2 I - -theorem evalExpr_getTick_rVar_afterLogStep63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogStep63 I } - evm (.var "r") = .ok (getTickSourceLogRAfter63Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogStep63_r] - -theorem evalExpr_getTick_log2Var_afterLogStep63 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogStep63 I } - evm (.var "log_2") = .ok (getTickSourceLog2After63Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogStep63_log2] - -theorem evalExpr_getTick_log_r_mul_r_62 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogStep63 I } - evm (mulE (.var "r") (.var "r")) = - .ok (.int (Int.ofNat (getTickSourceLogRAfter63Nat I * getTickSourceLogRAfter63Nat I))) := by - unfold mulE - simp only [evalExpr?, evalExpr_getTick_rVar_afterLogStep63, EvalResult.bind, bind, - evalBinaryOp?, getTickSourceLogRAfter63Value] - rw [← Int.natCast_mul] - rfl - -theorem evalExpr_getTick_log_r_shifted_62 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogStep63 I } - evm (shrE (mulE (.var "r") (.var "r")) (.intLit 127)) = - .ok (getTickSourceLogRShifted62Value I) := by - unfold shrE - simp only [evalExpr?, evalExpr_getTick_log_r_mul_r_62, EvalResult.bind, bind, pure] - rw [evalBinaryOp_int_shr_ok] - · rw [getTickSourceLogRShifted62Value, getTickSourceLogRShifted62Nat] - rw [intOfNat_toNat_div_pow_127_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceLogRAfter63Nat_mul_self_lt_wordModulus I) - · norm_num - · norm_num - -theorem assignStorageRef_getTick_r_shifted62 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterLogStep63 I } - evm .localVar (varRef "r") (getTickSourceLogRShifted62Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterLogRShifted62 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterLogStep63_r] - simp [getTickStoreAfterLogRShifted62, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem getTickStoreAfterLogRShifted62_r (I : ExecutionEnv) : - (getTickStoreAfterLogRShifted62 I).get? "r" = - some (getTickSourceLogRShifted62Value I) := by - rw [getTickStoreAfterLogRShifted62, store_get_self] - -theorem getTickStoreAfterLogRShifted62_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogRShifted62 I).get? "log_2" = - some (getTickSourceLog2After63Value I) := by - rw [getTickStoreAfterLogRShifted62] - rw [store_get_ne (getTickStoreAfterLogStep63 I) (k := "r") (a := "log_2") - (getTickSourceLogRShifted62Value I) (by decide)] - exact getTickStoreAfterLogStep63_log2 I - -theorem evalExpr_getTick_rVar_afterLogRShifted62 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogRShifted62 I } - evm (.var "r") = .ok (getTickSourceLogRShifted62Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogRShifted62_r] - -theorem evalExpr_getTick_log_f62 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogRShifted62 I } - evm (shrE (.var "r") shift128) = .ok (getTickSourceLogF62Value I) := by - unfold shrE shift128 - simp only [evalExpr?, evalExpr_getTick_rVar_afterLogRShifted62, EvalResult.bind, bind, pure] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceLogRShifted62Nat I))) - (.int (Int.ofNat 128)) = .ok (getTickSourceLogF62Value I) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceLogF62Value getTickSourceLogF62Nat - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceLogRShifted62Nat_lt_wordModulus I) - · norm_num - · norm_num - -theorem getTickStoreAfterLogF62Let_r (I : ExecutionEnv) : - (getTickStoreAfterLogF62Let I).get? "r" = - some (getTickSourceLogRShifted62Value I) := by - rw [getTickStoreAfterLogF62Let] - rw [store_get_ne (getTickStoreAfterLogRShifted62 I) (k := "f") (a := "r") - (getTickSourceLogF62Value I) (by decide)] - exact getTickStoreAfterLogRShifted62_r I - -theorem getTickStoreAfterLogF62Let_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogF62Let I).get? "log_2" = - some (getTickSourceLog2After63Value I) := by - rw [getTickStoreAfterLogF62Let] - rw [store_get_ne (getTickStoreAfterLogRShifted62 I) (k := "f") (a := "log_2") - (getTickSourceLogF62Value I) (by decide)] - exact getTickStoreAfterLogRShifted62_log2 I - -theorem getTickStoreAfterLogF62Let_f (I : ExecutionEnv) : - (getTickStoreAfterLogF62Let I).get? "f" = some (getTickSourceLogF62Value I) := by - rw [getTickStoreAfterLogF62Let, store_get_self] - -theorem evalExpr_getTick_log2Var_afterLogF62 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogF62Let I } - evm (.var "log_2") = .ok (getTickSourceLog2After63Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogF62Let_log2] - -theorem evalExpr_getTick_fVar_afterLogF62 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogF62Let I } - evm (.var "f") = .ok (getTickSourceLogF62Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogF62Let_f] - -theorem evalExpr_getTick_log2_add_f62 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogF62Let I } - evm (addE (.var "log_2") (mulE (.var "f") (.intLit (2 ^ (62 : Nat))))) = - .ok (getTickSourceLog2After62Value I) := by - unfold addE mulE getTickSourceLog2After62Value getTickSourceLog2After62Int - simp only [evalExpr?, evalExpr_getTick_log2Var_afterLogF62, evalExpr_getTick_fVar_afterLogF62, - EvalResult.bind, bind, evalBinaryOp?, getTickSourceLogF62Value, - getTickSourceLog2After63Value] - -theorem assignStorageRef_getTick_log2_after62 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterLogF62Let I } - evm .localVar (varRef "log_2") (getTickSourceLog2After62Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterLog2Step62 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterLogF62Let_log2] - simp [getTickStoreAfterLog2Step62, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem getTickStoreAfterLog2Step62_r (I : ExecutionEnv) : - (getTickStoreAfterLog2Step62 I).get? "r" = - some (getTickSourceLogRShifted62Value I) := by - rw [getTickStoreAfterLog2Step62] - rw [store_get_ne (getTickStoreAfterLogF62Let I) (k := "log_2") (a := "r") - (getTickSourceLog2After62Value I) (by decide)] - exact getTickStoreAfterLogF62Let_r I - -theorem getTickStoreAfterLog2Step62_f (I : ExecutionEnv) : - (getTickStoreAfterLog2Step62 I).get? "f" = some (getTickSourceLogF62Value I) := by - rw [getTickStoreAfterLog2Step62] - rw [store_get_ne (getTickStoreAfterLogF62Let I) (k := "log_2") (a := "f") - (getTickSourceLog2After62Value I) (by decide)] - exact getTickStoreAfterLogF62Let_f I - -theorem evalExpr_getTick_rVar_afterLog2Step62 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLog2Step62 I } - evm (.var "r") = .ok (getTickSourceLogRShifted62Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLog2Step62_r] - -theorem evalExpr_getTick_fVar_afterLog2Step62 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLog2Step62 I } - evm (.var "f") = .ok (getTickSourceLogF62Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLog2Step62_f] - -theorem evalExpr_getTick_log_r_after62 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLog2Step62 I } - evm (shrE (.var "r") (.var "f")) = .ok (getTickSourceLogRAfter62Value I) := by - unfold shrE - simp only [evalExpr?, evalExpr_getTick_rVar_afterLog2Step62, - evalExpr_getTick_fVar_afterLog2Step62, EvalResult.bind, bind] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceLogRShifted62Nat I))) - (.int (Int.ofNat (getTickSourceLogF62Nat I))) = - .ok (getTickSourceLogRAfter62Value I) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceLogRAfter62Value getTickSourceLogRAfter62Nat - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceLogRShifted62Nat_lt_wordModulus I) - · exact Int.natCast_nonneg _ - · have hle := getTickSourceLogF62Nat_le_1 I - have hlt : getTickSourceLogF62Nat I < 256 := by omega - exact Int.ofNat_lt.mpr hlt - -theorem assignStorageRef_getTick_r_afterLog62 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterLog2Step62 I } - evm .localVar (varRef "r") (getTickSourceLogRAfter62Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterLogStep62 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterLog2Step62_r] - simp [getTickStoreAfterLogStep62, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStep62 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep63 I } - evm (logStep 62 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep62 I } evm) := by - change ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep63 I } - evm - [ .assign .localVar (varRef "r") (shrE (mulE (.var "r") (.var "r")) (.intLit 127)), - .letDecl "f" (some uint256) (shrE (.var "r") shift128), - .assign .localVar (varRef "log_2") - (addE (.var "log_2") (mulE (.var "f") (.intLit (2 ^ (62 : Nat))))), - .assign .localVar (varRef "r") (shrE (.var "r") (.var "f")) ] - (.ok { contract := contract v, locals := getTickStoreAfterLogStep62 I } evm) - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_log_r_shifted_62 evm I) - (assignStorageRef_getTick_r_shifted62 evm I)) ?_ - refine ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_log_f62 evm I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_log2_add_f62 evm I) - (assignStorageRef_getTick_log2_after62 evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_log_r_after62 evm I) - (assignStorageRef_getTick_r_afterLog62 evm I)) - ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceThroughLogStep62 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - (((msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF ++ - msbStep 4 0xFFFF ++ - msbStep 3 0xFF ++ - msbStep 2 0xF ++ - msbStep 1 0x3 ++ - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0x1)) (.intLit 1) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - Stmt.ite (geE (.var "msb") (.intLit 128)) - [ .assign .localVar (varRef "r") - (shrE (.var "ratio") (subE (.var "msb") (.intLit 127))) ] - [ .assign .localVar (varRef "r") - (shlE (.var "ratio") (subE (.intLit 127) (.var "msb"))) ], - .letDecl "log_2" (some int256) - (mulE (subE (.var "msb") (.intLit 128)) (.intLit (2 ^ (64 : Nat)))) ]) ++ - logStep 63 true) ++ - logStep 62 true) - (.ok { contract := contract v, locals := getTickStoreAfterLogStep62 I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceThroughLogStep63 evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceLogStep62 evm I) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickMsb.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickMsb.lean deleted file mode 100644 index 348598c6..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickMsb.lean +++ /dev/null @@ -1,1473 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeSourceSuccess - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def getTickSourceRAfterMsb5Gt4 (I : ExecutionEnv) : Bool := - decide (getTickSourceRAfterMsb5Nat I > 0xFFFF) - -def getTickSourceMsbF4Nat (I : ExecutionEnv) : Nat := - if getTickSourceRAfterMsb5Gt4 I then 2 ^ (4 : Nat) else 0 - -def getTickSourceMsbF4Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbF4Nat I) - -def getTickStoreAfterF4Let (I : ExecutionEnv) : Store := - (getTickStoreAfterMsbStep5 I).insert "f" (getTickSourceMsbF4Value I) - -def getTickSourceMsbAfter4Nat (I : ExecutionEnv) : Nat := - getTickSourceMsbAfter5Nat I + getTickSourceMsbF4Nat I - -def getTickSourceMsbAfter4Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbAfter4Nat I) - -def getTickStoreAfterMsb4 (I : ExecutionEnv) : Store := - (getTickStoreAfterF4Let I).insert "msb" (getTickSourceMsbAfter4Value I) - -def getTickSourceRAfterMsb4Nat (I : ExecutionEnv) : Nat := - getTickSourceRAfterMsb5Nat I / 2 ^ getTickSourceMsbF4Nat I - -def getTickSourceRAfterMsb4Value (I : ExecutionEnv) : Value := - .int (getTickSourceRAfterMsb4Nat I) - -def getTickStoreAfterMsbStep4 (I : ExecutionEnv) : Store := - (getTickStoreAfterMsb4 I).insert "r" (getTickSourceRAfterMsb4Value I) - -theorem getTickSourceRAfterMsb5Nat_lt_wordModulus (I : ExecutionEnv) : - getTickSourceRAfterMsb5Nat I < EVM.wordModulus := by - unfold getTickSourceRAfterMsb5Nat - exact lt_of_le_of_lt (Nat.div_le_self _ _) (getTickSourceRAfterMsb6Nat_lt_wordModulus I) - -theorem getTickStoreAfterMsb5_msb (I : ExecutionEnv) : - (getTickStoreAfterMsb5 I).get? "msb" = some (getTickSourceMsbAfter5Value I) := by - rw [getTickStoreAfterMsb5, store_get_self] - -theorem getTickStoreAfterMsbStep5_r (I : ExecutionEnv) : - (getTickStoreAfterMsbStep5 I).get? "r" = - some (getTickSourceRAfterMsb5Value I) := by - rw [getTickStoreAfterMsbStep5, store_get_self] - -theorem getTickStoreAfterMsbStep5_msb (I : ExecutionEnv) : - (getTickStoreAfterMsbStep5 I).get? "msb" = - some (getTickSourceMsbAfter5Value I) := by - rw [getTickStoreAfterMsbStep5] - rw [store_get_ne (getTickStoreAfterMsb5 I) (k := "r") (a := "msb") - (getTickSourceRAfterMsb5Value I) (by decide)] - exact getTickStoreAfterMsb5_msb I - -theorem evalExpr_getTick_rVar_afterMsbStep5 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep5 I } - evm (.var "r") = .ok (getTickSourceRAfterMsb5Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbStep5_r] - -theorem evalExpr_getTick_msbVar_afterMsbStep5 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep5 I } - evm (.var "msb") = .ok (getTickSourceMsbAfter5Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbStep5_msb] - -theorem evalBinaryOp_getTick_rAfter5Gt4 (I : ExecutionEnv) : - evalBinaryOp? .gt (getTickSourceRAfterMsb5Value I) - (.int 0xFFFF) = - .ok (.bool (getTickSourceRAfterMsb5Gt4 I)) := by - unfold getTickSourceRAfterMsb5Value getTickSourceRAfterMsb5Gt4 - simp only [evalBinaryOp?] - by_cases h : getTickSourceRAfterMsb5Nat I > 0xFFFF - · have hInt : ((getTickSourceRAfterMsb5Nat I : Nat) : Int) > (0xFFFF : Int) := by - omega - rw [decide_eq_true hInt, decide_eq_true h] - · have hInt : ¬(((getTickSourceRAfterMsb5Nat I : Nat) : Int) > (0xFFFF : Int)) := by - omega - rw [decide_eq_false hInt, decide_eq_false h] - -theorem evalExpr_getTick_msbF4 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep5 I } evm - (.ite (gtE (.var "r") (.intLit 0xFFFF)) - (.intLit (2 ^ (4 : Nat))) (.intLit 0)) = - .ok (getTickSourceMsbF4Value I) := by - unfold gtE getTickSourceMsbF4Value getTickSourceMsbF4Nat - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsbStep5, EvalResult.bind, bind, pure] - rw [evalBinaryOp_getTick_rAfter5Gt4] - cases getTickSourceRAfterMsb5Gt4 I <;> rfl - -theorem getTickSourceMsbF4Nat_le_16 (I : ExecutionEnv) : - getTickSourceMsbF4Nat I ≤ 16 := by - unfold getTickSourceMsbF4Nat - split <;> norm_num - -theorem getTickStoreAfterF4Let_msb (I : ExecutionEnv) : - (getTickStoreAfterF4Let I).get? "msb" = some (getTickSourceMsbAfter5Value I) := by - rw [getTickStoreAfterF4Let] - rw [store_get_ne (getTickStoreAfterMsbStep5 I) (k := "f") (a := "msb") - (getTickSourceMsbF4Value I) (by decide)] - exact getTickStoreAfterMsbStep5_msb I - -theorem getTickStoreAfterF4Let_f (I : ExecutionEnv) : - (getTickStoreAfterF4Let I).get? "f" = some (getTickSourceMsbF4Value I) := by - rw [getTickStoreAfterF4Let, store_get_self] - -theorem evalExpr_getTick_msb_add_f4 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterF4Let I } evm - (addE (.var "msb") (.var "f")) = .ok (getTickSourceMsbAfter4Value I) := by - unfold addE getTickSourceMsbAfter4Value getTickSourceMsbAfter4Nat - simp only [evalExpr?, EvalResult.ofOption, getTickStoreAfterF4Let_msb, - getTickStoreAfterF4Let_f, getTickSourceMsbAfter5Value, getTickSourceMsbF4Value, - EvalResult.bind, bind, evalBinaryOp?] - rw [(Nat.cast_add (getTickSourceMsbAfter5Nat I) (getTickSourceMsbF4Nat I)).symm] - -theorem assignStorageRef_getTick_msb_afterF4 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterF4Let I } - evm .localVar (varRef "msb") (getTickSourceMsbAfter4Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsb4 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterF4Let_msb] - simp [getTickStoreAfterMsb4, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem getTickStoreAfterMsb4_r (I : ExecutionEnv) : - (getTickStoreAfterMsb4 I).get? "r" = some (getTickSourceRAfterMsb5Value I) := by - rw [getTickStoreAfterMsb4] - rw [store_get_ne (getTickStoreAfterF4Let I) (k := "msb") (a := "r") - (getTickSourceMsbAfter4Value I) (by decide)] - rw [getTickStoreAfterF4Let] - rw [store_get_ne (getTickStoreAfterMsbStep5 I) (k := "f") (a := "r") - (getTickSourceMsbF4Value I) (by decide)] - exact getTickStoreAfterMsbStep5_r I - -theorem getTickStoreAfterMsb4_f (I : ExecutionEnv) : - (getTickStoreAfterMsb4 I).get? "f" = some (getTickSourceMsbF4Value I) := by - rw [getTickStoreAfterMsb4] - rw [store_get_ne (getTickStoreAfterF4Let I) (k := "msb") (a := "f") - (getTickSourceMsbAfter4Value I) (by decide)] - exact getTickStoreAfterF4Let_f I - -theorem evalExpr_getTick_rVar_afterMsb4 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb4 I } - evm (.var "r") = .ok (getTickSourceRAfterMsb5Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb4_r] - -theorem evalExpr_getTick_fVar_afterMsb4 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb4 I } - evm (.var "f") = .ok (getTickSourceMsbF4Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb4_f] - -theorem evalExpr_getTick_r_shr_f4 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb4 I } evm - (shrE (.var "r") (.var "f")) = .ok (getTickSourceRAfterMsb4Value I) := by - unfold shrE - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsb4, - evalExpr_getTick_fVar_afterMsb4, EvalResult.bind, bind] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceRAfterMsb5Nat I))) - (.int (Int.ofNat (getTickSourceMsbF4Nat I))) = - .ok (getTickSourceRAfterMsb4Value I) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceRAfterMsb4Value getTickSourceRAfterMsb4Nat - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceRAfterMsb5Nat_lt_wordModulus I) - · exact Int.natCast_nonneg _ - · have hle := getTickSourceMsbF4Nat_le_16 I - have hltNat : getTickSourceMsbF4Nat I < 256 := by omega - exact Int.ofNat_lt.mpr hltNat - -theorem assignStorageRef_getTick_r_afterF4 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterMsb4 I } - evm .localVar (varRef "r") (getTickSourceRAfterMsb4Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsbStep4 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterMsb4_r] - simp [getTickStoreAfterMsbStep4, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep4 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterMsbStep5 I } evm - (msbStep 4 0xFFFF) - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep4 I } evm) := by - change ExecBlock (config v) - { contract := contract v, locals := getTickStoreAfterMsbStep5 I } evm - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0xFFFF)) - (.intLit (2 ^ (4 : Nat))) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - .assign .localVar (varRef "r") (shrE (.var "r") (.var "f")) ] - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep4 I } evm) - refine ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_msbF4 evm I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_msb_add_f4 evm I) - (assignStorageRef_getTick_msb_afterF4 evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_r_shr_f4 evm I) - (assignStorageRef_getTick_r_afterF4 evm I)) - ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps7654 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - (msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF ++ - msbStep 4 0xFFFF) - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep4 I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps765 evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep4 evm I) - -def getTickSourceRAfterMsb4Gt3 (I : ExecutionEnv) : Bool := - decide (getTickSourceRAfterMsb4Nat I > 0xFF) - -def getTickSourceMsbF3Nat (I : ExecutionEnv) : Nat := - if getTickSourceRAfterMsb4Gt3 I then 2 ^ (3 : Nat) else 0 - -def getTickSourceMsbF3Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbF3Nat I) - -def getTickStoreAfterF3Let (I : ExecutionEnv) : Store := - (getTickStoreAfterMsbStep4 I).insert "f" (getTickSourceMsbF3Value I) - -def getTickSourceMsbAfter3Nat (I : ExecutionEnv) : Nat := - getTickSourceMsbAfter4Nat I + getTickSourceMsbF3Nat I - -def getTickSourceMsbAfter3Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbAfter3Nat I) - -def getTickStoreAfterMsb3 (I : ExecutionEnv) : Store := - (getTickStoreAfterF3Let I).insert "msb" (getTickSourceMsbAfter3Value I) - -def getTickSourceRAfterMsb3Nat (I : ExecutionEnv) : Nat := - getTickSourceRAfterMsb4Nat I / 2 ^ getTickSourceMsbF3Nat I - -def getTickSourceRAfterMsb3Value (I : ExecutionEnv) : Value := - .int (getTickSourceRAfterMsb3Nat I) - -def getTickStoreAfterMsbStep3 (I : ExecutionEnv) : Store := - (getTickStoreAfterMsb3 I).insert "r" (getTickSourceRAfterMsb3Value I) - -theorem getTickSourceRAfterMsb4Nat_lt_wordModulus (I : ExecutionEnv) : - getTickSourceRAfterMsb4Nat I < EVM.wordModulus := by - unfold getTickSourceRAfterMsb4Nat - exact lt_of_le_of_lt (Nat.div_le_self _ _) (getTickSourceRAfterMsb5Nat_lt_wordModulus I) - -theorem getTickStoreAfterMsb4_msb (I : ExecutionEnv) : - (getTickStoreAfterMsb4 I).get? "msb" = some (getTickSourceMsbAfter4Value I) := by - rw [getTickStoreAfterMsb4, store_get_self] - -theorem getTickStoreAfterMsbStep4_r (I : ExecutionEnv) : - (getTickStoreAfterMsbStep4 I).get? "r" = - some (getTickSourceRAfterMsb4Value I) := by - rw [getTickStoreAfterMsbStep4, store_get_self] - -theorem getTickStoreAfterMsbStep4_msb (I : ExecutionEnv) : - (getTickStoreAfterMsbStep4 I).get? "msb" = - some (getTickSourceMsbAfter4Value I) := by - rw [getTickStoreAfterMsbStep4] - rw [store_get_ne (getTickStoreAfterMsb4 I) (k := "r") (a := "msb") - (getTickSourceRAfterMsb4Value I) (by decide)] - exact getTickStoreAfterMsb4_msb I - -theorem evalExpr_getTick_rVar_afterMsbStep4 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep4 I } - evm (.var "r") = .ok (getTickSourceRAfterMsb4Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbStep4_r] - -theorem evalExpr_getTick_msbVar_afterMsbStep4 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep4 I } - evm (.var "msb") = .ok (getTickSourceMsbAfter4Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbStep4_msb] - -theorem evalBinaryOp_getTick_rAfter4Gt3 (I : ExecutionEnv) : - evalBinaryOp? .gt (getTickSourceRAfterMsb4Value I) (.int 0xFF) = - .ok (.bool (getTickSourceRAfterMsb4Gt3 I)) := by - unfold getTickSourceRAfterMsb4Value getTickSourceRAfterMsb4Gt3 - simp only [evalBinaryOp?] - by_cases h : getTickSourceRAfterMsb4Nat I > 0xFF - · have hInt : ((getTickSourceRAfterMsb4Nat I : Nat) : Int) > (0xFF : Int) := by - omega - rw [decide_eq_true hInt, decide_eq_true h] - · have hInt : ¬(((getTickSourceRAfterMsb4Nat I : Nat) : Int) > (0xFF : Int)) := by - omega - rw [decide_eq_false hInt, decide_eq_false h] - -theorem evalExpr_getTick_msbF3 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep4 I } evm - (.ite (gtE (.var "r") (.intLit 0xFF)) - (.intLit (2 ^ (3 : Nat))) (.intLit 0)) = - .ok (getTickSourceMsbF3Value I) := by - unfold gtE getTickSourceMsbF3Value getTickSourceMsbF3Nat - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsbStep4, EvalResult.bind, bind, pure] - rw [evalBinaryOp_getTick_rAfter4Gt3] - cases getTickSourceRAfterMsb4Gt3 I <;> rfl - -theorem getTickSourceMsbF3Nat_le_8 (I : ExecutionEnv) : - getTickSourceMsbF3Nat I ≤ 8 := by - unfold getTickSourceMsbF3Nat - split <;> norm_num - -theorem getTickStoreAfterF3Let_msb (I : ExecutionEnv) : - (getTickStoreAfterF3Let I).get? "msb" = some (getTickSourceMsbAfter4Value I) := by - rw [getTickStoreAfterF3Let] - rw [store_get_ne (getTickStoreAfterMsbStep4 I) (k := "f") (a := "msb") - (getTickSourceMsbF3Value I) (by decide)] - exact getTickStoreAfterMsbStep4_msb I - -theorem getTickStoreAfterF3Let_f (I : ExecutionEnv) : - (getTickStoreAfterF3Let I).get? "f" = some (getTickSourceMsbF3Value I) := by - rw [getTickStoreAfterF3Let, store_get_self] - -theorem evalExpr_getTick_msb_add_f3 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterF3Let I } evm - (addE (.var "msb") (.var "f")) = .ok (getTickSourceMsbAfter3Value I) := by - unfold addE getTickSourceMsbAfter3Value getTickSourceMsbAfter3Nat - simp only [evalExpr?, EvalResult.ofOption, getTickStoreAfterF3Let_msb, - getTickStoreAfterF3Let_f, getTickSourceMsbAfter4Value, getTickSourceMsbF3Value, - EvalResult.bind, bind, evalBinaryOp?] - rw [(Nat.cast_add (getTickSourceMsbAfter4Nat I) (getTickSourceMsbF3Nat I)).symm] - -theorem assignStorageRef_getTick_msb_afterF3 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterF3Let I } - evm .localVar (varRef "msb") (getTickSourceMsbAfter3Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsb3 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterF3Let_msb] - simp [getTickStoreAfterMsb3, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem getTickStoreAfterMsb3_r (I : ExecutionEnv) : - (getTickStoreAfterMsb3 I).get? "r" = some (getTickSourceRAfterMsb4Value I) := by - rw [getTickStoreAfterMsb3] - rw [store_get_ne (getTickStoreAfterF3Let I) (k := "msb") (a := "r") - (getTickSourceMsbAfter3Value I) (by decide)] - rw [getTickStoreAfterF3Let] - rw [store_get_ne (getTickStoreAfterMsbStep4 I) (k := "f") (a := "r") - (getTickSourceMsbF3Value I) (by decide)] - exact getTickStoreAfterMsbStep4_r I - -theorem getTickStoreAfterMsb3_f (I : ExecutionEnv) : - (getTickStoreAfterMsb3 I).get? "f" = some (getTickSourceMsbF3Value I) := by - rw [getTickStoreAfterMsb3] - rw [store_get_ne (getTickStoreAfterF3Let I) (k := "msb") (a := "f") - (getTickSourceMsbAfter3Value I) (by decide)] - exact getTickStoreAfterF3Let_f I - -theorem evalExpr_getTick_rVar_afterMsb3 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb3 I } - evm (.var "r") = .ok (getTickSourceRAfterMsb4Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb3_r] - -theorem evalExpr_getTick_fVar_afterMsb3 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb3 I } - evm (.var "f") = .ok (getTickSourceMsbF3Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb3_f] - -theorem evalExpr_getTick_r_shr_f3 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb3 I } evm - (shrE (.var "r") (.var "f")) = .ok (getTickSourceRAfterMsb3Value I) := by - unfold shrE - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsb3, - evalExpr_getTick_fVar_afterMsb3, EvalResult.bind, bind] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceRAfterMsb4Nat I))) - (.int (Int.ofNat (getTickSourceMsbF3Nat I))) = - .ok (getTickSourceRAfterMsb3Value I) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceRAfterMsb3Value getTickSourceRAfterMsb3Nat - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceRAfterMsb4Nat_lt_wordModulus I) - · exact Int.natCast_nonneg _ - · have hle := getTickSourceMsbF3Nat_le_8 I - have hltNat : getTickSourceMsbF3Nat I < 256 := by omega - exact Int.ofNat_lt.mpr hltNat - -theorem assignStorageRef_getTick_r_afterF3 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterMsb3 I } - evm .localVar (varRef "r") (getTickSourceRAfterMsb3Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsbStep3 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterMsb3_r] - simp [getTickStoreAfterMsbStep3, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep3 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterMsbStep4 I } evm - (msbStep 3 0xFF) - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep3 I } evm) := by - change ExecBlock (config v) - { contract := contract v, locals := getTickStoreAfterMsbStep4 I } evm - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0xFF)) - (.intLit (2 ^ (3 : Nat))) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - .assign .localVar (varRef "r") (shrE (.var "r") (.var "f")) ] - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep3 I } evm) - refine ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_msbF3 evm I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_msb_add_f3 evm I) - (assignStorageRef_getTick_msb_afterF3 evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_r_shr_f3 evm I) - (assignStorageRef_getTick_r_afterF3 evm I)) - ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps76543 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - (msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF ++ - msbStep 4 0xFFFF ++ - msbStep 3 0xFF) - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep3 I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps7654 evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep3 evm I) - -def getTickSourceRAfterMsb3Gt2 (I : ExecutionEnv) : Bool := - decide (getTickSourceRAfterMsb3Nat I > 0xF) - -def getTickSourceMsbF2Nat (I : ExecutionEnv) : Nat := - if getTickSourceRAfterMsb3Gt2 I then 2 ^ (2 : Nat) else 0 - -def getTickSourceMsbF2Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbF2Nat I) - -def getTickStoreAfterF2Let (I : ExecutionEnv) : Store := - (getTickStoreAfterMsbStep3 I).insert "f" (getTickSourceMsbF2Value I) - -def getTickSourceMsbAfter2Nat (I : ExecutionEnv) : Nat := - getTickSourceMsbAfter3Nat I + getTickSourceMsbF2Nat I - -def getTickSourceMsbAfter2Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbAfter2Nat I) - -def getTickStoreAfterMsb2 (I : ExecutionEnv) : Store := - (getTickStoreAfterF2Let I).insert "msb" (getTickSourceMsbAfter2Value I) - -def getTickSourceRAfterMsb2Nat (I : ExecutionEnv) : Nat := - getTickSourceRAfterMsb3Nat I / 2 ^ getTickSourceMsbF2Nat I - -def getTickSourceRAfterMsb2Value (I : ExecutionEnv) : Value := - .int (getTickSourceRAfterMsb2Nat I) - -def getTickStoreAfterMsbStep2 (I : ExecutionEnv) : Store := - (getTickStoreAfterMsb2 I).insert "r" (getTickSourceRAfterMsb2Value I) - -theorem getTickSourceRAfterMsb3Nat_lt_wordModulus (I : ExecutionEnv) : - getTickSourceRAfterMsb3Nat I < EVM.wordModulus := by - unfold getTickSourceRAfterMsb3Nat - exact lt_of_le_of_lt (Nat.div_le_self _ _) (getTickSourceRAfterMsb4Nat_lt_wordModulus I) - -theorem getTickStoreAfterMsb3_msb (I : ExecutionEnv) : - (getTickStoreAfterMsb3 I).get? "msb" = some (getTickSourceMsbAfter3Value I) := by - rw [getTickStoreAfterMsb3, store_get_self] - -theorem getTickStoreAfterMsbStep3_r (I : ExecutionEnv) : - (getTickStoreAfterMsbStep3 I).get? "r" = - some (getTickSourceRAfterMsb3Value I) := by - rw [getTickStoreAfterMsbStep3, store_get_self] - -theorem getTickStoreAfterMsbStep3_msb (I : ExecutionEnv) : - (getTickStoreAfterMsbStep3 I).get? "msb" = - some (getTickSourceMsbAfter3Value I) := by - rw [getTickStoreAfterMsbStep3] - rw [store_get_ne (getTickStoreAfterMsb3 I) (k := "r") (a := "msb") - (getTickSourceRAfterMsb3Value I) (by decide)] - exact getTickStoreAfterMsb3_msb I - -theorem evalExpr_getTick_rVar_afterMsbStep3 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep3 I } - evm (.var "r") = .ok (getTickSourceRAfterMsb3Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbStep3_r] - -theorem evalBinaryOp_getTick_rAfter3Gt2 (I : ExecutionEnv) : - evalBinaryOp? .gt (getTickSourceRAfterMsb3Value I) (.int 0xF) = - .ok (.bool (getTickSourceRAfterMsb3Gt2 I)) := by - unfold getTickSourceRAfterMsb3Value getTickSourceRAfterMsb3Gt2 - simp only [evalBinaryOp?] - by_cases h : getTickSourceRAfterMsb3Nat I > 0xF - · have hInt : ((getTickSourceRAfterMsb3Nat I : Nat) : Int) > (0xF : Int) := by - omega - rw [decide_eq_true hInt, decide_eq_true h] - · have hInt : ¬(((getTickSourceRAfterMsb3Nat I : Nat) : Int) > (0xF : Int)) := by - omega - rw [decide_eq_false hInt, decide_eq_false h] - -theorem evalExpr_getTick_msbF2 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep3 I } evm - (.ite (gtE (.var "r") (.intLit 0xF)) - (.intLit (2 ^ (2 : Nat))) (.intLit 0)) = - .ok (getTickSourceMsbF2Value I) := by - unfold gtE getTickSourceMsbF2Value getTickSourceMsbF2Nat - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsbStep3, EvalResult.bind, bind, pure] - rw [evalBinaryOp_getTick_rAfter3Gt2] - cases getTickSourceRAfterMsb3Gt2 I <;> rfl - -theorem getTickSourceMsbF2Nat_le_4 (I : ExecutionEnv) : - getTickSourceMsbF2Nat I ≤ 4 := by - unfold getTickSourceMsbF2Nat - split <;> norm_num - -theorem getTickStoreAfterF2Let_msb (I : ExecutionEnv) : - (getTickStoreAfterF2Let I).get? "msb" = some (getTickSourceMsbAfter3Value I) := by - rw [getTickStoreAfterF2Let] - rw [store_get_ne (getTickStoreAfterMsbStep3 I) (k := "f") (a := "msb") - (getTickSourceMsbF2Value I) (by decide)] - rw [getTickStoreAfterMsbStep3] - rw [store_get_ne (getTickStoreAfterMsb3 I) (k := "r") (a := "msb") - (getTickSourceRAfterMsb3Value I) (by decide)] - exact getTickStoreAfterMsb3_msb I - -theorem getTickStoreAfterF2Let_f (I : ExecutionEnv) : - (getTickStoreAfterF2Let I).get? "f" = some (getTickSourceMsbF2Value I) := by - rw [getTickStoreAfterF2Let, store_get_self] - -theorem evalExpr_getTick_msb_add_f2 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterF2Let I } evm - (addE (.var "msb") (.var "f")) = .ok (getTickSourceMsbAfter2Value I) := by - unfold addE getTickSourceMsbAfter2Value getTickSourceMsbAfter2Nat - simp only [evalExpr?, EvalResult.ofOption, getTickStoreAfterF2Let_msb, - getTickStoreAfterF2Let_f, getTickSourceMsbAfter3Value, getTickSourceMsbF2Value, - EvalResult.bind, bind, evalBinaryOp?] - rw [(Nat.cast_add (getTickSourceMsbAfter3Nat I) (getTickSourceMsbF2Nat I)).symm] - -theorem assignStorageRef_getTick_msb_afterF2 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterF2Let I } - evm .localVar (varRef "msb") (getTickSourceMsbAfter2Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsb2 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterF2Let_msb] - simp [getTickStoreAfterMsb2, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem getTickStoreAfterMsb2_r (I : ExecutionEnv) : - (getTickStoreAfterMsb2 I).get? "r" = some (getTickSourceRAfterMsb3Value I) := by - rw [getTickStoreAfterMsb2] - rw [store_get_ne (getTickStoreAfterF2Let I) (k := "msb") (a := "r") - (getTickSourceMsbAfter2Value I) (by decide)] - rw [getTickStoreAfterF2Let] - rw [store_get_ne (getTickStoreAfterMsbStep3 I) (k := "f") (a := "r") - (getTickSourceMsbF2Value I) (by decide)] - exact getTickStoreAfterMsbStep3_r I - -theorem getTickStoreAfterMsb2_f (I : ExecutionEnv) : - (getTickStoreAfterMsb2 I).get? "f" = some (getTickSourceMsbF2Value I) := by - rw [getTickStoreAfterMsb2] - rw [store_get_ne (getTickStoreAfterF2Let I) (k := "msb") (a := "f") - (getTickSourceMsbAfter2Value I) (by decide)] - exact getTickStoreAfterF2Let_f I - -theorem evalExpr_getTick_rVar_afterMsb2 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb2 I } - evm (.var "r") = .ok (getTickSourceRAfterMsb3Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb2_r] - -theorem evalExpr_getTick_fVar_afterMsb2 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb2 I } - evm (.var "f") = .ok (getTickSourceMsbF2Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb2_f] - -theorem evalExpr_getTick_r_shr_f2 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb2 I } evm - (shrE (.var "r") (.var "f")) = .ok (getTickSourceRAfterMsb2Value I) := by - unfold shrE - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsb2, - evalExpr_getTick_fVar_afterMsb2, EvalResult.bind, bind] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceRAfterMsb3Nat I))) - (.int (Int.ofNat (getTickSourceMsbF2Nat I))) = - .ok (getTickSourceRAfterMsb2Value I) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceRAfterMsb2Value getTickSourceRAfterMsb2Nat - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceRAfterMsb3Nat_lt_wordModulus I) - · exact Int.natCast_nonneg _ - · have hle := getTickSourceMsbF2Nat_le_4 I - have hltNat : getTickSourceMsbF2Nat I < 256 := by omega - exact Int.ofNat_lt.mpr hltNat - -theorem assignStorageRef_getTick_r_afterF2 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterMsb2 I } - evm .localVar (varRef "r") (getTickSourceRAfterMsb2Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsbStep2 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterMsb2_r] - simp [getTickStoreAfterMsbStep2, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep2 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterMsbStep3 I } evm - (msbStep 2 0xF) - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep2 I } evm) := by - change ExecBlock (config v) - { contract := contract v, locals := getTickStoreAfterMsbStep3 I } evm - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0xF)) - (.intLit (2 ^ (2 : Nat))) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - .assign .localVar (varRef "r") (shrE (.var "r") (.var "f")) ] - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep2 I } evm) - refine ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_msbF2 evm I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_msb_add_f2 evm I) - (assignStorageRef_getTick_msb_afterF2 evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_r_shr_f2 evm I) - (assignStorageRef_getTick_r_afterF2 evm I)) - ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps765432 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - (msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF ++ - msbStep 4 0xFFFF ++ - msbStep 3 0xFF ++ - msbStep 2 0xF) - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep2 I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps76543 evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep2 evm I) - -def getTickSourceRAfterMsb2Gt1 (I : ExecutionEnv) : Bool := - decide (getTickSourceRAfterMsb2Nat I > 0x3) - -def getTickSourceMsbF1Nat (I : ExecutionEnv) : Nat := - if getTickSourceRAfterMsb2Gt1 I then 2 ^ (1 : Nat) else 0 - -def getTickSourceMsbF1Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbF1Nat I) - -def getTickStoreAfterF1Let (I : ExecutionEnv) : Store := - (getTickStoreAfterMsbStep2 I).insert "f" (getTickSourceMsbF1Value I) - -def getTickSourceMsbAfter1Nat (I : ExecutionEnv) : Nat := - getTickSourceMsbAfter2Nat I + getTickSourceMsbF1Nat I - -def getTickSourceMsbAfter1Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbAfter1Nat I) - -def getTickStoreAfterMsb1 (I : ExecutionEnv) : Store := - (getTickStoreAfterF1Let I).insert "msb" (getTickSourceMsbAfter1Value I) - -def getTickSourceRAfterMsb1Nat (I : ExecutionEnv) : Nat := - getTickSourceRAfterMsb2Nat I / 2 ^ getTickSourceMsbF1Nat I - -def getTickSourceRAfterMsb1Value (I : ExecutionEnv) : Value := - .int (getTickSourceRAfterMsb1Nat I) - -def getTickStoreAfterMsbStep1 (I : ExecutionEnv) : Store := - (getTickStoreAfterMsb1 I).insert "r" (getTickSourceRAfterMsb1Value I) - -theorem getTickSourceRAfterMsb2Nat_lt_wordModulus (I : ExecutionEnv) : - getTickSourceRAfterMsb2Nat I < EVM.wordModulus := by - unfold getTickSourceRAfterMsb2Nat - exact lt_of_le_of_lt (Nat.div_le_self _ _) (getTickSourceRAfterMsb3Nat_lt_wordModulus I) - -theorem getTickStoreAfterMsb2_msb (I : ExecutionEnv) : - (getTickStoreAfterMsb2 I).get? "msb" = some (getTickSourceMsbAfter2Value I) := by - rw [getTickStoreAfterMsb2, store_get_self] - -theorem getTickStoreAfterMsbStep2_r (I : ExecutionEnv) : - (getTickStoreAfterMsbStep2 I).get? "r" = - some (getTickSourceRAfterMsb2Value I) := by - rw [getTickStoreAfterMsbStep2, store_get_self] - -theorem getTickStoreAfterMsbStep2_msb (I : ExecutionEnv) : - (getTickStoreAfterMsbStep2 I).get? "msb" = - some (getTickSourceMsbAfter2Value I) := by - rw [getTickStoreAfterMsbStep2] - rw [store_get_ne (getTickStoreAfterMsb2 I) (k := "r") (a := "msb") - (getTickSourceRAfterMsb2Value I) (by decide)] - exact getTickStoreAfterMsb2_msb I - -theorem evalExpr_getTick_rVar_afterMsbStep2 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep2 I } - evm (.var "r") = .ok (getTickSourceRAfterMsb2Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbStep2_r] - -theorem evalBinaryOp_getTick_rAfter2Gt1 (I : ExecutionEnv) : - evalBinaryOp? .gt (getTickSourceRAfterMsb2Value I) (.int 0x3) = - .ok (.bool (getTickSourceRAfterMsb2Gt1 I)) := by - unfold getTickSourceRAfterMsb2Value getTickSourceRAfterMsb2Gt1 - simp only [evalBinaryOp?] - by_cases h : getTickSourceRAfterMsb2Nat I > 0x3 - · have hInt : ((getTickSourceRAfterMsb2Nat I : Nat) : Int) > (0x3 : Int) := by - omega - rw [decide_eq_true hInt, decide_eq_true h] - · have hInt : ¬(((getTickSourceRAfterMsb2Nat I : Nat) : Int) > (0x3 : Int)) := by - omega - rw [decide_eq_false hInt, decide_eq_false h] - -theorem evalExpr_getTick_msbF1 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep2 I } evm - (.ite (gtE (.var "r") (.intLit 0x3)) - (.intLit (2 ^ (1 : Nat))) (.intLit 0)) = - .ok (getTickSourceMsbF1Value I) := by - unfold gtE getTickSourceMsbF1Value getTickSourceMsbF1Nat - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsbStep2, EvalResult.bind, bind, pure] - rw [evalBinaryOp_getTick_rAfter2Gt1] - cases getTickSourceRAfterMsb2Gt1 I <;> rfl - -theorem getTickSourceMsbF1Nat_le_2 (I : ExecutionEnv) : - getTickSourceMsbF1Nat I ≤ 2 := by - unfold getTickSourceMsbF1Nat - split <;> norm_num - -theorem getTickStoreAfterF1Let_msb (I : ExecutionEnv) : - (getTickStoreAfterF1Let I).get? "msb" = some (getTickSourceMsbAfter2Value I) := by - rw [getTickStoreAfterF1Let] - rw [store_get_ne (getTickStoreAfterMsbStep2 I) (k := "f") (a := "msb") - (getTickSourceMsbF1Value I) (by decide)] - rw [getTickStoreAfterMsbStep2] - rw [store_get_ne (getTickStoreAfterMsb2 I) (k := "r") (a := "msb") - (getTickSourceRAfterMsb2Value I) (by decide)] - exact getTickStoreAfterMsb2_msb I - -theorem getTickStoreAfterF1Let_f (I : ExecutionEnv) : - (getTickStoreAfterF1Let I).get? "f" = some (getTickSourceMsbF1Value I) := by - rw [getTickStoreAfterF1Let, store_get_self] - -theorem evalExpr_getTick_msb_add_f1 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterF1Let I } evm - (addE (.var "msb") (.var "f")) = .ok (getTickSourceMsbAfter1Value I) := by - unfold addE getTickSourceMsbAfter1Value getTickSourceMsbAfter1Nat - simp only [evalExpr?, EvalResult.ofOption, getTickStoreAfterF1Let_msb, - getTickStoreAfterF1Let_f, getTickSourceMsbAfter2Value, getTickSourceMsbF1Value, - EvalResult.bind, bind, evalBinaryOp?] - rw [(Nat.cast_add (getTickSourceMsbAfter2Nat I) (getTickSourceMsbF1Nat I)).symm] - -theorem assignStorageRef_getTick_msb_afterF1 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterF1Let I } - evm .localVar (varRef "msb") (getTickSourceMsbAfter1Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsb1 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterF1Let_msb] - simp [getTickStoreAfterMsb1, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem getTickStoreAfterMsb1_r (I : ExecutionEnv) : - (getTickStoreAfterMsb1 I).get? "r" = some (getTickSourceRAfterMsb2Value I) := by - rw [getTickStoreAfterMsb1] - rw [store_get_ne (getTickStoreAfterF1Let I) (k := "msb") (a := "r") - (getTickSourceMsbAfter1Value I) (by decide)] - rw [getTickStoreAfterF1Let] - rw [store_get_ne (getTickStoreAfterMsbStep2 I) (k := "f") (a := "r") - (getTickSourceMsbF1Value I) (by decide)] - exact getTickStoreAfterMsbStep2_r I - -theorem getTickStoreAfterMsb1_f (I : ExecutionEnv) : - (getTickStoreAfterMsb1 I).get? "f" = some (getTickSourceMsbF1Value I) := by - rw [getTickStoreAfterMsb1] - rw [store_get_ne (getTickStoreAfterF1Let I) (k := "msb") (a := "f") - (getTickSourceMsbAfter1Value I) (by decide)] - exact getTickStoreAfterF1Let_f I - -theorem evalExpr_getTick_rVar_afterMsb1 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb1 I } - evm (.var "r") = .ok (getTickSourceRAfterMsb2Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb1_r] - -theorem evalExpr_getTick_fVar_afterMsb1 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb1 I } - evm (.var "f") = .ok (getTickSourceMsbF1Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb1_f] - -theorem evalExpr_getTick_r_shr_f1 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb1 I } evm - (shrE (.var "r") (.var "f")) = .ok (getTickSourceRAfterMsb1Value I) := by - unfold shrE - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsb1, - evalExpr_getTick_fVar_afterMsb1, EvalResult.bind, bind] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceRAfterMsb2Nat I))) - (.int (Int.ofNat (getTickSourceMsbF1Nat I))) = - .ok (getTickSourceRAfterMsb1Value I) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceRAfterMsb1Value getTickSourceRAfterMsb1Nat - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceRAfterMsb2Nat_lt_wordModulus I) - · exact Int.natCast_nonneg _ - · have hle := getTickSourceMsbF1Nat_le_2 I - have hltNat : getTickSourceMsbF1Nat I < 256 := by omega - exact Int.ofNat_lt.mpr hltNat - -theorem assignStorageRef_getTick_r_afterF1 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterMsb1 I } - evm .localVar (varRef "r") (getTickSourceRAfterMsb1Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsbStep1 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterMsb1_r] - simp [getTickStoreAfterMsbStep1, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep1 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterMsbStep2 I } evm - (msbStep 1 0x3) - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep1 I } evm) := by - change ExecBlock (config v) - { contract := contract v, locals := getTickStoreAfterMsbStep2 I } evm - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0x3)) - (.intLit (2 ^ (1 : Nat))) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - .assign .localVar (varRef "r") (shrE (.var "r") (.var "f")) ] - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep1 I } evm) - refine ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_msbF1 evm I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_msb_add_f1 evm I) - (assignStorageRef_getTick_msb_afterF1 evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_r_shr_f1 evm I) - (assignStorageRef_getTick_r_afterF1 evm I)) - ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps7654321 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - (msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF ++ - msbStep 4 0xFFFF ++ - msbStep 3 0xFF ++ - msbStep 2 0xF ++ - msbStep 1 0x3) - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep1 I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps765432 evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep1 evm I) - -def getTickSourceRAfterMsb1Gt0 (I : ExecutionEnv) : Bool := - decide (getTickSourceRAfterMsb1Nat I > 0x1) - -def getTickSourceMsbF0Nat (I : ExecutionEnv) : Nat := - if getTickSourceRAfterMsb1Gt0 I then 1 else 0 - -def getTickSourceMsbF0Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbF0Nat I) - -def getTickStoreAfterF0Let (I : ExecutionEnv) : Store := - (getTickStoreAfterMsbStep1 I).insert "f" (getTickSourceMsbF0Value I) - -def getTickSourceMsbAfter0Nat (I : ExecutionEnv) : Nat := - getTickSourceMsbAfter1Nat I + getTickSourceMsbF0Nat I - -def getTickSourceMsbAfter0Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbAfter0Nat I) - -def getTickStoreAfterMsbCombine (I : ExecutionEnv) : Store := - (getTickStoreAfterF0Let I).insert "msb" (getTickSourceMsbAfter0Value I) - -theorem getTickStoreAfterMsb1_msb (I : ExecutionEnv) : - (getTickStoreAfterMsb1 I).get? "msb" = some (getTickSourceMsbAfter1Value I) := by - rw [getTickStoreAfterMsb1, store_get_self] - -theorem getTickStoreAfterMsbStep1_r (I : ExecutionEnv) : - (getTickStoreAfterMsbStep1 I).get? "r" = - some (getTickSourceRAfterMsb1Value I) := by - rw [getTickStoreAfterMsbStep1, store_get_self] - -theorem getTickStoreAfterMsbStep1_msb (I : ExecutionEnv) : - (getTickStoreAfterMsbStep1 I).get? "msb" = - some (getTickSourceMsbAfter1Value I) := by - rw [getTickStoreAfterMsbStep1] - rw [store_get_ne (getTickStoreAfterMsb1 I) (k := "r") (a := "msb") - (getTickSourceRAfterMsb1Value I) (by decide)] - exact getTickStoreAfterMsb1_msb I - -theorem evalExpr_getTick_rVar_afterMsbStep1 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep1 I } - evm (.var "r") = .ok (getTickSourceRAfterMsb1Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbStep1_r] - -theorem evalBinaryOp_getTick_rAfter1Gt0 (I : ExecutionEnv) : - evalBinaryOp? .gt (getTickSourceRAfterMsb1Value I) (.int 0x1) = - .ok (.bool (getTickSourceRAfterMsb1Gt0 I)) := by - unfold getTickSourceRAfterMsb1Value getTickSourceRAfterMsb1Gt0 - simp only [evalBinaryOp?] - by_cases h : getTickSourceRAfterMsb1Nat I > 0x1 - · have hInt : ((getTickSourceRAfterMsb1Nat I : Nat) : Int) > (0x1 : Int) := by - omega - rw [decide_eq_true hInt, decide_eq_true h] - · have hInt : ¬(((getTickSourceRAfterMsb1Nat I : Nat) : Int) > (0x1 : Int)) := by - omega - rw [decide_eq_false hInt, decide_eq_false h] - -theorem evalExpr_getTick_msbF0 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep1 I } evm - (.ite (gtE (.var "r") (.intLit 0x1)) (.intLit 1) (.intLit 0)) = - .ok (getTickSourceMsbF0Value I) := by - unfold gtE getTickSourceMsbF0Value getTickSourceMsbF0Nat - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsbStep1, EvalResult.bind, bind, pure] - rw [evalBinaryOp_getTick_rAfter1Gt0] - cases getTickSourceRAfterMsb1Gt0 I <;> rfl - -theorem getTickStoreAfterF0Let_msb (I : ExecutionEnv) : - (getTickStoreAfterF0Let I).get? "msb" = some (getTickSourceMsbAfter1Value I) := by - rw [getTickStoreAfterF0Let] - rw [store_get_ne (getTickStoreAfterMsbStep1 I) (k := "f") (a := "msb") - (getTickSourceMsbF0Value I) (by decide)] - exact getTickStoreAfterMsbStep1_msb I - -theorem getTickStoreAfterF0Let_f (I : ExecutionEnv) : - (getTickStoreAfterF0Let I).get? "f" = some (getTickSourceMsbF0Value I) := by - rw [getTickStoreAfterF0Let, store_get_self] - -theorem evalExpr_getTick_msb_add_f0 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterF0Let I } evm - (addE (.var "msb") (.var "f")) = .ok (getTickSourceMsbAfter0Value I) := by - unfold addE getTickSourceMsbAfter0Value getTickSourceMsbAfter0Nat - simp only [evalExpr?, EvalResult.ofOption, getTickStoreAfterF0Let_msb, - getTickStoreAfterF0Let_f, getTickSourceMsbAfter1Value, getTickSourceMsbF0Value, - EvalResult.bind, bind, evalBinaryOp?] - rw [(Nat.cast_add (getTickSourceMsbAfter1Nat I) (getTickSourceMsbF0Nat I)).symm] - -theorem assignStorageRef_getTick_msb_afterF0 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterF0Let I } - evm .localVar (varRef "msb") (getTickSourceMsbAfter0Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsbCombine I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterF0Let_msb] - simp [getTickStoreAfterMsbCombine, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbCombine {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterMsbStep1 I } evm - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0x1)) (.intLit 1) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")) ] - (.ok { contract := contract v, locals := getTickStoreAfterMsbCombine I } evm) := by - refine ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_msbF0 evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_msb_add_f0 evm I) - (assignStorageRef_getTick_msb_afterF0 evm I)) - ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps76543210 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - (msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF ++ - msbStep 4 0xFFFF ++ - msbStep 3 0xFF ++ - msbStep 2 0xF ++ - msbStep 1 0x3 ++ - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0x1)) (.intLit 1) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")) ]) - (.ok { contract := contract v, locals := getTickStoreAfterMsbCombine I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps7654321 evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceMsbCombine evm I) - -def getTickSourceMsbGe128 (I : ExecutionEnv) : Bool := - decide (128 ≤ getTickSourceMsbAfter0Nat I) - -def getTickSourceRNormalizedHighNat (I : ExecutionEnv) : Nat := - getTickSourceRatioNat I / 2 ^ (getTickSourceMsbAfter0Nat I - 127) - -def getTickSourceRNormalizedLowNat (I : ExecutionEnv) : Nat := - (getTickSourceRatioNat I * 2 ^ (127 - getTickSourceMsbAfter0Nat I)) % EVM.wordModulus - -def getTickSourceRNormalizedNat (I : ExecutionEnv) : Nat := - if getTickSourceMsbGe128 I then - getTickSourceRNormalizedHighNat I - else - getTickSourceRNormalizedLowNat I - -def getTickSourceRNormalizedValue (I : ExecutionEnv) : Value := - .int (getTickSourceRNormalizedNat I) - -def getTickStoreAfterNormalizeR (I : ExecutionEnv) : Store := - (getTickStoreAfterMsbCombine I).insert "r" (getTickSourceRNormalizedValue I) - -theorem getTickSourceMsbF0Nat_le_1 (I : ExecutionEnv) : - getTickSourceMsbF0Nat I ≤ 1 := by - unfold getTickSourceMsbF0Nat - split <;> norm_num - -theorem getTickSourceMsbAfter0Nat_le_255 (I : ExecutionEnv) : - getTickSourceMsbAfter0Nat I ≤ 255 := by - have h7 := getTickSourceMsbF7Nat_le_128 I - have h6 := getTickSourceMsbF6Nat_le_64 I - have h5 := getTickSourceMsbF5Nat_le_32 I - have h4 := getTickSourceMsbF4Nat_le_16 I - have h3 := getTickSourceMsbF3Nat_le_8 I - have h2 := getTickSourceMsbF2Nat_le_4 I - have h1 := getTickSourceMsbF1Nat_le_2 I - have h0 := getTickSourceMsbF0Nat_le_1 I - unfold getTickSourceMsbAfter0Nat getTickSourceMsbAfter1Nat getTickSourceMsbAfter2Nat - getTickSourceMsbAfter3Nat getTickSourceMsbAfter4Nat getTickSourceMsbAfter5Nat - getTickSourceMsbAfter6Nat - omega - -theorem getTickSourceRNormalizedNat_lt_wordModulus (I : ExecutionEnv) : - getTickSourceRNormalizedNat I < EVM.wordModulus := by - unfold getTickSourceRNormalizedNat getTickSourceRNormalizedHighNat - getTickSourceRNormalizedLowNat - by_cases h : getTickSourceMsbGe128 I - · rw [if_pos h] - exact lt_of_le_of_lt (Nat.div_le_self _ _) (getTickSourceRatioNat_lt_wordModulus I) - · rw [if_neg h] - exact Nat.mod_lt _ (by native_decide : 0 < EVM.wordModulus) - -theorem evalBinaryOp_int_shl_ok {x s : Int} - (hx0 : 0 ≤ x) (hxlt : x < (EVM.wordModulus : Int)) - (hs0 : 0 ≤ s) (hslt : s < 256) : - evalBinaryOp? .shl (.int x) (.int s) = - .ok (.int ((x.toNat * 2 ^ s.toNat) % EVM.wordModulus)) := by - simp only [evalBinaryOp?] - rw [if_pos ⟨hx0, hxlt, hs0⟩] - rw [if_neg] - omega - -theorem intOfNat_toNat_mul_pow_mod_cast (n s : Nat) : - (((Int.ofNat n).toNat * 2 ^ (Int.ofNat s).toNat % EVM.wordModulus : Nat) : Int) = - (n * 2 ^ s % EVM.wordModulus : Nat) := by - rfl - -theorem getTickStoreAfterMsbCombine_msb (I : ExecutionEnv) : - (getTickStoreAfterMsbCombine I).get? "msb" = - some (getTickSourceMsbAfter0Value I) := by - rw [getTickStoreAfterMsbCombine, store_get_self] - -theorem getTickStoreAfterMsbCombine_r (I : ExecutionEnv) : - (getTickStoreAfterMsbCombine I).get? "r" = - some (getTickSourceRAfterMsb1Value I) := by - rw [getTickStoreAfterMsbCombine] - rw [store_get_ne (getTickStoreAfterF0Let I) (k := "msb") (a := "r") - (getTickSourceMsbAfter0Value I) (by decide)] - rw [getTickStoreAfterF0Let] - rw [store_get_ne (getTickStoreAfterMsbStep1 I) (k := "f") (a := "r") - (getTickSourceMsbF0Value I) (by decide)] - exact getTickStoreAfterMsbStep1_r I - -theorem getTickStoreAfterMsbCombine_ratio (I : ExecutionEnv) : - (getTickStoreAfterMsbCombine I).get? "ratio" = some (getTickSourceRatioValue I) := by - rw [getTickStoreAfterMsbCombine] - rw [store_get_ne (getTickStoreAfterF0Let I) (k := "msb") (a := "ratio") - (getTickSourceMsbAfter0Value I) (by decide)] - rw [getTickStoreAfterF0Let] - rw [store_get_ne (getTickStoreAfterMsbStep1 I) (k := "f") (a := "ratio") - (getTickSourceMsbF0Value I) (by decide)] - rw [getTickStoreAfterMsbStep1] - rw [store_get_ne (getTickStoreAfterMsb1 I) (k := "r") (a := "ratio") - (getTickSourceRAfterMsb1Value I) (by decide)] - rw [getTickStoreAfterMsb1] - rw [store_get_ne (getTickStoreAfterF1Let I) (k := "msb") (a := "ratio") - (getTickSourceMsbAfter1Value I) (by decide)] - rw [getTickStoreAfterF1Let] - rw [store_get_ne (getTickStoreAfterMsbStep2 I) (k := "f") (a := "ratio") - (getTickSourceMsbF1Value I) (by decide)] - rw [getTickStoreAfterMsbStep2] - rw [store_get_ne (getTickStoreAfterMsb2 I) (k := "r") (a := "ratio") - (getTickSourceRAfterMsb2Value I) (by decide)] - rw [getTickStoreAfterMsb2] - rw [store_get_ne (getTickStoreAfterF2Let I) (k := "msb") (a := "ratio") - (getTickSourceMsbAfter2Value I) (by decide)] - rw [getTickStoreAfterF2Let] - rw [store_get_ne (getTickStoreAfterMsbStep3 I) (k := "f") (a := "ratio") - (getTickSourceMsbF2Value I) (by decide)] - rw [getTickStoreAfterMsbStep3] - rw [store_get_ne (getTickStoreAfterMsb3 I) (k := "r") (a := "ratio") - (getTickSourceRAfterMsb3Value I) (by decide)] - rw [getTickStoreAfterMsb3] - rw [store_get_ne (getTickStoreAfterF3Let I) (k := "msb") (a := "ratio") - (getTickSourceMsbAfter3Value I) (by decide)] - rw [getTickStoreAfterF3Let] - rw [store_get_ne (getTickStoreAfterMsbStep4 I) (k := "f") (a := "ratio") - (getTickSourceMsbF3Value I) (by decide)] - rw [getTickStoreAfterMsbStep4] - rw [store_get_ne (getTickStoreAfterMsb4 I) (k := "r") (a := "ratio") - (getTickSourceRAfterMsb4Value I) (by decide)] - rw [getTickStoreAfterMsb4] - rw [store_get_ne (getTickStoreAfterF4Let I) (k := "msb") (a := "ratio") - (getTickSourceMsbAfter4Value I) (by decide)] - rw [getTickStoreAfterF4Let] - rw [store_get_ne (getTickStoreAfterMsbStep5 I) (k := "f") (a := "ratio") - (getTickSourceMsbF4Value I) (by decide)] - rw [getTickStoreAfterMsbStep5] - rw [store_get_ne (getTickStoreAfterMsb5 I) (k := "r") (a := "ratio") - (getTickSourceRAfterMsb5Value I) (by decide)] - rw [getTickStoreAfterMsb5] - rw [store_get_ne (getTickStoreAfterF5Let I) (k := "msb") (a := "ratio") - (getTickSourceMsbAfter5Value I) (by decide)] - rw [getTickStoreAfterF5Let] - rw [store_get_ne (getTickStoreAfterMsbStep6 I) (k := "f") (a := "ratio") - (getTickSourceMsbF5Value I) (by decide)] - rw [getTickStoreAfterMsbStep6] - rw [store_get_ne (getTickStoreAfterMsb6 I) (k := "r") (a := "ratio") - (getTickSourceRAfterMsb6Value I) (by decide)] - rw [getTickStoreAfterMsb6] - rw [store_get_ne (getTickStoreAfterF6Let I) (k := "msb") (a := "ratio") - (getTickSourceMsbAfter6Value I) (by decide)] - rw [getTickStoreAfterF6Let] - rw [store_get_ne (getTickStoreAfterMsbStep7 I) (k := "f") (a := "ratio") - (getTickSourceMsbF6Value I) (by decide)] - rw [getTickStoreAfterMsbStep7] - rw [store_get_ne (getTickStoreAfterMsb7 I) (k := "r") (a := "ratio") - (getTickSourceRAfterMsb7Value I) (by decide)] - rw [getTickStoreAfterMsb7] - rw [store_get_ne (getTickStoreAfterF7Let I) (k := "msb") (a := "ratio") - (getTickSourceMsbAfter7Value I) (by decide)] - rw [getTickStoreAfterF7Let] - rw [store_get_ne (getTickStoreWithMsb I) (k := "f") (a := "ratio") - (getTickSourceMsbF7Value I) (by decide)] - rw [getTickStoreWithMsb] - rw [store_get_ne (getTickStoreWithR I) (k := "msb") (a := "ratio") - getTickSourceMsbValue (by decide)] - rw [getTickStoreWithR] - rw [store_get_ne (getTickStoreWithRatio I) (k := "r") (a := "ratio") - (getTickSourceRatioValue I) (by decide)] - exact getTickStoreWithRatio_ratio I - -theorem evalExpr_getTick_msbVar_afterMsbCombine {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbCombine I } - evm (.var "msb") = .ok (getTickSourceMsbAfter0Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbCombine_msb] - -theorem evalExpr_getTick_rVar_afterMsbCombine {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbCombine I } - evm (.var "r") = .ok (getTickSourceRAfterMsb1Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbCombine_r] - -theorem evalExpr_getTick_ratioVar_afterMsbCombine {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbCombine I } - evm (.var "ratio") = .ok (getTickSourceRatioValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbCombine_ratio] - -theorem evalBinaryOp_getTick_msbGe128 (I : ExecutionEnv) : - evalBinaryOp? .ge (getTickSourceMsbAfter0Value I) (.int 128) = - .ok (.bool (getTickSourceMsbGe128 I)) := by - unfold getTickSourceMsbAfter0Value getTickSourceMsbGe128 - simp only [evalBinaryOp?] - by_cases h : 128 ≤ getTickSourceMsbAfter0Nat I - · have hInt : ((getTickSourceMsbAfter0Nat I : Nat) : Int) ≥ (128 : Int) := by - omega - rw [decide_eq_true hInt, decide_eq_true h] - · have hInt : ¬(((getTickSourceMsbAfter0Nat I : Nat) : Int) ≥ (128 : Int)) := by - omega - rw [decide_eq_false hInt, decide_eq_false h] - -theorem evalExpr_getTick_msbGe128 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbCombine I } - evm (geE (.var "msb") (.intLit 128)) = - .ok (.bool (getTickSourceMsbGe128 I)) := by - unfold geE - simp only [evalExpr?, evalExpr_getTick_msbVar_afterMsbCombine, EvalResult.bind, bind, - pure] - exact evalBinaryOp_getTick_msbGe128 I - -theorem evalExpr_getTick_msbMinus127_high {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (hge : getTickSourceMsbGe128 I = true) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbCombine I } - evm (subE (.var "msb") (.intLit 127)) = - .ok (.int (Int.ofNat (getTickSourceMsbAfter0Nat I - 127))) := by - have hNat : 128 ≤ getTickSourceMsbAfter0Nat I := by - unfold getTickSourceMsbGe128 at hge - exact of_decide_eq_true hge - unfold subE - simp only [evalExpr?, evalExpr_getTick_msbVar_afterMsbCombine, EvalResult.bind, bind, - pure, getTickSourceMsbAfter0Value, evalBinaryOp?] - congr 2 - exact (Int.ofNat_sub (m := 127) (n := getTickSourceMsbAfter0Nat I) (by omega)).symm - -theorem evalExpr_getTick_127MinusMsb_low {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (hge : getTickSourceMsbGe128 I = false) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbCombine I } - evm (subE (.intLit 127) (.var "msb")) = - .ok (.int (Int.ofNat (127 - getTickSourceMsbAfter0Nat I))) := by - have hNat : getTickSourceMsbAfter0Nat I < 128 := by - unfold getTickSourceMsbGe128 at hge - exact Nat.lt_of_not_ge (of_decide_eq_false hge) - unfold subE - simp only [evalExpr?, evalExpr_getTick_msbVar_afterMsbCombine, EvalResult.bind, bind, - pure, getTickSourceMsbAfter0Value, evalBinaryOp?] - congr 2 - exact (Int.ofNat_sub (m := getTickSourceMsbAfter0Nat I) (n := 127) (by omega)).symm - -theorem evalExpr_getTick_normalizeR_high {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (hge : getTickSourceMsbGe128 I = true) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbCombine I } - evm (shrE (.var "ratio") (subE (.var "msb") (.intLit 127))) = - .ok (getTickSourceRNormalizedValue I) := by - have hNat : 128 ≤ getTickSourceMsbAfter0Nat I := by - unfold getTickSourceMsbGe128 at hge - exact of_decide_eq_true hge - have hShiftLt : getTickSourceMsbAfter0Nat I - 127 < 256 := by - have hle := getTickSourceMsbAfter0Nat_le_255 I - omega - unfold shrE - simp only [evalExpr?, evalExpr_getTick_ratioVar_afterMsbCombine, - evalExpr_getTick_msbMinus127_high evm I hge, EvalResult.bind, bind] - unfold getTickSourceRatioValue - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceRNormalizedValue getTickSourceRNormalizedNat - getTickSourceRNormalizedHighNat - rw [if_pos hge] - exact congrArg (fun z : Int => (EvalResult.ok (Value.int z) : EvalResult Value)) - (intOfNat_toNat_div_pow_cast (getTickSourceRatioNat I) - (getTickSourceMsbAfter0Nat I - 127)) - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceRatioNat_lt_wordModulus I) - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr hShiftLt - -theorem evalExpr_getTick_normalizeR_low {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (hge : getTickSourceMsbGe128 I = false) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbCombine I } - evm (shlE (.var "ratio") (subE (.intLit 127) (.var "msb"))) = - .ok (getTickSourceRNormalizedValue I) := by - have hNat : getTickSourceMsbAfter0Nat I < 128 := by - unfold getTickSourceMsbGe128 at hge - exact Nat.lt_of_not_ge (of_decide_eq_false hge) - have hShiftLt : 127 - getTickSourceMsbAfter0Nat I < 256 := by omega - unfold shlE - simp only [evalExpr?, evalExpr_getTick_ratioVar_afterMsbCombine, - evalExpr_getTick_127MinusMsb_low evm I hge, EvalResult.bind, bind] - unfold getTickSourceRatioValue - rw [evalBinaryOp_int_shl_ok] - · unfold getTickSourceRNormalizedValue getTickSourceRNormalizedNat - getTickSourceRNormalizedLowNat - rw [if_neg (Bool.eq_false_iff.mp hge)] - exact congrArg (fun z : Int => (EvalResult.ok (Value.int z) : EvalResult Value)) - (intOfNat_toNat_mul_pow_mod_cast (getTickSourceRatioNat I) - (127 - getTickSourceMsbAfter0Nat I)) - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceRatioNat_lt_wordModulus I) - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr hShiftLt - -theorem assignStorageRef_getTick_r_normalized {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterMsbCombine I } - evm .localVar (varRef "r") (getTickSourceRNormalizedValue I) = - .ok ({ contract := contract v, locals := getTickStoreAfterNormalizeR I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterMsbCombine_r] - simp [getTickStoreAfterNormalizeR, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceNormalizeR {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecStmt (config v) { contract := contract v, locals := getTickStoreAfterMsbCombine I } evm - (Stmt.ite (geE (.var "msb") (.intLit 128)) - [ .assign .localVar (varRef "r") - (shrE (.var "ratio") (subE (.var "msb") (.intLit 127))) ] - [ .assign .localVar (varRef "r") - (shlE (.var "ratio") (subE (.intLit 127) (.var "msb"))) ]) - (.ok { contract := contract v, locals := getTickStoreAfterNormalizeR I } evm) := by - by_cases hge : getTickSourceMsbGe128 I = true - · refine ExecStmt.iteTrue ?_ ?_ - · rw [evalExpr_getTick_msbGe128] - rw [hge] - · exact ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_normalizeR_high evm I hge) - (assignStorageRef_getTick_r_normalized evm I)) - ExecBlock.nil - · have hfalse : getTickSourceMsbGe128 I = false := by - exact Bool.eq_false_iff.mpr hge - refine ExecStmt.iteFalse ?_ ?_ - · rw [evalExpr_getTick_msbGe128] - rw [hfalse] - · exact ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_normalizeR_low evm I hfalse) - (assignStorageRef_getTick_r_normalized evm I)) - ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceThroughNormalizeR {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - (msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF ++ - msbStep 4 0xFFFF ++ - msbStep 3 0xFF ++ - msbStep 2 0xF ++ - msbStep 1 0x3 ++ - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0x1)) (.intLit 1) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - Stmt.ite (geE (.var "msb") (.intLit 128)) - [ .assign .localVar (varRef "r") - (shrE (.var "ratio") (subE (.var "msb") (.intLit 127))) ] - [ .assign .localVar (varRef "r") - (shlE (.var "ratio") (subE (.intLit 127) (.var "msb"))) ] ]) - (.ok { contract := contract v, locals := getTickStoreAfterNormalizeR I } evm) := by - change ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - ((msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF ++ - msbStep 4 0xFFFF ++ - msbStep 3 0xFF ++ - msbStep 2 0xF ++ - msbStep 1 0x3 ++ - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0x1)) (.intLit 1) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")) ]) ++ - [ Stmt.ite (geE (.var "msb") (.intLit 128)) - [ .assign .localVar (varRef "r") - (shrE (.var "ratio") (subE (.var "msb") (.intLit 127))) ] - [ .assign .localVar (varRef "r") - (shlE (.var "ratio") (subE (.intLit 127) (.var "msb"))) ] ]) - (.ok { contract := contract v, locals := getTickStoreAfterNormalizeR I } evm) - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps76543210 evm I) - (ExecBlock.consNormal (uniswapV3PoolGetTickAtSqrtRatioSourceNormalizeR evm I) - ExecBlock.nil) - -def getTickSourceLog2BaseInt (I : ExecutionEnv) : Int := - ((getTickSourceMsbAfter0Nat I : Int) - 128) * (2 ^ (64 : Nat) : Int) - -def getTickSourceLog2BaseValue (I : ExecutionEnv) : Value := - .int (getTickSourceLog2BaseInt I) - -def getTickStoreAfterLog2BaseLet (I : ExecutionEnv) : Store := - (getTickStoreAfterNormalizeR I).insert "log_2" (getTickSourceLog2BaseValue I) - -theorem getTickStoreAfterNormalizeR_msb (I : ExecutionEnv) : - (getTickStoreAfterNormalizeR I).get? "msb" = - some (getTickSourceMsbAfter0Value I) := by - rw [getTickStoreAfterNormalizeR] - rw [store_get_ne (getTickStoreAfterMsbCombine I) (k := "r") (a := "msb") - (getTickSourceRNormalizedValue I) (by decide)] - exact getTickStoreAfterMsbCombine_msb I - -theorem evalExpr_getTick_msbVar_afterNormalizeR {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterNormalizeR I } - evm (.var "msb") = .ok (getTickSourceMsbAfter0Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterNormalizeR_msb] - -theorem evalExpr_getTick_msbMinus128 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterNormalizeR I } - evm (subE (.var "msb") (.intLit 128)) = - .ok (.int ((getTickSourceMsbAfter0Nat I : Int) - 128)) := by - unfold subE - simp only [evalExpr?, evalExpr_getTick_msbVar_afterNormalizeR, getTickSourceMsbAfter0Value, - EvalResult.bind, bind, pure, evalBinaryOp?] - -theorem evalExpr_getTick_log2Base {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterNormalizeR I } - evm (mulE (subE (.var "msb") (.intLit 128)) (.intLit (2 ^ (64 : Nat)))) = - .ok (getTickSourceLog2BaseValue I) := by - unfold mulE getTickSourceLog2BaseValue getTickSourceLog2BaseInt - simp only [evalExpr?, evalExpr_getTick_msbMinus128, EvalResult.bind, bind, pure, - evalBinaryOp?] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLog2BaseLet {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterNormalizeR I } - evm - [ .letDecl "log_2" (some int256) - (mulE (subE (.var "msb") (.intLit 128)) (.intLit (2 ^ (64 : Nat)))) ] - (.ok { contract := contract v, locals := getTickStoreAfterLog2BaseLet I } evm) := by - exact ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_log2Base evm I)) - ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceThroughLog2Base {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - (msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF ++ - msbStep 4 0xFFFF ++ - msbStep 3 0xFF ++ - msbStep 2 0xF ++ - msbStep 1 0x3 ++ - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0x1)) (.intLit 1) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - Stmt.ite (geE (.var "msb") (.intLit 128)) - [ .assign .localVar (varRef "r") - (shrE (.var "ratio") (subE (.var "msb") (.intLit 127))) ] - [ .assign .localVar (varRef "r") - (shlE (.var "ratio") (subE (.intLit 127) (.var "msb"))) ], - .letDecl "log_2" (some int256) - (mulE (subE (.var "msb") (.intLit 128)) (.intLit (2 ^ (64 : Nat)))) ]) - (.ok { contract := contract v, locals := getTickStoreAfterLog2BaseLet I } evm) := by - change ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - ((msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF ++ - msbStep 4 0xFFFF ++ - msbStep 3 0xFF ++ - msbStep 2 0xF ++ - msbStep 1 0x3 ++ - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0x1)) (.intLit 1) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - Stmt.ite (geE (.var "msb") (.intLit 128)) - [ .assign .localVar (varRef "r") - (shrE (.var "ratio") (subE (.var "msb") (.intLit 127))) ] - [ .assign .localVar (varRef "r") - (shlE (.var "ratio") (subE (.intLit 127) (.var "msb"))) ] ]) ++ - [ .letDecl "log_2" (some int256) - (mulE (subE (.var "msb") (.intLit 128)) (.intLit (2 ^ (64 : Nat)))) ]) - (.ok { contract := contract v, locals := getTickStoreAfterLog2BaseLet I } evm) - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceThroughNormalizeR evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceLog2BaseLet evm I) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickPostLog.lean b/Benchmarks/UniswapV3Pool/InitializeSourceGetTickPostLog.lean deleted file mode 100644 index de6c41ed..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeSourceGetTickPostLog.lean +++ /dev/null @@ -1,1120 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeSourceGetTickLogRemaining - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def getTickSourceLogSqrt10001MultiplierInt : Int := - 255738958999603826347141 - -def getTickSourceLogSqrt10001Int (I : ExecutionEnv) : Int := - getTickSourceLog2After50Int I * getTickSourceLogSqrt10001MultiplierInt - -def getTickSourceLogSqrt10001Value (I : ExecutionEnv) : Value := - .int (getTickSourceLogSqrt10001Int I) - -def getTickStoreAfterLogSqrt10001 (I : ExecutionEnv) : Store := - (getTickStoreAfterLogStep50 I).insert "log_sqrt10001" (getTickSourceLogSqrt10001Value I) - -def getTickSourceTickLowOffsetInt : Int := - 3402992956809132418596140100660247210 - -def getTickSourceTickHiOffsetInt : Int := - 291339464771989622907027621153398088495 - -def getTickSourceFixedPoint128Int : Int := - 2 ^ (128 : Nat) - -def getTickSourceTickLowInt (I : ExecutionEnv) : Int := - (getTickSourceLogSqrt10001Int I - getTickSourceTickLowOffsetInt) / - getTickSourceFixedPoint128Int - -def getTickSourceTickLowValue (I : ExecutionEnv) : Value := - .int (getTickSourceTickLowInt I) - -def getTickStoreAfterTickLowLet (I : ExecutionEnv) : Store := - (getTickStoreAfterLogSqrt10001 I).insert "tickLow" (getTickSourceTickLowValue I) - -def getTickSourceTickHiInt (I : ExecutionEnv) : Int := - (getTickSourceLogSqrt10001Int I + getTickSourceTickHiOffsetInt) / - getTickSourceFixedPoint128Int - -def getTickSourceTickHiValue (I : ExecutionEnv) : Value := - .int (getTickSourceTickHiInt I) - -def getTickStoreAfterTickHiLet (I : ExecutionEnv) : Store := - (getTickStoreAfterTickLowLet I).insert "tickHi" (getTickSourceTickHiValue I) - -def getTickSourceSqrtRatioAtTickHiValue (I : ExecutionEnv) : Value := - .int (Int.ofNat (getTickHiSqrtRatioWord I).toNat) - -def getTickStoreForSqrtRatioAtTickHiCall (I : ExecutionEnv) : Store := - (∅ : Store).insert "tick" (getTickSourceTickHiValue I) - -def getTickStoreAfterSqrtRatioAtTickHiCall (I : ExecutionEnv) : Store := - (getTickStoreAfterTickHiLet I).insert "sqrtRatioAtTickHi" - (getTickSourceSqrtRatioAtTickHiValue I) - -def getTickSourceFinalReturnExpr : Expr := - .ite (eqE (.var "tickLow") (.var "tickHi")) - (.var "tickLow") - (.ite (leE (.var "sqrtRatioAtTickHi") (.var "sqrtPriceX96")) - (.var "tickHi") - (.var "tickLow")) - -def getTickSourceFinalValue (I : ExecutionEnv) : Value := - if getTickSourceTickLowValue I == getTickSourceTickHiValue I then - getTickSourceTickLowValue I - else if Int.ofNat (getTickHiSqrtRatioWord I).toNat ≤ Int.ofNat (initializeArgWord I).toNat then - getTickSourceTickHiValue I - else - getTickSourceTickLowValue I - -theorem getTickStoreAfterLogStep50_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogStep50 I).get? "log_2" = - some (Value.int (getTickSourceLog2After50Int I)) := by - rw [getTickStoreAfterLogStep50, getTickSourceLogStepStoreAfterLog2, store_get_self] - rfl - -theorem getTickStoreAfterLogSqrt10001_log (I : ExecutionEnv) : - (getTickStoreAfterLogSqrt10001 I).get? "log_sqrt10001" = - some (getTickSourceLogSqrt10001Value I) := by - rw [getTickStoreAfterLogSqrt10001, store_get_self] - -theorem getTickStoreAfterLogSqrt10001_log2 (I : ExecutionEnv) : - (getTickStoreAfterLogSqrt10001 I).get? "log_2" = - some (Value.int (getTickSourceLog2After50Int I)) := by - rw [getTickStoreAfterLogSqrt10001] - rw [store_get_ne (getTickStoreAfterLogStep50 I) (k := "log_sqrt10001") (a := "log_2") - (getTickSourceLogSqrt10001Value I) (by decide)] - exact getTickStoreAfterLogStep50_log2 I - -theorem getTickStoreAfterLogSqrt10001_sqrtPriceX96_of_logStep50 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep50 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterLogSqrt10001 I).get? "sqrtPriceX96" = - some (initializeArgValue I) := by - rw [getTickStoreAfterLogSqrt10001] - rw [store_get_ne (getTickStoreAfterLogStep50 I) (k := "log_sqrt10001") - (a := "sqrtPriceX96") (getTickSourceLogSqrt10001Value I) (by decide)] - exact hsqrtPrice - -theorem getTickStoreAfterTickLowLet_log (I : ExecutionEnv) : - (getTickStoreAfterTickLowLet I).get? "log_sqrt10001" = - some (getTickSourceLogSqrt10001Value I) := by - rw [getTickStoreAfterTickLowLet] - rw [store_get_ne (getTickStoreAfterLogSqrt10001 I) (k := "tickLow") - (a := "log_sqrt10001") (getTickSourceTickLowValue I) (by decide)] - exact getTickStoreAfterLogSqrt10001_log I - -theorem getTickStoreAfterTickLowLet_tickLow (I : ExecutionEnv) : - (getTickStoreAfterTickLowLet I).get? "tickLow" = - some (getTickSourceTickLowValue I) := by - rw [getTickStoreAfterTickLowLet, store_get_self] - -theorem getTickStoreAfterTickLowLet_sqrtPriceX96_of_logStep50 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep50 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterTickLowLet I).get? "sqrtPriceX96" = - some (initializeArgValue I) := by - rw [getTickStoreAfterTickLowLet] - rw [store_get_ne (getTickStoreAfterLogSqrt10001 I) (k := "tickLow") - (a := "sqrtPriceX96") (getTickSourceTickLowValue I) (by decide)] - exact getTickStoreAfterLogSqrt10001_sqrtPriceX96_of_logStep50 I hsqrtPrice - -theorem getTickStoreAfterTickHiLet_log (I : ExecutionEnv) : - (getTickStoreAfterTickHiLet I).get? "log_sqrt10001" = - some (getTickSourceLogSqrt10001Value I) := by - rw [getTickStoreAfterTickHiLet] - rw [store_get_ne (getTickStoreAfterTickLowLet I) (k := "tickHi") - (a := "log_sqrt10001") (getTickSourceTickHiValue I) (by decide)] - exact getTickStoreAfterTickLowLet_log I - -theorem getTickStoreAfterTickHiLet_tickLow (I : ExecutionEnv) : - (getTickStoreAfterTickHiLet I).get? "tickLow" = - some (getTickSourceTickLowValue I) := by - rw [getTickStoreAfterTickHiLet] - rw [store_get_ne (getTickStoreAfterTickLowLet I) (k := "tickHi") (a := "tickLow") - (getTickSourceTickHiValue I) (by decide)] - exact getTickStoreAfterTickLowLet_tickLow I - -theorem getTickStoreAfterTickHiLet_tickHi (I : ExecutionEnv) : - (getTickStoreAfterTickHiLet I).get? "tickHi" = - some (getTickSourceTickHiValue I) := by - rw [getTickStoreAfterTickHiLet, store_get_self] - -theorem getTickStoreAfterTickHiLet_sqrtPriceX96_of_logStep50 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep50 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterTickHiLet I).get? "sqrtPriceX96" = - some (initializeArgValue I) := by - rw [getTickStoreAfterTickHiLet] - rw [store_get_ne (getTickStoreAfterTickLowLet I) (k := "tickHi") - (a := "sqrtPriceX96") (getTickSourceTickHiValue I) (by decide)] - exact getTickStoreAfterTickLowLet_sqrtPriceX96_of_logStep50 I hsqrtPrice - -theorem evalExpr_getTick_tickHiVar_afterTickHi {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterTickHiLet I } - evm (.var "tickHi") = .ok (getTickSourceTickHiValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterTickHiLet_tickHi] - -theorem evalExprs_getTick_tickHiArg_afterTickHi {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExprs? (config v) { contract := contract v, locals := getTickStoreAfterTickHiLet I } - evm [.var "tickHi"] = .ok [getTickSourceTickHiValue I] := by - simp only [evalExprs?, evalExpr_getTick_tickHiVar_afterTickHi, EvalResult.bind, bind, pure] - -theorem evalBinaryOp_int_eq_ok (x y : Int) : - evalBinaryOp? .eq (.int x) (.int y) = .ok (.bool ((Value.int x) == Value.int y)) := by - rfl - -theorem evalBinaryOp_int_le_ok (x y : Int) : - evalBinaryOp? .le (.int x) (.int y) = .ok (.bool (x ≤ y)) := by - rfl - -theorem evalExpr_ite_true {cfg : Config} {solm : Frame} {evm : EVM.State} - {cond thenExpr elseExpr : Expr} {value : Value} - (hcond : evalExpr? cfg solm evm cond = .ok (.bool true)) - (hthen : evalExpr? cfg solm evm thenExpr = .ok value) : - evalExpr? cfg solm evm (.ite cond thenExpr elseExpr) = .ok value := by - simp only [evalExpr?, hcond, EvalResult.bind, bind] - exact hthen - -theorem evalExpr_ite_false {cfg : Config} {solm : Frame} {evm : EVM.State} - {cond thenExpr elseExpr : Expr} {value : Value} - (hcond : evalExpr? cfg solm evm cond = .ok (.bool false)) - (helse : evalExpr? cfg solm evm elseExpr = .ok value) : - evalExpr? cfg solm evm (.ite cond thenExpr elseExpr) = .ok value := by - simp only [evalExpr?, hcond, EvalResult.bind, bind] - exact helse - -theorem getTickStoreAfterSqrtRatioAtTickHiCall_tickLow (I : ExecutionEnv) : - (getTickStoreAfterSqrtRatioAtTickHiCall I).get? "tickLow" = - some (getTickSourceTickLowValue I) := by - rw [getTickStoreAfterSqrtRatioAtTickHiCall] - rw [store_get_ne (getTickStoreAfterTickHiLet I) (k := "sqrtRatioAtTickHi") - (a := "tickLow") (getTickSourceSqrtRatioAtTickHiValue I) (by decide)] - exact getTickStoreAfterTickHiLet_tickLow I - -theorem getTickStoreAfterSqrtRatioAtTickHiCall_tickHi (I : ExecutionEnv) : - (getTickStoreAfterSqrtRatioAtTickHiCall I).get? "tickHi" = - some (getTickSourceTickHiValue I) := by - rw [getTickStoreAfterSqrtRatioAtTickHiCall] - rw [store_get_ne (getTickStoreAfterTickHiLet I) (k := "sqrtRatioAtTickHi") - (a := "tickHi") (getTickSourceSqrtRatioAtTickHiValue I) (by decide)] - exact getTickStoreAfterTickHiLet_tickHi I - -set_option maxRecDepth 4096 in -theorem getTickStoreAfterSqrtRatioAtTickHiCall_sqrtRatioAtTickHi (I : ExecutionEnv) : - (getTickStoreAfterSqrtRatioAtTickHiCall I).get? "sqrtRatioAtTickHi" = - some (getTickSourceSqrtRatioAtTickHiValue I) := by - rw [getTickStoreAfterSqrtRatioAtTickHiCall, store_get_self] - -theorem getTickStoreAfterSqrtRatioAtTickHiCall_sqrtPriceX96_of_logStep50 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep50 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterSqrtRatioAtTickHiCall I).get? "sqrtPriceX96" = - some (initializeArgValue I) := by - rw [getTickStoreAfterSqrtRatioAtTickHiCall] - rw [store_get_ne (getTickStoreAfterTickHiLet I) (k := "sqrtRatioAtTickHi") - (a := "sqrtPriceX96") (getTickSourceSqrtRatioAtTickHiValue I) (by decide)] - exact getTickStoreAfterTickHiLet_sqrtPriceX96_of_logStep50 I hsqrtPrice - -theorem evalExpr_getTick_tickLowVar_afterSqrtRatioAtTickHiCall - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (.var "tickLow") = .ok (getTickSourceTickLowValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterSqrtRatioAtTickHiCall_tickLow] - -theorem evalExpr_getTick_tickHiVar_afterSqrtRatioAtTickHiCall - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (.var "tickHi") = .ok (getTickSourceTickHiValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterSqrtRatioAtTickHiCall_tickHi] - -theorem evalExpr_getTick_sqrtRatioAtTickHiVar_afterSqrtRatioAtTickHiCall - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (.var "sqrtRatioAtTickHi") = .ok (getTickSourceSqrtRatioAtTickHiValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterSqrtRatioAtTickHiCall_sqrtRatioAtTickHi] - -theorem evalExpr_getTick_sqrtPriceX96Var_afterSqrtRatioAtTickHiCall - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterSqrtRatioAtTickHiCall I).get? "sqrtPriceX96" = - some (initializeArgValue I)) : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (.var "sqrtPriceX96") = .ok (initializeArgValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [hsqrtPrice] - -theorem evalExpr_getTick_tickLowEqTickHi_afterSqrtRatioAtTickHiCall - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (eqE (.var "tickLow") (.var "tickHi")) = - .ok (.bool (getTickSourceTickLowValue I == getTickSourceTickHiValue I)) := by - unfold eqE - simp only [evalExpr?, evalExpr_getTick_tickLowVar_afterSqrtRatioAtTickHiCall, - evalExpr_getTick_tickHiVar_afterSqrtRatioAtTickHiCall, EvalResult.bind, bind] - unfold getTickSourceTickLowValue getTickSourceTickHiValue - exact evalBinaryOp_int_eq_ok (getTickSourceTickLowInt I) (getTickSourceTickHiInt I) - -theorem evalExpr_getTick_sqrtRatioAtTickHiLeSqrtPrice_afterSqrtRatioAtTickHiCall - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterSqrtRatioAtTickHiCall I).get? "sqrtPriceX96" = - some (initializeArgValue I)) : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (leE (.var "sqrtRatioAtTickHi") (.var "sqrtPriceX96")) = - .ok (.bool (Int.ofNat (getTickHiSqrtRatioWord I).toNat ≤ - Int.ofNat (initializeArgWord I).toNat)) := by - unfold leE - simp only [evalExpr?, evalExpr_getTick_sqrtRatioAtTickHiVar_afterSqrtRatioAtTickHiCall, - evalExpr_getTick_sqrtPriceX96Var_afterSqrtRatioAtTickHiCall, EvalResult.bind, bind, - hsqrtPrice] - unfold getTickSourceSqrtRatioAtTickHiValue initializeArgValue - exact evalBinaryOp_int_le_ok (Int.ofNat (getTickHiSqrtRatioWord I).toNat) - (Int.ofNat (initializeArgWord I).toNat) - -theorem evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterSqrtRatioAtTickHiCall I).get? "sqrtPriceX96" = - some (initializeArgValue I)) : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm getTickSourceFinalReturnExpr = .ok (getTickSourceFinalValue I) := by - unfold getTickSourceFinalReturnExpr getTickSourceFinalValue - by_cases hEq : (getTickSourceTickLowValue I == getTickSourceTickHiValue I) = true - · rw [if_pos hEq] - apply evalExpr_ite_true - · rw [evalExpr_getTick_tickLowEqTickHi_afterSqrtRatioAtTickHiCall] - exact congrArg (fun b => EvalResult.ok (Value.bool b)) hEq - · exact evalExpr_getTick_tickLowVar_afterSqrtRatioAtTickHiCall (v := v) evm I - · have hEqFalse : - (getTickSourceTickLowValue I == getTickSourceTickHiValue I) = false := by - cases h : (getTickSourceTickLowValue I == getTickSourceTickHiValue I) <;> simp_all - rw [if_neg hEq] - apply evalExpr_ite_false - · rw [evalExpr_getTick_tickLowEqTickHi_afterSqrtRatioAtTickHiCall] - exact congrArg (fun b => EvalResult.ok (Value.bool b)) hEqFalse - · by_cases hLe : Int.ofNat (getTickHiSqrtRatioWord I).toNat ≤ - Int.ofNat (initializeArgWord I).toNat - · rw [if_pos hLe] - apply evalExpr_ite_true - · rw [evalExpr_getTick_sqrtRatioAtTickHiLeSqrtPrice_afterSqrtRatioAtTickHiCall] - · exact congrArg (fun b => EvalResult.ok (Value.bool b)) (decide_eq_true hLe) - · exact hsqrtPrice - · exact evalExpr_getTick_tickHiVar_afterSqrtRatioAtTickHiCall (v := v) evm I - · rw [if_neg hLe] - apply evalExpr_ite_false - · rw [evalExpr_getTick_sqrtRatioAtTickHiLeSqrtPrice_afterSqrtRatioAtTickHiCall] - · exact congrArg (fun b => EvalResult.ok (Value.bool b)) (decide_eq_false hLe) - · exact hsqrtPrice - · exact evalExpr_getTick_tickLowVar_afterSqrtRatioAtTickHiCall (v := v) evm I - -theorem evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall_of_eq - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterSqrtRatioAtTickHiCall I).get? "sqrtPriceX96" = - some (initializeArgValue I)) - (hvalue : getTickSourceFinalValue I = initializeTickValue I) : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm getTickSourceFinalReturnExpr = .ok (initializeTickValue I) := by - rw [← hvalue] - exact evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall evm I hsqrtPrice - -theorem evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall_of_logStep50_eq - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep50 I).get? "sqrtPriceX96" = some (initializeArgValue I)) - (hvalue : getTickSourceFinalValue I = initializeTickValue I) : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm getTickSourceFinalReturnExpr = .ok (initializeTickValue I) := by - exact evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall_of_eq evm I - (getTickStoreAfterSqrtRatioAtTickHiCall_sqrtPriceX96_of_logStep50 I hsqrtPrice) - hvalue - -theorem getTickSourceLogStepStoreAfter_preserve_ne (S : Store) (log2 : Int) (r bit : Nat) - {a : Ident} (hR : ("r" == a) = false) (hF : ("f" == a) = false) - (hLog2 : ("log_2" == a) = false) : - (getTickSourceLogStepStoreAfter S log2 r bit).get? a = S.get? a := by - rw [getTickSourceLogStepStoreAfter] - rw [store_get_ne (getTickSourceLogStepStoreAfterLog2 S log2 r bit) (k := "r") - (a := a) (getTickSourceLogStepRAfterValue r) hR] - rw [getTickSourceLogStepStoreAfterLog2] - rw [store_get_ne (getTickSourceLogStepStoreAfterFLet S r) (k := "log_2") - (a := a) (getTickSourceLogStepLog2AfterValue log2 r bit) hLog2] - rw [getTickSourceLogStepStoreAfterFLet] - rw [store_get_ne (getTickSourceLogStepStoreAfterRShifted S r) (k := "f") - (a := a) (getTickSourceLogStepFValue r) hF] - rw [getTickSourceLogStepStoreAfterRShifted] - rw [store_get_ne S (k := "r") (a := a) (getTickSourceLogStepRShiftedValue r) hR] - -theorem getTickStoreAfterLogStep_preserve_ne (S : Store) (log2 : Int) (r bit : Nat) - {a : Ident} (hR : ("r" == a) = false) (hF : ("f" == a) = false) - (hLog2 : ("log_2" == a) = false) : - (getTickStoreAfterLogStep S log2 r bit).get? a = S.get? a := by - simpa [getTickStoreAfterLogStep] using - getTickSourceLogStepStoreAfter_preserve_ne S log2 r bit hR hF hLog2 - -theorem getTickSourceLogStepStoreAfterLog2_preserve_ne - (S : Store) (log2 : Int) (r bit : Nat) {a : Ident} - (hR : ("r" == a) = false) (hF : ("f" == a) = false) - (hLog2 : ("log_2" == a) = false) : - (getTickSourceLogStepStoreAfterLog2 S log2 r bit).get? a = S.get? a := by - rw [getTickSourceLogStepStoreAfterLog2] - rw [store_get_ne (getTickSourceLogStepStoreAfterFLet S r) (k := "log_2") - (a := a) (getTickSourceLogStepLog2AfterValue log2 r bit) hLog2] - rw [getTickSourceLogStepStoreAfterFLet] - rw [store_get_ne (getTickSourceLogStepStoreAfterRShifted S r) (k := "f") - (a := a) (getTickSourceLogStepFValue r) hF] - rw [getTickSourceLogStepStoreAfterRShifted] - rw [store_get_ne S (k := "r") (a := a) (getTickSourceLogStepRShiftedValue r) hR] - -theorem getTickStoreWithMsb_sqrtPriceX96 (I : ExecutionEnv) : - (getTickStoreWithMsb I).get? "sqrtPriceX96" = some (initializeArgValue I) := by - rw [getTickStoreWithMsb] - rw [store_get_ne (getTickStoreWithR I) (k := "msb") (a := "sqrtPriceX96") - getTickSourceMsbValue (by decide)] - rw [getTickStoreWithR] - rw [store_get_ne (getTickStoreWithRatio I) (k := "r") (a := "sqrtPriceX96") - (getTickSourceRatioValue I) (by decide)] - rw [getTickStoreWithRatio] - rw [store_get_ne (initializeStore I) (k := "ratio") (a := "sqrtPriceX96") - (getTickSourceRatioValue I) (by decide)] - rw [initializeStore, store_get_self] - -theorem getTickStoreAfterMsbCombine_sqrtPriceX96 (I : ExecutionEnv) : - (getTickStoreAfterMsbCombine I).get? "sqrtPriceX96" = - some (initializeArgValue I) := by - rw [getTickStoreAfterMsbCombine] - rw [store_get_ne (getTickStoreAfterF0Let I) (k := "msb") (a := "sqrtPriceX96") - (getTickSourceMsbAfter0Value I) (by decide)] - rw [getTickStoreAfterF0Let] - rw [store_get_ne (getTickStoreAfterMsbStep1 I) (k := "f") (a := "sqrtPriceX96") - (getTickSourceMsbF0Value I) (by decide)] - rw [getTickStoreAfterMsbStep1] - rw [store_get_ne (getTickStoreAfterMsb1 I) (k := "r") (a := "sqrtPriceX96") - (getTickSourceRAfterMsb1Value I) (by decide)] - rw [getTickStoreAfterMsb1] - rw [store_get_ne (getTickStoreAfterF1Let I) (k := "msb") (a := "sqrtPriceX96") - (getTickSourceMsbAfter1Value I) (by decide)] - rw [getTickStoreAfterF1Let] - rw [store_get_ne (getTickStoreAfterMsbStep2 I) (k := "f") (a := "sqrtPriceX96") - (getTickSourceMsbF1Value I) (by decide)] - rw [getTickStoreAfterMsbStep2] - rw [store_get_ne (getTickStoreAfterMsb2 I) (k := "r") (a := "sqrtPriceX96") - (getTickSourceRAfterMsb2Value I) (by decide)] - rw [getTickStoreAfterMsb2] - rw [store_get_ne (getTickStoreAfterF2Let I) (k := "msb") (a := "sqrtPriceX96") - (getTickSourceMsbAfter2Value I) (by decide)] - rw [getTickStoreAfterF2Let] - rw [store_get_ne (getTickStoreAfterMsbStep3 I) (k := "f") (a := "sqrtPriceX96") - (getTickSourceMsbF2Value I) (by decide)] - rw [getTickStoreAfterMsbStep3] - rw [store_get_ne (getTickStoreAfterMsb3 I) (k := "r") (a := "sqrtPriceX96") - (getTickSourceRAfterMsb3Value I) (by decide)] - rw [getTickStoreAfterMsb3] - rw [store_get_ne (getTickStoreAfterF3Let I) (k := "msb") (a := "sqrtPriceX96") - (getTickSourceMsbAfter3Value I) (by decide)] - rw [getTickStoreAfterF3Let] - rw [store_get_ne (getTickStoreAfterMsbStep4 I) (k := "f") (a := "sqrtPriceX96") - (getTickSourceMsbF3Value I) (by decide)] - rw [getTickStoreAfterMsbStep4] - rw [store_get_ne (getTickStoreAfterMsb4 I) (k := "r") (a := "sqrtPriceX96") - (getTickSourceRAfterMsb4Value I) (by decide)] - rw [getTickStoreAfterMsb4] - rw [store_get_ne (getTickStoreAfterF4Let I) (k := "msb") (a := "sqrtPriceX96") - (getTickSourceMsbAfter4Value I) (by decide)] - rw [getTickStoreAfterF4Let] - rw [store_get_ne (getTickStoreAfterMsbStep5 I) (k := "f") (a := "sqrtPriceX96") - (getTickSourceMsbF4Value I) (by decide)] - rw [getTickStoreAfterMsbStep5] - rw [store_get_ne (getTickStoreAfterMsb5 I) (k := "r") (a := "sqrtPriceX96") - (getTickSourceRAfterMsb5Value I) (by decide)] - rw [getTickStoreAfterMsb5] - rw [store_get_ne (getTickStoreAfterF5Let I) (k := "msb") (a := "sqrtPriceX96") - (getTickSourceMsbAfter5Value I) (by decide)] - rw [getTickStoreAfterF5Let] - rw [store_get_ne (getTickStoreAfterMsbStep6 I) (k := "f") (a := "sqrtPriceX96") - (getTickSourceMsbF5Value I) (by decide)] - rw [getTickStoreAfterMsbStep6] - rw [store_get_ne (getTickStoreAfterMsb6 I) (k := "r") (a := "sqrtPriceX96") - (getTickSourceRAfterMsb6Value I) (by decide)] - rw [getTickStoreAfterMsb6] - rw [store_get_ne (getTickStoreAfterF6Let I) (k := "msb") (a := "sqrtPriceX96") - (getTickSourceMsbAfter6Value I) (by decide)] - rw [getTickStoreAfterF6Let] - rw [store_get_ne (getTickStoreAfterMsbStep7 I) (k := "f") (a := "sqrtPriceX96") - (getTickSourceMsbF6Value I) (by decide)] - rw [getTickStoreAfterMsbStep7] - rw [store_get_ne (getTickStoreAfterMsb7 I) (k := "r") (a := "sqrtPriceX96") - (getTickSourceRAfterMsb7Value I) (by decide)] - rw [getTickStoreAfterMsb7] - rw [store_get_ne (getTickStoreAfterF7Let I) (k := "msb") (a := "sqrtPriceX96") - (getTickSourceMsbAfter7Value I) (by decide)] - rw [getTickStoreAfterF7Let] - rw [store_get_ne (getTickStoreWithMsb I) (k := "f") (a := "sqrtPriceX96") - (getTickSourceMsbF7Value I) (by decide)] - exact getTickStoreWithMsb_sqrtPriceX96 I - -theorem getTickStoreAfterNormalizeR_sqrtPriceX96 (I : ExecutionEnv) : - (getTickStoreAfterNormalizeR I).get? "sqrtPriceX96" = - some (initializeArgValue I) := by - rw [getTickStoreAfterNormalizeR] - rw [store_get_ne (getTickStoreAfterMsbCombine I) (k := "r") (a := "sqrtPriceX96") - (getTickSourceRNormalizedValue I) (by decide)] - exact getTickStoreAfterMsbCombine_sqrtPriceX96 I - -theorem getTickStoreAfterLog2BaseLet_sqrtPriceX96 (I : ExecutionEnv) : - (getTickStoreAfterLog2BaseLet I).get? "sqrtPriceX96" = - some (initializeArgValue I) := by - rw [getTickStoreAfterLog2BaseLet] - rw [store_get_ne (getTickStoreAfterNormalizeR I) (k := "log_2") (a := "sqrtPriceX96") - (getTickSourceLog2BaseValue I) (by decide)] - exact getTickStoreAfterNormalizeR_sqrtPriceX96 I - -theorem getTickStoreAfterLogStep63_sqrtPriceX96 (I : ExecutionEnv) : - (getTickStoreAfterLogStep63 I).get? "sqrtPriceX96" = - some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep63] - rw [store_get_ne (getTickStoreAfterLog2Step63 I) (k := "r") (a := "sqrtPriceX96") - (getTickSourceLogRAfter63Value I) (by decide)] - rw [getTickStoreAfterLog2Step63] - rw [store_get_ne (getTickStoreAfterLogF63Let I) (k := "log_2") (a := "sqrtPriceX96") - (getTickSourceLog2After63Value I) (by decide)] - rw [getTickStoreAfterLogF63Let] - rw [store_get_ne (getTickStoreAfterLogRShifted63 I) (k := "f") (a := "sqrtPriceX96") - (getTickSourceLogF63Value I) (by decide)] - rw [getTickStoreAfterLogRShifted63] - rw [store_get_ne (getTickStoreAfterLog2BaseLet I) (k := "r") (a := "sqrtPriceX96") - (getTickSourceLogRShifted63Value I) (by decide)] - exact getTickStoreAfterLog2BaseLet_sqrtPriceX96 I - -theorem getTickStoreAfterLogStep62_sqrtPriceX96 (I : ExecutionEnv) : - (getTickStoreAfterLogStep62 I).get? "sqrtPriceX96" = - some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep62] - rw [store_get_ne (getTickStoreAfterLog2Step62 I) (k := "r") (a := "sqrtPriceX96") - (getTickSourceLogRAfter62Value I) (by decide)] - rw [getTickStoreAfterLog2Step62] - rw [store_get_ne (getTickStoreAfterLogF62Let I) (k := "log_2") (a := "sqrtPriceX96") - (getTickSourceLog2After62Value I) (by decide)] - rw [getTickStoreAfterLogF62Let] - rw [store_get_ne (getTickStoreAfterLogRShifted62 I) (k := "f") (a := "sqrtPriceX96") - (getTickSourceLogF62Value I) (by decide)] - rw [getTickStoreAfterLogRShifted62] - rw [store_get_ne (getTickStoreAfterLogStep63 I) (k := "r") (a := "sqrtPriceX96") - (getTickSourceLogRShifted62Value I) (by decide)] - exact getTickStoreAfterLogStep63_sqrtPriceX96 I - -theorem getTickStoreAfterLogStep61_sqrtPriceX96 (I : ExecutionEnv) : - (getTickStoreAfterLogStep61 I).get? "sqrtPriceX96" = - some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep61] - rw [getTickSourceLogStepStoreAfter_preserve_ne] - exact getTickStoreAfterLogStep62_sqrtPriceX96 I - all_goals decide - -theorem getTickStoreAfterLogStep60_sqrtPriceX96 (I : ExecutionEnv) : - (getTickStoreAfterLogStep60 I).get? "sqrtPriceX96" = - some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep60] - rw [getTickSourceLogStepStoreAfter_preserve_ne] - exact getTickStoreAfterLogStep61_sqrtPriceX96 I - all_goals decide - -theorem getTickStoreAfterLogStep59_sqrtPriceX96_of_logStep60 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep60 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterLogStep59 I).get? "sqrtPriceX96" = some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep59] - rw [getTickStoreAfterLogStep_preserve_ne] - exact hsqrtPrice - all_goals decide - -theorem getTickStoreAfterLogStep58_sqrtPriceX96_of_logStep60 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep60 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterLogStep58 I).get? "sqrtPriceX96" = some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep58] - rw [getTickStoreAfterLogStep_preserve_ne] - exact getTickStoreAfterLogStep59_sqrtPriceX96_of_logStep60 I hsqrtPrice - all_goals decide - -theorem getTickStoreAfterLogStep57_sqrtPriceX96_of_logStep60 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep60 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterLogStep57 I).get? "sqrtPriceX96" = some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep57] - rw [getTickStoreAfterLogStep_preserve_ne] - exact getTickStoreAfterLogStep58_sqrtPriceX96_of_logStep60 I hsqrtPrice - all_goals decide - -theorem getTickStoreAfterLogStep56_sqrtPriceX96_of_logStep60 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep60 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterLogStep56 I).get? "sqrtPriceX96" = some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep56] - rw [getTickStoreAfterLogStep_preserve_ne] - exact getTickStoreAfterLogStep57_sqrtPriceX96_of_logStep60 I hsqrtPrice - all_goals decide - -theorem getTickStoreAfterLogStep55_sqrtPriceX96_of_logStep60 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep60 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterLogStep55 I).get? "sqrtPriceX96" = some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep55] - rw [getTickStoreAfterLogStep_preserve_ne] - exact getTickStoreAfterLogStep56_sqrtPriceX96_of_logStep60 I hsqrtPrice - all_goals decide - -theorem getTickStoreAfterLogStep54_sqrtPriceX96_of_logStep60 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep60 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterLogStep54 I).get? "sqrtPriceX96" = some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep54] - rw [getTickStoreAfterLogStep_preserve_ne] - exact getTickStoreAfterLogStep55_sqrtPriceX96_of_logStep60 I hsqrtPrice - all_goals decide - -theorem getTickStoreAfterLogStep53_sqrtPriceX96_of_logStep60 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep60 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterLogStep53 I).get? "sqrtPriceX96" = some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep53] - rw [getTickStoreAfterLogStep_preserve_ne] - exact getTickStoreAfterLogStep54_sqrtPriceX96_of_logStep60 I hsqrtPrice - all_goals decide - -theorem getTickStoreAfterLogStep52_sqrtPriceX96_of_logStep60 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep60 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterLogStep52 I).get? "sqrtPriceX96" = some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep52] - rw [getTickStoreAfterLogStep_preserve_ne] - exact getTickStoreAfterLogStep53_sqrtPriceX96_of_logStep60 I hsqrtPrice - all_goals decide - -theorem getTickStoreAfterLogStep51_sqrtPriceX96_of_logStep60 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep60 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterLogStep51 I).get? "sqrtPriceX96" = some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep51] - rw [getTickStoreAfterLogStep_preserve_ne] - exact getTickStoreAfterLogStep52_sqrtPriceX96_of_logStep60 I hsqrtPrice - all_goals decide - -theorem getTickStoreAfterLogStep50_sqrtPriceX96_of_logStep60 - (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep60 I).get? "sqrtPriceX96" = some (initializeArgValue I)) : - (getTickStoreAfterLogStep50 I).get? "sqrtPriceX96" = some (initializeArgValue I) := by - rw [getTickStoreAfterLogStep50] - rw [getTickSourceLogStepStoreAfterLog2_preserve_ne] - exact getTickStoreAfterLogStep51_sqrtPriceX96_of_logStep60 I hsqrtPrice - all_goals decide - -theorem evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall_of_logStep60_eq - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hsqrtPrice : - (getTickStoreAfterLogStep60 I).get? "sqrtPriceX96" = some (initializeArgValue I)) - (hvalue : getTickSourceFinalValue I = initializeTickValue I) : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm getTickSourceFinalReturnExpr = .ok (initializeTickValue I) := by - exact evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall_of_logStep50_eq evm I - (getTickStoreAfterLogStep50_sqrtPriceX96_of_logStep60 I hsqrtPrice) - hvalue - -theorem evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall_of_finalValue_eq - {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hvalue : getTickSourceFinalValue I = initializeTickValue I) : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm getTickSourceFinalReturnExpr = .ok (initializeTickValue I) := by - exact evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall_of_logStep60_eq evm I - (getTickStoreAfterLogStep60_sqrtPriceX96 I) hvalue - -theorem evalExpr_getTick_log2Var_afterLogStep50 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogStep50 I } - evm (.var "log_2") = .ok (Value.int (getTickSourceLog2After50Int I)) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogStep50_log2] - -theorem evalExpr_getTick_log_sqrt10001 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogStep50 I } - evm (mulE (.var "log_2") (.intLit 255738958999603826347141)) = - .ok (getTickSourceLogSqrt10001Value I) := by - unfold mulE getTickSourceLogSqrt10001Value getTickSourceLogSqrt10001Int - getTickSourceLogSqrt10001MultiplierInt - simp only [evalExpr?, evalExpr_getTick_log2Var_afterLogStep50, EvalResult.bind, bind, - pure, evalBinaryOp?] - -theorem evalExpr_getTick_logSqrtVar_afterLogSqrt {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogSqrt10001 I } - evm (.var "log_sqrt10001") = .ok (getTickSourceLogSqrt10001Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterLogSqrt10001_log] - -theorem evalExpr_getTick_tickLowNumerator {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogSqrt10001 I } - evm (subE (.var "log_sqrt10001") (.intLit 3402992956809132418596140100660247210)) = - .ok (.int (getTickSourceLogSqrt10001Int I - getTickSourceTickLowOffsetInt)) := by - unfold subE getTickSourceTickLowOffsetInt - simp only [evalExpr?, evalExpr_getTick_logSqrtVar_afterLogSqrt, EvalResult.bind, bind, - pure, evalBinaryOp?, getTickSourceLogSqrt10001Value] - -theorem evalExpr_getTick_tickLow {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterLogSqrt10001 I } - evm (divE - (subE (.var "log_sqrt10001") (.intLit 3402992956809132418596140100660247210)) - fixedPoint128Q128) = - .ok (getTickSourceTickLowValue I) := by - unfold divE fixedPoint128Q128 getTickSourceTickLowValue getTickSourceTickLowInt - getTickSourceFixedPoint128Int - simp only [evalExpr?, evalExpr_getTick_tickLowNumerator, EvalResult.bind, bind, pure, - evalBinaryOp?] - norm_num - -theorem evalExpr_getTick_logSqrtVar_afterTickLow {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterTickLowLet I } - evm (.var "log_sqrt10001") = .ok (getTickSourceLogSqrt10001Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterTickLowLet_log] - -theorem evalExpr_getTick_tickHiNumerator {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterTickLowLet I } - evm (addE (.var "log_sqrt10001") (.intLit 291339464771989622907027621153398088495)) = - .ok (.int (getTickSourceLogSqrt10001Int I + getTickSourceTickHiOffsetInt)) := by - unfold addE getTickSourceTickHiOffsetInt - simp only [evalExpr?, evalExpr_getTick_logSqrtVar_afterTickLow, EvalResult.bind, bind, - pure, evalBinaryOp?, getTickSourceLogSqrt10001Value] - -theorem evalExpr_getTick_tickHi {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterTickLowLet I } - evm (divE - (addE (.var "log_sqrt10001") (.intLit 291339464771989622907027621153398088495)) - fixedPoint128Q128) = - .ok (getTickSourceTickHiValue I) := by - unfold divE fixedPoint128Q128 getTickSourceTickHiValue getTickSourceTickHiInt - getTickSourceFixedPoint128Int - simp only [evalExpr?, evalExpr_getTick_tickHiNumerator, EvalResult.bind, bind, pure, - evalBinaryOp?] - norm_num - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogSqrt10001Let {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep50 I } - evm - [ .letDecl "log_sqrt10001" (some int256) - (mulE (.var "log_2") (.intLit 255738958999603826347141)) ] - (.ok { contract := contract v, locals := getTickStoreAfterLogSqrt10001 I } evm) := by - exact ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_log_sqrt10001 evm I)) - ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceTickLowHiLets {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogSqrt10001 I } - evm - [ .letDecl "tickLow" (some int24) - (divE - (subE (.var "log_sqrt10001") (.intLit 3402992956809132418596140100660247210)) - fixedPoint128Q128), - .letDecl "tickHi" (some int24) - (divE - (addE (.var "log_sqrt10001") (.intLit 291339464771989622907027621153398088495)) - fixedPoint128Q128) ] - (.ok { contract := contract v, locals := getTickStoreAfterTickHiLet I } evm) := by - refine ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_tickLow evm I)) ?_ - exact ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_tickHi evm I)) ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogSteps59To50AndLogSqrt {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep60 I } evm - (((logStep 59 true ++ - (logStep 58 true ++ - (logStep 57 true ++ - (logStep 56 true ++ - (logStep 55 true ++ - (logStep 54 true ++ - (logStep 53 true ++ - (logStep 52 true ++ - logStep 51 true)))))))) ++ - logStep 50 false) ++ - [ .letDecl "log_sqrt10001" (some int256) - (mulE (.var "log_2") (.intLit 255738958999603826347141)) ]) - (.ok { contract := contract v, locals := getTickStoreAfterLogSqrt10001 I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceLogSteps59To50 evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceLogSqrt10001Let evm I) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStepsAndTickLowHi {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep60 I } evm - ((((logStep 59 true ++ - (logStep 58 true ++ - (logStep 57 true ++ - (logStep 56 true ++ - (logStep 55 true ++ - (logStep 54 true ++ - (logStep 53 true ++ - (logStep 52 true ++ - logStep 51 true)))))))) ++ - logStep 50 false) ++ - [ .letDecl "log_sqrt10001" (some int256) - (mulE (.var "log_2") (.intLit 255738958999603826347141)) ]) ++ - [ .letDecl "tickLow" (some int24) - (divE - (subE (.var "log_sqrt10001") (.intLit 3402992956809132418596140100660247210)) - fixedPoint128Q128), - .letDecl "tickHi" (some int24) - (divE - (addE (.var "log_sqrt10001") (.intLit 291339464771989622907027621153398088495)) - fixedPoint128Q128) ]) - (.ok { contract := contract v, locals := getTickStoreAfterTickHiLet I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceLogSteps59To50AndLogSqrt evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceTickLowHiLets evm I) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceSqrtRatioAtTickHiCall - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} {calleeSolm : Frame} - (hbody : - ExecFuncBody (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - evm getSqrtRatioAtTickFunction.body - (.returned calleeSolm evm (some [getTickSourceSqrtRatioAtTickHiValue I]))) : - ExecStmt (config v) { contract := contract v, locals := getTickStoreAfterTickHiLet I } - evm (.internalCall "getSqrtRatioAtTick" [.var "tickHi"] "sqrtRatioAtTickHi") - (.ok { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm) := by - have hstmt := internalCallFunctionReturn - (cfg := config v) - (caller := { contract := contract v, locals := getTickStoreAfterTickHiLet I }) - (evm := evm) (calleeEvm := evm) - (name := "getSqrtRatioAtTick") (retVar := "sqrtRatioAtTickHi") - (args := [.var "tickHi"]) (argVals := [getTickSourceTickHiValue I]) - (callee := getSqrtRatioAtTickFunction) - (locals := getTickStoreForSqrtRatioAtTickHiCall I) - (calleeSolm := calleeSolm) (value := some [getTickSourceSqrtRatioAtTickHiValue I]) - (evalExprs_getTick_tickHiArg_afterTickHi evm I) - (by - simp [lookupCallable?, lookupFunction?, contract, functions, getSqrtRatioAtTickFunction]) - (by rfl) - hbody - simpa [getTickStoreAfterSqrtRatioAtTickHiCall, resumeAfterInternalCall, collapseReturns] - using hstmt - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceSqrtRatioAtTickHiAndReturn - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} {calleeSolm : Frame} - (hbody : - ExecFuncBody (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - evm getSqrtRatioAtTickFunction.body - (.returned calleeSolm evm (some [getTickSourceSqrtRatioAtTickHiValue I]))) - (hret : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm getTickSourceFinalReturnExpr = .ok (initializeTickValue I)) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterTickHiLet I } evm - [ .internalCall "getSqrtRatioAtTick" [.var "tickHi"] "sqrtRatioAtTickHi", - .return [getTickSourceFinalReturnExpr] ] - (.returned { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (some [initializeTickValue I])) := by - refine ExecBlock.consNormal - (uniswapV3PoolGetTickAtSqrtRatioSourceSqrtRatioAtTickHiCall - (v := v) (evm := evm) (I := I) hbody) ?_ - exact ExecBlock.consReturn (ExecStmt.return (evalExprs?_singleton hret)) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceSqrtRatioAtTickHiAndReturnOfFinalValue - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} {calleeSolm : Frame} - (hbody : - ExecFuncBody (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - evm getSqrtRatioAtTickFunction.body - (.returned calleeSolm evm (some [getTickSourceSqrtRatioAtTickHiValue I]))) - (hsqrtPrice : - (getTickStoreAfterSqrtRatioAtTickHiCall I).get? "sqrtPriceX96" = - some (initializeArgValue I)) - (hvalue : getTickSourceFinalValue I = initializeTickValue I) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterTickHiLet I } evm - [ .internalCall "getSqrtRatioAtTick" [.var "tickHi"] "sqrtRatioAtTickHi", - .return [getTickSourceFinalReturnExpr] ] - (.returned { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (some [initializeTickValue I])) := by - exact uniswapV3PoolGetTickAtSqrtRatioSourceSqrtRatioAtTickHiAndReturn hbody - (evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall_of_eq evm I hsqrtPrice hvalue) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceSqrtRatioAtTickHiAndReturnOfLogStep50FinalValue - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} {calleeSolm : Frame} - (hbody : - ExecFuncBody (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - evm getSqrtRatioAtTickFunction.body - (.returned calleeSolm evm (some [getTickSourceSqrtRatioAtTickHiValue I]))) - (hsqrtPrice : - (getTickStoreAfterLogStep50 I).get? "sqrtPriceX96" = some (initializeArgValue I)) - (hvalue : getTickSourceFinalValue I = initializeTickValue I) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterTickHiLet I } evm - [ .internalCall "getSqrtRatioAtTick" [.var "tickHi"] "sqrtRatioAtTickHi", - .return [getTickSourceFinalReturnExpr] ] - (.returned { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (some [initializeTickValue I])) := by - exact uniswapV3PoolGetTickAtSqrtRatioSourceSqrtRatioAtTickHiAndReturn hbody - (evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall_of_logStep50_eq evm I - hsqrtPrice hvalue) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceSqrtRatioAtTickHiAndReturnOfFinalValueEq - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} {calleeSolm : Frame} - (hbody : - ExecFuncBody (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - evm getSqrtRatioAtTickFunction.body - (.returned calleeSolm evm (some [getTickSourceSqrtRatioAtTickHiValue I]))) - (hvalue : getTickSourceFinalValue I = initializeTickValue I) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterTickHiLet I } evm - [ .internalCall "getSqrtRatioAtTick" [.var "tickHi"] "sqrtRatioAtTickHi", - .return [getTickSourceFinalReturnExpr] ] - (.returned { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (some [initializeTickValue I])) := by - exact uniswapV3PoolGetTickAtSqrtRatioSourceSqrtRatioAtTickHiAndReturn hbody - (evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall_of_finalValue_eq evm I hvalue) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStepsTickLowHiAndReturn - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} {calleeSolm : Frame} - (hbody : - ExecFuncBody (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - evm getSqrtRatioAtTickFunction.body - (.returned calleeSolm evm (some [getTickSourceSqrtRatioAtTickHiValue I]))) - (hret : - evalExpr? (config v) - { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm getTickSourceFinalReturnExpr = .ok (initializeTickValue I)) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep60 I } evm - (((((logStep 59 true ++ - (logStep 58 true ++ - (logStep 57 true ++ - (logStep 56 true ++ - (logStep 55 true ++ - (logStep 54 true ++ - (logStep 53 true ++ - (logStep 52 true ++ - logStep 51 true)))))))) ++ - logStep 50 false) ++ - [ .letDecl "log_sqrt10001" (some int256) - (mulE (.var "log_2") (.intLit 255738958999603826347141)) ]) ++ - [ .letDecl "tickLow" (some int24) - (divE - (subE (.var "log_sqrt10001") (.intLit 3402992956809132418596140100660247210)) - fixedPoint128Q128), - .letDecl "tickHi" (some int24) - (divE - (addE (.var "log_sqrt10001") (.intLit 291339464771989622907027621153398088495)) - fixedPoint128Q128) ]) ++ - [ .internalCall "getSqrtRatioAtTick" [.var "tickHi"] "sqrtRatioAtTickHi", - .return [getTickSourceFinalReturnExpr] ]) - (.returned { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (some [initializeTickValue I])) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceLogStepsAndTickLowHi evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceSqrtRatioAtTickHiAndReturn hbody hret) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStepsTickLowHiAndReturnOfFinalValue - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} {calleeSolm : Frame} - (hbody : - ExecFuncBody (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - evm getSqrtRatioAtTickFunction.body - (.returned calleeSolm evm (some [getTickSourceSqrtRatioAtTickHiValue I]))) - (hsqrtPrice : - (getTickStoreAfterSqrtRatioAtTickHiCall I).get? "sqrtPriceX96" = - some (initializeArgValue I)) - (hvalue : getTickSourceFinalValue I = initializeTickValue I) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep60 I } evm - (((((logStep 59 true ++ - (logStep 58 true ++ - (logStep 57 true ++ - (logStep 56 true ++ - (logStep 55 true ++ - (logStep 54 true ++ - (logStep 53 true ++ - (logStep 52 true ++ - logStep 51 true)))))))) ++ - logStep 50 false) ++ - [ .letDecl "log_sqrt10001" (some int256) - (mulE (.var "log_2") (.intLit 255738958999603826347141)) ]) ++ - [ .letDecl "tickLow" (some int24) - (divE - (subE (.var "log_sqrt10001") (.intLit 3402992956809132418596140100660247210)) - fixedPoint128Q128), - .letDecl "tickHi" (some int24) - (divE - (addE (.var "log_sqrt10001") (.intLit 291339464771989622907027621153398088495)) - fixedPoint128Q128) ]) ++ - [ .internalCall "getSqrtRatioAtTick" [.var "tickHi"] "sqrtRatioAtTickHi", - .return [getTickSourceFinalReturnExpr] ]) - (.returned { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (some [initializeTickValue I])) := by - exact uniswapV3PoolGetTickAtSqrtRatioSourceLogStepsTickLowHiAndReturn hbody - (evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall_of_eq evm I hsqrtPrice hvalue) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStepsTickLowHiAndReturnOfLogStep50FinalValue - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} {calleeSolm : Frame} - (hbody : - ExecFuncBody (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - evm getSqrtRatioAtTickFunction.body - (.returned calleeSolm evm (some [getTickSourceSqrtRatioAtTickHiValue I]))) - (hsqrtPrice : - (getTickStoreAfterLogStep50 I).get? "sqrtPriceX96" = some (initializeArgValue I)) - (hvalue : getTickSourceFinalValue I = initializeTickValue I) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep60 I } evm - (((((logStep 59 true ++ - (logStep 58 true ++ - (logStep 57 true ++ - (logStep 56 true ++ - (logStep 55 true ++ - (logStep 54 true ++ - (logStep 53 true ++ - (logStep 52 true ++ - logStep 51 true)))))))) ++ - logStep 50 false) ++ - [ .letDecl "log_sqrt10001" (some int256) - (mulE (.var "log_2") (.intLit 255738958999603826347141)) ]) ++ - [ .letDecl "tickLow" (some int24) - (divE - (subE (.var "log_sqrt10001") (.intLit 3402992956809132418596140100660247210)) - fixedPoint128Q128), - .letDecl "tickHi" (some int24) - (divE - (addE (.var "log_sqrt10001") (.intLit 291339464771989622907027621153398088495)) - fixedPoint128Q128) ]) ++ - [ .internalCall "getSqrtRatioAtTick" [.var "tickHi"] "sqrtRatioAtTickHi", - .return [getTickSourceFinalReturnExpr] ]) - (.returned { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (some [initializeTickValue I])) := by - exact uniswapV3PoolGetTickAtSqrtRatioSourceLogStepsTickLowHiAndReturn hbody - (evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall_of_logStep50_eq evm I - hsqrtPrice hvalue) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceLogStepsTickLowHiAndReturnOfFinalValueEq - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} {calleeSolm : Frame} - (hbody : - ExecFuncBody (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - evm getSqrtRatioAtTickFunction.body - (.returned calleeSolm evm (some [getTickSourceSqrtRatioAtTickHiValue I]))) - (hvalue : getTickSourceFinalValue I = initializeTickValue I) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterLogStep60 I } evm - (((((logStep 59 true ++ - (logStep 58 true ++ - (logStep 57 true ++ - (logStep 56 true ++ - (logStep 55 true ++ - (logStep 54 true ++ - (logStep 53 true ++ - (logStep 52 true ++ - logStep 51 true)))))))) ++ - logStep 50 false) ++ - [ .letDecl "log_sqrt10001" (some int256) - (mulE (.var "log_2") (.intLit 255738958999603826347141)) ]) ++ - [ .letDecl "tickLow" (some int24) - (divE - (subE (.var "log_sqrt10001") (.intLit 3402992956809132418596140100660247210)) - fixedPoint128Q128), - .letDecl "tickHi" (some int24) - (divE - (addE (.var "log_sqrt10001") (.intLit 291339464771989622907027621153398088495)) - fixedPoint128Q128) ]) ++ - [ .internalCall "getSqrtRatioAtTick" [.var "tickHi"] "sqrtRatioAtTickHi", - .return [getTickSourceFinalReturnExpr] ]) - (.returned { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (some [initializeTickValue I])) := by - exact uniswapV3PoolGetTickAtSqrtRatioSourceLogStepsTickLowHiAndReturn hbody - (evalExpr_getTick_finalReturn_afterSqrtRatioAtTickHiCall_of_finalValue_eq evm I hvalue) - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceSuccessOfSqrtRatioAtTickHi - {v : PoolImmutables} {evm : EVM.State} {I : ExecutionEnv} - {calleeSolm : Frame} - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) - (hbody : - ExecFuncBody (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - evm getSqrtRatioAtTickFunction.body - (.returned calleeSolm evm (some [getTickSourceSqrtRatioAtTickHiValue I]))) - (hvalue : getTickSourceFinalValue I = initializeTickValue I) : - ExecFuncBody (config v) { contract := contract v, locals := initializeStore I } - evm getTickAtSqrtRatioFunction.body - (.returned { contract := contract v, locals := getTickStoreAfterSqrtRatioAtTickHiCall I } - evm (some [initializeTickValue I])) := by - refine ExecFuncBody.execBlockRet ?_ - have hprefix := uniswapV3PoolGetTickAtSqrtRatioSourcePrefix (v := v) evm I hlo hhi - have hthrough60 := uniswapV3PoolGetTickAtSqrtRatioSourceThroughLogStep60 (v := v) evm I - have htail := - uniswapV3PoolGetTickAtSqrtRatioSourceLogStepsTickLowHiAndReturnOfFinalValueEq - (v := v) (evm := evm) (I := I) hbody hvalue - simpa [getTickAtSqrtRatioFunction] using execBlock_append hprefix - (execBlock_append hthrough60 htail) - -theorem uniswapV3PoolInitializeSourceSuccessBodyOfSqrtRatioAtTickHi - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} {calleeSolm : Frame} - (hwv : I.weiValue = ⟨0⟩) - (hzero : slot0SqrtPriceX96Word σ I = ⟨0⟩) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) - (hbody : - ExecFuncBody (config v) - { contract := contract v, locals := getTickStoreForSqrtRatioAtTickHiCall I } - (initState cA gh bl σ σ₀ g A I) getSqrtRatioAtTickFunction.body - (.returned calleeSolm (initState cA gh bl σ σ₀ g A I) - (some [getTickSourceSqrtRatioAtTickHiValue I]))) - (hvalue : getTickSourceFinalValue I = initializeTickValue I) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (initializeStore I) - initializeTransition.body - (.returned { contract := contract v, locals := initializeStoreWithTickAndTime I } - (initializeSourceAfterStorageTailState (initState cA gh bl σ σ₀ g A I) I) - none) := by - exact uniswapV3PoolInitializeSourceSuccessBodyOfGetTickFunc (v := v) hwv hzero - (uniswapV3PoolGetTickAtSqrtRatioSourceSuccessOfSqrtRatioAtTickHi - (v := v) (evm := initState cA gh bl σ σ₀ g A I) (I := I) - hlo hhi hbody hvalue) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceStorageEquiv.lean b/Benchmarks/UniswapV3Pool/InitializeSourceStorageEquiv.lean deleted file mode 100644 index ad7e9226..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeSourceStorageEquiv.lean +++ /dev/null @@ -1,1939 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeSourceSuccess - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def initializeObservationInitializedTrueWord (evm : EVM.State) : UInt256 := - UInt256.ofNat - ((Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩).toNat % 2 ^ 248 + - 2 ^ 248) - -theorem initializeObservationInitializedTrueWord_nat_lt (evm : EVM.State) : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩).toNat % 2 ^ 248 + - 2 ^ 248 < - UInt256.size := by - have hmod : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩).toNat % 2 ^ 248 < - 2 ^ 248 := Nat.mod_lt _ (by norm_num) - norm_num [UInt256.size] at hmod ⊢ - omega - -theorem storageStore_find?_codeOwner_same (evm : EVM.State) (slot val : UInt256) - {acc : Account} - (hacc : evm.accountMap.find? evm.executionEnv.codeOwner = some acc) : - (Solm.EVM.storageStore evm evm.executionEnv.codeOwner slot val).accountMap.find? - evm.executionEnv.codeOwner = - some (Account.updateStorage acc slot val) := by - simp only [Solm.EVM.storageStore, State.lookupAccount, hacc, Option.option] - simp only [State.setAccount] - rw [accountMap_find_insert_self] - -theorem initializeObservationLow32_insert_toNat' (low old : UInt256) - (hlow : low.toNat < 2 ^ 32) : - (UInt256.lor low (UInt256.land (UInt256.lnot (⟨4294967295⟩ : UInt256)) old)).toNat = - low.toNat + old.toNat / 2 ^ 32 * 2 ^ 32 := by - rw [u256_lor_toNat] - have hclearMask : UInt256.lnot (⟨4294967295⟩ : UInt256) = - UInt256.ofNat ((2 : Nat) ^ 256 - 2 ^ 32) := by - native_decide - have hhigh : - (UInt256.land (UInt256.lnot (⟨4294967295⟩ : UInt256)) old).toNat = - old.toNat / 2 ^ 32 * 2 ^ 32 := by - rw [hclearMask] - exact u256_land_high_mask_toNat old 32 (by norm_num) - have hq : old.toNat / 2 ^ 32 < 2 ^ 224 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 32 * 2 ^ 224 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - simp [UInt256.size] - have hlorLt : - Nat.lor low.toNat - ((UInt256.land (UInt256.lnot (⟨4294967295⟩ : UInt256)) old).toNat) < - UInt256.size := by - rw [hhigh] - rw [nat_lor_shift_add low.toNat (old.toNat / 2 ^ 32) 32 hlow] - have hqle : old.toNat / 2 ^ 32 ≤ 2 ^ 224 - 1 := Nat.le_pred_of_lt hq - have hprod : (old.toNat / 2 ^ 32) * 2 ^ 32 ≤ (2 ^ 224 - 1) * 2 ^ 32 := by - exact Nat.mul_le_mul_right _ hqle - norm_num [UInt256.size, Nat.pow_add] at hprod ⊢ - omega - rw [Nat.mod_eq_of_lt hlorLt] - rw [hhigh] - exact nat_lor_shift_add low.toNat (old.toNat / 2 ^ 32) 32 hlow - -theorem initializeObservationTimestampSlotWord_mod32 (evm : EVM.State) (I : ExecutionEnv) : - (initializeObservationTimestampSlotWord evm I).toNat % 2 ^ 32 = - (initializeObservationTimestampWord I).toNat := by - unfold initializeObservationTimestampSlotWord - rw [initializeObservationLow32_insert_toNat'] - · rw [Nat.add_mul_mod_self_right] - exact Nat.mod_eq_of_lt (initializeObservationTimestampWord_lt_twoPow32 I) - · exact initializeObservationTimestampWord_lt_twoPow32 I - -theorem initializeObservationInitializedTrueWord_afterSeconds {cA gh bl σ_solm σ₀ A I} - {g : Sat256} {accS : Account} - (hfindS : σ_solm.find? I.codeOwner = some accS) : - let evm0 := initState cA gh bl σ_solm σ₀ g A I - let evm1 := initializeObservationAfterTimestampState evm0 I - let evm2 := initializeObservationAfterTickState evm1 - let evm3 := initializeObservationAfterSecondsState evm2 - initializeObservationInitializedTrueWord evm3 = - UInt256.lor (UInt256.shiftLeft ⟨1⟩ ⟨248⟩) (initializeObservationTimestampWord I) := by - intro evm0 evm1 evm2 evm3 - have hacc0 : evm0.accountMap.find? evm0.executionEnv.codeOwner = some accS := by - simpa [evm0, initState] using hfindS - have hload1 : - Solm.EVM.storageLoad evm1 evm1.executionEnv.codeOwner ⟨8⟩ = - initializeObservationTimestampSlotWord evm0 I := by - dsimp [evm1, initializeObservationAfterTimestampState] - rw [storageStore_executionEnv] - exact storageLoad_storageStore_same_present evm0 evm0.executionEnv.codeOwner hacc0 ⟨8⟩ - (initializeObservationTimestampSlotWord evm0 I) - have hacc1 : - evm1.accountMap.find? evm1.executionEnv.codeOwner = - some (Account.updateStorage accS ⟨8⟩ (initializeObservationTimestampSlotWord evm0 I)) := by - dsimp [evm1, initializeObservationAfterTimestampState] - simpa [storageStore_executionEnv] using - storageStore_find?_codeOwner_same evm0 ⟨8⟩ (initializeObservationTimestampSlotWord evm0 I) - hacc0 - have hload2 : - Solm.EVM.storageLoad evm2 evm2.executionEnv.codeOwner ⟨8⟩ = - initializeObservationAfterTickWord evm1 := by - dsimp [evm2, initializeObservationAfterTickState] - rw [storageStore_executionEnv] - exact storageLoad_storageStore_same_present evm1 evm1.executionEnv.codeOwner hacc1 ⟨8⟩ - (initializeObservationAfterTickWord evm1) - have hacc2 : - evm2.accountMap.find? evm2.executionEnv.codeOwner = - some (Account.updateStorage - (Account.updateStorage accS ⟨8⟩ (initializeObservationTimestampSlotWord evm0 I)) - ⟨8⟩ (initializeObservationAfterTickWord evm1)) := by - dsimp [evm2, initializeObservationAfterTickState] - simpa [storageStore_executionEnv] using - storageStore_find?_codeOwner_same evm1 ⟨8⟩ (initializeObservationAfterTickWord evm1) - hacc1 - have hload3 : - Solm.EVM.storageLoad evm3 evm3.executionEnv.codeOwner ⟨8⟩ = - initializeObservationAfterSecondsWord evm2 := by - dsimp [evm3, initializeObservationAfterSecondsState] - rw [storageStore_executionEnv] - exact storageLoad_storageStore_same_present evm2 evm2.executionEnv.codeOwner hacc2 ⟨8⟩ - (initializeObservationAfterSecondsWord evm2) - apply u256_inj - unfold initializeObservationInitializedTrueWord - rw [hload3] - rw [show (initializeObservationAfterSecondsWord evm2).toNat = - (initializeObservationAfterTickWord evm1).toNat % 2 ^ 88 + - (initializeObservationAfterTickWord evm1).toNat / 2 ^ 248 * 2 ^ 248 by - dsimp [initializeObservationAfterSecondsWord] - rw [hload2] - exact ulit_toNat' _ (by - simpa [hload2] using initializeObservationAfterSecondsWord_nat_lt evm2)] - rw [show (initializeObservationAfterTickWord evm1).toNat = - (initializeObservationTimestampSlotWord evm0 I).toNat % 2 ^ 32 + - (initializeObservationTimestampSlotWord evm0 I).toNat / 2 ^ 88 * 2 ^ 88 by - dsimp [initializeObservationAfterTickWord] - rw [hload1] - exact ulit_toNat' _ (by - simpa [hload1] using initializeObservationAfterTickWord_nat_lt evm1)] - rw [initializeObservationTimestampSlotWord_mod32] - rw [u256_lor_toNat] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨248⟩).toNat = 2 ^ 248 by - native_decide] - have ht := initializeObservationTimestampWord_lt_twoPow32 I - have htm : (initializeObservationTimestampWord I).toNat < 2 ^ 88 := by omega - have htm248 : (initializeObservationTimestampWord I).toNat < 2 ^ 248 := by omega - have hlor : - Nat.lor (2 ^ 248) (initializeObservationTimestampWord I).toNat = - (initializeObservationTimestampWord I).toNat + 2 ^ 248 := by - rw [nat_lor_comm] - rw [show 2 ^ (248 : Nat) = 1 * 2 ^ (248 : Nat) by ring] - rw [nat_lor_shift_add (initializeObservationTimestampWord I).toNat 1 248 htm248] - rw [hlor] - rw [ulit_toNat' _ (by - have hmod : - (((initializeObservationTimestampWord I).toNat + - (initializeObservationTimestampSlotWord evm0 I).toNat / 2 ^ 88 * 2 ^ 88) % - 2 ^ 88 + - ((initializeObservationTimestampWord I).toNat + - (initializeObservationTimestampSlotWord evm0 I).toNat / 2 ^ 88 * 2 ^ 88) / - 2 ^ 248 * - 2 ^ 248) % - 2 ^ 248 < - 2 ^ 248 := Nat.mod_lt _ (by norm_num) - norm_num [UInt256.size] at hmod ⊢ - omega)] - rw [Nat.add_mul_mod_self_right] - rw [Nat.mod_eq_of_lt (lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 88)) - (by norm_num : 2 ^ 88 < 2 ^ 248))] - rw [Nat.add_mul_mod_self_right] - rw [Nat.mod_eq_of_lt htm] - rw [Nat.mod_eq_of_lt (by - norm_num [UInt256.size] at ht ⊢ - omega)] - -theorem initializeObservationAfterInitializedState_accountMap - (evm : EVM.State) : - (initializeObservationAfterInitializedState evm).accountMap = - (Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨8⟩ - (initializeObservationInitializedTrueWord evm)).accountMap := by - unfold initializeObservationAfterInitializedState - simp [storageLocStore, storageLocWriteWord, initializeObservationInitializedTrueWord, - storageStore_accountMap] - apply congrArg - (fun w : UInt256 => sstoreAccountMap evm.executionEnv.codeOwner evm.accountMap ⟨8⟩ w) - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩ - show fromBytes' - (List.take 31 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - (List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1)) ++ - List.drop 32 ↑(EVM.Word.toBytesLEWithSizeProof w))) = - (UInt256.ofNat (w.toNat % 2 ^ 248 + 2 ^ 248)).toNat - rw [show List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1)) = - ([1] : List UInt8) by native_decide] - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - have hlen31 : - (List.take 31 (EVM.Word.toBytesLEWithSizeProof w).1).length = 31 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - rw [hlen31] - rw [show fromBytes' ([1] : List UInt8) = 1 by native_decide] - rw [show 256 ^ (31 : Nat) = 2 ^ (248 : Nat) by norm_num [Nat.pow_mul]] - rw [show 256 ^ (32 : Nat) = 2 ^ (256 : Nat) by norm_num [Nat.pow_mul]] - rw [show 2 ^ (8 * 31) = 2 ^ (248 : Nat) by norm_num] - have hdiv : w.toNat / 2 ^ 256 = 0 := Nat.div_eq_of_lt w.val.isLt - rw [hdiv] - norm_num - exact (ulit_toNat' _ (initializeObservationInitializedTrueWord_nat_lt evm)).symm - -theorem initializeObservationAfterAllState_accountMapEquiv {cA gh bl σ_evm σ_solm σ₀ A I} - {g : Sat256} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - accountMapEquiv - (sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ (initializeObservationSstoreWord σ_evm I)) - (initializeObservationAfterAllState (initState cA gh bl σ_solm σ₀ g A I) I).accountMap := by - by_cases hmissing : σ_evm.find? I.codeOwner = none - · have hmissingSolm := accountMapEquiv_find?_none hAccounts hmissing - unfold initializeObservationAfterAllState - rw [initializeObservationAfterInitializedState_accountMap] - intro addr - simp [Option.option, initializeObservationAfterSecondsState, - initializeObservationAfterTickState, initializeObservationAfterTimestampState, - Solm.EVM.storageStore, State.lookupAccount, sstoreAccountMap, initState, hmissing, - hmissingSolm] - exact hAccounts addr - · cases hfindE : σ_evm.find? I.codeOwner with - | none => exact False.elim (hmissing hfindE) - | some _accE => - obtain ⟨accS, hfindS⟩ := accountMapEquiv_find?_some_exists hAccounts hfindE - rw [initializeObservationSstoreWord_eq_timestamp] - unfold initializeObservationAfterAllState - rw [initializeObservationAfterInitializedState_accountMap] - rw [initializeObservationInitializedTrueWord_afterSeconds (hfindS := hfindS)] - simp only [initializeObservationAfterSecondsState, initializeObservationAfterTickState, - initializeObservationAfterTimestampState, storageStore_accountMap, storageStore_executionEnv, - initState] - let evm0 := initState cA gh bl σ_solm σ₀ g A I - let v1 := initializeObservationTimestampSlotWord evm0 I - let evm1 := Solm.EVM.storageStore evm0 I.codeOwner ⟨8⟩ v1 - let v2 := initializeObservationAfterTickWord evm1 - let evm2 := Solm.EVM.storageStore evm1 I.codeOwner ⟨8⟩ v2 - let v3 := initializeObservationAfterSecondsWord evm2 - let final := - UInt256.lor (UInt256.shiftLeft ⟨1⟩ ⟨248⟩) (initializeObservationTimestampWord I) - have hbase : accountMapEquiv - (sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ final) - (sstoreAccountMap I.codeOwner σ_solm ⟨8⟩ final) := by - exact accountMapEquiv_sstoreAccountMap I.codeOwner ⟨8⟩ final hAccounts - have h1 : accountMapEquiv - (sstoreAccountMap I.codeOwner σ_solm ⟨8⟩ final) - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner σ_solm ⟨8⟩ v1) ⟨8⟩ final) := by - exact accountMapEquiv_sstoreAccountMap_self_update σ_solm I.codeOwner ⟨8⟩ v1 final - have h2 : accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner σ_solm ⟨8⟩ v1) ⟨8⟩ final) - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner σ_solm ⟨8⟩ v1) ⟨8⟩ v2) ⟨8⟩ final) := by - exact accountMapEquiv_sstoreAccountMap_self_update - (sstoreAccountMap I.codeOwner σ_solm ⟨8⟩ v1) I.codeOwner ⟨8⟩ v2 final - have h3 : accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner σ_solm ⟨8⟩ v1) ⟨8⟩ v2) ⟨8⟩ final) - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner σ_solm ⟨8⟩ v1) ⟨8⟩ v2) ⟨8⟩ v3) - ⟨8⟩ final) := by - exact accountMapEquiv_sstoreAccountMap_self_update - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner σ_solm ⟨8⟩ v1) ⟨8⟩ v2) I.codeOwner ⟨8⟩ v3 final - exact hbase.trans (h1.trans (h2.trans h3)) - -theorem initializeSlot0SstoreWord_accountMapEquiv {σ τ : AccountMap} - {I : ExecutionEnv} {sqrt tick : UInt256} - (hAccounts : accountMapEquiv σ τ) : - initializeSlot0SstoreWord σ I sqrt tick = initializeSlot0SstoreWord τ I sqrt tick := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ (⟨0⟩ : UInt256) - simp [initializeSlot0SstoreWord, codeOwnerStorageWord, hslot] - -theorem initializeSetLow160Word_nat_lt (old val : UInt256) : - (UInt256.land val solcAddrMask).toNat + old.toNat / 2 ^ 160 * 2 ^ 160 < - UInt256.size := by - have hlow : (UInt256.land val solcAddrMask).toNat < 2 ^ 160 := by - simpa [EVM.addressModulus, EVM.twoPow] using solcAddrMask_result_canonical val - have hq : old.toNat / 2 ^ 160 < 2 ^ 96 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 160 * 2 ^ 96 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - exact old.val.isLt - have hlowLe : (UInt256.land val solcAddrMask).toNat ≤ 2 ^ 160 - 1 := - Nat.le_pred_of_lt hlow - have hqLe : old.toNat / 2 ^ 160 ≤ 2 ^ 96 - 1 := Nat.le_pred_of_lt hq - have hprod : old.toNat / 2 ^ 160 * 2 ^ 160 ≤ (2 ^ 96 - 1) * 2 ^ 160 := - Nat.mul_le_mul_right _ hqLe - have hmax : (2 ^ 160 - 1) + (2 ^ 96 - 1) * 2 ^ 160 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - -theorem initializeSetLow160Word_eq (old val : UInt256) : - UInt256.lor (UInt256.land val solcAddrMask) - (UInt256.land old (UInt256.lnot solcAddrMask)) = - UInt256.ofNat - ((UInt256.land val solcAddrMask).toNat + old.toNat / 2 ^ 160 * 2 ^ 160) := by - apply u256_inj - rw [u256_lor_toNat, addressOffset0High160Mask_toNat] - have hlow : (UInt256.land val solcAddrMask).toNat < 2 ^ 160 := by - simpa [EVM.addressModulus, EVM.twoPow] using solcAddrMask_result_canonical val - have hlt := initializeSetLow160Word_nat_lt old val - rw [nat_lor_shift_add (UInt256.land val solcAddrMask).toNat (old.toNat / 2 ^ 160) 160 - hlow] - rw [Nat.mod_eq_of_lt hlt] - rw [ulit_toNat' _ hlt] - -abbrev initializeSlot0SlotWithSqrt - (σ : AccountMap) (I : ExecutionEnv) (sqrt : UInt256) : UInt256 := - UInt256.lor - (initializeSlot0SqrtEventWord sqrt) - (UInt256.land (codeOwnerStorageWord I σ ⟨0⟩) (UInt256.lnot solcAddrMask)) - -theorem storageLocStore_initializeSlot0_sqrtPriceX96_packed - (evm : EVM.State) (I : ExecutionEnv) (hEnv : evm.executionEnv = I) : - storageLocStore evm initializeSlot0SqrtPriceX96Loc (initializeArgValue I) = - some (Solm.EVM.storageStore evm I.codeOwner ⟨0⟩ - (initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I))) := by - unfold storageLocStore storageLocWriteWord initializeSlot0SqrtPriceX96Loc loc - simp only [valueToWord, wordOfInt_ofNat_toNat, bind, Option.bind, pure] - rw [hEnv] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm I.codeOwner ⟨0⟩ - show fromBytes' - (List.take 0 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 20 ↑(EVM.Word.toBytesLEWithSizeProof (initializeArgWord I)) ++ - List.drop (0 + 20) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I)).toNat - rw [List.take_zero, List.nil_append] - rw [fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - have hlen20 : - (List.take 20 (EVM.Word.toBytesLEWithSizeProof (initializeArgWord I)).1).length = - 20 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof (initializeArgWord I)).2] - norm_num - rw [hlen20] - rw [show 256 ^ (20 : Nat) = 2 ^ 160 by norm_num [Nat.pow_add]] - rw [show 2 ^ (8 * 20) = 2 ^ 160 by norm_num] - have hargLt : (initializeArgWord I).toNat < 2 ^ 160 := by - unfold initializeArgWord - rw [initializeUint160Mask_decode] - exact Nat.mod_lt _ (by norm_num [EVM.twoPow] : 0 < EVM.twoPow 160) - have hargClean : UInt256.land (initializeArgWord I) solcAddrMask = initializeArgWord I := by - exact solcAddrMask_clean (by simpa [EVM.addressModulus, EVM.twoPow] using hargLt) - have hvalMask : (initializeArgWord I).toNat % 2 ^ 160 = - (UInt256.land (initializeArgWord I) solcAddrMask).toNat := by - rw [hargClean] - exact Nat.mod_eq_of_lt hargLt - rw [hvalMask] - rw [show (initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I)).toNat = - ((UInt256.land (initializeArgWord I) solcAddrMask).toNat + - w.toNat / 2 ^ 160 * 2 ^ 160) by - dsimp [initializeSlot0SlotWithSqrt, initializeSlot0SqrtEventWord, codeOwnerStorageWord, w] - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask by - native_decide] - rw [initializeSetLow160Word_eq] - exact ulit_toNat' _ (initializeSetLow160Word_nat_lt w (initializeArgWord I))] - ring - -theorem initializeSlot0AfterSqrtPriceX96State_accountMapEquiv_same - (evm : EVM.State) (I : ExecutionEnv) (hEnv : evm.executionEnv = I) : - accountMapEquiv - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I))) - (initializeSlot0AfterSqrtPriceX96State evm I).accountMap := by - have hstate : - initializeSlot0AfterSqrtPriceX96State evm I = - Solm.EVM.storageStore evm I.codeOwner ⟨0⟩ - (initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I)) := by - apply Option.some.inj - rw [← storageLocStore_initializeSlot0_sqrtPriceX96 evm I] - exact storageLocStore_initializeSlot0_sqrtPriceX96_packed evm I hEnv - rw [hstate] - simpa [storageStore_accountMap] using - accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I)) - (accountMapEquiv_refl evm.accountMap) - -theorem initializeSignextendTwo_mod24 (w : UInt256) : - (UInt256.signextend ⟨2⟩ w).toNat % 2 ^ 24 = w.toNat % 2 ^ 24 := by - rw [← wordOfInt_sint24Value_eq_signextend_two] - unfold tickSpacingSint24Value - let m := w.toNat % EVM.twoPow 24 - have hmdef : m = w.toNat % EVM.twoPow 24 := rfl - have hmhi : m < EVM.twoPow 24 := by - rw [hmdef] - exact Nat.mod_lt _ (by norm_num [EVM.twoPow]) - by_cases h : m < EVM.twoPow 23 - · have hval : - (let m := w.toNat % EVM.twoPow 24 - if m < EVM.twoPow 23 then (m : Int) else (m : Int) - (EVM.twoPow 24 : Int)) = - (m : Int) := by - dsimp - have h' : w.toNat % EVM.twoPow 24 < EVM.twoPow 23 := by rwa [← hmdef] - rw [if_pos h'] - omega - rw [hval] - have hword : (EVM.wordOfInt (m : Int)).toNat = m := by - unfold EVM.wordOfInt - rw [if_neg (by omega)] - unfold EVM.word EVM.uintN UInt256.toNat - change m % EVM.twoPow 256 = m - apply Nat.mod_eq_of_lt - norm_num [EVM.twoPow] at hmhi ⊢ - omega - rw [hword] - change m % 2 ^ 24 = w.toNat % 2 ^ 24 - rw [Nat.mod_eq_of_lt (by simpa [EVM.twoPow] using hmhi)] - exact hmdef - · have hval : - (let m := w.toNat % EVM.twoPow 24 - if m < EVM.twoPow 23 then (m : Int) else (m : Int) - (EVM.twoPow 24 : Int)) = - (m : Int) - (EVM.twoPow 24 : Int) := by - dsimp - have h' : ¬ w.toNat % EVM.twoPow 24 < EVM.twoPow 23 := by - intro hh - exact h (by rwa [hmdef]) - rw [if_neg h'] - omega - rw [hval] - have hneg : ((m : Int) - (EVM.twoPow 24 : Int)) < 0 := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hnatAbs : ((m : Int) - (EVM.twoPow 24 : Int)).natAbs = - EVM.twoPow 24 - m := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hdiffPos : EVM.twoPow 24 - m ≠ 0 := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hdiffLt : EVM.twoPow 24 - m < EVM.wordModulus := by - norm_num [EVM.wordModulus, EVM.twoPow] at hmhi ⊢ - omega - have hword : - (EVM.wordOfInt ((m : Int) - (EVM.twoPow 24 : Int))).toNat = - UInt256.size - (EVM.twoPow 24 - m) := by - unfold EVM.wordOfInt - rw [if_pos hneg] - rw [hnatAbs, Nat.mod_eq_of_lt hdiffLt, if_neg hdiffPos] - change (UInt256.ofNat (EVM.wordModulus - (EVM.twoPow 24 - m))).toNat = _ - rw [ulit_toNat'] - · simp [EVM.wordModulus, EVM.twoPow, UInt256.size] - · norm_num [EVM.wordModulus, EVM.twoPow, UInt256.size] at hmhi ⊢ - omega - rw [hword] - change (UInt256.size - (EVM.twoPow 24 - m)) % 2 ^ 24 = w.toNat % 2 ^ 24 - have hmge : 2 ^ 23 ≤ m := by - have hnot : ¬ m < 2 ^ 23 := by simpa [EVM.twoPow] using h - omega - have hmod : (UInt256.size - (EVM.twoPow 24 - m)) % 2 ^ 24 = m := by - norm_num [EVM.twoPow, UInt256.size] at hmhi hmge ⊢ - omega - rw [hmod] - exact hmdef - -theorem initializeSlot0TickLow24_toNat (tick : UInt256) : - (UInt256.land (UInt256.signextend ⟨2⟩ (initializeSlot0TickEventWord tick)) - ⟨16777215⟩).toNat = - tick.toNat % 2 ^ 24 := by - unfold initializeSlot0TickEventWord - rw [slot0SignextendTwo_idempotent] - rw [u256_land_toNat] - rw [show (⟨16777215⟩ : UInt256).toNat = 2 ^ 24 - 1 by native_decide] - rw [nat_land_mask_eq_mod] - rw [initializeSignextendTwo_mod24] - exact Nat.mod_eq_of_lt (lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 24)) - (by norm_num [UInt256.size])) - -abbrev initializeSlot0TickSlotWord (evm : EVM.State) (I : ExecutionEnv) : UInt256 := - UInt256.ofNat - ((Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 160 + - (getTickEstimatedWord I).toNat % 2 ^ 24 * 2 ^ 160 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 184 * - 2 ^ 184) - -theorem initializeSlot0TickSlotWord_nat_lt (evm : EVM.State) (I : ExecutionEnv) : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 160 + - (getTickEstimatedWord I).toNat % 2 ^ 24 * 2 ^ 160 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 184 * - 2 ^ 184 < - UInt256.size := by - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - have hlow : w.toNat % 2 ^ 160 ≤ 2 ^ 160 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have htick : (getTickEstimatedWord I).toNat % 2 ^ 24 ≤ 2 ^ 24 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 184 < 2 ^ 72 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 184 * 2 ^ 72 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 184 ≤ 2 ^ 72 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : - (2 ^ 160 - 1) + (2 ^ 24 - 1) * 2 ^ 160 + (2 ^ 72 - 1) * 2 ^ 184 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - dsimp [w] at hlow hhigh - omega - -theorem storageLocStore_initializeSlot0_tick_packed - (evm : EVM.State) (I : ExecutionEnv) : - storageLocStore evm initializeSlot0TickLoc (initializeTickValue I) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0TickSlotWord evm I)) := by - unfold storageLocStore storageLocWriteWord initializeSlot0TickLoc loc - rw [show valueToWord (initializeTickValue I) = - some (UInt256.signextend ⟨2⟩ (getTickEstimatedWord I)) by - unfold initializeTickValue wordToElem int24Int valueToWord - simp only - exact congrArg some (wordOfInt_sint24Value_eq_signextend_two (getTickEstimatedWord I))] - simp only [bind, Option.bind] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - show fromBytes' - ((List.take 20 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 3 - ↑(EVM.Word.toBytesLEWithSizeProof - (UInt256.signextend ⟨2⟩ (getTickEstimatedWord I)))) ++ - List.drop (20 + 3) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (initializeSlot0TickSlotWord evm I).toNat - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [show 256 ^ (20 : Nat) = 2 ^ 160 by norm_num [Nat.pow_add]] - rw [show 256 ^ (3 : Nat) = 2 ^ 24 by norm_num] - rw [show 256 ^ (23 : Nat) = 2 ^ 184 by norm_num [Nat.pow_add]] - have hlen20 : (List.take 20 (EVM.Word.toBytesLEWithSizeProof w).1).length = 20 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - have hlen3 : - (List.take 3 - (EVM.Word.toBytesLEWithSizeProof - (UInt256.signextend ⟨2⟩ (getTickEstimatedWord I))).1).length = - 3 := by - rw [List.length_take, - (EVM.Word.toBytesLEWithSizeProof - (UInt256.signextend ⟨2⟩ (getTickEstimatedWord I))).2] - norm_num - have hlen23 : - (List.take 20 (EVM.Word.toBytesLEWithSizeProof w).1 ++ - List.take 3 - (EVM.Word.toBytesLEWithSizeProof - (UInt256.signextend ⟨2⟩ (getTickEstimatedWord I))).1).length = - 23 := by - rw [List.length_append, hlen20, hlen3] - rw [hlen20, hlen23] - rw [show (initializeSlot0TickSlotWord evm I).toNat = - w.toNat % 2 ^ 160 + (getTickEstimatedWord I).toNat % 2 ^ 24 * 2 ^ 160 + - w.toNat / 2 ^ 184 * 2 ^ 184 by - dsimp [initializeSlot0TickSlotWord, w] - exact ulit_toNat' _ (initializeSlot0TickSlotWord_nat_lt evm I)] - rw [initializeSignextendTwo_mod24] - ring - -abbrev initializeSlot0ObservationIndexSlotWord (evm : EVM.State) : UInt256 := - UInt256.ofNat - ((Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 184 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 200 * - 2 ^ 200) - -theorem initializeSlot0ObservationIndexSlotWord_nat_lt (evm : EVM.State) : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 184 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 200 * - 2 ^ 200 < - UInt256.size := by - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - have hlow : w.toNat % 2 ^ 184 ≤ 2 ^ 184 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 200 < 2 ^ 56 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 200 * 2 ^ 56 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 200 ≤ 2 ^ 56 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 184 - 1) + (2 ^ 56 - 1) * 2 ^ 200 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - dsimp [w] at hlow hhigh - omega - -theorem storageLocStore_initializeSlot0_observationIndex_packed - (evm : EVM.State) : - storageLocStore evm initializeSlot0ObservationIndexLoc (.int 0) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0ObservationIndexSlotWord evm)) := by - unfold storageLocStore storageLocWriteWord initializeSlot0ObservationIndexLoc loc - simp only [valueToWord, bind, Option.bind] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - show fromBytes' - ((List.take 23 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 2 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0))) ++ - List.drop (23 + 2) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (initializeSlot0ObservationIndexSlotWord evm).toNat - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [show 256 ^ (23 : Nat) = 2 ^ 184 by norm_num [Nat.pow_add]] - rw [show 256 ^ (2 : Nat) = 2 ^ 16 by norm_num] - rw [show 256 ^ (25 : Nat) = 2 ^ 200 by norm_num [Nat.pow_add]] - rw [show (UInt256.ofNat 0).toNat = 0 by native_decide] - have hlen23 : (List.take 23 (EVM.Word.toBytesLEWithSizeProof w).1).length = 23 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - have hlen2 : - (List.take 2 (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0)).1).length = 2 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0)).2] - norm_num - have hlen25 : - (List.take 23 (EVM.Word.toBytesLEWithSizeProof w).1 ++ - List.take 2 (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0)).1).length = 25 := by - rw [List.length_append, hlen23, hlen2] - rw [hlen23, hlen25] - rw [show (initializeSlot0ObservationIndexSlotWord evm).toNat = - w.toNat % 2 ^ 184 + w.toNat / 2 ^ 200 * 2 ^ 200 by - dsimp [initializeSlot0ObservationIndexSlotWord, w] - exact ulit_toNat' _ (initializeSlot0ObservationIndexSlotWord_nat_lt evm)] - ring - -abbrev initializeSlot0ObservationCardinalitySlotWord (evm : EVM.State) : UInt256 := - UInt256.ofNat - ((Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 200 + - 2 ^ 200 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 216 * - 2 ^ 216) - -theorem initializeSlot0ObservationCardinalitySlotWord_nat_lt (evm : EVM.State) : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 200 + - 2 ^ 200 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 216 * - 2 ^ 216 < - UInt256.size := by - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - have hlow : w.toNat % 2 ^ 200 ≤ 2 ^ 200 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 216 < 2 ^ 40 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 216 * 2 ^ 40 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 216 ≤ 2 ^ 40 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 200 - 1) + 2 ^ 200 + (2 ^ 40 - 1) * 2 ^ 216 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - dsimp [w] at hlow hhigh - omega - -theorem storageLocStore_initializeSlot0_observationCardinality_packed - (evm : EVM.State) : - storageLocStore evm initializeSlot0ObservationCardinalityLoc (.int 1) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0ObservationCardinalitySlotWord evm)) := by - unfold storageLocStore storageLocWriteWord initializeSlot0ObservationCardinalityLoc loc - simp only [valueToWord, bind, Option.bind] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - show fromBytes' - ((List.take 25 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 2 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1))) ++ - List.drop (25 + 2) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (initializeSlot0ObservationCardinalitySlotWord evm).toNat - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [show 256 ^ (25 : Nat) = 2 ^ 200 by norm_num [Nat.pow_add]] - rw [show 256 ^ (2 : Nat) = 2 ^ 16 by norm_num] - rw [show 256 ^ (27 : Nat) = 2 ^ 216 by norm_num [Nat.pow_add]] - rw [show (UInt256.ofNat 1).toNat = 1 by native_decide] - have hlen25 : (List.take 25 (EVM.Word.toBytesLEWithSizeProof w).1).length = 25 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - have hlen2 : - (List.take 2 (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1)).1).length = 2 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1)).2] - norm_num - have hlen27 : - (List.take 25 (EVM.Word.toBytesLEWithSizeProof w).1 ++ - List.take 2 (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1)).1).length = 27 := by - rw [List.length_append, hlen25, hlen2] - rw [hlen25, hlen27] - rw [show (initializeSlot0ObservationCardinalitySlotWord evm).toNat = - w.toNat % 2 ^ 200 + 2 ^ 200 + w.toNat / 2 ^ 216 * 2 ^ 216 by - dsimp [initializeSlot0ObservationCardinalitySlotWord, w] - exact ulit_toNat' _ (initializeSlot0ObservationCardinalitySlotWord_nat_lt evm)] - ring - -abbrev initializeSlot0ObservationCardinalityNextSlotWord (evm : EVM.State) : UInt256 := - UInt256.ofNat - ((Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 216 + - 2 ^ 216 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 232 * - 2 ^ 232) - -theorem initializeSlot0ObservationCardinalityNextSlotWord_nat_lt (evm : EVM.State) : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 216 + - 2 ^ 216 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 232 * - 2 ^ 232 < - UInt256.size := by - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - have hlow : w.toNat % 2 ^ 216 ≤ 2 ^ 216 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 232 < 2 ^ 24 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 232 * 2 ^ 24 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 232 ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 216 - 1) + 2 ^ 216 + (2 ^ 24 - 1) * 2 ^ 232 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - dsimp [w] at hlow hhigh - omega - -theorem storageLocStore_initializeSlot0_observationCardinalityNext_packed - (evm : EVM.State) : - storageLocStore evm initializeSlot0ObservationCardinalityNextLoc (.int 1) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0ObservationCardinalityNextSlotWord evm)) := by - unfold storageLocStore storageLocWriteWord initializeSlot0ObservationCardinalityNextLoc loc - simp only [valueToWord, bind, Option.bind] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - show fromBytes' - ((List.take 27 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 2 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1))) ++ - List.drop (27 + 2) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (initializeSlot0ObservationCardinalityNextSlotWord evm).toNat - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [show 256 ^ (27 : Nat) = 2 ^ 216 by norm_num [Nat.pow_add]] - rw [show 256 ^ (2 : Nat) = 2 ^ 16 by norm_num] - rw [show 256 ^ (29 : Nat) = 2 ^ 232 by norm_num [Nat.pow_add]] - rw [show (UInt256.ofNat 1).toNat = 1 by native_decide] - have hlen27 : (List.take 27 (EVM.Word.toBytesLEWithSizeProof w).1).length = 27 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - have hlen2 : - (List.take 2 (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1)).1).length = 2 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1)).2] - norm_num - have hlen29 : - (List.take 27 (EVM.Word.toBytesLEWithSizeProof w).1 ++ - List.take 2 (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1)).1).length = 29 := by - rw [List.length_append, hlen27, hlen2] - rw [hlen27, hlen29] - rw [show (initializeSlot0ObservationCardinalityNextSlotWord evm).toNat = - w.toNat % 2 ^ 216 + 2 ^ 216 + w.toNat / 2 ^ 232 * 2 ^ 232 by - dsimp [initializeSlot0ObservationCardinalityNextSlotWord, w] - exact ulit_toNat' _ (initializeSlot0ObservationCardinalityNextSlotWord_nat_lt evm)] - ring - -abbrev initializeSlot0FeeProtocolSlotWord (evm : EVM.State) : UInt256 := - UInt256.ofNat - ((Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 232 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 240 * - 2 ^ 240) - -theorem initializeSlot0FeeProtocolSlotWord_nat_lt (evm : EVM.State) : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 232 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 240 * - 2 ^ 240 < - UInt256.size := by - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - have hlow : w.toNat % 2 ^ 232 ≤ 2 ^ 232 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 240 < 2 ^ 16 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 240 * 2 ^ 16 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 240 ≤ 2 ^ 16 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 232 - 1) + (2 ^ 16 - 1) * 2 ^ 240 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - dsimp [w] at hlow hhigh - omega - -theorem storageLocStore_initializeSlot0_feeProtocol_packed - (evm : EVM.State) : - storageLocStore evm initializeSlot0FeeProtocolLoc (.int 0) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0FeeProtocolSlotWord evm)) := by - unfold storageLocStore storageLocWriteWord initializeSlot0FeeProtocolLoc loc - simp only [valueToWord, bind, Option.bind] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - show fromBytes' - ((List.take 29 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0))) ++ - List.drop (29 + 1) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (initializeSlot0FeeProtocolSlotWord evm).toNat - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [show 256 ^ (29 : Nat) = 2 ^ 232 by norm_num [Nat.pow_add]] - rw [show 256 ^ (1 : Nat) = 2 ^ 8 by norm_num] - rw [show 256 ^ (30 : Nat) = 2 ^ 240 by norm_num [Nat.pow_add]] - rw [show (UInt256.ofNat 0).toNat = 0 by native_decide] - have hlen29 : (List.take 29 (EVM.Word.toBytesLEWithSizeProof w).1).length = 29 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - have hlen1 : - (List.take 1 (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0)).1).length = 1 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0)).2] - norm_num - have hlen30 : - (List.take 29 (EVM.Word.toBytesLEWithSizeProof w).1 ++ - List.take 1 (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0)).1).length = 30 := by - rw [List.length_append, hlen29, hlen1] - rw [hlen29, hlen30] - rw [show (initializeSlot0FeeProtocolSlotWord evm).toNat = - w.toNat % 2 ^ 232 + w.toNat / 2 ^ 240 * 2 ^ 240 by - dsimp [initializeSlot0FeeProtocolSlotWord, w] - exact ulit_toNat' _ (initializeSlot0FeeProtocolSlotWord_nat_lt evm)] - ring - -abbrev initializeSlot0UnlockedTrueSlotWord (evm : EVM.State) : UInt256 := - UInt256.ofNat - ((Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 240 + - 2 ^ 240 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 248 * - 2 ^ 248) - -theorem initializeSlot0UnlockedTrueSlotWord_nat_lt (evm : EVM.State) : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 240 + - 2 ^ 240 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 248 * - 2 ^ 248 < - UInt256.size := by - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - have hlow : w.toNat % 2 ^ 240 ≤ 2 ^ 240 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 248 < 2 ^ 8 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 248 * 2 ^ 8 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 248 ≤ 2 ^ 8 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 240 - 1) + 2 ^ 240 + (2 ^ 8 - 1) * 2 ^ 248 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - dsimp [w] at hlow hhigh - omega - -theorem storageLocStore_initializeSlot0_unlocked_true_packed - (evm : EVM.State) : - storageLocStore evm initializeSlot0UnlockedLoc (.bool true) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0UnlockedTrueSlotWord evm)) := by - unfold storageLocStore storageLocWriteWord initializeSlot0UnlockedLoc loc - simp only [valueToWord, Bool.toUInt256_true, bind, Option.bind] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - show fromBytes' - ((List.take 30 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1))) ++ - List.drop (30 + 1) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (initializeSlot0UnlockedTrueSlotWord evm).toNat - rw [show List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1)) = - ([1] : List UInt8) by - native_decide] - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [show 256 ^ (30 : Nat) = 2 ^ 240 by norm_num [Nat.pow_add]] - rw [show 256 ^ (31 : Nat) = 2 ^ 248 by norm_num [Nat.pow_add]] - have hlen30 : (List.take 30 (EVM.Word.toBytesLEWithSizeProof w).1).length = 30 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - have hlen31 : (List.take 30 (EVM.Word.toBytesLEWithSizeProof w).1 ++ [1]).length = 31 := by - rw [List.length_append, hlen30] - norm_num - rw [hlen30, hlen31] - rw [show (initializeSlot0UnlockedTrueSlotWord evm).toNat = - w.toNat % 2 ^ 240 + 2 ^ 240 + w.toNat / 2 ^ 248 * 2 ^ 248 by - dsimp [initializeSlot0UnlockedTrueSlotWord, w] - exact ulit_toNat' _ (initializeSlot0UnlockedTrueSlotWord_nat_lt evm)] - simp [fromBytes'] - ring - -theorem initializeSlot0AfterTickState_accountMapEquiv_same - (evm : EVM.State) (I : ExecutionEnv) : - accountMapEquiv - (sstoreAccountMap evm.executionEnv.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0TickSlotWord evm I)) - (initializeSlot0AfterTickState evm I).accountMap := by - have hstate : - initializeSlot0AfterTickState evm I = - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0TickSlotWord evm I) := by - apply Option.some.inj - rw [← storageLocStore_initializeSlot0_tick evm I] - exact storageLocStore_initializeSlot0_tick_packed evm I - rw [hstate] - simpa [storageStore_accountMap] using - accountMapEquiv_sstoreAccountMap evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0TickSlotWord evm I) (accountMapEquiv_refl evm.accountMap) - -theorem initializeSlot0AfterObservationIndexState_accountMapEquiv_same - (evm : EVM.State) : - accountMapEquiv - (sstoreAccountMap evm.executionEnv.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0ObservationIndexSlotWord evm)) - (initializeSlot0AfterObservationIndexState evm).accountMap := by - have hstate : - initializeSlot0AfterObservationIndexState evm = - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0ObservationIndexSlotWord evm) := by - apply Option.some.inj - rw [← storageLocStore_initializeSlot0_observationIndex evm] - exact storageLocStore_initializeSlot0_observationIndex_packed evm - rw [hstate] - simpa [storageStore_accountMap] using - accountMapEquiv_sstoreAccountMap evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0ObservationIndexSlotWord evm) (accountMapEquiv_refl evm.accountMap) - -theorem initializeSlot0AfterObservationCardinalityState_accountMapEquiv_same - (evm : EVM.State) : - accountMapEquiv - (sstoreAccountMap evm.executionEnv.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0ObservationCardinalitySlotWord evm)) - (initializeSlot0AfterObservationCardinalityState evm).accountMap := by - have hstate : - initializeSlot0AfterObservationCardinalityState evm = - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0ObservationCardinalitySlotWord evm) := by - apply Option.some.inj - rw [← storageLocStore_initializeSlot0_observationCardinality evm] - exact storageLocStore_initializeSlot0_observationCardinality_packed evm - rw [hstate] - simpa [storageStore_accountMap] using - accountMapEquiv_sstoreAccountMap evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0ObservationCardinalitySlotWord evm) (accountMapEquiv_refl evm.accountMap) - -theorem initializeSlot0AfterObservationCardinalityNextState_accountMapEquiv_same - (evm : EVM.State) : - accountMapEquiv - (sstoreAccountMap evm.executionEnv.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0ObservationCardinalityNextSlotWord evm)) - (initializeSlot0AfterObservationCardinalityNextState evm).accountMap := by - have hstate : - initializeSlot0AfterObservationCardinalityNextState evm = - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0ObservationCardinalityNextSlotWord evm) := by - apply Option.some.inj - rw [← storageLocStore_initializeSlot0_observationCardinalityNext evm] - exact storageLocStore_initializeSlot0_observationCardinalityNext_packed evm - rw [hstate] - simpa [storageStore_accountMap] using - accountMapEquiv_sstoreAccountMap evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0ObservationCardinalityNextSlotWord evm) - (accountMapEquiv_refl evm.accountMap) - -theorem initializeSlot0AfterFeeProtocolState_accountMapEquiv_same - (evm : EVM.State) : - accountMapEquiv - (sstoreAccountMap evm.executionEnv.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0FeeProtocolSlotWord evm)) - (initializeSlot0AfterFeeProtocolState evm).accountMap := by - have hstate : - initializeSlot0AfterFeeProtocolState evm = - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0FeeProtocolSlotWord evm) := by - apply Option.some.inj - rw [← storageLocStore_initializeSlot0_feeProtocol evm] - exact storageLocStore_initializeSlot0_feeProtocol_packed evm - rw [hstate] - simpa [storageStore_accountMap] using - accountMapEquiv_sstoreAccountMap evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0FeeProtocolSlotWord evm) (accountMapEquiv_refl evm.accountMap) - -theorem initializeSlot0AfterUnlockedState_accountMapEquiv_same - (evm : EVM.State) : - accountMapEquiv - (sstoreAccountMap evm.executionEnv.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0UnlockedTrueSlotWord evm)) - (initializeSlot0AfterUnlockedState evm).accountMap := by - have hstate : - initializeSlot0AfterUnlockedState evm = - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0UnlockedTrueSlotWord evm) := by - apply Option.some.inj - rw [← storageLocStore_initializeSlot0_unlocked_true evm] - exact storageLocStore_initializeSlot0_unlocked_true_packed evm - rw [hstate] - simpa [storageStore_accountMap] using - accountMapEquiv_sstoreAccountMap evm.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0UnlockedTrueSlotWord evm) (accountMapEquiv_refl evm.accountMap) - -set_option maxHeartbeats 1000000 in -theorem initializeSlot0AfterAllState_accountMapEquiv_sourceSequence - (evm : EVM.State) (I : ExecutionEnv) (hEnv : evm.executionEnv = I) : - let evm1 := initializeSlot0AfterSqrtPriceX96State evm I - let evm2 := initializeSlot0AfterTickState evm1 I - let evm3 := initializeSlot0AfterObservationIndexState evm2 - let evm4 := initializeSlot0AfterObservationCardinalityState evm3 - let evm5 := initializeSlot0AfterObservationCardinalityNextState evm4 - let evm6 := initializeSlot0AfterFeeProtocolState evm5 - accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I))) - ⟨0⟩ (initializeSlot0TickSlotWord evm1 I)) - ⟨0⟩ (initializeSlot0ObservationIndexSlotWord evm2)) - ⟨0⟩ (initializeSlot0ObservationCardinalitySlotWord evm3)) - ⟨0⟩ (initializeSlot0ObservationCardinalityNextSlotWord evm4)) - ⟨0⟩ (initializeSlot0FeeProtocolSlotWord evm5)) - ⟨0⟩ (initializeSlot0UnlockedTrueSlotWord evm6)) - (initializeSlot0AfterAllState evm I).accountMap := by - intro evm1 evm2 evm3 evm4 evm5 evm6 - have h1 : accountMapEquiv - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I))) - evm1.accountMap := by - simpa [evm1] using initializeSlot0AfterSqrtPriceX96State_accountMapEquiv_same evm I hEnv - have hEnv1 : evm1.executionEnv = I := by - have hEnv1base : evm1.executionEnv = evm.executionEnv := by - simpa [evm1] using storageLocStore_executionEnv_of - (storageLocStore_initializeSlot0_sqrtPriceX96 evm I) - exact hEnv1base.trans hEnv - have h2base := accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (initializeSlot0TickSlotWord evm1 I) h1 - have h2src := initializeSlot0AfterTickState_accountMapEquiv_same evm1 I - have h2 : accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I))) - ⟨0⟩ (initializeSlot0TickSlotWord evm1 I)) - evm2.accountMap := by - exact h2base.trans (by simpa [evm2, hEnv1] using h2src) - have hEnv2 : evm2.executionEnv = I := by - simpa [evm2, hEnv1] using storageLocStore_executionEnv_of - (storageLocStore_initializeSlot0_tick evm1 I) - have h3base := accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (initializeSlot0ObservationIndexSlotWord evm2) h2 - have h3src := initializeSlot0AfterObservationIndexState_accountMapEquiv_same evm2 - have h3 : accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I))) - ⟨0⟩ (initializeSlot0TickSlotWord evm1 I)) - ⟨0⟩ (initializeSlot0ObservationIndexSlotWord evm2)) - evm3.accountMap := by - exact h3base.trans (by simpa [evm3, hEnv2] using h3src) - have hEnv3 : evm3.executionEnv = I := by - simpa [evm3, hEnv2] using storageLocStore_executionEnv_of - (storageLocStore_initializeSlot0_observationIndex evm2) - have h4base := accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (initializeSlot0ObservationCardinalitySlotWord evm3) h3 - have h4src := initializeSlot0AfterObservationCardinalityState_accountMapEquiv_same evm3 - have h4 : accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I))) - ⟨0⟩ (initializeSlot0TickSlotWord evm1 I)) - ⟨0⟩ (initializeSlot0ObservationIndexSlotWord evm2)) - ⟨0⟩ (initializeSlot0ObservationCardinalitySlotWord evm3)) - evm4.accountMap := by - exact h4base.trans (by simpa [evm4, hEnv3] using h4src) - have hEnv4 : evm4.executionEnv = I := by - simpa [evm4, hEnv3] using storageLocStore_executionEnv_of - (storageLocStore_initializeSlot0_observationCardinality evm3) - have h5base := accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (initializeSlot0ObservationCardinalityNextSlotWord evm4) h4 - have h5src := initializeSlot0AfterObservationCardinalityNextState_accountMapEquiv_same evm4 - have h5 : accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I))) - ⟨0⟩ (initializeSlot0TickSlotWord evm1 I)) - ⟨0⟩ (initializeSlot0ObservationIndexSlotWord evm2)) - ⟨0⟩ (initializeSlot0ObservationCardinalitySlotWord evm3)) - ⟨0⟩ (initializeSlot0ObservationCardinalityNextSlotWord evm4)) - evm5.accountMap := by - exact h5base.trans (by simpa [evm5, hEnv4] using h5src) - have hEnv5 : evm5.executionEnv = I := by - simpa [evm5, hEnv4] using storageLocStore_executionEnv_of - (storageLocStore_initializeSlot0_observationCardinalityNext evm4) - have h6base := accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (initializeSlot0FeeProtocolSlotWord evm5) h5 - have h6src := initializeSlot0AfterFeeProtocolState_accountMapEquiv_same evm5 - have h6 : accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ - (initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I))) - ⟨0⟩ (initializeSlot0TickSlotWord evm1 I)) - ⟨0⟩ (initializeSlot0ObservationIndexSlotWord evm2)) - ⟨0⟩ (initializeSlot0ObservationCardinalitySlotWord evm3)) - ⟨0⟩ (initializeSlot0ObservationCardinalityNextSlotWord evm4)) - ⟨0⟩ (initializeSlot0FeeProtocolSlotWord evm5)) - evm6.accountMap := by - exact h6base.trans (by simpa [evm6, hEnv5] using h6src) - have hEnv6 : evm6.executionEnv = I := by - simpa [evm6, hEnv5] using storageLocStore_executionEnv_of - (storageLocStore_initializeSlot0_feeProtocol evm5) - have h7base := accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (initializeSlot0UnlockedTrueSlotWord evm6) h6 - have h7src := initializeSlot0AfterUnlockedState_accountMapEquiv_same evm6 - unfold initializeSlot0AfterAllState - exact h7base.trans (by simpa [evm1, evm2, evm3, evm4, evm5, evm6, hEnv6] using h7src) - -theorem initializeNatLandClearMiddle - (n lo hi : Nat) (hn : n < 2 ^ 256) (hlohi : lo < hi) (hhi : hi ≤ 256) : - Nat.land n (2 ^ 256 - 2 ^ hi + (2 ^ lo - 1)) = - n % 2 ^ lo + (n / 2 ^ hi) * 2 ^ hi := by - apply Nat.eq_of_testBit_eq - intro i - change (n &&& (2 ^ 256 - 2 ^ hi + (2 ^ lo - 1))).testBit i = - (n % 2 ^ lo + n / 2 ^ hi * 2 ^ hi).testBit i - rw [Nat.testBit_and] - rw [show n % 2 ^ lo + (n / 2 ^ hi) * 2 ^ hi = - 2 ^ hi * (n / 2 ^ hi) + n % 2 ^ lo by ring] - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ hi) - (b_lt := lt_trans (Nat.mod_lt _ (Nat.two_pow_pos lo)) - (Nat.pow_lt_pow_right (by norm_num : 1 < 2) hlohi))] - have hmaskEq : 2 ^ 256 - 2 ^ hi + (2 ^ lo - 1) = - 2 ^ hi * (2 ^ (256 - hi) - 1) + (2 ^ lo - 1) := by - have hpow : 2 ^ hi * 2 ^ (256 - hi) = 2 ^ 256 := by - rw [← Nat.pow_add] - congr 1 - omega - have hmul : 2 ^ hi * (2 ^ (256 - hi) - 1) = 2 ^ 256 - 2 ^ hi := by - rw [Nat.mul_sub_left_distrib] - rw [hpow] - simp - rw [hmul] - rw [hmaskEq] - have hmaskLow : 2 ^ lo - 1 < 2 ^ hi := - lt_of_le_of_lt (Nat.pred_le _) - (Nat.pow_lt_pow_right (by norm_num : 1 < 2) hlohi) - rw [Nat.testBit_two_pow_mul_add (a := 2 ^ (256 - hi) - 1) (b_lt := hmaskLow)] - by_cases hihi : i < hi - · simp [hihi] - by_cases hilo : i < lo - · simp [hilo, Bool.and_comm] - · simp [hilo, Bool.and_comm] - · have hile : hi ≤ i := Nat.le_of_not_gt hihi - simp [hihi] - by_cases hi256 : i < 256 - · have hsub : i - hi < 256 - hi := by omega - have hdiv := divPow_testBit n hi i hile - rw [hdiv] - simp [hsub] - · have hsub : ¬ i - hi < 256 - hi := by omega - have hnbit : n.testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hn (Nat.pow_le_pow_right (by norm_num) (by omega : 256 ≤ i))) - have hdivfalse : (n / 2 ^ hi).testBit (i - hi) = false := by - rw [divPow_testBit n hi i hile, hnbit] - rw [hdivfalse, hnbit] - simp [hsub] - -theorem initializeNatLorPackedMiddle - (n field lo width hi : Nat) - (hfield : field < 2 ^ width) (hlohi : lo < hi) (hhi : lo + width = hi) : - Nat.lor (n % 2 ^ lo + n / 2 ^ hi * 2 ^ hi) (field * 2 ^ lo) = - n % 2 ^ lo + field * 2 ^ lo + n / 2 ^ hi * 2 ^ hi := by - apply Nat.eq_of_testBit_eq - intro i - change ((n % 2 ^ lo + n / 2 ^ hi * 2 ^ hi) ||| (field * 2 ^ lo)).testBit i = - (n % 2 ^ lo + field * 2 ^ lo + n / 2 ^ hi * 2 ^ hi).testBit i - rw [Nat.testBit_or] - rw [show n % 2 ^ lo + n / 2 ^ hi * 2 ^ hi = - 2 ^ hi * (n / 2 ^ hi) + n % 2 ^ lo by ring] - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ hi) - (b_lt := lt_trans (Nat.mod_lt _ (Nat.two_pow_pos lo)) - (Nat.pow_lt_pow_right (by norm_num : 1 < 2) hlohi))] - rw [show n % 2 ^ lo + field * 2 ^ lo + n / 2 ^ hi * 2 ^ hi = - 2 ^ hi * (n / 2 ^ hi) + (2 ^ lo * field + n % 2 ^ lo) by ring] - have hmid : 2 ^ lo * field + n % 2 ^ lo < 2 ^ hi := by - have hlow : n % 2 ^ lo < 2 ^ lo := Nat.mod_lt _ (Nat.two_pow_pos lo) - have hstep : 2 ^ lo * field + n % 2 ^ lo < 2 ^ lo * (field + 1) := by - calc - 2 ^ lo * field + n % 2 ^ lo < 2 ^ lo * field + 2 ^ lo := - Nat.add_lt_add_left hlow _ - _ = 2 ^ lo * (field + 1) := by ring - have hfield_succ : field + 1 ≤ 2 ^ width := Nat.succ_le_of_lt hfield - have hbound : 2 ^ lo * (field + 1) ≤ 2 ^ lo * 2 ^ width := - Nat.mul_le_mul_left _ hfield_succ - have hpow : 2 ^ lo * 2 ^ width = 2 ^ hi := by - rw [← Nat.pow_add, hhi] - exact lt_of_lt_of_le hstep (by simpa [hpow] using hbound) - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ hi) (b_lt := hmid)] - rw [Nat.testBit_two_pow_mul_add (a := field) - (b_lt := Nat.mod_lt _ (Nat.two_pow_pos lo))] - rw [show field * 2 ^ lo = 2 ^ lo * field + 0 by ring] - rw [Nat.testBit_two_pow_mul_add (a := field) (b_lt := Nat.two_pow_pos lo)] - by_cases hilo : i < lo - · simp [hilo] - · have hlole : lo ≤ i := Nat.le_of_not_gt hilo - have hlowfalse : (n % 2 ^ lo).testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le (Nat.mod_lt _ (Nat.two_pow_pos lo)) - (Nat.pow_le_pow_right (by norm_num) hlole)) - by_cases hihi : i < hi - · simp [hilo, hihi, hlowfalse] - · have hfieldfalse : field.testBit (i - lo) = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hfield (Nat.pow_le_pow_right (by norm_num) (by omega))) - simp [hilo, hihi, hfieldfalse] - -theorem initializeNatLorPackedGap - (n field keepLo fieldLo width hi : Nat) - (hfield : field < 2 ^ width) - (hkeepfield : keepLo ≤ fieldLo) - (hfieldhi : fieldLo < hi) - (hhi : fieldLo + width = hi) : - Nat.lor (n % 2 ^ keepLo + n / 2 ^ hi * 2 ^ hi) (field * 2 ^ fieldLo) = - n % 2 ^ keepLo + field * 2 ^ fieldLo + n / 2 ^ hi * 2 ^ hi := by - apply Nat.eq_of_testBit_eq - intro i - change ((n % 2 ^ keepLo + n / 2 ^ hi * 2 ^ hi) ||| (field * 2 ^ fieldLo)).testBit i = - (n % 2 ^ keepLo + field * 2 ^ fieldLo + n / 2 ^ hi * 2 ^ hi).testBit i - rw [Nat.testBit_or] - have hkeepHi : keepLo < hi := lt_of_le_of_lt hkeepfield hfieldhi - rw [show n % 2 ^ keepLo + n / 2 ^ hi * 2 ^ hi = - 2 ^ hi * (n / 2 ^ hi) + n % 2 ^ keepLo by ring] - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ hi) - (b_lt := lt_trans (Nat.mod_lt _ (Nat.two_pow_pos keepLo)) - (Nat.pow_lt_pow_right (by norm_num : 1 < 2) hkeepHi))] - rw [show n % 2 ^ keepLo + field * 2 ^ fieldLo + n / 2 ^ hi * 2 ^ hi = - 2 ^ hi * (n / 2 ^ hi) + (2 ^ fieldLo * field + n % 2 ^ keepLo) by - ring] - have hmid : 2 ^ fieldLo * field + n % 2 ^ keepLo < 2 ^ hi := by - have hlow : n % 2 ^ keepLo < 2 ^ keepLo := Nat.mod_lt _ (Nat.two_pow_pos keepLo) - have hlowField : n % 2 ^ keepLo < 2 ^ fieldLo := - lt_of_lt_of_le hlow (Nat.pow_le_pow_right (by norm_num) hkeepfield) - have hstep : - 2 ^ fieldLo * field + n % 2 ^ keepLo < 2 ^ fieldLo * (field + 1) := by - calc - 2 ^ fieldLo * field + n % 2 ^ keepLo < - 2 ^ fieldLo * field + 2 ^ fieldLo := Nat.add_lt_add_left hlowField _ - _ = 2 ^ fieldLo * (field + 1) := by ring - have hfield_succ : field + 1 ≤ 2 ^ width := Nat.succ_le_of_lt hfield - have hbound : 2 ^ fieldLo * (field + 1) ≤ 2 ^ fieldLo * 2 ^ width := - Nat.mul_le_mul_left _ hfield_succ - have hpow : 2 ^ fieldLo * 2 ^ width = 2 ^ hi := by - rw [← Nat.pow_add, hhi] - exact lt_of_lt_of_le hstep (by simpa [hpow] using hbound) - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ hi) (b_lt := hmid)] - have hlowField : n % 2 ^ keepLo < 2 ^ fieldLo := - lt_of_lt_of_le (Nat.mod_lt _ (Nat.two_pow_pos keepLo)) - (Nat.pow_le_pow_right (by norm_num) hkeepfield) - rw [Nat.testBit_two_pow_mul_add (a := field) (b_lt := hlowField)] - rw [show field * 2 ^ fieldLo = 2 ^ fieldLo * field + 0 by ring] - rw [Nat.testBit_two_pow_mul_add (a := field) (b_lt := Nat.two_pow_pos fieldLo)] - by_cases hiField : i < fieldLo - · simp [hiField] - · have hfieldLoLe : fieldLo ≤ i := Nat.le_of_not_gt hiField - have hlowfalse : (n % 2 ^ keepLo).testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le (Nat.mod_lt _ (Nat.two_pow_pos keepLo)) - (Nat.pow_le_pow_right (by norm_num) (le_trans hkeepfield hfieldLoLe))) - by_cases hihi : i < hi - · simp [hiField, hihi, hlowfalse] - · have hfieldfalse : field.testBit (i - fieldLo) = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hfield (Nat.pow_le_pow_right (by norm_num) (by omega))) - simp [hiField, hihi, hfieldfalse] - -theorem initializeSlot0TickClearMask160_toNat : - (UInt256.lnot (UInt256.shiftLeft (⟨16777215⟩ : UInt256) ⟨160⟩)).toNat = - 2 ^ 256 - 2 ^ 184 + (2 ^ 160 - 1) := by - native_decide - -theorem initializeSlot0TickClearMask_toNat : - initializeSlot0TickClearMask.toNat = 2 ^ 256 - 2 ^ 216 + (2 ^ 184 - 1) := by - native_decide - -theorem initializeSlot0CardinalityNextClearMask_toNat : - (UInt256.lnot (UInt256.shiftLeft (⟨65535⟩ : UInt256) ⟨216⟩)).toNat = - 2 ^ 256 - 2 ^ 232 + (2 ^ 216 - 1) := by - native_decide - -theorem initializeSlot0UnlockedClearMask_toNat : - initializeSlot0UnlockedClearMask.toNat = 2 ^ 256 - 2 ^ 248 + (2 ^ 232 - 1) := by - native_decide - -theorem initializeSlot0TickInsertWord_nat_lt (w tick : UInt256) : - w.toNat % 2 ^ 160 + tick.toNat % 2 ^ 24 * 2 ^ 160 + - w.toNat / 2 ^ 184 * 2 ^ 184 < - UInt256.size := by - have hlow : w.toNat % 2 ^ 160 ≤ 2 ^ 160 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have htick : tick.toNat % 2 ^ 24 ≤ 2 ^ 24 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 184 < 2 ^ 72 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 184 * 2 ^ 72 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 184 ≤ 2 ^ 72 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : - (2 ^ 160 - 1) + (2 ^ 24 - 1) * 2 ^ 160 + (2 ^ 72 - 1) * 2 ^ 184 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - -theorem initializeSlot0TickInsertWord_eq (w tick : UInt256) : - UInt256.lor - (UInt256.mul - (UInt256.land (UInt256.signextend ⟨2⟩ (initializeSlot0TickEventWord tick)) - ⟨16777215⟩) - (UInt256.shiftLeft ⟨1⟩ ⟨160⟩)) - (UInt256.land (UInt256.lnot (UInt256.shiftLeft ⟨16777215⟩ ⟨160⟩)) w) = - UInt256.ofNat - (w.toNat % 2 ^ 160 + tick.toNat % 2 ^ 24 * 2 ^ 160 + - w.toNat / 2 ^ 184 * 2 ^ 184) := by - apply u256_inj - rw [u256_lor_toNat, u256_mul_toNat] - rw [initializeSlot0TickLow24_toNat] - rw [u256_land_toNat] - rw [initializeSlot0TickClearMask160_toNat] - rw [nat_land_comm] - rw [initializeNatLandClearMiddle w.toNat 160 184 w.val.isLt (by norm_num) (by norm_num)] - have hclearLt : w.toNat % 2 ^ 160 + w.toNat / 2 ^ 184 * 2 ^ 184 < UInt256.size := by - rw [← initializeNatLandClearMiddle w.toNat 160 184 w.val.isLt (by norm_num) (by norm_num)] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [UInt256.size]) - rw [Nat.mod_eq_of_lt hclearLt] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩).toNat = 2 ^ 160 by - native_decide] - have hmulLt : tick.toNat % 2 ^ 24 * 2 ^ 160 < UInt256.size := by - have htick : tick.toNat % 2 ^ 24 < 2 ^ 24 := Nat.mod_lt _ (by norm_num) - have hmul : tick.toNat % 2 ^ 24 * 2 ^ 160 < 2 ^ 24 * 2 ^ 160 := - Nat.mul_lt_mul_of_pos_right htick (by norm_num) - norm_num [UInt256.size, Nat.pow_add] at hmul ⊢ - omega - rw [Nat.mod_eq_of_lt hmulLt] - rw [nat_lor_comm] - rw [initializeNatLorPackedMiddle _ _ 160 24 184] - rw [ulit_toNat' _ (initializeSlot0TickInsertWord_nat_lt w tick)] - exact Nat.mod_eq_of_lt (initializeSlot0TickInsertWord_nat_lt w tick) - · exact Nat.mod_lt _ (by norm_num : 0 < 2 ^ 24) - · norm_num - · norm_num - -theorem initializeSlot0CardinalityInsertWord_nat_lt (w : UInt256) : - w.toNat % 2 ^ 184 + 2 ^ 200 + w.toNat / 2 ^ 216 * 2 ^ 216 < UInt256.size := by - have hlow : w.toNat % 2 ^ 184 ≤ 2 ^ 184 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 216 < 2 ^ 40 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 216 * 2 ^ 40 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 216 ≤ 2 ^ 40 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 184 - 1) + 2 ^ 200 + (2 ^ 40 - 1) * 2 ^ 216 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - -theorem initializeSlot0CardinalityInsertWord_eq (w : UInt256) : - UInt256.lor - (UInt256.mul initializeSlot0ObservationCardinalityEventWord - (UInt256.shiftLeft ⟨1⟩ ⟨200⟩)) - (UInt256.land initializeSlot0TickClearMask w) = - UInt256.ofNat (w.toNat % 2 ^ 184 + 2 ^ 200 + w.toNat / 2 ^ 216 * 2 ^ 216) := by - apply u256_inj - rw [u256_lor_toNat, u256_mul_toNat, u256_land_toNat] - rw [initializeSlot0TickClearMask_toNat] - rw [nat_land_comm] - rw [initializeNatLandClearMiddle w.toNat 184 216 w.val.isLt (by norm_num) (by norm_num)] - have hclearLt : w.toNat % 2 ^ 184 + w.toNat / 2 ^ 216 * 2 ^ 216 < - UInt256.size := by - rw [← initializeNatLandClearMiddle w.toNat 184 216 w.val.isLt (by norm_num) - (by norm_num)] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [UInt256.size]) - rw [Nat.mod_eq_of_lt hclearLt] - rw [show initializeSlot0ObservationCardinalityEventWord.toNat = 1 by native_decide] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨200⟩).toNat = 2 ^ 200 by - native_decide] - have hmulLt : 1 * 2 ^ 200 < UInt256.size := by norm_num [UInt256.size] - rw [Nat.mod_eq_of_lt hmulLt] - rw [nat_lor_comm] - rw [initializeNatLorPackedGap _ 1 184 200 16 216] - rw [show 1 * 2 ^ 200 = 2 ^ 200 by ring] - rw [ulit_toNat' _ (initializeSlot0CardinalityInsertWord_nat_lt w)] - exact Nat.mod_eq_of_lt (initializeSlot0CardinalityInsertWord_nat_lt w) - · norm_num - · norm_num - · norm_num - · norm_num - -theorem initializeSlot0CardinalityNextInsertWord_nat_lt (w : UInt256) : - w.toNat % 2 ^ 216 + 2 ^ 216 + w.toNat / 2 ^ 232 * 2 ^ 232 < UInt256.size := by - have hlow : w.toNat % 2 ^ 216 ≤ 2 ^ 216 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 232 < 2 ^ 24 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 232 * 2 ^ 24 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 232 ≤ 2 ^ 24 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 216 - 1) + 2 ^ 216 + (2 ^ 24 - 1) * 2 ^ 232 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - -theorem initializeSlot0CardinalityNextInsertWord_eq (w : UInt256) : - UInt256.lor - (UInt256.mul initializeSlot0ObservationCardinalityNextEventWord - (UInt256.shiftLeft ⟨1⟩ ⟨216⟩)) - (UInt256.land (UInt256.lnot (UInt256.shiftLeft ⟨65535⟩ ⟨216⟩)) w) = - UInt256.ofNat (w.toNat % 2 ^ 216 + 2 ^ 216 + w.toNat / 2 ^ 232 * 2 ^ 232) := by - apply u256_inj - rw [u256_lor_toNat, u256_mul_toNat, u256_land_toNat] - rw [initializeSlot0CardinalityNextClearMask_toNat] - rw [nat_land_comm] - rw [initializeNatLandClearMiddle w.toNat 216 232 w.val.isLt (by norm_num) (by norm_num)] - have hclearLt : w.toNat % 2 ^ 216 + w.toNat / 2 ^ 232 * 2 ^ 232 < - UInt256.size := by - rw [← initializeNatLandClearMiddle w.toNat 216 232 w.val.isLt (by norm_num) - (by norm_num)] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [UInt256.size]) - rw [Nat.mod_eq_of_lt hclearLt] - rw [show initializeSlot0ObservationCardinalityNextEventWord.toNat = 1 by native_decide] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨216⟩).toNat = 2 ^ 216 by - native_decide] - have hmulLt : 1 * 2 ^ 216 < UInt256.size := by norm_num [UInt256.size] - rw [Nat.mod_eq_of_lt hmulLt] - rw [nat_lor_comm] - rw [initializeNatLorPackedMiddle _ 1 216 16 232] - rw [show 1 * 2 ^ 216 = 2 ^ 216 by ring] - rw [ulit_toNat' _ (initializeSlot0CardinalityNextInsertWord_nat_lt w)] - exact Nat.mod_eq_of_lt (initializeSlot0CardinalityNextInsertWord_nat_lt w) - · norm_num - · norm_num - · norm_num - -theorem initializeSlot0UnlockedInsertWord_nat_lt (w : UInt256) : - w.toNat % 2 ^ 232 + 2 ^ 240 + w.toNat / 2 ^ 248 * 2 ^ 248 < UInt256.size := by - have hlow : w.toNat % 2 ^ 232 ≤ 2 ^ 232 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 248 < 2 ^ 8 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 248 * 2 ^ 8 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 248 ≤ 2 ^ 8 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 232 - 1) + 2 ^ 240 + (2 ^ 8 - 1) * 2 ^ 248 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - -theorem initializeSlot0UnlockedInsertWord_eq (w : UInt256) : - UInt256.lor - (UInt256.land initializeSlot0UnlockedClearMask w) - (UInt256.shiftLeft ⟨1⟩ ⟨240⟩) = - UInt256.ofNat (w.toNat % 2 ^ 232 + 2 ^ 240 + w.toNat / 2 ^ 248 * 2 ^ 248) := by - apply u256_inj - rw [u256_lor_toNat, u256_land_toNat] - rw [initializeSlot0UnlockedClearMask_toNat] - rw [nat_land_comm] - rw [initializeNatLandClearMiddle w.toNat 232 248 w.val.isLt (by norm_num) (by norm_num)] - have hclearLt : w.toNat % 2 ^ 232 + w.toNat / 2 ^ 248 * 2 ^ 248 < - UInt256.size := by - rw [← initializeNatLandClearMiddle w.toNat 232 248 w.val.isLt (by norm_num) - (by norm_num)] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [UInt256.size]) - rw [Nat.mod_eq_of_lt hclearLt] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨240⟩).toNat = 2 ^ 240 by - native_decide] - rw [show 2 ^ 240 = 1 * 2 ^ 240 by ring] - rw [initializeNatLorPackedGap _ 1 232 240 8 248] - rw [show 1 * 2 ^ 240 = 2 ^ 240 by ring] - rw [ulit_toNat' _ (initializeSlot0UnlockedInsertWord_nat_lt w)] - exact Nat.mod_eq_of_lt (initializeSlot0UnlockedInsertWord_nat_lt w) - · norm_num - · norm_num - · norm_num - · norm_num - -theorem initializeSlot0ObservationIndexThenCardinalityWord_eq (w : UInt256) : - let wi := UInt256.ofNat (w.toNat % 2 ^ 184 + w.toNat / 2 ^ 200 * 2 ^ 200) - UInt256.ofNat (wi.toNat % 2 ^ 200 + 2 ^ 200 + wi.toNat / 2 ^ 216 * 2 ^ 216) = - UInt256.ofNat (w.toNat % 2 ^ 184 + 2 ^ 200 + w.toNat / 2 ^ 216 * 2 ^ 216) := by - intro wi - apply u256_inj - have hwiLt : w.toNat % 2 ^ 184 + w.toNat / 2 ^ 200 * 2 ^ 200 < UInt256.size := by - have hlow : w.toNat % 2 ^ 184 ≤ 2 ^ 184 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 200 < 2 ^ 56 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 200 * 2 ^ 56 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 200 ≤ 2 ^ 56 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 184 - 1) + (2 ^ 56 - 1) * 2 ^ 200 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - rw [ulit_toNat' _ hwiLt] - have hmod200 : - (w.toNat % 2 ^ 184 + w.toNat / 2 ^ 200 * 2 ^ 200) % 2 ^ 200 = - w.toNat % 2 ^ 184 := by - rw [Nat.add_mul_mod_self_right] - exact Nat.mod_eq_of_lt (lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 184)) - (by norm_num : 2 ^ 184 < 2 ^ 200)) - rw [hmod200] - have hdiv216 : - (w.toNat % 2 ^ 184 + w.toNat / 2 ^ 200 * 2 ^ 200) / 2 ^ 216 = - w.toNat / 2 ^ 216 := by - omega - rw [hdiv216] - -theorem initializeSlot0FeeProtocolThenUnlockedWord_eq (w : UInt256) : - let wf := UInt256.ofNat (w.toNat % 2 ^ 232 + w.toNat / 2 ^ 240 * 2 ^ 240) - UInt256.ofNat (wf.toNat % 2 ^ 240 + 2 ^ 240 + wf.toNat / 2 ^ 248 * 2 ^ 248) = - UInt256.ofNat (w.toNat % 2 ^ 232 + 2 ^ 240 + w.toNat / 2 ^ 248 * 2 ^ 248) := by - intro wf - apply u256_inj - have hwfLt : w.toNat % 2 ^ 232 + w.toNat / 2 ^ 240 * 2 ^ 240 < UInt256.size := by - have hlow : w.toNat % 2 ^ 232 ≤ 2 ^ 232 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 240 < 2 ^ 16 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 240 * 2 ^ 16 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 240 ≤ 2 ^ 16 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 232 - 1) + (2 ^ 16 - 1) * 2 ^ 240 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - omega - rw [ulit_toNat' _ hwfLt] - have hmod240 : - (w.toNat % 2 ^ 232 + w.toNat / 2 ^ 240 * 2 ^ 240) % 2 ^ 240 = - w.toNat % 2 ^ 232 := by - rw [Nat.add_mul_mod_self_right] - exact Nat.mod_eq_of_lt (lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 232)) - (by norm_num : 2 ^ 232 < 2 ^ 240)) - rw [hmod240] - have hdiv248 : - (w.toNat % 2 ^ 232 + w.toNat / 2 ^ 240 * 2 ^ 240) / 2 ^ 248 = - w.toNat / 2 ^ 248 := by - omega - rw [hdiv248] - -set_option maxHeartbeats 1000000 in -theorem initializeSlot0SstoreWord_eq_sourceFinal_present - (evm : EVM.State) (I : ExecutionEnv) (hEnv : evm.executionEnv = I) - {acc : Account} (hacc : evm.accountMap.find? I.codeOwner = some acc) : - let evm1 := initializeSlot0AfterSqrtPriceX96State evm I - let evm2 := initializeSlot0AfterTickState evm1 I - let evm3 := initializeSlot0AfterObservationIndexState evm2 - let evm4 := initializeSlot0AfterObservationCardinalityState evm3 - let evm5 := initializeSlot0AfterObservationCardinalityNextState evm4 - let evm6 := initializeSlot0AfterFeeProtocolState evm5 - initializeSlot0SstoreWord evm.accountMap I (initializeArgWord I) (getTickEstimatedWord I) = - initializeSlot0UnlockedTrueSlotWord evm6 := by - intro evm1 evm2 evm3 evm4 evm5 evm6 - subst I - let w1 := initializeSlot0SlotWithSqrt evm.accountMap evm.executionEnv - (initializeArgWord evm.executionEnv) - have hstate1 : evm1 = Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ w1 := by - apply Option.some.inj - rw [← storageLocStore_initializeSlot0_sqrtPriceX96 evm evm.executionEnv] - simpa [w1] using - storageLocStore_initializeSlot0_sqrtPriceX96_packed evm evm.executionEnv rfl - have hload1 : Solm.EVM.storageLoad evm1 evm1.executionEnv.codeOwner ⟨0⟩ = w1 := by - rw [hstate1] - simpa [storageStore_executionEnv] using - storageLoad_storageStore_same_present evm evm.executionEnv.codeOwner hacc ⟨0⟩ w1 - have hacc1 : - evm1.accountMap.find? evm1.executionEnv.codeOwner = - some (Account.updateStorage acc ⟨0⟩ w1) := by - rw [hstate1] - simpa [storageStore_executionEnv] using storageStore_find?_codeOwner_same evm ⟨0⟩ w1 hacc - have hword2 : initializeSlot0TickSlotWord evm1 evm.executionEnv = - UInt256.ofNat (w1.toNat % 2 ^ 160 + - (getTickEstimatedWord evm.executionEnv).toNat % 2 ^ 24 * 2 ^ 160 + - w1.toNat / 2 ^ 184 * 2 ^ 184) := by - simp [initializeSlot0TickSlotWord, hload1] - have hstate2 : evm2 = Solm.EVM.storageStore evm1 evm1.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0TickSlotWord evm1 evm.executionEnv) := by - apply Option.some.inj - rw [← storageLocStore_initializeSlot0_tick evm1 evm.executionEnv] - exact storageLocStore_initializeSlot0_tick_packed evm1 evm.executionEnv - have hload2 : Solm.EVM.storageLoad evm2 evm2.executionEnv.codeOwner ⟨0⟩ = - initializeSlot0TickSlotWord evm1 evm.executionEnv := by - rw [hstate2] - simpa [storageStore_executionEnv] using - storageLoad_storageStore_same_present evm1 evm1.executionEnv.codeOwner hacc1 ⟨0⟩ - (initializeSlot0TickSlotWord evm1 evm.executionEnv) - have hacc2 : evm2.accountMap.find? evm2.executionEnv.codeOwner = - some (Account.updateStorage (Account.updateStorage acc ⟨0⟩ w1) ⟨0⟩ - (initializeSlot0TickSlotWord evm1 evm.executionEnv)) := by - rw [hstate2] - simpa [storageStore_executionEnv] using - storageStore_find?_codeOwner_same evm1 ⟨0⟩ - (initializeSlot0TickSlotWord evm1 evm.executionEnv) hacc1 - have hword3 : initializeSlot0ObservationIndexSlotWord evm2 = - UInt256.ofNat ((initializeSlot0TickSlotWord evm1 evm.executionEnv).toNat % 2 ^ 184 + - (initializeSlot0TickSlotWord evm1 evm.executionEnv).toNat / 2 ^ 200 * 2 ^ 200) := by - simp [initializeSlot0ObservationIndexSlotWord, hload2] - have hstate3 : evm3 = Solm.EVM.storageStore evm2 evm2.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0ObservationIndexSlotWord evm2) := by - apply Option.some.inj - rw [← storageLocStore_initializeSlot0_observationIndex evm2] - exact storageLocStore_initializeSlot0_observationIndex_packed evm2 - have hload3 : Solm.EVM.storageLoad evm3 evm3.executionEnv.codeOwner ⟨0⟩ = - initializeSlot0ObservationIndexSlotWord evm2 := by - rw [hstate3] - simpa [storageStore_executionEnv] using - storageLoad_storageStore_same_present evm2 evm2.executionEnv.codeOwner hacc2 ⟨0⟩ - (initializeSlot0ObservationIndexSlotWord evm2) - have hacc3 : evm3.accountMap.find? evm3.executionEnv.codeOwner = - some (Account.updateStorage - (Account.updateStorage (Account.updateStorage acc ⟨0⟩ w1) ⟨0⟩ - (initializeSlot0TickSlotWord evm1 evm.executionEnv)) ⟨0⟩ - (initializeSlot0ObservationIndexSlotWord evm2)) := by - rw [hstate3] - simpa [storageStore_executionEnv] using - storageStore_find?_codeOwner_same evm2 ⟨0⟩ - (initializeSlot0ObservationIndexSlotWord evm2) hacc2 - have hword4 : initializeSlot0ObservationCardinalitySlotWord evm3 = - UInt256.ofNat ((initializeSlot0TickSlotWord evm1 evm.executionEnv).toNat % 2 ^ 184 + - 2 ^ 200 + (initializeSlot0TickSlotWord evm1 evm.executionEnv).toNat / 2 ^ 216 * - 2 ^ 216) := by - rw [show initializeSlot0ObservationCardinalitySlotWord evm3 = - UInt256.ofNat ((initializeSlot0ObservationIndexSlotWord evm2).toNat % 2 ^ 200 + - 2 ^ 200 + (initializeSlot0ObservationIndexSlotWord evm2).toNat / 2 ^ 216 * - 2 ^ 216) by - simp [initializeSlot0ObservationCardinalitySlotWord, hload3]] - rw [hword3] - exact initializeSlot0ObservationIndexThenCardinalityWord_eq - (initializeSlot0TickSlotWord evm1 evm.executionEnv) - have hstate4 : evm4 = Solm.EVM.storageStore evm3 evm3.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0ObservationCardinalitySlotWord evm3) := by - apply Option.some.inj - rw [← storageLocStore_initializeSlot0_observationCardinality evm3] - exact storageLocStore_initializeSlot0_observationCardinality_packed evm3 - have hload4 : Solm.EVM.storageLoad evm4 evm4.executionEnv.codeOwner ⟨0⟩ = - initializeSlot0ObservationCardinalitySlotWord evm3 := by - rw [hstate4] - simpa [storageStore_executionEnv] using - storageLoad_storageStore_same_present evm3 evm3.executionEnv.codeOwner hacc3 ⟨0⟩ - (initializeSlot0ObservationCardinalitySlotWord evm3) - have hacc4 : evm4.accountMap.find? evm4.executionEnv.codeOwner = - some (Account.updateStorage - (Account.updateStorage - (Account.updateStorage (Account.updateStorage acc ⟨0⟩ w1) ⟨0⟩ - (initializeSlot0TickSlotWord evm1 evm.executionEnv)) ⟨0⟩ - (initializeSlot0ObservationIndexSlotWord evm2)) ⟨0⟩ - (initializeSlot0ObservationCardinalitySlotWord evm3)) := by - rw [hstate4] - simpa [storageStore_executionEnv] using - storageStore_find?_codeOwner_same evm3 ⟨0⟩ - (initializeSlot0ObservationCardinalitySlotWord evm3) hacc3 - have hword5 : initializeSlot0ObservationCardinalityNextSlotWord evm4 = - UInt256.ofNat ((initializeSlot0ObservationCardinalitySlotWord evm3).toNat % 2 ^ 216 + - 2 ^ 216 + (initializeSlot0ObservationCardinalitySlotWord evm3).toNat / 2 ^ 232 * - 2 ^ 232) := by - simp [initializeSlot0ObservationCardinalityNextSlotWord, hload4] - have hstate5 : evm5 = Solm.EVM.storageStore evm4 evm4.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0ObservationCardinalityNextSlotWord evm4) := by - apply Option.some.inj - rw [← storageLocStore_initializeSlot0_observationCardinalityNext evm4] - exact storageLocStore_initializeSlot0_observationCardinalityNext_packed evm4 - have hload5 : Solm.EVM.storageLoad evm5 evm5.executionEnv.codeOwner ⟨0⟩ = - initializeSlot0ObservationCardinalityNextSlotWord evm4 := by - rw [hstate5] - simpa [storageStore_executionEnv] using - storageLoad_storageStore_same_present evm4 evm4.executionEnv.codeOwner hacc4 ⟨0⟩ - (initializeSlot0ObservationCardinalityNextSlotWord evm4) - have hacc5 : evm5.accountMap.find? evm5.executionEnv.codeOwner = - some (Account.updateStorage - (Account.updateStorage - (Account.updateStorage - (Account.updateStorage (Account.updateStorage acc ⟨0⟩ w1) ⟨0⟩ - (initializeSlot0TickSlotWord evm1 evm.executionEnv)) ⟨0⟩ - (initializeSlot0ObservationIndexSlotWord evm2)) ⟨0⟩ - (initializeSlot0ObservationCardinalitySlotWord evm3)) ⟨0⟩ - (initializeSlot0ObservationCardinalityNextSlotWord evm4)) := by - rw [hstate5] - simpa [storageStore_executionEnv] using - storageStore_find?_codeOwner_same evm4 ⟨0⟩ - (initializeSlot0ObservationCardinalityNextSlotWord evm4) hacc4 - have hword6 : initializeSlot0FeeProtocolSlotWord evm5 = - UInt256.ofNat ((initializeSlot0ObservationCardinalityNextSlotWord evm4).toNat % 2 ^ 232 + - (initializeSlot0ObservationCardinalityNextSlotWord evm4).toNat / 2 ^ 240 * - 2 ^ 240) := by - simp [initializeSlot0FeeProtocolSlotWord, hload5] - have hstate6 : evm6 = Solm.EVM.storageStore evm5 evm5.executionEnv.codeOwner ⟨0⟩ - (initializeSlot0FeeProtocolSlotWord evm5) := by - apply Option.some.inj - rw [← storageLocStore_initializeSlot0_feeProtocol evm5] - exact storageLocStore_initializeSlot0_feeProtocol_packed evm5 - have hload6 : Solm.EVM.storageLoad evm6 evm6.executionEnv.codeOwner ⟨0⟩ = - initializeSlot0FeeProtocolSlotWord evm5 := by - rw [hstate6] - simpa [storageStore_executionEnv] using - storageLoad_storageStore_same_present evm5 evm5.executionEnv.codeOwner hacc5 ⟨0⟩ - (initializeSlot0FeeProtocolSlotWord evm5) - have hfinalWord : initializeSlot0UnlockedTrueSlotWord evm6 = - UInt256.ofNat ((initializeSlot0ObservationCardinalityNextSlotWord evm4).toNat % 2 ^ 232 + - 2 ^ 240 + (initializeSlot0ObservationCardinalityNextSlotWord evm4).toNat / 2 ^ 248 * - 2 ^ 248) := by - rw [show initializeSlot0UnlockedTrueSlotWord evm6 = - UInt256.ofNat ((initializeSlot0FeeProtocolSlotWord evm5).toNat % 2 ^ 240 + - 2 ^ 240 + (initializeSlot0FeeProtocolSlotWord evm5).toNat / 2 ^ 248 * - 2 ^ 248) by - simp [initializeSlot0UnlockedTrueSlotWord, hload6]] - rw [hword6] - exact initializeSlot0FeeProtocolThenUnlockedWord_eq - (initializeSlot0ObservationCardinalityNextSlotWord evm4) - dsimp [initializeSlot0SstoreWord, initializeSlot0SlotWithSqrt, w1] - rw [show UInt256.lor - (UInt256.mul - (UInt256.land (UInt256.signextend ⟨2⟩ - (initializeSlot0TickEventWord (getTickEstimatedWord evm.executionEnv))) ⟨16777215⟩) - (UInt256.shiftLeft ⟨1⟩ ⟨160⟩)) - (UInt256.land (UInt256.lnot (UInt256.shiftLeft ⟨16777215⟩ ⟨160⟩)) - (UInt256.lor (initializeSlot0SqrtEventWord (initializeArgWord evm.executionEnv)) - (UInt256.land (codeOwnerStorageWord evm.executionEnv evm.accountMap ⟨0⟩) - (UInt256.lnot solcAddrMask)))) = - initializeSlot0TickSlotWord evm1 evm.executionEnv by - rw [initializeSlot0TickInsertWord_eq] - exact hword2.symm] - rw [show UInt256.lor - (UInt256.mul initializeSlot0ObservationCardinalityEventWord - (UInt256.shiftLeft ⟨1⟩ ⟨200⟩)) - (UInt256.land initializeSlot0TickClearMask - (initializeSlot0TickSlotWord evm1 evm.executionEnv)) = - initializeSlot0ObservationCardinalitySlotWord evm3 by - rw [initializeSlot0CardinalityInsertWord_eq] - exact hword4.symm] - rw [show UInt256.lor - (UInt256.mul initializeSlot0ObservationCardinalityNextEventWord - (UInt256.shiftLeft ⟨1⟩ ⟨216⟩)) - (UInt256.land (UInt256.lnot (UInt256.shiftLeft ⟨65535⟩ ⟨216⟩)) - (initializeSlot0ObservationCardinalitySlotWord evm3)) = - initializeSlot0ObservationCardinalityNextSlotWord evm4 by - rw [initializeSlot0CardinalityNextInsertWord_eq] - exact hword5.symm] - rw [show UInt256.lor - (UInt256.land initializeSlot0UnlockedClearMask - (initializeSlot0ObservationCardinalityNextSlotWord evm4)) - (UInt256.shiftLeft ⟨1⟩ ⟨240⟩) = initializeSlot0UnlockedTrueSlotWord evm6 by - rw [initializeSlot0UnlockedInsertWord_eq] - exact hfinalWord.symm] - -set_option maxHeartbeats 1000000 in -theorem initializeSlot0AfterAllState_accountMapEquiv - {evm : EVM.State} {σ : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ evm.accountMap) (hEnv : evm.executionEnv = I) : - accountMapEquiv - (sstoreAccountMap I.codeOwner σ ⟨0⟩ - (initializeSlot0SstoreWord σ I (initializeArgWord I) (getTickEstimatedWord I))) - (initializeSlot0AfterAllState evm I).accountMap := by - by_cases hmissing : σ.find? I.codeOwner = none - · have hmissingSolm : evm.accountMap.find? I.codeOwner = none := - accountMapEquiv_find?_none hAccounts hmissing - rw [sstoreAccountMap_absent_same hmissing] - have hseq := initializeSlot0AfterAllState_accountMapEquiv_sourceSequence evm I hEnv - have hsource : accountMapEquiv evm.accountMap - (initializeSlot0AfterAllState evm I).accountMap := by - simpa [sstoreAccountMap_absent_same hmissingSolm] using hseq - exact hAccounts.trans hsource - · cases hfind : σ.find? I.codeOwner with - | none => exact False.elim (hmissing hfind) - | some _accE => - obtain ⟨_accS, hfindS⟩ := accountMapEquiv_find?_some_exists hAccounts hfind - have hwordTransport : - initializeSlot0SstoreWord σ I (initializeArgWord I) (getTickEstimatedWord I) = - initializeSlot0SstoreWord evm.accountMap I (initializeArgWord I) - (getTickEstimatedWord I) := by - exact initializeSlot0SstoreWord_accountMapEquiv hAccounts - have hwordFinal := initializeSlot0SstoreWord_eq_sourceFinal_present evm I hEnv hfindS - rw [hwordTransport, hwordFinal] - let evm1 := initializeSlot0AfterSqrtPriceX96State evm I - let evm2 := initializeSlot0AfterTickState evm1 I - let evm3 := initializeSlot0AfterObservationIndexState evm2 - let evm4 := initializeSlot0AfterObservationCardinalityState evm3 - let evm5 := initializeSlot0AfterObservationCardinalityNextState evm4 - let evm6 := initializeSlot0AfterFeeProtocolState evm5 - let w1 := initializeSlot0SlotWithSqrt evm.accountMap I (initializeArgWord I) - let w2 := initializeSlot0TickSlotWord evm1 I - let w3 := initializeSlot0ObservationIndexSlotWord evm2 - let w4 := initializeSlot0ObservationCardinalitySlotWord evm3 - let w5 := initializeSlot0ObservationCardinalityNextSlotWord evm4 - let w6 := initializeSlot0FeeProtocolSlotWord evm5 - let final := initializeSlot0UnlockedTrueSlotWord evm6 - have hbase : accountMapEquiv - (sstoreAccountMap I.codeOwner σ ⟨0⟩ final) - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ final) := by - exact accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ final hAccounts - have h1 : accountMapEquiv - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ final) - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ final) := by - exact accountMapEquiv_sstoreAccountMap_self_update evm.accountMap I.codeOwner ⟨0⟩ - w1 final - have h2 : accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ final) - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ w2) ⟨0⟩ - final) := by - exact accountMapEquiv_sstoreAccountMap_self_update - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) I.codeOwner ⟨0⟩ w2 final - have h3 : accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ w2) ⟨0⟩ - final) - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ w2) ⟨0⟩ - w3) ⟨0⟩ final) := by - exact accountMapEquiv_sstoreAccountMap_self_update - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ w2) I.codeOwner - ⟨0⟩ w3 final - have h4 : accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ w2) ⟨0⟩ - w3) ⟨0⟩ final) - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ w2) ⟨0⟩ - w3) ⟨0⟩ w4) ⟨0⟩ final) := by - exact accountMapEquiv_sstoreAccountMap_self_update - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ w2) ⟨0⟩ w3) - I.codeOwner ⟨0⟩ w4 final - have h5 : accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ w2) ⟨0⟩ - w3) ⟨0⟩ w4) ⟨0⟩ final) - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ w2) ⟨0⟩ - w3) ⟨0⟩ w4) ⟨0⟩ w5) ⟨0⟩ final) := by - exact accountMapEquiv_sstoreAccountMap_self_update - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ w2) ⟨0⟩ w3) - ⟨0⟩ w4) I.codeOwner ⟨0⟩ w5 final - have h6 : accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ w2) ⟨0⟩ - w3) ⟨0⟩ w4) ⟨0⟩ w5) ⟨0⟩ final) - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ w2) ⟨0⟩ - w3) ⟨0⟩ w4) ⟨0⟩ w5) ⟨0⟩ w6) ⟨0⟩ final) := by - exact accountMapEquiv_sstoreAccountMap_self_update - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner evm.accountMap ⟨0⟩ w1) ⟨0⟩ w2) ⟨0⟩ w3) - ⟨0⟩ w4) ⟨0⟩ w5) I.codeOwner ⟨0⟩ w6 final - have hcollapse := h1.trans (h2.trans (h3.trans (h4.trans (h5.trans h6)))) - have hseq := initializeSlot0AfterAllState_accountMapEquiv_sourceSequence evm I hEnv - exact hbase.trans (hcollapse.trans (by - simpa [evm1, evm2, evm3, evm4, evm5, evm6, w1, w2, w3, w4, w5, w6, final] - using hseq)) - -theorem initializeSourceAfterStorageTailState_accountMapEquiv - {cA : Batteries.RBSet AccountAddress compare} {gh : BlockHeader} {bl : ProcessedBlocks} - {σ_evm σ_solm σ₀ : AccountMap} {A : Substate} {I : ExecutionEnv} {g : Sat256} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ (initializeObservationSstoreWord σ_evm I)) - ⟨0⟩ - (initializeSlot0SstoreWord - (sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ (initializeObservationSstoreWord σ_evm I)) - I (initializeArgWord I) (getTickEstimatedWord I))) - (initializeSourceAfterStorageTailState - (initState cA gh bl σ_solm σ₀ g A I) I).accountMap := by - let evm0 := initState cA gh bl σ_solm σ₀ g A I - let evmObs := initializeObservationAfterAllState evm0 I - have hObs : accountMapEquiv - (sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ (initializeObservationSstoreWord σ_evm I)) - evmObs.accountMap := by - simpa [evmObs, evm0] using - initializeObservationAfterAllState_accountMapEquiv - (cA := cA) (gh := gh) (bl := bl) (σ_evm := σ_evm) (σ_solm := σ_solm) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hAccounts - have hEnvObs : evmObs.executionEnv = I := by - simp [evmObs, evm0, initializeObservationAfterAllState_executionEnv, initState] - have hSlot := initializeSlot0AfterAllState_accountMapEquiv (evm := evmObs) - (σ := sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ (initializeObservationSstoreWord σ_evm I)) - (I := I) hObs hEnvObs - simpa [initializeSourceAfterStorageTailState, evmObs, evm0] using hSlot - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSourceSuccess.lean b/Benchmarks/UniswapV3Pool/InitializeSourceSuccess.lean deleted file mode 100644 index 8bee49bc..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeSourceSuccess.lean +++ /dev/null @@ -1,1892 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeSuccess - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def initializeObservationEvaledRef (field : Ident) : EvaledStorageRef := - { base := "observations", steps := [.aindex (.int 0), .field field] } - -theorem evalStorageRef_initializeObservation {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (field : Ident) : - evalStorageRef (config v) { contract := contract v, locals := initializeStore I } evm - (observationsF (.intLit 0) field) = .ok (initializeObservationEvaledRef field) := by - simp [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, observationsF, - initializeObservationEvaledRef, valueToKey?, EvalResult.bind, EvalResult.ofOption, bind, pure, - contract, storageDecls, storageTypeAt?, evalExpr?] - -theorem initializeObservationBase_zero : observationBase (.int 0) = (⟨8⟩ : UInt256) := by - unfold observationBase keyValueToWord EVM.wordOfInt - apply u256_inj - rfl - -abbrev initializeTimeValue (I : ExecutionEnv) : Value := - .int (Int.ofNat (initializeObservationTimestampWord I).toNat) - -abbrev initializeTickValue (I : ExecutionEnv) : Value := - wordToElem (.int int24Int) (getTickEstimatedWord I) - -abbrev initializeStoreWithTick (I : ExecutionEnv) : Store := - (initializeStore I).insert "tick" (initializeTickValue I) - -abbrev initializeStoreWithTickAndTime (I : ExecutionEnv) : Store := - (initializeStoreWithTick I).insert "time" (initializeTimeValue I) - -def getTickSourceRatioNat (I : ExecutionEnv) : Nat := - ((initializeArgWord I).toNat * 2 ^ (32 : Nat)) % EVM.wordModulus - -def getTickSourceRatioValue (I : ExecutionEnv) : Value := - .int (getTickSourceRatioNat I) - -abbrev getTickSourceMsbValue : Value := - .int 0 - -def getTickStoreWithRatio (I : ExecutionEnv) : Store := - (initializeStore I).insert "ratio" (getTickSourceRatioValue I) - -def getTickStoreWithR (I : ExecutionEnv) : Store := - (getTickStoreWithRatio I).insert "r" (getTickSourceRatioValue I) - -def getTickStoreWithMsb (I : ExecutionEnv) : Store := - (getTickStoreWithR I).insert "msb" getTickSourceMsbValue - -theorem evalExpr_getTick_sourceRatio {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := initializeStore I } evm - (shlE (.var "sqrtPriceX96") shift32) = .ok (getTickSourceRatioValue I) := by - unfold shlE shift32 getTickSourceRatioValue - simp only [evalExpr?, uniswapV3PoolInitializeEvalSqrtPriceVar, EvalResult.bind, bind, - pure, evalBinaryOp?] - rw [if_pos] - · rw [if_neg] - · rw [show Int.toNat 32 = 32 by native_decide] - rfl - · norm_num - · constructor - · exact Int.natCast_nonneg _ - · constructor - · exact Int.ofNat_lt.mpr (initializeArgWord I).val.isLt - · norm_num [EVM.wordModulus] - -theorem getTickSourceRatioNat_lt_wordModulus (I : ExecutionEnv) : - getTickSourceRatioNat I < EVM.wordModulus := by - exact Nat.mod_lt _ (by native_decide) - -theorem getTickStoreWithRatio_ratio (I : ExecutionEnv) : - (getTickStoreWithRatio I).get? "ratio" = some (getTickSourceRatioValue I) := - store_get_self (initializeStore I) "ratio" (getTickSourceRatioValue I) - -theorem evalExpr_getTick_ratioVar {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreWithRatio I } - evm (.var "ratio") = .ok (getTickSourceRatioValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreWithRatio_ratio] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourcePrefix {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) - (hlo : 4295128739 ≤ (initializeArgWord I).toNat) - (hhi : (initializeArgWord I).toNat < - 1461446703485210103287273052203988822378723970342) : - ExecBlock (config v) { contract := contract v, locals := initializeStore I } evm - [ .require (andE (geE (.var "sqrtPriceX96") minSqrtRatio) - (ltE (.var "sqrtPriceX96") maxSqrtRatio)), - .letDecl "ratio" (some uint256) (shlE (.var "sqrtPriceX96") shift32), - .letDecl "r" (some uint256) (.var "ratio"), - .letDecl "msb" (some uint256) (.intLit 0) ] - (.ok { contract := contract v, locals := getTickStoreWithMsb I } evm) := by - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (uniswapV3PoolGetTickAtSqrtRatioEvalRangeTrue (v := v) (evm := evm) (I := I) - hlo hhi)) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl (evalExpr_getTick_sourceRatio evm I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.letDecl (evalExpr_getTick_ratioVar evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.letDecl (by simp [evalExpr?, getTickSourceMsbValue, pure])) - ExecBlock.nil - -def getTickSourceRatioGt7 (I : ExecutionEnv) : Bool := - decide (getTickSourceRatioNat I > 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) - -def getTickSourceMsbF7Nat (I : ExecutionEnv) : Nat := - if getTickSourceRatioGt7 I then 2 ^ (7 : Nat) else 0 - -def getTickSourceMsbF7Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbF7Nat I) - -def getTickStoreAfterF7Let (I : ExecutionEnv) : Store := - (getTickStoreWithMsb I).insert "f" (getTickSourceMsbF7Value I) - -def getTickSourceMsbAfter7Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbF7Nat I) - -def getTickStoreAfterMsb7 (I : ExecutionEnv) : Store := - (getTickStoreAfterF7Let I).insert "msb" (getTickSourceMsbAfter7Value I) - -def getTickSourceRAfterMsb7Nat (I : ExecutionEnv) : Nat := - getTickSourceRatioNat I / 2 ^ getTickSourceMsbF7Nat I - -def getTickSourceRAfterMsb7Value (I : ExecutionEnv) : Value := - .int (getTickSourceRAfterMsb7Nat I) - -def getTickStoreAfterMsbStep7 (I : ExecutionEnv) : Store := - (getTickStoreAfterMsb7 I).insert "r" (getTickSourceRAfterMsb7Value I) - -theorem getTickStoreWithMsb_r (I : ExecutionEnv) : - (getTickStoreWithMsb I).get? "r" = some (getTickSourceRatioValue I) := by - rw [getTickStoreWithMsb] - rw [store_get_ne (getTickStoreWithR I) (k := "msb") (a := "r") - getTickSourceMsbValue (by decide)] - rw [getTickStoreWithR, store_get_self] - -theorem getTickStoreWithMsb_msb (I : ExecutionEnv) : - (getTickStoreWithMsb I).get? "msb" = some getTickSourceMsbValue := by - rw [getTickStoreWithMsb, store_get_self] - -theorem evalExpr_getTick_rVar_withMsb {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreWithMsb I } - evm (.var "r") = .ok (getTickSourceRatioValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreWithMsb_r] - -theorem evalExpr_getTick_msbVar_withMsb {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreWithMsb I } - evm (.var "msb") = .ok getTickSourceMsbValue := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreWithMsb_msb] - -theorem evalBinaryOp_getTick_ratioGt7 (I : ExecutionEnv) : - evalBinaryOp? .gt (getTickSourceRatioValue I) - (.int 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) = - .ok (.bool (getTickSourceRatioGt7 I)) := by - unfold getTickSourceRatioValue getTickSourceRatioGt7 - simp only [evalBinaryOp?] - by_cases h : getTickSourceRatioNat I > 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - · have hInt : ((getTickSourceRatioNat I : Nat) : Int) > - (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF : Int) := by omega - rw [decide_eq_true hInt, decide_eq_true h] - · have hInt : ¬(((getTickSourceRatioNat I : Nat) : Int) > - (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF : Int)) := by omega - rw [decide_eq_false hInt, decide_eq_false h] - -theorem evalExpr_getTick_msbF7 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - (.ite (gtE (.var "r") (.intLit 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) - (.intLit (2 ^ (7 : Nat))) (.intLit 0)) = - .ok (getTickSourceMsbF7Value I) := by - unfold gtE getTickSourceMsbF7Value getTickSourceMsbF7Nat - simp only [evalExpr?, evalExpr_getTick_rVar_withMsb, EvalResult.bind, bind, pure] - rw [evalBinaryOp_getTick_ratioGt7] - cases getTickSourceRatioGt7 I <;> rfl - -theorem getTickSourceMsbF7Nat_le_128 (I : ExecutionEnv) : - getTickSourceMsbF7Nat I ≤ 128 := by - unfold getTickSourceMsbF7Nat - split <;> norm_num - -theorem getTickStoreAfterF7Let_msb (I : ExecutionEnv) : - (getTickStoreAfterF7Let I).get? "msb" = some getTickSourceMsbValue := by - rw [getTickStoreAfterF7Let] - rw [store_get_ne (getTickStoreWithMsb I) (k := "f") (a := "msb") - (getTickSourceMsbF7Value I) (by decide)] - rw [getTickStoreWithMsb, store_get_self] - -theorem getTickStoreAfterF7Let_f (I : ExecutionEnv) : - (getTickStoreAfterF7Let I).get? "f" = some (getTickSourceMsbF7Value I) := by - rw [getTickStoreAfterF7Let, store_get_self] - -theorem evalExpr_getTick_msb_add_f7 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterF7Let I } evm - (addE (.var "msb") (.var "f")) = .ok (getTickSourceMsbAfter7Value I) := by - unfold addE getTickSourceMsbAfter7Value - simp only [evalExpr?, EvalResult.ofOption, getTickStoreAfterF7Let_msb, - getTickStoreAfterF7Let_f, getTickSourceMsbValue, getTickSourceMsbF7Value, - EvalResult.bind, bind, evalBinaryOp?] - simp - -theorem assignStorageRef_getTick_msb_afterF7 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterF7Let I } - evm .localVar (varRef "msb") (getTickSourceMsbAfter7Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsb7 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterF7Let_msb] - simp [getTickStoreAfterMsb7, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem getTickStoreAfterMsb7_r (I : ExecutionEnv) : - (getTickStoreAfterMsb7 I).get? "r" = some (getTickSourceRatioValue I) := by - rw [getTickStoreAfterMsb7] - rw [store_get_ne (getTickStoreAfterF7Let I) (k := "msb") (a := "r") - (getTickSourceMsbAfter7Value I) (by decide)] - rw [getTickStoreAfterF7Let] - rw [store_get_ne (getTickStoreWithMsb I) (k := "f") (a := "r") - (getTickSourceMsbF7Value I) (by decide)] - exact getTickStoreWithMsb_r I - -theorem getTickStoreAfterMsb7_f (I : ExecutionEnv) : - (getTickStoreAfterMsb7 I).get? "f" = some (getTickSourceMsbF7Value I) := by - rw [getTickStoreAfterMsb7] - rw [store_get_ne (getTickStoreAfterF7Let I) (k := "msb") (a := "f") - (getTickSourceMsbAfter7Value I) (by decide)] - exact getTickStoreAfterF7Let_f I - -theorem evalExpr_getTick_rVar_afterMsb7 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb7 I } - evm (.var "r") = .ok (getTickSourceRatioValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb7_r] - -theorem evalExpr_getTick_fVar_afterMsb7 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb7 I } - evm (.var "f") = .ok (getTickSourceMsbF7Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb7_f] - --- LIBRARY CANDIDATE: generic successful evaluation for Solm integer `SHR`. -theorem evalBinaryOp_int_shr_ok {x s : Int} - (hx0 : 0 ≤ x) (hxlt : x < (EVM.wordModulus : Int)) - (hs0 : 0 ≤ s) (hslt : s < 256) : - evalBinaryOp? .shr (.int x) (.int s) = .ok (.int (x.toNat / 2 ^ s.toNat)) := by - simp only [evalBinaryOp?] - rw [if_pos ⟨hx0, hxlt, hs0⟩] - rw [if_neg (not_le.mpr hslt)] - -theorem intOfNat_toNat_div_pow (n s : Nat) : - (Int.ofNat n).toNat / 2 ^ (Int.ofNat s).toNat = n / 2 ^ s := by - rfl - -theorem intOfNat_toNat_div_pow_cast (n s : Nat) : - ((Int.ofNat n).toNat / 2 ^ (Int.ofNat s).toNat : Int) = - (n / 2 ^ s : Nat) := by - rfl - -theorem evalExpr_getTick_r_shr_f7 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb7 I } evm - (shrE (.var "r") (.var "f")) = .ok (getTickSourceRAfterMsb7Value I) := by - unfold shrE - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsb7, - evalExpr_getTick_fVar_afterMsb7, EvalResult.bind, bind] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceRatioNat I))) - (.int (Int.ofNat (getTickSourceMsbF7Nat I))) = - .ok (getTickSourceRAfterMsb7Value I) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceRAfterMsb7Value getTickSourceRAfterMsb7Nat - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceRatioNat_lt_wordModulus I) - · exact Int.natCast_nonneg _ - · have hle := getTickSourceMsbF7Nat_le_128 I - have hltNat : getTickSourceMsbF7Nat I < 256 := by omega - exact Int.ofNat_lt.mpr hltNat - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep7Prefix {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) - (.intLit (2 ^ (7 : Nat))) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")) ] - (.ok { contract := contract v, locals := getTickStoreAfterMsb7 I } evm) := by - refine ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_msbF7 evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_msb_add_f7 evm I) - (assignStorageRef_getTick_msb_afterF7 evm I)) - ExecBlock.nil - -theorem assignStorageRef_getTick_r_afterF7 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterMsb7 I } - evm .localVar (varRef "r") (getTickSourceRAfterMsb7Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsbStep7 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterMsb7_r] - simp [getTickStoreAfterMsbStep7, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep7 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - (msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep7 I } evm) := by - change ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) - (.intLit (2 ^ (7 : Nat))) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - .assign .localVar (varRef "r") (shrE (.var "r") (.var "f")) ] - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep7 I } evm) - refine ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_msbF7 evm I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_msb_add_f7 evm I) - (assignStorageRef_getTick_msb_afterF7 evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_r_shr_f7 evm I) - (assignStorageRef_getTick_r_afterF7 evm I)) - ExecBlock.nil - -def getTickSourceRAfterMsb7Gt6 (I : ExecutionEnv) : Bool := - decide (getTickSourceRAfterMsb7Nat I > 0xFFFFFFFFFFFFFFFF) - -def getTickSourceMsbF6Nat (I : ExecutionEnv) : Nat := - if getTickSourceRAfterMsb7Gt6 I then 2 ^ (6 : Nat) else 0 - -def getTickSourceMsbF6Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbF6Nat I) - -def getTickStoreAfterF6Let (I : ExecutionEnv) : Store := - (getTickStoreAfterMsbStep7 I).insert "f" (getTickSourceMsbF6Value I) - -def getTickSourceMsbAfter6Nat (I : ExecutionEnv) : Nat := - getTickSourceMsbF7Nat I + getTickSourceMsbF6Nat I - -def getTickSourceMsbAfter6Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbAfter6Nat I) - -def getTickStoreAfterMsb6 (I : ExecutionEnv) : Store := - (getTickStoreAfterF6Let I).insert "msb" (getTickSourceMsbAfter6Value I) - -def getTickSourceRAfterMsb6Nat (I : ExecutionEnv) : Nat := - getTickSourceRAfterMsb7Nat I / 2 ^ getTickSourceMsbF6Nat I - -def getTickSourceRAfterMsb6Value (I : ExecutionEnv) : Value := - .int (getTickSourceRAfterMsb6Nat I) - -def getTickStoreAfterMsbStep6 (I : ExecutionEnv) : Store := - (getTickStoreAfterMsb6 I).insert "r" (getTickSourceRAfterMsb6Value I) - -theorem getTickSourceRAfterMsb7Nat_lt_wordModulus (I : ExecutionEnv) : - getTickSourceRAfterMsb7Nat I < EVM.wordModulus := by - unfold getTickSourceRAfterMsb7Nat - exact lt_of_le_of_lt (Nat.div_le_self _ _) (getTickSourceRatioNat_lt_wordModulus I) - -theorem getTickStoreAfterMsb7_msb (I : ExecutionEnv) : - (getTickStoreAfterMsb7 I).get? "msb" = some (getTickSourceMsbAfter7Value I) := by - rw [getTickStoreAfterMsb7, store_get_self] - -theorem getTickStoreAfterMsbStep7_r (I : ExecutionEnv) : - (getTickStoreAfterMsbStep7 I).get? "r" = - some (getTickSourceRAfterMsb7Value I) := by - rw [getTickStoreAfterMsbStep7, store_get_self] - -theorem getTickStoreAfterMsbStep7_msb (I : ExecutionEnv) : - (getTickStoreAfterMsbStep7 I).get? "msb" = - some (getTickSourceMsbAfter7Value I) := by - rw [getTickStoreAfterMsbStep7] - rw [store_get_ne (getTickStoreAfterMsb7 I) (k := "r") (a := "msb") - (getTickSourceRAfterMsb7Value I) (by decide)] - exact getTickStoreAfterMsb7_msb I - -theorem evalExpr_getTick_rVar_afterMsbStep7 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep7 I } - evm (.var "r") = .ok (getTickSourceRAfterMsb7Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbStep7_r] - -theorem evalExpr_getTick_msbVar_afterMsbStep7 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep7 I } - evm (.var "msb") = .ok (getTickSourceMsbAfter7Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbStep7_msb] - -theorem evalBinaryOp_getTick_rAfter7Gt6 (I : ExecutionEnv) : - evalBinaryOp? .gt (getTickSourceRAfterMsb7Value I) - (.int 0xFFFFFFFFFFFFFFFF) = - .ok (.bool (getTickSourceRAfterMsb7Gt6 I)) := by - unfold getTickSourceRAfterMsb7Value getTickSourceRAfterMsb7Gt6 - simp only [evalBinaryOp?] - by_cases h : getTickSourceRAfterMsb7Nat I > 0xFFFFFFFFFFFFFFFF - · have hInt : ((getTickSourceRAfterMsb7Nat I : Nat) : Int) > - (0xFFFFFFFFFFFFFFFF : Int) := by omega - rw [decide_eq_true hInt, decide_eq_true h] - · have hInt : ¬(((getTickSourceRAfterMsb7Nat I : Nat) : Int) > - (0xFFFFFFFFFFFFFFFF : Int)) := by omega - rw [decide_eq_false hInt, decide_eq_false h] - -theorem evalExpr_getTick_msbF6 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep7 I } evm - (.ite (gtE (.var "r") (.intLit 0xFFFFFFFFFFFFFFFF)) - (.intLit (2 ^ (6 : Nat))) (.intLit 0)) = - .ok (getTickSourceMsbF6Value I) := by - unfold gtE getTickSourceMsbF6Value getTickSourceMsbF6Nat - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsbStep7, EvalResult.bind, bind, pure] - rw [evalBinaryOp_getTick_rAfter7Gt6] - cases getTickSourceRAfterMsb7Gt6 I <;> rfl - -theorem getTickSourceMsbF6Nat_le_64 (I : ExecutionEnv) : - getTickSourceMsbF6Nat I ≤ 64 := by - unfold getTickSourceMsbF6Nat - split <;> norm_num - -theorem getTickStoreAfterF6Let_msb (I : ExecutionEnv) : - (getTickStoreAfterF6Let I).get? "msb" = some (getTickSourceMsbAfter7Value I) := by - rw [getTickStoreAfterF6Let] - rw [store_get_ne (getTickStoreAfterMsbStep7 I) (k := "f") (a := "msb") - (getTickSourceMsbF6Value I) (by decide)] - exact getTickStoreAfterMsbStep7_msb I - -theorem getTickStoreAfterF6Let_f (I : ExecutionEnv) : - (getTickStoreAfterF6Let I).get? "f" = some (getTickSourceMsbF6Value I) := by - rw [getTickStoreAfterF6Let, store_get_self] - -theorem evalExpr_getTick_msb_add_f6 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterF6Let I } evm - (addE (.var "msb") (.var "f")) = .ok (getTickSourceMsbAfter6Value I) := by - unfold addE getTickSourceMsbAfter6Value - getTickSourceMsbAfter6Nat - simp only [evalExpr?, EvalResult.ofOption, getTickStoreAfterF6Let_msb, - getTickStoreAfterF6Let_f, getTickSourceMsbAfter7Value, getTickSourceMsbF6Value, - EvalResult.bind, bind, evalBinaryOp?] - rw [(Nat.cast_add (getTickSourceMsbF7Nat I) (getTickSourceMsbF6Nat I)).symm] - -theorem assignStorageRef_getTick_msb_afterF6 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterF6Let I } - evm .localVar (varRef "msb") (getTickSourceMsbAfter6Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsb6 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterF6Let_msb] - simp [getTickStoreAfterMsb6, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem getTickStoreAfterMsb6_r (I : ExecutionEnv) : - (getTickStoreAfterMsb6 I).get? "r" = some (getTickSourceRAfterMsb7Value I) := by - rw [getTickStoreAfterMsb6] - rw [store_get_ne (getTickStoreAfterF6Let I) (k := "msb") (a := "r") - (getTickSourceMsbAfter6Value I) (by decide)] - rw [getTickStoreAfterF6Let] - rw [store_get_ne (getTickStoreAfterMsbStep7 I) (k := "f") (a := "r") - (getTickSourceMsbF6Value I) (by decide)] - exact getTickStoreAfterMsbStep7_r I - -theorem getTickStoreAfterMsb6_f (I : ExecutionEnv) : - (getTickStoreAfterMsb6 I).get? "f" = some (getTickSourceMsbF6Value I) := by - rw [getTickStoreAfterMsb6] - rw [store_get_ne (getTickStoreAfterF6Let I) (k := "msb") (a := "f") - (getTickSourceMsbAfter6Value I) (by decide)] - exact getTickStoreAfterF6Let_f I - -theorem evalExpr_getTick_rVar_afterMsb6 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb6 I } - evm (.var "r") = .ok (getTickSourceRAfterMsb7Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb6_r] - -theorem evalExpr_getTick_fVar_afterMsb6 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb6 I } - evm (.var "f") = .ok (getTickSourceMsbF6Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb6_f] - -theorem evalExpr_getTick_r_shr_f6 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb6 I } evm - (shrE (.var "r") (.var "f")) = .ok (getTickSourceRAfterMsb6Value I) := by - unfold shrE - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsb6, - evalExpr_getTick_fVar_afterMsb6, EvalResult.bind, bind] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceRAfterMsb7Nat I))) - (.int (Int.ofNat (getTickSourceMsbF6Nat I))) = - .ok (getTickSourceRAfterMsb6Value I) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceRAfterMsb6Value getTickSourceRAfterMsb6Nat - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceRAfterMsb7Nat_lt_wordModulus I) - · exact Int.natCast_nonneg _ - · have hle := getTickSourceMsbF6Nat_le_64 I - have hltNat : getTickSourceMsbF6Nat I < 256 := by omega - exact Int.ofNat_lt.mpr hltNat - -theorem assignStorageRef_getTick_r_afterF6 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterMsb6 I } - evm .localVar (varRef "r") (getTickSourceRAfterMsb6Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsbStep6 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterMsb6_r] - simp [getTickStoreAfterMsbStep6, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep6 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterMsbStep7 I } evm - (msbStep 6 0xFFFFFFFFFFFFFFFF) - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep6 I } evm) := by - change ExecBlock (config v) - { contract := contract v, locals := getTickStoreAfterMsbStep7 I } evm - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0xFFFFFFFFFFFFFFFF)) - (.intLit (2 ^ (6 : Nat))) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - .assign .localVar (varRef "r") (shrE (.var "r") (.var "f")) ] - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep6 I } evm) - refine ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_msbF6 evm I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_msb_add_f6 evm I) - (assignStorageRef_getTick_msb_afterF6 evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_r_shr_f6 evm I) - (assignStorageRef_getTick_r_afterF6 evm I)) - ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps76 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - (msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF) - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep6 I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep7 evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep6 evm I) - -def getTickSourceRAfterMsb6Gt5 (I : ExecutionEnv) : Bool := - decide (getTickSourceRAfterMsb6Nat I > 0xFFFFFFFF) - -def getTickSourceMsbF5Nat (I : ExecutionEnv) : Nat := - if getTickSourceRAfterMsb6Gt5 I then 2 ^ (5 : Nat) else 0 - -def getTickSourceMsbF5Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbF5Nat I) - -def getTickStoreAfterF5Let (I : ExecutionEnv) : Store := - (getTickStoreAfterMsbStep6 I).insert "f" (getTickSourceMsbF5Value I) - -def getTickSourceMsbAfter5Nat (I : ExecutionEnv) : Nat := - getTickSourceMsbAfter6Nat I + getTickSourceMsbF5Nat I - -def getTickSourceMsbAfter5Value (I : ExecutionEnv) : Value := - .int (getTickSourceMsbAfter5Nat I) - -def getTickStoreAfterMsb5 (I : ExecutionEnv) : Store := - (getTickStoreAfterF5Let I).insert "msb" (getTickSourceMsbAfter5Value I) - -def getTickSourceRAfterMsb5Nat (I : ExecutionEnv) : Nat := - getTickSourceRAfterMsb6Nat I / 2 ^ getTickSourceMsbF5Nat I - -def getTickSourceRAfterMsb5Value (I : ExecutionEnv) : Value := - .int (getTickSourceRAfterMsb5Nat I) - -def getTickStoreAfterMsbStep5 (I : ExecutionEnv) : Store := - (getTickStoreAfterMsb5 I).insert "r" (getTickSourceRAfterMsb5Value I) - -theorem getTickSourceRAfterMsb6Nat_lt_wordModulus (I : ExecutionEnv) : - getTickSourceRAfterMsb6Nat I < EVM.wordModulus := by - unfold getTickSourceRAfterMsb6Nat - exact lt_of_le_of_lt (Nat.div_le_self _ _) (getTickSourceRAfterMsb7Nat_lt_wordModulus I) - -theorem getTickStoreAfterMsb6_msb (I : ExecutionEnv) : - (getTickStoreAfterMsb6 I).get? "msb" = some (getTickSourceMsbAfter6Value I) := by - rw [getTickStoreAfterMsb6, store_get_self] - -theorem getTickStoreAfterMsbStep6_r (I : ExecutionEnv) : - (getTickStoreAfterMsbStep6 I).get? "r" = - some (getTickSourceRAfterMsb6Value I) := by - rw [getTickStoreAfterMsbStep6, store_get_self] - -theorem getTickStoreAfterMsbStep6_msb (I : ExecutionEnv) : - (getTickStoreAfterMsbStep6 I).get? "msb" = - some (getTickSourceMsbAfter6Value I) := by - rw [getTickStoreAfterMsbStep6] - rw [store_get_ne (getTickStoreAfterMsb6 I) (k := "r") (a := "msb") - (getTickSourceRAfterMsb6Value I) (by decide)] - exact getTickStoreAfterMsb6_msb I - -theorem evalExpr_getTick_rVar_afterMsbStep6 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep6 I } - evm (.var "r") = .ok (getTickSourceRAfterMsb6Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbStep6_r] - -theorem evalExpr_getTick_msbVar_afterMsbStep6 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep6 I } - evm (.var "msb") = .ok (getTickSourceMsbAfter6Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsbStep6_msb] - -theorem evalBinaryOp_getTick_rAfter6Gt5 (I : ExecutionEnv) : - evalBinaryOp? .gt (getTickSourceRAfterMsb6Value I) - (.int 0xFFFFFFFF) = - .ok (.bool (getTickSourceRAfterMsb6Gt5 I)) := by - unfold getTickSourceRAfterMsb6Value getTickSourceRAfterMsb6Gt5 - simp only [evalBinaryOp?] - by_cases h : getTickSourceRAfterMsb6Nat I > 0xFFFFFFFF - · have hInt : ((getTickSourceRAfterMsb6Nat I : Nat) : Int) > - (0xFFFFFFFF : Int) := by omega - rw [decide_eq_true hInt, decide_eq_true h] - · have hInt : ¬(((getTickSourceRAfterMsb6Nat I : Nat) : Int) > - (0xFFFFFFFF : Int)) := by omega - rw [decide_eq_false hInt, decide_eq_false h] - -theorem evalExpr_getTick_msbF5 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsbStep6 I } evm - (.ite (gtE (.var "r") (.intLit 0xFFFFFFFF)) - (.intLit (2 ^ (5 : Nat))) (.intLit 0)) = - .ok (getTickSourceMsbF5Value I) := by - unfold gtE getTickSourceMsbF5Value getTickSourceMsbF5Nat - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsbStep6, EvalResult.bind, bind, pure] - rw [evalBinaryOp_getTick_rAfter6Gt5] - cases getTickSourceRAfterMsb6Gt5 I <;> rfl - -theorem getTickSourceMsbF5Nat_le_32 (I : ExecutionEnv) : - getTickSourceMsbF5Nat I ≤ 32 := by - unfold getTickSourceMsbF5Nat - split <;> norm_num - -theorem getTickStoreAfterF5Let_msb (I : ExecutionEnv) : - (getTickStoreAfterF5Let I).get? "msb" = some (getTickSourceMsbAfter6Value I) := by - rw [getTickStoreAfterF5Let] - rw [store_get_ne (getTickStoreAfterMsbStep6 I) (k := "f") (a := "msb") - (getTickSourceMsbF5Value I) (by decide)] - exact getTickStoreAfterMsbStep6_msb I - -theorem getTickStoreAfterF5Let_f (I : ExecutionEnv) : - (getTickStoreAfterF5Let I).get? "f" = some (getTickSourceMsbF5Value I) := by - rw [getTickStoreAfterF5Let, store_get_self] - -theorem evalExpr_getTick_msb_add_f5 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterF5Let I } evm - (addE (.var "msb") (.var "f")) = .ok (getTickSourceMsbAfter5Value I) := by - unfold addE getTickSourceMsbAfter5Value - getTickSourceMsbAfter5Nat - simp only [evalExpr?, EvalResult.ofOption, getTickStoreAfterF5Let_msb, - getTickStoreAfterF5Let_f, getTickSourceMsbAfter6Value, getTickSourceMsbF5Value, - EvalResult.bind, bind, evalBinaryOp?] - rw [(Nat.cast_add (getTickSourceMsbAfter6Nat I) (getTickSourceMsbF5Nat I)).symm] - -theorem assignStorageRef_getTick_msb_afterF5 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterF5Let I } - evm .localVar (varRef "msb") (getTickSourceMsbAfter5Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsb5 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterF5Let_msb] - simp [getTickStoreAfterMsb5, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem getTickStoreAfterMsb5_r (I : ExecutionEnv) : - (getTickStoreAfterMsb5 I).get? "r" = some (getTickSourceRAfterMsb6Value I) := by - rw [getTickStoreAfterMsb5] - rw [store_get_ne (getTickStoreAfterF5Let I) (k := "msb") (a := "r") - (getTickSourceMsbAfter5Value I) (by decide)] - rw [getTickStoreAfterF5Let] - rw [store_get_ne (getTickStoreAfterMsbStep6 I) (k := "f") (a := "r") - (getTickSourceMsbF5Value I) (by decide)] - exact getTickStoreAfterMsbStep6_r I - -theorem getTickStoreAfterMsb5_f (I : ExecutionEnv) : - (getTickStoreAfterMsb5 I).get? "f" = some (getTickSourceMsbF5Value I) := by - rw [getTickStoreAfterMsb5] - rw [store_get_ne (getTickStoreAfterF5Let I) (k := "msb") (a := "f") - (getTickSourceMsbAfter5Value I) (by decide)] - exact getTickStoreAfterF5Let_f I - -theorem evalExpr_getTick_rVar_afterMsb5 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb5 I } - evm (.var "r") = .ok (getTickSourceRAfterMsb6Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb5_r] - -theorem evalExpr_getTick_fVar_afterMsb5 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb5 I } - evm (.var "f") = .ok (getTickSourceMsbF5Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [getTickStoreAfterMsb5_f] - -theorem evalExpr_getTick_r_shr_f5 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := getTickStoreAfterMsb5 I } evm - (shrE (.var "r") (.var "f")) = .ok (getTickSourceRAfterMsb5Value I) := by - unfold shrE - simp only [evalExpr?, evalExpr_getTick_rVar_afterMsb5, - evalExpr_getTick_fVar_afterMsb5, EvalResult.bind, bind] - change evalBinaryOp? .shr (.int (Int.ofNat (getTickSourceRAfterMsb6Nat I))) - (.int (Int.ofNat (getTickSourceMsbF5Nat I))) = - .ok (getTickSourceRAfterMsb5Value I) - rw [evalBinaryOp_int_shr_ok] - · unfold getTickSourceRAfterMsb5Value getTickSourceRAfterMsb5Nat - rw [intOfNat_toNat_div_pow_cast] - · exact Int.natCast_nonneg _ - · exact Int.ofNat_lt.mpr (getTickSourceRAfterMsb6Nat_lt_wordModulus I) - · exact Int.natCast_nonneg _ - · have hle := getTickSourceMsbF5Nat_le_32 I - have hltNat : getTickSourceMsbF5Nat I < 256 := by omega - exact Int.ofNat_lt.mpr hltNat - -theorem assignStorageRef_getTick_r_afterF5 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - assignStorageRef? (config v) { contract := contract v, locals := getTickStoreAfterMsb5 I } - evm .localVar (varRef "r") (getTickSourceRAfterMsb5Value I) = - .ok ({ contract := contract v, locals := getTickStoreAfterMsbStep5 I }, evm) := by - rw [assignStorageRef?] - rw [varRef] - rw [getTickStoreAfterMsb5_r] - simp [getTickStoreAfterMsbStep5, updateLocalPath?, pure, bind, EvalResult.bind] - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep5 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreAfterMsbStep6 I } evm - (msbStep 5 0xFFFFFFFF) - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep5 I } evm) := by - change ExecBlock (config v) - { contract := contract v, locals := getTickStoreAfterMsbStep6 I } evm - [ .letDecl "f" (some uint256) - (.ite (gtE (.var "r") (.intLit 0xFFFFFFFF)) - (.intLit (2 ^ (5 : Nat))) (.intLit 0)), - .assign .localVar (varRef "msb") (addE (.var "msb") (.var "f")), - .assign .localVar (varRef "r") (shrE (.var "r") (.var "f")) ] - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep5 I } evm) - refine ExecBlock.consNormal (ExecStmt.letDecl (evalExpr_getTick_msbF5 evm I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_msb_add_f5 evm I) - (assignStorageRef_getTick_msb_afterF5 evm I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (evalExpr_getTick_r_shr_f5 evm I) - (assignStorageRef_getTick_r_afterF5 evm I)) - ExecBlock.nil - -theorem uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps765 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := getTickStoreWithMsb I } evm - (msbStep 7 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ++ - msbStep 6 0xFFFFFFFFFFFFFFFF ++ - msbStep 5 0xFFFFFFFF) - (.ok { contract := contract v, locals := getTickStoreAfterMsbStep5 I } evm) := by - exact execBlock_append (uniswapV3PoolGetTickAtSqrtRatioSourceMsbSteps76 evm I) - (uniswapV3PoolGetTickAtSqrtRatioSourceMsbStep5 evm I) - -def initializeObservationBlockTimestampLoc : StorageLoc := - loc ⟨8⟩ ⟨0, by decide⟩ ⟨4, by decide⟩ (by decide) (.int uint32Int) - -def initializeObservationTimestampSlotWord (evm : EVM.State) (I : ExecutionEnv) : UInt256 := - UInt256.lor (initializeObservationTimestampWord I) - (UInt256.land (UInt256.lnot (⟨4294967295⟩ : UInt256)) - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩)) - -def initializeObservationAfterTimestampState (evm : EVM.State) (I : ExecutionEnv) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨8⟩ - (initializeObservationTimestampSlotWord evm I) - -def initializeObservationTickCumulativeLoc : StorageLoc := - loc ⟨8⟩ ⟨4, by decide⟩ ⟨7, by decide⟩ (by decide) (.int int56Int) - -def initializeObservationAfterTickWord (evm : EVM.State) : UInt256 := - UInt256.ofNat - ((Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩).toNat % 2 ^ 32 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩).toNat / 2 ^ 88 * 2 ^ 88) - -def initializeObservationAfterTickState (evm : EVM.State) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨8⟩ - (initializeObservationAfterTickWord evm) - -def initializeObservationSecondsPerLiquidityLoc : StorageLoc := - loc ⟨8⟩ ⟨11, by decide⟩ ⟨20, by decide⟩ (by decide) (.int uint160Int) - -def initializeObservationAfterSecondsWord (evm : EVM.State) : UInt256 := - UInt256.ofNat - ((Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩).toNat % 2 ^ 88 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩).toNat / 2 ^ 248 * 2 ^ 248) - -def initializeObservationAfterSecondsState (evm : EVM.State) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨8⟩ - (initializeObservationAfterSecondsWord evm) - -abbrev initializeObservationInitializedLoc : StorageLoc := - { slot := ⟨8⟩, offset := ⟨31, by decide⟩, size := ⟨1, by decide⟩, - hbound := by decide, type := .bool } - -theorem initializeObservationTimestampWord_toNat (I : ExecutionEnv) : - (initializeObservationTimestampWord I).toNat = - (UInt256.ofNat I.header.timestamp).toNat % 2 ^ 32 := by - unfold initializeObservationTimestampWord - rw [u256_land_toNat] - have hmask32 : (⟨4294967295⟩ : UInt256).toNat = 2 ^ 32 - 1 := by native_decide - rw [hmask32, nat_land_comm, nat_land_mask_eq_mod] - rw [Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 32)) (by norm_num [UInt256.size]))] - -theorem evalExpr_initializeTime {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) - (hEnv : evm.executionEnv = I) : - evalExpr? (config v) { contract := contract v, locals := initializeStore I } evm - (modE (.env .timestamp) uint32Modulus) = .ok (initializeTimeValue I) := by - unfold modE uint32Modulus initializeTimeValue - simp only [evalExpr?, envValue, EvalResult.bind, bind, pure, evalBinaryOp?] - rw [hEnv] - rw [initializeObservationTimestampWord_toNat] - norm_num - -theorem evalExpr_initializeTimeVar {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm (.var "time") = .ok (initializeTimeValue I) := by - simp [evalExpr?, initializeStoreWithTickAndTime, EvalResult.ofOption] - -theorem evalExpr_initializeTime_withTick {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (hEnv : evm.executionEnv = I) : - evalExpr? (config v) { contract := contract v, locals := initializeStoreWithTick I } evm - (modE (.env .timestamp) uint32Modulus) = .ok (initializeTimeValue I) := by - unfold modE uint32Modulus initializeTimeValue - simp only [evalExpr?, envValue, EvalResult.bind, bind, pure, evalBinaryOp?] - rw [hEnv] - rw [initializeObservationTimestampWord_toNat] - norm_num - -theorem evalStorageRef_initializeObservation_withTickAndTime {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) (field : Ident) : - evalStorageRef (config v) { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm (observationsF (.intLit 0) field) = .ok (initializeObservationEvaledRef field) := by - simp [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, observationsF, - initializeObservationEvaledRef, valueToKey?, EvalResult.bind, EvalResult.ofOption, bind, pure, - contract, storageDecls, storageTypeAt?, evalExpr?] - -theorem initializeObservationTimestampWord_lt_twoPow32 (I : ExecutionEnv) : - (initializeObservationTimestampWord I).toNat < 2 ^ 32 := by - rw [initializeObservationTimestampWord_toNat] - exact Nat.mod_lt _ (by norm_num) - -private theorem initializeObservationLow32_insert_toNat (low old : UInt256) - (hlow : low.toNat < 2 ^ 32) : - (UInt256.lor low (UInt256.land (UInt256.lnot (⟨4294967295⟩ : UInt256)) old)).toNat = - low.toNat + old.toNat / 2 ^ 32 * 2 ^ 32 := by - rw [u256_lor_toNat] - have hclearMask : UInt256.lnot (⟨4294967295⟩ : UInt256) = - UInt256.ofNat ((2 : Nat) ^ 256 - 2 ^ 32) := by - native_decide - have hhigh : - (UInt256.land (UInt256.lnot (⟨4294967295⟩ : UInt256)) old).toNat = - old.toNat / 2 ^ 32 * 2 ^ 32 := by - rw [hclearMask] - exact u256_land_high_mask_toNat old 32 (by norm_num) - have hq : old.toNat / 2 ^ 32 < 2 ^ 224 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 32 * 2 ^ 224 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - simp [UInt256.size] - have hlorLt : - Nat.lor low.toNat - ((UInt256.land (UInt256.lnot (⟨4294967295⟩ : UInt256)) old).toNat) < - UInt256.size := by - rw [hhigh] - rw [nat_lor_shift_add low.toNat (old.toNat / 2 ^ 32) 32 hlow] - have hqle : old.toNat / 2 ^ 32 ≤ 2 ^ 224 - 1 := Nat.le_pred_of_lt hq - have hprod : (old.toNat / 2 ^ 32) * 2 ^ 32 ≤ (2 ^ 224 - 1) * 2 ^ 32 := by - exact Nat.mul_le_mul_right _ hqle - norm_num [UInt256.size, Nat.pow_add] at hprod ⊢ - omega - rw [Nat.mod_eq_of_lt hlorLt] - rw [hhigh] - exact nat_lor_shift_add low.toNat (old.toNat / 2 ^ 32) 32 hlow - -theorem storageLocStore_initializeObservation_timestamp (evm : EVM.State) (I : ExecutionEnv) : - storageLocStore evm initializeObservationBlockTimestampLoc (initializeTimeValue I) = - some (initializeObservationAfterTimestampState evm I) := by - unfold storageLocStore storageLocWriteWord initializeObservationBlockTimestampLoc - initializeObservationAfterTimestampState initializeObservationTimestampSlotWord initializeTimeValue loc - simp only [valueToWord, wordOfInt_ofNat_toNat, bind, Option.bind] - apply congrArg some - apply congrArg (fun w : UInt256 => Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨8⟩ w) - apply u256_inj - rw [initializeObservationLow32_insert_toNat] - · change fromBytes' - (List.take 0 ↑(EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩)) ++ - List.take 4 ↑(EVM.Word.toBytesLEWithSizeProof (initializeObservationTimestampWord I)) ++ - List.drop (0 + 4) ↑(EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩))) = - (initializeObservationTimestampWord I).toNat + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩).toNat / 2 ^ 32 * 2 ^ 32 - rw [List.take_zero, List.nil_append] - rw [fromBytes'_append, fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - simp only [(EVM.Word.toBytesLEWithSizeProof (initializeObservationTimestampWord I)).2, - List.length_take] - rw [show min 4 32 = 4 by norm_num] - rw [show 256 ^ 4 = 2 ^ 32 by norm_num] - rw [Nat.mod_eq_of_lt (initializeObservationTimestampWord_lt_twoPow32 I)] - ring - · exact initializeObservationTimestampWord_lt_twoPow32 I - -theorem assignStorageRef_initializeObservation_blockTimestamp {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - assignStorageRef? (config v) - { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm .storage (observationsF (.intLit 0) "blockTimestamp") (initializeTimeValue I) = - .ok ({ contract := contract v, locals := initializeStoreWithTickAndTime I }, - initializeObservationAfterTimestampState evm I) := by - apply assignStorageRef_storage_scalar_value - (er := initializeObservationEvaledRef "blockTimestamp") - (ty := .elem (.int uint32Int)) - (loc := initializeObservationBlockTimestampLoc) - · simp [observationsF, initializeStoreWithTickAndTime, initializeStoreWithTick, - initializeStore] - · exact evalStorageRef_initializeObservation_withTickAndTime evm I "blockTimestamp" - · simp [contract, storageDecls, storageTypeAt?, initializeObservationEvaledRef, - observationStructTy, uint32St] - native_decide - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - initializeObservationEvaledRef, initializeObservationBlockTimestampLoc, loc, - initializeObservationBase_zero] - · trivial - · exact storageLocStore_initializeObservation_timestamp evm I - -theorem initializeObservationAfterTickWord_nat_lt (evm : EVM.State) : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩).toNat % 2 ^ 32 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩).toNat / 2 ^ 88 * 2 ^ 88 < - UInt256.size := by - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩ - have hlow : w.toNat % 2 ^ 32 ≤ 2 ^ 32 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 88 < 2 ^ 168 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 88 * 2 ^ 168 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 88 ≤ 2 ^ 168 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 32 - 1) + (2 ^ 168 - 1) * 2 ^ 88 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - dsimp [w] at hlow hhigh - omega - -theorem storageLocStore_initializeObservation_tick_zero (evm : EVM.State) : - storageLocStore evm initializeObservationTickCumulativeLoc (.int 0) = - some (initializeObservationAfterTickState evm) := by - unfold storageLocStore storageLocWriteWord initializeObservationTickCumulativeLoc - initializeObservationAfterTickState loc - simp only [valueToWord, EVM.wordOfInt, bind, Option.bind] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner { val := 8 } - show fromBytes' - ((List.take 4 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 7 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0))) ++ - List.drop (4 + 7) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (initializeObservationAfterTickWord evm).toNat - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [show 256 ^ (4 : Nat) = 2 ^ 32 by norm_num [Nat.pow_add]] - rw [show 256 ^ (7 : Nat) = 2 ^ 56 by norm_num [Nat.pow_add]] - rw [show 256 ^ (11 : Nat) = 2 ^ 88 by norm_num [Nat.pow_add]] - have hlen4 : (List.take 4 (EVM.Word.toBytesLEWithSizeProof w).1).length = 4 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - have hlen11 : - (List.take 4 (EVM.Word.toBytesLEWithSizeProof w).1 ++ - List.take 7 (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0)).1).length = 11 := by - rw [List.length_append, hlen4] - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0)).2] - norm_num - rw [hlen4, hlen11] - rw [show (UInt256.ofNat 0).toNat % 2 ^ 56 = 0 by native_decide] - rw [show (initializeObservationAfterTickWord evm).toNat = - w.toNat % 2 ^ 32 + w.toNat / 2 ^ 88 * 2 ^ 88 by - dsimp [initializeObservationAfterTickWord, w] - exact ulit_toNat' _ (initializeObservationAfterTickWord_nat_lt evm)] - ring - -theorem assignStorageRef_initializeObservation_tickCumulative_zero {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - assignStorageRef? (config v) - { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm .storage (observationsF (.intLit 0) "tickCumulative") (.int 0) = - .ok ({ contract := contract v, locals := initializeStoreWithTickAndTime I }, - initializeObservationAfterTickState evm) := by - apply assignStorageRef_storage_scalar_value - (er := initializeObservationEvaledRef "tickCumulative") - (ty := .elem (.int int56Int)) - (loc := initializeObservationTickCumulativeLoc) - · simp [observationsF, initializeStoreWithTickAndTime, initializeStoreWithTick, - initializeStore] - · exact evalStorageRef_initializeObservation_withTickAndTime evm I "tickCumulative" - · simp [contract, storageDecls, storageTypeAt?, initializeObservationEvaledRef, - observationStructTy, int56St] - native_decide - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - initializeObservationEvaledRef, initializeObservationTickCumulativeLoc, loc, - initializeObservationBase_zero] - · trivial - · exact storageLocStore_initializeObservation_tick_zero evm - -theorem initializeObservationAfterSecondsWord_nat_lt (evm : EVM.State) : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩).toNat % 2 ^ 88 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩).toNat / 2 ^ 248 * - 2 ^ 248 < - UInt256.size := by - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨8⟩ - have hlow : w.toNat % 2 ^ 88 ≤ 2 ^ 88 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 248 < 2 ^ 8 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 248 * 2 ^ 8 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 248 ≤ 2 ^ 8 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 88 - 1) + (2 ^ 8 - 1) * 2 ^ 248 < UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - dsimp [w] at hlow hhigh - omega - -theorem storageLocStore_initializeObservation_seconds_zero (evm : EVM.State) : - storageLocStore evm initializeObservationSecondsPerLiquidityLoc (.int 0) = - some (initializeObservationAfterSecondsState evm) := by - unfold storageLocStore storageLocWriteWord initializeObservationSecondsPerLiquidityLoc - initializeObservationAfterSecondsState loc - simp only [valueToWord, EVM.wordOfInt, bind, Option.bind] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner { val := 8 } - show fromBytes' - ((List.take 11 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 20 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0))) ++ - List.drop (11 + 20) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (initializeObservationAfterSecondsWord evm).toNat - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [show 256 ^ (11 : Nat) = 2 ^ 88 by norm_num [Nat.pow_add]] - rw [show 256 ^ (20 : Nat) = 2 ^ 160 by norm_num [Nat.pow_add]] - rw [show 256 ^ (31 : Nat) = 2 ^ 248 by norm_num [Nat.pow_add]] - have hlen11 : (List.take 11 (EVM.Word.toBytesLEWithSizeProof w).1).length = 11 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - have hlen31 : - (List.take 11 (EVM.Word.toBytesLEWithSizeProof w).1 ++ - List.take 20 (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0)).1).length = - 31 := by - rw [List.length_append, hlen11] - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0)).2] - norm_num - rw [hlen11, hlen31] - rw [show (UInt256.ofNat 0).toNat % 2 ^ 160 = 0 by native_decide] - rw [show (initializeObservationAfterSecondsWord evm).toNat = - w.toNat % 2 ^ 88 + w.toNat / 2 ^ 248 * 2 ^ 248 by - dsimp [initializeObservationAfterSecondsWord, w] - exact ulit_toNat' _ (initializeObservationAfterSecondsWord_nat_lt evm)] - ring - -theorem assignStorageRef_initializeObservation_seconds_zero {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - assignStorageRef? (config v) - { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm .storage (observationsF (.intLit 0) "secondsPerLiquidityCumulativeX128") (.int 0) = - .ok ({ contract := contract v, locals := initializeStoreWithTickAndTime I }, - initializeObservationAfterSecondsState evm) := by - apply assignStorageRef_storage_scalar_value - (er := initializeObservationEvaledRef "secondsPerLiquidityCumulativeX128") - (ty := .elem (.int uint160Int)) - (loc := initializeObservationSecondsPerLiquidityLoc) - · simp [observationsF, initializeStoreWithTickAndTime, initializeStoreWithTick, - initializeStore] - · exact evalStorageRef_initializeObservation_withTickAndTime evm I - "secondsPerLiquidityCumulativeX128" - · simp [contract, storageDecls, storageTypeAt?, initializeObservationEvaledRef, - observationStructTy, uint160St] - native_decide - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - initializeObservationEvaledRef, initializeObservationSecondsPerLiquidityLoc, loc, - initializeObservationBase_zero] - · trivial - · exact storageLocStore_initializeObservation_seconds_zero evm - -theorem storageLocStore_initializeObservation_initialized_isSome (evm : EVM.State) : - (storageLocStore evm initializeObservationInitializedLoc (.bool true)).isSome := by - unfold storageLocStore storageLocWriteWord initializeObservationInitializedLoc - simp only [valueToWord, Bool.toUInt256_true, bind, Option.bind, Option.isSome_some] - -noncomputable def initializeObservationAfterInitializedState (evm : EVM.State) : EVM.State := - (storageLocStore evm initializeObservationInitializedLoc (.bool true)).get - (storageLocStore_initializeObservation_initialized_isSome evm) - -theorem storageLocStore_initializeObservation_initialized_true (evm : EVM.State) : - storageLocStore evm initializeObservationInitializedLoc (.bool true) = - some (initializeObservationAfterInitializedState evm) := by - exact (Option.some_get (storageLocStore_initializeObservation_initialized_isSome evm)).symm - -theorem storageLocStore_createdAccounts_of {evm evm' : EVM.State} - {loc : StorageLoc} {value : Value} - (h : storageLocStore evm loc value = some evm') : - evm'.createdAccounts = evm.createdAccounts := by - unfold storageLocStore at h - cases hv : valueToWord value with - | none => simp [hv] at h - | some valueWord => - simp [hv, bind, Option.bind] at h - cases h - simp [storageStore_createdAccounts] - -theorem storageLocStore_executionEnv_of {evm evm' : EVM.State} - {loc : StorageLoc} {value : Value} - (h : storageLocStore evm loc value = some evm') : - evm'.executionEnv = evm.executionEnv := by - unfold storageLocStore at h - cases hv : valueToWord value with - | none => simp [hv] at h - | some valueWord => - simp [hv, bind, Option.bind] at h - cases h - simp [storageStore_executionEnv] - -theorem assignStorageRef_initializeObservation_initialized_true {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - assignStorageRef? (config v) - { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm .storage (observationsF (.intLit 0) "initialized") (.bool true) = - .ok ({ contract := contract v, locals := initializeStoreWithTickAndTime I }, - initializeObservationAfterInitializedState evm) := by - apply assignStorageRef_storage_scalar_value - (er := initializeObservationEvaledRef "initialized") - (ty := .elem .bool) - (loc := initializeObservationInitializedLoc) - · simp [observationsF, initializeStoreWithTickAndTime, initializeStoreWithTick, - initializeStore] - · exact evalStorageRef_initializeObservation_withTickAndTime evm I "initialized" - · simp [contract, storageDecls, storageTypeAt?, initializeObservationEvaledRef, - observationStructTy, boolSt] - native_decide - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - initializeObservationEvaledRef, initializeObservationInitializedLoc, - initializeObservationBase_zero, loc] - · trivial - · exact storageLocStore_initializeObservation_initialized_true evm - -noncomputable def initializeObservationAfterAllState (evm : EVM.State) (I : ExecutionEnv) : - EVM.State := - initializeObservationAfterInitializedState - (initializeObservationAfterSecondsState - (initializeObservationAfterTickState - (initializeObservationAfterTimestampState evm I))) - -theorem uniswapV3PoolInitializeSourceObservationStores {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm - [ .assign .storage (observationsF (.intLit 0) "blockTimestamp") (.var "time"), - .assign .storage (observationsF (.intLit 0) "tickCumulative") (.intLit 0), - .assign .storage (observationsF (.intLit 0) "secondsPerLiquidityCumulativeX128") - (.intLit 0), - .assign .storage (observationsF (.intLit 0) "initialized") (.boolLit true) ] - (.ok { contract := contract v, locals := initializeStoreWithTickAndTime I } - (initializeObservationAfterAllState evm I)) := by - unfold initializeObservationAfterAllState - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_initializeTimeVar evm I) - (assignStorageRef_initializeObservation_blockTimestamp evm I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) - (assignStorageRef_initializeObservation_tickCumulative_zero - (initializeObservationAfterTimestampState evm I) I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) - (assignStorageRef_initializeObservation_seconds_zero - (initializeObservationAfterTickState (initializeObservationAfterTimestampState evm I)) I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) - (assignStorageRef_initializeObservation_initialized_true - (initializeObservationAfterSecondsState - (initializeObservationAfterTickState (initializeObservationAfterTimestampState evm I))) I)) - ExecBlock.nil - -theorem initializeObservationAfterAllState_createdAccounts - (evm : EVM.State) (I : ExecutionEnv) : - (initializeObservationAfterAllState evm I).createdAccounts = evm.createdAccounts := by - unfold initializeObservationAfterAllState - rw [storageLocStore_createdAccounts_of - (storageLocStore_initializeObservation_initialized_true - (initializeObservationAfterSecondsState - (initializeObservationAfterTickState (initializeObservationAfterTimestampState evm I))))] - simp [initializeObservationAfterSecondsState, initializeObservationAfterTickState, - initializeObservationAfterTimestampState, storageStore_createdAccounts] - -theorem initializeObservationAfterAllState_executionEnv - (evm : EVM.State) (I : ExecutionEnv) : - (initializeObservationAfterAllState evm I).executionEnv = evm.executionEnv := by - unfold initializeObservationAfterAllState - rw [storageLocStore_executionEnv_of - (storageLocStore_initializeObservation_initialized_true - (initializeObservationAfterSecondsState - (initializeObservationAfterTickState (initializeObservationAfterTimestampState evm I))))] - simp [initializeObservationAfterSecondsState, initializeObservationAfterTickState, - initializeObservationAfterTimestampState, storageStore_executionEnv] - -theorem uniswapV3PoolInitializeSourceObservationTail {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) (hEnv : evm.executionEnv = I) : - ExecBlock (config v) { contract := contract v, locals := initializeStoreWithTick I } - evm - [ .letDecl "time" (some uint32) (modE (.env .timestamp) uint32Modulus), - .assign .storage (observationsF (.intLit 0) "blockTimestamp") (.var "time"), - .assign .storage (observationsF (.intLit 0) "tickCumulative") (.intLit 0), - .assign .storage (observationsF (.intLit 0) "secondsPerLiquidityCumulativeX128") - (.intLit 0), - .assign .storage (observationsF (.intLit 0) "initialized") (.boolLit true) ] - (.ok { contract := contract v, locals := initializeStoreWithTickAndTime I } - (initializeObservationAfterAllState evm I)) := by - refine ExecBlock.consNormal - (ExecStmt.letDecl (evalExpr_initializeTime_withTick evm I hEnv)) ?_ - exact uniswapV3PoolInitializeSourceObservationStores evm I - -abbrev initializeSlot0SqrtPriceX96Loc : StorageLoc := - loc ⟨0⟩ ⟨0, by decide⟩ ⟨20, by decide⟩ (by decide) (.int uint160Int) - -abbrev initializeSlot0TickLoc : StorageLoc := - loc ⟨0⟩ ⟨20, by decide⟩ ⟨3, by decide⟩ (by decide) (.int int24Int) - -abbrev initializeSlot0ObservationIndexLoc : StorageLoc := - loc ⟨0⟩ ⟨23, by decide⟩ ⟨2, by decide⟩ (by decide) (.int uint16Int) - -abbrev initializeSlot0ObservationCardinalityLoc : StorageLoc := - loc ⟨0⟩ ⟨25, by decide⟩ ⟨2, by decide⟩ (by decide) (.int uint16Int) - -abbrev initializeSlot0ObservationCardinalityNextLoc : StorageLoc := - loc ⟨0⟩ ⟨27, by decide⟩ ⟨2, by decide⟩ (by decide) (.int uint16Int) - -abbrev initializeSlot0FeeProtocolLoc : StorageLoc := - loc ⟨0⟩ ⟨29, by decide⟩ ⟨1, by decide⟩ (by decide) (.int uint8Int) - -abbrev initializeSlot0UnlockedLoc : StorageLoc := - loc ⟨0⟩ ⟨30, by decide⟩ ⟨1, by decide⟩ (by decide) .bool - -private theorem storageLocStore_int_value_isSome (evm : EVM.State) (loc : StorageLoc) - (n : Int) : - (storageLocStore evm loc (.int n)).isSome := by - obtain ⟨evm', h⟩ := storageLocStore_int_some evm loc n - rw [h] - rfl - -theorem storageLocStore_initializeSlot0_sqrtPriceX96_isSome - (evm : EVM.State) (I : ExecutionEnv) : - (storageLocStore evm initializeSlot0SqrtPriceX96Loc (initializeArgValue I)).isSome := by - rw [show initializeArgValue I = .int (Int.ofNat (initializeArgWord I).toNat) by rfl] - exact storageLocStore_int_value_isSome evm initializeSlot0SqrtPriceX96Loc _ - -noncomputable def initializeSlot0AfterSqrtPriceX96State - (evm : EVM.State) (I : ExecutionEnv) : EVM.State := - (storageLocStore evm initializeSlot0SqrtPriceX96Loc (initializeArgValue I)).get - (storageLocStore_initializeSlot0_sqrtPriceX96_isSome evm I) - -theorem storageLocStore_initializeSlot0_sqrtPriceX96 - (evm : EVM.State) (I : ExecutionEnv) : - storageLocStore evm initializeSlot0SqrtPriceX96Loc (initializeArgValue I) = - some (initializeSlot0AfterSqrtPriceX96State evm I) := by - exact (Option.some_get (storageLocStore_initializeSlot0_sqrtPriceX96_isSome evm I)).symm - -theorem initializeSlot0AfterSqrtPriceX96State_createdAccounts - (evm : EVM.State) (I : ExecutionEnv) : - (initializeSlot0AfterSqrtPriceX96State evm I).createdAccounts = - evm.createdAccounts := - storageLocStore_createdAccounts_of (storageLocStore_initializeSlot0_sqrtPriceX96 evm I) - -theorem storageLocStore_initializeSlot0_tick_isSome - (evm : EVM.State) (I : ExecutionEnv) : - (storageLocStore evm initializeSlot0TickLoc (initializeTickValue I)).isSome := by - unfold initializeTickValue wordToElem int24Int - exact storageLocStore_int_value_isSome evm initializeSlot0TickLoc _ - -noncomputable def initializeSlot0AfterTickState - (evm : EVM.State) (I : ExecutionEnv) : EVM.State := - (storageLocStore evm initializeSlot0TickLoc (initializeTickValue I)).get - (storageLocStore_initializeSlot0_tick_isSome evm I) - -theorem storageLocStore_initializeSlot0_tick (evm : EVM.State) (I : ExecutionEnv) : - storageLocStore evm initializeSlot0TickLoc (initializeTickValue I) = - some (initializeSlot0AfterTickState evm I) := by - exact (Option.some_get (storageLocStore_initializeSlot0_tick_isSome evm I)).symm - -theorem initializeSlot0AfterTickState_createdAccounts - (evm : EVM.State) (I : ExecutionEnv) : - (initializeSlot0AfterTickState evm I).createdAccounts = evm.createdAccounts := - storageLocStore_createdAccounts_of (storageLocStore_initializeSlot0_tick evm I) - -theorem storageLocStore_initializeSlot0_observationIndex_isSome (evm : EVM.State) : - (storageLocStore evm initializeSlot0ObservationIndexLoc (.int 0)).isSome := - storageLocStore_int_value_isSome evm initializeSlot0ObservationIndexLoc 0 - -noncomputable def initializeSlot0AfterObservationIndexState - (evm : EVM.State) : EVM.State := - (storageLocStore evm initializeSlot0ObservationIndexLoc (.int 0)).get - (storageLocStore_initializeSlot0_observationIndex_isSome evm) - -theorem storageLocStore_initializeSlot0_observationIndex (evm : EVM.State) : - storageLocStore evm initializeSlot0ObservationIndexLoc (.int 0) = - some (initializeSlot0AfterObservationIndexState evm) := by - exact (Option.some_get (storageLocStore_initializeSlot0_observationIndex_isSome evm)).symm - -theorem initializeSlot0AfterObservationIndexState_createdAccounts - (evm : EVM.State) : - (initializeSlot0AfterObservationIndexState evm).createdAccounts = evm.createdAccounts := - storageLocStore_createdAccounts_of (storageLocStore_initializeSlot0_observationIndex evm) - -theorem storageLocStore_initializeSlot0_observationCardinality_isSome (evm : EVM.State) : - (storageLocStore evm initializeSlot0ObservationCardinalityLoc (.int 1)).isSome := - storageLocStore_int_value_isSome evm initializeSlot0ObservationCardinalityLoc 1 - -noncomputable def initializeSlot0AfterObservationCardinalityState - (evm : EVM.State) : EVM.State := - (storageLocStore evm initializeSlot0ObservationCardinalityLoc (.int 1)).get - (storageLocStore_initializeSlot0_observationCardinality_isSome evm) - -theorem storageLocStore_initializeSlot0_observationCardinality (evm : EVM.State) : - storageLocStore evm initializeSlot0ObservationCardinalityLoc (.int 1) = - some (initializeSlot0AfterObservationCardinalityState evm) := by - exact (Option.some_get - (storageLocStore_initializeSlot0_observationCardinality_isSome evm)).symm - -theorem initializeSlot0AfterObservationCardinalityState_createdAccounts - (evm : EVM.State) : - (initializeSlot0AfterObservationCardinalityState evm).createdAccounts = - evm.createdAccounts := - storageLocStore_createdAccounts_of - (storageLocStore_initializeSlot0_observationCardinality evm) - -theorem storageLocStore_initializeSlot0_observationCardinalityNext_isSome (evm : EVM.State) : - (storageLocStore evm initializeSlot0ObservationCardinalityNextLoc (.int 1)).isSome := - storageLocStore_int_value_isSome evm initializeSlot0ObservationCardinalityNextLoc 1 - -noncomputable def initializeSlot0AfterObservationCardinalityNextState - (evm : EVM.State) : EVM.State := - (storageLocStore evm initializeSlot0ObservationCardinalityNextLoc (.int 1)).get - (storageLocStore_initializeSlot0_observationCardinalityNext_isSome evm) - -theorem storageLocStore_initializeSlot0_observationCardinalityNext (evm : EVM.State) : - storageLocStore evm initializeSlot0ObservationCardinalityNextLoc (.int 1) = - some (initializeSlot0AfterObservationCardinalityNextState evm) := by - exact (Option.some_get - (storageLocStore_initializeSlot0_observationCardinalityNext_isSome evm)).symm - -theorem initializeSlot0AfterObservationCardinalityNextState_createdAccounts - (evm : EVM.State) : - (initializeSlot0AfterObservationCardinalityNextState evm).createdAccounts = - evm.createdAccounts := - storageLocStore_createdAccounts_of - (storageLocStore_initializeSlot0_observationCardinalityNext evm) - -theorem storageLocStore_initializeSlot0_feeProtocol_isSome (evm : EVM.State) : - (storageLocStore evm initializeSlot0FeeProtocolLoc (.int 0)).isSome := - storageLocStore_int_value_isSome evm initializeSlot0FeeProtocolLoc 0 - -noncomputable def initializeSlot0AfterFeeProtocolState (evm : EVM.State) : EVM.State := - (storageLocStore evm initializeSlot0FeeProtocolLoc (.int 0)).get - (storageLocStore_initializeSlot0_feeProtocol_isSome evm) - -theorem storageLocStore_initializeSlot0_feeProtocol (evm : EVM.State) : - storageLocStore evm initializeSlot0FeeProtocolLoc (.int 0) = - some (initializeSlot0AfterFeeProtocolState evm) := by - exact (Option.some_get (storageLocStore_initializeSlot0_feeProtocol_isSome evm)).symm - -theorem initializeSlot0AfterFeeProtocolState_createdAccounts (evm : EVM.State) : - (initializeSlot0AfterFeeProtocolState evm).createdAccounts = evm.createdAccounts := - storageLocStore_createdAccounts_of (storageLocStore_initializeSlot0_feeProtocol evm) - -theorem storageLocStore_initializeSlot0_unlocked_isSome (evm : EVM.State) : - (storageLocStore evm initializeSlot0UnlockedLoc (.bool true)).isSome := by - unfold storageLocStore storageLocWriteWord initializeSlot0UnlockedLoc - simp only [valueToWord, Bool.toUInt256_true, bind, Option.bind, Option.isSome_some] - -noncomputable def initializeSlot0AfterUnlockedState (evm : EVM.State) : EVM.State := - (storageLocStore evm initializeSlot0UnlockedLoc (.bool true)).get - (storageLocStore_initializeSlot0_unlocked_isSome evm) - -theorem storageLocStore_initializeSlot0_unlocked_true (evm : EVM.State) : - storageLocStore evm initializeSlot0UnlockedLoc (.bool true) = - some (initializeSlot0AfterUnlockedState evm) := by - exact (Option.some_get (storageLocStore_initializeSlot0_unlocked_isSome evm)).symm - -theorem initializeSlot0AfterUnlockedState_createdAccounts (evm : EVM.State) : - (initializeSlot0AfterUnlockedState evm).createdAccounts = evm.createdAccounts := - storageLocStore_createdAccounts_of (storageLocStore_initializeSlot0_unlocked_true evm) - -noncomputable def initializeSlot0AfterAllState (evm : EVM.State) (I : ExecutionEnv) : - EVM.State := - initializeSlot0AfterUnlockedState - (initializeSlot0AfterFeeProtocolState - (initializeSlot0AfterObservationCardinalityNextState - (initializeSlot0AfterObservationCardinalityState - (initializeSlot0AfterObservationIndexState - (initializeSlot0AfterTickState - (initializeSlot0AfterSqrtPriceX96State evm I) I))))) - -theorem initializeSlot0AfterAllState_createdAccounts - (evm : EVM.State) (I : ExecutionEnv) : - (initializeSlot0AfterAllState evm I).createdAccounts = evm.createdAccounts := by - unfold initializeSlot0AfterAllState - rw [initializeSlot0AfterUnlockedState_createdAccounts] - rw [initializeSlot0AfterFeeProtocolState_createdAccounts] - rw [initializeSlot0AfterObservationCardinalityNextState_createdAccounts] - rw [initializeSlot0AfterObservationCardinalityState_createdAccounts] - rw [initializeSlot0AfterObservationIndexState_createdAccounts] - rw [initializeSlot0AfterTickState_createdAccounts] - exact initializeSlot0AfterSqrtPriceX96State_createdAccounts evm I - -theorem initializeSlot0AfterAllState_executionEnv - (evm : EVM.State) (I : ExecutionEnv) : - (initializeSlot0AfterAllState evm I).executionEnv = evm.executionEnv := by - unfold initializeSlot0AfterAllState - rw [storageLocStore_executionEnv_of (storageLocStore_initializeSlot0_unlocked_true _)] - rw [storageLocStore_executionEnv_of (storageLocStore_initializeSlot0_feeProtocol _)] - rw [storageLocStore_executionEnv_of - (storageLocStore_initializeSlot0_observationCardinalityNext _)] - rw [storageLocStore_executionEnv_of - (storageLocStore_initializeSlot0_observationCardinality _)] - rw [storageLocStore_executionEnv_of - (storageLocStore_initializeSlot0_observationIndex _)] - rw [storageLocStore_executionEnv_of (storageLocStore_initializeSlot0_tick _ I)] - exact storageLocStore_executionEnv_of (storageLocStore_initializeSlot0_sqrtPriceX96 evm I) - -theorem initializeStoreWithTickAndTime_sqrtPriceX96 (I : ExecutionEnv) : - (initializeStoreWithTickAndTime I).get? "sqrtPriceX96" = - some (initializeArgValue I) := by - rw [initializeStoreWithTickAndTime] - rw [store_get_ne (initializeStoreWithTick I) (initializeTimeValue I) (by decide)] - rw [initializeStoreWithTick] - rw [store_get_ne (initializeStore I) (initializeTickValue I) (by decide)] - exact store_get_self (∅ : Store) "sqrtPriceX96" (initializeArgValue I) - -theorem initializeStoreWithTickAndTime_tick (I : ExecutionEnv) : - (initializeStoreWithTickAndTime I).get? "tick" = some (initializeTickValue I) := by - rw [initializeStoreWithTickAndTime] - rw [store_get_ne (initializeStoreWithTick I) (initializeTimeValue I) (by decide)] - rw [initializeStoreWithTick] - exact store_get_self (initializeStore I) "tick" (initializeTickValue I) - -theorem evalExpr_initializeSqrtPriceVar_withTickAndTime {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm (.var "sqrtPriceX96") = .ok (initializeArgValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [initializeStoreWithTickAndTime_sqrtPriceX96] - -theorem evalExpr_initializeTickVar_withTickAndTime {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm (.var "tick") = .ok (initializeTickValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [initializeStoreWithTickAndTime_tick] - -theorem assignStorageRef_initializeSlot0_sqrtPriceX96 {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - assignStorageRef? (config v) - { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm .storage (slot0F "sqrtPriceX96") (initializeArgValue I) = - .ok ({ contract := contract v, locals := initializeStoreWithTickAndTime I }, - initializeSlot0AfterSqrtPriceX96State evm I) := by - apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "sqrtPriceX96"] }) - (ty := .elem (.int uint160Int)) - (loc := initializeSlot0SqrtPriceX96Loc) - · simp [slot0F, initializeStoreWithTickAndTime, initializeStoreWithTick, initializeStore] - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, uint160St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - initializeSlot0SqrtPriceX96Loc, loc] - · trivial - · exact storageLocStore_initializeSlot0_sqrtPriceX96 evm I - -theorem assignStorageRef_initializeSlot0_tick {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - assignStorageRef? (config v) - { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm .storage (slot0F "tick") (initializeTickValue I) = - .ok ({ contract := contract v, locals := initializeStoreWithTickAndTime I }, - initializeSlot0AfterTickState evm I) := by - apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "tick"] }) - (ty := .elem (.int int24Int)) - (loc := initializeSlot0TickLoc) - · simp [slot0F, initializeStoreWithTickAndTime, initializeStoreWithTick, initializeStore] - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, int24St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - initializeSlot0TickLoc, loc] - · trivial - · exact storageLocStore_initializeSlot0_tick evm I - -theorem assignStorageRef_initializeSlot0_observationIndex {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - assignStorageRef? (config v) - { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm .storage (slot0F "observationIndex") (.int 0) = - .ok ({ contract := contract v, locals := initializeStoreWithTickAndTime I }, - initializeSlot0AfterObservationIndexState evm) := by - apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "observationIndex"] }) - (ty := .elem (.int uint16Int)) - (loc := initializeSlot0ObservationIndexLoc) - · simp [slot0F, initializeStoreWithTickAndTime, initializeStoreWithTick, initializeStore] - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, uint16St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - initializeSlot0ObservationIndexLoc, loc] - · trivial - · exact storageLocStore_initializeSlot0_observationIndex evm - -theorem assignStorageRef_initializeSlot0_observationCardinality {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - assignStorageRef? (config v) - { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm .storage (slot0F "observationCardinality") (.int 1) = - .ok ({ contract := contract v, locals := initializeStoreWithTickAndTime I }, - initializeSlot0AfterObservationCardinalityState evm) := by - apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "observationCardinality"] }) - (ty := .elem (.int uint16Int)) - (loc := initializeSlot0ObservationCardinalityLoc) - · simp [slot0F, initializeStoreWithTickAndTime, initializeStoreWithTick, initializeStore] - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, uint16St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - initializeSlot0ObservationCardinalityLoc, loc] - · trivial - · exact storageLocStore_initializeSlot0_observationCardinality evm - -theorem assignStorageRef_initializeSlot0_observationCardinalityNext {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - assignStorageRef? (config v) - { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm .storage (slot0F "observationCardinalityNext") (.int 1) = - .ok ({ contract := contract v, locals := initializeStoreWithTickAndTime I }, - initializeSlot0AfterObservationCardinalityNextState evm) := by - apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "observationCardinalityNext"] }) - (ty := .elem (.int uint16Int)) - (loc := initializeSlot0ObservationCardinalityNextLoc) - · simp [slot0F, initializeStoreWithTickAndTime, initializeStoreWithTick, initializeStore] - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, uint16St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - initializeSlot0ObservationCardinalityNextLoc, loc] - · trivial - · exact storageLocStore_initializeSlot0_observationCardinalityNext evm - -theorem assignStorageRef_initializeSlot0_feeProtocol {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - assignStorageRef? (config v) - { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm .storage (slot0F "feeProtocol") (.int 0) = - .ok ({ contract := contract v, locals := initializeStoreWithTickAndTime I }, - initializeSlot0AfterFeeProtocolState evm) := by - apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "feeProtocol"] }) - (ty := .elem (.int uint8Int)) - (loc := initializeSlot0FeeProtocolLoc) - · simp [slot0F, initializeStoreWithTickAndTime, initializeStoreWithTick, initializeStore] - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, uint8St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - initializeSlot0FeeProtocolLoc, loc] - · trivial - · exact storageLocStore_initializeSlot0_feeProtocol evm - -theorem assignStorageRef_initializeSlot0_unlocked {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - assignStorageRef? (config v) - { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm .storage (slot0F "unlocked") (.bool true) = - .ok ({ contract := contract v, locals := initializeStoreWithTickAndTime I }, - initializeSlot0AfterUnlockedState evm) := by - apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "unlocked"] }) - (ty := .elem .bool) - (loc := initializeSlot0UnlockedLoc) - · simp [slot0F, initializeStoreWithTickAndTime, initializeStoreWithTick, initializeStore] - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, boolSt] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - initializeSlot0UnlockedLoc, loc] - · trivial - · exact storageLocStore_initializeSlot0_unlocked_true evm - -theorem uniswapV3PoolInitializeSourceSlot0Stores {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) : - ExecBlock (config v) { contract := contract v, locals := initializeStoreWithTickAndTime I } - evm - [ .assign .storage (slot0F "sqrtPriceX96") (.var "sqrtPriceX96"), - .assign .storage (slot0F "tick") (.var "tick"), - .assign .storage (slot0F "observationIndex") (.intLit 0), - .assign .storage (slot0F "observationCardinality") (.intLit 1), - .assign .storage (slot0F "observationCardinalityNext") (.intLit 1), - .assign .storage (slot0F "feeProtocol") (.intLit 0), - .assign .storage (slot0F "unlocked") (.boolLit true) ] - (.ok { contract := contract v, locals := initializeStoreWithTickAndTime I } - (initializeSlot0AfterAllState evm I)) := by - unfold initializeSlot0AfterAllState - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_initializeSqrtPriceVar_withTickAndTime evm I) - (assignStorageRef_initializeSlot0_sqrtPriceX96 evm I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (evalExpr_initializeTickVar_withTickAndTime - (initializeSlot0AfterSqrtPriceX96State evm I) I) - (assignStorageRef_initializeSlot0_tick - (initializeSlot0AfterSqrtPriceX96State evm I) I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) - (assignStorageRef_initializeSlot0_observationIndex - (initializeSlot0AfterTickState - (initializeSlot0AfterSqrtPriceX96State evm I) I) I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) - (assignStorageRef_initializeSlot0_observationCardinality - (initializeSlot0AfterObservationIndexState - (initializeSlot0AfterTickState - (initializeSlot0AfterSqrtPriceX96State evm I) I)) I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) - (assignStorageRef_initializeSlot0_observationCardinalityNext - (initializeSlot0AfterObservationCardinalityState - (initializeSlot0AfterObservationIndexState - (initializeSlot0AfterTickState - (initializeSlot0AfterSqrtPriceX96State evm I) I))) I)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) - (assignStorageRef_initializeSlot0_feeProtocol - (initializeSlot0AfterObservationCardinalityNextState - (initializeSlot0AfterObservationCardinalityState - (initializeSlot0AfterObservationIndexState - (initializeSlot0AfterTickState - (initializeSlot0AfterSqrtPriceX96State evm I) I)))) I)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) - (assignStorageRef_initializeSlot0_unlocked - (initializeSlot0AfterFeeProtocolState - (initializeSlot0AfterObservationCardinalityNextState - (initializeSlot0AfterObservationCardinalityState - (initializeSlot0AfterObservationIndexState - (initializeSlot0AfterTickState - (initializeSlot0AfterSqrtPriceX96State evm I) I))))) I)) - ExecBlock.nil - -noncomputable def initializeSourceAfterStorageTailState - (evm : EVM.State) (I : ExecutionEnv) : EVM.State := - initializeSlot0AfterAllState (initializeObservationAfterAllState evm I) I - -theorem initializeSourceAfterStorageTailState_createdAccounts - (evm : EVM.State) (I : ExecutionEnv) : - (initializeSourceAfterStorageTailState evm I).createdAccounts = evm.createdAccounts := by - unfold initializeSourceAfterStorageTailState - rw [initializeSlot0AfterAllState_createdAccounts] - exact initializeObservationAfterAllState_createdAccounts evm I - -theorem initializeSourceAfterStorageTailState_executionEnv - (evm : EVM.State) (I : ExecutionEnv) : - (initializeSourceAfterStorageTailState evm I).executionEnv = evm.executionEnv := by - unfold initializeSourceAfterStorageTailState - rw [initializeSlot0AfterAllState_executionEnv] - exact initializeObservationAfterAllState_executionEnv evm I - -theorem uniswapV3PoolInitializeSourceStorageTail {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) (hEnv : evm.executionEnv = I) : - ExecBlock (config v) { contract := contract v, locals := initializeStoreWithTick I } - evm - [ .letDecl "time" (some uint32) (modE (.env .timestamp) uint32Modulus), - .assign .storage (observationsF (.intLit 0) "blockTimestamp") (.var "time"), - .assign .storage (observationsF (.intLit 0) "tickCumulative") (.intLit 0), - .assign .storage (observationsF (.intLit 0) "secondsPerLiquidityCumulativeX128") - (.intLit 0), - .assign .storage (observationsF (.intLit 0) "initialized") (.boolLit true), - .assign .storage (slot0F "sqrtPriceX96") (.var "sqrtPriceX96"), - .assign .storage (slot0F "tick") (.var "tick"), - .assign .storage (slot0F "observationIndex") (.intLit 0), - .assign .storage (slot0F "observationCardinality") (.intLit 1), - .assign .storage (slot0F "observationCardinalityNext") (.intLit 1), - .assign .storage (slot0F "feeProtocol") (.intLit 0), - .assign .storage (slot0F "unlocked") (.boolLit true) ] - (.ok { contract := contract v, locals := initializeStoreWithTickAndTime I } - (initializeSourceAfterStorageTailState evm I)) := by - have hobs := uniswapV3PoolInitializeSourceObservationTail (v := v) evm I hEnv - have hslot0 := uniswapV3PoolInitializeSourceSlot0Stores (v := v) - (initializeObservationAfterAllState evm I) I - simpa [initializeSourceAfterStorageTailState] using execBlock_append hobs hslot0 - -theorem uniswapV3PoolInitializeSourceSuccessBodyFromGetTick {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hzero : slot0SqrtPriceX96Word σ I = ⟨0⟩) - (hgetTick : - ExecStmt (config v) { contract := contract v, locals := initializeStore I } - (initState cA gh bl σ σ₀ g A I) - (.internalCall "getTickAtSqrtRatio" [.var "sqrtPriceX96"] "tick") - (.ok { contract := contract v, locals := initializeStoreWithTick I } - (initState cA gh bl σ σ₀ g A I))) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (initializeStore I) - initializeTransition.body - (.returned { contract := contract v, locals := initializeStoreWithTickAndTime I } - (initializeSourceAfterStorageTailState (initState cA gh bl σ σ₀ g A I) I) - none) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (initializeStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (eqE (.storage (slot0F "sqrtPriceX96")) (.intLit 0)), - .internalCall "getTickAtSqrtRatio" [.var "sqrtPriceX96"] "tick", - .letDecl "time" (some uint32) (modE (.env .timestamp) uint32Modulus), - .assign .storage (observationsF (.intLit 0) "blockTimestamp") (.var "time"), - .assign .storage (observationsF (.intLit 0) "tickCumulative") (.intLit 0), - .assign .storage (observationsF (.intLit 0) "secondsPerLiquidityCumulativeX128") - (.intLit 0), - .assign .storage (observationsF (.intLit 0) "initialized") (.boolLit true), - .assign .storage (slot0F "sqrtPriceX96") (.var "sqrtPriceX96"), - .assign .storage (slot0F "tick") (.var "tick"), - .assign .storage (slot0F "observationIndex") (.intLit 0), - .assign .storage (slot0F "observationCardinality") (.intLit 1), - .assign .storage (slot0F "observationCardinalityNext") (.intLit 1), - .assign .storage (slot0F "feeProtocol") (.intLit 0), - .assign .storage (slot0F "unlocked") (.boolLit true) ] - (.returned { contract := contract v, locals := initializeStoreWithTickAndTime I } - (initializeSourceAfterStorageTailState (initState cA gh bl σ σ₀ g A I) I) - none) - refine ExecFuncBody.execBlockOK ?_ - refine ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true (by - simp [initState, hwv]))) ?_ - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (uniswapV3PoolInitializeEvalSqrtPriceX96EqZeroTrue (v := v) hzero)) ?_ - refine ExecBlock.consNormal hgetTick ?_ - exact uniswapV3PoolInitializeSourceStorageTail - (initState cA gh bl σ σ₀ g A I) I (by simp [initState]) - -theorem uniswapV3PoolInitializeSourceGetTickStatementSuccess {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} {calleeSolm : Frame} - (hbody : - ExecFuncBody (config v) { contract := contract v, locals := initializeStore I } - (initState cA gh bl σ σ₀ g A I) getTickAtSqrtRatioFunction.body - (.returned calleeSolm (initState cA gh bl σ σ₀ g A I) - (some [initializeTickValue I]))) : - ExecStmt (config v) { contract := contract v, locals := initializeStore I } - (initState cA gh bl σ σ₀ g A I) - (.internalCall "getTickAtSqrtRatio" [.var "sqrtPriceX96"] "tick") - (.ok { contract := contract v, locals := initializeStoreWithTick I } - (initState cA gh bl σ σ₀ g A I)) := by - have hstmt := internalCallFunctionReturn - (cfg := config v) - (caller := { contract := contract v, locals := initializeStore I }) - (evm := initState cA gh bl σ σ₀ g A I) - (calleeEvm := initState cA gh bl σ σ₀ g A I) - (name := "getTickAtSqrtRatio") (retVar := "tick") - (args := [.var "sqrtPriceX96"]) (argVals := [initializeArgValue I]) - (callee := getTickAtSqrtRatioFunction) (locals := initializeStore I) - (calleeSolm := calleeSolm) (value := some [initializeTickValue I]) - (by - simp [evalExprs?, uniswapV3PoolInitializeEvalSqrtPriceVar, EvalResult.bind, bind, pure]) - (by - simp [lookupCallable?, lookupFunction?, contract, functions, getSqrtRatioAtTickFunction, - getTickAtSqrtRatioFunction]) - (by rfl) - hbody - simpa [resumeAfterInternalCall, collapseReturns, initializeStoreWithTick] using hstmt - -theorem uniswapV3PoolInitializeSourceSuccessBodyOfGetTickFunc {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} {calleeSolm : Frame} - (hwv : I.weiValue = ⟨0⟩) - (hzero : slot0SqrtPriceX96Word σ I = ⟨0⟩) - (hgetTickBody : - ExecFuncBody (config v) { contract := contract v, locals := initializeStore I } - (initState cA gh bl σ σ₀ g A I) getTickAtSqrtRatioFunction.body - (.returned calleeSolm (initState cA gh bl σ σ₀ g A I) - (some [initializeTickValue I]))) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (initializeStore I) - initializeTransition.body - (.returned { contract := contract v, locals := initializeStoreWithTickAndTime I } - (initializeSourceAfterStorageTailState (initState cA gh bl σ σ₀ g A I) I) - none) := by - exact uniswapV3PoolInitializeSourceSuccessBodyFromGetTick (v := v) hwv hzero - (uniswapV3PoolInitializeSourceGetTickStatementSuccess (v := v) hgetTickBody) - -private theorem initializeObservationLow32_merge (low old : UInt256) - (hlow : low.toNat < 2 ^ 32) : - UInt256.land (⟨4294967295⟩ : UInt256) - (UInt256.lor low (UInt256.land (UInt256.lnot (⟨4294967295⟩ : UInt256)) old)) = - low := by - apply u256_inj - have hmask32 : (⟨4294967295⟩ : UInt256).toNat = 2 ^ 32 - 1 := by native_decide - have hclearMask : UInt256.lnot (⟨4294967295⟩ : UInt256) = - UInt256.ofNat ((2 : Nat) ^ 256 - 2 ^ 32) := by - native_decide - have hhigh : - (UInt256.land (UInt256.lnot (⟨4294967295⟩ : UInt256)) old).toNat = - old.toNat / 2 ^ 32 * 2 ^ 32 := by - rw [hclearMask] - exact u256_land_high_mask_toNat old 32 (by norm_num) - have hq : old.toNat / 2 ^ 32 < 2 ^ 224 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 32 * 2 ^ 224 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change old.val.val < 2 ^ 256 - simp [UInt256.size] - have hlorLt : - Nat.lor low.toNat - ((UInt256.land (UInt256.lnot (⟨4294967295⟩ : UInt256)) old).toNat) < - UInt256.size := by - rw [hhigh] - rw [nat_lor_shift_add low.toNat (old.toNat / 2 ^ 32) 32 hlow] - have hqle : old.toNat / 2 ^ 32 ≤ 2 ^ 224 - 1 := Nat.le_pred_of_lt hq - have hprod : (old.toNat / 2 ^ 32) * 2 ^ 32 ≤ (2 ^ 224 - 1) * 2 ^ 32 := by - exact Nat.mul_le_mul_right _ hqle - norm_num [UInt256.size, Nat.pow_add] at hprod ⊢ - omega - rw [u256_land_toNat] - rw [hmask32] - rw [nat_land_comm] - rw [nat_land_mask_eq_mod] - rw [Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 32)) (by norm_num [UInt256.size]))] - rw [u256_lor_toNat] - rw [Nat.mod_eq_of_lt hlorLt] - rw [hhigh] - rw [nat_lor_shift_add low.toNat (old.toNat / 2 ^ 32) 32 hlow] - rw [Nat.add_mul_mod_self_right] - exact Nat.mod_eq_of_lt hlow - -theorem initializeObservationSstoreWord_eq_timestamp (σ : AccountMap) (ee : ExecutionEnv) : - initializeObservationSstoreWord σ ee = - UInt256.lor (UInt256.shiftLeft ⟨1⟩ ⟨248⟩) (initializeObservationTimestampWord ee) := by - unfold initializeObservationSstoreWord - rw [initializeObservationLow32_merge] - unfold initializeObservationTimestampWord - rw [u256_land_toNat] - have hmask32 : (⟨4294967295⟩ : UInt256).toNat = 2 ^ 32 - 1 := by native_decide - rw [hmask32, nat_land_comm, nat_land_mask_eq_mod] - rw [Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 32)) (by norm_num [UInt256.size]))] - exact Nat.mod_lt _ (by norm_num) - -theorem initializeObservationAccountMapEquiv {cA gh bl σ_evm σ_solm σ₀ A I} - {g : Sat256} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - accountMapEquiv - (sstoreAccountMap I.codeOwner σ_evm ⟨8⟩ (initializeObservationSstoreWord σ_evm I)) - (Solm.EVM.storageStore (initState cA gh bl σ_solm σ₀ g A I) I.codeOwner ⟨8⟩ - (UInt256.lor (UInt256.shiftLeft ⟨1⟩ ⟨248⟩) - (initializeObservationTimestampWord I))).accountMap := by - rw [initializeObservationSstoreWord_eq_timestamp] - simpa [storageStore_accountMap, initState] using - accountMapEquiv_sstoreAccountMap I.codeOwner ⟨8⟩ - (UInt256.lor (UInt256.shiftLeft ⟨1⟩ ⟨248⟩) (initializeObservationTimestampWord I)) - hAccounts - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/InitializeSuccess.lean b/Benchmarks/UniswapV3Pool/InitializeSuccess.lean deleted file mode 100644 index a61814cb..00000000 --- a/Benchmarks/UniswapV3Pool/InitializeSuccess.lean +++ /dev/null @@ -1,1548 +0,0 @@ -import Benchmarks.UniswapV3Pool.InitializeGetTickSqrtRatioFull - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolInitializePatchDisjointTimestamp {v : PoolImmutables} - {pc : UInt256} (hlo : 11291 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 15650) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest10809 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨10809⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest11303 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11303⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest17514 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨17514⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest10817 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨10817⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolInitializePatchPreservesJumpDest857 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨857⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolInitializePatchDisjointObservationStore {v : PoolImmutables} - {pc : UInt256} (hlo : 17514 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19295) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -theorem uniswapV3PoolJumpDestPatched10809 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10809⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest10809 - -theorem uniswapV3PoolJumpDestPatched11303 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11303⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest11303 - -theorem uniswapV3PoolJumpDestPatched17514 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨17514⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest17514 - -theorem uniswapV3PoolJumpDestPatched10817 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10817⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest10817 - -theorem uniswapV3PoolInitializeJumpDestPatched857 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨857⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolInitializePatchPreservesJumpDest857 - -def initializeObservationTimestampWord (ee : ExecutionEnv) : UInt256 := - UInt256.land ⟨4294967295⟩ (UInt256.ofNat ee.header.timestamp) - -def initializeObservationSstoreWord (σ : AccountMap) (ee : ExecutionEnv) : UInt256 := - UInt256.lor - (UInt256.shiftLeft ⟨1⟩ ⟨248⟩) - (UInt256.land ⟨4294967295⟩ - (UInt256.lor (initializeObservationTimestampWord ee) - (UInt256.land (UInt256.lnot ⟨4294967295⟩) (codeOwnerStorageWord ee σ ⟨8⟩)))) - -noncomputable def initializeObservationStoreMem0 : ByteArray := - writeWord solcFreePtrMem 64 (UInt256.ofNat 256) - -noncomputable def initializeObservationStoreMem1 (ee : ExecutionEnv) : ByteArray := - writeWord initializeObservationStoreMem0 128 (initializeObservationTimestampWord ee) - -noncomputable def initializeObservationStoreMem2 (ee : ExecutionEnv) : ByteArray := - writeWord (initializeObservationStoreMem1 ee) 160 ⟨0⟩ - -noncomputable def initializeObservationStoreMem3 (ee : ExecutionEnv) : ByteArray := - writeWord (initializeObservationStoreMem2 ee) 192 ⟨0⟩ - -noncomputable def initializeObservationStoreMem (ee : ExecutionEnv) : ByteArray := - writeWord (initializeObservationStoreMem3 ee) 224 ⟨1⟩ - -theorem initializeObservationStoreMem_size (ee : ExecutionEnv) : - (initializeObservationStoreMem ee).size = 256 := by - unfold initializeObservationStoreMem initializeObservationStoreMem3 initializeObservationStoreMem2 - initializeObservationStoreMem1 initializeObservationStoreMem0 - change (writeCascade solcFreePtrMem - [(64, UInt256.ofNat 256), (128, initializeObservationTimestampWord ee), - (160, (⟨0⟩ : UInt256)), (192, (⟨0⟩ : UInt256)), (224, (⟨1⟩ : UInt256))]).size = - 256 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem initializeObservationStoreMem_read64 (ee : ExecutionEnv) : - (initializeObservationStoreMem ee).readWithPadding 64 32 = - UInt256.toByteArray (UInt256.ofNat 256) := by - unfold initializeObservationStoreMem initializeObservationStoreMem3 initializeObservationStoreMem2 - initializeObservationStoreMem1 initializeObservationStoreMem0 - change ((writeCascade solcFreePtrMem - [(64, UInt256.ofNat 256), (128, initializeObservationTimestampWord ee), - (160, (⟨0⟩ : UInt256)), (192, (⟨0⟩ : UInt256)), (224, (⟨1⟩ : UInt256))]).readWithPadding - 64 32 = UInt256.toByteArray (UInt256.ofNat 256)) - exact writeCascade_read_word_of_head_of_base solcFreePtrMem (base := 96) (off := 64) - (UInt256.ofNat 256) - [(128, initializeObservationTimestampWord ee), (160, (⟨0⟩ : UInt256)), - (192, (⟨0⟩ : UInt256)), (224, (⟨1⟩ : UInt256))] - solcFreePtrMem_size (by native_decide) - (by - norm_num [WindowDisjointFromWrites] - all_goals native_decide) - -theorem initializeObservationStoreMem_mload64 (ee : ExecutionEnv) : - (if (⟨64⟩ : UInt256).toNat ≥ (initializeObservationStoreMem ee).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 8 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((initializeObservationStoreMem ee).readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - UInt256.ofNat 256 := by - exact mloadWordValue_of_readWithPadding - (by rw [initializeObservationStoreMem_size]; decide) - (by decide) - (by simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using initializeObservationStoreMem_read64 ee) - -def initializeSlot0SqrtEventWord (sqrt : UInt256) : UInt256 := - UInt256.land sqrt (UInt256.sub (UInt256.shiftLeft ⟨1⟩ ⟨160⟩) ⟨1⟩) - -def initializeSlot0TickEventWord (tick : UInt256) : UInt256 := - UInt256.signextend ⟨2⟩ tick - -def initializeSlot0ObservationCardinalityEventWord : UInt256 := - UInt256.land ⟨65535⟩ ⟨1⟩ - -def initializeSlot0ObservationCardinalityNextEventWord : UInt256 := - UInt256.land ⟨1⟩ ⟨65535⟩ - -abbrev initializeSlot0TickClearMask : UInt256 := - ⟨115792089237210883131926947750643844047320047785756073890994934722613756297215⟩ - -abbrev initializeSlot0UnlockedClearMask : UInt256 := - ⟨115339783290479275825761448283253582990243601239149377756565007982906442776575⟩ - -abbrev initializeSlot0EventTopic : UInt256 := - ⟨68927134888976591364352437975413714156611039632452992126063371163455731879061⟩ - -abbrev initializeSlot0SstoreWord - (σ : AccountMap) (ee : ExecutionEnv) (sqrt tick : UInt256) : UInt256 := - let slotWithSqrt := - UInt256.lor - (initializeSlot0SqrtEventWord sqrt) - (UInt256.land (codeOwnerStorageWord ee σ ⟨0⟩) (UInt256.lnot solcAddrMask)) - let tickShifted := - UInt256.mul - (UInt256.land (UInt256.signextend ⟨2⟩ (initializeSlot0TickEventWord tick)) - ⟨16777215⟩) - (UInt256.shiftLeft ⟨1⟩ ⟨160⟩) - let slotWithTick := - UInt256.lor - tickShifted - (UInt256.land (UInt256.lnot (UInt256.shiftLeft ⟨16777215⟩ ⟨160⟩)) - slotWithSqrt) - let slotWithCardinality := - UInt256.lor - (UInt256.mul - initializeSlot0ObservationCardinalityEventWord - (UInt256.shiftLeft ⟨1⟩ ⟨200⟩)) - (UInt256.land initializeSlot0TickClearMask slotWithTick) - let slotWithCardinalityNext := - UInt256.lor - (UInt256.mul - initializeSlot0ObservationCardinalityNextEventWord - (UInt256.shiftLeft ⟨1⟩ ⟨216⟩)) - (UInt256.land (UInt256.lnot (UInt256.shiftLeft ⟨65535⟩ ⟨216⟩)) - slotWithCardinality) - UInt256.lor - (UInt256.land initializeSlot0UnlockedClearMask slotWithCardinalityNext) - (UInt256.shiftLeft ⟨1⟩ ⟨240⟩) - -noncomputable def initializeSlot0EventMem0 (ee : ExecutionEnv) : ByteArray := - writeWord (initializeObservationStoreMem ee) 64 (UInt256.ofNat 480) - -noncomputable def initializeSlot0EventMem1 (ee : ExecutionEnv) (sqrt : UInt256) : - ByteArray := - writeWord (initializeSlot0EventMem0 ee) 256 (initializeSlot0SqrtEventWord sqrt) - -noncomputable def initializeSlot0EventMem2 - (ee : ExecutionEnv) (sqrt tick : UInt256) : ByteArray := - writeWord (initializeSlot0EventMem1 ee sqrt) 288 (initializeSlot0TickEventWord tick) - -noncomputable def initializeSlot0EventMem3 - (ee : ExecutionEnv) (sqrt tick : UInt256) : ByteArray := - writeWord (initializeSlot0EventMem2 ee sqrt tick) 320 ⟨0⟩ - -noncomputable def initializeSlot0EventMem4 - (ee : ExecutionEnv) (sqrt tick : UInt256) : ByteArray := - writeWord (initializeSlot0EventMem3 ee sqrt tick) 352 - initializeSlot0ObservationCardinalityEventWord - -noncomputable def initializeSlot0EventMem5 - (ee : ExecutionEnv) (sqrt tick : UInt256) : ByteArray := - writeWord (initializeSlot0EventMem4 ee sqrt tick) 384 - initializeSlot0ObservationCardinalityNextEventWord - -noncomputable def initializeSlot0EventMem6 - (ee : ExecutionEnv) (sqrt tick : UInt256) : ByteArray := - writeWord (initializeSlot0EventMem5 ee sqrt tick) 416 ⟨0⟩ - -noncomputable def initializeSlot0EventMem - (ee : ExecutionEnv) (sqrt tick : UInt256) : ByteArray := - writeWord (initializeSlot0EventMem6 ee sqrt tick) 448 ⟨1⟩ - -noncomputable def initializeSlot0LogMem0 - (ee : ExecutionEnv) (sqrt tick : UInt256) : ByteArray := - writeWord (initializeSlot0EventMem ee sqrt tick) 480 (initializeSlot0SqrtEventWord sqrt) - -noncomputable def initializeSlot0LogMem - (ee : ExecutionEnv) (sqrt tick : UInt256) : ByteArray := - writeWord (initializeSlot0LogMem0 ee sqrt tick) 512 (initializeSlot0TickEventWord tick) - -theorem initializeSlot0EventMem_size (ee : ExecutionEnv) (sqrt tick : UInt256) : - (initializeSlot0EventMem ee sqrt tick).size = 480 := by - unfold initializeSlot0EventMem initializeSlot0EventMem6 initializeSlot0EventMem5 - initializeSlot0EventMem4 initializeSlot0EventMem3 initializeSlot0EventMem2 - initializeSlot0EventMem1 initializeSlot0EventMem0 - change (writeCascade (initializeObservationStoreMem ee) - [(64, UInt256.ofNat 480), (256, initializeSlot0SqrtEventWord sqrt), - (288, initializeSlot0TickEventWord tick), (320, (⟨0⟩ : UInt256)), - (352, initializeSlot0ObservationCardinalityEventWord), - (384, initializeSlot0ObservationCardinalityNextEventWord), (416, (⟨0⟩ : UInt256)), - (448, (⟨1⟩ : UInt256))]).size = 480 - exact writeCascade_size_of_base (initializeObservationStoreMem ee) _ - (initializeObservationStoreMem_size ee) - (by - norm_num [WriteGapsOk]) - (by norm_num [writeCascadeSize]) - -theorem initializeSlot0EventMem_read64 (ee : ExecutionEnv) (sqrt tick : UInt256) : - (initializeSlot0EventMem ee sqrt tick).readWithPadding 64 32 = - UInt256.toByteArray (UInt256.ofNat 480) := by - unfold initializeSlot0EventMem initializeSlot0EventMem6 initializeSlot0EventMem5 - initializeSlot0EventMem4 initializeSlot0EventMem3 initializeSlot0EventMem2 - initializeSlot0EventMem1 initializeSlot0EventMem0 - change ((writeCascade (initializeObservationStoreMem ee) - [(64, UInt256.ofNat 480), (256, initializeSlot0SqrtEventWord sqrt), - (288, initializeSlot0TickEventWord tick), (320, (⟨0⟩ : UInt256)), - (352, initializeSlot0ObservationCardinalityEventWord), - (384, initializeSlot0ObservationCardinalityNextEventWord), (416, (⟨0⟩ : UInt256)), - (448, (⟨1⟩ : UInt256))]).readWithPadding 64 32 = - UInt256.toByteArray (UInt256.ofNat 480)) - exact writeCascade_read_word_of_head_of_base (initializeObservationStoreMem ee) - (base := 256) (off := 64) (UInt256.ofNat 480) - [(256, initializeSlot0SqrtEventWord sqrt), (288, initializeSlot0TickEventWord tick), - (320, (⟨0⟩ : UInt256)), (352, initializeSlot0ObservationCardinalityEventWord), - (384, initializeSlot0ObservationCardinalityNextEventWord), (416, (⟨0⟩ : UInt256)), - (448, (⟨1⟩ : UInt256))] - (initializeObservationStoreMem_size ee) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem initializeSlot0EventMem_mload64 (ee : ExecutionEnv) (sqrt tick : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (initializeSlot0EventMem ee sqrt tick).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 15 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((initializeSlot0EventMem ee sqrt tick).readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - UInt256.ofNat 480 := by - exact mloadWordValue_of_readWithPadding - (by rw [initializeSlot0EventMem_size]; decide) - (by decide) - (by simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using initializeSlot0EventMem_read64 ee sqrt tick) - -theorem initializeSlot0LogMem_size (ee : ExecutionEnv) (sqrt tick : UInt256) : - (initializeSlot0LogMem ee sqrt tick).size = 544 := by - unfold initializeSlot0LogMem initializeSlot0LogMem0 - change (writeCascade (initializeSlot0EventMem ee sqrt tick) - [(480, initializeSlot0SqrtEventWord sqrt), - (512, initializeSlot0TickEventWord tick)]).size = 544 - exact writeCascade_size_of_base (initializeSlot0EventMem ee sqrt tick) _ - (initializeSlot0EventMem_size ee sqrt tick) - (by - norm_num [WriteGapsOk]) - (by norm_num [writeCascadeSize]) - -theorem initializeSlot0LogMem_read64 (ee : ExecutionEnv) (sqrt tick : UInt256) : - (initializeSlot0LogMem ee sqrt tick).readWithPadding 64 32 = - UInt256.toByteArray (UInt256.ofNat 480) := by - unfold initializeSlot0LogMem initializeSlot0LogMem0 - change ((writeCascade (initializeSlot0EventMem ee sqrt tick) - [(480, initializeSlot0SqrtEventWord sqrt), - (512, initializeSlot0TickEventWord tick)]).readWithPadding 64 32 = - UInt256.toByteArray (UInt256.ofNat 480)) - rw [writeCascade_read_preserved_of_base (initializeSlot0EventMem ee sqrt tick) - [(480, initializeSlot0SqrtEventWord sqrt), (512, initializeSlot0TickEventWord tick)] - (base := 480) (read := 64) (initializeSlot0EventMem_size ee sqrt tick)] - · exact initializeSlot0EventMem_read64 ee sqrt tick - · norm_num [WindowDisjointFromWrites] - -theorem initializeSlot0LogMem_mload64 (ee : ExecutionEnv) (sqrt tick : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (initializeSlot0LogMem ee sqrt tick).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 17 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((initializeSlot0LogMem ee sqrt tick).readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - UInt256.ofNat 480 := by - exact mloadWordValue_of_readWithPadding - (by rw [initializeSlot0LogMem_size]; decide) - (by decide) - (by simpa [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - using initializeSlot0LogMem_read64 ee sqrt tick) - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolInitializeReachObservationStore {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tick sqrt ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨10793⟩ (tick :: ⟨0⟩ :: sqrt :: ret :: R) - mem aw rdata acc k C) - (hov : R.length + 9 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨17514⟩ - (UInt256.ofNat ee.header.timestamp :: ⟨8⟩ :: ⟨10817⟩ :: ⟨0⟩ :: ⟨0⟩ :: - tick :: sqrt :: ret :: R) - mem aw rdata acc k' C' := by - have hdecodeBody {pc : UInt256} (hlo : 10597 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 11259) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 11259 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointBody hlo hhi)] - have hdecodeTimestamp {pc : UInt256} (hlo : 11291 ≤ pc.toNat) - (hhi : pc.toNat + 33 ≤ 15650) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointTimestamp hlo hhi)] - have hd10793 : decode code ⟨10793⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd10794 : decode code ⟨10794⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd10795 : decode code ⟨10795⟩ = some (.POP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd10796 : decode code ⟨10796⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd10798 : decode code ⟨10798⟩ = some (.DUP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd10799 : decode code ⟨10799⟩ = some (.Push .PUSH2, some (⟨10817⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd10802 : decode code ⟨10802⟩ = some (.Push .PUSH2, some (⟨10809⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd10805 : decode code ⟨10805⟩ = some (.Push .PUSH2, some (⟨11303⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd10808 : decode code ⟨10808⟩ = some (.JUMP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd10809 : decode code ⟨10809⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd10810 : decode code ⟨10810⟩ = some (.Push .PUSH1, some (⟨8⟩, 1)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd10812 : decode code ⟨10812⟩ = some (.SWAP1, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd10813 : decode code ⟨10813⟩ = some (.Push .PUSH2, some (⟨17514⟩, 2)) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd10816 : decode code ⟨10816⟩ = some (.JUMP, .none) := by - rw [hdecodeBody (by native_decide) (by native_decide)] - native_decide - have hd11303 : decode code ⟨11303⟩ = some (.JUMPDEST, .none) := by - rw [hdecodeTimestamp (by native_decide) (by native_decide)] - native_decide - have hd11304 : decode code ⟨11304⟩ = some (.TIMESTAMP, .none) := by - rw [hdecodeTimestamp (by native_decide) (by native_decide)] - native_decide - have hd11305 : decode code ⟨11305⟩ = some (.SWAP1, .none) := by - rw [hdecodeTimestamp (by native_decide) (by native_decide)] - native_decide - have hd11306 : decode code ⟨11306⟩ = some (.JUMP, .none) := by - rw [hdecodeTimestamp (by native_decide) (by native_decide)] - native_decide - have rd10808 := evm_run h with [ - raw jumpdest hd10793 (by evm_ov), - raw swap1 hd10794 (by evm_ov), - raw pop hd10795 (by evm_ov), - raw push1 ⟨0⟩ hd10796 (by evm_ov), - raw dup1 hd10798 (by evm_ov), - raw push2 ⟨10817⟩ hd10799 (by evm_ov), - raw push2 ⟨10809⟩ hd10802 (by evm_ov), - raw push2 ⟨11303⟩ hd10805 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd11303 := rd10808.jump hd10808 (uniswapV3PoolJumpDestPatched11303 hpatch) - (by evm_ov) - have rd11306 := evm_run rd11303 with [ - raw jumpdest hd11303 (by evm_ov), - raw timestamp hd11304 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap1 hd11305 (by evm_ov)] - have rd10809 := rd11306.jump hd11306 (uniswapV3PoolJumpDestPatched10809 hpatch) - (by evm_ov) - have rd10816 := evm_run rd10809 with [ - raw jumpdest hd10809 (by evm_ov), - raw push1 ⟨8⟩ hd10810 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap1 hd10812 (by evm_ov), - raw push2 ⟨17514⟩ hd10813 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - exact ⟨_, _, rd10816.jump hd10816 (uniswapV3PoolJumpDestPatched17514 hpatch) (by evm_ov)⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolInitializeObservationStore {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tick sqrt ret : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨17514⟩ - (UInt256.ofNat ee.header.timestamp :: ⟨8⟩ :: ⟨10817⟩ :: ⟨0⟩ :: ⟨0⟩ :: - tick :: sqrt :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hperm : ee.perm = true) - (hov : R.length + 14 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨10817⟩ - (⟨1⟩ :: ⟨1⟩ :: ⟨0⟩ :: ⟨0⟩ :: tick :: sqrt :: ret :: R) - (initializeObservationStoreMem ee) (UInt256.ofNat 8) rdata - (cA, sstoreAccountMap ee.codeOwner σ ⟨8⟩ (initializeObservationSstoreWord σ ee)) - k' C' := by - have hdecode {pc : UInt256} (hlo : 17514 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 19295) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 19295 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointObservationStore hlo hhi)] - have hd17514 : decode code ⟨17514⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17515 : decode code ⟨17515⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17517 : decode code ⟨17517⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17518 : decode code ⟨17518⟩ = some (.MLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17519 : decode code ⟨17519⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17521 : decode code ⟨17521⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17522 : decode code ⟨17522⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17523 : decode code ⟨17523⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17524 : decode code ⟨17524⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17525 : decode code ⟨17525⟩ = - some (.Push .PUSH4, some (⟨4294967295⟩, 4)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17530 : decode code ⟨17530⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17531 : decode code ⟨17531⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17532 : decode code ⟨17532⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17533 : decode code ⟨17533⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17534 : decode code ⟨17534⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17535 : decode code ⟨17535⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17536 : decode code ⟨17536⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17538 : decode code ⟨17538⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17540 : decode code ⟨17540⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17541 : decode code ⟨17541⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17542 : decode code ⟨17542⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17543 : decode code ⟨17543⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17544 : decode code ⟨17544⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17545 : decode code ⟨17545⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17546 : decode code ⟨17546⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17547 : decode code ⟨17547⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17548 : decode code ⟨17548⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17549 : decode code ⟨17549⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17550 : decode code ⟨17550⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17551 : decode code ⟨17551⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17552 : decode code ⟨17552⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17554 : decode code ⟨17554⟩ = some (.Push .PUSH1, some (⟨96⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17556 : decode code ⟨17556⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17557 : decode code ⟨17557⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17558 : decode code ⟨17558⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17559 : decode code ⟨17559⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17560 : decode code ⟨17560⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17561 : decode code ⟨17561⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17562 : decode code ⟨17562⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17563 : decode code ⟨17563⟩ = some (.SLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17564 : decode code ⟨17564⟩ = - some (.Push .PUSH4, some (⟨4294967295⟩, 4)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17569 : decode code ⟨17569⟩ = some (.NOT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17570 : decode code ⟨17570⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17571 : decode code ⟨17571⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17572 : decode code ⟨17572⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17573 : decode code ⟨17573⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17574 : decode code ⟨17574⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17575 : decode code ⟨17575⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17576 : decode code ⟨17576⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17577 : decode code ⟨17577⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17579 : decode code ⟨17579⟩ = some (.Push .PUSH1, some (⟨248⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17581 : decode code ⟨17581⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17582 : decode code ⟨17582⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17583 : decode code ⟨17583⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17584 : decode code ⟨17584⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17585 : decode code ⟨17585⟩ = some (.SSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17586 : decode code ⟨17586⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17587 : decode code ⟨17587⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17588 : decode code ⟨17588⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd17589 : decode code ⟨17589⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd17518 := evm_run h with [ - raw jumpdest hd17514 (by evm_ov), - raw push1 ⟨64⟩ hd17515 (by evm_ov), - raw dup1 hd17517 (by evm_ov)] - have rd17519 := evm_run rd17518 with [ - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) hd17518 mem_cost - solcFreePtrMem_mload64 - (by native_decide) (by evm_ov)] - have rd17525 := evm_run rd17519 with [ - raw push1 ⟨128⟩ hd17519 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup2 hd17521 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw add hd17522 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup3 hd17523 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw mstore 0 initializeObservationStoreMem0 (UInt256.ofNat 3) - hd17524 mem_cost rfl (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd17535 := evm_run rd17525 with [ - raw push4 ⟨4294967295⟩ hd17525 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap3 hd17530 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup4 hd17531 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd17532 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup1 hd17533 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup3 hd17534 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd17536 := evm_run rd17535 with [ - raw mstore 6 (initializeObservationStoreMem1 ee) (UInt256.ofNat 5) - hd17535 mem_cost rfl (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd17545 := evm_run rd17536 with [ - raw push1 ⟨0⟩ hd17536 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨32⟩ hd17538 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup4 hd17540 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw add hd17541 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup2 hd17542 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap1 hd17543 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw mstore 3 (initializeObservationStoreMem2 ee) (UInt256.ofNat 6) - hd17544 mem_cost rfl (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd17552 := evm_run rd17545 with [ - raw swap3 hd17545 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup3 hd17546 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw add hd17547 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap3 hd17548 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap1 hd17549 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap3 hd17550 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw mstore 3 (initializeObservationStoreMem3 ee) (UInt256.ofNat 7) - hd17551 mem_cost rfl (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd17562 := evm_run rd17552 with [ - raw push1 ⟨1⟩ hd17552 (by evm_ov), - raw push1 ⟨96⟩ hd17554 (by evm_ov), - raw swap1 hd17556 (by evm_ov), - raw swap2 hd17557 (by evm_ov), - raw add hd17558 (by evm_ov), - raw dup2 hd17559 (by evm_ov), - raw swap1 hd17560 (by evm_ov), - raw mstore 3 (initializeObservationStoreMem ee) (UInt256.ofNat 8) - hd17561 mem_cost rfl (by native_decide) (by evm_ov), - raw dup4 hd17562 (by evm_ov)] - obtain ⟨_, _, rd17564⟩ := rd17562.sload hd17563 (by evm_ov) - have rd17585 := evm_run rd17564 with [ - raw push4 ⟨4294967295⟩ hd17564 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw not hd17569 (by evm_ov), - raw and hd17570 (by evm_ov), - raw swap1 hd17571 (by evm_ov), - raw swap2 hd17572 (by evm_ov), - raw lor hd17573 (by evm_ov), - raw swap1 hd17574 (by evm_ov), - raw swap2 hd17575 (by evm_ov), - raw and hd17576 (by evm_ov), - raw push1 ⟨1⟩ hd17577 (by evm_ov), - raw push1 ⟨248⟩ hd17579 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd17581 (by evm_ov), - raw lor hd17582 (by evm_ov), - raw swap1 hd17583 (by evm_ov), - raw swap2 hd17584 (by evm_ov)] - obtain ⟨_, _, rd17586⟩ := rd17585.sstore hperm hd17585 (by evm_ov) - have rd17589 := evm_run rd17586 with [ - raw swap1 hd17586 (by evm_ov), - raw dup2 hd17587 (by evm_ov), - raw swap1 hd17588 (by evm_ov)] - have rd10817 := rd17589.jump hd17589 (uniswapV3PoolJumpDestPatched10817 hpatch) - (by evm_ov) - exact ⟨_, _, by - simpa [initializeObservationSstoreWord, initializeObservationTimestampWord, - codeOwnerStorageWord] using rd10817⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolInitializeSlot0EventSetup {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tick sqrt ret : UInt256} {R : List UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨10817⟩ - (⟨1⟩ :: ⟨1⟩ :: ⟨0⟩ :: ⟨0⟩ :: tick :: sqrt :: ret :: R) - (initializeObservationStoreMem ee) (UInt256.ofNat 8) rdata acc k C) - (hov : R.length + 24 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨10904⟩ - (⟨0⟩ :: initializeSlot0ObservationCardinalityEventWord :: ⟨0⟩ :: ⟨32⟩ :: - initializeSlot0TickEventWord tick :: ⟨2⟩ :: initializeSlot0SqrtEventWord sqrt :: - initializeSlot0ObservationCardinalityNextEventWord :: ⟨64⟩ :: ⟨1⟩ :: ⟨1⟩ :: - ⟨0⟩ :: ⟨0⟩ :: tick :: sqrt :: ret :: R) - (initializeSlot0EventMem ee sqrt tick) (UInt256.ofNat 15) rdata acc k' C' := by - have hdecode {pc : UInt256} (hlo : 10597 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 11259) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 11259 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointBody hlo hhi)] - have hd10817 : decode code ⟨10817⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10818 : decode code ⟨10818⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10820 : decode code ⟨10820⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10821 : decode code ⟨10821⟩ = some (.MLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10822 : decode code ⟨10822⟩ = some (.Push .PUSH1, some (⟨224⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10824 : decode code ⟨10824⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10825 : decode code ⟨10825⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10826 : decode code ⟨10826⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10827 : decode code ⟨10827⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10828 : decode code ⟨10828⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10830 : decode code ⟨10830⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10832 : decode code ⟨10832⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10834 : decode code ⟨10834⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10835 : decode code ⟨10835⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10836 : decode code ⟨10836⟩ = some (.DUP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10837 : decode code ⟨10837⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10838 : decode code ⟨10838⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10839 : decode code ⟨10839⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10840 : decode code ⟨10840⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10841 : decode code ⟨10841⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10843 : decode code ⟨10843⟩ = some (.DUP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10844 : decode code ⟨10844⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10845 : decode code ⟨10845⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10846 : decode code ⟨10846⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10848 : decode code ⟨10848⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10849 : decode code ⟨10849⟩ = some (.DUP6, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10850 : decode code ⟨10850⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10851 : decode code ⟨10851⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10852 : decode code ⟨10852⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10853 : decode code ⟨10853⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10854 : decode code ⟨10854⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10856 : decode code ⟨10856⟩ = some (.DUP6, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10857 : decode code ⟨10857⟩ = some (.DUP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10858 : decode code ⟨10858⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10859 : decode code ⟨10859⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10860 : decode code ⟨10860⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10861 : decode code ⟨10861⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10862 : decode code ⟨10862⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10865 : decode code ⟨10865⟩ = some (.DUP10, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10866 : decode code ⟨10866⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10867 : decode code ⟨10867⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10868 : decode code ⟨10868⟩ = some (.Push .PUSH1, some (⟨96⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10870 : decode code ⟨10870⟩ = some (.DUP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10871 : decode code ⟨10871⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10872 : decode code ⟨10872⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10873 : decode code ⟨10873⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10874 : decode code ⟨10874⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10875 : decode code ⟨10875⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10876 : decode code ⟨10876⟩ = some (.DUP10, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10877 : decode code ⟨10877⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10878 : decode code ⟨10878⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10880 : decode code ⟨10880⟩ = some (.DUP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10881 : decode code ⟨10881⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10882 : decode code ⟨10882⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10883 : decode code ⟨10883⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10884 : decode code ⟨10884⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10885 : decode code ⟨10885⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10887 : decode code ⟨10887⟩ = some (.DUP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10888 : decode code ⟨10888⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10889 : decode code ⟨10889⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10890 : decode code ⟨10890⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10891 : decode code ⟨10891⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10892 : decode code ⟨10892⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10894 : decode code ⟨10894⟩ = some (.Push .PUSH1, some (⟨192⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10896 : decode code ⟨10896⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10897 : decode code ⟨10897⟩ = some (.SWAP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10898 : decode code ⟨10898⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10899 : decode code ⟨10899⟩ = some (.SWAP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10900 : decode code ⟨10900⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10901 : decode code ⟨10901⟩ = some (.SWAP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10902 : decode code ⟨10902⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10903 : decode code ⟨10903⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have rd10821 := evm_run h with [ - raw jumpdest hd10817 (by evm_ov), - raw push1 ⟨64⟩ hd10818 (by evm_ov), - raw dup1 hd10820 (by evm_ov)] - have rd10822 := evm_run rd10821 with [ - raw mload 0 (UInt256.ofNat 256) (UInt256.ofNat 8) hd10821 mem_cost - (initializeObservationStoreMem_mload64 ee) - (by native_decide) (by evm_ov)] - have rd10828 := evm_run rd10822 with [ - raw push1 ⟨224⟩ hd10822 (by evm_ov), - raw dup2 hd10824 (by evm_ov), - raw add hd10825 (by evm_ov), - raw dup3 hd10826 (by evm_ov), - raw mstore 0 (initializeSlot0EventMem0 ee) (UInt256.ofNat 8) - hd10827 mem_cost rfl (by native_decide) (by evm_ov)] - have rd10840 := evm_run rd10828 with [ - raw push1 ⟨1⟩ hd10828 (by evm_ov), - raw push1 ⟨1⟩ hd10830 (by evm_ov), - raw push1 ⟨160⟩ hd10832 (by evm_ov), - raw shl hd10834 (by evm_ov), - raw sub hd10835 (by evm_ov), - raw dup9 hd10836 (by evm_ov), - raw and hd10837 (by evm_ov), - raw dup1 hd10838 (by evm_ov), - raw dup3 hd10839 (by evm_ov), - raw mstore 3 (initializeSlot0EventMem1 ee sqrt) (UInt256.ofNat 9) - hd10840 mem_cost rfl (by native_decide) (by evm_ov)] - have rd10845 := evm_run rd10840 with [ - raw push1 ⟨2⟩ hd10841 (by evm_ov), - raw dup9 hd10843 (by evm_ov), - raw dup2 hd10844 (by evm_ov)] - have rd10846 := RD.signextend rd10845 hd10845 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd10853 := evm_run rd10846 with [ - raw push1 ⟨32⟩ hd10846 (by evm_ov), - raw dup1 hd10848 (by evm_ov), - raw dup6 hd10849 (by evm_ov), - raw add hd10850 (by evm_ov), - raw dup3 hd10851 (by evm_ov), - raw swap1 hd10852 (by evm_ov), - raw mstore 3 (initializeSlot0EventMem2 ee sqrt tick) (UInt256.ofNat 10) - hd10853 mem_cost rfl (by native_decide) (by evm_ov)] - have rd10861 := evm_run rd10853 with [ - raw push1 ⟨0⟩ hd10854 (by evm_ov), - raw dup6 hd10856 (by evm_ov), - raw dup8 hd10857 (by evm_ov), - raw add hd10858 (by evm_ov), - raw dup2 hd10859 (by evm_ov), - raw swap1 hd10860 (by evm_ov), - raw mstore 3 (initializeSlot0EventMem3 ee sqrt tick) (UInt256.ofNat 11) - hd10861 mem_cost rfl (by native_decide) (by evm_ov)] - have rd10874 := evm_run rd10861 with [ - raw push2 ⟨65535⟩ hd10862 (by evm_ov), - raw dup10 hd10865 (by evm_ov), - raw dup2 hd10866 (by evm_ov), - raw and hd10867 (by evm_ov), - raw push1 ⟨96⟩ hd10868 (by evm_ov), - raw dup9 hd10870 (by evm_ov), - raw add hd10871 (by evm_ov), - raw dup2 hd10872 (by evm_ov), - raw swap1 hd10873 (by evm_ov), - raw mstore 3 (initializeSlot0EventMem4 ee sqrt tick) (UInt256.ofNat 12) - hd10874 mem_cost rfl (by native_decide) (by evm_ov)] - have rd10884 := evm_run rd10874 with [ - raw swap1 hd10875 (by evm_ov), - raw dup10 hd10876 (by evm_ov), - raw and hd10877 (by evm_ov), - raw push1 ⟨128⟩ hd10878 (by evm_ov), - raw dup9 hd10880 (by evm_ov), - raw add hd10881 (by evm_ov), - raw dup2 hd10882 (by evm_ov), - raw swap1 hd10883 (by evm_ov), - raw mstore 3 (initializeSlot0EventMem5 ee sqrt tick) (UInt256.ofNat 13) - hd10884 mem_cost rfl (by native_decide) (by evm_ov)] - have rd10891 := evm_run rd10884 with [ - raw push1 ⟨160⟩ hd10885 (by evm_ov), - raw dup9 hd10887 (by evm_ov), - raw add hd10888 (by evm_ov), - raw dup4 hd10889 (by evm_ov), - raw swap1 hd10890 (by evm_ov), - raw mstore 3 (initializeSlot0EventMem6 ee sqrt tick) (UInt256.ofNat 14) - hd10891 mem_cost rfl (by native_decide) (by evm_ov)] - have rd10898 := evm_run rd10891 with [ - raw push1 ⟨1⟩ hd10892 (by evm_ov), - raw push1 ⟨192⟩ hd10894 (by evm_ov), - raw swap1 hd10896 (by evm_ov)] - have rd10899 := RD.swap9 rd10898 hd10897 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd10904 := evm_run rd10899 with [ - raw add hd10898 (by evm_ov), - raw swap8 hd10899 (by evm_ov), - raw swap1 hd10900 (by evm_ov), - raw swap8 hd10901 (by evm_ov), - raw mstore 3 (initializeSlot0EventMem ee sqrt tick) (UInt256.ofNat 15) - hd10902 mem_cost rfl (by native_decide) (by evm_ov), - raw dup2 hd10903 (by evm_ov)] - exact ⟨_, _, by - simpa [initializeSlot0SqrtEventWord, initializeSlot0TickEventWord, - initializeSlot0ObservationCardinalityEventWord, - initializeSlot0ObservationCardinalityNextEventWord] using rd10904⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolInitializeSlot0Store {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tick sqrt ret : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨10904⟩ - (⟨0⟩ :: initializeSlot0ObservationCardinalityEventWord :: ⟨0⟩ :: ⟨32⟩ :: - initializeSlot0TickEventWord tick :: ⟨2⟩ :: initializeSlot0SqrtEventWord sqrt :: - initializeSlot0ObservationCardinalityNextEventWord :: ⟨64⟩ :: ⟨1⟩ :: ⟨1⟩ :: - ⟨0⟩ :: ⟨0⟩ :: tick :: sqrt :: ret :: R) - (initializeSlot0EventMem ee sqrt tick) (UInt256.ofNat 15) rdata (cA, σ) k C) - (hperm : ee.perm = true) - (hov : R.length + 24 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11075⟩ - (⟨32⟩ :: initializeSlot0SqrtEventWord sqrt :: initializeSlot0TickEventWord tick :: - ⟨64⟩ :: ⟨1⟩ :: ⟨1⟩ :: ⟨0⟩ :: ⟨0⟩ :: tick :: sqrt :: ret :: R) - (initializeSlot0EventMem ee sqrt tick) (UInt256.ofNat 15) rdata - (cA, sstoreAccountMap ee.codeOwner σ ⟨0⟩ (initializeSlot0SstoreWord σ ee sqrt tick)) - k' C' := by - have hdecode {pc : UInt256} (hlo : 10597 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 11259) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 11259 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointBody hlo hhi)] - have hd10904 : decode code ⟨10904⟩ = some (.SLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10905 : decode code ⟨10905⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10907 : decode code ⟨10907⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10909 : decode code ⟨10909⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10910 : decode code ⟨10910⟩ = some (.Push .PUSH20, some (solcAddrMask, 20)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10931 : decode code ⟨10931⟩ = some (.NOT, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10932 : decode code ⟨10932⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10933 : decode code ⟨10933⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10934 : decode code ⟨10934⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10935 : decode code ⟨10935⟩ = some (.DUP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10936 : decode code ⟨10936⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10937 : decode code ⟨10937⟩ = some (.Push .PUSH3, some (⟨16777215⟩, 3)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10941 : decode code ⟨10941⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10943 : decode code ⟨10943⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10944 : decode code ⟨10944⟩ = some (.NOT, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10945 : decode code ⟨10945⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10946 : decode code ⟨10946⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10948 : decode code ⟨10948⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10950 : decode code ⟨10950⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10951 : decode code ⟨10951⟩ = some (.Push .PUSH3, some (⟨16777215⟩, 3)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10955 : decode code ⟨10955⟩ = some (.SWAP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10956 : decode code ⟨10956⟩ = some (.DUP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10957 : decode code ⟨10957⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10958 : decode code ⟨10958⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10959 : decode code ⟨10959⟩ = some (.SWAP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10960 : decode code ⟨10960⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10961 : decode code ⟨10961⟩ = some (.SWAP8, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10962 : decode code ⟨10962⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10963 : decode code ⟨10963⟩ = some (.SWAP7, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10964 : decode code ⟨10964⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10965 : decode code ⟨10965⟩ = some (.SWAP7, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10966 : decode code ⟨10966⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10967 : decode code ⟨10967⟩ = some (.SWAP6, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10968 : decode code ⟨10968⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10969 : decode code ⟨10969⟩ = some (.SWAP6, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10970 : decode code ⟨10970⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd10971 : - decode code ⟨10971⟩ = - some (.Push .PUSH32, some (initializeSlot0TickClearMask, 32)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11004 : decode code ⟨11004⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11005 : decode code ⟨11005⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11007 : decode code ⟨11007⟩ = some (.Push .PUSH1, some (⟨200⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11009 : decode code ⟨11009⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11010 : decode code ⟨11010⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11011 : decode code ⟨11011⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11012 : decode code ⟨11012⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11013 : decode code ⟨11013⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11014 : decode code ⟨11014⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11017 : decode code ⟨11017⟩ = some (.Push .PUSH1, some (⟨216⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11019 : decode code ⟨11019⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11020 : decode code ⟨11020⟩ = some (.NOT, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11021 : decode code ⟨11021⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11022 : decode code ⟨11022⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11024 : decode code ⟨11024⟩ = some (.Push .PUSH1, some (⟨216⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11026 : decode code ⟨11026⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11027 : decode code ⟨11027⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11028 : decode code ⟨11028⟩ = some (.SWAP7, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11029 : decode code ⟨11029⟩ = some (.MUL, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11030 : decode code ⟨11030⟩ = some (.SWAP6, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11031 : decode code ⟨11031⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11032 : decode code ⟨11032⟩ = some (.SWAP6, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11033 : decode code ⟨11033⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11034 : - decode code ⟨11034⟩ = - some (.Push .PUSH32, some (initializeSlot0UnlockedClearMask, 32)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11067 : decode code ⟨11067⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11068 : decode code ⟨11068⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11069 : decode code ⟨11069⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11070 : decode code ⟨11070⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11071 : decode code ⟨11071⟩ = some (.OR, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11072 : decode code ⟨11072⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11073 : decode code ⟨11073⟩ = some (.SWAP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11074 : decode code ⟨11074⟩ = some (.SSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - obtain ⟨_, _, rd10905₀⟩ := h.sload hd10904 (by evm_ov) - have rd10958 := evm_run rd10905₀ with [ - raw push1 ⟨1⟩ hd10905 (by evm_ov), - raw push1 ⟨240⟩ hd10907 (by evm_ov), - raw shl hd10909 (by evm_ov), - raw pushConst solcAddrMask - (show Operation.POp.PUSH20 ≠ Operation.POp.PUSH0 by native_decide) - hd10910 - (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw not hd10931 (by evm_ov), - raw swap1 hd10932 (by evm_ov), - raw swap2 hd10933 (by evm_ov), - raw and hd10934 (by evm_ov), - raw dup8 hd10935 (by evm_ov), - raw lor hd10936 (by evm_ov), - raw pushConst ⟨16777215⟩ - (show Operation.POp.PUSH3 ≠ Operation.POp.PUSH0 by native_decide) - hd10937 - (by evm_ov), - raw push1 ⟨160⟩ hd10941 (by evm_ov), - raw shl hd10943 (by evm_ov), - raw not hd10944 (by evm_ov), - raw and hd10945 (by evm_ov), - raw push1 ⟨1⟩ hd10946 (by evm_ov), - raw push1 ⟨160⟩ hd10948 (by evm_ov), - raw shl hd10950 (by evm_ov), - raw pushConst ⟨16777215⟩ - (show Operation.POp.PUSH3 ≠ Operation.POp.PUSH0 by native_decide) - hd10951 - (by evm_ov), - raw swap8 hd10955 (by evm_ov), - raw dup8 hd10956 (by evm_ov), - raw swap1 hd10957 (by evm_ov)] - have rd10959 := RD.signextend rd10958 hd10958 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega) - have rd11074 := evm_run rd10959 with [ - raw swap8 hd10959 (by evm_ov), - raw swap1 hd10960 (by evm_ov), - raw swap8 hd10961 (by evm_ov), - raw and hd10962 (by evm_ov), - raw swap7 hd10963 (by evm_ov), - raw swap1 hd10964 (by evm_ov), - raw swap7 hd10965 (by evm_ov), - raw mul hd10966 (by evm_ov), - raw swap6 hd10967 (by evm_ov), - raw swap1 hd10968 (by evm_ov), - raw swap6 hd10969 (by evm_ov), - raw lor hd10970 (by evm_ov), - raw pushConst initializeSlot0TickClearMask - (show Operation.POp.PUSH32 ≠ Operation.POp.PUSH0 by native_decide) - hd10971 - (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd11004 (by evm_ov), - raw push1 ⟨1⟩ hd11005 (by evm_ov), - raw push1 ⟨200⟩ hd11007 (by evm_ov), - raw shl hd11009 (by evm_ov), - raw swap1 hd11010 (by evm_ov), - raw swap2 hd11011 (by evm_ov), - raw mul hd11012 (by evm_ov), - raw lor hd11013 (by evm_ov), - raw push2 ⟨65535⟩ hd11014 (by evm_ov), - raw push1 ⟨216⟩ hd11017 (by evm_ov), - raw shl hd11019 (by evm_ov), - raw not hd11020 (by evm_ov), - raw and hd11021 (by evm_ov), - raw push1 ⟨1⟩ hd11022 (by evm_ov), - raw push1 ⟨216⟩ hd11024 (by evm_ov), - raw shl hd11026 (by evm_ov), - raw swap1 hd11027 (by evm_ov), - raw swap7 hd11028 (by evm_ov), - raw mul hd11029 (by evm_ov), - raw swap6 hd11030 (by evm_ov), - raw swap1 hd11031 (by evm_ov), - raw swap6 hd11032 (by evm_ov), - raw lor hd11033 (by evm_ov), - raw pushConst initializeSlot0UnlockedClearMask - (show Operation.POp.PUSH32 ≠ Operation.POp.PUSH0 by native_decide) - hd11034 - (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd11067 (by evm_ov), - raw swap3 hd11068 (by evm_ov), - raw swap1 hd11069 (by evm_ov), - raw swap3 hd11070 (by evm_ov), - raw lor hd11071 (by evm_ov), - raw swap1 hd11072 (by evm_ov), - raw swap4 hd11073 (by evm_ov)] - obtain ⟨_, _, rd11075⟩ := rd11074.sstore hperm hd11074 (by evm_ov) - norm_num at rd11075 - exact ⟨_, _, by - simpa [initializeSlot0SstoreWord, initializeSlot0SqrtEventWord, - initializeSlot0TickEventWord, initializeSlot0ObservationCardinalityEventWord, - initializeSlot0ObservationCardinalityNextEventWord, codeOwnerStorageWord] using rd11075⟩ - -set_option maxRecDepth 4096 in -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolInitializeSlot0LogAndReturn {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {tick sqrt : UInt256} {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11075⟩ - (⟨32⟩ :: initializeSlot0SqrtEventWord sqrt :: initializeSlot0TickEventWord tick :: - ⟨64⟩ :: ⟨1⟩ :: ⟨1⟩ :: ⟨0⟩ :: ⟨0⟩ :: tick :: sqrt :: ⟨857⟩ :: R) - (initializeSlot0EventMem ee sqrt tick) (UInt256.ofNat 15) rdata (cA, σ) k C) - (hperm : ee.perm = true) - (hov : R.length + 16 ≤ 1024) : - RDret code g s0 (cA, σ) ByteArray.empty := by - have hdecode {pc : UInt256} (hlo : 10597 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 11259) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 11259 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolInitializePatchDisjointBody hlo hhi)] - have hd11075 : decode code ⟨11075⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11076 : decode code ⟨11076⟩ = some (.MLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11077 : decode code ⟨11077⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11078 : decode code ⟨11078⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11079 : decode code ⟨11079⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11080 : decode code ⟨11080⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11081 : decode code ⟨11081⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11082 : decode code ⟨11082⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11083 : decode code ⟨11083⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11084 : decode code ⟨11084⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11085 : decode code ⟨11085⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11086 : decode code ⟨11086⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11087 : decode code ⟨11087⟩ = some (.MLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11088 : decode code ⟨11088⟩ = some (.SWAP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11089 : decode code ⟨11089⟩ = some (.SWAP6, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11090 : decode code ⟨11090⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11091 : decode code ⟨11091⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11092 : decode code ⟨11092⟩ = some (.SWAP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11093 : decode code ⟨11093⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11094 : - decode code ⟨11094⟩ = - some (.Push .PUSH32, some (initializeSlot0EventTopic, 32)) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11127 : decode code ⟨11127⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11128 : decode code ⟨11128⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11129 : decode code ⟨11129⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11130 : decode code ⟨11130⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11131 : decode code ⟨11131⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11132 : decode code ⟨11132⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11133 : decode code ⟨11133⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11134 : decode code ⟨11134⟩ = some (.LOG1, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11135 : decode code ⟨11135⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11136 : decode code ⟨11136⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11137 : decode code ⟨11137⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11138 : decode code ⟨11138⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd11139 : decode code ⟨11139⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)]; native_decide - have hd857 : decode code ⟨857⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd858 : decode code ⟨858⟩ = some (.STOP, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have rd11079 := evm_run h with [ - raw dup4 hd11075 (by evm_ov), - raw mload 0 (UInt256.ofNat 480) (UInt256.ofNat 15) hd11076 mem_cost - (initializeSlot0EventMem_mload64 ee sqrt tick) - (by native_decide) (by evm_ov), - raw swap2 hd11077 (by evm_ov), - raw dup3 hd11078 (by evm_ov)] - have rd11086 := evm_run rd11079 with [ - raw mstore 3 (initializeSlot0LogMem0 ee sqrt tick) (UInt256.ofNat 16) - hd11079 mem_cost rfl (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup2 hd11080 (by evm_ov), - raw add hd11081 (by evm_ov), - raw swap2 hd11082 (by evm_ov), - raw swap1 hd11083 (by evm_ov), - raw swap2 hd11084 (by evm_ov), - raw mstore 3 (initializeSlot0LogMem ee sqrt tick) (UInt256.ofNat 17) - hd11085 mem_cost rfl (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd11135 := evm_run rd11086 with [ - raw dup2 hd11086 (by evm_ov), - raw mload 0 (UInt256.ofNat 480) (UInt256.ofNat 17) hd11087 mem_cost - (initializeSlot0LogMem_mload64 ee sqrt tick) - (by native_decide) (by evm_ov), - raw swap4 hd11088 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw swap6 hd11089 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw pop hd11090 (by evm_ov), - raw swap2 hd11091 (by evm_ov), - raw swap4 hd11092 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw pop hd11093 (by evm_ov), - raw pushConst initializeSlot0EventTopic - (show Operation.POp.PUSH32 ≠ Operation.POp.PUSH0 by native_decide) - hd11094 - (by evm_ov), - raw swap3 hd11127 (by evm_ov), - raw swap2 hd11128 (by evm_ov), - raw dup3 hd11129 (by evm_ov), - raw swap1 hd11130 (by evm_ov), - raw sub hd11131 (by evm_ov), - raw add hd11132 (by evm_ov), - raw swap1 hd11133 (by evm_ov), - raw log1 0 (UInt256.ofNat 17) hd11134 hperm mem_cost - (by native_decide) (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega)] - have rd11139 := evm_run rd11135 with [ - raw pop hd11135 (by evm_ov), - raw pop hd11136 (by evm_ov), - raw pop hd11137 (by evm_ov), - raw pop hd11138 (by evm_ov)] - have rd857 := rd11139.jump hd11139 (uniswapV3PoolInitializeJumpDestPatched857 hpatch) - (by evm_ov) - have rd858 := rd857.jumpdest hd857 (by evm_ov) - exact rd858.stop hd858 (by - have h := hov - omega) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Liquidity.lean b/Benchmarks/UniswapV3Pool/Liquidity.lean deleted file mode 100644 index afd7ad14..00000000 --- a/Benchmarks/UniswapV3Pool/Liquidity.lean +++ /dev/null @@ -1,474 +0,0 @@ -import Benchmarks.UniswapV3Pool.Uint128 - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolLiquidityReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 2 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨646⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 2 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0x1a 0x68 0x65 0x02 - (uniswapV3PoolSelNat 2) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h239 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨239⟩) hpatch h32 hgt32 - have hgt239 : UInt256.gt (armSelNat code ⟨239⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h348 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨348⟩) hpatch h239 hgt239 - have hgt348 : UInt256.gt (armSelNat code ⟨348⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h397 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨397⟩) hpatch h348 hgt348 - have hmiss0 : (uniswapV3PoolSelBytes 0 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h408 := uniswapV3PoolSelectorArmMissToOf (i := 0) (next := ⟨408⟩) - hpatch hsz hmiss0 h397 - have hmiss1 : (uniswapV3PoolSelBytes 1 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h419 := uniswapV3PoolSelectorArmMissToOf (i := 1) (next := ⟨419⟩) - hpatch hsz hmiss1 h408 - have h646 := uniswapV3PoolSelectorArmHitTo (i := 2) (target := ⟨646⟩) - hpatch hsz hsel h419 - exact ⟨_, _, h646⟩ - -theorem uniswapV3PoolLiquidityDecode {v : PoolImmutables} {I : ExecutionEnv} - (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode (liquidityTransition.params.map Param.name) - (transitionSignature liquidityTransition).paramTypes I.calldata = some (∅ : Store) := by - simpa [config, liquidityTransition, transitionSignature] using - decodeCalldataWithMode_empty_ok (mode := DecodeMode.legacySolc05) (cd := I.calldata) hsz - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolDispatch_liquidity {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 2 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some liquidityTransition := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, factoryTransition v, - feeTransition v, feegrowthglobal0X128Transition, feegrowthglobal1X128Transition, - flashTransition v, increaseobservationcardinalitynextTransition v, initializeTransition]) - (post := [maxliquiditypertickTransition v, mintTransition v, observationsTransition, - observeTransition v, positionsTransition, protocolfeesTransition, setfeeprotocolTransition v, - slot0Transition, snapshotcumulativesinsideTransition v, swapTransition v, - tickbitmapTransition, tickspacingTransition v, ticksTransition, token0Transition v, - token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 2) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 2) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 2) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 2) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 2) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 2) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 2) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 2) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 5) (j := 2) - (by native_decide) hsel - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 25) (j := 2) - (by native_decide) hsel - · rw [selectorOf, liquiditySelectorBytes] - simpa [uniswapV3PoolSelBytes] using hsel - -/- LIBRARY CANDIDATE: generalizes Reasoning.Solc.solcAddressSlotGetterWf to 128-bit masks. -/ -@[reducible] def solcUint128SlotGetterWf - (code : ByteArray) (pc slot : UInt256) : Prop := - let p1 := pc + ⟨1⟩ - let p3 := p1 + UInt256.ofNat 2 - let p4 := p3 + ⟨1⟩ - let p6 := p4 + UInt256.ofNat 2 - let p8 := p6 + UInt256.ofNat 2 - let p10 := p8 + UInt256.ofNat 2 - let p11 := p10 + ⟨1⟩ - let p12 := p11 + ⟨1⟩ - let p13 := p12 + ⟨1⟩ - let p14 := p13 + ⟨1⟩ - decode code pc = some (.JUMPDEST, .none) - ∧ decode code p1 = some (.Push .PUSH1, some (slot, 1)) - ∧ decode code p3 = some (.SLOAD, .none) - ∧ decode code p4 = some (.Push .PUSH1, some (⟨1⟩, 1)) - ∧ decode code p6 = some (.Push .PUSH1, some (⟨1⟩, 1)) - ∧ decode code p8 = some (.Push .PUSH1, some (⟨128⟩, 1)) - ∧ decode code p10 = some (.SHL, .none) - ∧ decode code p11 = some (.SUB, .none) - ∧ decode code p12 = some (.AND, .none) - ∧ decode code p13 = some (.DUP2, .none) - ∧ decode code p14 = some (.JUMP, .none) - -theorem RD.solcUint128SlotGetter {code : ByteArray} {g : Sat256} {s0 : State} - {ee : ExecutionEnv} {k C : ℕ} {pc slot ret : UInt256} {R : List UInt256} - {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - (h : RD code ee g s0 pc (ret :: R) mem aw rdata (cA, σ) k C) - (hwf : solcUint128SlotGetterWf code pc slot) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 6 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret - (UInt256.land uint128Mask - (σ.find? ee.codeOwner |>.option ⟨0⟩ (fun acc => acc.storage.findD slot ⟨0⟩)) :: - ret :: R) mem aw rdata (cA, σ) k' C' := by - rcases hwf with ⟨hd0, hd1, hd2, hd3, hd4, hd5, hd6, hd7, hd8, hd9, hd10⟩ - have rd1 := h.jumpdest hd0 (by simp only [List.length_cons]; omega) - have rd3 := rd1.push1 slot hd1 (by simp only [List.length_cons]; omega) - obtain ⟨_, _, rd4⟩ := rd3.sload hd2 (by simp only [List.length_cons]; omega) - have rd6 := rd4.push1 ⟨1⟩ hd3 (by simp only [List.length_cons]; omega) - have rd8 := rd6.push1 ⟨1⟩ hd4 (by simp only [List.length_cons]; omega) - have rd10 := rd8.push1 ⟨128⟩ hd5 (by simp only [List.length_cons]; omega) - have rd11 := rd10.shl hd6 (by simp only [List.length_cons]; omega) - have rd12 := rd11.sub hd7 (by simp only [List.length_cons]; omega) - have rd13 := rd12.and hd8 (by simp only [List.length_cons]; omega) - have rd14 := rd13.dup2 hd9 (by omega) - have rdRet := rd14.jump hd10 hret (by simp only [List.length_cons]; omega) - have hmask : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨1⟩ = uint128Mask := by - native_decide - exact ⟨_, _, by simpa [hmask] using rdRet⟩ - -/- LIBRARY CANDIDATE: generalizes Reasoning.Solc.solcReturnAddressFromMemWf to 128-bit masks. -/ -@[reducible] def solcReturnUint128FromMemWf (code : ByteArray) (pc : UInt256) : Prop := - decode code pc = some (.JUMPDEST, .none) - ∧ decode code (pc + ⟨1⟩) = some (.Push .PUSH1, some (⟨64⟩, 1)) - ∧ decode code (pc + ⟨1⟩ + UInt256.ofNat 2) = some (.DUP1, .none) - ∧ decode code (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩) = some (.MLOAD, .none) - ∧ decode code (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩) = - some (.Push .PUSH1, some (⟨1⟩, 1)) - ∧ decode code (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2) = - some (.Push .PUSH1, some (⟨1⟩, 1)) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2) = - some (.Push .PUSH1, some (⟨128⟩, 1)) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2) = - some (.SHL, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩) = - some (.SUB, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩) = - some (.SWAP1, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) = - some (.SWAP3, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) = - some (.AND, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - ⟨1⟩) = - some (.DUP3, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - ⟨1⟩ + ⟨1⟩) = - some (.MSTORE, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - ⟨1⟩ + ⟨1⟩ + ⟨1⟩) = - some (.MLOAD, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) = - some (.SWAP1, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) = - some (.DUP2, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) = - some (.SWAP1, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) = - some (.SUB, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) = - some (.Push .PUSH1, some (⟨32⟩, 1)) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - UInt256.ofNat 2) = - some (.ADD, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - UInt256.ofNat 2 + ⟨1⟩) = - some (.SWAP1, .none) - ∧ decode code - (pc + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - UInt256.ofNat 2 + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + - UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩) = - some (.RETURN, .none) - -theorem RD.solcReturnUint128FromMem {code : ByteArray} {g : Sat256} {s0 : State} - {ee : ExecutionEnv} {k C : ℕ} {pc val ret : UInt256} {R : List UInt256} - {mem memout rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - (h : RD code ee g s0 pc (val :: ret :: R) mem (UInt256.ofNat 3) rdata acc k C) - (hwf : solcReturnUint128FromMemWf code pc) - (hmload64 : - (if (⟨64⟩ : UInt256).toNat ≥ mem.size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 3 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (mem.readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩) - (hmemout : - (UInt256.toByteArray (UInt256.land val uint128Mask)).write 0 mem 128 32 = memout) - (hmemoutLoad64 : - (if (⟨64⟩ : UInt256).toNat ≥ memout.size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 5 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (memout.readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩) - (hread128 : memout.readWithPadding 128 32 = - UInt256.toByteArray (UInt256.land val uint128Mask)) - (hov : R.length + 9 ≤ 1024) : - RDret code g s0 acc (UInt256.toByteArray (UInt256.land val uint128Mask)) := by - rcases hwf with - ⟨hd0, hd1, hd3, hd4, hd5, hd7, hd9, hd11, hd12, hd13, hd14, hd15, hd16, hd17, - hd18, hd19, hd20, hd21, hd22, hd23, hd25, hd26, hd27⟩ - exact evm_run h with [ - raw jumpdest hd0 (by evm_ov), - raw push1 ⟨64⟩ hd1 (by evm_ov), - raw dup1 hd3 (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) hd4 mem_cost hmload64 (by decide) (by evm_ov), - raw push1 ⟨1⟩ hd5 (by evm_ov), - raw push1 ⟨1⟩ hd7 (by evm_ov), - raw push1 ⟨128⟩ hd9 (by evm_ov), - raw shl hd11 (by evm_ov), - raw sub hd12 (by evm_ov), - raw swap1 hd13 (by evm_ov), - raw swap3 hd14 (by evm_ov), - raw and hd15 (by evm_ov), - raw dup3 hd16 (by evm_ov), - raw mstore 6 memout (UInt256.ofNat 5) hd17 mem_cost - (by - rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨1⟩ = - uint128Mask from by native_decide, - show (⟨128⟩ : UInt256).toNat = 128 from by decide] - exact hmemout) - (by decide) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 5) hd18 mem_cost hmemoutLoad64 (by decide) - (by evm_ov), - raw swap1 hd19 (by evm_ov), - raw dup2 hd20 (by evm_ov), - raw swap1 hd21 (by evm_ov), - raw sub hd22 (by evm_ov), - raw push1 ⟨32⟩ hd23 (by evm_ov), - raw add hd25 (by evm_ov), - raw swap1 hd26 (by evm_ov), - raw ret 0 (UInt256.toByteArray (UInt256.land val uint128Mask)) hd27 mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - show ((⟨32⟩ : UInt256) + UInt256.sub (⟨128⟩ : UInt256) ⟨128⟩).toNat = 32 - from by decide] - exact hread128) - (by evm_ov)] - -theorem RD.solcUint128GetterExternal {code : ByteArray} {cA gh bl σ σ₀ A I} - {g : Sat256} {sel entry routine slot returnPc : UInt256} - (hreach : ∃ k C, RD code I g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) - entry [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hentry : solcGetterEntryWf code entry returnPc routine) - (hgetter : solcUint128SlotGetterWf code routine slot) - (hroutine : (D_J code 0).contains routine = true) - (hret : (D_J code 0).contains returnPc = true) - (hreturn : solcReturnUint128FromMemWf code returnPc) : - RDret code g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land (solcSlotWord σ I slot) uint128Mask)) := by - obtain ⟨_, _, rdRoutine⟩ := RD.solcGetterThunk hreach hentry hroutine - obtain ⟨_, _, rdReturn⟩ := RD.solcUint128SlotGetter (slot := slot) (R := [sel]) - rdRoutine hgetter hret (by simp only [List.length_singleton]; omega) - have hrd := RD.solcReturnUint128FromMem rdReturn hreturn - solcFreePtrMem_mload64 - (by rfl) - (solcReturnMem_mload64 - (UInt256.land (UInt256.land uint128Mask (solcSlotWord σ I slot)) uint128Mask)) - (solcReturnMem_read128 - (UInt256.land (UInt256.land uint128Mask (solcSlotWord σ I slot)) uint128Mask)) - (by simp only [List.length_singleton]; omega) - have hclean : - UInt256.land (UInt256.land uint128Mask (solcSlotWord σ I slot)) uint128Mask = - UInt256.land (solcSlotWord σ I slot) uint128Mask := by - rw [u256_land_comm uint128Mask (solcSlotWord σ I slot)] - exact uint128Mask_clean (uint128Mask_bound (solcSlotWord σ I slot)) - simpa [hclean] using hrd - -private theorem uniswapV3PoolLiquidityPatchDisjoint {v : PoolImmutables} {pc : UInt256} - (hlo : 5293 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 6603) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> - omega - -theorem uniswapV3PoolLiquidityEntryWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcGetterEntryWf code ⟨646⟩ ⟨654⟩ ⟨5293⟩ := by - dsimp [solcGetterEntryWf] - refine ⟨?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolLiquidityGetterWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcUint128SlotGetterWf code ⟨5293⟩ ⟨4⟩ := by - dsimp [solcUint128SlotGetterWf] - refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolLiquidityPatchDisjoint (by native_decide) (by native_decide))] - native_decide - -theorem uniswapV3PoolLiquidityReturnWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcReturnUint128FromMemWf code ⟨654⟩ := by - dsimp [solcReturnUint128FromMemWf] - refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, - ?_, ?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolLiquidityReturnJumpDest {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨654⟩ = true := - uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide) - -theorem uniswapV3PoolLiquidityEvm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 2 == I.calldata.extract 0 4) = true) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land (solcSlotWord σ I ⟨4⟩) uint128Mask)) := by - have hreach := uniswapV3PoolLiquidityReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - exact RD.solcUint128GetterExternal (slot := ⟨4⟩) hreach - (uniswapV3PoolLiquidityEntryWf hpatch) - (uniswapV3PoolLiquidityGetterWf hpatch) - (uniswapV3PoolJumpDestPatched5293 hpatch) - (uniswapV3PoolLiquidityReturnJumpDest hpatch) - (uniswapV3PoolLiquidityReturnWf hpatch) - -theorem uniswapV3PoolLiquiditySourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) liquidityTransition.body - (.returned { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) - (some [Value.int (Int.ofNat - (UInt256.land (solcSlotWord σ I ⟨4⟩) uint128Mask).toNat)])) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [.storage liquidityRef] ] _ - apply nonpayableReturnExprBodyReturns - · simp [initState, hwv] - · apply evalExpr_storage_scalar_value - (er := { base := "liquidity", steps := [] }) - (t := .int uint128Int) - (loc := loc ⟨4⟩ ⟨0, by decide⟩ ⟨16, by decide⟩ (by decide) (.int uint128Int)) - · simp [liquidityRef] - · simp [evalStorageRef, liquidityRef, pure, bind, EvalResult.bind] - · simp [contract, storageDecls, storageTypeAt?, uint128St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc] - · simpa [initState, solcSlotWord, loc] using - (storageLocLoad_uint_offset0 (initState cA gh bl σ σ₀ g A I) ⟨4⟩ - ⟨16, by decide⟩ ⟨128, by decide⟩ (hbound := by decide) (by decide)) - -theorem uniswapV3PoolLiquidityValueTransport {σ_evm σ_solm : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - some [Value.int (Int.ofNat (UInt256.land (solcSlotWord σ_solm I ⟨4⟩) uint128Mask).toNat)] = - some [Value.int (Int.ofNat (UInt256.land (solcSlotWord σ_evm I ⟨4⟩) uint128Mask).toNat)] := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨4⟩ (⟨0⟩ : UInt256) - dsimp [solcSlotWord] - rw [← hslot] - -theorem uniswapV3PoolLiquidityBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 2 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_liquidity (v := v) (cd := I.calldata) hsel - have hdecode := uniswapV3PoolLiquidityDecode (v := v) (I := I) hsz - have hbody := uniswapV3PoolLiquiditySourceBody (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hvalue := uniswapV3PoolLiquidityValueTransport (σ_evm := σ_evm) - (σ_solm := σ_solm) (I := I) hAccounts - have hrd := uniswapV3PoolLiquidityEvm (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel - exact hrd.reEquivExecutionTransport hcode hdispatch hdecode hbody hvalue hAccounts - (returnEquiv_of_encode (uint128ReturnEncodingMasked (solcSlotWord σ_evm I ⟨4⟩))) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Locking.lean b/Benchmarks/UniswapV3Pool/Locking.lean deleted file mode 100644 index 57ed4b76..00000000 --- a/Benchmarks/UniswapV3Pool/Locking.lean +++ /dev/null @@ -1,290 +0,0 @@ -import Benchmarks.UniswapV3Pool.Slot0 - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev slot0UnlockedLoc : StorageLoc := - loc ⟨0⟩ ⟨30, by decide⟩ ⟨1, by decide⟩ (by decide) .bool - -abbrev slot0UnlockedClearMask : UInt256 := - UInt256.lnot (UInt256.shiftLeft (UInt256.ofNat (2 ^ 8 - 1)) ⟨240⟩) - -abbrev slot0UnlockedTrueSlotWord (evm : EVM.State) : UInt256 := - UInt256.ofNat - ((Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 240 + - 2 ^ 240 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 248 * - 2 ^ 248) - -abbrev slot0AfterUnlockState (evm : EVM.State) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (slot0UnlockedTrueSlotWord evm) - -theorem slot0UnlockedClearMask_toNat : - slot0UnlockedClearMask.toNat = 2 ^ 256 - 2 ^ 248 + (2 ^ 240 - 1) := by - native_decide - -theorem slot0UnlockedTrueSlotWord_nat_lt (evm : EVM.State) : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 240 + - 2 ^ 240 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 248 * - 2 ^ 248 < - UInt256.size := by - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - have hlow : w.toNat % 2 ^ 240 ≤ 2 ^ 240 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 248 < 2 ^ 8 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 248 * 2 ^ 8 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 248 ≤ 2 ^ 8 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 240 - 1) + 2 ^ 240 + (2 ^ 8 - 1) * 2 ^ 248 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - dsimp [w] at hlow hhigh - omega - -theorem natLandClearSlot0UnlockedByte (n : Nat) (hn : n < 2 ^ 256) : - Nat.land n (2 ^ 256 - 2 ^ 248 + (2 ^ 240 - 1)) = - n % 2 ^ 240 + (n / 2 ^ 248) * 2 ^ 248 := by - apply Nat.eq_of_testBit_eq - intro i - change (n &&& (2 ^ 256 - 2 ^ 248 + (2 ^ 240 - 1))).testBit i = - (n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248).testBit i - rw [Nat.testBit_and] - rw [show n % 2 ^ 240 + (n / 2 ^ 248) * 2 ^ 248 = - 2 ^ 248 * (n / 2 ^ 248) + n % 2 ^ 240 by ring] - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 248) - (b_lt := lt_trans (Nat.mod_lt _ (by positivity : 0 < 2 ^ 240)) - (by norm_num : 2 ^ 240 < 2 ^ 248))] - rw [show 2 ^ 256 - 2 ^ 248 + (2 ^ 240 - 1) = - 2 ^ 248 * (2 ^ 8 - 1) + (2 ^ 240 - 1) by norm_num [Nat.pow_add]] - have hmaskLow : 2 ^ 240 - 1 < 2 ^ 248 := by norm_num - rw [Nat.testBit_two_pow_mul_add (a := 2 ^ 8 - 1) (b_lt := hmaskLow)] - by_cases hi248 : i < 248 - · simp [hi248] - change (n.testBit i && (2 ^ 240 - 1).testBit i) = (n % 2 ^ 240).testBit i - by_cases hi240 : i < 240 - · have hmask : (2 ^ 240 - 1).testBit i = true := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_true hi240 - have hmod : (n % 2 ^ 240).testBit i = n.testBit i := by - rw [Nat.testBit_mod_two_pow] - simp [hi240] - rw [hmask, hmod] - simp - · have hmask : (2 ^ 240 - 1).testBit i = false := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_false hi240 - have hmod : (n % 2 ^ 240).testBit i = false := by - rw [Nat.testBit_mod_two_pow] - simp [hi240] - rw [hmask, hmod] - simp - · have h248le : 248 ≤ i := Nat.le_of_not_gt hi248 - simp [hi248] - change (n.testBit i && (2 ^ 8 - 1).testBit (i - 248)) = - (n / 2 ^ 248).testBit (i - 248) - by_cases hi256 : i < 256 - · have hsub8 : i - 248 < 8 := by omega - have hdiv := divPow_testBit n 248 i h248le - have hmask : (2 ^ 8 - 1).testBit (i - 248) = true := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_true hsub8 - rw [hdiv, hmask] - simp - · have hsub8 : ¬ i - 248 < 8 := by omega - have hnbit : n.testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hn (Nat.pow_le_pow_right (by norm_num) (by omega : 256 ≤ i))) - have hdivfalse : (n / 2 ^ 248).testBit (i - 248) = false := by - rw [divPow_testBit n 248 i h248le, hnbit] - have hmask : (2 ^ 8 - 1).testBit (i - 248) = false := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_false hsub8 - rw [hmask, hdivfalse] - simp - -theorem storageLocStore_slot0Unlocked_false (evm : EVM.State) : - storageLocStore evm slot0UnlockedLoc (.bool false) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - slot0UnlockedClearMask)) := by - unfold storageLocStore storageLocWriteWord slot0UnlockedLoc loc - simp only [valueToWord, Bool.toUInt256_false, bind, Option.bind] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner { val := 0 } - show fromBytes' - ((List.take 30 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0))) ++ - List.drop (30 + 1) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (UInt256.land w slot0UnlockedClearMask).toNat - rw [show List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0)) = - ([0] : List UInt8) by - native_decide] - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [u256_land_toNat, slot0UnlockedClearMask_toNat] - rw [natLandClearSlot0UnlockedByte w.toNat w.val.isLt] - have hsumLt : - w.toNat % 2 ^ 240 + w.toNat / 2 ^ 248 * 2 ^ 248 < UInt256.size := by - rw [← natLandClearSlot0UnlockedByte w.toNat w.val.isLt] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [UInt256.size]) - rw [Nat.mod_eq_of_lt hsumLt] - have hlen30 : (List.take 30 (EVM.Word.toBytesLEWithSizeProof w).1).length = 30 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - have hlen31 : (List.take 30 (EVM.Word.toBytesLEWithSizeProof w).1 ++ [0]).length = 31 := by - rw [List.length_append, hlen30] - norm_num - rw [hlen30] - rw [hlen31] - simp [fromBytes'] - ring - -theorem natLorSlot0UnlockedByte (n byte : Nat) (hbyte : byte < 2 ^ 8) : - Nat.lor (n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248) (byte * 2 ^ 240) = - n % 2 ^ 240 + byte * 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248 := by - apply Nat.eq_of_testBit_eq - intro i - change ((n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248) ||| (byte * 2 ^ 240)).testBit i = - (n % 2 ^ 240 + byte * 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248).testBit i - rw [Nat.testBit_or] - rw [show n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248 = - 2 ^ 248 * (n / 2 ^ 248) + n % 2 ^ 240 by ring] - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 248) - (b_lt := lt_trans (Nat.mod_lt _ (show 0 < 2 ^ 240 by norm_num)) - (by norm_num : 2 ^ 240 < 2 ^ 248))] - rw [show n % 2 ^ 240 + byte * 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248 = - 2 ^ 248 * (n / 2 ^ 248) + (2 ^ 240 * byte + n % 2 ^ 240) by ring] - have hmid : 2 ^ 240 * byte + n % 2 ^ 240 < 2 ^ 248 := by - have hlow : n % 2 ^ 240 ≤ 2 ^ 240 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (show 0 < 2 ^ 240 by norm_num)) - have hbytele : byte ≤ 2 ^ 8 - 1 := Nat.le_pred_of_lt hbyte - have hmax : 2 ^ 240 * (2 ^ 8 - 1) + (2 ^ 240 - 1) < 2 ^ 248 := by - norm_num [Nat.pow_add] - nlinarith - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 248) (b_lt := hmid)] - rw [Nat.testBit_two_pow_mul_add (a := byte) - (b_lt := Nat.mod_lt _ (show 0 < 2 ^ 240 by norm_num))] - rw [show byte * 2 ^ 240 = 2 ^ 240 * byte + 0 by ring] - rw [Nat.testBit_two_pow_mul_add (a := byte) (b_lt := show 0 < 2 ^ 240 by norm_num)] - by_cases hi240 : i < 240 - · simp [hi240] - · have h240le : 240 ≤ i := Nat.le_of_not_gt hi240 - have hlowfalse : (n % 2 ^ 240).testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le (Nat.mod_lt _ (show 0 < 2 ^ 240 by norm_num)) - (Nat.pow_le_pow_right (by norm_num) h240le)) - by_cases hi248 : i < 248 - · simp [hi240, hi248] - intro hlowtrue - have hlowfalse' : - (n % 1766847064778384329583297500742918515827483896875618958121606201292619776).testBit i = - false := by - simpa using hlowfalse - rw [hlowfalse'] at hlowtrue - cases hlowtrue - · have hbytefalse : byte.testBit (i - 240) = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hbyte (Nat.pow_le_pow_right (by norm_num) (by omega))) - simp [hi240, hi248] - intro hbytetrue - rw [hbytefalse] at hbytetrue - cases hbytetrue - -theorem natLorSlot0UnlockedTrueByte (n : Nat) : - Nat.lor (n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248) (2 ^ 240) = - n % 2 ^ 240 + 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248 := by - simpa using natLorSlot0UnlockedByte n 1 (by norm_num : 1 < 2 ^ 8) - -theorem slot0UnlockedTrueSlotWord_eq_of_accountMapEquiv - {evm : EVM.State} {σ : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ evm.accountMap) (hEnv : evm.executionEnv = I) : - UInt256.lor - (UInt256.shiftLeft ⟨1⟩ ⟨240⟩) - (UInt256.land slot0UnlockedClearMask (codeOwnerStorageWord I σ ⟨0⟩)) = - slot0UnlockedTrueSlotWord evm := by - have hload : - Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ = - codeOwnerStorageWord I σ ⟨0⟩ := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ (⟨0⟩ : UInt256) - simpa [Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage, - codeOwnerStorageWord, hEnv] using hslot.symm - have hclearLt : - (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 240 + - (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 248 * 2 ^ 248 < - UInt256.size := by - rw [← natLandClearSlot0UnlockedByte - (codeOwnerStorageWord I σ ⟨0⟩).toNat (codeOwnerStorageWord I σ ⟨0⟩).val.isLt] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [UInt256.size]) - have htrueLt : - (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 240 + 2 ^ 240 + - (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 248 * 2 ^ 248 < - UInt256.size := by - let w := codeOwnerStorageWord I σ ⟨0⟩ - have hlow : w.toNat % 2 ^ 240 ≤ 2 ^ 240 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 248 < 2 ^ 8 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 248 * 2 ^ 8 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 248 ≤ 2 ^ 8 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 240 - 1) + 2 ^ 240 + (2 ^ 8 - 1) * 2 ^ 248 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - dsimp [w] at hlow hhigh - omega - apply u256_inj - rw [slot0UnlockedTrueSlotWord, hload, u256_lor_toNat, u256_land_toNat] - rw [slot0UnlockedClearMask_toNat] - rw [nat_land_comm, natLandClearSlot0UnlockedByte] - rw [Nat.mod_eq_of_lt hclearLt] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨240⟩).toNat = 2 ^ 240 by - native_decide] - rw [nat_lor_comm, natLorSlot0UnlockedTrueByte] - rw [Nat.mod_eq_of_lt htrueLt] - exact (ulit_toNat' _ htrueLt).symm - exact (codeOwnerStorageWord I σ ⟨0⟩).val.isLt - -theorem storageLocStore_slot0Unlocked_true (evm : EVM.State) : - storageLocStore evm slot0UnlockedLoc (.bool true) = - some (slot0AfterUnlockState evm) := by - unfold storageLocStore storageLocWriteWord slot0UnlockedLoc loc - simp only [valueToWord, Bool.toUInt256_true, bind, Option.bind] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner { val := 0 } - show fromBytes' - ((List.take 30 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1))) ++ - List.drop (30 + 1) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (slot0UnlockedTrueSlotWord evm).toNat - rw [show List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1)) = - ([1] : List UInt8) by - native_decide] - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [show 256 ^ (30 : Nat) = 2 ^ 240 by norm_num [Nat.pow_add]] - rw [show 256 ^ (31 : Nat) = 2 ^ 248 by norm_num [Nat.pow_add]] - have hlen30 : (List.take 30 (EVM.Word.toBytesLEWithSizeProof w).1).length = 30 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - have hlen31 : (List.take 30 (EVM.Word.toBytesLEWithSizeProof w).1 ++ [1]).length = 31 := by - rw [List.length_append, hlen30] - norm_num - rw [hlen30, hlen31] - rw [show (slot0UnlockedTrueSlotWord evm).toNat = - w.toNat % 2 ^ 240 + 2 ^ 240 + w.toNat / 2 ^ 248 * 2 ^ 248 by - dsimp [slot0UnlockedTrueSlotWord, w] - exact ulit_toNat' _ (slot0UnlockedTrueSlotWord_nat_lt evm)] - simp [fromBytes'] - ring - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/MaxLiquidityPerTick.lean b/Benchmarks/UniswapV3Pool/MaxLiquidityPerTick.lean deleted file mode 100644 index dc291704..00000000 --- a/Benchmarks/UniswapV3Pool/MaxLiquidityPerTick.lean +++ /dev/null @@ -1,393 +0,0 @@ -import Benchmarks.UniswapV3Pool.Liquidity - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -private theorem uniswapV3PoolPatchPreservesJumpDest8172 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨8172⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched8172 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨8172⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest8172 - -theorem uniswapV3PoolMaxLiquidityPerTickReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 13 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1478⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 13 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0x70 0xcf 0x75 0x4a - (uniswapV3PoolSelNat 13) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h43 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨43⟩) hpatch h32 hgt32 - have hgt43 : UInt256.gt (armSelNat code ⟨43⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h152 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨152⟩) hpatch h43 hgt43 - have hgt152 : UInt256.gt (armSelNat code ⟨152⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h201 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨201⟩) hpatch h152 hgt152 - have h1478 := uniswapV3PoolSelectorArmHitTo (i := 13) (target := ⟨1478⟩) - hpatch hsz hsel h201 - exact ⟨_, _, h1478⟩ - -theorem uniswapV3PoolMaxLiquidityPerTickDecode {v : PoolImmutables} {I : ExecutionEnv} - (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - ((maxliquiditypertickTransition v).params.map Param.name) - (transitionSignature (maxliquiditypertickTransition v)).paramTypes I.calldata = - some (∅ : Store) := by - simpa [config, maxliquiditypertickTransition, transitionSignature] using - decodeCalldataWithMode_empty_ok (mode := DecodeMode.legacySolc05) (cd := I.calldata) hsz - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolDispatch_maxLiquidityPerTick {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 13 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some (maxliquiditypertickTransition v) := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, - factoryTransition v, feeTransition v, feegrowthglobal0X128Transition, - feegrowthglobal1X128Transition, flashTransition v, - increaseobservationcardinalitynextTransition v, initializeTransition, liquidityTransition]) - (post := [mintTransition v, observationsTransition, observeTransition v, positionsTransition, - protocolfeesTransition, setfeeprotocolTransition v, slot0Transition, - snapshotcumulativesinsideTransition v, swapTransition v, tickbitmapTransition, - tickspacingTransition v, ticksTransition, token0Transition v, token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 13) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 13) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 13) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 13) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 13) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 13) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 13) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 13) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 5) (j := 13) - (by native_decide) hsel - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 25) (j := 13) - (by native_decide) hsel - · rw [selectorOf, liquiditySelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 2) (j := 13) - (by native_decide) hsel - · rw [selectorOf, maxLiquidityPerTickSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hsel - -theorem uniswapV3PoolMaxLiquidityPerTickPatchWord {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - code.extract 8174 8206 = UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick) := by - let value := UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick) - let pre : List (Nat × ByteArray) := - [(8315, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (8829, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (10457, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (2258, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4853, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (6740, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (7822, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (9150, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (15650, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4551, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (6789, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (7924, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (9284, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (10529, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (15979, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (3311, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6603, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6658, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (10565, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (3072, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (10493, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19402, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19452, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing))] - let post : List (Nat × ByteArray) := - [(19295, value), (19350, value), - (11259, UInt256.toByteArray (EVM.Word.ofNat v.original.toNat))] - have hpatch' : patchRuntime uniswapV3PoolBytecode (pre ++ (8174, value) :: post) = - some code := by - dsimp [pre, post, value] - simpa [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup, - toByteArray_eq_toBytesBE] using hpatch - have hpost : ∀ p ∈ post, 8174 + 32 ≤ p.1 ∨ p.1 + 32 ≤ 8174 := by - intro p hp - dsimp [post] at hp - simp at hp - rcases hp with rfl | rfl | rfl - all_goals omega - have hsize : value.size = 32 := by - dsimp [value] - exact toByteArray_size _ - exact patchRuntime_extract_patch hsize hpost hpatch' - -theorem uniswapV3PoolMaxLiquidityPerTickConstDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨8173⟩ = - some (.Push .PUSH32, some (EVM.wordOfInt v.maxLiquidityPerTick, 32)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have hget : code.get? ({ val := 8173 } : UInt256).toNat = - uniswapV3PoolBytecode.get? ({ val := 8173 } : UInt256).toNat := by - change code.get? 8173 = uniswapV3PoolBytecode.get? 8173 - apply get?_eq_of_extract_one - · rw [hsize] - native_decide - · native_decide - · exact patchRuntime_extract_eq (start := 8173) (stop := 8174) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by native_decide) - (fun p hp => by - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl - all_goals omega) hpatch - have hextract : code.extract' ({ val := 8173 } : UInt256).toNat.succ - (({ val := 8173 } : UInt256).toNat.succ + 32) = - UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick) := by - change code.extract' 8174 8206 = - UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick) - unfold ByteArray.extract' - have hguard : (decide (8174 < 2 ^ 64) && decide (8206 < 2 ^ 64)) = true := by - native_decide - rw [if_pos hguard] - exact uniswapV3PoolMaxLiquidityPerTickPatchWord hpatch - have hgetSome : code.get? ({ val := 8173 } : UInt256).toNat = some 0x7f := by - rw [hget] - native_decide - have hparse : (some (0x7f : UInt8) >>= parseInstr) = some (.Push .PUSH32) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH32, - some (uInt256OfByteArray - (code.extract' ({ val := 8173 } : UInt256).toNat.succ - (({ val := 8173 } : UInt256).toNat.succ + 32)), 32)) = - some (Operation.Push Operation.POp.PUSH32, - some (EVM.wordOfInt v.maxLiquidityPerTick, 32)) - rw [hextract, uInt256OfByteArray_eq, fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - -theorem uniswapV3PoolMaxLiquidityPerTickGetterJumpdestDecode {v : PoolImmutables} - {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨8172⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8172⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 8173 ≤ p.1 ∨ p.1 + 32 ≤ 8172 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolMaxLiquidityPerTickGetterDupDecode {v : PoolImmutables} - {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨8206⟩ = some (.DUP2, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8206⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 8207 ≤ p.1 ∨ p.1 + 32 ≤ 8206 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolMaxLiquidityPerTickGetterJumpDecode {v : PoolImmutables} - {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨8207⟩ = some (.JUMP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8207⟩) (byte := 0x56) - (op := .JUMP) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 8208 ≤ p.1 ∨ p.1 + 32 ≤ 8207 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolMaxLiquidityPerTickEntryWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcGetterEntryWf code ⟨1478⟩ ⟨654⟩ ⟨8172⟩ := by - dsimp [solcGetterEntryWf] - refine ⟨?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolMaxLiquidityPerTickGetterWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcConstGetterWf code ⟨8172⟩ (EVM.wordOfInt v.maxLiquidityPerTick) 32 .PUSH32 := by - dsimp [solcConstGetterWf] - refine ⟨?_, ?_, ?_, ?_, ?_⟩ - · exact uniswapV3PoolMaxLiquidityPerTickGetterJumpdestDecode hpatch - · native_decide - · exact uniswapV3PoolMaxLiquidityPerTickConstDecode hpatch - · exact uniswapV3PoolMaxLiquidityPerTickGetterDupDecode hpatch - · exact uniswapV3PoolMaxLiquidityPerTickGetterJumpDecode hpatch - -theorem RD.solcUint128ConstGetterExternal {code : ByteArray} {cA gh bl σ σ₀ A I} - {g : Sat256} {sel entry routine returnPc val : UInt256} {width : Nat} - {op : Operation.POp} - (hreach : ∃ k C, RD code I g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) - entry [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hentry : solcGetterEntryWf code entry returnPc routine) - (hgetter : solcConstGetterWf code routine val width op) - (hroutine : (D_J code 0).contains routine = true) - (hret : (D_J code 0).contains returnPc = true) - (hreturn : solcReturnUint128FromMemWf code returnPc) : - RDret code g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land val uint128Mask)) := by - obtain ⟨_, _, rdRoutine⟩ := RD.solcGetterThunk hreach hentry hroutine - obtain ⟨_, _, rdReturn⟩ := RD.solcConstGetter (val := val) (width := width) - (op := op) (R := [sel]) rdRoutine hgetter hret - (by simp only [List.length_singleton]; omega) - exact RD.solcReturnUint128FromMem rdReturn hreturn - solcFreePtrMem_mload64 - (by rfl) - (solcReturnMem_mload64 (UInt256.land val uint128Mask)) - (solcReturnMem_read128 (UInt256.land val uint128Mask)) - (by simp only [List.length_singleton]; omega) - -theorem uniswapV3PoolMaxLiquidityPerTickEvm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 13 == I.calldata.extract 0 4) = true) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land (EVM.wordOfInt v.maxLiquidityPerTick) uint128Mask)) := by - have hreach := uniswapV3PoolMaxLiquidityPerTickReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - exact RD.solcUint128ConstGetterExternal - (sel := solcSelectorWord I) (entry := ⟨1478⟩) (routine := ⟨8172⟩) - (returnPc := ⟨654⟩) (val := EVM.wordOfInt v.maxLiquidityPerTick) (width := 32) - (op := .PUSH32) hreach - (uniswapV3PoolMaxLiquidityPerTickEntryWf hpatch) - (uniswapV3PoolMaxLiquidityPerTickGetterWf hpatch) - (uniswapV3PoolJumpDestPatched8172 hpatch) - (uniswapV3PoolLiquidityReturnJumpDest hpatch) - (uniswapV3PoolLiquidityReturnWf hpatch) - -theorem uint128ReturnEncodingInt (i : Int) (h0 : 0 ≤ i) (hlt : i < 2 ^ 128) : - encodeReturnValue? uint128 (.int i) = some (UInt256.toByteArray (EVM.wordOfInt i)) := by - have hword : EVM.wordOfInt i = EVM.word i.toNat := wordOfInt_nonneg i h0 - have hltWord : i < ↑(EVM.twoPow 128) := by - simpa [EVM.twoPow] using hlt - refine scalarReturnEncoding (t := (.int (.uint ⟨128, by decide⟩))) - (w := EVM.wordOfInt i) rfl ?_ ?_ - · simp only [abiTupleHeadSize?, staticABIEncodedSize?, isDynamicABIType, bind, Option.bind] - decide - · simp [encodeABIValue?, encodeABIWord?, hword, h0, hltWord] - -theorem uint128MaskCleanOfInt (i : Int) (h0 : 0 ≤ i) (hlt : i < 2 ^ 128) : - UInt256.land (EVM.wordOfInt i) uint128Mask = EVM.wordOfInt i := by - apply uint128Mask_clean - rw [wordOfInt_nonneg i h0] - have hltNat : i.toNat < EVM.twoPow 128 := by - exact (Int.toNat_lt h0).2 (by simpa [EVM.twoPow] using hlt) - unfold EVM.word EVM.uintN UInt256.toNat - simp only - rw [Nat.mod_eq_of_lt] - · exact hltNat - · have : EVM.twoPow 128 < EVM.twoPow 256 := by - norm_num [EVM.twoPow] - omega - -theorem uniswapV3PoolMaxLiquidityPerTickSourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) (maxliquiditypertickTransition v).body - (.returned { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) - (some [Value.int v.maxLiquidityPerTick])) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [.intLit v.maxLiquidityPerTick] ] _ - exact nonpayableIntLiteralBodyReturns (initState cA gh bl σ σ₀ g A I) - (∅ : Store) v.maxLiquidityPerTick hwv - -theorem uniswapV3PoolMaxLiquidityPerTickBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 13 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_maxLiquidityPerTick (v := v) (cd := I.calldata) hsel - have hdecode := uniswapV3PoolMaxLiquidityPerTickDecode (v := v) (I := I) hsz - have hbody := uniswapV3PoolMaxLiquidityPerTickSourceBody (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hrd := uniswapV3PoolMaxLiquidityPerTickEvm (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel - have hmask := uint128MaskCleanOfInt v.maxLiquidityPerTick - v.maxLiquidityPerTick_nonneg v.maxLiquidityPerTick_lt - exact hrd.reEquivExecution hcode hdispatch hdecode hbody hAccounts - (returnEquiv_of_encode (by - simpa [hmask] using uint128ReturnEncodingInt v.maxLiquidityPerTick - v.maxLiquidityPerTick_nonneg v.maxLiquidityPerTick_lt)) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Mint.lean b/Benchmarks/UniswapV3Pool/Mint.lean deleted file mode 100644 index af3774e1..00000000 --- a/Benchmarks/UniswapV3Pool/Mint.lean +++ /dev/null @@ -1,18 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolMintBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 7 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/NoDelegateCall.lean b/Benchmarks/UniswapV3Pool/NoDelegateCall.lean deleted file mode 100644 index 0c35f960..00000000 --- a/Benchmarks/UniswapV3Pool/NoDelegateCall.lean +++ /dev/null @@ -1,780 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev uniswapV3PoolNoDelegateCallGuard (v : PoolImmutables) - (I : ExecutionEnv) : UInt256 := - UInt256.eq - (UInt256.land (EVM.Word.ofNat v.original.toNat) solcAddrMask) - (UInt256.ofNat I.codeOwner.val) - -private theorem uniswapV3PoolNoDelegateCallPatchDisjointWidth - {v : PoolImmutables} {pc : UInt256} {n : Nat} - (h : (5486 ≤ pc.toNat ∧ pc.toNat + n ≤ 6603) ∨ - (10597 ≤ pc.toNat ∧ pc.toNat + n ≤ 11259) ∨ - (11291 ≤ pc.toNat ∧ pc.toNat + n ≤ 15650)) : - ∀ p ∈ patches v, pc.toNat + n ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - rcases h with hlow | hmid | hhigh - all_goals - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolNoDelegateCallDecodePatchedPush1 {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 2 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 2 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x60) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1)) = n) : - decode code pc = some (.Push .PUSH1, some (n, 1)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + 1) = - uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1) := by - unfold ByteArray.extract' - have hguard : - (decide (pc.toNat.succ < 2 ^ 64) && decide (pc.toNat.succ + 1 < 2 ^ 64)) = - true := by - rw [Bool.and_eq_true] - constructor <;> rw [decide_eq_true_eq] <;> omega - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq (start := pc.toNat.succ) (stop := pc.toNat.succ + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl hbefore - · exact Or.inr (by omega)) - hpatch - have hgetSome : code.get? pc.toNat = some 0x60 := by - rw [hget, hgetTemplate] - have hparse : (some (0x60 : UInt8) >>= parseInstr) = some (.Push .PUSH1) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH1, - some (uInt256OfByteArray (code.extract' pc.toNat.succ (pc.toNat.succ + 1)), 1)) = - some (Operation.Push Operation.POp.PUSH1, some (n, 1)) - rw [hextract, hval] - -private theorem uniswapV3PoolNoDelegateCallDecodePatchedPush2 {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 3 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 3 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x61) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 2)) = n) : - decode code pc = some (.Push .PUSH2, some (n, 2)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + 2) = - uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 2) := by - unfold ByteArray.extract' - have hguard : - (decide (pc.toNat.succ < 2 ^ 64) && decide (pc.toNat.succ + 2 < 2 ^ 64)) = - true := by - rw [Bool.and_eq_true] - constructor <;> rw [decide_eq_true_eq] <;> omega - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq (start := pc.toNat.succ) (stop := pc.toNat.succ + 2) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl hbefore - · exact Or.inr (by omega)) - hpatch - have hgetSome : code.get? pc.toNat = some 0x61 := by - rw [hget, hgetTemplate] - have hparse : (some (0x61 : UInt8) >>= parseInstr) = some (.Push .PUSH2) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH2, - some (uInt256OfByteArray (code.extract' pc.toNat.succ (pc.toNat.succ + 2)), 2)) = - some (Operation.Push Operation.POp.PUSH2, some (n, 2)) - rw [hextract, hval] - -theorem uniswapV3PoolOriginalPatchWord {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - code.extract 11259 11291 = UInt256.toByteArray (EVM.Word.ofNat v.original.toNat) := by - let value := UInt256.toByteArray (EVM.Word.ofNat v.original.toNat) - let pre : List (Nat × ByteArray) := - [(8315, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (8829, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (10457, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (2258, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4853, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (6740, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (7822, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (9150, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (15650, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4551, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (6789, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (7924, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (9284, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (10529, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (15979, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (3311, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6603, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6658, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (10565, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (3072, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (10493, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19402, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (19452, UInt256.toByteArray (EVM.wordOfInt v.tickSpacing)), - (8174, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19295, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19350, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick))] - have hpatch' : patchRuntime uniswapV3PoolBytecode (pre ++ (11259, value) :: []) = - some code := by - dsimp [pre, value] - simpa [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup, - toByteArray_eq_toBytesBE] using hpatch - have hpost : ∀ p ∈ ([] : List (Nat × ByteArray)), - 11259 + 32 ≤ p.1 ∨ p.1 + 32 ≤ 11259 := by - simp - have hsize : value.size = 32 := by - dsimp [value] - exact toByteArray_size _ - simpa [value] using - (patchRuntime_extract_patch (template := uniswapV3PoolBytecode) (out := code) - (value := value) (pre := pre) (post := []) (offset := 11259) hsize hpost hpatch') - -theorem uniswapV3PoolOriginalConstDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨11258⟩ = - some (.Push .PUSH32, some (EVM.Word.ofNat v.original.toNat, 32)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have hget : code.get? ({ val := 11258 } : UInt256).toNat = - uniswapV3PoolBytecode.get? ({ val := 11258 } : UInt256).toNat := by - change code.get? 11258 = uniswapV3PoolBytecode.get? 11258 - apply get?_eq_of_extract_one - · rw [hsize] - native_decide - · native_decide - · exact patchRuntime_extract_eq (start := 11258) (stop := 11259) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by native_decide) - (fun p hp => by - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl - all_goals omega) hpatch - have hextract : code.extract' ({ val := 11258 } : UInt256).toNat.succ - (({ val := 11258 } : UInt256).toNat.succ + 32) = - UInt256.toByteArray (EVM.Word.ofNat v.original.toNat) := by - change code.extract' 11259 11291 = - UInt256.toByteArray (EVM.Word.ofNat v.original.toNat) - unfold ByteArray.extract' - have hguard : (decide (11259 < 2 ^ 64) && decide (11291 < 2 ^ 64)) = true := by - native_decide - rw [if_pos hguard] - exact uniswapV3PoolOriginalPatchWord hpatch - have hgetSome : code.get? ({ val := 11258 } : UInt256).toNat = some 0x7f := by - rw [hget] - native_decide - have hparse : (some (0x7f : UInt8) >>= parseInstr) = some (.Push .PUSH32) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH32, - some (uInt256OfByteArray - (code.extract' ({ val := 11258 } : UInt256).toNat.succ - (({ val := 11258 } : UInt256).toNat.succ + 32)), 32)) = - some (Operation.Push Operation.POp.PUSH32, some (EVM.Word.ofNat v.original.toNat, 32)) - rw [hextract, uInt256OfByteArray_eq, fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - -private theorem uniswapV3PoolPatchPreservesJumpDest5493 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨5493⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest11248 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11248⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest11301 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨11301⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched5493 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨5493⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest5493 - -theorem uniswapV3PoolJumpDestPatched11248 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11248⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest11248 - -theorem uniswapV3PoolJumpDestPatched11301 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨11301⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest11301 - -private theorem uniswapV3PoolNoDelegateCallDecodeNoArg {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} {byte : UInt8} {op : Operation} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hdisj : (5486 ≤ pc.toNat ∧ pc.toNat + 1 ≤ 6603) ∨ - (10597 ≤ pc.toNat ∧ pc.toNat + 1 ≤ 11259) ∨ - (11291 ≤ pc.toNat ∧ pc.toNat + 1 ≤ 15650)) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some byte) - (hparse : (some byte >>= parseInstr) = some op) - (harg : argOnNBytesOfInstr op = 0) : - decode code pc = some (op, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := pc) (byte := byte) (op := op) - hpatch (by - have hsize : 15650 ≤ uniswapV3PoolBytecode.size := by native_decide - rcases hdisj with hlow | hmid | hhigh <;> omega) ?_ hgetTemplate hparse harg - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 1) hdisj - -private theorem uniswapV3PoolNoDelegateCallJumpInOk - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5486⟩ R mem aw rdata acc k C) - (hov : R.length + 2 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨11248⟩ (⟨5493⟩ :: R) mem aw rdata acc k' C' := by - have hd5486 : decode code ⟨5486⟩ = some (.Push .PUSH2, some (⟨5493⟩, 2)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush2 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 3) - (Or.inl ⟨by native_decide, by native_decide⟩) - have hd5489 : decode code ⟨5489⟩ = some (.Push .PUSH2, some (⟨11248⟩, 2)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush2 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 3) - (Or.inl ⟨by native_decide, by native_decide⟩) - have hd5492 : decode code ⟨5492⟩ = some (.JUMP, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x56) (op := .JUMP) - hpatch (Or.inl ⟨by native_decide, by native_decide⟩) - (by native_decide) (by native_decide) (by native_decide) - have rd5489 := by - simpa using h.push2 ⟨5493⟩ hd5486 (by omega) - have rd5492 := by - simpa using rd5489.push2 ⟨11248⟩ hd5489 (by simp only [List.length_cons]; omega) - exact ⟨_, _, rd5492.jump hd5492 (uniswapV3PoolJumpDestPatched11248 hpatch) - (by simp only [List.length_cons]; omega)⟩ - -theorem uniswapV3PoolNoDelegateCallReturnOk - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {mem : ByteArray} {aw ret : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11248⟩ (ret :: R) mem aw rdata acc k C) - (hguard : uniswapV3PoolNoDelegateCallGuard v ee ≠ ⟨0⟩) - (htarget : (D_J code 0).contains ret = true) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret R mem aw rdata acc k' C' := by - have hd11248 : decode code ⟨11248⟩ = some (.JUMPDEST, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x5b) (op := .JUMPDEST) - hpatch (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11249 : decode code ⟨11249⟩ = some (.ADDRESS, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x30) (op := .ADDRESS) - hpatch (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11250 : decode code ⟨11250⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush1 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 2) - (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - have hd11252 : decode code ⟨11252⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush1 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 2) - (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - have hd11254 : decode code ⟨11254⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush1 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 2) - (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - have hd11256 : decode code ⟨11256⟩ = some (.SHL, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x1b) (op := .SHL) - hpatch (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11257 : decode code ⟨11257⟩ = some (.SUB, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x03) (op := .SUB) - hpatch (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11258 : decode code ⟨11258⟩ = - some (.Push .PUSH32, some (EVM.Word.ofNat v.original.toNat, 32)) := - uniswapV3PoolOriginalConstDecode hpatch - have hd11291 : decode code ⟨11291⟩ = some (.AND, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x16) (op := .AND) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11292 : decode code ⟨11292⟩ = some (.EQ, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x14) (op := .EQ) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11293 : decode code ⟨11293⟩ = some (.Push .PUSH2, some (⟨11301⟩, 2)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush2 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 3) - (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - have hd11296 : decode code ⟨11296⟩ = some (.JUMPI, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x57) (op := .JUMPI) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11301 : decode code ⟨11301⟩ = some (.JUMPDEST, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x5b) (op := .JUMPDEST) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11302 : decode code ⟨11302⟩ = some (.JUMP, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x56) (op := .JUMP) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have rd11249 := by - simpa using h.jumpdest hd11248 (by evm_ov) - have rd11250 := by - simpa using rd11249.address hd11249 (by simp only [List.length_cons]; omega) - have rd11252 := by - simpa using rd11250.push1 ⟨1⟩ hd11250 (by simp only [List.length_cons]; omega) - have rd11254 := by - simpa using rd11252.push1 ⟨1⟩ hd11252 (by simp only [List.length_cons]; omega) - have rd11256 := by - simpa using rd11254.push1 ⟨160⟩ hd11254 (by simp only [List.length_cons]; omega) - have rd11257 := by - simpa using rd11256.shl hd11256 (by simp only [List.length_cons]; omega) - have hmask : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by - native_decide - have rd11258 := by - simpa [hmask] using rd11257.sub hd11257 (by simp only [List.length_cons]; omega) - have rd11291 := by - simpa using rd11258.pushConst (EVM.Word.ofNat v.original.toNat) - (by native_decide : Operation.POp.PUSH32 ≠ .PUSH0) hd11258 - (by simp only [List.length_cons]; omega) - have rd11292 := by - simpa using rd11291.and hd11291 (by simp only [List.length_cons]; omega) - have rd11293 := by - simpa [uniswapV3PoolNoDelegateCallGuard] using rd11292.eq hd11292 - (by simp only [List.length_cons]; omega) - have rd11296 := by - simpa using rd11293.push2 ⟨11301⟩ hd11293 (by simp only [List.length_cons]; omega) - have rd11301 := rd11296.jumpiT hd11296 hguard - (uniswapV3PoolJumpDestPatched11301 hpatch) (by simp only [List.length_cons]; omega) - have rd11302 := by - simpa using rd11301.jumpdest hd11301 (by evm_ov) - exact ⟨_, _, rd11302.jump hd11302 htarget (by omega)⟩ - -theorem uniswapV3PoolNoDelegateCallOk - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5486⟩ R mem aw rdata acc k C) - (hguard : uniswapV3PoolNoDelegateCallGuard v ee ≠ ⟨0⟩) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨5493⟩ R mem aw rdata acc k' C' := by - obtain ⟨_, _, rd11248⟩ := - uniswapV3PoolNoDelegateCallJumpInOk (v := v) (code := code) (ee := ee) (g := g) - (s0 := s0) (R := R) (mem := mem) (aw := aw) (rdata := rdata) (acc := acc) - hpatch h (by omega) - have hd11248 : decode code ⟨11248⟩ = some (.JUMPDEST, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x5b) (op := .JUMPDEST) - hpatch (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11249 : decode code ⟨11249⟩ = some (.ADDRESS, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x30) (op := .ADDRESS) - hpatch (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11250 : decode code ⟨11250⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush1 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 2) - (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - have hd11252 : decode code ⟨11252⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush1 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 2) - (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - have hd11254 : decode code ⟨11254⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush1 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 2) - (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - have hd11256 : decode code ⟨11256⟩ = some (.SHL, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x1b) (op := .SHL) - hpatch (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11257 : decode code ⟨11257⟩ = some (.SUB, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x03) (op := .SUB) - hpatch (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11258 : decode code ⟨11258⟩ = - some (.Push .PUSH32, some (EVM.Word.ofNat v.original.toNat, 32)) := - uniswapV3PoolOriginalConstDecode hpatch - have hd11291 : decode code ⟨11291⟩ = some (.AND, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x16) (op := .AND) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11292 : decode code ⟨11292⟩ = some (.EQ, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x14) (op := .EQ) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11293 : decode code ⟨11293⟩ = some (.Push .PUSH2, some (⟨11301⟩, 2)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush2 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 3) - (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - have hd11296 : decode code ⟨11296⟩ = some (.JUMPI, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x57) (op := .JUMPI) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11301 : decode code ⟨11301⟩ = some (.JUMPDEST, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x5b) (op := .JUMPDEST) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11302 : decode code ⟨11302⟩ = some (.JUMP, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x56) (op := .JUMP) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have rd11249 := by - simpa using rd11248.jumpdest hd11248 (by evm_ov) - have rd11250 := by - simpa using rd11249.address hd11249 (by simp only [List.length_cons]; omega) - have rd11252 := by - simpa using rd11250.push1 ⟨1⟩ hd11250 (by simp only [List.length_cons]; omega) - have rd11254 := by - simpa using rd11252.push1 ⟨1⟩ hd11252 (by simp only [List.length_cons]; omega) - have rd11256 := by - simpa using rd11254.push1 ⟨160⟩ hd11254 (by simp only [List.length_cons]; omega) - have rd11257 := by - simpa using rd11256.shl hd11256 (by simp only [List.length_cons]; omega) - have hmask : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by - native_decide - have rd11258 := by - simpa [hmask] using rd11257.sub hd11257 (by simp only [List.length_cons]; omega) - have rd11291 := by - simpa using rd11258.pushConst (EVM.Word.ofNat v.original.toNat) - (by native_decide : Operation.POp.PUSH32 ≠ .PUSH0) hd11258 - (by simp only [List.length_cons]; omega) - have rd11292 := by - simpa using rd11291.and hd11291 (by simp only [List.length_cons]; omega) - have rd11293 := by - simpa [uniswapV3PoolNoDelegateCallGuard] using rd11292.eq hd11292 - (by simp only [List.length_cons]; omega) - have rd11296 := by - simpa using rd11293.push2 ⟨11301⟩ hd11293 (by simp only [List.length_cons]; omega) - have rd11301 := rd11296.jumpiT hd11296 hguard - (uniswapV3PoolJumpDestPatched11301 hpatch) (by simp only [List.length_cons]; omega) - have rd11302 := by - simpa using rd11301.jumpdest hd11301 (by evm_ov) - exact ⟨_, _, rd11302.jump hd11302 (uniswapV3PoolJumpDestPatched5493 hpatch) - (by omega)⟩ - -theorem uniswapV3PoolNoDelegateCallReturnRevert - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {mem : ByteArray} {aw ret : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨11248⟩ (ret :: R) mem aw rdata acc k C) - (hguard : uniswapV3PoolNoDelegateCallGuard v ee = ⟨0⟩) - (hov : R.length + 5 ≤ 1024) : - RDrev code g s0 := by - let rd11248 := h - have hd11248 : decode code ⟨11248⟩ = some (.JUMPDEST, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x5b) (op := .JUMPDEST) - hpatch (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11249 : decode code ⟨11249⟩ = some (.ADDRESS, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x30) (op := .ADDRESS) - hpatch (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11250 : decode code ⟨11250⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush1 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 2) - (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - have hd11252 : decode code ⟨11252⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush1 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 2) - (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - have hd11254 : decode code ⟨11254⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush1 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 2) - (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - have hd11256 : decode code ⟨11256⟩ = some (.SHL, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x1b) (op := .SHL) - hpatch (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11257 : decode code ⟨11257⟩ = some (.SUB, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x03) (op := .SUB) - hpatch (Or.inr (Or.inl ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11258 : decode code ⟨11258⟩ = - some (.Push .PUSH32, some (EVM.Word.ofNat v.original.toNat, 32)) := - uniswapV3PoolOriginalConstDecode hpatch - have hd11291 : decode code ⟨11291⟩ = some (.AND, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x16) (op := .AND) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11292 : decode code ⟨11292⟩ = some (.EQ, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x14) (op := .EQ) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11293 : decode code ⟨11293⟩ = some (.Push .PUSH2, some (⟨11301⟩, 2)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush2 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 3) - (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - have hd11296 : decode code ⟨11296⟩ = some (.JUMPI, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x57) (op := .JUMPI) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11297 : decode code ⟨11297⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - refine uniswapV3PoolNoDelegateCallDecodePatchedPush1 hpatch (by native_decide) - ?_ (by native_decide) (by native_decide) - exact uniswapV3PoolNoDelegateCallPatchDisjointWidth (n := 2) - (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - have hd11299 : decode code ⟨11299⟩ = some (.DUP1, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0x80) (op := .DUP1) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have hd11300 : decode code ⟨11300⟩ = some (.REVERT, .none) := by - exact uniswapV3PoolNoDelegateCallDecodeNoArg (byte := 0xfd) (op := .REVERT) - hpatch (Or.inr (Or.inr ⟨by native_decide, by native_decide⟩)) - (by native_decide) (by native_decide) (by native_decide) - have rd11249 := by - simpa using rd11248.jumpdest hd11248 (by evm_ov) - have rd11250 := by - simpa using rd11249.address hd11249 (by simp only [List.length_cons]; omega) - have rd11252 := by - simpa using rd11250.push1 ⟨1⟩ hd11250 (by simp only [List.length_cons]; omega) - have rd11254 := by - simpa using rd11252.push1 ⟨1⟩ hd11252 (by simp only [List.length_cons]; omega) - have rd11256 := by - simpa using rd11254.push1 ⟨160⟩ hd11254 (by simp only [List.length_cons]; omega) - have rd11257 := by - simpa using rd11256.shl hd11256 (by simp only [List.length_cons]; omega) - have hmask : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by - native_decide - have rd11258 := by - simpa [hmask] using rd11257.sub hd11257 (by simp only [List.length_cons]; omega) - have rd11291 := by - simpa using rd11258.pushConst (EVM.Word.ofNat v.original.toNat) - (by native_decide : Operation.POp.PUSH32 ≠ .PUSH0) hd11258 - (by simp only [List.length_cons]; omega) - have rd11292 := by - simpa using rd11291.and hd11291 (by simp only [List.length_cons]; omega) - have rd11293 := by - simpa [uniswapV3PoolNoDelegateCallGuard] using rd11292.eq hd11292 - (by simp only [List.length_cons]; omega) - have rd11296 := by - simpa using rd11293.push2 ⟨11301⟩ hd11293 (by simp only [List.length_cons]; omega) - have rd11297 := rd11296.jumpiNT hd11296 hguard (by simp only [List.length_cons]; omega) - exact RD.solcPush1Dup1Revert0 rd11297 hd11297 hd11299 hd11300 - (by simp only [List.length_cons]; omega) - -theorem uniswapV3PoolNoDelegateCallRevert - {v : PoolImmutables} {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5486⟩ R mem aw rdata acc k C) - (hguard : uniswapV3PoolNoDelegateCallGuard v ee = ⟨0⟩) - (hov : R.length + 5 ≤ 1024) : - RDrev code g s0 := by - obtain ⟨_, _, rd11248⟩ := - uniswapV3PoolNoDelegateCallJumpInOk (v := v) (code := code) (ee := ee) (g := g) - (s0 := s0) (R := R) (mem := mem) (aw := aw) (rdata := rdata) (acc := acc) - hpatch h (by omega) - exact uniswapV3PoolNoDelegateCallReturnRevert (v := v) (code := code) (ee := ee) (g := g) - (s0 := s0) (ret := ⟨5493⟩) (R := R) (mem := mem) (aw := aw) (rdata := rdata) - (acc := acc) hpatch rd11248 hguard (by omega) - -theorem uniswapV3PoolNoDelegateCallOriginalClean (a : AccountAddress) : - UInt256.land (EVM.Word.ofNat a.toNat) solcAddrMask = EVM.Word.ofNat a.toNat := by - apply solcAddrMask_clean - rw [accountAddressWord_toNat] - simp [EVM.addressModulus, EVM.twoPow, AccountAddress.size] - -theorem uniswapV3PoolAccountAddressOfNatToNat (a : AccountAddress) : - AccountAddress.ofNat a.toNat = a := by - ext - simp [AccountAddress.ofNat] - -theorem uniswapV3PoolNoDelegateCallGuard_word_eq_address_eq - {v : PoolImmutables} {I : ExecutionEnv} - (hword : UInt256.land (EVM.Word.ofNat v.original.toNat) solcAddrMask = - UInt256.ofNat I.codeOwner.val) : - I.codeOwner = v.original := by - have hclean := uniswapV3PoolNoDelegateCallOriginalClean v.original - have hword' : EVM.Word.ofNat v.original.toNat = UInt256.ofNat I.codeOwner.val := by - rwa [hclean] at hword - have hnat := congrArg UInt256.toNat hword' - have horig := accountAddressWord_toNat v.original - have hthis := accountAddressWord_toNat I.codeOwner - rw [horig] at hnat - change v.original.val = (UInt256.ofNat I.codeOwner.val).toNat at hnat - rw [show (UInt256.ofNat I.codeOwner.val).toNat = I.codeOwner.val from by - simpa [EVM.Word.ofNat] using hthis] at hnat - ext - exact hnat.symm - -theorem uniswapV3PoolNoDelegateCallGuard_eq_zero_of_codeOwner_ne - {v : PoolImmutables} {I : ExecutionEnv} - (hne : I.codeOwner ≠ v.original) : - uniswapV3PoolNoDelegateCallGuard v I = ⟨0⟩ := by - unfold uniswapV3PoolNoDelegateCallGuard - apply u256_eq_of_ne - intro hword - exact hne (uniswapV3PoolNoDelegateCallGuard_word_eq_address_eq hword) - -theorem uniswapV3PoolNoDelegateCallGuard_eq_one_of_codeOwner_eq - {v : PoolImmutables} {I : ExecutionEnv} - (heq : I.codeOwner = v.original) : - uniswapV3PoolNoDelegateCallGuard v I = ⟨1⟩ := by - rw [uniswapV3PoolNoDelegateCallGuard] - rw [uniswapV3PoolNoDelegateCallOriginalClean] - rw [heq] - simpa [EVM.Word.ofNat] using uInt256_eq_self (UInt256.ofNat v.original.val) - -theorem uniswapV3PoolAddrLitEvalFrame {v : PoolImmutables} - {cA gh bl σ σ₀ A I L} {g : Sat256} (a : EVM.Address) : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) (addrLit a) = - .ok (Value.address (AccountAddress.ofNat a.toNat)) := by - dsimp [addrLit] - have hint : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) (.intLit (↑↑a)) = - .ok (.int (↑↑a)) := by - simp [evalExpr?, pure] - unfold evalExpr? - rw [hint] - change (if (↑↑a : Int) < 0 then EvalResult.error EvalError.typeError - else EvalResult.ok - (Value.address (AccountAddress.ofNat (Int.toNat (↑↑a : Int))))) = - EvalResult.ok (Value.address (AccountAddress.ofNat ↑a)) - rw [if_neg (by omega)] - simp - -theorem uniswapV3PoolNoDelegateCallEvalTrue - {v : PoolImmutables} {cA gh bl σ σ₀ A I L} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I ≠ ⟨0⟩) : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) - (.binary .eq (.env .this) (addrLit v.original)) = .ok (.bool true) := by - have haddr : I.codeOwner = v.original := by - by_contra hne - exact hguard (uniswapV3PoolNoDelegateCallGuard_eq_zero_of_codeOwner_ne hne) - have hofNat := uniswapV3PoolAccountAddressOfNatToNat v.original - have hbeq : - (Value.address I.codeOwner == Value.address (AccountAddress.ofNat v.original.toNat)) = - true := by - rw [beq_iff_eq] - rw [hofNat, haddr] - have hthis : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) (.env .this) = - .ok (Value.address I.codeOwner) := by - simp [evalExpr?, envValue, initState, pure] - have horig := uniswapV3PoolAddrLitEvalFrame (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (L := L) (g := g) - v.original - unfold evalExpr? - rw [hthis, horig] - simp [EvalResult.bind, bind, evalBinaryOp?, haddr] - exact hofNat.symm - -theorem uniswapV3PoolNoDelegateCallEvalFalse - {v : PoolImmutables} {cA gh bl σ σ₀ A I L} {g : Sat256} - (hguard : uniswapV3PoolNoDelegateCallGuard v I = ⟨0⟩) : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) - (.binary .eq (.env .this) (addrLit v.original)) = .ok (.bool false) := by - have hne : I.codeOwner ≠ v.original := by - intro haddr - have hone := uniswapV3PoolNoDelegateCallGuard_eq_one_of_codeOwner_eq - (v := v) (I := I) haddr - exact (by native_decide : (⟨0⟩ : UInt256) ≠ ⟨1⟩) (by simpa [hguard] using hone) - have hofNat := uniswapV3PoolAccountAddressOfNatToNat v.original - have hneValue : - Value.address I.codeOwner ≠ Value.address (AccountAddress.ofNat v.original.toNat) := by - intro hval - rw [hofNat] at hval - injection hval with haddr - exact hne haddr - have hbeq : - (Value.address I.codeOwner == Value.address (AccountAddress.ofNat v.original.toNat)) = - false := by - rw [beq_eq_false_iff_ne] - exact hneValue - have hthis : - evalExpr? (config v) { contract := contract v, locals := L } - (initState cA gh bl σ σ₀ g A I) (.env .this) = - .ok (Value.address I.codeOwner) := by - simp [evalExpr?, envValue, initState, pure] - have horig := uniswapV3PoolAddrLitEvalFrame (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (L := L) (g := g) - v.original - unfold evalExpr? - rw [hthis, horig] - simp [EvalResult.bind, bind, evalBinaryOp?] - intro h - exact hne (h.trans hofNat) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Observations.lean b/Benchmarks/UniswapV3Pool/Observations.lean deleted file mode 100644 index 70d538fc..00000000 --- a/Benchmarks/UniswapV3Pool/Observations.lean +++ /dev/null @@ -1,1740 +0,0 @@ -import Benchmarks.UniswapV3Pool.ObservationsInt56 -import Reasoning.MemCascade - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev observationsArgWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -abbrev observationsArgValue (I : ExecutionEnv) : Value := - .int (Int.ofNat (observationsArgWord I).toNat) - -abbrev observationsArgKey (I : ExecutionEnv) : KeyValue := - .int (Int.ofNat (observationsArgWord I).toNat) - -abbrev observationsStore (I : ExecutionEnv) : Store := - (∅ : Store).insert "arg0" (observationsArgValue I) - -abbrev observationsBaseSlot (I : ExecutionEnv) : UInt256 := - observationBase (observationsArgKey I) - -theorem observationsArgAddBase_eq_baseSlot (I : ExecutionEnv) : - observationsArgWord I + ⟨8⟩ = observationsBaseSlot I := by - unfold observationsBaseSlot observationsArgKey observationBase - rw [keyValueToWord_uint256] - rw [u256_ofNat_toNat] - rw [u256_add_comm] - -abbrev observationsSlotWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (observationsBaseSlot I) - -abbrev observationsShiftBytes (n : Nat) : UInt256 := - UInt256.ofNat (256 ^ n) - -abbrev observationsUint32Mask : UInt256 := - UInt256.ofNat (2 ^ 32 - 1) - -theorem observationsUint32Mask_toNat : - observationsUint32Mask.toNat = 2 ^ 32 - 1 := by - exact ulit_toNat' _ (by norm_num [UInt256.size]) - -theorem observationsUint32Mask_bound (w : UInt256) : - (UInt256.land w observationsUint32Mask).toNat < EVM.twoPow 32 := by - rw [uland_toNat] - rw [observationsUint32Mask_toNat] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [EVM.twoPow]) - -theorem observationsUint32Mask_clean {w : UInt256} (hcanon : w.toNat < EVM.twoPow 32) : - UInt256.land w observationsUint32Mask = w := by - apply u256_inj - show Nat.land w.toNat observationsUint32Mask.toNat % EVM.twoPow 256 = w.toNat - rw [observationsUint32Mask_toNat, nat_land_mask_eq_mod] - rw [show EVM.twoPow 32 = 2 ^ 32 from rfl] at hcanon - rw [Nat.mod_eq_of_lt hcanon] - exact Nat.mod_eq_of_lt w.val.isLt - -abbrev observationsBlockTimestampWord (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - UInt256.land (observationsSlotWord σ I) observationsUint32Mask - -abbrev observationsTickRawWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.div (observationsSlotWord σ I) (observationsShiftBytes 4) - -abbrev observationsTickStorageWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (observationsTickRawWord σ I) observationsUint56Mask - -abbrev observationsTickReturnWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨6⟩ (observationsTickRawWord σ I) - -abbrev observationsSecondsPerLiquidityWord (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - UInt256.land (UInt256.div (observationsSlotWord σ I) (observationsShiftBytes 11)) - slot0Uint160Mask - -abbrev observationsInitializedRawWord (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - UInt256.land (UInt256.div (observationsSlotWord σ I) (observationsShiftBytes 31)) - slot0Uint8Mask - -abbrev observationsInitializedReturnWord (σ : AccountMap) (I : ExecutionEnv) : - UInt256 := - slot0BoolReturnWord (observationsInitializedRawWord σ I) - -abbrev observationsReturnValues (σ : AccountMap) (I : ExecutionEnv) : List Value := - [ .int (Int.ofNat (observationsBlockTimestampWord σ I).toNat), - wordToElem (.int int56Int) (observationsTickStorageWord σ I), - .int (Int.ofNat (observationsSecondsPerLiquidityWord σ I).toNat), - wordToElem .bool (observationsInitializedRawWord σ I) ] - -theorem observationsStore_arg0 (I : ExecutionEnv) : - Std.HashMap.get? (observationsStore I) "arg0" = some (observationsArgValue I) := by - simp [observationsStore] - -theorem evalExpr_observations_arg0 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := observationsStore I } evm - (.var "arg0") = .ok (observationsArgValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [observationsStore_arg0] - -def observationsEvaledRef (I : ExecutionEnv) (field : Ident) : EvaledStorageRef := - { base := "observations", steps := [.aindex (observationsArgKey I), .field field] } - -def observationsRawEvaledRef (I : ExecutionEnv) (field : Ident) : EvaledStorageRef := - { base := "observationsRaw", steps := [.mindex (observationsArgKey I), .field field] } - -theorem evalStorageRef_observationsRaw {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (field : Ident) : - evalStorageRef (config v) { contract := contract v, locals := observationsStore I } evm - (observationsRawF (.var "arg0") field) = - .ok (observationsRawEvaledRef I field) := by - simp [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, observationsRawF, - observationsRawEvaledRef, evalExpr_observations_arg0, observationsArgValue, - observationsArgKey, valueToKey?, EvalResult.bind, EvalResult.ofOption, bind, pure] - -theorem evalExpr_observations_bound_true {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (hbound : (observationsArgWord I).toNat < 65535) : - evalExpr? (config v) { contract := contract v, locals := observationsStore I } evm - (ltE (.var "arg0") (.intLit 65535)) = .ok (.bool true) := by - unfold ltE - simp only [evalExpr?, evalExpr_observations_arg0, observationsArgValue, - EvalResult.bind, bind, pure, evalBinaryOp?] - have hlt : Int.ofNat (observationsArgWord I).toNat < (65535 : Int) := by - change ((observationsArgWord I).toNat : Int) < (65535 : Int) - exact_mod_cast hbound - rw [show decide (Int.ofNat (observationsArgWord I).toNat < 65535) = true from - decide_eq_true hlt] - -theorem evalExpr_observations_bound_false {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (hoob : 65535 ≤ (observationsArgWord I).toNat) : - evalExpr? (config v) { contract := contract v, locals := observationsStore I } evm - (ltE (.var "arg0") (.intLit 65535)) = .ok (.bool false) := by - unfold ltE - simp only [evalExpr?, evalExpr_observations_arg0, observationsArgValue, - EvalResult.bind, bind, pure, evalBinaryOp?] - have hnot : ¬ Int.ofNat (observationsArgWord I).toNat < (65535 : Int) := by - intro hlt - change ((observationsArgWord I).toNat : Int) < (65535 : Int) at hlt - have hltNat : (observationsArgWord I).toNat < 65535 := by - exact_mod_cast hlt - exact not_lt_of_ge hoob hltNat - rw [show decide (Int.ofNat (observationsArgWord I).toNat < 65535) = false from - decide_eq_false hnot] - -private theorem observationsStorageTypeAtBase : - storageTypeAt? storageDecls { base := "observations", steps := [] } = - some (.array observationStructTy 65535) := by - rfl - -theorem observationsArrayIndexInBounds_ok {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (hbound : (observationsArgWord I).toNat < 65535) : - arrayIndexInBounds? (config v) evm (contract v).storage "observations" [] - (observationsArgKey I) = .ok () := by - unfold arrayIndexInBounds? - rw [show (contract v).storage = storageDecls by rfl, observationsStorageTypeAtBase] - change (if 0 ≤ Int.ofNat (observationsArgWord I).toNat ∧ - Int.ofNat (observationsArgWord I).toNat < (↑(65535 : Nat) : Int) then - EvalResult.ok () else EvalResult.revert) = EvalResult.ok () - have hin : 0 ≤ Int.ofNat (observationsArgWord I).toNat ∧ - Int.ofNat (observationsArgWord I).toNat < (↑(65535 : Nat) : Int) := by - constructor - · exact Int.natCast_nonneg _ - · change ((observationsArgWord I).toNat : Int) < (65535 : Int) - exact_mod_cast hbound - rw [if_pos hin] - -theorem observationsArrayIndexInBounds_oob {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (hoob : 65535 ≤ (observationsArgWord I).toNat) : - arrayIndexInBounds? (config v) evm (contract v).storage "observations" [] - (observationsArgKey I) = .revert := by - unfold arrayIndexInBounds? - rw [show (contract v).storage = storageDecls by rfl, observationsStorageTypeAtBase] - change (if 0 ≤ Int.ofNat (observationsArgWord I).toNat ∧ - Int.ofNat (observationsArgWord I).toNat < (↑(65535 : Nat) : Int) then - EvalResult.ok () else EvalResult.revert) = EvalResult.revert - have hout : ¬(0 ≤ Int.ofNat (observationsArgWord I).toNat ∧ - Int.ofNat (observationsArgWord I).toNat < (↑(65535 : Nat) : Int)) := by - intro h - have hltInt : ((observationsArgWord I).toNat : Int) < (65535 : Int) := by - simpa using h.2 - exact not_lt_of_ge hoob (by exact_mod_cast hltInt) - rw [if_neg hout] - -theorem uniswapV3PoolObservationsDecodeOk {v : PoolImmutables} {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - (observationsTransition.params.map Param.name) - (transitionSignature observationsTransition).paramTypes I.calldata = - some (observationsStore I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake4 : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have hword4 : ABI.bytesToWord ((I.calldata.toList.drop 4).take 32) = - calldataWord I.calldata 4 := - decode_word_at_eq I.calldata 4 (by omega) (by norm_num) - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := observationsTransition.params.map Param.name) - (types := (transitionSignature observationsTransition).paramTypes) (cd := I.calldata)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint256] - (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["arg0"] values ∅ - | none => none) = some (observationsStore I) - rw [show uint256 = abiUInt256 by rfl] - simp only [decodeScalarWordsWithMode?] - rw [decodeScalarWordWithMode_uint256_ok (mode := DecodeMode.legacySolc05) - (bytes := I.calldata.toList.drop 4) (start := 0) htake4] - change decodeCalldata.insertValues ["arg0"] - [Value.int - (Int.ofNat (ABI.bytesToWord ((I.calldata.toList.drop 4).take 32)).toNat)] ∅ = - some (observationsStore I) - simp [decodeCalldata.insertValues, observationsStore, observationsArgValue, - observationsArgWord] - rw [hword4] - · native_decide - -theorem uniswapV3PoolObservationsDecodeShort {v : PoolImmutables} {I : ExecutionEnv} - (hshort : I.calldata.size < 36) : - decodeCalldataWithMode (config v).abiDecodeMode - (observationsTransition.params.map Param.name) - (transitionSignature observationsTransition).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := observationsTransition.params.map Param.name) - (types := (transitionSignature observationsTransition).paramTypes) (cd := I.calldata)] - · by_cases hsz4 : I.calldata.size < 4 - · rw [if_pos (by rw [htlen]; omega : I.calldata.toList.length < 4)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint256] - (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["arg0"] values ∅ - | none => none) = none - rw [show uint256 = abiUInt256 by rfl] - simp only [decodeScalarWordsWithMode?] - rw [decodeScalarWordWithMode_uint256_none_short (mode := DecodeMode.legacySolc05) - (bytes := I.calldata.toList.drop 4) (start := 0) (by - have htake0n : ¬ ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - simpa using htake0n)] - simp only [Option.bind, bind] - · native_decide - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolDispatch_observations {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 4 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some observationsTransition := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, factoryTransition v, - feeTransition v, feegrowthglobal0X128Transition, feegrowthglobal1X128Transition, - flashTransition v, increaseobservationcardinalitynextTransition v, initializeTransition, - liquidityTransition, maxliquiditypertickTransition v, mintTransition v]) - (post := [observeTransition v, positionsTransition, protocolfeesTransition, - setfeeprotocolTransition v, slot0Transition, snapshotcumulativesinsideTransition v, - swapTransition v, tickbitmapTransition, tickspacingTransition v, ticksTransition, - token0Transition v, token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 4) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 4) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 4) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 4) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 4) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 4) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 4) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 4) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 5) (j := 4) - (by native_decide) hsel - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 25) (j := 4) - (by native_decide) hsel - · rw [selectorOf, liquiditySelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 2) (j := 4) - (by native_decide) hsel - · rw [selectorOf, maxLiquidityPerTickSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 13) (j := 4) - (by native_decide) hsel - · rw [selectorOf, mintSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 7) (j := 4) - (by native_decide) hsel - · rw [selectorOf, observationsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using hsel - -theorem uniswapV3PoolObservationsReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 4 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨737⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 4 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0x25 0x2c 0x09 0xd7 - (uniswapV3PoolSelNat 4) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h239 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨239⟩) hpatch h32 hgt32 - have hgt239 : UInt256.gt (armSelNat code ⟨239⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h348 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨348⟩) hpatch h239 hgt239 - have hgt348 : UInt256.gt (armSelNat code ⟨348⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h359 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨359⟩) hpatch h348 hgt348 - have hmiss3 : (uniswapV3PoolSelBytes 3 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h370 := uniswapV3PoolSelectorArmMissToOf (i := 3) (next := ⟨370⟩) - hpatch hsz hmiss3 h359 - have h737 := uniswapV3PoolSelectorArmHitTo (i := 4) (target := ⟨737⟩) - hpatch hsz hsel h370 - exact ⟨_, _, h737⟩ - -private theorem uniswapV3PoolPatchPreservesJumpDest5334 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨5334⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched5334 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨5334⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest5334 - -private theorem uniswapV3PoolPatchPreservesJumpDest5351 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨5351⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched5351 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨5351⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest5351 - -private theorem uniswapV3PoolObservationsDecodedReachRoutine {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {de ret : UInt256} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨759⟩ (de :: ⟨4⟩ :: ret :: R) mem aw rdata acc k C) - (hov : R.length + 3 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨5334⟩ (observationsArgWord ee :: ret :: R) - mem aw rdata acc k' C' := by - have rd760 : RD code ee g s0 ⟨760⟩ (de :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1) (C + 1) := by - simpa using h.jumpdest - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd761 : RD code ee g s0 ⟨761⟩ (⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1) (C + 1 + 2) := by - simpa using rd760.pop - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd762 : RD code ee g s0 ⟨762⟩ (observationsArgWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1) (C + 1 + 2 + 3) := by - simpa [observationsArgWord, calldataWord, - show (⟨4⟩ : UInt256).toNat = 4 from by decide] using - (rd761.calldataload - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov)) - have rd765 : RD code ee g s0 ⟨765⟩ (⟨5334⟩ :: observationsArgWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3) := by - simpa using rd762.push2 ⟨5334⟩ - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - exact ⟨_, _, rd765.jump - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (uniswapV3PoolJumpDestPatched5334 hpatch) - (by evm_ov)⟩ - -set_option maxHeartbeats 3000000 in -private theorem uniswapV3PoolObservationsExternalLenOk {v : PoolImmutables} - {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hreach : ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨737⟩ - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨759⟩ - (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩ :: ⟨4⟩ :: ⟨766⟩ :: - [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact RD.solcExternalStaticArgsLenOk (need := ⟨32⟩) - (entry := ⟨737⟩) (ret := ⟨766⟩) (decoded := ⟨759⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (solcDecodeLenCheckOkUnsigned (by simpa using hsz36) hsize) - -theorem uniswapV3PoolObservationsEvmDecodeShort {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 4 == I.calldata.extract 0 4) = true) - (hshort : I.calldata.size < 36) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - have hreach := uniswapV3PoolObservationsReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - have hlt : - UInt256.lt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩ := by - apply ult_one - rw [usub_ofNat_word_toNat (by - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega) hsize] - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide] - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega - exact RD.solcExternalStaticArgsShortReverts (need := ⟨32⟩) - (entry := ⟨737⟩) (ret := ⟨766⟩) (decoded := ⟨759⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - hlt - -private theorem uniswapV3PoolObservationsRoutinePatchDisjoint {v : PoolImmutables} - {pc : UInt256} (hlo : 5308 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 6603) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl <;> - omega - -private def observationsStSignextend (s : State) (v : UInt256) - (t : List UInt256) : State := - { s with - machineState.stack := v :: t, - machineState.gasAvailable := s.machineState.gasAvailable.subNat 5 - machineState.pc := s.machineState.pc + ⟨1⟩ - machineState.execLength := s.machineState.execLength + 1 } - -private theorem observationsSignextendXstep {code : ByteArray} {s : State} - {pc a b : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pc) - (hdec : decode code pc = some (.SIGNEXTEND, .none)) - (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : - Xstep (D_J code 0) s = - if s.machineState.gasAvailable.toNat < 5 then .error .OutOfGass - else .ok (observationsStSignextend s (UInt256.signextend a b) t, .none) := by - have hdecS : decode s.executionEnv.code s.machineState.pc = some (.SIGNEXTEND, .none) := by - rw [hcode, hpc] - exact hdec - have hstep := step_signextend s hdecS - have hnoOverflow : ¬ 1024 ≤ t.length := by omega - simpa [hcode, hstk, GasConstants.Glow, observationsStSignextend, hnoOverflow] using hstep - -private theorem observationsRDSignextend {code : ByteArray} {ee : ExecutionEnv} - {g : Sat256} {s0 : State} {pc : UInt256} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.SIGNEXTEND, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.signextend a b :: t) mem aw rdata acc - (k + 1) (C + 5) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, - hee, hworld⟩ - · exact Or.inl hoog - · have st := observationsSignextendXstep hcode hpc hdec hstk hov - by_cases gg : g.toNat < C + 5 - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨observationsStSignextend s (UInt256.signextend a b) t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, - by omega, by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [observationsStSignextend]; exact hcode - · simp only [observationsStSignextend]; rw [hpc] - · rfl - · simp only [observationsStSignextend]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [observationsStSignextend]; exact hmem - · simp only [observationsStSignextend]; exact haw - · simp only [observationsStSignextend]; exact hrdata - · simp only [observationsStSignextend]; exact hacc - · exact hee - · exact hworld - -theorem uniswapV3PoolObservationsRoutine {v : PoolImmutables} {code : ByteArray} - {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {ret : UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5334⟩ (observationsArgWord ee :: ret :: R) - mem aw rdata (cA, σ) k C) - (hret : (D_J code 0).contains ret = true) - (hbound : (observationsArgWord ee).toNat < 65535) - (hov : R.length + 8 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret - (observationsInitializedRawWord σ ee :: - observationsSecondsPerLiquidityWord σ ee :: - observationsTickReturnWord σ ee :: - observationsBlockTimestampWord σ ee :: ret :: R) - mem aw rdata (cA, σ) k' C' := by - have hlt : UInt256.lt (observationsArgWord ee) ⟨65535⟩ = ⟨1⟩ := by - apply ult_one - rw [show (⟨65535⟩ : UInt256).toNat = 65535 from by decide] - exact hbound - have hdecode {pc : UInt256} (hlo : 5308 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 6603) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 6603 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolObservationsRoutinePatchDisjoint hlo hhi)] - have hd5334 : decode code ⟨5334⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5335 : decode code ⟨5335⟩ = some (.Push .PUSH1, some (⟨8⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5337 : decode code ⟨5337⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5338 : decode code ⟨5338⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5341 : decode code ⟨5341⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5342 : decode code ⟨5342⟩ = some (.LT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5343 : decode code ⟨5343⟩ = some (.Push .PUSH2, some (⟨5351⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5346 : decode code ⟨5346⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5351 : decode code ⟨5351⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5352 : decode code ⟨5352⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5353 : decode code ⟨5353⟩ = some (.SLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5354 : decode code ⟨5354⟩ = some (.Push .PUSH4, some (⟨4294967295⟩, 4)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5359 : decode code ⟨5359⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5360 : decode code ⟨5360⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5361 : decode code ⟨5361⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5362 : decode code ⟨5362⟩ = some (.POP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5363 : decode code ⟨5363⟩ = - some (.Push .PUSH5, some (⟨4294967296⟩, 5)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5369 : decode code ⟨5369⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5370 : decode code ⟨5370⟩ = some (.DIV, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5371 : decode code ⟨5371⟩ = some (.Push .PUSH1, some (⟨6⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5373 : decode code ⟨5373⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5374 : decode code ⟨5374⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5375 : decode code ⟨5375⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5377 : decode code ⟨5377⟩ = some (.Push .PUSH1, some (⟨88⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5379 : decode code ⟨5379⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5380 : decode code ⟨5380⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5381 : decode code ⟨5381⟩ = some (.DIV, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5382 : decode code ⟨5382⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5384 : decode code ⟨5384⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5386 : decode code ⟨5386⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5388 : decode code ⟨5388⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5389 : decode code ⟨5389⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5390 : decode code ⟨5390⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5391 : decode code ⟨5391⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5392 : decode code ⟨5392⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5394 : decode code ⟨5394⟩ = some (.Push .PUSH1, some (⟨248⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5396 : decode code ⟨5396⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5397 : decode code ⟨5397⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5398 : decode code ⟨5398⟩ = some (.DIV, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5399 : decode code ⟨5399⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5401 : decode code ⟨5401⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5402 : decode code ⟨5402⟩ = some (.DUP5, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5403 : decode code ⟨5403⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd5343 := evm_run h with [ - raw jumpdest hd5334 (by evm_ov), - raw push1 ⟨8⟩ hd5335 (by evm_ov), - raw dup2 hd5337 (by evm_ov), - raw push2 ⟨65535⟩ hd5338 (by evm_ov), - raw dup2 hd5341 (by evm_ov), - raw lt hd5342 (by evm_ov)] - rw [hlt] at rd5343 - have rd5346 := evm_run rd5343 with [ - raw push2 ⟨5351⟩ hd5343 (by evm_ov)] - have rd5351 := rd5346.jumpiT hd5346 - (by decide : (⟨1⟩ : UInt256) ≠ ⟨0⟩) - (uniswapV3PoolJumpDestPatched5351 hpatch) - (by evm_ov) - have rd5353 := evm_run rd5351 with [ - raw jumpdest hd5351 (by evm_ov), - raw add hd5352 (by evm_ov)] - obtain ⟨_, _, rd5354⟩ := rd5353.sload hd5353 (by evm_ov) - have rd5363 := evm_run rd5354 with [ - raw push4 ⟨4294967295⟩ hd5354 (by evm_ov), - raw dup2 hd5359 (by evm_ov), - raw and hd5360 (by evm_ov), - raw swap2 hd5361 (by evm_ov), - raw pop hd5362 (by evm_ov)] - have rd5369Ex : ∃ k' C', RD code ee g s0 ⟨5369⟩ - (⟨4294967296⟩ :: - (σ.find? ee.codeOwner |>.option ⟨0⟩ - (fun ac => ac.storage.findD (observationsArgWord ee + ⟨8⟩) ⟨0⟩)) :: - UInt256.land - (σ.find? ee.codeOwner |>.option ⟨0⟩ - (fun ac => ac.storage.findD (observationsArgWord ee + ⟨8⟩) ⟨0⟩)) - ⟨4294967295⟩ :: - ret :: R) - mem aw rdata (cA, σ) k' C' := by - exact ⟨_, _, by - simpa using rd5363.pushConst ⟨4294967296⟩ - (by decide : Operation.POp.PUSH5 ≠ .PUSH0) hd5363 (by evm_ov)⟩ - obtain ⟨_, _, rd5369⟩ := rd5369Ex - have rd5373 := evm_run rd5369 with [ - raw dup2 hd5369 (by evm_ov), - raw div hd5370 (by evm_ov), - raw push1 ⟨6⟩ hd5371 (by evm_ov)] - have rd5374 := observationsRDSignextend rd5373 hd5373 (by evm_ov) - have rd5403 := evm_run rd5374 with [ - raw swap1 hd5374 (by evm_ov), - raw push1 ⟨1⟩ hd5375 (by evm_ov), - raw push1 ⟨88⟩ hd5377 (by evm_ov), - raw shl hd5379 (by evm_ov), - raw dup2 hd5380 (by evm_ov), - raw div hd5381 (by evm_ov), - raw push1 ⟨1⟩ hd5382 (by evm_ov), - raw push1 ⟨1⟩ hd5384 (by evm_ov), - raw push1 ⟨160⟩ hd5386 (by evm_ov), - raw shl hd5388 (by evm_ov), - raw sub hd5389 (by evm_ov), - raw and hd5390 (by evm_ov), - raw swap1 hd5391 (by evm_ov), - raw push1 ⟨1⟩ hd5392 (by evm_ov), - raw push1 ⟨248⟩ hd5394 (by evm_ov), - raw shl hd5396 (by evm_ov), - raw swap1 hd5397 (by evm_ov), - raw div hd5398 (by evm_ov), - raw push1 ⟨255⟩ hd5399 (by evm_ov), - raw and hd5401 (by evm_ov), - raw dup5 hd5402 (by evm_ov)] - have rdRet := rd5403.jump hd5403 hret (by evm_ov) - have hmask32 : (⟨4294967295⟩ : UInt256) = observationsUint32Mask := by - native_decide - have hshift32 : (⟨4294967296⟩ : UInt256) = observationsShiftBytes 4 := by - native_decide - have hshift88 : - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨88⟩ = observationsShiftBytes 11 := by - native_decide - have hmask160 : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask := by - native_decide - have hshift248 : - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨248⟩ = observationsShiftBytes 31 := by - native_decide - have hmask8 : (⟨255⟩ : UInt256) = slot0Uint8Mask := by - native_decide - have hsecondsComm : - UInt256.land slot0Uint160Mask - (UInt256.div (observationsSlotWord σ ee) (observationsShiftBytes 11)) = - UInt256.land - (UInt256.div (observationsSlotWord σ ee) (observationsShiftBytes 11)) - slot0Uint160Mask := by - rw [u256_land_comm] - have hinitializedComm : - UInt256.land slot0Uint8Mask - (UInt256.div (observationsSlotWord σ ee) (observationsShiftBytes 31)) = - UInt256.land - (UInt256.div (observationsSlotWord σ ee) (observationsShiftBytes 31)) - slot0Uint8Mask := by - rw [u256_land_comm] - exact ⟨_, _, by - rw [hmask32, hshift32, hshift88, hmask160, hshift248, hmask8] at rdRet - simpa [observationsInitializedRawWord, observationsSecondsPerLiquidityWord, - observationsTickReturnWord, observationsTickRawWord, observationsBlockTimestampWord, - observationsSlotWord, solcSlotWord, observationsArgAddBase_eq_baseSlot, - hsecondsComm, hinitializedComm] using rdRet⟩ - -theorem uniswapV3PoolObservationsRoutineOob {v : PoolImmutables} {code : ByteArray} - {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {ret : UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5334⟩ (observationsArgWord ee :: ret :: R) - mem aw rdata (cA, σ) k C) - (hoob : 65535 ≤ (observationsArgWord ee).toNat) - (hov : R.length + 6 ≤ 1024) : - RDrev code g s0 := by - have hlt : UInt256.lt (observationsArgWord ee) ⟨65535⟩ = ⟨0⟩ := by - apply ult_zero - rw [show (⟨65535⟩ : UInt256).toNat = 65535 from by decide] - exact hoob - have hdecode {pc : UInt256} (hlo : 5308 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 6603) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 6603 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolObservationsRoutinePatchDisjoint hlo hhi)] - have hd5334 : decode code ⟨5334⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5335 : decode code ⟨5335⟩ = some (.Push .PUSH1, some (⟨8⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5337 : decode code ⟨5337⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5338 : decode code ⟨5338⟩ = some (.Push .PUSH2, some (⟨65535⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5341 : decode code ⟨5341⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5342 : decode code ⟨5342⟩ = some (.LT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5343 : decode code ⟨5343⟩ = some (.Push .PUSH2, some (⟨5351⟩, 2)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5346 : decode code ⟨5346⟩ = some (.JUMPI, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5347 : decode code ⟨5347⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5349 : decode code ⟨5349⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd5350 : decode code ⟨5350⟩ = some (.REVERT, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd5343 := evm_run h with [ - raw jumpdest hd5334 (by evm_ov), - raw push1 ⟨8⟩ hd5335 (by evm_ov), - raw dup2 hd5337 (by evm_ov), - raw push2 ⟨65535⟩ hd5338 (by evm_ov), - raw dup2 hd5341 (by evm_ov), - raw lt hd5342 (by evm_ov)] - rw [hlt] at rd5343 - have rd5346 := evm_run rd5343 with [ - raw push2 ⟨5351⟩ hd5343 (by evm_ov)] - have rd5347 := rd5346.jumpiNT hd5346 - (by decide : (⟨0⟩ : UInt256) = ⟨0⟩) - (by evm_ov) - exact RD.solcPush1Dup1Revert0 rd5347 hd5347 hd5349 hd5350 (by evm_ov) - -theorem uniswapV3PoolObservationsEvmOob {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 4 == I.calldata.extract 0 4) = true) - (hsz36 : 36 ≤ I.calldata.size) - (hoob : 65535 ≤ (observationsArgWord I).toNat) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - have hreach := uniswapV3PoolObservationsReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - obtain ⟨_, _, hdecoded⟩ := uniswapV3PoolObservationsExternalLenOk - hpatch hreach hsz36 hsize - obtain ⟨_, _, hroutine⟩ := uniswapV3PoolObservationsDecodedReachRoutine - hpatch hdecoded (by simp only [List.length_singleton]; omega) - exact uniswapV3PoolObservationsRoutineOob hpatch hroutine hoob - (by simp only [List.length_singleton]; omega) - -theorem uniswapV3PoolObservationsEvmLoaded {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 4 == I.calldata.extract 0 4) = true) - (hsz36 : 36 ≤ I.calldata.size) - (hbound : (observationsArgWord I).toNat < 65535) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨766⟩ - (observationsInitializedRawWord σ I :: - observationsSecondsPerLiquidityWord σ I :: - observationsTickReturnWord σ I :: - observationsBlockTimestampWord σ I :: ⟨766⟩ :: [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hreach := uniswapV3PoolObservationsReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - obtain ⟨_, _, hdecoded⟩ := uniswapV3PoolObservationsExternalLenOk - hpatch hreach hsz36 hsize - obtain ⟨_, _, hroutine⟩ := uniswapV3PoolObservationsDecodedReachRoutine - hpatch hdecoded (by simp only [List.length_singleton]; omega) - exact uniswapV3PoolObservationsRoutine hpatch hroutine - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - hbound (by simp only [List.length_singleton]; omega) - -noncomputable def observationsReturnMem1 (blockTimestamp : UInt256) : ByteArray := - writeCascade solcFreePtrMem [(128, blockTimestamp)] - -noncomputable def observationsReturnMem2 (blockTimestamp tick : UInt256) : ByteArray := - writeCascade solcFreePtrMem [(128, blockTimestamp), (160, tick)] - -noncomputable def observationsReturnMem3 (blockTimestamp tick seconds : UInt256) : - ByteArray := - writeCascade solcFreePtrMem [(128, blockTimestamp), (160, tick), (192, seconds)] - -noncomputable def observationsReturnMem - (blockTimestamp tick seconds initialized : UInt256) : ByteArray := - writeCascade solcFreePtrMem - [(128, blockTimestamp), (160, tick), (192, seconds), (224, initialized)] - -theorem observationsReturnMem1_eq (blockTimestamp : UInt256) : - observationsReturnMem1 blockTimestamp = writeWord solcFreePtrMem 128 blockTimestamp := by - rfl - -theorem observationsReturnMem2_eq (blockTimestamp tick : UInt256) : - observationsReturnMem2 blockTimestamp tick = - writeWord (observationsReturnMem1 blockTimestamp) 160 tick := by - rfl - -theorem observationsReturnMem3_eq (blockTimestamp tick seconds : UInt256) : - observationsReturnMem3 blockTimestamp tick seconds = - writeWord (observationsReturnMem2 blockTimestamp tick) 192 seconds := by - rfl - -theorem observationsReturnMem_eq - (blockTimestamp tick seconds initialized : UInt256) : - observationsReturnMem blockTimestamp tick seconds initialized = - writeWord (observationsReturnMem3 blockTimestamp tick seconds) 224 initialized := by - rfl - -theorem observationsReturnMem1_size (blockTimestamp : UInt256) : - (observationsReturnMem1 blockTimestamp).size = 160 := by - unfold observationsReturnMem1 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem observationsReturnMem2_size (blockTimestamp tick : UInt256) : - (observationsReturnMem2 blockTimestamp tick).size = 192 := by - unfold observationsReturnMem2 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem observationsReturnMem3_size (blockTimestamp tick seconds : UInt256) : - (observationsReturnMem3 blockTimestamp tick seconds).size = 224 := by - unfold observationsReturnMem3 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem observationsReturnMem_size - (blockTimestamp tick seconds initialized : UInt256) : - (observationsReturnMem blockTimestamp tick seconds initialized).size = 256 := by - unfold observationsReturnMem - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem observationsReturnMem_read64 - (blockTimestamp tick seconds initialized : UInt256) : - (observationsReturnMem blockTimestamp tick seconds initialized).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - unfold observationsReturnMem - rw [writeCascade_read_preserved_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WindowDisjointFromWrites] - all_goals native_decide)] - exact solcFreePtrMem_read64 - -theorem observationsReturnMem_mload64 - (blockTimestamp tick seconds initialized : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ - (observationsReturnMem blockTimestamp tick seconds initialized).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 8 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((observationsReturnMem blockTimestamp tick seconds initialized).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - ⟨128⟩ := - mloadFreePtrValue (by rw [observationsReturnMem_size]; decide) (by decide) - (observationsReturnMem_read64 blockTimestamp tick seconds initialized) - -theorem observationsReturnMem_read128 - (blockTimestamp tick seconds initialized : UInt256) : - (observationsReturnMem blockTimestamp tick seconds initialized).readWithPadding 128 32 = - UInt256.toByteArray blockTimestamp := by - unfold observationsReturnMem - exact writeCascade_read_word_of_head_of_base solcFreePtrMem (base := 96) (off := 128) - blockTimestamp [(160, tick), (192, seconds), (224, initialized)] - solcFreePtrMem_size (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem observationsReturnMem_read160 - (blockTimestamp tick seconds initialized : UInt256) : - (observationsReturnMem blockTimestamp tick seconds initialized).readWithPadding 160 32 = - UInt256.toByteArray tick := by - unfold observationsReturnMem - change (writeCascade (observationsReturnMem1 blockTimestamp) - [(160, tick), (192, seconds), (224, initialized)]).readWithPadding 160 32 = - UInt256.toByteArray tick - exact writeCascade_read_word_of_head_of_base (observationsReturnMem1 blockTimestamp) - (base := 160) (off := 160) tick [(192, seconds), (224, initialized)] - (observationsReturnMem1_size blockTimestamp) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem observationsReturnMem_read192 - (blockTimestamp tick seconds initialized : UInt256) : - (observationsReturnMem blockTimestamp tick seconds initialized).readWithPadding 192 32 = - UInt256.toByteArray seconds := by - unfold observationsReturnMem - change (writeCascade (observationsReturnMem2 blockTimestamp tick) - [(192, seconds), (224, initialized)]).readWithPadding 192 32 = - UInt256.toByteArray seconds - exact writeCascade_read_word_of_head_of_base (observationsReturnMem2 blockTimestamp tick) - (base := 192) (off := 192) seconds [(224, initialized)] - (observationsReturnMem2_size blockTimestamp tick) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem observationsReturnMem_read224 - (blockTimestamp tick seconds initialized : UInt256) : - (observationsReturnMem blockTimestamp tick seconds initialized).readWithPadding 224 32 = - UInt256.toByteArray initialized := by - unfold observationsReturnMem - change (writeCascade (observationsReturnMem3 blockTimestamp tick seconds) - [(224, initialized)]).readWithPadding 224 32 = - UInt256.toByteArray initialized - exact writeCascade_read_word_of_head_of_base - (observationsReturnMem3 blockTimestamp tick seconds) (base := 224) (off := 224) - initialized [] (observationsReturnMem3_size blockTimestamp tick seconds) - (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem observationsReturnMem_read128_128 - (blockTimestamp tick seconds initialized : UInt256) : - (observationsReturnMem blockTimestamp tick seconds initialized).readWithPadding 128 128 = - UInt256.toByteArray blockTimestamp ++ UInt256.toByteArray tick ++ - UInt256.toByteArray seconds ++ UInt256.toByteArray initialized := by - let mem := observationsReturnMem blockTimestamp tick seconds initialized - have hsize : mem.size = 256 := by - simpa [mem] using observationsReturnMem_size blockTimestamp tick seconds initialized - have h128 : mem.readWithPadding 128 32 = UInt256.toByteArray blockTimestamp := by - simpa [mem] using observationsReturnMem_read128 blockTimestamp tick seconds initialized - have h160 : mem.readWithPadding 160 32 = UInt256.toByteArray tick := by - simpa [mem] using observationsReturnMem_read160 blockTimestamp tick seconds initialized - have h192 : mem.readWithPadding 192 32 = UInt256.toByteArray seconds := by - simpa [mem] using observationsReturnMem_read192 blockTimestamp tick seconds initialized - have h224 : mem.readWithPadding 224 32 = UInt256.toByteArray initialized := by - simpa [mem] using observationsReturnMem_read224 blockTimestamp tick seconds initialized - change mem.readWithPadding 128 128 = _ - rw [byteArray_readWithPadding_split mem 128 32 96 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h128] - rw [byteArray_readWithPadding_split mem 160 32 64 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h160] - rw [byteArray_readWithPadding_split mem 192 32 32 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h192, h224] - simp only [ByteArray.append_assoc] - -theorem uniswapV3PoolObservationsReturn {v : PoolImmutables} {code : ByteArray} - {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} - {initialized seconds tick blockTimestamp : UInt256} {R : List UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨766⟩ - (initialized :: seconds :: tick :: blockTimestamp :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 10 ≤ 1024) : - RDret code g s0 acc - (UInt256.toByteArray (UInt256.land blockTimestamp observationsUint32Mask) ++ - UInt256.toByteArray (UInt256.signextend ⟨6⟩ tick) ++ - UInt256.toByteArray (UInt256.land seconds slot0Uint160Mask) ++ - UInt256.toByteArray (slot0BoolReturnWord initialized)) := by - let blockTimestamp' := UInt256.land blockTimestamp observationsUint32Mask - let tick' := UInt256.signextend ⟨6⟩ tick - let seconds' := UInt256.land seconds slot0Uint160Mask - let initialized' := slot0BoolReturnWord initialized - have hmask32 : (⟨4294967295⟩ : UInt256) = observationsUint32Mask := by - native_decide - have hmask160 : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask := by - native_decide - have hdecode {pc : UInt256} (hpc : pc.toNat + 33 ≤ 2258) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch hpc] - have hd766 : decode code ⟨766⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd767 : decode code ⟨767⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [hdecode (by native_decide)] - native_decide - have hd769 : decode code ⟨769⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd770 : decode code ⟨770⟩ = some (.MLOAD, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd771 : decode code ⟨771⟩ = - some (.Push .PUSH4, some (⟨4294967295⟩, 4)) := by - rw [hdecode (by native_decide)] - native_decide - have hd776 : decode code ⟨776⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd777 : decode code ⟨777⟩ = some (.SWAP6, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd778 : decode code ⟨778⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd779 : decode code ⟨779⟩ = some (.DUP6, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd780 : decode code ⟨780⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd781 : decode code ⟨781⟩ = some (.Push .PUSH1, some (⟨6⟩, 1)) := by - rw [hdecode (by native_decide)] - native_decide - have hd783 : decode code ⟨783⟩ = some (.SWAP4, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd784 : decode code ⟨784⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd785 : decode code ⟨785⟩ = some (.SWAP4, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd786 : decode code ⟨786⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd787 : decode code ⟨787⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdecode (by native_decide)] - native_decide - have hd789 : decode code ⟨789⟩ = some (.DUP6, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd790 : decode code ⟨790⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd791 : decode code ⟨791⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd792 : decode code ⟨792⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide)] - native_decide - have hd794 : decode code ⟨794⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide)] - native_decide - have hd796 : decode code ⟨796⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide)] - native_decide - have hd798 : decode code ⟨798⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd799 : decode code ⟨799⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd800 : decode code ⟨800⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd801 : decode code ⟨801⟩ = some (.SWAP2, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd802 : decode code ⟨802⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd803 : decode code ⟨803⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd804 : decode code ⟨804⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd805 : decode code ⟨805⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd806 : decode code ⟨806⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd807 : decode code ⟨807⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd808 : decode code ⟨808⟩ = some (.ISZERO, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd809 : decode code ⟨809⟩ = some (.Push .PUSH1, some (⟨96⟩, 1)) := by - rw [hdecode (by native_decide)] - native_decide - have hd811 : decode code ⟨811⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd812 : decode code ⟨812⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd813 : decode code ⟨813⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd814 : decode code ⟨814⟩ = some (.MLOAD, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd815 : decode code ⟨815⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd816 : decode code ⟨816⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd817 : decode code ⟨817⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd818 : decode code ⟨818⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd819 : decode code ⟨819⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide)] - native_decide - have hd821 : decode code ⟨821⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd822 : decode code ⟨822⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide)] - native_decide - have hd823 : decode code ⟨823⟩ = some (.RETURN, .none) := by - rw [hdecode (by native_decide)] - native_decide - have rd780 := evm_run h with [ - raw jumpdest hd766 (by evm_ov), - raw push1 ⟨64⟩ hd767 (by evm_ov), - raw dup1 hd769 (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) hd770 mem_cost solcFreePtrMem_mload64 - (by decide) (by evm_ov), - raw push4 ⟨4294967295⟩ hd771 (by evm_ov), - raw swap1 hd776 (by evm_ov), - raw swap6 hd777 (by evm_ov), - raw and hd778 (by evm_ov), - raw dup6 hd779 (by evm_ov)] - have rd781 := rd780.mstore 6 (observationsReturnMem1 blockTimestamp') - (UInt256.ofNat 5) hd780 mem_cost - (by - dsimp [blockTimestamp'] - rw [hmask32, show (⟨128⟩ : UInt256).toNat = 128 from by decide, - observationsReturnMem1_eq] - rfl) - (by decide) (by evm_ov) - have rd786 := evm_run rd781 with [ - raw push1 ⟨6⟩ hd781 (by evm_ov), - raw swap4 hd783 (by evm_ov), - raw swap1 hd784 (by evm_ov), - raw swap4 hd785 (by evm_ov)] - have rd787 := observationsRDSignextend rd786 hd786 (by evm_ov) - have rd791 := evm_run rd787 with [ - raw push1 ⟨32⟩ hd787 (by evm_ov), - raw dup6 hd789 (by evm_ov), - raw add hd790 (by evm_ov)] - have rd792 := rd791.mstore 3 (observationsReturnMem2 blockTimestamp' tick') - (UInt256.ofNat 6) hd791 mem_cost - (by - dsimp [tick'] - rw [show ((⟨128⟩ : UInt256) + ⟨32⟩).toNat = 160 from by decide, - observationsReturnMem2_eq] - rfl) - (by decide) (by evm_ov) - have rd806 := evm_run rd792 with [ - raw push1 ⟨1⟩ hd792 (by evm_ov), - raw push1 ⟨1⟩ hd794 (by evm_ov), - raw push1 ⟨160⟩ hd796 (by evm_ov), - raw shl hd798 (by evm_ov), - raw sub hd799 (by evm_ov), - raw swap1 hd800 (by evm_ov), - raw swap2 hd801 (by evm_ov), - raw and hd802 (by evm_ov), - raw dup4 hd803 (by evm_ov), - raw dup4 hd804 (by evm_ov), - raw add hd805 (by evm_ov)] - have rd807 := rd806.mstore 3 (observationsReturnMem3 blockTimestamp' tick' seconds') - (UInt256.ofNat 7) hd806 mem_cost - (by - dsimp [seconds'] - rw [hmask160, show ((⟨64⟩ : UInt256) + ⟨128⟩).toNat = 192 from by decide, - observationsReturnMem3_eq] - rfl) - (by decide) (by evm_ov) - have rd813 := evm_run rd807 with [ - raw iszero hd807 (by evm_ov), - raw iszero hd808 (by evm_ov), - raw push1 ⟨96⟩ hd809 (by evm_ov), - raw dup4 hd811 (by evm_ov), - raw add hd812 (by evm_ov)] - have rd814 := rd813.mstore 3 - (observationsReturnMem blockTimestamp' tick' seconds' initialized') - (UInt256.ofNat 8) hd813 mem_cost - (by - dsimp [initialized', slot0BoolReturnWord] - rw [show ((⟨128⟩ : UInt256) + ⟨96⟩).toNat = 224 from by decide, - observationsReturnMem_eq] - rfl) - (by decide) (by evm_ov) - exact evm_run rd814 with [ - raw mload 0 ⟨128⟩ (UInt256.ofNat 8) hd814 mem_cost - (observationsReturnMem_mload64 blockTimestamp' tick' seconds' initialized') - (by decide) (by evm_ov), - raw swap1 hd815 (by evm_ov), - raw dup2 hd816 (by evm_ov), - raw swap1 hd817 (by evm_ov), - raw sub hd818 (by evm_ov), - raw push1 ⟨128⟩ hd819 (by evm_ov), - raw add hd821 (by evm_ov), - raw swap1 hd822 (by evm_ov), - raw ret 0 - (UInt256.toByteArray blockTimestamp' ++ UInt256.toByteArray tick' ++ - UInt256.toByteArray seconds' ++ UInt256.toByteArray initialized') - hd823 mem_cost - (by - dsimp [blockTimestamp', tick', seconds', initialized'] - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - show ((⟨128⟩ : UInt256) + UInt256.sub (⟨128⟩ : UInt256) ⟨128⟩).toNat = - 128 from by decide] - exact observationsReturnMem_read128_128 - (UInt256.land blockTimestamp observationsUint32Mask) - (UInt256.signextend ⟨6⟩ tick) - (UInt256.land seconds slot0Uint160Mask) (slot0BoolReturnWord initialized)) - (by evm_ov)] - -theorem uniswapV3PoolObservationsEvm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 4 == I.calldata.extract 0 4) = true) - (hsz36 : 36 ≤ I.calldata.size) - (hbound : (observationsArgWord I).toNat < 65535) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (observationsBlockTimestampWord σ I) ++ - UInt256.toByteArray (UInt256.signextend ⟨6⟩ (observationsTickReturnWord σ I)) ++ - UInt256.toByteArray (observationsSecondsPerLiquidityWord σ I) ++ - UInt256.toByteArray (observationsInitializedReturnWord σ I)) := by - obtain ⟨_, _, rdReturn⟩ := uniswapV3PoolObservationsEvmLoaded - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - hsz36 hbound - have hret := uniswapV3PoolObservationsReturn hpatch - (initialized := observationsInitializedRawWord σ I) - (seconds := observationsSecondsPerLiquidityWord σ I) - (tick := observationsTickReturnWord σ I) - (blockTimestamp := observationsBlockTimestampWord σ I) - (R := [⟨766⟩, solcSelectorWord I]) rdReturn - (by simp only [List.length_cons, List.length_nil]; omega) - have hblock : - UInt256.land (observationsBlockTimestampWord σ I) observationsUint32Mask = - observationsBlockTimestampWord σ I := by - exact observationsUint32Mask_clean (by - simpa [observationsBlockTimestampWord] using - observationsUint32Mask_bound (observationsSlotWord σ I)) - have hseconds : - UInt256.land (observationsSecondsPerLiquidityWord σ I) slot0Uint160Mask = - observationsSecondsPerLiquidityWord σ I := by - exact slot0Uint160Mask_clean (by - simpa [observationsSecondsPerLiquidityWord] using - slot0Uint160Mask_bound - (UInt256.div (observationsSlotWord σ I) (observationsShiftBytes 11))) - simpa [observationsInitializedReturnWord, hblock, hseconds] using hret - -theorem observationsStorageLocLoad_blockTimestamp (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (observationsBaseSlot I) ⟨0, by decide⟩ ⟨4, by decide⟩ - (by decide) (.int uint32Int)) = - .int (Int.ofNat (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (observationsBaseSlot I)) - observationsUint32Mask).toNat) := by - rw [← show UInt256.ofNat (2 ^ (8 * 4) - 1) = observationsUint32Mask by native_decide] - simpa [loc, uint32Int] using - storageLocLoad_uint_offset0 evm (observationsBaseSlot I) (4 : Fin 33) ⟨32, by decide⟩ - (hbound := by decide) (by decide) - -theorem observationsStorageLocLoad_tickCumulative (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (observationsBaseSlot I) ⟨4, by decide⟩ ⟨7, by decide⟩ - (by decide) (.int int56Int)) = - wordToElem (.int int56Int) - (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (observationsBaseSlot I)) - (observationsShiftBytes 4)) - observationsUint56Mask) := by - rw [← show UInt256.ofNat (256 ^ (4 : Nat)) = observationsShiftBytes 4 by rfl] - rw [← show UInt256.ofNat (256 ^ (7 : Nat) - 1) = observationsUint56Mask by - native_decide] - simpa [loc, int56Int] using - storageLocLoad_sint_offset evm (observationsBaseSlot I) (4 : Fin 32) (7 : Fin 33) - ⟨56, by decide⟩ (hbound := by decide) (by decide) (by decide) - -theorem observationsStorageLocLoad_secondsPerLiquidity (evm : EVM.State) - (I : ExecutionEnv) : - storageLocLoad evm - (loc (observationsBaseSlot I) ⟨11, by decide⟩ ⟨20, by decide⟩ - (by decide) (.int uint160Int)) = - .int (Int.ofNat (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (observationsBaseSlot I)) - (observationsShiftBytes 11)) - slot0Uint160Mask).toNat) := by - rw [← show UInt256.ofNat (256 ^ (11 : Nat)) = observationsShiftBytes 11 by rfl] - rw [← show UInt256.ofNat (256 ^ (20 : Nat) - 1) = slot0Uint160Mask by native_decide] - simpa [loc, uint160Int] using - storageLocLoad_uint_offset evm (observationsBaseSlot I) (11 : Fin 32) (20 : Fin 33) - ⟨160, by decide⟩ (hbound := by decide) (by decide) (by decide) - -theorem observationsStorageLocLoad_initialized (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (observationsBaseSlot I) ⟨31, by decide⟩ ⟨1, by decide⟩ - (by decide) .bool) = - wordToElem .bool - (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (observationsBaseSlot I)) - (observationsShiftBytes 31)) - slot0Uint8Mask) := by - rw [← show UInt256.ofNat (256 ^ (31 : Nat)) = observationsShiftBytes 31 by rfl] - simpa [loc] using - storageLocLoad_bool_offset evm (observationsBaseSlot I) (31 : Fin 32) - (hbound := by decide) (by decide) - -theorem uniswapV3PoolObservationsSourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hbound : (observationsArgWord I).toNat < 65535) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (observationsStore I) observationsTransition.body - (.returned { contract := contract v, locals := observationsStore I } - (initState cA gh bl σ σ₀ g A I) - (some (observationsReturnValues σ I))) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (observationsStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (ltE (.var "arg0") (.intLit 65535)), - .return [ .storage (observationsRawF (.var "arg0") "blockTimestamp"), - .storage (observationsRawF (.var "arg0") "tickCumulative"), - .storage (observationsRawF (.var "arg0") "secondsPerLiquidityCumulativeX128"), - .storage (observationsRawF (.var "arg0") "initialized") ] ] _ - exact ExecFuncBody.execBlockRet <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true (by simp [initState, hwv]))) <| - ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_observations_bound_true (initState cA gh bl σ σ₀ g A I) I hbound)) <| - ExecBlock.consReturn <| ExecStmt.return (by - have hblock : - evalExpr? (config v) { contract := contract v, locals := observationsStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (observationsRawF (.var "arg0") "blockTimestamp")) = - .ok (.int (Int.ofNat (observationsBlockTimestampWord σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := observationsRawEvaledRef I "blockTimestamp") - (t := .int uint32Int) - (loc := loc (observationsBaseSlot I) ⟨0, by decide⟩ ⟨4, by decide⟩ - (by decide) (.int uint32Int)) - · simp [observationsStore, observationsRawF] - · exact evalStorageRef_observationsRaw - (v := v) (initState cA gh bl σ σ₀ g A I) I "blockTimestamp" - · simp [observationsRawEvaledRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, observationStructTy, uint32St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - observationsRawEvaledRef, observationsBaseSlot, loc] - · simpa [initState, observationsBlockTimestampWord, observationsSlotWord, - solcSlotWord] using - observationsStorageLocLoad_blockTimestamp (initState cA gh bl σ σ₀ g A I) I - have htick : - evalExpr? (config v) { contract := contract v, locals := observationsStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (observationsRawF (.var "arg0") "tickCumulative")) = - .ok (wordToElem (.int int56Int) (observationsTickStorageWord σ I)) := by - apply evalExpr_storage_scalar_value - (er := observationsRawEvaledRef I "tickCumulative") - (t := .int int56Int) - (loc := loc (observationsBaseSlot I) ⟨4, by decide⟩ ⟨7, by decide⟩ - (by decide) (.int int56Int)) - · simp [observationsStore, observationsRawF] - · exact evalStorageRef_observationsRaw - (v := v) (initState cA gh bl σ σ₀ g A I) I "tickCumulative" - · simp [observationsRawEvaledRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, observationStructTy, int56St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - observationsRawEvaledRef, observationsBaseSlot, loc] - · simpa [initState, observationsTickStorageWord, observationsTickRawWord, - observationsSlotWord, solcSlotWord] using - observationsStorageLocLoad_tickCumulative (initState cA gh bl σ σ₀ g A I) I - have hseconds : - evalExpr? (config v) { contract := contract v, locals := observationsStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (observationsRawF (.var "arg0") - "secondsPerLiquidityCumulativeX128")) = - .ok (.int (Int.ofNat (observationsSecondsPerLiquidityWord σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := observationsRawEvaledRef I "secondsPerLiquidityCumulativeX128") - (t := .int uint160Int) - (loc := loc (observationsBaseSlot I) ⟨11, by decide⟩ ⟨20, by decide⟩ - (by decide) (.int uint160Int)) - · simp [observationsStore, observationsRawF] - · exact evalStorageRef_observationsRaw - (v := v) (initState cA gh bl σ σ₀ g A I) - I "secondsPerLiquidityCumulativeX128" - · simp [observationsRawEvaledRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, observationStructTy, uint160St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - observationsRawEvaledRef, observationsBaseSlot, loc] - · simpa [initState, observationsSecondsPerLiquidityWord, observationsSlotWord, - solcSlotWord] using - observationsStorageLocLoad_secondsPerLiquidity - (initState cA gh bl σ σ₀ g A I) I - have hinit : - evalExpr? (config v) { contract := contract v, locals := observationsStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (observationsRawF (.var "arg0") "initialized")) = - .ok (wordToElem .bool (observationsInitializedRawWord σ I)) := by - apply evalExpr_storage_scalar_value - (er := observationsRawEvaledRef I "initialized") - (t := .bool) - (loc := loc (observationsBaseSlot I) ⟨31, by decide⟩ ⟨1, by decide⟩ - (by decide) .bool) - · simp [observationsStore, observationsRawF] - · exact evalStorageRef_observationsRaw - (v := v) (initState cA gh bl σ σ₀ g A I) I "initialized" - · simp [observationsRawEvaledRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, observationStructTy, boolSt] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - observationsRawEvaledRef, observationsBaseSlot, loc] - · simpa [initState, observationsInitializedRawWord, observationsSlotWord, - solcSlotWord] using - observationsStorageLocLoad_initialized (initState cA gh bl σ σ₀ g A I) I - simp only [observationsReturnValues, Solm.evalExprs?.eq_def, hblock, htick, - hseconds, hinit, EvalResult.bind, bind, pure]) - -theorem uniswapV3PoolObservationsSourceBodyOob {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hoob : 65535 ≤ (observationsArgWord I).toNat) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (observationsStore I) observationsTransition.body - .reverted := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (observationsStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (ltE (.var "arg0") (.intLit 65535)), - .return [ .storage (observationsRawF (.var "arg0") "blockTimestamp"), - .storage (observationsRawF (.var "arg0") "tickCumulative"), - .storage (observationsRawF (.var "arg0") "secondsPerLiquidityCumulativeX128"), - .storage (observationsRawF (.var "arg0") "initialized") ] ] _ - exact ExecFuncBody.execBlockRevert <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true (by simp [initState, hwv]))) <| - ExecBlock.consRevert <| - ExecStmt.requireFalse - (evalExpr_observations_bound_false (initState cA gh bl σ σ₀ g A I) I hoob) - -theorem observationsReturnEncoding (σ : AccountMap) (I : ExecutionEnv) : - encodeReturnValues? [uint32, int56, uint160, boolTy] - (observationsReturnValues σ I) = - some (UInt256.toByteArray (observationsBlockTimestampWord σ I) ++ - UInt256.toByteArray (UInt256.signextend ⟨6⟩ (observationsTickReturnWord σ I)) ++ - UInt256.toByteArray (observationsSecondsPerLiquidityWord σ I) ++ - UInt256.toByteArray (slot0BoolReturnWord (observationsInitializedRawWord σ I))) := by - have hwordBlock : EVM.word (observationsBlockTimestampWord σ I).toNat = - observationsBlockTimestampWord σ I := u256_ofNat_toNat _ - have hwordSeconds : EVM.word (observationsSecondsPerLiquidityWord σ I).toNat = - observationsSecondsPerLiquidityWord σ I := u256_ofNat_toNat _ - have hblockLt : (observationsBlockTimestampWord σ I).toNat < EVM.twoPow 32 := by - simpa [observationsBlockTimestampWord] using - observationsUint32Mask_bound (observationsSlotWord σ I) - have hsecondsLt : (observationsSecondsPerLiquidityWord σ I).toNat < - EVM.twoPow 160 := by - simpa [observationsSecondsPerLiquidityWord] using - slot0Uint160Mask_bound - (UInt256.div (observationsSlotWord σ I) (observationsShiftBytes 11)) - have hencBlock : - encodeABIValue? uint32 - (.int (Int.ofNat (observationsBlockTimestampWord σ I).toNat)) = - some (EVM.Word.toBytesBE (observationsBlockTimestampWord σ I)) := by - simp [uint32, uint32Int, encodeABIValue?, encodeABIWord?, hwordBlock, hblockLt] - have hencTick : - encodeABIValue? int56 - (wordToElem (.int int56Int) (observationsTickStorageWord σ I)) = - some (EVM.Word.toBytesBE - (UInt256.signextend ⟨6⟩ (observationsTickReturnWord σ I))) := by - change encodeABIValue? int56 - (.int (observationsSint56Value (observationsTickStorageWord σ I))) = - some (EVM.Word.toBytesBE - (UInt256.signextend ⟨6⟩ (observationsTickReturnWord σ I))) - have hge := observationsSint56Value_ge (observationsTickStorageWord σ I) - have hlt := observationsSint56Value_lt (observationsTickStorageWord σ I) - have hidem : UInt256.signextend ⟨6⟩ (observationsTickReturnWord σ I) = - observationsTickReturnWord σ I := by - dsimp [observationsTickReturnWord] - exact observationsSignextendSix_idempotent (observationsTickRawWord σ I) - have hword : EVM.wordOfInt - (observationsSint56Value (observationsTickStorageWord σ I)) = - UInt256.signextend ⟨6⟩ (observationsTickReturnWord σ I) := by - rw [hidem] - dsimp [observationsTickStorageWord, observationsTickReturnWord] - exact observationsTickRawValue_wordOfInt (observationsTickRawWord σ I) - simp only [int56, int56Int, encodeABIValue?, encodeABIWord?] - rw [if_neg (by decide : 56 ≠ 0), if_pos] - · rw [hword] - rfl - · constructor - · simpa [EVM.twoPow] using hge - · simpa [EVM.twoPow] using hlt - have hencSeconds : - encodeABIValue? uint160 - (.int (Int.ofNat (observationsSecondsPerLiquidityWord σ I).toNat)) = - some (EVM.Word.toBytesBE (observationsSecondsPerLiquidityWord σ I)) := by - simp [uint160, uint160Int, encodeABIValue?, encodeABIWord?, hwordSeconds, - hsecondsLt] - have hencInitialized : - encodeABIValue? boolTy (wordToElem .bool (observationsInitializedRawWord σ I)) = - some (EVM.Word.toBytesBE - (slot0BoolReturnWord (observationsInitializedRawWord σ I))) := - slot0BoolABIEncoding (observationsInitializedRawWord σ I) - have hhead : abiTupleHeadSize? [uint32, int56, uint160, boolTy] = some 128 := by - native_decide - have hdyn32 : isDynamicABIType uint32 = false := by native_decide - have hdyn56 : isDynamicABIType int56 = false := by native_decide - have hdyn160 : isDynamicABIType uint160 = false := by native_decide - have hdynBool : isDynamicABIType boolTy = false := by native_decide - rw [toByteArray_eq_toBytesBE (observationsBlockTimestampWord σ I), - toByteArray_eq_toBytesBE (UInt256.signextend ⟨6⟩ (observationsTickReturnWord σ I)), - toByteArray_eq_toBytesBE (observationsSecondsPerLiquidityWord σ I), - toByteArray_eq_toBytesBE (slot0BoolReturnWord (observationsInitializedRawWord σ I))] - simp only [observationsReturnValues, encodeReturnValues?, encodeABIValues?, - encodeABIValuesFrom?, hhead, hencBlock, hencTick, hencSeconds, hencInitialized, - hdyn32, hdyn56, hdyn160, hdynBool, bind, Option.bind, Bool.false_eq_true, if_false, - List.nil_append, List.append_nil] - apply congrArg some - apply ByteArray.ext - apply Array.toList_inj.mp - simp - -theorem uniswapV3PoolObservationsValueTransport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - some (observationsReturnValues σ_solm I) = - some (observationsReturnValues σ_evm I) := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner - (observationsBaseSlot I) (⟨0⟩ : UInt256) - dsimp [observationsReturnValues, observationsBlockTimestampWord, - observationsTickStorageWord, observationsTickRawWord, observationsSecondsPerLiquidityWord, - observationsInitializedRawWord, observationsSlotWord, solcSlotWord] - rw [← hslot] - -theorem uniswapV3PoolObservationsBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 4 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_observations (v := v) (cd := I.calldata) hsel - have hvalue := uniswapV3PoolObservationsValueTransport (σ_evm := σ_evm) - (σ_solm := σ_solm) (I := I) hAccounts - by_cases hsz36 : 36 ≤ I.calldata.size - · have hdecode := uniswapV3PoolObservationsDecodeOk (v := v) (I := I) hsz36 - by_cases hbound : (observationsArgWord I).toNat < 65535 - · have hbody := uniswapV3PoolObservationsSourceBody (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv hbound - have hrd := uniswapV3PoolObservationsEvm (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hsz36 hbound - exact hrd.reEquivExecutionTransport hcode hdispatch hdecode hbody hvalue hAccounts - (by - rw [show observationsTransition.returnType = [uint32, int56, uint160, boolTy] from rfl] - exact returnEquiv.returned rfl (observationsReturnEncoding σ_evm I)) - · have hoob : 65535 ≤ (observationsArgWord I).toNat := by omega - have hbody := uniswapV3PoolObservationsSourceBodyOob (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv hoob - have hrd := uniswapV3PoolObservationsEvmOob (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hsz36 hoob - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hshort : I.calldata.size < 36 := by omega - have hdecode := uniswapV3PoolObservationsDecodeShort (v := v) (I := I) hshort - have hrd := uniswapV3PoolObservationsEvmDecodeShort (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hshort - exact hrd.reEquivDecodingFailed hcode hdispatch hdecode - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/ObservationsInt56.lean b/Benchmarks/UniswapV3Pool/ObservationsInt56.lean deleted file mode 100644 index 54266207..00000000 --- a/Benchmarks/UniswapV3Pool/ObservationsInt56.lean +++ /dev/null @@ -1,379 +0,0 @@ -import Benchmarks.UniswapV3Pool.Slot0 - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev observationsUint56Mask : UInt256 := - UInt256.ofNat (2 ^ 56 - 1) - -def observationsSint56Value (w : UInt256) : Int := - let m := w.toNat % EVM.twoPow 56 - if m < EVM.twoPow 55 then (m : Int) else (m : Int) - (EVM.twoPow 56 : Int) - -theorem observationsUint56Mask_toNat : - observationsUint56Mask.toNat = 2 ^ 56 - 1 := by - exact ulit_toNat' _ (by norm_num [UInt256.size]) - -private theorem signextend_six_norm (w : UInt256) : UInt256.signextend ⟨6⟩ w = - if UInt256.land w (UInt256.ofNat (2 ^ 55)) = ⟨0⟩ then - UInt256.land w (UInt256.ofNat (2 ^ 55 - 1)) - else UInt256.lor w (UInt256.ofNat (UInt256.size - 2 ^ 55)) := by - unfold UInt256.signextend - rw [if_pos (by native_decide : (⟨6⟩ : UInt256).toNat ≤ 31)] - have htest : (⟨6⟩ : UInt256) * ⟨8⟩ + ⟨7⟩ = ⟨55⟩ := by native_decide - simp only [htest] - have hsign : (⟨1⟩ : UInt256) <<< (⟨55⟩ : UInt256) = UInt256.ofNat (2 ^ 55) := by - native_decide - rw [hsign] - have hsub1 : UInt256.ofNat (2 ^ 55) - ⟨1⟩ = UInt256.ofNat (2 ^ 55 - 1) := by - native_decide - have hsub2 : UInt256.size.toUInt256 - UInt256.ofNat (2 ^ 55) = - UInt256.ofNat (UInt256.size - 2 ^ 55) := by - native_decide - rw [hsub1, hsub2] - change (if UInt256.land w (UInt256.ofNat (2 ^ 55)) ≠ ⟨0⟩ then - UInt256.lor w (UInt256.ofNat (UInt256.size - 2 ^ 55)) - else UInt256.land w (UInt256.ofNat (2 ^ 55 - 1))) = _ - by_cases hzero : UInt256.land w (UInt256.ofNat (2 ^ 55)) = ⟨0⟩ - · rw [if_neg (by exact not_not.mpr hzero), if_pos hzero] - · rw [if_pos hzero, if_neg hzero] - -private theorem signextend_six_sign_bit_zero (w : UInt256) - (hm : w.toNat % EVM.twoPow 56 < EVM.twoPow 55) : - UInt256.land w (UInt256.ofNat (2 ^ 55)) = ⟨0⟩ := by - apply u256_inj - rw [u256_land_toNat] - have hbitm : (w.toNat % EVM.twoPow 56).testBit 55 = false := by - exact Nat.testBit_lt_two_pow (x := w.toNat % EVM.twoPow 56) (i := 55) hm - change (w.toNat % 2 ^ 56).testBit 55 = false at hbitm - rw [Nat.testBit_mod_two_pow] at hbitm - have hbitw : w.toNat.testBit 55 = false := by simpa using hbitm - rw [show (UInt256.ofNat (2 ^ 55)).toNat = 2 ^ 55 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] - change (w.toNat &&& 2 ^ 55) % UInt256.size = (⟨0⟩ : UInt256).toNat - rw [Nat.and_two_pow, hbitw] - norm_num - -private theorem signextend_six_sign_bit_ne_zero (w : UInt256) - (hm : ¬ w.toNat % EVM.twoPow 56 < EVM.twoPow 55) : - UInt256.land w (UInt256.ofNat (2 ^ 55)) ≠ ⟨0⟩ := by - intro hzero - have hmhi : w.toNat % EVM.twoPow 56 < EVM.twoPow 56 := - Nat.mod_lt _ (by norm_num [EVM.twoPow]) - have hmge : EVM.twoPow 55 ≤ w.toNat % EVM.twoPow 56 := by omega - have hdiv : (w.toNat % EVM.twoPow 56) / EVM.twoPow 55 = 1 := by - apply Nat.div_eq_of_lt_le (k := 1) - · simpa [EVM.twoPow] using hmge - · simpa [EVM.twoPow] using hmhi - have hbitm : (w.toNat % EVM.twoPow 56).testBit 55 = true := by - simp [Nat.testBit, Nat.shiftRight_eq_div_pow, EVM.twoPow] - have hdiv' : w.toNat % 72057594037927936 / 36028797018963968 = 1 := by - simpa [EVM.twoPow] using hdiv - rw [hdiv'] - change (w.toNat % 2 ^ 56).testBit 55 = true at hbitm - rw [Nat.testBit_mod_two_pow] at hbitm - have hbitw : w.toNat.testBit 55 = true := by simpa using hbitm - have htoNat := congrArg UInt256.toNat hzero - rw [u256_land_toNat] at htoNat - rw [show (UInt256.ofNat (2 ^ 55)).toNat = 2 ^ 55 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] at htoNat - change (w.toNat &&& 2 ^ 55) % UInt256.size = (⟨0⟩ : UInt256).toNat at htoNat - rw [Nat.and_two_pow, hbitw] at htoNat - norm_num [UInt256.size] at htoNat - -private theorem nat_lor_high_mask_55 (n : Nat) (hn : n < 2 ^ 256) : - Nat.lor n (2 ^ 256 - 2 ^ 55) = n % 2 ^ 55 + (2 ^ 256 - 2 ^ 55) := by - have hmask : 2 ^ 256 - 2 ^ 55 = (2 ^ (256 - 55) - 1) <<< 55 := by - rw [Nat.shiftLeft_eq] - norm_num [Nat.pow_add] - rw [hmask] - rw [Nat.shiftLeft_eq] - rw [← nat_lor_shift_add (n % 2 ^ 55) (2 ^ (256 - 55) - 1) 55 - (Nat.mod_lt _ (by norm_num))] - apply Nat.eq_of_testBit_eq - intro i - change (n ||| ((2 ^ (256 - 55) - 1) * 2 ^ 55)).testBit i = - ((n % 2 ^ 55) ||| ((2 ^ (256 - 55) - 1) * 2 ^ 55)).testBit i - rw [Nat.testBit_or, Nat.testBit_or] - rw [show (2 ^ (256 - 55) - 1) * 2 ^ 55 = - (2 ^ (256 - 55) - 1) <<< 55 by rw [Nat.shiftLeft_eq]] - rw [testBit_shiftLeft] - by_cases hi55 : i < 55 - · rw [if_pos hi55] - conv_rhs => rw [Nat.testBit_mod_two_pow] - simp [hi55] - · rw [if_neg hi55] - rw [Nat.testBit_two_pow_sub_one] - by_cases hi256 : i < 256 - · have hlt201 : i - 55 < 256 - 55 := by omega - rw [decide_eq_true hlt201] - simp - · have hnbit : n.testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hn (Nat.pow_le_pow_right (by norm_num) (by omega))) - have hmodbit : (n % 2 ^ 55).testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 55)) - (Nat.pow_le_pow_right (by norm_num) (by omega))) - have hnot201 : ¬ i - 55 < 256 - 55 := by omega - rw [decide_eq_false hnot201, hnbit, hmodbit] - -private theorem wordOfInt_sint56_neg_toNat (m : Nat) (hmhi : m < EVM.twoPow 56) : - (EVM.wordOfInt ((m : Int) - (EVM.twoPow 56 : Int))).toNat = - UInt256.size - (EVM.twoPow 56 - m) := by - have hneg : ((m : Int) - (EVM.twoPow 56 : Int)) < 0 := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hnatAbs : ((m : Int) - (EVM.twoPow 56 : Int)).natAbs = EVM.twoPow 56 - m := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hdiffPos : EVM.twoPow 56 - m ≠ 0 := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hdiffLt : EVM.twoPow 56 - m < EVM.wordModulus := by - norm_num [EVM.wordModulus, EVM.twoPow] at hmhi ⊢ - omega - unfold EVM.wordOfInt - rw [if_pos hneg] - rw [hnatAbs, Nat.mod_eq_of_lt hdiffLt, if_neg hdiffPos] - change (UInt256.ofNat (EVM.wordModulus - (EVM.twoPow 56 - m))).toNat = _ - rw [ulit_toNat'] - · simp [EVM.wordModulus, EVM.twoPow, UInt256.size] - · norm_num [EVM.wordModulus, EVM.twoPow, UInt256.size] at hmhi ⊢ - omega - -theorem wordOfInt_sint56Value_eq_signextend_six (w : UInt256) : - EVM.wordOfInt (observationsSint56Value w) = UInt256.signextend ⟨6⟩ w := by - apply u256_inj - rw [signextend_six_norm] - unfold observationsSint56Value - let m := w.toNat % EVM.twoPow 56 - have hmdef : m = w.toNat % EVM.twoPow 56 := rfl - have hmhi : m < EVM.twoPow 56 := by - rw [hmdef] - exact Nat.mod_lt _ (by norm_num [EVM.twoPow]) - have hwlt : w.toNat < UInt256.size := by - simp [UInt256.toNat] - by_cases h : m < EVM.twoPow 55 - · have hzero : UInt256.land w (UInt256.ofNat (2 ^ 55)) = ⟨0⟩ := by - apply signextend_six_sign_bit_zero - rwa [← hmdef] - rw [if_pos hzero] - have hval : - (let m := w.toNat % EVM.twoPow 56 - if m < EVM.twoPow 55 then (m : Int) else (m : Int) - (EVM.twoPow 56 : Int)) = - (m : Int) := by - dsimp - have h' : w.toNat % EVM.twoPow 56 < EVM.twoPow 55 := by rwa [← hmdef] - rw [if_pos h'] - omega - rw [hval] - have hword : (EVM.wordOfInt (m : Int)).toNat = m := by - unfold EVM.wordOfInt - rw [if_neg (by omega)] - unfold EVM.word EVM.uintN UInt256.toNat - change m % EVM.twoPow 256 = m - apply Nat.mod_eq_of_lt - norm_num [EVM.twoPow] at hmhi ⊢ - omega - rw [hword] - rw [u256_land_toNat] - rw [show (UInt256.ofNat (2 ^ 55 - 1)).toNat = 2 ^ 55 - 1 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] - change m = Nat.land w.toNat (2 ^ 55 - 1) % UInt256.size - rw [nat_land_mask_eq_mod] - have hmdef' : m = w.toNat % 2 ^ 56 := by simpa [EVM.twoPow] using hmdef - have hmod55 : w.toNat % 2 ^ 55 = m := by - have hmod56 : w.toNat % 2 ^ 56 = m := hmdef'.symm - rw [← Nat.mod_mod_of_dvd (a := w.toNat) (show 2 ^ 55 ∣ 2 ^ 56 by norm_num)] - rw [hmod56] - exact Nat.mod_eq_of_lt (by simpa [EVM.twoPow] using h) - rw [hmod55] - rw [Nat.mod_eq_of_lt (by - norm_num [EVM.twoPow, UInt256.size] at hmhi ⊢ - omega)] - · have hne : UInt256.land w (UInt256.ofNat (2 ^ 55)) ≠ ⟨0⟩ := by - apply signextend_six_sign_bit_ne_zero - rwa [← hmdef] - rw [if_neg hne] - have hval : - (let m := w.toNat % EVM.twoPow 56 - if m < EVM.twoPow 55 then (m : Int) else (m : Int) - (EVM.twoPow 56 : Int)) = - (m : Int) - (EVM.twoPow 56 : Int) := by - dsimp - have h' : ¬ w.toNat % EVM.twoPow 56 < EVM.twoPow 55 := by - intro hh - exact h (by rwa [hmdef]) - rw [if_neg h'] - omega - rw [hval] - have hword := wordOfInt_sint56_neg_toNat m hmhi - rw [hword] - rw [u256_lor_toNat] - rw [show (UInt256.ofNat (UInt256.size - 2 ^ 55)).toNat = - UInt256.size - 2 ^ 55 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] - have hlor := nat_lor_high_mask_55 w.toNat (by simpa [UInt256.size] using hwlt) - change UInt256.size - (EVM.twoPow 56 - m) = - (Nat.lor w.toNat (2 ^ 256 - 2 ^ 55)) % UInt256.size - rw [hlor] - have hmdef' : m = w.toNat % 2 ^ 56 := by simpa [EVM.twoPow] using hmdef - have hmod55 : w.toNat % 2 ^ 55 = m - 2 ^ 55 := by - have hge : 2 ^ 55 ≤ m := by - have hnot : ¬ m < 2 ^ 55 := by simpa [EVM.twoPow] using h - omega - have hmhi' : m < 2 ^ 56 := by simpa [EVM.twoPow] using hmhi - have hmod56 : w.toNat % 2 ^ 56 = m := hmdef'.symm - rw [← Nat.mod_mod_of_dvd (a := w.toNat) (show 2 ^ 55 ∣ 2 ^ 56 by norm_num)] - rw [hmod56] - rw [Nat.mod_eq_sub_mod hge] - rw [Nat.mod_eq_of_lt (by omega : m - 2 ^ 55 < 2 ^ 55)] - rw [hmod55] - norm_num [UInt256.size, EVM.twoPow] at h hmhi ⊢ - omega - -theorem observationsSint56Value_mask (w : UInt256) : - observationsSint56Value (UInt256.land w observationsUint56Mask) = - observationsSint56Value w := by - unfold observationsSint56Value - have hmod : (UInt256.land w observationsUint56Mask).toNat % EVM.twoPow 56 = - w.toNat % EVM.twoPow 56 := by - rw [uland_toNat, observationsUint56Mask_toNat] - change Nat.land w.toNat (2 ^ 56 - 1) % EVM.twoPow 56 = - w.toNat % EVM.twoPow 56 - rw [nat_land_mask_eq_mod] - simp [EVM.twoPow] - rw [hmod] - -theorem observationsTickRawValue_wordOfInt (w : UInt256) : - EVM.wordOfInt (observationsSint56Value (UInt256.land w observationsUint56Mask)) = - UInt256.signextend ⟨6⟩ w := by - rw [observationsSint56Value_mask] - exact wordOfInt_sint56Value_eq_signextend_six w - -theorem observationsSint56Value_ge (w : UInt256) : - -(2 ^ 55 : Int) ≤ observationsSint56Value w := by - unfold observationsSint56Value - by_cases h : w.toNat % EVM.twoPow 56 < EVM.twoPow 55 - · rw [if_pos h] - exact le_trans (by norm_num : -(2 ^ 55 : Int) ≤ 0) (Int.natCast_nonneg _) - · rw [if_neg h] - have hmhi := Nat.mod_lt w.toNat (by norm_num [EVM.twoPow] : 0 < EVM.twoPow 56) - norm_num [EVM.twoPow] at h hmhi ⊢ - omega - -theorem observationsSint56Value_lt (w : UInt256) : - observationsSint56Value w < (2 ^ 55 : Int) := by - unfold observationsSint56Value - by_cases h : w.toNat % EVM.twoPow 56 < EVM.twoPow 55 - · rw [if_pos h] - norm_num [EVM.twoPow] at h ⊢ - omega - · rw [if_neg h] - have hmhi := Nat.mod_lt w.toNat (by norm_num [EVM.twoPow] : 0 < EVM.twoPow 56) - norm_num [EVM.twoPow] at h hmhi ⊢ - omega - -private theorem observationsWordOfIntNeg_toNat (i : Int) (hneg : i < 0) - (hle : i.natAbs < EVM.wordModulus) : - (EVM.wordOfInt i).toNat = UInt256.size - i.natAbs := by - have hdiffPos : i.natAbs ≠ 0 := by - intro h - have : i = 0 := by omega - omega - have hpos : 0 < i.natAbs := Nat.pos_of_ne_zero hdiffPos - unfold EVM.wordOfInt - rw [if_pos hneg] - rw [Nat.mod_eq_of_lt hle, if_neg hdiffPos] - change (UInt256.ofNat (EVM.wordModulus - i.natAbs)).toNat = UInt256.size - i.natAbs - rw [ulit_toNat'] - · rw [show EVM.wordModulus = UInt256.size by native_decide] - · rw [show EVM.wordModulus = UInt256.size by native_decide] - exact Nat.sub_lt (by native_decide : 0 < UInt256.size) hpos - -private theorem observationsSint56Value_wordOfInt (i : Int) - (hge : -(2 ^ 55) ≤ i) (hlt : i < 2 ^ 55) : - observationsSint56Value (EVM.wordOfInt i) = i := by - unfold observationsSint56Value - by_cases h0 : 0 ≤ i - · have hword : EVM.wordOfInt i = EVM.word i.toNat := wordOfInt_nonneg i h0 - rw [hword] - have hltNat : i.toNat < EVM.twoPow 55 := by - exact (Int.toNat_lt h0).2 (by simpa [EVM.twoPow] using hlt) - have hto : (EVM.word i.toNat).toNat = i.toNat := by - unfold EVM.word EVM.uintN UInt256.toNat - simp only - show i.toNat % EVM.twoPow 256 = i.toNat - rw [Nat.mod_eq_of_lt] - norm_num [EVM.twoPow, UInt256.size] at hltNat ⊢ - omega - rw [hto] - have hmod : i.toNat % EVM.twoPow 56 = i.toNat := by - apply Nat.mod_eq_of_lt - norm_num [EVM.twoPow] at hltNat ⊢ - omega - rw [hmod] - rw [if_pos] - · exact Int.toNat_of_nonneg h0 - · simpa [EVM.twoPow] using hltNat - · have hneg : i < 0 := by omega - have hrle : i.natAbs ≤ EVM.twoPow 55 := by - have habs : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - have : (i.natAbs : Int) ≤ (EVM.twoPow 55 : Int) := by - rw [habs] - norm_num [EVM.twoPow] at hge ⊢ - omega - omega - have hrpos : 0 < i.natAbs := by - by_contra hz - have : i.natAbs = 0 := by omega - have : i = 0 := by omega - omega - have hword := observationsWordOfIntNeg_toNat i hneg (by - exact lt_of_le_of_lt hrle (by native_decide : EVM.twoPow 55 < EVM.wordModulus)) - rw [hword] - let r := i.natAbs - have hrle' : r ≤ EVM.twoPow 55 := by simpa [r] using hrle - have hrle56 : r ≤ EVM.twoPow 56 := le_trans hrle' (by native_decide) - have hrpos' : 0 < r := by simpa [r] using hrpos - have hmodm : (UInt256.size - r) % EVM.twoPow 56 = EVM.twoPow 56 - r := by - have hEq : UInt256.size - r = - (UInt256.size - EVM.twoPow 56) + (EVM.twoPow 56 - r) := by - norm_num [UInt256.size, EVM.twoPow] at hrle56 ⊢ - omega - rw [hEq, Nat.add_mod] - have hdiv : (UInt256.size - EVM.twoPow 56) % EVM.twoPow 56 = 0 := by - native_decide - have hltSub : EVM.twoPow 56 - r < EVM.twoPow 56 := by omega - rw [hdiv, Nat.zero_add] - rw [Nat.mod_eq_of_lt hltSub] - rw [Nat.mod_eq_of_lt hltSub] - rw [hmodm] - rw [if_neg] - · have habs : (r : Int) = -i := by - dsimp [r] - exact Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [EVM.twoPow] at hrle' ⊢ - omega - · norm_num [EVM.twoPow] at hrle' hrpos' ⊢ - omega - -theorem signextend_six_wordOfInt_observations (i : Int) - (hge : -(2 ^ 55) ≤ i) (hlt : i < 2 ^ 55) : - UInt256.signextend ⟨6⟩ (EVM.wordOfInt i) = EVM.wordOfInt i := by - rw [← wordOfInt_sint56Value_eq_signextend_six (EVM.wordOfInt i)] - rw [observationsSint56Value_wordOfInt i hge hlt] - -theorem observationsSignextendSix_idempotent (w : UInt256) : - UInt256.signextend ⟨6⟩ (UInt256.signextend ⟨6⟩ w) = - UInt256.signextend ⟨6⟩ w := by - let i := observationsSint56Value w - have hword : EVM.wordOfInt i = UInt256.signextend ⟨6⟩ w := by - simpa [i] using wordOfInt_sint56Value_eq_signextend_six w - rw [← hword] - exact signextend_six_wordOfInt_observations i (observationsSint56Value_ge w) - (observationsSint56Value_lt w) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Observe.lean b/Benchmarks/UniswapV3Pool/Observe.lean deleted file mode 100644 index 1e89617e..00000000 --- a/Benchmarks/UniswapV3Pool/Observe.lean +++ /dev/null @@ -1,18 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolObserveBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 16 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Positions.lean b/Benchmarks/UniswapV3Pool/Positions.lean deleted file mode 100644 index 4a6277e4..00000000 --- a/Benchmarks/UniswapV3Pool/Positions.lean +++ /dev/null @@ -1,1915 +0,0 @@ -import Benchmarks.UniswapV3Pool.Uint128 -import Reasoning.MemCascade - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev positionsArgWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -abbrev positionsArgValue (I : ExecutionEnv) : Value := - .fixedBytes bytes32Width (EVM.Word.toBytesBE (positionsArgWord I)) - -abbrev positionsArgKey (I : ExecutionEnv) : KeyValue := - .fixedBytes bytes32Width (EVM.Word.toBytesBE (positionsArgWord I)) - -abbrev positionsStore (I : ExecutionEnv) : Store := - (∅ : Store).insert "arg0" (positionsArgValue I) - -abbrev positionsBaseSlot (I : ExecutionEnv) : UInt256 := - positionsBase (positionsArgKey I) - -abbrev positionsPackedSlot (I : ExecutionEnv) : UInt256 := - positionsBaseSlot I + ⟨3⟩ - -abbrev positionsShift : UInt256 := - UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ - -abbrev positionsLiquidityWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (solcSlotWord σ I (positionsBaseSlot I)) uint128Mask - -abbrev positionsFeeGrowthInside0Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (positionsBaseSlot I + ⟨1⟩) - -abbrev positionsFeeGrowthInside1Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (positionsBaseSlot I + ⟨2⟩) - -abbrev positionsPackedWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (positionsPackedSlot I) - -abbrev positionsTokensOwed0Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (positionsPackedWord σ I) uint128Mask - -abbrev positionsTokensOwed1Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.div (positionsPackedWord σ I) positionsShift) uint128Mask - -def positionsReturnValues (σ : AccountMap) (I : ExecutionEnv) : List Value := - [ .int (Int.ofNat (positionsLiquidityWord σ I).toNat), - .int (Int.ofNat (positionsFeeGrowthInside0Word σ I).toNat), - .int (Int.ofNat (positionsFeeGrowthInside1Word σ I).toNat), - .int (Int.ofNat (positionsTokensOwed0Word σ I).toNat), - .int (Int.ofNat (positionsTokensOwed1Word σ I).toNat) ] - -theorem positionsArgSlice_eq_toBytesBE {I : ExecutionEnv} (hsz36 : 36 ≤ I.calldata.size) : - (I.calldata.toList.drop 4).take 32 = EVM.Word.toBytesBE (positionsArgWord I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have hlen : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have hword := decode_word_at_eq I.calldata 4 (by omega : 4 + 32 ≤ I.calldata.size) - (by native_decide : 4 < 2 ^ 64) - calc - (I.calldata.toList.drop 4).take 32 = - EVM.Word.toBytesBE (ABI.bytesToWord ((I.calldata.toList.drop 4).take 32)) := by - exact (toBytesBE_bytesToWord_of_length hlen).symm - _ = EVM.Word.toBytesBE (positionsArgWord I) := by - rw [hword] - -theorem positionsBaseSlot_eq_solcMappingSlot (I : ExecutionEnv) : - positionsBaseSlot I = solcMappingSlot ⟨7⟩ (positionsArgWord I) := by - have hkey : - keyValueToWord (KeyValue.fixedBytes bytes32Width - (EVM.Word.toBytesBE (positionsArgWord I))) = positionsArgWord I := by - simpa [bytes32Width] using keyValueToWord_fixedBytes32 (positionsArgWord I) - unfold positionsBaseSlot positionsBase positionsArgKey mapSlot solcMappingSlot - rw [hkey] - -private theorem decodeCalldataWithMode_legacy_bytes32_ok {cd : ByteArray} {x : Solm.Ident} - (hsz36 : 36 ≤ cd.size) : - decodeCalldataWithMode DecodeMode.legacySolc05 [x] [abiBytes32] cd = - some ((∅ : Solm.Store).insert x - (.fixedBytes abiBytes32Width ((cd.toList.drop 4).take 32))) := by - unfold decodeCalldataWithMode decodeCalldata - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have hnot4 : ¬ cd.toList.length < 4 := by - rw [htlen] - omega - rw [if_neg hnot4] - have hnotDyn : ¬ ([abiBytes32].any isDynamicABIType = true ∧ 2 ^ 255 ≤ cd.toList.length) := by - simp [abiBytes32, isDynamicABIType] - rw [if_neg hnotDyn] - have hread : readBytes? (cd.toList.drop 4) 0 32 = - some ((cd.toList.drop 4).take 32) := by - unfold readBytes? - have hlen : (((cd.toList.drop 4).drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, List.length_drop, htlen] - omega - rw [if_pos hlen, List.drop_zero] - have hblen : ((cd.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have htake : List.take 32 ((cd.toList.drop 4).take 32) = (cd.toList.drop 4).take 32 := - List.take_of_length_le (by rw [hblen]) - have hnotArgShort : ¬ cd.toList.length - 4 < 32 := by - rw [htlen] - omega - simp [decodeCalldata.decodeArgs, decodeCalldata.insertValues, abiBytes32, - ABI.decodeABIValues?, ABI.decodeABIValue?, isDynamicABIType, staticABIEncodedSize?, - abiTupleHeadSize?, hread, abiBytes32Width, htake, hnotArgShort] - -private theorem decodeCalldataWithMode_legacy_bytes32_none_short {cd : ByteArray} - {x : Solm.Ident} (hshort : cd.size < 36) : - decodeCalldataWithMode DecodeMode.legacySolc05 [x] [abiBytes32] cd = none := by - unfold decodeCalldataWithMode decodeCalldata - have htlen : cd.toList.length = cd.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have hnotDyn : ¬ ([abiBytes32].any isDynamicABIType = true ∧ 2 ^ 255 ≤ cd.toList.length) := by - simp [abiBytes32, isDynamicABIType] - by_cases hsz4 : cd.size < 4 - · rw [if_pos (by rw [htlen]; omega : cd.toList.length < 4)] - · rw [if_neg (by rw [htlen]; omega : ¬ cd.toList.length < 4)] - rw [if_neg hnotDyn] - have hread : readBytes? (cd.toList.drop 4) 0 32 = none := by - unfold readBytes? - have hlen : ¬ (((cd.toList.drop 4).drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, List.length_drop, htlen] - omega - rw [if_neg hlen] - simp [decodeCalldata.decodeArgs, abiBytes32, ABI.decodeABIValues?, ABI.decodeABIValue?, - isDynamicABIType, staticABIEncodedSize?, abiTupleHeadSize?, hread] - -theorem uniswapV3PoolPositionsDecodeOk {v : PoolImmutables} {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - (positionsTransition.params.map Param.name) - (transitionSignature positionsTransition).paramTypes I.calldata = - some (positionsStore I) := by - have hdecode := decodeCalldataWithMode_legacy_bytes32_ok - (cd := I.calldata) (x := "arg0") hsz36 - have hslice := positionsArgSlice_eq_toBytesBE (I := I) hsz36 - simpa [config, positionsTransition, transitionSignature, positionsStore, positionsArgValue, - bytes32, bytes32Width, abiBytes32, abiBytes32Width, hslice] using hdecode - -theorem uniswapV3PoolPositionsDecodeShort {v : PoolImmutables} {I : ExecutionEnv} - (hshort : I.calldata.size < 36) : - decodeCalldataWithMode (config v).abiDecodeMode - (positionsTransition.params.map Param.name) - (transitionSignature positionsTransition).paramTypes I.calldata = none := by - simpa [config, positionsTransition, transitionSignature, bytes32, bytes32Width, abiBytes32, - abiBytes32Width] using - decodeCalldataWithMode_legacy_bytes32_none_short (cd := I.calldata) (x := "arg0") hshort - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolDispatch_positions {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 11 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some positionsTransition := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, factoryTransition v, - feeTransition v, feegrowthglobal0X128Transition, feegrowthglobal1X128Transition, - flashTransition v, increaseobservationcardinalitynextTransition v, initializeTransition, - liquidityTransition, maxliquiditypertickTransition v, mintTransition v, observationsTransition, - observeTransition v]) - (post := [protocolfeesTransition, setfeeprotocolTransition v, slot0Transition, - snapshotcumulativesinsideTransition v, swapTransition v, tickbitmapTransition, - tickspacingTransition v, ticksTransition, token0Transition v, token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 11) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 11) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 11) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 11) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 11) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 11) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 11) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 11) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 5) (j := 11) - (by native_decide) hsel - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 25) (j := 11) - (by native_decide) hsel - · rw [selectorOf, liquiditySelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 2) (j := 11) - (by native_decide) hsel - · rw [selectorOf, maxLiquidityPerTickSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 13) (j := 11) - (by native_decide) hsel - · rw [selectorOf, mintSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 7) (j := 11) - (by native_decide) hsel - · rw [selectorOf, observationsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 4) (j := 11) - (by native_decide) hsel - · rw [selectorOf, observeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 16) (j := 11) - (by native_decide) hsel - · rw [selectorOf, positionsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using hsel - -private theorem uniswapV3PoolPatchPreservesJumpDest8093 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨8093⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched8093 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨8093⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest8093 - -theorem uniswapV3PoolPositionsReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 11 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1357⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 11 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0x51 0x4e 0xa4 0xbf - (uniswapV3PoolSelNat 11) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h239 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨239⟩) hpatch h32 hgt32 - have hgt239 : UInt256.gt (armSelNat code ⟨239⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h250 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨250⟩) hpatch h239 hgt239 - have hgt250 : UInt256.gt (armSelNat code ⟨250⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h261 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨261⟩) hpatch h250 hgt250 - have hmiss9 : (uniswapV3PoolSelBytes 9 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h272 := uniswapV3PoolSelectorArmMissToOf (i := 9) (next := ⟨272⟩) - hpatch hsz hmiss9 h261 - have hmiss10 : (uniswapV3PoolSelBytes 10 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h283 := uniswapV3PoolSelectorArmMissToOf (i := 10) (next := ⟨283⟩) - hpatch hsz hmiss10 h272 - have h1357 := uniswapV3PoolSelectorArmHitTo (i := 11) (target := ⟨1357⟩) - hpatch hsz hsel h283 - exact ⟨_, _, h1357⟩ - -private theorem uniswapV3PoolPositionsDecodedReachRoutine {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {de ret : UInt256} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨1379⟩ (de :: ⟨4⟩ :: ret :: R) mem aw rdata acc k C) - (hov : R.length + 3 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8093⟩ (positionsArgWord ee :: ret :: R) - mem aw rdata acc k' C' := by - have rd1380 : RD code ee g s0 ⟨1380⟩ (de :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1) (C + 1) := by - simpa using h.jumpdest - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1381 : RD code ee g s0 ⟨1381⟩ (⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1) (C + 1 + 2) := by - simpa using rd1380.pop - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1382 : RD code ee g s0 ⟨1382⟩ (positionsArgWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1) (C + 1 + 2 + 3) := by - simpa [positionsArgWord, calldataWord, show (⟨4⟩ : UInt256).toNat = 4 from by decide] - using (rd1381.calldataload - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov)) - have rd1385 : RD code ee g s0 ⟨1385⟩ (⟨8093⟩ :: positionsArgWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3) := by - simpa using rd1382.push2 ⟨8093⟩ - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - exact ⟨_, _, rd1385.jump - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (uniswapV3PoolJumpDestPatched8093 hpatch) - (by evm_ov)⟩ - -set_option maxHeartbeats 3000000 in -private theorem uniswapV3PoolPositionsExternalLenOk {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hreach : ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1357⟩ - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1379⟩ - (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩ :: ⟨4⟩ :: ⟨1386⟩ :: - [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact RD.solcExternalStaticArgsLenOk (need := ⟨32⟩) - (entry := ⟨1357⟩) (ret := ⟨1386⟩) (decoded := ⟨1379⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (solcDecodeLenCheckOkUnsigned (by simpa using hsz36) hsize) - -theorem uniswapV3PoolPositionsEvmDecodeShort {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 11 == I.calldata.extract 0 4) = true) - (hshort : I.calldata.size < 36) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - have hreach := uniswapV3PoolPositionsReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - have hlt : - UInt256.lt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩ := by - apply ult_one - rw [usub_ofNat_word_toNat (by - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega) hsize] - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide] - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega - exact RD.solcExternalStaticArgsShortReverts (need := ⟨32⟩) - (entry := ⟨1357⟩) (ret := ⟨1386⟩) (decoded := ⟨1379⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - hlt - -private theorem uniswapV3PoolPositionsRoutinePatchDisjoint1 {v : PoolImmutables} - {pc : UInt256} (hlo : 8093 ≤ pc.toNat) (hhi : pc.toNat + 1 ≤ 8174) : - ∀ p ∈ patches v, pc.toNat + 1 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolPositionsRoutinePatchDisjoint2 {v : PoolImmutables} - {pc : UInt256} (hlo : 8093 ≤ pc.toNat) (hhi : pc.toNat + 2 ≤ 8174) : - ∀ p ∈ patches v, pc.toNat + 2 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolPositionsDecodePatchedPush1 {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 2 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 2 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x60) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1)) = n) : - decode code pc = some (.Push .PUSH1, some (n, 1)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + 1) = - uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1) := by - unfold ByteArray.extract' - have hguard : - (decide (pc.toNat.succ < 2 ^ 64) && decide (pc.toNat.succ + 1 < 2 ^ 64)) = - true := by - rw [Bool.and_eq_true] - constructor <;> rw [decide_eq_true_eq] <;> omega - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq (start := pc.toNat.succ) (stop := pc.toNat.succ + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl hbefore - · exact Or.inr (by omega)) - hpatch - have hgetSome : code.get? pc.toNat = some 0x60 := by - rw [hget, hgetTemplate] - have hparse : (some (0x60 : UInt8) >>= parseInstr) = some (.Push .PUSH1) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH1, - some (uInt256OfByteArray (code.extract' pc.toNat.succ (pc.toNat.succ + 1)), 1)) = - some (Operation.Push Operation.POp.PUSH1, some (n, 1)) - rw [hextract, hval] - -theorem uniswapV3PoolPositionsRoutine {v : PoolImmutables} {code : ByteArray} - {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {ret : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8093⟩ (positionsArgWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 9 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret - (positionsTokensOwed1Word σ ee :: positionsTokensOwed0Word σ ee :: - positionsFeeGrowthInside1Word σ ee :: positionsFeeGrowthInside0Word σ ee :: - positionsLiquidityWord σ ee :: ret :: R) - (solcMappingHashMem ⟨7⟩ (positionsArgWord ee)) (UInt256.ofNat 3) rdata (cA, σ) - k' C' := by - have hd8093 : decode code ⟨8093⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8093⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8094 : decode code ⟨8094⟩ = some (.Push .PUSH1, some (⟨7⟩, 1)) := by - exact uniswapV3PoolPositionsDecodePatchedPush1 (pc := ⟨8094⟩) (n := ⟨7⟩) - hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8096 : decode code ⟨8096⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - exact uniswapV3PoolPositionsDecodePatchedPush1 (pc := ⟨8096⟩) (n := ⟨32⟩) - hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8098 : decode code ⟨8098⟩ = some (.MSTORE, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8098⟩) (byte := 0x52) - (op := .MSTORE) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8099 : decode code ⟨8099⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - exact uniswapV3PoolPositionsDecodePatchedPush1 (pc := ⟨8099⟩) (n := ⟨0⟩) - hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8101 : decode code ⟨8101⟩ = some (.SWAP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8101⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8102 : decode code ⟨8102⟩ = some (.DUP2, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8102⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8103 : decode code ⟨8103⟩ = some (.MSTORE, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8103⟩) (byte := 0x52) - (op := .MSTORE) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8104 : decode code ⟨8104⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - exact uniswapV3PoolPositionsDecodePatchedPush1 (pc := ⟨8104⟩) (n := ⟨64⟩) - hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8106 : decode code ⟨8106⟩ = some (.SWAP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8106⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8107 : decode code ⟨8107⟩ = some (.KECCAK256, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8107⟩) (byte := 0x20) - (op := .KECCAK256) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8108 : decode code ⟨8108⟩ = some (.DUP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8108⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8109 : decode code ⟨8109⟩ = some (.SLOAD, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8109⟩) (byte := 0x54) - (op := .SLOAD) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8110 : decode code ⟨8110⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - exact uniswapV3PoolPositionsDecodePatchedPush1 (pc := ⟨8110⟩) (n := ⟨1⟩) - hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8112 : decode code ⟨8112⟩ = some (.DUP3, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8112⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8113 : decode code ⟨8113⟩ = some (.ADD, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8113⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8114 : decode code ⟨8114⟩ = some (.SLOAD, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8114⟩) (byte := 0x54) - (op := .SLOAD) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8115 : decode code ⟨8115⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - exact uniswapV3PoolPositionsDecodePatchedPush1 (pc := ⟨8115⟩) (n := ⟨2⟩) - hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8117 : decode code ⟨8117⟩ = some (.DUP4, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8117⟩) (byte := 0x83) - (op := .DUP4) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8118 : decode code ⟨8118⟩ = some (.ADD, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8118⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8119 : decode code ⟨8119⟩ = some (.SLOAD, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8119⟩) (byte := 0x54) - (op := .SLOAD) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8120 : decode code ⟨8120⟩ = some (.Push .PUSH1, some (⟨3⟩, 1)) := by - exact uniswapV3PoolPositionsDecodePatchedPush1 (pc := ⟨8120⟩) (n := ⟨3⟩) - hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8122 : decode code ⟨8122⟩ = some (.SWAP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8122⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8123 : decode code ⟨8123⟩ = some (.SWAP4, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8123⟩) (byte := 0x93) - (op := .SWAP4) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8124 : decode code ⟨8124⟩ = some (.ADD, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8124⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8125 : decode code ⟨8125⟩ = some (.SLOAD, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8125⟩) (byte := 0x54) - (op := .SLOAD) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8126 : decode code ⟨8126⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - exact uniswapV3PoolPositionsDecodePatchedPush1 (pc := ⟨8126⟩) (n := ⟨1⟩) - hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8128 : decode code ⟨8128⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - exact uniswapV3PoolPositionsDecodePatchedPush1 (pc := ⟨8128⟩) (n := ⟨1⟩) - hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8130 : decode code ⟨8130⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - exact uniswapV3PoolPositionsDecodePatchedPush1 (pc := ⟨8130⟩) (n := ⟨128⟩) - hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8132 : decode code ⟨8132⟩ = some (.SHL, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8132⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8133 : decode code ⟨8133⟩ = some (.SUB, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8133⟩) (byte := 0x03) - (op := .SUB) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8134 : decode code ⟨8134⟩ = some (.SWAP3, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8134⟩) (byte := 0x92) - (op := .SWAP3) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8135 : decode code ⟨8135⟩ = some (.DUP4, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8135⟩) (byte := 0x83) - (op := .DUP4) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8136 : decode code ⟨8136⟩ = some (.AND, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8136⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8137 : decode code ⟨8137⟩ = some (.SWAP4, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8137⟩) (byte := 0x93) - (op := .SWAP4) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8138 : decode code ⟨8138⟩ = some (.SWAP2, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8138⟩) (byte := 0x91) - (op := .SWAP2) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8139 : decode code ⟨8139⟩ = some (.SWAP3, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8139⟩) (byte := 0x92) - (op := .SWAP3) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8140 : decode code ⟨8140⟩ = some (.DUP2, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8140⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8141 : decode code ⟨8141⟩ = some (.DUP2, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8141⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8142 : decode code ⟨8142⟩ = some (.AND, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8142⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8143 : decode code ⟨8143⟩ = some (.SWAP2, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8143⟩) (byte := 0x91) - (op := .SWAP2) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8144 : decode code ⟨8144⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - exact uniswapV3PoolPositionsDecodePatchedPush1 (pc := ⟨8144⟩) (n := ⟨1⟩) - hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8146 : decode code ⟨8146⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - exact uniswapV3PoolPositionsDecodePatchedPush1 (pc := ⟨8146⟩) (n := ⟨128⟩) - hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8148 : decode code ⟨8148⟩ = some (.SHL, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8148⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8149 : decode code ⟨8149⟩ = some (.SWAP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8149⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8150 : decode code ⟨8150⟩ = some (.DIV, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8150⟩) (byte := 0x04) - (op := .DIV) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8151 : decode code ⟨8151⟩ = some (.AND, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8151⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8152 : decode code ⟨8152⟩ = some (.DUP6, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8152⟩) (byte := 0x85) - (op := .DUP6) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8153 : decode code ⟨8153⟩ = some (.JUMP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8153⟩) (byte := 0x56) - (op := .JUMP) hpatch (by native_decide) - (uniswapV3PoolPositionsRoutinePatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have rd8094 := h.jumpdest hd8093 (by simp only [List.length_cons]; omega) - have rd8096 := rd8094.push1 ⟨7⟩ hd8094 (by evm_ov) - have rd8098 := rd8096.push1 ⟨32⟩ hd8096 (by evm_ov) - have rd8099 := rd8098.mstore 0 (solcMappingBaseSlotMem ⟨7⟩) - (UInt256.ofNat 3) hd8098 mem_cost (by rfl) (by native_decide) (by evm_ov) - have rd8101 := rd8099.push1 ⟨0⟩ hd8099 (by evm_ov) - have rd8102 := rd8101.swap1 hd8101 (by evm_ov) - have rd8103 := rd8102.dup2 hd8102 (by evm_ov) - have rd8104 := rd8103.mstore 0 (solcMappingHashMem ⟨7⟩ (positionsArgWord ee)) - (UInt256.ofNat 3) hd8103 mem_cost (by rfl) (by native_decide) (by evm_ov) - have rd8106 := rd8104.push1 ⟨64⟩ hd8104 (by evm_ov) - have rd8107 := rd8106.swap1 hd8106 (by evm_ov) - have hslot := solcMappingKeccakSlot ⟨7⟩ (positionsArgWord ee) - have rd8108 := rd8107.keccak256 0 (solcMappingSlot ⟨7⟩ (positionsArgWord ee)) - (UInt256.ofNat 3) hd8107 mem_cost - (by simpa [show (⟨0⟩ : UInt256).toNat = 0 from by decide, - show (⟨64⟩ : UInt256).toNat = 64 from by decide] using hslot) - (by native_decide) (by evm_ov) - have rd8109 := rd8108.dup1 hd8108 (by evm_ov) - obtain ⟨_, _, rd8110⟩ := rd8109.sload hd8109 (by evm_ov) - have rd8114 := evm_run rd8110 with [ - raw push1 ⟨1⟩ hd8110 (by evm_ov), - raw dup3 hd8112 (by evm_ov), - raw add hd8113 (by evm_ov)] - obtain ⟨_, _, rd8115⟩ := rd8114.sload hd8114 (by evm_ov) - have rd8119 := evm_run rd8115 with [ - raw push1 ⟨2⟩ hd8115 (by evm_ov), - raw dup4 hd8117 (by evm_ov), - raw add hd8118 (by evm_ov)] - obtain ⟨_, _, rd8120⟩ := rd8119.sload hd8119 (by evm_ov) - have rd8125 := evm_run rd8120 with [ - raw push1 ⟨3⟩ hd8120 (by evm_ov), - raw swap1 hd8122 (by evm_ov), - raw swap4 hd8123 (by evm_ov), - raw add hd8124 (by evm_ov)] - obtain ⟨_, _, rd8126⟩ := rd8125.sload hd8125 (by evm_ov) - have rd8153 := evm_run rd8126 with [ - raw push1 ⟨1⟩ hd8126 (by evm_ov), - raw push1 ⟨1⟩ hd8128 (by evm_ov), - raw push1 ⟨128⟩ hd8130 (by evm_ov), - raw shl hd8132 (by evm_ov), - raw sub hd8133 (by evm_ov), - raw swap3 hd8134 (by evm_ov), - raw dup4 hd8135 (by evm_ov), - raw and hd8136 (by evm_ov), - raw swap4 hd8137 (by evm_ov), - raw swap2 hd8138 (by evm_ov), - raw swap3 hd8139 (by evm_ov), - raw dup2 hd8140 (by evm_ov), - raw dup2 hd8141 (by evm_ov), - raw and hd8142 (by evm_ov), - raw swap2 hd8143 (by evm_ov), - raw push1 ⟨1⟩ hd8144 (by evm_ov), - raw push1 ⟨128⟩ hd8146 (by evm_ov), - raw shl hd8148 (by evm_ov), - raw swap1 hd8149 (by evm_ov), - raw div hd8150 (by evm_ov), - raw and hd8151 (by evm_ov), - raw dup6 hd8152 (by evm_ov)] - have rdRet := rd8153.jump hd8153 hret (by evm_ov) - have hmask : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨1⟩ = uint128Mask := by - native_decide - have hliqComm : - UInt256.land uint128Mask - (σ.find? ee.codeOwner |>.option ⟨0⟩ - (fun ac => - ac.storage.findD (solcMappingSlot ⟨7⟩ (positionsArgWord ee)) ⟨0⟩)) = - UInt256.land - (σ.find? ee.codeOwner |>.option ⟨0⟩ - (fun ac => - ac.storage.findD (solcMappingSlot ⟨7⟩ (positionsArgWord ee)) ⟨0⟩)) - uint128Mask := by - rw [u256_land_comm] - have htow0Comm : - UInt256.land uint128Mask - (σ.find? ee.codeOwner |>.option ⟨0⟩ - (fun ac => - ac.storage.findD (solcMappingSlot ⟨7⟩ (positionsArgWord ee) + ⟨3⟩) ⟨0⟩)) = - UInt256.land - (σ.find? ee.codeOwner |>.option ⟨0⟩ - (fun ac => - ac.storage.findD (solcMappingSlot ⟨7⟩ (positionsArgWord ee) + ⟨3⟩) ⟨0⟩)) - uint128Mask := by - rw [u256_land_comm] - exact ⟨_, _, by - rw [hmask] at rdRet - simpa [positionsTokensOwed1Word, positionsTokensOwed0Word, - positionsFeeGrowthInside1Word, positionsFeeGrowthInside0Word, positionsLiquidityWord, - positionsPackedWord, positionsPackedSlot, positionsBaseSlot_eq_solcMappingSlot ee, - positionsShift, solcSlotWord, hliqComm, htow0Comm] using rdRet⟩ - -private theorem uniswapV3PoolPositionsDecodedToLoaded {v : PoolImmutables} - {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} {de : UInt256} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (rdDecoded : RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1379⟩ - (de :: ⟨4⟩ :: ⟨1386⟩ :: [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1386⟩ - (positionsTokensOwed1Word σ I :: positionsTokensOwed0Word σ I :: - positionsFeeGrowthInside1Word σ I :: positionsFeeGrowthInside0Word σ I :: - positionsLiquidityWord σ I :: ⟨1386⟩ :: [solcSelectorWord I]) - (solcMappingHashMem ⟨7⟩ (positionsArgWord I)) (UInt256.ofNat 3) - ByteArray.empty (cA, σ) k' C' := by - obtain ⟨_, _, rdRoutine⟩ := - uniswapV3PoolPositionsDecodedReachRoutine hpatch rdDecoded - (by simp only [List.length_singleton]; omega) - exact uniswapV3PoolPositionsRoutine hpatch rdRoutine - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (by simp only [List.length_singleton]; omega) - -noncomputable def positionsReturnMem1 (liq : UInt256) : ByteArray := - writeCascade solcFreePtrMem [(128, liq)] - -noncomputable def positionsReturnMem2 (liq fee0 : UInt256) : ByteArray := - writeCascade solcFreePtrMem [(128, liq), (160, fee0)] - -noncomputable def positionsReturnMem3 (liq fee0 fee1 : UInt256) : ByteArray := - writeCascade solcFreePtrMem [(128, liq), (160, fee0), (192, fee1)] - -noncomputable def positionsReturnMem4 (liq fee0 fee1 owed0 : UInt256) : ByteArray := - writeCascade solcFreePtrMem [(128, liq), (160, fee0), (192, fee1), (224, owed0)] - -noncomputable def positionsReturnMem - (liq fee0 fee1 owed0 owed1 : UInt256) : ByteArray := - writeCascade solcFreePtrMem - [(128, liq), (160, fee0), (192, fee1), (224, owed0), (256, owed1)] - -theorem positionsReturnMem1_eq (liq : UInt256) : - positionsReturnMem1 liq = writeWord solcFreePtrMem 128 liq := by - rfl - -theorem positionsReturnMem2_eq (liq fee0 : UInt256) : - positionsReturnMem2 liq fee0 = writeWord (positionsReturnMem1 liq) 160 fee0 := by - rfl - -theorem positionsReturnMem3_eq (liq fee0 fee1 : UInt256) : - positionsReturnMem3 liq fee0 fee1 = - writeWord (positionsReturnMem2 liq fee0) 192 fee1 := by - rfl - -theorem positionsReturnMem4_eq (liq fee0 fee1 owed0 : UInt256) : - positionsReturnMem4 liq fee0 fee1 owed0 = - writeWord (positionsReturnMem3 liq fee0 fee1) 224 owed0 := by - rfl - -theorem positionsReturnMem_eq (liq fee0 fee1 owed0 owed1 : UInt256) : - positionsReturnMem liq fee0 fee1 owed0 owed1 = - writeWord (positionsReturnMem4 liq fee0 fee1 owed0) 256 owed1 := by - rfl - -theorem positionsReturnMem1_size (liq : UInt256) : - (positionsReturnMem1 liq).size = 160 := by - unfold positionsReturnMem1 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem positionsReturnMem2_size (liq fee0 : UInt256) : - (positionsReturnMem2 liq fee0).size = 192 := by - unfold positionsReturnMem2 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem positionsReturnMem3_size (liq fee0 fee1 : UInt256) : - (positionsReturnMem3 liq fee0 fee1).size = 224 := by - unfold positionsReturnMem3 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem positionsReturnMem4_size (liq fee0 fee1 owed0 : UInt256) : - (positionsReturnMem4 liq fee0 fee1 owed0).size = 256 := by - unfold positionsReturnMem4 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem positionsReturnMem_size (liq fee0 fee1 owed0 owed1 : UInt256) : - (positionsReturnMem liq fee0 fee1 owed0 owed1).size = 288 := by - unfold positionsReturnMem - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem positionsReturnMem_read64 (liq fee0 fee1 owed0 owed1 : UInt256) : - (positionsReturnMem liq fee0 fee1 owed0 owed1).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - unfold positionsReturnMem - rw [writeCascade_read_preserved_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WindowDisjointFromWrites] - all_goals native_decide)] - exact solcFreePtrMem_read64 - -theorem positionsReturnMem_mload64 (liq fee0 fee1 owed0 owed1 : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (positionsReturnMem liq fee0 fee1 owed0 owed1).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 9 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((positionsReturnMem liq fee0 fee1 owed0 owed1).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - ⟨128⟩ := - mloadFreePtrValue (by rw [positionsReturnMem_size]; decide) (by decide) - (positionsReturnMem_read64 liq fee0 fee1 owed0 owed1) - -theorem positionsReturnMem_read128 (liq fee0 fee1 owed0 owed1 : UInt256) : - (positionsReturnMem liq fee0 fee1 owed0 owed1).readWithPadding 128 32 = - UInt256.toByteArray liq := by - unfold positionsReturnMem - exact writeCascade_read_word_of_head_of_base solcFreePtrMem (base := 96) (off := 128) - liq [(160, fee0), (192, fee1), (224, owed0), (256, owed1)] - solcFreePtrMem_size (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem positionsReturnMem_read160 (liq fee0 fee1 owed0 owed1 : UInt256) : - (positionsReturnMem liq fee0 fee1 owed0 owed1).readWithPadding 160 32 = - UInt256.toByteArray fee0 := by - unfold positionsReturnMem - change (writeCascade (positionsReturnMem1 liq) - [(160, fee0), (192, fee1), (224, owed0), (256, owed1)]).readWithPadding 160 32 = - UInt256.toByteArray fee0 - exact writeCascade_read_word_of_head_of_base (positionsReturnMem1 liq) (base := 160) - (off := 160) fee0 [(192, fee1), (224, owed0), (256, owed1)] - (positionsReturnMem1_size liq) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem positionsReturnMem_read192 (liq fee0 fee1 owed0 owed1 : UInt256) : - (positionsReturnMem liq fee0 fee1 owed0 owed1).readWithPadding 192 32 = - UInt256.toByteArray fee1 := by - unfold positionsReturnMem - change (writeCascade (positionsReturnMem2 liq fee0) - [(192, fee1), (224, owed0), (256, owed1)]).readWithPadding 192 32 = - UInt256.toByteArray fee1 - exact writeCascade_read_word_of_head_of_base (positionsReturnMem2 liq fee0) (base := 192) - (off := 192) fee1 [(224, owed0), (256, owed1)] - (positionsReturnMem2_size liq fee0) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem positionsReturnMem_read224 (liq fee0 fee1 owed0 owed1 : UInt256) : - (positionsReturnMem liq fee0 fee1 owed0 owed1).readWithPadding 224 32 = - UInt256.toByteArray owed0 := by - unfold positionsReturnMem - change (writeCascade (positionsReturnMem3 liq fee0 fee1) - [(224, owed0), (256, owed1)]).readWithPadding 224 32 = - UInt256.toByteArray owed0 - exact writeCascade_read_word_of_head_of_base (positionsReturnMem3 liq fee0 fee1) - (base := 224) (off := 224) owed0 [(256, owed1)] - (positionsReturnMem3_size liq fee0 fee1) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem positionsReturnMem_read256 (liq fee0 fee1 owed0 owed1 : UInt256) : - (positionsReturnMem liq fee0 fee1 owed0 owed1).readWithPadding 256 32 = - UInt256.toByteArray owed1 := by - unfold positionsReturnMem - change (writeCascade (positionsReturnMem4 liq fee0 fee1 owed0) - [(256, owed1)]).readWithPadding 256 32 = - UInt256.toByteArray owed1 - exact writeCascade_read_word_of_head_of_base (positionsReturnMem4 liq fee0 fee1 owed0) - (base := 256) (off := 256) owed1 [] - (positionsReturnMem4_size liq fee0 fee1 owed0) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem positionsReturnMem_read128_160 (liq fee0 fee1 owed0 owed1 : UInt256) : - (positionsReturnMem liq fee0 fee1 owed0 owed1).readWithPadding 128 160 = - UInt256.toByteArray liq ++ UInt256.toByteArray fee0 ++ UInt256.toByteArray fee1 ++ - UInt256.toByteArray owed0 ++ UInt256.toByteArray owed1 := by - let mem := positionsReturnMem liq fee0 fee1 owed0 owed1 - have hsize : mem.size = 288 := by - simpa [mem] using positionsReturnMem_size liq fee0 fee1 owed0 owed1 - have h128 : mem.readWithPadding 128 32 = UInt256.toByteArray liq := by - simpa [mem] using positionsReturnMem_read128 liq fee0 fee1 owed0 owed1 - have h160 : mem.readWithPadding 160 32 = UInt256.toByteArray fee0 := by - simpa [mem] using positionsReturnMem_read160 liq fee0 fee1 owed0 owed1 - have h192 : mem.readWithPadding 192 32 = UInt256.toByteArray fee1 := by - simpa [mem] using positionsReturnMem_read192 liq fee0 fee1 owed0 owed1 - have h224 : mem.readWithPadding 224 32 = UInt256.toByteArray owed0 := by - simpa [mem] using positionsReturnMem_read224 liq fee0 fee1 owed0 owed1 - have h256 : mem.readWithPadding 256 32 = UInt256.toByteArray owed1 := by - simpa [mem] using positionsReturnMem_read256 liq fee0 fee1 owed0 owed1 - change mem.readWithPadding 128 160 = _ - rw [byteArray_readWithPadding_split mem 128 32 128 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h128] - rw [byteArray_readWithPadding_split mem 160 32 96 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h160] - rw [byteArray_readWithPadding_split mem 192 32 64 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h192] - rw [byteArray_readWithPadding_split mem 224 32 32 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h224, h256] - simp only [ByteArray.append_assoc] - -noncomputable def positionsScratchReturnMem1 (scratch : ByteArray) (liq : UInt256) : - ByteArray := - writeCascade scratch [(128, liq)] - -noncomputable def positionsScratchReturnMem2 (scratch : ByteArray) (liq fee0 : UInt256) : - ByteArray := - writeCascade scratch [(128, liq), (160, fee0)] - -noncomputable def positionsScratchReturnMem3 - (scratch : ByteArray) (liq fee0 fee1 : UInt256) : ByteArray := - writeCascade scratch [(128, liq), (160, fee0), (192, fee1)] - -noncomputable def positionsScratchReturnMem4 - (scratch : ByteArray) (liq fee0 fee1 owed0 : UInt256) : ByteArray := - writeCascade scratch [(128, liq), (160, fee0), (192, fee1), (224, owed0)] - -noncomputable def positionsScratchReturnMem - (scratch : ByteArray) (liq fee0 fee1 owed0 owed1 : UInt256) : ByteArray := - writeCascade scratch - [(128, liq), (160, fee0), (192, fee1), (224, owed0), (256, owed1)] - -theorem positionsScratchReturnMem1_eq (scratch : ByteArray) (liq : UInt256) : - positionsScratchReturnMem1 scratch liq = writeWord scratch 128 liq := by - rfl - -theorem positionsScratchReturnMem2_eq (scratch : ByteArray) (liq fee0 : UInt256) : - positionsScratchReturnMem2 scratch liq fee0 = - writeWord (positionsScratchReturnMem1 scratch liq) 160 fee0 := by - rfl - -theorem positionsScratchReturnMem3_eq - (scratch : ByteArray) (liq fee0 fee1 : UInt256) : - positionsScratchReturnMem3 scratch liq fee0 fee1 = - writeWord (positionsScratchReturnMem2 scratch liq fee0) 192 fee1 := by - rfl - -theorem positionsScratchReturnMem4_eq - (scratch : ByteArray) (liq fee0 fee1 owed0 : UInt256) : - positionsScratchReturnMem4 scratch liq fee0 fee1 owed0 = - writeWord (positionsScratchReturnMem3 scratch liq fee0 fee1) 224 owed0 := by - rfl - -theorem positionsScratchReturnMem_eq - (scratch : ByteArray) (liq fee0 fee1 owed0 owed1 : UInt256) : - positionsScratchReturnMem scratch liq fee0 fee1 owed0 owed1 = - writeWord (positionsScratchReturnMem4 scratch liq fee0 fee1 owed0) 256 owed1 := by - rfl - -theorem positionsScratchReturnMem1_size {scratch : ByteArray} (liq : UInt256) - (hscratch : scratch.size = 96) : - (positionsScratchReturnMem1 scratch liq).size = 160 := by - unfold positionsScratchReturnMem1 - exact writeCascade_size_of_base scratch _ hscratch - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem positionsScratchReturnMem2_size {scratch : ByteArray} (liq fee0 : UInt256) - (hscratch : scratch.size = 96) : - (positionsScratchReturnMem2 scratch liq fee0).size = 192 := by - unfold positionsScratchReturnMem2 - exact writeCascade_size_of_base scratch _ hscratch - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem positionsScratchReturnMem3_size {scratch : ByteArray} (liq fee0 fee1 : UInt256) - (hscratch : scratch.size = 96) : - (positionsScratchReturnMem3 scratch liq fee0 fee1).size = 224 := by - unfold positionsScratchReturnMem3 - exact writeCascade_size_of_base scratch _ hscratch - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem positionsScratchReturnMem4_size {scratch : ByteArray} (liq fee0 fee1 owed0 : UInt256) - (hscratch : scratch.size = 96) : - (positionsScratchReturnMem4 scratch liq fee0 fee1 owed0).size = 256 := by - unfold positionsScratchReturnMem4 - exact writeCascade_size_of_base scratch _ hscratch - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem positionsScratchReturnMem_size {scratch : ByteArray} - (liq fee0 fee1 owed0 owed1 : UInt256) (hscratch : scratch.size = 96) : - (positionsScratchReturnMem scratch liq fee0 fee1 owed0 owed1).size = 288 := by - unfold positionsScratchReturnMem - exact writeCascade_size_of_base scratch _ hscratch - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem positionsScratchReturnMem_read64 {scratch : ByteArray} - (liq fee0 fee1 owed0 owed1 : UInt256) (hscratch : scratch.size = 96) - (hread64 : scratch.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : - (positionsScratchReturnMem scratch liq fee0 fee1 owed0 owed1).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - unfold positionsScratchReturnMem - rw [writeCascade_read_preserved_of_base scratch _ hscratch - (by - norm_num [WindowDisjointFromWrites] - all_goals native_decide)] - exact hread64 - -theorem positionsScratchReturnMem_mload64 {scratch : ByteArray} - (liq fee0 fee1 owed0 owed1 : UInt256) (hscratch : scratch.size = 96) - (hread64 : scratch.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : - (if (⟨64⟩ : UInt256).toNat ≥ - (positionsScratchReturnMem scratch liq fee0 fee1 owed0 owed1).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 9 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((positionsScratchReturnMem scratch liq fee0 fee1 owed0 owed1).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - ⟨128⟩ := - mloadFreePtrValue (by rw [positionsScratchReturnMem_size liq fee0 fee1 owed0 owed1 hscratch]; decide) - (by decide) - (positionsScratchReturnMem_read64 liq fee0 fee1 owed0 owed1 hscratch hread64) - -theorem positionsScratchReturnMem_read128 {scratch : ByteArray} - (liq fee0 fee1 owed0 owed1 : UInt256) (hscratch : scratch.size = 96) : - (positionsScratchReturnMem scratch liq fee0 fee1 owed0 owed1).readWithPadding 128 32 = - UInt256.toByteArray liq := by - unfold positionsScratchReturnMem - exact writeCascade_read_word_of_head_of_base scratch (base := 96) (off := 128) - liq [(160, fee0), (192, fee1), (224, owed0), (256, owed1)] - hscratch (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem positionsScratchReturnMem_read160 {scratch : ByteArray} - (liq fee0 fee1 owed0 owed1 : UInt256) (hscratch : scratch.size = 96) : - (positionsScratchReturnMem scratch liq fee0 fee1 owed0 owed1).readWithPadding 160 32 = - UInt256.toByteArray fee0 := by - unfold positionsScratchReturnMem - change (writeCascade (positionsScratchReturnMem1 scratch liq) - [(160, fee0), (192, fee1), (224, owed0), (256, owed1)]).readWithPadding 160 32 = - UInt256.toByteArray fee0 - exact writeCascade_read_word_of_head_of_base (positionsScratchReturnMem1 scratch liq) - (base := 160) (off := 160) fee0 [(192, fee1), (224, owed0), (256, owed1)] - (positionsScratchReturnMem1_size liq hscratch) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem positionsScratchReturnMem_read192 {scratch : ByteArray} - (liq fee0 fee1 owed0 owed1 : UInt256) (hscratch : scratch.size = 96) : - (positionsScratchReturnMem scratch liq fee0 fee1 owed0 owed1).readWithPadding 192 32 = - UInt256.toByteArray fee1 := by - unfold positionsScratchReturnMem - change (writeCascade (positionsScratchReturnMem2 scratch liq fee0) - [(192, fee1), (224, owed0), (256, owed1)]).readWithPadding 192 32 = - UInt256.toByteArray fee1 - exact writeCascade_read_word_of_head_of_base (positionsScratchReturnMem2 scratch liq fee0) - (base := 192) (off := 192) fee1 [(224, owed0), (256, owed1)] - (positionsScratchReturnMem2_size liq fee0 hscratch) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem positionsScratchReturnMem_read224 {scratch : ByteArray} - (liq fee0 fee1 owed0 owed1 : UInt256) (hscratch : scratch.size = 96) : - (positionsScratchReturnMem scratch liq fee0 fee1 owed0 owed1).readWithPadding 224 32 = - UInt256.toByteArray owed0 := by - unfold positionsScratchReturnMem - change (writeCascade (positionsScratchReturnMem3 scratch liq fee0 fee1) - [(224, owed0), (256, owed1)]).readWithPadding 224 32 = - UInt256.toByteArray owed0 - exact writeCascade_read_word_of_head_of_base - (positionsScratchReturnMem3 scratch liq fee0 fee1) (base := 224) (off := 224) - owed0 [(256, owed1)] - (positionsScratchReturnMem3_size liq fee0 fee1 hscratch) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem positionsScratchReturnMem_read256 {scratch : ByteArray} - (liq fee0 fee1 owed0 owed1 : UInt256) (hscratch : scratch.size = 96) : - (positionsScratchReturnMem scratch liq fee0 fee1 owed0 owed1).readWithPadding 256 32 = - UInt256.toByteArray owed1 := by - unfold positionsScratchReturnMem - change (writeCascade (positionsScratchReturnMem4 scratch liq fee0 fee1 owed0) - [(256, owed1)]).readWithPadding 256 32 = - UInt256.toByteArray owed1 - exact writeCascade_read_word_of_head_of_base - (positionsScratchReturnMem4 scratch liq fee0 fee1 owed0) (base := 256) (off := 256) - owed1 [] - (positionsScratchReturnMem4_size liq fee0 fee1 owed0 hscratch) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem positionsScratchReturnMem_read128_160 {scratch : ByteArray} - (liq fee0 fee1 owed0 owed1 : UInt256) (hscratch : scratch.size = 96) : - (positionsScratchReturnMem scratch liq fee0 fee1 owed0 owed1).readWithPadding 128 160 = - UInt256.toByteArray liq ++ UInt256.toByteArray fee0 ++ UInt256.toByteArray fee1 ++ - UInt256.toByteArray owed0 ++ UInt256.toByteArray owed1 := by - let mem := positionsScratchReturnMem scratch liq fee0 fee1 owed0 owed1 - have hsize : mem.size = 288 := by - simpa [mem] using positionsScratchReturnMem_size liq fee0 fee1 owed0 owed1 hscratch - have h128 : mem.readWithPadding 128 32 = UInt256.toByteArray liq := by - simpa [mem] using positionsScratchReturnMem_read128 liq fee0 fee1 owed0 owed1 hscratch - have h160 : mem.readWithPadding 160 32 = UInt256.toByteArray fee0 := by - simpa [mem] using positionsScratchReturnMem_read160 liq fee0 fee1 owed0 owed1 hscratch - have h192 : mem.readWithPadding 192 32 = UInt256.toByteArray fee1 := by - simpa [mem] using positionsScratchReturnMem_read192 liq fee0 fee1 owed0 owed1 hscratch - have h224 : mem.readWithPadding 224 32 = UInt256.toByteArray owed0 := by - simpa [mem] using positionsScratchReturnMem_read224 liq fee0 fee1 owed0 owed1 hscratch - have h256 : mem.readWithPadding 256 32 = UInt256.toByteArray owed1 := by - simpa [mem] using positionsScratchReturnMem_read256 liq fee0 fee1 owed0 owed1 hscratch - change mem.readWithPadding 128 160 = _ - rw [byteArray_readWithPadding_split mem 128 32 128 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h128] - rw [byteArray_readWithPadding_split mem 160 32 96 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h160] - rw [byteArray_readWithPadding_split mem 192 32 64 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h192] - rw [byteArray_readWithPadding_split mem 224 32 32 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h224, h256] - simp only [ByteArray.append_assoc] - -theorem positionsScratch_mload64 {scratch : ByteArray} - (hscratch : scratch.size = 96) - (hread64 : scratch.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : - (if (⟨64⟩ : UInt256).toNat ≥ scratch.size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 3 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (scratch.readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - ⟨128⟩ := - mloadFreePtrValue (by rw [hscratch]; decide) (by decide) hread64 - -theorem positionsReturnEncodingMasked - (liq fee0 fee1 owed0 owed1 : UInt256) : - encodeReturnValues? [uint128, uint256, uint256, uint128, uint128] - [.int (Int.ofNat (UInt256.land liq uint128Mask).toNat), - .int (Int.ofNat fee0.toNat), - .int (Int.ofNat fee1.toNat), - .int (Int.ofNat (UInt256.land owed0 uint128Mask).toNat), - .int (Int.ofNat (UInt256.land owed1 uint128Mask).toNat)] = - some (UInt256.toByteArray (UInt256.land liq uint128Mask) ++ - UInt256.toByteArray fee0 ++ UInt256.toByteArray fee1 ++ - UInt256.toByteArray (UInt256.land owed0 uint128Mask) ++ - UInt256.toByteArray (UInt256.land owed1 uint128Mask)) := by - let liq' := UInt256.land liq uint128Mask - let owed0' := UInt256.land owed0 uint128Mask - let owed1' := UInt256.land owed1 uint128Mask - have hwordLiq : EVM.word liq'.toNat = liq' := by - show UInt256.ofNat liq'.toNat = liq' - exact u256_ofNat_toNat liq' - have hwordFee0 : EVM.word fee0.toNat = fee0 := by - show UInt256.ofNat fee0.toNat = fee0 - exact u256_ofNat_toNat fee0 - have hwordFee1 : EVM.word fee1.toNat = fee1 := by - show UInt256.ofNat fee1.toNat = fee1 - exact u256_ofNat_toNat fee1 - have hwordOwed0 : EVM.word owed0'.toNat = owed0' := by - show UInt256.ofNat owed0'.toNat = owed0' - exact u256_ofNat_toNat owed0' - have hwordOwed1 : EVM.word owed1'.toNat = owed1' := by - show UInt256.ofNat owed1'.toNat = owed1' - exact u256_ofNat_toNat owed1' - have hfee0Lt : fee0.toNat < EVM.twoPow 256 := by - change fee0.val.val < EVM.twoPow 256 - exact fee0.val.isLt - have hfee1Lt : fee1.toNat < EVM.twoPow 256 := by - change fee1.val.val < EVM.twoPow 256 - exact fee1.val.isLt - have hliqLt : liq'.toNat < EVM.twoPow 128 := by - simpa [liq'] using uint128Mask_bound liq - have howed0Lt : owed0'.toNat < EVM.twoPow 128 := by - simpa [owed0'] using uint128Mask_bound owed0 - have howed1Lt : owed1'.toNat < EVM.twoPow 128 := by - simpa [owed1'] using uint128Mask_bound owed1 - have hencLiq : - encodeABIValue? uint128 (.int (Int.ofNat liq'.toNat)) = - some (EVM.Word.toBytesBE liq') := by - simp [uint128, uint128Int, encodeABIValue?, encodeABIWord?, hwordLiq, - hliqLt] - have hencFee0 : - encodeABIValue? uint256 (.int (Int.ofNat fee0.toNat)) = - some (EVM.Word.toBytesBE fee0) := by - simp [uint256, uint256Int, encodeABIValue?, encodeABIWord?, hwordFee0, hfee0Lt] - have hencFee1 : - encodeABIValue? uint256 (.int (Int.ofNat fee1.toNat)) = - some (EVM.Word.toBytesBE fee1) := by - simp [uint256, uint256Int, encodeABIValue?, encodeABIWord?, hwordFee1, hfee1Lt] - have hencOwed0 : - encodeABIValue? uint128 (.int (Int.ofNat owed0'.toNat)) = - some (EVM.Word.toBytesBE owed0') := by - simp [uint128, uint128Int, encodeABIValue?, encodeABIWord?, hwordOwed0, - howed0Lt] - have hencOwed1 : - encodeABIValue? uint128 (.int (Int.ofNat owed1'.toNat)) = - some (EVM.Word.toBytesBE owed1') := by - simp [uint128, uint128Int, encodeABIValue?, encodeABIWord?, hwordOwed1, - howed1Lt] - have hhead : - abiTupleHeadSize? [uint128, uint256, uint256, uint128, uint128] = some 160 := by - native_decide - have hdyn128 : isDynamicABIType uint128 = false := by native_decide - have hdyn256 : isDynamicABIType uint256 = false := by native_decide - change encodeReturnValues? [uint128, uint256, uint256, uint128, uint128] - [.int (Int.ofNat liq'.toNat), .int (Int.ofNat fee0.toNat), - .int (Int.ofNat fee1.toNat), .int (Int.ofNat owed0'.toNat), - .int (Int.ofNat owed1'.toNat)] = - some (UInt256.toByteArray liq' ++ UInt256.toByteArray fee0 ++ - UInt256.toByteArray fee1 ++ UInt256.toByteArray owed0' ++ UInt256.toByteArray owed1') - rw [toByteArray_eq_toBytesBE liq', toByteArray_eq_toBytesBE fee0, - toByteArray_eq_toBytesBE fee1, toByteArray_eq_toBytesBE owed0', - toByteArray_eq_toBytesBE owed1'] - simp only [encodeReturnValues?, encodeABIValues?, encodeABIValuesFrom?, hhead, hencLiq, - hencFee0, hencFee1, hencOwed0, hencOwed1, hdyn128, hdyn256, bind, Option.bind, - Bool.false_eq_true, if_false, List.nil_append, List.append_nil] - apply congrArg some - apply ByteArray.ext - apply Array.toList_inj.mp - simp [liq', owed0', owed1'] - -theorem uniswapV3PoolPositionsReturn {v : PoolImmutables} {code : ByteArray} - {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} - {owed1 owed0 fee1 fee0 liq : UInt256} {R : List UInt256} {scratch rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨1386⟩ - (owed1 :: owed0 :: fee1 :: fee0 :: liq :: R) - scratch (UInt256.ofNat 3) rdata acc k C) - (hscratch : scratch.size = 96) - (hread64 : scratch.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) - (hov : R.length + 12 ≤ 1024) : - RDret code g s0 acc - (UInt256.toByteArray (UInt256.land liq uint128Mask) ++ - UInt256.toByteArray fee0 ++ UInt256.toByteArray fee1 ++ - UInt256.toByteArray (UInt256.land owed0 uint128Mask) ++ - UInt256.toByteArray (UInt256.land owed1 uint128Mask)) := by - let liq' := UInt256.land liq uint128Mask - let owed0' := UInt256.land owed0 uint128Mask - let owed1' := UInt256.land owed1 uint128Mask - have hmask : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨1⟩ = uint128Mask := by - native_decide - exact evm_run h with [ - raw jumpdest (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨64⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost (positionsScratch_mload64 hscratch hread64) (by decide) - (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨128⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw shl (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap7 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup8 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup2 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 6 (positionsScratchReturnMem1 scratch liq') (UInt256.ofNat 5) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [liq'] - rw [hmask, show (⟨128⟩ : UInt256).toNat = 128 from by decide, - u256_land_comm uint128Mask liq, positionsScratchReturnMem1_eq] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨32⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup2 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap6 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap6 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 (positionsScratchReturnMem2 scratch liq' fee0) (UInt256.ofNat 6) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - rw [show ((⟨128⟩ : UInt256) + ⟨32⟩).toNat = 160 from by decide, - positionsScratchReturnMem2_eq] - rfl) - (by decide) (by evm_ov), - raw dup5 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup2 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap4 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap4 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 (positionsScratchReturnMem3 scratch liq' fee0 fee1) - (UInt256.ofNat 7) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - rw [show ((⟨64⟩ : UInt256) + ⟨128⟩).toNat = 192 from by decide, - positionsScratchReturnMem3_eq] - rfl) - (by decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup5 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨96⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup5 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 (positionsScratchReturnMem4 scratch liq' fee0 fee1 owed0') - (UInt256.ofNat 8) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [owed0'] - rw [hmask, show ((⟨128⟩ : UInt256) + ⟨96⟩).toNat = 224 from by decide, - u256_land_comm uint128Mask owed0, positionsScratchReturnMem4_eq] - rfl) - (by decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap3 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨128⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup3 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 (positionsScratchReturnMem scratch liq' fee0 fee1 owed0' owed1') - (UInt256.ofNat 9) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [owed1'] - rw [hmask, show ((⟨128⟩ : UInt256) + ⟨128⟩).toNat = 256 from by decide, - u256_land_comm uint128Mask owed1, positionsScratchReturnMem_eq] - rfl) - (by decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 9) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (positionsScratchReturnMem_mload64 liq' fee0 fee1 owed0' owed1' hscratch hread64) - (by decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup2 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨160⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw ret 0 - (UInt256.toByteArray liq' ++ UInt256.toByteArray fee0 ++ UInt256.toByteArray fee1 ++ - UInt256.toByteArray owed0' ++ UInt256.toByteArray owed1') - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [liq', owed0', owed1'] - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - show ((⟨160⟩ : UInt256) + UInt256.sub (⟨128⟩ : UInt256) ⟨128⟩).toNat = - 160 from by decide] - exact positionsScratchReturnMem_read128_160 - (UInt256.land liq uint128Mask) fee0 fee1 - (UInt256.land owed0 uint128Mask) (UInt256.land owed1 uint128Mask) hscratch) - (by evm_ov)] - -private theorem uniswapV3PoolPositionsLoadedToReturn {v : PoolImmutables} - {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (rdLoaded : RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1386⟩ - (positionsTokensOwed1Word σ I :: positionsTokensOwed0Word σ I :: - positionsFeeGrowthInside1Word σ I :: positionsFeeGrowthInside0Word σ I :: - positionsLiquidityWord σ I :: ⟨1386⟩ :: [solcSelectorWord I]) - (solcMappingHashMem ⟨7⟩ (positionsArgWord I)) (UInt256.ofNat 3) - ByteArray.empty (cA, σ) k C) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land (positionsLiquidityWord σ I) uint128Mask) ++ - UInt256.toByteArray (positionsFeeGrowthInside0Word σ I) ++ - UInt256.toByteArray (positionsFeeGrowthInside1Word σ I) ++ - UInt256.toByteArray (UInt256.land (positionsTokensOwed0Word σ I) uint128Mask) ++ - UInt256.toByteArray - (UInt256.land (positionsTokensOwed1Word σ I) uint128Mask)) := by - exact uniswapV3PoolPositionsReturn hpatch - (owed1 := positionsTokensOwed1Word σ I) (owed0 := positionsTokensOwed0Word σ I) - (fee1 := positionsFeeGrowthInside1Word σ I) - (fee0 := positionsFeeGrowthInside0Word σ I) - (liq := positionsLiquidityWord σ I) (R := [⟨1386⟩, solcSelectorWord I]) - rdLoaded (solcMappingHashMem_size ⟨7⟩ (positionsArgWord I)) - (solcMappingHashMem_read64 ⟨7⟩ (positionsArgWord I)) - (by simp only [List.length_cons, List.length_nil]; omega) - -theorem uniswapV3PoolPositionsEvm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 11 == I.calldata.extract 0 4) = true) - (hsz36 : 36 ≤ I.calldata.size) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (positionsLiquidityWord σ I) ++ - UInt256.toByteArray (positionsFeeGrowthInside0Word σ I) ++ - UInt256.toByteArray (positionsFeeGrowthInside1Word σ I) ++ - UInt256.toByteArray (positionsTokensOwed0Word σ I) ++ - UInt256.toByteArray (positionsTokensOwed1Word σ I)) := by - have hreach := uniswapV3PoolPositionsReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - have hdecoded := uniswapV3PoolPositionsExternalLenOk hpatch hreach hsz36 hsize - obtain ⟨_, _, rdDecoded⟩ := hdecoded - obtain ⟨_, _, rdLoaded⟩ := uniswapV3PoolPositionsDecodedToLoaded hpatch rdDecoded - have hret := uniswapV3PoolPositionsLoadedToReturn hpatch rdLoaded - have hcleanLiq : - UInt256.land (positionsLiquidityWord σ I) uint128Mask = - positionsLiquidityWord σ I := by - exact uint128Mask_clean (by - simpa [positionsLiquidityWord] using uint128Mask_bound (solcSlotWord σ I - (positionsBaseSlot I))) - have hcleanOwed0 : - UInt256.land (positionsTokensOwed0Word σ I) uint128Mask = - positionsTokensOwed0Word σ I := by - exact uint128Mask_clean (by - simpa [positionsTokensOwed0Word] using uint128Mask_bound (positionsPackedWord σ I)) - have hcleanOwed1 : - UInt256.land (positionsTokensOwed1Word σ I) uint128Mask = - positionsTokensOwed1Word σ I := by - exact uint128Mask_clean (by - simpa [positionsTokensOwed1Word] using - uint128Mask_bound (UInt256.div (positionsPackedWord σ I) positionsShift)) - simpa [hcleanLiq, hcleanOwed0, hcleanOwed1] using hret - -theorem positionsStore_arg0 (I : ExecutionEnv) : - Std.HashMap.get? (positionsStore I) "arg0" = some (positionsArgValue I) := by - simp [positionsStore] - -theorem evalExpr_positions_arg0 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := positionsStore I } evm - (.var "arg0") = .ok (positionsArgValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [positionsStore_arg0] - -def positionsEvaledRef (I : ExecutionEnv) (field : Ident) : EvaledStorageRef := - { base := "positions", steps := [.mindex (positionsArgKey I), .field field] } - -theorem evalStorageRef_positions {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (field : Ident) : - evalStorageRef (config v) { contract := contract v, locals := positionsStore I } evm - (positionsF (.var "arg0") field) = .ok (positionsEvaledRef I field) := by - have hlen : (EVM.Word.toBytesBE (positionsArgWord I)).length = bytes32Width.val + 1 := by - simpa [bytes32Width] using word_toBytesBE_toByteArray_size (positionsArgWord I) - simp [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, positionsF, - positionsEvaledRef, evalExpr_positions_arg0, positionsArgValue, positionsArgKey, - valueToKey?, hlen, EvalResult.bind, EvalResult.ofOption, bind, pure] - -theorem positionsStorageLocLoad_liquidity (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (positionsBaseSlot I) ⟨0, by decide⟩ ⟨16, by decide⟩ (by decide) - (.int uint128Int)) = - .int (Int.ofNat (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (positionsBaseSlot I)) - uint128Mask).toNat) := by - rw [← show UInt256.ofNat (2 ^ (8 * 16) - 1) = uint128Mask by native_decide] - simpa [loc, uint128Int] using - storageLocLoad_uint_offset0 evm (positionsBaseSlot I) (16 : Fin 33) ⟨128, by decide⟩ - (hbound := by decide) (by decide) - -theorem positionsStorageLocLoad_feeGrowthInside0 (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (positionsBaseSlot I + ⟨1⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int)) = - .int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (positionsBaseSlot I + ⟨1⟩)).toNat) := by - simpa [loc, uint256Loc] using - storageLocLoad_uint256 evm (positionsBaseSlot I + ⟨1⟩) - -theorem positionsStorageLocLoad_feeGrowthInside1 (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (positionsBaseSlot I + ⟨2⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int)) = - .int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (positionsBaseSlot I + ⟨2⟩)).toNat) := by - simpa [loc, uint256Loc] using - storageLocLoad_uint256 evm (positionsBaseSlot I + ⟨2⟩) - -theorem positionsStorageLocLoad_tokensOwed0 (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (positionsPackedSlot I) ⟨0, by decide⟩ ⟨16, by decide⟩ (by decide) - (.int uint128Int)) = - .int (Int.ofNat (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (positionsPackedSlot I)) - uint128Mask).toNat) := by - rw [← show UInt256.ofNat (2 ^ (8 * 16) - 1) = uint128Mask by native_decide] - simpa [loc, uint128Int] using - storageLocLoad_uint_offset0 evm (positionsPackedSlot I) (16 : Fin 33) ⟨128, by decide⟩ - (hbound := by decide) (by decide) - -theorem positionsStorageLocLoad_tokensOwed1 (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (positionsPackedSlot I) ⟨16, by decide⟩ ⟨16, by decide⟩ (by decide) - (.int uint128Int)) = - .int (Int.ofNat (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (positionsPackedSlot I)) - positionsShift) uint128Mask).toNat) := by - rw [← show UInt256.ofNat (256 ^ 16) = positionsShift by native_decide] - rw [← show UInt256.ofNat (256 ^ 16 - 1) = uint128Mask by native_decide] - simpa [loc, uint128Int] using - storageLocLoad_uint_offset evm (positionsPackedSlot I) (16 : Fin 32) (16 : Fin 33) - ⟨128, by decide⟩ (by decide) (by decide) - -theorem uniswapV3PoolPositionsSourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (positionsStore I) positionsTransition.body - (.returned { contract := contract v, locals := positionsStore I } - (initState cA gh bl σ σ₀ g A I) - (some (positionsReturnValues σ I))) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (positionsStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [ .storage (positionsF (.var "arg0") "liquidity"), - .storage (positionsF (.var "arg0") "feeGrowthInside0LastX128"), - .storage (positionsF (.var "arg0") "feeGrowthInside1LastX128"), - .storage (positionsF (.var "arg0") "tokensOwed0"), - .storage (positionsF (.var "arg0") "tokensOwed1") ] ] _ - exact ExecFuncBody.execBlockRet <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true (by simp [initState, hwv]))) <| - ExecBlock.consReturn <| ExecStmt.return (by - have hliq : - evalExpr? (config v) { contract := contract v, locals := positionsStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (positionsF (.var "arg0") "liquidity")) = - .ok (.int (Int.ofNat (positionsLiquidityWord σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := positionsEvaledRef I "liquidity") - (t := .int uint128Int) - (loc := loc (positionsBaseSlot I) ⟨0, by decide⟩ ⟨16, by decide⟩ - (by decide) (.int uint128Int)) - · simp [positionsStore, positionsF] - · exact evalStorageRef_positions (v := v) (initState cA gh bl σ σ₀ g A I) I - "liquidity" - · simp [positionsEvaledRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, positionInfoStructTy, uint128St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - positionsEvaledRef, positionsBaseSlot, loc] - · simpa [initState, positionsLiquidityWord, solcSlotWord] using - positionsStorageLocLoad_liquidity (initState cA gh bl σ σ₀ g A I) I - have hfee0 : - evalExpr? (config v) { contract := contract v, locals := positionsStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (positionsF (.var "arg0") "feeGrowthInside0LastX128")) = - .ok (.int (Int.ofNat (positionsFeeGrowthInside0Word σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := positionsEvaledRef I "feeGrowthInside0LastX128") - (t := .int uint256Int) - (loc := loc (positionsBaseSlot I + ⟨1⟩) ⟨0, by decide⟩ - ⟨32, by decide⟩ (by decide) (.int uint256Int)) - · simp [positionsStore, positionsF] - · exact evalStorageRef_positions (v := v) (initState cA gh bl σ σ₀ g A I) I - "feeGrowthInside0LastX128" - · simp [positionsEvaledRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, positionInfoStructTy, uint256St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - positionsEvaledRef, positionsBaseSlot, loc] - · simpa [initState, positionsFeeGrowthInside0Word, solcSlotWord] using - positionsStorageLocLoad_feeGrowthInside0 (initState cA gh bl σ σ₀ g A I) I - have hfee1 : - evalExpr? (config v) { contract := contract v, locals := positionsStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (positionsF (.var "arg0") "feeGrowthInside1LastX128")) = - .ok (.int (Int.ofNat (positionsFeeGrowthInside1Word σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := positionsEvaledRef I "feeGrowthInside1LastX128") - (t := .int uint256Int) - (loc := loc (positionsBaseSlot I + ⟨2⟩) ⟨0, by decide⟩ - ⟨32, by decide⟩ (by decide) (.int uint256Int)) - · simp [positionsStore, positionsF] - · exact evalStorageRef_positions (v := v) (initState cA gh bl σ σ₀ g A I) I - "feeGrowthInside1LastX128" - · simp [positionsEvaledRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, positionInfoStructTy, uint256St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - positionsEvaledRef, positionsBaseSlot, loc] - · simpa [initState, positionsFeeGrowthInside1Word, solcSlotWord] using - positionsStorageLocLoad_feeGrowthInside1 (initState cA gh bl σ σ₀ g A I) I - have htok0 : - evalExpr? (config v) { contract := contract v, locals := positionsStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (positionsF (.var "arg0") "tokensOwed0")) = - .ok (.int (Int.ofNat (positionsTokensOwed0Word σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := positionsEvaledRef I "tokensOwed0") - (t := .int uint128Int) - (loc := loc (positionsPackedSlot I) ⟨0, by decide⟩ ⟨16, by decide⟩ - (by decide) (.int uint128Int)) - · simp [positionsStore, positionsF] - · exact evalStorageRef_positions (v := v) (initState cA gh bl σ σ₀ g A I) I - "tokensOwed0" - · simp [positionsEvaledRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, positionInfoStructTy, uint128St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - positionsEvaledRef, positionsBaseSlot, positionsPackedSlot, loc] - · simpa [initState, positionsTokensOwed0Word, positionsPackedWord, solcSlotWord] using - positionsStorageLocLoad_tokensOwed0 (initState cA gh bl σ σ₀ g A I) I - have htok1 : - evalExpr? (config v) { contract := contract v, locals := positionsStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (positionsF (.var "arg0") "tokensOwed1")) = - .ok (.int (Int.ofNat (positionsTokensOwed1Word σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := positionsEvaledRef I "tokensOwed1") - (t := .int uint128Int) - (loc := loc (positionsPackedSlot I) ⟨16, by decide⟩ ⟨16, by decide⟩ - (by decide) (.int uint128Int)) - · simp [positionsStore, positionsF] - · exact evalStorageRef_positions (v := v) (initState cA gh bl σ σ₀ g A I) I - "tokensOwed1" - · simp [positionsEvaledRef, contract, storageDecls, storageTypeAt?, - storageTypeStep?, positionInfoStructTy, uint128St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - positionsEvaledRef, positionsBaseSlot, positionsPackedSlot, loc] - · simpa [initState, positionsTokensOwed1Word, positionsPackedWord, solcSlotWord] using - positionsStorageLocLoad_tokensOwed1 (initState cA gh bl σ σ₀ g A I) I - simp only [positionsReturnValues, Solm.evalExprs?.eq_def, hliq, hfee0, hfee1, htok0, - htok1, EvalResult.bind, bind, pure]) - -theorem uniswapV3PoolPositionsValueTransport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - some (positionsReturnValues σ_solm I) = some (positionsReturnValues σ_evm I) := by - have hbase := accountMapEquiv_storage_findD hAccounts I.codeOwner - (positionsBaseSlot I) (⟨0⟩ : UInt256) - have hfee0 := accountMapEquiv_storage_findD hAccounts I.codeOwner - (positionsBaseSlot I + ⟨1⟩) (⟨0⟩ : UInt256) - have hfee1 := accountMapEquiv_storage_findD hAccounts I.codeOwner - (positionsBaseSlot I + ⟨2⟩) (⟨0⟩ : UInt256) - have hpacked := accountMapEquiv_storage_findD hAccounts I.codeOwner - (positionsPackedSlot I) (⟨0⟩ : UInt256) - dsimp [positionsReturnValues, positionsLiquidityWord, positionsFeeGrowthInside0Word, - positionsFeeGrowthInside1Word, positionsTokensOwed0Word, positionsTokensOwed1Word, - positionsPackedWord, solcSlotWord] - rw [← hbase, ← hfee0, ← hfee1, ← hpacked] - -theorem uniswapV3PoolPositionsBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 11 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_positions (v := v) (cd := I.calldata) hsel - have hvalue := uniswapV3PoolPositionsValueTransport (σ_evm := σ_evm) - (σ_solm := σ_solm) (I := I) hAccounts - by_cases hsz36 : 36 ≤ I.calldata.size - · have hdecode := uniswapV3PoolPositionsDecodeOk (v := v) (I := I) hsz36 - have hbody := uniswapV3PoolPositionsSourceBody (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hrd := uniswapV3PoolPositionsEvm (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hsz36 - exact hrd.reEquivExecutionTransport hcode hdispatch hdecode hbody hvalue hAccounts - (by - rw [show positionsTransition.returnType = - [uint128, uint256, uint256, uint128, uint128] from rfl] - exact returnEquiv.returned rfl - (positionsReturnEncodingMasked (solcSlotWord σ_evm I (positionsBaseSlot I)) - (positionsFeeGrowthInside0Word σ_evm I) - (positionsFeeGrowthInside1Word σ_evm I) - (positionsPackedWord σ_evm I) - (UInt256.div (positionsPackedWord σ_evm I) positionsShift))) - · have hshort : I.calldata.size < 36 := by omega - have hdecode := uniswapV3PoolPositionsDecodeShort (v := v) (I := I) hshort - have hrd := uniswapV3PoolPositionsEvmDecodeShort (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hshort - exact hrd.reEquivDecodingFailed hcode hdispatch hdecode - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/ProtocolFees.lean b/Benchmarks/UniswapV3Pool/ProtocolFees.lean deleted file mode 100644 index f884d765..00000000 --- a/Benchmarks/UniswapV3Pool/ProtocolFees.lean +++ /dev/null @@ -1,724 +0,0 @@ -import Benchmarks.UniswapV3Pool.Uint128 - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev protocolFeesShift : UInt256 := UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ - -abbrev protocolFeesSlotWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I ⟨3⟩ - -abbrev protocolFeesToken0Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (protocolFeesSlotWord σ I) uint128Mask - -abbrev protocolFeesToken1Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.div (protocolFeesSlotWord σ I) protocolFeesShift) uint128Mask - -theorem uniswapV3PoolProtocolFeesReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 3 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨682⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 3 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0x1a 0xd8 0xb0 0x3b - (uniswapV3PoolSelNat 3) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h239 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨239⟩) hpatch h32 hgt32 - have hgt239 : UInt256.gt (armSelNat code ⟨239⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h348 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨348⟩) hpatch h239 hgt239 - have hgt348 : UInt256.gt (armSelNat code ⟨348⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h359 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨359⟩) hpatch h348 hgt348 - have h682 := uniswapV3PoolSelectorArmHitTo (i := 3) (target := ⟨682⟩) - hpatch hsz hsel h359 - exact ⟨_, _, h682⟩ - -theorem uniswapV3PoolProtocolFeesDecode {v : PoolImmutables} {I : ExecutionEnv} - (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - (protocolfeesTransition.params.map Param.name) - (transitionSignature protocolfeesTransition).paramTypes I.calldata = some (∅ : Store) := by - simpa [config, protocolfeesTransition, transitionSignature] using - decodeCalldataWithMode_empty_ok (mode := DecodeMode.legacySolc05) (cd := I.calldata) hsz - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolDispatch_protocolFees {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 3 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some protocolfeesTransition := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, factoryTransition v, - feeTransition v, feegrowthglobal0X128Transition, feegrowthglobal1X128Transition, - flashTransition v, increaseobservationcardinalitynextTransition v, initializeTransition, - liquidityTransition, maxliquiditypertickTransition v, mintTransition v, observationsTransition, - observeTransition v, positionsTransition]) - (post := [setfeeprotocolTransition v, slot0Transition, snapshotcumulativesinsideTransition v, - swapTransition v, tickbitmapTransition, tickspacingTransition v, ticksTransition, - token0Transition v, token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 3) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 3) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 3) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 3) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 3) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 3) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 3) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 3) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 5) (j := 3) - (by native_decide) hsel - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 25) (j := 3) - (by native_decide) hsel - · rw [selectorOf, liquiditySelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 2) (j := 3) - (by native_decide) hsel - · rw [selectorOf, maxLiquidityPerTickSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 13) (j := 3) - (by native_decide) hsel - · rw [selectorOf, mintSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 7) (j := 3) - (by native_decide) hsel - · rw [selectorOf, observationsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 4) (j := 3) - (by native_decide) hsel - · rw [selectorOf, observeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 16) (j := 3) - (by native_decide) hsel - · rw [selectorOf, positionsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 11) (j := 3) - (by native_decide) hsel - · rw [selectorOf, protocolFeesSelectorBytes] - simpa [uniswapV3PoolSelBytes] using hsel - -private theorem uniswapV3PoolProtocolFeesPatchDisjoint {v : PoolImmutables} {pc : UInt256} - (hlo : 5308 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 6603) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> - omega - -private theorem uniswapV3PoolPatchPreservesJumpDest5308 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨5308⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched5308 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨5308⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest5308 - -theorem uniswapV3PoolProtocolFeesEntryWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcGetterEntryWf code ⟨682⟩ ⟨690⟩ ⟨5308⟩ := by - dsimp [solcGetterEntryWf] - refine ⟨?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolProtocolFeesRoutine {v : PoolImmutables} {code : ByteArray} - {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {ret : UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5308⟩ (ret :: R) mem aw rdata (cA, σ) k C) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 8 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret - (protocolFeesToken1Word σ ee :: protocolFeesToken0Word σ ee :: ret :: R) - mem aw rdata (cA, σ) k' C' := by - have hd5308 : decode code ⟨5308⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5309 : decode code ⟨5309⟩ = some (.Push .PUSH1, some (⟨3⟩, 1)) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5311 : decode code ⟨5311⟩ = some (.SLOAD, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5312 : decode code ⟨5312⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5314 : decode code ⟨5314⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5316 : decode code ⟨5316⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5318 : decode code ⟨5318⟩ = some (.SHL, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5319 : decode code ⟨5319⟩ = some (.SUB, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5320 : decode code ⟨5320⟩ = some (.DUP1, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5321 : decode code ⟨5321⟩ = some (.DUP3, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5322 : decode code ⟨5322⟩ = some (.AND, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5323 : decode code ⟨5323⟩ = some (.SWAP2, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5324 : decode code ⟨5324⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5326 : decode code ⟨5326⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5328 : decode code ⟨5328⟩ = some (.SHL, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5329 : decode code ⟨5329⟩ = some (.SWAP1, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5330 : decode code ⟨5330⟩ = some (.DIV, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5331 : decode code ⟨5331⟩ = some (.AND, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5332 : decode code ⟨5332⟩ = some (.DUP3, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have hd5333 : decode code ⟨5333⟩ = some (.JUMP, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolProtocolFeesPatchDisjoint (by native_decide) (by native_decide))] - native_decide - have rd5309 := h.jumpdest hd5308 (by simp only [List.length_cons]; omega) - have rd5311 := rd5309.push1 ⟨3⟩ hd5309 (by simp only [List.length_cons]; omega) - obtain ⟨_, _, rd5312⟩ := rd5311.sload hd5311 (by simp only [List.length_cons]; omega) - have rd5333 := evm_run rd5312 with [ - raw push1 ⟨1⟩ hd5312 (by evm_ov), - raw push1 ⟨1⟩ hd5314 (by evm_ov), - raw push1 ⟨128⟩ hd5316 (by evm_ov), - raw shl hd5318 (by evm_ov), - raw sub hd5319 (by evm_ov), - raw dup1 hd5320 (by evm_ov), - raw dup3 hd5321 (by evm_ov), - raw and hd5322 (by evm_ov), - raw swap2 hd5323 (by evm_ov), - raw push1 ⟨1⟩ hd5324 (by evm_ov), - raw push1 ⟨128⟩ hd5326 (by evm_ov), - raw shl hd5328 (by evm_ov), - raw swap1 hd5329 (by evm_ov), - raw div hd5330 (by evm_ov), - raw and hd5331 (by evm_ov), - raw dup3 hd5332 (by evm_ov)] - have rdRet := rd5333.jump hd5333 hret (by simp only [List.length_cons]; omega) - have hmask : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨1⟩ = uint128Mask := by - native_decide - exact ⟨_, _, by - rw [hmask] at rdRet - simpa [protocolFeesToken0Word, protocolFeesToken1Word, protocolFeesSlotWord, - protocolFeesShift] using rdRet⟩ - -noncomputable def protocolFeesReturn0Mem (t0 : UInt256) : ByteArray := - (UInt256.toByteArray t0).write 0 solcFreePtrMem 128 32 - -noncomputable def protocolFeesReturnMem (t0 t1 : UInt256) : ByteArray := - (UInt256.toByteArray t1).write 0 (protocolFeesReturn0Mem t0) 160 32 - -theorem protocolFeesReturn0Mem_size (t0 : UInt256) : - (protocolFeesReturn0Mem t0).size = 160 := by - unfold protocolFeesReturn0Mem - rw [toByteArray_write_eq _ _ _ (by rw [solcFreePtrMem_size]; omega) - (by rw [solcFreePtrMem_size]; exact lt_usize _ (by norm_num)), - ByteArray.size_append, ByteArray.size_append, solcFreePtrMem_size, ByteArray_zeroes_size, - show (USize.ofNat (128 - 96)).toNat = 32 from by - exact USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num)), - toByteArray_size] - -theorem protocolFeesReturnMem_size (t0 t1 : UInt256) : - (protocolFeesReturnMem t0 t1).size = 192 := by - unfold protocolFeesReturnMem - rw [toByteArray_write_eq _ _ _ (by rw [protocolFeesReturn0Mem_size]) - (by rw [protocolFeesReturn0Mem_size]; exact lt_usize _ (by norm_num)), - ByteArray.size_append, ByteArray.size_append, protocolFeesReturn0Mem_size, - ByteArray_zeroes_size, - show (USize.ofNat (160 - 160)).toNat = 0 from by - exact USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num)), - toByteArray_size] - -theorem protocolFeesReturn0Mem_read64 (t0 : UInt256) : - (protocolFeesReturn0Mem t0).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by - unfold protocolFeesReturn0Mem - rw [toByteArray_write_eq _ _ _ (by rw [solcFreePtrMem_size]; omega) - (by rw [solcFreePtrMem_size]; exact lt_usize _ (by norm_num))] - rw [readWithPadding_eq_extract _ 64 (by - rw [ByteArray.size_append, ByteArray.size_append, solcFreePtrMem_size, - ByteArray_zeroes_size, - show (USize.ofNat (128 - 96)).toNat = 32 from by - exact USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num)), - toByteArray_size] - norm_num)] - rw [extract_append_left _ _ _ _ (by - rw [ByteArray.size_append, solcFreePtrMem_size, ByteArray_zeroes_size, - show (USize.ofNat (128 - 96)).toNat = 32 from by - exact USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num))] - omega)] - rw [extract_append_left _ _ _ _ (by rw [solcFreePtrMem_size]), - ← readWithPadding_eq_extract _ 64 (by rw [solcFreePtrMem_size]), solcFreePtrMem_read64] - -theorem protocolFeesReturnMem_read64 (t0 t1 : UInt256) : - (protocolFeesReturnMem t0 t1).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by - unfold protocolFeesReturnMem - rw [write32_read_below _ _ 160 64 (by rw [toByteArray_size]) - (by rw [protocolFeesReturn0Mem_size]) (by omega)] - exact protocolFeesReturn0Mem_read64 t0 - -theorem protocolFeesReturnMem_mload64 (t0 t1 : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ (protocolFeesReturnMem t0 t1).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 6 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((protocolFeesReturnMem t0 t1).readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩ := - mloadFreePtrValue (by rw [protocolFeesReturnMem_size]; decide) (by decide) - (protocolFeesReturnMem_read64 t0 t1) - -set_option maxHeartbeats 800000 in -theorem protocolFeesReturnMem_read128_64 (t0 t1 : UInt256) : - (protocolFeesReturnMem t0 t1).readWithPadding 128 64 = - UInt256.toByteArray t0 ++ UInt256.toByteArray t1 := by - rw [readWithPadding_eq_extract' _ 128 64 (by norm_num) (by norm_num) - (by rw [protocolFeesReturnMem_size])] - unfold protocolFeesReturnMem - rw [toByteArray_write_eq _ _ _ (by rw [protocolFeesReturn0Mem_size]) - (by rw [protocolFeesReturn0Mem_size]; exact lt_usize _ (by norm_num))] - rw [extract_append_span - (protocolFeesReturn0Mem t0 ++ - ffi.ByteArray.zeroes (USize.ofNat (160 - (protocolFeesReturn0Mem t0).size))) - (UInt256.toByteArray t1) 128 192 (by - rw [ByteArray.size_append, protocolFeesReturn0Mem_size, ByteArray_zeroes_size, - show (USize.ofNat (160 - 160)).toNat = 0 from by - exact USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num))] - omega) (by - rw [ByteArray.size_append, protocolFeesReturn0Mem_size, ByteArray_zeroes_size, - show (USize.ofNat (160 - 160)).toNat = 0 from by - exact USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num))] - omega)] - rw [ByteArray.size_append, protocolFeesReturn0Mem_size, ByteArray_zeroes_size, - show (USize.ofNat (160 - 160)).toNat = 0 from by - exact USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num))] - rw [show ffi.ByteArray.zeroes (USize.ofNat (160 - 160)) = ByteArray.empty by - exact zeroes_zero (n := USize.ofNat 0) - (by exact USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num)))] - simp - unfold protocolFeesReturn0Mem - rw [toByteArray_write_eq _ _ _ (by rw [solcFreePtrMem_size]; omega) - (by rw [solcFreePtrMem_size]; exact lt_usize _ (by norm_num))] - rw [extract_append_right_window - (solcFreePtrMem ++ ffi.ByteArray.zeroes (USize.ofNat (128 - solcFreePtrMem.size))) - (UInt256.toByteArray t0) 128 160 (by - rw [ByteArray.size_append, solcFreePtrMem_size, ByteArray_zeroes_size, - show (USize.ofNat (128 - 96)).toNat = 32 from by - exact USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num))])] - rw [ByteArray.size_append, solcFreePtrMem_size, ByteArray_zeroes_size, - show (USize.ofNat (128 - 96)).toNat = 32 from by - exact USize.toNat_ofNat_of_lt' (lt_usize _ (by norm_num))] - norm_num - repeat' - first - | rw [show (UInt256.toByteArray t0).extract 0 32 = UInt256.toByteArray t0 from by - apply ByteArray.ext - rw [ByteArray.data_extract] - exact Array.extract_eq_self_of_le (by - change (UInt256.toByteArray t0).size ≤ 32 - rw [toByteArray_size])] - | rw [show (UInt256.toByteArray t1).extract 0 32 = UInt256.toByteArray t1 from by - apply ByteArray.ext - rw [ByteArray.data_extract] - exact Array.extract_eq_self_of_le (by - change (UInt256.toByteArray t1).size ≤ 32 - rw [toByteArray_size])] - -theorem protocolFeesRetLen_toNat : - ((⟨64⟩ : UInt256) + UInt256.sub (⟨128⟩ : UInt256) ⟨128⟩).toNat = 64 := by - decide - -theorem uniswapV3PoolProtocolFeesReturn {v : PoolImmutables} {code : ByteArray} - {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} - {t1 t0 : UInt256} {R : List UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨690⟩ (t1 :: t0 :: R) solcFreePtrMem (UInt256.ofNat 3) - rdata acc k C) - (hov : R.length + 10 ≤ 1024) : - RDret code g s0 acc - (UInt256.toByteArray (UInt256.land t0 uint128Mask) ++ - UInt256.toByteArray (UInt256.land t1 uint128Mask)) := by - let t0' := UInt256.land t0 uint128Mask - let t1' := UInt256.land t1 uint128Mask - have hmask : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨1⟩ = uint128Mask := by - native_decide - exact evm_run h with [ - raw jumpdest (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨64⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - raw dup1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup4 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨128⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw shl (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup2 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 6 (protocolFeesReturn0Mem t0') (UInt256.ofNat 5) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - rw [hmask, u256_land_comm uint128Mask t0, - show (⟨128⟩ : UInt256).toNat = 128 from by decide] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨32⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup3 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨128⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw shl (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup2 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 (protocolFeesReturnMem t0' t1') (UInt256.ofNat 6) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - rw [hmask, u256_land_comm uint128Mask t1, - show ((⟨32⟩ : UInt256) + ⟨128⟩).toNat = 160 from by decide] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨32⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap3 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw pop (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw pop (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw pop (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨64⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 6) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost (protocolFeesReturnMem_mload64 t0' t1') (by decide) - (by evm_ov), - raw dup1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap2 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw ret 0 (UInt256.toByteArray t0' ++ UInt256.toByteArray t1') (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - show ((⟨32⟩ + (⟨32⟩ + ⟨128⟩ : UInt256)).sub ⟨128⟩).toNat = 64 from by - decide] - exact protocolFeesReturnMem_read128_64 t0' t1') - (by evm_ov)] - -theorem uniswapV3PoolProtocolFeesReturnJumpDest {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨690⟩ = true := - uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide) - -theorem uniswapV3PoolProtocolFeesEvm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 3 == I.calldata.extract 0 4) = true) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (protocolFeesToken0Word σ I) ++ - UInt256.toByteArray (protocolFeesToken1Word σ I)) := by - have hreach := uniswapV3PoolProtocolFeesReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - obtain ⟨_, _, rdRoutine⟩ := RD.solcGetterThunk hreach - (uniswapV3PoolProtocolFeesEntryWf hpatch) - (uniswapV3PoolJumpDestPatched5308 hpatch) - obtain ⟨_, _, rdReturn⟩ := uniswapV3PoolProtocolFeesRoutine hpatch rdRoutine - (uniswapV3PoolProtocolFeesReturnJumpDest hpatch) - (by simp only [List.length_singleton]; omega) - have hret := uniswapV3PoolProtocolFeesReturn hpatch - (t1 := protocolFeesToken1Word σ I) (t0 := protocolFeesToken0Word σ I) - (R := [⟨690⟩, solcSelectorWord I]) rdReturn - (by simp only [List.length_cons, List.length_nil]; omega) - have hclean0 : UInt256.land (protocolFeesToken0Word σ I) uint128Mask = - protocolFeesToken0Word σ I := by - exact uint128Mask_clean (by - simpa [protocolFeesToken0Word] using uint128Mask_bound (protocolFeesSlotWord σ I)) - have hclean1 : UInt256.land (protocolFeesToken1Word σ I) uint128Mask = - protocolFeesToken1Word σ I := by - exact uint128Mask_clean (by - simpa [protocolFeesToken1Word] using - uint128Mask_bound (UInt256.div (protocolFeesSlotWord σ I) protocolFeesShift)) - simpa [hclean0, hclean1] using hret - -theorem protocolFeesStorageLocLoad_token0 (evm : EVM.State) : - storageLocLoad evm - (loc ⟨3⟩ ⟨0, by decide⟩ ⟨16, by decide⟩ (by decide) (.int uint128Int)) = - .int (Int.ofNat (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨3⟩) uint128Mask).toNat) := by - rw [← show UInt256.ofNat (2 ^ (8 * 16) - 1) = uint128Mask by native_decide] - simpa [loc, uint128Int] using - storageLocLoad_uint_offset0 evm ⟨3⟩ (16 : Fin 33) ⟨128, by decide⟩ - (hbound := by decide) (by decide) - -theorem protocolFeesStorageLocLoad_token1 (evm : EVM.State) : - storageLocLoad evm - (loc ⟨3⟩ ⟨16, by decide⟩ ⟨16, by decide⟩ (by decide) (.int uint128Int)) = - .int (Int.ofNat (UInt256.land - (UInt256.div (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨3⟩) - protocolFeesShift) uint128Mask).toNat) := by - rw [← show UInt256.ofNat (256 ^ 16) = protocolFeesShift by native_decide] - rw [← show UInt256.ofNat (256 ^ 16 - 1) = uint128Mask by native_decide] - simpa [loc, uint128Int] using - storageLocLoad_uint_offset evm ⟨3⟩ (16 : Fin 32) (16 : Fin 33) ⟨128, by decide⟩ - (by decide) (by decide) - -theorem uniswapV3PoolProtocolFeesSourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) protocolfeesTransition.body - (.returned { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) - (some [Value.int (Int.ofNat (protocolFeesToken0Word σ I).toNat), - Value.int (Int.ofNat (protocolFeesToken1Word σ I).toNat)])) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [.storage (protocolFeesF "token0"), .storage (protocolFeesF "token1")] ] _ - exact ExecFuncBody.execBlockRet <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true (by simp [initState, hwv]))) <| - ExecBlock.consReturn <| ExecStmt.return (by - have hret0 : - evalExpr? (config v) { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) (.storage (protocolFeesF "token0")) = - .ok (.int (Int.ofNat (protocolFeesToken0Word σ I).toNat)) := by - rw [evalExpr_storage_scalar - (t := .int uint128Int) - (slot := protocolFeesF "token0") - (er := { base := "protocolFees", steps := [.field "token0"] }) - (loc := loc ⟨3⟩ ⟨0, by decide⟩ ⟨16, by decide⟩ (by decide) - (.int uint128Int)) - (hbase := by simp [protocolFeesF]) - (her := by - simp [evalStorageRef, evalStorageRefStep, protocolFeesF, EvalResult.bind, - pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, - protocolFeesStructTy, uint128St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [initState, protocolFeesToken0Word, protocolFeesSlotWord, solcSlotWord] using - protocolFeesStorageLocLoad_token0 (initState cA gh bl σ σ₀ g A I) - have hret1 : - evalExpr? (config v) { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) (.storage (protocolFeesF "token1")) = - .ok (.int (Int.ofNat (protocolFeesToken1Word σ I).toNat)) := by - rw [evalExpr_storage_scalar - (t := .int uint128Int) - (slot := protocolFeesF "token1") - (er := { base := "protocolFees", steps := [.field "token1"] }) - (loc := loc ⟨3⟩ ⟨16, by decide⟩ ⟨16, by decide⟩ (by decide) - (.int uint128Int)) - (hbase := by simp [protocolFeesF]) - (her := by - simp [evalStorageRef, evalStorageRefStep, protocolFeesF, EvalResult.bind, - pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, - protocolFeesStructTy, uint128St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [initState, protocolFeesToken1Word, protocolFeesSlotWord, solcSlotWord] using - protocolFeesStorageLocLoad_token1 (initState cA gh bl σ σ₀ g A I) - simp only [Solm.evalExprs?.eq_def, hret0, hret1, EvalResult.bind, bind, pure]) - -theorem uniswapV3PoolProtocolFeesValueTransport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - some [Value.int (Int.ofNat (protocolFeesToken0Word σ_solm I).toNat), - Value.int (Int.ofNat (protocolFeesToken1Word σ_solm I).toNat)] = - some [Value.int (Int.ofNat (protocolFeesToken0Word σ_evm I).toNat), - Value.int (Int.ofNat (protocolFeesToken1Word σ_evm I).toNat)] := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨3⟩ (⟨0⟩ : UInt256) - dsimp [protocolFeesToken0Word, protocolFeesToken1Word, protocolFeesSlotWord, solcSlotWord] - rw [← hslot] - -theorem uniswapV3PoolProtocolFeesBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 3 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_protocolFees (v := v) (cd := I.calldata) hsel - have hdecode := uniswapV3PoolProtocolFeesDecode (v := v) (I := I) hsz - have hbody := uniswapV3PoolProtocolFeesSourceBody (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hvalue := uniswapV3PoolProtocolFeesValueTransport (σ_evm := σ_evm) - (σ_solm := σ_solm) (I := I) hAccounts - have hrd := uniswapV3PoolProtocolFeesEvm (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel - exact hrd.reEquivExecutionTransport hcode hdispatch hdecode hbody hvalue hAccounts - (by - rw [show protocolfeesTransition.returnType = [uint128, uint128] from rfl] - exact returnEquiv.returned rfl - (uint128PairReturnEncodingMasked (protocolFeesSlotWord σ_evm I) - (UInt256.div (protocolFeesSlotWord σ_evm I) protocolFeesShift))) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocol.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocol.lean deleted file mode 100644 index dfd1402b..00000000 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocol.lean +++ /dev/null @@ -1,1873 +0,0 @@ -import Benchmarks.UniswapV3Pool.SetFeeProtocolSuccess - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem setFeeProtocolUint8Mask_toNat : - setFeeProtocolUint8Mask.toNat = 2 ^ 8 - 1 := by - exact ulit_toNat' _ (by norm_num [UInt256.size]) - -theorem setFeeProtocolUint8Mask_decode (w : UInt256) : - (UInt256.land w setFeeProtocolUint8Mask).toNat = w.toNat % EVM.twoPow 8 := by - rw [u256_land_toNat, setFeeProtocolUint8Mask_toNat, nat_land_mask_eq_mod] - exact Nat.mod_eq_of_lt (by - exact lt_trans (Nat.mod_lt _ (by norm_num [EVM.twoPow])) - (by norm_num [EVM.twoPow, UInt256.size])) - -theorem decodeScalarWordWithMode_uint8_ok {bytes : List UInt8} {start : Nat} - (hlen : ((bytes.drop start).take 32).length = 32) : - decodeScalarWordWithMode? DecodeMode.legacySolc05 uint8 bytes start = - some - (.int (Int.ofNat - (UInt256.land (ABI.bytesToWord ((bytes.drop start).take 32)) - setFeeProtocolUint8Mask).toNat), - start + 32) := by - simp only [decodeScalarWordWithMode?] - unfold readWord? readBytes? uint8 uint8Int - rw [if_pos hlen] - simp only [bind, Option.bind] - unfold decodeABIWord? - simp only [OfNat.ofNat_ne_zero, ↓reduceIte] - rw [setFeeProtocolUint8Mask_decode] - rfl - -theorem decodeScalarWordsWithMode_uint8_uint8_ok {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) - (hlen32 : ((bytes.drop 32).take 32).length = 32) : - decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint8, uint8] bytes 0 = - some - [ .int (Int.ofNat - (UInt256.land (ABI.bytesToWord (bytes.take 32)) - setFeeProtocolUint8Mask).toNat), - .int (Int.ofNat - (UInt256.land (ABI.bytesToWord ((bytes.drop 32).take 32)) - setFeeProtocolUint8Mask).toNat) ] := by - simp only [decodeScalarWordsWithMode?] - rw [decodeScalarWordWithMode_uint8_ok (bytes := bytes) (start := 0) (by simpa using hlen0)] - simp only [List.drop_zero, bind, Option.bind] - rw [decodeScalarWordWithMode_uint8_ok (bytes := bytes) (start := 32) hlen32] - -theorem decodeScalarWordsWithMode_uint8_uint8_none_short {bytes : List UInt8} - (hshort : bytes.length < 64) : - decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint8, uint8] bytes 0 = none := by - simp only [decodeScalarWordsWithMode?] - by_cases hlen0 : (bytes.take 32).length = 32 - · rw [decodeScalarWordWithMode_uint8_ok (bytes := bytes) (start := 0) (by simpa using hlen0)] - simp only [bind, Option.bind] - have hlen32 : ¬ ((bytes.drop 32).take 32).length = 32 := by - rw [List.length_take, List.length_drop] - omega - unfold decodeScalarWordWithMode? readWord? readBytes? uint8 uint8Int - rw [if_neg hlen32] - simp only [bind, Option.bind] - · unfold decodeScalarWordWithMode? readWord? readBytes? uint8 uint8Int - simp only [List.drop_zero] - rw [if_neg hlen0] - simp only [bind, Option.bind] - -theorem uniswapV3PoolSetFeeProtocolDecodeOk {v : PoolImmutables} {I : ExecutionEnv} - (hsz68 : 68 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - ((setfeeprotocolTransition v).params.map Param.name) - (transitionSignature (setfeeprotocolTransition v)).paramTypes I.calldata = - some (setFeeProtocolStore I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake4 : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have htake36 : - (((I.calldata.toList.drop 4).drop 32).take 32).length = 32 := by - rw [List.length_take, List.length_drop, List.length_drop, htlen] - omega - have hword4 : ABI.bytesToWord ((I.calldata.toList.drop 4).take 32) = - calldataWord I.calldata 4 := - decode_word_at_eq I.calldata 4 (by omega) (by norm_num) - have hword36 : ABI.bytesToWord ((I.calldata.toList.drop 36).take 32) = - calldataWord I.calldata 36 := by - exact decode_word_at_eq I.calldata 36 (by omega) (by norm_num) - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := (setfeeprotocolTransition v).params.map Param.name) - (types := (transitionSignature (setfeeprotocolTransition v)).paramTypes) - (cd := I.calldata)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint8, uint8] - (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["feeProtocol0", "feeProtocol1"] values ∅ - | none => none) = some (setFeeProtocolStore I) - rw [decodeScalarWordsWithMode_uint8_uint8_ok - (bytes := I.calldata.toList.drop 4) htake4 htake36] - simp [decodeCalldata.insertValues, setFeeProtocolStore, setFeeProtocolArg0Value, - setFeeProtocolArg1Value, setFeeProtocolArg0Word, setFeeProtocolArg1Word] - rw [hword4, hword36] - · simp [setfeeprotocolTransition, transitionSignature, isABIScalarWordType, uint8] - -theorem uniswapV3PoolSetFeeProtocolDecodeShort {v : PoolImmutables} {I : ExecutionEnv} - (hshort : I.calldata.size < 68) : - decodeCalldataWithMode (config v).abiDecodeMode - ((setfeeprotocolTransition v).params.map Param.name) - (transitionSignature (setfeeprotocolTransition v)).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := (setfeeprotocolTransition v).params.map Param.name) - (types := (transitionSignature (setfeeprotocolTransition v)).paramTypes) - (cd := I.calldata)] - · by_cases hsz4 : I.calldata.size < 4 - · rw [if_pos (by rw [htlen]; omega : I.calldata.toList.length < 4)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 [uint8, uint8] - (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["feeProtocol0", "feeProtocol1"] values ∅ - | none => none) = none - rw [decodeScalarWordsWithMode_uint8_uint8_none_short - (bytes := I.calldata.toList.drop 4) - (by rw [List.length_drop, htlen]; omega)] - · simp [setfeeprotocolTransition, transitionSignature, isABIScalarWordType, uint8] - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolDispatch_setFeeProtocol {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 14 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some (setfeeprotocolTransition v) := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, - factoryTransition v, feeTransition v, feegrowthglobal0X128Transition, - feegrowthglobal1X128Transition, flashTransition v, - increaseobservationcardinalitynextTransition v, initializeTransition, liquidityTransition, - maxliquiditypertickTransition v, mintTransition v, observationsTransition, - observeTransition v, positionsTransition, protocolfeesTransition]) - (post := [slot0Transition, snapshotcumulativesinsideTransition v, swapTransition v, - tickbitmapTransition, tickspacingTransition v, ticksTransition, token0Transition v, - token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 14) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 14) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 14) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 14) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 14) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 14) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 14) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 14) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 5) (j := 14) - (by native_decide) hsel - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 25) (j := 14) - (by native_decide) hsel - · rw [selectorOf, liquiditySelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 2) (j := 14) - (by native_decide) hsel - · rw [selectorOf, maxLiquidityPerTickSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 13) (j := 14) - (by native_decide) hsel - · rw [selectorOf, mintSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 7) (j := 14) - (by native_decide) hsel - · rw [selectorOf, observationsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 4) (j := 14) - (by native_decide) hsel - · rw [selectorOf, observeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 16) (j := 14) - (by native_decide) hsel - · rw [selectorOf, positionsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 11) (j := 14) - (by native_decide) hsel - · rw [selectorOf, protocolFeesSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 3) (j := 14) - (by native_decide) hsel - · rw [selectorOf, setFeeProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hsel - -private theorem uniswapV3PoolPatchPreservesJumpDest8208 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨8208⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest8276 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨8276⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched8208 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨8208⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest8208 - -theorem uniswapV3PoolJumpDestPatched8276 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨8276⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest8276 - -theorem uniswapV3PoolSetFeeProtocolReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 14 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1486⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 14 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0x82 0x06 0xa4 0xd1 - (uniswapV3PoolSelNat 14) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h43 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨43⟩) hpatch h32 hgt32 - have hgt43 : UInt256.gt (armSelNat code ⟨43⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h152 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨152⟩) hpatch h43 hgt43 - have hgt152 : UInt256.gt (armSelNat code ⟨152⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h201 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨201⟩) hpatch h152 hgt152 - have hmiss13 : (uniswapV3PoolSelBytes 13 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h212 := uniswapV3PoolSelectorArmMissToOf (i := 13) (next := ⟨212⟩) - hpatch hsz hmiss13 h201 - have h1486 := uniswapV3PoolSelectorArmHitTo (i := 14) (target := ⟨1486⟩) - hpatch hsz hsel h212 - exact ⟨_, _, h1486⟩ - -set_option maxHeartbeats 3000000 in -private theorem uniswapV3PoolSetFeeProtocolExternalLenOk {v : PoolImmutables} - {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hreach : ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1486⟩ - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hsz68 : 68 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1508⟩ - (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩ :: ⟨4⟩ :: ⟨857⟩ :: - [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact RD.solcExternalStaticArgsLenOk (need := ⟨64⟩) - (entry := ⟨1486⟩) (ret := ⟨857⟩) (decoded := ⟨1508⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (solcDecodeLenCheckOkUnsigned (by simpa using hsz68) hsize) - -private theorem uniswapV3PoolSetFeeProtocolDecodedReachRoutine {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {de ret : UInt256} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨1508⟩ (de :: ⟨4⟩ :: ret :: R) mem aw rdata acc k C) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8208⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: ret :: R) - mem aw rdata acc k' C' := by - have harg0 : - UInt256.land setFeeProtocolUint8Mask (calldataWord ee.calldata 4) = - setFeeProtocolArg0Word ee := by - rw [u256_land_comm] - have rd1509 : RD code ee g s0 ⟨1509⟩ (de :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1) (C + 1) := by - simpa using h.jumpdest - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1510 : RD code ee g s0 ⟨1510⟩ (⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1) (C + 1 + 2) := by - simpa using rd1509.pop - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1512 : RD code ee g s0 ⟨1512⟩ (setFeeProtocolUint8Mask :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1) (C + 1 + 2 + 3) := by - simpa [setFeeProtocolUint8Mask] using rd1510.push1 ⟨255⟩ - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1513 : RD code ee g s0 ⟨1513⟩ - (⟨4⟩ :: setFeeProtocolUint8Mask :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3) := by - simpa using rd1512.dup2 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1514 : RD code ee g s0 ⟨1514⟩ - (calldataWord ee.calldata 4 :: setFeeProtocolUint8Mask :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3 + 3) := by - simpa [calldataWord, show (⟨4⟩ : UInt256).toNat = 4 from by decide] using - (rd1513.calldataload - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov)) - have rd1515 : RD code ee g s0 ⟨1515⟩ - (setFeeProtocolUint8Mask :: calldataWord ee.calldata 4 :: - setFeeProtocolUint8Mask :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1) - (C + 1 + 2 + 3 + 3 + 3 + 3) := by - simpa using rd1514.dup2 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1516 : RD code ee g s0 ⟨1516⟩ - (setFeeProtocolArg0Word ee :: setFeeProtocolUint8Mask :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 1 + 2 + 3 + 3 + 3 + 3 + 3) := by - simpa [harg0] using rd1515.and - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1517 : RD code ee g s0 ⟨1517⟩ - (⟨4⟩ :: setFeeProtocolUint8Mask :: setFeeProtocolArg0Word ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 1 + 2 + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa using rd1516.swap2 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1519 : RD code ee g s0 ⟨1519⟩ - (⟨32⟩ :: ⟨4⟩ :: setFeeProtocolUint8Mask :: setFeeProtocolArg0Word ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 1 + 2 + 3 + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa using rd1517.push1 ⟨32⟩ - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1520 : RD code ee g s0 ⟨1520⟩ - (⟨36⟩ :: setFeeProtocolUint8Mask :: setFeeProtocolArg0Word ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 1 + 2 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa using rd1519.add - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1521 : RD code ee g s0 ⟨1521⟩ - (calldataWord ee.calldata 36 :: setFeeProtocolUint8Mask :: - setFeeProtocolArg0Word ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 1 + 2 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa [calldataWord, show (⟨36⟩ : UInt256).toNat = 36 from by decide] using - (rd1520.calldataload - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov)) - have rd1522 : RD code ee g s0 ⟨1522⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: ret :: R) - mem aw rdata acc - (k + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 1 + 2 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa [setFeeProtocolArg1Word] using rd1521.and - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1525 : RD code ee g s0 ⟨1525⟩ - (⟨8208⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: ret :: R) - mem aw rdata acc - (k + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) - (C + 1 + 2 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3) := by - simpa using rd1522.push2 ⟨8208⟩ - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - exact ⟨_, _, rd1525.jump - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (uniswapV3PoolJumpDestPatched8208 hpatch) - (by evm_ov)⟩ - -private theorem uniswapV3PoolSetFeeProtocolPatchDisjoint1 {v : PoolImmutables} - {pc : UInt256} (hlo : 8208 ≤ pc.toNat) (hhi : pc.toNat + 1 ≤ 8315) : - ∀ p ∈ patches v, pc.toNat + 1 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolSetFeeProtocolPatchDisjoint2 {v : PoolImmutables} - {pc : UInt256} (hlo : 8208 ≤ pc.toNat) (hhi : pc.toNat + 2 ≤ 8315) : - ∀ p ∈ patches v, pc.toNat + 2 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolSetFeeProtocolPatchDisjoint3 {v : PoolImmutables} - {pc : UInt256} (hlo : 8208 ≤ pc.toNat) (hhi : pc.toNat + 3 ≤ 8315) : - ∀ p ∈ patches v, pc.toNat + 3 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolSetFeeProtocolPatchDisjoint4 {v : PoolImmutables} - {pc : UInt256} (hlo : 8208 ≤ pc.toNat) (hhi : pc.toNat + 4 ≤ 8315) : - ∀ p ∈ patches v, pc.toNat + 4 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl - all_goals omega - -private theorem uniswapV3PoolSetFeeProtocolPatchDisjoint5 {v : PoolImmutables} - {pc : UInt256} (hlo : 8208 ≤ pc.toNat) (hhi : pc.toNat + 5 ≤ 8315) : - ∀ p ∈ patches v, pc.toNat + 5 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl - all_goals omega - -private theorem uniswapV3PoolSetFeeProtocolPatchDisjointAfterFactory1 {v : PoolImmutables} - {pc : UInt256} (hlo : 8347 ≤ pc.toNat) (hhi : pc.toNat + 1 ≤ 8829) : - ∀ p ∈ patches v, pc.toNat + 1 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolSetFeeProtocolPatchDisjointAfterFactory2 {v : PoolImmutables} - {pc : UInt256} (hlo : 8347 ≤ pc.toNat) (hhi : pc.toNat + 2 ≤ 8829) : - ∀ p ∈ patches v, pc.toNat + 2 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolSetFeeProtocolPatchDisjointAfterFactory3 {v : PoolImmutables} - {pc : UInt256} (hlo : 8347 ≤ pc.toNat) (hhi : pc.toNat + 3 ≤ 8829) : - ∀ p ∈ patches v, pc.toNat + 3 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolSetFeeProtocolPatchDisjointAfterFactory4 {v : PoolImmutables} - {pc : UInt256} (hlo : 8347 ≤ pc.toNat) (hhi : pc.toNat + 4 ≤ 8829) : - ∀ p ∈ patches v, pc.toNat + 4 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolSetFeeProtocolPatchDisjointAfterFactory5 {v : PoolImmutables} - {pc : UInt256} (hlo : 8347 ≤ pc.toNat) (hhi : pc.toNat + 5 ≤ 8829) : - ∀ p ∈ patches v, pc.toNat + 5 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolSetFeeProtocolDecodePatchedPush1 {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 2 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 2 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x60) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1)) = n) : - decode code pc = some (.Push .PUSH1, some (n, 1)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + 1) = - uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1) := by - unfold ByteArray.extract' - have hguard : - (decide (pc.toNat.succ < 2 ^ 64) && decide (pc.toNat.succ + 1 < 2 ^ 64)) = - true := by - rw [Bool.and_eq_true] - constructor <;> rw [decide_eq_true_eq] <;> omega - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq (start := pc.toNat.succ) (stop := pc.toNat.succ + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl hbefore - · exact Or.inr (by omega)) - hpatch - have hgetSome : code.get? pc.toNat = some 0x60 := by - rw [hget, hgetTemplate] - have hparse : (some (0x60 : UInt8) >>= parseInstr) = some (.Push .PUSH1) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH1, - some (uInt256OfByteArray (code.extract' pc.toNat.succ (pc.toNat.succ + 1)), 1)) = - some (Operation.Push Operation.POp.PUSH1, some (n, 1)) - rw [hextract, hval] - -private theorem uniswapV3PoolSetFeeProtocolDecodePatchedPush2 {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 3 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 3 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x61) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 2)) = n) : - decode code pc = some (.Push .PUSH2, some (n, 2)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + 2) = - uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 2) := by - unfold ByteArray.extract' - have hguard : - (decide (pc.toNat.succ < 2 ^ 64) && decide (pc.toNat.succ + 2 < 2 ^ 64)) = - true := by - rw [Bool.and_eq_true] - constructor <;> rw [decide_eq_true_eq] <;> omega - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq (start := pc.toNat.succ) (stop := pc.toNat.succ + 2) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl hbefore - · exact Or.inr (by omega)) - hpatch - have hgetSome : code.get? pc.toNat = some 0x61 := by - rw [hget, hgetTemplate] - have hparse : (some (0x61 : UInt8) >>= parseInstr) = some (.Push .PUSH2) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH2, - some (uInt256OfByteArray (code.extract' pc.toNat.succ (pc.toNat.succ + 2)), 2)) = - some (Operation.Push Operation.POp.PUSH2, some (n, 2)) - rw [hextract, hval] - -private theorem uniswapV3PoolSetFeeProtocolDecodePatchedPush3 {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 4 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 4 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x62) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 3)) = n) : - decode code pc = some (.Push .PUSH3, some (n, 3)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + 3) = - uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 3) := by - unfold ByteArray.extract' - have hguard : - (decide (pc.toNat.succ < 2 ^ 64) && decide (pc.toNat.succ + 3 < 2 ^ 64)) = - true := by - rw [Bool.and_eq_true] - constructor <;> rw [decide_eq_true_eq] <;> omega - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq (start := pc.toNat.succ) (stop := pc.toNat.succ + 3) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl hbefore - · exact Or.inr (by omega)) - hpatch - have hgetSome : code.get? pc.toNat = some 0x62 := by - rw [hget, hgetTemplate] - have hparse : (some (0x62 : UInt8) >>= parseInstr) = some (.Push .PUSH3) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH3, - some (uInt256OfByteArray (code.extract' pc.toNat.succ (pc.toNat.succ + 3)), 3)) = - some (Operation.Push Operation.POp.PUSH3, some (n, 3)) - rw [hextract, hval] - -private theorem uniswapV3PoolSetFeeProtocolDecodePatchedPush4 {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 5 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 5 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x63) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 4)) = n) : - decode code pc = some (.Push .PUSH4, some (n, 4)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + 4) = - uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 4) := by - unfold ByteArray.extract' - have hguard : - (decide (pc.toNat.succ < 2 ^ 64) && decide (pc.toNat.succ + 4 < 2 ^ 64)) = - true := by - rw [Bool.and_eq_true] - constructor <;> rw [decide_eq_true_eq] <;> omega - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq (start := pc.toNat.succ) (stop := pc.toNat.succ + 4) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl hbefore - · exact Or.inr (by omega)) - hpatch - have hgetSome : code.get? pc.toNat = some 0x63 := by - rw [hget, hgetTemplate] - have hparse : (some (0x63 : UInt8) >>= parseInstr) = some (.Push .PUSH4) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH4, - some (uInt256OfByteArray (code.extract' pc.toNat.succ (pc.toNat.succ + 4)), 4)) = - some (Operation.Push Operation.POp.PUSH4, some (n, 4)) - rw [hextract, hval] - -private theorem uniswapV3PoolSetFeeProtocolLockedRevertTailWf {v : PoolImmutables} - {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcErrorStringRevertTailWf code ⟨8226⟩ ⟨3⟩ ⟨5001035⟩ ⟨232⟩ .PUSH3 3 := by - repeat' constructor - · exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8226⟩) (n := ⟨64⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8228⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8229⟩) (byte := 0x51) - (op := .MLOAD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · exact uniswapV3PoolSetFeeProtocolDecodePatchedPush3 (pc := ⟨8230⟩) - (n := ⟨4594637⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint4 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8234⟩) (n := ⟨229⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8236⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8237⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8238⟩) (byte := 0x52) - (op := .MSTORE) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8239⟩) (n := ⟨32⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8241⟩) (n := ⟨4⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8243⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8244⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8245⟩) (byte := 0x52) - (op := .MSTORE) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8246⟩) (n := ⟨3⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8248⟩) (n := ⟨36⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8250⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8251⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8252⟩) (byte := 0x52) - (op := .MSTORE) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · exact uniswapV3PoolSetFeeProtocolDecodePatchedPush3 (pc := ⟨8253⟩) - (n := ⟨5001035⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint4 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8257⟩) (n := ⟨232⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8259⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8260⟩) (n := ⟨68⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8262⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8263⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8264⟩) (byte := 0x52) - (op := .MSTORE) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8265⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8266⟩) (byte := 0x51) - (op := .MLOAD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8267⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8268⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8269⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8270⟩) (byte := 0x03) - (op := .SUB) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8271⟩) (n := ⟨100⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8273⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8274⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8275⟩) (byte := 0xfd) - (op := .REVERT) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - -private theorem uniswapV3PoolSetFeeProtocolLockEnterOk {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8208⟩ R mem aw rdata (cA, σ) k C) - (hperm : ee.perm = true) - (hunlocked : setFeeProtocolUnlockedByte σ ee ≠ ⟨0⟩) - (hov : R.length + 4 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8290⟩ R mem aw rdata - (cA, sstoreAccountMap ee.codeOwner σ ⟨0⟩ (setFeeProtocolLockedSlotWord σ ee)) k' C' := by - have hd8208 : decode code ⟨8208⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8208⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8209 : decode code ⟨8209⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8209⟩) (n := ⟨0⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8211 : decode code ⟨8211⟩ = some (.SLOAD, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8211⟩) (byte := 0x54) - (op := .SLOAD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8212 : decode code ⟨8212⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8212⟩) (n := ⟨1⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8214 : decode code ⟨8214⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8214⟩) (n := ⟨240⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8216 : decode code ⟨8216⟩ = some (.SHL, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8216⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8217 : decode code ⟨8217⟩ = some (.SWAP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8217⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8218 : decode code ⟨8218⟩ = some (.DIV, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8218⟩) (byte := 0x04) - (op := .DIV) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8219 : decode code ⟨8219⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8219⟩) (n := ⟨255⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8221 : decode code ⟨8221⟩ = some (.AND, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8221⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8222 : decode code ⟨8222⟩ = some (.Push .PUSH2, some (⟨8276⟩, 2)) := by - exact uniswapV3PoolSetFeeProtocolDecodePatchedPush2 (pc := ⟨8222⟩) (n := ⟨8276⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint3 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8225 : decode code ⟨8225⟩ = some (.JUMPI, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8225⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8276 : decode code ⟨8276⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8276⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8277 : decode code ⟨8277⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8277⟩) (n := ⟨0⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8279 : decode code ⟨8279⟩ = some (.DUP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8279⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8280 : decode code ⟨8280⟩ = some (.SLOAD, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8280⟩) (byte := 0x54) - (op := .SLOAD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8281 : decode code ⟨8281⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8281⟩) (n := ⟨255⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8283 : decode code ⟨8283⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8283⟩) (n := ⟨240⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8285 : decode code ⟨8285⟩ = some (.SHL, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8285⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8286 : decode code ⟨8286⟩ = some (.NOT, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8286⟩) (byte := 0x19) - (op := .NOT) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8287 : decode code ⟨8287⟩ = some (.AND, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8287⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8288 : decode code ⟨8288⟩ = some (.SWAP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8288⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8289 : decode code ⟨8289⟩ = some (.SSTORE, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8289⟩) (byte := 0x55) - (op := .SSTORE) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have rd8209 : RD code ee g s0 ⟨8209⟩ R mem aw rdata (cA, σ) (k + 1) (C + 1) := by - simpa using h.jumpdest - hd8208 - (by evm_ov) - have rd8211 : RD code ee g s0 ⟨8211⟩ (⟨0⟩ :: R) mem aw rdata (cA, σ) - (k + 1 + 1) (C + 1 + 3) := by - simpa using rd8209.push1 ⟨0⟩ - hd8209 - (by evm_ov) - obtain ⟨_, _, rd8212₀⟩ := rd8211.sload - hd8211 - (by evm_ov) - have rd8212 := by - simpa [solcSlotWord] using rd8212₀ - have rd8214 := by - simpa using rd8212.push1 ⟨1⟩ - hd8212 - (by evm_ov) - have rd8216 := by - simpa using rd8214.push1 ⟨240⟩ - hd8214 - (by evm_ov) - have rd8217 := by - simpa [setFeeProtocolUnlockedShift] using rd8216.shl - hd8216 - (by evm_ov) - have rd8218 := by - simpa using rd8217.swap1 - hd8217 - (by evm_ov) - have rd8219 := by - simpa using rd8218.div - hd8218 - (by evm_ov) - have rd8221 := by - simpa [setFeeProtocolUint8Mask] using rd8219.push1 ⟨255⟩ - hd8219 - (by evm_ov) - have rd8222 := by - simpa [setFeeProtocolUnlockedByte] using rd8221.and - hd8221 - (by evm_ov) - have rd8225 := by - simpa using rd8222.push2 ⟨8276⟩ - hd8222 - (by evm_ov) - have rd8276 := rd8225.jumpiT - hd8225 - hunlocked - (uniswapV3PoolJumpDestPatched8276 hpatch) - (by evm_ov) - have rd8277 := by - simpa using rd8276.jumpdest - hd8276 - (by evm_ov) - have rd8279 := by - simpa using rd8277.push1 ⟨0⟩ - hd8277 - (by evm_ov) - have rd8280 := by - simpa using rd8279.dup1 - hd8279 - (by evm_ov) - obtain ⟨_, _, rd8281₀⟩ := rd8280.sload - hd8280 - (by evm_ov) - have rd8281 := by - simpa [solcSlotWord] using rd8281₀ - have rd8283 := by - simpa [setFeeProtocolUint8Mask] using rd8281.push1 ⟨255⟩ - hd8281 - (by evm_ov) - have rd8285 := by - simpa using rd8283.push1 ⟨240⟩ - hd8283 - (by evm_ov) - have rd8286 := by - simpa using rd8285.shl - hd8285 - (by evm_ov) - have rd8287 := by - simpa [setFeeProtocolUnlockedClearMask] using rd8286.not - hd8286 - (by evm_ov) - have rd8288 := by - simpa [setFeeProtocolLockedSlotWord] using rd8287.and - hd8287 - (by evm_ov) - have rd8289 := by - simpa using rd8288.swap1 - hd8288 - (by evm_ov) - exact rd8289.sstore hperm - hd8289 - (by evm_ov) - -private theorem uniswapV3PoolSetFeeProtocolLockEnterLockedRevert {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8208⟩ R solcFreePtrMem (UInt256.ofNat 3) rdata - (cA, σ) k C) - (hlocked : setFeeProtocolUnlockedByte σ ee = ⟨0⟩) - (hov : R.length + 6 ≤ 1024) : - RDrev code g s0 := by - have hd8208 : decode code ⟨8208⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8208⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8209 : decode code ⟨8209⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8209⟩) (n := ⟨0⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8211 : decode code ⟨8211⟩ = some (.SLOAD, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8211⟩) (byte := 0x54) - (op := .SLOAD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8212 : decode code ⟨8212⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8212⟩) (n := ⟨1⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8214 : decode code ⟨8214⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8214⟩) (n := ⟨240⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8216 : decode code ⟨8216⟩ = some (.SHL, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8216⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8217 : decode code ⟨8217⟩ = some (.SWAP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8217⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8218 : decode code ⟨8218⟩ = some (.DIV, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8218⟩) (byte := 0x04) - (op := .DIV) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8219 : decode code ⟨8219⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolDecodePatchedPush1 (pc := ⟨8219⟩) (n := ⟨255⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8221 : decode code ⟨8221⟩ = some (.AND, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8221⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8222 : decode code ⟨8222⟩ = some (.Push .PUSH2, some (⟨8276⟩, 2)) := by - exact uniswapV3PoolSetFeeProtocolDecodePatchedPush2 (pc := ⟨8222⟩) (n := ⟨8276⟩) - hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint3 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8225 : decode code ⟨8225⟩ = some (.JUMPI, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8225⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have rd8209 : RD code ee g s0 ⟨8209⟩ R solcFreePtrMem (UInt256.ofNat 3) rdata - (cA, σ) (k + 1) (C + 1) := by - simpa using h.jumpdest - hd8208 - (by evm_ov) - have rd8211 : RD code ee g s0 ⟨8211⟩ (⟨0⟩ :: R) solcFreePtrMem - (UInt256.ofNat 3) rdata (cA, σ) (k + 1 + 1) (C + 1 + 3) := by - simpa using rd8209.push1 ⟨0⟩ - hd8209 - (by evm_ov) - obtain ⟨_, _, rd8212₀⟩ := rd8211.sload - hd8211 - (by evm_ov) - have rd8212 := by - simpa [solcSlotWord] using rd8212₀ - have rd8214 := by - simpa using rd8212.push1 ⟨1⟩ - hd8212 - (by evm_ov) - have rd8216 := by - simpa using rd8214.push1 ⟨240⟩ - hd8214 - (by evm_ov) - have rd8217 := by - simpa [setFeeProtocolUnlockedShift] using rd8216.shl - hd8216 - (by evm_ov) - have rd8218 := by - simpa using rd8217.swap1 - hd8217 - (by evm_ov) - have rd8219 := by - simpa using rd8218.div - hd8218 - (by evm_ov) - have rd8221 := by - simpa [setFeeProtocolUint8Mask] using rd8219.push1 ⟨255⟩ - hd8219 - (by evm_ov) - have rd8222 := by - simpa [setFeeProtocolUnlockedByte] using rd8221.and - hd8221 - (by evm_ov) - have rd8225 := by - simpa using rd8222.push2 ⟨8276⟩ - hd8222 - (by evm_ov) - have rd8226 := rd8225.jumpiNT - hd8225 - hlocked - (by evm_ov) - exact RD.solcErrorStringRevertTail - (pc := ⟨8226⟩) (len := ⟨3⟩) (rawWord := ⟨5001035⟩) (shift := ⟨232⟩) - (word := UInt256.shiftLeft ⟨5001035⟩ ⟨232⟩) (op := .PUSH3) (width := 3) - rd8226 - (uniswapV3PoolSetFeeProtocolLockedRevertTailWf hpatch) - (by native_decide) - rfl - solcFreePtrMem_size - solcFreePtrMem_read64 - (by omega) - -private theorem uniswapV3PoolSetFeeProtocolEvmAfterLock {v : PoolImmutables} - {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hperm : I.perm = true) - (hsel : (uniswapV3PoolSelBytes 14 == I.calldata.extract 0 4) = true) - (hsz68 : 68 ≤ I.calldata.size) - (hunlocked : setFeeProtocolUnlockedByte σ I ≠ ⟨0⟩) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨8290⟩ - (setFeeProtocolArg1Word I :: setFeeProtocolArg0Word I :: ⟨857⟩ :: - [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty - (cA, sstoreAccountMap I.codeOwner σ ⟨0⟩ (setFeeProtocolLockedSlotWord σ I)) k C := by - have hreach := uniswapV3PoolSetFeeProtocolReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - obtain ⟨_, _, rdDecoded⟩ := - uniswapV3PoolSetFeeProtocolExternalLenOk hpatch hreach hsz68 hsize - obtain ⟨_, _, rdRoutine⟩ := - uniswapV3PoolSetFeeProtocolDecodedReachRoutine hpatch rdDecoded - (by simp only [List.length_singleton]; omega) - exact uniswapV3PoolSetFeeProtocolLockEnterOk hpatch rdRoutine hperm hunlocked - (by simp only [List.length_cons, List.length_nil]; omega) - -theorem uniswapV3PoolSetFeeProtocolEvmLocked {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 14 == I.calldata.extract 0 4) = true) - (hsz68 : 68 ≤ I.calldata.size) - (hlocked : setFeeProtocolUnlockedByte σ I = ⟨0⟩) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - have hreach := uniswapV3PoolSetFeeProtocolReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - obtain ⟨_, _, rdDecoded⟩ := - uniswapV3PoolSetFeeProtocolExternalLenOk hpatch hreach hsz68 hsize - obtain ⟨_, _, rdRoutine⟩ := - uniswapV3PoolSetFeeProtocolDecodedReachRoutine hpatch rdDecoded - (by simp only [List.length_singleton]; omega) - exact uniswapV3PoolSetFeeProtocolLockEnterLockedRevert hpatch rdRoutine hlocked - (by simp only [List.length_cons, List.length_nil]; omega) - -theorem uniswapV3PoolSetFeeProtocolEvmDecodeShort {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 14 == I.calldata.extract 0 4) = true) - (hshort : I.calldata.size < 68) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - have hreach := uniswapV3PoolSetFeeProtocolReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - have hlt : - UInt256.lt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨64⟩ = ⟨1⟩ := by - apply ult_one - rw [usub_ofNat_word_toNat (by - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega) hsize] - rw [show (⟨64⟩ : UInt256).toNat = 64 from by decide] - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega - exact RD.solcExternalStaticArgsShortReverts (need := ⟨64⟩) - (entry := ⟨1486⟩) (ret := ⟨857⟩) (decoded := ⟨1508⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - hlt - -theorem uniswapV3PoolSetFeeProtocolBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 14 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_setFeeProtocol (v := v) (cd := I.calldata) hsel - by_cases hsz68 : 68 ≤ I.calldata.size - · have hdecode := uniswapV3PoolSetFeeProtocolDecodeOk (v := v) (I := I) hsz68 - by_cases hunlocked : setFeeProtocolUnlockedByte σ_evm I ≠ ⟨0⟩ - · obtain ⟨kLock, CLock, hrdAfterLock⟩ := - uniswapV3PoolSetFeeProtocolEvmAfterLock (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize _hperm hsel - hsz68 hunlocked - have hunlockedSolm : setFeeProtocolUnlockedByte σ_solm I ≠ ⟨0⟩ := by - rw [setFeeProtocolUnlockedByte_transport (σ_evm := σ_evm) (σ_solm := σ_solm) - hAccounts] - exact hunlocked - have hsourceLock := uniswapV3PoolSetFeeProtocolSourceLockPrefixExact (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm - have hlockedWord : - setFeeProtocolLockedSlotWord σ_solm I = - setFeeProtocolLockedSlotWord σ_evm I := - setFeeProtocolLockedSlotWord_transport (σ_evm := σ_evm) (σ_solm := σ_solm) - hAccounts - have hAccountsAfterLock : - accountMapEquiv - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_evm I)) - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_solm I)) := by - rw [hlockedWord] - exact accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_evm I) hAccounts - obtain ⟨kOwnerSetup, COwnerSetup, hrdOwnerSetup⟩ := - uniswapV3PoolSetFeeProtocolOwnerCallSetup (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [setFeeProtocolArg1Word I, setFeeProtocolArg0Word I, ⟨857⟩, - solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_evm I)) - hpatch hrdAfterLock - (by simp only [List.length_cons, List.length_nil]; omega) - obtain ⟨kOwnerGuard, COwnerGuard, hrdOwnerGuard⟩ := - uniswapV3PoolSetFeeProtocolOwnerCallGuardSetup (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [setFeeProtocolArg1Word I, setFeeProtocolArg0Word I, ⟨857⟩, - solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_evm I)) - hpatch hrdOwnerSetup - (by simp only [List.length_cons, List.length_nil]; omega) - by_cases hfactoryCode : - Reasoning.Theory.extCodeSizeWord - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_evm I)) - (setFeeProtocolFactoryWord v) ≠ ⟨0⟩ - · have hfactoryCodeSolm : - Reasoning.Theory.extCodeSizeWord - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_solm I)) - (setFeeProtocolFactoryWord v) ≠ ⟨0⟩ := by - rw [← extCodeSizeWord_accountMapEquiv hAccountsAfterLock - (setFeeProtocolFactoryWord v)] - exact hfactoryCode - let evmLockSolm := - initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_solm I)) σ₀ (Sat256.ofUInt256 g) A I - have hfactoryGuardSolm : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } - evmLockSolm - (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)) = - .ok (.bool true) := by - exact evalExpr_setFeeProtocol_factoryExtCodeSizeGuard_true (v := v) - (evm := evmLockSolm) (I := I) (by simpa [evmLockSolm, initState]) - by_cases hdepth : I.depth.val < 1024 - · obtain ⟨cAOwner, σOwnerEvm, zOwner, oOwner, AOwnerEvm, - kOwnerCall, COwnerCall, hrdOwnerCall, hcallOwnerEvm, hoOwnerSize⟩ := - uniswapV3PoolSetFeeProtocolOwnerTypedStaticcallMade (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) - (σ := sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_evm I)) - (σ₀ := σ₀) (A := A) (I := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [setFeeProtocolArg1Word I, setFeeProtocolArg0Word I, ⟨857⟩, - solcSelectorWord I]) - (rdata := ByteArray.empty) hpatch (by rfl) (by rfl) (by rfl) - hrdOwnerGuard hfactoryCode hdepth - (by simp only [List.length_cons, List.length_nil]; omega) - obtain ⟨σOwnerSolm, AOwnerSolm, hcallOwnerSolm, hAccountsOwner⟩ := - typedCallViaEVM_initState_accountMapEquiv (hcall := hcallOwnerEvm) - hAccountsAfterLock - obtain ⟨hOwnerStatusOk, hOwnerStatusRevert⟩ := - uniswapV3PoolSetFeeProtocolOwnerStaticcallStatusGuard (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [setFeeProtocolArg1Word I, setFeeProtocolArg0Word I, ⟨857⟩, - solcSelectorWord I]) - (o := oOwner) (mem := setFeeProtocolOwnerStaticcallMem oOwner) - (aw := setFeeProtocolOwnerStaticcallActiveWords) (acc := (cAOwner, σOwnerEvm)) - hpatch hrdOwnerCall hoOwnerSize - (by simp only [List.length_cons, List.length_nil]; omega) - by_cases hzOwner : zOwner = true - · obtain ⟨kOwnerStatus, COwnerStatus, hrdOwnerStatus⟩ := - hOwnerStatusOk hzOwner - by_cases hownerShort : oOwner.size < 32 - · have hrdOwnerDecodeShort := - uniswapV3PoolSetFeeProtocolOwnerReturnDecodeShortReverts (v := v) - (code := code) (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [setFeeProtocolArg1Word I, setFeeProtocolArg0Word I, ⟨857⟩, - solcSelectorWord I]) - (o := oOwner) (acc := (cAOwner, σOwnerEvm)) - hpatch hrdOwnerStatus hownerShort hoOwnerSize - (by simp only [List.length_cons, List.length_nil]; omega) - have hcallOwnerSolmTrue : - typedCallViaEVM (config v) - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_solm I)) σ₀ (Sat256.ofUInt256 g) A I) - (EVM.address (AccountAddress.ofNat v.factory.toNat)) "owner" 0 [] - (true, { initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_solm I)) σ₀ - (Sat256.ofUInt256 g) A I with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }, oOwner) false := by - simpa [hzOwner] using hcallOwnerSolm - have hownerRevert := - uniswapV3PoolSetFeeProtocolSourceOwnerCallDecodeRevert (v := v) - (evm := evmLockSolm) - (evm' := { evmLockSolm with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }) - (I := I) (out := oOwner) hfactoryGuardSolm - (by simpa [evmLockSolm] using hcallOwnerSolmTrue) - (setFeeProtocolOwnerDecodeNoneShort (v := v) hownerShort) - have hbody := - uniswapV3PoolSetFeeProtocolSourceOwnerCallRevertBody (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm - hownerRevert - exact hrdOwnerDecodeShort.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hownerSize32 : 32 ≤ oOwner.size := Nat.le_of_not_gt hownerShort - obtain ⟨kOwnerDecode, COwnerDecode, hrdOwnerDecode⟩ := - uniswapV3PoolSetFeeProtocolOwnerReturnDecodeOk (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [setFeeProtocolArg1Word I, setFeeProtocolArg0Word I, ⟨857⟩, - solcSelectorWord I]) - (o := oOwner) (acc := (cAOwner, σOwnerEvm)) - hpatch hrdOwnerStatus hownerSize32 hoOwnerSize - (by simp only [List.length_cons, List.length_nil]; omega) - have hcallOwnerSolmTrue : - typedCallViaEVM (config v) - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_solm I)) σ₀ (Sat256.ofUInt256 g) A I) - (EVM.address (AccountAddress.ofNat v.factory.toNat)) "owner" 0 [] - (true, { initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_solm I)) σ₀ - (Sat256.ofUInt256 g) A I with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }, oOwner) false := by - simpa [hzOwner] using hcallOwnerSolm - have hownerCallOk := - uniswapV3PoolSetFeeProtocolSourceOwnerCallSuccess (v := v) - (evm := evmLockSolm) - (evm' := { evmLockSolm with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }) - (I := I) (out := oOwner) - (value := [Value.address - (AccountAddress.ofNat - (UInt256.ofNat (fromByteArrayBigEndian (oOwner.extract 0 32))).toNat)]) - hfactoryGuardSolm - (by simpa [evmLockSolm] using hcallOwnerSolmTrue) - (setFeeProtocolOwnerDecodeOk (v := v) hownerSize32) - by_cases hownerCaller : - UInt256.land solcAddrMask (setFeeProtocolOwnerWord oOwner) = solcSourceWord I - · obtain ⟨kOwnerCaller, COwnerCaller, hrdOwnerCaller⟩ := - uniswapV3PoolSetFeeProtocolOwnerCallerGuardOk (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [setFeeProtocolArg1Word I, setFeeProtocolArg0Word I, ⟨857⟩, - solcSelectorWord I]) - (owner := setFeeProtocolOwnerWord oOwner) - (mem := setFeeProtocolOwnerStaticcallMem oOwner) - (aw := setFeeProtocolOwnerStaticcallActiveWords) (rdata := oOwner) - (acc := (cAOwner, σOwnerEvm)) hpatch - (by simpa [setFeeProtocolOwnerWord] using hrdOwnerDecode) - hownerCaller - (by simp only [List.length_cons, List.length_nil]; omega) - have hownerAddress : - setFeeProtocolOwnerAddress oOwner = - ({ evmLockSolm with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }).executionEnv.source := by - have haddr := - setFeeProtocolOwnerAddress_eq_source_of_mask_eq - (out := oOwner) (I := I) hownerCaller - simpa [evmLockSolm, initState] using haddr - have hownerRequireOk := - uniswapV3PoolSetFeeProtocolSourceOwnerRequireSuccessPrefixExact (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - (evmOwner := { evmLockSolm with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }) - (out := oOwner) hwv hunlockedSolm - (by - simpa [evmLockSolm, setFeeProtocolStoreWithOwner, - setFeeProtocolOwnerAddress, setFeeProtocolOwnerWord] using hownerCallOk) - hownerAddress - by_cases hfee : - setFeeProtocolEnabledNat (setFeeProtocolArg0Word I).toNat ∧ - setFeeProtocolEnabledNat (setFeeProtocolArg1Word I).toNat - · obtain ⟨hfee0, hfee1⟩ := hfee - obtain ⟨kFee, CFee, hrdFee⟩ := - uniswapV3PoolSetFeeProtocolFeeProtocolGuardsOk (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [⟨857⟩, solcSelectorWord I]) - (mem := setFeeProtocolOwnerStaticcallMem oOwner) - (aw := setFeeProtocolOwnerStaticcallActiveWords) (rdata := oOwner) - (acc := (cAOwner, σOwnerEvm)) hpatch hrdOwnerCaller hfee0 hfee1 - (by simp only [List.length_cons, List.length_nil]; omega) - have hfeeRequireOk := - uniswapV3PoolSetFeeProtocolSourceFeeProtocolRequireSuccessPrefixExact (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - (evmOwner := { evmLockSolm with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }) - (out := oOwner) hownerRequireOk hfee0 hfee1 - have hbody := - uniswapV3PoolSetFeeProtocolSourceSuccessBody (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - (evmOwner := { evmLockSolm with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }) - (out := oOwner) hfeeRequireOk - obtain ⟨kStore, CStore, hrdStore⟩ := - uniswapV3PoolSetFeeProtocolFeeProtocolStoreEvm (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [⟨857⟩, solcSelectorWord I]) - (mem := setFeeProtocolOwnerStaticcallMem oOwner) - (aw := setFeeProtocolOwnerStaticcallActiveWords) (rdata := oOwner) - (cA := cAOwner) (σ := σOwnerEvm) hpatch hrdFee _hperm - (by simp only [List.length_cons, List.length_nil]; omega) - obtain ⟨kEvent, CEvent, hrdEvent⟩ := - uniswapV3PoolSetFeeProtocolEventLogEvm (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [⟨857⟩, solcSelectorWord I]) (out := oOwner) - (rdata := oOwner) (cA := cAOwner) - (σ := sstoreAccountMap I.codeOwner σOwnerEvm ⟨0⟩ - (setFeeProtocolEvmFeeProtocolSlotWord σOwnerEvm I)) - (oldSlot := codeOwnerStorageWord I σOwnerEvm ⟨0⟩) - hpatch hrdStore _hperm hownerSize32 hoOwnerSize - (by simp only [List.length_cons, List.length_nil]; omega) - have hrdSuccess := - uniswapV3PoolSetFeeProtocolUnlockReturnEvm (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [solcSelectorWord I]) - (mem := setFeeProtocolEventMem - (codeOwnerStorageWord I σOwnerEvm ⟨0⟩) I oOwner) - (aw := UInt256.ofNat 8) (rdata := oOwner) - (cA := cAOwner) - (σ := sstoreAccountMap I.codeOwner σOwnerEvm ⟨0⟩ - (setFeeProtocolEvmFeeProtocolSlotWord σOwnerEvm I)) - (oldFeeProtocol := setFeeProtocolEventOldFeeProtocolWord - (codeOwnerStorageWord I σOwnerEvm ⟨0⟩)) - hpatch hrdEvent _hperm - (by simp only [List.length_cons, List.length_nil]; omega) - exact hrdSuccess.reEquivExecutionGenAccountMapEquiv hcode hdispatch hdecode hbody - (by - simp [setFeeProtocolAfterUnlockState, setFeeProtocolAfterFeeProtocolState, - storageStore_createdAccounts]) - (by - exact setFeeProtocolFinalAccountMapEquiv - (evmOwner := { evmLockSolm with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }) - (σOwnerEvm := σOwnerEvm) (I := I) - (by simpa using hAccountsOwner) - (by simp [evmLockSolm, initState]) - hfee0 hfee1) - (by - rw [show (setfeeprotocolTransition v).returnType = [] from rfl] - exact returnEquiv.fallthrough rfl rfl (by native_decide)) - · have hrdFeeRevert := - uniswapV3PoolSetFeeProtocolFeeProtocolGuardsRevert (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [⟨857⟩, solcSelectorWord I]) - (mem := setFeeProtocolOwnerStaticcallMem oOwner) - (aw := setFeeProtocolOwnerStaticcallActiveWords) (rdata := oOwner) - (acc := (cAOwner, σOwnerEvm)) hpatch hrdOwnerCaller hfee - (by simp only [List.length_cons, List.length_nil]; omega) - have hbody := - uniswapV3PoolSetFeeProtocolSourceFeeProtocolRequireRevertBody (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - (evmOwner := { evmLockSolm with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }) - (out := oOwner) hownerRequireOk hfee - exact hrdFeeRevert.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hrdOwnerCallerRevert := - uniswapV3PoolSetFeeProtocolOwnerCallerGuardReverts (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [setFeeProtocolArg1Word I, setFeeProtocolArg0Word I, ⟨857⟩, - solcSelectorWord I]) - (owner := setFeeProtocolOwnerWord oOwner) - (mem := setFeeProtocolOwnerStaticcallMem oOwner) - (aw := setFeeProtocolOwnerStaticcallActiveWords) (rdata := oOwner) - (acc := (cAOwner, σOwnerEvm)) hpatch - (by simpa [setFeeProtocolOwnerWord] using hrdOwnerDecode) - hownerCaller - (by simp only [List.length_cons, List.length_nil]; omega) - have hownerAddressNe : - setFeeProtocolOwnerAddress oOwner ≠ - ({ evmLockSolm with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }).executionEnv.source := by - have hne := - setFeeProtocolOwnerAddress_ne_source_of_mask_ne - (out := oOwner) (I := I) hownerCaller - simpa [evmLockSolm, initState] using hne - have hbody := - uniswapV3PoolSetFeeProtocolSourceOwnerRequireRevertBody (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) - (evmOwner := { evmLockSolm with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }) - (out := oOwner) hwv hunlockedSolm - (by - simpa [evmLockSolm, setFeeProtocolStoreWithOwner, - setFeeProtocolOwnerAddress, setFeeProtocolOwnerWord] using hownerCallOk) - hownerAddressNe - exact hrdOwnerCallerRevert.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hzOwnerFalse : zOwner = false := by - cases zOwner <;> simp at hzOwner ⊢ - have hrdOwnerRevert := hOwnerStatusRevert hzOwnerFalse - have hcallOwnerSolmFalse : - typedCallViaEVM (config v) - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_solm I)) σ₀ (Sat256.ofUInt256 g) A I) - (EVM.address (AccountAddress.ofNat v.factory.toNat)) "owner" 0 [] - (false, { initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_solm I)) σ₀ (Sat256.ofUInt256 g) A I with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }, oOwner) false := by - simpa [hzOwnerFalse] using hcallOwnerSolm - have hownerRevert := - uniswapV3PoolSetFeeProtocolSourceOwnerCallFailure (v := v) - (evm := evmLockSolm) - (evm' := { evmLockSolm with - accountMap := σOwnerSolm - substate := AOwnerSolm - createdAccounts := cAOwner }) - (I := I) (out := oOwner) hfactoryGuardSolm - (by simpa [evmLockSolm] using hcallOwnerSolmFalse) - have hbody := - uniswapV3PoolSetFeeProtocolSourceOwnerCallRevertBody (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm - hownerRevert - exact hrdOwnerRevert.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hdepthEq : I.depth = (1024 : Fin 1025) := by - apply Fin.ext - have hle : 1024 ≤ I.depth.val := Nat.le_of_not_gt hdepth - exact le_antisymm (Nat.le_of_lt_succ I.depth.isLt) hle - have hrdOwnerDepth := - uniswapV3PoolSetFeeProtocolOwnerStaticcallDepthLimitReverts (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [setFeeProtocolArg1Word I, setFeeProtocolArg0Word I, ⟨857⟩, - solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_evm I)) - hpatch hrdOwnerGuard hfactoryCode hdepthEq - (by simp only [List.length_cons, List.length_nil]; omega) - have hcallOwnerDepth : - typedCallViaEVM (config v) evmLockSolm - (EVM.address (AccountAddress.ofNat v.factory.toNat)) "owner" 0 [] - (false, - { evmLockSolm with - substate := - (evmLockSolm.addAccessedAccount - (EVM.address (AccountAddress.ofNat v.factory.toNat))).substate }, - ByteArray.empty) false := by - exact callNotMade_depthLimit (cfg := config v) (evm := evmLockSolm) - (tgt := EVM.address (AccountAddress.ofNat v.factory.toNat)) - (name := "owner") (args := []) (callPerm := false) - (setFeeProtocolOwnerCallMem_encode_owner (v := v)) - (by simpa [evmLockSolm, initState] using hdepthEq) - have hownerRevert := - uniswapV3PoolSetFeeProtocolSourceOwnerCallFailure (v := v) - (evm := evmLockSolm) - (evm' := { evmLockSolm with - substate := - (evmLockSolm.addAccessedAccount - (EVM.address (AccountAddress.ofNat v.factory.toNat))).substate }) - (I := I) (out := ByteArray.empty) hfactoryGuardSolm hcallOwnerDepth - have hbody := - uniswapV3PoolSetFeeProtocolSourceOwnerCallRevertBody (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm - hownerRevert - exact hrdOwnerDepth.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hfactoryNoCodeEvm : - Reasoning.Theory.extCodeSizeWord - (sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_evm I)) - (setFeeProtocolFactoryWord v) = ⟨0⟩ := by - by_contra hne - exact hfactoryCode hne - have hrdOwnerNoCode := - uniswapV3PoolSetFeeProtocolOwnerExtcodesizeMissingReverts (v := v) (code := code) - (ee := I) (g := Sat256.ofUInt256 g) - (s0 := initState cA gh bl σ_evm σ₀ (Sat256.ofUInt256 g) A I) - (R := [setFeeProtocolArg1Word I, setFeeProtocolArg0Word I, ⟨857⟩, - solcSelectorWord I]) - (rdata := ByteArray.empty) (cA := cA) - (σ := sstoreAccountMap I.codeOwner σ_evm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_evm I)) - hpatch hrdOwnerGuard hfactoryNoCodeEvm - (by simp only [List.length_cons, List.length_nil]; omega) - have hfactoryNoCodeSolm : - Reasoning.Theory.extCodeSizeWord - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_solm I)) - (setFeeProtocolFactoryWord v) = ⟨0⟩ := by - rw [← extCodeSizeWord_accountMapEquiv hAccountsAfterLock - (setFeeProtocolFactoryWord v)] - exact hfactoryNoCodeEvm - let evmLockSolm := - initState cA gh bl - (sstoreAccountMap I.codeOwner σ_solm ⟨0⟩ - (setFeeProtocolLockedSlotWord σ_solm I)) σ₀ (Sat256.ofUInt256 g) A I - have hfactoryGuardNoCodeSolm : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } - evmLockSolm - (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)) = - .ok (.bool false) := by - exact evalExpr_setFeeProtocol_factoryExtCodeSizeGuard_false (v := v) - (evm := evmLockSolm) (I := I) (by simpa [evmLockSolm, initState]) - have hownerRevert : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - evmLockSolm - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false) ] - .reverted := by - exact checkedExternalCallNoCode (receiver := addrLit v.factory) (name := "owner") - (sendVal := 0) (args := []) (retVar := "_factoryOwner") - (perm := false) hfactoryGuardNoCodeSolm - have hbody := - uniswapV3PoolSetFeeProtocolSourceOwnerCallRevertBody (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) - (A := A) (I := I) (g := Sat256.ofUInt256 g) hwv hunlockedSolm hownerRevert - exact hrdOwnerNoCode.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hlockedEvm : setFeeProtocolUnlockedByte σ_evm I = ⟨0⟩ := by - by_contra hne - exact hunlocked hne - have hlockedSolm : setFeeProtocolUnlockedByte σ_solm I = ⟨0⟩ := by - rw [setFeeProtocolUnlockedByte_transport (σ_evm := σ_evm) (σ_solm := σ_solm) - hAccounts] - exact hlockedEvm - have hbody := uniswapV3PoolSetFeeProtocolSourceLockedReverts (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hwv hlockedSolm - have hrd := uniswapV3PoolSetFeeProtocolEvmLocked (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hsz68 - hlockedEvm - exact hrd.reEquivExecutionRevert hcode hdispatch hdecode hbody - · have hshort : I.calldata.size < 68 := by omega - have hdecode := uniswapV3PoolSetFeeProtocolDecodeShort (v := v) (I := I) hshort - have hrd := uniswapV3PoolSetFeeProtocolEvmDecodeShort (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hshort - exact hrd.reEquivDecodingFailed hcode hdispatch hdecode - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocolFeeProtocolCheck.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocolFeeProtocolCheck.lean deleted file mode 100644 index 3200d138..00000000 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocolFeeProtocolCheck.lean +++ /dev/null @@ -1,1667 +0,0 @@ -import Benchmarks.UniswapV3Pool.SetFeeProtocolSource - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev setFeeProtocolEnabledNat (n : Nat) : Prop := - n = 0 ∨ (4 ≤ n ∧ n ≤ 10) - -private theorem uniswapV3PoolPatchPreservesJumpDest8484 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨8484⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest8526 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨8526⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest8535 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨8535⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched8484 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨8484⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest8484 - -theorem uniswapV3PoolJumpDestPatched8526 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨8526⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest8526 - -theorem uniswapV3PoolJumpDestPatched8535 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨8535⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest8535 - -theorem setFeeProtocolDecodeNoArgAfterFactory {v : PoolImmutables} - {code : ByteArray} {pc : UInt256} {byte : UInt8} {op : Operation} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 8347 ≤ pc.toNat) (hhi : pc.toNat + 1 ≤ 8829) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some byte) - (hparse : (some byte >>= parseInstr) = some op) - (harg : argOnNBytesOfInstr op = 0) : - decode code pc = some (op, .none) := by - have hsize : 8829 ≤ uniswapV3PoolBytecode.size := by native_decide - exact uniswapV3PoolDecodePatchedNoArg hpatch (by omega) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory - (n := 1) hlo hhi) - hgetTemplate hparse harg - -theorem setFeeProtocolDecodePush1AfterFactory {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 8347 ≤ pc.toNat) (hhi : pc.toNat + 2 ≤ 8829) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x60) - (hval : - uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1)) = n) : - decode code pc = some (.Push .PUSH1, some (n, 1)) := by - have hsize : 8829 ≤ uniswapV3PoolBytecode.size := by native_decide - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 hpatch (by omega) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory - (n := 2) hlo hhi) - hgetTemplate hval - -theorem setFeeProtocolDecodePush2AfterFactory {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hlo : 8347 ≤ pc.toNat) (hhi : pc.toNat + 3 ≤ 8829) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x61) - (hval : - uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 2)) = n) : - decode code pc = some (.Push .PUSH2, some (n, 2)) := by - have hsize : 8829 ≤ uniswapV3PoolBytecode.size := by native_decide - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush2 hpatch (by omega) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory - (n := 3) hlo hhi) - hgetTemplate hval - -theorem setFeeProtocolArg0Word_clean (I : ExecutionEnv) : - UInt256.land (setFeeProtocolArg0Word I) ⟨255⟩ = setFeeProtocolArg0Word I := by - have hmask : (⟨255⟩ : UInt256) = slot0Uint8Mask := by native_decide - have hsource : setFeeProtocolUint8Mask = slot0Uint8Mask := by native_decide - have hbound : (setFeeProtocolArg0Word I).toNat < EVM.twoPow 8 := by - rw [setFeeProtocolArg0Word, hsource] - exact slot0Uint8Mask_bound (calldataWord I.calldata 4) - rw [hmask] - exact slot0Uint8Mask_clean hbound - -theorem setFeeProtocolArg1Word_clean (I : ExecutionEnv) : - UInt256.land (setFeeProtocolArg1Word I) ⟨255⟩ = setFeeProtocolArg1Word I := by - have hmask : (⟨255⟩ : UInt256) = slot0Uint8Mask := by native_decide - have hsource : setFeeProtocolUint8Mask = slot0Uint8Mask := by native_decide - have hbound : (setFeeProtocolArg1Word I).toNat < EVM.twoPow 8 := by - rw [setFeeProtocolArg1Word, hsource] - exact slot0Uint8Mask_bound (calldataWord I.calldata 36) - rw [hmask] - exact slot0Uint8Mask_clean hbound - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocol0ZeroTo8484 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8449⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hzero : (setFeeProtocolArg0Word ee).toNat = 0) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8484⟩ - (⟨1⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k' C' := by - have hd8449 : decode code ⟨8449⟩ = some (.JUMPDEST, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8449⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8450 : decode code ⟨8450⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8450⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8452 : decode code ⟨8452⟩ = some (.DUP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8452⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8453 : decode code ⟨8453⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8453⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8454 : decode code ⟨8454⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8454⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8455 : decode code ⟨8455⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8455⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8456 : decode code ⟨8456⟩ = some (.Push .PUSH2, some (⟨8484⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8456⟩) - (n := ⟨8484⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8459 : decode code ⟨8459⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8459⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have harg0Zero : setFeeProtocolArg0Word ee = ⟨0⟩ := - uint256_toNat_eq_zero hzero - have rd8459 := evm_run h with [ - raw jumpdest hd8449 (by evm_ov), - raw push1 ⟨255⟩ hd8450 (by evm_ov), - raw dup3 hd8452 (by evm_ov), - raw and hd8453 (by evm_ov), - raw iszero hd8454 (by evm_ov), - raw dup1 hd8455 (by evm_ov), - raw push2 ⟨8484⟩ hd8456 (by evm_ov)] - rw [setFeeProtocolArg0Word_clean ee, harg0Zero] at rd8459 - have rd8484 := rd8459.jumpiT hd8459 (by decide) - (uniswapV3PoolJumpDestPatched8484 hpatch) (by evm_ov) - exact ⟨_, _, by simpa [harg0Zero] using rd8484⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocol0RangeTo8484 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8449⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hge : 4 ≤ (setFeeProtocolArg0Word ee).toNat) - (hle : (setFeeProtocolArg0Word ee).toNat ≤ 10) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8484⟩ - (⟨1⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k' C' := by - have hd8449 : decode code ⟨8449⟩ = some (.JUMPDEST, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8449⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8450 : decode code ⟨8450⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8450⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8452 : decode code ⟨8452⟩ = some (.DUP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8452⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8453 : decode code ⟨8453⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8453⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8454 : decode code ⟨8454⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8454⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8455 : decode code ⟨8455⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8455⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8456 : decode code ⟨8456⟩ = some (.Push .PUSH2, some (⟨8484⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8456⟩) - (n := ⟨8484⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8459 : decode code ⟨8459⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8459⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8460 : decode code ⟨8460⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8460⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8461 : decode code ⟨8461⟩ = some (.Push .PUSH1, some (⟨4⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8461⟩) - (n := ⟨4⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8463 : decode code ⟨8463⟩ = some (.DUP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8463⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8464 : decode code ⟨8464⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8464⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8466 : decode code ⟨8466⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8466⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8467 : decode code ⟨8467⟩ = some (.LT, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8467⟩) (byte := 0x10) - (op := .LT) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8468 : decode code ⟨8468⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8468⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8469 : decode code ⟨8469⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8469⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8470 : decode code ⟨8470⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8470⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8471 : decode code ⟨8471⟩ = some (.Push .PUSH2, some (⟨8484⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8471⟩) - (n := ⟨8484⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8474 : decode code ⟨8474⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8474⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8475 : decode code ⟨8475⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8475⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8476 : decode code ⟨8476⟩ = some (.Push .PUSH1, some (⟨10⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8476⟩) - (n := ⟨10⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8478 : decode code ⟨8478⟩ = some (.DUP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8478⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8479 : decode code ⟨8479⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8479⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8481 : decode code ⟨8481⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8481⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8482 : decode code ⟨8482⟩ = some (.GT, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8482⟩) (byte := 0x11) - (op := .GT) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8483 : decode code ⟨8483⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8483⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have harg0Ne : setFeeProtocolArg0Word ee ≠ ⟨0⟩ := by - intro hbad - have hbadNat := congrArg UInt256.toNat hbad - simp at hbadNat - omega - have hlt0 : UInt256.lt (setFeeProtocolArg0Word ee) ⟨4⟩ = ⟨0⟩ := by - exact ult_zero (by simpa using hge) - have hgt0 : UInt256.gt (setFeeProtocolArg0Word ee) ⟨10⟩ = ⟨0⟩ := by - exact ugt_zero (by simpa using hle) - have rd8459 := evm_run h with [ - raw jumpdest hd8449 (by evm_ov), - raw push1 ⟨255⟩ hd8450 (by evm_ov), - raw dup3 hd8452 (by evm_ov), - raw and hd8453 (by evm_ov), - raw iszero hd8454 (by evm_ov), - raw dup1 hd8455 (by evm_ov), - raw push2 ⟨8484⟩ hd8456 (by evm_ov)] - rw [setFeeProtocolArg0Word_clean ee, isZero_eq_zero_of_ne harg0Ne] at rd8459 - have rd8460 := rd8459.jumpiNT hd8459 (by decide) (by evm_ov) - have rd8474 := evm_run rd8460 with [ - raw pop hd8460 (by evm_ov), - raw push1 ⟨4⟩ hd8461 (by evm_ov), - raw dup3 hd8463 (by evm_ov), - raw push1 ⟨255⟩ hd8464 (by evm_ov), - raw and hd8466 (by evm_ov), - raw lt hd8467 (by evm_ov), - raw iszero hd8468 (by evm_ov), - raw dup1 hd8469 (by evm_ov), - raw iszero hd8470 (by evm_ov), - raw push2 ⟨8484⟩ hd8471 (by evm_ov)] - rw [u256_land_comm ⟨255⟩ (setFeeProtocolArg0Word ee), - setFeeProtocolArg0Word_clean ee, hlt0] at rd8474 - have rd8475 := rd8474.jumpiNT hd8474 (by decide) (by evm_ov) - have rd8484 := evm_run rd8475 with [ - raw pop hd8475 (by evm_ov), - raw push1 ⟨10⟩ hd8476 (by evm_ov), - raw dup3 hd8478 (by evm_ov), - raw push1 ⟨255⟩ hd8479 (by evm_ov), - raw and hd8481 (by evm_ov), - raw gt hd8482 (by evm_ov), - raw iszero hd8483 (by evm_ov)] - rw [u256_land_comm ⟨255⟩ (setFeeProtocolArg0Word ee), - setFeeProtocolArg0Word_clean ee, hgt0] at rd8484 - exact ⟨_, _, by simpa using rd8484⟩ - -theorem uniswapV3PoolSetFeeProtocolFeeProtocol0EnabledTo8484 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8449⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hfee0 : setFeeProtocolEnabledNat (setFeeProtocolArg0Word ee).toNat) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8484⟩ - (⟨1⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k' C' := by - rcases hfee0 with hzero | hrange - · exact uniswapV3PoolSetFeeProtocolFeeProtocol0ZeroTo8484 hpatch h hzero hov - · exact uniswapV3PoolSetFeeProtocolFeeProtocol0RangeTo8484 hpatch h - hrange.1 hrange.2 hov - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocolFalseAt8526Reverts {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8526⟩ (⟨0⟩ :: R) mem aw rdata acc k C) - (hov : R.length + 2 ≤ 1024) : - RDrev code g s0 := by - have hd8526 : decode code ⟨8526⟩ = some (.JUMPDEST, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8526⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8527 : decode code ⟨8527⟩ = some (.Push .PUSH2, some (⟨8535⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8527⟩) - (n := ⟨8535⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8530 : decode code ⟨8530⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8530⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8531 : decode code ⟨8531⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8531⟩) - (n := ⟨0⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8533 : decode code ⟨8533⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8533⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8534 : decode code ⟨8534⟩ = some (.REVERT, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8534⟩) (byte := 0xfd) - (op := .REVERT) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have rd8530 := evm_run h with [ - raw jumpdest hd8526 (by evm_ov), - raw push2 ⟨8535⟩ hd8527 (by evm_ov)] - have rd8531 := rd8530.jumpiNT hd8530 (by decide) (by evm_ov) - exact RD.solcPush1Dup1Revert0 rd8531 hd8531 - (by simpa [show (⟨8531⟩ : UInt256) + UInt256.ofNat 2 = ⟨8533⟩ by native_decide] - using hd8533) - (by simpa [ - show (⟨8531⟩ : UInt256) + UInt256.ofNat 2 + ⟨1⟩ = ⟨8534⟩ by native_decide] - using hd8534) - (by omega) - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocolFalseAt8484Reverts {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8484⟩ (⟨0⟩ :: R) mem aw rdata acc k C) - (hov : R.length + 3 ≤ 1024) : - RDrev code g s0 := by - have hd8484 : decode code ⟨8484⟩ = some (.JUMPDEST, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8484⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8485 : decode code ⟨8485⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8485⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8486 : decode code ⟨8486⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8486⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8487 : decode code ⟨8487⟩ = some (.Push .PUSH2, some (⟨8526⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8487⟩) - (n := ⟨8526⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8490 : decode code ⟨8490⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8490⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have rd8490 := evm_run h with [ - raw jumpdest hd8484 (by evm_ov), - raw dup1 hd8485 (by evm_ov), - raw iszero hd8486 (by evm_ov), - raw push2 ⟨8526⟩ hd8487 (by evm_ov)] - have rd8526 := rd8490.jumpiT hd8490 (by decide) - (uniswapV3PoolJumpDestPatched8526 hpatch) (by evm_ov) - exact uniswapV3PoolSetFeeProtocolFeeProtocolFalseAt8526Reverts hpatch rd8526 - (by omega) - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocolTrueAt8484To8492 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8484⟩ (⟨1⟩ :: R) mem aw rdata acc k C) - (hov : R.length + 3 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8492⟩ R mem aw rdata acc k' C' := by - have hd8484 : decode code ⟨8484⟩ = some (.JUMPDEST, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8484⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8485 : decode code ⟨8485⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8485⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8486 : decode code ⟨8486⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8486⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8487 : decode code ⟨8487⟩ = some (.Push .PUSH2, some (⟨8526⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8487⟩) - (n := ⟨8526⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8490 : decode code ⟨8490⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8490⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8491 : decode code ⟨8491⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8491⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have rd8490 := evm_run h with [ - raw jumpdest hd8484 (by evm_ov), - raw dup1 hd8485 (by evm_ov), - raw iszero hd8486 (by evm_ov), - raw push2 ⟨8526⟩ hd8487 (by evm_ov)] - have rd8491 := rd8490.jumpiNT hd8490 (by decide) (by evm_ov) - exact ⟨_, _, by - simpa [show - (⟨8484⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 3 + ⟨1⟩ + ⟨1⟩ = - ⟨8492⟩ by native_decide] using - (evm_run rd8491 with [raw pop hd8491 (by evm_ov)])⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocol1ZeroTo8526 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8492⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hzero : (setFeeProtocolArg1Word ee).toNat = 0) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8526⟩ - (⟨1⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k' C' := by - have hd8492 : decode code ⟨8492⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8492⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8494 : decode code ⟨8494⟩ = some (.DUP2, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8494⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8495 : decode code ⟨8495⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8495⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8496 : decode code ⟨8496⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8496⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8497 : decode code ⟨8497⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8497⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8498 : decode code ⟨8498⟩ = some (.Push .PUSH2, some (⟨8526⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8498⟩) - (n := ⟨8526⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8501 : decode code ⟨8501⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8501⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have harg1Zero : setFeeProtocolArg1Word ee = ⟨0⟩ := - uint256_toNat_eq_zero hzero - have rd8501 := evm_run h with [ - raw push1 ⟨255⟩ hd8492 (by evm_ov), - raw dup2 hd8494 (by evm_ov), - raw and hd8495 (by evm_ov), - raw iszero hd8496 (by evm_ov), - raw dup1 hd8497 (by evm_ov), - raw push2 ⟨8526⟩ hd8498 (by evm_ov)] - rw [setFeeProtocolArg1Word_clean ee, harg1Zero] at rd8501 - have rd8526 := rd8501.jumpiT hd8501 (by decide) - (uniswapV3PoolJumpDestPatched8526 hpatch) (by evm_ov) - exact ⟨_, _, by simpa [harg1Zero] using rd8526⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocol1RangeTo8526 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8492⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hge : 4 ≤ (setFeeProtocolArg1Word ee).toNat) - (hle : (setFeeProtocolArg1Word ee).toNat ≤ 10) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8526⟩ - (⟨1⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k' C' := by - have hd8492 : decode code ⟨8492⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8492⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8494 : decode code ⟨8494⟩ = some (.DUP2, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8494⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8495 : decode code ⟨8495⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8495⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8496 : decode code ⟨8496⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8496⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8497 : decode code ⟨8497⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8497⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8498 : decode code ⟨8498⟩ = some (.Push .PUSH2, some (⟨8526⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8498⟩) - (n := ⟨8526⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8501 : decode code ⟨8501⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8501⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8502 : decode code ⟨8502⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8502⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8503 : decode code ⟨8503⟩ = some (.Push .PUSH1, some (⟨4⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8503⟩) - (n := ⟨4⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8505 : decode code ⟨8505⟩ = some (.DUP2, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8505⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8506 : decode code ⟨8506⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8506⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8508 : decode code ⟨8508⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8508⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8509 : decode code ⟨8509⟩ = some (.LT, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8509⟩) (byte := 0x10) - (op := .LT) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8510 : decode code ⟨8510⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8510⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8511 : decode code ⟨8511⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8511⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8512 : decode code ⟨8512⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8512⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8513 : decode code ⟨8513⟩ = some (.Push .PUSH2, some (⟨8526⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8513⟩) - (n := ⟨8526⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8516 : decode code ⟨8516⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8516⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8517 : decode code ⟨8517⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8517⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8518 : decode code ⟨8518⟩ = some (.Push .PUSH1, some (⟨10⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8518⟩) - (n := ⟨10⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8520 : decode code ⟨8520⟩ = some (.DUP2, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8520⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8521 : decode code ⟨8521⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8521⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8523 : decode code ⟨8523⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8523⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8524 : decode code ⟨8524⟩ = some (.GT, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8524⟩) (byte := 0x11) - (op := .GT) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8525 : decode code ⟨8525⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8525⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have harg1Ne : setFeeProtocolArg1Word ee ≠ ⟨0⟩ := by - intro hbad - have hbadNat := congrArg UInt256.toNat hbad - simp at hbadNat - omega - have hlt0 : UInt256.lt (setFeeProtocolArg1Word ee) ⟨4⟩ = ⟨0⟩ := by - exact ult_zero (by simpa using hge) - have hgt0 : UInt256.gt (setFeeProtocolArg1Word ee) ⟨10⟩ = ⟨0⟩ := by - exact ugt_zero (by simpa using hle) - have rd8501 := evm_run h with [ - raw push1 ⟨255⟩ hd8492 (by evm_ov), - raw dup2 hd8494 (by evm_ov), - raw and hd8495 (by evm_ov), - raw iszero hd8496 (by evm_ov), - raw dup1 hd8497 (by evm_ov), - raw push2 ⟨8526⟩ hd8498 (by evm_ov)] - rw [setFeeProtocolArg1Word_clean ee, isZero_eq_zero_of_ne harg1Ne] at rd8501 - have rd8502 := rd8501.jumpiNT hd8501 (by decide) (by evm_ov) - have rd8516 := evm_run rd8502 with [ - raw pop hd8502 (by evm_ov), - raw push1 ⟨4⟩ hd8503 (by evm_ov), - raw dup2 hd8505 (by evm_ov), - raw push1 ⟨255⟩ hd8506 (by evm_ov), - raw and hd8508 (by evm_ov), - raw lt hd8509 (by evm_ov), - raw iszero hd8510 (by evm_ov), - raw dup1 hd8511 (by evm_ov), - raw iszero hd8512 (by evm_ov), - raw push2 ⟨8526⟩ hd8513 (by evm_ov)] - rw [u256_land_comm ⟨255⟩ (setFeeProtocolArg1Word ee), - setFeeProtocolArg1Word_clean ee, hlt0] at rd8516 - have rd8517 := rd8516.jumpiNT hd8516 (by decide) (by evm_ov) - have rd8526 := evm_run rd8517 with [ - raw pop hd8517 (by evm_ov), - raw push1 ⟨10⟩ hd8518 (by evm_ov), - raw dup2 hd8520 (by evm_ov), - raw push1 ⟨255⟩ hd8521 (by evm_ov), - raw and hd8523 (by evm_ov), - raw gt hd8524 (by evm_ov), - raw iszero hd8525 (by evm_ov)] - rw [u256_land_comm ⟨255⟩ (setFeeProtocolArg1Word ee), - setFeeProtocolArg1Word_clean ee, hgt0] at rd8526 - exact ⟨_, _, by simpa using rd8526⟩ - -theorem uniswapV3PoolSetFeeProtocolFeeProtocol1EnabledTo8526 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8492⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hfee1 : setFeeProtocolEnabledNat (setFeeProtocolArg1Word ee).toNat) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8526⟩ - (⟨1⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k' C' := by - rcases hfee1 with hzero | hrange - · exact uniswapV3PoolSetFeeProtocolFeeProtocol1ZeroTo8526 hpatch h hzero hov - · exact uniswapV3PoolSetFeeProtocolFeeProtocol1RangeTo8526 hpatch h - hrange.1 hrange.2 hov - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocol1NonzeroTo8502 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8492⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hne : setFeeProtocolArg1Word ee ≠ ⟨0⟩) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8502⟩ - (⟨0⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k' C' := by - have hd8492 : decode code ⟨8492⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8492⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8494 : decode code ⟨8494⟩ = some (.DUP2, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8494⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8495 : decode code ⟨8495⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8495⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8496 : decode code ⟨8496⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8496⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8497 : decode code ⟨8497⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8497⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8498 : decode code ⟨8498⟩ = some (.Push .PUSH2, some (⟨8526⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8498⟩) - (n := ⟨8526⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8501 : decode code ⟨8501⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8501⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have rd8501 := evm_run h with [ - raw push1 ⟨255⟩ hd8492 (by evm_ov), - raw dup2 hd8494 (by evm_ov), - raw and hd8495 (by evm_ov), - raw iszero hd8496 (by evm_ov), - raw dup1 hd8497 (by evm_ov), - raw push2 ⟨8526⟩ hd8498 (by evm_ov)] - rw [setFeeProtocolArg1Word_clean ee, isZero_eq_zero_of_ne hne] at rd8501 - exact ⟨_, _, rd8501.jumpiNT hd8501 (by decide) (by evm_ov)⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocol1BelowTo8526False {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8502⟩ - (⟨0⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hlt : (setFeeProtocolArg1Word ee).toNat < 4) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8526⟩ - (⟨0⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k' C' := by - have hd8502 : decode code ⟨8502⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8502⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8503 : decode code ⟨8503⟩ = some (.Push .PUSH1, some (⟨4⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8503⟩) - (n := ⟨4⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8505 : decode code ⟨8505⟩ = some (.DUP2, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8505⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8506 : decode code ⟨8506⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8506⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8508 : decode code ⟨8508⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8508⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8509 : decode code ⟨8509⟩ = some (.LT, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8509⟩) (byte := 0x10) - (op := .LT) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8510 : decode code ⟨8510⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8510⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8511 : decode code ⟨8511⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8511⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8512 : decode code ⟨8512⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8512⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8513 : decode code ⟨8513⟩ = some (.Push .PUSH2, some (⟨8526⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8513⟩) - (n := ⟨8526⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8516 : decode code ⟨8516⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8516⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hlt1 : UInt256.lt (setFeeProtocolArg1Word ee) ⟨4⟩ = ⟨1⟩ := by - exact ult_one (by simpa using hlt) - have rd8516 := evm_run h with [ - raw pop hd8502 (by evm_ov), - raw push1 ⟨4⟩ hd8503 (by evm_ov), - raw dup2 hd8505 (by evm_ov), - raw push1 ⟨255⟩ hd8506 (by evm_ov), - raw and hd8508 (by evm_ov), - raw lt hd8509 (by evm_ov), - raw iszero hd8510 (by evm_ov), - raw dup1 hd8511 (by evm_ov), - raw iszero hd8512 (by evm_ov), - raw push2 ⟨8526⟩ hd8513 (by evm_ov)] - rw [u256_land_comm ⟨255⟩ (setFeeProtocolArg1Word ee), - setFeeProtocolArg1Word_clean ee, hlt1] at rd8516 - exact ⟨_, _, rd8516.jumpiT hd8516 (by decide) - (uniswapV3PoolJumpDestPatched8526 hpatch) (by evm_ov)⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocol1AboveTo8526False {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8502⟩ - (⟨0⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hge : 4 ≤ (setFeeProtocolArg1Word ee).toNat) - (hgt : 10 < (setFeeProtocolArg1Word ee).toNat) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8526⟩ - (⟨0⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k' C' := by - have hd8502 : decode code ⟨8502⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8502⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8503 : decode code ⟨8503⟩ = some (.Push .PUSH1, some (⟨4⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8503⟩) - (n := ⟨4⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8505 : decode code ⟨8505⟩ = some (.DUP2, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8505⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8506 : decode code ⟨8506⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8506⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8508 : decode code ⟨8508⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8508⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8509 : decode code ⟨8509⟩ = some (.LT, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8509⟩) (byte := 0x10) - (op := .LT) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8510 : decode code ⟨8510⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8510⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8511 : decode code ⟨8511⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8511⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8512 : decode code ⟨8512⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8512⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8513 : decode code ⟨8513⟩ = some (.Push .PUSH2, some (⟨8526⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8513⟩) - (n := ⟨8526⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8516 : decode code ⟨8516⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8516⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8517 : decode code ⟨8517⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8517⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8518 : decode code ⟨8518⟩ = some (.Push .PUSH1, some (⟨10⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8518⟩) - (n := ⟨10⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8520 : decode code ⟨8520⟩ = some (.DUP2, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8520⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8521 : decode code ⟨8521⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8521⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8523 : decode code ⟨8523⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8523⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8524 : decode code ⟨8524⟩ = some (.GT, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8524⟩) (byte := 0x11) - (op := .GT) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8525 : decode code ⟨8525⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8525⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hlt0 : UInt256.lt (setFeeProtocolArg1Word ee) ⟨4⟩ = ⟨0⟩ := by - exact ult_zero (by simpa using hge) - have hgt1 : UInt256.gt (setFeeProtocolArg1Word ee) ⟨10⟩ = ⟨1⟩ := by - exact ugt_one (by simpa using hgt) - have rd8516 := evm_run h with [ - raw pop hd8502 (by evm_ov), - raw push1 ⟨4⟩ hd8503 (by evm_ov), - raw dup2 hd8505 (by evm_ov), - raw push1 ⟨255⟩ hd8506 (by evm_ov), - raw and hd8508 (by evm_ov), - raw lt hd8509 (by evm_ov), - raw iszero hd8510 (by evm_ov), - raw dup1 hd8511 (by evm_ov), - raw iszero hd8512 (by evm_ov), - raw push2 ⟨8526⟩ hd8513 (by evm_ov)] - rw [u256_land_comm ⟨255⟩ (setFeeProtocolArg1Word ee), - setFeeProtocolArg1Word_clean ee, hlt0] at rd8516 - have rd8517 := rd8516.jumpiNT hd8516 (by decide) (by evm_ov) - have rd8526 := evm_run rd8517 with [ - raw pop hd8517 (by evm_ov), - raw push1 ⟨10⟩ hd8518 (by evm_ov), - raw dup2 hd8520 (by evm_ov), - raw push1 ⟨255⟩ hd8521 (by evm_ov), - raw and hd8523 (by evm_ov), - raw gt hd8524 (by evm_ov), - raw iszero hd8525 (by evm_ov)] - rw [u256_land_comm ⟨255⟩ (setFeeProtocolArg1Word ee), - setFeeProtocolArg1Word_clean ee, hgt1] at rd8526 - exact ⟨_, _, by simpa using rd8526⟩ - -theorem uniswapV3PoolSetFeeProtocolFeeProtocol1DisabledReverts {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8492⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hbad : ¬ setFeeProtocolEnabledNat (setFeeProtocolArg1Word ee).toNat) - (hov : R.length + 5 ≤ 1024) : - RDrev code g s0 := by - have hne : setFeeProtocolArg1Word ee ≠ ⟨0⟩ := by - intro hzero - have hzeroNat := congrArg UInt256.toNat hzero - simp at hzeroNat - exact hbad (Or.inl hzeroNat) - obtain ⟨_, _, rd8502⟩ := - uniswapV3PoolSetFeeProtocolFeeProtocol1NonzeroTo8502 hpatch h hne hov - by_cases hge : 4 ≤ (setFeeProtocolArg1Word ee).toNat - · have hnle : ¬ (setFeeProtocolArg1Word ee).toNat ≤ 10 := by - intro hle - exact hbad (Or.inr ⟨hge, hle⟩) - obtain ⟨_, _, rd8526⟩ := - uniswapV3PoolSetFeeProtocolFeeProtocol1AboveTo8526False hpatch rd8502 hge - (Nat.lt_of_not_ge hnle) hov - exact uniswapV3PoolSetFeeProtocolFeeProtocolFalseAt8526Reverts hpatch rd8526 - (by simp only [List.length_cons]; omega) - · obtain ⟨_, _, rd8526⟩ := - uniswapV3PoolSetFeeProtocolFeeProtocol1BelowTo8526False hpatch rd8502 - (Nat.lt_of_not_ge hge) hov - exact uniswapV3PoolSetFeeProtocolFeeProtocolFalseAt8526Reverts hpatch rd8526 - (by simp only [List.length_cons]; omega) - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocol0NonzeroTo8460 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8449⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hne : setFeeProtocolArg0Word ee ≠ ⟨0⟩) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8460⟩ - (⟨0⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k' C' := by - have hd8449 : decode code ⟨8449⟩ = some (.JUMPDEST, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8449⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8450 : decode code ⟨8450⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8450⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8452 : decode code ⟨8452⟩ = some (.DUP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8452⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8453 : decode code ⟨8453⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8453⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8454 : decode code ⟨8454⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8454⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8455 : decode code ⟨8455⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8455⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8456 : decode code ⟨8456⟩ = some (.Push .PUSH2, some (⟨8484⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8456⟩) - (n := ⟨8484⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8459 : decode code ⟨8459⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8459⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have rd8459 := evm_run h with [ - raw jumpdest hd8449 (by evm_ov), - raw push1 ⟨255⟩ hd8450 (by evm_ov), - raw dup3 hd8452 (by evm_ov), - raw and hd8453 (by evm_ov), - raw iszero hd8454 (by evm_ov), - raw dup1 hd8455 (by evm_ov), - raw push2 ⟨8484⟩ hd8456 (by evm_ov)] - rw [setFeeProtocolArg0Word_clean ee, isZero_eq_zero_of_ne hne] at rd8459 - exact ⟨_, _, rd8459.jumpiNT hd8459 (by decide) (by evm_ov)⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocol0BelowTo8484False {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8460⟩ - (⟨0⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hlt : (setFeeProtocolArg0Word ee).toNat < 4) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8484⟩ - (⟨0⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k' C' := by - have hd8460 : decode code ⟨8460⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8460⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8461 : decode code ⟨8461⟩ = some (.Push .PUSH1, some (⟨4⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8461⟩) - (n := ⟨4⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8463 : decode code ⟨8463⟩ = some (.DUP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8463⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8464 : decode code ⟨8464⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8464⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8466 : decode code ⟨8466⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8466⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8467 : decode code ⟨8467⟩ = some (.LT, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8467⟩) (byte := 0x10) - (op := .LT) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8468 : decode code ⟨8468⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8468⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8469 : decode code ⟨8469⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8469⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8470 : decode code ⟨8470⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8470⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8471 : decode code ⟨8471⟩ = some (.Push .PUSH2, some (⟨8484⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8471⟩) - (n := ⟨8484⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8474 : decode code ⟨8474⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8474⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hlt1 : UInt256.lt (setFeeProtocolArg0Word ee) ⟨4⟩ = ⟨1⟩ := by - exact ult_one (by simpa using hlt) - have rd8474 := evm_run h with [ - raw pop hd8460 (by evm_ov), - raw push1 ⟨4⟩ hd8461 (by evm_ov), - raw dup3 hd8463 (by evm_ov), - raw push1 ⟨255⟩ hd8464 (by evm_ov), - raw and hd8466 (by evm_ov), - raw lt hd8467 (by evm_ov), - raw iszero hd8468 (by evm_ov), - raw dup1 hd8469 (by evm_ov), - raw iszero hd8470 (by evm_ov), - raw push2 ⟨8484⟩ hd8471 (by evm_ov)] - rw [u256_land_comm ⟨255⟩ (setFeeProtocolArg0Word ee), - setFeeProtocolArg0Word_clean ee, hlt1] at rd8474 - exact ⟨_, _, rd8474.jumpiT hd8474 (by decide) - (uniswapV3PoolJumpDestPatched8484 hpatch) (by evm_ov)⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocol0AboveTo8484False {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8460⟩ - (⟨0⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hge : 4 ≤ (setFeeProtocolArg0Word ee).toNat) - (hgt : 10 < (setFeeProtocolArg0Word ee).toNat) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8484⟩ - (⟨0⟩ :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k' C' := by - have hd8460 : decode code ⟨8460⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8460⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8461 : decode code ⟨8461⟩ = some (.Push .PUSH1, some (⟨4⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8461⟩) - (n := ⟨4⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8463 : decode code ⟨8463⟩ = some (.DUP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8463⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8464 : decode code ⟨8464⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8464⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8466 : decode code ⟨8466⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8466⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8467 : decode code ⟨8467⟩ = some (.LT, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8467⟩) (byte := 0x10) - (op := .LT) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8468 : decode code ⟨8468⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8468⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8469 : decode code ⟨8469⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8469⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8470 : decode code ⟨8470⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8470⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8471 : decode code ⟨8471⟩ = some (.Push .PUSH2, some (⟨8484⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8471⟩) - (n := ⟨8484⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8474 : decode code ⟨8474⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8474⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8475 : decode code ⟨8475⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8475⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8476 : decode code ⟨8476⟩ = some (.Push .PUSH1, some (⟨10⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8476⟩) - (n := ⟨10⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8478 : decode code ⟨8478⟩ = some (.DUP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8478⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8479 : decode code ⟨8479⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8479⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8481 : decode code ⟨8481⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8481⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8482 : decode code ⟨8482⟩ = some (.GT, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8482⟩) (byte := 0x11) - (op := .GT) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8483 : decode code ⟨8483⟩ = some (.ISZERO, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8483⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hlt0 : UInt256.lt (setFeeProtocolArg0Word ee) ⟨4⟩ = ⟨0⟩ := by - exact ult_zero (by simpa using hge) - have hgt1 : UInt256.gt (setFeeProtocolArg0Word ee) ⟨10⟩ = ⟨1⟩ := by - exact ugt_one (by simpa using hgt) - have rd8474 := evm_run h with [ - raw pop hd8460 (by evm_ov), - raw push1 ⟨4⟩ hd8461 (by evm_ov), - raw dup3 hd8463 (by evm_ov), - raw push1 ⟨255⟩ hd8464 (by evm_ov), - raw and hd8466 (by evm_ov), - raw lt hd8467 (by evm_ov), - raw iszero hd8468 (by evm_ov), - raw dup1 hd8469 (by evm_ov), - raw iszero hd8470 (by evm_ov), - raw push2 ⟨8484⟩ hd8471 (by evm_ov)] - rw [u256_land_comm ⟨255⟩ (setFeeProtocolArg0Word ee), - setFeeProtocolArg0Word_clean ee, hlt0] at rd8474 - have rd8475 := rd8474.jumpiNT hd8474 (by decide) (by evm_ov) - have rd8484 := evm_run rd8475 with [ - raw pop hd8475 (by evm_ov), - raw push1 ⟨10⟩ hd8476 (by evm_ov), - raw dup3 hd8478 (by evm_ov), - raw push1 ⟨255⟩ hd8479 (by evm_ov), - raw and hd8481 (by evm_ov), - raw gt hd8482 (by evm_ov), - raw iszero hd8483 (by evm_ov)] - rw [u256_land_comm ⟨255⟩ (setFeeProtocolArg0Word ee), - setFeeProtocolArg0Word_clean ee, hgt1] at rd8484 - exact ⟨_, _, by simpa using rd8484⟩ - -theorem uniswapV3PoolSetFeeProtocolFeeProtocol0DisabledReverts {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8449⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hbad : ¬ setFeeProtocolEnabledNat (setFeeProtocolArg0Word ee).toNat) - (hov : R.length + 5 ≤ 1024) : - RDrev code g s0 := by - have hne : setFeeProtocolArg0Word ee ≠ ⟨0⟩ := by - intro hzero - have hzeroNat := congrArg UInt256.toNat hzero - simp at hzeroNat - exact hbad (Or.inl hzeroNat) - obtain ⟨_, _, rd8460⟩ := - uniswapV3PoolSetFeeProtocolFeeProtocol0NonzeroTo8460 hpatch h hne hov - by_cases hge : 4 ≤ (setFeeProtocolArg0Word ee).toNat - · have hnle : ¬ (setFeeProtocolArg0Word ee).toNat ≤ 10 := by - intro hle - exact hbad (Or.inr ⟨hge, hle⟩) - obtain ⟨_, _, rd8484⟩ := - uniswapV3PoolSetFeeProtocolFeeProtocol0AboveTo8484False hpatch rd8460 hge - (Nat.lt_of_not_ge hnle) hov - exact uniswapV3PoolSetFeeProtocolFeeProtocolFalseAt8484Reverts hpatch rd8484 - (by simp only [List.length_cons]; omega) - · obtain ⟨_, _, rd8484⟩ := - uniswapV3PoolSetFeeProtocolFeeProtocol0BelowTo8484False hpatch rd8460 - (Nat.lt_of_not_ge hge) hov - exact uniswapV3PoolSetFeeProtocolFeeProtocolFalseAt8484Reverts hpatch rd8484 - (by simp only [List.length_cons]; omega) - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocolTrueAt8526To8535 {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8526⟩ (⟨1⟩ :: R) mem aw rdata acc k C) - (hov : R.length + 2 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8535⟩ R mem aw rdata acc k' C' := by - have hd8526 : decode code ⟨8526⟩ = some (.JUMPDEST, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8526⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8527 : decode code ⟨8527⟩ = some (.Push .PUSH2, some (⟨8535⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8527⟩) - (n := ⟨8535⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8530 : decode code ⟨8530⟩ = some (.JUMPI, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8530⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have rd8530 := evm_run h with [ - raw jumpdest hd8526 (by evm_ov), - raw push2 ⟨8535⟩ hd8527 (by evm_ov)] - have rd8535 := rd8530.jumpiT hd8530 (by decide) - (uniswapV3PoolJumpDestPatched8535 hpatch) (by evm_ov) - exact ⟨_, _, by simpa using rd8535⟩ - -theorem uniswapV3PoolSetFeeProtocolFeeProtocolGuardsOk {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8449⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hfee0 : setFeeProtocolEnabledNat (setFeeProtocolArg0Word ee).toNat) - (hfee1 : setFeeProtocolEnabledNat (setFeeProtocolArg1Word ee).toNat) - (hov : R.length + 5 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8535⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k' C' := by - obtain ⟨_, _, rd8484⟩ := - uniswapV3PoolSetFeeProtocolFeeProtocol0EnabledTo8484 hpatch h hfee0 hov - obtain ⟨_, _, rd8492⟩ := - uniswapV3PoolSetFeeProtocolFeeProtocolTrueAt8484To8492 hpatch rd8484 - (by simp only [List.length_cons]; omega) - obtain ⟨_, _, rd8526⟩ := - uniswapV3PoolSetFeeProtocolFeeProtocol1EnabledTo8526 hpatch rd8492 hfee1 hov - exact uniswapV3PoolSetFeeProtocolFeeProtocolTrueAt8526To8535 hpatch rd8526 - (by simp only [List.length_cons]; omega) - -theorem uniswapV3PoolSetFeeProtocolFeeProtocolGuardsRevert {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8449⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata acc k C) - (hbad : - ¬(setFeeProtocolEnabledNat (setFeeProtocolArg0Word ee).toNat ∧ - setFeeProtocolEnabledNat (setFeeProtocolArg1Word ee).toNat)) - (hov : R.length + 5 ≤ 1024) : - RDrev code g s0 := by - by_cases hfee0 : setFeeProtocolEnabledNat (setFeeProtocolArg0Word ee).toNat - · have hfee1 : ¬ setFeeProtocolEnabledNat (setFeeProtocolArg1Word ee).toNat := by - intro hfee1 - exact hbad ⟨hfee0, hfee1⟩ - obtain ⟨_, _, rd8484⟩ := - uniswapV3PoolSetFeeProtocolFeeProtocol0EnabledTo8484 hpatch h hfee0 hov - obtain ⟨_, _, rd8492⟩ := - uniswapV3PoolSetFeeProtocolFeeProtocolTrueAt8484To8492 hpatch rd8484 - (by simp only [List.length_cons]; omega) - exact uniswapV3PoolSetFeeProtocolFeeProtocol1DisabledReverts hpatch rd8492 hfee1 hov - · exact uniswapV3PoolSetFeeProtocolFeeProtocol0DisabledReverts hpatch h hfee0 hov - -theorem setFeeProtocolStoreWithOwner_feeProtocol0 (I : ExecutionEnv) (out : ByteArray) : - (setFeeProtocolStoreWithOwner I out).get? "feeProtocol0" = - some (setFeeProtocolArg0Value I) := by - rw [setFeeProtocolStoreWithOwner] - rw [store_get_ne (setFeeProtocolStore I) (.address (setFeeProtocolOwnerAddress out)) - (by decide)] - exact setFeeProtocolStore_feeProtocol0 I - -theorem setFeeProtocolStoreWithOwner_feeProtocol1 (I : ExecutionEnv) (out : ByteArray) : - (setFeeProtocolStoreWithOwner I out).get? "feeProtocol1" = - some (setFeeProtocolArg1Value I) := by - rw [setFeeProtocolStoreWithOwner] - rw [store_get_ne (setFeeProtocolStore I) (.address (setFeeProtocolOwnerAddress out)) - (by decide)] - exact setFeeProtocolStore_feeProtocol1 I - -theorem evalExpr_setFeeProtocol_feeProtocol0_withOwner {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) (out : ByteArray) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evm (.var "feeProtocol0") = .ok (setFeeProtocolArg0Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setFeeProtocolStoreWithOwner_feeProtocol0] - -theorem evalExpr_setFeeProtocol_feeProtocol1_withOwner {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) (out : ByteArray) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evm (.var "feeProtocol1") = .ok (setFeeProtocolArg1Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setFeeProtocolStoreWithOwner_feeProtocol1] - -theorem evalExpr_setFeeProtocol_feeProtocol0Enabled_true {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) (out : ByteArray) - (h : setFeeProtocolEnabledNat (setFeeProtocolArg0Word I).toNat) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evm (feeProtocolEnabled (.var "feeProtocol0")) = .ok (.bool true) := by - rcases h with hzero | hrange - · simp only [feeProtocolEnabled, orE, andE, geE, leE, eqE, evalExpr?, - evalExpr_setFeeProtocol_feeProtocol0_withOwner, bind, EvalResult.bind, evalBinaryOp?, - pure] - simp [setFeeProtocolArg0Value, hzero, BEq.beq] - · have hne : ¬(setFeeProtocolArg0Word I).toNat = 0 := by omega - simp only [feeProtocolEnabled, orE, andE, geE, leE, eqE, evalExpr?, - evalExpr_setFeeProtocol_feeProtocol0_withOwner, bind, EvalResult.bind, evalBinaryOp?, - pure] - simp [setFeeProtocolArg0Value, hne, BEq.beq, hrange.1, hrange.2] - -theorem evalExpr_setFeeProtocol_feeProtocol1Enabled_true {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) (out : ByteArray) - (h : setFeeProtocolEnabledNat (setFeeProtocolArg1Word I).toNat) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evm (feeProtocolEnabled (.var "feeProtocol1")) = .ok (.bool true) := by - rcases h with hzero | hrange - · simp only [feeProtocolEnabled, orE, andE, geE, leE, eqE, evalExpr?, - evalExpr_setFeeProtocol_feeProtocol1_withOwner, bind, EvalResult.bind, evalBinaryOp?, - pure] - simp [setFeeProtocolArg1Value, hzero, BEq.beq] - · have hne : ¬(setFeeProtocolArg1Word I).toNat = 0 := by omega - simp only [feeProtocolEnabled, orE, andE, geE, leE, eqE, evalExpr?, - evalExpr_setFeeProtocol_feeProtocol1_withOwner, bind, EvalResult.bind, evalBinaryOp?, - pure] - simp [setFeeProtocolArg1Value, hne, BEq.beq, hrange.1, hrange.2] - -theorem evalExpr_setFeeProtocol_feeProtocol0Enabled_false {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) (out : ByteArray) - (h : ¬ setFeeProtocolEnabledNat (setFeeProtocolArg0Word I).toNat) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evm (feeProtocolEnabled (.var "feeProtocol0")) = .ok (.bool false) := by - have hneZero : ¬(setFeeProtocolArg0Word I).toNat = 0 := by - intro hzero - exact h (Or.inl hzero) - have hnotRange : ¬(4 ≤ (setFeeProtocolArg0Word I).toNat ∧ - (setFeeProtocolArg0Word I).toNat ≤ 10) := by - intro hrange - exact h (Or.inr hrange) - by_cases hge : 4 ≤ (setFeeProtocolArg0Word I).toNat - · have hnotLe : ¬(setFeeProtocolArg0Word I).toNat ≤ 10 := by - intro hle - exact hnotRange ⟨hge, hle⟩ - simp only [feeProtocolEnabled, orE, andE, geE, leE, eqE, evalExpr?, - evalExpr_setFeeProtocol_feeProtocol0_withOwner, bind, EvalResult.bind, evalBinaryOp?, - pure] - simp [setFeeProtocolArg0Value, hneZero, hge, hnotLe, BEq.beq] - · simp only [feeProtocolEnabled, orE, andE, geE, leE, eqE, evalExpr?, - evalExpr_setFeeProtocol_feeProtocol0_withOwner, bind, EvalResult.bind, evalBinaryOp?, - pure] - simp [setFeeProtocolArg0Value, hneZero, hge, BEq.beq] - -theorem evalExpr_setFeeProtocol_feeProtocol1Enabled_false {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) (out : ByteArray) - (h : ¬ setFeeProtocolEnabledNat (setFeeProtocolArg1Word I).toNat) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evm (feeProtocolEnabled (.var "feeProtocol1")) = .ok (.bool false) := by - have hneZero : ¬(setFeeProtocolArg1Word I).toNat = 0 := by - intro hzero - exact h (Or.inl hzero) - have hnotRange : ¬(4 ≤ (setFeeProtocolArg1Word I).toNat ∧ - (setFeeProtocolArg1Word I).toNat ≤ 10) := by - intro hrange - exact h (Or.inr hrange) - by_cases hge : 4 ≤ (setFeeProtocolArg1Word I).toNat - · have hnotLe : ¬(setFeeProtocolArg1Word I).toNat ≤ 10 := by - intro hle - exact hnotRange ⟨hge, hle⟩ - simp only [feeProtocolEnabled, orE, andE, geE, leE, eqE, evalExpr?, - evalExpr_setFeeProtocol_feeProtocol1_withOwner, bind, EvalResult.bind, evalBinaryOp?, - pure] - simp [setFeeProtocolArg1Value, hneZero, hge, hnotLe, BEq.beq] - · simp only [feeProtocolEnabled, orE, andE, geE, leE, eqE, evalExpr?, - evalExpr_setFeeProtocol_feeProtocol1_withOwner, bind, EvalResult.bind, evalBinaryOp?, - pure] - simp [setFeeProtocolArg1Value, hneZero, hge, BEq.beq] - -theorem uniswapV3PoolSetFeeProtocolSourceFeeProtocolRequireSuccess {v : PoolImmutables} - {evm evmOwner : EVM.State} {I : ExecutionEnv} {out : ByteArray} - (howner : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evmOwner)) - (hfee0 : setFeeProtocolEnabledNat (setFeeProtocolArg0Word I).toNat) - (hfee1 : setFeeProtocolEnabledNat (setFeeProtocolArg1Word I).toNat) : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")), - .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evmOwner) := by - have hreq : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evmOwner - [ .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evmOwner) := by - refine ExecBlock.consNormal (ExecStmt.requireTrue ?_) ?_ - · simp only [andE, evalExpr?, evalExpr_setFeeProtocol_feeProtocol0Enabled_true - evmOwner I out hfee0, bind, EvalResult.bind] - rw [evalExpr_setFeeProtocol_feeProtocol1Enabled_true evmOwner I out hfee1] - rfl - · exact ExecBlock.nil - simpa using execBlock_append howner hreq - -theorem uniswapV3PoolSetFeeProtocolSourceFeeProtocolRequireRevert {v : PoolImmutables} - {evm evmOwner : EVM.State} {I : ExecutionEnv} {out : ByteArray} - (howner : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evmOwner)) - (hfee : - ¬(setFeeProtocolEnabledNat (setFeeProtocolArg0Word I).toNat ∧ - setFeeProtocolEnabledNat (setFeeProtocolArg1Word I).toNat)) : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")), - .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))) ] - .reverted := by - have hreq : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evmOwner - [ .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))) ] .reverted := by - by_cases hfee0 : setFeeProtocolEnabledNat (setFeeProtocolArg0Word I).toNat - · have hfee1 : ¬ setFeeProtocolEnabledNat (setFeeProtocolArg1Word I).toNat := by - intro hfee1 - exact hfee ⟨hfee0, hfee1⟩ - refine ExecBlock.consRevert (ExecStmt.requireFalse ?_) - simp only [andE, evalExpr?, evalExpr_setFeeProtocol_feeProtocol0Enabled_true - evmOwner I out hfee0, bind, EvalResult.bind] - rw [evalExpr_setFeeProtocol_feeProtocol1Enabled_false evmOwner I out hfee1] - rfl - · refine ExecBlock.consRevert (ExecStmt.requireFalse ?_) - simp only [andE, evalExpr?, evalExpr_setFeeProtocol_feeProtocol0Enabled_false - evmOwner I out hfee0, bind, EvalResult.bind] - rfl - simpa using execBlock_append howner hreq - -theorem uniswapV3PoolSetFeeProtocolSourceFeeProtocolRequireSuccessPrefixExact - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - {evmOwner : EVM.State} {out : ByteArray} - (hprefix : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - (initState cA gh bl σ σ₀ g A I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evmOwner)) - (hfee0 : setFeeProtocolEnabledNat (setFeeProtocolArg0Word I).toNat) - (hfee1 : setFeeProtocolEnabledNat (setFeeProtocolArg1Word I).toNat) : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - (initState cA gh bl σ σ₀ g A I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")), - .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evmOwner) := by - have hreq : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evmOwner - [ .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evmOwner) := by - refine ExecBlock.consNormal (ExecStmt.requireTrue ?_) ?_ - · simp only [andE, evalExpr?, evalExpr_setFeeProtocol_feeProtocol0Enabled_true - evmOwner I out hfee0, bind, EvalResult.bind] - rw [evalExpr_setFeeProtocol_feeProtocol1Enabled_true evmOwner I out hfee1] - rfl - · exact ExecBlock.nil - simpa using execBlock_append hprefix hreq - -theorem uniswapV3PoolSetFeeProtocolSourceFeeProtocolRequireRevertBody - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - {evmOwner : EVM.State} {out : ByteArray} - (hprefix : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - (initState cA gh bl σ σ₀ g A I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evmOwner)) - (hfee : - ¬(setFeeProtocolEnabledNat (setFeeProtocolArg0Word I).toNat ∧ - setFeeProtocolEnabledNat (setFeeProtocolArg1Word I).toNat)) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (setFeeProtocolStore I) - (setfeeprotocolTransition v).body .reverted := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (setFeeProtocolStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")), - .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))), - .letDecl "feeProtocolOld" (some uint8) (.storage (slot0F "feeProtocol")), - .assign .storage (slot0F "feeProtocol") - (addE (.var "feeProtocol0") (shlE (.var "feeProtocol1") (.intLit 4))), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted - refine ExecFuncBody.execBlockRevert ?_ - have hfeeRevert : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - (initState cA gh bl σ σ₀ g A I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")), - .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))) ] - .reverted := by - have hreq : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evmOwner - [ .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))) ] .reverted := by - by_cases hfee0 : setFeeProtocolEnabledNat (setFeeProtocolArg0Word I).toNat - · have hfee1 : ¬ setFeeProtocolEnabledNat (setFeeProtocolArg1Word I).toNat := by - intro hfee1 - exact hfee ⟨hfee0, hfee1⟩ - refine ExecBlock.consRevert (ExecStmt.requireFalse ?_) - simp only [andE, evalExpr?, evalExpr_setFeeProtocol_feeProtocol0Enabled_true - evmOwner I out hfee0, bind, EvalResult.bind] - rw [evalExpr_setFeeProtocol_feeProtocol1Enabled_false evmOwner I out hfee1] - rfl - · refine ExecBlock.consRevert (ExecStmt.requireFalse ?_) - simp only [andE, evalExpr?, evalExpr_setFeeProtocol_feeProtocol0Enabled_false - evmOwner I out hfee0, bind, EvalResult.bind] - rfl - simpa using execBlock_append hprefix hreq - exact execBlock_append_term (s2 := - [ .letDecl "feeProtocolOld" (some uint8) (.storage (slot0F "feeProtocol")), - .assign .storage (slot0F "feeProtocol") - (addE (.var "feeProtocol0") (shlE (.var "feeProtocol1") (.intLit 4))), - .assign .storage (slot0F "unlocked") (.boolLit true) ]) - hfeeRevert (by intro f e h; cases h) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocolOwnerCall.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocolOwnerCall.lean deleted file mode 100644 index c9c867c6..00000000 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocolOwnerCall.lean +++ /dev/null @@ -1,1714 +0,0 @@ -import Benchmarks.UniswapV3Pool.ImmutableGetters -import Reasoning.ExternalCall - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem setFeeProtocolExternalABIEncodeOwner {v : PoolImmutables} : - (config v).externalABI.encode? "owner" [] = some ownerSelector := by - simp [config, poolExternalABI] - -abbrev setFeeProtocolOwnerSelectorWord : UInt256 := - UInt256.shiftLeft ⟨2376452955⟩ ⟨224⟩ - -abbrev setFeeProtocolOwnerCallMem : ByteArray := - (UInt256.toByteArray setFeeProtocolOwnerSelectorWord).write 0 solcFreePtrMem 128 32 - -abbrev setFeeProtocolFactoryWord (v : PoolImmutables) : UInt256 := - EVM.Word.ofNat v.factory.toNat - -theorem setFeeProtocolFactoryAddress_eq (v : PoolImmutables) : - AccountAddress.ofUInt256 (setFeeProtocolFactoryWord v) = - AccountAddress.ofNat v.factory.toNat := by - rw [accountAddress_ofUInt256_eq_ofNat_toNat, setFeeProtocolFactoryWord, - accountAddressWord_toNat] - -theorem setFeeProtocolFactoryMask_eq_solcAddrMask : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by - native_decide - -theorem setFeeProtocolFactoryTarget_eq (v : PoolImmutables) : - UInt256.land (setFeeProtocolFactoryWord v) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩) = - setFeeProtocolFactoryWord v := by - rw [setFeeProtocolFactoryMask_eq_solcAddrMask] - apply solcAddrMask_clean - rw [setFeeProtocolFactoryWord, accountAddressWord_toNat] - change v.factory.toNat < EVM.twoPow 160 - simp [EVM.twoPow, AccountAddress.size] - -theorem setFeeProtocolOwnerSelectorWord_extract : - (UInt256.toByteArray setFeeProtocolOwnerSelectorWord).extract 0 4 = ownerSelector := by - native_decide - -theorem setFeeProtocolOwnerCallMem_read_selector : - setFeeProtocolOwnerCallMem.readWithPadding 128 4 = ownerSelector := by - rw [setFeeProtocolOwnerCallMem] - rw [toByteArray_write_read_window_of_gap - (b := setFeeProtocolOwnerSelectorWord) (mem := solcFreePtrMem) - (off := 128) (start := 0) (len := 4) - (by norm_num) (by norm_num) (by norm_num) - (by rw [solcFreePtrMem_size]; native_decide)] - exact setFeeProtocolOwnerSelectorWord_extract - -theorem setFeeProtocolOwnerCallMem_encode_owner {v : PoolImmutables} : - (config v).externalABI.encode? "owner" [] = - some (setFeeProtocolOwnerCallMem.readWithPadding 128 4) := by - rw [setFeeProtocolOwnerCallMem_read_selector] - exact setFeeProtocolExternalABIEncodeOwner - -theorem setFeeProtocolOwnerCallMem_read64 : - setFeeProtocolOwnerCallMem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by - rw [setFeeProtocolOwnerCallMem] - rw [toByteArray_write_read_below_of_gap - (b := setFeeProtocolOwnerSelectorWord) (mem := solcFreePtrMem) - (off := 128) (read := 64) - (by rw [solcFreePtrMem_size]) - (by norm_num) - (by rw [solcFreePtrMem_size]; native_decide)] - exact solcFreePtrMem_read64 - -theorem setFeeProtocolOwnerCallMem_mload64 : - (if (⟨64⟩ : UInt256).toNat ≥ setFeeProtocolOwnerCallMem.size ∨ - (⟨64⟩ : UInt256) ≥ UInt256.ofNat 5 * ⟨32⟩ then - ⟨0⟩ - else - UInt256.ofNat - (fromByteArrayBigEndian (setFeeProtocolOwnerCallMem.readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = ⟨128⟩ := by - exact mloadWordValue_of_readWithPadding (mem := setFeeProtocolOwnerCallMem) - (aw := UInt256.ofNat 5) (off := ⟨64⟩) (v := ⟨128⟩) - (by rw [setFeeProtocolOwnerCallMem]; native_decide) - (by native_decide) - setFeeProtocolOwnerCallMem_read64 - -theorem setFeeProtocolOwnerCallMem_size : - setFeeProtocolOwnerCallMem.size = 160 := by - native_decide - -abbrev setFeeProtocolOwnerStaticcallMem (o : ByteArray) : ByteArray := - o.write 0 setFeeProtocolOwnerCallMem 128 - (min (⟨32⟩ : UInt256) (UInt256.ofNat o.size)).toNat - -abbrev setFeeProtocolOwnerStaticcallActiveWords : UInt256 := - UInt256.ofNat (MachineState.M (MachineState.M (UInt256.ofNat 5).toNat 128 4) 128 32) - -theorem setFeeProtocolOwnerStaticcallWriteLen_of_size_lt (o : ByteArray) - (hshort : o.size < 32) (hhi : o.size < UInt256.size) : - (min (⟨32⟩ : UInt256) (UInt256.ofNat o.size)).toNat = o.size := by - simpa using - umin_ofNat_right_toNat_of_lt (c := 32) (n := o.size) (by decide) hshort hhi - -theorem setFeeProtocolOwnerStaticcallWriteLen_of_size_ge (o : ByteArray) - (hlo : 32 ≤ o.size) (hhi : o.size < UInt256.size) : - (min (⟨32⟩ : UInt256) (UInt256.ofNat o.size)).toNat = 32 := by - simpa using - umin_ofNat_right_toNat_of_ge (c := 32) (n := o.size) (by decide) hlo hhi - -theorem setFeeProtocolOwnerStaticcallMem_size_of_size_ge (o : ByteArray) - (hlo : 32 ≤ o.size) (hhi : o.size < UInt256.size) : - (setFeeProtocolOwnerStaticcallMem o).size = 160 := by - unfold setFeeProtocolOwnerStaticcallMem - rw [setFeeProtocolOwnerStaticcallWriteLen_of_size_ge o hlo hhi] - rw [write32_eq _ _ _ hlo (by rw [setFeeProtocolOwnerCallMem_size]; omega), - ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, setFeeProtocolOwnerCallMem_size] - omega - -theorem setFeeProtocolOwnerStaticcallMem_size_of_size_lt (o : ByteArray) - (hshort : o.size < 32) (hhi : o.size < UInt256.size) : - (setFeeProtocolOwnerStaticcallMem o).size = 160 := by - unfold setFeeProtocolOwnerStaticcallMem - rw [setFeeProtocolOwnerStaticcallWriteLen_of_size_lt o hshort hhi] - by_cases hzero : o.size = 0 - · rw [hzero, byteArray_write_len_zero] - exact setFeeProtocolOwnerCallMem_size - · rw [write_eq_gen _ _ 128 o.size hzero le_rfl - (by rw [setFeeProtocolOwnerCallMem_size]; omega)] - rw [ByteArray.size_append, ByteArray.size_append, ByteArray.size_extract, - ByteArray.size_extract, ByteArray.size_extract, setFeeProtocolOwnerCallMem_size] - omega - -theorem setFeeProtocolOwnerStaticcallMem_read64_of_size_lt (o : ByteArray) - (hshort : o.size < 32) (hhi : o.size < UInt256.size) : - (setFeeProtocolOwnerStaticcallMem o).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - unfold setFeeProtocolOwnerStaticcallMem - rw [setFeeProtocolOwnerStaticcallWriteLen_of_size_lt o hshort hhi] - by_cases hzero : o.size = 0 - · rw [hzero, byteArray_write_len_zero] - exact setFeeProtocolOwnerCallMem_read64 - · rw [write_read_below_gen _ _ 128 o.size 64 hzero le_rfl - (by rw [setFeeProtocolOwnerCallMem_size]; omega) (by omega)] - exact setFeeProtocolOwnerCallMem_read64 - -theorem setFeeProtocolOwnerStaticcallMem_read64_of_size_ge (o : ByteArray) - (hlo : 32 ≤ o.size) (hhi : o.size < UInt256.size) : - (setFeeProtocolOwnerStaticcallMem o).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - unfold setFeeProtocolOwnerStaticcallMem - rw [setFeeProtocolOwnerStaticcallWriteLen_of_size_ge o hlo hhi] - rw [write32_read_below _ _ 128 64 hlo (by rw [setFeeProtocolOwnerCallMem_size]; omega) - (by omega)] - exact setFeeProtocolOwnerCallMem_read64 - -theorem setFeeProtocolOwnerStaticcallMem_mload64_of_size_lt (o : ByteArray) - (hshort : o.size < 32) (hhi : o.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ (setFeeProtocolOwnerStaticcallMem o).size - ∨ (⟨64⟩ : UInt256) ≥ setFeeProtocolOwnerStaticcallActiveWords * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setFeeProtocolOwnerStaticcallMem o).readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩ := - mloadFreePtrValue - (by rw [setFeeProtocolOwnerStaticcallMem_size_of_size_lt o hshort hhi]; decide) - (by decide) - (setFeeProtocolOwnerStaticcallMem_read64_of_size_lt o hshort hhi) - -theorem setFeeProtocolOwnerStaticcallMem_mload64_of_size_ge (o : ByteArray) - (hlo : 32 ≤ o.size) (hhi : o.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ (setFeeProtocolOwnerStaticcallMem o).size - ∨ (⟨64⟩ : UInt256) ≥ setFeeProtocolOwnerStaticcallActiveWords * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setFeeProtocolOwnerStaticcallMem o).readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩ := - mloadFreePtrValue - (by rw [setFeeProtocolOwnerStaticcallMem_size_of_size_ge o hlo hhi]; decide) - (by decide) - (setFeeProtocolOwnerStaticcallMem_read64_of_size_ge o hlo hhi) - -theorem setFeeProtocolOwnerStaticcallMem_read128_of_size_ge (o : ByteArray) - (hlo : 32 ≤ o.size) (hhi : o.size < UInt256.size) : - (setFeeProtocolOwnerStaticcallMem o).readWithPadding 128 32 = o.extract 0 32 := by - unfold setFeeProtocolOwnerStaticcallMem - rw [setFeeProtocolOwnerStaticcallWriteLen_of_size_ge o hlo hhi] - exact write32_read_back _ _ 128 hlo (by rw [setFeeProtocolOwnerCallMem_size]; omega) - -theorem setFeeProtocolOwnerStaticcallMem_mload128_of_size_ge (o : ByteArray) - (hlo : 32 ≤ o.size) (hhi : o.size < UInt256.size) : - (if (⟨128⟩ : UInt256).toNat ≥ (setFeeProtocolOwnerStaticcallMem o).size - ∨ (⟨128⟩ : UInt256) ≥ setFeeProtocolOwnerStaticcallActiveWords * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setFeeProtocolOwnerStaticcallMem o).readWithPadding (⟨128⟩ : UInt256).toNat 32))) - = UInt256.ofNat (fromByteArrayBigEndian (o.extract 0 32)) := by - rw [if_neg] - · rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - setFeeProtocolOwnerStaticcallMem_read128_of_size_ge o hlo hhi] - · rw [not_or] - constructor - · rw [setFeeProtocolOwnerStaticcallMem_size_of_size_ge o hlo hhi] - decide - · decide - -theorem uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory {v : PoolImmutables} - {pc : UInt256} {n : Nat} (hlo : 8208 ≤ pc.toNat) (hhi : pc.toNat + n ≤ 8315) : - ∀ p ∈ patches v, pc.toNat + n ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -theorem uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory {v : PoolImmutables} - {pc : UInt256} {n : Nat} (hlo : 8347 ≤ pc.toNat) (hhi : pc.toNat + n ≤ 8829) : - ∀ p ∈ patches v, pc.toNat + n ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -theorem uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 2 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 2 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x60) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1)) = n) : - decode code pc = some (.Push .PUSH1, some (n, 1)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + 1) = - uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1) := by - unfold ByteArray.extract' - have hguard : - (decide (pc.toNat.succ < 2 ^ 64) && decide (pc.toNat.succ + 1 < 2 ^ 64)) = - true := by - rw [Bool.and_eq_true] - constructor <;> rw [decide_eq_true_eq] <;> omega - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq (start := pc.toNat.succ) (stop := pc.toNat.succ + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl hbefore - · exact Or.inr (by omega)) - hpatch - have hgetSome : code.get? pc.toNat = some 0x60 := by - rw [hget, hgetTemplate] - have hparse : (some (0x60 : UInt8) >>= parseInstr) = some (.Push .PUSH1) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH1, - some (uInt256OfByteArray (code.extract' pc.toNat.succ (pc.toNat.succ + 1)), 1)) = - some (Operation.Push Operation.POp.PUSH1, some (n, 1)) - rw [hextract, hval] - -theorem uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush2 {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 3 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 3 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x61) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 2)) = n) : - decode code pc = some (.Push .PUSH2, some (n, 2)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + 2) = - uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 2) := by - unfold ByteArray.extract' - have hguard : - (decide (pc.toNat.succ < 2 ^ 64) && decide (pc.toNat.succ + 2 < 2 ^ 64)) = - true := by - rw [Bool.and_eq_true] - constructor <;> rw [decide_eq_true_eq] <;> omega - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq (start := pc.toNat.succ) (stop := pc.toNat.succ + 2) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl hbefore - · exact Or.inr (by omega)) - hpatch - have hgetSome : code.get? pc.toNat = some 0x61 := by - rw [hget, hgetTemplate] - have hparse : (some (0x61 : UInt8) >>= parseInstr) = some (.Push .PUSH2) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH2, - some (uInt256OfByteArray (code.extract' pc.toNat.succ (pc.toNat.succ + 2)), 2)) = - some (Operation.Push Operation.POp.PUSH2, some (n, 2)) - rw [hextract, hval] - -theorem uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush4 {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 5 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 5 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x63) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 4)) = n) : - decode code pc = some (.Push .PUSH4, some (n, 4)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + 4) = - uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 4) := by - unfold ByteArray.extract' - have hguard : - (decide (pc.toNat.succ < 2 ^ 64) && decide (pc.toNat.succ + 4 < 2 ^ 64)) = - true := by - rw [Bool.and_eq_true] - constructor <;> rw [decide_eq_true_eq] <;> omega - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq (start := pc.toNat.succ) (stop := pc.toNat.succ + 4) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl hbefore - · exact Or.inr (by omega)) - hpatch - have hgetSome : code.get? pc.toNat = some 0x63 := by - rw [hget, hgetTemplate] - have hparse : (some (0x63 : UInt8) >>= parseInstr) = some (.Push .PUSH4) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH4, - some (uInt256OfByteArray (code.extract' pc.toNat.succ (pc.toNat.succ + 4)), 4)) = - some (Operation.Push Operation.POp.PUSH4, some (n, 4)) - rw [hextract, hval] - -theorem uniswapV3PoolSetFeeProtocolOwnerCallSetup {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8290⟩ R solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hov : R.length + 8 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8348⟩ - (setFeeProtocolFactoryWord v :: ⟨128⟩ :: ⟨128⟩ :: R) - setFeeProtocolOwnerCallMem (UInt256.ofNat 5) rdata (cA, σ) k' C' := by - have hd8347 : decode code ⟨8347⟩ = some (.AND, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8347⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8314 : - decode code ⟨8314⟩ = - some (.Push .PUSH32, some (setFeeProtocolFactoryWord v, 32)) := by - simpa [setFeeProtocolFactoryWord] using - uniswapV3PoolFactoryConstDecode8314 (v := v) (code := code) hpatch - have rd8348Pre := evm_run h with [ - raw push1 ⟨64⟩ (by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8290⟩) - (n := ⟨64⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide)) (by omega), - raw dup1 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8292⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by omega), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8293⟩) (byte := 0x51) - (op := .MLOAD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - mem_cost solcFreePtrMem_mload64 (by decide) - (by simp only [List.length_cons]; omega), - raw push4 ⟨2376452955⟩ (by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush4 (pc := ⟨8294⟩) - (n := ⟨2376452955⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 5) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide)) (by simp only [List.length_cons]; omega), - raw push1 ⟨224⟩ (by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8299⟩) - (n := ⟨224⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide)) (by simp only [List.length_cons]; omega), - raw shl (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8301⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw dup2 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8302⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw mstore 6 setFeeProtocolOwnerCallMem (UInt256.ofNat 5) (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8303⟩) (byte := 0x52) - (op := .MSTORE) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - mem_cost (by rfl) (by decide) (by simp only [List.length_cons]; omega), - raw swap1 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8304⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by omega), - raw mload 0 ⟨128⟩ (UInt256.ofNat 5) (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8305⟩) (byte := 0x51) - (op := .MLOAD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - mem_cost setFeeProtocolOwnerCallMem_mload64 (by decide) - (by simp only [List.length_cons]; omega), - raw push1 ⟨1⟩ (by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8306⟩) - (n := ⟨1⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide)) (by simp only [List.length_cons]; omega), - raw push1 ⟨1⟩ (by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8308⟩) - (n := ⟨1⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide)) (by simp only [List.length_cons]; omega), - raw push1 ⟨160⟩ (by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8310⟩) - (n := ⟨160⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide)) (by simp only [List.length_cons]; omega), - raw shl (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8312⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw sub (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8313⟩) (byte := 0x03) - (op := .SUB) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointBeforeFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw pushConst (setFeeProtocolFactoryWord v) - (show Operation.POp.PUSH32 ≠ .PUSH0 by native_decide) - hd8314 - (by simp only [List.length_cons]; omega), - raw and (by simpa using hd8347) (by simp only [List.length_cons]; omega)] - rw [setFeeProtocolFactoryTarget_eq v] at rd8348Pre - exact ⟨_, _, rd8348Pre⟩ - -theorem uniswapV3PoolSetFeeProtocolOwnerCallGuardSetup {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8348⟩ - (setFeeProtocolFactoryWord v :: ⟨128⟩ :: ⟨128⟩ :: R) - setFeeProtocolOwnerCallMem (UInt256.ofNat 5) rdata (cA, σ) k C) - (hov : R.length + 9 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8373⟩ - (setFeeProtocolFactoryWord v :: setFeeProtocolFactoryWord v :: ⟨128⟩ :: ⟨4⟩ :: - ⟨128⟩ :: ⟨32⟩ :: ⟨132⟩ :: ⟨2376452955⟩ :: setFeeProtocolFactoryWord v :: R) - setFeeProtocolOwnerCallMem (UInt256.ofNat 5) rdata (cA, σ) k' C' := by - have rd8373 := evm_run h with [ - raw swap2 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8348⟩) (byte := 0x91) - (op := .SWAP2) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by omega), - raw push4 ⟨2376452955⟩ (by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush4 (pc := ⟨8349⟩) - (n := ⟨2376452955⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 5) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide)) (by simp only [List.length_cons]; omega), - raw swap2 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8354⟩) (byte := 0x91) - (op := .SWAP2) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw push1 ⟨4⟩ (by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8355⟩) - (n := ⟨4⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide)) (by simp only [List.length_cons]; omega), - raw dup1 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8357⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw dup4 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8358⟩) (byte := 0x83) - (op := .DUP4) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw add (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8359⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw swap3 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8360⟩) (byte := 0x92) - (op := .SWAP3) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw push1 ⟨32⟩ (by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8361⟩) - (n := ⟨32⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide)) (by simp only [List.length_cons]; omega), - raw swap3 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8363⟩) (byte := 0x92) - (op := .SWAP3) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw swap2 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8364⟩) (byte := 0x91) - (op := .SWAP2) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw swap1 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8365⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw dup3 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8366⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw swap1 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8367⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw sub (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8368⟩) (byte := 0x03) - (op := .SUB) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw add (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8369⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw dup2 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8370⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega), - raw dup7 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8371⟩) (byte := 0x86) - (op := .DUP7) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by omega), - raw dup1 (by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8372⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide)) - (by simp only [List.length_cons]; omega)] - exact ⟨_, _, rd8373⟩ - -private theorem uniswapV3PoolPatchPreservesJumpDest8385 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨8385⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest8405 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨8405⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest8427 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨8427⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolPatchPreservesJumpDest8449 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨8449⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched8385 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨8385⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest8385 - -theorem uniswapV3PoolJumpDestPatched8405 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨8405⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest8405 - -theorem uniswapV3PoolJumpDestPatched8427 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨8427⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest8427 - -theorem uniswapV3PoolJumpDestPatched8449 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨8449⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest8449 - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolOwnerExtcodesizeMissingReverts {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8373⟩ - (setFeeProtocolFactoryWord v :: setFeeProtocolFactoryWord v :: ⟨128⟩ :: ⟨4⟩ :: - ⟨128⟩ :: ⟨32⟩ :: ⟨132⟩ :: ⟨2376452955⟩ :: setFeeProtocolFactoryWord v :: R) - setFeeProtocolOwnerCallMem (UInt256.ofNat 5) rdata (cA, σ) k C) - (hcodeSize : - Reasoning.Theory.extCodeSizeWord σ (setFeeProtocolFactoryWord v) = ⟨0⟩) - (hov : R.length + 11 ≤ 1024) : - RDrev code g s0 := by - have hd8373 : decode code ⟨8373⟩ = some (.EXTCODESIZE, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8373⟩) (byte := 0x3b) - (op := .EXTCODESIZE) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8374 : decode code ⟨8374⟩ = some (.ISZERO, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8374⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8375 : decode code ⟨8375⟩ = some (.DUP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8375⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8376 : decode code ⟨8376⟩ = some (.ISZERO, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8376⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8377 : decode code ⟨8377⟩ = some (.Push .PUSH2, some (⟨8385⟩, 2)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush2 (pc := ⟨8377⟩) - (n := ⟨8385⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 3) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8380 : decode code ⟨8380⟩ = some (.JUMPI, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8380⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8381 : decode code ⟨8381⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8381⟩) - (n := ⟨0⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8383 : decode code ⟨8383⟩ = some (.DUP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8383⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8384 : decode code ⟨8384⟩ = some (.REVERT, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8384⟩) (byte := 0xfd) - (op := .REVERT) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - exact RD.solcExtcodesizeGuardMissing (pc := ⟨8373⟩) (okPc := ⟨8385⟩) h - hcodeSize hd8373 (by simpa using hd8374) (by simpa using hd8375) - (by simpa using hd8376) (by simpa using hd8377) (by simpa using hd8380) - (by simpa using hd8381) (by simpa using hd8383) (by simpa using hd8384) - (by simp only [List.length_cons]; omega) - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolOwnerStaticcallMade {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8373⟩ - (setFeeProtocolFactoryWord v :: setFeeProtocolFactoryWord v :: ⟨128⟩ :: ⟨4⟩ :: - ⟨128⟩ :: ⟨32⟩ :: ⟨132⟩ :: ⟨2376452955⟩ :: setFeeProtocolFactoryWord v :: R) - setFeeProtocolOwnerCallMem (UInt256.ofNat 5) rdata (cA, σ) k C) - (hcodeSize : - Reasoning.Theory.extCodeSizeWord σ (setFeeProtocolFactoryWord v) ≠ ⟨0⟩) - (hdepth : ee.depth.val < 1024) - (hov : R.length + 11 ≤ 1024) : - ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) - (z : Bool) (o : ByteArray) (A_in : Substate) (callGas : UInt256) (k' C' : ℕ), - (∃ (g'' : UInt256) (A' : Substate), - (cA', σ', g'', A', z, o) = Ethereum.EVM.Θ ee.blobVersionedHashes cA - s0.genesisBlockHeader s0.blocks σ s0.σ₀ A_in - (AccountAddress.ofUInt256 (UInt256.ofNat ee.codeOwner)) ee.sender - (AccountAddress.ofUInt256 (setFeeProtocolFactoryWord v)) - (toExecute σ (AccountAddress.ofUInt256 (setFeeProtocolFactoryWord v))) - callGas (UInt256.ofNat ee.gasPrice) ⟨0⟩ ⟨0⟩ - (setFeeProtocolOwnerCallMem.readWithPadding 128 4) (ee.depth + 1) ee.header false) - ∧ RD code ee g s0 ⟨8389⟩ - ((if z then (⟨1⟩ : UInt256) else ⟨0⟩) :: ⟨132⟩ :: ⟨2376452955⟩ :: - setFeeProtocolFactoryWord v :: R) - (setFeeProtocolOwnerStaticcallMem o) setFeeProtocolOwnerStaticcallActiveWords o - (cA', σ') k' C' - ∧ o.size < UInt256.size := by - have hd8373 : decode code ⟨8373⟩ = some (.EXTCODESIZE, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8373⟩) (byte := 0x3b) - (op := .EXTCODESIZE) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8374 : decode code ⟨8374⟩ = some (.ISZERO, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8374⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8375 : decode code ⟨8375⟩ = some (.DUP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8375⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8376 : decode code ⟨8376⟩ = some (.ISZERO, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8376⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8377 : decode code ⟨8377⟩ = some (.Push .PUSH2, some (⟨8385⟩, 2)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush2 (pc := ⟨8377⟩) - (n := ⟨8385⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 3) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8380 : decode code ⟨8380⟩ = some (.JUMPI, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8380⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8385 : decode code ⟨8385⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8385⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8386 : decode code ⟨8386⟩ = some (.POP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8386⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8387 : decode code ⟨8387⟩ = some (.GAS, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8387⟩) (byte := 0x5a) - (op := .GAS) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8388 : decode code ⟨8388⟩ = some (.STATICCALL, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8388⟩) (byte := 0xfa) - (op := .STATICCALL) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - obtain ⟨gasWord, kGas, CGas, rd8388⟩ := - RD.solcExtcodesizeGuardOkGas (pc := ⟨8373⟩) (okPc := ⟨8385⟩) h hcodeSize - hd8373 (by simpa using hd8374) (by simpa using hd8375) (by simpa using hd8376) - (by simpa using hd8377) (by simpa using hd8380) - (uniswapV3PoolJumpDestPatched8385 hpatch) (by simpa using hd8385) - (by simpa using hd8386) (by simpa using hd8387) - (by simp only [List.length_cons]; omega) - obtain ⟨cA', σ', z, o, A_in, callGas, k', C', hΘ, rd8389, hoSize⟩ := - RD.solcStaticcall rd8388 (by simpa using hd8388) hdepth - (by simp only [List.length_cons]; omega) - exact ⟨cA', σ', z, o, A_in, callGas, k', C', - hΘ, - by - simpa [setFeeProtocolOwnerStaticcallMem, setFeeProtocolOwnerStaticcallActiveWords] - using rd8389, - hoSize⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolOwnerTypedStaticcallMade {v : PoolImmutables} - {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} {s0 : State} - {R : List UInt256} {rdata : ByteArray} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hs0Genesis : s0.genesisBlockHeader = gh) - (hs0Blocks : s0.blocks = bl) - (hs0Original : s0.σ₀ = σ₀) - (h : RD code I g s0 ⟨8373⟩ - (setFeeProtocolFactoryWord v :: setFeeProtocolFactoryWord v :: ⟨128⟩ :: ⟨4⟩ :: - ⟨128⟩ :: ⟨32⟩ :: ⟨132⟩ :: ⟨2376452955⟩ :: setFeeProtocolFactoryWord v :: R) - setFeeProtocolOwnerCallMem (UInt256.ofNat 5) rdata (cA, σ) k C) - (hcodeSize : - Reasoning.Theory.extCodeSizeWord σ (setFeeProtocolFactoryWord v) ≠ ⟨0⟩) - (hdepth : I.depth.val < 1024) - (hov : R.length + 11 ≤ 1024) : - ∃ (cA' : Batteries.RBSet AccountAddress compare) (σ' : AccountMap) - (z : Bool) (o : ByteArray) (A' : Substate) (k' C' : ℕ), - RD code I g s0 ⟨8389⟩ - ((if z then (⟨1⟩ : UInt256) else ⟨0⟩) :: ⟨132⟩ :: ⟨2376452955⟩ :: - setFeeProtocolFactoryWord v :: R) - (setFeeProtocolOwnerStaticcallMem o) setFeeProtocolOwnerStaticcallActiveWords o - (cA', σ') k' C' - ∧ typedCallViaEVM (config v) (initState cA gh bl σ σ₀ g A I) - (EVM.address (AccountAddress.ofNat v.factory.toNat)) "owner" 0 [] - (z, - { initState cA gh bl σ σ₀ g A I with - accountMap := σ', substate := A', createdAccounts := cA' }, - o) false - ∧ o.size < UInt256.size := by - obtain ⟨cA', σ', z, o, A_in, callGas, k', C', hΘpack, rd8389, hoSize⟩ := - uniswapV3PoolSetFeeProtocolOwnerStaticcallMade (v := v) (code := code) - (ee := I) (g := g) (s0 := s0) - (R := R) (rdata := rdata) (cA := cA) (σ := σ) - hpatch h hcodeSize hdepth hov - obtain ⟨g'', A', hΘ⟩ := hΘpack - refine ⟨cA', σ', z, o, A', k', C', rd8389, ?_, hoSize⟩ - refine callCoincides (A_in := A_in) (g'' := g'') (callGas := callGas) - (callPerm := false) (targetWord := setFeeProtocolFactoryWord v) - (mem := setFeeProtocolOwnerCallMem) (inOff := ⟨128⟩) (inSize := ⟨4⟩) - (fun hdepthEq => - absurd hdepth (by - rw [show I.depth = (1024 : Fin 1025) from hdepthEq] - decide)) - (by - have hAddressId (a : AccountAddress) : EVM.address a = a := by - apply Fin.ext - show ↑a % EVM.twoPow 160 = ↑a - rw [Nat.mod_eq_of_lt] - exact a.isLt - rw [setFeeProtocolFactoryAddress_eq] - exact hAddressId (AccountAddress.ofNat v.factory.toNat)) - (setFeeProtocolOwnerCallMem_encode_owner (v := v)) - (by simpa [initState, hs0Genesis, hs0Blocks, hs0Original] using hΘ) - -theorem uniswapV3PoolSetFeeProtocolOwnerStaticcallStatusGuard {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {o mem : ByteArray} {aw : UInt256} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} {z : Bool} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8389⟩ - ((if z then (⟨1⟩ : UInt256) else ⟨0⟩) :: ⟨132⟩ :: ⟨2376452955⟩ :: - setFeeProtocolFactoryWord v :: R) - mem aw o acc k C) - (hoSize : o.size < UInt256.size) - (hov : R.length + 8 ≤ 1024) : - (z = true → - ∃ k' C', RD code ee g s0 ⟨8407⟩ - (⟨132⟩ :: ⟨2376452955⟩ :: setFeeProtocolFactoryWord v :: R) - mem aw o acc k' C') ∧ - (z = false → RDrev code g s0) := by - have hd8389 : decode code ⟨8389⟩ = some (.ISZERO, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8389⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8390 : decode code ⟨8390⟩ = some (.DUP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8390⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8391 : decode code ⟨8391⟩ = some (.ISZERO, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8391⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8392 : decode code ⟨8392⟩ = some (.Push .PUSH2, some (⟨8405⟩, 2)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush2 (pc := ⟨8392⟩) - (n := ⟨8405⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 3) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8395 : decode code ⟨8395⟩ = some (.JUMPI, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8395⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8396 : decode code ⟨8396⟩ = some (.RETURNDATASIZE, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8396⟩) (byte := 0x3d) - (op := .RETURNDATASIZE) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8397 : decode code ⟨8397⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8397⟩) - (n := ⟨0⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8399 : decode code ⟨8399⟩ = some (.DUP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8399⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8400 : decode code ⟨8400⟩ = some (.RETURNDATACOPY, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8400⟩) (byte := 0x3e) - (op := .RETURNDATACOPY) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8401 : decode code ⟨8401⟩ = some (.RETURNDATASIZE, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8401⟩) (byte := 0x3d) - (op := .RETURNDATASIZE) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8402 : decode code ⟨8402⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8402⟩) - (n := ⟨0⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8404 : decode code ⟨8404⟩ = some (.REVERT, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8404⟩) (byte := 0xfd) - (op := .REVERT) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8405 : decode code ⟨8405⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8405⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8406 : decode code ⟨8406⟩ = some (.POP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8406⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - constructor - · intro hz - have hstatus : (if z then (⟨1⟩ : UInt256) else ⟨0⟩) ≠ ⟨0⟩ := by - rw [hz] - decide - exact RD.solcCallSuccessGuardOk (pc := ⟨8389⟩) (okPc := ⟨8405⟩) h hstatus - hd8389 (by simpa using hd8390) (by simpa using hd8391) (by simpa using hd8392) - (by simpa using hd8395) (uniswapV3PoolJumpDestPatched8405 hpatch) - (by simpa using hd8405) (by simpa using hd8406) - (by simp only [List.length_cons]; omega) - · intro hz - have hstatus : (if z then (⟨1⟩ : UInt256) else ⟨0⟩) = ⟨0⟩ := by - rw [hz] - rfl - refine RD.solcCallSuccessGuardMissing (pc := ⟨8389⟩) (okPc := ⟨8405⟩) h hstatus - hd8389 (by simpa using hd8390) (by simpa using hd8391) (by simpa using hd8392) - (by simpa using hd8395) (by simpa using hd8396) (by simpa using hd8397) - (by simpa using hd8399) (by simpa using hd8400) (by simpa using hd8401) - (by simpa using hd8402) (by simpa using hd8404) ?_ ?_ - · exact hoSize - · simp only [List.length_cons] - omega - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolOwnerReturnDecodeShortReverts {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {o : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8407⟩ - (⟨132⟩ :: ⟨2376452955⟩ :: setFeeProtocolFactoryWord v :: R) - (setFeeProtocolOwnerStaticcallMem o) setFeeProtocolOwnerStaticcallActiveWords o acc k C) - (hshort : o.size < 32) (hhi : o.size < UInt256.size) - (hov : R.length + 4 ≤ 1024) : - RDrev code g s0 := by - have hd8407 : decode code ⟨8407⟩ = some (.POP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8407⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8408 : decode code ⟨8408⟩ = some (.POP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8408⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8409 : decode code ⟨8409⟩ = some (.POP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8409⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8410 : decode code ⟨8410⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8410⟩) - (n := ⟨64⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8412 : decode code ⟨8412⟩ = some (.MLOAD, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8412⟩) (byte := 0x51) - (op := .MLOAD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8413 : decode code ⟨8413⟩ = some (.RETURNDATASIZE, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8413⟩) (byte := 0x3d) - (op := .RETURNDATASIZE) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8414 : decode code ⟨8414⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8414⟩) - (n := ⟨32⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8416 : decode code ⟨8416⟩ = some (.DUP2, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8416⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8417 : decode code ⟨8417⟩ = some (.LT, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8417⟩) (byte := 0x10) - (op := .LT) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8418 : decode code ⟨8418⟩ = some (.ISZERO, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8418⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8419 : decode code ⟨8419⟩ = some (.Push .PUSH2, some (⟨8427⟩, 2)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush2 (pc := ⟨8419⟩) - (n := ⟨8427⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 3) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8422 : decode code ⟨8422⟩ = some (.JUMPI, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8422⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8423 : decode code ⟨8423⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8423⟩) - (n := ⟨0⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8425 : decode code ⟨8425⟩ = some (.DUP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8425⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8426 : decode code ⟨8426⟩ = some (.REVERT, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8426⟩) (byte := 0xfd) - (op := .REVERT) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - exact RD.solcUint256ReturnWordDecodeShortReverts h hshort hhi - (fun s haw hstk => by - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', Cₘ, haw, hstk] - native_decide) - (by native_decide) - (setFeeProtocolOwnerStaticcallMem_mload64_of_size_lt o hshort hhi) - hd8407 - (by simpa [show (⟨8407⟩ : UInt256) + ⟨1⟩ = ⟨8408⟩ by native_decide] using hd8408) - (by simpa [show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ = ⟨8409⟩ by native_decide] - using hd8409) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ = ⟨8410⟩ by native_decide] - using hd8410) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 = - ⟨8412⟩ by native_decide] - using hd8412) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ = - ⟨8413⟩ by native_decide] - using hd8413) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + - ⟨1⟩ = ⟨8414⟩ by native_decide] - using hd8414) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + - ⟨1⟩ + UInt256.ofNat 2 = ⟨8416⟩ by native_decide] - using hd8416) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + - ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ = ⟨8417⟩ by native_decide] - using hd8417) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + - ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ = ⟨8418⟩ by native_decide] - using hd8418) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + - ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ = ⟨8419⟩ by native_decide] - using hd8419) - (by simpa [ - show ((⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + - ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) + UInt256.ofNat 3 = - ⟨8422⟩ by native_decide] - using hd8422) - (by simpa [ - show (((⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) + - UInt256.ofNat 3) + ⟨1⟩ = ⟨8423⟩ by native_decide] - using hd8423) - (by simpa [ - show ((((⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) + - UInt256.ofNat 3) + ⟨1⟩) + UInt256.ofNat 2 = ⟨8425⟩ by native_decide] - using hd8425) - (by simpa [ - show (((((⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + - ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) + - UInt256.ofNat 3) + ⟨1⟩) + UInt256.ofNat 2) + ⟨1⟩ = - ⟨8426⟩ by native_decide] - using hd8426) - hov - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolOwnerReturnDecodeOk {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {o : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8407⟩ - (⟨132⟩ :: ⟨2376452955⟩ :: setFeeProtocolFactoryWord v :: R) - (setFeeProtocolOwnerStaticcallMem o) setFeeProtocolOwnerStaticcallActiveWords o acc k C) - (hlo : 32 ≤ o.size) (hhi : o.size < UInt256.size) - (hov : R.length + 4 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8430⟩ - (UInt256.ofNat (fromByteArrayBigEndian (o.extract 0 32)) :: R) - (setFeeProtocolOwnerStaticcallMem o) setFeeProtocolOwnerStaticcallActiveWords o acc k' C' := by - have hd8407 : decode code ⟨8407⟩ = some (.POP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8407⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8408 : decode code ⟨8408⟩ = some (.POP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8408⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8409 : decode code ⟨8409⟩ = some (.POP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8409⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8410 : decode code ⟨8410⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8410⟩) - (n := ⟨64⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8412 : decode code ⟨8412⟩ = some (.MLOAD, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8412⟩) (byte := 0x51) - (op := .MLOAD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8413 : decode code ⟨8413⟩ = some (.RETURNDATASIZE, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8413⟩) (byte := 0x3d) - (op := .RETURNDATASIZE) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8414 : decode code ⟨8414⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8414⟩) - (n := ⟨32⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8416 : decode code ⟨8416⟩ = some (.DUP2, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8416⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8417 : decode code ⟨8417⟩ = some (.LT, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8417⟩) (byte := 0x10) - (op := .LT) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8418 : decode code ⟨8418⟩ = some (.ISZERO, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8418⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8419 : decode code ⟨8419⟩ = some (.Push .PUSH2, some (⟨8427⟩, 2)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush2 (pc := ⟨8419⟩) - (n := ⟨8427⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 3) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8422 : decode code ⟨8422⟩ = some (.JUMPI, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8422⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8427 : decode code ⟨8427⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8427⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8428 : decode code ⟨8428⟩ = some (.POP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8428⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8429 : decode code ⟨8429⟩ = some (.MLOAD, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8429⟩) (byte := 0x51) - (op := .MLOAD) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - simpa [show (⟨8427⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ = ⟨8430⟩ by native_decide] - using RD.solcUint256ReturnWordDecodeOk h hlo hhi - (fun s haw hstk => by - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', Cₘ, haw, hstk] - native_decide) - (by native_decide) - (setFeeProtocolOwnerStaticcallMem_mload64_of_size_ge o hlo hhi) - (setFeeProtocolOwnerStaticcallMem_mload128_of_size_ge o hlo hhi) - (fun s haw hstk => by - simp [memoryExpansionCost, memoryExpansionCost.μᵢ', Cₘ, haw, hstk] - native_decide) - (by native_decide) - hd8407 - (by simpa [show (⟨8407⟩ : UInt256) + ⟨1⟩ = ⟨8408⟩ by native_decide] using hd8408) - (by simpa [show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ = ⟨8409⟩ by native_decide] - using hd8409) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ = ⟨8410⟩ by native_decide] - using hd8410) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 = - ⟨8412⟩ by native_decide] - using hd8412) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ = - ⟨8413⟩ by native_decide] - using hd8413) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + - ⟨1⟩ = ⟨8414⟩ by native_decide] - using hd8414) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + - ⟨1⟩ + UInt256.ofNat 2 = ⟨8416⟩ by native_decide] - using hd8416) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + - ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ = ⟨8417⟩ by native_decide] - using hd8417) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + - ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ = ⟨8418⟩ by native_decide] - using hd8418) - (by simpa [ - show (⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + - ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ = ⟨8419⟩ by native_decide] - using hd8419) - (by simpa [ - show ((⟨8407⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + - ⟨1⟩ + UInt256.ofNat 2 + ⟨1⟩ + ⟨1⟩ + ⟨1⟩) + UInt256.ofNat 3 = - ⟨8422⟩ by native_decide] - using hd8422) - (uniswapV3PoolJumpDestPatched8427 hpatch) - hd8427 - (by simpa [show (⟨8427⟩ : UInt256) + ⟨1⟩ = ⟨8428⟩ by native_decide] using hd8428) - (by simpa [show (⟨8427⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ = ⟨8429⟩ by native_decide] - using hd8429) - hov - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolOwnerCallerGuardOk {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {owner : UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8430⟩ (owner :: R) mem aw rdata acc k C) - (hcaller : UInt256.land solcAddrMask owner = solcSourceWord ee) - (hov : R.length + 4 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8449⟩ R mem aw rdata acc k' C' := by - have hd8430 : decode code ⟨8430⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8430⟩) - (n := ⟨1⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8432 : decode code ⟨8432⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8432⟩) - (n := ⟨1⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8434 : decode code ⟨8434⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8434⟩) - (n := ⟨160⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8436 : decode code ⟨8436⟩ = some (.SHL, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8436⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8437 : decode code ⟨8437⟩ = some (.SUB, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8437⟩) (byte := 0x03) - (op := .SUB) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8438 : decode code ⟨8438⟩ = some (.AND, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8438⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8439 : decode code ⟨8439⟩ = some (.CALLER, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8439⟩) (byte := 0x33) - (op := .CALLER) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8440 : decode code ⟨8440⟩ = some (.EQ, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8440⟩) (byte := 0x14) - (op := .EQ) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8441 : decode code ⟨8441⟩ = some (.Push .PUSH2, some (⟨8449⟩, 2)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush2 (pc := ⟨8441⟩) - (n := ⟨8449⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 3) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8444 : decode code ⟨8444⟩ = some (.JUMPI, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8444⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask := by - exact setFeeProtocolFactoryMask_eq_solcAddrMask - have heq : - UInt256.eq (solcSourceWord ee) (UInt256.land solcAddrMask owner) ≠ ⟨0⟩ := by - rw [hcaller, u256_eq_refl] - decide - have rd8444 := evm_run h with [ - raw push1 ⟨1⟩ hd8430 (by evm_ov), - raw push1 ⟨1⟩ hd8432 (by evm_ov), - raw push1 ⟨160⟩ hd8434 (by evm_ov), - raw shl hd8436 (by evm_ov), - raw sub hd8437 (by evm_ov), - raw and hd8438 (by evm_ov), - raw caller hd8439 (by evm_ov), - raw eq hd8440 (by evm_ov), - raw push2 ⟨8449⟩ hd8441 (by evm_ov)] - rw [hmask] at rd8444 - have rd8449 := rd8444.jumpiT hd8444 heq (uniswapV3PoolJumpDestPatched8449 hpatch) - (by evm_ov) - exact ⟨_, _, rd8449⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolOwnerCallerGuardReverts {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {owner : UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8430⟩ (owner :: R) mem aw rdata acc k C) - (hcaller : UInt256.land solcAddrMask owner ≠ solcSourceWord ee) - (hov : R.length + 4 ≤ 1024) : - RDrev code g s0 := by - have hd8430 : decode code ⟨8430⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8430⟩) - (n := ⟨1⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8432 : decode code ⟨8432⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8432⟩) - (n := ⟨1⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8434 : decode code ⟨8434⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8434⟩) - (n := ⟨160⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8436 : decode code ⟨8436⟩ = some (.SHL, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8436⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8437 : decode code ⟨8437⟩ = some (.SUB, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8437⟩) (byte := 0x03) - (op := .SUB) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8438 : decode code ⟨8438⟩ = some (.AND, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8438⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8439 : decode code ⟨8439⟩ = some (.CALLER, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8439⟩) (byte := 0x33) - (op := .CALLER) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8440 : decode code ⟨8440⟩ = some (.EQ, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8440⟩) (byte := 0x14) - (op := .EQ) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8441 : decode code ⟨8441⟩ = some (.Push .PUSH2, some (⟨8449⟩, 2)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush2 (pc := ⟨8441⟩) - (n := ⟨8449⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 3) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8444 : decode code ⟨8444⟩ = some (.JUMPI, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8444⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8445 : decode code ⟨8445⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush1 (pc := ⟨8445⟩) - (n := ⟨0⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 2) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8447 : decode code ⟨8447⟩ = some (.DUP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8447⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8448 : decode code ⟨8448⟩ = some (.REVERT, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8448⟩) (byte := 0xfd) - (op := .REVERT) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - solcAddrMask := by - exact setFeeProtocolFactoryMask_eq_solcAddrMask - have heq : - UInt256.eq (solcSourceWord ee) (UInt256.land solcAddrMask owner) = ⟨0⟩ := by - apply u256_eq_of_ne - intro hbad - exact hcaller hbad.symm - have rd8444 := evm_run h with [ - raw push1 ⟨1⟩ hd8430 (by evm_ov), - raw push1 ⟨1⟩ hd8432 (by evm_ov), - raw push1 ⟨160⟩ hd8434 (by evm_ov), - raw shl hd8436 (by evm_ov), - raw sub hd8437 (by evm_ov), - raw and hd8438 (by evm_ov), - raw caller hd8439 (by evm_ov), - raw eq hd8440 (by evm_ov), - raw push2 ⟨8449⟩ hd8441 (by evm_ov)] - rw [hmask, heq] at rd8444 - have rd8445 := rd8444.jumpiNT hd8444 (by decide) (by evm_ov) - exact RD.solcPush1Dup1Revert0 rd8445 hd8445 - (by simpa [show (⟨8445⟩ : UInt256) + UInt256.ofNat 2 = ⟨8447⟩ by native_decide] - using hd8447) - (by simpa [ - show (⟨8445⟩ : UInt256) + UInt256.ofNat 2 + ⟨1⟩ = ⟨8448⟩ by native_decide] - using hd8448) - (by omega) - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolOwnerStaticcallDepthLimitReverts {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8373⟩ - (setFeeProtocolFactoryWord v :: setFeeProtocolFactoryWord v :: ⟨128⟩ :: ⟨4⟩ :: - ⟨128⟩ :: ⟨32⟩ :: ⟨132⟩ :: ⟨2376452955⟩ :: setFeeProtocolFactoryWord v :: R) - setFeeProtocolOwnerCallMem (UInt256.ofNat 5) rdata (cA, σ) k C) - (hcodeSize : - Reasoning.Theory.extCodeSizeWord σ (setFeeProtocolFactoryWord v) ≠ ⟨0⟩) - (hdepth : ee.depth = 1024) - (hov : R.length + 11 ≤ 1024) : - RDrev code g s0 := by - have hd8373 : decode code ⟨8373⟩ = some (.EXTCODESIZE, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8373⟩) (byte := 0x3b) - (op := .EXTCODESIZE) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8374 : decode code ⟨8374⟩ = some (.ISZERO, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8374⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8375 : decode code ⟨8375⟩ = some (.DUP1, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8375⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8376 : decode code ⟨8376⟩ = some (.ISZERO, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8376⟩) (byte := 0x15) - (op := .ISZERO) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8377 : decode code ⟨8377⟩ = some (.Push .PUSH2, some (⟨8385⟩, 2)) := by - exact uniswapV3PoolSetFeeProtocolOwnerCallDecodePatchedPush2 (pc := ⟨8377⟩) - (n := ⟨8385⟩) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 3) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - have hd8380 : decode code ⟨8380⟩ = some (.JUMPI, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8380⟩) (byte := 0x57) - (op := .JUMPI) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8385 : decode code ⟨8385⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8385⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8386 : decode code ⟨8386⟩ = some (.POP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8386⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8387 : decode code ⟨8387⟩ = some (.GAS, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8387⟩) (byte := 0x5a) - (op := .GAS) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - have hd8388 : decode code ⟨8388⟩ = some (.STATICCALL, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8388⟩) (byte := 0xfa) - (op := .STATICCALL) hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory (n := 1) - (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - obtain ⟨_, _, _, rd8388⟩ := - RD.solcExtcodesizeGuardOkGas (pc := ⟨8373⟩) (okPc := ⟨8385⟩) h hcodeSize - hd8373 (by simpa using hd8374) (by simpa using hd8375) (by simpa using hd8376) - (by simpa using hd8377) (by simpa using hd8380) - (uniswapV3PoolJumpDestPatched8385 hpatch) (by simpa using hd8385) - (by simpa using hd8386) (by simpa using hd8387) - (by simp only [List.length_cons]; omega) - obtain ⟨kDepth, CDepth, rd8389⟩ := - RD.solcStaticcallDepthLimit rd8388 (by simpa using hd8388) hdepth - (by simp only [List.length_cons]; omega) - have rd8389' : RD code ee g s0 ⟨8389⟩ - ((if false then (⟨1⟩ : UInt256) else ⟨0⟩) :: ⟨132⟩ :: ⟨2376452955⟩ :: - setFeeProtocolFactoryWord v :: R) - (ByteArray.empty.write 0 setFeeProtocolOwnerCallMem (⟨128⟩ : UInt256).toNat - (min (⟨32⟩ : UInt256) (UInt256.ofNat ByteArray.empty.size)).toNat) - (UInt256.ofNat (MachineState.M - (MachineState.M (UInt256.ofNat 5).toNat (⟨128⟩ : UInt256).toNat - (⟨4⟩ : UInt256).toNat) - (⟨128⟩ : UInt256).toNat (⟨32⟩ : UInt256).toNat)) - ByteArray.empty (cA, σ) kDepth CDepth := by - simpa [show (⟨8385⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ = ⟨8389⟩ by - native_decide] using rd8389 - obtain ⟨_, hRevert⟩ := - uniswapV3PoolSetFeeProtocolOwnerStaticcallStatusGuard (v := v) (code := code) - (ee := ee) (g := g) (s0 := s0) (R := R) (o := ByteArray.empty) - hpatch rd8389' (by native_decide) (by omega) - exact hRevert rfl - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocolSource.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocolSource.lean deleted file mode 100644 index 3425b63d..00000000 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocolSource.lean +++ /dev/null @@ -1,820 +0,0 @@ -import Benchmarks.UniswapV3Pool.Slot0 -import Benchmarks.UniswapV3Pool.SetFeeProtocolOwnerCall - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev setFeeProtocolUint8Mask : UInt256 := - UInt256.ofNat (2 ^ 8 - 1) - -abbrev setFeeProtocolArg0Word (I : ExecutionEnv) : UInt256 := - UInt256.land (calldataWord I.calldata 4) setFeeProtocolUint8Mask - -abbrev setFeeProtocolArg1Word (I : ExecutionEnv) : UInt256 := - UInt256.land (calldataWord I.calldata 36) setFeeProtocolUint8Mask - -abbrev setFeeProtocolArg0Value (I : ExecutionEnv) : Value := - .int (Int.ofNat (setFeeProtocolArg0Word I).toNat) - -abbrev setFeeProtocolArg1Value (I : ExecutionEnv) : Value := - .int (Int.ofNat (setFeeProtocolArg1Word I).toNat) - -abbrev setFeeProtocolStore (I : ExecutionEnv) : Store := - ((∅ : Store).insert "feeProtocol0" (setFeeProtocolArg0Value I)).insert - "feeProtocol1" (setFeeProtocolArg1Value I) - -theorem setFeeProtocolStore_feeProtocol0 (I : ExecutionEnv) : - (setFeeProtocolStore I).get? "feeProtocol0" = some (setFeeProtocolArg0Value I) := by - rw [setFeeProtocolStore] - rw [store_get_ne (L := (∅ : Store).insert "feeProtocol0" (setFeeProtocolArg0Value I)) - (k := "feeProtocol1") (a := "feeProtocol0") (setFeeProtocolArg1Value I) - (by native_decide)] - exact store_get_self (∅ : Store) "feeProtocol0" (setFeeProtocolArg0Value I) - -theorem setFeeProtocolStore_feeProtocol1 (I : ExecutionEnv) : - (setFeeProtocolStore I).get? "feeProtocol1" = some (setFeeProtocolArg1Value I) := by - rw [setFeeProtocolStore] - exact store_get_self ((∅ : Store).insert "feeProtocol0" (setFeeProtocolArg0Value I)) - "feeProtocol1" (setFeeProtocolArg1Value I) - -theorem evalExpr_setFeeProtocol_feeProtocol0 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - (.var "feeProtocol0") = .ok (setFeeProtocolArg0Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setFeeProtocolStore_feeProtocol0] - -theorem evalExpr_setFeeProtocol_feeProtocol1 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - (.var "feeProtocol1") = .ok (setFeeProtocolArg1Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setFeeProtocolStore_feeProtocol1] - -theorem evalExpr_setFeeProtocol_addrLit {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (a : EVM.Address) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - (addrLit a) = .ok (Value.address (AccountAddress.ofNat a.toNat)) := by - dsimp [addrLit] - have hint : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - (.intLit (↑↑a)) = .ok (.int (↑↑a)) := by - simp [evalExpr?, pure] - unfold evalExpr? - rw [hint] - change (if (↑↑a : Int) < 0 then EvalResult.error EvalError.typeError - else EvalResult.ok - (Value.address (AccountAddress.ofNat (Int.toNat (↑↑a : Int))))) = - EvalResult.ok (Value.address (AccountAddress.ofNat ↑a)) - rw [if_neg (by omega)] - simp - -theorem evalExpr_setFeeProtocol_factoryExtCodeSizeGuard_true {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) - (hcode : - Reasoning.Theory.extCodeSizeWord evm.accountMap - (setFeeProtocolFactoryWord v) ≠ ⟨0⟩) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)) = .ok (.bool true) := by - unfold Reasoning.Theory.extCodeSizeWord at hcode - have haddr : AccountAddress.ofUInt256 (setFeeProtocolFactoryWord v) = - AccountAddress.ofNat ↑v.factory := by - simpa using setFeeProtocolFactoryAddress_eq v - rw [haddr] at hcode - have hword : - EVM.Word.ofNat - ((evm.accountMap.find? (AccountAddress.ofNat ↑v.factory)).option 0 - (fun acc => acc.code.size)) ≠ (⟨0⟩ : UInt256) := by - cases hacc : evm.accountMap.find? (AccountAddress.ofNat ↑v.factory) - · simp [Option.option, hacc] at hcode - · simpa [EVM.Word.ofNat, Option.option, hacc] using hcode - have hnat : - (EVM.Word.ofNat - ((evm.accountMap.find? (AccountAddress.ofNat ↑v.factory)).option 0 - (fun acc => acc.code.size))).toNat ≠ 0 := by - intro hz - exact hword (uint256_toNat_eq_zero hz) - have hpos : - 0 < - (EVM.Word.ofNat - ((evm.accountMap.find? (AccountAddress.ofNat ↑v.factory)).option 0 - (fun acc => acc.code.size))).toNat := - Nat.pos_of_ne_zero hnat - simp [evalExpr?, evalExpr_setFeeProtocol_addrLit, EvalResult.bind, evalBinaryOp?, - State.lookupAccount, pure, bind, hpos] - -theorem evalExpr_setFeeProtocol_factoryExtCodeSizeGuard_false {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) - (hcode : - Reasoning.Theory.extCodeSizeWord evm.accountMap - (setFeeProtocolFactoryWord v) = ⟨0⟩) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)) = .ok (.bool false) := by - unfold Reasoning.Theory.extCodeSizeWord at hcode - have haddr : AccountAddress.ofUInt256 (setFeeProtocolFactoryWord v) = - AccountAddress.ofNat ↑v.factory := by - simpa using setFeeProtocolFactoryAddress_eq v - rw [haddr] at hcode - have hword : - EVM.Word.ofNat - ((evm.accountMap.find? (AccountAddress.ofNat ↑v.factory)).option 0 - (fun acc => acc.code.size)) = (⟨0⟩ : UInt256) := by - cases hacc : evm.accountMap.find? (AccountAddress.ofNat ↑v.factory) - · native_decide - · simpa [EVM.Word.ofNat, Option.option, hacc] using hcode - have hnat : - (EVM.Word.ofNat - ((evm.accountMap.find? (AccountAddress.ofNat ↑v.factory)).option 0 - (fun acc => acc.code.size))).toNat = 0 := - congrArg UInt256.toNat hword - simp [evalExpr?, evalExpr_setFeeProtocol_addrLit, EvalResult.bind, evalBinaryOp?, - State.lookupAccount, pure, bind, hnat] - -abbrev setFeeProtocolUnlockedShift : UInt256 := - UInt256.shiftLeft ⟨1⟩ ⟨240⟩ - -abbrev setFeeProtocolUnlockedByte (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land setFeeProtocolUint8Mask - (UInt256.div (solcSlotWord σ I ⟨0⟩) setFeeProtocolUnlockedShift) - -abbrev setFeeProtocolUnlockedClearMask : UInt256 := - UInt256.lnot (UInt256.shiftLeft setFeeProtocolUint8Mask ⟨240⟩) - -abbrev setFeeProtocolLockedSlotWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land setFeeProtocolUnlockedClearMask (solcSlotWord σ I ⟨0⟩) - -abbrev setFeeProtocolUnlockedLoc : StorageLoc := - loc ⟨0⟩ ⟨30, by decide⟩ ⟨1, by decide⟩ (by decide) .bool - -theorem setFeeProtocolUnlockedByte_eq_slot0UnlockedRawWord (σ : AccountMap) - (I : ExecutionEnv) : - setFeeProtocolUnlockedByte σ I = slot0UnlockedRawWord σ I := by - have hshift : setFeeProtocolUnlockedShift = slot0ShiftBytes 30 := by native_decide - simp [setFeeProtocolUnlockedByte, slot0UnlockedRawWord, setFeeProtocolUnlockedShift, - slot0ShiftBytes, slot0SlotWord, setFeeProtocolUint8Mask, slot0Uint8Mask, hshift, - u256_land_comm] - -theorem uniswapV3PoolSetFeeProtocolEvalUnlocked {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "unlocked")) = - .ok (wordToElem .bool (setFeeProtocolUnlockedByte σ I)) := by - rw [evalExpr_storage_scalar - (t := .bool) - (slot := slot0F "unlocked") - (er := { base := "slot0", steps := [.field "unlocked"] }) - (loc := loc ⟨0⟩ ⟨30, by decide⟩ ⟨1, by decide⟩ (by decide) .bool) - (hbase := by simp [slot0F, setFeeProtocolStore]) - (her := by - simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, boolSt]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [setFeeProtocolUnlockedByte_eq_slot0UnlockedRawWord] using - slot0StorageLocLoad_unlocked (initState cA gh bl σ σ₀ g A I) - -theorem setFeeProtocolUnlockedByte_wordToElem_false {σ : AccountMap} {I : ExecutionEnv} - (hzero : setFeeProtocolUnlockedByte σ I = ⟨0⟩) : - wordToElem .bool (setFeeProtocolUnlockedByte σ I) = .bool false := by - simp [wordToElem, hzero] - -theorem setFeeProtocolUnlockedByte_wordToElem_true {σ : AccountMap} {I : ExecutionEnv} - (hnz : setFeeProtocolUnlockedByte σ I ≠ ⟨0⟩) : - wordToElem .bool (setFeeProtocolUnlockedByte σ I) = .bool true := by - have hbeq : ((setFeeProtocolUnlockedByte σ I).val == 0) = false := by - rw [beq_eq_false_iff_ne] - intro hval - apply hnz - apply u256_inj - simpa [UInt256.toNat] using hval - simp [wordToElem, hbeq] - -theorem setFeeProtocolUnlockedByte_transport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - setFeeProtocolUnlockedByte σ_solm I = setFeeProtocolUnlockedByte σ_evm I := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ (⟨0⟩ : UInt256) - dsimp [setFeeProtocolUnlockedByte, solcSlotWord] - rw [← hslot] - -theorem setFeeProtocolLockedSlotWord_transport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - setFeeProtocolLockedSlotWord σ_solm I = setFeeProtocolLockedSlotWord σ_evm I := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ (⟨0⟩ : UInt256) - dsimp [setFeeProtocolLockedSlotWord, solcSlotWord] - rw [← hslot] - -theorem uniswapV3PoolSetFeeProtocolSourceLockedReverts {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hlocked : setFeeProtocolUnlockedByte σ I = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (setFeeProtocolStore I) - (setfeeprotocolTransition v).body .reverted := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (setFeeProtocolStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")), - .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))), - .letDecl "feeProtocolOld" (some uint8) (.storage (slot0F "feeProtocol")), - .assign .storage (slot0F "feeProtocol") - (addE (.var "feeProtocol0") (shlE (.var "feeProtocol1") (.intLit 4))), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted - exact ExecFuncBody.execBlockRevert <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true (by simp [initState, hwv]))) <| - ExecBlock.consRevert (ExecStmt.requireFalse (by - rw [uniswapV3PoolSetFeeProtocolEvalUnlocked] - exact congrArg EvalResult.ok (setFeeProtocolUnlockedByte_wordToElem_false hlocked))) - -theorem setFeeProtocolStorageLocStore_unlocked_false_some (evm : EVM.State) : - ∃ evm', storageLocStore evm setFeeProtocolUnlockedLoc (.bool false) = some evm' := by - unfold storageLocStore storageLocWriteWord setFeeProtocolUnlockedLoc loc - simp [valueToWord] - -theorem uniswapV3PoolSetFeeProtocolSourceOwnerCallSuccess {v : PoolImmutables} - {evm evm' : EVM.State} {I : ExecutionEnv} {out : ByteArray} {value : List Value} - (hguard : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)) = .ok (.bool true)) - (hcall : - typedCallViaEVM (config v) evm (EVM.address (AccountAddress.ofNat v.factory.toNat)) - "owner" 0 [] (true, evm', out) false) - (hdec : (config v).externalABI.decode? "owner" out = some value) : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false) ] - (.ok { contract := contract v, - locals := (setFeeProtocolStore I).insert "_factoryOwner" (collapseReturns value) } - evm') := by - exact checkedExternalCallSuccess hguard (evalExpr_setFeeProtocol_addrLit evm I v.factory) - (by rfl) hcall hdec - -theorem uniswapV3PoolSetFeeProtocolSourceOwnerCallFailure {v : PoolImmutables} - {evm evm' : EVM.State} {I : ExecutionEnv} {out : ByteArray} - (hguard : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)) = .ok (.bool true)) - (hcall : - typedCallViaEVM (config v) evm (EVM.address (AccountAddress.ofNat v.factory.toNat)) - "owner" 0 [] (false, evm', out) false) : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false) ] - .reverted := by - exact checkedExternalCallFailure hguard (evalExpr_setFeeProtocol_addrLit evm I v.factory) - (by rfl) hcall - -theorem uniswapV3PoolSetFeeProtocolSourceOwnerCallDecodeRevert {v : PoolImmutables} - {evm evm' : EVM.State} {I : ExecutionEnv} {out : ByteArray} - (hguard : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)) = .ok (.bool true)) - (hcall : - typedCallViaEVM (config v) evm (EVM.address (AccountAddress.ofNat v.factory.toNat)) - "owner" 0 [] (true, evm', out) false) - (hdec : (config v).externalABI.decode? "owner" out = none) : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false) ] - .reverted := by - exact checkedExternalCallDecodeRevert hguard (evalExpr_setFeeProtocol_addrLit evm I v.factory) - (by rfl) hcall hdec - -theorem decodeReturnValueWithMode_legacy_address_none_short {returndata : ByteArray} - (hshort : returndata.size < 32) : - ABI.decodeReturnValueWithMode? DecodeMode.legacySolc05 abiAddress returndata = none := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake0n : ¬ ((returndata.toList.drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, hlen] - omega - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValuesWithMode? - rw [abiTupleHeadSize_scalarWords_eq (types := [abiAddress]) (by decide)] - simp only [bind, Option.bind] - rw [decodeABIValues_scalarWordsWithMode_eq (mode := DecodeMode.legacySolc05) - (types := [abiAddress]) (bytes := returndata.toList) (cursor := 0) - (total := 32 * [abiAddress].length) - (by decide) (by simp)] - simp only [decodeScalarWordsWithMode?] - rw [decodeScalarWord_legacyAddress_none_short (bytes := returndata.toList) (start := 0) - htake0n] - rfl - -theorem decodeReturnValueWithMode_legacy_address_ok {returndata : ByteArray} - (hlo : 32 ≤ returndata.size) : - ABI.decodeReturnValueWithMode? DecodeMode.legacySolc05 abiAddress returndata = - some (.address - (AccountAddress.ofNat - (UInt256.ofNat (fromByteArrayBigEndian (returndata.extract 0 32))).toNat)) := by - have hlen : returndata.toList.length = returndata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake0 : ((returndata.toList.drop 0).take 32).length = 32 := by - rw [List.drop_zero, List.length_take, hlen] - omega - have hword := bytesToWord_take32_eq_extract0_32 (returndata := returndata) - unfold ABI.decodeReturnValueWithMode? ABI.decodeReturnValuesWithMode? - rw [abiTupleHeadSize_scalarWords_eq (types := [abiAddress]) (by decide)] - simp only [bind, Option.bind] - rw [decodeABIValues_scalarWordsWithMode_eq (mode := DecodeMode.legacySolc05) - (types := [abiAddress]) (bytes := returndata.toList) (cursor := 0) - (total := 32 * [abiAddress].length) - (by decide) (by simp)] - simp only [decodeScalarWordsWithMode?] - rw [decodeScalarWord_legacyAddress_ok (bytes := returndata.toList) (start := 0) htake0] - simp [hword] - -theorem setFeeProtocolOwnerDecodeNoneShort {v : PoolImmutables} {out : ByteArray} - (hshort : out.size < 32) : - (config v).externalABI.decode? "owner" out = none := by - simp [config, poolExternalABI, decodeReturn?, addr, - decodeReturnValueWithMode_legacy_address_none_short hshort] - -theorem setFeeProtocolOwnerDecodeOk {v : PoolImmutables} {out : ByteArray} - (hlo : 32 ≤ out.size) : - (config v).externalABI.decode? "owner" out = - some [Value.address - (AccountAddress.ofNat - (UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32))).toNat)] := by - simp [config, poolExternalABI, decodeReturn?, addr, - decodeReturnValueWithMode_legacy_address_ok hlo] - -abbrev setFeeProtocolOwnerWord (out : ByteArray) : UInt256 := - UInt256.ofNat (fromByteArrayBigEndian (out.extract 0 32)) - -abbrev setFeeProtocolOwnerAddress (out : ByteArray) : AccountAddress := - AccountAddress.ofNat (setFeeProtocolOwnerWord out).toNat - -abbrev setFeeProtocolStoreWithOwner (I : ExecutionEnv) (out : ByteArray) : Store := - (setFeeProtocolStore I).insert "_factoryOwner" (.address (setFeeProtocolOwnerAddress out)) - -theorem setFeeProtocolOwnerAddress_eq_source_of_mask_eq {out : ByteArray} {I : ExecutionEnv} - (h : UInt256.land solcAddrMask (setFeeProtocolOwnerWord out) = solcSourceWord I) : - setFeeProtocolOwnerAddress out = I.source := by - have hvalue := solcAddressValue_masked (setFeeProtocolOwnerWord out) - have hmasked : - AccountAddress.ofNat (UInt256.land solcAddrMask (setFeeProtocolOwnerWord out)).toNat = - I.source := by - rw [h] - exact solcSource_ofNat I - unfold setFeeProtocolOwnerAddress - simpa [setFeeProtocolOwnerWord, hmasked] using hvalue - -theorem setFeeProtocolOwnerMask_eq_source_of_address_eq {out : ByteArray} {I : ExecutionEnv} - (h : setFeeProtocolOwnerAddress out = I.source) : - UInt256.land solcAddrMask (setFeeProtocolOwnerWord out) = solcSourceWord I := by - apply u256_inj - rw [uland_toNat, solcSourceWord_toNat] - have haddr : - (setFeeProtocolOwnerWord out).toNat % AccountAddress.size = I.source.val := by - have hval := congrArg Fin.val h - unfold setFeeProtocolOwnerAddress AccountAddress.ofNat at hval - simpa [Fin.val_ofNat] using hval - rw [show solcAddrMask.toNat = 2 ^ 160 - 1 by decide] - rw [show 2 ^ 160 - 1 &&& (setFeeProtocolOwnerWord out).toNat = - (setFeeProtocolOwnerWord out).toNat &&& (2 ^ 160 - 1) by - exact Nat.and_comm _ _] - change Nat.land (setFeeProtocolOwnerWord out).toNat (2 ^ 160 - 1) = I.source.val - rw [nat_land_mask_eq_mod] - simpa [AccountAddress.size] using haddr - -theorem setFeeProtocolOwnerAddress_ne_source_of_mask_ne {out : ByteArray} {I : ExecutionEnv} - (h : UInt256.land solcAddrMask (setFeeProtocolOwnerWord out) ≠ solcSourceWord I) : - setFeeProtocolOwnerAddress out ≠ I.source := by - intro haddr - exact h (setFeeProtocolOwnerMask_eq_source_of_address_eq haddr) - -theorem setFeeProtocolStoreWithOwner_factoryOwner (I : ExecutionEnv) (out : ByteArray) : - (setFeeProtocolStoreWithOwner I out).get? "_factoryOwner" = - some (.address (setFeeProtocolOwnerAddress out)) := by - rw [setFeeProtocolStoreWithOwner] - exact store_get_self (setFeeProtocolStore I) "_factoryOwner" - (.address (setFeeProtocolOwnerAddress out)) - -theorem evalExpr_setFeeProtocol_factoryOwner {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (out : ByteArray) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evm (.var "_factoryOwner") = .ok (.address (setFeeProtocolOwnerAddress out)) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setFeeProtocolStoreWithOwner_factoryOwner] - -theorem evalExpr_setFeeProtocol_ownerCaller_eq_true {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (out : ByteArray) - (hcaller : setFeeProtocolOwnerAddress out = evm.executionEnv.source) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evm (eqE (.env .caller) (.var "_factoryOwner")) = .ok (.bool true) := by - simp only [eqE, evalExpr?, evalExpr_setFeeProtocol_factoryOwner, bind, EvalResult.bind, - evalBinaryOp?] - rw [hcaller] - simp [envValue, BEq.beq] - -theorem evalExpr_setFeeProtocol_ownerCaller_eq_false {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (out : ByteArray) - (hcaller : setFeeProtocolOwnerAddress out ≠ evm.executionEnv.source) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evm (eqE (.env .caller) (.var "_factoryOwner")) = .ok (.bool false) := by - simp only [eqE, evalExpr?, evalExpr_setFeeProtocol_factoryOwner, bind, EvalResult.bind, - evalBinaryOp?] - have hcaller' : evm.executionEnv.source ≠ setFeeProtocolOwnerAddress out := by - intro h - exact hcaller h.symm - simp [envValue, BEq.beq, hcaller'] - -theorem setFeeProtocolUnlockedClearMask_toNat : - setFeeProtocolUnlockedClearMask.toNat = 2 ^ 256 - 2 ^ 248 + (2 ^ 240 - 1) := by - native_decide - -theorem natLandClearByte240 (n : Nat) (hn : n < 2 ^ 256) : - Nat.land n (2 ^ 256 - 2 ^ 248 + (2 ^ 240 - 1)) = - n % 2 ^ 240 + (n / 2 ^ 248) * 2 ^ 248 := by - apply Nat.eq_of_testBit_eq - intro i - change (n &&& (2 ^ 256 - 2 ^ 248 + (2 ^ 240 - 1))).testBit i = - (n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248).testBit i - rw [Nat.testBit_and] - rw [show n % 2 ^ 240 + (n / 2 ^ 248) * 2 ^ 248 = - 2 ^ 248 * (n / 2 ^ 248) + n % 2 ^ 240 by ring] - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 248) - (b_lt := lt_trans (Nat.mod_lt _ (by positivity : 0 < 2 ^ 240)) - (by norm_num : 2 ^ 240 < 2 ^ 248))] - rw [show 2 ^ 256 - 2 ^ 248 + (2 ^ 240 - 1) = - 2 ^ 248 * (2 ^ 8 - 1) + (2 ^ 240 - 1) by norm_num [Nat.pow_add]] - have hmaskLow : 2 ^ 240 - 1 < 2 ^ 248 := by norm_num - rw [Nat.testBit_two_pow_mul_add (a := 2 ^ 8 - 1) (b_lt := hmaskLow)] - by_cases hi248 : i < 248 - · simp [hi248] - change (n.testBit i && (2 ^ 240 - 1).testBit i) = (n % 2 ^ 240).testBit i - by_cases hi240 : i < 240 - · have hmask : (2 ^ 240 - 1).testBit i = true := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_true hi240 - have hmod : (n % 2 ^ 240).testBit i = n.testBit i := by - rw [Nat.testBit_mod_two_pow] - simp [hi240] - rw [hmask, hmod] - simp - · have hmask : (2 ^ 240 - 1).testBit i = false := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_false hi240 - have hmod : (n % 2 ^ 240).testBit i = false := by - rw [Nat.testBit_mod_two_pow] - simp [hi240] - rw [hmask, hmod] - simp - · have h248le : 248 ≤ i := Nat.le_of_not_gt hi248 - simp [hi248] - change (n.testBit i && (2 ^ 8 - 1).testBit (i - 248)) = - (n / 2 ^ 248).testBit (i - 248) - by_cases hi256 : i < 256 - · have hsub8 : i - 248 < 8 := by omega - have hdiv := divPow_testBit n 248 i h248le - have hmask : (2 ^ 8 - 1).testBit (i - 248) = true := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_true hsub8 - rw [hdiv, hmask] - simp - · have hsub8 : ¬ i - 248 < 8 := by omega - have hnbit : n.testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hn (Nat.pow_le_pow_right (by norm_num) (by omega : 256 ≤ i))) - have hdivfalse : (n / 2 ^ 248).testBit (i - 248) = false := by - rw [divPow_testBit n 248 i h248le, hnbit] - have hmask : (2 ^ 8 - 1).testBit (i - 248) = false := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_false hsub8 - rw [hmask, hdivfalse] - simp - -theorem setFeeProtocolStorageLocStore_unlocked_false (evm : EVM.State) : - storageLocStore evm setFeeProtocolUnlockedLoc (.bool false) = - some (Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - setFeeProtocolUnlockedClearMask)) := by - unfold storageLocStore storageLocWriteWord setFeeProtocolUnlockedLoc loc - simp only [valueToWord, Bool.toUInt256_false, bind, Option.bind] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner { val := 0 } - show fromBytes' - ((List.take 30 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0))) ++ - List.drop (30 + 1) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (UInt256.land w setFeeProtocolUnlockedClearMask).toNat - rw [show List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 0)) = - ([0] : List UInt8) by - native_decide] - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [u256_land_toNat, setFeeProtocolUnlockedClearMask_toNat] - rw [natLandClearByte240 w.toNat w.val.isLt] - have hsumLt : - w.toNat % 2 ^ 240 + w.toNat / 2 ^ 248 * 2 ^ 248 < UInt256.size := by - rw [← natLandClearByte240 w.toNat w.val.isLt] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [UInt256.size]) - rw [Nat.mod_eq_of_lt hsumLt] - have hlen30 : (List.take 30 (EVM.Word.toBytesLEWithSizeProof w).1).length = 30 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - have hlen31 : (List.take 30 (EVM.Word.toBytesLEWithSizeProof w).1 ++ [0]).length = 31 := by - rw [List.length_append, hlen30] - norm_num - rw [hlen30] - rw [hlen31] - simp [fromBytes'] - ring - -theorem uniswapV3PoolSetFeeProtocolSourceLockPrefixExact {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : setFeeProtocolUnlockedByte σ I ≠ ⟨0⟩) : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - (initState cA gh bl σ σ₀ g A I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false) ] - (.ok { contract := contract v, locals := setFeeProtocolStore I } - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (setFeeProtocolLockedSlotWord σ I))) := by - refine nonpayableRequireAssignStorageBlock - (cfg := config v) (solm := { contract := contract v, locals := setFeeProtocolStore I }) - (evm := initState cA gh bl σ σ₀ g A I) - (evm' := Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (setFeeProtocolLockedSlotWord σ I)) - (guard := .storage (slot0F "unlocked")) (rhs := .boolLit false) - (ref := slot0F "unlocked") (value := .bool false) - (by simp [initState, hwv]) ?_ ?_ ?_ - · rw [uniswapV3PoolSetFeeProtocolEvalUnlocked] - exact congrArg EvalResult.ok (setFeeProtocolUnlockedByte_wordToElem_true hunlocked) - · simp [evalExpr?, pure] - · apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "unlocked"] }) - (ty := .elem .bool) - (loc := setFeeProtocolUnlockedLoc) - · simp [slot0F, setFeeProtocolStore] - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, boolSt] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - setFeeProtocolUnlockedLoc, loc] - · trivial - · simpa [initState, setFeeProtocolLockedSlotWord, solcSlotWord, u256_land_comm] using - setFeeProtocolStorageLocStore_unlocked_false (initState cA gh bl σ σ₀ g A I) - -theorem uniswapV3PoolSetFeeProtocolSourceOwnerCallRevertBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : setFeeProtocolUnlockedByte σ I ≠ ⟨0⟩) - (howner : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (setFeeProtocolLockedSlotWord σ I)) σ₀ g A I) - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false) ] - .reverted) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (setFeeProtocolStore I) - (setfeeprotocolTransition v).body .reverted := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (setFeeProtocolStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")), - .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))), - .letDecl "feeProtocolOld" (some uint8) (.storage (slot0F "feeProtocol")), - .assign .storage (slot0F "feeProtocol") - (addE (.var "feeProtocol0") (shlE (.var "feeProtocol1") (.intLit 4))), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolSetFeeProtocolSourceLockPrefixExact (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) hwv hunlocked - have hstate : - Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (setFeeProtocolLockedSlotWord σ I) = - initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (setFeeProtocolLockedSlotWord σ I)) σ₀ g A I := by - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have hfail : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (setFeeProtocolLockedSlotWord σ I)) - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false) ] - .reverted := by - simpa [hstate] using howner - have hthrough := execBlock_append hprefix hfail - exact execBlock_append_term (s2 := - [ .require (eqE (.env .caller) (.var "_factoryOwner")), - .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))), - .letDecl "feeProtocolOld" (some uint8) (.storage (slot0F "feeProtocol")), - .assign .storage (slot0F "feeProtocol") - (addE (.var "feeProtocol0") (shlE (.var "feeProtocol1") (.intLit 4))), - .assign .storage (slot0F "unlocked") (.boolLit true) ]) - hthrough (by intro f e h; cases h) - -theorem uniswapV3PoolSetFeeProtocolSourceOwnerRequireSuccess {v : PoolImmutables} - {evm evm' : EVM.State} {I : ExecutionEnv} {out : ByteArray} - (howner : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evm')) - (hcaller : setFeeProtocolOwnerAddress out = evm'.executionEnv.source) : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evm') := by - have hreq : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evm' [ .require (eqE (.env .caller) (.var "_factoryOwner")) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evm') := by - refine ExecBlock.consNormal - (ExecStmt.requireTrue - (evalExpr_setFeeProtocol_ownerCaller_eq_true evm' I out hcaller)) ?_ - exact ExecBlock.nil - simpa using execBlock_append howner hreq - -theorem uniswapV3PoolSetFeeProtocolSourceOwnerRequireRevert {v : PoolImmutables} - {evm evm' : EVM.State} {I : ExecutionEnv} {out : ByteArray} - (howner : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evm')) - (hcaller : setFeeProtocolOwnerAddress out ≠ evm'.executionEnv.source) : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } evm - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")) ] - .reverted := by - have hreq : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evm' [ .require (eqE (.env .caller) (.var "_factoryOwner")) ] .reverted := by - exact ExecBlock.consRevert - (ExecStmt.requireFalse - (evalExpr_setFeeProtocol_ownerCaller_eq_false evm' I out hcaller)) - simpa using execBlock_append howner hreq - -theorem uniswapV3PoolSetFeeProtocolSourceOwnerRequireSuccessPrefixExact - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - {evmOwner : EVM.State} {out : ByteArray} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : setFeeProtocolUnlockedByte σ I ≠ ⟨0⟩) - (howner : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (setFeeProtocolLockedSlotWord σ I)) σ₀ g A I) - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evmOwner)) - (hcaller : setFeeProtocolOwnerAddress out = evmOwner.executionEnv.source) : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - (initState cA gh bl σ σ₀ g A I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evmOwner) := by - have hprefix := uniswapV3PoolSetFeeProtocolSourceLockPrefixExact (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) hwv hunlocked - have hstate : - Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (setFeeProtocolLockedSlotWord σ I) = - initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (setFeeProtocolLockedSlotWord σ I)) σ₀ g A I := by - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have howner' : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (setFeeProtocolLockedSlotWord σ I)) - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evmOwner) := by - simpa [hstate] using howner - have hownerRequire := - uniswapV3PoolSetFeeProtocolSourceOwnerRequireSuccess (v := v) - (evm := Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (setFeeProtocolLockedSlotWord σ I)) - (evm' := evmOwner) (I := I) (out := out) howner' hcaller - simpa using execBlock_append hprefix hownerRequire - -theorem uniswapV3PoolSetFeeProtocolSourceOwnerRequireRevertBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} {evmOwner : EVM.State} {out : ByteArray} - (hwv : I.weiValue = ⟨0⟩) - (hunlocked : setFeeProtocolUnlockedByte σ I ≠ ⟨0⟩) - (howner : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - (initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (setFeeProtocolLockedSlotWord σ I)) σ₀ g A I) - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evmOwner)) - (hcaller : setFeeProtocolOwnerAddress out ≠ evmOwner.executionEnv.source) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (setFeeProtocolStore I) - (setfeeprotocolTransition v).body .reverted := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (setFeeProtocolStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")), - .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))), - .letDecl "feeProtocolOld" (some uint8) (.storage (slot0F "feeProtocol")), - .assign .storage (slot0F "feeProtocol") - (addE (.var "feeProtocol0") (shlE (.var "feeProtocol1") (.intLit 4))), - .assign .storage (slot0F "unlocked") (.boolLit true) ] .reverted - refine ExecFuncBody.execBlockRevert ?_ - have hprefix := uniswapV3PoolSetFeeProtocolSourceLockPrefixExact (v := v) - (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) - (g := g) hwv hunlocked - have hstate : - Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (setFeeProtocolLockedSlotWord σ I) = - initState cA gh bl - (sstoreAccountMap I.codeOwner σ ⟨0⟩ (setFeeProtocolLockedSlotWord σ I)) σ₀ g A I := by - unfold Solm.EVM.storageStore State.lookupAccount sstoreAccountMap - cases hlookup : σ.find? I.codeOwner with - | none => - simp [initState, Option.option, hlookup] - | some _ => - simp [initState, State.setAccount, Account.updateStorage, Option.option, hlookup] - have howner' : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - (Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (setFeeProtocolLockedSlotWord σ I)) - [ .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evmOwner) := by - simpa [hstate] using howner - have hownerRequire := - uniswapV3PoolSetFeeProtocolSourceOwnerRequireRevert (v := v) - (evm := Solm.EVM.storageStore (initState cA gh bl σ σ₀ g A I) I.codeOwner ⟨0⟩ - (setFeeProtocolLockedSlotWord σ I)) - (evm' := evmOwner) (I := I) (out := out) howner' hcaller - have hthrough := execBlock_append hprefix hownerRequire - exact execBlock_append_term (s2 := - [ .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))), - .letDecl "feeProtocolOld" (some uint8) (.storage (slot0F "feeProtocol")), - .assign .storage (slot0F "feeProtocol") - (addE (.var "feeProtocol0") (shlE (.var "feeProtocol1") (.intLit 4))), - .assign .storage (slot0F "unlocked") (.boolLit true) ]) - hthrough (by intro f e h; cases h) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/SetFeeProtocolSuccess.lean b/Benchmarks/UniswapV3Pool/SetFeeProtocolSuccess.lean deleted file mode 100644 index 94aa0ffd..00000000 --- a/Benchmarks/UniswapV3Pool/SetFeeProtocolSuccess.lean +++ /dev/null @@ -1,1672 +0,0 @@ -import Benchmarks.UniswapV3Pool.SetFeeProtocolFeeProtocolCheck - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev setFeeProtocolFeeProtocolLoc : StorageLoc := - loc ⟨0⟩ ⟨29, by decide⟩ ⟨1, by decide⟩ (by decide) (.int uint8Int) - -abbrev setFeeProtocolNewFeeProtocolNat (I : ExecutionEnv) : Nat := - (setFeeProtocolArg0Word I).toNat + - ((setFeeProtocolArg1Word I).toNat * 2 ^ 4) % EVM.wordModulus - -abbrev setFeeProtocolNewFeeProtocolValue (I : ExecutionEnv) : Value := - .int (Int.ofNat (setFeeProtocolNewFeeProtocolNat I)) - -abbrev setFeeProtocolFeeProtocolSlotWord (evm : EVM.State) (I : ExecutionEnv) : UInt256 := - UInt256.ofNat - ((Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 232 + - (setFeeProtocolNewFeeProtocolNat I % 2 ^ 8) * 2 ^ 232 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 240 * - 2 ^ 240) - -abbrev setFeeProtocolAfterFeeProtocolState (evm : EVM.State) (I : ExecutionEnv) : - EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (setFeeProtocolFeeProtocolSlotWord evm I) - -abbrev setFeeProtocolUnlockedTrueSlotWord (evm : EVM.State) : UInt256 := - UInt256.ofNat - ((Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 240 + - 2 ^ 240 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 248 * - 2 ^ 248) - -abbrev setFeeProtocolAfterUnlockState (evm : EVM.State) : EVM.State := - Solm.EVM.storageStore evm evm.executionEnv.codeOwner ⟨0⟩ - (setFeeProtocolUnlockedTrueSlotWord evm) - -abbrev setFeeProtocolFeeProtocolClearMask : UInt256 := - ⟨115790329291997763829805189145943027211779609632852660590886017564236060819455⟩ - -abbrev setFeeProtocolEvmNewFeeProtocolWord (I : ExecutionEnv) : UInt256 := - UInt256.land - ⟨255⟩ - (setFeeProtocolArg0Word I + - UInt256.land (UInt256.shiftLeft (setFeeProtocolArg1Word I) ⟨4⟩) ⟨4080⟩) - -abbrev setFeeProtocolEvmFeeProtocolSlotWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.lor - (UInt256.land (codeOwnerStorageWord I σ ⟨0⟩) setFeeProtocolFeeProtocolClearMask) - (UInt256.mul (UInt256.shiftLeft ⟨1⟩ ⟨232⟩) - (setFeeProtocolEvmNewFeeProtocolWord I)) - -abbrev setFeeProtocolEvmUnlockedClearMask : UInt256 := - UInt256.lnot (UInt256.shiftLeft ⟨255⟩ ⟨240⟩) - -abbrev setFeeProtocolEvmUnlockedTrueSlotWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.lor - (UInt256.shiftLeft ⟨1⟩ ⟨240⟩) - (UInt256.land setFeeProtocolEvmUnlockedClearMask (codeOwnerStorageWord I σ ⟨0⟩)) - -abbrev setFeeProtocolEventTopic : UInt256 := - ⟨68407994909122337899402930436989363150185057688881605929376750743032331481395⟩ - -abbrev setFeeProtocolEventOldFeeProtocolWord (oldSlot : UInt256) : UInt256 := - UInt256.land (UInt256.div oldSlot (UInt256.shiftLeft ⟨1⟩ ⟨232⟩)) ⟨255⟩ - -abbrev setFeeProtocolEventOldFeeProtocol0Word (oldFeeProtocol : UInt256) : UInt256 := - UInt256.land ⟨255⟩ (UInt256.mod oldFeeProtocol ⟨16⟩) - -abbrev setFeeProtocolEventOldFeeProtocol1Word (oldFeeProtocol : UInt256) : UInt256 := - UInt256.land (UInt256.shiftRight oldFeeProtocol ⟨4⟩) ⟨15⟩ - -abbrev setFeeProtocolEventNewFeeProtocol0Word (I : ExecutionEnv) : UInt256 := - UInt256.land ⟨255⟩ (setFeeProtocolArg0Word I) - -abbrev setFeeProtocolEventNewFeeProtocol1Word (I : ExecutionEnv) : UInt256 := - UInt256.land (setFeeProtocolArg1Word I) ⟨255⟩ - -abbrev setFeeProtocolEventMem0 (w0 : UInt256) (mem : ByteArray) : ByteArray := - (UInt256.toByteArray w0).write 0 mem 128 32 - -abbrev setFeeProtocolEventMem1 (w0 w1 : UInt256) (mem : ByteArray) : ByteArray := - (UInt256.toByteArray w1).write 0 (setFeeProtocolEventMem0 w0 mem) 160 32 - -abbrev setFeeProtocolEventMem2 (w0 w1 w2 : UInt256) (mem : ByteArray) : ByteArray := - (UInt256.toByteArray w2).write 0 (setFeeProtocolEventMem1 w0 w1 mem) 192 32 - -abbrev setFeeProtocolEventMem3 (w0 w1 w2 w3 : UInt256) (mem : ByteArray) : - ByteArray := - (UInt256.toByteArray w3).write 0 (setFeeProtocolEventMem2 w0 w1 w2 mem) 224 32 - -abbrev setFeeProtocolEventMem (oldSlot : UInt256) (I : ExecutionEnv) (out : ByteArray) : - ByteArray := - let oldFeeProtocol := setFeeProtocolEventOldFeeProtocolWord oldSlot - setFeeProtocolEventMem3 - (setFeeProtocolEventOldFeeProtocol0Word oldFeeProtocol) - (setFeeProtocolEventOldFeeProtocol1Word oldFeeProtocol) - (setFeeProtocolEventNewFeeProtocol0Word I) - (setFeeProtocolEventNewFeeProtocol1Word I) - (setFeeProtocolOwnerStaticcallMem out) - -private theorem setFeeProtocolEventMem0_size {mem : ByteArray} (w0 : UInt256) - (hmem : mem.size = 160) : - (setFeeProtocolEventMem0 w0 mem).size = 160 := by - exact toByteArray_write32_size_of_le mem w0 128 160 160 hmem - (by rw [hmem]; omega) - (by norm_num) - -private theorem setFeeProtocolEventMem1_size {mem : ByteArray} (w0 w1 : UInt256) - (hmem : mem.size = 160) : - (setFeeProtocolEventMem1 w0 w1 mem).size = 192 := by - exact toByteArray_write32_size_of_le (setFeeProtocolEventMem0 w0 mem) w1 160 160 192 - (setFeeProtocolEventMem0_size w0 hmem) - (by rw [setFeeProtocolEventMem0_size w0 hmem]) - (by norm_num) - -private theorem setFeeProtocolEventMem2_size {mem : ByteArray} (w0 w1 w2 : UInt256) - (hmem : mem.size = 160) : - (setFeeProtocolEventMem2 w0 w1 w2 mem).size = 224 := by - exact toByteArray_write32_size_of_le (setFeeProtocolEventMem1 w0 w1 mem) w2 192 192 224 - (setFeeProtocolEventMem1_size w0 w1 hmem) - (by rw [setFeeProtocolEventMem1_size w0 w1 hmem]) - (by norm_num) - -private theorem setFeeProtocolEventMem3_size {mem : ByteArray} (w0 w1 w2 w3 : UInt256) - (hmem : mem.size = 160) : - (setFeeProtocolEventMem3 w0 w1 w2 w3 mem).size = 256 := by - exact toByteArray_write32_size_of_le (setFeeProtocolEventMem2 w0 w1 w2 mem) w3 - 224 224 256 - (setFeeProtocolEventMem2_size w0 w1 w2 hmem) - (by rw [setFeeProtocolEventMem2_size w0 w1 w2 hmem]) - (by norm_num) - -private theorem setFeeProtocolEventMem3_read64_of_base {mem : ByteArray} - (w0 w1 w2 w3 : UInt256) (hmem : mem.size = 160) - (hread64 : mem.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : - (setFeeProtocolEventMem3 w0 w1 w2 w3 mem).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - change ((UInt256.toByteArray w3).write 0 (setFeeProtocolEventMem2 w0 w1 w2 mem) - 224 32).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ - rw [write32_read_below _ _ 224 64 (by rw [toByteArray_size]) - (by rw [setFeeProtocolEventMem2_size w0 w1 w2 hmem]) (by omega)] - change ((UInt256.toByteArray w2).write 0 (setFeeProtocolEventMem1 w0 w1 mem) - 192 32).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ - rw [write32_read_below _ _ 192 64 (by rw [toByteArray_size]) - (by rw [setFeeProtocolEventMem1_size w0 w1 hmem]) (by omega)] - change ((UInt256.toByteArray w1).write 0 (setFeeProtocolEventMem0 w0 mem) - 160 32).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ - rw [write32_read_below _ _ 160 64 (by rw [toByteArray_size]) - (by rw [setFeeProtocolEventMem0_size w0 hmem]) (by omega)] - change ((UInt256.toByteArray w0).write 0 mem 128 32).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ - rw [write32_read_below _ _ 128 64 (by rw [toByteArray_size]) - (by rw [hmem]; omega) (by omega)] - exact hread64 - -theorem setFeeProtocolEventMem_mload64_of_size_ge (oldSlot : UInt256) (I : ExecutionEnv) - (out : ByteArray) (hlo : 32 ≤ out.size) (hhi : out.size < UInt256.size) : - (if (⟨64⟩ : UInt256).toNat ≥ (setFeeProtocolEventMem oldSlot I out).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 8 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((setFeeProtocolEventMem oldSlot I out).readWithPadding - (⟨64⟩ : UInt256).toNat 32))) = - ⟨128⟩ := by - let oldFeeProtocol := setFeeProtocolEventOldFeeProtocolWord oldSlot - exact mloadFreePtrValue - (by - have hsz : (setFeeProtocolEventMem oldSlot I out).size = 256 := by - dsimp [setFeeProtocolEventMem, oldFeeProtocol] - exact setFeeProtocolEventMem3_size _ _ _ _ - (setFeeProtocolOwnerStaticcallMem_size_of_size_ge out hlo hhi) - dsimp [setFeeProtocolEventMem, oldFeeProtocol] - rw [hsz] - decide) - (by native_decide) - (by - dsimp [setFeeProtocolEventMem, oldFeeProtocol] - exact setFeeProtocolEventMem3_read64_of_base _ _ _ _ - (setFeeProtocolOwnerStaticcallMem_size_of_size_ge out hlo hhi) - (setFeeProtocolOwnerStaticcallMem_read64_of_size_ge out hlo hhi)) - -private theorem setFeeProtocolModXstep {s : State} {code : ByteArray} - {pcv a b : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.MOD, .none)) - (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 5 then .error .OutOfGass - else .ok (stBinop5 s (UInt256.mod a b) t, .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.MOD, .none) := by - rw [hcode, hpc] - exact hdec - rw [← hcode, step_mod s hd, hstk] - have hov' : ¬ ((a :: b :: t).length - 2 + 1 > 1024) := by - simp only [List.length_cons] - omega - simp only [if_neg hov', GasConstants.Glow, stBinop5] - -private theorem setFeeProtocolRDMod {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {pc : UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} {a b : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.MOD, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.mod a b :: t) mem aw rdata acc - (k + 1) (C + 5) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, - hee, hworld⟩ - · exact Or.inl hoog - · have st := setFeeProtocolModXstep hcode hpc hdec hstk hov - by_cases gg : g.toNat < C + 5 - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨stBinop5 s (UInt256.mod a b) t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, - by omega, by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [stBinop5]; exact hcode - · simp only [stBinop5]; rw [hpc] - · rfl - · simp only [stBinop5]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [stBinop5]; exact hmem - · simp only [stBinop5]; exact haw - · simp only [stBinop5]; exact hrdata - · simp only [stBinop5]; exact hacc - · exact hee - · exact hworld - -private theorem uniswapV3PoolPatchPreservesJumpDest857 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨857⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched857 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨857⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest857 - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolFeeProtocolStoreEvm {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8535⟩ - (setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata (cA, σ) k C) - (hperm : ee.perm = true) - (hov : R.length + 9 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8603⟩ - (⟨255⟩ :: codeOwnerStorageWord ee σ ⟨0⟩ :: UInt256.shiftLeft ⟨1⟩ ⟨232⟩ :: - setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - mem aw rdata - (cA, sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (setFeeProtocolEvmFeeProtocolSlotWord σ ee)) - k' C' := by - have hd8535 : decode code ⟨8535⟩ = some (.JUMPDEST, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8535⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8536 : decode code ⟨8536⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8536⟩) - (n := ⟨0⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8538 : decode code ⟨8538⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8538⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8539 : decode code ⟨8539⟩ = some (.SLOAD, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8539⟩) (byte := 0x54) - (op := .SLOAD) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8540 : decode code ⟨8540⟩ = some (.Push .PUSH2, some (⟨4080⟩, 2)) := by - exact setFeeProtocolDecodePush2AfterFactory (pc := ⟨8540⟩) - (n := ⟨4080⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8543 : decode code ⟨8543⟩ = some (.Push .PUSH1, some (⟨4⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8543⟩) - (n := ⟨4⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8545 : decode code ⟨8545⟩ = some (.DUP5, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8545⟩) (byte := 0x84) - (op := .DUP5) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8546 : decode code ⟨8546⟩ = some (.SWAP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8546⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8547 : decode code ⟨8547⟩ = some (.SHL, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8547⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8548 : decode code ⟨8548⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8548⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8549 : decode code ⟨8549⟩ = some (.DUP5, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8549⟩) (byte := 0x84) - (op := .DUP5) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8550 : decode code ⟨8550⟩ = some (.ADD, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8550⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8551 : decode code ⟨8551⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8551⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8553 : decode code ⟨8553⟩ = some (.SWAP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8553⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8554 : decode code ⟨8554⟩ = some (.DUP2, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8554⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8555 : decode code ⟨8555⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8555⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8556 : decode code ⟨8556⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8556⟩) - (n := ⟨1⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8558 : decode code ⟨8558⟩ = some (.Push .PUSH1, some (⟨232⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8558⟩) - (n := ⟨232⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8560 : decode code ⟨8560⟩ = some (.SHL, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8560⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8561 : decode code ⟨8561⟩ = some (.SWAP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8561⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8562 : decode code ⟨8562⟩ = some (.DUP2, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8562⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8563 : decode code ⟨8563⟩ = some (.MUL, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8563⟩) (byte := 0x02) - (op := .MUL) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8564 : - decode code ⟨8564⟩ = - some (.Push .PUSH32, some (setFeeProtocolFeeProtocolClearMask, 32)) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory - (n := 33) (by native_decide) (by native_decide))] - native_decide - have hd8597 : decode code ⟨8597⟩ = some (.DUP5, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8597⟩) (byte := 0x84) - (op := .DUP5) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8598 : decode code ⟨8598⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8598⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8599 : decode code ⟨8599⟩ = some (.OR, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8599⟩) (byte := 0x17) - (op := .OR) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8600 : decode code ⟨8600⟩ = some (.SWAP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8600⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8601 : decode code ⟨8601⟩ = some (.SWAP4, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8601⟩) (byte := 0x93) - (op := .SWAP4) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8602 : decode code ⟨8602⟩ = some (.SSTORE, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8602⟩) (byte := 0x55) - (op := .SSTORE) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have rd8539 := evm_run h with [ - raw jumpdest hd8535 (by evm_ov), - raw push1 ⟨0⟩ hd8536 (by evm_ov), - raw dup1 hd8538 (by evm_ov)] - obtain ⟨_, _, rd8540₀⟩ := rd8539.sload hd8539 (by evm_ov) - have rd8602 := evm_run rd8540₀ with [ - raw push2 ⟨4080⟩ hd8540 (by evm_ov), - raw push1 ⟨4⟩ hd8543 (by evm_ov), - raw dup5 hd8545 (by evm_ov), - raw swap1 hd8546 (by evm_ov), - raw shl hd8547 (by evm_ov), - raw and hd8548 (by evm_ov), - raw dup5 hd8549 (by evm_ov), - raw add hd8550 (by evm_ov), - raw push1 ⟨255⟩ hd8551 (by evm_ov), - raw swap1 hd8553 (by evm_ov), - raw dup2 hd8554 (by evm_ov), - raw and hd8555 (by evm_ov), - raw push1 ⟨1⟩ hd8556 (by evm_ov), - raw push1 ⟨232⟩ hd8558 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd8560 (by evm_ov), - raw swap1 hd8561 (by evm_ov), - raw dup2 hd8562 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw mul hd8563 (by evm_ov), - raw pushConst setFeeProtocolFeeProtocolClearMask - (show Operation.POp.PUSH32 ≠ .PUSH0 by native_decide) - hd8564 - (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw dup5 hd8597 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd8598 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw lor hd8599 (by evm_ov), - raw swap1 hd8600 (by evm_ov), - raw swap4 hd8601 (by evm_ov)] - obtain ⟨_, _, rd8603⟩ := rd8602.sstore hperm hd8602 (by evm_ov) - norm_num at rd8603 - exact ⟨_, _, by - simpa [setFeeProtocolEvmFeeProtocolSlotWord, setFeeProtocolEvmNewFeeProtocolWord, - codeOwnerStorageWord] using rd8603⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolEventLogEvm {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {out : ByteArray} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - {oldSlot : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8603⟩ - (⟨255⟩ :: oldSlot :: UInt256.shiftLeft ⟨1⟩ ⟨232⟩ :: - setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - (setFeeProtocolOwnerStaticcallMem out) setFeeProtocolOwnerStaticcallActiveWords - rdata (cA, σ) k C) - (hperm : ee.perm = true) - (houtSize32 : 32 ≤ out.size) (houtSize : out.size < UInt256.size) - (hov : R.length + 12 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8696⟩ - (setFeeProtocolEventOldFeeProtocolWord oldSlot :: - setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: R) - (setFeeProtocolEventMem oldSlot ee out) (UInt256.ofNat 8) - rdata (cA, σ) k' C' := by - have hd8603 : decode code ⟨8603⟩ = some (.SWAP2, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8603⟩) (byte := 0x91) - (op := .SWAP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8604 : decode code ⟨8604⟩ = some (.SWAP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8604⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8605 : decode code ⟨8605⟩ = some (.DIV, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8605⟩) (byte := 0x04) - (op := .DIV) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8606 : decode code ⟨8606⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8606⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8607 : - decode code ⟨8607⟩ = - some (.Push .PUSH32, some (setFeeProtocolEventTopic, 32)) := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSetFeeProtocolOwnerCallPatchDisjointAfterFactory - (n := 33) (by native_decide) (by native_decide))] - native_decide - have hd8640 : decode code ⟨8640⟩ = some (.Push .PUSH1, some (⟨16⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8640⟩) - (n := ⟨16⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8642 : decode code ⟨8642⟩ = some (.DUP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8642⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8643 : decode code ⟨8643⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8643⟩) - (n := ⟨64⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8645 : decode code ⟨8645⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8645⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8646 : decode code ⟨8646⟩ = some (.MLOAD, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8646⟩) (byte := 0x51) - (op := .MLOAD) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8647 : decode code ⟨8647⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8647⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8649 : decode code ⟨8649⟩ = some (.SWAP4, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8649⟩) (byte := 0x93) - (op := .SWAP4) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8650 : decode code ⟨8650⟩ = some (.SWAP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8650⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8651 : decode code ⟨8651⟩ = some (.SWAP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8651⟩) (byte := 0x92) - (op := .SWAP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8652 : decode code ⟨8652⟩ = some (.MOD, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8652⟩) (byte := 0x06) - (op := .MOD) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8653 : decode code ⟨8653⟩ = some (.DUP4, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8653⟩) (byte := 0x83) - (op := .DUP4) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8654 : decode code ⟨8654⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8654⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8655 : decode code ⟨8655⟩ = some (.DUP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8655⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8656 : decode code ⟨8656⟩ = some (.MSTORE, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8656⟩) (byte := 0x52) - (op := .MSTORE) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8657 : decode code ⟨8657⟩ = some (.Push .PUSH1, some (⟨15⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8657⟩) - (n := ⟨15⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8659 : decode code ⟨8659⟩ = some (.Push .PUSH1, some (⟨4⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8659⟩) - (n := ⟨4⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8661 : decode code ⟨8661⟩ = some (.DUP7, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8661⟩) (byte := 0x86) - (op := .DUP7) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8662 : decode code ⟨8662⟩ = some (.SWAP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8662⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8663 : decode code ⟨8663⟩ = some (.SHR, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8663⟩) (byte := 0x1c) - (op := .SHR) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8664 : decode code ⟨8664⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8664⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8665 : decode code ⟨8665⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8665⟩) - (n := ⟨32⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8667 : decode code ⟨8667⟩ = some (.DUP4, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8667⟩) (byte := 0x83) - (op := .DUP4) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8668 : decode code ⟨8668⟩ = some (.ADD, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8668⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8669 : decode code ⟨8669⟩ = some (.MSTORE, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8669⟩) (byte := 0x52) - (op := .MSTORE) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8670 : decode code ⟨8670⟩ = some (.DUP7, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8670⟩) (byte := 0x86) - (op := .DUP7) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8671 : decode code ⟨8671⟩ = some (.DUP4, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8671⟩) (byte := 0x83) - (op := .DUP4) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8672 : decode code ⟨8672⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8672⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8673 : decode code ⟨8673⟩ = some (.DUP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8673⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8674 : decode code ⟨8674⟩ = some (.DUP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8674⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8675 : decode code ⟨8675⟩ = some (.ADD, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8675⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8676 : decode code ⟨8676⟩ = some (.MSTORE, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8676⟩) (byte := 0x52) - (op := .MSTORE) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8677 : decode code ⟨8677⟩ = some (.SWAP2, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8677⟩) (byte := 0x91) - (op := .SWAP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8678 : decode code ⟨8678⟩ = some (.DUP6, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8678⟩) (byte := 0x85) - (op := .DUP6) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8679 : decode code ⟨8679⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8679⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8680 : decode code ⟨8680⟩ = some (.Push .PUSH1, some (⟨96⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8680⟩) - (n := ⟨96⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8682 : decode code ⟨8682⟩ = some (.DUP3, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8682⟩) (byte := 0x82) - (op := .DUP3) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8683 : decode code ⟨8683⟩ = some (.ADD, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8683⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8684 : decode code ⟨8684⟩ = some (.MSTORE, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8684⟩) (byte := 0x52) - (op := .MSTORE) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8685 : decode code ⟨8685⟩ = some (.SWAP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8685⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8686 : decode code ⟨8686⟩ = some (.MLOAD, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8686⟩) (byte := 0x51) - (op := .MLOAD) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8687 : decode code ⟨8687⟩ = some (.SWAP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8687⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8688 : decode code ⟨8688⟩ = some (.DUP2, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8688⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8689 : decode code ⟨8689⟩ = some (.SWAP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8689⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8690 : decode code ⟨8690⟩ = some (.SUB, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8690⟩) (byte := 0x03) - (op := .SUB) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8691 : decode code ⟨8691⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8691⟩) - (n := ⟨128⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8693 : decode code ⟨8693⟩ = some (.ADD, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8693⟩) (byte := 0x01) - (op := .ADD) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8694 : decode code ⟨8694⟩ = some (.SWAP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8694⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8695 : decode code ⟨8695⟩ = some (.LOG1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8695⟩) (byte := 0xa1) - (op := .LOG1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have rd8652 := evm_run h with [ - raw swap2 hd8603 (by evm_ov), - raw swap1 hd8604 (by evm_ov), - raw div hd8605 (by evm_ov), - raw and hd8606 (by evm_ov), - raw pushConst setFeeProtocolEventTopic - (show Operation.POp.PUSH32 ≠ .PUSH0 by native_decide) - hd8607 - (by evm_ov), - raw push1 ⟨16⟩ hd8640 (by evm_ov), - raw dup3 hd8642 (by evm_ov), - raw push1 ⟨64⟩ hd8643 (by evm_ov), - raw dup1 hd8645 (by evm_ov), - raw mload 0 ⟨128⟩ setFeeProtocolOwnerStaticcallActiveWords hd8646 mem_cost - (setFeeProtocolOwnerStaticcallMem_mload64_of_size_ge out houtSize32 houtSize) - (by native_decide) (by evm_ov), - raw push1 ⟨255⟩ hd8647 (by evm_ov), - raw swap4 hd8649 (by evm_ov), - raw swap1 hd8650 (by evm_ov), - raw swap3 hd8651 (by evm_ov)] - have rd8653 := setFeeProtocolRDMod rd8652 hd8652 (by evm_ov) - have rd8696 := evm_run rd8653 with [ - raw dup4 hd8653 (by evm_ov), - raw and hd8654 (by evm_ov), - raw dup3 hd8655 (by evm_ov), - raw mstore 0 - (setFeeProtocolEventMem0 - (setFeeProtocolEventOldFeeProtocol0Word - (setFeeProtocolEventOldFeeProtocolWord oldSlot)) - (setFeeProtocolOwnerStaticcallMem out)) - setFeeProtocolOwnerStaticcallActiveWords hd8656 mem_cost rfl - (by native_decide) (by evm_ov), - raw push1 ⟨15⟩ hd8657 (by evm_ov), - raw push1 ⟨4⟩ hd8659 (by evm_ov), - raw dup7 hd8661 (by evm_ov), - raw swap1 hd8662 (by evm_ov), - raw shr hd8663 (by evm_ov), - raw and hd8664 (by evm_ov), - raw push1 ⟨32⟩ hd8665 (by evm_ov), - raw dup4 hd8667 (by evm_ov), - raw add hd8668 (by evm_ov), - raw mstore 3 - (setFeeProtocolEventMem1 - (setFeeProtocolEventOldFeeProtocol0Word - (setFeeProtocolEventOldFeeProtocolWord oldSlot)) - (setFeeProtocolEventOldFeeProtocol1Word - (setFeeProtocolEventOldFeeProtocolWord oldSlot)) - (setFeeProtocolOwnerStaticcallMem out)) - (UInt256.ofNat 6) hd8669 mem_cost rfl - (by native_decide) (by evm_ov), - raw dup7 hd8670 (by evm_ov), - raw dup4 hd8671 (by evm_ov), - raw and hd8672 (by evm_ov), - raw dup3 hd8673 (by evm_ov), - raw dup3 hd8674 (by evm_ov), - raw add hd8675 (by evm_ov), - raw mstore 3 - (setFeeProtocolEventMem2 - (setFeeProtocolEventOldFeeProtocol0Word - (setFeeProtocolEventOldFeeProtocolWord oldSlot)) - (setFeeProtocolEventOldFeeProtocol1Word - (setFeeProtocolEventOldFeeProtocolWord oldSlot)) - (setFeeProtocolEventNewFeeProtocol0Word ee) - (setFeeProtocolOwnerStaticcallMem out)) - (UInt256.ofNat 7) hd8676 mem_cost rfl - (by native_decide) (by evm_ov), - raw swap2 hd8677 (by evm_ov), - raw dup6 hd8678 (by evm_ov), - raw and hd8679 (by evm_ov), - raw push1 ⟨96⟩ hd8680 (by evm_ov), - raw dup3 hd8682 (by evm_ov), - raw add hd8683 (by evm_ov), - raw mstore 3 - (setFeeProtocolEventMem oldSlot ee out) - (UInt256.ofNat 8) hd8684 mem_cost - (by rfl) - (by native_decide) (by evm_ov), - raw swap1 hd8685 (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 8) hd8686 mem_cost - (setFeeProtocolEventMem_mload64_of_size_ge oldSlot ee out houtSize32 houtSize) - (by native_decide) (by evm_ov), - raw swap1 hd8687 (by evm_ov), - raw dup2 hd8688 (by evm_ov), - raw swap1 hd8689 (by evm_ov), - raw sub hd8690 (by evm_ov), - raw push1 ⟨128⟩ hd8691 (by evm_ov), - raw add hd8693 (by evm_ov), - raw swap1 hd8694 (by evm_ov), - raw log1 0 (UInt256.ofNat 8) hd8695 hperm mem_cost - (by native_decide) (by evm_ov)] - exact ⟨_, _, rd8696⟩ - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolSetFeeProtocolUnlockReturnEvm {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} {k C : ℕ} - {oldFeeProtocol : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨8696⟩ - (oldFeeProtocol :: setFeeProtocolArg1Word ee :: setFeeProtocolArg0Word ee :: ⟨857⟩ :: R) - mem aw rdata (cA, σ) k C) - (hperm : ee.perm = true) - (hov : R.length + 6 ≤ 1024) : - RDret code g s0 - (cA, sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (setFeeProtocolEvmUnlockedTrueSlotWord σ ee)) - ByteArray.empty := by - have hd8696 : decode code ⟨8696⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8696⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8697 : decode code ⟨8697⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8697⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8698 : decode code ⟨8698⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8698⟩) - (n := ⟨0⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8700 : decode code ⟨8700⟩ = some (.DUP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8700⟩) (byte := 0x80) - (op := .DUP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8701 : decode code ⟨8701⟩ = some (.SLOAD, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8701⟩) (byte := 0x54) - (op := .SLOAD) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8702 : decode code ⟨8702⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8702⟩) - (n := ⟨255⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8704 : decode code ⟨8704⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8704⟩) - (n := ⟨240⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8706 : decode code ⟨8706⟩ = some (.SHL, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8706⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8707 : decode code ⟨8707⟩ = some (.NOT, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8707⟩) (byte := 0x19) - (op := .NOT) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8708 : decode code ⟨8708⟩ = some (.AND, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8708⟩) (byte := 0x16) - (op := .AND) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8709 : decode code ⟨8709⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8709⟩) - (n := ⟨1⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8711 : decode code ⟨8711⟩ = some (.Push .PUSH1, some (⟨240⟩, 1)) := by - exact setFeeProtocolDecodePush1AfterFactory (pc := ⟨8711⟩) - (n := ⟨240⟩) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) - have hd8713 : decode code ⟨8713⟩ = some (.SHL, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8713⟩) (byte := 0x1b) - (op := .SHL) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8714 : decode code ⟨8714⟩ = some (.OR, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8714⟩) (byte := 0x17) - (op := .OR) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8715 : decode code ⟨8715⟩ = some (.SWAP1, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8715⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8716 : decode code ⟨8716⟩ = some (.SSTORE, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8716⟩) (byte := 0x55) - (op := .SSTORE) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8717 : decode code ⟨8717⟩ = some (.POP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8717⟩) (byte := 0x50) - (op := .POP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd8718 : decode code ⟨8718⟩ = some (.JUMP, .none) := by - refine setFeeProtocolDecodeNoArgAfterFactory (pc := ⟨8718⟩) (byte := 0x56) - (op := .JUMP) hpatch (by native_decide) (by native_decide) - (by native_decide) (by native_decide) (by native_decide) - have hd857 : decode code ⟨857⟩ = some (.JUMPDEST, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have hd858 : decode code ⟨858⟩ = some (.STOP, .none) := by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - have rd8701 := evm_run h with [ - raw pop hd8696 (by evm_ov), - raw pop hd8697 (by evm_ov), - raw push1 ⟨0⟩ hd8698 (by evm_ov), - raw dup1 hd8700 (by evm_ov)] - obtain ⟨_, _, rd8702₀⟩ := rd8701.sload hd8701 (by evm_ov) - have rd8716 := evm_run rd8702₀ with [ - raw push1 ⟨255⟩ hd8702 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨240⟩ hd8704 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd8706 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw not hd8707 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw and hd8708 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨1⟩ hd8709 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw push1 ⟨240⟩ hd8711 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw shl hd8713 (by - have h := hov - simp only [List.length_cons] at h ⊢ - omega), - raw lor hd8714 (by evm_ov), - raw swap1 hd8715 (by evm_ov)] - obtain ⟨_, _, rd8717⟩ := rd8716.sstore hperm hd8716 (by evm_ov) - have rd8718 := evm_run rd8717 with [ - raw pop hd8717 (by evm_ov)] - have rd857 := rd8718.jump hd8718 (uniswapV3PoolJumpDestPatched857 hpatch) (by evm_ov) - have rd858 := rd857.jumpdest hd857 (by evm_ov) - obtain ⟨k858, C858, rd858'⟩ : ∃ k' C', RD code ee g s0 ⟨858⟩ R mem aw rdata - (cA, sstoreAccountMap ee.codeOwner σ ⟨0⟩ - (setFeeProtocolEvmUnlockedTrueSlotWord σ ee)) k' C' := by - exact ⟨_, _, by - simpa [setFeeProtocolEvmUnlockedTrueSlotWord, setFeeProtocolEvmUnlockedClearMask, - codeOwnerStorageWord] using rd858⟩ - exact rd858'.stop hd858 (by - have h := hov - omega) - -theorem setFeeProtocolNewFeeProtocolNat_lt_word (I : ExecutionEnv) : - setFeeProtocolNewFeeProtocolNat I < UInt256.size := by - have h0 : (setFeeProtocolArg0Word I).toNat < 2 ^ 8 := by - simpa [setFeeProtocolArg0Word, setFeeProtocolUint8Mask, slot0Uint8Mask] using - slot0Uint8Mask_bound (calldataWord I.calldata 4) - have h1 : (setFeeProtocolArg1Word I).toNat < 2 ^ 8 := by - simpa [setFeeProtocolArg1Word, setFeeProtocolUint8Mask, slot0Uint8Mask] using - slot0Uint8Mask_bound (calldataWord I.calldata 36) - have hshift : - ((setFeeProtocolArg1Word I).toNat * 2 ^ 4) % EVM.wordModulus < 2 ^ 12 := by - exact lt_of_le_of_lt (Nat.mod_le _ _) (Nat.mul_lt_mul_of_pos_right h1 (by norm_num)) - have hsum : (setFeeProtocolArg0Word I).toNat + - ((setFeeProtocolArg1Word I).toNat * 2 ^ 4) % EVM.wordModulus < 2 ^ 13 := by - calc - (setFeeProtocolArg0Word I).toNat + - ((setFeeProtocolArg1Word I).toNat * 2 ^ 4) % EVM.wordModulus - < 2 ^ 8 + 2 ^ 12 := by omega - _ < 2 ^ 13 := by norm_num - dsimp [setFeeProtocolNewFeeProtocolNat] - exact lt_trans hsum (pow_lt_size (by omega : 13 < 256)) - -theorem setFeeProtocolNewFeeProtocolNat_mod_lt (I : ExecutionEnv) : - setFeeProtocolNewFeeProtocolNat I % 2 ^ 8 < 2 ^ 8 := - Nat.mod_lt _ (by norm_num) - -theorem setFeeProtocolFeeProtocolSlotWord_nat_lt (evm : EVM.State) (I : ExecutionEnv) : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 232 + - (setFeeProtocolNewFeeProtocolNat I % 2 ^ 8) * 2 ^ 232 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 240 * - 2 ^ 240 < - UInt256.size := by - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - have hlow : w.toNat % 2 ^ 232 ≤ 2 ^ 232 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hbyte : setFeeProtocolNewFeeProtocolNat I % 2 ^ 8 ≤ 2 ^ 8 - 1 := - Nat.le_pred_of_lt (setFeeProtocolNewFeeProtocolNat_mod_lt I) - have hhighLt : w.toNat / 2 ^ 240 < 2 ^ 16 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 240 * 2 ^ 16 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 240 ≤ 2 ^ 16 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : - (2 ^ 232 - 1) + (2 ^ 8 - 1) * 2 ^ 232 + (2 ^ 16 - 1) * 2 ^ 240 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - dsimp [w] at hlow hhigh - omega - -theorem setFeeProtocolUnlockedTrueSlotWord_nat_lt (evm : EVM.State) : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 240 + - 2 ^ 240 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 248 * - 2 ^ 248 < - UInt256.size := by - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ - have hlow : w.toNat % 2 ^ 240 ≤ 2 ^ 240 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (by norm_num)) - have hhighLt : w.toNat / 2 ^ 248 < 2 ^ 8 := by - apply Nat.div_lt_of_lt_mul - rw [show 2 ^ 248 * 2 ^ 8 = (2 : Nat) ^ 256 by rw [← Nat.pow_add]] - change w.val.val < UInt256.size - exact w.val.isLt - have hhigh : w.toNat / 2 ^ 248 ≤ 2 ^ 8 - 1 := Nat.le_pred_of_lt hhighLt - have hmax : (2 ^ 240 - 1) + 2 ^ 240 + (2 ^ 8 - 1) * 2 ^ 248 < - UInt256.size := by - norm_num [UInt256.size, Nat.pow_add] - dsimp [w] at hlow hhigh - omega - -private theorem setFeeProtocolEnabledNat_lt_16 {n : Nat} - (h : setFeeProtocolEnabledNat n) : n < 16 := by - rcases h with hzero | hrange - · omega - · omega - -private theorem setFeeProtocolUInt256_eq_of_toNat_eq {w : UInt256} {n : Nat} - (h : w.toNat = n) (hn : n < UInt256.size) : w = UInt256.ofNat n := by - apply u256_inj - rw [h] - exact (ulit_toNat' n hn).symm - -theorem setFeeProtocolEvmNewFeeProtocolWord_eq (I : ExecutionEnv) - (hfee0 : setFeeProtocolEnabledNat (setFeeProtocolArg0Word I).toNat) - (hfee1 : setFeeProtocolEnabledNat (setFeeProtocolArg1Word I).toNat) : - setFeeProtocolEvmNewFeeProtocolWord I = UInt256.ofNat (setFeeProtocolNewFeeProtocolNat I) := by - have h0lt16 := setFeeProtocolEnabledNat_lt_16 hfee0 - have h1lt16 := setFeeProtocolEnabledNat_lt_16 hfee1 - have h0lt : (setFeeProtocolArg0Word I).toNat < UInt256.size := - (setFeeProtocolArg0Word I).val.isLt - have h1lt : (setFeeProtocolArg1Word I).toNat < UInt256.size := - (setFeeProtocolArg1Word I).val.isLt - dsimp [setFeeProtocolEvmNewFeeProtocolWord, setFeeProtocolNewFeeProtocolNat] - interval_cases h0 : (setFeeProtocolArg0Word I).toNat <;> - interval_cases h1 : (setFeeProtocolArg1Word I).toNat <;> - rw [setFeeProtocolUInt256_eq_of_toNat_eq h0 h0lt, - setFeeProtocolUInt256_eq_of_toNat_eq h1 h1lt] <;> - native_decide - -theorem setFeeProtocolNewFeeProtocolNat_lt_256_of_enabled (I : ExecutionEnv) - (hfee0 : setFeeProtocolEnabledNat (setFeeProtocolArg0Word I).toNat) - (hfee1 : setFeeProtocolEnabledNat (setFeeProtocolArg1Word I).toNat) : - setFeeProtocolNewFeeProtocolNat I < 2 ^ 8 := by - have h0lt := setFeeProtocolEnabledNat_lt_16 hfee0 - have h1lt := setFeeProtocolEnabledNat_lt_16 hfee1 - dsimp [setFeeProtocolNewFeeProtocolNat] - have hmod : ((setFeeProtocolArg1Word I).toNat * 16) % EVM.wordModulus = - (setFeeProtocolArg1Word I).toNat * 16 := by - apply Nat.mod_eq_of_lt - have : (setFeeProtocolArg1Word I).toNat * 16 < 16 * 16 := by - exact Nat.mul_lt_mul_of_pos_right h1lt (by norm_num) - norm_num [EVM.wordModulus, EVM.twoPow] at this ⊢ - omega - rw [hmod] - have : (setFeeProtocolArg1Word I).toNat * 16 < 16 * 16 := by - exact Nat.mul_lt_mul_of_pos_right h1lt (by norm_num) - omega - -theorem setFeeProtocolFeeProtocolClearMask_toNat : - setFeeProtocolFeeProtocolClearMask.toNat = 2 ^ 256 - 2 ^ 240 + (2 ^ 232 - 1) := by - native_decide - -theorem natLandClearByte232 (n : Nat) (hn : n < 2 ^ 256) : - Nat.land n (2 ^ 256 - 2 ^ 240 + (2 ^ 232 - 1)) = - n % 2 ^ 232 + (n / 2 ^ 240) * 2 ^ 240 := by - apply Nat.eq_of_testBit_eq - intro i - change (n &&& (2 ^ 256 - 2 ^ 240 + (2 ^ 232 - 1))).testBit i = - (n % 2 ^ 232 + n / 2 ^ 240 * 2 ^ 240).testBit i - rw [Nat.testBit_and] - rw [show n % 2 ^ 232 + (n / 2 ^ 240) * 2 ^ 240 = - 2 ^ 240 * (n / 2 ^ 240) + n % 2 ^ 232 by ring] - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 240) - (b_lt := lt_trans (Nat.mod_lt _ (show 0 < 2 ^ 232 by norm_num)) - (by norm_num : 2 ^ 232 < 2 ^ 240))] - rw [show 2 ^ 256 - 2 ^ 240 + (2 ^ 232 - 1) = - 2 ^ 240 * (2 ^ 16 - 1) + (2 ^ 232 - 1) by norm_num [Nat.pow_add]] - have hmaskLow : 2 ^ 232 - 1 < 2 ^ 240 := by norm_num - rw [Nat.testBit_two_pow_mul_add (a := 2 ^ 16 - 1) (b_lt := hmaskLow)] - by_cases hi240 : i < 240 - · simp [hi240] - change (n.testBit i && (2 ^ 232 - 1).testBit i) = (n % 2 ^ 232).testBit i - by_cases hi232 : i < 232 - · have hmask : (2 ^ 232 - 1).testBit i = true := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_true hi232 - have hmod : (n % 2 ^ 232).testBit i = n.testBit i := by - rw [Nat.testBit_mod_two_pow] - simp [hi232] - rw [hmask, hmod] - simp - · have hmask : (2 ^ 232 - 1).testBit i = false := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_false hi232 - have hmod : (n % 2 ^ 232).testBit i = false := by - rw [Nat.testBit_mod_two_pow] - simp [hi232] - rw [hmask, hmod] - simp - · have h240le : 240 ≤ i := Nat.le_of_not_gt hi240 - simp [hi240] - change (n.testBit i && (2 ^ 16 - 1).testBit (i - 240)) = - (n / 2 ^ 240).testBit (i - 240) - by_cases hi256 : i < 256 - · have hsub16 : i - 240 < 16 := by omega - have hdiv := divPow_testBit n 240 i h240le - have hmask : (2 ^ 16 - 1).testBit (i - 240) = true := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_true hsub16 - rw [hdiv, hmask] - simp - · have hsub16 : ¬ i - 240 < 16 := by omega - have hnbit : n.testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hn (Nat.pow_le_pow_right (by norm_num) (by omega : 256 ≤ i))) - have hdivfalse : (n / 2 ^ 240).testBit (i - 240) = false := by - rw [divPow_testBit n 240 i h240le, hnbit] - have hmask : (2 ^ 16 - 1).testBit (i - 240) = false := by - rw [Nat.testBit_two_pow_sub_one] - exact decide_eq_false hsub16 - rw [hmask, hdivfalse] - simp - -private theorem nat_lor_packed_byte232 (n byte : Nat) (hbyte : byte < 2 ^ 8) : - Nat.lor (n % 2 ^ 232 + n / 2 ^ 240 * 2 ^ 240) (byte * 2 ^ 232) = - n % 2 ^ 232 + byte * 2 ^ 232 + n / 2 ^ 240 * 2 ^ 240 := by - apply Nat.eq_of_testBit_eq - intro i - change ((n % 2 ^ 232 + n / 2 ^ 240 * 2 ^ 240) ||| (byte * 2 ^ 232)).testBit i = - (n % 2 ^ 232 + byte * 2 ^ 232 + n / 2 ^ 240 * 2 ^ 240).testBit i - rw [Nat.testBit_or] - rw [show n % 2 ^ 232 + n / 2 ^ 240 * 2 ^ 240 = - 2 ^ 240 * (n / 2 ^ 240) + n % 2 ^ 232 by ring] - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 240) - (b_lt := lt_trans (Nat.mod_lt _ (show 0 < 2 ^ 232 by norm_num)) - (by norm_num : 2 ^ 232 < 2 ^ 240))] - rw [show n % 2 ^ 232 + byte * 2 ^ 232 + n / 2 ^ 240 * 2 ^ 240 = - 2 ^ 240 * (n / 2 ^ 240) + (2 ^ 232 * byte + n % 2 ^ 232) by ring] - have hmid : 2 ^ 232 * byte + n % 2 ^ 232 < 2 ^ 240 := by - have hlow : n % 2 ^ 232 ≤ 2 ^ 232 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (show 0 < 2 ^ 232 by norm_num)) - have hbytele : byte ≤ 2 ^ 8 - 1 := Nat.le_pred_of_lt hbyte - have hmax : 2 ^ 232 * (2 ^ 8 - 1) + (2 ^ 232 - 1) < 2 ^ 240 := by - norm_num [Nat.pow_add] - nlinarith - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 240) (b_lt := hmid)] - rw [Nat.testBit_two_pow_mul_add (a := byte) - (b_lt := Nat.mod_lt _ (show 0 < 2 ^ 232 by norm_num))] - rw [show byte * 2 ^ 232 = 2 ^ 232 * byte + 0 by ring] - rw [Nat.testBit_two_pow_mul_add (a := byte) (b_lt := show 0 < 2 ^ 232 by norm_num)] - by_cases hi232 : i < 232 - · simp [hi232] - · have h232le : 232 ≤ i := Nat.le_of_not_gt hi232 - have hlowfalse : (n % 2 ^ 232).testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le (Nat.mod_lt _ (show 0 < 2 ^ 232 by norm_num)) - (Nat.pow_le_pow_right (by norm_num) h232le)) - by_cases hi240 : i < 240 - · simp [hi232, hi240] - intro hlowtrue - have hlowfalse' : - (n % 6901746346790563787434755862277025452451108972170386555162524223799296).testBit i = - false := by - simpa using hlowfalse - rw [hlowfalse'] at hlowtrue - cases hlowtrue - · have hbytefalse : byte.testBit (i - 232) = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hbyte (Nat.pow_le_pow_right (by norm_num) (by omega))) - simp [hi232, hi240] - intro hbytetrue - rw [hbytefalse] at hbytetrue - cases hbytetrue - -private theorem nat_lor_packed_byte240 (n byte : Nat) (hbyte : byte < 2 ^ 8) : - Nat.lor (n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248) (byte * 2 ^ 240) = - n % 2 ^ 240 + byte * 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248 := by - apply Nat.eq_of_testBit_eq - intro i - change ((n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248) ||| (byte * 2 ^ 240)).testBit i = - (n % 2 ^ 240 + byte * 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248).testBit i - rw [Nat.testBit_or] - rw [show n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248 = - 2 ^ 248 * (n / 2 ^ 248) + n % 2 ^ 240 by ring] - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 248) - (b_lt := lt_trans (Nat.mod_lt _ (show 0 < 2 ^ 240 by norm_num)) - (by norm_num : 2 ^ 240 < 2 ^ 248))] - rw [show n % 2 ^ 240 + byte * 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248 = - 2 ^ 248 * (n / 2 ^ 248) + (2 ^ 240 * byte + n % 2 ^ 240) by ring] - have hmid : 2 ^ 240 * byte + n % 2 ^ 240 < 2 ^ 248 := by - have hlow : n % 2 ^ 240 ≤ 2 ^ 240 - 1 := - Nat.le_pred_of_lt (Nat.mod_lt _ (show 0 < 2 ^ 240 by norm_num)) - have hbytele : byte ≤ 2 ^ 8 - 1 := Nat.le_pred_of_lt hbyte - have hmax : 2 ^ 240 * (2 ^ 8 - 1) + (2 ^ 240 - 1) < 2 ^ 248 := by - norm_num [Nat.pow_add] - nlinarith - rw [Nat.testBit_two_pow_mul_add (a := n / 2 ^ 248) (b_lt := hmid)] - rw [Nat.testBit_two_pow_mul_add (a := byte) - (b_lt := Nat.mod_lt _ (show 0 < 2 ^ 240 by norm_num))] - rw [show byte * 2 ^ 240 = 2 ^ 240 * byte + 0 by ring] - rw [Nat.testBit_two_pow_mul_add (a := byte) (b_lt := show 0 < 2 ^ 240 by norm_num)] - by_cases hi240 : i < 240 - · simp [hi240] - · have h240le : 240 ≤ i := Nat.le_of_not_gt hi240 - have hlowfalse : (n % 2 ^ 240).testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le (Nat.mod_lt _ (show 0 < 2 ^ 240 by norm_num)) - (Nat.pow_le_pow_right (by norm_num) h240le)) - by_cases hi248 : i < 248 - · simp [hi240, hi248] - intro hlowtrue - have hlowfalse' : - (n % 1766847064778384329583297500742918515827483896875618958121606201292619776).testBit i = - false := by - simpa using hlowfalse - rw [hlowfalse'] at hlowtrue - cases hlowtrue - · have hbytefalse : byte.testBit (i - 240) = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hbyte (Nat.pow_le_pow_right (by norm_num) (by omega))) - simp [hi240, hi248] - intro hbytetrue - rw [hbytefalse] at hbytetrue - cases hbytetrue - -private theorem nat_lor_packed_true_byte240 (n : Nat) : - Nat.lor (n % 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248) (2 ^ 240) = - n % 2 ^ 240 + 2 ^ 240 + n / 2 ^ 248 * 2 ^ 248 := by - simpa using nat_lor_packed_byte240 n 1 (by norm_num : 1 < 2 ^ 8) - -theorem setFeeProtocolStorageLoad_codeOwner_eq {evm : EVM.State} {σ : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ evm.accountMap) (hEnv : evm.executionEnv = I) : - Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩ = codeOwnerStorageWord I σ ⟨0⟩ := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ (⟨0⟩ : UInt256) - simpa [Solm.EVM.storageLoad, State.lookupAccount, Account.lookupStorage, - codeOwnerStorageWord, hEnv] using hslot.symm - -theorem setFeeProtocolEvmFeeProtocolSlotWord_eq {evm : EVM.State} {σ : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ evm.accountMap) (hEnv : evm.executionEnv = I) - (hfee0 : setFeeProtocolEnabledNat (setFeeProtocolArg0Word I).toNat) - (hfee1 : setFeeProtocolEnabledNat (setFeeProtocolArg1Word I).toNat) : - setFeeProtocolEvmFeeProtocolSlotWord σ I = setFeeProtocolFeeProtocolSlotWord evm I := by - have hload := setFeeProtocolStorageLoad_codeOwner_eq (evm := evm) (σ := σ) (I := I) - hAccounts hEnv - have hnew := setFeeProtocolEvmNewFeeProtocolWord_eq I hfee0 hfee1 - have hnewLt := setFeeProtocolNewFeeProtocolNat_lt_256_of_enabled I hfee0 hfee1 - have hclearLt : - (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 232 + - (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 240 * 2 ^ 240 < UInt256.size := by - rw [← natLandClearByte232 (codeOwnerStorageWord I σ ⟨0⟩).toNat - (codeOwnerStorageWord I σ ⟨0⟩).val.isLt] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [UInt256.size]) - have hinsertLt : 2 ^ 232 * setFeeProtocolNewFeeProtocolNat I < UInt256.size := by - have hmul : 2 ^ 232 * setFeeProtocolNewFeeProtocolNat I < 2 ^ 232 * 2 ^ 8 := by - exact Nat.mul_lt_mul_of_pos_left hnewLt (by norm_num) - norm_num [UInt256.size, Nat.pow_add] at hmul ⊢ - omega - have hloadHigh : - (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 240 * 2 ^ 240 = - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 240 * - 2 ^ 240 := - congrArg (fun w : UInt256 => w.toNat / 2 ^ 240 * 2 ^ 240) hload.symm - have hloadLow : - (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 232 = - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 232 := - congrArg (fun w : UInt256 => w.toNat % 2 ^ 232) hload.symm - have hsourceLtNested : - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 232 + - (setFeeProtocolNewFeeProtocolNat I % 2 ^ 8 % 2 ^ 8) * 2 ^ 232 + - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 240 * - 2 ^ 240 < UInt256.size := by - rw [Nat.mod_eq_of_lt (setFeeProtocolNewFeeProtocolNat_mod_lt I)] - exact setFeeProtocolFeeProtocolSlotWord_nat_lt evm I - apply u256_inj - rw [setFeeProtocolEvmFeeProtocolSlotWord, setFeeProtocolFeeProtocolSlotWord] - rw [u256_lor_toNat, u256_land_toNat, u256_mul_toNat] - rw [hnew] - rw [ulit_toNat' _ (lt_trans hnewLt (by norm_num [UInt256.size]))] - rw [setFeeProtocolFeeProtocolClearMask_toNat] - rw [natLandClearByte232] - rw [Nat.mod_eq_of_lt hclearLt] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩).toNat = 2 ^ 232 by native_decide] - rw [Nat.mod_eq_of_lt hinsertLt] - rw [show 2 ^ 232 * setFeeProtocolNewFeeProtocolNat I = - setFeeProtocolNewFeeProtocolNat I * 2 ^ 232 by ring] - rw [nat_lor_packed_byte232 _ _ hnewLt] - rw [hloadHigh, hloadLow] - rw [← show setFeeProtocolNewFeeProtocolNat I % 2 ^ 8 = setFeeProtocolNewFeeProtocolNat I by - exact Nat.mod_eq_of_lt hnewLt] - rw [ulit_toNat' _ hsourceLtNested] - rw [Nat.mod_eq_of_lt (setFeeProtocolNewFeeProtocolNat_mod_lt I)] - exact Nat.mod_eq_of_lt (setFeeProtocolFeeProtocolSlotWord_nat_lt evm I) - exact (codeOwnerStorageWord I σ ⟨0⟩).val.isLt - -theorem setFeeProtocolEvmUnlockedClearMask_toNat : - setFeeProtocolEvmUnlockedClearMask.toNat = 2 ^ 256 - 2 ^ 248 + (2 ^ 240 - 1) := by - native_decide - -theorem setFeeProtocolEvmUnlockedTrueSlotWord_eq {evm : EVM.State} {σ : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ evm.accountMap) (hEnv : evm.executionEnv = I) : - setFeeProtocolEvmUnlockedTrueSlotWord σ I = setFeeProtocolUnlockedTrueSlotWord evm := by - have hload := setFeeProtocolStorageLoad_codeOwner_eq (evm := evm) (σ := σ) (I := I) - hAccounts hEnv - have hclearLt : - (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 240 + - (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 248 * 2 ^ 248 < UInt256.size := by - rw [← natLandClearByte240 (codeOwnerStorageWord I σ ⟨0⟩).toNat - (codeOwnerStorageWord I σ ⟨0⟩).val.isLt] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [UInt256.size]) - have hloadHigh : - (codeOwnerStorageWord I σ ⟨0⟩).toNat / 2 ^ 248 * 2 ^ 248 = - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat / 2 ^ 248 * - 2 ^ 248 := - congrArg (fun w : UInt256 => w.toNat / 2 ^ 248 * 2 ^ 248) hload.symm - have hloadLow : - (codeOwnerStorageWord I σ ⟨0⟩).toNat % 2 ^ 240 = - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩).toNat % 2 ^ 240 := - congrArg (fun w : UInt256 => w.toNat % 2 ^ 240) hload.symm - apply u256_inj - rw [setFeeProtocolEvmUnlockedTrueSlotWord, setFeeProtocolUnlockedTrueSlotWord] - rw [u256_lor_toNat, u256_land_toNat] - rw [setFeeProtocolEvmUnlockedClearMask_toNat] - rw [nat_land_comm] - rw [natLandClearByte240] - rw [Nat.mod_eq_of_lt hclearLt] - rw [show (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨240⟩).toNat = 2 ^ 240 by native_decide] - rw [nat_lor_comm] - rw [nat_lor_packed_true_byte240] - rw [hloadHigh, hloadLow] - rw [ulit_toNat' _ (setFeeProtocolUnlockedTrueSlotWord_nat_lt evm)] - exact Nat.mod_eq_of_lt (setFeeProtocolUnlockedTrueSlotWord_nat_lt evm) - exact (codeOwnerStorageWord I σ ⟨0⟩).val.isLt - -theorem setFeeProtocolFinalAccountMapEquiv {evmOwner : EVM.State} {σOwnerEvm : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σOwnerEvm evmOwner.accountMap) - (hEnv : evmOwner.executionEnv = I) - (hfee0 : setFeeProtocolEnabledNat (setFeeProtocolArg0Word I).toNat) - (hfee1 : setFeeProtocolEnabledNat (setFeeProtocolArg1Word I).toNat) : - accountMapEquiv - (sstoreAccountMap I.codeOwner - (sstoreAccountMap I.codeOwner σOwnerEvm ⟨0⟩ - (setFeeProtocolEvmFeeProtocolSlotWord σOwnerEvm I)) - ⟨0⟩ - (setFeeProtocolEvmUnlockedTrueSlotWord - (sstoreAccountMap I.codeOwner σOwnerEvm ⟨0⟩ - (setFeeProtocolEvmFeeProtocolSlotWord σOwnerEvm I)) I)) - (setFeeProtocolAfterUnlockState - (setFeeProtocolAfterFeeProtocolState evmOwner I)).accountMap := by - have hfirstWord := setFeeProtocolEvmFeeProtocolSlotWord_eq - (evm := evmOwner) (σ := σOwnerEvm) (I := I) hAccounts hEnv hfee0 hfee1 - have hFirstAccounts : - accountMapEquiv - (sstoreAccountMap I.codeOwner σOwnerEvm ⟨0⟩ - (setFeeProtocolEvmFeeProtocolSlotWord σOwnerEvm I)) - (setFeeProtocolAfterFeeProtocolState evmOwner I).accountMap := by - rw [hfirstWord] - simpa [setFeeProtocolAfterFeeProtocolState, storageStore_accountMap, hEnv] using - accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (setFeeProtocolFeeProtocolSlotWord evmOwner I) hAccounts - have hFirstEnv : (setFeeProtocolAfterFeeProtocolState evmOwner I).executionEnv = I := by - simp [setFeeProtocolAfterFeeProtocolState, storageStore_executionEnv, hEnv] - have hsecondWord := setFeeProtocolEvmUnlockedTrueSlotWord_eq - (evm := setFeeProtocolAfterFeeProtocolState evmOwner I) - (σ := sstoreAccountMap I.codeOwner σOwnerEvm ⟨0⟩ - (setFeeProtocolEvmFeeProtocolSlotWord σOwnerEvm I)) - (I := I) hFirstAccounts hFirstEnv - rw [hsecondWord] - simpa [setFeeProtocolAfterUnlockState, storageStore_accountMap, hFirstEnv] using - accountMapEquiv_sstoreAccountMap I.codeOwner ⟨0⟩ - (setFeeProtocolUnlockedTrueSlotWord (setFeeProtocolAfterFeeProtocolState evmOwner I)) - hFirstAccounts - -theorem setFeeProtocolStorageLocStore_feeProtocol (evm : EVM.State) (I : ExecutionEnv) : - storageLocStore evm setFeeProtocolFeeProtocolLoc (setFeeProtocolNewFeeProtocolValue I) = - some (setFeeProtocolAfterFeeProtocolState evm I) := by - unfold storageLocStore storageLocWriteWord setFeeProtocolFeeProtocolLoc loc - simp only [valueToWord, bind, Option.bind] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner { val := 0 } - show fromBytes' - ((List.take 29 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof - (UInt256.ofNat (setFeeProtocolNewFeeProtocolNat I)))) ++ - List.drop (29 + 1) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (setFeeProtocolFeeProtocolSlotWord evm I).toNat - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [show 256 ^ (29 : Nat) = 2 ^ 232 by norm_num [Nat.pow_add]] - rw [show 256 ^ (1 : Nat) = 2 ^ 8 by norm_num] - rw [show 256 ^ (30 : Nat) = 2 ^ 240 by norm_num [Nat.pow_add]] - have hnewLt := setFeeProtocolNewFeeProtocolNat_lt_word I - rw [ulit_toNat' _ hnewLt] - have hlen29 : (List.take 29 (EVM.Word.toBytesLEWithSizeProof w).1).length = 29 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - have hlen1 : - (List.take 1 (EVM.Word.toBytesLEWithSizeProof - (UInt256.ofNat (setFeeProtocolNewFeeProtocolNat I))).1).length = 1 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof - (UInt256.ofNat (setFeeProtocolNewFeeProtocolNat I))).2] - norm_num - have hlen30 : - (List.take 29 (EVM.Word.toBytesLEWithSizeProof w).1 ++ - List.take 1 (EVM.Word.toBytesLEWithSizeProof - (UInt256.ofNat (setFeeProtocolNewFeeProtocolNat I))).1).length = 30 := by - rw [List.length_append, hlen29, hlen1] - rw [hlen29, hlen30] - rw [show (setFeeProtocolFeeProtocolSlotWord evm I).toNat = - w.toNat % 2 ^ 232 + (setFeeProtocolNewFeeProtocolNat I % 2 ^ 8) * 2 ^ 232 + - w.toNat / 2 ^ 240 * 2 ^ 240 by - dsimp [setFeeProtocolFeeProtocolSlotWord, w] - exact ulit_toNat' _ (setFeeProtocolFeeProtocolSlotWord_nat_lt evm I)] - ring - -theorem setFeeProtocolStorageLocStore_unlocked_true (evm : EVM.State) : - storageLocStore evm setFeeProtocolUnlockedLoc (.bool true) = - some (setFeeProtocolAfterUnlockState evm) := by - unfold storageLocStore storageLocWriteWord setFeeProtocolUnlockedLoc loc - simp only [valueToWord, Bool.toUInt256_true, bind, Option.bind] - congr 2 - apply u256_inj - let w := Solm.EVM.storageLoad evm evm.executionEnv.codeOwner { val := 0 } - show fromBytes' - ((List.take 30 ↑(EVM.Word.toBytesLEWithSizeProof w) ++ - List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1))) ++ - List.drop (30 + 1) ↑(EVM.Word.toBytesLEWithSizeProof w)) = - (setFeeProtocolUnlockedTrueSlotWord evm).toNat - rw [show List.take 1 ↑(EVM.Word.toBytesLEWithSizeProof (UInt256.ofNat 1)) = - ([1] : List UInt8) by - native_decide] - rw [fromBytes'_append, fromBytes'_append] - rw [fromBytes'_take_wordLE, fromBytes'_drop_wordLE] - rw [show 256 ^ (30 : Nat) = 2 ^ 240 by norm_num [Nat.pow_add]] - rw [show 256 ^ (31 : Nat) = 2 ^ 248 by norm_num [Nat.pow_add]] - have hlen30 : (List.take 30 (EVM.Word.toBytesLEWithSizeProof w).1).length = 30 := by - rw [List.length_take, (EVM.Word.toBytesLEWithSizeProof w).2] - norm_num - have hlen31 : (List.take 30 (EVM.Word.toBytesLEWithSizeProof w).1 ++ [1]).length = 31 := by - rw [List.length_append, hlen30] - norm_num - rw [hlen30, hlen31] - rw [show (setFeeProtocolUnlockedTrueSlotWord evm).toNat = - w.toNat % 2 ^ 240 + 2 ^ 240 + w.toNat / 2 ^ 248 * 2 ^ 248 by - dsimp [setFeeProtocolUnlockedTrueSlotWord, w] - exact ulit_toNat' _ (setFeeProtocolUnlockedTrueSlotWord_nat_lt evm)] - simp [fromBytes'] - ring - -abbrev setFeeProtocolOldFeeProtocolWord (evm : EVM.State) : UInt256 := - UInt256.land - (UInt256.div (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - (slot0ShiftBytes 29)) - slot0Uint8Mask - -abbrev setFeeProtocolOldFeeProtocolValue (evm : EVM.State) : Value := - .int (Int.ofNat (setFeeProtocolOldFeeProtocolWord evm).toNat) - -abbrev setFeeProtocolStoreWithOwnerAndOld (I : ExecutionEnv) (out : ByteArray) - (evm : EVM.State) : Store := - (setFeeProtocolStoreWithOwner I out).insert "feeProtocolOld" - (setFeeProtocolOldFeeProtocolValue evm) - -theorem setFeeProtocolStoreWithOwnerAndOld_feeProtocol0 (I : ExecutionEnv) (out : ByteArray) - (evm : EVM.State) : - (setFeeProtocolStoreWithOwnerAndOld I out evm).get? "feeProtocol0" = - some (setFeeProtocolArg0Value I) := by - rw [setFeeProtocolStoreWithOwnerAndOld] - rw [store_get_ne (setFeeProtocolStoreWithOwner I out) - (setFeeProtocolOldFeeProtocolValue evm) (by decide)] - exact setFeeProtocolStoreWithOwner_feeProtocol0 I out - -theorem setFeeProtocolStoreWithOwnerAndOld_feeProtocol1 (I : ExecutionEnv) (out : ByteArray) - (evm : EVM.State) : - (setFeeProtocolStoreWithOwnerAndOld I out evm).get? "feeProtocol1" = - some (setFeeProtocolArg1Value I) := by - rw [setFeeProtocolStoreWithOwnerAndOld] - rw [store_get_ne (setFeeProtocolStoreWithOwner I out) - (setFeeProtocolOldFeeProtocolValue evm) (by decide)] - exact setFeeProtocolStoreWithOwner_feeProtocol1 I out - -theorem evalExpr_setFeeProtocol_feeProtocol0_withOld {v : PoolImmutables} - (evm evmOld : EVM.State) (I : ExecutionEnv) (out : ByteArray) : - evalExpr? (config v) - { contract := contract v, locals := setFeeProtocolStoreWithOwnerAndOld I out evmOld } - evm (.var "feeProtocol0") = .ok (setFeeProtocolArg0Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setFeeProtocolStoreWithOwnerAndOld_feeProtocol0] - -theorem evalExpr_setFeeProtocol_feeProtocol1_withOld {v : PoolImmutables} - (evm evmOld : EVM.State) (I : ExecutionEnv) (out : ByteArray) : - evalExpr? (config v) - { contract := contract v, locals := setFeeProtocolStoreWithOwnerAndOld I out evmOld } - evm (.var "feeProtocol1") = .ok (setFeeProtocolArg1Value I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [setFeeProtocolStoreWithOwnerAndOld_feeProtocol1] - -theorem evalExpr_setFeeProtocol_feeProtocolStorage {v : PoolImmutables} - (evm : EVM.State) (I : ExecutionEnv) (out : ByteArray) : - evalExpr? (config v) { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } - evm (.storage (slot0F "feeProtocol")) = - .ok (setFeeProtocolOldFeeProtocolValue evm) := by - rw [evalExpr_storage_scalar - (t := .int uint8Int) - (slot := slot0F "feeProtocol") - (er := { base := "slot0", steps := [.field "feeProtocol"] }) - (loc := setFeeProtocolFeeProtocolLoc) - (hbase := by simp [slot0F, setFeeProtocolStoreWithOwner, setFeeProtocolStore]) - (her := by - simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - uint8St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - setFeeProtocolFeeProtocolLoc, loc])] - simpa [setFeeProtocolOldFeeProtocolValue, setFeeProtocolOldFeeProtocolWord] using - slot0StorageLocLoad_feeProtocol evm - -theorem setFeeProtocolArg1Word_toNat_lt_wordModulus (I : ExecutionEnv) : - (setFeeProtocolArg1Word I).toNat < EVM.wordModulus := by - have h1small : (setFeeProtocolArg1Word I).toNat < 2 ^ 8 := by - simpa [setFeeProtocolArg1Word, setFeeProtocolUint8Mask, slot0Uint8Mask] using - slot0Uint8Mask_bound (calldataWord I.calldata 36) - exact lt_trans h1small (by - change 2 ^ 8 < 2 ^ 256 - exact Nat.pow_lt_pow_right (by norm_num) (by norm_num)) - -theorem setFeeProtocolArg1Word_int_lt_wordModulus (I : ExecutionEnv) : - (Int.ofNat (setFeeProtocolArg1Word I).toNat) < (EVM.wordModulus : Int) := - Int.ofNat_lt.mpr (setFeeProtocolArg1Word_toNat_lt_wordModulus I) - -theorem evalBinaryOp_setFeeProtocol_shl_feeProtocol1 (I : ExecutionEnv) : - evalBinaryOp? .shl (setFeeProtocolArg1Value I) (.int 4) = - .ok (.int (((setFeeProtocolArg1Word I).toNat : Int) * 2 ^ (4 : Nat) % - (EVM.wordModulus : Int))) := by - have h1ltInt := setFeeProtocolArg1Word_int_lt_wordModulus I - simp only [evalBinaryOp?] - rw [if_pos (by - constructor - · exact Int.natCast_nonneg _ - · constructor - · exact h1ltInt - · norm_num)] - rw [if_neg (by norm_num)] - rw [show Int.toNat 4 = 4 by native_decide] - rw [show (Int.ofNat (setFeeProtocolArg1Word I).toNat).toNat = - (setFeeProtocolArg1Word I).toNat by simp] - -theorem evalBinaryOp_setFeeProtocol_add_newFeeProtocol (I : ExecutionEnv) : - evalBinaryOp? .add (setFeeProtocolArg0Value I) - (.int (((setFeeProtocolArg1Word I).toNat : Int) * 2 ^ (4 : Nat) % - (EVM.wordModulus : Int))) = - .ok (setFeeProtocolNewFeeProtocolValue I) := by - simp only [evalBinaryOp?] - congr 2 - -theorem evalExpr_setFeeProtocol_shl_feeProtocol1_withOld {v : PoolImmutables} - (evm evmOld : EVM.State) (I : ExecutionEnv) (out : ByteArray) : - evalExpr? (config v) - { contract := contract v, locals := setFeeProtocolStoreWithOwnerAndOld I out evmOld } - evm (shlE (.var "feeProtocol1") (.intLit 4)) = - .ok (.int (((setFeeProtocolArg1Word I).toNat : Int) * 2 ^ (4 : Nat) % - (EVM.wordModulus : Int))) := by - simp only [shlE, evalExpr?, evalExpr_setFeeProtocol_feeProtocol1_withOld, bind, - EvalResult.bind, pure] - exact evalBinaryOp_setFeeProtocol_shl_feeProtocol1 I - -theorem evalExpr_setFeeProtocol_newFeeProtocol_withOld {v : PoolImmutables} - (evm evmOld : EVM.State) (I : ExecutionEnv) (out : ByteArray) : - evalExpr? (config v) - { contract := contract v, locals := setFeeProtocolStoreWithOwnerAndOld I out evmOld } - evm (addE (.var "feeProtocol0") (shlE (.var "feeProtocol1") (.intLit 4))) = - .ok (setFeeProtocolNewFeeProtocolValue I) := by - simp only [addE, evalExpr?, evalExpr_setFeeProtocol_feeProtocol0_withOld, - evalExpr_setFeeProtocol_shl_feeProtocol1_withOld, bind, EvalResult.bind] - exact evalBinaryOp_setFeeProtocol_add_newFeeProtocol I - -theorem assignStorageRef_setFeeProtocol_feeProtocol {v : PoolImmutables} - (evm evmOld : EVM.State) (I : ExecutionEnv) (out : ByteArray) : - assignStorageRef? (config v) - { contract := contract v, locals := setFeeProtocolStoreWithOwnerAndOld I out evmOld } - evm .storage (slot0F "feeProtocol") (setFeeProtocolNewFeeProtocolValue I) = - .ok ({ contract := contract v, - locals := setFeeProtocolStoreWithOwnerAndOld I out evmOld }, - setFeeProtocolAfterFeeProtocolState evm I) := by - apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "feeProtocol"] }) - (ty := .elem (.int uint8Int)) - (loc := setFeeProtocolFeeProtocolLoc) - · simp [slot0F, setFeeProtocolStoreWithOwnerAndOld, setFeeProtocolStoreWithOwner, - setFeeProtocolStore] - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - uint8St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - setFeeProtocolFeeProtocolLoc, loc] - · trivial - · exact setFeeProtocolStorageLocStore_feeProtocol evm I - -theorem assignStorageRef_setFeeProtocol_unlocked_true {v : PoolImmutables} - (evm evmOld : EVM.State) (I : ExecutionEnv) (out : ByteArray) : - assignStorageRef? (config v) - { contract := contract v, locals := setFeeProtocolStoreWithOwnerAndOld I out evmOld } - evm .storage (slot0F "unlocked") (.bool true) = - .ok ({ contract := contract v, - locals := setFeeProtocolStoreWithOwnerAndOld I out evmOld }, - setFeeProtocolAfterUnlockState evm) := by - apply assignStorageRef_storage_scalar_value - (er := { base := "slot0", steps := [.field "unlocked"] }) - (ty := .elem .bool) - (loc := setFeeProtocolUnlockedLoc) - · simp [slot0F, setFeeProtocolStoreWithOwnerAndOld, setFeeProtocolStoreWithOwner, - setFeeProtocolStore] - · simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind] - · simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, boolSt] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - setFeeProtocolUnlockedLoc, loc] - · trivial - · exact setFeeProtocolStorageLocStore_unlocked_true evm - -theorem uniswapV3PoolSetFeeProtocolSourceSuccessBody - {v : PoolImmutables} {cA gh bl σ σ₀ A I} {g : Sat256} - {evmOwner : EVM.State} {out : ByteArray} - (hprefix : - ExecBlock (config v) { contract := contract v, locals := setFeeProtocolStore I } - (initState cA gh bl σ σ₀ g A I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")), - .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))) ] - (.ok { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evmOwner)) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (setFeeProtocolStore I) - (setfeeprotocolTransition v).body - (.returned - { contract := contract v, locals := setFeeProtocolStoreWithOwnerAndOld I out evmOwner } - (setFeeProtocolAfterUnlockState - (setFeeProtocolAfterFeeProtocolState evmOwner I)) - none) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (setFeeProtocolStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .require (.storage (slot0F "unlocked")), - .assign .storage (slot0F "unlocked") (.boolLit false), - .require (.binary .gt (.extCodeSize (addrLit v.factory)) (.intLit 0)), - .externalCall (addrLit v.factory) "owner" (.intLit 0) [] "_factoryOwner" - (perm := false), - .require (eqE (.env .caller) (.var "_factoryOwner")), - .require - (andE (feeProtocolEnabled (.var "feeProtocol0")) - (feeProtocolEnabled (.var "feeProtocol1"))), - .letDecl "feeProtocolOld" (some uint8) (.storage (slot0F "feeProtocol")), - .assign .storage (slot0F "feeProtocol") - (addE (.var "feeProtocol0") (shlE (.var "feeProtocol1") (.intLit 4))), - .assign .storage (slot0F "unlocked") (.boolLit true) ] - (.returned - { contract := contract v, locals := setFeeProtocolStoreWithOwnerAndOld I out evmOwner } - (setFeeProtocolAfterUnlockState - (setFeeProtocolAfterFeeProtocolState evmOwner I)) - none) - refine ExecFuncBody.execBlockOK ?_ - have htail : - ExecBlock (config v) - { contract := contract v, locals := setFeeProtocolStoreWithOwner I out } evmOwner - [ .letDecl "feeProtocolOld" (some uint8) (.storage (slot0F "feeProtocol")), - .assign .storage (slot0F "feeProtocol") - (addE (.var "feeProtocol0") (shlE (.var "feeProtocol1") (.intLit 4))), - .assign .storage (slot0F "unlocked") (.boolLit true) ] - (.ok - { contract := contract v, locals := setFeeProtocolStoreWithOwnerAndOld I out evmOwner } - (setFeeProtocolAfterUnlockState - (setFeeProtocolAfterFeeProtocolState evmOwner I))) := by - refine ExecBlock.consNormal - (ExecStmt.letDecl (evalExpr_setFeeProtocol_feeProtocolStorage evmOwner I out)) ?_ - refine ExecBlock.consNormal - (ExecStmt.assign - (evalExpr_setFeeProtocol_newFeeProtocol_withOld - evmOwner evmOwner I out) - (assignStorageRef_setFeeProtocol_feeProtocol evmOwner evmOwner I out)) ?_ - exact ExecBlock.consNormal - (ExecStmt.assign (by simp [evalExpr?, pure]) - (assignStorageRef_setFeeProtocol_unlocked_true - (setFeeProtocolAfterFeeProtocolState evmOwner I) evmOwner I out)) - ExecBlock.nil - simpa using execBlock_append hprefix htail - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Slot0.lean b/Benchmarks/UniswapV3Pool/Slot0.lean deleted file mode 100644 index d24f64bc..00000000 --- a/Benchmarks/UniswapV3Pool/Slot0.lean +++ /dev/null @@ -1,1904 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common -import Benchmarks.UniswapV3Pool.TickSpacing -import Reasoning.MemCascade - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev slot0SlotWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I ⟨0⟩ - -abbrev slot0ShiftBytes (n : Nat) : UInt256 := - UInt256.ofNat (256 ^ n) - -abbrev slot0Uint160Mask : UInt256 := UInt256.ofNat (2 ^ 160 - 1) -abbrev slot0Uint24Mask : UInt256 := UInt256.ofNat (2 ^ 24 - 1) -abbrev slot0Uint16Mask : UInt256 := UInt256.ofNat (2 ^ 16 - 1) -abbrev slot0Uint8Mask : UInt256 := UInt256.ofNat (2 ^ 8 - 1) - -abbrev slot0SqrtPriceX96Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (slot0SlotWord σ I) slot0Uint160Mask - -abbrev slot0TickRawWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 20)) slot0Uint24Mask - -abbrev slot0TickReturnWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨2⟩ (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 20)) - -abbrev slot0ObservationIndexWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 23)) slot0Uint16Mask - -abbrev slot0ObservationCardinalityWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 25)) slot0Uint16Mask - -abbrev slot0ObservationCardinalityNextWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 27)) slot0Uint16Mask - -abbrev slot0FeeProtocolWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 29)) slot0Uint8Mask - -abbrev slot0UnlockedRawWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 30)) slot0Uint8Mask - -abbrev slot0BoolReturnWord (u : UInt256) : UInt256 := - UInt256.isZero (UInt256.isZero u) - -abbrev slot0ReturnValues (σ : AccountMap) (I : ExecutionEnv) : List Value := - [ .int (Int.ofNat (slot0SqrtPriceX96Word σ I).toNat), - wordToElem (.int int24Int) (slot0TickRawWord σ I), - .int (Int.ofNat (slot0ObservationIndexWord σ I).toNat), - .int (Int.ofNat (slot0ObservationCardinalityWord σ I).toNat), - .int (Int.ofNat (slot0ObservationCardinalityNextWord σ I).toNat), - .int (Int.ofNat (slot0FeeProtocolWord σ I).toNat), - wordToElem .bool (slot0UnlockedRawWord σ I) ] - -theorem slot0Uint160Mask_bound (w : UInt256) : - (UInt256.land w slot0Uint160Mask).toNat < EVM.twoPow 160 := by - rw [show slot0Uint160Mask = solcAddrMask by native_decide] - simpa [EVM.addressModulus] using solcAddrMask_result_canonical w - -theorem slot0Uint160Mask_clean {w : UInt256} (hcanon : w.toNat < EVM.twoPow 160) : - UInt256.land w slot0Uint160Mask = w := by - rw [show slot0Uint160Mask = solcAddrMask by native_decide] - exact solcAddrMask_clean (by simpa [EVM.addressModulus] using hcanon) - -theorem slot0Uint24Mask_toNat : - slot0Uint24Mask.toNat = 2 ^ 24 - 1 := by - exact ulit_toNat' _ (by norm_num [UInt256.size]) - -theorem slot0Uint16Mask_toNat : - slot0Uint16Mask.toNat = 2 ^ 16 - 1 := by - exact ulit_toNat' _ (by norm_num [UInt256.size]) - -theorem slot0Uint16Mask_bound (w : UInt256) : - (UInt256.land w slot0Uint16Mask).toNat < EVM.twoPow 16 := by - rw [uland_toNat, slot0Uint16Mask_toNat] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [EVM.twoPow]) - -theorem slot0Uint16Mask_clean {w : UInt256} (hcanon : w.toNat < EVM.twoPow 16) : - UInt256.land w slot0Uint16Mask = w := by - apply u256_inj - show Nat.land w.toNat slot0Uint16Mask.toNat % EVM.twoPow 256 = w.toNat - rw [slot0Uint16Mask_toNat, nat_land_mask_eq_mod] - rw [show EVM.twoPow 16 = 2 ^ 16 from rfl] at hcanon - rw [Nat.mod_eq_of_lt hcanon] - exact Nat.mod_eq_of_lt w.val.isLt - -theorem slot0Uint16Mask_clean_left {w : UInt256} (hcanon : w.toNat < EVM.twoPow 16) : - UInt256.land slot0Uint16Mask w = w := by - rw [u256_land_comm slot0Uint16Mask w] - exact slot0Uint16Mask_clean hcanon - -theorem slot0Uint8Mask_toNat : - slot0Uint8Mask.toNat = 2 ^ 8 - 1 := by - exact ulit_toNat' _ (by norm_num [UInt256.size]) - -theorem slot0Uint8Mask_bound (w : UInt256) : - (UInt256.land w slot0Uint8Mask).toNat < EVM.twoPow 8 := by - rw [uland_toNat, slot0Uint8Mask_toNat] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [EVM.twoPow]) - -theorem slot0Uint8Mask_clean {w : UInt256} (hcanon : w.toNat < EVM.twoPow 8) : - UInt256.land w slot0Uint8Mask = w := by - apply u256_inj - show Nat.land w.toNat slot0Uint8Mask.toNat % EVM.twoPow 256 = w.toNat - rw [slot0Uint8Mask_toNat, nat_land_mask_eq_mod] - rw [show EVM.twoPow 8 = 2 ^ 8 from rfl] at hcanon - rw [Nat.mod_eq_of_lt hcanon] - exact Nat.mod_eq_of_lt w.val.isLt - -theorem slot0Sint24Value_mask (w : UInt256) : - tickSpacingSint24Value (UInt256.land w slot0Uint24Mask) = tickSpacingSint24Value w := by - unfold tickSpacingSint24Value - have hmod : (UInt256.land w slot0Uint24Mask).toNat % EVM.twoPow 24 = - w.toNat % EVM.twoPow 24 := by - rw [uland_toNat, slot0Uint24Mask_toNat] - change Nat.land w.toNat (2 ^ 24 - 1) % EVM.twoPow 24 = - w.toNat % EVM.twoPow 24 - rw [nat_land_mask_eq_mod] - simp [EVM.twoPow] - rw [hmod] - -theorem slot0Sint24Value_ge (w : UInt256) : - -(2 ^ 23 : Int) ≤ tickSpacingSint24Value w := by - unfold tickSpacingSint24Value - by_cases h : w.toNat % EVM.twoPow 24 < EVM.twoPow 23 - · rw [if_pos h] - exact le_trans (by norm_num : -(2 ^ 23 : Int) ≤ 0) (Int.natCast_nonneg _) - · rw [if_neg h] - have hmhi := Nat.mod_lt w.toNat (by norm_num [EVM.twoPow] : 0 < EVM.twoPow 24) - norm_num [EVM.twoPow] at h hmhi ⊢ - omega - -theorem slot0Sint24Value_lt (w : UInt256) : - tickSpacingSint24Value w < (2 ^ 23 : Int) := by - unfold tickSpacingSint24Value - by_cases h : w.toNat % EVM.twoPow 24 < EVM.twoPow 23 - · rw [if_pos h] - norm_num [EVM.twoPow] at h ⊢ - omega - · rw [if_neg h] - have hmhi := Nat.mod_lt w.toNat (by norm_num [EVM.twoPow] : 0 < EVM.twoPow 24) - norm_num [EVM.twoPow] at h hmhi ⊢ - omega - -theorem slot0TickRawValue_wordOfInt (w : UInt256) : - EVM.wordOfInt (tickSpacingSint24Value (UInt256.land w slot0Uint24Mask)) = - UInt256.signextend ⟨2⟩ w := by - rw [slot0Sint24Value_mask] - exact wordOfInt_sint24Value_eq_signextend_two w - -theorem slot0SignextendTwo_idempotent (w : UInt256) : - UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ w) = - UInt256.signextend ⟨2⟩ w := by - let i := tickSpacingSint24Value w - have hword : EVM.wordOfInt i = UInt256.signextend ⟨2⟩ w := by - simpa [i] using wordOfInt_sint24Value_eq_signextend_two w - rw [← hword] - exact signextend_two_wordOfInt_tickSpacing i (slot0Sint24Value_ge w) - (slot0Sint24Value_lt w) - -theorem slot0BoolABIEncoding (w : UInt256) : - encodeABIValue? boolTy (wordToElem .bool w) = - some (EVM.Word.toBytesBE (slot0BoolReturnWord w)) := by - by_cases hval : w.val = 0 - · have hz : w = ⟨0⟩ := by - apply u256_inj - exact congrArg Fin.val hval - simp [boolTy, wordToElem, hz, slot0BoolReturnWord, encodeABIValue?, encodeABIWord?, - Bool.toUInt256_false] - native_decide - · have hz : w ≠ ⟨0⟩ := by - intro hx - apply hval - rw [hx] - have hiz : UInt256.isZero w = ⟨0⟩ := isZero_eq_zero_of_ne hz - simp [boolTy, wordToElem, hval, slot0BoolReturnWord, hiz, encodeABIValue?, encodeABIWord?, - Bool.toUInt256_true] - native_decide - -theorem slot0ReturnEncoding (σ : AccountMap) (I : ExecutionEnv) : - encodeReturnValues? [uint160, int24, uint16, uint16, uint16, uint8, boolTy] - (slot0ReturnValues σ I) = - some (UInt256.toByteArray (slot0SqrtPriceX96Word σ I) ++ - UInt256.toByteArray (slot0TickReturnWord σ I) ++ - UInt256.toByteArray (slot0ObservationIndexWord σ I) ++ - UInt256.toByteArray (slot0ObservationCardinalityWord σ I) ++ - UInt256.toByteArray (slot0ObservationCardinalityNextWord σ I) ++ - UInt256.toByteArray (slot0FeeProtocolWord σ I) ++ - UInt256.toByteArray (slot0BoolReturnWord (slot0UnlockedRawWord σ I))) := by - have hwordSqrt : EVM.word (slot0SqrtPriceX96Word σ I).toNat = - slot0SqrtPriceX96Word σ I := u256_ofNat_toNat _ - have hwordObsIndex : EVM.word (slot0ObservationIndexWord σ I).toNat = - slot0ObservationIndexWord σ I := u256_ofNat_toNat _ - have hwordObsCardinality : EVM.word (slot0ObservationCardinalityWord σ I).toNat = - slot0ObservationCardinalityWord σ I := u256_ofNat_toNat _ - have hwordObsCardinalityNext : - EVM.word (slot0ObservationCardinalityNextWord σ I).toNat = - slot0ObservationCardinalityNextWord σ I := u256_ofNat_toNat _ - have hwordFee : EVM.word (slot0FeeProtocolWord σ I).toNat = - slot0FeeProtocolWord σ I := u256_ofNat_toNat _ - have hsqrtLt : (slot0SqrtPriceX96Word σ I).toNat < EVM.twoPow 160 := by - simpa [slot0SqrtPriceX96Word] using slot0Uint160Mask_bound (slot0SlotWord σ I) - have hobsIndexLt : (slot0ObservationIndexWord σ I).toNat < EVM.twoPow 16 := by - simpa [slot0ObservationIndexWord] using - slot0Uint16Mask_bound (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 23)) - have hobsCardinalityLt : (slot0ObservationCardinalityWord σ I).toNat < - EVM.twoPow 16 := by - simpa [slot0ObservationCardinalityWord] using - slot0Uint16Mask_bound (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 25)) - have hobsCardinalityNextLt : (slot0ObservationCardinalityNextWord σ I).toNat < - EVM.twoPow 16 := by - simpa [slot0ObservationCardinalityNextWord] using - slot0Uint16Mask_bound (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 27)) - have hfeeLt : (slot0FeeProtocolWord σ I).toNat < EVM.twoPow 8 := by - simpa [slot0FeeProtocolWord] using - slot0Uint8Mask_bound (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 29)) - have hencSqrt : - encodeABIValue? uint160 (.int (Int.ofNat (slot0SqrtPriceX96Word σ I).toNat)) = - some (EVM.Word.toBytesBE (slot0SqrtPriceX96Word σ I)) := by - simp [uint160, uint160Int, encodeABIValue?, encodeABIWord?, hwordSqrt, hsqrtLt] - have hencTick : - encodeABIValue? int24 (wordToElem (.int int24Int) (slot0TickRawWord σ I)) = - some (EVM.Word.toBytesBE (slot0TickReturnWord σ I)) := by - change encodeABIValue? int24 - (.int (tickSpacingSint24Value (slot0TickRawWord σ I))) = - some (EVM.Word.toBytesBE (slot0TickReturnWord σ I)) - have hge := slot0Sint24Value_ge (slot0TickRawWord σ I) - have hlt := slot0Sint24Value_lt (slot0TickRawWord σ I) - have hword : EVM.wordOfInt (tickSpacingSint24Value (slot0TickRawWord σ I)) = - slot0TickReturnWord σ I := by - dsimp [slot0TickRawWord, slot0TickReturnWord] - exact slot0TickRawValue_wordOfInt - (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 20)) - simp only [int24, int24Int, encodeABIValue?, encodeABIWord?] - rw [if_neg (by decide : 24 ≠ 0), if_pos] - · rw [hword] - rfl - · constructor - · simpa [EVM.twoPow] using hge - · simpa [EVM.twoPow] using hlt - have hencObsIndex : - encodeABIValue? uint16 - (.int (Int.ofNat (slot0ObservationIndexWord σ I).toNat)) = - some (EVM.Word.toBytesBE (slot0ObservationIndexWord σ I)) := by - simp [uint16, uint16Int, encodeABIValue?, encodeABIWord?, hwordObsIndex, - hobsIndexLt] - have hencObsCardinality : - encodeABIValue? uint16 - (.int (Int.ofNat (slot0ObservationCardinalityWord σ I).toNat)) = - some (EVM.Word.toBytesBE (slot0ObservationCardinalityWord σ I)) := by - simp [uint16, uint16Int, encodeABIValue?, encodeABIWord?, hwordObsCardinality, - hobsCardinalityLt] - have hencObsCardinalityNext : - encodeABIValue? uint16 - (.int (Int.ofNat (slot0ObservationCardinalityNextWord σ I).toNat)) = - some (EVM.Word.toBytesBE (slot0ObservationCardinalityNextWord σ I)) := by - simp [uint16, uint16Int, encodeABIValue?, encodeABIWord?, hwordObsCardinalityNext, - hobsCardinalityNextLt] - have hencFee : - encodeABIValue? uint8 (.int (Int.ofNat (slot0FeeProtocolWord σ I).toNat)) = - some (EVM.Word.toBytesBE (slot0FeeProtocolWord σ I)) := by - simp [uint8, uint8Int, encodeABIValue?, encodeABIWord?, hwordFee, hfeeLt] - have hencUnlocked : - encodeABIValue? boolTy (wordToElem .bool (slot0UnlockedRawWord σ I)) = - some (EVM.Word.toBytesBE (slot0BoolReturnWord (slot0UnlockedRawWord σ I))) := - slot0BoolABIEncoding (slot0UnlockedRawWord σ I) - have hhead : - abiTupleHeadSize? [uint160, int24, uint16, uint16, uint16, uint8, boolTy] = - some 224 := by native_decide - have hdyn160 : isDynamicABIType uint160 = false := by native_decide - have hdyn24 : isDynamicABIType int24 = false := by native_decide - have hdyn16 : isDynamicABIType uint16 = false := by native_decide - have hdyn8 : isDynamicABIType uint8 = false := by native_decide - have hdynBool : isDynamicABIType boolTy = false := by native_decide - rw [toByteArray_eq_toBytesBE (slot0SqrtPriceX96Word σ I), - toByteArray_eq_toBytesBE (slot0TickReturnWord σ I), - toByteArray_eq_toBytesBE (slot0ObservationIndexWord σ I), - toByteArray_eq_toBytesBE (slot0ObservationCardinalityWord σ I), - toByteArray_eq_toBytesBE (slot0ObservationCardinalityNextWord σ I), - toByteArray_eq_toBytesBE (slot0FeeProtocolWord σ I), - toByteArray_eq_toBytesBE (slot0BoolReturnWord (slot0UnlockedRawWord σ I))] - simp only [slot0ReturnValues, encodeReturnValues?, encodeABIValues?, - encodeABIValuesFrom?, hhead, hencSqrt, hencTick, hencObsIndex, - hencObsCardinality, hencObsCardinalityNext, hencFee, hencUnlocked, - hdyn160, hdyn24, hdyn16, hdyn8, hdynBool, bind, Option.bind, - Bool.false_eq_true, if_false, List.nil_append, List.append_nil] - apply congrArg some - apply ByteArray.ext - apply Array.toList_inj.mp - simp - -noncomputable def slot0ReturnMem1 (sqrt : UInt256) : ByteArray := - writeCascade solcFreePtrMem [(128, sqrt)] - -noncomputable def slot0ReturnMem2 (sqrt tick : UInt256) : ByteArray := - writeCascade solcFreePtrMem [(128, sqrt), (160, tick)] - -noncomputable def slot0ReturnMem3 (sqrt tick obsIndex : UInt256) : ByteArray := - writeCascade solcFreePtrMem [(128, sqrt), (160, tick), (192, obsIndex)] - -noncomputable def slot0ReturnMem4 (sqrt tick obsIndex obsCardinality : UInt256) : - ByteArray := - writeCascade solcFreePtrMem - [(128, sqrt), (160, tick), (192, obsIndex), (224, obsCardinality)] - -noncomputable def slot0ReturnMem5 - (sqrt tick obsIndex obsCardinality obsCardinalityNext : UInt256) : ByteArray := - writeCascade solcFreePtrMem - [(128, sqrt), (160, tick), (192, obsIndex), (224, obsCardinality), - (256, obsCardinalityNext)] - -noncomputable def slot0ReturnMem6 - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol : UInt256) : - ByteArray := - writeCascade solcFreePtrMem - [(128, sqrt), (160, tick), (192, obsIndex), (224, obsCardinality), - (256, obsCardinalityNext), (288, feeProtocol)] - -noncomputable def slot0ReturnMem - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked : UInt256) : - ByteArray := - writeCascade solcFreePtrMem - [(128, sqrt), (160, tick), (192, obsIndex), (224, obsCardinality), - (256, obsCardinalityNext), (288, feeProtocol), (320, unlocked)] - -theorem slot0ReturnMem1_eq (sqrt : UInt256) : - slot0ReturnMem1 sqrt = writeWord solcFreePtrMem 128 sqrt := by - rfl - -theorem slot0ReturnMem2_eq (sqrt tick : UInt256) : - slot0ReturnMem2 sqrt tick = writeWord (slot0ReturnMem1 sqrt) 160 tick := by - rfl - -theorem slot0ReturnMem3_eq (sqrt tick obsIndex : UInt256) : - slot0ReturnMem3 sqrt tick obsIndex = - writeWord (slot0ReturnMem2 sqrt tick) 192 obsIndex := by - rfl - -theorem slot0ReturnMem4_eq (sqrt tick obsIndex obsCardinality : UInt256) : - slot0ReturnMem4 sqrt tick obsIndex obsCardinality = - writeWord (slot0ReturnMem3 sqrt tick obsIndex) 224 obsCardinality := by - rfl - -theorem slot0ReturnMem5_eq - (sqrt tick obsIndex obsCardinality obsCardinalityNext : UInt256) : - slot0ReturnMem5 sqrt tick obsIndex obsCardinality obsCardinalityNext = - writeWord (slot0ReturnMem4 sqrt tick obsIndex obsCardinality) 256 - obsCardinalityNext := by - rfl - -theorem slot0ReturnMem6_eq - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol : UInt256) : - slot0ReturnMem6 sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol = - writeWord (slot0ReturnMem5 sqrt tick obsIndex obsCardinality obsCardinalityNext) 288 - feeProtocol := by - rfl - -theorem slot0ReturnMem_eq - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked : UInt256) : - slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked = - writeWord (slot0ReturnMem6 sqrt tick obsIndex obsCardinality obsCardinalityNext - feeProtocol) 320 unlocked := by - rfl - -theorem slot0ReturnMem1_size (sqrt : UInt256) : - (slot0ReturnMem1 sqrt).size = 160 := by - unfold slot0ReturnMem1 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem slot0ReturnMem2_size (sqrt tick : UInt256) : - (slot0ReturnMem2 sqrt tick).size = 192 := by - unfold slot0ReturnMem2 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem slot0ReturnMem3_size (sqrt tick obsIndex : UInt256) : - (slot0ReturnMem3 sqrt tick obsIndex).size = 224 := by - unfold slot0ReturnMem3 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem slot0ReturnMem4_size (sqrt tick obsIndex obsCardinality : UInt256) : - (slot0ReturnMem4 sqrt tick obsIndex obsCardinality).size = 256 := by - unfold slot0ReturnMem4 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem slot0ReturnMem5_size - (sqrt tick obsIndex obsCardinality obsCardinalityNext : UInt256) : - (slot0ReturnMem5 sqrt tick obsIndex obsCardinality obsCardinalityNext).size = 288 := by - unfold slot0ReturnMem5 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem slot0ReturnMem6_size - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol : UInt256) : - (slot0ReturnMem6 sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol).size = - 320 := by - unfold slot0ReturnMem6 - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem slot0ReturnMem_size - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked : UInt256) : - (slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked).size = - 352 := by - unfold slot0ReturnMem - exact writeCascade_size_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem slot0ReturnMem_read64 - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked : UInt256) : - (slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by - unfold slot0ReturnMem - rw [writeCascade_read_preserved_of_base solcFreePtrMem _ solcFreePtrMem_size - (by - norm_num [WindowDisjointFromWrites] - all_goals native_decide)] - exact solcFreePtrMem_read64 - -theorem slot0ReturnMem_mload64 - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked : UInt256) : - (if (⟨64⟩ : UInt256).toNat ≥ - (slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 11 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked).readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - ⟨128⟩ := - mloadFreePtrValue (by rw [slot0ReturnMem_size]; decide) (by decide) - (slot0ReturnMem_read64 sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked) - -theorem slot0ReturnMem_read128 - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked : UInt256) : - (slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked).readWithPadding 128 32 = UInt256.toByteArray sqrt := by - unfold slot0ReturnMem - exact writeCascade_read_word_of_head_of_base solcFreePtrMem (base := 96) (off := 128) - sqrt [(160, tick), (192, obsIndex), (224, obsCardinality), (256, obsCardinalityNext), - (288, feeProtocol), (320, unlocked)] - solcFreePtrMem_size (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem slot0ReturnMem_read160 - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked : UInt256) : - (slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked).readWithPadding 160 32 = UInt256.toByteArray tick := by - unfold slot0ReturnMem - change (writeCascade (slot0ReturnMem1 sqrt) - [(160, tick), (192, obsIndex), (224, obsCardinality), (256, obsCardinalityNext), - (288, feeProtocol), (320, unlocked)]).readWithPadding 160 32 = - UInt256.toByteArray tick - exact writeCascade_read_word_of_head_of_base (slot0ReturnMem1 sqrt) (base := 160) - (off := 160) tick - [(192, obsIndex), (224, obsCardinality), (256, obsCardinalityNext), (288, feeProtocol), - (320, unlocked)] - (slot0ReturnMem1_size sqrt) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem slot0ReturnMem_read192 - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked : UInt256) : - (slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked).readWithPadding 192 32 = UInt256.toByteArray obsIndex := by - unfold slot0ReturnMem - change (writeCascade (slot0ReturnMem2 sqrt tick) - [(192, obsIndex), (224, obsCardinality), (256, obsCardinalityNext), - (288, feeProtocol), (320, unlocked)]).readWithPadding 192 32 = - UInt256.toByteArray obsIndex - exact writeCascade_read_word_of_head_of_base (slot0ReturnMem2 sqrt tick) (base := 192) - (off := 192) obsIndex - [(224, obsCardinality), (256, obsCardinalityNext), (288, feeProtocol), (320, unlocked)] - (slot0ReturnMem2_size sqrt tick) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem slot0ReturnMem_read224 - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked : UInt256) : - (slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked).readWithPadding 224 32 = UInt256.toByteArray obsCardinality := by - unfold slot0ReturnMem - change (writeCascade (slot0ReturnMem3 sqrt tick obsIndex) - [(224, obsCardinality), (256, obsCardinalityNext), (288, feeProtocol), - (320, unlocked)]).readWithPadding 224 32 = - UInt256.toByteArray obsCardinality - exact writeCascade_read_word_of_head_of_base (slot0ReturnMem3 sqrt tick obsIndex) - (base := 224) (off := 224) obsCardinality - [(256, obsCardinalityNext), (288, feeProtocol), (320, unlocked)] - (slot0ReturnMem3_size sqrt tick obsIndex) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem slot0ReturnMem_read256 - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked : UInt256) : - (slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked).readWithPadding 256 32 = UInt256.toByteArray obsCardinalityNext := by - unfold slot0ReturnMem - change (writeCascade (slot0ReturnMem4 sqrt tick obsIndex obsCardinality) - [(256, obsCardinalityNext), (288, feeProtocol), (320, unlocked)]).readWithPadding - 256 32 = - UInt256.toByteArray obsCardinalityNext - exact writeCascade_read_word_of_head_of_base - (slot0ReturnMem4 sqrt tick obsIndex obsCardinality) (base := 256) (off := 256) - obsCardinalityNext [(288, feeProtocol), (320, unlocked)] - (slot0ReturnMem4_size sqrt tick obsIndex obsCardinality) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem slot0ReturnMem_read288 - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked : UInt256) : - (slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked).readWithPadding 288 32 = UInt256.toByteArray feeProtocol := by - unfold slot0ReturnMem - change (writeCascade - (slot0ReturnMem5 sqrt tick obsIndex obsCardinality obsCardinalityNext) - [(288, feeProtocol), (320, unlocked)]).readWithPadding 288 32 = - UInt256.toByteArray feeProtocol - exact writeCascade_read_word_of_head_of_base - (slot0ReturnMem5 sqrt tick obsIndex obsCardinality obsCardinalityNext) (base := 288) - (off := 288) feeProtocol [(320, unlocked)] - (slot0ReturnMem5_size sqrt tick obsIndex obsCardinality obsCardinalityNext) - (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem slot0ReturnMem_read320 - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked : UInt256) : - (slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked).readWithPadding 320 32 = UInt256.toByteArray unlocked := by - unfold slot0ReturnMem - change (writeCascade - (slot0ReturnMem6 sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol) - [(320, unlocked)]).readWithPadding 320 32 = - UInt256.toByteArray unlocked - exact writeCascade_read_word_of_head_of_base - (slot0ReturnMem6 sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol) - (base := 320) (off := 320) unlocked [] - (slot0ReturnMem6_size sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol) - (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem slot0ReturnMem_read128_224 - (sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol unlocked : UInt256) : - (slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked).readWithPadding 128 224 = - UInt256.toByteArray sqrt ++ UInt256.toByteArray tick ++ UInt256.toByteArray obsIndex ++ - UInt256.toByteArray obsCardinality ++ UInt256.toByteArray obsCardinalityNext ++ - UInt256.toByteArray feeProtocol ++ UInt256.toByteArray unlocked := by - let mem := slot0ReturnMem sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked - have hsize : mem.size = 352 := by - simpa [mem] using - slot0ReturnMem_size sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked - have h128 : mem.readWithPadding 128 32 = UInt256.toByteArray sqrt := by - simpa [mem] using - slot0ReturnMem_read128 sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked - have h160 : mem.readWithPadding 160 32 = UInt256.toByteArray tick := by - simpa [mem] using - slot0ReturnMem_read160 sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked - have h192 : mem.readWithPadding 192 32 = UInt256.toByteArray obsIndex := by - simpa [mem] using - slot0ReturnMem_read192 sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked - have h224 : mem.readWithPadding 224 32 = UInt256.toByteArray obsCardinality := by - simpa [mem] using - slot0ReturnMem_read224 sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked - have h256 : mem.readWithPadding 256 32 = UInt256.toByteArray obsCardinalityNext := by - simpa [mem] using - slot0ReturnMem_read256 sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked - have h288 : mem.readWithPadding 288 32 = UInt256.toByteArray feeProtocol := by - simpa [mem] using - slot0ReturnMem_read288 sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked - have h320 : mem.readWithPadding 320 32 = UInt256.toByteArray unlocked := by - simpa [mem] using - slot0ReturnMem_read320 sqrt tick obsIndex obsCardinality obsCardinalityNext feeProtocol - unlocked - change mem.readWithPadding 128 224 = _ - rw [byteArray_readWithPadding_split mem 128 32 192 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h128] - rw [byteArray_readWithPadding_split mem 160 32 160 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h160] - rw [byteArray_readWithPadding_split mem 192 32 128 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h192] - rw [byteArray_readWithPadding_split mem 224 32 96 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h224] - rw [byteArray_readWithPadding_split mem 256 32 64 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h256] - rw [byteArray_readWithPadding_split mem 288 32 32 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h288, h320] - simp only [ByteArray.append_assoc] - -theorem storageLocLoad_sint_offset (evm : EVM.State) (slot : UInt256) - (offset : Fin 32) (size : Fin 33) (width : ABI.BitWidth) - {hbound : offset.val + size.val - 1 < 32} - (hoff : 8 * offset.val < 256) (hsize : 8 * size.val ≤ 256) : - storageLocLoad evm - { slot := slot, offset := offset, size := size, hbound := hbound, - type := .int (.sint width) } = - wordToElem (.int (.sint width)) - (UInt256.land - (UInt256.div (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) - (UInt256.ofNat (256 ^ offset.val))) - (UInt256.ofNat (256 ^ size.val - 1))) := by - unfold storageLocLoad - change wordToElem (.int (.sint width)) - ⟨fromBytes' - (((EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).1).extract - offset.val (offset.val + size.val)), _⟩ = _ - congr - rw [List.extract_eq_take_drop] - simpa [Nat.add_sub_cancel_left] using - fromBytes'_drop_take_wordLE_land_div_mask - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) offset.val size.val hoff hsize - -theorem storageLocLoad_bool_offset (evm : EVM.State) (slot : UInt256) - (offset : Fin 32) {hbound : offset.val + (1 : Fin 33).val - 1 < 32} - (hoff : 8 * offset.val < 256) : - storageLocLoad evm - { slot := slot, offset := offset, size := (1 : Fin 33), hbound := hbound, - type := .bool } = - wordToElem .bool - (UInt256.land - (UInt256.div (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) - (UInt256.ofNat (256 ^ offset.val))) - slot0Uint8Mask) := by - unfold storageLocLoad - change wordToElem .bool - ⟨fromBytes' - (((EVM.Word.toBytesLEWithSizeProof - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot)).1).extract - offset.val (offset.val + 1)), _⟩ = _ - congr - rw [List.extract_eq_take_drop] - rw [← show UInt256.ofNat (256 ^ (1 : Nat) - 1) = slot0Uint8Mask by native_decide] - simpa [Nat.add_sub_cancel_left] using - fromBytes'_drop_take_wordLE_land_div_mask - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner slot) offset.val 1 hoff - (by decide) - -theorem slot0StorageLocLoad_sqrtPriceX96 (evm : EVM.State) : - storageLocLoad evm - (loc ⟨0⟩ ⟨0, by decide⟩ ⟨20, by decide⟩ (by decide) (.int uint160Int)) = - .int (Int.ofNat (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) slot0Uint160Mask).toNat) := by - rw [← show UInt256.ofNat (2 ^ (8 * 20) - 1) = slot0Uint160Mask by native_decide] - simpa [loc, uint160Int] using - storageLocLoad_uint_offset0 evm ⟨0⟩ (20 : Fin 33) ⟨160, by decide⟩ - (hbound := by decide) (by decide) - -theorem slot0StorageLocLoad_tick (evm : EVM.State) : - storageLocLoad evm - (loc ⟨0⟩ ⟨20, by decide⟩ ⟨3, by decide⟩ (by decide) (.int int24Int)) = - wordToElem (.int int24Int) - (UInt256.land - (UInt256.div (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - (slot0ShiftBytes 20)) - slot0Uint24Mask) := by - rw [← show UInt256.ofNat (256 ^ (20 : Nat)) = slot0ShiftBytes 20 by rfl] - rw [← show UInt256.ofNat (256 ^ (3 : Nat) - 1) = slot0Uint24Mask by native_decide] - simpa [loc, int24Int] using - storageLocLoad_sint_offset evm ⟨0⟩ (20 : Fin 32) (3 : Fin 33) ⟨24, by decide⟩ - (hbound := by decide) (by decide) (by decide) - -theorem slot0StorageLocLoad_observationIndex (evm : EVM.State) : - storageLocLoad evm - (loc ⟨0⟩ ⟨23, by decide⟩ ⟨2, by decide⟩ (by decide) (.int uint16Int)) = - .int (Int.ofNat (UInt256.land - (UInt256.div (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - (slot0ShiftBytes 23)) slot0Uint16Mask).toNat) := by - rw [← show UInt256.ofNat (256 ^ (23 : Nat)) = slot0ShiftBytes 23 by rfl] - rw [← show UInt256.ofNat (256 ^ (2 : Nat) - 1) = slot0Uint16Mask by native_decide] - simpa [loc, uint16Int] using - storageLocLoad_uint_offset evm ⟨0⟩ (23 : Fin 32) (2 : Fin 33) ⟨16, by decide⟩ - (hbound := by decide) (by decide) (by decide) - -theorem slot0StorageLocLoad_observationCardinality (evm : EVM.State) : - storageLocLoad evm - (loc ⟨0⟩ ⟨25, by decide⟩ ⟨2, by decide⟩ (by decide) (.int uint16Int)) = - .int (Int.ofNat (UInt256.land - (UInt256.div (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - (slot0ShiftBytes 25)) slot0Uint16Mask).toNat) := by - rw [← show UInt256.ofNat (256 ^ (25 : Nat)) = slot0ShiftBytes 25 by rfl] - rw [← show UInt256.ofNat (256 ^ (2 : Nat) - 1) = slot0Uint16Mask by native_decide] - simpa [loc, uint16Int] using - storageLocLoad_uint_offset evm ⟨0⟩ (25 : Fin 32) (2 : Fin 33) ⟨16, by decide⟩ - (hbound := by decide) (by decide) (by decide) - -theorem slot0StorageLocLoad_observationCardinalityNext (evm : EVM.State) : - storageLocLoad evm - (loc ⟨0⟩ ⟨27, by decide⟩ ⟨2, by decide⟩ (by decide) (.int uint16Int)) = - .int (Int.ofNat (UInt256.land - (UInt256.div (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - (slot0ShiftBytes 27)) slot0Uint16Mask).toNat) := by - rw [← show UInt256.ofNat (256 ^ (27 : Nat)) = slot0ShiftBytes 27 by rfl] - rw [← show UInt256.ofNat (256 ^ (2 : Nat) - 1) = slot0Uint16Mask by native_decide] - simpa [loc, uint16Int] using - storageLocLoad_uint_offset evm ⟨0⟩ (27 : Fin 32) (2 : Fin 33) ⟨16, by decide⟩ - (hbound := by decide) (by decide) (by decide) - -theorem slot0StorageLocLoad_feeProtocol (evm : EVM.State) : - storageLocLoad evm - (loc ⟨0⟩ ⟨29, by decide⟩ ⟨1, by decide⟩ (by decide) (.int uint8Int)) = - .int (Int.ofNat (UInt256.land - (UInt256.div (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - (slot0ShiftBytes 29)) slot0Uint8Mask).toNat) := by - rw [← show UInt256.ofNat (256 ^ (29 : Nat)) = slot0ShiftBytes 29 by rfl] - rw [← show UInt256.ofNat (256 ^ (1 : Nat) - 1) = slot0Uint8Mask by native_decide] - simpa [loc, uint8Int] using - storageLocLoad_uint_offset evm ⟨0⟩ (29 : Fin 32) (1 : Fin 33) ⟨8, by decide⟩ - (hbound := by decide) (by decide) (by decide) - -theorem slot0StorageLocLoad_unlocked (evm : EVM.State) : - storageLocLoad evm - (loc ⟨0⟩ ⟨30, by decide⟩ ⟨1, by decide⟩ (by decide) .bool) = - wordToElem .bool - (UInt256.land - (UInt256.div (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner ⟨0⟩) - (slot0ShiftBytes 30)) - slot0Uint8Mask) := by - rw [← show UInt256.ofNat (256 ^ (30 : Nat)) = slot0ShiftBytes 30 by rfl] - simpa [loc] using - storageLocLoad_bool_offset evm ⟨0⟩ (30 : Fin 32) (hbound := by decide) (by decide) - -theorem uniswapV3PoolSlot0ReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 6 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨859⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 6 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0x38 0x50 0xc7 0xbd - (uniswapV3PoolSelNat 6) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h239 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨239⟩) hpatch h32 hgt32 - have hgt239 : UInt256.gt (armSelNat code ⟨239⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h250 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨250⟩) hpatch h239 hgt239 - have hgt250 : UInt256.gt (armSelNat code ⟨250⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h310 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨310⟩) hpatch h250 hgt250 - have h859 := uniswapV3PoolSelectorArmHitTo (i := 6) (target := ⟨859⟩) - hpatch hsz hsel h310 - exact ⟨_, _, h859⟩ - -theorem uniswapV3PoolSlot0Decode {v : PoolImmutables} {I : ExecutionEnv} - (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - (slot0Transition.params.map Param.name) - (transitionSignature slot0Transition).paramTypes I.calldata = some (∅ : Store) := by - simpa [config, slot0Transition, transitionSignature] using - decodeCalldataWithMode_empty_ok (mode := DecodeMode.legacySolc05) (cd := I.calldata) hsz - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolDispatch_slot0 {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 6 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some slot0Transition := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, factoryTransition v, - feeTransition v, feegrowthglobal0X128Transition, feegrowthglobal1X128Transition, - flashTransition v, increaseobservationcardinalitynextTransition v, initializeTransition, - liquidityTransition, maxliquiditypertickTransition v, mintTransition v, observationsTransition, - observeTransition v, positionsTransition, protocolfeesTransition, setfeeprotocolTransition v]) - (post := [snapshotcumulativesinsideTransition v, swapTransition v, tickbitmapTransition, - tickspacingTransition v, ticksTransition, token0Transition v, token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 6) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 6) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 6) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 6) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 6) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 6) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 6) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 6) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 5) (j := 6) - (by native_decide) hsel - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 25) (j := 6) - (by native_decide) hsel - · rw [selectorOf, liquiditySelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 2) (j := 6) - (by native_decide) hsel - · rw [selectorOf, maxLiquidityPerTickSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 13) (j := 6) - (by native_decide) hsel - · rw [selectorOf, mintSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 7) (j := 6) - (by native_decide) hsel - · rw [selectorOf, observationsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 4) (j := 6) - (by native_decide) hsel - · rw [selectorOf, observeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 16) (j := 6) - (by native_decide) hsel - · rw [selectorOf, positionsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 11) (j := 6) - (by native_decide) hsel - · rw [selectorOf, protocolFeesSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 3) (j := 6) - (by native_decide) hsel - · rw [selectorOf, setFeeProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 14) (j := 6) - (by native_decide) hsel - · rw [selectorOf, slot0SelectorBytes] - simpa [uniswapV3PoolSelBytes] using hsel - -theorem uniswapV3PoolSlot0SourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) slot0Transition.body - (.returned { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) (some (slot0ReturnValues σ I))) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [(.storage (slot0F "sqrtPriceX96")), (.storage (slot0F "tick")), - (.storage (slot0F "observationIndex")), - (.storage (slot0F "observationCardinality")), - (.storage (slot0F "observationCardinalityNext")), (.storage (slot0F "feeProtocol")), - (.storage (slot0F "unlocked"))] ] _ - exact ExecFuncBody.execBlockRet <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true (by simp [initState, hwv]))) <| - ExecBlock.consReturn <| ExecStmt.return (by - have hret0 : - evalExpr? (config v) { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "sqrtPriceX96")) = - .ok (.int (Int.ofNat (slot0SqrtPriceX96Word σ I).toNat)) := by - rw [evalExpr_storage_scalar - (t := .int uint160Int) - (slot := slot0F "sqrtPriceX96") - (er := { base := "slot0", steps := [.field "sqrtPriceX96"] }) - (loc := loc ⟨0⟩ ⟨0, by decide⟩ ⟨20, by decide⟩ (by decide) - (.int uint160Int)) - (hbase := by simp [slot0F]) - (her := by - simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - uint160St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [initState, slot0SqrtPriceX96Word, slot0SlotWord, solcSlotWord] using - slot0StorageLocLoad_sqrtPriceX96 (initState cA gh bl σ σ₀ g A I) - have hret1 : - evalExpr? (config v) { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "tick")) = - .ok (wordToElem (.int int24Int) (slot0TickRawWord σ I)) := by - rw [evalExpr_storage_scalar - (t := .int int24Int) - (slot := slot0F "tick") - (er := { base := "slot0", steps := [.field "tick"] }) - (loc := loc ⟨0⟩ ⟨20, by decide⟩ ⟨3, by decide⟩ (by decide) (.int int24Int)) - (hbase := by simp [slot0F]) - (her := by - simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - int24St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [initState, slot0TickRawWord, slot0SlotWord, solcSlotWord] using - slot0StorageLocLoad_tick (initState cA gh bl σ σ₀ g A I) - have hret2 : - evalExpr? (config v) { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "observationIndex")) = - .ok (.int (Int.ofNat (slot0ObservationIndexWord σ I).toNat)) := by - rw [evalExpr_storage_scalar - (t := .int uint16Int) - (slot := slot0F "observationIndex") - (er := { base := "slot0", steps := [.field "observationIndex"] }) - (loc := loc ⟨0⟩ ⟨23, by decide⟩ ⟨2, by decide⟩ (by decide) - (.int uint16Int)) - (hbase := by simp [slot0F]) - (her := by - simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - uint16St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [initState, slot0ObservationIndexWord, slot0SlotWord, solcSlotWord] using - slot0StorageLocLoad_observationIndex (initState cA gh bl σ σ₀ g A I) - have hret3 : - evalExpr? (config v) { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "observationCardinality")) = - .ok (.int (Int.ofNat (slot0ObservationCardinalityWord σ I).toNat)) := by - rw [evalExpr_storage_scalar - (t := .int uint16Int) - (slot := slot0F "observationCardinality") - (er := { base := "slot0", steps := [.field "observationCardinality"] }) - (loc := loc ⟨0⟩ ⟨25, by decide⟩ ⟨2, by decide⟩ (by decide) - (.int uint16Int)) - (hbase := by simp [slot0F]) - (her := by - simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - uint16St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [initState, slot0ObservationCardinalityWord, slot0SlotWord, solcSlotWord] using - slot0StorageLocLoad_observationCardinality (initState cA gh bl σ σ₀ g A I) - have hret4 : - evalExpr? (config v) { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) - (.storage (slot0F "observationCardinalityNext")) = - .ok (.int (Int.ofNat (slot0ObservationCardinalityNextWord σ I).toNat)) := by - rw [evalExpr_storage_scalar - (t := .int uint16Int) - (slot := slot0F "observationCardinalityNext") - (er := { base := "slot0", steps := [.field "observationCardinalityNext"] }) - (loc := loc ⟨0⟩ ⟨27, by decide⟩ ⟨2, by decide⟩ (by decide) - (.int uint16Int)) - (hbase := by simp [slot0F]) - (her := by - simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - uint16St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [initState, slot0ObservationCardinalityNextWord, slot0SlotWord, solcSlotWord] using - slot0StorageLocLoad_observationCardinalityNext (initState cA gh bl σ σ₀ g A I) - have hret5 : - evalExpr? (config v) { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "feeProtocol")) = - .ok (.int (Int.ofNat (slot0FeeProtocolWord σ I).toNat)) := by - rw [evalExpr_storage_scalar - (t := .int uint8Int) - (slot := slot0F "feeProtocol") - (er := { base := "slot0", steps := [.field "feeProtocol"] }) - (loc := loc ⟨0⟩ ⟨29, by decide⟩ ⟨1, by decide⟩ (by decide) (.int uint8Int)) - (hbase := by simp [slot0F]) - (her := by - simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - uint8St]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [initState, slot0FeeProtocolWord, slot0SlotWord, solcSlotWord] using - slot0StorageLocLoad_feeProtocol (initState cA gh bl σ σ₀ g A I) - have hret6 : - evalExpr? (config v) { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) (.storage (slot0F "unlocked")) = - .ok (wordToElem .bool (slot0UnlockedRawWord σ I)) := by - rw [evalExpr_storage_scalar - (t := .bool) - (slot := slot0F "unlocked") - (er := { base := "slot0", steps := [.field "unlocked"] }) - (loc := loc ⟨0⟩ ⟨30, by decide⟩ ⟨1, by decide⟩ (by decide) .bool) - (hbase := by simp [slot0F]) - (her := by - simp [evalStorageRef, evalStorageRefStep, slot0F, EvalResult.bind, pure, bind]) - (hty := by - simp [contract, storageDecls, storageTypeAt?, storageTypeStep?, slot0StructTy, - boolSt]) - (hloc := by - funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, loc])] - simpa [initState, slot0UnlockedRawWord, slot0SlotWord, solcSlotWord] using - slot0StorageLocLoad_unlocked (initState cA gh bl σ σ₀ g A I) - simp only [Solm.evalExprs?.eq_def, hret0, hret1, hret2, hret3, hret4, hret5, - hret6, EvalResult.bind, bind, pure, slot0ReturnValues]) - -theorem uniswapV3PoolSlot0ValueTransport {σ_evm σ_solm : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - some (slot0ReturnValues σ_solm I) = some (slot0ReturnValues σ_evm I) := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner ⟨0⟩ (⟨0⟩ : UInt256) - dsimp [slot0ReturnValues, slot0SqrtPriceX96Word, slot0TickRawWord, - slot0ObservationIndexWord, slot0ObservationCardinalityWord, - slot0ObservationCardinalityNextWord, slot0FeeProtocolWord, slot0UnlockedRawWord, - slot0SlotWord, solcSlotWord] - rw [← hslot] - -private theorem uniswapV3PoolSlot0PatchDisjoint {v : PoolImmutables} {pc : UInt256} - (hlo : 5654 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 6603) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl <;> - omega - -private theorem uniswapV3PoolPatchPreservesJumpDest5654 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨5654⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched5654 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨5654⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest5654 - -theorem uniswapV3PoolSlot0EntryWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcGetterEntryWf code ⟨859⟩ ⟨867⟩ ⟨5654⟩ := by - dsimp [solcGetterEntryWf] - refine ⟨?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolSlot0ReturnJumpDest {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨867⟩ = true := - uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide) - -private def slot0StSignextend (s : State) (v : UInt256) (t : List UInt256) : State := - { s with - machineState.stack := v :: t, - machineState.gasAvailable := s.machineState.gasAvailable.subNat 5 - machineState.pc := s.machineState.pc + ⟨1⟩ - machineState.execLength := s.machineState.execLength + 1 } - -private theorem slot0SignextendXstep {code : ByteArray} {s : State} {pc a b : UInt256} - {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pc) - (hdec : decode code pc = some (.SIGNEXTEND, .none)) - (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : - Xstep (D_J code 0) s = - if s.machineState.gasAvailable.toNat < 5 then .error .OutOfGass - else .ok (slot0StSignextend s (UInt256.signextend a b) t, .none) := by - have hdecS : decode s.executionEnv.code s.machineState.pc = some (.SIGNEXTEND, .none) := by - rw [hcode, hpc] - exact hdec - have hstep := step_signextend s hdecS - have hnoOverflow : ¬ 1024 ≤ t.length := by omega - simpa [hcode, hstk, GasConstants.Glow, slot0StSignextend, hnoOverflow] using hstep - -private theorem slot0RDSignextend {code : ByteArray} {ee : ExecutionEnv} - {g : Sat256} {s0 : State} {pc : UInt256} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.SIGNEXTEND, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.signextend a b :: t) mem aw rdata acc - (k + 1) (C + 5) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, hee, - hworld⟩ - · exact Or.inl hoog - · have st := slot0SignextendXstep hcode hpc hdec hstk hov - by_cases gg : g.toNat < C + 5 - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨slot0StSignextend s (UInt256.signextend a b) t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, by omega, - by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [slot0StSignextend]; exact hcode - · simp only [slot0StSignextend]; rw [hpc] - · rfl - · simp only [slot0StSignextend]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [slot0StSignextend]; exact hmem - · simp only [slot0StSignextend]; exact haw - · simp only [slot0StSignextend]; exact hrdata - · simp only [slot0StSignextend]; exact hacc - · exact hee - · exact hworld - -private theorem slot0Swap9Xstep {s : State} {code : ByteArray} - {pcv a b c d e f gg hh ii jj : UInt256} {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pcv) - (hdec : decode code pcv = some (.SWAP9, .none)) - (hstk : s.machineState.stack = a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: t) - (hov : t.length + 10 ≤ 1024) : - Xstep (D_J code 0) s - = (if s.machineState.gasAvailable.toNat < 3 then .error .OutOfGass - else .ok (stSwap s (jj :: b :: c :: d :: e :: f :: gg :: hh :: ii :: a :: t), - .none)) := by - have hd : decode s.executionEnv.code s.machineState.pc = some (.SWAP9, .none) := by - rw [hcode, hpc] - exact hdec - rw [← hcode, step_swap9 s hd, hstk] - have hov' : - ¬ ((a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: t).length - 10 + 10 > - 1024) := by - simp only [List.length_cons] - omega - simp only [if_neg hov', GasConstants.Gverylow, stSwap] - -private theorem slot0RDSwap9 {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} - {s0 : State} {pc : UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b c d e f gg hh ii jj : UInt256} {t : List UInt256} - (rd : RD code ee g s0 pc (a :: b :: c :: d :: e :: f :: gg :: hh :: ii :: jj :: t) - mem aw rdata acc k C) - (hdec : decode code pc = some (.SWAP9, .none)) (hov : t.length + 10 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) - (jj :: b :: c :: d :: e :: f :: gg :: hh :: ii :: a :: t) - mem aw rdata acc (k + 1) (C + 3) := - rd.stepSwap (fun _ hc hp hs => slot0Swap9Xstep hc hp hdec hs hov) - -theorem uniswapV3PoolSlot0Routine {v : PoolImmutables} {code : ByteArray} - {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {ret : UInt256} - {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨5654⟩ (ret :: R) mem aw rdata (cA, σ) k C) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 12 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret - (slot0UnlockedRawWord σ ee :: slot0FeeProtocolWord σ ee :: - slot0ObservationCardinalityNextWord σ ee :: - slot0ObservationCardinalityWord σ ee :: slot0ObservationIndexWord σ ee :: - slot0TickReturnWord σ ee :: slot0SqrtPriceX96Word σ ee :: ret :: R) - mem aw rdata (cA, σ) k' C' := by - have rd5655 := h.jumpdest (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) - (by simp only [List.length_cons]; omega) - have rd5657 := rd5655.push1 ⟨0⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) - (by simp only [List.length_cons]; omega) - obtain ⟨_, _, rd5658⟩ := rd5657.sload (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) - (by simp only [List.length_cons]; omega) - have rd5678 := evm_run rd5658 with [ - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨160⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw shl (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw sub (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw dup2 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨160⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw shl (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw dup2 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw div (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨2⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov)] - have rd5679 := slot0RDSignextend rd5678 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) - (by simp only [List.length_cons]; omega) - have rd5733 := evm_run rd5679 with [ - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push2 ⟨65535⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨184⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw shl (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw dup3 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw div (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw dup2 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw swap2 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨200⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw shl (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw dup2 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw div (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw dup3 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw swap2 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨216⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw shl (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw dup3 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw div (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨255⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨232⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw shl (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw dup3 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw div (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw dup2 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw swap2 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw push1 ⟨240⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw shl (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw div (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov), - raw dup8 (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) (by evm_ov)] - have rdRet := rd5733.jump (by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolSlot0PatchDisjoint (by native_decide) (by native_decide))] - native_decide) - hret (by simp only [List.length_cons]; omega) - have hmask160 : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask := by - native_decide - have hmask16 : (⟨65535⟩ : UInt256) = slot0Uint16Mask := by - native_decide - have hmask8 : (⟨255⟩ : UInt256) = slot0Uint8Mask := by - native_decide - have hshift160 : UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩ = slot0ShiftBytes 20 := by - native_decide - have hshift184 : UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨184⟩ = slot0ShiftBytes 23 := by - native_decide - have hshift200 : UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨200⟩ = slot0ShiftBytes 25 := by - native_decide - have hshift216 : UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨216⟩ = slot0ShiftBytes 27 := by - native_decide - have hshift232 : UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨232⟩ = slot0ShiftBytes 29 := by - native_decide - have hshift240 : UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨240⟩ = slot0ShiftBytes 30 := by - native_decide - exact ⟨_, _, by - rw [hmask160, hmask16, hmask8, hshift160, hshift184, hshift200, hshift216, - hshift232, hshift240] at rdRet - dsimp [slot0UnlockedRawWord, slot0FeeProtocolWord, - slot0ObservationCardinalityNextWord, slot0ObservationCardinalityWord, - slot0ObservationIndexWord, slot0TickReturnWord, slot0SqrtPriceX96Word, slot0SlotWord, - solcSlotWord] at rdRet ⊢ - rw [u256_land_comm slot0Uint8Mask - (UInt256.div ((σ.find? ee.codeOwner).option ⟨0⟩ - (fun acc => acc.storage.findD ⟨0⟩ ⟨0⟩)) (slot0ShiftBytes 29)), - u256_land_comm slot0Uint16Mask - (UInt256.div ((σ.find? ee.codeOwner).option ⟨0⟩ - (fun acc => acc.storage.findD ⟨0⟩ ⟨0⟩)) (slot0ShiftBytes 25)), - u256_land_comm slot0Uint16Mask - (UInt256.div ((σ.find? ee.codeOwner).option ⟨0⟩ - (fun acc => acc.storage.findD ⟨0⟩ ⟨0⟩)) (slot0ShiftBytes 23))] at rdRet - simpa using rdRet⟩ - -theorem uniswapV3PoolSlot0EvmAtReturn {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 6 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨867⟩ - (slot0UnlockedRawWord σ I :: slot0FeeProtocolWord σ I :: - slot0ObservationCardinalityNextWord σ I :: - slot0ObservationCardinalityWord σ I :: slot0ObservationIndexWord σ I :: - slot0TickReturnWord σ I :: slot0SqrtPriceX96Word σ I :: ⟨867⟩ :: - [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - have hreach := uniswapV3PoolSlot0ReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - obtain ⟨_, _, rdRoutine⟩ := RD.solcGetterThunk hreach - (uniswapV3PoolSlot0EntryWf hpatch) - (uniswapV3PoolJumpDestPatched5654 hpatch) - exact uniswapV3PoolSlot0Routine hpatch rdRoutine - (uniswapV3PoolSlot0ReturnJumpDest hpatch) - (by simp only [List.length_singleton]; omega) - -theorem uniswapV3PoolSlot0Return {v : PoolImmutables} {code : ByteArray} - {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} - {unlocked feeProtocol obsCardinalityNext obsCardinality obsIndex tick sqrt : UInt256} - {R : List UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨867⟩ - (unlocked :: feeProtocol :: obsCardinalityNext :: obsCardinality :: obsIndex :: tick :: - sqrt :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata acc k C) - (hov : R.length + 16 ≤ 1024) : - RDret code g s0 acc - (UInt256.toByteArray (UInt256.land sqrt slot0Uint160Mask) ++ - UInt256.toByteArray (UInt256.signextend ⟨2⟩ tick) ++ - UInt256.toByteArray (UInt256.land slot0Uint16Mask obsIndex) ++ - UInt256.toByteArray (UInt256.land slot0Uint16Mask obsCardinality) ++ - UInt256.toByteArray (UInt256.land slot0Uint16Mask obsCardinalityNext) ++ - UInt256.toByteArray (UInt256.land feeProtocol slot0Uint8Mask) ++ - UInt256.toByteArray (slot0BoolReturnWord unlocked)) := by - let sqrt' := UInt256.land sqrt slot0Uint160Mask - let tick' := UInt256.signextend ⟨2⟩ tick - let obsIndex' := UInt256.land slot0Uint16Mask obsIndex - let obsCardinality' := UInt256.land slot0Uint16Mask obsCardinality - let obsCardinalityNext' := UInt256.land slot0Uint16Mask obsCardinalityNext - let feeProtocol' := UInt256.land feeProtocol slot0Uint8Mask - let unlocked' := slot0BoolReturnWord unlocked - have hmask160 : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask := by - native_decide - have hmask16 : (⟨65535⟩ : UInt256) = slot0Uint16Mask := by - native_decide - have hmask8 : (⟨255⟩ : UInt256) = slot0Uint8Mask := by - native_decide - have rd881 := evm_run h with [ - raw jumpdest (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨64⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost solcFreePtrMem_mload64 (by decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨160⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw shl (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov)] - have rd882 := slot0RDSwap9 rd881 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by omega) - have rd890 := evm_run rd882 with [ - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup9 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 6 (slot0ReturnMem1 sqrt') (UInt256.ofNat 5) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [sqrt'] - rw [hmask160, show (⟨128⟩ : UInt256).toNat = 128 from by decide, - slot0ReturnMem1_eq] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨2⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap7 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap7 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov)] - have rd891 := slot0RDSignextend rd890 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by simp only [List.length_cons]; omega) - have rd938 := evm_run rd891 with [ - raw push1 ⟨32⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup9 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 (slot0ReturnMem2 sqrt' tick') (UInt256.ofNat 6) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [tick'] - rw [show ((⟨128⟩ : UInt256) + ⟨32⟩).toNat = 160 from by decide, - slot0ReturnMem2_eq] - rfl) - (by decide) (by evm_ov), - raw push2 ⟨65535⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap5 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup6 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup8 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup8 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 (slot0ReturnMem3 sqrt' tick' obsIndex') (UInt256.ofNat 7) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [obsIndex'] - rw [hmask16, show ((⟨64⟩ : UInt256) + ⟨128⟩).toNat = 192 from by decide, - slot0ReturnMem3_eq] - rfl) - (by decide) (by evm_ov), - raw swap3 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup5 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨96⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup8 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 (slot0ReturnMem4 sqrt' tick' obsIndex' obsCardinality') - (UInt256.ofNat 8) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [obsCardinality'] - rw [hmask16, show ((⟨128⟩ : UInt256) + ⟨96⟩).toNat = 224 from by decide, - slot0ReturnMem4_eq] - rfl) - (by decide) (by evm_ov), - raw swap3 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨128⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup6 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 - (slot0ReturnMem5 sqrt' tick' obsIndex' obsCardinality' obsCardinalityNext') - (UInt256.ofNat 9) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [obsCardinalityNext'] - rw [hmask16, show ((⟨128⟩ : UInt256) + ⟨128⟩).toNat = 256 from by decide, - slot0ReturnMem5_eq] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨255⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap2 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨160⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup5 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 - (slot0ReturnMem6 sqrt' tick' obsIndex' obsCardinality' obsCardinalityNext' - feeProtocol') - (UInt256.ofNat 10) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [feeProtocol'] - rw [hmask8, show ((⟨128⟩ : UInt256) + ⟨160⟩).toNat = 288 from by decide, - slot0ReturnMem6_eq] - rfl) - (by decide) (by evm_ov), - raw iszero (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw iszero (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨192⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup4 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 - (slot0ReturnMem sqrt' tick' obsIndex' obsCardinality' obsCardinalityNext' - feeProtocol' unlocked') - (UInt256.ofNat 11) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [unlocked', slot0BoolReturnWord] - rw [show ((⟨128⟩ : UInt256) + ⟨192⟩).toNat = 320 from by decide, - slot0ReturnMem_eq] - rfl) - (by decide) (by evm_ov)] - exact evm_run rd938 with [ - raw mload 0 ⟨128⟩ (UInt256.ofNat 11) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (slot0ReturnMem_mload64 sqrt' tick' obsIndex' obsCardinality' obsCardinalityNext' - feeProtocol' unlocked') - (by decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup2 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨224⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw ret 0 - (UInt256.toByteArray sqrt' ++ UInt256.toByteArray tick' ++ - UInt256.toByteArray obsIndex' ++ UInt256.toByteArray obsCardinality' ++ - UInt256.toByteArray obsCardinalityNext' ++ UInt256.toByteArray feeProtocol' ++ - UInt256.toByteArray unlocked') - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [sqrt', tick', obsIndex', obsCardinality', obsCardinalityNext', - feeProtocol', unlocked'] - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - show ((⟨224⟩ : UInt256) + UInt256.sub (⟨128⟩ : UInt256) ⟨128⟩).toNat = - 224 from by decide] - exact slot0ReturnMem_read128_224 - (UInt256.land sqrt slot0Uint160Mask) (UInt256.signextend ⟨2⟩ tick) - (UInt256.land slot0Uint16Mask obsIndex) - (UInt256.land slot0Uint16Mask obsCardinality) - (UInt256.land slot0Uint16Mask obsCardinalityNext) - (UInt256.land feeProtocol slot0Uint8Mask) (slot0BoolReturnWord unlocked)) - (by evm_ov)] - -theorem uniswapV3PoolSlot0Evm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 6 == I.calldata.extract 0 4) = true) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (slot0SqrtPriceX96Word σ I) ++ - UInt256.toByteArray (slot0TickReturnWord σ I) ++ - UInt256.toByteArray (slot0ObservationIndexWord σ I) ++ - UInt256.toByteArray (slot0ObservationCardinalityWord σ I) ++ - UInt256.toByteArray (slot0ObservationCardinalityNextWord σ I) ++ - UInt256.toByteArray (slot0FeeProtocolWord σ I) ++ - UInt256.toByteArray (slot0BoolReturnWord (slot0UnlockedRawWord σ I))) := by - obtain ⟨_, _, rdReturn⟩ := uniswapV3PoolSlot0EvmAtReturn - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - have hret := uniswapV3PoolSlot0Return hpatch rdReturn - (by simp only [List.length_cons, List.length_nil]; omega) - have hsqrt : UInt256.land (slot0SqrtPriceX96Word σ I) slot0Uint160Mask = - slot0SqrtPriceX96Word σ I := by - exact slot0Uint160Mask_clean (by - simpa [slot0SqrtPriceX96Word] using slot0Uint160Mask_bound (slot0SlotWord σ I)) - have htick : UInt256.signextend ⟨2⟩ (slot0TickReturnWord σ I) = - slot0TickReturnWord σ I := by - dsimp [slot0TickReturnWord] - exact slot0SignextendTwo_idempotent - (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 20)) - have hobsIndex : UInt256.land slot0Uint16Mask (slot0ObservationIndexWord σ I) = - slot0ObservationIndexWord σ I := by - exact slot0Uint16Mask_clean_left (by - simpa [slot0ObservationIndexWord] using - slot0Uint16Mask_bound (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 23))) - have hobsCardinality : - UInt256.land slot0Uint16Mask (slot0ObservationCardinalityWord σ I) = - slot0ObservationCardinalityWord σ I := by - exact slot0Uint16Mask_clean_left (by - simpa [slot0ObservationCardinalityWord] using - slot0Uint16Mask_bound (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 25))) - have hobsCardinalityNext : - UInt256.land slot0Uint16Mask (slot0ObservationCardinalityNextWord σ I) = - slot0ObservationCardinalityNextWord σ I := by - exact slot0Uint16Mask_clean_left (by - simpa [slot0ObservationCardinalityNextWord] using - slot0Uint16Mask_bound (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 27))) - have hfee : UInt256.land (slot0FeeProtocolWord σ I) slot0Uint8Mask = - slot0FeeProtocolWord σ I := by - exact slot0Uint8Mask_clean (by - simpa [slot0FeeProtocolWord] using - slot0Uint8Mask_bound (UInt256.div (slot0SlotWord σ I) (slot0ShiftBytes 29))) - simpa [hsqrt, htick, hobsIndex, hobsCardinality, hobsCardinalityNext, hfee] using hret - -theorem uniswapV3PoolSlot0BodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 6 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_slot0 (v := v) (cd := I.calldata) hsel - have hdecode := uniswapV3PoolSlot0Decode (v := v) (I := I) hsz - have hbody := uniswapV3PoolSlot0SourceBody (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hvalue := uniswapV3PoolSlot0ValueTransport (σ_evm := σ_evm) - (σ_solm := σ_solm) (I := I) hAccounts - have hrd := uniswapV3PoolSlot0Evm (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel - exact hrd.reEquivExecutionTransport hcode hdispatch hdecode hbody hvalue hAccounts - (by - rw [show slot0Transition.returnType = - [uint160, int24, uint16, uint16, uint16, uint8, boolTy] from rfl] - exact returnEquiv.returned rfl (slot0ReturnEncoding σ_evm I)) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/SnapshotCumulativesInside.lean b/Benchmarks/UniswapV3Pool/SnapshotCumulativesInside.lean deleted file mode 100644 index 43bba50e..00000000 --- a/Benchmarks/UniswapV3Pool/SnapshotCumulativesInside.lean +++ /dev/null @@ -1,18 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolSnapshotCumulativesInsideBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 18 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Swap.lean b/Benchmarks/UniswapV3Pool/Swap.lean deleted file mode 100644 index c44fac95..00000000 --- a/Benchmarks/UniswapV3Pool/Swap.lean +++ /dev/null @@ -1,18 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolSwapBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 1 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/TickBitmap.lean b/Benchmarks/UniswapV3Pool/TickBitmap.lean deleted file mode 100644 index c912770d..00000000 --- a/Benchmarks/UniswapV3Pool/TickBitmap.lean +++ /dev/null @@ -1,988 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev tickBitmapArgWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -def tickBitmapSint16Value (w : UInt256) : Int := - let m := w.toNat % EVM.twoPow 16 - if m < EVM.twoPow 15 then (m : Int) else (m : Int) - (EVM.twoPow 16 : Int) - -abbrev tickBitmapArgCleanWord (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨1⟩ (tickBitmapArgWord I) - -abbrev tickBitmapArgValue (I : ExecutionEnv) : Value := - .int (tickBitmapSint16Value (tickBitmapArgWord I)) - -abbrev tickBitmapArgKey (I : ExecutionEnv) : KeyValue := - .int (tickBitmapSint16Value (tickBitmapArgWord I)) - -abbrev tickBitmapStore (I : ExecutionEnv) : Store := - (∅ : Store).insert "arg0" (tickBitmapArgValue I) - -abbrev tickBitmapStorageSlot (I : ExecutionEnv) : UInt256 := - tickBitmapSlot (tickBitmapArgKey I) - -abbrev tickBitmapWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (tickBitmapStorageSlot I) - -private theorem signextend_one_norm (w : UInt256) : UInt256.signextend ⟨1⟩ w = - if UInt256.land w (UInt256.ofNat (2^15)) = ⟨0⟩ then - UInt256.land w (UInt256.ofNat (2^15 - 1)) - else UInt256.lor w (UInt256.ofNat (UInt256.size - 2^15)) := by - unfold UInt256.signextend - rw [if_pos (by native_decide : (⟨1⟩ : UInt256).toNat ≤ 31)] - have htest : (⟨1⟩ : UInt256) * ⟨8⟩ + ⟨7⟩ = ⟨15⟩ := by native_decide - simp only [htest] - have hsign : (⟨1⟩ : UInt256) <<< (⟨15⟩ : UInt256) = UInt256.ofNat (2^15) := by - native_decide - rw [hsign] - have hsub1 : UInt256.ofNat (2 ^ 15) - ⟨1⟩ = UInt256.ofNat (2 ^ 15 - 1) := by - native_decide - have hsub2 : UInt256.size.toUInt256 - UInt256.ofNat (2 ^ 15) = - UInt256.ofNat (UInt256.size - 2 ^ 15) := by - native_decide - rw [hsub1, hsub2] - change (if UInt256.land w (UInt256.ofNat (2 ^ 15)) ≠ ⟨0⟩ then - UInt256.lor w (UInt256.ofNat (UInt256.size - 2 ^ 15)) - else UInt256.land w (UInt256.ofNat (2 ^ 15 - 1))) = _ - by_cases hzero : UInt256.land w (UInt256.ofNat (2 ^ 15)) = ⟨0⟩ - · rw [if_neg (by exact not_not.mpr hzero), if_pos hzero] - · rw [if_pos hzero, if_neg hzero] - -private theorem signextend_one_sign_bit_zero (w : UInt256) - (hm : w.toNat % EVM.twoPow 16 < EVM.twoPow 15) : - UInt256.land w (UInt256.ofNat (2^15)) = ⟨0⟩ := by - apply u256_inj - rw [u256_land_toNat] - have hbitm : (w.toNat % EVM.twoPow 16).testBit 15 = false := by - exact Nat.testBit_lt_two_pow (x := w.toNat % EVM.twoPow 16) (i := 15) hm - change (w.toNat % 2 ^ 16).testBit 15 = false at hbitm - rw [Nat.testBit_mod_two_pow] at hbitm - have hbitw : w.toNat.testBit 15 = false := by simpa using hbitm - rw [show (UInt256.ofNat (2 ^ 15)).toNat = 2 ^ 15 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] - change (w.toNat &&& 2 ^ 15) % UInt256.size = (⟨0⟩ : UInt256).toNat - rw [Nat.and_two_pow, hbitw] - norm_num - -private theorem signextend_one_sign_bit_ne_zero (w : UInt256) - (hm : ¬ w.toNat % EVM.twoPow 16 < EVM.twoPow 15) : - UInt256.land w (UInt256.ofNat (2^15)) ≠ ⟨0⟩ := by - intro hzero - have hmhi : w.toNat % EVM.twoPow 16 < EVM.twoPow 16 := - Nat.mod_lt _ (by norm_num [EVM.twoPow]) - have hmge : EVM.twoPow 15 ≤ w.toNat % EVM.twoPow 16 := by omega - have hdiv : (w.toNat % EVM.twoPow 16) / EVM.twoPow 15 = 1 := by - apply Nat.div_eq_of_lt_le (k := 1) - · simpa [EVM.twoPow] using hmge - · simpa [EVM.twoPow] using hmhi - have hbitm : (w.toNat % EVM.twoPow 16).testBit 15 = true := by - simp [Nat.testBit, Nat.shiftRight_eq_div_pow, EVM.twoPow] - have hdiv' : w.toNat % 65536 / 32768 = 1 := by simpa [EVM.twoPow] using hdiv - rw [hdiv'] - change (w.toNat % 2 ^ 16).testBit 15 = true at hbitm - rw [Nat.testBit_mod_two_pow] at hbitm - have hbitw : w.toNat.testBit 15 = true := by simpa using hbitm - have htoNat := congrArg UInt256.toNat hzero - rw [u256_land_toNat] at htoNat - rw [show (UInt256.ofNat (2 ^ 15)).toNat = 2 ^ 15 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] at htoNat - change (w.toNat &&& 2 ^ 15) % UInt256.size = (⟨0⟩ : UInt256).toNat at htoNat - rw [Nat.and_two_pow, hbitw] at htoNat - norm_num [UInt256.size] at htoNat - -private theorem nat_lor_high_mask_15 (n : Nat) (hn : n < 2 ^ 256) : - Nat.lor n (2 ^ 256 - 2 ^ 15) = n % 2 ^ 15 + (2 ^ 256 - 2 ^ 15) := by - have hmask : 2 ^ 256 - 2 ^ 15 = (2 ^ (256 - 15) - 1) <<< 15 := by - rw [Nat.shiftLeft_eq] - norm_num [Nat.pow_add] - rw [hmask] - rw [Nat.shiftLeft_eq] - rw [← nat_lor_shift_add (n % 2 ^ 15) (2 ^ (256 - 15) - 1) 15 - (Nat.mod_lt _ (by norm_num))] - apply Nat.eq_of_testBit_eq - intro i - change (n ||| ((2 ^ (256 - 15) - 1) * 2 ^ 15)).testBit i = - ((n % 2 ^ 15) ||| ((2 ^ (256 - 15) - 1) * 2 ^ 15)).testBit i - rw [Nat.testBit_or, Nat.testBit_or] - rw [show (2 ^ (256 - 15) - 1) * 2 ^ 15 = - (2 ^ (256 - 15) - 1) <<< 15 by rw [Nat.shiftLeft_eq]] - rw [testBit_shiftLeft] - by_cases hi15 : i < 15 - · rw [if_pos hi15] - conv_rhs => rw [Nat.testBit_mod_two_pow] - simp [hi15] - · rw [if_neg hi15] - rw [Nat.testBit_two_pow_sub_one] - by_cases hi256 : i < 256 - · have hlt241 : i - 15 < 256 - 15 := by omega - rw [decide_eq_true hlt241] - simp - · have hnbit : n.testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hn (Nat.pow_le_pow_right (by norm_num) (by omega))) - have hmodbit : (n % 2 ^ 15).testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 15)) - (Nat.pow_le_pow_right (by norm_num) (by omega))) - have hnot241 : ¬ i - 15 < 256 - 15 := by omega - rw [decide_eq_false hnot241, hnbit, hmodbit] - -private theorem wordOfInt_sint16_neg_toNat (m : Nat) (hmhi : m < EVM.twoPow 16) : - (EVM.wordOfInt ((m : Int) - (EVM.twoPow 16 : Int))).toNat = - UInt256.size - (EVM.twoPow 16 - m) := by - have hneg : ((m : Int) - (EVM.twoPow 16 : Int)) < 0 := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hnatAbs : ((m : Int) - (EVM.twoPow 16 : Int)).natAbs = EVM.twoPow 16 - m := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hdiffPos : EVM.twoPow 16 - m ≠ 0 := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hdiffLt : EVM.twoPow 16 - m < EVM.wordModulus := by - norm_num [EVM.wordModulus, EVM.twoPow] at hmhi ⊢ - omega - unfold EVM.wordOfInt - rw [if_pos hneg] - rw [hnatAbs, Nat.mod_eq_of_lt hdiffLt, if_neg hdiffPos] - change (UInt256.ofNat (EVM.wordModulus - (EVM.twoPow 16 - m))).toNat = _ - rw [ulit_toNat'] - · simp [EVM.wordModulus, EVM.twoPow, UInt256.size] - · norm_num [EVM.wordModulus, EVM.twoPow, UInt256.size] at hmhi ⊢ - omega - -private theorem wordOfInt_sint16Value_eq_signextend_one (w : UInt256) : - EVM.wordOfInt (tickBitmapSint16Value w) = UInt256.signextend ⟨1⟩ w := by - apply u256_inj - rw [signextend_one_norm] - unfold tickBitmapSint16Value - let m := w.toNat % EVM.twoPow 16 - have hmdef : m = w.toNat % EVM.twoPow 16 := rfl - have hmhi : m < EVM.twoPow 16 := by - rw [hmdef] - exact Nat.mod_lt _ (by norm_num [EVM.twoPow]) - have hwlt : w.toNat < UInt256.size := by - simp [UInt256.toNat] - by_cases h : m < EVM.twoPow 15 - · have hzero : UInt256.land w (UInt256.ofNat (2 ^ 15)) = ⟨0⟩ := by - apply signextend_one_sign_bit_zero - rwa [← hmdef] - rw [if_pos hzero] - have hval : - (let m := w.toNat % EVM.twoPow 16 - if m < EVM.twoPow 15 then (m : Int) else (m : Int) - (EVM.twoPow 16 : Int)) = - (m : Int) := by - dsimp - have h' : w.toNat % EVM.twoPow 16 < EVM.twoPow 15 := by rwa [← hmdef] - rw [if_pos h'] - omega - rw [hval] - have hword : (EVM.wordOfInt (m : Int)).toNat = m := by - unfold EVM.wordOfInt - rw [if_neg (by omega)] - unfold EVM.word EVM.uintN UInt256.toNat - change m % EVM.twoPow 256 = m - apply Nat.mod_eq_of_lt - norm_num [EVM.twoPow] at hmhi ⊢ - omega - rw [hword] - rw [u256_land_toNat] - rw [show (UInt256.ofNat (2 ^ 15 - 1)).toNat = 2 ^ 15 - 1 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] - change m = Nat.land w.toNat (2 ^ 15 - 1) % UInt256.size - rw [nat_land_mask_eq_mod] - have hmdef' : m = w.toNat % 2 ^ 16 := by simpa [EVM.twoPow] using hmdef - have hmod15 : w.toNat % 2 ^ 15 = m := by - have hmod16 : w.toNat % 2 ^ 16 = m := hmdef'.symm - rw [← Nat.mod_mod_of_dvd (a := w.toNat) (show 2 ^ 15 ∣ 2 ^ 16 by norm_num)] - rw [hmod16] - exact Nat.mod_eq_of_lt (by simpa [EVM.twoPow] using h) - rw [hmod15] - rw [Nat.mod_eq_of_lt (by - norm_num [EVM.twoPow, UInt256.size] at hmhi ⊢ - omega)] - · have hne : UInt256.land w (UInt256.ofNat (2 ^ 15)) ≠ ⟨0⟩ := by - apply signextend_one_sign_bit_ne_zero - rwa [← hmdef] - rw [if_neg hne] - have hval : - (let m := w.toNat % EVM.twoPow 16 - if m < EVM.twoPow 15 then (m : Int) else (m : Int) - (EVM.twoPow 16 : Int)) = - (m : Int) - (EVM.twoPow 16 : Int) := by - dsimp - have h' : ¬ w.toNat % EVM.twoPow 16 < EVM.twoPow 15 := by - intro hh - exact h (by rwa [hmdef]) - rw [if_neg h'] - omega - rw [hval] - have hword := wordOfInt_sint16_neg_toNat m hmhi - rw [hword] - rw [u256_lor_toNat] - rw [show (UInt256.ofNat (UInt256.size - 2 ^ 15)).toNat = UInt256.size - 2 ^ 15 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] - have hlor := nat_lor_high_mask_15 w.toNat (by simpa [UInt256.size] using hwlt) - change UInt256.size - (EVM.twoPow 16 - m) = - (Nat.lor w.toNat (2 ^ 256 - 2 ^ 15)) % UInt256.size - rw [hlor] - have hmdef' : m = w.toNat % 2 ^ 16 := by simpa [EVM.twoPow] using hmdef - have hmod15 : w.toNat % 2 ^ 15 = m - 2 ^ 15 := by - have hge : 2 ^ 15 ≤ m := by - have hnot : ¬ m < 2 ^ 15 := by simpa [EVM.twoPow] using h - omega - have hmhi' : m < 2 ^ 16 := by simpa [EVM.twoPow] using hmhi - have hmod16 : w.toNat % 2 ^ 16 = m := hmdef'.symm - rw [← Nat.mod_mod_of_dvd (a := w.toNat) (show 2 ^ 15 ∣ 2 ^ 16 by norm_num)] - rw [hmod16] - rw [Nat.mod_eq_sub_mod hge] - rw [Nat.mod_eq_of_lt (by omega : m - 2 ^ 15 < 2 ^ 15)] - rw [hmod15] - norm_num [UInt256.size, EVM.twoPow] at h hmhi ⊢ - omega - -theorem tickBitmapArgKeyWord (I : ExecutionEnv) : - keyValueToWord (tickBitmapArgKey I) = tickBitmapArgCleanWord I := by - unfold tickBitmapArgKey tickBitmapArgCleanWord tickBitmapArgWord keyValueToWord - exact wordOfInt_sint16Value_eq_signextend_one (calldataWord I.calldata 4) - -theorem decodeScalarWordsWithMode_int16_ok {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) : - decodeScalarWordsWithMode? DecodeMode.legacySolc05 [int16] bytes 0 = - some [Value.int (tickBitmapSint16Value (ABI.bytesToWord (bytes.take 32)))] := by - simp only [decodeScalarWordsWithMode?] - unfold decodeScalarWordWithMode? readWord? readBytes? int16 int16Int tickBitmapSint16Value - simp only [List.drop_zero] - rw [if_pos hlen0] - simp only [Option.bind, bind] - unfold decodeABIWord? - simp only [OfNat.ofNat_ne_zero, ↓reduceIte] - rfl - -theorem decodeScalarWordsWithMode_int16_none_short {bytes : List UInt8} - (hshort : bytes.length < 32) : - decodeScalarWordsWithMode? DecodeMode.legacySolc05 [int16] bytes 0 = none := by - simp only [decodeScalarWordsWithMode?] - have htake0n : ¬ (bytes.take 32).length = 32 := by - rw [List.length_take] - omega - unfold decodeScalarWordWithMode? readWord? readBytes? int16 int16Int - simp only [List.drop_zero] - rw [if_neg htake0n] - simp only [Option.bind, bind] - -theorem uniswapV3PoolTickBitmapDecodeOk {v : PoolImmutables} {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - (tickbitmapTransition.params.map Param.name) - (transitionSignature tickbitmapTransition).paramTypes I.calldata = some (tickBitmapStore I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake4 : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have hword4 : ABI.bytesToWord ((I.calldata.toList.drop 4).take 32) = - calldataWord I.calldata 4 := - decode_word_at_eq I.calldata 4 (by omega) (by norm_num) - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := tickbitmapTransition.params.map Param.name) - (types := (transitionSignature tickbitmapTransition).paramTypes) (cd := I.calldata)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 [int16] - (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["arg0"] values ∅ - | none => none) = some (tickBitmapStore I) - rw [decodeScalarWordsWithMode_int16_ok (bytes := I.calldata.toList.drop 4) htake4] - change decodeCalldata.insertValues ["arg0"] - [Value.int - (tickBitmapSint16Value (ABI.bytesToWord ((I.calldata.toList.drop 4).take 32)))] ∅ = - some (tickBitmapStore I) - simp [decodeCalldata.insertValues, tickBitmapStore, tickBitmapArgValue, tickBitmapArgWord] - rw [hword4] - · native_decide - -theorem uniswapV3PoolTickBitmapDecodeShort {v : PoolImmutables} {I : ExecutionEnv} - (hshort : I.calldata.size < 36) : - decodeCalldataWithMode (config v).abiDecodeMode - (tickbitmapTransition.params.map Param.name) - (transitionSignature tickbitmapTransition).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := tickbitmapTransition.params.map Param.name) - (types := (transitionSignature tickbitmapTransition).paramTypes) (cd := I.calldata)] - · by_cases hsz4 : I.calldata.size < 4 - · rw [if_pos (by rw [htlen]; omega : I.calldata.toList.length < 4)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 [int16] - (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["arg0"] values ∅ - | none => none) = none - rw [decodeScalarWordsWithMode_int16_none_short - (bytes := I.calldata.toList.drop 4) (by rw [List.length_drop, htlen]; omega)] - · native_decide - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolDispatch_tickBitmap {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 12 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some tickbitmapTransition := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, factoryTransition v, - feeTransition v, feegrowthglobal0X128Transition, feegrowthglobal1X128Transition, - flashTransition v, increaseobservationcardinalitynextTransition v, initializeTransition, - liquidityTransition, maxliquiditypertickTransition v, mintTransition v, observationsTransition, - observeTransition v, positionsTransition, protocolfeesTransition, setfeeprotocolTransition v, - slot0Transition, snapshotcumulativesinsideTransition v, swapTransition v]) - (post := [tickspacingTransition v, ticksTransition, token0Transition v, token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 12) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 12) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 12) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 12) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 12) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 12) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 12) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 12) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 5) (j := 12) - (by native_decide) hsel - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 25) (j := 12) - (by native_decide) hsel - · rw [selectorOf, liquiditySelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 2) (j := 12) - (by native_decide) hsel - · rw [selectorOf, maxLiquidityPerTickSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 13) (j := 12) - (by native_decide) hsel - · rw [selectorOf, mintSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 7) (j := 12) - (by native_decide) hsel - · rw [selectorOf, observationsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 4) (j := 12) - (by native_decide) hsel - · rw [selectorOf, observeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 16) (j := 12) - (by native_decide) hsel - · rw [selectorOf, positionsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 11) (j := 12) - (by native_decide) hsel - · rw [selectorOf, protocolFeesSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 3) (j := 12) - (by native_decide) hsel - · rw [selectorOf, setFeeProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 14) (j := 12) - (by native_decide) hsel - · rw [selectorOf, slot0SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 6) (j := 12) - (by native_decide) hsel - · rw [selectorOf, snapshotCumulativesInsideSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 18) (j := 12) - (by native_decide) hsel - · rw [selectorOf, swapSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 1) (j := 12) - (by native_decide) hsel - · rw [selectorOf, tickBitmapSelectorBytes] - simpa [uniswapV3PoolSelBytes] using hsel - -theorem tickBitmapStore_arg0 (I : ExecutionEnv) : - Std.HashMap.get? (tickBitmapStore I) "arg0" = some (tickBitmapArgValue I) := by - simp [tickBitmapStore] - -theorem evalExpr_tickBitmap_arg0 {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := tickBitmapStore I } evm - (.var "arg0") = .ok (tickBitmapArgValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [tickBitmapStore_arg0] - -def tickBitmapEvaledRef (I : ExecutionEnv) : EvaledStorageRef := - { base := "tickBitmap", steps := [.mindex (tickBitmapArgKey I)] } - -theorem evalStorageRef_tickBitmap {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalStorageRef (config v) { contract := contract v, locals := tickBitmapStore I } evm - (tickBitmapRef (.var "arg0")) = .ok (tickBitmapEvaledRef I) := by - simp [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, tickBitmapRef, - tickBitmapEvaledRef, evalExpr_tickBitmap_arg0, tickBitmapArgValue, tickBitmapArgKey, - valueToKey?, EvalResult.bind, EvalResult.ofOption, bind, pure] - -theorem evalExpr_tickBitmap_storage {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := tickBitmapStore I } evm - (.storage (tickBitmapRef (.var "arg0"))) = - .ok (.int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (tickBitmapStorageSlot I)).toNat)) := by - rw [evalExpr_storage_scalar - (t := .int uint256Int) - (slot := tickBitmapRef (.var "arg0")) - (er := tickBitmapEvaledRef I) - (loc := loc (tickBitmapStorageSlot I) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int)) - (hbase := by simp [tickBitmapStore, tickBitmapRef]) - (her := evalStorageRef_tickBitmap evm I) - (hty := by - simp [storageTypeAt?, tickBitmapEvaledRef, contract, storageDecls, uint256St, - storageTypeStep?]) - (hloc := by - funext evm' - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, tickBitmapEvaledRef, - tickBitmapStorageSlot, loc])] - simpa [loc, uint256Loc] using storageLocLoad_uint256 evm (tickBitmapStorageSlot I) - -theorem uniswapV3PoolTickBitmapSourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (tickBitmapStore I) tickbitmapTransition.body - (.returned { contract := contract v, locals := tickBitmapStore I } - (initState cA gh bl σ σ₀ g A I) - (some [Value.int (Int.ofNat (tickBitmapWord σ I).toNat)])) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (tickBitmapStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [.storage (tickBitmapRef (.var "arg0"))] ] _ - exact ExecFuncBody.execBlockRet <| - (ABlock.start.requireStep (evalCallvalueEq_true (by simp [initState, hwv]))).returns (by - simpa [initState, tickBitmapWord, tickBitmapStorageSlot, solcSlotWord] using - evalExpr_tickBitmap_storage (v := v) (initState cA gh bl σ σ₀ g A I) I) - -theorem uniswapV3PoolTickBitmapValueTransport {σ_evm σ_solm : AccountMap} - {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - some [Value.int (Int.ofNat (tickBitmapWord σ_solm I).toNat)] = - some [Value.int (Int.ofNat (tickBitmapWord σ_evm I).toNat)] := by - have hslot := accountMapEquiv_storage_findD hAccounts I.codeOwner - (tickBitmapStorageSlot I) (⟨0⟩ : UInt256) - dsimp [tickBitmapWord, solcSlotWord] - rw [← hslot] - -private theorem uniswapV3PoolTickBitmapGetterPatchDisjoint1 {v : PoolImmutables} - {pc : UInt256} (hlo : 8154 ≤ pc.toNat) (hhi : pc.toNat + 1 ≤ 8174) : - ∀ p ∈ patches v, pc.toNat + 1 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolTickBitmapGetterPatchDisjoint2 {v : PoolImmutables} - {pc : UInt256} (hlo : 8154 ≤ pc.toNat) (hhi : pc.toNat + 2 ≤ 8174) : - ∀ p ∈ patches v, pc.toNat + 2 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -private theorem uniswapV3PoolTickBitmapDecodePatchedPush1 {v : PoolImmutables} - {code : ByteArray} {pc n : UInt256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hwin : pc.toNat + 2 ≤ uniswapV3PoolBytecode.size) - (hdisj : ∀ p ∈ patches v, pc.toNat + 2 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat) - (hgetTemplate : uniswapV3PoolBytecode.get? pc.toNat = some 0x60) - (hval : uInt256OfByteArray - (uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1)) = n) : - decode code pc = some (.Push .PUSH1, some (n, 1)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have htemplate64 : uniswapV3PoolBytecode.size < 2 ^ 64 := by native_decide - have hget : code.get? pc.toNat = uniswapV3PoolBytecode.get? pc.toNat := by - apply get?_eq_of_extract_one - · rw [hsize] - omega - · omega - · exact patchRuntime_extract_eq (start := pc.toNat) (stop := pc.toNat + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl (by omega) - · exact Or.inr hafter) - hpatch - have hextract : - code.extract' pc.toNat.succ (pc.toNat.succ + 1) = - uniswapV3PoolBytecode.extract' pc.toNat.succ (pc.toNat.succ + 1) := by - unfold ByteArray.extract' - have hguard : - (decide (pc.toNat.succ < 2 ^ 64) && decide (pc.toNat.succ + 1 < 2 ^ 64)) = - true := by - rw [Bool.and_eq_true] - constructor <;> rw [decide_eq_true_eq] <;> omega - rw [if_pos hguard, if_pos hguard] - exact patchRuntime_extract_eq (start := pc.toNat.succ) (stop := pc.toNat.succ + 1) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by omega) - (fun p hp => by - rcases hdisj p hp with hbefore | hafter - · exact Or.inl hbefore - · exact Or.inr (by omega)) - hpatch - have hgetSome : code.get? pc.toNat = some 0x60 := by - rw [hget, hgetTemplate] - have hparse : (some (0x60 : UInt8) >>= parseInstr) = some (.Push .PUSH1) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH1, - some (uInt256OfByteArray (code.extract' pc.toNat.succ (pc.toNat.succ + 1)), 1)) = - some (Operation.Push Operation.POp.PUSH1, some (n, 1)) - rw [hextract, hval] - -private theorem uniswapV3PoolPatchPreservesJumpDest8154 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨8154⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched8154 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨8154⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest8154 - -theorem uniswapV3PoolTickBitmapGetterWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcSingleMappingGetterWf code ⟨8154⟩ ⟨6⟩ := by - dsimp [solcSingleMappingGetterWf] - refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8154⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · exact uniswapV3PoolTickBitmapDecodePatchedPush1 (pc := ⟨8155⟩) (n := ⟨6⟩) - hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · exact uniswapV3PoolTickBitmapDecodePatchedPush1 (pc := ⟨8157⟩) (n := ⟨32⟩) - hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8159⟩) (byte := 0x52) - (op := .MSTORE) hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · exact uniswapV3PoolTickBitmapDecodePatchedPush1 (pc := ⟨8160⟩) (n := ⟨0⟩) - hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8162⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8163⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8164⟩) (byte := 0x52) - (op := .MSTORE) hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · exact uniswapV3PoolTickBitmapDecodePatchedPush1 (pc := ⟨8165⟩) (n := ⟨64⟩) - hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint2 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8167⟩) (byte := 0x90) - (op := .SWAP1) hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8168⟩) (byte := 0x20) - (op := .KECCAK256) hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8169⟩) (byte := 0x54) - (op := .SLOAD) hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8170⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - · refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨8171⟩) (byte := 0x56) - (op := .JUMP) hpatch (by native_decide) - (uniswapV3PoolTickBitmapGetterPatchDisjoint1 (by native_decide) (by native_decide)) - (by native_decide) (by native_decide) (by native_decide) - -theorem uniswapV3PoolTickBitmapReturnWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcReturnWordFromMemWf code ⟨1118⟩ := by - dsimp [solcReturnWordFromMemWf] - refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem tickBitmapStorageSlot_eq_solcMappingSlot (I : ExecutionEnv) : - tickBitmapStorageSlot I = solcMappingSlot ⟨6⟩ (tickBitmapArgCleanWord I) := by - unfold tickBitmapStorageSlot tickBitmapSlot mapSlot solcMappingSlot - rw [tickBitmapArgKeyWord I] - -private def tickBitmapStSignextend (s : State) (res : UInt256) (t : List UInt256) : - State := - { s with - machineState.stack := res :: t, - machineState.gasAvailable := s.machineState.gasAvailable.subNat 5 - machineState.pc := s.machineState.pc + ⟨1⟩ - machineState.execLength := s.machineState.execLength + 1 } - -private theorem tickBitmapSignextendXstep {code : ByteArray} {s : State} {pc a b : UInt256} - {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pc) - (hdec : decode code pc = some (.SIGNEXTEND, .none)) - (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : - Xstep (D_J code 0) s = - if s.machineState.gasAvailable.toNat < 5 then .error .OutOfGass - else .ok (tickBitmapStSignextend s (UInt256.signextend a b) t, .none) := by - have hdecS : decode s.executionEnv.code s.machineState.pc = some (.SIGNEXTEND, .none) := by - rw [hcode, hpc] - exact hdec - have hstep := step_signextend s hdecS - have hnoOverflow : ¬ 1024 ≤ t.length := by omega - simpa [hcode, hstk, GasConstants.Glow, tickBitmapStSignextend, hnoOverflow] using hstep - -private theorem tickBitmapRDSignextend {code : ByteArray} {ee : ExecutionEnv} - {g : Sat256} {s0 : State} {pc : UInt256} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.SIGNEXTEND, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.signextend a b :: t) mem aw rdata acc - (k + 1) (C + 5) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, hee, - hworld⟩ - · exact Or.inl hoog - · have st := tickBitmapSignextendXstep hcode hpc hdec hstk hov - by_cases gg : g.toNat < C + 5 - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨tickBitmapStSignextend s (UInt256.signextend a b) t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, by omega, - by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [tickBitmapStSignextend]; exact hcode - · simp only [tickBitmapStSignextend]; rw [hpc] - · rfl - · simp only [tickBitmapStSignextend]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [tickBitmapStSignextend]; exact hmem - · simp only [tickBitmapStSignextend]; exact haw - · simp only [tickBitmapStSignextend]; exact hrdata - · simp only [tickBitmapStSignextend]; exact hacc - · exact hee - · exact hworld - -theorem uniswapV3PoolTickBitmapReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 12 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1446⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 12 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0x53 0x39 0xc2 0x96 - (uniswapV3PoolSelNat 12) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h239 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨239⟩) hpatch h32 hgt32 - have hgt239 : UInt256.gt (armSelNat code ⟨239⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h250 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨250⟩) hpatch h239 hgt239 - have hgt250 : UInt256.gt (armSelNat code ⟨250⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h261 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨261⟩) hpatch h250 hgt250 - have hmiss9 : (uniswapV3PoolSelBytes 9 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h272 := uniswapV3PoolSelectorArmMissToOf (i := 9) (next := ⟨272⟩) - hpatch hsz hmiss9 h261 - have hmiss10 : (uniswapV3PoolSelBytes 10 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h283 := uniswapV3PoolSelectorArmMissToOf (i := 10) (next := ⟨283⟩) - hpatch hsz hmiss10 h272 - have hmiss11 : (uniswapV3PoolSelBytes 11 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h294 := uniswapV3PoolSelectorArmMissToOf (i := 11) (next := ⟨294⟩) - hpatch hsz hmiss11 h283 - have h1446 := uniswapV3PoolSelectorArmHitTo (i := 12) (target := ⟨1446⟩) - hpatch hsz hsel h294 - exact ⟨_, _, h1446⟩ - -private theorem uniswapV3PoolTickBitmapDecodedReachRoutine {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {de ret : UInt256} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨1468⟩ (de :: ⟨4⟩ :: ret :: R) mem aw rdata acc k C) - (hov : R.length + 3 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨8154⟩ (tickBitmapArgCleanWord ee :: ret :: R) - mem aw rdata acc k' C' := by - have rd1469 : RD code ee g s0 ⟨1469⟩ (de :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1) (C + 1) := by - simpa using h.jumpdest - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1470 : RD code ee g s0 ⟨1470⟩ (⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1) (C + 1 + 2) := by - simpa using rd1469.pop - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1471 : RD code ee g s0 ⟨1471⟩ (tickBitmapArgWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1) (C + 1 + 2 + 3) := by - simpa [tickBitmapArgWord, calldataWord, show (⟨4⟩ : UInt256).toNat = 4 from by decide] - using (rd1470.calldataload - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov)) - have rd1473 : RD code ee g s0 ⟨1473⟩ (⟨1⟩ :: tickBitmapArgWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3) := by - simpa using rd1471.push1 ⟨1⟩ - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd1474 : RD code ee g s0 ⟨1474⟩ (tickBitmapArgCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3 + 5) := by - simpa [tickBitmapArgCleanWord] using - (tickBitmapRDSignextend rd1473 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov)) - have rd1477 : RD code ee g s0 ⟨1477⟩ (⟨8154⟩ :: tickBitmapArgCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1) - (C + 1 + 2 + 3 + 3 + 5 + 3) := by - simpa using rd1474.push2 ⟨8154⟩ - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - exact ⟨_, _, rd1477.jump - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (uniswapV3PoolJumpDestPatched8154 hpatch) - (by evm_ov)⟩ - -set_option maxHeartbeats 3000000 in -private theorem uniswapV3PoolTickBitmapExternalLenOk {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hreach : ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1446⟩ - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1468⟩ - (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩ :: ⟨4⟩ :: ⟨1118⟩ :: - [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact RD.solcExternalStaticArgsLenOk (need := ⟨32⟩) - (entry := ⟨1446⟩) (ret := ⟨1118⟩) (decoded := ⟨1468⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (solcDecodeLenCheckOkUnsigned (by simpa using hsz36) hsize) - -set_option maxHeartbeats 2000000 in -private theorem uniswapV3PoolTickBitmapDecodedToLoaded {v : PoolImmutables} - {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} {de : UInt256} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (rdDecoded : RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1468⟩ - (de :: ⟨4⟩ :: ⟨1118⟩ :: [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : - ∃ k' C', RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1118⟩ - (tickBitmapWord σ I :: ⟨1118⟩ :: [solcSelectorWord I]) - (solcMappingHashMem ⟨6⟩ (tickBitmapArgCleanWord I)) (UInt256.ofNat 3) - ByteArray.empty (cA, σ) k' C' := by - obtain ⟨_, _, rdRoutine⟩ := - uniswapV3PoolTickBitmapDecodedReachRoutine hpatch rdDecoded - (by simp only [List.length_singleton]; omega) - obtain ⟨_, _, rdLoaded0⟩ := RD.solcSingleMappingGetter (baseSlot := ⟨6⟩) - (key := tickBitmapArgCleanWord I) (ret := ⟨1118⟩) (R := [solcSelectorWord I]) - rdRoutine (uniswapV3PoolTickBitmapGetterWf hpatch) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (by simp only [List.length_singleton]; omega) - exact ⟨_, _, by - simpa [tickBitmapWord, tickBitmapStorageSlot_eq_solcMappingSlot I] using rdLoaded0⟩ - -private theorem uniswapV3PoolTickBitmapLoadedToReturn {v : PoolImmutables} - {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (rdLoaded : RD code I g (initState cA gh bl σ σ₀ g A I) ⟨1118⟩ - (tickBitmapWord σ I :: ⟨1118⟩ :: [solcSelectorWord I]) - (solcMappingHashMem ⟨6⟩ (tickBitmapArgCleanWord I)) (UInt256.ofNat 3) - ByteArray.empty (cA, σ) k C) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (tickBitmapWord σ I)) := by - exact RD.solcReturnWordFromMem rdLoaded - (uniswapV3PoolTickBitmapReturnWf hpatch) - (solcMappingHashMem_mload64 ⟨6⟩ (tickBitmapArgCleanWord I)) - (by rfl) - (solcScratchReturnMem_mload64 (tickBitmapWord σ I) - (solcMappingHashMem_size ⟨6⟩ (tickBitmapArgCleanWord I)) - (solcMappingHashMem_read64 ⟨6⟩ (tickBitmapArgCleanWord I))) - (solcScratchReturnMem_read128 (tickBitmapWord σ I) - (solcMappingHashMem_size ⟨6⟩ (tickBitmapArgCleanWord I))) - (by simp only [List.length_singleton]; omega) - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolTickBitmapEvm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 12 == I.calldata.extract 0 4) = true) - (hsz36 : 36 ≤ I.calldata.size) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (tickBitmapWord σ I)) := by - have hreach := uniswapV3PoolTickBitmapReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - have hdecoded := uniswapV3PoolTickBitmapExternalLenOk hpatch hreach hsz36 hsize - obtain ⟨_, _, rdDecoded⟩ := hdecoded - obtain ⟨_, _, rdLoaded⟩ := uniswapV3PoolTickBitmapDecodedToLoaded hpatch rdDecoded - exact uniswapV3PoolTickBitmapLoadedToReturn hpatch rdLoaded - -theorem uniswapV3PoolTickBitmapEvmDecodeShort {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 12 == I.calldata.extract 0 4) = true) - (hshort : I.calldata.size < 36) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - have hreach := uniswapV3PoolTickBitmapReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - have hlt : - UInt256.lt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩ := by - apply ult_one - rw [usub_ofNat_word_toNat (by - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega) hsize] - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide] - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega - exact RD.solcExternalStaticArgsShortReverts (need := ⟨32⟩) - (entry := ⟨1446⟩) (ret := ⟨1118⟩) (decoded := ⟨1468⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - hlt - -theorem uniswapV3PoolTickBitmapBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 12 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_tickBitmap (v := v) (cd := I.calldata) hsel - by_cases hsz36 : 36 ≤ I.calldata.size - · have hdecode := uniswapV3PoolTickBitmapDecodeOk (v := v) (I := I) hsz36 - have hbody := uniswapV3PoolTickBitmapSourceBody (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hvalue := uniswapV3PoolTickBitmapValueTransport (σ_evm := σ_evm) - (σ_solm := σ_solm) (I := I) hAccounts - have hrd := uniswapV3PoolTickBitmapEvm (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hsz36 - exact hrd.reEquivExecutionTransport hcode hdispatch hdecode hbody hvalue hAccounts - (returnEquiv_of_encode (uint256ReturnEncoding (tickBitmapWord σ_evm I))) - · have hshort : I.calldata.size < 36 := by omega - have hdecode := uniswapV3PoolTickBitmapDecodeShort (v := v) (I := I) hshort - have hrd := uniswapV3PoolTickBitmapEvmDecodeShort (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hshort - exact hrd.reEquivDecodingFailed hcode hdispatch hdecode - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/TickSpacing.lean b/Benchmarks/UniswapV3Pool/TickSpacing.lean deleted file mode 100644 index 9edd1a49..00000000 --- a/Benchmarks/UniswapV3Pool/TickSpacing.lean +++ /dev/null @@ -1,1400 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def tickSpacingSint24Value (w : UInt256) : Int := - let m := w.toNat % EVM.twoPow 24 - if m < EVM.twoPow 23 then (m : Int) else (m : Int) - (EVM.twoPow 24 : Int) - -private theorem signextend_two_norm (w : UInt256) : UInt256.signextend ⟨2⟩ w = - if UInt256.land w (UInt256.ofNat (2 ^ 23)) = ⟨0⟩ then - UInt256.land w (UInt256.ofNat (2 ^ 23 - 1)) - else UInt256.lor w (UInt256.ofNat (UInt256.size - 2 ^ 23)) := by - unfold UInt256.signextend - rw [if_pos (by native_decide : (⟨2⟩ : UInt256).toNat ≤ 31)] - have htest : (⟨2⟩ : UInt256) * ⟨8⟩ + ⟨7⟩ = ⟨23⟩ := by native_decide - simp only [htest] - have hsign : (⟨1⟩ : UInt256) <<< (⟨23⟩ : UInt256) = UInt256.ofNat (2 ^ 23) := by - native_decide - rw [hsign] - have hsub1 : UInt256.ofNat (2 ^ 23) - ⟨1⟩ = UInt256.ofNat (2 ^ 23 - 1) := by - native_decide - have hsub2 : UInt256.size.toUInt256 - UInt256.ofNat (2 ^ 23) = - UInt256.ofNat (UInt256.size - 2 ^ 23) := by - native_decide - rw [hsub1, hsub2] - change (if UInt256.land w (UInt256.ofNat (2 ^ 23)) ≠ ⟨0⟩ then - UInt256.lor w (UInt256.ofNat (UInt256.size - 2 ^ 23)) - else UInt256.land w (UInt256.ofNat (2 ^ 23 - 1))) = _ - by_cases hzero : UInt256.land w (UInt256.ofNat (2 ^ 23)) = ⟨0⟩ - · rw [if_neg (by exact not_not.mpr hzero), if_pos hzero] - · rw [if_pos hzero, if_neg hzero] - -private theorem signextend_two_sign_bit_zero (w : UInt256) - (hm : w.toNat % EVM.twoPow 24 < EVM.twoPow 23) : - UInt256.land w (UInt256.ofNat (2 ^ 23)) = ⟨0⟩ := by - apply u256_inj - rw [u256_land_toNat] - have hbitm : (w.toNat % EVM.twoPow 24).testBit 23 = false := by - exact Nat.testBit_lt_two_pow (x := w.toNat % EVM.twoPow 24) (i := 23) hm - change (w.toNat % 2 ^ 24).testBit 23 = false at hbitm - rw [Nat.testBit_mod_two_pow] at hbitm - have hbitw : w.toNat.testBit 23 = false := by simpa using hbitm - rw [show (UInt256.ofNat (2 ^ 23)).toNat = 2 ^ 23 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] - change (w.toNat &&& 2 ^ 23) % UInt256.size = (⟨0⟩ : UInt256).toNat - rw [Nat.and_two_pow, hbitw] - norm_num - -private theorem signextend_two_sign_bit_ne_zero (w : UInt256) - (hm : ¬ w.toNat % EVM.twoPow 24 < EVM.twoPow 23) : - UInt256.land w (UInt256.ofNat (2 ^ 23)) ≠ ⟨0⟩ := by - intro hzero - have hmhi : w.toNat % EVM.twoPow 24 < EVM.twoPow 24 := - Nat.mod_lt _ (by norm_num [EVM.twoPow]) - have hmge : EVM.twoPow 23 ≤ w.toNat % EVM.twoPow 24 := by omega - have hdiv : (w.toNat % EVM.twoPow 24) / EVM.twoPow 23 = 1 := by - apply Nat.div_eq_of_lt_le (k := 1) - · simpa [EVM.twoPow] using hmge - · simpa [EVM.twoPow] using hmhi - have hbitm : (w.toNat % EVM.twoPow 24).testBit 23 = true := by - simp [Nat.testBit, Nat.shiftRight_eq_div_pow, EVM.twoPow] - have hdiv' : w.toNat % 16777216 / 8388608 = 1 := by - simpa [EVM.twoPow] using hdiv - rw [hdiv'] - change (w.toNat % 2 ^ 24).testBit 23 = true at hbitm - rw [Nat.testBit_mod_two_pow] at hbitm - have hbitw : w.toNat.testBit 23 = true := by simpa using hbitm - have htoNat := congrArg UInt256.toNat hzero - rw [u256_land_toNat] at htoNat - rw [show (UInt256.ofNat (2 ^ 23)).toNat = 2 ^ 23 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] at htoNat - change (w.toNat &&& 2 ^ 23) % UInt256.size = (⟨0⟩ : UInt256).toNat at htoNat - rw [Nat.and_two_pow, hbitw] at htoNat - norm_num [UInt256.size] at htoNat - -private theorem nat_lor_high_mask_23 (n : Nat) (hn : n < 2 ^ 256) : - Nat.lor n (2 ^ 256 - 2 ^ 23) = n % 2 ^ 23 + (2 ^ 256 - 2 ^ 23) := by - have hmask : 2 ^ 256 - 2 ^ 23 = (2 ^ (256 - 23) - 1) <<< 23 := by - rw [Nat.shiftLeft_eq] - norm_num [Nat.pow_add] - rw [hmask] - rw [Nat.shiftLeft_eq] - rw [← nat_lor_shift_add (n % 2 ^ 23) (2 ^ (256 - 23) - 1) 23 - (Nat.mod_lt _ (by norm_num))] - apply Nat.eq_of_testBit_eq - intro i - change (n ||| ((2 ^ (256 - 23) - 1) * 2 ^ 23)).testBit i = - ((n % 2 ^ 23) ||| ((2 ^ (256 - 23) - 1) * 2 ^ 23)).testBit i - rw [Nat.testBit_or, Nat.testBit_or] - rw [show (2 ^ (256 - 23) - 1) * 2 ^ 23 = - (2 ^ (256 - 23) - 1) <<< 23 by rw [Nat.shiftLeft_eq]] - rw [testBit_shiftLeft] - by_cases hi23 : i < 23 - · rw [if_pos hi23] - conv_rhs => rw [Nat.testBit_mod_two_pow] - simp [hi23] - · rw [if_neg hi23] - rw [Nat.testBit_two_pow_sub_one] - by_cases hi256 : i < 256 - · have hlt233 : i - 23 < 256 - 23 := by omega - rw [decide_eq_true hlt233] - simp - · have hnbit : n.testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hn (Nat.pow_le_pow_right (by norm_num) (by omega))) - have hmodbit : (n % 2 ^ 23).testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 23)) - (Nat.pow_le_pow_right (by norm_num) (by omega))) - have hnot233 : ¬ i - 23 < 256 - 23 := by omega - rw [decide_eq_false hnot233, hnbit, hmodbit] - -private theorem wordOfInt_sint24_neg_toNat (m : Nat) (hmhi : m < EVM.twoPow 24) : - (EVM.wordOfInt ((m : Int) - (EVM.twoPow 24 : Int))).toNat = - UInt256.size - (EVM.twoPow 24 - m) := by - have hneg : ((m : Int) - (EVM.twoPow 24 : Int)) < 0 := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hnatAbs : ((m : Int) - (EVM.twoPow 24 : Int)).natAbs = EVM.twoPow 24 - m := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hdiffPos : EVM.twoPow 24 - m ≠ 0 := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hdiffLt : EVM.twoPow 24 - m < EVM.wordModulus := by - norm_num [EVM.wordModulus, EVM.twoPow] at hmhi ⊢ - omega - unfold EVM.wordOfInt - rw [if_pos hneg] - rw [hnatAbs, Nat.mod_eq_of_lt hdiffLt, if_neg hdiffPos] - change (UInt256.ofNat (EVM.wordModulus - (EVM.twoPow 24 - m))).toNat = _ - rw [ulit_toNat'] - · simp [EVM.wordModulus, EVM.twoPow, UInt256.size] - · norm_num [EVM.wordModulus, EVM.twoPow, UInt256.size] at hmhi ⊢ - omega - -theorem wordOfInt_sint24Value_eq_signextend_two (w : UInt256) : - EVM.wordOfInt (tickSpacingSint24Value w) = UInt256.signextend ⟨2⟩ w := by - apply u256_inj - rw [signextend_two_norm] - unfold tickSpacingSint24Value - let m := w.toNat % EVM.twoPow 24 - have hmdef : m = w.toNat % EVM.twoPow 24 := rfl - have hmhi : m < EVM.twoPow 24 := by - rw [hmdef] - exact Nat.mod_lt _ (by norm_num [EVM.twoPow]) - have hwlt : w.toNat < UInt256.size := by - simp [UInt256.toNat] - by_cases h : m < EVM.twoPow 23 - · have hzero : UInt256.land w (UInt256.ofNat (2 ^ 23)) = ⟨0⟩ := by - apply signextend_two_sign_bit_zero - rwa [← hmdef] - rw [if_pos hzero] - have hval : - (let m := w.toNat % EVM.twoPow 24 - if m < EVM.twoPow 23 then (m : Int) else (m : Int) - (EVM.twoPow 24 : Int)) = - (m : Int) := by - dsimp - have h' : w.toNat % EVM.twoPow 24 < EVM.twoPow 23 := by rwa [← hmdef] - rw [if_pos h'] - omega - rw [hval] - have hword : (EVM.wordOfInt (m : Int)).toNat = m := by - unfold EVM.wordOfInt - rw [if_neg (by omega)] - unfold EVM.word EVM.uintN UInt256.toNat - change m % EVM.twoPow 256 = m - apply Nat.mod_eq_of_lt - norm_num [EVM.twoPow] at hmhi ⊢ - omega - rw [hword] - rw [u256_land_toNat] - rw [show (UInt256.ofNat (2 ^ 23 - 1)).toNat = 2 ^ 23 - 1 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] - change m = Nat.land w.toNat (2 ^ 23 - 1) % UInt256.size - rw [nat_land_mask_eq_mod] - have hmdef' : m = w.toNat % 2 ^ 24 := by simpa [EVM.twoPow] using hmdef - have hmod23 : w.toNat % 2 ^ 23 = m := by - have hmod24 : w.toNat % 2 ^ 24 = m := hmdef'.symm - rw [← Nat.mod_mod_of_dvd (a := w.toNat) (show 2 ^ 23 ∣ 2 ^ 24 by norm_num)] - rw [hmod24] - exact Nat.mod_eq_of_lt (by simpa [EVM.twoPow] using h) - rw [hmod23] - rw [Nat.mod_eq_of_lt (by - norm_num [EVM.twoPow, UInt256.size] at hmhi ⊢ - omega)] - · have hne : UInt256.land w (UInt256.ofNat (2 ^ 23)) ≠ ⟨0⟩ := by - apply signextend_two_sign_bit_ne_zero - rwa [← hmdef] - rw [if_neg hne] - have hval : - (let m := w.toNat % EVM.twoPow 24 - if m < EVM.twoPow 23 then (m : Int) else (m : Int) - (EVM.twoPow 24 : Int)) = - (m : Int) - (EVM.twoPow 24 : Int) := by - dsimp - have h' : ¬ w.toNat % EVM.twoPow 24 < EVM.twoPow 23 := by - intro hh - exact h (by rwa [hmdef]) - rw [if_neg h'] - omega - rw [hval] - have hword := wordOfInt_sint24_neg_toNat m hmhi - rw [hword] - rw [u256_lor_toNat] - rw [show (UInt256.ofNat (UInt256.size - 2 ^ 23)).toNat = - UInt256.size - 2 ^ 23 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] - have hlor := nat_lor_high_mask_23 w.toNat (by simpa [UInt256.size] using hwlt) - change UInt256.size - (EVM.twoPow 24 - m) = - (Nat.lor w.toNat (2 ^ 256 - 2 ^ 23)) % UInt256.size - rw [hlor] - have hmdef' : m = w.toNat % 2 ^ 24 := by simpa [EVM.twoPow] using hmdef - have hmod23 : w.toNat % 2 ^ 23 = m - 2 ^ 23 := by - have hge : 2 ^ 23 ≤ m := by - have hnot : ¬ m < 2 ^ 23 := by simpa [EVM.twoPow] using h - omega - have hmhi' : m < 2 ^ 24 := by simpa [EVM.twoPow] using hmhi - have hmod24 : w.toNat % 2 ^ 24 = m := hmdef'.symm - rw [← Nat.mod_mod_of_dvd (a := w.toNat) (show 2 ^ 23 ∣ 2 ^ 24 by norm_num)] - rw [hmod24] - rw [Nat.mod_eq_sub_mod hge] - rw [Nat.mod_eq_of_lt (by omega : m - 2 ^ 23 < 2 ^ 23)] - rw [hmod23] - norm_num [UInt256.size, EVM.twoPow] at h hmhi ⊢ - omega - -private theorem wordOfInt_neg_toNat (i : Int) (hneg : i < 0) - (hle : i.natAbs < EVM.wordModulus) : - (EVM.wordOfInt i).toNat = UInt256.size - i.natAbs := by - have hdiffPos : i.natAbs ≠ 0 := by - intro h - have : i = 0 := by omega - omega - have hpos : 0 < i.natAbs := Nat.pos_of_ne_zero hdiffPos - unfold EVM.wordOfInt - rw [if_pos hneg] - rw [Nat.mod_eq_of_lt hle, if_neg hdiffPos] - change (UInt256.ofNat (EVM.wordModulus - i.natAbs)).toNat = UInt256.size - i.natAbs - rw [ulit_toNat'] - · rw [show EVM.wordModulus = UInt256.size by native_decide] - · rw [show EVM.wordModulus = UInt256.size by native_decide] - exact Nat.sub_lt (by native_decide : 0 < UInt256.size) hpos - -private theorem int_ediv_pow128_natAbs_of_neg (i : Int) (hneg : i < 0) : - (i / (2 ^ 128 : Int)).natAbs = (i.natAbs - 1) / 2 ^ 128 + 1 := by - have hq0 : i / (340282366920938463463374607431768211456 : Int) = - -((-i - 1) / (340282366920938463463374607431768211456 : Int) + 1) := by - simpa using Int.ediv_of_neg_of_pos (a := i) - (b := (340282366920938463463374607431768211456 : Int)) hneg (by norm_num) - have hq : i / (2 ^ 128 : Int) = -((((i.natAbs - 1) / 2 ^ 128 : Nat) : Int) + 1) := by - norm_num - rw [hq0] - have hnum : -i - 1 = ((i.natAbs - 1 : Nat) : Int) := by - have habs : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - omega - rw [hnum] - have hdivNatCast : - (((i.natAbs - 1) / 340282366920938463463374607431768211456 : Nat) : Int) = - ((i.natAbs - 1 : Nat) : Int) / - (340282366920938463463374607431768211456 : Int) := by - rw [Int.natCast_ediv] - norm_num - rw [← hdivNatCast] - ring - rw [hq] - omega - -private theorem u256_complement_toNat_of_lt (w : UInt256) - (h : w.toNat < UInt256.size - 1) : - (UInt256.complement w).toNat = UInt256.size - (w.toNat + 1) := by - change (UInt256.sub (⟨0⟩ : UInt256) (w + ⟨1⟩)).toNat = _ - have hadd : (w + ⟨1⟩).toNat = w.toNat + 1 := by - rw [uadd_toNat] - change (w.toNat + 1) % UInt256.size = w.toNat + 1 - exact Nat.mod_eq_of_lt (by omega) - have hpos : (⟨0⟩ : UInt256).toNat < (w + ⟨1⟩).toNat := by - rw [hadd] - change 0 < w.toNat + 1 - omega - rw [usub_toNat_underflow (a := (⟨0⟩ : UInt256)) (b := w + ⟨1⟩) hpos, hadd] - change UInt256.size + 0 - (w.toNat + 1) = UInt256.size - (w.toNat + 1) - rfl - -private theorem u256_complement_toNat_of_toNat_eq_size_sub (w : UInt256) (n : Nat) - (hpos : 0 < n) (hlt : n < UInt256.size) (hw : w.toNat = UInt256.size - n) : - (UInt256.complement w).toNat = n - 1 := by - by_cases hn1 : n = 1 - · subst hn1 - have hwtop : w.toNat = UInt256.size - 1 := by simpa using hw - change (UInt256.sub (⟨0⟩ : UInt256) (w + ⟨1⟩)).toNat = 0 - have hadd : (w + ⟨1⟩).toNat = 0 := by - rw [uadd_toNat, hwtop] - change (UInt256.size - 1 + 1) % UInt256.size = 0 - rw [show UInt256.size - 1 + 1 = UInt256.size by omega] - exact Nat.mod_self _ - rw [usub_toNat (a := (⟨0⟩ : UInt256)) (b := w + ⟨1⟩) (by rw [hadd]; rfl), - hadd] - rfl - · have hltw : w.toNat < UInt256.size - 1 := by - rw [hw] - omega - rw [u256_complement_toNat_of_lt w hltw] - rw [hw] - have hsum : UInt256.size - n + 1 = UInt256.size - (n - 1) := by omega - rw [hsum] - omega - -private theorem sar128_wordOfInt_nonneg (i : Int) - (h0 : 0 ≤ i) (hlt : i < (2 ^ 255 : Int)) : - UInt256.sar ⟨128⟩ (EVM.wordOfInt i) = EVM.wordOfInt (i / (2 ^ 128 : Int)) := by - apply u256_inj - rw [wordOfInt_nonneg i h0] - have hdiv0 : 0 ≤ i / (2 ^ 128 : Int) := Int.ediv_nonneg h0 (by norm_num) - rw [wordOfInt_nonneg (i / (2 ^ 128 : Int)) hdiv0] - unfold UInt256.sar - have hwordNat : (EVM.word i.toNat).toNat = i.toNat := by - unfold EVM.word EVM.uintN UInt256.toNat - change i.toNat % EVM.twoPow 256 = i.toNat - apply Nat.mod_eq_of_lt - have hltNat : i.toNat < EVM.twoPow 255 := - (Int.toNat_lt h0).2 (by simpa [EVM.twoPow] using hlt) - norm_num [EVM.twoPow] at hltNat ⊢ - omega - have hslt : UInt256.sltBool (EVM.word i.toNat) ⟨0⟩ = false := by - unfold UInt256.sltBool - rw [hwordNat] - have hltNat : i.toNat < 2 ^ 255 := (Int.toNat_lt h0).2 hlt - rw [if_neg (by omega : ¬ 2 ^ 255 ≤ i.toNat)] - rw [decide_eq_false (show ¬ EVM.word i.toNat < (⟨0⟩ : UInt256) from - not_lt_of_ge (Nat.zero_le _))] - simp - rw [hslt] - change (UInt256.shiftRight (EVM.word i.toNat) ⟨128⟩).toNat = - (EVM.word (i / 2 ^ 128).toNat).toNat - unfold UInt256.shiftRight - rw [if_neg (by decide : ¬ (⟨128⟩ : UInt256).val ≥ 256)] - unfold UInt256.toNat - rw [Fin.shiftRight_val] - rw [Nat.shiftRight_eq_div_pow] - have hleft : (EVM.word i.toNat).val.val = i.toNat := by - simpa [UInt256.toNat] using hwordNat - rw [hleft] - have hdivNat : (i / (2 ^ 128 : Int)).toNat = i.toNat / 2 ^ 128 := by - apply Int.ofNat_inj.mp - rw [Int.toNat_of_nonneg hdiv0] - rw [Int.natCast_ediv] - rw [Int.toNat_of_nonneg h0] - norm_num - have hdivNatLiteral : - (i / (340282366920938463463374607431768211456 : Int)).toNat = - i.toNat / 2 ^ 128 := by - simpa using hdivNat - simp only [EVM.word, EVM.uintN] - change i.toNat / 2 ^ (128 % UInt256.size) = - (i / (340282366920938463463374607431768211456 : Int)).toNat % EVM.twoPow 256 - rw [hdivNatLiteral] - have hltNat : i.toNat < EVM.twoPow 255 := - (Int.toNat_lt h0).2 (by simpa [EVM.twoPow] using hlt) - have hltDiv : i.toNat / 2 ^ 128 < EVM.twoPow 256 := by - exact lt_of_le_of_lt (Nat.div_le_self _ _) (lt_trans hltNat (by norm_num [EVM.twoPow])) - rw [Nat.mod_eq_of_lt hltDiv] - norm_num [UInt256.size] - -private theorem sar128_wordOfInt_neg (i : Int) - (hneg : i < 0) (hge : -(2 ^ 255 : Int) ≤ i) : - UInt256.sar ⟨128⟩ (EVM.wordOfInt i) = EVM.wordOfInt (i / (2 ^ 128 : Int)) := by - apply u256_inj - have hnpos : 0 < i.natAbs := by - have : i ≠ 0 := by omega - exact Int.natAbs_pos.mpr this - have hnlt : i.natAbs < UInt256.size := by - have habs : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - have : (i.natAbs : Int) ≤ 2 ^ 255 := by - rw [habs] - omega - norm_num [UInt256.size] at this ⊢ - omega - have hw : (EVM.wordOfInt i).toNat = UInt256.size - i.natAbs := by - exact wordOfInt_neg_toNat i hneg (by simpa [EVM.wordModulus] using hnlt) - unfold UInt256.sar - have hslt : UInt256.sltBool (EVM.wordOfInt i) ⟨0⟩ = true := by - unfold UInt256.sltBool - rw [hw] - have hsign : 2 ^ 255 ≤ UInt256.size - i.natAbs := by - have habs : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - have : (i.natAbs : Int) ≤ 2 ^ 255 := by - rw [habs] - omega - norm_num [UInt256.size] at this ⊢ - omega - rw [if_pos hsign] - rw [if_neg (by norm_num : ¬ (⟨0⟩ : UInt256).toNat ≥ 2 ^ 255)] - rw [hslt] - simp only [if_true] - change (UInt256.complement - (UInt256.shiftRight (UInt256.complement (EVM.wordOfInt i)) ⟨128⟩)).toNat = - (EVM.wordOfInt (i / (2 ^ 128 : Int))).toNat - let n := i.natAbs - have hcomp : (UInt256.complement (EVM.wordOfInt i)).toNat = n - 1 := by - dsimp [n] - exact u256_complement_toNat_of_toNat_eq_size_sub (EVM.wordOfInt i) i.natAbs - hnpos hnlt hw - have hshift : - (UInt256.shiftRight (UInt256.complement (EVM.wordOfInt i)) ⟨128⟩).toNat = - (n - 1) / 2 ^ 128 := by - unfold UInt256.shiftRight - rw [if_neg (by decide : ¬ (⟨128⟩ : UInt256).val ≥ 256)] - unfold UInt256.toNat - rw [Fin.shiftRight_val] - rw [Nat.shiftRight_eq_div_pow] - rw [show (UInt256.complement (EVM.wordOfInt i)).val.val = - (UInt256.complement (EVM.wordOfInt i)).toNat by rfl] - rw [hcomp] - norm_num [UInt256.size] - let m := (n - 1) / 2 ^ 128 - have hmSmall : m < UInt256.size - 1 := by - dsimp [m, n] - have hle : (i.natAbs - 1) / 2 ^ 128 ≤ i.natAbs - 1 := Nat.div_le_self _ _ - omega - have hcomp2 : - (UInt256.complement - (UInt256.shiftRight (UInt256.complement (EVM.wordOfInt i)) ⟨128⟩)).toNat = - UInt256.size - (m + 1) := by - rw [u256_complement_toNat_of_lt - (UInt256.shiftRight (UInt256.complement (EVM.wordOfInt i)) ⟨128⟩)] - · rw [hshift] - · rw [hshift] - exact hmSmall - rw [hcomp2] - have hquotNeg : i / (2 ^ 128 : Int) < 0 := by - exact Int.ediv_neg_of_neg_of_pos hneg (by norm_num) - have hqAbs : (i / (2 ^ 128 : Int)).natAbs = m + 1 := by - simpa [m, n] using int_ediv_pow128_natAbs_of_neg i hneg - have hqLt : (i / (2 ^ 128 : Int)).natAbs < EVM.wordModulus := by - rw [hqAbs] - dsimp [m, n] - have hle : (i.natAbs - 1) / 2 ^ 128 ≤ i.natAbs - 1 := Nat.div_le_self _ _ - have hmod : i.natAbs < EVM.wordModulus := by - simpa [EVM.wordModulus] using hnlt - omega - rw [wordOfInt_neg_toNat (i / (2 ^ 128 : Int)) hquotNeg hqLt] - rw [hqAbs] - -theorem sar128_wordOfInt (i : Int) - (hge : -(2 ^ 255 : Int) ≤ i) (hlt : i < 2 ^ 255) : - UInt256.sar ⟨128⟩ (EVM.wordOfInt i) = EVM.wordOfInt (i / (2 ^ 128 : Int)) := by - by_cases h0 : 0 ≤ i - · exact sar128_wordOfInt_nonneg i h0 hlt - · exact sar128_wordOfInt_neg i (by omega) hge - -private theorem tickSpacingSint24Value_wordOfInt (i : Int) - (hge : -(2 ^ 23) ≤ i) (hlt : i < 2 ^ 23) : - tickSpacingSint24Value (EVM.wordOfInt i) = i := by - unfold tickSpacingSint24Value - by_cases h0 : 0 ≤ i - · have hword : EVM.wordOfInt i = EVM.word i.toNat := wordOfInt_nonneg i h0 - rw [hword] - have hltNat : i.toNat < EVM.twoPow 23 := by - exact (Int.toNat_lt h0).2 (by simpa [EVM.twoPow] using hlt) - have hto : (EVM.word i.toNat).toNat = i.toNat := by - unfold EVM.word EVM.uintN UInt256.toNat - simp only - show i.toNat % EVM.twoPow 256 = i.toNat - rw [Nat.mod_eq_of_lt] - norm_num [EVM.twoPow, UInt256.size] at hltNat ⊢ - omega - rw [hto] - have hmod : i.toNat % EVM.twoPow 24 = i.toNat := by - apply Nat.mod_eq_of_lt - norm_num [EVM.twoPow] at hltNat ⊢ - omega - rw [hmod] - rw [if_pos] - · exact Int.toNat_of_nonneg h0 - · simpa [EVM.twoPow] using hltNat - · have hneg : i < 0 := by omega - have hrle : i.natAbs ≤ EVM.twoPow 23 := by - have habs : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - have : (i.natAbs : Int) ≤ (EVM.twoPow 23 : Int) := by - rw [habs] - norm_num [EVM.twoPow] at hge ⊢ - omega - omega - have hrpos : 0 < i.natAbs := by - by_contra hz - have : i.natAbs = 0 := by omega - have : i = 0 := by omega - omega - have hword := wordOfInt_neg_toNat i hneg (by - exact lt_of_le_of_lt hrle (by native_decide : EVM.twoPow 23 < EVM.wordModulus)) - rw [hword] - let r := i.natAbs - have hrle' : r ≤ EVM.twoPow 23 := by simpa [r] using hrle - have hrle24 : r ≤ EVM.twoPow 24 := le_trans hrle' (by native_decide) - have hrpos' : 0 < r := by simpa [r] using hrpos - have hmodm : (UInt256.size - r) % EVM.twoPow 24 = EVM.twoPow 24 - r := by - have hEq : UInt256.size - r = - (UInt256.size - EVM.twoPow 24) + (EVM.twoPow 24 - r) := by - norm_num [UInt256.size, EVM.twoPow] at hrle24 ⊢ - omega - rw [hEq, Nat.add_mod] - have hdiv : (UInt256.size - EVM.twoPow 24) % EVM.twoPow 24 = 0 := by - native_decide - have hltSub : EVM.twoPow 24 - r < EVM.twoPow 24 := by omega - rw [hdiv, Nat.zero_add] - rw [Nat.mod_eq_of_lt hltSub] - rw [Nat.mod_eq_of_lt hltSub] - rw [hmodm] - rw [if_neg] - · have habs : (r : Int) = -i := by - dsimp [r] - exact Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [EVM.twoPow] at hrle' ⊢ - omega - · norm_num [EVM.twoPow] at hrle' hrpos' ⊢ - omega - -theorem signextend_two_wordOfInt_tickSpacing (i : Int) - (hge : -(2 ^ 23) ≤ i) (hlt : i < 2 ^ 23) : - UInt256.signextend ⟨2⟩ (EVM.wordOfInt i) = EVM.wordOfInt i := by - rw [← wordOfInt_sint24Value_eq_signextend_two (EVM.wordOfInt i)] - rw [tickSpacingSint24Value_wordOfInt i hge hlt] - -theorem wordToElem_int24_wordOfInt (i : Int) - (hge : -(2 ^ 23) ≤ i) (hlt : i < 2 ^ 23) : - wordToElem (.int int24Int) (EVM.wordOfInt i) = .int i := by - unfold wordToElem int24Int - change Value.int (tickSpacingSint24Value (EVM.wordOfInt i)) = .int i - rw [tickSpacingSint24Value_wordOfInt i hge hlt] - -theorem wordOfInt_int24_inj {i j : Int} - (hige : -(2 ^ 23) ≤ i) (hilt : i < 2 ^ 23) - (hjge : -(2 ^ 23) ≤ j) (hjlt : j < 2 ^ 23) - (h : EVM.wordOfInt i = EVM.wordOfInt j) : - i = j := by - have hdecoded := congrArg (wordToElem (.int int24Int)) h - rw [wordToElem_int24_wordOfInt i hige hilt, - wordToElem_int24_wordOfInt j hjge hjlt] at hdecoded - exact Value.int.inj hdecoded - --- LIBRARY CANDIDATE: signed comparison of a bounded `wordOfInt` with zero. -theorem slt_wordOfInt_int24_zero (i : Int) - (hge : -(2 ^ 23 : Int) ≤ i) (hlt : i < 2 ^ 23) : - UInt256.slt (EVM.wordOfInt i) ⟨0⟩ = if i < 0 then ⟨1⟩ else ⟨0⟩ := by - by_cases hneg : i < 0 - · rw [if_pos hneg] - apply slt_lit_one_high (m := 0) - · norm_num - · have hto := wordOfInt_neg_toNat i hneg (by - have hle : i.natAbs ≤ EVM.twoPow 23 := by - have habs : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [EVM.twoPow] at hge ⊢ - omega - exact lt_of_le_of_lt hle (by native_decide : EVM.twoPow 23 < EVM.wordModulus)) - rw [hto] - have hle : i.natAbs ≤ 2 ^ 23 := by - have habs : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - norm_num at hge ⊢ - omega - norm_num [UInt256.size] at hle ⊢ - omega - · rw [if_neg hneg] - have h0 : 0 ≤ i := by omega - rw [wordOfInt_nonneg i h0] - apply slt_lit_zero (m := 0) - · norm_num - · simp - · have hltNat : i.toNat < 2 ^ 23 := (Int.toNat_lt h0).2 hlt - unfold EVM.word EVM.uintN UInt256.toNat - simp only - rw [Nat.mod_eq_of_lt] - · exact lt_trans hltNat (by norm_num) - · exact lt_trans hltNat (by norm_num [EVM.twoPow]) - --- LIBRARY CANDIDATE: negating a bounded negative signed integer as an EVM word. -theorem zero_sub_wordOfInt_int24_neg (i : Int) - (hneg : i < 0) (hge : -(2 ^ 23 : Int) ≤ i) : - UInt256.sub ⟨0⟩ (EVM.wordOfInt i) = EVM.wordOfInt (-i) := by - apply u256_inj - have hleAbs : i.natAbs ≤ EVM.twoPow 23 := by - have habs : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [EVM.twoPow] at hge ⊢ - omega - have hword := wordOfInt_neg_toNat i hneg - (lt_of_le_of_lt hleAbs (by native_decide : EVM.twoPow 23 < EVM.wordModulus)) - have hwordPos : 0 < (EVM.wordOfInt i).toNat := by - rw [hword] - have hpos : 0 < i.natAbs := by - have : i ≠ 0 := by omega - exact Int.natAbs_pos.mpr this - norm_num [UInt256.size] at hleAbs ⊢ - omega - rw [usub_toNat_underflow (a := (⟨0⟩ : UInt256)) (b := EVM.wordOfInt i) hwordPos] - rw [hword] - have hnegNonneg : 0 ≤ -i := by omega - rw [wordOfInt_nonneg (-i) hnegNonneg] - unfold EVM.word EVM.uintN UInt256.toNat - simp only - rw [Nat.mod_eq_of_lt] - · have habs : (-i).toNat = i.natAbs := by omega - rw [habs] - norm_num [UInt256.size] at hleAbs ⊢ - omega - · have habs : (-i).toNat = i.natAbs := by omega - rw [habs] - exact lt_of_le_of_lt hleAbs (by native_decide : EVM.twoPow 23 < EVM.twoPow 256) - -theorem wordOfInt_nonneg_toNat_lt_wordModulus (i : Int) - (h0 : 0 ≤ i) (hlt : i < EVM.wordModulus) : - (EVM.wordOfInt i).toNat = i.toNat := by - rw [wordOfInt_nonneg i h0] - unfold EVM.word EVM.uintN UInt256.toNat - simp only - rw [Nat.mod_eq_of_lt] - exact (Int.toNat_lt h0).2 hlt - -theorem wordOfInt_neg_toNat_lt_wordModulus (i : Int) - (hneg : i < 0) (hlt : i.natAbs < EVM.wordModulus) : - (EVM.wordOfInt i).toNat = UInt256.size - i.natAbs := by - exact wordOfInt_neg_toNat i hneg hlt - -theorem tickSpacingSint24Value_ge (w : UInt256) : - -(2 ^ 23 : Int) ≤ tickSpacingSint24Value w := by - unfold tickSpacingSint24Value - by_cases h : w.toNat % EVM.twoPow 24 < EVM.twoPow 23 - · rw [if_pos h] - exact le_trans (by norm_num : -(2 ^ 23 : Int) ≤ 0) (Int.natCast_nonneg _) - · rw [if_neg h] - have hmhi := Nat.mod_lt w.toNat (by norm_num [EVM.twoPow] : 0 < EVM.twoPow 24) - norm_num [EVM.twoPow] at h hmhi ⊢ - omega - -theorem tickSpacingSint24Value_lt (w : UInt256) : - tickSpacingSint24Value w < (2 ^ 23 : Int) := by - unfold tickSpacingSint24Value - by_cases h : w.toNat % EVM.twoPow 24 < EVM.twoPow 23 - · rw [if_pos h] - norm_num [EVM.twoPow] at h ⊢ - omega - · rw [if_neg h] - have hmhi := Nat.mod_lt w.toNat (by norm_num [EVM.twoPow] : 0 < EVM.twoPow 24) - norm_num [EVM.twoPow] at h hmhi ⊢ - omega - -theorem signextend_two_tickSpacing_idempotent (w : UInt256) : - UInt256.signextend ⟨2⟩ (UInt256.signextend ⟨2⟩ w) = - UInt256.signextend ⟨2⟩ w := by - let i := tickSpacingSint24Value w - have hword : EVM.wordOfInt i = UInt256.signextend ⟨2⟩ w := by - simpa [i] using wordOfInt_sint24Value_eq_signextend_two w - rw [← hword] - exact signextend_two_wordOfInt_tickSpacing i (tickSpacingSint24Value_ge w) - (tickSpacingSint24Value_lt w) - -private theorem int24_natAbs_le {i : Int} - (hge : -(2 ^ 23 : Int) ≤ i) (hlt : i < 2 ^ 23) : - i.natAbs ≤ 2 ^ 23 := by - by_cases hneg : i < 0 - · have habs : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - norm_num at hge hlt ⊢ - omega - · have h0 : 0 ≤ i := by omega - have hcast : (i.natAbs : Int) ≤ 2 ^ 23 := by - have habs : (i.natAbs : Int) = i := Int.natAbs_of_nonneg h0 - rw [habs] - omega - exact_mod_cast hcast - --- LIBRARY CANDIDATE: signed comparison of two bounded `wordOfInt` int24 values. -theorem slt_wordOfInt_int24 (i j : Int) - (hige : -(2 ^ 23 : Int) ≤ i) (hilt : i < 2 ^ 23) - (hjge : -(2 ^ 23 : Int) ≤ j) (hjlt : j < 2 ^ 23) : - UInt256.slt (EVM.wordOfInt i) (EVM.wordOfInt j) = - if i < j then ⟨1⟩ else ⟨0⟩ := by - have hiAbsLe := int24_natAbs_le hige hilt - have hjAbsLe := int24_natAbs_le hjge hjlt - by_cases hi : i < 0 - · have hito := wordOfInt_neg_toNat_lt_wordModulus i hi (by - exact lt_of_le_of_lt hiAbsLe (by native_decide : 2 ^ 23 < EVM.wordModulus)) - have hiHigh : 2 ^ 255 ≤ (EVM.wordOfInt i).toNat := by - rw [hito] - norm_num [UInt256.size] at hiAbsLe ⊢ - omega - by_cases hj : j < 0 - · have hjto := wordOfInt_neg_toNat_lt_wordModulus j hj (by - exact lt_of_le_of_lt hjAbsLe (by native_decide : 2 ^ 23 < EVM.wordModulus)) - have hjHigh : 2 ^ 255 ≤ (EVM.wordOfInt j).toNat := by - rw [hjto] - norm_num [UInt256.size] at hjAbsLe ⊢ - omega - unfold UInt256.slt UInt256.sltBool UInt256.fromBool Bool.toUInt256 - rw [if_pos hiHigh, if_pos hjHigh] - by_cases hij : i < j - · rw [if_pos hij] - have hword : EVM.wordOfInt i < EVM.wordOfInt j := by - show (EVM.wordOfInt i).toNat < (EVM.wordOfInt j).toNat - rw [hito, hjto] - have habsI : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - have habsJ : (j.natAbs : Int) = -j := Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [UInt256.size] at hiAbsLe hjAbsLe ⊢ - omega - rw [if_pos (decide_eq_true hword)] - rfl - · rw [if_neg hij] - have hword : ¬ EVM.wordOfInt i < EVM.wordOfInt j := by - intro hword - have hnat : (EVM.wordOfInt i).toNat < (EVM.wordOfInt j).toNat := hword - rw [hito, hjto] at hnat - have habsI : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - have habsJ : (j.natAbs : Int) = -j := Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [UInt256.size] at hiAbsLe hjAbsLe hnat - omega - rw [if_neg (by rw [decide_eq_false hword]; decide)] - rfl - · have hj0 : 0 ≤ j := by omega - have hjto := wordOfInt_nonneg_toNat_lt_wordModulus j hj0 (by - exact lt_of_lt_of_le hjlt (by native_decide : (2 ^ 23 : Int) ≤ EVM.wordModulus)) - have hjLow : (EVM.wordOfInt j).toNat < 2 ^ 255 := by - rw [hjto] - have hjNatLt : j.toNat < 2 ^ 23 := (Int.toNat_lt hj0).2 hjlt - norm_num at hjNatLt ⊢ - omega - rw [if_pos (by omega : i < j)] - unfold UInt256.slt UInt256.sltBool UInt256.fromBool Bool.toUInt256 - rw [if_pos hiHigh, if_neg (by omega : ¬ (EVM.wordOfInt j).toNat ≥ 2 ^ 255)] - rfl - · have hi0 : 0 ≤ i := by omega - have hito := wordOfInt_nonneg_toNat_lt_wordModulus i hi0 (by - exact lt_of_lt_of_le hilt (by native_decide : (2 ^ 23 : Int) ≤ EVM.wordModulus)) - have hiLow : (EVM.wordOfInt i).toNat < 2 ^ 255 := by - rw [hito] - have hiNatLt : i.toNat < 2 ^ 23 := (Int.toNat_lt hi0).2 hilt - norm_num at hiNatLt ⊢ - omega - by_cases hj : j < 0 - · have hjto := wordOfInt_neg_toNat_lt_wordModulus j hj (by - exact lt_of_le_of_lt hjAbsLe (by native_decide : 2 ^ 23 < EVM.wordModulus)) - have hjHigh : 2 ^ 255 ≤ (EVM.wordOfInt j).toNat := by - rw [hjto] - norm_num [UInt256.size] at hjAbsLe ⊢ - omega - rw [if_neg (by omega : ¬ i < j)] - unfold UInt256.slt UInt256.sltBool UInt256.fromBool Bool.toUInt256 - rw [if_neg (by omega : ¬ (EVM.wordOfInt i).toNat ≥ 2 ^ 255), if_pos hjHigh] - rfl - · have hj0 : 0 ≤ j := by omega - have hjto := wordOfInt_nonneg_toNat_lt_wordModulus j hj0 (by - exact lt_of_lt_of_le hjlt (by native_decide : (2 ^ 23 : Int) ≤ EVM.wordModulus)) - have hjLow : (EVM.wordOfInt j).toNat < 2 ^ 255 := by - rw [hjto] - have hjNatLt : j.toNat < 2 ^ 23 := (Int.toNat_lt hj0).2 hjlt - norm_num at hjNatLt ⊢ - omega - unfold UInt256.slt UInt256.sltBool UInt256.fromBool Bool.toUInt256 - rw [if_neg (by omega : ¬ (EVM.wordOfInt i).toNat ≥ 2 ^ 255), - if_neg (by omega : ¬ (EVM.wordOfInt j).toNat ≥ 2 ^ 255)] - by_cases hij : i < j - · rw [if_pos hij] - have hword : EVM.wordOfInt i < EVM.wordOfInt j := by - show (EVM.wordOfInt i).toNat < (EVM.wordOfInt j).toNat - rw [hito, hjto] - omega - rw [if_pos (decide_eq_true hword)] - rfl - · rw [if_neg hij] - have hword : ¬ EVM.wordOfInt i < EVM.wordOfInt j := by - intro hword - have hnat : (EVM.wordOfInt i).toNat < (EVM.wordOfInt j).toNat := hword - rw [hito, hjto] at hnat - omega - rw [if_neg (by rw [decide_eq_false hword]; decide)] - rfl - --- LIBRARY CANDIDATE: `SGT a b` is signed `SLT b a`. -theorem sgt_eq_slt_swap (a b : UInt256) : - UInt256.sgt a b = UInt256.slt b a := by - unfold UInt256.sgt UInt256.slt UInt256.sgtBool UInt256.sltBool UInt256.fromBool - Bool.toUInt256 - by_cases ha : a.toNat ≥ 2 ^ 255 <;> by_cases hb : b.toNat ≥ 2 ^ 255 - · rw [if_pos ha, if_pos hb, if_pos hb, if_pos ha] - · rw [if_pos ha, if_neg hb, if_neg hb, if_pos ha] - · rw [if_neg ha, if_pos hb, if_pos hb, if_neg ha] - · rw [if_neg ha, if_neg hb, if_neg hb, if_neg ha] - -theorem zero_sub_wordOfInt_int24_neg_toNat (i : Int) - (hneg : i < 0) (hge : -(2 ^ 23 : Int) ≤ i) : - (UInt256.sub ⟨0⟩ (EVM.wordOfInt i)).toNat = (-i).toNat := by - have hleAbs : i.natAbs ≤ EVM.twoPow 23 := by - have habs : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [EVM.twoPow] at hge ⊢ - omega - have hword := wordOfInt_neg_toNat i hneg - (lt_of_le_of_lt hleAbs (by native_decide : EVM.twoPow 23 < EVM.wordModulus)) - have hwordPos : 0 < (EVM.wordOfInt i).toNat := by - rw [hword] - have hpos : 0 < i.natAbs := by - have : i ≠ 0 := by omega - exact Int.natAbs_pos.mpr this - norm_num [UInt256.size] at hleAbs ⊢ - omega - rw [usub_toNat_underflow (a := (⟨0⟩ : UInt256)) (b := EVM.wordOfInt i) hwordPos] - rw [hword] - have habs : (-i).toNat = i.natAbs := by omega - rw [habs] - norm_num [UInt256.size] at hleAbs ⊢ - omega - -theorem int24ReturnEncodingInt (i : Int) (hge : -(2 ^ 23) ≤ i) (hlt : i < 2 ^ 23) : - encodeReturnValue? int24 (.int i) = some (UInt256.toByteArray (EVM.wordOfInt i)) := by - have hge' : -(Int.ofNat (EVM.twoPow 23)) ≤ i := by - simpa [EVM.twoPow] using hge - have hlt' : i < Int.ofNat (EVM.twoPow 23) := by - simpa [EVM.twoPow] using hlt - refine scalarReturnEncoding (t := (.int (.sint ⟨24, by decide⟩))) - (w := EVM.wordOfInt i) rfl ?_ ?_ - · simp only [abiTupleHeadSize?, staticABIEncodedSize?, isDynamicABIType, bind, Option.bind] - decide - · simp only [encodeABIValue?, encodeABIWord?] - rw [if_neg (by decide : 24 ≠ 0)] - rw [if_pos] - · rfl - · constructor - · simpa [EVM.twoPow] using hge - · simpa [EVM.twoPow] using hlt - -private theorem uniswapV3PoolPatchPreservesJumpDest10491 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨10491⟩ 0 = true := by - native_decide - -theorem uniswapV3PoolJumpDestPatched10491 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10491⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest10491 - -theorem uniswapV3PoolTickSpacingReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 20 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨2009⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 20 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0xd0 0xc9 0x3a 0x7c - (uniswapV3PoolSelNat 20) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h43 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨43⟩) hpatch h32 hgt32 - have hgt43 : UInt256.gt (armSelNat code ⟨43⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h54 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨54⟩) hpatch h43 hgt43 - have hgt54 : UInt256.gt (armSelNat code ⟨54⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h114 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨114⟩) hpatch h54 hgt54 - have hmiss19 : (uniswapV3PoolSelBytes 19 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h125 := uniswapV3PoolSelectorArmMissToOf (i := 19) (next := ⟨125⟩) - hpatch hsz hmiss19 h114 - have h2009 := uniswapV3PoolSelectorArmHitTo (i := 20) (target := ⟨2009⟩) - hpatch hsz hsel h125 - exact ⟨_, _, h2009⟩ - -theorem uniswapV3PoolTickSpacingDecode {v : PoolImmutables} {I : ExecutionEnv} - (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - ((tickspacingTransition v).params.map Param.name) - (transitionSignature (tickspacingTransition v)).paramTypes I.calldata = - some (∅ : Store) := by - simpa [config, tickspacingTransition, transitionSignature] using - decodeCalldataWithMode_empty_ok (mode := DecodeMode.legacySolc05) (cd := I.calldata) hsz - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolDispatch_tickSpacing {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 20 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some (tickspacingTransition v) := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, - factoryTransition v, feeTransition v, feegrowthglobal0X128Transition, - feegrowthglobal1X128Transition, flashTransition v, - increaseobservationcardinalitynextTransition v, initializeTransition, liquidityTransition, - maxliquiditypertickTransition v, mintTransition v, observationsTransition, observeTransition v, - positionsTransition, protocolfeesTransition, setfeeprotocolTransition v, slot0Transition, - snapshotcumulativesinsideTransition v, swapTransition v, tickbitmapTransition]) - (post := [ticksTransition, token0Transition v, token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 20) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 20) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 20) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 20) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 20) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 20) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 20) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 20) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 5) (j := 20) - (by native_decide) hsel - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 25) (j := 20) - (by native_decide) hsel - · rw [selectorOf, liquiditySelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 2) (j := 20) - (by native_decide) hsel - · rw [selectorOf, maxLiquidityPerTickSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 13) (j := 20) - (by native_decide) hsel - · rw [selectorOf, mintSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 7) (j := 20) - (by native_decide) hsel - · rw [selectorOf, observationsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 4) (j := 20) - (by native_decide) hsel - · rw [selectorOf, observeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 16) (j := 20) - (by native_decide) hsel - · rw [selectorOf, positionsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 11) (j := 20) - (by native_decide) hsel - · rw [selectorOf, protocolFeesSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 3) (j := 20) - (by native_decide) hsel - · rw [selectorOf, setFeeProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 14) (j := 20) - (by native_decide) hsel - · rw [selectorOf, slot0SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 6) (j := 20) - (by native_decide) hsel - · rw [selectorOf, snapshotCumulativesInsideSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 18) (j := 20) - (by native_decide) hsel - · rw [selectorOf, swapSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 1) (j := 20) - (by native_decide) hsel - · rw [selectorOf, tickBitmapSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 12) (j := 20) - (by native_decide) hsel - · rw [selectorOf, tickSpacingSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hsel - -theorem uniswapV3PoolTickSpacingPatchWord {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - code.extract 10493 10525 = UInt256.toByteArray (EVM.wordOfInt v.tickSpacing) := by - let value := UInt256.toByteArray (EVM.wordOfInt v.tickSpacing) - let pre : List (Nat × ByteArray) := - [(8315, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (8829, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (10457, UInt256.toByteArray (EVM.Word.ofNat v.factory.toNat)), - (2258, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4853, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (6740, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (7822, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (9150, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (15650, UInt256.toByteArray (EVM.Word.ofNat v.token0.toNat)), - (4551, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (6789, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (7924, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (9284, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (10529, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (15979, UInt256.toByteArray (EVM.Word.ofNat v.token1.toNat)), - (3311, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6603, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (6658, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (10565, UInt256.toByteArray (EVM.wordOfInt v.fee)), - (3072, value)] - let post : List (Nat × ByteArray) := - [(19402, value), (19452, value), - (8174, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19295, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (19350, UInt256.toByteArray (EVM.wordOfInt v.maxLiquidityPerTick)), - (11259, UInt256.toByteArray (EVM.Word.ofNat v.original.toNat))] - have hpatch' : patchRuntime uniswapV3PoolBytecode (pre ++ (10493, value) :: post) = - some code := by - dsimp [pre, post, value] - simpa [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup, - toByteArray_eq_toBytesBE] using hpatch - have hpost : ∀ p ∈ post, 10493 + 32 ≤ p.1 ∨ p.1 + 32 ≤ 10493 := by - intro p hp - dsimp [post] at hp - simp at hp - rcases hp with rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - have hsize : value.size = 32 := by - dsimp [value] - exact toByteArray_size _ - exact patchRuntime_extract_patch hsize hpost hpatch' - -theorem uniswapV3PoolTickSpacingConstDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10492⟩ = some (.Push .PUSH32, some (EVM.wordOfInt v.tickSpacing, 32)) := by - have hsize := uniswapV3PoolPatchedSize hpatch - have hget : code.get? ({ val := 10492 } : UInt256).toNat = - uniswapV3PoolBytecode.get? ({ val := 10492 } : UInt256).toNat := by - change code.get? 10492 = uniswapV3PoolBytecode.get? 10492 - apply get?_eq_of_extract_one - · rw [hsize] - native_decide - · native_decide - · exact patchRuntime_extract_eq (start := 10492) (stop := 10493) - (template := uniswapV3PoolBytecode) (out := code) (ps := patches v) - (by omega) (by native_decide) - (fun p hp => by - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, - List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl - all_goals omega) hpatch - have hextract : code.extract' ({ val := 10492 } : UInt256).toNat.succ - (({ val := 10492 } : UInt256).toNat.succ + 32) = - UInt256.toByteArray (EVM.wordOfInt v.tickSpacing) := by - change code.extract' 10493 10525 = UInt256.toByteArray (EVM.wordOfInt v.tickSpacing) - unfold ByteArray.extract' - have hguard : (decide (10493 < 2 ^ 64) && decide (10525 < 2 ^ 64)) = true := by - native_decide - rw [if_pos hguard] - exact uniswapV3PoolTickSpacingPatchWord hpatch - have hgetSome : code.get? ({ val := 10492 } : UInt256).toNat = some 0x7f := by - rw [hget] - native_decide - have hparse : (some (0x7f : UInt8) >>= parseInstr) = some (.Push .PUSH32) := by - native_decide - unfold decode - rw [hgetSome, hparse] - change some (Operation.Push Operation.POp.PUSH32, - some (uInt256OfByteArray - (code.extract' ({ val := 10492 } : UInt256).toNat.succ - (({ val := 10492 } : UInt256).toNat.succ + 32)), 32)) = - some (Operation.Push Operation.POp.PUSH32, some (EVM.wordOfInt v.tickSpacing, 32)) - rw [hextract, uInt256OfByteArray_eq, fromByteArrayBigEndian_toByteArray, u256_ofNat_toNat] - -theorem uniswapV3PoolTickSpacingGetterJumpdestDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10491⟩ = some (.JUMPDEST, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨10491⟩) (byte := 0x5b) - (op := .JUMPDEST) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 10492 ≤ p.1 ∨ p.1 + 32 ≤ 10491 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolTickSpacingGetterDupDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10525⟩ = some (.DUP2, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨10525⟩) (byte := 0x81) - (op := .DUP2) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 10526 ≤ p.1 ∨ p.1 + 32 ≤ 10525 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolTickSpacingGetterJumpDecode {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - decode code ⟨10526⟩ = some (.JUMP, .none) := by - refine uniswapV3PoolDecodePatchedNoArg (pc := ⟨10526⟩) (byte := 0x56) - (op := .JUMP) hpatch (by native_decide) ?_ (by native_decide) - (by native_decide) (by native_decide) - change ∀ p ∈ patches v, 10527 ≤ p.1 ∨ p.1 + 32 ≤ 10526 - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - all_goals omega - -theorem uniswapV3PoolTickSpacingEntryWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcGetterEntryWf code ⟨2009⟩ ⟨2017⟩ ⟨10491⟩ := by - dsimp [solcGetterEntryWf] - refine ⟨?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolTickSpacingGetterWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcConstGetterWf code ⟨10491⟩ (EVM.wordOfInt v.tickSpacing) 32 .PUSH32 := by - dsimp [solcConstGetterWf] - refine ⟨?_, ?_, ?_, ?_, ?_⟩ - · exact uniswapV3PoolTickSpacingGetterJumpdestDecode hpatch - · native_decide - · exact uniswapV3PoolTickSpacingConstDecode hpatch - · exact uniswapV3PoolTickSpacingGetterDupDecode hpatch - · exact uniswapV3PoolTickSpacingGetterJumpDecode hpatch - -private def tickSpacingStSignextend (s : State) (v : UInt256) (t : List UInt256) : State := - { s with - machineState.stack := v :: t, - machineState.gasAvailable := s.machineState.gasAvailable.subNat 5 - machineState.pc := s.machineState.pc + ⟨1⟩ - machineState.execLength := s.machineState.execLength + 1 } - -private theorem tickSpacingSignextendXstep {code : ByteArray} {s : State} {pc a b : UInt256} - {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pc) - (hdec : decode code pc = some (.SIGNEXTEND, .none)) - (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : - Xstep (D_J code 0) s = - if s.machineState.gasAvailable.toNat < 5 then .error .OutOfGass - else .ok (tickSpacingStSignextend s (UInt256.signextend a b) t, .none) := by - have hdecS : decode s.executionEnv.code s.machineState.pc = some (.SIGNEXTEND, .none) := by - rw [hcode, hpc] - exact hdec - have hstep := step_signextend s hdecS - have hnoOverflow : ¬ 1024 ≤ t.length := by omega - simpa [hcode, hstk, GasConstants.Glow, tickSpacingStSignextend, hnoOverflow] using hstep - -private theorem tickSpacingRDSignextend {code : ByteArray} {ee : ExecutionEnv} - {g : Sat256} {s0 : State} {pc : UInt256} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.SIGNEXTEND, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.signextend a b :: t) mem aw rdata acc - (k + 1) (C + 5) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, hee, - hworld⟩ - · exact Or.inl hoog - · have st := tickSpacingSignextendXstep hcode hpc hdec hstk hov - by_cases gg : g.toNat < C + 5 - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨tickSpacingStSignextend s (UInt256.signextend a b) t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, by omega, - by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [tickSpacingStSignextend]; exact hcode - · simp only [tickSpacingStSignextend]; rw [hpc] - · rfl - · simp only [tickSpacingStSignextend]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [tickSpacingStSignextend]; exact hmem - · simp only [tickSpacingStSignextend]; exact haw - · simp only [tickSpacingStSignextend]; exact hrdata - · simp only [tickSpacingStSignextend]; exact hacc - · exact hee - · exact hworld - -@[reducible] def solcReturnInt24FromMemWf (code : ByteArray) (pc : UInt256) : Prop := - let p1 := pc + ⟨1⟩ - let p3 := p1 + UInt256.ofNat 2 - let p4 := p3 + ⟨1⟩ - let p5 := p4 + ⟨1⟩ - let p7 := p5 + UInt256.ofNat 2 - let p8 := p7 + ⟨1⟩ - let p9 := p8 + ⟨1⟩ - let p10 := p9 + ⟨1⟩ - let p11 := p10 + ⟨1⟩ - let p12 := p11 + ⟨1⟩ - let p13 := p12 + ⟨1⟩ - let p14 := p13 + ⟨1⟩ - let p15 := p14 + ⟨1⟩ - let p16 := p15 + ⟨1⟩ - let p17 := p16 + ⟨1⟩ - let p18 := p17 + ⟨1⟩ - let p20 := p18 + UInt256.ofNat 2 - let p21 := p20 + ⟨1⟩ - let p22 := p21 + ⟨1⟩ - decode code pc = some (.JUMPDEST, .none) - ∧ decode code p1 = some (.Push .PUSH1, some (⟨64⟩, 1)) - ∧ decode code p3 = some (.DUP1, .none) - ∧ decode code p4 = some (.MLOAD, .none) - ∧ decode code p5 = some (.Push .PUSH1, some (⟨2⟩, 1)) - ∧ decode code p7 = some (.SWAP3, .none) - ∧ decode code p8 = some (.SWAP1, .none) - ∧ decode code p9 = some (.SWAP3, .none) - ∧ decode code p10 = some (.SIGNEXTEND, .none) - ∧ decode code p11 = some (.DUP3, .none) - ∧ decode code p12 = some (.MSTORE, .none) - ∧ decode code p13 = some (.MLOAD, .none) - ∧ decode code p14 = some (.SWAP1, .none) - ∧ decode code p15 = some (.DUP2, .none) - ∧ decode code p16 = some (.SWAP1, .none) - ∧ decode code p17 = some (.SUB, .none) - ∧ decode code p18 = some (.Push .PUSH1, some (⟨32⟩, 1)) - ∧ decode code p20 = some (.ADD, .none) - ∧ decode code p21 = some (.SWAP1, .none) - ∧ decode code p22 = some (.RETURN, .none) - -set_option maxHeartbeats 1000000 in -theorem RD.solcReturnInt24FromMem {code : ByteArray} {g : Sat256} {s0 : State} - {ee : ExecutionEnv} {k C : ℕ} {pc val ret : UInt256} {R : List UInt256} - {mem memout rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - (h : RD code ee g s0 pc (val :: ret :: R) mem (UInt256.ofNat 3) rdata acc k C) - (hwf : solcReturnInt24FromMemWf code pc) - (hmload64 : - (if (⟨64⟩ : UInt256).toNat ≥ mem.size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 3 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (mem.readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩) - (hmemout : - (UInt256.toByteArray (UInt256.signextend ⟨2⟩ val)).write 0 mem 128 32 = memout) - (hmemoutLoad64 : - (if (⟨64⟩ : UInt256).toNat ≥ memout.size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 5 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian (memout.readWithPadding (⟨64⟩ : UInt256).toNat 32))) - = ⟨128⟩) - (hread128 : - memout.readWithPadding 128 32 = UInt256.toByteArray (UInt256.signextend ⟨2⟩ val)) - (hov : R.length + 9 ≤ 1024) : - RDret code g s0 acc (UInt256.toByteArray (UInt256.signextend ⟨2⟩ val)) := by - rcases hwf with - ⟨hd0, hd1, hd3, hd4, hd5, hd7, hd8, hd9, hd10, hd11, hd12, hd13, hd14, hd15, - hd16, hd17, hd18, hd20, hd21, hd22⟩ - have rd1 := RD.jumpdest h hd0 (by simp only [List.length_cons]; omega) - have rd3 := RD.push1 rd1 ⟨64⟩ hd1 (by simp only [List.length_cons]; omega) - have rd4 := RD.dup1 rd3 hd3 (by simp only [List.length_cons]; omega) - have rd5 := RD.mload 0 ⟨128⟩ (UInt256.ofNat 3) rd4 hd4 mem_cost hmload64 - (by decide) (by simp only [List.length_cons]; omega) - have rd7 := RD.push1 rd5 ⟨2⟩ hd5 (by simp only [List.length_cons]; omega) - have rd8 := RD.swap3 rd7 hd7 (by simp only [List.length_cons]; omega) - have rd9 := RD.swap1 rd8 hd8 (by simp only [List.length_cons]; omega) - have rd10 := RD.swap3 rd9 hd9 (by simp only [List.length_cons]; omega) - have rd11 := tickSpacingRDSignextend rd10 hd10 - (by simp only [List.length_cons]; omega) - have rd12pre := RD.dup3 rd11 hd11 (by simp only [List.length_cons]; omega) - have rd13 := RD.mstore 6 memout (UInt256.ofNat 5) rd12pre hd12 mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide] - exact hmemout) - (by decide) (by simp only [List.length_cons]; omega) - have rd14 := RD.mload 0 ⟨128⟩ (UInt256.ofNat 5) rd13 hd13 mem_cost hmemoutLoad64 - (by decide) (by simp only [List.length_cons]; omega) - have rd15 := RD.swap1 rd14 hd14 (by simp only [List.length_cons]; omega) - have rd16 := RD.dup2 rd15 hd15 (by simp only [List.length_cons]; omega) - have rd17 := RD.swap1 rd16 hd16 (by simp only [List.length_cons]; omega) - have rd18 := RD.sub rd17 hd17 (by simp only [List.length_cons]; omega) - have rd20 := RD.push1 rd18 ⟨32⟩ hd18 (by simp only [List.length_cons]; omega) - have rd21 := RD.add rd20 hd20 (by simp only [List.length_cons]; omega) - have rd22 := RD.swap1 rd21 hd21 (by simp only [List.length_cons]; omega) - exact RD.ret 0 (UInt256.toByteArray (UInt256.signextend ⟨2⟩ val)) rd22 hd22 mem_cost - (by - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - show ((⟨32⟩ : UInt256) + UInt256.sub (⟨128⟩ : UInt256) ⟨128⟩).toNat = 32 - from by decide] - exact hread128) - (by simp only [List.length_cons]; omega) - -theorem RD.solcInt24ConstGetterExternal {code : ByteArray} {cA gh bl σ σ₀ A I} - {g : Sat256} {sel entry routine returnPc val : UInt256} {width : Nat} - {op : Operation.POp} - (hreach : ∃ k C, RD code I g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) - entry [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hentry : solcGetterEntryWf code entry returnPc routine) - (hgetter : solcConstGetterWf code routine val width op) - (hroutine : (D_J code 0).contains routine = true) - (hret : (D_J code 0).contains returnPc = true) - (hreturn : solcReturnInt24FromMemWf code returnPc) : - RDret code g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.signextend ⟨2⟩ val)) := by - obtain ⟨_, _, rdRoutine⟩ := RD.solcGetterThunk hreach hentry hroutine - obtain ⟨_, _, rdReturn⟩ := RD.solcConstGetter (val := val) (width := width) - (op := op) (R := [sel]) rdRoutine hgetter hret - (by simp only [List.length_singleton]; omega) - exact RD.solcReturnInt24FromMem rdReturn hreturn - solcFreePtrMem_mload64 - (by rfl) - (solcReturnMem_mload64 (UInt256.signextend ⟨2⟩ val)) - (solcReturnMem_read128 (UInt256.signextend ⟨2⟩ val)) - (by simp only [List.length_singleton]; omega) - -theorem uniswapV3PoolTickSpacingReturnWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcReturnInt24FromMemWf code ⟨2017⟩ := by - dsimp [solcReturnInt24FromMemWf] - refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolTickSpacingReturnJumpDest {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨2017⟩ = true := - uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide) - -theorem uniswapV3PoolTickSpacingEvm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 20 == I.calldata.extract 0 4) = true) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.signextend ⟨2⟩ (EVM.wordOfInt v.tickSpacing))) := by - have hreach := uniswapV3PoolTickSpacingReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - exact RD.solcInt24ConstGetterExternal - (sel := solcSelectorWord I) (entry := ⟨2009⟩) (routine := ⟨10491⟩) - (returnPc := ⟨2017⟩) (val := EVM.wordOfInt v.tickSpacing) (width := 32) - (op := .PUSH32) hreach - (uniswapV3PoolTickSpacingEntryWf hpatch) - (uniswapV3PoolTickSpacingGetterWf hpatch) - (uniswapV3PoolJumpDestPatched10491 hpatch) - (uniswapV3PoolTickSpacingReturnJumpDest hpatch) - (uniswapV3PoolTickSpacingReturnWf hpatch) - -theorem uniswapV3PoolTickSpacingSourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) (tickspacingTransition v).body - (.returned { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) - (some [Value.int v.tickSpacing])) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [.intLit v.tickSpacing] ] _ - exact nonpayableIntLiteralBodyReturns (initState cA gh bl σ σ₀ g A I) - (∅ : Store) v.tickSpacing hwv - -theorem uniswapV3PoolTickSpacingBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 20 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_tickSpacing (v := v) (cd := I.calldata) hsel - have hdecode := uniswapV3PoolTickSpacingDecode (v := v) (I := I) hsz - have hbody := uniswapV3PoolTickSpacingSourceBody (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hrd := uniswapV3PoolTickSpacingEvm (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel - have hsign := signextend_two_wordOfInt_tickSpacing v.tickSpacing - v.tickSpacing_ge v.tickSpacing_lt - exact hrd.reEquivExecution hcode hdispatch hdecode hbody hAccounts - (returnEquiv_of_encode (by - simpa [hsign] using int24ReturnEncodingInt v.tickSpacing - v.tickSpacing_ge v.tickSpacing_lt)) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Ticks.lean b/Benchmarks/UniswapV3Pool/Ticks.lean deleted file mode 100644 index a54a7111..00000000 --- a/Benchmarks/UniswapV3Pool/Ticks.lean +++ /dev/null @@ -1,1970 +0,0 @@ -import Benchmarks.UniswapV3Pool.Uint128 -import Benchmarks.UniswapV3Pool.ObservationsInt56 -import Benchmarks.UniswapV3Pool.TicksInt128 -import Benchmarks.UniswapV3Pool.TicksReturnMemory -import Reasoning.MemCascade - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev ticksArgWord (I : ExecutionEnv) : UInt256 := - calldataWord I.calldata 4 - -abbrev ticksArgCleanWord (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨2⟩ (ticksArgWord I) - -abbrev ticksArgValue (I : ExecutionEnv) : Value := - .int (tickSpacingSint24Value (ticksArgWord I)) - -abbrev ticksArgKey (I : ExecutionEnv) : KeyValue := - .int (tickSpacingSint24Value (ticksArgWord I)) - -abbrev ticksStore (I : ExecutionEnv) : Store := - (∅ : Store).insert "arg0" (ticksArgValue I) - -abbrev ticksBaseSlot (I : ExecutionEnv) : UInt256 := - ticksBase (ticksArgKey I) - -abbrev ticksPacked3Slot (I : ExecutionEnv) : UInt256 := - ticksBaseSlot I + ⟨3⟩ - -abbrev ticksShiftBytes (n : Nat) : UInt256 := - UInt256.ofNat (256 ^ n) - -abbrev ticksUint32Mask : UInt256 := - UInt256.ofNat (2 ^ 32 - 1) - -theorem ticksUint32Mask_toNat : - ticksUint32Mask.toNat = 2 ^ 32 - 1 := by - exact ulit_toNat' _ (by norm_num [UInt256.size]) - -theorem ticksUint32Mask_bound (w : UInt256) : - (UInt256.land w ticksUint32Mask).toNat < EVM.twoPow 32 := by - rw [uland_toNat] - rw [ticksUint32Mask_toNat] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [EVM.twoPow]) - -theorem ticksUint32Mask_clean {w : UInt256} (hcanon : w.toNat < EVM.twoPow 32) : - UInt256.land w ticksUint32Mask = w := by - apply u256_inj - show Nat.land w.toNat ticksUint32Mask.toNat % EVM.twoPow 256 = w.toNat - rw [ticksUint32Mask_toNat, nat_land_mask_eq_mod] - rw [show EVM.twoPow 32 = 2 ^ 32 from rfl] at hcanon - rw [Nat.mod_eq_of_lt hcanon] - exact Nat.mod_eq_of_lt w.val.isLt - -abbrev ticksPacked0Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (ticksBaseSlot I) - -abbrev ticksLiquidityGrossWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (ticksPacked0Word σ I) uint128Mask - -abbrev ticksLiquidityNetRawWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.div (ticksPacked0Word σ I) (ticksShiftBytes 16) - -abbrev ticksLiquidityNetStorageWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (ticksLiquidityNetRawWord σ I) uint128Mask - -abbrev ticksLiquidityNetReturnWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨15⟩ (ticksLiquidityNetRawWord σ I) - -abbrev ticksFeeGrowthOutside0Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (ticksBaseSlot I + ⟨1⟩) - -abbrev ticksFeeGrowthOutside1Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (ticksBaseSlot I + ⟨2⟩) - -abbrev ticksPacked3Word (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - solcSlotWord σ I (ticksPacked3Slot I) - -abbrev ticksTickCumulativeRawWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.div (ticksPacked3Word σ I) (ticksShiftBytes 0) - -abbrev ticksTickCumulativeStorageWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (ticksTickCumulativeRawWord σ I) observationsUint56Mask - -abbrev ticksTickCumulativeReturnWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.signextend ⟨6⟩ (ticksPacked3Word σ I) - -abbrev ticksSecondsPerLiquidityWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.div (ticksPacked3Word σ I) (ticksShiftBytes 7)) slot0Uint160Mask - -abbrev ticksSecondsOutsideWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.div (ticksPacked3Word σ I) (ticksShiftBytes 27)) - ticksUint32Mask - -abbrev ticksInitializedRawWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - UInt256.land (UInt256.div (ticksPacked3Word σ I) (ticksShiftBytes 31)) slot0Uint8Mask - -abbrev ticksInitializedReturnWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := - slot0BoolReturnWord (ticksInitializedRawWord σ I) - -abbrev ticksReturnValues (σ : AccountMap) (I : ExecutionEnv) : List Value := - [ .int (Int.ofNat (ticksLiquidityGrossWord σ I).toNat), - wordToElem (.int int128Int) (ticksLiquidityNetStorageWord σ I), - .int (Int.ofNat (ticksFeeGrowthOutside0Word σ I).toNat), - .int (Int.ofNat (ticksFeeGrowthOutside1Word σ I).toNat), - wordToElem (.int int56Int) (ticksTickCumulativeStorageWord σ I), - .int (Int.ofNat (ticksSecondsPerLiquidityWord σ I).toNat), - .int (Int.ofNat (ticksSecondsOutsideWord σ I).toNat), - wordToElem .bool (ticksInitializedRawWord σ I) ] - -theorem ticksArgKeyWord (I : ExecutionEnv) : - keyValueToWord (ticksArgKey I) = ticksArgCleanWord I := by - unfold ticksArgKey ticksArgCleanWord ticksArgWord keyValueToWord - exact wordOfInt_sint24Value_eq_signextend_two (calldataWord I.calldata 4) - -theorem ticksBaseSlot_eq_solcMappingSlot (I : ExecutionEnv) : - ticksBaseSlot I = solcMappingSlot ⟨5⟩ (ticksArgCleanWord I) := by - unfold ticksBaseSlot ticksBase mapSlot solcMappingSlot - rw [ticksArgKeyWord I] - -theorem decodeScalarWordsWithMode_int24_ok {bytes : List UInt8} - (hlen0 : (bytes.take 32).length = 32) : - decodeScalarWordsWithMode? DecodeMode.legacySolc05 [int24] bytes 0 = - some [Value.int (tickSpacingSint24Value (ABI.bytesToWord (bytes.take 32)))] := by - simp only [decodeScalarWordsWithMode?] - unfold decodeScalarWordWithMode? readWord? readBytes? int24 int24Int tickSpacingSint24Value - simp only [List.drop_zero] - rw [if_pos hlen0] - simp only [Option.bind, bind] - unfold decodeABIWord? - simp only [OfNat.ofNat_ne_zero, ↓reduceIte] - rfl - -theorem decodeScalarWordsWithMode_int24_none_short {bytes : List UInt8} - (hshort : bytes.length < 32) : - decodeScalarWordsWithMode? DecodeMode.legacySolc05 [int24] bytes 0 = none := by - simp only [decodeScalarWordsWithMode?] - have htake0n : ¬ (bytes.take 32).length = 32 := by - rw [List.length_take] - omega - unfold decodeScalarWordWithMode? readWord? readBytes? int24 int24Int - simp only [List.drop_zero] - rw [if_neg htake0n] - simp only [Option.bind, bind] - -theorem uniswapV3PoolTicksDecodeOk {v : PoolImmutables} {I : ExecutionEnv} - (hsz36 : 36 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode - (ticksTransition.params.map Param.name) - (transitionSignature ticksTransition).paramTypes I.calldata = some (ticksStore I) := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - have htake4 : ((I.calldata.toList.drop 4).take 32).length = 32 := by - rw [List.length_take, List.length_drop, htlen] - omega - have hword4 : ABI.bytesToWord ((I.calldata.toList.drop 4).take 32) = - calldataWord I.calldata 4 := - decode_word_at_eq I.calldata 4 (by omega) (by norm_num) - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := ticksTransition.params.map Param.name) - (types := (transitionSignature ticksTransition).paramTypes) (cd := I.calldata)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 [int24] - (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["arg0"] values ∅ - | none => none) = some (ticksStore I) - rw [decodeScalarWordsWithMode_int24_ok (bytes := I.calldata.toList.drop 4) htake4] - change decodeCalldata.insertValues ["arg0"] - [Value.int - (tickSpacingSint24Value - (ABI.bytesToWord ((I.calldata.toList.drop 4).take 32)))] ∅ = - some (ticksStore I) - simp [decodeCalldata.insertValues, ticksStore, ticksArgValue, ticksArgWord] - rw [hword4] - · native_decide - -theorem uniswapV3PoolTicksDecodeShort {v : PoolImmutables} {I : ExecutionEnv} - (hshort : I.calldata.size < 36) : - decodeCalldataWithMode (config v).abiDecodeMode - (ticksTransition.params.map Param.name) - (transitionSignature ticksTransition).paramTypes I.calldata = none := by - have htlen : I.calldata.toList.length = I.calldata.size := by - rw [byteArray_toList_eq, Array.length_toList] - rfl - rw [show (config v).abiDecodeMode = DecodeMode.legacySolc05 from rfl] - rw [decodeCalldataWithMode_legacyScalarWords_eq - (names := ticksTransition.params.map Param.name) - (types := (transitionSignature ticksTransition).paramTypes) (cd := I.calldata)] - · by_cases hsz4 : I.calldata.size < 4 - · rw [if_pos (by rw [htlen]; omega : I.calldata.toList.length < 4)] - · rw [if_neg (by rw [htlen]; omega : ¬ I.calldata.toList.length < 4)] - change (match decodeScalarWordsWithMode? DecodeMode.legacySolc05 [int24] - (I.calldata.toList.drop 4) 0 with - | some values => decodeCalldata.insertValues ["arg0"] values ∅ - | none => none) = none - rw [decodeScalarWordsWithMode_int24_none_short - (bytes := I.calldata.toList.drop 4) (by rw [List.length_drop, htlen]; omega)] - · native_decide - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolDispatch_ticks {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 24 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some ticksTransition := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, factoryTransition v, - feeTransition v, feegrowthglobal0X128Transition, feegrowthglobal1X128Transition, - flashTransition v, increaseobservationcardinalitynextTransition v, initializeTransition, - liquidityTransition, maxliquiditypertickTransition v, mintTransition v, - observationsTransition, observeTransition v, positionsTransition, protocolfeesTransition, - setfeeprotocolTransition v, slot0Transition, snapshotcumulativesinsideTransition v, - swapTransition v, tickbitmapTransition, tickspacingTransition v]) - (post := [token0Transition v, token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 24) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 24) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 24) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 24) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 24) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 24) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 24) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 24) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 5) (j := 24) - (by native_decide) hsel - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 25) (j := 24) - (by native_decide) hsel - · rw [selectorOf, liquiditySelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 2) (j := 24) - (by native_decide) hsel - · rw [selectorOf, maxLiquidityPerTickSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 13) (j := 24) - (by native_decide) hsel - · rw [selectorOf, mintSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 7) (j := 24) - (by native_decide) hsel - · rw [selectorOf, observationsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 4) (j := 24) - (by native_decide) hsel - · rw [selectorOf, observeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 16) (j := 24) - (by native_decide) hsel - · rw [selectorOf, positionsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 11) (j := 24) - (by native_decide) hsel - · rw [selectorOf, protocolFeesSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 3) (j := 24) - (by native_decide) hsel - · rw [selectorOf, setFeeProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 14) (j := 24) - (by native_decide) hsel - · rw [selectorOf, slot0SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 6) (j := 24) - (by native_decide) hsel - · rw [selectorOf, snapshotCumulativesInsideSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 18) (j := 24) - (by native_decide) hsel - · rw [selectorOf, swapSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 1) (j := 24) - (by native_decide) hsel - · rw [selectorOf, tickBitmapSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 12) (j := 24) - (by native_decide) hsel - · rw [selectorOf, tickSpacingSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 20) (j := 24) - (by native_decide) hsel - · rw [selectorOf, ticksSelectorBytes] - simpa [uniswapV3PoolSelBytes] using hsel - -theorem ticksStore_arg0 (I : ExecutionEnv) : - Std.HashMap.get? (ticksStore I) "arg0" = some (ticksArgValue I) := by - simp [ticksStore] - -theorem evalExpr_ticks_arg0 {v : PoolImmutables} (evm : EVM.State) (I : ExecutionEnv) : - evalExpr? (config v) { contract := contract v, locals := ticksStore I } evm - (.var "arg0") = .ok (ticksArgValue I) := by - simp only [evalExpr?, EvalResult.ofOption] - rw [ticksStore_arg0] - -def ticksEvaledRef (I : ExecutionEnv) (field : Ident) : EvaledStorageRef := - { base := "ticks", steps := [.mindex (ticksArgKey I), .field field] } - -theorem evalStorageRef_ticks {v : PoolImmutables} (evm : EVM.State) - (I : ExecutionEnv) (field : Ident) : - evalStorageRef (config v) { contract := contract v, locals := ticksStore I } evm - (ticksF (.var "arg0") field) = .ok (ticksEvaledRef I field) := by - simp [evalStorageRef, evalStorageRefStep, evalStorageRefSteps, ticksF, - ticksEvaledRef, evalExpr_ticks_arg0, ticksArgValue, ticksArgKey, valueToKey?, - EvalResult.bind, EvalResult.ofOption, bind, pure] - -theorem ticksStorageLocLoad_liquidityGross (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (ticksBaseSlot I) ⟨0, by decide⟩ ⟨16, by decide⟩ (by decide) - (.int uint128Int)) = - .int (Int.ofNat (UInt256.land - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (ticksBaseSlot I)) - uint128Mask).toNat) := by - rw [← show UInt256.ofNat (2 ^ (8 * 16) - 1) = uint128Mask by native_decide] - simpa [loc, uint128Int] using - storageLocLoad_uint_offset0 evm (ticksBaseSlot I) (16 : Fin 33) ⟨128, by decide⟩ - (hbound := by decide) (by decide) - -theorem ticksStorageLocLoad_liquidityNet (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (ticksBaseSlot I) ⟨16, by decide⟩ ⟨16, by decide⟩ (by decide) - (.int int128Int)) = - wordToElem (.int int128Int) - (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (ticksBaseSlot I)) - (ticksShiftBytes 16)) - uint128Mask) := by - rw [← show UInt256.ofNat (256 ^ (16 : Nat)) = ticksShiftBytes 16 by rfl] - rw [← show UInt256.ofNat (256 ^ (16 : Nat) - 1) = uint128Mask by native_decide] - simpa [loc, int128Int] using - storageLocLoad_sint_offset evm (ticksBaseSlot I) (16 : Fin 32) (16 : Fin 33) - ⟨128, by decide⟩ (hbound := by decide) (by decide) (by decide) - -theorem ticksStorageLocLoad_feeGrowthOutside0 (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (ticksBaseSlot I + ⟨1⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int)) = - .int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (ticksBaseSlot I + ⟨1⟩)).toNat) := by - simpa [loc, uint256Loc] using storageLocLoad_uint256 evm (ticksBaseSlot I + ⟨1⟩) - -theorem ticksStorageLocLoad_feeGrowthOutside1 (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (ticksBaseSlot I + ⟨2⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int)) = - .int (Int.ofNat - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner - (ticksBaseSlot I + ⟨2⟩)).toNat) := by - simpa [loc, uint256Loc] using storageLocLoad_uint256 evm (ticksBaseSlot I + ⟨2⟩) - -theorem ticksStorageLocLoad_tickCumulativeOutside (evm : EVM.State) - (I : ExecutionEnv) : - storageLocLoad evm - (loc (ticksPacked3Slot I) ⟨0, by decide⟩ ⟨7, by decide⟩ - (by decide) (.int int56Int)) = - wordToElem (.int int56Int) - (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (ticksPacked3Slot I)) - (ticksShiftBytes 0)) - observationsUint56Mask) := by - rw [← show UInt256.ofNat (256 ^ (0 : Nat)) = ticksShiftBytes 0 by rfl] - rw [← show UInt256.ofNat (256 ^ (7 : Nat) - 1) = observationsUint56Mask by - native_decide] - simpa [loc, int56Int] using - storageLocLoad_sint_offset evm (ticksPacked3Slot I) (0 : Fin 32) (7 : Fin 33) - ⟨56, by decide⟩ (hbound := by decide) (by decide) (by decide) - -theorem ticksStorageLocLoad_secondsPerLiquidity (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (ticksPacked3Slot I) ⟨7, by decide⟩ ⟨20, by decide⟩ - (by decide) (.int uint160Int)) = - .int (Int.ofNat (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (ticksPacked3Slot I)) - (ticksShiftBytes 7)) - slot0Uint160Mask).toNat) := by - rw [← show UInt256.ofNat (256 ^ (7 : Nat)) = ticksShiftBytes 7 by rfl] - rw [← show UInt256.ofNat (256 ^ (20 : Nat) - 1) = slot0Uint160Mask by native_decide] - simpa [loc, uint160Int] using - storageLocLoad_uint_offset evm (ticksPacked3Slot I) (7 : Fin 32) (20 : Fin 33) - ⟨160, by decide⟩ (hbound := by decide) (by decide) (by decide) - -theorem ticksStorageLocLoad_secondsOutside (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (ticksPacked3Slot I) ⟨27, by decide⟩ ⟨4, by decide⟩ - (by decide) (.int uint32Int)) = - .int (Int.ofNat (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (ticksPacked3Slot I)) - (ticksShiftBytes 27)) - ticksUint32Mask).toNat) := by - rw [← show UInt256.ofNat (256 ^ (27 : Nat)) = ticksShiftBytes 27 by rfl] - rw [← show UInt256.ofNat (256 ^ (4 : Nat) - 1) = ticksUint32Mask by native_decide] - simpa [loc, uint32Int] using - storageLocLoad_uint_offset evm (ticksPacked3Slot I) (27 : Fin 32) (4 : Fin 33) - ⟨32, by decide⟩ (hbound := by decide) (by decide) (by decide) - -theorem ticksStorageLocLoad_initialized (evm : EVM.State) (I : ExecutionEnv) : - storageLocLoad evm - (loc (ticksPacked3Slot I) ⟨31, by decide⟩ ⟨1, by decide⟩ - (by decide) .bool) = - wordToElem .bool - (UInt256.land - (UInt256.div - (Solm.EVM.storageLoad evm evm.executionEnv.codeOwner (ticksPacked3Slot I)) - (ticksShiftBytes 31)) - slot0Uint8Mask) := by - rw [← show UInt256.ofNat (256 ^ (31 : Nat)) = ticksShiftBytes 31 by rfl] - simpa [loc] using - storageLocLoad_bool_offset evm (ticksPacked3Slot I) (31 : Fin 32) - (hbound := by decide) (by decide) - -theorem uniswapV3PoolTicksSourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (ticksStore I) ticksTransition.body - (.returned { contract := contract v, locals := ticksStore I } - (initState cA gh bl σ σ₀ g A I) - (some (ticksReturnValues σ I))) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (ticksStore I) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [ .storage (ticksF (.var "arg0") "liquidityGross"), - .storage (ticksF (.var "arg0") "liquidityNet"), - .storage (ticksF (.var "arg0") "feeGrowthOutside0X128"), - .storage (ticksF (.var "arg0") "feeGrowthOutside1X128"), - .storage (ticksF (.var "arg0") "tickCumulativeOutside"), - .storage (ticksF (.var "arg0") "secondsPerLiquidityOutsideX128"), - .storage (ticksF (.var "arg0") "secondsOutside"), - .storage (ticksF (.var "arg0") "initialized") ] ] _ - exact ExecFuncBody.execBlockRet <| - ExecBlock.consNormal (ExecStmt.requireTrue (evalCallvalueEq_true (by simp [initState, hwv]))) <| - ExecBlock.consReturn <| ExecStmt.return (by - have hgross : - evalExpr? (config v) { contract := contract v, locals := ticksStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (ticksF (.var "arg0") "liquidityGross")) = - .ok (.int (Int.ofNat (ticksLiquidityGrossWord σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := ticksEvaledRef I "liquidityGross") - (t := .int uint128Int) - (loc := loc (ticksBaseSlot I) ⟨0, by decide⟩ ⟨16, by decide⟩ - (by decide) (.int uint128Int)) - · simp [ticksStore, ticksF] - · exact evalStorageRef_ticks (v := v) (initState cA gh bl σ σ₀ g A I) I - "liquidityGross" - · simp [ticksEvaledRef, contract, storageDecls, storageTypeAt?, storageTypeStep?, - tickInfoStructTy, uint128St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - ticksEvaledRef, ticksBaseSlot, loc] - · simpa [initState, ticksLiquidityGrossWord, ticksPacked0Word, solcSlotWord] using - ticksStorageLocLoad_liquidityGross (initState cA gh bl σ σ₀ g A I) I - have hnet : - evalExpr? (config v) { contract := contract v, locals := ticksStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (ticksF (.var "arg0") "liquidityNet")) = - .ok (wordToElem (.int int128Int) (ticksLiquidityNetStorageWord σ I)) := by - apply evalExpr_storage_scalar_value - (er := ticksEvaledRef I "liquidityNet") - (t := .int int128Int) - (loc := loc (ticksBaseSlot I) ⟨16, by decide⟩ ⟨16, by decide⟩ - (by decide) (.int int128Int)) - · simp [ticksStore, ticksF] - · exact evalStorageRef_ticks (v := v) (initState cA gh bl σ σ₀ g A I) I - "liquidityNet" - · simp [ticksEvaledRef, contract, storageDecls, storageTypeAt?, storageTypeStep?, - tickInfoStructTy, int128St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - ticksEvaledRef, ticksBaseSlot, loc] - · simpa [initState, ticksLiquidityNetStorageWord, ticksLiquidityNetRawWord, - ticksPacked0Word, solcSlotWord] using - ticksStorageLocLoad_liquidityNet (initState cA gh bl σ σ₀ g A I) I - have hfee0 : - evalExpr? (config v) { contract := contract v, locals := ticksStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (ticksF (.var "arg0") "feeGrowthOutside0X128")) = - .ok (.int (Int.ofNat (ticksFeeGrowthOutside0Word σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := ticksEvaledRef I "feeGrowthOutside0X128") - (t := .int uint256Int) - (loc := loc (ticksBaseSlot I + ⟨1⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int)) - · simp [ticksStore, ticksF] - · exact evalStorageRef_ticks (v := v) (initState cA gh bl σ σ₀ g A I) I - "feeGrowthOutside0X128" - · simp [ticksEvaledRef, contract, storageDecls, storageTypeAt?, storageTypeStep?, - tickInfoStructTy, uint256St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - ticksEvaledRef, ticksBaseSlot, loc] - · simpa [initState, ticksFeeGrowthOutside0Word, solcSlotWord] using - ticksStorageLocLoad_feeGrowthOutside0 (initState cA gh bl σ σ₀ g A I) I - have hfee1 : - evalExpr? (config v) { contract := contract v, locals := ticksStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (ticksF (.var "arg0") "feeGrowthOutside1X128")) = - .ok (.int (Int.ofNat (ticksFeeGrowthOutside1Word σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := ticksEvaledRef I "feeGrowthOutside1X128") - (t := .int uint256Int) - (loc := loc (ticksBaseSlot I + ⟨2⟩) ⟨0, by decide⟩ ⟨32, by decide⟩ - (by decide) (.int uint256Int)) - · simp [ticksStore, ticksF] - · exact evalStorageRef_ticks (v := v) (initState cA gh bl σ σ₀ g A I) I - "feeGrowthOutside1X128" - · simp [ticksEvaledRef, contract, storageDecls, storageTypeAt?, storageTypeStep?, - tickInfoStructTy, uint256St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - ticksEvaledRef, ticksBaseSlot, loc] - · simpa [initState, ticksFeeGrowthOutside1Word, solcSlotWord] using - ticksStorageLocLoad_feeGrowthOutside1 (initState cA gh bl σ σ₀ g A I) I - have htick : - evalExpr? (config v) { contract := contract v, locals := ticksStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (ticksF (.var "arg0") "tickCumulativeOutside")) = - .ok (wordToElem (.int int56Int) (ticksTickCumulativeStorageWord σ I)) := by - apply evalExpr_storage_scalar_value - (er := ticksEvaledRef I "tickCumulativeOutside") - (t := .int int56Int) - (loc := loc (ticksPacked3Slot I) ⟨0, by decide⟩ ⟨7, by decide⟩ - (by decide) (.int int56Int)) - · simp [ticksStore, ticksF] - · exact evalStorageRef_ticks (v := v) (initState cA gh bl σ σ₀ g A I) I - "tickCumulativeOutside" - · simp [ticksEvaledRef, contract, storageDecls, storageTypeAt?, storageTypeStep?, - tickInfoStructTy, int56St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - ticksEvaledRef, ticksBaseSlot, ticksPacked3Slot, loc] - · simpa [initState, ticksTickCumulativeStorageWord, ticksTickCumulativeRawWord, - ticksPacked3Word, solcSlotWord] using - ticksStorageLocLoad_tickCumulativeOutside (initState cA gh bl σ σ₀ g A I) I - have hsecondsLiq : - evalExpr? (config v) { contract := contract v, locals := ticksStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (ticksF (.var "arg0") "secondsPerLiquidityOutsideX128")) = - .ok (.int (Int.ofNat (ticksSecondsPerLiquidityWord σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := ticksEvaledRef I "secondsPerLiquidityOutsideX128") - (t := .int uint160Int) - (loc := loc (ticksPacked3Slot I) ⟨7, by decide⟩ ⟨20, by decide⟩ - (by decide) (.int uint160Int)) - · simp [ticksStore, ticksF] - · exact evalStorageRef_ticks (v := v) (initState cA gh bl σ σ₀ g A I) I - "secondsPerLiquidityOutsideX128" - · simp [ticksEvaledRef, contract, storageDecls, storageTypeAt?, storageTypeStep?, - tickInfoStructTy, uint160St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - ticksEvaledRef, ticksBaseSlot, ticksPacked3Slot, loc] - · simpa [initState, ticksSecondsPerLiquidityWord, ticksPacked3Word, - solcSlotWord] using - ticksStorageLocLoad_secondsPerLiquidity (initState cA gh bl σ σ₀ g A I) I - have hsecondsOut : - evalExpr? (config v) { contract := contract v, locals := ticksStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (ticksF (.var "arg0") "secondsOutside")) = - .ok (.int (Int.ofNat (ticksSecondsOutsideWord σ I).toNat)) := by - apply evalExpr_storage_scalar_value - (er := ticksEvaledRef I "secondsOutside") - (t := .int uint32Int) - (loc := loc (ticksPacked3Slot I) ⟨27, by decide⟩ ⟨4, by decide⟩ - (by decide) (.int uint32Int)) - · simp [ticksStore, ticksF] - · exact evalStorageRef_ticks (v := v) (initState cA gh bl σ σ₀ g A I) I - "secondsOutside" - · simp [ticksEvaledRef, contract, storageDecls, storageTypeAt?, storageTypeStep?, - tickInfoStructTy, uint32St] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - ticksEvaledRef, ticksBaseSlot, ticksPacked3Slot, loc] - · simpa [initState, ticksSecondsOutsideWord, ticksPacked3Word, solcSlotWord] using - ticksStorageLocLoad_secondsOutside (initState cA gh bl σ σ₀ g A I) I - have hinit : - evalExpr? (config v) { contract := contract v, locals := ticksStore I } - (initState cA gh bl σ σ₀ g A I) - (.storage (ticksF (.var "arg0") "initialized")) = - .ok (wordToElem .bool (ticksInitializedRawWord σ I)) := by - apply evalExpr_storage_scalar_value - (er := ticksEvaledRef I "initialized") - (t := .bool) - (loc := loc (ticksPacked3Slot I) ⟨31, by decide⟩ ⟨1, by decide⟩ - (by decide) .bool) - · simp [ticksStore, ticksF] - · exact evalStorageRef_ticks (v := v) (initState cA gh bl σ σ₀ g A I) I - "initialized" - · simp [ticksEvaledRef, contract, storageDecls, storageTypeAt?, storageTypeStep?, - tickInfoStructTy, boolSt] - · funext evm - simp [config, storageLayout, storageLayoutRaw, solidityStorageLayout, - ticksEvaledRef, ticksBaseSlot, ticksPacked3Slot, loc] - · simpa [initState, ticksInitializedRawWord, ticksPacked3Word, solcSlotWord] using - ticksStorageLocLoad_initialized (initState cA gh bl σ σ₀ g A I) I - simp only [ticksReturnValues, Solm.evalExprs?.eq_def, hgross, hnet, hfee0, hfee1, - htick, hsecondsLiq, hsecondsOut, hinit, EvalResult.bind, bind, pure]) - -theorem uniswapV3PoolTicksValueTransport {σ_evm σ_solm : AccountMap} {I : ExecutionEnv} - (hAccounts : accountMapEquiv σ_evm σ_solm) : - some (ticksReturnValues σ_solm I) = some (ticksReturnValues σ_evm I) := by - have hbase := accountMapEquiv_storage_findD hAccounts I.codeOwner - (ticksBaseSlot I) (⟨0⟩ : UInt256) - have hfee0 := accountMapEquiv_storage_findD hAccounts I.codeOwner - (ticksBaseSlot I + ⟨1⟩) (⟨0⟩ : UInt256) - have hfee1 := accountMapEquiv_storage_findD hAccounts I.codeOwner - (ticksBaseSlot I + ⟨2⟩) (⟨0⟩ : UInt256) - have hpacked3 := accountMapEquiv_storage_findD hAccounts I.codeOwner - (ticksPacked3Slot I) (⟨0⟩ : UInt256) - dsimp [ticksReturnValues, ticksLiquidityGrossWord, ticksLiquidityNetStorageWord, - ticksLiquidityNetRawWord, ticksFeeGrowthOutside0Word, ticksFeeGrowthOutside1Word, - ticksTickCumulativeStorageWord, ticksTickCumulativeRawWord, - ticksSecondsPerLiquidityWord, ticksSecondsOutsideWord, ticksInitializedRawWord, - ticksPacked0Word, ticksPacked3Word, solcSlotWord] - rw [← hbase, ← hfee0, ← hfee1, ← hpacked3] - -private def ticksStSignextend (s : State) (res : UInt256) (t : List UInt256) : State := - { s with - machineState.stack := res :: t, - machineState.gasAvailable := s.machineState.gasAvailable.subNat 5 - machineState.pc := s.machineState.pc + ⟨1⟩ - machineState.execLength := s.machineState.execLength + 1 } - -private theorem ticksSignextendXstep {code : ByteArray} {s : State} {pc a b : UInt256} - {t : List UInt256} - (hcode : s.executionEnv.code = code) (hpc : s.machineState.pc = pc) - (hdec : decode code pc = some (.SIGNEXTEND, .none)) - (hstk : s.machineState.stack = a :: b :: t) (hov : t.length + 1 ≤ 1024) : - Xstep (D_J code 0) s = - if s.machineState.gasAvailable.toNat < 5 then .error .OutOfGass - else .ok (ticksStSignextend s (UInt256.signextend a b) t, .none) := by - have hdecS : decode s.executionEnv.code s.machineState.pc = some (.SIGNEXTEND, .none) := by - rw [hcode, hpc] - exact hdec - have hstep := step_signextend s hdecS - have hnoOverflow : ¬ 1024 ≤ t.length := by omega - simpa [hcode, hstk, GasConstants.Glow, ticksStSignextend, hnoOverflow] using hstep - -private theorem ticksRDSignextend {code : ByteArray} {ee : ExecutionEnv} - {g : Sat256} {s0 : State} {pc : UInt256} {mem : ByteArray} - {aw : UInt256} {rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} {k C : ℕ} - {a b : UInt256} {t : List UInt256} - (h : RD code ee g s0 pc (a :: b :: t) mem aw rdata acc k C) - (hdec : decode code pc = some (.SIGNEXTEND, .none)) (hov : t.length + 1 ≤ 1024) : - RD code ee g s0 (pc + ⟨1⟩) (UInt256.signextend a b :: t) mem aw rdata acc - (k + 1) (C + 5) := by - unfold RD at h ⊢ - rcases h with hoog | ⟨s, hX, hcode, hpc, hstk, hgas, hk, hC, hmem, haw, hrdata, hacc, hee, - hworld⟩ - · exact Or.inl hoog - · have st := ticksSignextendXstep hcode hpc hdec hstk hov - by_cases gg : g.toNat < C + 5 - · exact Or.inl (hX.trans (stepOOG hgas st hk hC (by omega))) - · refine Or.inr ⟨ticksStSignextend s (UInt256.signextend a b) t, - hX.trans (stepContinue hgas st hk (Nat.not_lt.mp gg)), ?_, ?_, ?_, ?_, by omega, - by omega, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simp only [ticksStSignextend]; exact hcode - · simp only [ticksStSignextend]; rw [hpc] - · rfl - · simp only [ticksStSignextend]; rw [hgas, Sat256.subNat_sub_add_of_sub_sub] - · simp only [ticksStSignextend]; exact hmem - · simp only [ticksStSignextend]; exact haw - · simp only [ticksStSignextend]; exact hrdata - · simp only [ticksStSignextend]; exact hacc - · exact hee - · exact hworld - -private theorem uniswapV3PoolPatchPreservesJumpDest10605 : - D_J_auxPreservesTargetBool uniswapV3PoolBytecode uniswapV3PoolPatchOffsets - ⟨10605⟩ 0 = true := by - native_decide - -private theorem uniswapV3PoolTicksRoutinePatchDisjoint {v : PoolImmutables} - {pc : UInt256} (hlo : 10605 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 11259) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl - all_goals omega - -theorem uniswapV3PoolJumpDestPatched10605 {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10605⟩ = true := by - exact D_J_aux_contains_of_patchRuntime_preservesTarget hpatch - (uniswapV3PoolPatchOffsetMem v) - uniswapV3PoolPatchPreservesJumpDest10605 - -theorem uniswapV3PoolTicksReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 24 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨2088⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 24 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0xf3 0x0d 0xba 0x93 - (uniswapV3PoolSelNat 24) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h43 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨43⟩) hpatch h32 hgt32 - have hgt43 : UInt256.gt (armSelNat code ⟨43⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h54 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨54⟩) hpatch h43 hgt43 - have hgt54 : UInt256.gt (armSelNat code ⟨54⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h65 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨65⟩) hpatch h54 hgt54 - have hmiss22 : (uniswapV3PoolSelBytes 22 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h76 := uniswapV3PoolSelectorArmMissToOf (i := 22) (next := ⟨76⟩) - hpatch hsz hmiss22 h65 - have hmiss23 : (uniswapV3PoolSelBytes 23 == I.calldata.extract 0 4) = false := - uniswapV3PoolSelectorMissOfHit I (by native_decide) hsel - have h87 := uniswapV3PoolSelectorArmMissToOf (i := 23) (next := ⟨87⟩) - hpatch hsz hmiss23 h76 - have h2088 := uniswapV3PoolSelectorArmHitTo (i := 24) (target := ⟨2088⟩) - hpatch hsz hsel h87 - exact ⟨_, _, h2088⟩ - -private theorem uniswapV3PoolTicksDecodedReachRoutine {v : PoolImmutables} - {code : ByteArray} {ee : ExecutionEnv} {g : Sat256} {s0 : State} - {de ret : UInt256} {R : List UInt256} {mem : ByteArray} {aw : UInt256} - {rdata : ByteArray} {acc : Batteries.RBSet AccountAddress compare × AccountMap} - {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨2110⟩ (de :: ⟨4⟩ :: ret :: R) mem aw rdata acc k C) - (hov : R.length + 3 ≤ 1024) : - ∃ k' C', RD code ee g s0 ⟨10605⟩ (ticksArgCleanWord ee :: ret :: R) - mem aw rdata acc k' C' := by - have rd2111 : RD code ee g s0 ⟨2111⟩ (de :: ⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1) (C + 1) := by - simpa using h.jumpdest - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd2112 : RD code ee g s0 ⟨2112⟩ (⟨4⟩ :: ret :: R) - mem aw rdata acc (k + 1 + 1) (C + 1 + 2) := by - simpa using rd2111.pop - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd2113 : RD code ee g s0 ⟨2113⟩ (ticksArgWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1) (C + 1 + 2 + 3) := by - simpa [ticksArgWord, calldataWord, show (⟨4⟩ : UInt256).toNat = 4 from by decide] - using (rd2112.calldataload - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov)) - have rd2115 : RD code ee g s0 ⟨2115⟩ (⟨2⟩ :: ticksArgWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3) := by - simpa using rd2113.push1 ⟨2⟩ - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd2116 : RD code ee g s0 ⟨2116⟩ (ticksArgCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1) (C + 1 + 2 + 3 + 3 + 5) := by - simpa [ticksArgCleanWord] using - (ticksRDSignextend rd2115 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov)) - have rd2119 : RD code ee g s0 ⟨2119⟩ (⟨10605⟩ :: ticksArgCleanWord ee :: ret :: R) - mem aw rdata acc (k + 1 + 1 + 1 + 1 + 1 + 1) - (C + 1 + 2 + 3 + 3 + 5 + 3) := by - simpa using rd2116.push2 ⟨10605⟩ - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - exact ⟨_, _, rd2119.jump - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (uniswapV3PoolJumpDestPatched10605 hpatch) - (by evm_ov)⟩ - -set_option maxHeartbeats 3000000 in -private theorem uniswapV3PoolTicksExternalLenOk {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hreach : ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨2088⟩ - [solcSelectorWord I] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) - (hsz36 : 36 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨2110⟩ - (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩ :: ⟨4⟩ :: ⟨2120⟩ :: - [solcSelectorWord I]) - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - exact RD.solcExternalStaticArgsLenOk (need := ⟨32⟩) - (entry := ⟨2088⟩) (ret := ⟨2120⟩) (decoded := ⟨2110⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (solcDecodeLenCheckOkUnsigned (by simpa using hsz36) hsize) - -theorem uniswapV3PoolTicksEvmDecodeShort {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 24 == I.calldata.extract 0 4) = true) - (hshort : I.calldata.size < 36) : - RDrev code g (initState cA gh bl σ σ₀ g A I) := by - have hreach := uniswapV3PoolTicksReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - have hlt : - UInt256.lt (UInt256.sub (UInt256.ofNat I.calldata.size) ⟨4⟩) ⟨32⟩ = ⟨1⟩ := by - apply ult_one - rw [usub_ofNat_word_toNat (by - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega) hsize] - rw [show (⟨32⟩ : UInt256).toNat = 32 from by decide] - rw [show (⟨4⟩ : UInt256).toNat = 4 from by decide] - omega - exact RD.solcExternalStaticArgsShortReverts (need := ⟨32⟩) - (entry := ⟨2088⟩) (ret := ⟨2120⟩) (decoded := ⟨2110⟩) hreach - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - (by rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)]; native_decide) - hlt - -set_option maxHeartbeats 3000000 in -private theorem uniswapV3PoolTicksRoutine {v : PoolImmutables} {code : ByteArray} - {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {ret : UInt256} - {R : List UInt256} {rdata : ByteArray} - {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨10605⟩ (ticksArgCleanWord ee :: ret :: R) - solcFreePtrMem (UInt256.ofNat 3) rdata (cA, σ) k C) - (hret : (D_J code 0).contains ret = true) - (hov : R.length + 12 ≤ 1024) : - ∃ k' C', RD code ee g s0 ret - (ticksInitializedRawWord σ ee :: ticksSecondsOutsideWord σ ee :: - ticksSecondsPerLiquidityWord σ ee :: ticksTickCumulativeReturnWord σ ee :: - ticksFeeGrowthOutside1Word σ ee :: ticksFeeGrowthOutside0Word σ ee :: - ticksLiquidityNetReturnWord σ ee :: ticksLiquidityGrossWord σ ee :: ret :: R) - (solcMappingHashMem ⟨5⟩ (ticksArgCleanWord ee)) (UInt256.ofNat 3) - rdata (cA, σ) k' C' := by - have hdecode {pc : UInt256} (hlo : 10605 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 11259) : - decode code pc = decode uniswapV3PoolBytecode pc := by - rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by - have hsize : 11259 ≤ uniswapV3PoolBytecode.size := by native_decide - omega) - (uniswapV3PoolTicksRoutinePatchDisjoint hlo hhi)] - have hd10605 : decode code ⟨10605⟩ = some (.JUMPDEST, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10606 : decode code ⟨10606⟩ = some (.Push .PUSH1, some (⟨5⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10608 : decode code ⟨10608⟩ = some (.Push .PUSH1, some (⟨32⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10610 : decode code ⟨10610⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10611 : decode code ⟨10611⟩ = some (.Push .PUSH1, some (⟨0⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10613 : decode code ⟨10613⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10614 : decode code ⟨10614⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10615 : decode code ⟨10615⟩ = some (.MSTORE, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10616 : decode code ⟨10616⟩ = some (.Push .PUSH1, some (⟨64⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10618 : decode code ⟨10618⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10619 : decode code ⟨10619⟩ = some (.KECCAK256, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10620 : decode code ⟨10620⟩ = some (.DUP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10621 : decode code ⟨10621⟩ = some (.SLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10622 : decode code ⟨10622⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10624 : decode code ⟨10624⟩ = some (.DUP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10625 : decode code ⟨10625⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10626 : decode code ⟨10626⟩ = some (.SLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10627 : decode code ⟨10627⟩ = some (.Push .PUSH1, some (⟨2⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10629 : decode code ⟨10629⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10630 : decode code ⟨10630⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10631 : decode code ⟨10631⟩ = some (.SLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10632 : decode code ⟨10632⟩ = some (.Push .PUSH1, some (⟨3⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10634 : decode code ⟨10634⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10635 : decode code ⟨10635⟩ = some (.SWAP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10636 : decode code ⟨10636⟩ = some (.ADD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10637 : decode code ⟨10637⟩ = some (.SLOAD, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10638 : decode code ⟨10638⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10640 : decode code ⟨10640⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10642 : decode code ⟨10642⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10644 : decode code ⟨10644⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10645 : decode code ⟨10645⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10646 : decode code ⟨10646⟩ = some (.DUP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10647 : decode code ⟨10647⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10648 : decode code ⟨10648⟩ = some (.SWAP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10649 : decode code ⟨10649⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10651 : decode code ⟨10651⟩ = some (.Push .PUSH1, some (⟨128⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10653 : decode code ⟨10653⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10654 : decode code ⟨10654⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10655 : decode code ⟨10655⟩ = some (.SWAP4, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10656 : decode code ⟨10656⟩ = some (.DIV, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10657 : decode code ⟨10657⟩ = some (.Push .PUSH1, some (⟨15⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10659 : decode code ⟨10659⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10660 : decode code ⟨10660⟩ = some (.SWAP3, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10661 : decode code ⟨10661⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10662 : decode code ⟨10662⟩ = some (.Push .PUSH1, some (⟨6⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10664 : decode code ⟨10664⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10665 : decode code ⟨10665⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10666 : decode code ⟨10666⟩ = some (.SIGNEXTEND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10667 : decode code ⟨10667⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10668 : decode code ⟨10668⟩ = - some (.Push .PUSH8, some (⟨72057594037927936⟩, 8)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10677 : decode code ⟨10677⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10678 : decode code ⟨10678⟩ = some (.DIV, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10679 : decode code ⟨10679⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10681 : decode code ⟨10681⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10683 : decode code ⟨10683⟩ = some (.Push .PUSH1, some (⟨160⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10685 : decode code ⟨10685⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10686 : decode code ⟨10686⟩ = some (.SUB, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10687 : decode code ⟨10687⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10688 : decode code ⟨10688⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10689 : decode code ⟨10689⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10691 : decode code ⟨10691⟩ = some (.Push .PUSH1, some (⟨216⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10693 : decode code ⟨10693⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10694 : decode code ⟨10694⟩ = some (.DUP2, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10695 : decode code ⟨10695⟩ = some (.DIV, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10696 : decode code ⟨10696⟩ = - some (.Push .PUSH4, some (⟨4294967295⟩, 4)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10701 : decode code ⟨10701⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10702 : decode code ⟨10702⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10703 : decode code ⟨10703⟩ = some (.Push .PUSH1, some (⟨1⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10705 : decode code ⟨10705⟩ = some (.Push .PUSH1, some (⟨248⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10707 : decode code ⟨10707⟩ = some (.SHL, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10708 : decode code ⟨10708⟩ = some (.SWAP1, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10709 : decode code ⟨10709⟩ = some (.DIV, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10710 : decode code ⟨10710⟩ = some (.Push .PUSH1, some (⟨255⟩, 1)) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10712 : decode code ⟨10712⟩ = some (.AND, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10713 : decode code ⟨10713⟩ = some (.DUP9, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have hd10714 : decode code ⟨10714⟩ = some (.JUMP, .none) := by - rw [hdecode (by native_decide) (by native_decide)] - native_decide - have rd10619Pre := evm_run h with [ - raw jumpdest hd10605 (by evm_ov), - raw push1 ⟨5⟩ hd10606 (by evm_ov), - raw push1 ⟨32⟩ hd10608 (by evm_ov), - raw mstore 0 (solcMappingBaseSlotMem ⟨5⟩) (UInt256.ofNat 3) hd10610 mem_cost - (by rfl) (by native_decide) (by evm_ov), - raw push1 ⟨0⟩ hd10611 (by evm_ov), - raw swap1 hd10613 (by evm_ov), - raw dup2 hd10614 (by evm_ov), - raw mstore 0 (solcMappingHashMem ⟨5⟩ (ticksArgCleanWord ee)) - (UInt256.ofNat 3) hd10615 mem_cost (by rfl) (by native_decide) (by evm_ov), - raw push1 ⟨64⟩ hd10616 (by evm_ov), - raw swap1 hd10618 (by evm_ov)] - have hslot := solcMappingKeccakSlot ⟨5⟩ (ticksArgCleanWord ee) - have rd10620 := rd10619Pre.keccak256 0 (solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee)) - (UInt256.ofNat 3) hd10619 mem_cost - (by simpa [show (⟨0⟩ : UInt256).toNat = 0 from by decide, - show (⟨64⟩ : UInt256).toNat = 64 from by decide] using hslot) - (by native_decide) (by evm_ov) - have rd10621 := evm_run rd10620 with [raw dup1 hd10620 (by evm_ov)] - obtain ⟨_, _, rd10622⟩ := rd10621.sload hd10621 (by evm_ov) - have rd10626Pre := evm_run rd10622 with [ - raw push1 ⟨1⟩ hd10622 (by evm_ov), - raw dup3 hd10624 (by evm_ov), - raw add hd10625 (by evm_ov)] - obtain ⟨_, _, rd10627⟩ := rd10626Pre.sload hd10626 (by evm_ov) - have rd10631Pre := evm_run rd10627 with [ - raw push1 ⟨2⟩ hd10627 (by evm_ov), - raw dup4 hd10629 (by evm_ov), - raw add hd10630 (by evm_ov)] - obtain ⟨_, _, rd10632⟩ := rd10631Pre.sload hd10631 (by evm_ov) - have rd10637Pre := evm_run rd10632 with [ - raw push1 ⟨3⟩ hd10632 (by evm_ov), - raw swap1 hd10634 (by evm_ov), - raw swap4 hd10635 (by evm_ov), - raw add hd10636 (by evm_ov)] - obtain ⟨_, _, rd10638⟩ := rd10637Pre.sload hd10637 (by evm_ov) - have rd10659Pre := evm_run rd10638 with [ - raw push1 ⟨1⟩ hd10638 (by evm_ov), - raw push1 ⟨1⟩ hd10640 (by evm_ov), - raw push1 ⟨128⟩ hd10642 (by evm_ov), - raw shl hd10644 (by evm_ov), - raw sub hd10645 (by evm_ov), - raw dup4 hd10646 (by evm_ov), - raw and hd10647 (by evm_ov), - raw swap4 hd10648 (by evm_ov), - raw push1 ⟨1⟩ hd10649 (by evm_ov), - raw push1 ⟨128⟩ hd10651 (by evm_ov), - raw shl hd10653 (by evm_ov), - raw swap1 hd10654 (by evm_ov), - raw swap4 hd10655 (by evm_ov), - raw div hd10656 (by evm_ov), - raw push1 ⟨15⟩ hd10657 (by evm_ov)] - have rd10660 := ticksRDSignextend rd10659Pre hd10659 (by evm_ov) - have rd10666Pre := evm_run rd10660 with [ - raw swap3 hd10660 (by evm_ov), - raw swap1 hd10661 (by evm_ov), - raw push1 ⟨6⟩ hd10662 (by evm_ov), - raw dup2 hd10664 (by evm_ov), - raw swap1 hd10665 (by evm_ov)] - have rd10667 := ticksRDSignextend rd10666Pre hd10666 (by evm_ov) - have rd10668 := evm_run rd10667 with [raw swap1 hd10667 (by evm_ov)] - have rd10677Ex : ∃ k' C', RD code ee g s0 ⟨10677⟩ - (⟨72057594037927936⟩ :: - (σ.find? ee.codeOwner |>.option ⟨0⟩ - (fun ac => ac.storage.findD (solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee) + ⟨3⟩) - ⟨0⟩)) :: - UInt256.signextend ⟨6⟩ - (σ.find? ee.codeOwner |>.option ⟨0⟩ - (fun ac => ac.storage.findD (solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee) + ⟨3⟩) - ⟨0⟩)) :: - (σ.find? ee.codeOwner |>.option ⟨0⟩ - (fun ac => ac.storage.findD (solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee) + ⟨2⟩) - ⟨0⟩)) :: - (σ.find? ee.codeOwner |>.option ⟨0⟩ - (fun ac => ac.storage.findD (solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee) + ⟨1⟩) - ⟨0⟩)) :: - UInt256.signextend ⟨15⟩ - (UInt256.div - (σ.find? ee.codeOwner |>.option ⟨0⟩ - (fun ac => ac.storage.findD (solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee)) ⟨0⟩)) - (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩)) :: - UInt256.land - (σ.find? ee.codeOwner |>.option ⟨0⟩ - (fun ac => ac.storage.findD (solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee)) ⟨0⟩)) - (UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨1⟩) :: - ret :: R) - (solcMappingHashMem ⟨5⟩ (ticksArgCleanWord ee)) (UInt256.ofNat 3) - rdata (cA, σ) k' C' := by - exact ⟨_, _, by - simpa using rd10668.pushConst ⟨72057594037927936⟩ - (width := 8) (op := .PUSH8) - (by decide : Operation.POp.PUSH8 ≠ .PUSH0) hd10668 (by evm_ov)⟩ - obtain ⟨_, _, rd10677⟩ := rd10677Ex - have rd10714Pre := evm_run rd10677 with [ - raw dup2 hd10677 (by evm_ov), - raw div hd10678 (by evm_ov), - raw push1 ⟨1⟩ hd10679 (by evm_ov), - raw push1 ⟨1⟩ hd10681 (by evm_ov), - raw push1 ⟨160⟩ hd10683 (by evm_ov), - raw shl hd10685 (by evm_ov), - raw sub hd10686 (by evm_ov), - raw and hd10687 (by evm_ov), - raw swap1 hd10688 (by evm_ov), - raw push1 ⟨1⟩ hd10689 (by evm_ov), - raw push1 ⟨216⟩ hd10691 (by evm_ov), - raw shl hd10693 (by evm_ov), - raw dup2 hd10694 (by evm_ov), - raw div hd10695 (by evm_ov), - raw push4 ⟨4294967295⟩ hd10696 (by evm_ov), - raw and hd10701 (by evm_ov), - raw swap1 hd10702 (by evm_ov), - raw push1 ⟨1⟩ hd10703 (by evm_ov), - raw push1 ⟨248⟩ hd10705 (by evm_ov), - raw shl hd10707 (by evm_ov), - raw swap1 hd10708 (by evm_ov), - raw div hd10709 (by evm_ov), - raw push1 ⟨255⟩ hd10710 (by evm_ov), - raw and hd10712 (by evm_ov), - raw dup9 hd10713 (by evm_ov)] - have rdRet := rd10714Pre.jump hd10714 hret (by evm_ov) - have hbase : ticksBaseSlot ee = solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee) := - ticksBaseSlot_eq_solcMappingSlot ee - have hmask128 : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨1⟩ = uint128Mask := by - native_decide - have hshift128 : UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩ = ticksShiftBytes 16 := by - native_decide - have hshift56 : (⟨72057594037927936⟩ : UInt256) = ticksShiftBytes 7 := by - native_decide - have hmask160 : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask := by - native_decide - have hshift216 : UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨216⟩ = ticksShiftBytes 27 := by - native_decide - have hmask32 : (⟨4294967295⟩ : UInt256) = ticksUint32Mask := by - native_decide - have hshift248 : UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨248⟩ = ticksShiftBytes 31 := by - native_decide - have hmask8 : (⟨255⟩ : UInt256) = slot0Uint8Mask := by - native_decide - have hsecondsLiqComm : - UInt256.land slot0Uint160Mask - (UInt256.div (solcSlotWord σ ee (solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee) + ⟨3⟩)) - (ticksShiftBytes 7)) = - UInt256.land - (UInt256.div (solcSlotWord σ ee (solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee) + ⟨3⟩)) - (ticksShiftBytes 7)) - slot0Uint160Mask := by - rw [u256_land_comm] - have hsecondsOutComm : - UInt256.land ticksUint32Mask - (UInt256.div (solcSlotWord σ ee (solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee) + ⟨3⟩)) - (ticksShiftBytes 27)) = - UInt256.land - (UInt256.div (solcSlotWord σ ee (solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee) + ⟨3⟩)) - (ticksShiftBytes 27)) - ticksUint32Mask := by - rw [u256_land_comm] - have hinitComm : - UInt256.land slot0Uint8Mask - (UInt256.div (solcSlotWord σ ee (solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee) + ⟨3⟩)) - (ticksShiftBytes 31)) = - UInt256.land - (UInt256.div (solcSlotWord σ ee (solcMappingSlot ⟨5⟩ (ticksArgCleanWord ee) + ⟨3⟩)) - (ticksShiftBytes 31)) - slot0Uint8Mask := by - rw [u256_land_comm] - exact ⟨_, _, by - rw [hmask128, hshift128, hshift56, hmask160, hshift216, hmask32, hshift248, - hmask8] at rdRet - simpa [ticksInitializedRawWord, ticksSecondsOutsideWord, ticksSecondsPerLiquidityWord, - ticksTickCumulativeReturnWord, ticksFeeGrowthOutside1Word, ticksFeeGrowthOutside0Word, - ticksLiquidityNetReturnWord, ticksLiquidityNetRawWord, ticksLiquidityGrossWord, - ticksPacked3Word, ticksPacked3Slot, ticksPacked0Word, solcSlotWord, hbase, - hsecondsLiqComm, hsecondsOutComm, hinitComm] using rdRet⟩ - -set_option maxHeartbeats 3000000 in -theorem uniswapV3PoolTicksReturn {v : PoolImmutables} {code : ByteArray} - {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} - {initialized secondsOut secondsLiq tick fee1 fee0 net gross : UInt256} - {R : List UInt256} {scratch rdata : ByteArray} - {acc : Batteries.RBSet AccountAddress compare × AccountMap} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (h : RD code ee g s0 ⟨2120⟩ - (initialized :: secondsOut :: secondsLiq :: tick :: fee1 :: fee0 :: net :: gross :: R) - scratch (UInt256.ofNat 3) rdata acc k C) - (hscratch : scratch.size = 96) - (hread64 : scratch.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) - (hov : R.length + 24 ≤ 1024) : - RDret code g s0 acc - (UInt256.toByteArray (UInt256.land gross uint128Mask) ++ - UInt256.toByteArray (UInt256.signextend ⟨15⟩ net) ++ - UInt256.toByteArray fee0 ++ UInt256.toByteArray fee1 ++ - UInt256.toByteArray (UInt256.signextend ⟨6⟩ tick) ++ - UInt256.toByteArray (UInt256.land secondsLiq slot0Uint160Mask) ++ - UInt256.toByteArray (UInt256.land secondsOut ticksUint32Mask) ++ - UInt256.toByteArray (slot0BoolReturnWord initialized)) := by - let gross' := UInt256.land gross uint128Mask - let net' := UInt256.signextend ⟨15⟩ net - let tick' := UInt256.signextend ⟨6⟩ tick - let secondsLiq' := UInt256.land secondsLiq slot0Uint160Mask - let secondsOut' := UInt256.land secondsOut ticksUint32Mask - let initialized' := slot0BoolReturnWord initialized - have hmask128 : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨128⟩) ⟨1⟩ = uint128Mask := by - native_decide - have hmask160 : - UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = - slot0Uint160Mask := by - native_decide - have hmask32 : (⟨4294967295⟩ : UInt256) = ticksUint32Mask := by - native_decide - have rd2134 := evm_run h with [ - raw jumpdest (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨64⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 3) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost (ticksScratch_mload64 hscratch hread64) (by decide) - (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨128⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw shl (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov)] - have rd2135 := RD.swap10 rd2134 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by omega) - have rd2136 := evm_run rd2135 with [ - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov)] - have rd2137 := RD.dup10 rd2136 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by omega) - have rd2140 := evm_run rd2137 with [ - raw mstore 6 (ticksScratchReturnMem1 scratch gross') (UInt256.ofNat 5) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [gross'] - rw [hmask128, show (⟨128⟩ : UInt256).toNat = 128 from by decide, - ticksScratchReturnMem1_eq] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨15⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov)] - have rd2141 := RD.swap8 rd2140 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by simp only [List.length_cons]; omega) - have rd2142 := evm_run rd2141 with [ - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov)] - have rd2143 := RD.swap8 rd2142 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by simp only [List.length_cons]; omega) - have rd2144 := ticksRDSignextend rd2143 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - have rd2146 := evm_run rd2144 with [ - raw push1 ⟨32⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov)] - have rd2147 := RD.dup10 rd2146 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by omega) - have rd2169 := evm_run rd2147 with [ - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 (ticksScratchReturnMem2 scratch gross' net') (UInt256.ofNat 6) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [net'] - rw [show ((⟨128⟩ : UInt256) + ⟨32⟩).toNat = 160 from by decide, - ticksScratchReturnMem2_eq] - rfl) - (by decide) (by evm_ov), - raw dup8 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup8 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap6 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap6 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 (ticksScratchReturnMem3 scratch gross' net' fee0) (UInt256.ofNat 7) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - rw [show ((⟨64⟩ : UInt256) + ⟨128⟩).toNat = 192 from by decide, - ticksScratchReturnMem3_eq] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨96⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup8 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap4 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap4 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 (ticksScratchReturnMem4 scratch gross' net' fee0 fee1) - (UInt256.ofNat 8) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - rw [show ((⟨128⟩ : UInt256) + ⟨96⟩).toNat = 224 from by decide, - ticksScratchReturnMem4_eq] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨6⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap2 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap2 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov)] - have rd2170 := ticksRDSignextend rd2169 - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) - (by evm_ov) - exact evm_run rd2170 with [ - raw push1 ⟨128⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup7 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 (ticksScratchReturnMem5 scratch gross' net' fee0 fee1 tick') - (UInt256.ofNat 9) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [tick'] - rw [show ((⟨128⟩ : UInt256) + ⟨128⟩).toNat = 256 from by decide, - ticksScratchReturnMem5_eq] - rfl) - (by decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨1⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨160⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw shl (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨160⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup6 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 - (ticksScratchReturnMem6 scratch gross' net' fee0 fee1 tick' secondsLiq') - (UInt256.ofNat 10) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [secondsLiq'] - rw [hmask160, show ((⟨128⟩ : UInt256) + ⟨160⟩).toNat = 288 from by decide, - u256_land_comm slot0Uint160Mask secondsLiq, ticksScratchReturnMem6_eq] - rfl) - (by decide) (by evm_ov), - raw push4 ⟨4294967295⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw and (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨192⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup5 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 - (ticksScratchReturnMem7 scratch gross' net' fee0 fee1 tick' secondsLiq' secondsOut') - (UInt256.ofNat 11) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [secondsOut'] - rw [hmask32, show ((⟨128⟩ : UInt256) + ⟨192⟩).toNat = 320 from by decide, - u256_land_comm ticksUint32Mask secondsOut, ticksScratchReturnMem7_eq] - rfl) - (by decide) (by evm_ov), - raw iszero (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw iszero (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push1 ⟨224⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup4 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw mstore 3 - (ticksScratchReturnMem scratch gross' net' fee0 fee1 tick' secondsLiq' secondsOut' - initialized') - (UInt256.ofNat 12) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [initialized', slot0BoolReturnWord] - rw [show ((⟨128⟩ : UInt256) + ⟨224⟩).toNat = 352 from by decide, - ticksScratchReturnMem_eq] - rfl) - (by decide) (by evm_ov), - raw mload 0 ⟨128⟩ (UInt256.ofNat 12) (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (ticksScratchReturnMem_mload64 gross' net' fee0 fee1 tick' secondsLiq' secondsOut' - initialized' hscratch hread64) - (by decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw dup2 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw sub (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw push2 ⟨256⟩ (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw add (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw swap1 (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) (by evm_ov), - raw ret 0 - (UInt256.toByteArray gross' ++ UInt256.toByteArray net' ++ - UInt256.toByteArray fee0 ++ UInt256.toByteArray fee1 ++ - UInt256.toByteArray tick' ++ UInt256.toByteArray secondsLiq' ++ - UInt256.toByteArray secondsOut' ++ UInt256.toByteArray initialized') - (by - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide) mem_cost - (by - dsimp [gross', net', tick', secondsLiq', secondsOut', initialized'] - rw [show (⟨128⟩ : UInt256).toNat = 128 from by decide, - show ((⟨256⟩ : UInt256) + UInt256.sub (⟨128⟩ : UInt256) ⟨128⟩).toNat = - 256 from by decide] - exact ticksScratchReturnMem_read128_256 - (UInt256.land gross uint128Mask) (UInt256.signextend ⟨15⟩ net) fee0 fee1 - (UInt256.signextend ⟨6⟩ tick) (UInt256.land secondsLiq slot0Uint160Mask) - (UInt256.land secondsOut ticksUint32Mask) (slot0BoolReturnWord initialized) - hscratch) - (by evm_ov)] - -private theorem uniswapV3PoolTicksLoadedToReturn {v : PoolImmutables} - {code : ByteArray} {cA gh bl σ σ₀ A I} {g : Sat256} {k C : ℕ} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (rdLoaded : RD code I g (initState cA gh bl σ σ₀ g A I) ⟨2120⟩ - (ticksInitializedRawWord σ I :: ticksSecondsOutsideWord σ I :: - ticksSecondsPerLiquidityWord σ I :: ticksTickCumulativeReturnWord σ I :: - ticksFeeGrowthOutside1Word σ I :: ticksFeeGrowthOutside0Word σ I :: - ticksLiquidityNetReturnWord σ I :: ticksLiquidityGrossWord σ I :: - ⟨2120⟩ :: [solcSelectorWord I]) - (solcMappingHashMem ⟨5⟩ (ticksArgCleanWord I)) (UInt256.ofNat 3) - ByteArray.empty (cA, σ) k C) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land (ticksLiquidityGrossWord σ I) uint128Mask) ++ - UInt256.toByteArray (UInt256.signextend ⟨15⟩ (ticksLiquidityNetReturnWord σ I)) ++ - UInt256.toByteArray (ticksFeeGrowthOutside0Word σ I) ++ - UInt256.toByteArray (ticksFeeGrowthOutside1Word σ I) ++ - UInt256.toByteArray - (UInt256.signextend ⟨6⟩ (ticksTickCumulativeReturnWord σ I)) ++ - UInt256.toByteArray - (UInt256.land (ticksSecondsPerLiquidityWord σ I) slot0Uint160Mask) ++ - UInt256.toByteArray - (UInt256.land (ticksSecondsOutsideWord σ I) ticksUint32Mask) ++ - UInt256.toByteArray - (slot0BoolReturnWord (ticksInitializedRawWord σ I))) := by - exact uniswapV3PoolTicksReturn hpatch - (initialized := ticksInitializedRawWord σ I) - (secondsOut := ticksSecondsOutsideWord σ I) - (secondsLiq := ticksSecondsPerLiquidityWord σ I) - (tick := ticksTickCumulativeReturnWord σ I) - (fee1 := ticksFeeGrowthOutside1Word σ I) - (fee0 := ticksFeeGrowthOutside0Word σ I) - (net := ticksLiquidityNetReturnWord σ I) - (gross := ticksLiquidityGrossWord σ I) - (R := [⟨2120⟩, solcSelectorWord I]) rdLoaded - (solcMappingHashMem_size ⟨5⟩ (ticksArgCleanWord I)) - (solcMappingHashMem_read64 ⟨5⟩ (ticksArgCleanWord I)) - (by simp only [List.length_cons, List.length_nil]; omega) - -theorem uniswapV3PoolTicksEvm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 24 == I.calldata.extract 0 4) = true) - (hsz36 : 36 ≤ I.calldata.size) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land (ticksLiquidityGrossWord σ I) uint128Mask) ++ - UInt256.toByteArray (UInt256.signextend ⟨15⟩ (ticksLiquidityNetReturnWord σ I)) ++ - UInt256.toByteArray (ticksFeeGrowthOutside0Word σ I) ++ - UInt256.toByteArray (ticksFeeGrowthOutside1Word σ I) ++ - UInt256.toByteArray - (UInt256.signextend ⟨6⟩ (ticksTickCumulativeReturnWord σ I)) ++ - UInt256.toByteArray - (UInt256.land (ticksSecondsPerLiquidityWord σ I) slot0Uint160Mask) ++ - UInt256.toByteArray - (UInt256.land (ticksSecondsOutsideWord σ I) ticksUint32Mask) ++ - UInt256.toByteArray - (slot0BoolReturnWord (ticksInitializedRawWord σ I))) := by - have hreach := uniswapV3PoolTicksReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - have hdecoded := uniswapV3PoolTicksExternalLenOk hpatch hreach hsz36 hsize - obtain ⟨_, _, rdDecoded⟩ := hdecoded - obtain ⟨_, _, rdRoutine⟩ := uniswapV3PoolTicksDecodedReachRoutine hpatch rdDecoded - (by simp only [List.length_cons, List.length_nil]; omega) - obtain ⟨_, _, rdLoaded⟩ := uniswapV3PoolTicksRoutine hpatch rdRoutine - (uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide)) - (by simp only [List.length_cons, List.length_nil]; omega) - exact uniswapV3PoolTicksLoadedToReturn hpatch rdLoaded - -theorem ticksReturnEncoding (σ : AccountMap) (I : ExecutionEnv) : - encodeReturnValues? [uint128, int128, uint256, uint256, int56, uint160, uint32, boolTy] - (ticksReturnValues σ I) = - some (UInt256.toByteArray (UInt256.land (ticksLiquidityGrossWord σ I) uint128Mask) ++ - UInt256.toByteArray (UInt256.signextend ⟨15⟩ (ticksLiquidityNetReturnWord σ I)) ++ - UInt256.toByteArray (ticksFeeGrowthOutside0Word σ I) ++ - UInt256.toByteArray (ticksFeeGrowthOutside1Word σ I) ++ - UInt256.toByteArray - (UInt256.signextend ⟨6⟩ (ticksTickCumulativeReturnWord σ I)) ++ - UInt256.toByteArray - (UInt256.land (ticksSecondsPerLiquidityWord σ I) slot0Uint160Mask) ++ - UInt256.toByteArray - (UInt256.land (ticksSecondsOutsideWord σ I) ticksUint32Mask) ++ - UInt256.toByteArray - (slot0BoolReturnWord (ticksInitializedRawWord σ I))) := by - have hgross : UInt256.land (ticksLiquidityGrossWord σ I) uint128Mask = - ticksLiquidityGrossWord σ I := by - exact uint128Mask_clean (by - simpa [ticksLiquidityGrossWord] using uint128Mask_bound (ticksPacked0Word σ I)) - have hnet : UInt256.signextend ⟨15⟩ (ticksLiquidityNetReturnWord σ I) = - ticksLiquidityNetReturnWord σ I := by - dsimp [ticksLiquidityNetReturnWord] - exact ticksSignextendFifteen_idempotent (ticksLiquidityNetRawWord σ I) - have htick : UInt256.signextend ⟨6⟩ (ticksTickCumulativeReturnWord σ I) = - ticksTickCumulativeReturnWord σ I := by - dsimp [ticksTickCumulativeReturnWord] - exact observationsSignextendSix_idempotent (ticksPacked3Word σ I) - have hsecondsLiq : - UInt256.land (ticksSecondsPerLiquidityWord σ I) slot0Uint160Mask = - ticksSecondsPerLiquidityWord σ I := by - exact slot0Uint160Mask_clean (by - simpa [ticksSecondsPerLiquidityWord] using - slot0Uint160Mask_bound - (UInt256.div (ticksPacked3Word σ I) (ticksShiftBytes 7))) - have hsecondsOut : - UInt256.land (ticksSecondsOutsideWord σ I) ticksUint32Mask = - ticksSecondsOutsideWord σ I := by - exact ticksUint32Mask_clean (by - simpa [ticksSecondsOutsideWord] using - ticksUint32Mask_bound - (UInt256.div (ticksPacked3Word σ I) (ticksShiftBytes 27))) - rw [hgross, hnet, htick, hsecondsLiq, hsecondsOut] - have hwordGross : EVM.word (ticksLiquidityGrossWord σ I).toNat = - ticksLiquidityGrossWord σ I := u256_ofNat_toNat _ - have hwordFee0 : EVM.word (ticksFeeGrowthOutside0Word σ I).toNat = - ticksFeeGrowthOutside0Word σ I := u256_ofNat_toNat _ - have hwordFee1 : EVM.word (ticksFeeGrowthOutside1Word σ I).toNat = - ticksFeeGrowthOutside1Word σ I := u256_ofNat_toNat _ - have hwordSecondsLiq : EVM.word (ticksSecondsPerLiquidityWord σ I).toNat = - ticksSecondsPerLiquidityWord σ I := u256_ofNat_toNat _ - have hwordSecondsOut : EVM.word (ticksSecondsOutsideWord σ I).toNat = - ticksSecondsOutsideWord σ I := u256_ofNat_toNat _ - have hgrossLt : (ticksLiquidityGrossWord σ I).toNat < EVM.twoPow 128 := by - simpa [ticksLiquidityGrossWord] using uint128Mask_bound (ticksPacked0Word σ I) - have hfee0Lt : (ticksFeeGrowthOutside0Word σ I).toNat < EVM.twoPow 256 := by - change (ticksFeeGrowthOutside0Word σ I).val.val < EVM.twoPow 256 - exact (ticksFeeGrowthOutside0Word σ I).val.isLt - have hfee1Lt : (ticksFeeGrowthOutside1Word σ I).toNat < EVM.twoPow 256 := by - change (ticksFeeGrowthOutside1Word σ I).val.val < EVM.twoPow 256 - exact (ticksFeeGrowthOutside1Word σ I).val.isLt - have hsecondsLiqLt : (ticksSecondsPerLiquidityWord σ I).toNat < EVM.twoPow 160 := by - simpa [ticksSecondsPerLiquidityWord] using - slot0Uint160Mask_bound - (UInt256.div (ticksPacked3Word σ I) (ticksShiftBytes 7)) - have hsecondsOutLt : (ticksSecondsOutsideWord σ I).toNat < EVM.twoPow 32 := by - simpa [ticksSecondsOutsideWord] using - ticksUint32Mask_bound - (UInt256.div (ticksPacked3Word σ I) (ticksShiftBytes 27)) - have hencGross : - encodeABIValue? uint128 (.int (Int.ofNat (ticksLiquidityGrossWord σ I).toNat)) = - some (EVM.Word.toBytesBE (ticksLiquidityGrossWord σ I)) := by - simp [uint128, uint128Int, encodeABIValue?, encodeABIWord?, hwordGross, hgrossLt] - have hencNet : - encodeABIValue? int128 - (wordToElem (.int int128Int) (ticksLiquidityNetStorageWord σ I)) = - some (EVM.Word.toBytesBE (ticksLiquidityNetReturnWord σ I)) := by - change encodeABIValue? int128 - (.int (ticksSint128Value (ticksLiquidityNetStorageWord σ I))) = - some (EVM.Word.toBytesBE (ticksLiquidityNetReturnWord σ I)) - have hge := ticksSint128Value_ge (ticksLiquidityNetStorageWord σ I) - have hlt := ticksSint128Value_lt (ticksLiquidityNetStorageWord σ I) - have hword : EVM.wordOfInt - (ticksSint128Value (ticksLiquidityNetStorageWord σ I)) = - ticksLiquidityNetReturnWord σ I := by - dsimp [ticksLiquidityNetStorageWord, ticksLiquidityNetReturnWord] - exact ticksLiquidityNetRawValue_wordOfInt (ticksLiquidityNetRawWord σ I) - simp only [int128, int128Int, encodeABIValue?, encodeABIWord?] - rw [if_neg (by decide : 128 ≠ 0), if_pos] - · rw [hword] - rfl - · constructor - · simpa [EVM.twoPow] using hge - · simpa [EVM.twoPow] using hlt - have hencFee0 : - encodeABIValue? uint256 (.int (Int.ofNat (ticksFeeGrowthOutside0Word σ I).toNat)) = - some (EVM.Word.toBytesBE (ticksFeeGrowthOutside0Word σ I)) := by - simp [uint256, uint256Int, encodeABIValue?, encodeABIWord?, hwordFee0, hfee0Lt] - have hencFee1 : - encodeABIValue? uint256 (.int (Int.ofNat (ticksFeeGrowthOutside1Word σ I).toNat)) = - some (EVM.Word.toBytesBE (ticksFeeGrowthOutside1Word σ I)) := by - simp [uint256, uint256Int, encodeABIValue?, encodeABIWord?, hwordFee1, hfee1Lt] - have hencTick : - encodeABIValue? int56 - (wordToElem (.int int56Int) (ticksTickCumulativeStorageWord σ I)) = - some (EVM.Word.toBytesBE (ticksTickCumulativeReturnWord σ I)) := by - change encodeABIValue? int56 - (.int (observationsSint56Value (ticksTickCumulativeStorageWord σ I))) = - some (EVM.Word.toBytesBE (ticksTickCumulativeReturnWord σ I)) - have hge := observationsSint56Value_ge (ticksTickCumulativeStorageWord σ I) - have hlt := observationsSint56Value_lt (ticksTickCumulativeStorageWord σ I) - have hdiv0 : - UInt256.div (ticksPacked3Word σ I) (ticksShiftBytes 0) = - ticksPacked3Word σ I := by - apply u256_inj - rw [udiv_toNat] - simp only [ticksShiftBytes, Nat.pow_zero] - rw [show (UInt256.ofNat 1).toNat = 1 by decide] - exact Nat.div_one (ticksPacked3Word σ I).toNat - have hword : EVM.wordOfInt - (observationsSint56Value (ticksTickCumulativeStorageWord σ I)) = - ticksTickCumulativeReturnWord σ I := by - dsimp [ticksTickCumulativeStorageWord, ticksTickCumulativeRawWord, - ticksTickCumulativeReturnWord] - rw [hdiv0] - exact observationsTickRawValue_wordOfInt (ticksPacked3Word σ I) - simp only [int56, int56Int, encodeABIValue?, encodeABIWord?] - rw [if_neg (by decide : 56 ≠ 0), if_pos] - · rw [hword] - rfl - · constructor - · simpa [EVM.twoPow] using hge - · simpa [EVM.twoPow] using hlt - have hencSecondsLiq : - encodeABIValue? uint160 (.int (Int.ofNat (ticksSecondsPerLiquidityWord σ I).toNat)) = - some (EVM.Word.toBytesBE (ticksSecondsPerLiquidityWord σ I)) := by - simp [uint160, uint160Int, encodeABIValue?, encodeABIWord?, hwordSecondsLiq, - hsecondsLiqLt] - have hencSecondsOut : - encodeABIValue? uint32 (.int (Int.ofNat (ticksSecondsOutsideWord σ I).toNat)) = - some (EVM.Word.toBytesBE (ticksSecondsOutsideWord σ I)) := by - simp [uint32, uint32Int, encodeABIValue?, encodeABIWord?, hwordSecondsOut, - hsecondsOutLt] - have hencInitialized : - encodeABIValue? boolTy (wordToElem .bool (ticksInitializedRawWord σ I)) = - some (EVM.Word.toBytesBE - (slot0BoolReturnWord (ticksInitializedRawWord σ I))) := - slot0BoolABIEncoding (ticksInitializedRawWord σ I) - have hhead : - abiTupleHeadSize? [uint128, int128, uint256, uint256, int56, uint160, uint32, - boolTy] = some 256 := by native_decide - have hdyn128 : isDynamicABIType uint128 = false := by native_decide - have hdynInt128 : isDynamicABIType int128 = false := by native_decide - have hdyn256 : isDynamicABIType uint256 = false := by native_decide - have hdyn56 : isDynamicABIType int56 = false := by native_decide - have hdyn160 : isDynamicABIType uint160 = false := by native_decide - have hdyn32 : isDynamicABIType uint32 = false := by native_decide - have hdynBool : isDynamicABIType boolTy = false := by native_decide - rw [toByteArray_eq_toBytesBE (ticksLiquidityGrossWord σ I), - toByteArray_eq_toBytesBE (ticksLiquidityNetReturnWord σ I), - toByteArray_eq_toBytesBE (ticksFeeGrowthOutside0Word σ I), - toByteArray_eq_toBytesBE (ticksFeeGrowthOutside1Word σ I), - toByteArray_eq_toBytesBE (ticksTickCumulativeReturnWord σ I), - toByteArray_eq_toBytesBE (ticksSecondsPerLiquidityWord σ I), - toByteArray_eq_toBytesBE (ticksSecondsOutsideWord σ I), - toByteArray_eq_toBytesBE (slot0BoolReturnWord (ticksInitializedRawWord σ I))] - simp only [ticksReturnValues, encodeReturnValues?, encodeABIValues?, - encodeABIValuesFrom?, hhead, hencGross, hencNet, hencFee0, hencFee1, hencTick, - hencSecondsLiq, hencSecondsOut, hencInitialized, hdyn128, hdynInt128, hdyn256, - hdyn56, hdyn160, hdyn32, hdynBool, bind, Option.bind, Bool.false_eq_true, if_false, - List.nil_append, List.append_nil] - apply congrArg some - apply ByteArray.ext - apply Array.toList_inj.mp - simp - -theorem uniswapV3PoolTicksBodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 24 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_ticks (v := v) (cd := I.calldata) hsel - have hvalue := uniswapV3PoolTicksValueTransport (σ_evm := σ_evm) - (σ_solm := σ_solm) (I := I) hAccounts - by_cases hsz36 : 36 ≤ I.calldata.size - · have hdecode := uniswapV3PoolTicksDecodeOk (v := v) (I := I) hsz36 - have hbody := uniswapV3PoolTicksSourceBody (v := v) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hrd := uniswapV3PoolTicksEvm (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hsz36 - exact hrd.reEquivExecutionTransport hcode hdispatch hdecode hbody hvalue hAccounts - (by - rw [show ticksTransition.returnType = - [uint128, int128, uint256, uint256, int56, uint160, uint32, boolTy] from rfl] - exact returnEquiv.returned rfl (ticksReturnEncoding σ_evm I)) - · have hshort : I.calldata.size < 36 := by omega - have hdecode := uniswapV3PoolTicksDecodeShort (v := v) (I := I) hshort - have hrd := uniswapV3PoolTicksEvmDecodeShort (v := v) (code := code) - (cA := cA) (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) - (I := I) (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel hshort - exact hrd.reEquivDecodingFailed hcode hdispatch hdecode - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/TicksInt128.lean b/Benchmarks/UniswapV3Pool/TicksInt128.lean deleted file mode 100644 index 59ffadc4..00000000 --- a/Benchmarks/UniswapV3Pool/TicksInt128.lean +++ /dev/null @@ -1,424 +0,0 @@ -import Benchmarks.UniswapV3Pool.Uint128 - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -abbrev ticksUint128Mask : UInt256 := - uint128Mask - -def ticksSint128Value (w : UInt256) : Int := - let m := w.toNat % EVM.twoPow 128 - if m < EVM.twoPow 127 then (m : Int) else (m : Int) - (EVM.twoPow 128 : Int) - -theorem ticksUint128Mask_toNat : - ticksUint128Mask.toNat = 2 ^ 128 - 1 := by - exact ulit_toNat' _ (by norm_num [UInt256.size]) - -private theorem signextend_fifteen_norm (w : UInt256) : UInt256.signextend ⟨15⟩ w = - if UInt256.land w (UInt256.ofNat (2 ^ 127)) = ⟨0⟩ then - UInt256.land w (UInt256.ofNat (2 ^ 127 - 1)) - else UInt256.lor w (UInt256.ofNat (UInt256.size - 2 ^ 127)) := by - unfold UInt256.signextend - rw [if_pos (by native_decide : (⟨15⟩ : UInt256).toNat ≤ 31)] - have htest : (⟨15⟩ : UInt256) * ⟨8⟩ + ⟨7⟩ = ⟨127⟩ := by native_decide - simp only [htest] - have hsign : (⟨1⟩ : UInt256) <<< (⟨127⟩ : UInt256) = UInt256.ofNat (2 ^ 127) := by - native_decide - rw [hsign] - have hsub1 : UInt256.ofNat (2 ^ 127) - ⟨1⟩ = UInt256.ofNat (2 ^ 127 - 1) := by - native_decide - have hsub2 : UInt256.size.toUInt256 - UInt256.ofNat (2 ^ 127) = - UInt256.ofNat (UInt256.size - 2 ^ 127) := by - native_decide - rw [hsub1, hsub2] - change (if UInt256.land w (UInt256.ofNat (2 ^ 127)) ≠ ⟨0⟩ then - UInt256.lor w (UInt256.ofNat (UInt256.size - 2 ^ 127)) - else UInt256.land w (UInt256.ofNat (2 ^ 127 - 1))) = _ - by_cases hzero : UInt256.land w (UInt256.ofNat (2 ^ 127)) = ⟨0⟩ - · rw [if_neg (by exact not_not.mpr hzero), if_pos hzero] - · rw [if_pos hzero, if_neg hzero] - -private theorem signextend_fifteen_sign_bit_zero (w : UInt256) - (hm : w.toNat % EVM.twoPow 128 < EVM.twoPow 127) : - UInt256.land w (UInt256.ofNat (2 ^ 127)) = ⟨0⟩ := by - apply u256_inj - rw [u256_land_toNat] - have hbitm : (w.toNat % EVM.twoPow 128).testBit 127 = false := by - exact Nat.testBit_lt_two_pow (x := w.toNat % EVM.twoPow 128) (i := 127) hm - change (w.toNat % 2 ^ 128).testBit 127 = false at hbitm - rw [Nat.testBit_mod_two_pow] at hbitm - have hbitw : w.toNat.testBit 127 = false := by simpa using hbitm - rw [show (UInt256.ofNat (2 ^ 127)).toNat = 2 ^ 127 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] - change (w.toNat &&& 2 ^ 127) % UInt256.size = (⟨0⟩ : UInt256).toNat - rw [Nat.and_two_pow, hbitw] - norm_num - -private theorem signextend_fifteen_sign_bit_ne_zero (w : UInt256) - (hm : ¬ w.toNat % EVM.twoPow 128 < EVM.twoPow 127) : - UInt256.land w (UInt256.ofNat (2 ^ 127)) ≠ ⟨0⟩ := by - intro hzero - have hmhi : w.toNat % EVM.twoPow 128 < EVM.twoPow 128 := - Nat.mod_lt _ (by norm_num [EVM.twoPow]) - have hmge : EVM.twoPow 127 ≤ w.toNat % EVM.twoPow 128 := by omega - have hdiv : (w.toNat % EVM.twoPow 128) / EVM.twoPow 127 = 1 := by - apply Nat.div_eq_of_lt_le (k := 1) - · simpa [EVM.twoPow] using hmge - · simpa [EVM.twoPow] using hmhi - have hbitm : (w.toNat % EVM.twoPow 128).testBit 127 = true := by - simp [Nat.testBit, Nat.shiftRight_eq_div_pow, EVM.twoPow] - have hdiv' : w.toNat % 340282366920938463463374607431768211456 / 170141183460469231731687303715884105728 = 1 := by - simpa [EVM.twoPow] using hdiv - rw [hdiv'] - change (w.toNat % 2 ^ 128).testBit 127 = true at hbitm - rw [Nat.testBit_mod_two_pow] at hbitm - have hbitw : w.toNat.testBit 127 = true := by simpa using hbitm - have htoNat := congrArg UInt256.toNat hzero - rw [u256_land_toNat] at htoNat - rw [show (UInt256.ofNat (2 ^ 127)).toNat = 2 ^ 127 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] at htoNat - change (w.toNat &&& 2 ^ 127) % UInt256.size = (⟨0⟩ : UInt256).toNat at htoNat - rw [Nat.and_two_pow, hbitw] at htoNat - norm_num [UInt256.size] at htoNat - -private theorem nat_lor_high_mask_127 (n : Nat) (hn : n < 2 ^ 256) : - Nat.lor n (2 ^ 256 - 2 ^ 127) = n % 2 ^ 127 + (2 ^ 256 - 2 ^ 127) := by - have hmask : 2 ^ 256 - 2 ^ 127 = (2 ^ (256 - 127) - 1) <<< 127 := by - rw [Nat.shiftLeft_eq] - norm_num [Nat.pow_add] - rw [hmask] - rw [Nat.shiftLeft_eq] - rw [← nat_lor_shift_add (n % 2 ^ 127) (2 ^ (256 - 127) - 1) 127 - (Nat.mod_lt _ (by norm_num))] - apply Nat.eq_of_testBit_eq - intro i - change (n ||| ((2 ^ (256 - 127) - 1) * 2 ^ 127)).testBit i = - ((n % 2 ^ 127) ||| ((2 ^ (256 - 127) - 1) * 2 ^ 127)).testBit i - rw [Nat.testBit_or, Nat.testBit_or] - rw [show (2 ^ (256 - 127) - 1) * 2 ^ 127 = - (2 ^ (256 - 127) - 1) <<< 127 by rw [Nat.shiftLeft_eq]] - rw [testBit_shiftLeft] - by_cases hi55 : i < 127 - · rw [if_pos hi55] - conv_rhs => rw [Nat.testBit_mod_two_pow] - simp [hi55] - · rw [if_neg hi55] - rw [Nat.testBit_two_pow_sub_one] - by_cases hi256 : i < 256 - · have hlt201 : i - 127 < 256 - 127 := by omega - rw [decide_eq_true hlt201] - simp - · have hnbit : n.testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le hn (Nat.pow_le_pow_right (by norm_num) (by omega))) - have hmodbit : (n % 2 ^ 127).testBit i = false := by - exact Nat.testBit_lt_two_pow - (lt_of_lt_of_le (Nat.mod_lt _ (by norm_num : 0 < 2 ^ 127)) - (Nat.pow_le_pow_right (by norm_num) (by omega))) - have hnot201 : ¬ i - 127 < 256 - 127 := by omega - rw [decide_eq_false hnot201, hnbit, hmodbit] - -private theorem wordOfInt_sint128_neg_toNat (m : Nat) (hmhi : m < EVM.twoPow 128) : - (EVM.wordOfInt ((m : Int) - (EVM.twoPow 128 : Int))).toNat = - UInt256.size - (EVM.twoPow 128 - m) := by - have hneg : ((m : Int) - (EVM.twoPow 128 : Int)) < 0 := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hnatAbs : ((m : Int) - (EVM.twoPow 128 : Int)).natAbs = EVM.twoPow 128 - m := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hdiffPos : EVM.twoPow 128 - m ≠ 0 := by - norm_num [EVM.twoPow] at hmhi ⊢ - omega - have hdiffLt : EVM.twoPow 128 - m < EVM.wordModulus := by - norm_num [EVM.wordModulus, EVM.twoPow] at hmhi ⊢ - omega - unfold EVM.wordOfInt - rw [if_pos hneg] - rw [hnatAbs, Nat.mod_eq_of_lt hdiffLt, if_neg hdiffPos] - change (UInt256.ofNat (EVM.wordModulus - (EVM.twoPow 128 - m))).toNat = _ - rw [ulit_toNat'] - · simp [EVM.wordModulus, EVM.twoPow, UInt256.size] - · norm_num [EVM.wordModulus, EVM.twoPow, UInt256.size] at hmhi ⊢ - omega - -theorem wordOfInt_sint128Value_eq_signextend_fifteen (w : UInt256) : - EVM.wordOfInt (ticksSint128Value w) = UInt256.signextend ⟨15⟩ w := by - apply u256_inj - rw [signextend_fifteen_norm] - unfold ticksSint128Value - let m := w.toNat % EVM.twoPow 128 - have hmdef : m = w.toNat % EVM.twoPow 128 := rfl - have hmhi : m < EVM.twoPow 128 := by - rw [hmdef] - exact Nat.mod_lt _ (by norm_num [EVM.twoPow]) - have hwlt : w.toNat < UInt256.size := by - simp [UInt256.toNat] - by_cases h : m < EVM.twoPow 127 - · have hzero : UInt256.land w (UInt256.ofNat (2 ^ 127)) = ⟨0⟩ := by - apply signextend_fifteen_sign_bit_zero - rwa [← hmdef] - rw [if_pos hzero] - have hval : - (let m := w.toNat % EVM.twoPow 128 - if m < EVM.twoPow 127 then (m : Int) else (m : Int) - (EVM.twoPow 128 : Int)) = - (m : Int) := by - dsimp - have h' : w.toNat % EVM.twoPow 128 < EVM.twoPow 127 := by rwa [← hmdef] - rw [if_pos h'] - omega - rw [hval] - have hword : (EVM.wordOfInt (m : Int)).toNat = m := by - unfold EVM.wordOfInt - rw [if_neg (by omega)] - unfold EVM.word EVM.uintN UInt256.toNat - change m % EVM.twoPow 256 = m - apply Nat.mod_eq_of_lt - norm_num [EVM.twoPow] at hmhi ⊢ - omega - rw [hword] - rw [u256_land_toNat] - rw [show (UInt256.ofNat (2 ^ 127 - 1)).toNat = 2 ^ 127 - 1 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] - change m = Nat.land w.toNat (2 ^ 127 - 1) % UInt256.size - rw [nat_land_mask_eq_mod] - have hmdef' : m = w.toNat % 2 ^ 128 := by simpa [EVM.twoPow] using hmdef - have hmod55 : w.toNat % 2 ^ 127 = m := by - have hmod56 : w.toNat % 2 ^ 128 = m := hmdef'.symm - rw [← Nat.mod_mod_of_dvd (a := w.toNat) (show 2 ^ 127 ∣ 2 ^ 128 by norm_num)] - rw [hmod56] - exact Nat.mod_eq_of_lt (by simpa [EVM.twoPow] using h) - rw [hmod55] - rw [Nat.mod_eq_of_lt (by - norm_num [EVM.twoPow, UInt256.size] at hmhi ⊢ - omega)] - · have hne : UInt256.land w (UInt256.ofNat (2 ^ 127)) ≠ ⟨0⟩ := by - apply signextend_fifteen_sign_bit_ne_zero - rwa [← hmdef] - rw [if_neg hne] - have hval : - (let m := w.toNat % EVM.twoPow 128 - if m < EVM.twoPow 127 then (m : Int) else (m : Int) - (EVM.twoPow 128 : Int)) = - (m : Int) - (EVM.twoPow 128 : Int) := by - dsimp - have h' : ¬ w.toNat % EVM.twoPow 128 < EVM.twoPow 127 := by - intro hh - exact h (by rwa [hmdef]) - rw [if_neg h'] - omega - rw [hval] - have hword := wordOfInt_sint128_neg_toNat m hmhi - rw [hword] - rw [u256_lor_toNat] - rw [show (UInt256.ofNat (UInt256.size - 2 ^ 127)).toNat = - UInt256.size - 2 ^ 127 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] - have hlor := nat_lor_high_mask_127 w.toNat (by simpa [UInt256.size] using hwlt) - change UInt256.size - (EVM.twoPow 128 - m) = - (Nat.lor w.toNat (2 ^ 256 - 2 ^ 127)) % UInt256.size - rw [hlor] - have hmdef' : m = w.toNat % 2 ^ 128 := by simpa [EVM.twoPow] using hmdef - have hmod55 : w.toNat % 2 ^ 127 = m - 2 ^ 127 := by - have hge : 2 ^ 127 ≤ m := by - have hnot : ¬ m < 2 ^ 127 := by simpa [EVM.twoPow] using h - omega - have hmhi' : m < 2 ^ 128 := by simpa [EVM.twoPow] using hmhi - have hmod56 : w.toNat % 2 ^ 128 = m := hmdef'.symm - rw [← Nat.mod_mod_of_dvd (a := w.toNat) (show 2 ^ 127 ∣ 2 ^ 128 by norm_num)] - rw [hmod56] - rw [Nat.mod_eq_sub_mod hge] - rw [Nat.mod_eq_of_lt (by omega : m - 2 ^ 127 < 2 ^ 127)] - rw [hmod55] - norm_num [UInt256.size, EVM.twoPow] at h hmhi ⊢ - omega - -theorem ticksSint128Value_mask (w : UInt256) : - ticksSint128Value (UInt256.land w ticksUint128Mask) = - ticksSint128Value w := by - unfold ticksSint128Value - have hmod : (UInt256.land w ticksUint128Mask).toNat % EVM.twoPow 128 = - w.toNat % EVM.twoPow 128 := by - rw [uland_toNat, ticksUint128Mask_toNat] - change Nat.land w.toNat (2 ^ 128 - 1) % EVM.twoPow 128 = - w.toNat % EVM.twoPow 128 - rw [nat_land_mask_eq_mod] - simp [EVM.twoPow] - rw [hmod] - -theorem ticksLiquidityNetRawValue_wordOfInt (w : UInt256) : - EVM.wordOfInt (ticksSint128Value (UInt256.land w ticksUint128Mask)) = - UInt256.signextend ⟨15⟩ w := by - rw [ticksSint128Value_mask] - exact wordOfInt_sint128Value_eq_signextend_fifteen w - -theorem ticksSint128Value_ge (w : UInt256) : - -(2 ^ 127 : Int) ≤ ticksSint128Value w := by - unfold ticksSint128Value - by_cases h : w.toNat % EVM.twoPow 128 < EVM.twoPow 127 - · rw [if_pos h] - exact le_trans (by norm_num : -(2 ^ 127 : Int) ≤ 0) (Int.natCast_nonneg _) - · rw [if_neg h] - have hmhi := Nat.mod_lt w.toNat (by norm_num [EVM.twoPow] : 0 < EVM.twoPow 128) - norm_num [EVM.twoPow] at h hmhi ⊢ - omega - -theorem ticksSint128Value_lt (w : UInt256) : - ticksSint128Value w < (2 ^ 127 : Int) := by - unfold ticksSint128Value - by_cases h : w.toNat % EVM.twoPow 128 < EVM.twoPow 127 - · rw [if_pos h] - norm_num [EVM.twoPow] at h ⊢ - omega - · rw [if_neg h] - have hmhi := Nat.mod_lt w.toNat (by norm_num [EVM.twoPow] : 0 < EVM.twoPow 128) - norm_num [EVM.twoPow] at h hmhi ⊢ - omega - -private theorem ticksWordOfIntNeg_toNat (i : Int) (hneg : i < 0) - (hle : i.natAbs < EVM.wordModulus) : - (EVM.wordOfInt i).toNat = UInt256.size - i.natAbs := by - have hdiffPos : i.natAbs ≠ 0 := by - intro h - have : i = 0 := by omega - omega - have hpos : 0 < i.natAbs := Nat.pos_of_ne_zero hdiffPos - unfold EVM.wordOfInt - rw [if_pos hneg] - rw [Nat.mod_eq_of_lt hle, if_neg hdiffPos] - change (UInt256.ofNat (EVM.wordModulus - i.natAbs)).toNat = UInt256.size - i.natAbs - rw [ulit_toNat'] - · rw [show EVM.wordModulus = UInt256.size by native_decide] - · rw [show EVM.wordModulus = UInt256.size by native_decide] - exact Nat.sub_lt (by native_decide : 0 < UInt256.size) hpos - -private theorem ticksSint128Value_wordOfInt (i : Int) - (hge : -(2 ^ 127) ≤ i) (hlt : i < 2 ^ 127) : - ticksSint128Value (EVM.wordOfInt i) = i := by - unfold ticksSint128Value - by_cases h0 : 0 ≤ i - · have hword : EVM.wordOfInt i = EVM.word i.toNat := wordOfInt_nonneg i h0 - rw [hword] - have hltNat : i.toNat < EVM.twoPow 127 := by - exact (Int.toNat_lt h0).2 (by simpa [EVM.twoPow] using hlt) - have hto : (EVM.word i.toNat).toNat = i.toNat := by - unfold EVM.word EVM.uintN UInt256.toNat - simp only - show i.toNat % EVM.twoPow 256 = i.toNat - rw [Nat.mod_eq_of_lt] - norm_num [EVM.twoPow, UInt256.size] at hltNat ⊢ - omega - rw [hto] - have hmod : i.toNat % EVM.twoPow 128 = i.toNat := by - apply Nat.mod_eq_of_lt - norm_num [EVM.twoPow] at hltNat ⊢ - omega - rw [hmod] - rw [if_pos] - · exact Int.toNat_of_nonneg h0 - · simpa [EVM.twoPow] using hltNat - · have hneg : i < 0 := by omega - have hrle : i.natAbs ≤ EVM.twoPow 127 := by - have habs : (i.natAbs : Int) = -i := Int.ofNat_natAbs_of_nonpos (by omega) - have : (i.natAbs : Int) ≤ (EVM.twoPow 127 : Int) := by - rw [habs] - norm_num [EVM.twoPow] at hge ⊢ - omega - omega - have hrpos : 0 < i.natAbs := by - by_contra hz - have : i.natAbs = 0 := by omega - have : i = 0 := by omega - omega - have hword := ticksWordOfIntNeg_toNat i hneg (by - exact lt_of_le_of_lt hrle (by native_decide : EVM.twoPow 127 < EVM.wordModulus)) - rw [hword] - let r := i.natAbs - have hrle' : r ≤ EVM.twoPow 127 := by simpa [r] using hrle - have hrle56 : r ≤ EVM.twoPow 128 := le_trans hrle' (by native_decide) - have hrpos' : 0 < r := by simpa [r] using hrpos - have hmodm : (UInt256.size - r) % EVM.twoPow 128 = EVM.twoPow 128 - r := by - have hEq : UInt256.size - r = - (UInt256.size - EVM.twoPow 128) + (EVM.twoPow 128 - r) := by - norm_num [UInt256.size, EVM.twoPow] at hrle56 ⊢ - omega - rw [hEq, Nat.add_mod] - have hdiv : (UInt256.size - EVM.twoPow 128) % EVM.twoPow 128 = 0 := by - native_decide - have hltSub : EVM.twoPow 128 - r < EVM.twoPow 128 := by omega - rw [hdiv, Nat.zero_add] - rw [Nat.mod_eq_of_lt hltSub] - rw [Nat.mod_eq_of_lt hltSub] - rw [hmodm] - rw [if_neg] - · have habs : (r : Int) = -i := by - dsimp [r] - exact Int.ofNat_natAbs_of_nonpos (by omega) - norm_num [EVM.twoPow] at hrle' ⊢ - omega - · norm_num [EVM.twoPow] at hrle' hrpos' ⊢ - omega - -theorem signextend_fifteen_wordOfInt_ticks (i : Int) - (hge : -(2 ^ 127) ≤ i) (hlt : i < 2 ^ 127) : - UInt256.signextend ⟨15⟩ (EVM.wordOfInt i) = EVM.wordOfInt i := by - rw [← wordOfInt_sint128Value_eq_signextend_fifteen (EVM.wordOfInt i)] - rw [ticksSint128Value_wordOfInt i hge hlt] - -theorem ticksSignextendFifteen_idempotent (w : UInt256) : - UInt256.signextend ⟨15⟩ (UInt256.signextend ⟨15⟩ w) = - UInt256.signextend ⟨15⟩ w := by - let i := ticksSint128Value w - have hword : EVM.wordOfInt i = UInt256.signextend ⟨15⟩ w := by - simpa [i] using wordOfInt_sint128Value_eq_signextend_fifteen w - rw [← hword] - exact signextend_fifteen_wordOfInt_ticks i (ticksSint128Value_ge w) - (ticksSint128Value_lt w) - -theorem signextend_fifteen_eq_self_of_toNat_lt_twoPow127 {w : UInt256} - (hlt : w.toNat < EVM.twoPow 127) : - UInt256.signextend ⟨15⟩ w = w := by - have hge : -(2 ^ 127 : Int) ≤ Int.ofNat w.toNat := by - exact le_trans (by norm_num : -(2 ^ 127 : Int) ≤ 0) (Int.natCast_nonneg _) - have hltInt : Int.ofNat w.toNat < (2 ^ 127 : Int) := by - exact Int.ofNat_lt.mpr (by simpa [EVM.twoPow] using hlt) - rw [← wordOfInt_ofNat_toNat w] - exact signextend_fifteen_wordOfInt_ticks (Int.ofNat w.toNat) hge hltInt - -theorem signextend_fifteen_eq_self_toNat_lt_twoPow127 {w : UInt256} - (h128 : w.toNat < EVM.twoPow 128) - (hcanon : UInt256.signextend ⟨15⟩ w = w) : - w.toNat < EVM.twoPow 127 := by - by_contra hlt - have hnotm : ¬ w.toNat % EVM.twoPow 128 < EVM.twoPow 127 := by - rw [Nat.mod_eq_of_lt h128] - exact hlt - have hsign : UInt256.land w (UInt256.ofNat (2 ^ 127)) ≠ ⟨0⟩ := - signextend_fifteen_sign_bit_ne_zero w hnotm - have hnorm := signextend_fifteen_norm w - rw [hnorm, if_neg hsign] at hcanon - have hto := congrArg UInt256.toNat hcanon - rw [u256_lor_toNat] at hto - rw [show (UInt256.ofNat (UInt256.size - 2 ^ 127)).toNat = - UInt256.size - 2 ^ 127 by - exact ulit_toNat' _ (by norm_num [UInt256.size])] at hto - have hwlt : w.toNat < UInt256.size := by - simp [UInt256.toNat] - change w.toNat.lor (2 ^ 256 - 2 ^ 127) % UInt256.size = w.toNat at hto - rw [nat_lor_high_mask_127 w.toNat hwlt] at hto - rw [Nat.mod_eq_of_lt] at hto - · norm_num [UInt256.size, EVM.twoPow] at h128 hto - omega - · have hlow : w.toNat % 2 ^ 127 < 2 ^ 127 := - Nat.mod_lt _ (by norm_num) - norm_num [UInt256.size] at hlow ⊢ - omega - -theorem signextend_fifteen_ne_self_toNat_ge_twoPow127 {w : UInt256} - (hne : UInt256.signextend ⟨15⟩ w ≠ w) : - EVM.twoPow 127 ≤ w.toNat := by - by_contra hlt - exact hne (signextend_fifteen_eq_self_of_toNat_lt_twoPow127 (Nat.lt_of_not_ge hlt)) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/TicksReturnMemory.lean b/Benchmarks/UniswapV3Pool/TicksReturnMemory.lean deleted file mode 100644 index 66ad3158..00000000 --- a/Benchmarks/UniswapV3Pool/TicksReturnMemory.lean +++ /dev/null @@ -1,433 +0,0 @@ -import Benchmarks.UniswapV3Pool.Uint128 -import Reasoning.MemCascade - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -noncomputable def ticksScratchReturnMem1 (scratch : ByteArray) (gross : UInt256) : - ByteArray := - writeCascade scratch [(128, gross)] - -noncomputable def ticksScratchReturnMem2 (scratch : ByteArray) (gross net : UInt256) : - ByteArray := - writeCascade scratch [(128, gross), (160, net)] - -noncomputable def ticksScratchReturnMem3 (scratch : ByteArray) (gross net fee0 : UInt256) : - ByteArray := - writeCascade scratch [(128, gross), (160, net), (192, fee0)] - -noncomputable def ticksScratchReturnMem4 - (scratch : ByteArray) (gross net fee0 fee1 : UInt256) : ByteArray := - writeCascade scratch [(128, gross), (160, net), (192, fee0), (224, fee1)] - -noncomputable def ticksScratchReturnMem5 - (scratch : ByteArray) (gross net fee0 fee1 tick : UInt256) : ByteArray := - writeCascade scratch - [(128, gross), (160, net), (192, fee0), (224, fee1), (256, tick)] - -noncomputable def ticksScratchReturnMem6 - (scratch : ByteArray) (gross net fee0 fee1 tick secondsLiq : UInt256) : - ByteArray := - writeCascade scratch - [(128, gross), (160, net), (192, fee0), (224, fee1), (256, tick), - (288, secondsLiq)] - -noncomputable def ticksScratchReturnMem7 - (scratch : ByteArray) (gross net fee0 fee1 tick secondsLiq secondsOut : UInt256) : - ByteArray := - writeCascade scratch - [(128, gross), (160, net), (192, fee0), (224, fee1), (256, tick), - (288, secondsLiq), (320, secondsOut)] - -noncomputable def ticksScratchReturnMem - (scratch : ByteArray) (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) : - ByteArray := - writeCascade scratch - [(128, gross), (160, net), (192, fee0), (224, fee1), (256, tick), - (288, secondsLiq), (320, secondsOut), (352, initialized)] - -theorem ticksScratchReturnMem1_eq (scratch : ByteArray) (gross : UInt256) : - ticksScratchReturnMem1 scratch gross = writeWord scratch 128 gross := by - rfl - -theorem ticksScratchReturnMem2_eq (scratch : ByteArray) (gross net : UInt256) : - ticksScratchReturnMem2 scratch gross net = - writeWord (ticksScratchReturnMem1 scratch gross) 160 net := by - rfl - -theorem ticksScratchReturnMem3_eq (scratch : ByteArray) (gross net fee0 : UInt256) : - ticksScratchReturnMem3 scratch gross net fee0 = - writeWord (ticksScratchReturnMem2 scratch gross net) 192 fee0 := by - rfl - -theorem ticksScratchReturnMem4_eq - (scratch : ByteArray) (gross net fee0 fee1 : UInt256) : - ticksScratchReturnMem4 scratch gross net fee0 fee1 = - writeWord (ticksScratchReturnMem3 scratch gross net fee0) 224 fee1 := by - rfl - -theorem ticksScratchReturnMem5_eq - (scratch : ByteArray) (gross net fee0 fee1 tick : UInt256) : - ticksScratchReturnMem5 scratch gross net fee0 fee1 tick = - writeWord (ticksScratchReturnMem4 scratch gross net fee0 fee1) 256 tick := by - rfl - -theorem ticksScratchReturnMem6_eq - (scratch : ByteArray) (gross net fee0 fee1 tick secondsLiq : UInt256) : - ticksScratchReturnMem6 scratch gross net fee0 fee1 tick secondsLiq = - writeWord (ticksScratchReturnMem5 scratch gross net fee0 fee1 tick) 288 secondsLiq := by - rfl - -theorem ticksScratchReturnMem7_eq - (scratch : ByteArray) (gross net fee0 fee1 tick secondsLiq secondsOut : UInt256) : - ticksScratchReturnMem7 scratch gross net fee0 fee1 tick secondsLiq secondsOut = - writeWord (ticksScratchReturnMem6 scratch gross net fee0 fee1 tick secondsLiq) 320 - secondsOut := by - rfl - -theorem ticksScratchReturnMem_eq - (scratch : ByteArray) (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) : - ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut initialized = - writeWord (ticksScratchReturnMem7 scratch gross net fee0 fee1 tick secondsLiq secondsOut) - 352 initialized := by - rfl - -theorem ticksScratchReturnMem1_size {scratch : ByteArray} (gross : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem1 scratch gross).size = 160 := by - unfold ticksScratchReturnMem1 - exact writeCascade_size_of_base scratch _ hscratch - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem ticksScratchReturnMem2_size {scratch : ByteArray} (gross net : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem2 scratch gross net).size = 192 := by - unfold ticksScratchReturnMem2 - exact writeCascade_size_of_base scratch _ hscratch - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem ticksScratchReturnMem3_size {scratch : ByteArray} (gross net fee0 : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem3 scratch gross net fee0).size = 224 := by - unfold ticksScratchReturnMem3 - exact writeCascade_size_of_base scratch _ hscratch - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem ticksScratchReturnMem4_size {scratch : ByteArray} - (gross net fee0 fee1 : UInt256) (hscratch : scratch.size = 96) : - (ticksScratchReturnMem4 scratch gross net fee0 fee1).size = 256 := by - unfold ticksScratchReturnMem4 - exact writeCascade_size_of_base scratch _ hscratch - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem ticksScratchReturnMem5_size {scratch : ByteArray} - (gross net fee0 fee1 tick : UInt256) (hscratch : scratch.size = 96) : - (ticksScratchReturnMem5 scratch gross net fee0 fee1 tick).size = 288 := by - unfold ticksScratchReturnMem5 - exact writeCascade_size_of_base scratch _ hscratch - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem ticksScratchReturnMem6_size {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq : UInt256) (hscratch : scratch.size = 96) : - (ticksScratchReturnMem6 scratch gross net fee0 fee1 tick secondsLiq).size = 320 := by - unfold ticksScratchReturnMem6 - exact writeCascade_size_of_base scratch _ hscratch - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem ticksScratchReturnMem7_size {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq secondsOut : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem7 scratch gross net fee0 fee1 tick secondsLiq secondsOut).size = - 352 := by - unfold ticksScratchReturnMem7 - exact writeCascade_size_of_base scratch _ hscratch - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem ticksScratchReturnMem_size {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized).size = 384 := by - unfold ticksScratchReturnMem - exact writeCascade_size_of_base scratch _ hscratch - (by - norm_num [WriteGapsOk] - all_goals native_decide) - (by norm_num [writeCascadeSize]) - -theorem ticksScratchReturnMem_read64 {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) - (hscratch : scratch.size = 96) - (hread64 : scratch.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : - (ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized).readWithPadding 64 32 = - UInt256.toByteArray ⟨128⟩ := by - unfold ticksScratchReturnMem - rw [writeCascade_read_preserved_of_base scratch _ hscratch - (by - norm_num [WindowDisjointFromWrites] - all_goals native_decide)] - exact hread64 - -theorem ticksScratchReturnMem_mload64 {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) - (hscratch : scratch.size = 96) - (hread64 : scratch.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : - (if (⟨64⟩ : UInt256).toNat ≥ - (ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized).size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 12 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - ((ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized).readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - ⟨128⟩ := - mloadFreePtrValue - (by - rw [ticksScratchReturnMem_size gross net fee0 fee1 tick secondsLiq secondsOut - initialized hscratch] - decide) - (by decide) - (ticksScratchReturnMem_read64 gross net fee0 fee1 tick secondsLiq secondsOut initialized - hscratch hread64) - -theorem ticksScratchReturnMem_read128 {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized).readWithPadding 128 32 = - UInt256.toByteArray gross := by - unfold ticksScratchReturnMem - exact writeCascade_read_word_of_head_of_base scratch (base := 96) (off := 128) - gross [(160, net), (192, fee0), (224, fee1), (256, tick), (288, secondsLiq), - (320, secondsOut), (352, initialized)] hscratch (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -set_option maxHeartbeats 1000000 in -theorem ticksScratchReturnMem_read160 {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized).readWithPadding 160 32 = - UInt256.toByteArray net := by - unfold ticksScratchReturnMem - change (writeCascade (ticksScratchReturnMem1 scratch gross) - [(160, net), (192, fee0), (224, fee1), (256, tick), (288, secondsLiq), - (320, secondsOut), (352, initialized)]).readWithPadding 160 32 = - UInt256.toByteArray net - exact writeCascade_read_word_of_head_of_base (ticksScratchReturnMem1 scratch gross) - (base := 160) (off := 160) net [(192, fee0), (224, fee1), (256, tick), - (288, secondsLiq), (320, secondsOut), (352, initialized)] - (ticksScratchReturnMem1_size gross hscratch) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem ticksScratchReturnMem_read192 {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized).readWithPadding 192 32 = - UInt256.toByteArray fee0 := by - unfold ticksScratchReturnMem - change (writeCascade (ticksScratchReturnMem2 scratch gross net) - [(192, fee0), (224, fee1), (256, tick), (288, secondsLiq), (320, secondsOut), - (352, initialized)]).readWithPadding 192 32 = - UInt256.toByteArray fee0 - exact writeCascade_read_word_of_head_of_base (ticksScratchReturnMem2 scratch gross net) - (base := 192) (off := 192) fee0 [(224, fee1), (256, tick), (288, secondsLiq), - (320, secondsOut), (352, initialized)] - (ticksScratchReturnMem2_size gross net hscratch) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem ticksScratchReturnMem_read224 {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized).readWithPadding 224 32 = - UInt256.toByteArray fee1 := by - unfold ticksScratchReturnMem - change (writeCascade (ticksScratchReturnMem3 scratch gross net fee0) - [(224, fee1), (256, tick), (288, secondsLiq), (320, secondsOut), - (352, initialized)]).readWithPadding 224 32 = - UInt256.toByteArray fee1 - exact writeCascade_read_word_of_head_of_base (ticksScratchReturnMem3 scratch gross net fee0) - (base := 224) (off := 224) fee1 [(256, tick), (288, secondsLiq), (320, secondsOut), - (352, initialized)] - (ticksScratchReturnMem3_size gross net fee0 hscratch) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem ticksScratchReturnMem_read256 {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized).readWithPadding 256 32 = - UInt256.toByteArray tick := by - unfold ticksScratchReturnMem - change (writeCascade (ticksScratchReturnMem4 scratch gross net fee0 fee1) - [(256, tick), (288, secondsLiq), (320, secondsOut), - (352, initialized)]).readWithPadding 256 32 = - UInt256.toByteArray tick - exact writeCascade_read_word_of_head_of_base - (ticksScratchReturnMem4 scratch gross net fee0 fee1) (base := 256) (off := 256) - tick [(288, secondsLiq), (320, secondsOut), (352, initialized)] - (ticksScratchReturnMem4_size gross net fee0 fee1 hscratch) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem ticksScratchReturnMem_read288 {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized).readWithPadding 288 32 = - UInt256.toByteArray secondsLiq := by - unfold ticksScratchReturnMem - change (writeCascade (ticksScratchReturnMem5 scratch gross net fee0 fee1 tick) - [(288, secondsLiq), (320, secondsOut), (352, initialized)]).readWithPadding - 288 32 = - UInt256.toByteArray secondsLiq - exact writeCascade_read_word_of_head_of_base - (ticksScratchReturnMem5 scratch gross net fee0 fee1 tick) (base := 288) (off := 288) - secondsLiq [(320, secondsOut), (352, initialized)] - (ticksScratchReturnMem5_size gross net fee0 fee1 tick hscratch) (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem ticksScratchReturnMem_read320 {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized).readWithPadding 320 32 = - UInt256.toByteArray secondsOut := by - unfold ticksScratchReturnMem - change (writeCascade (ticksScratchReturnMem6 scratch gross net fee0 fee1 tick secondsLiq) - [(320, secondsOut), (352, initialized)]).readWithPadding 320 32 = - UInt256.toByteArray secondsOut - exact writeCascade_read_word_of_head_of_base - (ticksScratchReturnMem6 scratch gross net fee0 fee1 tick secondsLiq) (base := 320) - (off := 320) secondsOut [(352, initialized)] - (ticksScratchReturnMem6_size gross net fee0 fee1 tick secondsLiq hscratch) - (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem ticksScratchReturnMem_read352 {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized).readWithPadding 352 32 = - UInt256.toByteArray initialized := by - unfold ticksScratchReturnMem - change (writeCascade - (ticksScratchReturnMem7 scratch gross net fee0 fee1 tick secondsLiq secondsOut) - [(352, initialized)]).readWithPadding 352 32 = - UInt256.toByteArray initialized - exact writeCascade_read_word_of_head_of_base - (ticksScratchReturnMem7 scratch gross net fee0 fee1 tick secondsLiq secondsOut) - (base := 352) (off := 352) initialized [] - (ticksScratchReturnMem7_size gross net fee0 fee1 tick secondsLiq secondsOut hscratch) - (by native_decide) - (by - norm_num [WindowDisjointFromWrites]) - -theorem ticksScratchReturnMem_read128_256 {scratch : ByteArray} - (gross net fee0 fee1 tick secondsLiq secondsOut initialized : UInt256) - (hscratch : scratch.size = 96) : - (ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized).readWithPadding 128 256 = - UInt256.toByteArray gross ++ UInt256.toByteArray net ++ UInt256.toByteArray fee0 ++ - UInt256.toByteArray fee1 ++ UInt256.toByteArray tick ++ - UInt256.toByteArray secondsLiq ++ UInt256.toByteArray secondsOut ++ - UInt256.toByteArray initialized := by - let mem := ticksScratchReturnMem scratch gross net fee0 fee1 tick secondsLiq secondsOut - initialized - have hsize : mem.size = 384 := by - simpa [mem] using - ticksScratchReturnMem_size gross net fee0 fee1 tick secondsLiq secondsOut initialized - hscratch - have h128 : mem.readWithPadding 128 32 = UInt256.toByteArray gross := by - simpa [mem] using - ticksScratchReturnMem_read128 gross net fee0 fee1 tick secondsLiq secondsOut initialized - hscratch - have h160 : mem.readWithPadding 160 32 = UInt256.toByteArray net := by - simpa [mem] using - ticksScratchReturnMem_read160 gross net fee0 fee1 tick secondsLiq secondsOut initialized - hscratch - have h192 : mem.readWithPadding 192 32 = UInt256.toByteArray fee0 := by - simpa [mem] using - ticksScratchReturnMem_read192 gross net fee0 fee1 tick secondsLiq secondsOut initialized - hscratch - have h224 : mem.readWithPadding 224 32 = UInt256.toByteArray fee1 := by - simpa [mem] using - ticksScratchReturnMem_read224 gross net fee0 fee1 tick secondsLiq secondsOut initialized - hscratch - have h256 : mem.readWithPadding 256 32 = UInt256.toByteArray tick := by - simpa [mem] using - ticksScratchReturnMem_read256 gross net fee0 fee1 tick secondsLiq secondsOut initialized - hscratch - have h288 : mem.readWithPadding 288 32 = UInt256.toByteArray secondsLiq := by - simpa [mem] using - ticksScratchReturnMem_read288 gross net fee0 fee1 tick secondsLiq secondsOut initialized - hscratch - have h320 : mem.readWithPadding 320 32 = UInt256.toByteArray secondsOut := by - simpa [mem] using - ticksScratchReturnMem_read320 gross net fee0 fee1 tick secondsLiq secondsOut initialized - hscratch - have h352 : mem.readWithPadding 352 32 = UInt256.toByteArray initialized := by - simpa [mem] using - ticksScratchReturnMem_read352 gross net fee0 fee1 tick secondsLiq secondsOut initialized - hscratch - change mem.readWithPadding 128 256 = _ - rw [byteArray_readWithPadding_split mem 128 32 224 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h128] - rw [byteArray_readWithPadding_split mem 160 32 192 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h160] - rw [byteArray_readWithPadding_split mem 192 32 160 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h192] - rw [byteArray_readWithPadding_split mem 224 32 128 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h224] - rw [byteArray_readWithPadding_split mem 256 32 96 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h256] - rw [byteArray_readWithPadding_split mem 288 32 64 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h288] - rw [byteArray_readWithPadding_split mem 320 32 32 (by norm_num) (by norm_num) - (by norm_num) (by norm_num) (by norm_num) (by omega), h320, h352] - simp only [ByteArray.append_assoc] - -theorem ticksScratch_mload64 {scratch : ByteArray} - (hscratch : scratch.size = 96) - (hread64 : scratch.readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩) : - (if (⟨64⟩ : UInt256).toNat ≥ scratch.size - ∨ (⟨64⟩ : UInt256) ≥ UInt256.ofNat 3 * ⟨32⟩ then ⟨0⟩ - else UInt256.ofNat - (fromByteArrayBigEndian - (scratch.readWithPadding (⟨64⟩ : UInt256).toNat 32))) = - ⟨128⟩ := - mloadFreePtrValue (by rw [hscratch]; decide) (by decide) hread64 - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Token0.lean b/Benchmarks/UniswapV3Pool/Token0.lean deleted file mode 100644 index f58a0791..00000000 --- a/Benchmarks/UniswapV3Pool/Token0.lean +++ /dev/null @@ -1,279 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolToken0ReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 0 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨435⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 0 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0x0d 0xfe 0x16 0x81 - (uniswapV3PoolSelNat 0) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h239 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨239⟩) hpatch h32 hgt32 - have hgt239 : UInt256.gt (armSelNat code ⟨239⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h348 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨348⟩) hpatch h239 hgt239 - have hgt348 : UInt256.gt (armSelNat code ⟨348⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h397 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨397⟩) hpatch h348 hgt348 - have h435 := uniswapV3PoolSelectorArmHitTo (i := 0) (target := ⟨435⟩) - hpatch hsz hsel h397 - exact ⟨_, _, h435⟩ - -theorem uniswapV3PoolToken0Decode {v : PoolImmutables} {I : ExecutionEnv} - (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode ((token0Transition v).params.map Param.name) - (transitionSignature (token0Transition v)).paramTypes I.calldata = some (∅ : Store) := by - simpa [config, token0Transition, transitionSignature] using - decodeCalldataWithMode_empty_ok (mode := DecodeMode.legacySolc05) (cd := I.calldata) hsz - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolDispatch_token0 {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 0 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some (token0Transition v) := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, factoryTransition v, - feeTransition v, feegrowthglobal0X128Transition, feegrowthglobal1X128Transition, - flashTransition v, increaseobservationcardinalitynextTransition v, initializeTransition, - liquidityTransition, maxliquiditypertickTransition v, mintTransition v, observationsTransition, - observeTransition v, positionsTransition, protocolfeesTransition, setfeeprotocolTransition v, - slot0Transition, snapshotcumulativesinsideTransition v, swapTransition v, tickbitmapTransition, - tickspacingTransition v, ticksTransition]) - (post := [token1Transition v]) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 0) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 0) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 0) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 0) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 0) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 0) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 0) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 0) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 5) (j := 0) - (by native_decide) hsel - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 25) (j := 0) - (by native_decide) hsel - · rw [selectorOf, liquiditySelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 2) (j := 0) - (by native_decide) hsel - · rw [selectorOf, maxLiquidityPerTickSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 13) (j := 0) - (by native_decide) hsel - · rw [selectorOf, mintSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 7) (j := 0) - (by native_decide) hsel - · rw [selectorOf, observationsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 4) (j := 0) - (by native_decide) hsel - · rw [selectorOf, observeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 16) (j := 0) - (by native_decide) hsel - · rw [selectorOf, positionsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 11) (j := 0) - (by native_decide) hsel - · rw [selectorOf, protocolFeesSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 3) (j := 0) - (by native_decide) hsel - · rw [selectorOf, setFeeProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 14) (j := 0) - (by native_decide) hsel - · rw [selectorOf, slot0SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 6) (j := 0) - (by native_decide) hsel - · rw [selectorOf, snapshotCumulativesInsideSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 18) (j := 0) - (by native_decide) hsel - · rw [selectorOf, swapSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 1) (j := 0) - (by native_decide) hsel - · rw [selectorOf, tickBitmapSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 12) (j := 0) - (by native_decide) hsel - · rw [selectorOf, tickSpacingSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 20) (j := 0) - (by native_decide) hsel - · rw [selectorOf, ticksSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 24) (j := 0) - (by native_decide) hsel - · rw [selectorOf, token0SelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hsel - -private theorem uniswapV3PoolToken0PatchDisjoint {v : PoolImmutables} {pc : UInt256} - (hlo : 2290 ≤ pc.toNat) (hhi : pc.toNat + 33 ≤ 3072) : - ∀ p ∈ patches v, pc.toNat + 33 ≤ p.1 ∨ p.1 + 32 ≤ pc.toNat := by - intro p hp - simp [patches, patchesFrom, offsets, immValues, wordBytes?, valueToWord, List.lookup] at hp - rcases hp with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> - omega - -theorem uniswapV3PoolToken0EntryWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcGetterEntryWf code ⟨435⟩ ⟨443⟩ ⟨2256⟩ := by - dsimp [solcGetterEntryWf] - refine ⟨?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolToken0GetterWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcConstGetterWf code ⟨2256⟩ (EVM.Word.ofNat v.token0.toNat) 32 .PUSH32 := by - dsimp [solcConstGetterWf] - refine ⟨?_, ?_, ?_, ?_, ?_⟩ - · exact uniswapV3PoolToken0GetterJumpdestDecode hpatch - · native_decide - · exact uniswapV3PoolToken0ConstDecode hpatch - · rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolToken0PatchDisjoint (by native_decide) (by native_decide))] - native_decide - · rw [uniswapV3PoolDecodePatchedEqTemplateDisjoint hpatch (by native_decide) - (uniswapV3PoolToken0PatchDisjoint (by native_decide) (by native_decide))] - native_decide - -theorem uniswapV3PoolToken0ReturnWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcReturnAddressFromMemWf code ⟨443⟩ := - uniswapV3PoolReturnAddress443Wf hpatch - -theorem uniswapV3PoolToken0RoutineJumpDest {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨2256⟩ = true := - uniswapV3PoolJumpDestPatched2258 hpatch (by native_decide) - -theorem uniswapV3PoolToken0ReturnJumpDest {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨443⟩ = true := - uniswapV3PoolReturn443JumpDest hpatch - -theorem uniswapV3PoolToken0Evm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 0 == I.calldata.extract 0 4) = true) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land (EVM.Word.ofNat v.token0.toNat) solcAddrMask)) := by - have hreach := uniswapV3PoolToken0ReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - exact RD.solcAddressConstGetterExternal - (sel := solcSelectorWord I) (entry := ⟨435⟩) (routine := ⟨2256⟩) - (returnPc := ⟨443⟩) (val := EVM.Word.ofNat v.token0.toNat) (width := 32) - (op := .PUSH32) hreach - (uniswapV3PoolToken0EntryWf hpatch) - (uniswapV3PoolToken0GetterWf hpatch) - (uniswapV3PoolToken0RoutineJumpDest hpatch) - (uniswapV3PoolToken0ReturnJumpDest hpatch) - (uniswapV3PoolToken0ReturnWf hpatch) - -theorem uniswapV3PoolToken0SourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) (token0Transition v).body - (.returned { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) - (some [Value.address (AccountAddress.ofNat v.token0.toNat)])) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [addrLit v.token0] ] _ - apply nonpayableReturnExprBodyReturns - · simp [initState, hwv] - · exact uniswapV3PoolAddrLitEval (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) v.token0 - -theorem uniswapV3PoolToken0ValueTransport {v : PoolImmutables} : - some [Value.address (AccountAddress.ofNat v.token0.toNat)] = - some [Value.address (AccountAddress.ofNat - (UInt256.land (EVM.Word.ofNat v.token0.toNat) solcAddrMask).toNat)] := - uniswapV3PoolAddressValueTransport v.token0 - -theorem uniswapV3PoolToken0BodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 0 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_token0 (v := v) (cd := I.calldata) hsel - have hdecode := uniswapV3PoolToken0Decode (v := v) (I := I) hsz - have hbody := uniswapV3PoolToken0SourceBody (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hrd := uniswapV3PoolToken0Evm (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel - exact hrd.reEquivExecutionTransport hcode hdispatch hdecode hbody - (uniswapV3PoolToken0ValueTransport (v := v)) hAccounts - (returnEquiv_of_encode - (solcAddressReturnEncoding rfl (EVM.Word.ofNat v.token0.toNat))) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Token1.lean b/Benchmarks/UniswapV3Pool/Token1.lean deleted file mode 100644 index 66a8b012..00000000 --- a/Benchmarks/UniswapV3Pool/Token1.lean +++ /dev/null @@ -1,281 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -theorem uniswapV3PoolToken1ReachEntry {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 21 == I.calldata.extract 0 4) = true) : - ∃ k C, RD code I g (initState cA gh bl σ σ₀ g A I) ⟨2040⟩ [solcSelectorWord I] - solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, h32⟩ := uniswapV3PoolReachSelector32 - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize - have hword : solcSelectorWord I = uniswapV3PoolSelNat 21 := by - simpa [uniswapV3PoolSelBytes, uniswapV3PoolSelNat] using - solcSelectorWord_eq_of_beq I hsz 0xd2 0x12 0x20 0xa7 - (uniswapV3PoolSelNat 21) (by native_decide) hsel - have hgt32 : UInt256.gt (armSelNat code ⟨32⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h43 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨43⟩) hpatch h32 hgt32 - have hgt43 : UInt256.gt (armSelNat code ⟨43⟩) (solcSelectorWord I) = ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h54 := uniswapV3PoolSelectorSplitNotTakenTo (next := ⟨54⟩) hpatch h43 hgt43 - have hgt54 : UInt256.gt (armSelNat code ⟨54⟩) (solcSelectorWord I) ≠ ⟨0⟩ := by - rw [uniswapV3PoolArmSelNatPatchedEqTemplate2258 hpatch (by native_decide), hword] - native_decide - have h114 := uniswapV3PoolSelectorSplitTakenTo (next := ⟨114⟩) hpatch h54 hgt54 - have hmiss19 : (uniswapV3PoolSelBytes 19 == I.calldata.extract 0 4) = false := by - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := I.calldata) (i := 19) (j := 21) - (by native_decide) hsel - have h125 := uniswapV3PoolSelectorArmMissToOf (i := 19) (next := ⟨125⟩) - hpatch hsz hmiss19 h114 - have hmiss20 : (uniswapV3PoolSelBytes 20 == I.calldata.extract 0 4) = false := by - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := I.calldata) (i := 20) (j := 21) - (by native_decide) hsel - have h136 := uniswapV3PoolSelectorArmMissToOf (i := 20) (next := ⟨136⟩) - hpatch hsz hmiss20 h125 - have h2040 := uniswapV3PoolSelectorArmHitTo (i := 21) (target := ⟨2040⟩) - hpatch hsz hsel h136 - exact ⟨_, _, h2040⟩ - -theorem uniswapV3PoolToken1Decode {v : PoolImmutables} {I : ExecutionEnv} - (hsz : 4 ≤ I.calldata.size) : - decodeCalldataWithMode (config v).abiDecodeMode ((token1Transition v).params.map Param.name) - (transitionSignature (token1Transition v)).paramTypes I.calldata = some (∅ : Store) := by - simpa [config, token1Transition, transitionSignature] using - decodeCalldataWithMode_empty_ok (mode := DecodeMode.legacySolc05) (cd := I.calldata) hsz - -set_option maxHeartbeats 1000000 in -theorem uniswapV3PoolDispatch_token1 {v : PoolImmutables} {cd : ByteArray} - (hsel : (uniswapV3PoolSelBytes 21 == cd.extract 0 4) = true) : - dispatchMsg (contract v) cd = some (token1Transition v) := by - apply dispatchMsg_eq_some_of_split - (pre := [burnTransition, collectTransition v, collectprotocolTransition v, factoryTransition v, - feeTransition v, feegrowthglobal0X128Transition, feegrowthglobal1X128Transition, - flashTransition v, increaseobservationcardinalitynextTransition v, initializeTransition, - liquidityTransition, maxliquiditypertickTransition v, mintTransition v, observationsTransition, - observeTransition v, positionsTransition, protocolfeesTransition, setfeeprotocolTransition v, - slot0Transition, snapshotcumulativesinsideTransition v, swapTransition v, tickbitmapTransition, - tickspacingTransition v, ticksTransition, token0Transition v]) - (post := []) - · simp [contract, transitions] - · intro t ht - simp at ht - rcases ht with - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | - rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl - · rw [selectorOf, burnSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 17) (j := 21) - (by native_decide) hsel - · rw [selectorOf, collectSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 10) (j := 21) - (by native_decide) hsel - · rw [selectorOf, collectProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 15) (j := 21) - (by native_decide) hsel - · rw [selectorOf, factorySelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 19) (j := 21) - (by native_decide) hsel - · rw [selectorOf, feeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 22) (j := 21) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal0X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 23) (j := 21) - (by native_decide) hsel - · rw [selectorOf, feeGrowthGlobal1X128SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 8) (j := 21) - (by native_decide) hsel - · rw [selectorOf, flashSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 9) (j := 21) - (by native_decide) hsel - · rw [selectorOf, increaseObservationCardinalityNextSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 5) (j := 21) - (by native_decide) hsel - · rw [selectorOf, initializeSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 25) (j := 21) - (by native_decide) hsel - · rw [selectorOf, liquiditySelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 2) (j := 21) - (by native_decide) hsel - · rw [selectorOf, maxLiquidityPerTickSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 13) (j := 21) - (by native_decide) hsel - · rw [selectorOf, mintSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 7) (j := 21) - (by native_decide) hsel - · rw [selectorOf, observationsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 4) (j := 21) - (by native_decide) hsel - · rw [selectorOf, observeSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 16) (j := 21) - (by native_decide) hsel - · rw [selectorOf, positionsSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 11) (j := 21) - (by native_decide) hsel - · rw [selectorOf, protocolFeesSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 3) (j := 21) - (by native_decide) hsel - · rw [selectorOf, setFeeProtocolSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 14) (j := 21) - (by native_decide) hsel - · rw [selectorOf, slot0SelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 6) (j := 21) - (by native_decide) hsel - · rw [selectorOf, snapshotCumulativesInsideSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 18) (j := 21) - (by native_decide) hsel - · rw [selectorOf, swapSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 1) (j := 21) - (by native_decide) hsel - · rw [selectorOf, tickBitmapSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 12) (j := 21) - (by native_decide) hsel - · rw [selectorOf, tickSpacingSelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 20) (j := 21) - (by native_decide) hsel - · rw [selectorOf, ticksSelectorBytes] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 24) (j := 21) - (by native_decide) hsel - · rw [selectorOf, token0SelectorBytes v] - simpa [uniswapV3PoolSelBytes] using - uniswapV3PoolSelectorMissOfHitBytes (cd := cd) (i := 0) (j := 21) - (by native_decide) hsel - · rw [selectorOf, token1SelectorBytes v] - simpa [uniswapV3PoolSelBytes] using hsel - -theorem uniswapV3PoolToken1EntryWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcGetterEntryWf code ⟨2040⟩ ⟨443⟩ ⟨10527⟩ := by - dsimp [solcGetterEntryWf] - refine ⟨?_, ?_, ?_, ?_⟩ - all_goals - rw [uniswapV3PoolDecodePatchedEqTemplate2258 hpatch (by native_decide)] - native_decide - -theorem uniswapV3PoolToken1GetterWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcConstGetterWf code ⟨10527⟩ (EVM.Word.ofNat v.token1.toNat) 32 .PUSH32 := by - dsimp [solcConstGetterWf] - refine ⟨?_, ?_, ?_, ?_, ?_⟩ - · exact uniswapV3PoolToken1GetterJumpdestDecode hpatch - · native_decide - · exact uniswapV3PoolToken1ConstDecode hpatch - · exact uniswapV3PoolToken1GetterDupDecode hpatch - · exact uniswapV3PoolToken1GetterJumpDecode hpatch - -theorem uniswapV3PoolToken1ReturnWf {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - solcReturnAddressFromMemWf code ⟨443⟩ := - uniswapV3PoolReturnAddress443Wf hpatch - -theorem uniswapV3PoolToken1RoutineJumpDest {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨10527⟩ = true := - uniswapV3PoolJumpDestPatched10527 hpatch - -theorem uniswapV3PoolToken1ReturnJumpDest {v : PoolImmutables} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) : - (D_J code 0).contains ⟨443⟩ = true := - uniswapV3PoolReturn443JumpDest hpatch - -theorem uniswapV3PoolToken1Evm {v : PoolImmutables} {code : ByteArray} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (hsel : (uniswapV3PoolSelBytes 21 == I.calldata.extract 0 4) = true) : - RDret code g (initState cA gh bl σ σ₀ g A I) (cA, σ) - (UInt256.toByteArray (UInt256.land (EVM.Word.ofNat v.token1.toNat) solcAddrMask)) := by - have hreach := uniswapV3PoolToken1ReachEntry - (v := v) (code := code) (cA := cA) (gh := gh) (bl := bl) (σ := σ) - (σ₀ := σ₀) (A := A) (I := I) (g := g) hpatch hcode hwv hsz hsize hsel - exact RD.solcAddressConstGetterExternal - (sel := solcSelectorWord I) (entry := ⟨2040⟩) (routine := ⟨10527⟩) - (returnPc := ⟨443⟩) (val := EVM.Word.ofNat v.token1.toNat) (width := 32) - (op := .PUSH32) hreach - (uniswapV3PoolToken1EntryWf hpatch) - (uniswapV3PoolToken1GetterWf hpatch) - (uniswapV3PoolToken1RoutineJumpDest hpatch) - (uniswapV3PoolToken1ReturnJumpDest hpatch) - (uniswapV3PoolToken1ReturnWf hpatch) - -theorem uniswapV3PoolToken1SourceBody {v : PoolImmutables} - {cA gh bl σ σ₀ A I} {g : Sat256} - (hwv : I.weiValue = ⟨0⟩) : - ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) (token1Transition v).body - (.returned { contract := contract v, locals := ∅ } - (initState cA gh bl σ σ₀ g A I) - (some [Value.address (AccountAddress.ofNat v.token1.toNat)])) := by - change ExecTransitionBody (config v) (contract v) - (initState cA gh bl σ σ₀ g A I) (∅ : Store) - [ .require (.binary .eq (.env .callvalue) (.intLit 0)), - .return [addrLit v.token1] ] _ - apply nonpayableReturnExprBodyReturns - · simp [initState, hwv] - · exact uniswapV3PoolAddrLitEval (v := v) (cA := cA) (gh := gh) (bl := bl) - (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) v.token1 - -theorem uniswapV3PoolToken1ValueTransport {v : PoolImmutables} : - some [Value.address (AccountAddress.ofNat v.token1.toNat)] = - some [Value.address (AccountAddress.ofNat - (UInt256.land (EVM.Word.ofNat v.token1.toNat) solcAddrMask).toNat)] := - uniswapV3PoolAddressValueTransport v.token1 - -theorem uniswapV3PoolToken1BodyCore {v : PoolImmutables} - {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {code : ByteArray} - (hpatch : patchRuntime uniswapV3PoolBytecode (patches v) = some code) - (hcode : I.code = code) (hwv : I.weiValue = ⟨0⟩) - (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size) - (_hperm : I.perm = true) - (hAccounts : accountMapEquiv σ_evm σ_solm) - (hsel : (uniswapV3PoolSelBytes 21 == I.calldata.extract 0 4) = true) : - runtimeEquivalenceFor (config v) (contract v) cA gh bl σ_evm σ_solm σ₀ g A I := by - have hdispatch := uniswapV3PoolDispatch_token1 (v := v) (cd := I.calldata) hsel - have hdecode := uniswapV3PoolToken1Decode (v := v) (I := I) hsz - have hbody := uniswapV3PoolToken1SourceBody (v := v) (cA := cA) (gh := gh) - (bl := bl) (σ := σ_solm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hwv - have hrd := uniswapV3PoolToken1Evm (v := v) (code := code) (cA := cA) - (gh := gh) (bl := bl) (σ := σ_evm) (σ₀ := σ₀) (A := A) (I := I) - (g := Sat256.ofUInt256 g) hpatch hcode hwv hsz hsize hsel - exact hrd.reEquivExecutionTransport hcode hdispatch hdecode hbody - (uniswapV3PoolToken1ValueTransport (v := v)) hAccounts - (returnEquiv_of_encode - (solcAddressReturnEncoding rfl (EVM.Word.ofNat v.token1.toNat))) - -end Benchmarks.UniswapV3Pool diff --git a/Benchmarks/UniswapV3Pool/Uint128.lean b/Benchmarks/UniswapV3Pool/Uint128.lean deleted file mode 100644 index e9b97750..00000000 --- a/Benchmarks/UniswapV3Pool/Uint128.lean +++ /dev/null @@ -1,86 +0,0 @@ -import Benchmarks.UniswapV3Pool.Common - -open Solm ABI Ethereum Ethereum.EVM Benchmarks.UniswapV3Pool.Immutables -open Reasoning.Theory Reasoning.Reach - -namespace Benchmarks.UniswapV3Pool - -def uint128Mask : UInt256 := UInt256.ofNat (2 ^ 128 - 1) - -theorem uint128Mask_toNat : - uint128Mask.toNat = 2 ^ 128 - 1 := by - exact ulit_toNat' _ (by norm_num [UInt256.size]) - -theorem uint128Mask_bound (w : UInt256) : - (UInt256.land w uint128Mask).toNat < EVM.twoPow 128 := by - rw [uland_toNat] - rw [uint128Mask_toNat] - exact lt_of_le_of_lt (nat_land_le_right _ _) (by norm_num [EVM.twoPow]) - -theorem uint128Mask_clean {w : UInt256} (hcanon : w.toNat < EVM.twoPow 128) : - UInt256.land w uint128Mask = w := by - apply u256_inj - show Nat.land w.toNat uint128Mask.toNat % EVM.twoPow 256 = w.toNat - rw [uint128Mask_toNat, nat_land_mask_eq_mod] - rw [show EVM.twoPow 128 = 2 ^ 128 from rfl] at hcanon - rw [Nat.mod_eq_of_lt hcanon] - exact Nat.mod_eq_of_lt w.val.isLt - -theorem uint128Mask_clean_left {w : UInt256} (hcanon : w.toNat < EVM.twoPow 128) : - UInt256.land uint128Mask w = w := by - rw [u256_land_comm uint128Mask w] - exact uint128Mask_clean hcanon - -theorem uint128ReturnEncodingMasked (w : UInt256) : - encodeReturnValue? uint128 - (.int (Int.ofNat (UInt256.land w uint128Mask).toNat)) = - some (UInt256.toByteArray (UInt256.land w uint128Mask)) := by - have hword : EVM.word (UInt256.land w uint128Mask).toNat = UInt256.land w uint128Mask := by - show UInt256.ofNat (UInt256.land w uint128Mask).toNat = UInt256.land w uint128Mask - exact u256_ofNat_toNat _ - refine scalarReturnEncoding (t := (.int (.uint ⟨128, by decide⟩))) - (w := UInt256.land w uint128Mask) rfl ?_ ?_ - · simp only [abiTupleHeadSize?, staticABIEncodedSize?, isDynamicABIType, bind, Option.bind] - decide - · simp [encodeABIValue?, encodeABIWord?, hword, uint128Mask_bound w] - -theorem uint128PairReturnEncodingMasked (w0 w1 : UInt256) : - encodeReturnValues? [uint128, uint128] - [.int (Int.ofNat (UInt256.land w0 uint128Mask).toNat), - .int (Int.ofNat (UInt256.land w1 uint128Mask).toNat)] = - some (UInt256.toByteArray (UInt256.land w0 uint128Mask) ++ - UInt256.toByteArray (UInt256.land w1 uint128Mask)) := by - let r0 := UInt256.land w0 uint128Mask - let r1 := UInt256.land w1 uint128Mask - have hword0 : EVM.word r0.toNat = r0 := by - show UInt256.ofNat r0.toNat = r0 - exact u256_ofNat_toNat r0 - have hword1 : EVM.word r1.toNat = r1 := by - show UInt256.ofNat r1.toNat = r1 - exact u256_ofNat_toNat r1 - have henc0 : - encodeABIValue? uint128 (.int (Int.ofNat r0.toNat)) = - some (EVM.Word.toBytesBE r0) := by - simp [uint128, uint128Int, encodeABIValue?, encodeABIWord?, hword0, - show r0.toNat < EVM.twoPow 128 from by simpa [r0] using uint128Mask_bound w0] - have henc1 : - encodeABIValue? uint128 (.int (Int.ofNat r1.toNat)) = - some (EVM.Word.toBytesBE r1) := by - simp [uint128, uint128Int, encodeABIValue?, encodeABIWord?, hword1, - show r1.toNat < EVM.twoPow 128 from by simpa [r1] using uint128Mask_bound w1] - have hhead : abiTupleHeadSize? [uint128, uint128] = some 64 := by - native_decide - have hdyn : isDynamicABIType uint128 = false := by - native_decide - change encodeReturnValues? [uint128, uint128] - [.int (Int.ofNat r0.toNat), .int (Int.ofNat r1.toNat)] = - some (UInt256.toByteArray r0 ++ UInt256.toByteArray r1) - rw [toByteArray_eq_toBytesBE r0, toByteArray_eq_toBytesBE r1] - simp only [encodeReturnValues?, encodeABIValues?, encodeABIValuesFrom?, hhead, henc0, henc1, - hdyn, bind, Option.bind, Bool.false_eq_true, if_false, List.nil_append, List.append_nil] - apply congrArg some - apply ByteArray.ext - apply Array.toList_inj.mp - simp [r0, r1] - -end Benchmarks.UniswapV3Pool diff --git a/Examples.lean b/Examples.lean index 81fea982..c2beda68 100644 --- a/Examples.lean +++ b/Examples.lean @@ -14,3 +14,5 @@ import Examples.OpenZeppelinBench.AccessControl.Correct import Examples.OpenZeppelinBench.Pausable.Correct import Examples.OpenZeppelinBench.ERC6909.Correct import Examples.UniswapV2Pair.Correct +import Examples.Reuse.Correct +import Examples.VyperERC20.Correct diff --git a/Examples/README.md b/Examples/README.md new file mode 100644 index 00000000..acf94a31 --- /dev/null +++ b/Examples/README.md @@ -0,0 +1,45 @@ +# Examples + +Contracts used to develop and exercise the framework. Each directory holds one contract: +its Sol⁻ specification (`Spec.lean`, with Solidity-like surface syntax in `SpecSyntax.lean`), +the exact compiled bytecode as a Lean byte array (`Bytecode.lean`), and the refinement proof, +assembled in `Correct.lean`. The top-level theorem of each example is named in the table. + +All proofs are complete except `UniswapV2Pair` (see status column). + +| Example | Source | Compiler | Top-level theorem | +|---|---|---|---| +| `Truth` | Hand-written one-getter contract | solc, optimizer off, Shanghai | `truthCorrect` | +| `Pow` | Hand-written loop (exponentiation) | solc, optimizer off, Shanghai | `powCorrect` | +| `Caller` | Hand-written external-call contract | solc, optimizer off, Shanghai | `callerCorrect` | +| `CtorTruth` | `Truth` plus its real solc constructor | solc, `--no-cbor-metadata`, Shanghai | `ctorTruthRuntimeCorrect` | +| `CtorStore` | Hand-written minimal initcode storing one word | hand-written creation bytecode | `ctorStoreRuntimeCorrect` | +| `ERC20` | Minimal hand-written ERC20 | solc, optimizer off, Shanghai | `erc20Correct` | +| `VyperERC20` | ERC20 in Vyper | vyper 0.4.3 | `runtimeCorrect` | +| `StringStoreLite` | Hand-written string-storage contract | solc, optimizer off, Shanghai | `stringStoreLiteCorrect` | +| `TinyImmutable` | Hand-written immutables contract | solc 0.8.35, standard-json | `tinyImmutableCorrect` | +| `Reuse` | Two functions sharing a code block | solc 0.8.35, optimizer on, Shanghai | `cCorrect` | +| `Ballot` | Solidity documentation example | solc 0.8.35, optimizer on, Shanghai | `ballotCorrect` | +| `SimpleAuction` | Solidity documentation example | solc 0.8.35, optimizer on, Shanghai | `simpleAuctionCorrect` | +| `BlindAuction` | Solidity documentation example | solc 0.8.35, optimizer on, Shanghai | `blindAuctionCorrect` | +| `OpenZeppelinBench/Ownable2Step` | OpenZeppelin Contracts (master snapshot, 2026-06-23) | solc, optimizer on, Shanghai | `ownable2StepCorrect` | +| `OpenZeppelinBench/AccessControl` | OpenZeppelin Contracts (same snapshot) | solc, optimizer on, Shanghai | `accessControlCorrect` | +| `OpenZeppelinBench/Pausable` | OpenZeppelin Contracts (same snapshot) | solc, optimizer on, Shanghai | `pausableCorrect` | +| `OpenZeppelinBench/ERC6909` | OpenZeppelin Contracts (same snapshot) | solc, optimizer on, Shanghai | `erc6909Correct` | +| `UniswapV2Pair` | Unmodified `Uniswap/v2-core` tag `v1.0.1` | solc 0.5.16, optimizer on (200 runs) | `uniswapV2PairCorrect` — **in progress** | + +## File conventions + +- `Spec.lean` — the Sol⁻ contract: storage layout, transitions, external-call hooks. +- `SpecSyntax.lean` — the same spec in Solidity-like surface syntax, proved equal to `Spec.lean`. +- `Bytecode.lean` — the compiled bytecode as a byte array, with the compiler invocation recorded + in the header, plus the verified jump-destination table. +- `Correct.lean` — the top-level theorem; per-function proofs live in sibling files. +- `.sol`/`.vy` sources are checked in next to the Lean files. + +## Trusted base + +Concrete keccak values cannot be computed inside Lean (`ffi.keccak256` is an opaque extern +function), so each contract's 4-byte function selectors are stated as per-contract axioms +(in `Bytecode.lean` or `Trusted.lean`). Jump-destination tables are verified with +`native_decide`, which trusts the Lean compiler. From d8387f40a3f93094618867f46e3f170a83a0fcfb Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 01:10:10 +0300 Subject: [PATCH 26/38] README: nits --- Benchmarks/README.md | 62 ++++++++++----------- Examples/README.md | 32 +++++------ README.md | 129 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 155 insertions(+), 68 deletions(-) diff --git a/Benchmarks/README.md b/Benchmarks/README.md index e06eeda4..c1723e22 100644 --- a/Benchmarks/README.md +++ b/Benchmarks/README.md @@ -18,26 +18,26 @@ Sizes are bytes of checked-in `runtime.hex`. | Benchmark | Upstream source | solc | Runtime bytes | Top-level theorem | |---|---|---|---|---| -| `WETH9` | Canonical mainnet WETH | 0.5.16 | 1763 | `weth9ContractCorrect` | -| `Dss/Dai` | MakerDAO `makerdao/dss` | 0.6.12 | 4011 | `daiContractCorrect` | -| `Dss/Vat` | MakerDAO `makerdao/dss` | 0.6.12 | 6965 | `vatContractCorrect` | -| `Dss/Vow` | MakerDAO `makerdao/dss` | 0.6.12 | 5150 | `vowContractCorrect` | -| `Dss/Pot` | MakerDAO `makerdao/dss` | 0.6.12 | 2595 | `potContractCorrect` | -| `Dss/Jug` | MakerDAO `makerdao/dss` | 0.6.12 | 2440 | `jugContractCorrect` | -| `Dss/Spot` | MakerDAO `makerdao/dss` | 0.6.12 | 2178 | `spotContractCorrect` | -| `Dss/Cat` | MakerDAO `makerdao/dss` | 0.6.12 | 3873 | `catContractCorrect` | -| `Dss/Dog` | MakerDAO `makerdao/dss` | 0.6.12 | 4745 | `dogContractCorrect` | -| `Dss/Cure` | MakerDAO `makerdao/dss` | 0.6.12 | 3875 | `cureContractCorrect` | -| `Dss/End` | MakerDAO `makerdao/dss` | 0.6.12 | 10265 | `endContractCorrect` | -| `Dss/Flapper` | MakerDAO `makerdao/dss` | 0.6.12 | 5008 | `flapperContractCorrect` | -| `Dss/Flipper` | MakerDAO `makerdao/dss` | 0.6.12 | 6386 | `flipperContractCorrect` | -| `Dss/Flopper` | MakerDAO `makerdao/dss` | 0.6.12 | 4780 | `flopperContractCorrect` | -| `Dss/GemJoin` | MakerDAO `makerdao/dss` (`join.sol`) | 0.6.12 | 2022 | `gemJoinContractCorrect` | -| `Dss/DaiJoin` | MakerDAO `makerdao/dss` (`join.sol`) | 0.6.12 | 1733 | `daiJoinContractCorrect` | -| `Dss/LinearDecrease` | MakerDAO `makerdao/dss` (`abaci.sol`) | 0.6.12 | 1128 | `linearDecreaseContractCorrect` | -| `Dss/StairstepExponentialDecrease` | MakerDAO `makerdao/dss` (`abaci.sol`) | 0.6.12 | 1433 | `stairstepExponentialDecreaseContractCorrect` | -| `Dss/ExponentialDecrease` | MakerDAO `makerdao/dss` (`abaci.sol`) | 0.6.12 | 1321 | `exponentialDecreaseContractCorrect` | -| `Dss/Clipper` | MakerDAO `makerdao/dss` | 0.6.12 | 9360 | `clipperContractCorrect` — **in progress**| +| `WETH9` | [`gnosis/canonical-weth`](https://github.com/gnosis/canonical-weth/blob/master/contracts/WETH9.sol) (canonical mainnet WETH) | 0.5.16 | 1763 | `weth9ContractCorrect` | +| `Dss/Dai` | [`makerdao/dss` `dai.sol`](https://github.com/makerdao/dss/blob/master/src/dai.sol) | 0.6.12 | 4011 | `daiContractCorrect` | +| `Dss/Vat` | [`makerdao/dss` `vat.sol`](https://github.com/makerdao/dss/blob/master/src/vat.sol) | 0.6.12 | 6965 | `vatContractCorrect` | +| `Dss/Vow` | [`makerdao/dss` `vow.sol`](https://github.com/makerdao/dss/blob/master/src/vow.sol) | 0.6.12 | 5150 | `vowContractCorrect` | +| `Dss/Pot` | [`makerdao/dss` `pot.sol`](https://github.com/makerdao/dss/blob/master/src/pot.sol) | 0.6.12 | 2595 | `potContractCorrect` | +| `Dss/Jug` | [`makerdao/dss` `jug.sol`](https://github.com/makerdao/dss/blob/master/src/jug.sol) | 0.6.12 | 2440 | `jugContractCorrect` | +| `Dss/Spot` | [`makerdao/dss` `spot.sol`](https://github.com/makerdao/dss/blob/master/src/spot.sol) | 0.6.12 | 2178 | `spotContractCorrect` | +| `Dss/Cat` | [`makerdao/dss` `cat.sol`](https://github.com/makerdao/dss/blob/master/src/cat.sol) | 0.6.12 | 3873 | `catContractCorrect` | +| `Dss/Dog` | [`makerdao/dss` `dog.sol`](https://github.com/makerdao/dss/blob/master/src/dog.sol) | 0.6.12 | 4745 | `dogContractCorrect` | +| `Dss/Cure` | [`makerdao/dss` `cure.sol`](https://github.com/makerdao/dss/blob/master/src/cure.sol) | 0.6.12 | 3875 | `cureContractCorrect` | +| `Dss/End` | [`makerdao/dss` `end.sol`](https://github.com/makerdao/dss/blob/master/src/end.sol) | 0.6.12 | 10265 | `endContractCorrect` | +| `Dss/Flapper` | [`makerdao/dss` `flap.sol`](https://github.com/makerdao/dss/blob/master/src/flap.sol) | 0.6.12 | 5008 | `flapperContractCorrect` | +| `Dss/Flipper` | [`makerdao/dss` `flip.sol`](https://github.com/makerdao/dss/blob/master/src/flip.sol) | 0.6.12 | 6386 | `flipperContractCorrect` | +| `Dss/Flopper` | [`makerdao/dss` `flop.sol`](https://github.com/makerdao/dss/blob/master/src/flop.sol) | 0.6.12 | 4780 | `flopperContractCorrect` | +| `Dss/GemJoin` | [`makerdao/dss` `join.sol`](https://github.com/makerdao/dss/blob/master/src/join.sol) | 0.6.12 | 2022 | `gemJoinContractCorrect` | +| `Dss/DaiJoin` | [`makerdao/dss` `join.sol`](https://github.com/makerdao/dss/blob/master/src/join.sol) | 0.6.12 | 1733 | `daiJoinContractCorrect` | +| `Dss/LinearDecrease` | [`makerdao/dss` `abaci.sol`](https://github.com/makerdao/dss/blob/master/src/abaci.sol) | 0.6.12 | 1128 | `linearDecreaseContractCorrect` | +| `Dss/StairstepExponentialDecrease` | [`makerdao/dss` `abaci.sol`](https://github.com/makerdao/dss/blob/master/src/abaci.sol) | 0.6.12 | 1433 | `stairstepExponentialDecreaseContractCorrect` | +| `Dss/ExponentialDecrease` | [`makerdao/dss` `abaci.sol`](https://github.com/makerdao/dss/blob/master/src/abaci.sol) | 0.6.12 | 1321 | `exponentialDecreaseContractCorrect` | +| `Dss/Clipper` | [`makerdao/dss` `clip.sol`](https://github.com/makerdao/dss/blob/master/src/clip.sol) | 0.6.12 | 9360 | `clipperContractCorrect` — **in progress**| `Dss/Clipper` stays here rather than in `Scaffolds/` because it completes the Dss suite and its proof is substantially under way. @@ -46,17 +46,17 @@ proof is substantially under way. | Benchmark | Upstream source | solc | Runtime bytes | |---|---|---|---| -| `Scaffolds/Safe` | Safe (Gnosis Safe) | 0.8.35 | 11874 | -| `Scaffolds/Klima` | KlimaDAO `KlimaToken` | 0.7.5 | 6975 | -| `Scaffolds/Auction` | Nouns auction house | 0.8.23 | 6150 | -| `Scaffolds/ERC721` | Compact ERC721 core | 0.8.35 | 1482 | -| `Scaffolds/EAS/Attester` | Ethereum Attestation Service | 0.8.26 | 3186 | -| `Scaffolds/CometRewards` | Compound III | 0.8.15 via-IR | 4063 | -| `Scaffolds/Comet` | Compound III | 0.8.15 via-IR | 18655 | -| `Scaffolds/VestingWallet` | OpenZeppelin Contracts | 0.8.35 | 2277 | -| `Scaffolds/TimelockController` | OpenZeppelin Contracts | 0.8.35 | 6509 | -| `Scaffolds/UniswapV3Pool` | `Uniswap/v3-core` | 0.7.6 | 22142 | -| `Scaffolds/UniswapV2Router02` | `Uniswap/v2-periphery` | 0.6.6 | 21955 | +| `Scaffolds/Safe` | [`safe-global/safe-smart-account`](https://github.com/safe-global/safe-smart-account/blob/77901a5a1ad835b74ad3b72f73a8412cfe491c57/contracts/Safe.sol) | 0.8.35 | 11874 | +| `Scaffolds/Klima` | [`KlimaDAO/klimadao-solidity`](https://github.com/KlimaDAO/klimadao-solidity/blob/0eb4770c1e9cbead8dd23ef0c23a9a27d761d029/src/protocol/tokens/regular/KlimaToken.sol) | 0.7.5 | 6975 | +| `Scaffolds/Auction` | [Nouns auction house, `nounsDAO/nouns-monorepo`](https://github.com/nounsDAO/nouns-monorepo) | 0.8.23 | 6150 | +| `Scaffolds/ERC721` | Benchmark-local compact ERC721 core ([`ERC721.sol`](Scaffolds/ERC721/ERC721.sol)) | 0.8.35 | 1482 | +| `Scaffolds/EAS/Attester` | [`ethereum-attestation-service/eas-contracts-example`](https://github.com/ethereum-attestation-service/eas-contracts-example/blob/d2864b166a08f9b3f9314f8b302316d67f227462/contracts/Attester.sol) | 0.8.26 | 3186 | +| `Scaffolds/CometRewards` | [`compound-finance/comet`](https://github.com/compound-finance/comet/blob/f766f51583c23acc33b2a7824654ef2029a96804/contracts/CometRewards.sol) | 0.8.15 via-IR | 4063 | +| `Scaffolds/Comet` | [`compound-finance/comet`](https://github.com/compound-finance/comet/blob/f766f51583c23acc33b2a7824654ef2029a96804/contracts/Comet.sol) | 0.8.15 via-IR | 18655 | +| `Scaffolds/VestingWallet` | [OpenZeppelin `VestingWallet.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/finance/VestingWallet.sol) | 0.8.35 | 2277 | +| `Scaffolds/TimelockController` | [OpenZeppelin `TimelockController.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/governance/TimelockController.sol) | 0.8.35 | 6509 | +| `Scaffolds/UniswapV3Pool` | [`Uniswap/v3-core`](https://github.com/Uniswap/v3-core/blob/d0831dc6b8a318df3872b6d68f6de135c9f3ec29/contracts/UniswapV3Pool.sol) | 0.7.6 | 22142 | +| `Scaffolds/UniswapV2Router02` | [`Uniswap/v2-periphery`](https://github.com/Uniswap/v2-periphery/blob/ed24991304291297c3b4a52818d02f46a17aa9a2/contracts/UniswapV2Router02.sol) | 0.6.6 | 21955 | `Scaffolds/CompoundIII/` and `Scaffolds/OpenZeppelinBench/` hold source closures shared by the respective scaffolds. diff --git a/Examples/README.md b/Examples/README.md index acf94a31..05a291f8 100644 --- a/Examples/README.md +++ b/Examples/README.md @@ -9,24 +9,24 @@ All proofs are complete except `UniswapV2Pair` (see status column). | Example | Source | Compiler | Top-level theorem | |---|---|---|---| -| `Truth` | Hand-written one-getter contract | solc, optimizer off, Shanghai | `truthCorrect` | -| `Pow` | Hand-written loop (exponentiation) | solc, optimizer off, Shanghai | `powCorrect` | -| `Caller` | Hand-written external-call contract | solc, optimizer off, Shanghai | `callerCorrect` | -| `CtorTruth` | `Truth` plus its real solc constructor | solc, `--no-cbor-metadata`, Shanghai | `ctorTruthRuntimeCorrect` | -| `CtorStore` | Hand-written minimal initcode storing one word | hand-written creation bytecode | `ctorStoreRuntimeCorrect` | -| `ERC20` | Minimal hand-written ERC20 | solc, optimizer off, Shanghai | `erc20Correct` | -| `VyperERC20` | ERC20 in Vyper | vyper 0.4.3 | `runtimeCorrect` | -| `StringStoreLite` | Hand-written string-storage contract | solc, optimizer off, Shanghai | `stringStoreLiteCorrect` | +| `Truth` | Hand-written one-getter contract | solc 0.8.35, optimizer off, Shanghai | `truthCorrect` | +| `Pow` | Hand-written loop (exponentiation) | solc 0.8.35, optimizer off, Shanghai | `powCorrect` | +| `Caller` | Hand-written external-call contract | solc 0.8.35, optimizer off, Shanghai | `callerCorrect` | +| `CtorTruth` | `Truth` plus its real solc constructor | solc 0.8.35, `--no-cbor-metadata`, Shanghai | `ctorTruthRuntimeCorrect` | +| `CtorStore` | Hand-written minimal initcode storing one word | solc 0.8.35 runtime, hand-written creation bytecode | `ctorStoreRuntimeCorrect` | +| `ERC20` | Minimal hand-written ERC20 | solc 0.8.35, optimizer off, Shanghai | `erc20Correct` | +| `VyperERC20` | Hand-written Vyper version of the minimal ERC20 | vyper 0.4.3 | `runtimeCorrect` | +| `StringStoreLite` | Hand-written string-storage contract | solc 0.8.35, optimizer off, Shanghai | `stringStoreLiteCorrect` | | `TinyImmutable` | Hand-written immutables contract | solc 0.8.35, standard-json | `tinyImmutableCorrect` | | `Reuse` | Two functions sharing a code block | solc 0.8.35, optimizer on, Shanghai | `cCorrect` | -| `Ballot` | Solidity documentation example | solc 0.8.35, optimizer on, Shanghai | `ballotCorrect` | -| `SimpleAuction` | Solidity documentation example | solc 0.8.35, optimizer on, Shanghai | `simpleAuctionCorrect` | -| `BlindAuction` | Solidity documentation example | solc 0.8.35, optimizer on, Shanghai | `blindAuctionCorrect` | -| `OpenZeppelinBench/Ownable2Step` | OpenZeppelin Contracts (master snapshot, 2026-06-23) | solc, optimizer on, Shanghai | `ownable2StepCorrect` | -| `OpenZeppelinBench/AccessControl` | OpenZeppelin Contracts (same snapshot) | solc, optimizer on, Shanghai | `accessControlCorrect` | -| `OpenZeppelinBench/Pausable` | OpenZeppelin Contracts (same snapshot) | solc, optimizer on, Shanghai | `pausableCorrect` | -| `OpenZeppelinBench/ERC6909` | OpenZeppelin Contracts (same snapshot) | solc, optimizer on, Shanghai | `erc6909Correct` | -| `UniswapV2Pair` | Unmodified `Uniswap/v2-core` tag `v1.0.1` | solc 0.5.16, optimizer on (200 runs) | `uniswapV2PairCorrect` — **in progress** | +| `Ballot` | [Solidity docs: Voting](https://docs.soliditylang.org/en/latest/solidity-by-example.html#voting) | solc 0.8.35, optimizer on, Shanghai | `ballotCorrect` | +| `SimpleAuction` | [Solidity docs: Simple Open Auction](https://docs.soliditylang.org/en/latest/solidity-by-example.html#simple-open-auction) | solc 0.8.35, optimizer on, Shanghai | `simpleAuctionCorrect` | +| `BlindAuction` | [Solidity docs: Blind Auction](https://docs.soliditylang.org/en/latest/solidity-by-example.html#blind-auction) | solc 0.8.35, optimizer on, Shanghai | `blindAuctionCorrect` | +| `OpenZeppelinBench/Ownable2Step` | [OpenZeppelin `Ownable2Step.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable2Step.sol) (master snapshot, 2026-06-23) | solc 0.8.35, optimizer on, Shanghai | `ownable2StepCorrect` | +| `OpenZeppelinBench/AccessControl` | [OpenZeppelin `AccessControl.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/AccessControl.sol) (same snapshot) | solc 0.8.35, optimizer on, Shanghai | `accessControlCorrect` | +| `OpenZeppelinBench/Pausable` | [OpenZeppelin `Pausable.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Pausable.sol) (same snapshot) | solc 0.8.35, optimizer on, Shanghai | `pausableCorrect` | +| `OpenZeppelinBench/ERC6909` | [OpenZeppelin `ERC6909.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC6909/ERC6909.sol) (same snapshot) | solc 0.8.35, optimizer on, Shanghai | `erc6909Correct` | +| `UniswapV2Pair` | [`Uniswap/v2-core` `v1.0.1`](https://github.com/Uniswap/v2-core/blob/v1.0.1/contracts/UniswapV2Pair.sol) | solc 0.5.16, optimizer on (200 runs) | `uniswapV2PairCorrect` — **in progress** | ## File conventions diff --git a/README.md b/README.md index 37960493..a2ffd27d 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,17 @@ verification of the contract's behavior or in human audits. Refinement proofs are intended to be generated by autonomous LLM agents. We are currently evaluating the capabilities of LLMs to provide such refinement proofs autonomously and their cost (see the `Examples/` and `Benchmarks/` directories). -The framework has been designed with this goal in mind. We have used the +The framework has been designed with this goal in mind. + +**Status.** EquiVM is experimental work under active development: the Sol⁻ +language, the reasoning library, and the proof interfaces are still evolving, +and the example and benchmark proof developments are at varying stages of +completion. We have used the framework to prove refinement for several real-world contracts, including MakerDAO's Dss, WETH9, and several OpenZeppelin contracts. Our case studies exercise various versions and options of the `solc` compiler, including the optimizer, and we have proof-of-concept proofs for the Vyper compiler as well. - ## Sol⁻ Sol⁻ is a small imperative language, inspired by Solidity and designed to be syntactically close to it. However, Sol⁻ is just a semantic specification @@ -27,8 +31,9 @@ compiler at all). Sol⁻ specifications are written in Lean with a Solidity-like surface syntax (`solidity%`, defined in [`Solm/Notation.lean`](Solm/Notation.lean)); every -contract under `Examples/` and `Benchmarks/` carries one in its -`SpecSyntax.lean`. From the ERC20 example: +contract under `Examples/` and `Benchmarks/` carries one specification in the +file `SpecSyntax.lean`. For example, for the ERC20 contract, the `transfer` +function is specified as: ```lean function transfer(address «to», uint256 value) external returns (bool) { @@ -49,14 +54,16 @@ EquiVM provides the tools for stating and proving that the bytecode implements the Sol⁻ specification. This includes semantics for the EVM, semantic rules for Sol⁻, the formal specification of the ABI, and the refinement relation between Sol⁻ and EVM. Furthermore, EquiVM provides a library of compositional lemmas and -tactics to help with the proofs. +tactics to help with the proofs. ## Refinement -The top-level *refinement* states that the bytecode faithfully implements the semantics of the Sol⁻ specification. The refinement relation is defined in [`Solm/Equiv.lean`](Solm/Equiv.lean). +The top-level *refinement* states that the bytecode faithfully implements the +semantics of the Sol⁻ specification. The refinement relation is defined in +[`Solm/Equiv.lean`](Solm/Equiv.lean). -Once refinement is established, one can reason about the bytecode at the Sol⁻ level. -This alleviates the need to both reason about low-level EVM bytecode and +Once refinement is established, one can reason about the bytecode at the Sol⁻ +level. This alleviates the need to both reason about low-level EVM bytecode and to trust the compiler that produced it. For a contract ``, the certificate is the capstone theorem of its @@ -70,33 +77,112 @@ theorem ContractCorrect : which bundles the constructor equivalence (creation code) with the runtime equivalence (deployed code). +## Walkthrough: the ERC20 example + +[`Examples/ERC20/`](Examples/ERC20/) is a minimal ERC20 token. It contains: + +- [`ERC20.sol`](Examples/ERC20/ERC20.sol) — the Solidity source, compiled with solc 0.8.35 + (optimizer off). +- [`Bytecode.lean`](Examples/ERC20/Bytecode.lean) — the exact compiled bytecode + as a Lean byte array, the verified jump-destination table, and the six + function selectors (per-contract trusted facts, since Keccak is an opaque + foreign constant). +- [`Spec.lean`](Examples/ERC20/Spec.lean) / + [`SpecSyntax.lean`](Examples/ERC20/SpecSyntax.lean) — the Sol⁻ specification, + and the same spec in surface syntax, proved definitionally equal. +- [`Correct.lean`](Examples/ERC20/Correct.lean) — the top-level theorem; + per-function proofs live in sibling files (`Transfer.lean`, `Approve.lean`, …). + +The specification declares the storage layout and one transition per ABI +function (`transfer` is shown in full above): + +```lean +def contractSyntax : ContractDecl := solidity% contract ERC20 { + mapping(address => uint256) balanceOf; + mapping(address => mapping(address => uint256)) allowance; + uint256 totalSupply; + + constructor(uint256 initialSupply) { + balanceOf[msg.sender] = initialSupply; + totalSupply = initialSupply; + } + + function approve(address spender, uint256 value) external returns (bool) { ... } + function totalSupply() external returns (uint256) { ... } + function transferFrom(address «from», address «to», uint256 value) external returns (bool) { ... } + function balanceOf(address owner) external returns (uint256) { ... } + function transfer(address «to», uint256 value) external returns (bool) { ... } + function allowance(address owner, address spender) external returns (uint256) { ... } +} +``` + +The top-level theorem is + +```lean +theorem erc20Correct : runtimeEquivalence erc20Config erc20Bytecode erc20Contract +``` + +It quantifies over every initial state: any account map, block environment, +calldata, call value, and gas, provided the deployed code is `erc20Bytecode`. +For each such state it relates one full execution of the bytecode to one +execution of the specification: either the bytecode execution runs out of gas +(in which case the specification side is unconstrained), or both revert (no +function matches the selector, argument decoding fails, or a `require` fails), +or both succeed, returning the same ABI-encoded value and leaving +observationally equal storage. Because the theorem holds for *all* inputs and +gas values, every behavior of the deployed contract is covered by the six +transitions of the specification above. The companion `erc20ContractCorrect` +bundles this with the constructor equivalence for the creation code. + +Checking the proof can be done with: + +```sh +lake build Examples.ERC20.Correct +``` + +and `#print axioms ERC20.erc20Correct` lists the trusted facts it rests on +(see *Trusted computing base* below). + ## Interoperability -One of the technical innovations of Sol⁻ is that it gives a formal semantics -to a contract interacting with arbitrary EVM bytecode. We achieve this by -using an approach inspired by multi-language semantics: the external call +One of the technical innovations of Sol⁻ is that it gives a formal semantics +to a contract interacting with arbitrary EVM bytecode. We achieve this by +using an approach inspired by multi-language semantics: the external call boundary is defined in terms of the EVM semantics. ## Architecture - **EVM semantics** ([`EVM/`](EVM/)) - We build on top of the [EVMLean](https://github.com/lefterislazar/EVMLean) semantics, a formal model of the EVM in Lean. The semantics is a port of Nethermind's [EVMYulLean](https://github.com/NethermindEth/EVMYulLean) to a newer version of Lean with a few other adjustments. The EVM semantics is executable and it passes the official EVM conformance test suite. + We build on top of the [EVMLean](https://github.com/lefterislazar/EVMLean) + semantics, a formal model of the EVM in Lean. The semantics is a port of + Nethermind's [EVMYulLean](https://github.com/NethermindEth/EVMYulLean) to a + newer version of Lean with a few other adjustments. The EVM semantics is + executable and it passes the official EVM conformance test suite. - **Sol⁻** ([`Solm/`](Solm/)) - This contains Sol⁻'s syntax, semantics, and surface notation. The file [`Solm/Equiv.lean`](Solm/Equiv.lean) defines the refinement relation between Sol⁻ and EVM. + This contains Sol⁻'s syntax, semantics, and surface notation. The file + [`Solm/Equiv.lean`](Solm/Equiv.lean) defines the refinement relation between + Sol⁻ and EVM. - **ABI** ([`ABI/`](ABI/)) - This contains the formal specification of the EVM ABI, including encoding and decoding of calldata and return data, function signatures, and selectors. + This contains the formal specification of the EVM ABI, including encoding and + decoding of calldata and return data, function signatures, and selectors. - **Reasoning library** ([`Reasoning/`](Reasoning/)) - A library of compositional lemmas and tactics to help with the proofs. - Among other things, it includes forward symbolic-execution combinators, dispatcher/ABI/storage lemmas, and external-call bridges. + A library of compositional lemmas and tactics to help with the proofs. Among + other things, it includes forward symbolic-execution combinators, + dispatcher/ABI/storage lemmas, and external-call bridges. - **Examples** ([`Examples/`](Examples/)) - Contracts (small or large ones) that were proved correct using LLMs in parallel to the development of the reasoning library. The proofs drove the design of the library and its lemmas and tactics. The file [`Examples/README.md`](Examples/README.md) is the per-contract status index. + Contracts (small or large ones) that were proved correct using LLMs in + parallel to the development of the reasoning library. The proofs drove the + design of the library and its lemmas and tactics. The file + [`Examples/README.md`](Examples/README.md) is the per-contract status index. - **Benchmarks** ([`Benchmarks/`](Benchmarks/)) - Larger case studies of real contracts that were proved correct by LLMs. The file [`Benchmarks/README.md`](Benchmarks/README.md) is the per-contract status index. + Larger case studies of real contracts that were proved correct by LLMs. The + file [`Benchmarks/README.md`](Benchmarks/README.md) is the per-contract + status index. - **Miscellaneous** ([`Misc/`](Misc/)) Miscellaneous files, including the contract template ([`Misc/Template/`](Misc/Template/)) @@ -130,7 +216,6 @@ is not a translation of it. LLMs can also be used to draft the Sol⁻ specification, or to audit its semantic faithfulness against the bytecode before attempting a proof. - ## Trusted computing base An EquiVM certificate is a Lean theorem, so what must be trusted is small: the @@ -150,7 +235,7 @@ To check a certificate: `lake build .Correct`, then `#print axioms .ContractCorrect` and compare the footprint against the accepted set above. -## Note on AI use +## Note on AI use The development of EquiVM is assisted by LLMs. Semantics and related definitions were designed and reviewed by humans. Proofs of equivalence between the Sol⁻ @@ -159,7 +244,9 @@ specifications themselves were produced by LLMs. ## Paper -You can find a detailed description of the theory and evaluation in the paper [*Foundational Refinement Proofs for Deployed Bytecode, at The Price of Tokens*](TODO). +A detailed description of the theory and evaluation can be found in the paper +*Foundational Refinement Proofs for Deployed Bytecode, at The Price of Tokens*. +The arXiv link will appear here as soon as the submission finishes processing. ## License From 7769f50b4b542d6daa64e00e3d52b53255856676 Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 01:46:00 +0300 Subject: [PATCH 27/38] Examples: add uniswapv2 progress --- Examples/UniswapV2Pair/Common.lean | 14 +- Examples/UniswapV2Pair/ExternalCalls.lean | 6 +- Examples/UniswapV2Pair/GetReserves.lean | 21 +- Examples/UniswapV2Pair/Initialize.lean | 4 +- Examples/UniswapV2Pair/Mint.lean | 81 ++++-- Examples/UniswapV2Pair/Permit.lean | 258 +++++++++++++++--- Examples/UniswapV2Pair/PermitDecode.lean | 10 +- Examples/UniswapV2Pair/Routines.lean | 16 +- .../UniswapV2Pair/SafeTransferRuntime.lean | 4 +- .../SkimSafeTransferRuntime.lean | 4 +- ...econdSafeTransferDynamicOffsetRuntime.lean | 8 +- .../SkimSecondSafeTransferRuntime.lean | 12 +- Examples/UniswapV2Pair/UpdateRoutines.lean | 6 +- README.md | 10 +- 14 files changed, 336 insertions(+), 118 deletions(-) diff --git a/Examples/UniswapV2Pair/Common.lean b/Examples/UniswapV2Pair/Common.lean index 76373cf9..2c2c46bf 100644 --- a/Examples/UniswapV2Pair/Common.lean +++ b/Examples/UniswapV2Pair/Common.lean @@ -1101,7 +1101,7 @@ theorem uniswapCheckedTokenBalanceOfThisCallsPrefix (by simp [evalStorageRef, evalStorageRefSteps, token1Ref, EvalResult.bind, pure, bind]) (by decide) (by rfl) hcall1 hdec1 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using.execBlock_append htoken0 htoken1 + using execBlock_append htoken0 htoken1 theorem uniswapCheckedTokenBalanceOfThisFirstCallNoCode (evm : EVM.State) (locals : Store) @@ -1116,7 +1116,7 @@ theorem uniswapCheckedTokenBalanceOfThisFirstCallNoCode exact uniswapCheckedExternalBalanceOfThisNoCode (evm := evm) (locals := locals) (ref := token0Ref) (retVar := "balance0") hguard0 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using.execBlock_append_term + using execBlock_append_term (s2 := token1BalanceOfThisStmts "balance1") hfirst (by intro f e h; cases h) theorem uniswapCheckedTokenBalanceOfThisFirstCallFailure @@ -1140,7 +1140,7 @@ theorem uniswapCheckedTokenBalanceOfThisFirstCallFailure (by simp [evalStorageRef, evalStorageRefSteps, token0Ref, EvalResult.bind, pure, bind]) (by decide) (by rfl) hcall0 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using.execBlock_append_term + using execBlock_append_term (s2 := token1BalanceOfThisStmts "balance1") hfirst (by intro f e h; cases h) theorem uniswapCheckedTokenBalanceOfThisFirstCallDecodeRevert @@ -1165,7 +1165,7 @@ theorem uniswapCheckedTokenBalanceOfThisFirstCallDecodeRevert (by simp [evalStorageRef, evalStorageRefSteps, token0Ref, EvalResult.bind, pure, bind]) (by decide) (by rfl) hcall0 hdec0 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using.execBlock_append_term + using execBlock_append_term (s2 := token1BalanceOfThisStmts "balance1") hfirst (by intro f e h; cases h) theorem uniswapCheckedTokenBalanceOfThisSecondCallNoCode @@ -1200,7 +1200,7 @@ theorem uniswapCheckedTokenBalanceOfThisSecondCallNoCode (evm := evm0) (locals := locals.insert "balance0" balance0) (ref := token1Ref) (retVar := "balance1") hguard1 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using.execBlock_append htoken0 htoken1 + using execBlock_append htoken0 htoken1 theorem uniswapCheckedTokenBalanceOfThisSecondCallFailure (evm evm0 evm1 : EVM.State) (locals : Store) @@ -1243,7 +1243,7 @@ theorem uniswapCheckedTokenBalanceOfThisSecondCallFailure (by simp [evalStorageRef, evalStorageRefSteps, token1Ref, EvalResult.bind, pure, bind]) (by decide) (by rfl) hcall1 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using.execBlock_append htoken0 htoken1 + using execBlock_append htoken0 htoken1 theorem uniswapCheckedTokenBalanceOfThisSecondCallDecodeRevert (evm evm0 evm1 : EVM.State) (locals : Store) @@ -1287,7 +1287,7 @@ theorem uniswapCheckedTokenBalanceOfThisSecondCallDecodeRevert (by simp [evalStorageRef, evalStorageRefSteps, token1Ref, EvalResult.bind, pure, bind]) (by decide) (by rfl) hcall1 hdec1 simpa [pairBalanceOfThisStmts, token0BalanceOfThisStmts, token1BalanceOfThisStmts] - using.execBlock_append htoken0 htoken1 + using execBlock_append htoken0 htoken1 theorem uniswapAddressGetterBodyReturns (evm : EVM.State) (locals : Store) {ref : StorageRef} {er : EvaledStorageRef} {slot : UInt256} diff --git a/Examples/UniswapV2Pair/ExternalCalls.lean b/Examples/UniswapV2Pair/ExternalCalls.lean index 2d9ad597..9b948585 100644 --- a/Examples/UniswapV2Pair/ExternalCalls.lean +++ b/Examples/UniswapV2Pair/ExternalCalls.lean @@ -95,12 +95,13 @@ theorem transferCalldataMem_read128_4 (recipient value : UInt256) : (by rw [transferSelectorMem_size]; omega) (by omega) (by rw [transferSelectorMem_size]; omega) (by norm_num) (by norm_num)] + have hzero32 : (ffi.ByteArray.zeroes 32).size = 32 := ByteArray_zeroes_size 32 rw [show transferSelectorMem = solcReturnMem transferSelectorShifted from rfl] rw [readWithPadding_eq_extract' _ 128 4 (by norm_num) (by norm_num) (by rw [solcReturnMem_size]; omega)] rw [solcReturnMem_eq] rw [extract_append_right_window - (solcFreePtrMem ++ ffi.ByteArray.zeroes 32) + (solcFreePtrMem ++ ffi.ByteArray.zeroes (32)) (UInt256.toByteArray transferSelectorShifted) 128 (128 + 4) (by simp [ByteArray.size_append, solcFreePtrMem_size, ByteArray_zeroes_size])] rw [ByteArray.size_append, solcFreePtrMem_size, ByteArray_zeroes_size] @@ -195,12 +196,13 @@ theorem transferCalldataMem_encode (recipient : AccountAddress) (value : UInt256 theorem balanceOfThisSelectorMem_read128_4 : balanceOfThisSelectorMem.readWithPadding 128 4 = balanceOfSelector := by + have hzero32 : (ffi.ByteArray.zeroes 32).size = 32 := ByteArray_zeroes_size 32 rw [show balanceOfThisSelectorMem = solcReturnMem balanceOfSelectorShifted from rfl] rw [readWithPadding_eq_extract' _ 128 4 (by norm_num) (by norm_num) (by rw [solcReturnMem_size]; omega)] rw [solcReturnMem_eq] rw [extract_append_right_window - (solcFreePtrMem ++ ffi.ByteArray.zeroes 32) + (solcFreePtrMem ++ ffi.ByteArray.zeroes (32)) (UInt256.toByteArray balanceOfSelectorShifted) 128 (128 + 4) (by simp [ByteArray.size_append, solcFreePtrMem_size, ByteArray_zeroes_size])] rw [ByteArray.size_append, solcFreePtrMem_size, ByteArray_zeroes_size] diff --git a/Examples/UniswapV2Pair/GetReserves.lean b/Examples/UniswapV2Pair/GetReserves.lean index 75afceac..3d11a86d 100644 --- a/Examples/UniswapV2Pair/GetReserves.lean +++ b/Examples/UniswapV2Pair/GetReserves.lean @@ -201,7 +201,8 @@ theorem getReservesReturn1Mem_size (r0 r1 : UInt256) : rw [toByteArray_write_eq _ _ _ (by rw [getReservesReturn0Mem_size]) (by rw [getReservesReturn0Mem_size]; exact lt_usize _ (by norm_num)), ByteArray.size_append, ByteArray.size_append, getReservesReturn0Mem_size, - ByteArray_zeroes_size, toByteArray_size] + ByteArray_zeroes_size, + toByteArray_size] theorem getReservesReturnMem_size (r0 r1 ts : UInt256) : (getReservesReturnMem r0 r1 ts).size = 224 := by @@ -209,7 +210,8 @@ theorem getReservesReturnMem_size (r0 r1 ts : UInt256) : rw [toByteArray_write_eq _ _ _ (by rw [getReservesReturn1Mem_size]) (by rw [getReservesReturn1Mem_size]; exact lt_usize _ (by norm_num)), ByteArray.size_append, ByteArray.size_append, getReservesReturn1Mem_size, - ByteArray_zeroes_size, toByteArray_size] + ByteArray_zeroes_size, + toByteArray_size] theorem getReservesReturn0Mem_read64 (r0 : UInt256) : (getReservesReturn0Mem r0).readWithPadding 64 32 = UInt256.toByteArray ⟨128⟩ := by @@ -218,7 +220,8 @@ theorem getReservesReturn0Mem_read64 (r0 : UInt256) : (by rw [solcFreePtrMem_size]; exact lt_usize _ (by norm_num))] rw [readWithPadding_eq_extract _ 64 (by rw [ByteArray.size_append, ByteArray.size_append, solcFreePtrMem_size, - ByteArray_zeroes_size, toByteArray_size] + ByteArray_zeroes_size, + toByteArray_size] native_decide)] rw [extract_append_left _ _ _ _ (by rw [ByteArray.size_append, solcFreePtrMem_size, ByteArray_zeroes_size] @@ -257,36 +260,34 @@ theorem getReservesReturnMem_read128_96 (r0 r1 ts : UInt256) : (by rw [getReservesReturn1Mem_size]; exact lt_usize _ (by norm_num))] rw [extract_append_span (getReservesReturn1Mem r0 r1 ++ - ffi.ByteArray.zeroes (192 - (getReservesReturn1Mem r0 r1).size)) + ffi.ByteArray.zeroes ((192 - (getReservesReturn1Mem r0 r1).size))) (UInt256.toByteArray ts) 128 (128 + 96) (by rw [ByteArray.size_append, getReservesReturn1Mem_size, ByteArray_zeroes_size] omega) (by rw [ByteArray.size_append, getReservesReturn1Mem_size, ByteArray_zeroes_size] omega)] rw [ByteArray.size_append, getReservesReturn1Mem_size, ByteArray_zeroes_size] - rw [show ffi.ByteArray.zeroes (192 - 192) = ByteArray.empty by - exact zeroes_zero (n := 0) (by rfl)] + rw [show ffi.ByteArray.zeroes (192 - 192) = ByteArray.empty from zeroes_zero rfl] simp unfold getReservesReturn1Mem rw [toByteArray_write_eq _ _ _ (by rw [getReservesReturn0Mem_size]) (by rw [getReservesReturn0Mem_size]; exact lt_usize _ (by norm_num))] rw [extract_append_span (getReservesReturn0Mem r0 ++ - ffi.ByteArray.zeroes (160 - (getReservesReturn0Mem r0).size)) + ffi.ByteArray.zeroes ((160 - (getReservesReturn0Mem r0).size))) (UInt256.toByteArray r1) 128 192 (by rw [ByteArray.size_append, getReservesReturn0Mem_size, ByteArray_zeroes_size] omega) (by rw [ByteArray.size_append, getReservesReturn0Mem_size, ByteArray_zeroes_size] omega)] rw [ByteArray.size_append, getReservesReturn0Mem_size, ByteArray_zeroes_size] - rw [show ffi.ByteArray.zeroes (160 - 160) = ByteArray.empty by - exact zeroes_zero (n := 0) (by rfl)] + rw [show ffi.ByteArray.zeroes (160 - 160) = ByteArray.empty from zeroes_zero rfl] simp unfold getReservesReturn0Mem rw [toByteArray_write_eq _ _ _ (by rw [solcFreePtrMem_size]; omega) (by rw [solcFreePtrMem_size]; exact lt_usize _ (by norm_num))] rw [extract_append_right_window - (solcFreePtrMem ++ ffi.ByteArray.zeroes (128 - solcFreePtrMem.size)) + (solcFreePtrMem ++ ffi.ByteArray.zeroes ((128 - solcFreePtrMem.size))) (UInt256.toByteArray r0) 128 160 (by rw [ByteArray.size_append, solcFreePtrMem_size, ByteArray_zeroes_size])] rw [ByteArray.size_append, solcFreePtrMem_size, ByteArray_zeroes_size] diff --git a/Examples/UniswapV2Pair/Initialize.lean b/Examples/UniswapV2Pair/Initialize.lean index 2ae84b83..23bfecb8 100644 --- a/Examples/UniswapV2Pair/Initialize.lean +++ b/Examples/UniswapV2Pair/Initialize.lean @@ -461,7 +461,7 @@ theorem uniswapX_initialize_success {cA gh bl σ σ₀ A I} {g : Sat256} {sel : State.lookupAccount] using rd3230₀⟩ have rd3256₀ := evm_run rd3230 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, swap4, dup5, and, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, swap2, dup3, and, lor, + push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, swap2, dup3, and, or, swap1, swap2] have hset0 : UInt256.lor @@ -490,7 +490,7 @@ theorem uniswapX_initialize_success {cA gh bl σ σ₀ A I} {g : Sat256} {sel : exact ⟨_, _, by simpa [initializeToken1OldWord, uniswapSlotWord, initState, Solm.EVM.storageLoad, State.lookupAccount] using rd3261₀⟩ - have rd3268₀ := evm_run rd3261 with [swap3, swap1, swap4, and, swap2, and, lor, swap1] + have rd3268₀ := evm_run rd3261 with [swap3, swap1, swap4, and, swap2, and, or, swap1] have hset1 : UInt256.lor (UInt256.land (initializeToken1OldWord σ I) (UInt256.lnot solcAddrMask)) diff --git a/Examples/UniswapV2Pair/Mint.lean b/Examples/UniswapV2Pair/Mint.lean index 7ba067d7..9d24cece 100644 --- a/Examples/UniswapV2Pair/Mint.lean +++ b/Examples/UniswapV2Pair/Mint.lean @@ -1033,10 +1033,7 @@ theorem uniswapMintBody hbound0Source hbound1Source helapsedSource) exact uniswapMintFinishProportionalFeeOffCumulative - (reserve0 := reserve0) (reserve1 := reserve1) - hcode hdispatch hsz36 - (by simpa [hreserve0Eq, hreserve1Eq] using hbody) - rd3701 + hcode hdispatch hsz36 hbody rd3701 hPostAccountsFee henvFeeI hcreatedFee rfl htotalNonzero hclean0 hclean1 hmulFit0 hmulFit1 hreserve0Nonzero hreserve1Nonzero rfl hliqNonzero @@ -1567,10 +1564,28 @@ theorem uniswapMintBody simpa [hmask] using hbound1 norm_num [maxUint112] exact_mod_cast hnat - -- TODO: Reconnect this source return after the post-main API - -- drift; elaborating the old body proof currently hits maxRecDepth. - exact by - sorry + have hbody := + ExecFuncBody.execBlockRet + (uniswapMintProportionalFeeOnCumulativeReturn_kLastZero + evmS evm0S evm1S evmFeeS I feeTo + (by simp only [evmS, initState]; exact hwv) + hunlockedSolm hguard0 hguard1 hcall0 hdec0 + hcall1 hdec1 hle0Source hle1Source hfeeGuard + hfeeCall hfeeDec hfeeToAddr hkLastSource + htotalSourceNonzero hfitSource0 hfitSource1 + hreserve0Source hreserve1Source hliquiditySource + hliqNonzero hfitSupplySource hbalanceFitSource + hbound0Source hbound1Source + helapsedSource hfitKLastSource) + exact + uniswapMintFinishProportionalFeeOnCumulativeKLastUpdated + hcode hdispatch hsz36 hbody rd3701 + hPostAccountsFee henvFeeI hcreatedFee rfl + htotalNonzero hclean0 hclean1 hmulFit0 hmulFit1 + hreserve0Nonzero hreserve1Nonzero rfl hliqNonzero + hperm htotalFit hbalanceFit hfitSupplySource + hbalanceFitSource hbound0 hbound1 helapsedNe + hfitKLastRuntime hmem hmem64 · let σCleared := sstoreAccountMap I.codeOwner σFee ⟨11⟩ ⟨0⟩ let evmAfterFee := mintFeeKLastClearedState evmFeeS @@ -2123,12 +2138,7 @@ theorem uniswapMintBody hbound1Source helapsedSource) exact uniswapMintFinishProportionalFeeOffCumulative - (reserve0 := reserve0) (reserve1 := reserve1) - (liquidity := liquidityCleared) - (totalSupply := totalSupplyCleared) - hcode hdispatch hsz36 - (by simpa [hreserve0Eq, hreserve1Eq] using hbody) - rd3701 + hcode hdispatch hsz36 hbody rd3701 hPostCleared henvCleared hcreatedCleared rfl htotalNonzero hclean0 hclean1 hmulFit0 hmulFit1 hreserve0Nonzero hreserve1Nonzero rfl hliqNonzero @@ -2596,22 +2606,41 @@ theorem uniswapMintBody UInt256.land feeToWord solcAddrMask ≠ ⟨0⟩ · by_cases hkLastNonzeroFinal : mintFeeKLastSlotWord σFee I ≠ ⟨0⟩ - · exact by - sorry - · exact by - sorry - · exact by - sorry + · exact False.elim (hfeeOnKLastNonzeroInitial (by + unfold mintFeeOnKLastNonzeroInitialOverflowFromFactoryCasesData + mintFeeOnKLastNonzeroInitialFromFactoryCasesData + mintFeeOnKLastNonzeroInitialReturnFromFactoryCaseData + mintFeeOnKLastNonzeroInitialZeroFromFactoryCaseData + mintFeeOnKLastNonzeroInitialProductOverflowFromFactoryCaseData + mintFeeOnKLastNonzeroInitialRootUnderflowFromFactoryCaseData + mintFeeOnKLastNonzeroInitialMinimumBalanceOverflowFromFactoryCaseData + mintFeeOnKLastNonzeroInitialSecondMintTotalSupplyOverflowFromFactoryCaseData + mintFeeOnKLastNonzeroInitialSecondMintBalanceOverflowFromFactoryCaseData + mintFeeOnKLastNonzeroNoFeeLiquidityFromFactoryCaseData + unfold mintFeeOnKLastNonzeroRootArithmeticOverflowFromFactoryCaseData at hrootArithmetic + unfold mintProportionalProductOverflowCase at hproductOverflow + unfold mintProportionalSecondMintOverflowCase at hsecondMintOverflow + simp [hfeeToNonzeroFinal, + hkLastNonzeroFinal, htotalEq])) + · exfalso + contradiction + · exfalso + contradiction · by_cases hfeeToNonzeroFinal : UInt256.land feeToWord solcAddrMask ≠ ⟨0⟩ · by_cases hkLastNonzeroFinal : mintFeeKLastSlotWord σFee I ≠ ⟨0⟩ - · exact by - sorry - · exact by - sorry - · exact by - sorry + · exact False.elim (hfeeOnKLastNonzeroSuccess (by + unfold mintFeeOnKLastNonzeroSuccessFromFactoryCasesData + mintFeeOnKLastNonzeroNoMintFromFactoryCaseData + unfold mintFeeOnKLastNonzeroRootArithmeticOverflowFromFactoryCaseData at hrootArithmetic + unfold mintProportionalProductOverflowCase at hproductOverflow + unfold mintProportionalSecondMintOverflowCase at hsecondMintOverflow + simp_all)) + · exfalso + contradiction + · exfalso + contradiction · rw [not_lt] at hdepth have hdepth1024 : I.depth = 1024 := Fin.ext (by have := I.depth.isLt; omega) let evmL := uniswapLockEnteredState evmS diff --git a/Examples/UniswapV2Pair/Permit.lean b/Examples/UniswapV2Pair/Permit.lean index f19cee14..0e2ac263 100644 --- a/Examples/UniswapV2Pair/Permit.lean +++ b/Examples/UniswapV2Pair/Permit.lean @@ -146,7 +146,7 @@ abbrev permitNonceWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := abbrev permitNonceNextWord (σ : AccountMap) (I : ExecutionEnv) : UInt256 := permitNonceWord σ I + ⟨1⟩ -abbrev permitStructTypehashWord : UInt256 := +abbrev permitTypehashWord : UInt256 := permitRuntimeTypehashWord noncomputable def permitStructHashDataWrites (σ : AccountMap) (I : ExecutionEnv) : @@ -203,11 +203,11 @@ theorem permitDigestMem_size (σ : AccountMap) (I : ExecutionEnv) : theorem permitStructHashMem_read160_192 (σ : AccountMap) (I : ExecutionEnv) : (permitStructHashMem σ I).readWithPadding 160 192 = - UInt256.toByteArray permitStructTypehashWord ++ UInt256.toByteArray (permitOwnerMaskedWord I) ++ + UInt256.toByteArray permitTypehashWord ++ UInt256.toByteArray (permitOwnerMaskedWord I) ++ UInt256.toByteArray (permitSpenderMaskedWord I) ++ UInt256.toByteArray (permitValueWord I) ++ UInt256.toByteArray (permitNonceWord σ I) ++ UInt256.toByteArray (permitDeadlineWord I) := by - simpa [permitStructHashMem, permitStructTypehashWord] using + simpa [permitStructHashMem, permitTypehashWord] using permitRuntimeStructHashMem_read160_192 (permitOwnerMaskedWord I) (permitSpenderMaskedWord I) (permitValueWord I) (permitNonceWord σ I) (permitDeadlineWord I) (permitNonceHashMem_size I) @@ -461,6 +461,18 @@ theorem fromByteArrayBigEndian_readWithPadding0_32_lt (o : ByteArray) : · rw [if_neg h] rw [ByteArray.size_extract] omega + have hz : + ({ toBitVec := + (↑32 : BitVec System.Platform.numBits) - ↑(o.readWithoutPadding 0 32).size } : + USize).toNat = + 32 - (o.readWithoutPadding 0 32).size := by + simpa using pad_toNat (o.readWithoutPadding 0 32).size hreadLe + change (o.readWithoutPadding 0 32).size + + ({ toBitVec := + (32 : BitVec System.Platform.numBits) - ↑(o.readWithoutPadding 0 32).size } : + USize).toNat = + 32 + rw [hz] omega rw [hlen] at h simpa [UInt256.size] using h @@ -877,19 +889,18 @@ theorem permitDecodeReturnValue_legacyAddress_none_short {returndata : ByteArray theorem uniswapEcrecoverDecode_ok {returndata : ByteArray} (hlo : 32 ≤ returndata.size) : config.externalABI.decode? "ecrecover" returndata = - some [.address (AccountAddress.ofNat - (fromByteArrayBigEndian (returndata.extract 0 32)))] := by + some (.address (AccountAddress.ofNat + (fromByteArrayBigEndian (returndata.extract 0 32)))) := by change uniswapExternalABI.decode? "ecrecover" returndata = _ - unfold uniswapExternalABI ExternalCallABI.decode? - simp [permitDecodeReturnValue_legacyAddress_ok (returndata := returndata) hlo] + simp [uniswapExternalABI, decodeEcrecoverOutput?] + rw [readWithPadding_eq_extract returndata 0 hlo] theorem uniswapEcrecoverDecode_padded (returndata : ByteArray) : config.externalABI.decode? "ecrecover" returndata = - some [.address (AccountAddress.ofNat - (fromByteArrayBigEndian (returndata.readWithPadding 0 32)))] := by - -- TODO: The current ExternalCallABI decoder rejects short return data, - -- while this legacy helper models Solidity's padded `ecrecover` read. - sorry + some (.address (AccountAddress.ofNat + (fromByteArrayBigEndian (returndata.readWithPadding 0 32)))) := by + change uniswapExternalABI.decode? "ecrecover" returndata = _ + simp [uniswapExternalABI, decodeEcrecoverOutput?] theorem permitDecodeABIValues_ok {I : ExecutionEnv} (hsz228 : 228 ≤ I.calldata.size) : decodeABIValues? [legacyAddr, legacyAddr, uint256, uint256, uint8, bytes32, bytes32] @@ -1336,7 +1347,7 @@ theorem evalExpr_permit_afterNonce_s (evm : EVM.State) (I : ExecutionEnv) : rw [permitAfterNonceLoadStore_s] theorem permitTypehashBytes_eq_toBytesBE : - permitTypehashBytes = EVM.Word.toBytesBE permitStructTypehashWord := by + permitTypehashBytes = EVM.Word.toBytesBE permitTypehashWord := by native_decide theorem byteArray_mk_toList_toArray (b : ByteArray) : @@ -1377,12 +1388,12 @@ theorem permitEncodePacked_bytes32 (w : UInt256) : theorem permitEncodePacked_typehash : encodePackedValue? bytes32 (.fixedBytes bytes32Width permitTypehashBytes) = - some (EVM.Word.toBytesBE permitStructTypehashWord) := by + some (EVM.Word.toBytesBE permitTypehashWord) := by have hlen : permitTypehashBytes.length = fixedBytesSize bytes32Width := by native_decide - have hbytes : permitTypehashBytes = EVM.Word.toBytesBE permitStructTypehashWord := + have hbytes : permitTypehashBytes = EVM.Word.toBytesBE permitTypehashWord := permitTypehashBytes_eq_toBytesBE - have hwordLen : (EVM.Word.toBytesBE permitStructTypehashWord).length = + have hwordLen : (EVM.Word.toBytesBE permitTypehashWord).length = fixedBytesSize bytes32Width := by simpa [← hbytes] using hlen simp [encodePackedValue?, bytes32, bytes32Width, hbytes, hwordLen] @@ -1539,7 +1550,7 @@ theorem evalPackedArgs_permit_structHash_at {cA gh bl σ σ₀ A I} {g : Sat256} simp only [byteArray_toList_append, List.append_assoc] refine permitEvalPackedArgs_cons (v := .fixedBytes bytes32Width permitTypehashBytes) - (head := permitStructTypehashWord.toByteArray.toList) + (head := permitTypehashWord.toByteArray.toList) (tailBytes := (permitOwnerMaskedWord I).toByteArray.toList ++ ((permitSpenderMaskedWord I).toByteArray.toList ++ @@ -1718,7 +1729,12 @@ theorem evalExpr_permit_digest_at {base cur : EVM.State} {σ I} { contract := contract, locals := permitAfterStructHashStore base I (permitStructHashValue σ I) } cur permitDigestExpr = .ok (permitDigestValue σ I) := by - sorry + rw [permitDigestExpr, evalExpr?, evalExpr?] + simp only [evalPackedArgs_permit_digest_at hdomain, EvalResult.bind, bind, + byteArray_mk_toList_toArray] + simp only [permitDigestValue, permitWordBytes32Value, permitDigestWord, permitRuntimeDigestWord] + rw [keccakSlot_eq, toBytesBE_keccak_uInt256OfByteArray] + rfl theorem evalExpr_permit_digest_afterNonce_at {cA gh bl σ σ₀ A I} {g : Sat256} : evalExpr? config @@ -2008,7 +2024,21 @@ theorem evalExpr_permit_afterEcrecover_require_true (base cur : EVM.State) (I : (.binary .ne (.var "recoveredAddress") zeroAddr) (.binary .eq (.var "recoveredAddress") (.var "owner"))) = .ok (.bool true) := by - sorry + have hownerNz : + AccountAddress.ofNat (permitOwnerWord I).toNat ≠ AccountAddress.ofNat 0 := by + intro h + apply hnz + rw [heq] + simp [permitOwnerValue, h] + simp only [zeroAddr, addrSt, evalExpr?, castValue?, EvalResult.ofOption, + EvalResult.bind, bind, pure] + rw [permitAfterEcrecoverStore_owner] + have hzero : + (Value.address (AccountAddress.ofNat (Int.toNat 0))) = + (Value.address (AccountAddress.ofNat 0)) := by + norm_num + rw [hzero] + simp [evalBinaryOp?, heq, hownerNz] theorem evalExpr_permit_afterEcrecover_require_false_zero (base cur : EVM.State) (I : ExecutionEnv) @@ -2076,7 +2106,7 @@ theorem uniswapPermitEcrecoverCallSuccess {evm evm' : EVM.State} {I : ExecutionE {structHash digest recovered : Value} {out : ByteArray} (hcall : typedCallViaEVM config evm (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, evm', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) : + (hdec : config.externalABI.decode? "ecrecover" out = some recovered) : ExecBlock config { contract := contract, locals := permitAfterDigestStore evm I structHash digest } evm [ .externalCall (.cast (.intLit 1) addrSt) "ecrecover" (.intLit 0) @@ -2093,7 +2123,7 @@ theorem uniswapPermitEcrecoverCallSuccess {evm evm' : EVM.State} {I : ExecutionE (args := [.var "digest", .var "v", .var "r", .var "s"]) (argVals := [digest, permitVValue I, permitRValue I, permitSValue I]) (retVar := "recoveredAddress") (perm := false) - (value := [recovered]) (out := out) + (value := recovered) (out := out) (evalExpr_permit_ecrecover_receiver { contract := contract, locals := permitAfterDigestStore evm I structHash digest } evm) (evalExprs_permit_ecrecover_args evm I structHash digest) @@ -2103,7 +2133,7 @@ theorem uniswapPermitEcrecoverCallSuccessAt {base cur cur' : EVM.State} {I : Exe {structHash digest recovered : Value} {out : ByteArray} (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) : + (hdec : config.externalABI.decode? "ecrecover" out = some recovered) : ExecBlock config { contract := contract, locals := permitAfterDigestStore base I structHash digest } cur [ .externalCall (.cast (.intLit 1) addrSt) "ecrecover" (.intLit 0) @@ -2120,7 +2150,7 @@ theorem uniswapPermitEcrecoverCallSuccessAt {base cur cur' : EVM.State} {I : Exe (args := [.var "digest", .var "v", .var "r", .var "s"]) (argVals := [digest, permitVValue I, permitRValue I, permitSValue I]) (retVar := "recoveredAddress") (perm := false) - (value := [recovered]) (out := out) + (value := recovered) (out := out) (evalExpr_permit_ecrecover_receiver { contract := contract, locals := permitAfterDigestStore base I structHash digest } cur) (evalExprs_permit_ecrecover_args_at base cur I structHash digest) @@ -2511,7 +2541,7 @@ theorem uniswapPermitHashEcrecoverSuccessAt {base cur cur' : EVM.State} {I : Exe cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) : + (hdec : config.externalABI.decode? "ecrecover" out = some recovered) : ExecBlock config { contract := contract, locals := permitAfterNonceLoadStore base I } cur [ .letDecl "structHash" (some bytes32) permitStructHashExpr, .letDecl "digest" (some bytes32) permitDigestExpr, @@ -2587,7 +2617,7 @@ theorem uniswapPermitHashEcrecoverRequireSuccessAt {base cur cur' : EVM.State} cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) + (hdec : config.externalABI.decode? "ecrecover" out = some recovered) (hnz : recovered ≠ .address (AccountAddress.ofNat 0)) (heq : recovered = permitOwnerValue I) : ExecBlock config { contract := contract, locals := permitAfterNonceLoadStore base I } cur @@ -2632,7 +2662,7 @@ theorem uniswapPermitHashEcrecoverRequireZeroRevertAt {base cur cur' : EVM.State cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) + (hdec : config.externalABI.decode? "ecrecover" out = some recovered) (hzero : recovered = .address (AccountAddress.ofNat 0)) : ExecBlock config { contract := contract, locals := permitAfterNonceLoadStore base I } cur [ .letDecl "structHash" (some bytes32) permitStructHashExpr, @@ -2672,7 +2702,7 @@ theorem uniswapPermitHashEcrecoverRequireMismatchRevertAt {base cur cur' : EVM.S cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) + (hdec : config.externalABI.decode? "ecrecover" out = some recovered) (haddr : recovered = .address recoveredAddr) (hnz : recoveredAddr ≠ AccountAddress.ofNat 0) (hne : .address recoveredAddr ≠ permitOwnerValue I) : @@ -2713,7 +2743,7 @@ theorem uniswapPermitAfterNonceSuccessAt {base cur cur' : EVM.State} cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) + (hdec : config.externalABI.decode? "ecrecover" out = some recovered) (hnz : recovered ≠ .address (AccountAddress.ofNat 0)) (heq : recovered = permitOwnerValue I) : ExecBlock config { contract := contract, locals := permitAfterNonceLoadStore base I } cur @@ -2791,7 +2821,7 @@ theorem uniswapPermitAfterNonceRequireZeroRevertAt {base cur cur' : EVM.State} cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) + (hdec : config.externalABI.decode? "ecrecover" out = some recovered) (hzero : recovered = .address (AccountAddress.ofNat 0)) : ExecBlock config { contract := contract, locals := permitAfterNonceLoadStore base I } cur permitAfterNonceBody .reverted := by @@ -2816,7 +2846,7 @@ theorem uniswapPermitAfterNonceRequireMismatchRevertAt {base cur cur' : EVM.Stat cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) + (hdec : config.externalABI.decode? "ecrecover" out = some recovered) (haddr : recovered = .address recoveredAddr) (hnz : recoveredAddr ≠ AccountAddress.ofNat 0) (hne : .address recoveredAddr ≠ permitOwnerValue I) : @@ -2886,7 +2916,9 @@ theorem uniswapPermitBlockAfterDeadline {evm : EVM.State} {I : ExecutionEnv} {re permitAfterDeadlineBody result) : ExecBlock config { contract := contract, locals := permitStore I } evm permitTransition.body result := by - sorry + have hblock := execBlock_append + (uniswapPermitDeadlinePrefix evm I hwv hnotExpired) hrest + simpa [permitTransition, permitDeadlinePrefixBody, permitAfterDeadlineBody] using hblock theorem uniswapPermitX_expired {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} (hexpired : (permitDeadlineWord I).toNat < @@ -3026,7 +3058,7 @@ theorem uniswapPermitX_structHashed {cA gh bl σ σ₀ A I} {g : Sat256} {sel : (by simp only [List.length_singleton]; omega) exact ⟨_, _, by simpa [permitStructHashWord, permitStructHashMem, permitStructHashLenMem, - permitStructHashDataMem, permitStructHashDataWrites, permitStructTypehashWord] using rd5688⟩ + permitStructHashDataMem, permitStructHashDataWrites, permitTypehashWord] using rd5688⟩ theorem uniswapPermitX_digestHashed {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} (hstructEvm : ∃ k C, RD uniswapV2PairBytecode I g @@ -3914,7 +3946,82 @@ theorem uniswapPermitBodyCoreOk_afterNonce UInt256.land (UInt256.ofNat (fromByteArrayBigEndian (o.extract 0 32))) solcAddrMask = permitOwnerMaskedWord I) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry + let evmS := initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I + let evmNonceS := permitAfterNonceState evmS I + let recoveredValue : Value := + .address (AccountAddress.ofNat (fromByteArrayBigEndian (o.extract 0 32))) + have hdec : config.externalABI.decode? "ecrecover" o = some recoveredValue := by + simpa [recoveredValue] using uniswapEcrecoverDecode_ok (returndata := o) ho32 + have hnzSource : recoveredValue ≠ .address (AccountAddress.ofNat 0) := by + simpa [recoveredValue] using permitRecoveredAddress_ne_zero_of_mask_ne_zero ho32 hnz + have hmatchSource : recoveredValue = permitOwnerValue I := by + simpa [recoveredValue] using permitRecoveredAddress_eq_owner_of_mask_eq ho32 hmatch + have hrest : + ExecBlock config { contract := contract, locals := permitAfterNonceLoadStore evmS I } + evmNonceS permitAfterNonceBody + (.ok (show Frame from + { contract := contract, + locals := permitAfterApproveStore evmS I + (permitStructHashValue σ_solm I) (permitDigestValue σ_solm I) recoveredValue }) + (permitApprovePostState evmCallS I)) := by + exact uniswapPermitAfterNonceSuccessAt (base := evmS) (cur := evmNonceS) + (cur' := evmCallS) (I := I) (structHash := permitStructHashValue σ_solm I) + (digest := permitDigestValue σ_solm I) (recovered := recoveredValue) (out := o) + (by simpa [evmS, evmNonceS] using hstruct) + (by simpa [evmS, evmNonceS] using hdigest) + hcall hdec hnzSource hmatchSource + have hafterNonce : + ExecBlock config { contract := contract, locals := permitStore I } evmS + permitAfterDeadlineBody + (.ok (show Frame from + { contract := contract, + locals := permitAfterApproveStore evmS I + (permitStructHashValue σ_solm I) (permitDigestValue σ_solm I) recoveredValue }) + (permitApprovePostState evmCallS I)) := by + exact uniswapPermitBlockAfterNonce (evm := evmS) (I := I) hrest + have hblock : + ExecBlock config { contract := contract, locals := permitStore I } evmS + permitTransition.body + (.ok (show Frame from + { contract := contract, + locals := permitAfterApproveStore evmS I + (permitStructHashValue σ_solm I) (permitDigestValue σ_solm I) recoveredValue }) + (permitApprovePostState evmCallS I)) := by + exact uniswapPermitBlockAfterDeadline (evm := evmS) (I := I) + (by simp only [evmS, initState]; exact hwv) + (by simpa [evmS, initState] using hnotExpired) + hafterNonce + have hbody : + ExecTransitionBody config contract + (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) (permitStore I) + permitTransition.body + (.returned (show Frame from + { contract := contract, + locals := permitAfterApproveStore evmS I + (permitStructHashValue σ_solm I) (permitDigestValue σ_solm I) recoveredValue }) + (permitApprovePostState evmCallS I) none) := by + simpa [evmS, ExecTransitionBody] using ExecFuncBody.execBlockOK hblock + have hok := uniswapPermitX_ecrecoverSignatureGuardOk + (g := Sat256.ofUInt256 g) hdecoded hnz hmatch + have rdRet := uniswapPermitX_approveAndReturn + (g := Sat256.ofUInt256 g) hok hperm ho32 hoSize + have hcreated : + (cA', sstoreAccountMap I.codeOwner σ' + (mapSlot (permitSpenderMaskedWord I) (mapSlot (permitOwnerMaskedWord I) ⟨2⟩)) + (permitValueWord I)).1 = + (permitApprovePostState evmCallS I).createdAccounts := by + simp [permitApprovePostState_createdAccounts, hcreatedCall] + have hAccountsPost : + accountMapEquiv + (sstoreAccountMap I.codeOwner σ' + (mapSlot (permitSpenderMaskedWord I) (mapSlot (permitOwnerMaskedWord I) ⟨2⟩)) + (permitValueWord I)) + (permitApprovePostState evmCallS I).accountMap := + permitApprovePostState_accountMap_equiv (evm := evmCallS) (I := I) (σ := σ') + henvCall hAccountsCall + exact rdRet.reEquivExecutionGenAccountMapEquiv hcode hdispatch + (uniswapDecode_permit_ok hsz228) hbody hcreated hAccountsPost + (returnEquiv.void rfl rfl rfl) theorem uniswapPermitBodyCoreOk_afterNonce_short {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {sel : UInt256} @@ -3967,7 +4074,82 @@ theorem uniswapPermitBodyCoreOk_afterNonce_short solcAddrMask = permitOwnerMaskedWord I) : runtimeEquivalenceFor config contract cA gh bl σ_evm σ_solm σ₀ g A I := by - sorry + let evmS := initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I + let evmNonceS := permitAfterNonceState evmS I + let recoveredValue : Value := + .address (AccountAddress.ofNat (fromByteArrayBigEndian (o.readWithPadding 0 32))) + have hdec : config.externalABI.decode? "ecrecover" o = some recoveredValue := by + simpa [recoveredValue] using uniswapEcrecoverDecode_padded (returndata := o) + have hnzSource : recoveredValue ≠ .address (AccountAddress.ofNat 0) := by + simpa [recoveredValue] using permitRecoveredPaddedAddress_ne_zero_of_mask_ne_zero hnz + have hmatchSource : recoveredValue = permitOwnerValue I := by + simpa [recoveredValue] using permitRecoveredPaddedAddress_eq_owner_of_mask_eq hmatch + have hrest : + ExecBlock config { contract := contract, locals := permitAfterNonceLoadStore evmS I } + evmNonceS permitAfterNonceBody + (.ok (show Frame from + { contract := contract, + locals := permitAfterApproveStore evmS I + (permitStructHashValue σ_solm I) (permitDigestValue σ_solm I) recoveredValue }) + (permitApprovePostState evmCallS I)) := by + exact uniswapPermitAfterNonceSuccessAt (base := evmS) (cur := evmNonceS) + (cur' := evmCallS) (I := I) (structHash := permitStructHashValue σ_solm I) + (digest := permitDigestValue σ_solm I) (recovered := recoveredValue) (out := o) + (by simpa [evmS, evmNonceS] using hstruct) + (by simpa [evmS, evmNonceS] using hdigest) + hcall hdec hnzSource hmatchSource + have hafterNonce : + ExecBlock config { contract := contract, locals := permitStore I } evmS + permitAfterDeadlineBody + (.ok (show Frame from + { contract := contract, + locals := permitAfterApproveStore evmS I + (permitStructHashValue σ_solm I) (permitDigestValue σ_solm I) recoveredValue }) + (permitApprovePostState evmCallS I)) := by + exact uniswapPermitBlockAfterNonce (evm := evmS) (I := I) hrest + have hblock : + ExecBlock config { contract := contract, locals := permitStore I } evmS + permitTransition.body + (.ok (show Frame from + { contract := contract, + locals := permitAfterApproveStore evmS I + (permitStructHashValue σ_solm I) (permitDigestValue σ_solm I) recoveredValue }) + (permitApprovePostState evmCallS I)) := by + exact uniswapPermitBlockAfterDeadline (evm := evmS) (I := I) + (by simp only [evmS, initState]; exact hwv) + (by simpa [evmS, initState] using hnotExpired) + hafterNonce + have hbody : + ExecTransitionBody config contract + (initState cA gh bl σ_solm σ₀ (Sat256.ofUInt256 g) A I) (permitStore I) + permitTransition.body + (.returned (show Frame from + { contract := contract, + locals := permitAfterApproveStore evmS I + (permitStructHashValue σ_solm I) (permitDigestValue σ_solm I) recoveredValue }) + (permitApprovePostState evmCallS I) none) := by + simpa [evmS, ExecTransitionBody] using ExecFuncBody.execBlockOK hblock + have hok := uniswapPermitX_ecrecoverSignatureGuardOk + (g := Sat256.ofUInt256 g) hdecoded hnz hmatch + have rdRet := uniswapPermitX_approveAndReturnShort + (g := Sat256.ofUInt256 g) hok hperm hshort hoSize + have hcreated : + (cA', sstoreAccountMap I.codeOwner σ' + (mapSlot (permitSpenderMaskedWord I) (mapSlot (permitOwnerMaskedWord I) ⟨2⟩)) + (permitValueWord I)).1 = + (permitApprovePostState evmCallS I).createdAccounts := by + simp [permitApprovePostState_createdAccounts, hcreatedCall] + have hAccountsPost : + accountMapEquiv + (sstoreAccountMap I.codeOwner σ' + (mapSlot (permitSpenderMaskedWord I) (mapSlot (permitOwnerMaskedWord I) ⟨2⟩)) + (permitValueWord I)) + (permitApprovePostState evmCallS I).accountMap := + permitApprovePostState_accountMap_equiv (evm := evmCallS) (I := I) (σ := σ') + henvCall hAccountsCall + exact rdRet.reEquivExecutionGenAccountMapEquiv hcode hdispatch + (uniswapDecode_permit_ok hsz228) hbody hcreated hAccountsPost + (returnEquiv.void rfl rfl rfl) theorem uniswapPermitBodyRevertsAfterNonce {evm : EVM.State} {I : ExecutionEnv} (hwv : evm.executionEnv.weiValue = ⟨0⟩) @@ -4082,7 +4264,7 @@ theorem uniswapPermitBodyCoreRevert_zero_afterNonce let evmNonceS := permitAfterNonceState evmS I let recoveredValue : Value := .address (AccountAddress.ofNat (fromByteArrayBigEndian (o.extract 0 32))) - have hdec : config.externalABI.decode? "ecrecover" o = some [recoveredValue] := by + have hdec : config.externalABI.decode? "ecrecover" o = some recoveredValue := by simpa [recoveredValue] using uniswapEcrecoverDecode_ok (returndata := o) ho32 have hzeroSource : recoveredValue = .address (AccountAddress.ofNat 0) := by simpa [recoveredValue] using permitRecoveredAddress_eq_zero_of_mask_eq_zero ho32 hzero @@ -4157,7 +4339,7 @@ theorem uniswapPermitBodyCoreRevert_mismatch_afterNonce let evmNonceS := permitAfterNonceState evmS I let recoveredAddr := AccountAddress.ofNat (fromByteArrayBigEndian (o.extract 0 32)) let recoveredValue : Value := .address recoveredAddr - have hdec : config.externalABI.decode? "ecrecover" o = some [recoveredValue] := by + have hdec : config.externalABI.decode? "ecrecover" o = some recoveredValue := by simpa [recoveredValue, recoveredAddr] using uniswapEcrecoverDecode_ok (returndata := o) ho32 have hnzValue : recoveredValue ≠ .address (AccountAddress.ofNat 0) := by simpa [recoveredValue, recoveredAddr] using @@ -4239,7 +4421,7 @@ theorem uniswapPermitBodyCoreRevert_zero_afterNonce_short let evmNonceS := permitAfterNonceState evmS I let recoveredValue : Value := .address (AccountAddress.ofNat (fromByteArrayBigEndian (o.readWithPadding 0 32))) - have hdec : config.externalABI.decode? "ecrecover" o = some [recoveredValue] := by + have hdec : config.externalABI.decode? "ecrecover" o = some recoveredValue := by simpa [recoveredValue] using uniswapEcrecoverDecode_padded (returndata := o) have hzeroSource : recoveredValue = .address (AccountAddress.ofNat 0) := by simpa [recoveredValue] using permitRecoveredPaddedAddress_eq_zero_of_mask_eq_zero hzero @@ -4316,7 +4498,7 @@ theorem uniswapPermitBodyCoreRevert_mismatch_afterNonce_short let evmNonceS := permitAfterNonceState evmS I let recoveredAddr := AccountAddress.ofNat (fromByteArrayBigEndian (o.readWithPadding 0 32)) let recoveredValue : Value := .address recoveredAddr - have hdec : config.externalABI.decode? "ecrecover" o = some [recoveredValue] := by + have hdec : config.externalABI.decode? "ecrecover" o = some recoveredValue := by simpa [recoveredValue, recoveredAddr] using uniswapEcrecoverDecode_padded (returndata := o) have hnzValue : recoveredValue ≠ .address (AccountAddress.ofNat 0) := by simpa [recoveredValue, recoveredAddr] using diff --git a/Examples/UniswapV2Pair/PermitDecode.lean b/Examples/UniswapV2Pair/PermitDecode.lean index d9562941..73b7cc64 100644 --- a/Examples/UniswapV2Pair/PermitDecode.lean +++ b/Examples/UniswapV2Pair/PermitDecode.lean @@ -33,20 +33,16 @@ theorem permitDecodeABIValue_uint8_legacy_ok_core {bytes : List UInt8} {start : some (.int (Int.ofNat ((ABI.bytesToWord ((bytes.drop start).take 32)).toNat % EVM.twoPow 8)), start + 32) := by - rw [decodeABIValue_scalarWordWithMode_eq (mode := DecodeMode.legacySolc05) - (ty := uint8) (bytes := bytes) (start := start) (by decide)] - simp only [uint8, uint8Int, decodeScalarWordWithMode?, readWord?, readBytes?, - decodeABIWord?, bind, Option.bind] + simp only [uint8, uint8Int, decodeABIValue?, readWord?, readBytes?, decodeABIWord?, bind, + Option.bind] rw [if_pos hlen] - simp only - rw [if_neg (show ¬ ((8 : Nat) = 0) from by decide)] rfl theorem permitDecodeABIValue_bytes32_ok_core {bytes : List UInt8} {start : Nat} (hlen : ((bytes.drop start).take 32).length = 32) : decodeABIValue? bytes32 bytes start DecodeMode.legacySolc05 = some (.fixedBytes bytes32Width ((bytes.drop start).take 32), start + 32) := by - simp only [bytes32, bytes32Width, decodeABIValue?, readBytes?, bind, + simp only [bytes32, bytes32Width, decodeABIValue?, readBytes?, zeroPadding?, bind, Option.bind] rw [if_pos hlen] simp diff --git a/Examples/UniswapV2Pair/Routines.lean b/Examples/UniswapV2Pair/Routines.lean index 065b35ea..947ebb10 100644 --- a/Examples/UniswapV2Pair/Routines.lean +++ b/Examples/UniswapV2Pair/Routines.lean @@ -1093,7 +1093,8 @@ theorem uniswapTransferLogMem_size (src toWord value : UInt256) : rw [toByteArray_write_eq _ _ _ (by rw [uniswapTransferCreditHashMem_size]; omega) (by rw [uniswapTransferCreditHashMem_size]; exact lt_usize _ (by norm_num)), ByteArray.size_append, ByteArray.size_append, uniswapTransferCreditHashMem_size, - ByteArray_zeroes_size, toByteArray_size] + ByteArray_zeroes_size, + toByteArray_size] theorem uniswapTransferLogMem_read64 (src toWord value : UInt256) : (uniswapTransferLogMem src toWord value).readWithPadding 64 32 = @@ -1131,10 +1132,11 @@ theorem uniswapTransferLogMem_read128 (src toWord value : UInt256) : (by rw [uniswapTransferCreditHashMem_size]; exact lt_usize _ (by norm_num))] rw [readWithPadding_eq_extract _ 128 (by rw [ByteArray.size_append, ByteArray.size_append, uniswapTransferCreditHashMem_size, - ByteArray_zeroes_size, toByteArray_size])] + ByteArray_zeroes_size, + toByteArray_size])] rw [extract_append_right_window (uniswapTransferCreditHashMem src toWord ++ - ffi.ByteArray.zeroes (128 - (uniswapTransferCreditHashMem src toWord).size)) + ffi.ByteArray.zeroes ((128 - (uniswapTransferCreditHashMem src toWord).size))) (UInt256.toByteArray value) 128 (128 + 32) (by rw [ByteArray.size_append, uniswapTransferCreditHashMem_size, ByteArray_zeroes_size])] rw [ByteArray.size_append, uniswapTransferCreditHashMem_size, ByteArray_zeroes_size] @@ -1350,7 +1352,8 @@ theorem uniswapApproveLogMem_size (owner spender value : UInt256) : rw [toByteArray_write_eq _ _ _ (by rw [uniswapApproveHashMem_size]; omega) (by rw [uniswapApproveHashMem_size]; exact lt_usize _ (by norm_num)), ByteArray.size_append, ByteArray.size_append, uniswapApproveHashMem_size, - ByteArray_zeroes_size, toByteArray_size] + ByteArray_zeroes_size, + toByteArray_size] theorem uniswapApproveLogMem_read64 (owner spender value : UInt256) : (uniswapApproveLogMem owner spender value).readWithPadding 64 32 = @@ -1388,10 +1391,11 @@ theorem uniswapApproveLogMem_read128 (owner spender value : UInt256) : (by rw [uniswapApproveHashMem_size]; exact lt_usize _ (by norm_num))] rw [readWithPadding_eq_extract _ 128 (by rw [ByteArray.size_append, ByteArray.size_append, uniswapApproveHashMem_size, - ByteArray_zeroes_size, toByteArray_size])] + ByteArray_zeroes_size, + toByteArray_size])] rw [extract_append_right_window (uniswapApproveHashMem owner spender ++ - ffi.ByteArray.zeroes (128 - (uniswapApproveHashMem owner spender).size)) + ffi.ByteArray.zeroes ((128 - (uniswapApproveHashMem owner spender).size))) (UInt256.toByteArray value) 128 (128 + 32) (by rw [ByteArray.size_append, uniswapApproveHashMem_size, ByteArray_zeroes_size])] rw [ByteArray.size_append, uniswapApproveHashMem_size, ByteArray_zeroes_size] diff --git a/Examples/UniswapV2Pair/SafeTransferRuntime.lean b/Examples/UniswapV2Pair/SafeTransferRuntime.lean index f5147431..159e48e1 100644 --- a/Examples/UniswapV2Pair/SafeTransferRuntime.lean +++ b/Examples/UniswapV2Pair/SafeTransferRuntime.lean @@ -996,7 +996,7 @@ theorem RD.uniswapSafeTransferEntryToCallMade {g : Sat256} {s0 : State} have rd6485 := rd6480.pushConst transferSelectorWord (width := 4) (op := .PUSH4) (by native_decide) (by native_decide) (by evm_ov) have rd6491 := evm_run rd6485 with [ - push1 ⟨224⟩, shl, lor, dup2, + push1 ⟨224⟩, shl, or, dup2, raw mstore 0 (safeTransferRuntimeMem7 base toWord value) (UInt256.ofNat 10) (by native_decide) mem_cost (by unfold safeTransferRuntimeMem7 safeTransferRuntimePatchedSelectorWord; rfl) @@ -1065,7 +1065,7 @@ theorem RD.uniswapSafeTransferEntryToCallMade {g : Sat256} {s0 : State} raw mload 3 ⟨0⟩ (UInt256.ofNat 13) (by native_decide) mem_cost (safeTransferRuntimeCallMem1_mload356 toWord value hbase) (by native_decide) (by evm_ov), - and, dup1, dup3, lor, dup6, + and, dup1, dup3, or, dup6, raw mstore 0 (safeTransferRuntimeCallMem2 base toWord value) (UInt256.ofNat 13) (by native_decide) mem_cost (by diff --git a/Examples/UniswapV2Pair/SkimSafeTransferRuntime.lean b/Examples/UniswapV2Pair/SkimSafeTransferRuntime.lean index 6dd9b37e..2ac56ba6 100644 --- a/Examples/UniswapV2Pair/SkimSafeTransferRuntime.lean +++ b/Examples/UniswapV2Pair/SkimSafeTransferRuntime.lean @@ -993,7 +993,7 @@ theorem RD.uniswapSkimSafeTransferCopySetupToSelectorPatch {g : Sat256} {s0 : St have rd6485 := rd6480.pushConst transferSelectorWord (width := 4) (op := .PUSH4) (by native_decide) (by native_decide) (by evm_ov) have rd6491 := evm_run rd6485 with [ - push1 ⟨224⟩, shl, lor, dup2, + push1 ⟨224⟩, shl, or, dup2, raw mstore 0 (skimSafeTransferMem7 self o toWord value) (UInt256.ofNat 10) (by native_decide) mem_cost (by unfold skimSafeTransferMem7 skimSafeTransferPatchedSelectorWord; rfl) @@ -1128,7 +1128,7 @@ theorem RD.uniswapSkimSafeTransferCopyTail {g : Sat256} {s0 : State} raw mload 3 ⟨0⟩ (UInt256.ofNat 13) (by native_decide) mem_cost (skimSafeTransferCallMem1_mload356 self toWord value ho32 hoSize) (by native_decide) (by evm_ov), - and, dup1, dup3, lor, dup6, + and, dup1, dup3, or, dup6, raw mstore 0 (skimSafeTransferCallMem2 self o toWord value) (UInt256.ofNat 13) (by native_decide) mem_cost (by unfold skimSafeTransferCallMem2 skimSafeTransferTailWord skimSafeTransferTailMask; rfl) diff --git a/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetRuntime.lean b/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetRuntime.lean index 395a5bcf..c228e4ec 100644 --- a/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetRuntime.lean +++ b/Examples/UniswapV2Pair/SkimSecondSafeTransferDynamicOffsetRuntime.lean @@ -424,8 +424,8 @@ theorem skimSafeTransferReturnDataMem_size_le_ptr_add32 omega private theorem byteArray_zeroes_size_le (n : Nat) : - (ffi.ByteArray.zeroes n).size ≤ n := by - rw [ByteArray_zeroes_size] + (ffi.ByteArray.zeroes n).size ≤ n := + (ByteArray_zeroes_size n).le private theorem byteArray_copySlice_size_le (source destination : ByteArray) (sourceOffset destinationOffset length : Nat) : @@ -2485,7 +2485,7 @@ theorem RD.uniswapSkimSecondSafeTransferEntryToCallMade_dynamic_offset have rd6485 := rd6480.pushConst transferSelectorWord (width := 4) (op := .PUSH4) (by native_decide) (by native_decide) (by evm_ov) have rd6491 := evm_run rd6485 with [ - push1 ⟨224⟩, shl, lor, dup2, + push1 ⟨224⟩, shl, or, dup2, raw mstore 0 (skimSecondSafeTransferDynamicMem7 self o toWord prevValue out1 out2 value) (skimSecondSafeTransferDynamicWordsMem4 out1) (by native_decide) @@ -2693,7 +2693,7 @@ theorem RD.uniswapSkimSecondSafeTransferEntryToCallMade_dynamic_offset prevValue value ho32 hoSize hout1Ne hout1Size hout2_32 hout2Size) (by unfold skimSecondSafeTransferDynamicWordsCall2; rfl) (by evm_ov), - and, dup1, dup3, lor, dup6, + and, dup1, dup3, or, dup6, raw mstore 0 (skimSecondSafeTransferDynamicCallMem2 self o toWord prevValue out1 out2 value) (skimSecondSafeTransferDynamicWordsCall2 out1) diff --git a/Examples/UniswapV2Pair/SkimSecondSafeTransferRuntime.lean b/Examples/UniswapV2Pair/SkimSecondSafeTransferRuntime.lean index 98bd2f32..2731766f 100644 --- a/Examples/UniswapV2Pair/SkimSecondSafeTransferRuntime.lean +++ b/Examples/UniswapV2Pair/SkimSecondSafeTransferRuntime.lean @@ -569,7 +569,9 @@ theorem skimSecondSafeTransferCallMem0_size exact lt_usize 0 (by norm_num)), ByteArray.size_append, ByteArray.size_append, skimSecondSafeTransferMem7_size self toWord prevValue value ho32 hoSize hout32 houtSize, - ByteArray_zeroes_size, toByteArray_size] + ByteArray_zeroes_size, + show (456 - 456 : ℕ) = 0 from rfl, + toByteArray_size] theorem skimSecondSafeTransferCallMem1_size (self : UInt256) {o : ByteArray} (toWord prevValue : UInt256) {out2 : ByteArray} @@ -590,7 +592,9 @@ theorem skimSecondSafeTransferCallMem1_size ByteArray.size_append, ByteArray.size_append, skimSecondSafeTransferCallMem0_size self toWord prevValue value ho32 hoSize hout32 houtSize, - ByteArray_zeroes_size, toByteArray_size] + ByteArray_zeroes_size, + show (488 - 488 : ℕ) = 0 from rfl, + toByteArray_size] theorem skimSecondSafeTransferCallMem2_size (self : UInt256) {o : ByteArray} (toWord prevValue : UInt256) {out2 : ByteArray} @@ -1277,7 +1281,7 @@ theorem RD.uniswapSkimSecondSafeTransferEntryToCallMade {g : Sat256} {s0 : State have rd6485 := rd6480.pushConst transferSelectorWord (width := 4) (op := .PUSH4) (by native_decide) (by native_decide) (by evm_ov) have rd6491 := evm_run rd6485 with [ - push1 ⟨224⟩, shl, lor, dup2, + push1 ⟨224⟩, shl, or, dup2, raw mstore 0 (skimSecondSafeTransferMem7 self o toWord prevValue out2 value) (UInt256.ofNat 15) (by native_decide) mem_cost @@ -1358,7 +1362,7 @@ theorem RD.uniswapSkimSecondSafeTransferEntryToCallMade {g : Sat256} {s0 : State mem_cost (skimSecondSafeTransferCallMem1_mload520 self toWord prevValue value ho32 hoSize hout32 houtSize) (by native_decide) (by evm_ov), - and, dup1, dup3, lor, dup6, + and, dup1, dup3, or, dup6, raw mstore 0 (skimSecondSafeTransferCallMem2 self o toWord prevValue out2 value) (UInt256.ofNat 18) (by native_decide) mem_cost diff --git a/Examples/UniswapV2Pair/UpdateRoutines.lean b/Examples/UniswapV2Pair/UpdateRoutines.lean index 458f35ae..68f70ef3 100644 --- a/Examples/UniswapV2Pair/UpdateRoutines.lean +++ b/Examples/UniswapV2Pair/UpdateRoutines.lean @@ -449,16 +449,16 @@ theorem RD.uniswapUpdateStorePackedReserves {g : Sat256} {s0 : State} (by decide) (by decide) (by evm_ov) have rd7278 := evm_run rd7261 with [ not, and, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨112⟩, shl, sub, dup9, dup2, and, - swap2, swap1, swap2, lor] + swap2, swap1, swap2, or] have rd7293 := rd7278.pushConst reserve112Mask (width := 14) (op := .PUSH14) (by decide) (by decide) (by evm_ov) have rd7338 := evm_run rd7293 with [ push1 ⟨112⟩, shl, not, and, push1 ⟨1⟩, push1 ⟨112⟩, shl, dup9, dup4, and, dup2, mul, - swap2, swap1, swap2, lor, + swap2, swap1, swap2, or, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨224⟩, shl, sub, and, push1 ⟨1⟩, push1 ⟨224⟩, shl, push4 ⟨4294967295⟩, dup8, and, mul, - lor, swap3, dup4, swap1] + or, swap3, dup4, swap1] obtain ⟨_, _, rd7339⟩ := rd7338.sstore hperm (by native_decide) (by simp only [List.length_cons]; omega) exact ⟨_, _, by diff --git a/README.md b/README.md index a2ffd27d..bb66d537 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,11 @@ The framework has been designed with this goal in mind. **Status.** EquiVM is experimental work under active development: the Sol⁻ language, the reasoning library, and the proof interfaces are still evolving, and the example and benchmark proof developments are at varying stages of -completion. We have used the -framework to prove refinement for several real-world contracts, including -MakerDAO's Dss, WETH9, and several OpenZeppelin contracts. Our case studies -exercise various versions and options of the `solc` compiler, including the -optimizer, and we have proof-of-concept proofs for the Vyper compiler as well. +completion. We have used the framework to prove refinement for several +real-world contracts, including MakerDAO's Dss, WETH9, and several OpenZeppelin +contracts. Our case studies exercise various versions and options of the `solc` +compiler, including optimizations, and we have proof-of-concept proofs for the +Vyper compiler as well. ## Sol⁻ Sol⁻ is a small imperative language, inspired by Solidity and designed to be From 5382acec0e1eac64173ade65f39427bd20641768 Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 09:19:55 +0300 Subject: [PATCH 28/38] Examples: add uniswapv2 progress --- Examples/UniswapV2Pair/MintFeeRoutines.lean | 16 ++--- Examples/UniswapV2Pair/Permit.lean | 80 ++++++++++----------- Examples/UniswapV2Pair/Swap.lean | 4 +- 3 files changed, 49 insertions(+), 51 deletions(-) diff --git a/Examples/UniswapV2Pair/MintFeeRoutines.lean b/Examples/UniswapV2Pair/MintFeeRoutines.lean index 7af7ae61..881be1a0 100644 --- a/Examples/UniswapV2Pair/MintFeeRoutines.lean +++ b/Examples/UniswapV2Pair/MintFeeRoutines.lean @@ -419,7 +419,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_fromRootBlock (ExecBlock.consReturn (ExecStmt.return (evalExprs?_singleton hreturn))) refine ExecFuncBody.execBlockRet ?_ simpa [mintFeeFunction, List.append_assoc] using - .execBlock_append hchecked htail + execBlock_append hchecked htail theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_positiveNoLiquidity (evm evmFee : EVM.State) (reserve0 reserve1 : UInt256) {out : ByteArray} @@ -481,7 +481,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_positiveNoLiquidity (mintFeeKLastWord evmFee) rootK rootKLast) evmFee) := by simpa [mintFeeRootComparisonStmt, mintFeePositiveRootBranchStmts, List.append_assoc] - using.execBlock_append hprefix + using execBlock_append hprefix (uniswapMintFeeAfterRoots_positiveNoLiquidity evmFee reserve0 reserve1 feeTo (mintFeeKLastWord evmFee) rootK rootKLast hroot hrootKNonneg hrootKSize hrootKLastNonneg hnumFit hrootFiveFit hdenFit hdenom hliq) @@ -561,7 +561,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_positiveWithLiquidity rootK rootKLast) (mintFunctionPostState evmFee feeTo (mintFeeLiquidityWord evmFee rootK rootKLast))) := by simpa [mintFeeRootComparisonStmt, mintFeePositiveRootBranchStmts, List.append_assoc] - using.execBlock_append hprefix + using execBlock_append hprefix (uniswapMintFeeAfterRoots_positiveWithLiquidity evmFee reserve0 reserve1 feeTo (mintFeeKLastWord evmFee) rootK rootKLast hroot hrootKNonneg hrootKSize hrootKLastNonneg hnumFit hrootFiveFit hdenFit hdenom hliq hliqFit hfitSupply @@ -632,7 +632,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_noMint (mintFeeKLastWord evmFee) rootK rootKLast) evmFee) := by simpa [mintFeeRootComparisonStmt, mintFeePositiveRootBranchStmts, List.append_assoc] - using.execBlock_append hprefix + using execBlock_append hprefix (uniswapMintFeeAfterRoots_noMint evmFee reserve0 reserve1 feeTo (mintFeeKLastWord evmFee) rootK rootKLast hroot) have htail : @@ -749,7 +749,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_noMint (mintFeeKLastWord evmFee) rootK rootKLast)))) refine ExecFuncBody.execBlockRet ?_ simpa [mintFeeFunction, List.append_assoc] using - .execBlock_append hchecked htail + execBlock_append hchecked htail theorem mintFeeAssignKLastZero (evm : EVM.State) (reserve0 reserve1 : UInt256) (feeTo : AccountAddress) @@ -880,7 +880,7 @@ theorem uniswapMintFeeFunctionBody_feeOff_kLastZero (mintFeeKLastWord evmFee))))) refine ExecFuncBody.execBlockRet ?_ simpa [mintFeeFunction, List.append_assoc] using - .execBlock_append hchecked htail + execBlock_append hchecked htail theorem uniswapMintFeeFunctionBody_feeOn_kLastZero (evm evmFee : EVM.State) (reserve0 reserve1 : UInt256) {out : ByteArray} @@ -1010,7 +1010,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastZero (mintFeeKLastWord evmFee))))) refine ExecFuncBody.execBlockRet ?_ simpa [mintFeeFunction, List.append_assoc] using - .execBlock_append hchecked htail + execBlock_append hchecked htail theorem uniswapMintFeeFunctionBody_feeOff_kLastNonzero (evm evmFee : EVM.State) (reserve0 reserve1 : UInt256) {out : ByteArray} @@ -1137,7 +1137,7 @@ theorem uniswapMintFeeFunctionBody_feeOff_kLastNonzero feeTo false (mintFeeKLastWord evmFee))))) refine ExecFuncBody.execBlockRet ?_ simpa [mintFeeFunction, List.append_assoc] using - .execBlock_append hchecked htail + execBlock_append hchecked htail end UniswapV2Pair diff --git a/Examples/UniswapV2Pair/Permit.lean b/Examples/UniswapV2Pair/Permit.lean index 0e2ac263..ae03ac64 100644 --- a/Examples/UniswapV2Pair/Permit.lean +++ b/Examples/UniswapV2Pair/Permit.lean @@ -461,18 +461,6 @@ theorem fromByteArrayBigEndian_readWithPadding0_32_lt (o : ByteArray) : · rw [if_neg h] rw [ByteArray.size_extract] omega - have hz : - ({ toBitVec := - (↑32 : BitVec System.Platform.numBits) - ↑(o.readWithoutPadding 0 32).size } : - USize).toNat = - 32 - (o.readWithoutPadding 0 32).size := by - simpa using pad_toNat (o.readWithoutPadding 0 32).size hreadLe - change (o.readWithoutPadding 0 32).size + - ({ toBitVec := - (32 : BitVec System.Platform.numBits) - ↑(o.readWithoutPadding 0 32).size } : - USize).toNat = - 32 - rw [hz] omega rw [hlen] at h simpa [UInt256.size] using h @@ -889,18 +877,23 @@ theorem permitDecodeReturnValue_legacyAddress_none_short {returndata : ByteArray theorem uniswapEcrecoverDecode_ok {returndata : ByteArray} (hlo : 32 ≤ returndata.size) : config.externalABI.decode? "ecrecover" returndata = - some (.address (AccountAddress.ofNat - (fromByteArrayBigEndian (returndata.extract 0 32)))) := by + some [.address (AccountAddress.ofNat + (fromByteArrayBigEndian (returndata.extract 0 32)))] := by change uniswapExternalABI.decode? "ecrecover" returndata = _ - simp [uniswapExternalABI, decodeEcrecoverOutput?] - rw [readWithPadding_eq_extract returndata 0 hlo] - + simp [uniswapExternalABI, permitDecodeReturnValue_legacyAddress_ok hlo] + +-- BLOCKED: false for `returndata.size < 32` — the legacy decoder returns `none` there +-- (`permitDecodeReturnValue_legacyAddress_none_short`), so the source statement decode-reverts +-- while the bytecode uses the zero-padded word. Its three call sites (`…_afterNonce_short`, +-- `…_zero_afterNonce_short`, `…_mismatch_afterNonce_short`) are reached from +-- `uniswapPermitBody_depthOk` under `hshort : o.size < 32` with `o` an arbitrary Θ output, +-- so no `32 ≤ o.size` fact is available. Needs an architecture decision (see report). theorem uniswapEcrecoverDecode_padded (returndata : ByteArray) : config.externalABI.decode? "ecrecover" returndata = - some (.address (AccountAddress.ofNat - (fromByteArrayBigEndian (returndata.readWithPadding 0 32)))) := by + some [.address (AccountAddress.ofNat + (fromByteArrayBigEndian (returndata.readWithPadding 0 32)))] := by change uniswapExternalABI.decode? "ecrecover" returndata = _ - simp [uniswapExternalABI, decodeEcrecoverOutput?] + simp [uniswapExternalABI] theorem permitDecodeABIValues_ok {I : ExecutionEnv} (hsz228 : 228 ≤ I.calldata.size) : decodeABIValues? [legacyAddr, legacyAddr, uint256, uint256, uint8, bytes32, bytes32] @@ -2039,6 +2032,11 @@ theorem evalExpr_permit_afterEcrecover_require_true (base cur : EVM.State) (I : norm_num rw [hzero] simp [evalBinaryOp?, heq, hownerNz] + have hbeqFalse : + (permitOwnerValue I == Value.address (AccountAddress.ofNat 0)) = false := by + simp [permitOwnerValue, hownerNz] + rw [hbeqFalse] + rfl theorem evalExpr_permit_afterEcrecover_require_false_zero (base cur : EVM.State) (I : ExecutionEnv) @@ -2106,7 +2104,7 @@ theorem uniswapPermitEcrecoverCallSuccess {evm evm' : EVM.State} {I : ExecutionE {structHash digest recovered : Value} {out : ByteArray} (hcall : typedCallViaEVM config evm (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, evm', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some recovered) : + (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) : ExecBlock config { contract := contract, locals := permitAfterDigestStore evm I structHash digest } evm [ .externalCall (.cast (.intLit 1) addrSt) "ecrecover" (.intLit 0) @@ -2114,7 +2112,7 @@ theorem uniswapPermitEcrecoverCallSuccess {evm evm' : EVM.State} {I : ExecutionE (.ok (show Frame from { contract := contract, locals := permitAfterEcrecoverStore evm I structHash digest recovered }) evm') := by - simpa [permitAfterEcrecoverStore] using + simpa [permitAfterEcrecoverStore, collapseReturns] using (Reasoning.Theory.externalCallSuccess (cfg := config) (C := contract) (evm := evm) (evm' := evm') (locals := permitAfterDigestStore evm I structHash digest) @@ -2123,7 +2121,7 @@ theorem uniswapPermitEcrecoverCallSuccess {evm evm' : EVM.State} {I : ExecutionE (args := [.var "digest", .var "v", .var "r", .var "s"]) (argVals := [digest, permitVValue I, permitRValue I, permitSValue I]) (retVar := "recoveredAddress") (perm := false) - (value := recovered) (out := out) + (value := [recovered]) (out := out) (evalExpr_permit_ecrecover_receiver { contract := contract, locals := permitAfterDigestStore evm I structHash digest } evm) (evalExprs_permit_ecrecover_args evm I structHash digest) @@ -2133,7 +2131,7 @@ theorem uniswapPermitEcrecoverCallSuccessAt {base cur cur' : EVM.State} {I : Exe {structHash digest recovered : Value} {out : ByteArray} (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some recovered) : + (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) : ExecBlock config { contract := contract, locals := permitAfterDigestStore base I structHash digest } cur [ .externalCall (.cast (.intLit 1) addrSt) "ecrecover" (.intLit 0) @@ -2141,7 +2139,7 @@ theorem uniswapPermitEcrecoverCallSuccessAt {base cur cur' : EVM.State} {I : Exe (.ok (show Frame from { contract := contract, locals := permitAfterEcrecoverStore base I structHash digest recovered }) cur') := by - simpa [permitAfterEcrecoverStore] using + simpa [permitAfterEcrecoverStore, collapseReturns] using (Reasoning.Theory.externalCallSuccess (cfg := config) (C := contract) (evm := cur) (evm' := cur') (locals := permitAfterDigestStore base I structHash digest) @@ -2150,7 +2148,7 @@ theorem uniswapPermitEcrecoverCallSuccessAt {base cur cur' : EVM.State} {I : Exe (args := [.var "digest", .var "v", .var "r", .var "s"]) (argVals := [digest, permitVValue I, permitRValue I, permitSValue I]) (retVar := "recoveredAddress") (perm := false) - (value := recovered) (out := out) + (value := [recovered]) (out := out) (evalExpr_permit_ecrecover_receiver { contract := contract, locals := permitAfterDigestStore base I structHash digest } cur) (evalExprs_permit_ecrecover_args_at base cur I structHash digest) @@ -2541,7 +2539,7 @@ theorem uniswapPermitHashEcrecoverSuccessAt {base cur cur' : EVM.State} {I : Exe cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some recovered) : + (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) : ExecBlock config { contract := contract, locals := permitAfterNonceLoadStore base I } cur [ .letDecl "structHash" (some bytes32) permitStructHashExpr, .letDecl "digest" (some bytes32) permitDigestExpr, @@ -2617,7 +2615,7 @@ theorem uniswapPermitHashEcrecoverRequireSuccessAt {base cur cur' : EVM.State} cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some recovered) + (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) (hnz : recovered ≠ .address (AccountAddress.ofNat 0)) (heq : recovered = permitOwnerValue I) : ExecBlock config { contract := contract, locals := permitAfterNonceLoadStore base I } cur @@ -2662,7 +2660,7 @@ theorem uniswapPermitHashEcrecoverRequireZeroRevertAt {base cur cur' : EVM.State cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some recovered) + (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) (hzero : recovered = .address (AccountAddress.ofNat 0)) : ExecBlock config { contract := contract, locals := permitAfterNonceLoadStore base I } cur [ .letDecl "structHash" (some bytes32) permitStructHashExpr, @@ -2702,7 +2700,7 @@ theorem uniswapPermitHashEcrecoverRequireMismatchRevertAt {base cur cur' : EVM.S cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some recovered) + (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) (haddr : recovered = .address recoveredAddr) (hnz : recoveredAddr ≠ AccountAddress.ofNat 0) (hne : .address recoveredAddr ≠ permitOwnerValue I) : @@ -2743,7 +2741,7 @@ theorem uniswapPermitAfterNonceSuccessAt {base cur cur' : EVM.State} cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some recovered) + (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) (hnz : recovered ≠ .address (AccountAddress.ofNat 0)) (heq : recovered = permitOwnerValue I) : ExecBlock config { contract := contract, locals := permitAfterNonceLoadStore base I } cur @@ -2821,7 +2819,7 @@ theorem uniswapPermitAfterNonceRequireZeroRevertAt {base cur cur' : EVM.State} cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some recovered) + (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) (hzero : recovered = .address (AccountAddress.ofNat 0)) : ExecBlock config { contract := contract, locals := permitAfterNonceLoadStore base I } cur permitAfterNonceBody .reverted := by @@ -2846,7 +2844,7 @@ theorem uniswapPermitAfterNonceRequireMismatchRevertAt {base cur cur' : EVM.Stat cur permitDigestExpr = .ok digest) (hcall : typedCallViaEVM config cur (AccountAddress.ofNat 1) "ecrecover" 0 [digest, permitVValue I, permitRValue I, permitSValue I] (true, cur', out) false) - (hdec : config.externalABI.decode? "ecrecover" out = some recovered) + (hdec : config.externalABI.decode? "ecrecover" out = some [recovered]) (haddr : recovered = .address recoveredAddr) (hnz : recoveredAddr ≠ AccountAddress.ofNat 0) (hne : .address recoveredAddr ≠ permitOwnerValue I) : @@ -3950,7 +3948,7 @@ theorem uniswapPermitBodyCoreOk_afterNonce let evmNonceS := permitAfterNonceState evmS I let recoveredValue : Value := .address (AccountAddress.ofNat (fromByteArrayBigEndian (o.extract 0 32))) - have hdec : config.externalABI.decode? "ecrecover" o = some recoveredValue := by + have hdec : config.externalABI.decode? "ecrecover" o = some [recoveredValue] := by simpa [recoveredValue] using uniswapEcrecoverDecode_ok (returndata := o) ho32 have hnzSource : recoveredValue ≠ .address (AccountAddress.ofNat 0) := by simpa [recoveredValue] using permitRecoveredAddress_ne_zero_of_mask_ne_zero ho32 hnz @@ -4021,7 +4019,7 @@ theorem uniswapPermitBodyCoreOk_afterNonce henvCall hAccountsCall exact rdRet.reEquivExecutionGenAccountMapEquiv hcode hdispatch (uniswapDecode_permit_ok hsz228) hbody hcreated hAccountsPost - (returnEquiv.void rfl rfl rfl) + (returnEquiv.fallthrough rfl rfl (by native_decide)) theorem uniswapPermitBodyCoreOk_afterNonce_short {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} {sel : UInt256} @@ -4078,7 +4076,7 @@ theorem uniswapPermitBodyCoreOk_afterNonce_short let evmNonceS := permitAfterNonceState evmS I let recoveredValue : Value := .address (AccountAddress.ofNat (fromByteArrayBigEndian (o.readWithPadding 0 32))) - have hdec : config.externalABI.decode? "ecrecover" o = some recoveredValue := by + have hdec : config.externalABI.decode? "ecrecover" o = some [recoveredValue] := by simpa [recoveredValue] using uniswapEcrecoverDecode_padded (returndata := o) have hnzSource : recoveredValue ≠ .address (AccountAddress.ofNat 0) := by simpa [recoveredValue] using permitRecoveredPaddedAddress_ne_zero_of_mask_ne_zero hnz @@ -4149,7 +4147,7 @@ theorem uniswapPermitBodyCoreOk_afterNonce_short henvCall hAccountsCall exact rdRet.reEquivExecutionGenAccountMapEquiv hcode hdispatch (uniswapDecode_permit_ok hsz228) hbody hcreated hAccountsPost - (returnEquiv.void rfl rfl rfl) + (returnEquiv.fallthrough rfl rfl (by native_decide)) theorem uniswapPermitBodyRevertsAfterNonce {evm : EVM.State} {I : ExecutionEnv} (hwv : evm.executionEnv.weiValue = ⟨0⟩) @@ -4264,7 +4262,7 @@ theorem uniswapPermitBodyCoreRevert_zero_afterNonce let evmNonceS := permitAfterNonceState evmS I let recoveredValue : Value := .address (AccountAddress.ofNat (fromByteArrayBigEndian (o.extract 0 32))) - have hdec : config.externalABI.decode? "ecrecover" o = some recoveredValue := by + have hdec : config.externalABI.decode? "ecrecover" o = some [recoveredValue] := by simpa [recoveredValue] using uniswapEcrecoverDecode_ok (returndata := o) ho32 have hzeroSource : recoveredValue = .address (AccountAddress.ofNat 0) := by simpa [recoveredValue] using permitRecoveredAddress_eq_zero_of_mask_eq_zero ho32 hzero @@ -4339,7 +4337,7 @@ theorem uniswapPermitBodyCoreRevert_mismatch_afterNonce let evmNonceS := permitAfterNonceState evmS I let recoveredAddr := AccountAddress.ofNat (fromByteArrayBigEndian (o.extract 0 32)) let recoveredValue : Value := .address recoveredAddr - have hdec : config.externalABI.decode? "ecrecover" o = some recoveredValue := by + have hdec : config.externalABI.decode? "ecrecover" o = some [recoveredValue] := by simpa [recoveredValue, recoveredAddr] using uniswapEcrecoverDecode_ok (returndata := o) ho32 have hnzValue : recoveredValue ≠ .address (AccountAddress.ofNat 0) := by simpa [recoveredValue, recoveredAddr] using @@ -4421,7 +4419,7 @@ theorem uniswapPermitBodyCoreRevert_zero_afterNonce_short let evmNonceS := permitAfterNonceState evmS I let recoveredValue : Value := .address (AccountAddress.ofNat (fromByteArrayBigEndian (o.readWithPadding 0 32))) - have hdec : config.externalABI.decode? "ecrecover" o = some recoveredValue := by + have hdec : config.externalABI.decode? "ecrecover" o = some [recoveredValue] := by simpa [recoveredValue] using uniswapEcrecoverDecode_padded (returndata := o) have hzeroSource : recoveredValue = .address (AccountAddress.ofNat 0) := by simpa [recoveredValue] using permitRecoveredPaddedAddress_eq_zero_of_mask_eq_zero hzero @@ -4498,7 +4496,7 @@ theorem uniswapPermitBodyCoreRevert_mismatch_afterNonce_short let evmNonceS := permitAfterNonceState evmS I let recoveredAddr := AccountAddress.ofNat (fromByteArrayBigEndian (o.readWithPadding 0 32)) let recoveredValue : Value := .address recoveredAddr - have hdec : config.externalABI.decode? "ecrecover" o = some recoveredValue := by + have hdec : config.externalABI.decode? "ecrecover" o = some [recoveredValue] := by simpa [recoveredValue, recoveredAddr] using uniswapEcrecoverDecode_padded (returndata := o) have hnzValue : recoveredValue ≠ .address (AccountAddress.ofNat 0) := by simpa [recoveredValue, recoveredAddr] using diff --git a/Examples/UniswapV2Pair/Swap.lean b/Examples/UniswapV2Pair/Swap.lean index d80e9a48..89c5c853 100644 --- a/Examples/UniswapV2Pair/Swap.lean +++ b/Examples/UniswapV2Pair/Swap.lean @@ -951,7 +951,7 @@ theorem uniswapSwapX_lengthHuge {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt simpa [solcLegacyMaxU32] using hlenHuge have rd548 := rd548₀ rw [hgtHuge] at rd548 - have rd549 := RD.lor rd548 (by native_decide) (by evm_ov) + have rd549 := RD.or rd548 (by native_decide) (by evm_ov) have rd550₀ := rd549.iszero (by native_decide) (by evm_ov) have rd550 := rd550₀ rw [isZero_eq_zero_of_ne (swapU256_lor_one_ne_zero_left _)] at rd550 @@ -1187,7 +1187,7 @@ theorem uniswapSwapX_payloadShort {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UI (by decide) (by native_decide) (by evm_ov) have rd547 := rd546.dup4 (by native_decide) (by evm_ov) have rd548 := rd547.gt (by native_decide) (by evm_ov) - have rd549 := RD.lor rd548 (by native_decide) (by evm_ov) + have rd549 := RD.or rd548 (by native_decide) (by evm_ov) have rd550₀ := rd549.iszero (by native_decide) (by evm_ov) have rd550 := rd550₀ rw [isZero_eq_zero_of_ne (swapU256_lor_one_ne_zero_right _)] at rd550 From 6c4ed3837ac2ce0a6f75d09f8da5f3a41a2d5fcb Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 09:31:18 +0300 Subject: [PATCH 29/38] Examples: add uniswapv2 --- Examples/UniswapV2Pair/Spec.lean | 8 ++++++-- Examples/UniswapV2Pair/SpecSyntax.lean | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Examples/UniswapV2Pair/Spec.lean b/Examples/UniswapV2Pair/Spec.lean index ed6a23a8..bfdf9abf 100644 --- a/Examples/UniswapV2Pair/Spec.lean +++ b/Examples/UniswapV2Pair/Spec.lean @@ -259,7 +259,9 @@ def permitStructHashExpr : Expr := def permitDigestExpr : Expr := .keccak256 (.abiEncodePacked [ (bytes2, .fixedBytesLit bytes2Width [0x19, 0x01]), - (bytes32, .storage domainSeparatorRef), + -- The cached pre-increment read: solc loads DOMAIN_SEPARATOR (slot 3) before the nonce + -- SSTORE, so the spec binds it up front rather than re-reading storage here. + (bytes32, .var "domainSeparator"), (bytes32, .var "structHash") ]) /-! ## Internal functions -/ @@ -525,9 +527,11 @@ def permitTransition : TransitionDecl := body := nonpayable ++ [ .require (.binary .ge (.var "deadline") now), + .letDecl "domainSeparator" (some bytes32) (.storage domainSeparatorRef), .letDecl "nonce" (some uint256) (.storage (noncesRef (.var "owner"))), + -- solc 0.5.16 compiles `nonces[owner]++` UNchecked: the store wraps mod 2^256. .assign .storage (noncesRef (.var "owner")) - (u256 (.binary .add (.var "nonce") (.intLit 1))), + (wrapU256 (.binary .add (.var "nonce") (.intLit 1))), .letDecl "structHash" (some bytes32) permitStructHashExpr, .letDecl "digest" (some bytes32) permitDigestExpr, .externalCall (.cast (.intLit 1) addrSt) "ecrecover" (.intLit 0) diff --git a/Examples/UniswapV2Pair/SpecSyntax.lean b/Examples/UniswapV2Pair/SpecSyntax.lean index a01c41f3..a8836702 100644 --- a/Examples/UniswapV2Pair/SpecSyntax.lean +++ b/Examples/UniswapV2Pair/SpecSyntax.lean @@ -363,8 +363,9 @@ def contractSyntax : ContractDecl := solidity% contract UniswapV2Pair { function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external { require(deadline >= block.timestamp); + bytes32 domainSeparator = DOMAIN_SEPARATOR; uint256 nonce = nonces[owner]; - nonces[owner] = (nonce + 1) as uint256; + nonces[owner] = (nonce + 1) % #twoPow256; bytes32 structHash = keccak256(abi.encodePacked( bytes32(bytes32(0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9)), uint256(uint256(owner)), @@ -374,7 +375,7 @@ def contractSyntax : ContractDecl := solidity% contract UniswapV2Pair { uint256(deadline))); bytes32 digest = keccak256(abi.encodePacked( bytes2(bytes2(0x1901)), - bytes32(DOMAIN_SEPARATOR), + bytes32(domainSeparator), bytes32(structHash))); ${[Stmt.externalCall (Expr.cast (.intLit 1) addrSt) "ecrecover" (.intLit 0) [.var "digest", .var "v", .var "r", .var "s"] "recoveredAddress" (perm := false)]} From c9d5255c9e817b38846b3557bf402daac8c13f68 Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 09:49:43 +0300 Subject: [PATCH 30/38] Examples: nits --- Benchmarks/Dss/Flapper/Tend.lean | 2 +- Examples/Ballot/Constructor.lean | 2 +- Examples/Ballot/Delegate.lean | 4 ++-- Examples/Ballot/DelegateTail.lean | 4 ++-- Examples/Ballot/Vote.lean | 2 +- Examples/BlindAuction/AuctionEnd.lean | 2 +- Examples/BlindAuction/Reveal/PlaceBid.lean | 6 +++--- .../OpenZeppelinBench/ERC6909/SetOperator.lean | 2 +- .../Ownable2Step/AcceptOwnership.lean | 2 +- .../Ownable2Step/RenounceOwnership.lean | 2 +- .../Ownable2Step/TransferOwnership.lean | 2 +- Examples/OpenZeppelinBench/Pausable/Pause.lean | 2 +- Examples/SimpleAuction/AuctionEnd.lean | 2 +- Examples/SimpleAuction/Bid.lean | 4 ++-- Examples/UniswapV2Pair/Approve.lean | 6 +++--- Examples/UniswapV2Pair/Common.lean | 6 +++--- Examples/UniswapV2Pair/ExternalWrappers.lean | 6 +++--- Examples/UniswapV2Pair/Factory.lean | 2 +- Examples/UniswapV2Pair/Permit.lean | 18 +++++++----------- Examples/UniswapV2Pair/Routines.lean | 10 +++++----- Examples/UniswapV2Pair/Token0.lean | 2 +- Examples/UniswapV2Pair/Token1.lean | 2 +- Examples/UniswapV2Pair/Transfer.lean | 6 +++--- Examples/UniswapV2Pair/TransferFrom.lean | 4 ++-- Examples/UniswapV2Pair/TransferFromDecode.lean | 2 +- Examples/UniswapV2Pair/TransferFromMasked.lean | 4 ++-- 26 files changed, 51 insertions(+), 55 deletions(-) diff --git a/Benchmarks/Dss/Flapper/Tend.lean b/Benchmarks/Dss/Flapper/Tend.lean index 0ecc6f4b..096c8453 100644 --- a/Benchmarks/Dss/Flapper/Tend.lean +++ b/Benchmarks/Dss/Flapper/Tend.lean @@ -2399,7 +2399,7 @@ theorem flapperTendBodyReturns_success_callerNe [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) (.ok { contract := contract, locals := tendTicLocals (tendRefundRetLocals evm I) evmPay I } (tendPostState evmPay I)) := by - simpa [evmGuy] using.execBlock_append hrefundPrefix hpayTail + simpa [evmGuy] using execBlock_append hrefundPrefix hpayTail refine ExecFuncBody.execBlockOK ?_ simpa [tendTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append, List.append_assoc] using diff --git a/Examples/Ballot/Constructor.lean b/Examples/Ballot/Constructor.lean index 95a937df..553bf4f8 100644 --- a/Examples/Ballot/Constructor.lean +++ b/Examples/Ballot/Constructor.lean @@ -1302,7 +1302,7 @@ theorem ballotConstructorPrelude {cA : Batteries.RBSet AccountAddress compare} { jumpdest, push0, dup1 ]).sload (by ctor_decode) (by evm_ov) have rd65 := ctor_run rd52 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨0xa0⟩, shl, sub, not, and, caller, swap1, dup2 ] - have rd66 := RD.lor rd65 (by ctor_decode) (by evm_ov) + have rd66 := RD.or rd65 (by ctor_decode) (by evm_ov) have rd67 := ctor_run rd66 with [dup3] have hchair : UInt256.lor (ballotSourceWord I) diff --git a/Examples/Ballot/Delegate.lean b/Examples/Ballot/Delegate.lean index 0b368cca..0d0153b6 100644 --- a/Examples/Ballot/Delegate.lean +++ b/Examples/Ballot/Delegate.lean @@ -3214,9 +3214,9 @@ theorem ballotDelegateX_afterSenderPackedStore {cA gh bl σ σ₀ A I} {g : Sat2 have rd1205 := evm_run rd1182 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨168⟩, shl, sub, not, and, push2 ⟨256⟩, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup8, and, mul ] - have rd1207 := RD.lor rd1205 (by decide) (by evm_ov) + have rd1207 := RD.or rd1205 (by decide) (by evm_ov) have rd1208 := evm_run rd1207 with [dup3] - have rd1209 := RD.lor rd1208 (by decide) (by evm_ov) + have rd1209 := RD.or rd1208 (by decide) (by evm_ov) have rd1210 := evm_run rd1209 with [swap1] obtain ⟨_, _, rd1211⟩ := rd1210.sstore hperm (by decide) (by evm_ov) exact ⟨_, _, by diff --git a/Examples/Ballot/DelegateTail.lean b/Examples/Ballot/DelegateTail.lean index e269935f..b084c7b0 100644 --- a/Examples/Ballot/DelegateTail.lean +++ b/Examples/Ballot/DelegateTail.lean @@ -1797,9 +1797,9 @@ theorem ballotDelegateX_tailAfterSenderPackedStoreFrom1134 {cA gh bl σ σ₀ A have rd1205 := evm_run rd1182 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨168⟩, shl, sub, not, and, push2 ⟨256⟩, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup8, and, mul ] - have rd1207 := RD.lor rd1205 (by decide) (by evm_ov) + have rd1207 := RD.or rd1205 (by decide) (by evm_ov) have rd1208 := evm_run rd1207 with [dup3] - have rd1209 := RD.lor rd1208 (by decide) (by evm_ov) + have rd1209 := RD.or rd1208 (by decide) (by evm_ov) have rd1210 := evm_run rd1209 with [swap1] obtain ⟨_, _, rd1211⟩ := rd1210.sstore hperm (by decide) (by evm_ov) exact ⟨_, _, by diff --git a/Examples/Ballot/Vote.lean b/Examples/Ballot/Vote.lean index be95d99a..4f177779 100644 --- a/Examples/Ballot/Vote.lean +++ b/Examples/Ballot/Vote.lean @@ -1220,7 +1220,7 @@ theorem ballotVoteX_afterSenderStores {cA gh bl σ σ₀ A I} {g : Sat256} {sel have rd593 := evm_run rd586 with [jumpdest, push1 ⟨1⟩, dup2, dup2, add, dup1] obtain ⟨_, _, rd594⟩ := rd593.sload (by decide) (by evm_ov) have rd600 := evm_run rd594 with [push1 ⟨255⟩, not, and, swap1, swap2] - have rd601 := RD.lor rd600 (by decide) (by evm_ov) + have rd601 := RD.or rd600 (by decide) (by evm_ov) have rd602 := evm_run rd601 with [swap1] obtain ⟨_, _, rd603⟩ := rd602.sstore hperm (by decide) (by evm_ov) have rd610 := evm_run rd603 with [push1 ⟨2⟩, dup1, dup3, add, dup4, swap1] diff --git a/Examples/BlindAuction/AuctionEnd.lean b/Examples/BlindAuction/AuctionEnd.lean index 26b5a26f..a5c2adc8 100644 --- a/Examples/BlindAuction/AuctionEnd.lean +++ b/Examples/BlindAuction/AuctionEnd.lean @@ -764,7 +764,7 @@ theorem blindAuctionX_auctionEnd_afterStoreAndLog {cA gh bl σ σ₀ A I} {g : S UInt256.land (auctionEndEndedRawWord σ I) (UInt256.lnot ⟨255⟩) := by exact Reasoning.Theory.u256_land_comm (UInt256.lnot ⟨255⟩) (auctionEndEndedRawWord σ I) rw [hland] at rd728 - have rd731₀ := RD.lor rd728 (by decide) (by evm_ov) + have rd731₀ := RD.or rd728 (by decide) (by evm_ov) have rd731 := rd731₀ have hlor : UInt256.lor ⟨1⟩ (UInt256.land (auctionEndEndedRawWord σ I) (UInt256.lnot ⟨255⟩)) = diff --git a/Examples/BlindAuction/Reveal/PlaceBid.lean b/Examples/BlindAuction/Reveal/PlaceBid.lean index fd0a99d2..e7427396 100644 --- a/Examples/BlindAuction/Reveal/PlaceBid.lean +++ b/Examples/BlindAuction/Reveal/PlaceBid.lean @@ -980,7 +980,7 @@ theorem scratch_RD_placeBid_true_zero {g : Sat256} {s0 : State} {I : ExecutionEn have rd1649 := evm_run rd1629 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, and, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup5, and] - have rd1650 := RD.lor rd1649 (by decide) (by evm_ov) + have rd1650 := RD.or rd1649 (by decide) (by evm_ov) have hpack : UInt256.lor (UInt256.land bidder (((⟨1⟩ : UInt256).shiftLeft ⟨160⟩).sub ⟨1⟩)) @@ -1364,7 +1364,7 @@ theorem scratch_RD_placeBid_true_nonzero {g : Sat256} {s0 : State} {I : Executio have rd1649 := evm_run rd1629 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, and, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup5, and] - have rd1650 := RD.lor rd1649 (by decide) (by evm_ov) + have rd1650 := RD.or rd1649 (by decide) (by evm_ov) have hpack : UInt256.lor (UInt256.land bidder (((⟨1⟩ : UInt256).shiftLeft ⟨160⟩).sub ⟨1⟩)) @@ -1586,7 +1586,7 @@ theorem scratch_RD_placeBid_true_nonzero_anyMem {g : Sat256} {s0 : State} {I : E have rd1649 := evm_run rd1629 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, and, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup5, and] - have rd1650 := RD.lor rd1649 (by decide) (by evm_ov) + have rd1650 := RD.or rd1649 (by decide) (by evm_ov) have hpack : UInt256.lor (UInt256.land bidder (((⟨1⟩ : UInt256).shiftLeft ⟨160⟩).sub ⟨1⟩)) diff --git a/Examples/OpenZeppelinBench/ERC6909/SetOperator.lean b/Examples/OpenZeppelinBench/ERC6909/SetOperator.lean index 6c62b48e..69e2e675 100644 --- a/Examples/OpenZeppelinBench/ERC6909/SetOperator.lean +++ b/Examples/OpenZeppelinBench/ERC6909/SetOperator.lean @@ -980,7 +980,7 @@ theorem erc6909SetOperatorX_toPreStore {cA gh bl σ σ₀ A I} {g : Sat256} simpa [setOperatorStoredLoadedStack] using rd1082 have rd1091 := evm_run rd1082' with [ push1 ⟨255⟩, not, and, dup7, iszero, iszero, swap1, dup2 ] - have rd1092 := RD.lor rd1091 (by decide) (by simp) + have rd1092 := RD.or rd1091 (by decide) (by simp) have rd1094 := evm_run rd1092 with [swap1, swap2] have hmask : UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask := by diff --git a/Examples/OpenZeppelinBench/Ownable2Step/AcceptOwnership.lean b/Examples/OpenZeppelinBench/Ownable2Step/AcceptOwnership.lean index a48b25b5..49da96b5 100644 --- a/Examples/OpenZeppelinBench/Ownable2Step/AcceptOwnership.lean +++ b/Examples/OpenZeppelinBench/Ownable2Step/AcceptOwnership.lean @@ -361,7 +361,7 @@ theorem ownable2StepX_acceptOwnership_success {cA gh bl σ σ₀ A I} {g : Sat25 have rd478 := evm_run rd455 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup4, dup2, and, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, dup4, and, dup2] - have rd479₀ := RD.lor rd478 (by decide) (by evm_ov) + have rd479₀ := RD.or rd478 (by decide) (by evm_ov) have rd480₀ := evm_run rd479₀ with [dup5] have hset : UInt256.lor diff --git a/Examples/OpenZeppelinBench/Ownable2Step/RenounceOwnership.lean b/Examples/OpenZeppelinBench/Ownable2Step/RenounceOwnership.lean index b4b6b6ea..3bda2629 100644 --- a/Examples/OpenZeppelinBench/Ownable2Step/RenounceOwnership.lean +++ b/Examples/OpenZeppelinBench/Ownable2Step/RenounceOwnership.lean @@ -340,7 +340,7 @@ theorem ownable2StepX_renounceOwnership_success {cA gh bl σ σ₀ A I} {g : Sat have rd478 := evm_run rd455 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup4, dup2, and, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, dup4, and, dup2] - have rd479₀ := RD.lor rd478 (by decide) (by evm_ov) + have rd479₀ := RD.or rd478 (by decide) (by evm_ov) have rd480₀ := evm_run rd479₀ with [dup5] have hset : UInt256.lor diff --git a/Examples/OpenZeppelinBench/Ownable2Step/TransferOwnership.lean b/Examples/OpenZeppelinBench/Ownable2Step/TransferOwnership.lean index 7298151f..b13574fe 100644 --- a/Examples/OpenZeppelinBench/Ownable2Step/TransferOwnership.lean +++ b/Examples/OpenZeppelinBench/Ownable2Step/TransferOwnership.lean @@ -441,7 +441,7 @@ theorem ownable2StepX_transferOwnership_success {cA gh bl σ σ₀ A I} {g : Sat have rd311₀ := evm_run rd288 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, dup4, and, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, swap1, swap2, and, dup2] - have rd312₀ := RD.lor rd311₀ (by decide) (by evm_ov) + have rd312₀ := RD.or rd311₀ (by decide) (by evm_ov) have hset : UInt256.lor (UInt256.land (transferOwnershipNewOwnerWord I) solcAddrMask) diff --git a/Examples/OpenZeppelinBench/Pausable/Pause.lean b/Examples/OpenZeppelinBench/Pausable/Pause.lean index 690c711f..46e26b67 100644 --- a/Examples/OpenZeppelinBench/Pausable/Pause.lean +++ b/Examples/OpenZeppelinBench/Pausable/Pause.lean @@ -123,7 +123,7 @@ theorem pausableX_pause_success {cA gh bl σ σ₀ A I} {g : Sat256} UInt256.land (pausedRawWord σ I) (UInt256.lnot ⟨255⟩) := by exact Reasoning.Theory.u256_land_comm (UInt256.lnot ⟨255⟩) (pausedRawWord σ I) rw [hland] at rd288 - have rd291₀ := RD.lor rd288 (by decide) (by evm_ov) + have rd291₀ := RD.or rd288 (by decide) (by evm_ov) have rd291 := evm_run rd291₀ with [swap1] have hlor : UInt256.lor ⟨1⟩ (UInt256.land (pausedRawWord σ I) (UInt256.lnot ⟨255⟩)) = pausedSetTrueWord (pausedRawWord σ I) := by diff --git a/Examples/SimpleAuction/AuctionEnd.lean b/Examples/SimpleAuction/AuctionEnd.lean index 70849fe3..58139f31 100644 --- a/Examples/SimpleAuction/AuctionEnd.lean +++ b/Examples/SimpleAuction/AuctionEnd.lean @@ -312,7 +312,7 @@ theorem simpleAuctionX_auctionEnd_afterStoreAndLog {cA gh bl σ σ₀ A I} {g : UInt256.land (auctionEndEndedRawWord σ I) (UInt256.lnot ⟨255⟩) := by exact u256_land_comm (UInt256.lnot ⟨255⟩) (auctionEndEndedRawWord σ I) rw [hland] at rd635 - have rd638₀ := RD.lor rd635 (by decide) (by evm_ov) + have rd638₀ := RD.or rd635 (by decide) (by evm_ov) have rd638 := rd638₀ have hlor : UInt256.lor ⟨1⟩ (UInt256.land (auctionEndEndedRawWord σ I) (UInt256.lnot ⟨255⟩)) = diff --git a/Examples/SimpleAuction/Bid.lean b/Examples/SimpleAuction/Bid.lean index 3a1e30ff..21379ce8 100644 --- a/Examples/SimpleAuction/Bid.lean +++ b/Examples/SimpleAuction/Bid.lean @@ -834,7 +834,7 @@ theorem simpleAuctionX_bid_successNoPending {cA gh bl σ σ₀ A I} {g : Sat256} push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, and, caller, swap1, dup2] have rd486 := rd486₀ rw [hmask] at rd486 - have rd487 := RD.lor rd486 (by decide) (by evm_ov) + have rd487 := RD.or rd486 (by decide) (by evm_ov) have rd489 := evm_run rd487 with [swap1, swap2] obtain ⟨_, _, rd490⟩ := rd489.sstore hperm (by decide) (by evm_ov) have rd495 := evm_run rd490 with [callvalue, push1 ⟨3⟩, dup2, swap1] @@ -899,7 +899,7 @@ theorem simpleAuctionX_bid_successWithPending {cA gh bl σ σ₀ A I} {g : Sat25 push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, and, caller, swap1, dup2] have rd486 := rd486₀ rw [hmask] at rd486 - have rd487 := RD.lor rd486 (by decide) (by evm_ov) + have rd487 := RD.or rd486 (by decide) (by evm_ov) have rd489 := evm_run rd487 with [swap1, swap2] obtain ⟨_, _, rd490⟩ := rd489.sstore hperm (by decide) (by evm_ov) have rd495 := evm_run rd490 with [callvalue, push1 ⟨3⟩, dup2, swap1] diff --git a/Examples/UniswapV2Pair/Approve.lean b/Examples/UniswapV2Pair/Approve.lean index 9ac79e92..3b1a77e3 100644 --- a/Examples/UniswapV2Pair/Approve.lean +++ b/Examples/UniswapV2Pair/Approve.lean @@ -158,10 +158,10 @@ theorem uniswapApproveX_decoded {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt ∃ k C, RD uniswapV2PairBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2894⟩ [approveValueWord I, approveSpenderMaskedWord I, ⟨797⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd775⟩ := RD.uniswapAddressUint256ExternalLenOk + obtain ⟨_, _, rd775⟩ := RD.addressUint256ExternalLenOk (entry := ⟨753⟩) (ret := ⟨797⟩) (routine := ⟨2894⟩) hreach uniswap_address_uint256_external_entry_wf (by jump_dest) hsz68 hsize - obtain ⟨_, _, rd2894⟩ := RD.uniswapAddressUint256ExternalMaskAndJumpMasked + obtain ⟨_, _, rd2894⟩ := RD.addressUint256ExternalMaskAndJumpMasked (entry := ⟨753⟩) (ret := ⟨797⟩) (routine := ⟨2894⟩) (R := [sel]) rd775 uniswap_address_uint256_external_entry_wf (by jump_dest) (by simp only [List.length_singleton]; omega) @@ -180,7 +180,7 @@ theorem uniswapApproveX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UIn (initState cA gh bl σ σ₀ g A I) ⟨753⟩ [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : RDrev uniswapV2PairBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapAddressUint256ExternalShort + exact RD.addressUint256ExternalShort (entry := ⟨753⟩) (ret := ⟨797⟩) (routine := ⟨2894⟩) hreach uniswap_address_uint256_external_entry_wf hsz4 hsize hshort diff --git a/Examples/UniswapV2Pair/Common.lean b/Examples/UniswapV2Pair/Common.lean index 2c2c46bf..994bd489 100644 --- a/Examples/UniswapV2Pair/Common.lean +++ b/Examples/UniswapV2Pair/Common.lean @@ -1698,7 +1698,7 @@ theorem RD.uniswapLockEnterLocked {g : Sat256} {s0 : State} {ee : ExecutionEnv} (by rfl) hov -theorem RD.uniswapAddressSlotGetter {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} +theorem RD.addressSlotGetter {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {pc slot ret : UInt256} {R : List UInt256} {mem : ByteArray} {aw : UInt256} {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} (h : RD UniswapV2Pair.uniswapV2PairBytecode ee g s0 pc (ret :: R) mem aw rdata @@ -1825,7 +1825,7 @@ theorem RD.uniswapReturnUint8_949 {g : Sat256} {s0 : State} {ee : ExecutionEnv} (solcReturnMem_read128 (UInt256.land val ⟨255⟩)) hov -theorem RD.uniswapAddressGetterExternal {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} +theorem RD.addressGetterExternal {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} {entry routine slot : UInt256} (hreach : ∃ k C, RD UniswapV2Pair.uniswapV2PairBytecode I g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) entry [sel] @@ -1942,7 +1942,7 @@ theorem uniswapAddressGetterBodyCore simpa [uniswapAddressReturnWord] using (returnEquiv_of_encode (solcAddressReturnEncoding (addrTy := addr) rfl (uniswapSlotWord slot σ_evm I))) - exact (RD.uniswapAddressGetterExternal (g := Sat256.ofUInt256 g) + exact (RD.addressGetterExternal (g := Sat256.ofUInt256 g) (entry := entry) (routine := routine) (slot := slot) hreach hentry hgetter hroutine (by jump_dest)).reEquivExecutionTransport hcode hdispatch hdecode hbody hval hAccounts henc diff --git a/Examples/UniswapV2Pair/ExternalWrappers.lean b/Examples/UniswapV2Pair/ExternalWrappers.lean index 41988e2f..d9989c2f 100644 --- a/Examples/UniswapV2Pair/ExternalWrappers.lean +++ b/Examples/UniswapV2Pair/ExternalWrappers.lean @@ -274,7 +274,7 @@ theorem RD.uniswapTwoAddressExternalMaskAndJumpMasked {g : Sat256} {s0 : State} hd32 hd33 hd34 hd35 hd36 hd37 hd39 hd40 hd41 hd42 hd45 hroutine hov set_option maxHeartbeats 1000000 in -theorem RD.uniswapAddressUint256ExternalShort {cA gh bl σ σ₀ A I} {g : Sat256} +theorem RD.addressUint256ExternalShort {cA gh bl σ σ₀ A I} {g : Sat256} {sel entry ret routine : UInt256} (hreach : ∃ k C, RD UniswapV2Pair.uniswapV2PairBytecode I g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) entry [sel] @@ -299,7 +299,7 @@ theorem RD.uniswapAddressUint256ExternalShort {cA gh bl σ σ₀ A I} {g : Sat25 hd11 hd12 hd13 hd14 hd17 hd18 hd20 hd21 hlt set_option maxHeartbeats 1000000 in -theorem RD.uniswapAddressAddressUint256ExternalShort {cA gh bl σ σ₀ A I} {g : Sat256} +theorem RD.addressAddressUint256ExternalShort {cA gh bl σ σ₀ A I} {g : Sat256} {sel entry ret routine : UInt256} (hreach : ∃ k C, RD UniswapV2Pair.uniswapV2PairBytecode I g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) entry [sel] @@ -325,7 +325,7 @@ theorem RD.uniswapAddressAddressUint256ExternalShort {cA gh bl σ σ₀ A I} {g hd11 hd12 hd13 hd14 hd17 hd18 hd20 hd21 hlt set_option maxHeartbeats 1000000 in -theorem RD.uniswapAddressAddressUint256ExternalMaskAndJumpMasked {g : Sat256} {s0 : State} +theorem RD.addressAddressUint256ExternalMaskAndJumpMasked {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {entry ret routine de : UInt256} {R : List UInt256} {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} (h : RD UniswapV2Pair.uniswapV2PairBytecode ee g s0 diff --git a/Examples/UniswapV2Pair/Factory.lean b/Examples/UniswapV2Pair/Factory.lean index ac744194..cdd880cf 100644 --- a/Examples/UniswapV2Pair/Factory.lean +++ b/Examples/UniswapV2Pair/Factory.lean @@ -38,7 +38,7 @@ theorem uniswapX_factory {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : RDret uniswapV2PairBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) (UInt256.toByteArray (factoryReturnWord σ I)) := by - exact RD.uniswapAddressGetterExternal (entry := ⟨1324⟩) (routine := ⟨5443⟩) + exact RD.addressGetterExternal (entry := ⟨1324⟩) (routine := ⟨5443⟩) (slot := ⟨5⟩) hreach uniswap_address_getter_entry_wf uniswap_address_slot_getter_wf (by jump_dest) (by jump_dest) diff --git a/Examples/UniswapV2Pair/Permit.lean b/Examples/UniswapV2Pair/Permit.lean index ae03ac64..c5266fc8 100644 --- a/Examples/UniswapV2Pair/Permit.lean +++ b/Examples/UniswapV2Pair/Permit.lean @@ -1,3 +1,4 @@ +import Examples.UniswapV2Pair.EcrecoverTheta import Examples.UniswapV2Pair.MutatorDispatch import Examples.UniswapV2Pair.PermitDecode import Examples.UniswapV2Pair.PermitRuntime @@ -882,18 +883,13 @@ theorem uniswapEcrecoverDecode_ok {returndata : ByteArray} change uniswapExternalABI.decode? "ecrecover" returndata = _ simp [uniswapExternalABI, permitDecodeReturnValue_legacyAddress_ok hlo] --- BLOCKED: false for `returndata.size < 32` — the legacy decoder returns `none` there --- (`permitDecodeReturnValue_legacyAddress_none_short`), so the source statement decode-reverts --- while the bytecode uses the zero-padded word. Its three call sites (`…_afterNonce_short`, --- `…_zero_afterNonce_short`, `…_mismatch_afterNonce_short`) are reached from --- `uniswapPermitBody_depthOk` under `hshort : o.size < 32` with `o` an arbitrary Θ output, --- so no `32 ≤ o.size` fact is available. Needs an architecture decision (see report). -theorem uniswapEcrecoverDecode_padded (returndata : ByteArray) : - config.externalABI.decode? "ecrecover" returndata = - some [.address (AccountAddress.ofNat - (fromByteArrayBigEndian (returndata.readWithPadding 0 32)))] := by +-- Short returndata fails the legacy `address` decode. Only `o.size = 0` is reachable here: +-- the ecrecover precompile returns 0 or 32 bytes (`staticcallTheta_ecrecover_output_size`). +theorem uniswapEcrecoverDecode_none_short {returndata : ByteArray} + (hshort : returndata.size < 32) : + config.externalABI.decode? "ecrecover" returndata = none := by change uniswapExternalABI.decode? "ecrecover" returndata = _ - simp [uniswapExternalABI] + simp [uniswapExternalABI, permitDecodeReturnValue_legacyAddress_none_short hshort] theorem permitDecodeABIValues_ok {I : ExecutionEnv} (hsz228 : 228 ≤ I.calldata.size) : decodeABIValues? [legacyAddr, legacyAddr, uint256, uint256, uint8, bytes32, bytes32] diff --git a/Examples/UniswapV2Pair/Routines.lean b/Examples/UniswapV2Pair/Routines.lean index 947ebb10..caaf131f 100644 --- a/Examples/UniswapV2Pair/Routines.lean +++ b/Examples/UniswapV2Pair/Routines.lean @@ -239,7 +239,7 @@ macro "uniswap_address_uint256_external_entry_wf" : term => repeat' first | apply And.intro | native_decide) set_option maxHeartbeats 1000000 in -theorem RD.uniswapAddressUint256ExternalLenOk {cA gh bl σ σ₀ A I} {g : Sat256} +theorem RD.addressUint256ExternalLenOk {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} {entry ret routine : UInt256} (hreach : ∃ k C, RD UniswapV2Pair.uniswapV2PairBytecode I g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) entry [sel] @@ -261,7 +261,7 @@ theorem RD.uniswapAddressUint256ExternalLenOk {cA gh bl σ σ₀ A I} {g : Sat25 hd13 hd14 hd17 hdecoded hsz68 hsize set_option maxHeartbeats 1000000 in -theorem RD.uniswapAddressUint256ExternalMaskAndJump {g : Sat256} {s0 : State} +theorem RD.addressUint256ExternalMaskAndJump {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {entry ret routine de : UInt256} {R : List UInt256} {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} (h : RD UniswapV2Pair.uniswapV2PairBytecode ee g s0 @@ -282,7 +282,7 @@ theorem RD.uniswapAddressUint256ExternalMaskAndJump {g : Sat256} {s0 : State} hd31 hd32 hd33 hd34 hd35 hd36 hd38 hd39 hd40 hd43 hcanon hroutine hov set_option maxHeartbeats 1000000 in -theorem RD.uniswapAddressUint256ExternalMaskAndJumpMasked {g : Sat256} {s0 : State} +theorem RD.addressUint256ExternalMaskAndJumpMasked {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {entry ret routine de : UInt256} {R : List UInt256} {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} (h : RD UniswapV2Pair.uniswapV2PairBytecode ee g s0 @@ -414,7 +414,7 @@ macro "uniswap_address_address_uint256_external_entry_wf" : term => repeat' first | apply And.intro | native_decide) set_option maxHeartbeats 1000000 in -theorem RD.uniswapAddressAddressUint256ExternalLenOk {cA gh bl σ σ₀ A I} {g : Sat256} +theorem RD.addressAddressUint256ExternalLenOk {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} {entry ret routine : UInt256} (hreach : ∃ k C, RD UniswapV2Pair.uniswapV2PairBytecode I g (Reasoning.Theory.initState cA gh bl σ σ₀ g A I) entry [sel] @@ -440,7 +440,7 @@ theorem RD.uniswapAddressAddressUint256ExternalLenOk {cA gh bl σ σ₀ A I} {g hd13 hd14 hd17 hdecoded hlt set_option maxHeartbeats 1000000 in -theorem RD.uniswapAddressAddressUint256ExternalMaskAndJump {g : Sat256} {s0 : State} +theorem RD.addressAddressUint256ExternalMaskAndJump {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ} {entry ret routine de : UInt256} {R : List UInt256} {rdata : ByteArray} {cA : Batteries.RBSet AccountAddress compare} {σ : AccountMap} (h : RD UniswapV2Pair.uniswapV2PairBytecode ee g s0 diff --git a/Examples/UniswapV2Pair/Token0.lean b/Examples/UniswapV2Pair/Token0.lean index 8a8c42bd..c3c36d43 100644 --- a/Examples/UniswapV2Pair/Token0.lean +++ b/Examples/UniswapV2Pair/Token0.lean @@ -38,7 +38,7 @@ theorem uniswapX_token0 {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : RDret uniswapV2PairBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) (UInt256.toByteArray (token0ReturnWord σ I)) := by - exact RD.uniswapAddressGetterExternal (entry := ⟨817⟩) (routine := ⟨2917⟩) + exact RD.addressGetterExternal (entry := ⟨817⟩) (routine := ⟨2917⟩) (slot := ⟨6⟩) hreach uniswap_address_getter_entry_wf uniswap_address_slot_getter_wf (by jump_dest) (by jump_dest) diff --git a/Examples/UniswapV2Pair/Token1.lean b/Examples/UniswapV2Pair/Token1.lean index 0ae29353..b89660c0 100644 --- a/Examples/UniswapV2Pair/Token1.lean +++ b/Examples/UniswapV2Pair/Token1.lean @@ -38,7 +38,7 @@ theorem uniswapX_token1 {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UInt256} solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : RDret uniswapV2PairBytecode g (initState cA gh bl σ σ₀ g A I) (cA, σ) (UInt256.toByteArray (token1ReturnWord σ I)) := by - exact RD.uniswapAddressGetterExternal (entry := ⟨1332⟩) (routine := ⟨5458⟩) + exact RD.addressGetterExternal (entry := ⟨1332⟩) (routine := ⟨5458⟩) (slot := ⟨7⟩) hreach uniswap_address_getter_entry_wf uniswap_address_slot_getter_wf (by jump_dest) (by jump_dest) diff --git a/Examples/UniswapV2Pair/Transfer.lean b/Examples/UniswapV2Pair/Transfer.lean index a83e4df8..1b33b8bf 100644 --- a/Examples/UniswapV2Pair/Transfer.lean +++ b/Examples/UniswapV2Pair/Transfer.lean @@ -414,10 +414,10 @@ theorem uniswapTransferX_decoded {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UIn ∃ k C, RD uniswapV2PairBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨5061⟩ [transferValueWord I, transferToMaskedWord I, ⟨797⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd1256⟩ := RD.uniswapAddressUint256ExternalLenOk + obtain ⟨_, _, rd1256⟩ := RD.addressUint256ExternalLenOk (entry := ⟨1234⟩) (ret := ⟨797⟩) (routine := ⟨5061⟩) hreach uniswap_address_uint256_external_entry_wf (by jump_dest) hsz68 hsize - obtain ⟨_, _, rd5061⟩ := RD.uniswapAddressUint256ExternalMaskAndJumpMasked + obtain ⟨_, _, rd5061⟩ := RD.addressUint256ExternalMaskAndJumpMasked (entry := ⟨1234⟩) (ret := ⟨797⟩) (routine := ⟨5061⟩) (R := [sel]) rd1256 uniswap_address_uint256_external_entry_wf (by jump_dest) (by simp only [List.length_singleton]; omega) @@ -435,7 +435,7 @@ theorem uniswapTransferX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} {sel : UI (initState cA gh bl σ σ₀ g A I) ⟨1234⟩ [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : RDrev uniswapV2PairBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapAddressUint256ExternalShort + exact RD.addressUint256ExternalShort (entry := ⟨1234⟩) (ret := ⟨797⟩) (routine := ⟨5061⟩) hreach uniswap_address_uint256_external_entry_wf hsz4 hsize hshort diff --git a/Examples/UniswapV2Pair/TransferFrom.lean b/Examples/UniswapV2Pair/TransferFrom.lean index 7fa074ff..cdd6eb4a 100644 --- a/Examples/UniswapV2Pair/TransferFrom.lean +++ b/Examples/UniswapV2Pair/TransferFrom.lean @@ -154,10 +154,10 @@ theorem uniswapTransferFromX_decoded {cA gh bl σ σ₀ A I} {g : Sat256} {sel : ∃ k C, RD uniswapV2PairBytecode I g (initState cA gh bl σ σ₀ g A I) ⟨2938⟩ [transferFromValueWord I, transferFromToWord I, transferFromFromWord I, ⟨797⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd901⟩ := RD.uniswapAddressAddressUint256ExternalLenOk + obtain ⟨_, _, rd901⟩ := RD.addressAddressUint256ExternalLenOk (entry := ⟨879⟩) (ret := ⟨797⟩) (routine := ⟨2938⟩) hreach uniswap_address_address_uint256_external_entry_wf (by jump_dest) hsz100 hsize - obtain ⟨_, _, rd2938⟩ := RD.uniswapAddressAddressUint256ExternalMaskAndJump + obtain ⟨_, _, rd2938⟩ := RD.addressAddressUint256ExternalMaskAndJump (entry := ⟨879⟩) (ret := ⟨797⟩) (routine := ⟨2938⟩) (R := [sel]) rd901 uniswap_address_address_uint256_external_entry_wf (by simpa [transferFromFromWord] using hcanonFrom) diff --git a/Examples/UniswapV2Pair/TransferFromDecode.lean b/Examples/UniswapV2Pair/TransferFromDecode.lean index 056dcc68..4b1a2239 100644 --- a/Examples/UniswapV2Pair/TransferFromDecode.lean +++ b/Examples/UniswapV2Pair/TransferFromDecode.lean @@ -20,7 +20,7 @@ theorem uniswapTransferFromX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} {sel (initState cA gh bl σ σ₀ g A I) ⟨879⟩ [sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C) : RDrev uniswapV2PairBytecode g (initState cA gh bl σ σ₀ g A I) := by - exact RD.uniswapAddressAddressUint256ExternalShort + exact RD.addressAddressUint256ExternalShort (entry := ⟨879⟩) (ret := ⟨797⟩) (routine := ⟨2938⟩) hreach uniswap_address_address_uint256_external_entry_wf hsz4 hsize hshort diff --git a/Examples/UniswapV2Pair/TransferFromMasked.lean b/Examples/UniswapV2Pair/TransferFromMasked.lean index 50825064..9241f341 100644 --- a/Examples/UniswapV2Pair/TransferFromMasked.lean +++ b/Examples/UniswapV2Pair/TransferFromMasked.lean @@ -72,10 +72,10 @@ theorem uniswapTransferFromX_decoded_masked {cA gh bl σ σ₀ A I} {g : Sat256} [transferFromValueWord I, transferFromToMaskedWord I, transferFromFromMaskedWord I, ⟨797⟩, sel] solcFreePtrMem (UInt256.ofNat 3) ByteArray.empty (cA, σ) k C := by - obtain ⟨_, _, rd901⟩ := RD.uniswapAddressAddressUint256ExternalLenOk + obtain ⟨_, _, rd901⟩ := RD.addressAddressUint256ExternalLenOk (entry := ⟨879⟩) (ret := ⟨797⟩) (routine := ⟨2938⟩) hreach uniswap_address_address_uint256_external_entry_wf (by jump_dest) hsz100 hsize - obtain ⟨_, _, rd2938⟩ := RD.uniswapAddressAddressUint256ExternalMaskAndJumpMasked + obtain ⟨_, _, rd2938⟩ := RD.addressAddressUint256ExternalMaskAndJumpMasked (entry := ⟨879⟩) (ret := ⟨797⟩) (routine := ⟨2938⟩) (R := [sel]) rd901 uniswap_address_address_uint256_external_entry_wf (by jump_dest) (by simp only [List.length_singleton]; omega) From 1c4708d3a26a2f09ee9ac53218e2a7d7b18b58c9 Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 09:53:26 +0300 Subject: [PATCH 31/38] Remove TODO --- TODO.md | 198 -------------------------------------------------------- 1 file changed, 198 deletions(-) delete mode 100644 TODO.md diff --git a/TODO.md b/TODO.md deleted file mode 100644 index 64083d58..00000000 --- a/TODO.md +++ /dev/null @@ -1,198 +0,0 @@ -# Release TODOs - -- [X] EquiVM/EVM -- [X] Solm -- [X] ABI -- [X] Reasoning -- [ ] Examples - + [X] Concrete syntax - + [X]Verify structure -- [ ] Benchmarks - + [X] Concrete syntax - + [X] Verify structure -- [X] Proofs -- [X] Misc - + [X] Proof template -- [ ] Docs - + [ ] README - * [ ] External call section - * [ ] Top-level theorem section - + [ ] GUIDE -- [ ] CI/CD - - - -# Solm Semantics -- [X] Constructor calls - + currently we don't have -- [X] Arithmetic overflow handling - + Option 1: wrap-around arithmetic and explicit overflow checks in the spec - + Option 2: parameterize with the checked arith semantics of the language - + [CURRENT] Option 3: unbounded arith, explicit inRange checks, and truncation to bounded arith when storing to storage -- [X] Add low level call in Solm -- [ ] Study locals (esp. arrays, mappings and structs) and how to model them in Solm -- [ ] Dynamic data (arrays and strings) - -- [ ] Out of gas - + currently we treat OOG as equivalent to any spec - + nonterminting EVM programs are currently equivalent to any spec [OK] - -- When writing spec, the reads/writes of mappings (and likely arrays too) should happen in the - order they appear in the bytecode. Otherwise, we may need ta add keccak axioms. - -- Optimizations on vs off - -- Maybe Solidity example with inline assembly - -- StorageRef - + probably rename with something else, since it is used for locals too. - -- We need to remove the huge eqDec definitions somewhere else so our syntax/semantics files remain readable. - -- What we do not have (and may be fine for now) - + - + no delete for memory arrays - - -- Discuss legacy Solidity issues that came up. - -- Solidity out-of-scope - + Checked arithmetic (we have unbounded arithmetic with explicit inRange checks) - + Events - + Multiple returns - + Inheritance and interfaces - + Memory references - + Transient storage - + Revert reasons - + memory references - + fixed-point decimals - + function pointers - + Solm's parameter types carry no memory/calldata marker - -- Still TODOs - + string/bytes handling - + delete for memory arrays - + StorageRef is not a good name as it is used for locals too. - - -- When a contract inherits other contracts, that we have already proved correct, - can we reuse the proofs? - - - - - -- gasleft()/tx.gasprice - -- INVALID - -- flat multi-value return encoding → returnType : List ABIType - -- Dynamic tuple return: - -The ABI rule. A function's return data is encoded as if the output list were the argument list of a top-level tuple: encode((T1, T2, …, Tn)). Heads for all outputs come first (static values inline, dynamic values as offset words), tails after. The crucial point: there is no extra nesting level around the outputs. function f() returns (int56[] memory, uint160[] memory) produces: - - -head: offset₁ (0x40) offset₂ -tail: len₁, data₁..., len₂, data₂... -What the model does. returnType : Option ABIType forces N outputs to be represented as one value of type .tuple [T1, …, Tn]. Encoding goes through encodeReturnValue? ty v = encodeABIValues? [ty] [v] (Encode.lean:163-164) — i.e. a top-level tuple with one member, which is itself your tuple. encodeABIValuesFrom? then asks isDynamicABIType (.tuple …): if any member is dynamic, the whole tuple is dynamic, so it emits a leading offset word 0x20 and shifts every inner offset by 32 (Encode.lean:145-152). Result: one spurious 32-byte prefix and wrong inner offsets versus what solc returns. returnEquiv.returned compares byte-for-byte → unsatisfiable for every successful call. - -Why nobody noticed until now. Two coincidences hid it: - -A single return value is genuinely a 1-tuple at top level, so encodeABIValues? [ty] [v] is exactly right — including single dynamic values (WETH9's name() string, getOwners()'s address[], which do get a leading 0x20 on-chain too). Those all check out. -A static tuple's members encode inline in the head with no offset word, so "wrapped as one tuple" and "flat outputs" produce identical bytes. All multi-returns in Examples/ and most in these benchmarks (slot0(), positions(), ticks(), burn, swap, mint) are all-static — fine as-is. -It breaks exactly when N > 1 outputs AND at least one is dynamic: Safe's getModulesPaginated → (address[], address) (Spec.lean:226) and Uniswap's observe → (int56[], uint160[]) (Spec.lean:356). - -Why you can't just "unwrap" .tuple in the encoder. A Solidity function can also return a struct, whose ABI output list is [tuple(...)] — one output that legitimately gets the offset word. If the model treated every top-level .tuple returnType as "multiple outputs, encode flat", struct returns would become inexpressible. Option ABIType simply can't distinguish "N outputs" from "1 tuple-typed output". (No current benchmark returns a dynamic struct, so a pragmatic unwrap would work today, but it bakes in the ambiguity.) - -The clean fix. Make the return type a list: returnType : List ABIType (empty = void), encode with encodeABIValues? types values directly (the function already exists — encodeReturnValues? at Encode.lean:158-160 is sitting there unused for this), and have returnEquiv unpack a Value.tuple into the member values for N > 1. A struct return is then the singleton list [.tuple …], which correctly keeps its offset word. Ripple effects are contained but real: returnEquiv/returnDataEquiv in Equiv.lean, defaultAbiValue (the fallthrough-zero-return case), transitionSignature is unaffected (it's over params), the Stmt.return eval rules unchanged (specs already build Value.tuple via tupleLit), plus mechanical returnType edits in every existing spec and the corresponding proof scripts. - -Also worth knowing: the same wrapped-vs-flat question exists on the decode side for abiDecode/checkedCall returns of multiple values — currently abiDecode : ABIType → … has the same single-type shape, so if a spec ever decodes a two-output external call's returndata as .tuple, it inherits the same mismatch. Same fix applies there if/when needed. - -Severity check: this is not load-bearing for the hard parts of the benchmarks — both affected functions are view functions — but as long as they're in the ABI surface, the whole-contract theorem demands them, so it's a genuine blocker for the top-level statement. - -- Immutables - -Parameterized statement (the principled one). Add a trusted patchRuntime : ByteArray → List (Nat × EVM.Word) → ByteArray and the offset table — solc emits exactly this as immutableReferences in its standard-JSON output, so the table is a compiler artifact, not something you reverse-engineer. Then: - -Runtime: ∀ vals, runtimeEquivalence cfg (patchRuntime template (offsets vals)) (poolSpec vals) — one proof, universally quantified over instantiations. The proof works exactly like today's, except symbolic PUSH32 operands where the template had zeros. -Constructor: generalize ctorResultEquiv's o = runtimeCode to o = patchRuntime template (offsets (valsOf env solmState)), where the expected values are derived from the same things the spec constructor computed (the parameters() return, env .this). This is a change to the equivalence-statement layer only — Solm syntax and semantics don't move. - - - -- The wordToElem sign-extension bug - -This one isn't a missing feature — it's a bug in the trusted storage-load semantics, the same class as the storageLocStore endianness bug you found via the Caller proof. - -What solc does. A packed signed field (say int24 slot0.tick at byte offset 20 of slot 0) is stored as its low N bytes in two's complement. On load, solc shifts/masks the field out and applies SIGNEXTEND at the field's width, so stored bytes 0xFFFFFF come back as −1. - -What the model does. storageLocLoad (Storage.lean:69-90) extracts exactly the field's loc.size bytes from the slot and rebuilds a word from them — so the word's upper bytes are always zero. Then wordToElem dispatches on the declared type, and for signed ints does: - - -| .int (.sint _) => .int (EVM.signed w) -(Value.lean:229) — note the _: the declared bit width is ignored, and EVM.signed (EVM/Types.lean:66-71) tests the 256-bit sign bit. Since the extracted word is < 2^(8·size), that sign bit is never set for any packed field narrower than a full slot. So every negative packed signed value loads as a large positive: int24 −1 → +16777215, int128 −1 → +2¹²⁸−1. - -Why it's asymmetric (and therefore doesn't round-trip). The store direction is correct: wordOfInt reduces mod 2²⁵⁶ giving full-width two's complement, and the packer keeps the low size bytes — 0xFFFFFF for int24 −1, matching solc. So spec-store then spec-load of −1 yields +16777215. The bug is confined to the load. - -Boundary cases that still work, so you know the blast radius precisely: - -Full-slot int256: the extracted word is the whole slot, width = 256, EVM.signed is exactly right. -All unsigned fields, addresses, bools, bytesN: unaffected. -Non-negative signed values: unaffected (both interpretations agree). -How it manifests in the benchmark. UniswapV3 reads packed signed fields on essentially every path: slot0.tick (int24), ticks[t].liquidityNet (int128), tickCumulativeOutside/observations[i].tickCumulative (int56). Two failure shapes: - -In arithmetic/comparisons: the bytecode SIGNEXTENDs and does SLT; the spec computes with the bogus positive — results diverge, equivalence unprovable on any state with a negative tick (half the tick range). -Even the plain slot0()/ticks() getters fail loudly: encodeABIWord? range-checks signed values (Encode.lean:44-52), and +16777215 is outside int24's [−2²³, 2²³), so encoding returns none and returnEquiv has no witness at all. -One consolation: because the layout code is trusted, this can never prove a false equivalence — it makes true equivalences unprovable. But it would silently poison Proofs/-style theorems about specs (you'd be proving invariants of the wrong load semantics), which is the more insidious direction. - -The fix. The width is already sitting in the ignored pattern: .int (.sint bits). Sign-extend at the declared width inside wordToElem: - -| .int (.sint bits) => - let m := w.toNat % 2 ^ bits.width -- however IntType exposes it - .int (if m < 2 ^ (bits.width - 1) then (m : Int) else (m : Int) - 2 ^ bits.width) - - -- Integer bitwise ops - -Add int cases to evalBinaryOp? (small model change, my recommendation). For .int x, .int y with 0 ≤ x, y < 2²⁵⁶: Nat.land/lor/xor on the Nats, and x <<< k as x * 2^k % 2^256, >>> as division; out-of-range or negative operands → .error .typeError (specs on signed values must go through an explicit two's-complement re-encode first, which keeps the semantics honest rather than guessing a signed-bitwise convention). This keeps specs looking like the source. On the proof side it's actually cheaper than route 1: the spec op and the EVM op are now the same function of the same word, so the per-site lemma disappears. - -Do the bytesN → int cast regardless of the route — Safe needs it for uint256(r) in signature splitting, and it's a one-arm addition (fixedBytesToNat? already exists). - - -- The bytes/string header-validation mismatch - -So the fix, stated in the terms you've been pushing me toward: - -WETH9's own Spec.lean defines its own readValue?/writeValue?/clearValue? functions — hand-written, like the rest of its layout — implementing the 0.5.16 behavior I verified from the disassembly: - -len := if header even then (header &&& 0xFF) / 2 else header / 2 — total, never reverts; -short/long form chosen by len < 32; -read = first len bytes of the slot word (short) or of the keccak(slot) data words (long); -write = header word + data words, clearing ⌈oldLen/32⌉ words computed with the same total decode. -That's it. No change to Solm/, no change to SolidityLayout.lean, no mode knob, no precondition — one contract's layout record carries its own compiler-faithful string semantics, which is exactly what the per-contract layout design is for. The trusted surface is those ~30 lines in WETH9's spec, reviewed against the disassembly (the read side I've verified; the write/clear side still deserves the creation.hex check I flagged). - -Marking this one resolved: "WETH9 strings: hand-written per-contract layout hooks with total 0.5.16 header semantics." - - -- EXTCODECOPY — Safe's EIP-7702 probe - - -The fix — one Expr, exactly the extCodeSize pattern: - - -| extCodePrefix : Expr /- address -/ -> Nat /- n bytes -/ -> Expr -with the eval rule reading the same source the opcode reads: - - -| .extCodePrefix e n => do - match <- evalExpr? cfg solm evm e with - | .address a => - let code := (evm.accountMap.find? a).elim ByteArray.empty (·.code) - pure (.bytes (padRightZeros (code.extract 0 n) n)) -- EXTCODECOPY zero-pads past the end - | _ => .error .typeError -The zero-padding is the one semantic detail to get right: EXTCODECOPY pads reads beyond the code size with zero bytes, so an empty/short-code account yields 0x000000, which correctly fails the 0xef0100 comparison. The spec then writes the guard as a comparison against a 3-byte bytesLit. (A more general extCodeSlice addr offset n costs the same to add; offset 0 is all Safe needs.) - -Total cost: the Expr constructor + eval case + DecidableEq arm + exprEvalSize case, and — when the Safe proof actually reaches this branch — one opcode-bridge lemma in the Reasoning framework connecting it to EXTCODECOPY, the same shape extCodeSize/EXTCODESIZE already has. No relation change, no config change. - -One honest caveat: I've verified the Solidity source and the Solm side; I have not disassembled Safe's runtime.hex to confirm how the optimizer compiled this sequence (e.g. whether the shr(232, …)/eq survives as-is). That check belongs to whoever writes the Safe spec's guard expression, so the spec-side comparison matches the compiled predicate exactly — on the model side, extCodePrefix + eq against a fixedBytesLit/bytesLit is sufficient either way. - From 183eb2c8ba0a968c3c9516f2b285438a597dfdb4 Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 10:01:34 +0300 Subject: [PATCH 32/38] Examples: uniswap --- Examples/UniswapV2Pair/Permit.lean | 15 +++++++-------- Examples/UniswapV2Pair/Spec.lean | 9 ++++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Examples/UniswapV2Pair/Permit.lean b/Examples/UniswapV2Pair/Permit.lean index c5266fc8..e5dda7ac 100644 --- a/Examples/UniswapV2Pair/Permit.lean +++ b/Examples/UniswapV2Pair/Permit.lean @@ -1,4 +1,3 @@ -import Examples.UniswapV2Pair.EcrecoverTheta import Examples.UniswapV2Pair.MutatorDispatch import Examples.UniswapV2Pair.PermitDecode import Examples.UniswapV2Pair.PermitRuntime @@ -881,15 +880,15 @@ theorem uniswapEcrecoverDecode_ok {returndata : ByteArray} some [.address (AccountAddress.ofNat (fromByteArrayBigEndian (returndata.extract 0 32)))] := by change uniswapExternalABI.decode? "ecrecover" returndata = _ - simp [uniswapExternalABI, permitDecodeReturnValue_legacyAddress_ok hlo] + simp [uniswapExternalABI, decodeEcrecoverOutput?] + rw [readWithPadding_eq_extract returndata 0 hlo] --- Short returndata fails the legacy `address` decode. Only `o.size = 0` is reachable here: --- the ecrecover precompile returns 0 or 32 bytes (`staticcallTheta_ecrecover_output_size`). -theorem uniswapEcrecoverDecode_none_short {returndata : ByteArray} - (hshort : returndata.size < 32) : - config.externalABI.decode? "ecrecover" returndata = none := by +theorem uniswapEcrecoverDecode_padded (returndata : ByteArray) : + config.externalABI.decode? "ecrecover" returndata = + some [.address (AccountAddress.ofNat + (fromByteArrayBigEndian (returndata.readWithPadding 0 32)))] := by change uniswapExternalABI.decode? "ecrecover" returndata = _ - simp [uniswapExternalABI, permitDecodeReturnValue_legacyAddress_none_short hshort] + simp [uniswapExternalABI, decodeEcrecoverOutput?] theorem permitDecodeABIValues_ok {I : ExecutionEnv} (hsz228 : 228 ≤ I.calldata.size) : decodeABIValues? [legacyAddr, legacyAddr, uint256, uint256, uint8, bytes32, bytes32] diff --git a/Examples/UniswapV2Pair/Spec.lean b/Examples/UniswapV2Pair/Spec.lean index bfdf9abf..f4985c21 100644 --- a/Examples/UniswapV2Pair/Spec.lean +++ b/Examples/UniswapV2Pair/Spec.lean @@ -768,6 +768,13 @@ def decodeOptionalBoolOrEmpty? (out : EVM.Bytes) : Option (List Value) := | some (.bool true) => some [] | _ => none +-- `ecrecover` returndata decode. The bytecode performs an unconditional zero-padded 32-byte +-- read of the staticcall output (empty returndata from the precompile ⇒ zero word), so the +-- model decode is total. +open Ethereum Ethereum.EVM in +def decodeEcrecoverOutput? (out : EVM.Bytes) : Option (List Value) := + some [.address (AccountAddress.ofNat (fromByteArrayBigEndian (out.readWithPadding 0 32)))] + def encodeEcrecoverInput? (args : List Value) : Option EVM.Bytes := do let payload <- ABI.encodeABIValues? [bytes32, uint8, bytes32, bytes32] args some payload.toByteArray @@ -798,7 +805,7 @@ def uniswapExternalABI : ExternalCallABI where else if name = "uniswapV2Call" then some [] else if name = "ecrecover" then - (ABI.decodeReturnValueWithMode? DecodeMode.legacySolc05 addr out).map (fun v => [v]) + decodeEcrecoverOutput? out else none From 863ac98fdab3f7b2ad776546ae1e56a1d0c1b9f1 Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 10:06:29 +0300 Subject: [PATCH 33/38] Examples: wip --- Benchmarks/Dss/Cat/ConstructorTraceVat.lean | 2 +- Benchmarks/Dss/Cure/Drop.lean | 2 +- Benchmarks/Dss/Cure/Lift.lean | 2 +- .../Dss/DaiJoin/ConstructorTraceStores.lean | 4 ++-- Benchmarks/Dss/Dog/FileAddress.lean | 2 +- Benchmarks/Dss/Dog/FileIlkClip.lean | 2 +- Benchmarks/Dss/End/FileAddressTail.lean | 4 ++-- .../Dss/Flapper/ConstructorTraceDefaults.lean | 4 ++-- .../Dss/Flapper/ConstructorTraceStores.lean | 4 ++-- Benchmarks/Dss/Flapper/Kick.lean | 4 ++-- Benchmarks/Dss/Flapper/Tend.lean | 4 ++-- Benchmarks/Dss/Flapper/Tick.lean | 2 +- Benchmarks/Dss/Flipper/Constructor.lean | 12 +++++----- Benchmarks/Dss/Flipper/DentRefundEVM.lean | 2 +- Benchmarks/Dss/Flipper/DentTail.lean | 2 +- Benchmarks/Dss/Flipper/FileUint.lean | 2 +- Benchmarks/Dss/Flipper/Kick.lean | 2 +- Benchmarks/Dss/Flipper/KickTail.lean | 6 ++--- Benchmarks/Dss/Flipper/TendRefund.lean | 2 +- Benchmarks/Dss/Flipper/TendTail.lean | 2 +- Benchmarks/Dss/Flipper/Tick.lean | 2 +- .../Dss/Flopper/ConstructorTraceDefaults.lean | 4 ++-- .../Dss/Flopper/ConstructorTraceStores.lean | 4 ++-- Benchmarks/Dss/Flopper/Dent/Part5.lean | 2 +- Benchmarks/Dss/Flopper/Dent/Part6.lean | 4 ++-- Benchmarks/Dss/Flopper/Dent/Part7.lean | 2 +- Benchmarks/Dss/Flopper/Kick/Part1.lean | 2 +- Benchmarks/Dss/Flopper/Kick/Part2.lean | 2 +- Benchmarks/Dss/Flopper/Tick/Part2.lean | 2 +- .../Dss/GemJoin/ConstructorTraceStores.lean | 4 ++-- .../Dss/Jug/ConstructorTraceVatMask.lean | 2 +- Benchmarks/Dss/Pot/ConstructorTraceVat.lean | 2 +- .../Dss/Spot/ConstructorTraceVatMask.lean | 2 +- Benchmarks/Dss/Vat/Fork.lean | 10 ++++---- Benchmarks/Dss/Vat/FrobBase.lean | 24 +++++++++---------- Benchmarks/Dss/Vow/Constructor.lean | 6 ++--- Benchmarks/WETH9/Constructor.lean | 2 +- Benchmarks/WETH9/ConstructorStore.lean | 2 +- Examples/Ballot/Constructor.lean | 2 +- Examples/BlindAuction/Correct.lean | 6 ++--- .../AccessControl/GrantRole.lean | 2 +- Examples/Reuse/Correct.lean | 4 ++-- Examples/SimpleAuction/Correct.lean | 4 ++-- Examples/StringStoreLite/Getters.lean | 6 ++--- Examples/StringStoreLite/SetOldLong.lean | 4 ++-- Examples/VyperERC20/Allowance.lean | 8 +++---- Examples/VyperERC20/Approve.lean | 6 ++--- Examples/VyperERC20/BalanceOf.lean | 6 ++--- Examples/VyperERC20/Correct.lean | 10 ++++---- Examples/VyperERC20/Transfer.lean | 8 +++---- .../TransferFromAllowancePhase.lean | 2 +- Examples/VyperERC20/TransferFromBase.lean | 6 ++--- 52 files changed, 109 insertions(+), 109 deletions(-) diff --git a/Benchmarks/Dss/Cat/ConstructorTraceVat.lean b/Benchmarks/Dss/Cat/ConstructorTraceVat.lean index 602eee7c..5f8b14e3 100644 --- a/Benchmarks/Dss/Cat/ConstructorTraceVat.lean +++ b/Benchmarks/Dss/Cat/ConstructorTraceVat.lean @@ -118,7 +118,7 @@ theorem catCtorVatMaskJoinReach (catCtorWardsHashMem I vat) (UInt256.ofNat 5) ByteArray.empty (createdAccounts, σWards) k' C' := by have rd108 := cat_ctor_run rd102 with [ - swap3, swap1, swap3, lor, swap1, swap2] + swap3, swap1, swap3, or, swap1, swap2] have hpc108 : (⟨102⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ = ⟨108⟩ := by native_decide diff --git a/Benchmarks/Dss/Cure/Drop.lean b/Benchmarks/Dss/Cure/Drop.lean index b3f7951a..109cc88a 100644 --- a/Benchmarks/Dss/Cure/Drop.lean +++ b/Benchmarks/Dss/Cure/Drop.lean @@ -487,7 +487,7 @@ theorem RD.cureDropSwapStoreMoveElemPrefix {g : Sat256} {s0 : State} raw swap5 (by native_decide) (by evm_ov), raw dup6 (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov)] + raw or (by native_decide) (by evm_ov)] rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask from by decide] at rdSetRaw rw [hstored] at rdSetRaw diff --git a/Benchmarks/Dss/Cure/Lift.lean b/Benchmarks/Dss/Cure/Lift.lean index f987ce21..06741dff 100644 --- a/Benchmarks/Dss/Cure/Lift.lean +++ b/Benchmarks/Dss/Cure/Lift.lean @@ -640,7 +640,7 @@ theorem RD.cureLiftStoreAndLog {g : Sat256} {s0 : State} have rdElemStorePre := evm_run rdCleared with [ raw swap1 (by native_decide) (by evm_ov), raw dup2 (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov)] + raw or (by native_decide) (by evm_ov)] rw [hnewWord] at rdElemStorePre have rdElemStoreReady := evm_run rdElemStorePre with [ raw swap1 (by native_decide) (by evm_ov), diff --git a/Benchmarks/Dss/DaiJoin/ConstructorTraceStores.lean b/Benchmarks/Dss/DaiJoin/ConstructorTraceStores.lean index dee0b6ee..aac42cac 100644 --- a/Benchmarks/Dss/DaiJoin/ConstructorTraceStores.lean +++ b/Benchmarks/Dss/DaiJoin/ConstructorTraceStores.lean @@ -57,7 +57,7 @@ theorem daiJoinCtorVatStoreReach have rdBeforeStore := daiJoin_ctor_run rd89 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, swap3, dup4, and, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, raw not (by daiJoin_ctor_decode) (by evm_ov), - swap2, dup3, and, raw lor (by daiJoin_ctor_decode) (by evm_ov), swap1, swap2] + swap2, dup3, and, raw or (by daiJoin_ctor_decode) (by evm_ov), swap1, swap2] obtain ⟨k', C', rd116⟩ := rdBeforeStore.sstore hperm (by daiJoin_ctor_decode) (by evm_ov) exact ⟨k', C', by simpa [oldVat, daiJoinCtorVatStored, setAddressOffset0Word, solcSlotWord, solcAddrMask, @@ -91,7 +91,7 @@ theorem daiJoinCtorDaiStoreReach obtain ⟨_, _, rd120⟩ := (daiJoin_ctor_run rd116 with [push1 ⟨2⟩, dup1]).sload (by daiJoin_ctor_decode) (by evm_ov) have rdBeforeStore := daiJoin_ctor_run rd120 with [ - swap3, swap1, swap4, and, swap2, and, raw lor (by daiJoin_ctor_decode) (by evm_ov), + swap3, swap1, swap4, and, swap2, and, raw or (by daiJoin_ctor_decode) (by evm_ov), swap1] obtain ⟨k', C', rd129⟩ := rdBeforeStore.sstore hperm (by daiJoin_ctor_decode) (by evm_ov) exact ⟨k', C', by diff --git a/Benchmarks/Dss/Dog/FileAddress.lean b/Benchmarks/Dss/Dog/FileAddress.lean index 4cec20d6..4fd5ff24 100644 --- a/Benchmarks/Dss/Dog/FileAddress.lean +++ b/Benchmarks/Dss/Dog/FileAddress.lean @@ -720,7 +720,7 @@ theorem RD.dogFileAddressStoreVowLog {v : DogImmutables} {code : ByteArray} raw and (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw lor + raw or (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)]; native_decide) (by evm_ov), raw swap1 diff --git a/Benchmarks/Dss/Dog/FileIlkClip.lean b/Benchmarks/Dss/Dog/FileIlkClip.lean index b65c263f..cd9b4cd3 100644 --- a/Benchmarks/Dss/Dog/FileIlkClip.lean +++ b/Benchmarks/Dss/Dog/FileIlkClip.lean @@ -3054,7 +3054,7 @@ theorem RD.dogFileIlkClipStoreLog {v : DogImmutables} {code : ByteArray} raw and (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)]; native_decide) (by evm_ov), - raw lor + raw or (by rw [dogDecodePatchedEqTemplateAway hpatch (by native_decide) (by native_decide)]; native_decide) (by evm_ov), raw swap1 diff --git a/Benchmarks/Dss/End/FileAddressTail.lean b/Benchmarks/Dss/End/FileAddressTail.lean index 20e29407..50cf309d 100644 --- a/Benchmarks/Dss/End/FileAddressTail.lean +++ b/Benchmarks/Dss/End/FileAddressTail.lean @@ -567,7 +567,7 @@ theorem endFileAddressX_spot_ok {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} raw sub (by native_decide) (by evm_ov), raw dup4 (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] have hstoreWord : UInt256.lor (UInt256.land (fileAddressDataKey I) solcAddrMask) @@ -695,7 +695,7 @@ theorem endFileAddressX_cure_ok {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ} raw sub (by native_decide) (by evm_ov), raw dup4 (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] have hstoreWord : UInt256.lor (UInt256.land (fileAddressDataKey I) solcAddrMask) diff --git a/Benchmarks/Dss/Flapper/ConstructorTraceDefaults.lean b/Benchmarks/Dss/Flapper/ConstructorTraceDefaults.lean index 252baf10..4133b7d5 100644 --- a/Benchmarks/Dss/Flapper/ConstructorTraceDefaults.lean +++ b/Benchmarks/Dss/Flapper/ConstructorTraceDefaults.lean @@ -60,13 +60,13 @@ theorem flapperCtorDefaultsReach have rd24 := flapper_ctor_run rd21 with [push2 flapperCtorTtlWord] have rd31 := rd24.pushConst flapperUint48Mask (width := 6) (op := .PUSH6) (by decide) (by flapper_ctor_decode) (by evm_ov) - have rd36 := flapper_ctor_run rd31 with [not, swap1, swap2, and, lor] + have rd36 := flapper_ctor_run rd31 with [not, swap1, swap2, and, or] have rd43 := rd36.pushConst flapperUint48Mask (width := 6) (op := .PUSH6) (by decide) (by flapper_ctor_decode) (by evm_ov) have rd48 := flapper_ctor_run rd43 with [push1 ⟨48⟩, shl, not, and] have rd58 := rd48.pushConst (UInt256.shiftLeft flapperCtorTauWord ⟨48⟩) (width := 9) (op := .PUSH9) (by decide) (by flapper_ctor_decode) (by evm_ov) - have rd60 := flapper_ctor_run rd58 with [lor, swap1] + have rd60 := flapper_ctor_run rd58 with [or, swap1] obtain ⟨k61, C61, rd61raw⟩ := rd60.sstore hperm (by flapper_ctor_decode) (by evm_ov) have rd61 : RD (flapperCtorCode vat gem) I g diff --git a/Benchmarks/Dss/Flapper/ConstructorTraceStores.lean b/Benchmarks/Dss/Flapper/ConstructorTraceStores.lean index cef04fde..d6df1ac5 100644 --- a/Benchmarks/Dss/Flapper/ConstructorTraceStores.lean +++ b/Benchmarks/Dss/Flapper/ConstructorTraceStores.lean @@ -83,7 +83,7 @@ theorem flapperCtorVatStoreReach have rd173 := flapper_ctor_run rd147 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, swap4, dup5, and, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, swap2, dup3, and, - lor, swap1, swap2] + or, swap1, swap2] obtain ⟨k', C', rd174raw⟩ := rd173.sstore hperm (by flapper_ctor_decode) (by evm_ov) have holdComm : UInt256.land (UInt256.lnot solcAddrMask) (solcSlotWord σWards I ⟨2⟩) = @@ -135,7 +135,7 @@ theorem flapperCtorGemStoreReach rfl simpa [hload] using rd178raw have rd190 := flapper_ctor_run rd178 with [ - swap4, swap1, swap5, and, swap3, and, swap2, swap1, swap2, lor, swap1, swap2] + swap4, swap1, swap5, and, swap3, and, swap2, swap1, swap2, or, swap1, swap2] obtain ⟨k', C', rd191raw⟩ := rd190.sstore hperm (by flapper_ctor_decode) (by evm_ov) exact ⟨k', C', by simpa [flapperCtorGemStored, setAddressOffset0Word, diff --git a/Benchmarks/Dss/Flapper/Kick.lean b/Benchmarks/Dss/Flapper/Kick.lean index cc0d1411..0e537b7e 100644 --- a/Benchmarks/Dss/Flapper/Kick.lean +++ b/Benchmarks/Dss/Flapper/Kick.lean @@ -2633,7 +2633,7 @@ theorem flapperKickX_toCheckedAddStart {cA σ I} {g : Sat256} {s0 : State} raw not (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] obtain ⟨k4290, C4290, rd4290raw⟩ := rd4288pre.sstore hperm (by native_decide) (by evm_ov) @@ -2937,7 +2937,7 @@ theorem flapperKickX_toMoveSetupStart {cA σ I} {g : Sat256} {s0 : State} raw swap5 (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap5 (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap4 (by native_decide) (by evm_ov)] obtain ⟨k4377, C4377, rd4377raw⟩ := rd4376pre.sstore hperm diff --git a/Benchmarks/Dss/Flapper/Tend.lean b/Benchmarks/Dss/Flapper/Tend.lean index 096c8453..5efce14d 100644 --- a/Benchmarks/Dss/Flapper/Tend.lean +++ b/Benchmarks/Dss/Flapper/Tend.lean @@ -5273,7 +5273,7 @@ theorem flapperTendX_refundCallSuccessToPayStart raw not (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] obtain ⟨k2597, C2597, rd2597raw⟩ := rd2596pre.sstore hperm (by native_decide) (by evm_ov) @@ -5632,7 +5632,7 @@ theorem flapperTendX_successFromAddOkAw8 raw swap4 (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap4 (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap3 (by native_decide) (by evm_ov)] obtain ⟨k2821, C2821, rd2821raw⟩ := rd2819pre.sstore hperm diff --git a/Benchmarks/Dss/Flapper/Tick.lean b/Benchmarks/Dss/Flapper/Tick.lean index 46974b7d..b0bb3527 100644 --- a/Benchmarks/Dss/Flapper/Tick.lean +++ b/Benchmarks/Dss/Flapper/Tick.lean @@ -1468,7 +1468,7 @@ theorem flapperTickX_success raw swap2 (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap2 (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] obtain ⟨k4893, C4893, rd4893raw⟩ := rd4892pre.sstore hperm (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Flipper/Constructor.lean b/Benchmarks/Dss/Flipper/Constructor.lean index 04cf7780..642921a3 100644 --- a/Benchmarks/Dss/Flipper/Constructor.lean +++ b/Benchmarks/Dss/Flipper/Constructor.lean @@ -998,7 +998,7 @@ theorem flipperCtorNonpayableRDrev raw swap1 (by flipper_ctor_decode) (by evm_ov), raw swap2 (by flipper_ctor_decode) (by evm_ov), raw and (by flipper_ctor_decode) (by evm_ov), - raw lor (by flipper_ctor_decode) (by evm_ov)] + raw or (by flipper_ctor_decode) (by evm_ov)] have rd43 := rd36.pushConst (⟨281474976710655⟩ : UInt256) (width := 6) (op := .PUSH6) (by native_decide : Operation.POp.PUSH6 ≠ .PUSH0) (by flipper_ctor_decode) (by evm_ov) @@ -1011,7 +1011,7 @@ theorem flipperCtorNonpayableRDrev (width := 9) (op := .PUSH9) (by native_decide : Operation.POp.PUSH9 ≠ .PUSH0) (by flipper_ctor_decode) (by evm_ov) have rd60 := evm_run rd58 with [ - raw lor (by flipper_ctor_decode) (by evm_ov), + raw or (by flipper_ctor_decode) (by evm_ov), raw swap1 (by flipper_ctor_decode) (by evm_ov)] let slot5New := UInt256.lor (⟨0x02a300000000000000⟩ : UInt256) @@ -1203,7 +1203,7 @@ theorem flipperCtorInitReach raw swap1 (by flipper_ctor_decode) (by evm_ov), raw swap2 (by flipper_ctor_decode) (by evm_ov), raw and (by flipper_ctor_decode) (by evm_ov), - raw lor (by flipper_ctor_decode) (by evm_ov)] + raw or (by flipper_ctor_decode) (by evm_ov)] have rd43 := rd36.pushConst (⟨281474976710655⟩ : UInt256) (width := 6) (op := .PUSH6) (by native_decide : Operation.POp.PUSH6 ≠ .PUSH0) (by flipper_ctor_decode) (by evm_ov) @@ -1216,7 +1216,7 @@ theorem flipperCtorInitReach (width := 9) (op := .PUSH9) (by native_decide : Operation.POp.PUSH9 ≠ .PUSH0) (by flipper_ctor_decode) (by evm_ov) have rd60 := evm_run rd58 with [ - raw lor (by flipper_ctor_decode) (by evm_ov), + raw or (by flipper_ctor_decode) (by evm_ov), raw swap1 (by flipper_ctor_decode) (by evm_ov)] obtain ⟨_, _, rd61raw⟩ := rd60.sstore hperm (by flipper_ctor_decode) (by simp only [List.length_nil]; omega) @@ -1503,7 +1503,7 @@ theorem flipperCtorVatStoreReach raw swap2 (by flipper_ctor_decode) (by evm_ov), raw dup3 (by flipper_ctor_decode) (by evm_ov), raw and (by flipper_ctor_decode) (by evm_ov), - raw lor (by flipper_ctor_decode) (by evm_ov), + raw or (by flipper_ctor_decode) (by evm_ov), raw swap1 (by flipper_ctor_decode) (by evm_ov), raw swap2 (by flipper_ctor_decode) (by evm_ov)] have hload : @@ -1602,7 +1602,7 @@ theorem flipperCtorCatStoreReach raw swap4 (by flipper_ctor_decode) (by evm_ov), raw swap1 (by flipper_ctor_decode) (by evm_ov), raw swap4 (by flipper_ctor_decode) (by evm_ov), - raw lor (by flipper_ctor_decode) (by evm_ov), + raw or (by flipper_ctor_decode) (by evm_ov), raw swap1 (by flipper_ctor_decode) (by evm_ov)] have hload : (σVat.find? I.codeOwner |>.option ⟨0⟩ (fun ac => ac.storage.findD ⟨7⟩ ⟨0⟩)) = diff --git a/Benchmarks/Dss/Flipper/DentRefundEVM.lean b/Benchmarks/Dss/Flipper/DentRefundEVM.lean index ef320bf5..9cdebdf2 100644 --- a/Benchmarks/Dss/Flipper/DentRefundEVM.lean +++ b/Benchmarks/Dss/Flipper/DentRefundEVM.lean @@ -539,7 +539,7 @@ theorem flipperDentX_storeRefundGuyToFluxStart {cA σ I} {g : Sat256} {s0 : Stat raw not (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] rw [hmask160, hstoredRaw] at rd4925 obtain ⟨k4926, C4926, rd4926raw⟩ := rd4925.sstore hperm (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Flipper/DentTail.lean b/Benchmarks/Dss/Flipper/DentTail.lean index 388d5ffc..432f5c6f 100644 --- a/Benchmarks/Dss/Flipper/DentTail.lean +++ b/Benchmarks/Dss/Flipper/DentTail.lean @@ -1930,7 +1930,7 @@ theorem flipperDentX_storeTicReturn {cA σ I} {g : Sat256} {s0 : State} raw swap4 (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap4 (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap3 (by native_decide) (by evm_ov)] have hstoredRaw : diff --git a/Benchmarks/Dss/Flipper/FileUint.lean b/Benchmarks/Dss/Flipper/FileUint.lean index b0c558ca..dc939c3c 100644 --- a/Benchmarks/Dss/Flipper/FileUint.lean +++ b/Benchmarks/Dss/Flipper/FileUint.lean @@ -1012,7 +1012,7 @@ theorem flipperFileUintX_storeTtl {cA σ I} {g : Sat256} {s0 : State} (by evm_ov), raw dup4 (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] obtain ⟨_, _, rd1851⟩ := rd1850.sstore hperm (by native_decide) (by evm_ov) have rd1988 := rd1851.push2 ⟨1988⟩ (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Flipper/Kick.lean b/Benchmarks/Dss/Flipper/Kick.lean index 494b8b18..e589669a 100644 --- a/Benchmarks/Dss/Flipper/Kick.lean +++ b/Benchmarks/Dss/Flipper/Kick.lean @@ -1310,7 +1310,7 @@ theorem flipperKickX_toAdd48 {cA σ I} {g : Sat256} {s0 : State} raw not (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] rw [hmask160, hstoredGuy] at rd2205pre obtain ⟨k2206, C2206, rd2206⟩ := rd2205pre.sstore hperm (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Flipper/KickTail.lean b/Benchmarks/Dss/Flipper/KickTail.lean index 24b62533..0713cc3e 100644 --- a/Benchmarks/Dss/Flipper/KickTail.lean +++ b/Benchmarks/Dss/Flipper/KickTail.lean @@ -94,7 +94,7 @@ theorem test_flipperKickX_toEndStore {cA σ I} {g : Sat256} {s0 : State} raw swap6 (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap6 (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap5 (by native_decide) (by evm_ov)] have hdiv26 : @@ -222,7 +222,7 @@ theorem test_flipperKickX_toUsrStore {cA σ I} {g : Sat256} {s0 : State} raw swap3 (by native_decide) (by evm_ov), raw dup4 (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap3 (by native_decide) (by evm_ov)] have hmask160 : @@ -325,7 +325,7 @@ theorem test_flipperKickX_toGalStore {cA σ I} {g : Sat256} {s0 : State} raw swap3 (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap3 (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap2 (by native_decide) (by evm_ov)] have hstoredRaw : diff --git a/Benchmarks/Dss/Flipper/TendRefund.lean b/Benchmarks/Dss/Flipper/TendRefund.lean index 148d00bc..bff65271 100644 --- a/Benchmarks/Dss/Flipper/TendRefund.lean +++ b/Benchmarks/Dss/Flipper/TendRefund.lean @@ -2039,7 +2039,7 @@ theorem flipperTendX_storeRefundGuyToPayStart {cA σ I} {g : Sat256} {s0 : State raw not (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] rw [hmask160, hstoredRaw] at rd3684 obtain ⟨k3685, C3685, rd3685raw⟩ := rd3684.sstore hperm (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Flipper/TendTail.lean b/Benchmarks/Dss/Flipper/TendTail.lean index d4496410..62ec4ef6 100644 --- a/Benchmarks/Dss/Flipper/TendTail.lean +++ b/Benchmarks/Dss/Flipper/TendTail.lean @@ -1702,7 +1702,7 @@ theorem flipperTendX_storeTicReturn {cA σ I} {g : Sat256} {s0 : State} raw swap4 (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap4 (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap3 (by native_decide) (by evm_ov)] have hstoredRaw := tendStoredTicRuntimeWord σ I diff --git a/Benchmarks/Dss/Flipper/Tick.lean b/Benchmarks/Dss/Flipper/Tick.lean index fbcf9081..d84f70ff 100644 --- a/Benchmarks/Dss/Flipper/Tick.lean +++ b/Benchmarks/Dss/Flipper/Tick.lean @@ -1176,7 +1176,7 @@ theorem flipperTickX_storeEnd {cA σ I} {g : Sat256} {s0 : State} raw swap2 (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap2 (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] have hdiv26 : UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨208⟩ = uint48Divisor26 := by diff --git a/Benchmarks/Dss/Flopper/ConstructorTraceDefaults.lean b/Benchmarks/Dss/Flopper/ConstructorTraceDefaults.lean index 219146b7..d4a743a4 100644 --- a/Benchmarks/Dss/Flopper/ConstructorTraceDefaults.lean +++ b/Benchmarks/Dss/Flopper/ConstructorTraceDefaults.lean @@ -70,13 +70,13 @@ theorem flopperCtorDefaultsReach have rd36 := flopper_ctor_run rd33 with [push2 flopperCtorTtlWord] have rd43 := rd36.pushConst flopperUint48Mask (width := 6) (op := .PUSH6) (by decide) (by flopper_ctor_decode) (by evm_ov) - have rd48 := flopper_ctor_run rd43 with [not, swap1, swap2, and, lor] + have rd48 := flopper_ctor_run rd43 with [not, swap1, swap2, and, or] have rd55 := rd48.pushConst flopperUint48Mask (width := 6) (op := .PUSH6) (by decide) (by flopper_ctor_decode) (by evm_ov) have rd60 := flopper_ctor_run rd55 with [push1 ⟨48⟩, shl, not, and] have rd70 := rd60.pushConst (UInt256.shiftLeft flopperCtorTauWord ⟨48⟩) (width := 9) (op := .PUSH9) (by decide) (by flopper_ctor_decode) (by evm_ov) - have rd72 := flopper_ctor_run rd70 with [lor, swap1] + have rd72 := flopper_ctor_run rd70 with [or, swap1] obtain ⟨k73, C73, rd73raw⟩ := rd72.sstore hperm (by flopper_ctor_decode) (by evm_ov) have rd73 : RD (flopperCtorCode vat gem) I g diff --git a/Benchmarks/Dss/Flopper/ConstructorTraceStores.lean b/Benchmarks/Dss/Flopper/ConstructorTraceStores.lean index 201cd1bd..42cb8fb2 100644 --- a/Benchmarks/Dss/Flopper/ConstructorTraceStores.lean +++ b/Benchmarks/Dss/Flopper/ConstructorTraceStores.lean @@ -83,7 +83,7 @@ theorem flopperCtorVatStoreReach have rd185 := flopper_ctor_run rd159 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, swap4, dup5, and, push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, swap2, dup3, and, - lor, swap1, swap2] + or, swap1, swap2] obtain ⟨k', C', rd186raw⟩ := rd185.sstore hperm (by flopper_ctor_decode) (by evm_ov) have holdComm : UInt256.land (UInt256.lnot solcAddrMask) (solcSlotWord σWards I ⟨2⟩) = @@ -135,7 +135,7 @@ theorem flopperCtorGemStoreReach rfl simpa [hload] using rd190raw have rd202 := flopper_ctor_run rd190 with [ - swap4, swap1, swap5, and, swap3, and, swap2, swap1, swap2, lor, swap1, swap2] + swap4, swap1, swap5, and, swap3, and, swap2, swap1, swap2, or, swap1, swap2] obtain ⟨k', C', rd203raw⟩ := rd202.sstore hperm (by flopper_ctor_decode) (by evm_ov) exact ⟨k', C', by simpa [flopperCtorGemStored, setAddressOffset0Word, diff --git a/Benchmarks/Dss/Flopper/Dent/Part5.lean b/Benchmarks/Dss/Flopper/Dent/Part5.lean index db195f42..8b4e69a2 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part5.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part5.lean @@ -1547,7 +1547,7 @@ theorem flopperDentX_moveSuccessTicNonzeroToTail raw not (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] obtain ⟨k2889, C2889, rd2889raw⟩ := rd2887pre.sstore hperm (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Flopper/Dent/Part6.lean b/Benchmarks/Dss/Flopper/Dent/Part6.lean index aa66c1fe..60302f87 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part6.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part6.lean @@ -1075,7 +1075,7 @@ theorem flopperDentX_guyStoreTailFrom2855 raw not (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), raw caller (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] obtain ⟨k2889, C2889, rd2889raw⟩ := rd2887pre.sstore hperm (by native_decide) (by evm_ov) @@ -1462,7 +1462,7 @@ theorem flopperDentX_successFromAddOk raw swap4 (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap4 (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap3 (by native_decide) (by evm_ov)] obtain ⟨k2991, C2991, rd2991raw⟩ := rd2990pre.sstore hperm diff --git a/Benchmarks/Dss/Flopper/Dent/Part7.lean b/Benchmarks/Dss/Flopper/Dent/Part7.lean index 7934742a..d21e5131 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part7.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part7.lean @@ -116,7 +116,7 @@ theorem flopperDentX_successFromAddOkAw8 raw swap4 (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap4 (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap3 (by native_decide) (by evm_ov)] obtain ⟨k2991, C2991, rd2991raw⟩ := rd2990pre.sstore hperm diff --git a/Benchmarks/Dss/Flopper/Kick/Part1.lean b/Benchmarks/Dss/Flopper/Kick/Part1.lean index 20ce78e0..e6047d7f 100644 --- a/Benchmarks/Dss/Flopper/Kick/Part1.lean +++ b/Benchmarks/Dss/Flopper/Kick/Part1.lean @@ -1498,7 +1498,7 @@ theorem flopperKickX_toCheckedAddStart {cA σ I} {g : Sat256} {s0 : State} {k C raw sub (by native_decide) (by evm_ov), raw dup7 (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] obtain ⟨k3709, C3709, rd3709raw⟩ := rd3708pre.sstore hperm (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Flopper/Kick/Part2.lean b/Benchmarks/Dss/Flopper/Kick/Part2.lean index b6fe3a10..d10b3475 100644 --- a/Benchmarks/Dss/Flopper/Kick/Part2.lean +++ b/Benchmarks/Dss/Flopper/Kick/Part2.lean @@ -274,7 +274,7 @@ theorem flopperKickX_toEventStart {cA σ I} {g : Sat256} {s0 : State} {k C : ℕ raw swap4 (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap4 (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap3 (by native_decide) (by evm_ov)] obtain ⟨k3796, C3796, rd3796raw⟩ := rd3795pre'.sstore hperm diff --git a/Benchmarks/Dss/Flopper/Tick/Part2.lean b/Benchmarks/Dss/Flopper/Tick/Part2.lean index 54a7ffc1..722eec69 100644 --- a/Benchmarks/Dss/Flopper/Tick/Part2.lean +++ b/Benchmarks/Dss/Flopper/Tick/Part2.lean @@ -489,7 +489,7 @@ theorem flopperTickX_success raw swap2 (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw swap2 (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov)] obtain ⟨k4673, C4673, rd4673raw⟩ := rd4672pre.sstore hperm (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/GemJoin/ConstructorTraceStores.lean b/Benchmarks/Dss/GemJoin/ConstructorTraceStores.lean index 58d90ee4..42a8e4d4 100644 --- a/Benchmarks/Dss/GemJoin/ConstructorTraceStores.lean +++ b/Benchmarks/Dss/GemJoin/ConstructorTraceStores.lean @@ -112,7 +112,7 @@ theorem gemJoinCtorVatMaskHighReach have rd116 := gem_ctor_run rd103 with [ push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨160⟩, shl, sub, not, swap3, dup4, raw and (by gem_ctor_decode) (by evm_ov), - lor] + or] exact ⟨_, _, by simpa [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask from by decide, @@ -203,7 +203,7 @@ theorem gemJoinCtorGemStoreReach rw [hload] at rd128 have rd140 := gem_ctor_run rd128 with [ dup4, dup6, raw and (by gem_ctor_decode) (by evm_ov), swap3, - raw and (by gem_ctor_decode) (by evm_ov), swap2, swap1, swap2, lor, swap1, + raw and (by gem_ctor_decode) (by evm_ov), swap2, swap1, swap2, or, swap1, dup2, swap1] obtain ⟨k', C', rd141⟩ := rd140.sstore hperm (by gem_ctor_decode) (by evm_ov) exact ⟨k', C', by diff --git a/Benchmarks/Dss/Jug/ConstructorTraceVatMask.lean b/Benchmarks/Dss/Jug/ConstructorTraceVatMask.lean index 9c2772d0..68bc6cc3 100644 --- a/Benchmarks/Dss/Jug/ConstructorTraceVatMask.lean +++ b/Benchmarks/Dss/Jug/ConstructorTraceVatMask.lean @@ -28,7 +28,7 @@ theorem jugCtorVatMaskJoinReach (jugCtorWardsHashMem I vat) (UInt256.ofNat 5) ByteArray.empty (createdAccounts, σWards) k' C' := by have rd105 := jug_ctor_run rd100 with [ - swap2, swap1, swap2, lor, swap1] + swap2, swap1, swap2, or, swap1] have hpc105 : (⟨100⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ = ⟨105⟩ := by native_decide diff --git a/Benchmarks/Dss/Pot/ConstructorTraceVat.lean b/Benchmarks/Dss/Pot/ConstructorTraceVat.lean index 04d8e6f6..75e32894 100644 --- a/Benchmarks/Dss/Pot/ConstructorTraceVat.lean +++ b/Benchmarks/Dss/Pot/ConstructorTraceVat.lean @@ -119,7 +119,7 @@ theorem potCtorVatMaskJoinReach (potCtorWardsHashMem I vat) (UInt256.ofNat 5) ByteArray.empty (createdAccounts, σWards) k' C' := by have rd108 := pot_ctor_run rd102 with [ - swap3, swap1, swap3, lor, swap1, swap2] + swap3, swap1, swap3, or, swap1, swap2] have hpc108 : (⟨102⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ = ⟨108⟩ := by native_decide diff --git a/Benchmarks/Dss/Spot/ConstructorTraceVatMask.lean b/Benchmarks/Dss/Spot/ConstructorTraceVatMask.lean index e6f2d975..a19ca1cd 100644 --- a/Benchmarks/Dss/Spot/ConstructorTraceVatMask.lean +++ b/Benchmarks/Dss/Spot/ConstructorTraceVatMask.lean @@ -28,7 +28,7 @@ theorem spotCtorVatMaskJoinReach (spotCtorWardsHashMem I vat) (UInt256.ofNat 5) ByteArray.empty (createdAccounts, σWards) k' C' := by have rd108 := spot_ctor_run rd102 with [ - swap3, swap1, swap3, lor, swap1, swap2] + swap3, swap1, swap3, or, swap1, swap2] have hpc108 : (⟨102⟩ : UInt256) + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ + ⟨1⟩ = ⟨108⟩ := by native_decide diff --git a/Benchmarks/Dss/Vat/Fork.lean b/Benchmarks/Dss/Vat/Fork.lean index b3a60341..366b104c 100644 --- a/Benchmarks/Dss/Vat/Fork.lean +++ b/Benchmarks/Dss/Vat/Fork.lean @@ -12750,7 +12750,7 @@ theorem RD.vatForkDustChecksSuccess have rd6791 := rd5191pre.jump (by native_decide) (by jump_dest) (by evm_ov) have rd5192 := evm_run rd6791 with [ raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd5196pre := evm_run rd5192 with [ @@ -12787,7 +12787,7 @@ theorem RD.vatForkDustChecksSuccess have rd6791' := rd5279pre.jump (by native_decide) (by jump_dest) (by evm_ov) have rd5280 := evm_run rd6791' with [ raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd5284pre := evm_run rd5280 with [ @@ -12847,7 +12847,7 @@ theorem RD.vatForkSrcDustCheckRevert have rd6791 := rd5191pre.jump (by native_decide) (by jump_dest) (by evm_ov) have rd5192 := evm_run rd6791 with [ raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd5196pre := evm_run rd5192 with [ @@ -12920,7 +12920,7 @@ theorem RD.vatForkDstDustCheckRevert have rd6791 := rd5191pre.jump (by native_decide) (by jump_dest) (by evm_ov) have rd5192 := evm_run rd6791 with [ raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd5196pre := evm_run rd5192 with [ @@ -12957,7 +12957,7 @@ theorem RD.vatForkDstDustCheckRevert have rd6791' := rd5279pre.jump (by native_decide) (by jump_dest) (by evm_ov) have rd5280 := evm_run rd6791' with [ raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd5284pre := evm_run rd5280 with [ diff --git a/Benchmarks/Dss/Vat/FrobBase.lean b/Benchmarks/Dss/Vat/FrobBase.lean index 24b7980d..96dfab81 100644 --- a/Benchmarks/Dss/Vat/FrobBase.lean +++ b/Benchmarks/Dss/Vat/FrobBase.lean @@ -5250,7 +5250,7 @@ theorem RD.vatFrobCeilingCheckSuccess raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3422 := evm_run rd3421 with [ raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3426 := evm_run rd3422 with [ @@ -5470,7 +5470,7 @@ theorem RD.vatFrobCeilingCheckRevert raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3422 := evm_run rd3421 with [ raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3426 := evm_run rd3422 with [ @@ -5808,7 +5808,7 @@ theorem RD.vatFrobSafetyCheckSuccess have rd6791 := rd3540.jump (by native_decide) (by jump_dest) (by evm_ov) have rd3541 := evm_run rd6791 with [ raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3545 := evm_run rd3541 with [ @@ -5966,7 +5966,7 @@ theorem RD.vatFrobSafetyCheckRevert have rd6791 := rd3540.jump (by native_decide) (by jump_dest) (by evm_ov) have rd3541 := evm_run rd6791 with [ raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3545 := evm_run rd3541 with [ @@ -6372,7 +6372,7 @@ theorem RD.vatFrobUWishCheckSuccess raw push2 ⟨6791⟩ (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov), raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3640 := evm_run rd3636 with [ @@ -6469,7 +6469,7 @@ theorem RD.vatFrobUWishCheckRevertFall raw push2 ⟨6791⟩ (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov), raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3640 := evm_run rd3636 with [ @@ -6648,7 +6648,7 @@ theorem RD.vatFrobVWishCheckSuccess raw push2 ⟨6791⟩ (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov), raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3727 := evm_run rd3723 with [ @@ -6737,7 +6737,7 @@ theorem RD.vatFrobVWishCheckRevert raw push2 ⟨6791⟩ (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov), raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3727 := evm_run rd3723 with [ @@ -6889,7 +6889,7 @@ theorem RD.vatFrobWWishCheckSuccess raw push2 ⟨6791⟩ (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov), raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3814 := evm_run rd3810 with [ @@ -6992,7 +6992,7 @@ theorem RD.vatFrobWWishCheckRevert raw push2 ⟨6791⟩ (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov), raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3814 := evm_run rd3810 with [ @@ -7245,7 +7245,7 @@ theorem RD.vatFrobDustCheckSuccess have rd6791 := rd3902.jump (by native_decide) (by jump_dest) (by evm_ov) have rd3903 := evm_run rd6791 with [ raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3907 := evm_run rd3903 with [ @@ -7428,7 +7428,7 @@ theorem RD.vatFrobDustCheckRevert have rd6791 := rd3902.jump (by native_decide) (by jump_dest) (by evm_ov) have rd3903 := evm_run rd6791 with [ raw jumpdest (by native_decide) (by evm_ov), - raw lor (by native_decide) (by evm_ov), + raw or (by native_decide) (by evm_ov), raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd3907 := evm_run rd3903 with [ diff --git a/Benchmarks/Dss/Vow/Constructor.lean b/Benchmarks/Dss/Vow/Constructor.lean index e3b64254..acae88a4 100644 --- a/Benchmarks/Dss/Vow/Constructor.lean +++ b/Benchmarks/Dss/Vow/Constructor.lean @@ -811,7 +811,7 @@ theorem vowCtorVatStoreReach raw swap3 (by ctor_decode) (by evm_ov), raw dup4 (by ctor_decode) (by evm_ov), raw and (by ctor_decode) (by evm_ov), - raw lor (by ctor_decode) (by evm_ov), + raw or (by ctor_decode) (by evm_ov), raw swap3 (by ctor_decode) (by evm_ov), raw dup4 (by ctor_decode) (by evm_ov), raw swap1 (by ctor_decode) (by evm_ov)] @@ -882,7 +882,7 @@ theorem vowCtorFlapperStoreReach raw dup5 (by ctor_decode) (by evm_ov), raw and (by ctor_decode) (by evm_ov), raw dup2 (by ctor_decode) (by evm_ov), - raw lor (by ctor_decode) (by evm_ov), + raw or (by ctor_decode) (by evm_ov), raw swap1 (by ctor_decode) (by evm_ov), raw swap2 (by ctor_decode) (by evm_ov)] have hload : @@ -973,7 +973,7 @@ theorem vowCtorFlopperStoreReach raw swap4 (by ctor_decode) (by evm_ov), raw swap1 (by ctor_decode) (by evm_ov), raw swap4 (by ctor_decode) (by evm_ov), - raw lor (by ctor_decode) (by evm_ov), + raw or (by ctor_decode) (by evm_ov), raw swap1 (by ctor_decode) (by evm_ov), raw swap3 (by ctor_decode) (by evm_ov)] have hload : diff --git a/Benchmarks/WETH9/Constructor.lean b/Benchmarks/WETH9/Constructor.lean index 6c74d226..bf6da012 100644 --- a/Benchmarks/WETH9/Constructor.lean +++ b/Benchmarks/WETH9/Constructor.lean @@ -249,7 +249,7 @@ theorem weth9CtorReachGuard {cA gh bl σ σ₀ A I} {g : Sat256} -- Segment 3a: POP; decimals RMW; reach pc 105. have rd91 := evm_run rd90 with [jumpdest, pop, push1 ⟨2⟩, dup1] obtain ⟨_, _, rd96⟩ := rd91.sload (by native_decide) (by evm_ov) - have rd104 := evm_run rd96 with [push1 ⟨255⟩, not, and, push1 ⟨18⟩, lor, swap1] + have rd104 := evm_run rd96 with [push1 ⟨255⟩, not, and, push1 ⟨18⟩, or, swap1] obtain ⟨_, _, rd105⟩ := rd104.sstore hperm (by native_decide) (by evm_ov) exact ⟨_, _, rd105⟩ diff --git a/Benchmarks/WETH9/ConstructorStore.lean b/Benchmarks/WETH9/ConstructorStore.lean index af988cc5..375de007 100644 --- a/Benchmarks/WETH9/ConstructorStore.lean +++ b/Benchmarks/WETH9/ConstructorStore.lean @@ -165,7 +165,7 @@ theorem weth9StringStoreSubroutine exact hmemData) (weth9AwMemPtr_eq aw memPtr.toNat hawMem) (by evm_ov) -- Phase E: build the short word, SSTORE it at `slot`. - have hE := evm_run hMload with [push1 ⟨255⟩, not, and, dup4, dup1, add, lor, dup6] + have hE := evm_run hMload with [push1 ⟨255⟩, not, and, dup4, dup1, add, or, dup6] obtain ⟨_, _, hSstore⟩ := hE.sstore hperm (by native_decide) (by evm_ov) -- Phase F: return-dance setup to the clear-loop head ⟨254⟩. have hF := evm_run hSstore with [ diff --git a/Examples/Ballot/Constructor.lean b/Examples/Ballot/Constructor.lean index 553bf4f8..7244b63e 100644 --- a/Examples/Ballot/Constructor.lean +++ b/Examples/Ballot/Constructor.lean @@ -845,7 +845,7 @@ theorem ballotDecoderAlloc {cA : Batteries.RBSet AccountAddress compare} {gh : B -- part 2: newFP + overflow check have rd2 := ctor_run rd1 with [ dup2, add, - push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨0x40⟩, shl, sub, dup2, gt, dup3, dup3, lt, lor, iszero, push2 ⟨0x14e⟩, + push1 ⟨1⟩, push1 ⟨1⟩, push1 ⟨0x40⟩, shl, sub, dup2, gt, dup3, dup3, lt, or, iszero, push2 ⟨0x14e⟩, jumpiT (by rw [hfp]; exact ballotAllocOverflow n elemBytes argBytes hstruct helems hszH h64 hn64) (by ctor_jd) ] -- part 3: MSTORE M[0x40] := newFP (aw stable) diff --git a/Examples/BlindAuction/Correct.lean b/Examples/BlindAuction/Correct.lean index dbf9f67a..d3d2bfc5 100644 --- a/Examples/BlindAuction/Correct.lean +++ b/Examples/BlindAuction/Correct.lean @@ -667,7 +667,7 @@ theorem blindAuctionInitcodeBiddingOverflowRevert obtain ⟨kSload, CSload, rdAfterSload⟩ := rdBeforeSload.sload (by blind_ctor_decode) (by evm_ov) have rdBeforeStore := blind_ctor_run rdAfterSload with [ - push20 solcAddrMask, not, and, lor, swap1, pop, push0] + push20 solcAddrMask, not, and, or, swap1, pop, push0] have hpacked : UInt256.lor (UInt256.land (UInt256.lnot solcAddrMask) oldBeneficiarySlot) (UInt256.land solcAddrMask (EVM.word beneficiaryAddress)) = @@ -751,7 +751,7 @@ theorem blindAuctionInitcodeRevealOverflowRevert obtain ⟨kSload, CSload, rdAfterSload⟩ := rdBeforeSload.sload (by blind_ctor_decode) (by evm_ov) have rdBeforeStore := blind_ctor_run rdAfterSload with [ - push20 solcAddrMask, not, and, lor, swap1, pop, push0] + push20 solcAddrMask, not, and, or, swap1, pop, push0] have hpacked : UInt256.lor (UInt256.land (UInt256.lnot solcAddrMask) oldBeneficiarySlot) (UInt256.land solcAddrMask (EVM.word beneficiaryAddress)) = @@ -894,7 +894,7 @@ theorem blindAuctionInitcodeSuccess obtain ⟨kSload, CSload, rdAfterSload⟩ := rdBeforeSload.sload (by blind_ctor_decode) (by evm_ov) have rdBeforeStore := blind_ctor_run rdAfterSload with [ - push20 solcAddrMask, not, and, lor, swap1, pop, push0] + push20 solcAddrMask, not, and, or, swap1, pop, push0] have hpacked : UInt256.lor (UInt256.land (UInt256.lnot solcAddrMask) oldBeneficiarySlot) (UInt256.land solcAddrMask (EVM.word beneficiaryAddress)) = diff --git a/Examples/OpenZeppelinBench/AccessControl/GrantRole.lean b/Examples/OpenZeppelinBench/AccessControl/GrantRole.lean index db80107a..33622d74 100644 --- a/Examples/OpenZeppelinBench/AccessControl/GrantRole.lean +++ b/Examples/OpenZeppelinBench/AccessControl/GrantRole.lean @@ -1104,7 +1104,7 @@ theorem accessControlGrantRoleX_grant_write {cA gh bl σ σ₀ A I} {g : Sat256} exact u256_land_comm (UInt256.lnot ⟨255⟩) (grantRoleTargetStorageWord σ I) have rd597pre := evm_run rd589 with [ - push1 ⟨255⟩, not, and, push1 ⟨1⟩, lor, swap1] + push1 ⟨255⟩, not, and, push1 ⟨1⟩, or, swap1] have hsetWord : UInt256.lor ⟨1⟩ (UInt256.land (UInt256.lnot ⟨255⟩) (grantRoleTargetStorageWord σ I)) = diff --git a/Examples/Reuse/Correct.lean b/Examples/Reuse/Correct.lean index 979587d2..8d8f5396 100644 --- a/Examples/Reuse/Correct.lean +++ b/Examples/Reuse/Correct.lean @@ -425,7 +425,7 @@ theorem RD.cCheckedMul2 {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k C : ℕ rw [Reasoning.Theory.cDiv_mul2 hmul, uInt256_eq_self] decide exact ⟨_, _, evm_run h with [ - jumpdest, dup1, dup3, mul, dup2, iszero, dup3, dup3, div, dup5, eq, lor, + jumpdest, dup1, dup3, mul, dup2, iszero, dup3, dup3, div, dup5, eq, or, push1 ⟨121⟩, jumpiT hcond (by jump_dest), jumpdest, swap3, swap2, pop, pop, jump hret ]⟩ @@ -446,7 +446,7 @@ theorem RD.cCheckedMul2_overflow {g : Sat256} {s0 : State} {ee : ExecutionEnv} { rw [heq] decide have rd193₀ := evm_run h with [ - jumpdest, dup1, dup3, mul, dup2, iszero, dup3, dup3, div, dup5, eq, lor ] + jumpdest, dup1, dup3, mul, dup2, iszero, dup3, dup3, div, dup5, eq, or ] have rd193 := rd193₀ rw [hcond] at rd193 have rd196 := evm_run rd193 with [ push1 ⟨121⟩, jumpiNT (by decide) ] diff --git a/Examples/SimpleAuction/Correct.lean b/Examples/SimpleAuction/Correct.lean index 1a87accd..684b46d0 100644 --- a/Examples/SimpleAuction/Correct.lean +++ b/Examples/SimpleAuction/Correct.lean @@ -495,7 +495,7 @@ theorem simpleAuctionInitcodeOverflowRevert obtain ⟨kSload, CSload, rdAfterSload⟩ := rdBeforeSload.sload (by simple_ctor_decode) (by evm_ov) have rdBeforeStore := simple_ctor_run rdAfterSload with [ - push20 solcAddrMask, not, and, lor, swap1, pop, push0] + push20 solcAddrMask, not, and, or, swap1, pop, push0] have hpacked : UInt256.lor (UInt256.land (UInt256.lnot solcAddrMask) oldBeneficiarySlot) (UInt256.land solcAddrMask (EVM.word beneficiaryAddress)) = @@ -582,7 +582,7 @@ theorem simpleAuctionInitcodeSuccess obtain ⟨kSload, CSload, rdAfterSload⟩ := rdBeforeSload.sload (by simple_ctor_decode) (by evm_ov) have rdBeforeStore := simple_ctor_run rdAfterSload with [ - push20 solcAddrMask, not, and, lor, swap1, pop, push0] + push20 solcAddrMask, not, and, or, swap1, pop, push0] have hpacked : UInt256.lor (UInt256.land (UInt256.lnot solcAddrMask) oldBeneficiarySlot) (UInt256.land solcAddrMask (EVM.word beneficiaryAddress)) = diff --git a/Examples/StringStoreLite/Getters.lean b/Examples/StringStoreLite/Getters.lean index 1e8778df..7003db44 100644 --- a/Examples/StringStoreLite/Getters.lean +++ b/Examples/StringStoreLite/Getters.lean @@ -3968,7 +3968,7 @@ theorem stringStoreLiteX_setEmptyWriteShortZero {cA gh bl σ σ₀ A I} {g : Sat jump (by jump_dest), jumpdest, not, dup1, dup4, and, swap2, pop, pop, swap3, swap2, pop, pop, jump (by jump_dest), - jumpdest, swap2, pop, dup3, push1 ⟨2⟩, mul, dup3, lor, swap1, pop, + jumpdest, swap2, pop, dup3, push1 ⟨2⟩, mul, dup3, or, swap1, pop, swap3, swap2, pop, pop, jump (by jump_dest)] have rd1448pre := evm_run rd1446 with [jumpdest, dup7] obtain ⟨_, _, rd1449₀⟩ := rd1448pre.sstore hperm (by native_decide) (by evm_ov) @@ -4086,7 +4086,7 @@ theorem stringStoreLiteX_setEmptyWriteShortValid {cA gh bl σ σ₀ A I} {g : Sa jump (by jump_dest), jumpdest, not, dup1, dup4, and, swap2, pop, pop, swap3, swap2, pop, pop, jump (by jump_dest), - jumpdest, swap2, pop, dup3, push1 ⟨2⟩, mul, dup3, lor, swap1, pop, + jumpdest, swap2, pop, dup3, push1 ⟨2⟩, mul, dup3, or, swap1, pop, swap3, swap2, pop, pop, jump (by jump_dest)] have rd1448pre := evm_run rd1446 with [jumpdest, dup7] obtain ⟨_, _, rd1449₀⟩ := rd1448pre.sstore hperm (by native_decide) (by evm_ov) @@ -4134,7 +4134,7 @@ theorem stringStoreLiteX_setWriteShortPackedFrom1436 {cA gh bl σinit σ₀ A I} jump (by jump_dest), jumpdest, not, dup1, dup4, and, swap2, pop, pop, swap3, swap2, pop, pop, jump (by jump_dest), - jumpdest, swap2, pop, dup3, push1 ⟨2⟩, mul, dup3, lor, swap1, pop, + jumpdest, swap2, pop, dup3, push1 ⟨2⟩, mul, dup3, or, swap1, pop, swap3, swap2, pop, pop, jump (by jump_dest)] have rd1448pre := evm_run rd1446 with [jumpdest, dup7] obtain ⟨_, _, rd1449₀⟩ := rd1448pre.sstore hperm (by native_decide) (by evm_ov) diff --git a/Examples/StringStoreLite/SetOldLong.lean b/Examples/StringStoreLite/SetOldLong.lean index a0f116ac..2649a6c4 100644 --- a/Examples/StringStoreLite/SetOldLong.lean +++ b/Examples/StringStoreLite/SetOldLong.lean @@ -1405,7 +1405,7 @@ theorem stringStoreLiteX_setStoreHelperZero {cA gh bl σinit σ₀ A I} {g : Sat have rd1021 := RD.swap6 rd1019 (by native_decide) (by evm_ov) have rd1123 := evm_run rd1021 with [ pop, dup1, not, dup5, and, swap4, pop, dup1, dup7, - and, dup5, lor, swap3, pop, pop, pop, swap4, swap3, pop, pop, pop, + and, dup5, or, swap3, pop, pop, pop, swap4, swap3, pop, pop, pop, jump (by jump_dest), jumpdest, dup3] obtain ⟨_, _, rd1126₀⟩ := rd1123.sstore hperm (by native_decide) (by evm_ov) @@ -1549,7 +1549,7 @@ theorem stringStoreLiteX_setEmptyWriteZeroFrom1405 {cA gh bl σinit σ₀ A I} jump (by jump_dest), jumpdest, not, dup1, dup4, and, swap2, pop, pop, swap3, swap2, pop, pop, jump (by jump_dest), - jumpdest, swap2, pop, dup3, push1 ⟨2⟩, mul, dup3, lor, swap1, pop, + jumpdest, swap2, pop, dup3, push1 ⟨2⟩, mul, dup3, or, swap1, pop, swap3, swap2, pop, pop, jump (by jump_dest)] have rd1448pre := evm_run rd1446 with [jumpdest, dup7] obtain ⟨_, _, rd1449₀⟩ := rd1448pre.sstore hperm (by native_decide) (by evm_ov) diff --git a/Examples/VyperERC20/Allowance.lean b/Examples/VyperERC20/Allowance.lean index bed1ccb4..a1f4ca9a 100644 --- a/Examples/VyperERC20/Allowance.lean +++ b/Examples/VyperERC20/Allowance.lean @@ -454,7 +454,7 @@ theorem erc20X_allowanceFromEntry {cA gh bl σ σ₀ A I} {g : Sat256} calldatasize, lt, callvalue, - lor, + or, push2 ⟨801⟩, jumpiNT (by rw [hsizeGuard, hwv]; decide), push1 ⟨4⟩, @@ -596,7 +596,7 @@ theorem erc20AllowanceX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} calldatasize, lt, callvalue, - lor, + or, push2 ⟨801⟩, jumpiT (by rw [hwv, hsizeGuard68]; decide) (by vyper_erc20_allowance_decode)] exact vyperRuntimeRevert801 (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) @@ -626,7 +626,7 @@ theorem erc20AllowanceX_noncanon_owner {cA gh bl σ σ₀ A I} {g : Sat256} calldatasize, lt, callvalue, - lor, + or, push2 ⟨801⟩, jumpiNT (by rw [hwv, hsizeGuard]; decide), push1 ⟨4⟩, @@ -668,7 +668,7 @@ theorem erc20AllowanceX_noncanon_spender {cA gh bl σ σ₀ A I} {g : Sat256} calldatasize, lt, callvalue, - lor, + or, push2 ⟨801⟩, jumpiNT (by rw [hwv, hsizeGuard]; decide), push1 ⟨4⟩, diff --git a/Examples/VyperERC20/Approve.lean b/Examples/VyperERC20/Approve.lean index f80ec855..d154f4ac 100644 --- a/Examples/VyperERC20/Approve.lean +++ b/Examples/VyperERC20/Approve.lean @@ -427,7 +427,7 @@ theorem erc20X_approveFromEntry {cA gh bl σ σ₀ A I} {g : Sat256} jumpdest, raw push4 approveSelectorWord (by vyper_erc20_approve_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨68⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨68⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiNT (by rw [hsizeGuard, hwv]; decide), push1 ⟨4⟩, calldataload, dup1, push1 ⟨160⟩, shr, push2 ⟨801⟩, jumpiNT (by simpa [approveSpenderWord, calldataWord] using hcanonSpenderGuard), @@ -523,7 +523,7 @@ theorem erc20ApproveX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} jumpdest, raw push4 approveSelectorWord (by vyper_erc20_approve_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨68⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨68⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiT (by rw [hwv, hsizeGuard68]; decide) (by vyper_erc20_approve_decode)] exact vyperRuntimeRevert801 (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (g := g) rd801 rfl (by norm_num) @@ -545,7 +545,7 @@ theorem erc20ApproveX_noncanon_spender {cA gh bl σ σ₀ A I} {g : Sat256} jumpdest, raw push4 approveSelectorWord (by vyper_erc20_approve_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨68⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨68⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiNT (by rw [hwv, hsizeGuard]; decide), push1 ⟨4⟩, calldataload, dup1, push1 ⟨160⟩, shr, push2 ⟨801⟩, jumpiT (by diff --git a/Examples/VyperERC20/BalanceOf.lean b/Examples/VyperERC20/BalanceOf.lean index d6efa726..e4af3853 100644 --- a/Examples/VyperERC20/BalanceOf.lean +++ b/Examples/VyperERC20/BalanceOf.lean @@ -249,7 +249,7 @@ theorem erc20X_balanceOfFromEntry {cA gh bl σ σ₀ A I} {g : Sat256} calldatasize, lt, callvalue, - lor, + or, push2 ⟨801⟩, jumpiNT (by rw [hsizeGuard, hwv]; decide), push1 ⟨4⟩, @@ -415,7 +415,7 @@ theorem erc20BalanceOfX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} calldatasize, lt, callvalue, - lor, + or, push2 ⟨801⟩, jumpiT (by rw [hwv, hsizeGuard36]; decide) (by vyper_erc20_balance_decode)] exact vyperRuntimeRevert801 (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) @@ -448,7 +448,7 @@ theorem erc20BalanceOfX_noncanon_owner {cA gh bl σ σ₀ A I} {g : Sat256} calldatasize, lt, callvalue, - lor, + or, push2 ⟨801⟩, jumpiNT (by rw [hwv, hsizeGuard36]; decide), push1 ⟨4⟩, diff --git a/Examples/VyperERC20/Correct.lean b/Examples/VyperERC20/Correct.lean index 47617e46..1effe8c2 100644 --- a/Examples/VyperERC20/Correct.lean +++ b/Examples/VyperERC20/Correct.lean @@ -1449,7 +1449,7 @@ theorem erc20ApproveNonPayableRuntime jumpdest, raw push4 approveSelectorWord (by vyper_erc20_approve_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨68⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨68⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiT (by simpa [u256_lor_comm] using (u256_lor_ne_zero_right @@ -1509,7 +1509,7 @@ theorem erc20TransferFromNonPayableRuntime jumpdest, raw push4 transferFromSelectorWord (by native_decide) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨100⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨100⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiT (by simpa [u256_lor_comm] using (u256_lor_ne_zero_right @@ -1534,7 +1534,7 @@ theorem erc20BalanceOfNonPayableRuntime jumpdest, raw push4 balanceOfSelectorWord (by vyper_erc20_balance_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨36⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨36⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiT (by simpa [u256_lor_comm] using (u256_lor_ne_zero_right @@ -1559,7 +1559,7 @@ theorem erc20TransferNonPayableRuntime jumpdest, raw push4 transferSelectorWord (by vyper_erc20_transfer_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨68⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨68⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiT (by simpa [u256_lor_comm] using (u256_lor_ne_zero_right @@ -1584,7 +1584,7 @@ theorem erc20AllowanceNonPayableRuntime jumpdest, raw push4 allowanceSelectorWord (by vyper_erc20_allowance_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨68⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨68⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiT (by simpa [u256_lor_comm] using (u256_lor_ne_zero_right diff --git a/Examples/VyperERC20/Transfer.lean b/Examples/VyperERC20/Transfer.lean index 4fbb4f92..78738d39 100644 --- a/Examples/VyperERC20/Transfer.lean +++ b/Examples/VyperERC20/Transfer.lean @@ -934,7 +934,7 @@ theorem erc20X_transferAfterBalanceGuard {cA gh bl σ σ₀ A I} {g : Sat256} jumpdest, raw push4 transferSelectorWord (by vyper_erc20_transfer_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨68⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨68⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiNT (by rw [hsizeGuard, hwv]; decide), push1 ⟨4⟩, calldataload, dup1, push1 ⟨160⟩, shr, push2 ⟨801⟩, jumpiNT (by simpa [transferToWord, calldataWord] using hcanonToGuard), @@ -1399,7 +1399,7 @@ theorem erc20TransferX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} jumpdest, raw push4 transferSelectorWord (by vyper_erc20_transfer_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨68⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨68⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiT (by rw [hsizeGuard, hwv]; decide) (by vyper_erc20_transfer_decode)] exact transferRevertStub (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (g := g) rd801 rfl (by norm_num) @@ -1422,7 +1422,7 @@ theorem erc20TransferX_noncanon_to {cA gh bl σ σ₀ A I} {g : Sat256} jumpdest, raw push4 transferSelectorWord (by vyper_erc20_transfer_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨68⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨68⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiNT (by rw [hsizeGuard, hwv]; decide), push1 ⟨4⟩, calldataload, dup1, push1 ⟨160⟩, shr, push2 ⟨801⟩, jumpiT (by @@ -1464,7 +1464,7 @@ theorem erc20TransferX_insufficient {cA gh bl σ σ₀ A I} {g : Sat256} jumpdest, raw push4 transferSelectorWord (by vyper_erc20_transfer_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨68⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨68⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiNT (by rw [hsizeGuard, hwv]; decide), push1 ⟨4⟩, calldataload, dup1, push1 ⟨160⟩, shr, push2 ⟨801⟩, jumpiNT (by simpa [transferToWord, calldataWord] using hcanonToGuard), diff --git a/Examples/VyperERC20/TransferFromAllowancePhase.lean b/Examples/VyperERC20/TransferFromAllowancePhase.lean index d3e54404..988ee1fb 100644 --- a/Examples/VyperERC20/TransferFromAllowancePhase.lean +++ b/Examples/VyperERC20/TransferFromAllowancePhase.lean @@ -34,7 +34,7 @@ theorem erc20X_transferFromAfterAllowanceSLoad {cA gh bl σ σ₀ A I} {g : Sat2 jumpdest, raw push4 transferFromSelectorWord (by vyper_erc20_transferFrom_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨100⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨100⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiNT (by rw [u256_lor_comm, hwv, u256_lor_zero]; exact hsizeGuard), push1 ⟨4⟩, calldataload, dup1, push1 ⟨160⟩, shr, push2 ⟨801⟩, jumpiNT (by simpa [transferFromFromWord, calldataWord] using hcanonFromGuard), diff --git a/Examples/VyperERC20/TransferFromBase.lean b/Examples/VyperERC20/TransferFromBase.lean index 47b6383e..06c08dcb 100644 --- a/Examples/VyperERC20/TransferFromBase.lean +++ b/Examples/VyperERC20/TransferFromBase.lean @@ -2390,7 +2390,7 @@ theorem erc20TransferFromX_shortarg {cA gh bl σ σ₀ A I} {g : Sat256} jumpdest, raw push4 transferFromSelectorWord (by vyper_erc20_transferFrom_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨100⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨100⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiT (by rw [hwv, hsizeGuard100]; decide) (by vyper_erc20_transferFrom_decode)] exact vyperRuntimeRevert801 (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) rd801 rfl (by norm_num) @@ -2415,7 +2415,7 @@ theorem erc20TransferFromX_noncanon_from {cA gh bl σ σ₀ A I} {g : Sat256} jumpdest, raw push4 transferFromSelectorWord (by vyper_erc20_transferFrom_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨100⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨100⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiNT (by rw [hwv, hsizeGuard100]; decide), push1 ⟨4⟩, calldataload, dup1, push1 ⟨160⟩, shr, push2 ⟨801⟩, jumpiT (by @@ -2449,7 +2449,7 @@ theorem erc20TransferFromX_noncanon_to {cA gh bl σ σ₀ A I} {g : Sat256} jumpdest, raw push4 transferFromSelectorWord (by vyper_erc20_transferFrom_decode) (by evm_ov), dup2, xor, push2 ⟨797⟩, jumpiNT (by native_decide), - push1 ⟨100⟩, calldatasize, lt, callvalue, lor, push2 ⟨801⟩, + push1 ⟨100⟩, calldatasize, lt, callvalue, or, push2 ⟨801⟩, jumpiNT (by rw [hwv, hsizeGuard100]; decide), push1 ⟨4⟩, calldataload, dup1, push1 ⟨160⟩, shr, push2 ⟨801⟩, jumpiNT (by simpa [transferFromFromWord, calldataWord] using hcanonFromGuard), From c5052c42b40bc9f65c19546b8bedd712b499c111 Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 10:24:51 +0300 Subject: [PATCH 34/38] Examples: wip --- Benchmarks/Dss/End/Cage.lean | 16 ++++++++-------- Benchmarks/Dss/End/Skim.lean | 2 +- Benchmarks/Dss/End/Skip.lean | 18 +++++++++--------- Benchmarks/Dss/End/Snip.lean | 14 +++++++------- Benchmarks/Dss/Flapper/Tend.lean | 14 +++++++------- Benchmarks/Dss/Flopper/Dent/Part1.lean | 6 +++--- Benchmarks/Dss/Flopper/Dent/Part3.lean | 4 ++-- Benchmarks/Dss/Flopper/Dent/Part4.lean | 8 ++++---- Benchmarks/Dss/Vow/Constructor.lean | 6 +++--- .../MintFeeOnKLastNonzeroRevertCases.lean | 2 +- 10 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Benchmarks/Dss/End/Cage.lean b/Benchmarks/Dss/End/Cage.lean index 713dc3a4..b6eb10c3 100644 --- a/Benchmarks/Dss/End/Cage.lean +++ b/Benchmarks/Dss/End/Cage.lean @@ -3128,7 +3128,7 @@ theorem endCageExecBlock_append_revert {f f1 : Frame} {e e1 : EVM.State} .execBlock_append_term (s2 := tail) h2 (by intro f' e' h; cases h) simpa [List.append_assoc] using - .execBlock_append (s2 := s2 ++ tail) h1 h2tail + execBlock_append (s2 := s2 ++ tail) h1 h2tail theorem endCageSourceAuthReverts {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) @@ -3427,7 +3427,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (endCageSourceStorePrefixStmts ++ endCageSourceVatStmts) (.ok { contract := contract, locals := lVat } evmS1) := by simpa [l0, List.append_assoc] using - .execBlock_append (s2 := endCageSourceVatStmts) + execBlock_append (s2 := endCageSourceVatStmts) hSrc0 hVatBlock by_cases hCatCodeE : Reasoning.Theory.extCodeSizeWord evmE1.accountMap @@ -3584,7 +3584,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} endCageSourceCatStmts) (.ok { contract := contract, locals := lCat } evmS2) := by simpa [List.append_assoc] using - .execBlock_append (s2 := endCageSourceCatStmts) + execBlock_append (s2 := endCageSourceCatStmts) hSrcVat hCatBlock by_cases hDogCodeE : Reasoning.Theory.extCodeSizeWord evmE2.accountMap @@ -3745,7 +3745,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} endCageSourceCatStmts ++ endCageSourceDogStmts) (.ok { contract := contract, locals := lDog } evmS3) := by simpa [List.append_assoc] using - .execBlock_append + execBlock_append (s2 := endCageSourceDogStmts) hSrcCat hDogBlock by_cases hVowCodeE : Reasoning.Theory.extCodeSizeWord evmE3.accountMap @@ -3912,7 +3912,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} endCageSourceVowStmts) (.ok { contract := contract, locals := lVow } evmS4) := by simpa [List.append_assoc] using - .execBlock_append + execBlock_append (s2 := endCageSourceVowStmts) hSrcDog hVowBlock by_cases hSpotCodeE : Reasoning.Theory.extCodeSizeWord evmE4.accountMap @@ -4089,7 +4089,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (.ok { contract := contract, locals := lSpot } evmS5) := by simpa [List.append_assoc] using - .execBlock_append + execBlock_append (s2 := endCageSourceSpotStmts) hSrcVow hSpotBlock by_cases hPotCodeE : Reasoning.Theory.extCodeSizeWord evmE5.accountMap @@ -4279,7 +4279,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (.ok { contract := contract, locals := lPot } evmS6) := by simpa [List.append_assoc] using - .execBlock_append + execBlock_append (s2 := endCageSourcePotStmts) hSrcSpot hPotBlock by_cases hCureCodeE : Reasoning.Theory.extCodeSizeWord evmE6.accountMap @@ -4489,7 +4489,7 @@ theorem endCageBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} (.ok { contract := contract, locals := lCure } evmS7) := by simpa [List.append_assoc] using - .execBlock_append + execBlock_append (s2 := endCageSourceCureStmts) hSrcPot hCureBlock have hbody : diff --git a/Benchmarks/Dss/End/Skim.lean b/Benchmarks/Dss/End/Skim.lean index b2459b32..0cbb92de 100644 --- a/Benchmarks/Dss/End/Skim.lean +++ b/Benchmarks/Dss/End/Skim.lean @@ -7431,7 +7431,7 @@ theorem endSkimBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} have hurnsInkArt := .execBlock_append hurnsBlock hinkArt simpa [List.append_assoc] using - .execBlock_append hprefix hurnsInkArt + execBlock_append hprefix hurnsInkArt have hTagCoupleUrns : endSkimTagWord σ_urns I = endSkimTagWord σ_urns_solm I := by simpa [endSkimTagWord, endSlotWord] using diff --git a/Benchmarks/Dss/End/Skip.lean b/Benchmarks/Dss/End/Skip.lean index 162470e6..34e27555 100644 --- a/Benchmarks/Dss/End/Skip.lean +++ b/Benchmarks/Dss/End/Skip.lean @@ -9915,7 +9915,7 @@ theorem endSkipTailAfterTabReturns {I σLoc} have htail3 :=.execBlock_append htail2 hhope have htail4 :=.execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using - .execBlock_append htail4 hartBlock + execBlock_append htail4 hartBlock theorem endSkipTailReverts_suck1 {I} {catOut vatOut bidOut : ByteArray} {evmTab : EVM.State} @@ -9925,7 +9925,7 @@ theorem endSkipTailReverts_suck1 {I} {catOut vatOut bidOut : ByteArray} ExecBlock config { contract := contract, locals := endSkipStoreTab I catOut vatOut bidOut } evmTab endSkipTailNoGrabStmts .reverted := by simpa [endSkipTailNoGrabStmts, List.append_assoc] using - .execBlock_append_term hsuck1 (by intro f' e' h; cases h) + execBlock_append_term hsuck1 (by intro f' e' h; cases h) theorem endSkipTailReverts_suck2 {I} {catOut vatOut bidOut : ByteArray} {evmTab evmSuck1 : EVM.State} @@ -9951,7 +9951,7 @@ theorem endSkipTailReverts_suck2 {I} {catOut vatOut bidOut : ByteArray} (s2 := endSkipHopeStmts ++ endSkipYankStmts ++ endSkipArtStmts) hsuck2 (by intro f' e' h; cases h)) simpa [endSkipTailNoGrabStmts, List.append_assoc] using - .execBlock_append hsuck1 hsuck2Tail + execBlock_append hsuck1 hsuck2Tail theorem endSkipTailReverts_hope {I} {catOut vatOut bidOut : ByteArray} {evmTab evmSuck1 evmSuck2 : EVM.State} @@ -9983,7 +9983,7 @@ theorem endSkipTailReverts_hope {I} {catOut vatOut bidOut : ByteArray} hhope (by intro f' e' h; cases h)) have htail2 :=.execBlock_append hsuck1 hsuck2 simpa [endSkipTailNoGrabStmts, List.append_assoc] using - .execBlock_append htail2 hhopeTail + execBlock_append htail2 hhopeTail theorem endSkipTailReverts_yank {I} {catOut vatOut bidOut : ByteArray} {evmTab evmSuck1 evmSuck2 evmHope : EVM.State} @@ -10018,7 +10018,7 @@ theorem endSkipTailReverts_yank {I} {catOut vatOut bidOut : ByteArray} have htail2 :=.execBlock_append hsuck1 hsuck2 have htail3 :=.execBlock_append htail2 hhope simpa [endSkipTailNoGrabStmts, List.append_assoc] using - .execBlock_append htail3 hyankTail + execBlock_append htail3 hyankTail theorem endSkipTailReverts_artDivZero {I} {catOut vatOut bidOut : ByteArray} {evmTab evmSuck1 evmSuck2 evmHope evmYank : EVM.State} @@ -10056,7 +10056,7 @@ theorem endSkipTailReverts_artDivZero {I} {catOut vatOut bidOut : ByteArray} have htail3 :=.execBlock_append htail2 hhope have htail4 :=.execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using - .execBlock_append htail4 hartRevert + execBlock_append htail4 hartRevert theorem endSkipTailReverts_artAddOverflow {I σLoc} {catOut vatOut bidOut : ByteArray} @@ -10104,7 +10104,7 @@ theorem endSkipTailReverts_artAddOverflow {I σLoc} have htail3 :=.execBlock_append htail2 hhope have htail4 :=.execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using - .execBlock_append htail4 hartBlock + execBlock_append htail4 hartBlock theorem endSkipTailReverts_intGuardLot {I σLoc} {catOut vatOut bidOut : ByteArray} @@ -10160,7 +10160,7 @@ theorem endSkipTailReverts_intGuardLot {I σLoc} have htail3 :=.execBlock_append htail2 hhope have htail4 :=.execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using - .execBlock_append htail4 hartBlock + execBlock_append htail4 hartBlock theorem endSkipTailReverts_intGuardArt {I σLoc} {catOut vatOut bidOut : ByteArray} @@ -10217,7 +10217,7 @@ theorem endSkipTailReverts_intGuardArt {I σLoc} have htail3 :=.execBlock_append htail2 hhope have htail4 :=.execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using - .execBlock_append htail4 hartBlock + execBlock_append htail4 hartBlock theorem endSkipBodyReverts_afterTabTailReverted {I} {catOut vatOut bidOut : ByteArray} {evm0 evmTab : EVM.State} diff --git a/Benchmarks/Dss/End/Snip.lean b/Benchmarks/Dss/End/Snip.lean index 6584f471..b41ea59e 100644 --- a/Benchmarks/Dss/End/Snip.lean +++ b/Benchmarks/Dss/End/Snip.lean @@ -8191,7 +8191,7 @@ theorem endSnipTailAfterUsrReturns {I σLoc} I σLoc dogOut vatOut saleOut hlot hart)) ExecBlock.nil simpa [List.append_assoc] using - .execBlock_append hsuck + execBlock_append hsuck (Reasoning.Theory.execBlock_append hyank hartBlock) theorem endSnipTailReverts_suck {I} {dogOut vatOut saleOut : ByteArray} @@ -8216,7 +8216,7 @@ theorem endSnipTailReverts_suck {I} {dogOut vatOut saleOut : ByteArray} (.binary .lt (.var "art") (.intLit int256Limit))) ]) .reverted := by simpa [List.append_assoc] using - .execBlock_append_term hsuck (by intro f' e' h; cases h) + execBlock_append_term hsuck (by intro f' e' h; cases h) theorem endSnipTailReverts_yank {I} {dogOut vatOut saleOut : ByteArray} {evmUsr evmSuck : EVM.State} @@ -8259,7 +8259,7 @@ theorem endSnipTailReverts_yank {I} {dogOut vatOut saleOut : ByteArray} .reverted := by exact.execBlock_append_term hyank (by intro f' e' h; cases h) simpa [List.append_assoc] using - .execBlock_append hsuck hyankTail + execBlock_append hsuck hyankTail theorem endSnipTailReverts_artDivZero {I} {dogOut vatOut saleOut : ByteArray} {evmUsr evmSuck evmYank : EVM.State} @@ -8303,7 +8303,7 @@ theorem endSnipTailReverts_artDivZero {I} {dogOut vatOut saleOut : ByteArray} .reverted := ExecBlock.consRevert (endSnipStmtArtReverts evmYank I dogOut vatOut saleOut hrate) simpa [List.append_assoc] using - .execBlock_append hsuck + execBlock_append hsuck (Reasoning.Theory.execBlock_append hyank hartRevert) theorem endSnipTailReverts_artAddOverflow {I σLoc} @@ -8357,7 +8357,7 @@ theorem endSnipTailReverts_artAddOverflow {I σLoc} exact ExecBlock.consRevert (endSnipStmtArtNewAddReverts evmYank I σLoc dogOut vatOut saleOut hsz68 hArtLoad hover) simpa [List.append_assoc] using - .execBlock_append hsuck + execBlock_append hsuck (Reasoning.Theory.execBlock_append hyank hartBlock) theorem endSnipTailReverts_intGuardLot {I σLoc} @@ -8419,7 +8419,7 @@ theorem endSnipTailReverts_intGuardLot {I σLoc} (endSnipPostArtState evmYank I (endSnipArtNewWord σLoc I vatOut saleOut)) I σLoc dogOut vatOut saleOut hlot)) simpa [List.append_assoc] using - .execBlock_append hsuck + execBlock_append hsuck (Reasoning.Theory.execBlock_append hyank hartBlock) theorem endSnipTailReverts_intGuardArt {I σLoc} @@ -8482,7 +8482,7 @@ theorem endSnipTailReverts_intGuardArt {I σLoc} (endSnipPostArtState evmYank I (endSnipArtNewWord σLoc I vatOut saleOut)) I σLoc dogOut vatOut saleOut hlot hart)) simpa [List.append_assoc] using - .execBlock_append hsuck + execBlock_append hsuck (Reasoning.Theory.execBlock_append hyank hartBlock) theorem endSnipBodyReverts_afterUsrTailReverted {I} {dogOut vatOut saleOut : ByteArray} diff --git a/Benchmarks/Dss/Flapper/Tend.lean b/Benchmarks/Dss/Flapper/Tend.lean index 5efce14d..696fbc6d 100644 --- a/Benchmarks/Dss/Flapper/Tend.lean +++ b/Benchmarks/Dss/Flapper/Tend.lean @@ -7878,7 +7878,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [List.append_assoc] using - .execBlock_append hskipRefund hpayTail + execBlock_append hskipRefund hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by @@ -7954,7 +7954,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [List.append_assoc] using - .execBlock_append hskipRefund hpayTail + execBlock_append hskipRefund hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by @@ -8086,7 +8086,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [List.append_assoc] using - .execBlock_append hskipRefund hpayTail + execBlock_append hskipRefund hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by @@ -8142,7 +8142,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [List.append_assoc] using - .execBlock_append hskipRefund hpayTail + execBlock_append hskipRefund hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by @@ -8373,7 +8373,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [evmGuySolm] using - .execBlock_append hprefix hpayTail + execBlock_append hprefix hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by @@ -8562,7 +8562,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [evmGuySolm] using - .execBlock_append hprefix hpayTail + execBlock_append hprefix hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by @@ -8613,7 +8613,7 @@ theorem flapperTendBodyCoreIncreaseSufficient_finishFromGuard [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) .reverted := by simpa [evmGuySolm] using - .execBlock_append hprefix hpayTail + execBlock_append hprefix hpayTail have hbody : ExecTransitionBody config contract evmSolm (tendLocals I) tendTransition.body .reverted := by diff --git a/Benchmarks/Dss/Flopper/Dent/Part1.lean b/Benchmarks/Dss/Flopper/Dent/Part1.lean index 7a75ab8b..50ff7f3b 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part1.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part1.lean @@ -1523,7 +1523,7 @@ theorem flopperDentBodyAfterAshSuccessKissNoCode simpa [checkedExternalCallStmts] using checkedExternalCallNoCode hguard simpa [List.cons_append, List.nil_append] using - .execBlock_append hmin hkiss + execBlock_append hmin hkiss theorem flopperDentBodyAfterAshSuccessKissCallFailure (localsEvm evmAsh evmKiss : EVM.State) (I : ExecutionEnv) @@ -1582,7 +1582,7 @@ theorem flopperDentBodyAfterAshSuccessKissCallFailure simpa [checkedExternalCallStmts] using checkedExternalCallFailure hguard htarget hargs hcall simpa [List.cons_append, List.nil_append] using - .execBlock_append hmin hkiss + execBlock_append hmin hkiss theorem flopperDentBodyAfterAshSuccessKissCallSuccess (localsEvm evmAsh evmKiss : EVM.State) (I : ExecutionEnv) @@ -1642,7 +1642,7 @@ theorem flopperDentBodyAfterAshSuccessKissCallSuccess simpa [checkedExternalCallStmts, dentKissRetLocals] using checkedExternalCallSuccess hguard htarget hargs hcall (dentKissDecode_ok outKiss) simpa [List.cons_append, List.nil_append] using - .execBlock_append hmin hkiss + execBlock_append hmin hkiss theorem evalExpr_dent_live_one_true (evm : EVM.State) (I : ExecutionEnv) (hlive : dentLiveWord evm = ⟨1⟩) : diff --git a/Benchmarks/Dss/Flopper/Dent/Part3.lean b/Benchmarks/Dss/Flopper/Dent/Part3.lean index 178cc9a0..52e4e6b1 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part3.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part3.lean @@ -1143,7 +1143,7 @@ theorem flopperDentBodyReverts_afterAshRevert_moveCallerNe_ticZero (.intLit 0) [.var "kissAmt"] "_kissRet") .reverted := by simpa [List.append_assoc] using - .execBlock_append hashChecked hafterAsh + execBlock_append hashChecked hafterAsh have hafterMove : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove [.ite (.binary .eq (.storage (bidsF (.var "id") "tic")) (.intLit 0)) @@ -1605,7 +1605,7 @@ theorem flopperDentBodyMoveAshKissSuccessTicZeroToLot (.intLit 0) [.var "kissAmt"] "_kissRet") (.ok { contract := contract, locals := dentKissRetLocals evm I outAsh } evmKiss) := by simpa [List.append_assoc] using - .execBlock_append hashChecked hafterAsh + execBlock_append hashChecked hafterAsh have hinnerGuy : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove [.ite (.binary .eq (.storage (bidsF (.var "id") "tic")) (.intLit 0)) diff --git a/Benchmarks/Dss/Flopper/Dent/Part4.lean b/Benchmarks/Dss/Flopper/Dent/Part4.lean index 272ed359..0d0514fa 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part4.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part4.lean @@ -109,7 +109,7 @@ theorem flopperDentBodyReverts_addOverflow_moveCallerNe_ticZero_kissSuccess [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := by simpa [List.cons_append, List.nil_append, evmGuy, evmLot] using - .execBlock_append htailIteLot htickTail + execBlock_append htailIteLot htickTail refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -246,7 +246,7 @@ theorem flopperDentBodyReturns_success_moveCallerNe_ticZero_kissSuccess (.ok { contract := contract, locals := dentKissRetTicLocals evm evmGuy I outAsh } (dentPostState evmGuy I)) := by simpa [List.cons_append, List.nil_append, evmGuy, evmLot] using - .execBlock_append htailIteLot htickLet + execBlock_append htailIteLot htickLet refine ExecFuncBody.execBlockOK ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append, evmGuy] using @@ -354,7 +354,7 @@ theorem flopperDentBodyReverts_addOverflow_moveCallerNe_ticNonzero [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := by simpa [List.cons_append, List.nil_append, evmGuy, evmLot] using - .execBlock_append htailIteLot htickTail + execBlock_append htailIteLot htickTail refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -468,7 +468,7 @@ theorem flopperDentBodyReturns_success_moveCallerNe_ticNonzero (.ok { contract := contract, locals := dentMoveTicLocals evm evmGuy I } (dentPostState evmGuy I)) := by simpa [List.cons_append, List.nil_append, evmGuy, evmLot] using - .execBlock_append htailIteLot htickLet + execBlock_append htailIteLot htickLet refine ExecFuncBody.execBlockOK ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append, evmGuy] using diff --git a/Benchmarks/Dss/Vow/Constructor.lean b/Benchmarks/Dss/Vow/Constructor.lean index acae88a4..2cd7c0f4 100644 --- a/Benchmarks/Dss/Vow/Constructor.lean +++ b/Benchmarks/Dss/Vow/Constructor.lean @@ -1708,7 +1708,7 @@ theorem vowCtorSolmExecReverts_noCode exact ExecBlock.consRevert (ExecStmt.requireFalse hguard) simpa [ExecTransitionBody, contract, constructorDecl, nonpayable, checkedExternalCallStmts, locals, evm0, evm1, evm2, evm3, evm4, List.cons_append, List.nil_append] using - .execBlock_append hprefix htail + execBlock_append hprefix htail theorem vowCtorSolmExecReverts_callFailure {createdAccounts : Batteries.RBSet AccountAddress compare} @@ -1782,7 +1782,7 @@ theorem vowCtorSolmExecReverts_callFailure (by simpa [evm0, evm1, evm2, evm3, evm4] using hcall)) simpa [ExecTransitionBody, contract, constructorDecl, nonpayable, checkedExternalCallStmts, locals, evm0, evm1, evm2, evm3, evm4, List.cons_append, List.nil_append] using - .execBlock_append hprefix htail + execBlock_append hprefix htail theorem vowCtorSolmExecSuccess {createdAccounts : Batteries.RBSet AccountAddress compare} @@ -1879,7 +1879,7 @@ theorem vowCtorSolmExecSuccess (.ok { contract := contract, locals := localsHope } evm5) := by simpa [constructorDecl, nonpayable, checkedExternalCallStmts, locals, evm0, evm1, evm2, evm3, evm4, evm5, List.cons_append, List.nil_append] using - .execBlock_append hprefix htail + execBlock_append hprefix htail simpa [ExecTransitionBody, contract, constructorDecl, locals, localsHope, evm0, evm5] using ExecFuncBody.execBlockOK hblock diff --git a/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroRevertCases.lean b/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroRevertCases.lean index 98a92b2f..9e14be8c 100644 --- a/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroRevertCases.lean +++ b/Examples/UniswapV2Pair/MintFeeOnKLastNonzeroRevertCases.lean @@ -340,7 +340,7 @@ theorem uniswapMintFeeFunctionBody_feeOn_kLastNonzero_fromRootBlockRevert refine ExecFuncBody.execBlockRevert ?_ simpa [mintFeeFunction, mintFeeRootComparisonStmt, mintFeePositiveRootBranchStmts, List.append_assoc] using - .execBlock_append hchecked htail + execBlock_append hchecked htail theorem uniswapMintFeeCallFromMint_feeOn_kLastNonzero_fromRootBlockRevert (reserveEvm callEvm evmFee : EVM.State) (I : ExecutionEnv) From 4d2246f364b2a76a4842819768d482772615eb5e Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 10:36:58 +0300 Subject: [PATCH 35/38] Reasoning: make zeros opaque again --- Reasoning/Memory.lean | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Reasoning/Memory.lean b/Reasoning/Memory.lean index e0a88f6d..4957b5b9 100644 --- a/Reasoning/Memory.lean +++ b/Reasoning/Memory.lean @@ -403,6 +403,13 @@ theorem zeroes_ofNat_size (n : ℕ) (_h : n < 2 ^ 32) : (ffi.ByteArray.zeroes n).size = n := by rw [ByteArray_zeroes_size] +-- `zeroes` used to be an `opaque` extern in evmlean, i.e. an unfolding WALL during defeq. It is +-- now a plain def (`Array.replicate`), and letting defeq descend into it makes large state +-- comparisons stack-overflow (observed in UniswapV2Pair/Mint). Re-erect the wall: reason about +-- `zeroes` only through the equations above (`ByteArray_zeroes_size`, `zeroes_zero`, …). +set_option allowUnsafeReducibility true in +attribute [irreducible] ffi.ByteArray.zeroes + theorem zeroes32_extract_zeroes (n : Nat) (hn : n ≤ 32) : (ffi.ByteArray.zeroes 32).extract 0 n = ffi.ByteArray.zeroes n := by From e42ed8965c4e4f61e282009ca67f7b2f98d3238f Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 12:08:51 +0300 Subject: [PATCH 36/38] Examples: wip remove mint for now --- Examples/UniswapV2Pair/Mint.lean | 120 ++++++++++++++++--------------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/Examples/UniswapV2Pair/Mint.lean b/Examples/UniswapV2Pair/Mint.lean index 9d24cece..4ce4c460 100644 --- a/Examples/UniswapV2Pair/Mint.lean +++ b/Examples/UniswapV2Pair/Mint.lean @@ -1031,15 +1031,11 @@ theorem uniswapMintBody hreserve0Source hreserve1Source hliquiditySource hliqNonzero hfitSupplySource hbalanceFitSource hbound0Source hbound1Source helapsedSource) - exact - uniswapMintFinishProportionalFeeOffCumulative - hcode hdispatch hsz36 hbody rd3701 - hPostAccountsFee henvFeeI hcreatedFee rfl - htotalNonzero hclean0 hclean1 hmulFit0 hmulFit1 - hreserve0Nonzero hreserve1Nonzero rfl hliqNonzero - hperm htotalFit hbalanceFit hfitSupplySource - hbalanceFitSource hbound0 hbound1 helapsedNe - rfl hmem hmem64 + -- WIP: broken by the Reasoning library port — + -- reserve-spelling drift (local reserve0/1 vs + -- uniswapReserve0Word (uniswapLockEnteredState evmS)); + -- needs bridges like hfitKLastSource'. + exact sorry · let packed := uniswapUpdatePackedReserveWord (uniswapSlotWord ⟨8⟩ σAfterMint I) @@ -1564,6 +1560,40 @@ theorem uniswapMintBody simpa [hmask] using hbound1 norm_num [maxUint112] exact_mod_cast hnat + have hfitKLastSource' : + mintFeeReserveProductNat + (uniswapReserve0Word + (syncUpdateCumulativePackedReserveStateWith + (mintFunctionPostState evmFeeS + (AccountAddress.ofNat + (mintToWord I).toNat) liquidity) + balance0 balance1 + (uniswapReserve0Word + (uniswapLockEnteredState evmS)) + (uniswapReserve1Word + (uniswapLockEnteredState evmS)))) + (uniswapReserve1Word + (syncUpdateCumulativePackedReserveStateWith + (mintFunctionPostState evmFeeS + (AccountAddress.ofNat + (mintToWord I).toNat) liquidity) + balance0 balance1 + (uniswapReserve0Word + (uniswapLockEnteredState evmS)) + (uniswapReserve1Word + (uniswapLockEnteredState evmS)))) < + UInt256.size := by + rw [show + uniswapReserve0Word + (uniswapLockEnteredState evmS) = + reserve0 by + simpa [reserve0] using hreserve0Eq] + rw [show + uniswapReserve1Word + (uniswapLockEnteredState evmS) = + reserve1 by + simpa [reserve1] using hreserve1Eq] + exact hfitKLastSource have hbody := ExecFuncBody.execBlockRet (uniswapMintProportionalFeeOnCumulativeReturn_kLastZero @@ -1576,16 +1606,12 @@ theorem uniswapMintBody hreserve0Source hreserve1Source hliquiditySource hliqNonzero hfitSupplySource hbalanceFitSource hbound0Source hbound1Source - helapsedSource hfitKLastSource) - exact - uniswapMintFinishProportionalFeeOnCumulativeKLastUpdated - hcode hdispatch hsz36 hbody rd3701 - hPostAccountsFee henvFeeI hcreatedFee rfl - htotalNonzero hclean0 hclean1 hmulFit0 hmulFit1 - hreserve0Nonzero hreserve1Nonzero rfl hliqNonzero - hperm htotalFit hbalanceFit hfitSupplySource - hbalanceFitSource hbound0 hbound1 helapsedNe - hfitKLastRuntime hmem hmem64 + helapsedSource hfitKLastSource') + -- WIP: broken by the Reasoning library port — + -- reserve-spelling drift (hclean0) and + -- hfitKLastRuntime whnf timeout; hbody above + -- compiles via the hfitKLastSource' bridge. + exact sorry · let σCleared := sstoreAccountMap I.codeOwner σFee ⟨11⟩ ⟨0⟩ let evmAfterFee := mintFeeKLastClearedState evmFeeS @@ -2136,15 +2162,9 @@ theorem uniswapMintBody hreserve1Source hliquiditySource hliqNonzero hfitSupplySource hbalanceFitSource hbound0Source hbound1Source helapsedSource) - exact - uniswapMintFinishProportionalFeeOffCumulative - hcode hdispatch hsz36 hbody rd3701 - hPostCleared henvCleared hcreatedCleared rfl - htotalNonzero hclean0 hclean1 hmulFit0 hmulFit1 - hreserve0Nonzero hreserve1Nonzero rfl hliqNonzero - hperm htotalFit hbalanceFit hfitSupplySource - hbalanceFitSource hbound0 hbound1 helapsedNe - rfl hmem hmem64 + -- WIP: broken by the Reasoning library port — + -- reserve-spelling drift (hclean0). + exact sorry · by_cases hsmallNoMint : UInt256.land feeToWord solcAddrMask ≠ ⟨0⟩ ∧ mintFeeKLastSlotWord σFee I ≠ ⟨0⟩ ∧ @@ -2606,41 +2626,23 @@ theorem uniswapMintBody UInt256.land feeToWord solcAddrMask ≠ ⟨0⟩ · by_cases hkLastNonzeroFinal : mintFeeKLastSlotWord σFee I ≠ ⟨0⟩ - · exact False.elim (hfeeOnKLastNonzeroInitial (by - unfold mintFeeOnKLastNonzeroInitialOverflowFromFactoryCasesData - mintFeeOnKLastNonzeroInitialFromFactoryCasesData - mintFeeOnKLastNonzeroInitialReturnFromFactoryCaseData - mintFeeOnKLastNonzeroInitialZeroFromFactoryCaseData - mintFeeOnKLastNonzeroInitialProductOverflowFromFactoryCaseData - mintFeeOnKLastNonzeroInitialRootUnderflowFromFactoryCaseData - mintFeeOnKLastNonzeroInitialMinimumBalanceOverflowFromFactoryCaseData - mintFeeOnKLastNonzeroInitialSecondMintTotalSupplyOverflowFromFactoryCaseData - mintFeeOnKLastNonzeroInitialSecondMintBalanceOverflowFromFactoryCaseData - mintFeeOnKLastNonzeroNoFeeLiquidityFromFactoryCaseData - unfold mintFeeOnKLastNonzeroRootArithmeticOverflowFromFactoryCaseData at hrootArithmetic - unfold mintProportionalProductOverflowCase at hproductOverflow - unfold mintProportionalSecondMintOverflowCase at hsecondMintOverflow - simp [hfeeToNonzeroFinal, - hkLastNonzeroFinal, htotalEq])) - · exfalso - contradiction - · exfalso - contradiction + · -- WIP: broken by the Reasoning library port. + exact sorry + · -- WIP: broken by the Reasoning library port. + exact sorry + · -- WIP: broken by the Reasoning library port. + exact sorry · by_cases hfeeToNonzeroFinal : UInt256.land feeToWord solcAddrMask ≠ ⟨0⟩ · by_cases hkLastNonzeroFinal : mintFeeKLastSlotWord σFee I ≠ ⟨0⟩ - · exact False.elim (hfeeOnKLastNonzeroSuccess (by - unfold mintFeeOnKLastNonzeroSuccessFromFactoryCasesData - mintFeeOnKLastNonzeroNoMintFromFactoryCaseData - unfold mintFeeOnKLastNonzeroRootArithmeticOverflowFromFactoryCaseData at hrootArithmetic - unfold mintProportionalProductOverflowCase at hproductOverflow - unfold mintProportionalSecondMintOverflowCase at hsecondMintOverflow - simp_all)) - · exfalso - contradiction - · exfalso - contradiction + · -- WIP: broken by the Reasoning library port — + -- simp_all diverges on drift-spelled state hyps. + exact sorry + · -- WIP: broken by the Reasoning library port. + exact sorry + · -- WIP: broken by the Reasoning library port. + exact sorry · rw [not_lt] at hdepth have hdepth1024 : I.depth = 1024 := Fin.ext (by have := I.depth.isLt; omega) let evmL := uniswapLockEnteredState evmS From b18f8a2836c2eb5fb7eb140b70251eca3d6698e2 Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 13:09:29 +0300 Subject: [PATCH 37/38] Examples: wip remove mint for now --- Examples/UniswapV2Pair/PermitTypehash.lean | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Examples/UniswapV2Pair/PermitTypehash.lean b/Examples/UniswapV2Pair/PermitTypehash.lean index bb67a876..314ec8b4 100644 --- a/Examples/UniswapV2Pair/PermitTypehash.lean +++ b/Examples/UniswapV2Pair/PermitTypehash.lean @@ -1,4 +1,5 @@ import Examples.UniswapV2Pair.Dispatch +import Examples.UniswapV2Pair.Permit import Reasoning.SolmBody open Solm ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach @@ -7,10 +8,7 @@ set_option maxRecDepth 2000000 namespace UniswapV2Pair -/-! ## `PERMIT_TYPEHASH()` constant getter -/ - -def permitTypehashWord : UInt256 := - ⟨49955707469362902507454157297736832118868343942642399513960811609542965143241⟩ +/-! ## `PERMIT_TYPEHASH()` constant getter (constant lives in Permit.lean) -/ theorem permitTypehashWord_toBytesBE : EVM.Word.toBytesBE permitTypehashWord = permitTypehashBytes := by From 4f907e58cf6c0a68e7dc4a4e504245671810cfaf Mon Sep 17 00:00:00 2001 From: zoep Date: Wed, 29 Jul 2026 15:02:57 +0300 Subject: [PATCH 38/38] Benchmarks: cleanup port --- Benchmarks/Dss/Cat/FileAddress.lean | 2 +- Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean | 2 +- Benchmarks/Dss/Cure/LoadSource.lean | 14 +- Benchmarks/Dss/End/Cage.lean | 2 +- Benchmarks/Dss/End/CageIlk.lean | 20 +-- Benchmarks/Dss/End/Cash.lean | 14 +- Benchmarks/Dss/End/FileAddress.lean | 14 +- Benchmarks/Dss/End/Flow.lean | 8 +- Benchmarks/Dss/End/Free.lean | 16 +- Benchmarks/Dss/End/Pack.lean | 8 +- Benchmarks/Dss/End/Skim.lean | 22 +-- Benchmarks/Dss/End/Skip.lean | 70 ++++---- Benchmarks/Dss/End/Snip.lean | 36 ++-- Benchmarks/Dss/End/Thaw.lean | 38 ++--- Benchmarks/Dss/Flapper/Deal.lean | 18 +- Benchmarks/Dss/Flapper/File.lean | 4 +- Benchmarks/Dss/Flapper/Kick.lean | 6 +- Benchmarks/Dss/Flapper/Tend.lean | 30 ++-- Benchmarks/Dss/Flapper/Yank.lean | 4 +- Benchmarks/Dss/Flipper/FileAddress.lean | 2 +- Benchmarks/Dss/Flipper/FileUint.lean | 2 +- Benchmarks/Dss/Flopper/Cage.lean | 2 +- Benchmarks/Dss/Flopper/Deal.lean | 4 +- Benchmarks/Dss/Flopper/Dent/Part3.lean | 44 ++--- Benchmarks/Dss/Flopper/Dent/Part4.lean | 10 +- Benchmarks/Dss/Flopper/File/Part1.lean | 4 +- Benchmarks/Dss/Flopper/Tick/Part1.lean | 6 +- Benchmarks/Dss/Flopper/Yank/Part1.lean | 4 +- Benchmarks/Dss/Jug/FileVow.lean | 2 +- Benchmarks/Dss/Pot/FileVow.lean | 2 +- Benchmarks/Dss/Spot/FilePip.lean | 2 +- Benchmarks/Dss/Vat/Flux.lean | 4 +- Benchmarks/Dss/Vat/FoldCommon.lean | 20 +-- Benchmarks/Dss/Vat/FoldTail.lean | 22 +-- Benchmarks/Dss/Vat/Fork.lean | 182 ++++++++++----------- Benchmarks/Dss/Vat/FrobBase.lean | 56 +++---- Benchmarks/Dss/Vat/FrobLive.lean | 38 ++--- Benchmarks/Dss/Vat/FrobLiveSuccess.lean | 38 ++--- Benchmarks/Dss/Vat/Grab.lean | 78 ++++----- Benchmarks/Dss/Vat/Move.lean | 4 +- Benchmarks/Dss/Vat/Suck.lean | 104 ++++++------ Benchmarks/Dss/Vow/CageHealRuntime.lean | 4 +- Benchmarks/Dss/Vow/CageRuntime.lean | 52 +++--- Benchmarks/Dss/Vow/CageTailRuntime.lean | 20 +-- Benchmarks/Dss/Vow/FileAddress.lean | 4 +- Benchmarks/Dss/Vow/FileAddressFlapper.lean | 2 +- Benchmarks/Dss/Vow/FlapBody.lean | 6 +- Benchmarks/Dss/Vow/FlapDaiBody.lean | 6 +- Benchmarks/Dss/Vow/FlapKickBody.lean | 8 +- Benchmarks/Dss/Vow/FlapSin1Body.lean | 6 +- Benchmarks/Dss/Vow/FlapSubBody.lean | 6 +- 51 files changed, 536 insertions(+), 536 deletions(-) diff --git a/Benchmarks/Dss/Cat/FileAddress.lean b/Benchmarks/Dss/Cat/FileAddress.lean index f904c540..453610cf 100644 --- a/Benchmarks/Dss/Cat/FileAddress.lean +++ b/Benchmarks/Dss/Cat/FileAddress.lean @@ -566,7 +566,7 @@ theorem RD.catFileAddressStoreVow {g : Sat256} {s0 : State} {ee : ExecutionEnv} have rd3206 := rd3205.sub (by native_decide) (by evm_ov) have rd3207 := rd3206.dup4 (by native_decide) (by evm_ov) have rd3208 := rd3207.and (by native_decide) (by evm_ov) - have rd3209 := rd3208.lor (by native_decide) (by evm_ov) + have rd3209 := rd3208.or (by native_decide) (by evm_ov) rw [show UInt256.sub (UInt256.shiftLeft (⟨1⟩ : UInt256) ⟨160⟩) ⟨1⟩ = solcAddrMask from by decide] at rd3209 rw [setAddressOffset0Word_bytecode] at rd3209 diff --git a/Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean b/Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean index 422d9db1..a40e33aa 100644 --- a/Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean +++ b/Benchmarks/Dss/Cat/FileIlkFlipCalls2.lean @@ -317,7 +317,7 @@ theorem RD.catFileIlkFlipStore {g : Sat256} {s0 : State} {ee : ExecutionEnv} {k have rd3619 := rd3618.and (by native_decide) (by evm_ov) have rd3620 := rd3619.swap2 (by native_decide) (by evm_ov) have rd3621 := rd3620.dup3 (by native_decide) (by evm_ov) - have rd3622 := rd3621.lor (by native_decide) (by evm_ov) + have rd3622 := rd3621.or (by native_decide) (by evm_ov) rw [u256_land_comm solcAddrMask flip, setAddressOffset0Word_bytecode] at rd3622 have rd3623 := rd3622.swap1 (by native_decide) (by evm_ov) have rd3624 := rd3623.swap3 (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Cure/LoadSource.lean b/Benchmarks/Dss/Cure/LoadSource.lean index c3d1bbe4..4b023af2 100644 --- a/Benchmarks/Dss/Cure/LoadSource.lean +++ b/Benchmarks/Dss/Cure/LoadSource.lean @@ -137,7 +137,7 @@ theorem cureLoadSourceBodyNoCodeRevert {cA gh bl σ σ₀ A I} {g : UInt256} .assign .storage lCountRef (incUnchecked (.storage lCountRef)) ] [] ]) .reverted := by - exact.execBlock_append_term hcall (by intro f e h; cases h) + exact execBlock_append_term hcall (by intro f e h; cases h) have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -232,7 +232,7 @@ theorem cureLoadSourceBodyCallFailureRevert {cA gh bl σ σ₀ A I} {g : UInt256 .assign .storage lCountRef (incUnchecked (.storage lCountRef)) ] [] ]) .reverted := by - exact.execBlock_append_term hcallBlock (by intro f e h; cases h) + exact execBlock_append_term hcallBlock (by intro f e h; cases h) have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -330,7 +330,7 @@ theorem cureLoadSourceBodyReturnDecodeRevert {cA gh bl σ σ₀ A I} {g : UInt25 .assign .storage lCountRef (incUnchecked (.storage lCountRef)) ] [] ]) .reverted := by - exact.execBlock_append_term hcallBlock (by intro f e h; cases h) + exact execBlock_append_term hcallBlock (by intro f e h; cases h) have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -550,7 +550,7 @@ theorem cureLoadSourceBodySubRevert {cA gh bl σ σ₀ A I} {g : UInt256} .reverted := by refine ExecBlock.consNormal (ExecStmt.assign hnewVar hassignAmt) ?_ exact ExecBlock.consRevert hsubStmt - exact.execBlock_append hcallBlock hrest + exact execBlock_append hcallBlock hrest have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -829,7 +829,7 @@ theorem cureLoadSourceBodyAddRevert {cA gh bl σ σ₀ A I} {g : UInt256} refine ExecBlock.consNormal (ExecStmt.assign hnewVar hassignAmt) ?_ refine ExecBlock.consNormal hsubStmt ?_ exact ExecBlock.consRevert haddStmt - exact.execBlock_append hcallBlock hrest + exact execBlock_append hcallBlock hrest have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -1161,7 +1161,7 @@ theorem cureLoadSourceBodyOkLoadedNonzero {cA gh bl σ σ₀ A I} {g : UInt256} refine ExecBlock.consNormal haddStmt ?_ refine ExecBlock.consNormal (ExecStmt.assign hsayNewVar hassignSay) ?_ exact ExecBlock.consNormal (ExecStmt.iteFalse hcond ExecBlock.nil) ExecBlock.nil - exact.execBlock_append hcallBlock hrest + exact execBlock_append hcallBlock hrest have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -1511,7 +1511,7 @@ theorem cureLoadSourceBodyOkLoadedZero {cA gh bl σ σ₀ A I} {g : UInt256} refine ExecBlock.consNormal haddStmt ?_ refine ExecBlock.consNormal (ExecStmt.assign hsayNewVar hassignSay) ?_ exact ExecBlock.consNormal htail ExecBlock.nil - exact.execBlock_append hcallBlock hrest + exact execBlock_append hcallBlock hrest have hblock : ExecBlock config { contract := contract, locals := loadLocals I } evm0 (.require (.binary .eq (.env .callvalue) (.intLit 0)) :: diff --git a/Benchmarks/Dss/End/Cage.lean b/Benchmarks/Dss/End/Cage.lean index b6eb10c3..4d09576a 100644 --- a/Benchmarks/Dss/End/Cage.lean +++ b/Benchmarks/Dss/End/Cage.lean @@ -3125,7 +3125,7 @@ theorem endCageExecBlock_append_revert {f f1 : Frame} {e e1 : EVM.State} ExecBlock config f e (s1 ++ s2 ++ tail) .reverted := by have h2tail : ExecBlock config f1 e1 (s2 ++ tail) .reverted := - .execBlock_append_term + execBlock_append_term (s2 := tail) h2 (by intro f' e' h; cases h) simpa [List.append_assoc] using execBlock_append (s2 := s2 ++ tail) h1 h2tail diff --git a/Benchmarks/Dss/End/CageIlk.lean b/Benchmarks/Dss/End/CageIlk.lean index 9afd7090..ad2c3c90 100644 --- a/Benchmarks/Dss/End/CageIlk.lean +++ b/Benchmarks/Dss/End/CageIlk.lean @@ -4925,7 +4925,7 @@ theorem endCageIlkBodyReverts_vatIlksTerminated {cA gh bl σ σ₀ A I} {g : UIn · exact evalCallvalueEq_true (by simp only [evm0, initState]; exact hwv) refine ExecBlock.consNormal (ExecStmt.requireTrue hguardLive) ?_ refine ExecBlock.consNormal (ExecStmt.requireTrue hguardTag) ?_ - exact.execBlock_append_term + exact execBlock_append_term (s1 := checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] "vatIlk") (s2 := @@ -5041,7 +5041,7 @@ theorem endCageIlkTailFromVatReverts_spotTerminated (evmVat : EVM.State) "spotIlk" (perm := false)) .reverted := by simpa [evmArt] using hspot refine ExecBlock.consNormal (endCageIlkStmtArt evmVat I vatOut hsz36) ?_ - exact.execBlock_append_term + exact execBlock_append_term (s1 := checkedExternalCallStmts (.storage spotRef) "spotIlks" (.intLit 0) [.var "ilk"] "spotIlk" (perm := false)) (s2 := @@ -5170,7 +5170,7 @@ theorem endCageIlkTailAfterSpotReverts_parTerminated {evmSpot : EVM.State} [ .internalCall "wdiv" [.var "parV", .cast (.var "pipRead") uint256St] "tagV", .assign .storage (tagRef (.var "ilk")) (.var "tagV") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s1 := checkedExternalCallStmts (.storage spotRef) "par" (.intLit 0) [] "parV" (perm := false)) (s2 := @@ -5258,7 +5258,7 @@ theorem endCageIlkTailAfterParReverts_readTerminated {evmPar : EVM.State} [ .internalCall "wdiv" [.var "parV", .cast (.var "pipRead") uint256St] "tagV", .assign .storage (tagRef (.var "ilk")) (.var "tagV") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s1 := checkedExternalCallStmts (.var "pip") "read" (.intLit 0) [] "pipRead" (perm := false)) (s2 := @@ -5349,7 +5349,7 @@ theorem endCageIlkTailAfterParReadOk {evmPar evmRead : EVM.State} (evm := evmPar) (evm' := evmRead) (I := I) (vatOut := vatOut) (spotOut := spotOut) (parOut := parOut) (readOut := readOut) hcodeSize hcall hlo - exact.execBlock_append hread htail + exact execBlock_append hread htail theorem endCageIlkTailAfterSpotParOk {evmSpot evmPar : EVM.State} {I : ExecutionEnv} {vatOut spotOut parOut : ByteArray} @@ -5385,7 +5385,7 @@ theorem endCageIlkTailAfterSpotParOk {evmSpot evmPar : EVM.State} endCageIlkCheckedParSuccess (evm := evmSpot) (evm' := evmPar) (I := I) (vatOut := vatOut) (spotOut := spotOut) (parOut := parOut) hcodeSize hcall hlo - have happ :=.execBlock_append + have happ := execBlock_append (s2 := checkedExternalCallStmts (.var "pip") "read" (.intLit 0) [] "pipRead" (perm := false) ++ @@ -5461,7 +5461,7 @@ theorem endCageIlkTailFromVatSpotOk {evmVat evmSpot : EVM.State} "spotIlk" (perm := false) ++ [ .letDecl "pip" (some addr) (.tupleGet (.var "spotIlk") 0) ]) (.ok { contract := contract, locals := endCageIlkStorePip I vatOut spotOut } evmSpot) := by - exact.execBlock_append hspot hpip + exact execBlock_append hspot hpip have hrest : ExecBlock config { contract := contract, locals := endCageIlkStoreVatIlk I vatOut } evmArt @@ -5475,7 +5475,7 @@ theorem endCageIlkTailFromVatSpotOk {evmVat evmSpot : EVM.State} [ .internalCall "wdiv" [.var "parV", .cast (.var "pipRead") uint256St] "tagV", .assign .storage (tagRef (.var "ilk")) (.var "tagV") ]) res := by - have happ :=.execBlock_append + have happ := execBlock_append (s2 := checkedExternalCallStmts (.storage spotRef) "par" (.intLit 0) [] "parV" (perm := false) ++ @@ -5588,7 +5588,7 @@ theorem endCageIlkBodyReverts_vatIlksOkTailReverted {cA gh bl σ σ₀ A I} have hblock : ExecBlock config { contract := contract, locals := endCageIlkStore I } evm0 cageIlkTransition.body .reverted := by - have happ :=.execBlock_append + have happ := execBlock_append (s2 := [ .assign .storage (ArtRef (.var "ilk")) (.tupleGet (.var "vatIlk") 0) ] ++ checkedExternalCallStmts (.storage spotRef) "spotIlks" (.intLit 0) [.var "ilk"] @@ -5650,7 +5650,7 @@ theorem endCageIlkBodyReturns_vatIlksOkTail {cA gh bl σ σ₀ A I} have hblock : ExecBlock config { contract := contract, locals := endCageIlkStore I } evm0 cageIlkTransition.body (.ok fPost evmPost) := by - have happ :=.execBlock_append + have happ := execBlock_append (s2 := [ .assign .storage (ArtRef (.var "ilk")) (.tupleGet (.var "vatIlk") 0) ] ++ checkedExternalCallStmts (.storage spotRef) "spotIlks" (.intLit 0) [.var "ilk"] diff --git a/Benchmarks/Dss/End/Cash.lean b/Benchmarks/Dss/End/Cash.lean index 910d7065..08632b11 100644 --- a/Benchmarks/Dss/End/Cash.lean +++ b/Benchmarks/Dss/End/Cash.lean @@ -2834,7 +2834,7 @@ theorem endCashBodyReverts_fluxNoCode {cA gh bl σ σ₀ A I} {g : UInt256} .require (.binary .le (.var "outNew") (.storage (bagRef sender))) ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .internalCall "add" [.storage (outRef (.var "ilk") sender), .var "wad"] "outNew", .assign .storage (outRef (.var "ilk") sender) (.var "outNew"), @@ -2962,7 +2962,7 @@ theorem endCashBodyReverts_fluxCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} .require (.binary .le (.var "outNew") (.storage (bagRef sender))) ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .internalCall "add" [.storage (outRef (.var "ilk") sender), .var "wad"] "outNew", .assign .storage (outRef (.var "ilk") sender) (.var "outNew"), @@ -3325,7 +3325,7 @@ theorem endCashTailReverts_outExceedsBag (evm : EVM.State) (I : ExecutionEnv) (.binary .le (.var "outNew") (.storage (bagRef sender))) ] .reverted := ExecBlock.consRevert (ExecStmt.requireFalse hreq) - have happ :=.execBlock_append + have happ := execBlock_append (s2 := [ .require (.binary .le (.var "outNew") (.storage (bagRef sender))) ]) hprefix htail @@ -3390,7 +3390,7 @@ theorem endCashTailReturns (evm : EVM.State) (I : ExecutionEnv) (.binary .le (.var "outNew") (.storage (bagRef sender))) ] (.ok { contract := contract, locals := endCashStoreOutNew σ I outNew } evmPost) := ExecBlock.consNormal (ExecStmt.requireTrue hreq) ExecBlock.nil - have happ :=.execBlock_append + have happ := execBlock_append (s2 := [ .require (.binary .le (.var "outNew") (.storage (bagRef sender))) ]) hprefix htail @@ -3560,7 +3560,7 @@ theorem endCashBodyReverts_outAddOverflow {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endCashStore I } evm0 cashTransition.body .reverted := by - have happ :=.execBlock_append + have happ := execBlock_append (s2 := [ .internalCall "add" [.storage (outRef (.var "ilk") sender), .var "wad"] "outNew", .assign .storage (outRef (.var "ilk") sender) (.var "outNew"), @@ -3614,7 +3614,7 @@ theorem endCashBodyReverts_outExceedsBag {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endCashStore I } evm0 cashTransition.body .reverted := by - have happ :=.execBlock_append + have happ := execBlock_append (s2 := [ .internalCall "add" [.storage (outRef (.var "ilk") sender), .var "wad"] "outNew", .assign .storage (outRef (.var "ilk") sender) (.var "outNew"), @@ -3674,7 +3674,7 @@ theorem endCashBodyReturns {cA gh bl σ σ₀ A I} {g : UInt256} cashTransition.body (.ok { contract := contract, locals := endCashStoreOutNew σ I outNew } (endCashPostState evmFlux I outNew)) := by - have happ :=.execBlock_append + have happ := execBlock_append (s2 := [ .internalCall "add" [.storage (outRef (.var "ilk") sender), .var "wad"] "outNew", .assign .storage (outRef (.var "ilk") sender) (.var "outNew"), diff --git a/Benchmarks/Dss/End/FileAddress.lean b/Benchmarks/Dss/End/FileAddress.lean index c9b84542..7c18aebf 100644 --- a/Benchmarks/Dss/End/FileAddress.lean +++ b/Benchmarks/Dss/End/FileAddress.lean @@ -831,7 +831,7 @@ theorem RD.endFileAddressStoreVat {g : Sat256} {s0 : State} {ee : ExecutionEnv} have rd8464 := rd8463.sub (by native_decide) (by evm_ov) have rd8465 := rd8464.dup4 (by native_decide) (by evm_ov) have rd8466 := rd8465.and (by native_decide) (by evm_ov) - have rd8467 := rd8466.lor (by native_decide) (by evm_ov) + have rd8467 := rd8466.or (by native_decide) (by evm_ov) have rd8468 := rd8467.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd8469⟩ := rd8468.sstore hperm (by native_decide) (by evm_ov) have rd8472 := rd8469.push2 endFileAddressEventPc (by native_decide) (by evm_ov) @@ -942,7 +942,7 @@ theorem RD.endFileAddressStoreCat {g : Sat256} {s0 : State} {ee : ExecutionEnv} have rd := rd.sub (by native_decide) (by evm_ov) have rd := rd.dup4 (by native_decide) (by evm_ov) have rd := rd.and (by native_decide) (by evm_ov) - have rd := rd.lor (by native_decide) (by evm_ov) + have rd := rd.or (by native_decide) (by evm_ov) have rd := rd.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd⟩ := rd.sstore hperm (by native_decide) (by evm_ov) have rd := rd.push2 endFileAddressEventPc (by native_decide) (by evm_ov) @@ -1023,7 +1023,7 @@ theorem RD.endFileAddressStoreDog {g : Sat256} {s0 : State} {ee : ExecutionEnv} have rd := rd.sub (by native_decide) (by evm_ov) have rd := rd.dup4 (by native_decide) (by evm_ov) have rd := rd.and (by native_decide) (by evm_ov) - have rd := rd.lor (by native_decide) (by evm_ov) + have rd := rd.or (by native_decide) (by evm_ov) have rd := rd.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd⟩ := rd.sstore hperm (by native_decide) (by evm_ov) have rd := rd.push2 endFileAddressEventPc (by native_decide) (by evm_ov) @@ -1104,7 +1104,7 @@ theorem RD.endFileAddressStoreVow {g : Sat256} {s0 : State} {ee : ExecutionEnv} have rd := rd.sub (by native_decide) (by evm_ov) have rd := rd.dup4 (by native_decide) (by evm_ov) have rd := rd.and (by native_decide) (by evm_ov) - have rd := rd.lor (by native_decide) (by evm_ov) + have rd := rd.or (by native_decide) (by evm_ov) have rd := rd.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd⟩ := rd.sstore hperm (by native_decide) (by evm_ov) have rd := rd.push2 endFileAddressEventPc (by native_decide) (by evm_ov) @@ -1185,7 +1185,7 @@ theorem RD.endFileAddressStorePot {g : Sat256} {s0 : State} {ee : ExecutionEnv} have rd := rd.sub (by native_decide) (by evm_ov) have rd := rd.dup4 (by native_decide) (by evm_ov) have rd := rd.and (by native_decide) (by evm_ov) - have rd := rd.lor (by native_decide) (by evm_ov) + have rd := rd.or (by native_decide) (by evm_ov) have rd := rd.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd⟩ := rd.sstore hperm (by native_decide) (by evm_ov) have rd := rd.push2 endFileAddressEventPc (by native_decide) (by evm_ov) @@ -1266,7 +1266,7 @@ theorem RD.endFileAddressStoreSpot {g : Sat256} {s0 : State} {ee : ExecutionEnv} have rd := rd.sub (by native_decide) (by evm_ov) have rd := rd.dup4 (by native_decide) (by evm_ov) have rd := rd.and (by native_decide) (by evm_ov) - have rd := rd.lor (by native_decide) (by evm_ov) + have rd := rd.or (by native_decide) (by evm_ov) have rd := rd.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd⟩ := rd.sstore hperm (by native_decide) (by evm_ov) have rd := rd.push2 endFileAddressEventPc (by native_decide) (by evm_ov) @@ -1347,7 +1347,7 @@ theorem RD.endFileAddressStoreCure {g : Sat256} {s0 : State} {ee : ExecutionEnv} have rd := rd.sub (by native_decide) (by evm_ov) have rd := rd.dup4 (by native_decide) (by evm_ov) have rd := rd.and (by native_decide) (by evm_ov) - have rd := rd.lor (by native_decide) (by evm_ov) + have rd := rd.or (by native_decide) (by evm_ov) have rd := rd.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd⟩ := rd.sstore hperm (by native_decide) (by evm_ov) have hword := endFileAddressStoreWord_eq (solcSlotWord σ ee ⟨7⟩) data diff --git a/Benchmarks/Dss/End/Flow.lean b/Benchmarks/Dss/End/Flow.lean index a83fba6c..c071955e 100644 --- a/Benchmarks/Dss/End/Flow.lean +++ b/Benchmarks/Dss/End/Flow.lean @@ -4015,7 +4015,7 @@ theorem endFlowBodyReverts_vatIlksBlock {cA gh bl σ σ₀ A I} {g : UInt256} .letDecl "fixV" (some uint256) (.binary .div (.var "num") (.var "den")), .assign .storage (fixRef (.var "ilk")) (.var "fixV") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1), .internalCall "rmul" [.storage (ArtRef (.var "ilk")), .var "rate"] "wad0", @@ -4206,7 +4206,7 @@ theorem endFlowBodyReverts_vatIlksOkTailReverted {cA gh bl σ σ₀ A I} {g : UI have hblock : ExecBlock config { contract := contract, locals := endFlowStore I } evm0 flowTransition.body .reverted := by - have happ :=.execBlock_append + have happ := execBlock_append (s2 := [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1), .internalCall "rmul" [.storage (ArtRef (.var "ilk")), .var "rate"] "wad0", @@ -4264,7 +4264,7 @@ theorem endFlowBodyReturns_vatIlksOkTail {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endFlowStore I } evm0 flowTransition.body (.ok fPost evmPost) := by - have happ :=.execBlock_append + have happ := execBlock_append (s2 := [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1), .internalCall "rmul" [.storage (ArtRef (.var "ilk")), .var "rate"] "wad0", @@ -4336,7 +4336,7 @@ theorem endFlowBodyReturns {cA gh bl σ σ₀ A I} {g : UInt256} flowTransition.body (.ok { contract := contract, locals := endFlowStoreFixV σ I out } (endFlowPostState evmVat I (endFlowFixVWord σ I out))) := by - have happ :=.execBlock_append + have happ := execBlock_append (s2 := [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1), .internalCall "rmul" [.storage (ArtRef (.var "ilk")), .var "rate"] "wad0", diff --git a/Benchmarks/Dss/End/Free.lean b/Benchmarks/Dss/End/Free.lean index 88a77cb3..37665f6c 100644 --- a/Benchmarks/Dss/End/Free.lean +++ b/Benchmarks/Dss/End/Free.lean @@ -1364,7 +1364,7 @@ theorem endFreeBodyReverts_urnsNoCode {cA gh bl σ σ₀ A I} {g : UInt256} have hurnsWithTail : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 (endFreeUrnsCallStmts ++ endFreeAfterUrnsStmts) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := endFreeAfterUrnsStmts) hurnsBlock (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 @@ -1438,7 +1438,7 @@ theorem endFreeBodyReverts_urnsCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} have hurnsWithTail : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 (endFreeUrnsCallStmts ++ endFreeAfterUrnsStmts) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := endFreeAfterUrnsStmts) hurnsBlock (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 @@ -1514,7 +1514,7 @@ theorem endFreeBodyReverts_urnsDecodeShort {cA gh bl σ σ₀ A I} {g : UInt256} have hurnsWithTail : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 (endFreeUrnsCallStmts ++ endFreeAfterUrnsStmts) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := endFreeAfterUrnsStmts) hurnsBlock (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 @@ -2121,7 +2121,7 @@ theorem endFreeBodyReverts_artNonzero {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 freeTransition.body .reverted := by - have hseq :=.execBlock_append + have hseq := execBlock_append (s2 := endFreeAfterUrnsStmts) hprefix htail simpa [freeTransition, nonpayable, endFreeUrnsCallStmts, endFreeAfterUrnsStmts, checkedExternalCallStmts, List.cons_append, List.nil_append, List.append_assoc] using hseq @@ -2160,7 +2160,7 @@ theorem endFreeBodyReverts_inkOverflow {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 freeTransition.body .reverted := by - have hseq :=.execBlock_append + have hseq := execBlock_append (s2 := endFreeAfterUrnsStmts) hprefix htail simpa [freeTransition, nonpayable, endFreeUrnsCallStmts, endFreeAfterUrnsStmts, checkedExternalCallStmts, List.cons_append, List.nil_append, List.append_assoc] using hseq @@ -2204,7 +2204,7 @@ theorem endFreeBodyReverts_grabNoCode {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 freeTransition.body .reverted := by - have hseq :=.execBlock_append + have hseq := execBlock_append (s2 := endFreeAfterUrnsStmts) hprefix htail simpa [freeTransition, nonpayable, endFreeUrnsCallStmts, endFreeAfterUrnsStmts, checkedExternalCallStmts, List.cons_append, List.nil_append, List.append_assoc] using hseq @@ -2260,7 +2260,7 @@ theorem endFreeBodyReverts_grabCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endFreeStore I } evm0 freeTransition.body .reverted := by - have hseq :=.execBlock_append + have hseq := execBlock_append (s2 := endFreeAfterUrnsStmts) hprefix htail simpa [freeTransition, nonpayable, endFreeUrnsCallStmts, endFreeAfterUrnsStmts, checkedExternalCallStmts, List.cons_append, List.nil_append, List.append_assoc] using hseq @@ -2318,7 +2318,7 @@ theorem endFreeBodyReturns_grabSuccess {cA gh bl σ σ₀ A I} {g : UInt256} ExecBlock config { contract := contract, locals := endFreeStore I } evm0 freeTransition.body (.ok { contract := contract, locals := endFreeStoreGrab I out } evmGrab) := by - have hseq :=.execBlock_append + have hseq := execBlock_append (s2 := endFreeAfterUrnsStmts) hprefix htail simpa [freeTransition, nonpayable, endFreeUrnsCallStmts, endFreeAfterUrnsStmts, checkedExternalCallStmts, List.cons_append, List.nil_append, List.append_assoc] using hseq diff --git a/Benchmarks/Dss/End/Pack.lean b/Benchmarks/Dss/End/Pack.lean index 3ce0133d..4071329e 100644 --- a/Benchmarks/Dss/End/Pack.lean +++ b/Benchmarks/Dss/End/Pack.lean @@ -1977,7 +1977,7 @@ theorem endPackBodyReverts_moveNoCode {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "add" [.storage (bagRef sender), .var "wad"] "bagNew", .assign .storage (bagRef sender) (.var "bagNew") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .internalCall "add" [.storage (bagRef sender), .var "wad"] "bagNew", .assign .storage (bagRef sender) (.var "bagNew") ]) @@ -2127,7 +2127,7 @@ theorem endPackBodyReverts_moveCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "add" [.storage (bagRef sender), .var "wad"] "bagNew", .assign .storage (bagRef sender) (.var "bagNew") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .internalCall "add" [.storage (bagRef sender), .var "wad"] "bagNew", .assign .storage (bagRef sender) (.var "bagNew") ]) @@ -2333,7 +2333,7 @@ theorem endPackBodyReverts_bagAddOverflow {cA gh bl σ σ₀ A I} {g : UInt256} have hblock : ExecBlock config { contract := contract, locals := endPackStore I } evm0 packTransition.body .reverted := by - have happ :=.execBlock_append + have happ := execBlock_append (s2 := [ .internalCall "add" [.storage (bagRef sender), .var "wad"] "bagNew", .assign .storage (bagRef sender) (.var "bagNew") ]) @@ -2394,7 +2394,7 @@ theorem endPackBodyReturns {cA gh bl σ σ₀ A I} {g : UInt256} packTransition.body (.ok { contract := contract, locals := endPackStoreBagNew I bagNew } (endPackPostState evmMove I bagNew)) := by - have happ :=.execBlock_append + have happ := execBlock_append (s2 := [ .internalCall "add" [.storage (bagRef sender), .var "wad"] "bagNew", .assign .storage (bagRef sender) (.var "bagNew") ]) diff --git a/Benchmarks/Dss/End/Skim.lean b/Benchmarks/Dss/End/Skim.lean index 0cbb92de..dad48b8b 100644 --- a/Benchmarks/Dss/End/Skim.lean +++ b/Benchmarks/Dss/End/Skim.lean @@ -6538,11 +6538,11 @@ theorem endSkimBodyReverts_afterArtTailReverted {I} {vatOut urnOut : ByteArray} (.binary .le (.var "wad") (.intLit int256Limit)) (.binary .le (.var "art") (.intLit int256Limit))) ] ++ grabTail) .reverted := by - exact.execBlock_append_term htail (by intro f' e' h; cases h) + exact execBlock_append_term htail (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSkimStore I } evm0 skimTransition.body .reverted := by - have hseq :=.execBlock_append hprefixArt htailWithGrab + have hseq := execBlock_append hprefixArt htailWithGrab simpa [skimTransition, grabTail, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -6606,11 +6606,11 @@ theorem endSkimBodyReverts_afterArtTailGrabReverted {I σLoc} (.binary .le (.var "wad") (.intLit int256Limit)) (.binary .le (.var "art") (.intLit int256Limit))) ] ++ grabTail) .reverted := by - exact.execBlock_append htail hgrab + exact execBlock_append htail hgrab have hblock : ExecBlock config { contract := contract, locals := endSkimStore I } evm0 skimTransition.body .reverted := by - have hseq :=.execBlock_append hprefixArt htailWithGrab + have hseq := execBlock_append hprefixArt htailWithGrab simpa [skimTransition, grabTail, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -6677,13 +6677,13 @@ theorem endSkimBodyReturns_afterArtTailGrabSuccess {I σLoc} (.binary .le (.var "art") (.intLit int256Limit))) ] ++ grabTail) (.ok { contract := contract, locals := endSkimStoreGrab σLoc I vatOut urnOut } evmGrab) := by - exact.execBlock_append htail hgrab + exact execBlock_append htail hgrab have hblock : ExecBlock config { contract := contract, locals := endSkimStore I } evm0 skimTransition.body (.ok { contract := contract, locals := endSkimStoreGrab σLoc I vatOut urnOut } evmGrab) := by - have hseq :=.execBlock_append hprefixArt htailWithGrab + have hseq := execBlock_append hprefixArt htailWithGrab simpa [skimTransition, grabTail, List.append_assoc] using hseq exact ExecFuncBody.execBlockOK hblock @@ -6737,7 +6737,7 @@ theorem endSkimBodyReverts_vatIlksBlock {cA gh bl σ σ₀ A I} {g : UInt256} .unary .neg (asInt256 (.var "wad")), .unary .neg (asInt256 (.var "art"))] "_grab") .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1) ] ++ checkedExternalCallStmts (.storage vatRef) "urns" (.intLit 0) @@ -6887,7 +6887,7 @@ theorem endSkimPrefixRateSuccess {cA gh bl σ σ₀ A I} {g : UInt256} "vatIlk" ++ [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1) ]) (.ok { contract := contract, locals := endSkimStoreRate I out } evmVat) := by - exact.execBlock_append hvat hrate + exact execBlock_append hvat hrate simp only [nonpayable, List.cons_append, List.nil_append] refine ExecBlock.consNormal (ExecStmt.requireTrue ?_) ?_ · exact evalCallvalueEq_true (by simp [evm0, initState]; exact hwv) @@ -6930,12 +6930,12 @@ theorem endSkimBodyReverts_afterRateUrnsBlock {I} {vatOut : ByteArray} ExecBlock config { contract := contract, locals := endSkimStoreRate I vatOut } evmRate (checkedExternalCallStmts (.storage vatRef) "urns" (.intLit 0) [.var "ilk", .var "urn"] "vatUrn" ++ afterUrns) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := afterUrns) hurns (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSkimStore I } evm0 skimTransition.body .reverted := by - have hseq :=.execBlock_append hprefix hurnsWithTail + have hseq := execBlock_append hprefix hurnsWithTail simpa [skimTransition, afterUrns, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -7429,7 +7429,7 @@ theorem endSkimBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} locals := endSkimStoreArt I vatOut urnOut } evmUrnsSolm) := by have hurnsInkArt := - .execBlock_append hurnsBlock hinkArt + execBlock_append hurnsBlock hinkArt simpa [List.append_assoc] using execBlock_append hprefix hurnsInkArt have hTagCoupleUrns : diff --git a/Benchmarks/Dss/End/Skip.lean b/Benchmarks/Dss/End/Skip.lean index 34e27555..e9b7fa5e 100644 --- a/Benchmarks/Dss/End/Skip.lean +++ b/Benchmarks/Dss/End/Skip.lean @@ -7620,7 +7620,7 @@ theorem endSkipBodyReverts_catIlksBlock {cA gh bl σ σ₀ A I} {g : UInt256} [.var "ilk", .var "usr", thisAddr, vowAddr, asInt256 (.var "lot"), asInt256 (.var "art")] "_grab") .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .letDecl "flip" (some addr) (.tupleGet (.var "catIlk") 0) ] ++ checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] @@ -7778,7 +7778,7 @@ theorem endSkipPrefixFlipSuccess {cA gh bl σ σ₀ A I} {g : UInt256} "catIlk" ++ [ .letDecl "flip" (some addr) (.tupleGet (.var "catIlk") 0) ]) (.ok { contract := contract, locals := endSkipStoreFlip I out } evmCat) := by - exact.execBlock_append hcat hflip + exact execBlock_append hcat hflip simp only [nonpayable, List.cons_append, List.nil_append] refine ExecBlock.consNormal (ExecStmt.requireTrue ?_) ?_ · exact evalCallvalueEq_true (by simp [evm0, initState]; exact hwv) @@ -8031,8 +8031,8 @@ theorem endSkipPrefixRateSuccess {I} {catOut vatOut : ByteArray} [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1) ]) (.ok { contract := contract, locals := endSkipStoreRate I catOut vatOut } evmVat) := by - exact.execBlock_append hvat hrate - have hseq :=.execBlock_append hprefix hvatRate + exact execBlock_append hvat hrate + have hseq := execBlock_append hprefix hvatRate simpa [List.append_assoc] using hseq theorem endSkipBodyReverts_afterFlipVatIlksBlock {I} {catOut : ByteArray} @@ -8078,12 +8078,12 @@ theorem endSkipBodyReverts_afterFlipVatIlksBlock {I} {catOut : ByteArray} ExecBlock config { contract := contract, locals := endSkipStoreFlip I catOut } evmCat (checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] "vatIlk" ++ afterVat) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := afterVat) hvat (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSkipStore I } evm0 skipTransition.body .reverted := by - have hseq :=.execBlock_append hprefix hvatWithTail + have hseq := execBlock_append hprefix hvatWithTail simpa [skipTransition, afterVat, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -8512,8 +8512,8 @@ theorem endSkipPrefixTabSuccess {I} {catOut vatOut bidOut : ByteArray} .letDecl "tab" (some uint256) (.tupleGet (.var "flipBid") 7) ]) (.ok { contract := contract, locals := endSkipStoreTab I catOut vatOut bidOut } evmBids) := by - exact.execBlock_append hbids hlets - have hseq :=.execBlock_append hprefix hbidsLets + exact execBlock_append hbids hlets + have hseq := execBlock_append hprefix hbidsLets simpa [List.append_assoc] using hseq theorem endSkipBodyReverts_afterRateBidsBlock {I} {catOut vatOut : ByteArray} @@ -8561,12 +8561,12 @@ theorem endSkipBodyReverts_afterRateBidsBlock {I} {catOut vatOut : ByteArray} evmVat (checkedExternalCallStmts (.var "flip") "bids" (.intLit 0) [.var "id"] "flipBid" (perm := false) ++ afterBids) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := afterBids) hbids (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSkipStore I } evm0 skipTransition.body .reverted := by - have hseq :=.execBlock_append hprefix hbidsWithTail + have hseq := execBlock_append hprefix hbidsWithTail simpa [skipTransition, afterBids, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -9911,9 +9911,9 @@ theorem endSkipTailAfterTabReturns {I σLoc} (endSkipPostArtState evmYank I (endSkipArtNewWord σLoc I vatOut bidOut)) I σLoc catOut vatOut bidOut hlot hart)) ExecBlock.nil - have htail2 :=.execBlock_append hsuck1 hsuck2 - have htail3 :=.execBlock_append htail2 hhope - have htail4 :=.execBlock_append htail3 hyank + have htail2 := execBlock_append hsuck1 hsuck2 + have htail3 := execBlock_append htail2 hhope + have htail4 := execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using execBlock_append htail4 hartBlock @@ -9981,7 +9981,7 @@ theorem endSkipTailReverts_hope {I} {catOut vatOut bidOut : ByteArray} (Reasoning.Theory.execBlock_append_term (s2 := endSkipYankStmts ++ endSkipArtStmts) hhope (by intro f' e' h; cases h)) - have htail2 :=.execBlock_append hsuck1 hsuck2 + have htail2 := execBlock_append hsuck1 hsuck2 simpa [endSkipTailNoGrabStmts, List.append_assoc] using execBlock_append htail2 hhopeTail @@ -10014,9 +10014,9 @@ theorem endSkipTailReverts_yank {I} {catOut vatOut bidOut : ByteArray} ExecBlock config { contract := contract, locals := endSkipStoreHope I catOut vatOut bidOut } evmHope (endSkipYankStmts ++ endSkipArtStmts) .reverted := by - exact.execBlock_append_term hyank (by intro f' e' h; cases h) - have htail2 :=.execBlock_append hsuck1 hsuck2 - have htail3 :=.execBlock_append htail2 hhope + exact execBlock_append_term hyank (by intro f' e' h; cases h) + have htail2 := execBlock_append hsuck1 hsuck2 + have htail3 := execBlock_append htail2 hhope simpa [endSkipTailNoGrabStmts, List.append_assoc] using execBlock_append htail3 hyankTail @@ -10052,9 +10052,9 @@ theorem endSkipTailReverts_artDivZero {I} {catOut vatOut bidOut : ByteArray} ExecBlock config { contract := contract, locals := endSkipStoreYank I catOut vatOut bidOut } evmYank endSkipArtStmts .reverted := ExecBlock.consRevert (endSkipStmtArtReverts evmYank I catOut vatOut bidOut hrate) - have htail2 :=.execBlock_append hsuck1 hsuck2 - have htail3 :=.execBlock_append htail2 hhope - have htail4 :=.execBlock_append htail3 hyank + have htail2 := execBlock_append hsuck1 hsuck2 + have htail3 := execBlock_append htail2 hhope + have htail4 := execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using execBlock_append htail4 hartRevert @@ -10100,9 +10100,9 @@ theorem endSkipTailReverts_artAddOverflow {I σLoc} refine ExecBlock.consNormal (endSkipStmtArt evmYank I catOut vatOut bidOut hrate) ?_ exact ExecBlock.consRevert (endSkipStmtArtNewAddReverts evmYank I σLoc catOut vatOut bidOut hsz68 hArtLoad hover) - have htail2 :=.execBlock_append hsuck1 hsuck2 - have htail3 :=.execBlock_append htail2 hhope - have htail4 :=.execBlock_append htail3 hyank + have htail2 := execBlock_append hsuck1 hsuck2 + have htail3 := execBlock_append htail2 hhope + have htail4 := execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using execBlock_append htail4 hartBlock @@ -10156,9 +10156,9 @@ theorem endSkipTailReverts_intGuardLot {I σLoc} (endSkipEvalExpr_intGuard_false_lot (endSkipPostArtState evmYank I (endSkipArtNewWord σLoc I vatOut bidOut)) I σLoc catOut vatOut bidOut hlot)) - have htail2 :=.execBlock_append hsuck1 hsuck2 - have htail3 :=.execBlock_append htail2 hhope - have htail4 :=.execBlock_append htail3 hyank + have htail2 := execBlock_append hsuck1 hsuck2 + have htail3 := execBlock_append htail2 hhope + have htail4 := execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using execBlock_append htail4 hartBlock @@ -10213,9 +10213,9 @@ theorem endSkipTailReverts_intGuardArt {I σLoc} (endSkipEvalExpr_intGuard_false_art (endSkipPostArtState evmYank I (endSkipArtNewWord σLoc I vatOut bidOut)) I σLoc catOut vatOut bidOut hlot hart)) - have htail2 :=.execBlock_append hsuck1 hsuck2 - have htail3 :=.execBlock_append htail2 hhope - have htail4 :=.execBlock_append htail3 hyank + have htail2 := execBlock_append hsuck1 hsuck2 + have htail3 := execBlock_append htail2 hhope + have htail4 := execBlock_append htail3 hyank simpa [endSkipTailNoGrabStmts, List.append_assoc] using execBlock_append htail4 hartBlock @@ -10246,11 +10246,11 @@ theorem endSkipBodyReverts_afterTabTailReverted {I} {catOut vatOut bidOut : Byte have htailWithGrab : ExecBlock config { contract := contract, locals := endSkipStoreTab I catOut vatOut bidOut } evmTab (endSkipTailNoGrabStmts ++ endSkipGrabStmts) .reverted := by - exact.execBlock_append_term htail (by intro f' e' h; cases h) + exact execBlock_append_term htail (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSkipStore I } evm0 skipTransition.body .reverted := by - have hseq :=.execBlock_append hprefixTab htailWithGrab + have hseq := execBlock_append hprefixTab htailWithGrab simpa [skipTransition, endSkipTailNoGrabStmts, endSkipGrabStmts, endSkipSuck1Stmts, endSkipSuck2Stmts, endSkipHopeStmts, endSkipYankStmts, endSkipArtStmts, List.append_assoc] using hseq @@ -10289,11 +10289,11 @@ theorem endSkipBodyReverts_afterTabTailGrabReverted {I σLoc} have htailWithGrab : ExecBlock config { contract := contract, locals := endSkipStoreTab I catOut vatOut bidOut } evmTab (endSkipTailNoGrabStmts ++ endSkipGrabStmts) .reverted := by - exact.execBlock_append htail hgrab + exact execBlock_append htail hgrab have hblock : ExecBlock config { contract := contract, locals := endSkipStore I } evm0 skipTransition.body .reverted := by - have hseq :=.execBlock_append hprefixTab htailWithGrab + have hseq := execBlock_append hprefixTab htailWithGrab simpa [skipTransition, endSkipTailNoGrabStmts, endSkipGrabStmts, endSkipSuck1Stmts, endSkipSuck2Stmts, endSkipHopeStmts, endSkipYankStmts, endSkipArtStmts, List.append_assoc] using hseq @@ -10339,13 +10339,13 @@ theorem endSkipBodyReturns_afterTabTailGrabSuccess {I σLoc} evmTab (endSkipTailNoGrabStmts ++ endSkipGrabStmts) (.ok { contract := contract, locals := endSkipStoreGrab σLoc I catOut vatOut bidOut } evmGrab) := by - exact.execBlock_append htail hgrab + exact execBlock_append htail hgrab have hblock : ExecBlock config { contract := contract, locals := endSkipStore I } evm0 skipTransition.body (.ok { contract := contract, locals := endSkipStoreGrab σLoc I catOut vatOut bidOut } evmGrab) := by - have hseq :=.execBlock_append hprefixTab htailWithGrab + have hseq := execBlock_append hprefixTab htailWithGrab simpa [skipTransition, endSkipTailNoGrabStmts, endSkipGrabStmts, endSkipSuck1Stmts, endSkipSuck2Stmts, endSkipHopeStmts, endSkipYankStmts, endSkipArtStmts, List.append_assoc] using hseq diff --git a/Benchmarks/Dss/End/Snip.lean b/Benchmarks/Dss/End/Snip.lean index b41ea59e..e2428dd2 100644 --- a/Benchmarks/Dss/End/Snip.lean +++ b/Benchmarks/Dss/End/Snip.lean @@ -6311,7 +6311,7 @@ theorem endSnipBodyReverts_dogIlksBlock {cA gh bl σ σ₀ A I} {g : UInt256} [.var "ilk", .var "usr", thisAddr, vowAddr, asInt256 (.var "lot"), asInt256 (.var "art")] "_grab") .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .letDecl "clip" (some addr) (.tupleGet (.var "dogIlk") 0) ] ++ checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] @@ -6464,7 +6464,7 @@ theorem endSnipPrefixClipSuccess {cA gh bl σ σ₀ A I} {g : UInt256} "dogIlk" ++ [ .letDecl "clip" (some addr) (.tupleGet (.var "dogIlk") 0) ]) (.ok { contract := contract, locals := endSnipStoreClip I out } evmDog) := by - exact.execBlock_append hdog hclip + exact execBlock_append hdog hclip simp only [nonpayable, List.cons_append, List.nil_append] refine ExecBlock.consNormal (ExecStmt.requireTrue ?_) ?_ · exact evalCallvalueEq_true (by simp [evm0, initState]; exact hwv) @@ -6715,8 +6715,8 @@ theorem endSnipPrefixRateSuccess {I} {dogOut vatOut : ByteArray} "vatIlk" ++ [ .letDecl "rate" (some uint256) (.tupleGet (.var "vatIlk") 1) ]) (.ok { contract := contract, locals := endSnipStoreRate I dogOut vatOut } evmVat) := by - exact.execBlock_append hvat hrate - have hseq :=.execBlock_append hprefix hvatRate + exact execBlock_append hvat hrate + have hseq := execBlock_append hprefix hvatRate simpa [List.append_assoc] using hseq theorem endSnipBodyReverts_afterClipVatIlksBlock {I} {dogOut : ByteArray} @@ -6758,12 +6758,12 @@ theorem endSnipBodyReverts_afterClipVatIlksBlock {I} {dogOut : ByteArray} ExecBlock config { contract := contract, locals := endSnipStoreClip I dogOut } evmDog (checkedExternalCallStmts (.storage vatRef) "vatIlks" (.intLit 0) [.var "ilk"] "vatIlk" ++ afterVat) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := afterVat) hvat (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSnipStore I } evm0 snipTransition.body .reverted := by - have hseq :=.execBlock_append hprefix hvatWithTail + have hseq := execBlock_append hprefix hvatWithTail simpa [snipTransition, afterVat, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -7146,7 +7146,7 @@ theorem endSnipPrefixUsrSuccess {I} {dogOut vatOut saleOut : ByteArray} .letDecl "usr" (some addr) (.tupleGet (.var "clipSale") 3) ] (.ok { contract := contract, locals := endSnipStoreUsr I dogOut vatOut saleOut } evmSales) := by - exact.execBlock_append htab + exact execBlock_append htab (Reasoning.Theory.execBlock_append hlot husr) have hsalesTail : ExecBlock config { contract := contract, locals := endSnipStoreRate I dogOut vatOut } @@ -7158,8 +7158,8 @@ theorem endSnipPrefixUsrSuccess {I} {dogOut vatOut saleOut : ByteArray} .letDecl "usr" (some addr) (.tupleGet (.var "clipSale") 3) ]) (.ok { contract := contract, locals := endSnipStoreUsr I dogOut vatOut saleOut } evmSales) := by - exact.execBlock_append hsales htail - have hseq :=.execBlock_append hprefix hsalesTail + exact execBlock_append hsales htail + have hseq := execBlock_append hprefix hsalesTail simpa [List.append_assoc] using hseq theorem endSnipVatReceiver_afterUsr {σ I dogOut vatOut saleOut evm} @@ -8257,7 +8257,7 @@ theorem endSnipTailReverts_yank {I} {dogOut vatOut saleOut : ByteArray} (.binary .lt (.var "lot") (.intLit int256Limit)) (.binary .lt (.var "art") (.intLit int256Limit))) ]) .reverted := by - exact.execBlock_append_term hyank (by intro f' e' h; cases h) + exact execBlock_append_term hyank (by intro f' e' h; cases h) simpa [List.append_assoc] using execBlock_append hsuck hyankTail @@ -8537,11 +8537,11 @@ theorem endSnipBodyReverts_afterUsrTailReverted {I} {dogOut vatOut saleOut : Byt (.binary .lt (.var "lot") (.intLit int256Limit)) (.binary .lt (.var "art") (.intLit int256Limit))) ] ++ grabTail) .reverted := by - exact.execBlock_append_term htail (by intro f' e' h; cases h) + exact execBlock_append_term htail (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSnipStore I } evm0 snipTransition.body .reverted := by - have hseq :=.execBlock_append hprefixUsr htailWithGrab + have hseq := execBlock_append hprefixUsr htailWithGrab simpa [snipTransition, grabTail, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -8606,11 +8606,11 @@ theorem endSnipBodyReverts_afterUsrTailGrabReverted {I σLoc} (.binary .lt (.var "lot") (.intLit int256Limit)) (.binary .lt (.var "art") (.intLit int256Limit))) ] ++ grabTail) .reverted := by - exact.execBlock_append htail hgrab + exact execBlock_append htail hgrab have hblock : ExecBlock config { contract := contract, locals := endSnipStore I } evm0 snipTransition.body .reverted := by - have hseq :=.execBlock_append hprefixUsr htailWithGrab + have hseq := execBlock_append hprefixUsr htailWithGrab simpa [snipTransition, grabTail, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock @@ -8679,13 +8679,13 @@ theorem endSnipBodyReturns_afterUsrTailGrabSuccess {I σLoc} (.binary .lt (.var "art") (.intLit int256Limit))) ] ++ grabTail) (.ok { contract := contract, locals := endSnipStoreGrab σLoc I dogOut vatOut saleOut } evmGrab) := by - exact.execBlock_append htail hgrab + exact execBlock_append htail hgrab have hblock : ExecBlock config { contract := contract, locals := endSnipStore I } evm0 snipTransition.body (.ok { contract := contract, locals := endSnipStoreGrab σLoc I dogOut vatOut saleOut } evmGrab) := by - have hseq :=.execBlock_append hprefixUsr htailWithGrab + have hseq := execBlock_append hprefixUsr htailWithGrab simpa [snipTransition, grabTail, List.append_assoc] using hseq exact ExecFuncBody.execBlockOK hblock @@ -8730,12 +8730,12 @@ theorem endSnipBodyReverts_afterRateSalesBlock {I} {dogOut vatOut : ByteArray} evmVat (checkedExternalCallStmts (.var "clip") "sales" (.intLit 0) [.var "id"] "clipSale" (perm := false) ++ afterSales) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := afterSales) hsales (by intro f' e' h; cases h) have hblock : ExecBlock config { contract := contract, locals := endSnipStore I } evm0 snipTransition.body .reverted := by - have hseq :=.execBlock_append hprefix hsalesWithTail + have hseq := execBlock_append hprefix hsalesWithTail simpa [snipTransition, afterSales, List.append_assoc] using hseq exact ExecFuncBody.execBlockRevert hblock diff --git a/Benchmarks/Dss/End/Thaw.lean b/Benchmarks/Dss/End/Thaw.lean index e862c402..34c6ffa1 100644 --- a/Benchmarks/Dss/End/Thaw.lean +++ b/Benchmarks/Dss/End/Thaw.lean @@ -3103,7 +3103,7 @@ theorem endThawBodyReverts_daiNoCode {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .require (.binary .eq (.var "vatDai") (.intLit 0)), .internalCall "add" [.storage whenRef, .storage waitRef] "deadline", @@ -3247,7 +3247,7 @@ theorem endThawBodyReverts_daiCallFailed {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .require (.binary .eq (.var "vatDai") (.intLit 0)), .internalCall "add" [.storage whenRef, .storage waitRef] "deadline", @@ -3350,7 +3350,7 @@ theorem endThawBodyReverts_daiBlockReverted {cA gh bl σ σ₀ A I} {g : UInt256 [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .require (.binary .eq (.var "vatDai") (.intLit 0)), .internalCall "add" [.storage whenRef, .storage waitRef] "deadline", @@ -3525,7 +3525,7 @@ theorem endThawBodyReverts_daiOkTailReverted {cA gh bl σ σ₀ A I} {g : UInt25 [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact.execBlock_append + exact execBlock_append (s2 := [ .require (.binary .eq (.var "vatDai") (.intLit 0)), .internalCall "add" [.storage whenRef, .storage waitRef] "deadline", @@ -3636,7 +3636,7 @@ theorem endThawBodyReverts_daiNonzero {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .internalCall "add" [.storage whenRef, .storage waitRef] "deadline", .require (.binary .ge nowT (.var "deadline")) ] ++ @@ -3788,7 +3788,7 @@ theorem endThawBodyReverts_deadlineAddOverflow {cA gh bl σ σ₀ A I} {g : UInt [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .require (.binary .ge nowT (.var "deadline")) ] ++ checkedExternalCallStmts (.storage vatRef) "debt" (.intLit 0) [] "vatDebt" ++ @@ -3967,7 +3967,7 @@ theorem endThawBodyReverts_waitNotFinished {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := checkedExternalCallStmts (.storage vatRef) "debt" (.intLit 0) [] "vatDebt" ++ checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" @@ -4695,7 +4695,7 @@ theorem endThawBodyReturns_daiOkTail {cA gh bl σ σ₀ A I} {g : UInt256} [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) (.ok fPost evmPost) := by - exact.execBlock_append + exact execBlock_append (s2 := [ .require (.binary .eq (.var "vatDai") (.intLit 0)), .internalCall "add" [.storage whenRef, .storage waitRef] "deadline", @@ -4901,14 +4901,14 @@ theorem endThawReadyTailRevertsAtDebt (evmDai : EVM.State) (out : ByteArray) [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" (perm := false) ++ [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) hdebt (by intro f' e' h; cases h) - exact.execBlock_append + exact execBlock_append (s2 := checkedExternalCallStmts (.storage vatRef) "debt" (.intLit 0) [] "vatDebt" ++ checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" @@ -4964,14 +4964,14 @@ theorem endThawReadyTailRevertsAfterDebt (evmDai evmDebt : EVM.State) [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact.execBlock_append + exact execBlock_append (s2 := checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" (perm := false) ++ [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) hdebt htellTail - exact.execBlock_append + exact execBlock_append (s2 := checkedExternalCallStmts (.storage vatRef) "debt" (.intLit 0) [] "vatDebt" ++ checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" @@ -5031,7 +5031,7 @@ theorem endThawReadyTailReturnsAfterDebt (evmDai evmDebt evmTell : EVM.State) .assign .storage debtRef (.var "debtNew") ]) (.ok { contract := contract, locals := postLocals } (endThawPostState evmTell debtNew)) := by - exact.execBlock_append + exact execBlock_append (s2 := [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) @@ -5046,14 +5046,14 @@ theorem endThawReadyTailReturnsAfterDebt (evmDai evmDebt evmTell : EVM.State) .assign .storage debtRef (.var "debtNew") ]) (.ok { contract := contract, locals := postLocals } (endThawPostState evmTell debtNew)) := by - exact.execBlock_append + exact execBlock_append (s2 := checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" (perm := false) ++ [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) hdebt hafterTell - exact.execBlock_append + exact execBlock_append (s2 := checkedExternalCallStmts (.storage vatRef) "debt" (.intLit 0) [] "vatDebt" ++ checkedExternalCallStmts (.storage cureRef) "tell" (.intLit 0) [] "cureTell" @@ -5642,7 +5642,7 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", @@ -5781,7 +5781,7 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", @@ -5863,7 +5863,7 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} [.var "vatDebt", .var "cureTell"] "debtNew", .assign .storage debtRef (.var "debtNew") ]) .reverted := by - exact.execBlock_append_term + exact execBlock_append_term (s2 := [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", @@ -6071,7 +6071,7 @@ theorem endThawBody {cA gh bl σ_evm σ_solm σ₀ A I} {g : UInt256} .assign .storage debtRef (.var "debtNew") ]) .reverted := by exact - .execBlock_append + execBlock_append (s2 := [ .internalCall "sub" [.var "vatDebt", .var "cureTell"] "debtNew", diff --git a/Benchmarks/Dss/Flapper/Deal.lean b/Benchmarks/Dss/Flapper/Deal.lean index 78c9b45b..badfd4ca 100644 --- a/Benchmarks/Dss/Flapper/Deal.lean +++ b/Benchmarks/Dss/Flapper/Deal.lean @@ -1445,7 +1445,7 @@ theorem flapperDealBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) checkedExternalCallStmts (.storage gemRef) "burn" (.intLit 0) [thisAddr, .storage (bidsF (.var "id") "bid")] "_burnRet") .reverted := - .execBlock_append_term hchecked (by intro f e h; cases h) + execBlock_append_term hchecked (by intro f e h; cases h) have htail : ExecBlock config { contract := contract, locals := dealLotLocals evm I } evm ((checkedExternalCallStmts (.storage vatRef) "move" (.intLit 0) @@ -1456,7 +1456,7 @@ theorem flapperDealBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) .internalCall "sub" [.storage fillRef, .var "lot"] "fillNew", .assign .storage fillRef (.var "fillNew")]) .reverted := - .execBlock_append_term hmoveTail (by intro f e h; cases h) + execBlock_append_term hmoveTail (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -1520,7 +1520,7 @@ theorem flapperDealBodyReverts_moveCallFailure checkedExternalCallStmts (.storage gemRef) "burn" (.intLit 0) [thisAddr, .storage (bidsF (.var "id") "bid")] "_burnRet") .reverted := - .execBlock_append_term hchecked (by intro f e h; cases h) + execBlock_append_term hchecked (by intro f e h; cases h) have htail : ExecBlock config { contract := contract, locals := dealLotLocals evm I } evm ((checkedExternalCallStmts (.storage vatRef) "move" (.intLit 0) @@ -1531,7 +1531,7 @@ theorem flapperDealBodyReverts_moveCallFailure .internalCall "sub" [.storage fillRef, .var "lot"] "fillNew", .assign .storage fillRef (.var "fillNew")]) .reverted := - .execBlock_append_term hmoveTail (by intro f e h; cases h) + execBlock_append_term hmoveTail (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -1624,7 +1624,7 @@ theorem flapperDealBodyReverts_burnNoCode checkedExternalCallStmts (.storage gemRef) "burn" (.intLit 0) [thisAddr, .storage (bidsF (.var "id") "bid")] "_burnRet") .reverted := - .execBlock_append hmoveChecked hburnChecked + execBlock_append hmoveChecked hburnChecked have htail : ExecBlock config { contract := contract, locals := dealLotLocals evm I } evm ((checkedExternalCallStmts (.storage vatRef) "move" (.intLit 0) @@ -1635,7 +1635,7 @@ theorem flapperDealBodyReverts_burnNoCode .internalCall "sub" [.storage fillRef, .var "lot"] "fillNew", .assign .storage fillRef (.var "fillNew")]) .reverted := - .execBlock_append_term hmoveTail (by intro f e h; cases h) + execBlock_append_term hmoveTail (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -1737,7 +1737,7 @@ theorem flapperDealBodyReverts_burnCallFailure checkedExternalCallStmts (.storage gemRef) "burn" (.intLit 0) [thisAddr, .storage (bidsF (.var "id") "bid")] "_burnRet") .reverted := - .execBlock_append hmoveChecked hburnChecked + execBlock_append hmoveChecked hburnChecked have htail : ExecBlock config { contract := contract, locals := dealLotLocals evm I } evm ((checkedExternalCallStmts (.storage vatRef) "move" (.intLit 0) @@ -1748,7 +1748,7 @@ theorem flapperDealBodyReverts_burnCallFailure .internalCall "sub" [.storage fillRef, .var "lot"] "fillNew", .assign .storage fillRef (.var "fillNew")]) .reverted := - .execBlock_append_term hmoveTail (by intro f e h; cases h) + execBlock_append_term hmoveTail (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -1844,7 +1844,7 @@ theorem flapperDealBodyBurnSuccessPrefix simpa [checkedExternalCallStmts, dealBurnLocals] using checkedExternalCallSuccess hburnGuard hgem hburnArgs hburnCall (dealBurnDecode_ok outBurn) - exact.execBlock_append hmoveChecked hburnChecked + exact execBlock_append hmoveChecked hburnChecked theorem flapperDealBodyReverts_fillSubUnderflow (evm evmMove evmBurn : EVM.State) (I : ExecutionEnv) diff --git a/Benchmarks/Dss/Flapper/File.lean b/Benchmarks/Dss/Flapper/File.lean index 066189b0..29cfacc0 100644 --- a/Benchmarks/Dss/Flapper/File.lean +++ b/Benchmarks/Dss/Flapper/File.lean @@ -1653,7 +1653,7 @@ theorem RD.flapperFileStoreTtlTail {cA σ I} {g : Sat256} {s0 : State} have rd1393pre := evm_run rd1391 with [ raw dup4 (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov)] - have rd1394 := rd1393pre.lor (by native_decide) (by evm_ov) + have rd1394 := rd1393pre.or (by native_decide) (by evm_ov) have rd1395 := rd1394.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd1396raw⟩ := rd1395.sstore hperm (by native_decide) (by evm_ov) have hword : @@ -1709,7 +1709,7 @@ theorem RD.flapperFileStoreTauTail {cA σ I} {g : Sat256} {s0 : State} raw dup5 (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), raw mul (by native_decide) (by evm_ov)] - have rd1449 := rd1446pre.lor (by native_decide) (by evm_ov) + have rd1449 := rd1446pre.or (by native_decide) (by evm_ov) have rd1450 := rd1449.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd1451raw⟩ := rd1450.sstore hperm (by native_decide) (by evm_ov) have hword : diff --git a/Benchmarks/Dss/Flapper/Kick.lean b/Benchmarks/Dss/Flapper/Kick.lean index 0e537b7e..271db254 100644 --- a/Benchmarks/Dss/Flapper/Kick.lean +++ b/Benchmarks/Dss/Flapper/Kick.lean @@ -1528,7 +1528,7 @@ theorem flapperKickBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) [sender, thisAddr, .var "lot"] "_moveRet" ++ [.return [.var "id"]]) .reverted := - .execBlock_append_term hchecked (by intro f e h; cases h) + execBlock_append_term hchecked (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [kickTransition, nonpayable, auth, checkedAddUintInto, checkedAdd48Into, checkedExternalCallStmts, List.cons_append, List.nil_append, evmMove] using @@ -1642,7 +1642,7 @@ theorem flapperKickBodyReverts_moveCallFailure [sender, thisAddr, .var "lot"] "_moveRet" ++ [.return [.var "id"]]) .reverted := - .execBlock_append_term hchecked (by intro f e h; cases h) + execBlock_append_term hchecked (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [kickTransition, nonpayable, auth, checkedAddUintInto, checkedAdd48Into, checkedExternalCallStmts, List.cons_append, List.nil_append, evmMove] using @@ -1773,7 +1773,7 @@ theorem flapperKickBodyReturns_moveCallSuccess [.return [.var "id"]]) (.returned { contract := contract, locals := kickMoveLocals evm I } evm' (some [.int (Int.ofNat (kickIdWord evm).toNat)])) := - .execBlock_append hchecked hreturn + execBlock_append hchecked hreturn refine ExecFuncBody.execBlockRet ?_ simpa [kickTransition, nonpayable, auth, checkedAddUintInto, checkedAdd48Into, checkedExternalCallStmts, List.cons_append, List.nil_append, evmMove] using diff --git a/Benchmarks/Dss/Flapper/Tend.lean b/Benchmarks/Dss/Flapper/Tend.lean index 696fbc6d..e3dadf8d 100644 --- a/Benchmarks/Dss/Flapper/Tend.lean +++ b/Benchmarks/Dss/Flapper/Tend.lean @@ -2099,7 +2099,7 @@ theorem flapperTendPaySuccessTail [.assign .storage (bidsF (.var "id") "bid") (.var "bid")]) (.ok { contract := contract, locals := tendPayRetLocals baseLocals } (tendAfterBidStore evmPay I)) := - .execBlock_append hpayChecked hbidAssign + execBlock_append hpayChecked hbidAssign have hticExpr : evalExpr? config { contract := contract, locals := tendTicLocals baseLocals evmPay I } (tendAfterBidStore evmPay I) (.var "tic_") = @@ -2128,7 +2128,7 @@ theorem flapperTendPaySuccessTail (tendTicLocals_get_id evmPay I hid) (tendTicLocals_get_bids evmPay I hbids) haddFit)) ExecBlock.nil) - exact.execBlock_append hpayBidTail htick + exact execBlock_append hpayBidTail htick set_option maxHeartbeats 1000000 in theorem flapperTendBodyReturns_success_callerEq @@ -2203,7 +2203,7 @@ theorem flapperTendBodyReturns_success_callerEq [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]))) (.ok { contract := contract, locals := tendTicLocals (tendBegBidLocals evm I) evmPay I } (tendPostState evmPay I)) := - .execBlock_append hskipRefund hpayTail + execBlock_append hskipRefund hpayTail refine ExecFuncBody.execBlockOK ?_ simpa [tendTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append, List.append_assoc] using @@ -2305,7 +2305,7 @@ theorem flapperTendRefundSuccessPrefix [.assign .storage (bidsF (.var "id") "guy") sender]) (.ok { contract := contract, locals := tendRefundRetLocals evm I } (tendAfterGuyStore evmRefund I)) := - .execBlock_append hrefundChecked hassign + execBlock_append hrefundChecked hassign exact ExecBlock.consNormal (ExecStmt.iteTrue hcallerCond hbranch) ExecBlock.nil set_option maxHeartbeats 1000000 in @@ -2481,7 +2481,7 @@ theorem flapperTendRefundNoCodeTail .storage (bidsF (.var "id") "bid")] "_refundRet" ++ [.assign .storage (bidsF (.var "id") "guy") sender]) .reverted := - .execBlock_append_term hrefundChecked (by intro f e h; cases h) + execBlock_append_term hrefundChecked (by intro f e h; cases h) have hite : ExecBlock config { contract := contract, locals := tendBegBidLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -2492,7 +2492,7 @@ theorem flapperTendRefundNoCodeTail []] .reverted := ExecBlock.consRevert (ExecStmt.iteTrue hcallerCond hthen) - exact.execBlock_append_term hite (by intro f e h; cases h) + exact execBlock_append_term hite (by intro f e h; cases h) theorem flapperTendRefundCallFailureTail (evm evmRefund : EVM.State) (I : ExecutionEnv) (outRefund : ByteArray) @@ -2557,7 +2557,7 @@ theorem flapperTendRefundCallFailureTail .storage (bidsF (.var "id") "bid")] "_refundRet" ++ [.assign .storage (bidsF (.var "id") "guy") sender]) .reverted := - .execBlock_append_term hrefundChecked (by intro f e h; cases h) + execBlock_append_term hrefundChecked (by intro f e h; cases h) have hite : ExecBlock config { contract := contract, locals := tendBegBidLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -2568,7 +2568,7 @@ theorem flapperTendRefundCallFailureTail []] .reverted := ExecBlock.consRevert (ExecStmt.iteTrue hcallerCond hthen) - exact.execBlock_append_term hite (by intro f e h; cases h) + exact execBlock_append_term hite (by intro f e h; cases h) theorem flapperTendPayNoCodeTail (evm : EVM.State) (I : ExecutionEnv) (baseLocals : Store) @@ -2616,8 +2616,8 @@ theorem flapperTendPayNoCodeTail "_payRet" ++ [.assign .storage (bidsF (.var "id") "bid") (.var "bid")]) .reverted := - .execBlock_append_term hchecked (by intro f e h; cases h) - exact.execBlock_append_term hpayBidTail + execBlock_append_term hchecked (by intro f e h; cases h) + exact execBlock_append_term hpayBidTail (by intro f e h; cases h) set_option maxHeartbeats 1000000 in @@ -2679,8 +2679,8 @@ theorem flapperTendPayCallFailureTail "_payRet" ++ [.assign .storage (bidsF (.var "id") "bid") (.var "bid")]) .reverted := - .execBlock_append_term hchecked (by intro f e h; cases h) - exact.execBlock_append_term hpayBidTail + execBlock_append_term hchecked (by intro f e h; cases h) + exact execBlock_append_term hpayBidTail (by intro f e h; cases h) set_option maxHeartbeats 1000000 in @@ -2774,7 +2774,7 @@ theorem flapperTendPayAddOverflowTail [.assign .storage (bidsF (.var "id") "bid") (.var "bid")]) (.ok { contract := contract, locals := tendPayRetLocals baseLocals } (tendAfterBidStore evmPay I)) := - .execBlock_append hpayChecked hbidAssign + execBlock_append hpayChecked hbidAssign have htickChecked : ExecBlock config { contract := contract, locals := tendPayRetLocals baseLocals } (tendAfterBidStore evmPay I) @@ -2794,8 +2794,8 @@ theorem flapperTendPayAddOverflowTail (checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]) .reverted := - .execBlock_append_term htickChecked (by intro f e h; cases h) - exact.execBlock_append hpayBidTail htickTail + execBlock_append_term htickChecked (by intro f e h; cases h) + exact execBlock_append hpayBidTail htickTail set_option maxHeartbeats 1000000 in theorem flapperTendBodyReverts_afterIncrease diff --git a/Benchmarks/Dss/Flapper/Yank.lean b/Benchmarks/Dss/Flapper/Yank.lean index 887c968d..d0a0b1bc 100644 --- a/Benchmarks/Dss/Flapper/Yank.lean +++ b/Benchmarks/Dss/Flapper/Yank.lean @@ -1266,7 +1266,7 @@ theorem flapperYankBodyReverts_moveCallFailure .storage (bidsF (.var "id") "bid")] "_moveRet" ++ [.delete (bidRef (.var "id"))]) .reverted := - .execBlock_append_term hchecked (by intro f e h; cases h) + execBlock_append_term hchecked (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [yankTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -1347,7 +1347,7 @@ theorem flapperYankBodyReturns_moveCallSuccess [.delete (bidRef (.var "id"))]) (.ok { contract := contract, locals := yankMoveLocals I } (yankDeletePostState evm' I)) := - .execBlock_append hchecked hdelete + execBlock_append hchecked hdelete refine ExecFuncBody.execBlockOK ?_ simpa [yankTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using diff --git a/Benchmarks/Dss/Flipper/FileAddress.lean b/Benchmarks/Dss/Flipper/FileAddress.lean index a0f3054b..a8a12e16 100644 --- a/Benchmarks/Dss/Flipper/FileAddress.lean +++ b/Benchmarks/Dss/Flipper/FileAddress.lean @@ -559,7 +559,7 @@ theorem flipperFileAddressX_storeAuthorized {cA σ I} {g : Sat256} {s0 : State} have rd5940 := rd5939.sub (by native_decide) (by evm_ov) have rd5941 := rd5940.dup4 (by native_decide) (by evm_ov) have rd5942 := rd5941.and (by native_decide) (by evm_ov) - have rd5943 := rd5942.lor (by native_decide) (by evm_ov) + have rd5943 := rd5942.or (by native_decide) (by evm_ov) have rd5944 := rd5943.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd5945⟩ := rd5944.sstore hperm (by native_decide) (by evm_ov) have rd5948 := rd5945.push2 ⟨1988⟩ (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Flipper/FileUint.lean b/Benchmarks/Dss/Flipper/FileUint.lean index dc939c3c..acb6c8dc 100644 --- a/Benchmarks/Dss/Flipper/FileUint.lean +++ b/Benchmarks/Dss/Flipper/FileUint.lean @@ -1110,7 +1110,7 @@ theorem flipperFileUintX_storeTauTail {cA σ I} {g : Sat256} {s0 : State} have rd1902 := rd1901.dup5 (by native_decide) (by evm_ov) have rd1903 := rd1902.and (by native_decide) (by evm_ov) have rd1904 := rd1903.mul (by native_decide) (by evm_ov) - have rd1905 := rd1904.lor (by native_decide) (by evm_ov) + have rd1905 := rd1904.or (by native_decide) (by evm_ov) have rd1906 := rd1905.swap1 (by native_decide) (by evm_ov) let slot5New := UInt256.lor (UInt256.mul (UInt256.land (fileUintData I) uint48Mask) uint48Divisor) diff --git a/Benchmarks/Dss/Flopper/Cage.lean b/Benchmarks/Dss/Flopper/Cage.lean index 144e85f2..046e24c1 100644 --- a/Benchmarks/Dss/Flopper/Cage.lean +++ b/Benchmarks/Dss/Flopper/Cage.lean @@ -296,7 +296,7 @@ theorem flopperCageX_storeAuthorized {cA σ I} {g : Sat256} {s0 : State} {k C : raw not (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov)] have rd3245 := rd3244.caller (by native_decide) (by evm_ov) - have rd3246 := rd3245.lor (by native_decide) (by evm_ov) + have rd3246 := rd3245.or (by native_decide) (by evm_ov) have rd3247 := rd3246.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd3248raw⟩ := rd3247.sstore hperm (by native_decide) (by evm_ov) have hsourceClean : UInt256.land (relySourceWord I) solcAddrMask = relySourceWord I := by diff --git a/Benchmarks/Dss/Flopper/Deal.lean b/Benchmarks/Dss/Flopper/Deal.lean index 6ebde3d8..f75f2f6e 100644 --- a/Benchmarks/Dss/Flopper/Deal.lean +++ b/Benchmarks/Dss/Flopper/Deal.lean @@ -781,7 +781,7 @@ theorem flopperDealBodyReverts_mintCallFailure "_mintRet" ++ [.delete (bidRef (.var "id"))]) .reverted := - .execBlock_append_term hchecked (by intro f e h; cases h) + execBlock_append_term hchecked (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -854,7 +854,7 @@ theorem flopperDealBodyReturns_mintCallSuccess [.delete (bidRef (.var "id"))]) (.ok { contract := contract, locals := dealMintLocals I } (auctionDeletePostState (dealIdWord I) evm')) := - .execBlock_append hchecked hdelete + execBlock_append hchecked hdelete refine ExecFuncBody.execBlockOK ?_ simpa [dealTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using diff --git a/Benchmarks/Dss/Flopper/Dent/Part3.lean b/Benchmarks/Dss/Flopper/Dent/Part3.lean index 52e4e6b1..fa90277c 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part3.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part3.lean @@ -127,7 +127,7 @@ theorem flopperDentBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) [], .assign .storage (bidsF (.var "id") "guy") sender ]) .reverted := - .execBlock_append_term hchecked (by intro f e h; cases h) + execBlock_append_term hchecked (by intro f e h; cases h) have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -165,7 +165,7 @@ theorem flopperDentBodyReverts_moveNoCode (evm : EVM.State) (I : ExecutionEnv) checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - .execBlock_append_term hite (by intro f e h; cases h) + execBlock_append_term hite (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -272,7 +272,7 @@ theorem flopperDentBodyReverts_moveCallFailure [], .assign .storage (bidsF (.var "id") "guy") sender ]) .reverted := - .execBlock_append_term hchecked (by intro f e h; cases h) + execBlock_append_term hchecked (by intro f e h; cases h) have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -310,7 +310,7 @@ theorem flopperDentBodyReverts_moveCallFailure checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - .execBlock_append_term hite (by intro f e h; cases h) + execBlock_append_term hite (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -455,7 +455,7 @@ theorem flopperDentBodyReverts_ashNoCode_moveCallerNe_ticZero (.intLit 0) [] "Ash" ++ [ .internalCall "min" [.var "bid", .var "Ash"] "kissAmt" ]) .reverted := - .execBlock_append_term hashChecked (by intro f e h; cases h) + execBlock_append_term hashChecked (by intro f e h; cases h) have hashBranch : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove (checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "Ash" @@ -464,7 +464,7 @@ theorem flopperDentBodyReverts_ashNoCode_moveCallerNe_ticZero checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "kiss" (.intLit 0) [.var "kissAmt"] "_kissRet") .reverted := - .execBlock_append_term hashMin (by intro f e h; cases h) + execBlock_append_term hashMin (by intro f e h; cases h) have hafterMove : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove [.ite (.binary .eq (.storage (bidsF (.var "id") "tic")) (.intLit 0)) @@ -491,7 +491,7 @@ theorem flopperDentBodyReverts_ashNoCode_moveCallerNe_ticZero [], .assign .storage (bidsF (.var "id") "guy") sender ]) .reverted := - .execBlock_append hchecked hafterMove + execBlock_append hchecked hafterMove have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -529,7 +529,7 @@ theorem flopperDentBodyReverts_ashNoCode_moveCallerNe_ticZero checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - .execBlock_append_term hite (by intro f e h; cases h) + execBlock_append_term hite (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -680,7 +680,7 @@ theorem flopperDentBodyReverts_ashCallFailure_moveCallerNe_ticZero (.intLit 0) [] "Ash" ++ [ .internalCall "min" [.var "bid", .var "Ash"] "kissAmt" ]) .reverted := - .execBlock_append_term hashChecked (by intro f e h; cases h) + execBlock_append_term hashChecked (by intro f e h; cases h) have hashBranch : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove (checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "Ash" @@ -689,7 +689,7 @@ theorem flopperDentBodyReverts_ashCallFailure_moveCallerNe_ticZero checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "kiss" (.intLit 0) [.var "kissAmt"] "_kissRet") .reverted := - .execBlock_append_term hashMin (by intro f e h; cases h) + execBlock_append_term hashMin (by intro f e h; cases h) have hafterMove : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove [.ite (.binary .eq (.storage (bidsF (.var "id") "tic")) (.intLit 0)) @@ -716,7 +716,7 @@ theorem flopperDentBodyReverts_ashCallFailure_moveCallerNe_ticZero [], .assign .storage (bidsF (.var "id") "guy") sender ]) .reverted := - .execBlock_append hchecked hafterMove + execBlock_append hchecked hafterMove have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -754,7 +754,7 @@ theorem flopperDentBodyReverts_ashCallFailure_moveCallerNe_ticZero checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - .execBlock_append_term hite (by intro f e h; cases h) + execBlock_append_term hite (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -907,7 +907,7 @@ theorem flopperDentBodyReverts_ashDecodeShort_moveCallerNe_ticZero (.intLit 0) [] "Ash" ++ [ .internalCall "min" [.var "bid", .var "Ash"] "kissAmt" ]) .reverted := - .execBlock_append_term hashChecked (by intro f e h; cases h) + execBlock_append_term hashChecked (by intro f e h; cases h) have hashBranch : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove (checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "Ash" @@ -916,7 +916,7 @@ theorem flopperDentBodyReverts_ashDecodeShort_moveCallerNe_ticZero checkedExternalCallStmts (.storage (bidsF (.var "id") "guy")) "kiss" (.intLit 0) [.var "kissAmt"] "_kissRet") .reverted := - .execBlock_append_term hashMin (by intro f e h; cases h) + execBlock_append_term hashMin (by intro f e h; cases h) have hafterMove : ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmMove [.ite (.binary .eq (.storage (bidsF (.var "id") "tic")) (.intLit 0)) @@ -943,7 +943,7 @@ theorem flopperDentBodyReverts_ashDecodeShort_moveCallerNe_ticZero [], .assign .storage (bidsF (.var "id") "guy") sender ]) .reverted := - .execBlock_append hchecked hafterMove + execBlock_append hchecked hafterMove have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -981,7 +981,7 @@ theorem flopperDentBodyReverts_ashDecodeShort_moveCallerNe_ticZero checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - .execBlock_append_term hite (by intro f e h; cases h) + execBlock_append_term hite (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -1170,7 +1170,7 @@ theorem flopperDentBodyReverts_afterAshRevert_moveCallerNe_ticZero [], .assign .storage (bidsF (.var "id") "guy") sender ]) .reverted := - .execBlock_append hchecked hafterMove + execBlock_append hchecked hafterMove have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -1208,7 +1208,7 @@ theorem flopperDentBodyReverts_afterAshRevert_moveCallerNe_ticZero checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - .execBlock_append_term hite (by intro f e h; cases h) + execBlock_append_term hite (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -1436,7 +1436,7 @@ theorem flopperDentBodyMoveSuccessTicNonzeroToLot [], .assign .storage (bidsF (.var "id") "guy") sender ]) (.ok { contract := contract, locals := dentMoveLocals evm I } evmGuy) := - .execBlock_append hchecked hguyAssign + execBlock_append hchecked hguyAssign have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -1466,7 +1466,7 @@ theorem flopperDentBodyMoveSuccessTicNonzeroToLot (dentMoveLocals_get_id evm I) (dentMoveLocals_get_bids evm I))) ExecBlock.nil have htail := - .execBlock_append hite hlotAssign + execBlock_append hite hlotAssign simpa [evmGuy, evmLot] using htail set_option maxHeartbeats 1000000 in @@ -1640,7 +1640,7 @@ theorem flopperDentBodyMoveAshKissSuccessTicZeroToLot [], .assign .storage (bidsF (.var "id") "guy") sender ]) (.ok { contract := contract, locals := dentKissRetLocals evm I outAsh } evmGuy) := - .execBlock_append hchecked hinnerGuy + execBlock_append hchecked hinnerGuy have hite : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm [.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -1672,7 +1672,7 @@ theorem flopperDentBodyMoveAshKissSuccessTicZeroToLot (dentKissRetLocals_get_bids evm I outAsh))) ExecBlock.nil have htail := - .execBlock_append hite hlotAssign + execBlock_append hite hlotAssign simpa [evmGuy, evmLot] using htail end Benchmarks.Dss.Flopper diff --git a/Benchmarks/Dss/Flopper/Dent/Part4.lean b/Benchmarks/Dss/Flopper/Dent/Part4.lean index 0d0514fa..5f3f0b6f 100644 --- a/Benchmarks/Dss/Flopper/Dent/Part4.lean +++ b/Benchmarks/Dss/Flopper/Dent/Part4.lean @@ -88,7 +88,7 @@ theorem flopperDentBodyReverts_addOverflow_moveCallerNe_ticZero_kissSuccess evmLot (checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]) .reverted := - .execBlock_append_term htickChecked (by intro f e h; cases h) + execBlock_append_term htickChecked (by intro f e h; cases h) have htail : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm ([.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -333,7 +333,7 @@ theorem flopperDentBodyReverts_addOverflow_moveCallerNe_ticNonzero ExecBlock config { contract := contract, locals := dentMoveLocals evm I } evmLot (checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]) .reverted := - .execBlock_append_term htickChecked (by intro f e h; cases h) + execBlock_append_term htickChecked (by intro f e h; cases h) have htail : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm ([.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -561,7 +561,7 @@ theorem flopperDentBodyReverts_addOverflow_callerEq (evm : EVM.State) (I : Execu ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evmLot (checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")]) .reverted := - .execBlock_append_term htickChecked (by intro f e h; cases h) + execBlock_append_term htickChecked (by intro f e h; cases h) have htail : ExecBlock config { contract := contract, locals := dentLotOneLocals evm I } evm ([.ite (.binary .ne sender (.storage (bidsF (.var "id") "guy"))) @@ -581,7 +581,7 @@ theorem flopperDentBodyReverts_addOverflow_callerEq (evm : EVM.State) (I : Execu (checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) .reverted := - .execBlock_append htailIteLot htickTail + execBlock_append htailIteLot htickTail refine ExecFuncBody.execBlockRevert ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -696,7 +696,7 @@ theorem flopperDentBodyReturns_success_callerEq (evm : EVM.State) (I : Execution (checkedAdd48Into "tic_" now48 (.storage ttlRef) ++ [.assign .storage (bidsF (.var "id") "tic") (.var "tic_")])) (.ok { contract := contract, locals := dentTicLocals evm I } (dentPostState evm I)) := - .execBlock_append htailIteLot htickLet + execBlock_append htailIteLot htickLet refine ExecFuncBody.execBlockOK ?_ simpa [dentTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using diff --git a/Benchmarks/Dss/Flopper/File/Part1.lean b/Benchmarks/Dss/Flopper/File/Part1.lean index 548da2f1..2e849e9a 100644 --- a/Benchmarks/Dss/Flopper/File/Part1.lean +++ b/Benchmarks/Dss/Flopper/File/Part1.lean @@ -1486,7 +1486,7 @@ theorem RD.flopperFileStoreTtlTail {cA σ I} {g : Sat256} {s0 : State} have rd1393pre := evm_run rd1391 with [ raw dup4 (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov)] - have rd1394 := rd1393pre.lor (by native_decide) (by evm_ov) + have rd1394 := rd1393pre.or (by native_decide) (by evm_ov) have rd1395 := rd1394.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd1396raw⟩ := rd1395.sstore hperm (by native_decide) (by evm_ov) have hword : @@ -1542,7 +1542,7 @@ theorem RD.flopperFileStoreTauTail {cA σ I} {g : Sat256} {s0 : State} raw dup5 (by native_decide) (by evm_ov), raw and (by native_decide) (by evm_ov), raw mul (by native_decide) (by evm_ov)] - have rd1449 := rd1446pre.lor (by native_decide) (by evm_ov) + have rd1449 := rd1446pre.or (by native_decide) (by evm_ov) have rd1450 := rd1449.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd1451raw⟩ := rd1450.sstore hperm (by native_decide) (by evm_ov) have hword : diff --git a/Benchmarks/Dss/Flopper/Tick/Part1.lean b/Benchmarks/Dss/Flopper/Tick/Part1.lean index cf4ff076..a1ed4bea 100644 --- a/Benchmarks/Dss/Flopper/Tick/Part1.lean +++ b/Benchmarks/Dss/Flopper/Tick/Part1.lean @@ -1077,7 +1077,7 @@ theorem flopperTickBodyReverts_addOverflow (evm : EVM.State) (I : ExecutionEnv) ExecBlock config { contract := contract, locals := tickLotBaseLocals evm I } evmLot (checkedAdd48Into "end_" now48 (.storage tauRef) ++ [.assign .storage (bidsF (.var "id") "end") (.var "end_")]) .reverted := - .execBlock_append_term hendChecked (by intro f e h; cases h) + execBlock_append_term hendChecked (by intro f e h; cases h) have htail : ExecBlock config { contract := contract, locals := tickLotBaseLocals evm I } evm ([.assign .storage (bidsF (.var "id") "lot") @@ -1085,7 +1085,7 @@ theorem flopperTickBodyReverts_addOverflow (evm : EVM.State) (I : ExecutionEnv) (checkedAdd48Into "end_" now48 (.storage tauRef) ++ [.assign .storage (bidsF (.var "id") "end") (.var "end_")])) .reverted := - .execBlock_append hlotAssign hendTail + execBlock_append hlotAssign hendTail refine ExecFuncBody.execBlockRevert ?_ simpa [tickTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using @@ -1142,7 +1142,7 @@ theorem flopperTickBodyReturns_success (evm : EVM.State) (I : ExecutionEnv) (checkedAdd48Into "end_" now48 (.storage tauRef) ++ [.assign .storage (bidsF (.var "id") "end") (.var "end_")])) (.ok { contract := contract, locals := tickEndLocals evm I } (tickPostState evm I)) := - .execBlock_append hlotAssign hendLet + execBlock_append hlotAssign hendLet refine ExecFuncBody.execBlockOK ?_ simpa [tickTransition, nonpayable, checkedMulUintInto, List.cons_append, List.nil_append] using diff --git a/Benchmarks/Dss/Flopper/Yank/Part1.lean b/Benchmarks/Dss/Flopper/Yank/Part1.lean index dc77acbe..7718421b 100644 --- a/Benchmarks/Dss/Flopper/Yank/Part1.lean +++ b/Benchmarks/Dss/Flopper/Yank/Part1.lean @@ -989,7 +989,7 @@ theorem flopperYankBodyReverts_suckCallFailure .storage (bidsF (.var "id") "bid")] "_suckRet" ++ [.delete (bidRef (.var "id"))]) .reverted := - .execBlock_append_term hchecked (by intro f e h; cases h) + execBlock_append_term hchecked (by intro f e h; cases h) refine ExecFuncBody.execBlockRevert ?_ simpa [yankTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using @@ -1071,7 +1071,7 @@ theorem flopperYankBodyReturns_suckCallSuccess [.delete (bidRef (.var "id"))]) (.ok { contract := contract, locals := yankSuckLocals I } (yankDeletePostState evm' I)) := - .execBlock_append hchecked hdelete + execBlock_append hchecked hdelete refine ExecFuncBody.execBlockOK ?_ simpa [yankTransition, nonpayable, checkedExternalCallStmts, List.cons_append, List.nil_append] using diff --git a/Benchmarks/Dss/Jug/FileVow.lean b/Benchmarks/Dss/Jug/FileVow.lean index c014486c..dd08ebff 100644 --- a/Benchmarks/Dss/Jug/FileVow.lean +++ b/Benchmarks/Dss/Jug/FileVow.lean @@ -631,7 +631,7 @@ theorem jugFileVowX_storeAuthorized {cA σ I} {g : Sat256} {s0 : State} {k C : have rd2097 := rd2096.sub (by native_decide) (by evm_ov) have rd2098 := rd2097.dup4 (by native_decide) (by evm_ov) have rd2099 := rd2098.and (by native_decide) (by evm_ov) - have rd2100 := rd2099.lor (by native_decide) (by evm_ov) + have rd2100 := rd2099.or (by native_decide) (by evm_ov) have rd2101 := rd2100.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd2102⟩ := rd2101.sstore hperm (by native_decide) (by evm_ov) have rd2105 := rd2102.push2 ⟨1013⟩ (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Pot/FileVow.lean b/Benchmarks/Dss/Pot/FileVow.lean index 07abcc58..6626ab0f 100644 --- a/Benchmarks/Dss/Pot/FileVow.lean +++ b/Benchmarks/Dss/Pot/FileVow.lean @@ -709,7 +709,7 @@ theorem potFileVowX_storeAuthorized {cA σ I} {g : Sat256} {s0 : State} {k C : have rd2269 := rd2268.sub (by native_decide) (by evm_ov) have rd2270 := rd2269.dup4 (by native_decide) (by evm_ov) have rd2271 := rd2270.and (by native_decide) (by evm_ov) - have rd2272 := rd2271.lor (by native_decide) (by evm_ov) + have rd2272 := rd2271.or (by native_decide) (by evm_ov) have rd2273 := rd2272.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd2274⟩ := rd2273.sstore hperm (by native_decide) (by evm_ov) have rd2277 := rd2274.push2 ⟨1326⟩ (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Spot/FilePip.lean b/Benchmarks/Dss/Spot/FilePip.lean index ea7f8bed..63827651 100644 --- a/Benchmarks/Dss/Spot/FilePip.lean +++ b/Benchmarks/Dss/Spot/FilePip.lean @@ -804,7 +804,7 @@ theorem spotFilePipX_storeAuthorized {cA σ I} {g : Sat256} {s0 : State} {k C : have rd2042 := rd2041.sub (by native_decide) (by evm_ov) have rd2043 := rd2042.dup4 (by native_decide) (by evm_ov) have rd2044 := rd2043.and (by native_decide) (by evm_ov) - have rd2045 := rd2044.lor (by native_decide) (by evm_ov) + have rd2045 := rd2044.or (by native_decide) (by evm_ov) have rd2046 := rd2045.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd2047⟩ := rd2046.sstore hperm (by native_decide) (by evm_ov) have hword : diff --git a/Benchmarks/Dss/Vat/Flux.lean b/Benchmarks/Dss/Vat/Flux.lean index 9cce3f3b..eee32b8e 100644 --- a/Benchmarks/Dss/Vat/Flux.lean +++ b/Benchmarks/Dss/Vat/Flux.lean @@ -718,7 +718,7 @@ theorem RD.vatFluxWishBranchOk raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd6792 := evm_run rd6791 with [ raw jumpdest (by native_decide) (by evm_ov)] - have rd6793 := rd6792.lor (by native_decide) (by evm_ov) + have rd6793 := rd6792.or (by native_decide) (by evm_ov) have rd6612raw := evm_run rd6793 with [ raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] @@ -763,7 +763,7 @@ theorem RD.vatFluxWishBranchRevert raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd6792 := evm_run rd6791 with [ raw jumpdest (by native_decide) (by evm_ov)] - have rd6793 := rd6792.lor (by native_decide) (by evm_ov) + have rd6793 := rd6792.or (by native_decide) (by evm_ov) have rd6612raw := evm_run rd6793 with [ raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] diff --git a/Benchmarks/Dss/Vat/FoldCommon.lean b/Benchmarks/Dss/Vat/FoldCommon.lean index 27d4c6a2..33e848b3 100644 --- a/Benchmarks/Dss/Vat/FoldCommon.lean +++ b/Benchmarks/Dss/Vat/FoldCommon.lean @@ -1354,10 +1354,10 @@ theorem vatFoldSourceRevertAfterDaiBlock (evm evmRate : EVM.State) (I : Executio · exact evalCallvalueEq_true hwv refine ExecBlock.consNormal (ExecStmt.requireTrue hauth) ?_ exact ExecBlock.consNormal (ExecStmt.requireTrue hlive) ExecBlock.nil - have h01 :=.execBlock_append hprefix hrateOk - have h02 :=.execBlock_append h01 hradOk - have h03 :=.execBlock_append h02 hdaiRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hrateOk + have h02 := execBlock_append h01 hradOk + have h03 := execBlock_append h02 hdaiRevert + have hblock := execBlock_append_term (s2 := [ .assign .storage (daiRef (.var "u")) (.var "daiNew") ] ++ checkedAddSignedInto "debtNew" (.storage debtRef) (.var "rad") ++ @@ -1411,12 +1411,12 @@ theorem vatFoldSourceRevertAfterDebtBlock · exact evalCallvalueEq_true hwv refine ExecBlock.consNormal (ExecStmt.requireTrue hauth) ?_ exact ExecBlock.consNormal (ExecStmt.requireTrue hlive) ExecBlock.nil - have h01 :=.execBlock_append hprefix hrateOk - have h02 :=.execBlock_append h01 hradOk - have h03 :=.execBlock_append h02 hdaiOk - have h04 :=.execBlock_append h03 hdaiAssign - have h05 :=.execBlock_append h04 hdebtRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hrateOk + have h02 := execBlock_append h01 hradOk + have h03 := execBlock_append h02 hdaiOk + have h04 := execBlock_append h03 hdaiAssign + have h05 := execBlock_append h04 hdebtRevert + have hblock := execBlock_append_term (s2 := [ .assign .storage debtRef (.var "debtNew") ]) h05 (by intro f e h; cases h) simpa [ExecTransitionBody, foldTransition, nonpayable, auth, requireLive, diff --git a/Benchmarks/Dss/Vat/FoldTail.lean b/Benchmarks/Dss/Vat/FoldTail.lean index c54c805d..c37f4b1c 100644 --- a/Benchmarks/Dss/Vat/FoldTail.lean +++ b/Benchmarks/Dss/Vat/FoldTail.lean @@ -285,8 +285,8 @@ theorem vatFoldSourceRevertAfterRateBlock (evm : EVM.State) (I : ExecutionEnv) · exact evalCallvalueEq_true hwv refine ExecBlock.consNormal (ExecStmt.requireTrue hauth) ?_ exact ExecBlock.consNormal (ExecStmt.requireTrue hlive) ExecBlock.nil - have h01 :=.execBlock_append hprefix hrateRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hrateRevert + have hblock := execBlock_append_term (s2 := [ .assign .storage (ilksF (.var "i") "rate") (.var "rateNew") ] ++ checkedMulSignedInto "rad" (.storage (ilksF (.var "i") "Art")) (.var "rate") ++ @@ -330,9 +330,9 @@ theorem vatFoldSourceRevertAfterRadBlock (evm evmRate : EVM.State) (I : Executio · exact evalCallvalueEq_true hwv refine ExecBlock.consNormal (ExecStmt.requireTrue hauth) ?_ exact ExecBlock.consNormal (ExecStmt.requireTrue hlive) ExecBlock.nil - have h01 :=.execBlock_append hprefix hrateOk - have h02 :=.execBlock_append h01 hradRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hrateOk + have h02 := execBlock_append h01 hradRevert + have hblock := execBlock_append_term (s2 := checkedAddSignedInto "daiNew" (.storage (daiRef (.var "u"))) (.var "rad") ++ [ .assign .storage (daiRef (.var "u")) (.var "daiNew") ] ++ @@ -757,12 +757,12 @@ theorem vatFoldSourceSuccess (evm : EVM.State) (I : ExecutionEnv) (by simpa [evmDai, evmRate, storageStore_executionEnv] using hDebtGuardPos) have hdebtAssign := vatFoldAssignDebtOk evmDai I (rateNew := rateNew) (rad := rad) (daiNew := daiNew) (debtNew := debtNew) - have h01 :=.execBlock_append hprefix hrateBlock - have h02 :=.execBlock_append h01 hradBlock - have h03 :=.execBlock_append h02 hdaiBlock - have h04 :=.execBlock_append h03 hdaiAssign - have h05 :=.execBlock_append h04 hdebtBlock - have hblock :=.execBlock_append h05 hdebtAssign + have h01 := execBlock_append hprefix hrateBlock + have h02 := execBlock_append h01 hradBlock + have h03 := execBlock_append h02 hdaiBlock + have h04 := execBlock_append h03 hdaiAssign + have h05 := execBlock_append h04 hdebtBlock + have hblock := execBlock_append h05 hdebtAssign simpa [ExecTransitionBody, foldTransition, nonpayable, auth, requireLive, List.append_assoc, evmRate, evmDai, foldPostState, storageStore_executionEnv] using ExecFuncBody.execBlockOK hblock diff --git a/Benchmarks/Dss/Vat/Fork.lean b/Benchmarks/Dss/Vat/Fork.lean index 366b104c..b9f19d95 100644 --- a/Benchmarks/Dss/Vat/Fork.lean +++ b/Benchmarks/Dss/Vat/Fork.lean @@ -2750,7 +2750,7 @@ theorem execForkSrcInkUpdateRevertGuardNeg {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hdinkAfter) (by simpa [locals'] using hstorageAfter) (forkDinkSubGuardNegFailCond hfail) - exact.execBlock_append_term hsub (by intro f e h; cases h) + exact execBlock_append_term hsub (by intro f e h; cases h) theorem execForkSrcInkUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (srcInkOld srcInkNew : UInt256) @@ -2834,7 +2834,7 @@ theorem execForkSrcInkUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hstorageAfter) (by simpa [locals'] using hguardNegEval) (forkDinkSubGuardPosFailCond hfail) - exact.execBlock_append_term hsub (by intro f e h; cases h) + exact execBlock_append_term hsub (by intro f e h; cases h) theorem execForkSrcArtUpdateOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (srcArtOld srcArtNew : UInt256) @@ -3023,7 +3023,7 @@ theorem execForkSrcArtUpdateRevertGuardNeg {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hdartAfter) (by simpa [locals'] using hstorageAfter) (forkDartSubGuardNegFailCond hfail) - exact.execBlock_append_term hsub (by intro f e h; cases h) + exact execBlock_append_term hsub (by intro f e h; cases h) theorem execForkSrcArtUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (srcArtOld srcArtNew : UInt256) @@ -3107,7 +3107,7 @@ theorem execForkSrcArtUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hstorageAfter) (by simpa [locals'] using hguardNegEval) (forkDartSubGuardPosFailCond hfail) - exact.execBlock_append_term hsub (by intro f e h; cases h) + exact execBlock_append_term hsub (by intro f e h; cases h) theorem execForkDstInkUpdateOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (dstInkOld dstInkNew : UInt256) @@ -3293,7 +3293,7 @@ theorem execForkDstInkUpdateRevertGuardNeg {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hdinkAfter) (by simpa [locals'] using hstorageAfter) (forkDinkAddGuardNegFailCond hfail) - exact.execBlock_append_term hadd (by intro f e h; cases h) + exact execBlock_append_term hadd (by intro f e h; cases h) theorem execForkDstInkUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (dstInkOld dstInkNew : UInt256) @@ -3375,7 +3375,7 @@ theorem execForkDstInkUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hstorageAfter) (by simpa [locals'] using hguardNegEval) (forkDinkAddGuardPosFailCond hfail) - exact.execBlock_append_term hadd (by intro f e h; cases h) + exact execBlock_append_term hadd (by intro f e h; cases h) theorem execForkDstArtUpdateOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (dstArtOld dstArtNew : UInt256) @@ -3561,7 +3561,7 @@ theorem execForkDstArtUpdateRevertGuardNeg {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hdartAfter) (by simpa [locals'] using hstorageAfter) (forkDartAddGuardNegFailCond hfail) - exact.execBlock_append_term hadd (by intro f e h; cases h) + exact execBlock_append_term hadd (by intro f e h; cases h) theorem execForkDstArtUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (dstArtOld dstArtNew : UInt256) @@ -3643,7 +3643,7 @@ theorem execForkDstArtUpdateRevertGuardPos {evm : EVM.State} {I : ExecutionEnv} (by simpa [locals'] using hstorageAfter) (by simpa [locals'] using hguardNegEval) (forkDartAddGuardPosFailCond hfail) - exact.execBlock_append_term hadd (by intro f e h; cases h) + exact execBlock_append_term hadd (by intro f e h; cases h) theorem execForkFinalLoadsOk {evm : EVM.State} {I : ExecutionEnv} (srcInkNew srcArtNew dstInkNew dstArtNew @@ -7516,16 +7516,16 @@ theorem execForkSourceOk {evm0 : EVM.State} {I : ExecutionEnv} (.binary .eq (.var "dstArtFinal") (.intLit 0))) ] (.ok { contract := contract, locals := finalLocals } evm4) := execForkFinalRequiresOk hwish hutabLe hvtabLe hsrcDust hdstDust - have h01 :=.execBlock_append hprefix hsrcInkBlock - have h02 :=.execBlock_append h01 hsrcArtBlock - have h03 :=.execBlock_append h02 hdstInkBlock - have h04 :=.execBlock_append h03 hdstArtBlock - have h05 :=.execBlock_append h04 hfinalLoadsBlock - have h06 :=.execBlock_append h05 hutabBlock - have h06 :=.execBlock_append h06 hvtabBlock - have h07 :=.execBlock_append h06 hsrcInkSpotBlock - have hblock :=.execBlock_append h07 hdstInkSpotBlock - have hblock :=.execBlock_append hblock hfinalBlock + have h01 := execBlock_append hprefix hsrcInkBlock + have h02 := execBlock_append h01 hsrcArtBlock + have h03 := execBlock_append h02 hdstInkBlock + have h04 := execBlock_append h03 hdstArtBlock + have h05 := execBlock_append h04 hfinalLoadsBlock + have h06 := execBlock_append h05 hutabBlock + have h06 := execBlock_append h06 hvtabBlock + have h07 := execBlock_append h06 hsrcInkSpotBlock + have hblock := execBlock_append h07 hdstInkSpotBlock + have hblock := execBlock_append hblock hfinalBlock simpa [ExecTransitionBody, forkTransition, nonpayable, checkedSubSignedInto, checkedAddSignedInto, checkedMulUintInto, List.append_assoc, storageStore_executionEnv] using ExecFuncBody.execBlockOK hblock @@ -7559,8 +7559,8 @@ theorem execForkSourceRevertSrcInkGuardNeg {evm0 : EVM.State} {I : ExecutionEnv} execForkSrcInkUpdateRevertGuardNeg (evm := evm0) (I := I) (locals := forkStore I) srcInkOld srcInkNew hsz164 (forkStore_get_ilk I) (forkStore_get_src I) (forkStore_get_dink I) (forkStore_urns I) hloadSrcInk hsrcInkNew hfail - have h01 :=.execBlock_append hprefix hsrcInkRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsrcInkRevert + have hblock := execBlock_append_term (s2 := checkedSubSignedInto "srcArtNew" (.storage (urnsF (.var "ilk") (.var "src") "art")) (.var "dart") ++ @@ -7638,8 +7638,8 @@ theorem execForkSourceRevertSrcInkGuardPos {evm0 : EVM.State} {I : ExecutionEnv} execForkSrcInkUpdateRevertGuardPos (evm := evm0) (I := I) (locals := forkStore I) srcInkOld srcInkNew hsz164 (forkStore_get_ilk I) (forkStore_get_src I) (forkStore_get_dink I) (forkStore_urns I) hloadSrcInk hsrcInkNew hguardNeg hfail - have h01 :=.execBlock_append hprefix hsrcInkRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsrcInkRevert + have hblock := execBlock_append_term (s2 := checkedSubSignedInto "srcArtNew" (.storage (urnsF (.var "ilk") (.var "src") "art")) (.var "dart") ++ @@ -7742,9 +7742,9 @@ theorem execForkSourceRevertSrcArtGuardNeg {evm0 : EVM.State} {I : ExecutionEnv} (forkStoreSrcInkNew_get_dart I srcInkNew) (forkStoreSrcInkNew_get_urns I srcInkNew) (by simpa [evm1] using hloadSrcArt) hsrcArtNew hfail - have h01 :=.execBlock_append hprefix hsrcInkBlock - have h02 :=.execBlock_append h01 hsrcArtRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsrcInkBlock + have h02 := execBlock_append h01 hsrcArtRevert + have hblock := execBlock_append_term (s2 := checkedAddSignedInto "dstInkNew" (.storage (urnsF (.var "ilk") (.var "dst") "ink")) (.var "dink") ++ @@ -7846,9 +7846,9 @@ theorem execForkSourceRevertSrcArtGuardPos {evm0 : EVM.State} {I : ExecutionEnv} (forkStoreSrcInkNew_get_dart I srcInkNew) (forkStoreSrcInkNew_get_urns I srcInkNew) (by simpa [evm1] using hloadSrcArt) hsrcArtNew hguardNeg hfail - have h01 :=.execBlock_append hprefix hsrcInkBlock - have h02 :=.execBlock_append h01 hsrcArtRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsrcInkBlock + have h02 := execBlock_append h01 hsrcArtRevert + have hblock := execBlock_append_term (s2 := checkedAddSignedInto "dstInkNew" (.storage (urnsF (.var "ilk") (.var "dst") "ink")) (.var "dink") ++ @@ -7961,10 +7961,10 @@ theorem execForkSourceRevertDstInkGuardNeg {evm0 : EVM.State} {I : ExecutionEnv} (forkStoreSrcArtNew_get_urns I srcInkNew srcArtNew) (by simpa [evm1, evm2, storageStore_executionEnv] using hloadDstInk) hdstInkNew hfail - have h01 :=.execBlock_append hprefix hsrcInkBlock - have h02 :=.execBlock_append h01 hsrcArtBlock - have h03 :=.execBlock_append h02 hdstInkRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsrcInkBlock + have h02 := execBlock_append h01 hsrcArtBlock + have h03 := execBlock_append h02 hdstInkRevert + have hblock := execBlock_append_term (s2 := checkedAddSignedInto "dstArtNew" (.storage (urnsF (.var "ilk") (.var "dst") "art")) (.var "dart") ++ @@ -8076,10 +8076,10 @@ theorem execForkSourceRevertDstInkGuardPos {evm0 : EVM.State} {I : ExecutionEnv} (forkStoreSrcArtNew_get_urns I srcInkNew srcArtNew) (by simpa [evm1, evm2, storageStore_executionEnv] using hloadDstInk) hdstInkNew hguardNeg hfail - have h01 :=.execBlock_append hprefix hsrcInkBlock - have h02 :=.execBlock_append h01 hsrcArtBlock - have h03 :=.execBlock_append h02 hdstInkRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsrcInkBlock + have h02 := execBlock_append h01 hsrcArtBlock + have h03 := execBlock_append h02 hdstInkRevert + have hblock := execBlock_append_term (s2 := checkedAddSignedInto "dstArtNew" (.storage (urnsF (.var "ilk") (.var "dst") "art")) (.var "dart") ++ @@ -8213,11 +8213,11 @@ theorem execForkSourceRevertDstArtGuardNeg {evm0 : EVM.State} {I : ExecutionEnv} (forkStoreDstInkNew_get_urns I srcInkNew srcArtNew dstInkNew) (by simpa [evm1, evm2, evm3, storageStore_executionEnv] using hloadDstArt) hdstArtNew hfail - have h01 :=.execBlock_append hprefix hsrcInkBlock - have h02 :=.execBlock_append h01 hsrcArtBlock - have h03 :=.execBlock_append h02 hdstInkBlock - have h04 :=.execBlock_append h03 hdstArtRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsrcInkBlock + have h02 := execBlock_append h01 hsrcArtBlock + have h03 := execBlock_append h02 hdstInkBlock + have h04 := execBlock_append h03 hdstArtRevert + have hblock := execBlock_append_term (s2 := [ .letDecl "srcArtFinal" (some uint256) (.storage (urnsF (.var "ilk") (.var "src") "art")), @@ -8350,11 +8350,11 @@ theorem execForkSourceRevertDstArtGuardPos {evm0 : EVM.State} {I : ExecutionEnv} (forkStoreDstInkNew_get_urns I srcInkNew srcArtNew dstInkNew) (by simpa [evm1, evm2, evm3, storageStore_executionEnv] using hloadDstArt) hdstArtNew hguardNeg hfail - have h01 :=.execBlock_append hprefix hsrcInkBlock - have h02 :=.execBlock_append h01 hsrcArtBlock - have h03 :=.execBlock_append h02 hdstInkBlock - have h04 :=.execBlock_append h03 hdstArtRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsrcInkBlock + have h02 := execBlock_append h01 hsrcArtBlock + have h03 := execBlock_append h02 hdstInkBlock + have h04 := execBlock_append h03 hdstArtRevert + have hblock := execBlock_append_term (s2 := [ .letDecl "srcArtFinal" (some uint256) (.storage (urnsF (.var "ilk") (.var "src") "art")), @@ -8590,13 +8590,13 @@ theorem execForkSourceRevertUtabMul {evm0 : EVM.State} {I : ExecutionEnv} execForkMulUintIntoRevertOfOverflow (evm := evm4) (locals := localsFinal) "utab" (.var "srcArtFinal") (.storage (ilksF (.var "ilk") "rate")) srcArtFinal rate hsrcArtEval hrateEval hover - have h01 :=.execBlock_append hprefix hsrcInkBlock - have h02 :=.execBlock_append h01 hsrcArtBlock - have h03 :=.execBlock_append h02 hdstInkBlock - have h04 :=.execBlock_append h03 hdstArtBlock - have h05 :=.execBlock_append h04 hfinalLoadsBlock - have h06 :=.execBlock_append h05 hutabRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsrcInkBlock + have h02 := execBlock_append h01 hsrcArtBlock + have h03 := execBlock_append h02 hdstInkBlock + have h04 := execBlock_append h03 hdstArtBlock + have h05 := execBlock_append h04 hfinalLoadsBlock + have h06 := execBlock_append h05 hutabRevert + have hblock := execBlock_append_term (s2 := checkedMulUintInto "vtab" (.var "dstArtFinal") (.storage (ilksF (.var "ilk") "rate")) ++ @@ -8829,14 +8829,14 @@ theorem execForkSourceRevertVtabMul {evm0 : EVM.State} {I : ExecutionEnv} execForkMulUintIntoRevertOfOverflow (evm := evm4) (locals := localsUtab) "vtab" (.var "dstArtFinal") (.storage (ilksF (.var "ilk") "rate")) dstArtFinal rate hdstArtEval hrateEval hover - have h01 :=.execBlock_append hprefix hsrcInkBlock - have h02 :=.execBlock_append h01 hsrcArtBlock - have h03 :=.execBlock_append h02 hdstInkBlock - have h04 :=.execBlock_append h03 hdstArtBlock - have h05 :=.execBlock_append h04 hfinalLoadsBlock - have h06 :=.execBlock_append h05 hutabBlock - have h07 :=.execBlock_append h06 hvtabRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsrcInkBlock + have h02 := execBlock_append h01 hsrcArtBlock + have h03 := execBlock_append h02 hdstInkBlock + have h04 := execBlock_append h03 hdstArtBlock + have h05 := execBlock_append h04 hfinalLoadsBlock + have h06 := execBlock_append h05 hutabBlock + have h07 := execBlock_append h06 hvtabRevert + have hblock := execBlock_append_term (s2 := checkedMulUintInto "srcInkSpot" (.var "srcInkFinal") (.storage (ilksF (.var "ilk") "spot")) ++ @@ -9089,15 +9089,15 @@ theorem execForkSourceRevertSrcInkSpotMul {evm0 : EVM.State} {I : ExecutionEnv} execForkMulUintIntoRevertOfOverflow (evm := evm4) (locals := localsVtab) "srcInkSpot" (.var "srcInkFinal") (.storage (ilksF (.var "ilk") "spot")) srcInkFinal spot hsrcInkEval hspotEval hover - have h01 :=.execBlock_append hprefix hsrcInkBlock - have h02 :=.execBlock_append h01 hsrcArtBlock - have h03 :=.execBlock_append h02 hdstInkBlock - have h04 :=.execBlock_append h03 hdstArtBlock - have h05 :=.execBlock_append h04 hfinalLoadsBlock - have h06 :=.execBlock_append h05 hutabBlock - have h07 :=.execBlock_append h06 hvtabBlock - have h08 :=.execBlock_append h07 hsrcInkSpotRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsrcInkBlock + have h02 := execBlock_append h01 hsrcArtBlock + have h03 := execBlock_append h02 hdstInkBlock + have h04 := execBlock_append h03 hdstArtBlock + have h05 := execBlock_append h04 hfinalLoadsBlock + have h06 := execBlock_append h05 hutabBlock + have h07 := execBlock_append h06 hvtabBlock + have h08 := execBlock_append h07 hsrcInkSpotRevert + have hblock := execBlock_append_term (s2 := checkedMulUintInto "dstInkSpot" (.var "dstInkFinal") (.storage (ilksF (.var "ilk") "spot")) ++ @@ -9358,16 +9358,16 @@ theorem execForkSourceRevertDstInkSpotMul {evm0 : EVM.State} {I : ExecutionEnv} execForkMulUintIntoRevertOfOverflow (evm := evm4) (locals := localsSrcInkSpot) "dstInkSpot" (.var "dstInkFinal") (.storage (ilksF (.var "ilk") "spot")) dstInkFinal spot hdstInkEval hspotEval hover - have h01 :=.execBlock_append hprefix hsrcInkBlock - have h02 :=.execBlock_append h01 hsrcArtBlock - have h03 :=.execBlock_append h02 hdstInkBlock - have h04 :=.execBlock_append h03 hdstArtBlock - have h05 :=.execBlock_append h04 hfinalLoadsBlock - have h06 :=.execBlock_append h05 hutabBlock - have h07 :=.execBlock_append h06 hvtabBlock - have h08 :=.execBlock_append h07 hsrcInkSpotBlock - have h09 :=.execBlock_append h08 hdstInkSpotRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsrcInkBlock + have h02 := execBlock_append h01 hsrcArtBlock + have h03 := execBlock_append h02 hdstInkBlock + have h04 := execBlock_append h03 hdstArtBlock + have h05 := execBlock_append h04 hfinalLoadsBlock + have h06 := execBlock_append h05 hutabBlock + have h07 := execBlock_append h06 hvtabBlock + have h08 := execBlock_append h07 hsrcInkSpotBlock + have h09 := execBlock_append h08 hdstInkSpotRevert + have hblock := execBlock_append_term (s2 := [ .require (bothExpr (wishExpr (.var "src") sender) (wishExpr (.var "dst") sender)), .require (.binary .le (.var "utab") (.var "srcInkSpot")), @@ -9616,16 +9616,16 @@ theorem execForkSourceRevertFinal {evm0 : EVM.State} {I : ExecutionEnv} srcInkNew srcArtNew dstInkNew dstArtNew srcArtFinal dstArtFinal srcInkFinal dstInkFinal spot utab vtab srcInkSpot dstInkSpot hsz164 hloadSpotFinal hdstInkSpotProd hdstInkSpotFit hdstInkSpotGuard - have h01 :=.execBlock_append hprefix hsrcInkBlock - have h02 :=.execBlock_append h01 hsrcArtBlock - have h03 :=.execBlock_append h02 hdstInkBlock - have h04 :=.execBlock_append h03 hdstArtBlock - have h05 :=.execBlock_append h04 hfinalLoadsBlock - have h06 :=.execBlock_append h05 hutabBlock - have h06 :=.execBlock_append h06 hvtabBlock - have h07 :=.execBlock_append h06 hsrcInkSpotBlock - have hblock :=.execBlock_append h07 hdstInkSpotBlock - have hblock :=.execBlock_append hblock hfinalBlock + have h01 := execBlock_append hprefix hsrcInkBlock + have h02 := execBlock_append h01 hsrcArtBlock + have h03 := execBlock_append h02 hdstInkBlock + have h04 := execBlock_append h03 hdstArtBlock + have h05 := execBlock_append h04 hfinalLoadsBlock + have h06 := execBlock_append h05 hutabBlock + have h06 := execBlock_append h06 hvtabBlock + have h07 := execBlock_append h06 hsrcInkSpotBlock + have hblock := execBlock_append h07 hdstInkSpotBlock + have hblock := execBlock_append hblock hfinalBlock simpa [ExecTransitionBody, forkTransition, nonpayable, checkedSubSignedInto, checkedAddSignedInto, checkedMulUintInto, List.append_assoc, storageStore_executionEnv] using ExecFuncBody.execBlockRevert hblock @@ -12036,7 +12036,7 @@ theorem RD.vatForkWishReturnOk raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd6792 := evm_run rd6791 with [ raw jumpdest (by native_decide) (by evm_ov)] - have rd6793 := rd6792.lor (by native_decide) (by evm_ov) + have rd6793 := rd6792.or (by native_decide) (by evm_ov) have rd6612raw := evm_run rd6793 with [ raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] diff --git a/Benchmarks/Dss/Vat/FrobBase.lean b/Benchmarks/Dss/Vat/FrobBase.lean index 96dfab81..cfb6acd8 100644 --- a/Benchmarks/Dss/Vat/FrobBase.lean +++ b/Benchmarks/Dss/Vat/FrobBase.lean @@ -6267,7 +6267,7 @@ theorem RD.vatWishReturnOk raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd6792 := evm_run rd6791 with [ raw jumpdest (by native_decide) (by evm_ov)] - have rd6793 := rd6792.lor (by native_decide) (by evm_ov) + have rd6793 := rd6792.or (by native_decide) (by evm_ov) have rd6612raw := evm_run rd6793 with [ raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] @@ -11913,11 +11913,11 @@ theorem execFrobLoadedPrefixThreeAdds {evm : EVM.State} {I : ExecutionEnv} ilkDust) (by simp [ilkArtNew]) (by simpa [ilkArtNew] using hIlkNeg) (by simpa [ilkArtNew] using hIlkPos) - have h01 :=.execBlock_append hprefix + have h01 := execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) - have h02 :=.execBlock_append h01 + have h02 := execBlock_append h01 (by simpa [localsLoaded, localsInk] using hArtBlock) - have h03 :=.execBlock_append h02 + have h03 := execBlock_append h02 (by simpa [localsLoaded, localsInk, localsArt] using hIlkBlock) simpa [localsLoaded, localsInk, localsArt, List.append_assoc] using h03 @@ -12483,7 +12483,7 @@ theorem execFrobCeilingInkSpotCheckedOk {evm : EVM.State} {locals : Store} exact execForkMulUintIntoOk "inkSpot" (.var "urnInkNew") (.var "ilkSpot") urnInkNew ilkSpot inkSpot hurnInkNewEval hilkSpotEval hinkSpot hinkFit hinkGuardEval - have h :=.execBlock_append hceilingBlock hinkBlock + have h := execBlock_append hceilingBlock hinkBlock simpa [localsCeiling, List.append_assoc] using h theorem execFrobCeilingSafetyOk {evm : EVM.State} {locals : Store} @@ -12579,7 +12579,7 @@ theorem execFrobCeilingSafetyOk {evm : EVM.State} {locals : Store} · simpa [localsFinal] using hceilingReq · exact ExecBlock.consNormal (ExecStmt.requireTrue (by simpa [localsFinal] using hsafeReq)) ExecBlock.nil - have h :=.execBlock_append hmul hreqs + have h := execBlock_append hmul hreqs simpa [localsFinal, List.append_assoc] using h theorem execFrobCeilingRequireRevert {evm : EVM.State} {locals : Store} @@ -12643,7 +12643,7 @@ theorem execFrobCeilingRequireRevert {evm : EVM.State} {locals : Store} .reverted := by exact ExecBlock.consRevert (ExecStmt.requireFalse (by simpa [localsFinal] using hceilingReq)) - have h :=.execBlock_append hmul hreq + have h := execBlock_append hmul hreq simpa [localsFinal, List.append_assoc] using h theorem execFrobSafetyRequireRevert {evm : EVM.State} {locals : Store} @@ -12734,7 +12734,7 @@ theorem execFrobSafetyRequireRevert {evm : EVM.State} {locals : Store} · simpa [localsFinal] using hceilingReq · exact ExecBlock.consRevert (ExecStmt.requireFalse (by simpa [localsFinal] using hsafeReq)) - have h :=.execBlock_append hmul hreqs + have h := execBlock_append hmul hreqs simpa [localsFinal, List.append_assoc] using h theorem execFrobAuthorizationDustOk {evm : EVM.State} {locals : Store} @@ -13610,7 +13610,7 @@ theorem execFrobGemUpdateOk {evm : EVM.State} {I : ExecutionEnv} [ .assign .storage (gemRef (.var "i") (.var "v")) (.var "gemNew") ] (.ok { contract := contract, locals := localsGem } evmGem) := by exact ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - have h :=.execBlock_append hsub hassignBlock + have h := execBlock_append hsub hassignBlock simpa [localsGem, evmGem, List.append_assoc] using h theorem execFrobDaiAddCheckedOk {evm : EVM.State} {I : ExecutionEnv} @@ -13852,7 +13852,7 @@ theorem execFrobDaiUpdateOk {evm : EVM.State} {I : ExecutionEnv} [ .assign .storage (daiRef (.var "w")) (.var "daiNew") ] (.ok { contract := contract, locals := localsDai } evmDai) := by exact ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - have h :=.execBlock_append hadd hassignBlock + have h := execBlock_append hadd hassignBlock simpa [localsDai, evmDai, List.append_assoc] using h theorem execFrobFinalStoreTailGemRevertFromBlock {evm : EVM.State} @@ -13876,7 +13876,7 @@ theorem execFrobFinalStoreTailGemRevertFromBlock {evm : EVM.State} .assign .storage (ilksF (.var "i") "line") (.var "ilkLine"), .assign .storage (ilksF (.var "i") "dust") (.var "ilkDust") ]) .reverted := by - have h :=.execBlock_append_term + have h := execBlock_append_term (s2 := [ .assign .storage (gemRef (.var "i") (.var "v")) (.var "gemNew") ] ++ checkedAddSignedInto "daiNew" (.storage (daiRef (.var "w"))) (.var "dtab") ++ @@ -13917,8 +13917,8 @@ theorem execFrobFinalStoreTailDaiRevertFromBlock {evm evmGem : EVM.State} .assign .storage (ilksF (.var "i") "line") (.var "ilkLine"), .assign .storage (ilksF (.var "i") "dust") (.var "ilkDust") ]) .reverted := by - have h01 :=.execBlock_append hGem hDai - have h :=.execBlock_append_term + have h01 := execBlock_append hGem hDai + have h := execBlock_append_term (s2 := [ .assign .storage (daiRef (.var "w")) (.var "daiNew"), .assign .storage (urnsF (.var "i") (.var "u") "ink") (.var "urnInkNew"), @@ -14171,8 +14171,8 @@ theorem execFrobFinalStoreTailOk {evm : EVM.State} {I : ExecutionEnv} (evalVarAfterDai (evm' := evmLine) hilkDust (by native_decide) (by native_decide)) hassignDust) ExecBlock.nil - have h01 :=.execBlock_append hgemBlock hdaiBlock - have h02 :=.execBlock_append h01 hstores + have h01 := execBlock_append hgemBlock hdaiBlock + have h02 := execBlock_append h01 hstores simpa [localsGem, localsDai, evmGem, evmDai, evmInk, evmArt, evmIlk, evmRate, evmSpot, evmLine, evmDust, List.append_assoc] using h02 @@ -14270,7 +14270,7 @@ theorem execFrobDebtAddStoreOk {evm : EVM.State} {locals : Store} [ .assign .storage debtRef (.var "debtNew") ] (.ok { contract := contract, locals := localsDebt } evmDebt) := by exact ExecBlock.consNormal (ExecStmt.assign hdebtNewEval hdebtAssign) ExecBlock.nil - have h :=.execBlock_append hAdd hAssign + have h := execBlock_append hAdd hAssign simpa [localsDebt, evmDebt, List.append_assoc] using h theorem execFrobDebtAddCheckedRevertGuardNeg {evm : EVM.State} {locals : Store} @@ -14406,7 +14406,7 @@ theorem execFrobLoadedPrefixUrnInkRevertGuardNeg {evm : EVM.State} {I : Executio frobStoreIlkDust_get_dink I urnInk urnArt ilkArt ilkRate ilkSpot ilkLine ilkDust) (by simp [urnInkNew]) (by simpa [urnInkNew] using hcond) - have h :=.execBlock_append hprefix + have h := execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) simpa [localsLoaded, List.append_assoc] using h @@ -14444,7 +14444,7 @@ theorem execFrobLoadedPrefixUrnInkRevertGuardPos {evm : EVM.State} {I : Executio ilkDust) (by simp [urnInkNew]) (by simpa [urnInkNew] using hguardNeg) (by simpa [urnInkNew] using hcond) - have h :=.execBlock_append hprefix + have h := execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) simpa [localsLoaded, List.append_assoc] using h @@ -14513,9 +14513,9 @@ theorem execFrobLoadedPrefixUrnArtRevertGuardNeg {evm : EVM.State} {I : Executio frobStoreIlkDust_get_dart I urnInk urnArt ilkArt ilkRate ilkSpot ilkLine ilkDust) (by simp [urnArtNew]) (by simpa [urnArtNew] using hcond) - have h01 :=.execBlock_append hprefix + have h01 := execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) - have h02 :=.execBlock_append h01 + have h02 := execBlock_append h01 (by simpa [localsLoaded, localsInk] using hArtBlock) simpa [localsLoaded, localsInk, List.append_assoc] using h02 @@ -14586,9 +14586,9 @@ theorem execFrobLoadedPrefixUrnArtRevertGuardPos {evm : EVM.State} {I : Executio ilkDust) (by simp [urnArtNew]) (by simpa [urnArtNew] using hArtNeg) (by simpa [urnArtNew] using hcond) - have h01 :=.execBlock_append hprefix + have h01 := execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) - have h02 :=.execBlock_append h01 + have h02 := execBlock_append h01 (by simpa [localsLoaded, localsInk] using hArtBlock) simpa [localsLoaded, localsInk, List.append_assoc] using h02 @@ -14690,11 +14690,11 @@ theorem execFrobLoadedPrefixIlkArtRevertGuardNeg {evm : EVM.State} {I : Executio frobStoreIlkDust_get_dart I urnInk urnArt ilkArt ilkRate ilkSpot ilkLine ilkDust) (by simp [ilkArtNew]) (by simpa [ilkArtNew] using hcond) - have h01 :=.execBlock_append hprefix + have h01 := execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) - have h02 :=.execBlock_append h01 + have h02 := execBlock_append h01 (by simpa [localsLoaded, localsInk] using hArtBlock) - have h03 :=.execBlock_append h02 + have h03 := execBlock_append h02 (by simpa [localsLoaded, localsInk, localsArt] using hIlkBlock) simpa [localsLoaded, localsInk, localsArt, List.append_assoc] using h03 @@ -14798,11 +14798,11 @@ theorem execFrobLoadedPrefixIlkArtRevertGuardPos {evm : EVM.State} {I : Executio ilkDust) (by simp [ilkArtNew]) (by simpa [ilkArtNew] using hIlkNeg) (by simpa [ilkArtNew] using hcond) - have h01 :=.execBlock_append hprefix + have h01 := execBlock_append hprefix (by simpa [localsLoaded] using hInkBlock) - have h02 :=.execBlock_append h01 + have h02 := execBlock_append h01 (by simpa [localsLoaded, localsInk] using hArtBlock) - have h03 :=.execBlock_append h02 + have h03 := execBlock_append h02 (by simpa [localsLoaded, localsInk, localsArt] using hIlkBlock) simpa [localsLoaded, localsInk, localsArt, List.append_assoc] using h03 diff --git a/Benchmarks/Dss/Vat/FrobLive.lean b/Benchmarks/Dss/Vat/FrobLive.lean index 2dcc02dc..3c38d115 100644 --- a/Benchmarks/Dss/Vat/FrobLive.lean +++ b/Benchmarks/Dss/Vat/FrobLive.lean @@ -252,7 +252,7 @@ theorem hsourceRevertFromPrefix {evm : EVM.State} {I : ExecutionEnv} ExecBlock config { contract := contract, locals := frobStore I } evm frobTransition.body .reverted := by rw [hbody] - exact.execBlock_append_term (s2 := tail) hsrcPrefixRevert + exact execBlock_append_term (s2 := tail) hsrcPrefixRevert (by intro f e h; cases h) exact ExecFuncBody.execBlockRevert hblock @@ -1085,7 +1085,7 @@ theorem hsourceRevertFromFinalStoreTail {evm evmDebt : EVM.State} {I : Execution .reverted) : ExecTransitionBody config contract evm (frobStore I) frobTransition.body .reverted := by - have hblock :=.execBlock_append hsourceDust htail + have hblock := execBlock_append hsourceDust htail exact ExecFuncBody.execBlockRevert (by simpa [ExecTransitionBody, frobTransition, List.append_assoc] using hblock) @@ -1475,7 +1475,7 @@ theorem execFrobLoadedPrefixDtabMulRevertRange {evm : EVM.State} .reverted := execFrobDtabMulCheckedRevertRange (evm := evm) (I := I) localsIlk ilkRate dtab hrateGet hdartGet hdtab hbad - have hfull :=.execBlock_append + have hfull := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk] using hthree) hdtabBlock simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, @@ -1565,7 +1565,7 @@ theorem execFrobLoadedPrefixDtabMulRevertMaxSlt {evm : EVM.State} execFrobDtabMulCheckedRevertMaxSlt (evm := evm) (I := I) localsIlk ilkRate dtab hrateGet hdartGet hdtab hdtabLo hdtabHi hRateMaxFail - have hfull :=.execBlock_append + have hfull := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk] using hthree) hdtabBlock simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, @@ -1668,7 +1668,7 @@ theorem execFrobLoadedPrefixTabMulRevertOverflow {evm : EVM.State} execFrobDtabMulCheckedOk (evm := evm) (I := I) localsIlk ilkRate dtab hrateGetIlk hdartGet hdtab hdtabLo hdtabHi hdtabGuards.1 hdtabGuards.2 - have hsourceDtab :=.execBlock_append + have hsourceDtab := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk] using hthree) hdtabBlock have hrateGetDtab : @@ -1695,7 +1695,7 @@ theorem execFrobLoadedPrefixTabMulRevertOverflow {evm : EVM.State} (evm := evm) (locals := localsIlk.insert "dtab" (.int dtab)) ilkRate urnArtNew hrateGetDtab hurnArtNewGet (by simpa [urnArtNew] using htabOverflow) - have hfull :=.execBlock_append + have hfull := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, List.append_assoc] using hsourceDtab) htabBlock @@ -1805,7 +1805,7 @@ theorem execFrobLoadedPrefixThroughTabOk {evm : EVM.State} execFrobDtabMulCheckedOk (evm := evm) (I := I) localsIlk ilkRate dtab hrateGetIlk hdartGet hdtab hdtabLo hdtabHi hdtabGuards.1 hdtabGuards.2 - have hsourceDtab :=.execBlock_append + have hsourceDtab := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk] using hthree) hdtabBlock have hTabMulS : @@ -1839,7 +1839,7 @@ theorem execFrobLoadedPrefixThroughTabOk {evm : EVM.State} exact execFrobTabMulCheckedOk (evm := evm) (locals := localsDtab) ilkRate urnArtNew tab hrateGetDtab hurnArtNewGet (by rfl) htabFitGuard.1 htabFitGuard.2 - have hfull :=.execBlock_append + have hfull := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, List.append_assoc] using hsourceDtab) htabBlock @@ -1962,7 +1962,7 @@ theorem execFrobLoadedPrefixThroughDebtOk {evm : EVM.State} debtOld debtNew dtabWord dtab hbaseDebt hdtabGet hdebtLoad hdtabMod hnew (signedAddGuardNegCond_of_word hdtabLo hdtabHi hdtabMod hDebtNeg) (signedAddGuardPosCond_of_word hdtabLo hdtabHi hdtabMod hDebtPos) - have hfull :=.execBlock_append + have hfull := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, List.append_assoc] using hsourceTab) hdebtBlock @@ -2072,7 +2072,7 @@ theorem execFrobLoadedPrefixDebtAddRevertGuardNeg {evm : EVM.State} debtOld debtNew dtabWord dtab hbaseDebt hdtabGet hdebtLoad hdtabMod hnew (signedAddGuardNegFalseCond_of_word hdtabLo hdtabHi hdtabMod hDebtNegFail) - have hfull :=.execBlock_append + have hfull := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, List.append_assoc] using hsourceTab) hdebtBlock @@ -2185,7 +2185,7 @@ theorem execFrobLoadedPrefixDebtAddRevertGuardPos {evm : EVM.State} (signedAddGuardNegCond_of_word hdtabLo hdtabHi hdtabMod hDebtNeg) (signedAddGuardPosFalseCond_of_word hdtabLo hdtabHi hdtabMod hDebtPosFail) - have hfull :=.execBlock_append + have hfull := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, List.append_assoc] using hsourceTab) hdebtBlock @@ -2580,7 +2580,7 @@ theorem execFrobLoadedPrefixThroughSafetyOk {evm : EVM.State} (by rfl) hCeilingFitGuard.1 hCeilingFitGuard.2 (by rfl) hInkFitGuard.1 hInkFitGuard.2 hceilingReqEval hsafetyReqEval - have hfull :=.execBlock_append + have hfull := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, localsDebt, evmDebt, List.append_assoc] using hsourceDebt) @@ -2707,7 +2707,7 @@ theorem execFrobLoadedPrefixCeilingMulRevertOverflow {evm : EVM.State} (evm := evmDebt) (locals := localsDebt) ilkArtNew ilkRate hlocalsDebtIlkArtNew hlocalsDebtRate (by simpa [ilkArtNew] using hover) - have hfull :=.execBlock_append + have hfull := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, localsDebt, evmDebt, List.append_assoc] using hsourceDebt) @@ -2900,8 +2900,8 @@ theorem execFrobLoadedPrefixInkSpotMulRevertOverflow {evm : EVM.State} rw [store_get_ne _ _ (by decide)] exact hlocalsDebtSpot) (by simpa [urnInkNew] using hover) - have hmulRevert :=.execBlock_append hceilBlock hinkBlock - have hfull :=.execBlock_append + have hmulRevert := execBlock_append hceilBlock hinkBlock + have hfull := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, localsDebt, evmDebt, List.append_assoc] using hsourceDebt) @@ -3208,7 +3208,7 @@ theorem execFrobLoadedPrefixCeilingRequireRevert {evm : EVM.State} (by rfl) hCeilingFitGuard.1 hCeilingFitGuard.2 (by rfl) hInkFitGuard.1 hInkFitGuard.2 hceilingReqEval - have hfull :=.execBlock_append + have hfull := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, localsDebt, evmDebt, List.append_assoc] using hsourceDebt) @@ -3592,7 +3592,7 @@ theorem execFrobLoadedPrefixSafetyRequireRevert {evm : EVM.State} (by rfl) hCeilingFitGuard.1 hCeilingFitGuard.2 (by rfl) hInkFitGuard.1 hInkFitGuard.2 hceilingReqEval hsafetyReqEval - have hfull :=.execBlock_append + have hfull := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, localsDebt, evmDebt, List.append_assoc] using hsourceDebt) @@ -5098,7 +5098,7 @@ theorem vatFrobBodyCoreLiveFinalArithmeticOverflowReverts (eitherExpr (.binary .eq (.var "urnArtNew") (.intLit 0)) (.binary .ge (.var "tab") (.var "ilkDust"))) ]) (.ok { contract := contract, locals := localsSafe } evmDebt) := by - have hprefix :=.execBlock_append hsourceSafety hauthDust + have hprefix := execBlock_append hsourceSafety hauthDust simpa [List.append_assoc] using hprefix obtain ⟨_, _, hDustDone⟩ := RD.vatFrobAuthorizationDustChecksSuccess @@ -6789,7 +6789,7 @@ theorem vatFrobBodyCoreLiveWishAuthDustReverts .reverted := by intro hauthRevert exact hsourceRevertFromAuthorizationDust (by - have hprefix :=.execBlock_append hsourceSafety hauthRevert + have hprefix := execBlock_append hsourceSafety hauthRevert simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab, debtOld, dtabWord, debtNew, localsDebt, evmDebt, ceilingDebt, inkSpot, localsSafe, List.append_assoc] using hprefix) diff --git a/Benchmarks/Dss/Vat/FrobLiveSuccess.lean b/Benchmarks/Dss/Vat/FrobLiveSuccess.lean index 6591a25e..7a84d54e 100644 --- a/Benchmarks/Dss/Vat/FrobLiveSuccess.lean +++ b/Benchmarks/Dss/Vat/FrobLiveSuccess.lean @@ -232,7 +232,7 @@ theorem execFrobGemDaiUpdatesOk {evm : EVM.State} {I : ExecutionEnv} execFrobDaiUpdateOk (evm := evmGem) (I := I) localsGem daiOld daiNew dtabWord dtab hwGem hdtabGem hbaseDaiGem (by simpa [evmGem] using hloadDai) hdtabMod hdaiNew hDaiNeg hDaiPos - have h :=.execBlock_append hgemBlock hdaiBlock + have h := execBlock_append hgemBlock hdaiBlock simpa [localsGem, localsDai, evmGem, evmDai, List.append_assoc] using h set_option maxHeartbeats 0 in @@ -964,7 +964,7 @@ theorem execFrobFinalStoreTailFromConstructedLocalsSplit {evmDebt : EVM.State} urnInkNew urnArtNew ilkArtNew ilkRate ilkSpot ilkLine ilkDust hsz196 hTailBaseI hTailBaseU hTailUrns hTailIlks hTailUrnInkNew hTailUrnArtNew hTailIlkArtNew hTailIlkRate hTailIlkSpot hTailIlkLine hTailIlkDust - have h :=.execBlock_append hgemDai hstores + have h := execBlock_append hgemDai hstores simpa [localsGem, localsDai, evmGem, evmDai, evmInk, evmArt, evmIlk, evmRate, evmSpot, evmLine, evmDust, List.append_assoc] using h -/ @@ -1303,7 +1303,7 @@ theorem vatFrobSourceBodySuccessFromDustBlock (frobDinkSubGuardPosCond hGemNegS) (signedAddGuardNegCond_of_word hdtabRange.1 hdtabRange.2 hdtabMod hDaiNegS) (signedAddGuardPosCond_of_word hdtabRange.1 hdtabRange.2 hdtabMod hDaiPosS) - have hfull :=.execBlock_append + have hfull := execBlock_append (s2 := checkedSubSignedInto "gemNew" (.storage (gemRef (.var "i") (.var "v"))) (.var "dink") ++ @@ -2175,7 +2175,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards using hguardMax) (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk] using hguardMul) - have h04 :=.execBlock_append + have h04 := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk] using hsourceAdds) hdtabBlock @@ -2449,7 +2449,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards exact execFrobTabMulCheckedOk (evm := evm0) (locals := localsDtab) ilkRate urnArtNew tab hrateGet hurnArtNewGet (by rfl) htabFitGuard.1 htabFitGuard.2 - have h05 :=.execBlock_append + have h05 := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab] using hsourceDtab) htabBlock @@ -2742,7 +2742,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards hDebtNegS) (signedAddGuardPosCond_of_word hdtabRange.1 hdtabRange.2 hdtabMod hDebtPosS) - have h06 :=.execBlock_append + have h06 := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsTab] using hsourceTab) hdebtBlock @@ -3237,7 +3237,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards (by rw [store_get_self]) (frobSafetySourceCond_of_evm (I := I) hSafetyOkS)) - have h07 :=.execBlock_append + have h07 := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsDebt, debtOld, dtabWord, debtNew, evmDebt] using hsourceDebt) @@ -3818,7 +3818,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards (frobAuthVSourceCond_of_evm (I := I) hV') (frobAuthWSourceCond_of_evm (I := I) hW') (frobDustSourceCond_of_evm hDustS) - have h08 :=.execBlock_append + have h08 := execBlock_append (by simpa [localsLoaded, urnInkNew, urnArtNew, ilkArtNew, localsIlk, localsDtab, tab, localsDebt, debtOld, dtabWord, debtNew, evmDebt, ceilingDebt, inkSpot, localsSafe] using hsourceSafe) @@ -4173,7 +4173,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock :=.execBlock_append_term + have hblock := execBlock_append_term (s2 := checkedAddSignedInto "urnArtNew" (.var "urnArt") (.var "dart") ++ checkedAddSignedInto "ilkArtNew" (.var "ilkArt") (.var "dart") ++ @@ -4245,7 +4245,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock :=.execBlock_append_term + have hblock := execBlock_append_term (s2 := checkedAddSignedInto "ilkArtNew" (.var "ilkArt") (.var "dart") ++ checkedMulSignedInto "dtab" (.var "ilkRate") (.var "dart") ++ @@ -4317,7 +4317,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock :=.execBlock_append_term + have hblock := execBlock_append_term (s2 := checkedMulSignedInto "dtab" (.var "ilkRate") (.var "dart") ++ checkedMulUintInto "tab" (.var "ilkRate") (.var "urnArtNew") ++ @@ -4389,7 +4389,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock :=.execBlock_append_term + have hblock := execBlock_append_term (s2 := checkedMulUintInto "tab" (.var "ilkRate") (.var "urnArtNew") ++ checkedAddSignedInto "debtNew" (.storage debtRef) (.var "dtab") ++ @@ -4461,7 +4461,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock :=.execBlock_append_term + have hblock := execBlock_append_term (s2 := checkedAddSignedInto "debtNew" (.storage debtRef) (.var "dtab") ++ [ .assign .storage debtRef (.var "debtNew") ] ++ @@ -4533,7 +4533,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock :=.execBlock_append_term + have hblock := execBlock_append_term (s2 := [ .assign .storage debtRef (.var "debtNew") ] ++ checkedMulUintInto "ceilingDebt" (.var "ilkArtNew") (.var "ilkRate") ++ @@ -4606,7 +4606,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock :=.execBlock_append_term + have hblock := execBlock_append_term (s2 := checkedMulUintInto "inkSpot" (.var "urnInkNew") (.var "ilkSpot") ++ [ .require @@ -4678,7 +4678,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock :=.execBlock_append_term + have hblock := execBlock_append_term (s2 := [ .require (eitherExpr @@ -4755,7 +4755,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock :=.execBlock_append_term + have hblock := execBlock_append_term (s2 := [ .require (eitherExpr @@ -4832,7 +4832,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock :=.execBlock_append_term + have hblock := execBlock_append_term (s2 := [ .require (eitherExpr @@ -4918,7 +4918,7 @@ theorem vatFrobBodyCoreLiveSuccessGuards .reverted) : ExecTransitionBody config contract evm0 (frobStore I) frobTransition.body .reverted := by - have hblock :=.execBlock_append_term + have hblock := execBlock_append_term (s2 := checkedSubSignedInto "gemNew" (.storage (gemRef (.var "i") (.var "v"))) (.var "dink") ++ diff --git a/Benchmarks/Dss/Vat/Grab.lean b/Benchmarks/Dss/Vat/Grab.lean index db330c0b..187057ee 100644 --- a/Benchmarks/Dss/Vat/Grab.lean +++ b/Benchmarks/Dss/Vat/Grab.lean @@ -4624,7 +4624,7 @@ theorem execGrabUrnArtUpdateOk {evm : EVM.State} {I : ExecutionEnv} [ .assign .storage (urnsF (.var "i") (.var "u") "art") (.var "urnArtNew") ] (.ok { contract := contract, locals := locals' } evm') := ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - exact.execBlock_append hchecked hassignBlock + exact execBlock_append hchecked hassignBlock theorem execGrabIlkArtUpdateOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (ilkArtOld ilkArtNew : UInt256) @@ -4677,7 +4677,7 @@ theorem execGrabIlkArtUpdateOk {evm : EVM.State} {I : ExecutionEnv} [ .assign .storage (ilksF (.var "i") "Art") (.var "ilkArtNew") ] (.ok { contract := contract, locals := locals' } evm') := ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - exact.execBlock_append hchecked hassignBlock + exact execBlock_append hchecked hassignBlock theorem execGrabGemUpdateOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (gemOld gemNew : UInt256) @@ -4735,7 +4735,7 @@ theorem execGrabGemUpdateOk {evm : EVM.State} {I : ExecutionEnv} [ .assign .storage (gemRef (.var "i") (.var "v")) (.var "gemNew") ] (.ok { contract := contract, locals := locals' } evm') := ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - exact.execBlock_append hchecked hassignBlock + exact execBlock_append hchecked hassignBlock theorem execGrabSinUpdateOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) (sinOld sinNew dtabWord : UInt256) (dtab : Int) @@ -4786,7 +4786,7 @@ theorem execGrabSinUpdateOk {evm : EVM.State} {I : ExecutionEnv} [ .assign .storage (sinRef (.var "w")) (.var "sinNew") ] (.ok { contract := contract, locals := locals' } evm') := ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - exact.execBlock_append hchecked hassignBlock + exact execBlock_append hchecked hassignBlock theorem execGrabViceUpdateOk {evm : EVM.State} (locals : Store) (viceOld viceNew dtabWord : UInt256) (dtab : Int) @@ -4829,7 +4829,7 @@ theorem execGrabViceUpdateOk {evm : EVM.State} [ .assign .storage viceRef (.var "viceNew") ] (.ok { contract := contract, locals := locals' } evm') := ExecBlock.consNormal (ExecStmt.assign hnewEval hassign) ExecBlock.nil - exact.execBlock_append hchecked hassignBlock + exact execBlock_append hchecked hassignBlock theorem execGrabFinalAssignmentsOk {evm : EVM.State} {I : ExecutionEnv} (locals : Store) @@ -5432,13 +5432,13 @@ theorem execGrabSourceOk {cA gh bl σ σ₀ A I} {g : UInt256} viceOld viceNew dtabWord dtab hVice_dtab hVice_vice (by simpa [evm0, evm1, evm2, evm3, evm4, evm5] using hloadVice) hdtabMod hviceNew hviceNeg hvicePos - have h01 :=.execBlock_append hprefix hInkBlock - have h02 :=.execBlock_append h01 hArtBlock - have h03 :=.execBlock_append h02 hIlkBlock - have h04 :=.execBlock_append h03 hDtabBlock - have h05 :=.execBlock_append h04 hGemBlock - have h06 :=.execBlock_append h05 hSinBlock - have hblock :=.execBlock_append h06 hViceBlock + have h01 := execBlock_append hprefix hInkBlock + have h02 := execBlock_append h01 hArtBlock + have h03 := execBlock_append h02 hIlkBlock + have h04 := execBlock_append h03 hDtabBlock + have h05 := execBlock_append h04 hGemBlock + have h06 := execBlock_append h05 hSinBlock + have hblock := execBlock_append h06 hViceBlock simpa [ExecTransitionBody] using ExecFuncBody.execBlockOK hblock theorem vatGrabSourceBodySuccessFromFinalValues @@ -5724,8 +5724,8 @@ theorem vatGrabSourceBodyUrnInkRevertGuardNeg (grabSourceLoad_urnInk (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hsz196)) (by simp [grabUrnInkNew, vatSlotWord]) hguardNeg - have h01 :=.execBlock_append hprefix hInkRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hInkRevert + have hblock := execBlock_append_term (s2 := [ .assign .storage (urnsF (.var "i") (.var "u") "ink") (.var "urnInkNew") ] ++ checkedAddSignedInto "urnArtNew" (.storage (urnsF (.var "i") (.var "u") "art")) @@ -5788,8 +5788,8 @@ theorem vatGrabSourceBodyUrnInkRevertGuardPos (grabSourceLoad_urnInk (cA := cA) (gh := gh) (bl := bl) (σ := σ) (σ₀ := σ₀) (A := A) (I := I) (g := g) hsz196)) (by simp [grabUrnInkNew, vatSlotWord]) hguardNeg hguardPos - have h01 :=.execBlock_append hprefix hInkRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hInkRevert + have hblock := execBlock_append_term (s2 := [ .assign .storage (urnsF (.var "i") (.var "u") "ink") (.var "urnInkNew") ] ++ checkedAddSignedInto "urnArtNew" (.storage (urnsF (.var "i") (.var "u") "art")) @@ -5870,14 +5870,14 @@ theorem vatGrabSourceBodyUrnArtRevertFromBlock (by simp [urnInkNew, grabUrnInkNew, vatSlotWord]) (by simpa [urnInkNew, vatSlotWord] using hinkNeg) (by simpa [urnInkNew, vatSlotWord] using hinkPos) - have h01 :=.execBlock_append hprefix hInkBlock + have h01 := execBlock_append hprefix hInkBlock have hArt : ExecBlock config { contract := contract, locals := localsInk } evm1 (checkedAddSignedInto "urnArtNew" (.storage (urnsF (.var "i") (.var "u") "art")) (.var "dart")) .reverted := by simpa [evm0, evm1, localsInk, urnInkNew] using hArtRevert - have h02 :=.execBlock_append h01 hArt - have hblock :=.execBlock_append_term + have h02 := execBlock_append h01 hArt + have hblock := execBlock_append_term (s2 := [ .assign .storage (urnsF (.var "i") (.var "u") "art") (.var "urnArtNew") ] ++ checkedAddSignedInto "ilkArtNew" (.storage (ilksF (.var "i") "Art")) @@ -6115,15 +6115,15 @@ theorem vatGrabSourceBodyIlkArtRevertFromBlock (by simp [urnArtNew, grabUrnArtNew]) (by simpa [urnArtNew] using hartNeg) (by simpa [urnArtNew] using hartPos) - have h01 :=.execBlock_append hprefix hInkBlock - have h02 :=.execBlock_append h01 hArtBlock + have h01 := execBlock_append hprefix hInkBlock + have h02 := execBlock_append h01 hArtBlock have hIlk : ExecBlock config { contract := contract, locals := localsArt } evm2 (checkedAddSignedInto "ilkArtNew" (.storage (ilksF (.var "i") "Art")) (.var "dart")) .reverted := by simpa [evm0, evm1, evm2, localsArt, urnInkNew, urnArtNew] using hIlkRevert - have h03 :=.execBlock_append h02 hIlk - have hblock :=.execBlock_append_term + have h03 := execBlock_append h02 hIlk + have hblock := execBlock_append_term (s2 := [ .assign .storage (ilksF (.var "i") "Art") (.var "ilkArtNew") ] ++ checkedMulSignedInto "dtab" (.storage (ilksF (.var "i") "rate")) (.var "dart") ++ @@ -6432,16 +6432,16 @@ theorem vatGrabSourceBodyDtabRevertFromBlock (by simp [ilkArtNew, grabIlkArtNew]) (by simpa [ilkArtNew] using hilkNeg) (by simpa [ilkArtNew] using hilkPos) - have h01 :=.execBlock_append hprefix hInkBlock - have h02 :=.execBlock_append h01 hArtBlock - have h03 :=.execBlock_append h02 hIlkBlock + have h01 := execBlock_append hprefix hInkBlock + have h02 := execBlock_append h01 hArtBlock + have h03 := execBlock_append h02 hIlkBlock have hDtab : ExecBlock config { contract := contract, locals := localsIlk } evm3 (checkedMulSignedInto "dtab" (.storage (ilksF (.var "i") "rate")) (.var "dart")) .reverted := by simpa [evm0, evm1, evm2, evm3, localsIlk, urnInkNew, urnArtNew, ilkArtNew] using hDtabRevert - have h04 :=.execBlock_append h03 hDtab - have hblock :=.execBlock_append_term + have h04 := execBlock_append h03 hDtab + have hblock := execBlock_append_term (s2 := checkedSubSignedInto "gemNew" (.storage (gemRef (.var "i") (.var "v"))) (.var "dink") ++ @@ -6656,11 +6656,11 @@ theorem vatGrabSourceBodyPostDtabRevertFromBlock .reverted := by simpa [evm0, evm1, evm2, evm3, localsDtab, urnInkNew, urnArtNew, ilkArtNew] using hTailRevert - have h01 :=.execBlock_append hprefix hInkBlock - have h02 :=.execBlock_append h01 hArtBlock - have h03 :=.execBlock_append h02 hIlkBlock - have h04 :=.execBlock_append h03 hDtab - have h05 :=.execBlock_append h04 hTail + have h01 := execBlock_append hprefix hInkBlock + have h02 := execBlock_append h01 hArtBlock + have h03 := execBlock_append h02 hIlkBlock + have h04 := execBlock_append h03 hDtab + have h05 := execBlock_append h04 hTail simpa [ExecTransitionBody, grabTransition, nonpayable, auth, evm0, evm1, evm2, evm3, localsInk, localsArt, localsIlk, localsDtab, urnInkNew, urnArtNew, ilkArtNew, List.append_assoc] using ExecFuncBody.execBlockRevert h05 @@ -6681,7 +6681,7 @@ theorem execGrabTailGemRevertFromBlock {evm : EVM.State} checkedSubSignedInto "viceNew" (.storage viceRef) (.var "dtab") ++ [ .assign .storage viceRef (.var "viceNew") ]) .reverted := by - have h :=.execBlock_append_term + have h := execBlock_append_term (s2 := [ .assign .storage (gemRef (.var "i") (.var "v")) (.var "gemNew") ] ++ checkedSubSignedInto "sinNew" (.storage (sinRef (.var "w"))) (.var "dtab") ++ @@ -6712,8 +6712,8 @@ theorem execGrabTailSinRevertFromBlock {evm evm4 : EVM.State} checkedSubSignedInto "viceNew" (.storage viceRef) (.var "dtab") ++ [ .assign .storage viceRef (.var "viceNew") ]) .reverted := by - have h01 :=.execBlock_append hGem hSin - have h :=.execBlock_append_term + have h01 := execBlock_append hGem hSin + have h := execBlock_append_term (s2 := [ .assign .storage (sinRef (.var "w")) (.var "sinNew") ] ++ checkedSubSignedInto "viceNew" (.storage viceRef) (.var "dtab") ++ @@ -6747,9 +6747,9 @@ theorem execGrabTailViceRevertFromBlock {evm evm4 evm5 : EVM.State} checkedSubSignedInto "viceNew" (.storage viceRef) (.var "dtab") ++ [ .assign .storage viceRef (.var "viceNew") ]) .reverted := by - have h01 :=.execBlock_append hGem hSin - have h02 :=.execBlock_append h01 hVice - have h :=.execBlock_append_term + have h01 := execBlock_append hGem hSin + have h02 := execBlock_append h01 hVice + have h := execBlock_append_term (s2 := [ .assign .storage viceRef (.var "viceNew") ]) h02 (by intro f e h; cases h) simpa [List.append_assoc] using h diff --git a/Benchmarks/Dss/Vat/Move.lean b/Benchmarks/Dss/Vat/Move.lean index fe068174..66ba93aa 100644 --- a/Benchmarks/Dss/Vat/Move.lean +++ b/Benchmarks/Dss/Vat/Move.lean @@ -1165,7 +1165,7 @@ theorem RD.vatMoveWishBranchOk raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd6792 := evm_run rd6791 with [ raw jumpdest (by native_decide) (by evm_ov)] - have rd6793 := rd6792.lor (by native_decide) (by evm_ov) + have rd6793 := rd6792.or (by native_decide) (by evm_ov) have rd6612raw := evm_run rd6793 with [ raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] @@ -1209,7 +1209,7 @@ theorem RD.vatMoveWishBranchRevert raw jump (by native_decide) (by jump_dest) (by evm_ov)] have rd6792 := evm_run rd6791 with [ raw jumpdest (by native_decide) (by evm_ov)] - have rd6793 := rd6792.lor (by native_decide) (by evm_ov) + have rd6793 := rd6792.or (by native_decide) (by evm_ov) have rd6612raw := evm_run rd6793 with [ raw swap1 (by native_decide) (by evm_ov), raw jump (by native_decide) (by jump_dest) (by evm_ov)] diff --git a/Benchmarks/Dss/Vat/Suck.lean b/Benchmarks/Dss/Vat/Suck.lean index 5999525c..508f1781 100644 --- a/Benchmarks/Dss/Vat/Suck.lean +++ b/Benchmarks/Dss/Vat/Suck.lean @@ -981,14 +981,14 @@ theorem vatSuckSourceSuccess (evm : EVM.State) (I : ExecutionEnv) have hdebtAssign := vatSuckAssignDebtOk evmVice I (sinNew := sinNew) (daiNew := daiNew) (viceNew := viceNew) (debtNew := debtNew) - have h01 :=.execBlock_append hprefix hsinAdd - have h02 :=.execBlock_append h01 hsinAssign - have h03 :=.execBlock_append h02 hdaiAdd - have h04 :=.execBlock_append h03 hdaiAssign - have h05 :=.execBlock_append h04 hviceAdd - have h06 :=.execBlock_append h05 hviceAssign - have h07 :=.execBlock_append h06 hdebtAdd - have hblock :=.execBlock_append h07 hdebtAssign + have h01 := execBlock_append hprefix hsinAdd + have h02 := execBlock_append h01 hsinAssign + have h03 := execBlock_append h02 hdaiAdd + have h04 := execBlock_append h03 hdaiAssign + have h05 := execBlock_append h04 hviceAdd + have h06 := execBlock_append h05 hviceAssign + have h07 := execBlock_append h06 hdebtAdd + have hblock := execBlock_append h07 hdebtAssign simpa [ExecTransitionBody, suckTransition, nonpayable, auth, checkedAddUintInto, List.append_assoc, suckPostState, evmSin, evmDai, evmVice, storageStore_executionEnv] using ExecFuncBody.execBlockOK hblock @@ -1027,10 +1027,10 @@ theorem vatSuckSourceRevertDaiOverflow (evm : EVM.State) (I : ExecutionEnv) have hdaiRevert := vatSuckDaiAddBlockRevert evmSin I (sinNew := sinNew) (daiVal := daiVal) hdaiLoad hdaiOverflow - have h01 :=.execBlock_append hprefix hsinAdd - have h02 :=.execBlock_append h01 hsinAssign - have h03 :=.execBlock_append h02 hdaiRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsinAdd + have h02 := execBlock_append h01 hsinAssign + have h03 := execBlock_append h02 hdaiRevert + have hblock := execBlock_append_term (s2 := [ .assign .storage (daiRef (.var "v")) (.var "daiNew") ] ++ checkedAddUintInto "viceNew" (.storage viceRef) (.var "rad") ++ @@ -1100,10 +1100,10 @@ theorem vatSuckSourceRevertDaiOverflowVat have hdaiRevert := vatSuckDaiAddBlockRevert evmSin I (sinNew := sinNew) (daiVal := daiVal) hdaiLoad hdaiOverflowLoad - have h01 :=.execBlock_append hprefix hsinAdd - have h02 :=.execBlock_append h01 hsinAssign - have h03 :=.execBlock_append h02 hdaiRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsinAdd + have h02 := execBlock_append h01 hsinAssign + have h03 := execBlock_append h02 hdaiRevert + have hblock := execBlock_append_term (s2 := [ .assign .storage (daiRef (.var "v")) (.var "daiNew") ] ++ checkedAddUintInto "viceNew" (.storage viceRef) (.var "rad") ++ @@ -1158,12 +1158,12 @@ theorem vatSuckSourceRevertViceOverflow (evm : EVM.State) (I : ExecutionEnv) have hviceRevert := vatSuckViceAddBlockRevert evmDai I (sinNew := sinNew) (daiNew := daiNew) (viceVal := viceVal) hviceLoad hviceOverflow - have h01 :=.execBlock_append hprefix hsinAdd - have h02 :=.execBlock_append h01 hsinAssign - have h03 :=.execBlock_append h02 hdaiAdd - have h04 :=.execBlock_append h03 hdaiAssign - have h05 :=.execBlock_append h04 hviceRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsinAdd + have h02 := execBlock_append h01 hsinAssign + have h03 := execBlock_append h02 hdaiAdd + have h04 := execBlock_append h03 hdaiAssign + have h05 := execBlock_append h04 hviceRevert + have hblock := execBlock_append_term (s2 := [ .assign .storage viceRef (.var "viceNew") ] ++ checkedAddUintInto "debtNew" (.storage debtRef) (.var "rad") ++ @@ -1261,12 +1261,12 @@ theorem vatSuckSourceRevertViceOverflowVat sinNew).executionEnv.codeOwner (suckDaiSlot I) daiNew) I (sinNew := sinNew) (daiNew := daiNew) (viceVal := vatSlotWord suckViceSlot σDaiSolm I) hviceLoad hviceOverflow - have h01 :=.execBlock_append hprefix hsinAdd - have h02 :=.execBlock_append h01 hsinAssign - have h03 :=.execBlock_append h02 hdaiAdd - have h04 :=.execBlock_append h03 hdaiAssign - have h05 :=.execBlock_append h04 hviceRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsinAdd + have h02 := execBlock_append h01 hsinAssign + have h03 := execBlock_append h02 hdaiAdd + have h04 := execBlock_append h03 hdaiAssign + have h05 := execBlock_append h04 hviceRevert + have hblock := execBlock_append_term (s2 := [ .assign .storage viceRef (.var "viceNew") ] ++ checkedAddUintInto "debtNew" (.storage debtRef) (.var "rad") ++ @@ -1332,14 +1332,14 @@ theorem vatSuckSourceRevertDebtOverflow (evm : EVM.State) (I : ExecutionEnv) have hdebtRevert := vatSuckDebtAddBlockRevert evmVice I (sinNew := sinNew) (daiNew := daiNew) (viceNew := viceNew) (debtVal := debtVal) hdebtLoad hdebtOverflow - have h01 :=.execBlock_append hprefix hsinAdd - have h02 :=.execBlock_append h01 hsinAssign - have h03 :=.execBlock_append h02 hdaiAdd - have h04 :=.execBlock_append h03 hdaiAssign - have h05 :=.execBlock_append h04 hviceAdd - have h06 :=.execBlock_append h05 hviceAssign - have h07 :=.execBlock_append h06 hdebtRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsinAdd + have h02 := execBlock_append h01 hsinAssign + have h03 := execBlock_append h02 hdaiAdd + have h04 := execBlock_append h03 hdaiAssign + have h05 := execBlock_append h04 hviceAdd + have h06 := execBlock_append h05 hviceAssign + have h07 := execBlock_append h06 hdebtRevert + have hblock := execBlock_append_term (s2 := [ .assign .storage debtRef (.var "debtNew") ]) h07 (by intro f' e' h; cases h) simpa [ExecTransitionBody, suckTransition, nonpayable, auth, checkedAddUintInto, @@ -1439,14 +1439,14 @@ theorem vatSuckSourceRevertDebtOverflowVat vatSuckDebtAddBlockRevert evmVice I (sinNew := sinNew) (daiNew := daiNew) (viceNew := viceNew) (debtVal := vatSlotWord suckDebtSlot σViceSolm I) hdebtLoad hdebtOverflow - have h01 :=.execBlock_append hprefix hsinAdd - have h02 :=.execBlock_append h01 hsinAssign - have h03 :=.execBlock_append h02 hdaiAdd - have h04 :=.execBlock_append h03 hdaiAssign - have h05 :=.execBlock_append h04 hviceAdd - have h06 :=.execBlock_append h05 hviceAssign - have h07 :=.execBlock_append h06 hdebtRevert - have hblock :=.execBlock_append_term + have h01 := execBlock_append hprefix hsinAdd + have h02 := execBlock_append h01 hsinAssign + have h03 := execBlock_append h02 hdaiAdd + have h04 := execBlock_append h03 hdaiAssign + have h05 := execBlock_append h04 hviceAdd + have h06 := execBlock_append h05 hviceAssign + have h07 := execBlock_append h06 hdebtRevert + have hblock := execBlock_append_term (s2 := [ .assign .storage debtRef (.var "debtNew") ]) h07 (by intro f' e' h; cases h) simpa [ExecTransitionBody, suckTransition, nonpayable, auth, checkedAddUintInto, @@ -1555,14 +1555,14 @@ theorem vatSuckSourceSuccessVat have hdebtAssign := vatSuckAssignDebtOk evmVice I (sinNew := sinNew) (daiNew := daiNew) (viceNew := viceNew) (debtNew := debtNew) - have h01 :=.execBlock_append hprefix hsinAdd - have h02 :=.execBlock_append h01 hsinAssign - have h03 :=.execBlock_append h02 hdaiAdd - have h04 :=.execBlock_append h03 hdaiAssign - have h05 :=.execBlock_append h04 hviceAdd - have h06 :=.execBlock_append h05 hviceAssign - have h07 :=.execBlock_append h06 hdebtAdd - have hblock :=.execBlock_append h07 hdebtAssign + have h01 := execBlock_append hprefix hsinAdd + have h02 := execBlock_append h01 hsinAssign + have h03 := execBlock_append h02 hdaiAdd + have h04 := execBlock_append h03 hdaiAssign + have h05 := execBlock_append h04 hviceAdd + have h06 := execBlock_append h05 hviceAssign + have h07 := execBlock_append h06 hdebtAdd + have hblock := execBlock_append h07 hdebtAssign simpa [ExecTransitionBody, suckTransition, nonpayable, auth, checkedAddUintInto, List.append_assoc, suckPostState, evmSin, evmDai, evmVice, evmDebt, storageStore_executionEnv] using ExecFuncBody.execBlockOK hblock diff --git a/Benchmarks/Dss/Vow/CageHealRuntime.lean b/Benchmarks/Dss/Vow/CageHealRuntime.lean index 2cb29c45..4042b986 100644 --- a/Benchmarks/Dss/Vow/CageHealRuntime.lean +++ b/Benchmarks/Dss/Vow/CageHealRuntime.lean @@ -118,7 +118,7 @@ theorem cageSourceVatSinSuccessTailRevertFromBlock exact cageVatDaiSuccess (evm := evmFlop) (evmDai := evmDai2) (outDai := outDai2) (flapperDai := flapperDai) (vatDai := vatDai) hvatCode2 hcallDai2 hdecDai2 - have hprefix :=.execBlock_append + have hprefix := execBlock_append (Reasoning.Theory.execBlock_append (Reasoning.Theory.execBlock_append (Reasoning.Theory.execBlock_append @@ -258,7 +258,7 @@ theorem cageSourceVatSinSuccessTailOkFromBlock exact cageVatDaiSuccess (evm := evmFlop) (evmDai := evmDai2) (outDai := outDai2) (flapperDai := flapperDai) (vatDai := vatDai) hvatCode2 hcallDai2 hdecDai2 - have hprefix :=.execBlock_append + have hprefix := execBlock_append (Reasoning.Theory.execBlock_append (Reasoning.Theory.execBlock_append (Reasoning.Theory.execBlock_append diff --git a/Benchmarks/Dss/Vow/CageRuntime.lean b/Benchmarks/Dss/Vow/CageRuntime.lean index 23542b5b..999e04c6 100644 --- a/Benchmarks/Dss/Vow/CageRuntime.lean +++ b/Benchmarks/Dss/Vow/CageRuntime.lean @@ -328,7 +328,7 @@ theorem cageFirstDaiFlapperNoCode ExecBlock config { contract := contract, locals := ∅ } evm (cageFirstVatDaiStmts ++ cageFlapperCageStmts) .reverted := by have hfirst := cageFirstVatDaiNoCode (evm := evm) hvatNoCode - exact.execBlock_append_term (s2 := cageFlapperCageStmts) hfirst + exact execBlock_append_term (s2 := cageFlapperCageStmts) hfirst (by intro f e h; cases h) theorem cageFirstDaiFlapperCallFailure @@ -345,7 +345,7 @@ theorem cageFirstDaiFlapperCallFailure (cageFirstVatDaiStmts ++ cageFlapperCageStmts) .reverted := by have hfirst := cageFirstVatDaiCallFailure (evm := evm) (evmDai := evmDai) (outDai := outDai) hvatCode hcallDai - exact.execBlock_append_term (s2 := cageFlapperCageStmts) hfirst + exact execBlock_append_term (s2 := cageFlapperCageStmts) hfirst (by intro f e h; cases h) theorem cageFirstDaiFlapperReturnDecodeFailure @@ -363,7 +363,7 @@ theorem cageFirstDaiFlapperReturnDecodeFailure (cageFirstVatDaiStmts ++ cageFlapperCageStmts) .reverted := by have hfirst := cageFirstVatDaiReturnDecodeFailure (evm := evm) (evmDai := evmDai) (outDai := outDai) hvatCode hcallDai hdecDai - exact.execBlock_append_term (s2 := cageFlapperCageStmts) hfirst + exact execBlock_append_term (s2 := cageFlapperCageStmts) hfirst (by intro f e h; cases h) theorem cageFirstDaiFlapperCageNoCode @@ -389,7 +389,7 @@ theorem cageFirstDaiFlapperCageNoCode (outDai := outDai) (flapperDai := flapperDai) hvatCode hcallDai hdecDai have hflapper := cageFlapperCageNoCode (evm := evmDai) (flapperDai := flapperDai) hflapperNoCode - exact.execBlock_append hfirst hflapper + exact execBlock_append hfirst hflapper theorem cageFirstDaiFlapperCageCallFailure {evm evmDai evmFlap : EVM.State} {outDai outFlap : ByteArray} @@ -419,7 +419,7 @@ theorem cageFirstDaiFlapperCageCallFailure (outDai := outDai) (flapperDai := flapperDai) hvatCode hcallDai hdecDai have hflapper := cageFlapperCageCallFailure (evm := evmDai) (evmFlap := evmFlap) (outFlap := outFlap) (flapperDai := flapperDai) hflapperCode hcallFlap - exact.execBlock_append hfirst hflapper + exact execBlock_append hfirst hflapper theorem cageFirstDaiFlapperCageSuccess {evm evmDai evmFlap : EVM.State} {outDai outFlap : ByteArray} @@ -451,7 +451,7 @@ theorem cageFirstDaiFlapperCageSuccess (outDai := outDai) (flapperDai := flapperDai) hvatCode hcallDai hdecDai have hflapper := cageFlapperCageSuccess (evm := evmDai) (evmFlap := evmFlap) (outFlap := outFlap) (flapperDai := flapperDai) hflapperCode hcallFlap - exact.execBlock_append hfirst hflapper + exact execBlock_append hfirst hflapper theorem cageSourceFirstDaiNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (hwv : I.weiValue = ⟨0⟩) @@ -490,7 +490,7 @@ theorem cageSourceFirstDaiNoCode {cA gh bl σ σ₀ A I} {g : UInt256} (cageFirstVatDaiStmts ++ cageFlapperCageStmts) .reverted := by exact cageFirstDaiFlapperNoCode (evm := evmAsh) (by simpa [evm0, evmLive, evmSin, evmAsh] using hvatNoCode) - have hprefix :=.execBlock_append hclear hfirst + have hprefix := execBlock_append hclear hfirst have hblock : ExecBlock config { contract := contract, locals := locals } evm0 ((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -501,7 +501,7 @@ theorem cageSourceFirstDaiNoCode {cA gh bl σ σ₀ A I} {g : UInt256} .assign .storage AshRef (.intLit 0) ] ++ cageFirstVatDaiStmts ++ cageFlapperCageStmts) ++ cageAfterFlapperStmts) .reverted := - .execBlock_append_term (s2 := cageAfterFlapperStmts) + execBlock_append_term (s2 := cageAfterFlapperStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) have hbody := ExecFuncBody.execBlockRevert hblock @@ -558,7 +558,7 @@ theorem cageSourceFirstDaiCallFailure (outDai := outDai) (by simpa [evm0, evmLive, evmSin, evmAsh] using hvatCode) (by simpa [evm0, evmLive, evmSin, evmAsh] using hcallDai) - have hprefix :=.execBlock_append hclear hfirst + have hprefix := execBlock_append hclear hfirst have hblock : ExecBlock config { contract := contract, locals := locals } evm0 ((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -569,7 +569,7 @@ theorem cageSourceFirstDaiCallFailure .assign .storage AshRef (.intLit 0) ] ++ cageFirstVatDaiStmts ++ cageFlapperCageStmts) ++ cageAfterFlapperStmts) .reverted := - .execBlock_append_term (s2 := cageAfterFlapperStmts) + execBlock_append_term (s2 := cageAfterFlapperStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) have hbody := ExecFuncBody.execBlockRevert hblock @@ -628,7 +628,7 @@ theorem cageSourceFirstDaiReturnDecodeFailure (by simpa [evm0, evmLive, evmSin, evmAsh] using hvatCode) (by simpa [evm0, evmLive, evmSin, evmAsh] using hcallDai) hdecDai - have hprefix :=.execBlock_append hclear hfirst + have hprefix := execBlock_append hclear hfirst have hblock : ExecBlock config { contract := contract, locals := locals } evm0 ((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -639,7 +639,7 @@ theorem cageSourceFirstDaiReturnDecodeFailure .assign .storage AshRef (.intLit 0) ] ++ cageFirstVatDaiStmts ++ cageFlapperCageStmts) ++ cageAfterFlapperStmts) .reverted := - .execBlock_append_term (s2 := cageAfterFlapperStmts) + execBlock_append_term (s2 := cageAfterFlapperStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) have hbody := ExecFuncBody.execBlockRevert hblock @@ -705,7 +705,7 @@ theorem cageSourceFlapperCageNoCode (by simpa [evm0, evmLive, evmSin, evmAsh] using hvatCode) (by simpa [evm0, evmLive, evmSin, evmAsh] using hcallDai) hdecDai hflapperNoCode - have hprefix :=.execBlock_append hclear hfirst + have hprefix := execBlock_append hclear hfirst have hblock : ExecBlock config { contract := contract, locals := locals } evm0 ((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -716,7 +716,7 @@ theorem cageSourceFlapperCageNoCode .assign .storage AshRef (.intLit 0) ] ++ cageFirstVatDaiStmts ++ cageFlapperCageStmts) ++ cageAfterFlapperStmts) .reverted := - .execBlock_append_term (s2 := cageAfterFlapperStmts) + execBlock_append_term (s2 := cageAfterFlapperStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) have hbody := ExecFuncBody.execBlockRevert hblock @@ -787,7 +787,7 @@ theorem cageSourceFlapperCageCallFailure (by simpa [evm0, evmLive, evmSin, evmAsh] using hvatCode) (by simpa [evm0, evmLive, evmSin, evmAsh] using hcallDai) hdecDai hflapperCode hcallFlap - have hprefix :=.execBlock_append hclear hfirst + have hprefix := execBlock_append hclear hfirst have hblock : ExecBlock config { contract := contract, locals := locals } evm0 ((.require (.binary .eq (.env .callvalue) (.intLit 0)) :: @@ -798,7 +798,7 @@ theorem cageSourceFlapperCageCallFailure .assign .storage AshRef (.intLit 0) ] ++ cageFirstVatDaiStmts ++ cageFlapperCageStmts) ++ cageAfterFlapperStmts) .reverted := - .execBlock_append_term (s2 := cageAfterFlapperStmts) + execBlock_append_term (s2 := cageAfterFlapperStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) have hbody := ExecFuncBody.execBlockRevert hblock @@ -881,7 +881,7 @@ theorem cageSourceFlopperCageNoCode evmFlap cageFlopperCageStmts .reverted := cageFlopperCageNoCode (evm := evmFlap) (flapperDai := flapperDai) hflopperNoCode - have hprefix :=.execBlock_append + have hprefix := execBlock_append (Reasoning.Theory.execBlock_append hclear hfirst) hflopper have hblock : ExecBlock config { contract := contract, locals := locals } evm0 @@ -895,7 +895,7 @@ theorem cageSourceFlopperCageNoCode cageFlopperCageStmts) ++ cageVatDaiStmts ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) .reverted := - .execBlock_append_term + execBlock_append_term (s2 := cageVatDaiStmts ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) @@ -982,7 +982,7 @@ theorem cageSourceFlopperCageCallFailure evmFlap cageFlopperCageStmts .reverted := cageFlopperCageCallFailure (evm := evmFlap) (evmFlop := evmFlop) (outFlop := outFlop) (flapperDai := flapperDai) hflopperCode hcallFlop - have hprefix :=.execBlock_append + have hprefix := execBlock_append (Reasoning.Theory.execBlock_append hclear hfirst) hflopper have hblock : ExecBlock config { contract := contract, locals := locals } evm0 @@ -996,7 +996,7 @@ theorem cageSourceFlopperCageCallFailure cageFlopperCageStmts) ++ cageVatDaiStmts ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) .reverted := - .execBlock_append_term + execBlock_append_term (s2 := cageVatDaiStmts ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) @@ -1550,7 +1550,7 @@ theorem cageMinHealLeftNoCode (vatSin := vatSin) (evm := evm) hle have hheal := cageVatHealNoCode (flapperDai := flapperDai) (vatDai := vatDai) (vatSin := vatSin) (healRad := vatDai) (evm := evm) hvatNoCode - exact.execBlock_append hmin hheal + exact execBlock_append hmin hheal theorem cageMinHealRightNoCode {evm : EVM.State} {flapperDai vatDai vatSin : UInt256} @@ -1567,7 +1567,7 @@ theorem cageMinHealRightNoCode (vatSin := vatSin) (evm := evm) hlt have hheal := cageVatHealNoCode (flapperDai := flapperDai) (vatDai := vatDai) (vatSin := vatSin) (healRad := vatSin) (evm := evm) hvatNoCode - exact.execBlock_append hmin hheal + exact execBlock_append hmin hheal theorem cageMinHealLeftCallFailure {evm evmHeal : EVM.State} {outHeal : ByteArray} @@ -1589,7 +1589,7 @@ theorem cageMinHealLeftCallFailure have hheal := cageVatHealCallFailure (flapperDai := flapperDai) (vatDai := vatDai) (vatSin := vatSin) (healRad := vatDai) (evm := evm) (evmHeal := evmHeal) (outHeal := outHeal) hvatCode hcallHeal - exact.execBlock_append hmin hheal + exact execBlock_append hmin hheal theorem cageMinHealRightCallFailure {evm evmHeal : EVM.State} {outHeal : ByteArray} @@ -1611,7 +1611,7 @@ theorem cageMinHealRightCallFailure have hheal := cageVatHealCallFailure (flapperDai := flapperDai) (vatDai := vatDai) (vatSin := vatSin) (healRad := vatSin) (evm := evm) (evmHeal := evmHeal) (outHeal := outHeal) hvatCode hcallHeal - exact.execBlock_append hmin hheal + exact execBlock_append hmin hheal theorem cageMinHealLeftSuccess {evm evmHeal : EVM.State} {outHeal : ByteArray} @@ -1635,7 +1635,7 @@ theorem cageMinHealLeftSuccess have hheal := cageVatHealSuccess (flapperDai := flapperDai) (vatDai := vatDai) (vatSin := vatSin) (healRad := vatDai) (evm := evm) (evmHeal := evmHeal) (outHeal := outHeal) hvatCode hcallHeal - exact.execBlock_append hmin hheal + exact execBlock_append hmin hheal theorem cageMinHealRightSuccess {evm evmHeal : EVM.State} {outHeal : ByteArray} @@ -1659,6 +1659,6 @@ theorem cageMinHealRightSuccess have hheal := cageVatHealSuccess (flapperDai := flapperDai) (vatDai := vatDai) (vatSin := vatSin) (healRad := vatSin) (evm := evm) (evmHeal := evmHeal) (outHeal := outHeal) hvatCode hcallHeal - exact.execBlock_append hmin hheal + exact execBlock_append hmin hheal end Benchmarks.Dss.Vow diff --git a/Benchmarks/Dss/Vow/CageTailRuntime.lean b/Benchmarks/Dss/Vow/CageTailRuntime.lean index d53ffbc7..09b253a3 100644 --- a/Benchmarks/Dss/Vow/CageTailRuntime.lean +++ b/Benchmarks/Dss/Vow/CageTailRuntime.lean @@ -96,7 +96,7 @@ theorem cageSourceSecondDaiNoCode { contract := contract, locals := cageLocalsAfterFlopCage flapperDai } evmFlop cageVatDaiStmts .reverted := cageVatDaiNoCode (evm := evmFlop) (flapperDai := flapperDai) hvatNoCode - have hprefix :=.execBlock_append + have hprefix := execBlock_append (Reasoning.Theory.execBlock_append (Reasoning.Theory.execBlock_append hclear hfirst) hflopper) hsecond have hblock : @@ -111,7 +111,7 @@ theorem cageSourceSecondDaiNoCode cageFlopperCageStmts) ++ cageVatDaiStmts) ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) .reverted := - .execBlock_append_term + execBlock_append_term (s2 := cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) @@ -215,7 +215,7 @@ theorem cageSourceSecondDaiCallFailure evmFlop cageVatDaiStmts .reverted := cageVatDaiCallFailure (evm := evmFlop) (evmDai := evmDai2) (outDai := outDai2) (flapperDai := flapperDai) hvatCode2 hcallDai2 - have hprefix :=.execBlock_append + have hprefix := execBlock_append (Reasoning.Theory.execBlock_append (Reasoning.Theory.execBlock_append hclear hfirst) hflopper) hsecond have hblock : @@ -230,7 +230,7 @@ theorem cageSourceSecondDaiCallFailure cageFlopperCageStmts) ++ cageVatDaiStmts) ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) .reverted := - .execBlock_append_term + execBlock_append_term (s2 := cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) @@ -335,7 +335,7 @@ theorem cageSourceSecondDaiReturnDecodeFailure evmFlop cageVatDaiStmts .reverted := cageVatDaiReturnDecodeFailure (evm := evmFlop) (evmDai := evmDai2) (outDai := outDai2) (flapperDai := flapperDai) hvatCode2 hcallDai2 hdecDai2 - have hprefix :=.execBlock_append + have hprefix := execBlock_append (Reasoning.Theory.execBlock_append (Reasoning.Theory.execBlock_append hclear hfirst) hflopper) hsecond have hblock : @@ -350,7 +350,7 @@ theorem cageSourceSecondDaiReturnDecodeFailure cageFlopperCageStmts) ++ cageVatDaiStmts) ++ cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) .reverted := - .execBlock_append_term + execBlock_append_term (s2 := cageVatSinStmts ++ cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) @@ -470,7 +470,7 @@ theorem cageSourceVatSinNoCode evmDai2 cageVatSinStmts .reverted := cageVatSinNoCode (evm := evmDai2) (flapperDai := flapperDai) (vatDai := vatDai) hvatNoCode - have hprefix :=.execBlock_append + have hprefix := execBlock_append (Reasoning.Theory.execBlock_append (Reasoning.Theory.execBlock_append (Reasoning.Theory.execBlock_append hclear hfirst) hflopper) hsecond) hsin @@ -486,7 +486,7 @@ theorem cageSourceVatSinNoCode cageFlopperCageStmts) ++ cageVatDaiStmts) ++ cageVatSinStmts) ++ cageMinStmts ++ cageVatHealStmts) .reverted := - .execBlock_append_term + execBlock_append_term (s2 := cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) @@ -600,7 +600,7 @@ theorem cageSourceVatSinRevertFromBlock exact cageVatDaiSuccess (evm := evmFlop) (evmDai := evmDai2) (outDai := outDai2) (flapperDai := flapperDai) (vatDai := vatDai) hvatCode2 hcallDai2 hdecDai2 - have hprefix :=.execBlock_append + have hprefix := execBlock_append (Reasoning.Theory.execBlock_append (Reasoning.Theory.execBlock_append (Reasoning.Theory.execBlock_append hclear hfirst) hflopper) hsecond) hsin @@ -616,7 +616,7 @@ theorem cageSourceVatSinRevertFromBlock cageFlopperCageStmts) ++ cageVatDaiStmts) ++ cageVatSinStmts) ++ cageMinStmts ++ cageVatHealStmts) .reverted := - .execBlock_append_term + execBlock_append_term (s2 := cageMinStmts ++ cageVatHealStmts) (by simpa [List.append_assoc] using hprefix) (by intro f e h; cases h) diff --git a/Benchmarks/Dss/Vow/FileAddress.lean b/Benchmarks/Dss/Vow/FileAddress.lean index f8f2a9c6..10ea555a 100644 --- a/Benchmarks/Dss/Vow/FileAddress.lean +++ b/Benchmarks/Dss/Vow/FileAddress.lean @@ -1289,7 +1289,7 @@ theorem RD.vowFileAddressNopeSuccessStoreFlapper have rd4344 := rd4343.and (by native_decide) (by evm_ov) have rd4345 := rd4344.swap2 (by native_decide) (by evm_ov) have rd4346 := rd4345.dup3 (by native_decide) (by evm_ov) - have rd4347 := rd4346.lor (by native_decide) (by evm_ov) + have rd4347 := rd4346.or (by native_decide) (by evm_ov) have rd4348 := rd4347.swap1 (by native_decide) (by evm_ov) have rd4349 := rd4348.swap3 (by native_decide) (by evm_ov) obtain ⟨_, _, rd4350⟩ := rd4349.sstore hperm (by native_decide) (by evm_ov) @@ -1400,7 +1400,7 @@ theorem RD.vowFileAddressStoreFlopper {g : Sat256} {s0 : State} {ee : ExecutionE have rd4489 := rd4488.sub (by native_decide) (by evm_ov) have rd4490 := rd4489.dup4 (by native_decide) (by evm_ov) have rd4491 := rd4490.and (by native_decide) (by evm_ov) - have rd4492 := rd4491.lor (by native_decide) (by evm_ov) + have rd4492 := rd4491.or (by native_decide) (by evm_ov) have rd4493 := rd4492.swap1 (by native_decide) (by evm_ov) obtain ⟨_, _, rd4494⟩ := rd4493.sstore hperm (by native_decide) (by evm_ov) have rd4497 := rd4494.push2 ⟨2233⟩ (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Vow/FileAddressFlapper.lean b/Benchmarks/Dss/Vow/FileAddressFlapper.lean index fa2b9676..1a478e3b 100644 --- a/Benchmarks/Dss/Vow/FileAddressFlapper.lean +++ b/Benchmarks/Dss/Vow/FileAddressFlapper.lean @@ -779,7 +779,7 @@ theorem RD.vowFileAddressNopeSuccessStoreFlapperWithTarget have rd4344 := rd4343.and (by native_decide) (by evm_ov) have rd4345 := rd4344.swap2 (by native_decide) (by evm_ov) have rd4346 := rd4345.dup3 (by native_decide) (by evm_ov) - have rd4347 := rd4346.lor (by native_decide) (by evm_ov) + have rd4347 := rd4346.or (by native_decide) (by evm_ov) have rd4348 := rd4347.swap1 (by native_decide) (by evm_ov) have rd4349 := rd4348.swap3 (by native_decide) (by evm_ov) obtain ⟨_, _, rd4350⟩ := rd4349.sstore hperm (by native_decide) (by evm_ov) diff --git a/Benchmarks/Dss/Vow/FlapBody.lean b/Benchmarks/Dss/Vow/FlapBody.lean index 49212041..5908b527 100644 --- a/Benchmarks/Dss/Vow/FlapBody.lean +++ b/Benchmarks/Dss/Vow/FlapBody.lean @@ -730,7 +730,7 @@ theorem flapSourceInsufficientSurplus have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat :=.execBlock_append hprefix htail + have hcat := execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -1212,7 +1212,7 @@ theorem flapPostDaiToKickSuccess (vatDai := vatDai) (vatSin1 := vatSin1) (freeSin := freeSin) (debt := debt) (BumpVal := BumpVal) (id := id) hBumpLoad hflapperCode hcallKick hdecKick - have htail :=.execBlock_append hpost hkick + have htail := execBlock_append hpost hkick simpa [flapTailStmts] using htail theorem flapSourceBlockSuccess @@ -1328,7 +1328,7 @@ theorem flapSourceBlockSuccess ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body (.returned { contract := contract, locals := locals8 } evmKick (some [.int (Int.ofNat id.toNat)])) := by - have hcat :=.execBlock_append hprefix htail + have hcat := execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat diff --git a/Benchmarks/Dss/Vow/FlapDaiBody.lean b/Benchmarks/Dss/Vow/FlapDaiBody.lean index 551954f0..f082afca 100644 --- a/Benchmarks/Dss/Vow/FlapDaiBody.lean +++ b/Benchmarks/Dss/Vow/FlapDaiBody.lean @@ -225,7 +225,7 @@ theorem flapSourceDai0NoCode have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat :=.execBlock_append hbefore htail + have hcat := execBlock_append hbefore htail simpa [flapTransition, flapBeforeDaiStmts, flapDai0AndTailStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -313,7 +313,7 @@ theorem flapSourceDai0CallFailure have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat :=.execBlock_append hbefore htail + have hcat := execBlock_append hbefore htail simpa [flapTransition, flapBeforeDaiStmts, flapDai0AndTailStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -402,7 +402,7 @@ theorem flapSourceDai0DecodeRevert have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat :=.execBlock_append hbefore htail + have hcat := execBlock_append hbefore htail simpa [flapTransition, flapBeforeDaiStmts, flapDai0AndTailStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat diff --git a/Benchmarks/Dss/Vow/FlapKickBody.lean b/Benchmarks/Dss/Vow/FlapKickBody.lean index ac5d9e26..8ebdf999 100644 --- a/Benchmarks/Dss/Vow/FlapKickBody.lean +++ b/Benchmarks/Dss/Vow/FlapKickBody.lean @@ -331,12 +331,12 @@ theorem vowFlapKickNoCodeBodyCore have htail : ExecBlock config { contract := contract, locals := locals4 } evmDai flapTailStmts .reverted := by - have hcat :=.execBlock_append hpost hkick + have hcat := execBlock_append hpost hkick simpa [flapTailStmts] using hcat have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat :=.execBlock_append hprefix htail + have hcat := execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -450,12 +450,12 @@ theorem flapSourceKickRevert have htail : ExecBlock config { contract := contract, locals := locals4 } evmDai flapTailStmts .reverted := by - have hcat :=.execBlock_append hpost hkick' + have hcat := execBlock_append hpost hkick' simpa [flapTailStmts] using hcat have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat :=.execBlock_append hprefix htail + have hcat := execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat diff --git a/Benchmarks/Dss/Vow/FlapSin1Body.lean b/Benchmarks/Dss/Vow/FlapSin1Body.lean index 2b6cd446..eee106f2 100644 --- a/Benchmarks/Dss/Vow/FlapSin1Body.lean +++ b/Benchmarks/Dss/Vow/FlapSin1Body.lean @@ -287,7 +287,7 @@ theorem vowFlapSin1NoCodeBodyCore have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat :=.execBlock_append hprefix htail + have hcat := execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -385,7 +385,7 @@ theorem vowFlapSin1CallFailureBodyCore have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat :=.execBlock_append hprefix htail + have hcat := execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -515,7 +515,7 @@ theorem vowFlapSin1DecodeShortBodyCore have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat :=.execBlock_append hprefix htail + have hcat := execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat diff --git a/Benchmarks/Dss/Vow/FlapSubBody.lean b/Benchmarks/Dss/Vow/FlapSubBody.lean index 0c838024..6255cdd0 100644 --- a/Benchmarks/Dss/Vow/FlapSubBody.lean +++ b/Benchmarks/Dss/Vow/FlapSubBody.lean @@ -224,7 +224,7 @@ theorem vowFlapFreeSinUnderflowBodyCore have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat :=.execBlock_append hprefix htail + have hcat := execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -508,7 +508,7 @@ theorem vowFlapDebtUnderflowBodyCore have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat :=.execBlock_append hprefix htail + have hcat := execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat @@ -825,7 +825,7 @@ theorem vowFlapDebtNotZeroBodyCore have hblock : ExecBlock config { contract := contract, locals := locals } evm0 flapTransition.body .reverted := by - have hcat :=.execBlock_append hprefix htail + have hcat := execBlock_append hprefix htail simpa [flapTransition, flapPrefixToDaiStmts, flapTailStmts, flapPostDaiToKickStmts, flapKickAndReturnStmts, nonpayable, checkedExternalCallStmts, locals, evm0] using hcat